@solidjs/web 2.0.0-rc.15 → 2.0.0-rc.17

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 (55) hide show
  1. package/README.md +1 -1
  2. package/dist/server.dev.js +361 -483
  3. package/dist/server.js +346 -391
  4. package/dist/server.observe.js +346 -391
  5. package/dist/web.dev.js +110 -55
  6. package/dist/web.js +51 -50
  7. package/dist/web.observe.js +61 -55
  8. package/frames/dist/client.dev.js +610 -621
  9. package/frames/dist/client.js +540 -566
  10. package/frames/dist/client.observe.js +571 -573
  11. package/frames/dist/regions.js +43 -2
  12. package/frames/dist/server.dev.js +793 -424
  13. package/frames/dist/server.js +792 -371
  14. package/frames/dist/server.observe.js +792 -371
  15. package/frames/dist/wire.js +371 -6
  16. package/package.json +11 -11
  17. package/serialization/dist/decode.js +9 -7
  18. package/serialization/dist/serialization.js +9 -7
  19. package/serialization/types/serializer-decode.d.ts +2 -2
  20. package/server-functions/dist/client.dev.js +13 -22
  21. package/server-functions/dist/client.js +11 -22
  22. package/server-functions/dist/client.observe.js +13 -22
  23. package/server-functions/dist/rich-args.js +84 -1
  24. package/server-functions/dist/server.dev.js +194 -20
  25. package/server-functions/dist/server.js +194 -20
  26. package/server-functions/dist/server.observe.js +194 -20
  27. package/skills/server-components/SKILL.md +74 -185
  28. package/types/client.d.ts +27 -5
  29. package/types/diagnostics.d.ts +16 -0
  30. package/types/frames/assets-tier.d.ts +2 -2
  31. package/types/frames/client.d.ts +8 -3
  32. package/types/frames/frame-client.d.ts +121 -157
  33. package/types/frames/frame-morph.d.ts +28 -0
  34. package/types/frames/frame-sink.d.ts +13 -9
  35. package/types/frames/frame-transport.d.ts +30 -1
  36. package/types/frames/regions-tier.d.ts +15 -0
  37. package/types/frames/serializer-decode.d.ts +2 -2
  38. package/types/frames/server.d.ts +0 -52
  39. package/types/frames/wire-tier.d.ts +54 -1
  40. package/types/index.d.ts +2 -2
  41. package/types/jsx.d.ts +11 -5
  42. package/types/observe.d.ts +14 -7
  43. package/types/render.d.ts +3 -1
  44. package/types/response.d.ts +5 -4
  45. package/types/serializer-decode.d.ts +2 -2
  46. package/types/server-functions/argument-codec.d.ts +30 -0
  47. package/types/server-functions/client.d.ts +27 -9
  48. package/types/server-functions/server.d.ts +23 -2
  49. package/types/server-functions/shared.d.ts +19 -0
  50. package/types/server-functions/uploads.d.ts +50 -0
  51. package/types/server-observe.d.ts +3 -2
  52. package/types/server.d.ts +58 -77
  53. package/frames/dist/bind.dev.js +0 -326
  54. package/frames/dist/bind.js +0 -295
  55. package/types/frames/bind-tier.d.ts +0 -60
@@ -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.15",
4
+ "version": "2.0.0-rc.17",
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"
@@ -385,12 +377,20 @@
385
377
  "seroval-plugins": "1.6.7"
386
378
  },
387
379
  "peerDependencies": {
388
- "solid-js": "^2.0.0-rc.15"
380
+ "solid-js": "^2.0.0-rc.17"
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
  }
@@ -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
@@ -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
@@ -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;
@@ -858,7 +858,7 @@ function parseServerFunctionActionUrl(url) {
858
858
  }
