svelte-effect-runtime 4.0.0 → 4.1.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 (150) hide show
  1. package/.dist/chunks/client-DbwVAMWm.js +530 -0
  2. package/.dist/chunks/client-DbwVAMWm.js.map +1 -0
  3. package/.dist/chunks/compiler-Dpyu4Owd.js +412 -0
  4. package/.dist/chunks/compiler-Dpyu4Owd.js.map +1 -0
  5. package/.dist/chunks/descriptors-q909VWyR.js +216 -0
  6. package/.dist/chunks/descriptors-q909VWyR.js.map +1 -0
  7. package/.dist/chunks/diagnostics-DLwwrBWb.js +359 -0
  8. package/.dist/chunks/diagnostics-DLwwrBWb.js.map +1 -0
  9. package/.dist/chunks/dispatcher-CTWINW5I.js +534 -0
  10. package/.dist/chunks/dispatcher-CTWINW5I.js.map +1 -0
  11. package/.dist/chunks/dispatcher-pZPzarul.js +23 -0
  12. package/.dist/chunks/dispatcher-pZPzarul.js.map +1 -0
  13. package/.dist/chunks/{errors-IJjsUwrE.js → errors-qhcbUH6o.js} +56 -44
  14. package/.dist/chunks/errors-qhcbUH6o.js.map +1 -0
  15. package/.dist/chunks/live-BW7xZKjb.js +146 -0
  16. package/.dist/chunks/live-BW7xZKjb.js.map +1 -0
  17. package/.dist/chunks/live-CHK0RrZu.js +10 -0
  18. package/.dist/chunks/live-CHK0RrZu.js.map +1 -0
  19. package/.dist/chunks/{remote-client-CVI4t66c.js → remote-client-mkQAfP1G.js} +29 -23
  20. package/.dist/chunks/remote-client-mkQAfP1G.js.map +1 -0
  21. package/.dist/chunks/{runtime-GBQz32DZ.js → runtime-CPosEhGl.js} +3 -27
  22. package/.dist/chunks/runtime-CPosEhGl.js.map +1 -0
  23. package/.dist/chunks/{server-D1LcDnZE.js → server-yQrNoiCR.js} +15 -84
  24. package/.dist/chunks/server-yQrNoiCR.js.map +1 -0
  25. package/.dist/chunks/source-scan-cSawCvsg.js +1059 -0
  26. package/.dist/chunks/source-scan-cSawCvsg.js.map +1 -0
  27. package/.dist/chunks/{transform-jNUr65K9.js → transform-D7TTlPpK.js} +245 -371
  28. package/.dist/chunks/transform-D7TTlPpK.js.map +1 -0
  29. package/.dist/compiler/markup-identifiers.d.ts +2 -0
  30. package/.dist/compiler/remote-client.d.ts +1 -19
  31. package/.dist/compiler/source-scan.d.ts +11 -108
  32. package/.dist/compiler/sveltekit-remote-bridge.d.ts +3 -0
  33. package/.dist/compiler.d.ts +6 -0
  34. package/.dist/compiler.js +1 -1
  35. package/.dist/detect.d.ts +0 -31
  36. package/.dist/detect.js +0 -39
  37. package/.dist/detect.js.map +1 -1
  38. package/.dist/diagnostics.d.ts +0 -16
  39. package/.dist/dispatcher/deps.d.ts +3 -14
  40. package/.dist/dispatcher/fibers.d.ts +5 -46
  41. package/.dist/dispatcher/index.d.ts +42 -135
  42. package/.dist/dispatcher/scope.d.ts +36 -0
  43. package/.dist/dispatcher/types.d.ts +0 -151
  44. package/.dist/dispatcher.d.ts +2 -1
  45. package/.dist/dispatcher.js +2 -2
  46. package/.dist/errors.d.ts +44 -42
  47. package/.dist/generated/dispatcher.d.ts +6 -51
  48. package/.dist/generators.d.ts +2 -12
  49. package/.dist/internal/descriptors.d.ts +0 -16
  50. package/.dist/internal/generators.js +14 -9
  51. package/.dist/internal/generators.js.map +1 -1
  52. package/.dist/internal/live.d.ts +9 -0
  53. package/.dist/internal/remote-client.js +2 -2
  54. package/.dist/internal/remote-server.js +2 -2
  55. package/.dist/internal/schema.d.ts +0 -54
  56. package/.dist/live.d.ts +9 -26
  57. package/.dist/markup/event-attributes.d.ts +0 -32
  58. package/.dist/markup/promise.d.ts +1 -23
  59. package/.dist/markup/promise.js +2 -18
  60. package/.dist/markup/promise.js.map +1 -1
  61. package/.dist/markup/run.d.ts +1 -10
  62. package/.dist/markup/run.js +2 -11
  63. package/.dist/markup/run.js.map +1 -1
  64. package/.dist/markup/transform/apply.d.ts +5 -4
  65. package/.dist/markup/transform/classify.d.ts +2 -11
  66. package/.dist/markup/transform/constants.d.ts +2 -1
  67. package/.dist/markup/transform/effect-bindings.d.ts +2 -26
  68. package/.dist/markup/transform/effect-callbacks.d.ts +0 -20
  69. package/.dist/markup/transform/emit.d.ts +2 -11
  70. package/.dist/markup/transform/expressions.d.ts +0 -35
  71. package/.dist/markup/transform/scan.d.ts +3 -22
  72. package/.dist/markup/transform/types.d.ts +15 -127
  73. package/.dist/markup/transform.js +1 -1
  74. package/.dist/markup/value.d.ts +1 -18
  75. package/.dist/markup/value.js +2 -19
  76. package/.dist/markup/value.js.map +1 -1
  77. package/.dist/mod.d.ts +3 -8
  78. package/.dist/mod.js +5 -5
  79. package/.dist/mod.js.map +1 -1
  80. package/.dist/remote/cause-codec.d.ts +3 -37
  81. package/.dist/remote/client/command.d.ts +3 -17
  82. package/.dist/remote/client/form-data.d.ts +0 -7
  83. package/.dist/remote/client/form-enhance.d.ts +0 -7
  84. package/.dist/remote/client/form-transport.d.ts +14 -20
  85. package/.dist/remote/client/form.d.ts +4 -24
  86. package/.dist/remote/client/index.d.ts +2 -1
  87. package/.dist/remote/client/prerender.d.ts +6 -0
  88. package/.dist/remote/client/query-result.d.ts +2 -14
  89. package/.dist/remote/client/query.d.ts +8 -48
  90. package/.dist/remote/client/responses.d.ts +3 -27
  91. package/.dist/remote/client/types.d.ts +16 -110
  92. package/.dist/remote/client/utils.d.ts +0 -8
  93. package/.dist/remote/client.d.ts +2 -2
  94. package/.dist/remote/client.js +2 -2
  95. package/.dist/remote/effect.d.ts +6 -0
  96. package/.dist/remote/failures.d.ts +4 -0
  97. package/.dist/remote/query-update.d.ts +2 -0
  98. package/.dist/remote/resource.d.ts +25 -0
  99. package/.dist/remote/server.d.ts +5 -50
  100. package/.dist/remote/server.js +2 -2
  101. package/.dist/remote/shared.d.ts +6 -145
  102. package/.dist/remote/shared.js +6 -127
  103. package/.dist/remote/shared.js.map +1 -1
  104. package/.dist/runtime/transform.js +26 -31
  105. package/.dist/runtime/transform.js.map +1 -1
  106. package/.dist/script-transform/ast.d.ts +0 -46
  107. package/.dist/script-transform/imports.d.ts +3 -39
  108. package/.dist/script-transform/index.d.ts +2 -0
  109. package/.dist/script-transform/lower.d.ts +0 -9
  110. package/.dist/script-transform/runes.d.ts +0 -10
  111. package/.dist/script-transform/runtime-block.d.ts +0 -17
  112. package/.dist/script-transform/source.d.ts +0 -24
  113. package/.dist/script-transform/types.d.ts +9 -126
  114. package/.dist/server/effects.d.ts +4 -53
  115. package/.dist/server/factories.d.ts +7 -7
  116. package/.dist/server/index.d.ts +1 -1
  117. package/.dist/server/invalid.d.ts +0 -7
  118. package/.dist/server/live-snapshot.d.ts +5 -0
  119. package/.dist/server/remote-handler-context.d.ts +5 -0
  120. package/.dist/server/runtime.d.ts +6 -24
  121. package/.dist/server/schema.d.ts +0 -14
  122. package/.dist/server/transport.d.ts +2 -0
  123. package/.dist/server/types.d.ts +49 -26
  124. package/.dist/server/wrappers.d.ts +3 -40
  125. package/.dist/server.d.ts +1 -1
  126. package/.dist/server.js +200 -215
  127. package/.dist/server.js.map +1 -1
  128. package/.dist/yieldable.d.ts +1 -35
  129. package/package.json +2 -2
  130. package/.dist/chunks/client-DcZUV4rR.js +0 -653
  131. package/.dist/chunks/client-DcZUV4rR.js.map +0 -1
  132. package/.dist/chunks/compiler-BBPNyXmQ.js +0 -460
  133. package/.dist/chunks/compiler-BBPNyXmQ.js.map +0 -1
  134. package/.dist/chunks/dispatcher-DOx8iC6r.js +0 -505
  135. package/.dist/chunks/dispatcher-DOx8iC6r.js.map +0 -1
  136. package/.dist/chunks/dispatcher-H-Ia0Os4.js +0 -47
  137. package/.dist/chunks/dispatcher-H-Ia0Os4.js.map +0 -1
  138. package/.dist/chunks/errors-IJjsUwrE.js.map +0 -1
  139. package/.dist/chunks/live-BXAKre_4.js +0 -104
  140. package/.dist/chunks/live-BXAKre_4.js.map +0 -1
  141. package/.dist/chunks/remote-client-CVI4t66c.js.map +0 -1
  142. package/.dist/chunks/runtime-GBQz32DZ.js.map +0 -1
  143. package/.dist/chunks/schema-D9pct6Y5.js +0 -89
  144. package/.dist/chunks/schema-D9pct6Y5.js.map +0 -1
  145. package/.dist/chunks/server-D1LcDnZE.js.map +0 -1
  146. package/.dist/chunks/source-scan-C4PsggID.js +0 -341
  147. package/.dist/chunks/source-scan-C4PsggID.js.map +0 -1
  148. package/.dist/chunks/transform-jNUr65K9.js.map +0 -1
  149. package/.dist/remote/client/effect.d.ts +0 -29
  150. package/.dist/remote/client/failures.d.ts +0 -42
