gemi 0.242.2 → 0.242.3
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.
- package/dist/{chunk-d8aegerq.js → chunk-21qtrkze.js} +1 -1
- package/dist/{chunk-8gc7rygz.js → chunk-6dnbm8ww.js} +4 -4
- package/dist/{chunk-8gc7rygz.js.map → chunk-6dnbm8ww.js.map} +3 -3
- package/dist/{chunk-zd73z5av.js → chunk-mjc726j5.js} +2 -2
- package/dist/{chunk-zd73z5av.js.map → chunk-mjc726j5.js.map} +1 -1
- package/dist/chunks/{RealtimeClient-Di8ozsFv.js → RealtimeClient-DjGXYF2W.js} +2 -2
- package/dist/chunks/{RealtimeClient-Di8ozsFv.js.map → RealtimeClient-DjGXYF2W.js.map} +1 -1
- package/dist/chunks/{ThemeProvider-wwhaAveo.js → ThemeProvider-B2wbwyMP.js} +20 -4
- package/dist/chunks/{ThemeProvider-wwhaAveo.js.map → ThemeProvider-B2wbwyMP.js.map} +1 -1
- package/dist/chunks/{fetchFileRequest-B3dlL_eX.js → fetchFileRequest-Cfjz5PW5.js} +2 -2
- package/dist/chunks/{fetchFileRequest-B3dlL_eX.js.map → fetchFileRequest-Cfjz5PW5.js.map} +1 -1
- package/dist/chunks/{live-DZBIdcg7.js → live-BqtkjCBg.js} +3 -3
- package/dist/chunks/{live-DZBIdcg7.js.map → live-BqtkjCBg.js.map} +1 -1
- package/dist/chunks/{mutationExtras-CnzA8Ie-.js → mutationExtras-Dzqhh3yy.js} +2 -2
- package/dist/chunks/{mutationExtras-CnzA8Ie-.js.map → mutationExtras-Dzqhh3yy.js.map} +1 -1
- package/dist/chunks/{subscriptionStream-DLA3izlS.js → subscriptionStream-CnFC0cvd.js} +2 -2
- package/dist/chunks/{subscriptionStream-DLA3izlS.js.map → subscriptionStream-CnFC0cvd.js.map} +1 -1
- package/dist/client/ClientRouter.d.ts.map +1 -1
- package/dist/client/chunkLoadRecovery.d.ts +12 -0
- package/dist/client/chunkLoadRecovery.d.ts.map +1 -1
- package/dist/client/index.js +31 -5
- package/dist/client/index.js.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/testing/index.js +2 -2
- package/package.json +1 -1
- /package/dist/{chunk-d8aegerq.js.map → chunk-21qtrkze.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ct as QueryError, bt as parseRetryAfter, tt as applyParams } from "./ThemeProvider-B2wbwyMP.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-
|
|
57
|
+
//# sourceMappingURL=fetchFileRequest-Cfjz5PW5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchFileRequest-
|
|
1
|
+
{"version":3,"file":"fetchFileRequest-Cfjz5PW5.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,QAA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ACjB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
-
import {
|
|
2
|
+
import { $ as loadedModule, X as realtime } from "./ThemeProvider-B2wbwyMP.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-
|
|
68
|
+
else import("./RealtimeClient-DjGXYF2W.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-
|
|
77
|
+
//# sourceMappingURL=live-BqtkjCBg.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-
|
|
1
|
+
{"version":3,"file":"live-BqtkjCBg.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,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 {
|
|
1
|
+
import { et as toVariantKey, tt as applyParams } from "./ThemeProvider-B2wbwyMP.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.";
|
|
@@ -143,4 +143,4 @@ function invalidateQueries(resources, keys) {
|
|
|
143
143
|
//#endregion
|
|
144
144
|
export { applyQueryUpdates, invalidateQueries, withMutationErrorHelpers, writeQueryData };
|
|
145
145
|
|
|
146
|
-
//# sourceMappingURL=mutationExtras-
|
|
146
|
+
//# sourceMappingURL=mutationExtras-Dzqhh3yy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutationExtras-CnzA8Ie-.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), and invalidation by key (#1329). 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\n/**\n * Invalidates every cached query a key matches: one a mounted reader is\n * rendering refetches now, any other is marked stale and revalidates when next\n * read. A key is a resolved path (`\"/posts\"`, every search variant of it), a\n * single variant (`\"/posts?status=open\"`), or a prefix ending in `*`\n * (`\"/posts/*\"`).\n */\nexport function invalidateQueries(\n resources: Iterable<QueryResource>,\n keys: ReadonlyArray<string>,\n) {\n if (keys.length === 0) return;\n const all = [...resources];\n // Collected first, so a variant two keys match refetches once.\n const matched = new Map<QueryResource, Set<string>>();\n const add = (resource: QueryResource, variantKeys: string[]) => {\n const set = matched.get(resource) ?? new Set<string>();\n for (const variantKey of variantKeys) set.add(variantKey);\n matched.set(resource, set);\n };\n for (const key of keys) {\n const at = key.indexOf(\"?\");\n const path = at === -1 ? key : key.slice(0, at);\n if (path.endsWith(\"*\")) {\n const prefix = path.slice(0, -1);\n for (const resource of all) {\n if (resource.key.startsWith(prefix)) add(resource, resource.variantKeys());\n }\n continue;\n }\n for (const resource of all) {\n if (resource.key !== path) continue;\n add(resource, at === -1 ? resource.variantKeys() : [toVariantKey(key.slice(at + 1))]);\n }\n }\n for (const [resource, variantKeys] of matched) {\n for (const variantKey of variantKeys) resource.invalidate(variantKey);\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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AAK,MAAM,OAAO,MAAM;EACtB,MAAM,KAAK,IAAI,QAAQ,GAAG;EAC1B,MAAM,OAAO,OAAO,KAAK,MAAM,IAAI,MAAM,GAAG,EAAE;EAC9C,IAAI,KAAK,SAAS,GAAG,GAAG;GACtB,MAAM,SAAS,KAAK,MAAM,GAAG,EAAE;GAC/B,KAAK,MAAM,YAAY,KACrB,IAAI,SAAS,IAAI,WAAW,MAAM,GAAG,IAAI,UAAU,SAAS,YAAY,CAAC;GAE3E;EACF;EACA,KAAK,MAAM,YAAY,KAAK;GAC1B,IAAI,SAAS,QAAQ,MAAM;GAC3B,IAAI,UAAU,OAAO,KAAK,SAAS,YAAY,IAAI,CAAC,aAAa,IAAI,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;EACtF;CACF;CACA,KAAK,MAAM,CAAC,UAAU,gBAAgB,SACpC,KAAK,MAAM,cAAc,aAAa,SAAS,WAAW,UAAU;AAExE"}
|
|
1
|
+
{"version":3,"file":"mutationExtras-Dzqhh3yy.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), and invalidation by key (#1329). 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\n/**\n * Invalidates every cached query a key matches: one a mounted reader is\n * rendering refetches now, any other is marked stale and revalidates when next\n * read. A key is a resolved path (`\"/posts\"`, every search variant of it), a\n * single variant (`\"/posts?status=open\"`), or a prefix ending in `*`\n * (`\"/posts/*\"`).\n */\nexport function invalidateQueries(\n resources: Iterable<QueryResource>,\n keys: ReadonlyArray<string>,\n) {\n if (keys.length === 0) return;\n const all = [...resources];\n // Collected first, so a variant two keys match refetches once.\n const matched = new Map<QueryResource, Set<string>>();\n const add = (resource: QueryResource, variantKeys: string[]) => {\n const set = matched.get(resource) ?? new Set<string>();\n for (const variantKey of variantKeys) set.add(variantKey);\n matched.set(resource, set);\n };\n for (const key of keys) {\n const at = key.indexOf(\"?\");\n const path = at === -1 ? key : key.slice(0, at);\n if (path.endsWith(\"*\")) {\n const prefix = path.slice(0, -1);\n for (const resource of all) {\n if (resource.key.startsWith(prefix)) add(resource, resource.variantKeys());\n }\n continue;\n }\n for (const resource of all) {\n if (resource.key !== path) continue;\n add(resource, at === -1 ? resource.variantKeys() : [toVariantKey(key.slice(at + 1))]);\n }\n }\n for (const [resource, variantKeys] of matched) {\n for (const variantKey of variantKeys) resource.invalidate(variantKey);\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,K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ACtB,MAAM,KAAK,IAAI,QAAQ,GAAG;EAC1B,MAAM,OAAO,OAAO,KAAK,MAAM,IAAI,MAAM,GAAG,EAAE;EAC9C,IAAI,KAAK,SAAS,GAAG,GAAG;GACtB,MAAM,SAAS,KAAK,MAAM,GAAG,EAAE;GAC/B,KAAK,MAAM,YAAY,KACrB,IAAI,SAAS,IAAI,WAAW,MAAM,GAAG,IAAI,UAAU,SAAS,YAAY,CAAC;GAE3E;EACF;EACA,KAAK,MAAM,YAAY,KAAK;GAC1B,IAAI,SAAS,QAAQ,MAAM;GAC3B,IAAI,UAAU,OAAO,KAAK,SAAS,YAAY,IAAI,CAAC,aAAa,IAAI,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;EACtF;CACF;CACA,KAAK,MAAM,CAAC,UAAU,gBAAgB,SACpC,KAAK,MAAM,cAAc,aAAa,SAAS,WAAW,UAAU;AAExE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { vt as equalJitter } from "./ThemeProvider-B2wbwyMP.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-
|
|
178
|
+
//# sourceMappingURL=subscriptionStream-CnFC0cvd.js.map
|
package/dist/chunks/{subscriptionStream-DLA3izlS.js.map → subscriptionStream-CnFC0cvd.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscriptionStream-DLA3izlS.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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AAQ,KAAK,CAAC,EAAA,CAAG,QAAQ,UAAU,IAAI;GAClF,IAAI,WAAW,OAAO,QAAQ,MAAM;GACpC,OAAO,aAAa,IAAI;IACtB,MAAM,QAAQ,OAAO,MAAM,GAAG,QAAQ;IACtC,SAAS,OAAO,MAAM,WAAW,CAAC;IAClC,WAAW,OAAO,QAAQ,MAAM;IAChC,IAAI;IACJ,MAAM,OAAiB,CAAC;IACxB,KAAK,MAAM,QAAQ,MAAM,MAAM,IAAI,GAAG;KACpC,IAAI,SAAS,MAAM,KAAK,WAAW,GAAG,GAAG;KACzC,MAAM,QAAQ,KAAK,QAAQ,GAAG;KAC9B,MAAM,QAAQ,UAAU,KAAK,OAAO,KAAK,MAAM,GAAG,KAAK;KACvD,IAAI,OAAO,UAAU,KAAK,KAAK,KAAK,MAAM,QAAQ,CAAC;KACnD,IAAI,KAAK,WAAW,GAAG,GAAG,OAAO,KAAK,MAAM,CAAC;KAC7C,IAAI,UAAU,MAAM,KAAK;UACpB,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-CnFC0cvd.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;C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QAAQ;IACtC,SAAS,OAAO,MAAM,WAAW,CAAC;IAClC,WAAW,OAAO,QAAQ,MAAM;IAChC,IAAI;IACJ,MAAM,OAAiB,CAAC;IACxB,KAAK,MAAM,QAAQ,MAAM,MAAM,IAAI,GAAG;KACpC,IAAI,SAAS,MAAM,KAAK,WAAW,GAAG,GAAG;KACzC,MAAM,QAAQ,KAAK,QAAQ,GAAG;KAC9B,MAAM,QAAQ,UAAU,KAAK,OAAO,KAAK,MAAM,GAAG,KAAK;KACvD,IAAI,OAAO,UAAU,KAAK,KAAK,KAAK,MAAM,QAAQ,CAAC;KACnD,IAAI,KAAK,WAAW,GAAG,GAAG,OAAO,KAAK,MAAM,CAAC;KAC7C,IAAI,UAAU,MAAM,KAAK;UACpB,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientRouter.d.ts","sourceRoot":"","sources":["../../client/ClientRouter.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAqB,aAAa,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAKpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAO7C,OAAO,EAA6C,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKpG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"ClientRouter.d.ts","sourceRoot":"","sources":["../../client/ClientRouter.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAqB,aAAa,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAKpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAO7C,OAAO,EAA6C,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKpG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAoB/E,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC;KACrC;CACF;AAiGD,eAAO,MAAM,IAAI,8CACP;IACN,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,6CAoDF,CAAC;AAwXF,eAAO,MAAM,YAAY,GAAI,OAAO;IAClC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;IACxD,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IAClD,UAAU,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC3C,iEAAiE;IACjE,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,4CAkDA,CAAC"}
|
|
@@ -156,6 +156,18 @@ export declare function recoverFromBuildMismatch({ url, clientBuild, serverBuild
|
|
|
156
156
|
clientBuild: string;
|
|
157
157
|
serverBuild: string;
|
|
158
158
|
}): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Loads `url` in full because the client's redirects went round in a loop
|
|
161
|
+
* (two routes sending a navigation to each other, a stale cached `.json`
|
|
162
|
+
* redirect). Following them client-side calls `history.replaceState` on every
|
|
163
|
+
* hop, and Safari throws `SecurityError` past 100 calls in 10 seconds. A
|
|
164
|
+
* document load asks the server afresh, and a real loop there is one the
|
|
165
|
+
* browser stops on its own. Same guard as a chunk failure, once per URL per
|
|
166
|
+
* cooldown, and not subject to `chunkLoadRecovery: false`: it is the loop
|
|
167
|
+
* breaker, not a recovery an app opts out of. Returns whether the load was
|
|
168
|
+
* started; when it was not, the caller leaves the page on screen.
|
|
169
|
+
*/
|
|
170
|
+
export declare function recoverFromRedirectLoop(url: string): boolean;
|
|
159
171
|
/**
|
|
160
172
|
* The build that answered a `.json` navigation, when it is not `clientBuild`;
|
|
161
173
|
* otherwise `null`. Unknown on either side (dev, a test double, a server from
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunkLoadRecovery.d.ts","sourceRoot":"","sources":["../../client/chunkLoadRecovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,mFAAmF;AACnF,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAE3C,kFAAkF;AAClF,eAAO,MAAM,gCAAgC,QAAS,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,GAAG,KAAK,CAAC;AAElF;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;AAEzE,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,OAAO,CAAC;IACf,+DAA+D;IAC/D,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,oBAAoB,CAAC;IAC7B,+DAA+D;IAC/D,OAAO,EAAE,gBAAgB,CAAC;CAC3B;AAED,MAAM,WAAW,oBAAoB;IACnC,uEAAuE;IACvE,GAAG,EAAE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AO,CAeT;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,GAAG,EACH,WAAW,EACX,WAAW,GACZ,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB,GAAG,OAAO,CAYV;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAQ5D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAG7F;AA2ED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,GAAG,MAAM,GACtB,IAAI,GAAG,UAAU,GAAG,SAAS,CA8F/B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,MAAyC,GACpD,MAAM,CAQR"}
|
package/dist/client/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as loadedModule, A as useRoute, B as routeHref, C as recoverFromRedirectLoop, Ct as QueryError, D as setActiveLocale, E as registerDictionary, F as ServerDataContext, G as useCspNonce, H as loadURLPattern, I as ServerDataProvider, J as followLive, K as RealtimeContext, L as useLocation, M as useNavigate, N as I18nContext, O as readRoutePayload, P as I18nProvider, Q as loadLazy, R as domainUrl, S as recoverFromChunkLoadError, St as shouldRetryQuery, T as loadDictionaryForRender, U as CspNonceContext, W as applyDocumentNonce, X as realtime, Z as reconnectRealtime, _ as configureChunkLoadRecovery, _t as readResponseBody, a as useRouteTransition, at as USER_QUERY_CONFIG_KEYS, b as otherBuild, c as ClientRouterContext, ct as RequestTimeoutError, d as ComponentsContext, dt as reportAuthenticationRefusal, et as toVariantKey, f as ComponentsProvider, ft as resetAuthenticationIncident, g as CHUNK_RELOAD_MARKER, gt as safeRedirectPath, h as subscribeViewModules, ht as isExternalRedirect, i as RouteTransitionProvider, it as QueryManagerProvider, j as useSearchParams, k as routeDataUrl, l as ClientRouterProvider, lt as startRequestTimeout, m as loadViewModule, mt as INTENDED_URL_PARAM, n as useTheme, nt as QueryConfigContext, o as useChannelSubscription, ot as pickDefined, p as initialViewModulesReady, pt as setAuthenticationNavigator, q as configureRealtime, r as m, rt as QueryManagerContext, s as useCoalesced, st as DEFAULT_STALE_TIME, t as ThemeProvider, tt as applyParams$1, u as restoreScroll, ut as configureAuthenticationErrors, v as isChunkLoadError, w as loadDictionary, wt as Subject, x as recoverFromBuildMismatch, xt as retryDelayFor, y as navigationStarted, yt as isRetryableQueryError, z as isAbsoluteUrl } from "../chunks/ThemeProvider-B2wbwyMP.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";
|
|
@@ -1017,7 +1017,7 @@ var SOCKET_ID_HEADER = "x-gemi-socket";
|
|
|
1017
1017
|
*/
|
|
1018
1018
|
var mutationExtras = {
|
|
1019
1019
|
current: null,
|
|
1020
|
-
load: () => import("../chunks/mutationExtras-
|
|
1020
|
+
load: () => import("../chunks/mutationExtras-Dzqhh3yy.js")
|
|
1021
1021
|
};
|
|
1022
1022
|
/** Starts loading `./mutationExtras`: the hooks' mount effect. */
|
|
1023
1023
|
function preloadMutationExtras() {
|
|
@@ -1435,7 +1435,7 @@ function useInvalidate() {
|
|
|
1435
1435
|
//#region client/fetchFile.ts
|
|
1436
1436
|
var request = {
|
|
1437
1437
|
current: null,
|
|
1438
|
-
load: () => import("../chunks/fetchFileRequest-
|
|
1438
|
+
load: () => import("../chunks/fetchFileRequest-Cfjz5PW5.js")
|
|
1439
1439
|
};
|
|
1440
1440
|
/**
|
|
1441
1441
|
* Downloads a file route's body as a `Blob`.
|
|
@@ -1501,7 +1501,7 @@ function useSetQueryData() {
|
|
|
1501
1501
|
//#endregion
|
|
1502
1502
|
//#region client/useSubscription.ts
|
|
1503
1503
|
/** `./subscriptionStream`, loaded on first use. Replaceable in tests. */
|
|
1504
|
-
var streamModule = { load: () => import("../chunks/subscriptionStream-
|
|
1504
|
+
var streamModule = { load: () => import("../chunks/subscriptionStream-CnFC0cvd.js") };
|
|
1505
1505
|
/**
|
|
1506
1506
|
* Follows a route that answers with `ChangeFeed.stream`, as long as the
|
|
1507
1507
|
* component is mounted: each change reaches `onChange`, in order, exactly
|
|
@@ -2697,6 +2697,13 @@ var Tree = memo((props) => {
|
|
|
2697
2697
|
}, `slot-${slot}`);
|
|
2698
2698
|
}) });
|
|
2699
2699
|
});
|
|
2700
|
+
/**
|
|
2701
|
+
* How many redirects one navigation follows client-side before gemi stops and
|
|
2702
|
+
* loads the page in full. Each hop is a `history.replaceState`, and a loop of
|
|
2703
|
+
* them (two routes redirecting to each other) used to spin until the browser
|
|
2704
|
+
* threw: Safari allows 100 calls in 10 seconds.
|
|
2705
|
+
*/
|
|
2706
|
+
var MAX_CLIENT_REDIRECTS = 5;
|
|
2700
2707
|
var Routes = (props) => {
|
|
2701
2708
|
const { componentTree } = props;
|
|
2702
2709
|
const [isPending, startTransition] = useTransition();
|
|
@@ -2780,10 +2787,15 @@ var Routes = (props) => {
|
|
|
2780
2787
|
buildId
|
|
2781
2788
|
};
|
|
2782
2789
|
});
|
|
2790
|
+
const redirectChainRef = useRef([]);
|
|
2791
|
+
const followingRedirectRef = useRef(false);
|
|
2783
2792
|
useEffect(() => {
|
|
2784
2793
|
return routerSubject?.subscribe(async (routerState) => {
|
|
2785
2794
|
const { fetchRouteCSS, preloadRouteModules, takePrefetched, hydrate, buildId } = subscriberDepsRef.current;
|
|
2786
2795
|
const { pathname, search, state, views } = routerState;
|
|
2796
|
+
const here = currentUrl();
|
|
2797
|
+
redirectChainRef.current = followingRedirectRef.current ? [...redirectChainRef.current, here] : [here];
|
|
2798
|
+
followingRedirectRef.current = false;
|
|
2787
2799
|
navigationStarted();
|
|
2788
2800
|
setTransitionPath((current) => {
|
|
2789
2801
|
const [, prevTarget] = current;
|
|
@@ -2834,7 +2846,18 @@ var Routes = (props) => {
|
|
|
2834
2846
|
updateMeta(meta, i18n?.currentLocale ?? i18n?.defaultLocale);
|
|
2835
2847
|
if (directive?.kind === "Redirect") {
|
|
2836
2848
|
if (isExternalRedirect(directive?.path)) window.location.replace(directive.path);
|
|
2837
|
-
else if (directive?.path)
|
|
2849
|
+
else if (directive?.path) {
|
|
2850
|
+
const chain = redirectChainRef.current;
|
|
2851
|
+
const target = new URL(directive.path, window.location.href);
|
|
2852
|
+
if (chain.includes(target.pathname + target.search) || chain.length > MAX_CLIENT_REDIRECTS) {
|
|
2853
|
+
console.error(`gemi: stopped following client redirects that loop: ${[...chain, target.pathname + target.search].join(" -> ")}`);
|
|
2854
|
+
if (!recoverFromRedirectLoop(target.href)) setIsFetching(false);
|
|
2855
|
+
return;
|
|
2856
|
+
}
|
|
2857
|
+
followingRedirectRef.current = true;
|
|
2858
|
+
replace(directive.path);
|
|
2859
|
+
followingRedirectRef.current = false;
|
|
2860
|
+
}
|
|
2838
2861
|
return;
|
|
2839
2862
|
}
|
|
2840
2863
|
if (is404) {
|
|
@@ -2889,6 +2912,9 @@ var Routes = (props) => {
|
|
|
2889
2912
|
})
|
|
2890
2913
|
});
|
|
2891
2914
|
};
|
|
2915
|
+
function currentUrl() {
|
|
2916
|
+
return window.location.pathname + window.location.search;
|
|
2917
|
+
}
|
|
2892
2918
|
var ClientRouter = (props) => {
|
|
2893
2919
|
const { RootLayout } = props;
|
|
2894
2920
|
const { routeManifest, router, componentTree, pageData, cssManifest, modulePreloadManifest, assetBase, breadcrumbs, i18n, meta } = useContext(ServerDataContext);
|