@thomasfosterau/effect-sveltekit 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -0
  3. package/dist/Hooks.d.ts +33 -0
  4. package/dist/Hooks.js +34 -0
  5. package/dist/Hooks.js.map +1 -0
  6. package/dist/Navigation.d.ts +110 -0
  7. package/dist/Navigation.js +155 -0
  8. package/dist/Navigation.js.map +1 -0
  9. package/dist/Remote.d.ts +52 -0
  10. package/dist/Remote.js +67 -0
  11. package/dist/Remote.js.map +1 -0
  12. package/dist/State.d.ts +17 -0
  13. package/dist/State.js +65 -0
  14. package/dist/State.js.map +1 -0
  15. package/dist/_virtual/_rolldown/runtime.js +13 -0
  16. package/dist/adapter/handler.d.ts +67 -0
  17. package/dist/adapter/handler.js +158 -0
  18. package/dist/adapter/handler.js.map +1 -0
  19. package/dist/adapter/index.d.ts +29 -0
  20. package/dist/adapter/index.js +105 -0
  21. package/dist/adapter/index.js.map +1 -0
  22. package/dist/adapter/serve.d.ts +46 -0
  23. package/dist/adapter/serve.js +57 -0
  24. package/dist/adapter/serve.js.map +1 -0
  25. package/dist/app-runtime.d.ts +212 -0
  26. package/dist/app-runtime.js +173 -0
  27. package/dist/app-runtime.js.map +1 -0
  28. package/dist/client/Hooks.d.ts +48 -0
  29. package/dist/client/Hooks.js +61 -0
  30. package/dist/client/Hooks.js.map +1 -0
  31. package/dist/client.d.ts +6 -0
  32. package/dist/client.js +6 -0
  33. package/dist/config.d.ts +17 -0
  34. package/dist/config.js +51 -0
  35. package/dist/config.js.map +1 -0
  36. package/dist/index.d.ts +6 -0
  37. package/dist/index.js +6 -0
  38. package/dist/internal/app-state.d.ts +39 -0
  39. package/dist/internal/app-state.js +52 -0
  40. package/dist/internal/app-state.js.map +1 -0
  41. package/dist/internal/auto.d.ts +70 -0
  42. package/dist/internal/auto.js +161 -0
  43. package/dist/internal/auto.js.map +1 -0
  44. package/dist/internal/default-runtime.js +21 -0
  45. package/dist/internal/default-runtime.js.map +1 -0
  46. package/dist/internal/error.js +31 -0
  47. package/dist/internal/error.js.map +1 -0
  48. package/dist/internal/navigation-events.js +41 -0
  49. package/dist/internal/navigation-events.js.map +1 -0
  50. package/dist/remote-reactive.d.ts +38 -0
  51. package/dist/remote-reactive.js +44 -0
  52. package/dist/remote-reactive.js.map +1 -0
  53. package/dist/remote.server.d.ts +48 -0
  54. package/dist/remote.server.js +90 -0
  55. package/dist/remote.server.js.map +1 -0
  56. package/dist/runtime.d.ts +130 -0
  57. package/dist/runtime.js +143 -0
  58. package/dist/runtime.js.map +1 -0
  59. package/dist/server/Endpoint.d.ts +101 -0
  60. package/dist/server/Endpoint.js +109 -0
  61. package/dist/server/Endpoint.js.map +1 -0
  62. package/dist/server/Hooks.d.ts +97 -0
  63. package/dist/server/Hooks.js +108 -0
  64. package/dist/server/Hooks.js.map +1 -0
  65. package/dist/server.d.ts +108 -0
  66. package/dist/server.js +131 -0
  67. package/dist/server.js.map +1 -0
  68. package/dist/transport.d.ts +23 -0
  69. package/dist/transport.js +34 -0
  70. package/dist/transport.js.map +1 -0
  71. package/dist/universal.d.ts +35 -0
  72. package/dist/universal.js +36 -0
  73. package/dist/universal.js.map +1 -0
  74. package/dist/vite.d.ts +42 -0
  75. package/dist/vite.js +242 -0
  76. package/dist/vite.js.map +1 -0
  77. package/package.json +101 -0
