brumate 0.7.2 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/{boot-CMy0f_iC.d.ts → boot-DQuAhAd5.d.ts} +2 -2
  2. package/dist/cli.js +3 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{client-DnFF9_lv.d.ts → client-4eabQtYJ.d.ts} +38 -12
  5. package/dist/{client-COm1iA6w.js → client-CwVcmymi.js} +145 -28
  6. package/dist/client-CwVcmymi.js.map +1 -0
  7. package/dist/{defer-Cesb-k2Q.js → defer-BaXWydb0.js} +2 -2
  8. package/dist/{defer-Cesb-k2Q.js.map → defer-BaXWydb0.js.map} +1 -1
  9. package/dist/{devtools-C9IEkgc1.js → devtools-CMuj12yR.js} +257 -118
  10. package/dist/devtools-CMuj12yR.js.map +1 -0
  11. package/dist/devtools-calls-DGW6nLZ2.js +249 -0
  12. package/dist/devtools-calls-DGW6nLZ2.js.map +1 -0
  13. package/dist/devtools-panel-Cq8LpsyW.js +3978 -0
  14. package/dist/devtools-panel-Cq8LpsyW.js.map +1 -0
  15. package/dist/error-catalog-DakxjSgj.js +308 -0
  16. package/dist/error-catalog-DakxjSgj.js.map +1 -0
  17. package/dist/error-catalog-VxLbz-6p.js +1 -0
  18. package/dist/{files-BuQvpBwF.js → files-DXS8RAtZ.js} +2 -2
  19. package/dist/{files-BuQvpBwF.js.map → files-DXS8RAtZ.js.map} +1 -1
  20. package/dist/index.d.ts +73 -18
  21. package/dist/index.js +11 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/{inspect-BSHv1_25.js → inspect-B5AoHh5O.js} +639 -412
  24. package/dist/inspect-B5AoHh5O.js.map +1 -0
  25. package/dist/{loader-CLKrJMqw.js → loader-CTeT6ie9.js} +4 -4
  26. package/dist/{loader-CLKrJMqw.js.map → loader-CTeT6ie9.js.map} +1 -1
  27. package/dist/{navigate-OHb0Uw1P.js → navigate-Bj73X4ZS.js} +22 -8
  28. package/dist/navigate-Bj73X4ZS.js.map +1 -0
  29. package/dist/{rpc-BAKbRWOT.js → rpc-kVB0Ujdx.js} +5 -4
  30. package/dist/rpc-kVB0Ujdx.js.map +1 -0
  31. package/dist/runtime/bundles.d.ts +3 -2
  32. package/dist/runtime/bundles.js +14 -3
  33. package/dist/runtime/bundles.js.map +1 -1
  34. package/dist/runtime/client.d.ts +2 -2
  35. package/dist/runtime/client.js +4 -3
  36. package/dist/runtime/devtools.d.ts +59 -1
  37. package/dist/runtime/devtools.js +1 -1
  38. package/dist/runtime/hot.d.ts +1 -1
  39. package/dist/runtime/hot.js +6 -2
  40. package/dist/runtime/hot.js.map +1 -1
  41. package/dist/runtime/loader.d.ts +2 -2
  42. package/dist/runtime/loader.js +2 -2
  43. package/dist/runtime/server.d.ts +1 -1
  44. package/dist/runtime/server.js +3 -2
  45. package/dist/runtime/signals.d.ts +1 -1
  46. package/dist/runtime/static-loader.d.ts +2 -2
  47. package/dist/runtime/static-loader.js +1 -1
  48. package/dist/runtime/store.d.ts +2 -2
  49. package/dist/runtime/store.js +1 -1
  50. package/dist/runtime/testing.d.ts +2 -2
  51. package/dist/runtime/testing.js +2 -2
  52. package/dist/search-params-Wg-0FsMj.js +148 -0
  53. package/dist/search-params-Wg-0FsMj.js.map +1 -0
  54. package/dist/{stream-RXLadXx1.js → serial-ioa17MuY.js} +67 -168
  55. package/dist/serial-ioa17MuY.js.map +1 -0
  56. package/dist/serial-ribg9NAj.js +1 -0
  57. package/dist/{server-BVObWh-w.js → server-BUuf7XPZ.js} +61 -16
  58. package/dist/server-BUuf7XPZ.js.map +1 -0
  59. package/dist/{server-0rS5vUW1.d.ts → server-DesBZv5g.d.ts} +8 -3
  60. package/dist/{search-params-C64liRBj.js → shared-CX_YacDm.js} +3 -148
  61. package/dist/shared-CX_YacDm.js.map +1 -0
  62. package/dist/{signals-DBnq9QRW.d.ts → signals-7VVD9C_H.d.ts} +2 -2
  63. package/dist/{static-loader-CxANokZ4.js → static-loader-BM0-wdIc.js} +2 -2
  64. package/dist/{static-loader-CxANokZ4.js.map → static-loader-BM0-wdIc.js.map} +1 -1
  65. package/dist/{static-loader-BYbXVJDY.d.ts → static-loader-BSAyFqG0.d.ts} +2 -2
  66. package/dist/{store-xlTzAM_r.d.ts → store-9_oa0HG1.d.ts} +15 -2
  67. package/dist/{store-BIBAYZo-.js → store-Cy4EEyZ7.js} +148 -2
  68. package/dist/store-Cy4EEyZ7.js.map +1 -0
  69. package/dist/stream-read-BTsYstJY.js +22 -0
  70. package/dist/stream-read-BTsYstJY.js.map +1 -0
  71. package/dist/stream-read-Dek3HnqO.js +1 -0
  72. package/dist/vite.d.ts +1 -1
  73. package/dist/vite.js +37 -5
  74. package/dist/vite.js.map +1 -1
  75. package/package.json +7 -4
  76. package/skills/brumate/SKILL.md +6 -2
  77. package/skills/brumate/references/errors.md +21 -2
  78. package/skills/brumate/references/state.md +31 -0
  79. package/skills/brumate/references/syntax.md +45 -1
  80. package/dist/client-COm1iA6w.js.map +0 -1
  81. package/dist/devtools-C9IEkgc1.js.map +0 -1
  82. package/dist/devtools-panel-Doit__YG.js +0 -2018
  83. package/dist/devtools-panel-Doit__YG.js.map +0 -1
  84. package/dist/inspect-BSHv1_25.js.map +0 -1
  85. package/dist/navigate-OHb0Uw1P.js.map +0 -1
  86. package/dist/rpc-BAKbRWOT.js.map +0 -1
  87. package/dist/search-params-C64liRBj.js.map +0 -1
  88. package/dist/server-BVObWh-w.js.map +0 -1
  89. package/dist/store-BIBAYZo-.js.map +0 -1
  90. package/dist/stream-RXLadXx1.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serial-ioa17MuY.js","names":[],"sources":["../src/runtime/calls.ts","../src/runtime/serial.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/shared';\nimport * as v from 'seroval/validator';\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/shared';\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/** A scope ID, which is a number or a string. */\nconst scopeId = v.union(v.string, v.number);\n\n/** The index of a file in the form: a whole number from 0. */\nfunction isIndex(value: unknown): value is number {\n return Number.isSafeInteger(value) && (value as number) >= 0;\n}\n\n/** An array whose items are not checked: the plugin that reads them checks them. */\nfunction isArray(value: unknown): value is unknown[] {\n return Array.isArray(value);\n}\n\n/** The arguments of a handler: an array, or null when only modifiers follow. */\nfunction isArgs(value: unknown): value is unknown[] | null {\n return value === null || Array.isArray(value);\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 validate: { a: scopeId, b: v.number },\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 validate: { a: scopeId, b: v.number },\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 validate: { b: scopeId, c: v.number },\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 validate: { a: v.string, b: scopeId, c: isArgs, d: v.array(v.string) },\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 validate: { a: isArray },\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 validate: { a: v.string, b: scopeId, c: scopeId, d: v.number },\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 validate: { h: v.string },\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 validate: { c: v.string },\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 validate: { b: scopeId, c: v.number, d: v.number },\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<string>(node.t);\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<string>(node.n);\n const lastModified = node.l === undefined ? undefined : ctx.deserialize<number>(node.l);\n return new File([file], name, { type, lastModified });\n },\n validate: { i: isIndex, t: v.string, n: v.string, l: v.number },\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"],"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,SAA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,mBAAmB,QAAQ,oBAAoB;CAC/C,aAAa,QAAQ;CAErB,MAAM,UAAU,mBAAmB,CAAC;CACpC,IAAI,YAAY,GACd,QAAQ,KACN,6BAA6B,UAAU,QAAQ,SAAS,WAAW,sBAAsB,6BAA6B,UAAU,QAAQ,SAAS,qEAAqE,gEAAgE,EACxR;AAEJ,CAAC"}
