@barqjs/start 0.0.0-stage → 0.2.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +791 -2
  3. package/dist/client-BHyIiYxt.js +1527 -0
  4. package/dist/client-BHyIiYxt.js.map +1 -0
  5. package/dist/client-DHCV7yvQ.d.ts +440 -0
  6. package/dist/client-DHCV7yvQ.d.ts.map +1 -0
  7. package/dist/client.d.ts +3 -0
  8. package/dist/client.js +4 -0
  9. package/dist/env-qA8EyOr1.d.ts +49 -0
  10. package/dist/env-qA8EyOr1.d.ts.map +1 -0
  11. package/dist/env.d.ts +2 -0
  12. package/dist/env.js +44 -0
  13. package/dist/env.js.map +1 -0
  14. package/dist/index-Bm_-MTj6.d.ts +915 -0
  15. package/dist/index-Bm_-MTj6.d.ts.map +1 -0
  16. package/dist/index.d.ts +5 -0
  17. package/dist/index.js +6 -0
  18. package/dist/middleware-BdVlE8qm.d.ts +576 -0
  19. package/dist/middleware-BdVlE8qm.d.ts.map +1 -0
  20. package/dist/middleware.d.ts +2 -0
  21. package/dist/middleware.js +282 -0
  22. package/dist/middleware.js.map +1 -0
  23. package/dist/prerender.d.ts +98 -0
  24. package/dist/prerender.d.ts.map +1 -0
  25. package/dist/prerender.js +289 -0
  26. package/dist/prerender.js.map +1 -0
  27. package/dist/protocol.d.ts +58 -0
  28. package/dist/protocol.d.ts.map +1 -0
  29. package/dist/protocol.js +26 -0
  30. package/dist/protocol.js.map +1 -0
  31. package/dist/serve.d.ts +135 -0
  32. package/dist/serve.d.ts.map +1 -0
  33. package/dist/serve.js +223 -0
  34. package/dist/serve.js.map +1 -0
  35. package/dist/server-BV3xKmLa.js +1148 -0
  36. package/dist/server-BV3xKmLa.js.map +1 -0
  37. package/dist/server.d.ts +142 -0
  38. package/dist/server.d.ts.map +1 -0
  39. package/dist/server.js +1 -0
  40. package/dist/src-ChnB_xug.js +1140 -0
  41. package/dist/src-ChnB_xug.js.map +1 -0
  42. package/dist/static-fn-DgjNArBe.js +123 -0
  43. package/dist/static-fn-DgjNArBe.js.map +1 -0
  44. package/package.json +106 -4
  45. package/src/client.ts +672 -0
  46. package/src/context.ts +666 -0
  47. package/src/cookies.ts +229 -0
  48. package/src/env.ts +86 -0
  49. package/src/fn-error.ts +97 -0
  50. package/src/frames-client.ts +1216 -0
  51. package/src/frames-server.ts +464 -0
  52. package/src/frames.ts +285 -0
  53. package/src/index.ts +714 -0
  54. package/src/live-client.ts +50 -0
  55. package/src/live-server.ts +182 -0
  56. package/src/middleware.ts +994 -0
  57. package/src/prerender.ts +477 -0
  58. package/src/protocol.ts +61 -0
  59. package/src/rate-limit.ts +202 -0
  60. package/src/serve.ts +153 -0
  61. package/src/server.ts +990 -0
  62. package/src/session.ts +449 -0
  63. package/src/start-instance.ts +147 -0
  64. package/src/static-fn.ts +181 -0
  65. package/src/static.ts +302 -0
  66. package/src/stubs.ts +32 -0
  67. package/src/timing.ts +29 -0
  68. package/src/wire-types.ts +139 -0
