svelte-effect-runtime 3.4.11 → 4.0.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 (83) hide show
  1. package/.dist/chunks/{client-CsVu54pU.js → client-DcZUV4rR.js} +76 -50
  2. package/.dist/chunks/client-DcZUV4rR.js.map +1 -0
  3. package/.dist/chunks/{vite-WGlbSnso.js → compiler-BBPNyXmQ.js} +84 -110
  4. package/.dist/chunks/compiler-BBPNyXmQ.js.map +1 -0
  5. package/.dist/chunks/{dispatcher-pHH4JcFR.js → dispatcher-DOx8iC6r.js} +2 -2
  6. package/.dist/chunks/{dispatcher-pHH4JcFR.js.map → dispatcher-DOx8iC6r.js.map} +1 -1
  7. package/.dist/chunks/{dispatcher-LtvFKYUp.js → dispatcher-H-Ia0Os4.js} +3 -3
  8. package/.dist/chunks/{dispatcher-LtvFKYUp.js.map → dispatcher-H-Ia0Os4.js.map} +1 -1
  9. package/.dist/chunks/{errors-Dcf0MVbq.js → errors-IJjsUwrE.js} +21 -65
  10. package/.dist/chunks/errors-IJjsUwrE.js.map +1 -0
  11. package/.dist/chunks/live-BXAKre_4.js +104 -0
  12. package/.dist/chunks/live-BXAKre_4.js.map +1 -0
  13. package/.dist/chunks/{remote-client-Bj1pZXgq.js → remote-client-CVI4t66c.js} +2 -2
  14. package/.dist/chunks/remote-client-CVI4t66c.js.map +1 -0
  15. package/.dist/chunks/{runtime-ekkMQ-wL.js → runtime-GBQz32DZ.js} +3 -3
  16. package/.dist/chunks/{runtime-ekkMQ-wL.js.map → runtime-GBQz32DZ.js.map} +1 -1
  17. package/.dist/chunks/schema-D9pct6Y5.js +89 -0
  18. package/.dist/chunks/schema-D9pct6Y5.js.map +1 -0
  19. package/.dist/chunks/server-D1LcDnZE.js +213 -0
  20. package/.dist/chunks/server-D1LcDnZE.js.map +1 -0
  21. package/.dist/chunks/source-scan-C4PsggID.js +341 -0
  22. package/.dist/chunks/source-scan-C4PsggID.js.map +1 -0
  23. package/.dist/chunks/{transform-CtQDGS9c.js → transform-jNUr65K9.js} +237 -239
  24. package/.dist/chunks/transform-jNUr65K9.js.map +1 -0
  25. package/.dist/compiler/source-scan.d.ts +198 -0
  26. package/.dist/{vite.d.ts → compiler.d.ts} +1 -1
  27. package/.dist/{vite.js → compiler.js} +1 -1
  28. package/.dist/dispatcher.js +1 -1
  29. package/.dist/errors.d.ts +15 -45
  30. package/.dist/generators.d.ts +3 -1
  31. package/.dist/internal/generators.js +20 -3
  32. package/.dist/internal/generators.js.map +1 -0
  33. package/.dist/internal/remote-client.js +1 -1
  34. package/.dist/internal/remote-server.js +1 -1
  35. package/.dist/internal/schema.d.ts +67 -0
  36. package/.dist/live.d.ts +123 -0
  37. package/.dist/markup/event-attributes.d.ts +16 -7
  38. package/.dist/markup/promise.js +1 -1
  39. package/.dist/markup/run.js +1 -1
  40. package/.dist/markup/transform/constants.d.ts +1 -0
  41. package/.dist/markup/transform/types.d.ts +1 -0
  42. package/.dist/markup/transform.js +1 -1
  43. package/.dist/markup/value.js +1 -1
  44. package/.dist/mod.d.ts +6 -3
  45. package/.dist/mod.js +5 -4
  46. package/.dist/mod.js.map +1 -1
  47. package/.dist/remote/cause-codec.d.ts +53 -0
  48. package/.dist/remote/client/form-transport.d.ts +4 -1
  49. package/.dist/remote/client/form.d.ts +10 -1
  50. package/.dist/remote/client/index.d.ts +1 -1
  51. package/.dist/remote/client/query.d.ts +6 -16
  52. package/.dist/remote/client/types.d.ts +32 -13
  53. package/.dist/remote/client.d.ts +1 -1
  54. package/.dist/remote/client.js +1 -1
  55. package/.dist/remote/server.d.ts +2 -12
  56. package/.dist/remote/server.js +1 -178
  57. package/.dist/runtime/transform.js +81 -68
  58. package/.dist/runtime/transform.js.map +1 -1
  59. package/.dist/script-transform/imports.d.ts +2 -0
  60. package/.dist/script-transform/types.d.ts +8 -0
  61. package/.dist/server/effects.d.ts +7 -7
  62. package/.dist/server/handler.d.ts +37 -0
  63. package/.dist/server/index.d.ts +4 -1
  64. package/.dist/server/schema.d.ts +2 -26
  65. package/.dist/server/types.d.ts +44 -50
  66. package/.dist/server/wrappers.d.ts +2 -2
  67. package/.dist/server.d.ts +2 -2
  68. package/.dist/server.js +88 -97
  69. package/.dist/server.js.map +1 -1
  70. package/.dist/yieldable.d.ts +41 -0
  71. package/README.md +1 -1
  72. package/package.json +4 -4
  73. package/.dist/chunks/client-CsVu54pU.js.map +0 -1
  74. package/.dist/chunks/descriptors-cOe9uRJz.js +0 -36
  75. package/.dist/chunks/descriptors-cOe9uRJz.js.map +0 -1
  76. package/.dist/chunks/errors-Dcf0MVbq.js.map +0 -1
  77. package/.dist/chunks/event-attributes-gHzP2ycp.js +0 -39
  78. package/.dist/chunks/event-attributes-gHzP2ycp.js.map +0 -1
  79. package/.dist/chunks/remote-client-Bj1pZXgq.js.map +0 -1
  80. package/.dist/chunks/transform-CtQDGS9c.js.map +0 -1
  81. package/.dist/chunks/vite-WGlbSnso.js.map +0 -1
  82. package/.dist/remote/server.js.map +0 -1
  83. /package/.dist/{vite → compiler}/remote-client.d.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-BXAKre_4.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/live.ts"],"sourcesContent":["import { Effect, Stream } from \"effect\";\n\nimport { InvalidLiveQueryFactoryError } from \"$/errors.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\n\n/**\n * Runtime marker attached to remote live streams created by SER.\n *\n * @since 3.4.8\n */\nexport const REMOTE_LIVE_STREAM: unique symbol = Symbol.for(\"ser.remote-live-stream\") as never;\n\nconst LIVE_METADATA: unique symbol = Symbol.for(\"ser.remote-live-metadata\") as never;\n\nconst LIVE_OPERATOR: unique symbol = Symbol.for(\"ser.live-operator\") as never;\n\ntype RemoteLivePipe<A, E> = {\n\t(): RemoteLiveStream<A, E>;\n\t(ab: LiveFactory[\"status\"]): Stream.Stream<LiveStatus, never, never>;\n\t(ab: LiveFactory[\"reconnect\"]): Effect.Effect<void, RemoteFailure<E>, never>;\n\t<B>(ab: LiveFactory[\"status\"], bc: (_: Stream.Stream<LiveStatus, never, never>) => B): B;\n\t<B>(\n\t\tab: LiveFactory[\"reconnect\"],\n\t\tbc: (_: Effect.Effect<void, RemoteFailure<E>, never>) => B,\n\t): B;\n\t<B, C>(\n\t\tab: LiveFactory[\"status\"],\n\t\tbc: (_: Stream.Stream<LiveStatus, never, never>) => B,\n\t\tcd: (_: B) => C,\n\t): C;\n\t<B, C>(\n\t\tab: LiveFactory[\"reconnect\"],\n\t\tbc: (_: Effect.Effect<void, RemoteFailure<E>, never>) => B,\n\t\tcd: (_: B) => C,\n\t): C;\n\t<B>(\n\t\tab: (\n\t\t\t_: Stream.Stream<A, RemoteFailure<E>, never>,\n\t\t) => Stream.Stream<B, RemoteFailure<E>, never>,\n\t): RemoteLiveStream<B, E>;\n\t<B>(ab: (_: Stream.Stream<A, RemoteFailure<E>, never>) => B): B;\n\t<B, C>(ab: (_: Stream.Stream<A, RemoteFailure<E>, never>) => B, bc: (_: B) => C): C;\n\t<B, C, D>(\n\t\tab: (_: Stream.Stream<A, RemoteFailure<E>, never>) => B,\n\t\tbc: (_: B) => C,\n\t\tcd: (_: C) => D,\n\t): D;\n};\n\n/**\n * Stream returned by `Query.live` remote functions.\n *\n * @example\n * ```ts\n * const Time = GetTime();\n * const Label = Time.pipe(Stream.map((time) => time.toISOString()));\n * ```\n *\n * @since 3.4.8\n */\nexport type RemoteLiveStream<A, E = never> = Omit<\n\tStream.Stream<A, RemoteFailure<E>, never>,\n\t\"pipe\"\n> & {\n\treadonly [REMOTE_LIVE_STREAM]: true;\n\treadonly pipe: RemoteLivePipe<A, E>;\n};\n\n/**\n * Transport state exposed separately from the data stream.\n *\n * @example\n * ```ts\n * const Status = GetTime().pipe(Live.status);\n * ```\n *\n * @since 3.4.8\n */\nexport type LiveStatus =\n\t| {\n\t\t\treadonly _tag: \"Idle\";\n\t }\n\t| {\n\t\t\treadonly _tag: \"Connecting\";\n\t }\n\t| {\n\t\t\treadonly _tag: \"Open\";\n\t }\n\t| {\n\t\t\treadonly _tag: \"Failed\";\n\t\t\treadonly cause: unknown;\n\t }\n\t| {\n\t\t\treadonly _tag: \"Closed\";\n\t };\n\n/**\n * Public live stream control helpers.\n *\n * @example\n * ```ts\n * yield* GetNotifications().pipe(Live.reconnect);\n * ```\n *\n * @since 3.4.8\n */\nexport interface LiveFactory {\n\treadonly status: {\n\t\treadonly [LIVE_OPERATOR]: true;\n\t\t/**\n\t\t * Creates a stream of transport status updates for a remote live stream.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * const Status = GetTime().pipe(Live.status);\n\t\t * ```\n\t\t *\n\t\t * @param stream - Remote live stream whose transport status should be read.\n\t\t * @returns A stream of transport status snapshots.\n\t\t */\n\t\t<A, E>(stream: RemoteLiveStream<A, E>): Stream.Stream<LiveStatus, never, never>;\n\t};\n\treadonly reconnect: {\n\t\treadonly [LIVE_OPERATOR]: true;\n\t\t/**\n\t\t * Reconnects the transport behind a remote live stream.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * yield* GetNotifications().pipe(Live.reconnect);\n\t\t * ```\n\t\t *\n\t\t * @param stream - Remote live stream whose transport should reconnect.\n\t\t * @returns An Effect that completes after the reconnect request is sent.\n\t\t */\n\t\t<A, E>(stream: RemoteLiveStream<A, E>): Effect.Effect<void, RemoteFailure<E>, never>;\n\t};\n}\n\ntype NativeLiveResource<A> = {\n\treadonly connected?: boolean;\n\treadonly current?: A;\n\treadonly done?: boolean;\n\treadonly error?: unknown;\n\treadonly loading?: boolean;\n\treadonly ready?: boolean;\n\treadonly reconnect?: () => Promise<void> | void;\n\treadonly [Symbol.asyncIterator]?: () => AsyncIterator<A>;\n};\n\ntype LiveMetadata<A = unknown, ErrorType = never> = {\n\treadonly resource: NativeLiveResource<A>;\n\treadonly on_error: (error: unknown) => RemoteFailure<ErrorType>;\n};\n\ntype LiveMetadataCarrier = {\n\treadonly [LIVE_METADATA]?: LiveMetadata<unknown, unknown>;\n};\n\ntype PipeableStream<A, E, R> = Stream.Stream<A, E, R> & {\n\treadonly pipe: (...args: readonly unknown[]) => unknown;\n};\n\n/**\n * Builds a remote live stream from SvelteKit's native live resource.\n *\n * @example\n * ```ts\n * const stream = make_remote_live_stream(resource, normalize_native_error);\n * ```\n *\n * @since 3.4.8\n * @param resource - Native SvelteKit live query resource.\n * @param on_error - Error mapper used for stream and reconnect failures.\n * @returns A remote live stream carrying hidden transport metadata.\n * @internal\n */\nexport function make_remote_live_stream<A, ErrorType = never>(\n\tresource: unknown,\n\ton_error: (error: unknown) => RemoteFailure<ErrorType>,\n): RemoteLiveStream<A, ErrorType> {\n\tconst live_resource = as_native_live_resource<A>(resource);\n\tconst stream = Stream.fromAsyncIterable(live_resource, on_error);\n\tconst metadata: LiveMetadata<A, ErrorType> = {\n\t\tresource: live_resource,\n\t\ton_error,\n\t};\n\n\treturn attach_live_metadata(stream, metadata) as RemoteLiveStream<A, ErrorType>;\n}\n\nconst live_status = Object.assign(\n\tfunction status<A, E>(stream: RemoteLiveStream<A, E>): Stream.Stream<LiveStatus, never, never> {\n\t\tconst metadata = get_live_metadata(stream);\n\n\t\tif (!metadata) {\n\t\t\treturn Stream.succeed({ _tag: \"Idle\" } as const);\n\t\t}\n\n\t\treturn Stream.succeed(read_live_status(metadata.resource)).pipe(\n\t\t\tStream.concat(\n\t\t\t\tStream.tick(\"250 millis\").pipe(\n\t\t\t\t\tStream.map(() => read_live_status(metadata.resource)),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t},\n\t{ [LIVE_OPERATOR]: true as const },\n) satisfies LiveFactory[\"status\"];\n\nconst live_reconnect = Object.assign(\n\tfunction reconnect<A, E>(\n\t\tstream: RemoteLiveStream<A, E>,\n\t): Effect.Effect<void, RemoteFailure<E>, never> {\n\t\tconst metadata = get_live_metadata(stream);\n\t\tconst reconnect = metadata?.resource.reconnect;\n\n\t\tif (!metadata || typeof reconnect !== \"function\") {\n\t\t\treturn Effect.fail(new InvalidLiveQueryFactoryError()) as unknown as Effect.Effect<\n\t\t\t\tvoid,\n\t\t\t\tRemoteFailure<E>,\n\t\t\t\tnever\n\t\t\t>;\n\t\t}\n\n\t\treturn Effect.tryPromise({\n\t\t\ttry: () => Promise.resolve(reconnect.call(metadata.resource)),\n\t\t\tcatch: metadata.on_error,\n\t\t}) as Effect.Effect<void, RemoteFailure<E>, never>;\n\t},\n\t{ [LIVE_OPERATOR]: true as const },\n) satisfies LiveFactory[\"reconnect\"];\n\n/**\n * Remote live transport helpers.\n *\n * @since 3.4.8\n */\nexport const Live: LiveFactory = {\n\tstatus: live_status,\n\treconnect: live_reconnect,\n};\n\nfunction as_native_live_resource<A>(resource: unknown): NativeLiveResource<A> & AsyncIterable<A> {\n\tif (!is_native_live_resource<A>(resource)) {\n\t\tthrow new InvalidLiveQueryFactoryError();\n\t}\n\n\treturn resource;\n}\n\nfunction is_native_live_resource<A>(\n\tresource: unknown,\n): resource is NativeLiveResource<A> & AsyncIterable<A> {\n\tconst resource_type = typeof resource;\n\n\tif (resource_type !== \"object\" && resource_type !== \"function\") {\n\t\treturn false;\n\t}\n\n\tif (resource === null) {\n\t\treturn false;\n\t}\n\n\treturn typeof (resource as NativeLiveResource<A>)[Symbol.asyncIterator] === \"function\";\n}\n\nfunction attach_live_metadata<A, E, R>(\n\tstream: Stream.Stream<A, E, R>,\n\tmetadata: LiveMetadata<unknown, unknown>,\n): Stream.Stream<A, E, R> {\n\tconst carrier = stream as Stream.Stream<A, E, R> & LiveMetadataCarrier;\n\n\tif (carrier[LIVE_METADATA]) {\n\t\treturn stream;\n\t}\n\n\tObject.defineProperty(carrier, LIVE_METADATA, {\n\t\tconfigurable: true,\n\t\tvalue: metadata,\n\t});\n\n\tObject.defineProperty(carrier, REMOTE_LIVE_STREAM, {\n\t\tconfigurable: true,\n\t\tvalue: true,\n\t});\n\n\tpropagate_live_metadata_through_pipe(carrier as PipeableStream<A, E, R>, metadata);\n\n\treturn stream;\n}\n\nfunction propagate_live_metadata_through_pipe<A, E, R>(\n\tstream: PipeableStream<A, E, R>,\n\tmetadata: LiveMetadata<unknown, unknown>,\n): void {\n\tconst pipe = stream.pipe.bind(stream);\n\n\tObject.defineProperty(stream, \"pipe\", {\n\t\tconfigurable: true,\n\t\tvalue: (...args: readonly unknown[]) => {\n\t\t\tconst result = pipe(...args);\n\n\t\t\tif (Stream.isStream(result)) {\n\t\t\t\treturn attach_live_metadata(result, metadata);\n\t\t\t}\n\n\t\t\treturn result;\n\t\t},\n\t});\n}\n\nfunction get_live_metadata<A, E>(stream: RemoteLiveStream<A, E>): LiveMetadata<A, E> | undefined;\nfunction get_live_metadata(\n\tstream: Stream.Stream<unknown, unknown, unknown>,\n): LiveMetadata<unknown, unknown> | undefined;\nfunction get_live_metadata(\n\tstream: Stream.Stream<unknown, unknown, unknown>,\n): LiveMetadata<unknown, unknown> | undefined {\n\treturn (stream as LiveMetadataCarrier)[LIVE_METADATA];\n}\n\nfunction read_live_status(resource: NativeLiveResource<unknown>): LiveStatus {\n\tif (resource.error !== undefined) {\n\t\treturn {\n\t\t\t_tag: \"Failed\",\n\t\t\tcause: resource.error,\n\t\t};\n\t}\n\n\tif (resource.done === true) {\n\t\treturn { _tag: \"Closed\" };\n\t}\n\n\tif (resource.connected === true) {\n\t\treturn { _tag: \"Open\" };\n\t}\n\n\treturn { _tag: \"Connecting\" };\n}\n"],"mappings":";;;;;;;;AAUA,MAAa,qBAAoC,OAAO,IAAI,wBAAwB;AAEpF,MAAM,gBAA+B,OAAO,IAAI,0BAA0B;AAE1E,MAAM,gBAA+B,OAAO,IAAI,mBAAmB;;;;;;;;;;;;;;;AAmKnE,SAAgB,wBACf,UACA,UACiC;CACjC,MAAM,gBAAgB,wBAA2B,QAAQ;CAOzD,OAAO,qBANQ,OAAO,kBAAkB,eAAe,QAMtB,GAAG;EAJnC,UAAU;EACV;CAG0C,CAAC;AAC7C;;;;;;AAiDA,MAAa,OAAoB;CAChC,QAhDmB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R;AAEA,SAAS,qCACR,QACA,UACO;CACP,MAAM,OAAO,OAAO,KAAK,KAAK,MAAM;CAEpC,OAAO,eAAe,QAAQ,QAAQ;EACrC,cAAc;EACd,QAAQ,GAAG,SAA6B;GACvC,MAAM,SAAS,KAAK,GAAG,IAAI;GAE3B,IAAI,OAAO,SAAS,MAAM,GACzB,OAAO,qBAAqB,QAAQ,QAAQ;GAG7C,OAAO;EACR;CACD,CAAC;AACF;AAMA,SAAS,kBACR,QAC6C;CAC7C,OAAQ,OAA+B;AACxC;AAEA,SAAS,iBAAiB,UAAmD;CAC5E,IAAI,SAAS,UAAU,KAAA,GACtB,OAAO;EACN,MAAM;EACN,OAAO,SAAS;CACjB;CAGD,IAAI,SAAS,SAAS,MACrB,OAAO,EAAE,MAAM,SAAS;CAGzB,IAAI,SAAS,cAAc,MAC1B,OAAO,EAAE,MAAM,OAAO;CAGvB,OAAO,EAAE,MAAM,aAAa;AAC7B"}
