svelte-effect-runtime 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/chunks/client-DkW4e4dD.js +199 -0
  2. package/dist/chunks/client-DkW4e4dD.js.map +1 -0
  3. package/dist/chunks/effect-CL8GJs8A.js +51 -0
  4. package/dist/chunks/effect-CL8GJs8A.js.map +1 -0
  5. package/dist/chunks/effect-compat-BhW0YPIs.js +103 -0
  6. package/dist/chunks/effect-compat-BhW0YPIs.js.map +1 -0
  7. package/dist/chunks/{magic-string.es-5gRBdMgP.js → magic-string.es-BnGH-5YR.js} +1 -1
  8. package/dist/chunks/{magic-string.es-5gRBdMgP.js.map → magic-string.es-BnGH-5YR.js.map} +1 -1
  9. package/dist/chunks/{markup-Ccw42uCl.js → markup-BpSHnnYD.js} +4 -4
  10. package/dist/chunks/{markup-Ccw42uCl.js.map → markup-BpSHnnYD.js.map} +1 -1
  11. package/dist/chunks/preprocess-CtLrnJcK.js +44 -0
  12. package/dist/chunks/preprocess-CtLrnJcK.js.map +1 -0
  13. package/dist/chunks/server-DR-6LMdP.js +629 -0
  14. package/dist/chunks/server-DR-6LMdP.js.map +1 -0
  15. package/dist/chunks/v3-p8V3Drpp.js +1 -0
  16. package/dist/chunks/v4-DIhYCbb_.js +1 -0
  17. package/dist/chunks/vite-DqjXRZd4.js +143 -0
  18. package/dist/chunks/vite-DqjXRZd4.js.map +1 -0
  19. package/dist/client.d.ts +1 -64
  20. package/dist/client.js +2 -170
  21. package/dist/effect.d.ts +1 -7
  22. package/dist/effect.js +1 -27
  23. package/dist/internal/effect-compat.d.ts +21 -0
  24. package/dist/internal/markup.d.ts +1 -1
  25. package/dist/internal/markup.js +1 -1
  26. package/dist/internal/remote-client.js +30 -6
  27. package/dist/internal/remote-client.js.map +1 -1
  28. package/dist/internal/transform.d.ts +1 -1
  29. package/dist/internal/transform.js +3 -4
  30. package/dist/internal/transform.js.map +1 -1
  31. package/dist/language-server.d.ts +9 -3
  32. package/dist/language-server.js +3 -3
  33. package/dist/mod.d.ts +1 -6
  34. package/dist/mod.js +3 -5
  35. package/dist/preprocess.d.ts +23 -6
  36. package/dist/preprocess.js +10 -31
  37. package/dist/preprocess.js.map +1 -1
  38. package/dist/root-node.d.ts +1 -14
  39. package/dist/root-node.js +63 -8
  40. package/dist/root-node.js.map +1 -0
  41. package/dist/server.d.ts +56 -129
  42. package/dist/server.js +44 -508
  43. package/dist/server.js.map +1 -1
  44. package/dist/v3/client.d.ts +93 -0
  45. package/dist/v3/effect.d.ts +17 -0
  46. package/dist/v3/mod.d.ts +3 -0
  47. package/dist/v3/preprocess.d.ts +28 -0
  48. package/dist/v3/root-node.d.ts +59 -0
  49. package/dist/v3/server.d.ts +167 -0
  50. package/dist/v3/vite.d.ts +46 -0
  51. package/dist/v4/client.d.ts +2 -0
  52. package/dist/v4/effect.d.ts +24 -0
  53. package/dist/v4/effect.js +19 -0
  54. package/dist/v4/effect.js.map +1 -0
  55. package/dist/v4/mod.d.ts +3 -0
  56. package/dist/v4/mod.js +3 -0
  57. package/dist/v4/preprocess.d.ts +30 -0
  58. package/dist/v4/preprocess.js +28 -0
  59. package/dist/v4/preprocess.js.map +1 -0
  60. package/dist/v4/root-node.d.ts +59 -0
  61. package/dist/v4/root-node.js +63 -0
  62. package/dist/v4/root-node.js.map +1 -0
  63. package/dist/v4/server.d.ts +118 -0
  64. package/dist/v4/server.js +22 -0
  65. package/dist/v4/server.js.map +1 -0
  66. package/dist/v4/vite.d.ts +34 -0
  67. package/dist/v4/vite.js +31 -0
  68. package/dist/v4/vite.js.map +1 -0
  69. package/dist/vite.d.ts +30 -15
  70. package/dist/vite.js +18 -101
  71. package/dist/vite.js.map +1 -1
  72. package/package.json +46 -3
  73. package/dist/client.js.map +0 -1
  74. package/dist/effect.js.map +0 -1