@@ -0,0 +1,1527 @@
1
+ import { NOT_FOUND, REDIRECT, flattenMiddleware, runMiddleware } from "./middleware.js";
2
+ import { withRange } from "@barqjs/web/internal";
3
+ import { withoutClaim } from "@barqjs/core/internal";
4
+ import { decodeWire, encodeWire, registerSerializationAdapters } from "@barqjs/server/codec";
5
+ import { bindEvent, classToString, delegate, element, insert, isHydrating, onHydrationEnd, ref, setClass, setProp, setStyle, useHead } from "@barqjs/web";
6
+ import { block, createRenderEffect, createRoot, createSignal, getOwner, onCleanup, runWithOwner, untrack } from "@barqjs/core";
7
+ //#region src/fn-error.ts
8
+ /**
9
+ * A server function answered with a failure.
10
+ *
11
+ * THE MESSAGE IS NOT THE HANDLER'S, and that is deliberate rather than
12
+ * unfinished. `server.ts` refuses to put a handler's error text on the wire
13
+ * because it can name a table, a column or a filesystem path, and none of that
14
+ * is the caller's business — TanStack serialises the whole error object to the
15
+ * client instead. What a caller legitimately needs is the STATUS, so it is here
16
+ * as a field rather than something to parse back out of a string.
17
+ */
18
+ var ServerFnError = class extends Error {
19
+ status;
20
+ /**
21
+ * What was wrong with the input, for a 400 the validator refused: one entry
22
+ * per issue, with the path to the field it is about. Sent in every build,
23
+ * because it describes the caller's own input.
24
+ */
25
+ issues;
26
+ /**
27
+ * What the handler threw: its name, message and source-mapped stack. Only a
28
+ * development server sends it; in production this is `undefined`, so handle
29
+ * a failure by its `status` rather than by this.
30
+ */
31
+ thrown;
32
+ /**
33
+ * The answer itself, unread.
34
+ *
35
+ * The server's own refusals land here: a 400 for input, a 403 for an origin,
36
+ * a 404, a 405, a 413. A `Response` a middleware or a handler THREW is not
37
+ * wrapped at all; the call rejects with it. A handler's own failure has
38
+ * nothing here worth reading: the server answers those with one fixed line,
39
+ * for the reason above.
40
+ */
41
+ response;
42
+ constructor(id, status, response, answer) {
43
+ super(failureMessage(id, status, answer));
44
+ this.name = "ServerFnError";
45
+ this.status = status;
46
+ this.response = response;
47
+ if (answer?.issues !== void 0) this.issues = answer.issues;
48
+ if (answer?.thrown !== void 0) this.thrown = answer.thrown;
49
+ }
50
+ };
51
+ function failureMessage(id, status, answer) {
52
+ const issues = answer?.issues;
53
+ if (issues !== void 0 && issues.length > 0) return `The server function \`${id}\` refused its input (${status}): ${issues.map((issue) => issue.path === void 0 ? issue.message : `\`${issue.path.join(".")}\`: ${issue.message}`).join("; ")}. \`error.issues\` holds each issue with the path to its field.`;
54
+ const thrown = answer?.thrown;
55
+ if (thrown !== void 0) return `The server function \`${id}\` threw \`${thrown.name}: ${thrown.message}\` and answered ${status}. The server's stack is in \`error.thrown.stack\` and in the development overlay. A production server sends only the status, so handle a failure by \`error.status\`.`;
56
+ return `The server function \`${id}\` answered ${status}. A handler's own error text is never sent to the browser, so read it in the server's log. \`error.response\` holds the server's answer.`;
57
+ }
58
+ //#endregion
59
+ //#region src/stubs.ts
60
+ /** How `live` calls a stub at the live address, its client middleware around the fetch. */
61
+ const LIVE_CALL = Symbol.for("barq.server-fn.live");
62
+ /**
63
+ * Every stub this page has made, by id: what a frame the page carries asks for
64
+ * its connection through when it was called through `live` on the server.
65
+ */
66
+ const STUBS = /* @__PURE__ */ new Map();
67
+ function registerStub(id, stub) {
68
+ STUBS.set(id, stub);
69
+ }
70
+ function clientStub(id) {
71
+ return STUBS.get(id);
72
+ }
73
+ //#endregion
74
+ //#region src/frames.ts
75
+ /** The brand on a frame, on either side, carrying where it lives. */
76
+ const FRAME = Symbol.for("barq.frame");
77
+ /** Whether a value is a frame: a server function's component result, on either side. */
78
+ function isFrame(value) {
79
+ return typeof value === "function" && value[FRAME] !== void 0;
80
+ }
81
+ /**
82
+ * How a server function's component result becomes a frame, installed by
83
+ * `@barqjs/start/server`: on the global, because a server bundle and the host
84
+ * serving it each carry a copy of this module, and the copy that defines a
85
+ * server function is not always the one that imported the server half.
86
+ */
87
+ const MAKE = Symbol.for("barq.frames.make");
88
+ function installFrames(make) {
89
+ globalThis[MAKE] = make;
90
+ }
91
+ /** The handler's result, a frame when it is a component and the server half is here. */
92
+ function asFrame(id, data, result) {
93
+ const make = globalThis[MAKE];
94
+ if (make === void 0 || typeof result !== "function" || isFrame(result)) return result;
95
+ return make(id, data, result);
96
+ }
97
+ /** The element a frame's markup stands in. `display: contents`, so it takes no box. */
98
+ const FRAME_TAG = "barq-frame";
99
+ /** The element a nested region of server markup stands in, inside a slot's content. */
100
+ const REGION_TAG = "barq-region";
101
+ /** The `type` of the script that carries a frame's payload. Not JavaScript, so never run. */
102
+ const PAYLOAD_TYPE = "application/barq-frame";
103
+ /** The `x-barq-rpc` value a frame response carries. */
104
+ const RPC_FRAME = "frame";
105
+ /**
106
+ * The `x-barq-rpc` value of a mutation's answer that carries the regions it
107
+ * changed beside its value: single flight, one round trip for both.
108
+ */
109
+ const RPC_FLIGHT = "flight";
110
+ /**
111
+ * The request header a page sends with a mutation: the frames it has mounted,
112
+ * as `[{ id, args }]`, so the answer can carry the ones the mutation changed.
113
+ * Bounded, as a header is: a page with more mounted frames names the first ones.
114
+ */
115
+ const FRAMES_HEADER = "x-barq-frames";
116
+ /** The `type` of the script a single-flight answer carries its value in. */
117
+ const FLIGHT_TYPE = "application/barq-flight";
118
+ /** Dispatched on `document` once a frame update has been applied to the page. */
119
+ const FRAME_APPLIED_EVENT = "barq:frame-applied";
120
+ function slotOpen(at) {
121
+ return `s:${at}`;
122
+ }
123
+ function slotClose(at) {
124
+ return `/s:${at}`;
125
+ }
126
+ /** The marker index a comment's data names, or `-1` when it is not a slot's opening marker. */
127
+ function slotIndex(data) {
128
+ return data.startsWith("s:") ? Number(data.slice(2)) : -1;
129
+ }
130
+ /** The marker index a comment's data names, or `-1` when it is not a slot's closing marker. */
131
+ function slotEnd(data) {
132
+ return data.startsWith("/s:") ? Number(data.slice(3)) : -1;
133
+ }
134
+ /**
135
+ * A string of 32-bit FNV-1a, in base 36: short enough to be an attribute,
136
+ * stable across processes, which a frame's address has to be.
137
+ */
138
+ function digest(text) {
139
+ let hash = 2166136261;
140
+ for (let at = 0; at < text.length; at++) {
141
+ hash ^= text.charCodeAt(at);
142
+ hash = Math.imul(hash, 16777619);
143
+ }
144
+ return (hash >>> 0).toString(36);
145
+ }
146
+ /**
147
+ * Where a frame lives: the server function and what it was called with. One
148
+ * address is one region, so asking for it again updates that region rather
149
+ * than mounting a second one, and an answer for other arguments is another.
150
+ */
151
+ function frameAddress(id, wireArgs) {
152
+ return `${id}#${digest(JSON.stringify(wireArgs ?? null))}`;
153
+ }
154
+ /** The payload as the text of its script: `<` escaped, so no string in it can end the element. */
155
+ function payloadText(payload) {
156
+ return JSON.stringify(payload).replaceAll("<", "\\u003c");
157
+ }
158
+ /** The opening of a frame's markup, the payload's script included. */
159
+ function frameOpen(address, payload) {
160
+ const attribute = address.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;");
161
+ return `<${FRAME_TAG} data-frame="${attribute}" style="display:contents"><script type="${PAYLOAD_TYPE}">${payloadText(payload)}<\/script>`;
162
+ }
163
+ const FRAME_CLOSE = `</${FRAME_TAG}>`;
164
+ function regionMarkup(key, html) {
165
+ const attribute = key.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;");
166
+ return `<${REGION_TAG} data-region="${attribute}" style="display:contents">${html}</${REGION_TAG}>`;
167
+ }
168
+ function bindEntry(text) {
169
+ const colon = text.indexOf(":");
170
+ if (colon < 1) return null;
171
+ const at = Number(text.slice(0, colon));
172
+ if (!Number.isInteger(at)) return null;
173
+ const equals = text.indexOf("=", colon);
174
+ const key = decodeURIComponent(equals === -1 ? text.slice(colon + 1) : text.slice(colon + 1, equals));
175
+ return equals === -1 ? {
176
+ at,
177
+ key
178
+ } : {
179
+ at,
180
+ key,
181
+ member: decodeURIComponent(text.slice(equals + 1))
182
+ };
183
+ }
184
+ /** The entries of a marker attribute's value. */
185
+ function bindEntries(value) {
186
+ const out = [];
187
+ for (const text of value.split(",")) {
188
+ const entry = bindEntry(text);
189
+ if (entry !== null) out.push(entry);
190
+ }
191
+ return out;
192
+ }
193
+ /** The entry a text position's opening comment names, or `null` when it is not one. */
194
+ function bindTextEntry(data) {
195
+ return data.startsWith("_b:") ? bindEntry(data.slice(3)) : null;
196
+ }
197
+ //#endregion
198
+ //#region src/frames-client.ts
199
+ /**
200
+ * The browser half of frames: the component a server function's frame answer
201
+ * becomes, and the update that applies a new answer to every place it is
202
+ * mounted without building any of the page again.
203
+ *
204
+ * One component per address. Asking for a frame again hands back the SAME
205
+ * component, so a `dynamic` over it does not remount: the new markup is
206
+ * morphed into the region where it stands. Server nodes are patched in place,
207
+ * and a slot's content, which the browser owns, is kept, its arguments
208
+ * updated, and moved only when the server moved it.
209
+ */
210
+ const FRAMES = /* @__PURE__ */ new Map();
211
+ /**
212
+ * Keep a frame the page was served through `live` current: the connection a
213
+ * `live` call in the browser would have opened, through the same stub and so
214
+ * its client middleware, opened once the page has been claimed and closed
215
+ * when the last place the frame is mounted goes.
216
+ */
217
+ function connect(state) {
218
+ if (state.connection !== null || state.payload?.live !== true) return;
219
+ const stub = clientStub(state.ref.id);
220
+ if (stub === void 0) return;
221
+ const iterator = liveIterable(stub, { data: state.payload.args === void 0 ? void 0 : decodeWire(state.payload.args) })[Symbol.asyncIterator]();
222
+ const connection = { stop: () => void iterator.return?.() };
223
+ state.connection = connection;
224
+ (async () => {
225
+ try {
226
+ for (;;) if ((await iterator.next()).done === true) return;
227
+ } catch (error) {
228
+ console.error(`[barq] The live frame of ${JSON.stringify(state.ref.id)} could not stay connected, so it shows what it last received. The error:`, error);
229
+ } finally {
230
+ if (state.connection === connection) state.connection = null;
231
+ }
232
+ })();
233
+ }
234
+ function stateFor(ref) {
235
+ const known = FRAMES.get(ref.address);
236
+ if (known !== void 0) return known;
237
+ const [head, setHead] = createSignal([], { ownedWrite: true });
238
+ const state = {
239
+ ref,
240
+ payload: null,
241
+ markup: null,
242
+ mounts: /* @__PURE__ */ new Set(),
243
+ head,
244
+ setHead,
245
+ component: null,
246
+ connection: null
247
+ };
248
+ const component = (props) => mount(state, props);
249
+ state.component = Object.assign(component, { [FRAME]: ref });
250
+ FRAMES.set(ref.address, state);
251
+ return state;
252
+ }
253
+ /**
254
+ * How a frame named in the page's seed becomes the component for the region
255
+ * the page already carries. The client entry installs it beside the
256
+ * application's own adapters, before the seed is read.
257
+ */
258
+ const frameAdapter = {
259
+ key: "barq.frame",
260
+ test: isFrame,
261
+ toSerializable: (frame) => ({
262
+ id: frame[FRAME].id,
263
+ address: frame[FRAME].address
264
+ }),
265
+ fromSerializable: (ref) => stateFor(ref).component
266
+ };
267
+ function payloadOf(host) {
268
+ const script = host.firstElementChild;
269
+ if (script === null || script.localName !== "script") return null;
270
+ if (script.getAttribute("type") !== "application/barq-frame") return null;
271
+ const text = script.textContent ?? "";
272
+ return text === "" ? null : JSON.parse(text);
273
+ }
274
+ /** The frame's own script, which the morph leaves to `setPayload`. */
275
+ function isPayload(node) {
276
+ return node !== null && node.nodeType === 1 && node.localName === "script" && node.getAttribute("type") === "application/barq-frame";
277
+ }
278
+ function setPayload(host, payload) {
279
+ const script = host.firstElementChild;
280
+ if (script !== null && isPayload(script)) script.textContent = JSON.stringify(payload);
281
+ }
282
+ function recordAt(payload, at) {
283
+ return payload.slots.find((record) => record.at === at);
284
+ }
285
+ /** The comment that closes the slot `start` opens, among its siblings. */
286
+ function closeOf(start) {
287
+ const at = slotIndex(start.data);
288
+ for (let node = start.nextSibling; node !== null; node = node.nextSibling) if (node.nodeType === 8 && slotEnd(node.data) === at) return node;
289
+ return null;
290
+ }
291
+ function between(start, end) {
292
+ const out = [];
293
+ for (let node = start.nextSibling; node !== null && node !== end; node = node.nextSibling) out.push(node);
294
+ return out;
295
+ }
296
+ /** Every slot opening in `root` that no occurrence owns yet, in document order. */
297
+ function unfilled(root, owned) {
298
+ const walker = root.ownerDocument.createTreeWalker(root, NodeFilter.SHOW_COMMENT);
299
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
300
+ const comment = node;
301
+ if (slotIndex(comment.data) !== -1 && !owned.has(comment)) return comment;
302
+ }
303
+ return null;
304
+ }
305
+ function regionElement(key, markup) {
306
+ const region = document.createElement(REGION_TAG);
307
+ region.setAttribute("data-region", key);
308
+ region.setAttribute("style", "display:contents");
309
+ region.innerHTML = markup;
310
+ return region;
311
+ }
312
+ /**
313
+ * Fill one slot: the page's `children` where the server placed them, or the
314
+ * page's function for a named slot called with the occurrence's arguments.
315
+ *
316
+ * While the page is being claimed, the server's content for the slot is
317
+ * CLAIMED: the fill runs over a cursor on the slot's range, as the content of
318
+ * any other hole does, and takes the nodes the server wrote for it. Otherwise
319
+ * the slot is empty and the fill builds into it. A nested region the server
320
+ * wrote is handed to the fill as its children either way.
321
+ */
322
+ function fill(site, start, record) {
323
+ const end = closeOf(start);
324
+ if (end === null) return null;
325
+ const parent = end.parentNode;
326
+ if (parent === null) return null;
327
+ const served = between(start, end);
328
+ const claiming = site.claiming && served.length > 0;
329
+ let region = null;
330
+ if (record.hasRegion === true) {
331
+ for (const node of served) {
332
+ const found = node.nodeType === 1 && node.localName === "barq-region" ? node : node.nodeType === 1 ? node.querySelector(REGION_TAG) : null;
333
+ if (found !== null) {
334
+ region = found;
335
+ break;
336
+ }
337
+ }
338
+ if (!claiming) region?.remove();
339
+ region ??= regionElement(String(record.at), record.region ?? "");
340
+ }
341
+ if (!claiming) for (const node of served) node.parentNode?.removeChild(node);
342
+ const [args, setArgs] = createSignal(record.args === void 0 ? {} : decodeWire(record.args), { ownedWrite: true });
343
+ const given = site.props[record.name];
344
+ const content = () => {
345
+ if (record.name === "children") return given;
346
+ const fn = typeof given === "function" ? untrack(given) : given;
347
+ if (typeof fn !== "function") return fn ?? null;
348
+ const props = {};
349
+ for (const key of Object.keys(untrack(args))) props[key] = () => args()[key];
350
+ if (region !== null) {
351
+ const placed = region;
352
+ props.children = block(() => placed);
353
+ }
354
+ return untrack(() => fn(props));
355
+ };
356
+ const range = {
357
+ open: start,
358
+ close: end,
359
+ parent,
360
+ nodes: served
361
+ };
362
+ const dispose = claiming ? runWithOwner(site.owner, () => createRoot((release) => {
363
+ withRange(range, () => {
364
+ const value = content();
365
+ return typeof value === "function" ? value(getOwner()) : value;
366
+ });
367
+ return release;
368
+ })) : withoutClaim(() => runWithOwner(site.owner, () => createRoot((release) => {
369
+ insert(parent, content(), end);
370
+ return release;
371
+ })));
372
+ return {
373
+ key: record.key,
374
+ name: record.name,
375
+ start,
376
+ end,
377
+ region,
378
+ setArgs,
379
+ dispose
380
+ };
381
+ }
382
+ /** Fill every slot in the mount that has no content yet, outermost first. */
383
+ function fillAll(site, payload) {
384
+ for (;;) {
385
+ const start = unfilled(site.host, site.occurrences);
386
+ if (start === null) return;
387
+ const record = recordAt(payload, slotIndex(start.data));
388
+ const occurrence = record === void 0 ? null : fill(site, start, record);
389
+ site.occurrences.set(start, occurrence ?? DEAD);
390
+ }
391
+ }
392
+ const DEAD = {
393
+ key: "",
394
+ name: "",
395
+ start: null,
396
+ end: null,
397
+ region: null,
398
+ setArgs: () => {},
399
+ dispose: () => {}
400
+ };
401
+ function mount(state, props) {
402
+ const owner = getOwner();
403
+ const host = element(FRAME_TAG, {});
404
+ const adopted = host.getAttribute("data-frame") === state.ref.address && payloadOf(host) !== null;
405
+ if (!adopted) withoutClaim(() => {
406
+ host.setAttribute("data-frame", state.ref.address);
407
+ host.setAttribute("style", "display:contents");
408
+ host.innerHTML = `<script type="${PAYLOAD_TYPE}"><\/script>${state.markup ?? markupOnPage(state) ?? ""}`;
409
+ if (state.payload !== null) setPayload(host, state.payload);
410
+ });
411
+ state.payload ??= payloadOf(host);
412
+ const payload = state.payload ?? {
413
+ v: 1,
414
+ slots: [],
415
+ head: []
416
+ };
417
+ if (untrack(state.head).length === 0 && payload.head.length > 0) state.setHead(payload.head);
418
+ const placed = {
419
+ host,
420
+ owner,
421
+ props,
422
+ occurrences: /* @__PURE__ */ new Map(),
423
+ bindings: /* @__PURE__ */ new Map(),
424
+ claiming: adopted && isHydrating()
425
+ };
426
+ fillAll(placed, payload);
427
+ bindAll(placed, payload);
428
+ placed.claiming = false;
429
+ state.mounts.add(placed);
430
+ useHead(() => state.head());
431
+ if (adopted) onHydrationEnd(() => connect(state));
432
+ onCleanup(() => {
433
+ state.mounts.delete(placed);
434
+ for (const occurrence of placed.occurrences.values()) occurrence.dispose();
435
+ for (const binding of placed.bindings.values()) binding.dispose();
436
+ if (state.mounts.size === 0) state.connection?.stop();
437
+ });
438
+ return host;
439
+ }
440
+ /**
441
+ * A frame the page carries but this mount was not claimed over: one that
442
+ * rendered on the server and is mounted again after the page started, from a
443
+ * seed that named it. Its markup is taken from the page.
444
+ */
445
+ function markupOnPage(state) {
446
+ for (const candidate of document.querySelectorAll(FRAME_TAG)) {
447
+ if (candidate.getAttribute("data-frame") !== state.ref.address) continue;
448
+ state.payload ??= payloadOf(candidate);
449
+ const copy = candidate.cloneNode(true);
450
+ copy.firstElementChild?.remove();
451
+ for (const comment of commentsIn(copy)) {
452
+ if (slotIndex(comment.data) === -1) continue;
453
+ const end = closeOf(comment);
454
+ if (end !== null) for (const node of between(comment, end)) node.parentNode?.removeChild(node);
455
+ }
456
+ return copy.innerHTML;
457
+ }
458
+ return null;
459
+ }
460
+ /** Every comment in `root`, collected before the caller changes the tree around them. */
461
+ function commentsIn(root) {
462
+ const walker = (root.ownerDocument ?? document).createTreeWalker(root, NodeFilter.SHOW_COMMENT);
463
+ const out = [];
464
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) out.push(node);
465
+ return out;
466
+ }
467
+ /** The page's fill for a binding slot, run once: the object whose properties fill its positions. */
468
+ function bindOccurrence(site, record) {
469
+ const [args, setArgs] = createSignal(record.args === void 0 ? {} : decodeWire(record.args), { ownedWrite: true });
470
+ const given = site.props[record.name];
471
+ return runWithOwner(site.owner, () => createRoot((dispose) => {
472
+ const props = {};
473
+ for (const key of Object.keys(untrack(args))) props[key] = () => args()[key];
474
+ const result = withoutClaim(() => untrack(() => {
475
+ const fn = typeof given === "function" ? given() : given;
476
+ return typeof fn === "function" ? fn(props) : fn;
477
+ }));
478
+ let values = null;
479
+ if (typeof result === "object" && result !== null && !Array.isArray(result) && !(result instanceof Node)) values = result;
480
+ else if (given !== void 0) console.error(`[barq] The page's \`${record.name}\` fill returned ${result === null ? "null" : Array.isArray(result) ? "an array" : typeof result} where the server component reads it as data. A binding slot's fill returns a plain object whose properties fill the positions the server marked, so the server's values stay in place.`);
481
+ const binding = {
482
+ name: record.name,
483
+ owner: getOwner(),
484
+ values,
485
+ setArgs,
486
+ positions: /* @__PURE__ */ new Map(),
487
+ dispose: () => {
488
+ for (const at of binding.positions.values()) for (const release of at.values()) release();
489
+ binding.positions.clear();
490
+ dispose();
491
+ }
492
+ };
493
+ return binding;
494
+ }));
495
+ }
496
+ /** Every position marked in `root`, a nested frame's aside, in document order. */
497
+ function positionsIn(root) {
498
+ const out = [];
499
+ const walker = root.ownerDocument.createTreeWalker(root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT, { acceptNode: (node) => node !== root && node.nodeType === 1 && node.localName === "barq-frame" ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT });
500
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
501
+ if (node.nodeType === 8) {
502
+ const entry = bindTextEntry(node.data);
503
+ if (entry !== null) out.push({
504
+ node,
505
+ position: "",
506
+ entry
507
+ });
508
+ continue;
509
+ }
510
+ const element = node;
511
+ for (const name of element.getAttributeNames()) {
512
+ if (!name.startsWith("_b-")) continue;
513
+ const position = name.slice(3);
514
+ for (const entry of bindEntries(element.getAttribute(name) ?? "")) out.push({
515
+ node,
516
+ position,
517
+ entry
518
+ });
519
+ }
520
+ }
521
+ return out;
522
+ }
523
+ /**
524
+ * Bring the binding slot occurrences up to date with a payload: a new one's
525
+ * fill runs, a kept one's arguments move and its fill is not run again, and
526
+ * each position in the markup is bound once, a position the morph replaced or
527
+ * dropped released.
528
+ */
529
+ function bindAll(site, payload) {
530
+ const byAt = /* @__PURE__ */ new Map();
531
+ const next = /* @__PURE__ */ new Map();
532
+ for (const record of payload.slots) {
533
+ if (record.bind !== true) continue;
534
+ let binding = site.bindings.get(record.key);
535
+ if (binding !== void 0 && binding.name === record.name) {
536
+ if (record.args !== void 0) binding.setArgs(decodeWire(record.args));
537
+ } else binding = bindOccurrence(site, record);
538
+ next.set(record.key, binding);
539
+ byAt.set(record.at, binding);
540
+ }
541
+ for (const [key, binding] of site.bindings) if (next.get(key) !== binding) binding.dispose();
542
+ site.bindings = next;
543
+ if (next.size === 0) return;
544
+ const seen = /* @__PURE__ */ new Map();
545
+ for (const found of positionsIn(site.host)) {
546
+ const binding = byAt.get(found.entry.at);
547
+ if (binding === void 0 || binding.values === null) continue;
548
+ const id = `${found.position}|${found.entry.key}|${found.entry.member ?? ""}`;
549
+ let nodes = seen.get(binding);
550
+ if (nodes === void 0) seen.set(binding, nodes = /* @__PURE__ */ new Map());
551
+ let ids = nodes.get(found.node);
552
+ if (ids === void 0) nodes.set(found.node, ids = /* @__PURE__ */ new Set());
553
+ ids.add(id);
554
+ let at = binding.positions.get(found.node);
555
+ if (at === void 0) binding.positions.set(found.node, at = /* @__PURE__ */ new Map());
556
+ if (at.has(id)) continue;
557
+ const claiming = site.claiming;
558
+ const values = binding.values;
559
+ at.set(id, runWithOwner(binding.owner, () => createRoot((release) => {
560
+ bindPosition(found, values, claiming);
561
+ return release;
562
+ })));
563
+ }
564
+ for (const binding of next.values()) {
565
+ const nodes = seen.get(binding);
566
+ for (const [node, at] of binding.positions) {
567
+ const ids = nodes?.get(node);
568
+ for (const [id, release] of at) {
569
+ if (ids?.has(id) === true) continue;
570
+ release();
571
+ at.delete(id);
572
+ }
573
+ if (at.size === 0) binding.positions.delete(node);
574
+ }
575
+ }
576
+ }
577
+ function textOf(value) {
578
+ return typeof value === "string" ? value : typeof value === "number" || typeof value === "bigint" ? String(value) : "";
579
+ }
580
+ /**
581
+ * A detached element for the style a claimed position already shows: what
582
+ * `setStyle` would have applied, without writing to the page's element.
583
+ */
584
+ let scratch = null;
585
+ /**
586
+ * Fill one position from the fill's object. A value position follows the
587
+ * property, a handler and a ref are read once, as the page's own JSX reads
588
+ * them. While the page is claimed the server already wrote each value, so the
589
+ * first run writes nothing.
590
+ */
591
+ function bindPosition(found, values, claiming) {
592
+ const { node, position, entry } = found;
593
+ const read = () => values[entry.key];
594
+ if (position === "") {
595
+ const start = node;
596
+ let text;
597
+ if (start.nextSibling !== null && start.nextSibling.nodeType === 3) text = start.nextSibling;
598
+ else {
599
+ text = document.createTextNode("");
600
+ start.parentNode?.insertBefore(text, start.nextSibling);
601
+ }
602
+ createRenderEffect(() => textOf(read()), (value) => {
603
+ if (text.data !== value) text.data = value;
604
+ });
605
+ return;
606
+ }
607
+ const element = node;
608
+ if (position === "ref") {
609
+ ref(element, untrack(read));
610
+ return;
611
+ }
612
+ if (position.startsWith("on-")) {
613
+ const type = position.slice(3);
614
+ const capture = entry.member === "capture";
615
+ bindEvent(element, type, untrack(read), capture);
616
+ if (!capture) onCleanup(() => delegate(element, type, void 0));
617
+ return;
618
+ }
619
+ if (position === "class" && entry.member !== void 0) {
620
+ const name = entry.member;
621
+ createRenderEffect(() => Boolean(read()), (on) => {
622
+ if (element.classList.contains(name) !== on) element.classList.toggle(name, on);
623
+ });
624
+ return;
625
+ }
626
+ let applied;
627
+ let first = claiming;
628
+ if (position === "style") {
629
+ const member = entry.member;
630
+ createRenderEffect(() => member === void 0 ? read() : { [member]: read() }, (value) => {
631
+ if (first) {
632
+ first = false;
633
+ scratch ??= document.createElement("div");
634
+ scratch.removeAttribute("style");
635
+ applied = setStyle(scratch, "style", value);
636
+ return;
637
+ }
638
+ applied = setStyle(element, "style", value, applied);
639
+ });
640
+ return;
641
+ }
642
+ if (position === "class") {
643
+ createRenderEffect(read, (value) => {
644
+ if (first) {
645
+ first = false;
646
+ applied = classToString(value);
647
+ return;
648
+ }
649
+ applied = setClass(element, "class", value, applied);
650
+ });
651
+ return;
652
+ }
653
+ createRenderEffect(read, (value) => {
654
+ if (first) {
655
+ first = false;
656
+ return;
657
+ }
658
+ setProp(element, position, value);
659
+ });
660
+ }
661
+ function sameNode(current, next) {
662
+ if (current.nodeType !== next.nodeType) return false;
663
+ if (current.nodeType !== 1) return true;
664
+ const a = current;
665
+ const b = next;
666
+ return a.localName === b.localName && a.getAttribute("id") === b.getAttribute("id");
667
+ }
668
+ /**
669
+ * The positions of an element a binding slot fills, by its markers: whole
670
+ * attributes, and the class names and style properties it fills in object form.
671
+ */
672
+ function ownedBy(element) {
673
+ const owned = {
674
+ whole: /* @__PURE__ */ new Set(),
675
+ classes: /* @__PURE__ */ new Set(),
676
+ styles: /* @__PURE__ */ new Set()
677
+ };
678
+ for (const name of element.getAttributeNames()) {
679
+ if (!name.startsWith("_b-")) continue;
680
+ const position = name.slice(3);
681
+ if (position === "ref" || position.startsWith("on-")) continue;
682
+ for (const entry of bindEntries(element.getAttribute(name) ?? "")) if (entry.member === void 0) owned.whole.add(position);
683
+ else if (position === "class") owned.classes.add(entry.member);
684
+ else if (position === "style") owned.styles.add(entry.member);
685
+ }
686
+ return owned;
687
+ }
688
+ /**
689
+ * The server's attributes, written over the element's, except where the page
690
+ * fills a position: a whole attribute it fills is left as it stands, and the
691
+ * class names and style properties it fills keep their current state inside
692
+ * the server's new class and style.
693
+ */
694
+ function patchAttributes(current, next) {
695
+ const owned = ownedBy(next);
696
+ const classes = owned.classes.size > 0;
697
+ const styles = owned.styles.size > 0;
698
+ for (const name of current.getAttributeNames()) {
699
+ if (owned.whole.has(name) || name === "class" && classes || name === "style" && styles) continue;
700
+ if (!next.hasAttribute(name)) current.removeAttribute(name);
701
+ }
702
+ for (const name of next.getAttributeNames()) {
703
+ if (owned.whole.has(name) || name === "class" && classes || name === "style" && styles) continue;
704
+ const value = next.getAttribute(name) ?? "";
705
+ if (current.getAttribute(name) !== value) current.setAttribute(name, value);
706
+ }
707
+ if (classes) {
708
+ const tokens = new Set((next.getAttribute("class") ?? "").split(/\s+/).filter(Boolean));
709
+ for (const name of owned.classes) if (current.classList.contains(name)) tokens.add(name);
710
+ else tokens.delete(name);
711
+ const value = [...tokens].join(" ");
712
+ if ((current.getAttribute("class") ?? "") !== value) current.setAttribute("class", value);
713
+ }
714
+ if (styles) {
715
+ const style = current.style;
716
+ const kept = /* @__PURE__ */ new Map();
717
+ for (const property of owned.styles) {
718
+ const css = cssProperty(property);
719
+ kept.set(css, style.getPropertyValue(css));
720
+ }
721
+ const value = next.getAttribute("style");
722
+ if (current.getAttribute("style") !== value) {
723
+ if (value === null) current.removeAttribute("style");
724
+ else current.setAttribute("style", value);
725
+ for (const [css, text] of kept) if (text === "") style.removeProperty(css);
726
+ else style.setProperty(css, text);
727
+ }
728
+ }
729
+ }
730
+ /** A style object's key as the declaration's name, as `setStyle` writes it. */
731
+ function cssProperty(property) {
732
+ return property.startsWith("--") ? property : property.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
733
+ }
734
+ function isTextEnd(node) {
735
+ return node !== null && node.nodeType === 8 && node.data === "/_b";
736
+ }
737
+ function occurrenceAt(context, node) {
738
+ if (node === null || node.nodeType !== 8) return null;
739
+ const found = context.mount.occurrences.get(node);
740
+ return found === void 0 || found === DEAD ? null : found;
741
+ }
742
+ /** Move an occurrence's whole range, markers and content, to stand before `before`. */
743
+ function place(occurrence, parent, before) {
744
+ const nodes = [
745
+ occurrence.start,
746
+ ...between(occurrence.start, occurrence.end),
747
+ occurrence.end
748
+ ];
749
+ for (const node of nodes) parent.insertBefore(node, before);
750
+ }
751
+ function morphChildren(current, next, context) {
752
+ let cursor = current.firstChild;
753
+ if (isPayload(cursor)) cursor = cursor.nextSibling;
754
+ const incoming = [...next.childNodes];
755
+ for (let at = 0; at < incoming.length; at++) {
756
+ const node = incoming[at];
757
+ for (let standing = occurrenceAt(context, cursor); standing !== null;) {
758
+ cursor = standing.end.nextSibling;
759
+ standing = occurrenceAt(context, cursor);
760
+ }
761
+ const opening = node.nodeType === 8 ? slotIndex(node.data) : -1;
762
+ if (opening !== -1) {
763
+ let close = at + 1;
764
+ while (close < incoming.length) {
765
+ const candidate = incoming[close];
766
+ if (candidate.nodeType === 8 && slotEnd(candidate.data) === opening) break;
767
+ close++;
768
+ }
769
+ at = close;
770
+ const record = recordAt(context.payload, opening);
771
+ const kept = record === void 0 ? void 0 : context.keep.get(record.key);
772
+ if (kept !== void 0 && kept.name === record.name) {
773
+ context.keep.delete(kept.key);
774
+ context.used.add(kept);
775
+ if (kept.start.nextSibling !== cursor || kept.start.parentNode !== current) place(kept, current, cursor);
776
+ kept.start.data = slotOpen(opening);
777
+ kept.end.data = slotClose(opening);
778
+ continue;
779
+ }
780
+ current.insertBefore(document.createComment(slotOpen(opening)), cursor);
781
+ current.insertBefore(document.createComment(slotClose(opening)), cursor);
782
+ continue;
783
+ }
784
+ if (node.nodeType === 8 && bindTextEntry(node.data) !== null && cursor !== null && cursor.nodeType === 8 && cursor.data === node.data) {
785
+ while (at + 1 < incoming.length && !isTextEnd(incoming[at])) at++;
786
+ let end = cursor.nextSibling;
787
+ while (end !== null && !isTextEnd(end)) end = end.nextSibling;
788
+ cursor = end === null ? null : end.nextSibling;
789
+ continue;
790
+ }
791
+ if (cursor !== null && sameNode(cursor, node)) {
792
+ if (cursor.nodeType === 1) {
793
+ patchAttributes(cursor, node);
794
+ morphChildren(cursor, node, context);
795
+ } else if (cursor.nodeValue !== node.nodeValue) cursor.nodeValue = node.nodeValue;
796
+ cursor = cursor.nextSibling;
797
+ continue;
798
+ }
799
+ current.insertBefore(document.importNode(node, true), cursor);
800
+ }
801
+ while (cursor !== null) {
802
+ const standing = occurrenceAt(context, cursor);
803
+ if (standing !== null) {
804
+ cursor = standing.end.nextSibling;
805
+ continue;
806
+ }
807
+ const gone = cursor;
808
+ cursor = cursor.nextSibling;
809
+ current.removeChild(gone);
810
+ }
811
+ }
812
+ /** Apply a new answer to one mount: morph the region, then bring the occurrences up to date. */
813
+ function update(site, payload, markup) {
814
+ const next = document.createElement("template");
815
+ next.innerHTML = markup;
816
+ const keep = /* @__PURE__ */ new Map();
817
+ for (const occurrence of site.occurrences.values()) if (occurrence !== DEAD) keep.set(occurrence.key, occurrence);
818
+ const context = {
819
+ mount: site,
820
+ payload,
821
+ keep,
822
+ used: /* @__PURE__ */ new Set()
823
+ };
824
+ withoutClaim(() => {
825
+ morphChildren(site.host, next.content, context);
826
+ setPayload(site.host, payload);
827
+ });
828
+ const occurrences = /* @__PURE__ */ new Map();
829
+ for (const occurrence of context.used) {
830
+ occurrences.set(occurrence.start, occurrence);
831
+ const record = recordAt(payload, slotIndex(occurrence.start.data));
832
+ if (record === void 0) continue;
833
+ if (record.args !== void 0) occurrence.setArgs(decodeWire(record.args));
834
+ if (occurrence.region !== null && record.region !== void 0) {
835
+ const region = document.createElement("template");
836
+ region.innerHTML = record.region;
837
+ withoutClaim(() => morphChildren(occurrence.region, region.content, context));
838
+ for (const nested of context.used) occurrences.set(nested.start, nested);
839
+ }
840
+ }
841
+ for (const occurrence of site.occurrences.values()) {
842
+ if (occurrence === DEAD || context.used.has(occurrence)) continue;
843
+ occurrence.dispose();
844
+ for (const node of [
845
+ occurrence.start,
846
+ ...between(occurrence.start, occurrence.end),
847
+ occurrence.end
848
+ ]) node.parentNode?.removeChild(node);
849
+ }
850
+ site.occurrences.clear();
851
+ for (const [start, occurrence] of occurrences) site.occurrences.set(start, occurrence);
852
+ fillAll(site, payload);
853
+ bindAll(site, payload);
854
+ }
855
+ /**
856
+ * The region's stylesheets, loaded before it is shown: a region revealed
857
+ * before its styles is the flash a server render exists to prevent. Each is
858
+ * the element `useHead` takes over when the frame mounts.
859
+ */
860
+ async function loadStylesheets(head) {
861
+ const loading = [];
862
+ for (const tag of head) {
863
+ const props = tag.props ?? {};
864
+ if (tag.tag !== "link" || props.rel !== "stylesheet" || typeof props.href !== "string") continue;
865
+ const key = `link:stylesheet:${props.href}`;
866
+ let present = false;
867
+ for (const candidate of document.head.querySelectorAll("[data-bh]")) if (candidate.getAttribute("data-bh") === key) present = true;
868
+ if (present) continue;
869
+ const link = document.createElement("link");
870
+ link.rel = "stylesheet";
871
+ link.href = props.href;
872
+ link.setAttribute("data-bh", key);
873
+ loading.push(new Promise((resolve) => {
874
+ link.addEventListener("load", () => resolve(), { once: true });
875
+ link.addEventListener("error", () => resolve(), { once: true });
876
+ }));
877
+ document.head.appendChild(link);
878
+ }
879
+ await Promise.all(loading);
880
+ }
881
+ /**
882
+ * Read a frame answer and apply it: the component for its address, the same
883
+ * one every time, with every place it is mounted morphed to the new markup
884
+ * once the region's stylesheets have loaded.
885
+ */
886
+ async function applyFrameResponse(response) {
887
+ const template = document.createElement("template");
888
+ template.innerHTML = await response.text();
889
+ return applyFrameMarkup(template.content.firstElementChild);
890
+ }
891
+ /** A frame's markup as text, a live event's, applied as a frame answer is. */
892
+ function applyFrameText(markup) {
893
+ const template = document.createElement("template");
894
+ template.innerHTML = markup;
895
+ return applyFrameMarkup(template.content.firstElementChild);
896
+ }
897
+ /** One frame's markup, applied to every place its address is mounted. */
898
+ async function applyFrameMarkup(host) {
899
+ const address = host?.getAttribute("data-frame") ?? null;
900
+ const payload = host === null ? null : payloadOf(host);
901
+ if (host === null || address === null || payload === null) throw new Error("[barq] A server function answered with a frame whose markup has no `barq-frame` element and payload, so there is nothing to apply. The server and this page were built from different versions: reload the page.");
902
+ if (payload.v !== 1) throw new Error(`[barq] A server function answered with frame version ${payload.v}, and this page reads version 1. The server was deployed after this page loaded: reload the page.`);
903
+ host.firstElementChild?.remove();
904
+ const markup = host.innerHTML;
905
+ const state = stateFor({
906
+ id: address.slice(0, address.lastIndexOf("#")),
907
+ address
908
+ });
909
+ await loadStylesheets(payload.head);
910
+ state.payload = payload;
911
+ state.markup = markup;
912
+ state.setHead(payload.head);
913
+ for (const placed of state.mounts) update(placed, payload, markup);
914
+ document.dispatchEvent(new CustomEvent(FRAME_APPLIED_EVENT, { detail: { address } }));
915
+ return state.component;
916
+ }
917
+ /**
918
+ * What a mutation sends so its answer can carry the regions it changed: every
919
+ * mounted frame's function and arguments, up to the budget, or `null` with
920
+ * none mounted.
921
+ */
922
+ function mountedFramesHeader() {
923
+ const out = [];
924
+ for (const state of FRAMES.values()) {
925
+ if (state.mounts.size === 0 || state.payload === null) continue;
926
+ out.push({
927
+ id: state.ref.id,
928
+ args: state.payload.args
929
+ });
930
+ if (out.length === 32) break;
931
+ }
932
+ return out.length === 0 ? null : JSON.stringify(out);
933
+ }
934
+ /**
935
+ * A mutation's single-flight answer: each region it carries applied where it
936
+ * is mounted, then the value, which is what the caller is handed.
937
+ */
938
+ async function applyFlight(response) {
939
+ const template = document.createElement("template");
940
+ template.innerHTML = await response.text();
941
+ const script = template.content.firstElementChild;
942
+ if (script === null || script.localName !== "script" || script.getAttribute("type") !== "application/barq-flight") throw new Error("[barq] A server function answered with a single flight whose value script is missing, so there is no value to hand the caller. The server and this page were built from different versions: reload the page.");
943
+ const value = decodeWire(JSON.parse(script.textContent ?? "null"));
944
+ for (const host of template.content.children) if (host.localName === "barq-frame") await applyFrameMarkup(host);
945
+ return value;
946
+ }
947
+ /** The events of a `text/event-stream` body, as the spec frames them. */
948
+ async function* eventsOf(body) {
949
+ const reader = body.getReader();
950
+ const decoder = new TextDecoder();
951
+ let pending = "";
952
+ let event = "message";
953
+ let id = null;
954
+ let data = [];
955
+ try {
956
+ for (;;) {
957
+ const { done, value } = await reader.read();
958
+ pending += done ? decoder.decode() : decoder.decode(value, { stream: true });
959
+ let end = pending.search(/\r\n|\r|\n/);
960
+ while (end !== -1) {
961
+ const line = pending.slice(0, end);
962
+ pending = pending.slice(end + (pending.startsWith("\r\n", end) ? 2 : 1));
963
+ if (line === "") {
964
+ if (data.length > 0 || event !== "message") yield {
965
+ event,
966
+ id,
967
+ data: data.join("\n")
968
+ };
969
+ event = "message";
970
+ data = [];
971
+ } else if (!line.startsWith(":")) {
972
+ const colon = line.indexOf(":");
973
+ const field = colon === -1 ? line : line.slice(0, colon);
974
+ const text = colon === -1 ? "" : line.slice(colon + 1).replace(/^ /, "");
975
+ if (field === "data") data.push(text);
976
+ else if (field === "event") event = text;
977
+ else if (field === "id") id = text;
978
+ }
979
+ end = pending.search(/\r\n|\r|\n/);
980
+ }
981
+ if (done) return;
982
+ }
983
+ } finally {
984
+ reader.cancel().catch(() => {});
985
+ }
986
+ }
987
+ /** Statuses that say "ask again" even though they refuse this time. */
988
+ const RETRY = /* @__PURE__ */ new Set([
989
+ 408,
990
+ 425,
991
+ 429
992
+ ]);
993
+ /** How long to wait before the next connection, the nth failure in a row. */
994
+ function pause(failures, signal) {
995
+ const ms = Math.min(3e4, 250 * 2 ** failures);
996
+ return new Promise((resolve) => {
997
+ const timer = setTimeout(done, ms);
998
+ function done() {
999
+ clearTimeout(timer);
1000
+ globalThis.removeEventListener?.("online", done);
1001
+ signal.removeEventListener("abort", done);
1002
+ resolve();
1003
+ }
1004
+ globalThis.addEventListener?.("online", done, { once: true });
1005
+ signal.addEventListener("abort", done, { once: true });
1006
+ });
1007
+ }
1008
+ /** The reconnecting iteration of one live call. */
1009
+ function liveIterable(stub, options) {
1010
+ const iterable = { [Symbol.asyncIterator]: () => {
1011
+ const controller = new AbortController();
1012
+ const running = loop(stub, options, iterable, controller);
1013
+ return {
1014
+ next: () => running.next(),
1015
+ return: (value) => {
1016
+ controller.abort();
1017
+ return running.return(value);
1018
+ }
1019
+ };
1020
+ } };
1021
+ return iterable;
1022
+ }
1023
+ async function* loop(stub, options, told, controller) {
1024
+ let lastEventId = null;
1025
+ let failures = 0;
1026
+ let connected = false;
1027
+ try {
1028
+ for (;;) {
1029
+ let response;
1030
+ try {
1031
+ response = await stub[LIVE_CALL](options, {
1032
+ lastEventId,
1033
+ signal: controller.signal
1034
+ });
1035
+ } catch (error) {
1036
+ if (controller.signal.aborted) return;
1037
+ if (!connected) throw error;
1038
+ told.onstatus?.("reconnecting", error);
1039
+ await pause(failures++, controller.signal);
1040
+ continue;
1041
+ }
1042
+ if (!response.ok || response.body === null) {
1043
+ const retries = RETRY.has(response.status) || response.headers.has("retry-after");
1044
+ const error = new ServerFnError(stub.meta.id, response.status, response);
1045
+ if (!connected || !retries && response.status >= 400 && response.status < 500) throw error;
1046
+ told.onstatus?.("reconnecting", error);
1047
+ await pause(failures++, controller.signal);
1048
+ continue;
1049
+ }
1050
+ connected = true;
1051
+ failures = 0;
1052
+ told.onstatus?.("connected");
1053
+ let yielded = void 0;
1054
+ let complete = false;
1055
+ let died = /* @__PURE__ */ new Error(`[barq] The live connection of ${JSON.stringify(stub.meta.id)} ended before it was complete.`);
1056
+ try {
1057
+ for await (const event of eventsOf(response.body)) {
1058
+ if (event.event === "complete") {
1059
+ complete = true;
1060
+ break;
1061
+ }
1062
+ if (event.id !== null) lastEventId = event.id;
1063
+ const data = JSON.parse(event.data);
1064
+ if (event.event === "frame") {
1065
+ const component = await applyFrameText(data);
1066
+ if (component !== yielded) {
1067
+ yielded = component;
1068
+ yield component;
1069
+ }
1070
+ continue;
1071
+ }
1072
+ yield decodeWire(data);
1073
+ }
1074
+ } catch (error) {
1075
+ died = error;
1076
+ }
1077
+ if (complete || controller.signal.aborted) return;
1078
+ told.onstatus?.("reconnecting", died);
1079
+ await pause(failures++, controller.signal);
1080
+ }
1081
+ } finally {
1082
+ controller.abort();
1083
+ told.onstatus?.("closed");
1084
+ }
1085
+ }
1086
+ //#endregion
1087
+ //#region src/start-instance.ts
1088
+ /**
1089
+ * The application-wide middleware, declared once.
1090
+ *
1091
+ * TanStack Start's `createStart`, written in a project's `src/start.ts`:
1092
+ *
1093
+ * ```ts
1094
+ * export const startInstance = createStart(() => ({
1095
+ * requestMiddleware: [logging],
1096
+ * functionMiddleware: [requireSession],
1097
+ * }));
1098
+ * ```
1099
+ *
1100
+ * Its own module, importing nothing that reaches `node:async_hooks`, because
1101
+ * the client stub reads it: a global function middleware's client half runs in
1102
+ * the browser around every call.
1103
+ */
1104
+ /**
1105
+ * One instance for the process, whichever copy of this module asks.
1106
+ *
1107
+ * It is configuration, fixed once the application has loaded, so it has none
1108
+ * of the hazards an ambient request would: nothing a visitor does changes it.
1109
+ * On the global registry for the reason the server-function registry is: a
1110
+ * build compiles this module into its server bundle, and a host serving that
1111
+ * bundle through its own `serveBarq` has imported a second copy.
1112
+ */
1113
+ const REGISTERED = globalThis[Symbol.for("barq.start.instance")] ??= { instance: null };
1114
+ const NONE = Object.freeze({});
1115
+ /**
1116
+ * Declare the application's global middleware.
1117
+ *
1118
+ * The function is called once, the first time anything asks, so a middleware
1119
+ * module that imports this one back is fully evaluated by then.
1120
+ */
1121
+ function createStart(options) {
1122
+ let resolved;
1123
+ const instance = { getOptions: () => {
1124
+ if (resolved === void 0) {
1125
+ resolved = options();
1126
+ if (resolved.serializationAdapters !== void 0) registerSerializationAdapters(resolved.serializationAdapters);
1127
+ }
1128
+ return resolved;
1129
+ } };
1130
+ REGISTERED.instance = instance;
1131
+ return instance;
1132
+ }
1133
+ /** What the application declared, or nothing. */
1134
+ function startOptions() {
1135
+ return REGISTERED.instance?.getOptions() ?? NONE;
1136
+ }
1137
+ /** Test seam. Not for application use. */
1138
+ function clearStart() {
1139
+ REGISTERED.instance = null;
1140
+ }
1141
+ //#endregion
1142
+ //#region src/live-client.ts
1143
+ /** Whether a server function is the server half, which runs in this process. */
1144
+ function inProcess(fn) {
1145
+ return typeof fn === "function" && "built" in fn;
1146
+ }
1147
+ /**
1148
+ * Declare a server function's answer a standing one. In the browser, calling
1149
+ * the result returns an iterable that stays connected; on the server it is the
1150
+ * call itself, a frame it answers with marked for the page to connect.
1151
+ */
1152
+ function live(fn) {
1153
+ if (inProcess(fn)) return ((...args) => fn(...args).then((answer) => {
1154
+ const frame = typeof answer === "function" ? answer[FRAME] : void 0;
1155
+ if (frame !== void 0) frame.live = true;
1156
+ return answer;
1157
+ }));
1158
+ return ((options) => liveIterable(fn, options));
1159
+ }
1160
+ //#endregion
1161
+ //#region src/client.ts
1162
+ /**
1163
+ * The client half of a server function, and NOTHING the server half needs.
1164
+ *
1165
+ * Its own module because of what importing it costs. The compiler replaces a
1166
+ * server-function module's contents with `export const x = clientRpc("<id>")`,
1167
+ * and that stub used to import from `@barqjs/start` — whose index re-exports
1168
+ * `context.ts`, which is `node:async_hooks`. Every client bundle that reached
1169
+ * one server function therefore pulled the request-context machinery, the
1170
+ * middleware runner, the validators and the error classes, and Vite printed
1171
+ * "node:async_hooks has been externalized for browser compatibility" on every
1172
+ * build.
1173
+ *
1174
+ * That was survivable while a route module was `lazy()`, because the cost sat
1175
+ * in that route's own chunk. It stopped being survivable when `routeTree.gen.ts`
1176
+ * started importing route modules STATICALLY: measured on
1177
+ * `packages/kitchen-sink`, 25.7 kB of it moved into the set every page
1178
+ * preloads, for an application with two server functions on one route.
1179
+ *
1180
+ * So the stub imports from here. `index.ts` re-exports every name below, so an
1181
+ * application still writes `import { createServerFn } from "@barqjs/start"` and
1182
+ * nothing about the authoring surface changes.
1183
+ */
1184
+ const SERVER_FN = Symbol.for("barq.server-fn");
1185
+ /** Where mounted server functions answer. */
1186
+ const RPC_PREFIX = "/_barq/fn/";
1187
+ /**
1188
+ * What distinguishes an RPC call from a form submission: the URL, not a header.
1189
+ *
1190
+ * `/_barq/fn/<id>` is what `<form action={fn}>` writes, takes `FormData`, and
1191
+ * answers with a redirect a browser can follow with JS disabled.
1192
+ * `/_barq/fn/<id>.data` is the JSON channel and answers with a value.
1193
+ *
1194
+ * React Router's `.data` suffix, and the reason is its reason: a header decides
1195
+ * the response shape invisibly, and a form cannot set one. RedwoodSDK shows the
1196
+ * failure — it emits the right hidden fields for a no-JS submit and never reads
1197
+ * them, so the form posts, returns 200, and nothing happens.
1198
+ */
1199
+ const DATA_SUFFIX = ".data";
1200
+ /**
1201
+ * `/_barq/fn/<id>.live` is the live address: the data address's answer, framed
1202
+ * as server-sent events for as long as it stands. Its own URL, because a cache
1203
+ * keys on the URL and not on a header nothing tells it to vary by.
1204
+ */
1205
+ const LIVE_SUFFIX = ".live";
1206
+ /**
1207
+ * How the data channel says "the answer is an instruction, not a value".
1208
+ *
1209
+ * A HEADER rather than a body sniff, so a caller that does not care never
1210
+ * parses the body to find out, and so a handler returning a plain object that
1211
+ * happens to have a `to` field is never mistaken for a redirect.
1212
+ */
1213
+ const RPC_CONTROL = "x-barq-rpc";
1214
+ /**
1215
+ * The {@link RPC_CONTROL} value for a `Response` the handler returned.
1216
+ *
1217
+ * The response IS the result then, and its body is whatever the handler wrote,
1218
+ * so the stub hands it back whole rather than reading it as a wire value. No
1219
+ * body rides under this one, which is why it is not an {@link RpcControl} kind.
1220
+ */
1221
+ const RPC_RESPONSE = "response";
1222
+ /**
1223
+ * The {@link RPC_CONTROL} value for a `Response` a handler, a validator or a
1224
+ * middleware THREW: the call rejects with that response itself, as TanStack's
1225
+ * does. Its body and status are what the author wrote for the caller.
1226
+ */
1227
+ const RPC_THROWN = "thrown";
1228
+ /**
1229
+ * The {@link RPC_CONTROL} value for an answer that arrives over time.
1230
+ *
1231
+ * The body is then one JSON line for each value the function yielded, each
1232
+ * holding a wire-encoded value, and the stub hands the caller an async iterable
1233
+ * of them. A line that says the function failed ends it with a
1234
+ * {@link ServerFnError}.
1235
+ */
1236
+ const RPC_STREAM = "stream";
1237
+ /**
1238
+ * Present when a middleware's `sendContext` rides back with the result.
1239
+ *
1240
+ * A HEADER flagging a different body shape, which is what `RPC_CONTROL` already
1241
+ * does and for the same reason: an ordinary call — every call, in almost every
1242
+ * application — must not pay a second parse or a wrapper object to carry
1243
+ * something it does not have. With the flag the body is `{ result, context }`;
1244
+ * without it the body IS the result, byte for byte as before.
1245
+ */
1246
+ const RPC_CONTEXT = "x-barq-ctx";
1247
+ /**
1248
+ * A redirect that arrived over the wire, rebuilt on the client.
1249
+ *
1250
+ * NOT `@barqjs/router`'s `Redirect` — this package cannot construct that one.
1251
+ * It carries the same brand, so `isRedirect` from the router accepts it and the
1252
+ * router navigates on it exactly as it would on a redirect a loader threw. That
1253
+ * interchangeability is the whole reason those predicates are brand checks
1254
+ * rather than `instanceof`.
1255
+ */
1256
+ var RpcRedirect = class extends Error {
1257
+ [REDIRECT] = true;
1258
+ to;
1259
+ status;
1260
+ statusCode;
1261
+ /**
1262
+ * The navigation an options-form redirect described: `to`, `params`,
1263
+ * `search`, `hash`, `replace`, `reloadDocument`, `href`. The router goes
1264
+ * there in place of `to` when it is present.
1265
+ */
1266
+ options;
1267
+ constructor(to, status, options) {
1268
+ super(`redirect to ${to}`);
1269
+ this.name = "Redirect";
1270
+ this.to = to;
1271
+ this.status = status;
1272
+ this.statusCode = status;
1273
+ this.options = options;
1274
+ }
1275
+ };
1276
+ /** The `notFound()` counterpart, branded for the same reason. */
1277
+ var RpcNotFound = class extends Error {
1278
+ [NOT_FOUND] = true;
1279
+ isNotFound = true;
1280
+ /** What `notFound({ data })` carried, for the `notFoundComponent` that renders this. */
1281
+ data;
1282
+ /** The route whose `notFoundComponent` answers, when the thrower named one. */
1283
+ routeId;
1284
+ constructor(message, data, routeId) {
1285
+ super(message);
1286
+ this.name = "NotFound";
1287
+ this.data = data;
1288
+ this.routeId = routeId;
1289
+ }
1290
+ };
1291
+ /** The JSON a failed call answered with, read from a copy so `error.response` stays unread. */
1292
+ async function failedAnswer(response) {
1293
+ if (!(response.headers.get("content-type") ?? "").includes("application/json")) return void 0;
1294
+ try {
1295
+ return await response.clone().json();
1296
+ } catch {
1297
+ return;
1298
+ }
1299
+ }
1300
+ /**
1301
+ * The request header every GET call the stub makes carries, and is refused
1302
+ * without.
1303
+ *
1304
+ * A link, an `<img>`, a prefetch and a navigation cannot set a header; only
1305
+ * script can, and a cross-origin script that sets one is preflighted and
1306
+ * refused by the origin check. So a `GET` server function stays out of reach
1307
+ * of everything that is not this application's own code, which is the reason
1308
+ * `GET` was once refused outright: a mutation reachable by navigation is a
1309
+ * one-click CSRF carrying `SameSite=Lax` cookies.
1310
+ */
1311
+ const RPC_CALLER = "x-barq-fn";
1312
+ /** Where a GET call's payload rides, since a GET has no body. */
1313
+ const PAYLOAD_PARAM = "payload";
1314
+ /** The form endpoint of a mounted id, or nothing for a function with none. */
1315
+ function urlOf(id) {
1316
+ return id === "" ? "" : RPC_PREFIX + encodeURIComponent(id);
1317
+ }
1318
+ /** The `data` out of a call, whichever of the two shapes it arrived in. */
1319
+ function dataOf(options) {
1320
+ if (options instanceof FormData) return options;
1321
+ if (options === void 0 || options === null) return void 0;
1322
+ return options.data;
1323
+ }
1324
+ /** What a call asked for beside its `data`. A bare `FormData` asks for nothing. */
1325
+ function callOptionsOf(options) {
1326
+ if (options instanceof FormData || options === void 0 || options === null) return void 0;
1327
+ return options;
1328
+ }
1329
+ /**
1330
+ * The client half. The compiler emits this in a module compiled for the client,
1331
+ * with the id, the chain, and nothing else — no handler body, no validator, no
1332
+ * imports the body needed.
1333
+ *
1334
+ * `chain` is the middlewares the function declared, and it is here so a
1335
+ * `.client()` half can run around the fetch. Only the CLIENT halves survive the
1336
+ * compile: `createMiddleware(...).server(fn)` has its `server` argument deleted
1337
+ * in the client build, so a middleware may hold both without the server body —
1338
+ * or the database import it needed — reaching the browser.
1339
+ */
1340
+ function clientRpc(id, declaredChain = [], declared) {
1341
+ const method = declared?.method ?? "POST";
1342
+ const chain = inlineServerFns(declaredChain);
1343
+ let composed = null;
1344
+ const composition = () => {
1345
+ const global = startOptions().functionMiddleware;
1346
+ if (composed === null || composed.from !== global) composed = {
1347
+ from: global,
1348
+ chain: flattenMiddleware([...global ?? [], ...chain])
1349
+ };
1350
+ return composed.chain;
1351
+ };
1352
+ /**
1353
+ * The fetch, as the INNERMOST step of the chain.
1354
+ *
1355
+ * A client middleware therefore wraps the request the way a server one wraps
1356
+ * the handler: it can read what it is about to send, add to `sendContext`,
1357
+ * and see the result on the way back. TanStack reaches the same arrangement
1358
+ * by appending the server function itself to the chain as a middleware.
1359
+ */
1360
+ const send = async (input, sendContext, context, asked, chainHeaders, chainFetch, live) => {
1361
+ const form = input instanceof FormData;
1362
+ if (form && method === "GET") throw new TypeError(`[barq] The server function \`${id}\` answers GET, and a GET has no body to carry a form. Declare it \`createServerFn({ method: "POST" })\` to accept a \`FormData\`.`);
1363
+ const payload = form ? void 0 : JSON.stringify(Object.keys(sendContext).length === 0 ? { input: encodeWire(input) } : {
1364
+ input: encodeWire(input),
1365
+ context: encodeWire(sendContext)
1366
+ });
1367
+ let headers = method === "GET" ? CALLER : form ? void 0 : JSON_BODY;
1368
+ const mountedFrames = method === "POST" && live === void 0 ? mountedFramesHeader() : null;
1369
+ if (mountedFrames !== null) {
1370
+ const withFrames = new Headers(headers);
1371
+ withFrames.set(FRAMES_HEADER, mountedFrames);
1372
+ headers = withFrames;
1373
+ }
1374
+ if (chainHeaders !== void 0 || asked?.headers !== void 0) {
1375
+ const merged = new Headers(chainHeaders);
1376
+ if (mountedFrames !== null) merged.set(FRAMES_HEADER, mountedFrames);
1377
+ if (asked?.headers !== void 0) for (const [name, value] of new Headers(asked.headers)) merged.set(name, value);
1378
+ if (form || method === "GET") merged.delete("content-type");
1379
+ else merged.set("content-type", "application/json");
1380
+ if (method === "GET") merged.set(RPC_CALLER, "1");
1381
+ headers = merged;
1382
+ }
1383
+ if (live !== void 0) {
1384
+ const withPosition = new Headers(headers);
1385
+ if (live.lastEventId !== null) withPosition.set("last-event-id", live.lastEventId);
1386
+ headers = withPosition;
1387
+ }
1388
+ const endpoint = RPC_PREFIX + encodeURIComponent(id) + (live === void 0 ? DATA_SUFFIX : LIVE_SUFFIX);
1389
+ const response = await (asked?.fetch ?? chainFetch ?? startOptions().serverFns?.fetch ?? fetch)(method === "GET" ? `${endpoint}?${PAYLOAD_PARAM}=${encodeURIComponent(payload ?? "")}` : endpoint, {
1390
+ method,
1391
+ headers,
1392
+ signal: live?.signal ?? asked?.signal,
1393
+ body: method === "GET" ? void 0 : form ? input : payload,
1394
+ credentials: "same-origin",
1395
+ redirect: "manual"
1396
+ });
1397
+ if (response.type === "opaqueredirect") return response;
1398
+ if (live !== void 0) return response;
1399
+ const control = response.headers.get(RPC_CONTROL);
1400
+ if (control === "response") return response;
1401
+ if (control === "thrown") throw response;
1402
+ if (control === "stream") return received(response, id, context);
1403
+ if (control === "frame") return await applyFrameResponse(response);
1404
+ if (control === "flight") {
1405
+ const flown = await applyFlight(response);
1406
+ if (response.headers.get("x-barq-ctx") === null) return flown;
1407
+ const envelope = flown;
1408
+ if (context !== void 0) Object.assign(context, envelope.context);
1409
+ return envelope.result;
1410
+ }
1411
+ if (control !== null) throw fromControl(await response.json());
1412
+ if (!response.ok) throw new ServerFnError(id, response.status, response, await failedAnswer(response));
1413
+ if (response.headers.get("x-barq-ctx") === null) return decodeWire(await response.json());
1414
+ const envelope = decodeWire(await response.json());
1415
+ if (context !== void 0) Object.assign(context, envelope.context);
1416
+ return envelope.result;
1417
+ };
1418
+ const call = async (options, live) => {
1419
+ const input = dataOf(options);
1420
+ const asked = callOptionsOf(options);
1421
+ const flattened = composition();
1422
+ if (flattened.length === 0) return send(input, EMPTY_CONTEXT, void 0, asked, void 0, void 0, live);
1423
+ const context = {};
1424
+ const sendContext = {};
1425
+ const headers = new Headers();
1426
+ const chosen = { current: void 0 };
1427
+ return await runMiddleware(flattened, "client", {
1428
+ data: input,
1429
+ meta: { id },
1430
+ method,
1431
+ signal: asked?.signal ?? new AbortController().signal,
1432
+ context,
1433
+ sendContext,
1434
+ headers,
1435
+ fetch: chosen,
1436
+ run: (data) => send(data, sendContext, context, asked, headers, chosen.current, live)
1437
+ });
1438
+ };
1439
+ const meta = method === "GET" ? {
1440
+ id,
1441
+ method
1442
+ } : { id };
1443
+ const stub = Object.assign((options) => call(options), {
1444
+ [SERVER_FN]: true,
1445
+ [SERVER_FN_CHAIN]: chain,
1446
+ [LIVE_CALL]: (options, live) => call(options, live),
1447
+ meta,
1448
+ serverFnMeta: meta,
1449
+ method,
1450
+ url: urlOf(id)
1451
+ });
1452
+ registerStub(id, stub);
1453
+ return stub;
1454
+ }
1455
+ /**
1456
+ * A streamed answer, as the values it carries.
1457
+ *
1458
+ * Read a line at a time, so a value is handed over when its line has arrived
1459
+ * rather than when the answer is complete. Leaving the loop early cancels the
1460
+ * body, which is what tells the server to stop producing.
1461
+ */
1462
+ async function* received(response, id, context) {
1463
+ const body = response.body;
1464
+ if (body === null) return;
1465
+ const reader = body.getReader();
1466
+ const decoder = new TextDecoder();
1467
+ let pending = "";
1468
+ try {
1469
+ for (;;) {
1470
+ const { done, value } = await reader.read();
1471
+ pending += done ? decoder.decode() : decoder.decode(value, { stream: true });
1472
+ let end = pending.indexOf("\n");
1473
+ while (end !== -1) {
1474
+ const line = JSON.parse(pending.slice(0, end));
1475
+ pending = pending.slice(end + 1);
1476
+ if ("e" in line) throw new ServerFnError(id, 500, void 0, { thrown: line.t });
1477
+ if ("c" in line) {
1478
+ if (context !== void 0) Object.assign(context, decodeWire(line.c));
1479
+ } else yield decodeWire(line.v);
1480
+ end = pending.indexOf("\n");
1481
+ }
1482
+ if (done) return;
1483
+ }
1484
+ } finally {
1485
+ reader.cancel().catch(() => {});
1486
+ }
1487
+ }
1488
+ /** One object for every JSON call, which only ever reads it. */
1489
+ const JSON_BODY = { "content-type": "application/json" };
1490
+ /** What a GET call carries in place of a body's type. */
1491
+ const CALLER = { [RPC_CALLER]: "1" };
1492
+ /** Shared, because the no-middleware path never writes to it. */
1493
+ const EMPTY_CONTEXT = {};
1494
+ /**
1495
+ * Rebuild the throwable a control answer describes.
1496
+ *
1497
+ * An UNKNOWN kind is an error rather than a pass-through: it means the server is
1498
+ * newer than the client and is describing something this build cannot act on,
1499
+ * and returning it as a value would let a navigation instruction be rendered as
1500
+ * data.
1501
+ */
1502
+ function fromControl(control) {
1503
+ if (control.kind === "redirect") return new RpcRedirect(control.to, control.status, control.options === void 0 ? void 0 : decodeWire(control.options));
1504
+ if (control.kind === "not-found") return new RpcNotFound(control.message, control.data === void 0 ? void 0 : decodeWire(control.data), control.routeId);
1505
+ return /* @__PURE__ */ new Error(`[barq] server function answered with an unrecognised ${RPC_CONTROL} kind ${JSON.stringify(control.kind)}; the server is newer than this client bundle.`);
1506
+ }
1507
+ /** Where a server function keeps the middleware it declared, for another to inline. */
1508
+ const SERVER_FN_CHAIN = Symbol.for("barq.server-fn-chain");
1509
+ /**
1510
+ * A chain with each server function in it replaced by the middleware that
1511
+ * function declared, which is TanStack's rule: listing a function lists its
1512
+ * guards, never its handler.
1513
+ */
1514
+ function inlineServerFns(chain) {
1515
+ return chain.flatMap((step) => isServerFn(step) ? chainOf(step) : [step]);
1516
+ }
1517
+ function chainOf(fn) {
1518
+ return fn[SERVER_FN_CHAIN] ?? [];
1519
+ }
1520
+ /** Whether a value is a server function, by brand rather than by shape. */
1521
+ function isServerFn(value) {
1522
+ return typeof value === "function" && value[SERVER_FN] === true;
1523
+ }
1524
+ //#endregion
1525
+ export { FRAME_APPLIED_EVENT as A, regionMarkup as B, createStart as C, FLIGHT_TYPE as D, frameAdapter as E, bindEntries as F, ServerFnError as G, slotOpen as H, frameAddress as I, frameOpen as L, RPC_FLIGHT as M, RPC_FRAME as N, FRAME as O, asFrame as P, installFrames as R, clearStart as S, applyFrameResponse as T, LIVE_CALL as U, slotClose as V, clientStub as W, dataOf as _, RPC_CONTEXT as a, urlOf as b, RPC_RESPONSE as c, RpcNotFound as d, RpcRedirect as f, clientRpc as g, callOptionsOf as h, RPC_CALLER as i, FRAME_CLOSE as j, FRAMES_HEADER as k, RPC_STREAM as l, SERVER_FN_CHAIN as m, LIVE_SUFFIX as n, RPC_CONTROL as o, SERVER_FN as p, PAYLOAD_PARAM as r, RPC_PREFIX as s, DATA_SUFFIX as t, RPC_THROWN as u, inlineServerFns as v, startOptions as w, live as x, isServerFn as y, isFrame as z };
1526
+
1527
+ //# sourceMappingURL=client-BHyIiYxt.js.map