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.
- package/dist/{boot-CMy0f_iC.d.ts → boot-DQuAhAd5.d.ts} +2 -2
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/{client-DnFF9_lv.d.ts → client-4eabQtYJ.d.ts} +38 -12
- package/dist/{client-COm1iA6w.js → client-CwVcmymi.js} +145 -28
- package/dist/client-CwVcmymi.js.map +1 -0
- package/dist/{defer-Cesb-k2Q.js → defer-BaXWydb0.js} +2 -2
- package/dist/{defer-Cesb-k2Q.js.map → defer-BaXWydb0.js.map} +1 -1
- package/dist/{devtools-C9IEkgc1.js → devtools-CMuj12yR.js} +257 -118
- package/dist/devtools-CMuj12yR.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-Cq8LpsyW.js +3978 -0
- package/dist/devtools-panel-Cq8LpsyW.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-DXS8RAtZ.js} +2 -2
- package/dist/{files-BuQvpBwF.js.map → files-DXS8RAtZ.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-B5AoHh5O.js} +639 -412
- package/dist/inspect-B5AoHh5O.js.map +1 -0
- package/dist/{loader-CLKrJMqw.js → loader-CTeT6ie9.js} +4 -4
- package/dist/{loader-CLKrJMqw.js.map → loader-CTeT6ie9.js.map} +1 -1
- package/dist/{navigate-OHb0Uw1P.js → navigate-Bj73X4ZS.js} +22 -8
- package/dist/navigate-Bj73X4ZS.js.map +1 -0
- package/dist/{rpc-BAKbRWOT.js → rpc-kVB0Ujdx.js} +5 -4
- package/dist/rpc-kVB0Ujdx.js.map +1 -0
- package/dist/runtime/bundles.d.ts +3 -2
- package/dist/runtime/bundles.js +14 -3
- package/dist/runtime/bundles.js.map +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-BM0-wdIc.js} +2 -2
- package/dist/{static-loader-CxANokZ4.js.map → static-loader-BM0-wdIc.js.map} +1 -1
- package/dist/{static-loader-BYbXVJDY.d.ts → static-loader-BSAyFqG0.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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-Cy4EEyZ7.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// Derived stores: a read-only store that computes its value from other stores, with the API of\n// Svelte 4's `derived`.\n\n/** The stores that `derived` reads: one store, or an array of them. */\nexport type Stores = StoreLike<any> | [StoreLike<any>, ...StoreLike<any>[]] | StoreLike<any>[];\n\n/** The values of `Stores`: a value for one store, an array of values for an array. */\nexport type StoresValues<S> =\n S extends StoreLike<infer U>\n ? U\n : { [K in keyof S]: S[K] extends StoreLike<infer U> ? U : never };\n\n/** The derived stores that heard of a change and wait to compute. */\nconst waiting: Computed[] = [];\n/** The listener sets that have a trailing listener, which computes the waiting stores. */\nconst armed = new Set<Set<unknown>>();\n/** True while the waiting stores compute. */\nlet flushing = false;\n\n/** Computes the waiting derived stores, the ones that read the fewest derived stores first. */\nfunction flushComputed(): void {\n flushing = true;\n try {\n while (waiting.length > 0) {\n let next = 0;\n for (let i = 1; i < waiting.length; i++) {\n if (waiting[i]!.level < waiting[next]!.level) {\n next = i;\n }\n }\n const [computed] = waiting.splice(next, 1);\n computed!.waits = false;\n computed!.run();\n }\n } catch (error) {\n // The stores that still wait would never hear a source again, so they leave the queue.\n for (const computed of waiting) {\n computed.waits = false;\n }\n waiting.length = 0;\n throw error;\n } finally {\n flushing = false;\n }\n}\n\n/** The state of a derived store while it has subscribers. */\ninterface Computed {\n /** The number of derived stores below it, so a store computes after the ones it reads. */\n level: number;\n /** True while it waits in the queue. */\n waits: boolean;\n run(): void;\n}\n\n/**\n * A store computed from `sources`. With a function of one parameter, the result is the value. With\n * two or three, the function calls `set` or `update`, and a function it returns runs before the\n * next call and when the last subscriber leaves. It follows its sources only while it has\n * subscribers; `get` computes from the sources otherwise. A source change that reaches it in one\n * pass computes it once, after the stores it reads.\n */\nexport function derived<S extends Stores, T>(\n sources: S,\n fn: (\n values: StoresValues<S>,\n set: (value: T) => void,\n update: (change: (value: T) => T) => void,\n ) => (() => void) | void,\n initial?: T,\n): StoreLike<T>;\nexport function derived<S extends Stores, T>(\n sources: S,\n fn: (values: StoresValues<S>) => T,\n initial?: T,\n): StoreLike<T>;\nexport function derived<T>(\n sources: Stores,\n fn: (\n values: unknown,\n set: (value: T) => void,\n update: (change: (value: T) => T) => void,\n ) => unknown,\n initial?: T,\n): StoreLike<T> {\n const single = !Array.isArray(sources);\n const list: StoreLike<unknown>[] = single ? [sources] : sources;\n for (const source of list) {\n if (!source) {\n throw new Error('derived() expects stores as input, got a falsy value');\n }\n }\n const auto = fn.length < 2;\n const out = new Store<T>(initial as T);\n const subscribers = new Set<() => void>();\n let level = 1;\n for (const source of list) {\n level = Math.max(level, ((source as { d?: number }).d ?? 0) + 1);\n }\n\n // The state of one run: `cleanup` is what `fn` returned, and `write` is where `set` goes.\n let cleanup: (() => void) | undefined;\n let started = false;\n let starting = false;\n let stops: (() => void)[] = [];\n\n /** Runs `fn` over the current values of the sources. */\n const compute = (write: (value: T) => void): void => {\n const values: unknown[] = [];\n for (const source of list) {\n values.push(source.get());\n }\n const set = write;\n const update = (change: (value: T) => T): void => write(change(out.v));\n cleanup?.();\n cleanup = undefined;\n const result = fn(single ? values[0] : values, set, update);\n if (auto) {\n write(result as T);\n } else if (typeof result === 'function') {\n cleanup = result as () => void;\n }\n };\n\n // The value is written without a notice while the first subscriber starts it, since nobody\n // listens yet and `subscribe` does not call the listener.\n const send = (value: T): void => {\n if (starting) {\n out.v = value;\n } else if (started) {\n sendStore(out, value);\n } else {\n // A late `set` after the last subscriber left keeps its value, as Svelte's store does.\n out.v = value;\n }\n };\n\n const state: Computed = {\n level,\n waits: false,\n run() {\n if (started) {\n compute(send);\n }\n },\n };\n\n /**\n * Called by a source. The store waits until the source has called all its listeners, so a store\n * that reads this one and the source computes once, after this one.\n */\n const heard = (source: StoreLike<unknown>): void => {\n if (!started || state.waits) {\n return;\n }\n state.waits = true;\n waiting.push(state);\n if (flushing) {\n return;\n }\n const listeners = (source as Partial<Store<unknown>>).l;\n if (!listeners || armed.has(listeners)) {\n if (!listeners) {\n // A store of another library has no listeners to wait behind.\n flushComputed();\n }\n return;\n }\n // A listener added now runs after the ones of the source, in the same send.\n const trail = (): void => {\n listeners.delete(trail);\n armed.delete(listeners);\n flushComputed();\n };\n armed.add(listeners);\n listeners.add(trail as never);\n };\n\n const start = (): void => {\n starting = true;\n started = true;\n try {\n compute(send);\n for (const source of list) {\n stops.push(source.subscribe(() => heard(source)));\n }\n } catch (error) {\n // A store that failed to start has no subscriptions, so it can start again.\n started = false;\n for (const end of stops) {\n end();\n }\n stops = [];\n cleanup?.();\n cleanup = undefined;\n throw error;\n } finally {\n starting = false;\n }\n };\n\n const stop = (): void => {\n started = false;\n for (const end of stops) {\n end();\n }\n stops = [];\n cleanup?.();\n cleanup = undefined;\n if (state.waits) {\n state.waits = false;\n waiting.splice(waiting.indexOf(state), 1);\n }\n };\n\n return Object.assign(\n {\n get(): T {\n if (started) {\n return out.v;\n }\n // No subscriber: compute once from the sources and stop. The async form keeps the\n // initial value until `set` runs.\n let value = out.v;\n started = true;\n try {\n compute((next) => {\n value = next;\n });\n } finally {\n started = false;\n cleanup?.();\n cleanup = undefined;\n }\n return value;\n },\n subscribe(listener: (value: T) => void): () => void {\n const stopListening = out.subscribe(listener);\n if (!started) {\n try {\n start();\n } catch (error) {\n stopListening();\n throw error;\n }\n }\n subscribers.add(stopListening);\n return () => {\n if (subscribers.delete(stopListening)) {\n stopListening();\n if (subscribers.size === 0) {\n stop();\n }\n }\n };\n },\n },\n { d: level },\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,OAAO,IAAI,cAAc;;AAGtC,SAAgB,UAAU,OAA2C;CACnE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA4B,QAAQ,YAC5C,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,KAC9B,CAAC,WAAW,KAAK;AAErB;;;;;;AAOA,SAAgB,WACd,OACA,MACA,OACA,KACoB;CACpB,MAAM,QAAQ,SAAS,KAAA,IAAY,QAAS,QAAgD;CAC5F,IAAI,CAAC,WAAW,KAAK,GAAG;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AE,MAAM,KAAK,MAAM,UACzC,UAAU,KAAK,MAAM,KAAK,IAAI,KAAA;CACnD;;CAGA,MAAc,OAAgB;EAC5B,IAAI,KAAK,KAAK,GACZ,KAAK,EAAG,EAAE,IAAK,KAAK,KAAK,GAAG,KAAK;OAEjC,KAAU,KAAK,CAAC,CAAC,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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { a as serialOptions, i as plugins } from "./serial-ioa17MuY.js";
|
|
2
|
+
import { fromWebStream } from "@seroval/transport/web";
|
|
3
|
+
import { createJSONReader } from "@seroval/transport/read";
|
|
4
|
+
//#region src/runtime/stream-read.ts
|
|
5
|
+
/** The key of the answer among the values of the stream. */
|
|
6
|
+
const ANSWER = "answer";
|
|
7
|
+
/**
|
|
8
|
+
* Reads the first value of a byte stream, and the rest in the background, so
|
|
9
|
+
* the promises and async iterables in it settle as their messages arrive.
|
|
10
|
+
*/
|
|
11
|
+
async function fromChunkStream(stream) {
|
|
12
|
+
const reader = createJSONReader({
|
|
13
|
+
plugins,
|
|
14
|
+
...serialOptions()
|
|
15
|
+
});
|
|
16
|
+
fromWebStream(stream, reader);
|
|
17
|
+
return reader.get(ANSWER);
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { fromChunkStream as n, ANSWER as t };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=stream-read-BTsYstJY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-read-BTsYstJY.js","names":[],"sources":["../src/runtime/stream-read.ts"],"sourcesContent":["// The read side of the answer of a server function. The browser loads only this\n// module, not the writer that the server uses (see `stream.ts`).\n\nimport { createJSONReader } from '@seroval/transport/read';\nimport { fromWebStream } from '@seroval/transport/web';\nimport { serialOptions, plugins } from './serial.ts';\n\n/** The key of the answer among the values of the stream. */\nexport const ANSWER = 'answer';\n\n/**\n * Reads the first value of a byte stream, and the rest in the background, so\n * the promises and async iterables in it settle as their messages arrive.\n */\nexport async function fromChunkStream(stream: ReadableStream<Uint8Array>): Promise<unknown> {\n const reader = createJSONReader({ plugins, ...serialOptions() });\n void fromWebStream(stream, reader);\n return reader.get(ANSWER);\n}\n"],"mappings":";;;;;AAQA,MAAa,SAAS;;;;;AAMtB,eAAsB,gBAAgB,QAAsD;CAC1F,MAAM,SAAS,iBAAiB;EAAE;EAAS,GAAG,cAAc;CAAE,CAAC;CAC/D,cAAmB,QAAQ,MAAM;CACjC,OAAO,OAAO,IAAI,MAAM;AAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as ANSWER, n as fromChunkStream } from "./stream-read-BTsYstJY.js";
|
package/dist/vite.d.ts
CHANGED
package/dist/vite.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as resolveFromDisk, D as entryClasses, F as parse, G as bridgeModuleId, H as resolveMacros, J as nameBridges, K as hasBridge, M as importedComponents, N as resolveRelative, O as refreshedNames, Q as getLocation, R as forEachNode, S as isReactiveModule, T as originalPosition, U as walk, _ as getComponentName, a as scopeLabel, b as generateShared, f as instanceScope, g as functionId, i as report, j as importSource, k as analyzeProject, n as formatReport, p as slotIndex, q as mayHaveBridge, s as compile, t as anchorLabel, v as hash, w as builtin, y as SHARED_QUERY, z as analyze } from "./inspect-B5AoHh5O.js";
|
|
2
2
|
import { s as toNodeHeaders } from "./cookies-Cnbf4w-S.js";
|
|
3
3
|
import { t as LOGO } from "./logo-DQ_OYhBi.js";
|
|
4
|
-
import { _ as findPackages, a as findScripts, b as resolveComponentPackage, d as isScriptFile, f as serverExports, g as findPackage, h as findBridgePackages, i as findFiles, l as hasServerMiddleware, m as serverStubs, n as defaultExclude, o as findServerFiles, p as serverModule, r as findBridgeFiles, s as findPackageServerFile, u as hasUseServer, v as packageFileName, y as reachableFiles } from "./files-
|
|
4
|
+
import { _ as findPackages, a as findScripts, b as resolveComponentPackage, d as isScriptFile, f as serverExports, g as findPackage, h as findBridgePackages, i as findFiles, l as hasServerMiddleware, m as serverStubs, n as defaultExclude, o as findServerFiles, p as serverModule, r as findBridgeFiles, s as findPackageServerFile, u as hasUseServer, v as packageFileName, y as reachableFiles } from "./files-DXS8RAtZ.js";
|
|
5
5
|
import { parseSync } from "oxc-parser";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
@@ -1755,6 +1755,11 @@ async function inBatches(list, run) {
|
|
|
1755
1755
|
return results;
|
|
1756
1756
|
}
|
|
1757
1757
|
const START = "virtual:brumate/start";
|
|
1758
|
+
/**
|
|
1759
|
+
* On the dev server, a client entry that imports `start` from `brumate/loader` gets this module
|
|
1760
|
+
* in its place. It sets up the hot updates and the devtools around `start`.
|
|
1761
|
+
*/
|
|
1762
|
+
const DEV_START = "virtual:brumate/dev-start";
|
|
1758
1763
|
/** Exports `load(id)`, which imports the client module of a component. */
|
|
1759
1764
|
const MANIFEST = "virtual:brumate/manifest";
|
|
1760
1765
|
/** `virtual:brumate/bundle/<id>` imports the client modules of a root component and those it renders. */
|
|
@@ -1858,7 +1863,8 @@ function getMarkup(result) {
|
|
|
1858
1863
|
const ranges = [
|
|
1859
1864
|
...file.instanceScript ? [file.instanceScript] : [],
|
|
1860
1865
|
...file.moduleScript ? [file.moduleScript] : [],
|
|
1861
|
-
...file.styles
|
|
1866
|
+
...file.styles,
|
|
1867
|
+
...file.blockStyles
|
|
1862
1868
|
];
|
|
1863
1869
|
forEachNode(file.children, (node) => {
|
|
1864
1870
|
if ("body" in node && node.body && "script" in node.body && node.body.script) ranges.push(node.body.script);
|
|
@@ -2799,6 +2805,18 @@ function brumate(options = {}) {
|
|
|
2799
2805
|
response.end(errorPage(error, server));
|
|
2800
2806
|
}
|
|
2801
2807
|
}
|
|
2808
|
+
let recording;
|
|
2809
|
+
async function recorder() {
|
|
2810
|
+
if (!recording) {
|
|
2811
|
+
const [{ AsyncLocalStorage }, { format }, { createRecorder }] = await Promise.all([
|
|
2812
|
+
import("node:async_hooks"),
|
|
2813
|
+
import("node:util"),
|
|
2814
|
+
import("./devtools-calls-DGW6nLZ2.js")
|
|
2815
|
+
]);
|
|
2816
|
+
recording = createRecorder(new AsyncLocalStorage(), format);
|
|
2817
|
+
}
|
|
2818
|
+
return recording;
|
|
2819
|
+
}
|
|
2802
2820
|
async function handleDevRPC(server, request, response) {
|
|
2803
2821
|
const id = decodeURIComponent((request.url ?? "").slice(rpc.length + 1).split("?")[0]);
|
|
2804
2822
|
const owner = id.split("#")[0];
|
|
@@ -2823,7 +2841,7 @@ function brumate(options = {}) {
|
|
|
2823
2841
|
body: new Uint8Array(await readBody(request))
|
|
2824
2842
|
});
|
|
2825
2843
|
const began = performance.now();
|
|
2826
|
-
const answer = await handle(webRequest, { address: request.socket.remoteAddress });
|
|
2844
|
+
const answer = await (await recorder())(() => handle(webRequest, { address: request.socket.remoteAddress }));
|
|
2827
2845
|
answer.headers.append("server-timing", `brumate;dur=${(performance.now() - began).toFixed(1)};desc="server function"`);
|
|
2828
2846
|
response.statusCode = answer.status;
|
|
2829
2847
|
for (const [name, value] of Object.entries(toNodeHeaders(answer.headers))) response.setHeader(name, value);
|
|
@@ -3178,7 +3196,8 @@ function brumate(options = {}) {
|
|
|
3178
3196
|
writeRouteTypes();
|
|
3179
3197
|
},
|
|
3180
3198
|
async resolveId(id, importer, resolveOptions) {
|
|
3181
|
-
if (
|
|
3199
|
+
if (isServe && id === "brumate/loader" && !resolveOptions?.ssr && importer !== `\0${START}` && importer !== `\0${DEV_START}`) return `\0${DEV_START}`;
|
|
3200
|
+
if (id === START || id === DEV_START || id === MANIFEST || id === SERVER || id === ROUTES || id === TESTING || id === BUNDLES || id === CLIENT_BUNDLES || id.startsWith(BUNDLE)) return `\0${id}`;
|
|
3182
3201
|
const env = resolveOptions?.ssr ? void 0 : envFile();
|
|
3183
3202
|
const from = importer?.split("?")[0];
|
|
3184
3203
|
if (env && importer && from && from !== env && isScriptFile(from) && !importer.startsWith("\0") && !importer.includes(SERVER_QUERY) && !importer.includes("/node_modules/")) {
|
|
@@ -3228,6 +3247,19 @@ function brumate(options = {}) {
|
|
|
3228
3247
|
vite: version
|
|
3229
3248
|
})}, import.meta.hot));`] : []
|
|
3230
3249
|
].join("\n");
|
|
3250
|
+
if (id === `\0${DEV_START}`) return [
|
|
3251
|
+
"import { start as startLoader } from 'brumate/loader';",
|
|
3252
|
+
"import { hotLoad } from 'brumate/hot';",
|
|
3253
|
+
"export { startWithoutNavigation } from 'brumate/loader';",
|
|
3254
|
+
"export function start(options) {",
|
|
3255
|
+
" const stop = startLoader({ ...options, load: hotLoad(import.meta.hot, options.load) });",
|
|
3256
|
+
...options.devtools !== false ? [` import('brumate/devtools').then((m) => m.installDevtools(${JSON.stringify(INSPECT)}, ${JSON.stringify(rpc)}, ${JSON.stringify({
|
|
3257
|
+
version: BRUMATE_VERSION,
|
|
3258
|
+
vite: version
|
|
3259
|
+
})}, import.meta.hot));`] : [],
|
|
3260
|
+
" return stop;",
|
|
3261
|
+
"}"
|
|
3262
|
+
].join("\n");
|
|
3231
3263
|
if (id === `\0${MANIFEST}`) return await manifest();
|
|
3232
3264
|
if (id === `\0${BUNDLES}`) {
|
|
3233
3265
|
const lines = [];
|