@solidjs/web 2.0.0-beta.2 → 2.0.0-beta.21

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 (52) hide show
  1. package/README.md +27 -4
  2. package/dist/dev.cjs +790 -223
  3. package/dist/dev.js +764 -217
  4. package/dist/server.cjs +742 -186
  5. package/dist/server.js +714 -183
  6. package/dist/web.cjs +779 -196
  7. package/dist/web.js +753 -190
  8. package/package.json +193 -38
  9. package/serialization/dist/serialization.cjs +83 -0
  10. package/serialization/dist/serialization.js +75 -0
  11. package/serialization/package.json +20 -0
  12. package/serialization/types/index.d.ts +139 -0
  13. package/serialization/types-cjs/index.d.cts +139 -0
  14. package/serialization/types-cjs/package.json +3 -0
  15. package/server-functions/dist/client.cjs +448 -0
  16. package/server-functions/dist/client.js +435 -0
  17. package/server-functions/dist/server.cjs +632 -0
  18. package/server-functions/dist/server.js +615 -0
  19. package/server-functions/package.json +30 -0
  20. package/storage/package.json +8 -3
  21. package/storage/types/index.d.ts +26 -0
  22. package/storage/types-cjs/index.d.cts +28 -0
  23. package/storage/types-cjs/package.json +3 -0
  24. package/types/client.d.ts +64 -21
  25. package/types/core.d.ts +3 -3
  26. package/types/index.d.ts +156 -24
  27. package/types/jsx-properties.d.ts +93 -0
  28. package/types/jsx.d.ts +4135 -1
  29. package/types/response.d.ts +93 -0
  30. package/types/serializer.d.ts +139 -0
  31. package/types/server-functions/client.d.ts +137 -0
  32. package/types/server-functions/server.d.ts +307 -0
  33. package/types/server-functions/shared.d.ts +342 -0
  34. package/types/server-mock.d.ts +89 -0
  35. package/types/server.d.ts +123 -28
  36. package/types-cjs/client.d.cts +131 -0
  37. package/types-cjs/core.d.cts +3 -0
  38. package/types-cjs/index.d.cts +178 -0
  39. package/types-cjs/jsx-properties.d.cts +93 -0
  40. package/types-cjs/jsx.d.cts +4135 -0
  41. package/types-cjs/package.json +3 -0
  42. package/types-cjs/response.d.cts +93 -0
  43. package/types-cjs/serializer.d.cts +139 -0
  44. package/types-cjs/server-functions/client.d.cts +137 -0
  45. package/types-cjs/server-functions/server.d.cts +307 -0
  46. package/types-cjs/server-functions/shared.d.cts +342 -0
  47. package/types-cjs/server-mock.d.cts +161 -0
  48. package/types-cjs/server.d.cts +251 -0
  49. package/storage/types/src/client.d.ts +0 -1
  50. package/storage/types/src/index.d.ts +0 -46
  51. package/storage/types/src/server-mock.d.ts +0 -72
  52. package/storage/types/storage/src/index.d.ts +0 -2
