svelte-effect-runtime 2.5.0 → 2.5.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.
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { t as transform_markup_effect } from "./transform-Cx5bjmP6.js";
|
|
2
2
|
import { t as transform_script_effect } from "./preprocess-DseI9Doo.js";
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __exportAll = (all, no_symbols) => {
|
|
6
|
+
let target = {};
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
11
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
12
|
+
return target;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
3
15
|
//#region src/runtime/transform.ts
|
|
16
|
+
var transform_exports = /* @__PURE__ */ __exportAll({ transform_svelte_effect: () => transform_svelte_effect });
|
|
4
17
|
/**
|
|
5
18
|
* Lowers SER syntax in a complete Svelte component without using Svelte's
|
|
6
19
|
* preprocessor adapter API.
|
|
@@ -54,6 +67,6 @@ function has_typescript_lang(attrs) {
|
|
|
54
67
|
return lang === "ts" || lang === "typescript";
|
|
55
68
|
}
|
|
56
69
|
//#endregion
|
|
57
|
-
export { transform_svelte_effect as t };
|
|
70
|
+
export { transform_svelte_effect as n, transform_exports as t };
|
|
58
71
|
|
|
59
|
-
//# sourceMappingURL=transform-
|
|
72
|
+
//# sourceMappingURL=transform-BotzDlj3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-
|
|
1
|
+
{"version":3,"file":"transform-BotzDlj3.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/runtime/transform.ts"],"sourcesContent":["import { transform_markup_effect } from \"$/markup/transform.ts\";\nimport { transform_script_effect } from \"$/preprocess.ts\";\n\n/**\n * Result returned by the direct whole-file Svelte transform.\n *\n * @example\n * ```ts\n * const result = transform_svelte_effect(\"<p>{yield* load()}</p>\", \"App.svelte\");\n * result.code;\n * ```\n *\n * @since 2.5.0\n */\nexport interface SvelteTransformResult {\n /** Transformed Svelte source. */\n code: string;\n}\n\n/**\n * Lowers SER syntax in a complete Svelte component without using Svelte's\n * preprocessor adapter API.\n *\n * @example\n * ```ts\n * const result = transform_svelte_effect(\n * \"<script effect>const value = yield* load()</script>\",\n * \"App.svelte\",\n * );\n * ```\n *\n * @since 2.5.0\n * @param content - Full Svelte component source to lower before Svelte parses\n * it.\n * @param filename - Component filename used in generated cache identifiers and\n * diagnostics.\n * @returns The transformed component source.\n */\nexport function transform_svelte_effect(\n content: string,\n filename = \"unknown.svelte\",\n): SvelteTransformResult {\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, filename, {\n emit_types: script.is_typescript,\n });\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, filename);\n\n return { code: result.code };\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 is_typescript: boolean;\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 is_typescript: has_typescript_lang(attrs),\n };\n }\n\n return undefined;\n}\n\nfunction has_typescript_lang(attrs: string): boolean {\n const lang_match = /\\blang\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s>]+))/i.exec(\n attrs,\n );\n const lang = (lang_match?.[1] ?? lang_match?.[2] ?? lang_match?.[3] ?? \"\")\n .toLowerCase();\n\n return lang === \"ts\" || lang === \"typescript\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,wBACd,SACA,WAAW,kBACY;CACvB,MAAM,SAAS,YAAY,OAAO;CAElC,IAAI,WAAW;CAEf,IAAI,QAAQ,YAAY;EACtB,MAAM,SAAS,wBAAwB,OAAO,MAAM,UAAU,EAC5D,YAAY,OAAO,cACrB,CAAC;EAED,WAAW,QAAQ,MAAM,GAAG,OAAO,iBAAiB,IAClD,QAAQ,MAAM,OAAO,iBAAiB,OAAO,QAAQ,IACrD,OAAO,OACP,QAAQ,MAAM,OAAO,WAAW;CACpC;CAIA,OAAO,EAAE,MAFM,wBAAwB,UAAU,QAE7B,EAAE,KAAK;AAC7B;AAEA,SAAS,YAAY,SAUP;CAGZ,KAAK,MAAM,SAAS,QAAQ,SAAS,4CAAO,GAAG;EAC7C,IAAI,MAAM,UAAU,KAAA,KAAa,aAAa,KAAK,MAAM,MAAM,EAAE,GAC/D;EAGF,MAAM,QAAQ,MAAM,MAAM;EAC1B,MAAM,eAAe,mDAClB,KAAK,KAAK;EACb,MAAM,WAAW,MAAM,QAAQ,MAAM,GAAG,QAAQ,GAAG,IAAI;EACvD,MAAM,aAAa,cAAc,SAAS,MAAM;EAChD,MAAM,WAAW,cAAc,eAAe,GAAG,UAAU;EAE3D,OAAO;GACL,MAAM,MAAM;GACZ;GACA,aAAa,MAAM,QAAQ,MAAM,GAAG,YAAY,GAAG;GACnD,YAAY,iBAAiB;GAC7B,mBAAmB,MAAM,QAAQ,IAAmB;GACpD,iBAAiB,MAAM,QAAQ,IAAmB;GAClD,eAAe,oBAAoB,KAAK;EAC1C;CACF;AAGF;AAEA,SAAS,oBAAoB,OAAwB;CACnD,MAAM,aAAa,kDAAkD,KACnE,KACF;CACA,MAAM,QAAQ,aAAa,MAAM,aAAa,MAAM,aAAa,MAAM,IACpE,YAAY;CAEf,OAAO,SAAS,QAAQ,SAAS;AACnC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { n as transform_svelte_effect } from "../chunks/transform-BotzDlj3.js";
|
|
1
2
|
import { t as transform_markup_effect } from "../chunks/transform-Cx5bjmP6.js";
|
|
2
3
|
import { t as transform_script_effect } from "../chunks/preprocess-DseI9Doo.js";
|
|
3
|
-
import { t as transform_svelte_effect } from "../chunks/transform-BDfspL1K.js";
|
|
4
4
|
//#region src/runtime/preprocess.ts
|
|
5
5
|
/**
|
|
6
6
|
* Svelte preprocessor that lowers `yield*` in script and markup blocks.
|
package/.dist/vite.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { t as transform_svelte_effect } from "./chunks/transform-BDfspL1K.js";
|
|
2
1
|
//#region src/vite.ts
|
|
3
2
|
/**
|
|
4
3
|
* Vite plugin for SvelteKit. The pre plugin rewrites server-side imports
|
|
@@ -30,8 +29,9 @@ function make_svelte_transform_plugin() {
|
|
|
30
29
|
enforce: "pre",
|
|
31
30
|
transform: {
|
|
32
31
|
order: "pre",
|
|
33
|
-
handler(code, id) {
|
|
32
|
+
async handler(code, id) {
|
|
34
33
|
if (!is_svelte_component_module(id)) return;
|
|
34
|
+
const { transform_svelte_effect } = await import("./chunks/transform-BotzDlj3.js").then((n) => n.t);
|
|
35
35
|
const result = transform_svelte_effect(code, id);
|
|
36
36
|
if (result.code === code) return;
|
|
37
37
|
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 { transform_svelte_effect } from \"./runtime/transform.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 /** 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_svelte_transform_plugin(),\n make_server_rewrite_plugin(),\n make_remote_client_wrapper_plugin(options),\n ];\n}\n\nfunction make_svelte_transform_plugin(): Plugin {\n return {\n name: \"svelte-effect-runtime:svelte-transform\",\n enforce: \"pre\",\n\n transform: {\n order: \"pre\",\n handler(code: string, id: string) {\n if (!is_svelte_component_module(id)) {\n return undefined;\n }\n\n const result = transform_svelte_effect(code, id);\n\n if (result.code === code) {\n return undefined;\n }\n\n return { code: result.code, map: null };\n },\n },\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\nfunction is_svelte_component_module(id: string): boolean {\n const [filename, query = \"\"] = id.split(\"?\", 2);\n\n if (!filename.endsWith(\".svelte\")) {\n return false;\n }\n\n if (query.length === 0) {\n return true;\n }\n\n const params = new URLSearchParams(query);\n const allowed_params = [\"t\", \"v\"];\n\n return [...params.keys()].every((key) => allowed_params.includes(key));\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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F,EAAE,KAAK,IAAI;CAEX,MAAM,aAAa,SAAS,QACxB,wDACA;CAEJ,MAAM,WAAW;EACf,aAAa;EACb;EACA;EACA;CACF,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI;CAE3B,OAAO,KAAK,QAAQ,aAAa,IAAI,QAAQ;AAC/C;AAEA,SAAS,mBACP,MACA,MACA,YACA,WACQ;CACR,MAAM,cAAc,GAAG,UAAU,GAAG,KAAK,GAAG,WAAW;CAEvD,IAAI,SAAS,WACX,OAAO,gBAAgB,KAAK,mCAAmC,YAAY;CAG7E,IAAI,SAAS,QACX,OAAO,gBAAgB,KAAK,gCAAgC,YAAY;CAG1E,IAAI,SAAS,cACX,OAAO,gBAAgB,KAAK,sCAAsC,YAAY;CAGhF,OAAO,gBAAgB,KAAK,iCAAiC,YAAY;AAC3E"}
|
|
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_svelte_transform_plugin(),\n make_server_rewrite_plugin(),\n make_remote_client_wrapper_plugin(options),\n ];\n}\n\nfunction make_svelte_transform_plugin(): Plugin {\n return {\n name: \"svelte-effect-runtime:svelte-transform\",\n enforce: \"pre\",\n\n transform: {\n order: \"pre\",\n async handler(code: string, id: string) {\n if (!is_svelte_component_module(id)) {\n return undefined;\n }\n\n const { transform_svelte_effect } = await import(\n \"./runtime/transform.ts\"\n );\n const result = transform_svelte_effect(code, id);\n\n if (result.code === code) {\n return undefined;\n }\n\n return { code: result.code, map: null };\n },\n },\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\nfunction is_svelte_component_module(id: string): boolean {\n const [filename, query = \"\"] = id.split(\"?\", 2);\n\n if (!filename.endsWith(\".svelte\")) {\n return false;\n }\n\n if (query.length === 0) {\n return true;\n }\n\n const params = new URLSearchParams(query);\n const allowed_params = [\"t\", \"v\"];\n\n return [...params.keys()].every((key) => allowed_params.includes(key));\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;CACxD,OAAO;EACL,6BAA6B;EAC7B,2BAA2B;EAC3B,kCAAkC,OAAO;CAC3C;AACF;AAEA,SAAS,+BAAuC;CAC9C,OAAO;EACL,MAAM;EACN,SAAS;EAET,WAAW;GACT,OAAO;GACP,MAAM,QAAQ,MAAc,IAAY;IACtC,IAAI,CAAC,2BAA2B,EAAE,GAChC;IAGF,MAAM,EAAE,4BAA4B,MAAM,OACxC,kCAAA,MAAA,MAAA,EAAA,CAAA;IAEF,MAAM,SAAS,wBAAwB,MAAM,EAAE;IAE/C,IAAI,OAAO,SAAS,MAClB;IAGF,OAAO;KAAE,MAAM,OAAO;KAAM,KAAK;IAAK;GACxC;EACF;CACF;AACF;AAEA,SAAS,6BAAqC;CAC5C,OAAO;EACL,MAAM;EACN,SAAS;EAET,SAAS;GACP,OAAO,EAAE,cAAc,EAAE,SAAS,CAAC,uBAAuB,EAAE,EAAE;EAChE;EAEA,UAAU,MAAc,IAA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