@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
@@ -1,11 +1,15 @@
1
- import { sharedConfig } from 'solid-js';
2
1
  import { fromCrossJSON, Feature, toCrossJSONStream } from 'seroval';
3
2
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
3
+ import { sharedConfig } from 'solid-js';
4
4
 
5
5
  const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
6
6
  function isResponseEnvelope(value) {
7
7
  return !!(value && typeof value === "object" && value[ENVELOPE]);
8
8
  }
9
+ const SAFE_ERROR = Symbol.for("solid.SafeError");
10
+ function isSafeError(value) {
11
+ return !!(value && (typeof value === "object" || typeof value === "function") && value[SAFE_ERROR]);
12
+ }
9
13
  const REVALIDATE_HEADER = "X-Revalidate";
10
14
 
11
15
  Feature.AggregateError | Feature.BigIntTypedArray;
@@ -55,11 +59,6 @@ function createJSONDeserializer(options) {
55
59
  };
56
60
  }
57
61
 
58
- const RequestContext = Symbol.for("solid.RequestContext");
59
- function getRequestEvent() {
60
- return globalThis[RequestContext] ? globalThis[RequestContext].getStore() || sharedConfig.context && sharedConfig.context.event || console.warn("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.") : undefined;
61
- }
62
-
63
62
  const codecConfig = {
64
63
  codec: undefined
65
64
  };
@@ -124,10 +123,6 @@ const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
124
123
  function hasFlashCookie(cookieHeader) {
125
124
  return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
126
125
  }
127
- function matchFlashCookie(cookieHeader) {
128
- const match = cookieHeader && cookieHeader.match(FLASH_MATCHER);
129
- return match ? match[1] : undefined;
130
- }
131
126
  function clearFlashCookie() {
132
127
  return `${FLASH_COOKIE}=; Max-Age=0; Path=/`;
133
128
  }
@@ -235,13 +230,11 @@ async function extractBody(source, codecOptions) {
235
230
  return undefined;
236
231
  }
237
232
  function createChunk(data) {
238
- const encodeData = new TextEncoder().encode(data);
233
+ const encoder = new TextEncoder();
234
+ const encodeData = encoder.encode(data);
239
235
  const bytes = encodeData.length;
240
- const baseHex = bytes.toString(16);
241
- const totalHex = "00000000".substring(0, 8 - baseHex.length) + baseHex;
242
- const head = new TextEncoder().encode(`;0x${totalHex};`);
243
236
  const chunk = new Uint8Array(12 + bytes);
244
- chunk.set(head);
237
+ chunk.set(encoder.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
245
238
  chunk.set(encodeData, 12);
246
239
  return chunk;
247
240
  }
@@ -273,8 +266,8 @@ class ChunkReader {
273
266
  }
274
267
  await this.readChunk();
275
268
  }
276
- const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
277
- const bytes = Number.parseInt(head, 16);
269
+ const decoder = new TextDecoder();
270
+ const bytes = Number.parseInt(decoder.decode(this.buffer.subarray(1, 11)), 16);
278
271
  if (Number.isNaN(bytes)) {
279
272
  throw new Error("Malformed server function stream.");
280
273
  }
@@ -284,7 +277,7 @@ class ChunkReader {
284
277
  }
285
278
  await this.readChunk();
286
279
  }
287
- const partial = new TextDecoder().decode(this.buffer.subarray(12, 12 + bytes));
280
+ const partial = decoder.decode(this.buffer.subarray(12, 12 + bytes));
288
281
  this.buffer = this.buffer.subarray(12 + bytes);
289
282
  return {
290
283
  done: false,
@@ -355,6 +348,114 @@ async function decodeResponsePayload(response, codecOptions) {
355
348
  };
356
349
  }
357
350
 