@@ -0,0 +1 @@
1
+ export { t as BridgeDataError, n as callPlugins, r as disabledFeatures, i as plugins, a as serialOptions, o as syncPlugins, s as uploadPlugin } from "./serial-ioa17MuY.js";
@@ -2,13 +2,18 @@ import { n as closesParagraph, r as firstTag } from "./nesting-DA5vJw9X.js";
2
2
  import { n as MODIFIERS } from "./events-LgLdp1R7.js";
3
3
  import { C as spread$1, S as rawHTML, a as attribute$1, b as ownValue, d as escapeAttribute, f as handlerEntry, g as isRaw, n as VOID_ELEMENTS, p as insertValue, r as actionAttributes, s as bindEntry, u as escape, v as onAttribute, w as styleElement } from "./html-Cf5uKhLs.js";
4
4
  import { n as deleteCookie, o as setCookie, r as getCookies } from "./cookies-Cnbf4w-S.js";
5
- import { a as callPlugins, c as syncPlugins, i as BridgeDataError, l as functionReferences, o as plugins, r as toChunkStream, s as serialOptions, t as STREAM_TYPE } from "./stream-RXLadXx1.js";
6
- import { a as findStored, l as isForeignStore, m as sentForeignStore, n as Store, u as isStore } from "./store-BIBAYZo-.js";
7
- import { T as parseId, _ as isAsyncIterable, a as Binding, b as isSlotReference, c as ElementReference, d as PARTS, f as PropPromise, h as addEntryHandlers, l as FunctionReference, m as SlotReference, o as CHILDREN_REF, s as ChildrenReference, u as MemoError, v as isBinding } from "./search-params-C64liRBj.js";
5
+ import { a as serialOptions, c as functionReferences, i as plugins, n as callPlugins, o as syncPlugins, t as BridgeDataError } from "./serial-ioa17MuY.js";
6
+ import { d as isStore, h as sentForeignStore, n as Store, o as findStored, u as isForeignStore } from "./store-Cy4EEyZ7.js";
7
+ import { a as FunctionReference, c as PropPromise, d as addEntryHandlers, g as isSlotReference, i as ElementReference, m as isBinding, n as CHILDREN_REF, o as MemoError, p as isAsyncIterable, r as ChildrenReference, s as PARTS, t as Binding, u as SlotReference, x as parseId } from "./shared-CX_YacDm.js";
8
8
  import { n as serverSecrets } from "./secrets-BxagsJxJ.js";
