@devlusoft/devix 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist/cli/build.js +145 -6
- package/dist/cli/build.js.map +4 -4
- package/dist/cli/dev.js +155 -4
- package/dist/cli/dev.js.map +4 -4
- package/dist/cli/generate.js +174 -12
- package/dist/cli/generate.js.map +4 -4
- package/dist/cli/index.js +200 -18
- package/dist/cli/index.js.map +4 -4
- package/dist/cli/start.js +12 -0
- package/dist/cli/start.js.map +3 -3
- package/dist/runtime/api-context.d.ts +3 -2
- package/dist/runtime/api-context.js.map +1 -1
- package/dist/runtime/fetch.d.ts +19 -0
- package/dist/runtime/fetch.js +35 -0
- package/dist/runtime/fetch.js.map +7 -0
- package/dist/runtime/index.d.ts +6 -1
- package/dist/runtime/index.js +68 -0
- package/dist/runtime/index.js.map +3 -3
- package/dist/server/api-router.d.ts +1 -0
- package/dist/server/api-router.js +1 -0
- package/dist/server/api-router.js.map +2 -2
- package/dist/server/api.js +1 -0
- package/dist/server/api.js.map +2 -2
- package/dist/server/index.js.map +2 -2
- package/dist/utils/cookies.d.ts +12 -0
- package/dist/utils/cookies.js +29 -0
- package/dist/utils/cookies.js.map +7 -0
- package/dist/utils/env.d.ts +1 -0
- package/dist/utils/env.js +14 -0
- package/dist/utils/env.js.map +7 -0
- package/dist/utils/response.d.ts +3 -0
- package/dist/utils/response.js +10 -0
- package/dist/utils/response.js.map +7 -0
- package/dist/vite/codegen/extract-methods.d.ts +4 -0
- package/dist/vite/codegen/extract-methods.js +16 -0
- package/dist/vite/codegen/extract-methods.js.map +7 -0
- package/dist/vite/codegen/routes-dts.d.ts +10 -0
- package/dist/vite/codegen/routes-dts.js +61 -0
- package/dist/vite/codegen/routes-dts.js.map +7 -0
- package/dist/vite/codegen/scan-api.d.ts +2 -0
- package/dist/vite/codegen/scan-api.js +78 -0
- package/dist/vite/codegen/scan-api.js.map +7 -0
- package/dist/vite/codegen/write-routes-dts.d.ts +1 -0
- package/dist/vite/codegen/write-routes-dts.js +17 -0
- package/dist/vite/codegen/write-routes-dts.js.map +7 -0
- package/dist/vite/index.js +143 -4
- package/dist/vite/index.js.map +4 -4
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/response.ts"],
|
|
4
|
+
"sourcesContent": ["export const json = (data: unknown, status = 200): Response =>\n Response.json(data, {status})\n\nexport const text = (body: string, status = 200): Response =>\n new Response(body, {status, headers: {'Content-Type': 'text/plain; charset=utf-8'}})\n\nexport const redirect = (url: string, status = 302): Response =>\n new Response(null, {status, headers: {Location: url}})\n"],
|
|
5
|
+
"mappings": ";AAAO,IAAM,OAAO,CAAC,MAAe,SAAS,QACzC,SAAS,KAAK,MAAM,EAAC,OAAM,CAAC;AAEzB,IAAM,OAAO,CAAC,MAAc,SAAS,QACxC,IAAI,SAAS,MAAM,EAAC,QAAQ,SAAS,EAAC,gBAAgB,4BAA2B,EAAC,CAAC;AAEhF,IAAM,WAAW,CAAC,KAAa,SAAS,QAC3C,IAAI,SAAS,MAAM,EAAC,QAAQ,SAAS,EAAC,UAAU,IAAG,EAAC,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/vite/codegen/extract-methods.ts
|
|
2
|
+
var METHOD_EXPORT_RE = /export\s+(?:const|async\s+function|function)\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g;
|
|
3
|
+
function stripComments(content) {
|
|
4
|
+
return content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
|
|
5
|
+
}
|
|
6
|
+
function extractHttpMethods(content) {
|
|
7
|
+
const found = /* @__PURE__ */ new Set();
|
|
8
|
+
for (const match of stripComments(content).matchAll(METHOD_EXPORT_RE)) {
|
|
9
|
+
found.add(match[1]);
|
|
10
|
+
}
|
|
11
|
+
return [...found];
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
extractHttpMethods
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=extract-methods.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/vite/codegen/extract-methods.ts"],
|
|
4
|
+
"sourcesContent": ["const HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'] as const\nexport type HttpMethod = (typeof HTTP_METHODS)[number]\n\nconst METHOD_EXPORT_RE = /export\\s+(?:const|async\\s+function|function)\\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\\b/g\n\nfunction stripComments(content: string): string {\n return content\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n .replace(/\\/\\/.*$/gm, '')\n}\n\nexport function extractHttpMethods(content: string): HttpMethod[] {\n const found = new Set<HttpMethod>()\n for (const match of stripComments(content).matchAll(METHOD_EXPORT_RE)) {\n found.add(match[1] as HttpMethod)\n }\n return [...found]\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,IAAM,mBAAmB;AAEzB,SAAS,cAAc,SAAyB;AAC5C,SAAO,QACF,QAAQ,qBAAqB,EAAE,EAC/B,QAAQ,aAAa,EAAE;AAChC;AAEO,SAAS,mBAAmB,SAA+B;AAC9D,QAAM,QAAQ,oBAAI,IAAgB;AAClC,aAAW,SAAS,cAAc,OAAO,EAAE,SAAS,gBAAgB,GAAG;AACnE,UAAM,IAAI,MAAM,CAAC,CAAe;AAAA,EACpC;AACA,SAAO,CAAC,GAAG,KAAK;AACpB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HttpMethod } from './extract-methods';
|
|
2
|
+
export interface RouteEntry {
|
|
3
|
+
filePath: string;
|
|
4
|
+
urlPattern: string;
|
|
5
|
+
identifier: string;
|
|
6
|
+
methods: HttpMethod[];
|
|
7
|
+
}
|
|
8
|
+
export declare function filePathToIdentifier(filePath: string, apiDir: string): string;
|
|
9
|
+
export declare function buildRouteEntry(filePath: string, apiDir: string, methods: HttpMethod[]): RouteEntry;
|
|
10
|
+
export declare function generateRoutesDts(entries: RouteEntry[], apiDir: string): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/utils/patterns.ts
|
|
2
|
+
function routePattern(rel) {
|
|
3
|
+
return rel.replace(/\.(tsx|ts|jsx|js)$/, "").replace(/\(.*?\)\//g, "").replace(/^index$|\/index$/, "").replace(/\[([^\]]+)]/g, ":$1") || "/";
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/server/api-router.ts
|
|
7
|
+
function keyToRoutePattern(key, apiDir) {
|
|
8
|
+
const rel = key.slice(apiDir.length + 1).replace(/\\/g, "/");
|
|
9
|
+
const pattern = routePattern(rel);
|
|
10
|
+
return pattern === "/" ? "/api" : `/api/${pattern}`.replace("/api//", "/api/");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/vite/codegen/routes-dts.ts
|
|
14
|
+
function filePathToIdentifier(filePath, apiDir) {
|
|
15
|
+
return "_api_" + filePath.slice(`${apiDir}/`.length).replace(/\.(ts|tsx)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
16
|
+
}
|
|
17
|
+
function buildRouteEntry(filePath, apiDir, methods) {
|
|
18
|
+
return {
|
|
19
|
+
filePath,
|
|
20
|
+
urlPattern: keyToRoutePattern(filePath, apiDir),
|
|
21
|
+
identifier: filePathToIdentifier(filePath, apiDir),
|
|
22
|
+
methods
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function generateRoutesDts(entries, apiDir) {
|
|
26
|
+
if (entries.length === 0) {
|
|
27
|
+
return `// auto-generado por devix \u2014 no editar
|
|
28
|
+
declare module '@devlusoft/devix' {
|
|
29
|
+
interface ApiRoutes {}
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
}
|
|
33
|
+
const imports = entries.map((e) => {
|
|
34
|
+
const importPath = "../" + e.filePath.replace(/\.(ts|tsx)$/, "");
|
|
35
|
+
return `import type * as ${e.identifier} from '${importPath}'`;
|
|
36
|
+
}).join("\n");
|
|
37
|
+
const routeLines = entries.flatMap(
|
|
38
|
+
(e) => e.methods.map(
|
|
39
|
+
(m) => ` '${m} ${e.urlPattern}': InferRoute<(typeof ${e.identifier})['${m}']>`
|
|
40
|
+
)
|
|
41
|
+
).join("\n");
|
|
42
|
+
return `// auto-generado por devix \u2014 no editar
|
|
43
|
+
${imports}
|
|
44
|
+
|
|
45
|
+
type InferRoute<T> = T extends (...args: any[]) => any
|
|
46
|
+
? Exclude<Awaited<ReturnType<T>>, Response | null | void>
|
|
47
|
+
: never
|
|
48
|
+
|
|
49
|
+
declare module '@devlusoft/devix' {
|
|
50
|
+
interface ApiRoutes {
|
|
51
|
+
${routeLines}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
buildRouteEntry,
|
|
58
|
+
filePathToIdentifier,
|
|
59
|
+
generateRoutesDts
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=routes-dts.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/patterns.ts", "../../../src/server/api-router.ts", "../../../src/vite/codegen/routes-dts.ts"],
|
|
4
|
+
"sourcesContent": ["export function routePattern(rel: string): string {\n return rel\n .replace(/\\.(tsx|ts|jsx|js)$/, '')\n .replace(/\\(.*?\\)\\//g, '')\n .replace(/^index$|\\/index$/, '')\n .replace(/\\[([^\\]]+)]/g, ':$1')\n || '/'\n}", "import {routePattern} from \"../utils/patterns\";\n\nexport interface ApiRoute {\n path: string\n key: string\n params: string[]\n regex: RegExp\n}\n\nexport interface ApiMiddleware {\n dir: string\n key: string\n}\n\nexport interface ApiResult {\n routes: ApiRoute[]\n middlewares: ApiMiddleware[]\n}\n\nexport function keyToRoutePattern(key: string, apiDir: string): string {\n const rel = key.slice(apiDir.length + 1).replace(/\\\\/g, '/')\n const pattern = routePattern(rel)\n return pattern === '/' ? '/api' : `/api/${pattern}`.replace('/api//', '/api/')\n}\n\nfunction keyToDir(key: string): string {\n return key.slice(0, key.lastIndexOf('/'))\n}\n\nlet cache: ApiResult | null = null\n\nexport function invalidateApiCache() {\n cache = null\n}\n\nexport function buildRoutes(routeKeys: string[], middlewareKeys: string[], apiDir: string): ApiResult {\n if (cache) return cache\n\n const routes: ApiRoute[] = []\n const middlewares: ApiMiddleware[] = []\n\n for (const key of middlewareKeys) {\n middlewares.push({dir: keyToDir(key), key})\n }\n\n for (const key of routeKeys) {\n const pattern = keyToRoutePattern(key, apiDir)\n const params = [...pattern.matchAll(/:([^/]+)/g)].map(m => m[1])\n const regexStr = pattern\n .replace(/:[^/]+/g, '([^/]+)')\n .replace(/\\//g, '\\\\/')\n routes.push({path: pattern, key, params, regex: new RegExp(`^${regexStr}$`)})\n }\n routes.sort((a, b) => {\n const aScore = (a.path.match(/:/g) || []).length\n const bScore = (b.path.match(/:/g) || []).length\n if (aScore !== bScore) return aScore - bScore\n return b.path.length - a.path.length\n })\n\n cache = {routes, middlewares}\n return cache\n}\n\nexport function collectMiddlewareChain(routeKey: string, middlewares: ApiMiddleware[]): ApiMiddleware[] {\n const routeDir = keyToDir(routeKey)\n\n return middlewares\n .filter(mw => routeDir.startsWith(mw.dir))\n .sort((a, b) => a.dir.split('/').length - b.dir.split('/').length)\n}\n\nexport function matchRoute(\n pathname: string,\n routes: ApiRoute[]\n): {route: ApiRoute; params: Record<string, string>} | null {\n for (const route of routes) {\n const match = pathname.match(route.regex)\n if (match) {\n const params: Record<string, string> = {}\n route.params.forEach((name, i) => {\n params[name] = decodeURIComponent(match[i + 1])\n })\n return {route, params}\n }\n }\n return null\n}\n", "import { keyToRoutePattern } from '../../server/api-router'\nimport type { HttpMethod } from './extract-methods'\n\nexport interface RouteEntry {\n filePath: string\n urlPattern: string\n identifier: string\n methods: HttpMethod[]\n}\n\nexport function filePathToIdentifier(filePath: string, apiDir: string): string {\n return '_api_' + filePath\n .slice(`${apiDir}/`.length)\n .replace(/\\.(ts|tsx)$/, '')\n .replace(/[^a-zA-Z0-9]/g, '_')\n}\n\nexport function buildRouteEntry(filePath: string, apiDir: string, methods: HttpMethod[]): RouteEntry {\n return {\n filePath,\n urlPattern: keyToRoutePattern(filePath, apiDir),\n identifier: filePathToIdentifier(filePath, apiDir),\n methods,\n }\n}\n\nexport function generateRoutesDts(entries: RouteEntry[], apiDir: string): string {\n if (entries.length === 0) {\n return `// auto-generado por devix \u2014 no editar\\ndeclare module '@devlusoft/devix' {\\n interface ApiRoutes {}\\n}\\n`\n }\n\n const imports = entries\n .map(e => {\n const importPath = '../' + e.filePath.replace(/\\.(ts|tsx)$/, '')\n return `import type * as ${e.identifier} from '${importPath}'`\n })\n .join('\\n')\n\n const routeLines = entries.flatMap(e =>\n e.methods.map(m =>\n ` '${m} ${e.urlPattern}': InferRoute<(typeof ${e.identifier})['${m}']>`\n )\n ).join('\\n')\n\n return `// auto-generado por devix \u2014 no editar\n${imports}\n\ntype InferRoute<T> = T extends (...args: any[]) => any\n ? Exclude<Awaited<ReturnType<T>>, Response | null | void>\n : never\n\ndeclare module '@devlusoft/devix' {\n interface ApiRoutes {\n${routeLines}\n }\n}\n`\n}\n"],
|
|
5
|
+
"mappings": ";AAAO,SAAS,aAAa,KAAqB;AAC9C,SAAO,IACE,QAAQ,sBAAsB,EAAE,EAChC,QAAQ,cAAc,EAAE,EACxB,QAAQ,oBAAoB,EAAE,EAC9B,QAAQ,gBAAgB,KAAK,KAC/B;AACX;;;ACYO,SAAS,kBAAkB,KAAa,QAAwB;AACnE,QAAM,MAAM,IAAI,MAAM,OAAO,SAAS,CAAC,EAAE,QAAQ,OAAO,GAAG;AAC3D,QAAM,UAAU,aAAa,GAAG;AAChC,SAAO,YAAY,MAAM,SAAS,QAAQ,OAAO,GAAG,QAAQ,UAAU,OAAO;AACjF;;;ACbO,SAAS,qBAAqB,UAAkB,QAAwB;AAC3E,SAAO,UAAU,SACZ,MAAM,GAAG,MAAM,IAAI,MAAM,EACzB,QAAQ,eAAe,EAAE,EACzB,QAAQ,iBAAiB,GAAG;AACrC;AAEO,SAAS,gBAAgB,UAAkB,QAAgB,SAAmC;AACjG,SAAO;AAAA,IACH;AAAA,IACA,YAAY,kBAAkB,UAAU,MAAM;AAAA,IAC9C,YAAY,qBAAqB,UAAU,MAAM;AAAA,IACjD;AAAA,EACJ;AACJ;AAEO,SAAS,kBAAkB,SAAuB,QAAwB;AAC7E,MAAI,QAAQ,WAAW,GAAG;AACtB,WAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EACX;AAEA,QAAM,UAAU,QACX,IAAI,OAAK;AACN,UAAM,aAAa,QAAQ,EAAE,SAAS,QAAQ,eAAe,EAAE;AAC/D,WAAO,oBAAoB,EAAE,UAAU,UAAU,UAAU;AAAA,EAC/D,CAAC,EACA,KAAK,IAAI;AAEd,QAAM,aAAa,QAAQ;AAAA,IAAQ,OAC/B,EAAE,QAAQ;AAAA,MAAI,OACV,QAAQ,CAAC,IAAI,EAAE,UAAU,yBAAyB,EAAE,UAAU,MAAM,CAAC;AAAA,IACzE;AAAA,EACJ,EAAE,KAAK,IAAI;AAEX,SAAO;AAAA,EACT,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP,UAAU;AAAA;AAAA;AAAA;AAIZ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/vite/codegen/scan-api.ts
|
|
2
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
3
|
+
import { join, relative } from "node:path";
|
|
4
|
+
|
|
5
|
+
// src/vite/codegen/extract-methods.ts
|
|
6
|
+
var METHOD_EXPORT_RE = /export\s+(?:const|async\s+function|function)\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g;
|
|
7
|
+
function stripComments(content) {
|
|
8
|
+
return content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
|
|
9
|
+
}
|
|
10
|
+
function extractHttpMethods(content) {
|
|
11
|
+
const found = /* @__PURE__ */ new Set();
|
|
12
|
+
for (const match of stripComments(content).matchAll(METHOD_EXPORT_RE)) {
|
|
13
|
+
found.add(match[1]);
|
|
14
|
+
}
|
|
15
|
+
return [...found];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/utils/patterns.ts
|
|
19
|
+
function routePattern(rel) {
|
|
20
|
+
return rel.replace(/\.(tsx|ts|jsx|js)$/, "").replace(/\(.*?\)\//g, "").replace(/^index$|\/index$/, "").replace(/\[([^\]]+)]/g, ":$1") || "/";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/server/api-router.ts
|
|
24
|
+
function keyToRoutePattern(key, apiDir) {
|
|
25
|
+
const rel = key.slice(apiDir.length + 1).replace(/\\/g, "/");
|
|
26
|
+
const pattern = routePattern(rel);
|
|
27
|
+
return pattern === "/" ? "/api" : `/api/${pattern}`.replace("/api//", "/api/");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/vite/codegen/routes-dts.ts
|
|
31
|
+
function filePathToIdentifier(filePath, apiDir) {
|
|
32
|
+
return "_api_" + filePath.slice(`${apiDir}/`.length).replace(/\.(ts|tsx)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
33
|
+
}
|
|
34
|
+
function buildRouteEntry(filePath, apiDir, methods) {
|
|
35
|
+
return {
|
|
36
|
+
filePath,
|
|
37
|
+
urlPattern: keyToRoutePattern(filePath, apiDir),
|
|
38
|
+
identifier: filePathToIdentifier(filePath, apiDir),
|
|
39
|
+
methods
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/vite/codegen/scan-api.ts
|
|
44
|
+
function walkDir(dir, root) {
|
|
45
|
+
const entries = [];
|
|
46
|
+
for (const name of readdirSync(dir)) {
|
|
47
|
+
const full = join(dir, name);
|
|
48
|
+
if (statSync(full).isDirectory()) {
|
|
49
|
+
entries.push(...walkDir(full, root));
|
|
50
|
+
} else if (/\.(ts|tsx)$/.test(name)) {
|
|
51
|
+
entries.push(relative(root, full).replace(/\\/g, "/"));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return entries;
|
|
55
|
+
}
|
|
56
|
+
function scanApiFiles(appDir, projectRoot) {
|
|
57
|
+
const apiDir = join(projectRoot, appDir, "api");
|
|
58
|
+
let files;
|
|
59
|
+
try {
|
|
60
|
+
files = walkDir(apiDir, projectRoot);
|
|
61
|
+
} catch {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
return files.filter((f) => !f.endsWith("middleware.ts") && !f.endsWith("middleware.tsx")).flatMap((filePath) => {
|
|
65
|
+
try {
|
|
66
|
+
const content = readFileSync(join(projectRoot, filePath), "utf-8");
|
|
67
|
+
const methods = extractHttpMethods(content);
|
|
68
|
+
if (methods.length === 0) return [];
|
|
69
|
+
return [buildRouteEntry(filePath, `${appDir}/api`, methods)];
|
|
70
|
+
} catch {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
scanApiFiles
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=scan-api.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/vite/codegen/scan-api.ts", "../../../src/vite/codegen/extract-methods.ts", "../../../src/utils/patterns.ts", "../../../src/server/api-router.ts", "../../../src/vite/codegen/routes-dts.ts"],
|
|
4
|
+
"sourcesContent": ["import {readFileSync, readdirSync, statSync} from 'node:fs'\nimport {join, relative} from 'node:path'\nimport {extractHttpMethods} from './extract-methods'\nimport {buildRouteEntry} from './routes-dts'\nimport type {RouteEntry} from './routes-dts'\n\nfunction walkDir(dir: string, root: string): string[] {\n const entries: string[] = []\n for (const name of readdirSync(dir)) {\n const full = join(dir, name)\n if (statSync(full).isDirectory()) {\n entries.push(...walkDir(full, root))\n } else if (/\\.(ts|tsx)$/.test(name)) {\n entries.push(relative(root, full).replace(/\\\\/g, '/'))\n }\n }\n return entries\n}\n\nexport function scanApiFiles(appDir: string, projectRoot: string): RouteEntry[] {\n const apiDir = join(projectRoot, appDir, 'api')\n\n let files: string[]\n try {\n files = walkDir(apiDir, projectRoot)\n } catch {\n return []\n }\n\n return files\n .filter(f => !f.endsWith('middleware.ts') && !f.endsWith('middleware.tsx'))\n .flatMap(filePath => {\n try {\n const content = readFileSync(join(projectRoot, filePath), 'utf-8')\n const methods = extractHttpMethods(content)\n if (methods.length === 0) return []\n return [buildRouteEntry(filePath, `${appDir}/api`, methods)]\n } catch {\n return []\n }\n })\n}\n", "const HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'] as const\nexport type HttpMethod = (typeof HTTP_METHODS)[number]\n\nconst METHOD_EXPORT_RE = /export\\s+(?:const|async\\s+function|function)\\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\\b/g\n\nfunction stripComments(content: string): string {\n return content\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n .replace(/\\/\\/.*$/gm, '')\n}\n\nexport function extractHttpMethods(content: string): HttpMethod[] {\n const found = new Set<HttpMethod>()\n for (const match of stripComments(content).matchAll(METHOD_EXPORT_RE)) {\n found.add(match[1] as HttpMethod)\n }\n return [...found]\n}\n", "export function routePattern(rel: string): string {\n return rel\n .replace(/\\.(tsx|ts|jsx|js)$/, '')\n .replace(/\\(.*?\\)\\//g, '')\n .replace(/^index$|\\/index$/, '')\n .replace(/\\[([^\\]]+)]/g, ':$1')\n || '/'\n}", "import {routePattern} from \"../utils/patterns\";\n\nexport interface ApiRoute {\n path: string\n key: string\n params: string[]\n regex: RegExp\n}\n\nexport interface ApiMiddleware {\n dir: string\n key: string\n}\n\nexport interface ApiResult {\n routes: ApiRoute[]\n middlewares: ApiMiddleware[]\n}\n\nexport function keyToRoutePattern(key: string, apiDir: string): string {\n const rel = key.slice(apiDir.length + 1).replace(/\\\\/g, '/')\n const pattern = routePattern(rel)\n return pattern === '/' ? '/api' : `/api/${pattern}`.replace('/api//', '/api/')\n}\n\nfunction keyToDir(key: string): string {\n return key.slice(0, key.lastIndexOf('/'))\n}\n\nlet cache: ApiResult | null = null\n\nexport function invalidateApiCache() {\n cache = null\n}\n\nexport function buildRoutes(routeKeys: string[], middlewareKeys: string[], apiDir: string): ApiResult {\n if (cache) return cache\n\n const routes: ApiRoute[] = []\n const middlewares: ApiMiddleware[] = []\n\n for (const key of middlewareKeys) {\n middlewares.push({dir: keyToDir(key), key})\n }\n\n for (const key of routeKeys) {\n const pattern = keyToRoutePattern(key, apiDir)\n const params = [...pattern.matchAll(/:([^/]+)/g)].map(m => m[1])\n const regexStr = pattern\n .replace(/:[^/]+/g, '([^/]+)')\n .replace(/\\//g, '\\\\/')\n routes.push({path: pattern, key, params, regex: new RegExp(`^${regexStr}$`)})\n }\n routes.sort((a, b) => {\n const aScore = (a.path.match(/:/g) || []).length\n const bScore = (b.path.match(/:/g) || []).length\n if (aScore !== bScore) return aScore - bScore\n return b.path.length - a.path.length\n })\n\n cache = {routes, middlewares}\n return cache\n}\n\nexport function collectMiddlewareChain(routeKey: string, middlewares: ApiMiddleware[]): ApiMiddleware[] {\n const routeDir = keyToDir(routeKey)\n\n return middlewares\n .filter(mw => routeDir.startsWith(mw.dir))\n .sort((a, b) => a.dir.split('/').length - b.dir.split('/').length)\n}\n\nexport function matchRoute(\n pathname: string,\n routes: ApiRoute[]\n): {route: ApiRoute; params: Record<string, string>} | null {\n for (const route of routes) {\n const match = pathname.match(route.regex)\n if (match) {\n const params: Record<string, string> = {}\n route.params.forEach((name, i) => {\n params[name] = decodeURIComponent(match[i + 1])\n })\n return {route, params}\n }\n }\n return null\n}\n", "import { keyToRoutePattern } from '../../server/api-router'\nimport type { HttpMethod } from './extract-methods'\n\nexport interface RouteEntry {\n filePath: string\n urlPattern: string\n identifier: string\n methods: HttpMethod[]\n}\n\nexport function filePathToIdentifier(filePath: string, apiDir: string): string {\n return '_api_' + filePath\n .slice(`${apiDir}/`.length)\n .replace(/\\.(ts|tsx)$/, '')\n .replace(/[^a-zA-Z0-9]/g, '_')\n}\n\nexport function buildRouteEntry(filePath: string, apiDir: string, methods: HttpMethod[]): RouteEntry {\n return {\n filePath,\n urlPattern: keyToRoutePattern(filePath, apiDir),\n identifier: filePathToIdentifier(filePath, apiDir),\n methods,\n }\n}\n\nexport function generateRoutesDts(entries: RouteEntry[], apiDir: string): string {\n if (entries.length === 0) {\n return `// auto-generado por devix \u2014 no editar\\ndeclare module '@devlusoft/devix' {\\n interface ApiRoutes {}\\n}\\n`\n }\n\n const imports = entries\n .map(e => {\n const importPath = '../' + e.filePath.replace(/\\.(ts|tsx)$/, '')\n return `import type * as ${e.identifier} from '${importPath}'`\n })\n .join('\\n')\n\n const routeLines = entries.flatMap(e =>\n e.methods.map(m =>\n ` '${m} ${e.urlPattern}': InferRoute<(typeof ${e.identifier})['${m}']>`\n )\n ).join('\\n')\n\n return `// auto-generado por devix \u2014 no editar\n${imports}\n\ntype InferRoute<T> = T extends (...args: any[]) => any\n ? Exclude<Awaited<ReturnType<T>>, Response | null | void>\n : never\n\ndeclare module '@devlusoft/devix' {\n interface ApiRoutes {\n${routeLines}\n }\n}\n`\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAQ,cAAc,aAAa,gBAAe;AAClD,SAAQ,MAAM,gBAAe;;;ACE7B,IAAM,mBAAmB;AAEzB,SAAS,cAAc,SAAyB;AAC5C,SAAO,QACF,QAAQ,qBAAqB,EAAE,EAC/B,QAAQ,aAAa,EAAE;AAChC;AAEO,SAAS,mBAAmB,SAA+B;AAC9D,QAAM,QAAQ,o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ACX;AAEO,SAAS,aAAa,QAAgB,aAAmC;AAC5E,QAAM,SAAS,KAAK,aAAa,QAAQ,KAAK;AAE9C,MAAI;AACJ,MAAI;AACA,YAAQ,QAAQ,QAAQ,WAAW;AAAA,EACvC,QAAQ;AACJ,WAAO,CAAC;AAAA,EACZ;AAEA,SAAO,MACF,OAAO,OAAK,CAAC,EAAE,SAAS,eAAe,KAAK,CAAC,EAAE,SAAS,gBAAgB,CAAC,EACzE,QAAQ,cAAY;AACjB,QAAI;AACA,YAAM,UAAU,aAAa,KAAK,aAAa,QAAQ,GAAG,OAAO;AACjE,YAAM,UAAU,mBAAmB,OAAO;AAC1C,UAAI,QAAQ,WAAW,EAAG,QAAO,CAAC;AAClC,aAAO,CAAC,gBAAgB,UAAU,GAAG,MAAM,QAAQ,OAAO,CAAC;AAAA,IAC/D,QAAQ;AACJ,aAAO,CAAC;AAAA,IACZ;AAAA,EACJ,CAAC;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function writeRoutesDts(content: string, projectRoot: string): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/vite/codegen/write-routes-dts.ts
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
function writeRoutesDts(content, projectRoot) {
|
|
5
|
+
const devixDir = join(projectRoot, ".devix");
|
|
6
|
+
const outPath = join(devixDir, "routes.d.ts");
|
|
7
|
+
mkdirSync(devixDir, { recursive: true });
|
|
8
|
+
if (existsSync(outPath) && readFileSync(outPath, "utf-8") === content) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
writeFileSync(outPath, content, "utf-8");
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
writeRoutesDts
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=write-routes-dts.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/vite/codegen/write-routes-dts.ts"],
|
|
4
|
+
"sourcesContent": ["import {mkdirSync, readFileSync, writeFileSync, existsSync} from 'node:fs'\nimport {join} from 'node:path'\n\nexport function writeRoutesDts(content: string, projectRoot: string): boolean {\n const devixDir = join(projectRoot, '.devix')\n const outPath = join(devixDir, 'routes.d.ts')\n\n mkdirSync(devixDir, {recursive: true})\n\n if (existsSync(outPath) && readFileSync(outPath, 'utf-8') === content) {\n return false\n }\n\n writeFileSync(outPath, content, 'utf-8')\n return true\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAQ,WAAW,cAAc,eAAe,kBAAiB;AACjE,SAAQ,YAAW;AAEZ,SAAS,eAAe,SAAiB,aAA8B;AAC1E,QAAM,WAAW,KAAK,aAAa,QAAQ;AAC3C,QAAM,UAAU,KAAK,UAAU,aAAa;AAE5C,YAAU,UAAU,EAAC,WAAW,KAAI,CAAC;AAErC,MAAI,WAAW,OAAO,KAAK,aAAa,SAAS,OAAO,MAAM,SAAS;AACnE,WAAO;AAAA,EACX;AAEA,gBAAc,SAAS,SAAS,OAAO;AACvC,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/vite/index.js
CHANGED
|
@@ -146,6 +146,11 @@ export function handleApiRequest(url, request) {
|
|
|
146
146
|
`;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
// src/utils/patterns.ts
|
|
150
|
+
function routePattern(rel) {
|
|
151
|
+
return rel.replace(/\.(tsx|ts|jsx|js)$/, "").replace(/\(.*?\)\//g, "").replace(/^index$|\/index$/, "").replace(/\[([^\]]+)]/g, ":$1") || "/";
|
|
152
|
+
}
|
|
153
|
+
|
|
149
154
|
// src/server/pages-router.ts
|
|
150
155
|
var cache = null;
|
|
151
156
|
function invalidatePagesCache() {
|
|
@@ -153,6 +158,11 @@ function invalidatePagesCache() {
|
|
|
153
158
|
}
|
|
154
159
|
|
|
155
160
|
// src/server/api-router.ts
|
|
161
|
+
function keyToRoutePattern(key, apiDir) {
|
|
162
|
+
const rel = key.slice(apiDir.length + 1).replace(/\\/g, "/");
|
|
163
|
+
const pattern = routePattern(rel);
|
|
164
|
+
return pattern === "/" ? "/api" : `/api/${pattern}`.replace("/api//", "/api/");
|
|
165
|
+
}
|
|
156
166
|
var cache2 = null;
|
|
157
167
|
function invalidateApiCache() {
|
|
158
168
|
cache2 = null;
|
|
@@ -165,6 +175,114 @@ export {RouterContext} from '@devlusoft/devix/runtime/context'
|
|
|
165
175
|
`;
|
|
166
176
|
}
|
|
167
177
|
|
|
178
|
+
// src/vite/codegen/scan-api.ts
|
|
179
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
180
|
+
import { join, relative } from "node:path";
|
|
181
|
+
|
|
182
|
+
// src/vite/codegen/extract-methods.ts
|
|
183
|
+
var METHOD_EXPORT_RE = /export\s+(?:const|async\s+function|function)\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g;
|
|
184
|
+
function stripComments(content) {
|
|
185
|
+
return content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
|
|
186
|
+
}
|
|
187
|
+
function extractHttpMethods(content) {
|
|
188
|
+
const found = /* @__PURE__ */ new Set();
|
|
189
|
+
for (const match of stripComments(content).matchAll(METHOD_EXPORT_RE)) {
|
|
190
|
+
found.add(match[1]);
|
|
191
|
+
}
|
|
192
|
+
return [...found];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/vite/codegen/routes-dts.ts
|
|
196
|
+
function filePathToIdentifier(filePath, apiDir) {
|
|
197
|
+
return "_api_" + filePath.slice(`${apiDir}/`.length).replace(/\.(ts|tsx)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
198
|
+
}
|
|
199
|
+
function buildRouteEntry(filePath, apiDir, methods) {
|
|
200
|
+
return {
|
|
201
|
+
filePath,
|
|
202
|
+
urlPattern: keyToRoutePattern(filePath, apiDir),
|
|
203
|
+
identifier: filePathToIdentifier(filePath, apiDir),
|
|
204
|
+
methods
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function generateRoutesDts(entries, apiDir) {
|
|
208
|
+
if (entries.length === 0) {
|
|
209
|
+
return `// auto-generado por devix \u2014 no editar
|
|
210
|
+
declare module '@devlusoft/devix' {
|
|
211
|
+
interface ApiRoutes {}
|
|
212
|
+
}
|
|
213
|
+
`;
|
|
214
|
+
}
|
|
215
|
+
const imports = entries.map((e) => {
|
|
216
|
+
const importPath = "../" + e.filePath.replace(/\.(ts|tsx)$/, "");
|
|
217
|
+
return `import type * as ${e.identifier} from '${importPath}'`;
|
|
218
|
+
}).join("\n");
|
|
219
|
+
const routeLines = entries.flatMap(
|
|
220
|
+
(e) => e.methods.map(
|
|
221
|
+
(m) => ` '${m} ${e.urlPattern}': InferRoute<(typeof ${e.identifier})['${m}']>`
|
|
222
|
+
)
|
|
223
|
+
).join("\n");
|
|
224
|
+
return `// auto-generado por devix \u2014 no editar
|
|
225
|
+
${imports}
|
|
226
|
+
|
|
227
|
+
type InferRoute<T> = T extends (...args: any[]) => any
|
|
228
|
+
? Exclude<Awaited<ReturnType<T>>, Response | null | void>
|
|
229
|
+
: never
|
|
230
|
+
|
|
231
|
+
declare module '@devlusoft/devix' {
|
|
232
|
+
interface ApiRoutes {
|
|
233
|
+
${routeLines}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/vite/codegen/scan-api.ts
|
|
240
|
+
function walkDir(dir, root) {
|
|
241
|
+
const entries = [];
|
|
242
|
+
for (const name of readdirSync(dir)) {
|
|
243
|
+
const full = join(dir, name);
|
|
244
|
+
if (statSync(full).isDirectory()) {
|
|
245
|
+
entries.push(...walkDir(full, root));
|
|
246
|
+
} else if (/\.(ts|tsx)$/.test(name)) {
|
|
247
|
+
entries.push(relative(root, full).replace(/\\/g, "/"));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return entries;
|
|
251
|
+
}
|
|
252
|
+
function scanApiFiles(appDir, projectRoot) {
|
|
253
|
+
const apiDir = join(projectRoot, appDir, "api");
|
|
254
|
+
let files;
|
|
255
|
+
try {
|
|
256
|
+
files = walkDir(apiDir, projectRoot);
|
|
257
|
+
} catch {
|
|
258
|
+
return [];
|
|
259
|
+
}
|
|
260
|
+
return files.filter((f) => !f.endsWith("middleware.ts") && !f.endsWith("middleware.tsx")).flatMap((filePath) => {
|
|
261
|
+
try {
|
|
262
|
+
const content = readFileSync(join(projectRoot, filePath), "utf-8");
|
|
263
|
+
const methods = extractHttpMethods(content);
|
|
264
|
+
if (methods.length === 0) return [];
|
|
265
|
+
return [buildRouteEntry(filePath, `${appDir}/api`, methods)];
|
|
266
|
+
} catch {
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/vite/codegen/write-routes-dts.ts
|
|
273
|
+
import { mkdirSync, readFileSync as readFileSync2, writeFileSync, existsSync } from "node:fs";
|
|
274
|
+
import { join as join2 } from "node:path";
|
|
275
|
+
function writeRoutesDts(content, projectRoot) {
|
|
276
|
+
const devixDir = join2(projectRoot, ".devix");
|
|
277
|
+
const outPath = join2(devixDir, "routes.d.ts");
|
|
278
|
+
mkdirSync(devixDir, { recursive: true });
|
|
279
|
+
if (existsSync(outPath) && readFileSync2(outPath, "utf-8") === content) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
writeFileSync(outPath, content, "utf-8");
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
|
|
168
286
|
// src/vite/index.ts
|
|
169
287
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
170
288
|
var VIRTUAL_ENTRY_CLIENT = "virtual:devix/entry-client";
|
|
@@ -201,14 +319,35 @@ function devix(config) {
|
|
|
201
319
|
if (id === `\0${VIRTUAL_CONTEXT}`)
|
|
202
320
|
return generateContext();
|
|
203
321
|
},
|
|
322
|
+
buildStart() {
|
|
323
|
+
const root = process.cwd();
|
|
324
|
+
const entries = scanApiFiles(appDir, root);
|
|
325
|
+
writeRoutesDts(generateRoutesDts(entries, `${appDir}/api`), root);
|
|
326
|
+
},
|
|
204
327
|
configureServer(server) {
|
|
328
|
+
const root = process.cwd();
|
|
329
|
+
const regenerateDts = () => {
|
|
330
|
+
const entries = scanApiFiles(appDir, root);
|
|
331
|
+
writeRoutesDts(generateRoutesDts(entries, `${appDir}/api`), root);
|
|
332
|
+
};
|
|
205
333
|
server.watcher.on("add", (file) => {
|
|
206
|
-
if (file.startsWith(resolve(
|
|
207
|
-
if (file.includes(`${appDir}/api`))
|
|
334
|
+
if (file.startsWith(resolve(root, pagesDir))) invalidatePagesCache();
|
|
335
|
+
if (file.includes(`${appDir}/api`)) {
|
|
336
|
+
invalidateApiCache();
|
|
337
|
+
regenerateDts();
|
|
338
|
+
}
|
|
208
339
|
});
|
|
209
340
|
server.watcher.on("unlink", (file) => {
|
|
210
|
-
if (file.startsWith(resolve(
|
|
211
|
-
if (file.includes(`${appDir}/api`))
|
|
341
|
+
if (file.startsWith(resolve(root, pagesDir))) invalidatePagesCache();
|
|
342
|
+
if (file.includes(`${appDir}/api`)) {
|
|
343
|
+
invalidateApiCache();
|
|
344
|
+
regenerateDts();
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
server.watcher.on("change", (file) => {
|
|
348
|
+
if (file.includes(`${appDir}/api`) && !file.endsWith("middleware.ts")) {
|
|
349
|
+
regenerateDts();
|
|
350
|
+
}
|
|
212
351
|
});
|
|
213
352
|
}
|
|
214
353
|
};
|
package/dist/vite/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/vite/index.ts", "../../src/vite/codegen/entry-client.ts", "../../src/vite/codegen/client-routes.ts", "../../src/vite/codegen/render.ts", "../../src/vite/codegen/api.ts", "../../src/server/pages-router.ts", "../../src/server/api-router.ts", "../../src/vite/codegen/context.ts"],
|
|
4
|
-
"sourcesContent": ["import {UserConfig, Plugin, mergeConfig} from 'vite'\nimport type {DevixConfig} from '../config'\nimport react from '@vitejs/plugin-react'\nimport {fileURLToPath} from 'node:url'\nimport {dirname, resolve} from 'node:path'\nimport {generateEntryClient} from './codegen/entry-client'\nimport {generateClientRoutes} from './codegen/client-routes'\nimport {generateRender} from './codegen/render'\nimport {generateApi} from './codegen/api'\nimport {invalidatePagesCache} from \"../server/pages-router\";\nimport {invalidateApiCache} from \"../server/api-router\";\nimport {generateContext} from \"./codegen/context\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\nconst VIRTUAL_ENTRY_CLIENT = 'virtual:devix/entry-client'\nconst VIRTUAL_CLIENT_ROUTES = 'virtual:devix/client-routes'\nconst VIRTUAL_RENDER = 'virtual:devix/render'\nconst VIRTUAL_API = 'virtual:devix/api'\nconst VIRTUAL_CONTEXT = 'virtual:devix/context'\n\nexport function devix(config: DevixConfig): UserConfig {\n const appDir = config.appDir ?? 'app'\n const pagesDir = `${appDir}/pages`\n const cssUrls = (config.css ?? []).map(u => u.startsWith('/') ? u : `/${u.replace(/^\\.\\//, '')}`)\n\n const renderPath = resolve(__dirname, '../server/render.js').replace(/\\\\/g, '/')\n const apiPath = resolve(__dirname, '../server/api.js').replace(/\\\\/g, '/')\n const matcherPath = resolve(__dirname, '../runtime/client-router.js').replace(/\\\\/g, '/')\n\n const virtualPlugin: Plugin = {\n name: 'devix',\n enforce: 'pre',\n\n resolveId(id) {\n if (id === VIRTUAL_ENTRY_CLIENT) return `\\0${VIRTUAL_ENTRY_CLIENT}`\n if (id === VIRTUAL_CLIENT_ROUTES) return `\\0${VIRTUAL_CLIENT_ROUTES}`\n if (id === VIRTUAL_RENDER) return `\\0${VIRTUAL_RENDER}`\n if (id === VIRTUAL_API) return `\\0${VIRTUAL_API}`\n if (id === VIRTUAL_CONTEXT) return `\\0${VIRTUAL_CONTEXT}`\n },\n\n load(id) {\n if (id === `\\0${VIRTUAL_ENTRY_CLIENT}`)\n return generateEntryClient({cssUrls})\n if (id === `\\0${VIRTUAL_CLIENT_ROUTES}`)\n return generateClientRoutes({pagesDir, matcherPath})\n if (id === `\\0${VIRTUAL_RENDER}`)\n return generateRender({pagesDir, renderPath})\n if (id === `\\0${VIRTUAL_API}`)\n return generateApi({apiPath, appDir})\n if (id === `\\0${VIRTUAL_CONTEXT}`)\n return generateContext()\n },\n\n configureServer(server) {\n server.watcher.on('add', (file) => {\n if (file.startsWith(resolve(process.cwd(), pagesDir))) invalidatePagesCache()\n if (file.includes(`${appDir}/api`)) invalidateApiCache()\n })\n server.watcher.on('unlink', (file) => {\n if (file.startsWith(resolve(process.cwd(), pagesDir))) invalidatePagesCache()\n if (file.includes(`${appDir}/api`)) invalidateApiCache()\n })\n },\n }\n\n const base: UserConfig = {\n plugins: [react(), virtualPlugin],\n ssr: {noExternal: ['@devlusoft/devix']},\n ...(config.envPrefix ? {envPrefix: config.envPrefix} : {}),\n }\n\n return mergeConfig(base, config.vite ?? {})\n}", "interface EntryClientOptions {\n cssUrls: string[]\n}\n\nexport function generateEntryClient({cssUrls}: EntryClientOptions): string {\n const cssImports = cssUrls.map(u => `import '${u}'`).join('\\n')\n\n return `\n${cssImports}\nimport \"@vitejs/plugin-react/preamble\"\nimport React from \"react\"\nimport {hydrateRoot, createRoot} from 'react-dom/client'\nimport {matchClientRoute, loadErrorPage, getDefaultErrorPage} from 'virtual:devix/client-routes'\nimport {RouterProvider} from '@devlusoft/devix'\n\nconst root = document.getElementById('devix-root')\n\nif (!window.__DEVIX__) {\n const ErrorPage = getDefaultErrorPage()\n createRoot(root).render(React.createElement(ErrorPage, {statusCode: 500, message: 'Server error'}))\n} else {\n const {metadata, viewport, clientEntry} = window.__DEVIX__\n const loaderData = window.__LOADER_DATA__\n const layoutsData = window.__LAYOUTS_DATA__ ?? []\n\n const matched = matchClientRoute(window.location.pathname)\n\n if (matched) {\n const [pageMod, ...layoutMods] = await Promise.all([\n matched.load(),\n ...matched.loadLayouts.map(l => l()),\n ])\n hydrateRoot(\n root,\n React.createElement(RouterProvider, {\n clientEntry,\n initialData: loaderData,\n initialParams: matched.params,\n initialPage: pageMod.default,\n initialLayouts: layoutMods.map(m => m.default),\n initialLayoutsData: layoutsData,\n initialMeta: metadata,\n initialViewport: viewport,\n })\n )\n } else {\n const ErrorPage = await loadErrorPage() ?? getDefaultErrorPage()\n createRoot(root).render(\n React.createElement(RouterProvider, {\n clientEntry,\n initialData: null,\n initialParams: {},\n initialPage: () => null,\n initialLayouts: [],\n initialLayoutsData: [],\n initialMeta: null,\n initialError: {statusCode: 404, message: 'Not found'},\n initialErrorPage: ErrorPage,\n })\n )\n }\n}\n`\n}", "interface ClientRoutesOptions {\n pagesDir: string\n matcherPath: string\n}\n\nexport function generateClientRoutes({pagesDir, matcherPath}: ClientRoutesOptions) {\n return `\nimport React from 'react'\nimport { createMatcher } from '${matcherPath}'\nconst pageFiles = import.meta.glob(['/${pagesDir}/**/*.tsx', '!**/error.tsx', '!**/layout.tsx'])\nconst layoutFiles = import.meta.glob('/${pagesDir}/**/layout.tsx')\nconst errorFiles = import.meta.glob('/${pagesDir}/**/error.tsx')\n\nexport const matchClientRoute = createMatcher(pageFiles, layoutFiles)\n\nexport async function loadErrorPage() {\n const key = Object.keys(errorFiles)[0]\n if (!key) return null\n const mod = await errorFiles[key]()\n return mod?.default ?? null\n}\n\nexport function getDefaultErrorPage() {\n return function DefaultError({ statusCode, message }) {\n return React.createElement('main', {\n style: { minHeight: '100dvh', display: 'flex', flexDirection: 'column', \n alignItems: 'center', justifyContent: 'center', gap: '8px',\n fontFamily: 'system-ui, sans-serif' }\n },\n React.createElement('h1', {style: {fontSize: '4rem', fontWeight: 700}}, statusCode),\n React.createElement('p', {style: {color: '#666'}}, message ?? 'An unexpected error occurred'),\n )\n }\n}\n`\n}", "interface RenderOptions {\n pagesDir: string\n renderPath: string\n}\n\nexport function generateRender({pagesDir, renderPath}: RenderOptions): string {\n return `\nimport { render as _render, runLoader as _runLoader, getStaticRoutes as _getStaticRoutes } from '${renderPath}'\n\nconst _pages = import.meta.glob(['/${pagesDir}/**/*.tsx', '!**/error.tsx', '!**/layout.tsx'])\nconst _layouts = import.meta.glob('/${pagesDir}/**/layout.tsx')\n\nconst _glob = {\n pages: _pages,\n layouts: _layouts,\n pagesDir: '/${pagesDir}',\n}\n\nexport function render(url, request, options) {\n return _render(url, request, _glob, options)\n}\n\nexport function runLoader(url, request, options) {\n return _runLoader(url, request, _glob, options)\n}\n\nexport function getStaticRoutes() {\n return _getStaticRoutes(_glob)\n}\n`\n}\n", "interface ApiOptions {\n apiPath: string\n appDir: string\n}\n\nexport function generateApi({apiPath, appDir}: ApiOptions): string {\n return `\nimport { handleApiRequest as _handleApiRequest } from '${apiPath}'\n\nconst _routes = import.meta.glob(['/${appDir}/api/**/*.ts', '!**/middleware.ts'])\nconst _middlewares = import.meta.glob('/${appDir}/api/**/middleware.ts')\n\nconst _glob = {\n routes: _routes,\n middlewares: _middlewares,\n apiDir: '/${appDir}/api',\n}\n\nexport function handleApiRequest(url, request) {\n return _handleApiRequest(url, request, _glob)\n}\n`\n}\n", "import {routePattern} from \"../utils/patterns\";\n\nexport interface Page {\n path: string\n key: string\n params: string[]\n regex: RegExp\n}\n\nexport interface Layout {\n dir: string\n key: string\n}\n\nexport interface PagesResult {\n pages: Page[]\n layouts: Layout[]\n}\n\nfunction keyToRoutePattern(key: string, pagesDir: string): string {\n const rel = key.slice(pagesDir.length + 1).replace(/\\\\/g, '/')\n const pattern = routePattern(rel)\n return pattern === \"/\" ? \"/\" : `/${pattern}`\n}\n\nfunction keyToDir(key: string): string {\n return key.slice(0, key.lastIndexOf('/'))\n}\n\nlet cache: PagesResult | null = null\n\nexport function invalidatePagesCache() {\n cache = null\n}\n\nexport function buildPages(pageKeys: string[], layoutKeys: string[], pagesDir: string): PagesResult {\n if (cache) return cache\n\n const pages: Page[] = []\n const layouts: Layout[] = []\n\n for (const key of layoutKeys) {\n layouts.push({dir: keyToDir(key), key})\n }\n\n for (const key of pageKeys) {\n const pattern = keyToRoutePattern(key, pagesDir)\n const params = [...pattern.matchAll(/:([^/]+)/g)].map(m => m[1])\n const regexStr = pattern\n .replace(/:[^/]+/g, '([^/]+)')\n .replace(/\\//g, '\\\\/')\n pages.push({path: pattern, key, params, regex: new RegExp(`^${regexStr}$`)})\n }\n\n pages.sort((a, b) => {\n const aScore = (a.path.match(/:/g) || []).length\n const bScore = (b.path.match(/:/g) || []).length\n if (aScore !== bScore) return aScore - bScore\n return b.path.length - a.path.length\n })\n\n cache = {pages, layouts}\n return cache\n}\n\nexport function collectLayoutChain(pageKey: string, layouts: Layout[]): Layout[] {\n const pageDir = keyToDir(pageKey)\n\n return layouts\n .filter(layout => pageDir.startsWith(layout.dir))\n .sort((a, b) => a.dir.split('/').length - b.dir.split('/').length)\n}\n\nexport function matchPage(pathname: string, pages: Page[]): {\n page: Page\n params: Record<string, string>\n} | null {\n for (const page of pages) {\n const match = pathname.match(page.regex)\n if (match) {\n const params: Record<string, string> = {}\n page.params.forEach((name, i) => {\n params[name] = decodeURIComponent(match[i + 1])\n })\n return {page, params}\n }\n }\n return null\n}\n", "import {routePattern} from \"../utils/patterns\";\n\nexport interface ApiRoute {\n path: string\n key: string\n params: string[]\n regex: RegExp\n}\n\nexport interface ApiMiddleware {\n dir: string\n key: string\n}\n\nexport interface ApiResult {\n routes: ApiRoute[]\n middlewares: ApiMiddleware[]\n}\n\nfunction keyToRoutePattern(key: string, apiDir: string): string {\n const rel = key.slice(apiDir.length + 1).replace(/\\\\/g, '/')\n const pattern = routePattern(rel)\n return pattern === '/' ? '/api' : `/api/${pattern}`.replace('/api//', '/api/')\n}\n\nfunction keyToDir(key: string): string {\n return key.slice(0, key.lastIndexOf('/'))\n}\n\nlet cache: ApiResult | null = null\n\nexport function invalidateApiCache() {\n cache = null\n}\n\nexport function buildRoutes(routeKeys: string[], middlewareKeys: string[], apiDir: string): ApiResult {\n if (cache) return cache\n\n const routes: ApiRoute[] = []\n const middlewares: ApiMiddleware[] = []\n\n for (const key of middlewareKeys) {\n middlewares.push({dir: keyToDir(key), key})\n }\n\n for (const key of routeKeys) {\n const pattern = keyToRoutePattern(key, apiDir)\n const params = [...pattern.matchAll(/:([^/]+)/g)].map(m => m[1])\n const regexStr = pattern\n .replace(/:[^/]+/g, '([^/]+)')\n .replace(/\\//g, '\\\\/')\n routes.push({path: pattern, key, params, regex: new RegExp(`^${regexStr}$`)})\n }\n routes.sort((a, b) => {\n const aScore = (a.path.match(/:/g) || []).length\n const bScore = (b.path.match(/:/g) || []).length\n if (aScore !== bScore) return aScore - bScore\n return b.path.length - a.path.length\n })\n\n cache = {routes, middlewares}\n return cache\n}\n\nexport function collectMiddlewareChain(routeKey: string, middlewares: ApiMiddleware[]): ApiMiddleware[] {\n const routeDir = keyToDir(routeKey)\n\n return middlewares\n .filter(mw => routeDir.startsWith(mw.dir))\n .sort((a, b) => a.dir.split('/').length - b.dir.split('/').length)\n}\n\nexport function matchRoute(\n pathname: string,\n routes: ApiRoute[]\n): {route: ApiRoute; params: Record<string, string>} | null {\n for (const route of routes) {\n const match = pathname.match(route.regex)\n if (match) {\n const params: Record<string, string> = {}\n route.params.forEach((name, i) => {\n params[name] = decodeURIComponent(match[i + 1])\n })\n return {route, params}\n }\n }\n return null\n}\n", "export function generateContext(): string {\n return `\nexport {RouterContext} from '@devlusoft/devix/runtime/context'\n`\n}"],
|
|
5
|
-
"mappings": ";AAAA,SAA4B,mBAAkB;AAE9C,OAAO,WAAW;AAClB,SAAQ,qBAAoB;AAC5B,SAAQ,SAAS,eAAc;;;ACAxB,SAAS,oBAAoB,EAAC,QAAO,GAA+B;AACvE,QAAM,aAAa,QAAQ,IAAI,OAAK,WAAW,CAAC,GAAG,EAAE,KAAK,IAAI;AAE9D,SAAO;AAAA,EACT,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuDZ;;;AC1DO,SAAS,qBAAqB,EAAC,UAAU,YAAW,GAAwB;AAC/E,SAAO;AAAA;AAAA,iCAEsB,WAAW;AAAA,wCACJ,QAAQ;AAAA,yCACP,QAAQ;AAAA,wCACT,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBhD;;;AC9BO,SAAS,eAAe,EAAC,UAAU,WAAU,GAA0B;AAC1E,SAAO;AAAA,mGACwF,UAAU;AAAA;AAAA,qCAExE,QAAQ;AAAA,sCACP,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,kBAK5B,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAe1B;;;ACzBO,SAAS,YAAY,EAAC,SAAS,OAAM,GAAuB;AAC/D,SAAO;AAAA,yDAC8C,OAAO;AAAA;AAAA,sCAE1B,MAAM;AAAA,0CACF,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,gBAKhC,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOtB;;;
|
|
6
|
-
"names": ["cache"]
|
|
3
|
+
"sources": ["../../src/vite/index.ts", "../../src/vite/codegen/entry-client.ts", "../../src/vite/codegen/client-routes.ts", "../../src/vite/codegen/render.ts", "../../src/vite/codegen/api.ts", "../../src/utils/patterns.ts", "../../src/server/pages-router.ts", "../../src/server/api-router.ts", "../../src/vite/codegen/context.ts", "../../src/vite/codegen/scan-api.ts", "../../src/vite/codegen/extract-methods.ts", "../../src/vite/codegen/routes-dts.ts", "../../src/vite/codegen/write-routes-dts.ts"],
|
|
4
|
+
"sourcesContent": ["import {UserConfig, Plugin, mergeConfig} from 'vite'\nimport type {DevixConfig} from '../config'\nimport react from '@vitejs/plugin-react'\nimport {fileURLToPath} from 'node:url'\nimport {dirname, resolve} from 'node:path'\nimport {generateEntryClient} from './codegen/entry-client'\nimport {generateClientRoutes} from './codegen/client-routes'\nimport {generateRender} from './codegen/render'\nimport {generateApi} from './codegen/api'\nimport {invalidatePagesCache} from \"../server/pages-router\";\nimport {invalidateApiCache} from \"../server/api-router\";\nimport {generateContext} from \"./codegen/context\";\nimport {scanApiFiles} from \"./codegen/scan-api\";\nimport {generateRoutesDts} from \"./codegen/routes-dts\";\nimport {writeRoutesDts} from \"./codegen/write-routes-dts\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\nconst VIRTUAL_ENTRY_CLIENT = 'virtual:devix/entry-client'\nconst VIRTUAL_CLIENT_ROUTES = 'virtual:devix/client-routes'\nconst VIRTUAL_RENDER = 'virtual:devix/render'\nconst VIRTUAL_API = 'virtual:devix/api'\nconst VIRTUAL_CONTEXT = 'virtual:devix/context'\n\nexport function devix(config: DevixConfig): UserConfig {\n const appDir = config.appDir ?? 'app'\n const pagesDir = `${appDir}/pages`\n const cssUrls = (config.css ?? []).map(u => u.startsWith('/') ? u : `/${u.replace(/^\\.\\//, '')}`)\n\n const renderPath = resolve(__dirname, '../server/render.js').replace(/\\\\/g, '/')\n const apiPath = resolve(__dirname, '../server/api.js').replace(/\\\\/g, '/')\n const matcherPath = resolve(__dirname, '../runtime/client-router.js').replace(/\\\\/g, '/')\n\n const virtualPlugin: Plugin = {\n name: 'devix',\n enforce: 'pre',\n\n resolveId(id) {\n if (id === VIRTUAL_ENTRY_CLIENT) return `\\0${VIRTUAL_ENTRY_CLIENT}`\n if (id === VIRTUAL_CLIENT_ROUTES) return `\\0${VIRTUAL_CLIENT_ROUTES}`\n if (id === VIRTUAL_RENDER) return `\\0${VIRTUAL_RENDER}`\n if (id === VIRTUAL_API) return `\\0${VIRTUAL_API}`\n if (id === VIRTUAL_CONTEXT) return `\\0${VIRTUAL_CONTEXT}`\n },\n\n load(id) {\n if (id === `\\0${VIRTUAL_ENTRY_CLIENT}`)\n return generateEntryClient({cssUrls})\n if (id === `\\0${VIRTUAL_CLIENT_ROUTES}`)\n return generateClientRoutes({pagesDir, matcherPath})\n if (id === `\\0${VIRTUAL_RENDER}`)\n return generateRender({pagesDir, renderPath})\n if (id === `\\0${VIRTUAL_API}`)\n return generateApi({apiPath, appDir})\n if (id === `\\0${VIRTUAL_CONTEXT}`)\n return generateContext()\n },\n\n buildStart() {\n const root = process.cwd()\n const entries = scanApiFiles(appDir, root)\n writeRoutesDts(generateRoutesDts(entries, `${appDir}/api`), root)\n },\n\n configureServer(server) {\n const root = process.cwd()\n\n const regenerateDts = () => {\n const entries = scanApiFiles(appDir, root)\n writeRoutesDts(generateRoutesDts(entries, `${appDir}/api`), root)\n }\n\n server.watcher.on('add', (file) => {\n if (file.startsWith(resolve(root, pagesDir))) invalidatePagesCache()\n if (file.includes(`${appDir}/api`)) { invalidateApiCache(); regenerateDts() }\n })\n server.watcher.on('unlink', (file) => {\n if (file.startsWith(resolve(root, pagesDir))) invalidatePagesCache()\n if (file.includes(`${appDir}/api`)) { invalidateApiCache(); regenerateDts() }\n })\n server.watcher.on('change', (file) => {\n if (file.includes(`${appDir}/api`) && !file.endsWith('middleware.ts')) {\n regenerateDts()\n }\n })\n },\n }\n\n const base: UserConfig = {\n plugins: [react(), virtualPlugin],\n ssr: {noExternal: ['@devlusoft/devix']},\n ...(config.envPrefix ? {envPrefix: config.envPrefix} : {}),\n }\n\n return mergeConfig(base, config.vite ?? {})\n}", "interface EntryClientOptions {\n cssUrls: string[]\n}\n\nexport function generateEntryClient({cssUrls}: EntryClientOptions): string {\n const cssImports = cssUrls.map(u => `import '${u}'`).join('\\n')\n\n return `\n${cssImports}\nimport \"@vitejs/plugin-react/preamble\"\nimport React from \"react\"\nimport {hydrateRoot, createRoot} from 'react-dom/client'\nimport {matchClientRoute, loadErrorPage, getDefaultErrorPage} from 'virtual:devix/client-routes'\nimport {RouterProvider} from '@devlusoft/devix'\n\nconst root = document.getElementById('devix-root')\n\nif (!window.__DEVIX__) {\n const ErrorPage = getDefaultErrorPage()\n createRoot(root).render(React.createElement(ErrorPage, {statusCode: 500, message: 'Server error'}))\n} else {\n const {metadata, viewport, clientEntry} = window.__DEVIX__\n const loaderData = window.__LOADER_DATA__\n const layoutsData = window.__LAYOUTS_DATA__ ?? []\n\n const matched = matchClientRoute(window.location.pathname)\n\n if (matched) {\n const [pageMod, ...layoutMods] = await Promise.all([\n matched.load(),\n ...matched.loadLayouts.map(l => l()),\n ])\n hydrateRoot(\n root,\n React.createElement(RouterProvider, {\n clientEntry,\n initialData: loaderData,\n initialParams: matched.params,\n initialPage: pageMod.default,\n initialLayouts: layoutMods.map(m => m.default),\n initialLayoutsData: layoutsData,\n initialMeta: metadata,\n initialViewport: viewport,\n })\n )\n } else {\n const ErrorPage = await loadErrorPage() ?? getDefaultErrorPage()\n createRoot(root).render(\n React.createElement(RouterProvider, {\n clientEntry,\n initialData: null,\n initialParams: {},\n initialPage: () => null,\n initialLayouts: [],\n initialLayoutsData: [],\n initialMeta: null,\n initialError: {statusCode: 404, message: 'Not found'},\n initialErrorPage: ErrorPage,\n })\n )\n }\n}\n`\n}", "interface ClientRoutesOptions {\n pagesDir: string\n matcherPath: string\n}\n\nexport function generateClientRoutes({pagesDir, matcherPath}: ClientRoutesOptions) {\n return `\nimport React from 'react'\nimport { createMatcher } from '${matcherPath}'\nconst pageFiles = import.meta.glob(['/${pagesDir}/**/*.tsx', '!**/error.tsx', '!**/layout.tsx'])\nconst layoutFiles = import.meta.glob('/${pagesDir}/**/layout.tsx')\nconst errorFiles = import.meta.glob('/${pagesDir}/**/error.tsx')\n\nexport const matchClientRoute = createMatcher(pageFiles, layoutFiles)\n\nexport async function loadErrorPage() {\n const key = Object.keys(errorFiles)[0]\n if (!key) return null\n const mod = await errorFiles[key]()\n return mod?.default ?? null\n}\n\nexport function getDefaultErrorPage() {\n return function DefaultError({ statusCode, message }) {\n return React.createElement('main', {\n style: { minHeight: '100dvh', display: 'flex', flexDirection: 'column', \n alignItems: 'center', justifyContent: 'center', gap: '8px',\n fontFamily: 'system-ui, sans-serif' }\n },\n React.createElement('h1', {style: {fontSize: '4rem', fontWeight: 700}}, statusCode),\n React.createElement('p', {style: {color: '#666'}}, message ?? 'An unexpected error occurred'),\n )\n }\n}\n`\n}", "interface RenderOptions {\n pagesDir: string\n renderPath: string\n}\n\nexport function generateRender({pagesDir, renderPath}: RenderOptions): string {\n return `\nimport { render as _render, runLoader as _runLoader, getStaticRoutes as _getStaticRoutes } from '${renderPath}'\n\nconst _pages = import.meta.glob(['/${pagesDir}/**/*.tsx', '!**/error.tsx', '!**/layout.tsx'])\nconst _layouts = import.meta.glob('/${pagesDir}/**/layout.tsx')\n\nconst _glob = {\n pages: _pages,\n layouts: _layouts,\n pagesDir: '/${pagesDir}',\n}\n\nexport function render(url, request, options) {\n return _render(url, request, _glob, options)\n}\n\nexport function runLoader(url, request, options) {\n return _runLoader(url, request, _glob, options)\n}\n\nexport function getStaticRoutes() {\n return _getStaticRoutes(_glob)\n}\n`\n}\n", "interface ApiOptions {\n apiPath: string\n appDir: string\n}\n\nexport function generateApi({apiPath, appDir}: ApiOptions): string {\n return `\nimport { handleApiRequest as _handleApiRequest } from '${apiPath}'\n\nconst _routes = import.meta.glob(['/${appDir}/api/**/*.ts', '!**/middleware.ts'])\nconst _middlewares = import.meta.glob('/${appDir}/api/**/middleware.ts')\n\nconst _glob = {\n routes: _routes,\n middlewares: _middlewares,\n apiDir: '/${appDir}/api',\n}\n\nexport function handleApiRequest(url, request) {\n return _handleApiRequest(url, request, _glob)\n}\n`\n}\n", "export function routePattern(rel: string): string {\n return rel\n .replace(/\\.(tsx|ts|jsx|js)$/, '')\n .replace(/\\(.*?\\)\\//g, '')\n .replace(/^index$|\\/index$/, '')\n .replace(/\\[([^\\]]+)]/g, ':$1')\n || '/'\n}", "import {routePattern} from \"../utils/patterns\";\n\nexport interface Page {\n path: string\n key: string\n params: string[]\n regex: RegExp\n}\n\nexport interface Layout {\n dir: string\n key: string\n}\n\nexport interface PagesResult {\n pages: Page[]\n layouts: Layout[]\n}\n\nfunction keyToRoutePattern(key: string, pagesDir: string): string {\n const rel = key.slice(pagesDir.length + 1).replace(/\\\\/g, '/')\n const pattern = routePattern(rel)\n return pattern === \"/\" ? \"/\" : `/${pattern}`\n}\n\nfunction keyToDir(key: string): string {\n return key.slice(0, key.lastIndexOf('/'))\n}\n\nlet cache: PagesResult | null = null\n\nexport function invalidatePagesCache() {\n cache = null\n}\n\nexport function buildPages(pageKeys: string[], layoutKeys: string[], pagesDir: string): PagesResult {\n if (cache) return cache\n\n const pages: Page[] = []\n const layouts: Layout[] = []\n\n for (const key of layoutKeys) {\n layouts.push({dir: keyToDir(key), key})\n }\n\n for (const key of pageKeys) {\n const pattern = keyToRoutePattern(key, pagesDir)\n const params = [...pattern.matchAll(/:([^/]+)/g)].map(m => m[1])\n const regexStr = pattern\n .replace(/:[^/]+/g, '([^/]+)')\n .replace(/\\//g, '\\\\/')\n pages.push({path: pattern, key, params, regex: new RegExp(`^${regexStr}$`)})\n }\n\n pages.sort((a, b) => {\n const aScore = (a.path.match(/:/g) || []).length\n const bScore = (b.path.match(/:/g) || []).length\n if (aScore !== bScore) return aScore - bScore\n return b.path.length - a.path.length\n })\n\n cache = {pages, layouts}\n return cache\n}\n\nexport function collectLayoutChain(pageKey: string, layouts: Layout[]): Layout[] {\n const pageDir = keyToDir(pageKey)\n\n return layouts\n .filter(layout => pageDir.startsWith(layout.dir))\n .sort((a, b) => a.dir.split('/').length - b.dir.split('/').length)\n}\n\nexport function matchPage(pathname: string, pages: Page[]): {\n page: Page\n params: Record<string, string>\n} | null {\n for (const page of pages) {\n const match = pathname.match(page.regex)\n if (match) {\n const params: Record<string, string> = {}\n page.params.forEach((name, i) => {\n params[name] = decodeURIComponent(match[i + 1])\n })\n return {page, params}\n }\n }\n return null\n}\n", "import {routePattern} from \"../utils/patterns\";\n\nexport interface ApiRoute {\n path: string\n key: string\n params: string[]\n regex: RegExp\n}\n\nexport interface ApiMiddleware {\n dir: string\n key: string\n}\n\nexport interface ApiResult {\n routes: ApiRoute[]\n middlewares: ApiMiddleware[]\n}\n\nexport function keyToRoutePattern(key: string, apiDir: string): string {\n const rel = key.slice(apiDir.length + 1).replace(/\\\\/g, '/')\n const pattern = routePattern(rel)\n return pattern === '/' ? '/api' : `/api/${pattern}`.replace('/api//', '/api/')\n}\n\nfunction keyToDir(key: string): string {\n return key.slice(0, key.lastIndexOf('/'))\n}\n\nlet cache: ApiResult | null = null\n\nexport function invalidateApiCache() {\n cache = null\n}\n\nexport function buildRoutes(routeKeys: string[], middlewareKeys: string[], apiDir: string): ApiResult {\n if (cache) return cache\n\n const routes: ApiRoute[] = []\n const middlewares: ApiMiddleware[] = []\n\n for (const key of middlewareKeys) {\n middlewares.push({dir: keyToDir(key), key})\n }\n\n for (const key of routeKeys) {\n const pattern = keyToRoutePattern(key, apiDir)\n const params = [...pattern.matchAll(/:([^/]+)/g)].map(m => m[1])\n const regexStr = pattern\n .replace(/:[^/]+/g, '([^/]+)')\n .replace(/\\//g, '\\\\/')\n routes.push({path: pattern, key, params, regex: new RegExp(`^${regexStr}$`)})\n }\n routes.sort((a, b) => {\n const aScore = (a.path.match(/:/g) || []).length\n const bScore = (b.path.match(/:/g) || []).length\n if (aScore !== bScore) return aScore - bScore\n return b.path.length - a.path.length\n })\n\n cache = {routes, middlewares}\n return cache\n}\n\nexport function collectMiddlewareChain(routeKey: string, middlewares: ApiMiddleware[]): ApiMiddleware[] {\n const routeDir = keyToDir(routeKey)\n\n return middlewares\n .filter(mw => routeDir.startsWith(mw.dir))\n .sort((a, b) => a.dir.split('/').length - b.dir.split('/').length)\n}\n\nexport function matchRoute(\n pathname: string,\n routes: ApiRoute[]\n): {route: ApiRoute; params: Record<string, string>} | null {\n for (const route of routes) {\n const match = pathname.match(route.regex)\n if (match) {\n const params: Record<string, string> = {}\n route.params.forEach((name, i) => {\n params[name] = decodeURIComponent(match[i + 1])\n })\n return {route, params}\n }\n }\n return null\n}\n", "export function generateContext(): string {\n return `\nexport {RouterContext} from '@devlusoft/devix/runtime/context'\n`\n}", "import {readFileSync, readdirSync, statSync} from 'node:fs'\nimport {join, relative} from 'node:path'\nimport {extractHttpMethods} from './extract-methods'\nimport {buildRouteEntry} from './routes-dts'\nimport type {RouteEntry} from './routes-dts'\n\nfunction walkDir(dir: string, root: string): string[] {\n const entries: string[] = []\n for (const name of readdirSync(dir)) {\n const full = join(dir, name)\n if (statSync(full).isDirectory()) {\n entries.push(...walkDir(full, root))\n } else if (/\\.(ts|tsx)$/.test(name)) {\n entries.push(relative(root, full).replace(/\\\\/g, '/'))\n }\n }\n return entries\n}\n\nexport function scanApiFiles(appDir: string, projectRoot: string): RouteEntry[] {\n const apiDir = join(projectRoot, appDir, 'api')\n\n let files: string[]\n try {\n files = walkDir(apiDir, projectRoot)\n } catch {\n return []\n }\n\n return files\n .filter(f => !f.endsWith('middleware.ts') && !f.endsWith('middleware.tsx'))\n .flatMap(filePath => {\n try {\n const content = readFileSync(join(projectRoot, filePath), 'utf-8')\n const methods = extractHttpMethods(content)\n if (methods.length === 0) return []\n return [buildRouteEntry(filePath, `${appDir}/api`, methods)]\n } catch {\n return []\n }\n })\n}\n", "const HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'] as const\nexport type HttpMethod = (typeof HTTP_METHODS)[number]\n\nconst METHOD_EXPORT_RE = /export\\s+(?:const|async\\s+function|function)\\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\\b/g\n\nfunction stripComments(content: string): string {\n return content\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n .replace(/\\/\\/.*$/gm, '')\n}\n\nexport function extractHttpMethods(content: string): HttpMethod[] {\n const found = new Set<HttpMethod>()\n for (const match of stripComments(content).matchAll(METHOD_EXPORT_RE)) {\n found.add(match[1] as HttpMethod)\n }\n return [...found]\n}\n", "import { keyToRoutePattern } from '../../server/api-router'\nimport type { HttpMethod } from './extract-methods'\n\nexport interface RouteEntry {\n filePath: string\n urlPattern: string\n identifier: string\n methods: HttpMethod[]\n}\n\nexport function filePathToIdentifier(filePath: string, apiDir: string): string {\n return '_api_' + filePath\n .slice(`${apiDir}/`.length)\n .replace(/\\.(ts|tsx)$/, '')\n .replace(/[^a-zA-Z0-9]/g, '_')\n}\n\nexport function buildRouteEntry(filePath: string, apiDir: string, methods: HttpMethod[]): RouteEntry {\n return {\n filePath,\n urlPattern: keyToRoutePattern(filePath, apiDir),\n identifier: filePathToIdentifier(filePath, apiDir),\n methods,\n }\n}\n\nexport function generateRoutesDts(entries: RouteEntry[], apiDir: string): string {\n if (entries.length === 0) {\n return `// auto-generado por devix \u2014 no editar\\ndeclare module '@devlusoft/devix' {\\n interface ApiRoutes {}\\n}\\n`\n }\n\n const imports = entries\n .map(e => {\n const importPath = '../' + e.filePath.replace(/\\.(ts|tsx)$/, '')\n return `import type * as ${e.identifier} from '${importPath}'`\n })\n .join('\\n')\n\n const routeLines = entries.flatMap(e =>\n e.methods.map(m =>\n ` '${m} ${e.urlPattern}': InferRoute<(typeof ${e.identifier})['${m}']>`\n )\n ).join('\\n')\n\n return `// auto-generado por devix \u2014 no editar\n${imports}\n\ntype InferRoute<T> = T extends (...args: any[]) => any\n ? Exclude<Awaited<ReturnType<T>>, Response | null | void>\n : never\n\ndeclare module '@devlusoft/devix' {\n interface ApiRoutes {\n${routeLines}\n }\n}\n`\n}\n", "import {mkdirSync, readFileSync, writeFileSync, existsSync} from 'node:fs'\nimport {join} from 'node:path'\n\nexport function writeRoutesDts(content: string, projectRoot: string): boolean {\n const devixDir = join(projectRoot, '.devix')\n const outPath = join(devixDir, 'routes.d.ts')\n\n mkdirSync(devixDir, {recursive: true})\n\n if (existsSync(outPath) && readFileSync(outPath, 'utf-8') === content) {\n return false\n }\n\n writeFileSync(outPath, content, 'utf-8')\n return true\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAA4B,mBAAkB;AAE9C,OAAO,WAAW;AAClB,SAAQ,qBAAoB;AAC5B,SAAQ,SAAS,eAAc;;;ACAxB,SAAS,oBAAoB,EAAC,QAAO,GAA+B;AACvE,QAAM,aAAa,QAAQ,IAAI,OAAK,WAAW,CAAC,GAAG,EAAE,KAAK,IAAI;AAE9D,SAAO;AAAA,EACT,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuDZ;;;AC1DO,SAAS,qBAAqB,EAAC,UAAU,YAAW,GAAwB;AAC/E,SAAO;AAAA;AAAA,iCAEsB,WAAW;AAAA,wCACJ,QAAQ;AAAA,yCACP,QAAQ;AAAA,wCACT,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBhD;;;AC9BO,SAAS,eAAe,EAAC,UAAU,WAAU,GAA0B;AAC1E,SAAO;AAAA,mGACwF,UAAU;AAAA;AAAA,qCAExE,QAA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