@solidjs/web 2.0.0-beta.31 → 2.0.0-beta.32

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 (64) hide show
  1. package/README.md +1 -6
  2. package/dist/dev.cjs +234 -45
  3. package/dist/dev.js +221 -42
  4. package/dist/server.cjs +456 -123
  5. package/dist/server.js +445 -120
  6. package/dist/web.cjs +234 -45
  7. package/dist/web.js +221 -42
  8. package/frames/dist/client.cjs +217 -112
  9. package/frames/dist/client.dev.cjs +217 -112
  10. package/frames/dist/client.dev.js +218 -113
  11. package/frames/dist/client.js +218 -113
  12. package/frames/dist/server.cjs +488 -177
  13. package/frames/dist/server.js +489 -179
  14. package/package.json +55 -4
  15. package/serialization/dist/serialization.cjs +8 -0
  16. package/serialization/dist/serialization.js +1 -0
  17. package/serialization/types/index.d.ts +173 -6
  18. package/serialization/types-cjs/index.d.cts +173 -6
  19. package/server-functions/dist/client.cjs +46 -9
  20. package/server-functions/dist/client.js +47 -11
  21. package/server-functions/dist/rich-args.cjs +11 -0
  22. package/server-functions/dist/rich-args.js +9 -0
  23. package/server-functions/dist/server.cjs +275 -126
  24. package/server-functions/dist/server.dev.cjs +1053 -0
  25. package/server-functions/dist/server.dev.js +1021 -0
  26. package/server-functions/dist/server.js +273 -127
  27. package/server-functions/package.json +10 -0
  28. package/server-functions/rich-args/package.json +20 -0
  29. package/storage/types/index.d.ts +1 -1
  30. package/storage/types-cjs/index.d.cts +1 -1
  31. package/types/client.d.ts +127 -6
  32. package/types/core.d.ts +3 -1
  33. package/types/frames/client.d.ts +15 -1
  34. package/types/frames/frame-client.d.ts +37 -7
  35. package/types/frames/frame-sink.d.ts +26 -3
  36. package/types/frames/frame-transport.d.ts +39 -7
  37. package/types/frames/serializer.d.ts +173 -6
  38. package/types/frames/server.d.ts +22 -0
  39. package/types/index.d.ts +2 -3
  40. package/types/response.d.ts +45 -0
  41. package/types/serializer.d.ts +173 -6
  42. package/types/server-functions/client.d.ts +1 -0
  43. package/types/server-functions/rich-args.d.ts +10 -0
  44. package/types/server-functions/server.d.ts +98 -0
  45. package/types/server-functions/shared.d.ts +22 -0
  46. package/types/server-mock.d.ts +171 -59
  47. package/types/server.d.ts +188 -36
  48. package/types-cjs/client.d.cts +127 -6
  49. package/types-cjs/core.d.cts +3 -1
  50. package/types-cjs/frames/client.d.cts +15 -1
  51. package/types-cjs/frames/frame-client.d.cts +37 -7
  52. package/types-cjs/frames/frame-sink.d.cts +26 -3
  53. package/types-cjs/frames/frame-transport.d.cts +39 -7
  54. package/types-cjs/frames/serializer.d.cts +173 -6
  55. package/types-cjs/frames/server.d.cts +22 -0
  56. package/types-cjs/index.d.cts +2 -3
  57. package/types-cjs/response.d.cts +45 -0
  58. package/types-cjs/serializer.d.cts +173 -6
  59. package/types-cjs/server-functions/client.d.cts +1 -0
  60. package/types-cjs/server-functions/rich-args.d.cts +10 -0
  61. package/types-cjs/server-functions/server.d.cts +98 -0
  62. package/types-cjs/server-functions/shared.d.cts +22 -0
  63. package/types-cjs/server-mock.d.cts +171 -59
  64. package/types-cjs/server.d.cts +188 -36
@@ -6,6 +6,7 @@ var web = require('seroval-plugins/web');
6
6
  const REVALIDATE_HEADER = "X-Revalidate";
7
7
 
8
8
  seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
9
+ const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : seroval.Feature.ErrorPrototypeStack;
9
10
  const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
10
11
  web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
11
12
  web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin]);
@@ -25,6 +26,21 @@ function resolveCodecOptions({
25
26
  depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
26
27
  };
27
28
  }
