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
@@ -2,68 +2,13 @@ import type { FormIssue } from "./shared.js";
2
2
  import { Cause, Effect } from "effect";
3
3
  type SvelteInvalid = (...issues: readonly (FormIssue | string)[]) => never;
4
4
  type SvelteError = (status: number, body: unknown) => never;
5
- /**
6
- * Runs a user-supplied Effect program through a ManagedRuntime, maps its
7
- * exit into the shape expected by SvelteKit, and returns the result or
8
- * throws a SvelteKit-compatible error.
9
- *
10
- * @since 2.0.0
11
- * @param effect - The Effect program to execute.
12
- * @param runtime - The server-side ManagedRuntime.
13
- * @param invalid - SvelteKit's `invalid` helper (bound per-request).
14
- * @param error - SvelteKit's `error` helper.
15
- * @returns A Promise that resolves with the effect's success value.
16
- * @internal
17
- */
5
+ export { encode_remote_failure } from "./cause-codec.js";
6
+ /** Maps a remote Effect exit into the control flow expected by SvelteKit. */
18
7
  export declare function run_remote_effect<A>(effect: Effect.Effect<A, unknown, unknown>, runtime: {
19
8
  runPromise: (e: Effect.Effect<unknown, unknown, unknown>) => Promise<unknown>;
20
9
  }, invalid: SvelteInvalid, error: SvelteError): Promise<A>;
21
- /**
22
- * Encodes an Effect Cause into a string that the client-side adapter can
23
- * decode back into a typed `RemoteFailure`.
24
- *
25
- * @since 2.0.0
26
- * @param cause - The Effect Cause from a failed execution.
27
- * @returns A devalue-encoded string representing the serialised failure.
28
- * @internal
29
- */
30
- export declare function encode_remote_failure(cause: Cause.Cause<unknown>): string;
31
- /**
32
- * Throws a SvelteKit `invalid` response from a {@link FormError}, calling
33
- * through to the request-scoped `invalid` helper.
34
- *
35
- * @example
36
- * ```ts
37
- * throw_form_error(
38
- * [{ message: "Name is required", path: ["name"] }],
39
- * invalid,
40
- * );
41
- * ```
42
- *
43
- * @since 2.0.0
44
- * @param issues - The list of form validation issues.
45
- * @param invalid - SvelteKit's `invalid` helper bound to the current request.
46
- * @internal
47
- */
10
+ /** Applies a classified remote Cause decision to SvelteKit's server helpers. */
11
+ export declare function throw_remote_cause(cause: Cause.Cause<unknown>, invalid: SvelteInvalid, error: SvelteError): never;
48
12
  export declare function throw_form_error(issues: readonly FormIssue[], invalid: SvelteInvalid): never;
49
- /**
50
- * Remaps SvelteKit's unbranded request-context errors into clear, actionable
51
- * messages.
52
- *
53
- * @example
54
- * ```ts
55
- * try {
56
- * return native_query(handler);
57
- * } catch (err) {
58
- * throw normalize_remote_helper_error(err, "Query");
59
- * }
60
- * ```
61
- *
62
- * @since 2.0.0
63
- * @param err - The error thrown by SvelteKit's native functions.
64
- * @param helper_name - Name of the helper that triggered the error.
65
- * @returns A more descriptive error.
66
- * @internal
67
- */
13
+ /** Rebrands SvelteKit context failures with the remote helper that triggered them. */
68
14
  export declare function normalize_remote_helper_error(err: unknown, helper_name: string): Error;
