svelte-effect-runtime 4.1.1 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.dist/chunks/{client-DbwVAMWm.js → client-CkxjaRTA.js} +2 -2
  2. package/.dist/chunks/{client-DbwVAMWm.js.map → client-CkxjaRTA.js.map} +1 -1
  3. package/.dist/chunks/{dispatcher-CTWINW5I.js → dispatcher-B6ZRUsjN.js} +139 -44
  4. package/.dist/chunks/dispatcher-B6ZRUsjN.js.map +1 -0
  5. package/.dist/chunks/{dispatcher-pZPzarul.js → dispatcher-D8j5wTx6.js} +3 -3
  6. package/.dist/chunks/{dispatcher-pZPzarul.js.map → dispatcher-D8j5wTx6.js.map} +1 -1
  7. package/.dist/chunks/{runtime-CPosEhGl.js → runtime-B8RHHy3v.js} +2 -2
  8. package/.dist/chunks/{runtime-CPosEhGl.js.map → runtime-B8RHHy3v.js.map} +1 -1
  9. package/.dist/chunks/server-NeyeDSax.js +339 -0
  10. package/.dist/chunks/server-NeyeDSax.js.map +1 -0
  11. package/.dist/chunks/{transform-D7TTlPpK.js → transform-C0jW8Qta.js} +38 -5
  12. package/.dist/chunks/transform-C0jW8Qta.js.map +1 -0
  13. package/.dist/dispatcher.js +1 -1
  14. package/.dist/environment.d.ts +87 -0
  15. package/.dist/environment.js +44 -0
  16. package/.dist/environment.js.map +1 -0
  17. package/.dist/internal/generators.js +2 -2
  18. package/.dist/internal/remote-client.js +1 -1
  19. package/.dist/internal/remote-server.js +2 -2
  20. package/.dist/markup/promise.js +1 -1
  21. package/.dist/markup/run.js +1 -1
  22. package/.dist/markup/transform.js +1 -1
  23. package/.dist/markup/value.js +1 -1
  24. package/.dist/mod.d.ts +2 -0
  25. package/.dist/mod.js +3 -2
  26. package/.dist/mod.js.map +1 -1
  27. package/.dist/remote/cause-codec.d.ts +35 -0
  28. package/.dist/remote/client.js +1 -1
  29. package/.dist/remote/diagnostics.d.ts +67 -0
  30. package/.dist/remote/server.d.ts +26 -2
  31. package/.dist/remote/server.js +2 -2
  32. package/.dist/runtime/transform.js +8 -5
  33. package/.dist/runtime/transform.js.map +1 -1
  34. package/.dist/script-transform/imports.d.ts +1 -1
  35. package/.dist/server.js +6 -6
  36. package/.dist/server.js.map +1 -1
  37. package/package.json +5 -1
  38. package/.dist/chunks/dispatcher-CTWINW5I.js.map +0 -1
  39. package/.dist/chunks/server-yQrNoiCR.js +0 -144
  40. package/.dist/chunks/server-yQrNoiCR.js.map +0 -1
  41. package/.dist/chunks/transform-D7TTlPpK.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatcher-B6ZRUsjN.js","names":["#on_dispose","#scope","#disposed","#notify_value_cells","#runtime","#root_scope","#component_scopes","#current_scope","#disposed","#scope_ids","#clear_scope_cache","#emit_markup_value","#emit_markup_promise","#emit_markup_run","#next_fiber_id","#fibers","#scope_id","#make_scoped_id","#make_value_cache_key","#value_ids","#subscribe_value_cells","#value_cells","#interrupt_cached_fiber","#clear_pending_value_cell","#should_start_value_fiber","#start_value_fiber","#make_promise_cache_key","#promise_ids","#promise_values","#start_promise_fiber","#is_server_render","#clear_value_cells","#hash_deps","#next_scope_id","#delete_value_cell","#is_current_fiber","#set_value_cell","#complete_fiber","#publish_value_success","#publish_value_failure","#get_dispatcher","#scope"],"sources":["../../../modules/svelte-effect-runtime/src/dispatcher/fibers.ts","../../../modules/svelte-effect-runtime/src/dispatcher/scope.ts","../../../modules/svelte-effect-runtime/src/dispatcher/deps.ts","../../../modules/svelte-effect-runtime/src/dispatcher/types.ts","../../../modules/svelte-effect-runtime/src/dispatcher/index.ts"],"sourcesContent":["import type { Fiber as FiberType } from \"effect/Fiber\";\nimport { Cause, Effect, Exit, Fiber } from \"effect\";\n\nexport interface FiberWatchCallbacks<A> {\n\ton_complete?: () => void;\n\ton_success?: (value: A) => void;\n\ton_failure?: (error: unknown) => void;\n\tsurface_failure?: boolean;\n}\n\nexport const InterruptFiber = (fiber: FiberType<unknown, unknown>) =>\n\tEffect.gen(function* () {\n\t\tyield* Fiber.interrupt(fiber);\n\t});\n\n/** Observes fiber completion and surfaces failures without taking ownership of the fiber. */\nexport const WatchFiberExit = <A>(\n\toptions: { fiber: FiberType<unknown, unknown> } & FiberWatchCallbacks<A>,\n) => {\n\tconst { fiber, on_complete, on_success, on_failure, surface_failure = true } = options;\n\n\treturn Effect.gen(function* () {\n\t\tconst exit = yield* Fiber.await(fiber);\n\n\t\tyield* Effect.sync(() => {\n\t\t\tif (Exit.isSuccess(exit)) {\n\t\t\t\ton_success?.(exit.value as A);\n\t\t\t\ton_complete?.();\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!Cause.hasInterruptsOnly(exit.cause)) {\n\t\t\t\tconst error = Cause.squash(exit.cause);\n\n\t\t\t\ton_failure?.(error);\n\n\t\t\t\tif (surface_failure) {\n\t\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ton_complete?.();\n\t\t});\n\t});\n};\n","import { Effect, Exit, Scope } from \"effect\";\nimport type { Fiber } from \"effect\";\n\n/**\n * A component-owned Effect scope.\n *\n * A `ComponentScope` wraps a `Scope.Closeable` forked from the dispatcher's\n * root scope. Work is forked into the scope with `Effect.forkIn`, so closing\n * the scope interrupts that work and runs its finalizers. The generated\n * component teardown disposes the scope on destroy. Disposal is idempotent.\n *\n * @since 4.1.0\n */\nexport class ComponentScope {\n\t#scope: Scope.Closeable;\n\t#disposed = false;\n\treadonly #on_dispose: (scope: ComponentScope) => void;\n\n\tprivate constructor(scope: Scope.Closeable, on_dispose: (scope: ComponentScope) => void) {\n\t\tthis.#scope = scope;\n\t\tthis.#on_dispose = on_dispose;\n\t}\n\n\t/** Forks a child scope from the given root and returns it wrapped. */\n\tstatic fork(\n\t\troot: Scope.Closeable,\n\t\ton_dispose: (scope: ComponentScope) => void,\n\t): ComponentScope {\n\t\treturn new ComponentScope(Scope.forkUnsafe(root), on_dispose);\n\t}\n\n\t/** The underlying closeable scope used to bind Effect work. */\n\tget underlying(): Scope.Closeable {\n\t\treturn this.#scope;\n\t}\n\n\t/** Whether this scope has already been disposed. */\n\tget disposed(): boolean {\n\t\treturn this.#disposed;\n\t}\n\n\t/**\n\t * Forks an effect into this scope. The fiber becomes a child of the scope,\n\t * so disposing the scope interrupts it and runs its finalizers. The scope\n\t * is provided ambiently so `Effect.forkIn` registers the fiber as a child.\n\t */\n\tfork_in<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<Fiber.Fiber<A, E>, never, R> {\n\t\t/**\n\t\t * The effect must see the scope before it is forked: provide the scope\n\t\t * inside the forked program so `acquireRelease`-style work resolves it,\n\t\t * and fork that program into the scope so the fiber is a child whose\n\t\t * finalizers run when the scope closes.\n\t\t */\n\t\treturn Effect.forkIn(\n\t\t\tEffect.provideService(effect, Scope.Scope, this.#scope),\n\t\t\tthis.#scope,\n\t\t) as Effect.Effect<Fiber.Fiber<A, E>, never, R>;\n\t}\n\n\t/** Effect that closes the scope. Must be run by the owning dispatcher. */\n\tget close_effect(): Effect.Effect<void> {\n\t\treturn Scope.close(this.#scope, Exit.void);\n\t}\n\n\t/**\n\t * Marks the scope disposed and detaches it from the dispatcher. The caller\n\t * is responsible for running {@link close_effect} to run finalizers.\n\t * Idempotent.\n\t */\n\tdispose(): void {\n\t\tif (this.#disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#disposed = true;\n\t\tthis.#on_dispose(this);\n\t}\n}\n","/** Assigns stable identities to object dependencies while hashing value dependencies. */\nexport type DependencyHasher = (deps: readonly unknown[]) => string;\n\nexport function make_dependency_hasher(): DependencyHasher {\n\tconst object_dep_ids = new WeakMap<object, number>();\n\tconst symbol_dep_ids = new Map<symbol, number>();\n\n\tlet next_object_dep_id = 0;\n\tlet next_symbol_dep_id = 0;\n\n\tconst hash_symbol_dep = (dep: symbol): string => {\n\t\tlet id = symbol_dep_ids.get(dep);\n\n\t\tif (id === undefined) {\n\t\t\tnext_symbol_dep_id += 1;\n\t\t\tid = next_symbol_dep_id;\n\t\t\tsymbol_dep_ids.set(dep, id);\n\t\t}\n\n\t\treturn `y:${id}`;\n\t};\n\n\tconst hash_object_dep = (dep: object): string => {\n\t\tlet id = object_dep_ids.get(dep);\n\n\t\tif (id === undefined) {\n\t\t\tnext_object_dep_id += 1;\n\t\t\tid = next_object_dep_id;\n\t\t\tobject_dep_ids.set(dep, id);\n\t\t}\n\n\t\treturn `o:${id}`;\n\t};\n\n\tconst hash_dep = (dep: unknown): string | readonly [\"s\", string] => {\n\t\tif (dep === null) {\n\t\t\treturn \"l:null\";\n\t\t}\n\n\t\tif (dep === undefined) {\n\t\t\treturn \"u:undefined\";\n\t\t}\n\n\t\tconst type = typeof dep;\n\n\t\tif (type === \"string\") {\n\t\t\treturn [\"s\", dep as string];\n\t\t}\n\n\t\tif (type === \"number\") {\n\t\t\treturn `n:${Object.is(dep, -0) ? \"-0\" : String(dep)}`;\n\t\t}\n\n\t\tif (type === \"bigint\") {\n\t\t\treturn `b:${dep}`;\n\t\t}\n\n\t\tif (type === \"boolean\") {\n\t\t\treturn dep ? \"t:true\" : \"f:false\";\n\t\t}\n\n\t\tif (type === \"symbol\") {\n\t\t\treturn hash_symbol_dep(dep as symbol);\n\t\t}\n\n\t\treturn hash_object_dep(dep as object);\n\t};\n\n\tconst hash_deps = (deps: readonly unknown[]): string => JSON.stringify(deps.map(hash_dep));\n\n\treturn hash_deps;\n}\n","import type { Effect } from \"effect\";\n\nexport const Code = {\n\tMarkup: {\n\t\tPromise: \"MarkupPromise\",\n\t\tRun: \"MarkupRun\",\n\t\tValue: \"MarkupValue\",\n\t},\n} as const;\n\nexport interface MarkupPromiseOptions {\n\t/** Keep the SSR promise pending so Svelte renders an await block fallback. */\n\tssr?: \"pending\";\n}\n\nexport type Dispose = () => void;\n\nexport interface ValueOptions<A> {\n\t/** Stable cache key for this value block. */\n\tid: string;\n\tdeps: readonly unknown[];\n\t/** Value returned synchronously while the effect is running or during SSR. */\n\tfallback: A;\n\tfactory: () => Effect.gen.Return<A, unknown, unknown>;\n}\n\nexport interface PromiseOptions<A> {\n\t/** Stable cache key for this promise block. */\n\tid: string;\n\tdeps: readonly unknown[];\n\tfactory: () => Effect.gen.Return<A, unknown, unknown>;\n}\n\nexport interface MarkupValueEvent<A, F> {\n\ttype: typeof Code.Markup.Value;\n\t/** Stable identifier generated from the expression's source position. */\n\tid: string;\n\tdeps: readonly unknown[];\n\t/** Value returned synchronously while the effect is pending. */\n\tfallback: F;\n\tfn: () => Effect.gen.Return<A, unknown, unknown>;\n}\n\nexport interface MarkupPromiseEvent<A> {\n\ttype: typeof Code.Markup.Promise;\n\t/** Stable identifier generated from the expression's source position. */\n\tid: string;\n\tdeps: readonly unknown[];\n\tfn: () => Effect.gen.Return<A, unknown, unknown>;\n\t/** Value resolved during SSR when a fallback is required. */\n\tssr_fallback?: A;\n\t/** Optional SSR behavior for await blocks and similar contexts. */\n\toptions?: MarkupPromiseOptions;\n}\n\nexport interface MarkupRunEvent<A> {\n\ttype: typeof Code.Markup.Run;\n\tfn: () => Effect.gen.Return<A, unknown, unknown>;\n}\n\nexport type DispatcherEvent<A, F = A> =\n\t| MarkupPromiseEvent<A>\n\t| MarkupRunEvent<A>\n\t| MarkupValueEvent<A, F>;\n","import type {\n\tDispatcherEvent,\n\tDispose,\n\tMarkupPromiseEvent,\n\tMarkupRunEvent,\n\tMarkupValueEvent,\n\tPromiseOptions,\n\tValueOptions,\n} from \"./types.ts\";\nimport {\n\tRuntimeAlreadyInitializedError,\n\tDispatcherDisposedError,\n\tScopeDisposedError,\n} from \"$/errors.ts\";\nimport type { ManagedRuntime as ManagedRuntimeType } from \"effect/ManagedRuntime\";\nimport { Cause, Effect, Exit, Fiber, Layer, ManagedRuntime, Scope } from \"effect\";\nimport { InterruptFiber, WatchFiberExit } from \"./fibers.ts\";\nimport { ComponentScope } from \"./scope.ts\";\nimport type { Fiber as FiberType } from \"effect/Fiber\";\nimport { createSubscriber } from \"svelte/reactivity\";\nimport { make_dependency_hasher } from \"./deps.ts\";\nimport { isRedirect } from \"@sveltejs/kit\";\nimport { Code } from \"./types.ts\";\n\nexport { Code } from \"./types.ts\";\nexport type { Dispose, PromiseOptions, ValueOptions } from \"./types.ts\";\n\ntype ValueCell<A> =\n\t| {\n\t\t\treadonly status: \"pending\";\n\t\t\treadonly fiber: FiberType<unknown, unknown>;\n\t }\n\t| {\n\t\t\treadonly status: \"success\";\n\t\t\treadonly value: A;\n\t }\n\t| {\n\t\t\treadonly status: \"failure\";\n\t\t\treadonly error: unknown;\n\t };\n\nexport class Dispatcher {\n\t#runtime: ManagedRuntimeType<unknown, unknown>;\n\t#fibers = new Map<string, FiberType<unknown, unknown>>();\n\t#value_cells = new Map<string, ValueCell<unknown>>();\n\t#notify_value_cells = (): void => {};\n\t#subscribe_value_cells = createSubscriber((update) => {\n\t\tthis.#notify_value_cells = update;\n\n\t\treturn () => {\n\t\t\tif (this.#notify_value_cells !== update) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#notify_value_cells = (): void => {};\n\t\t};\n\t});\n\t#promise_values = new Map<string, Promise<unknown>>();\n\t#value_ids = new Map<string, string>();\n\t#promise_ids = new Map<string, string>();\n\t#scope_ids = new WeakMap<ComponentScope, string>();\n\t#hash_deps = make_dependency_hasher();\n\t#disposed = false;\n\t#next_fiber_id = 0;\n\t#next_scope_id = 0;\n\t#root_scope = Scope.makeUnsafe();\n\t#component_scopes = new Set<ComponentScope>();\n\t/**\n\t * The component scope that effect execution currently enters. Set by\n\t * generated code via {@link with_scope}; `undefined` outside components.\n\t */\n\t#current_scope: ComponentScope | undefined = undefined;\n\n\tstatic make<R = never>(layer?: Layer.Layer<R>): Dispatcher {\n\t\tif (current_dispatcher) {\n\t\t\tthrow new RuntimeAlreadyInitializedError(\"ClientRuntime\");\n\t\t}\n\n\t\tconst runtime = ManagedRuntime.make(layer ?? (Layer.empty as unknown as Layer.Layer<R>));\n\n\t\tconst dispatcher = new Dispatcher(runtime as ManagedRuntimeType<unknown, unknown>);\n\t\tcurrent_dispatcher = dispatcher;\n\n\t\treturn dispatcher;\n\t}\n\n\tconstructor(runtime?: ManagedRuntimeType<unknown, unknown>) {\n\t\tthis.#runtime =\n\t\t\truntime ??\n\t\t\t(ManagedRuntime.make(Layer.empty) as unknown as ManagedRuntimeType<unknown, unknown>);\n\t}\n\n\t/**\n\t * Begin a component-owned Effect scope. Pass the returned scope to\n\t * {@link run_scoped} so the work is interrupted and finalized when the\n\t * component is destroyed. Disposal is idempotent.\n\t */\n\tbegin_scope(): ComponentScope {\n\t\tconst scope = ComponentScope.fork(this.#root_scope, (disposed) => {\n\t\t\tthis.#component_scopes.delete(disposed);\n\t\t});\n\n\t\tthis.#component_scopes.add(scope);\n\n\t\treturn scope;\n\t}\n\n\t/**\n\t * Runs `fn` with `scope` as the current component scope. While active,\n\t * every effect path ({@link promise}, {@link run}, {@link value}) forks\n\t * its work into `scope` so disposing the scope interrupts it and runs its\n\t * finalizers. A disposed scope falls back to unscoped execution.\n\t */\n\twith_scope<T>(scope: ComponentScope, fn: () => T): T {\n\t\tif (scope.disposed) {\n\t\t\treturn fn();\n\t\t}\n\n\t\tconst previous = this.#current_scope;\n\t\tthis.#current_scope = scope;\n\n\t\ttry {\n\t\t\treturn fn();\n\t\t} finally {\n\t\t\tthis.#current_scope = previous;\n\t\t}\n\t}\n\n\t/**\n\t * Forks an effect into a component scope and starts it. The fiber becomes\n\t * a child of the scope, so disposing the scope interrupts it and runs its\n\t * finalizers. Returns an idempotent handle that interrupts the scoped\n\t * fiber directly.\n\t *\n\t * Throws {@link ScopeDisposedError} when the scope was already disposed\n\t * and {@link DispatcherDisposedError} when the dispatcher was shut down.\n\t */\n\trun_scoped<A, E, R>(scope: ComponentScope, effect: Effect.Effect<A, E, R>): Dispose {\n\t\tif (this.#disposed) {\n\t\t\treturn () => {};\n\t\t}\n\n\t\tif (scope.disposed || !this.#component_scopes.has(scope)) {\n\t\t\tthrow new ScopeDisposedError();\n\t\t}\n\n\t\t/**\n\t\t * Track the scoped fiber itself: `forkIn` binds it to the component\n\t\t * scope rather than the awaiting parent, so per-run disposal must\n\t\t * interrupt the scoped fiber directly.\n\t\t */\n\t\tlet scoped_fiber: FiberType<unknown, unknown> | undefined;\n\n\t\tthis.#runtime.runFork(\n\t\t\tEffect.flatMap(scope.fork_in(effect), (fiber) => {\n\t\t\t\tscoped_fiber = fiber;\n\n\t\t\t\treturn Effect.asVoid(Fiber.await(fiber));\n\t\t\t}) as Effect.Effect<unknown, unknown, unknown>,\n\t\t);\n\n\t\tlet disposed = false;\n\n\t\treturn (): void => {\n\t\t\tif (disposed) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tdisposed = true;\n\n\t\t\tif (scoped_fiber) {\n\t\t\t\tthis.#runtime.runFork(InterruptFiber(scoped_fiber));\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Disposes a component scope owned by this dispatcher, interrupting its\n\t * bound work and running its finalizers. Idempotent. Rejects scopes owned\n\t * by another dispatcher with {@link ScopeDisposedError}.\n\t */\n\tdispose_scope(scope: ComponentScope): void {\n\t\tif (!this.#component_scopes.has(scope)) {\n\t\t\tif (scope.disposed) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthrow new ScopeDisposedError();\n\t\t}\n\n\t\tconst scope_id = this.#scope_ids.get(scope);\n\n\t\tif (scope_id !== undefined) {\n\t\t\tthis.#scope_ids.delete(scope);\n\t\t\tthis.#clear_scope_cache(scope_id);\n\t\t}\n\n\t\tscope.dispose();\n\t\tthis.#runtime.runFork(scope.close_effect as Effect.Effect<unknown, unknown, unknown>);\n\t}\n\n\temit<A, F>(event: MarkupValueEvent<A, F>): A | F;\n\temit<A>(event: MarkupPromiseEvent<A>): Promise<A>;\n\temit<A>(event: MarkupRunEvent<A>): Promise<A>;\n\temit<A, F>(event: DispatcherEvent<A, F>): A | F | Promise<A>;\n\temit<A, F>(event: DispatcherEvent<A, F>): A | F | Promise<A> {\n\t\tswitch (event.type) {\n\t\t\tcase Code.Markup.Value:\n\t\t\t\treturn this.#emit_markup_value(event);\n\n\t\t\tcase Code.Markup.Promise:\n\t\t\t\treturn this.#emit_markup_promise(event);\n\n\t\t\tcase Code.Markup.Run:\n\t\t\t\treturn this.#emit_markup_run(event);\n\t\t}\n\t}\n\n\tfork<A, E, R>(effect: Effect.Effect<A, E, R>): Dispose {\n\t\tif (this.#disposed) {\n\t\t\treturn () => {};\n\t\t}\n\n\t\tconst fiber = this.#runtime.runFork(effect as Effect.Effect<unknown, unknown, unknown>);\n\t\tconst key = `fork:${this.#next_fiber_id}`;\n\n\t\tthis.#next_fiber_id += 1;\n\t\tthis.#fibers.set(key, fiber);\n\t\tthis.#runtime.runFork(\n\t\t\tWatchFiberExit({\n\t\t\t\tfiber,\n\t\t\t\ton_complete: () => this.#fibers.delete(key),\n\t\t\t}),\n\t\t);\n\n\t\tlet disposed = false;\n\n\t\treturn (): void => {\n\t\t\tif (disposed) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tdisposed = true;\n\t\t\tthis.#runtime.runFork(InterruptFiber(fiber));\n\t\t};\n\t}\n\n\tvalue<A>(options: ValueOptions<A>): A {\n\t\tif (this.#disposed) {\n\t\t\treturn options.fallback;\n\t\t}\n\n\t\tconst scope_id = this.#scope_id(this.#current_scope);\n\t\tconst cache_id = this.#make_scoped_id(scope_id, options.id);\n\t\tconst cache_key = this.#make_value_cache_key(cache_id, options.deps);\n\t\tconst old_key = this.#value_ids.get(cache_id);\n\n\t\tthis.#subscribe_value_cells();\n\n\t\tconst cell = this.#value_cells.get(cache_key);\n\n\t\tif (old_key !== undefined && old_key !== cache_key) {\n\t\t\tconst old_fiber = this.#interrupt_cached_fiber(old_key);\n\n\t\t\tthis.#clear_pending_value_cell(old_key, old_fiber);\n\t\t}\n\n\t\tthis.#value_ids.set(cache_id, cache_key);\n\n\t\tif (this.#should_start_value_fiber(cache_key, cell)) {\n\t\t\tthis.#start_value_fiber(cache_key, options);\n\t\t}\n\n\t\tif (cell?.status === \"success\") {\n\t\t\treturn cell.value as A;\n\t\t}\n\n\t\tif (cell?.status === \"failure\") {\n\t\t\tthrow cell.error;\n\t\t}\n\n\t\treturn options.fallback;\n\t}\n\n\tpromise<A>(options: PromiseOptions<A>): Promise<A> {\n\t\tif (this.#disposed) {\n\t\t\treturn Promise.reject(new DispatcherDisposedError());\n\t\t}\n\n\t\tconst scope_id = this.#scope_id(this.#current_scope);\n\t\tconst cache_id = this.#make_scoped_id(scope_id, options.id);\n\t\tconst cache_key = this.#make_promise_cache_key(cache_id, options.deps);\n\t\tconst old_key = this.#promise_ids.get(cache_id);\n\n\t\tif (old_key !== undefined && old_key !== cache_key) {\n\t\t\tthis.#interrupt_cached_fiber(old_key);\n\t\t\tthis.#promise_values.delete(old_key);\n\t\t}\n\n\t\tthis.#promise_ids.set(cache_id, cache_key);\n\n\t\tconst existing = this.#promise_values.get(cache_key);\n\n\t\tif (existing) {\n\t\t\treturn existing as Promise<A>;\n\t\t}\n\n\t\tconst promise = this.#start_promise_fiber(cache_key, options, cache_id);\n\n\t\tthis.#promise_values.set(cache_key, promise);\n\n\t\treturn promise;\n\t}\n\n\trun<A, E, R>(effect: Effect.Effect<A, E, R>): Promise<A> {\n\t\tif (this.#disposed) {\n\t\t\treturn Promise.reject(new DispatcherDisposedError());\n\t\t}\n\n\t\tconst scoped_effect = Effect.gen(function* () {\n\t\t\tconst result = yield* Effect.exit(effect);\n\n\t\t\tif (Exit.isSuccess(result)) {\n\t\t\t\treturn result.value;\n\t\t\t}\n\n\t\t\tif (Cause.hasInterruptsOnly(result.cause)) {\n\t\t\t\treturn undefined as A;\n\t\t\t}\n\n\t\t\tconst error = Cause.squash(result.cause);\n\n\t\t\tif (isRedirect(error)) {\n\t\t\t\treturn undefined as A;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Surface the failure without reporting it. Both the scoped and the\n\t\t\t * unscoped path funnel through `interpreted_program`, which reports\n\t\t\t * once, so reporting here would raise every failure twice.\n\t\t\t */\n\t\t\treturn yield* Effect.fail(error);\n\t\t});\n\n\t\tconst scope = this.#current_scope;\n\t\tconst materialized_program = scope\n\t\t\t? Effect.flatMap(scope.fork_in(scoped_effect), (fiber) => Fiber.await(fiber))\n\t\t\t: Effect.exit(scoped_effect);\n\t\tconst interpreted_program = Effect.gen(function* () {\n\t\t\tconst result = yield* materialized_program;\n\n\t\t\tif (Exit.isSuccess(result)) {\n\t\t\t\treturn result.value;\n\t\t\t}\n\n\t\t\tif (Cause.hasInterruptsOnly(result.cause)) {\n\t\t\t\treturn undefined as A;\n\t\t\t}\n\n\t\t\tconst error = Cause.squash(result.cause);\n\n\t\t\tif (isRedirect(error)) {\n\t\t\t\treturn undefined as A;\n\t\t\t}\n\n\t\t\tyield* Effect.sync(() => {\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t\t});\n\n\t\t\treturn yield* Effect.fail(error);\n\t\t});\n\n\t\treturn this.#runtime.runPromise(interpreted_program as Effect.Effect<A, unknown, unknown>);\n\t}\n\n\t#emit_markup_value<A, F>(event: MarkupValueEvent<A, F>): A | F {\n\t\tif (this.#is_server_render()) {\n\t\t\treturn event.fallback;\n\t\t}\n\n\t\treturn this.value<A | F>({\n\t\t\tid: event.id,\n\t\t\tdeps: event.deps,\n\t\t\tfallback: event.fallback,\n\t\t\tfactory: event.fn,\n\t\t});\n\t}\n\n\t#emit_markup_promise<A>(event: MarkupPromiseEvent<A>): Promise<A> {\n\t\tif (this.#is_server_render()) {\n\t\t\tif (event.options?.ssr === \"pending\") {\n\t\t\t\treturn new Promise<A>(() => {});\n\t\t\t}\n\n\t\t\tif (\"ssr_fallback\" in event) {\n\t\t\t\treturn Promise.resolve(event.ssr_fallback as A);\n\t\t\t}\n\t\t}\n\n\t\treturn this.promise({\n\t\t\tid: event.id,\n\t\t\tdeps: event.deps,\n\t\t\tfactory: event.fn,\n\t\t});\n\t}\n\n\t#emit_markup_run<A>(event: MarkupRunEvent<A>): Promise<A> {\n\t\tconst Program = Effect.gen(event.fn);\n\n\t\treturn this.run(Program);\n\t}\n\n\tdispose(): void {\n\t\tthis.#disposed = true;\n\n\t\tfor (const scope of this.#component_scopes) {\n\t\t\tscope.dispose();\n\t\t}\n\n\t\tthis.#component_scopes.clear();\n\t\tthis.#runtime.runFork(\n\t\t\tScope.close(this.#root_scope, Exit.void) as Effect.Effect<unknown, unknown, unknown>,\n\t\t);\n\n\t\tfor (const fiber of this.#fibers.values()) {\n\t\t\tthis.#runtime.runFork(InterruptFiber(fiber));\n\t\t}\n\n\t\tthis.#fibers.clear();\n\t\tthis.#clear_value_cells();\n\t\tthis.#promise_values.clear();\n\t\tthis.#value_ids.clear();\n\t\tthis.#promise_ids.clear();\n\n\t\tvoid this.#runtime.dispose().catch((error: unknown) => {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t});\n\t}\n\n\t#make_value_cache_key(id: string, deps: readonly unknown[]): string {\n\t\treturn `value:${id}::${this.#hash_deps(deps)}`;\n\t}\n\n\t#make_promise_cache_key(id: string, deps: readonly unknown[]): string {\n\t\treturn `promise:${id}::${this.#hash_deps(deps)}`;\n\t}\n\n\t#is_server_render(): boolean {\n\t\treturn typeof document === \"undefined\";\n\t}\n\n\t#scope_id(scope: ComponentScope | undefined): string {\n\t\tif (!scope || scope.disposed) {\n\t\t\treturn \"global\";\n\t\t}\n\n\t\tconst existing = this.#scope_ids.get(scope);\n\n\t\tif (existing) {\n\t\t\treturn existing;\n\t\t}\n\n\t\tconst next = String(this.#next_scope_id);\n\t\tthis.#next_scope_id += 1;\n\t\tthis.#scope_ids.set(scope, next);\n\n\t\treturn next;\n\t}\n\n\t#clear_scope_cache(scope_id: string): void {\n\t\tconst value_prefix = `${scope_id}|`;\n\t\tconst promise_prefix = `${scope_id}|`;\n\n\t\tfor (const [cache_id, cache_key] of this.#value_ids) {\n\t\t\tif (!cache_id.startsWith(value_prefix)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tthis.#value_ids.delete(cache_id);\n\t\t\tthis.#interrupt_cached_fiber(cache_key);\n\t\t\tthis.#delete_value_cell(cache_key);\n\t\t}\n\n\t\tfor (const [cache_id, cache_key] of this.#promise_ids) {\n\t\t\tif (!cache_id.startsWith(promise_prefix)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tthis.#promise_ids.delete(cache_id);\n\t\t\tthis.#promise_values.delete(cache_key);\n\t\t\tthis.#interrupt_cached_fiber(cache_key);\n\t\t}\n\n\t\t/**\n\t\t * The id maps only name the newest key per entry, so a scope whose\n\t\t * dependencies changed leaves the settled cells of every superseded key\n\t\t * behind. Sweep the caches themselves so unmounting releases them all.\n\t\t */\n\t\tconst value_key_prefix = `value:${scope_id}|`;\n\t\tconst promise_key_prefix = `promise:${scope_id}|`;\n\n\t\tfor (const cache_key of [...this.#value_cells.keys()]) {\n\t\t\tif (!cache_key.startsWith(value_key_prefix)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tthis.#interrupt_cached_fiber(cache_key);\n\t\t\tthis.#delete_value_cell(cache_key);\n\t\t}\n\n\t\tfor (const cache_key of [...this.#promise_values.keys()]) {\n\t\t\tif (!cache_key.startsWith(promise_key_prefix)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tthis.#interrupt_cached_fiber(cache_key);\n\t\t\tthis.#promise_values.delete(cache_key);\n\t\t}\n\t}\n\n\t#make_scoped_id(scope_id: string, id: string): string {\n\t\treturn `${scope_id}|${id}`;\n\t}\n\n\t#interrupt_cached_fiber(cache_key: string): FiberType<unknown, unknown> | undefined {\n\t\tconst old_fiber = this.#fibers.get(cache_key);\n\n\t\tif (!old_fiber) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tthis.#runtime.runFork(InterruptFiber(old_fiber));\n\t\tthis.#fibers.delete(cache_key);\n\n\t\treturn old_fiber;\n\t}\n\n\t#should_start_value_fiber(cache_key: string, cell: ValueCell<unknown> | undefined): boolean {\n\t\treturn !this.#disposed && !this.#fibers.has(cache_key) && cell === undefined;\n\t}\n\n\t#start_value_fiber<A>(cache_key: string, options: ValueOptions<A>): void {\n\t\tconst Program = Effect.gen(function* () {\n\t\t\tconst result = yield* Effect.gen(options.factory);\n\n\t\t\treturn result;\n\t\t});\n\t\tconst scope = this.#current_scope;\n\n\t\tif (!scope) {\n\t\t\tconst fiber = this.#runtime.runFork(\n\t\t\t\tProgram as Effect.Effect<unknown, unknown, unknown>,\n\t\t\t);\n\n\t\t\tthis.#fibers.set(cache_key, fiber);\n\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tif (!this.#is_current_fiber(cache_key, fiber)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (this.#value_cells.has(cache_key)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.#set_value_cell(cache_key, {\n\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\tfiber,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tthis.#runtime.runFork(\n\t\t\t\tWatchFiberExit({\n\t\t\t\t\tfiber,\n\t\t\t\t\tsurface_failure: false,\n\t\t\t\t\ton_complete: () => this.#complete_fiber(cache_key, fiber),\n\t\t\t\t\ton_success: (value) => this.#publish_value_success(cache_key, fiber, value),\n\t\t\t\t\ton_failure: (error) => this.#publish_value_failure(cache_key, fiber, error),\n\t\t\t\t}),\n\t\t\t);\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst launch_fiber = this.#runtime.runFork(\n\t\t\tEffect.flatMap(scope.fork_in(Program), (scoped_fiber) => {\n\t\t\t\tif (this.#is_current_fiber(cache_key, launch_fiber)) {\n\t\t\t\t\tthis.#fibers.set(cache_key, scoped_fiber);\n\t\t\t\t}\n\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\tif (!this.#is_current_fiber(cache_key, scoped_fiber)) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.#runtime.runFork(\n\t\t\t\t\t\tWatchFiberExit({\n\t\t\t\t\t\t\tfiber: scoped_fiber,\n\t\t\t\t\t\t\tsurface_failure: false,\n\t\t\t\t\t\t\ton_complete: () => this.#complete_fiber(cache_key, scoped_fiber),\n\t\t\t\t\t\t\ton_success: (value) =>\n\t\t\t\t\t\t\t\tthis.#publish_value_success(cache_key, scoped_fiber, value),\n\t\t\t\t\t\t\ton_failure: (error) =>\n\t\t\t\t\t\t\t\tthis.#publish_value_failure(cache_key, scoped_fiber, error),\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\n\t\t\t\t\tif (this.#value_cells.has(cache_key)) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.#set_value_cell(cache_key, {\n\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\tfiber: scoped_fiber,\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\t\treturn Effect.asVoid(Fiber.await(scoped_fiber));\n\t\t\t}) as Effect.Effect<unknown, unknown, unknown>,\n\t\t);\n\n\t\tthis.#fibers.set(cache_key, launch_fiber);\n\t}\n\n\t#start_promise_fiber<A>(\n\t\tcache_key: string,\n\t\toptions: PromiseOptions<A>,\n\t\tcache_id: string,\n\t): Promise<A> {\n\t\tconst Program = Effect.gen(function* () {\n\t\t\tconst result = yield* Effect.gen(options.factory);\n\n\t\t\treturn result;\n\t\t});\n\t\tconst scope = this.#current_scope;\n\n\t\t/** Generator bodies passed to `Effect.gen` carry their own `this`. */\n\t\tconst dispatcher = this;\n\n\t\tif (!scope) {\n\t\t\tconst fiber = this.#runtime.runFork(\n\t\t\t\tProgram as Effect.Effect<unknown, unknown, unknown>,\n\t\t\t);\n\t\t\tconst ReleaseFiber = Effect.sync(() => {\n\t\t\t\tif (!this.#is_current_fiber(cache_key, fiber)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.#fibers.delete(cache_key);\n\t\t\t\tthis.#promise_values.delete(cache_key);\n\n\t\t\t\tif (this.#promise_ids.get(cache_id) === cache_key) {\n\t\t\t\t\tthis.#promise_ids.delete(cache_id);\n\t\t\t\t}\n\t\t\t});\n\t\t\tconst AwaitFiber = Effect.gen(function* () {\n\t\t\t\tconst exit = yield* Fiber.await(fiber);\n\n\t\t\t\tyield* ReleaseFiber;\n\n\t\t\t\tif (Exit.isSuccess(exit)) {\n\t\t\t\t\treturn exit.value as A;\n\t\t\t\t}\n\n\t\t\t\treturn yield* Effect.fail(Cause.squash(exit.cause));\n\t\t\t});\n\n\t\t\tthis.#fibers.set(cache_key, fiber);\n\t\t\tthis.#promise_values.set(cache_key, this.#runtime.runPromise(AwaitFiber));\n\n\t\t\treturn this.#promise_values.get(cache_key) as Promise<A>;\n\t\t}\n\n\t\tconst promise = this.#runtime.runPromise(\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst scoped_fiber = yield* scope.fork_in(Program);\n\n\t\t\t\tdispatcher.#fibers.set(cache_key, scoped_fiber);\n\t\t\t\tdispatcher.#runtime.runFork(\n\t\t\t\t\tWatchFiberExit({\n\t\t\t\t\t\tfiber: scoped_fiber,\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The promise this call returns already rejects with the\n\t\t\t\t\t\t * failure, so surfacing it again would hand a handled\n\t\t\t\t\t\t * rejection back as an uncaught error.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tsurface_failure: false,\n\t\t\t\t\t\ton_complete: () => {\n\t\t\t\t\t\t\tif (!dispatcher.#is_current_fiber(cache_key, scoped_fiber)) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tdispatcher.#fibers.delete(cache_key);\n\t\t\t\t\t\t\tdispatcher.#promise_values.delete(cache_key);\n\n\t\t\t\t\t\t\tif (dispatcher.#promise_ids.get(cache_id) === cache_key) {\n\t\t\t\t\t\t\t\tdispatcher.#promise_ids.delete(cache_id);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\tconst exit = yield* Fiber.await(scoped_fiber);\n\n\t\t\t\tif (Exit.isSuccess(exit)) {\n\t\t\t\t\treturn exit.value as A;\n\t\t\t\t}\n\n\t\t\t\treturn yield* Effect.fail(Cause.squash(exit.cause));\n\t\t\t}),\n\t\t);\n\n\t\tthis.#promise_values.set(cache_key, promise);\n\n\t\treturn promise;\n\t}\n\n\t#clear_pending_value_cell(\n\t\tcache_key: string,\n\t\tfiber: FiberType<unknown, unknown> | undefined,\n\t): void {\n\t\tconst cell = this.#value_cells.get(cache_key);\n\n\t\tif (cell?.status !== \"pending\") {\n\t\t\treturn;\n\t\t}\n\n\t\tif (fiber !== undefined && cell.fiber !== fiber) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#delete_value_cell(cache_key);\n\t}\n\n\t#complete_fiber(cache_key: string, fiber: FiberType<unknown, unknown>): void {\n\t\tif (!this.#is_current_fiber(cache_key, fiber)) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#fibers.delete(cache_key);\n\t}\n\n\t#publish_value_success<A>(\n\t\tcache_key: string,\n\t\tfiber: FiberType<unknown, unknown>,\n\t\tvalue: A,\n\t): void {\n\t\tif (!this.#is_current_fiber(cache_key, fiber)) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#set_value_cell(cache_key, {\n\t\t\tstatus: \"success\",\n\t\t\tvalue,\n\t\t});\n\t}\n\n\t#publish_value_failure(\n\t\tcache_key: string,\n\t\tfiber: FiberType<unknown, unknown>,\n\t\terror: unknown,\n\t): void {\n\t\tif (!this.#is_current_fiber(cache_key, fiber)) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#set_value_cell(cache_key, {\n\t\t\tstatus: \"failure\",\n\t\t\terror,\n\t\t});\n\t}\n\n\t#set_value_cell(cache_key: string, cell: ValueCell<unknown>): void {\n\t\tthis.#value_cells.set(cache_key, cell);\n\t\tthis.#notify_value_cells();\n\t}\n\n\t#delete_value_cell(cache_key: string): void {\n\t\tconst deleted = this.#value_cells.delete(cache_key);\n\n\t\tif (!deleted) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#notify_value_cells();\n\t}\n\n\t#clear_value_cells(): void {\n\t\tif (this.#value_cells.size === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#value_cells.clear();\n\t\tthis.#notify_value_cells();\n\t}\n\n\t#is_current_fiber(cache_key: string, fiber: FiberType<unknown, unknown>): boolean {\n\t\treturn !this.#disposed && this.#fibers.get(cache_key) === fiber;\n\t}\n}\n\nlet current_dispatcher: Dispatcher | null = null;\n\nexport function get_dispatcher(): Dispatcher {\n\tcurrent_dispatcher ??= new Dispatcher();\n\n\treturn current_dispatcher;\n}\n\nexport function reset_dispatcher(): void {\n\tcurrent_dispatcher?.dispose();\n\tcurrent_dispatcher = null;\n}\n\n/**\n * Lazily-created component scope used by generated component code.\n *\n * The holder is created synchronously during component init (before any\n * top-level `await`, where `onDestroy` is not yet available), and the scope\n * itself is materialized on first use. Disposal is registered separately\n * through `onDestroy` during component initialisation, so the scope is\n * reliably closed on unmount.\n *\n * @since 4.1.0\n */\nexport class ComponentScopeRef {\n\treadonly #get_dispatcher: () => Dispatcher;\n\t#scope: ComponentScope | undefined;\n\t#disposed = false;\n\n\tconstructor(get_dispatcher_fn: () => Dispatcher) {\n\t\tthis.#get_dispatcher = get_dispatcher_fn;\n\t}\n\n\t/** The component scope, creating it on first access. */\n\tget scope(): ComponentScope {\n\t\tif (this.#disposed) {\n\t\t\tthrow new ScopeDisposedError();\n\t\t}\n\n\t\tthis.#scope ??= this.#get_dispatcher().begin_scope();\n\n\t\treturn this.#scope;\n\t}\n\n\t/** Disposes the scope if it was created. Idempotent. */\n\tdispose(): void {\n\t\tthis.#disposed = true;\n\n\t\tconst scope = this.#scope;\n\t\tthis.#scope = undefined;\n\n\t\tif (scope && !scope.disposed) {\n\t\t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C1B,IAAI,KAAKkB,aAAa,SAAS,GAC9B;EAGD,KAAKA,aAAa,MAAM;EACxB,KAAKlB,oBAAoB;CAC1B;CAEA,kBAAkB,WAAmB,OAA6C;EACjF,OAAO,CAAC,KAAKK,aAAa,KAAKO,QAAQ,IAAI,SAAS,MAAM;CAC3D;AACD;AAEA,IAAI,qBAAwC;AAE5C,SAAgB,iBAA6B;CAC5C,uBAAuB,IAAI,WAAW;CAEtC,OAAO;AACR;AAEA,SAAgB,mBAAyB;CACxC,oBAAoB,QAAQ;CAC5B,qBAAqB;AACtB;;;;;;;;;;;;AAaA,IAAa,oBAAb,MAA+B;CAC9B;CACA;CACA,YAAY;CAEZ,YAAY,mBAAqC;EAChD,KAAKyB,kBAAkB;CACxB;;CAGA,IAAI,QAAwB;EAC3B,IAAI,KAAKhC,WACR,MAAM,IAAI,mBAAmB;EAG9B,KAAKiC,WAAW,KAAKD,gBAAgB,CAAC,CAAC,YAAY;EAEnD,OAAO,KAAKC;CACb;;CAGA,UAAgB;EACf,KAAKjC,YAAY;EAEjB,MAAM,QAAQ,KAAKiC;EACnB,KAAKA,SAAS,KAAA;EAEd,IAAI,SAAS,CAAC,MAAM,UACnB,KAAKD,gBAAgB,CAAC,CAAC,cAAc,KAAK;CAE5C;AACD"}