@@ -1,6 +1,6 @@
1
1
  import ts from "typescript";
2
2
  import MagicString from "magic-string";
3
- //#region src/vite/remote-client.ts
3
+ //#region src/compiler/remote-client.ts
4
4
  const remote_client_export_types = /* @__PURE__ */ new Set([
5
5
  "query_batch",
6
6
  "query_live",
@@ -105,4 +105,4 @@ function is_const_declaration_list(declaration_list) {
105
105
  //#endregion
106
106
  export { rewrite_remote_client_exports };
107
107
 
108
- //# sourceMappingURL=remote-client-Bj1pZXgq.js.map
108
+ //# sourceMappingURL=remote-client-CVI4t66c.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-client-CVI4t66c.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/compiler/remote-client.ts"],"sourcesContent":["import type {\n\tExpression,\n\tImportDeclaration,\n\tSourceFile,\n\tStatement,\n\tVariableStatement,\n} from \"typescript\";\n\nimport MagicString from \"magic-string\";\nimport ts from \"typescript\";\n\ninterface RemoteClientRewriteOptions {\n\tdebug?: boolean;\n}\n\ntype RemoteClientExportType =\n\t| \"query_batch\"\n\t| \"query_live\"\n\t| \"query\"\n\t| \"command\"\n\t| \"form\"\n\t| \"prerender\";\n\ninterface RemoteNamespaceImport {\n\tname: string;\n\tstatement: ImportDeclaration;\n}\n\ninterface RemoteClientExport {\n\tname: string;\n\ttype: RemoteClientExportType;\n\tstatement: VariableStatement;\n\tnative_call: string;\n}\n\nconst remote_client_export_types = new Set<RemoteClientExportType>([\n\t\"query_batch\",\n\t\"query_live\",\n\t\"query\",\n\t\"command\",\n\t\"form\",\n\t\"prerender\",\n]);\n\n/**\n * Rewrites SvelteKit's generated client remote module into Effect-aware\n * wrappers while preserving the native remote factory calls.\n *\n * @example\n * ```ts\n * const rewritten = rewrite_remote_client_exports(\n * `export const get_post = __remote.query(\"hash/get_post\")`,\n * );\n * ```\n *\n * @since 2.0.0\n * @param code - Generated SvelteKit remote client module source to inspect and\n * rewrite.\n * @param options - Optional rewrite options forwarded from the SER Vite plugin.\n * @returns The rewritten module source, or the original source when no remote\n * exports are found.\n * @internal\n */\nexport function rewrite_remote_client_exports(\n\tcode: string,\n\toptions?: RemoteClientRewriteOptions,\n): string {\n\tconst source_file = ts.createSourceFile(\n\t\t\"sveltekit-remote-client.ts\",\n\t\tcode,\n\t\tts.ScriptTarget.Latest,\n\t\ttrue,\n\t\tts.ScriptKind.TS,\n\t);\n\tconst namespace_import = find_remote_namespace_import(source_file);\n\n\tif (!namespace_import) {\n\t\treturn code;\n\t}\n\n\tconst remote_exports = collect_remote_client_exports(source_file, code, namespace_import.name);\n\n\tif (remote_exports.length === 0) {\n\t\treturn code;\n\t}\n\n\tconst magic = new MagicString(code);\n\tconst imports = [\n\t\t`import { app_dir, base } from \"$app/paths/internal/client\";`,\n\t\t`import { create_remote_query_adapter, create_remote_live_query_adapter, create_remote_command_adapter, create_remote_form_adapter } from \"svelte-effect-runtime/internal/remote-client\";`,\n\t].join(\"\\n\");\n\tconst helpers = [\n\t\t`const __SER___remote_base = \\`\\${base}/\\${app_dir}/remote\\`;`,\n\t\t`function __SER___decode_payload(value) { return value; }`,\n\t].join(\"\\n\");\n\tconst debug_line = options?.debug ? `console.log(\"[ser] remote client wrappers loaded\");` : \"\";\n\tconst injected = [imports, helpers, debug_line].filter(Boolean).join(\"\\n\");\n\n\tmagic.appendRight(namespace_import.statement.end, `\\n${injected}`);\n\n\tfor (const remote_export of remote_exports) {\n\t\tmagic.overwrite(\n\t\t\tremote_export.statement.getStart(source_file),\n\t\t\tremote_export.statement.end,\n\t\t\tmake_remote_export(remote_export.name, remote_export.type, remote_export.native_call),\n\t\t);\n\t}\n\n\treturn magic.toString();\n}\n\nfunction make_remote_export(\n\tname: string,\n\tremote_type: RemoteClientExportType,\n\tnative_call: string,\n): string {\n\tif (remote_type === \"command\") {\n\t\treturn `export const ${name} = create_remote_command_adapter(${native_call}, __SER___decode_payload);`;\n\t}\n\n\tif (remote_type === \"form\") {\n\t\treturn `export const ${name} = create_remote_form_adapter(${native_call}, __SER___decode_payload, __SER___remote_base);`;\n\t}\n\n\tif (remote_type === \"query_live\") {\n\t\treturn `export const ${name} = create_remote_live_query_adapter(${native_call}, __SER___decode_payload);`;\n\t}\n\n\treturn `export const ${name} = create_remote_query_adapter(${native_call}, __SER___decode_payload);`;\n}\n\nfunction find_remote_namespace_import(source_file: SourceFile): RemoteNamespaceImport | undefined {\n\tfor (const statement of source_file.statements) {\n\t\tif (!ts.isImportDeclaration(statement)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst namespace_import = get_remote_namespace_import(statement);\n\n\t\tif (namespace_import) {\n\t\t\treturn namespace_import;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction get_remote_namespace_import(\n\tstatement: ImportDeclaration,\n): RemoteNamespaceImport | undefined {\n\tif (\n\t\t!ts.isStringLiteral(statement.moduleSpecifier) ||\n\t\tstatement.moduleSpecifier.text !== \"__sveltekit/remote\"\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst import_clause = statement.importClause;\n\tconst bindings = import_clause?.namedBindings;\n\n\tif (import_clause?.isTypeOnly || !bindings || !ts.isNamespaceImport(bindings)) {\n\t\treturn undefined;\n\t}\n\n\treturn {\n\t\tname: bindings.name.text,\n\t\tstatement,\n\t};\n}\n\nfunction collect_remote_client_exports(\n\tsource_file: SourceFile,\n\tcode: string,\n\tnamespace: string,\n): RemoteClientExport[] {\n\treturn source_file.statements.flatMap((statement) =>\n\t\tcollect_remote_client_export(source_file, code, namespace, statement),\n\t);\n}\n\nfunction collect_remote_client_export(\n\tsource_file: SourceFile,\n\tcode: string,\n\tnamespace: string,\n\tstatement: Statement,\n): RemoteClientExport[] {\n\tif (\n\t\t!ts.isVariableStatement(statement) ||\n\t\t!is_export_statement(statement) ||\n\t\t!is_const_declaration_list(statement.declarationList) ||\n\t\tstatement.declarationList.declarations.length !== 1\n\t) {\n\t\treturn [];\n\t}\n\n\tconst declaration = statement.declarationList.declarations[0];\n\tconst initializer = declaration.initializer;\n\n\tif (!ts.isIdentifier(declaration.name) || !initializer) {\n\t\treturn [];\n\t}\n\n\tconst remote_type = get_remote_client_export_type(initializer, namespace);\n\n\tif (!remote_type) {\n\t\treturn [];\n\t}\n\n\treturn [\n\t\t{\n\t\t\tname: declaration.name.text,\n\t\t\ttype: remote_type,\n\t\t\tstatement,\n\t\t\tnative_call: code.slice(initializer.getStart(source_file), initializer.end),\n\t\t},\n\t];\n}\n\nfunction get_remote_client_export_type(\n\tinitializer: Expression,\n\tnamespace: string,\n): RemoteClientExportType | undefined {\n\tif (!ts.isCallExpression(initializer)) {\n\t\treturn undefined;\n\t}\n\n\tconst expression = initializer.expression;\n\n\tif (!ts.isPropertyAccessExpression(expression)) {\n\t\treturn undefined;\n\t}\n\n\tif (!ts.isIdentifier(expression.expression) || expression.expression.text !== namespace) {\n\t\treturn undefined;\n\t}\n\n\tconst remote_type = expression.name.text;\n\n\tif (!is_remote_client_export_type(remote_type)) {\n\t\treturn undefined;\n\t}\n\n\treturn remote_type;\n}\n\nfunction is_remote_client_export_type(value: string): value is RemoteClientExportType {\n\treturn remote_client_export_types.has(value as RemoteClientExportType);\n}\n\nfunction is_export_statement(statement: Statement): boolean {\n\tconst modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) : undefined;\n\n\treturn modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;\n}\n\nfunction is_const_declaration_list(declaration_list: ts.VariableDeclarationList): boolean {\n\treturn (ts.getCombinedNodeFlags(declaration_list) & ts.NodeFlags.Const) !== 0;\n}\n"],"mappings":";;;AAmCA,MAAM,6CAA6B,IAAI,IAA4B;CAClE;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;;;;;;;;;;;;;;;;;;;AAqBD,SAAgB,8BACf,MACA,SACS;CACT,MAAM,cAAc,GAAG,iBACtB,8BACA,MACA,GAAG,aAAa,QAChB,MACA,GAAG,WAAW,EACf;CACA,MAAM,mBAAmB,6BAA6B,WAAW;CAEjE,IAAI,CAAC,kBACJ,OAAO;CAGR,MAAM,iBAAiB,8BAA8B,aAAa,MAAM,iBAAiB,IAAI;CAE7F,IAAI,eAAe,WAAW,GAC7B,OAAO;CAGR,MAAM,QAAQ,IAAI,YAAY,IAAI;CAUlC,MAAM,WAAW;EATD,CACf,+DACA,0LACD,CAAC,CAAC,KAAK,IAMiB;EALR,CACf,gEACA,0DACD,CAAC,CAAC,KAAK,IAE0B;EADd,SAAS,QAAQ,wDAAwD;CAC9C,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI;CAEzE,MAAM,YAAY,iBAAiB,UAAU,KAAK,KAAK,UAAU;CAEjE,KAAK,MAAM,iBAAiB,gBAC3B,MAAM,UACL,cAAc,UAAU,SAAS,WAAW,GAC5C,cAAc,UAAU,KACxB,mBAAmB,cAAc,MAAM,cAAc,MAAM,cAAc,WAAW,CACrF;CAGD,OAAO,MAAM,SAAS;AACvB;AAEA,SAAS,mBACR,MACA,aACA,aACS;CACT,IAAI,gBAAgB,WACnB,OAAO,gBAAgB,KAAK,mCAAmC,YAAY;CA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,WAAW,GAAG,YAAY,GAAG;CAC3E,CACD;AACD;AAEA,SAAS,8BACR,aACA,WACqC;CACrC,IAAI,CAAC,GAAG,iBAAiB,WAAW,GACnC;CAGD,MAAM,aAAa,YAAY;CAE/B,IAAI,CAAC,GAAG,2BAA2B,UAAU,GAC5C;CAGD,IAAI,CAAC,GAAG,aAAa,WAAW,UAAU,KAAK,WAAW,WAAW,SAAS,WAC7E;CAGD,MAAM,cAAc,WAAW,KAAK;CAEpC,IAAI,CAAC,6BAA6B,WAAW,GAC5C;CAGD,OAAO;AACR;AAEA,SAAS,6BAA6B,OAAgD;CACrF,OAAO,2BAA2B,IAAI,KAA+B;AACtE;AAEA,SAAS,oBAAoB,WAA+B;CAG3D,QAFkB,GAAG,iBAAiB,SAAS,IAAI,GAAG,aAAa,SAAS,IAAI,KAAA,EAAA,EAE9D,MAAM,aAAa,SAAS,SAAS,GAAG,WAAW,aAAa,KAAK;AACxF;AAEA,SAAS,0BAA0B,kBAAuD;CACzF,QAAQ,GAAG,qBAAqB,gBAAgB,IAAI,GAAG,UAAU,WAAW;AAC7E"}
@@ -1,5 +1,5 @@
1
- import { _ as RuntimeAlreadyInitializedError, g as RequestEventUnavailableError } from "./errors-Dcf0MVbq.js";
2
- import { t as Dispatcher } from "./dispatcher-pHH4JcFR.js";
1
+ import { _ as RequestEventUnavailableError, v as RuntimeAlreadyInitializedError } from "./errors-IJjsUwrE.js";
2
+ import { t as Dispatcher } from "./dispatcher-DOx8iC6r.js";
3
3
  import { Context, Layer, ManagedRuntime } from "effect";
4
4
  //#region src/server/runtime.ts
5
5
  /**
@@ -114,4 +114,4 @@ function reset_server_runtime() {
114
114
  //#endregion
115
115
  export { get_server_runtime_or_throw as i, ServerRuntime as n, get_server_dispatcher as r, RequestEvent as t };
116
116
 
117
- //# sourceMappingURL=runtime-ekkMQ-wL.js.map
117
+ //# sourceMappingURL=runtime-GBQz32DZ.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-ekkMQ-wL.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 * @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\n/**\n * Returns a dispatcher backed by the active server runtime.\n *\n * @example\n * ```ts\n * const dispatcher = get_server_dispatcher();\n * ```\n *\n * @since 3.0.1\n * @returns The cached server dispatcher, creating one from the current server\n * runtime when needed.\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\n/**\n * Resets the internal server runtime singleton used by source-level tests.\n *\n * @example\n * ```ts\n * reset_server_runtime();\n * ```\n *\n * @since 3.4.0\n * @returns Nothing.\n * @internal\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":";;;;;;;;;;;;;;AAkCA,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;;;;;;;;;;;;;AAcA,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;;;;;;;;;;;;;AAcA,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-GBQz32DZ.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 * @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\n/**\n * Returns a dispatcher backed by the active server runtime.\n *\n * @example\n * ```ts\n * const dispatcher = get_server_dispatcher();\n * ```\n *\n * @since 3.0.1\n * @returns The cached server dispatcher, creating one from the current server\n * runtime when needed.\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\n/**\n * Resets the internal server runtime singleton used by source-level tests.\n *\n * @example\n * ```ts\n * reset_server_runtime();\n * ```\n *\n * @since 3.4.0\n * @returns Nothing.\n * @internal\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":";;;;;;;;;;;;;;AAkCA,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;;;;;;;;;;;;;AAcA,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;;;;;;;;;;;;;AAcA,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,89 @@
1
+ import { Schema } from "effect";
2
+ //#region src/internal/descriptors.ts
3
+ const default_excluded_descriptor_keys = /* @__PURE__ */ new Set([
4
+ "length",
5
+ "name",
6
+ "prototype"
7
+ ]);
8
+ /**
9
+ * Copies own property descriptors from a native helper to a wrapper while
10
+ * skipping function metadata and any caller-specific keys.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * copy_property_descriptors(native_remote, wrapped_remote);
15
+ * ```
16
+ *
17
+ * @since 2.0.0
18
+ * @param source - Source object or function whose descriptors should be
19
+ * mirrored.
20
+ * @param target - Wrapper object or function that receives copied descriptors.
21
+ * @param exclude - Additional property keys that should not be copied.
22
+ * @returns Nothing.
23
+ */
24
+ function copy_property_descriptors(source, target, exclude = default_excluded_descriptor_keys) {
25
+ if (typeof source !== "object" && typeof source !== "function") return;
26
+ if (source === null) return;
27
+ for (const key of Reflect.ownKeys(source)) {
28
+ if (default_excluded_descriptor_keys.has(key) || exclude.has(key)) continue;
29
+ const descriptor = Object.getOwnPropertyDescriptor(source, key);
30
+ if (!descriptor) continue;
31
+ Object.defineProperty(target, key, descriptor);
32
+ }
33
+ }
34
+ //#endregion
35
+ //#region src/internal/schema.ts
36
+ /**
37
+ * Checks whether a value implements the Standard Schema contract.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * if (is_standard_schema(value)) {
42
+ * value["~standard"].validate(input);
43
+ * }
44
+ * ```
45
+ *
46
+ * @since 2.0.0
47
+ * @param value - Value to inspect.
48
+ * @returns Whether the value is a Standard Schema.
49
+ */
50
+ function is_standard_schema(value) {
51
+ return typeof value === "object" && value !== null && "~standard" in value;
52
+ }
53
+ /**
54
+ * Checks whether a value looks like an Effect Schema.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * if (is_effect_schema(value)) {
59
+ * Schema.toStandardSchemaV1(value);
60
+ * }
61
+ * ```
62
+ *
63
+ * @since 2.0.0
64
+ * @param value - Value to inspect.
65
+ * @returns Whether the value should be converted to Standard Schema.
66
+ */
67
+ function is_effect_schema(value) {
68
+ return typeof value === "object" && value !== null && "ast" in value && "make" in value;
69
+ }
70
+ /**
71
+ * Converts Effect Schema inputs to Standard Schema for SvelteKit.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const validator = normalize_validator(Schema.Struct({ title: Schema.String }));
76
+ * ```
77
+ *
78
+ * @since 2.0.0
79
+ * @param value - Schema or handler input.
80
+ * @returns Original value or Standard Schema view of an Effect Schema.
81
+ */
82
+ function normalize_validator(value) {
83
+ if (is_standard_schema(value) || !is_effect_schema(value)) return value;
84
+ return Schema.toStandardSchemaV1(value);
85
+ }
86
+ //#endregion
87
+ export { normalize_validator as n, copy_property_descriptors as r, is_standard_schema as t };
88
+
89
+ //# sourceMappingURL=schema-D9pct6Y5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-D9pct6Y5.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/internal/descriptors.ts","../../../modules/svelte-effect-runtime/src/internal/schema.ts"],"sourcesContent":["const default_excluded_descriptor_keys = new Set<PropertyKey>([\"length\", \"name\", \"prototype\"]);\n\n/**\n * Copies own property descriptors from a native helper to a wrapper while\n * skipping function metadata and any caller-specific keys.\n *\n * @example\n * ```ts\n * copy_property_descriptors(native_remote, wrapped_remote);\n * ```\n *\n * @since 2.0.0\n * @param source - Source object or function whose descriptors should be\n * mirrored.\n * @param target - Wrapper object or function that receives copied descriptors.\n * @param exclude - Additional property keys that should not be copied.\n * @returns Nothing.\n */\nexport function copy_property_descriptors(\n\tsource: unknown,\n\ttarget: object,\n\texclude: ReadonlySet<PropertyKey> = default_excluded_descriptor_keys,\n): void {\n\tif (typeof source !== \"object\" && typeof source !== \"function\") {\n\t\treturn;\n\t}\n\n\tif (source === null) {\n\t\treturn;\n\t}\n\n\tfor (const key of Reflect.ownKeys(source)) {\n\t\tif (default_excluded_descriptor_keys.has(key) || exclude.has(key)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(source, key);\n\n\t\tif (!descriptor) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tObject.defineProperty(target, key, descriptor);\n\t}\n}\n","import { Schema } from \"effect\";\n\n/**\n * Minimal Standard Schema shape accepted by SvelteKit remote helpers.\n *\n * @example\n * ```ts\n * const schema: StandardSchema = {\n * \"~standard\": {\n * validate: (input) => ({ value: input }),\n * },\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport type StandardSchema = {\n\treadonly \"~standard\": {\n\t\treadonly types?: {\n\t\t\treadonly input: unknown;\n\t\t\treadonly output: unknown;\n\t\t};\n\t\treadonly validate: (input: unknown) => unknown;\n\t};\n};\n\n/**\n * Checks whether a value implements the Standard Schema contract.\n *\n * @example\n * ```ts\n * if (is_standard_schema(value)) {\n * value[\"~standard\"].validate(input);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - Value to inspect.\n * @returns Whether the value is a Standard Schema.\n */\nexport function is_standard_schema(value: unknown): value is StandardSchema {\n\treturn typeof value === \"object\" && value !== null && \"~standard\" in value;\n}\n\n/**\n * Checks whether a value looks like an Effect Schema.\n *\n * @example\n * ```ts\n * if (is_effect_schema(value)) {\n * Schema.toStandardSchemaV1(value);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - Value to inspect.\n * @returns Whether the value should be converted to Standard Schema.\n */\nexport function is_effect_schema(value: unknown): value is Schema.Schema<unknown> {\n\treturn typeof value === \"object\" && value !== null && \"ast\" in value && \"make\" in value;\n}\n\n/**\n * Converts Effect Schema inputs to Standard Schema for SvelteKit.\n *\n * @example\n * ```ts\n * const validator = normalize_validator(Schema.Struct({ title: Schema.String }));\n * ```\n *\n * @since 2.0.0\n * @param value - Schema or handler input.\n * @returns Original value or Standard Schema view of an Effect Schema.\n */\nexport function normalize_validator(value: unknown): unknown {\n\tif (is_standard_schema(value) || !is_effect_schema(value)) {\n\t\treturn value;\n\t}\n\n\treturn Schema.toStandardSchemaV1(value as never);\n}\n"],"mappings":";;AAAA,MAAM,mDAAmC,IAAI,IAAiB;CAAC;CAAU;CAAQ;AAAW,CAAC;;;;;;;;;;;;;;;;;AAkB7F,SAAgB,0BACf,QACA,QACA,UAAoC,kCAC7B;CACP,IAAI,OAAO,WAAW,YAAY,OAAO,WAAW,YACnD;CAGD,IAAI,WAAW,MACd;CAGD,KAAK,MAAM,OAAO,QAAQ,QAAQ,MAAM,GAAG;EAC1C,IAAI,iCAAiC,IAAI,GAAG,KAAK,QAAQ,IAAI,GAAG,GAC/D;EAGD,MAAM,aAAa,OAAO,yBAAyB,QAAQ,GAAG;EAE9D,IAAI,CAAC,YACJ;EAGD,OAAO,eAAe,QAAQ,KAAK,UAAU;CAC9C;AACD;;;;;;;;;;;;;;;;;ACJA,SAAgB,mBAAmB,OAAyC;CAC3E,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,eAAe;AACtE;;;;;;;;;;;;;;;AAgBA,SAAgB,iBAAiB,OAAiD;CACjF,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS,SAAS,UAAU;AACnF;;;;;;;;;;;;;AAcA,SAAgB,oBAAoB,OAAyB;CAC5D,IAAI,mBAAmB,KAAK,KAAK,CAAC,iBAAiB,KAAK,GACvD,OAAO;CAGR,OAAO,OAAO,mBAAmB,KAAc;AAChD"}
@@ -0,0 +1,213 @@
1
+ import { g as RemoteHelperError, h as RemoteHelperContextError } from "./errors-IJjsUwrE.js";
2
+ import { create_serialized_remote_failure_envelope } from "../remote/shared.js";
3
+ import { Cause, Effect, Exit } from "effect";
4
+ import { isHttpError, isRedirect, isValidationError } from "@sveltejs/kit";
5
+ import { stringify } from "devalue";
6
+ //#region src/remote/cause-codec.ts
7
+ /**
8
+ * Classifies a failed Effect Cause into the server action SER should take.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const resolution = classify_remote_cause(Cause.fail({ _tag: "DbError" }));
13
+ * ```
14
+ *
15
+ * @since 4.0.0
16
+ * @param cause - Failed Effect Cause produced by a remote handler.
17
+ * @returns A remote boundary decision preserving control flow, form errors,
18
+ * interrupts, or encoded typed failures.
19
+ * @internal
20
+ */
21
+ function classify_remote_cause(cause) {
22
+ const control_flow = find_sveltekit_control_flow(cause);
23
+ if (control_flow !== void 0) return {
24
+ _tag: "SvelteKitControlFlow",
25
+ value: control_flow
26
+ };
27
+ if (Cause.hasInterruptsOnly(cause)) return {
28
+ _tag: "InterruptOnly",
29
+ cause
30
+ };
31
+ const form_error_issues = find_form_error_issues(cause);
32
+ if (form_error_issues !== void 0) return {
33
+ _tag: "FormInvalid",
34
+ issues: form_error_issues
35
+ };
36
+ return {
37
+ _tag: "RemoteFailure",
38
+ encoded: encode_remote_failure(cause)
39
+ };
40
+ }
41
+ /**
42
+ * Encodes an Effect Cause into a string that the client-side adapter can
43
+ * decode back into a typed `RemoteFailure`.
44
+ *
45
+ * @since 2.0.0
46
+ * @param cause - The Effect Cause from a failed execution.
47
+ * @returns A devalue-encoded string representing the serialised failure.
48
+ * @internal
49
+ */
50
+ function encode_remote_failure(cause) {
51
+ for (const reason of cause.reasons) {
52
+ if (!Cause.isFailReason(reason)) continue;
53
+ const encoded = stringify_failure(to_public_remote_failure(reason.error));
54
+ if (encoded !== void 0) return encoded;
55
+ }
56
+ return stringify_unknown_remote_failure();
57
+ }
58
+ function find_sveltekit_control_flow(cause) {
59
+ for (const reason of cause.reasons) {
60
+ if (!Cause.isDieReason(reason)) continue;
61
+ if (is_sveltekit_control_flow(reason.defect)) return reason.defect;
62
+ }
63
+ }
64
+ function find_form_error_issues(cause) {
65
+ for (const reason of cause.reasons) {
66
+ if (!Cause.isFailReason(reason)) continue;
67
+ const issues = get_form_error_issues(reason.error);
68
+ if (issues !== void 0) return issues;
69
+ }
70
+ }
71
+ function get_form_error_issues(value) {
72
+ if (!is_object_like(value) || value._tag !== "FormError") return;
73
+ return value.issues ?? [];
74
+ }
75
+ function is_sveltekit_control_flow(value) {
76
+ return isRedirect(value) || isHttpError(value) || isValidationError(value);
77
+ }
78
+ function stringify_failure(value) {
79
+ try {
80
+ return stringify(value);
81
+ } catch {
82
+ return;
83
+ }
84
+ }
85
+ function to_public_remote_failure(value) {
86
+ if (!has_public_remote_failure_tag(value)) return create_unknown_remote_failure();
87
+ return to_serializable_public_failure(value) ?? create_unknown_remote_failure();
88
+ }
89
+ function to_serializable_public_failure(value, seen = /* @__PURE__ */ new WeakSet()) {
90
+ if (typeof value === "function" || typeof value === "symbol") return;
91
+ if (!is_object_like(value)) return value;
92
+ if (stringify_failure(value) !== void 0) return value;
93
+ if (is_internal_object(value)) return;
94
+ if (seen.has(value)) return;
95
+ seen.add(value);
96
+ const serializable = Array.isArray(value) ? value.map((item) => to_serializable_public_failure(item, seen)) : to_plain_record(value, seen);
97
+ seen.delete(value);
98
+ return serializable;
99
+ }
100
+ function to_plain_record(value, seen) {
101
+ const descriptors = Object.getOwnPropertyDescriptors(value);
102
+ const record = {};
103
+ for (const [key, descriptor] of Object.entries(descriptors)) {
104
+ if (key === "stack" || !("value" in descriptor)) continue;
105
+ record[key] = to_serializable_public_failure(descriptor.value, seen);
106
+ }
107
+ if (value instanceof Error && !("message" in record)) record.message = value.message;
108
+ return record;
109
+ }
110
+ function is_object_like(value) {
111
+ return typeof value === "object" && value !== null;
112
+ }
113
+ function has_public_remote_failure_tag(value) {
114
+ return is_object_like(value) && typeof value._tag === "string";
115
+ }
116
+ function is_internal_object(value) {
117
+ return !Array.isArray(value) && !is_plain_record(value) && !has_public_remote_failure_tag(value);
118
+ }
119
+ function is_plain_record(value) {
120
+ const prototype = Object.getPrototypeOf(value);
121
+ return prototype === Object.prototype || prototype === null;
122
+ }
123
+ function create_unknown_remote_failure() {
124
+ return { message: "[UNKNOWN_REMOTE_FAILURE]: Unknown error" };
125
+ }
126
+ function stringify_unknown_remote_failure() {
127
+ return stringify(create_unknown_remote_failure());
128
+ }
129
+ //#endregion
130
+ //#region src/remote/server.ts
131
+ const request_event_context_error_start = "Can only read the current request event inside functions invoked during `handle`";
132
+ const request_store_context_error = "Could not get the request store.";
133
+ /**
134
+ * Runs a user-supplied Effect program through a ManagedRuntime, maps its
135
+ * exit into the shape expected by SvelteKit, and returns the result or
136
+ * throws a SvelteKit-compatible error.
137
+ *
138
+ * @since 2.0.0
139
+ * @param effect - The Effect program to execute.
140
+ * @param runtime - The server-side ManagedRuntime.
141
+ * @param invalid - SvelteKit's `invalid` helper (bound per-request).
142
+ * @param error - SvelteKit's `error` helper.
143
+ * @returns A Promise that resolves with the effect's success value.
144
+ * @internal
145
+ */
146
+ async function run_remote_effect(effect, runtime, invalid, error) {
147
+ const exit = await runtime.runPromise(Effect.exit(effect));
148
+ if (Exit.isSuccess(exit)) return exit.value;
149
+ handle_failure(exit.cause, invalid, error);
150
+ }
151
+ /**
152
+ * Applies a classified remote Cause decision to SvelteKit's server helpers.
153
+ */
154
+ function handle_failure(cause, invalid, error) {
155
+ const resolution = classify_remote_cause(cause);
156
+ switch (resolution._tag) {
157
+ case "SvelteKitControlFlow": throw resolution.value;
158
+ case "InterruptOnly": throw Cause.squash(resolution.cause);
159
+ case "FormInvalid": invalid(...resolution.issues);
160
+ case "RemoteFailure": error(500, create_serialized_remote_failure_envelope(resolution.encoded));
161
+ }
162
+ }
163
+ /**
164
+ * Throws a SvelteKit `invalid` response from a {@link FormError}, calling
165
+ * through to the request-scoped `invalid` helper.
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * throw_form_error(
170
+ * [{ message: "Name is required", path: ["name"] }],
171
+ * invalid,
172
+ * );
173
+ * ```
174
+ *
175
+ * @since 2.0.0
176
+ * @param issues - The list of form validation issues.
177
+ * @param invalid - SvelteKit's `invalid` helper bound to the current request.
178
+ * @internal
179
+ */
180
+ function throw_form_error(issues, invalid) {
181
+ invalid(...issues);
182
+ }
183
+ /**
184
+ * Remaps SvelteKit's unbranded request-context errors into clear, actionable
185
+ * messages.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * try {
190
+ * return native_query(handler);
191
+ * } catch (err) {
192
+ * throw normalize_remote_helper_error(err, "Query");
193
+ * }
194
+ * ```
195
+ *
196
+ * @since 2.0.0
197
+ * @param err - The error thrown by SvelteKit's native functions.
198
+ * @param helper_name - Name of the helper that triggered the error.
199
+ * @returns A more descriptive error.
200
+ * @internal
201
+ */
202
+ function normalize_remote_helper_error(err, helper_name) {
203
+ if (is_sveltekit_remote_context_error(err)) return new RemoteHelperContextError(helper_name);
204
+ return err instanceof Error ? err : new RemoteHelperError(err);
205
+ }
206
+ function is_sveltekit_remote_context_error(err) {
207
+ if (!(err instanceof Error)) return false;
208
+ return err.message.startsWith(request_event_context_error_start) || err.message === request_store_context_error;
209
+ }
210
+ //#endregion
211
+ export { encode_remote_failure as i, run_remote_effect as n, throw_form_error as r, normalize_remote_helper_error as t };
212
+
213
+ //# sourceMappingURL=server-D1LcDnZE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-D1LcDnZE.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/remote/cause-codec.ts","../../../modules/svelte-effect-runtime/src/remote/server.ts"],"sourcesContent":["import type { FormIssue } from \"$/remote/shared.ts\";\nimport { isHttpError, isRedirect, isValidationError } from \"@sveltejs/kit\";\nimport { Cause } from \"effect\";\nimport { stringify } from \"devalue\";\n\n/**\n * Classified result of inspecting an Effect Cause at the remote server boundary.\n *\n * @example\n * ```ts\n * const resolution = classify_remote_cause(cause);\n * if (resolution._tag === \"RemoteFailure\") {\n * console.log(resolution.encoded);\n * }\n * ```\n *\n * @since 4.0.0\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 };\n\n/**\n * Classifies a failed Effect Cause into the server action SER should take.\n *\n * @example\n * ```ts\n * const resolution = classify_remote_cause(Cause.fail({ _tag: \"DbError\" }));\n * ```\n *\n * @since 4.0.0\n * @param cause - Failed Effect Cause produced by a remote handler.\n * @returns A remote boundary decision preserving control flow, form errors,\n * interrupts, or encoded typed failures.\n * @internal\n */\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\treturn {\n\t\t_tag: \"RemoteFailure\",\n\t\tencoded: encode_remote_failure(cause),\n\t};\n}\n\n/**\n * Encodes an Effect Cause into a string that the client-side adapter can\n * decode back into a typed `RemoteFailure`.\n *\n * @since 2.0.0\n * @param cause - The Effect Cause from a failed execution.\n * @returns A devalue-encoded string representing the serialised failure.\n * @internal\n */\nexport function encode_remote_failure(cause: Cause.Cause<unknown>): string {\n\tfor (const reason of cause.reasons) {\n\t\tif (!Cause.isFailReason(reason)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst failure = to_public_remote_failure(reason.error);\n\t\tconst encoded = stringify_failure(failure);\n\n\t\tif (encoded !== undefined) {\n\t\t\treturn encoded;\n\t\t}\n\t}\n\n\treturn stringify_unknown_remote_failure();\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_object_like(value) || (value as { readonly _tag?: unknown })._tag !== \"FormError\") {\n\t\treturn undefined;\n\t}\n\n\treturn (value as { readonly issues?: readonly FormIssue[] }).issues ?? [];\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_public_remote_failure(value: unknown): unknown {\n\tif (!has_public_remote_failure_tag(value)) {\n\t\treturn create_unknown_remote_failure();\n\t}\n\n\tconst serializable_failure = to_serializable_public_failure(value);\n\n\treturn serializable_failure ?? create_unknown_remote_failure();\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","import { create_serialized_remote_failure_envelope } from \"$/remote/shared.ts\";\nimport type { FormIssue } from \"$/remote/shared.ts\";\nimport { RemoteHelperContextError, RemoteHelperError } from \"$/errors.ts\";\nimport { classify_remote_cause } from \"$/remote/cause-codec.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/**\n * Runs a user-supplied Effect program through a ManagedRuntime, maps its\n * exit into the shape expected by SvelteKit, and returns the result or\n * throws a SvelteKit-compatible error.\n *\n * @since 2.0.0\n * @param effect - The Effect program to execute.\n * @param runtime - The server-side ManagedRuntime.\n * @param invalid - SvelteKit's `invalid` helper (bound per-request).\n * @param error - SvelteKit's `error` helper.\n * @returns A Promise that resolves with the effect's success value.\n * @internal\n */\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): 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\thandle_failure(exit.cause, invalid, error);\n}\n\n/**\n * Applies a classified remote Cause decision to SvelteKit's server helpers.\n */\nfunction handle_failure(\n\tcause: Cause.Cause<unknown>,\n\tinvalid: SvelteInvalid,\n\terror: SvelteError,\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\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\terror(500, envelope);\n\t\t}\n\t}\n}\n\n/**\n * Throws a SvelteKit `invalid` response from a {@link FormError}, calling\n * through to the request-scoped `invalid` helper.\n *\n * @example\n * ```ts\n * throw_form_error(\n * [{ message: \"Name is required\", path: [\"name\"] }],\n * invalid,\n * );\n * ```\n *\n * @since 2.0.0\n * @param issues - The list of form validation issues.\n * @param invalid - SvelteKit's `invalid` helper bound to the current request.\n * @internal\n */\nexport function throw_form_error(issues: readonly FormIssue[], invalid: SvelteInvalid): never {\n\tinvalid(...issues);\n}\n\n/**\n * Remaps SvelteKit's unbranded request-context errors into clear, actionable\n * messages.\n *\n * @example\n * ```ts\n * try {\n * return native_query(handler);\n * } catch (err) {\n * throw normalize_remote_helper_error(err, \"Query\");\n * }\n * ```\n *\n * @since 2.0.0\n * @param err - The error thrown by SvelteKit's native functions.\n * @param helper_name - Name of the helper that triggered the error.\n * @returns A more descriptive error.\n * @internal\n */\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);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