svelte-effect-runtime 3.4.11 → 4.0.1

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