@@ -1,5 +1,5 @@
1
- import { r as get_dispatcher$1 } from "./dispatcher-CTWINW5I.js";
2
- import { r as get_server_dispatcher } from "./runtime-CPosEhGl.js";
1
+ import { r as get_dispatcher$1 } from "./dispatcher-B6ZRUsjN.js";
2
+ import { r as get_server_dispatcher } from "./runtime-B8RHHy3v.js";
3
3
  //#region src/generated/dispatcher.ts
4
4
  var Dispatcher = class {
5
5
  static emit(event) {
@@ -20,4 +20,4 @@ function get_dispatcher() {
20
20
  //#endregion
21
21
  export { get_dispatcher as n, Dispatcher as t };
22
22
 
23
- //# sourceMappingURL=dispatcher-pZPzarul.js.map
23
+ //# sourceMappingURL=dispatcher-D8j5wTx6.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dispatcher-pZPzarul.js","names":["get_client_dispatcher"],"sources":["../../../modules/svelte-effect-runtime/src/generated/dispatcher.ts"],"sourcesContent":["import type {\n\tComponentScope,\n\tDispatcher as RuntimeDispatcher,\n\tDispatcherEvent,\n\tMarkupPromiseEvent,\n\tMarkupRunEvent,\n\tMarkupValueEvent,\n} from \"$/dispatcher.ts\";\nimport { get_dispatcher as get_client_dispatcher } from \"$/dispatcher.ts\";\nimport { get_server_dispatcher } from \"$/server/runtime.ts\";\n\nexport { Code } from \"$/dispatcher.ts\";\nexport type {\n\tDispatcherEvent,\n\tMarkupPromiseEvent,\n\tMarkupPromiseOptions,\n\tMarkupRunEvent,\n\tMarkupValueEvent,\n} from \"$/dispatcher.ts\";\n\nexport class Dispatcher {\n\tstatic emit<A, F>(event: MarkupValueEvent<A, F>): A | F;\n\tstatic emit<A>(event: MarkupPromiseEvent<A>): Promise<A>;\n\tstatic emit<A>(event: MarkupRunEvent<A>): Promise<A>;\n\tstatic emit<A, F>(event: DispatcherEvent<A, F>): A | F | Promise<A>;\n\tstatic emit<A, F>(event: DispatcherEvent<A, F>): A | F | Promise<A> {\n\t\treturn get_dispatcher().emit(event);\n\t}\n\n\t/**\n\t * Runs `fn` with `scope` as the active component scope so emitted work is\n\t * bound to the calling component's lifetime.\n\t */\n\tstatic with_scope<T>(scope: ComponentScope, fn: () => T): T {\n\t\treturn get_dispatcher().with_scope(scope, fn);\n\t}\n}\n\nexport function get_dispatcher(): RuntimeDispatcher {\n\tif (typeof document === \"undefined\") {\n\t\treturn get_server_dispatcher();\n\t}\n\n\treturn get_client_dispatcher();\n}\n"],"mappings":";;;AAoBA,IAAa,aAAb,MAAwB;CAKvB,OAAO,KAAW,OAAkD;EACnE,OAAO,eAAe,CAAC,CAAC,KAAK,KAAK;CACnC;;;;;CAMA,OAAO,WAAc,OAAuB,IAAgB;EAC3D,OAAO,eAAe,CAAC,CAAC,WAAW,OAAO,EAAE;CAC7C;AACD;AAEA,SAAgB,iBAAoC;CACnD,IAAI,OAAO,aAAa,aACvB,OAAO,sBAAsB;CAG9B,OAAOA,iBAAsB;AAC9B"}
1
+ {"version":3,"file":"dispatcher-D8j5wTx6.js","names":["get_client_dispatcher"],"sources":["../../../modules/svelte-effect-runtime/src/generated/dispatcher.ts"],"sourcesContent":["import type {\n\tComponentScope,\n\tDispatcher as RuntimeDispatcher,\n\tDispatcherEvent,\n\tMarkupPromiseEvent,\n\tMarkupRunEvent,\n\tMarkupValueEvent,\n} from \"$/dispatcher.ts\";\nimport { get_dispatcher as get_client_dispatcher } from \"$/dispatcher.ts\";\nimport { get_server_dispatcher } from \"$/server/runtime.ts\";\n\nexport { Code } from \"$/dispatcher.ts\";\nexport type {\n\tDispatcherEvent,\n\tMarkupPromiseEvent,\n\tMarkupPromiseOptions,\n\tMarkupRunEvent,\n\tMarkupValueEvent,\n} from \"$/dispatcher.ts\";\n\nexport class Dispatcher {\n\tstatic emit<A, F>(event: MarkupValueEvent<A, F>): A | F;\n\tstatic emit<A>(event: MarkupPromiseEvent<A>): Promise<A>;\n\tstatic emit<A>(event: MarkupRunEvent<A>): Promise<A>;\n\tstatic emit<A, F>(event: DispatcherEvent<A, F>): A | F | Promise<A>;\n\tstatic emit<A, F>(event: DispatcherEvent<A, F>): A | F | Promise<A> {\n\t\treturn get_dispatcher().emit(event);\n\t}\n\n\t/**\n\t * Runs `fn` with `scope` as the active component scope so emitted work is\n\t * bound to the calling component's lifetime.\n\t */\n\tstatic with_scope<T>(scope: ComponentScope, fn: () => T): T {\n\t\treturn get_dispatcher().with_scope(scope, fn);\n\t}\n}\n\nexport function get_dispatcher(): RuntimeDispatcher {\n\tif (typeof document === \"undefined\") {\n\t\treturn get_server_dispatcher();\n\t}\n\n\treturn get_client_dispatcher();\n}\n"],"mappings":";;;AAoBA,IAAa,aAAb,MAAwB;CAKvB,OAAO,KAAW,OAAkD;EACnE,OAAO,eAAe,CAAC,CAAC,KAAK,KAAK;CACnC;;;;;CAMA,OAAO,WAAc,OAAuB,IAAgB;EAC3D,OAAO,eAAe,CAAC,CAAC,WAAW,OAAO,EAAE;CAC7C;AACD;AAEA,SAAgB,iBAAoC;CACnD,IAAI,OAAO,aAAa,aACvB,OAAO,sBAAsB;CAG9B,OAAOA,iBAAsB;AAC9B"}
@@ -1,5 +1,5 @@
1
1
  import { b as RuntimeAlreadyInitializedError, y as RequestEventUnavailableError } from "./errors-qhcbUH6o.js";
2
- import { n as Dispatcher } from "./dispatcher-CTWINW5I.js";
2
+ import { n as Dispatcher } from "./dispatcher-B6ZRUsjN.js";
3
3
  import { Context, Layer, ManagedRuntime } from "effect";
4
4
  //#region src/server/runtime.ts
5
5
  /**
@@ -90,4 +90,4 @@ function reset_server_runtime() {
90
90
  //#endregion
91
91
  export { get_server_runtime_or_throw as i, ServerRuntime as n, get_server_dispatcher as r, RequestEvent as t };
92
92
 
93
- //# sourceMappingURL=runtime-CPosEhGl.js.map
93
+ //# sourceMappingURL=runtime-B8RHHy3v.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-CPosEhGl.js","names":["InternalDispatcher"],"sources":["../../../modules/svelte-effect-runtime/src/server/runtime.ts"],"sourcesContent":["import { RequestEventUnavailableError, RuntimeAlreadyInitializedError } from \"$/errors.ts\";\nimport type { ManagedRuntime as ManagedRuntimeType } from \"effect/ManagedRuntime\";\nimport type { RequestEvent as SvelteKitRequestEvent } from \"@sveltejs/kit\";\nimport { Dispatcher as InternalDispatcher } from \"$/dispatcher.ts\";\nimport { Context, Layer, ManagedRuntime } from \"effect\";\n\ntype ViteImportMeta = ImportMeta & {\n\treadonly env?: {\n\t\treadonly DEV?: boolean;\n\t\treadonly MODE?: string;\n\t\treadonly SSR?: boolean;\n\t};\n};\n\n/**\n * Subset of SvelteKit's `RequestEvent` that remote handlers typically access.\n *\n * @example\n * ```ts\n * const event: RequestEvent = yield* RequestEvent;\n * console.log(event.url.pathname);\n * ```\n *\n * @since 2.0.0\n */\nexport interface RequestEvent extends Pick<\n\tSvelteKitRequestEvent,\n\t\"cookies\" | \"getClientAddress\" | \"locals\" | \"params\" | \"platform\" | \"request\" | \"route\" | \"url\"\n> {}\n\n/**\n * SvelteKit's `RequestEvent` exposed as an Effect {@link Context.Tag}.\n *\n * @example\n * ```ts\n * const event = yield* RequestEvent;\n * ```\n *\n * @since 2.0.0\n */\nexport const RequestEvent: Context.Reference<RequestEvent> = Context.Reference<RequestEvent>(\n\t\"@ser/RequestEvent\",\n\t{\n\t\tdefaultValue: () => {\n\t\t\tthrow new RequestEventUnavailableError();\n\t\t},\n\t},\n);\n\n/**\n * Builder for the server-side Effect runtime.\n *\n * @example\n * ```ts\n * ServerRuntime.make(Db.Live);\n * ```\n *\n * @since 2.0.0\n */\nexport class ServerRuntime {\n\t/**\n\t * Build and cache the server-side `ManagedRuntime`.\n\t *\n\t * @since 2.0.0\n\t * @param layer - Optional Effect layer to provide to the runtime.\n\t * @returns The configured ManagedRuntime.\n\t */\n\tstatic make<R = never>(layer?: Layer.Layer<R>): ManagedRuntime.ManagedRuntime<R, never> {\n\t\tconst should_replace_dev_runtime =\n\t\t\tcurrent_server_runtime !== undefined && is_vite_dev_ssr();\n\n\t\t/**\n\t\t * Keep duplicate production initialization loud while allowing SvelteKit's\n\t\t * dev server to re-run hooks.server.ts after an HMR invalidation.\n\t\t */\n\t\tif (current_server_runtime && !should_replace_dev_runtime) {\n\t\t\tthrow new RuntimeAlreadyInitializedError(\"ServerRuntime\");\n\t\t}\n\n\t\tif (should_replace_dev_runtime) {\n\t\t\treset_server_runtime();\n\t\t}\n\n\t\tconst runtime = ManagedRuntime.make(layer ?? (Layer.empty as unknown as Layer.Layer<R>));\n\n\t\tcurrent_server_runtime = runtime as ManagedRuntime.ManagedRuntime<unknown, never>;\n\t\tcurrent_server_dispatcher = new InternalDispatcher(\n\t\t\truntime as unknown as ManagedRuntimeType<unknown, unknown>,\n\t\t);\n\n\t\treturn runtime;\n\t}\n}\n\nlet current_server_runtime: ManagedRuntime.ManagedRuntime<unknown, never> | undefined;\nlet current_server_dispatcher: InternalDispatcher | undefined;\n\n/**\n * Returns the active server runtime, creating a default one if needed.\n *\n * @example\n * ```ts\n * const runtime = get_server_runtime_or_throw();\n * ```\n *\n * @since 2.0.0\n * @returns The current ManagedRuntime instance.\n */\nexport function get_server_runtime_or_throw(): ManagedRuntime.ManagedRuntime<unknown, never> {\n\tif (!current_server_runtime) {\n\t\tcurrent_server_runtime = ManagedRuntime.make(Layer.empty) as ManagedRuntime.ManagedRuntime<\n\t\t\tunknown,\n\t\t\tnever\n\t\t>;\n\t}\n\n\treturn current_server_runtime;\n}\n\nexport function get_server_dispatcher(): InternalDispatcher {\n\tcurrent_server_dispatcher ??= new InternalDispatcher(\n\t\tget_server_runtime_or_throw() as unknown as ManagedRuntimeType<unknown, unknown>,\n\t);\n\n\treturn current_server_dispatcher;\n}\n\nfunction is_vite_dev_ssr(): boolean {\n\tconst env = (import.meta as ViteImportMeta).env;\n\n\treturn env?.DEV === true && env?.SSR === true && env.MODE !== \"test\";\n}\n\nexport function reset_server_runtime(): void {\n\tconst dispatcher = current_server_dispatcher;\n\tconst runtime = current_server_runtime;\n\n\tcurrent_server_dispatcher = undefined;\n\tcurrent_server_runtime = undefined;\n\n\tif (dispatcher) {\n\t\tdispatcher.dispose();\n\n\t\treturn;\n\t}\n\n\tvoid runtime?.dispose().catch((error: unknown) => {\n\t\tqueueMicrotask(() => {\n\t\t\tthrow error;\n\t\t});\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;AAwCA,MAAa,eAAgD,QAAQ,UACpE,qBACA,EACC,oBAAoB;CACnB,MAAM,IAAI,6BAA6B;AACxC,EACD,CACD;;;;;;;;;;;AAYA,IAAa,gBAAb,MAA2B;;;;;;;;CAQ1B,OAAO,KAAgB,OAAiE;EACvF,MAAM,6BACL,2BAA2B,KAAA,KAAa,gBAAgB;;;;;EAMzD,IAAI,0BAA0B,CAAC,4BAC9B,MAAM,IAAI,+BAA+B,eAAe;EAGzD,IAAI,4BACH,qBAAqB;EAGtB,MAAM,UAAU,eAAe,KAAK,SAAU,MAAM,KAAmC;EAEvF,yBAAyB;EACzB,4BAA4B,IAAIA,WAC/B,OACD;EAEA,OAAO;CACR;AACD;AAEA,IAAI;AACJ,IAAI;;;;;;;;;;;;AAaJ,SAAgB,8BAA6E;CAC5F,IAAI,CAAC,wBACJ,yBAAyB,eAAe,KAAK,MAAM,KAAK;CAMzD,OAAO;AACR;AAEA,SAAgB,wBAA4C;CAC3D,8BAA8B,IAAIA,WACjC,4BAA4B,CAC7B;CAEA,OAAO;AACR;AAEA,SAAS,kBAA2B;CACnC,MAAM,MAAO,OAAO,KAAwB;CAE5C,OAAO,KAAK,QAAQ,QAAQ,KAAK,QAAQ,QAAQ,IAAI,SAAS;AAC/D;AAEA,SAAgB,uBAA6B;CAC5C,MAAM,aAAa;CACnB,MAAM,UAAU;CAEhB,4BAA4B,KAAA;CAC5B,yBAAyB,KAAA;CAEzB,IAAI,YAAY;EACf,WAAW,QAAQ;EAEnB;CACD;CAEA,SAAc,QAAQ,CAAC,CAAC,OAAO,UAAmB;EACjD,qBAAqB;GACpB,MAAM;EACP,CAAC;CACF,CAAC;AACF"}
1
+ {"version":3,"file":"runtime-B8RHHy3v.js","names":["InternalDispatcher"],"sources":["../../../modules/svelte-effect-runtime/src/server/runtime.ts"],"sourcesContent":["import { RequestEventUnavailableError, RuntimeAlreadyInitializedError } from \"$/errors.ts\";\nimport type { ManagedRuntime as ManagedRuntimeType } from \"effect/ManagedRuntime\";\nimport type { RequestEvent as SvelteKitRequestEvent } from \"@sveltejs/kit\";\nimport { Dispatcher as InternalDispatcher } from \"$/dispatcher.ts\";\nimport { Context, Layer, ManagedRuntime } from \"effect\";\n\ntype ViteImportMeta = ImportMeta & {\n\treadonly env?: {\n\t\treadonly DEV?: boolean;\n\t\treadonly MODE?: string;\n\t\treadonly SSR?: boolean;\n\t};\n};\n\n/**\n * Subset of SvelteKit's `RequestEvent` that remote handlers typically access.\n *\n * @example\n * ```ts\n * const event: RequestEvent = yield* RequestEvent;\n * console.log(event.url.pathname);\n * ```\n *\n * @since 2.0.0\n */\nexport interface RequestEvent extends Pick<\n\tSvelteKitRequestEvent,\n\t\"cookies\" | \"getClientAddress\" | \"locals\" | \"params\" | \"platform\" | \"request\" | \"route\" | \"url\"\n> {}\n\n/**\n * SvelteKit's `RequestEvent` exposed as an Effect {@link Context.Tag}.\n *\n * @example\n * ```ts\n * const event = yield* RequestEvent;\n * ```\n *\n * @since 2.0.0\n */\nexport const RequestEvent: Context.Reference<RequestEvent> = Context.Reference<RequestEvent>(\n\t\"@ser/RequestEvent\",\n\t{\n\t\tdefaultValue: () => {\n\t\t\tthrow new RequestEventUnavailableError();\n\t\t},\n\t},\n);\n\n/**\n * Builder for the server-side Effect runtime.\n *\n * @example\n * ```ts\n * ServerRuntime.make(Db.Live);\n * ```\n *\n * @since 2.0.0\n */\nexport class ServerRuntime {\n\t/**\n\t * Build and cache the server-side `ManagedRuntime`.\n\t *\n\t * @since 2.0.0\n\t * @param layer - Optional Effect layer to provide to the runtime.\n\t * @returns The configured ManagedRuntime.\n\t */\n\tstatic make<R = never>(layer?: Layer.Layer<R>): ManagedRuntime.ManagedRuntime<R, never> {\n\t\tconst should_replace_dev_runtime =\n\t\t\tcurrent_server_runtime !== undefined && is_vite_dev_ssr();\n\n\t\t/**\n\t\t * Keep duplicate production initialization loud while allowing SvelteKit's\n\t\t * dev server to re-run hooks.server.ts after an HMR invalidation.\n\t\t */\n\t\tif (current_server_runtime && !should_replace_dev_runtime) {\n\t\t\tthrow new RuntimeAlreadyInitializedError(\"ServerRuntime\");\n\t\t}\n\n\t\tif (should_replace_dev_runtime) {\n\t\t\treset_server_runtime();\n\t\t}\n\n\t\tconst runtime = ManagedRuntime.make(layer ?? (Layer.empty as unknown as Layer.Layer<R>));\n\n\t\tcurrent_server_runtime = runtime as ManagedRuntime.ManagedRuntime<unknown, never>;\n\t\tcurrent_server_dispatcher = new InternalDispatcher(\n\t\t\truntime as unknown as ManagedRuntimeType<unknown, unknown>,\n\t\t);\n\n\t\treturn runtime;\n\t}\n}\n\nlet current_server_runtime: ManagedRuntime.ManagedRuntime<unknown, never> | undefined;\nlet current_server_dispatcher: InternalDispatcher | undefined;\n\n/**\n * Returns the active server runtime, creating a default one if needed.\n *\n * @example\n * ```ts\n * const runtime = get_server_runtime_or_throw();\n * ```\n *\n * @since 2.0.0\n * @returns The current ManagedRuntime instance.\n */\nexport function get_server_runtime_or_throw(): ManagedRuntime.ManagedRuntime<unknown, never> {\n\tif (!current_server_runtime) {\n\t\tcurrent_server_runtime = ManagedRuntime.make(Layer.empty) as ManagedRuntime.ManagedRuntime<\n\t\t\tunknown,\n\t\t\tnever\n\t\t>;\n\t}\n\n\treturn current_server_runtime;\n}\n\nexport function get_server_dispatcher(): InternalDispatcher {\n\tcurrent_server_dispatcher ??= new InternalDispatcher(\n\t\tget_server_runtime_or_throw() as unknown as ManagedRuntimeType<unknown, unknown>,\n\t);\n\n\treturn current_server_dispatcher;\n}\n\nfunction is_vite_dev_ssr(): boolean {\n\tconst env = (import.meta as ViteImportMeta).env;\n\n\treturn env?.DEV === true && env?.SSR === true && env.MODE !== \"test\";\n}\n\nexport function reset_server_runtime(): void {\n\tconst dispatcher = current_server_dispatcher;\n\tconst runtime = current_server_runtime;\n\n\tcurrent_server_dispatcher = undefined;\n\tcurrent_server_runtime = undefined;\n\n\tif (dispatcher) {\n\t\tdispatcher.dispose();\n\n\t\treturn;\n\t}\n\n\tvoid runtime?.dispose().catch((error: unknown) => {\n\t\tqueueMicrotask(() => {\n\t\t\tthrow error;\n\t\t});\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;AAwCA,MAAa,eAAgD,QAAQ,UACpE,qBACA,EACC,oBAAoB;CACnB,MAAM,IAAI,6BAA6B;AACxC,EACD,CACD;;;;;;;;;;;AAYA,IAAa,gBAAb,MAA2B;;;;;;;;CAQ1B,OAAO,KAAgB,OAAiE;EACvF,MAAM,6BACL,2BAA2B,KAAA,KAAa,gBAAgB;;;;;EAMzD,IAAI,0BAA0B,CAAC,4BAC9B,MAAM,IAAI,+BAA+B,eAAe;EAGzD,IAAI,4BACH,qBAAqB;EAGtB,MAAM,UAAU,eAAe,KAAK,SAAU,MAAM,KAAmC;EAEvF,yBAAyB;EACzB,4BAA4B,IAAIA,WAC/B,OACD;EAEA,OAAO;CACR;AACD;AAEA,IAAI;AACJ,IAAI;;;;;;;;;;;;AAaJ,SAAgB,8BAA6E;CAC5F,IAAI,CAAC,wBACJ,yBAAyB,eAAe,KAAK,MAAM,KAAK;CAMzD,OAAO;AACR;AAEA,SAAgB,wBAA4C;CAC3D,8BAA8B,IAAIA,WACjC,4BAA4B,CAC7B;CAEA,OAAO;AACR;AAEA,SAAS,kBAA2B;CACnC,MAAM,MAAO,OAAO,KAAwB;CAE5C,OAAO,KAAK,QAAQ,QAAQ,KAAK,QAAQ,QAAQ,IAAI,SAAS;AAC/D;AAEA,SAAgB,uBAA6B;CAC5C,MAAM,aAAa;CACnB,MAAM,UAAU;CAEhB,4BAA4B,KAAA;CAC5B,yBAAyB,KAAA;CAEzB,IAAI,YAAY;EACf,WAAW,QAAQ;EAEnB;CACD;CAEA,SAAc,QAAQ,CAAC,CAAC,OAAO,UAAmB;EACjD,qBAAqB;GACpB,MAAM;EACP,CAAC;CACF,CAAC;AACF"}
@@ -0,0 +1,339 @@
1
+ import { _ as RemoteHelperContextError, v as RemoteHelperError } from "./errors-qhcbUH6o.js";
2
+ import { create_serialized_remote_failure_envelope, is_form_error } from "../remote/shared.js";
3
+ import { Cause, Effect, Exit, Schema } from "effect";
4
+ import { isHttpError, isRedirect, isValidationError } from "@sveltejs/kit";
5
+ import { stringify } from "devalue";
6
+ //#region src/remote/diagnostics.ts
7
+ const explanations = {
8
+ untagged: "the failure has no string `_tag`, so it cannot be told apart from an arbitrary object on the wire",
9
+ unserializable: "the failure could not be serialized, even after being reduced to its own enumerable properties",
10
+ unknown: "the cause carries no failure reason, so there was nothing to serialize",
11
+ interrupted: "the handler's fiber was interrupted before it produced a result"
12
+ };
13
+ const remedies = {
14
+ untagged: "Fail with a tagged error (`Data.TaggedError` or `Schema.TaggedError`) so SER can carry it to the client.",
15
+ unserializable: "Remove non-transportable values (functions, class instances, cycles) from the error, or map it to a tagged error first.",
16
+ unknown: "Check for a defect thrown outside the Effect error channel; the original value is shown above.",
17
+ interrupted: "An interrupt usually means the runtime was disposed mid-request, for example when the dev server restarted while this request was in flight."
18
+ };
19
+ /**
20
+ * Reports a remote failure that had to be replaced with an opaque envelope.
21
+ *
22
+ * SER cannot send an unrecognized failure to the browser, so the client only
23
+ * ever sees a generic 500. Without this report the original error would be
24
+ * lost entirely, which is the difference between a debuggable failure and a
25
+ * silent one.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * report_opaque_remote_failure("untagged", cause, value, { url: "/checkout" });
30
+ * ```
31
+ *
32
+ * @since 4.2.0
33
+ * @param reason - Why the failure could not be transported.
34
+ * @param cause - Full Effect cause behind the failure.
35
+ * @param value - The original failure value, when one was found.
36
+ * @param context - Optional request detail for the log header.
37
+ * @param report - Sink for the rendered report; defaults to `console.error`.
38
+ */
39
+ function report_opaque_remote_failure(reason, cause, value, context, report = default_reporter) {
40
+ /**
41
+ * Reporting runs before SvelteKit's error helper, and the failure it
42
+ * describes is arbitrary user data. Throwing here would replace the 500
43
+ * the handler owes the client with the reporter's own error.
44
+ */
45
+ try {
46
+ report(render_opaque_remote_failure(reason, cause, value, context));
47
+ } catch {}
48
+ }
49
+ /**
50
+ * Renders the report emitted by {@link report_opaque_remote_failure}.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const message = render_opaque_remote_failure("untagged", cause, value);
55
+ * ```
56
+ *
57
+ * @since 4.2.0
58
+ * @param reason - Why the failure could not be transported.
59
+ * @param cause - Full Effect cause behind the failure.
60
+ * @param value - The original failure value, when one was found.
61
+ * @param context - Optional request detail for the log header.
62
+ * @returns The multi-line report.
63
+ */
64
+ function render_opaque_remote_failure(reason, cause, value, context) {
65
+ const request = render_request(context);
66
+ const lines = ["[svelte-effect-runtime] A remote handler failed with an error that could not be sent to the client.", ` Reason: ${explanations[reason]}.`];
67
+ if (request) lines.push(` Request: ${request}`);
68
+ if (reason !== "interrupted") lines.push(` Failure: ${inspect_failure(value)}`);
69
+ lines.push(" Cause:", indent(pretty_cause(cause)), ` Fix: ${remedies[reason]}`);
70
+ return lines.join("\n");
71
+ }
72
+ function render_request(context) {
73
+ if (!context) return;
74
+ const target = context.url ?? context.route;
75
+ const parts = [context.method, target].filter(Boolean);
76
+ const route = Boolean(context.route && context.url && context.route !== context.url) ? ` (route ${context.route})` : "";
77
+ if (parts.length === 0) return;
78
+ return `${parts.join(" ")}${route}`;
79
+ }
80
+ function pretty_cause(cause) {
81
+ try {
82
+ return Cause.pretty(cause);
83
+ } catch {
84
+ return String(cause);
85
+ }
86
+ }
87
+ /**
88
+ * Renders the failure value itself. Errors keep their stack because that is
89
+ * the only part of an untagged failure that identifies its source.
90
+ */
91
+ function inspect_failure(value) {
92
+ if (value === void 0) return "(none)";
93
+ if (value instanceof globalThis.Error) return value.stack ?? `${value.name}: ${value.message}`;
94
+ if (typeof value !== "object" || value === null) return describe_primitive(value);
95
+ try {
96
+ return JSON.stringify(value, void 0, 2) ?? describe_object(value);
97
+ } catch {
98
+ return describe_object(value);
99
+ }
100
+ }
101
+ /** A primitive can still carry a throwing `Symbol.toPrimitive`. */
102
+ function describe_primitive(value) {
103
+ try {
104
+ return String(value);
105
+ } catch {
106
+ return typeof value;
107
+ }
108
+ }
109
+ /**
110
+ * Falls back through conversions an object can subvert. A null-prototype or
111
+ * hostile object may throw from `toString` and lack `Object.prototype`, so the
112
+ * last resort must not touch the value at all.
113
+ */
114
+ function describe_object(value) {
115
+ try {
116
+ return String(value);
117
+ } catch {}
118
+ try {
119
+ return Object.prototype.toString.call(value);
120
+ } catch {
121
+ return "[unrenderable failure]";
122
+ }
123
+ }
124
+ function indent(value) {
125
+ return value.split("\n").map((line) => ` ${line}`).join("\n");
126
+ }
127
+ function default_reporter(message) {
128
+ console.error(message);
129
+ }
130
+ //#endregion
131
+ //#region src/remote/cause-codec.ts
132
+ /** Preserves SvelteKit control flow before classifying transportable Effect failures. */
133
+ function classify_remote_cause(cause) {
134
+ const control_flow = find_sveltekit_control_flow(cause);
135
+ if (control_flow !== void 0) return {
136
+ _tag: "SvelteKitControlFlow",
137
+ value: control_flow
138
+ };
139
+ if (Cause.hasInterruptsOnly(cause)) return {
140
+ _tag: "InterruptOnly",
141
+ cause
142
+ };
143
+ const form_error_issues = find_form_error_issues(cause);
144
+ if (form_error_issues !== void 0) return {
145
+ _tag: "FormInvalid",
146
+ issues: form_error_issues
147
+ };
148
+ const failure = encode_remote_failure_detailed(cause);
149
+ return {
150
+ _tag: "RemoteFailure",
151
+ encoded: failure.encoded,
152
+ ...failure.opaque ? { opaque: failure.opaque } : {}
153
+ };
154
+ }
155
+ /** Encodes a remote failure into the transport ABI shared with generated clients. */
156
+ function encode_remote_failure(cause) {
157
+ return encode_remote_failure_detailed(cause).encoded;
158
+ }
159
+ /**
160
+ * Encodes a remote failure and reports whether its detail survived encoding.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * const { encoded, opaque } = encode_remote_failure_detailed(cause);
165
+ * ```
166
+ *
167
+ * @since 4.2.0
168
+ * @param cause - Cause carrying the handler's failure.
169
+ * @returns The encoded payload and, when detail was lost, why.
170
+ */
171
+ function encode_remote_failure_detailed(cause) {
172
+ for (const reason of cause.reasons) {
173
+ if (!Cause.isFailReason(reason)) continue;
174
+ if (!has_public_remote_failure_tag(reason.error)) return {
175
+ encoded: stringify_unknown_remote_failure(),
176
+ opaque: {
177
+ reason: "untagged",
178
+ value: reason.error
179
+ }
180
+ };
181
+ const failure = to_serializable_public_failure(reason.error);
182
+ const encoded = failure === void 0 ? void 0 : stringify_failure(failure);
183
+ if (encoded !== void 0) return { encoded };
184
+ return {
185
+ encoded: stringify_unknown_remote_failure(),
186
+ opaque: {
187
+ reason: "unserializable",
188
+ value: reason.error
189
+ }
190
+ };
191
+ }
192
+ return {
193
+ encoded: stringify_unknown_remote_failure(),
194
+ opaque: {
195
+ reason: "unknown",
196
+ value: find_defect(cause)
197
+ }
198
+ };
199
+ }
200
+ /** Surfaces a defect so an unencodable cause still names something concrete. */
201
+ function find_defect(cause) {
202
+ for (const reason of cause.reasons) if (Cause.isDieReason(reason)) return reason.defect;
203
+ }
204
+ function find_sveltekit_control_flow(cause) {
205
+ for (const reason of cause.reasons) {
206
+ if (!Cause.isDieReason(reason)) continue;
207
+ if (is_sveltekit_control_flow(reason.defect)) return reason.defect;
208
+ }
209
+ }
210
+ function find_form_error_issues(cause) {
211
+ for (const reason of cause.reasons) {
212
+ if (!Cause.isFailReason(reason)) continue;
213
+ const issues = get_form_error_issues(reason.error);
214
+ if (issues !== void 0) return issues;
215
+ }
216
+ }
217
+ function get_form_error_issues(value) {
218
+ if (is_form_error(value)) return value.issues;
219
+ return is_tagged_form_error(value) ? [] : void 0;
220
+ }
221
+ function is_sveltekit_control_flow(value) {
222
+ return isRedirect(value) || isHttpError(value) || isValidationError(value);
223
+ }
224
+ function stringify_failure(value) {
225
+ try {
226
+ return stringify(value);
227
+ } catch {
228
+ return;
229
+ }
230
+ }
231
+ function to_serializable_public_failure(value, seen = /* @__PURE__ */ new WeakSet()) {
232
+ if (typeof value === "function" || typeof value === "symbol") return;
233
+ if (!is_object_like(value)) return value;
234
+ if (stringify_failure(value) !== void 0) return value;
235
+ if (is_internal_object(value)) return;
236
+ if (seen.has(value)) return;
237
+ seen.add(value);
238
+ const serializable = Array.isArray(value) ? value.map((item) => to_serializable_public_failure(item, seen)) : to_plain_record(value, seen);
239
+ seen.delete(value);
240
+ return serializable;
241
+ }
242
+ function to_plain_record(value, seen) {
243
+ const descriptors = Object.getOwnPropertyDescriptors(value);
244
+ const record = {};
245
+ for (const [key, descriptor] of Object.entries(descriptors)) {
246
+ if (key === "stack" || !("value" in descriptor)) continue;
247
+ record[key] = to_serializable_public_failure(descriptor.value, seen);
248
+ }
249
+ if (value instanceof Error && !("message" in record)) record.message = value.message;
250
+ return record;
251
+ }
252
+ function is_object_like(value) {
253
+ return typeof value === "object" && value !== null;
254
+ }
255
+ function has_public_remote_failure_tag(value) {
256
+ return is_object_like(value) && typeof value._tag === "string";
257
+ }
258
+ function is_internal_object(value) {
259
+ return !Array.isArray(value) && !is_plain_record(value) && !has_public_remote_failure_tag(value);
260
+ }
261
+ function is_plain_record(value) {
262
+ const prototype = Object.getPrototypeOf(value);
263
+ return prototype === Object.prototype || prototype === null;
264
+ }
265
+ function create_unknown_remote_failure() {
266
+ return { message: "[UNKNOWN_REMOTE_FAILURE]: Unknown error" };
267
+ }
268
+ function stringify_unknown_remote_failure() {
269
+ return stringify(create_unknown_remote_failure());
270
+ }
271
+ const is_tagged_form_error = Schema.is(Schema.Struct({ _tag: Schema.Literal("FormError") }));
272
+ //#endregion
273
+ //#region src/remote/server.ts
274
+ const request_event_context_error_start = "Can only read the current request event inside functions invoked during `handle`";
275
+ const request_store_context_error = "Could not get the request store.";
276
+ /** Maps a remote Effect exit into the control flow expected by SvelteKit. */
277
+ async function run_remote_effect(effect, runtime, invalid, error, context) {
278
+ const exit = await runtime.runPromise(Effect.exit(effect));
279
+ if (Exit.isSuccess(exit)) return exit.value;
280
+ throw_remote_cause(exit.cause, invalid, error, context);
281
+ }
282
+ /** Applies a classified remote Cause decision to SvelteKit's server helpers. */
283
+ function throw_remote_cause(cause, invalid, error, context, report) {
284
+ const resolution = classify_remote_cause(cause);
285
+ switch (resolution._tag) {
286
+ case "SvelteKitControlFlow": throw resolution.value;
287
+ case "InterruptOnly":
288
+ report_opaque_remote_failure("interrupted", resolution.cause, void 0, context, report);
289
+ throw Cause.squash(resolution.cause);
290
+ case "FormInvalid": invalid(...resolution.issues);
291
+ case "RemoteFailure": {
292
+ const envelope = create_serialized_remote_failure_envelope(resolution.encoded);
293
+ /**
294
+ * The client only receives a generic 500 for a failure SER could not
295
+ * encode, so the original error is reported here or lost entirely.
296
+ */
297
+ if (resolution.opaque) report_opaque_remote_failure(resolution.opaque.reason, cause, resolution.opaque.value, context, report);
298
+ error(500, envelope);
299
+ }
300
+ }
301
+ }
302
+ /**
303
+ * Describes the request a remote failure occurred in.
304
+ *
305
+ * @example
306
+ * ```ts
307
+ * const context = to_remote_failure_context(event);
308
+ * ```
309
+ *
310
+ * @since 4.2.0
311
+ * @param event - Request event the handler ran under.
312
+ * @returns Request detail for opaque failure reports.
313
+ */
314
+ function to_remote_failure_context(event) {
315
+ const method = event.request?.method;
316
+ const route = event.route?.id ?? void 0;
317
+ const url = event.url?.pathname;
318
+ return {
319
+ ...method ? { method } : {},
320
+ ...route ? { route } : {},
321
+ ...url ? { url } : {}
322
+ };
323
+ }
324
+ function throw_form_error(issues, invalid) {
325
+ invalid(...issues);
326
+ }
327
+ /** Rebrands SvelteKit context failures with the remote helper that triggered them. */
328
+ function normalize_remote_helper_error(err, helper_name) {
329
+ if (is_sveltekit_remote_context_error(err)) return new RemoteHelperContextError(helper_name);
330
+ return err instanceof Error ? err : new RemoteHelperError(err);
331
+ }
332
+ function is_sveltekit_remote_context_error(err) {
333
+ if (!(err instanceof Error)) return false;
334
+ return err.message.startsWith(request_event_context_error_start) || err.message === request_store_context_error;
335
+ }
336
+ //#endregion
337
+ export { to_remote_failure_context as a, throw_remote_cause as i, run_remote_effect as n, encode_remote_failure as o, throw_form_error as r, normalize_remote_helper_error as t };
338
+
339
+ //# sourceMappingURL=server-NeyeDSax.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-NeyeDSax.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/remote/diagnostics.ts","../../../modules/svelte-effect-runtime/src/remote/cause-codec.ts","../../../modules/svelte-effect-runtime/src/remote/server.ts"],"sourcesContent":["import { Cause } from \"effect\";\n\n/**\n * Why a remote failure reached the client without its original detail.\n *\n * @example\n * ```ts\n * const reason: OpaqueRemoteFailureReason = \"untagged\";\n * ```\n *\n * @since 4.2.0\n */\nexport type OpaqueRemoteFailureReason = \"untagged\" | \"unserializable\" | \"unknown\" | \"interrupted\";\n\n/**\n * Request detail attached to an opaque remote failure report so the log line\n * points at the handler that produced it.\n *\n * @example\n * ```ts\n * const context: RemoteFailureContext = { method: \"POST\", url: \"/checkout\" };\n * ```\n *\n * @since 4.2.0\n */\nexport type RemoteFailureContext = {\n\treadonly method?: string;\n\treadonly route?: string;\n\treadonly url?: string;\n};\n\ntype Reporter = (message: string) => void;\n\nconst explanations: Readonly<Record<OpaqueRemoteFailureReason, string>> = {\n\tuntagged:\n\t\t\"the failure has no string `_tag`, so it cannot be told apart from an arbitrary object on the wire\",\n\tunserializable:\n\t\t\"the failure could not be serialized, even after being reduced to its own enumerable properties\",\n\tunknown: \"the cause carries no failure reason, so there was nothing to serialize\",\n\tinterrupted: \"the handler's fiber was interrupted before it produced a result\",\n};\n\nconst remedies: Readonly<Record<OpaqueRemoteFailureReason, string>> = {\n\tuntagged:\n\t\t\"Fail with a tagged error (`Data.TaggedError` or `Schema.TaggedError`) so SER can carry it to the client.\",\n\tunserializable:\n\t\t\"Remove non-transportable values (functions, class instances, cycles) from the error, or map it to a tagged error first.\",\n\tunknown:\n\t\t\"Check for a defect thrown outside the Effect error channel; the original value is shown above.\",\n\tinterrupted:\n\t\t\"An interrupt usually means the runtime was disposed mid-request, for example when the dev server restarted while this request was in flight.\",\n};\n\n/**\n * Reports a remote failure that had to be replaced with an opaque envelope.\n *\n * SER cannot send an unrecognized failure to the browser, so the client only\n * ever sees a generic 500. Without this report the original error would be\n * lost entirely, which is the difference between a debuggable failure and a\n * silent one.\n *\n * @example\n * ```ts\n * report_opaque_remote_failure(\"untagged\", cause, value, { url: \"/checkout\" });\n * ```\n *\n * @since 4.2.0\n * @param reason - Why the failure could not be transported.\n * @param cause - Full Effect cause behind the failure.\n * @param value - The original failure value, when one was found.\n * @param context - Optional request detail for the log header.\n * @param report - Sink for the rendered report; defaults to `console.error`.\n */\nexport function report_opaque_remote_failure(\n\treason: OpaqueRemoteFailureReason,\n\tcause: Cause.Cause<unknown>,\n\tvalue: unknown,\n\tcontext?: RemoteFailureContext,\n\treport: Reporter = default_reporter,\n): void {\n\t/**\n\t * Reporting runs before SvelteKit's error helper, and the failure it\n\t * describes is arbitrary user data. Throwing here would replace the 500\n\t * the handler owes the client with the reporter's own error.\n\t */\n\ttry {\n\t\treport(render_opaque_remote_failure(reason, cause, value, context));\n\t} catch {\n\t\t/** A diagnostic is never worth failing the request over. */\n\t}\n}\n\n/**\n * Renders the report emitted by {@link report_opaque_remote_failure}.\n *\n * @example\n * ```ts\n * const message = render_opaque_remote_failure(\"untagged\", cause, value);\n * ```\n *\n * @since 4.2.0\n * @param reason - Why the failure could not be transported.\n * @param cause - Full Effect cause behind the failure.\n * @param value - The original failure value, when one was found.\n * @param context - Optional request detail for the log header.\n * @returns The multi-line report.\n */\nexport function render_opaque_remote_failure(\n\treason: OpaqueRemoteFailureReason,\n\tcause: Cause.Cause<unknown>,\n\tvalue: unknown,\n\tcontext?: RemoteFailureContext,\n): string {\n\tconst request = render_request(context);\n\tconst lines = [\n\t\t\"[svelte-effect-runtime] A remote handler failed with an error that could not be sent to the client.\",\n\t\t` Reason: ${explanations[reason]}.`,\n\t];\n\n\tif (request) {\n\t\tlines.push(` Request: ${request}`);\n\t}\n\n\tif (reason !== \"interrupted\") {\n\t\tlines.push(` Failure: ${inspect_failure(value)}`);\n\t}\n\n\tlines.push(\" Cause:\", indent(pretty_cause(cause)), ` Fix: ${remedies[reason]}`);\n\n\treturn lines.join(\"\\n\");\n}\n\nfunction render_request(context?: RemoteFailureContext): string | undefined {\n\tif (!context) {\n\t\treturn undefined;\n\t}\n\n\tconst target = context.url ?? context.route;\n\tconst parts = [context.method, target].filter(Boolean);\n\tconst names_route = Boolean(context.route && context.url && context.route !== context.url);\n\tconst route = names_route ? ` (route ${context.route})` : \"\";\n\n\tif (parts.length === 0) {\n\t\treturn undefined;\n\t}\n\n\treturn `${parts.join(\" \")}${route}`;\n}\n\nfunction pretty_cause(cause: Cause.Cause<unknown>): string {\n\ttry {\n\t\treturn Cause.pretty(cause);\n\t} catch {\n\t\treturn String(cause);\n\t}\n}\n\n/**\n * Renders the failure value itself. Errors keep their stack because that is\n * the only part of an untagged failure that identifies its source.\n */\nfunction inspect_failure(value: unknown): string {\n\tif (value === undefined) {\n\t\treturn \"(none)\";\n\t}\n\n\tif (value instanceof globalThis.Error) {\n\t\treturn value.stack ?? `${value.name}: ${value.message}`;\n\t}\n\n\tif (typeof value !== \"object\" || value === null) {\n\t\treturn describe_primitive(value);\n\t}\n\n\ttry {\n\t\treturn JSON.stringify(value, undefined, 2) ?? describe_object(value);\n\t} catch {\n\t\treturn describe_object(value);\n\t}\n}\n\n/** A primitive can still carry a throwing `Symbol.toPrimitive`. */\nfunction describe_primitive(value: unknown): string {\n\ttry {\n\t\treturn String(value);\n\t} catch {\n\t\treturn typeof value;\n\t}\n}\n\n/**\n * Falls back through conversions an object can subvert. A null-prototype or\n * hostile object may throw from `toString` and lack `Object.prototype`, so the\n * last resort must not touch the value at all.\n */\nfunction describe_object(value: object): string {\n\ttry {\n\t\treturn String(value);\n\t} catch {\n\t\t/** Fall through to a conversion the value cannot override. */\n\t}\n\n\ttry {\n\t\treturn Object.prototype.toString.call(value);\n\t} catch {\n\t\treturn \"[unrenderable failure]\";\n\t}\n}\n\nfunction indent(value: string): string {\n\treturn value\n\t\t.split(\"\\n\")\n\t\t.map((line) => ` ${line}`)\n\t\t.join(\"\\n\");\n}\n\nfunction default_reporter(message: string): void {\n\tconsole.error(message);\n}\n","import type { OpaqueRemoteFailureReason } from \"$/remote/diagnostics.ts\";\nimport { isHttpError, isRedirect, isValidationError } from \"@sveltejs/kit\";\nimport { is_form_error, type FormIssue } from \"$/remote/shared.ts\";\nimport { Cause, Schema } from \"effect\";\nimport { stringify } from \"devalue\";\n\n/**\n * Records that a failure lost its detail on the way to the client, so callers\n * can report the original error instead of dropping it silently.\n *\n * @example\n * ```ts\n * const diagnostic: OpaqueRemoteFailure = { reason: \"untagged\", value: err };\n * ```\n *\n * @since 4.2.0\n */\nexport type OpaqueRemoteFailure = {\n\treadonly reason: OpaqueRemoteFailureReason;\n\treadonly value: unknown;\n};\n\ntype EncodedRemoteFailure = {\n\treadonly encoded: string;\n\treadonly opaque?: OpaqueRemoteFailure;\n};\n\nexport type RemoteCauseResolution =\n\t| {\n\t\t\treadonly _tag: \"SvelteKitControlFlow\";\n\t\t\treadonly value: unknown;\n\t }\n\t| {\n\t\t\treadonly _tag: \"InterruptOnly\";\n\t\t\treadonly cause: Cause.Cause<unknown>;\n\t }\n\t| {\n\t\t\treadonly _tag: \"FormInvalid\";\n\t\t\treadonly issues: readonly FormIssue[];\n\t }\n\t| {\n\t\t\treadonly _tag: \"RemoteFailure\";\n\t\t\treadonly encoded: string;\n\t\t\treadonly opaque?: OpaqueRemoteFailure;\n\t };\n\n/** Preserves SvelteKit control flow before classifying transportable Effect failures. */\nexport function classify_remote_cause(cause: Cause.Cause<unknown>): RemoteCauseResolution {\n\tconst control_flow = find_sveltekit_control_flow(cause);\n\n\tif (control_flow !== undefined) {\n\t\treturn {\n\t\t\t_tag: \"SvelteKitControlFlow\",\n\t\t\tvalue: control_flow,\n\t\t};\n\t}\n\n\tif (Cause.hasInterruptsOnly(cause)) {\n\t\treturn {\n\t\t\t_tag: \"InterruptOnly\",\n\t\t\tcause,\n\t\t};\n\t}\n\n\tconst form_error_issues = find_form_error_issues(cause);\n\n\tif (form_error_issues !== undefined) {\n\t\treturn {\n\t\t\t_tag: \"FormInvalid\",\n\t\t\tissues: form_error_issues,\n\t\t};\n\t}\n\n\tconst failure = encode_remote_failure_detailed(cause);\n\n\treturn {\n\t\t_tag: \"RemoteFailure\",\n\t\tencoded: failure.encoded,\n\t\t...(failure.opaque ? { opaque: failure.opaque } : {}),\n\t};\n}\n\n/** Encodes a remote failure into the transport ABI shared with generated clients. */\nexport function encode_remote_failure(cause: Cause.Cause<unknown>): string {\n\treturn encode_remote_failure_detailed(cause).encoded;\n}\n\n/**\n * Encodes a remote failure and reports whether its detail survived encoding.\n *\n * @example\n * ```ts\n * const { encoded, opaque } = encode_remote_failure_detailed(cause);\n * ```\n *\n * @since 4.2.0\n * @param cause - Cause carrying the handler's failure.\n * @returns The encoded payload and, when detail was lost, why.\n */\nexport function encode_remote_failure_detailed(cause: Cause.Cause<unknown>): EncodedRemoteFailure {\n\tfor (const reason of cause.reasons) {\n\t\tif (!Cause.isFailReason(reason)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst tagged = has_public_remote_failure_tag(reason.error);\n\n\t\tif (!tagged) {\n\t\t\treturn {\n\t\t\t\tencoded: stringify_unknown_remote_failure(),\n\t\t\t\topaque: { reason: \"untagged\", value: reason.error },\n\t\t\t};\n\t\t}\n\n\t\tconst failure = to_serializable_public_failure(reason.error);\n\t\tconst encoded = failure === undefined ? undefined : stringify_failure(failure);\n\n\t\tif (encoded !== undefined) {\n\t\t\treturn { encoded };\n\t\t}\n\n\t\treturn {\n\t\t\tencoded: stringify_unknown_remote_failure(),\n\t\t\topaque: { reason: \"unserializable\", value: reason.error },\n\t\t};\n\t}\n\n\treturn {\n\t\tencoded: stringify_unknown_remote_failure(),\n\t\topaque: { reason: \"unknown\", value: find_defect(cause) },\n\t};\n}\n\n/** Surfaces a defect so an unencodable cause still names something concrete. */\nfunction find_defect(cause: Cause.Cause<unknown>): unknown {\n\tfor (const reason of cause.reasons) {\n\t\tif (Cause.isDieReason(reason)) {\n\t\t\treturn reason.defect;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction find_sveltekit_control_flow(cause: Cause.Cause<unknown>): unknown | undefined {\n\tfor (const reason of cause.reasons) {\n\t\tif (!Cause.isDieReason(reason)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (is_sveltekit_control_flow(reason.defect)) {\n\t\t\treturn reason.defect;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction find_form_error_issues(cause: Cause.Cause<unknown>): readonly FormIssue[] | undefined {\n\tfor (const reason of cause.reasons) {\n\t\tif (!Cause.isFailReason(reason)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst issues = get_form_error_issues(reason.error);\n\n\t\tif (issues !== undefined) {\n\t\t\treturn issues;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction get_form_error_issues(value: unknown): readonly FormIssue[] | undefined {\n\tif (is_form_error(value)) {\n\t\treturn value.issues;\n\t}\n\n\treturn is_tagged_form_error(value) ? [] : undefined;\n}\n\nfunction is_sveltekit_control_flow(value: unknown): boolean {\n\treturn isRedirect(value) || isHttpError(value) || isValidationError(value);\n}\n\nfunction stringify_failure(value: unknown): string | undefined {\n\ttry {\n\t\treturn stringify(value);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction to_serializable_public_failure(value: unknown, seen = new WeakSet<object>()): unknown {\n\tif (typeof value === \"function\" || typeof value === \"symbol\") {\n\t\treturn undefined;\n\t}\n\n\tif (!is_object_like(value)) {\n\t\treturn value;\n\t}\n\n\tif (stringify_failure(value) !== undefined) {\n\t\treturn value;\n\t}\n\n\tif (is_internal_object(value)) {\n\t\treturn undefined;\n\t}\n\n\tif (seen.has(value)) {\n\t\treturn undefined;\n\t}\n\n\tseen.add(value);\n\n\tconst serializable = Array.isArray(value)\n\t\t? value.map((item) => to_serializable_public_failure(item, seen))\n\t\t: to_plain_record(value, seen);\n\n\tseen.delete(value);\n\n\treturn serializable;\n}\n\nfunction to_plain_record(value: object, seen: WeakSet<object>): Record<string, unknown> {\n\tconst descriptors = Object.getOwnPropertyDescriptors(value);\n\tconst record: Record<string, unknown> = {};\n\n\tfor (const [key, descriptor] of Object.entries(descriptors)) {\n\t\tif (key === \"stack\" || !(\"value\" in descriptor)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\trecord[key] = to_serializable_public_failure(descriptor.value, seen);\n\t}\n\n\tif (value instanceof Error && !(\"message\" in record)) {\n\t\trecord.message = value.message;\n\t}\n\n\treturn record;\n}\n\nfunction is_object_like(value: unknown): value is object {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction has_public_remote_failure_tag(value: unknown): boolean {\n\treturn is_object_like(value) && typeof (value as { _tag?: unknown })._tag === \"string\";\n}\n\nfunction is_internal_object(value: object): boolean {\n\treturn (\n\t\t!Array.isArray(value) && !is_plain_record(value) && !has_public_remote_failure_tag(value)\n\t);\n}\n\nfunction is_plain_record(value: object): boolean {\n\tconst prototype = Object.getPrototypeOf(value);\n\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nfunction create_unknown_remote_failure(): { readonly message: string } {\n\treturn { message: \"[UNKNOWN_REMOTE_FAILURE]: Unknown error\" };\n}\n\nfunction stringify_unknown_remote_failure(): string {\n\treturn stringify(create_unknown_remote_failure());\n}\n\nconst is_tagged_form_error = Schema.is(\n\tSchema.Struct({\n\t\t_tag: Schema.Literal(\"FormError\"),\n\t}),\n);\n","import { create_serialized_remote_failure_envelope } from \"$/remote/shared.ts\";\nimport { report_opaque_remote_failure } from \"$/remote/diagnostics.ts\";\nimport { RemoteHelperContextError, RemoteHelperError } from \"$/errors.ts\";\nimport type { RemoteFailureContext } from \"$/remote/diagnostics.ts\";\nimport { classify_remote_cause } from \"$/remote/cause-codec.ts\";\nimport type { FormIssue } from \"$/remote/shared.ts\";\nimport { Cause, Effect, Exit } from \"effect\";\n\ntype SvelteInvalid = (...issues: readonly (FormIssue | string)[]) => never;\n\ntype SvelteError = (status: number, body: unknown) => never;\n\nconst request_event_context_error_start =\n\t\"Can only read the current request event inside functions invoked during `handle`\";\n\nconst request_store_context_error = \"Could not get the request store.\";\n\nexport { encode_remote_failure } from \"$/remote/cause-codec.ts\";\n\n/** Maps a remote Effect exit into the control flow expected by SvelteKit. */\nexport async function run_remote_effect<A>(\n\teffect: Effect.Effect<A, unknown, unknown>,\n\truntime: {\n\t\trunPromise: (e: Effect.Effect<unknown, unknown, unknown>) => Promise<unknown>;\n\t},\n\tinvalid: SvelteInvalid,\n\terror: SvelteError,\n\tcontext?: RemoteFailureContext,\n): Promise<A> {\n\tconst exit: Exit.Exit<A, unknown> = (await runtime.runPromise(\n\t\tEffect.exit(effect) as Effect.Effect<unknown, unknown, unknown>,\n\t)) as Exit.Exit<A, unknown>;\n\n\tif (Exit.isSuccess(exit)) {\n\t\treturn exit.value;\n\t}\n\n\tthrow_remote_cause(exit.cause, invalid, error, context);\n}\n\n/** Applies a classified remote Cause decision to SvelteKit's server helpers. */\nexport function throw_remote_cause(\n\tcause: Cause.Cause<unknown>,\n\tinvalid: SvelteInvalid,\n\terror: SvelteError,\n\tcontext?: RemoteFailureContext,\n\treport?: (message: string) => void,\n): never {\n\tconst resolution = classify_remote_cause(cause);\n\n\tswitch (resolution._tag) {\n\t\tcase \"SvelteKitControlFlow\": {\n\t\t\tthrow resolution.value;\n\t\t}\n\t\tcase \"InterruptOnly\": {\n\t\t\treport_opaque_remote_failure(\n\t\t\t\t\"interrupted\",\n\t\t\t\tresolution.cause,\n\t\t\t\tundefined,\n\t\t\t\tcontext,\n\t\t\t\treport,\n\t\t\t);\n\n\t\t\tthrow Cause.squash(resolution.cause);\n\t\t}\n\t\tcase \"FormInvalid\": {\n\t\t\tinvalid(...resolution.issues);\n\t\t}\n\t\tcase \"RemoteFailure\": {\n\t\t\tconst envelope = create_serialized_remote_failure_envelope(resolution.encoded);\n\n\t\t\t/**\n\t\t\t * The client only receives a generic 500 for a failure SER could not\n\t\t\t * encode, so the original error is reported here or lost entirely.\n\t\t\t */\n\t\t\tif (resolution.opaque) {\n\t\t\t\treport_opaque_remote_failure(\n\t\t\t\t\tresolution.opaque.reason,\n\t\t\t\t\tcause,\n\t\t\t\t\tresolution.opaque.value,\n\t\t\t\t\tcontext,\n\t\t\t\t\treport,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\terror(500, envelope);\n\t\t}\n\t}\n}\n\n/**\n * Describes the request a remote failure occurred in.\n *\n * @example\n * ```ts\n * const context = to_remote_failure_context(event);\n * ```\n *\n * @since 4.2.0\n * @param event - Request event the handler ran under.\n * @returns Request detail for opaque failure reports.\n */\nexport function to_remote_failure_context(event: {\n\treadonly request?: { readonly method?: string };\n\treadonly route?: { readonly id?: string | null };\n\treadonly url?: { readonly pathname?: string };\n}): RemoteFailureContext {\n\tconst method = event.request?.method;\n\tconst route = event.route?.id ?? undefined;\n\tconst url = event.url?.pathname;\n\n\treturn {\n\t\t...(method ? { method } : {}),\n\t\t...(route ? { route } : {}),\n\t\t...(url ? { url } : {}),\n\t};\n}\n\nexport function throw_form_error(issues: readonly FormIssue[], invalid: SvelteInvalid): never {\n\tinvalid(...issues);\n}\n\n/** Rebrands SvelteKit context failures with the remote helper that triggered them. */\nexport function normalize_remote_helper_error(err: unknown, helper_name: string): Error {\n\tif (is_sveltekit_remote_context_error(err)) {\n\t\treturn new RemoteHelperContextError(helper_name);\n\t}\n\n\treturn err instanceof Error ? err : new RemoteHelperError(err);\n}\n\nfunction is_sveltekit_remote_context_error(err: unknown): err is Error {\n\tif (!(err instanceof Error)) {\n\t\treturn false;\n\t}\n\n\treturn (\n\t\terr.message.startsWith(request_event_context_error_start) ||\n\t\terr.message === request_store_context_error\n\t);\n}\n"],"mappings":";;;;;;AAiCA,MAAM,eAAoE;CACzE,UACC;CACD,gBACC;CACD,SAAS;CACT,aAAa;AACd;AAEA,MAAM,WAAgE;CACrE,UACC;CACD,gBACC;CACD,SACC;CACD,aACC;AACF;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,6BACf,QACA,OACA,OACA,SACA,SAAmB,kBACZ;;;;;;CAMP,IAAI;EACH,OAAO,6BAA6B,QAAQ,OAAO,OAAO,OAAO,CAAC;CACnE,QAAQ,CAER;AACD;;;;;;;;;;;;;;;;AAiBA,SAAgB,6BACf,QACA,OACA,OACA,SACS;CACT,MAAM,UAAU,eAAe,OAAO;CACtC,MAAM,QAAQ,CACb,uGACA,aAAa,aAAa,QAAQ,EACnC;CAEA,IAAI,SACH,MAAM,KAAK,cAAc,SAAS;CAGnC,IAAI,WAAW,eACd,M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