Lines 85–101 at 26 (were 85–90 at 25)
8585 return sent === undefined ? baseMs : baseMs + Math.floor(Buffer.byteLength(sent) / 100_000) * 1000; 89+ * How long a publish or a land may take before the client stops waiting: the 90+ * server gives one request up to 2 minutes of work, so a small body can still 91+ * take that long (a large merge). Waiting less reported publishes as failed 92+ * that went on to land. 94+export const PUBLISH_TIMEOUT_MS = 150_000; 96+/** The most versions the server's log sends at once. */ 97+export const LOG_PAGE = 200; 8899/** A query string from the values that are set (null and undefined are left out). */ 89100function query(values: Record<string, string | number | null | undefined>): URLSearchParams { 90101 const q = new URLSearchParams(); Lines 179–194 at 26 (were 168–177 at 25)
171− async json<T>(method: "GET" | "POST", path: string, body?: unknown, server = this.config.server): Promise<T> {
183+ method: "GET" | "POST", 186+ server = this.config.server, 172189 let res: Response | undefined; 173190 const sent = body === undefined ? undefined : JSON.stringify(body); 174− const timeoutMs = timeoutFor(this.timeoutMs, sent);
191+ const timeoutMs = Math.max(atLeastMs, timeoutFor(this.timeoutMs, sent)); 175192 // A connection that never opened is tried once more, IPv4 first (#37, GAME - UI/UX: one IPv6 176193 // address timed out, and the same command went through seconds later). Nothing went out, so 177194 // a POST is as safe to send again as a GET. Lines 392–404 at 26 (were 375–381 at 25)
377394 publish(message: string, asIs = false): Promise<PublishAnswer> { 378− return this.json("POST", this.agentPath("publish"), { message, ...(asIs ? { asIs: true } : {}) });
397+ this.agentPath("publish"), 398+ { message, ...(asIs ? { asIs: true } : {}) }, 381404 /** One change (#44). */ Lines 732–738 at 26 (were 709–715 at 25)
710733 /** Land never queues: with the merge queue on, the server refuses it (#39). */ 711734 land(message: string): Promise<Exclude<PublishAnswer, { queued: number }>> { 712− return this.json("POST", this.agentPath("land"), { message });
735+ return this.json("POST", this.agentPath("land"), { message }, undefined, PUBLISH_TIMEOUT_MS); 715738 draftSync(): Promise<DraftSyncAnswer> { Lines 754–784 at 26 (were 731–740 at 25)
733756 /** The versions of a space, newest first; with `path`, only those that changed it. */ 734− log(where: Where, limit?: number, path?: string): Promise<LogAnswer> {
735− return this.json("GET", `/log?${query({ ...where, limit, path })}`);
758+ * The versions newest first, below `before` when it's given. The server 759+ * sends at most LOG_PAGE at a time, so a longer log is read page by page, 760+ * following each page's next. `next` on the answer says older ones are left. 762+ async log(where: Where, limit?: number, path?: string, before?: number): Promise<LogAnswer> { 763+ let page = await this.#logPage(where, limit === undefined ? undefined : Math.min(limit, LOG_PAGE), path, before); 764+ const versions = [...page.versions]; 765+ while (limit !== undefined && versions.length < limit && page.next !== undefined) { 766+ page = await this.#logPage(where, Math.min(limit - versions.length, LOG_PAGE), path, page.next); 767+ versions.push(...page.versions); 769+ const { next, ...rest } = page; 770+ return { ...rest, versions, ...(next !== undefined ? { next } : {}) }; 775+ limit: number | undefined, 776+ path: string | undefined, 777+ before: number | undefined, 778+ ): Promise<LogAnswer> { 779+ return this.json("GET", `/log?${query({ ...where, limit, path, before })}`); 738782 show(version: number, where: Where): Promise<ShowAnswer> { 739783 return this.json("GET", `/show?${query({ version, ...where })}`);