@solidjs/web 2.0.0-beta.3 → 2.0.0-beta.30

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 (73) hide show
  1. package/README.md +27 -4
  2. package/dist/dev.cjs +1211 -205
  3. package/dist/dev.js +1175 -199
  4. package/dist/server.cjs +1342 -234
  5. package/dist/server.js +1304 -231
  6. package/dist/web.cjs +1195 -196
  7. package/dist/web.js +1159 -190
  8. package/frames/dist/client.cjs +1746 -0
  9. package/frames/dist/client.dev.cjs +1759 -0
  10. package/frames/dist/client.dev.js +1747 -0
  11. package/frames/dist/client.js +1734 -0
  12. package/frames/dist/server.cjs +2426 -0
  13. package/frames/dist/server.js +2414 -0
  14. package/frames/package.json +30 -0
  15. package/package.json +287 -38
  16. package/serialization/dist/serialization.cjs +169 -0
  17. package/serialization/dist/serialization.js +159 -0
  18. package/serialization/package.json +20 -0
  19. package/serialization/types/index.d.ts +157 -0
  20. package/serialization/types-cjs/index.d.cts +157 -0
  21. package/serialization/types-cjs/package.json +3 -0
  22. package/server-functions/dist/client.cjs +613 -0
  23. package/server-functions/dist/client.js +585 -0
  24. package/server-functions/dist/server.cjs +904 -0
  25. package/server-functions/dist/server.js +875 -0
  26. package/server-functions/package.json +30 -0
  27. package/storage/package.json +8 -3
  28. package/storage/types/index.d.ts +26 -0
  29. package/storage/types-cjs/index.d.cts +28 -0
  30. package/storage/types-cjs/package.json +3 -0
  31. package/types/client.d.ts +125 -21
  32. package/types/core.d.ts +4 -3
  33. package/types/frames/client.d.ts +20 -0
  34. package/types/frames/frame-client.d.ts +270 -0
  35. package/types/frames/frame-sink.d.ts +168 -0
  36. package/types/frames/frame-transport.d.ts +196 -0
  37. package/types/frames/serializer.d.ts +157 -0
  38. package/types/frames/server.d.ts +30 -0
  39. package/types/index.d.ts +211 -26
  40. package/types/jsx-properties.d.ts +93 -0
  41. package/types/jsx.d.ts +4150 -1
  42. package/types/response.d.ts +129 -0
  43. package/types/serializer.d.ts +157 -0
  44. package/types/server-functions/client.d.ts +200 -0
  45. package/types/server-functions/flash.d.ts +38 -0
  46. package/types/server-functions/server.d.ts +490 -0
  47. package/types/server-functions/shared.d.ts +445 -0
  48. package/types/server-mock.d.ts +93 -0
  49. package/types/server.d.ts +221 -28
  50. package/types-cjs/client.d.cts +192 -0
  51. package/types-cjs/core.d.cts +4 -0
  52. package/types-cjs/frames/client.d.cts +20 -0
  53. package/types-cjs/frames/frame-client.d.cts +270 -0
  54. package/types-cjs/frames/frame-sink.d.cts +168 -0
  55. package/types-cjs/frames/frame-transport.d.cts +196 -0
  56. package/types-cjs/frames/serializer.d.cts +157 -0
  57. package/types-cjs/frames/server.d.cts +30 -0
  58. package/types-cjs/index.d.cts +231 -0
  59. package/types-cjs/jsx-properties.d.cts +93 -0
  60. package/types-cjs/jsx.d.cts +4150 -0
  61. package/types-cjs/package.json +3 -0
  62. package/types-cjs/response.d.cts +129 -0
  63. package/types-cjs/serializer.d.cts +157 -0
  64. package/types-cjs/server-functions/client.d.cts +200 -0
  65. package/types-cjs/server-functions/flash.d.cts +38 -0
  66. package/types-cjs/server-functions/server.d.cts +490 -0
  67. package/types-cjs/server-functions/shared.d.cts +445 -0
  68. package/types-cjs/server-mock.d.cts +165 -0
  69. package/types-cjs/server.d.cts +349 -0
  70. package/storage/types/src/client.d.ts +0 -1
  71. package/storage/types/src/index.d.ts +0 -46
  72. package/storage/types/src/server-mock.d.ts +0 -72
  73. package/storage/types/storage/src/index.d.ts +0 -2