29
+ function serializeJSON(value, {
30
+ onParse,
31
+ onDone,
32
+ onError,
33
+ ...codecOptions
34
+ }) {
35
+ const resolved = resolveCodecOptions(codecOptions);
36
+ return seroval.toCrossJSONStream(value, {
37
+ onParse,
38
+ onDone,
39
+ onError,
40
+ ...resolved,
41
+ disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures()
42
+ });
43
+ }
28
44
  function createJSONDeserializer(options) {
29
45
  const refs = new Map();
30
46
  const resolved = resolveCodecOptions(options);
@@ -259,13 +275,11 @@ async function extractBody(source, codecOptions) {
259
275
  return undefined;
260
276
  }
261
277
  function createChunk(data) {
262
- const encodeData = new TextEncoder().encode(data);
278
+ const encoder = new TextEncoder();
279
+ const encodeData = encoder.encode(data);
263
280
  const bytes = encodeData.length;
264
- const baseHex = bytes.toString(16);
265
- const totalHex = "00000000".substring(0, 8 - baseHex.length) + baseHex;
266
- const head = new TextEncoder().encode(`;0x${totalHex};`);
267
281
  const chunk = new Uint8Array(12 + bytes);
268
- chunk.set(head);
282
+ chunk.set(encoder.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
269
283
  chunk.set(encodeData, 12);
270
284
  return chunk;
271
285
  }
@@ -297,8 +311,8 @@ class ChunkReader {
297
311
  }
298
312
  await this.readChunk();
299
313
  }
300
- const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
301
- const bytes = Number.parseInt(head, 16);
314
+ const decoder = new TextDecoder();
315
+ const bytes = Number.parseInt(decoder.decode(this.buffer.subarray(1, 11)), 16);
302
316
  if (Number.isNaN(bytes)) {
303
317
  throw new Error("Malformed server function stream.");
304
318
  }
@@ -308,7 +322,7 @@ class ChunkReader {
308
322
  }
309
323
  await this.readChunk();
310
324
  }
311
- const partial = new TextDecoder().decode(this.buffer.subarray(12, 12 + bytes));
325
+ const partial = decoder.decode(this.buffer.subarray(12, 12 + bytes));
312
326
  this.buffer = this.buffer.subarray(12 + bytes);
313
327
  return {
314
328
  done: false,
@@ -325,6 +339,28 @@ class ChunkReader {
325
339
  }
326
340
  }
327
341
  }
342
+ function serializeStream(value, codecOptions) {
343
+ return new ReadableStream({
344
+ start(controller) {
345
+ serializeJSON(value, {
346
+ ...codecOptions,
347
+ onParse(node) {
348
+ controller.enqueue(createChunk(JSON.stringify(node)));
349
+ },
350
+ onDone() {
351
+ controller.close();
352
+ },
353
+ onError(error) {
354
+ controller.error(error);
355
+ }
356
+ });
357
+ }
358
+ });
359
+ }
360
+ async function serializeString(value, codecOptions) {
361
+ const response = new Response(serializeStream(value, codecOptions));
362
+ return await response.text();
363
+ }
328
364
  async function deserializeStream(source, codecOptions) {
329
365
  if (!source.body) {
330
366
  throw new Error("missing body");
@@ -381,7 +417,7 @@ function isJSONSafe(value) {
381
417
  }
382
418
  function serializeArguments(args) {
383
419
  if (!config.serializeArgs) {
384
- throw new Error("Server function arguments are sent as JSON by default and these " + "arguments are not JSON-serializable. Call enableRichArguments() " + "(from the server-functions rich-args entry) 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.");
420
+ 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.");
385
421
  }
386
422
  return config.serializeArgs(args);
387
423
  }
@@ -609,5 +645,6 @@ exports.getServerFunctionsCodec = getServerFunctionsCodec;
609
645
  exports.hasFlashCookie = hasFlashCookie;
610
646
  exports.isServerFunction = isServerFunction;
611
647
  exports.registerServerReference = registerServerReference;
648
+ exports.serializeString = serializeString;
612
649
  exports.subscribeFlightData = subscribeFlightData;
613
650
  exports.withMeta = withMeta;
@@ -1,9 +1,10 @@
1
- import { fromCrossJSON, Feature } from 'seroval';
1
+ import { fromCrossJSON, Feature, toCrossJSONStream } 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 REVALIDATE_HEADER = "X-Revalidate";
5
5
 
6
6
  Feature.AggregateError | Feature.BigIntTypedArray;
7
+ const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : Feature.ErrorPrototypeStack;
7
8
  const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
8
9
  CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
9
10
  FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin]);
@@ -23,6 +24,21 @@ function resolveCodecOptions({
23
24
  depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
24
25
  };
25
26
  }
