svelte-effect-runtime 1.2.4 → 1.3.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 (73) hide show
  1. package/dist/chunks/client-DkW4e4dD.js +199 -0
  2. package/dist/chunks/client-DkW4e4dD.js.map +1 -0
  3. package/dist/chunks/effect-CL8GJs8A.js +51 -0
  4. package/dist/chunks/effect-CL8GJs8A.js.map +1 -0
  5. package/dist/chunks/effect-compat-BhW0YPIs.js +103 -0
  6. package/dist/chunks/effect-compat-BhW0YPIs.js.map +1 -0
  7. package/dist/chunks/{magic-string.es-5gRBdMgP.js → magic-string.es-BnGH-5YR.js} +1 -1
  8. package/dist/chunks/{magic-string.es-5gRBdMgP.js.map → magic-string.es-BnGH-5YR.js.map} +1 -1
  9. package/dist/chunks/{markup-Ccw42uCl.js → markup-BpSHnnYD.js} +4 -4
  10. package/dist/chunks/{markup-Ccw42uCl.js.map → markup-BpSHnnYD.js.map} +1 -1
  11. package/dist/chunks/preprocess-CtLrnJcK.js +44 -0
  12. package/dist/chunks/preprocess-CtLrnJcK.js.map +1 -0
  13. package/dist/chunks/server-DR-6LMdP.js +629 -0
  14. package/dist/chunks/server-DR-6LMdP.js.map +1 -0
  15. package/dist/chunks/v3-p8V3Drpp.js +1 -0
  16. package/dist/chunks/v4-DIhYCbb_.js +1 -0
  17. package/dist/chunks/vite-DqjXRZd4.js +143 -0
  18. package/dist/chunks/vite-DqjXRZd4.js.map +1 -0
  19. package/dist/client.d.ts +1 -64
  20. package/dist/client.js +2 -170
  21. package/dist/effect.d.ts +1 -7
  22. package/dist/effect.js +1 -27
  23. package/dist/internal/effect-compat.d.ts +21 -0
  24. package/dist/internal/markup.d.ts +1 -1
  25. package/dist/internal/markup.js +1 -1
  26. package/dist/internal/remote-client.js +30 -6
  27. package/dist/internal/remote-client.js.map +1 -1
  28. package/dist/internal/transform.d.ts +1 -1
  29. package/dist/internal/transform.js +3 -4
  30. package/dist/internal/transform.js.map +1 -1
  31. package/dist/language-server.d.ts +9 -3
  32. package/dist/language-server.js +3 -3
  33. package/dist/mod.d.ts +1 -6
  34. package/dist/mod.js +3 -5
  35. package/dist/preprocess.d.ts +23 -6
  36. package/dist/preprocess.js +10 -31
  37. package/dist/preprocess.js.map +1 -1
  38. package/dist/root-node.d.ts +1 -14
  39. package/dist/root-node.js +63 -8
  40. package/dist/root-node.js.map +1 -0
  41. package/dist/server.d.ts +56 -129
  42. package/dist/server.js +44 -508
  43. package/dist/server.js.map +1 -1
  44. package/dist/v3/client.d.ts +93 -0
  45. package/dist/v3/effect.d.ts +17 -0
  46. package/dist/v3/mod.d.ts +3 -0
  47. package/dist/v3/preprocess.d.ts +28 -0
  48. package/dist/v3/root-node.d.ts +59 -0
  49. package/dist/v3/server.d.ts +167 -0
  50. package/dist/v3/vite.d.ts +46 -0
  51. package/dist/v4/client.d.ts +2 -0
  52. package/dist/v4/effect.d.ts +24 -0
  53. package/dist/v4/effect.js +19 -0
  54. package/dist/v4/effect.js.map +1 -0
  55. package/dist/v4/mod.d.ts +3 -0
  56. package/dist/v4/mod.js +3 -0
  57. package/dist/v4/preprocess.d.ts +30 -0
  58. package/dist/v4/preprocess.js +28 -0
  59. package/dist/v4/preprocess.js.map +1 -0
  60. package/dist/v4/root-node.d.ts +59 -0
  61. package/dist/v4/root-node.js +4 -0
  62. package/dist/v4/server.d.ts +124 -0
  63. package/dist/v4/server.js +22 -0
  64. package/dist/v4/server.js.map +1 -0
  65. package/dist/v4/vite.d.ts +34 -0
  66. package/dist/v4/vite.js +31 -0
  67. package/dist/v4/vite.js.map +1 -0
  68. package/dist/vite.d.ts +30 -15
  69. package/dist/vite.js +18 -101
  70. package/dist/vite.js.map +1 -1
  71. package/package.json +46 -3
  72. package/dist/client.js.map +0 -1
  73. package/dist/effect.js.map +0 -1