69
- export {};
@@ -1,179 +1,2 @@
1
- import { h as RemoteHelperError, m as RemoteHelperContextError } from "../chunks/errors-Dcf0MVbq.js";
2
- import { create_serialized_remote_failure_envelope } from "./shared.js";
3
- import { Cause, Effect, Exit } from "effect";
4
- import { isHttpError, isRedirect, isValidationError } from "@sveltejs/kit";
5
- import { stringify } from "devalue";
6
- //#region src/remote/server.ts
7
- const request_event_context_error_start = "Can only read the current request event inside functions invoked during `handle`";
8
- const request_store_context_error = "Could not get the request store.";
9
- /**
10
- * Runs a user-supplied Effect program through a ManagedRuntime, maps its
11
- * exit into the shape expected by SvelteKit, and returns the result or
12
- * throws a SvelteKit-compatible error.
13
- *
14
- * @since 2.0.0
15
- * @param effect - The Effect program to execute.
16
- * @param runtime - The server-side ManagedRuntime.
17
- * @param invalid - SvelteKit's `invalid` helper (bound per-request).
18
- * @param error - SvelteKit's `error` helper.
19
- * @returns A Promise that resolves with the effect's success value.
20
- * @internal
21
- */
22
- async function run_remote_effect(effect, runtime, invalid, error) {
23
- const exit = await runtime.runPromise(Effect.exit(effect));
24
- if (Exit.isSuccess(exit)) return exit.value;
25
- handle_failure(exit.cause, invalid, error);
26
- }
27
- /**
28
- * Inspects the Effect Cause for failures and either throws a form
29
- * validation error (via SvelteKit's `invalid`) or encodes the error
30
- * and throws it via SvelteKit's `error`.
31
- */
32
- function handle_failure(cause, invalid, error) {
33
- const reasons = get_cause_reasons(cause);
34
- /**
35
- * Phase 1 — let SvelteKit's thrown control-flow sentinels escape.
36
- */
37
- for (const reason of reasons) {
38
- if (!Cause.isDieReason(reason)) continue;
39
- const defect = reason.defect;
40
- if (is_sveltekit_control_flow(defect)) throw defect;
41
- }
42
- /**
43
- * Phase 2 — let cancellation escape without becoming a remote failure.
44
- */
45
- if (Cause.hasInterruptsOnly(cause)) throw Cause.squash(cause);
46
- /**
47
- * Phase 3 — preserve typed form validation failures.
48
- */
49
- for (const reason of reasons) if (Cause.isFailReason(reason)) {
50
- const failure = reason.error;
51
- if (typeof failure === "object" && failure !== null && failure._tag === "FormError") invalid(...failure.issues ?? []);
52
- }
53
- error(500, create_serialized_remote_failure_envelope(encode_remote_failure(cause)));
54
- }
55
- /**
56
- * Encodes an Effect Cause into a string that the client-side adapter can
57
- * decode back into a typed `RemoteFailure`.
58
- *
59
- * @since 2.0.0
60
- * @param cause - The Effect Cause from a failed execution.
61
- * @returns A devalue-encoded string representing the serialised failure.
62
- * @internal
63
- */
64
- function encode_remote_failure(cause) {
65
- const reasons = get_cause_reasons(cause);
66
- for (const reason of reasons) if (Cause.isFailReason(reason)) {
67
- const encoded = stringify_failure(to_public_remote_failure(reason.error));
68
- if (encoded !== void 0) return encoded;
69
- }
70
- return stringify_unknown_remote_failure();
71
- }
72
- function get_cause_reasons(cause) {
73
- return cause.reasons ?? [];
74
- }
75
- function is_sveltekit_control_flow(value) {
76
- return isRedirect(value) || isHttpError(value) || isValidationError(value);
77
- }
78
- function stringify_failure(value) {
79
- try {
80
- return stringify(value);
81
- } catch {
82
- return;
83
- }
84
- }
85
- function to_public_remote_failure(value) {
86
- if (!has_public_remote_failure_tag(value)) return create_unknown_remote_failure();
87
- return to_serializable_public_failure(value) ?? create_unknown_remote_failure();
88
- }
89
- function to_serializable_public_failure(value, seen = /* @__PURE__ */ new WeakSet()) {
90
- if (typeof value === "function" || typeof value === "symbol") return;
91
- if (!is_object_like(value)) return value;
92
- if (stringify_failure(value) !== void 0) return value;
93
- if (is_internal_object(value)) return;
94
- if (seen.has(value)) return;
95
- seen.add(value);
96
- const serializable = Array.isArray(value) ? value.map((item) => to_serializable_public_failure(item, seen)) : to_plain_record(value, seen);
97
- seen.delete(value);
98
- return serializable;
99
- }
100
- function to_plain_record(value, seen) {
101
- const descriptors = Object.getOwnPropertyDescriptors(value);
102
- const record = {};
103
- for (const [key, descriptor] of Object.entries(descriptors)) {
104
- if (key === "stack" || !("value" in descriptor)) continue;
105
- record[key] = to_serializable_public_failure(descriptor.value, seen);
106
- }
107
- if (value instanceof Error && !("message" in record)) record.message = value.message;
108
- return record;
109
- }
110
- function is_object_like(value) {
111
- return typeof value === "object" && value !== null;
112
- }
113
- function has_public_remote_failure_tag(value) {
114
- return is_object_like(value) && typeof value._tag === "string";
115
- }
116
- function is_internal_object(value) {
117
- return !Array.isArray(value) && !is_plain_record(value) && !has_public_remote_failure_tag(value);
118
- }
119
- function is_plain_record(value) {
120
- const prototype = Object.getPrototypeOf(value);
121
- return prototype === Object.prototype || prototype === null;
122
- }
123
- function create_unknown_remote_failure() {
124
- return { message: "[UNKNOWN_REMOTE_FAILURE]: Unknown error" };
125
- }
126
- function stringify_unknown_remote_failure() {
127
- return stringify(create_unknown_remote_failure());
128
- }
129
- /**
130
- * Throws a SvelteKit `invalid` response from a {@link FormError}, calling
131
- * through to the request-scoped `invalid` helper.
132
- *
133
- * @example
134
- * ```ts
135
- * throw_form_error(
136
- * [{ message: "Name is required", path: ["name"] }],
137
- * invalid,
138
- * );
139
- * ```
140
- *
141
- * @since 2.0.0
142
- * @param issues - The list of form validation issues.
143
- * @param invalid - SvelteKit's `invalid` helper bound to the current request.
144
- * @internal
145
- */
146
- function throw_form_error(issues, invalid) {
147
- invalid(...issues);
148
- }
149
- /**
150
- * Remaps SvelteKit's unbranded request-context errors into clear, actionable
151
- * messages.
152
- *
153
- * @example
154
- * ```ts
155
- * try {
156
- * return native_query(handler);
157
- * } catch (err) {
158
- * throw normalize_remote_helper_error(err, "Query");
159
- * }
160
- * ```
161
- *
162
- * @since 2.0.0
163
- * @param err - The error thrown by SvelteKit's native functions.
164
- * @param helper_name - Name of the helper that triggered the error.
165
- * @returns A more descriptive error.
166
- * @internal
167
- */
168
- function normalize_remote_helper_error(err, helper_name) {
169
- if (is_sveltekit_remote_context_error(err)) return new RemoteHelperContextError(helper_name);
170
- return err instanceof Error ? err : new RemoteHelperError(err);
171
- }
172
- function is_sveltekit_remote_context_error(err) {
173
- if (!(err instanceof Error)) return false;
174
- return err.message.startsWith(request_event_context_error_start) || err.message === request_store_context_error;
175
- }
176
- //#endregion
177
- export { encode_remote_failure, normalize_remote_helper_error, run_remote_effect, throw_form_error };
178
-
179
- //# sourceMappingURL=server.js.map
1
+ import { a as encode_remote_failure, i as throw_remote_cause, n as run_remote_effect, r as throw_form_error, t as normalize_remote_helper_error } from "../chunks/server-BNrA1I-u.js";
2
+ export { encode_remote_failure, normalize_remote_helper_error, run_remote_effect, throw_form_error, throw_remote_cause };
@@ -1,39 +1,8 @@
1
- /**
2
- * Shared types, markers, and constructors used by both the client-side remote
3
- * adapters and the server-side handler runtime. These types define the error
4
- * protocol that flows across the network boundary.
5
- *
6
- * @since 2.0.0
7
- */
8
- /**
9
- * Well-known marker injected into every serialised remote-failure envelope
10
- * so the client can reliably distinguish runtime errors from domain values.
11
- *
12
- * @example
13
- * ```ts
14
- * if (envelope[EFFECT_REMOTE_ERROR_MARKER] === true) {
15
- * console.log(envelope.encoded);
16
- * }
17
- * ```
18
- *
19
- * @since 2.0.0
20
- * @internal
21
- */
22
- export declare const EFFECT_REMOTE_ERROR_MARKER = "__svelte_effect_remote__";
23
- /**
24
- * Well-known symbol used to attach a payload decoder to a remote function
25
- * so the client's transport layer can decode domain error types.
26
- *
27
- * @example
28
- * ```ts
29
- * Reflect.get(remote_function, REMOTE_ERROR_DECODER);
30
- * ```
31
- *
32
- * @since 2.0.0
33
- * @internal
34
- */
35
- export declare const REMOTE_ERROR_DECODER: unique symbol;
36
- /** Form validation helpers and types. */
1
+ /** Remote error wire protocol shared by client and server adapters. */
2
+ /** Shared marker used to recognize remote errors across package copies. */
3
+ export declare const effect_remote_error_marker = "__svelte_effect_remote__";
4
+ /** Decodes the shared remote-error marker without relying on class identity. */
5
+ export declare const remote_error_decoder: unique symbol;
37
6
  /**
38
7
  * A single field-level or form-level validation issue reported by a
39
8
  * {@link Form} handler.
@@ -75,20 +44,6 @@ export interface FormError<SchemaType = unknown> {
75
44
  /** Phantom type slot for the schema this error was derived from. */
76
45
  readonly _schema?: SchemaType;
77
46
  }