package/dist/vite.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vite.js","names":[],"sources":["../../modules/svelte-effect-runtime/vite.ts"],"sourcesContent":["import {\n type Options as SveltePluginOptions,\n svelte,\n} from \"@sveltejs/vite-plugin-svelte\";\nimport { createRequire } from \"node:module\";\nimport { dirname, resolve } from \"node:path\";\nimport process from \"node:process\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { Plugin } from \"vite\";\nimport {\n effectPreprocess,\n type EffectPreprocessOptions,\n} from \"./preprocess.ts\";\n\nexport interface SvelteEffectRuntimeOptions {\n effect?: EffectPreprocessOptions;\n svelte?: SveltePluginOptions;\n}\n\nexport interface SveltekitEffectRuntimeOptions {\n /**\n * Override the client-side module SvelteKit uses for generated `.remote.ts`\n * imports so remote calls default to Effect-returning adapters.\n */\n remoteModuleId?: string;\n}\n\nconst ROOT_PACKAGE_ID = \"svelte-effect-runtime\";\nconst INTERNAL_SERVER_PACKAGE_ID = \"svelte-effect-runtime/_server\";\nconst SERVER_SOURCE_PATTERN =\n /(?:^|\\/)(?:hooks\\.server\\.[cm]?[jt]s|.+\\.server\\.[cm]?[jt]s|.+\\.remote\\.[cm]?[jt]s)$/;\n\nfunction arrayify<T>(value: T | T[] | undefined): T[] {\n if (value === undefined) {\n return [];\n }\n\n return Array.isArray(value) ? value : [value];\n}\n\nexport function svelteEffectRuntime(\n options: SvelteEffectRuntimeOptions = {},\n): Plugin[] {\n const existingPreprocessors = arrayify(options.svelte?.preprocess);\n\n return svelte({\n ...options.svelte,\n preprocess: [\n effectPreprocess(options.effect),\n ...existingPreprocessors,\n ],\n });\n}\n\nfunction resolve_runtime_internal_path(\n source_relative_path: string,\n dist_relative_path: string,\n): string {\n const relative_path = import.meta.url.endsWith(\".ts\")\n ? source_relative_path\n : dist_relative_path;\n\n return fileURLToPath(new URL(relative_path, import.meta.url));\n}\n\nfunction resolve_kit_internal_runtime_path(relative_path: string): string {\n const runtime_require = createRequire(resolve(process.cwd(), \"package.json\"));\n const kit_package_path = runtime_require.resolve(\n \"@sveltejs/kit/package.json\",\n );\n const kit_root = dirname(kit_package_path);\n\n return pathToFileURL(resolve(kit_root, relative_path)).href;\n}\n\nfunction create_remote_runtime_module_code(): string {\n const adapter_module_path = resolve_runtime_internal_path(\n \"./internal/remote-client.ts\",\n \"./internal/remote-client.js\",\n );\n const kit_query_module_path = resolve_kit_internal_runtime_path(\n \"src/runtime/client/remote-functions/query.svelte.js\",\n );\n const kit_command_module_path = resolve_kit_internal_runtime_path(\n \"src/runtime/client/remote-functions/command.svelte.js\",\n );\n const kit_form_module_path = resolve_kit_internal_runtime_path(\n \"src/runtime/client/remote-functions/form.svelte.js\",\n );\n const kit_prerender_module_path = resolve_kit_internal_runtime_path(\n \"src/runtime/client/remote-functions/prerender.svelte.js\",\n );\n const kit_shared_module_path = resolve_kit_internal_runtime_path(\n \"src/runtime/client/remote-functions/shared.svelte.js\",\n );\n const kit_client_module_path = resolve_kit_internal_runtime_path(\n \"src/runtime/client/client.js\",\n );\n const kit_form_utils_module_path = resolve_kit_internal_runtime_path(\n \"src/runtime/form-utils.js\",\n );\n const kit_shared_runtime_module_path = resolve_kit_internal_runtime_path(\n \"src/runtime/shared.js\",\n );\n\n return `\nimport * as devalue from \"devalue\";\nimport { base, app_dir } from \"$app/paths/internal/client\";\nimport { query as native_query, query_batch as native_query_batch } from ${\n JSON.stringify(kit_query_module_path)\n };\nimport { command as native_command } from ${\n JSON.stringify(kit_command_module_path)\n };\nimport { form as native_form } from ${JSON.stringify(kit_form_module_path)};\nimport { prerender as native_prerender } from ${\n JSON.stringify(kit_prerender_module_path)\n };\nimport {\n apply_refreshes,\n get_remote_request_headers,\n remote_request\n} from ${JSON.stringify(kit_shared_module_path)};\nimport { app, invalidateAll, _goto } from ${\n JSON.stringify(kit_client_module_path)\n };\nimport { BINARY_FORM_CONTENT_TYPE, serialize_binary_form } from ${\n JSON.stringify(kit_form_utils_module_path)\n };\nimport { stringify_remote_arg } from ${\n JSON.stringify(kit_shared_runtime_module_path)\n };\nimport {\n create_remote_command_adapter,\n create_remote_form_adapter,\n create_remote_query_adapter\n} from ${JSON.stringify(adapter_module_path)};\n\nconst decode_payload = (encoded) => devalue.parse(encoded, app?.decoders ?? {});\nconst request_dependencies = {\n app,\n app_dir,\n apply_refreshes,\n base,\n get_remote_request_headers,\n remote_request,\n stringify_remote_arg\n};\n\nexport const query = create_remote_query_adapter(native_query, decode_payload, request_dependencies, \"query\");\nexport const query_batch = create_remote_query_adapter(native_query_batch, decode_payload, request_dependencies, \"query_batch\");\nexport const command = create_remote_command_adapter(native_command, decode_payload, request_dependencies);\nexport const prerender = create_remote_query_adapter(native_prerender, decode_payload, request_dependencies, \"prerender\");\nexport const form = create_remote_form_adapter(native_form, decode_payload, {\n binary_form_content_type: BINARY_FORM_CONTENT_TYPE,\n goto: _goto,\n invalidate_all: invalidateAll,\n serialize_binary_form,\n ...request_dependencies\n});\n`;\n}\n\nexport function sveltekitEffectRuntime(\n options: SveltekitEffectRuntimeOptions = {},\n): Plugin {\n const remote_module_id = options.remoteModuleId ??\n \"\\0svelte-effect-runtime:remote\";\n\n return {\n name: \"svelte-effect-runtime-remote\",\n enforce: \"pre\",\n resolveId(id) {\n if (id === \"__sveltekit/remote\") {\n return remote_module_id;\n }\n },\n load(id) {\n if (id !== remote_module_id) {\n return;\n }\n\n return create_remote_runtime_module_code();\n },\n transform(code, id) {\n const filename = id.split(\"?\", 1)[0];\n if (!SERVER_SOURCE_PATTERN.test(filename)) {\n return null;\n }\n\n if (!code.includes(ROOT_PACKAGE_ID)) {\n return null;\n }\n\n return code.replaceAll(ROOT_PACKAGE_ID, INTERNAL_SERVER_PACKAGE_ID);\n },\n };\n}\n"],"mappings":";;;;;;;AA2BA,MAAM,kBAAkB;AACxB,MAAM,6BAA6B;AACnC,MAAM,wBACJ;AAEF,SAAS,SAAY,OAAiC;AACpD,KAAI,UAAU,KAAA,EACZ,QAAO,EAAE;AAGX,QAAO,MAAM,QAAQ,MAAM,GAAG,QAAQ,CAAC,MAAM;;AAG/C,SAAgB,oBACd,UAAsC,EAAE,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B;AAEF,QAAO;EACL,MAAM;EACN,SAAS;EACT,UAAU,IAAI;AACZ,OAAI,OAAO,qBACT,QAAO;;EAGX,KAAK,IAAI;AACP,OAAI,OAAO,iBACT;AAGF,UAAO,mCAAmC;;EAE5C,UAAU,MAAM,IAAI;GAClB,MAAM,WAAW,GAAG,MAAM,KAAK,EAAE,CAAC;AAClC,OAAI,CAAC,sBAAsB,KAAK,SAAS,CACvC,QAAO;AAGT,OAAI,CAAC,KAAK,SAAS,gBAAgB,CACjC,QAAO;AAGT,UAAO,KAAK,WAAW,iBAAiB,2BAA2B;;EAEtE"}
1
+ {"version":3,"file":"vite.js","names":["create_svelte_effect_runtime","create_sveltekit_effect_runtime"],"sources":["../../modules/svelte-effect-runtime/vite.ts"],"sourcesContent":["/**\n * Public Vite entrypoint wrappers for `svelte-effect-runtime`.\n *\n * @example\n * ```ts\n * import { sveltekit_effect_runtime } from \"svelte-effect-runtime/vite\";\n *\n * export default {\n * plugins: [sveltekit_effect_runtime()],\n * };\n * ```\n *\n * @module\n */\nimport type { Plugin } from \"vite\";\nimport {\n svelte_effect_runtime as create_svelte_effect_runtime,\n type SvelteEffectRuntimeOptions,\n sveltekit_effect_runtime as create_sveltekit_effect_runtime,\n type SveltekitEffectRuntimeOptions,\n} from \"$/v3/vite.ts\";\n\nexport type {\n SvelteEffectRuntimeOptions,\n SveltekitEffectRuntimeOptions,\n} from \"$/v3/vite.ts\";\n\n/**\n * Compose the low-level Svelte preprocessor directly into a plain Vite +\n * Svelte project.\n *\n * @see https://ser.barekey.dev/content/reference/tooling\n */\nexport function svelte_effect_runtime(\n options?: SvelteEffectRuntimeOptions,\n): Plugin[] {\n return create_svelte_effect_runtime(options);\n}\n\n/**\n * Install the remote-function adapter that rewrites SvelteKit remote helpers\n * to return `Effect` values.\n *\n * @see https://ser.barekey.dev/content/reference/tooling\n */\nexport function sveltekit_effect_runtime(\n options?: SveltekitEffectRuntimeOptions,\n): Plugin {\n return create_sveltekit_effect_runtime(options);\n}\n"],"mappings":";;;;;;;;AAiCA,SAAgB,sBACd,SACU;AACV,QAAOA,wBAA6B,QAAQ;;;;;;;;AAS9C,SAAgB,yBACd,SACQ;AACR,QAAOC,2BAAgC,QAAQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-effect-runtime",
3
- "version": "1.2.3",
3
+ "version": "1.3.0",
4
4
  "description": "Client-side Effect runtime support for Svelte <script> blocks.",
5
5
  "license": "BSD-3-Clause",
6
6
  "type": "module",
@@ -21,10 +21,52 @@
21
21
  "node": "./dist/root-node.js",
22
22
  "default": "./dist/mod.js"
23
23
  },