@@ -0,0 +1,613 @@
1
+ 'use strict';
2
+
3
+ var seroval = require('seroval');
4
+ var web = require('seroval-plugins/web');
5
+
6
+ const REVALIDATE_HEADER = "X-Revalidate";
7
+
8
+ seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
9
+ const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
10
+ web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
11
+ web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin]);
12
+ function resolveSerializerPlugins(customPlugins) {
13
+ return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
14
+ }
15
+ const JSON_CODEC_DISABLED_FEATURES = seroval.Feature.RegExp;
16
+ const JSON_CODEC_DEPTH_LIMIT = 64;
17
+ function resolveCodecOptions({
18
+ plugins,
19
+ disabledFeatures,
20
+ depthLimit
21
+ } = {}) {
22
+ return {
23
+ plugins: resolveSerializerPlugins(plugins),
24
+ disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
25
+ depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
26
+ };
27
+ }
28
+ function createJSONDeserializer(options) {
29
+ const refs = new Map();
30
+ const resolved = resolveCodecOptions(options);
31
+ return function deserializeJSONChunk(node) {
32
+ return seroval.fromCrossJSON(node, {
33
+ refs,
34
+ ...resolved
35
+ });
36
+ };
37
+ }
38
+
39
+ const codecConfig = {
40
+ codec: undefined
41
+ };
42
+ function configureServerFunctionsCodec(codec) {
43
+ codecConfig.codec = codec;
44
+ }
45
+ function getServerFunctionsCodec() {
46
+ return codecConfig.codec;
47
+ }
48
+ const flightConfig = {
49
+ consumer: undefined
50
+ };
51
+ function subscribeFlightData(consumer) {
52
+ flightConfig.consumer = consumer;
53
+ return () => {
54
+ if (flightConfig.consumer === consumer) flightConfig.consumer = undefined;
55
+ };
56
+ }
57
+ function getFlightDataConsumer() {
58
+ return flightConfig.consumer;
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
+ }
104
+ const SERVER_FUNCTION_METADATA = Symbol.for("solid.ServerFunctionMetadata");
105
+ function getServerFunctionMetadata(fn) {
106
+ if (typeof fn !== "function") return undefined;
107
+ return fn[SERVER_FUNCTION_METADATA] || undefined;
108
+ }
109
+ function isServerFunction(fn) {
110
+ return typeof fn === "function" && !!fn[SERVER_FUNCTION_METADATA];
111
+ }
112
+ function withMeta(fn, meta) {
113
+ const metadata = getServerFunctionMetadata(fn);
114
+ if (!metadata) {
115
+ throw new Error("withMeta expects a server function reference");
116
+ }
117
+ Object.assign(metadata, meta);
118
+ return fn;
119
+ }
120
+ const FUNCTION_HEADER = "X-Server-Function-Id";
121
+ const ERROR_HEADER = "X-Server-Function-Error";
122
+ const ERROR_HEADER_MARKER = "=?1?";
123
+ const NEEDS_ENCODING = /[^\x20-\x7e\xa0-\xff]/;
124
+ function encodeErrorHeaderValue(value) {
125
+ let stripped = String(value).replace(/[\r\n]+/g, "");
126
+ if (!NEEDS_ENCODING.test(stripped) && !stripped.startsWith(ERROR_HEADER_MARKER) && stripped === stripped.trim()) {
127
+ return stripped;
128
+ }
129
+ if (typeof stripped.toWellFormed === "function") {
130
+ stripped = stripped.toWellFormed();
131
+ } else {
132
+ stripped = stripped.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "\uFFFD");
133
+ }
134
+ return ERROR_HEADER_MARKER + encodeURIComponent(stripped);
135
+ }
136
+ function decodeErrorHeaderValue(value) {
137
+ if (typeof value !== "string" || !value.startsWith(ERROR_HEADER_MARKER)) {
138
+ return value;
139
+ }
140
+ try {
141
+ return decodeURIComponent(value.slice(ERROR_HEADER_MARKER.length));
142
+ } catch {
143
+ return value;
144
+ }
145
+ }
146
+ const INSTANCE_HEADER = "X-Server-Function-Instance";
147
+ const BODY_FORMAT_HEADER = "X-Server-Function-Format";
148
+ const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
149
+ const FILE_FORM_KEY = "__server_function_file__";
150
+ const FLASH_COOKIE = "flash";
151
+ const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
152
+ function hasFlashCookie(cookieHeader) {
153
+ return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
154
+ }
155
+ function clearFlashCookie() {
156
+ return `${FLASH_COOKIE}=; Max-Age=0; Path=/`;
157
+ }
158
+ const BodyFormat = {
159
+ Serialized: "0",
160
+ String: "1",
161
+ FormData: "2",
162
+ URLSearchParams: "3",
163
+ Blob: "4",
164
+ File: "5",
165
+ ArrayBuffer: "6",
166
+ Uint8Array: "7",
167
+ Json: "8"
168
+ };
169
+ function getHeadersAndBody(body) {
170
+ switch (true) {
171
+ case typeof body === "string":
172
+ return {
173
+ headers: {
174
+ "Content-Type": "text/plain",
175
+ [BODY_FORMAT_HEADER]: BodyFormat.String
176
+ },
177
+ body
178
+ };
179
+ case body instanceof FormData:
180
+ return {
181
+ headers: {
182
+ [BODY_FORMAT_HEADER]: BodyFormat.FormData
183
+ },
184
+ body
185
+ };
186
+ case body instanceof URLSearchParams:
187
+ return {
188
+ headers: {
189
+ "Content-Type": "application/x-www-form-urlencoded",
190
+ [BODY_FORMAT_HEADER]: BodyFormat.URLSearchParams
191
+ },
192
+ body
193
+ };
194
+ case typeof File !== "undefined" && body instanceof File:
195
+ {
196
+ const formData = new FormData();
197
+ formData.append(FILE_FORM_KEY, body, body.name);
198
+ return {
199
+ headers: {
200
+ [BODY_FORMAT_HEADER]: BodyFormat.File
201
+ },
202
+ body: formData
203
+ };
204
+ }
205
+ case body instanceof Blob:
206
+ return {
207
+ headers: {
208
+ [BODY_FORMAT_HEADER]: BodyFormat.Blob
209
+ },
210
+ body
211
+ };
212
+ case body instanceof ArrayBuffer:
213
+ return {
214
+ headers: {
215
+ [BODY_FORMAT_HEADER]: BodyFormat.ArrayBuffer
216
+ },
217
+ body
218
+ };
219
+ case body instanceof Uint8Array:
220
+ return {
221
+ headers: {
222
+ [BODY_FORMAT_HEADER]: BodyFormat.Uint8Array
223
+ },
224
+ body: new Uint8Array(body)
225
+ };
226
+ default:
227
+ return undefined;
228
+ }
229
+ }
230
+ async function extractBody(source, codecOptions) {
231
+ const contentType = source.headers.get("content-type");
232
+ const format = source.headers.get(BODY_FORMAT_HEADER);
233
+ const clone = source.clone();
234
+ switch (true) {
235
+ case format === BodyFormat.Serialized:
236
+ return await deserializeStream(clone, codecOptions);
237
+ case format === BodyFormat.Json:
238
+ return JSON.parse(await clone.text());
239
+ case format === BodyFormat.String:
240
+ return await clone.text();
241
+ case format === BodyFormat.File:
242
+ {
243
+ const formData = await clone.formData();
244
+ return formData.get(FILE_FORM_KEY);
245
+ }
246
+ case format === BodyFormat.FormData:
247
+ case contentType && contentType.startsWith("multipart/form-data"):
248
+ return await clone.formData();
249
+ case format === BodyFormat.URLSearchParams:
250
+ case contentType && contentType.startsWith("application/x-www-form-urlencoded"):
251
+ return new URLSearchParams(await clone.text());
252
+ case format === BodyFormat.Blob:
253
+ return await clone.blob();
254
+ case format === BodyFormat.ArrayBuffer:
255
+ return await clone.arrayBuffer();
256
+ case format === BodyFormat.Uint8Array:
257
+ return new Uint8Array(await clone.arrayBuffer());
258
+ }
259
+ return undefined;
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
+ }
272
+ class ChunkReader {
273
+ constructor(stream) {
274
+ this.reader = stream.getReader();
275
+ this.buffer = new Uint8Array(0);
276
+ this.done = false;
277
+ }
278
+ async readChunk() {
279
+ const chunk = await this.reader.read();
280
+ if (!chunk.done) {
281
+ const newBuffer = new Uint8Array(this.buffer.length + chunk.value.length);
282
+ newBuffer.set(this.buffer);
283
+ newBuffer.set(chunk.value, this.buffer.length);
284
+ this.buffer = newBuffer;
285
+ } else {
286
+ this.done = true;
287
+ }
288
+ }
289
+ async next() {
290
+ while (this.buffer.length < 12) {
291
+ if (this.done) {
292
+ if (this.buffer.length === 0) return {
293
+ done: true,
294
+ value: undefined
295
+ };
296
+ throw new Error("Malformed server function stream.");
297
+ }
298
+ await this.readChunk();
299
+ }
300
+ const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
301
+ const bytes = Number.parseInt(head, 16);
302
+ if (Number.isNaN(bytes)) {
303
+ throw new Error("Malformed server function stream.");
304
+ }
305
+ while (bytes > this.buffer.length - 12) {
306
+ if (this.done) {
307
+ throw new Error("Malformed server function stream.");
308
+ }
309
+ await this.readChunk();
310
+ }
311
+ const partial = new TextDecoder().decode(this.buffer.subarray(12, 12 + bytes));
312
+ this.buffer = this.buffer.subarray(12 + bytes);
313
+ return {
314
+ done: false,
315
+ value: partial
316
+ };
317
+ }
318
+ async drain(interpret) {
319
+ while (true) {
320
+ const result = await this.next();
321
+ if (result.done) {
322
+ break;
323
+ }
324
+ interpret(result.value);
325
+ }
326
+ }
327
+ }
328
+ async function deserializeStream(source, codecOptions) {
329
+ if (!source.body) {
330
+ throw new Error("missing body");
331
+ }
332
+ const reader = new ChunkReader(source.body);
333
+ const result = await reader.next();
334
+ if (!result.done) {
335
+ const deserializeChunk = createJSONDeserializer(codecOptions);
336
+ function interpretChunk(chunk) {
337
+ return deserializeChunk(JSON.parse(chunk));
338
+ }
339
+ void reader.drain(interpretChunk);
340
+ return interpretChunk(result.value);
341
+ }
342
+ return undefined;
343
+ }
344
+ async function decodeResponse(response, codecOptions) {
345
+ if (!response.body) return undefined;
346
+ return await extractBody(response, codecOptions === undefined ? codecConfig.codec : codecOptions);
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
+ }
360
+
361
+ const config = {
362
+ endpoint: "/_server",
363
+ prepareRequest: undefined,
364
+ responseHandler: undefined,
365
+ serializeArgs: undefined
366
+ };
367
+ function isJSONSafe(value) {
368
+ if (value === null) return true;
369
+ const t = typeof value;
370
+ if (t === "string" || t === "boolean") return true;
371
+ if (t === "number") return Number.isFinite(value);
372
+ if (t !== "object") return false;
373
+ if (Array.isArray(value)) {
374
+ for (const v of value) if (!isJSONSafe(v)) return false;
375
+ return true;
376
+ }
377
+ const proto = Object.getPrototypeOf(value);
378
+ if (proto !== Object.prototype && proto !== null) return false;
379
+ for (const k in value) if (!isJSONSafe(value[k])) return false;
380
+ return true;
381
+ }
382
+ function serializeArguments(args) {
383
+ 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.");
385
+ }
386
+ return config.serializeArgs(args);
387
+ }
388
+ function configureServerFunctionsClient({
389
+ endpoint,
390
+ codec,
391
+ prepareRequest,
392
+ responseHandler,
393
+ serializeArgs
394
+ } = {}) {
395
+ if (endpoint !== undefined) config.endpoint = endpoint;
396
+ if (codec !== undefined) configureServerFunctionsCodec(codec);
397
+ if (prepareRequest !== undefined) config.prepareRequest = prepareRequest;
398
+ if (responseHandler !== undefined) config.responseHandler = responseHandler;
399
+ if (serializeArgs !== undefined) config.serializeArgs = serializeArgs;
400
+ }
401
+ let INSTANCE = 0;
402
+ async function createRequest(base, id, instance, options, meta) {
403
+ const headers = {
404
+ ...options.headers,
405
+ [FUNCTION_HEADER]: id,
406
+ [INSTANCE_HEADER]: instance
407
+ };
408
+ if (getFlightDataConsumer() && (!options.method || options.method.toUpperCase() !== "GET")) {
409
+ headers[SINGLE_FLIGHT_HEADER] = "true";
410
+ }
411
+ let init = {
412
+ method: "POST",
413
+ ...options,
414
+ headers
415
+ };
416
+ if (config.prepareRequest) {
417
+ init = (await config.prepareRequest(init, {
418
+ id,
419
+ meta
420
+ })) || init;
421
+ }
422
+ return fetch(base, init);
423
+ }
424
+ async function initializeResponse(base, id, instance, options, args, meta) {
425
+ if (args.length === 0) {
426
+ return createRequest(base, id, instance, options, meta);
427
+ }
428
+ if (args.length === 1) {
429
+ const result = getHeadersAndBody(args[0]);
430
+ if (result) {
431
+ return createRequest(base, id, instance, {
432
+ ...options,
433
+ body: result.body,
434
+ headers: {
435
+ ...options.headers,
436
+ ...result.headers
437
+ }
438
+ }, meta);
439
+ }
440
+ }
441
+ if (isJSONSafe(args)) {
442
+ return createRequest(base, id, instance, {
443
+ ...options,
444
+ body: JSON.stringify(args),
445
+ headers: {
446
+ ...options.headers,
447
+ "Content-Type": "application/json",
448
+ [BODY_FORMAT_HEADER]: BodyFormat.Json
449
+ }
450
+ }, meta);
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
+ }
467
+ return createRequest(base, id, instance, {
468
+ ...options,
469
+ body: await serializeArguments(args),
470
+ headers: {
471
+ ...options.headers,
472
+ "Content-Type": "text/plain",
473
+ [BODY_FORMAT_HEADER]: BodyFormat.Serialized
474
+ }
475
+ }, meta);
476
+ }
477
+ async function fetchServerFunction(base, id, options, args, meta, callArgs = args) {
478
+ const instance = `server-function:${INSTANCE++}`;
479
+ const handler = config.responseHandler;
480
+ const context = handler && handler.capture ? handler.capture({
481
+ id,
482
+ meta
483
+ }) : undefined;
484
+ const response = await initializeResponse(base, id, instance, options, args, meta);
485
+ if (handler) {
486
+ const handled = handler.handle(response, {
487
+ id,
488
+ meta,
489
+ args: callArgs,
490
+ context
491
+ });
492
+ if (handled !== undefined) return handled;
493
+ }
494
+ if (response.headers.has(SINGLE_FLIGHT_HEADER)) {
495
+ const consumer = getFlightDataConsumer();
496
+ if (consumer) {
497
+ const payload = await decodeResponse(response);
498
+ await consumer(payload.data, {
499
+ response
500
+ });
501
+ if (response.headers.has(ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has(REVALIDATE_HEADER)) {
502
+ throw payload.value;
503
+ }
504
+ return payload.value;
505
+ }
506
+ }
507
+ if (response.headers.has("Location") || response.headers.has(REVALIDATE_HEADER) || response.headers.has(SINGLE_FLIGHT_HEADER)) {
508
+ return response;
509
+ }
510
+ const result = await decodeResponse(response.clone());
511
+ if (response.headers.has(ERROR_HEADER)) {
512
+ throw result;
513
+ }
514
+ return result;
515
+ }
516
+ function createServerReference(id, name, base) {
517
+ const metadata = name === undefined ? {} : {
518
+ name
519
+ };
520
+ const fn = (...args) => {
521
+ const handler = config.responseHandler;
522
+ if (handler && handler.intercept) {
523
+ const hit = handler.intercept({
524
+ id,
525
+ meta: metadata,
526
+ args
527
+ });
528
+ if (hit !== undefined) return hit;
529
+ }
530
+ return fetchServerFunction(base || config.endpoint, id, {}, args, metadata);
531
+ };
532
+ fn[SERVER_FUNCTION_METADATA] = metadata;
533
+ return new Proxy(fn, {
534
+ get(target, prop) {
535
+ if (prop === "id") return id;
536
+ if (prop === "url") {
537
+ return base || `${config.endpoint}?id=${encodeURIComponent(id)}`;
538
+ }
539
+ return target[prop];
540
+ }
541
+ });
542
+ }
543
+ function GET(fn) {
544
+ if (!isServerFunction(fn)) {
545
+ throw new Error("GET expects a server function reference");
546
+ }
547
+ const id = fn.id;
548
+ const metadata = {
549
+ ...getServerFunctionMetadata(fn)
550
+ };
551
+ const wrapped = async (...args) => {
552
+ const handler = config.responseHandler;
553
+ if (handler && handler.intercept) {
554
+ const hit = handler.intercept({
555
+ id,
556
+ meta: metadata,
557
+ args
558
+ });
559
+ if (hit !== undefined) return hit;
560
+ }
561
+ let base = `${config.endpoint}?id=${encodeURIComponent(id)}`;
562
+ if (args.length) {
563
+ const encoded = isJSONSafe(args) ? JSON.stringify(args) : await serializeArguments(args);
564
+ base += `&args=${encodeURIComponent(encoded)}`;
565
+ }
566
+ return fetchServerFunction(base, id, {
567
+ method: "GET"
568
+ }, [], metadata, args);
569
+ };
570
+ wrapped[SERVER_FUNCTION_METADATA] = metadata;
571
+ wrapped.id = id;
572
+ Object.defineProperty(wrapped, "url", {
573
+ get: () => `${config.endpoint}?id=${encodeURIComponent(id)}`,
574
+ configurable: true
575
+ });
576
+ return withMeta(wrapped, {
577
+ method: "GET"
578
+ });
579
+ }
580
+ function registerServerReference() {
581
+ throw new Error("registerServerReference must not be called in the client build");
582
+ }
583
+ function getServerFunctionInvocation() {
584
+ return undefined;
585
+ }
586
+
587
+ exports.ChunkReader = ChunkReader;
588
+ exports.ERROR_HEADER = ERROR_HEADER;
589
+ exports.FLASH_COOKIE = FLASH_COOKIE;
590
+ exports.FUNCTION_HEADER = FUNCTION_HEADER;
591
+ exports.GET = GET;
592
+ exports.INSTANCE_HEADER = INSTANCE_HEADER;
593
+ exports.REVALIDATE_HEADER = REVALIDATE_HEADER;
594
+ exports.SINGLE_FLIGHT_HEADER = SINGLE_FLIGHT_HEADER;
595
+ exports.clearFlashCookie = clearFlashCookie;
596
+ exports.configureServerFunctionsClient = configureServerFunctionsClient;
597
+ exports.createChunk = createChunk;
598
+ exports.createServerReference = createServerReference;
599
+ exports.decodeErrorHeaderValue = decodeErrorHeaderValue;
600
+ exports.decodeResponse = decodeResponse;
601
+ exports.decodeResponsePayload = decodeResponsePayload;
602
+ exports.deserializeStream = deserializeStream;
603
+ exports.encodeErrorHeaderValue = encodeErrorHeaderValue;
604
+ exports.frameAddress = frameAddress;
605
+ exports.getFlightDataConsumer = getFlightDataConsumer;
606
+ exports.getServerFunctionInvocation = getServerFunctionInvocation;
607
+ exports.getServerFunctionMetadata = getServerFunctionMetadata;
608
+ exports.getServerFunctionsCodec = getServerFunctionsCodec;
609
+ exports.hasFlashCookie = hasFlashCookie;
610
+ exports.isServerFunction = isServerFunction;
611
+ exports.registerServerReference = registerServerReference;
612
+ exports.subscribeFlightData = subscribeFlightData;
613
+ exports.withMeta = withMeta;