@catmint/vite 0.0.0-prealpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +339 -0
- package/dist/boundary.d.ts +15 -0
- package/dist/boundary.d.ts.map +1 -0
- package/dist/boundary.js +193 -0
- package/dist/boundary.js.map +1 -0
- package/dist/build-entries.d.ts +81 -0
- package/dist/build-entries.d.ts.map +1 -0
- package/dist/build-entries.js +1139 -0
- package/dist/build-entries.js.map +1 -0
- package/dist/cors-utils.d.ts +22 -0
- package/dist/cors-utils.d.ts.map +1 -0
- package/dist/cors-utils.js +36 -0
- package/dist/cors-utils.js.map +1 -0
- package/dist/dev-server.d.ts +34 -0
- package/dist/dev-server.d.ts.map +1 -0
- package/dist/dev-server.js +1683 -0
- package/dist/dev-server.js.map +1 -0
- package/dist/env-transform.d.ts +16 -0
- package/dist/env-transform.d.ts.map +1 -0
- package/dist/env-transform.js +125 -0
- package/dist/env-transform.js.map +1 -0
- package/dist/error-page.d.ts +19 -0
- package/dist/error-page.d.ts.map +1 -0
- package/dist/error-page.js +152 -0
- package/dist/error-page.js.map +1 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +100 -0
- package/dist/index.js.map +1 -0
- package/dist/mdx-transform.d.ts +33 -0
- package/dist/mdx-transform.d.ts.map +1 -0
- package/dist/mdx-transform.js +86 -0
- package/dist/mdx-transform.js.map +1 -0
- package/dist/middleware.d.ts +13 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +155 -0
- package/dist/middleware.js.map +1 -0
- package/dist/resolve-utils.d.ts +17 -0
- package/dist/resolve-utils.d.ts.map +1 -0
- package/dist/resolve-utils.js +51 -0
- package/dist/resolve-utils.js.map +1 -0
- package/dist/route-gen.d.ts +12 -0
- package/dist/route-gen.d.ts.map +1 -0
- package/dist/route-gen.js +221 -0
- package/dist/route-gen.js.map +1 -0
- package/dist/server-fn-transform.d.ts +12 -0
- package/dist/server-fn-transform.d.ts.map +1 -0
- package/dist/server-fn-transform.js +394 -0
- package/dist/server-fn-transform.js.map +1 -0
- package/dist/utils.d.ts +56 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +198 -0
- package/dist/utils.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-fn-transform.d.ts","sourceRoot":"","sources":["../src/server-fn-transform.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AAOnD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CA+DhD"}
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
// @catmint/vite/server-fn-transform — Server function compilation
|
|
2
|
+
//
|
|
3
|
+
// Handles:
|
|
4
|
+
// - Transforming createServerFn imports to fetch stubs in client bundle
|
|
5
|
+
// - Hashing function names deterministically
|
|
6
|
+
// - Inline async handler extraction for event handler props
|
|
7
|
+
//
|
|
8
|
+
// Uses SWC for AST parsing and MagicString for source-map-safe replacements,
|
|
9
|
+
// replacing the previous regex-based approach.
|
|
10
|
+
import { parseSync } from "@swc/core";
|
|
11
|
+
import MagicString from "magic-string";
|
|
12
|
+
import { isServerFnFile, deterministicHash, toPosixPath } from "./utils.js";
|
|
13
|
+
// ─── Plugin ──────────────────────────────────────────────────────────────────
|
|
14
|
+
/**
|
|
15
|
+
* Create the server function transform Vite plugin.
|
|
16
|
+
*
|
|
17
|
+
* In client bundles, `createServerFn` calls are transformed into `fetch()` stubs.
|
|
18
|
+
* The function name is hashed to produce a stable, opaque endpoint identifier.
|
|
19
|
+
*
|
|
20
|
+
* Additionally, inline async handlers on event props (`onClick`, `onSubmit`, etc.)
|
|
21
|
+
* in server components are extracted and compiled to server function fetch stubs.
|
|
22
|
+
*/
|
|
23
|
+
export function serverFnTransformPlugin() {
|
|
24
|
+
let root = "";
|
|
25
|
+
return {
|
|
26
|
+
name: "catmint:server-fn-transform",
|
|
27
|
+
enforce: "pre",
|
|
28
|
+
configResolved(config) {
|
|
29
|
+
root = config.root;
|
|
30
|
+
},
|
|
31
|
+
transform(code, id) {
|
|
32
|
+
// Detect server-side environment at transform time.
|
|
33
|
+
// In Vite 6 multi-environment mode, `this.environment` provides
|
|
34
|
+
// the current environment. In single-environment mode, fall back
|
|
35
|
+
// to the config's build.ssr flag.
|
|
36
|
+
const env = this.environment;
|
|
37
|
+
const isServer = env?.name === "rsc" ||
|
|
38
|
+
env?.name === "ssr" ||
|
|
39
|
+
env?.config?.consumer === "server" ||
|
|
40
|
+
!!env?.config?.build?.ssr;
|
|
41
|
+
// Only transform in client builds — on the server, .fn.ts files
|
|
42
|
+
// should execute directly (no RPC stubs).
|
|
43
|
+
if (isServer)
|
|
44
|
+
return null;
|
|
45
|
+
// Skip MDX files — they are raw markdown at this stage and must be
|
|
46
|
+
// compiled to JSX by the MDX plugin before any JS transforms apply.
|
|
47
|
+
if (id.endsWith(".mdx"))
|
|
48
|
+
return null;
|
|
49
|
+
// --- Transform .fn.ts files into fetch stubs in client bundles ---
|
|
50
|
+
if (isServerFnFile(id)) {
|
|
51
|
+
const result = transformServerFnModule(code, id, root);
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
let s;
|
|
55
|
+
// --- Transform createServerFn calls in non-.fn.ts files ---
|
|
56
|
+
if (/\bcreateServerFn\b/.test(code)) {
|
|
57
|
+
s = transformInlineCreateServerFn(code, id, root);
|
|
58
|
+
}
|
|
59
|
+
// --- Inline async handler extraction ---
|
|
60
|
+
if (/\bon[A-Z]/.test(code)) {
|
|
61
|
+
const handlerResult = transformInlineAsyncHandlers(s ? s.toString() : code, id, root);
|
|
62
|
+
if (handlerResult) {
|
|
63
|
+
s = handlerResult;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (s) {
|
|
67
|
+
return { code: s.toString(), map: s.generateMap({ hires: true }) };
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
74
|
+
/**
|
|
75
|
+
* Generate a fetch stub function body for a server function endpoint.
|
|
76
|
+
*/
|
|
77
|
+
function makeFetchStub(endpoint) {
|
|
78
|
+
return (` const res = await fetch(${JSON.stringify(endpoint)}, {\n` +
|
|
79
|
+
` method: "POST",\n` +
|
|
80
|
+
` headers: { "Content-Type": "application/json" },\n` +
|
|
81
|
+
` body: JSON.stringify(input),\n` +
|
|
82
|
+
` });\n` +
|
|
83
|
+
` if (!res.ok) throw new Error(\`Server function failed: \${res.status}\`);\n` +
|
|
84
|
+
` return res.json();`);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Compute the relative path for a module, in posix form.
|
|
88
|
+
*/
|
|
89
|
+
function getRelativePath(id, root) {
|
|
90
|
+
const posixId = toPosixPath(id);
|
|
91
|
+
const posixRoot = toPosixPath(root);
|
|
92
|
+
return posixId.startsWith(posixRoot)
|
|
93
|
+
? posixId.slice(posixRoot.length + 1)
|
|
94
|
+
: posixId;
|
|
95
|
+
}
|
|
96
|
+
// ─── Generic AST Walker ─────────────────────────────────────────────────────
|
|
97
|
+
/**
|
|
98
|
+
* Recursively walk an SWC AST node tree, calling `visitor` for every node
|
|
99
|
+
* that has a `type` property. This is necessary because the SWC JS API does
|
|
100
|
+
* not expose a built-in visitor/walker.
|
|
101
|
+
*/
|
|
102
|
+
function walkSwcAst(node, visitor, parent) {
|
|
103
|
+
if (!node || typeof node !== "object")
|
|
104
|
+
return;
|
|
105
|
+
visitor(node, parent);
|
|
106
|
+
for (const key of Object.keys(node)) {
|
|
107
|
+
if (key === "span")
|
|
108
|
+
continue; // skip span objects — not AST nodes
|
|
109
|
+
const child = node[key];
|
|
110
|
+
if (Array.isArray(child)) {
|
|
111
|
+
for (const item of child) {
|
|
112
|
+
if (item && typeof item === "object" && item.type) {
|
|
113
|
+
walkSwcAst(item, visitor, node);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (child && typeof child === "object" && child.type) {
|
|
118
|
+
walkSwcAst(child, visitor, node);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Convert an SWC byte-offset span position to a 0-based character offset
|
|
124
|
+
* suitable for MagicString. SWC spans are absolute byte offsets; we subtract
|
|
125
|
+
* the module's span.start (which is typically 0, but we stay safe).
|
|
126
|
+
*/
|
|
127
|
+
function offsetOf(pos, moduleSpanStart) {
|
|
128
|
+
return pos - moduleSpanStart;
|
|
129
|
+
}
|
|
130
|
+
// ─── Identifier extraction helpers ──────────────────────────────────────────
|
|
131
|
+
/**
|
|
132
|
+
* Extract the string name from an SWC Identifier, MemberExpression callee,
|
|
133
|
+
* or similar node. Returns undefined if it cannot be resolved to a simple name.
|
|
134
|
+
*/
|
|
135
|
+
function getIdentName(node) {
|
|
136
|
+
if (!node)
|
|
137
|
+
return undefined;
|
|
138
|
+
if (node.type === "Identifier")
|
|
139
|
+
return node.value;
|
|
140
|
+
// SWC sometimes nests the name differently
|
|
141
|
+
if (typeof node.value === "string")
|
|
142
|
+
return node.value;
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Check if a CallExpression's callee is `createServerFn`.
|
|
147
|
+
*/
|
|
148
|
+
function isCreateServerFnCall(callExpr) {
|
|
149
|
+
if (callExpr.type !== "CallExpression")
|
|
150
|
+
return false;
|
|
151
|
+
return getIdentName(callExpr.callee) === "createServerFn";
|
|
152
|
+
}
|
|
153
|
+
// ─── Transform: .fn.ts module → full replacement ────────────────────────────
|
|
154
|
+
/**
|
|
155
|
+
* Transform an entire .fn.ts module into client-side fetch stubs.
|
|
156
|
+
*
|
|
157
|
+
* For `.fn.ts` files in client builds, the ENTIRE module content is replaced
|
|
158
|
+
* with fetch stubs for each exported name. We parse with SWC to reliably
|
|
159
|
+
* find all exports rather than relying on regex.
|
|
160
|
+
*/
|
|
161
|
+
function transformServerFnModule(code, id, root) {
|
|
162
|
+
const relativePath = getRelativePath(id, root);
|
|
163
|
+
const ast = parseSync(code, {
|
|
164
|
+
syntax: "typescript",
|
|
165
|
+
tsx: id.endsWith(".tsx") || id.endsWith(".jsx"),
|
|
166
|
+
target: "es2022",
|
|
167
|
+
});
|
|
168
|
+
const exportedNames = new Set();
|
|
169
|
+
for (const item of ast.body) {
|
|
170
|
+
// export const foo = ..., export let bar = ...
|
|
171
|
+
if (item.type === "ExportDeclaration" &&
|
|
172
|
+
item.declaration.type === "VariableDeclaration") {
|
|
173
|
+
for (const decl of item.declaration.declarations) {
|
|
174
|
+
const name = getIdentName(decl.id);
|
|
175
|
+
if (name)
|
|
176
|
+
exportedNames.add(name);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// export function foo(...) { ... }
|
|
180
|
+
if (item.type === "ExportDeclaration" &&
|
|
181
|
+
item.declaration.type === "FunctionDeclaration") {
|
|
182
|
+
const name = getIdentName(item.declaration.identifier);
|
|
183
|
+
if (name)
|
|
184
|
+
exportedNames.add(name);
|
|
185
|
+
}
|
|
186
|
+
// export { foo, bar }
|
|
187
|
+
// export { foo as bar }
|
|
188
|
+
if (item.type === "ExportNamedDeclaration" && item.specifiers) {
|
|
189
|
+
for (const spec of item.specifiers) {
|
|
190
|
+
if (spec.type === "ExportSpecifier") {
|
|
191
|
+
// The exported name is `exported`, fallback to `orig`
|
|
192
|
+
const name = getIdentName(spec.exported) || getIdentName(spec.orig);
|
|
193
|
+
if (name)
|
|
194
|
+
exportedNames.add(name);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// export default ... — use "default" as the name
|
|
199
|
+
if (item.type === "ExportDefaultDeclaration") {
|
|
200
|
+
exportedNames.add("default");
|
|
201
|
+
}
|
|
202
|
+
if (item.type === "ExportDefaultExpression") {
|
|
203
|
+
exportedNames.add("default");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (exportedNames.size === 0) {
|
|
207
|
+
// No exports found — return original code unchanged
|
|
208
|
+
return { code, map: null };
|
|
209
|
+
}
|
|
210
|
+
const stubs = [];
|
|
211
|
+
for (const fnName of exportedNames) {
|
|
212
|
+
const hash = deterministicHash(`${relativePath}:${fnName}`);
|
|
213
|
+
const basePath = relativePath.replace(/\.(fn\.ts|fn\.tsx?)$/, "");
|
|
214
|
+
const endpoint = `/__catmint/fn/${basePath}/${hash}`;
|
|
215
|
+
if (fnName === "default") {
|
|
216
|
+
stubs.push(`export default async function (input) {\n${makeFetchStub(endpoint)}\n}`);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
stubs.push(`export async function ${fnName}(input) {\n${makeFetchStub(endpoint)}\n}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const newCode = `// Auto-generated client stubs for server functions\n${stubs.join("\n\n")}\n`;
|
|
223
|
+
return { code: newCode, map: null };
|
|
224
|
+
}
|
|
225
|
+
// ─── Transform: inline createServerFn calls ─────────────────────────────────
|
|
226
|
+
/**
|
|
227
|
+
* Transform inline `createServerFn(...)` calls that are not in .fn.ts files.
|
|
228
|
+
*
|
|
229
|
+
* Walks the AST to find VariableDeclarator nodes whose initializer is a
|
|
230
|
+
* CallExpression with callee `createServerFn`. Replaces the call with a
|
|
231
|
+
* fetch stub using MagicString.
|
|
232
|
+
*
|
|
233
|
+
* Returns a MagicString if any replacements were made, or undefined.
|
|
234
|
+
*/
|
|
235
|
+
function transformInlineCreateServerFn(code, id, root) {
|
|
236
|
+
const relativePath = getRelativePath(id, root);
|
|
237
|
+
const ast = parseSync(code, {
|
|
238
|
+
syntax: "typescript",
|
|
239
|
+
tsx: id.endsWith(".tsx") || id.endsWith(".jsx"),
|
|
240
|
+
target: "es2022",
|
|
241
|
+
});
|
|
242
|
+
const spanStart = ast.span.start;
|
|
243
|
+
const replacements = [];
|
|
244
|
+
walkSwcAst(ast, (node, _parent) => {
|
|
245
|
+
// Look for: const/let/var foo = createServerFn(...)
|
|
246
|
+
if (node.type !== "VariableDeclarator")
|
|
247
|
+
return;
|
|
248
|
+
if (!node.init || !isCreateServerFnCall(node.init))
|
|
249
|
+
return;
|
|
250
|
+
const fnName = getIdentName(node.id);
|
|
251
|
+
if (!fnName)
|
|
252
|
+
return;
|
|
253
|
+
const hash = deterministicHash(`${relativePath}:${fnName}`);
|
|
254
|
+
const basePath = relativePath.replace(/\.[^.]+$/, "");
|
|
255
|
+
const endpoint = `/__catmint/fn/${basePath}/${hash}`;
|
|
256
|
+
const callStart = offsetOf(node.init.span.start, spanStart);
|
|
257
|
+
const callEnd = offsetOf(node.init.span.end, spanStart);
|
|
258
|
+
replacements.push({
|
|
259
|
+
callStart,
|
|
260
|
+
callEnd,
|
|
261
|
+
replacement: `async (input) => {\n${makeFetchStub(endpoint)}\n}`,
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
if (replacements.length === 0)
|
|
265
|
+
return undefined;
|
|
266
|
+
const s = new MagicString(code);
|
|
267
|
+
for (const r of replacements) {
|
|
268
|
+
s.overwrite(r.callStart, r.callEnd, r.replacement);
|
|
269
|
+
}
|
|
270
|
+
// Remove the `createServerFn` import if it's no longer referenced.
|
|
271
|
+
// After our replacements, the only remaining references would be in other
|
|
272
|
+
// call sites we didn't replace (which shouldn't exist in practice), so
|
|
273
|
+
// check whether the identifier still appears in the transformed code.
|
|
274
|
+
removeCreateServerFnImport(ast, s, spanStart);
|
|
275
|
+
return s;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Remove the `createServerFn` import declaration from the AST using
|
|
279
|
+
* MagicString. Handles:
|
|
280
|
+
* - `import { createServerFn } from '...'` → remove entire statement
|
|
281
|
+
* - `import { createServerFn, other } from '...'` → remove just the specifier
|
|
282
|
+
*/
|
|
283
|
+
function removeCreateServerFnImport(ast, s, spanStart) {
|
|
284
|
+
for (const item of ast.body) {
|
|
285
|
+
if (item.type !== "ImportDeclaration")
|
|
286
|
+
continue;
|
|
287
|
+
if (!item.specifiers)
|
|
288
|
+
continue;
|
|
289
|
+
const idx = item.specifiers.findIndex((spec) => spec.type === "ImportSpecifier" &&
|
|
290
|
+
getIdentName(spec.local) === "createServerFn");
|
|
291
|
+
if (idx === -1)
|
|
292
|
+
continue;
|
|
293
|
+
if (item.specifiers.length === 1) {
|
|
294
|
+
// Only import — remove the entire import declaration
|
|
295
|
+
const start = offsetOf(item.span.start, spanStart);
|
|
296
|
+
const end = offsetOf(item.span.end, spanStart);
|
|
297
|
+
s.overwrite(start, end, "");
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
// Multiple specifiers — remove just this one.
|
|
301
|
+
// We rebuild the specifier list without `createServerFn`.
|
|
302
|
+
const remaining = item.specifiers
|
|
303
|
+
.filter((_, i) => i !== idx)
|
|
304
|
+
.map((spec) => {
|
|
305
|
+
const local = getIdentName(spec.local);
|
|
306
|
+
const imported = spec.imported
|
|
307
|
+
? getIdentName(spec.imported)
|
|
308
|
+
: undefined;
|
|
309
|
+
if (imported && imported !== local) {
|
|
310
|
+
return `${imported} as ${local}`;
|
|
311
|
+
}
|
|
312
|
+
return local;
|
|
313
|
+
})
|
|
314
|
+
.filter(Boolean);
|
|
315
|
+
const source = item.source.value;
|
|
316
|
+
const start = offsetOf(item.span.start, spanStart);
|
|
317
|
+
const end = offsetOf(item.span.end, spanStart);
|
|
318
|
+
s.overwrite(start, end, `import { ${remaining.join(", ")} } from ${JSON.stringify(source)};`);
|
|
319
|
+
}
|
|
320
|
+
break; // Only one import declaration for createServerFn expected
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
// ─── Transform: inline async event handlers ─────────────────────────────────
|
|
324
|
+
/** Event handler name pattern: on + uppercase letter */
|
|
325
|
+
const EVENT_HANDLER_RE = /^on[A-Z]/;
|
|
326
|
+
/**
|
|
327
|
+
* Transform inline async event handlers into server function fetch stubs.
|
|
328
|
+
*
|
|
329
|
+
* Walks the AST to find JSXAttribute nodes whose name matches `on[A-Z].*`
|
|
330
|
+
* (onClick, onSubmit, etc.) and whose value is an async arrow or function
|
|
331
|
+
* expression. Replaces the handler body with a fetch stub.
|
|
332
|
+
*
|
|
333
|
+
* Returns a MagicString if any replacements were made, or undefined.
|
|
334
|
+
*/
|
|
335
|
+
function transformInlineAsyncHandlers(code, id, root) {
|
|
336
|
+
// Only applies to TSX/JSX files
|
|
337
|
+
if (!id.endsWith(".tsx") && !id.endsWith(".jsx"))
|
|
338
|
+
return undefined;
|
|
339
|
+
const relativePath = getRelativePath(id, root);
|
|
340
|
+
const ast = parseSync(code, {
|
|
341
|
+
syntax: "typescript",
|
|
342
|
+
tsx: true,
|
|
343
|
+
target: "es2022",
|
|
344
|
+
});
|
|
345
|
+
const spanStart = ast.span.start;
|
|
346
|
+
const replacements = [];
|
|
347
|
+
let handlerIndex = 0;
|
|
348
|
+
walkSwcAst(ast, (node, _parent) => {
|
|
349
|
+
if (node.type !== "JSXAttribute")
|
|
350
|
+
return;
|
|
351
|
+
// Get attribute name — can be an Identifier or JSXIdentifier
|
|
352
|
+
const attrName = node.name?.value ?? node.name?.name ?? undefined;
|
|
353
|
+
if (!attrName || !EVENT_HANDLER_RE.test(attrName))
|
|
354
|
+
return;
|
|
355
|
+
// Value must be a JSXExpressionContainer
|
|
356
|
+
if (!node.value || node.value.type !== "JSXExpressionContainer")
|
|
357
|
+
return;
|
|
358
|
+
const expr = node.value.expression;
|
|
359
|
+
if (!expr)
|
|
360
|
+
return;
|
|
361
|
+
// Must be an async function expression or arrow
|
|
362
|
+
const isAsyncArrow = expr.type === "ArrowFunctionExpression" && expr.async === true;
|
|
363
|
+
const isAsyncFn = expr.type === "FunctionExpression" && expr.async === true;
|
|
364
|
+
if (!isAsyncArrow && !isAsyncFn)
|
|
365
|
+
return;
|
|
366
|
+
const fnIdent = `__handler_${attrName}_${handlerIndex++}`;
|
|
367
|
+
const hash = deterministicHash(`${relativePath}:${fnIdent}`);
|
|
368
|
+
const basePath = relativePath.replace(/\.[^.]+$/, "");
|
|
369
|
+
const endpoint = `/__catmint/fn/${basePath}/${hash}`;
|
|
370
|
+
// Replace the entire JSXExpressionContainer (from `{` to `}`)
|
|
371
|
+
const containerStart = offsetOf(node.value.span.start, spanStart);
|
|
372
|
+
const containerEnd = offsetOf(node.value.span.end, spanStart);
|
|
373
|
+
const replacement = `{async () => {\n` +
|
|
374
|
+
` await fetch(${JSON.stringify(endpoint)}, {\n` +
|
|
375
|
+
` method: "POST",\n` +
|
|
376
|
+
` headers: { "Content-Type": "application/json" },\n` +
|
|
377
|
+
` body: "{}",\n` +
|
|
378
|
+
` });\n` +
|
|
379
|
+
`}}`;
|
|
380
|
+
replacements.push({
|
|
381
|
+
start: containerStart,
|
|
382
|
+
end: containerEnd,
|
|
383
|
+
replacement,
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
if (replacements.length === 0)
|
|
387
|
+
return undefined;
|
|
388
|
+
const s = new MagicString(code);
|
|
389
|
+
for (const r of replacements) {
|
|
390
|
+
s.overwrite(r.start, r.end, r.replacement);
|
|
391
|
+
}
|
|
392
|
+
return s;
|
|
393
|
+
}
|
|
394
|
+
//# sourceMappingURL=server-fn-transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-fn-transform.js","sourceRoot":"","sources":["../src/server-fn-transform.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,EAAE;AACF,WAAW;AACX,wEAAwE;AACxE,6CAA6C;AAC7C,4DAA4D;AAC5D,EAAE;AACF,6EAA6E;AAC7E,+CAA+C;AAG/C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5E,gFAAgF;AAEhF;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB;IACrC,IAAI,IAAI,GAAG,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GAAG,EAAE,YAAY;YACjB,WAAW;SACZ,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAEhD,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,KAAK,MAAM,CAAC,IAAI,YAAY,EAAE,CAAC;QAC7B,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Produce a short deterministic hash from a string input.
|
|
3
|
+
* Used to generate stable, opaque endpoint identifiers for server functions.
|
|
4
|
+
*/
|
|
5
|
+
export declare function deterministicHash(input: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Check if a file is a server-only module based on its extension pattern.
|
|
8
|
+
* Matches `*.server.ts` and `*.server.tsx`.
|
|
9
|
+
*
|
|
10
|
+
* NOTE: `*.fn.ts` files are NOT server-only — they are importable from client
|
|
11
|
+
* code. The `catmint:server-fn-transform` plugin rewrites them into fetch stubs
|
|
12
|
+
* in client bundles, so the boundary plugin must allow them through.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isServerOnlyFile(id: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Check if a file is a client component based on its extension pattern.
|
|
17
|
+
* Matches `*.client.tsx`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isClientComponentFile(id: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Check if a file is an error boundary file (`error.tsx`).
|
|
22
|
+
*/
|
|
23
|
+
export declare function isErrorFile(id: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Check if a file is a page file (`page.tsx` or `page.mdx`).
|
|
26
|
+
*/
|
|
27
|
+
export declare function isPageFile(id: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Check if a file is a layout file (`layout.tsx`).
|
|
30
|
+
*/
|
|
31
|
+
export declare function isLayoutFile(id: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a file is a server function module (`*.fn.ts`).
|
|
34
|
+
*/
|
|
35
|
+
export declare function isServerFnFile(id: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Normalize a file path to a forward-slash posix path.
|
|
38
|
+
*/
|
|
39
|
+
export declare function toPosixPath(filePath: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Derive the RPC endpoint path for a server function.
|
|
42
|
+
* Uses the relative file path (from project root) and the function name
|
|
43
|
+
* to produce a stable `/__catmint/fn/<basename>/<hash>` path.
|
|
44
|
+
*/
|
|
45
|
+
export declare function serverFnEndpoint(relativeFilePath: string, fnName: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* JavaScript code inlined into client entry modules to enable client-side
|
|
48
|
+
* (soft) navigation. When a user clicks a relative link, this code intercepts
|
|
49
|
+
* the click, fetches the RSC flight stream for the target URL, deserializes
|
|
50
|
+
* it, and tells React to render the new tree — no full page reload needed.
|
|
51
|
+
*
|
|
52
|
+
* This runtime is shared between the dev server (virtual:catmint/client-hydrate)
|
|
53
|
+
* and the production build (virtual:catmint/client-rsc-entry).
|
|
54
|
+
*/
|
|
55
|
+
export declare const CLIENT_NAVIGATION_RUNTIME = "\nfunction setupClientNavigation(reactRoot) {\n if (!reactRoot) return;\n\n function isRelativeUrl(href) {\n if (href.startsWith(\"http://\") || href.startsWith(\"https://\") || href.startsWith(\"//\")) return false;\n if (/^[a-zA-Z][a-zA-Z0-9+\\-.]*:/.test(href)) return false;\n if (href.startsWith(\"#\")) return false;\n return true;\n }\n\n function shouldIntercept(event, anchor) {\n if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return false;\n if (event.button !== 0) return false;\n if (event.defaultPrevented) return false;\n var target = anchor.getAttribute(\"target\");\n if (target && target !== \"_self\") return false;\n if (anchor.hasAttribute(\"download\")) return false;\n if (anchor.hasAttribute(\"data-catmint-reload\")) return false;\n var href = anchor.getAttribute(\"href\");\n if (!href) return false;\n return isRelativeUrl(href);\n }\n\n function findAnchor(target) {\n if (!target || !(target instanceof Element)) return null;\n return target.closest(\"a\");\n }\n\n var navigating = false;\n\n async function performNavigation(url, opts) {\n if (navigating) return;\n navigating = true;\n\n try {\n var rscUrl = \"/__catmint/rsc?path=\" + encodeURIComponent(url.split(\"#\")[0]);\n var response = await fetch(rscUrl);\n\n if (!response.ok) {\n // RSC fetch failed \u2014 fall back to full page reload\n window.location.href = url;\n return;\n }\n\n // Dynamically import createFromReadableStream for RSC deserialization\n var rscBrowser = await import(\"@vitejs/plugin-rsc/browser\");\n var newRoot = await rscBrowser.createFromReadableStream(response.body);\n\n // Update the URL\n if (opts && opts.replace) {\n window.history.replaceState(null, \"\", url);\n } else {\n window.history.pushState(null, \"\", url);\n }\n\n // Tell React to render the new tree\n reactRoot.render(newRoot);\n\n // Scroll to top unless explicitly disabled\n if (!opts || opts.scroll !== false) {\n // Handle hash navigation\n var hashIdx = url.indexOf(\"#\");\n if (hashIdx !== -1) {\n var hash = url.slice(hashIdx + 1);\n var el = document.getElementById(hash);\n if (el) {\n el.scrollIntoView();\n } else {\n window.scrollTo(0, 0);\n }\n } else {\n window.scrollTo(0, 0);\n }\n }\n } catch (err) {\n console.error(\"[catmint] Client navigation error:\", err);\n // Fall back to full page reload on error\n window.location.href = url;\n } finally {\n navigating = false;\n }\n }\n\n // Intercept clicks on <a> tags with relative hrefs\n document.addEventListener(\"click\", function(event) {\n var anchor = findAnchor(event.target);\n if (!anchor) return;\n if (!shouldIntercept(event, anchor)) return;\n\n var href = anchor.getAttribute(\"href\");\n var resolved = new URL(href, window.location.href);\n\n // Only intercept same-origin\n if (resolved.origin !== window.location.origin) return;\n\n var targetPath = resolved.pathname + resolved.search;\n var currentPath = window.location.pathname + window.location.search;\n if (targetPath === currentPath && resolved.hash) return;\n\n event.preventDefault();\n var replace = anchor.hasAttribute(\"data-catmint-replace\");\n performNavigation(\n resolved.pathname + resolved.search + resolved.hash,\n { replace: replace, scroll: true }\n );\n });\n\n // Handle browser back/forward\n window.addEventListener(\"popstate\", function() {\n var url = window.location.pathname + window.location.search + window.location.hash;\n performNavigation(url, { replace: true, scroll: false });\n });\n}\n";
|
|
56
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAI9C;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,gBAAgB,EAAE,MAAM,EACxB,MAAM,EAAE,MAAM,GACb,MAAM,CAMR;AAMD;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,2xHAkHrC,CAAC"}
|