24
+ "./v3": {
25
+ "types": "./dist/root-node.d.ts",
26
+ "node": "./dist/root-node.js",
27
+ "default": "./dist/mod.js"
28
+ },
29
+ "./v4": {
30
+ "types": "./dist/v4/root-node.d.ts",
31
+ "node": "./dist/v4/root-node.js",
32
+ "default": "./dist/v4/mod.js"
33
+ },
34
+ "./preprocess": {
35
+ "types": "./dist/preprocess.d.ts",
36
+ "default": "./dist/preprocess.js"
37
+ },
38
+ "./v3/preprocess": {
39
+ "types": "./dist/preprocess.d.ts",
40
+ "default": "./dist/preprocess.js"
41
+ },
42
+ "./vite": {
43
+ "types": "./dist/vite.d.ts",
44
+ "default": "./dist/vite.js"
45
+ },
46
+ "./v3/vite": {
47
+ "types": "./dist/vite.d.ts",
48
+ "default": "./dist/vite.js"
49
+ },
50
+ "./v4/preprocess": {
51
+ "types": "./dist/v4/preprocess.d.ts",
52
+ "default": "./dist/v4/preprocess.js"
53
+ },
54
+ "./v4/vite": {
55
+ "types": "./dist/v4/vite.d.ts",
56
+ "default": "./dist/v4/vite.js"
57
+ },
24
58
  "./_server": {
25
59
  "types": "./dist/server.d.ts",
26
60
  "default": "./dist/server.js"
27
61
  },
