svelte-effect-runtime 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dist/chunks/client-BrZka6DW.js +530 -0
- package/.dist/chunks/client-BrZka6DW.js.map +1 -0
- package/.dist/chunks/compiler-COVzgLYo.js +412 -0
- package/.dist/chunks/compiler-COVzgLYo.js.map +1 -0
- package/.dist/chunks/descriptors-B4otDlm1.js +216 -0
- package/.dist/chunks/descriptors-B4otDlm1.js.map +1 -0
- package/.dist/chunks/diagnostics-BDrky-Di.js +359 -0
- package/.dist/chunks/diagnostics-BDrky-Di.js.map +1 -0
- package/.dist/chunks/dispatcher-BA0PLQhA.js +16 -0
- package/.dist/chunks/dispatcher-BA0PLQhA.js.map +1 -0
- package/.dist/chunks/{dispatcher-DOx8iC6r.js → dispatcher-_x0MQZBS.js} +84 -258
- package/.dist/chunks/dispatcher-_x0MQZBS.js.map +1 -0
- package/.dist/chunks/{errors-IJjsUwrE.js → errors-CLsbGjIa.js} +39 -44
- package/.dist/chunks/errors-CLsbGjIa.js.map +1 -0
- package/.dist/chunks/live-BundLSoY.js +146 -0
- package/.dist/chunks/live-BundLSoY.js.map +1 -0
- package/.dist/chunks/live-CHK0RrZu.js +10 -0
- package/.dist/chunks/live-CHK0RrZu.js.map +1 -0
- package/.dist/chunks/{remote-client-CVI4t66c.js → remote-client-mkQAfP1G.js} +29 -23
- package/.dist/chunks/remote-client-mkQAfP1G.js.map +1 -0
- package/.dist/chunks/{runtime-GBQz32DZ.js → runtime-HDTlEnzp.js} +3 -27
- package/.dist/chunks/runtime-HDTlEnzp.js.map +1 -0
- package/.dist/chunks/{server-D1LcDnZE.js → server-BNrA1I-u.js} +15 -84
- package/.dist/chunks/server-BNrA1I-u.js.map +1 -0
- package/.dist/chunks/source-scan-9pZxnfct.js +1059 -0
- package/.dist/chunks/source-scan-9pZxnfct.js.map +1 -0
- package/.dist/chunks/{transform-jNUr65K9.js → transform-BXyYUAez.js} +184 -358
- package/.dist/chunks/transform-BXyYUAez.js.map +1 -0
- package/.dist/compiler/markup-identifiers.d.ts +2 -0
- package/.dist/compiler/remote-client.d.ts +1 -19
- package/.dist/compiler/source-scan.d.ts +11 -108
- package/.dist/compiler/sveltekit-remote-bridge.d.ts +3 -0
- package/.dist/compiler.d.ts +6 -0
- package/.dist/compiler.js +1 -1
- package/.dist/detect.d.ts +0 -31
- package/.dist/detect.js +0 -39
- package/.dist/detect.js.map +1 -1
- package/.dist/diagnostics.d.ts +0 -16
- package/.dist/dispatcher/deps.d.ts +3 -14
- package/.dist/dispatcher/fibers.d.ts +5 -46
- package/.dist/dispatcher/index.d.ts +1 -143
- package/.dist/dispatcher/types.d.ts +0 -151
- package/.dist/dispatcher.js +1 -1
- package/.dist/errors.d.ts +30 -42
- package/.dist/generated/dispatcher.d.ts +0 -50
- package/.dist/generators.d.ts +1 -12
- package/.dist/internal/descriptors.d.ts +0 -16
- package/.dist/internal/generators.js +13 -8
- package/.dist/internal/generators.js.map +1 -1
- package/.dist/internal/live.d.ts +9 -0
- package/.dist/internal/remote-client.js +2 -2
- package/.dist/internal/remote-server.js +2 -2
- package/.dist/internal/schema.d.ts +0 -54
- package/.dist/live.d.ts +9 -26
- package/.dist/markup/event-attributes.d.ts +0 -32
- package/.dist/markup/promise.d.ts +1 -23
- package/.dist/markup/promise.js +2 -18
- package/.dist/markup/promise.js.map +1 -1
- package/.dist/markup/run.d.ts +1 -10
- package/.dist/markup/run.js +2 -11
- package/.dist/markup/run.js.map +1 -1
- package/.dist/markup/transform/apply.d.ts +4 -4
- package/.dist/markup/transform/classify.d.ts +2 -11
- package/.dist/markup/transform/constants.d.ts +1 -1
- package/.dist/markup/transform/effect-bindings.d.ts +2 -26
- package/.dist/markup/transform/effect-callbacks.d.ts +0 -20
- package/.dist/markup/transform/emit.d.ts +2 -11
- package/.dist/markup/transform/expressions.d.ts +0 -35
- package/.dist/markup/transform/scan.d.ts +3 -22
- package/.dist/markup/transform/types.d.ts +1 -129
- package/.dist/markup/transform.js +1 -1
- package/.dist/markup/value.d.ts +1 -18
- package/.dist/markup/value.js +2 -19
- package/.dist/markup/value.js.map +1 -1
- package/.dist/mod.d.ts +3 -8
- package/.dist/mod.js +5 -5
- package/.dist/mod.js.map +1 -1
- package/.dist/remote/cause-codec.d.ts +3 -37
- package/.dist/remote/client/command.d.ts +3 -17
- package/.dist/remote/client/form-data.d.ts +0 -7
- package/.dist/remote/client/form-enhance.d.ts +0 -7
- package/.dist/remote/client/form-transport.d.ts +14 -20
- package/.dist/remote/client/form.d.ts +4 -24
- package/.dist/remote/client/index.d.ts +2 -1
- package/.dist/remote/client/prerender.d.ts +6 -0
- package/.dist/remote/client/query-result.d.ts +2 -14
- package/.dist/remote/client/query.d.ts +8 -48
- package/.dist/remote/client/responses.d.ts +3 -27
- package/.dist/remote/client/types.d.ts +16 -110
- package/.dist/remote/client/utils.d.ts +0 -8
- package/.dist/remote/client.d.ts +2 -2
- package/.dist/remote/client.js +2 -2
- package/.dist/remote/effect.d.ts +6 -0
- package/.dist/remote/failures.d.ts +4 -0
- package/.dist/remote/query-update.d.ts +2 -0
- package/.dist/remote/resource.d.ts +25 -0
- package/.dist/remote/server.d.ts +5 -50
- package/.dist/remote/server.js +2 -2
- package/.dist/remote/shared.d.ts +6 -145
- package/.dist/remote/shared.js +6 -127
- package/.dist/remote/shared.js.map +1 -1
- package/.dist/runtime/transform.js +5 -22
- package/.dist/runtime/transform.js.map +1 -1
- package/.dist/script-transform/ast.d.ts +0 -46
- package/.dist/script-transform/imports.d.ts +0 -38
- package/.dist/script-transform/lower.d.ts +0 -9
- package/.dist/script-transform/runes.d.ts +0 -10
- package/.dist/script-transform/runtime-block.d.ts +0 -17
- package/.dist/script-transform/source.d.ts +0 -24
- package/.dist/script-transform/types.d.ts +1 -126
- package/.dist/server/effects.d.ts +4 -53
- package/.dist/server/factories.d.ts +7 -7
- package/.dist/server/index.d.ts +1 -1
- package/.dist/server/invalid.d.ts +0 -7
- package/.dist/server/live-snapshot.d.ts +5 -0
- package/.dist/server/remote-handler-context.d.ts +5 -0
- package/.dist/server/runtime.d.ts +6 -24
- package/.dist/server/schema.d.ts +0 -14
- package/.dist/server/transport.d.ts +2 -0
- package/.dist/server/types.d.ts +49 -26
- package/.dist/server/wrappers.d.ts +3 -40
- package/.dist/server.d.ts +1 -1
- package/.dist/server.js +200 -215
- package/.dist/server.js.map +1 -1
- package/.dist/yieldable.d.ts +1 -35
- package/package.json +2 -2
- package/.dist/chunks/client-DcZUV4rR.js +0 -653
- package/.dist/chunks/client-DcZUV4rR.js.map +0 -1
- package/.dist/chunks/compiler-BBPNyXmQ.js +0 -460
- package/.dist/chunks/compiler-BBPNyXmQ.js.map +0 -1
- package/.dist/chunks/dispatcher-DOx8iC6r.js.map +0 -1
- package/.dist/chunks/dispatcher-H-Ia0Os4.js +0 -47
- package/.dist/chunks/dispatcher-H-Ia0Os4.js.map +0 -1
- package/.dist/chunks/errors-IJjsUwrE.js.map +0 -1
- package/.dist/chunks/live-BXAKre_4.js +0 -104
- package/.dist/chunks/live-BXAKre_4.js.map +0 -1
- package/.dist/chunks/remote-client-CVI4t66c.js.map +0 -1
- package/.dist/chunks/runtime-GBQz32DZ.js.map +0 -1
- package/.dist/chunks/schema-D9pct6Y5.js +0 -89
- package/.dist/chunks/schema-D9pct6Y5.js.map +0 -1
- package/.dist/chunks/server-D1LcDnZE.js.map +0 -1
- package/.dist/chunks/source-scan-C4PsggID.js +0 -341
- package/.dist/chunks/source-scan-C4PsggID.js.map +0 -1
- package/.dist/chunks/transform-jNUr65K9.js.map +0 -1
- package/.dist/remote/client/effect.d.ts +0 -29
- package/.dist/remote/client/failures.d.ts +0 -42
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compiler-BBPNyXmQ.js","names":["candidate"],"sources":["../../../modules/svelte-effect-runtime/src/diagnostics.ts","../../../modules/svelte-effect-runtime/src/compiler.ts"],"sourcesContent":["import type { MarkupBraceExpression, ScriptRegion } from \"$/compiler/source-scan.ts\";\nimport { scan_svelte_effect_source } from \"$/compiler/source-scan.ts\";\n\n/**\n * Warning diagnostic produced by the SER Vite diagnostics plugin.\n */\ninterface Diagnostic {\n\tmessage: string;\n\tline: number;\n\tcolumn: number;\n}\n\ninterface SourceLocation {\n\tline: number;\n\tcolumn: number;\n}\n\n/**\n * Finds best-effort SER usage diagnostics in Svelte component markup.\n *\n * @example\n * ```ts\n * const diagnostics = find_svelte_effect_diagnostics(\n * `<button onclick={Effect.gen}>save</button>`,\n * \"Button.svelte\",\n * );\n * ```\n *\n * @since 2.0.0\n * @param code - Svelte component source to scan for suspicious Effect usage.\n * @param filename - Filename used in diagnostic messages.\n * @returns Warning diagnostics with a message and source location.\n */\nexport function find_svelte_effect_diagnostics(\n\tcode: string,\n\tfilename: string,\n): Array<{ message: string; line: number; column: number }> {\n\tconst scan = scan_svelte_effect_source(code, filename);\n\tconst effect_names = find_effect_local_names(scan.scripts);\n\tconst line_starts = make_line_starts(code);\n\n\treturn scan.markup_expressions.flatMap((expression) =>\n\t\tmake_expression_diagnostics(filename, effect_names, expression, line_starts),\n\t);\n}\n\nfunction find_effect_local_names(scripts: readonly ScriptRegion[]): Set<string> {\n\tconst names = new Set<string>([\"Effect\"]);\n\n\tfor (const script of scripts) {\n\t\tconst import_pattern = /import\\s+(type\\s+)?\\{([^}]+)\\}\\s+from\\s+[\"']effect[\"']/g;\n\n\t\tfor (const import_match of script.text.matchAll(import_pattern)) {\n\t\t\tconst is_type_only_import = import_match[1] !== undefined;\n\t\t\tconst specifiers = import_match[2].split(\",\");\n\n\t\t\tif (is_type_only_import) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const specifier of specifiers) {\n\t\t\t\tconst local_name = parse_effect_import_local_name(specifier);\n\n\t\t\t\tif (local_name) {\n\t\t\t\t\tnames.add(local_name);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn names;\n}\n\nfunction parse_effect_import_local_name(specifier: string): string | undefined {\n\tconst trimmed = specifier.trim();\n\tconst match = trimmed.match(/^Effect(?:\\s+as\\s+([A-Za-z_$][\\w$]*))?$/);\n\n\tif (!match) {\n\t\treturn undefined;\n\t}\n\n\treturn match[1] ?? \"Effect\";\n}\n\nfunction make_expression_diagnostics(\n\tfilename: string,\n\teffect_names: Set<string>,\n\texpression: MarkupBraceExpression,\n\tline_starts: number[],\n): Diagnostic[] {\n\tconst attribute_name = expression.attribute_name;\n\tconst expression_text = expression.expression_text;\n\t/** The source scanner exposes a name only for a direct single-expression value. */\n\tconst is_event_attribute = attribute_name !== undefined && attribute_name.startsWith(\"on\");\n\tconst is_attribute = attribute_name !== undefined;\n\n\tif (!contains_effect_reference(expression_text, effect_names)) {\n\t\treturn [];\n\t}\n\n\tif (starts_with_yield_star(expression_text)) {\n\t\treturn [];\n\t}\n\n\tconst loc = get_line_column(line_starts, expression.open);\n\n\tif (\n\t\tis_event_attribute &&\n\t\tis_callback_expression(expression_text) &&\n\t\tcontains_yield_star(expression_text)\n\t) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_hidden_event_yield_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (contains_effect_runner(expression_text, effect_names)) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_explicit_runner_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (is_bare_effect_gen(expression_text, effect_names)) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_bare_effect_gen_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (is_event_attribute && is_callback_expression(expression_text)) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_event_callback_returns_effect_warning(\n\t\t\t\t\tfilename,\n\t\t\t\t\tattribute_name,\n\t\t\t\t\texpression_text,\n\t\t\t\t),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (is_event_attribute) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_event_attribute_effect_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (is_attribute) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_attribute_effect_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\treturn [make_diagnostic(loc, make_sync_markup_effect_warning(filename, expression_text))];\n}\n\nfunction make_diagnostic(loc: { line: number; column: number }, message: string): Diagnostic {\n\treturn {\n\t\tmessage,\n\t\tline: loc.line,\n\t\tcolumn: loc.column,\n\t};\n}\n\nfunction make_hidden_event_yield_warning(\n\tfilename: string,\n\tattribute_name: string,\n\texpression_text: string,\n): string {\n\treturn [\n\t\t`[svelte-effect-runtime] Detected yield* hidden inside an event callback.`,\n\t\t`${filename}: ${attribute_name}={${expression_text}}`,\n\t\t`SER can only lower yield* at the event attribute boundary.`,\n\t\t`Write the event expression directly, for example: ${attribute_name}={yield* save()}`,\n\t].join(\"\\n\");\n}\n\nfunction make_explicit_runner_warning(\n\tfilename: string,\n\tattribute_name: string | undefined,\n\texpression_text: string,\n): string {\n\tconst location = attribute_name\n\t\t? `${attribute_name}={${expression_text}}`\n\t\t: `{${expression_text}}`;\n\n\treturn [\n\t\t`[svelte-effect-runtime] Detected an explicit Effect runner inside Svelte markup.`,\n\t\t`${filename}: ${location}`,\n\t\t`Explicit runners bypass SER cancellation and error handling for markup effects.`,\n\t\t`Prefer yield* so SER can manage the Effect lifecycle.`,\n\t].join(\"\\n\");\n}\n\nfunction make_bare_effect_gen_warning(\n\tfilename: string,\n\tattribute_name: string | undefined,\n\texpression_text: string,\n): string {\n\tconst location = attribute_name\n\t\t? `${attribute_name}={${expression_text}}`\n\t\t: `{${expression_text}}`;\n\tconst fixed = attribute_name\n\t\t? `${attribute_name}={yield* ${expression_text}(function* () { ... })}`\n\t\t: `{yield* ${expression_text}(function* () { ... })}`;\n\n\treturn [\n\t\t`[svelte-effect-runtime] Detected Effect.gen used as a value instead of an Effect program.`,\n\t\t`${filename}: ${location}`,\n\t\t`${expression_text} is a constructor, not the result of running a generator.`,\n\t\t`Use: ${fixed}`,\n\t].join(\"\\n\");\n}\n\nfunction make_event_callback_returns_effect_warning(\n\tfilename: string,\n\tattribute_name: string,\n\texpression_text: string,\n): string {\n\treturn [\n\t\t`[svelte-effect-runtime] Detected an event callback that returns an Effect but does not run it.`,\n\t\t`${filename}: ${attribute_name}={${expression_text}}`,\n\t\t`Svelte will call the callback and receive an Effect value, but SER will not manage it from inside the callback.`,\n\t\t`Use yield* at the event attribute boundary or explicitly run the Effect if you really want to bypass SER.`,\n\t].join(\"\\n\");\n}\n\nfunction make_event_attribute_effect_warning(\n\tfilename: string,\n\tattribute_name: string,\n\texpression_text: string,\n): string {\n\tconst fixed = `${attribute_name}={yield* ${expression_text}}`;\n\n\treturn [\n\t\t`[svelte-effect-runtime] Detected an event attribute that looks like an Effect but is not written with yield*.`,\n\t\t`${filename}: ${attribute_name}={${expression_text}}`,\n\t\t`If you are trying to use Effect in this event handler, use yield* at the beginning.`,\n\t\t`Use: ${fixed}`,\n\t].join(\"\\n\");\n}\n\nfunction make_attribute_effect_warning(\n\tfilename: string,\n\tattribute_name: string,\n\texpression_text: string,\n): string {\n\tconst fixed = `${attribute_name}={yield* ${expression_text}}`;\n\n\treturn [\n\t\t`[svelte-effect-runtime] Detected an attribute value that looks like an Effect but is not written with yield*.`,\n\t\t`${filename}: ${attribute_name}={${expression_text}}`,\n\t\t`Svelte attributes need the resolved Effect value, not the Effect object itself.`,\n\t\t`Use: ${fixed}`,\n\t].join(\"\\n\");\n}\n\nfunction make_sync_markup_effect_warning(filename: string, expression_text: string): string {\n\treturn [\n\t\t`[svelte-effect-runtime] Detected a markup expression that creates an Effect but is not written with yield*.`,\n\t\t`${filename}: {${expression_text}}`,\n\t\t`This expression will produce an Effect value, not its result.`,\n\t\t`Use yield* where Svelte expects the resolved value.`,\n\t].join(\"\\n\");\n}\n\nfunction contains_effect_reference(expression_text: string, effect_names: Set<string>): boolean {\n\tconst name_pattern = make_effect_name_pattern(effect_names);\n\tconst effect_pattern = new RegExp(\n\t\t`\\\\b(?:${name_pattern})\\\\.(?:gen|succeed|fail|try|tryPromise|promise|sync|all|void|log|runPromise|runSync|runFork)\\\\b`,\n\t);\n\n\treturn effect_pattern.test(expression_text);\n}\n\nfunction contains_effect_runner(expression_text: string, effect_names: Set<string>): boolean {\n\tconst name_pattern = make_effect_name_pattern(effect_names);\n\tconst runner_pattern = new RegExp(`\\\\b(?:${name_pattern})\\\\.run(?:Promise|Sync|Fork)\\\\b`);\n\n\treturn runner_pattern.test(expression_text);\n}\n\nfunction is_bare_effect_gen(expression_text: string, effect_names: Set<string>): boolean {\n\tconst name_pattern = make_effect_name_pattern(effect_names);\n\tconst bare_gen_pattern = new RegExp(`^(?:${name_pattern})\\\\.gen$`);\n\n\treturn bare_gen_pattern.test(expression_text);\n}\n\nfunction make_effect_name_pattern(effect_names: Set<string>): string {\n\treturn [...effect_names]\n\t\t.map(escape_regexp)\n\t\t.sort((a, b) => b.length - a.length)\n\t\t.join(\"|\");\n}\n\nfunction starts_with_yield_star(expression_text: string): boolean {\n\treturn /^yield\\s*\\*/.test(expression_text);\n}\n\nfunction contains_yield_star(expression_text: string): boolean {\n\treturn /\\byield\\s*\\*/.test(expression_text);\n}\n\nfunction is_callback_expression(expression_text: string): boolean {\n\treturn (\n\t\t/^(?:async\\s+)?(?:\\([^)]*\\)|[A-Za-z_$][\\w$]*)\\s*=>/.test(expression_text) ||\n\t\t/^(?:async\\s+)?function\\b/.test(expression_text)\n\t);\n}\n\nfunction get_line_column(line_starts: number[], position: number): SourceLocation {\n\tlet low = 0;\n\tlet high = line_starts.length - 1;\n\n\twhile (low <= high) {\n\t\tconst mid = Math.floor((low + high) / 2);\n\n\t\tif (line_starts[mid] <= position) {\n\t\t\tlow = mid + 1;\n\t\t} else {\n\t\t\thigh = mid - 1;\n\t\t}\n\t}\n\n\tconst line_index = Math.max(0, high);\n\tconst line = line_index + 1;\n\tconst column = position - line_starts[line_index];\n\n\treturn { line, column };\n}\n\nfunction make_line_starts(code: string): number[] {\n\tconst line_starts = [0];\n\n\tfor (let i = 0; i < code.length; i += 1) {\n\t\tif (code[i] !== \"\\n\") {\n\t\t\tcontinue;\n\t\t}\n\n\t\tline_starts.push(i + 1);\n\t}\n\n\treturn line_starts;\n}\n\nfunction escape_regexp(value: string): string {\n\treturn value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}","import { find_svelte_effect_diagnostics } from \"./diagnostics.ts\";\nimport type { Plugin } from \"vite\";\n\n/**\n * Options for the {@link effect} Vite plugin.\n *\n * @since 2.0.0\n */\nexport interface EffectOptions {\n\t/** Whether to emit debug logging in the generated remote client module. */\n\tdebug?: boolean;\n}\n\ninterface SvelteComponentModuleFilter {\n\tset_extensions(extensions: readonly string[]): void;\n\tis_module(id: string): boolean;\n}\n\ninterface VitePluginSvelteApi {\n\toptions?: {\n\t\textensions?: readonly unknown[];\n\t};\n}\n\ntype VitePluginSvelte = Plugin & {\n\tapi?: VitePluginSvelteApi;\n};\n\ntype VitePluginSvelteWithExtensions = Plugin & {\n\tapi: {\n\t\toptions: {\n\t\t\textensions: readonly string[];\n\t\t};\n\t};\n};\n\nconst default_svelte_component_extensions = [\".svelte\"] as const;\n\n/**\n * Vite plugin for SvelteKit. The server import plugin rewrites server-side\n * imports to the server entrypoint; the remote client plugin wraps SvelteKit's\n * generated client remote exports in Effect-returning adapters.\n *\n * @example\n * ```ts\n * import { effect } from \"svelte-effect-runtime/compiler\";\n * import { sveltekit } from \"@sveltejs/kit/vite\";\n *\n * export default defineConfig({ plugins: [effect(), sveltekit()] });\n * ```\n *\n * @since 2.0.0\n * @param options - Optional configuration.\n * @returns Vite plugins that integrate the runtime with SvelteKit.\n */\nexport function effect(options?: EffectOptions): Plugin[] {\n\tconst component_filter = make_svelte_component_module_filter();\n\n\treturn [\n\t\tmake_diagnostics_plugin(component_filter),\n\t\tmake_reserved_helper_guard_plugin(component_filter),\n\t\tmake_svelte_transform_plugin(component_filter),\n\t\tmake_server_rewrite_plugin(),\n\t\tmake_remote_client_wrapper_plugin(options),\n\t];\n}\n\nfunction make_diagnostics_plugin(component_filter: SvelteComponentModuleFilter): Plugin {\n\tconst warned_diagnostics = new Set<string>();\n\n\treturn {\n\t\tname: \"svelte-effect-runtime:diagnostics\",\n\n\t\ttransform(code: string, id: string) {\n\t\t\tif (!component_filter.is_module(id)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst clean_id = id.split(\"?\")[0] ?? id;\n\t\t\tconst diagnostics = find_svelte_effect_diagnostics(code, clean_id);\n\n\t\t\tfor (const diagnostic of diagnostics) {\n\t\t\t\tconst diagnostic_key = [\n\t\t\t\t\tclean_id,\n\t\t\t\t\tdiagnostic.line,\n\t\t\t\t\tdiagnostic.column,\n\t\t\t\t\tdiagnostic.message,\n\t\t\t\t].join(\":\");\n\n\t\t\t\tif (warned_diagnostics.has(diagnostic_key)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\twarned_diagnostics.add(diagnostic_key);\n\n\t\t\t\tthis.warn({\n\t\t\t\t\tid: clean_id,\n\t\t\t\t\tmessage: diagnostic.message,\n\t\t\t\t\tloc: {\n\t\t\t\t\t\tline: diagnostic.line,\n\t\t\t\t\t\tcolumn: diagnostic.column,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn undefined;\n\t\t},\n\t};\n}\n\nfunction make_reserved_helper_guard_plugin(component_filter: SvelteComponentModuleFilter): Plugin {\n\treturn {\n\t\tname: \"svelte-effect-runtime:reserved-helper-guard\",\n\n\t\ttransform(code: string, id: string) {\n\t\t\tif (!component_filter.is_module(id) || !has_ser_syntax(code)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst reserved_names = find_reserved_helper_names(code);\n\n\t\t\tif (reserved_names.length === 0) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tthis.warn(make_reserved_helper_warning(reserved_names));\n\n\t\t\treturn undefined;\n\t\t},\n\t};\n}\n\nfunction make_svelte_transform_plugin(component_filter: SvelteComponentModuleFilter): Plugin {\n\treturn {\n\t\tname: \"svelte-effect-runtime:svelte-transform\",\n\n\t\tconfigResolved(config) {\n\t\t\tconst extensions = find_svelte_component_extensions(config.plugins);\n\t\t\tconst conflicting_plugin_names = find_pre_transform_plugin_names(config.plugins);\n\n\t\t\tif (extensions) {\n\t\t\t\tcomponent_filter.set_extensions(extensions);\n\t\t\t}\n\n\t\t\tif (conflicting_plugin_names.length === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconfig.logger.info(make_pre_transform_plugin_notice(conflicting_plugin_names));\n\t\t},\n\n\t\tasync transform(code: string, id: string, options?: { ssr?: boolean }) {\n\t\t\tif (!component_filter.is_module(id)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst { transform_svelte_effect } = await import(\"./runtime/transform.ts\");\n\t\t\tconst result = transform_svelte_effect(code, id, {\n\t\t\t\ttarget: options?.ssr ? \"server\" : \"client\",\n\t\t\t});\n\n\t\t\tif (result.code === code) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\treturn { code: result.code, map: null };\n\t\t},\n\t};\n}\n\nfunction make_svelte_component_module_filter(): SvelteComponentModuleFilter {\n\tlet extensions: readonly string[] = default_svelte_component_extensions;\n\n\treturn {\n\t\tset_extensions(next_extensions) {\n\t\t\tconst normalized_extensions = normalize_svelte_component_extensions(next_extensions);\n\n\t\t\tif (normalized_extensions.length === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\textensions = normalized_extensions;\n\t\t},\n\n\t\tis_module(id) {\n\t\t\treturn is_svelte_component_module(id, extensions);\n\t\t},\n\t};\n}\n\nfunction normalize_svelte_component_extensions(extensions: readonly string[]): string[] {\n\tconst normalized_extensions = extensions\n\t\t.filter((extension) => extension.length > 0)\n\t\t.map((extension) => (extension.startsWith(\".\") ? extension : `.${extension}`));\n\n\treturn [...new Set(normalized_extensions)];\n}\n\nfunction find_svelte_component_extensions(\n\tplugins: readonly Plugin[],\n): readonly string[] | undefined {\n\tconst svelte_plugin = plugins.find(has_svelte_component_extensions);\n\n\treturn svelte_plugin?.api?.options?.extensions;\n}\n\nfunction has_svelte_component_extensions(plugin: Plugin): plugin is VitePluginSvelteWithExtensions {\n\tconst candidate = plugin as VitePluginSvelte;\n\tconst extensions = candidate.api?.options?.extensions;\n\n\tif (!plugin.name.startsWith(\"vite-plugin-svelte\")) {\n\t\treturn false;\n\t}\n\n\treturn (\n\t\tArray.isArray(extensions) && extensions.every((extension) => typeof extension === \"string\")\n\t);\n}\n\nfunction find_pre_transform_plugin_names(plugins: readonly Plugin[]): string[] {\n\treturn plugins\n\t\t.filter(\n\t\t\t(plugin) =>\n\t\t\t\t!plugin.name.startsWith(\"svelte-effect-runtime:\") &&\n\t\t\t\t!is_known_framework_pre_transform_plugin(plugin.name) &&\n\t\t\t\thas_pre_transform_priority(plugin),\n\t\t)\n\t\t.map((plugin) => plugin.name);\n}\n\nconst ansi_reset = \"\\x1b[0m\";\nconst ansi_light_green = \"\\x1b[92m\";\n\nfunction make_pre_transform_plugin_notice(plugin_names: readonly string[]): string {\n\tconst formatted_plugins = plugin_names.map((plugin_name) => ` - ${plugin_name}`).join(\"\\n\");\n\n\treturn [\n\t\t`${ansi_light_green}[svelte-effect-runtime]${ansi_reset} Svelte Effect Runtime noticed possible Vite plugin ordering conflicts.`,\n\t\t\"\",\n\t\t\"These plugins run before normal Svelte component transforms:\",\n\t\tformatted_plugins,\n\t\t\"\",\n\t\t\"This is usually fine, but if you see Svelte parser errors around <script effect>\",\n\t\t\"or yield* in components, one of those plugins may be reading component files before\",\n\t\t\"SER has lowered its syntax.\",\n\t].join(\"\\n\");\n}\n\nfunction is_known_framework_pre_transform_plugin(name: string): boolean {\n\treturn name.startsWith(\"vite:\") || name === \"vite-plugin-svelte:preprocess\";\n}\n\nfunction has_pre_transform_priority(plugin: Plugin): boolean {\n\tif (plugin.enforce === \"pre\" && plugin.transform) {\n\t\treturn true;\n\t}\n\n\tif (\n\t\ttypeof plugin.transform === \"object\" &&\n\t\tplugin.transform !== null &&\n\t\t\"order\" in plugin.transform &&\n\t\tplugin.transform.order === \"pre\"\n\t) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nfunction make_server_rewrite_plugin(): Plugin {\n\treturn {\n\t\tname: \"svelte-effect-runtime:server-imports\",\n\n\t\tconfig() {\n\t\t\treturn { optimizeDeps: { exclude: [\"svelte-effect-runtime\"] } };\n\t\t},\n\n\t\tasync transform(code: string, id: string) {\n\t\t\tif (!is_server_runtime_module(id)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tif (!code.includes(\"svelte-effect-runtime\")) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst rewritten = await rewrite_server_imports(code, id);\n\n\t\t\tif (rewritten === code) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\treturn { code: rewritten, map: null };\n\t\t},\n\t};\n}\n\nasync function rewrite_server_imports(code: string, id: string): Promise<string> {\n\tconst [{ default: MagicString }, ts] = await Promise.all([\n\t\timport(\"magic-string\"),\n\t\timport(\"typescript\"),\n\t]);\n\tconst filename = id.split(\"?\", 2)[0] ?? id;\n\tconst source_file = ts.createSourceFile(\n\t\tfilename,\n\t\tcode,\n\t\tts.ScriptTarget.Latest,\n\t\ttrue,\n\t\tget_script_kind(filename, ts),\n\t);\n\tconst magic = new MagicString(code);\n\tlet changed = false;\n\n\tconst rewrite_specifier = (specifier: import(\"typescript\").StringLiteralLike) => {\n\t\tconst replacement = get_server_import_replacement(specifier.text);\n\n\t\tif (!replacement) {\n\t\t\treturn;\n\t\t}\n\n\t\tmagic.overwrite(\n\t\t\tspecifier.getStart(source_file),\n\t\t\tspecifier.end,\n\t\t\tJSON.stringify(replacement),\n\t\t);\n\t\tchanged = true;\n\t};\n\n\tconst visit = (node: import(\"typescript\").Node) => {\n\t\tif (ts.isImportDeclaration(node) && ts.isStringLiteralLike(node.moduleSpecifier)) {\n\t\t\trewrite_specifier(node.moduleSpecifier);\n\t\t}\n\n\t\tif (\n\t\t\tts.isExportDeclaration(node) &&\n\t\t\tnode.moduleSpecifier &&\n\t\t\tts.isStringLiteralLike(node.moduleSpecifier)\n\t\t) {\n\t\t\trewrite_specifier(node.moduleSpecifier);\n\t\t}\n\n\t\tif (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {\n\t\t\tconst [specifier] = node.arguments;\n\n\t\t\tif (specifier && ts.isStringLiteralLike(specifier)) {\n\t\t\t\trewrite_specifier(specifier);\n\t\t\t}\n\t\t}\n\n\t\tts.forEachChild(node, visit);\n\t};\n\n\tvisit(source_file);\n\n\treturn changed ? magic.toString() : code;\n}\n\nfunction get_server_import_replacement(specifier: string): string | undefined {\n\tif (specifier === \"svelte-effect-runtime\") {\n\t\treturn \"svelte-effect-runtime/server\";\n\t}\n\n\tif (specifier === \"svelte-effect-runtime/internal/generators\") {\n\t\treturn \"svelte-effect-runtime/server\";\n\t}\n\n\treturn undefined;\n}\n\nfunction get_script_kind(filename: string, ts: typeof import(\"typescript\")) {\n\tconst normalized_filename = filename.toLowerCase();\n\n\tif (has_file_extension(normalized_filename, [\".tsx\"])) {\n\t\treturn ts.ScriptKind.TSX;\n\t}\n\n\tif (has_file_extension(normalized_filename, [\".jsx\"])) {\n\t\treturn ts.ScriptKind.JSX;\n\t}\n\n\tif (has_file_extension(normalized_filename, [\".js\", \".mjs\", \".cjs\"])) {\n\t\treturn ts.ScriptKind.JS;\n\t}\n\n\treturn ts.ScriptKind.TS;\n}\n\nfunction has_file_extension(filename: string, extensions: readonly string[]): boolean {\n\treturn extensions.some((extension) => filename.endsWith(extension));\n}\n\nfunction make_remote_client_wrapper_plugin(options?: EffectOptions): Plugin {\n\treturn {\n\t\tname: \"svelte-effect-runtime:remote-client\",\n\t\tenforce: \"post\",\n\n\t\tconfig() {\n\t\t\treturn { ssr: { noExternal: [\"svelte-effect-runtime\"] } };\n\t\t},\n\n\t\tconfigResolved(config) {\n\t\t\tconst no_external = config.ssr.noExternal;\n\t\t\tconst runtime_package = \"svelte-effect-runtime\";\n\n\t\t\tif (no_external === true) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (Array.isArray(no_external)) {\n\t\t\t\tconst has_runtime_package = no_external.some((entry) => entry === runtime_package);\n\n\t\t\t\tif (!has_runtime_package) {\n\t\t\t\t\tno_external.push(runtime_package);\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconfig.ssr.noExternal = [no_external, runtime_package].filter(\n\t\t\t\t(value): value is string | RegExp => value !== undefined,\n\t\t\t);\n\t\t},\n\n\t\tasync transform(code: string, id: string) {\n\t\t\tif (!is_remote_module(id) || !code.includes(\"__sveltekit/remote\")) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst rewritten = await rewrite_remote_client_exports(code, options);\n\n\t\t\tif (rewritten === code) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\treturn { code: rewritten, map: null };\n\t\t},\n\t};\n}\n\nfunction is_server_runtime_module(id: string): boolean {\n\tconst [filename] = id.split(\"?\", 2);\n\n\treturn (\n\t\t/\\.(server|remote)(?:\\.[cm])?\\.[jt]s$/.test(filename) ||\n\t\t/(?:^|[\\\\/])hooks\\.server(?:\\.[cm])?\\.[jt]s$/.test(filename)\n\t);\n}\n\nfunction is_remote_module(id: string): boolean {\n\treturn /\\.(remote|remote\\.[cm]?)\\.[jt]s(?:\\?.*)?$/.test(id) || id.includes(\".remote.\");\n}\n\nfunction is_svelte_component_module(id: string, extensions: readonly string[]): boolean {\n\tconst [filename, query = \"\"] = id.split(\"?\", 2);\n\n\tif (!extensions.some((extension) => filename.endsWith(extension))) {\n\t\treturn false;\n\t}\n\n\tif (query.length === 0) {\n\t\treturn true;\n\t}\n\n\tconst params = new URLSearchParams(query);\n\tconst allowed_params = [\"t\", \"v\"];\n\n\treturn [...params.keys()].every((key) => allowed_params.includes(key));\n}\n\nfunction has_ser_syntax(code: string): boolean {\n\treturn /\\byield\\s*\\*/.test(code) || /<script\\b[^>]*\\beffect(?:[\\s=>]|$)/.test(code);\n}\n\nfunction find_reserved_helper_names(code: string): string[] {\n\tconst script_segments = [...code.matchAll(/<script\\b[^>]*>([\\s\\S]*?)<\\/script\\s*>/gi)].map(\n\t\t(match) => match[1] ?? \"\",\n\t);\n\tconst markup_segments = [...code.matchAll(/\\{[^{}]*(?:Dispatcher|Code)[^{}]*\\}/g)].map(\n\t\t(match) => match[0],\n\t);\n\tconst search_segments = [...script_segments, ...markup_segments];\n\n\treturn [\"Dispatcher\", \"Code\"].filter((name) =>\n\t\tsearch_segments.some((segment) => new RegExp(`\\\\b${name}\\\\b`).test(segment)),\n\t);\n}\n\nfunction make_reserved_helper_warning(names: string[]): string {\n\tconst quoted_names = names.map((name) => `\\`${name}\\``);\n\tconst subject =\n\t\tquoted_names.length === 1\n\t\t\t? quoted_names[0]\n\t\t\t: `${quoted_names.slice(0, -1).join(\", \")} and ${\n\t\t\t\t\tquoted_names[quoted_names.length - 1]\n\t\t\t\t}`;\n\tconst verb = names.length === 1 ? \"is\" : \"are\";\n\n\treturn [\n\t\t`[svelte-effect-runtime] ${subject} ${verb} reserved for generated markup helpers.`,\n\t\t`Rename or alias local bindings that use ${subject} before using SER syntax in this component.`,\n\t].join(\" \");\n}\n\n/**\n * Rewrites SvelteKit's generated client remote module from:\n *\n * `export const get_post = __remote.query(\"hash/get_post\")`\n *\n * into an Effect-aware wrapper around the same native function.\n *\n * @example\n * ```ts\n * const rewritten = await rewrite_remote_client_exports(remote_module_code);\n * ```\n *\n * @since 2.0.0\n * @param code - The generated client remote module code.\n * @param options - Optional plugin options.\n * @returns A promise that resolves to the rewritten module code.\n * @internal\n */\nexport async function rewrite_remote_client_exports(\n\tcode: string,\n\toptions?: EffectOptions,\n): Promise<string> {\n\tconst remote_client = await import(\"./compiler/remote-client.ts\");\n\n\treturn remote_client.rewrite_remote_client_exports(code, options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiCA,SAAgB,+BACf,MACA,UAC2D;CAC3D,MAAM,OAAO,0BAA0B,MAAM,QAAQ;CACrD,MAAM,eAAe,wBAAwB,KAAK,OAAO;CACzD,MAAM,cAAc,iBAAiB,IAAI;CAEzC,OAAO,KAAK,mBAAmB,SAAS,eACvC,4BAA4B,UAAU,cAAc,YAAY,WAAW,CAC5E;AACD;AAEA,SAAS,wBAAwB,SAA+C;CAC/E,MAAM,wBAAQ,IAAI,IAAY,CAAC,QAAQ,CAAC;CAExC,KAAK,MAAM,UAAU,SAGpB,KAAK,MAAM,gBAAgB,OAAO,KAAK,SAAS,yDAAc,GAAG;EAChE,MAAM,sBAAsB,aAAa,OAAO,KAAA;EAChD,MAAM,aAAa,aAAa,EAAE,CAAC,MAAM,GAAG;EAE5C,IAAI,qBACH;EAGD,KAAK,MAAM,aAAa,YAAY;GACnC,MAAM,aAAa,+BAA+B,SAAS;GAE3D,IAAI,YACH,MAAM,IAAI,UAAU;EAEtB;CACD;CAGD,OAAO;AACR;AAEA,SAAS,+BAA+B,WAAuC;CAE9E,MAAM,QADU,UAAU,KACN,CAAC,CAAC,MAAM,yCAAyC;CAErE,IAAI,CAAC,OACJ;CAGD,OAAO,MAAM,MAAM;AACpB;AAEA,SAAS,4BACR,UACA,cACA,YACA,aACe;CACf,MAAM,iBAAiB,WAAW;CAClC,MAAM,kBAAkB,WAAW;;CAEnC,MAAM,qBAAqB,mBAAmB,KAAA,KAAa,eAAe,WAAW,IAAI;CACzF,MAAM,eAAe,mBAAmB,KAAA;CAExC,IAAI,CAAC,0BAA0B,iBAAiB,YAAY,GA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AAe,SAAS,GAAG,CAAC;AACtE;AAEA,SAAS,eAAe,MAAuB;CAC9C,OAAO,eAAe,KAAK,IAAI,KAAK,qCAAqC,KAAK,IAAI;AACnF;AAEA,SAAS,2BAA2B,MAAwB;CAC3D,MAAM,kBAAkB,CAAC,GAAG,KAAK,SAAS,0CAA0C,CAAC,CAAC,CAAC,KACrF,UAAU,MAAM,MAAM,EACxB;CACA,MAAM,kBAAkB,CAAC,GAAG,KAAK,SAAS,sCAAsC,CAAC,CAAC,CAAC,KACjF,UAAU,MAAM,EAClB;CACA,MAAM,kBAAkB,CAAC,GAAG,iBAAiB,GAAG,eAAe;CAE/D,OAAO,CAAC,cAAc,MAAM,CAAC,CAAC,QAAQ,SACrC,gBAAgB,MAAM,YAAY,IAAI,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,KAAK,OAAO,CAAC,CAC5E;AACD;AAEA,SAAS,6BAA6B,OAAyB;CAC9D,MAAM,eAAe,MAAM,KAAK,SAAS,KAAK,KAAK,GAAG;CACtD,MAAM,UACL,aAAa,WAAW,IACrB,aAAa,KACb,GAAG,aAAa,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,OACxC,aAAa,aAAa,SAAS;CAIvC,OAAO,CACN,2BAA2B,QAAQ,GAHvB,MAAM,WAAW,IAAI,OAAO,MAGG,0CAC3C,2CAA2C,QAAQ,4CACpD,CAAC,CAAC,KAAK,GAAG;AACX;;;;;;;;;;;;;;;;;;;AAoBA,eAAsB,8BACrB,MACA,SACkB;CAGlB,QAAO,MAFqB,OAAO,+BAAA,CAEd,8BAA8B,MAAM,OAAO;AACjE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher-DOx8iC6r.js","names":["#notify_value_cells","#runtime","#emit_markup_value","#emit_markup_promise","#emit_markup_run","#disposed","#next_fiber_id","#fibers","#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","#is_current_fiber","#set_value_cell","#complete_fiber","#publish_value_success","#publish_value_failure","#delete_value_cell"],"sources":["../../../modules/svelte-effect-runtime/src/dispatcher/fibers.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 { Cause, Effect, Exit, Fiber } from \"effect\";\nimport type { Fiber as FiberType } from \"effect/Fiber\";\nimport type { ManagedRuntime as ManagedRuntimeType } from \"effect/ManagedRuntime\";\n\n/**\n * Callbacks fired when a watched dispatcher fiber completes.\n *\n * @example\n * ```ts\n * const callbacks: FiberWatchCallbacks<number> = {\n * on_success: (value) => cache.set(key, value),\n * };\n * ```\n *\n * @since 2.0.0\n * @internal\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\n/**\n * Interrupts a dispatcher fiber through its managed runtime.\n *\n * @example\n * ```ts\n * interrupt_fiber(runtime, fiber);\n * ```\n *\n * @since 2.0.0\n * @param runtime - Managed runtime that owns the fiber.\n * @param fiber - Fiber to interrupt.\n * @returns Nothing.\n * @internal\n */\nexport function interrupt_fiber(\n\truntime: ManagedRuntimeType<unknown, unknown>,\n\tfiber: FiberType<unknown, unknown>,\n): void {\n\truntime.runFork(Fiber.interrupt(fiber) as Effect.Effect<unknown, unknown, unknown>);\n}\n\n/**\n * Watches a dispatcher fiber, runs completion callbacks, and surfaces\n * non-interrupt failures on the microtask queue.\n *\n * @example\n * ```ts\n * watch_fiber_exit({ runtime, fiber, on_complete: cleanup });\n * ```\n *\n * @since 2.0.0\n * @param options - Runtime, fiber, and callbacks used for the watcher.\n * @returns Nothing.\n * @internal\n */\nexport function watch_fiber_exit<A>(\n\toptions: {\n\t\truntime: ManagedRuntimeType<unknown, unknown>;\n\t\tfiber: FiberType<unknown, unknown>;\n\t} & FiberWatchCallbacks<A>,\n): void {\n\tconst { runtime, fiber, on_complete, on_success, on_failure, surface_failure = true } = options;\n\n\truntime.runFork(\n\t\tEffect.flatMap(Fiber.await(fiber), (exit) =>\n\t\t\tEffect.sync(() => {\n\t\t\t\tif (Exit.isSuccess(exit)) {\n\t\t\t\t\ton_success?.(exit.value as A);\n\t\t\t\t\ton_complete?.();\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (!Cause.hasInterruptsOnly(exit.cause)) {\n\t\t\t\t\tconst error = Cause.squash(exit.cause);\n\n\t\t\t\t\ton_failure?.(error);\n\n\t\t\t\t\tif (surface_failure) {\n\t\t\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\ton_complete?.();\n\t\t\t}),\n\t\t),\n\t);\n}\n","const object_dep_ids = new WeakMap<object, number>();\nconst symbol_dep_ids = new Map<symbol, number>();\n\nlet next_object_dep_id = 0;\nlet next_symbol_dep_id = 0;\n\n/**\n * Builds a deterministic cache key from a dependency array.\n *\n * @example\n * ```ts\n * const key = hash_deps([user_id, filters]);\n * ```\n *\n * @since 2.0.0\n * @param deps - Dependency array to encode for cache lookup.\n * @returns A structured string key suitable for Map lookups.\n * @internal\n */\nexport function hash_deps(deps: readonly unknown[]): string {\n\tconst parts = deps.map((dep) => {\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];\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\treturn JSON.stringify(parts);\n}\n\nfunction hash_symbol_dep(dep: symbol): string {\n\tlet id = symbol_dep_ids.get(dep);\n\n\tif (id === undefined) {\n\t\tnext_symbol_dep_id += 1;\n\t\tid = next_symbol_dep_id;\n\t\tsymbol_dep_ids.set(dep, id);\n\t}\n\n\treturn `y:${id}`;\n}\n\nfunction hash_object_dep(dep: object): string {\n\tlet id = object_dep_ids.get(dep);\n\n\tif (id === undefined) {\n\t\tnext_object_dep_id += 1;\n\t\tid = next_object_dep_id;\n\t\tobject_dep_ids.set(dep, id);\n\t}\n\n\treturn `o:${id}`;\n}\n","import type { Effect } from \"effect\";\n\n/**\n * Stable operation codes used by transform-generated dispatcher events.\n *\n * @example\n * ```ts\n * const type = Code.Markup.Promise;\n * ```\n *\n * @since 3.3.0\n * @internal\n */\nexport const Code = {\n\tMarkup: {\n\t\tPromise: \"MarkupPromise\",\n\t\tRun: \"MarkupRun\",\n\t\tValue: \"MarkupValue\",\n\t},\n} as const;\n\n/**\n * Options for markup promise behavior during server rendering.\n *\n * @example\n * ```ts\n * const options: MarkupPromiseOptions = { ssr: \"pending\" };\n * ```\n *\n * @since 3.3.0\n * @internal\n */\nexport interface MarkupPromiseOptions {\n\t/** Keep the SSR promise pending so Svelte renders an await block fallback. */\n\tssr?: \"pending\";\n}\n\n/**\n * Minimal cleanup handle returned by dispatcher lifecycle hooks.\n *\n * @example\n * ```ts\n * const dispose: Dispose = dispatcher.fork(program);\n * dispose();\n * ```\n *\n * @since 2.0.0\n * @internal\n */\nexport type Dispose = () => void;\n\n/**\n * Options for a cached dispatcher value block.\n *\n * @example\n * ```ts\n * const options: ValueOptions<number> = {\n * id: \"count\",\n * deps: [],\n * fallback: 0,\n * factory: () => Effect.succeed(1),\n * };\n * ```\n *\n * @since 2.0.0\n * @internal\n */\nexport interface ValueOptions<A> {\n\t/** Stable cache key for this value block. */\n\tid: string;\n\t/** Reactive dependency array. */\n\tdeps: readonly unknown[];\n\t/** Value returned synchronously while the effect is running or during SSR. */\n\tfallback: A;\n\t/** Generator function that yields the effect to run. */\n\tfactory: () => Effect.gen.Return<A, unknown, unknown>;\n}\n\n/**\n * Options for a cached dispatcher promise block.\n *\n * @example\n * ```ts\n * const options: PromiseOptions<number> = {\n * id: \"count\",\n * deps: [],\n * factory: () => Effect.succeed(1),\n * };\n * ```\n *\n * @since 2.0.0\n * @internal\n */\nexport interface PromiseOptions<A> {\n\t/** Stable cache key for this promise block. */\n\tid: string;\n\t/** Reactive dependency array. */\n\tdeps: readonly unknown[];\n\t/** Generator function that yields the effect to run. */\n\tfactory: () => Effect.gen.Return<A, unknown, unknown>;\n}\n\n/**\n * Generated event that reads a markup expression through the cached value\n * channel.\n *\n * @example\n * ```ts\n * const event: MarkupValueEvent<number, undefined> = {\n * type: Code.Markup.Value,\n * id: \"Component.svelte:1:2\",\n * deps: [],\n * fallback: undefined,\n * fn: function* () {\n * return yield* Effect.succeed(1);\n * },\n * };\n * ```\n *\n * @since 3.3.0\n * @internal\n */\nexport interface MarkupValueEvent<A, F> {\n\t/** Dispatcher code identifying a markup value read. */\n\ttype: typeof Code.Markup.Value;\n\t/** Stable identifier generated from the expression's source position. */\n\tid: string;\n\t/** Reactive dependency array captured from free identifiers. */\n\tdeps: readonly unknown[];\n\t/** Value returned synchronously while the effect is pending. */\n\tfallback: F;\n\t/** Generator function that yields the effect to run. */\n\tfn: () => Effect.gen.Return<A, unknown, unknown>;\n}\n\n/**\n * Generated event that reads a markup expression through the cached promise\n * channel.\n *\n * @example\n * ```ts\n * const event: MarkupPromiseEvent<number> = {\n * type: Code.Markup.Promise,\n * id: \"Component.svelte:1:2\",\n * deps: [],\n * fn: function* () {\n * return yield* Effect.succeed(1);\n * },\n * };\n * ```\n *\n * @since 3.3.0\n * @internal\n */\nexport interface MarkupPromiseEvent<A> {\n\t/** Dispatcher code identifying a markup promise read. */\n\ttype: typeof Code.Markup.Promise;\n\t/** Stable identifier generated from the expression's source position. */\n\tid: string;\n\t/** Reactive dependency array captured from free identifiers. */\n\tdeps: readonly unknown[];\n\t/** Generator function that yields the effect to run. */\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\n/**\n * Generated event that runs an event-handler Effect.\n *\n * @example\n * ```ts\n * const event: MarkupRunEvent<void> = {\n * type: Code.Markup.Run,\n * fn: function* () {\n * yield* Effect.void;\n * },\n * };\n * ```\n *\n * @since 3.3.0\n * @internal\n */\nexport interface MarkupRunEvent<A> {\n\t/** Dispatcher code identifying a markup event-handler run. */\n\ttype: typeof Code.Markup.Run;\n\t/** Generator function that yields the effect to run. */\n\tfn: () => Effect.gen.Return<A, unknown, unknown>;\n}\n\n/**\n * Union of generated dispatcher events.\n *\n * @example\n * ```ts\n * const event: DispatcherEvent<number, undefined> = {\n * type: Code.Markup.Value,\n * id: \"Component.svelte:1:2\",\n * deps: [],\n * fallback: undefined,\n * fn: function* () {\n * return yield* Effect.succeed(1);\n * },\n * };\n * ```\n *\n * @since 3.3.0\n * @internal\n */\nexport type DispatcherEvent<A, F = A> =\n\t| MarkupPromiseEvent<A>\n\t| MarkupRunEvent<A>\n\t| MarkupValueEvent<A, F>;\n","import type { ManagedRuntime as ManagedRuntimeType } from \"effect/ManagedRuntime\";\nimport { Cause, Effect, Exit, Fiber, Layer, ManagedRuntime } from \"effect\";\nimport { createSubscriber } from \"svelte/reactivity\";\nimport type { Fiber as FiberType } from \"effect/Fiber\";\nimport { isRedirect } from \"@sveltejs/kit\";\n\nimport { RuntimeAlreadyInitializedError, DispatcherDisposedError } from \"$/errors.ts\";\nimport { interrupt_fiber, watch_fiber_exit } from \"./fibers.ts\";\nimport { hash_deps } from \"./deps.ts\";\nimport { Code } from \"./types.ts\";\nimport type {\n\tDispatcherEvent,\n\tDispose,\n\tMarkupPromiseEvent,\n\tMarkupRunEvent,\n\tMarkupValueEvent,\n\tPromiseOptions,\n\tValueOptions,\n} 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\n/**\n * Unified effect block dispatcher. Manages the fiber lifecycle of every\n * effect block and wires results into reactive channels.\n *\n * @example\n * ```ts\n * const dispatcher = new Dispatcher();\n * const cancel = dispatcher.fork(Effect.log(\"running\"));\n * cancel();\n * ```\n *\n * @since 2.0.0\n * @internal\n */\nexport class Dispatcher {\n\t/** The underlying Effect runtime that executes forked programs. */\n\t#runtime: ManagedRuntimeType<unknown, unknown>;\n\t/** Active fibers keyed by cache id or generated fork id. */\n\t#fibers = new Map<string, FiberType<unknown, unknown>>();\n\t/** Reactive value cells keyed by value cache id. */\n\t#value_cells = new Map<string, ValueCell<unknown>>();\n\t/** Notifies subscribed Svelte template effects when value cells change. */\n\t#notify_value_cells = (): void => {};\n\t/** Subscribes the current Svelte tracking scope to value cell changes. */\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/** Pending promises keyed by promise cache id. */\n\t#promise_values = new Map<string, Promise<unknown>>();\n\t/** Current cache key per value block id. */\n\t#value_ids = new Map<string, string>();\n\t/** Current cache key per promise block id. */\n\t#promise_ids = new Map<string, string>();\n\t/** Whether dispose has been called, blocking new work. */\n\t#disposed = false;\n\t/** Monotonically increasing counter for unnamed fiber keys. */\n\t#next_fiber_id = 0;\n\n\t/**\n\t * Creates a dispatcher with an optional layer and installs it as the global\n\t * singleton returned by {@link get_dispatcher}.\n\t *\n\t * @example\n\t * ```ts\n\t * const dispatcher = Dispatcher.make(Db.Live);\n\t * ```\n\t *\n\t * @since 2.0.0\n\t * @param layer - Optional Effect layer to provide to the runtime.\n\t * @returns The newly created dispatcher.\n\t */\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\t/**\n\t * Creates a dispatcher backed by the provided managed runtime.\n\t *\n\t * @example\n\t * ```ts\n\t * const dispatcher = new Dispatcher(runtime);\n\t * ```\n\t *\n\t * @since 2.0.0\n\t * @param runtime - Managed runtime to use, or an empty-layer runtime when\n\t * omitted.\n\t */\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 * Handles a transform-generated dispatcher event.\n\t *\n\t * @example\n\t * ```ts\n\t * const value = dispatcher.emit({\n\t * type: Code.Markup.Value,\n\t * id: \"Component.svelte:1:2\",\n\t * deps: [],\n\t * fallback: undefined,\n\t * fn: function* () {\n\t * return yield* Effect.succeed(1);\n\t * },\n\t * });\n\t * ```\n\t *\n\t * @since 3.3.0\n\t * @param event - Generated event describing the dispatcher operation to run.\n\t * @returns The operation result for the emitted dispatcher event.\n\t */\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\t/**\n\t * Forks an effect as a managed fiber and returns a cleanup function.\n\t *\n\t * @example\n\t * ```ts\n\t * const dispose = dispatcher.fork(Effect.log(\"clicked\"));\n\t * ```\n\t *\n\t * @since 2.0.0\n\t * @param effect - Effect to fork.\n\t * @returns A function that interrupts the fiber.\n\t */\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\twatch_fiber_exit({\n\t\t\truntime: this.#runtime,\n\t\t\tfiber,\n\t\t\ton_complete: () => this.#fibers.delete(key),\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\tinterrupt_fiber(this.#runtime, fiber);\n\t\t};\n\t}\n\n\t/**\n\t * Forks an effect and exposes its result as a cached reactive value.\n\t *\n\t * @example\n\t * ```ts\n\t * const user = dispatcher.value({ id, deps, fallback, factory });\n\t * ```\n\t *\n\t * @since 2.0.0\n\t * @param options - Value id, dependency array, fallback, and effect factory.\n\t * @returns The cached value if resolved, otherwise the fallback.\n\t */\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 cache_key = this.#make_value_cache_key(options.id, options.deps);\n\t\tconst old_key = this.#value_ids.get(options.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(options.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\t/**\n\t * Forks an effect and exposes its completion as a cached promise.\n\t *\n\t * @example\n\t * ```ts\n\t * const promise = dispatcher.promise({ id, deps, factory });\n\t * ```\n\t *\n\t * @since 2.0.0\n\t * @param options - Promise id, dependency array, and effect factory.\n\t * @returns A promise that resolves with the effect result.\n\t */\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 cache_key = this.#make_promise_cache_key(options.id, options.deps);\n\t\tconst old_key = this.#promise_ids.get(options.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(options.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);\n\n\t\tthis.#promise_values.set(cache_key, promise);\n\n\t\treturn promise;\n\t}\n\n\t/**\n\t * Runs an event-handler effect and surfaces failures to Svelte.\n\t *\n\t * @example\n\t * ```ts\n\t * await dispatcher.run(Effect.log(\"submit\"));\n\t * ```\n\t *\n\t * @since 2.0.0\n\t * @param effect - Effect to execute.\n\t * @returns A promise that resolves or rejects when the effect completes.\n\t */\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 ExitProgram = Effect.exit(effect) as Effect.Effect<unknown, unknown, unknown>;\n\n\t\treturn this.#runtime.runPromise(ExitProgram).then((exit: unknown) => {\n\t\t\tconst result = exit as Exit.Exit<A, E>;\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\tqueueMicrotask(() => {\n\t\t\t\tthrow error;\n\t\t\t});\n\n\t\t\tthrow error;\n\t\t});\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\t/**\n\t * Cancels all running fibers and releases cached values.\n\t *\n\t * @example\n\t * ```ts\n\t * dispatcher.dispose();\n\t * ```\n\t *\n\t * @since 2.0.0\n\t * @returns Nothing.\n\t */\n\tdispose(): void {\n\t\tthis.#disposed = true;\n\n\t\tfor (const fiber of this.#fibers.values()) {\n\t\t\tinterrupt_fiber(this.#runtime, 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}::${hash_deps(deps)}`;\n\t}\n\n\t#make_promise_cache_key(id: string, deps: readonly unknown[]): string {\n\t\treturn `promise:${id}::${hash_deps(deps)}`;\n\t}\n\n\t#is_server_render(): boolean {\n\t\treturn typeof document === \"undefined\";\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\tinterrupt_fiber(this.#runtime, 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 fiber = this.#runtime.runFork(Program as Effect.Effect<unknown, unknown, unknown>);\n\n\t\tthis.#fibers.set(cache_key, fiber);\n\n\t\tqueueMicrotask(() => {\n\t\t\tif (!this.#is_current_fiber(cache_key, fiber)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (this.#value_cells.has(cache_key)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#set_value_cell(cache_key, {\n\t\t\t\tstatus: \"pending\",\n\t\t\t\tfiber,\n\t\t\t});\n\t\t});\n\n\t\twatch_fiber_exit({\n\t\t\truntime: this.#runtime,\n\t\t\tfiber,\n\t\t\tsurface_failure: false,\n\t\t\ton_complete: () => this.#complete_fiber(cache_key, fiber),\n\t\t\ton_success: (value) => this.#publish_value_success(cache_key, fiber, value),\n\t\t\ton_failure: (error) => this.#publish_value_failure(cache_key, fiber, error),\n\t\t});\n\t}\n\n\t#start_promise_fiber<A>(cache_key: string, options: PromiseOptions<A>): 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 fiber = this.#runtime.runFork(Program as Effect.Effect<unknown, unknown, unknown>);\n\n\t\tthis.#fibers.set(cache_key, fiber);\n\n\t\treturn this.#runtime.runPromise(\n\t\t\tEffect.flatMap(Fiber.await(fiber), (exit) =>\n\t\t\t\tEffect.sync(() => {\n\t\t\t\t\tconst is_current = this.#is_current_fiber(cache_key, fiber);\n\n\t\t\t\t\tif (is_current) {\n\t\t\t\t\t\tthis.#fibers.delete(cache_key);\n\t\t\t\t\t\tthis.#promise_values.delete(cache_key);\n\n\t\t\t\t\t\tif (this.#promise_ids.get(options.id) === cache_key) {\n\t\t\t\t\t\t\tthis.#promise_ids.delete(options.id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (Exit.isSuccess(exit)) {\n\t\t\t\t\t\treturn exit.value as A;\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow Cause.squash(exit.cause);\n\t\t\t\t}),\n\t\t\t),\n\t\t);\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\n/**\n * Resolves the active dispatcher, creating a default one if necessary.\n *\n * @example\n * ```ts\n * const dispatcher = get_dispatcher();\n * ```\n *\n * @since 2.0.0\n * @returns The active dispatcher singleton.\n * @internal\n */\nexport function get_dispatcher(): Dispatcher {\n\tcurrent_dispatcher ??= new Dispatcher();\n\n\treturn current_dispatcher;\n}\n\n/**\n * Resets the internal singleton dispatcher used by source-level tests.\n *\n * @example\n * ```ts\n * reset_dispatcher();\n * ```\n *\n * @since 2.0.0\n * @returns Nothing.\n * @internal\n */\nexport function reset_dispatcher(): void {\n\tcurrent_dispatcher?.dispose();\n\tcurrent_dispatcher = null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,gBACf,SACA,OACO;CACP,QAAQ,QAAQ,MAAM,UAAU,KAAK,CAA6C;AACnF;;;;;;;;;;;;;;;AAgBA,SAAgB,iBACf,SAIO;CACP,MAAM,EAAE,SAAS,OAAO,aAAa,YAAY,YAAY,kBAAkB,SAAS;CAExF,QAAQ,QACP,OAAO,QAAQ,MAAM,MAAM,KAAK,IAAI,SACnC,OAAO,WAAW;EACjB,IAAI,KAAK,UAAU,IAAI,GAAG;GACzB,aAAa,KAAK,KAAU;GAC5B,cAAc;GAEd;EACD;EAEA,IAAI,CAAC,MAAM,kBAAkB,KAAK,KAAK,GAAG;GACzC,MAAM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B,WAAmB,MAAgC;EAClE,KAAKZ,aAAa,IAAI,WAAW,IAAI;EACrC,KAAKX,oBAAoB;CAC1B;CAEA,mBAAmB,WAAyB;EAG3C,IAAI,CAFY,KAAKW,aAAa,OAAO,SAE9B,GACV;EAGD,KAAKX,oBAAoB;CAC1B;CAEA,qBAA2B;EAC1B,IAAI,KAAKW,aAAa,SAAS,GAC9B;EAGD,KAAKA,aAAa,MAAM;EACxB,KAAKX,oBAAoB;CAC1B;CAEA,kBAAkB,WAAmB,OAA6C;EACjF,OAAO,CAAC,KAAKK,aAAa,KAAKE,QAAQ,IAAI,SAAS,MAAM;CAC3D;AACD;AAEA,IAAI,qBAAwC;;;;;;;;;;;;;AAc5C,SAAgB,iBAA6B;CAC5C,uBAAuB,IAAI,WAAW;CAEtC,OAAO;AACR;;;;;;;;;;;;;AAcA,SAAgB,mBAAyB;CACxC,oBAAoB,QAAQ;CAC5B,qBAAqB;AACtB"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { n as get_dispatcher$1 } from "./dispatcher-DOx8iC6r.js";
|
|
2
|
-
import { r as get_server_dispatcher } from "./runtime-GBQz32DZ.js";
|
|
3
|
-
//#region src/generated/dispatcher.ts
|
|
4
|
-
/**
|
|
5
|
-
* Facade used by transform-generated component code to dispatch runtime
|
|
6
|
-
* events through the current client or server dispatcher.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const value = Dispatcher.emit({
|
|
11
|
-
* type: Code.Markup.Value,
|
|
12
|
-
* id: "Component.svelte:1:2",
|
|
13
|
-
* deps: [],
|
|
14
|
-
* fallback: undefined,
|
|
15
|
-
* fn: function* () {
|
|
16
|
-
* return yield* Effect.succeed(1);
|
|
17
|
-
* },
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @since 3.3.0
|
|
22
|
-
* @internal
|
|
23
|
-
*/
|
|
24
|
-
var Dispatcher = class {
|
|
25
|
-
static emit(event) {
|
|
26
|
-
return get_dispatcher().emit(event);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Returns the dispatcher appropriate for generated component code.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* const dispatcher = get_dispatcher();
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @since 3.0.1
|
|
38
|
-
* @returns The server dispatcher during SSR, otherwise the client dispatcher.
|
|
39
|
-
*/
|
|
40
|
-
function get_dispatcher() {
|
|
41
|
-
if (typeof document === "undefined") return get_server_dispatcher();
|
|
42
|
-
return get_dispatcher$1();
|
|
43
|
-
}
|
|
44
|
-
//#endregion
|
|
45
|
-
export { get_dispatcher as n, Dispatcher as t };
|
|
46
|
-
|
|
47
|
-
//# sourceMappingURL=dispatcher-H-Ia0Os4.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher-H-Ia0Os4.js","names":["get_client_dispatcher"],"sources":["../../../modules/svelte-effect-runtime/src/generated/dispatcher.ts"],"sourcesContent":["import { get_dispatcher as get_client_dispatcher } from \"$/dispatcher.ts\";\nimport { get_server_dispatcher } from \"$/server/runtime.ts\";\nimport type {\n\tDispatcher as RuntimeDispatcher,\n\tDispatcherEvent,\n\tMarkupPromiseEvent,\n\tMarkupRunEvent,\n\tMarkupValueEvent,\n} from \"$/dispatcher.ts\";\n\nexport { Code } from \"$/dispatcher.ts\";\nexport type {\n\tDispatcherEvent,\n\tMarkupPromiseEvent,\n\tMarkupPromiseOptions,\n\tMarkupRunEvent,\n\tMarkupValueEvent,\n} from \"$/dispatcher.ts\";\n\n/**\n * Facade used by transform-generated component code to dispatch runtime\n * events through the current client or server dispatcher.\n *\n * @example\n * ```ts\n * const value = Dispatcher.emit({\n * type: Code.Markup.Value,\n * id: \"Component.svelte:1:2\",\n * deps: [],\n * fallback: undefined,\n * fn: function* () {\n * return yield* Effect.succeed(1);\n * },\n * });\n * ```\n *\n * @since 3.3.0\n * @internal\n */\nexport class Dispatcher {\n\t/**\n\t * Emits a transform-generated dispatcher event.\n\t *\n\t * @example\n\t * ```ts\n\t * const promise = Dispatcher.emit({\n\t * type: Code.Markup.Promise,\n\t * id: \"Component.svelte:1:2\",\n\t * deps: [],\n\t * fn: function* () {\n\t * return yield* Effect.succeed(1);\n\t * },\n\t * });\n\t * ```\n\t *\n\t * @since 3.3.0\n\t * @param event - Generated event describing the dispatcher operation to run.\n\t * @returns The result produced by the active dispatcher.\n\t */\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\n/**\n * Returns the dispatcher appropriate for generated component code.\n *\n * @example\n * ```ts\n * const dispatcher = get_dispatcher();\n * ```\n *\n * @since 3.0.1\n * @returns The server dispatcher during SSR, otherwise the client dispatcher.\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":";;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,aAAb,MAAwB;CAwBvB,OAAO,KAAW,OAAkD;EACnE,OAAO,eAAe,CAAC,CAAC,KAAK,KAAK;CACnC;AACD;;;;;;;;;;;;AAaA,SAAgB,iBAAoC;CACnD,IAAI,OAAO,aAAa,aACvB,OAAO,sBAAsB;CAG9B,OAAOA,iBAAsB;AAC9B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors-IJjsUwrE.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/errors.ts"],"sourcesContent":["/**\n * Base class for runtime-authored errors. The class gives every local failure\n * a stable JavaScript error name while preserving the technical message that\n * reaches Vite, SvelteKit, and test output.\n *\n * @example\n * ```ts\n * throw new RuntimeError(\"Invariant violated.\");\n * ```\n *\n * @since 2.4.0\n * @param message - Technical diagnostic message describing the failed runtime\n * invariant.\n * @returns A runtime-authored Error instance.\n */\nexport class RuntimeError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RuntimeError\";\n\t}\n}\n\n/**\n * Formats a runtime-owned error message with a stable screaming-case code.\n *\n * @example\n * ```ts\n * throw new Error(make_error_message(\"DISPATCHER_DISPOSED\", \"Dispatcher has been disposed\"));\n * ```\n *\n * @since 2.0.0\n * @param code - Stable screaming-case identifier for the error category.\n * @param message - Human-readable error message without the leading code.\n * @returns The complete error message prefixed with the stable code.\n */\nexport function make_error_message(code: string, message: string): string {\n\treturn `[${code}]: ${message}`;\n}\n\n/**\n * Base error class for all preprocessor errors emitted during script and\n * markup transformation. Carries the source filename so error messages can\n * reference the affected file.\n *\n * @example\n * ```ts\n * throw new PreprocessError(\"Component.svelte: invalid transform input.\", \"Component.svelte\");\n * ```\n *\n * @since 2.0.0\n * @param message - Technical diagnostic message for the transform failure.\n * @param filename - Source filename that triggered the transform failure.\n * @returns A preprocessor Error instance with source file context.\n */\nexport class PreprocessError extends RuntimeError {\n\t/**\n\t * The source filename that triggered this error.\n\t *\n\t * @since 2.0.0\n\t */\n\treadonly filename: string;\n\n\tconstructor(message: string, filename: string) {\n\t\tsuper(message);\n\t\tthis.name = \"PreprocessError\";\n\t\tthis.filename = filename;\n\t}\n}\n\n/**\n * Thrown when a statement mixes JavaScript `await` with Effect `yield*` work\n * that must be lowered into an `Effect.gen` program.\n *\n * @example\n * ```ts\n * throw new AwaitInEffectWorkError(\"Component.svelte\", \"const value = await load();\");\n * ```\n *\n * @since 2.0.0\n * @param filename - Source filename containing the unsupported statement.\n * @param statement_text - Full source text for the statement containing\n * mixed async work.\n * @returns A preprocessor Error instance with statement context.\n */\nexport class AwaitInEffectWorkError extends PreprocessError {\n\t/**\n\t * The full text of the problematic statement containing mixed async work.\n\t *\n\t * @since 2.0.0\n\t */\n\treadonly statement_text: string;\n\n\tconstructor(filename: string, statement_text: string) {\n\t\tsuper(\n\t\t\t[\n\t\t\t\tmake_error_message(\n\t\t\t\t\t\"AWAIT_IN_EFFECT_WORK\",\n\t\t\t\t\t`${filename}: await cannot be mixed with yield* in Effect work.`,\n\t\t\t\t),\n\t\t\t\t`Top-level await is supported as ordinary Svelte async rendering, but statements lowered into Effect.gen must use yield* for async Effect work.`,\n\t\t\t\t\"\",\n\t\t\t\t`Problematic statement:`,\n\t\t\t\tstatement_text,\n\t\t\t].join(\"\\n\"),\n\t\t\tfilename,\n\t\t);\n\t\tthis.name = \"AwaitInEffectWorkError\";\n\t\tthis.statement_text = statement_text;\n\t}\n}\n\n/**\n * Thrown when async Effect work appears inside a Svelte rune position that\n * must stay synchronous.\n *\n * @example\n * ```ts\n * throw new AsyncEffectInSyncRuneError(\"$derived\", \"$derived(yield* load())\", \"Component.svelte\");\n * ```\n *\n * @since 2.0.0\n * @param rune_name - Name of the Svelte rune containing the unsupported async\n * Effect work.\n * @param expression_text - Full source text for the rune expression.\n * @param filename - Source filename containing the unsupported rune.\n * @returns A preprocessor Error instance with rune source context.\n */\nexport class AsyncEffectInSyncRuneError extends PreprocessError {\n\t/**\n\t * The name of the rune that contained async Effect work.\n\t *\n\t * @since 2.0.0\n\t */\n\treadonly rune_name: string;\n\n\t/**\n\t * The full text of the expression that triggered the error.\n\t *\n\t * @since 2.0.0\n\t */\n\treadonly expression_text: string;\n\n\tconstructor(rune_name: string, expression_text: string, filename: string) {\n\t\tsuper(\n\t\t\t[\n\t\t\t\tmake_error_message(\n\t\t\t\t\t\"ASYNC_EFFECT_IN_SYNC_RUNE\",\n\t\t\t\t\t`${filename}: yield* cannot be used inside ${rune_name}().`,\n\t\t\t\t),\n\t\t\t\t`${rune_name}() must stay synchronous. Do not put async Effect work inside this rune.`,\n\t\t\t\t\"\",\n\t\t\t\t`Problematic expression:`,\n\t\t\t\texpression_text,\n\t\t\t].join(\"\\n\"),\n\t\t\tfilename,\n\t\t);\n\t\tthis.name = \"AsyncEffectInSyncRuneError\";\n\t\tthis.rune_name = rune_name;\n\t\tthis.expression_text = expression_text;\n\t}\n}\n\n/**\n * Thrown when async Effect work appears inside a non-generator callback nested\n * in a markup event handler.\n *\n * @example\n * ```ts\n * throw new AsyncEffectInEventCallbackError(\n * \"Component.svelte\",\n * \"Effect.try(() => yield* save())\",\n * );\n * ```\n *\n * @since 2.0.0\n * @param filename - Source filename containing the invalid event handler.\n * @param expression_text - Event handler expression that contains the nested\n * unsupported async Effect work.\n * @returns A preprocessor Error instance with event expression context.\n */\nexport class AsyncEffectInEventCallbackError extends PreprocessError {\n\t/**\n\t * The full text of the problematic event handler body.\n\t *\n\t * @since 2.0.0\n\t */\n\treadonly expression_text: string;\n\n\tconstructor(filename: string, expression_text: string) {\n\t\tsuper(\n\t\t\t[\n\t\t\t\tmake_error_message(\n\t\t\t\t\t\"ASYNC_EFFECT_IN_EVENT_CALLBACK\",\n\t\t\t\t\t`${filename}: yield* cannot be used inside a nested non-generator callback in a markup event handler.`,\n\t\t\t\t),\n\t\t\t\t`Move the yield* to the event handler body. Effect.try and Effect.sync callbacks are plain synchronous JavaScript; do not call Effect-returning functions inside them.`,\n\t\t\t\t\"\",\n\t\t\t\t`Run the remote Effect directly:`,\n\t\t\t\t` onclick={yield* UpvotePost(id)}`,\n\t\t\t\t\"\",\n\t\t\t\t`Recover from remote failures by composing the Effect value:`,\n\t\t\t\t` onclick={yield* UpvotePost(id).pipe(Effect.catch(() => Effect.void))}`,\n\t\t\t\t\"\",\n\t\t\t\t`Problematic expression:`,\n\t\t\t\texpression_text,\n\t\t\t].join(\"\\n\"),\n\t\t\tfilename,\n\t\t);\n\t\tthis.name = \"AsyncEffectInEventCallbackError\";\n\t\tthis.expression_text = expression_text;\n\t}\n}\n\n/**\n * Thrown when an event handler callback contains the old raw `yield*`\n * shorthand. Effectful event handlers must put `yield*` directly in the event\n * attribute so the callback boundary is generated by the markup runtime.\n *\n * @example\n * ```ts\n * throw new YieldStarInEventCallbackError(\"Component.svelte\", \"() => yield* save()\");\n * ```\n *\n * @since 2.0.0\n * @param filename - Svelte component filename used to identify where the\n * invalid event handler callback was found.\n * @param expression_text - Original event handler callback text that contained\n * `yield*` and should be rewritten as a direct event Effect expression.\n * @returns A preprocessor Error instance with event callback context.\n */\nexport class YieldStarInEventCallbackError extends PreprocessError {\n\t/**\n\t * The full text of the problematic event handler callback.\n\t *\n\t * @since 2.0.0\n\t */\n\treadonly expression_text: string;\n\n\tconstructor(filename: string, expression_text: string) {\n\t\tsuper(\n\t\t\t[\n\t\t\t\tmake_error_message(\n\t\t\t\t\t\"ASYNC_EFFECT_IN_EVENT_HANDLER_CALLBACK\",\n\t\t\t\t\t`${filename}: yield* in markup event handlers must be written directly as the event attribute value.`,\n\t\t\t\t),\n\t\t\t\t`SER generates the event callback for effectful event handlers; do not put yield* inside a JavaScript callback.`,\n\t\t\t\t\"\",\n\t\t\t\t`Use this form:`,\n\t\t\t\t` onclick={yield* UpvotePost(id)}`,\n\t\t\t\t\"\",\n\t\t\t\t`Instead of this form:`,\n\t\t\t\t` onclick={() => yield* UpvotePost(id)}`,\n\t\t\t\t\"\",\n\t\t\t\t`Problematic expression:`,\n\t\t\t\texpression_text,\n\t\t\t].join(\"\\n\"),\n\t\t\tfilename,\n\t\t);\n\t\tthis.name = \"YieldStarInEventCallbackError\";\n\t\tthis.expression_text = expression_text;\n\t}\n}\n\n/**\n * Thrown when async Effect work appears in a markup position SER cannot lower\n * safely.\n *\n * @example\n * ```ts\n * throw new UnsupportedMarkupEffectPositionError(\n * \"Component.svelte\",\n * \"value={yield* load()}\",\n * );\n * ```\n *\n * @since 2.4.2\n * @param filename - Source filename containing the unsupported markup.\n * @param expression_text - The unsupported markup expression text.\n * @returns A preprocessor Error instance with markup source context.\n */\nexport class UnsupportedMarkupEffectPositionError extends PreprocessError {\n\t/**\n\t * The unsupported markup expression text.\n\t *\n\t * @since 2.4.2\n\t */\n\treadonly expression_text: string;\n\n\tconstructor(filename: string, expression_text: string) {\n\t\tsuper(\n\t\t\t[\n\t\t\t\tmake_error_message(\n\t\t\t\t\t\"UNSUPPORTED_MARKUP_EFFECT_POSITION\",\n\t\t\t\t\t`${filename}: yield* cannot be used in this markup position.`,\n\t\t\t\t),\n\t\t\t\t`Move the Effect work into a supported expression tag, block expression, render expression, declaration tag, or event handler.`,\n\t\t\t\t\"\",\n\t\t\t\t`Problematic expression:`,\n\t\t\t\texpression_text,\n\t\t\t].join(\"\\n\"),\n\t\t\tfilename,\n\t\t);\n\t\tthis.name = \"UnsupportedMarkupEffectPositionError\";\n\t\tthis.expression_text = expression_text;\n\t}\n}\n\n/**\n * Thrown when the request-scoped SvelteKit event context is read outside a\n * remote handler.\n *\n * @example\n * ```ts\n * throw new RequestEventUnavailableError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing missing request context.\n */\nexport class RequestEventUnavailableError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"RequestEvent is only available while a SER remote handler is executing inside a request-scoped Effect context.\",\n\t\t);\n\t\tthis.name = \"RequestEventUnavailableError\";\n\t}\n}\n\n/**\n * Thrown when an unchecked Query declaration omits the handler.\n *\n * @example\n * ```ts\n * throw new UncheckedQueryHandlerMissingError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing the invalid Query overload usage.\n */\nexport class UncheckedQueryHandlerMissingError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Query('unchecked', handler) requires a concrete handler function as the second argument; the unchecked schema sentinel cannot execute by itself.\",\n\t\t);\n\t\tthis.name = \"UncheckedQueryHandlerMissingError\";\n\t}\n}\n\n/**\n * Thrown when a batch Query declaration omits the batch handler.\n *\n * @example\n * ```ts\n * throw new BatchQueryHandlerMissingError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing the invalid batch Query overload usage.\n */\nexport class BatchQueryHandlerMissingError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Query.batch requires a concrete batch handler function; the batch helper cannot infer a handler from schema metadata alone.\",\n\t\t);\n\t\tthis.name = \"BatchQueryHandlerMissingError\";\n\t}\n}\n\n/**\n * Thrown when an unchecked live Query declaration omits the handler.\n *\n * @example\n * ```ts\n * throw new UncheckedLiveQueryHandlerMissingError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing the invalid live Query overload usage.\n */\nexport class UncheckedLiveQueryHandlerMissingError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Query.live('unchecked', handler) requires a concrete handler function as the second argument; the unchecked schema sentinel cannot produce a live source.\",\n\t\t);\n\t\tthis.name = \"UncheckedLiveQueryHandlerMissingError\";\n\t}\n}\n\n/**\n * Thrown when an unchecked Command declaration omits the handler.\n *\n * @example\n * ```ts\n * throw new UncheckedCommandHandlerMissingError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing the invalid Command overload usage.\n */\nexport class UncheckedCommandHandlerMissingError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Command('unchecked', handler) requires a concrete handler function as the second argument; the unchecked schema sentinel cannot execute a command.\",\n\t\t);\n\t\tthis.name = \"UncheckedCommandHandlerMissingError\";\n\t}\n}\n\n/**\n * Thrown when an unchecked Form declaration omits the handler.\n *\n * @example\n * ```ts\n * throw new UncheckedFormHandlerMissingError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing the invalid Form overload usage.\n */\nexport class UncheckedFormHandlerMissingError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Form('unchecked', handler) requires a concrete handler function as the second argument; the unchecked schema sentinel cannot process form data.\",\n\t\t);\n\t\tthis.name = \"UncheckedFormHandlerMissingError\";\n\t}\n}\n\n/**\n * Thrown when an unchecked Prerender declaration omits the handler.\n *\n * @example\n * ```ts\n * throw new UncheckedPrerenderHandlerMissingError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing the invalid Prerender overload usage.\n */\nexport class UncheckedPrerenderHandlerMissingError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Prerender('unchecked', handler) requires a concrete handler function as the second argument; the unchecked schema sentinel cannot produce prerendered data.\",\n\t\t);\n\t\tthis.name = \"UncheckedPrerenderHandlerMissingError\";\n\t}\n}\n\n/**\n * Thrown when a live query handler resolves to a value that cannot be streamed.\n *\n * @example\n * ```ts\n * throw new InvalidLiveQueryReturnError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing the expected live query return protocol.\n */\nexport class InvalidLiveQueryReturnError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Query.live handler must return an Effect Stream. Wrap native iterables with Stream.fromIterable, Stream.fromAsyncIterable, or another Stream constructor before returning them.\",\n\t\t);\n\t\tthis.name = \"InvalidLiveQueryReturnError\";\n\t}\n}\n\n/**\n * Thrown when generated component code yields a Stream that completes before\n * producing a value.\n *\n * @example\n * ```ts\n * throw new EmptyStreamYieldError();\n * ```\n *\n * @since 3.4.8\n * @returns An Error describing an empty Stream in a value position.\n */\nexport class EmptyStreamYieldError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Cannot resolve yield* stream expression because the Stream completed without emitting a value.\",\n\t\t);\n\t\tthis.name = \"EmptyStreamYieldError\";\n\t}\n}\n\n/**\n * Thrown when a dispatcher operation is requested after disposal.\n *\n * @example\n * ```ts\n * throw new DispatcherDisposedError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing an invalid dispatcher lifecycle transition.\n */\nexport class DispatcherDisposedError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Dispatcher has been disposed; no new Effect fibers or promise bridges can be started after component teardown.\",\n\t\t);\n\t\tthis.name = \"DispatcherDisposedError\";\n\t}\n}\n\n/**\n * Thrown when an application attempts to configure a runtime after one has\n * already been initialized.\n *\n * @example\n * ```ts\n * throw new RuntimeAlreadyInitializedError(\"ClientRuntime\");\n * ```\n *\n * @since 3.4.0\n * @param runtime_name - Public runtime API that was initialized more than once.\n * @returns An Error describing the invalid runtime lifecycle transition.\n */\nexport class RuntimeAlreadyInitializedError extends RuntimeError {\n\tconstructor(runtime_name: string) {\n\t\tsuper(\n\t\t\tmake_error_message(\n\t\t\t\t\"RUNTIME_ALREADY_INITIALIZED\",\n\t\t\t\t`${runtime_name}.make(...) cannot be called because the runtime has already been initialized. Configure it once during application startup, before any Effect-backed component, remote handler, or generated runtime code runs.`,\n\t\t\t),\n\t\t);\n\t\tthis.name = \"RuntimeAlreadyInitializedError\";\n\t}\n}\n\n/**\n * Thrown when a generated or native remote query export is not callable.\n *\n * @example\n * ```ts\n * throw new InvalidQueryFactoryError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing an invalid query adapter input.\n */\nexport class InvalidQueryFactoryError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Invalid query factory: expected a function or an object exposing query/load methods from SvelteKit remote query generation.\",\n\t\t);\n\t\tthis.name = \"InvalidQueryFactoryError\";\n\t}\n}\n\n/**\n * Thrown when a generated or native remote live query export is not callable.\n *\n * @example\n * ```ts\n * throw new InvalidLiveQueryFactoryError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing an invalid live query adapter input.\n */\nexport class InvalidLiveQueryFactoryError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Invalid live query factory: expected a function or an object exposing a query method from SvelteKit remote live query generation.\",\n\t\t);\n\t\tthis.name = \"InvalidLiveQueryFactoryError\";\n\t}\n}\n\n/**\n * Thrown when a generated or native remote command export is not callable.\n *\n * @example\n * ```ts\n * throw new InvalidCommandFactoryError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing an invalid command adapter input.\n */\nexport class InvalidCommandFactoryError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Invalid command factory: expected a function or an object exposing an invoke method from SvelteKit remote command generation.\",\n\t\t);\n\t\tthis.name = \"InvalidCommandFactoryError\";\n\t}\n}\n\n/**\n * Thrown when the client-side form adapter cannot derive a remote endpoint.\n *\n * @example\n * ```ts\n * throw new RemoteFormEndpointMissingError();\n * ```\n *\n * @since 2.4.0\n * @returns An Error describing missing form transport metadata.\n */\nexport class RemoteFormEndpointMissingError extends RuntimeError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"Form has no submit method or remote endpoint; the adapted SvelteKit form object does not expose an action id and no remote base URL was generated.\",\n\t\t);\n\t\tthis.name = \"RemoteFormEndpointMissingError\";\n\t}\n}\n\n/**\n * Thrown when a remote form response envelope is not an object with a response\n * type.\n *\n * @example\n * ```ts\n * throw new InvalidRemoteFormResponseError(envelope);\n * ```\n *\n * @since 2.4.0\n * @param envelope - Raw response envelope returned by the remote form endpoint.\n * @returns An Error describing malformed form response data.\n */\nexport class InvalidRemoteFormResponseError extends RuntimeError {\n\t/**\n\t * Raw response envelope returned by the remote form endpoint.\n\t *\n\t * @since 2.4.0\n\t */\n\treadonly envelope: unknown;\n\n\tconstructor(envelope?: unknown) {\n\t\tsuper(\n\t\t\t\"Invalid remote form response: expected an object envelope with a string type field returned by SvelteKit remote form transport.\",\n\t\t);\n\t\tthis.name = \"InvalidRemoteFormResponseError\";\n\t\tthis.envelope = envelope;\n\t}\n}\n\n/**\n * Thrown when a remote form response has a well-formed envelope but an\n * unsupported response type or payload slot.\n *\n * @example\n * ```ts\n * throw new UnsupportedRemoteFormResponseError(envelope);\n * ```\n *\n * @since 2.4.0\n * @param envelope - Raw response envelope returned by the remote form endpoint.\n * @returns An Error describing unsupported form response data.\n */\nexport class UnsupportedRemoteFormResponseError extends RuntimeError {\n\t/**\n\t * Raw response envelope returned by the remote form endpoint.\n\t *\n\t * @since 2.4.0\n\t */\n\treadonly envelope: unknown;\n\n\tconstructor(envelope?: unknown) {\n\t\tsuper(\n\t\t\t\"Unsupported remote form response: expected a result envelope with a devalue-encoded result or data string.\",\n\t\t);\n\t\tthis.name = \"UnsupportedRemoteFormResponseError\";\n\t\tthis.envelope = envelope;\n\t}\n}\n\n/**\n * Thrown when a serialized remote failure envelope cannot be decoded.\n *\n * @example\n * ```ts\n * throw new RemoteErrorDecodeError(raw);\n * ```\n *\n * @since 2.4.0\n * @param raw - Raw serialized remote failure payload that failed decoding.\n * @returns An Error describing a malformed remote failure payload.\n */\nexport class RemoteErrorDecodeError extends RuntimeError {\n\t/**\n\t * Raw serialized remote failure payload that failed decoding.\n\t *\n\t * @since 2.4.0\n\t */\n\treadonly raw: unknown;\n\n\tconstructor(raw?: unknown) {\n\t\tsuper(\n\t\t\t\"Failed to decode remote error payload: expected a devalue-encoded SER remote failure envelope compatible with the client decoder.\",\n\t\t);\n\t\tthis.name = \"RemoteErrorDecodeError\";\n\t\tthis.raw = raw;\n\t}\n}\n\n/**\n * Thrown when a root server-only helper is imported without Vite rewriting.\n *\n * @example\n * ```ts\n * throw new ServerOnlyImportError(\"Query\");\n * ```\n *\n * @since 2.4.0\n * @param export_name - Name of the server-only root export that was invoked.\n * @returns An Error describing a missing server rewrite.\n */\nexport class ServerOnlyImportError extends RuntimeError {\n\t/**\n\t * Name of the server-only root export that was invoked.\n\t *\n\t * @since 2.4.0\n\t */\n\treadonly export_name: string;\n\n\tconstructor(export_name: string) {\n\t\tsuper(\n\t\t\t`${export_name} is only available in SvelteKit server files. Ensure the SER Vite plugin is enabled so root imports are rewritten to svelte-effect-runtime/server before execution.`,\n\t\t);\n\t\tthis.name = \"ServerOnlyImportError\";\n\t\tthis.export_name = export_name;\n\t}\n}\n\n/**\n * Thrown when the publish-time `$app/server` shim executes outside SvelteKit.\n *\n * @example\n * ```ts\n * throw new SvelteKitServerExportUnavailableError(\"query\");\n * ```\n *\n * @since 2.4.0\n * @param export_name - Name of the `$app/server` export that was invoked.\n * @returns An Error describing an unavailable SvelteKit virtual module export.\n */\nexport class SvelteKitServerExportUnavailableError extends RuntimeError {\n\t/**\n\t * Name of the `$app/server` export that was invoked.\n\t *\n\t * @since 2.4.0\n\t */\n\treadonly export_name: string;\n\n\tconstructor(export_name: string) {\n\t\tsuper(\n\t\t\t`SvelteKit virtual $app/server export ${export_name} is only available inside a SvelteKit server module.`,\n\t\t);\n\t\tthis.name = \"SvelteKitServerExportUnavailableError\";\n\t\tthis.export_name = export_name;\n\t}\n}\n\n/**\n * Thrown when a SvelteKit remote helper reports that it was called outside the\n * route-scoped remote module context.\n *\n * @example\n * ```ts\n * throw new RemoteHelperContextError(\"Query\");\n * ```\n *\n * @since 2.4.0\n * @param helper_name - SER helper name that triggered the context failure.\n * @returns An Error describing the required `.remote.ts` placement.\n */\nexport class RemoteHelperContextError extends RuntimeError {\n\t/**\n\t * SER helper name that triggered the context failure.\n\t *\n\t * @since 2.4.0\n\t */\n\treadonly helper_name: string;\n\n\tconstructor(helper_name: string) {\n\t\tsuper(\n\t\t\tmake_error_message(\n\t\t\t\t\"REMOTE_HELPER_CONTEXT\",\n\t\t\t\t`${helper_name} was called outside a .remote.ts file. Ensure the file is named \\`*.remote.ts\\` and is located in a route directory so SvelteKit can bind remote helper context.`,\n\t\t\t),\n\t\t);\n\t\tthis.name = \"RemoteHelperContextError\";\n\t\tthis.helper_name = helper_name;\n\t}\n}\n\n/**\n * Thrown when a SvelteKit remote helper normalizes a non-Error thrown value.\n *\n * @example\n * ```ts\n * throw new RemoteHelperError(\"raw failure\");\n * ```\n *\n * @since 2.4.0\n * @param value - Non-Error value thrown while creating a remote helper.\n * @returns An Error preserving the remote helper failure value.\n */\nexport class RemoteHelperError extends RuntimeError {\n\t/**\n\t * Non-Error value that was normalized.\n\t *\n\t * @since 2.4.0\n\t */\n\treadonly value: unknown;\n\n\tconstructor(value: unknown) {\n\t\tsuper(make_error_message(\"REMOTE_HELPER_ERROR\", String(value)));\n\t\tthis.name = \"RemoteHelperError\";\n\t\tthis.value = value;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,IAAa,eAAb,cA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cAA2C,aAAa;;;;;;CAMvD;CAEA,YAAY,aAAqB;EAChC,MACC,GAAG,YAAY,oKAChB;EACA,KAAK,OAAO;EACZ,KAAK,cAAc;CACpB;AACD;;;;;;;;;;;;;AAcA,IAAa,wCAAb,cAA2D,aAAa;;;;;;CAMvE;CAEA,YAAY,aAAqB;EAChC,MACC,wCAAwC,YAAY,qDACrD;EACA,KAAK,OAAO;EACZ,KAAK,cAAc;CACpB;AACD;;;;;;;;;;;;;;AAeA,IAAa,2BAAb,cAA8C,aAAa;;;;;;CAM1D;CAEA,YAAY,aAAqB;EAChC,MACC,mBACC,yBACA,GAAG,YAAY,iKAChB,CACD;EACA,KAAK,OAAO;EACZ,KAAK,cAAc;CACpB;AACD;;;;;;;;;;;;;AAcA,IAAa,oBAAb,cAAuC,aAAa;;;;;;CAMnD;CAEA,YAAY,OAAgB;EAC3B,MAAM,mBAAmB,uBAAuB,OAAO,KAAK,CAAC,CAAC;EAC9D,KAAK,OAAO;EACZ,KAAK,QAAQ;CACd;AACD"}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { c as InvalidLiveQueryFactoryError } from "./errors-IJjsUwrE.js";
|
|
2
|
-
import { Effect, Stream } from "effect";
|
|
3
|
-
//#region src/live.ts
|
|
4
|
-
/**
|
|
5
|
-
* Runtime marker attached to remote live streams created by SER.
|
|
6
|
-
*
|
|
7
|
-
* @since 3.4.8
|
|
8
|
-
*/
|
|
9
|
-
const REMOTE_LIVE_STREAM = Symbol.for("ser.remote-live-stream");
|
|
10
|
-
const LIVE_METADATA = Symbol.for("ser.remote-live-metadata");
|
|
11
|
-
const LIVE_OPERATOR = Symbol.for("ser.live-operator");
|
|
12
|
-
/**
|
|
13
|
-
* Builds a remote live stream from SvelteKit's native live resource.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* const stream = make_remote_live_stream(resource, normalize_native_error);
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @since 3.4.8
|
|
21
|
-
* @param resource - Native SvelteKit live query resource.
|
|
22
|
-
* @param on_error - Error mapper used for stream and reconnect failures.
|
|
23
|
-
* @returns A remote live stream carrying hidden transport metadata.
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
function make_remote_live_stream(resource, on_error) {
|
|
27
|
-
const live_resource = as_native_live_resource(resource);
|
|
28
|
-
return attach_live_metadata(Stream.fromAsyncIterable(live_resource, on_error), {
|
|
29
|
-
resource: live_resource,
|
|
30
|
-
on_error
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Remote live transport helpers.
|
|
35
|
-
*
|
|
36
|
-
* @since 3.4.8
|
|
37
|
-
*/
|
|
38
|
-
const Live = {
|
|
39
|
-
status: Object.assign(function status(stream) {
|
|
40
|
-
const metadata = get_live_metadata(stream);
|
|
41
|
-
if (!metadata) return Stream.succeed({ _tag: "Idle" });
|
|
42
|
-
return Stream.succeed(read_live_status(metadata.resource)).pipe(Stream.concat(Stream.tick("250 millis").pipe(Stream.map(() => read_live_status(metadata.resource)))));
|
|
43
|
-
}, { [LIVE_OPERATOR]: true }),
|
|
44
|
-
reconnect: Object.assign(function reconnect(stream) {
|
|
45
|
-
const metadata = get_live_metadata(stream);
|
|
46
|
-
const reconnect = metadata?.resource.reconnect;
|
|
47
|
-
if (!metadata || typeof reconnect !== "function") return Effect.fail(new InvalidLiveQueryFactoryError());
|
|
48
|
-
return Effect.tryPromise({
|
|
49
|
-
try: () => Promise.resolve(reconnect.call(metadata.resource)),
|
|
50
|
-
catch: metadata.on_error
|
|
51
|
-
});
|
|
52
|
-
}, { [LIVE_OPERATOR]: true })
|
|
53
|
-
};
|
|
54
|
-
function as_native_live_resource(resource) {
|
|
55
|
-
if (!is_native_live_resource(resource)) throw new InvalidLiveQueryFactoryError();
|
|
56
|
-
return resource;
|
|
57
|
-
}
|
|
58
|
-
function is_native_live_resource(resource) {
|
|
59
|
-
const resource_type = typeof resource;
|
|
60
|
-
if (resource_type !== "object" && resource_type !== "function") return false;
|
|
61
|
-
if (resource === null) return false;
|
|
62
|
-
return typeof resource[Symbol.asyncIterator] === "function";
|
|
63
|
-
}
|
|
64
|
-
function attach_live_metadata(stream, metadata) {
|
|
65
|
-
const carrier = stream;
|
|
66
|
-
if (carrier[LIVE_METADATA]) return stream;
|
|
67
|
-
Object.defineProperty(carrier, LIVE_METADATA, {
|
|
68
|
-
configurable: true,
|
|
69
|
-
value: metadata
|
|
70
|
-
});
|
|
71
|
-
Object.defineProperty(carrier, REMOTE_LIVE_STREAM, {
|
|
72
|
-
configurable: true,
|
|
73
|
-
value: true
|
|
74
|
-
});
|
|
75
|
-
propagate_live_metadata_through_pipe(carrier, metadata);
|
|
76
|
-
return stream;
|
|
77
|
-
}
|
|
78
|
-
function propagate_live_metadata_through_pipe(stream, metadata) {
|
|
79
|
-
const pipe = stream.pipe.bind(stream);
|
|
80
|
-
Object.defineProperty(stream, "pipe", {
|
|
81
|
-
configurable: true,
|
|
82
|
-
value: (...args) => {
|
|
83
|
-
const result = pipe(...args);
|
|
84
|
-
if (Stream.isStream(result)) return attach_live_metadata(result, metadata);
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
function get_live_metadata(stream) {
|
|
90
|
-
return stream[LIVE_METADATA];
|
|
91
|
-
}
|
|
92
|
-
function read_live_status(resource) {
|
|
93
|
-
if (resource.error !== void 0) return {
|
|
94
|
-
_tag: "Failed",
|
|
95
|
-
cause: resource.error
|
|
96
|
-
};
|
|
97
|
-
if (resource.done === true) return { _tag: "Closed" };
|
|
98
|
-
if (resource.connected === true) return { _tag: "Open" };
|
|
99
|
-
return { _tag: "Connecting" };
|
|
100
|
-
}
|
|
101
|
-
//#endregion
|
|
102
|
-
export { make_remote_live_stream as n, Live as t };
|
|
103
|
-
|
|
104
|
-
//# sourceMappingURL=live-BXAKre_4.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,OAAO,OAC1B,SAAS,OAAa,QAAyE;EAC9F,MAAM,WAAW,kBAAkB,MAAM;EAEzC,IAAI,CAAC,UACJ,OAAO,OAAO,QAAQ,EAAE,MAAM,OAAO,CAAU;EAGhD,OAAO,OAAO,QAAQ,iBAAiB,SAAS,QAAQ,CAAC,CAAC,CAAC,KAC1D,OAAO,OACN,OAAO,KAAK,YAAY,CAAC,CAAC,KACzB,OAAO,UAAU,iBAAiB,SAAS,QAAQ,CAAC,CACrD,CACD,CACD;CACD,GACA,GAAG,gBAAgB,KAAc,CAgCzB;CACR,WA9BsB,OAAO,OAC7B,SAAS,UACR,QAC+C;EAC/C,MAAM,WAAW,kBAAkB,MAAM;EACzC,MAAM,YAAY,UAAU,SAAS;EAErC,IAAI,CAAC,YAAY,OAAO,cAAc,YACrC,OAAO,OAAO,KAAK,IAAI,6BAA6B,CAAC;EAOtD,OAAO,OAAO,WAAW;GACxB,WAAW,QAAQ,QAAQ,UAAU,KAAK,SAAS,QAAQ,CAAC;GAC5D,OAAO,SAAS;EACjB,CAAC;CACF,GACA,GAAG,gBAAgB,KAAc,CAUtB;AACZ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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,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AAa,YAAY,IAAI,KAAK,CAAC,aAC1C,OAAO,CAAC;CAGT,MAAM,cAAc,8BAA8B,aAAa,SAAS;CAExE,IAAI,CAAC,aACJ,OAAO,CAAC;CAGT,OAAO,CACN;EACC,MAAM,YAAY,KAAK;EACvB,MAAM;EACN;EACA,aAAa,KAAK,MAAM,YAAY,SAAS,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 +0,0 @@
|
|
|
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 = undef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F"}
|
|
@@ -1,89 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,sBAAsB,OAAoD;CACzF,MAAM,eAAe,4BAA4B,KAAK;CAEtD,IAAI,iBAAiB,KAAA,GACpB,OAAO;EACN,MAAM;EACN,OAAO;CACR;CAGD,IAAI,MAAM,kBAAkB,KAAK,GAChC,OAAO;EACN,MAAM;EACN;CACD;CAGD,MAAM,oBAAoB,uBAAuB,KAAK;CAEtD,IAAI,sBAAsB,KAAA,GACzB,OAAO;EACN,MAAM;EACN,QAAQ;CACT;CAGD,OAAO;EACN,MAAM;EACN,SAAS,sBAAsB,KAAK;CACrC;AACD;;;;;;;;;;AAWA,SAAgB,sBAAsB,OAAqC;CAC1E,KAAK,MAAM,UAAU,MAAM,SAAS;EACnC,IAAI,CAAC,MAAM,aAAa,MAAM,GAC7B;EAID,MAAM,UAAU,kBADA,yBAAyB,OAAO,KACR,CAAC;EAEzC,IAAI,YAAY,KAAA,GACf,OAAO;CAET;CAEA,OAAO,iCAAiC;AACzC;AAEA,SAAS,4BAA4B,OAAkD;CACtF,KAAK,MAAM,UAAU,MAAM,SAAS;EACnC,IAAI,CAAC,MAAM,YAAY,MAAM,GAC5B;EAGD,IAAI,0BAA0B,OAAO,MAAM,GAC1C,OAAO,OAAO;CAEhB;AAGD;AAEA,SAAS,uBAAuB,OAA+D;CA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