gemi 0.206.0 → 0.207.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/{chunk-qjk68wda.js → chunk-53fv4c39.js} +2 -2
  2. package/dist/{chunk-qjk68wda.js.map → chunk-53fv4c39.js.map} +4 -4
  3. package/dist/{chunk-jr5t2hrk.js → chunk-b1v4ync4.js} +1 -1
  4. package/dist/{chunk-s4tq4y69.js → chunk-j683qspe.js} +1 -1
  5. package/dist/{chunk-j9ga7b74.js → chunk-k8a41gkt.js} +1 -1
  6. package/dist/{chunk-xmpamj50.js → chunk-yqgyywpq.js} +2 -2
  7. package/dist/{chunk-xmpamj50.js.map → chunk-yqgyywpq.js.map} +1 -1
  8. package/dist/chunks/{RealtimeClient-CLXePUcE.js → RealtimeClient-D4qIHPf1.js} +2 -2
  9. package/dist/chunks/{RealtimeClient-CLXePUcE.js.map → RealtimeClient-D4qIHPf1.js.map} +1 -1
  10. package/dist/chunks/{ThemeProvider-COjYIalw.js → ThemeProvider-w_axEu6B.js} +48 -9
  11. package/dist/chunks/ThemeProvider-w_axEu6B.js.map +1 -0
  12. package/dist/chunks/{fetchFileRequest-BaufNZpI.js → fetchFileRequest-Bhh5BC_l.js} +2 -2
  13. package/dist/chunks/{fetchFileRequest-BaufNZpI.js.map → fetchFileRequest-Bhh5BC_l.js.map} +1 -1
  14. package/dist/chunks/{live-Dz_rk7fm.js → live-9IXFtoGy.js} +3 -3
  15. package/dist/chunks/{live-Dz_rk7fm.js.map → live-9IXFtoGy.js.map} +1 -1
  16. package/dist/chunks/{mutationExtras-DtSw6BcX.js → mutationExtras-bNF9JOSk.js} +2 -2
  17. package/dist/chunks/{mutationExtras-DtSw6BcX.js.map → mutationExtras-bNF9JOSk.js.map} +1 -1
  18. package/dist/chunks/{subscriptionStream-CqhJOfPn.js → subscriptionStream-D42DpDiZ.js} +2 -2
  19. package/dist/chunks/{subscriptionStream-CqhJOfPn.js.map → subscriptionStream-D42DpDiZ.js.map} +1 -1
  20. package/dist/client/QueryManagerContext.d.ts +5 -1
  21. package/dist/client/QueryManagerContext.d.ts.map +1 -1
  22. package/dist/client/QueryResource.d.ts +27 -1
  23. package/dist/client/QueryResource.d.ts.map +1 -1
  24. package/dist/client/index.js +55 -15
  25. package/dist/client/index.js.map +1 -1
  26. package/dist/client/useMultipleQuery.d.ts +11 -1
  27. package/dist/client/useMultipleQuery.d.ts.map +1 -1
  28. package/dist/client/useQuery.d.ts +12 -1
  29. package/dist/client/useQuery.d.ts.map +1 -1
  30. package/dist/facades/index.js +1 -1
  31. package/dist/http/index.js +1 -1
  32. package/dist/i18n/index.js +1 -1
  33. package/dist/kernel/index.js +1 -1
  34. package/dist/server/index.js +1 -1
  35. package/dist/services/index.js +1 -1
  36. package/dist/testing/index.js +2 -2
  37. package/package.json +1 -1
  38. package/skills/gemi-react-best-practices/rules/query-multiple-query-per-component.md +22 -0
  39. package/dist/chunks/ThemeProvider-COjYIalw.js.map +0 -1
  40. /package/dist/{chunk-jr5t2hrk.js.map → chunk-b1v4ync4.js.map} +0 -0
  41. /package/dist/{chunk-s4tq4y69.js.map → chunk-j683qspe.js.map} +0 -0
  42. /package/dist/{chunk-j9ga7b74.js.map → chunk-k8a41gkt.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- import { $ as applyParams, gt as parseRetryAfter, yt as QueryError } from "./ThemeProvider-COjYIalw.js";
1
+ import { $ as applyParams, gt as parseRetryAfter, yt as QueryError } from "./ThemeProvider-w_axEu6B.js";
2
2
  //#region client/fetchFileRequest.ts
3
3
  /**
4
4
  * `fetchBlob` / `fetchText` once loaded: the `GET`, a `QueryError` for a
@@ -54,4 +54,4 @@ function filenameOf(response) {
54
54
  //#endregion
55
55
  export { fetchFile, filenameOf };
56
56
 
57
- //# sourceMappingURL=fetchFileRequest-BaufNZpI.js.map
57
+ //# sourceMappingURL=fetchFileRequest-Bhh5BC_l.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchFileRequest-BaufNZpI.js","names":[],"sources":["../../client/fetchFileRequest.ts"],"sourcesContent":["import { applyParams } from \"../utils/applyParams\";\nimport type { FetchedBlob, FetchedText, FetchFileOptions } from \"./fetchFile\";\nimport { QueryError } from \"./QueryError\";\nimport { parseRetryAfter } from \"./retryPolicy\";\n\n// What `fetchBlob` and `fetchText` in `./fetchFile` load on their first call\n// (#915).\n\ntype RequestOptions = Omit<FetchFileOptions<string>, \"params\"> & {\n params?: Record<string, string | number | undefined>;\n};\n\n/**\n * `fetchBlob` / `fetchText` once loaded: the `GET`, a `QueryError` for a\n * non-2xx, and the body read `as` a blob or text.\n */\nexport async function fetchFile(\n path: string,\n // The caller's `FetchFileOptions<P>`, checked against its path there.\n options: object | undefined,\n as: \"blob\" | \"text\",\n): Promise<FetchedBlob | FetchedText> {\n const response = await request(path, options as RequestOptions);\n const body = as === \"blob\" ? { blob: await response.blob() } : { text: await response.text() };\n return { ...body, filename: filenameOf(response), response } as FetchedBlob | FetchedText;\n}\n\nasync function request(path: string, options: RequestOptions = {}) {\n const { params = {}, search, signal, init } = options;\n const url = applyParams(path, params);\n const query = searchString(search);\n const response = await fetch(`/api${url}${query ? `?${query}` : \"\"}`, {\n ...init,\n method: \"GET\",\n signal,\n });\n if (!response.ok) {\n // An error body that is not JSON (a proxy's HTML 502) is still that status.\n const body = await response.json().catch(() => null);\n throw new QueryError(\n url,\n query,\n response.status,\n body,\n parseRetryAfter(response.headers.get(\"retry-after\")),\n );\n }\n return response;\n}\n\nfunction searchString(search: FetchFileOptions<string>[\"search\"]) {\n if (!search) return \"\";\n if (search instanceof URLSearchParams) return search.toString();\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(search)) {\n if (value !== null && value !== undefined) params.append(key, String(value));\n }\n return params.toString();\n}\n\n/**\n * The file name in a `Content-Disposition` header: the RFC 5987\n * `filename*=UTF-8''...` form when present and decodable, else `filename`.\n *\n * @internal Exported for tests.\n */\nexport function filenameOf(response: Response): string | null {\n const header = response.headers.get(\"content-disposition\");\n if (!header) return null;\n const extended = /filename\\*\\s*=\\s*([^']*)'[^']*'([^;]+)/i.exec(header);\n if (extended) {\n try {\n return decodeURIComponent(extended[2].trim());\n } catch {\n // A malformed escape: fall back to the plain form.\n }\n }\n const plain = /filename\\s*=\\s*(?:\"((?:[^\"\\\\]|\\\\.)*)\"|([^;]+))/i.exec(header);\n if (!plain) return null;\n const name = plain[1] !== undefined ? plain[1].replace(/\\\\(.)/g, \"$1\") : plain[2].trim();\n return name || null;\n}\n"],"mappings":";;;;;;AAgBA,eAAsB,UACpB,MAEA,SACA,IACoC;CACpC,MAAM,WAAW,MAAM,QAAQ,MAAM,OAAyB;CAE9D,OAAO;EAAE,GADI,OAAO,SAAS,EAAE,MAAM,MAAM,SAAS,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,SAAS,KAAK,EAAE;EAC3E,UAAU,WAAW,QAAQ;EAAG;CAAS;AAC7D;AAEA,eAAe,QAAQ,MAAc,UAA0B,CAAC,GAAG;CACjE,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,QAAQ,SAAS;CAC9C,MAAM,MAAM,YAAY,MAAM,MAAM;CACpC,MAAM,QAAQ,aAAa,MAAM;CACjC,MAAM,WAAW,MAAM,MAAM,OAAO,MAAM,QAAQ,IAAI,UAAU,MAAM;EACpE,GAAG;EACH,QAAQ;EACR;CACF,CAAC;CACD,IAAI,CAAC,SAAS,IAAI;EAEhB,MAAM,OAAO,MAAM,SAAS,KAAK,CAAC,CAAC,YAAY,IAAI;EACnD,MAAM,IAAI,WACR,KACA,OACA,SAAS,QACT,MACA,gBAAgB,SAAS,QAAQ,IAAI,aAAa,CAAC,CACrD;CACF;CACA,OAAO;AACT;AAEA,SAAS,aAAa,QAA4C;CAChE,IAAI,CAAC,QAAQ,OAAO;CACpB,IAAI,kBAAkB,iBAAiB,OAAO,OAAO,SAAS;CAC9D,MAAM,SAAS,IAAI,gBAAgB;CACnC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAC9C,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO,OAAO,KAAK,OAAO,KAAK,CAAC;CAE7E,OAAO,OAAO,SAAS;AACzB;;;;;;;AAQA,SAAgB,WAAW,UAAmC;CAC5D,MAAM,SAAS,SAAS,QAAQ,IAAI,qBAAqB;CACzD,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,WAAW,0CAA0C,KAAK,MAAM;CACtE,IAAI,UACF,IAAI;EACF,OAAO,mBAAmB,SAAS,EAAE,CAAC,KAAK,CAAC;CAC9C,QAAQ,CAER;CAEF,MAAM,QAAQ,kDAAkD,KAAK,MAAM;CAC3E,IAAI,CAAC,OAAO,OAAO;CAEnB,QADa,MAAM,OAAO,KAAA,IAAY,MAAM,EAAE,CAAC,QAAQ,UAAU,IAAI,IAAI,MAAM,EAAE,CAAC,KAAK,MACxE;AACjB"}
1
+ {"version":3,"file":"fetchFileRequest-Bhh5BC_l.js","names":[],"sources":["../../client/fetchFileRequest.ts"],"sourcesContent":["import { applyParams } from \"../utils/applyParams\";\nimport type { FetchedBlob, FetchedText, FetchFileOptions } from \"./fetchFile\";\nimport { QueryError } from \"./QueryError\";\nimport { parseRetryAfter } from \"./retryPolicy\";\n\n// What `fetchBlob` and `fetchText` in `./fetchFile` load on their first call\n// (#915).\n\ntype RequestOptions = Omit<FetchFileOptions<string>, \"params\"> & {\n params?: Record<string, string | number | undefined>;\n};\n\n/**\n * `fetchBlob` / `fetchText` once loaded: the `GET`, a `QueryError` for a\n * non-2xx, and the body read `as` a blob or text.\n */\nexport async function fetchFile(\n path: string,\n // The caller's `FetchFileOptions<P>`, checked against its path there.\n options: object | undefined,\n as: \"blob\" | \"text\",\n): Promise<FetchedBlob | FetchedText> {\n const response = await request(path, options as RequestOptions);\n const body = as === \"blob\" ? { blob: await response.blob() } : { text: await response.text() };\n return { ...body, filename: filenameOf(response), response } as FetchedBlob | FetchedText;\n}\n\nasync function request(path: string, options: RequestOptions = {}) {\n const { params = {}, search, signal, init } = options;\n const url = applyParams(path, params);\n const query = searchString(search);\n const response = await fetch(`/api${url}${query ? `?${query}` : \"\"}`, {\n ...init,\n method: \"GET\",\n signal,\n });\n if (!response.ok) {\n // An error body that is not JSON (a proxy's HTML 502) is still that status.\n const body = await response.json().catch(() => null);\n throw new QueryError(\n url,\n query,\n response.status,\n body,\n parseRetryAfter(response.headers.get(\"retry-after\")),\n );\n }\n return response;\n}\n\nfunction searchString(search: FetchFileOptions<string>[\"search\"]) {\n if (!search) return \"\";\n if (search instanceof URLSearchParams) return search.toString();\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(search)) {\n if (value !== null && value !== undefined) params.append(key, String(value));\n }\n return params.toString();\n}\n\n/**\n * The file name in a `Content-Disposition` header: the RFC 5987\n * `filename*=UTF-8''...` form when present and decodable, else `filename`.\n *\n * @internal Exported for tests.\n */\nexport function filenameOf(response: Response): string | null {\n const header = response.headers.get(\"content-disposition\");\n if (!header) return null;\n const extended = /filename\\*\\s*=\\s*([^']*)'[^']*'([^;]+)/i.exec(header);\n if (extended) {\n try {\n return decodeURIComponent(extended[2].trim());\n } catch {\n // A malformed escape: fall back to the plain form.\n }\n }\n const plain = /filename\\s*=\\s*(?:\"((?:[^\"\\\\]|\\\\.)*)\"|([^;]+))/i.exec(header);\n if (!plain) return null;\n const name = plain[1] !== undefined ? plain[1].replace(/\\\\(.)/g, \"$1\") : plain[2].trim();\n return name || null;\n}\n"],"mappings":";;;;;;AAgBA,eAAsB,UACpB,MAEA,SACA,IACoC;CACpC,MAAM,WAAW,MAAM,QAAQ,MAAM,OAAyB;CAE9D,OAAO;EAAE,GADI,OAAO,SAAS,EAAE,MAAM,MAAM,SAAS,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,SAAS,KAAK,EAAE;EAC3E,UAAU,WAAW,QAAQ;EAAG;CAAS;AAC7D;AAEA,eAAe,QAAQ,MAAc,UAA0B,CAAC,GAAG;CACjE,MAAM,EA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realtime, Z as loadedModule } from "./ThemeProvider-COjYIalw.js";
2
+ import { J as realtime, Z as loadedModule } from "./ThemeProvider-w_axEu6B.js";
3
3
  //#region client/realtime/live.ts
4
4
  var live_exports = /* @__PURE__ */ __exportAll({
5
5
  followLive: () => followLive,
@@ -65,7 +65,7 @@ function followLive(provided, live, resource, setOpen) {
65
65
  };
66
66
  const socket = provided ?? realtime.client;
67
67
  if (socket) start(socket);
68
- else import("./RealtimeClient-CLXePUcE.js").then((module) => start(loadedModule(module).tabClient())).catch(() => {});
68
+ else import("./RealtimeClient-D4qIHPf1.js").then((module) => start(loadedModule(module).tabClient())).catch(() => {});
69
69
  return () => {
70
70
  stop?.();
71
71
  stop = null;
@@ -74,4 +74,4 @@ function followLive(provided, live, resource, setOpen) {
74
74
  //#endregion
75
75
  export { live_exports as n, followLive as t };
76
76
 
77
- //# sourceMappingURL=live-Dz_rk7fm.js.map
77
+ //# sourceMappingURL=live-9IXFtoGy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"live-Dz_rk7fm.js","names":[],"sources":["../../client/realtime/live.ts"],"sourcesContent":["import type { QueryResource } from \"../QueryResource\";\nimport type { ChannelPattern } from \"../useChannel\";\nimport { EVENT_COALESCE_MS } from \"./useChannelSubscription\";\nimport type { ChannelParamValues, RealtimeSocket } from \"./RealtimeClient\";\nimport { loadedModule } from \"../lazyModule\";\nimport { realtime } from \"./loader\";\n\n/**\n * `useQuery`'s `live` option: the channel whose events and resyncs refetch\n * the query. A pattern without params (`\"user\"`), `[pattern, params]`, or\n * `{ channel, params }`.\n */\nexport type LiveChannel =\n | ChannelPattern\n | readonly [ChannelPattern, ChannelParamValues]\n | { channel: ChannelPattern; params?: ChannelParamValues };\n\nexport function resolveLiveChannel(\n live: LiveChannel | null | undefined | false,\n): { pattern: string; params: ChannelParamValues } | null {\n if (!live) return null;\n if (typeof live === \"string\") return { pattern: live, params: {} };\n if (Array.isArray(live)) return { pattern: live[0], params: live[1] ?? {} };\n const object = live as { channel: string; params?: ChannelParamValues };\n return { pattern: object.channel, params: object.params ?? {} };\n}\n\n/**\n * `useQuery`'s `live` subscription, loaded on first use by `followLive` in\n * `./loader` (#891). The channel's events refetch every cached variant of the\n * query (the rendered ones now), a burst of them once per\n * `EVENT_COALESCE_MS`; a resync refetches at once. `setOpen` follows whether\n * the channel is open, which pauses the query's polling.\n */\nexport function subscribeLive(\n socket: RealtimeSocket,\n live: LiveChannel,\n resource: () => QueryResource,\n setOpen: (open: boolean) => void,\n): () => void {\n const channel = resolveLiveChannel(live);\n if (!channel) return () => {};\n const refresh = () => {\n const target = resource();\n for (const key of target.variantKeys()) target.invalidate(key);\n };\n let timer: ReturnType<typeof setTimeout> | null = null;\n const release = socket.subscribe(channel.pattern, channel.params, {\n onEvent: () => {\n if (timer) return;\n timer = setTimeout(() => {\n timer = null;\n refresh();\n }, EVENT_COALESCE_MS);\n },\n onResync: refresh,\n onStatus: (status) => setOpen(status === \"open\"),\n });\n return () => {\n if (timer) clearTimeout(timer);\n release();\n };\n}\n\n/**\n * What `followLive` in `./loader` hands over to once this module is loaded:\n * subscribes on the provided socket, or the tab's client, loading that first\n * when it is not there yet. Returns the function that stops it.\n */\nexport function followLive(\n provided: RealtimeSocket | null,\n live: LiveChannel,\n resource: () => QueryResource,\n setOpen: (open: boolean) => void,\n): () => void {\n // `undefined` until it subscribes, `null` once stopped.\n let stop: (() => void) | null | undefined;\n const start = (socket: RealtimeSocket) => {\n if (stop === undefined) stop = subscribeLive(socket, live, resource, setOpen);\n };\n const socket = provided ?? realtime.client;\n if (socket) start(socket);\n // Its own `import()` of the client rather than `loadRealtimeClient`, which\n // would keep that in the entry chunk of every app with a `useQuery`. A\n // failed load leaves the channel closed, so the query keeps polling.\n else\n import(\"./RealtimeClient.js\")\n .then((module) => start(loadedModule(module).tabClient()))\n .catch(() => {});\n return () => {\n stop?.();\n stop = null;\n };\n}\n"],"mappings":";;;;;;;;AAiBA,SAAgB,mBACd,MACwD;CACxD,IAAI,CAAC,MAAM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ts"],"sourcesContent":["import type { QueryResource } from \"../QueryResource\";\nimport type { ChannelPattern } from \"../useChannel\";\nimport { EVENT_COALESCE_MS } from \"./useChannelSubscription\";\nimport type { ChannelParamValues, RealtimeSocket } from \"./RealtimeClient\";\nimport { loadedModule } from \"../lazyModule\";\nimport { realtime } from \"./loader\";\n\n/**\n * `useQuery`'s `live` option: the channel whose events and resyncs refetch\n * the query. A pattern without params (`\"user\"`), `[pattern, params]`, or\n * `{ channel, params }`.\n */\nexport type LiveChannel =\n | ChannelPattern\n | readonly [ChannelPattern, ChannelParamValues]\n | { channel: ChannelPattern; params?: ChannelParamValues };\n\nexport function resolveLiveChannel(\n live: LiveChannel | null | undefined | false,\n): { pattern: string; params: ChannelParamValues } | null {\n if (!live) return null;\n if (typeof live === \"string\") return { pattern: live, params: {} };\n if (Array.isArray(live)) return { pattern: live[0], params: live[1] ?? {} };\n const object = live as { channel: string; params?: ChannelParamValues };\n return { pattern: object.channel, params: object.params ?? {} };\n}\n\n/**\n * `useQuery`'s `live` subscription, loaded on first use by `followLive` in\n * `./loader` (#891). The channel's events refetch every cached variant of the\n * query (the rendered ones now), a burst of them once per\n * `EVENT_COALESCE_MS`; a resync refetches at once. `setOpen` follows whether\n * the channel is open, which pauses the query's polling.\n */\nexport function subscribeLive(\n socket: RealtimeSocket,\n live: LiveChannel,\n resource: () => QueryResource,\n setOpen: (open: boolean) => void,\n): () => void {\n const channel = resolveLiveChannel(live);\n if (!channel) return () => {};\n const refresh = () => {\n const target = resource();\n for (const key of target.variantKeys()) target.invalidate(key);\n };\n let timer: ReturnType<typeof setTimeout> | null = null;\n const release = socket.subscribe(channel.pattern, channel.params, {\n onEvent: () => {\n if (timer) return;\n timer = setTimeout(() => {\n timer = null;\n refresh();\n }, EVENT_COALESCE_MS);\n },\n onResync: refresh,\n onStatus: (status) => setOpen(status === \"open\"),\n });\n return () => {\n if (timer) clearTimeout(timer);\n release();\n };\n}\n\n/**\n * What `followLive` in `./loader` hands over to once this module is loaded:\n * subscribes on the provided socket, or the tab's client, loading that first\n * when it is not there yet. Returns the function that stops it.\n */\nexport function followLive(\n provided: RealtimeSocket | null,\n live: LiveChannel,\n resource: () => QueryResource,\n setOpen: (open: boolean) => void,\n): () => void {\n // `undefined` until it subscribes, `null` once stopped.\n let stop: (() => void) | null | undefined;\n const start = (socket: RealtimeSocket) => {\n if (stop === undefined) stop = subscribeLive(socket, live, resource, setOpen);\n };\n const socket = provided ?? realtime.client;\n if (socket) start(socket);\n // Its own `import()` of the client rather than `loadRealtimeClient`, which\n // would keep that in the entry chunk of every app with a `useQuery`. A\n // failed load leaves the channel closed, so the query keeps polling.\n else\n import(\"./RealtimeClient.js\")\n .then((module) => start(loadedModule(module).tabClient()))\n .catch(() => {});\n return () => {\n stop?.();\n stop = null;\n };\n}\n"],"mappings":";;;;;;;;AAiBA,SAAgB,mBACd,MACwD;CACxD,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,OAAO,SAAS,UAAU,OAAO;EAAE,SAAS;EAAM,QAAQ,CAAC;CAAE;CACjE,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO;EAAE,SAAS,KAAK;EAAI,QAAQ,KAAK,MAAM,CAAC;CAAE;CAC1E,MAAM,SAAS;CACf,OAAO;EAAE,SAAS,OAAO;EAAS,QAAQ,OAAO,UAAU,CAAC;CAAE;AAChE;;;;;;;;AASA,SAAgB,cACd,QACA,MACA,UACA,SACY;CACZ,MAAM,UAAU,mBAAmB,IAAI;CACvC,IAAI,CAAC,SAAS,aAAa,CAAC;CAC5B,MAAM,gBAAgB;EACpB,MAAM,SAAS,SAAS;EACxB,KAAK,MAAM,OAAO,OAAO,YAAY,GAAG,OAAO,WAAW,GAAG;CAC/D;CACA,IAAI,QAA8C;CAClD,MAAM,UAAU,OAAO,UAAU,QAAQ,SAAS,QAAQ,QAAQ;EAChE,eAAe;GACb,IAAI,OAAO;GACX,QAAQ,iBAAiB;IACvB,QAAQ;IACR,QAAQ;GACV,GAAA,GAAoB;EACtB;EACA,UAAU;EACV,WAAW,WAAW,QAAQ,WAAW,MAAM;CACjD,CAAC;CACD,aAAa;EACX,IAAI,OAAO,aAAa,KAAK;EAC7B,QAAQ;CACV;AACF;;;;;;AAOA,SAAgB,WACd,UACA,MACA,UACA,SACY;CAEZ,IAAI;CACJ,MAAM,SAAS,WAA2B;EACxC,IAAI,SAAS,KAAA,GAAW,OAAO,cAAc,QAAQ,MAAM,UAAU,OAAO;CAC9E;CACA,MAAM,SAAS,YAAY,SAAS;CACpC,IAAI,QAAQ,MAAM,MAAM;MAKtB,OAAO,+BAAsB,CAC1B,MAAM,WAAW,MAAM,aAAa,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CACzD,YAAY,CAAC,CAAC;CACnB,aAAa;EACX,OAAO;EACP,OAAO;CACT;AACF"}
@@ -1,4 +1,4 @@
1
- import { $ as applyParams, Q as toVariantKey } from "./ThemeProvider-COjYIalw.js";
1
+ import { $ as applyParams, Q as toVariantKey } from "./ThemeProvider-w_axEu6B.js";
2
2
  import { p as mutationErrorFromBody, s as isObject } from "./MutationError-DuKqBW8o.js";
3
3
  //#region client/mutationErrorHelpers.ts
4
4
  var FALLBACK_MESSAGE = "Something went wrong. Try again.";
@@ -112,4 +112,4 @@ function applyQueryUpdates(getResource, routeParams, updates, answer) {
112
112
  //#endregion
113
113
  export { applyQueryUpdates, withMutationErrorHelpers, writeQueryData };
114
114
 
115
- //# sourceMappingURL=mutationExtras-DtSw6BcX.js.map
115
+ //# sourceMappingURL=mutationExtras-bNF9JOSk.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mutationExtras-DtSw6BcX.js","names":[],"sources":["../../client/mutationErrorHelpers.ts","../../client/queryUpdates.ts"],"sourcesContent":["import {\n isObject,\n mutationErrorFromBody,\n type MutationErrorHelpers,\n type MutationValidationError,\n type WithMutationErrorHelpers,\n} from \"./MutationError\";\n\n// `error.list()` and `error.field(name)` on what the mutation hooks hand over.\n// Loaded with the hooks' other extras when one mounts (see\n// `./mutationModules`), so no route's entry chunk carries it (#915).\n//\n// `list` and `field` repeat `mutationErrorList` and `mutationErrorField` from\n// `./MutationError` on purpose. Those are public and synchronous, so they sit\n// in whatever chunk calls them; importing them here would put them, and so\n// this code, back in every entry chunk. `MutationError.helpers.test` runs the\n// same cases through both.\n\nconst FALLBACK_MESSAGE = \"Something went wrong. Try again.\";\n\n// `isValidationError`, which an import would keep in the entry chunk.\nfunction isValidationError(error: unknown): error is MutationValidationError {\n return isObject(error) && error.kind === \"validation_error\";\n}\n\n// A `QueryError`'s refusal, read as the mutation hooks read a body. Read by\n// shape, not `instanceof`, so a copy of the class from another bundle works.\nfunction unwrapQueryError(error: unknown): unknown {\n if (error instanceof Error && error.name === \"QueryError\" && \"body\" in error) {\n const { body, status } = error as Error & { body: unknown; status: number };\n return body == null ? error : mutationErrorFromBody(body, status);\n }\n return error;\n}\n\n// `error.list(fallback)`: see `mutationErrorList`.\nfunction list(\n error: unknown,\n fallback: string = FALLBACK_MESSAGE,\n): string[] {\n const value = unwrapQueryError(error);\n if (isValidationError(value)) {\n const messages = Object.values(value.messages ?? {})\n .flat()\n .filter((message) => typeof message === \"string\" && message !== \"\");\n return messages.length > 0 ? messages : [fallback];\n }\n if (\n isObject(value) &&\n !(value instanceof Error) &&\n value.kind !== \"server_error\" &&\n typeof value.message === \"string\" &&\n value.message !== \"\"\n ) {\n return [value.message];\n }\n return [fallback];\n}\n\n// `error.field(name)`: see `mutationErrorField`.\nfunction field(error: unknown, name: string): string[] {\n const value = unwrapQueryError(error);\n if (!isValidationError(value)) return [];\n const messages = value.messages?.[name];\n return Array.isArray(messages) ? [...messages] : [];\n}\n\n/**\n * Puts `list` and `field` on an error the hooks hand over, as non-enumerable\n * properties, so `toEqual`, a spread and `JSON.stringify` see the same object\n * as before. A key the error already has is left alone; a primitive or a\n * frozen value is returned as it is.\n *\n * @internal\n */\nexport function withMutationErrorHelpers<T>(error: T): WithMutationErrorHelpers<T> {\n if (!isObject(error) || !Object.isExtensible(error)) {\n return error as WithMutationErrorHelpers<T>;\n }\n const helpers: MutationErrorHelpers = {\n list: (fallback) => list(error, fallback),\n field: (name) => field(error, name),\n };\n for (const key of [\"list\", \"field\"] as const) {\n if (key in error) continue;\n Object.defineProperty(error, key, {\n value: helpers[key],\n configurable: true,\n writable: true,\n enumerable: false,\n });\n }\n return error as WithMutationErrorHelpers<T>;\n}\n","import type { QueryResource } from \"./QueryResource\";\nimport type { QueryTarget, QueryUpdate } from \"./useSetQueryData\";\nimport { applyParams } from \"../utils/applyParams\";\nimport { toVariantKey } from \"../utils/variantKey\";\n\n// The cache writes behind a mutation's `updates` and `useSetQueryData()`\n// (#897). Loaded with the hooks' other extras when one mounts (see\n// `./mutationModules`), so no route's entry chunk carries it (#915).\n\ntype Resolve = (key: string) => QueryResource;\n\n/**\n * Write data the server just produced (a mutation's answer) into a variant,\n * with no refetch: unlike `mutate`, the value is not a guess to reconcile.\n * The variant counts as freshly fetched, so its `staleTime` starts again, and\n * a GET already on the wire for it is dropped when it lands, since it may\n * carry the data from before the write. A reader suspended on the variant\n * wakes up with it (#897). Here rather than on `QueryResource`, which every\n * entry chunk carries (#915).\n */\nfunction setVariant(resource: QueryResource, variantKey: string, data: unknown) {\n resource.dropHttpCache(variantKey);\n resource.markApplied(variantKey);\n const store = resource.store.getValue();\n resource.fill(store, variantKey, data, Date.now());\n resource.store.next(store);\n}\n\n/** The value to write, or a function of the cached one. */\nexport type WriteQueryNext = { value: unknown } | { update: (current: any) => unknown };\n\n/**\n * Write into every variant `target` names. `next` is the value to write, or\n * a function of the cached value; a function skips a variant with nothing\n * cached. A value seeds a single variant that is not cached yet; a predicate\n * only ever reaches variants that are.\n */\nexport function writeQueryData(\n getResource: Resolve,\n routeParams: Record<string, any>,\n target: QueryTarget<any>,\n next: WriteQueryNext,\n) {\n const { path, params = {}, search = {} } = target;\n const resource = getResource(applyParams(String(path), { ...routeParams, ...params }));\n const write = (variantKey: string) => {\n if (\"value\" in next) {\n setVariant(resource, variantKey, next.value);\n return;\n }\n const state = resource.peek(variantKey);\n if (!state?.hasData) return;\n setVariant(resource, variantKey, next.update(state.data));\n };\n\n if (typeof search === \"function\") {\n for (const variantKey of resource.variantKeys()) {\n if (!resource.peek(variantKey)?.hasData) continue;\n if (search(new URLSearchParams(variantKey))) write(variantKey);\n }\n return;\n }\n write(toVariantKey(search));\n}\n\n/**\n * Write a mutation's `updates` with its answer.\n */\nexport function applyQueryUpdates(\n getResource: Resolve,\n routeParams: Record<string, any>,\n updates: ReadonlyArray<QueryUpdate<any>> | undefined,\n answer: unknown,\n) {\n for (const update of updates ?? []) {\n const { data } = update as { data?: (answer: any, current: any) => any };\n writeQueryData(\n getResource,\n routeParams,\n update,\n data ? { update: (current) => data(answer, current) } : { value: answer },\n );\n }\n}\n"],"mappings":";;;AAkBA,IAAM,mBAAmB;AAGzB,SAAS,kBAAkB,OAAkD;CAC3E,OAAO,SAAS,KAAK,KAAK,MAAM,SAAS;AAC3C;AAIA,SAAS,iBAAiB,OAAyB;CACjD,IAAI,iBAAiB,SAAS,MAAM,SAAS,gBAAgB,UAAU,OAAO;EAC5E,MAAM,EAAE,MAAM,WAAW;EACzB,OAAO,QAAQ,OAAO,QAAQ,sBAAsB,MAAM,MAAM;CAClE;CACA,OAAO;AACT;AAGA,SAAS,KACP,OACA,WAAmB,kBACT;CACV,MAAM,QAAQ,iBAAiB,KAAK;CACpC,IAAI,kBAAkB,KAAK,GAAG;EAC5B,MAAM,WAAW,OAAO,OAAO,MAAM,YAAY,CAAC,CAAC,CAAC,CACjD,KAAK,CAAC,CACN,QAAQ,YAAY,OAAO,YAAY,YAAY,YAAY,EAAE;EACpE,OAAO,SAAS,SAAS,IAAI,WAAW,CAAC,QAAQ;CACnD;CACA,IACE,SAAS,KAAK,KACd,EAAE,iBAAiB,UACnB,MAAM,SAAS,kBACf,OAAO,MAAM,YAAY,YACzB,MAAM,YAAY,IAElB,OAAO,CAAC,MAAM,OAAO;CAEvB,OAAO,CAAC,QAAQ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AU,YAAY,KAAK,OAAO,MAAM,IAAI,CAAC;CAC1D;CAEA,IAAI,OAAO,WAAW,YAAY;EAChC,KAAK,MAAM,cAAc,SAAS,YAAY,GAAG;GAC/C,IAAI,CAAC,SAAS,KAAK,UAAU,CAAC,EAAE,SAAS;GACzC,IAAI,OAAO,IAAI,gBAAgB,UAAU,CAAC,GAAG,MAAM,UAAU;EAC/D;EACA;CACF;CACA,MAAM,aAAa,MAAM,CAAC;AAC5B;;;;AAKA,SAAgB,kBACd,aACA,aACA,SACA,QACA;CACA,KAAK,MAAM,UAAU,WAAW,CAAC,GAAG;EAClC,MAAM,EAAE,SAAS;EACjB,eACE,aACA,aACA,QACA,OAAO,EAAE,SAAS,YAAY,KAAK,QAAQ,OAAO,EAAE,IAAI,EAAE,OAAO,OAAO,CAC1E;CACF;AACF"}
1
+ {"version":3,"file":"mutationExtras-bNF9JOSk.js","names":[],"sources":["../../client/mutationErrorHelpers.ts","../../client/queryUpdates.ts"],"sourcesContent":["import {\n isObject,\n mutationErrorFromBody,\n type MutationErrorHelpers,\n type MutationValidationError,\n type WithMutationErrorHelpers,\n} from \"./MutationError\";\n\n// `error.list()` and `error.field(name)` on what the mutation hooks hand over.\n// Loaded with the hooks' other extras when one mounts (see\n// `./mutationModules`), so no route's entry chunk carries it (#915).\n//\n// `list` and `field` repeat `mutationErrorList` and `mutationErrorField` from\n// `./MutationError` on purpose. Those are public and synchronous, so they sit\n// in whatever chunk calls them; importing them here would put them, and so\n// this code, back in every entry chunk. `MutationError.helpers.test` runs the\n// same cases through both.\n\nconst FALLBACK_MESSAGE = \"Something went wrong. Try again.\";\n\n// `isValidationError`, which an import would keep in the entry chunk.\nfunction isValidationError(error: unknown): error is MutationValidationError {\n return isObject(error) && error.kind === \"validation_error\";\n}\n\n// A `QueryError`'s refusal, read as the mutation hooks read a body. Read by\n// shape, not `instanceof`, so a copy of the class from another bundle works.\nfunction unwrapQueryError(error: unknown): unknown {\n if (error instanceof Error && error.name === \"QueryError\" && \"body\" in error) {\n const { body, status } = error as Error & { body: unknown; status: number };\n return body == null ? error : mutationErrorFromBody(body, status);\n }\n return error;\n}\n\n// `error.list(fallback)`: see `mutationErrorList`.\nfunction list(\n error: unknown,\n fallback: string = FALLBACK_MESSAGE,\n): string[] {\n const value = unwrapQueryError(error);\n if (isValidationError(value)) {\n const messages = Object.values(value.messages ?? {})\n .flat()\n .filter((message) => typeof message === \"string\" && message !== \"\");\n return messages.length > 0 ? messages : [fallback];\n }\n if (\n isObject(value) &&\n !(value instanceof Error) &&\n value.kind !== \"server_error\" &&\n typeof value.message === \"string\" &&\n value.message !== \"\"\n ) {\n return [value.message];\n }\n return [fallback];\n}\n\n// `error.field(name)`: see `mutationErrorField`.\nfunction field(error: unknown, name: string): string[] {\n const value = unwrapQueryError(error);\n if (!isValidationError(value)) return [];\n const messages = value.messages?.[name];\n return Array.isArray(messages) ? [...messages] : [];\n}\n\n/**\n * Puts `list` and `field` on an error the hooks hand over, as non-enumerable\n * properties, so `toEqual`, a spread and `JSON.stringify` see the same object\n * as before. A key the error already has is left alone; a primitive or a\n * frozen value is returned as it is.\n *\n * @internal\n */\nexport function withMutationErrorHelpers<T>(error: T): WithMutationErrorHelpers<T> {\n if (!isObject(error) || !Object.isExtensible(error)) {\n return error as WithMutationErrorHelpers<T>;\n }\n const helpers: MutationErrorHelpers = {\n list: (fallback) => list(error, fallback),\n field: (name) => field(error, name),\n };\n for (const key of [\"list\", \"field\"] as const) {\n if (key in error) continue;\n Object.defineProperty(error, key, {\n value: helpers[key],\n configurable: true,\n writable: true,\n enumerable: false,\n });\n }\n return error as WithMutationErrorHelpers<T>;\n}\n","import type { QueryResource } from \"./QueryResource\";\nimport type { QueryTarget, QueryUpdate } from \"./useSetQueryData\";\nimport { applyParams } from \"../utils/applyParams\";\nimport { toVariantKey } from \"../utils/variantKey\";\n\n// The cache writes behind a mutation's `updates` and `useSetQueryData()`\n// (#897). Loaded with the hooks' other extras when one mounts (see\n// `./mutationModules`), so no route's entry chunk carries it (#915).\n\ntype Resolve = (key: string) => QueryResource;\n\n/**\n * Write data the server just produced (a mutation's answer) into a variant,\n * with no refetch: unlike `mutate`, the value is not a guess to reconcile.\n * The variant counts as freshly fetched, so its `staleTime` starts again, and\n * a GET already on the wire for it is dropped when it lands, since it may\n * carry the data from before the write. A reader suspended on the variant\n * wakes up with it (#897). Here rather than on `QueryResource`, which every\n * entry chunk carries (#915).\n */\nfunction setVariant(resource: QueryResource, variantKey: string, data: unknown) {\n resource.dropHttpCache(variantKey);\n resource.markApplied(variantKey);\n const store = resource.store.getValue();\n resource.fill(store, variantKey, data, Date.now());\n resource.store.next(store);\n}\n\n/** The value to write, or a function of the cached one. */\nexport type WriteQueryNext = { value: unknown } | { update: (current: any) => unknown };\n\n/**\n * Write into every variant `target` names. `next` is the value to write, or\n * a function of the cached value; a function skips a variant with nothing\n * cached. A value seeds a single variant that is not cached yet; a predicate\n * only ever reaches variants that are.\n */\nexport function writeQueryData(\n getResource: Resolve,\n routeParams: Record<string, any>,\n target: QueryTarget<any>,\n next: WriteQueryNext,\n) {\n const { path, params = {}, search = {} } = target;\n const resource = getResource(applyParams(String(path), { ...routeParams, ...params }));\n const write = (variantKey: string) => {\n if (\"value\" in next) {\n setVariant(resource, variantKey, next.value);\n return;\n }\n const state = resource.peek(variantKey);\n if (!state?.hasData) return;\n setVariant(resource, variantKey, next.update(state.data));\n };\n\n if (typeof search === \"function\") {\n for (const variantKey of resource.variantKeys()) {\n if (!resource.peek(variantKey)?.hasData) continue;\n if (search(new URLSearchParams(variantKey))) write(variantKey);\n }\n return;\n }\n write(toVariantKey(search));\n}\n\n/**\n * Write a mutation's `updates` with its answer.\n */\nexport function applyQueryUpdates(\n getResource: Resolve,\n routeParams: Record<string, any>,\n updates: ReadonlyArray<QueryUpdate<any>> | undefined,\n answer: unknown,\n) {\n for (const update of updates ?? []) {\n const { data } = update as { data?: (answer: any, current: any) => any };\n writeQueryData(\n getResource,\n routeParams,\n update,\n data ? { update: (current) => data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,OAAO,EAAE,IAAI,EAAE,OAAO,OAAO,CAC1E;CACF;AACF"}
@@ -1,4 +1,4 @@
1
- import { mt as equalJitter } from "./ThemeProvider-COjYIalw.js";
1
+ import { mt as equalJitter } from "./ThemeProvider-w_axEu6B.js";
2
2
  //#region client/subscriptionStream.ts
3
3
  var MIN_RETRY_MS = 1e3;
4
4
  var MAX_RETRY_MS = 3e4;
@@ -175,4 +175,4 @@ async function* readEvents(body) {
175
175
  //#endregion
176
176
  export { follow, readEvents };
177
177
 
178
- //# sourceMappingURL=subscriptionStream-CqhJOfPn.js.map
178
+ //# sourceMappingURL=subscriptionStream-D42DpDiZ.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"subscriptionStream-CqhJOfPn.js","names":[],"sources":["../../client/subscriptionStream.ts"],"sourcesContent":["import type { Dispatch, SetStateAction } from \"react\";\n\nimport type { ChangeFeedMessage } from \"../services/change-feed/wire\";\nimport { equalJitter } from \"./retryPolicy\";\nimport type { SubscriptionConfig, SubscriptionStatus } from \"./useSubscription\";\n\n// `useSubscription`'s connection: the SSE request, its reader and the\n// reconnect loop. Loaded by the hook with a dynamic `import()` when it first\n// connects, so it lands in a chunk of its own rather than in the entry chunk\n// every route loads (#891). Import it as a type only from anywhere else.\n\nconst MIN_RETRY_MS = 1_000;\nconst MAX_RETRY_MS = 30_000;\n\n/** The server answered in a way retrying will not change (401, 403, 404). */\nclass FatalStatus extends Error {\n constructor(readonly status: number) {\n super(`The subscription was refused with ${status}.`);\n }\n}\n\nexport interface SubscriptionState {\n status: SubscriptionStatus;\n cursor: string | null;\n error: Error | null;\n}\n\nexport interface FollowOptions {\n endpoint: string;\n pauseWhenHidden: boolean;\n /** Where to resume; advanced as events arrive. */\n cursor: { current: string | null };\n callbacks: { current: SubscriptionConfig<unknown> };\n setState: Dispatch<SetStateAction<SubscriptionState>>;\n /** The jitter's random source; `Math.random` unless a test passes its own. */\n random?: () => number;\n}\n\n/**\n * Follows `endpoint` until the returned function is called: connects,\n * reconnects with backoff, pauses while the tab is hidden, and reports\n * through `setState` and `callbacks`.\n *\n * The backoff step is 1s, doubling per failed attempt up to 30s, and back to\n * 1s once a stream reaches `ready`. Each wait is jittered (\"equal jitter\", a\n * random point between half the step and all of it): a server restart ends\n * every open tab's stream in the same instant, and an exact schedule would\n * bring them all back in the same instant too. A `Retry-After` the server\n * sent is waited out exactly.\n */\nexport function follow({\n endpoint,\n pauseWhenHidden,\n cursor,\n callbacks,\n setState,\n random = Math.random,\n}: FollowOptions): () => void {\n let stopped = false;\n let request: AbortController | null = null;\n let resume: (() => void) | null = null;\n let retryMs = MIN_RETRY_MS;\n const hidden = () =>\n pauseWhenHidden && typeof document !== \"undefined\" && document.visibilityState === \"hidden\";\n const onVisibilityChange = () => {\n if (hidden()) request?.abort();\n else resume?.();\n };\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", onVisibilityChange);\n }\n const wait = (ms: number) =>\n new Promise<void>((resolve) => {\n const timer = setTimeout(done, ms);\n function done() {\n clearTimeout(timer);\n resume = null;\n resolve();\n }\n // Shown again, or unmounted: stop waiting.\n resume = done;\n });\n\n void (async () => {\n while (!stopped) {\n if (hidden()) {\n setState((s) => ({ ...s, status: \"paused\" }));\n await new Promise<void>((resolve) => (resume = resolve));\n resume = null;\n continue;\n }\n setState((s) => ({ ...s, status: \"connecting\" }));\n const controller = (request = new AbortController());\n let delay = retryMs;\n let exact = false;\n try {\n const headers: Record<string, string> = { Accept: \"text/event-stream\" };\n if (cursor.current) headers[\"Last-Event-ID\"] = cursor.current;\n const response = await fetch(endpoint, { headers, signal: controller.signal });\n if (!response.ok || !response.body) {\n const status = response.status;\n if (status >= 400 && status < 500 && status !== 408 && status !== 429) {\n throw new FatalStatus(status);\n }\n const retryAfter = Number(response.headers.get(\"Retry-After\"));\n if (Number.isFinite(retryAfter) && retryAfter > 0) {\n delay = retryAfter * 1000;\n exact = true;\n }\n throw new Error(`The subscription answered ${status}.`);\n }\n for await (const { id, message } of readEvents(response.body)) {\n if (stopped) return;\n if (id !== undefined) cursor.current = id;\n if (message.type === \"ready\") {\n retryMs = MIN_RETRY_MS;\n delay = MIN_RETRY_MS;\n setState({ status: \"open\", cursor: cursor.current, error: null });\n } else {\n setState((s) => ({ ...s, cursor: cursor.current }));\n if (message.type === \"change\") callbacks.current.onChange?.(message as never);\n else if (message.type === \"reset\") callbacks.current.onReset?.(message as never);\n }\n }\n } catch (error) {\n if (stopped) return;\n if (error instanceof FatalStatus) {\n setState((s) => ({ ...s, status: \"closed\", error }));\n return;\n }\n // Aborted because the tab was hidden: the loop pauses instead.\n if (controller.signal.aborted) continue;\n setState((s) => ({ ...s, error: error as Error }));\n }\n if (stopped || controller.signal.aborted) continue;\n // The stream ended or failed: try again, a little later each time.\n setState((s) => ({ ...s, status: \"connecting\" }));\n await wait(exact ? delay : equalJitter(delay, random));\n retryMs = Math.min(retryMs * 2, MAX_RETRY_MS);\n }\n })();\n\n return () => {\n stopped = true;\n request?.abort();\n resume?.();\n if (typeof document !== \"undefined\") {\n document.removeEventListener(\"visibilitychange\", onVisibilityChange);\n }\n };\n}\n\n/**\n * The events of an SSE body: `id` and the JSON `data`. Comments (keepalives)\n * and events without data are skipped; an event whose data is not JSON is\n * dropped rather than ending the stream.\n */\nexport async function* readEvents(\n body: ReadableStream<Uint8Array>,\n): AsyncGenerator<{ id?: string; message: ChangeFeedMessage }> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) return;\n // `ChangeFeed.stream` writes `\\n` only; a proxy's `\\r\\n` is folded here.\n buffer = (buffer + decoder.decode(value, { stream: true })).replace(/\\r\\n?/g, \"\\n\");\n let boundary = buffer.indexOf(\"\\n\\n\");\n while (boundary !== -1) {\n const block = buffer.slice(0, boundary);\n buffer = buffer.slice(boundary + 2);\n boundary = buffer.indexOf(\"\\n\\n\");\n let id: string | undefined;\n const data: string[] = [];\n for (const line of block.split(\"\\n\")) {\n if (line === \"\" || line.startsWith(\":\")) continue;\n const colon = line.indexOf(\":\");\n const field = colon === -1 ? line : line.slice(0, colon);\n let text = colon === -1 ? \"\" : line.slice(colon + 1);\n if (text.startsWith(\" \")) text = text.slice(1);\n if (field === \"id\") id = text;\n else if (field === \"data\") data.push(text);\n }\n if (data.length === 0) continue;\n try {\n yield { id, message: JSON.parse(data.join(\"\\n\")) };\n } catch {\n // Not JSON: not ours to apply.\n }\n }\n }\n } finally {\n await reader.cancel().catch(() => {});\n }\n}\n"],"mappings":";;AAWA,IAAM,eAAe;AACrB,IAAM,eAAe;;AAGrB,IAAM,cAAN,cAA0B,MAAM;CACT;CAArB,YAAY,QAAyB;EACnC,MAAM,qCAAqC,OAAO,EAAE;EADjC,KAAA,SAAA;CAErB;AACF;;;;;;;;;;;;;AA+BA,SAAgB,OAAO,EACrB,UACA,iBACA,QACA,WACA,UACA,SAAS,KAAK,UACc;CAC5B,IAAI,UAAU;CACd,IAAI,UAAkC;CACtC,IAAI,SAA8B;CAClC,IAAI,UAAU;CACd,MAAM,eACJ,mBAAmB,OAAO,aAAa,eAAe,SAAS,oBAAoB;CACrF,MAAM,2BAA2B;EAC/B,IAAI,OAAO,GAAG,SAAS,MAAM;OACxB,SAAS;CAChB;CACA,IAAI,OAAO,aAAa,aACtB,SAAS,iBAAiB,oBAAoB,kBAAkB;CAElE,MAAM,QAAQ,OACZ,IAAI,SAAe,YAAY;EAC7B,MAAM,QAAQ,WAAW,MAAM,EAAE;EACjC,SAAS,OAAO;GACd,aAAa,KAAK;GAClB,SAAS;GACT,QAAQ;EACV;EAEA,SAAS;CACX,CAAC;CAEH,CAAM,YAAY;EAChB,OAAO,CAAC,SAAS;GACf,IAAI,OAAO,GAAG;IACZ,UAAU,OAAO;KAAE,GAAG;KAAG,QAAQ;IAAS,EAAE;IAC5C,MAAM,IAAI,SAAe,YAAa,SAAS,OAAQ;IACvD,SAAS;IACT;GACF;GACA,UAAU,OAAO;IAAE,GAAG;IAAG,QAAQ;GAAa,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,IAAI,UAAU,QAAQ,KAAK,KAAK,IAAI;IAC3C;IACA,IAAI,KAAK,WAAW,GAAG;IACvB,IAAI;KACF,MAAM;MAAE;MAAI,SAAS,KAAK,MAAM,KAAK,KAAK,IAAI,CAAC;KAAE;IACnD,QAAQ,CAER;GACF;EACF;CACF,UAAU;EACR,MAAM,OAAO,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC;CACtC;AACF"}
1
+ {"version":3,"file":"subscriptionStream-D42DpDiZ.js","names":[],"sources":["../../client/subscriptionStream.ts"],"sourcesContent":["import type { Dispatch, SetStateAction } from \"react\";\n\nimport type { ChangeFeedMessage } from \"../services/change-feed/wire\";\nimport { equalJitter } from \"./retryPolicy\";\nimport type { SubscriptionConfig, SubscriptionStatus } from \"./useSubscription\";\n\n// `useSubscription`'s connection: the SSE request, its reader and the\n// reconnect loop. Loaded by the hook with a dynamic `import()` when it first\n// connects, so it lands in a chunk of its own rather than in the entry chunk\n// every route loads (#891). Import it as a type only from anywhere else.\n\nconst MIN_RETRY_MS = 1_000;\nconst MAX_RETRY_MS = 30_000;\n\n/** The server answered in a way retrying will not change (401, 403, 404). */\nclass FatalStatus extends Error {\n constructor(readonly status: number) {\n super(`The subscription was refused with ${status}.`);\n }\n}\n\nexport interface SubscriptionState {\n status: SubscriptionStatus;\n cursor: string | null;\n error: Error | null;\n}\n\nexport interface FollowOptions {\n endpoint: string;\n pauseWhenHidden: boolean;\n /** Where to resume; advanced as events arrive. */\n cursor: { current: string | null };\n callbacks: { current: SubscriptionConfig<unknown> };\n setState: Dispatch<SetStateAction<SubscriptionState>>;\n /** The jitter's random source; `Math.random` unless a test passes its own. */\n random?: () => number;\n}\n\n/**\n * Follows `endpoint` until the returned function is called: connects,\n * reconnects with backoff, pauses while the tab is hidden, and reports\n * through `setState` and `callbacks`.\n *\n * The backoff step is 1s, doubling per failed attempt up to 30s, and back to\n * 1s once a stream reaches `ready`. Each wait is jittered (\"equal jitter\", a\n * random point between half the step and all of it): a server restart ends\n * every open tab's stream in the same instant, and an exact schedule would\n * bring them all back in the same instant too. A `Retry-After` the server\n * sent is waited out exactly.\n */\nexport function follow({\n endpoint,\n pauseWhenHidden,\n cursor,\n callbacks,\n setState,\n random = Math.random,\n}: FollowOptions): () => void {\n let stopped = false;\n let request: AbortController | null = null;\n let resume: (() => void) | null = null;\n let retryMs = MIN_RETRY_MS;\n const hidden = () =>\n pauseWhenHidden && typeof document !== \"undefined\" && document.visibilityState === \"hidden\";\n const onVisibilityChange = () => {\n if (hidden()) request?.abort();\n else resume?.();\n };\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", onVisibilityChange);\n }\n const wait = (ms: number) =>\n new Promise<void>((resolve) => {\n const timer = setTimeout(done, ms);\n function done() {\n clearTimeout(timer);\n resume = null;\n resolve();\n }\n // Shown again, or unmounted: stop waiting.\n resume = done;\n });\n\n void (async () => {\n while (!stopped) {\n if (hidden()) {\n setState((s) => ({ ...s, status: \"paused\" }));\n await new Promise<void>((resolve) => (resume = resolve));\n resume = null;\n continue;\n }\n setState((s) => ({ ...s, status: \"connecting\" }));\n const controller = (request = new AbortController());\n let delay = retryMs;\n let exact = false;\n try {\n const headers: Record<string, string> = { Accept: \"text/event-stream\" };\n if (cursor.current) headers[\"Last-Event-ID\"] = cursor.current;\n const response = await fetch(endpoint, { headers, signal: controller.signal });\n if (!response.ok || !response.body) {\n const status = response.status;\n if (status >= 400 && status < 500 && status !== 408 && status !== 429) {\n throw new FatalStatus(status);\n }\n const retryAfter = Number(response.headers.get(\"Retry-After\"));\n if (Number.isFinite(retryAfter) && retryAfter > 0) {\n delay = retryAfter * 1000;\n exact = true;\n }\n throw new Error(`The subscription answered ${status}.`);\n }\n for await (const { id, message } of readEvents(response.body)) {\n if (stopped) return;\n if (id !== undefined) cursor.current = id;\n if (message.type === \"ready\") {\n retryMs = MIN_RETRY_MS;\n delay = MIN_RETRY_MS;\n setState({ status: \"open\", cursor: cursor.current, error: null });\n } else {\n setState((s) => ({ ...s, cursor: cursor.current }));\n if (message.type === \"change\") callbacks.current.onChange?.(message as never);\n else if (message.type === \"reset\") callbacks.current.onReset?.(message as never);\n }\n }\n } catch (error) {\n if (stopped) return;\n if (error instanceof FatalStatus) {\n setState((s) => ({ ...s, status: \"closed\", error }));\n return;\n }\n // Aborted because the tab was hidden: the loop pauses instead.\n if (controller.signal.aborted) continue;\n setState((s) => ({ ...s, error: error as Error }));\n }\n if (stopped || controller.signal.aborted) continue;\n // The stream ended or failed: try again, a little later each time.\n setState((s) => ({ ...s, status: \"connecting\" }));\n await wait(exact ? delay : equalJitter(delay, random));\n retryMs = Math.min(retryMs * 2, MAX_RETRY_MS);\n }\n })();\n\n return () => {\n stopped = true;\n request?.abort();\n resume?.();\n if (typeof document !== \"undefined\") {\n document.removeEventListener(\"visibilitychange\", onVisibilityChange);\n }\n };\n}\n\n/**\n * The events of an SSE body: `id` and the JSON `data`. Comments (keepalives)\n * and events without data are skipped; an event whose data is not JSON is\n * dropped rather than ending the stream.\n */\nexport async function* readEvents(\n body: ReadableStream<Uint8Array>,\n): AsyncGenerator<{ id?: string; message: ChangeFeedMessage }> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) return;\n // `ChangeFeed.stream` writes `\\n` only; a proxy's `\\r\\n` is folded here.\n buffer = (buffer + decoder.decode(value, { stream: true })).replace(/\\r\\n?/g, \"\\n\");\n let boundary = buffer.indexOf(\"\\n\\n\");\n while (boundary !== -1) {\n const block = buffer.slice(0, boundary);\n buffer = buffer.slice(boundary + 2);\n boundary = buffer.indexOf(\"\\n\\n\");\n let id: string | undefined;\n const data: string[] = [];\n for (const line of block.split(\"\\n\")) {\n if (line === \"\" || line.startsWith(\":\")) continue;\n const colon = line.indexOf(\":\");\n const field = colon === -1 ? line : line.slice(0, colon);\n let text = colon === -1 ? \"\" : line.slice(colon + 1);\n if (text.startsWith(\" \")) text = text.slice(1);\n if (field === \"id\") id = text;\n else if (field === \"data\") data.push(text);\n }\n if (data.length === 0) continue;\n try {\n yield { id, message: JSON.parse(data.join(\"\\n\")) };\n } catch {\n // Not JSON: not ours to apply.\n }\n }\n }\n } finally {\n await reader.cancel().catch(() => {});\n }\n}\n"],"mappings":";;AAWA,IAAM,eAAe;AACrB,IAAM,eAAe;;AAGrB,IAAM,cAAN,cAA0B,MAAM;CACT;CAArB,YAAY,QAAyB;EACnC,MAAM,qCAAqC,OAAO,EAAE;EADjC,KAAA,SAAA;CAErB;AACF;;;;;;;;;;;;;AA+BA,SAAgB,OAAO,EACrB,UACA,iBACA,QACA,WACA,UACA,SAAS,KAAK,UACc;CAC5B,IAAI,UAAU;CACd,IAAI,UAAkC;CACtC,IAAI,SAA8B;CAClC,IAAI,UAAU;CACd,MAAM,eACJ,mBAAmB,OAAO,aAAa,eAAe,SAAS,oBAAoB;CACrF,MAAM,2BAA2B;EAC/B,IAAI,OAAO,GAAG,SAAS,MAAM;OACxB,SAAS;CAChB;CACA,IAAI,OAAO,aAAa,aACtB,SAAS,iBAAiB,oBAAoB,kBAAkB;CAElE,MAAM,QAAQ,OACZ,IAAI,SAAe,YAAY;EAC7B,MAAM,QAAQ,WAAW,MAAM,EAAE;EACjC,SAAS,OAAO;GACd,aAAa,KAAK;GAClB,SAAS;GACT,QAAQ;EACV;EAEA,SAAS;CACX,CAAC;CAEH,CAAM,YAAY;EAChB,OAAO,CAAC,SAAS;GACf,IAAI,OAAO,GAAG;IACZ,UAAU,OAAO;KAAE,GAAG;KAAG,QAAQ;IAAS,EAAE;IAC5C,MAAM,IAAI,SAAe,YAAa,SAAS,OAAQ;IACvD,SAAS;IACT;GACF;GACA,UAAU,OAAO;IAAE,GAAG;IAAG,QAAQ;GAAa,EAAE;GAChD,MAAM,aAAc,UAAU,IAAI,gBAAgB;GAClD,IAAI,QAAQ;GACZ,IAAI,QAAQ;GACZ,IAAI;IACF,MAAM,UAAkC,EAAE,QAAQ,oBAAoB;IACtE,IAAI,OAAO,SA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E;IACnD,QAAQ,CAER;GACF;EACF;CACF,UAAU;EACR,MAAM,OAAO,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC;CACtC;AACF"}
@@ -68,7 +68,11 @@ export declare function pickAppWideQueryConfig(queryConfig: QueryConfig | null |
68
68
  export type PrefetchedData = Record<string, Record<string, any>>;
69
69
  export interface QueryManagerContextValue {
70
70
  getResource: (key: string, initialState?: Record<string, any>) => QueryResource;
71
- hydrate: (prefetchedData?: PrefetchedData | null) => void;
71
+ /**
72
+ * `streamed`: the data came from a streamed server payload, which readers
73
+ * that don't suspend leave out while hydrating (`peekForHydration`).
74
+ */
75
+ hydrate: (prefetchedData?: PrefetchedData | null, streamed?: boolean) => void;
72
76
  clearErrors: () => void;
73
77
  }
74
78
  export declare const QueryManagerContext: import("react").Context<QueryManagerContextValue>;
@@ -1 +1 @@
1
- {"version":3,"file":"QueryManagerContext.d.ts","sourceRoot":"","sources":["../../client/QueryManagerContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAGlB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAKnE;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;OAIG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,qEAAqE;IACrE,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAA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AAc,KAAK,IAAI,CAAC;IAC/C,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,YAAY,CAAC;CACtD;AAgBD,eAAO,MAAM,oBAAoB,GAAI,4BAGlC,iBAAiB,CAAC;IAAE,WAAW,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;CAAE,CAAC,4CAmDzD,CAAC"}
@@ -72,6 +72,13 @@ export declare class QueryResource {
72
72
  * disconnect through `req.signal`.
73
73
  */
74
74
  private controllers;
75
+ /**
76
+ * Variants whose data came from a streamed server payload (#1253). A reader
77
+ * that does not suspend rendered them on the server before their answer
78
+ * existed, so hydration must render them the same way; see
79
+ * `peekForHydration`.
80
+ */
81
+ private streamed;
75
82
  constructor(key: string, initialState: Record<string, any>);
76
83
  /**
77
84
  * Adopt server-prefetched data into the cache.
@@ -81,7 +88,7 @@ export declare class QueryResource {
81
88
  * otherwise the resource cache (which is keyed by path for the lifetime of
82
89
  * the app) would keep serving the first payload and revalidate it over `/api`.
83
90
  */
84
- hydrate(initialState: Record<string, any> | null | undefined): void;
91
+ hydrate(initialState: Record<string, any> | null | undefined, streamed?: boolean): void;
85
92
  private pendingFor;
86
93
  private settle;
87
94
  private isStale;
@@ -97,6 +104,25 @@ export declare class QueryResource {
97
104
  * `getVariant`.
98
105
  */
99
106
  peek(variantKey: string): State;
107
+ /**
108
+ * The server snapshot of a reader that does not suspend. On the server it
109
+ * rendered only what the document's `__GEMI_DATA__` carried, never a
110
+ * streamed answer (its request may still have been on the wire), so while
111
+ * hydrating it leaves out data that arrived through the stream. React
112
+ * re-renders with `peek` right after hydrating.
113
+ */
114
+ peekForHydration(variantKey: string): State;
115
+ /** Whether a request for this variant is on the wire. */
116
+ isFetching(variantKey: string): boolean;
117
+ /**
118
+ * The render-phase start for a reader that does not suspend (#1253): a
119
+ * variant with nothing cached and no request on the wire starts its request
120
+ * now, so it runs alongside the suspending reads of the same render instead
121
+ * of waiting for the commit's effect. Silent, like `read`: it never writes
122
+ * the store synchronously, and the in-flight mark makes every later read
123
+ * and the mount effect's `getVariant` join it.
124
+ */
125
+ start(variantKey: string): void;
100
126
  /**
101
127
  * The read a render performs. Never suspends when data is in hand (stale
102
128
  * data revalidates in the background instead), dedupes across the render
@@ -1 +1 @@
1
- {"version":3,"file":"QueryResource.d.ts","sourceRoot":"","sources":["../../client/QueryResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAM3C,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC;IACV;;;;;;OAMG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,GAAG,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAIF,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAGvC,qBAAa,aAAa;IACxB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IACnC,aAAa,cAAqB;IAClC,eAAe,sBAA6B;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAqB;IACrC;;;;;OAKG;IACH,OAAO,CAAC,OAAO,CAA+B;IAC9C;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAA6B;IAC7C;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAA6B;IAC7C;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAoD;IACvE;;;;;;;;OAQG;IACH,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,OAAO,CAA6B;IAC5C;;;;;OAKG;IACH,OAAO,CAAC,WAAW,CAA2C;gBAElD,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAM1D;;;;;;;OAOG;IACH,OAAO,CAAC,YAAY,EAAE,MAAM,CA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AAC,UAAU,EAAE,MAAM;IAQ9B;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM;IAQ3B,2EAA2E;IAC3E,WAAW,IAAI,MAAM,EAAE;IAIvB;;;;;OAKG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG;IAgBtD,aAAa,CAAC,UAAU,EAAE,MAAM;IAiBhC,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,GAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAoB;IAkClE,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM;IAe1E,OAAO,CAAC,UAAU,EAAE,MAAM;IAI1B,4EAA4E;IAC5E,WAAW,CAAC,UAAU,EAAE,MAAM;YAIhB,cAAc;CAmL7B"}
@@ -1,4 +1,4 @@
1
- import { $ as applyParams$1, A as useSearchParams, B as loadURLPattern, C as loadDictionary, D as readRoutePayload, E as setActiveLocale, F as ServerDataProvider, G as configureRealtime, H as applyDocumentNonce, I as useLocation, J as realtime, K as followLive, L as domainUrl, M as I18nContext, N as I18nProvider, O as routeDataUrl, P as ServerDataContext, Q as toVariantKey, R as isAbsoluteUrl, S as recoverFromChunkLoadError, T as registerDictionary, U as useCspNonce, V as CspNonceContext, W as RealtimeContext, X as loadLazy, Y as reconnectRealtime, Z as loadedModule, _ as configureChunkLoadRecovery, _t as retryDelayFor, a as useRouteTransition, at as DEFAULT_STALE_TIME, b as otherBuild, bt as Subject, c as ClientRouterContext, ct as resetAuthenticationIncident, d as ComponentsContext, dt as isExternalRedirect, et as QueryConfigContext, f as ComponentsProvider, ft as safeRedirectPath, g as CHUNK_RELOAD_MARKER, h as subscribeViewModules, ht as isRetryableQueryError, i as RouteTransitionProvider, it as pickDefined, j as useNavigate, k as useRoute, l as ClientRouterProvider, lt as setAuthenticationNavigator, m as loadViewModule, n as useTheme, nt as QueryManagerProvider, o as useChannelSubscription, ot as configureAuthenticationErrors, p as initialViewModulesReady, pt as readResponseBody, r as m, rt as USER_QUERY_CONFIG_KEYS, s as useCoalesced, st as reportAuthenticationRefusal, t as ThemeProvider, tt as QueryManagerContext, u as restoreScroll, ut as INTENDED_URL_PARAM, v as isChunkLoadError, vt as shouldRetryQuery, w as loadDictionaryForRender, x as recoverFromBuildMismatch, y as navigationStarted, yt as QueryError } from "../chunks/ThemeProvider-COjYIalw.js";
1
+ import { $ as applyParams$1, A as useSearchParams, B as loadURLPattern, C as loadDictionary, D as readRoutePayload, E as setActiveLocale, F as ServerDataProvider, G as configureRealtime, H as applyDocumentNonce, I as useLocation, J as realtime, K as followLive, L as domainUrl, M as I18nContext, N as I18nProvider, O as routeDataUrl, P as ServerDataContext, Q as toVariantKey, R as isAbsoluteUrl, S as recoverFromChunkLoadError, T as registerDictionary, U as useCspNonce, V as CspNonceContext, W as RealtimeContext, X as loadLazy, Y as reconnectRealtime, Z as loadedModule, _ as configureChunkLoadRecovery, _t as retryDelayFor, a as useRouteTransition, at as DEFAULT_STALE_TIME, b as otherBuild, bt as Subject, c as ClientRouterContext, ct as resetAuthenticationIncident, d as ComponentsContext, dt as isExternalRedirect, et as QueryConfigContext, f as ComponentsProvider, ft as safeRedirectPath, g as CHUNK_RELOAD_MARKER, h as subscribeViewModules, ht as isRetryableQueryError, i as RouteTransitionProvider, it as pickDefined, j as useNavigate, k as useRoute, l as ClientRouterProvider, lt as setAuthenticationNavigator, m as loadViewModule, n as useTheme, nt as QueryManagerProvider, o as useChannelSubscription, ot as configureAuthenticationErrors, p as initialViewModulesReady, pt as readResponseBody, r as m, rt as USER_QUERY_CONFIG_KEYS, s as useCoalesced, st as reportAuthenticationRefusal, t as ThemeProvider, tt as QueryManagerContext, u as restoreScroll, ut as INTENDED_URL_PARAM, v as isChunkLoadError, vt as shouldRetryQuery, w as loadDictionaryForRender, x as recoverFromBuildMismatch, y as navigationStarted, yt as QueryError } from "../chunks/ThemeProvider-w_axEu6B.js";
2
2
  import { n as RouteStateContext, r as RouteStateProvider, t as useParams } from "../chunks/useParams-BN3XXfmG.js";
3
3
  import { a as isNetworkError, c as isPermissionError, d as isValidationError, f as mutationErrorField, h as mutationErrorList, i as isHttpError, l as isRateLimitError, m as mutationErrorKind, n as isCsrfError, o as isNotFoundError, p as mutationErrorFromBody, r as isFormError, s as isObject, t as isAuthenticationError, u as isServerError } from "../chunks/MutationError-DuKqBW8o.js";
4
4
  import { Fragment, StrictMode, Suspense, createContext, createElement, isValidElement, lazy, memo, use, useCallback, useContext, useDeferredValue, useEffect, useInsertionEffect, useMemo, useRef, useState, useSyncExternalStore, useTransition } from "react";
@@ -264,7 +264,7 @@ var defaultOptions$1 = {
264
264
  function useQuery(url, ...args) {
265
265
  const [options, config] = args;
266
266
  const { user: _user, ...queryConfig } = useContext(QueryConfigContext) ?? {};
267
- return useFrameworkQuery(url, options, mergeDefinedConfig(queryConfig, config));
267
+ return useFrameworkQuery(url, options, mergeDefinedConfig(queryConfig, config), { startOnServer: true });
268
268
  }
269
269
  /**
270
270
  * `useQuery` minus the app's provider-level `queryConfig`: per-call config
@@ -272,10 +272,15 @@ function useQuery(url, ...args) {
272
272
  * (`useUser`'s `suspense: false`, `useSignIn`'s `lazy`) build on this so an
273
273
  * app-wide `queryConfig` can never change their semantics. Deliberately not
274
274
  * exported from the package root.
275
+ *
276
+ * `startOnServer`: a `suspense: false` query starts its request on a
277
+ * streaming server render too (#1253). Only `useQuery` asks for it: `useUser`
278
+ * of an anonymous visitor would put a 401 for `/auth/me` on every render, and
279
+ * report it through `onRequestFail`.
275
280
  */
276
281
  function useFrameworkQuery(url, ...args) {
277
282
  const _params = useParams();
278
- const [_options = defaultOptions$1, _config = defaultConfig] = args;
283
+ const [_options = defaultOptions$1, _config = defaultConfig, internal] = args;
279
284
  const options = {
280
285
  ...defaultOptions$1,
281
286
  ..._options
@@ -327,13 +332,14 @@ function useFrameworkQuery(url, ...args) {
327
332
  };
328
333
  }, [resource, variantKey]);
329
334
  const getSnapshot = useCallback(() => resource.peek(variantKey), [resource, variantKey]);
330
- const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
335
+ const getServerSnapshot = useCallback(() => resource.peekForHydration(variantKey), [resource, variantKey]);
336
+ const snapshot = useSyncExternalStore(subscribe, getSnapshot, suspense ? getSnapshot : getServerSnapshot);
331
337
  const lastDataRef = useRef(snapshot?.hasData ? snapshot : null);
332
338
  useEffect(() => {
333
339
  if (snapshot?.hasData) lastDataRef.current = snapshot;
334
340
  }, [snapshot]);
335
341
  let state = snapshot;
336
- if (config.keepPreviousData && !snapshot?.hasData && snapshot?.loading && lastDataRef.current) state = {
342
+ if (config.keepPreviousData && !snapshot?.hasData && (snapshot ? snapshot.loading : !lazy) && lastDataRef.current) state = {
337
343
  ...lastDataRef.current,
338
344
  loading: true
339
345
  };
@@ -356,6 +362,12 @@ function useFrameworkQuery(url, ...args) {
356
362
  else if (entry.status === "rejected") serverError = entry.error;
357
363
  else readPromise = entry.promise;
358
364
  } else readPromise = resource.read(variantKey, config.staleTime).promise;
365
+ if (!suspense && !lazy && !snapshot?.hasData && !snapshot?.error) if (typeof window === "undefined") {
366
+ if (internal?.startOnServer) serverQueries?.ensure(url, {
367
+ params,
368
+ search
369
+ });
370
+ } else resource.start(variantKey);
359
371
  if (suspense && typeof window === "undefined" && unserved && !state?.hasData && process.env.NODE_ENV !== "production") warnUnprefetched(url, variantKey);
360
372
  useEffect(() => {
361
373
  if (!isDeferred) return;
@@ -412,6 +424,7 @@ function useFrameworkQuery(url, ...args) {
412
424
  fetchedRef.current = true;
413
425
  focusRef.current.eligible = true;
414
426
  const variant = resource.store.getValue().get(variantKey);
427
+ if (resource.isFetching(variantKey)) return;
415
428
  if (!variant || !variant.loading && !variant.hasData) resource.refetch(variantKey);
416
429
  }, [resource, variantKey]);
417
430
  const prefetch = useCallback(() => {
@@ -447,10 +460,14 @@ function useFrameworkQuery(url, ...args) {
447
460
  }
448
461
  //#endregion
449
462
  //#region client/useMultipleQuery.ts
450
- /** A key whose first answer is still on the wire: nothing to show for it yet. */
463
+ /**
464
+ * A key whose first answer is still on the wire: nothing to show for it yet.
465
+ * A variant with no state at all counts: its request was started silently in
466
+ * the render, or goes out in the mount effect.
467
+ */
451
468
  function awaitingFirstAnswer(target) {
452
469
  const state = target.resource.peek(target.variantKey);
453
- return !!state && state.loading && !state.hasData;
470
+ return !state || state.loading && !state.hasData;
454
471
  }
455
472
  function useMultipleQuery(queries, sharedConfig) {
456
473
  const { user: _user, ...appConfig } = useContext(QueryConfigContext) ?? {};
@@ -518,12 +535,13 @@ function useMultipleQuery(queries, sharedConfig) {
518
535
  });
519
536
  const entriesRef = useRef(entries);
520
537
  entriesRef.current = entries;
521
- const targets = useMemo(() => entriesRef.current.map(({ key, path, variantKey, resource }) => ({
538
+ const targets = useMemo(() => entriesRef.current.map(({ key, path, variantKey, suspense, resource }) => ({
522
539
  key,
523
540
  path,
524
541
  variantKey,
542
+ suspense,
525
543
  resource
526
- })), [entries.map((e) => `${e.key}\u0000${e.path}\u0000${e.variantKey}`).join("\n"), getResource]);
544
+ })), [entries.map((e) => `${e.key}\u0000${e.path}\u0000${e.variantKey}\u0000${e.suspense}`).join("\n"), getResource]);
527
545
  const subscribe = useCallback((onStoreChange) => {
528
546
  const releases = targets.map((t) => t.resource.retain(t.variantKey));
529
547
  let notified = targets.map((t) => t.resource.peek(t.variantKey));
@@ -560,7 +578,17 @@ function useMultipleQuery(queries, sharedConfig) {
560
578
  };
561
579
  return states;
562
580
  }, [targets]);
563
- const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
581
+ const serverCacheRef = useRef(null);
582
+ const snapshot = useSyncExternalStore(subscribe, getSnapshot, useCallback(() => {
583
+ const states = targets.map((t) => t.suspense ? t.resource.peek(t.variantKey) : t.resource.peekForHydration(t.variantKey));
584
+ const cached = serverCacheRef.current;
585
+ if (cached && cached.targets === targets && states.every((state, i) => state === cached.states[i])) return cached.states;
586
+ serverCacheRef.current = {
587
+ targets,
588
+ states
589
+ };
590
+ return states;
591
+ }, [targets]));
564
592
  const lastDataRef = useRef(/* @__PURE__ */ new Map());
565
593
  useEffect(() => {
566
594
  snapshot.forEach((state, i) => {
@@ -579,8 +607,17 @@ function useMultipleQuery(queries, sharedConfig) {
579
607
  const promises = [];
580
608
  let thrown = null;
581
609
  entries.forEach((e, i) => {
610
+ if (!e.suspense) {
611
+ if (snapshot[i]?.hasData || snapshot[i]?.error) return;
612
+ if (typeof window === "undefined") serverQueries?.ensure(e.url, {
613
+ params: e.params,
614
+ search: e.search
615
+ });
616
+ else e.resource.start(e.variantKey);
617
+ return;
618
+ }
582
619
  const state = states[i];
583
- if (!e.suspense || state?.hasData || state?.error) return;
620
+ if (state?.hasData || state?.error) return;
584
621
  if (typeof window === "undefined") {
585
622
  const entry = serverQueries?.ensure(e.url, {
586
623
  params: e.params,
@@ -723,12 +760,14 @@ function useMultipleQuery(queries, sharedConfig) {
723
760
  const error = {};
724
761
  const mutate = {};
725
762
  const refetch = {};
763
+ const loadingByKey = {};
726
764
  let loading = false;
727
765
  entries.forEach((e, i) => {
728
766
  const state = states[i];
729
767
  data[e.key] = state?.data;
730
768
  error[e.key] = state?.error ?? null;
731
- if (e.isDeferred || (state?.loading ?? true)) loading = true;
769
+ loadingByKey[e.key] = e.isDeferred || (state?.loading ?? true);
770
+ if (loadingByKey[e.key]) loading = true;
732
771
  mutate[e.key] = (fn) => {
733
772
  mutateQuery(e.resource, e.variantKey, fn);
734
773
  };
@@ -737,6 +776,7 @@ function useMultipleQuery(queries, sharedConfig) {
737
776
  return {
738
777
  data,
739
778
  loading,
779
+ loadingByKey,
740
780
  error,
741
781
  mutate,
742
782
  refetch
@@ -941,7 +981,7 @@ var SOCKET_ID_HEADER = "x-gemi-socket";
941
981
  */
942
982
  var mutationExtras = {
943
983
  current: null,
944
- load: () => import("../chunks/mutationExtras-DtSw6BcX.js")
984
+ load: () => import("../chunks/mutationExtras-bNF9JOSk.js")
945
985
  };
946
986
  /** Starts loading `./mutationExtras`: the hooks' mount effect. */
947
987
  function preloadMutationExtras() {
@@ -1299,7 +1339,7 @@ function useMutate() {
1299
1339
  //#region client/fetchFile.ts
1300
1340
  var request = {
1301
1341
  current: null,
1302
- load: () => import("../chunks/fetchFileRequest-BaufNZpI.js")
1342
+ load: () => import("../chunks/fetchFileRequest-Bhh5BC_l.js")
1303
1343
  };
1304
1344
  /**
1305
1345
  * Downloads a file route's body as a `Blob`.
@@ -1365,7 +1405,7 @@ function useSetQueryData() {
1365
1405
  //#endregion
1366
1406
  //#region client/useSubscription.ts
1367
1407
  /** `./subscriptionStream`, loaded on first use. Replaceable in tests. */
1368
- var streamModule = { load: () => import("../chunks/subscriptionStream-CqhJOfPn.js") };
1408
+ var streamModule = { load: () => import("../chunks/subscriptionStream-D42DpDiZ.js") };
1369
1409
  /**
1370
1410
  * Follows a route that answers with `ChangeFeed.stream`, as long as the
1371
1411
  * component is mounted: each change reaches `onChange`, in order, exactly