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

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 (88) hide show
  1. package/dist/server.dev.js +638 -124
  2. package/dist/server.js +445 -94
  3. package/dist/{server.dev.cjs → server.observe.js} +602 -416
  4. package/dist/web.dev.js +229 -49
  5. package/dist/web.js +194 -46
  6. package/dist/{web.cjs → web.observe.js} +290 -275
  7. package/frames/dist/client.dev.js +103 -4
  8. package/frames/dist/client.js +5 -2
  9. package/frames/dist/{client.dev.cjs → client.observe.js} +139 -79
  10. package/frames/dist/server.dev.js +540 -79
  11. package/frames/dist/server.js +371 -52
  12. package/frames/dist/{server.cjs → server.observe.js} +544 -140
  13. package/frames/package.json +15 -21
  14. package/package.json +145 -294
  15. package/serialization/decode/package.json +3 -9
  16. package/serialization/package.json +3 -9
  17. package/serialization/types/serializer-decode.d.ts +49 -2
  18. package/server-functions/dist/{client.cjs → client.dev.js} +140 -107
  19. package/server-functions/dist/client.js +74 -69
  20. package/server-functions/dist/client.observe.js +1102 -0
  21. package/server-functions/dist/server.dev.js +430 -41
  22. package/server-functions/dist/server.js +367 -40
  23. package/server-functions/dist/{server.cjs → server.observe.js} +430 -85
  24. package/server-functions/package.json +15 -21
  25. package/server-functions/rich-args/package.json +3 -9
  26. package/storage/package.json +3 -9
  27. package/types/client.d.ts +39 -1
  28. package/types/diagnostics.d.ts +24 -0
  29. package/types/frames/frame-transport.d.ts +1 -1
  30. package/types/frames/serializer-decode.d.ts +49 -2
  31. package/types/index.d.ts +25 -15
  32. package/types/index.server.d.ts +35 -8
  33. package/types/jsx.d.ts +15 -4
  34. package/types/observe.d.ts +294 -0
  35. package/types/response.d.ts +18 -0
  36. package/types/serializer-decode.d.ts +49 -2
  37. package/types/server-functions/client.d.ts +32 -22
  38. package/types/server-functions/server.d.ts +55 -41
  39. package/types/server-functions/shared.d.ts +39 -9
  40. package/types/server-mock.d.ts +26 -4
  41. package/types/server-observe.d.ts +39 -0
  42. package/types/server.d.ts +105 -6
  43. package/types/trace.d.ts +79 -0
  44. package/dist/server.cjs +0 -3708
  45. package/dist/web.dev.cjs +0 -2285
  46. package/frames/dist/client.cjs +0 -2043
  47. package/frames/dist/server.dev.cjs +0 -4584
  48. package/serialization/dist/decode.cjs +0 -155
  49. package/serialization/dist/serialization.cjs +0 -275
  50. package/serialization/types-cjs/index.d.cts +0 -101
  51. package/serialization/types-cjs/package.json +0 -3
  52. package/serialization/types-cjs/serializer-decode.d.cts +0 -172
  53. package/serialization/types-cjs/serializer.d.cts +0 -101
  54. package/server-functions/dist/rich-args.cjs +0 -11
  55. package/server-functions/dist/server.dev.cjs +0 -2409
  56. package/storage/dist/storage.cjs +0 -12
  57. package/storage/types-cjs/index.d.cts +0 -28
  58. package/storage/types-cjs/package.json +0 -3
  59. package/types-cjs/client.d.cts +0 -197
  60. package/types-cjs/constants.d.cts +0 -20
  61. package/types-cjs/cookies.d.cts +0 -41
  62. package/types-cjs/frames/client.d.cts +0 -36
  63. package/types-cjs/frames/frame-client.d.cts +0 -370
  64. package/types-cjs/frames/frame-container-plugin.d.cts +0 -71
  65. package/types-cjs/frames/frame-sink.d.cts +0 -92
  66. package/types-cjs/frames/frame-transport.d.cts +0 -189
  67. package/types-cjs/frames/serializer-decode.d.cts +0 -172
  68. package/types-cjs/frames/serializer.d.cts +0 -101
  69. package/types-cjs/frames/server.d.cts +0 -52
  70. package/types-cjs/head.d.cts +0 -19
  71. package/types-cjs/index.d.cts +0 -191
  72. package/types-cjs/index.server.d.cts +0 -147
  73. package/types-cjs/jsx-properties.d.cts +0 -93
  74. package/types-cjs/jsx.d.cts +0 -4146
  75. package/types-cjs/package.json +0 -3
  76. package/types-cjs/reconcile.d.cts +0 -1
  77. package/types-cjs/render.d.cts +0 -6
  78. package/types-cjs/response.d.cts +0 -81
  79. package/types-cjs/serializer-decode.d.cts +0 -172
  80. package/types-cjs/serializer.d.cts +0 -101
  81. package/types-cjs/server-functions/client.d.cts +0 -184
  82. package/types-cjs/server-functions/flash.d.cts +0 -36
  83. package/types-cjs/server-functions/registry.d.cts +0 -100
  84. package/types-cjs/server-functions/rich-args.d.cts +0 -1
  85. package/types-cjs/server-functions/server.d.cts +0 -546
  86. package/types-cjs/server-functions/shared.d.cts +0 -283
  87. package/types-cjs/server-mock.d.cts +0 -337
  88. package/types-cjs/server.d.cts +0 -408