27
+ function serializeJSON(value, {
28
+ onParse,
29
+ onDone,
30
+ onError,
31
+ ...codecOptions
32
+ }) {
33
+ const resolved = resolveCodecOptions(codecOptions);
34
+ return toCrossJSONStream(value, {
35
+ onParse,
36
+ onDone,
37
+ onError,
38
+ ...resolved,
39
+ disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures()
40
+ });
41
+ }
26
42
  function createJSONDeserializer(options) {
27
43
  const refs = new Map();
28
44
  const resolved = resolveCodecOptions(options);
@@ -257,13 +273,11 @@ async function extractBody(source, codecOptions) {
257
273
  return undefined;
258
274
  }
259
275
  function createChunk(data) {
260
- const encodeData = new TextEncoder().encode(data);
276
+ const encoder = new TextEncoder();
277
+ const encodeData = encoder.encode(data);
261
278
  const bytes = encodeData.length;
262
- const baseHex = bytes.toString(16);
263
- const totalHex = "00000000".substring(0, 8 - baseHex.length) + baseHex;
264
- const head = new TextEncoder().encode(`;0x${totalHex};`);
265
279
  const chunk = new Uint8Array(12 + bytes);
266
- chunk.set(head);
280
+ chunk.set(encoder.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
267
281
  chunk.set(encodeData, 12);
268
282
  return chunk;
269
283
  }
@@ -295,8 +309,8 @@ class ChunkReader {
295
309
  }
296
310
  await this.readChunk();
297
311
  }
298
- const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
299
- const bytes = Number.parseInt(head, 16);
312
+ const decoder = new TextDecoder();
313
+ const bytes = Number.parseInt(decoder.decode(this.buffer.subarray(1, 11)), 16);
300
314
  if (Number.isNaN(bytes)) {
301
315
  throw new Error("Malformed server function stream.");
302
316
  }
@@ -306,7 +320,7 @@ class ChunkReader {
306
320
  }
307
321
  await this.readChunk();
308
322
  }
309
- const partial = new TextDecoder().decode(this.buffer.subarray(12, 12 + bytes));
323
+ const partial = decoder.decode(this.buffer.subarray(12, 12 + bytes));
310
324
  this.buffer = this.buffer.subarray(12 + bytes);
311
325
  return {
312
326
  done: false,
@@ -323,6 +337,28 @@ class ChunkReader {
323
337
  }
324
338
  }
325
339
  }
340
+ function serializeStream(value, codecOptions) {
341
+ return new ReadableStream({
342
+ start(controller) {
343
+ serializeJSON(value, {
344
+ ...codecOptions,
345
+ onParse(node) {
346
+ controller.enqueue(createChunk(JSON.stringify(node)));
347
+ },
348
+ onDone() {
349
+ controller.close();
350
+ },
351
+ onError(error) {
352
+ controller.error(error);
353
+ }
354
+ });
355
+ }
356
+ });
357
+ }
358
+ async function serializeString(value, codecOptions) {
359
+ const response = new Response(serializeStream(value, codecOptions));
360
+ return await response.text();
361
+ }
326
362
  async function deserializeStream(source, codecOptions) {
327
363
  if (!source.body) {
328
364
  throw new Error("missing body");
@@ -379,7 +415,7 @@ function isJSONSafe(value) {
379
415
  }
380
416
  function serializeArguments(args) {
381
417
  if (!config.serializeArgs) {
382
- throw new Error("Server function arguments are sent as JSON by default and these " + "arguments are not JSON-serializable. Call enableRichArguments() " + "(from the server-functions rich-args entry) 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.");
418
+ 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.");
383
419
  }
384
420
  return config.serializeArgs(args);
385
421
  }
@@ -582,4 +618,4 @@ function getServerFunctionInvocation() {
582
618
  return undefined;
583
619
  }
584
620
 
585
- export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, GET, INSTANCE_HEADER, REVALIDATE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, configureServerFunctionsClient, createChunk, createServerReference, decodeErrorHeaderValue, decodeResponse, decodeResponsePayload, deserializeStream, encodeErrorHeaderValue, frameAddress, getFlightDataConsumer, getServerFunctionInvocation, getServerFunctionMetadata, getServerFunctionsCodec, hasFlashCookie, isServerFunction, registerServerReference, subscribeFlightData, withMeta };
621
+ export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, GET, INSTANCE_HEADER, REVALIDATE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, configureServerFunctionsClient, createChunk, createServerReference, decodeErrorHeaderValue, decodeResponse, decodeResponsePayload, deserializeStream, encodeErrorHeaderValue, frameAddress, getFlightDataConsumer, getServerFunctionInvocation, getServerFunctionMetadata, getServerFunctionsCodec, hasFlashCookie, isServerFunction, registerServerReference, serializeString, subscribeFlightData, withMeta };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var client = require('@solidjs/web/server-functions/client');
4
+
5
+ function enableRichArguments() {
6
+ client.configureServerFunctionsClient({
7
+ serializeArgs: args => client.serializeString(args, client.getServerFunctionsCodec())
8
+ });
9
+ }
10
+
11
+ exports.enableRichArguments = enableRichArguments;
@@ -0,0 +1,9 @@
1
+ import { configureServerFunctionsClient, serializeString, getServerFunctionsCodec } from '@solidjs/web/server-functions/client';
2
+
3
+ function enableRichArguments() {
4
+ configureServerFunctionsClient({
5
+ serializeArgs: args => serializeString(args, getServerFunctionsCodec())
6
+ });
7
+ }
8
+
9
+ export { enableRichArguments };