package/dist/vite.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ import { Plugin } from "vite";
2
+
3
+ //#region src/vite.d.ts
4
+ type EffectKitFileKind = "pageServer" | "page" | "layoutServer" | "layout" | "server" | "hooks" | "hooksServer" | "hooksClient";
5
+ interface EffectKitPluginOptions {
6
+ /**
7
+ * Restrict transformation to a subset of SvelteKit file kinds.
8
+ * Defaults to all standard route files.
9
+ */
10
+ include?: ReadonlyArray<EffectKitFileKind>;
11
+ /**
12
+ * Import specifier of a server-only module whose `runtime` (or default)
13
+ * export is an app-wide runtime created with `makeServerRuntime`.
14
+ *
15
+ * When set, Effects returned from server route files (`+page.server.ts`,
16
+ * `+layout.server.ts`, `+server.ts`, `hooks.server.ts`) have access to the
17
+ * services of that runtime's layer.
18
+ *
19
+ * @example "$lib/server/runtime"
20
+ */
21
+ serverRuntime?: string;
22
+ /**
23
+ * Import specifier of a universal module whose `runtime` (or default)
24
+ * export is an app-wide runtime created with `makeUniversalRuntime`.
25
+ *
26
+ * When set, Effects returned from universal route files (`+page.ts`,
27
+ * `+layout.ts`, `hooks.client.ts`) have access to the services of that
28
+ * runtime's layer. The module must be safe to import in the browser.
29
+ *
30
+ * @example "$lib/runtime"
31
+ */
32
+ clientRuntime?: string;
33
+ }
34
+ /**
35
+ * Vite plugin that rewrites SvelteKit route exports so that Effects, or
36
+ * functions returning Effects, are accepted wherever SvelteKit expects a
37
+ * function-shaped export.
38
+ */
39
+ declare function effectKit(options?: EffectKitPluginOptions): Plugin;
40
+ //#endregion
41
+ export { EffectKitFileKind, EffectKitPluginOptions, effectKit as default, effectKit };
42
+ //# sourceMappingURL=vite.d.ts.map
package/dist/vite.js ADDED
@@ -0,0 +1,242 @@
1
+ import MagicString from "magic-string";
2
+ //#region src/vite.ts
3
+ /**
4
+ * Vite plugin that lets you write SvelteKit route exports as Effects (or
5
+ * functions returning Effects) without manually wrapping them.
6
+ *
7
+ * ```ts
8
+ * // vite.config.ts
9
+ * import { sveltekit } from "@sveltejs/kit/vite";
10
+ * import { effectKit } from "@thomasfosterau/effect-sveltekit/vite";
11
+ *
12
+ * export default {
13
+ * plugins: [effectKit(), sveltekit()],
14
+ * };
15
+ * ```
16
+ *
17
+ * ```ts
18
+ * // +page.server.ts
19
+ * import { Effect } from "effect";
20
+ * import * as HttpClient from "effect/unstable/http/HttpClient";
21
+ *
22
+ * export const load = (event) =>
23
+ * Effect.gen(function* () {
24
+ * const client = yield* HttpClient.HttpClient;
25
+ * return { hello: "world" };
26
+ * });
27
+ * ```
28
+ *
29
+ * Under the hood the plugin rewrites the export to call the same wrappers
30
+ * that the explicit API (`serverLoad`, `actions`, `handle`, `endpoint`, ...)
31
+ * uses. Plain functions that return promises or values pass through
32
+ * unchanged, so the plugin is safe to enable on existing projects.
33
+ */
34
+ const INTERNAL_IMPORT = "@thomasfosterau/effect-sveltekit/internal/auto";
35
+ const ORIG_PREFIX = "__effect_kit_orig_";
36
+ const RUNTIME_IDENT = "__effect_kit_runtime";
37
+ /** File kinds whose exports only ever run on the server. */
38
+ const serverKinds = new Set([
39
+ "pageServer",
40
+ "layoutServer",
41
+ "server",
42
+ "hooksServer"
43
+ ]);
44
+ const wrapperByKind = {
45
+ pageServer: {
46
+ load: "wrapServerLoad",
47
+ actions: "wrapActions"
48
+ },
49
+ page: { load: "wrapLoad" },
50
+ layoutServer: { load: "wrapServerLoad" },
51
+ layout: { load: "wrapLoad" },
52
+ server: {
53
+ GET: "wrapEndpoint",
54
+ POST: "wrapEndpoint",
55
+ PUT: "wrapEndpoint",
56
+ PATCH: "wrapEndpoint",
57
+ DELETE: "wrapEndpoint",
58
+ OPTIONS: "wrapEndpoint",
59
+ HEAD: "wrapEndpoint",
60
+ fallback: "wrapEndpoint"
61
+ },
62
+ hooksServer: {
63
+ handle: "wrapHandle",
64
+ handleFetch: "wrapHandleFetch",
65
+ handleError: "wrapHandleError",
66
+ init: "wrapInit"
67
+ },
68
+ hooksClient: {
69
+ handleError: "wrapHandleError",
70
+ init: "wrapInit"
71
+ },
72
+ hooks: { reroute: "wrapReroute" }
73
+ };
74
+ function getFileKind(id) {
75
+ const path = id.split("?")[0].replace(/\\/g, "/");
76
+ if (/\/\+page\.server\.(?:ts|js|mts|mjs)$/.test(path)) return "pageServer";
77
+ if (/\/\+page\.(?:ts|js|mts|mjs)$/.test(path)) return "page";
78
+ if (/\/\+layout\.server\.(?:ts|js|mts|mjs)$/.test(path)) return "layoutServer";
79
+ if (/\/\+layout\.(?:ts|js|mts|mjs)$/.test(path)) return "layout";
80
+ if (/\/\+server\.(?:ts|js|mts|mjs)$/.test(path)) return "server";
81
+ if (/\/hooks\.server\.(?:ts|js|mts|mjs)$/.test(path)) return "hooksServer";
82
+ if (/\/hooks\.client\.(?:ts|js|mts|mjs)$/.test(path)) return "hooksClient";
83
+ if (/\/hooks\.(?:ts|js|mts|mjs)$/.test(path)) return "hooks";
84
+ return null;
85
+ }
86
+ /**
87
+ * Returns a copy of `source` with line/block comments and string/template
88
+ * contents replaced by spaces (newlines preserved). Byte offsets in the
89
+ * returned string line up with the original, so regex scans don't trip on
90
+ * tokens inside comments or strings.
91
+ */
92
+ function maskCommentsAndStrings(source) {
93
+ const out = [];
94
+ let i = 0;
95
+ const len = source.length;
96
+ while (i < len) {
97
+ const c = source[i];
98
+ const next = source[i + 1];
99
+ if (c === "/" && next === "/") {
100
+ out.push(" ");
101
+ i += 2;
102
+ while (i < len && source[i] !== "\n") {
103
+ out.push(" ");
104
+ i++;
105
+ }
106
+ continue;
107
+ }
108
+ if (c === "/" && next === "*") {
109
+ out.push(" ");
110
+ i += 2;
111
+ while (i < len && !(source[i] === "*" && source[i + 1] === "/")) {
112
+ out.push(source[i] === "\n" ? "\n" : " ");
113
+ i++;
114
+ }
115
+ if (i < len) {
116
+ out.push(" ");
117
+ i += 2;
118
+ }
119
+ continue;
120
+ }
121
+ if (c === "\"" || c === "'") {
122
+ const quote = c;
123
+ out.push(quote);
124
+ i++;
125
+ while (i < len && source[i] !== quote) {
126
+ if (source[i] === "\\" && i + 1 < len) {
127
+ out.push(" ");
128
+ i += 2;
129
+ continue;
130
+ }
131
+ out.push(source[i] === "\n" ? "\n" : " ");
132
+ i++;
133
+ }
134
+ if (i < len) {
135
+ out.push(quote);
136
+ i++;
137
+ }
138
+ continue;
139
+ }
140
+ if (c === "`") {
141
+ out.push("`");
142
+ i++;
143
+ while (i < len && source[i] !== "`") {
144
+ if (source[i] === "\\" && i + 1 < len) {
145
+ out.push(" ");
146
+ i += 2;
147
+ continue;
148
+ }
149
+ if (source[i] === "$" && source[i + 1] === "{") {
150
+ out.push("${");
151
+ i += 2;
152
+ let depth = 1;
153
+ while (i < len && depth > 0) {
154
+ out.push(source[i]);
155
+ if (source[i] === "{") depth++;
156
+ else if (source[i] === "}") depth--;
157
+ i++;
158
+ }
159
+ continue;
160
+ }
161
+ out.push(source[i] === "\n" ? "\n" : " ");
162
+ i++;
163
+ }
164
+ if (i < len) {
165
+ out.push("`");
166
+ i++;
167
+ }
168
+ continue;
169
+ }
170
+ out.push(c);
171
+ i++;
172
+ }
173
+ return out.join("");
174
+ }
175
+ /**
176
+ * Find top-level `export const|let|var|function NAME` declarations whose
177
+ * NAME is in `targetNames`. Returns the slice of the original source to
178
+ * replace, along with a renamed declaration to put in its place.
179
+ *
180
+ * `export { NAME }`, `export default`, and destructuring forms are not
181
+ * supported — users who need them should use the explicit wrappers.
182
+ */
183
+ function findExports(masked, targetNames) {
184
+ const matches = [];
185
+ const pattern = /^[ \t]*(export)[ \t]+(?:async[ \t]+)?(?:const|let|var|function)[ \t]+([A-Za-z_$][\w$]*)/gm;
186
+ let m;
187
+ while (m = pattern.exec(masked)) {
188
+ const [full, , name] = m;
189
+ if (!targetNames.has(name)) continue;
190
+ const exportStart = m.index + full.indexOf("export");
191
+ const nameEnd = m.index + full.length;
192
+ const renamed = `${ORIG_PREFIX}${name}`;
193
+ const replacement = masked.slice(exportStart, nameEnd).replace(/^export[ \t]+/, "").replace(new RegExp(`\\b${name}$`), renamed);
194
+ matches.push({
195
+ name,
196
+ start: exportStart,
197
+ end: nameEnd,
198
+ replacement
199
+ });
200
+ }
201
+ return matches;
202
+ }
203
+ /**
204
+ * Vite plugin that rewrites SvelteKit route exports so that Effects, or
205
+ * functions returning Effects, are accepted wherever SvelteKit expects a
206
+ * function-shaped export.
207
+ */
208
+ function effectKit(options = {}) {
209
+ const include = options.include ? new Set(options.include) : null;
210
+ return {
211
+ name: "effect-kit",
212
+ enforce: "pre",
213
+ transform(code, id) {
214
+ const kind = getFileKind(id);
215
+ if (!kind) return null;
216
+ if (include && !include.has(kind)) return null;
217
+ const wrappers = wrapperByKind[kind];
218
+ const targetNames = new Set(Object.keys(wrappers));
219
+ const found = findExports(maskCommentsAndStrings(code), targetNames);
220
+ if (found.length === 0) return null;
221
+ const s = new MagicString(code);
222
+ for (const match of found) s.overwrite(match.start, match.end, match.replacement);
223
+ const wrapperImports = Array.from(new Set(found.map((m) => wrappers[m.name])));
224
+ const runtimeSpecifier = serverKinds.has(kind) ? options.serverRuntime : options.clientRuntime;
225
+ const imports = `\nimport { ${wrapperImports.join(", ")} } from ${JSON.stringify(INTERNAL_IMPORT)};\n` + (runtimeSpecifier ? `import * as ${RUNTIME_IDENT} from ${JSON.stringify(runtimeSpecifier)};\n` : "");
226
+ const runtimeArg = runtimeSpecifier ? `, ${RUNTIME_IDENT}` : "";
227
+ const exports = found.map((m) => `export const ${m.name} = ${wrappers[m.name]}(${ORIG_PREFIX}${m.name}${runtimeArg});`).join("\n");
228
+ s.append(`\n${imports}${exports}\n`);
229
+ return {
230
+ code: s.toString(),
231
+ map: s.generateMap({
232
+ hires: "boundary",
233
+ source: id
234
+ })
235
+ };
236
+ }
237
+ };
238
+ }
239
+ //#endregion
240
+ export { effectKit as default, effectKit };
241
+
242
+ //# sourceMappingURL=vite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["/**\n * Vite plugin that lets you write SvelteKit route exports as Effects (or\n * functions returning Effects) without manually wrapping them.\n *\n * ```ts\n * // vite.config.ts\n * import { sveltekit } from \"@sveltejs/kit/vite\";\n * import { effectKit } from \"@thomasfosterau/effect-sveltekit/vite\";\n *\n * export default {\n * plugins: [effectKit(), sveltekit()],\n * };\n * ```\n *\n * ```ts\n * // +page.server.ts\n * import { Effect } from \"effect\";\n * import * as HttpClient from \"effect/unstable/http/HttpClient\";\n *\n * export const load = (event) =>\n * Effect.gen(function* () {\n * const client = yield* HttpClient.HttpClient;\n * return { hello: \"world\" };\n * });\n * ```\n *\n * Under the hood the plugin rewrites the export to call the same wrappers\n * that the explicit API (`serverLoad`, `actions`, `handle`, `endpoint`, ...)\n * uses. Plain functions that return promises or values pass through\n * unchanged, so the plugin is safe to enable on existing projects.\n */\n\nimport MagicString from \"magic-string\";\nimport type { Plugin } from \"vite\";\n\nconst INTERNAL_IMPORT = \"@thomasfosterau/effect-sveltekit/internal/auto\";\nconst ORIG_PREFIX = \"__effect_kit_orig_\";\nconst RUNTIME_IDENT = \"__effect_kit_runtime\";\n\nexport type EffectKitFileKind =\n | \"pageServer\"\n | \"page\"\n | \"layoutServer\"\n | \"layout\"\n | \"server\"\n | \"hooks\"\n | \"hooksServer\"\n | \"hooksClient\";\n\n/** File kinds whose exports only ever run on the server. */\nconst serverKinds: ReadonlySet<EffectKitFileKind> = new Set([\n \"pageServer\",\n \"layoutServer\",\n \"server\",\n \"hooksServer\",\n]);\n\nconst wrapperByKind: Record<EffectKitFileKind, Record<string, string>> = {\n pageServer: { load: \"wrapServerLoad\", actions: \"wrapActions\" },\n page: { load: \"wrapLoad\" },\n layoutServer: { load: \"wrapServerLoad\" },\n layout: { load: \"wrapLoad\" },\n server: {\n GET: \"wrapEndpoint\",\n POST: \"wrapEndpoint\",\n PUT: \"wrapEndpoint\",\n PATCH: \"wrapEndpoint\",\n DELETE: \"wrapEndpoint\",\n OPTIONS: \"wrapEndpoint\",\n HEAD: \"wrapEndpoint\",\n fallback: \"wrapEndpoint\",\n },\n hooksServer: {\n handle: \"wrapHandle\",\n handleFetch: \"wrapHandleFetch\",\n handleError: \"wrapHandleError\",\n init: \"wrapInit\",\n },\n hooksClient: {\n handleError: \"wrapHandleError\",\n init: \"wrapInit\",\n },\n // Universal `src/hooks.ts`: only `reroute` is function-shaped (the `transport`\n // export is plain data and is intentionally left untouched).\n hooks: {\n reroute: \"wrapReroute\",\n },\n};\n\nfunction getFileKind(id: string): EffectKitFileKind | null {\n const path = id.split(\"?\")[0]!.replace(/\\\\/g, \"/\");\n if (/\\/\\+page\\.server\\.(?:ts|js|mts|mjs)$/.test(path)) return \"pageServer\";\n if (/\\/\\+page\\.(?:ts|js|mts|mjs)$/.test(path)) return \"page\";\n if (/\\/\\+layout\\.server\\.(?:ts|js|mts|mjs)$/.test(path)) return \"layoutServer\";\n if (/\\/\\+layout\\.(?:ts|js|mts|mjs)$/.test(path)) return \"layout\";\n if (/\\/\\+server\\.(?:ts|js|mts|mjs)$/.test(path)) return \"server\";\n if (/\\/hooks\\.server\\.(?:ts|js|mts|mjs)$/.test(path)) return \"hooksServer\";\n if (/\\/hooks\\.client\\.(?:ts|js|mts|mjs)$/.test(path)) return \"hooksClient\";\n // Plain `hooks.ts` is the universal hooks file; checked last so the\n // `.server.`/`.client.` variants above take precedence.\n if (/\\/hooks\\.(?:ts|js|mts|mjs)$/.test(path)) return \"hooks\";\n return null;\n}\n\n/**\n * Returns a copy of `source` with line/block comments and string/template\n * contents replaced by spaces (newlines preserved). Byte offsets in the\n * returned string line up with the original, so regex scans don't trip on\n * tokens inside comments or strings.\n */\nfunction maskCommentsAndStrings(source: string): string {\n const out: string[] = [];\n let i = 0;\n const len = source.length;\n\n while (i < len) {\n const c = source[i]!;\n const next = source[i + 1];\n\n if (c === \"/\" && next === \"/\") {\n out.push(\" \");\n i += 2;\n while (i < len && source[i] !== \"\\n\") {\n out.push(\" \");\n i++;\n }\n continue;\n }\n\n if (c === \"/\" && next === \"*\") {\n out.push(\" \");\n i += 2;\n while (i < len && !(source[i] === \"*\" && source[i + 1] === \"/\")) {\n out.push(source[i] === \"\\n\" ? \"\\n\" : \" \");\n i++;\n }\n if (i < len) {\n out.push(\" \");\n i += 2;\n }\n continue;\n }\n\n if (c === '\"' || c === \"'\") {\n const quote = c;\n out.push(quote);\n i++;\n while (i < len && source[i] !== quote) {\n if (source[i] === \"\\\\\" && i + 1 < len) {\n out.push(\" \");\n i += 2;\n continue;\n }\n out.push(source[i] === \"\\n\" ? \"\\n\" : \" \");\n i++;\n }\n if (i < len) {\n out.push(quote);\n i++;\n }\n continue;\n }\n\n if (c === \"`\") {\n out.push(\"`\");\n i++;\n while (i < len && source[i] !== \"`\") {\n if (source[i] === \"\\\\\" && i + 1 < len) {\n out.push(\" \");\n i += 2;\n continue;\n }\n if (source[i] === \"$\" && source[i + 1] === \"{\") {\n // Preserve template expression so nested strings are masked by\n // the outer loop.\n out.push(\"${\");\n i += 2;\n let depth = 1;\n while (i < len && depth > 0) {\n out.push(source[i]!);\n if (source[i] === \"{\") depth++;\n else if (source[i] === \"}\") depth--;\n i++;\n }\n continue;\n }\n out.push(source[i] === \"\\n\" ? \"\\n\" : \" \");\n i++;\n }\n if (i < len) {\n out.push(\"`\");\n i++;\n }\n continue;\n }\n\n out.push(c);\n i++;\n }\n\n return out.join(\"\");\n}\n\ninterface ExportMatch {\n name: string;\n start: number;\n end: number;\n replacement: string;\n}\n\n/**\n * Find top-level `export const|let|var|function NAME` declarations whose\n * NAME is in `targetNames`. Returns the slice of the original source to\n * replace, along with a renamed declaration to put in its place.\n *\n * `export { NAME }`, `export default`, and destructuring forms are not\n * supported — users who need them should use the explicit wrappers.\n */\nfunction findExports(masked: string, targetNames: ReadonlySet<string>): ExportMatch[] {\n const matches: ExportMatch[] = [];\n const pattern =\n /^[ \\t]*(export)[ \\t]+(?:async[ \\t]+)?(?:const|let|var|function)[ \\t]+([A-Za-z_$][\\w$]*)/gm;\n\n let m: RegExpExecArray | null;\n while ((m = pattern.exec(masked))) {\n const [full, , name] = m;\n if (!targetNames.has(name!)) continue;\n\n const exportStart = m.index + full.indexOf(\"export\");\n const nameEnd = m.index + full.length;\n const renamed = `${ORIG_PREFIX}${name}`;\n\n const slice = masked.slice(exportStart, nameEnd);\n const replacement = slice\n .replace(/^export[ \\t]+/, \"\")\n .replace(new RegExp(`\\\\b${name}$`), renamed);\n\n matches.push({ name: name!, start: exportStart, end: nameEnd, replacement });\n }\n\n return matches;\n}\n\nexport interface EffectKitPluginOptions {\n /**\n * Restrict transformation to a subset of SvelteKit file kinds.\n * Defaults to all standard route files.\n */\n include?: ReadonlyArray<EffectKitFileKind>;\n\n /**\n * Import specifier of a server-only module whose `runtime` (or default)\n * export is an app-wide runtime created with `makeServerRuntime`.\n *\n * When set, Effects returned from server route files (`+page.server.ts`,\n * `+layout.server.ts`, `+server.ts`, `hooks.server.ts`) have access to the\n * services of that runtime's layer.\n *\n * @example \"$lib/server/runtime\"\n */\n serverRuntime?: string;\n\n /**\n * Import specifier of a universal module whose `runtime` (or default)\n * export is an app-wide runtime created with `makeUniversalRuntime`.\n *\n * When set, Effects returned from universal route files (`+page.ts`,\n * `+layout.ts`, `hooks.client.ts`) have access to the services of that\n * runtime's layer. The module must be safe to import in the browser.\n *\n * @example \"$lib/runtime\"\n */\n clientRuntime?: string;\n}\n\n/**\n * Vite plugin that rewrites SvelteKit route exports so that Effects, or\n * functions returning Effects, are accepted wherever SvelteKit expects a\n * function-shaped export.\n */\nexport function effectKit(options: EffectKitPluginOptions = {}): Plugin {\n const include = options.include ? new Set(options.include) : null;\n\n return {\n name: \"effect-kit\",\n enforce: \"pre\",\n transform(code, id) {\n const kind = getFileKind(id);\n if (!kind) return null;\n if (include && !include.has(kind)) return null;\n\n const wrappers = wrapperByKind[kind];\n const targetNames = new Set(Object.keys(wrappers));\n\n const masked = maskCommentsAndStrings(code);\n const found = findExports(masked, targetNames);\n if (found.length === 0) return null;\n\n const s = new MagicString(code);\n\n for (const match of found) {\n s.overwrite(match.start, match.end, match.replacement);\n }\n\n const wrapperImports = Array.from(new Set(found.map((m) => wrappers[m.name]!)));\n\n // Server-only files get the server runtime module; universal/client\n // files get the client runtime module (it must be browser-safe).\n const runtimeSpecifier = serverKinds.has(kind)\n ? options.serverRuntime\n : options.clientRuntime;\n\n const imports =\n `\\nimport { ${wrapperImports.join(\", \")} } from ${JSON.stringify(INTERNAL_IMPORT)};\\n` +\n (runtimeSpecifier\n ? `import * as ${RUNTIME_IDENT} from ${JSON.stringify(runtimeSpecifier)};\\n`\n : \"\");\n const runtimeArg = runtimeSpecifier ? `, ${RUNTIME_IDENT}` : \"\";\n const exports = found\n .map(\n (m) =>\n `export const ${m.name} = ${wrappers[m.name]}(${ORIG_PREFIX}${m.name}${runtimeArg});`,\n )\n .join(\"\\n\");\n\n s.append(`\\n${imports}${exports}\\n`);\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: \"boundary\", source: id }),\n };\n },\n };\n}\n\nexport default effectKit;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,kBAAkB;AACxB,MAAM,cAAc;AACpB,MAAM,gBAAgB;;AAatB,MAAM,cAA8C,IAAI,IAAI;CAC1D;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,gBAAmE;CACvE,YAAY;EAAE,MAAM;EAAkB,SAAS;CAAc;CAC7D,MAAM,EAAE,MAAM,WAAW;CACzB,cAAc,EAAE,MAAM,iBAAiB;CACvC,QAAQ,EAAE,MAAM,WAAW;CAC3B,QAAQ;EACN,KAAK;EACL,MAAM;EACN,KAAK;EACL,OAAO;EACP,QAAQ;EACR,SAAS;EACT,MAAM;EACN,UAAU;CACZ;CACA,aAAa;EACX,QAAQ;EACR,aAAa;EACb,aAAa;EACb,MAAM;CACR;CACA,aAAa;EACX,aAAa;EACb,MAAM;CACR;CAGA,OAAO,EACL,SAAS,cACX;AACF;AAEA,SAAS,YAAY,IAAsC;CACzD,MAAM,OAAO,GAAG,MAAM,GAAG,EAAE,GAAI,QAAQ,OAAO,GAAG;CACjD,IAAI,uCAAuC,KAAK,IAAI,GAAG,OAAO;CAC9D,IAAI,+BAA+B,KAAK,IAAI,GAAG,OAAO;CACtD,IAAI,yCAAyC,KAAK,IAAI,GAAG,OAAO;CAChE,IAAI,iCAAiC,KAAK,IAAI,GAAG,OAAO;CACxD,IAAI,iCAAiC,KAAK,IAAI,GAAG,OAAO;CACxD,IAAI,sCAAsC,KAAK,IAAI,GAAG,OAAO;CAC7D,IAAI,sCAAsC,KAAK,IAAI,GAAG,OAAO;CAG7D,IAAI,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I,IAAI,GAAG,OAAO;GAE1C,MAAM,WAAW,cAAc;GAC/B,MAAM,cAAc,IAAI,IAAI,OAAO,KAAK,QAAQ,CAAC;GAGjD,MAAM,QAAQ,YADC,uBAAuB,IACP,GAAG,WAAW;GAC7C,IAAI,MAAM,WAAW,GAAG,OAAO;GAE/B,MAAM,IAAI,IAAI,YAAY,IAAI;GAE9B,KAAK,MAAM,SAAS,OAClB,EAAE,UAAU,MAAM,OAAO,MAAM,KAAK,MAAM,WAAW;GAGvD,MAAM,iBAAiB,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,MAAM,SAAS,EAAE,KAAM,CAAC,CAAC;GAI9E,MAAM,mBAAmB,YAAY,IAAI,IAAI,IACzC,QAAQ,gBACR,QAAQ;GAEZ,MAAM,UACJ,cAAc,eAAe,KAAK,IAAI,EAAE,UAAU,KAAK,UAAU,eAAe,EAAE,QACjF,mBACG,eAAe,cAAc,QAAQ,KAAK,UAAU,gBAAgB,EAAE,OACtE;GACN,MAAM,aAAa,mBAAmB,KAAK,kBAAkB;GAC7D,MAAM,UAAU,MACb,KACE,MACC,gBAAgB,EAAE,KAAK,KAAK,SAAS,EAAE,MAAM,GAAG,cAAc,EAAE,OAAO,WAAW,GACtF,EACC,KAAK,IAAI;GAEZ,EAAE,OAAO,KAAK,UAAU,QAAQ,GAAG;GAEnC,OAAO;IACL,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,YAAY;KAAE,OAAO;KAAY,QAAQ;IAAG,CAAC;GACtD;EACF;CACF;AACF"}
package/package.json ADDED
@@ -0,0 +1,101 @@
1
+ {
2
+ "name": "@thomasfosterau/effect-sveltekit",
3
+ "version": "0.0.0",
4
+ "description": "Effect integration for SvelteKit: load/action/endpoint wrappers, remote functions, an effectKit() Vite plugin, and an Effect HTTP deployment adapter",
5
+ "keywords": [
6
+ "effect",
7
+ "functional-programming",
8
+ "svelte",
9
+ "sveltekit",
10
+ "typescript",
11
+ "vite-plugin"
12
+ ],
13
+ "homepage": "https://github.com/thomasfosterau/effect-svelte/tree/main/packages/sveltekit#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/thomasfosterau/effect-svelte/issues"
16
+ },
17
+ "license": "MIT",
18
+ "author": "Thomas Foster",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/thomasfosterau/effect-svelte.git",
22
+ "directory": "packages/sveltekit"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "type": "module",
30
+ "main": "./dist/index.js",
31
+ "module": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js"
37
+ },
38
+ "./server": {
39
+ "types": "./dist/server.d.ts",
40
+ "import": "./dist/server.js"
41
+ },
42
+ "./client": {
43
+ "types": "./dist/client.d.ts",
44
+ "import": "./dist/client.js"
45
+ },
46
+ "./vite": {
47
+ "types": "./dist/vite.d.ts",
48
+ "import": "./dist/vite.js"
49
+ },
50
+ "./adapter": {
51
+ "types": "./dist/adapter/index.d.ts",
52
+ "import": "./dist/adapter/index.js"
53
+ },
54
+ "./adapter/handler": {
55
+ "types": "./dist/adapter/handler.d.ts",
56
+ "import": "./dist/adapter/handler.js"
57
+ },
58
+ "./adapter/serve": {
59
+ "types": "./dist/adapter/serve.d.ts",
60
+ "import": "./dist/adapter/serve.js"
61
+ },
62
+ "./internal/auto": {
63
+ "types": "./dist/internal/auto.d.ts",
64
+ "import": "./dist/internal/auto.js"
65
+ }
66
+ },
67
+ "publishConfig": {
68
+ "access": "public"
69
+ },
70
+ "dependencies": {
71
+ "@standard-schema/spec": "^1.1.0",
72
+ "magic-string": "^0.30.0",
73
+ "@thomasfosterau/effect-svelte": "^0.0.0"
74
+ },
75
+ "peerDependencies": {
76
+ "@effect/platform-node": "^4.0.0-beta.75",
77
+ "@sveltejs/kit": "^2.0.0",
78
+ "effect": "^4.0.0-beta.75",
79
+ "svelte": "^5.40.0",
80
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
81
+ },
82
+ "peerDependenciesMeta": {
83
+ "@effect/platform-node": {
84
+ "optional": true
85
+ },
86
+ "@sveltejs/kit": {
87
+ "optional": true
88
+ },
89
+ "vite": {
90
+ "optional": true
91
+ }
92
+ },
93
+ "engines": {
94
+ "node": "^20.19.0 || >=22.12.0"
95
+ },
96
+ "scripts": {
97
+ "build": "vp pack",
98
+ "test": "vp test",
99
+ "clean": "rm -rf dist"
100
+ }
101
+ }