@solidjs/web 2.0.0-rc.5 → 2.0.0-rc.7

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 (52) hide show
  1. package/dist/server.cjs +122 -38
  2. package/dist/server.dev.cjs +3794 -0
  3. package/dist/server.dev.js +3627 -0
  4. package/dist/server.js +123 -39
  5. package/dist/web.cjs +102 -366
  6. package/dist/{dev.cjs → web.dev.cjs} +153 -376
  7. package/dist/{dev.js → web.dev.js} +155 -374
  8. package/dist/web.js +104 -364
  9. package/frames/dist/client.cjs +11 -3
  10. package/frames/dist/client.dev.cjs +11 -3
  11. package/frames/dist/client.dev.js +11 -3
  12. package/frames/dist/client.js +11 -3
  13. package/frames/dist/server.cjs +320 -53
  14. package/frames/dist/server.dev.cjs +4584 -0
  15. package/frames/dist/server.dev.js +4571 -0
  16. package/frames/dist/server.js +320 -53
  17. package/frames/package.json +10 -0
  18. package/package.json +78 -8
  19. package/serialization/dist/decode.cjs +18 -4
  20. package/serialization/dist/decode.js +18 -4
  21. package/serialization/dist/serialization.cjs +18 -4
  22. package/serialization/dist/serialization.js +18 -4
  23. package/server-functions/dist/client.cjs +27 -16
  24. package/server-functions/dist/client.js +27 -16
  25. package/server-functions/dist/server.cjs +529 -131
  26. package/server-functions/dist/server.dev.cjs +536 -130
  27. package/server-functions/dist/server.dev.js +536 -130
  28. package/server-functions/dist/server.js +529 -131
  29. package/types/client.d.ts +1 -3
  30. package/types/constants.d.ts +3 -1
  31. package/types/frames/frame-client.d.ts +1 -1
  32. package/types/head.d.ts +3 -0
  33. package/types/index.d.ts +18 -7
  34. package/types/index.server.d.ts +31 -9
  35. package/types/render.d.ts +3 -1
  36. package/types/server-functions/flash.d.ts +12 -3
  37. package/types/server-functions/server.d.ts +100 -5
  38. package/types/server-mock.d.ts +43 -7
  39. package/types/server.d.ts +47 -5
  40. package/types-cjs/client.d.cts +1 -3
  41. package/types-cjs/constants.d.cts +3 -1
  42. package/types-cjs/frames/frame-client.d.cts +1 -1
  43. package/types-cjs/head.d.cts +3 -0
  44. package/types-cjs/index.d.cts +18 -7
  45. package/types-cjs/index.server.d.cts +31 -9
  46. package/types-cjs/render.d.cts +3 -1
  47. package/types-cjs/server-functions/flash.d.cts +12 -3
  48. package/types-cjs/server-functions/server.d.cts +100 -5
  49. package/types-cjs/server-mock.d.cts +43 -7
  50. package/types-cjs/server.d.cts +47 -5
  51. package/types/patch-driver.d.ts +0 -3
  52. package/types-cjs/patch-driver.d.cts +0 -3
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.5",
4
+ "version": "2.0.0-rc.7",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -43,6 +43,16 @@
43
43
  "exports": {
44
44
  ".": {
45
45
  "worker": {
46
+ "development": {
47
+ "import": {
48
+ "types": "./types/index.d.ts",
49
+ "default": "./dist/server.dev.js"
50
+ },
51
+ "require": {
52
+ "types": "./types-cjs/index.d.cts",
53
+ "default": "./dist/server.dev.cjs"
54
+ }
55
+ },
46
56
  "import": {
47
57
  "types": "./types/index.d.ts",
48
58
  "default": "./dist/server.js"
@@ -56,11 +66,11 @@
56
66
  "development": {
57
67
  "import": {
58
68
  "types": "./types/index.d.ts",
59
- "default": "./dist/dev.js"
69
+ "default": "./dist/web.dev.js"
60
70
  },
61
71
  "require": {
62
72
  "types": "./types-cjs/index.d.cts",
63
- "default": "./dist/dev.cjs"
73
+ "default": "./dist/web.dev.cjs"
64
74
  }
65
75
  },
66
76
  "import": {
@@ -73,6 +83,16 @@
73
83
  }
74
84
  },
75
85
  "deno": {
86
+ "development": {
87
+ "import": {
88
+ "types": "./types/index.d.ts",
89
+ "default": "./dist/server.dev.js"
90
+ },
91
+ "require": {
92
+ "types": "./types-cjs/index.d.cts",
93
+ "default": "./dist/server.dev.cjs"
94
+ }
95
+ },
76
96
  "import": {
77
97
  "types": "./types/index.d.ts",
78
98
  "default": "./dist/server.js"
@@ -83,6 +103,16 @@
83
103
  }
84
104
  },
85
105
  "node": {
106
+ "development": {
107
+ "import": {
108
+ "types": "./types/index.d.ts",
109
+ "default": "./dist/server.dev.js"
110
+ },
111
+ "require": {
112
+ "types": "./types-cjs/index.d.cts",
113
+ "default": "./dist/server.dev.cjs"
114
+ }
115
+ },
86
116
  "import": {
87
117
  "types": "./types/index.d.ts",
88
118
  "default": "./dist/server.js"
@@ -95,11 +125,11 @@
95
125
  "development": {
96
126
  "import": {
97
127
  "types": "./types/index.d.ts",
98
- "default": "./dist/dev.js"
128
+ "default": "./dist/web.dev.js"
99
129
  },
100
130
  "require": {
101
131
  "types": "./types-cjs/index.d.cts",
102
- "default": "./dist/dev.cjs"
132
+ "default": "./dist/web.dev.cjs"
103
133
  }
104
134
  },
105
135
  "import": {
@@ -124,11 +154,11 @@
124
154
  "./jsx-dev-runtime": {
125
155
  "import": {
126
156
  "types": "./types/jsx.d.ts",
127
- "default": "./dist/dev.js"
157
+ "default": "./dist/web.dev.js"
128
158
  },
129
159
  "require": {
130
160
  "types": "./types-cjs/jsx.d.cts",
131
- "default": "./dist/dev.cjs"
161
+ "default": "./dist/web.dev.cjs"
132
162
  }
133
163
  },
134
164
  "./storage": {
@@ -283,6 +313,16 @@
283
313
  },
284
314
  "./frames": {
285
315
  "worker": {
316
+ "development": {
317
+ "import": {
318
+ "types": "./types/frames/server.d.ts",
319
+ "default": "./frames/dist/server.dev.js"
320
+ },
321
+ "require": {
322
+ "types": "./types-cjs/frames/server.d.cts",
323
+ "default": "./frames/dist/server.dev.cjs"
324
+ }
325
+ },
286
326
  "import": {
287
327
  "types": "./types/frames/server.d.ts",
288
328
  "default": "./frames/dist/server.js"
@@ -313,6 +353,16 @@
313
353
  }
314
354
  },
315
355
  "deno": {
356
+ "development": {
357
+ "import": {
358
+ "types": "./types/frames/server.d.ts",
359
+ "default": "./frames/dist/server.dev.js"
360
+ },
361
+ "require": {
362
+ "types": "./types-cjs/frames/server.d.cts",
363
+ "default": "./frames/dist/server.dev.cjs"
364
+ }
365
+ },
316
366
  "import": {
317
367
  "types": "./types/frames/server.d.ts",
318
368
  "default": "./frames/dist/server.js"
@@ -323,6 +373,16 @@
323
373
  }
324
374
  },
325
375
  "node": {
376
+ "development": {
377
+ "import": {
378
+ "types": "./types/frames/server.d.ts",
379
+ "default": "./frames/dist/server.dev.js"
380
+ },
381
+ "require": {
382
+ "types": "./types-cjs/frames/server.d.cts",
383
+ "default": "./frames/dist/server.dev.cjs"
384
+ }
385
+ },
326
386
  "import": {
327
387
  "types": "./types/frames/server.d.ts",
328
388
  "default": "./frames/dist/server.js"
@@ -352,6 +412,16 @@
352
412
  }
353
413
  },
354
414
  "./frames/server": {
415
+ "development": {
416
+ "import": {
417
+ "types": "./types/frames/server.d.ts",
418
+ "default": "./frames/dist/server.dev.js"
419
+ },
420
+ "require": {
421
+ "types": "./types-cjs/frames/server.d.cts",
422
+ "default": "./frames/dist/server.dev.cjs"
423
+ }
424
+ },
355
425
  "import": {
356
426
  "types": "./types/frames/server.d.ts",
357
427
  "default": "./frames/dist/server.js"
@@ -398,7 +468,7 @@
398
468
  "seroval-plugins": "~1.5.4"
399
469
  },
400
470
  "peerDependencies": {
401
- "solid-js": "^2.0.0-rc.5"
471
+ "solid-js": "^2.0.0-rc.7"
402
472
  },
403
473
  "devDependencies": {
404
474
  "@codspeed/vitest-plugin": "^5.4.0",
@@ -98,11 +98,25 @@ function resolveCodecOptions({
98
98
  function createJSONDeserializer(options) {
99
99
  const refs = new Map();
100
100
  const resolved = resolveCodecOptions(options);
101
+ let owned = 0;
102
+ function ownDecodedPromises() {
103
+ if (refs.size === owned) return;
104
+ let index = 0;
105
+ for (const value of refs.values()) {
106
+ if (index++ < owned) continue;
107
+ if (value instanceof Promise) value.then(undefined, () => {});
108
+ }
109
+ owned = refs.size;
110
+ }
101
111
  function deserializeJSONChunk(node) {
102
- return seroval.fromCrossJSON(node, {
103
- refs,
104
- ...resolved
105
- });
112
+ try {
113
+ return seroval.fromCrossJSON(node, {
114
+ refs,
115
+ ...resolved
116
+ });
117
+ } finally {
118
+ ownDecodedPromises();
119
+ }
106
120
  }
107
121
  deserializeJSONChunk.abort = function abort(error) {
108
122
  for (const value of refs.values()) {
@@ -96,11 +96,25 @@ function resolveCodecOptions({
96
96
  function createJSONDeserializer(options) {
97
97
  const refs = new Map();
98
98
  const resolved = resolveCodecOptions(options);
99
+ let owned = 0;
100
+ function ownDecodedPromises() {
101
+ if (refs.size === owned) return;
102
+ let index = 0;
103
+ for (const value of refs.values()) {
104
+ if (index++ < owned) continue;
105
+ if (value instanceof Promise) value.then(undefined, () => {});
106
+ }
107
+ owned = refs.size;
108
+ }
99
109
  function deserializeJSONChunk(node) {
100
- return fromCrossJSON(node, {
101
- refs,
102
- ...resolved
103
- });
110
+ try {
111
+ return fromCrossJSON(node, {
112
+ refs,
113
+ ...resolved
114
+ });
115
+ } finally {
116
+ ownDecodedPromises();
117
+ }
104
118
  }
105
119
  deserializeJSONChunk.abort = function abort(error) {
106
120
  for (const value of refs.values()) {
@@ -98,11 +98,25 @@ function resolveCodecOptions({
98
98
  function createJSONDeserializer(options) {
99
99
  const refs = new Map();
100
100
  const resolved = resolveCodecOptions(options);
101
+ let owned = 0;
102
+ function ownDecodedPromises() {
103
+ if (refs.size === owned) return;
104
+ let index = 0;
105
+ for (const value of refs.values()) {
106
+ if (index++ < owned) continue;
107
+ if (value instanceof Promise) value.then(undefined, () => {});
108
+ }
109
+ owned = refs.size;
110
+ }
101
111
  function deserializeJSONChunk(node) {
102
- return seroval.fromCrossJSON(node, {
103
- refs,
104
- ...resolved
105
- });
112
+ try {
113
+ return seroval.fromCrossJSON(node, {
114
+ refs,
115
+ ...resolved
116
+ });
117
+ } finally {
118
+ ownDecodedPromises();
119
+ }
106
120
  }
107
121
  deserializeJSONChunk.abort = function abort(error) {
108
122
  for (const value of refs.values()) {
@@ -96,11 +96,25 @@ function resolveCodecOptions({
96
96
  function createJSONDeserializer(options) {
97
97
  const refs = new Map();
98
98
  const resolved = resolveCodecOptions(options);
99
+ let owned = 0;
100
+ function ownDecodedPromises() {
101
+ if (refs.size === owned) return;
102
+ let index = 0;
103
+ for (const value of refs.values()) {
104
+ if (index++ < owned) continue;
105
+ if (value instanceof Promise) value.then(undefined, () => {});
106
+ }
107
+ owned = refs.size;
108
+ }
99
109
  function deserializeJSONChunk(node) {
100
- return fromCrossJSON(node, {
101
- refs,
102
- ...resolved
103
- });
110
+ try {
111
+ return fromCrossJSON(node, {
112
+ refs,
113
+ ...resolved
114
+ });
115
+ } finally {
116
+ ownDecodedPromises();
117
+ }
104
118
  }
105
119
  deserializeJSONChunk.abort = function abort(error) {
106
120
  for (const value of refs.values()) {
@@ -244,7 +244,7 @@ function isJSONSafe(value) {
244
244
  const t = typeof v;
245
245
  if (t === "string" || t === "boolean") continue;
246
246
  if (t === "number") {
247
- if (!Number.isFinite(v)) return false;
247
+ if (!Number.isFinite(v) || Object.is(v, -0)) return false;
248
248
  continue;
249
249
  }
250
250
  if (t !== "object") return false;
@@ -330,31 +330,30 @@ function getHeadersAndBody(body) {
330
330
  async function extractBody(source, codecOptions) {
331
331
  const contentType = source.headers.get("content-type");
332
332
  const format = source.headers.get(BODY_FORMAT_HEADER);
333
- const clone = source.clone();
334
333
  switch (true) {
335
334
  case format === BodyFormat.Serialized:
336
- return await deserializeStream(clone, codecOptions);
335
+ return await deserializeStream(source, codecOptions);
337
336
  case format === BodyFormat.Json:
338
- return JSON.parse(await clone.text());
337
+ return JSON.parse(await source.text());
339
338
  case format === BodyFormat.String:
340
- return await clone.text();
339
+ return await source.text();
341
340
  case format === BodyFormat.File:
342
341
  {
343
- const formData = await clone.formData();
342
+ const formData = await source.formData();
344
343
  return formData.get(FILE_FORM_KEY);
345
344
  }
346
345
  case format === BodyFormat.FormData:
347
346
  case contentType && contentType.startsWith("multipart/form-data"):
348
- return await clone.formData();
347
+ return await source.formData();
349
348
  case format === BodyFormat.URLSearchParams:
350
349
  case contentType && contentType.startsWith("application/x-www-form-urlencoded"):
351
- return new URLSearchParams(await clone.text());
350
+ return new URLSearchParams(await source.text());
352
351
  case format === BodyFormat.Blob:
353
- return await clone.blob();
352
+ return await source.blob();
354
353
  case format === BodyFormat.ArrayBuffer:
355
- return await clone.arrayBuffer();
354
+ return await source.arrayBuffer();
356
355
  case format === BodyFormat.Uint8Array:
357
- return new Uint8Array(await clone.arrayBuffer());
356
+ return new Uint8Array(await source.arrayBuffer());
358
357
  }
359
358
  return undefined;
360
359
  }
@@ -503,7 +502,7 @@ async function deserializeStream(source, codecOptions) {
503
502
  }
504
503
  async function decodeResponse(response, codecOptions) {
505
504
  if (!response.body) return undefined;
506
- return await extractBody(response, codecOptions === undefined ? codecConfig.codec : codecOptions);
505
+ return await extractBody(response.clone(), codecOptions === undefined ? codecConfig.codec : codecOptions);
507
506
  }
508
507
  async function decodeResponsePayload(response, codecOptions) {
509
508
  const decoded = await decodeResponse(response, codecOptions);
@@ -635,10 +634,19 @@ async function createRequest(base, id, instance, options, meta) {
635
634
  headers
636
635
  };
637
636
  if (config.prepareRequest) {
638
- init = (await config.prepareRequest(init, {
637
+ const prepared = await config.prepareRequest(init, {
639
638
  id,
640
639
  meta
641
- })) || init;
640
+ });
641
+ if (prepared && prepared !== init) {
642
+ if (typeof prepared !== "object") {
643
+ 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, ... } })");
644
+ }
645
+ if (!new Headers(prepared.headers).has(INSTANCE_HEADER)) {
646
+ throw new Error("prepareRequest returned an init without the transport headers " + `(${INSTANCE_HEADER}), which would send the call without its payload or ` + "protocol. Spread the init it received: " + "init => ({ ...init, headers: { ...init.headers, ... } })");
647
+ }
648
+ }
649
+ init = prepared || init;
642
650
  }
643
651
  const send = config.fetch || fetch;
644
652
  if (CALL_OBSERVERS.size === 0) return send(base, init);
@@ -740,7 +748,7 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
740
748
  const folded = response.headers.get(SINGLE_FLIGHT_HEADER).split(",");
741
749
  const consumers = folded.map(source => [source, getFlightDataConsumer(source)]).filter(([, consumer]) => consumer);
742
750
  if (consumers.length > 0) {
743
- const payload = await decodeResponse(response);
751
+ const payload = response.body ? await extractBody(response, getServerFunctionsCodec()) : undefined;
744
752
  for (const [source, consumer] of consumers) {
745
753
  await consumer(payload.data[source], {
746
754
  response
@@ -755,7 +763,10 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
755
763
  if (response.headers.has(REDIRECT_HEADER) || response.headers.has(REVALIDATE_HEADER) || response.headers.has(SINGLE_FLIGHT_HEADER) || response.status >= 300 && response.status < 400 && response.status !== 304) {
756
764
  return response;
757
765
  }
758
- const result = await decodeResponse(response.clone());
766
+ if (response.status < 300 && !response.headers.has(BODY_FORMAT_HEADER) && !response.headers.has("X-Content-Raw")) {
767
+ throw serverFunctionFailure(response, new Error(`Server function response carries no recognized encoding (status ${response.status}` + `${response.headers.get("Content-Type") ? `, content-type ${response.headers.get("Content-Type")}` : ""}): answered by something other than the server function runtime`));
768
+ }
769
+ const result = response.body ? await extractBody(response, getServerFunctionsCodec()) : undefined;
759
770
  if (failed) {
760
771
  throw serverFunctionFailure(response, result);
761
772
  }
@@ -242,7 +242,7 @@ function isJSONSafe(value) {
242
242
  const t = typeof v;
243
243
  if (t === "string" || t === "boolean") continue;
244
244
  if (t === "number") {
245
- if (!Number.isFinite(v)) return false;
245
+ if (!Number.isFinite(v) || Object.is(v, -0)) return false;
246
246
  continue;
247
247
  }
248
248
  if (t !== "object") return false;
@@ -328,31 +328,30 @@ function getHeadersAndBody(body) {
328
328
  async function extractBody(source, codecOptions) {
329
329
  const contentType = source.headers.get("content-type");
330
330
  const format = source.headers.get(BODY_FORMAT_HEADER);
331
- const clone = source.clone();
332
331
  switch (true) {
333
332
  case format === BodyFormat.Serialized:
334
- return await deserializeStream(clone, codecOptions);
333
+ return await deserializeStream(source, codecOptions);
335
334
  case format === BodyFormat.Json:
336
- return JSON.parse(await clone.text());
335
+ return JSON.parse(await source.text());
337
336
  case format === BodyFormat.String:
338
- return await clone.text();
337
+ return await source.text();
339
338
  case format === BodyFormat.File:
340
339
  {
341
- const formData = await clone.formData();
340
+ const formData = await source.formData();
342
341
  return formData.get(FILE_FORM_KEY);
343
342
  }
344
343
  case format === BodyFormat.FormData:
345
344
  case contentType && contentType.startsWith("multipart/form-data"):
346
- return await clone.formData();
345
+ return await source.formData();
347
346
  case format === BodyFormat.URLSearchParams:
348
347
  case contentType && contentType.startsWith("application/x-www-form-urlencoded"):
349
- return new URLSearchParams(await clone.text());
348
+ return new URLSearchParams(await source.text());
350
349
  case format === BodyFormat.Blob:
351
- return await clone.blob();
350
+ return await source.blob();
352
351
  case format === BodyFormat.ArrayBuffer:
353
- return await clone.arrayBuffer();
352
+ return await source.arrayBuffer();
354
353
  case format === BodyFormat.Uint8Array:
355
- return new Uint8Array(await clone.arrayBuffer());
354
+ return new Uint8Array(await source.arrayBuffer());
356
355
  }
357
356
  return undefined;
358
357
  }
@@ -501,7 +500,7 @@ async function deserializeStream(source, codecOptions) {
501
500
  }
502
501
  async function decodeResponse(response, codecOptions) {
503
502
  if (!response.body) return undefined;
504
- return await extractBody(response, codecOptions === undefined ? codecConfig.codec : codecOptions);
503
+ return await extractBody(response.clone(), codecOptions === undefined ? codecConfig.codec : codecOptions);
505
504
  }
506
505
  async function decodeResponsePayload(response, codecOptions) {
507
506
  const decoded = await decodeResponse(response, codecOptions);
@@ -633,10 +632,19 @@ async function createRequest(base, id, instance, options, meta) {
633
632
  headers
634
633
  };
635
634
  if (config.prepareRequest) {
636
- init = (await config.prepareRequest(init, {
635
+ const prepared = await config.prepareRequest(init, {
637
636
  id,
638
637
  meta
639
- })) || init;
638
+ });
639
+ if (prepared && prepared !== init) {
640
+ if (typeof prepared !== "object") {
641
+ 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, ... } })");
642
+ }
643
+ if (!new Headers(prepared.headers).has(INSTANCE_HEADER)) {
644
+ throw new Error("prepareRequest returned an init without the transport headers " + `(${INSTANCE_HEADER}), which would send the call without its payload or ` + "protocol. Spread the init it received: " + "init => ({ ...init, headers: { ...init.headers, ... } })");
645
+ }
646
+ }
647
+ init = prepared || init;
640
648
  }
641
649
  const send = config.fetch || fetch;
642
650
  if (CALL_OBSERVERS.size === 0) return send(base, init);
@@ -738,7 +746,7 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
738
746
  const folded = response.headers.get(SINGLE_FLIGHT_HEADER).split(",");
739
747
  const consumers = folded.map(source => [source, getFlightDataConsumer(source)]).filter(([, consumer]) => consumer);
740
748
  if (consumers.length > 0) {
741
- const payload = await decodeResponse(response);
749
+ const payload = response.body ? await extractBody(response, getServerFunctionsCodec()) : undefined;
742
750
  for (const [source, consumer] of consumers) {
743
751
  await consumer(payload.data[source], {
744
752
  response
@@ -753,7 +761,10 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
753
761
  if (response.headers.has(REDIRECT_HEADER) || response.headers.has(REVALIDATE_HEADER) || response.headers.has(SINGLE_FLIGHT_HEADER) || response.status >= 300 && response.status < 400 && response.status !== 304) {
754
762
  return response;
755
763
  }
756
- const result = await decodeResponse(response.clone());
764
+ if (response.status < 300 && !response.headers.has(BODY_FORMAT_HEADER) && !response.headers.has("X-Content-Raw")) {
765
+ throw serverFunctionFailure(response, new Error(`Server function response carries no recognized encoding (status ${response.status}` + `${response.headers.get("Content-Type") ? `, content-type ${response.headers.get("Content-Type")}` : ""}): answered by something other than the server function runtime`));
766
+ }
767
+ const result = response.body ? await extractBody(response, getServerFunctionsCodec()) : undefined;
757
768
  if (failed) {
758
769
  throw serverFunctionFailure(response, result);
759
770
  }