svelte-effect-runtime 1.2.4 → 1.3.0

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 (74) hide show
  1. package/dist/chunks/client-DkW4e4dD.js +199 -0
  2. package/dist/chunks/client-DkW4e4dD.js.map +1 -0
  3. package/dist/chunks/effect-CL8GJs8A.js +51 -0
  4. package/dist/chunks/effect-CL8GJs8A.js.map +1 -0
  5. package/dist/chunks/effect-compat-BhW0YPIs.js +103 -0
  6. package/dist/chunks/effect-compat-BhW0YPIs.js.map +1 -0
  7. package/dist/chunks/{magic-string.es-5gRBdMgP.js → magic-string.es-BnGH-5YR.js} +1 -1
  8. package/dist/chunks/{magic-string.es-5gRBdMgP.js.map → magic-string.es-BnGH-5YR.js.map} +1 -1
  9. package/dist/chunks/{markup-Ccw42uCl.js → markup-BpSHnnYD.js} +4 -4
  10. package/dist/chunks/{markup-Ccw42uCl.js.map → markup-BpSHnnYD.js.map} +1 -1
  11. package/dist/chunks/preprocess-CtLrnJcK.js +44 -0
  12. package/dist/chunks/preprocess-CtLrnJcK.js.map +1 -0
  13. package/dist/chunks/server-DR-6LMdP.js +629 -0
  14. package/dist/chunks/server-DR-6LMdP.js.map +1 -0
  15. package/dist/chunks/v3-p8V3Drpp.js +1 -0
  16. package/dist/chunks/v4-DIhYCbb_.js +1 -0
  17. package/dist/chunks/vite-DqjXRZd4.js +143 -0
  18. package/dist/chunks/vite-DqjXRZd4.js.map +1 -0
  19. package/dist/client.d.ts +1 -64
  20. package/dist/client.js +2 -170
  21. package/dist/effect.d.ts +1 -7
  22. package/dist/effect.js +1 -27
  23. package/dist/internal/effect-compat.d.ts +21 -0
  24. package/dist/internal/markup.d.ts +1 -1
  25. package/dist/internal/markup.js +1 -1
  26. package/dist/internal/remote-client.js +30 -6
  27. package/dist/internal/remote-client.js.map +1 -1
  28. package/dist/internal/transform.d.ts +1 -1
  29. package/dist/internal/transform.js +3 -4
  30. package/dist/internal/transform.js.map +1 -1
  31. package/dist/language-server.d.ts +9 -3
  32. package/dist/language-server.js +3 -3
  33. package/dist/mod.d.ts +1 -6
  34. package/dist/mod.js +3 -5
  35. package/dist/preprocess.d.ts +23 -6
  36. package/dist/preprocess.js +10 -31
  37. package/dist/preprocess.js.map +1 -1
  38. package/dist/root-node.d.ts +1 -14
  39. package/dist/root-node.js +63 -8
  40. package/dist/root-node.js.map +1 -0
  41. package/dist/server.d.ts +56 -129
  42. package/dist/server.js +44 -508
  43. package/dist/server.js.map +1 -1
  44. package/dist/v3/client.d.ts +93 -0
  45. package/dist/v3/effect.d.ts +17 -0
  46. package/dist/v3/mod.d.ts +3 -0
  47. package/dist/v3/preprocess.d.ts +28 -0
  48. package/dist/v3/root-node.d.ts +59 -0
  49. package/dist/v3/server.d.ts +167 -0
  50. package/dist/v3/vite.d.ts +46 -0
  51. package/dist/v4/client.d.ts +2 -0
  52. package/dist/v4/effect.d.ts +24 -0
  53. package/dist/v4/effect.js +19 -0
  54. package/dist/v4/effect.js.map +1 -0
  55. package/dist/v4/mod.d.ts +3 -0
  56. package/dist/v4/mod.js +3 -0
  57. package/dist/v4/preprocess.d.ts +30 -0
  58. package/dist/v4/preprocess.js +28 -0
  59. package/dist/v4/preprocess.js.map +1 -0
  60. package/dist/v4/root-node.d.ts +59 -0
  61. package/dist/v4/root-node.js +63 -0
  62. package/dist/v4/root-node.js.map +1 -0
  63. package/dist/v4/server.d.ts +118 -0
  64. package/dist/v4/server.js +22 -0
  65. package/dist/v4/server.js.map +1 -0
  66. package/dist/v4/vite.d.ts +34 -0
  67. package/dist/v4/vite.js +31 -0
  68. package/dist/v4/vite.js.map +1 -0
  69. package/dist/vite.d.ts +30 -15
  70. package/dist/vite.js +18 -101
  71. package/dist/vite.js.map +1 -1
  72. package/package.json +46 -3
  73. package/dist/client.js.map +0 -1
  74. package/dist/effect.js.map +0 -1
