@solidjs/web 2.0.0-rc.14 → 2.0.0-rc.16

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 (58) hide show
  1. package/README.md +1 -1
  2. package/dist/server.dev.js +475 -591
  3. package/dist/server.js +459 -489
  4. package/dist/server.observe.js +459 -498
  5. package/dist/web.dev.js +206 -220
  6. package/dist/web.js +196 -208
  7. package/dist/web.observe.js +206 -213
  8. package/frames/dist/client.dev.js +664 -643
  9. package/frames/dist/client.js +593 -582
  10. package/frames/dist/client.observe.js +624 -589
  11. package/frames/dist/regions.js +43 -2
  12. package/frames/dist/server.dev.js +578 -450
  13. package/frames/dist/server.js +578 -397
  14. package/frames/dist/server.observe.js +578 -397
  15. package/frames/dist/trace.js +4 -1
  16. package/frames/dist/wire.js +371 -6
  17. package/package.json +13 -13
  18. package/serialization/dist/decode.js +11 -9
  19. package/serialization/dist/serialization.js +11 -9
  20. package/serialization/types/serializer-decode.d.ts +2 -2
  21. package/server-functions/dist/client.dev.js +5 -2
  22. package/server-functions/dist/client.js +3 -2
  23. package/server-functions/dist/client.observe.js +5 -2
  24. package/server-functions/dist/rich-args.js +33 -1
  25. package/server-functions/dist/server.dev.js +218 -35
  26. package/server-functions/dist/server.js +218 -35
  27. package/server-functions/dist/server.observe.js +218 -35
  28. package/skills/server-components/SKILL.md +74 -185
  29. package/types/client.d.ts +112 -10
  30. package/types/constants.d.ts +2 -1
  31. package/types/frames/assets-tier.d.ts +2 -2
  32. package/types/frames/client.d.ts +8 -3
  33. package/types/frames/frame-client.d.ts +121 -157
  34. package/types/frames/frame-morph.d.ts +28 -0
  35. package/types/frames/frame-sink.d.ts +13 -9
  36. package/types/frames/frame-transport.d.ts +30 -1
  37. package/types/frames/regions-tier.d.ts +15 -0
  38. package/types/frames/serializer-decode.d.ts +2 -2
  39. package/types/frames/server.d.ts +1 -53
  40. package/types/frames/wire-tier.d.ts +54 -1
  41. package/types/head.d.ts +1 -0
  42. package/types/index.d.ts +57 -50
  43. package/types/index.server.d.ts +3 -27
  44. package/types/jsx.d.ts +14 -17
  45. package/types/observe.d.ts +14 -7
  46. package/types/render.d.ts +3 -1
  47. package/types/response.d.ts +31 -8
  48. package/types/serializer-decode.d.ts +2 -2
  49. package/types/server-functions/argument-codec.d.ts +21 -0
  50. package/types/server-functions/client.d.ts +18 -5
  51. package/types/server-functions/server.d.ts +6 -2
  52. package/types/server-functions/shared.d.ts +19 -0
  53. package/types/server-mock.d.ts +9 -2
  54. package/types/server-observe.d.ts +3 -2
  55. package/types/server.d.ts +124 -67
  56. package/frames/dist/bind.dev.js +0 -326
  57. package/frames/dist/bind.js +0 -295
  58. package/types/frames/bind-tier.d.ts +0 -60