@@ -1,653 +0,0 @@
1
- import { O as UnsupportedRemoteFormResponseError, c as InvalidLiveQueryFactoryError, d as InvalidRemoteFormResponseError, m as RemoteFormEndpointMissingError, p as RemoteErrorDecodeError, s as InvalidCommandFactoryError, u as InvalidQueryFactoryError } from "./errors-IJjsUwrE.js";
2
- import { n as get_dispatcher } from "./dispatcher-DOx8iC6r.js";
3
- import { n as make_remote_live_stream } from "./live-BXAKre_4.js";
4
- import { create_remote_http_error, create_remote_transport_error, create_remote_validation_error, is_serialized_remote_failure_envelope } from "../remote/shared.js";
5
- import { n as normalize_validator, r as copy_property_descriptors, t as is_standard_schema } from "./schema-D9pct6Y5.js";
6
- import { Effect, Option, Schema } from "effect";
7
- import { isRedirect } from "@sveltejs/kit";
8
- import { parse } from "devalue";
9
- //#region src/remote/client/utils.ts
10
- /**
11
- * Checks whether a value has a callable method property.
12
- *
13
- * @since 2.0.0
14
- * @param value - Value to inspect.
15
- * @param key - Method key to look up.
16
- * @returns Whether the value has a function at `key`.
17
- */
18
- function has_method(value, key) {
19
- return typeof value === "object" && value !== null && typeof value[key] === "function";
20
- }
21
- //#endregion
22
- //#region src/remote/client/failures.ts
23
- const RemoteErrorMessageEnvelopeSchema = Schema.Struct({ message: Schema.String });
24
- const DecodedRemoteFailureSchema = Schema.Struct({ _tag: Schema.String });
25
- const DecodeJsonString = Schema.decodeUnknownOption(Schema.UnknownFromJsonString);
26
- const is_decoded_remote_failure_value = Schema.is(DecodedRemoteFailureSchema);
27
- const is_remote_error_message_envelope = Schema.is(RemoteErrorMessageEnvelopeSchema);
28
- /**
29
- * Decodes a raw wire value into a remote failure when it uses the runtime
30
- * failure envelope.
31
- *
32
- * @example
33
- * ```ts
34
- * const failure = decode_remote_error(body);
35
- * ```
36
- *
37
- * @since 2.0.0
38
- * @param raw - Raw value received from the network or SvelteKit error body.
39
- * @param decode - Optional devalue decoder for custom error payloads.
40
- * @returns The decoded failure/value, or a transport error when decoding fails.
41
- */
42
- function decode_remote_error(raw, decode) {
43
- const embedded = decode_embedded_remote_failure(raw);
44
- if (embedded._tag === "EmbeddedRemoteFailureDecoded") return decode_remote_error(embedded.value, decode);
45
- if (is_serialized_remote_failure_envelope(raw)) {
46
- const decoded = decode_serialized_remote_failure(raw.encoded, decode);
47
- if (decoded._tag === "SerializedRemoteFailureInvalid") return create_remote_transport_error(new RemoteErrorDecodeError(raw), raw);
48
- return decoded.value;
49
- }
50
- return raw;
51
- }
52
- function decode_embedded_remote_failure(raw) {
53
- if (typeof raw === "string") return decode_embedded_json_remote_failure(raw);
54
- if (!is_remote_error_message_envelope(raw)) return { _tag: "EmbeddedRemoteFailureIgnored" };
55
- return decode_embedded_json_remote_failure(raw.message);
56
- }
57
- function decode_embedded_json_remote_failure(value) {
58
- const decoded = decode_json_string(value);
59
- if (decoded._tag === "JsonStringIgnored") return { _tag: "EmbeddedRemoteFailureIgnored" };
60
- return {
61
- _tag: "EmbeddedRemoteFailureDecoded",
62
- value: decoded.value
63
- };
64
- }
65
- function decode_json_string(value) {
66
- const decoded = DecodeJsonString(value);
67
- if (!Option.isSome(decoded)) return { _tag: "JsonStringIgnored" };
68
- return {
69
- _tag: "JsonStringDecoded",
70
- value: decoded.value
71
- };
72
- }
73
- function decode_serialized_remote_failure(encoded, decode) {
74
- try {
75
- return {
76
- _tag: "SerializedRemoteFailureDecoded",
77
- value: decode ? decode(encoded) : parse(encoded)
78
- };
79
- } catch {
80
- return { _tag: "SerializedRemoteFailureInvalid" };
81
- }
82
- }
83
- /**
84
- * Checks whether a decoded value is a tagged remote failure.
85
- *
86
- * @example
87
- * ```ts
88
- * if (is_decoded_remote_failure(value)) throw value;
89
- * ```
90
- *
91
- * @since 2.0.0
92
- * @param value - Value to inspect.
93
- * @returns Whether the value carries a `_tag` discriminator.
94
- */
95
- function is_decoded_remote_failure(value) {
96
- return is_decoded_remote_failure_value(value);
97
- }
98
- /**
99
- * Normalizes native thrown values into the runtime's remote failure model.
100
- *
101
- * @example
102
- * ```ts
103
- * const failure = normalize_native_error(error);
104
- * ```
105
- *
106
- * @since 2.0.0
107
- * @param error - Unknown value thrown by a native remote helper.
108
- * @returns A typed remote failure.
109
- */
110
- function normalize_native_error(error) {
111
- const body = get_error_body(error);
112
- const decoded = decode_remote_error(body);
113
- const status = get_error_status(error);
114
- if (is_decoded_remote_failure(decoded)) return decoded;
115
- if (status !== void 0) return create_remote_http_error(status, body, error);
116
- return create_remote_transport_error(error);
117
- }
118
- function get_error_status(error) {
119
- if (typeof error !== "object" || error === null) return;
120
- const status = error.status;
121
- return typeof status === "number" ? status : void 0;
122
- }
123
- function get_error_body(error) {
124
- if (typeof error !== "object" || error === null) return;
125
- if ("body" in error) return error.body;
126
- if ("data" in error) return error.data;
127
- }
128
- //#endregion
129
- //#region src/remote/client/responses.ts
130
- /**
131
- * Decodes a failed fetch response into the runtime failure model.
132
- *
133
- * @example
134
- * ```ts
135
- * const failure = await decode_response_failure(response);
136
- * ```
137
- *
138
- * @since 2.0.0
139
- * @param response - Failed fetch response returned by the remote endpoint.
140
- * @returns Remote failure represented by the response.
141
- */
142
- async function decode_response_failure(response) {
143
- const body = await response.json().catch(() => void 0);
144
- const decoded = decode_remote_error(body);
145
- if (is_decoded_remote_failure(decoded)) return decoded;
146
- return create_remote_http_error(response.status, body);
147
- }
148
- /**
149
- * Decodes either a raw value or `Response` returned by a native remote helper.
150
- *
151
- * @example
152
- * ```ts
153
- * const output = await decode_response_or_value(result, decode_payload);
154
- * ```
155
- *
156
- * @since 2.0.0
157
- * @param value - Native result value or fetch response.
158
- * @param decode_payload - Function used to decode successful payloads.
159
- * @returns Decoded successful output.
160
- */
161
- async function decode_response_or_value(value, decode_payload) {
162
- if (value instanceof Response) {
163
- if (!value.ok) throw await decode_response_failure(value);
164
- return decode_payload(await decode_success_response_body(value));
165
- }
166
- return decode_payload(value);
167
- }
168
- async function decode_success_response_body(response) {
169
- if (response.status === 204 || response.status === 205) return;
170
- const text = await response.text();
171
- if (text.length === 0) return;
172
- return JSON.parse(text);
173
- }
174
- //#endregion
175
- //#region src/remote/client/effect.ts
176
- /**
177
- * Wraps a promise-producing remote operation in an Effect with failure mapping.
178
- *
179
- * @example
180
- * ```ts
181
- * const program = make_effect_from_promise(() => native_remote(input));
182
- * ```
183
- *
184
- * @since 2.0.0
185
- * @param run - Promise-producing operation that invokes a native remote helper.
186
- * @returns Effect that maps thrown values into remote failures.
187
- */
188
- function MakeEffectFromPromise(run) {
189
- return Effect.tryPromise({
190
- try: run,
191
- catch: (error) => {
192
- if (isRedirect(error)) throw error;
193
- if (is_decoded_remote_failure(error)) return error;
194
- return normalize_native_error(error);
195
- }
196
- });
197
- }
198
- //#endregion
199
- //#region src/remote/client/command.ts
200
- /**
201
- * Creates a remote command adapter. The adapter preserves the native
202
- * pending getter and turns each invocation into an Effect.
203
- *
204
- * @since 2.0.0
205
- * @param native_factory - SvelteKit's native command function or a legacy
206
- * response factory used by tests.
207
- * @param decode_payload - Function to decode the response payload.
208
- * @param _base - Deprecated transport base retained for compatibility.
209
- * @param pending - Optional pending counter for legacy response factories.
210
- * @returns A function returning an Effect of the response.
211
- * @internal
212
- */
213
- function create_remote_command_adapter(native_factory, decode_payload, _base = "", pending) {
214
- const invoke = has_method(native_factory, "invoke") ? native_factory.invoke : void 0;
215
- if (typeof native_factory !== "function" && !invoke) throw new InvalidCommandFactoryError();
216
- const count = pending ?? { value: 0 };
217
- const adapter = (input) => MakeEffectFromPromise(async () => {
218
- count.value += 1;
219
- try {
220
- return await decode_response_or_value(invoke ? await invoke(input) : await native_factory(input), decode_payload);
221
- } finally {
222
- count.value -= 1;
223
- }
224
- });
225
- copy_property_descriptors(native_factory, adapter);
226
- if (!Object.prototype.hasOwnProperty.call(adapter, "pending")) Object.defineProperty(adapter, "pending", { get: () => count.value });
227
- return adapter;
228
- }
229
- //#endregion
230
- //#region src/remote/client/form-data.ts
231
- /**
232
- * Encodes remote form input into SvelteKit-compatible form data.
233
- *
234
- * @since 2.0.0
235
- * @param input - Input value supplied to the remote form.
236
- * @returns FormData payload for the remote endpoint.
237
- */
238
- function to_form_data(input) {
239
- const form_data = new FormData();
240
- append_form_value(form_data, "", input);
241
- return form_data;
242
- }
243
- function append_form_value(form_data, path, value) {
244
- if (value === void 0) return;
245
- if (Array.isArray(value)) {
246
- for (const [index, item] of value.entries()) append_form_value(form_data, `${path}[${index}]`, item);
247
- return;
248
- }
249
- if (value instanceof Blob) {
250
- form_data.append(path, value);
251
- return;
252
- }
253
- if (typeof value === "object" && value !== null) {
254
- for (const [key, child] of Object.entries(value)) append_form_value(form_data, path.length === 0 ? key : `${path}.${key}`, child);
255
- return;
256
- }
257
- if (typeof value === "number") {
258
- form_data.append(`n:${path}`, String(value));
259
- return;
260
- }
261
- if (typeof value === "boolean") {
262
- if (value) form_data.append(`b:${path}`, "on");
263
- return;
264
- }
265
- form_data.append(path, value === null ? "" : String(value));
266
- }
267
- //#endregion
268
- //#region src/remote/client/form-transport.ts
269
- const FormIssuePathSegmentSchema = Schema.Union([Schema.String, Schema.Number]);
270
- const FormIssueSchema = Schema.Struct({
271
- message: Schema.String,
272
- path: Schema.Array(FormIssuePathSegmentSchema)
273
- });
274
- const RemoteFormErrorEnvelopeSchema = Schema.Struct({
275
- type: Schema.Literal("error"),
276
- error: Schema.optional(Schema.Unknown),
277
- status: Schema.optional(Schema.Number)
278
- });
279
- const RemoteFormResultEnvelopeSchema = Schema.Struct({
280
- type: Schema.Literal("result"),
281
- data: Schema.optional(Schema.String),
282
- result: Schema.optional(Schema.String)
283
- });
284
- const RemoteFormResponseEnvelopeSchema = Schema.Union([RemoteFormErrorEnvelopeSchema, RemoteFormResultEnvelopeSchema]);
285
- const RemoteFormDecodedPayloadSchema = Schema.Struct({
286
- issues: Schema.optional(Schema.Array(FormIssueSchema)),
287
- result: Schema.optional(Schema.Unknown)
288
- });
289
- const DecodeRemoteFormResponseEnvelope = Schema.decodeUnknownOption(RemoteFormResponseEnvelopeSchema);
290
- const DecodeRemoteFormPayload = Schema.decodeUnknownOption(RemoteFormDecodedPayloadSchema);
291
- /**
292
- * Submits a native remote form through the SvelteKit remote endpoint.
293
- *
294
- * @since 2.0.0
295
- * @param form_obj - Native form object being adapted.
296
- * @param input - Form input value.
297
- * @param decode_payload - Function to decode successful payloads.
298
- * @param remote_base - Base URL for the remote endpoint.
299
- * @param preflight_schema - Optional schema used to mirror SvelteKit's
300
- * client-side preflight before posting direct programmatic input.
301
- * @returns Decoded form output.
302
- */
303
- async function submit_remote_form(form_obj, input, decode_payload, remote_base, preflight_schema) {
304
- const action_id = get_remote_action_id(form_obj);
305
- if (!action_id || remote_base.length === 0) throw create_remote_transport_error(new RemoteFormEndpointMissingError());
306
- await validate_preflight_input(preflight_schema, input);
307
- const response = await fetch(to_remote_form_url(remote_base, action_id), {
308
- method: "POST",
309
- headers: get_remote_request_headers(),
310
- body: to_form_data(input)
311
- });
312
- if (!response.ok) throw await decode_response_failure(response);
313
- return decode_form_response(await response.json(), decode_payload);
314
- }
315
- /**
316
- * Extracts SvelteKit's remote action id from a native form action URL.
317
- *
318
- * @since 2.0.0
319
- * @param form_obj - Native form object being adapted.
320
- * @returns Remote action id when present.
321
- */
322
- function get_remote_action_id(form_obj) {
323
- const action = form_obj.action;
324
- if (typeof action !== "string") return;
325
- const href = typeof location === "undefined" ? "http://localhost/" : location.href;
326
- const url = new URL(action, href);
327
- return url.searchParams.get("/remote") ?? url.searchParams.get("remote") ?? void 0;
328
- }
329
- function to_remote_form_url(remote_base, action_id) {
330
- const parts = action_id.split("/");
331
- const head = parts.slice(0, 2).join("/");
332
- const tail = parts.slice(2).join("/");
333
- const normalized_base = remote_base.replace(/\/$/, "");
334
- if (tail.length === 0) return `${normalized_base}/${head}`;
335
- return `${normalized_base}/${head}/${encodeURIComponent(tail)}`;
336
- }
337
- function get_remote_request_headers() {
338
- if (typeof location === "undefined") return {};
339
- return {
340
- "x-sveltekit-pathname": location.pathname,
341
- "x-sveltekit-search": location.search
342
- };
343
- }
344
- async function validate_preflight_input(schema, input) {
345
- if (!schema) return;
346
- const validated = await schema["~standard"].validate(input);
347
- if (!is_record(validated) || !Array.isArray(validated.issues)) return;
348
- const issues = validated.issues.map(normalize_standard_issue);
349
- throw create_remote_validation_error(issues, { issues }, 400);
350
- }
351
- function normalize_standard_issue(issue) {
352
- if (!is_record(issue)) return {
353
- message: String(issue),
354
- path: []
355
- };
356
- return {
357
- message: typeof issue.message === "string" ? issue.message : "Invalid input",
358
- path: Array.isArray(issue.path) ? issue.path.flatMap(normalize_path_segment) : []
359
- };
360
- }
361
- function normalize_path_segment(segment) {
362
- if (typeof segment === "string" || typeof segment === "number") return [segment];
363
- if (!is_record(segment)) return [];
364
- const key = segment.key;
365
- if (typeof key === "string" || typeof key === "number") return [key];
366
- return [];
367
- }
368
- function is_record(value) {
369
- return typeof value === "object" && value !== null;
370
- }
371
- function decode_form_response(envelope, decode_payload) {
372
- const response = decode_remote_form_response_envelope(envelope);
373
- if (!response) throw create_remote_transport_error(new InvalidRemoteFormResponseError(envelope), envelope);
374
- if (response._tag === "RemoteFormErrorEnvelope") {
375
- const decoded = decode_remote_error(response.error);
376
- if (is_decoded_remote_failure(decoded)) throw decoded;
377
- throw create_remote_http_error(response.status ?? 500, response.error);
378
- }
379
- const result_text = response.result ?? response.data;
380
- if (result_text === void 0) throw create_remote_transport_error(new UnsupportedRemoteFormResponseError(envelope), envelope);
381
- const decoded = decode_remote_form_payload(decode_payload(parse(result_text)));
382
- if (!decoded) throw create_remote_transport_error(new UnsupportedRemoteFormResponseError(envelope), envelope);
383
- if (decoded.issues && decoded.issues.length > 0) throw create_remote_validation_error(decoded.issues, decoded, 400);
384
- return decoded.result;
385
- }
386
- function decode_remote_form_response_envelope(envelope) {
387
- const decoded = DecodeRemoteFormResponseEnvelope(envelope);
388
- if (!Option.isSome(decoded)) return;
389
- if (decoded.value.type === "error") return {
390
- _tag: "RemoteFormErrorEnvelope",
391
- error: decoded.value.error,
392
- status: decoded.value.status
393
- };
394
- return {
395
- _tag: "RemoteFormResultEnvelope",
396
- data: decoded.value.data,
397
- result: decoded.value.result
398
- };
399
- }
400
- function decode_remote_form_payload(payload) {
401
- const decoded = DecodeRemoteFormPayload(payload);
402
- if (!Option.isSome(decoded)) return;
403
- return decoded.value;
404
- }
405
- //#endregion
406
- //#region src/remote/client/form-enhance.ts
407
- /**
408
- * Wraps a remote form enhance callback so Effect return values are run.
409
- *
410
- * @since 2.0.0
411
- * @param callback - Native enhance callback to wrap.
412
- * @returns Wrapped callback or undefined.
413
- */
414
- function wrap_enhance_callback(callback) {
415
- if (!callback) return;
416
- return (event) => {
417
- const result = callback(wrap_submit_callback(event));
418
- if (Effect.isEffect(result)) return get_dispatcher().run(result);
419
- return result;
420
- };
421
- }
422
- function wrap_submit_callback(event) {
423
- if (typeof event !== "object" || event === null || !has_method(event, "submit")) return event;
424
- const original_submit = event.submit;
425
- const { submit: _submit, ...descriptors } = Object.getOwnPropertyDescriptors(event);
426
- return Object.defineProperties({}, {
427
- ...descriptors,
428
- submit: {
429
- configurable: true,
430
- enumerable: false,
431
- value: () => make_submit_effect(original_submit, event)
432
- }
433
- });
434
- }
435
- function make_submit_effect(original_submit, event) {
436
- let updates_args;
437
- const SubmitEffect = MakeEffectFromPromise(async () => {
438
- const result = original_submit();
439
- const value = updates_args && has_method(result, "updates") ? await Promise.resolve(result.updates(...updates_args)) : await Promise.resolve(result);
440
- if (typeof value === "boolean") return read_submit_result(event);
441
- return value;
442
- });
443
- Object.defineProperty(SubmitEffect, "updates", {
444
- configurable: true,
445
- enumerable: false,
446
- value: (...args) => {
447
- updates_args ??= args;
448
- return SubmitEffect;
449
- }
450
- });
451
- return SubmitEffect;
452
- }
453
- function read_submit_result(event) {
454
- if (typeof event !== "object" || event === null || !("result" in event)) return;
455
- return Reflect.get(event, "result");
456
- }
457
- //#endregion
458
- //#region src/remote/client/form.ts
459
- /**
460
- * Creates a remote form adapter. The callable preserves SvelteKit's native
461
- * form descriptors while wrapping `validate`, `enhance`, and programmatic
462
- * submission in Effect-returning APIs.
463
- *
464
- * @example
465
- * ```ts
466
- * const createPost = create_remote_form_adapter(nativeForm, (value) => value);
467
- * yield* createPost.validate({ includeUntouched: true });
468
- * ```
469
- *
470
- * @since 2.0.0
471
- * @param native_factory - SvelteKit's native form object.
472
- * @param decode_payload - Function to decode the response payload.
473
- * @param remote_base - Base URL for SvelteKit's remote endpoint.
474
- * @param adapter_state - Shared mutable state used to mirror root form
475
- * preflight schemas across keyed form instances.
476
- * @param keyed - Whether this adapter wraps a keyed form instance returned by
477
- * SvelteKit's native `for(...)` helper.
478
- * @returns A callable form function whose properties mirror the native form.
479
- * @internal
480
- */
481
- function create_remote_form_adapter(native_factory, decode_payload, remote_base = "", adapter_state = {}, keyed = false) {
482
- const form_obj = native_factory;
483
- let local_preflight_schema;
484
- const submit_effect = (input) => MakeEffectFromPromise(async () => {
485
- const can_use_remote_endpoint = remote_base.length > 0 && get_remote_action_id(form_obj) !== void 0;
486
- if (has_method(form_obj, "submit") && !can_use_remote_endpoint) return await decode_response_or_value(await form_obj.submit(input), decode_payload);
487
- return await submit_remote_form(form_obj, input, decode_payload, remote_base, local_preflight_schema ?? adapter_state.shared_preflight_schema);
488
- });
489
- const callable = ((input) => submit_effect(input));
490
- copy_property_descriptors(form_obj, callable, /* @__PURE__ */ new Set([
491
- "submit",
492
- "validate",
493
- "enhance",
494
- "for",
495
- "preflight"
496
- ]));
497
- Object.defineProperty(callable, "submit", {
498
- configurable: true,
499
- enumerable: false,
500
- value: submit_effect
501
- });
502
- if (has_method(form_obj, "validate")) Object.defineProperty(callable, "validate", {
503
- configurable: true,
504
- enumerable: false,
505
- value: (options) => MakeEffectFromPromise(async () => {
506
- await form_obj.validate(normalize_validate_options(form_obj.validate, options));
507
- })
508
- });
509
- if (has_method(form_obj, "enhance")) Object.defineProperty(callable, "enhance", {
510
- configurable: true,
511
- enumerable: false,
512
- value: (callback) => form_obj.enhance(wrap_enhance_callback(callback))
513
- });
514
- if (has_method(form_obj, "for")) Object.defineProperty(callable, "for", {
515
- configurable: true,
516
- enumerable: false,
517
- value: (key) => create_remote_form_adapter(form_obj.for(key), decode_payload, remote_base, adapter_state, true)
518
- });
519
- if (has_method(form_obj, "preflight")) Object.defineProperty(callable, "preflight", {
520
- configurable: true,
521
- enumerable: false,
522
- value: (schema) => {
523
- const normalized_schema = normalize_validator(schema);
524
- if (is_standard_schema(normalized_schema)) {
525
- local_preflight_schema = normalized_schema;
526
- if (!keyed) adapter_state.shared_preflight_schema = normalized_schema;
527
- }
528
- form_obj.preflight(normalized_schema);
529
- return callable;
530
- }
531
- });
532
- return callable;
533
- }
534
- function normalize_validate_options(validate, options) {
535
- if (!options || !("all" in options) || "includeUntouched" in options) return options;
536
- const source = Function.prototype.toString.call(validate);
537
- if (!(source.includes("includeUntouched") && !/\ball\s*=/.test(source))) return options;
538
- return {
539
- ...options,
540
- includeUntouched: options.all
541
- };
542
- }
543
- //#endregion
544
- //#region src/remote/client/query-result.ts
545
- /**
546
- * Resolves native query results, including SvelteKit run handles.
547
- *
548
- * @example
549
- * ```ts
550
- * const output = await resolve_query_result(result, decode_payload);
551
- * ```
552
- *
553
- * @since 2.0.0
554
- * @param value - Native query result or query run handle.
555
- * @param decode_payload - Function used to decode successful payloads.
556
- * @returns Decoded query output.
557
- */
558
- async function resolve_query_result(value, decode_payload) {
559
- if (has_method(value, "then")) return decode_response_or_value(await Promise.resolve(value), decode_payload);
560
- if (has_method(value, "run")) return decode_response_or_value(await value.run(), decode_payload);
561
- return decode_response_or_value(await Promise.resolve(value), decode_payload);
562
- }
563
- //#endregion
564
- //#region src/remote/client/query.ts
565
- function create_remote_query_adapter(native_factory, decode_payload, _base = "") {
566
- const load = has_method(native_factory, "load") ? native_factory.load : void 0;
567
- const query = typeof native_factory === "function" ? native_factory : void 0;
568
- if (!query && !load) throw new InvalidQueryFactoryError();
569
- const wrapped = ((input) => {
570
- if (!query) return MakeEffectFromPromise(async () => {
571
- return await resolve_query_result(await load?.(input), decode_payload);
572
- });
573
- const resource = query(input);
574
- const QueryEffect = MakeEffectFromPromise(async () => await resolve_query_result(resource, decode_payload));
575
- attach_query_resource(resource, QueryEffect);
576
- return QueryEffect;
577
- });
578
- copy_property_descriptors(native_factory, wrapped);
579
- return wrapped;
580
- }
581
- /**
582
- * Creates a remote live query adapter. The returned function takes input and
583
- * returns an Effect Stream whose transport state is exposed through `Live`.
584
- *
585
- * @example
586
- * ```ts
587
- * const getTime = create_remote_live_query_adapter(nativeLive, (value) => value);
588
- * const time = getTime();
589
- * const first = yield* Stream.runHead(time);
590
- * ```
591
- *
592
- * @since 2.0.0
593
- * @param native_factory - SvelteKit's native live query function.
594
- * @param _decode_payload - Deprecated payload decoder retained for parity with
595
- * other remote adapters.
596
- * @param _base - Deprecated transport base retained for compatibility.
597
- * @returns A function returning a remote live stream.
598
- * @internal
599
- */
600
- function create_remote_live_query_adapter(native_factory, _decode_payload, _base = "") {
601
- const query = typeof native_factory === "function" ? native_factory : void 0;
602
- if (!query) throw new InvalidLiveQueryFactoryError();
603
- const wrapped = ((input) => {
604
- return make_remote_live_stream(query(input), normalize_native_error);
605
- });
606
- copy_property_descriptors(native_factory, wrapped);
607
- return wrapped;
608
- }
609
- function is_resource(resource) {
610
- const resource_type = typeof resource;
611
- return resource_type === "object" && resource !== null || resource_type === "function";
612
- }
613
- function attach_resource_getters(resource, effect) {
614
- const methods = is_resource(resource) ? resource : void 0;
615
- const keys = [
616
- "current",
617
- "error",
618
- "loading",
619
- "ready"
620
- ];
621
- if (!methods) return;
622
- for (const key of keys) {
623
- if (!(key in methods)) continue;
624
- Object.defineProperty(effect, key, {
625
- configurable: true,
626
- get: () => methods[key]
627
- });
628
- }
629
- }
630
- function attach_query_resource(resource, effect) {
631
- const methods = is_resource(resource) ? resource : void 0;
632
- const refresh = methods?.refresh;
633
- const set = methods?.set;
634
- const with_override = methods?.withOverride;
635
- attach_resource_getters(resource, effect);
636
- if (!methods) return;
637
- if (typeof refresh === "function") Object.defineProperty(effect, "refresh", {
638
- configurable: true,
639
- value: () => MakeEffectFromPromise(() => Promise.resolve(refresh.call(resource)))
640
- });
641
- if (typeof set === "function") Object.defineProperty(effect, "set", {
642
- configurable: true,
643
- value: (value) => set.call(resource, value)
644
- });
645
- if (typeof with_override === "function") Object.defineProperty(effect, "withOverride", {
646
- configurable: true,
647
- value: (update) => with_override.call(resource, update)
648
- });
649
- }
650
- //#endregion
651
- export { create_remote_command_adapter as i, create_remote_query_adapter as n, create_remote_form_adapter as r, create_remote_live_query_adapter as t };
652
-
653
- //# sourceMappingURL=client-DcZUV4rR.js.map