@solidjs/web 2.0.0-beta.27 → 2.0.0-beta.29

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 (43) hide show
  1. package/dist/dev.cjs +40 -2
  2. package/dist/dev.js +39 -4
  3. package/dist/server.cjs +113 -37
  4. package/dist/server.js +112 -39
  5. package/dist/web.cjs +40 -2
  6. package/dist/web.js +39 -4
  7. package/frames/dist/client.cjs +370 -209
  8. package/frames/dist/client.dev.cjs +370 -210
  9. package/frames/dist/client.dev.js +371 -211
  10. package/frames/dist/client.js +371 -210
  11. package/frames/dist/server.cjs +373 -74
  12. package/frames/dist/server.js +373 -75
  13. package/package.json +3 -3
  14. package/server-functions/dist/client.cjs +100 -3
  15. package/server-functions/dist/client.js +92 -4
  16. package/server-functions/dist/server.cjs +85 -17
  17. package/server-functions/dist/server.js +83 -17
  18. package/types/client.d.ts +15 -0
  19. package/types/core.d.ts +1 -1
  20. package/types/frames/client.d.ts +8 -5
  21. package/types/frames/frame-client.d.ts +17 -0
  22. package/types/frames/frame-sink.d.ts +29 -6
  23. package/types/frames/frame-transport.d.ts +76 -12
  24. package/types/frames/server.d.ts +29 -1
  25. package/types/index.d.ts +74 -0
  26. package/types/server-functions/client.d.ts +25 -0
  27. package/types/server-functions/server.d.ts +105 -18
  28. package/types/server-functions/shared.d.ts +22 -0
  29. package/types/server-mock.d.ts +6 -2
  30. package/types/server.d.ts +39 -1
  31. package/types-cjs/client.d.cts +15 -0
  32. package/types-cjs/core.d.cts +1 -1
  33. package/types-cjs/frames/client.d.cts +8 -5
  34. package/types-cjs/frames/frame-client.d.cts +17 -0
  35. package/types-cjs/frames/frame-sink.d.cts +29 -6
  36. package/types-cjs/frames/frame-transport.d.cts +76 -12
  37. package/types-cjs/frames/server.d.cts +29 -1
  38. package/types-cjs/index.d.cts +74 -0
  39. package/types-cjs/server-functions/client.d.cts +25 -0
  40. package/types-cjs/server-functions/server.d.cts +105 -18
  41. package/types-cjs/server-functions/shared.d.cts +22 -0
  42. package/types-cjs/server-mock.d.cts +6 -2
  43. package/types-cjs/server.d.cts +39 -1