@@ -9,6 +9,9 @@ const state = globalThis[STATE] || (globalThis[STATE] = {
9
9
  function setContainerTraceMaterializer(fn) {
10
10
  state.materializeTrace = fn;
11
11
  }
12
+ function isSerovalStream(value) {
13
+ return value.__SEROVAL_STREAM__ === true || typeof value.on === "function" && typeof value[Symbol.asyncIterator] !== "function";
14
+ }
12
15
  function materialize(marker, claiming) {
13
16
  let value = state.materialized.get(marker.$tr);
14
17
  if (value === undefined) {
@@ -21,7 +24,7 @@ function materialize(marker, claiming) {
21
24
  function isContainerTraceMarker(value) {
22
25
  if (value == null || typeof value !== "object" || value.$tr == null) return false;
23
26
  const tr = value.$tr;
24
- return tr.__SEROVAL_STREAM__ === true || typeof tr[Symbol.asyncIterator] === "function";
27
+ return isSerovalStream(tr) || typeof tr[Symbol.asyncIterator] === "function";
25
28
  }
26
29
  function reviveContainerTraces(value, claiming) {
27
30
  if (!state.materializeTrace || value == null || typeof value !== "object") return value;
@@ -1,8 +1,269 @@
1
1
  import { applyFrameResponse } from '@solidjs/web/frames';
2
- import { frameAddress, isEventStream, ChunkReader, LIVE_WIRE } from '@solidjs/web/server-functions/client';
2
+ import { isEventStream, ChunkReader, LIVE_WIRE, frameAddress } from '@solidjs/web/server-functions/client';
3
+ import 'solid-js';
4
+
5
+ const ELEMENT_NODE$1 = 1;
6
+ const COMMENT_NODE$1 = 8;
7
+ const CLAIMED_ELEMENTS = "a[href], form[action]";
8
+ const claimedAttr = name => name === "href" || name === "action";
9
+ const SLOT_START = /^slot:(.+):start$/;
10
+ const SLOT_END = /^slot:(.+):end$/;
11
+ const slotEnd = id => `slot:${id}:end`;
12
+ const FRAME_ID_ATTR = "data-fid";
13
+ function isFrameElement(node) {
14
+ return node.nodeType === ELEMENT_NODE$1 && node.hasAttribute(FRAME_ID_ATTR);
15
+ }
16
+ function parseFragment(html) {
17
+ const template = document.createElement("template");
18
+ template.innerHTML = html;
19
+ return template.content;
20
+ }
21
+ function rangeClose(start, id) {
22
+ let n = start.nextSibling;
23
+ while (n) {
24
+ if (n.nodeType === COMMENT_NODE$1 && n.data === id) return n;
25
+ n = n.nextSibling;
26
+ }
27
+ return null;
28
+ }
29
+ function slotStartId(node) {
30
+ if (node.nodeType !== COMMENT_NODE$1) return null;
31
+ const m = SLOT_START.exec(node.data);
32
+ return m ? m[1] : null;
33
+ }
34
+ function preservesOpen(el) {
35
+ const t = el.tagName;
36
+ return t === "DETAILS" || t === "DIALOG";
37
+ }
38
+ const afterRange = (start, id) => findMarker(start, slotEnd(id))?.nextSibling;
39
+ function findMarker(start, end) {
40
+ let n = start.nextSibling;
41
+ while (n) {
42
+ if (n.nodeType === COMMENT_NODE$1 && n.data === end) return n;
43
+ n = n.nextSibling;
44
+ }
45
+ return null;
46
+ }
3
47
 
4
48
  const FRAME_HAVE_HEADER = "X-Frame-Have";
5
49
  const FRAME_HAVE_BUDGET = 4096;
50
+ const ends = msg => !!msg.r && (":complete" in msg.r || ":error" in msg.r);
51
+
52
+ const ELEMENT_NODE = 1;
53
+ const TEXT_NODE = 3;
54
+ const COMMENT_NODE = 8;
55
+ function morph(parent, fragment, claim, ranges) {
56
+ const grafts = [];
57
+ reconcileChildren(parent, fragment, null, null, claim, ranges, grafts);
58
+ if (ranges.size) graft(grafts, ranges);
59
+ }
60
+ function graft(roots, ranges) {
61
+ for (const root of roots) flushGrafts(root, ranges);
62
+ }
63
+ function isSlotMarker(node) {
64
+ if (node.nodeType !== COMMENT_NODE) return false;
65
+ const data = node.data;
66
+ return SLOT_START.test(data) || SLOT_END.test(data);
67
+ }
68
+ function compatible(a, b) {
69
+ if (a.nodeType !== b.nodeType) return false;
70
+ if (a.nodeType === ELEMENT_NODE) return a.nodeName === b.nodeName && a.getAttribute("_key") === b.getAttribute("_key");
71
+ return a.nodeType === TEXT_NODE || a.nodeType === COMMENT_NODE;
72
+ }
73
+ function morphAttributes(oldEl, newEl, claim) {
74
+ let reclaim = false;
75
+ let changed = false;
76
+ const keepOpen = preservesOpen(oldEl);
77
+ const oldAttrs = oldEl.attributes;
78
+ for (let i = oldAttrs.length - 1; i >= 0; i--) {
79
+ const name = oldAttrs[i].name;
80
+ if (keepOpen && name === "open") continue;
81
+ if (!newEl.hasAttribute(name)) {
82
+ oldEl.removeAttribute(name);
83
+ changed = true;
84
+ reclaim ||= claimedAttr(name);
85
+ }
86
+ }
87
+ const newAttrs = newEl.attributes;
88
+ for (let i = 0; i < newAttrs.length; i++) {
89
+ const attr = newAttrs[i];
90
+ const name = attr.name;
91
+ if (keepOpen && name === "open") continue;
92
+ if (oldEl.getAttribute(name) !== attr.value) {
93
+ oldEl.setAttribute(name, attr.value);
94
+ changed = true;
95
+ reclaim ||= claimedAttr(name);
96
+ }
97
+ }
98
+ if (claim && (reclaim || changed && oldEl.matches(CLAIMED_ELEMENTS))) claim(oldEl, true);
99
+ }
100
+ function morphNode(oldNode, newNode, claim, ranges, grafts) {
101
+ if (oldNode.nodeType === ELEMENT_NODE) {
102
+ if (oldNode.hasAttribute("data-preserve")) return;
103
+ if (!ranges?.size && oldNode.isEqualNode(newNode)) return;
104
+ morphAttributes(oldNode, newNode, claim);
105
+ reconcileChildren(oldNode, newNode, null, null, claim, ranges, grafts);
106
+ } else if (oldNode.data !== newNode.data) {
107
+ oldNode.data = newNode.data;
108
+ }
109
+ }
110
+ function findRangeStart(from, id, bound) {
111
+ const target = `slot:${id}:start`;
112
+ let n = from;
113
+ while (n && n !== bound) {
114
+ if (n.nodeType === COMMENT_NODE && n.data === target) return n;
115
+ n = n.nextSibling;
116
+ }
117
+ return null;
118
+ }
119
+ function moveRangeBefore(parent, start, id, ref) {
120
+ const end = slotEnd(id);
121
+ let n = start;
122
+ while (n) {
123
+ const next = n.nextSibling;
124
+ const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
125
+ parent.insertBefore(n, ref);
126
+ if (isEnd) break;
127
+ n = next;
128
+ }
129
+ }
130
+ function placeRange(parent, range, id, ref) {
131
+ if (range.nodeType === 11 ) {
132
+ parent.insertBefore(range, ref);
133
+ } else {
134
+ moveRangeBefore(parent, range, id, ref);
135
+ }
136
+ }
137
+ function adoptRange(parent, start, id, ref, claim) {
138
+ const end = slotEnd(id);
139
+ let n = start;
140
+ let after = null;
141
+ while (n) {
142
+ const next = n.nextSibling;
143
+ const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
144
+ parent.insertBefore(n, ref);
145
+ if (claim) claim(n);
146
+ if (isEnd) {
147
+ after = next;
148
+ break;
149
+ }
150
+ n = next;
151
+ }
152
+ return after;
153
+ }
154
+ function reconcileChildren(parent, source, boundStart = null, boundEnd = null, claim = null, ranges = null, grafts = null) {
155
+ let oldChild = boundStart ? boundStart.nextSibling : parent.firstChild;
156
+ let newChild = source.firstChild;
157
+ while (newChild) {
158
+ const nextNew = newChild.nextSibling;
159
+ const pid = slotStartId(newChild);
160
+ const old = oldChild === boundEnd ? null : oldChild;
161
+ if (pid !== null) {
162
+ if (old && slotStartId(old) === pid) {
163
+ oldChild = afterRange(old, pid);
164
+ newChild = afterRange(newChild, pid);
165
+ } else {
166
+ const displaced = ranges && ranges.get(pid);
167
+ const existing = displaced || findRangeStart(old, pid, boundEnd);
168
+ if (existing) {
169
+ if (ranges) ranges.delete(pid);
170
+ placeRange(parent, existing, pid, old ?? boundEnd);
171
+ newChild = afterRange(newChild, pid);
172
+ } else {
173
+ newChild = adoptRange(parent, newChild, pid, old ?? boundEnd, claim);
174
+ }
175
+ }
176
+ continue;
177
+ }
178
+ if (!old) {
179
+ parent.insertBefore(newChild, boundEnd);
180
+ if (claim) claim(newChild);
181
+ if (grafts) grafts.push(newChild);
182
+ newChild = nextNew;
183
+ continue;
184
+ }
185
+ if (isSlotMarker(old)) {
186
+ parent.insertBefore(newChild, old);
187
+ if (claim) claim(newChild);
188
+ if (grafts) grafts.push(newChild);
189
+ newChild = nextNew;
190
+ continue;
191
+ }
192
+ if (compatible(old, newChild)) {
193
+ morphNode(old, newChild, claim, ranges, grafts);
194
+ oldChild = old.nextSibling;
195
+ newChild = nextNew;
196
+ continue;
197
+ }
198
+ if (old.nodeType === TEXT_NODE && newChild.nodeType !== TEXT_NODE) {
199
+ oldChild = old.nextSibling;
200
+ old.remove();
201
+ continue;
202
+ }
203
+ if (newChild.nodeType === 1) {
204
+ let ahead = old.nextSibling;
205
+ while (ahead && ahead !== boundEnd && !compatible(ahead, newChild)) {
206
+ const aheadPid = slotStartId(ahead);
207
+ ahead = aheadPid !== null ? afterRange(ahead, aheadPid) : ahead.nextSibling;
208
+ }
209
+ if (ahead && ahead !== boundEnd) {
210
+ parent.insertBefore(ahead, old);
211
+ morphNode(ahead, newChild, claim, ranges, grafts);
212
+ newChild = nextNew;
213
+ continue;
214
+ }
215
+ }
216
+ parent.insertBefore(newChild, old);
217
+ if (claim) claim(newChild);
218
+ if (grafts) grafts.push(newChild);
219
+ newChild = nextNew;
220
+ }
221
+ while (oldChild && oldChild !== boundEnd) {
222
+ const next = oldChild.nextSibling;
223
+ const pid = ranges ? slotStartId(oldChild) : null;
224
+ if (pid !== null && ranges.get(pid) === oldChild) {
225
+ const frag = document.createDocumentFragment();
226
+ const after = stashRange(frag, oldChild, pid);
227
+ ranges.set(pid, frag);
228
+ oldChild = after;
229
+ continue;
230
+ }
231
+ parent.removeChild(oldChild);
232
+ oldChild = next;
233
+ }
234
+ }
235
+ function flushGrafts(node, ranges) {
236
+ if (node.nodeType !== ELEMENT_NODE || isFrameElement(node)) return;
237
+ let n = node.firstChild;
238
+ while (n) {
239
+ const id = slotStartId(n);
240
+ if (id !== null) {
241
+ const next = afterRange(n, id);
242
+ const displaced = ranges.get(id);
243
+ if (displaced) {
244
+ ranges.delete(id);
245
+ placeRange(node, displaced, id, n);
246
+ stashRange(document.createDocumentFragment(), n, id);
247
+ }
248
+ n = next;
249
+ continue;
250
+ }
251
+ flushGrafts(n, ranges);
252
+ n = n.nextSibling;
253
+ }
254
+ }
255
+ function stashRange(frag, start, id) {
256
+ const end = slotEnd(id);
257
+ let n = start;
258
+ while (n) {
259
+ const next = n.nextSibling;
260
+ const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
261
+ frag.appendChild(n);
262
+ if (isEnd) return next;
263
+ n = next;
264
+ }
265
+ return null;
266
+ }
6
267
 
7
268
  const connections = new WeakMap();
8
269
  const connectionsOf = host => {
@@ -85,7 +346,7 @@ function connect(response, wire, address, binding, host, bump, begin) {
85
346
  prepareData: host.prepareData,
86
347
  apply(chunk) {
87
348
  if (drained) return;
88
- if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (chunk.type === "complete" || chunk.type === "error" && !chunk.key) open.delete(chunk.id);
349
+ if (chunk.type === "start") open.set(chunk.id, chunk.version);else if (ends(chunk)) open.delete(chunk.id);
89
350
  host.apply(chunk);
90
351
  }
91
352
  };
@@ -107,11 +368,12 @@ function connect(response, wire, address, binding, host, bump, begin) {
107
368
  error: dead,
108
369
  sweep: () => {
109
370
  for (const [id, version] of open) host.apply({
110
- type: "error",
111
371
  id,
112
372
  version,
113
- error: {
114
- message: String(dead && dead.message)
373
+ r: {
374
+ ":error": {
375
+ message: String(dead && dead.message)
376
+ }
115
377
  }
116
378
  });
117
379
  },
@@ -129,5 +391,108 @@ function connect(response, wire, address, binding, host, bump, begin) {
129
391
  });
130
392
  return binding;
131
393
  }
394
+ function rows(open, close, ops, parse, morph) {
395
+ const isRow = n => n.nodeType === 8 && n.data === "lr";
396
+ const starts = [];
397
+ for (let n = open.nextSibling; n && n !== close; n = n.nextSibling) {
398
+ if (isRow(n)) starts.push(n);else if (n.nodeType === 8 && /^lh:\d+$/.test(n.data)) {
399
+ const end = "lh:/" + n.data.slice(3);
400
+ while (n.nextSibling && !(n.nodeType === 8 && n.data === end)) n = n.nextSibling;
401
+ }
402
+ }
403
+ const had = starts.length;
404
+ const n = ops.n;
405
+ let appended = 0;
406
+ for (const [i] of ops.r) if (i >= had) appended++;
407
+ if (!had || appended !== Math.max(0, n - had)) return false;
408
+ const fragment = parse(ops.r.map(op => "<!--lr-->" + op[1]).join(""));
409
+ const parsed = [];
410
+ for (let c = fragment.firstChild; c;) {
411
+ const next = c.nextSibling;
412
+ if (isRow(c)) parsed.push(document.createDocumentFragment());else parsed[parsed.length - 1].appendChild(c);
413
+ c = next;
414
+ }
415
+ if (parsed.length !== ops.r.length) return false;
416
+ const parent = open.parentNode;
417
+ if (n < had) while (starts[n].nextSibling !== close) parent.removeChild(close.previousSibling);
418
+ if (n < had) parent.removeChild(starts[n]);
419
+ ops.r.forEach(([i], k) => {
420
+ if (i < had) {
421
+ const end = i + 1 < Math.min(n, had) ? starts[i + 1] : close;
422
+ morph(starts[i], end, parsed[k]);
423
+ } else {
424
+ const marker = document.createComment("lr");
425
+ parent.insertBefore(marker, close);
426
+ parent.insertBefore(parsed[k], close);
427
+ }
428
+ });
429
+ return true;
430
+ }
431
+ function hole(f, marker, record, index) {
432
+ const open = target(f, "hole:" + marker, n => n.nodeType === 8 && n.data === marker);
433
+ if (!open) return false;
434
+ const close = rangeClose(open, "lh:/" + marker.slice(3));
435
+ if (!close) {
436
+ f.w && f.w(marker, open);
437
+ return false;
438
+ }
439
+ if (record.rows) {
440
+ if (f.s()[marker] !== record.base || !rows(open, close, record.rows, parseFragment, (start, end, fragment) => reconcileChildren(start.parentNode, fragment, start, end, f.c))) {
441
+ f.x("hole:" + marker, record);
442
+ return false;
443
+ }
444
+ } else {
445
+ if (!index.r) f.k(index.r = new Map()), index.g = [];
446
+ reconcileChildren(open.parentNode, parseFragment(record.value), open, close, f.c, index.r.size ? index.r : null, index.g);
447
+ }
448
+ return true;
449
+ }
450
+ function attrs(f, addr, record) {
451
+ const el = target(f, "attr:" + addr, n => n.nodeType === 1 && n.getAttribute("data-lha") === addr);
452
+ if (!el) return false;
453
+ const parsed = parseFragment(`<i${record.value}></i>`).firstChild;
454
+ const keepOpen = preservesOpen(el);
455
+ const current = el.attributes;
456
+ for (let i = current.length - 1; i >= 0; i--) {
457
+ const name = current[i].name;
458
+ if (name === "data-lha" || keepOpen && name === "open") continue;
459
+ if (!parsed || !parsed.hasAttribute(name)) el.removeAttribute(name);
460
+ }
461
+ if (parsed) {
462
+ for (let i = 0; i < parsed.attributes.length; i++) {
463
+ const {
464
+ name,
465
+ value
466
+ } = parsed.attributes[i];
467
+ if (keepOpen && name === "open") continue;
468
+ if (el.getAttribute(name) !== value) el.setAttribute(name, value);
469
+ }
470
+ }
471
+ if (record.removed) for (const name of record.removed) {
472
+ if (keepOpen && name === "open") continue;
473
+ el.removeAttribute(name);
474
+ }
475
+ return true;
476
+ }
477
+ function target(f, key, test) {
478
+ let n = f.t.get(key);
479
+ if (n && test(n) && f.e.contains(n)) return n;
480
+ n = findTarget(f.e.firstChild, test);
481
+ n && f.t.set(key, n);
482
+ return n;
483
+ }
484
+ function findTarget(n, test) {
485
+ for (; n; n = n.nextSibling) {
486
+ if (n.nodeType === 1) {
487
+ const fid = isFrameElement(n) ? n.getAttribute(FRAME_ID_ATTR) : null;
488
+ if (fid === null || fid.includes(".")) {
489
+ if (test(n)) return n;
490
+ const found = findTarget(n.firstChild, test);
491
+ if (found) return found;
492
+ }
493
+ } else if (test(n)) return n;
494
+ }
495
+ return null;
496
+ }
132
497
 
133
- export { cancel, connect, encodeHaveList, have, haveOf, resume };
498
+ export { attrs, cancel, connect, encodeHaveList, graft, have, haveOf, hole, morph, resume };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@solidjs/web",
3
3
  "description": "Solid's web runtime: client rendering, hydration, SSR, and DOM-specific control flow (Portal, Dynamic).",
4
- "version": "2.0.0-rc.14",
4
+ "version": "2.0.0-rc.16",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -345,14 +345,6 @@
345
345
  "types": "./types/frames/assets-tier.d.ts",
346
346
  "default": "./frames/dist/assets.js"
347
347
  },
348
- "./frames/bind": {
349
- "development": {
350
- "types": "./types/frames/bind-tier.d.ts",
351
- "default": "./frames/dist/bind.dev.js"
352
- },
353
- "types": "./types/frames/bind-tier.d.ts",
354
- "default": "./frames/dist/bind.js"
355
- },
356
348
  "./frames/wire": {
357
349
  "types": "./types/frames/wire-tier.d.ts",
358
350
  "default": "./frames/dist/wire.js"
@@ -381,16 +373,24 @@
381
373
  "test-types": "tsc --project tsconfig.test.json && tsc --project tsconfig.test.augment.json"
382
374
  },
383
375
  "dependencies": {
384
- "seroval": "~1.6.7",
385
- "seroval-plugins": "~1.6.7"
376
+ "seroval": "1.6.7",
377
+ "seroval-plugins": "1.6.7"
386
378
  },
387
379
  "peerDependencies": {
388
- "solid-js": "^2.0.0-rc.14"
380
+ "solid-js": "^2.0.0-rc.16"
389
381
  },
390
382
  "devDependencies": {
391
383
  "@codspeed/vitest-plugin": "^5.4.0",
392
384
  "@solidjs/signals": "workspace:*",
393
385
  "fast-check": "3.23.2",
394
386
  "solid-js": "workspace:*"
395
- }
387
+ },
388
+ "keywords": [
389
+ "solid",
390
+ "solidjs",
391
+ "dom",
392
+ "ssr",
393
+ "hydration",
394
+ "tanstack-intent"
395
+ ]
396
396
  }
@@ -1,4 +1,4 @@
1
- import { fromCrossJSON, Feature, createStream } from 'seroval';
1
+ import { fromCrossJSON, isStream, Feature, createStream } from 'seroval';
2
2
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
3
3
 
4
4
  const STATE = Symbol.for("solid.container-trace-state");
@@ -80,14 +80,16 @@ function resolveSerializerPlugins(customPlugins) {
80
80
  }
81
81
  const jsonCodecDisabledFeatures = () => Feature.RegExp;
82
82
  const JSON_CODEC_DEPTH_LIMIT = 64;
83
- function resolveCodecOptions({
84
- plugins,
85
- disabledFeatures,
86
- depthLimit,
87
- serializeErrorStacks
88
- } = {}) {
83
+ const RESOLVED_PLUGINS = Symbol.for("solid.codec.resolvedPlugins");
84
+ function resolveCodecOptions(options = {}) {
85
+ const {
86
+ plugins,
87
+ disabledFeatures,
88
+ depthLimit,
89
+ serializeErrorStacks
90
+ } = options;
89
91
  return {
90
- plugins: resolveSerializerPlugins(plugins),
92
+ plugins: options[RESOLVED_PLUGINS] || resolveSerializerPlugins(plugins),
91
93
  disabledFeatures: disabledFeatures === undefined ? jsonCodecDisabledFeatures() : disabledFeatures,
92
94
  depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
93
95
  serializeErrorStacks
@@ -104,7 +106,7 @@ function createJSONDeserializer(options) {
104
106
  function classify(value) {
105
107
  if (value === null || typeof value !== "object") return 0;
106
108
  try {
107
- if (value.__SEROVAL_STREAM__) return STREAM;
109
+ if (isStream(value) && typeof value.on === "function") return STREAM;
108
110
  if (typeof value.s === "function" && typeof value.f === "function" && value.p instanceof Promise) return RESOLVER;
109
111
  } catch {}
110
112
  return 0;
@@ -1,4 +1,4 @@
1
- import { fromCrossJSON, Feature, createStream, OpaqueReference as OpaqueReference$1, createPlugin as createPlugin$1, toCrossJSONStream, Serializer, getCrossReferenceHeader } from 'seroval';
1
+ import { isStream, fromCrossJSON, Feature, createStream, OpaqueReference as OpaqueReference$1, createPlugin as createPlugin$1, toCrossJSONStream, Serializer, getCrossReferenceHeader } from 'seroval';
2
2
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
3
3
 
4
4
  const STATE = Symbol.for("solid.container-trace-state");
@@ -80,14 +80,16 @@ function resolveSerializerPlugins(customPlugins) {
80
80
  }
81
81
  const jsonCodecDisabledFeatures = () => Feature.RegExp;
82
82
  const JSON_CODEC_DEPTH_LIMIT = 64;
83
- function resolveCodecOptions({
84
- plugins,
85
- disabledFeatures,
86
- depthLimit,
87
- serializeErrorStacks
88
- } = {}) {
83
+ const RESOLVED_PLUGINS = Symbol.for("solid.codec.resolvedPlugins");
84
+ function resolveCodecOptions(options = {}) {
85
+ const {
86
+ plugins,
87
+ disabledFeatures,
88
+ depthLimit,
89
+ serializeErrorStacks
90
+ } = options;
89
91
  return {
90
- plugins: resolveSerializerPlugins(plugins),
92
+ plugins: options[RESOLVED_PLUGINS] || resolveSerializerPlugins(plugins),
91
93
  disabledFeatures: disabledFeatures === undefined ? jsonCodecDisabledFeatures() : disabledFeatures,
92
94
  depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
93
95
  serializeErrorStacks
@@ -104,7 +106,7 @@ function createJSONDeserializer(options) {
104
106
  function classify(value) {
105
107
  if (value === null || typeof value !== "object") return 0;
106
108
  try {
107
- if (value.__SEROVAL_STREAM__) return STREAM;
109
+ if (isStream(value) && typeof value.on === "function") return STREAM;
108
110
  if (typeof value.s === "function" && typeof value.f === "function" && value.p instanceof Promise) return RESOLVER;
109
111
  } catch {}
110
112
  return 0;
@@ -223,8 +223,8 @@ export declare const DEFAULT_WEB_PLUGINS: readonly ({
223
223
  * Integration-facing; may change (see the entry banner).
224
224
  */
225
225
  export declare function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
226
- export declare function resolveCodecOptions({ plugins, disabledFeatures, depthLimit, serializeErrorStacks }?: JSONCodecOptions): {
227
- plugins: SerializerPlugin<any, any>[];
226
+ export declare function resolveCodecOptions(options?: JSONCodecOptions): {
227
+ plugins: any;
228
228
  disabledFeatures: number;
229
229
  depthLimit: number;
230
230
  serializeErrorStacks: boolean;
@@ -948,10 +948,11 @@ async function createRequest(base, id, options, meta) {
948
948
  headers
949
949
  };
950
950
  if (config.prepareRequest) {
951
- const prepared = await config.prepareRequest(init, {
951
+ let prepared = config.prepareRequest(init, {
952
952
  id,
953
953
  meta
954
954
  });
955
+ if (prepared && typeof prepared.then === "function") prepared = await prepared;
955
956
  if (prepared && prepared !== init) {
956
957
  if (typeof prepared !== "object") {
957
958
  throw new Error("prepareRequest must return (or mutate and return) the RequestInit it received; " + `it returned a ${typeof prepared}. Spread the init: ` + "init => ({ ...init, headers: { ...init.headers, ... } })");
@@ -964,7 +965,7 @@ async function createRequest(base, id, options, meta) {
964
965
  }
965
966
  if (observation) observation.request(base, init);
966
967
  const send = config.fetch || fetch;
967
- return send(base, init);
968
+ return (meta.fetch || send)(base, init, send);
968
969
  }
969
970
  async function initializeResponse(base, id, options, args, meta) {
970
971
  if (args.length === 0) {
@@ -1056,6 +1057,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
1056
1057
  ...options,
1057
1058
  [CALL_OBSERVATION]: observation
1058
1059
  };
1060
+ const startedAt = handler ? performance.now() : undefined;
1059
1061
  const response = await initializeResponse(base, id, options, args, meta);
1060
1062
  if (observation) observation.response(response);
1061
1063
  if (handler) {
@@ -1066,6 +1068,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
1066
1068
  context,
1067
1069
  retry: () => fetchServerFunction(base, id, sent, args, meta, callArgs)
1068
1070
  };
1071
+ ctx.startedAt = startedAt;
1069
1072
  if (options[LIVE_WIRE]) ctx[LIVE_WIRE] = options[LIVE_WIRE];
1070
1073
  const handled = handler.handle(response, ctx);
1071
1074
  if (handled !== undefined) return handled;
@@ -833,10 +833,11 @@ async function createRequest(base, id, options, meta) {
833
833
  headers
834
834
  };
835
835
  if (config.prepareRequest) {
836
- const prepared = await config.prepareRequest(init, {
836
+ let prepared = config.prepareRequest(init, {
837
837
  id,
838
838
  meta
839
839
  });
840
+ if (prepared && typeof prepared.then === "function") prepared = await prepared;
840
841
  if (prepared && prepared !== init) {
841
842
  if (typeof prepared !== "object") {
842
843
  throw new Error("prepareRequest must return (or mutate and return) the RequestInit it received; " + `it returned a ${typeof prepared}. Spread the init: ` + "init => ({ ...init, headers: { ...init.headers, ... } })");
@@ -848,7 +849,7 @@ async function createRequest(base, id, options, meta) {
848
849
  init = prepared || init;
849
850
  }
850
851
  const send = config.fetch || fetch;
851
- return send(base, init);
852
+ return (meta.fetch || send)(base, init, send);
852
853
  }
853
854
  async function initializeResponse(base, id, options, args, meta) {
854
855
  if (args.length === 0) {
@@ -948,10 +948,11 @@ async function createRequest(base, id, options, meta) {
948
948
  headers
949
949
  };
950
950
  if (config.prepareRequest) {
951
- const prepared = await config.prepareRequest(init, {
951
+ let prepared = config.prepareRequest(init, {
952
952
  id,
953
953
  meta
954
954
  });
955
+ if (prepared && typeof prepared.then === "function") prepared = await prepared;
955
956
  if (prepared && prepared !== init) {
956
957
  if (typeof prepared !== "object") {
957
958
  throw new Error("prepareRequest must return (or mutate and return) the RequestInit it received; " + `it returned a ${typeof prepared}. Spread the init: ` + "init => ({ ...init, headers: { ...init.headers, ... } })");
@@ -964,7 +965,7 @@ async function createRequest(base, id, options, meta) {
964
965
  }
965
966
  if (observation) observation.request(base, init);
966
967
  const send = config.fetch || fetch;
967
- return send(base, init);
968
+ return (meta.fetch || send)(base, init, send);
968
969
  }
969
970
  async function initializeResponse(base, id, options, args, meta) {
970
971
  if (args.length === 0) {
@@ -1056,6 +1057,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
1056
1057
  ...options,
1057
1058
  [CALL_OBSERVATION]: observation
1058
1059
  };
1060
+ const startedAt = handler ? performance.now() : undefined;
1059
1061
  const response = await initializeResponse(base, id, options, args, meta);
1060
1062
  if (observation) observation.response(response);
1061
1063
  if (handler) {
@@ -1066,6 +1068,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
1066
1068
  context,
1067
1069
  retry: () => fetchServerFunction(base, id, sent, args, meta, callArgs)
1068
1070
  };
1071
+ ctx.startedAt = startedAt;
1069
1072
  if (options[LIVE_WIRE]) ctx[LIVE_WIRE] = options[LIVE_WIRE];
1070
1073
  const handled = handler.handle(response, ctx);
1071
1074
  if (handled !== undefined) return handled;