svelte-effect-runtime 2.0.0-beta.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dist/mod.d.ts +1 -1
- package/.dist/mod.js.map +1 -1
- package/.dist/runtime/preprocess.d.ts +1 -1
- package/.dist/runtime/preprocess.js +3 -2
- package/.dist/runtime/preprocess.js.map +1 -1
- package/.dist/vite.js +3 -2
- package/.dist/vite.js.map +1 -1
- package/package.json +70 -66
package/.dist/mod.d.ts
CHANGED
package/.dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/mod.ts"],"sourcesContent":["import { Dispatcher as InternalDispatcher } from \"$/dispatcher.ts\";\nimport type { RequestEvent as RequestEventShape } from \"$/server/runtime.ts\";\nimport type {\n CommandFactory,\n FormFactory,\n PrerenderFactory,\n QueryFactory,\n ServerRuntimeFactory,\n} from \"$/server/types.ts\";\nimport type { Context, Layer, ManagedRuntime } from \"effect\";\n\n/**\n * Result returned by the root Svelte markup preprocessor hook.\n *\n * @since 2.0.0\n */\ninterface MarkupResult {\n code: string;\n}\n\n/**\n * Root preprocessor group shape. The root export keeps transform code lazy so\n * client imports do not pull parser-only dependencies into the browser.\n *\n * @since 2.0.0\n */\ninterface PreprocessGroup {\n name: string;\n markup(\n options: { content: string; filename
|
|
1
|
+
{"version":3,"file":"mod.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/mod.ts"],"sourcesContent":["import { Dispatcher as InternalDispatcher } from \"$/dispatcher.ts\";\nimport type { RequestEvent as RequestEventShape } from \"$/server/runtime.ts\";\nimport type {\n CommandFactory,\n FormFactory,\n PrerenderFactory,\n QueryFactory,\n ServerRuntimeFactory,\n} from \"$/server/types.ts\";\nimport type { Context, Layer, ManagedRuntime } from \"effect\";\n\n/**\n * Result returned by the root Svelte markup preprocessor hook.\n *\n * @since 2.0.0\n */\ninterface MarkupResult {\n code: string;\n}\n\n/**\n * Root preprocessor group shape. The root export keeps transform code lazy so\n * client imports do not pull parser-only dependencies into the browser.\n *\n * @since 2.0.0\n */\ninterface PreprocessGroup {\n name: string;\n markup(\n options: { content: string; filename?: string },\n ): MarkupResult | Promise<MarkupResult>;\n}\n\n/**\n * Public API surface for `svelte-effect-runtime`.\n *\n * Call {@link ClientRuntime.make} in `hooks.client.ts`, call\n * {@link ServerRuntime.make} in `hooks.server.ts`, and let the Vite plugin\n * route server-only helpers to the server entrypoint automatically.\n *\n * @module\n */\n\n/**\n * Client-side runtime singleton. Call `ClientRuntime.make(layer?)` once\n * in `hooks.client.ts` to provide services to every component's effect\n * blocks.\n *\n * If never called, a default empty-layer runtime is created lazily on\n * the first `yield*` expression.\n *\n * @example\n * ```ts\n * import { ClientRuntime } from \"svelte-effect-runtime\";\n * import { Db } from \"./db.ts\";\n *\n * ClientRuntime.make(Db.Live);\n * ```\n *\n * @since 2.0.0\n */\nexport class ClientRuntime {\n /**\n * Build and cache the client-side dispatcher runtime.\n *\n * @since 2.0.0\n * @param layer - Optional Effect layer to provide to the runtime.\n */\n static make<R = never>(layer?: Layer.Layer<R>): void {\n InternalDispatcher.make(layer);\n }\n}\n\n/**\n * Server-side runtime singleton export. In SvelteKit server files the Vite\n * plugin rewrites root imports to `svelte-effect-runtime/server`, so this\n * name resolves to the real server implementation before it is evaluated.\n *\n * @example\n * ```ts\n * import { ServerRuntime } from \"svelte-effect-runtime\";\n *\n * ServerRuntime.make();\n * ```\n *\n * @since 2.0.0\n */\nexport const ServerRuntime: ServerRuntimeFactory = make_server_only_class(\n \"ServerRuntime\",\n) as never;\n\n/**\n * Remote query factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Query } from \"svelte-effect-runtime\";\n *\n * export const GetPosts = Query(Effect.succeed([]));\n * ```\n *\n * @since 2.0.0\n */\nexport const Query: QueryFactory = Object.assign(\n make_server_only_function(\"Query\"),\n {\n batch: make_server_only_function(\"Query.batch\"),\n live: make_server_only_function(\"Query.live\"),\n },\n) as never;\n\n/**\n * Remote command factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Command } from \"svelte-effect-runtime\";\n *\n * export const SavePost = Command(Schema.String, (id) => Effect.succeed(id));\n * ```\n *\n * @since 2.0.0\n */\nexport const Command: CommandFactory = make_server_only_function(\n \"Command\",\n) as never;\n\n/**\n * Remote form factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Form } from \"svelte-effect-runtime\";\n *\n * export const CreatePost = Form(PostInput, ({ data }) => Effect.succeed(data));\n * ```\n *\n * @since 2.0.0\n */\nexport const Form: FormFactory = make_server_only_function(\n \"Form\",\n) as never;\n\n/**\n * Remote prerender factory export for `.remote.ts` files imported from the\n * root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Prerender } from \"svelte-effect-runtime\";\n *\n * export const GetBuildInfo = Prerender(() => Effect.succeed(\"ready\"));\n * ```\n *\n * @since 2.0.0\n */\nexport const Prerender: PrerenderFactory = make_server_only_function(\n \"Prerender\",\n) as never;\n\n/**\n * Current SvelteKit request event service export for `.remote.ts` files\n * imported from the root entrypoint. The Vite plugin rewrites it to the real\n * server implementation.\n *\n * @example\n * ```ts\n * import { RequestEvent } from \"svelte-effect-runtime\";\n *\n * const event = yield* RequestEvent;\n * ```\n *\n * @since 2.0.0\n */\nexport const RequestEvent: Context.Reference<RequestEventShape> =\n make_server_only_function(\"RequestEvent\") as never;\n\n/**\n * Returns the active server runtime when imported from a server file. The Vite\n * plugin rewrites root imports to the real server implementation.\n *\n * @example\n * ```ts\n * import { get_server_runtime_or_throw } from \"svelte-effect-runtime\";\n *\n * const runtime = get_server_runtime_or_throw();\n * ```\n *\n * @since 2.0.0\n */\nexport const get_server_runtime_or_throw: () => ManagedRuntime.ManagedRuntime<\n unknown,\n never\n> = make_server_only_function(\"get_server_runtime_or_throw\") as never;\n\n/** Re-export error types users need for typed catch handlers. */\nexport type {\n FormError,\n FormIssue,\n RemoteFailure,\n RemoteHttpError,\n RemoteTransportError,\n RemoteValidationError,\n} from \"$/remote/shared.ts\";\n\nexport {\n is_form_error,\n is_remote_http_error,\n is_remote_transport_error,\n is_remote_validation_error,\n} from \"$/remote/shared.ts\";\n\n/** Re-export app setup helpers so users can import them from root. */\nexport { effect, type EffectOptions } from \"$/vite.ts\";\n\n/** Re-export server helper types from the root entrypoint. */\nexport type {\n EffectLike,\n EffectRemoteBatchHandler,\n EffectRemoteCommand,\n EffectRemoteForm,\n EffectRemoteFunction,\n EffectRemoteLiveQuery,\n EffectRemoteLiveQueryFunction,\n EffectRemoteLiveSource,\n EffectRemoteQuery,\n EffectRemoteQueryFunction,\n FormInvalid,\n PrerenderOptions,\n QueryBatchFactory,\n QueryFactory,\n QueryLiveFactory,\n RemoteLiveHandler,\n RemoteFormHandler,\n RemoteHandler,\n SchemaInput,\n CommandFactory,\n FormFactory,\n PrerenderFactory,\n ServerRuntimeFactory,\n StandardSchema,\n} from \"$/server/types.ts\";\n\n/**\n * Creates the Svelte preprocessor that lowers script and markup `yield*`\n * expressions. The heavy transform module is loaded lazily so browser imports\n * from the package root stay client-safe.\n *\n * @example\n * ```js\n * import { preprocess } from \"svelte-effect-runtime\";\n *\n * export default {\n * preprocess: [preprocess()],\n * };\n * ```\n *\n * @since 2.0.0\n * @returns A Svelte preprocessor group with an async markup hook.\n */\nexport function preprocess(): PreprocessGroup {\n return {\n name: \"svelte-effect-runtime\",\n\n async markup(options: { content: string; filename?: string }) {\n const runtime = await import(\"./runtime/preprocess.ts\");\n const group = runtime.preprocess();\n\n return await group.markup(options);\n },\n };\n}\n\nfunction make_server_only_class(name: string): unknown {\n return class ServerOnlyRuntime {\n static make(): never {\n throw make_server_only_error(name);\n }\n };\n}\n\nfunction make_server_only_function(name: string): (...args: unknown[]) => never {\n return (..._args: unknown[]): never => {\n throw make_server_only_error(name);\n };\n}\n\nfunction make_server_only_error(name: string): Error {\n return new Error(\n `${name} is only available in SvelteKit server files. ` +\n `Ensure the SER Vite plugin is enabled so root imports are rewritten ` +\n `to \\`svelte-effect-runtime/server\\` before evaluation.`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,IAAa,gBAAb,MAA2B;;;;;;;CAOzB,OAAO,KAAgB,OAA8B;AACnD,aAAmB,KAAK,MAAM;;;;;;;;;;;;;;;;;AAkBlC,MAAa,gBAAsC,uBACjD,gBACD;;;;;;;;;;;;;;AAeD,MAAa,QAAsB,OAAO,OACxC,0BAA0B,QAAQ,EAClC;CACE,OAAO,0BAA0B,cAAc;CAC/C,MAAM,0BAA0B,aAAa;CAC9C,CACF;;;;;;;;;;;;;;AAeD,MAAa,UAA0B,0BACrC,UACD;;;;;;;;;;;;;;AAeD,MAAa,OAAoB,0BAC/B,OACD;;;;;;;;;;;;;;;AAgBD,MAAa,YAA8B,0BACzC,YACD;;;;;;;;;;;;;;;AAgBD,MAAa,eACX,0BAA0B,eAAe;;;;;;;;;;;;;;AAe3C,MAAa,8BAGT,0BAA0B,8BAA8B;;;;;;;;;;;;;;;;;;AAmE5D,SAAgB,aAA8B;AAC5C,QAAO;EACL,MAAM;EAEN,MAAM,OAAO,SAAiD;AAI5D,UAAO,OAHS,MAAM,OAAO,4BACP,YAAY,CAEf,OAAO,QAAQ;;EAErC;;AAGH,SAAS,uBAAuB,MAAuB;AACrD,QAAO,MAAM,kBAAkB;EAC7B,OAAO,OAAc;AACnB,SAAM,uBAAuB,KAAK;;;;AAKxC,SAAS,0BAA0B,MAA6C;AAC9E,SAAQ,GAAG,UAA4B;AACrC,QAAM,uBAAuB,KAAK;;;AAItC,SAAS,uBAAuB,MAAqB;AACnD,wBAAO,IAAI,MACT,GAAG,KAAK,0KAGT"}
|
|
@@ -20,13 +20,14 @@ function preprocess() {
|
|
|
20
20
|
return {
|
|
21
21
|
name: "svelte-effect-runtime",
|
|
22
22
|
markup({ content, filename }) {
|
|
23
|
+
const resolved_filename = filename ?? "unknown.svelte";
|
|
23
24
|
const script = find_script(content);
|
|
24
25
|
let combined = content;
|
|
25
26
|
if (script?.has_effect) {
|
|
26
|
-
const result = transform_script_effect(script.text,
|
|
27
|
+
const result = transform_script_effect(script.text, resolved_filename);
|
|
27
28
|
combined = content.slice(0, script.effect_attr_start) + content.slice(script.effect_attr_end, script.open_end) + result.code + content.slice(script.close_start);
|
|
28
29
|
}
|
|
29
|
-
return { code: transform_markup_effect(combined,
|
|
30
|
+
return { code: transform_markup_effect(combined, resolved_filename).code };
|
|
30
31
|
}
|
|
31
32
|
};
|
|
32
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preprocess.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/runtime/preprocess.ts"],"sourcesContent":["import { transform_markup_effect } from \"$/markup/transform.ts\";\nimport { transform_script_effect } from \"$/preprocess.ts\";\n\n/**\n * Result returned by the Svelte markup preprocessor hook.\n *\n * @since 2.0.0\n */\ninterface MarkupResult {\n code: string;\n}\n\n/**\n * Minimal Svelte preprocessor group shape used by the runtime.\n *\n * @since 2.0.0\n */\ninterface PreprocessGroup {\n name: string;\n markup(options: { content: string; filename
|
|
1
|
+
{"version":3,"file":"preprocess.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/runtime/preprocess.ts"],"sourcesContent":["import { transform_markup_effect } from \"$/markup/transform.ts\";\nimport { transform_script_effect } from \"$/preprocess.ts\";\n\n/**\n * Result returned by the Svelte markup preprocessor hook.\n *\n * @since 2.0.0\n */\ninterface MarkupResult {\n code: string;\n}\n\n/**\n * Minimal Svelte preprocessor group shape used by the runtime.\n *\n * @since 2.0.0\n */\ninterface PreprocessGroup {\n name: string;\n markup(options: { content: string; filename?: string }): MarkupResult;\n}\n\n/**\n * Svelte preprocessor that lowers `yield*` in script and markup blocks.\n *\n * @example\n * ```js\n * import { preprocess } from \"svelte-effect-runtime\";\n *\n * export default {\n * preprocess: [preprocess()],\n * };\n * ```\n *\n * @since 2.0.0\n * @returns A Svelte preprocessor group with a `markup` hook.\n */\nexport function preprocess(): PreprocessGroup {\n return {\n name: \"svelte-effect-runtime\",\n\n markup({ content, filename }: { content: string; filename?: string }) {\n const resolved_filename = filename ?? \"unknown.svelte\";\n const script = find_script(content);\n\n let combined = content;\n\n if (script?.has_effect) {\n const result = transform_script_effect(script.text, resolved_filename);\n\n combined = content.slice(0, script.effect_attr_start) +\n content.slice(script.effect_attr_end, script.open_end) +\n result.code +\n content.slice(script.close_start);\n }\n\n const result = transform_markup_effect(combined, resolved_filename);\n\n return { code: result.code };\n },\n };\n}\n\nfunction find_script(content: string):\n | {\n text: string;\n open_end: number;\n close_start: number;\n has_effect: boolean;\n effect_attr_start: number;\n effect_attr_end: number;\n }\n | undefined {\n const pattern = /<script\\b([^>]*)>([\\s\\S]*?)<\\/script\\s*>/gi;\n\n for (const match of content.matchAll(pattern)) {\n if (match.index === undefined || /\\bmodule\\b/.test(match[1] ?? \"\")) {\n continue;\n }\n\n const attrs = match[1] ?? \"\";\n const effect_match = /\\s+effect(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+))?/\n .exec(attrs);\n const open_end = match.index + match[0].indexOf(\">\") + 1;\n const attr_start = effect_match?.index ?? attrs.length;\n const attr_end = attr_start + (effect_match?.[0].length ?? 0);\n\n return {\n text: match[2],\n open_end,\n close_start: match.index + match[0].lastIndexOf(\"<\"),\n has_effect: effect_match !== null,\n effect_attr_start: match.index + \"<script\".length + attr_start,\n effect_attr_end: match.index + \"<script\".length + attr_end,\n };\n }\n\n return undefined;\n}\n\nexport {\n type BlockRef,\n type ScriptTransformResult,\n transform_script_effect,\n} from \"$/preprocess.ts\";\n\nexport {\n type MarkupTransformResult,\n transform_markup_effect,\n} from \"$/markup/transform.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqCA,SAAgB,aAA8B;AAC5C,QAAO;EACL,MAAM;EAEN,OAAO,EAAE,SAAS,YAAoD;GACpE,MAAM,oBAAoB,YAAY;GACtC,MAAM,SAAS,YAAY,QAAQ;GAEnC,IAAI,WAAW;AAEf,OAAI,QAAQ,YAAY;IACtB,MAAM,SAAS,wBAAwB,OAAO,MAAM,kBAAkB;AAEtE,eAAW,QAAQ,MAAM,GAAG,OAAO,kBAAkB,GACnD,QAAQ,MAAM,OAAO,iBAAiB,OAAO,SAAS,GACtD,OAAO,OACP,QAAQ,MAAM,OAAO,YAAY;;AAKrC,UAAO,EAAE,MAFM,wBAAwB,UAAU,kBAAkB,CAE7C,MAAM;;EAE/B;;AAGH,SAAS,YAAY,SASP;AAGZ,MAAK,MAAM,SAAS,QAAQ,SAFZ,6CAE6B,EAAE;AAC7C,MAAI,MAAM,UAAU,KAAA,KAAa,aAAa,KAAK,MAAM,MAAM,GAAG,CAChE;EAGF,MAAM,QAAQ,MAAM,MAAM;EAC1B,MAAM,eAAe,mDAClB,KAAK,MAAM;EACd,MAAM,WAAW,MAAM,QAAQ,MAAM,GAAG,QAAQ,IAAI,GAAG;EACvD,MAAM,aAAa,cAAc,SAAS,MAAM;EAChD,MAAM,WAAW,cAAc,eAAe,GAAG,UAAU;AAE3D,SAAO;GACL,MAAM,MAAM;GACZ;GACA,aAAa,MAAM,QAAQ,MAAM,GAAG,YAAY,IAAI;GACpD,YAAY,iBAAiB;GAC7B,mBAAmB,MAAM,QAAQ,IAAmB;GACpD,iBAAiB,MAAM,QAAQ,IAAmB;GACnD"}
|
package/.dist/vite.js
CHANGED
|
@@ -46,12 +46,13 @@ function make_remote_client_wrapper_plugin(options) {
|
|
|
46
46
|
},
|
|
47
47
|
configResolved(config) {
|
|
48
48
|
const no_external = config.ssr.noExternal;
|
|
49
|
+
const runtime_package = "svelte-effect-runtime";
|
|
49
50
|
if (no_external === true) return;
|
|
50
51
|
if (Array.isArray(no_external)) {
|
|
51
|
-
if (!no_external.
|
|
52
|
+
if (!no_external.some((entry) => entry === runtime_package)) no_external.push(runtime_package);
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
|
-
config.ssr.noExternal = [no_external,
|
|
55
|
+
config.ssr.noExternal = [no_external, runtime_package].filter((value) => value !== void 0);
|
|
55
56
|
},
|
|
56
57
|
transform(code, id) {
|
|
57
58
|
if (!is_remote_module(id) || !code.includes("__sveltekit/remote")) return;
|
package/.dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/vite.ts"],"sourcesContent":["import 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 /** Whether to emit debug logging in the generated remote client module. */\n debug?: boolean;\n}\n\n/**\n * Vite plugin for SvelteKit. The pre plugin rewrites server-side imports\n * to the server entrypoint; the post plugin wraps SvelteKit's generated\n * client remote exports in Effect-returning adapters.\n *\n * @example\n * ```ts\n * import { effect } from \"svelte-effect-runtime\";\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 return [\n make_server_rewrite_plugin(),\n make_remote_client_wrapper_plugin(options),\n ];\n}\n\nfunction make_server_rewrite_plugin(): Plugin {\n return {\n name: \"svelte-effect-runtime:server-imports\",\n enforce: \"pre\",\n\n config() {\n return { optimizeDeps: { exclude: [\"svelte-effect-runtime\"] } };\n },\n\n transform(code: string, id: string) {\n if (!is_server_runtime_module(id)) {\n return undefined;\n }\n\n const rewritten = code\n .replace(\n /from\\s+[\"']svelte-effect-runtime[\"']/g,\n `from \"svelte-effect-runtime/server\"`,\n )\n .replace(\n /from\\s+[\"']svelte-effect-runtime\\/internal\\/generators[\"']/g,\n `from \"svelte-effect-runtime/server\"`,\n );\n\n if (rewritten === code) {\n return undefined;\n }\n\n return { code: rewritten, map: null };\n },\n };\n}\n\nfunction make_remote_client_wrapper_plugin(options?: EffectOptions): Plugin {\n return {\n name: \"svelte-effect-runtime:remote-client\",\n enforce: \"post\",\n\n config() {\n return { ssr: { noExternal: [\"svelte-effect-runtime\"] } };\n },\n\n configResolved(config) {\n const no_external = config.ssr.noExternal;\n\n if (no_external === true) {\n return;\n }\n\n if (Array.isArray(no_external)) {\n
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/vite.ts"],"sourcesContent":["import 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 /** Whether to emit debug logging in the generated remote client module. */\n debug?: boolean;\n}\n\n/**\n * Vite plugin for SvelteKit. The pre plugin rewrites server-side imports\n * to the server entrypoint; the post plugin wraps SvelteKit's generated\n * client remote exports in Effect-returning adapters.\n *\n * @example\n * ```ts\n * import { effect } from \"svelte-effect-runtime\";\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 return [\n make_server_rewrite_plugin(),\n make_remote_client_wrapper_plugin(options),\n ];\n}\n\nfunction make_server_rewrite_plugin(): Plugin {\n return {\n name: \"svelte-effect-runtime:server-imports\",\n enforce: \"pre\",\n\n config() {\n return { optimizeDeps: { exclude: [\"svelte-effect-runtime\"] } };\n },\n\n transform(code: string, id: string) {\n if (!is_server_runtime_module(id)) {\n return undefined;\n }\n\n const rewritten = code\n .replace(\n /from\\s+[\"']svelte-effect-runtime[\"']/g,\n `from \"svelte-effect-runtime/server\"`,\n )\n .replace(\n /from\\s+[\"']svelte-effect-runtime\\/internal\\/generators[\"']/g,\n `from \"svelte-effect-runtime/server\"`,\n );\n\n if (rewritten === code) {\n return undefined;\n }\n\n return { code: rewritten, map: null };\n },\n };\n}\n\nfunction make_remote_client_wrapper_plugin(options?: EffectOptions): Plugin {\n return {\n name: \"svelte-effect-runtime:remote-client\",\n enforce: \"post\",\n\n config() {\n return { ssr: { noExternal: [\"svelte-effect-runtime\"] } };\n },\n\n configResolved(config) {\n const no_external = config.ssr.noExternal;\n const runtime_package = \"svelte-effect-runtime\";\n\n if (no_external === true) {\n return;\n }\n\n if (Array.isArray(no_external)) {\n const has_runtime_package = no_external.some(\n (entry) => entry === runtime_package,\n );\n\n if (!has_runtime_package) {\n no_external.push(runtime_package);\n }\n\n return;\n }\n\n config.ssr.noExternal = [\n no_external,\n runtime_package,\n ].filter((value): value is string | RegExp => value !== undefined);\n },\n\n transform(code: string, id: string) {\n if (!is_remote_module(id) || !code.includes(\"__sveltekit/remote\")) {\n return undefined;\n }\n\n const rewritten = rewrite_remote_client_exports(code, options);\n\n if (rewritten === code) {\n return undefined;\n }\n\n return { code: rewritten, map: null };\n },\n };\n}\n\nfunction is_server_runtime_module(id: string): boolean {\n return (\n id.endsWith(\".server.ts\") ||\n id.endsWith(\".remote.ts\") ||\n id.includes(\"hooks.server.\")\n );\n}\n\nfunction is_remote_module(id: string): boolean {\n return /\\.(remote|remote\\.[cm]?)\\.[jt]s(?:\\?.*)?$/.test(id) ||\n id.includes(\".remote.\");\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 * @since 2.0.0\n * @param code - The generated client remote module code.\n * @param options - Optional plugin options.\n * @returns The rewritten module code.\n * @internal\n */\nexport function rewrite_remote_client_exports(\n code: string,\n options?: EffectOptions,\n): string {\n const import_match = code.match(\n /import\\s+\\*\\s+as\\s+([A-Za-z_$][\\w$]*)\\s+from\\s+[\"']__sveltekit\\/remote[\"'];?/,\n );\n\n if (!import_match) {\n return code;\n }\n\n const namespace = import_match[1];\n const export_pattern = new RegExp(\n `export\\\\s+const\\\\s+([A-Za-z_$][\\\\w$]*)\\\\s*=\\\\s*${namespace}\\\\.(query_batch|query_live|query|command|form|prerender)\\\\(([\"'][^\"']+[\"'])\\\\);?`,\n \"g\",\n );\n\n let replaced_any = false;\n const body = code.replace(\n export_pattern,\n (_match, name, type, id_literal) => {\n replaced_any = true;\n\n return make_remote_export(name, type, id_literal, namespace);\n },\n );\n\n if (!replaced_any) {\n return code;\n }\n\n const imports = [\n `import { app_dir, base } from \"$app/paths/internal/client\";`,\n `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 ].join(\"\\n\");\n\n const helpers = [\n `const __ser_remote_base = \\`\\${base}/\\${app_dir}/remote\\`;`,\n `function __ser_decode_payload(value) { return value; }`,\n ].join(\"\\n\");\n\n const debug_line = options?.debug\n ? `console.log(\"[ser] remote client wrappers loaded\");`\n : \"\";\n\n const injected = [\n import_match[0],\n imports,\n helpers,\n debug_line,\n ].filter(Boolean).join(\"\\n\");\n\n return body.replace(import_match[0], injected);\n}\n\nfunction make_remote_export(\n name: string,\n type: string,\n id_literal: string,\n namespace: string,\n): string {\n const native_call = `${namespace}.${type}(${id_literal})`;\n\n if (type === \"command\") {\n return `export const ${name} = create_remote_command_adapter(${native_call}, __ser_decode_payload);`;\n }\n\n if (type === \"form\") {\n return `export const ${name} = create_remote_form_adapter(${native_call}, __ser_decode_payload, __ser_remote_base);`;\n }\n\n if (type === \"query_live\") {\n return `export const ${name} = create_remote_live_query_adapter(${native_call}, __ser_decode_payload);`;\n }\n\n return `export const ${name} = create_remote_query_adapter(${native_call}, __ser_decode_payload);`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA6BA,SAAgB,OAAO,SAAmC;AACxD,QAAO,CACL,4BAA4B,EAC5B,kCAAkC,QAAQ,CAC3C;;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
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "svelte-effect-runtime",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Core module that houses the Vite plugin to enable effectful execution.",
|
|
5
|
+
"license": "BSD-3-Clause",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/usebarekey/svelte-effect-runtime.git"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
".dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./.dist/mod.d.ts",
|
|
21
|
+
"default": "./.dist/mod.js"
|
|
22
|
+
},
|
|
23
|
+
"./server": {
|
|
24
|
+
"types": "./.dist/server.d.ts",
|
|
25
|
+
"default": "./.dist/server.js"
|
|
26
|
+
},
|
|
27
|
+
"./vite": {
|
|
28
|
+
"types": "./.dist/vite.d.ts",
|
|
29
|
+
"default": "./.dist/vite.js"
|
|
30
|
+
},
|
|
31
|
+
"./runtime/preprocess": {
|
|
32
|
+
"types": "./.dist/runtime/preprocess.d.ts",
|
|
33
|
+
"default": "./.dist/runtime/preprocess.js"
|
|
34
|
+
},
|
|
35
|
+
"./internal/generators": {
|
|
36
|
+
"types": "./.dist/internal/generators.d.ts",
|
|
37
|
+
"default": "./.dist/internal/generators.js"
|
|
38
|
+
},
|
|
39
|
+
"./internal/remote-client": {
|
|
40
|
+
"types": "./.dist/internal/remote-client.d.ts",
|
|
41
|
+
"default": "./.dist/internal/remote-client.js"
|
|
42
|
+
},
|
|
43
|
+
"./internal/remote-server": {
|
|
44
|
+
"types": "./.dist/internal/remote-server.d.ts",
|
|
45
|
+
"default": "./.dist/internal/remote-server.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "deno task build",
|
|
50
|
+
"check": "deno task check",
|
|
51
|
+
"clean": "deno task clean",
|
|
52
|
+
"test": "deno task test"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@sveltejs/kit": "^2.0.0",
|
|
56
|
+
"@sveltejs/vite-plugin-svelte": "^6.0.0 || ^7.0.0",
|
|
57
|
+
"effect": "^4.0.0-beta",
|
|
58
|
+
"svelte": "^5.0.0",
|
|
59
|
+
"vite": "^7.0.0 || ^8.0.0"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"devalue": "^5.5.0",
|
|
63
|
+
"magic-string": "^0.30.21",
|
|
64
|
+
"typescript": "^5.9.3"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@types/node": "^24.6.1",
|
|
68
|
+
"rolldown": "^1.0.0-rc.13"
|
|
69
|
+
}
|
|
70
|
+
}
|