78
- /**
79
- * Creates a {@link FormError} holding the given issues.
80
- *
81
- * @example
82
- * ```ts
83
- * const error = create_form_error([
84
- * { message: "Required.", path: ["email"] },
85
- * ]);
86
- * ```
87
- *
88
- * @since 2.0.0
89
- * @param issues - The validation issues to attach.
90
- * @returns A FormError with the `_tag` set and no schema reference.
91
- */
92
47
  export declare function create_form_error(issues: readonly FormIssue[]): FormError;
93
48
  /**
94
49
  * Type guard that narrows an unknown value to a {@link FormError}.
@@ -105,15 +60,13 @@ export declare function create_form_error(issues: readonly FormIssue[]): FormErr
105
60
  * @returns `true` when the value is a FormError.
106
61
  */
107
62
  export declare function is_form_error(value: unknown): value is FormError;
108
- /** Remote error types shared by client and server helpers. */
109
63
  /**
110
64
  * Union of all wire-level error shapes that a remote function can
111
65
  * surface on its error channel.
112
66
  *
113
67
  * @example
114
68
  * ```ts
115
- * const result = yield* myQuery();
116
- * // error channel is RemoteFailure<DomainError>
69
+ * const result: Effect.Effect<User, RemoteFailure<DomainError>> = myQuery();
117
70
  * ```
118
71
  *
119
72
  * @since 2.0.0
@@ -180,106 +133,14 @@ export interface RemoteTransportError {
180
133
  readonly cause?: unknown;
181
134
  readonly body?: unknown;
182
135
  }
183
- /**
184
- * Wire format for an encoded remote failure. The server wraps domain
185
- * errors in this envelope before serialising them with devalue.
186
- *
187
- * @example
188
- * ```ts
189
- * const envelope: SerializedRemoteFailureEnvelope = {
190
- * __svelte_effect_remote__: true,
191
- * encoded: "[\"DomainError\"]",
192
- * };
193
- * ```
194
- *
195
- * @since 2.0.0
196
- * @internal
197
- */
198
136
  export interface SerializedRemoteFailureEnvelope {
199
137
  readonly __svelte_effect_remote__: true;
200
138
  readonly encoded: string;
201
139
  }
202
- /** Constructors for structured remote error values. */
203
- /**
204
- * Creates a {@link RemoteValidationError} from a list of form issues.
205
- *
206
- * @example
207
- * ```ts
208
- * const error = create_remote_validation_error([
209
- * { message: "Required.", path: ["email"] },
210
- * ]);
211
- * ```
212
- *
213
- * @since 2.0.0
214
- * @param issues - The validation issues reported by the server handler.
215
- * @param body - Optional response body returned alongside the error.
216
- * @param status - HTTP status code (defaults to 400).
217
- * @returns A remote-validation error shape.
218
- * @internal
219
- */
220
140
  export declare function create_remote_validation_error(issues: readonly FormIssue[], body?: unknown, status?: number): RemoteValidationError;
221
- /**
222
- * Creates a {@link RemoteHttpError} for a given HTTP status.
223
- *
224
- * @example
225
- * ```ts
226
- * const error = create_remote_http_error(404, { message: "Not found" });
227
- * ```
228
- *
229
- * @since 2.0.0
230
- * @param status - The HTTP status code.
231
- * @param body - Optional response body.
232
- * @param cause - Optional underlying cause.
233
- * @returns A remote HTTP error shape.
234
- * @internal
235
- */
236
141
  export declare function create_remote_http_error(status: number, body?: unknown, cause?: unknown): RemoteHttpError;
237
- /**
238
- * Creates a {@link RemoteTransportError} for network or decode failures.
239
- *
240
- * @example
241
- * ```ts
242
- * const error = create_remote_transport_error(new Error("Network unavailable"));
243
- * ```
244
- *
245
- * @since 2.0.0
246
- * @param cause - The underlying error that caused the transport failure.
247
- * @param body - Optional response body if one was received.
248
- * @returns A remote transport error shape.
249
- * @internal
250
- */
251
142
  export declare function create_remote_transport_error(cause: unknown, body?: unknown): RemoteTransportError;
252
- /**
253
- * Wraps a devalue-encoded error string inside a
254
- * {@link SerializedRemoteFailureEnvelope}.
255
- *
256
- * @example
257
- * ```ts
258
- * const envelope = create_serialized_remote_failure_envelope(encoded);
259
- * ```
260
- *
261
- * @since 2.0.0
262
- * @param encoded - The devalue-encoded error value.
263
- * @returns The wire-format envelope.
264
- * @internal
265
- */
266
143
  export declare function create_serialized_remote_failure_envelope(encoded: string): SerializedRemoteFailureEnvelope;
267
- /** Type guards for structured remote error values. */
268
- /**
269
- * Checks whether a value is a {@link SerializedRemoteFailureEnvelope}.
270
- *
271
- * @example
272
- * ```ts
273
- * if (is_serialized_remote_failure_envelope(value)) {
274
- * console.log(value.encoded);
275
- * }
276
- * ```
277
- *
278
- * @since 2.0.0
279
- * @param value - The value to check.
280
- * @returns `true` when the value is a serialised failure envelope.
281
- * @internal
282
- */
283
144
  export declare function is_serialized_remote_failure_envelope(value: unknown): value is SerializedRemoteFailureEnvelope;