@@ -0,0 +1,199 @@
1
+ import { REMOTE_ERROR_DECODER, create_remote_domain_error, create_remote_http_error, create_remote_transport_error, create_remote_validation_error, is_serialized_remote_failure_envelope } from "../internal/remote-shared.js";
2
+ import { n as exit_has_interrupts, t as create_async_effect } from "./effect-compat-BhW0YPIs.js";
3
+ import { Cause, Effect, Exit, Layer, ManagedRuntime } from "effect";
4
+ import { getContext, hasContext, onDestroy, setContext } from "svelte";
5
+ //#region v3/client.ts
6
+ const EFFECT_RUNTIME_CONTEXT = Symbol.for("svelte-effect-runtime/runtime");
7
+ let current_client_runtime = null;
8
+ function runtime_seed() {
9
+ return Layer.effectContext(Effect.context());
10
+ }
11
+ function pipe_client_runtime(...ops) {
12
+ if (ops.length === 0) return Layer.empty;
13
+ return ops.reduce((layer, op) => op(layer), runtime_seed());
14
+ }
15
+ function make_client_runtime(...ops) {
16
+ const layer = ops.length === 0 ? pipe_client_runtime() : pipe_client_runtime(...ops);
17
+ const runtime = track_client_runtime(ManagedRuntime.make(layer));
18
+ current_client_runtime?.dispose().catch(() => void 0);
19
+ current_client_runtime = runtime;
20
+ if (is_component_context_available()) return provide_effect_runtime(runtime, { disposeOnDestroy: true });
21
+ return runtime;
22
+ }
23
+ /**
24
+ * Build or compose the shared client-side `ManagedRuntime` used by generated
25
+ * `<script effect>` and markup helpers.
26
+ *
27
+ * @see https://ser.barekey.dev/content/reference/client-runtime
28
+ */
29
+ const ClientRuntime = {
30
+ pipe: pipe_client_runtime,
31
+ make: make_client_runtime
32
+ };
33
+ /**
34
+ * Register a pre-built `ManagedRuntime` on the current Svelte component
35
+ * context. Not exported - callers should go through `ClientRuntime.make`.
36
+ *
37
+ * @internal Internal - do not use.
38
+ */
39
+ function provide_effect_runtime(runtime, options = {}) {
40
+ current_client_runtime = track_client_runtime(runtime);
41
+ setContext(EFFECT_RUNTIME_CONTEXT, runtime);
42
+ if (options.disposeOnDestroy) onDestroy(() => {
43
+ runtime.dispose();
44
+ });
45
+ return runtime;
46
+ }
47
+ /**
48
+ * Look up the active client runtime for the current component, or lazily
49
+ * create a default empty-layer runtime when no explicit one has been
50
+ * registered.
51
+ *
52
+ * Emitted by the `<script effect>` / `{yield* ...}` preprocessor - users
53
+ * should never import this directly.
54
+ *
55
+ * @internal Internal - do not use.
56
+ * @see https://ser.barekey.dev/content/reference/client-runtime
57
+ */
58
+ function get_effect_runtime_or_throw() {
59
+ if (has_runtime_context()) return getContext(EFFECT_RUNTIME_CONTEXT);
60
+ if (current_client_runtime !== null) return current_client_runtime;
61
+ const default_runtime = track_client_runtime(ManagedRuntime.make(Layer.empty));
62
+ current_client_runtime = default_runtime;
63
+ return default_runtime;
64
+ }
65
+ /**
66
+ * Mount-time runner used by generated `<script effect>` output.
67
+ *
68
+ * Emitted by the preprocessor - users should never import this directly.
69
+ *
70
+ * @internal Internal - do not use.
71
+ * @see https://ser.barekey.dev/content/reference/client-runtime
72
+ */
73
+ function run_component_effect(runtime, program) {
74
+ let disposed = false;
75
+ const cancel = runtime.runCallback(program, { onExit(exit) {
76
+ if (Exit.isFailure(exit) && !exit_has_interrupts(exit)) queueMicrotask(() => {
77
+ throw Cause.squash(exit.cause);
78
+ });
79
+ } });
80
+ return () => {
81
+ if (disposed) return;
82
+ disposed = true;
83
+ cancel();
84
+ };
85
+ }
86
+ /**
87
+ * Promise-returning runner used by generated `{yield* ...}` markup helpers.
88
+ *
89
+ * Emitted by the preprocessor - users should never import this directly.
90
+ *
91
+ * @internal Internal - do not use.
92
+ * @see https://ser.barekey.dev/content/reference/client-runtime
93
+ */
94
+ function run_inline_effect(runtime, program) {
95
+ return runtime.runPromise(program).catch((error) => {
96
+ queueMicrotask(() => {
97
+ throw error;
98
+ });
99
+ throw error;
100
+ });
101
+ }
102
+ function has_runtime_context() {
103
+ try {
104
+ return hasContext(EFFECT_RUNTIME_CONTEXT);
105
+ } catch {
106
+ return false;
107
+ }
108
+ }
109
+ function is_component_context_available() {
110
+ try {
111
+ hasContext(EFFECT_RUNTIME_CONTEXT);
112
+ return true;
113
+ } catch {
114
+ return false;
115
+ }
116
+ }
117
+ function track_client_runtime(runtime) {
118
+ const tracked_runtime = runtime;
119
+ if (tracked_runtime.__ser_tracked__ === true) return tracked_runtime;
120
+ const dispose = runtime.dispose.bind(runtime);
121
+ tracked_runtime.__ser_tracked__ = true;
122
+ runtime.dispose = (() => {
123
+ if (current_client_runtime === tracked_runtime) current_client_runtime = null;
124
+ return dispose();
125
+ });
126
+ return tracked_runtime;
127
+ }
128
+ /**
129
+ * Internal redirect guard used by the remote client adapters.
130
+ *
131
+ * @internal Internal - do not use.
132
+ */
133
+ function is_redirect_like(value) {
134
+ return Boolean(value && typeof value === "object" && typeof value.location === "string" && typeof value.status === "number");
135
+ }
136
+ function is_http_error_like(value) {
137
+ return Boolean(value && typeof value === "object" && typeof value.status === "number");
138
+ }
139
+ function get_error_status(value) {
140
+ return is_http_error_like(value) ? value.status ?? 500 : 500;
141
+ }
142
+ function get_remote_error_decoder(value) {
143
+ if (value && (typeof value === "object" || typeof value === "function") && REMOTE_ERROR_DECODER in value) return value[REMOTE_ERROR_DECODER];
144
+ }
145
+ function decode_remote_error(error, decode_payload) {
146
+ if (is_http_error_like(error)) {
147
+ const body = error.body;
148
+ if (is_serialized_remote_failure_envelope(body) && decode_payload) try {
149
+ return create_remote_domain_error(decode_payload(body.encoded), get_error_status(error));
150
+ } catch (cause) {
151
+ return create_remote_transport_error(cause, body);
152
+ }
153
+ if (get_error_status(error) === 400) return create_remote_validation_error([], {
154
+ body,
155
+ status: 400
156
+ });
157
+ return create_remote_http_error(error, {
158
+ body,
159
+ status: get_error_status(error)
160
+ });
161
+ }
162
+ return create_remote_http_error(error);
163
+ }
164
+ /**
165
+ * Internal adapter that lifts a promise-producing callback into the shared
166
+ * remote failure channel used by client wrappers.
167
+ *
168
+ * @internal Internal - do not use.
169
+ */
170
+ function create_remote_effect_from_promise(create_promise, decode_error = (error) => create_remote_http_error(error)) {
171
+ return create_async_effect((resume) => {
172
+ Promise.resolve().then(create_promise).then((value) => resume(Effect.succeed(value)), (error) => {
173
+ if (is_redirect_like(error)) {
174
+ resume(Effect.die(error));
175
+ return;
176
+ }
177
+ resume(Effect.fail(decode_error(error)));
178
+ });
179
+ });
180
+ }
181
+ function to_effect(value) {
182
+ const decode_payload = get_remote_error_decoder(value);
183
+ if (typeof value === "function") return ((...args) => create_remote_effect_from_promise(() => Promise.resolve(value(...args)), (error) => decode_remote_error(error, decode_payload)));
184
+ return create_remote_effect_from_promise(() => value, (error) => decode_remote_error(error, decode_payload));
185
+ }
186
+ function to_native(value) {
187
+ let current = value;
188
+ const seen = /* @__PURE__ */ new Set();
189
+ while (current && (typeof current === "object" || typeof current === "function") && "native" in current) {
190
+ if (seen.has(current)) break;
191
+ seen.add(current);
192
+ current = current.native;
193
+ }
194
+ return current;
195
+ }
196
+ //#endregion
197
+ export { run_component_effect as a, to_native as c, is_redirect_like as i, create_remote_effect_from_promise as n, run_inline_effect as o, get_effect_runtime_or_throw as r, to_effect as s, ClientRuntime as t };
198
+
199
+ //# sourceMappingURL=client-DkW4e4dD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-DkW4e4dD.js","names":[],"sources":["../../../modules/svelte-effect-runtime/v3/client.ts"],"sourcesContent":["import { Cause, Effect, Exit, Layer, ManagedRuntime } from \"effect\";\nimport { getContext, hasContext, onDestroy, setContext } from \"svelte\";\nimport {\n create_remote_domain_error,\n create_remote_http_error,\n create_remote_transport_error,\n create_remote_validation_error,\n is_serialized_remote_failure_envelope,\n REMOTE_ERROR_DECODER,\n type RemoteFailure,\n} from \"$internal/remote-shared.ts\";\nimport {\n create_async_effect,\n exit_has_interrupts,\n} from \"$internal/effect-compat.ts\";\n\nconst EFFECT_RUNTIME_CONTEXT = Symbol.for(\"svelte-effect-runtime/runtime\");\nlet current_client_runtime: EffectRuntime<unknown> | null = null;\n\ninterface ProvideEffectRuntimeOptions {\n disposeOnDestroy?: boolean;\n}\n\nexport interface EffectRuntime<R = unknown> {\n runCallback<A, E, R2>(\n effect: Effect.Effect<A, E, R2>,\n options?: {\n onExit?: (exit: Exit.Exit<A, E>) => void;\n },\n ): () => void;\n runPromise<A, E, R2>(effect: Effect.Effect<A, E, R2>): Promise<A>;\n dispose(): Promise<void>;\n}\n\nexport type {\n FormError,\n FormIssue,\n RemoteDomainError,\n RemoteFailure,\n RemoteHttpError,\n RemoteTransportError,\n RemoteValidationError,\n} from \"$internal/remote-shared.ts\";\n\nexport interface ClientRuntimeService extends EffectRuntime<unknown> {}\n\ntype RuntimeSeedLayer<R> = Layer.Layer<R, never, R>;\n\nfunction runtime_seed<R>(): RuntimeSeedLayer<R> {\n return Layer.effectContext(Effect.context<R>());\n}\n\ntype RuntimeOperator = (\n self: Layer.Layer<unknown, unknown, unknown>,\n) => Layer.Layer<unknown, unknown, unknown>;\n\ntype ProvidedBy<Op> = Op extends\n (self: RuntimeSeedLayer<infer R>) => Layer.Layer<unknown, unknown, infer RIn>\n ? Exclude<R, RIn>\n : never;\n\ntype ProvidedByAll<Ops extends ReadonlyArray<RuntimeOperator>> = Ops extends\n readonly [infer Head, ...infer Tail] ?\n | ProvidedBy<Head>\n | ProvidedByAll<Extract<Tail, ReadonlyArray<RuntimeOperator>>>\n : never;\n\ntype ApplyOperator<Seed, Op> = Op extends (self: Seed) => infer Out ? Out\n : never;\n\ntype ApplyOperators<\n Seed,\n Ops extends ReadonlyArray<RuntimeOperator>,\n> = Ops extends readonly [infer Head, ...infer Tail] ? ApplyOperators<\n ApplyOperator<Seed, Head>,\n Extract<Tail, ReadonlyArray<RuntimeOperator>>\n >\n : Seed;\n\ntype FinalRuntimeLayer<Ops extends ReadonlyArray<RuntimeOperator>> =\n ApplyOperators<RuntimeSeedLayer<ProvidedByAll<Ops>>, Ops> extends infer Out\n ? Out extends Layer.Layer<unknown, unknown, infer RIn>\n ? [RIn] extends [never] ? Out\n : never\n : never\n : never;\n\ninterface ClientRuntimeSeed {\n pipe(): Layer.Layer<never>;\n pipe<const Ops extends readonly [RuntimeOperator, ...Array<RuntimeOperator>]>(\n ...ops: Ops\n ): FinalRuntimeLayer<Ops>;\n make(): ManagedRuntime.ManagedRuntime<never, never>;\n make<const Ops extends readonly [RuntimeOperator, ...Array<RuntimeOperator>]>(\n ...ops: Ops\n ): ManagedRuntimeFromOps<Ops>;\n}\n\ntype ManagedRuntimeFromOps<Ops extends ReadonlyArray<RuntimeOperator>> =\n ManagedRuntime.ManagedRuntime<\n Layer.Layer.Success<FinalRuntimeLayer<Ops>>,\n Layer.Layer.Error<FinalRuntimeLayer<Ops>>\n >;\n\nfunction pipe_client_runtime(): Layer.Layer<never>;\nfunction pipe_client_runtime<\n const Ops extends readonly [RuntimeOperator, ...Array<RuntimeOperator>],\n>(...ops: Ops): FinalRuntimeLayer<Ops>;\nfunction pipe_client_runtime(\n ...ops: Array<RuntimeOperator>\n): Layer.Layer<never, unknown, unknown> {\n if (ops.length === 0) {\n return Layer.empty;\n }\n\n return ops.reduce<Layer.Layer<unknown, unknown, unknown>>(\n (layer, op) => op(layer),\n runtime_seed<unknown>(),\n ) as Layer.Layer<never, unknown, unknown>;\n}\n\nfunction make_client_runtime(): ManagedRuntime.ManagedRuntime<never, never>;\nfunction make_client_runtime<\n const Ops extends readonly [RuntimeOperator, ...Array<RuntimeOperator>],\n>(...ops: Ops): ManagedRuntimeFromOps<Ops>;\nfunction make_client_runtime(\n ...ops: [] | [RuntimeOperator, ...Array<RuntimeOperator>]\n): ManagedRuntime.ManagedRuntime<never, unknown> {\n const layer = ops.length === 0 ? pipe_client_runtime() : pipe_client_runtime(\n ...(ops as [RuntimeOperator, ...Array<RuntimeOperator>]),\n );\n\n const runtime = track_client_runtime(ManagedRuntime.make(\n layer as unknown as Layer.Layer<unknown, unknown, never>,\n ));\n\n void current_client_runtime?.dispose().catch(() => undefined);\n current_client_runtime = runtime;\n\n if (is_component_context_available()) {\n return provide_effect_runtime(runtime, { disposeOnDestroy: true });\n }\n\n return runtime;\n}\n\n/**\n * Build or compose the shared client-side `ManagedRuntime` used by generated\n * `<script effect>` and markup helpers.\n *\n * @see https://ser.barekey.dev/content/reference/client-runtime\n */\nexport const ClientRuntime: ClientRuntimeSeed = {\n pipe: pipe_client_runtime,\n make: make_client_runtime,\n};\n\n/**\n * Register a pre-built `ManagedRuntime` on the current Svelte component\n * context. Not exported - callers should go through `ClientRuntime.make`.\n *\n * @internal Internal - do not use.\n */\nfunction provide_effect_runtime<T extends EffectRuntime>(\n runtime: T,\n options: ProvideEffectRuntimeOptions = {},\n): T {\n current_client_runtime = track_client_runtime(runtime);\n setContext(EFFECT_RUNTIME_CONTEXT, runtime);\n\n if (options.disposeOnDestroy) {\n onDestroy(() => {\n void runtime.dispose();\n });\n }\n\n return runtime;\n}\n\n/**\n * Look up the active client runtime for the current component, or lazily\n * create a default empty-layer runtime when no explicit one has been\n * registered.\n *\n * Emitted by the `<script effect>` / `{yield* ...}` preprocessor - users\n * should never import this directly.\n *\n * @internal Internal - do not use.\n * @see https://ser.barekey.dev/content/reference/client-runtime\n */\nexport function get_effect_runtime_or_throw<\n T extends EffectRuntime = EffectRuntime<never>,\n>(): T {\n if (has_runtime_context()) {\n return getContext<T>(EFFECT_RUNTIME_CONTEXT);\n }\n\n if (current_client_runtime !== null) {\n return current_client_runtime as T;\n }\n\n // No runtime registered — lazily create a default one with an empty layer.\n // This makes `ClientRuntime.make()` in `hooks.client.ts` optional for apps\n // that don't need to provide custom dependencies. A later explicit call to\n // `ClientRuntime.make(...)` will dispose this default and replace it.\n const default_runtime = track_client_runtime(\n ManagedRuntime.make(\n Layer.empty as unknown as Layer.Layer<unknown, unknown, never>,\n ),\n );\n current_client_runtime = default_runtime;\n return default_runtime as unknown as T;\n}\n\n/**\n * Mount-time runner used by generated `<script effect>` output.\n *\n * Emitted by the preprocessor - users should never import this directly.\n *\n * @internal Internal - do not use.\n * @see https://ser.barekey.dev/content/reference/client-runtime\n */\nexport function run_component_effect<A, E, R>(\n runtime: EffectRuntime<R>,\n program: Effect.Effect<A, E, R>,\n): () => void {\n let disposed = false;\n\n const cancel = runtime.runCallback(program, {\n onExit(exit) {\n if (Exit.isFailure(exit) && !exit_has_interrupts(exit)) {\n queueMicrotask(() => {\n throw Cause.squash(exit.cause);\n });\n }\n },\n });\n\n return () => {\n if (disposed) {\n return;\n }\n\n disposed = true;\n cancel();\n };\n}\n\n/**\n * Promise-returning runner used by generated `{yield* ...}` markup helpers.\n *\n * Emitted by the preprocessor - users should never import this directly.\n *\n * @internal Internal - do not use.\n * @see https://ser.barekey.dev/content/reference/client-runtime\n */\nexport function run_inline_effect<A, E, R>(\n runtime: EffectRuntime<R>,\n program: Effect.Effect<A, E, R>,\n): Promise<A> {\n return runtime.runPromise(program).catch((error) => {\n queueMicrotask(() => {\n throw error;\n });\n\n throw error;\n });\n}\n\nfunction has_runtime_context(): boolean {\n try {\n return hasContext(EFFECT_RUNTIME_CONTEXT);\n } catch {\n return false;\n }\n}\n\nfunction is_component_context_available(): boolean {\n try {\n void hasContext(EFFECT_RUNTIME_CONTEXT);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction track_client_runtime<T extends EffectRuntime>(runtime: T): T {\n const tracked_runtime = runtime as T & { __ser_tracked__?: true };\n\n if (tracked_runtime.__ser_tracked__ === true) {\n return tracked_runtime;\n }\n\n const dispose = runtime.dispose.bind(runtime);\n tracked_runtime.__ser_tracked__ = true;\n runtime.dispose = (() => {\n if (current_client_runtime === tracked_runtime) {\n current_client_runtime = null;\n }\n\n return dispose();\n }) as typeof runtime.dispose;\n\n return tracked_runtime;\n}\n\n/**\n * Internal redirect guard used by the remote client adapters.\n *\n * @internal Internal - do not use.\n */\nfunction is_redirect_like(value: unknown): boolean {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { location?: unknown }).location === \"string\" &&\n typeof (value as { status?: unknown }).status === \"number\",\n );\n}\n\ntype Decode_remote_payload = <ErrorType = unknown>(\n encoded: string,\n) => ErrorType;\n\nfunction is_http_error_like(\n value: unknown,\n): value is {\n readonly body?: unknown;\n readonly status?: number;\n} {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { status?: unknown }).status === \"number\",\n );\n}\n\nfunction get_error_status(value: unknown): number {\n return is_http_error_like(value) ? value.status ?? 500 : 500;\n}\n\nfunction get_remote_error_decoder(\n value: unknown,\n): Decode_remote_payload | undefined {\n if (\n value &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n REMOTE_ERROR_DECODER in value\n ) {\n return (value as { [REMOTE_ERROR_DECODER]: Decode_remote_payload })[\n REMOTE_ERROR_DECODER\n ];\n }\n}\n\nfunction decode_remote_error<ErrorType>(\n error: unknown,\n decode_payload?: Decode_remote_payload,\n): RemoteFailure<ErrorType> {\n if (is_http_error_like(error)) {\n const body = error.body;\n\n if (is_serialized_remote_failure_envelope(body) && decode_payload) {\n try {\n return create_remote_domain_error<ErrorType>(\n decode_payload<ErrorType>(body.encoded),\n get_error_status(error),\n );\n } catch (cause) {\n return create_remote_transport_error(cause, body);\n }\n }\n\n if (get_error_status(error) === 400) {\n return create_remote_validation_error([], {\n body,\n status: 400,\n });\n }\n\n return create_remote_http_error(error, {\n body,\n status: get_error_status(error),\n });\n }\n\n return create_remote_http_error(error);\n}\n\n/**\n * Internal adapter that lifts a promise-producing callback into the shared\n * remote failure channel used by client wrappers.\n *\n * @internal Internal - do not use.\n */\nfunction create_remote_effect_from_promise<Success, ErrorType = never>(\n create_promise: () => PromiseLike<Success>,\n decode_error: (error: unknown) => RemoteFailure<ErrorType> = (error) =>\n create_remote_http_error(error),\n): Effect.Effect<Success, RemoteFailure<ErrorType>, never> {\n return create_async_effect<Success, RemoteFailure<ErrorType>>((resume) => {\n void Promise.resolve()\n .then(create_promise)\n .then(\n (value) => resume(Effect.succeed(value)),\n (error) => {\n if (is_redirect_like(error)) {\n resume(Effect.die(error));\n return;\n }\n\n resume(Effect.fail(decode_error(error)));\n },\n );\n });\n}\n\ntype AnyCallable = (...args: Array<unknown>) => unknown;\n\n/**\n * Convert a promise or promise-returning function into an `Effect` that uses\n * the remote failure channel when applicable.\n *\n * @see https://ser.barekey.dev/content/reference/effect\n */\nexport function to_effect<Success, ErrorType = never>(\n promise_like: PromiseLike<Success>,\n): Effect.Effect<Success, RemoteFailure<ErrorType>, never>;\nexport function to_effect<\n Args extends Array<unknown>,\n Success,\n ErrorType = never,\n>(\n fn: (...args: Args) => PromiseLike<Success>,\n): (...args: Args) => Effect.Effect<Success, RemoteFailure<ErrorType>, never>;\nexport function to_effect<Success, ErrorType = never>(\n value: PromiseLike<Success> | AnyCallable,\n): Effect.Effect<Success, RemoteFailure<ErrorType>, never> | AnyCallable {\n const decode_payload = get_remote_error_decoder(value);\n\n if (typeof value === \"function\") {\n return ((...args: Array<unknown>) =>\n create_remote_effect_from_promise(\n () => Promise.resolve((value as AnyCallable)(...args)),\n (error) => decode_remote_error<ErrorType>(error, decode_payload),\n )) as AnyCallable;\n }\n\n return create_remote_effect_from_promise(\n () => value,\n (error) => decode_remote_error<ErrorType>(error, decode_payload),\n );\n}\n\n/**\n * Unwrap a runtime wrapper and recover the original native value.\n *\n * @see https://ser.barekey.dev/content/reference/effect\n */\nexport function to_native<Value>(\n value: Value,\n): Value extends { native: infer Native } ? Native\n : Value;\nexport function to_native(value: unknown): unknown {\n let current = value;\n const seen = new Set<unknown>();\n\n while (\n current &&\n (typeof current === \"object\" || typeof current === \"function\") &&\n \"native\" in current\n ) {\n if (seen.has(current)) {\n break;\n }\n\n seen.add(current);\n current = (current as { native: unknown }).native;\n }\n\n return current;\n}\n\nexport { create_remote_effect_from_promise, is_redirect_like };\n"],"mappings":";;;;;AAgBA,MAAM,yBAAyB,OAAO,IAAI,gCAAgC;AAC1E,IAAI,yBAAwD;AA+B5D,SAAS,eAAuC;AAC9C,QAAO,MAAM,cAAc,OAAO,SAAY,CAAC;;AA2DjD,SAAS,oBACP,GAAG,KACmC;AACtC,KAAI,IAAI,WAAW,EACjB,QAAO,MAAM;AAGf,QAAO,IAAI,QACR,OAAO,OAAO,GAAG,MAAM,EACxB,cAAuB,CACxB;;AAOH,SAAS,oBACP,GAAG,KAC4C;CAC/C,MAAM,QAAQ,IAAI,WAAW,IAAI,qBAAqB,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AAe,CACpB,MACE,UAAU,OAAO,OAAO,QAAQ,MAAM,CAAC,GACvC,UAAU;AACT,OAAI,iBAAiB,MAAM,EAAE;AAC3B,WAAO,OAAO,IAAI,MAAM,CAAC;AACzB;;AAGF,UAAO,OAAO,KAAK,aAAa,MAAM,CAAC,CAAC;IAE3C;GACH;;AAqBJ,SAAgB,UACd,OACuE;CACvE,MAAM,iBAAiB,yBAAyB,MAAM;AAEtD,KAAI,OAAO,UAAU,WACnB,UAAS,GAAG,SACV,wCACQ,QAAQ,QAAS,MAAsB,GAAG,KAAK,CAAC,GACrD,UAAU,oBAA+B,OAAO,eAAe,CACjE;AAGL,QAAO,wCACC,QACL,UAAU,oBAA+B,OAAO,eAAe,CACjE;;AAYH,SAAgB,UAAU,OAAyB;CACjD,IAAI,UAAU;CACd,MAAM,uBAAO,IAAI,KAAc;AAE/B,QACE,YACC,OAAO,YAAY,YAAY,OAAO,YAAY,eACnD,YAAY,SACZ;AACA,MAAI,KAAK,IAAI,QAAQ,CACnB;AAGF,OAAK,IAAI,QAAQ;AACjB,YAAW,QAAgC;;AAG7C,QAAO"}
@@ -0,0 +1,51 @@
1
+ import { t as effect_preprocess } from "./preprocess-CtLrnJcK.js";
2
+ import { n as sveltekit_effect_runtime } from "./vite-DqjXRZd4.js";
3
+ import { preprocess } from "svelte/compiler";
4
+ //#region v3/effect.ts
5
+ /**
6
+ * High-level Vite integration for `svelte-effect-runtime`.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { effect } from "svelte-effect-runtime";
11
+ *
12
+ * export default {
13
+ * plugins: [effect()],
14
+ * };
15
+ * ```
16
+ *
17
+ * @module
18
+ */
19
+ function create_effect_svelte_transform(options = {}) {
20
+ const preprocessor = effect_preprocess(options);
21
+ return {
22
+ name: "svelte-effect-runtime-transform",
23
+ enforce: "pre",
24
+ async transform(code, id, _options) {
25
+ const filename = id.split("?", 1)[0];
26
+ if (!filename.endsWith(".svelte")) return null;
27
+ const transformed = await preprocess(code, preprocessor, { filename });
28
+ if (transformed.code === code) return null;
29
+ return {
30
+ code: transformed.code,
31
+ ...transformed.map ? { map: transformed.map } : {}
32
+ };
33
+ }
34
+ };
35
+ }
36
+ /**
37
+ * Convenience Vite plugin that enables `<script effect>` transforms and wires
38
+ * SvelteKit remote functions to the Effect-aware client adapters.
39
+ *
40
+ * Use this in `vite.config.ts` instead of composing lower-level runtime
41
+ * plugins yourself.
42
+ *
43
+ * @see https://ser.barekey.dev/
44
+ */
45
+ function effect(options = {}) {
46
+ return [create_effect_svelte_transform(options.effect), sveltekit_effect_runtime({ remoteModuleId: options.remoteModuleId })];
47
+ }
48
+ //#endregion
49
+ export { effect as t };
50
+
51
+ //# sourceMappingURL=effect-CL8GJs8A.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect-CL8GJs8A.js","names":[],"sources":["../../../modules/svelte-effect-runtime/v3/effect.ts"],"sourcesContent":["/**\n * High-level Vite integration for `svelte-effect-runtime`.\n *\n * @example\n * ```ts\n * import { effect } from \"svelte-effect-runtime\";\n *\n * export default {\n * plugins: [effect()],\n * };\n * ```\n *\n * @module\n */\nimport { preprocess } from \"svelte/compiler\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport {\n effect_preprocess,\n type EffectPreprocessOptions,\n} from \"$/v3/preprocess.ts\";\nimport { sveltekit_effect_runtime } from \"$/v3/vite.ts\";\n\n/** Options for the high-level {@link effect} Vite plugin. */\nexport interface EffectPluginOptions {\n effect?: EffectPreprocessOptions;\n remoteModuleId?: string;\n}\n\nfunction create_effect_svelte_transform(\n options: EffectPreprocessOptions = {},\n): Plugin {\n const preprocessor = effect_preprocess(options);\n\n return {\n name: \"svelte-effect-runtime-transform\",\n enforce: \"pre\",\n async transform(code, id, _options) {\n const filename = id.split(\"?\", 1)[0];\n if (!filename.endsWith(\".svelte\")) {\n return null;\n }\n\n const transformed = await preprocess(code, preprocessor, { filename });\n if (transformed.code === code) {\n return null;\n }\n\n return {\n code: transformed.code,\n ...(transformed.map ? { map: transformed.map as never } : {}),\n };\n },\n };\n}\n\n/**\n * Convenience Vite plugin that enables `<script effect>` transforms and wires\n * SvelteKit remote functions to the Effect-aware client adapters.\n *\n * Use this in `vite.config.ts` instead of composing lower-level runtime\n * plugins yourself.\n *\n * @see https://ser.barekey.dev/\n */\nexport function effect(\n options: EffectPluginOptions = {},\n): PluginOption[] {\n const transform_plugin = create_effect_svelte_transform(options.effect);\n\n return [\n transform_plugin,\n sveltekit_effect_runtime({\n remoteModuleId: options.remoteModuleId,\n }),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,SAAS,+BACP,UAAmC,EAAE,EAC7B;CACR,MAAM,eAAe,kBAAkB,QAAQ;AAE/C,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,UAAU,MAAM,IAAI,UAAU;GAClC,MAAM,WAAW,GAAG,MAAM,KAAK,EAAE,CAAC;AAClC,OAAI,CAAC,SAAS,SAAS,UAAU,CAC/B,QAAO;GAGT,MAAM,cAAc,MAAM,WAAW,MAAM,cAAc,EAAE,UAAU,CAAC;AACtE,OAAI,YAAY,SAAS,KACvB,QAAO;AAGT,UAAO;IACL,MAAM,YAAY;IAClB,GAAI,YAAY,MAAM,EAAE,KAAK,YAAY,KAAc,GAAG,EAAE;IAC7D;;EAEJ;;;;;;;;;;;AAYH,SAAgB,OACd,UAA+B,EAAE,EACjB;AAGhB,QAAO,CAFkB,+BAA+B,QAAQ,OAAO,EAIrE,yBAAyB,EACvB,gBAAgB,QAAQ,gBACzB,CAAC,CACH"}
@@ -0,0 +1,103 @@
1
+ import { Cause, Context, Effect, Exit, Option, Schema, SchemaAST } from "effect";
2
+ //#region internal/effect-compat.ts
3
+ function make_context_key(key) {
4
+ const context_namespace = Context;
5
+ if (typeof context_namespace.Service === "function") return context_namespace.Service(key);
6
+ if (typeof context_namespace.GenericTag === "function") return context_namespace.GenericTag(key);
7
+ throw new Error("No compatible Effect context key constructor was found.");
8
+ }
9
+ function to_standard_schema_v1(schema) {
10
+ const schema_namespace = Schema;
11
+ const factory = schema_namespace.toStandardSchemaV1 ?? schema_namespace.standardSchemaV1;
12
+ if (!factory) throw new Error("No compatible standard schema adapter was found in effect/Schema.");
13
+ return factory(schema);
14
+ }
15
+ function create_async_effect(register) {
16
+ const effect_namespace = Effect;
17
+ if (typeof effect_namespace.callback === "function") return effect_namespace.callback((resume, _signal) => register(resume));
18
+ if (typeof effect_namespace.async === "function") return effect_namespace.async(register);
19
+ throw new Error("No compatible async Effect constructor was found.");
20
+ }
21
+ function get_cause_failure(cause) {
22
+ const cause_namespace = Cause;
23
+ if (typeof cause_namespace.failureOption === "function") {
24
+ const failure = cause_namespace.failureOption(cause);
25
+ return Option.isSome(failure) ? failure.value : void 0;
26
+ }
27
+ const fail_reason = get_fail_reason_from_cause(cause, cause_namespace.isFailReason);
28
+ if (fail_reason) return fail_reason.error;
29
+ if (typeof cause_namespace.findFail === "function") {
30
+ const match = extract_success_value(cause_namespace.findFail(cause));
31
+ if (is_fail_reason_like(match)) return match.error;
32
+ }
33
+ }
34
+ function exit_has_interrupts(exit) {
35
+ const exit_namespace = Exit;
36
+ if (typeof exit_namespace.hasInterrupts === "function") return exit_namespace.hasInterrupts(exit);
37
+ if (typeof exit_namespace.isInterrupted === "function") return exit_namespace.isInterrupted(exit);
38
+ return false;
39
+ }
40
+ function get_effect_schema_field_names(schema) {
41
+ if (schema.fields && typeof schema.fields === "object") return Object.keys(schema.fields);
42
+ const get_property_signatures = Reflect.get(SchemaAST, "getPropertySignatures");
43
+ if (schema.ast && typeof get_property_signatures === "function") return get_property_signatures(schema.ast).map((property_signature) => property_signature.name).filter((name) => typeof name === "string");
44
+ const is_objects_ast = Reflect.get(SchemaAST, "isObjects");
45
+ if (schema.ast && typeof is_objects_ast === "function" && is_objects_ast(schema.ast) && Array.isArray(schema.ast.propertySignatures)) return schema.ast.propertySignatures.map((property_signature) => property_signature.name).filter((name) => typeof name === "string");
46
+ return [];
47
+ }
48
+ function to_transportable_data(value, seen = /* @__PURE__ */ new WeakMap()) {
49
+ if (value === null || value === void 0 || typeof value !== "object") return value;
50
+ if (seen.has(value)) return seen.get(value);
51
+ if (value instanceof Date || value instanceof RegExp || value instanceof URL || value instanceof URLSearchParams || value instanceof ArrayBuffer || ArrayBuffer.isView(value)) return value;
52
+ if (value instanceof Map) {
53
+ const normalized = /* @__PURE__ */ new Map();
54
+ seen.set(value, normalized);
55
+ for (const [key, entry] of value.entries()) normalized.set(to_transportable_data(key, seen), to_transportable_data(entry, seen));
56
+ return normalized;
57
+ }
58
+ if (value instanceof Set) {
59
+ const normalized = /* @__PURE__ */ new Set();
60
+ seen.set(value, normalized);
61
+ for (const entry of value.values()) normalized.add(to_transportable_data(entry, seen));
62
+ return normalized;
63
+ }
64
+ if (Array.isArray(value)) {
65
+ const normalized = [];
66
+ seen.set(value, normalized);
67
+ for (const entry of value) normalized.push(to_transportable_data(entry, seen));
68
+ return normalized;
69
+ }
70
+ const normalized = {};
71
+ seen.set(value, normalized);
72
+ const property_names = new Set(Object.keys(value));
73
+ if (value instanceof Error) {
74
+ property_names.add("name");
75
+ property_names.add("message");
76
+ if ("stack" in value) property_names.add("stack");
77
+ if ("cause" in value) property_names.add("cause");
78
+ }
79
+ for (const property_name of property_names) {
80
+ const property_value = Reflect.get(value, property_name);
81
+ if (property_value === void 0) continue;
82
+ normalized[property_name] = to_transportable_data(property_value, seen);
83
+ }
84
+ return normalized;
85
+ }
86
+ function get_fail_reason_from_cause(cause, is_fail_reason) {
87
+ if (!Array.isArray(cause.reasons)) return;
88
+ const match = cause.reasons.find((reason) => is_fail_reason ? is_fail_reason(reason) : is_fail_reason_like(reason));
89
+ return is_fail_reason_like(match) ? match : void 0;
90
+ }
91
+ function extract_success_value(result) {
92
+ if (!result || typeof result !== "object") return;
93
+ if ("_tag" in result && result._tag === "Success" && "value" in result) return result.value;
94
+ if ("_tag" in result && result._tag === "Right" && "right" in result) return result.right;
95
+ if ("value" in result) return result.value;
96
+ }
97
+ function is_fail_reason_like(value) {
98
+ return Boolean(value && typeof value === "object" && "error" in value);
99
+ }
100
+ //#endregion
101
+ export { make_context_key as a, get_effect_schema_field_names as i, exit_has_interrupts as n, to_standard_schema_v1 as o, get_cause_failure as r, to_transportable_data as s, create_async_effect as t };
102
+
103
+ //# sourceMappingURL=effect-compat-BhW0YPIs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect-compat-BhW0YPIs.js","names":[],"sources":["../../../modules/svelte-effect-runtime/internal/effect-compat.ts"],"sourcesContent":["import { Cause, Context, Effect, Exit, Option, Schema, SchemaAST } from \"effect\";\n\nexport interface EffectContextKey<Identifier, Service> {\n readonly Identifier: Identifier;\n readonly Service: Service;\n readonly key: string;\n}\n\nexport interface EffectSchemaLike {\n readonly Encoded?: unknown;\n readonly Type?: unknown;\n readonly ast?: unknown;\n readonly fields?: Record<string, unknown>;\n}\n\ntype EffectResume<A, E, R> = (\n effect: Effect.Effect<A, E, R>,\n) => void;\n\ntype EffectCallbackFactory = <A, E = never, R = never>(\n register: (\n resume: EffectResume<A, E, R>,\n signal: AbortSignal,\n ) => void | Effect.Effect<void, never, R>,\n) => Effect.Effect<A, E, R>;\n\ntype EffectAsyncFactory = <A, E = never, R = never>(\n register: (\n resume: EffectResume<A, E, R>,\n ) => void | Effect.Effect<void, never, R>,\n) => Effect.Effect<A, E, R>;\n\ntype CauseLike = {\n readonly reasons?: ReadonlyArray<unknown>;\n};\n\ntype FailReasonLike<ErrorType = unknown> = {\n readonly error: ErrorType;\n};\n\ntype StandardSchemaFactory = (\n schema: EffectSchemaLike,\n) => unknown;\n\nexport function make_context_key<Identifier, Service = Identifier>(\n key: string,\n): EffectContextKey<Identifier, Service> {\n const context_namespace = Context as {\n GenericTag?: <I, S = I>(key: string) => EffectContextKey<I, S>;\n Service?: <I, S = I>(key: string) => EffectContextKey<I, S>;\n };\n\n if (typeof context_namespace.Service === \"function\") {\n return context_namespace.Service<Identifier, Service>(key);\n }\n\n if (typeof context_namespace.GenericTag === \"function\") {\n return context_namespace.GenericTag<Identifier, Service>(key);\n }\n\n throw new Error(\"No compatible Effect context key constructor was found.\");\n}\n\nexport function to_standard_schema_v1(\n schema: EffectSchemaLike,\n): unknown {\n const schema_namespace = Schema as unknown as {\n standardSchemaV1?: StandardSchemaFactory;\n toStandardSchemaV1?: StandardSchemaFactory;\n };\n const factory = schema_namespace.toStandardSchemaV1 ??\n schema_namespace.standardSchemaV1;\n\n if (!factory) {\n throw new Error(\n \"No compatible standard schema adapter was found in effect/Schema.\",\n );\n }\n\n return factory(schema);\n}\n\nexport function create_async_effect<A, E = never, R = never>(\n register: (\n resume: EffectResume<A, E, R>,\n ) => void | Effect.Effect<void, never, R>,\n): Effect.Effect<A, E, R> {\n const effect_namespace = Effect as unknown as {\n readonly callback?: EffectCallbackFactory;\n readonly async?: EffectAsyncFactory;\n };\n\n if (typeof effect_namespace.callback === \"function\") {\n return effect_namespace.callback((resume, _signal) => register(resume));\n }\n\n if (typeof effect_namespace.async === \"function\") {\n return effect_namespace.async(register);\n }\n\n throw new Error(\"No compatible async Effect constructor was found.\");\n}\n\nexport function get_cause_failure<ErrorType>(\n cause: unknown,\n): ErrorType | undefined {\n const cause_namespace = Cause as {\n failureOption?: (cause: unknown) => Option.Option<ErrorType>;\n findFail?: (cause: unknown) => unknown;\n isFailReason?: (reason: unknown) => reason is FailReasonLike<ErrorType>;\n };\n\n if (typeof cause_namespace.failureOption === \"function\") {\n const failure = cause_namespace.failureOption(cause);\n return Option.isSome(failure) ? failure.value : undefined;\n }\n\n const fail_reason = get_fail_reason_from_cause(\n cause as CauseLike,\n cause_namespace.isFailReason,\n );\n\n if (fail_reason) {\n return fail_reason.error as ErrorType;\n }\n\n if (typeof cause_namespace.findFail === \"function\") {\n const result = cause_namespace.findFail(cause);\n const match = extract_success_value(result);\n\n if (is_fail_reason_like(match)) {\n return match.error as ErrorType;\n }\n }\n\n return undefined;\n}\n\nexport function exit_has_interrupts<A, E>(\n exit: Exit.Exit<A, E>,\n): boolean {\n const exit_namespace = Exit as unknown as {\n readonly hasInterrupts?: (exit: Exit.Exit<A, E>) => boolean;\n readonly isInterrupted?: (exit: Exit.Exit<A, E>) => boolean;\n };\n\n if (typeof exit_namespace.hasInterrupts === \"function\") {\n return exit_namespace.hasInterrupts(exit);\n }\n\n if (typeof exit_namespace.isInterrupted === \"function\") {\n return exit_namespace.isInterrupted(exit);\n }\n\n return false;\n}\n\nexport function get_effect_schema_field_names(\n schema: EffectSchemaLike,\n): ReadonlyArray<string> {\n if (schema.fields && typeof schema.fields === \"object\") {\n return Object.keys(schema.fields);\n }\n\n const get_property_signatures = Reflect.get(\n SchemaAST as object,\n \"getPropertySignatures\",\n ) as\n | ((ast: unknown) => ReadonlyArray<{ readonly name: unknown }>)\n | undefined;\n\n if (schema.ast && typeof get_property_signatures === \"function\") {\n return get_property_signatures(schema.ast)\n .map((property_signature) => property_signature.name)\n .filter((name): name is string => typeof name === \"string\");\n }\n\n const is_objects_ast = Reflect.get(\n SchemaAST as object,\n \"isObjects\",\n ) as ((ast: unknown) => boolean) | undefined;\n\n if (\n schema.ast &&\n typeof is_objects_ast === \"function\" &&\n is_objects_ast(schema.ast) &&\n Array.isArray(\n (schema.ast as { readonly propertySignatures?: unknown })\n .propertySignatures,\n )\n ) {\n return (\n schema.ast as {\n readonly propertySignatures: ReadonlyArray<{ readonly name: unknown }>;\n }\n ).propertySignatures\n .map((property_signature) => property_signature.name)\n .filter((name): name is string => typeof name === \"string\");\n }\n\n return [];\n}\n\nexport function to_transportable_data(\n value: unknown,\n seen = new WeakMap<object, unknown>(),\n): unknown {\n if (value === null || value === undefined || typeof value !== \"object\") {\n return value;\n }\n\n if (seen.has(value)) {\n return seen.get(value);\n }\n\n if (\n value instanceof Date ||\n value instanceof RegExp ||\n value instanceof URL ||\n value instanceof URLSearchParams ||\n value instanceof ArrayBuffer ||\n ArrayBuffer.isView(value)\n ) {\n return value;\n }\n\n if (value instanceof Map) {\n const normalized = new Map<unknown, unknown>();\n seen.set(value, normalized);\n\n for (const [key, entry] of value.entries()) {\n normalized.set(\n to_transportable_data(key, seen),\n to_transportable_data(entry, seen),\n );\n }\n\n return normalized;\n }\n\n if (value instanceof Set) {\n const normalized = new Set<unknown>();\n seen.set(value, normalized);\n\n for (const entry of value.values()) {\n normalized.add(to_transportable_data(entry, seen));\n }\n\n return normalized;\n }\n\n if (Array.isArray(value)) {\n const normalized: Array<unknown> = [];\n seen.set(value, normalized);\n\n for (const entry of value) {\n normalized.push(to_transportable_data(entry, seen));\n }\n\n return normalized;\n }\n\n const normalized: Record<string, unknown> = {};\n seen.set(value, normalized);\n\n const property_names = new Set<string>(Object.keys(value));\n\n if (value instanceof Error) {\n property_names.add(\"name\");\n property_names.add(\"message\");\n\n if (\"stack\" in value) {\n property_names.add(\"stack\");\n }\n\n if (\"cause\" in value) {\n property_names.add(\"cause\");\n }\n }\n\n for (const property_name of property_names) {\n const property_value = Reflect.get(value, property_name);\n\n if (property_value === undefined) {\n continue;\n }\n\n normalized[property_name] = to_transportable_data(property_value, seen);\n }\n\n return normalized;\n}\n\nfunction get_fail_reason_from_cause<ErrorType>(\n cause: CauseLike,\n is_fail_reason?: (reason: unknown) => reason is FailReasonLike<ErrorType>,\n): FailReasonLike<ErrorType> | undefined {\n if (!Array.isArray(cause.reasons)) {\n return undefined;\n }\n\n const match = cause.reasons.find((reason) =>\n is_fail_reason ? is_fail_reason(reason) : is_fail_reason_like(reason)\n );\n\n return is_fail_reason_like(match)\n ? match as FailReasonLike<ErrorType>\n : undefined;\n}\n\nfunction extract_success_value(result: unknown): unknown {\n if (!result || typeof result !== \"object\") {\n return undefined;\n }\n\n if (\n \"_tag\" in result &&\n (result as { readonly _tag?: unknown })._tag === \"Success\" &&\n \"value\" in result\n ) {\n return (result as { readonly value?: unknown }).value;\n }\n\n if (\n \"_tag\" in result &&\n (result as { readonly _tag?: unknown })._tag === \"Right\" &&\n \"right\" in result\n ) {\n return (result as { readonly right?: unknown }).right;\n }\n\n if (\"value\" in result) {\n return (result as { readonly value?: unknown }).value;\n }\n\n return undefined;\n}\n\nfunction is_fail_reason_like(value: unknown): value is FailReasonLike {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n \"error\" in value,\n );\n}\n"],"mappings":";;AA4CA,SAAgB,iBACd,KACuC;CACvC,MAAM,oBAAoB;AAK1B,KAAI,OAAO,kBAAkB,YAAY,WACvC,QAAO,kBAAkB,QAA6B,IAAI;AAG5D,KAAI,OAAO,kBAAkB,eAAe,WAC1C,QAAO,kBAAkB,WAAgC,IAAI;AAG/D,OAAM,IAAI,MAAM,0DAA0D;;AAG5E,SAAgB,sBACd,QACS;CACT,MAAM,mBAAmB;CAIzB,MAAM,UAAU,iBAAiB,sBAC/B,iBAAiB;AAEnB,KAAI,CAAC,QACH,OAAM,IAAI,MACR,oEACD;AAGH,QAAO,QAAQ,OAAO;;AAGxB,SAAgB,oBACd,UAGwB;CACxB,MAAM,mBAAmB;AAKzB,KAAI,OAAO,iBAAiB,aAAa,WACvC,QAAO,iBAAiB,UAAU,QAAQ,YAAY,SAAS,OAAO,CAAC;AAGzE,KAAI,OAAO,iBAAiB,UAAU,WACpC,QAAO,iBAAiB,MAAM,SAAS;AAGzC,OAAM,IAAI,MAAM,oDAAoD;;AAGtE,SAAgB,kBACd,OACuB;CACvB,MAAM,kBAAkB;AAMxB,KAAI,OAAO,gBAAgB,kBAAkB,YAAY;EACvD,MAAM,UAAU,gBAAgB,cAAc,MAAM;AACpD,SAAO,OAAO,OAAO,QAAQ,GAAG,QAAQ,QAAQ,KAAA;;CAGlD,MAAM,cAAc,2BAClB,OACA,gBAAgB,aACjB;AAED,KAAI,YACF,QAAO,YAAY;AAGrB,KAAI,OAAO,gBAAgB,aAAa,YAAY;EAElD,MAAM,QAAQ,sBADC,gBAAgB,SAAS,MAAM,CACH;AAE3C,MAAI,oBAAoB,MAAM,CAC5B,QAAO,MAAM;;;AAOnB,SAAgB,oBACd,MACS;CACT,MAAM,iBAAiB;AAKvB,KAAI,OAAO,eAA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AQ,OAAwC;;AAMpD,SAAS,oBAAoB,OAAyC;AACpE,QAAO,QACL,SACE,OAAO,UAAU,YACjB,WAAW,MACd"}
@@ -1010,4 +1010,4 @@ var MagicString = class MagicString {
1010
1010
  //#endregion
1011
1011
  export { MagicString as t };
1012
1012
 
1013
- //# sourceMappingURL=magic-string.es-5gRBdMgP.js.map
1013
+ //# sourceMappingURL=magic-string.es-BnGH-5YR.js.map