9
+ import { t as ANSWER } from "./stream-read-BTsYstJY.js";
10
+ import "./search-params-Wg-0FsMj.js";
9
11
  import { i as missingContext } from "./context-CU4Fpn5a.js";
10
12
  import { a as applyIntent, d as formatPath, f as getAt, m as groupIssues, r as INTENT, u as formValues, v as parseIntent, y as parsePath } from "./forms-nXK7-Lv_.js";
11
- import { crossSerialize, crossSerializeStream, fromJSON, toJSON } from "seroval";
13
+ import { SerovalDeserializationError, SerovalMissingPluginError, SerovalPluginValidationError, fromJSON } from "seroval/read";
14
+ import { crossSerialize, crossSerializeStream, toJSON } from "seroval/write";
15
+ import { toWebStream } from "@seroval/transport/web";
16
+ import { createJSONWriter } from "@seroval/transport/write";
12
17
  //#region src/runtime/request.ts
13
18
  /** Where the server takes the error of a `waitUntil` promise that no host keeps, in place of the log. */
14
19
  const failures = {};
@@ -75,6 +80,11 @@ var RequestEvent = class {
75
80
  /** True while the build prerenders the page. */
76
81
  prerender;
77
82
  /**
83
+ * The Content Security Policy nonce of the render, from its `nonce` option. Undefined without
84
+ * one. A component that writes an inline script with `raw()` gives it this nonce.
85
+ */
86
+ nonce;
87
+ /**
78
88
  * The pattern of the route files that matched the path, such as
79
89
  * `/todos/[id]`. `handleRoute` sets it. Undefined for a path that no route
80
90
  * matches.
@@ -285,6 +295,7 @@ const IDEMPOTENT = Symbol.for("brumate.idempotent");
285
295
  const idempotentIds = /* @__PURE__ */ new Set();
286
296
  /** The ID of each function that `idempotent` made, once the server registered it. */
287
297
  const idempotentId = /* @__PURE__ */ new WeakMap();
298
+ const CALL_HOOK = Symbol.for("brumate.callHook");
288
299
  function dedupe(fn, id) {
289
300
  if (IDEMPOTENT in fn) {
290
301
  idempotentIds.add(id);
@@ -292,7 +303,10 @@ function dedupe(fn, id) {
292
303
  }
293
304
  const wrapper = ((...args) => {
294
305
  const cache = currentCalls;
295
- if (!cache) return fn(...args);
306
+ if (!cache) {
307
+ const hook = globalThis[CALL_HOOK];
308
+ return hook ? hook(id, () => fn(...args)) : fn(...args);
309
+ }
296
310
  let key;
297
311
  try {
298
312
  key = `${id} ${JSON.stringify(toJSON(args, {
@@ -503,6 +517,30 @@ async function revalidate(...tags) {
503
517
  await Promise.all(writes);
504
518
  }
505
519
  //#endregion
520
+ //#region src/runtime/stream.ts
521
+ /** The content type of a stream of messages. */
522
+ const STREAM_TYPE = "application/x-brumate-stream";
523
+ /**
524
+ * Serializes a value as a byte stream. `onError` gets the error of a value that cannot be
525
+ * serialized, which the reader only sees as a failed answer.
526
+ */
527
+ function toChunkStream(value, onCancel, onError) {
528
+ return toWebStream((sink) => {
529
+ const writer = createJSONWriter({
530
+ ...sink,
531
+ onError,
532
+ plugins,
533
+ ...serialOptions()
534
+ });
535
+ writer.write(ANSWER, value);
536
+ writer.flush();
537
+ return { close(reason) {
538
+ onCancel?.(reason);
539
+ writer.close(reason);
540
+ } };
541
+ });
542
+ }
543
+ //#endregion
506
544
  //#region src/runtime/router.ts
507
545
  function key(path, file, params) {
508
546
  return `${path}/${file} ${JSON.stringify(params)}`;
@@ -2945,6 +2983,7 @@ async function render(Root, props, options = {}) {
2945
2983
  prerender: options.prerender,
2946
2984
  onError: options.onError
2947
2985
  }) : void 0);
2986
+ if (event && options.nonce !== void 0) event.nonce = options.nonce;
2948
2987
  ctx.event = event;
2949
2988
  ctx.errors = event ? event.errors : errorSink(options.onError);
2950
2989
  const rendered = await ctx.run(() => Root(props, ctx));
@@ -3510,15 +3549,20 @@ async function handleForm(invoke, event) {
3510
3549
  * `file<index>`, whose index stands in the JSON.
3511
3550
  */
3512
3551
  async function readArgs(request) {
3513
- if (!request.headers.has("x-brumate-args")) return fromJSON(await request.json(), {
3514
- plugins,
3515
- ...serialOptions()
3516
- });
3517
- const form = await request.formData();
3518
- return fromJSON(JSON.parse(String(form.get("args"))), {
3519
- plugins: callPlugins(void 0, form),
3520
- ...serialOptions()
3521
- });
3552
+ try {
3553
+ if (!request.headers.has("x-brumate-args")) return fromJSON(await request.json(), {
3554
+ plugins,
3555
+ ...serialOptions()
3556
+ });
3557
+ const form = await request.formData();
3558
+ return fromJSON(JSON.parse(String(form.get("args"))), {
3559
+ plugins: callPlugins(void 0, form),
3560
+ ...serialOptions()
3561
+ });
3562
+ } catch (error) {
3563
+ if (error instanceof SerovalDeserializationError && (error.cause instanceof SerovalPluginValidationError || error.cause instanceof SerovalMissingPluginError)) throw new ServerError(`The arguments of the call are malformed: ${error.cause.message}`, { status: 400 });
3564
+ throw error;
3565
+ }
3522
3566
  }
3523
3567
  /**
3524
3568
  * True when a request comes from a page of another site. Server function
@@ -3613,7 +3657,7 @@ async function answerCall(functions, event, run) {
3613
3657
  if (ids.length > 0) headers.set("x-brumate-refresh", ids.join(","));
3614
3658
  }
3615
3659
  headers.set("content-type", STREAM_TYPE);
3616
- return respond(toChunkStream(result, (reason) => event.abort(reason)), { headers });
3660
+ return respond(toChunkStream(result, (reason) => event.abort(reason), (error) => logError(error, "call", event.errors, event)), { headers });
3617
3661
  } catch (error) {
3618
3662
  return callFailure(error, headers, event);
3619
3663
  }
@@ -3958,6 +4002,7 @@ async function handleRoute(tree, request, options = {}) {
3958
4002
  prerender: options.prerender,
3959
4003
  onError: options.onError
3960
4004
  });
4005
+ if (options.nonce !== void 0) event.nonce = options.nonce;
3961
4006
  event.route = match?.route;
3962
4007
  const answer = await routeAnswer(tree, match, url, {
3963
4008
  ...options,
@@ -4158,4 +4203,4 @@ function spread(attributes, on, names) {
4158
4203
  //#endregion
4159
4204
  export { dedupe as $, streamParts as A, ValidationError as B, setClientBundles as C, start as D, spread as E, RateLimitError as F, matchRoute as G, parse as H, clientAddress as I, revalidate as J, cached as K, configureRateLimit as L, wait as M, waitAll as N, stateScript as O, idempotent as P, ServerError as Q, rateLimit as R, renderToStream as S, spacerTag as T, parseForm as U, fieldErrors as V, safeParse as W, storageStore as X, setCacheStore as Y, RequestEvent as Z, memo as _, attribute as a, ready as b, children as c, handleRequest as d, defineMiddleware as et, handleRoute as f, lazy as g, isCrossSite as h, actionResult as i, withEvent as it, streamState as j, stateValue as k, component as l, insert as m, NotReady as n, isRedirect as nt, binding as o, inlineBodies as p, memoryStore as q, action as r, redirect as rt, caught as s, Context as t, getEvent as tt, dynamic as u, packState as v, settled as w, render as x, read as y, parseSubmission as z };
4160
4205
 
4161
- //# sourceMappingURL=server-BVObWh-w.js.map
4206
+ //# sourceMappingURL=server-BUuf7XPZ.js.map