284
145
  /**
285
146
  * Checks whether a value is a {@link RemoteValidationError}.
@@ -1,54 +1,10 @@
1
1
  import { Schema } from "effect";
2
2
  //#region src/remote/shared.ts
3
- /**
4
- * Shared types, markers, and constructors used by both the client-side remote
5
- * adapters and the server-side handler runtime. These types define the error
6
- * protocol that flows across the network boundary.
7
- *
8
- * @since 2.0.0
9
- */
10
- /**
11
- * Well-known marker injected into every serialised remote-failure envelope
12
- * so the client can reliably distinguish runtime errors from domain values.
13
- *
14
- * @example
15
- * ```ts
16
- * if (envelope[EFFECT_REMOTE_ERROR_MARKER] === true) {
17
- * console.log(envelope.encoded);
18
- * }
19
- * ```
20
- *
21
- * @since 2.0.0
22
- * @internal
23
- */
24
- const EFFECT_REMOTE_ERROR_MARKER = "__svelte_effect_remote__";
25
- /**
26
- * Well-known symbol used to attach a payload decoder to a remote function
27
- * so the client's transport layer can decode domain error types.
28
- *
29
- * @example
30
- * ```ts
31
- * Reflect.get(remote_function, REMOTE_ERROR_DECODER);
32
- * ```
33
- *
34
- * @since 2.0.0
35
- * @internal
36
- */
37
- const REMOTE_ERROR_DECODER = Symbol.for("svelte-effect-runtime/remote-error-decoder");
38
- /**
39
- * Creates a {@link FormError} holding the given issues.
40
- *
41
- * @example
42
- * ```ts
43
- * const error = create_form_error([
44
- * { message: "Required.", path: ["email"] },
45
- * ]);
46
- * ```
47
- *
48
- * @since 2.0.0
49
- * @param issues - The validation issues to attach.
50
- * @returns A FormError with the `_tag` set and no schema reference.
51
- */
3
+ /** Remote error wire protocol shared by client and server adapters. */
4
+ /** Shared marker used to recognize remote errors across package copies. */
5
+ const effect_remote_error_marker = "__svelte_effect_remote__";
6
+ /** Decodes the shared remote-error marker without relying on class identity. */
7
+ const remote_error_decoder = Symbol.for("svelte-effect-runtime/remote-error-decoder");
52
8
  function create_form_error(issues) {
53
9
  return {
54
10
  _tag: "FormError",
@@ -107,24 +63,6 @@ const is_remote_http_error_value = Schema.is(RemoteHttpErrorSchema);
107
63
  const is_remote_transport_error_value = Schema.is(RemoteTransportErrorSchema);
108
64
  const is_remote_validation_error_value = Schema.is(RemoteValidationErrorSchema);
109
65
  const is_serialized_remote_failure_envelope_value = Schema.is(SerializedRemoteFailureEnvelopeSchema);
110
- /** Constructors for structured remote error values. */
111
- /**
112
- * Creates a {@link RemoteValidationError} from a list of form issues.
113
- *
114
- * @example
115
- * ```ts
116
- * const error = create_remote_validation_error([
117
- * { message: "Required.", path: ["email"] },
118
- * ]);
119
- * ```
120
- *
121
- * @since 2.0.0
122
- * @param issues - The validation issues reported by the server handler.
123
- * @param body - Optional response body returned alongside the error.
124
- * @param status - HTTP status code (defaults to 400).
125
- * @returns A remote-validation error shape.
126
- * @internal
127
- */
128
66
  function create_remote_validation_error(issues, body, status = 400) {
129
67
  return {
130
68
  _tag: "RemoteValidationError",
@@ -133,21 +71,6 @@ function create_remote_validation_error(issues, body, status = 400) {
133
71
  status
134
72
  };
135
73
  }
136
- /**
137
- * Creates a {@link RemoteHttpError} for a given HTTP status.
138
- *
139
- * @example
140
- * ```ts
141
- * const error = create_remote_http_error(404, { message: "Not found" });
142
- * ```
143
- *
144
- * @since 2.0.0
145
- * @param status - The HTTP status code.
146
- * @param body - Optional response body.
147
- * @param cause - Optional underlying cause.
148
- * @returns A remote HTTP error shape.
149
- * @internal
150
- */
151
74
  function create_remote_http_error(status, body, cause) {
152
75
  return {
153
76
  _tag: "RemoteHttpError",
@@ -156,20 +79,6 @@ function create_remote_http_error(status, body, cause) {
156
79
  cause
157
80
  };
158
81
  }
159
- /**
160
- * Creates a {@link RemoteTransportError} for network or decode failures.
161
- *
162
- * @example
163
- * ```ts
164
- * const error = create_remote_transport_error(new Error("Network unavailable"));
165
- * ```
166
- *
167
- * @since 2.0.0
168
- * @param cause - The underlying error that caused the transport failure.
169
- * @param body - Optional response body if one was received.
170
- * @returns A remote transport error shape.
171
- * @internal
172
- */
173
82
  function create_remote_transport_error(cause, body) {
174
83
  return {
175
84
  _tag: "RemoteTransportError",
@@ -177,42 +86,12 @@ function create_remote_transport_error(cause, body) {
177
86
  body
178
87
  };
179
88
  }
180
- /**
181
- * Wraps a devalue-encoded error string inside a
182
- * {@link SerializedRemoteFailureEnvelope}.
183
- *
184
- * @example
185
- * ```ts
186
- * const envelope = create_serialized_remote_failure_envelope(encoded);
187
- * ```
188
- *
189
- * @since 2.0.0
190
- * @param encoded - The devalue-encoded error value.
191
- * @returns The wire-format envelope.
192
- * @internal
193
- */
194
89
  function create_serialized_remote_failure_envelope(encoded) {
195
90
  return {
196
91
  __svelte_effect_remote__: true,
197
92
  encoded
198
93
  };
199
94
  }
200
- /** Type guards for structured remote error values. */
201
- /**
202
- * Checks whether a value is a {@link SerializedRemoteFailureEnvelope}.
203
- *
204
- * @example
205
- * ```ts
206
- * if (is_serialized_remote_failure_envelope(value)) {
207
- * console.log(value.encoded);
208
- * }
209
- * ```
210
- *
211
- * @since 2.0.0
212
- * @param value - The value to check.
213
- * @returns `true` when the value is a serialised failure envelope.
214
- * @internal
215
- */
216
95
  function is_serialized_remote_failure_envelope(value) {
217
96
  return is_serialized_remote_failure_envelope_value(value);
218
97
  }
@@ -268,6 +147,6 @@ function is_remote_transport_error(value) {
268
147
  return is_remote_transport_error_value(value);
269
148
  }
270
149
  //#endregion
271
- export { EFFECT_REMOTE_ERROR_MARKER, REMOTE_ERROR_DECODER, create_form_error, create_remote_http_error, create_remote_transport_error, create_remote_validation_error, create_serialized_remote_failure_envelope, is_form_error, is_remote_http_error, is_remote_transport_error, is_remote_validation_error, is_serialized_remote_failure_envelope };
150
+ export { create_form_error, create_remote_http_error, create_remote_transport_error, create_remote_validation_error, create_serialized_remote_failure_envelope, effect_remote_error_marker, is_form_error, is_remote_http_error, is_remote_transport_error, is_remote_validation_error, is_serialized_remote_failure_envelope, remote_error_decoder };
272
151
 
273
152
  //# sourceMappingURL=shared.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/remote/shared.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\n/**\n * Shared types, markers, and constructors used by both the client-side remote\n * adapters and the server-side handler runtime. These types define the error\n * protocol that flows across the network boundary.\n *\n * @since 2.0.0\n */\n\n/**\n * Well-known marker injected into every serialised remote-failure envelope\n * so the client can reliably distinguish runtime errors from domain values.\n *\n * @example\n * ```ts\n * if (envelope[EFFECT_REMOTE_ERROR_MARKER] === true) {\n * console.log(envelope.encoded);\n * }\n * ```\n *\n * @since 2.0.0\n * @internal\n */\nexport const EFFECT_REMOTE_ERROR_MARKER = \"__svelte_effect_remote__\";\n\n/**\n * Well-known symbol used to attach a payload decoder to a remote function\n * so the client's transport layer can decode domain error types.\n *\n * @example\n * ```ts\n * Reflect.get(remote_function, REMOTE_ERROR_DECODER);\n * ```\n *\n * @since 2.0.0\n * @internal\n */\nexport const REMOTE_ERROR_DECODER = Symbol.for(\"svelte-effect-runtime/remote-error-decoder\");\n\n/** Form validation helpers and types. */\n\n/**\n * A single field-level or form-level validation issue reported by a\n * {@link Form} handler.\n *\n * @example\n * ```ts\n * const issue: FormIssue = {\n * message: \"Use an email address.\",\n * path: [\"email\"],\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface FormIssue {\n\t/** Human-readable validation message. */\n\tmessage: string;\n\t/** Path to the offending field as an array of string-or-number keys. */\n\tpath: (string | number)[];\n}\n\n/**\n * Error subtype thrown by {@link Form} handlers to signal validation\n * failures. The `issues` array is forwarded to SvelteKit's `invalid()`\n * helper on the server and surfaced as `FormError` on the client.\n *\n * @example\n * ```ts\n * const error: FormError = {\n * _tag: \"FormError\",\n * issues: [{ message: \"Required.\", path: [\"email\"] }],\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface FormError<SchemaType = unknown> {\n\treadonly _tag: \"FormError\";\n\treadonly issues: readonly FormIssue[];\n\t/** Phantom type slot for the schema this error was derived from. */\n\treadonly _schema?: SchemaType;\n}\n\n/**\n * Creates a {@link FormError} holding the given issues.\n *\n * @example\n * ```ts\n * const error = create_form_error([\n * { message: \"Required.\", path: [\"email\"] },\n * ]);\n * ```\n *\n * @since 2.0.0\n * @param issues - The validation issues to attach.\n * @returns A FormError with the `_tag` set and no schema reference.\n */\nexport function create_form_error(issues: readonly FormIssue[]): FormError {\n\treturn { _tag: \"FormError\", issues };\n}\n\n/**\n * Type guard that narrows an unknown value to a {@link FormError}.\n *\n * @example\n * ```ts\n * if (is_form_error(error)) {\n * console.log(error.issues);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a FormError.\n */\nexport function is_form_error(value: unknown): value is FormError {\n\treturn is_form_error_value(value);\n}\n\n/** Remote error types shared by client and server helpers. */\n\n/**\n * Union of all wire-level error shapes that a remote function can\n * surface on its error channel.\n *\n * @example\n * ```ts\n * const result = yield* myQuery();\n * // error channel is RemoteFailure<DomainError>\n * ```\n *\n * @since 2.0.0\n */\nexport type RemoteFailure<ErrorType> =\n\t| ErrorType\n\t| RemoteValidationError\n\t| RemoteHttpError\n\t| RemoteTransportError;\n\n/**\n * Validation errors that originate from a server-side {@link Form}\n * handler calling `invalid()` (SvelteKit's `fail`).\n *\n * @example\n * ```ts\n * const error: RemoteValidationError = {\n * _tag: \"RemoteValidationError\",\n * status: 400,\n * issues: [{ message: \"Required.\", path: [\"email\"] }],\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface RemoteValidationError {\n\treadonly _tag: \"RemoteValidationError\";\n\treadonly issues?: readonly FormIssue[];\n\treadonly body?: unknown;\n\treadonly status: number;\n}\n\n/**\n * HTTP-level errors with a status code and optional response body. Raised\n * when the server explicitly calls SvelteKit's `error(status, body)`.\n *\n * @example\n * ```ts\n * const error: RemoteHttpError = {\n * _tag: \"RemoteHttpError\",\n * status: 404,\n * body: { message: \"Not found\" },\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface RemoteHttpError {\n\treadonly _tag: \"RemoteHttpError\";\n\treadonly status: number;\n\treadonly body?: unknown;\n\treadonly cause?: unknown;\n}\n\n/**\n * Transport-level errors raised by the client adapter when the network\n * request fails or the response cannot be decoded.\n *\n * @example\n * ```ts\n * const error: RemoteTransportError = {\n * _tag: \"RemoteTransportError\",\n * cause: new Error(\"Network unavailable\"),\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface RemoteTransportError {\n\treadonly _tag: \"RemoteTransportError\";\n\treadonly cause?: unknown;\n\treadonly body?: unknown;\n}\n\n/**\n * Wire format for an encoded remote failure. The server wraps domain\n * errors in this envelope before serialising them with devalue.\n *\n * @example\n * ```ts\n * const envelope: SerializedRemoteFailureEnvelope = {\n * __svelte_effect_remote__: true,\n * encoded: \"[\\\"DomainError\\\"]\",\n * };\n * ```\n *\n * @since 2.0.0\n * @internal\n */\nexport interface SerializedRemoteFailureEnvelope {\n\treadonly __svelte_effect_remote__: true;\n\treadonly encoded: string;\n}\n\nconst FormIssuePathSegmentSchema = Schema.Union([Schema.String, Schema.Number]);\n\nconst FormIssueSchema = Schema.Struct({\n\tmessage: Schema.String,\n\tpath: Schema.Array(FormIssuePathSegmentSchema),\n});\n\nconst FormErrorSchema = Schema.Struct({\n\t_tag: Schema.Literal(\"FormError\"),\n\tissues: Schema.Array(FormIssueSchema),\n});\n\nconst SerializedRemoteFailureEnvelopeSchema = Schema.Struct({\n\t__svelte_effect_remote__: Schema.Literal(true),\n\tencoded: Schema.String,\n});\n\nconst RemoteValidationErrorSchema = Schema.Struct({\n\t_tag: Schema.Literal(\"RemoteValidationError\"),\n\tbody: Schema.optional(Schema.Unknown),\n\tissues: Schema.optional(Schema.Array(FormIssueSchema)),\n\tstatus: Schema.Number,\n});\n\nconst RemoteHttpErrorSchema = Schema.Struct({\n\t_tag: Schema.Literal(\"RemoteHttpError\"),\n\tbody: Schema.optional(Schema.Unknown),\n\tcause: Schema.optional(Schema.Unknown),\n\tstatus: Schema.Number,\n});\n\nconst RemoteTransportErrorSchema = Schema.Struct({\n\t_tag: Schema.Literal(\"RemoteTransportError\"),\n\tbody: Schema.optional(Schema.Unknown),\n\tcause: Schema.optional(Schema.Unknown),\n});\n\nconst is_form_error_value = Schema.is(FormErrorSchema);\nconst is_remote_http_error_value = Schema.is(RemoteHttpErrorSchema);\nconst is_remote_transport_error_value = Schema.is(RemoteTransportErrorSchema);\nconst is_remote_validation_error_value = Schema.is(RemoteValidationErrorSchema);\nconst is_serialized_remote_failure_envelope_value = Schema.is(\n\tSerializedRemoteFailureEnvelopeSchema,\n);\n\n/** Constructors for structured remote error values. */\n\n/**\n * Creates a {@link RemoteValidationError} from a list of form issues.\n *\n * @example\n * ```ts\n * const error = create_remote_validation_error([\n * { message: \"Required.\", path: [\"email\"] },\n * ]);\n * ```\n *\n * @since 2.0.0\n * @param issues - The validation issues reported by the server handler.\n * @param body - Optional response body returned alongside the error.\n * @param status - HTTP status code (defaults to 400).\n * @returns A remote-validation error shape.\n * @internal\n */\nexport function create_remote_validation_error(\n\tissues: readonly FormIssue[],\n\tbody?: unknown,\n\tstatus = 400,\n): RemoteValidationError {\n\treturn { _tag: \"RemoteValidationError\", issues, body, status };\n}\n\n/**\n * Creates a {@link RemoteHttpError} for a given HTTP status.\n *\n * @example\n * ```ts\n * const error = create_remote_http_error(404, { message: \"Not found\" });\n * ```\n *\n * @since 2.0.0\n * @param status - The HTTP status code.\n * @param body - Optional response body.\n * @param cause - Optional underlying cause.\n * @returns A remote HTTP error shape.\n * @internal\n */\nexport function create_remote_http_error(\n\tstatus: number,\n\tbody?: unknown,\n\tcause?: unknown,\n): RemoteHttpError {\n\treturn { _tag: \"RemoteHttpError\", status, body, cause };\n}\n\n/**\n * Creates a {@link RemoteTransportError} for network or decode failures.\n *\n * @example\n * ```ts\n * const error = create_remote_transport_error(new Error(\"Network unavailable\"));\n * ```\n *\n * @since 2.0.0\n * @param cause - The underlying error that caused the transport failure.\n * @param body - Optional response body if one was received.\n * @returns A remote transport error shape.\n * @internal\n */\nexport function create_remote_transport_error(\n\tcause: unknown,\n\tbody?: unknown,\n): RemoteTransportError {\n\treturn { _tag: \"RemoteTransportError\", cause, body };\n}\n\n/**\n * Wraps a devalue-encoded error string inside a\n * {@link SerializedRemoteFailureEnvelope}.\n *\n * @example\n * ```ts\n * const envelope = create_serialized_remote_failure_envelope(encoded);\n * ```\n *\n * @since 2.0.0\n * @param encoded - The devalue-encoded error value.\n * @returns The wire-format envelope.\n * @internal\n */\nexport function create_serialized_remote_failure_envelope(\n\tencoded: string,\n): SerializedRemoteFailureEnvelope {\n\treturn { __svelte_effect_remote__: true, encoded };\n}\n\n/** Type guards for structured remote error values. */\n\n/**\n * Checks whether a value is a {@link SerializedRemoteFailureEnvelope}.\n *\n * @example\n * ```ts\n * if (is_serialized_remote_failure_envelope(value)) {\n * console.log(value.encoded);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a serialised failure envelope.\n * @internal\n */\nexport function is_serialized_remote_failure_envelope(\n\tvalue: unknown,\n): value is SerializedRemoteFailureEnvelope {\n\treturn is_serialized_remote_failure_envelope_value(value);\n}\n\n/**\n * Checks whether a value is a {@link RemoteValidationError}.\n *\n * @example\n * ```ts\n * if (is_remote_validation_error(error)) {\n * console.log(error.issues);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a remote validation error.\n */\nexport function is_remote_validation_error(value: unknown): value is RemoteValidationError {\n\treturn is_remote_validation_error_value(value);\n}\n\n/**\n * Checks whether a value is a {@link RemoteHttpError}.\n *\n * @example\n * ```ts\n * if (is_remote_http_error(error)) {\n * console.log(error.status);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a remote HTTP error.\n */\nexport function is_remote_http_error(value: unknown): value is RemoteHttpError {\n\treturn is_remote_http_error_value(value);\n}\n\n/**\n * Checks whether a value is a {@link RemoteTransportError}.\n *\n * @example\n * ```ts\n * if (is_remote_transport_error(error)) {\n * console.error(error.cause);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a remote transport error.\n */\nexport function is_remote_transport_error(value: unknown): value is RemoteTransportError {\n\treturn is_remote_transport_error_value(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,6BAA6B;;;;;;;;;;;;;AAc1C,MAAa,uBAAuB,OAAO,IAAI,4CAA4C;;;;;;;;;;;;;;;AA6D3F,SAAgB,kBAAkB,QAAyC;CAC1E,OAAO;EAAE,MAAM;EAAa;CAAO;AACpC;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,OAAoC;CACjE,OAAO,oBAAoB,KAAK;AACjC;AA0GA,MAAM,6BAA6B,OAAO,MAAM,CAAC,OAAO,QAAQ,OAAO,MAAM,CAAC;AAE9E,MAAM,kBAAkB,OAAO,OAAO;CACrC,SAAS,OAAO;CAChB,MAAM,OAAO,MAAM,0BAA0B;AAC9C,CAAC;AAED,MAAM,kBAAkB,OAAO,OAAO;CACrC,MAAM,OAAO,QAAQ,WAAW;CAChC,QAAQ,OAAO,MAAM,eAAe;AACrC,CAAC;AAED,MAAM,wCAAwC,OAAO,OAAO;CAC3D,0BAA0B,OAAO,QAAQ,IAAI;CAC7C,SAAS,OAAO;AACjB,CAAC;AAED,MAAM,8BAA8B,OAAO,OAAO;CACjD,MAAM,OAAO,QAAQ,uBAAuB;CAC5C,MAAM,OAAO,SAAS,OAAO,OAAO;CACpC,QAAQ,OAAO,SAAS,OAAO,MAAM,eAAe,CAAC;CACrD,QAAQ,OAAO;AAChB,CAAC;AAED,MAAM,wBAAwB,OAAO,OAAO;CAC3C,MAAM,OAAO,QAAQ,iBAAiB;CACtC,MAAM,OAAO,SAAS,OAAO,OAAO;CACpC,OAAO,OAAO,SAAS,OAAO,OAAO;CACrC,QAAQ,OAAO;AAChB,CAAC;AAED,MAAM,6BAA6B,OAAO,OAAO;CAChD,MAAM,OAAO,QAAQ,sBAAsB;CAC3C,MAAM,OAAO,SAAS,OAAO,OAAO;CACpC,OAAO,OAAO,SAAS,OAAO,OAAO;AACtC,CAAC;AAED,MAAM,sBAAsB,OAAO,GAAG,eAAe;AACrD,MAAM,6BAA6B,OAAO,GAAG,qBAAqB;AAClE,MAAM,kCAAkC,OAAO,GAAG,0BAA0B;AAC5E,MAAM,mCAAmC,OAAO,GAAG,2BAA2B;AAC9E,MAAM,8CAA8C,OAAO,GAC1D,qCACD;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,+BACf,QACA,MACA,SAAS,KACe;CACxB,OAAO;EAAE,MAAM;EAAyB;EAAQ;EAAM;CAAO;AAC9D;;;;;;;;;;;;;;;;AAiBA,SAAgB,yBACf,QACA,MACA,OACkB;CAClB,OAAO;EAAE,MAAM;EAAmB;EAAQ;EAAM;CAAM;AACvD;;;;;;;;;;;;;;;AAgBA,SAAgB,8BACf,OACA,MACuB;CACvB,OAAO;EAAE,MAAM;EAAwB;EAAO;CAAK;AACpD;;;;;;;;;;;;;;;AAgBA,SAAgB,0CACf,SACkC;CAClC,OAAO;EAAE,0BAA0B;EAAM;CAAQ;AAClD;;;;;;;;;;;;;;;;;AAmBA,SAAgB,sCACf,OAC2C;CAC3C,OAAO,4CAA4C,KAAK;AACzD;;;;;;;;;;;;;;;AAgBA,SAAgB,2BAA2B,OAAgD;CAC1F,OAAO,iCAAiC,KAAK;AAC9C;;;;;;;;;;;;;;;AAgBA,SAAgB,qBAAqB,OAA0C;CAC9E,OAAO,2BAA2B,KAAK;AACxC;;;;;;;;;;;;;;;AAgBA,SAAgB,0BAA0B,OAA+C;CACxF,OAAO,gCAAgC,KAAK;AAC7C"}
1
+ {"version":3,"file":"shared.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/remote/shared.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\n/** Remote error wire protocol shared by client and server adapters. */\n\n/** Shared marker used to recognize remote errors across package copies. */\nexport const effect_remote_error_marker = \"__svelte_effect_remote__\";\n\n/** Decodes the shared remote-error marker without relying on class identity. */\nexport const remote_error_decoder = Symbol.for(\"svelte-effect-runtime/remote-error-decoder\");\n\n/**\n * A single field-level or form-level validation issue reported by a\n * {@link Form} handler.\n *\n * @example\n * ```ts\n * const issue: FormIssue = {\n * message: \"Use an email address.\",\n * path: [\"email\"],\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface FormIssue {\n\t/** Human-readable validation message. */\n\tmessage: string;\n\t/** Path to the offending field as an array of string-or-number keys. */\n\tpath: (string | number)[];\n}\n\n/**\n * Error subtype thrown by {@link Form} handlers to signal validation\n * failures. The `issues` array is forwarded to SvelteKit's `invalid()`\n * helper on the server and surfaced as `FormError` on the client.\n *\n * @example\n * ```ts\n * const error: FormError = {\n * _tag: \"FormError\",\n * issues: [{ message: \"Required.\", path: [\"email\"] }],\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface FormError<SchemaType = unknown> {\n\treadonly _tag: \"FormError\";\n\treadonly issues: readonly FormIssue[];\n\t/** Phantom type slot for the schema this error was derived from. */\n\treadonly _schema?: SchemaType;\n}\n\nexport function create_form_error(issues: readonly FormIssue[]): FormError {\n\treturn { _tag: \"FormError\", issues };\n}\n\n/**\n * Type guard that narrows an unknown value to a {@link FormError}.\n *\n * @example\n * ```ts\n * if (is_form_error(error)) {\n * console.log(error.issues);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a FormError.\n */\nexport function is_form_error(value: unknown): value is FormError {\n\treturn is_form_error_value(value);\n}\n\n/**\n * Union of all wire-level error shapes that a remote function can\n * surface on its error channel.\n *\n * @example\n * ```ts\n * const result: Effect.Effect<User, RemoteFailure<DomainError>> = myQuery();\n * ```\n *\n * @since 2.0.0\n */\nexport type RemoteFailure<ErrorType> =\n\t| ErrorType\n\t| RemoteValidationError\n\t| RemoteHttpError\n\t| RemoteTransportError;\n\n/**\n * Validation errors that originate from a server-side {@link Form}\n * handler calling `invalid()` (SvelteKit's `fail`).\n *\n * @example\n * ```ts\n * const error: RemoteValidationError = {\n * _tag: \"RemoteValidationError\",\n * status: 400,\n * issues: [{ message: \"Required.\", path: [\"email\"] }],\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface RemoteValidationError {\n\treadonly _tag: \"RemoteValidationError\";\n\treadonly issues?: readonly FormIssue[];\n\treadonly body?: unknown;\n\treadonly status: number;\n}\n\n/**\n * HTTP-level errors with a status code and optional response body. Raised\n * when the server explicitly calls SvelteKit's `error(status, body)`.\n *\n * @example\n * ```ts\n * const error: RemoteHttpError = {\n * _tag: \"RemoteHttpError\",\n * status: 404,\n * body: { message: \"Not found\" },\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface RemoteHttpError {\n\treadonly _tag: \"RemoteHttpError\";\n\treadonly status: number;\n\treadonly body?: unknown;\n\treadonly cause?: unknown;\n}\n\n/**\n * Transport-level errors raised by the client adapter when the network\n * request fails or the response cannot be decoded.\n *\n * @example\n * ```ts\n * const error: RemoteTransportError = {\n * _tag: \"RemoteTransportError\",\n * cause: new Error(\"Network unavailable\"),\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface RemoteTransportError {\n\treadonly _tag: \"RemoteTransportError\";\n\treadonly cause?: unknown;\n\treadonly body?: unknown;\n}\n\nexport interface SerializedRemoteFailureEnvelope {\n\treadonly __svelte_effect_remote__: true;\n\treadonly encoded: string;\n}\n\nconst FormIssuePathSegmentSchema = Schema.Union([Schema.String, Schema.Number]);\n\nconst FormIssueSchema = Schema.Struct({\n\tmessage: Schema.String,\n\tpath: Schema.Array(FormIssuePathSegmentSchema),\n});\n\nconst FormErrorSchema = Schema.Struct({\n\t_tag: Schema.Literal(\"FormError\"),\n\tissues: Schema.Array(FormIssueSchema),\n});\n\nconst SerializedRemoteFailureEnvelopeSchema = Schema.Struct({\n\t__svelte_effect_remote__: Schema.Literal(true),\n\tencoded: Schema.String,\n});\n\nconst RemoteValidationErrorSchema = Schema.Struct({\n\t_tag: Schema.Literal(\"RemoteValidationError\"),\n\tbody: Schema.optional(Schema.Unknown),\n\tissues: Schema.optional(Schema.Array(FormIssueSchema)),\n\tstatus: Schema.Number,\n});\n\nconst RemoteHttpErrorSchema = Schema.Struct({\n\t_tag: Schema.Literal(\"RemoteHttpError\"),\n\tbody: Schema.optional(Schema.Unknown),\n\tcause: Schema.optional(Schema.Unknown),\n\tstatus: Schema.Number,\n});\n\nconst RemoteTransportErrorSchema = Schema.Struct({\n\t_tag: Schema.Literal(\"RemoteTransportError\"),\n\tbody: Schema.optional(Schema.Unknown),\n\tcause: Schema.optional(Schema.Unknown),\n});\n\nconst is_form_error_value = Schema.is(FormErrorSchema);\nconst is_remote_http_error_value = Schema.is(RemoteHttpErrorSchema);\nconst is_remote_transport_error_value = Schema.is(RemoteTransportErrorSchema);\nconst is_remote_validation_error_value = Schema.is(RemoteValidationErrorSchema);\nconst is_serialized_remote_failure_envelope_value = Schema.is(\n\tSerializedRemoteFailureEnvelopeSchema,\n);\n\nexport function create_remote_validation_error(\n\tissues: readonly FormIssue[],\n\tbody?: unknown,\n\tstatus = 400,\n): RemoteValidationError {\n\treturn { _tag: \"RemoteValidationError\", issues, body, status };\n}\n\nexport function create_remote_http_error(\n\tstatus: number,\n\tbody?: unknown,\n\tcause?: unknown,\n): RemoteHttpError {\n\treturn { _tag: \"RemoteHttpError\", status, body, cause };\n}\n\nexport function create_remote_transport_error(\n\tcause: unknown,\n\tbody?: unknown,\n): RemoteTransportError {\n\treturn { _tag: \"RemoteTransportError\", cause, body };\n}\n\nexport function create_serialized_remote_failure_envelope(\n\tencoded: string,\n): SerializedRemoteFailureEnvelope {\n\treturn { __svelte_effect_remote__: true, encoded };\n}\n\nexport function is_serialized_remote_failure_envelope(\n\tvalue: unknown,\n): value is SerializedRemoteFailureEnvelope {\n\treturn is_serialized_remote_failure_envelope_value(value);\n}\n\n/**\n * Checks whether a value is a {@link RemoteValidationError}.\n *\n * @example\n * ```ts\n * if (is_remote_validation_error(error)) {\n * console.log(error.issues);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a remote validation error.\n */\nexport function is_remote_validation_error(value: unknown): value is RemoteValidationError {\n\treturn is_remote_validation_error_value(value);\n}\n\n/**\n * Checks whether a value is a {@link RemoteHttpError}.\n *\n * @example\n * ```ts\n * if (is_remote_http_error(error)) {\n * console.log(error.status);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a remote HTTP error.\n */\nexport function is_remote_http_error(value: unknown): value is RemoteHttpError {\n\treturn is_remote_http_error_value(value);\n}\n\n/**\n * Checks whether a value is a {@link RemoteTransportError}.\n *\n * @example\n * ```ts\n * if (is_remote_transport_error(error)) {\n * console.error(error.cause);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a remote transport error.\n */\nexport function is_remote_transport_error(value: unknown): value is RemoteTransportError {\n\treturn is_remote_transport_error_value(value);\n}\n"],"mappings":";;;;AAKA,MAAa,6BAA6B;;AAG1C,MAAa,uBAAuB,OAAO,IAAI,4CAA4C;AA6C3F,SAAgB,kBAAkB,QAAyC;CAC1E,OAAO;EAAE,MAAM;EAAa;CAAO;AACpC;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,OAAoC;CACjE,OAAO,oBAAoB,KAAK;AACjC;AAwFA,MAAM,6BAA6B,OAAO,MAAM,CAAC,OAAO,QAAQ,OAAO,MAAM,CAAC;AAE9E,MAAM,kBAAkB,OAAO,OAAO;CACrC,SAAS,OAAO;CAChB,MAAM,OAAO,MAAM,0BAA0B;AAC9C,CAAC;AAED,MAAM,kBAAkB,OAAO,OAAO;CACrC,MAAM,OAAO,QAAQ,WAAW;CAChC,QAAQ,OAAO,MAAM,eAAe;AACrC,CAAC;AAED,MAAM,wCAAwC,OAAO,OAAO;CAC3D,0BAA0B,OAAO,QAAQ,IAAI;CAC7C,SAAS,OAAO;AACjB,CAAC;AAED,MAAM,8BAA8B,OAAO,OAAO;CACjD,MAAM,OAAO,QAAQ,uBAAuB;CAC5C,MAAM,OAAO,SAAS,OAAO,OAAO;CACpC,QAAQ,OAAO,SAAS,OAAO,MAAM,eAAe,CAAC;CACrD,QAAQ,OAAO;AAChB,CAAC;AAED,MAAM,wBAAwB,OAAO,OAAO;CAC3C,MAAM,OAAO,QAAQ,iBAAiB;CACtC,MAAM,OAAO,SAAS,OAAO,OAAO;CACpC,OAAO,OAAO,SAAS,OAAO,OAAO;CACrC,QAAQ,OAAO;AAChB,CAAC;AAED,MAAM,6BAA6B,OAAO,OAAO;CAChD,MAAM,OAAO,QAAQ,sBAAsB;CAC3C,MAAM,OAAO,SAAS,OAAO,OAAO;CACpC,OAAO,OAAO,SAAS,OAAO,OAAO;AACtC,CAAC;AAED,MAAM,sBAAsB,OAAO,GAAG,eAAe;AACrD,MAAM,6BAA6B,OAAO,GAAG,qBAAqB;AAClE,MAAM,kCAAkC,OAAO,GAAG,0BAA0B;AAC5E,MAAM,mCAAmC,OAAO,GAAG,2BAA2B;AAC9E,MAAM,8CAA8C,OAAO,GAC1D,qCACD;AAEA,SAAgB,+BACf,QACA,MACA,SAAS,KACe;CACxB,OAAO;EAAE,MAAM;EAAyB;EAAQ;EAAM;CAAO;AAC9D;AAEA,SAAgB,yBACf,QACA,MACA,OACkB;CAClB,OAAO;EAAE,MAAM;EAAmB;EAAQ;EAAM;CAAM;AACvD;AAEA,SAAgB,8BACf,OACA,MACuB;CACvB,OAAO;EAAE,MAAM;EAAwB;EAAO;CAAK;AACpD;AAEA,SAAgB,0CACf,SACkC;CAClC,OAAO;EAAE,0BAA0B;EAAM;CAAQ;AAClD;AAEA,SAAgB,sCACf,OAC2C;CAC3C,OAAO,4CAA4C,KAAK;AACzD;;;;;;;;;;;;;;;AAgBA,SAAgB,2BAA2B,OAAgD;CAC1F,OAAO,iCAAiC,KAAK;AAC9C;;;;;;;;;;;;;;;AAgBA,SAAgB,qBAAqB,OAA0C;CAC9E,OAAO,2BAA2B,KAAK;AACxC;;;;;;;;;;;;;;;AAgBA,SAAgB,0BAA0B,OAA+C;CACxF,OAAO,gCAAgC,KAAK;AAC7C"}