package/dist/server.js CHANGED
@@ -1,523 +1,59 @@
1
- import { create_form_error, create_serialized_remote_failure_envelope, is_form_error } from "./internal/remote-shared.js";
2
- import * as Context from "effect/Context";
3
- import * as Effect from "effect/Effect";
4
- import * as Layer from "effect/Layer";
5
- import * as ManagedRuntime from "effect/ManagedRuntime";
6
- import * as Cause from "effect/Cause";
7
- import * as Exit from "effect/Exit";
8
- import { error, invalid } from "@sveltejs/kit";
9
- import { command, form, getRequestEvent, prerender, query } from "$app/server";
10
- import { get_request_store } from "@sveltejs/kit/internal/server";
11
- import * as Option from "effect/Option";
12
- import * as Schema from "effect/Schema";
13
- import * as Schema_ast from "effect/SchemaAST";
14
- //#region ../../node_modules/.deno/devalue@5.6.4/node_modules/devalue/src/utils.js
15
- var DevalueError = class extends Error {
16
- /**
17
- * @param {string} message
18
- * @param {string[]} keys
19
- * @param {any} [value] - The value that failed to be serialized
20
- * @param {any} [root] - The root value being serialized
21
- */
22
- constructor(message, keys, value, root) {
23
- super(message);
24
- this.name = "DevalueError";
25
- this.path = keys.join("");
26
- this.value = value;
27
- this.root = root;
28
- }
29
- };
30
- /** @param {any} thing */
31
- function is_primitive(thing) {
32
- return Object(thing) !== thing;
33
- }
34
- const object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
35
- /** @param {any} thing */
36
- function is_plain_object(thing) {
37
- const proto = Object.getPrototypeOf(thing);
38
- return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null || Object.getOwnPropertyNames(proto).sort().join("\0") === object_proto_names;
39
- }
40
- /** @param {any} thing */
41
- function get_type(thing) {
42
- return Object.prototype.toString.call(thing).slice(8, -1);
43
- }
44
- /** @param {string} char */
45
- function get_escaped_char(char) {
46
- switch (char) {
47
- case "\"": return "\\\"";
48
- case "<": return "\\u003C";
49
- case "\\": return "\\\\";
50
- case "\n": return "\\n";
51
- case "\r": return "\\r";
52
- case " ": return "\\t";
53
- case "\b": return "\\b";
54
- case "\f": return "\\f";
55
- case "\u2028": return "\\u2028";
56
- case "\u2029": return "\\u2029";
57
- default: return char < " " ? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}` : "";
58
- }
59
- }
60
- /** @param {string} str */
61
- function stringify_string(str) {
62
- let result = "";
63
- let last_pos = 0;
64
- const len = str.length;
65
- for (let i = 0; i < len; i += 1) {
66
- const char = str[i];
67
- const replacement = get_escaped_char(char);
68
- if (replacement) {
69
- result += str.slice(last_pos, i) + replacement;
70
- last_pos = i + 1;
71
- }
72
- }
73
- return `"${last_pos === 0 ? str : result + str.slice(last_pos)}"`;
74
- }
75
- /** @param {Record<string | symbol, any>} object */
76
- function enumerable_symbols(object) {
77
- return Object.getOwnPropertySymbols(object).filter((symbol) => Object.getOwnPropertyDescriptor(object, symbol).enumerable);
78
- }
79
- const is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
80
- /** @param {string} key */
81
- function stringify_key(key) {
82
- return is_identifier.test(key) ? "." + key : "[" + JSON.stringify(key) + "]";
83
- }
84
- /** @param {string} s */
85
- function is_valid_array_index(s) {
86
- if (s.length === 0) return false;
87
- if (s.length > 1 && s.charCodeAt(0) === 48) return false;
88
- for (let i = 0; i < s.length; i++) {
89
- const c = s.charCodeAt(i);
90
- if (c < 48 || c > 57) return false;
91
- }
92
- const n = +s;
93
- if (n >= 2 ** 32 - 1) return false;
94
- if (n < 0) return false;
95
- return true;
96
- }
1
+ import { a as RequestEvent$1, c as get_server_runtime_or_throw$1, i as Query$1, n as Form$1, o as ServerRuntime$1, r as Prerender$1, s as create_effect_transport$1, t as Command$1 } from "./chunks/server-DR-6LMdP.js";
2
+ //#region server.ts
97
3
  /**
98
- * Finds the populated indices of an array.
99
- * @param {unknown[]} array
4
+ * Define a read-only remote function that returns an `Effect` on the client.
5
+ *
6
+ * @see https://ser.barekey.dev/content/remote-functions/query
100
7
  */
101
- function valid_array_indices(array) {
102
- const keys = Object.keys(array);
103
- for (var i = keys.length - 1; i >= 0; i--) if (is_valid_array_index(keys[i])) break;
104
- keys.length = i + 1;
105
- return keys;
106
- }
107
- //#endregion
108
- //#region ../../node_modules/.deno/devalue@5.6.4/node_modules/devalue/src/base64.js
8
+ const Query = Query$1;
109
9
  /**
110
- * Base64 Encodes an arraybuffer
111
- * @param {ArrayBuffer} arraybuffer
112
- * @returns {string}
10
+ * Define a write-oriented remote function that returns an `Effect` on the
11
+ * client.
12
+ *
13
+ * @see https://ser.barekey.dev/content/remote-functions/command
113
14
  */
114
- function encode64(arraybuffer) {
115
- const dv = new DataView(arraybuffer);
116
- let binaryString = "";
117
- for (let i = 0; i < arraybuffer.byteLength; i++) binaryString += String.fromCharCode(dv.getUint8(i));
118
- return binaryToAscii(binaryString);
119
- }
120
- const KEY_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
15
+ const Command = Command$1;
121
16
  /**
122
- * Substitute for btoa since it's deprecated in node.
123
- * Does not do any input validation.
17
+ * Define a remote form handler that maps submitted data into an Effect
18
+ * program.
124
19
  *
125
- * @see https://github.com/jsdom/abab/blob/master/lib/btoa.js
20
+ * @see https://ser.barekey.dev/content/remote-functions/form
21
+ */
22
+ const Form = Form$1;
23
+ /**
24
+ * Define a prerenderable remote function backed by an Effect program.
126
25
  *
127
- * @param {string} str
128
- * @returns {string}
26
+ * @see https://ser.barekey.dev/content/remote-functions/prerender
129
27
  */
130
- function binaryToAscii(str) {
131
- let out = "";
132
- for (let i = 0; i < str.length; i += 3) {
133
- /** @type {[number, number, number, number]} */
134
- const groupsOfSix = [
135
- void 0,
136
- void 0,
137
- void 0,
138
- void 0
139
- ];
140
- groupsOfSix[0] = str.charCodeAt(i) >> 2;
141
- groupsOfSix[1] = (str.charCodeAt(i) & 3) << 4;
142
- if (str.length > i + 1) {
143
- groupsOfSix[1] |= str.charCodeAt(i + 1) >> 4;
144
- groupsOfSix[2] = (str.charCodeAt(i + 1) & 15) << 2;
145
- }
146
- if (str.length > i + 2) {
147
- groupsOfSix[2] |= str.charCodeAt(i + 2) >> 6;
148
- groupsOfSix[3] = str.charCodeAt(i + 2) & 63;
149
- }
150
- for (let j = 0; j < groupsOfSix.length; j++) if (typeof groupsOfSix[j] === "undefined") out += "=";
151
- else out += KEY_STRING[groupsOfSix[j]];
152
- }
153
- return out;
154
- }
155
- //#endregion
156
- //#region ../../node_modules/.deno/devalue@5.6.4/node_modules/devalue/src/stringify.js
28
+ const Prerender = Prerender$1;
157
29
  /**
158
- * Turn a value into a JSON string that can be parsed with `devalue.parse`
159
- * @param {any} value
160
- * @param {Record<string, (value: any) => any>} [reducers]
30
+ * Effect `Context.Tag` for the current SvelteKit `RequestEvent`.
31
+ *
32
+ * @see https://ser.barekey.dev/content/runtimes/server
161
33
  */
162
- function stringify(value, reducers) {
163
- /** @type {any[]} */
164
- const stringified = [];
165
- /** @type {Map<any, number>} */
166
- const indexes = /* @__PURE__ */ new Map();
167
- /** @type {Array<{ key: string, fn: (value: any) => any }>} */
168
- const custom = [];
169
- if (reducers) for (const key of Object.getOwnPropertyNames(reducers)) custom.push({
170
- key,
171
- fn: reducers[key]
172
- });
173
- /** @type {string[]} */
174
- const keys = [];
175
- let p = 0;
176
- /** @param {any} thing */
177
- function flatten(thing) {
178
- if (thing === void 0) return -1;
179
- if (Number.isNaN(thing)) return -3;
180
- if (thing === Infinity) return -4;
181
- if (thing === -Infinity) return -5;
182
- if (thing === 0 && 1 / thing < 0) return -6;
183
- if (indexes.has(thing)) return indexes.get(thing);
184
- const index = p++;
185
- indexes.set(thing, index);
186
- for (const { key, fn } of custom) {
187
- const value = fn(thing);
188
- if (value) {
189
- stringified[index] = `["${key}",${flatten(value)}]`;
190
- return index;
191
- }
192
- }
193
- if (typeof thing === "function") throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
194
- let str = "";
195
- if (is_primitive(thing)) str = stringify_primitive(thing);
196
- else {
197
- const type = get_type(thing);
198
- switch (type) {
199
- case "Number":
200
- case "String":
201
- case "Boolean":
202
- str = `["Object",${stringify_primitive(thing)}]`;
203
- break;
204
- case "BigInt":
205
- str = `["BigInt",${thing}]`;
206
- break;
207
- case "Date":
208
- str = `["Date","${!isNaN(thing.getDate()) ? thing.toISOString() : ""}"]`;
209
- break;
210
- case "URL":
211
- str = `["URL",${stringify_string(thing.toString())}]`;
212
- break;
213
- case "URLSearchParams":
214
- str = `["URLSearchParams",${stringify_string(thing.toString())}]`;
215
- break;
216
- case "RegExp":
217
- const { source, flags } = thing;
218
- str = flags ? `["RegExp",${stringify_string(source)},"${flags}"]` : `["RegExp",${stringify_string(source)}]`;
219
- break;
220
- case "Array": {
221
- let mostly_dense = false;
222
- str = "[";
223
- for (let i = 0; i < thing.length; i += 1) {
224
- if (i > 0) str += ",";
225
- if (Object.hasOwn(thing, i)) {
226
- keys.push(`[${i}]`);
227
- str += flatten(thing[i]);
228
- keys.pop();
229
- } else if (mostly_dense) str += -2;
230
- else {
231
- const populated_keys = valid_array_indices(thing);
232
- const population = populated_keys.length;
233
- const d = String(thing.length).length;
234
- if ((thing.length - population) * 3 > 4 + d + population * (d + 1)) {
235
- str = "[-7," + thing.length;
236
- for (let j = 0; j < populated_keys.length; j++) {
237
- const key = populated_keys[j];
238
- keys.push(`[${key}]`);
239
- str += "," + key + "," + flatten(thing[key]);
240
- keys.pop();
241
- }
242
- break;
243
- } else {
244
- mostly_dense = true;
245
- str += -2;
246
- }
247
- }
248
- }
249
- str += "]";
250
- break;
251
- }
252
- case "Set":
253
- str = "[\"Set\"";
254
- for (const value of thing) str += `,${flatten(value)}`;
255
- str += "]";
256
- break;
257
- case "Map":
258
- str = "[\"Map\"";
259
- for (const [key, value] of thing) {
260
- keys.push(`.get(${is_primitive(key) ? stringify_primitive(key) : "..."})`);
261
- str += `,${flatten(key)},${flatten(value)}`;
262
- keys.pop();
263
- }
264
- str += "]";
265
- break;
266
- case "Int8Array":
267
- case "Uint8Array":
268
- case "Uint8ClampedArray":
269
- case "Int16Array":
270
- case "Uint16Array":
271
- case "Int32Array":
272
- case "Uint32Array":
273
- case "Float32Array":
274
- case "Float64Array":
275
- case "BigInt64Array":
276
- case "BigUint64Array": {
277
- /** @type {import("./types.js").TypedArray} */
278
- const typedArray = thing;
279
- str = "[\"" + type + "\"," + flatten(typedArray.buffer);
280
- const a = thing.byteOffset;
281
- const b = a + thing.byteLength;
282
- if (a > 0 || b !== typedArray.buffer.byteLength) {
283
- const m = +/(\d+)/.exec(type)[1] / 8;
284
- str += `,${a / m},${b / m}`;
285
- }
286
- str += "]";
287
- break;
288
- }
289
- case "ArrayBuffer":
290
- str = `["ArrayBuffer","${encode64(thing)}"]`;
291
- break;
292
- case "Temporal.Duration":
293
- case "Temporal.Instant":
294
- case "Temporal.PlainDate":
295
- case "Temporal.PlainTime":
296
- case "Temporal.PlainDateTime":
297
- case "Temporal.PlainMonthDay":
298
- case "Temporal.PlainYearMonth":
299
- case "Temporal.ZonedDateTime":
300
- str = `["${type}",${stringify_string(thing.toString())}]`;
301
- break;
302
- default:
303
- if (!is_plain_object(thing)) throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value);
304
- if (enumerable_symbols(thing).length > 0) throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value);
305
- if (Object.getPrototypeOf(thing) === null) {
306
- str = "[\"null\"";
307
- for (const key of Object.keys(thing)) {
308
- if (key === "__proto__") throw new DevalueError(`Cannot stringify objects with __proto__ keys`, keys, thing, value);
309
- keys.push(stringify_key(key));
310
- str += `,${stringify_string(key)},${flatten(thing[key])}`;
311
- keys.pop();
312
- }
313
- str += "]";
314
- } else {
315
- str = "{";
316
- let started = false;
317
- for (const key of Object.keys(thing)) {
318
- if (key === "__proto__") throw new DevalueError(`Cannot stringify objects with __proto__ keys`, keys, thing, value);
319
- if (started) str += ",";
320
- started = true;
321
- keys.push(stringify_key(key));
322
- str += `${stringify_string(key)}:${flatten(thing[key])}`;
323
- keys.pop();
324
- }
325
- str += "}";
326
- }
327
- }
328
- }
329
- stringified[index] = str;
330
- return index;
331
- }
332
- const index = flatten(value);
333
- if (index < 0) return `${index}`;
334
- return `[${stringified.join(",")}]`;
335
- }
34
+ const RequestEvent = RequestEvent$1;
336
35
  /**
337
- * @param {any} thing
338
- * @returns {string}
36
+ * Server-side runtime builder used to provide long-lived Effect services to
37
+ * remote functions.
38
+ *
39
+ * @see https://ser.barekey.dev/content/reference/server-runtime
339
40
  */
340
- function stringify_primitive(thing) {
341
- const type = typeof thing;
342
- if (type === "string") return stringify_string(thing);
343
- if (thing instanceof String) return stringify_string(thing.toString());
344
- if (thing === void 0) return (-1).toString();
345
- if (thing === 0 && 1 / thing < 0) return (-6).toString();
346
- if (type === "bigint") return `["BigInt","${thing}"]`;
347
- return String(thing);
348
- }
349
- //#endregion
350
- //#region server.ts
351
- const RequestEvent = Context.GenericTag("svelte-effect-runtime/RequestEvent");
352
- let current_server_runtime = null;
353
- function runtime_seed() {
354
- return Layer.effectContext(Effect.context());
355
- }
356
- function pipe_server_runtime(...ops) {
357
- if (ops.length === 0) return Layer.empty;
358
- return ops.reduce((layer, op) => op(layer), runtime_seed());
359
- }
360
- function make_server_runtime(...ops) {
361
- const layer = ops.length === 0 ? pipe_server_runtime() : pipe_server_runtime(...ops);
362
- const previous_runtime = current_server_runtime;
363
- current_server_runtime = ManagedRuntime.make(layer);
364
- previous_runtime?.dispose().catch(() => void 0);
365
- }
366
- const ServerRuntime = {
367
- pipe: pipe_server_runtime,
368
- make: make_server_runtime
369
- };
370
- function get_server_runtime_or_throw() {
371
- if (current_server_runtime !== null) return current_server_runtime;
372
- current_server_runtime = ManagedRuntime.make(pipe_server_runtime());
373
- return current_server_runtime;
374
- }
375
- function is_effect_schema(value) {
376
- return Schema.isSchema(value);
377
- }
378
- function get_effect_schema_validator(schema) {
379
- return Schema.standardSchemaV1(schema);
380
- }
381
- function get_effect_form_validator(schema) {
382
- return Schema.standardSchemaV1(schema);
383
- }
384
- function resolve_remote_args(validate_or_fn, maybe_fn) {
385
- if (maybe_fn === void 0) return {
386
- fn: validate_or_fn,
387
- validate: void 0
388
- };
389
- if (validate_or_fn === "unchecked") return {
390
- fn: maybe_fn,
391
- validate: "unchecked"
392
- };
393
- if (!is_effect_schema(validate_or_fn)) throw new Error("Invalid schema passed to a remote function. Use Effect.Schema, 'unchecked', or omit the validator entirely.");
394
- return {
395
- fn: maybe_fn,
396
- validate: validate_or_fn
397
- };
398
- }
399
- function get_remote_failure_status(failure) {
400
- if (failure && typeof failure === "object" && typeof failure.status === "number") return failure.status;
401
- return 500;
402
- }
403
- function log_remote_server_step(step, details) {
404
- console.log("[svelte-effect-runtime][server]", step, details ?? {});
405
- }
406
- function encode_remote_failure(failure) {
407
- log_remote_server_step("encode_remote_failure:start", { failure });
408
- const { state } = get_request_store();
409
- const encoded = stringify(failure, Object.fromEntries(Object.entries(state.transport).map(([name, transporter]) => [name, transporter.encode])));
410
- throw error(get_remote_failure_status(failure), {
411
- message: "Effect remote failure",
412
- ...create_serialized_remote_failure_envelope(encoded)
413
- });
414
- }
415
- function throw_form_error(form_error) {
416
- log_remote_server_step("throw_form_error", { issues: form_error.issues });
417
- invalid(...form_error.issues.map((issue) => ({
418
- message: issue.message,
419
- path: [...issue.path]
420
- })));
421
- }
422
- async function run_remote_effect(program) {
423
- const request_event = getRequestEvent();
424
- const runtime = get_server_runtime_or_throw();
425
- log_remote_server_step("run_remote_effect:start", {
426
- method: request_event.request.method,
427
- url: request_event.url.toString()
428
- });
429
- const provided_program = Effect.provideService(program, RequestEvent, request_event);
430
- const exit = await runtime.runPromiseExit(provided_program);
431
- if (Exit.isSuccess(exit)) {
432
- log_remote_server_step("run_remote_effect:success", { value: exit.value });
433
- return exit.value;
434
- }
435
- const failure = Cause.failureOption(exit.cause);
436
- if (Option.isSome(failure)) {
437
- log_remote_server_step("run_remote_effect:failure", { failure: failure.value });
438
- if (is_form_error(failure.value)) throw_form_error(failure.value);
439
- encode_remote_failure(failure.value);
440
- }
441
- log_remote_server_step("run_remote_effect:defect", { cause: exit.cause });
442
- throw Cause.squash(exit.cause);
443
- }
444
- function get_schema_field_names(schema) {
445
- return Schema_ast.getPropertySignatures(schema.ast).map((property_signature) => property_signature.name).filter((name) => typeof name === "string");
446
- }
447
- function create_invalid_helper(options = {}) {
448
- const field_names = options.schema ? new Set(get_schema_field_names(options.schema)) : null;
449
- const create_issue_effect = (message, path) => Effect.fail(create_form_error({
450
- message,
451
- path
452
- }));
453
- return new Proxy({ form(message) {
454
- return create_issue_effect(message, []);
455
- } }, { get(target, property) {
456
- if (typeof property !== "string") return Reflect.get(target, property);
457
- if (property in target) return target[property];
458
- if (field_names !== null && !field_names.has(property)) throw new Error(`Unknown form field '${property}' in invalid helper. v1 only supports top-level fields declared in the Effect.Schema.`);
459
- return (message) => create_issue_effect(message, [property]);
460
- } });
461
- }
462
- function define_native_property(value, native) {
463
- Object.defineProperty(value, "native", {
464
- value: native,
465
- enumerable: false
466
- });
467
- return value;
468
- }
469
- function create_effect_transport(schemas) {
470
- return Object.fromEntries(Object.entries(schemas).map(([name, schema]) => {
471
- return [name, {
472
- encode(value) {
473
- try {
474
- return Schema.is(schema)(value) ? { value: Schema.encodeSync(schema)(value) } : false;
475
- } catch {
476
- return false;
477
- }
478
- },
479
- decode(data) {
480
- return Schema.decodeSync(schema)(data.value);
481
- }
482
- }];
483
- }));
484
- }
485
- function create_native_wrapper(value) {
486
- return define_native_property(value, value);
487
- }
488
- function query_batch_factory(validate_or_fn, maybe_fn) {
489
- const resolved = resolve_remote_args(validate_or_fn, maybe_fn);
490
- if (resolved.validate === void 0) throw new Error("Query.batch requires either 'unchecked' or an Effect.Schema validator to match SvelteKit's native API.");
491
- return create_native_wrapper(resolved.validate === "unchecked" ? query.batch("unchecked", (args) => run_remote_effect(resolved.fn(args))) : query.batch(get_effect_schema_validator(resolved.validate), (args) => run_remote_effect(resolved.fn(args))));
492
- }
493
- const query_impl = (validate_or_fn, maybe_fn) => {
494
- const resolved = resolve_remote_args(validate_or_fn, maybe_fn);
495
- return create_native_wrapper(resolved.validate === void 0 ? query(() => run_remote_effect(resolved.fn())) : resolved.validate === "unchecked" ? query("unchecked", (arg) => run_remote_effect(resolved.fn(arg))) : query(get_effect_schema_validator(resolved.validate), (arg) => run_remote_effect(resolved.fn(arg))));
496
- };
497
- const Query = Object.assign(query_impl, { batch: query_batch_factory });
498
- const command_impl = (validate_or_fn, maybe_fn) => {
499
- const resolved = resolve_remote_args(validate_or_fn, maybe_fn);
500
- return create_native_wrapper(resolved.validate === void 0 ? command(() => run_remote_effect(resolved.fn())) : resolved.validate === "unchecked" ? command("unchecked", (arg) => run_remote_effect(resolved.fn(arg))) : command(get_effect_schema_validator(resolved.validate), (arg) => run_remote_effect(resolved.fn(arg))));
501
- };
502
- const Command = command_impl;
503
- const form_impl = (validate_or_fn, maybe_fn) => {
504
- const resolved = resolve_remote_args(validate_or_fn, maybe_fn);
505
- return create_native_wrapper(resolved.validate === void 0 ? form(() => run_remote_effect(resolved.fn())) : resolved.validate === "unchecked" ? form("unchecked", (data) => run_remote_effect(resolved.fn({
506
- data,
507
- invalid: create_invalid_helper()
508
- }))) : form(get_effect_form_validator(resolved.validate), (data) => run_remote_effect(resolved.fn({
509
- data,
510
- invalid: create_invalid_helper({ schema: resolved.validate })
511
- }))));
512
- };
513
- const Form = form_impl;
514
- const native_prerender_fn = prerender;
515
- const prerender_impl = (validate_or_fn, fn_or_options, maybe_options) => {
516
- if (typeof validate_or_fn === "function" && typeof fn_or_options !== "function") return create_native_wrapper(native_prerender_fn(() => run_remote_effect(validate_or_fn()), fn_or_options));
517
- const resolved = resolve_remote_args(validate_or_fn, fn_or_options);
518
- return create_native_wrapper(resolved.validate === "unchecked" ? native_prerender_fn("unchecked", (arg) => run_remote_effect(resolved.fn(arg)), maybe_options) : native_prerender_fn(get_effect_schema_validator(resolved.validate), (arg) => run_remote_effect(resolved.fn(arg)), maybe_options));
519
- };
520
- const Prerender = prerender_impl;
41
+ const ServerRuntime = ServerRuntime$1;
42
+ /**
43
+ * Build a devalue transport table from Effect schemas so remote payloads can
44
+ * round-trip custom data across the client/server boundary.
45
+ *
46
+ * @see https://ser.barekey.dev/content/reference/transport
47
+ */
48
+ const create_effect_transport = create_effect_transport$1;
49
+ /**
50
+ * Resolve the active server runtime, lazily creating a default empty runtime
51
+ * when no explicit one has been registered.
52
+ *
53
+ * @internal Internal - do not use.
54
+ * @see https://ser.barekey.dev/content/reference/server-runtime
55
+ */
56
+ const get_server_runtime_or_throw = get_server_runtime_or_throw$1;
521
57
  //#endregion
522
58
  export { Command, Form, Prerender, Query, RequestEvent, ServerRuntime, create_effect_transport, get_server_runtime_or_throw };
523
59