@kosmojs/dev 0.0.5 → 0.0.7
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/package.json +34 -13
- package/pkg/base-plugin/routes.js +12 -11
- package/pkg/base-plugin/routes.js.map +3 -3
- package/pkg/base-plugin/worker.js +12 -11
- package/pkg/base-plugin/worker.js.map +3 -3
- package/pkg/cli/cli.js +589 -0
- package/pkg/cli/cli.js.map +7 -0
- package/pkg/cli/index.js +431 -0
- package/pkg/cli/index.js.map +7 -0
- package/pkg/cli/templates/.env +1 -0
- package/pkg/cli/templates/@src/api/app.hbs +32 -0
- package/pkg/cli/templates/@src/api/router.hbs +11 -0
- package/pkg/cli/templates/@src/api/server.hbs +4 -0
- package/pkg/cli/templates/@src/api/use.hbs +6 -0
- package/pkg/cli/templates/@src/config/index.hbs +2 -0
- package/pkg/cli/templates/@src/index.html +4 -0
- package/pkg/cli/templates/@src/vite.config.hbs +29 -0
- package/pkg/cli/templates/core/api/app.ts +6 -0
- package/pkg/cli/templates/core/api/env.d.ts +4 -0
- package/pkg/cli/templates/core/api/router.ts +6 -0
- package/pkg/cli/templates/core/api/server.ts +49 -0
- package/pkg/cli/templates/core/api/use.ts +21 -0
- package/pkg/cli/templates/vite.base.hbs +44 -0
- package/pkg/index.js +16 -13
- package/pkg/index.js.map +3 -3
- package/pkg/src/cli/base.d.ts +30 -0
- package/pkg/src/cli/cli.d.ts +2 -0
- package/pkg/src/cli/factory.d.ts +12 -0
- package/pkg/src/cli/index.d.ts +2 -0
- package/pkg/src/cli/templates/core/api/app.d.ts +3 -0
- package/pkg/src/cli/templates/core/api/router.d.ts +3 -0
- package/pkg/src/cli/templates/core/api/server.d.ts +3 -0
- package/pkg/src/cli/templates/core/api/use.d.ts +2 -0
- package/pkg/stub-generator/index.js +1 -1
- package/pkg/stub-generator/index.js.map +1 -1
- package/pkg/test/cli/create.test.d.ts +1 -0
- package/pkg/test/setup.d.ts +1 -0
- package/pkg/cli.js +0 -3
- package/pkg/cli.js.map +0 -7
- package/pkg/src/cli.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@kosmojs/dev",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"cacheVersion": "001",
|
|
6
6
|
"author": "Slee Woo",
|
|
7
7
|
"license": "MIT",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"pkg/*"
|
|
13
13
|
],
|
|
14
14
|
"bin": {
|
|
15
|
-
"kosmo": "pkg/cli.js"
|
|
15
|
+
"kosmo": "pkg/cli/cli.js"
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
@@ -27,36 +27,57 @@
|
|
|
27
27
|
"types": "./pkg/src/stub-generator/index.d.ts",
|
|
28
28
|
"default": "./pkg/stub-generator/index.js"
|
|
29
29
|
},
|
|
30
|
+
"./cli": {
|
|
31
|
+
"types": "./pkg/src/cli/index.d.ts",
|
|
32
|
+
"default": "./pkg/cli/index.js"
|
|
33
|
+
},
|
|
30
34
|
"./package.json": "./package.json"
|
|
31
35
|
},
|
|
32
36
|
"dependencies": {
|
|
33
37
|
"chokidar": "^4.0.3",
|
|
38
|
+
"concurrently": "^9.2.1",
|
|
34
39
|
"crc": "^4.3.2",
|
|
35
40
|
"dotenv": "^17.2.3",
|
|
36
41
|
"esbuild": "^0.27.0",
|
|
37
|
-
"fs-extra": "^11.3.2",
|
|
38
42
|
"ora": "^9.0.0",
|
|
39
43
|
"picomatch": "^4.0.3",
|
|
44
|
+
"prompts": "^2.4.2",
|
|
40
45
|
"tfusion": "^0.0.23",
|
|
41
46
|
"tinyglobby": "^0.2.15",
|
|
42
47
|
"ts-morph": "^27.0.2",
|
|
43
48
|
"typescript": "^5.9.3",
|
|
44
|
-
"kosmojs": "^0.0.
|
|
45
|
-
"@kosmojs/api": "^0.0.
|
|
46
|
-
"@kosmojs/
|
|
47
|
-
"@kosmojs/
|
|
48
|
-
"@kosmojs/devlib": "^0.0.5",
|
|
49
|
-
"@kosmojs/fetch-generator": "^0.0.5"
|
|
49
|
+
"@kosmojs/api": "^0.0.7",
|
|
50
|
+
"@kosmojs/api-generator": "^0.0.7",
|
|
51
|
+
"@kosmojs/devlib": "^0.0.7",
|
|
52
|
+
"@kosmojs/fetch-generator": "^0.0.7"
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
52
|
-
"@
|
|
55
|
+
"@solidjs/router": "^0.15.4",
|
|
53
56
|
"@types/koa": "^3.0.1",
|
|
57
|
+
"@types/koa__router": "^12.0.5",
|
|
58
|
+
"@types/node": "^24.10.1",
|
|
54
59
|
"@types/picomatch": "^4.0.2",
|
|
55
|
-
"
|
|
60
|
+
"@types/prompts": "^2.4.9",
|
|
61
|
+
"@types/qs": "^6.14.0",
|
|
62
|
+
"@types/react": "^19.2.3",
|
|
63
|
+
"@types/react-dom": "^19.2.3",
|
|
64
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
65
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
66
|
+
"qs": "^6.14.0",
|
|
67
|
+
"react": "^19.2.0",
|
|
68
|
+
"react-dom": "^19.2.0",
|
|
69
|
+
"react-router": "^7.9.5",
|
|
70
|
+
"solid-js": "^1.9.10",
|
|
71
|
+
"tslib": "^2.8.1",
|
|
72
|
+
"vite": "^7.2.2",
|
|
73
|
+
"vite-plugin-solid": "^2.11.10",
|
|
74
|
+
"vue": "^3.5.24",
|
|
75
|
+
"vue-router": "^4.6.3",
|
|
76
|
+
"@kosmojs/config": "^0.0.7"
|
|
56
77
|
},
|
|
57
78
|
"scripts": {
|
|
58
|
-
"build": "esbuilder src/index.ts src/base-plugin/routes.ts src/base-plugin/worker.ts src/stub-generator/index.ts src/cli.ts",
|
|
59
|
-
"postbuild": "
|
|
79
|
+
"build": "esbuilder src/index.ts src/base-plugin/routes.ts src/base-plugin/worker.ts src/stub-generator/index.ts src/cli/cli.ts src/cli/index.ts",
|
|
80
|
+
"postbuild": "rsync -av --delete src/cli/templates/ pkg/cli/templates",
|
|
60
81
|
"test": "vitest --root ../../.. --project core/dev"
|
|
61
82
|
}
|
|
62
83
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/base-plugin/routes.ts
|
|
2
|
-
import { dirname, join, resolve as resolve3 } from "node:path";
|
|
2
|
+
import { dirname as dirname2, join, resolve as resolve3 } from "node:path";
|
|
3
3
|
import crc3 from "crc/crc32";
|
|
4
4
|
import picomatch from "picomatch";
|
|
5
5
|
import { glob } from "tinyglobby";
|
|
@@ -267,11 +267,11 @@ var typeResolverFactory = ({ appRoot }) => {
|
|
|
267
267
|
};
|
|
268
268
|
|
|
269
269
|
// src/base-plugin/cache.ts
|
|
270
|
-
import {
|
|
270
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
271
|
+
import { dirname, resolve as resolve2 } from "node:path";
|
|
271
272
|
import crc2 from "crc/crc32";
|
|
272
|
-
import fsx from "fs-extra";
|
|
273
273
|
import self from "@kosmojs/dev/package.json" with { type: "json" };
|
|
274
|
-
import { pathResolver } from "@kosmojs/devlib";
|
|
274
|
+
import { pathExists, pathResolver } from "@kosmojs/devlib";
|
|
275
275
|
var cacheFactory = (route, {
|
|
276
276
|
appRoot,
|
|
277
277
|
sourceFolder,
|
|
@@ -282,9 +282,9 @@ var cacheFactory = (route, {
|
|
|
282
282
|
sourceFolder
|
|
283
283
|
}).resolve("apiLibDir", route.importPath, "cache.json");
|
|
284
284
|
const getCache = async (opt) => {
|
|
285
|
-
if (await
|
|
285
|
+
if (await pathExists(cacheFile)) {
|
|
286
286
|
try {
|
|
287
|
-
const cache = JSON.parse(await
|
|
287
|
+
const cache = JSON.parse(await readFile(cacheFile, "utf8"));
|
|
288
288
|
return opt?.validate ? validateCache(cache) : cache;
|
|
289
289
|
} catch (_e) {
|
|
290
290
|
}
|
|
@@ -307,7 +307,8 @@ var cacheFactory = (route, {
|
|
|
307
307
|
] = await generateFileHash(file);
|
|
308
308
|
}
|
|
309
309
|
const cache = { ...rest, hash, referencedFiles };
|
|
310
|
-
await
|
|
310
|
+
await mkdir(dirname(cacheFile), { recursive: true });
|
|
311
|
+
await writeFile(cacheFile, JSON.stringify(cache, null, 2), "utf8");
|
|
311
312
|
return cache;
|
|
312
313
|
};
|
|
313
314
|
const validateCache = async (cache) => {
|
|
@@ -339,7 +340,7 @@ var cacheFactory = (route, {
|
|
|
339
340
|
var generateFileHash = async (file, extraContext) => {
|
|
340
341
|
let fileContent;
|
|
341
342
|
try {
|
|
342
|
-
fileContent = await
|
|
343
|
+
fileContent = await readFile(file, "utf8");
|
|
343
344
|
} catch (_e) {
|
|
344
345
|
return 0;
|
|
345
346
|
}
|
|
@@ -401,9 +402,9 @@ var routes_default = async (pluginOptions) => {
|
|
|
401
402
|
}
|
|
402
403
|
const [folder, file] = resolvedPaths;
|
|
403
404
|
const fileFullpath = join(appRoot, sourceFolder, folder, file);
|
|
404
|
-
const pathTokens = pathTokensFactory(
|
|
405
|
+
const pathTokens = pathTokensFactory(dirname2(file));
|
|
405
406
|
const name = pathTokens.map((e) => e.orig).join("/");
|
|
406
|
-
const importPath =
|
|
407
|
+
const importPath = dirname2(file);
|
|
407
408
|
const importName = [
|
|
408
409
|
importPath.split(/\[/)[0].replace(/^\W+|\W+$/g, "").replace(/\W+/g, "_"),
|
|
409
410
|
crc3(importPath)
|
|
@@ -461,7 +462,7 @@ var routes_default = async (pluginOptions) => {
|
|
|
461
462
|
withReferencedFiles: true,
|
|
462
463
|
sourceFile: getSourceFile(fileFullpath),
|
|
463
464
|
relpathResolver(path) {
|
|
464
|
-
return join(sourceFolder, defaults.apiDir,
|
|
465
|
+
return join(sourceFolder, defaults.apiDir, dirname2(file), path);
|
|
465
466
|
}
|
|
466
467
|
}
|
|
467
468
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/base-plugin/routes.ts", "../../src/base-plugin/ast.ts", "../../src/base-plugin/cache.ts", "../../src/base-plugin/templates/resolved-types.hbs", "../../src/base-plugin/templates/types.hbs"],
|
|
4
|
-
"sourcesContent": ["import { dirname, join, resolve } from \"node:path\";\n\nimport crc from \"crc/crc32\";\nimport picomatch from \"picomatch\";\nimport { glob } from \"tinyglobby\";\n\nimport {\n type ApiRoute,\n defaults,\n type PageRoute,\n type PluginOptionsResolved,\n pathResolver,\n pathTokensFactory,\n type RouteEntry,\n type RouteResolver,\n render,\n renderToFile,\n} from \"@kosmojs/devlib\";\n\nimport { resolveRouteSignature, typeResolverFactory } from \"./ast\";\nimport { cacheFactory } from \"./cache\";\n\nimport resolvedTypesTpl from \"./templates/resolved-types.hbs\";\nimport typesFileTpl from \"./templates/types.hbs\";\n\nexport type Resolvers = Map<string, RouteResolver>;\n\nexport type ResolveRouteFile = (file: string) =>\n | [\n // Either `apiDir` or `pagesDir`\n folder: string,\n // Path to a file within the folder, nested at least one level deep\n file: string,\n ]\n | undefined;\n\nexport type ResolversFactory = (\n routeFiles: Array<string>,\n) => Map<string, RouteResolver>;\n\nexport default async (\n pluginOptions: PluginOptionsResolved,\n): Promise<{\n resolvers: Resolvers;\n resolversFactory: ResolversFactory;\n resolveRouteFile: ResolveRouteFile;\n}> => {\n const {\n appRoot,\n sourceFolder,\n generators = [],\n formatters = [],\n refineTypeName,\n } = pluginOptions;\n\n let resolveTypes = false;\n\n for (const { options } of generators) {\n if (options?.resolveTypes) {\n resolveTypes = true;\n }\n }\n\n const {\n //\n literalTypesResolver,\n getSourceFile,\n refreshSourceFile,\n } = typeResolverFactory(pluginOptions);\n\n const routeFilePatterns = [\n `${defaults.apiDir}/**/index.ts`,\n `${defaults.pagesDir}/**/index.{ts,tsx,vue,svelte}`,\n ];\n\n const resolveRouteFile: ResolveRouteFile = (file) => {\n const [_sourceFolder, folder, ...rest] = resolve(appRoot, file)\n .replace(`${appRoot}/`, \"\")\n .split(\"/\");\n\n /**\n * Ensure the file:\n * - is under the correct source root (`sourceFolder`)\n * - belongs to a known route folder (`apiDir` or `pagesDir`)\n * - is nested at least one level deep (not a direct child of the folder)\n */\n if (!folder || _sourceFolder !== sourceFolder || rest.length < 2) {\n return;\n }\n\n return picomatch.isMatch(join(folder, ...rest), routeFilePatterns)\n ? [folder, rest.join(\"/\")]\n : undefined;\n };\n\n const resolversFactory: ResolversFactory = (routeFiles) => {\n const resolvers = new Map<\n string, // fileFullpath\n RouteResolver\n >();\n\n const entries: Array<RouteEntry> = routeFiles.flatMap((_file) => {\n const resolvedPaths = resolveRouteFile(_file);\n\n if (!resolvedPaths) {\n return [];\n }\n\n const [folder, file] = resolvedPaths;\n\n const fileFullpath = join(appRoot, sourceFolder, folder, file);\n\n const pathTokens = pathTokensFactory(dirname(file));\n\n const name = pathTokens.map((e) => e.orig).join(\"/\");\n\n const importPath = dirname(file);\n\n const importName = [\n importPath\n .split(/\\[/)[0]\n .replace(/^\\W+|\\W+$/g, \"\")\n .replace(/\\W+/g, \"_\"),\n crc(importPath),\n ].join(\"_\");\n\n return [\n {\n name,\n folder,\n file,\n fileFullpath,\n pathTokens,\n importPath,\n importName,\n },\n ];\n });\n\n for (const entry of entries.filter((e) => e.folder === defaults.apiDir)) {\n const {\n name,\n file,\n folder,\n fileFullpath,\n pathTokens,\n importPath,\n importName,\n } = entry;\n\n const handler: RouteResolver[\"handler\"] = async (updatedFile) => {\n const paramsSchema = pathTokens.flatMap((e) => {\n return e.param ? [e.param] : [];\n });\n\n const optionalParams = paramsSchema.length\n ? !paramsSchema.some((e) => e.isRequired)\n : true;\n\n const { getCache, persistCache } = cacheFactory(\n { file, fileFullpath, importName, importPath },\n {\n appRoot,\n sourceFolder,\n extraContext: { resolveTypes },\n },\n );\n\n let cache = await getCache({ validate: true });\n\n if (!cache) {\n if (updatedFile === fileFullpath) {\n await refreshSourceFile(fileFullpath);\n }\n\n const {\n typeDeclarations,\n paramsRefinements,\n methods,\n payloadTypes,\n responseTypes,\n referencedFiles = [],\n } = await resolveRouteSignature(\n { importName, fileFullpath, optionalParams },\n {\n withReferencedFiles: true,\n sourceFile: getSourceFile(fileFullpath),\n relpathResolver(path) {\n return join(sourceFolder, defaults.apiDir, dirname(file), path);\n },\n },\n );\n\n const numericParams = paramsRefinements\n ? paramsRefinements.flatMap(({ text, index }) => {\n if (text === \"number\") {\n const param = paramsSchema.at(index);\n return param ? [param.name] : [];\n }\n return [];\n })\n : [];\n\n const typesFile = pathResolver({ appRoot, sourceFolder }).resolve(\n \"apiLibDir\",\n importPath,\n \"types.ts\",\n );\n\n const params: ApiRoute[\"params\"] = {\n id: [\"ParamsT\", crc(name)].join(\"\"),\n schema: paramsSchema,\n resolvedType: undefined,\n };\n\n const typesFileContent = render(typesFileTpl, {\n params,\n paramsSchema: paramsSchema.map((param, index) => {\n return {\n ...param,\n refinement: paramsRefinements?.at(index),\n };\n }),\n typeDeclarations,\n payloadTypes,\n responseTypes,\n });\n\n const resolvedTypes = resolveTypes\n ? literalTypesResolver(typesFileContent, {\n overrides: [...payloadTypes, ...responseTypes].reduce(\n (map: Record<string, string>, { id, skipValidation }) => {\n if (skipValidation) {\n map[id] = \"never\";\n }\n return map;\n },\n { [refineTypeName]: refineTypeName },\n ),\n withProperties: [params.id, ...payloadTypes.map((e) => e.id)],\n formatters,\n })\n : undefined;\n\n /**\n * Deploy types.ts file; required by core generators (like fetch).\n * If types resolved, write resolved types;\n * otherwise write original types extracted from API route.\n * */\n await renderToFile(\n typesFile,\n resolvedTypes ? resolvedTypesTpl : typesFileContent,\n { resolvedTypes },\n );\n\n params.resolvedType = resolvedTypes?.find(\n (e) => e.name === params.id,\n );\n\n cache = await persistCache({\n params,\n methods,\n typeDeclarations,\n numericParams,\n // text was needed at writing types.ts file, dropping from cache\n payloadTypes: payloadTypes.map(({ text, ...rest }) => {\n return {\n ...rest,\n resolvedType: resolvedTypes?.find((e) => e.name === rest.id),\n };\n }),\n responseTypes: responseTypes.map(({ text, ...rest }) => {\n return {\n ...rest,\n resolvedType: resolvedTypes?.find((e) => e.name === rest.id),\n };\n }),\n referencedFiles,\n });\n }\n\n const route: ApiRoute = {\n name,\n pathTokens,\n params: cache.params,\n numericParams: cache.numericParams,\n optionalParams,\n importName,\n importPath,\n folder,\n file,\n fileFullpath,\n methods: cache.methods,\n typeDeclarations: cache.typeDeclarations,\n payloadTypes: cache.payloadTypes,\n responseTypes: cache.responseTypes,\n referencedFiles: Object.keys(cache.referencedFiles).map(\n // expand referenced files path,\n // they are stored as relative in cache\n (e) => resolve(appRoot, e),\n ),\n };\n\n return {\n kind: \"api\",\n route,\n };\n };\n\n resolvers.set(fileFullpath, { name, handler });\n }\n\n for (const entry of entries.filter((e) => e.folder === defaults.pagesDir)) {\n const {\n //\n name,\n folder,\n file,\n fileFullpath,\n pathTokens,\n importPath,\n importName,\n } = entry;\n\n const handler: RouteResolver[\"handler\"] = async () => {\n const route: PageRoute = {\n name,\n pathTokens,\n params: {\n schema: pathTokens.flatMap((e) => (e.param ? [e.param] : [])),\n },\n folder,\n file,\n fileFullpath,\n importPath,\n importName,\n };\n\n return {\n kind: \"page\",\n route,\n };\n };\n\n resolvers.set(fileFullpath, { name, handler });\n }\n\n return resolvers;\n };\n\n const routeFiles = await glob(routeFilePatterns, {\n cwd: resolve(appRoot, sourceFolder),\n absolute: true,\n onlyFiles: true,\n ignore: [\n `${defaults.apiDir}/index.ts`,\n `${defaults.pagesDir}/index.ts{x,}`,\n ],\n });\n\n return {\n resolvers: resolversFactory(routeFiles),\n resolversFactory,\n resolveRouteFile,\n };\n};\n", "import { resolve } from \"node:path\";\n\nimport crc from \"crc/crc32\";\nimport { flattener } from \"tfusion\";\nimport {\n type CallExpression,\n type Identifier,\n type Node,\n Project,\n type ProjectOptions,\n type SourceFile,\n SyntaxKind,\n} from \"ts-morph\";\n\nimport { type HTTPMethod, HTTPMethods } from \"@kosmojs/api\";\nimport type {\n ApiRoute,\n PayloadType,\n PluginOptionsResolved,\n ResponseType,\n TypeDeclaration,\n} from \"@kosmojs/devlib\";\n\ntype PathResolver = (path: string) => string;\n\nexport const createProject = (opts?: ProjectOptions) => new Project(opts);\n\nexport const resolveRouteSignature = async (\n route: Pick<ApiRoute, \"importName\" | \"fileFullpath\" | \"optionalParams\">,\n opts?: {\n relpathResolver?: PathResolver;\n sourceFile?: SourceFile;\n withReferencedFiles?: boolean;\n },\n) => {\n const {\n sourceFile = createProject().addSourceFileAtPath(route.fileFullpath),\n } = { ...opts };\n\n const [typeDeclarations, referencedFiles] = extractTypeDeclarations(\n sourceFile,\n opts,\n );\n\n const defaultExport = extractDefaultExport(sourceFile);\n\n const paramsRefinements = defaultExport\n ? extractParamsRefinements(defaultExport)\n : undefined;\n\n const methods = defaultExport\n ? extractRouteMethods(defaultExport, route)\n : [];\n\n const payloadTypes = methods.flatMap((e) => {\n return e.payloadType ? [e.payloadType] : [];\n });\n\n const responseTypes = methods.flatMap((e) => {\n return e.responseType ? [e.responseType] : [];\n });\n\n return {\n typeDeclarations,\n paramsRefinements,\n methods: methods.map((e) => e.method),\n payloadTypes,\n responseTypes,\n referencedFiles,\n };\n};\n\nexport const extractDefaultExport = (\n sourceFile: SourceFile,\n): CallExpression | undefined => {\n const [defaultExport] = sourceFile\n .getExportAssignments()\n .flatMap((exportAssignment) => {\n if (exportAssignment.isExportEquals()) {\n return [];\n }\n const callExpression = exportAssignment.getExpression();\n return callExpression.isKind(SyntaxKind.CallExpression)\n ? [callExpression]\n : [];\n });\n return defaultExport;\n};\n\nexport const extractParamsRefinements = (\n callExpression: CallExpression,\n):\n | Array<{\n index: number;\n text: string;\n }>\n | undefined => {\n const [firstGeneric] = extractGenerics(callExpression);\n\n if (!firstGeneric?.node.isKind(SyntaxKind.TupleType)) {\n return;\n }\n\n const tupleElements = firstGeneric.node.getElements();\n\n if (!tupleElements?.length) {\n return;\n }\n\n return tupleElements.map((node, index) => {\n return {\n index,\n text: node.getText(),\n };\n });\n};\n\nexport const extractRouteMethods = (\n callExpression: CallExpression,\n route: Pick<ApiRoute, \"importName\" | \"optionalParams\">,\n): Array<{\n method: HTTPMethod;\n payloadType: (PayloadType & { text: string }) | undefined;\n responseType: (ResponseType & { text: string }) | undefined;\n}> => {\n const funcDeclaration =\n callExpression.getFirstChildByKind(SyntaxKind.ArrowFunction) ||\n callExpression.getFirstChildByKind(SyntaxKind.FunctionExpression);\n\n if (!funcDeclaration) {\n return [];\n }\n\n const arrayLiteralExpression = funcDeclaration.getFirstChildByKind(\n SyntaxKind.ArrayLiteralExpression,\n );\n\n if (!arrayLiteralExpression) {\n return [];\n }\n\n const callExpressions: Array<[CallExpression, HTTPMethod]> = [];\n\n for (const e of arrayLiteralExpression.getChildrenOfKind(\n SyntaxKind.CallExpression,\n )) {\n const name = e.getExpression().getText() as HTTPMethod;\n if (HTTPMethods[name]) {\n callExpressions.push([e, name]);\n }\n }\n\n const methods = [];\n\n const skipValidationFilter = (e: string) => /@skip-validation/.test(e);\n\n for (const [callExpression, method] of callExpressions) {\n const [payloadGeneric, responseGeneric] = extractGenerics(callExpression);\n\n const payloadText = payloadGeneric?.node\n ? payloadGeneric.node.getChildren().length === 0\n ? \"{}\"\n : payloadGeneric.node.getFullText()\n : undefined;\n\n const responseText = responseGeneric?.node.getText();\n\n const responseType = responseText\n ? {\n id: [\"ResponseT\", crc(route.importName + method)].join(\"\"),\n method,\n skipValidation: responseGeneric?.comments\n ? responseGeneric.comments.some(skipValidationFilter)\n : false,\n text: [\"never\", \"object\"].includes(responseText)\n ? \"{}\"\n : responseText,\n resolvedType: undefined,\n }\n : undefined;\n\n const payloadType = payloadText\n ? {\n id: [\"PayloadT\", crc(route.importName + method)].join(\"\"),\n responseTypeId: responseType?.id,\n method,\n skipValidation: payloadGeneric?.comments\n ? payloadGeneric.comments.some(skipValidationFilter)\n : false,\n isOptional: payloadText\n ? payloadText === \"{}\" || route.optionalParams\n : true,\n text: payloadText,\n resolvedType: undefined,\n }\n : undefined;\n\n methods.push({\n method,\n payloadType,\n responseType,\n });\n }\n\n return methods;\n};\n\nexport const extractTypeDeclarations = (\n sourceFile: SourceFile,\n opts?: {\n relpathResolver?: PathResolver;\n withReferencedFiles?: boolean;\n },\n): [d: Array<TypeDeclaration>, f?: Array<string>] => {\n const declarations: Array<TypeDeclaration> = [];\n\n const referencedFiles: Array<string> | undefined = opts?.withReferencedFiles\n ? []\n : undefined;\n\n for (const declaration of sourceFile.getImportDeclarations()) {\n const modulePath = declaration.getModuleSpecifierValue();\n\n const path = /^\\.\\.?\\/?/.test(modulePath)\n ? opts?.relpathResolver\n ? opts.relpathResolver(modulePath)\n : modulePath\n : modulePath;\n\n const typeOnlyDeclaration = declaration.isTypeOnly();\n\n const defaultImport = typeOnlyDeclaration\n ? declaration.getDefaultImport()\n : undefined;\n\n if (defaultImport) {\n const name = defaultImport.getText();\n const text = `import type ${name} from \"${path}\";`;\n declarations.push({\n importDeclaration: {\n name,\n path,\n },\n text,\n });\n if (referencedFiles) {\n referencedFiles.push(...getReferencedFiles(defaultImport));\n }\n }\n\n for (const namedImport of declaration.getNamedImports()) {\n if (namedImport.isTypeOnly() || typeOnlyDeclaration) {\n const nameNode = namedImport.getNameNode();\n const name = nameNode.getText();\n const alias = namedImport.getAliasNode()?.getText();\n const nameText = alias ? `${name} as ${alias}` : name;\n\n declarations.push({\n importDeclaration: {\n name,\n alias,\n path,\n },\n text: `import type { ${nameText} } from \"${path}\";`,\n });\n\n if (referencedFiles) {\n if (nameNode.isKind(SyntaxKind.Identifier)) {\n referencedFiles.push(...getReferencedFiles(nameNode));\n }\n }\n }\n }\n }\n\n for (const declaration of sourceFile.getTypeAliases()) {\n const name = declaration.getName();\n const text = declaration.getFullText().trim();\n declarations.push({\n typeAliasDeclaration: { name },\n text,\n });\n }\n\n for (const declaration of sourceFile.getInterfaces()) {\n const name = declaration.getName();\n const text = declaration.getFullText().trim();\n declarations.push({\n interfaceDeclaration: { name },\n text,\n });\n }\n\n for (const declaration of sourceFile.getEnums()) {\n const name = declaration.getName();\n const text = declaration.getFullText().trim();\n declarations.push({\n enumDeclaration: { name },\n text,\n });\n }\n\n for (const declaration of sourceFile.getExportDeclarations()) {\n const typeOnlyDeclaration = declaration.isTypeOnly();\n\n const modulePath = declaration.getModuleSpecifierValue();\n\n const path = modulePath\n ? /^\\.\\.?\\/?/.test(modulePath)\n ? opts?.relpathResolver\n ? opts.relpathResolver(modulePath)\n : modulePath\n : modulePath\n : undefined;\n\n for (const namedExport of declaration.getNamedExports()) {\n if (namedExport.isTypeOnly() || typeOnlyDeclaration) {\n const nameNode = namedExport.getNameNode();\n const name = nameNode.getText();\n const alias = namedExport.getAliasNode()?.getText();\n const nameText = alias ? `${name} as ${alias}` : name;\n\n declarations.push({\n exportDeclaration: {\n name,\n alias: alias ?? name,\n path,\n },\n text: path\n ? `export type { ${nameText} } from \"${path}\";`\n : `export type { ${nameText} };`,\n });\n\n if (referencedFiles) {\n if (nameNode.isKind(SyntaxKind.Identifier)) {\n referencedFiles.push(...getReferencedFiles(nameNode));\n }\n }\n }\n }\n }\n\n return referencedFiles\n ? [declarations, [...new Set<string>(referencedFiles)]]\n : [declarations];\n};\n\nconst getReferencedFiles = (importIdentifier: Identifier): Array<string> => {\n // ambient modules may have declarations in multiple files\n const declarations =\n importIdentifier //\n ?.getSymbol()\n ?.getAliasedSymbol()\n ?.getDeclarations() || [];\n\n return declarations.flatMap((e) => {\n const sourceFile = e.getSourceFile();\n return sourceFile //\n ? [sourceFile.getFilePath()]\n : [];\n });\n};\n\nconst extractGenerics = (\n callExpression: CallExpression,\n): Array<{ node: Node; comments: Array<string> }> => {\n return callExpression.getTypeArguments().map((node) => {\n return {\n node,\n comments: node\n .getLeadingCommentRanges()\n .map((range) => range.getText().trim()),\n };\n });\n};\n\nexport const typeResolverFactory = ({ appRoot }: PluginOptionsResolved) => {\n const project = createProject({\n tsConfigFilePath: resolve(appRoot, \"tsconfig.json\"),\n skipAddingFilesFromTsConfig: true,\n });\n\n const literalTypesResolver = (\n literalTypes: string,\n options: Parameters<typeof flattener>[2],\n ) => {\n const sourceFile = project.createSourceFile(\n `${crc(literalTypes)}-${Date.now()}.ts`,\n literalTypes,\n { overwrite: true },\n );\n\n const resolvedTypes = flattener(project, sourceFile, {\n ...options,\n stripComments: true,\n });\n\n project.removeSourceFile(sourceFile);\n\n return resolvedTypes;\n };\n\n return {\n getSourceFile: (fileFullpath: string) => {\n return (\n project.getSourceFile(fileFullpath) ||\n project.addSourceFileAtPath(fileFullpath)\n );\n },\n refreshSourceFile: async (fileFullpath: string) => {\n const sourceFile = project.getSourceFile(fileFullpath);\n if (sourceFile) {\n await sourceFile.refreshFromFileSystem();\n }\n },\n literalTypesResolver,\n };\n};\n", "import { resolve } from \"node:path\";\n\nimport crc from \"crc/crc32\";\nimport fsx from \"fs-extra\";\n\n/**\n * Import from published package to ensure correct version at runtime.\n * Local import would be bundled with pre-bump version; this external\n * import resolves to the actual published package.json.\n * */\nimport self from \"@kosmojs/dev/package.json\" with { type: \"json\" };\nimport { type ApiRoute, pathResolver } from \"@kosmojs/devlib\";\n\nexport type Cache = {\n hash: number;\n referencedFiles: Record<string, number>;\n} & Pick<\n ApiRoute,\n | \"params\"\n | \"methods\"\n | \"typeDeclarations\"\n | \"numericParams\"\n | \"payloadTypes\"\n | \"responseTypes\"\n>;\n\ntype ExtraContext = Record<string | number, unknown>;\n\nexport const cacheFactory = (\n route: Pick<ApiRoute, \"file\" | \"fileFullpath\" | \"importName\" | \"importPath\">,\n {\n appRoot,\n sourceFolder,\n extraContext,\n }: {\n appRoot: string;\n sourceFolder: string;\n extraContext?: ExtraContext;\n },\n) => {\n const cacheFile = pathResolver({\n appRoot,\n sourceFolder,\n }).resolve(\"apiLibDir\", route.importPath, \"cache.json\");\n\n const getCache = async (opt?: {\n validate?: boolean;\n }): Promise<Cache | undefined> => {\n if (await fsx.exists(cacheFile)) {\n try {\n const cache = JSON.parse(await fsx.readFile(cacheFile, \"utf8\"));\n return opt?.validate //\n ? validateCache(cache)\n : cache;\n } catch (_e) {}\n }\n return undefined;\n };\n\n const persistCache = async ({\n referencedFiles: _referencedFiles,\n ...rest\n }: Omit<Cache, \"hash\" | \"referencedFiles\"> & {\n referencedFiles: Array<string>;\n }): Promise<Cache> => {\n const hash = await generateFileHash(route.fileFullpath, {\n ...extraContext,\n });\n\n const referencedFiles: Cache[\"referencedFiles\"] = {};\n\n for (const file of _referencedFiles) {\n referencedFiles[\n // Strip project root to ensure cached paths are relative\n // and portable across environments (CI, local, etc.)\n file.replace(`${appRoot}/`, \"\")\n ] = await generateFileHash(file);\n }\n\n const cache = { ...rest, hash, referencedFiles };\n\n await fsx.outputJson(cacheFile, cache, { spaces: 2 });\n\n return cache;\n };\n\n const validateCache = async (\n cache: Cache | undefined,\n ): Promise<Cache | undefined> => {\n if (!cache?.hash) {\n return;\n }\n\n if (!cache.typeDeclarations || !cache.referencedFiles) {\n // incomplete cache\n return;\n }\n\n const hash = await generateFileHash(route.fileFullpath, {\n ...extraContext,\n });\n\n if (!identicalHashSum(cache.hash, hash)) {\n // route itself updated\n return;\n }\n\n for (const [file, hash] of Object.entries(cache.referencedFiles)) {\n if (\n !identicalHashSum(hash, await generateFileHash(resolve(appRoot, file)))\n ) {\n // some referenced file updated\n return;\n }\n }\n\n return cache;\n };\n\n return {\n getCache,\n validateCache,\n persistCache,\n };\n};\n\nconst generateFileHash = async (\n file: string,\n extraContext?: ExtraContext,\n): Promise<number> => {\n let fileContent: string | undefined;\n try {\n fileContent = await fsx.readFile(file, \"utf8\");\n } catch (_e) {\n // file could be deleted since last build\n return 0;\n }\n return fileContent\n ? crc(\n JSON.stringify({\n ...extraContext,\n [self.cacheVersion]: fileContent,\n }),\n )\n : 0;\n};\n\n// return true if sums are identical\nconst identicalHashSum = (a: number, b: number) => {\n return a === b;\n};\n", "{{#each resolvedTypes}}\nexport type {{name}} = {{text}};\n{{/each}}\n", "{{#each typeDeclarations}}{{text}}\n{{/each}}\n\nexport type {{params.id}} = {\n {{#each paramsSchema}}\n \"{{name}}\"{{#unless isRequired}}?{{/unless}}:{{#if isRest}} Array<{{/if}}\n {{#if refinement}}{{refinement.text}}{{else}}string{{/if}}\n {{#if isRest}}>{{/if}}\n {{/each}}\n};\n\n{{#each payloadTypes}}\nexport type {{id}} = {{text}};\n{{/each}}\n\n{{#each responseTypes}}\nexport type {{id}} = {{text}};\n{{/each}}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,SAAS,MAAM,WAAAA,gBAAe;AAEvC,OAAOC,UAAS;AAChB,OAAO,eAAe;AACtB,SAAS,YAAY;AAErB;AAAA,EAEE;AAAA,EAGA,gBAAAC;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACK;;;ACjBP,SAAS,eAAe;AAExB,OAAO,SAAS;AAChB,SAAS,iBAAiB;AAC1B;AAAA,EAIE;AAAA,EAGA;AAAA,OACK;AAEP,SAA0B,mBAAmB;AAWtC,IAAM,gBAAgB,CAAC,SAA0B,IAAI,QAAQ,IAAI;AAEjE,IAAM,wBAAwB,OACnC,OACA,SAKG;AACH,QAAM;AAAA,IACJ,aAAa,cAAc,EAAE,oBAAoB,MAAM,YAAY;AAAA,EACrE,IAAI,EAAE,GAAG,KAAK;AAEd,QAAM,CAAC,kBAAkB,eAAe,IAAI;AAAA,IAC1C;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAAgB,qBAAqB,UAAU;AAErD,QAAM,oBAAoB,gBACtB,yBAAyB,aAAa,IACtC;AAEJ,QAAM,UAAU,gBACZ,oBAAoB,eAAe,KAAK,IACxC,CAAC;AAEL,QAAM,eAAe,QAAQ,QAAQ,CAAC,MAAM;AAC1C,WAAO,EAAE,cAAc,CAAC,EAAE,WAAW,IAAI,CAAC;AAAA,EAC5C,CAAC;AAED,QAAM,gBAAgB,QAAQ,QAAQ,CAAC,MAAM;AAC3C,WAAO,EAAE,eAAe,CAAC,EAAE,YAAY,IAAI,CAAC;AAAA,EAC9C,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA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ACA;AAAA,UACA;AAAA,QACF;AAEA,eAAO;AAAA,UACL,MAAM;AAAA,UACN;AAAA,QACF;AAAA,MACF;AAEA,gBAAU,IAAI,cAAc,EAAE,MAAM,QAAQ,CAAC;AAAA,IAC/C;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,MAAM,KAAK,mBAAmB;AAAA,IAC/C,KAAKA,SAAQ,SAAS,YAAY;AAAA,IAClC,UAAU;AAAA,IACV,WAAW;AAAA,IACX,QAAQ;AAAA,MACN,GAAG,SAAS,MAAM;AAAA,MAClB,GAAG,SAAS,QAAQ;AAAA,IACtB;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,WAAW,iBAAiB,UAAU;AAAA,IACtC;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
|
-
"names": ["resolve", "crc", "pathResolver", "callExpression", "resolve", "crc", "hash", "resolve", "routeFiles", "crc", "pathResolver"]
|
|
4
|
+
"sourcesContent": ["import { dirname, join, resolve } from \"node:path\";\n\nimport crc from \"crc/crc32\";\nimport picomatch from \"picomatch\";\nimport { glob } from \"tinyglobby\";\n\nimport {\n type ApiRoute,\n defaults,\n type PageRoute,\n type PluginOptionsResolved,\n pathResolver,\n pathTokensFactory,\n type RouteEntry,\n type RouteResolver,\n render,\n renderToFile,\n} from \"@kosmojs/devlib\";\n\nimport { resolveRouteSignature, typeResolverFactory } from \"./ast\";\nimport { cacheFactory } from \"./cache\";\n\nimport resolvedTypesTpl from \"./templates/resolved-types.hbs\";\nimport typesFileTpl from \"./templates/types.hbs\";\n\nexport type Resolvers = Map<string, RouteResolver>;\n\nexport type ResolveRouteFile = (file: string) =>\n | [\n // Either `apiDir` or `pagesDir`\n folder: string,\n // Path to a file within the folder, nested at least one level deep\n file: string,\n ]\n | undefined;\n\nexport type ResolversFactory = (\n routeFiles: Array<string>,\n) => Map<string, RouteResolver>;\n\nexport default async (\n pluginOptions: PluginOptionsResolved,\n): Promise<{\n resolvers: Resolvers;\n resolversFactory: ResolversFactory;\n resolveRouteFile: ResolveRouteFile;\n}> => {\n const {\n appRoot,\n sourceFolder,\n generators = [],\n formatters = [],\n refineTypeName,\n } = pluginOptions;\n\n let resolveTypes = false;\n\n for (const { options } of generators) {\n if (options?.resolveTypes) {\n resolveTypes = true;\n }\n }\n\n const {\n //\n literalTypesResolver,\n getSourceFile,\n refreshSourceFile,\n } = typeResolverFactory(pluginOptions);\n\n const routeFilePatterns = [\n `${defaults.apiDir}/**/index.ts`,\n `${defaults.pagesDir}/**/index.{ts,tsx,vue,svelte}`,\n ];\n\n const resolveRouteFile: ResolveRouteFile = (file) => {\n const [_sourceFolder, folder, ...rest] = resolve(appRoot, file)\n .replace(`${appRoot}/`, \"\")\n .split(\"/\");\n\n /**\n * Ensure the file:\n * - is under the correct source root (`sourceFolder`)\n * - belongs to a known route folder (`apiDir` or `pagesDir`)\n * - is nested at least one level deep (not a direct child of the folder)\n */\n if (!folder || _sourceFolder !== sourceFolder || rest.length < 2) {\n return;\n }\n\n return picomatch.isMatch(join(folder, ...rest), routeFilePatterns)\n ? [folder, rest.join(\"/\")]\n : undefined;\n };\n\n const resolversFactory: ResolversFactory = (routeFiles) => {\n const resolvers = new Map<\n string, // fileFullpath\n RouteResolver\n >();\n\n const entries: Array<RouteEntry> = routeFiles.flatMap((_file) => {\n const resolvedPaths = resolveRouteFile(_file);\n\n if (!resolvedPaths) {\n return [];\n }\n\n const [folder, file] = resolvedPaths;\n\n const fileFullpath = join(appRoot, sourceFolder, folder, file);\n\n const pathTokens = pathTokensFactory(dirname(file));\n\n const name = pathTokens.map((e) => e.orig).join(\"/\");\n\n const importPath = dirname(file);\n\n const importName = [\n importPath\n .split(/\\[/)[0]\n .replace(/^\\W+|\\W+$/g, \"\")\n .replace(/\\W+/g, \"_\"),\n crc(importPath),\n ].join(\"_\");\n\n return [\n {\n name,\n folder,\n file,\n fileFullpath,\n pathTokens,\n importPath,\n importName,\n },\n ];\n });\n\n for (const entry of entries.filter((e) => e.folder === defaults.apiDir)) {\n const {\n name,\n file,\n folder,\n fileFullpath,\n pathTokens,\n importPath,\n importName,\n } = entry;\n\n const handler: RouteResolver[\"handler\"] = async (updatedFile) => {\n const paramsSchema = pathTokens.flatMap((e) => {\n return e.param ? [e.param] : [];\n });\n\n const optionalParams = paramsSchema.length\n ? !paramsSchema.some((e) => e.isRequired)\n : true;\n\n const { getCache, persistCache } = cacheFactory(\n { file, fileFullpath, importName, importPath },\n {\n appRoot,\n sourceFolder,\n extraContext: { resolveTypes },\n },\n );\n\n let cache = await getCache({ validate: true });\n\n if (!cache) {\n if (updatedFile === fileFullpath) {\n await refreshSourceFile(fileFullpath);\n }\n\n const {\n typeDeclarations,\n paramsRefinements,\n methods,\n payloadTypes,\n responseTypes,\n referencedFiles = [],\n } = await resolveRouteSignature(\n { importName, fileFullpath, optionalParams },\n {\n withReferencedFiles: true,\n sourceFile: getSourceFile(fileFullpath),\n relpathResolver(path) {\n return join(sourceFolder, defaults.apiDir, dirname(file), path);\n },\n },\n );\n\n const numericParams = paramsRefinements\n ? paramsRefinements.flatMap(({ text, index }) => {\n if (text === \"number\") {\n const param = paramsSchema.at(index);\n return param ? [param.name] : [];\n }\n return [];\n })\n : [];\n\n const typesFile = pathResolver({ appRoot, sourceFolder }).resolve(\n \"apiLibDir\",\n importPath,\n \"types.ts\",\n );\n\n const params: ApiRoute[\"params\"] = {\n id: [\"ParamsT\", crc(name)].join(\"\"),\n schema: paramsSchema,\n resolvedType: undefined,\n };\n\n const typesFileContent = render(typesFileTpl, {\n params,\n paramsSchema: paramsSchema.map((param, index) => {\n return {\n ...param,\n refinement: paramsRefinements?.at(index),\n };\n }),\n typeDeclarations,\n payloadTypes,\n responseTypes,\n });\n\n const resolvedTypes = resolveTypes\n ? literalTypesResolver(typesFileContent, {\n overrides: [...payloadTypes, ...responseTypes].reduce(\n (map: Record<string, string>, { id, skipValidation }) => {\n if (skipValidation) {\n map[id] = \"never\";\n }\n return map;\n },\n { [refineTypeName]: refineTypeName },\n ),\n withProperties: [params.id, ...payloadTypes.map((e) => e.id)],\n formatters,\n })\n : undefined;\n\n /**\n * Deploy types.ts file; required by core generators (like fetch).\n * If types resolved, write resolved types;\n * otherwise write original types extracted from API route.\n * */\n await renderToFile(\n typesFile,\n resolvedTypes ? resolvedTypesTpl : typesFileContent,\n { resolvedTypes },\n );\n\n params.resolvedType = resolvedTypes?.find(\n (e) => e.name === params.id,\n );\n\n cache = await persistCache({\n params,\n methods,\n typeDeclarations,\n numericParams,\n // text was needed at writing types.ts file, dropping from cache\n payloadTypes: payloadTypes.map(({ text, ...rest }) => {\n return {\n ...rest,\n resolvedType: resolvedTypes?.find((e) => e.name === rest.id),\n };\n }),\n responseTypes: responseTypes.map(({ text, ...rest }) => {\n return {\n ...rest,\n resolvedType: resolvedTypes?.find((e) => e.name === rest.id),\n };\n }),\n referencedFiles,\n });\n }\n\n const route: ApiRoute = {\n name,\n pathTokens,\n params: cache.params,\n numericParams: cache.numericParams,\n optionalParams,\n importName,\n importPath,\n folder,\n file,\n fileFullpath,\n methods: cache.methods,\n typeDeclarations: cache.typeDeclarations,\n payloadTypes: cache.payloadTypes,\n responseTypes: cache.responseTypes,\n referencedFiles: Object.keys(cache.referencedFiles).map(\n // expand referenced files path,\n // they are stored as relative in cache\n (e) => resolve(appRoot, e),\n ),\n };\n\n return {\n kind: \"api\",\n route,\n };\n };\n\n resolvers.set(fileFullpath, { name, handler });\n }\n\n for (const entry of entries.filter((e) => e.folder === defaults.pagesDir)) {\n const {\n //\n name,\n folder,\n file,\n fileFullpath,\n pathTokens,\n importPath,\n importName,\n } = entry;\n\n const handler: RouteResolver[\"handler\"] = async () => {\n const route: PageRoute = {\n name,\n pathTokens,\n params: {\n schema: pathTokens.flatMap((e) => (e.param ? [e.param] : [])),\n },\n folder,\n file,\n fileFullpath,\n importPath,\n importName,\n };\n\n return {\n kind: \"page\",\n route,\n };\n };\n\n resolvers.set(fileFullpath, { name, handler });\n }\n\n return resolvers;\n };\n\n const routeFiles = await glob(routeFilePatterns, {\n cwd: resolve(appRoot, sourceFolder),\n absolute: true,\n onlyFiles: true,\n ignore: [\n `${defaults.apiDir}/index.ts`,\n `${defaults.pagesDir}/index.ts{x,}`,\n ],\n });\n\n return {\n resolvers: resolversFactory(routeFiles),\n resolversFactory,\n resolveRouteFile,\n };\n};\n", "import { resolve } from \"node:path\";\n\nimport crc from \"crc/crc32\";\nimport { flattener } from \"tfusion\";\nimport {\n type CallExpression,\n type Identifier,\n type Node,\n Project,\n type ProjectOptions,\n type SourceFile,\n SyntaxKind,\n} from \"ts-morph\";\n\nimport { type HTTPMethod, HTTPMethods } from \"@kosmojs/api\";\nimport type {\n ApiRoute,\n PayloadType,\n PluginOptionsResolved,\n ResponseType,\n TypeDeclaration,\n} from \"@kosmojs/devlib\";\n\ntype PathResolver = (path: string) => string;\n\nexport const createProject = (opts?: ProjectOptions) => new Project(opts);\n\nexport const resolveRouteSignature = async (\n route: Pick<ApiRoute, \"importName\" | \"fileFullpath\" | \"optionalParams\">,\n opts?: {\n relpathResolver?: PathResolver;\n sourceFile?: SourceFile;\n withReferencedFiles?: boolean;\n },\n) => {\n const {\n sourceFile = createProject().addSourceFileAtPath(route.fileFullpath),\n } = { ...opts };\n\n const [typeDeclarations, referencedFiles] = extractTypeDeclarations(\n sourceFile,\n opts,\n );\n\n const defaultExport = extractDefaultExport(sourceFile);\n\n const paramsRefinements = defaultExport\n ? extractParamsRefinements(defaultExport)\n : undefined;\n\n const methods = defaultExport\n ? extractRouteMethods(defaultExport, route)\n : [];\n\n const payloadTypes = methods.flatMap((e) => {\n return e.payloadType ? [e.payloadType] : [];\n });\n\n const responseTypes = methods.flatMap((e) => {\n return e.responseType ? [e.responseType] : [];\n });\n\n return {\n typeDeclarations,\n paramsRefinements,\n methods: methods.map((e) => e.method),\n payloadTypes,\n responseTypes,\n referencedFiles,\n };\n};\n\nexport const extractDefaultExport = (\n sourceFile: SourceFile,\n): CallExpression | undefined => {\n const [defaultExport] = sourceFile\n .getExportAssignments()\n .flatMap((exportAssignment) => {\n if (exportAssignment.isExportEquals()) {\n return [];\n }\n const callExpression = exportAssignment.getExpression();\n return callExpression.isKind(SyntaxKind.CallExpression)\n ? [callExpression]\n : [];\n });\n return defaultExport;\n};\n\nexport const extractParamsRefinements = (\n callExpression: CallExpression,\n):\n | Array<{\n index: number;\n text: string;\n }>\n | undefined => {\n const [firstGeneric] = extractGenerics(callExpression);\n\n if (!firstGeneric?.node.isKind(SyntaxKind.TupleType)) {\n return;\n }\n\n const tupleElements = firstGeneric.node.getElements();\n\n if (!tupleElements?.length) {\n return;\n }\n\n return tupleElements.map((node, index) => {\n return {\n index,\n text: node.getText(),\n };\n });\n};\n\nexport const extractRouteMethods = (\n callExpression: CallExpression,\n route: Pick<ApiRoute, \"importName\" | \"optionalParams\">,\n): Array<{\n method: HTTPMethod;\n payloadType: (PayloadType & { text: string }) | undefined;\n responseType: (ResponseType & { text: string }) | undefined;\n}> => {\n const funcDeclaration =\n callExpression.getFirstChildByKind(SyntaxKind.ArrowFunction) ||\n callExpression.getFirstChildByKind(SyntaxKind.FunctionExpression);\n\n if (!funcDeclaration) {\n return [];\n }\n\n const arrayLiteralExpression = funcDeclaration.getFirstChildByKind(\n SyntaxKind.ArrayLiteralExpression,\n );\n\n if (!arrayLiteralExpression) {\n return [];\n }\n\n const callExpressions: Array<[CallExpression, HTTPMethod]> = [];\n\n for (const e of arrayLiteralExpression.getChildrenOfKind(\n SyntaxKind.CallExpression,\n )) {\n const name = e.getExpression().getText() as HTTPMethod;\n if (HTTPMethods[name]) {\n callExpressions.push([e, name]);\n }\n }\n\n const methods = [];\n\n const skipValidationFilter = (e: string) => /@skip-validation/.test(e);\n\n for (const [callExpression, method] of callExpressions) {\n const [payloadGeneric, responseGeneric] = extractGenerics(callExpression);\n\n const payloadText = payloadGeneric?.node\n ? payloadGeneric.node.getChildren().length === 0\n ? \"{}\"\n : payloadGeneric.node.getFullText()\n : undefined;\n\n const responseText = responseGeneric?.node.getText();\n\n const responseType = responseText\n ? {\n id: [\"ResponseT\", crc(route.importName + method)].join(\"\"),\n method,\n skipValidation: responseGeneric?.comments\n ? responseGeneric.comments.some(skipValidationFilter)\n : false,\n text: [\"never\", \"object\"].includes(responseText)\n ? \"{}\"\n : responseText,\n resolvedType: undefined,\n }\n : undefined;\n\n const payloadType = payloadText\n ? {\n id: [\"PayloadT\", crc(route.importName + method)].join(\"\"),\n responseTypeId: responseType?.id,\n method,\n skipValidation: payloadGeneric?.comments\n ? payloadGeneric.comments.some(skipValidationFilter)\n : false,\n isOptional: payloadText\n ? payloadText === \"{}\" || route.optionalParams\n : true,\n text: payloadText,\n resolvedType: undefined,\n }\n : undefined;\n\n methods.push({\n method,\n payloadType,\n responseType,\n });\n }\n\n return methods;\n};\n\nexport const extractTypeDeclarations = (\n sourceFile: SourceFile,\n opts?: {\n relpathResolver?: PathResolver;\n withReferencedFiles?: boolean;\n },\n): [d: Array<TypeDeclaration>, f?: Array<string>] => {\n const declarations: Array<TypeDeclaration> = [];\n\n const referencedFiles: Array<string> | undefined = opts?.withReferencedFiles\n ? []\n : undefined;\n\n for (const declaration of sourceFile.getImportDeclarations()) {\n const modulePath = declaration.getModuleSpecifierValue();\n\n const path = /^\\.\\.?\\/?/.test(modulePath)\n ? opts?.relpathResolver\n ? opts.relpathResolver(modulePath)\n : modulePath\n : modulePath;\n\n const typeOnlyDeclaration = declaration.isTypeOnly();\n\n const defaultImport = typeOnlyDeclaration\n ? declaration.getDefaultImport()\n : undefined;\n\n if (defaultImport) {\n const name = defaultImport.getText();\n const text = `import type ${name} from \"${path}\";`;\n declarations.push({\n importDeclaration: {\n name,\n path,\n },\n text,\n });\n if (referencedFiles) {\n referencedFiles.push(...getReferencedFiles(defaultImport));\n }\n }\n\n for (const namedImport of declaration.getNamedImports()) {\n if (namedImport.isTypeOnly() || typeOnlyDeclaration) {\n const nameNode = namedImport.getNameNode();\n const name = nameNode.getText();\n const alias = namedImport.getAliasNode()?.getText();\n const nameText = alias ? `${name} as ${alias}` : name;\n\n declarations.push({\n importDeclaration: {\n name,\n alias,\n path,\n },\n text: `import type { ${nameText} } from \"${path}\";`,\n });\n\n if (referencedFiles) {\n if (nameNode.isKind(SyntaxKind.Identifier)) {\n referencedFiles.push(...getReferencedFiles(nameNode));\n }\n }\n }\n }\n }\n\n for (const declaration of sourceFile.getTypeAliases()) {\n const name = declaration.getName();\n const text = declaration.getFullText().trim();\n declarations.push({\n typeAliasDeclaration: { name },\n text,\n });\n }\n\n for (const declaration of sourceFile.getInterfaces()) {\n const name = declaration.getName();\n const text = declaration.getFullText().trim();\n declarations.push({\n interfaceDeclaration: { name },\n text,\n });\n }\n\n for (const declaration of sourceFile.getEnums()) {\n const name = declaration.getName();\n const text = declaration.getFullText().trim();\n declarations.push({\n enumDeclaration: { name },\n text,\n });\n }\n\n for (const declaration of sourceFile.getExportDeclarations()) {\n const typeOnlyDeclaration = declaration.isTypeOnly();\n\n const modulePath = declaration.getModuleSpecifierValue();\n\n const path = modulePath\n ? /^\\.\\.?\\/?/.test(modulePath)\n ? opts?.relpathResolver\n ? opts.relpathResolver(modulePath)\n : modulePath\n : modulePath\n : undefined;\n\n for (const namedExport of declaration.getNamedExports()) {\n if (namedExport.isTypeOnly() || typeOnlyDeclaration) {\n const nameNode = namedExport.getNameNode();\n const name = nameNode.getText();\n const alias = namedExport.getAliasNode()?.getText();\n const nameText = alias ? `${name} as ${alias}` : name;\n\n declarations.push({\n exportDeclaration: {\n name,\n alias: alias ?? name,\n path,\n },\n text: path\n ? `export type { ${nameText} } from \"${path}\";`\n : `export type { ${nameText} };`,\n });\n\n if (referencedFiles) {\n if (nameNode.isKind(SyntaxKind.Identifier)) {\n referencedFiles.push(...getReferencedFiles(nameNode));\n }\n }\n }\n }\n }\n\n return referencedFiles\n ? [declarations, [...new Set<string>(referencedFiles)]]\n : [declarations];\n};\n\nconst getReferencedFiles = (importIdentifier: Identifier): Array<string> => {\n // ambient modules may have declarations in multiple files\n const declarations =\n importIdentifier //\n ?.getSymbol()\n ?.getAliasedSymbol()\n ?.getDeclarations() || [];\n\n return declarations.flatMap((e) => {\n const sourceFile = e.getSourceFile();\n return sourceFile //\n ? [sourceFile.getFilePath()]\n : [];\n });\n};\n\nconst extractGenerics = (\n callExpression: CallExpression,\n): Array<{ node: Node; comments: Array<string> }> => {\n return callExpression.getTypeArguments().map((node) => {\n return {\n node,\n comments: node\n .getLeadingCommentRanges()\n .map((range) => range.getText().trim()),\n };\n });\n};\n\nexport const typeResolverFactory = ({ appRoot }: PluginOptionsResolved) => {\n const project = createProject({\n tsConfigFilePath: resolve(appRoot, \"tsconfig.json\"),\n skipAddingFilesFromTsConfig: true,\n });\n\n const literalTypesResolver = (\n literalTypes: string,\n options: Parameters<typeof flattener>[2],\n ) => {\n const sourceFile = project.createSourceFile(\n `${crc(literalTypes)}-${Date.now()}.ts`,\n literalTypes,\n { overwrite: true },\n );\n\n const resolvedTypes = flattener(project, sourceFile, {\n ...options,\n stripComments: true,\n });\n\n project.removeSourceFile(sourceFile);\n\n return resolvedTypes;\n };\n\n return {\n getSourceFile: (fileFullpath: string) => {\n return (\n project.getSourceFile(fileFullpath) ||\n project.addSourceFileAtPath(fileFullpath)\n );\n },\n refreshSourceFile: async (fileFullpath: string) => {\n const sourceFile = project.getSourceFile(fileFullpath);\n if (sourceFile) {\n await sourceFile.refreshFromFileSystem();\n }\n },\n literalTypesResolver,\n };\n};\n", "import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname, resolve } from \"node:path\";\n\nimport crc from \"crc/crc32\";\n\n/**\n * Import from published package to ensure correct version at runtime.\n * Local import would be bundled with pre-bump version; this external\n * import resolves to the actual published package.json.\n * */\nimport self from \"@kosmojs/dev/package.json\" with { type: \"json\" };\nimport { type ApiRoute, pathExists, pathResolver } from \"@kosmojs/devlib\";\n\nexport type Cache = {\n hash: number;\n referencedFiles: Record<string, number>;\n} & Pick<\n ApiRoute,\n | \"params\"\n | \"methods\"\n | \"typeDeclarations\"\n | \"numericParams\"\n | \"payloadTypes\"\n | \"responseTypes\"\n>;\n\ntype ExtraContext = Record<string | number, unknown>;\n\nexport const cacheFactory = (\n route: Pick<ApiRoute, \"file\" | \"fileFullpath\" | \"importName\" | \"importPath\">,\n {\n appRoot,\n sourceFolder,\n extraContext,\n }: {\n appRoot: string;\n sourceFolder: string;\n extraContext?: ExtraContext;\n },\n) => {\n const cacheFile = pathResolver({\n appRoot,\n sourceFolder,\n }).resolve(\"apiLibDir\", route.importPath, \"cache.json\");\n\n const getCache = async (opt?: {\n validate?: boolean;\n }): Promise<Cache | undefined> => {\n if (await pathExists(cacheFile)) {\n try {\n const cache = JSON.parse(await readFile(cacheFile, \"utf8\"));\n return opt?.validate //\n ? validateCache(cache)\n : cache;\n } catch (_e) {}\n }\n return undefined;\n };\n\n const persistCache = async ({\n referencedFiles: _referencedFiles,\n ...rest\n }: Omit<Cache, \"hash\" | \"referencedFiles\"> & {\n referencedFiles: Array<string>;\n }): Promise<Cache> => {\n const hash = await generateFileHash(route.fileFullpath, {\n ...extraContext,\n });\n\n const referencedFiles: Cache[\"referencedFiles\"] = {};\n\n for (const file of _referencedFiles) {\n referencedFiles[\n // Strip project root to ensure cached paths are relative\n // and portable across environments (CI, local, etc.)\n file.replace(`${appRoot}/`, \"\")\n ] = await generateFileHash(file);\n }\n\n const cache = { ...rest, hash, referencedFiles };\n\n await mkdir(dirname(cacheFile), { recursive: true });\n await writeFile(cacheFile, JSON.stringify(cache, null, 2), \"utf8\");\n\n return cache;\n };\n\n const validateCache = async (\n cache: Cache | undefined,\n ): Promise<Cache | undefined> => {\n if (!cache?.hash) {\n return;\n }\n\n if (!cache.typeDeclarations || !cache.referencedFiles) {\n // incomplete cache\n return;\n }\n\n const hash = await generateFileHash(route.fileFullpath, {\n ...extraContext,\n });\n\n if (!identicalHashSum(cache.hash, hash)) {\n // route itself updated\n return;\n }\n\n for (const [file, hash] of Object.entries(cache.referencedFiles)) {\n if (\n !identicalHashSum(hash, await generateFileHash(resolve(appRoot, file)))\n ) {\n // some referenced file updated\n return;\n }\n }\n\n return cache;\n };\n\n return {\n getCache,\n validateCache,\n persistCache,\n };\n};\n\nconst generateFileHash = async (\n file: string,\n extraContext?: ExtraContext,\n): Promise<number> => {\n let fileContent: string | undefined;\n try {\n fileContent = await readFile(file, \"utf8\");\n } catch (_e) {\n // file could be deleted since last build\n return 0;\n }\n return fileContent\n ? crc(\n JSON.stringify({\n ...extraContext,\n [self.cacheVersion]: fileContent,\n }),\n )\n : 0;\n};\n\n// return true if sums are identical\nconst identicalHashSum = (a: number, b: number) => {\n return a === b;\n};\n", "{{#each resolvedTypes}}\nexport type {{name}} = {{text}};\n{{/each}}\n", "{{#each typeDeclarations}}{{text}}\n{{/each}}\n\nexport type {{params.id}} = {\n {{#each paramsSchema}}\n \"{{name}}\"{{#unless isRequired}}?{{/unless}}:{{#if isRest}} Array<{{/if}}\n {{#if refinement}}{{refinement.text}}{{else}}string{{/if}}\n {{#if isRest}}>{{/if}}\n {{/each}}\n};\n\n{{#each payloadTypes}}\nexport type {{id}} = {{text}};\n{{/each}}\n\n{{#each responseTypes}}\nexport type {{id}} = {{text}};\n{{/each}}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,WAAAA,UAAS,MAAM,WAAAC,gBAAe;AAEvC,OAAOC,UAAS;AAChB,OAAO,eAAe;AACtB,SAAS,YAAY;AAErB;AAAA,EAEE;AAAA,EAGA,gBAAAC;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACK;;;ACjBP,SAAS,eAAe;AAExB,OAAO,SAAS;AAChB,SAAS,iBAAiB;AAC1B;AAAA,EAIE;AAAA,EAGA;AAAA,OACK;AAEP,SAA0B,mBAAmB;AAWtC,IAAM,gBAAgB,CAAC,SAA0B,IAAI,QAAQ,IAAI;AAEjE,IAAM,wBAAwB,OACnC,OACA,SAKG;AACH,QAAM;AAAA,IACJ,aAAa,cAAc,EAAE,oBAAoB,MAAM,YAAY;AAAA,EACrE,IAAI,EAAE,GAAG,KAAK;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A,UAC3B;AAAA,QACF;AAEA,eAAO;AAAA,UACL,MAAM;AAAA,UACN;AAAA,QACF;AAAA,MACF;AAEA,gBAAU,IAAI,cAAc,EAAE,MAAM,QAAQ,CAAC;AAAA,IAC/C;AAEA,eAAW,SAAS,QAAQ,OAAO,CAAC,MAAM,EAAE,WAAW,SAAS,QAAQ,GAAG;AACzE,YAAM;AAAA;AAAA,QAEJ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,IAAI;AAEJ,YAAM,UAAoC,YAAY;AACpD,cAAM,QAAmB;AAAA,UACvB;AAAA,UACA;AAAA,UACA,QAAQ;AAAA,YACN,QAAQ,WAAW,QAAQ,CAAC,MAAO,EAAE,QAAQ,CAAC,EAAE,KAAK,IAAI,CAAC,CAAE;AAAA,UAC9D;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,eAAO;AAAA,UACL,MAAM;AAAA,UACN;AAAA,QACF;AAAA,MACF;AAEA,gBAAU,IAAI,cAAc,EAAE,MAAM,QAAQ,CAAC;AAAA,IAC/C;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,MAAM,KAAK,mBAAmB;AAAA,IAC/C,KAAKA,SAAQ,SAAS,YAAY;AAAA,IAClC,UAAU;AAAA,IACV,WAAW;AAAA,IACX,QAAQ;AAAA,MACN,GAAG,SAAS,MAAM;AAAA,MAClB,GAAG,SAAS,QAAQ;AAAA,IACtB;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,WAAW,iBAAiB,UAAU;AAAA,IACtC;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["dirname", "resolve", "crc", "pathResolver", "callExpression", "resolve", "crc", "hash", "resolve", "routeFiles", "dirname", "crc", "pathResolver"]
|
|
7
7
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@kosmojs/devlib";
|
|
8
8
|
|
|
9
9
|
// src/base-plugin/routes.ts
|
|
10
|
-
import { dirname, join, resolve as resolve3 } from "node:path";
|
|
10
|
+
import { dirname as dirname2, join, resolve as resolve3 } from "node:path";
|
|
11
11
|
import crc3 from "crc/crc32";
|
|
12
12
|
import picomatch from "picomatch";
|
|
13
13
|
import { glob } from "tinyglobby";
|
|
@@ -275,11 +275,11 @@ var typeResolverFactory = ({ appRoot: appRoot2 }) => {
|
|
|
275
275
|
};
|
|
276
276
|
|
|
277
277
|
// src/base-plugin/cache.ts
|
|
278
|
-
import {
|
|
278
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
279
|
+
import { dirname, resolve as resolve2 } from "node:path";
|
|
279
280
|
import crc2 from "crc/crc32";
|
|
280
|
-
import fsx from "fs-extra";
|
|
281
281
|
import self from "@kosmojs/dev/package.json" with { type: "json" };
|
|
282
|
-
import { pathResolver } from "@kosmojs/devlib";
|
|
282
|
+
import { pathExists, pathResolver } from "@kosmojs/devlib";
|
|
283
283
|
var cacheFactory = (route, {
|
|
284
284
|
appRoot: appRoot2,
|
|
285
285
|
sourceFolder: sourceFolder2,
|
|
@@ -290,9 +290,9 @@ var cacheFactory = (route, {
|
|
|
290
290
|
sourceFolder: sourceFolder2
|
|
291
291
|
}).resolve("apiLibDir", route.importPath, "cache.json");
|
|
292
292
|
const getCache = async (opt) => {
|
|
293
|
-
if (await
|
|
293
|
+
if (await pathExists(cacheFile)) {
|
|
294
294
|
try {
|
|
295
|
-
const cache = JSON.parse(await
|
|
295
|
+
const cache = JSON.parse(await readFile(cacheFile, "utf8"));
|
|
296
296
|
return opt?.validate ? validateCache(cache) : cache;
|
|
297
297
|
} catch (_e) {
|
|
298
298
|
}
|
|
@@ -315,7 +315,8 @@ var cacheFactory = (route, {
|
|
|
315
315
|
] = await generateFileHash(file);
|
|
316
316
|
}
|
|
317
317
|
const cache = { ...rest, hash, referencedFiles };
|
|
318
|
-
await
|
|
318
|
+
await mkdir(dirname(cacheFile), { recursive: true });
|
|
319
|
+
await writeFile(cacheFile, JSON.stringify(cache, null, 2), "utf8");
|
|
319
320
|
return cache;
|
|
320
321
|
};
|
|
321
322
|
const validateCache = async (cache) => {
|
|
@@ -347,7 +348,7 @@ var cacheFactory = (route, {
|
|
|
347
348
|
var generateFileHash = async (file, extraContext) => {
|
|
348
349
|
let fileContent;
|
|
349
350
|
try {
|
|
350
|
-
fileContent = await
|
|
351
|
+
fileContent = await readFile(file, "utf8");
|
|
351
352
|
} catch (_e) {
|
|
352
353
|
return 0;
|
|
353
354
|
}
|
|
@@ -409,9 +410,9 @@ var routes_default = async (pluginOptions) => {
|
|
|
409
410
|
}
|
|
410
411
|
const [folder, file] = resolvedPaths;
|
|
411
412
|
const fileFullpath = join(appRoot2, sourceFolder2, folder, file);
|
|
412
|
-
const pathTokens = pathTokensFactory(
|
|
413
|
+
const pathTokens = pathTokensFactory(dirname2(file));
|
|
413
414
|
const name = pathTokens.map((e) => e.orig).join("/");
|
|
414
|
-
const importPath =
|
|
415
|
+
const importPath = dirname2(file);
|
|
415
416
|
const importName = [
|
|
416
417
|
importPath.split(/\[/)[0].replace(/^\W+|\W+$/g, "").replace(/\W+/g, "_"),
|
|
417
418
|
crc3(importPath)
|
|
@@ -469,7 +470,7 @@ var routes_default = async (pluginOptions) => {
|
|
|
469
470
|
withReferencedFiles: true,
|
|
470
471
|
sourceFile: getSourceFile(fileFullpath),
|
|
471
472
|
relpathResolver(path) {
|
|
472
|
-
return join(sourceFolder2, defaults.apiDir,
|
|
473
|
+
return join(sourceFolder2, defaults.apiDir, dirname2(file), path);
|
|
473
474
|
}
|
|
474
475
|
}
|
|
475
476
|
);
|