@@ -0,0 +1,139 @@
1
+ import { Plugin, Serializer, SerovalNode } from "seroval";
2
+
3
+ /**
4
+ * Seroval's node shape — the intermediate representation `serializeJSON`
5
+ * emits and `createJSONDeserializer` consumes. Safe to `JSON.stringify`.
6
+ */
7
+ export type { SerovalNode };
8
+
9
+ /**
10
+ * A Seroval plugin usable with the web serializers — teaches the codec how
11
+ * to encode/decode a custom value type. Supply matching plugins on both
12
+ * peers of a transport.
13
+ */
14
+ export type SerializerPlugin = Plugin<any, any>;
15
+
16
+ /**
17
+ * Baseline plugin set for serializing web-platform values (AbortSignal,
18
+ * Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
19
+ * Applied by every serializer in this module; custom plugins compose ahead
20
+ * of it via `resolveSerializerPlugins`.
21
+ */
22
+ export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
23
+
24
+ /**
25
+ * Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
26
+ * first so they can shadow a default for values both would match. Returns a
27
+ * fresh array; the defaults are never mutated. Useful when handing a full
28
+ * plugin list to another serialization layer.
29
+ */
30
+ export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
31
+
32
+ /** Options for `createSerializer`. */
33
+ export interface WebSerializerOptions {
34
+ /** Name of the global object the emitted scripts write resolved values into. */
35
+ globalIdentifier: string;
36
+ /** Cross-reference scope id, for isolating multiple streams on one page. */
37
+ scopeId?: string;
38
+ /**
39
+ * Seroval feature bitflags to exclude from output. Defaults to disabling
40
+ * post-ES2017 features (AggregateError, BigInt typed arrays).
41
+ */
42
+ disabledFeatures?: number;
43
+ /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
44
+ plugins?: SerializerPlugin[];
45
+ /** Receives each emitted script chunk. */
46
+ onData: (result: string) => void;
47
+ onError?: (error: unknown) => void;
48
+ /** Fires once all async values have settled. */
49
+ onDone?: () => void;
50
+ }
51
+
52
+ /**
53
+ * Creates a streaming Seroval serializer preconfigured with the web plugin
54
+ * set and the default feature policy. Emits JavaScript chunks (through
55
+ * `onData`) that reconstruct the values under `globalIdentifier` when
56
+ * evaluated — the script-injection form of serialization renderers build
57
+ * on. For a JSON-based wire codec (no eval on the receiving side), use
58
+ * `serializeJSON` / `createJSONDeserializer` instead.
59
+ */
60
+ export function createSerializer(options: WebSerializerOptions): Serializer;
61
+
62
+ /**
63
+ * Options for `createHydrationSerializer` — `WebSerializerOptions` minus
64
+ * the knobs hydration pins (`globalIdentifier`, `disabledFeatures`).
65
+ * @internal
66
+ */
67
+ export type HydrationSerializerOptions = Omit<
68
+ WebSerializerOptions,
69
+ "globalIdentifier" | "disabledFeatures"
70
+ >;
71
+
72
+ /**
73
+ * Renderer primitive — the serializer SSR uses for hydration output. Pins
74
+ * the hydration global (`_$HY.r`) and feature policy; only the wiring
75
+ * options (callbacks, scope, extra plugins) are configurable. Not meant
76
+ * for hand-written code — custom serialization should use
77
+ * `createSerializer` or the JSON codec.
78
+ * @internal
79
+ */
80
+ export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
81
+
82
+ /**
83
+ * Renderer primitive — returns the cross-reference bootstrap script SSR
84
+ * emits ahead of hydration data for a render scope. Not meant for
85
+ * hand-written code.
86
+ * @internal
87
+ */
88
+ export function getLocalHeaderScript(id?: string): string;
89
+
90
+ // ---- JSON codec (server function transports) ----
91
+
92
+ /**
93
+ * Options shared by both halves of the JSON codec. All of them must match
94
+ * on the serializing and deserializing peer or payloads will not
95
+ * round-trip — for server functions, set them once through the
96
+ * client/server `codec` config option.
97
+ */
98
+ export interface JSONCodecOptions {
99
+ /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
100
+ plugins?: SerializerPlugin[];
101
+ /**
102
+ * Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
103
+ * (payloads may come from an untrusted peer). Must match on both peers.
104
+ */
105
+ disabledFeatures?: number;
106
+ /** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
107
+ depthLimit?: number;
108
+ }
109
+
110
+ /** Options for `serializeJSON`. */
111
+ export interface JSONSerializeOptions extends JSONCodecOptions {
112
+ /**
113
+ * Receives each serialized node; `initial` is true for the first chunk
114
+ * (the source value itself). Async values produce additional chunks as
115
+ * they resolve.
116
+ */
117
+ onParse: (node: SerovalNode, initial: boolean) => void;
118
+ onError?: (error: unknown) => void;
119
+ /** Fires once all async values have settled. */
120
+ onDone?: () => void;
121
+ }
122
+
123
+ /**
124
+ * Serializes `value` as SerovalNode chunks delivered through `onParse` —
125
+ * the encoding half of the eval-free JSON codec (RPC-style transports;
126
+ * the deserializing peer needs no script evaluation, so CSP-safe). Wire
127
+ * framing of the nodes is the transport's concern. Returns a cancel
128
+ * function that aborts pending async serialization.
129
+ */
130
+ export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
131
+
132
+ /**
133
+ * Creates the decoding counterpart of `serializeJSON`. Cross-references
134
+ * between chunks resolve through state shared across calls, so all chunks
135
+ * from one stream must go through the same deserializer instance. The first
136
+ * chunk's return value is the decoded source value; feeding later chunks
137
+ * settles the async values referenced inside it.
138
+ */
139
+ export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,448 @@
1
+ 'use strict';
2
+
3
+ var seroval = require('seroval');
4
+ var web = require('seroval-plugins/web');
5
+
6
+ seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
7
+ const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
8
+ web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
9
+ web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin]);
10
+ function resolveSerializerPlugins(customPlugins) {
11
+ return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
12
+ }
13
+ const JSON_CODEC_DISABLED_FEATURES = seroval.Feature.RegExp;
14
+ const JSON_CODEC_DEPTH_LIMIT = 64;
15
+ function resolveCodecOptions({
16
+ plugins,
17
+ disabledFeatures,
18
+ depthLimit
19
+ } = {}) {
20
+ return {
21
+ plugins: resolveSerializerPlugins(plugins),
22
+ disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
23
+ depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
24
+ };
25
+ }
26
+ function serializeJSON(value, {
27
+ onParse,
28
+ onDone,
29
+ onError,
30
+ ...codecOptions
31
+ }) {
32
+ return seroval.toCrossJSONStream(value, {
33
+ onParse,
34
+ onDone,
35
+ onError,
36
+ ...resolveCodecOptions(codecOptions)
37
+ });
38
+ }
39
+ function createJSONDeserializer(options) {
40
+ const refs = new Map();
41
+ const resolved = resolveCodecOptions(options);
42
+ return function deserializeJSONChunk(node) {
43
+ return seroval.fromCrossJSON(node, {
44
+ refs,
45
+ ...resolved
46
+ });
47
+ };
48
+ }
49
+
50
+ const codecConfig = {
51
+ codec: undefined
52
+ };
53
+ function configureServerFunctionsCodec(codec) {
54
+ codecConfig.codec = codec;
55
+ }
56
+ function getServerFunctionsCodec() {
57
+ return codecConfig.codec;
58
+ }
59
+ const flightConfig = {
60
+ consumer: undefined
61
+ };
62
+ function subscribeFlightData(consumer) {
63
+ flightConfig.consumer = consumer;
64
+ return () => {
65
+ if (flightConfig.consumer === consumer) flightConfig.consumer = undefined;
66
+ };
67
+ }
68
+ function getFlightDataConsumer() {
69
+ return flightConfig.consumer;
70
+ }
71
+ const SERVER_FUNCTION_METADATA = Symbol.for("solid.ServerFunctionMetadata");
72
+ function getServerFunctionMetadata(fn) {
73
+ if (typeof fn !== "function") return undefined;
74
+ return fn[SERVER_FUNCTION_METADATA] || undefined;
75
+ }
76
+ function isServerFunction(fn) {
77
+ return typeof fn === "function" && !!fn[SERVER_FUNCTION_METADATA];
78
+ }
79
+ function withMeta(fn, meta) {
80
+ const metadata = getServerFunctionMetadata(fn);
81
+ if (!metadata) {
82
+ throw new Error("withMeta expects a server function reference");
83
+ }
84
+ Object.assign(metadata, meta);
85
+ return fn;
86
+ }
87
+ const FUNCTION_HEADER = "X-Server-Function-Id";
88
+ const INSTANCE_HEADER = "X-Server-Function-Instance";
89
+ const BODY_FORMAT_HEADER = "X-Server-Function-Format";
90
+ const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
91
+ const FILE_FORM_KEY = "__server_function_file__";
92
+ const BodyFormat = {
93
+ Serialized: "0",
94
+ String: "1",
95
+ FormData: "2",
96
+ URLSearchParams: "3",
97
+ Blob: "4",
98
+ File: "5",
99
+ ArrayBuffer: "6",
100
+ Uint8Array: "7"
101
+ };
102
+ function getHeadersAndBody(body) {
103
+ switch (true) {
104
+ case typeof body === "string":
105
+ return {
106
+ headers: {
107
+ "Content-Type": "text/plain",
108
+ [BODY_FORMAT_HEADER]: BodyFormat.String
109
+ },
110
+ body
111
+ };
112
+ case body instanceof FormData:
113
+ return {
114
+ headers: {
115
+ [BODY_FORMAT_HEADER]: BodyFormat.FormData
116
+ },
117
+ body
118
+ };
119
+ case body instanceof URLSearchParams:
120
+ return {
121
+ headers: {
122
+ "Content-Type": "application/x-www-form-urlencoded",
123
+ [BODY_FORMAT_HEADER]: BodyFormat.URLSearchParams
124
+ },
125
+ body
126
+ };
127
+ case typeof File !== "undefined" && body instanceof File:
128
+ {
129
+ const formData = new FormData();
130
+ formData.append(FILE_FORM_KEY, body, body.name);
131
+ return {
132
+ headers: {
133
+ [BODY_FORMAT_HEADER]: BodyFormat.File
134
+ },
135
+ body: formData
136
+ };
137
+ }
138
+ case body instanceof Blob:
139
+ return {
140
+ headers: {
141
+ [BODY_FORMAT_HEADER]: BodyFormat.Blob
142
+ },
143
+ body
144
+ };
145
+ case body instanceof ArrayBuffer:
146
+ return {
147
+ headers: {
148
+ [BODY_FORMAT_HEADER]: BodyFormat.ArrayBuffer
149
+ },
150
+ body
151
+ };
152
+ case body instanceof Uint8Array:
153
+ return {
154
+ headers: {
155
+ [BODY_FORMAT_HEADER]: BodyFormat.Uint8Array
156
+ },
157
+ body: new Uint8Array(body)
158
+ };
159
+ default:
160
+ return undefined;
161
+ }
162
+ }
163
+ async function extractBody(source, codecOptions) {
164
+ const contentType = source.headers.get("content-type");
165
+ const format = source.headers.get(BODY_FORMAT_HEADER);
166
+ const clone = source.clone();
167
+ switch (true) {
168
+ case format === BodyFormat.Serialized:
169
+ return await deserializeStream(clone, codecOptions);
170
+ case format === BodyFormat.String:
171
+ return await clone.text();
172
+ case format === BodyFormat.File:
173
+ {
174
+ const formData = await clone.formData();
175
+ return formData.get(FILE_FORM_KEY);
176
+ }
177
+ case format === BodyFormat.FormData:
178
+ case contentType && contentType.startsWith("multipart/form-data"):
179
+ return await clone.formData();
180
+ case format === BodyFormat.URLSearchParams:
181
+ case contentType && contentType.startsWith("application/x-www-form-urlencoded"):
182
+ return new URLSearchParams(await clone.text());
183
+ case format === BodyFormat.Blob:
184
+ return await clone.blob();
185
+ case format === BodyFormat.ArrayBuffer:
186
+ return await clone.arrayBuffer();
187
+ case format === BodyFormat.Uint8Array:
188
+ return new Uint8Array(await clone.arrayBuffer());
189
+ }
190
+ return undefined;
191
+ }
192
+ function createChunk(data) {
193
+ const encodeData = new TextEncoder().encode(data);
194
+ const bytes = encodeData.length;
195
+ const baseHex = bytes.toString(16);
196
+ const totalHex = "00000000".substring(0, 8 - baseHex.length) + baseHex;
197
+ const head = new TextEncoder().encode(`;0x${totalHex};`);
198
+ const chunk = new Uint8Array(12 + bytes);
199
+ chunk.set(head);
200
+ chunk.set(encodeData, 12);
201
+ return chunk;
202
+ }
203
+ class ChunkReader {
204
+ constructor(stream) {
205
+ this.reader = stream.getReader();
206
+ this.buffer = new Uint8Array(0);
207
+ this.done = false;
208
+ }
209
+ async readChunk() {
210
+ const chunk = await this.reader.read();
211
+ if (!chunk.done) {
212
+ const newBuffer = new Uint8Array(this.buffer.length + chunk.value.length);
213
+ newBuffer.set(this.buffer);
214
+ newBuffer.set(chunk.value, this.buffer.length);
215
+ this.buffer = newBuffer;
216
+ } else {
217
+ this.done = true;
218
+ }
219
+ }
220
+ async next() {
221
+ if (this.buffer.length === 0) {
222
+ if (this.done) {
223
+ return {
224
+ done: true,
225
+ value: undefined
226
+ };
227
+ }
228
+ await this.readChunk();
229
+ return await this.next();
230
+ }
231
+ const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
232
+ const bytes = Number.parseInt(head, 16);
233
+ if (Number.isNaN(bytes)) {
234
+ throw new Error("Malformed server function stream.");
235
+ }
236
+ while (bytes > this.buffer.length - 12) {
237
+ if (this.done) {
238
+ throw new Error("Malformed server function stream.");
239
+ }
240
+ await this.readChunk();
241
+ }
242
+ const partial = new TextDecoder().decode(this.buffer.subarray(12, 12 + bytes));
243
+ this.buffer = this.buffer.subarray(12 + bytes);
244
+ return {
245
+ done: false,
246
+ value: partial
247
+ };
248
+ }
249
+ async drain(interpret) {
250
+ while (true) {
251
+ const result = await this.next();
252
+ if (result.done) {
253
+ break;
254
+ }
255
+ interpret(result.value);
256
+ }
257
+ }
258
+ }
259
+ function serializeStream(value, codecOptions) {
260
+ return new ReadableStream({
261
+ start(controller) {
262
+ serializeJSON(value, {
263
+ ...codecOptions,
264
+ onParse(node) {
265
+ controller.enqueue(createChunk(JSON.stringify(node)));
266
+ },
267
+ onDone() {
268
+ controller.close();
269
+ },
270
+ onError(error) {
271
+ controller.error(error);
272
+ }
273
+ });
274
+ }
275
+ });
276
+ }
277
+ async function serializeString(value, codecOptions) {
278
+ const response = new Response(serializeStream(value, codecOptions));
279
+ return await response.text();
280
+ }
281
+ async function deserializeStream(source, codecOptions) {
282
+ if (!source.body) {
283
+ throw new Error("missing body");
284
+ }
285
+ const reader = new ChunkReader(source.body);
286
+ const result = await reader.next();
287
+ if (!result.done) {
288
+ const deserializeChunk = createJSONDeserializer(codecOptions);
289
+ function interpretChunk(chunk) {
290
+ return deserializeChunk(JSON.parse(chunk));
291
+ }
292
+ void reader.drain(interpretChunk);
293
+ return interpretChunk(result.value);
294
+ }
295
+ return undefined;
296
+ }
297
+ async function decodeResponse(response, codecOptions) {
298
+ if (!response.body) return undefined;
299
+ return await extractBody(response, codecOptions === undefined ? codecConfig.codec : codecOptions);
300
+ }
301
+
302
+ const config = {
303
+ endpoint: "/_server",
304
+ prepareRequest: undefined
305
+ };
306
+ function configureServerFunctionsClient({
307
+ endpoint,
308
+ codec,
309
+ prepareRequest
310
+ } = {}) {
311
+ if (endpoint !== undefined) config.endpoint = endpoint;
312
+ if (codec !== undefined) configureServerFunctionsCodec(codec);
313
+ if (prepareRequest !== undefined) config.prepareRequest = prepareRequest;
314
+ }
315
+ let INSTANCE = 0;
316
+ async function createRequest(base, id, instance, options, meta) {
317
+ const headers = {
318
+ ...options.headers,
319
+ [FUNCTION_HEADER]: id,
320
+ [INSTANCE_HEADER]: instance
321
+ };
322
+ if (getFlightDataConsumer() && (!options.method || options.method.toUpperCase() !== "GET")) {
323
+ headers[SINGLE_FLIGHT_HEADER] = "true";
324
+ }
325
+ let init = {
326
+ method: "POST",
327
+ ...options,
328
+ headers
329
+ };
330
+ if (config.prepareRequest) {
331
+ init = (await config.prepareRequest(init, {
332
+ id,
333
+ meta
334
+ })) || init;
335
+ }
336
+ return fetch(base, init);
337
+ }
338
+ async function initializeResponse(base, id, instance, options, args, meta) {
339
+ if (args.length === 0) {
340
+ return createRequest(base, id, instance, options, meta);
341
+ }
342
+ if (args.length === 1) {
343
+ const result = getHeadersAndBody(args[0]);
344
+ if (result) {
345
+ return createRequest(base, id, instance, {
346
+ ...options,
347
+ body: result.body,
348
+ headers: {
349
+ ...options.headers,
350
+ ...result.headers
351
+ }
352
+ }, meta);
353
+ }
354
+ }
355
+ return createRequest(base, id, instance, {
356
+ ...options,
357
+ body: await serializeString(args, getServerFunctionsCodec()),
358
+ headers: {
359
+ ...options.headers,
360
+ "Content-Type": "text/plain",
361
+ [BODY_FORMAT_HEADER]: BodyFormat.Serialized
362
+ }
363
+ }, meta);
364
+ }
365
+ async function fetchServerFunction(base, id, options, args, meta) {
366
+ const instance = `server-function:${INSTANCE++}`;
367
+ const response = await initializeResponse(base, id, instance, options, args, meta);
368
+ if (response.headers.has(SINGLE_FLIGHT_HEADER)) {
369
+ const consumer = getFlightDataConsumer();
370
+ if (consumer) {
371
+ const payload = await decodeResponse(response);
372
+ await consumer(payload.data, {
373
+ response
374
+ });
375
+ if (response.headers.has("X-Server-Function-Error") && !response.headers.has("Location") && !response.headers.has("X-Revalidate")) {
376
+ throw payload.value;
377
+ }
378
+ return payload.value;
379
+ }
380
+ }
381
+ if (response.headers.has("Location") || response.headers.has("X-Revalidate") || response.headers.has(SINGLE_FLIGHT_HEADER)) {
382
+ return response;
383
+ }
384
+ const result = await decodeResponse(response.clone());
385
+ if (response.headers.has("X-Server-Function-Error")) {
386
+ throw result;
387
+ }
388
+ return result;
389
+ }
390
+ function createServerReference(id, name) {
391
+ const metadata = name === undefined ? {} : {
392
+ name
393
+ };
394
+ const fn = (...args) => fetchServerFunction(config.endpoint, id, {}, args, metadata);
395
+ fn[SERVER_FUNCTION_METADATA] = metadata;
396
+ return new Proxy(fn, {
397
+ get(target, prop) {
398
+ if (prop === "id") return id;
399
+ if (prop === "url") {
400
+ return `${config.endpoint}?id=${encodeURIComponent(id)}`;
401
+ }
402
+ return target[prop];
403
+ }
404
+ });
405
+ }
406
+ function GET(fn) {
407
+ if (!isServerFunction(fn)) {
408
+ throw new Error("GET expects a server function reference");
409
+ }
410
+ const id = fn.id;
411
+ const metadata = {
412
+ ...getServerFunctionMetadata(fn)
413
+ };
414
+ const wrapped = async (...args) => {
415
+ let base = `${config.endpoint}?id=${encodeURIComponent(id)}`;
416
+ if (args.length) {
417
+ base += `&args=${encodeURIComponent(await serializeString(args, getServerFunctionsCodec()))}`;
418
+ }
419
+ return fetchServerFunction(base, id, {
420
+ method: "GET"
421
+ }, [], metadata);
422
+ };
423
+ wrapped[SERVER_FUNCTION_METADATA] = metadata;
424
+ wrapped.id = id;
425
+ Object.defineProperty(wrapped, "url", {
426
+ get: () => `${config.endpoint}?id=${encodeURIComponent(id)}`,
427
+ configurable: true
428
+ });
429
+ return withMeta(wrapped, {
430
+ method: "GET"
431
+ });
432
+ }
433
+ function registerServerReference() {
434
+ throw new Error("registerServerReference must not be called in the client build");
435
+ }
436
+
437
+ exports.FUNCTION_HEADER = FUNCTION_HEADER;
438
+ exports.GET = GET;
439
+ exports.INSTANCE_HEADER = INSTANCE_HEADER;
440
+ exports.SINGLE_FLIGHT_HEADER = SINGLE_FLIGHT_HEADER;
441
+ exports.configureServerFunctionsClient = configureServerFunctionsClient;
442
+ exports.createServerReference = createServerReference;
443
+ exports.decodeResponse = decodeResponse;
444
+ exports.getServerFunctionMetadata = getServerFunctionMetadata;
445
+ exports.isServerFunction = isServerFunction;
446
+ exports.registerServerReference = registerServerReference;
447
+ exports.subscribeFlightData = subscribeFlightData;
448
+ exports.withMeta = withMeta;