brumate 0.7.2 → 0.8.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.
- package/dist/{boot-CMy0f_iC.d.ts → boot-BkUdiYOF.d.ts} +2 -2
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/{client-COm1iA6w.js → client-B0FXW5Kw.js} +48 -14
- package/dist/client-B0FXW5Kw.js.map +1 -0
- package/dist/{client-DnFF9_lv.d.ts → client-Cq6aTiDs.d.ts} +15 -7
- package/dist/{defer-Cesb-k2Q.js → defer-BMIMP4Hq.js} +2 -2
- package/dist/{defer-Cesb-k2Q.js.map → defer-BMIMP4Hq.js.map} +1 -1
- package/dist/{devtools-C9IEkgc1.js → devtools-B4prrxht.js} +257 -118
- package/dist/devtools-B4prrxht.js.map +1 -0
- package/dist/devtools-calls-DGW6nLZ2.js +249 -0
- package/dist/devtools-calls-DGW6nLZ2.js.map +1 -0
- package/dist/devtools-panel-B1nF1KB7.js +3978 -0
- package/dist/devtools-panel-B1nF1KB7.js.map +1 -0
- package/dist/error-catalog-DakxjSgj.js +308 -0
- package/dist/error-catalog-DakxjSgj.js.map +1 -0
- package/dist/error-catalog-VxLbz-6p.js +1 -0
- package/dist/{files-BuQvpBwF.js → files-D5GtxwEQ.js} +2 -2
- package/dist/{files-BuQvpBwF.js.map → files-D5GtxwEQ.js.map} +1 -1
- package/dist/index.d.ts +73 -18
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BSHv1_25.js → inspect-CGl5Y8q6.js} +581 -399
- package/dist/inspect-CGl5Y8q6.js.map +1 -0
- package/dist/{loader-CLKrJMqw.js → loader-BsaSuIoG.js} +4 -4
- package/dist/{loader-CLKrJMqw.js.map → loader-BsaSuIoG.js.map} +1 -1
- package/dist/{navigate-OHb0Uw1P.js → navigate-BlowKvhB.js} +13 -6
- package/dist/navigate-BlowKvhB.js.map +1 -0
- package/dist/{rpc-BAKbRWOT.js → rpc-C1jYVNAe.js} +5 -4
- package/dist/rpc-C1jYVNAe.js.map +1 -0
- package/dist/runtime/bundles.d.ts +1 -1
- package/dist/runtime/client.d.ts +2 -2
- package/dist/runtime/client.js +4 -3
- package/dist/runtime/devtools.d.ts +59 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/hot.js +6 -2
- package/dist/runtime/hot.js.map +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/server.d.ts +1 -1
- package/dist/runtime/server.js +3 -2
- package/dist/runtime/signals.d.ts +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/store.d.ts +2 -2
- package/dist/runtime/store.js +1 -1
- package/dist/runtime/testing.d.ts +2 -2
- package/dist/runtime/testing.js +2 -2
- package/dist/search-params-Wg-0FsMj.js +148 -0
- package/dist/search-params-Wg-0FsMj.js.map +1 -0
- package/dist/{stream-RXLadXx1.js → serial-ioa17MuY.js} +67 -168
- package/dist/serial-ioa17MuY.js.map +1 -0
- package/dist/serial-ribg9NAj.js +1 -0
- package/dist/{server-BVObWh-w.js → server-BUuf7XPZ.js} +61 -16
- package/dist/server-BUuf7XPZ.js.map +1 -0
- package/dist/{server-0rS5vUW1.d.ts → server-DesBZv5g.d.ts} +8 -3
- package/dist/{search-params-C64liRBj.js → shared-CX_YacDm.js} +3 -148
- package/dist/shared-CX_YacDm.js.map +1 -0
- package/dist/{signals-DBnq9QRW.d.ts → signals-7VVD9C_H.d.ts} +2 -2
- package/dist/{static-loader-CxANokZ4.js → static-loader-C_en-4v8.js} +2 -2
- package/dist/{static-loader-CxANokZ4.js.map → static-loader-C_en-4v8.js.map} +1 -1
- package/dist/{static-loader-BYbXVJDY.d.ts → static-loader-UKnK11Em.d.ts} +2 -2
- package/dist/{store-xlTzAM_r.d.ts → store-9_oa0HG1.d.ts} +15 -2
- package/dist/{store-BIBAYZo-.js → store-Cy4EEyZ7.js} +148 -2
- package/dist/store-Cy4EEyZ7.js.map +1 -0
- package/dist/stream-read-BTsYstJY.js +22 -0
- package/dist/stream-read-BTsYstJY.js.map +1 -0
- package/dist/stream-read-Dek3HnqO.js +1 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +37 -5
- package/dist/vite.js.map +1 -1
- package/package.json +7 -4
- package/skills/brumate/SKILL.md +6 -2
- package/skills/brumate/references/errors.md +21 -2
- package/skills/brumate/references/state.md +31 -0
- package/skills/brumate/references/syntax.md +45 -1
- package/dist/client-COm1iA6w.js.map +0 -1
- package/dist/devtools-C9IEkgc1.js.map +0 -1
- package/dist/devtools-panel-Doit__YG.js +0 -2018
- package/dist/devtools-panel-Doit__YG.js.map +0 -1
- package/dist/inspect-BSHv1_25.js.map +0 -1
- package/dist/navigate-OHb0Uw1P.js.map +0 -1
- package/dist/rpc-BAKbRWOT.js.map +0 -1
- package/dist/search-params-C64liRBj.js.map +0 -1
- package/dist/server-BVObWh-w.js.map +0 -1
- package/dist/store-BIBAYZo-.js.map +0 -1
- package/dist/stream-RXLadXx1.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-BIBAYZo-.js","names":[],"sources":["../src/runtime/store.ts"],"sourcesContent":["// Stores: values that change, which a context can hold while the context itself stays the same.\n// `$toStore` makes the store of a provider, and `$store` reads one in a component. The page state\n// sends only the value of a store; the browser makes a new store for it.\n\nimport type { Context } from './context.ts';\nimport { HAS_BRIDGES } from './features.ts';\n\n/** The pass of the core, which the browser sets, so a store's readers update in one pass. */\nconst PASS = Symbol.for('brumate.pass');\n\n/** True for a context, which `createContext` made. */\nexport function isContext(value: unknown): value is Context<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { key?: unknown }).key === 'string' &&\n Object.keys(value).length === 1 &&\n !isContract(value)\n );\n}\n\n/**\n * The store that `$store` reads: `value` is the store, or for `path` an object that holds it there.\n * `key` names the context that gave `value`, for the message. Throws a `TypeError` for a value that\n * is no store, such as `undefined` or a context, and for `write` on a store that has no `set`.\n */\nexport function findStored(\n value: unknown,\n path: string | undefined,\n write: boolean | undefined,\n key?: string,\n): StoreLike<unknown> {\n const found = path === undefined ? value : (value as Record<string, unknown> | undefined)?.[path];\n if (!isContract(found)) {\n // A context is the most likely mistake, so its message names the read that gives its store.\n if (isContext(found)) {\n throw new TypeError(\n `$store reads the context \"${found.key}\", which is no store. Read the store in it with $store($getContext(Context))`,\n );\n }\n throw new TypeError(\n `$store reads ${key === undefined ? 'a value' : `the context \"${key}\"`}${path === undefined ? '' : ` at \"${path}\"`}, which gives no store: a store has the functions get and subscribe`,\n );\n }\n if (write && !canSet(found)) {\n throw new TypeError(\n `let $store(${key ?? '…'}) writes the store, but the store has no set. Read it with const`,\n );\n }\n return found;\n}\n\n/**\n * The error of `$store` for a store of another library in a value that the page sends, such as a\n * prop: only the value of a store of `brumate/store` crosses. The fix is said here only.\n */\nexport function sentForeignStore(component: string, value: string): Error {\n return new Error(\n `$store in ${component} reads a store of another library from ${value}, which the page sends, and only a store of brumate/store crosses. Wrap the library's store with bridge() in a module, or read it from an import, <script module> or a call in this component`,\n );\n}\n\n/** Where `$toStore` made a store: its scope, the ID of its site, and the slot of its signal. */\nexport type StoreOrigin = [scope: number | string, site: number, slot?: number];\n\n/**\n * The contract of a store, which `$store` reads: `get`, `subscribe` (which returns the function\n * that stops it, and does not call the listener at once) and, for a two-way binding, `set`.\n */\nexport interface StoreLike<T> {\n get(): T;\n subscribe(listener: (value: T) => void): () => void;\n set?(value: T): void;\n}\n\n/** A value that changes, with the functions that read it and write it. */\nexport class Store<T> implements StoreLike<T> {\n /** The value. */\n v: T;\n /** The functions that `subscribe` added. */\n l: Set<(value: T) => void> = new Set();\n /** For a store of `$toStore(signal)`, the write of the signal, which the browser sets. */\n w?: (value: T) => void;\n /** True for a store of `$toStore(memo)`, which only its provider writes. */\n r?: boolean;\n /** Where `$toStore` made it, for the page state. */\n o?: StoreOrigin;\n /** True for a store of `$toStore` in the browser until its first update. */\n f?: boolean;\n /**\n * The mark of a store, which `isStore` reads in every copy of the runtime. A field, so a build\n * without stores drops the class.\n */\n k = 'brumate.store' as const;\n\n constructor(value: T) {\n this.v = value;\n }\n\n /** The current value. */\n get(): T {\n return this.v;\n }\n\n /** Calls `listener` with each new value. Returns the function that stops it. */\n subscribe(listener: (value: T) => void): () => void {\n this.l.add(listener);\n return () => {\n this.l.delete(listener);\n };\n }\n\n /**\n * Writes the value, and calls the listeners when it changed. A store of `$toStore(signal)`\n * writes the signal, and a store of a memo throws.\n */\n set(value: T): void {\n if (this.r) {\n throw new Error('This store follows a memo, so only its provider writes it');\n }\n if (Object.is(this.v, value)) {\n return;\n }\n if (this.w) {\n this.v = value;\n this.w(value);\n return;\n }\n sendStore(this, value);\n }\n}\n\n/** True for a store of `brumate/store`, of any copy of the runtime. */\nexport function isStore(value: unknown): value is Store<unknown> {\n return (\n typeof value === 'object' && value !== null && (value as { k?: unknown }).k === 'brumate.store'\n );\n}\n\n/** True for a value with the functions `get` and `subscribe` of the store contract. */\nexport function isContract(value: unknown): value is StoreLike<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { get?: unknown }).get === 'function' &&\n typeof (value as { subscribe?: unknown }).subscribe === 'function'\n );\n}\n\n/** True for a value of the store contract that is not a store of brumate. */\nexport function isForeignStore(value: unknown): boolean {\n return isContract(value) && !isStore(value) && !(HAS_BRIDGES && isBridged(value));\n}\n\n/** True when `$store` can write the store: it has `set`, and is not the store of a memo. */\nexport function canSet(value: StoreLike<unknown>): boolean {\n return typeof value.set === 'function' && !(value as Store<unknown>).r;\n}\n\n/** Makes a store, such as one that a module holds for the whole app. */\nexport function store<T>(value: T): Store<T> {\n return new Store(value);\n}\n\n/** Writes the value of a store and calls its listeners, in one pass of the page. */\nexport function sendStore<T>(target: Store<T>, value: T, force?: boolean): void {\n // The listeners hear of a change only. A provider's update forces it, since a `set` of\n // `$toStore(signal)` wrote the value before the signal's update came.\n if (!force && Object.is(target.v, value)) {\n return;\n }\n target.v = value;\n const listeners = () => {\n for (const listener of target.l) {\n listener(value);\n }\n };\n const pass = (globalThis as { [key: symbol]: (<R>(run: () => R) => R) | undefined })[PASS];\n if (pass) {\n pass(listeners);\n } else {\n listeners();\n }\n}\n\n// Bridges: a store of another library that can cross the page state. `bridge()` names how to make\n// the library's store, read it and listen to it, and the page state sends the data that `get`\n// reads, with the name of the bridge. The browser makes the library's store again, once, from\n// that data.\n\n/** What `bridge` takes. */\nexport interface BridgeOptions<S, T> {\n /**\n * Makes the library's store. On the server it runs once for each call of the bridge. In the\n * browser it runs once, when the store gets its first subscriber, with the data that the server\n * sent. It must be in a module that the browser can load.\n */\n create: (snapshot: T | undefined) => S;\n /** The data of the store: plain data that the page state can send. */\n get: (source: S) => T;\n /** Calls `listener` when the store changes. Returns the function that stops it. */\n subscribe: (source: S, listener: () => void) => () => void;\n /** Writes the store. The browser never calls it when the page resumes. */\n set?: (source: S, value: T) => void;\n}\n\n/** A store of `bridge()`: the contract of a store, and the store of the library. */\nexport interface BridgedStore<S, T> extends StoreLike<T> {\n /**\n * The store of the library. In the browser it is undefined until the store has a subscriber,\n * since the browser makes it at the first subscriber.\n */\n readonly source: S | undefined;\n}\n\n/** What `bridge` returns: makes a store, from the data of the server in the browser. */\nexport interface Bridge<S, T> {\n (snapshot?: T): BridgedStore<S, T>;\n /** The options. */\n b: BridgeOptions<S, T>;\n /** The name that the compiler gave, `bridge:<file>#<export>`. */\n i?: string;\n}\n\nconst BRIDGES = Symbol.for('brumate.bridges');\nconst BRIDGE_LOAD = Symbol.for('brumate.bridge-load');\n\ntype Global = { [BRIDGES]?: Map<string, Bridge<never, never>>; [BRIDGE_LOAD]?: Loader };\ntype Loader = [load: (module: string) => Promise<unknown>, report: (error: unknown) => void];\n\n/** The bridges by name, which any copy of the runtime shares. */\nfunction bridges(): Map<string, Bridge<never, never>> {\n return ((globalThis as Global)[BRIDGES] ??= new Map());\n}\n\n/**\n * Sets how the browser loads the module of a bridge, and where a failed load is reported. The\n * core calls it when it starts.\n */\nexport function setBridgeLoader(...loader: Loader): void {\n (globalThis as Global)[BRIDGE_LOAD] = loader;\n}\n\n/** The module of a bridge, from its name. */\nfunction bridgeModule(id: string): string {\n return id.slice(0, id.lastIndexOf('#'));\n}\n\n/**\n * Makes a bridge. Keep its value in a module-level export, so the page state can name it:\n * `export const bears = bridge({ … })`. The compiler gives it its name.\n */\nexport function bridge<S, T>(options: BridgeOptions<S, T>): Bridge<S, T> {\n const made = Object.assign(\n (snapshot?: T): BridgedStore<S, T> => new Bridged(made, options.create(snapshot)),\n { b: options },\n ) as Bridge<S, T>;\n return made;\n}\n\n/** Gives a bridge its name, which the compiler writes at the end of its module. */\nexport function nameBridge(made: Bridge<never, never>, id: string): void {\n made.i = id;\n bridges().set(id, made);\n}\n\n/** True for a store of `bridge()`, of any copy of the runtime. */\nexport function isBridged(value: unknown): value is Bridged<unknown, unknown> {\n return (\n typeof value === 'object' && value !== null && (value as { k?: unknown }).k === 'brumate.bridge'\n );\n}\n\n/**\n * Whether two values hold the same data: the same value, or arrays and plain objects whose items\n * hold the same data. A store that the browser makes again holds a new object with the content\n * the server sent, which needs no repair.\n */\nexport function sameData(a: unknown, b: unknown, open?: Map<object, Set<unknown>>): boolean {\n if (Object.is(a, b)) {\n return true;\n }\n const array = Array.isArray(a);\n if (array ? !Array.isArray(b) || a.length !== b.length : !isPlain(a) || !isPlain(b)) {\n return false;\n }\n const left = a as Record<string, unknown>;\n const right = b as Record<string, unknown>;\n // A pair already under compare is a cycle: it counts as the same, so each pair is compared once.\n open ??= new Map();\n let pairs = open.get(left);\n if (pairs?.has(right)) {\n return true;\n }\n if (!pairs) {\n pairs = new Set();\n open.set(left, pairs);\n }\n pairs.add(right);\n const keys = Object.keys(left);\n if (!array && keys.length !== Object.keys(right).length) {\n return false;\n }\n for (const key of keys) {\n if (!(key in right) || !sameData(left[key], right[key], open)) {\n return false;\n }\n }\n return true;\n}\n\n/** Whether a value is an object of `Object` or of no prototype, as page state holds. */\nfunction isPlain(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\n/**\n * The store that a bridge makes. On the server it holds the library's store from the start. In\n * the browser the page state makes it with the name of the bridge and the data of the server, and\n * it makes the library's store at its first subscriber.\n */\nexport class Bridged<S, T> implements BridgedStore<S, T> {\n /** The mark of a bridged store, which `isBridged` reads in every copy of the runtime. */\n k = 'brumate.bridge' as const;\n /** The bridge. Undefined for a store of the page state until the module of the bridge loads. */\n f?: Bridge<S, T>;\n /** The name of the bridge, for a store of the page state. */\n i?: string;\n /** The library's store. */\n s?: S;\n /** True once the library's store exists. */\n m = false;\n /** The data that the server sent, until the library's store exists. */\n v?: T;\n /** Whether the bridge has `set`, as the server sent it, until the module loads. */\n w?: boolean;\n\n constructor(\n made: Bridge<S, T> | undefined,\n source: S | undefined,\n id?: string,\n snapshot?: T,\n writable?: boolean,\n ) {\n this.f = made;\n this.i = id;\n this.v = snapshot;\n this.w = writable;\n if (made) {\n this.s = source;\n this.m = true;\n }\n }\n\n /**\n * The library's store. In the browser it is undefined until the store has a subscriber and the\n * module of the bridge has loaded.\n */\n get source(): S | undefined {\n return this.s;\n }\n\n /** The name of the bridge. */\n get id(): string | undefined {\n return this.f?.i ?? this.i;\n }\n\n /** The data of the store: what `get` reads, or what the server sent before the first subscriber. */\n get(): T {\n return this.m ? this.f!.b.get(this.s as S) : (this.v as T);\n }\n\n /**\n * Calls `listener` with the data when it changes. The first subscriber makes the library's\n * store in the browser. When the module of the bridge has not loaded, the subscription starts\n * when it has.\n */\n subscribe(listener: (value: T) => void, ...seen: [value?: T]): () => void {\n let stopped = false;\n let stop: (() => void) | undefined;\n // What this subscriber has seen, which `seen` can name: a source that starts later compares\n // with it.\n let last = seen.length > 0 ? (seen[0] as T) : this.get();\n const start = (): void => {\n if (stopped) {\n return;\n }\n const options = this.f!.b;\n const source = this.make();\n stop = options.subscribe(source, () => {\n const next = options.get(source);\n if (!sameData(next, last)) {\n last = next;\n listener(next);\n }\n });\n // A source that starts from other data than this subscriber saw, such as one that keeps its\n // own state, is written once.\n const first = options.get(source);\n if (!sameData(first, last)) {\n last = first;\n listener(first);\n }\n };\n if (this.find()) {\n start();\n } else {\n void this.load().then((loaded) => loaded && start());\n }\n return () => {\n stopped = true;\n stop?.();\n };\n }\n\n /** Writes the library's store, when the bridge has `set`. */\n get set(): ((value: T) => void) | undefined {\n // Before the module loads, the server's word is all there is, so `let` checks the same.\n const writable = this.find() ? !!this.f!.b.set : this.w !== false;\n return writable ? (value) => this.write(value) : undefined;\n }\n\n /** Writes the library's store, after the module of the bridge has loaded. */\n private write(value: T): void {\n if (this.find()) {\n this.f!.b.set!(this.make(), value);\n } else {\n void this.load().then((loaded) => loaded && this.write(value));\n }\n }\n\n /** The bridge, once its module has loaded. */\n private find(): Bridge<S, T> | undefined {\n if (!this.f && this.i !== undefined) {\n this.f = bridges().get(this.i) as Bridge<S, T> | undefined;\n }\n return this.f;\n }\n\n /** Loads the module of the bridge. A failure goes to the core's error path; it gives false. */\n private load(): Promise<boolean> {\n const [load, report] = (globalThis as Global)[BRIDGE_LOAD] ?? [];\n return Promise.resolve(load?.(bridgeModule(this.i!))).then(\n () => {\n if (this.find()) {\n return true;\n }\n this.fail(\n report,\n new Error(\n `The bridge \"${this.i}\" is not in its module. Keep bridge() in a module-level export, as \"export const name = bridge({ … })\"`,\n ),\n );\n return false;\n },\n (error: unknown) => {\n this.fail(report, error);\n return false;\n },\n );\n }\n\n private fail(report: ((error: unknown) => void) | undefined, error: unknown): void {\n if (report) {\n report(error);\n } else {\n console.error(error);\n }\n }\n\n /** Makes the library's store once, with the data of the server. */\n private make(): S {\n if (!this.m) {\n this.s = this.f!.b.create(this.v);\n this.m = true;\n }\n return this.s as S;\n }\n}\n"],"mappings":";;;AAQA,MAAM,OAAO,OA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C,MAAM,WAAW,UAAU,KAAK,MAAM,KAAK,CAAC;CAEjE;;CAGA,OAAyC;EACvC,IAAI,CAAC,KAAK,KAAK,KAAK,MAAM,KAAA,GACxB,KAAK,IAAI,QAAQ,CAAC,CAAC,IAAI,KAAK,CAAC;EAE/B,OAAO,KAAK;CACd;;CAGA,OAAiC;EAC/B,MAAM,CAAC,MAAM,UAAW,WAAsB,gBAAgB,CAAC;EAC/D,OAAO,QAAQ,QAAQ,OAAO,aAAa,KAAK,CAAE,CAAC,CAAC,CAAC,CAAC,WAC9C;GACJ,IAAI,KAAK,KAAK,GACZ,OAAO;GAET,KAAK,KACH,wBACA,IAAI,MACF,eAAe,KAAK,EAAE,uGACxB,CACF;GACA,OAAO;EACT,IACC,UAAmB;GAClB,KAAK,KAAK,QAAQ,KAAK;GACvB,OAAO;EACT,CACF;CACF;CAEA,KAAa,QAAgD,OAAsB;EACjF,IAAI,QACF,OAAO,KAAK;OAEZ,QAAQ,MAAM,KAAK;CAEvB;;CAGA,OAAkB;EAChB,IAAI,CAAC,KAAK,GAAG;GACX,KAAK,IAAI,KAAK,EAAG,EAAE,OAAO,KAAK,CAAC;GAChC,KAAK,IAAI;EACX;EACA,OAAO,KAAK;CACd;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream-RXLadXx1.js","names":[],"sources":["../src/runtime/calls.ts","../src/runtime/serial.ts","../src/runtime/stream.ts"],"sourcesContent":["// Values that only server function calls and their serialization use. They are\n// not in `shared.ts`, which the core imports, so a page's core does not hold them.\n\nimport type { FunctionReference } from './shared.ts';\n\n/**\n * Client functions that the server passes on, such as function props, with\n * their references. Kept under a symbol of the registry, so two copies of the\n * runtime, such as a component's and the render context's, share it.\n */\nexport const functionReferences: WeakMap<object, FunctionReference> = ((\n globalThis as Record<symbol, WeakMap<object, FunctionReference> | undefined>\n)[Symbol.for('brumate.functionReferences')] ??= new WeakMap());\n\n/**\n * True for a file or a blob. One from another frame, or another DOM, is an\n * instance of another `Blob` class, so its methods tell instead.\n */\nexport function isBlob(value: unknown): value is Blob {\n if (typeof Blob !== 'undefined' && value instanceof Blob) {\n return true;\n }\n const blob = value as Partial<Blob> | null;\n return (\n typeof blob === 'object' &&\n blob !== null &&\n typeof blob.size === 'number' &&\n typeof blob.type === 'string' &&\n typeof blob.arrayBuffer === 'function' &&\n typeof blob.slice === 'function'\n );\n}\n","// The seroval plugins of brumate's values. The server writes the page state\n// with them as code, and server function calls as JSON, which both sides\n// read with them. The core does not import this module: a state record\n// is code that makes its values with `stateValues`, so seroval loads in the\n// browser only with the first server function call.\n\nimport { Feature, createPlugin } from 'seroval';\nimport {\n AbortSignalPlugin,\n CustomEventPlugin,\n DOMExceptionPlugin,\n EventPlugin,\n FormDataPlugin,\n HeadersPlugin,\n ImageDataPlugin,\n ReadableStreamPlugin,\n RequestPlugin,\n ResponsePlugin,\n URLPlugin,\n URLSearchParamsPlugin,\n} from 'seroval-plugins/web';\nimport type {\n Plugin,\n SerovalNode,\n StreamParsePluginContext,\n SyncParsePluginContext,\n} from 'seroval';\nimport { type Internal, isInternal, isRaw, rawHTML } from './html.ts';\nimport type { Raw } from './html.ts';\nimport { functionReferences, isBlob } from './calls.ts';\nimport { MODIFIERS } from './events.ts';\nimport { HAS_BRIDGES } from './features.ts';\nimport {\n CHILDREN_REF,\n ElementReference,\n PARTS,\n isBinding,\n isPropWrapper,\n isSlotReference,\n onSerialOptions,\n onValuePlugin,\n stateValues,\n} from './shared.ts';\nimport type { ChildrenReference, MemoError, PropPromise, ScopeId } from './shared.ts';\nimport type { ValuePlugin } from './values.ts';\nimport { isBridged, isStore } from './store.ts';\nimport type { Bridged, Store } from './store.ts';\nimport type { Binding, SlotReference } from './shared.ts';\nimport type { ComponentValue } from './shared.ts';\n\ntype ReferenceNode = { a: SerovalNode; b: SerovalNode; c?: SerovalNode; d?: SerovalNode };\n\n/** Serializes the parts of a node that are set, joined as call arguments. */\nfunction serializeParts(\n parts: (SerovalNode | undefined)[],\n ctx: { serialize(node: SerovalNode): string },\n): string {\n const written: string[] = [];\n for (const part of parts) {\n if (part !== undefined) {\n written.push(ctx.serialize(part));\n }\n }\n return written.join(',');\n}\n\n/**\n * Returns the parse functions of a plugin. `read` returns the values of the\n * node by key, and each mode parses them in that order, so the nodes match.\n */\nfunction parsers<T, K extends string>(\n read: (value: T) => Record<K, unknown>,\n): Plugin<T, Record<K, SerovalNode>>['parse'] {\n type N = Record<K, SerovalNode>;\n function parse(value: T, ctx: SyncParsePluginContext | StreamParsePluginContext): N {\n const node = read(value) as Record<string, unknown>;\n for (const key in node) {\n node[key] = ctx.parse(node[key]);\n }\n return node as N;\n }\n return {\n sync: parse,\n stream: parse,\n async: async (value, ctx) => {\n const node = read(value) as Record<string, unknown>;\n for (const key in node) {\n // oxlint-disable-next-line no-await-in-loop -- In order, as the other modes parse, so the IDs match.\n node[key] = await ctx.parse(node[key]);\n }\n return node as N;\n },\n };\n}\n\n// In the page state, each value is a call of `stateValues`, which the code of a record gets as `$b`.\n\n// No plugin here matches a plain object, so each one sets skipPlainObjects and seroval\n// does not run its test on object literals. Raw HTML is a class instance for this reason.\nconst ElementPlugin = createPlugin<ElementReference, ReferenceNode>({\n tag: 'brumate/element',\n skipPlainObjects: true,\n test: (value) => value instanceof ElementReference,\n parse: parsers((value) => ({ a: value.scope, b: value.anchor })),\n serialize: (node, ctx) => `$b.e(${ctx.serialize(node.a)},${ctx.serialize(node.b)})`,\n deserialize: (node, ctx) =>\n stateValues.e(ctx.deserialize<number>(node.a), ctx.deserialize<number>(node.b)),\n});\n\nconst SlotPlugin = createPlugin<SlotReference, ReferenceNode>({\n tag: 'brumate/slot',\n skipPlainObjects: true,\n test: (value) => isSlotReference(value),\n parse: parsers((value) => ({ a: value.scope, b: value.slot })),\n serialize: (node, ctx) => `$b.l(${ctx.serialize(node.a)},${ctx.serialize(node.b)})`,\n deserialize: (node, ctx) =>\n stateValues.l(ctx.deserialize<number>(node.a), ctx.deserialize<number>(node.b)),\n});\n\n/** A binding that a rest prop holds: its value, and the scope and the slot it writes. */\nconst BindingPlugin = createPlugin<Binding, ReferenceNode>({\n tag: 'brumate/binding',\n skipPlainObjects: true,\n test: (value) => isBinding(value),\n parse: parsers((value) => {\n const node: Record<string, unknown> = { a: value.value, b: value.ref.scope, c: value.ref.slot };\n // The setter of `$bind(name, fn)`.\n if (value.set !== undefined) {\n node.d = value.set;\n }\n return node as Record<'a' | 'b' | 'c' | 'd', unknown>;\n }),\n serialize: (node, ctx) => `$b.b(${serializeParts([node.a, node.b, node.c, node.d], ctx)})`,\n deserialize: (node, ctx) =>\n stateValues.b(\n ctx.deserialize(node.a),\n ctx.deserialize<number>(node.b!),\n ctx.deserialize<number>(node.c!),\n node.d === undefined ? undefined : ctx.deserialize(node.d),\n ),\n});\n\nconst FunctionPlugin = createPlugin<object, ReferenceNode>({\n tag: 'brumate/function',\n skipPlainObjects: true,\n test: (value) => typeof value === 'function' && functionReferences.has(value),\n parse: parsers((value) => {\n const reference = functionReferences.get(value)!;\n // The arguments of a handler that `$handler` made go with it.\n const node: Record<string, unknown> = { a: reference.ref, b: reference.scope };\n // The modifiers of its wrappers, so a spread in markup that the browser renders writes them.\n const modifiers = (value as { [MODIFIERS]?: string[] })[MODIFIERS];\n if (reference.args !== undefined || modifiers) {\n node.c = reference.args ?? null;\n }\n if (modifiers) {\n node.d = modifiers;\n }\n return node as Record<'a' | 'b' | 'c' | 'd', unknown>;\n }),\n serialize: (node, ctx) => `$b.f(${serializeParts([node.a, node.b, node.c, node.d], ctx)})`,\n deserialize: (node, ctx) =>\n stateValues.f(\n ctx.deserialize<string>(node.a),\n ctx.deserialize<number>(node.b),\n node.c === undefined ? undefined : ctx.deserialize<unknown[] | null>(node.c),\n node.d === undefined ? undefined : ctx.deserialize<string[]>(node.d),\n ),\n});\n\n/** A handler that merges the handlers of one event, as the parts that refer to client functions. */\nconst MergedPlugin = createPlugin<object, { a: SerovalNode }>({\n tag: 'brumate/merged',\n skipPlainObjects: true,\n test: (value) => typeof value === 'function' && PARTS in value,\n parse: parsers((value) => {\n const parts: object[] = [];\n for (const part of (value as { [PARTS]: object[] })[PARTS]) {\n if (functionReferences.has(part)) {\n parts.push(part);\n }\n }\n return { a: parts };\n }),\n serialize: (node, ctx) => `$b.m(${ctx.serialize(node.a)})`,\n deserialize: (node, ctx) => stateValues.m(ctx.deserialize(node.a)),\n});\n\n/**\n * A value of an attribute that brumate writes, which a live rest prop can hold. The ones that\n * reach the page state are the scoped style attribute and `b-v`. The error \"holds a Internal\"\n * no longer catches any other, so a new one needs a check of its own.\n */\nconst InternalPlugin = createPlugin<Internal, { a: SerovalNode }>({\n tag: 'brumate/internal',\n skipPlainObjects: true,\n test: (value) => isInternal(value),\n parse: parsers((value) => ({ a: value.value })),\n serialize: (node, ctx) => `$b.i(${ctx.serialize(node.a)})`,\n deserialize: (node, ctx) => stateValues.i(ctx.deserialize(node.a)),\n});\n\n/** Children of a component, as the export that renders them in the browser. */\nconst ChildrenPlugin = createPlugin<object, ReferenceNode>({\n tag: 'brumate/children',\n skipPlainObjects: true,\n test: (value) => typeof value === 'object' && value !== null && CHILDREN_REF in value,\n parse: parsers((value) => {\n const reference = (value as { [CHILDREN_REF]: ChildrenReference })[CHILDREN_REF];\n const node: Record<string, unknown> = { a: reference.ref, b: reference.scope };\n // The scope and the anchor of the insert where the server rendered them.\n if (reference.at !== undefined) {\n node.c = reference.at;\n node.d = reference.anchor;\n }\n return node as Record<'a' | 'b' | 'c' | 'd', unknown>;\n }),\n serialize: (node, ctx) => `$b.n(${serializeParts([node.a, node.b, node.c, node.d], ctx)})`,\n deserialize: (node, ctx) =>\n stateValues.n(\n ctx.deserialize<string>(node.a),\n ctx.deserialize<ScopeId>(node.b!),\n node.c === undefined ? undefined : ctx.deserialize<ScopeId>(node.c),\n node.d === undefined ? undefined : ctx.deserialize<number>(node.d),\n ),\n});\n\n/**\n * A memo that failed on the server. The page state holds its error, so a read in the browser\n * throws it, as a memo that failed there. The server writes the error that is safe to send. See\n * `stateValue`.\n */\nconst MemoErrorPlugin = createPlugin<MemoError, { e: SerovalNode }>({\n tag: 'brumate/memo-error',\n skipPlainObjects: true,\n // The server marks the errors it holds, so the copies of the runtime agree on them.\n test: (value) =>\n typeof value === 'object' && value !== null && Symbol.for('brumate.held') in value,\n parse: parsers((value) => ({ e: value.error })),\n serialize: (node, ctx) => `$b.x(${ctx.serialize(node.e)})`,\n deserialize: (node, ctx) => stateValues.x(ctx.deserialize(node.e)),\n});\n\n/** A promise prop in the page state. See `PropPromise`. */\nconst PropPromisePlugin = createPlugin<PropPromise, { p: SerovalNode }>({\n tag: 'brumate/prop-promise',\n skipPlainObjects: true,\n test: isPropWrapper,\n parse: parsers((value) => ({ p: value.promise })),\n serialize: (node, ctx) => `$b.q(${ctx.serialize(node.p)})`,\n deserialize: (node, ctx) => stateValues.q(ctx.deserialize(node.p)),\n});\n\n/** HTML, such as the `children` of a component, so the client can insert it again. */\nconst RawPlugin = createPlugin<Raw, { h: SerovalNode }>({\n tag: 'brumate/raw',\n skipPlainObjects: true,\n test: isRaw,\n parse: parsers((value) => ({ h: rawHTML(value) })),\n serialize: (node, ctx) => `$b.r(${ctx.serialize(node.h)})`,\n deserialize: (node, ctx) => stateValues.r(ctx.deserialize<string>(node.h)),\n});\n\n/** A component in the page state, such as the value of a dynamic tag. See `stateValues.c`. */\nconst ComponentPlugin = createPlugin<ComponentValue, { c: SerovalNode }>({\n tag: 'brumate/component',\n skipPlainObjects: true,\n test: (value) =>\n typeof value === 'function' && typeof (value as Partial<ComponentValue>).brumateId === 'string',\n parse: parsers((value) => ({ c: value.brumateId })),\n serialize: (node, ctx) => `$b.c(${ctx.serialize(node.c)})`,\n deserialize: (node, ctx) => stateValues.c(ctx.deserialize<string>(node.c)),\n});\n\n/**\n * A store of `brumate/store`: only its value crosses, and where `$toStore` made it, so the\n * browser makes a new store that the provider writes. Readers subscribe as their scopes resume.\n */\nconst StorePlugin = createPlugin<Store<unknown>, ReferenceNode>({\n tag: 'brumate/store',\n skipPlainObjects: true,\n test: isStore,\n parse: parsers((value) => {\n const node: Record<string, unknown> = { a: value.v };\n if (value.o) {\n node.b = value.o[0];\n node.c = value.o[1];\n if (value.o[2] !== undefined) {\n node.d = value.o[2];\n }\n }\n return node as Record<'a' | 'b' | 'c' | 'd', unknown>;\n }),\n serialize: (node, ctx) => `$b.s(${serializeParts([node.a, node.b, node.c, node.d], ctx)})`,\n deserialize: (node, ctx) =>\n stateValues.s(\n ctx.deserialize(node.a),\n node.b === undefined ? undefined : ctx.deserialize<ScopeId>(node.b),\n node.c === undefined ? undefined : ctx.deserialize<number>(node.c),\n node.d === undefined ? undefined : ctx.deserialize<number>(node.d),\n ),\n});\n\n/**\n * The index of a file or a blob, and what a part of multipart form data does\n * not keep: the type (an empty one arrives as `application/octet-stream`),\n * whether the value was a blob or a file (every part arrives as a file), and\n * the name (some characters are escaped) and `lastModified` of a file. Calls\n * from pages before these fields send only the index.\n */\ntype UploadNode = { i: SerovalNode; t?: SerovalNode; n?: SerovalNode; l?: SerovalNode };\n\nfunction isFile(value: Blob): value is File {\n const file = value as Partial<File>;\n return typeof file.name === 'string' && typeof file.lastModified === 'number';\n}\n\n/**\n * Files and blobs, which go only in the arguments of a call, as parts of\n * multipart form data named `file<index>`. The node holds the index. The\n * call passes `sent`, which gets each blob, and the server passes the form\n * that it `received`, whose files the indexes read. Without them, as in the\n * page state and in the answer of a call, a blob throws.\n */\nexport function uploadPlugin(sent?: Blob[], received?: FormData): Plugin<Blob, UploadNode> {\n return createPlugin<Blob, UploadNode>({\n tag: 'brumate/upload',\n skipPlainObjects: true,\n test: isBlob,\n // Only the fields that are set go in the node, so `K` names just the index.\n parse: parsers<Blob, 'i'>((value) => {\n if (!sent) {\n throw new Error('A file or a blob can only be sent in the arguments of a server function');\n }\n const index = sent.push(value) - 1;\n if (isFile(value)) {\n return { i: index, t: value.type, n: value.name, l: value.lastModified };\n }\n return { i: index, t: value.type };\n }) as Plugin<Blob, UploadNode>['parse'],\n serialize: () => {\n throw new Error('A file or a blob can only be sent in the arguments of a server function');\n },\n deserialize: (node, ctx) => {\n const file = received?.get(`file${ctx.deserialize<number>(node.i)}`);\n if (!(file instanceof Blob)) {\n throw new TypeError('A file of the call is missing');\n }\n // A page before the metadata fields sends only the index.\n if (node.t === undefined) {\n return file;\n }\n const type = ctx.deserialize(node.t);\n if (typeof type !== 'string') {\n throw new TypeError('A file of the call is malformed');\n }\n // The new blob or file refers to the bytes of the part instead of copying them.\n if (node.n === undefined) {\n return new Blob([file], { type });\n }\n const name = ctx.deserialize(node.n);\n const lastModified = node.l === undefined ? undefined : ctx.deserialize(node.l);\n if (typeof name !== 'string' || typeof lastModified !== 'number') {\n throw new TypeError('A file of the call is malformed');\n }\n return new File([file], name, { type, lastModified });\n },\n });\n}\n\n/**\n * The plugin of `AbortSignal` from seroval-plugins, which sends whether the\n * signal aborted and its reason. The one of seroval-plugins waits for a live\n * signal to abort, so a call with one would not be sent, and a page or an\n * answer with one would not end.\n */\nconst SignalPlugin: typeof AbortSignalPlugin = {\n ...AbortSignalPlugin,\n parse: {\n sync: AbortSignalPlugin.parse.sync,\n stream: AbortSignalPlugin.parse.sync,\n async: async (value, ctx) => (value.aborted ? { reason: await ctx.parse(value.reason) } : {}),\n },\n};\n\n/**\n * The plugin of `Request` from seroval-plugins, whose body streams in the\n * stream mode. A request with a stream body needs `duplex: 'half'`, or its\n * constructor throws, so the plugin adds it.\n */\nconst BodyRequestPlugin: typeof RequestPlugin = {\n ...RequestPlugin,\n serialize: (node, ctx) =>\n `new Request(${ctx.serialize(node.url)},Object.assign(${ctx.serialize(node.options)},{duplex:\"half\"}))`,\n deserialize: (node, ctx) =>\n new Request(\n ctx.deserialize(node.url) as string,\n {\n ...(ctx.deserialize(node.options) as RequestInit),\n duplex: 'half',\n } as RequestInit,\n ),\n};\n\n/**\n * The error of a store of `bridge()` whose data the page state cannot send. It holds the store as\n * `value`, so the server finds the context or the prop that sends it.\n */\nexport class BridgeDataError extends Error {\n value: Bridged<unknown, unknown>;\n\n constructor(value: Bridged<unknown, unknown>, cause: unknown) {\n super(`get of the bridge \"${value.id}\" gives data that cannot be sent`, { cause });\n this.value = value;\n }\n}\n\n/** Reads the data of a bridged store for the page state. */\nfunction bridgeData(value: Bridged<unknown, unknown>): unknown {\n if (value.id === undefined) {\n throw new BridgeDataError(\n value,\n new Error(\n 'The bridge has no name. Keep bridge() in a module-level export of a script file, as \"export const name = bridge({ … })\", so the compiler names it',\n ),\n );\n }\n return value.get();\n}\n\n/** The node of a bridged store: its data and its name. An error of the data names the store. */\nfunction bridgeNode(\n value: Bridged<unknown, unknown>,\n parse: (data: unknown) => SerovalNode,\n): ReferenceNode {\n try {\n return { a: parse(bridgeData(value)), b: parse(value.id), c: parse(value.set ? 1 : 0) };\n } catch (error) {\n throw error instanceof BridgeDataError ? error : new BridgeDataError(value, error);\n }\n}\n\n/**\n * A store of `bridge()`: only the data that `get` reads crosses, and the name of the bridge, so\n * the browser makes the library's store again from the data at the first subscriber.\n */\nfunction makeBridgePlugin(): Plugin<Bridged<unknown, unknown>, ReferenceNode> {\n return createPlugin<Bridged<unknown, unknown>, ReferenceNode>({\n tag: 'brumate/bridge',\n skipPlainObjects: true,\n test: isBridged,\n parse: {\n sync: (value, ctx) => bridgeNode(value, (data) => ctx.parse(data)),\n stream: (value, ctx) => bridgeNode(value, (data) => ctx.parse(data)),\n async: async (value, ctx) => {\n try {\n const data = bridgeData(value);\n return {\n a: await ctx.parse(data),\n b: await ctx.parse(value.id),\n c: await ctx.parse(value.set ? 1 : 0),\n };\n } catch (error) {\n throw error instanceof BridgeDataError ? error : new BridgeDataError(value, error);\n }\n },\n },\n serialize: (node, ctx) =>\n `$b.g(${ctx.serialize(node.a)},${ctx.serialize(node.b)},${ctx.serialize(node.c!)})`,\n deserialize: (node, ctx) =>\n stateValues.g(\n ctx.deserialize(node.a),\n ctx.deserialize<string>(node.b),\n ctx.deserialize<number>(node.c!),\n ),\n });\n}\n\n/** The plugins after the plugin of uploads, which a call makes for its files. */\n// oxlint-disable-next-line typescript/no-explicit-any -- Plugin is invariant, so any is needed to hold every plugin.\nconst valuePlugins: Plugin<any, any>[] = [\n ElementPlugin,\n SlotPlugin,\n BindingPlugin,\n FunctionPlugin,\n MergedPlugin,\n InternalPlugin,\n MemoErrorPlugin,\n PropPromisePlugin,\n ChildrenPlugin,\n RawPlugin,\n ComponentPlugin,\n StorePlugin,\n ...(HAS_BRIDGES ? [makeBridgePlugin()] : []),\n // The web values of seroval-plugins. Requests and responses need the async or stream modes,\n // so a page state or a call result that holds one streams. The plugin of uploads takes files\n // and blobs, so those of seroval-plugins, which would put their bytes in the JSON, are left out.\n SignalPlugin,\n CustomEventPlugin,\n DOMExceptionPlugin,\n EventPlugin,\n FormDataPlugin,\n HeadersPlugin,\n ImageDataPlugin,\n ReadableStreamPlugin,\n BodyRequestPlugin,\n ResponsePlugin,\n URLPlugin,\n URLSearchParamsPlugin,\n];\n\n/**\n * The plugins of a call with files: `sent` gets the files that the call\n * sends, and `received` is the form that the server got them in.\n */\n// oxlint-disable-next-line typescript/no-explicit-any -- Plugin is invariant, so any is needed to hold every plugin.\nexport function callPlugins(sent?: Blob[], received?: FormData): Plugin<any, any>[] {\n return [uploadPlugin(sent, received), ...valuePlugins];\n}\n\n/** The plugins of the page state, of answers and of calls without files. */\n// oxlint-disable-next-line typescript/no-explicit-any -- Plugin is invariant, so any is needed to hold every plugin.\nexport const plugins: Plugin<any, any>[] = callPlugins();\n\n/**\n * Stops a sync mode at a value that only streams: an async iterable, such\n * as a `ReadableStream`. seroval writes one in a sync mode as a stream that\n * never gets its values, without an error.\n */\nconst StreamGuardPlugin = createPlugin<object, Record<string, never>>({\n tag: 'brumate/stream-guard',\n test: (value) =>\n (typeof ReadableStream !== 'undefined' && value instanceof ReadableStream) ||\n (typeof value === 'object' && value !== null && Symbol.asyncIterator in value),\n parse: {\n sync: () => {\n throw new Error('A stream needs the async or stream mode');\n },\n },\n serialize: () => '',\n deserialize: () => ({}),\n});\n\n/**\n * The plugins for the sync modes, which must throw for a value that only\n * streams, so the page state streams instead, and a call with a stream in\n * its arguments is not shared with another. The guard comes first, so it\n * takes a `ReadableStream` before the plugin of `ReadableStream`, which the\n * plugins of `Request` and `Response` bring in.\n */\n// oxlint-disable-next-line typescript/no-explicit-any -- Plugin is invariant, so any is needed to hold every plugin.\nexport const syncPlugins: Plugin<any, any>[] = [StreamGuardPlugin, ...plugins];\n\n/**\n * The seroval plugin of a plugin of the app. The page state writes its value\n * as `$b.u(tag, data)`, so the record does not need the class in scope.\n */\nfunction appPlugin(plugin: ValuePlugin): Plugin<unknown, { d: SerovalNode }> {\n return createPlugin<unknown, { d: SerovalNode }>({\n tag: `app:${plugin.tag}`,\n test: plugin.test,\n parse: parsers((value) => ({ d: plugin.toData(value) })),\n serialize: (node, ctx) => `$b.u(${JSON.stringify(plugin.tag)},${ctx.serialize(node.d)})`,\n deserialize: (node, ctx) => plugin.fromData(ctx.deserialize(node.d)),\n });\n}\n\n// The plugins of the app come before brumate's, in each list, as the entry adds them. The\n// plugin of uploads stays first in a call, and the guard of streams first in the sync modes.\nonValuePlugin((plugin) => {\n const added = appPlugin(plugin);\n valuePlugins.unshift(added);\n plugins.splice(1, 0, added);\n syncPlugins.splice(2, 0, added);\n});\n\n/**\n * Features that are off in both directions:\n *\n * - Errors keep their name and message only. A stack trace would show the\n * server's files and code to the browser.\n * - Regular expressions are not sent. A pattern from a client could take\n * the server a long time to match, and reading one is refused as well.\n */\nconst BRUMATE_DISABLED = Feature.ErrorPrototypeStack | Feature.RegExp;\n\nexport let disabledFeatures: number = BRUMATE_DISABLED;\nlet depthLimit: number | undefined;\n\n/** The options of every call of seroval: the features that are off, and the depth limit of the entry. */\nexport function serialOptions(): { disabledFeatures: number; depthLimit?: number } {\n return depthLimit === undefined ? { disabledFeatures } : { disabledFeatures, depthLimit };\n}\n\nonSerialOptions((options) => {\n disabledFeatures = options.disabledFeatures ?? BRUMATE_DISABLED;\n depthLimit = options.depthLimit;\n // oxlint-disable-next-line no-bitwise -- The features are flags.\n const enabled = BRUMATE_DISABLED & ~disabledFeatures;\n if (enabled !== 0) {\n console.warn(\n `The serial entry turns on ${enabled & Feature.RegExp ? 'RegExp' : 'ErrorPrototypeStack'}, which brumate turns off: ${enabled & Feature.RegExp ? 'a pattern from a client can take the server a long time to match' : 'a stack shows the files and code of the server to the browser'}.`,\n );\n }\n});\n","// The answer of a server function, as a stream of seroval chunks. Promises\n// and async iterables in the answer settle as their chunks arrive.\n//\n// Each chunk is a 12-byte header with the size of its data in bytes, as 8\n// hex digits, and the data: `;0x0000001f;{...}`. The reader knows how many\n// bytes to wait for, and can refuse a chunk that is too large.\n\nimport { Stream, fromCrossJSON, toCrossJSONStream } from 'seroval';\nimport type { SerovalNode } from 'seroval';\nimport { serialOptions, plugins } from './serial.ts';\n\nconst HEADER_SIZE = 12;\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder();\n\n/** The content type of a stream of chunks. */\nexport const STREAM_TYPE = 'application/x-brumate-stream';\n\n/** One chunk: its header and its data, in one array. */\nfunction chunk(text: string): Uint8Array {\n const data = encoder.encode(text);\n const result = new Uint8Array(HEADER_SIZE + data.length);\n encoder.encodeInto(`;0x${data.length.toString(16).padStart(8, '0')};`, result);\n result.set(data, HEADER_SIZE);\n return result;\n}\n\n/** Serializes a value as a stream of chunks. */\nexport function toChunkStream(\n value: unknown,\n onCancel?: (reason: unknown) => void,\n): ReadableStream<Uint8Array> {\n let cancelled = false;\n return new ReadableStream({\n start(controller) {\n toCrossJSONStream(value, {\n refs: new Map(),\n plugins,\n ...serialOptions(),\n onParse(node) {\n if (!cancelled) {\n controller.enqueue(chunk(JSON.stringify(node)));\n }\n },\n onDone() {\n if (!cancelled) {\n controller.close();\n }\n },\n onError(error) {\n if (!cancelled) {\n controller.error(error);\n }\n },\n });\n },\n // The reader went away, such as a browser that aborted the call.\n cancel(reason) {\n cancelled = true;\n onCancel?.(reason);\n },\n });\n}\n\n/** Reads chunks of a stream, buffering only the bytes of the chunk it waits for. */\nclass ChunkReader {\n private readonly reader: ReadableStreamDefaultReader<Uint8Array>;\n private pieces: Uint8Array[] = [];\n private length = 0;\n private done = false;\n\n constructor(stream: ReadableStream<Uint8Array>) {\n this.reader = stream.getReader();\n }\n\n private async fill(size: number): Promise<void> {\n while (this.length < size && !this.done) {\n // oxlint-disable-next-line no-await-in-loop -- Pieces arrive in order.\n const piece = await this.reader.read();\n if (piece.done) {\n this.done = true;\n } else {\n this.pieces.push(piece.value);\n this.length += piece.value.length;\n }\n }\n }\n\n private take(size: number): Uint8Array {\n const result = new Uint8Array(size);\n let offset = 0;\n while (offset < size) {\n const piece = this.pieces[0]!;\n const count = Math.min(piece.length, size - offset);\n result.set(piece.subarray(0, count), offset);\n offset += count;\n if (count === piece.length) {\n this.pieces.shift();\n } else {\n this.pieces[0] = piece.subarray(count);\n }\n }\n this.length -= size;\n return result;\n }\n\n /** The data of the next chunk, or undefined at the end of the stream. */\n async next(): Promise<string | undefined> {\n await this.fill(HEADER_SIZE);\n if (this.length === 0) {\n return undefined;\n }\n const head = this.length < HEADER_SIZE ? '' : decoder.decode(this.take(HEADER_SIZE));\n const match = /^;0x([0-9a-f]{8});$/.exec(head);\n if (!match) {\n throw new Error('The answer of a server function is not a stream of chunks');\n }\n const size = Number.parseInt(match[1]!, 16);\n await this.fill(size);\n if (this.length < size) {\n throw new Error('The answer of a server function ended in the middle of a chunk');\n }\n return decoder.decode(this.take(size));\n }\n\n cancel(reason: unknown): void {\n this.done = true;\n void this.reader.cancel(reason).catch(() => {});\n }\n}\n\nfunction ignore(): void {}\n\n/**\n * The refs of a stream. A promise in the answer can fail with nothing that\n * reads it, such as a field the caller ignores, so its failure is claimed\n * here. Code that awaits it still sees the failure.\n */\nclass Refs extends Map<number, unknown> {\n override set(id: number, value: unknown): this {\n if (value instanceof Promise) {\n value.catch(ignore);\n }\n return super.set(id, value);\n }\n}\n\n/**\n * Fails the promises and async iterables that still wait for a chunk, when\n * the stream ends early. Failing a settled one does nothing.\n */\nfunction failPending(refs: Refs, error: unknown): void {\n for (const value of refs.values()) {\n try {\n // The deserializer makes a Stream. A LiveStream comes only from user code, and its producer fails it.\n if (value instanceof Stream) {\n value.throw(error);\n } else if (value !== null && typeof value === 'object') {\n const resolver = value as { p?: unknown; f?: unknown };\n if (resolver.p instanceof Promise && typeof resolver.f === 'function') {\n resolver.p.catch(ignore);\n (resolver.f as (error: unknown) => void)(error);\n }\n }\n } catch {\n // A value that a plugin made, which has no such methods.\n }\n }\n}\n\n/**\n * Reads the first chunk of a stream as the value, and the rest in the\n * background, so the promises and async iterables in it settle as their\n * chunks arrive.\n */\nexport async function fromChunkStream(stream: ReadableStream<Uint8Array>): Promise<unknown> {\n const reader = new ChunkReader(stream);\n const refs = new Refs();\n function read(data: string): unknown {\n return fromCrossJSON(JSON.parse(data) as SerovalNode, { refs, plugins, ...serialOptions() });\n }\n const first = await reader.next();\n if (first === undefined) {\n throw new Error('The answer of a server function is empty');\n }\n const value = read(first);\n void (async () => {\n try {\n for (;;) {\n // oxlint-disable-next-line no-await-in-loop -- Chunks arrive in order.\n const data = await reader.next();\n if (data === undefined) {\n break;\n }\n read(data);\n }\n failPending(refs, new Error('The answer of a server function ended early'));\n } catch (error) {\n reader.cancel(error);\n failPending(refs, error);\n }\n })();\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;AAUA,MAAa,qBAA0D,WAErE,OAAO,IAAI,4BAA4B,uBAAO,IAAI,QAAQ;;;;;AAM5D,SAAgB,OAAO,OAA+B;CACpD,IAAI,OAAO,SAAS,eAAe,iBAAiB,MAClD,OAAO;CAET,MAAM,OAAO;CACb,OACE,OAAO,SAAS,YAChB,SAAS,QACT,OAAO,KAAK,SAAS,YACrB,OAAO,KAAK,SAAS,YACrB,OAAO,KAAK,gBAAgB,cAC5B,OAAO,KAAK,UAAU;AAE1B;;;;ACsBA,SAAS,eACP,OACA,KACQ;CACR,MAAM,UAAoB,CAAC;CAC3B,KAAK,MAAM,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