@faasjs/dev 8.0.0-beta.7 → 8.0.0-beta.9
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 +40 -0
- package/configs/oxfmt.base.json +16 -0
- package/configs/oxlint.base.json +5 -0
- package/dist/{chunk-CtajNgzt.mjs → chunk-D8kEL_kv.mjs} +2 -0
- package/dist/cli/index.cjs +297 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.mjs +295 -0
- package/dist/index.cjs +17 -33
- package/dist/index.d.ts +5 -6
- package/dist/index.mjs +14 -29
- package/dist/{typegen-D5s91_xL.mjs → typegen-BNWmP5Qp.mjs} +26 -27
- package/dist/{typegen-C6t9LIyi.cjs → typegen-HX5QyuhP.cjs} +25 -26
- package/faas.mjs +7 -0
- package/package.json +30 -33
- package/dist/cli.cjs +0 -67
- package/dist/cli.d.ts +0 -4
- package/dist/cli.mjs +0 -66
- package/faas-types.mjs +0 -7
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
let _faasjs_logger = require("@faasjs/logger");
|
|
2
1
|
let _faasjs_node_utils = require("@faasjs/node-utils");
|
|
3
2
|
let node_fs = require("node:fs");
|
|
4
3
|
let node_fs_promises = require("node:fs/promises");
|
|
@@ -15,24 +14,24 @@ function resolveServerConfig(root, logger, defaultBase = "/") {
|
|
|
15
14
|
const config = (0, _faasjs_node_utils.loadConfig)(srcRoot, (0, node_path.join)(srcRoot, "index.func.ts"), staging, logger);
|
|
16
15
|
const server = config && typeof config === "object" ? config.server : void 0;
|
|
17
16
|
return {
|
|
18
|
-
root:
|
|
19
|
-
base:
|
|
17
|
+
root: typeof server?.root === "string" && server.root.length ? (0, node_path.resolve)(projectRoot, server.root) : projectRoot,
|
|
18
|
+
base: typeof server?.base === "string" && server.base.length ? server.base : defaultBase,
|
|
20
19
|
staging
|
|
21
20
|
};
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
//#endregion
|
|
25
24
|
//#region src/typegen.ts
|
|
26
|
-
function normalizeSlashes(path) {
|
|
27
|
-
return path.replace(/\\/g, "/");
|
|
28
|
-
}
|
|
29
25
|
function normalizeRoute(path) {
|
|
30
|
-
const normalized = path.replace(/\/+/g, "/");
|
|
26
|
+
const normalized = path.replace(/\\/g, "/").replace(/\/+/g, "/");
|
|
31
27
|
if (!normalized.length || normalized === "/") return "/";
|
|
32
28
|
return normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
|
|
33
29
|
}
|
|
30
|
+
function toTypegenRoute(route) {
|
|
31
|
+
return route === "/" ? "/" : route.replace(/^\/+/, "");
|
|
32
|
+
}
|
|
34
33
|
function toRoute(srcRoot, file) {
|
|
35
|
-
const noTsPath =
|
|
34
|
+
const noTsPath = (0, node_path.relative)(srcRoot, file).replace(/\\/g, "/").replace(/\.ts$/, "");
|
|
36
35
|
if (noTsPath === "index.func") return {
|
|
37
36
|
route: "/",
|
|
38
37
|
priority: 2
|
|
@@ -53,10 +52,10 @@ function toRoute(srcRoot, file) {
|
|
|
53
52
|
route: normalizeRoute(`/${noTsPath.slice(0, -5)}`),
|
|
54
53
|
priority: 3
|
|
55
54
|
};
|
|
56
|
-
throw Error(`[faas
|
|
55
|
+
throw Error(`[faas types] Invalid func filename: ${file}`);
|
|
57
56
|
}
|
|
58
57
|
function toImportPath(fromFile, targetFile) {
|
|
59
|
-
const importPath =
|
|
58
|
+
const importPath = (0, node_path.relative)((0, node_path.dirname)(fromFile), targetFile).replace(/\\/g, "/").replace(/\.ts$/, "");
|
|
60
59
|
if (importPath.startsWith(".")) return importPath;
|
|
61
60
|
return `./${importPath}`;
|
|
62
61
|
}
|
|
@@ -81,35 +80,36 @@ function parsePluginTypes(config) {
|
|
|
81
80
|
}
|
|
82
81
|
async function readFuncFiles(dir) {
|
|
83
82
|
const result = [];
|
|
84
|
-
|
|
83
|
+
const pendingDirs = [dir];
|
|
84
|
+
while (pendingDirs.length) {
|
|
85
|
+
const currentDir = pendingDirs.pop();
|
|
85
86
|
const entries = await (0, node_fs_promises.readdir)(currentDir, { withFileTypes: true });
|
|
86
87
|
for (const entry of entries) {
|
|
87
88
|
if (entry.name === ".faasjs" || entry.name === "node_modules") continue;
|
|
88
89
|
const filePath = (0, node_path.join)(currentDir, entry.name);
|
|
89
90
|
if (entry.isDirectory()) {
|
|
90
|
-
|
|
91
|
+
pendingDirs.push(filePath);
|
|
91
92
|
continue;
|
|
92
93
|
}
|
|
93
94
|
if (entry.isFile() && entry.name.endsWith(".func.ts")) result.push(filePath);
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
|
-
await walk(dir);
|
|
97
97
|
return result.sort((a, b) => a.localeCompare(b));
|
|
98
98
|
}
|
|
99
99
|
function formatTypes(items) {
|
|
100
100
|
const actionLines = items.map((item) => {
|
|
101
|
-
return ` ${JSON.stringify(item.route)}: InferFaasAction<InferFaasFunc<typeof import(${JSON.stringify(item.importPath)})>>`;
|
|
101
|
+
return ` ${JSON.stringify(toTypegenRoute(item.route))}: InferFaasAction<InferFaasFunc<typeof import(${JSON.stringify(item.importPath)})>>`;
|
|
102
102
|
});
|
|
103
103
|
const eventLines = items.map((item) => {
|
|
104
104
|
const plugins = item.pluginTypes.length ? `[${item.pluginTypes.map((type) => JSON.stringify(type)).join(", ")}]` : "[]";
|
|
105
|
-
return ` ${JSON.stringify(item.route)}: InferPluginEvent<${plugins}>`;
|
|
105
|
+
return ` ${JSON.stringify(toTypegenRoute(item.route))}: InferPluginEvent<${plugins}>`;
|
|
106
106
|
});
|
|
107
107
|
return `/**
|
|
108
108
|
* Generated by @faasjs/dev.
|
|
109
109
|
*
|
|
110
110
|
* Do not edit this file manually.
|
|
111
111
|
*/
|
|
112
|
-
import type { Func, InferPluginEvent } from '@faasjs/
|
|
112
|
+
import type { Func, InferPluginEvent } from '@faasjs/core'
|
|
113
113
|
import type { InferFaasAction, InferFaasFunc } from '@faasjs/types'
|
|
114
114
|
|
|
115
115
|
declare module '@faasjs/types' {
|
|
@@ -122,25 +122,24 @@ ${eventLines.length ? `${eventLines.join("\n")}\n` : ""} }
|
|
|
122
122
|
`;
|
|
123
123
|
}
|
|
124
124
|
function isTypegenSourceFile(filePath) {
|
|
125
|
-
return
|
|
125
|
+
return filePath.endsWith(".func.ts") || /(^|[\\/])faas\.ya?ml$/.test(filePath);
|
|
126
126
|
}
|
|
127
127
|
async function generateFaasTypes(options = {}) {
|
|
128
|
-
const logger = options.logger
|
|
129
|
-
const { root: projectRoot, staging } = resolveServerConfig(options.root
|
|
128
|
+
const logger = options.logger ?? new _faasjs_node_utils.Logger("FaasJs:Typegen");
|
|
129
|
+
const { root: projectRoot, staging } = resolveServerConfig(options.root ?? process.cwd(), logger);
|
|
130
130
|
const srcRoot = (0, node_path.join)(projectRoot, "src");
|
|
131
131
|
const output = (0, node_path.join)(srcRoot, ".faasjs", "types.d.ts");
|
|
132
|
-
if (!(0, node_fs.existsSync)(srcRoot)) throw Error(`[faas
|
|
132
|
+
if (!(0, node_fs.existsSync)(srcRoot)) throw Error(`[faas types] Source directory not found: ${srcRoot}`);
|
|
133
133
|
const files = await readFuncFiles(srcRoot);
|
|
134
134
|
const routeMap = /* @__PURE__ */ new Map();
|
|
135
135
|
for (const file of files) {
|
|
136
136
|
const { route, priority } = toRoute(srcRoot, file);
|
|
137
|
-
const pluginTypes = parsePluginTypes((0, _faasjs_node_utils.loadConfig)(srcRoot, file, staging, logger));
|
|
138
|
-
const importPath = toImportPath(output, file);
|
|
139
137
|
const prev = routeMap.get(route);
|
|
140
|
-
if (
|
|
138
|
+
if (prev && priority <= prev.priority) continue;
|
|
139
|
+
routeMap.set(route, {
|
|
141
140
|
route,
|
|
142
|
-
importPath,
|
|
143
|
-
pluginTypes,
|
|
141
|
+
importPath: toImportPath(output, file),
|
|
142
|
+
pluginTypes: parsePluginTypes((0, _faasjs_node_utils.loadConfig)(srcRoot, file, staging, logger)),
|
|
144
143
|
priority
|
|
145
144
|
});
|
|
146
145
|
}
|
|
@@ -149,7 +148,7 @@ async function generateFaasTypes(options = {}) {
|
|
|
149
148
|
let changed = true;
|
|
150
149
|
try {
|
|
151
150
|
if (await (0, node_fs_promises.readFile)(output, "utf8") === content) changed = false;
|
|
152
|
-
} catch
|
|
151
|
+
} catch {}
|
|
153
152
|
if (changed) {
|
|
154
153
|
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(output), { recursive: true });
|
|
155
154
|
await (0, node_fs_promises.writeFile)(output, content);
|
package/faas.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/dev",
|
|
3
|
-
"version": "8.0.0-beta.
|
|
3
|
+
"version": "8.0.0-beta.9",
|
|
4
|
+
"homepage": "https://faasjs.com/doc/dev",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/faasjs/faasjs/issues"
|
|
7
|
+
},
|
|
4
8
|
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/faasjs/faasjs.git",
|
|
12
|
+
"directory": "packages/dev"
|
|
13
|
+
},
|
|
14
|
+
"funding": "https://github.com/sponsors/faasjs",
|
|
15
|
+
"bin": {
|
|
16
|
+
"faas": "faas.mjs"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"faas.mjs",
|
|
21
|
+
"configs"
|
|
22
|
+
],
|
|
5
23
|
"type": "module",
|
|
6
24
|
"main": "dist/index.cjs",
|
|
7
25
|
"module": "dist/index.mjs",
|
|
8
26
|
"types": "dist/index.d.ts",
|
|
9
|
-
"bin": {
|
|
10
|
-
"faas-types": "faas-types.mjs"
|
|
11
|
-
},
|
|
12
27
|
"exports": {
|
|
13
28
|
".": {
|
|
14
29
|
"types": "./dist/index.d.ts",
|
|
@@ -16,44 +31,26 @@
|
|
|
16
31
|
"require": "./dist/index.cjs"
|
|
17
32
|
}
|
|
18
33
|
},
|
|
19
|
-
"homepage": "https://faasjs.com/doc/dev",
|
|
20
|
-
"repository": {
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/faasjs/faasjs.git",
|
|
23
|
-
"directory": "packages/dev"
|
|
24
|
-
},
|
|
25
|
-
"bugs": {
|
|
26
|
-
"url": "https://github.com/faasjs/faasjs/issues"
|
|
27
|
-
},
|
|
28
|
-
"funding": "https://github.com/sponsors/faasjs",
|
|
29
34
|
"scripts": {
|
|
30
|
-
"build": "tsdown --entry src/index.ts --entry src/cli.ts --config ../../tsdown.config.ts"
|
|
35
|
+
"build": "tsdown --entry src/index.ts --entry src/cli/index.ts --config ../../tsdown.config.ts"
|
|
31
36
|
},
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
],
|
|
36
|
-
"peerDependencies": {
|
|
37
|
-
"@faasjs/func": ">=8.0.0-beta.7",
|
|
38
|
-
"@faasjs/http": ">=8.0.0-beta.7",
|
|
39
|
-
"@faasjs/knex": ">=8.0.0-beta.7",
|
|
40
|
-
"@faasjs/logger": ">=8.0.0-beta.7",
|
|
41
|
-
"@faasjs/node-utils": ">=8.0.0-beta.7",
|
|
42
|
-
"@faasjs/server": ">=8.0.0-beta.7",
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@faasjs/core": ">=8.0.0-beta.9",
|
|
39
|
+
"@faasjs/node-utils": ">=8.0.0-beta.9",
|
|
43
40
|
"@types/node": "*",
|
|
44
41
|
"knex": "*",
|
|
42
|
+
"oxfmt": "*",
|
|
43
|
+
"oxlint": "*",
|
|
45
44
|
"vite": "*",
|
|
46
45
|
"vitest": "*"
|
|
47
46
|
},
|
|
48
|
-
"
|
|
49
|
-
"@faasjs/
|
|
50
|
-
"@faasjs/
|
|
51
|
-
"@faasjs/knex": ">=8.0.0-beta.7",
|
|
52
|
-
"@faasjs/logger": ">=8.0.0-beta.7",
|
|
53
|
-
"@faasjs/node-utils": ">=8.0.0-beta.7",
|
|
54
|
-
"@faasjs/server": ">=8.0.0-beta.7",
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@faasjs/core": ">=8.0.0-beta.9",
|
|
49
|
+
"@faasjs/node-utils": ">=8.0.0-beta.9",
|
|
55
50
|
"@types/node": "*",
|
|
56
51
|
"knex": "*",
|
|
52
|
+
"oxfmt": "*",
|
|
53
|
+
"oxlint": "*",
|
|
57
54
|
"vite": "*",
|
|
58
55
|
"vitest": "*"
|
|
59
56
|
},
|
package/dist/cli.cjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_typegen = require('./typegen-C6t9LIyi.cjs');
|
|
3
|
-
|
|
4
|
-
//#region package.json
|
|
5
|
-
var version = "8.0.0-beta.6";
|
|
6
|
-
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/cli.ts
|
|
9
|
-
const HelpText = `Generate FaasJS API/event type declarations.
|
|
10
|
-
|
|
11
|
-
Usage:
|
|
12
|
-
faas-types [options]
|
|
13
|
-
|
|
14
|
-
Options:
|
|
15
|
-
--root <path> Project root path (default: process.cwd())
|
|
16
|
-
-h, --help Show help
|
|
17
|
-
-v, --version Show version
|
|
18
|
-
`;
|
|
19
|
-
function parseCliArgs(argv) {
|
|
20
|
-
const args = argv.slice(2);
|
|
21
|
-
const options = {};
|
|
22
|
-
const readValue = (index, name) => {
|
|
23
|
-
const value = args[index + 1];
|
|
24
|
-
if (!value || value.startsWith("-")) throw Error(`[faas-types] Missing value for ${name}`);
|
|
25
|
-
return value;
|
|
26
|
-
};
|
|
27
|
-
for (let i = 0; i < args.length; i++) {
|
|
28
|
-
const arg = args[i];
|
|
29
|
-
if (arg === "-h" || arg === "--help") return {
|
|
30
|
-
showHelp: true,
|
|
31
|
-
options
|
|
32
|
-
};
|
|
33
|
-
if (arg === "-v" || arg === "--version") return {
|
|
34
|
-
showVersion: true,
|
|
35
|
-
options
|
|
36
|
-
};
|
|
37
|
-
if (arg === "--root") {
|
|
38
|
-
options.root = readValue(i, arg);
|
|
39
|
-
i++;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
throw Error(`[faas-types] Unknown option: ${arg}`);
|
|
43
|
-
}
|
|
44
|
-
return { options };
|
|
45
|
-
}
|
|
46
|
-
async function main(argv = process.argv) {
|
|
47
|
-
try {
|
|
48
|
-
const parsed = parseCliArgs(argv);
|
|
49
|
-
if (parsed.showHelp) {
|
|
50
|
-
console.log(HelpText);
|
|
51
|
-
return 0;
|
|
52
|
-
}
|
|
53
|
-
if (parsed.showVersion) {
|
|
54
|
-
console.log(version);
|
|
55
|
-
return 0;
|
|
56
|
-
}
|
|
57
|
-
const result = await require_typegen.generateFaasTypes(parsed.options);
|
|
58
|
-
console.log(`[faas-types] ${result.changed ? "Generated" : "Up to date"} ${result.output} (${result.routeCount} routes from ${result.fileCount} files)`);
|
|
59
|
-
return 0;
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.error(error?.message || error);
|
|
62
|
-
return 1;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
exports.main = main;
|
package/dist/cli.d.ts
DELETED
package/dist/cli.mjs
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { t as generateFaasTypes } from "./typegen-D5s91_xL.mjs";
|
|
2
|
-
|
|
3
|
-
//#region package.json
|
|
4
|
-
var version = "8.0.0-beta.6";
|
|
5
|
-
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/cli.ts
|
|
8
|
-
const HelpText = `Generate FaasJS API/event type declarations.
|
|
9
|
-
|
|
10
|
-
Usage:
|
|
11
|
-
faas-types [options]
|
|
12
|
-
|
|
13
|
-
Options:
|
|
14
|
-
--root <path> Project root path (default: process.cwd())
|
|
15
|
-
-h, --help Show help
|
|
16
|
-
-v, --version Show version
|
|
17
|
-
`;
|
|
18
|
-
function parseCliArgs(argv) {
|
|
19
|
-
const args = argv.slice(2);
|
|
20
|
-
const options = {};
|
|
21
|
-
const readValue = (index, name) => {
|
|
22
|
-
const value = args[index + 1];
|
|
23
|
-
if (!value || value.startsWith("-")) throw Error(`[faas-types] Missing value for ${name}`);
|
|
24
|
-
return value;
|
|
25
|
-
};
|
|
26
|
-
for (let i = 0; i < args.length; i++) {
|
|
27
|
-
const arg = args[i];
|
|
28
|
-
if (arg === "-h" || arg === "--help") return {
|
|
29
|
-
showHelp: true,
|
|
30
|
-
options
|
|
31
|
-
};
|
|
32
|
-
if (arg === "-v" || arg === "--version") return {
|
|
33
|
-
showVersion: true,
|
|
34
|
-
options
|
|
35
|
-
};
|
|
36
|
-
if (arg === "--root") {
|
|
37
|
-
options.root = readValue(i, arg);
|
|
38
|
-
i++;
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
throw Error(`[faas-types] Unknown option: ${arg}`);
|
|
42
|
-
}
|
|
43
|
-
return { options };
|
|
44
|
-
}
|
|
45
|
-
async function main(argv = process.argv) {
|
|
46
|
-
try {
|
|
47
|
-
const parsed = parseCliArgs(argv);
|
|
48
|
-
if (parsed.showHelp) {
|
|
49
|
-
console.log(HelpText);
|
|
50
|
-
return 0;
|
|
51
|
-
}
|
|
52
|
-
if (parsed.showVersion) {
|
|
53
|
-
console.log(version);
|
|
54
|
-
return 0;
|
|
55
|
-
}
|
|
56
|
-
const result = await generateFaasTypes(parsed.options);
|
|
57
|
-
console.log(`[faas-types] ${result.changed ? "Generated" : "Up to date"} ${result.output} (${result.routeCount} routes from ${result.fileCount} files)`);
|
|
58
|
-
return 0;
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.error(error?.message || error);
|
|
61
|
-
return 1;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
|
-
export { main };
|