@evjs/build-tools 0.1.0 → 0.1.2
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/esm/index.d.ts +4 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +3 -2
- package/esm/index.js.map +1 -1
- package/esm/routes/client.d.ts +11 -0
- package/esm/routes/client.d.ts.map +1 -0
- package/esm/routes/client.js +111 -0
- package/esm/routes/client.js.map +1 -0
- package/esm/routes/index.d.ts +12 -0
- package/esm/routes/index.d.ts.map +1 -0
- package/esm/routes/index.js +18 -0
- package/esm/routes/index.js.map +1 -0
- package/esm/routes/server.d.ts +17 -0
- package/esm/routes/server.d.ts.map +1 -0
- package/esm/routes/server.js +162 -0
- package/esm/routes/server.js.map +1 -0
- package/esm/routes/shared.d.ts +8 -0
- package/esm/routes/shared.d.ts.map +1 -0
- package/esm/routes/shared.js +45 -0
- package/esm/routes/shared.js.map +1 -0
- package/esm/routes.d.ts +2 -22
- package/esm/routes.d.ts.map +1 -1
- package/esm/routes.js +1 -176
- package/esm/routes.js.map +1 -1
- package/esm/server-fns.d.ts +3 -0
- package/esm/server-fns.d.ts.map +1 -0
- package/esm/server-fns.js +15 -0
- package/esm/server-fns.js.map +1 -0
- package/esm/transforms/server/index.d.ts.map +1 -1
- package/esm/transforms/server/index.js +2 -3
- package/esm/transforms/server/index.js.map +1 -1
- package/esm/types.d.ts +1 -4
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils.d.ts +7 -2
- package/esm/utils.d.ts.map +1 -1
- package/esm/utils.js +14 -3
- package/esm/utils.js.map +1 -1
- package/package.json +1 -1
package/esm/index.d.ts
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export type { GenerateHtmlOptions, HtmlAsset } from "./html.js";
|
|
5
5
|
export { generateHtml } from "./html.js";
|
|
6
|
-
export type { ExtractedRoute } from "./routes.js";
|
|
7
|
-
export { detectServerRouteExports,
|
|
6
|
+
export type { ExtractedRoute, ExtractedServerRoute, RouteAnalysis, } from "./routes.js";
|
|
7
|
+
export { analyzeRoutes, detectServerRouteExports, extractClientRoutes, extractClientRoutesFromAst, extractServerRoutes, resolveRoutes, } from "./routes.js";
|
|
8
|
+
export { extractServerFunctionExports } from "./server-fns.js";
|
|
8
9
|
export type { TransformResult } from "./transforms/index.js";
|
|
9
10
|
export { transformServerFile } from "./transforms/index.js";
|
|
10
11
|
export type { RouteModuleInfo, ServerEntryConfig, TransformOptions, } from "./types.js";
|
|
11
|
-
export { detectUseServer,
|
|
12
|
+
export { detectUseServer, hashServerFunction, makeFnId, makeModuleId, parseModuleRef, } from "./utils.js";
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAC/D,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,QAAQ,EACR,YAAY,EACZ,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Bundler-agnostic build utilities for the ev framework.
|
|
3
3
|
*/
|
|
4
4
|
export { generateHtml } from "./html.js";
|
|
5
|
-
export { detectServerRouteExports,
|
|
5
|
+
export { analyzeRoutes, detectServerRouteExports, extractClientRoutes, extractClientRoutesFromAst, extractServerRoutes, resolveRoutes, } from "./routes.js";
|
|
6
|
+
export { extractServerFunctionExports } from "./server-fns.js";
|
|
6
7
|
export { transformServerFile } from "./transforms/index.js";
|
|
7
|
-
export { detectUseServer,
|
|
8
|
+
export { detectUseServer, hashServerFunction, makeFnId, makeModuleId, parseModuleRef, } from "./utils.js";
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAMzC,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAM5D,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,QAAQ,EACR,YAAY,EACZ,cAAc,GACf,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExtractedRoute } from "@evjs/manifest";
|
|
2
|
+
import { type RouteAst } from "./shared.js";
|
|
3
|
+
/**
|
|
4
|
+
* Extract client route metadata from source code by scanning for createRoute() calls.
|
|
5
|
+
*
|
|
6
|
+
* Only collects routes that have a `path` property. Pathless layouts using `id`
|
|
7
|
+
* are skipped because they do not represent navigable URLs.
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractClientRoutes(source: string): ExtractedRoute[];
|
|
10
|
+
export declare function extractClientRoutesFromAst(ast: RouteAst): ExtractedRoute[];
|
|
11
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/routes/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAOrD,OAAO,EAKL,KAAK,QAAQ,EACd,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE,CAIpE;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,QAAQ,GAAG,cAAc,EAAE,CAW1E"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { collectImportedNames, getPropertyName, isNamedCall, parseRouteModule, } from "./shared.js";
|
|
2
|
+
/**
|
|
3
|
+
* Extract client route metadata from source code by scanning for createRoute() calls.
|
|
4
|
+
*
|
|
5
|
+
* Only collects routes that have a `path` property. Pathless layouts using `id`
|
|
6
|
+
* are skipped because they do not represent navigable URLs.
|
|
7
|
+
*/
|
|
8
|
+
export function extractClientRoutes(source) {
|
|
9
|
+
const ast = parseRouteModule(source);
|
|
10
|
+
if (!ast)
|
|
11
|
+
return [];
|
|
12
|
+
return extractClientRoutesFromAst(ast);
|
|
13
|
+
}
|
|
14
|
+
export function extractClientRoutesFromAst(ast) {
|
|
15
|
+
const createRouteNames = collectClientCreateRouteNames(ast);
|
|
16
|
+
if (createRouteNames.size === 0)
|
|
17
|
+
return [];
|
|
18
|
+
const routes = [];
|
|
19
|
+
for (const item of ast.body) {
|
|
20
|
+
collectFromItem(item, createRouteNames, routes);
|
|
21
|
+
}
|
|
22
|
+
return routes;
|
|
23
|
+
}
|
|
24
|
+
function collectClientCreateRouteNames(ast) {
|
|
25
|
+
return collectImportedNames(ast, "@evjs/client", "createRoute");
|
|
26
|
+
}
|
|
27
|
+
/** Walk a top-level module item looking for createRoute calls. */
|
|
28
|
+
function collectFromItem(item, createRouteNames, routes) {
|
|
29
|
+
// export const fooRoute = createRoute({ ... })
|
|
30
|
+
if (item.type === "ExportDeclaration") {
|
|
31
|
+
const decl = item.declaration;
|
|
32
|
+
if (decl.type === "VariableDeclaration") {
|
|
33
|
+
for (const d of decl.declarations) {
|
|
34
|
+
if (d.init) {
|
|
35
|
+
const varName = d.id.type === "Identifier" ? d.id.value : undefined;
|
|
36
|
+
const route = tryExtractClientRoute(d.init, createRouteNames);
|
|
37
|
+
if (route) {
|
|
38
|
+
routes.push({ ...route, ...(varName ? { varName } : {}) });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// const fooRoute = createRoute({ ... })
|
|
46
|
+
if (item.type === "VariableDeclaration") {
|
|
47
|
+
for (const d of item.declarations) {
|
|
48
|
+
if (d.init) {
|
|
49
|
+
const varName = d.id.type === "Identifier" ? d.id.value : undefined;
|
|
50
|
+
const route = tryExtractClientRoute(d.init, createRouteNames);
|
|
51
|
+
if (route) {
|
|
52
|
+
routes.push({ ...route, ...(varName ? { varName } : {}) });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** If the expression is a client createRoute() call, extract route metadata. */
|
|
59
|
+
function tryExtractClientRoute(expr, createRouteNames) {
|
|
60
|
+
if (!isNamedCall(expr, createRouteNames))
|
|
61
|
+
return undefined;
|
|
62
|
+
const call = expr;
|
|
63
|
+
if (call.arguments.length === 0)
|
|
64
|
+
return undefined;
|
|
65
|
+
const arg = call.arguments[0].expression;
|
|
66
|
+
if (arg.type !== "ObjectExpression")
|
|
67
|
+
return undefined;
|
|
68
|
+
let path;
|
|
69
|
+
let parentName;
|
|
70
|
+
for (const prop of arg.properties) {
|
|
71
|
+
if (prop.type !== "KeyValueProperty")
|
|
72
|
+
continue;
|
|
73
|
+
const key = getPropertyName(prop);
|
|
74
|
+
if (key === "path" && prop.value.type === "StringLiteral") {
|
|
75
|
+
path = prop.value.value;
|
|
76
|
+
}
|
|
77
|
+
if (key === "getParentRoute") {
|
|
78
|
+
parentName = extractParentName(prop.value);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (path !== undefined) {
|
|
82
|
+
const route = { path };
|
|
83
|
+
if (parentName)
|
|
84
|
+
route.parentName = parentName;
|
|
85
|
+
return route;
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Extract the parent route variable name from a `getParentRoute` value.
|
|
91
|
+
*
|
|
92
|
+
* Handles arrow functions like:
|
|
93
|
+
* - `() => rootRoute` (expression body)
|
|
94
|
+
* - `() => { return rootRoute; }` (block body)
|
|
95
|
+
*/
|
|
96
|
+
function extractParentName(expr) {
|
|
97
|
+
if (expr.type !== "ArrowFunctionExpression")
|
|
98
|
+
return undefined;
|
|
99
|
+
if (expr.body.type === "Identifier") {
|
|
100
|
+
return expr.body.value;
|
|
101
|
+
}
|
|
102
|
+
if (expr.body.type === "BlockStatement" && expr.body.stmts.length === 1) {
|
|
103
|
+
const stmt = expr.body.stmts[0];
|
|
104
|
+
if (stmt.type === "ReturnStatement" &&
|
|
105
|
+
stmt.argument?.type === "Identifier") {
|
|
106
|
+
return stmt.argument.value;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/routes/client.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,WAAW,EACX,gBAAgB,GAEjB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,MAAM,GAAG,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,OAAO,0BAA0B,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,GAAa;IACtD,MAAM,gBAAgB,GAAG,6BAA6B,CAAC,GAAG,CAAC,CAAC;IAC5D,IAAI,gBAAgB,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAE3C,MAAM,MAAM,GAAqB,EAAE,CAAC;IAEpC,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QAC5B,eAAe,CAAC,IAAI,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,6BAA6B,CAAC,GAAa;IAClD,OAAO,oBAAoB,CAAC,GAAG,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;AAClE,CAAC;AAED,kEAAkE;AAClE,SAAS,eAAe,CACtB,IAAgB,EAChB,gBAA6B,EAC7B,MAAwB;IAExB,+CAA+C;IAC/C,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC;QAC9B,IAAI,IAAI,CAAC,IAA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ACzC,IAAI,IAAI,CAAC,IAAI,KAAK,yBAAyB;QAAE,OAAO,SAAS,CAAC;IAE9D,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IACzB,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,gBAAgB,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChC,IACE,IAAI,CAAC,IAAI,KAAK,iBAAiB;YAC/B,IAAI,CAAC,QAAQ,EAAE,IAAI,KAAK,YAAY,EACpC,CAAC;YACD,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExtractedRoute, ExtractedServerRoute } from "@evjs/manifest";
|
|
2
|
+
export type { ExtractedRoute, ExtractedServerRoute } from "@evjs/manifest";
|
|
3
|
+
export { resolveRoutes } from "@evjs/manifest";
|
|
4
|
+
export { extractClientRoutes, extractClientRoutesFromAst, } from "./client.js";
|
|
5
|
+
export { detectServerRouteExports, extractServerRoutes, extractServerRoutesFromAst, } from "./server.js";
|
|
6
|
+
export interface RouteAnalysis {
|
|
7
|
+
clientRoutes: ExtractedRoute[];
|
|
8
|
+
serverRoutes: ExtractedServerRoute[];
|
|
9
|
+
}
|
|
10
|
+
/** Parse once and run both client and server route collectors. */
|
|
11
|
+
export declare function analyzeRoutes(source: string): RouteAnalysis;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAK3E,YAAY,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EACL,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,cAAc,EAAE,CAAC;IAC/B,YAAY,EAAE,oBAAoB,EAAE,CAAC;CACtC;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAU3D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { extractClientRoutesFromAst } from "./client.js";
|
|
2
|
+
import { extractServerRoutesFromAst } from "./server.js";
|
|
3
|
+
import { parseRouteModule } from "./shared.js";
|
|
4
|
+
export { resolveRoutes } from "@evjs/manifest";
|
|
5
|
+
export { extractClientRoutes, extractClientRoutesFromAst, } from "./client.js";
|
|
6
|
+
export { detectServerRouteExports, extractServerRoutes, extractServerRoutesFromAst, } from "./server.js";
|
|
7
|
+
/** Parse once and run both client and server route collectors. */
|
|
8
|
+
export function analyzeRoutes(source) {
|
|
9
|
+
const ast = parseRouteModule(source);
|
|
10
|
+
if (!ast) {
|
|
11
|
+
return { clientRoutes: [], serverRoutes: [] };
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
clientRoutes: extractClientRoutesFromAst(ast),
|
|
15
|
+
serverRoutes: extractServerRoutesFromAst(ast),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EACL,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AAOrB,kEAAkE;AAClE,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,MAAM,GAAG,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;IAChD,CAAC;IAED,OAAO;QACL,YAAY,EAAE,0BAA0B,CAAC,GAAG,CAAC;QAC7C,YAAY,EAAE,0BAA0B,CAAC,GAAG,CAAC;KAC9C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ExtractedServerRoute } from "@evjs/manifest";
|
|
2
|
+
import { type RouteAst } from "./shared.js";
|
|
3
|
+
/**
|
|
4
|
+
* Detect server route handlers exported from this file.
|
|
5
|
+
* Returns the exported variable names, or null if this is not a server route file.
|
|
6
|
+
*/
|
|
7
|
+
export declare function detectServerRouteExports(source: string): string[] | null;
|
|
8
|
+
/**
|
|
9
|
+
* Extract server route handler metadata from exported @evjs/server createRoute() calls.
|
|
10
|
+
*
|
|
11
|
+
* Handles both direct exports and named export aliases:
|
|
12
|
+
* - export const users = createRoute("/api/users", { GET() {} })
|
|
13
|
+
* - const internal = createRoute("/api/users", { GET() {} }); export { internal as users }
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractServerRoutes(source: string): ExtractedServerRoute[];
|
|
16
|
+
export declare function extractServerRoutesFromAst(ast: RouteAst): ExtractedServerRoute[];
|
|
17
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/routes/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAKL,KAAK,QAAQ,EACd,MAAM,aAAa,CAAC;AAYrB;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CASxE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,EAAE,CAI1E;AAED,wBAAgB,0BAA0B,CACxC,GAAG,EAAE,QAAQ,GACZ,oBAAoB,EAAE,CAiDxB"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { collectImportedNames, getPropertyName, isNamedCall, parseRouteModule, } from "./shared.js";
|
|
2
|
+
const HTTP_METHODS = new Set([
|
|
3
|
+
"GET",
|
|
4
|
+
"POST",
|
|
5
|
+
"PUT",
|
|
6
|
+
"PATCH",
|
|
7
|
+
"DELETE",
|
|
8
|
+
"OPTIONS",
|
|
9
|
+
"HEAD",
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* Detect server route handlers exported from this file.
|
|
13
|
+
* Returns the exported variable names, or null if this is not a server route file.
|
|
14
|
+
*/
|
|
15
|
+
export function detectServerRouteExports(source) {
|
|
16
|
+
const ast = parseRouteModule(source);
|
|
17
|
+
if (!ast)
|
|
18
|
+
return null;
|
|
19
|
+
const createRouteNames = collectServerCreateRouteNames(ast);
|
|
20
|
+
if (createRouteNames.size === 0)
|
|
21
|
+
return null;
|
|
22
|
+
const exportNames = collectServerRouteExportNames(ast, createRouteNames);
|
|
23
|
+
return exportNames.length > 0 ? exportNames : null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Extract server route handler metadata from exported @evjs/server createRoute() calls.
|
|
27
|
+
*
|
|
28
|
+
* Handles both direct exports and named export aliases:
|
|
29
|
+
* - export const users = createRoute("/api/users", { GET() {} })
|
|
30
|
+
* - const internal = createRoute("/api/users", { GET() {} }); export { internal as users }
|
|
31
|
+
*/
|
|
32
|
+
export function extractServerRoutes(source) {
|
|
33
|
+
const ast = parseRouteModule(source);
|
|
34
|
+
if (!ast)
|
|
35
|
+
return [];
|
|
36
|
+
return extractServerRoutesFromAst(ast);
|
|
37
|
+
}
|
|
38
|
+
export function extractServerRoutesFromAst(ast) {
|
|
39
|
+
const createRouteNames = collectServerCreateRouteNames(ast);
|
|
40
|
+
if (createRouteNames.size === 0)
|
|
41
|
+
return [];
|
|
42
|
+
const routeDeclarations = new Map();
|
|
43
|
+
const routes = [];
|
|
44
|
+
for (const item of ast.body) {
|
|
45
|
+
if (item.type === "ExportDeclaration") {
|
|
46
|
+
const decl = item.declaration;
|
|
47
|
+
if (decl.type === "VariableDeclaration") {
|
|
48
|
+
for (const d of decl.declarations) {
|
|
49
|
+
if (d.init && d.id.type === "Identifier") {
|
|
50
|
+
const route = tryExtractServerRoute(d.init, createRouteNames);
|
|
51
|
+
if (route) {
|
|
52
|
+
routes.push(route);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (item.type === "VariableDeclaration") {
|
|
60
|
+
for (const d of item.declarations) {
|
|
61
|
+
if (d.init && d.id.type === "Identifier") {
|
|
62
|
+
const route = tryExtractServerRoute(d.init, createRouteNames);
|
|
63
|
+
if (route) {
|
|
64
|
+
routeDeclarations.set(d.id.value, route);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (item.type === "ExportNamedDeclaration") {
|
|
71
|
+
for (const spec of item.specifiers) {
|
|
72
|
+
if (spec.type !== "ExportSpecifier")
|
|
73
|
+
continue;
|
|
74
|
+
if (spec.orig.type !== "Identifier")
|
|
75
|
+
continue;
|
|
76
|
+
const route = routeDeclarations.get(spec.orig.value);
|
|
77
|
+
if (!route)
|
|
78
|
+
continue;
|
|
79
|
+
routes.push(route);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return routes;
|
|
84
|
+
}
|
|
85
|
+
function collectServerCreateRouteNames(ast) {
|
|
86
|
+
return collectImportedNames(ast, "@evjs/server", "createRoute");
|
|
87
|
+
}
|
|
88
|
+
function collectServerRouteExportNames(ast, createRouteNames) {
|
|
89
|
+
const routeDeclarations = new Set();
|
|
90
|
+
const exportNames = [];
|
|
91
|
+
for (const item of ast.body) {
|
|
92
|
+
if (item.type === "ExportDeclaration") {
|
|
93
|
+
const decl = item.declaration;
|
|
94
|
+
if (decl.type === "VariableDeclaration") {
|
|
95
|
+
for (const d of decl.declarations) {
|
|
96
|
+
if (d.init &&
|
|
97
|
+
d.id.type === "Identifier" &&
|
|
98
|
+
tryExtractServerRoute(d.init, createRouteNames)) {
|
|
99
|
+
exportNames.push(d.id.value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (item.type === "VariableDeclaration") {
|
|
106
|
+
for (const d of item.declarations) {
|
|
107
|
+
if (d.init &&
|
|
108
|
+
d.id.type === "Identifier" &&
|
|
109
|
+
tryExtractServerRoute(d.init, createRouteNames)) {
|
|
110
|
+
routeDeclarations.add(d.id.value);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (item.type === "ExportNamedDeclaration") {
|
|
116
|
+
for (const spec of item.specifiers) {
|
|
117
|
+
if (spec.type !== "ExportSpecifier")
|
|
118
|
+
continue;
|
|
119
|
+
if (spec.orig.type !== "Identifier")
|
|
120
|
+
continue;
|
|
121
|
+
if (!routeDeclarations.has(spec.orig.value))
|
|
122
|
+
continue;
|
|
123
|
+
const exported = spec.exported ?? spec.orig;
|
|
124
|
+
if (exported.type === "Identifier") {
|
|
125
|
+
exportNames.push(exported.value);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return exportNames;
|
|
131
|
+
}
|
|
132
|
+
function tryExtractServerRoute(expr, createRouteNames) {
|
|
133
|
+
if (!isNamedCall(expr, createRouteNames))
|
|
134
|
+
return undefined;
|
|
135
|
+
const call = expr;
|
|
136
|
+
if (call.arguments.length < 2)
|
|
137
|
+
return undefined;
|
|
138
|
+
const pathArg = call.arguments[0].expression;
|
|
139
|
+
if (pathArg.type !== "StringLiteral")
|
|
140
|
+
return undefined;
|
|
141
|
+
const definitionArg = call.arguments[1].expression;
|
|
142
|
+
if (definitionArg.type !== "ObjectExpression")
|
|
143
|
+
return undefined;
|
|
144
|
+
return {
|
|
145
|
+
path: pathArg.value,
|
|
146
|
+
methods: extractServerRouteMethods(definitionArg),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function extractServerRouteMethods(definition) {
|
|
150
|
+
const methods = [];
|
|
151
|
+
for (const prop of definition.properties) {
|
|
152
|
+
if (prop.type !== "KeyValueProperty" && prop.type !== "MethodProperty") {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const method = getPropertyName(prop);
|
|
156
|
+
if (method && HTTP_METHODS.has(method) && !methods.includes(method)) {
|
|
157
|
+
methods.push(method);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return methods;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/routes/server.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,WAAW,EACX,gBAAgB,GAEjB,MAAM,aAAa,CAA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C,CAAC,CAAC,UAAU,CAAC;IACnD,IAAI,aAAa,CAAC,IAAI,KAAK,kBAAkB;QAAE,OAAO,SAAS,CAAC;IAEhE,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,KAAK;QACnB,OAAO,EAAE,yBAAyB,CAAC,aAAa,CAAC;KAClD,CAAC;AACJ,CAAC;AAED,SAAS,yBAAyB,CAAC,UAA4B;IAC7D,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QACzC,IAAI,IAAI,CAAC,IAAI,KAAK,kBAAkB,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YACvE,SAAS;QACX,CAAC;QACD,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,MAAM,IAAI,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACpE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { parseSync } from "@swc/core";
|
|
2
|
+
import type { Expression, KeyValueProperty, MethodProperty } from "@swc/types";
|
|
3
|
+
export type RouteAst = ReturnType<typeof parseSync>;
|
|
4
|
+
export declare function parseRouteModule(source: string): RouteAst | null;
|
|
5
|
+
export declare function getPropertyName(property: KeyValueProperty | MethodProperty): string | null;
|
|
6
|
+
export declare function collectImportedNames(ast: RouteAst, moduleName: string, importedName: string): Set<string>;
|
|
7
|
+
export declare function isNamedCall(expr: Expression, names: Set<string>): boolean;
|
|
8
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/routes/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAEV,UAAU,EACV,gBAAgB,EAChB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAEpD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAUhE;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,gBAAgB,GAAG,cAAc,GAC1C,MAAM,GAAG,IAAI,CAIf;AAED,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,QAAQ,EACb,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GACnB,GAAG,CAAC,MAAM,CAAC,CAkBb;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO,CAIzE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { parseSync } from "@swc/core";
|
|
2
|
+
export function parseRouteModule(source) {
|
|
3
|
+
try {
|
|
4
|
+
return parseSync(source, {
|
|
5
|
+
syntax: "typescript",
|
|
6
|
+
tsx: true,
|
|
7
|
+
target: "esnext",
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function getPropertyName(property) {
|
|
15
|
+
if (property.key.type === "Identifier")
|
|
16
|
+
return property.key.value;
|
|
17
|
+
if (property.key.type === "StringLiteral")
|
|
18
|
+
return property.key.value;
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
export function collectImportedNames(ast, moduleName, importedName) {
|
|
22
|
+
const names = new Set();
|
|
23
|
+
for (const item of ast.body) {
|
|
24
|
+
if (item.type !== "ImportDeclaration")
|
|
25
|
+
continue;
|
|
26
|
+
if (item.source.value !== moduleName)
|
|
27
|
+
continue;
|
|
28
|
+
for (const spec of item.specifiers) {
|
|
29
|
+
if (spec.type !== "ImportSpecifier")
|
|
30
|
+
continue;
|
|
31
|
+
const imported = spec.imported ?? spec.local;
|
|
32
|
+
if (imported.type === "Identifier" && imported.value === importedName) {
|
|
33
|
+
names.add(spec.local.value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return names;
|
|
38
|
+
}
|
|
39
|
+
export function isNamedCall(expr, names) {
|
|
40
|
+
if (expr.type !== "CallExpression")
|
|
41
|
+
return false;
|
|
42
|
+
const callee = expr.callee;
|
|
43
|
+
return callee.type === "Identifier" && names.has(callee.value);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/routes/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAUtC,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,IAAI,CAAC;QACH,OAAO,SAAS,CAAC,MAAM,EAAE;YACvB,MAAM,EAAE,YAAY;YACpB,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,QAAQ;SACjB,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,QAA2C;IAE3C,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC;IAClE,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,eAAe;QAAE,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC;IACrE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,GAAa,EACb,UAAkB,EAClB,YAAoB;IAEpB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAEhC,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB;YAAE,SAAS;QAChD,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,UAAU;YAAE,SAAS;QAE/C,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACnC,IAAI,IAAI,CAAC,IAAI,KAAK,iBAAiB;gBAAE,SAAS;YAE9C,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC;YAC7C,IAAI,QAAQ,CAAC,IAAI,KAAK,YAAY,IAAI,QAAQ,CAAC,KAAK,KAAK,YAAY,EAAE,CAAC;gBACtE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAgB,EAAE,KAAkB;IAC9D,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,KAAK,CAAC;IACjD,MAAM,MAAM,GAAI,IAAuB,CAAC,MAAM,CAAC;IAC/C,OAAO,MAAM,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC"}
|
package/esm/routes.d.ts
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export { resolveRoutes } from "@evjs/manifest";
|
|
4
|
-
/**
|
|
5
|
-
* Extract route metadata from source code by scanning for createRoute() calls.
|
|
6
|
-
*
|
|
7
|
-
* Only collects routes that have a `path` property — pathless layouts (using `id`)
|
|
8
|
-
* are skipped since they don't represent navigable URLs.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* extractRoutes('export const r = createRoute({ path: "/foo" })')
|
|
13
|
-
* // => [{ path: "/foo" }]
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export declare function extractRoutes(source: string): ExtractedRoute[];
|
|
17
|
-
/**
|
|
18
|
-
* Detect server route handlers exported from this file.
|
|
19
|
-
* Returns the exported variable names, or null if this is not a server route file
|
|
20
|
-
* (i.e., it doesn't import `createRoute` from `@evjs/server`).
|
|
21
|
-
*/
|
|
22
|
-
export declare function detectServerRouteExports(source: string): string[] | null;
|
|
1
|
+
export type { ExtractedRoute, ExtractedServerRoute, RouteAnalysis, } from "./routes/index.js";
|
|
2
|
+
export { analyzeRoutes, detectServerRouteExports, extractClientRoutes, extractClientRoutesFromAst, extractServerRoutes, extractServerRoutesFromAst, resolveRoutes, } from "./routes/index.js";
|
|
23
3
|
//# sourceMappingURL=routes.d.ts.map
|
package/esm/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,0BAA0B,EAC1B,aAAa,GACd,MAAM,mBAAmB,CAAC"}
|
package/esm/routes.js
CHANGED
|
@@ -1,177 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export { resolveRoutes } from "@evjs/manifest";
|
|
3
|
-
/**
|
|
4
|
-
* Extract route metadata from source code by scanning for createRoute() calls.
|
|
5
|
-
*
|
|
6
|
-
* Only collects routes that have a `path` property — pathless layouts (using `id`)
|
|
7
|
-
* are skipped since they don't represent navigable URLs.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* extractRoutes('export const r = createRoute({ path: "/foo" })')
|
|
12
|
-
* // => [{ path: "/foo" }]
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export function extractRoutes(source) {
|
|
16
|
-
let ast;
|
|
17
|
-
try {
|
|
18
|
-
ast = parseSync(source, {
|
|
19
|
-
syntax: "typescript",
|
|
20
|
-
tsx: true,
|
|
21
|
-
target: "esnext",
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return [];
|
|
26
|
-
}
|
|
27
|
-
const routes = [];
|
|
28
|
-
for (const item of ast.body) {
|
|
29
|
-
collectFromItem(item, routes);
|
|
30
|
-
}
|
|
31
|
-
return routes;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Detect server route handlers exported from this file.
|
|
35
|
-
* Returns the exported variable names, or null if this is not a server route file
|
|
36
|
-
* (i.e., it doesn't import `createRoute` from `@evjs/server`).
|
|
37
|
-
*/
|
|
38
|
-
export function detectServerRouteExports(source) {
|
|
39
|
-
let ast;
|
|
40
|
-
try {
|
|
41
|
-
ast = parseSync(source, {
|
|
42
|
-
syntax: "typescript",
|
|
43
|
-
tsx: true,
|
|
44
|
-
target: "esnext",
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
let hasServerImport = false;
|
|
51
|
-
for (const item of ast.body) {
|
|
52
|
-
if (item.type === "ImportDeclaration") {
|
|
53
|
-
if (item.source.value === "@evjs/server") {
|
|
54
|
-
for (const spec of item.specifiers) {
|
|
55
|
-
if (spec.type === "ImportSpecifier" &&
|
|
56
|
-
spec.local.value === "createRoute") {
|
|
57
|
-
hasServerImport = true;
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (!hasServerImport)
|
|
65
|
-
return null;
|
|
66
|
-
const exports = [];
|
|
67
|
-
for (const item of ast.body) {
|
|
68
|
-
if (item.type === "ExportDeclaration") {
|
|
69
|
-
const decl = item.declaration;
|
|
70
|
-
if (decl.type === "VariableDeclaration") {
|
|
71
|
-
for (const d of decl.declarations) {
|
|
72
|
-
if (d.init &&
|
|
73
|
-
isCreateRouteCall(d.init) &&
|
|
74
|
-
d.id.type === "Identifier") {
|
|
75
|
-
exports.push(d.id.value);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return exports;
|
|
82
|
-
}
|
|
83
|
-
/** Walk a top-level module item looking for createRoute calls. */
|
|
84
|
-
function collectFromItem(item, routes) {
|
|
85
|
-
// export const fooRoute = createRoute({ ... })
|
|
86
|
-
if (item.type === "ExportDeclaration") {
|
|
87
|
-
const decl = item.declaration;
|
|
88
|
-
if (decl.type === "VariableDeclaration") {
|
|
89
|
-
for (const d of decl.declarations) {
|
|
90
|
-
if (d.init) {
|
|
91
|
-
const varName = d.id.type === "Identifier" ? d.id.value : undefined;
|
|
92
|
-
tryExtractFromExpr(d.init, routes, varName);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
// const fooRoute = createRoute({ ... })
|
|
99
|
-
if (item.type === "VariableDeclaration") {
|
|
100
|
-
for (const d of item.declarations) {
|
|
101
|
-
if (d.init) {
|
|
102
|
-
const varName = d.id.type === "Identifier" ? d.id.value : undefined;
|
|
103
|
-
tryExtractFromExpr(d.init, routes, varName);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/** If the expression is a createRoute() call, extract route metadata. */
|
|
109
|
-
function tryExtractFromExpr(expr, routes, varName) {
|
|
110
|
-
if (!isCreateRouteCall(expr))
|
|
111
|
-
return;
|
|
112
|
-
const call = expr;
|
|
113
|
-
if (call.arguments.length === 0)
|
|
114
|
-
return;
|
|
115
|
-
const arg = call.arguments[0].expression;
|
|
116
|
-
if (arg.type !== "ObjectExpression")
|
|
117
|
-
return;
|
|
118
|
-
let path;
|
|
119
|
-
let parentName;
|
|
120
|
-
for (const prop of arg.properties) {
|
|
121
|
-
if (prop.type !== "KeyValueProperty")
|
|
122
|
-
continue;
|
|
123
|
-
const key = getPropertyName(prop);
|
|
124
|
-
if (key === "path" && prop.value.type === "StringLiteral") {
|
|
125
|
-
path = prop.value.value;
|
|
126
|
-
}
|
|
127
|
-
if (key === "getParentRoute") {
|
|
128
|
-
parentName = extractParentName(prop.value);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (path !== undefined) {
|
|
132
|
-
const route = { path };
|
|
133
|
-
if (parentName)
|
|
134
|
-
route.parentName = parentName;
|
|
135
|
-
if (varName)
|
|
136
|
-
route.varName = varName;
|
|
137
|
-
routes.push(route);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Extract the parent route variable name from a `getParentRoute` value.
|
|
142
|
-
*
|
|
143
|
-
* Handles arrow functions like:
|
|
144
|
-
* - `() => rootRoute` (expression body)
|
|
145
|
-
* - `() => { return rootRoute; }` (block body — not common but safe)
|
|
146
|
-
*/
|
|
147
|
-
function extractParentName(expr) {
|
|
148
|
-
if (expr.type !== "ArrowFunctionExpression")
|
|
149
|
-
return undefined;
|
|
150
|
-
// () => rootRoute (expression body)
|
|
151
|
-
if (expr.body.type === "Identifier") {
|
|
152
|
-
return expr.body.value;
|
|
153
|
-
}
|
|
154
|
-
// () => { return rootRoute; }
|
|
155
|
-
if (expr.body.type === "BlockStatement" && expr.body.stmts.length === 1) {
|
|
156
|
-
const stmt = expr.body.stmts[0];
|
|
157
|
-
if (stmt.type === "ReturnStatement" &&
|
|
158
|
-
stmt.argument?.type === "Identifier") {
|
|
159
|
-
return stmt.argument.value;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
function isCreateRouteCall(expr) {
|
|
165
|
-
if (expr.type !== "CallExpression")
|
|
166
|
-
return false;
|
|
167
|
-
const callee = expr.callee;
|
|
168
|
-
return callee.type === "Identifier" && callee.value === "createRoute";
|
|
169
|
-
}
|
|
170
|
-
function getPropertyName(kv) {
|
|
171
|
-
if (kv.key.type === "Identifier")
|
|
172
|
-
return kv.key.value;
|
|
173
|
-
if (kv.key.type === "StringLiteral")
|
|
174
|
-
return kv.key.value;
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
1
|
+
export { analyzeRoutes, detectServerRouteExports, extractClientRoutes, extractClientRoutesFromAst, extractServerRoutes, extractServerRoutesFromAst, resolveRoutes, } from "./routes/index.js";
|
|
177
2
|
//# sourceMappingURL=routes.js.map
|
package/esm/routes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,0BAA0B,EAC1B,aAAa,GACd,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-fns.d.ts","sourceRoot":"","sources":["../src/server-fns.ts"],"names":[],"mappings":"AAIA,2EAA2E;AAC3E,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAUrE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { parseSync } from "@swc/core";
|
|
2
|
+
import { extractExportNames } from "./transforms/utils.js";
|
|
3
|
+
import { detectUseServer } from "./utils.js";
|
|
4
|
+
/** Extract exported server function names from a `"use server"` module. */
|
|
5
|
+
export function extractServerFunctionExports(source) {
|
|
6
|
+
if (!detectUseServer(source))
|
|
7
|
+
return [];
|
|
8
|
+
const ast = parseSync(source, {
|
|
9
|
+
syntax: "typescript",
|
|
10
|
+
tsx: true,
|
|
11
|
+
target: "esnext",
|
|
12
|
+
});
|
|
13
|
+
return extractExportNames(ast.body);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=server-fns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-fns.js","sourceRoot":"","sources":["../src/server-fns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,2EAA2E;AAC3E,MAAM,UAAU,4BAA4B,CAAC,MAAc;IACzD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,CAAC;IAExC,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,EAAE;QAC5B,MAAM,EAAE,YAAY;QACpB,GAAG,EAAE,IAAI;QACT,MAAM,EAAE,QAAQ;KACjB,CAAC,CAAC;IAEH,OAAO,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transforms/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAa,MAAM,WAAW,CAAC;AACnD,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transforms/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAa,MAAM,WAAW,CAAC;AACnD,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAehE,0EAA0E;AAC1E,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EAAE,EACrB,OAAO,EAAE,gBAAgB,GACxB,MAAM,CA4BR"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { parseSync } from "@swc/core";
|
|
2
2
|
import { RUNTIME } from "../../types.js";
|
|
3
|
-
import { makeFnId
|
|
3
|
+
import { makeFnId } from "../../utils.js";
|
|
4
4
|
/** Notify the manifest collector about each server function. */
|
|
5
5
|
function reportToManifest(exportNames, options) {
|
|
6
6
|
if (!options.onServerFn)
|
|
7
7
|
return;
|
|
8
|
-
const moduleId = makeModuleId(options.rootContext, options.resourcePath);
|
|
9
8
|
for (const name of exportNames) {
|
|
10
9
|
const fnId = makeFnId(options.rootContext, options.resourcePath, name);
|
|
11
|
-
options.onServerFn(fnId
|
|
10
|
+
options.onServerFn(fnId);
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
13
|
/** Server build: inject import and appends registrations as AST nodes. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transforms/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,SAAS,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,OAAO,EAAyB,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transforms/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,SAAS,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,OAAO,EAAyB,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,gEAAgE;AAChE,SAAS,gBAAgB,CACvB,WAAqB,EACrB,OAAyB;IAEzB,IAAI,CAAC,OAAO,CAAC,UAAU;QAAE,OAAO;IAChC,KAA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AE,EAAE,CAAC;QAC/C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/esm/types.d.ts
CHANGED
|
@@ -29,10 +29,7 @@ export interface TransformOptions {
|
|
|
29
29
|
/** Whether this is a server-side build. */
|
|
30
30
|
isServer: boolean;
|
|
31
31
|
/** Callback to register a server function in the manifest. */
|
|
32
|
-
onServerFn?: (fnId: string
|
|
33
|
-
moduleId: string;
|
|
34
|
-
export: string;
|
|
35
|
-
}) => void;
|
|
32
|
+
onServerFn?: (fnId: string) => void;
|
|
36
33
|
}
|
|
37
34
|
/**
|
|
38
35
|
* Runtime identifiers used in generated code.
|
package/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,0DAA0D;AAC1D,MAAM,WAAW,eAAe;IAC9B,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,oDAAoD;AACpD,MAAM,WAAW,gBAAgB;IAC/B,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,QAAQ,EAAE,OAAO,CAAC;IAClB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,0DAA0D;AAC1D,MAAM,WAAW,eAAe;IAC9B,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,oDAAoD;AACpD,MAAM,WAAW,gBAAgB;IAC/B,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,QAAQ,EAAE,OAAO,CAAC;IAClB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO;IAClB,8EAA8E;;IAE9E,mFAAmF;;IAEnF,mDAAmD;;IAEnD,0DAA0D;;IAE1D,6DAA6D;;IAE7D,uDAAuD;;CAE/C,CAAC"}
|
package/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAoCA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,8EAA8E;IAC9E,YAAY,EAAE,uBAAuB;IACrC,mFAAmF;IACnF,SAAS,EAAE,cAAc;IACzB,mDAAmD;IACnD,qBAAqB,EAAE,wBAAwB;IAC/C,0DAA0D;IAC1D,uBAAuB,EAAE,yBAAyB;IAClD,6DAA6D;IAC7D,qBAAqB,EAAE,uBAAuB;IAC9C,uDAAuD;IACvD,UAAU,EAAE,YAAY;CAChB,CAAC"}
|
package/esm/utils.d.ts
CHANGED
|
@@ -3,10 +3,15 @@ export declare function parseModuleRef(ref: string): {
|
|
|
3
3
|
module: string;
|
|
4
4
|
exportName: string;
|
|
5
5
|
};
|
|
6
|
-
/** Hash a string to a 16-character hex digest (SHA-256, truncated). */
|
|
7
|
-
export declare function hashString(input: string): string;
|
|
8
6
|
/** Derive a stable module ID from a file path relative to root. */
|
|
9
7
|
export declare function makeModuleId(rootContext: string, resourcePath: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Hash a server function using Utoopack's server-reference action ID algorithm.
|
|
10
|
+
*
|
|
11
|
+
* Keep this aligned with:
|
|
12
|
+
* https://github.com/utooland/utoo/blob/cbb5e27ba92c593dc1d709ba74aa154227b03e57/crates/pack-core/src/server_reference/proxy.rs#L28-L36
|
|
13
|
+
*/
|
|
14
|
+
export declare function hashServerFunction(moduleId: string, exportName: string): string;
|
|
10
15
|
/** Derive a stable function ID from the file path and export name. */
|
|
11
16
|
export declare function makeFnId(rootContext: string, resourcePath: string, exportName: string): string;
|
|
12
17
|
/** Check whether the source starts with the "use server" directive. */
|
package/esm/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAIA,gDAAgD;AAChD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAQA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAIA,gDAAgD;AAChD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAQA;AAOD,mEAAmE;AACnE,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB,MAAM,CAER;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,MAAM,CAER;AAED,sEAAsE;AACtE,wBAAgB,QAAQ,CACtB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,MAAM,CAKR;AAED,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAiCvD"}
|
package/esm/utils.js
CHANGED
|
@@ -10,17 +10,28 @@ export function parseModuleRef(ref) {
|
|
|
10
10
|
return { module: ref.slice(0, idx), exportName: ref.slice(idx + 1) };
|
|
11
11
|
}
|
|
12
12
|
/** Hash a string to a 16-character hex digest (SHA-256, truncated). */
|
|
13
|
-
|
|
13
|
+
function hashString(input) {
|
|
14
14
|
return createHash("sha256").update(input).digest("hex").slice(0, 16);
|
|
15
15
|
}
|
|
16
16
|
/** Derive a stable module ID from a file path relative to root. */
|
|
17
17
|
export function makeModuleId(rootContext, resourcePath) {
|
|
18
18
|
return hashString(path.relative(rootContext, resourcePath));
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Hash a server function using Utoopack's server-reference action ID algorithm.
|
|
22
|
+
*
|
|
23
|
+
* Keep this aligned with:
|
|
24
|
+
* https://github.com/utooland/utoo/blob/cbb5e27ba92c593dc1d709ba74aa154227b03e57/crates/pack-core/src/server_reference/proxy.rs#L28-L36
|
|
25
|
+
*/
|
|
26
|
+
export function hashServerFunction(moduleId, exportName) {
|
|
27
|
+
return hashString(`${moduleId}#${exportName}`);
|
|
28
|
+
}
|
|
20
29
|
/** Derive a stable function ID from the file path and export name. */
|
|
21
30
|
export function makeFnId(rootContext, resourcePath, exportName) {
|
|
22
|
-
const
|
|
23
|
-
|
|
31
|
+
const moduleId = path
|
|
32
|
+
.relative(rootContext, resourcePath)
|
|
33
|
+
.replaceAll("\\", "/");
|
|
34
|
+
return hashServerFunction(moduleId, exportName);
|
|
24
35
|
}
|
|
25
36
|
/** Check whether the source starts with the "use server" directive. */
|
|
26
37
|
export function detectUseServer(source) {
|
package/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,gDAAgD;AAChD,MAAM,UAAU,cAAc,CAAC,GAAW;IAIxC,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,6BAA6B,GAAG,0CAA0C,CAC3E,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC;AACvE,CAAC;AAED,uEAAuE;AACvE,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,gDAAgD;AAChD,MAAM,UAAU,cAAc,CAAC,GAAW;IAIxC,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,6BAA6B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