62
+ "./v3/_server": {
63
+ "types": "./dist/server.d.ts",
64
+ "default": "./dist/server.js"
65
+ },
66
+ "./v4/_server": {
67
+ "types": "./dist/v4/server.d.ts",
68
+ "default": "./dist/v4/server.js"
69
+ },
28
70
  "./language-server": {
29
71
  "types": "./dist/language-server.d.ts",
30
72
  "default": "./dist/language-server.js"
@@ -35,12 +77,13 @@
35
77
  "build:npm": "npm run build",
36
78
  "check": "deno task check",
37
79
  "clean": "deno task clean",
80
+ "smoke:v4": "deno task smoke:v4",
38
81
  "test": "deno task test"
39
82
  },
40
83
  "peerDependencies": {
41
84
  "@sveltejs/kit": "^2.0.0",
42
- "@sveltejs/vite-plugin-svelte": "^6.0.0",
43
- "effect": "^3.0.0",
85
+ "@sveltejs/vite-plugin-svelte": "^6.0.0 || ^7.0.0",
86
+ "effect": "^3.0.0 || >=4.0.0-beta.0 <5",
44
87
  "svelte": "^5.0.0",
45
88
  "vite": "^7.0.0 || ^8.0.0"
46
89
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["../../modules/svelte-effect-runtime/client.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as ManagedRuntime from \"effect/ManagedRuntime\";\nimport * as Cause from \"effect/Cause\";\nimport * as Exit from \"effect/Exit\";\nimport { getContext, hasContext, onDestroy, setContext } from \"svelte\";\nimport {\n create_remote_domain_error,\n create_remote_http_error,\n create_remote_transport_error,\n create_remote_validation_error,\n is_serialized_remote_failure_envelope,\n REMOTE_ERROR_DECODER,\n type RemoteFailure,\n} from \"./internal/remote-shared.ts\";\n\nconst EFFECT_RUNTIME_CONTEXT = Symbol.for(\"svelte-effect-runtime/runtime\");\nlet current_client_runtime: EffectRuntime<unknown> | null = null;\n\nexport interface ProvideEffectRuntimeOptions {\n disposeOnDestroy?: boolean;\n}\n\nexport interface ImportMetaLike {\n hot?: {\n dispose(callback: () => void): void;\n };\n}\n\nexport interface EffectRuntime<R = unknown> {\n runCallback<A, E, R2>(\n effect: Effect.Effect<A, E, R2>,\n options?: {\n onExit?: (exit: Exit.Exit<A, E>) => void;\n },\n ): () => void;\n runPromise<A, E, R2>(effect: Effect.Effect<A, E, R2>): Promise<A>;\n dispose(): Promise<void>;\n}\n\nexport type {\n FormError,\n FormIssue,\n RemoteDomainError,\n RemoteFailure,\n RemoteHttpError,\n RemoteTransportError,\n RemoteValidationError,\n} from \"./internal/remote-shared.ts\";\n\nexport interface ClientRuntimeService extends EffectRuntime<unknown> {}\n\nexport const ClientRuntimeTag = Context.GenericTag<ClientRuntimeService>(\n \"svelte-effect-runtime/ClientRuntime\",\n);\n\ntype RuntimeSeedLayer<R> = Layer.Layer<R, never, R>;\n\nfunction runtimeSeed<R>(): RuntimeSeedLayer<R> {\n return Layer.effectContext(Effect.context<R>());\n}\n\ntype RuntimeOperator = (\n self: Layer.Layer<unknown, unknown, unknown>,\n) => Layer.Layer<unknown, unknown, unknown>;\n\ntype ProvidedBy<Op> = Op extends\n (self: RuntimeSeedLayer<infer R>) => Layer.Layer<unknown, unknown, infer RIn>\n ? Exclude<R, RIn>\n : never;\n\ntype ProvidedByAll<Ops extends ReadonlyArray<RuntimeOperator>> = Ops extends\n readonly [infer Head, ...infer Tail] ?\n | ProvidedBy<Head>\n | ProvidedByAll<Extract<Tail, ReadonlyArray<RuntimeOperator>>>\n : never;\n\ntype ApplyOperator<Seed, Op> = Op extends (self: Seed) => infer Out ? Out\n : never;\n\ntype ApplyOperators<\n Seed,\n Ops extends ReadonlyArray<RuntimeOperator>,\n> = Ops extends readonly [infer Head, ...infer Tail] ? ApplyOperators<\n ApplyOperator<Seed, Head>,\n Extract<Tail, ReadonlyArray<RuntimeOperator>>\n >\n : Seed;\n\ntype FinalRuntimeLayer<Ops extends ReadonlyArray<RuntimeOperator>> =\n ApplyOperators<RuntimeSeedLayer<ProvidedByAll<Ops>>, Ops> extends infer Out\n ? Out extends Layer.Layer<unknown, unknown, infer RIn>\n ? [RIn] extends [never] ? Out\n : never\n : never\n : never;\n\ninterface ClientRuntimeSeed {\n pipe(): Layer.Layer<never>;\n pipe<const Ops extends readonly [RuntimeOperator, ...Array<RuntimeOperator>]>(\n ...ops: Ops\n ): FinalRuntimeLayer<Ops>;\n make(): ManagedRuntime.ManagedRuntime<never, never>;\n make<const Ops extends readonly [RuntimeOperator, ...Array<RuntimeOperator>]>(\n ...ops: Ops\n ): ManagedRuntimeFromOps<Ops>;\n}\n\ntype ManagedRuntimeFromOps<Ops extends ReadonlyArray<RuntimeOperator>> =\n ManagedRuntime.ManagedRuntime<\n Layer.Layer.Success<FinalRuntimeLayer<Ops>>,\n Layer.Layer.Error<FinalRuntimeLayer<Ops>>\n >;\n\nfunction pipeClientRuntime(): Layer.Layer<never>;\nfunction pipeClientRuntime<\n const Ops extends readonly [RuntimeOperator, ...Array<RuntimeOperator>],\n>(...ops: Ops): FinalRuntimeLayer<Ops>;\nfunction pipeClientRuntime(\n ...ops: Array<RuntimeOperator>\n): Layer.Layer<never, unknown, unknown> {\n if (ops.length === 0) {\n return Layer.empty;\n }\n\n return ops.reduce<Layer.Layer<unknown, unknown, unknown>>(\n (layer, op) => op(layer),\n runtimeSeed<unknown>(),\n ) as Layer.Layer<never, unknown, unknown>;\n}\n\nfunction makeClientRuntime(): ManagedRuntime.ManagedRuntime<never, never>;\nfunction makeClientRuntime<\n const Ops extends readonly [RuntimeOperator, ...Array<RuntimeOperator>],\n>(...ops: Ops): ManagedRuntimeFromOps<Ops>;\nfunction makeClientRuntime(\n ...ops: [] | [RuntimeOperator, ...Array<RuntimeOperator>]\n): ManagedRuntime.ManagedRuntime<never, unknown> {\n const layer = ops.length === 0 ? pipeClientRuntime() : pipeClientRuntime(\n ...(ops as [RuntimeOperator, ...Array<RuntimeOperator>]),\n );\n\n const runtime = track_client_runtime(ManagedRuntime.make(\n layer as unknown as Layer.Layer<unknown, unknown, never>,\n ));\n\n void current_client_runtime?.dispose().catch(() => undefined);\n current_client_runtime = runtime;\n\n if (is_component_context_available()) {\n return provideEffectRuntime(runtime, { disposeOnDestroy: true });\n }\n\n return runtime;\n}\n\n/**\n * A pass-through layer representing the dependency graph you want to include\n * in the client ManagedRuntime. Users can compose this directly:\n *\n * ManagedRuntime.make(\n * ClientRuntime.pipe(\n * Layer.provide(MyApi.Live),\n * Layer.provide(Logger.Live),\n * ),\n * )\n */\nexport const ClientRuntime: ClientRuntimeSeed = {\n pipe: pipeClientRuntime,\n make: makeClientRuntime,\n};\n\nexport function provideEffectRuntime<T extends EffectRuntime>(\n runtime: T,\n options: ProvideEffectRuntimeOptions = {},\n): T {\n current_client_runtime = track_client_runtime(runtime);\n setContext(EFFECT_RUNTIME_CONTEXT, runtime);\n\n if (options.disposeOnDestroy) {\n onDestroy(() => {\n void runtime.dispose();\n });\n }\n\n return runtime;\n}\n\nexport function getEffectRuntimeOrThrow<\n T extends EffectRuntime = EffectRuntime<never>,\n>(): T {\n if (has_runtime_context()) {\n return getContext<T>(EFFECT_RUNTIME_CONTEXT);\n }\n\n if (current_client_runtime !== null) {\n return current_client_runtime as T;\n }\n\n // No runtime registered — lazily create a default one with an empty layer.\n // This makes `ClientRuntime.make()` in `hooks.client.ts` optional for apps\n // that don't need to provide custom dependencies. A later explicit call to\n // `ClientRuntime.make(...)` will dispose this default and replace it.\n const default_runtime = track_client_runtime(\n ManagedRuntime.make(\n Layer.empty as unknown as Layer.Layer<unknown, unknown, never>,\n ),\n );\n current_client_runtime = default_runtime;\n return default_runtime as unknown as T;\n}\n\nexport function runComponentEffect<A, E, R>(\n runtime: EffectRuntime<R>,\n program: Effect.Effect<A, E, R>,\n): () => void {\n let disposed = false;\n\n const cancel = runtime.runCallback(program, {\n onExit(exit) {\n if (Exit.isFailure(exit) && !Exit.isInterrupted(exit)) {\n queueMicrotask(() => {\n throw Cause.squash(exit.cause);\n });\n }\n },\n });\n\n return () => {\n if (disposed) {\n return;\n }\n\n disposed = true;\n cancel();\n };\n}\n\nexport function runInlineEffect<A, E, R>(\n runtime: EffectRuntime<R>,\n program: Effect.Effect<A, E, R>,\n): Promise<A> {\n console.log(\"[svelte-effect-runtime][client]\", \"runInlineEffect:start\");\n return runtime.runPromise(program).catch((error) => {\n console.error(\"[svelte-effect-runtime][client]\", \"runInlineEffect:error\", {\n error,\n });\n queueMicrotask(() => {\n throw error;\n });\n\n throw error;\n });\n}\n\nexport function registerHotDispose(\n meta: ImportMetaLike,\n cleanup: () => void,\n): void {\n meta.hot?.dispose(cleanup);\n}\n\nfunction has_runtime_context(): boolean {\n try {\n return hasContext(EFFECT_RUNTIME_CONTEXT);\n } catch {\n return false;\n }\n}\n\nfunction is_component_context_available(): boolean {\n try {\n void hasContext(EFFECT_RUNTIME_CONTEXT);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction track_client_runtime<T extends EffectRuntime>(runtime: T): T {\n const tracked_runtime = runtime as T & { __ser_tracked__?: true };\n\n if (tracked_runtime.__ser_tracked__ === true) {\n return tracked_runtime;\n }\n\n const dispose = runtime.dispose.bind(runtime);\n tracked_runtime.__ser_tracked__ = true;\n runtime.dispose = (() => {\n if (current_client_runtime === tracked_runtime) {\n current_client_runtime = null;\n }\n\n return dispose();\n }) as typeof runtime.dispose;\n\n return tracked_runtime;\n}\n\nfunction is_redirect_like(value: unknown): boolean {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { location?: unknown }).location === \"string\" &&\n typeof (value as { status?: unknown }).status === \"number\",\n );\n}\n\ntype Decode_remote_payload = <ErrorType = unknown>(\n encoded: string,\n) => ErrorType;\n\nfunction is_http_error_like(\n value: unknown,\n): value is {\n readonly body?: unknown;\n readonly status?: number;\n} {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { status?: unknown }).status === \"number\",\n );\n}\n\nfunction get_error_status(value: unknown): number {\n return is_http_error_like(value) ? value.status ?? 500 : 500;\n}\n\nfunction get_remote_error_decoder(\n value: unknown,\n): Decode_remote_payload | undefined {\n if (\n value &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n REMOTE_ERROR_DECODER in value\n ) {\n return (value as { [REMOTE_ERROR_DECODER]: Decode_remote_payload })[\n REMOTE_ERROR_DECODER\n ];\n }\n}\n\nfunction decode_remote_error<ErrorType>(\n error: unknown,\n decode_payload?: Decode_remote_payload,\n): RemoteFailure<ErrorType> {\n if (is_http_error_like(error)) {\n const body = error.body;\n\n if (is_serialized_remote_failure_envelope(body) && decode_payload) {\n try {\n return create_remote_domain_error<ErrorType>(\n decode_payload<ErrorType>(body.encoded),\n get_error_status(error),\n );\n } catch (cause) {\n return create_remote_transport_error(cause, body);\n }\n }\n\n if (get_error_status(error) === 400) {\n return create_remote_validation_error([], {\n body,\n status: 400,\n });\n }\n\n return create_remote_http_error(error, {\n body,\n status: get_error_status(error),\n });\n }\n\n return create_remote_http_error(error);\n}\n\nfunction create_remote_effect_from_promise<Success, ErrorType = never>(\n create_promise: () => PromiseLike<Success>,\n decode_error: (error: unknown) => RemoteFailure<ErrorType> = (error) =>\n create_remote_http_error(error),\n): Effect.Effect<Success, RemoteFailure<ErrorType>, never> {\n return Effect.async<Success, RemoteFailure<ErrorType>>((resume) => {\n void Promise.resolve()\n .then(create_promise)\n .then(\n (value) => resume(Effect.succeed(value)),\n (error) => {\n if (is_redirect_like(error)) {\n resume(Effect.die(error));\n return;\n }\n\n resume(Effect.fail(decode_error(error)));\n },\n );\n });\n}\n\ntype AnyCallable = (...args: Array<unknown>) => unknown;\n\nexport function to_effect<Success, ErrorType = never>(\n promise_like: PromiseLike<Success>,\n): Effect.Effect<Success, RemoteFailure<ErrorType>, never>;\nexport function to_effect<Args extends Array<unknown>, Success, ErrorType = never>(\n fn: (...args: Args) => PromiseLike<Success>,\n): (...args: Args) => Effect.Effect<Success, RemoteFailure<ErrorType>, never>;\nexport function to_effect<Success, ErrorType = never>(\n value: PromiseLike<Success> | AnyCallable,\n): Effect.Effect<Success, RemoteFailure<ErrorType>, never> | AnyCallable {\n const decode_payload = get_remote_error_decoder(value);\n\n if (typeof value === \"function\") {\n return ((...args: Array<unknown>) =>\n create_remote_effect_from_promise(\n () => Promise.resolve((value as AnyCallable)(...args)),\n (error) => decode_remote_error<ErrorType>(error, decode_payload),\n )) as AnyCallable;\n }\n\n return create_remote_effect_from_promise(\n () => value,\n (error) => decode_remote_error<ErrorType>(error, decode_payload),\n );\n}\n\nexport function to_native<Value>(\n value: Value,\n): Value extends { native: infer Native } ? Native\n : Value;\nexport function to_native(value: unknown): unknown {\n let current = value;\n const seen = new Set<unknown>();\n\n while (\n current &&\n (typeof current === \"object\" || typeof current === \"function\") &&\n \"native\" in current\n ) {\n if (seen.has(current)) {\n break;\n }\n\n seen.add(current);\n current = (current as { native: unknown }).native;\n }\n\n return current;\n}\n\nexport { create_remote_effect_from_promise, is_redirect_like };\n"],"mappings":";;;;;;;;;AAiBA,MAAM,yBAAyB,OAAO,IAAI,gCAAgC;AAC1E,IAAI,yBAAwD;AAmC5D,MAAa,mBAAmB,QAAQ,WACtC,sCACD;AAID,SAAS,cAAsC;AAC7C,QAAO,MAAM,cAAc,OAAO,SAAY,CAAC;;AA2DjD,SAAS,kBACP,GAAG,KACmC;AACtC,KAAI,IAAI,WAAW,EACjB,QAAO,MAAM;AAGf,QAAO,IAAI,QACR,OAAO,OAAO,GAAG,MAAM,EACxB,aAAsB,CACvB;;AAOH,SAAS,kBACP,GAAG,KAC4C;CAC/C,MAAM,QAAQ,IAAI,WAAW,IAAI,mBAAmB,GAAG,kBACrD,GAAI,IACL;CAED,MAAM,UAAU,qBAAqB,eAAe,KAClD,MACD,CAAC;AAEG,yBAAwB,SAAS,CAAC,YAAY,KAAA,EAAU;AAC7D,0BAAyB;AAEzB,KAAI,gCAAgC,CAClC,QAAO,qBAAqB,SAAS,EAAE,kBAAkB,MAAM,CAAC;AAGlE,QAAO;;;;;;;;;;;;;AAcT,MAAa,gBAAmC;CAC9C,MAAM;CACN,MAAM;CACP;AAED,SAAgB,qBACd,SACA,UAAuC,EAAE,EACtC;AACH,0BAAyB,qBAAqB,QAAQ;AACtD,YAAW,wBAAwB,QAAQ;AAE3C,KAAI,QAAQ,iBACV,iBAAgB;AACT,UAAQ,SAAS;GACtB;AAGJ,QA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B,GAAG,KAAK,CAAC,GACrD,UAAU,oBAA+B,OAAO,eAAe,CACjE;AAGL,QAAO,wCACC,QACL,UAAU,oBAA+B,OAAO,eAAe,CACjE;;AAOH,SAAgB,UAAU,OAAyB;CACjD,IAAI,UAAU;CACd,MAAM,uBAAO,IAAI,KAAc;AAE/B,QACE,YACC,OAAO,YAAY,YAAY,OAAO,YAAY,eACnD,YAAY,SACZ;AACA,MAAI,KAAK,IAAI,QAAQ,CACnB;AAGF,OAAK,IAAI,QAAQ;AACjB,YAAW,QAAgC;;AAG7C,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"effect.js","names":[],"sources":["../../modules/svelte-effect-runtime/effect.ts"],"sourcesContent":["import { preprocess } from \"svelte/compiler\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport {\n effectPreprocess,\n type EffectPreprocessOptions,\n} from \"./preprocess.ts\";\nimport { sveltekitEffectRuntime } from \"./vite.ts\";\n\nexport interface EffectPluginOptions {\n effect?: EffectPreprocessOptions;\n remoteModuleId?: string;\n}\n\nfunction create_effect_svelte_transform(\n options: EffectPreprocessOptions = {},\n): Plugin {\n const preprocessor = effectPreprocess(options);\n\n return {\n name: \"svelte-effect-runtime-transform\",\n enforce: \"pre\",\n async transform(code, id, _options) {\n const filename = id.split(\"?\", 1)[0];\n if (!filename.endsWith(\".svelte\")) {\n return null;\n }\n\n const transformed = await preprocess(code, preprocessor, { filename });\n if (transformed.code === code) {\n return null;\n }\n\n return {\n code: transformed.code,\n ...(transformed.map ? { map: transformed.map as never } : {}),\n };\n },\n };\n}\n\nexport function effect(\n options: EffectPluginOptions = {},\n): PluginOption[] {\n const transform_plugin = create_effect_svelte_transform(options.effect);\n\n return [\n transform_plugin,\n sveltekitEffectRuntime({\n remoteModuleId: options.remoteModuleId,\n }),\n ];\n}\n"],"mappings":";;;;AAaA,SAAS,+BACP,UAAmC,EAAE,EAC7B;CACR,MAAM,eAAe,iBAAiB,QAAQ;AAE9C,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,UAAU,MAAM,IAAI,UAAU;GAClC,MAAM,WAAW,GAAG,MAAM,KAAK,EAAE,CAAC;AAClC,OAAI,CAAC,SAAS,SAAS,UAAU,CAC/B,QAAO;GAGT,MAAM,cAAc,MAAM,WAAW,MAAM,cAAc,EAAE,UAAU,CAAC;AACtE,OAAI,YAAY,SAAS,KACvB,QAAO;AAGT,UAAO;IACL,MAAM,YAAY;IAClB,GAAI,YAAY,MAAM,EAAE,KAAK,YAAY,KAAc,GAAG,EAAE;IAC7D;;EAEJ;;AAGH,SAAgB,OACd,UAA+B,EAAE,EACjB;AAGhB,QAAO,CAFkB,+BAA+B,QAAQ,OAAO,EAIrE,uBAAuB,EACrB,gBAAgB,QAAQ,gBACzB,CAAC,CACH"}