@@ -42,6 +42,9 @@ const codecConfig = {
42
42
  function configureServerFunctionsCodec(codec) {
43
43
  codecConfig.codec = codec;
44
44
  }
45
+ function getServerFunctionsCodec() {
46
+ return codecConfig.codec;
47
+ }
45
48
  const flightConfig = {
46
49
  consumer: undefined
47
50
  };
@@ -54,6 +57,50 @@ function subscribeFlightData(consumer) {
54
57
  function getFlightDataConsumer() {
55
58
  return flightConfig.consumer;
56
59
  }
60
+ function frameAddress(id, args) {
61
+ return args && args.length ? id + ":" + hashArguments(args) : id;
62
+ }
63
+ function hashArguments(args) {
64
+ let hash = 0;
65
+ const text = stableString(args);
66
+ for (let i = 0; i < text.length; i++) {
67
+ hash = (hash << 5) - hash + text.charCodeAt(i);
68
+ hash |= 0;
69
+ }
70
+ return (hash >>> 0).toString(36);
71
+ }
72
+ function stableString(value, seen) {
73
+ if (value === null || typeof value !== "object") {
74
+ return typeof value === "bigint" ? value + "n" : String(value);
75
+ }
76
+ if (value instanceof Date) return "Date:" + value.getTime();
77
+ seen || (seen = new Set());
78
+ if (seen.has(value)) return "~";
79
+ seen.add(value);
80
+ if (value instanceof Map) {
81
+ const entries = [];
82
+ for (const [k, v] of value) {
83
+ entries.push(stableString(k, seen) + "=>" + stableString(v, seen));
84
+ }
85
+ return "Map{" + entries.sort().join(",") + "}";
86
+ }
87
+ if (value instanceof Set) {
88
+ const members = [];
89
+ for (const v of value) members.push(stableString(v, seen));
90
+ return "Set{" + members.sort().join(",") + "}";
91
+ }
92
+ if (Array.isArray(value)) {
93
+ let out = "[";
94
+ for (let i = 0; i < value.length; i++) out += (i ? "," : "") + stableString(value[i], seen);
95
+ return out + "]";
96
+ }
97
+ const keys = Object.keys(value).sort();
98
+ let out = "{";
99
+ for (let i = 0; i < keys.length; i++) {
100
+ out += (i ? "," : "") + keys[i] + ":" + stableString(value[keys[i]], seen);
101
+ }
102
+ return out + "}";
103
+ }
57
104
  const SERVER_FUNCTION_METADATA = Symbol.for("solid.ServerFunctionMetadata");
58
105
  function getServerFunctionMetadata(fn) {
59
106
  if (typeof fn !== "function") return undefined;
@@ -211,6 +258,17 @@ async function extractBody(source, codecOptions) {
211
258
  }
212
259
  return undefined;
213
260
  }
261
+ function createChunk(data) {
262
+ const encodeData = new TextEncoder().encode(data);
263
+ 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
+ const chunk = new Uint8Array(12 + bytes);
268
+ chunk.set(head);
269
+ chunk.set(encodeData, 12);
270
+ return chunk;
271
+ }
214
272
  class ChunkReader {
215
273
  constructor(stream) {
216
274
  this.reader = stream.getReader();
@@ -287,6 +345,18 @@ async function decodeResponse(response, codecOptions) {
287
345
  if (!response.body) return undefined;
288
346
  return await extractBody(response, codecOptions === undefined ? codecConfig.codec : codecOptions);
289
347
  }
348
+ async function decodeResponsePayload(response, codecOptions) {
349
+ const decoded = await decodeResponse(response, codecOptions);
350
+ if (decoded !== undefined && response.headers.has(SINGLE_FLIGHT_HEADER)) {
351
+ return {
352
+ value: decoded.value,
353
+ flightData: decoded.data
354
+ };
355
+ }
356
+ return {
357
+ value: decoded
358
+ };
359
+ }
290
360
 
291
361
  const config = {
292
362
  endpoint: "/_server",
@@ -379,6 +449,21 @@ async function initializeResponse(base, id, instance, options, args, meta) {
379
449
  }
380
450
  }, meta);
381
451
  }
452
+ if (args.length > 1) {
453
+ const trailing = getHeadersAndBody(args[args.length - 1]);
454
+ const leading = args.slice(0, -1).map(arg => arg === undefined ? null : arg);
455
+ if (trailing && isJSONSafe(leading)) {
456
+ const target = base + (base.includes("?") ? "&" : "?") + "args=" + encodeURIComponent(JSON.stringify(leading));
457
+ return createRequest(target, id, instance, {
458
+ ...options,
459
+ body: trailing.body,
460
+ headers: {
461
+ ...options.headers,
462
+ ...trailing.headers
463
+ }
464
+ }, meta);
465
+ }
466
+ }
382
467
  return createRequest(base, id, instance, {
383
468
  ...options,
384
469
  body: await serializeArguments(args),
@@ -389,7 +474,7 @@ async function initializeResponse(base, id, instance, options, args, meta) {
389
474
  }
390
475
  }, meta);
391
476
  }
392
- async function fetchServerFunction(base, id, options, args, meta) {
477
+ async function fetchServerFunction(base, id, options, args, meta, callArgs = args) {
393
478
  const instance = `server-function:${INSTANCE++}`;
394
479
  const handler = config.responseHandler;
395
480
  const context = handler && handler.capture ? handler.capture({
@@ -401,7 +486,7 @@ async function fetchServerFunction(base, id, options, args, meta) {
401
486
  const handled = handler.handle(response, {
402
487
  id,
403
488
  meta,
404
- args,
489
+ args: callArgs,
405
490
  context
406
491
  });
407
492
  if (handled !== undefined) return handled;
@@ -480,7 +565,7 @@ function GET(fn) {
480
565
  }
481
566
  return fetchServerFunction(base, id, {
482
567
  method: "GET"
483
- }, [], metadata);
568
+ }, [], metadata, args);
484
569
  };
485
570
  wrapped[SERVER_FUNCTION_METADATA] = metadata;
486
571
  wrapped.id = id;
@@ -495,20 +580,32 @@ function GET(fn) {
495
580
  function registerServerReference() {
496
581
  throw new Error("registerServerReference must not be called in the client build");
497
582
  }
583
+ function getServerFunctionInvocation() {
584
+ return undefined;
585
+ }
498
586
 
587
+ exports.ChunkReader = ChunkReader;
499
588
  exports.ERROR_HEADER = ERROR_HEADER;
500
589
  exports.FLASH_COOKIE = FLASH_COOKIE;
501
590
  exports.FUNCTION_HEADER = FUNCTION_HEADER;
502
591
  exports.GET = GET;
503
592
  exports.INSTANCE_HEADER = INSTANCE_HEADER;
593
+ exports.REVALIDATE_HEADER = REVALIDATE_HEADER;
504
594
  exports.SINGLE_FLIGHT_HEADER = SINGLE_FLIGHT_HEADER;
505
595
  exports.clearFlashCookie = clearFlashCookie;
506
596
  exports.configureServerFunctionsClient = configureServerFunctionsClient;
597
+ exports.createChunk = createChunk;
507
598
  exports.createServerReference = createServerReference;
508
599
  exports.decodeErrorHeaderValue = decodeErrorHeaderValue;
509
600
  exports.decodeResponse = decodeResponse;
601
+ exports.decodeResponsePayload = decodeResponsePayload;
602
+ exports.deserializeStream = deserializeStream;
510
603
  exports.encodeErrorHeaderValue = encodeErrorHeaderValue;
604
+ exports.frameAddress = frameAddress;
605
+ exports.getFlightDataConsumer = getFlightDataConsumer;
606
+ exports.getServerFunctionInvocation = getServerFunctionInvocation;
511
607
  exports.getServerFunctionMetadata = getServerFunctionMetadata;
608
+ exports.getServerFunctionsCodec = getServerFunctionsCodec;
512
609
  exports.hasFlashCookie = hasFlashCookie;
513
610
  exports.isServerFunction = isServerFunction;
514
611
  exports.registerServerReference = registerServerReference;
@@ -40,6 +40,9 @@ const codecConfig = {
40
40
  function configureServerFunctionsCodec(codec) {
41
41
  codecConfig.codec = codec;
42
42
  }
43
+ function getServerFunctionsCodec() {
44
+ return codecConfig.codec;
45
+ }
43
46
  const flightConfig = {
44
47
  consumer: undefined
45
48
  };
@@ -52,6 +55,50 @@ function subscribeFlightData(consumer) {
52
55
  function getFlightDataConsumer() {
53
56
  return flightConfig.consumer;
54
57
  }
58
+ function frameAddress(id, args) {
59
+ return args && args.length ? id + ":" + hashArguments(args) : id;
60
+ }
61
+ function hashArguments(args) {
62
+ let hash = 0;
63
+ const text = stableString(args);
64
+ for (let i = 0; i < text.length; i++) {
65
+ hash = (hash << 5) - hash + text.charCodeAt(i);
66
+ hash |= 0;
67
+ }
68
+ return (hash >>> 0).toString(36);
69
+ }
70
+ function stableString(value, seen) {
71
+ if (value === null || typeof value !== "object") {
72
+ return typeof value === "bigint" ? value + "n" : String(value);
73
+ }
74
+ if (value instanceof Date) return "Date:" + value.getTime();
75
+ seen || (seen = new Set());
76
+ if (seen.has(value)) return "~";
77
+ seen.add(value);
78
+ if (value instanceof Map) {
79
+ const entries = [];
80
+ for (const [k, v] of value) {
81
+ entries.push(stableString(k, seen) + "=>" + stableString(v, seen));
82
+ }
83
+ return "Map{" + entries.sort().join(",") + "}";
84
+ }
85
+ if (value instanceof Set) {
86
+ const members = [];
87
+ for (const v of value) members.push(stableString(v, seen));
88
+ return "Set{" + members.sort().join(",") + "}";
89
+ }
90
+ if (Array.isArray(value)) {
91
+ let out = "[";
92
+ for (let i = 0; i < value.length; i++) out += (i ? "," : "") + stableString(value[i], seen);
93
+ return out + "]";
94
+ }
95
+ const keys = Object.keys(value).sort();
96
+ let out = "{";
97
+ for (let i = 0; i < keys.length; i++) {
98
+ out += (i ? "," : "") + keys[i] + ":" + stableString(value[keys[i]], seen);
99
+ }
100
+ return out + "}";
101
+ }
55
102
  const SERVER_FUNCTION_METADATA = Symbol.for("solid.ServerFunctionMetadata");
56
103
  function getServerFunctionMetadata(fn) {
57
104
  if (typeof fn !== "function") return undefined;
@@ -209,6 +256,17 @@ async function extractBody(source, codecOptions) {
209
256
  }
210
257
  return undefined;
211
258
  }
259
+ function createChunk(data) {
260
+ const encodeData = new TextEncoder().encode(data);
261
+ 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
+ const chunk = new Uint8Array(12 + bytes);
266
+ chunk.set(head);
267
+ chunk.set(encodeData, 12);
268
+ return chunk;
269
+ }
212
270
  class ChunkReader {
213
271
  constructor(stream) {
214
272
  this.reader = stream.getReader();
@@ -285,6 +343,18 @@ async function decodeResponse(response, codecOptions) {
285
343
  if (!response.body) return undefined;
286
344
  return await extractBody(response, codecOptions === undefined ? codecConfig.codec : codecOptions);
287
345
  }
346
+ async function decodeResponsePayload(response, codecOptions) {
347
+ const decoded = await decodeResponse(response, codecOptions);
348
+ if (decoded !== undefined && response.headers.has(SINGLE_FLIGHT_HEADER)) {
349
+ return {
350
+ value: decoded.value,
351
+ flightData: decoded.data
352
+ };
353
+ }
354
+ return {
355
+ value: decoded
356
+ };
357
+ }
288
358
 
289
359
  const config = {
290
360
  endpoint: "/_server",
@@ -377,6 +447,21 @@ async function initializeResponse(base, id, instance, options, args, meta) {
377
447
  }
378
448
  }, meta);
379
449
  }
450
+ if (args.length > 1) {
451
+ const trailing = getHeadersAndBody(args[args.length - 1]);
452
+ const leading = args.slice(0, -1).map(arg => arg === undefined ? null : arg);
453
+ if (trailing && isJSONSafe(leading)) {
454
+ const target = base + (base.includes("?") ? "&" : "?") + "args=" + encodeURIComponent(JSON.stringify(leading));
455
+ return createRequest(target, id, instance, {
456
+ ...options,
457
+ body: trailing.body,
458
+ headers: {
459
+ ...options.headers,
460
+ ...trailing.headers
461
+ }
462
+ }, meta);
463
+ }
464
+ }
380
465
  return createRequest(base, id, instance, {
381
466
  ...options,
382
467
  body: await serializeArguments(args),
@@ -387,7 +472,7 @@ async function initializeResponse(base, id, instance, options, args, meta) {
387
472
  }
388
473
  }, meta);
389
474
  }
390
- async function fetchServerFunction(base, id, options, args, meta) {
475
+ async function fetchServerFunction(base, id, options, args, meta, callArgs = args) {
391
476
  const instance = `server-function:${INSTANCE++}`;
392
477
  const handler = config.responseHandler;
393
478
  const context = handler && handler.capture ? handler.capture({
@@ -399,7 +484,7 @@ async function fetchServerFunction(base, id, options, args, meta) {
399
484
  const handled = handler.handle(response, {
400
485
  id,
401
486
  meta,
402
- args,
487
+ args: callArgs,
403
488
  context
404
489
  });
405
490
  if (handled !== undefined) return handled;
@@ -478,7 +563,7 @@ function GET(fn) {
478
563
  }
479
564
  return fetchServerFunction(base, id, {
480
565
  method: "GET"
481
- }, [], metadata);
566
+ }, [], metadata, args);
482
567
  };
483
568
  wrapped[SERVER_FUNCTION_METADATA] = metadata;
484
569
  wrapped.id = id;
@@ -493,5 +578,8 @@ function GET(fn) {
493
578
  function registerServerReference() {
494
579
  throw new Error("registerServerReference must not be called in the client build");
495
580
  }
581
+ function getServerFunctionInvocation() {
582
+ return undefined;
583
+ }
496
584
 
497
- export { ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, GET, INSTANCE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, configureServerFunctionsClient, createServerReference, decodeErrorHeaderValue, decodeResponse, encodeErrorHeaderValue, getServerFunctionMetadata, hasFlashCookie, isServerFunction, registerServerReference, subscribeFlightData, withMeta };
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 };
@@ -8,6 +8,7 @@ const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
8
8
  function isResponseEnvelope(value) {
9
9
  return !!(value && typeof value === "object" && value[ENVELOPE]);
10
10
  }
11
+ const REVALIDATE_HEADER = "X-Revalidate";
11
12
 
12
13
  seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
13
14
  const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : seroval.Feature.ErrorPrototypeStack;
@@ -343,6 +344,18 @@ async function decodeResponse(response, codecOptions) {
343
344
  if (!response.body) return undefined;
344
345
  return await extractBody(response, codecOptions === undefined ? codecConfig.codec : codecOptions);
345
346
  }
347
+ async function decodeResponsePayload(response, codecOptions) {
348
+ const decoded = await decodeResponse(response, codecOptions);
349
+ if (decoded !== undefined && response.headers.has(SINGLE_FLIGHT_HEADER)) {
350
+ return {
351
+ value: decoded.value,
352
+ flightData: decoded.data
353
+ };
354
+ }
355
+ return {
356
+ value: decoded
357
+ };
358
+ }
346
359
 
347
360
  function encodeInputValue(value) {
348
361
  if (value instanceof FormData) return {
@@ -397,6 +410,7 @@ const config = {
397
410
  provideEvent: undefined,
398
411
  collectFlightData: undefined,
399
412
  transformResult: undefined,
413
+ transformFlightResult: undefined,
400
414
  transformDirectResult: undefined,
401
415
  handleNoJS: undefined,
402
416
  endpoint: "/_server"
@@ -405,6 +419,7 @@ function configureServerFunctionsServer({
405
419
  provideEvent,
406
420
  collectFlightData,
407
421
  transformResult,
422
+ transformFlightResult,
408
423
  transformDirectResult,
409
424
  handleNoJS,
410
425
  endpoint,
@@ -413,6 +428,7 @@ function configureServerFunctionsServer({
413
428
  if (provideEvent !== undefined) config.provideEvent = provideEvent;
414
429
  if (collectFlightData !== undefined) config.collectFlightData = collectFlightData;
415
430
  if (transformResult !== undefined) config.transformResult = transformResult;
431
+ if (transformFlightResult !== undefined) config.transformFlightResult = transformFlightResult;
416
432
  if (transformDirectResult !== undefined) config.transformDirectResult = transformDirectResult;
417
433
  if (handleNoJS !== undefined) config.handleNoJS = handleNoJS;
418
434
  if (endpoint !== undefined) config.endpoint = endpoint;
@@ -426,6 +442,7 @@ function provideEvent(event, fn) {
426
442
  }
427
443
  const REGISTRATIONS = new Map();
428
444
  const METHODS = new Map();
445
+ const INVOCATIONS = new WeakMap();
429
446
  function registerServerFunction(id, callback) {
430
447
  REGISTRATIONS.set(id, callback);
431
448
  return callback;
@@ -469,9 +486,9 @@ function createServerReference({
469
486
  const evt = {
470
487
  ...ogEvt
471
488
  };
472
- evt.locals.serverFunctionMeta = {
489
+ INVOCATIONS.set(evt, {
473
490
  id
474
- };
491
+ });
475
492
  evt.serverOnly = true;
476
493
  const result = provideEvent(evt, () => {
477
494
  return fn.apply(thisArg, args);
@@ -480,11 +497,13 @@ function createServerReference({
480
497
  if (transform && result && typeof result.then === "function") {
481
498
  return result.then(value => transform(value, {
482
499
  id,
500
+ args,
483
501
  event: evt
484
502
  }));
485
503
  }
486
504
  return transform ? transform(result, {
487
505
  id,
506
+ args,
488
507
  event: evt
489
508
  }) : result;
490
509
  }
@@ -499,9 +518,11 @@ function GET(fn) {
499
518
  method: "GET"
500
519
  });
501
520
  }
502
- function getServerFunctionMeta() {
503
- const event = getRequestEvent();
504
- return event && event.locals.serverFunctionMeta;
521
+ function getServerFunctionInvocation() {
522
+ return getEventServerFunctionInvocation(getRequestEvent());
523
+ }
524
+ function getEventServerFunctionInvocation(event) {
525
+ return event && INVOCATIONS.get(event);
505
526
  }
506
527
  function resolveFunctionId(request, url) {
507
528
  const reference = request.headers.get(FUNCTION_HEADER);
@@ -531,15 +552,49 @@ async function parseArguments(request, url, instance, codec) {
531
552
  }
532
553
  return parsed;
533
554
  }
534
- async function foldFlightData(hook, event, headers, outcome) {
555
+ async function foldFlightData(hook, event, headers, outcome, context = {}) {
556
+ if (outcome.value instanceof Response && outcome.value.body) return outcome.value;
557
+ digestOutcome(event, outcome);
535
558
  const data = await hook(event, outcome);
536
559
  if (data === undefined) return outcome.value;
537
560
  headers.set(SINGLE_FLIGHT_HEADER, "true");
561
+ if (context.transformFlightResult) {
562
+ const transformed = await context.transformFlightResult(event, {
563
+ value: outcome.value,
564
+ data
565
+ }, context);
566
+ if (transformed !== undefined) {
567
+ for (const cookie of headers.getSetCookie()) transformed.headers.append("Set-Cookie", cookie);
568
+ headers.forEach((value, key) => {
569
+ if (key !== "set-cookie" && !transformed.headers.has(key)) {
570
+ transformed.headers.set(key, value);
571
+ }
572
+ });
573
+ return transformed;
574
+ }
575
+ }
538
576
  return {
539
577
  value: outcome.value,
540
578
  data
541
579
  };
542
580
  }
581
+ function digestOutcome(event, outcome) {
582
+ const {
583
+ request,
584
+ response
585
+ } = outcome;
586
+ outcome.revalidateKeys = response?.headers.get(REVALIDATE_HEADER)?.split(",");
587
+ outcome.foldedHeaders = foldSetCookies(request.headers, [...(event.response?.headers?.getSetCookie() ?? []), ...(response?.headers?.getSetCookie() ?? [])]);
588
+ try {
589
+ const referrer = request.headers.get("referer");
590
+ if (referrer) {
591
+ const location = response?.headers.get("Location");
592
+ const target = location ? new URL(location, request.url) : new URL(referrer);
593
+ if (target.origin === new URL(request.url).origin) outcome.targetUrl = target.toString();
594
+ }
595
+ } catch {
596
+ }
597
+ }
543
598
  function parseSetCookie(setCookie) {
544
599
  const [pair, ...attributes] = setCookie.split(";");
545
600
  const eq = pair.indexOf("=");
@@ -678,22 +733,29 @@ async function handleServerFunctionRequest(request, options = {}) {
678
733
  const provide = options.provideEvent || provideEvent;
679
734
  const flightHook = options.collectFlightData !== undefined ? options.collectFlightData : config.collectFlightData;
680
735
  const transformResult = options.transformResult !== undefined ? options.transformResult : config.transformResult;
736
+ const transformFlightResult = options.transformFlightResult !== undefined ? options.transformFlightResult : config.transformFlightResult;
681
737
  const handleNoJS = options.handleNoJS !== undefined ? options.handleNoJS : config.handleNoJS !== undefined ? config.handleNoJS : isFormPost(request) ? defaultNoJSHandler || (defaultNoJSHandler = createNoJSHandler()) : undefined;
682
738
  const collectsFlight = !!(flightHook && instance && request.headers.has(SINGLE_FLIGHT_HEADER));
683
739
  const parsed = await parseArguments(request, url, instance, codec);
740
+ const flightContext = {
741
+ id: functionId,
742
+ args: parsed,
743
+ instance,
744
+ request,
745
+ collectsFlight,
746
+ codec,
747
+ transformFlightResult
748
+ };
684
749
  const headers = new Headers();
685
750
  try {
686
751
  let result = await provide(event, async () => {
687
- event.locals.serverFunctionMeta = {
752
+ INVOCATIONS.set(event, {
688
753
  id: functionId
689
- };
754
+ });
690
755
  return serverFunction(...parsed);
691
756
  });
692
757
  if (transformResult) {
693
- result = await transformResult(event, result, {
694
- instance,
695
- request
696
- });
758
+ result = await transformResult(event, result, flightContext);
697
759
  }
698
760
  let status = 200;
699
761
  let metadata;
@@ -735,7 +797,8 @@ async function handleServerFunctionRequest(request, options = {}) {
735
797
  response: metadata,
736
798
  request,
737
799
  thrown: false
738
- });
800
+ }, flightContext);
801
+ if (result instanceof Response && result.headers.has("X-Content-Raw")) return result;
739
802
  }
740
803
  if (!instance) {
741
804
  if (handleNoJS) return handleNoJS(result, request, parsed);
@@ -747,8 +810,7 @@ async function handleServerFunctionRequest(request, options = {}) {
747
810
  if (x instanceof Response || isResponseEnvelope(x)) {
748
811
  if (transformResult) {
749
812
  x = await transformResult(event, x, {
750
- instance,
751
- request,
813
+ ...flightContext,
752
814
  thrown: true
753
815
  });
754
816
  }
@@ -786,7 +848,11 @@ async function handleServerFunctionRequest(request, options = {}) {
786
848
  response: metadata,
787
849
  request,
788
850
  thrown: true
789
- });
851
+ }, flightContext);
852
+ if (x instanceof Response && x.headers.has("X-Content-Raw")) {
853
+ x.headers.set(ERROR_HEADER, "true");
854
+ return x;
855
+ }
790
856
  }
791
857
  headers.set(ERROR_HEADER, "true");
792
858
  if (!instance) {
@@ -821,11 +887,13 @@ exports.createServerReference = createServerReference;
821
887
  exports.decodeErrorHeaderValue = decodeErrorHeaderValue;
822
888
  exports.decodeFlashCookie = decodeFlashCookie;
823
889
  exports.decodeResponse = decodeResponse;
890
+ exports.decodeResponsePayload = decodeResponsePayload;
824
891
  exports.encodeErrorHeaderValue = encodeErrorHeaderValue;
825
892
  exports.encodeFlashCookie = encodeFlashCookie;
826
893
  exports.foldSetCookies = foldSetCookies;
894
+ exports.getEventServerFunctionInvocation = getEventServerFunctionInvocation;
827
895
  exports.getServerFunction = getServerFunction;
828
- exports.getServerFunctionMeta = getServerFunctionMeta;
896
+ exports.getServerFunctionInvocation = getServerFunctionInvocation;
829
897
  exports.getServerFunctionMetadata = getServerFunctionMetadata;
830
898
  exports.handleServerFunctionRequest = handleServerFunctionRequest;
831
899
  exports.hasFlashCookie = hasFlashCookie;