859
859
  function serializeArguments(args) {
860
860
  if (!config.serializeArgs) {
861
- throw new Error("Server function arguments are sent as JSON by default and these " + "arguments are not JSON-serializable. Call enableRichArguments() " + '(from "@solidjs/web/server-functions/rich-args") once at startup ' + "to send Dates, Maps, Sets, typed arrays, etc. through the codec — " + "or pass a single Blob/FormData/File argument, which has a native " + "HTTP encoding.");
861
+ throw new Error("Server function arguments are sent as JSON by default and these " + "arguments are not JSON-serializable. Call enableRichArguments() " + '(from "@solidjs/web/server-functions/rich-args") once at startup ' + "to send Dates, Maps, Sets, typed arrays, files, etc. through the codec — " + "or pass a single Blob/FormData/File argument, which has a native " + "HTTP encoding.");
862
862
  }
863
863
  return config.serializeArgs(args);
864
864
  }
@@ -877,11 +877,10 @@ function configureServerFunctionsClient({
877
877
  if (responseHandler !== undefined) config.responseHandler = responseHandler;
878
878
  if (serializeArgs !== undefined) config.serializeArgs = serializeArgs;
879
879
  }
880
- let rpcProvided = false;
880
+ let rpc;
881
881
  function provideRPC() {
882
- if (rpcProvided) return;
883
- rpcProvided = true;
884
- provideServerFunctionRPC({
882
+ if (rpc) return;
883
+ provideServerFunctionRPC(rpc = {
885
884
  GET,
886
885
  decodeResponse
887
886
  });
@@ -895,7 +894,6 @@ function siblingAddressFor(base, kind) {
895
894
  return `${path.slice(0, slash + 1)}${kind}/${path.slice(slash + 1)}${rest}`;
896
895
  }
897
896
  const dataAddressFor = base => siblingAddressFor(base, "data");
898
- const liveAddressFor = base => siblingAddressFor(base, "live");
899
897
  function serverFunctionFailure(response, value) {
900
898
  const unknown = response.headers.get(UNKNOWN_HEADER) !== null;
901
899
  const error = value ?? new Error(unknown ? "Server function is not part of the deployment that answered (version skew or removed function)" : `Server function call failed with status ${response.status}`);
@@ -965,7 +963,7 @@ async function createRequest(base, id, options, meta) {
965
963
  }
966
964
  if (observation) observation.request(base, init);
967
965
  const send = config.fetch || fetch;
968
- return send(base, init);
966
+ return (meta.fetch || send)(base, init, send);
969
967
  }
970
968
  async function initializeResponse(base, id, options, args, meta) {
971
969
  if (args.length === 0) {
@@ -1022,7 +1020,6 @@ async function initializeResponse(base, id, options, args, meta) {
1022
1020
  body: await serializeArguments(args),
1023
1021
  headers: {
1024
1022
  ...options.headers,
1025
- "Content-Type": "text/plain",
1026
1023
  [BODY_FORMAT_HEADER]: BodyFormat.Serialized
1027
1024
  }
1028
1025
  }, meta);
@@ -1057,6 +1054,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
1057
1054
  ...options,
1058
1055
  [CALL_OBSERVATION]: observation
1059
1056
  };
1057
+ const startedAt = handler ? performance.now() : undefined;
1060
1058
  const response = await initializeResponse(base, id, options, args, meta);
1061
1059
  if (observation) observation.response(response);
1062
1060
  if (handler) {
@@ -1067,6 +1065,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
1067
1065
  context,
1068
1066
  retry: () => fetchServerFunction(base, id, sent, args, meta, callArgs)
1069
1067
  };
1068
+ ctx.startedAt = startedAt;
1070
1069
  if (options[LIVE_WIRE]) ctx[LIVE_WIRE] = options[LIVE_WIRE];
1071
1070
  const handled = handler.handle(response, ctx);
1072
1071
  if (handled !== undefined) return handled;
@@ -1223,6 +1222,9 @@ function trackLiveConnection(id, open) {
1223
1222
  const names = [...openLiveConnections].map(([fnId, n]) => n > 1 ? `${fnId} ×${n}` : fnId);
1224
1223
  console.warn(`live: ${total} live connections are open (${names.join(", ")}) and this page was served ` + `over ${protocol}. Browsers allow six connections per origin under HTTP/1.1, so the next ` + `request to this origin — a navigation, a fetch, an image — waits behind them. live ` + `requires HTTP/2: the dev server speaks it with \`server.https\`; production hosts do by default.`);
1225
1224
  }
1225
+ function broadcast(fn) {
1226
+ return live(fn);
1227
+ }
1226
1228
  function localOrSend(hit, send) {
1227
1229
  if (hit === null || typeof hit.then !== "function") return hit;
1228
1230
  return hit.then(answer => answer === undefined ? send() : answer);
@@ -1235,6 +1237,7 @@ function live(fn) {
1235
1237
  if (!isServerFunction(fn)) {
1236
1238
  throw new Error("live expects a server function reference");
1237
1239
  }
1240
+ if (getServerFunctionMetadata(fn)?.method !== "GET") fn = rpc.GET(fn);
1238
1241
  const id = fn.id;
1239
1242
  const metadata = {
1240
1243
  ...getServerFunctionMetadata(fn),
@@ -1327,19 +1330,7 @@ function live(fn) {
1327
1330
  wire.headers = from ? from.headers : undefined;
1328
1331
  if (from && from.position !== undefined) wire.position = from.position;
1329
1332
  }
1330
- if (metadata.method === "GET") return fn[SERVER_FUNCTION_INVOKE](args, wireOptions);
1331
- if (handler && handler.intercept && !wire.adopted) {
1332
- const hit = handler.intercept({
1333
- id,
1334
- meta: metadata,
1335
- args
1336
- });
1337
- if (hit !== undefined) return hit;
1338
- }
1339
- return fetchServerFunction(liveAddressFor(fn.url), id, {
1340
- ...wireOptions,
1341
- read: true
1342
- }, args, metadata, args);
1333
+ return fn[SERVER_FUNCTION_INVOKE](args, wireOptions);
1343
1334
  };
1344
1335
  const pull = async () => {
1345
1336
  if (resume !== undefined) {
@@ -1468,4 +1459,4 @@ function getServerFunctionInvocation() {
1468
1459
  return undefined;
1469
1460
  }
1470
1461
 
1471
- export { ChunkReader, ERROR_HEADER, EVENT_STREAM_HEARTBEAT, EventStreamReader, FLASH_COOKIE, GET, LAST_EVENT_ID_HEADER, LIVE_WIRE, REDIRECT_HEADER, REVALIDATE_HEADER, SERVER_FUNCTION_INVOKE, SINGLE_FLIGHT_HEADER, UNKNOWN_HEADER, clearFlashCookie, configureServerFunctionsClient, createChunk, createEventChunk, createServerReference, decodeErrorHeaderValue, decodeRedirectHeaderValue, decodeResponse, decodeResponsePayload, deliverFlightData, deserializeStream, encodeErrorHeaderValue, frameAddress, getFlightDataConsumer, getFlightDataSourceIds, getServerFunctionInvocation, getServerFunctionMetadata, getServerFunctionsCodec, hasFlashCookie, hasFlightMetadata, invoke, isEventStream, isServerFunction, live, parseServerFunctionActionUrl, positionDigest, registerServerReference, serializeString, serverFunctionActionUrl, serverFunctionUrl, subscribeFlightData, withMeta };
1462
+ export { ChunkReader, ERROR_HEADER, EVENT_STREAM_HEARTBEAT, EventStreamReader, FLASH_COOKIE, GET, LAST_EVENT_ID_HEADER, LIVE_WIRE, REDIRECT_HEADER, REVALIDATE_HEADER, SERVER_FUNCTION_INVOKE, SINGLE_FLIGHT_HEADER, UNKNOWN_HEADER, broadcast, clearFlashCookie, configureServerFunctionsClient, createChunk, createEventChunk, createServerReference, decodeErrorHeaderValue, decodeRedirectHeaderValue, decodeResponse, decodeResponsePayload, deliverFlightData, deserializeStream, encodeErrorHeaderValue, frameAddress, getFlightDataConsumer, getFlightDataSourceIds, getServerFunctionInvocation, getServerFunctionMetadata, getServerFunctionsCodec, hasFlashCookie, hasFlightMetadata, invoke, isEventStream, isServerFunction, live, parseServerFunctionActionUrl, positionDigest, registerServerReference, serializeString, serverFunctionActionUrl, serverFunctionUrl, subscribeFlightData, withMeta };