@@ -1,20 +1,14 @@
1
1
  {
2
2
  "name": "@solidjs/web/serialization",
3
- "main": "./dist/serialization.cjs",
3
+ "main": "./dist/serialization.js",
4
4
  "module": "./dist/serialization.js",
5
5
  "types": "./types/index.d.ts",
6
6
  "type": "module",
7
7
  "sideEffects": false,
8
8
  "exports": {
9
9
  ".": {
10
- "import": {
11
- "types": "./types/index.d.ts",
12
- "default": "./dist/serialization.js"
13
- },
14
- "require": {
15
- "types": "./types-cjs/index.d.cts",
16
- "default": "./dist/serialization.cjs"
17
- }
10
+ "types": "./types/index.d.ts",
11
+ "default": "./dist/serialization.js"
18
12
  }
19
13
  }
20
14
  }
@@ -145,7 +145,54 @@ export interface JSONDataTable {
145
145
  * and deserialize halves, so the set lives on the decode side and the
146
146
  * encode module composes over it.
147
147
  */
148
- export declare const DEFAULT_WEB_PLUGINS: any; /**
148
+ export declare const DEFAULT_WEB_PLUGINS: readonly ({
149
+ tag: string;
150
+ test(value: any): boolean;
151
+ parse: {
152
+ sync(): never;
153
+ async(value: any, ctx: any): Promise<{
154
+ a: number;
155
+ i: any;
156
+ }>;
157
+ stream: (value: any, ctx: any) => {
158
+ a: number;
159
+ i: any;
160
+ };
161
+ };
162
+ serialize(node: any, ctx: any): string;
163
+ deserialize(node: any, ctx: any): any;
164
+ } | import("seroval").Plugin<AbortSignal, {
165
+ reason?: import("seroval").SerovalNode;
166
+ controller?: import("seroval").SerovalNode;
167
+ factory?: import("seroval").SerovalNode;
168
+ }> | import("seroval").Plugin<CustomEvent<any>, {
169
+ type: import("seroval").SerovalNode;
170
+ options: import("seroval").SerovalNode;
171
+ }> | import("seroval").Plugin<DOMException, {
172
+ name: import("seroval").SerovalNode;
173
+ message: import("seroval").SerovalNode;
174
+ }> | import("seroval").Plugin<Event, {
175
+ type: import("seroval").SerovalNode;
176
+ options: import("seroval").SerovalNode;
177
+ }> | import("seroval").Plugin<FormData, {
178
+ factory: import("seroval").SerovalNode;
179
+ entries: import("seroval").SerovalNode;
180
+ }> | import("seroval").Plugin<Headers, {
181
+ value: import("seroval").SerovalNode;
182
+ }> | import("seroval").Plugin<ReadableStream<any>, {
183
+ factory: import("seroval").SerovalNode;
184
+ stream: import("seroval").SerovalNode;
185
+ }> | import("seroval").Plugin<Request, {
186
+ url: import("seroval").SerovalNode;
187
+ options: import("seroval").SerovalNode;
188
+ }> | import("seroval").Plugin<Response, {
189
+ body: import("seroval").SerovalNode;
190
+ options: import("seroval").SerovalNode;
191
+ }> | import("seroval").Plugin<URLSearchParams, {
192
+ value: import("seroval").SerovalNode;
193
+ }> | import("seroval").Plugin<URL, {
194
+ value: import("seroval").SerovalNode;
195
+ }>)[]; /**
149
196
  * Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
150
197
  * first so they can shadow a default for values both would match. Returns a
151
198
  * fresh array; the defaults are never mutated. Useful when handing a full
@@ -156,7 +203,7 @@ export declare const DEFAULT_WEB_PLUGINS: any; /**
156
203
  export declare function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
157
204
  export declare function resolveCodecOptions({ plugins, disabledFeatures, depthLimit, serializeErrorStacks }?: JSONCodecOptions): {
158
205
  plugins: SerializerPlugin<any, any>[];
159
- disabledFeatures: any;
206
+ disabledFeatures: number;
160
207
  depthLimit: number;
161
208
  serializeErrorStacks: boolean;
162
209
  }; /**
@@ -1,7 +1,57 @@
1
- 'use strict';
2
-
3
1
  const REVALIDATE_HEADER = "X-Revalidate";
4
2
 
3
+ const RECORDS = Symbol.for("@solidjs/signals/observe/records");
4
+ const ATTRIBUTION = Symbol.for("@solidjs/signals/observe/attribution");
5
+ function records() {
6
+ return globalThis[RECORDS];
7
+ }
8
+ function currentOrigin() {
9
+ const hooks = globalThis[ATTRIBUTION];
10
+ return hooks === undefined ? undefined : hooks.currentOrigin();
11
+ }
12
+ function isDeferredBody(value) {
13
+ if (value === null || typeof value !== "object" && typeof value !== "function") return false;
14
+ if (typeof ReadableStream !== "undefined" && value instanceof ReadableStream) return true;
15
+ const v = value;
16
+ if (typeof v[Symbol.asyncIterator] === "function") return true;
17
+ return typeof v[Symbol.iterator] === "function" && !Array.isArray(value) && !(value instanceof Map) && !(value instanceof Set) && !ArrayBuffer.isView(value);
18
+ }
19
+ function observeCall(id, method, args) {
20
+ const channel = records();
21
+ if (channel === undefined || !channel.observed("call")) return undefined;
22
+ const at = performance.now();
23
+ const origin = currentOrigin();
24
+ let response;
25
+ let settled = false;
26
+ return {
27
+ response(r) {
28
+ response = r;
29
+ },
30
+ settle(outcome, value) {
31
+ if (settled) return;
32
+ settled = true;
33
+ const event = {
34
+ id,
35
+ at,
36
+ durationMs: performance.now() - at,
37
+ method,
38
+ outcome
39
+ };
40
+ if (response !== undefined) event.status = response.status;
41
+ if (origin !== undefined) event.origin = origin;
42
+ const live = {
43
+ args
44
+ };
45
+ if (response !== undefined) live.response = response;
46
+ if (outcome === "ok") {
47
+ live.result = value;
48
+ if (isDeferredBody(value)) event.deferred = true;
49
+ } else live.error = value;
50
+ channel.emit("call", event, live);
51
+ }
52
+ };
53
+ }
54
+
5
55
  const SERVER_FUNCTION_METADATA = Symbol.for("solid.ServerFunctionMetadata");
6
56
  function getServerFunctionMetadata(fn) {
7
57
  if (typeof fn !== "function") return undefined;
@@ -166,6 +216,40 @@ function parseServerFunctionAddress(pathname, endpoint) {
166
216
  return null;
167
217
  }
168
218
  }
219
+ const MAX_GET_URL_LENGTH = 2000;
220
+ function urlTargetId(target, helper) {
221
+ if (typeof target === "string") return target;
222
+ if (isServerFunction(target) && typeof target.id === "string") return target.id;
223
+ throw new Error(`${helper} expects a server function reference (or its id).`);
224
+ }
225
+ function serverFunctionActionUrlFor(endpoint, target, boundArgs) {
226
+ const address = serverFunctionAddress(endpoint, urlTargetId(target, "serverFunctionActionUrl"));
227
+ if (!boundArgs.length) return address;
228
+ if (!isJSONSafe(boundArgs)) {
229
+ throw new Error("Bound arguments in an action url must be JSON-safe: the server reads them the way it " + "reads a form post's, and that convention has no codec. Pass the value through the " + "function's body, or call the reference instead of rendering a url for it.");
230
+ }
231
+ return `${address}?args=${encodeURIComponent(JSON.stringify(boundArgs))}`;
232
+ }
233
+ function serverFunctionUrlFor(endpoint, fn, args) {
234
+ if (!isServerFunction(fn) || typeof fn.id !== "string") {
235
+ throw new Error("serverFunctionUrl expects a server function reference.");
236
+ }
237
+ const metadata = getServerFunctionMetadata(fn);
238
+ if (!metadata || metadata.method !== "GET") {
239
+ throw new Error(`serverFunctionUrl: "${fn.id}" is not a declared read. A call over the default ` + "transport is a POST — its arguments travel in the body, so no url describes it. " + "Declare the function with GET(fn) for a cacheable read that has a url, or start " + 'the call itself: invoke(fn, { priority: "low" }, ...args).');
240
+ }
241
+ const address = serverFunctionDataAddress(endpoint, fn.id);
242
+ if (!args.length) return address;
243
+ if (!isJSONSafe(args)) {
244
+ throw new Error("Arguments in a server function url must be JSON-safe: the transport encodes anything " + "else through the codec asynchronously, and a url rendered as a value cannot wait for " + "it. Pass JSON-safe arguments, or call the reference instead of rendering a url for it.");
245
+ }
246
+ const url = `${address}?args=${encodeURIComponent(JSON.stringify(args))}`;
247
+ const length = new URL(url, globalThis.location?.href || "http://localhost").href.length;
248
+ if (length > MAX_GET_URL_LENGTH) {
249
+ throw new Error(`serverFunctionUrl: the url for "${fn.id}" with these arguments is ${length} characters; ` + `past ${MAX_GET_URL_LENGTH} the call dispatches over POST (a cache miss rather than a ` + "414), so no url describes it. Shorten the arguments, or call the reference instead.");
250
+ }
251
+ return url;
252
+ }
169
253
  const ERROR_HEADER = "X-Server-Function-Error";
170
254
  const ERROR_HEADER_MARKER = "=?1?";
171
255
  const NEEDS_ENCODING = /[^\x20-\x7e\xa0-\xff]/;
@@ -191,7 +275,6 @@ function decodeErrorHeaderValue(value) {
191
275
  return value;
192
276
  }
193
277
  }
194
- const INSTANCE_HEADER = "X-Server-Function-Instance";
195
278
  const BODY_FORMAT_HEADER = "X-Server-Function-Format";
196
279
  const UNKNOWN_HEADER = "X-Server-Function-Unknown";
197
280
  const REDIRECT_HEADER = "X-Server-Function-Redirect";
@@ -524,39 +607,13 @@ const config = {
524
607
  responseHandler: undefined,
525
608
  serializeArgs: undefined
526
609
  };
527
- const CALL_OBSERVERS = new Set();
528
- function notifyCallObservers(type, id, instance, value, meta) {
529
- if (CALL_OBSERVERS.size === 0) return;
530
- const field = type === "request" ? "request" : "response";
531
- const time = performance.now();
532
- for (const observer of new Set(CALL_OBSERVERS)) {
533
- try {
534
- observer({
535
- type,
536
- id,
537
- instance,
538
- [field]: value.clone(),
539
- meta,
540
- time
541
- });
542
- } catch (error) {
543
- console.error(error);
544
- }
545
- }
610
+ function serverFunctionUrl(fn, ...args) {
611
+ return serverFunctionUrlFor(config.endpoint, fn, args);
546
612
  }
547
- function observeServerFunctionCalls(observer) {
548
- CALL_OBSERVERS.add(observer);
549
- return () => CALL_OBSERVERS.delete(observer);
613
+ function serverFunctionActionUrl(fn, ...boundArgs) {
614
+ return serverFunctionActionUrlFor(config.endpoint, fn, boundArgs);
550
615
  }
551
- function serverFunctionUrl(id, boundArgs) {
552
- const address = serverFunctionAddress(config.endpoint, id);
553
- if (!boundArgs || !boundArgs.length) return address;
554
- if (!isJSONSafe(boundArgs)) {
555
- throw new Error("Bound arguments in an action url must be JSON-safe: the server reads them the way it " + "reads a form post's, and that convention has no codec. Pass the value through the " + "function's body, or call the reference instead of rendering a url for it.");
556
- }
557
- return `${address}?args=${encodeURIComponent(JSON.stringify(boundArgs))}`;
558
- }
559
- function parseServerFunctionUrl(url) {
616
+ function parseServerFunctionActionUrl(url) {
560
617
  const parsed = parseServerFunctionAddress(new URL(url, globalThis.location?.href || "http://localhost").pathname, config.endpoint);
561
618
  return parsed && parsed.id;
562
619
  }
@@ -581,8 +638,6 @@ function configureServerFunctionsClient({
581
638
  if (responseHandler !== undefined) config.responseHandler = responseHandler;
582
639
  if (serializeArgs !== undefined) config.serializeArgs = serializeArgs;
583
640
  }
584
- let INSTANCE = 0;
585
- const MAX_GET_URL_LENGTH = 2000;
586
641
  let rpcProvided = false;
587
642
  function provideRPC() {
588
643
  if (rpcProvided) return;
@@ -619,13 +674,15 @@ function parseRetryAfter(header) {
619
674
  if (!Number.isNaN(date)) return Math.max(0, Math.ceil((date - Date.now()) / 1000));
620
675
  return undefined;
621
676
  }
622
- async function createRequest(base, id, instance, options, meta) {
677
+ function isReadCall(options) {
678
+ return !!options.read || !!options.method && options.method.toUpperCase() === "GET";
679
+ }
680
+ async function createRequest(base, id, options, meta) {
623
681
  const headers = {
624
- ...options.headers,
625
- [INSTANCE_HEADER]: instance
682
+ ...options.headers
626
683
  };
627
684
  const flightSources = getFlightDataSourceIds();
628
- if (flightSources.length > 0 && !options.read && (!options.method || options.method.toUpperCase() !== "GET")) {
685
+ if (flightSources.length > 0 && !isReadCall(options)) {
629
686
  headers[SINGLE_FLIGHT_HEADER] = flightSources.join(",");
630
687
  }
631
688
  let init = {
@@ -642,31 +699,23 @@ async function createRequest(base, id, instance, options, meta) {
642
699
  if (typeof prepared !== "object") {
643
700
  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
701
  }
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, ... } })");
702
+ if (typeof prepared.method !== "string" || prepared.method.toUpperCase() !== init.method.toUpperCase()) {
703
+ throw new Error(`prepareRequest returned an init without the transport's ${init.method} method, ` + "which would send the call without its payload or protocol. Spread the init it " + "received: init => ({ ...init, headers: { ...init.headers, ... } })");
647
704
  }
648
705
  }
649
706
  init = prepared || init;
650
707
  }
651
708
  const send = config.fetch || fetch;
652
- if (CALL_OBSERVERS.size === 0) return send(base, init);
653
- const request = new Request(new URL(base, globalThis.location?.href || "http://localhost"), {
654
- ...init,
655
- body: init.body instanceof ReadableStream ? undefined : init.body
656
- });
657
- notifyCallObservers("request", id, instance, request, meta);
658
- const response = await send(base, init);
659
- notifyCallObservers("response", id, instance, response, meta);
660
- return response;
709
+ return send(base, init);
661
710
  }
662
- async function initializeResponse(base, id, instance, options, args, meta) {
711
+ async function initializeResponse(base, id, options, args, meta) {
663
712
  if (args.length === 0) {
664
- return createRequest(base, id, instance, options, meta);
713
+ return createRequest(base, id, options, meta);
665
714
  }
666
715
  if (args.length === 1) {
667
716
  const result = getHeadersAndBody(args[0]);
668
717
  if (result) {
669
- return createRequest(base, id, instance, {
718
+ return createRequest(base, id, {
670
719
  ...options,
671
720
  body: result.body,
672
721
  headers: {
@@ -678,7 +727,7 @@ async function initializeResponse(base, id, instance, options, args, meta) {
678
727
  }
679
728
  try {
680
729
  if (isJSONSafe(args)) {
681
- return createRequest(base, id, instance, {
730
+ return createRequest(base, id, {
682
731
  ...options,
683
732
  body: JSON.stringify(args),
684
733
  headers: {
@@ -696,7 +745,7 @@ async function initializeResponse(base, id, instance, options, args, meta) {
696
745
  const leading = args.slice(0, -1).map(arg => arg === undefined ? null : arg);
697
746
  if (trailing && isJSONSafe(leading)) {
698
747
  const target = base + (base.includes("?") ? "&" : "?") + "args=" + encodeURIComponent(JSON.stringify(leading));
699
- return createRequest(target, id, instance, {
748
+ return createRequest(target, id, {
700
749
  ...options,
701
750
  body: trailing.body,
702
751
  headers: {
@@ -708,7 +757,7 @@ async function initializeResponse(base, id, instance, options, args, meta) {
708
757
  } catch {
709
758
  }
710
759
  }
711
- return createRequest(base, id, instance, {
760
+ return createRequest(base, id, {
712
761
  ...options,
713
762
  body: await serializeArguments(args),
714
763
  headers: {
@@ -718,8 +767,21 @@ async function initializeResponse(base, id, instance, options, args, meta) {
718
767
  }
719
768
  }, meta);
720
769
  }
721
- async function fetchServerFunction(base, id, options, args, meta, callArgs = args) {
722
- const instance = `server-function:${INSTANCE++}`;
770
+ async function observedFetch(base, id, options, args, meta, callArgs = args) {
771
+ const observation = observeCall(id, options.method && options.method.toUpperCase() === "GET" ? "GET" : "POST", callArgs);
772
+ if (!observation) return dispatchServerFunction(base, id, options, args, meta, callArgs);
773
+ let result;
774
+ try {
775
+ result = await dispatchServerFunction(base, id, options, args, meta, callArgs, observation);
776
+ } catch (error) {
777
+ observation.settle("error", error);
778
+ throw error;
779
+ }
780
+ observation.settle("ok", result);
781
+ return result;
782
+ }
783
+ const fetchServerFunction = observedFetch ;
784
+ async function dispatchServerFunction(base, id, options, args, meta, callArgs = args, observation) {
723
785
  const handler = config.responseHandler;
724
786
  const context = handler && handler.capture ? handler.capture({
725
787
  id,
@@ -730,7 +792,8 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
730
792
  ...options,
731
793
  signal: controller.signal
732
794
  };
733
- const response = await initializeResponse(base, id, instance, options, args, meta);
795
+ const response = await initializeResponse(base, id, options, args, meta);
796
+ if (observation) observation.response(response);
734
797
  if (handler) {
735
798
  const handled = handler.handle(response, {
736
799
  id,
@@ -744,20 +807,26 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
744
807
  throw serverFunctionFailure(response, undefined);
745
808
  }
746
809
  const failed = response.headers.has(ERROR_HEADER);
747
- if (response.headers.has(SINGLE_FLIGHT_HEADER)) {
748
- const folded = response.headers.get(SINGLE_FLIGHT_HEADER).split(",");
749
- const consumers = folded.map(source => [source, getFlightDataConsumer(source)]).filter(([, consumer]) => consumer);
750
- if (consumers.length > 0) {
751
- const payload = response.body ? await extractBody(response, getServerFunctionsCodec()) : undefined;
752
- for (const [source, consumer] of consumers) {
753
- await consumer(payload.data[source], {
810
+ const registered = isReadCall(options) ? [] : getFlightDataSourceIds();
811
+ if (registered.length > 0) {
812
+ const folded = response.headers.has(SINGLE_FLIGHT_HEADER) ? response.headers.get(SINGLE_FLIGHT_HEADER).split(",") : [];
813
+ const metadata = response.headers.has(REDIRECT_HEADER) || response.headers.has(REVALIDATE_HEADER);
814
+ if (metadata || folded.length > 0) {
815
+ const decoded = response.body ? await extractBody(response, getServerFunctionsCodec()) : undefined;
816
+ const enveloped = folded.length > 0 && decoded !== undefined;
817
+ const value = enveloped ? decoded.value : decoded;
818
+ const data = enveloped ? decoded.data : undefined;
819
+ for (const source of registered) {
820
+ if (!metadata && !folded.includes(source)) continue;
821
+ const consumer = getFlightDataConsumer(source);
822
+ if (consumer) await consumer(data ? data[source] : undefined, {
754
823
  response
755
824
  });
756
825
  }
757
- if (failed && !response.headers.has(REDIRECT_HEADER) && !response.headers.has(REVALIDATE_HEADER)) {
758
- throw serverFunctionFailure(response, payload.value);
826
+ if (failed && !metadata) {
827
+ throw serverFunctionFailure(response, value);
759
828
  }
760
- return payload.value;
829
+ return value;
761
830
  }
762
831
  }
763
832
  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) {
@@ -1030,40 +1099,4 @@ function getServerFunctionInvocation() {
1030
1099
  return undefined;
1031
1100
  }
1032
1101
 
1033
- exports.ChunkReader = ChunkReader;
1034
- exports.ERROR_HEADER = ERROR_HEADER;
1035
- exports.FLASH_COOKIE = FLASH_COOKIE;
1036
- exports.GET = GET;
1037
- exports.INSTANCE_HEADER = INSTANCE_HEADER;
1038
- exports.REDIRECT_HEADER = REDIRECT_HEADER;
1039
- exports.REVALIDATE_HEADER = REVALIDATE_HEADER;
1040
- exports.SERVER_FUNCTION_INVOKE = SERVER_FUNCTION_INVOKE;
1041
- exports.SINGLE_FLIGHT_HEADER = SINGLE_FLIGHT_HEADER;
1042
- exports.UNKNOWN_HEADER = UNKNOWN_HEADER;
1043
- exports.clearFlashCookie = clearFlashCookie;
1044
- exports.configureServerFunctionsClient = configureServerFunctionsClient;
1045
- exports.createChunk = createChunk;
1046
- exports.createServerReference = createServerReference;
1047
- exports.decodeErrorHeaderValue = decodeErrorHeaderValue;
1048
- exports.decodeRedirectHeaderValue = decodeRedirectHeaderValue;
1049
- exports.decodeResponse = decodeResponse;
1050
- exports.decodeResponsePayload = decodeResponsePayload;
1051
- exports.deserializeStream = deserializeStream;
1052
- exports.encodeErrorHeaderValue = encodeErrorHeaderValue;
1053
- exports.frameAddress = frameAddress;
1054
- exports.getFlightDataConsumer = getFlightDataConsumer;
1055
- exports.getFlightDataSourceIds = getFlightDataSourceIds;
1056
- exports.getServerFunctionInvocation = getServerFunctionInvocation;
1057
- exports.getServerFunctionMetadata = getServerFunctionMetadata;
1058
- exports.getServerFunctionsCodec = getServerFunctionsCodec;
1059
- exports.hasFlashCookie = hasFlashCookie;
1060
- exports.invoke = invoke;
1061
- exports.isServerFunction = isServerFunction;
1062
- exports.live = live;
1063
- exports.observeServerFunctionCalls = observeServerFunctionCalls;
1064
- exports.parseServerFunctionUrl = parseServerFunctionUrl;
1065
- exports.registerServerReference = registerServerReference;
1066
- exports.serializeString = serializeString;
1067
- exports.serverFunctionUrl = serverFunctionUrl;
1068
- exports.subscribeFlightData = subscribeFlightData;
1069
- exports.withMeta = withMeta;
1102
+ export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, GET, REDIRECT_HEADER, REVALIDATE_HEADER, SERVER_FUNCTION_INVOKE, SINGLE_FLIGHT_HEADER, UNKNOWN_HEADER, clearFlashCookie, configureServerFunctionsClient, createChunk, createServerReference, decodeErrorHeaderValue, decodeRedirectHeaderValue, decodeResponse, decodeResponsePayload, deserializeStream, encodeErrorHeaderValue, frameAddress, getFlightDataConsumer, getFlightDataSourceIds, getServerFunctionInvocation, getServerFunctionMetadata, getServerFunctionsCodec, hasFlashCookie, invoke, isServerFunction, live, parseServerFunctionActionUrl, registerServerReference, serializeString, serverFunctionActionUrl, serverFunctionUrl, subscribeFlightData, withMeta };