351
+ function parseCookieHeader(header) {
352
+ const cookies = {};
353
+ if (!header) return cookies;
354
+ for (const part of header.split(";")) {
355
+ const eq = part.indexOf("=");
356
+ if (eq < 0) continue;
357
+ const name = decodeSafe(part.slice(0, eq).trim());
358
+ let value = part.slice(eq + 1).trim();
359
+ if (value.length > 1 && value[0] === '"' && value[value.length - 1] === '"') {
360
+ value = value.slice(1, -1);
361
+ }
362
+ cookies[name] = decodeSafe(value);
363
+ }
364
+ return cookies;
365
+ }
366
+ function decodeSafe(text) {
367
+ try {
368
+ return decodeURIComponent(text);
369
+ } catch {
370
+ return text;
371
+ }
372
+ }
373
+ function serializeCookie(name, value, options = {}) {
374
+ let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
375
+ cookie += `; Path=${options.path === undefined ? "/" : options.path}`;
376
+ if (options.domain) cookie += `; Domain=${options.domain}`;
377
+ if (options.maxAge !== undefined) cookie += `; Max-Age=${Math.trunc(options.maxAge)}`;
378
+ if (options.expires) cookie += `; Expires=${options.expires.toUTCString()}`;
379
+ if (options.httpOnly) cookie += "; HttpOnly";
380
+ if (options.secure) cookie += "; Secure";
381
+ if (options.sameSite) {
382
+ const sameSite = options.sameSite.toLowerCase();
383
+ cookie += `; SameSite=${sameSite === "none" ? "None" : sameSite === "strict" ? "Strict" : "Lax"}`;
384
+ }
385
+ return cookie;
386
+ }
387
+
388
+ const RequestContext = Symbol.for("solid.RequestContext");
389
+ function getRequestEvent() {
390
+ return globalThis[RequestContext] ? globalThis[RequestContext].getStore() || sharedConfig.context && sharedConfig.context.event || console.warn("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.") : undefined;
391
+ }
392
+ function reportLostHeaderWrite(method, name) {
393
+ const message = `Response header write dropped: headers.${method}(${JSON.stringify(String(name))}) ` + "ran after the response head was sent. Write headers before the shell flushes " + "(or before the handler returns).";
394
+ console.error(message);
395
+ }
396
+ function commitResponseStub(stub, {
397
+ allowLateLocation = false
398
+ } = {}) {
399
+ if (!stub || stub.committed) return stub;
400
+ stub.committed = true;
401
+ const headers = stub.headers;
402
+ if (!headers || typeof headers.set !== "function") return stub;
403
+ for (const method of ["set", "append", "delete"]) {
404
+ const original = headers[method].bind(headers);
405
+ headers[method] = function (name, ...rest) {
406
+ if (allowLateLocation && method === "set" && String(name).toLowerCase() === "location") {
407
+ return original(name, ...rest);
408
+ }
409
+ reportLostHeaderWrite(method, name);
410
+ };
411
+ }
412
+ return stub;
413
+ }
414
+ function copyInitHeaders(init) {
415
+ if (!init || !init.getSetCookie) return new Headers(init);
416
+ const headers = new Headers();
417
+ init.forEach((value, key) => {
418
+ if (key !== "set-cookie") headers.append(key, value);
419
+ });
420
+ for (const cookie of init.getSetCookie()) headers.append("Set-Cookie", cookie);
421
+ return headers;
422
+ }
423
+ const STUB_GAP_FILL_EXCLUDED = /*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, "Location"].map(header => header.toLowerCase()));
424
+ function fillsStubGap(key, headers, response) {
425
+ if (key === "set-cookie" || STUB_GAP_FILL_EXCLUDED.has(key)) return false;
426
+ if (response.body === null && (key === "content-type" || key === "content-length")) return false;
427
+ return !headers.has(key);
428
+ }
429
+ function commitEventResponse(response, event = getRequestEvent()) {
430
+ const stub = event && event.response;
431
+ if (!stub || !stub.headers || stub.committed) return response;
432
+ const cookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
433
+ commitResponseStub(stub);
434
+ let hasGaps = false;
435
+ stub.headers.forEach((value, key) => {
436
+ if (fillsStubGap(key, response.headers, response)) hasGaps = true;
437
+ });
438
+ if (!cookies.length && !hasGaps) return response;
439
+ try {
440
+ for (const cookie of cookies) response.headers.append("Set-Cookie", cookie);
441
+ stub.headers.forEach((value, key) => {
442
+ if (fillsStubGap(key, response.headers, response)) response.headers.set(key, value);
443
+ });
444
+ return response;
445
+ } catch {
446
+ const headers = copyInitHeaders(response.headers);
447
+ for (const cookie of cookies) headers.append("Set-Cookie", cookie);
448
+ stub.headers.forEach((value, key) => {
449
+ if (fillsStubGap(key, headers, response)) headers.set(key, value);
450
+ });
451
+ return new Response(response.body, {
452
+ status: response.status,
453
+ statusText: response.statusText,
454
+ headers
455
+ });
456
+ }
457
+ }
458
+
358
459
  function encodeInputValue(value) {
359
460
  if (value instanceof FormData) return {
360
461
  $f: [...value.entries()].filter(([, v]) => typeof v === "string")
@@ -384,13 +485,16 @@ function encodeFlashCookie(url, result, input, thrown) {
384
485
  thrown: !!thrown,
385
486
  input: input.map(encodeInputValue)
386
487
  };
387
- return `${FLASH_COOKIE}=${encodeURIComponent(JSON.stringify(payload))}; Secure; HttpOnly; Path=/`;
488
+ return serializeCookie(FLASH_COOKIE, JSON.stringify(payload), {
489
+ secure: true,
490
+ httpOnly: true
491
+ });
388
492
  }
389
493
  function decodeFlashCookie(cookieHeader) {
390
- const match = matchFlashCookie(cookieHeader);
494
+ const match = parseCookieHeader(cookieHeader)[FLASH_COOKIE];
391
495
  if (!match) return;
392
496
  try {
393
- const payload = JSON.parse(decodeURIComponent(match));
497
+ const payload = JSON.parse(match);
394
498
  if (!payload || !payload.result) return;
395
499
  const result = payload.error ? new Error(payload.result) : payload.result;
396
500
  return {
@@ -406,6 +510,7 @@ function decodeFlashCookie(cookieHeader) {
406
510
 
407
511
  const config = {
408
512
  provideEvent: undefined,
513
+ wrapInvocation: undefined,
409
514
  collectFlightData: undefined,
410
515
  transformResult: undefined,
411
516
  transformFlightResult: undefined,
@@ -415,6 +520,7 @@ const config = {
415
520
  };
416
521
  function configureServerFunctionsServer({
417
522
  provideEvent,
523
+ wrapInvocation,
418
524
  collectFlightData,
419
525
  transformResult,
420
526
  transformFlightResult,
@@ -424,6 +530,7 @@ function configureServerFunctionsServer({
424
530
  codec
425
531
  } = {}) {
426
532
  if (provideEvent !== undefined) config.provideEvent = provideEvent;
533
+ if (wrapInvocation !== undefined) config.wrapInvocation = wrapInvocation;
427
534
  if (collectFlightData !== undefined) config.collectFlightData = collectFlightData;
428
535
  if (transformResult !== undefined) config.transformResult = transformResult;
429
536
  if (transformFlightResult !== undefined) config.transformFlightResult = transformFlightResult;
@@ -489,7 +596,13 @@ function createServerReference({
489
596
  });
490
597
  evt.serverOnly = true;
491
598
  const result = provideEvent(evt, () => {
492
- return fn.apply(thisArg, args);
599
+ const run = () => fn.apply(thisArg, args);
600
+ return config.wrapInvocation ? config.wrapInvocation(run, {
601
+ id,
602
+ args,
603
+ event: evt,
604
+ direct: true
605
+ }) : run();
493
606
  });
494
607
  const transform = config.transformDirectResult;
495
608
  if (transform && result && typeof result.then === "function") {
@@ -631,6 +744,16 @@ function foldSetCookies(headers, setCookies) {
631
744
  if (serialized) folded.set("cookie", serialized);
632
745
  return folded;
633
746
  }
747
+ function mergeResponseHeaders(target, source) {
748
+ source.forEach((value, key) => {
749
+ if (key !== "set-cookie") target.append(key, value);
750
+ });
751
+ if (source.getSetCookie) {
752
+ for (const cookie of source.getSetCookie()) target.append("Set-Cookie", cookie);
753
+ } else if (source.has("set-cookie")) {
754
+ target.append("Set-Cookie", source.get("set-cookie"));
755
+ }
756
+ }
634
757
  const validRedirectStatuses = new Set([301, 302, 303, 307, 308]);
635
758
  function createNoJSHandler({
636
759
  base = ""
@@ -645,7 +768,8 @@ function createNoJSHandler({
645
768
  let status = 303;
646
769
  let headers;
647
770
  if (result instanceof Response) {
648
- headers = new Headers(result.headers);
771
+ headers = new Headers();
772
+ mergeResponseHeaders(headers, result.headers);
649
773
  if (result.headers.has("Location")) {
650
774
  headers.set("Location", new URL(result.headers.get("Location"), url.origin + base).toString());
651
775
  if (validRedirectStatuses.has(result.status)) status = result.status;
@@ -698,13 +822,23 @@ function encodeResult(value, headers, status, codec) {
698
822
  headers
699
823
  });
700
824
  }
825
+ const GENERIC_SERVER_ERROR_MESSAGE = "Internal Server Error";
826
+ let DEV = false === true;
827
+ function setServerFunctionsDev(dev) {
828
+ DEV = !!dev;
829
+ }
830
+ function sanitizeServerError(value) {
831
+ if (DEV) return value;
832
+ if (isSafeError(value)) return value;
833
+ return new Error(GENERIC_SERVER_ERROR_MESSAGE);
834
+ }
701
835
  async function handleServerFunctionRequest(request, options = {}) {
702
836
  const codec = options.codec !== undefined ? options.codec : getServerFunctionsCodec();
703
837
  const url = new URL(request.url);
704
838
  const instance = request.headers.get(INSTANCE_HEADER);
705
839
  const functionId = resolveFunctionId(request, url);
706
840
  if (!functionId) {
707
- return new Response(process.env.NODE_ENV === "development" ? "Server function not found" : null, {
841
+ return new Response(DEV ? "Server function not found" : null, {
708
842
  status: 404
709
843
  });
710
844
  }
@@ -712,12 +846,12 @@ async function handleServerFunctionRequest(request, options = {}) {
712
846
  try {
713
847
  serverFunction = getServerFunction(functionId);
714
848
  } catch {
715
- return new Response(process.env.NODE_ENV === "development" ? `Unknown server function: ${functionId}` : null, {
849
+ return new Response(DEV ? `Unknown server function: ${functionId}` : null, {
716
850
  status: 404
717
851
  });
718
852
  }
719
853
  if (request.method === "GET" && METHODS.get(functionId) !== "GET") {
720
- return new Response(process.env.NODE_ENV === "development" ? `Method not allowed for server function: ${functionId}` : null, {
854
+ return new Response(DEV ? `Method not allowed for server function: ${functionId}` : null, {
721
855
  status: 405,
722
856
  headers: {
723
857
  Allow: "POST"
@@ -731,6 +865,7 @@ async function handleServerFunctionRequest(request, options = {}) {
731
865
  const provide = options.provideEvent || provideEvent;
732
866
  const flightHook = options.collectFlightData !== undefined ? options.collectFlightData : config.collectFlightData;
733
867
  const transformResult = options.transformResult !== undefined ? options.transformResult : config.transformResult;
868
+ const wrapInvocation = options.wrapInvocation !== undefined ? options.wrapInvocation : config.wrapInvocation;
734
869
  const transformFlightResult = options.transformFlightResult !== undefined ? options.transformFlightResult : config.transformFlightResult;
735
870
  const handleNoJS = options.handleNoJS !== undefined ? options.handleNoJS : config.handleNoJS !== undefined ? config.handleNoJS : isFormPost(request) ? defaultNoJSHandler || (defaultNoJSHandler = createNoJSHandler()) : undefined;
736
871
  const collectsFlight = !!(flightHook && instance && request.headers.has(SINGLE_FLIGHT_HEADER));
@@ -745,131 +880,142 @@ async function handleServerFunctionRequest(request, options = {}) {
745
880
  transformFlightResult
746
881
  };
747
882
  const headers = new Headers();
748
- try {
749
- let result = await provide(event, async () => {
750
- INVOCATIONS.set(event, {
751
- id: functionId
883
+ const dispatch = async () => {
884
+ try {
885
+ let result = await provide(event, async () => {
886
+ INVOCATIONS.set(event, {
887
+ id: functionId
888
+ });
889
+ const run = () => serverFunction(...parsed);
890
+ return wrapInvocation ? wrapInvocation(run, {
891
+ id: functionId,
892
+ args: parsed,
893
+ event,
894
+ request,
895
+ direct: false
896
+ }) : run();
752
897
  });
753
- return serverFunction(...parsed);
754
- });
755
- if (transformResult) {
756
- result = await transformResult(event, result, flightContext);
757
- }
758
- let status = 200;
759
- let metadata;
760
- if (isResponseEnvelope(result)) {
761
- const {
762
- response,
763
- value
764
- } = result;
765
- if (!instance && !handleNoJS && response && response.body) {
766
- return response;
767
- }
768
- if (response && response.headers) {
769
- response.headers.forEach((val, key) => headers.append(key, val));
770
- }
771
- if (response && response.status && (response.status < 300 || response.status >= 400)) {
772
- status = response.status;
773
- }
774
- metadata = response;
775
- result = value;
776
- } else if (result instanceof Response) {
777
- if (result.headers && result.headers.has("X-Content-Raw")) return result;
778
- if (instance) {
779
- if (result.headers) {
780
- result.headers.forEach((value, key) => headers.append(key, value));
781
- }
782
- if (result.status && (result.status < 300 || result.status >= 400)) {
783
- status = result.status;
784
- }
785
- metadata = result;
786
- if (result.body == null) {
787
- result = null;
788
- }
789
- }
790
- }
791
- if (collectsFlight) {
792
- result = await foldFlightData(flightHook, event, headers, {
793
- id: functionId,
794
- value: result,
795
- response: metadata,
796
- request,
797
- thrown: false
798
- }, flightContext);
799
- if (result instanceof Response && result.headers.has("X-Content-Raw")) return result;
800
- }
801
- if (!instance) {
802
- if (handleNoJS) return handleNoJS(result, request, parsed);
803
- if (result instanceof Response) return result;
804
- return encodeResult(result, headers, 200, codec);
805
- }
806
- return encodeResult(result, headers, status, codec);
807
- } catch (x) {
808
- if (x instanceof Response || isResponseEnvelope(x)) {
809
898
  if (transformResult) {
810
- x = await transformResult(event, x, {
811
- ...flightContext,
812
- thrown: true
813
- });
899
+ result = await transformResult(event, result, flightContext);
814
900
  }
815
901
  let status = 200;
816
902
  let metadata;
817
- if (isResponseEnvelope(x)) {
903
+ if (isResponseEnvelope(result)) {
818
904
  const {
819
905
  response,
820
906
  value
821
- } = x;
907
+ } = result;
908
+ if (!instance && !handleNoJS && response && response.body) {
909
+ return response;
910
+ }
822
911
  if (response && response.headers) {
823
- response.headers.forEach((val, key) => headers.append(key, val));
912
+ mergeResponseHeaders(headers, response.headers);
824
913
  }
825
- if (response && response.status && (!instance || response.status < 300 || response.status >= 400)) {
914
+ if (response && response.status && (response.status < 300 || response.status >= 400)) {
826
915
  status = response.status;
827
916
  }
828
917
  metadata = response;
829
- x = value;
830
- } else if (x instanceof Response) {
831
- if (x.headers) {
832
- x.headers.forEach((value, key) => headers.append(key, value));
833
- }
834
- if (x.status && (!instance || x.status < 300 || x.status >= 400)) {
835
- status = x.status;
836
- }
837
- metadata = x;
838
- if (x.body == null) {
839
- x = null;
918
+ result = value;
919
+ } else if (result instanceof Response) {
920
+ if (result.headers && result.headers.has("X-Content-Raw")) return result;
921
+ if (instance) {
922
+ if (result.headers) {
923
+ mergeResponseHeaders(headers, result.headers);
924
+ }
925
+ if (result.status && (result.status < 300 || result.status >= 400)) {
926
+ status = result.status;
927
+ }
928
+ metadata = result;
929
+ if (result.body == null) {
930
+ result = null;
931
+ }
840
932
  }
841
933
  }
842
934
  if (collectsFlight) {
843
- x = await foldFlightData(flightHook, event, headers, {
935
+ result = await foldFlightData(flightHook, event, headers, {
844
936
  id: functionId,
845
- value: x,
937
+ value: result,
846
938
  response: metadata,
847
939
  request,
848
- thrown: true
940
+ thrown: false
849
941
  }, flightContext);
850
- if (x instanceof Response && x.headers.has("X-Content-Raw")) {
851
- x.headers.set(ERROR_HEADER, "true");
852
- return x;
942
+ if (result instanceof Response && result.headers.has("X-Content-Raw")) return result;
943
+ }
944
+ if (!instance) {
945
+ if (handleNoJS) return handleNoJS(result, request, parsed);
946
+ if (result instanceof Response) return result;
947
+ return encodeResult(result, headers, 200, codec);
948
+ }
949
+ return encodeResult(result, headers, status, codec);
950
+ } catch (x) {
951
+ if (x instanceof Response || isResponseEnvelope(x)) {
952
+ if (transformResult) {
953
+ x = await transformResult(event, x, {
954
+ ...flightContext,
955
+ thrown: true
956
+ });
957
+ }
958
+ let status = 200;
959
+ let metadata;
960
+ if (isResponseEnvelope(x)) {
961
+ const {
962
+ response,
963
+ value
964
+ } = x;
965
+ if (response && response.headers) {
966
+ mergeResponseHeaders(headers, response.headers);
967
+ }
968
+ if (response && response.status && (!instance || response.status < 300 || response.status >= 400)) {
969
+ status = response.status;
970
+ }
971
+ metadata = response;
972
+ x = value;
973
+ } else if (x instanceof Response) {
974
+ if (x.headers) {
975
+ mergeResponseHeaders(headers, x.headers);
976
+ }
977
+ if (x.status && (!instance || x.status < 300 || x.status >= 400)) {
978
+ status = x.status;
979
+ }
980
+ metadata = x;
981
+ if (x.body == null) {
982
+ x = null;
983
+ }
984
+ }
985
+ if (collectsFlight) {
986
+ x = await foldFlightData(flightHook, event, headers, {
987
+ id: functionId,
988
+ value: x,
989
+ response: metadata,
990
+ request,
991
+ thrown: true
992
+ }, flightContext);
993
+ if (x instanceof Response && x.headers.has("X-Content-Raw")) {
994
+ x.headers.set(ERROR_HEADER, "true");
995
+ return x;
996
+ }
997
+ }
998
+ headers.set(ERROR_HEADER, "true");
999
+ if (!instance) {
1000
+ if (handleNoJS) return handleNoJS(x ?? metadata, request, parsed, true);
1001
+ if (x instanceof Response) return x;
853
1002
  }
1003
+ return encodeResult(x, headers, status, codec);
854
1004
  }
855
- headers.set(ERROR_HEADER, "true");
1005
+ const safe = sanitizeServerError(x);
856
1006
  if (!instance) {
857
- if (handleNoJS) return handleNoJS(x ?? metadata, request, parsed, true);
858
- if (x instanceof Response) return x;
1007
+ if (handleNoJS) return handleNoJS(safe, request, parsed, true);
1008
+ const message = safe instanceof Error ? safe.message : String(safe);
1009
+ return new Response(DEV ? message : null, {
1010
+ status: 500
1011
+ });
859
1012
  }
860
- return encodeResult(x, headers, status, codec);
861
- }
862
- if (!instance) {
863
- if (handleNoJS) return handleNoJS(x, request, parsed, true);
864
- const message = x instanceof Error ? x.message : String(x);
865
- return new Response(process.env.NODE_ENV === "development" ? message : null, {
866
- status: 500
867
- });
1013
+ const error = safe instanceof Error ? safe.message : typeof safe === "string" ? safe : "true";
1014
+ headers.set(ERROR_HEADER, encodeErrorHeaderValue(error));
1015
+ return encodeResult(safe, headers, 200, codec);
868
1016
  }
869
- const error = x instanceof Error ? x.message : typeof x === "string" ? x : "true";
870
- headers.set(ERROR_HEADER, encodeErrorHeaderValue(error));
871
- return encodeResult(x, headers, 200, codec);
872
- }
1017
+ };
1018
+ return commitEventResponse(await dispatch(), event);
873
1019
  }
874
1020
 
875
- export { ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, GET, INSTANCE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, configureServerFunctionsServer, createNoJSHandler, createServerReference, decodeErrorHeaderValue, decodeFlashCookie, decodeResponse, decodeResponsePayload, encodeErrorHeaderValue, encodeFlashCookie, foldSetCookies, getEventServerFunctionInvocation, getServerFunction, getServerFunctionInvocation, getServerFunctionMetadata, handleServerFunctionRequest, hasFlashCookie, isServerFunction, registerServerFunction, registerServerReference, subscribeFlightData, withMeta };
1021
+ export { ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, GENERIC_SERVER_ERROR_MESSAGE, GET, INSTANCE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, configureServerFunctionsServer, createNoJSHandler, createServerReference, decodeErrorHeaderValue, decodeFlashCookie, decodeResponse, decodeResponsePayload, encodeErrorHeaderValue, encodeFlashCookie, foldSetCookies, getEventServerFunctionInvocation, getServerFunction, getServerFunctionInvocation, getServerFunctionMetadata, handleServerFunctionRequest, hasFlashCookie, isServerFunction, registerServerFunction, registerServerReference, sanitizeServerError, setServerFunctionsDev, subscribeFlightData, withMeta };
@@ -17,6 +17,16 @@
17
17
  "default": "./dist/client.cjs"
18
18
  }
19
19
  },
20
+ "development": {
21
+ "import": {
22
+ "types": "../types/server-functions/server.d.ts",
23
+ "default": "./dist/server.dev.js"
24
+ },
25
+ "require": {
26
+ "types": "../types-cjs/server-functions/server.d.cts",
27
+ "default": "./dist/server.dev.cjs"
28
+ }
29
+ },
20
30
  "import": {
21
31
  "types": "../types/server-functions/server.d.ts",
22
32
  "default": "./dist/server.js"
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@solidjs/web/server-functions/rich-args",
3
+ "main": "../dist/rich-args.cjs",
4
+ "module": "../dist/rich-args.js",
5
+ "types": "../../types/server-functions/rich-args.d.ts",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "../../types/server-functions/rich-args.d.ts",
12
+ "default": "../dist/rich-args.js"
13
+ },
14
+ "require": {
15
+ "types": "../../types-cjs/server-functions/rich-args.d.cts",
16
+ "default": "../dist/rich-args.cjs"
17
+ }
18
+ }
19
+ }
20
+ }
@@ -15,7 +15,7 @@ import type { RequestEvent } from "@solidjs/web";
15
15
  *
16
16
  * async function handler(request: Request) {
17
17
  * return provideRequestEvent({ request, locals: {} }, () =>
18
- * renderToStringAsync(() => <App />)
18
+ * renderToStream(() => <App />)
19
19
  * );
20
20
  * }
21
21
  * ```
@@ -15,7 +15,7 @@ import type { RequestEvent } from "@solidjs/web";
15
15
  *
16
16
  * async function handler(request: Request) {
17
17
  * return provideRequestEvent({ request, locals: {} }, () =>
18
- * renderToStringAsync(() => <App />)
18
+ * renderToStream(() => <App />)
19
19
  * );
20
20
  * }
21
21
  * ```