@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
package/README.md
CHANGED
|
@@ -46,21 +46,43 @@ expect(response.data).toEqual({ message: 'Hello, FaasJS' })
|
|
|
46
46
|
|
|
47
47
|
## Functions
|
|
48
48
|
|
|
49
|
+
- [closeAll](functions/closeAll.md)
|
|
50
|
+
- [createPgliteKnex](functions/createPgliteKnex.md)
|
|
51
|
+
- [defineApi](functions/defineApi.md)
|
|
49
52
|
- [generateFaasTypes](functions/generateFaasTypes.md)
|
|
53
|
+
- [getAll](functions/getAll.md)
|
|
54
|
+
- [initPostgresTypeParsers](functions/initPostgresTypeParsers.md)
|
|
50
55
|
- [isTypegenSourceFile](functions/isTypegenSourceFile.md)
|
|
56
|
+
- [mountFaasKnex](functions/mountFaasKnex.md)
|
|
51
57
|
- [nameFunc](functions/nameFunc.md)
|
|
52
58
|
- [parseFuncFilenameFromStack](functions/parseFuncFilenameFromStack.md)
|
|
59
|
+
- [query](functions/query.md)
|
|
60
|
+
- [raw](functions/raw.md)
|
|
61
|
+
- [staticHandler](functions/staticHandler.md)
|
|
53
62
|
- [streamToObject](functions/streamToObject.md)
|
|
54
63
|
- [streamToText](functions/streamToText.md)
|
|
55
64
|
- [test](functions/test.md)
|
|
65
|
+
- [transaction](functions/transaction.md)
|
|
66
|
+
- [unmountFaasKnex](functions/unmountFaasKnex.md)
|
|
56
67
|
- [useFunc](functions/useFunc.md)
|
|
68
|
+
- [useHttp](functions/useHttp.md)
|
|
69
|
+
- [useKnex](functions/useKnex.md)
|
|
70
|
+
- [useMiddleware](functions/useMiddleware.md)
|
|
71
|
+
- [useMiddlewares](functions/useMiddlewares.md)
|
|
57
72
|
- [usePlugin](functions/usePlugin.md)
|
|
58
73
|
- [viteFaasJsServer](functions/viteFaasJsServer.md)
|
|
59
74
|
|
|
60
75
|
## Classes
|
|
61
76
|
|
|
77
|
+
- [Cookie](classes/Cookie.md)
|
|
62
78
|
- [Func](classes/Func.md)
|
|
63
79
|
- [FuncWarper](classes/FuncWarper.md)
|
|
80
|
+
- [Http](classes/Http.md)
|
|
81
|
+
- [HttpError](classes/HttpError.md)
|
|
82
|
+
- [Knex](classes/Knex.md)
|
|
83
|
+
- [KnexSchema](classes/KnexSchema.md)
|
|
84
|
+
- [Server](classes/Server.md)
|
|
85
|
+
- [Session](classes/Session.md)
|
|
64
86
|
|
|
65
87
|
## Interfaces
|
|
66
88
|
|
|
@@ -69,6 +91,9 @@ expect(response.data).toEqual({ message: 'Hello, FaasJS' })
|
|
|
69
91
|
## Type Aliases
|
|
70
92
|
|
|
71
93
|
- [Config](type-aliases/Config.md)
|
|
94
|
+
- [CookieOptions](type-aliases/CookieOptions.md)
|
|
95
|
+
- [DefineApiData](type-aliases/DefineApiData.md)
|
|
96
|
+
- [DefineApiOptions](type-aliases/DefineApiOptions.md)
|
|
72
97
|
- [ExportedHandler](type-aliases/ExportedHandler.md)
|
|
73
98
|
- [FuncConfig](type-aliases/FuncConfig.md)
|
|
74
99
|
- [FuncEventType](type-aliases/FuncEventType.md)
|
|
@@ -76,18 +101,33 @@ expect(response.data).toEqual({ message: 'Hello, FaasJS' })
|
|
|
76
101
|
- [GenerateFaasTypesOptions](type-aliases/GenerateFaasTypesOptions.md)
|
|
77
102
|
- [GenerateFaasTypesResult](type-aliases/GenerateFaasTypesResult.md)
|
|
78
103
|
- [Handler](type-aliases/Handler.md)
|
|
104
|
+
- [HttpConfig](type-aliases/HttpConfig.md)
|
|
79
105
|
- [InferPluginEvent](type-aliases/InferPluginEvent.md)
|
|
80
106
|
- [InvokeData](type-aliases/InvokeData.md)
|
|
107
|
+
- [KnexConfig](type-aliases/KnexConfig.md)
|
|
81
108
|
- [LifeCycleKey](type-aliases/LifeCycleKey.md)
|
|
109
|
+
- [Middleware](type-aliases/Middleware.md)
|
|
110
|
+
- [MiddlewareContext](type-aliases/MiddlewareContext.md)
|
|
111
|
+
- [MiddlewareEvent](type-aliases/MiddlewareEvent.md)
|
|
82
112
|
- [MountData](type-aliases/MountData.md)
|
|
113
|
+
- [MountedKnexAdapter](type-aliases/MountedKnexAdapter.md)
|
|
114
|
+
- [MountFaasKnexOptions](type-aliases/MountFaasKnexOptions.md)
|
|
83
115
|
- [Next](type-aliases/Next.md)
|
|
84
116
|
- [NormalizePluginType](type-aliases/NormalizePluginType.md)
|
|
85
117
|
- [Plugin](type-aliases/Plugin.md)
|
|
86
118
|
- [ResolvePluginEvent](type-aliases/ResolvePluginEvent.md)
|
|
119
|
+
- [Response](type-aliases/Response.md)
|
|
120
|
+
- [ServerHandlerOptions](type-aliases/ServerHandlerOptions.md)
|
|
121
|
+
- [ServerOptions](type-aliases/ServerOptions.md)
|
|
122
|
+
- [SessionContent](type-aliases/SessionContent.md)
|
|
123
|
+
- [SessionOptions](type-aliases/SessionOptions.md)
|
|
87
124
|
- [Simplify](type-aliases/Simplify.md)
|
|
125
|
+
- [StaticHandlerOptions](type-aliases/StaticHandlerOptions.md)
|
|
88
126
|
- [UnionToIntersection](type-aliases/UnionToIntersection.md)
|
|
89
127
|
- [UseifyPlugin](type-aliases/UseifyPlugin.md)
|
|
90
128
|
|
|
91
129
|
## Variables
|
|
92
130
|
|
|
131
|
+
- [ContentType](variables/ContentType.md)
|
|
132
|
+
- [originKnex](variables/originKnex.md)
|
|
93
133
|
- [streamToString](variables/streamToString.md)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"singleQuote": true,
|
|
3
|
+
"jsxSingleQuote": true,
|
|
4
|
+
"semi": false,
|
|
5
|
+
"ignorePatterns": [
|
|
6
|
+
"**/dist/**",
|
|
7
|
+
"**/build/**",
|
|
8
|
+
"**/coverage/**",
|
|
9
|
+
"**/.vercel/**",
|
|
10
|
+
"**/.nuxt/**",
|
|
11
|
+
"**/.output/**",
|
|
12
|
+
"**/.vuepress/**",
|
|
13
|
+
"**/.vitepress/**",
|
|
14
|
+
"**/.turbo/**"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_typegen = require('../typegen-HX5QyuhP.cjs');
|
|
3
|
+
let _faasjs_core = require("@faasjs/core");
|
|
4
|
+
let _faasjs_node_utils = require("@faasjs/node-utils");
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
let node_child_process = require("node:child_process");
|
|
8
|
+
let node_module = require("node:module");
|
|
9
|
+
|
|
10
|
+
//#region package.json
|
|
11
|
+
var version = "8.0.0-beta.8";
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/cli/shared.ts
|
|
15
|
+
function parseCommonCliArgs(args, scope) {
|
|
16
|
+
const options = {};
|
|
17
|
+
const rest = [];
|
|
18
|
+
for (let i = 0; i < args.length; i++) {
|
|
19
|
+
const arg = args[i];
|
|
20
|
+
if (arg === "-h" || arg === "--help") return {
|
|
21
|
+
mode: "help",
|
|
22
|
+
options,
|
|
23
|
+
rest
|
|
24
|
+
};
|
|
25
|
+
if (arg === "-v" || arg === "--version") return {
|
|
26
|
+
mode: "version",
|
|
27
|
+
options,
|
|
28
|
+
rest
|
|
29
|
+
};
|
|
30
|
+
if (arg === "--root") {
|
|
31
|
+
const value = args[i + 1];
|
|
32
|
+
if (!value || value.startsWith("-")) throw Error(`[${scope}] Missing value for ${arg}`);
|
|
33
|
+
options.root = value;
|
|
34
|
+
i += 1;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (arg.startsWith("-")) throw Error(`[${scope}] Unknown option: ${arg}`);
|
|
38
|
+
rest.push(arg);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
mode: "run",
|
|
42
|
+
options,
|
|
43
|
+
rest
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function printVersion() {
|
|
47
|
+
console.log(version);
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
async function runCli(handler) {
|
|
51
|
+
try {
|
|
52
|
+
return await handler();
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(error?.message || error);
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function createMain(run) {
|
|
59
|
+
return async (argv = process.argv) => runCli(() => run(argv.slice(2)));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/cli/knex.ts
|
|
64
|
+
const MigrateActions = [
|
|
65
|
+
"latest",
|
|
66
|
+
"rollback",
|
|
67
|
+
"status",
|
|
68
|
+
"current",
|
|
69
|
+
"make"
|
|
70
|
+
];
|
|
71
|
+
function isMigrateAction(value) {
|
|
72
|
+
return MigrateActions.includes(value);
|
|
73
|
+
}
|
|
74
|
+
const ActionHandlers = {
|
|
75
|
+
latest: (schema) => schema.migrateLatest(),
|
|
76
|
+
rollback: (schema) => schema.migrateRollback(),
|
|
77
|
+
status: async (schema) => {
|
|
78
|
+
console.log(await schema.migrateStatus());
|
|
79
|
+
},
|
|
80
|
+
current: async (schema) => {
|
|
81
|
+
console.log(await schema.migrateCurrentVersion());
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const HelpText$3 = `Run FaasJS knex migrations.
|
|
85
|
+
|
|
86
|
+
Usage:
|
|
87
|
+
faas knex <action> [name] [options]
|
|
88
|
+
|
|
89
|
+
Actions:
|
|
90
|
+
latest Run all pending migrations
|
|
91
|
+
rollback Roll back the last migration batch
|
|
92
|
+
status Print pending migration count
|
|
93
|
+
current Print current migration version
|
|
94
|
+
make <name> Create a new migration file
|
|
95
|
+
|
|
96
|
+
Options:
|
|
97
|
+
--root <path> Project root path (default: process.cwd())
|
|
98
|
+
-h, --help Show help
|
|
99
|
+
-v, --version Show version
|
|
100
|
+
`;
|
|
101
|
+
function parseCliArgs(args) {
|
|
102
|
+
const { mode, options, rest } = parseCommonCliArgs(args, "faas knex");
|
|
103
|
+
if (mode !== "run") return {
|
|
104
|
+
mode,
|
|
105
|
+
options
|
|
106
|
+
};
|
|
107
|
+
const [action, name, extra] = rest;
|
|
108
|
+
if (!action) throw Error("[faas knex] Missing action. Usage: faas knex <latest|rollback|status|current|make>");
|
|
109
|
+
if (!isMigrateAction(action)) throw Error(`[faas knex] Unknown action: ${action}`);
|
|
110
|
+
if (action !== "make") {
|
|
111
|
+
if (name) throw Error(`[faas knex] Unexpected argument: ${name}`);
|
|
112
|
+
return {
|
|
113
|
+
mode: "run",
|
|
114
|
+
action,
|
|
115
|
+
options
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (!name) throw Error("[faas knex] Missing migration name. Usage: faas knex make create_users");
|
|
119
|
+
if (extra) throw Error(`[faas knex] Unexpected argument: ${extra}`);
|
|
120
|
+
return {
|
|
121
|
+
mode: "run",
|
|
122
|
+
action: "make",
|
|
123
|
+
name,
|
|
124
|
+
options
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async function run$3(args) {
|
|
128
|
+
const parsed = parseCliArgs(args);
|
|
129
|
+
if (parsed.mode === "help") {
|
|
130
|
+
console.log(HelpText$3);
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
if (parsed.mode === "version") return printVersion();
|
|
134
|
+
const { root: projectRoot, staging } = require_typegen.resolveServerConfig(parsed.options.root ?? process.cwd());
|
|
135
|
+
const srcRoot = (0, node_path.join)(projectRoot, "src");
|
|
136
|
+
const knex = (0, _faasjs_core.useKnex)({ config: (0, _faasjs_node_utils.loadConfig)(srcRoot, (0, node_path.join)(srcRoot, "index.func.ts"), staging).plugins?.knex?.config });
|
|
137
|
+
await knex.mount();
|
|
138
|
+
const schema = new _faasjs_core.KnexSchema(knex);
|
|
139
|
+
try {
|
|
140
|
+
if (parsed.action === "make") console.log(await schema.migrateMake(parsed.name));
|
|
141
|
+
else await ActionHandlers[parsed.action](schema);
|
|
142
|
+
} finally {
|
|
143
|
+
await knex.quit();
|
|
144
|
+
}
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
const main$3 = createMain(run$3);
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/cli/lint.ts
|
|
151
|
+
const HelpText$2 = `Run formatter and lint checks with Oxc shared configs.
|
|
152
|
+
|
|
153
|
+
Usage:
|
|
154
|
+
faas lint [options]
|
|
155
|
+
|
|
156
|
+
Options:
|
|
157
|
+
--root <path> Project root path (default: process.cwd())
|
|
158
|
+
-h, --help Show help
|
|
159
|
+
-v, --version Show version
|
|
160
|
+
`;
|
|
161
|
+
function resolvePackageJsonPath(projectRoot, packageName) {
|
|
162
|
+
const requireFromProject = (0, node_module.createRequire)((0, node_path.resolve)(projectRoot, "package.json"));
|
|
163
|
+
let packageEntryPath = "";
|
|
164
|
+
try {
|
|
165
|
+
packageEntryPath = requireFromProject.resolve(packageName);
|
|
166
|
+
} catch {
|
|
167
|
+
throw Error(`[faas lint] Missing dependency: ${packageName}. Please install ${packageName} in your project.`);
|
|
168
|
+
}
|
|
169
|
+
let currentPath = (0, node_path.dirname)(packageEntryPath);
|
|
170
|
+
let packageJsonPath = "";
|
|
171
|
+
while (true) {
|
|
172
|
+
const candidate = (0, node_path.join)(currentPath, "package.json");
|
|
173
|
+
if ((0, node_fs.existsSync)(candidate)) {
|
|
174
|
+
packageJsonPath = candidate;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
const parentPath = (0, node_path.dirname)(currentPath);
|
|
178
|
+
if (parentPath === currentPath) break;
|
|
179
|
+
currentPath = parentPath;
|
|
180
|
+
}
|
|
181
|
+
if (!packageJsonPath) throw Error(`[faas lint] Invalid dependency: Cannot find package.json for ${packageName}.`);
|
|
182
|
+
return packageJsonPath;
|
|
183
|
+
}
|
|
184
|
+
function resolveBinPath(projectRoot, packageName, binName) {
|
|
185
|
+
const packageJsonPath = resolvePackageJsonPath(projectRoot, packageName);
|
|
186
|
+
const packageJSON = JSON.parse((0, node_fs.readFileSync)(packageJsonPath, "utf8"));
|
|
187
|
+
const bin = typeof packageJSON.bin === "string" ? packageJSON.bin : packageJSON.bin?.[binName];
|
|
188
|
+
if (!bin) throw Error(`[faas lint] Invalid dependency: ${packageName} does not expose "${binName}" bin.`);
|
|
189
|
+
return (0, node_path.resolve)((0, node_path.dirname)(packageJsonPath), bin);
|
|
190
|
+
}
|
|
191
|
+
function resolveSharedConfigPath(projectRoot, configFileName) {
|
|
192
|
+
const configPath = (0, node_path.resolve)((0, node_path.dirname)(resolvePackageJsonPath(projectRoot, "@faasjs/dev")), "configs", configFileName);
|
|
193
|
+
if (!(0, node_fs.existsSync)(configPath)) throw Error(`[faas lint] Missing shared config: ${configPath}`);
|
|
194
|
+
return configPath;
|
|
195
|
+
}
|
|
196
|
+
function runNodeBin(projectRoot, command, binPath, args) {
|
|
197
|
+
try {
|
|
198
|
+
(0, node_child_process.execFileSync)(process.execPath, [binPath, ...args], {
|
|
199
|
+
cwd: projectRoot,
|
|
200
|
+
stdio: "inherit"
|
|
201
|
+
});
|
|
202
|
+
} catch {
|
|
203
|
+
throw Error(`[faas lint] ${command} failed`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async function run$2(args) {
|
|
207
|
+
const { mode, options, rest } = parseCommonCliArgs(args, "faas lint");
|
|
208
|
+
if (mode === "help") {
|
|
209
|
+
console.log(HelpText$2);
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
if (mode === "version") return printVersion();
|
|
213
|
+
if (rest.length) throw Error(`[faas lint] Unexpected argument: ${rest[0]}`);
|
|
214
|
+
const projectRoot = options.root ?? process.cwd();
|
|
215
|
+
const oxfmtBinPath = resolveBinPath(projectRoot, "oxfmt", "oxfmt");
|
|
216
|
+
const oxlintBinPath = resolveBinPath(projectRoot, "oxlint", "oxlint");
|
|
217
|
+
const oxfmtConfigPath = resolveSharedConfigPath(projectRoot, "oxfmt.base.json");
|
|
218
|
+
const oxlintConfigPath = resolveSharedConfigPath(projectRoot, "oxlint.base.json");
|
|
219
|
+
runNodeBin(projectRoot, "oxfmt", oxfmtBinPath, [
|
|
220
|
+
"-c",
|
|
221
|
+
oxfmtConfigPath,
|
|
222
|
+
"."
|
|
223
|
+
]);
|
|
224
|
+
runNodeBin(projectRoot, "oxlint", oxlintBinPath, [
|
|
225
|
+
"-c",
|
|
226
|
+
oxlintConfigPath,
|
|
227
|
+
"--fix",
|
|
228
|
+
"."
|
|
229
|
+
]);
|
|
230
|
+
console.log("[faas lint] Done");
|
|
231
|
+
return 0;
|
|
232
|
+
}
|
|
233
|
+
const main$2 = createMain(run$2);
|
|
234
|
+
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/cli/types.ts
|
|
237
|
+
const HelpText$1 = `Generate FaasJS API/event type declarations.
|
|
238
|
+
|
|
239
|
+
Usage:
|
|
240
|
+
faas types [options]
|
|
241
|
+
|
|
242
|
+
Options:
|
|
243
|
+
--root <path> Project root path (default: process.cwd())
|
|
244
|
+
-h, --help Show help
|
|
245
|
+
-v, --version Show version
|
|
246
|
+
`;
|
|
247
|
+
async function run$1(args) {
|
|
248
|
+
const { mode, options, rest } = parseCommonCliArgs(args, "faas types");
|
|
249
|
+
if (mode === "help") {
|
|
250
|
+
console.log(HelpText$1);
|
|
251
|
+
return 0;
|
|
252
|
+
}
|
|
253
|
+
if (mode === "version") return printVersion();
|
|
254
|
+
if (rest.length) throw Error(`[faas types] Unknown option: ${rest[0]}`);
|
|
255
|
+
const result = await require_typegen.generateFaasTypes(options);
|
|
256
|
+
console.log(`[faas types] ${result.changed ? "Generated" : "Up to date"} ${result.output} (${result.routeCount} routes from ${result.fileCount} files)`);
|
|
257
|
+
return 0;
|
|
258
|
+
}
|
|
259
|
+
const main$1 = createMain(run$1);
|
|
260
|
+
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/cli/index.ts
|
|
263
|
+
const HelpText = `FaasJS CLI.
|
|
264
|
+
|
|
265
|
+
Usage:
|
|
266
|
+
faas <command> [...args]
|
|
267
|
+
|
|
268
|
+
Commands:
|
|
269
|
+
types [options] Generate FaasJS API/event type declarations
|
|
270
|
+
knex <action> [name] [options] Run FaasJS knex migrations
|
|
271
|
+
lint [options] Run formatter and lint with Oxc
|
|
272
|
+
|
|
273
|
+
Options:
|
|
274
|
+
-h, --help Show help
|
|
275
|
+
-v, --version Show version
|
|
276
|
+
`;
|
|
277
|
+
const Commands = {
|
|
278
|
+
types: run$1,
|
|
279
|
+
knex: run$3,
|
|
280
|
+
lint: run$2
|
|
281
|
+
};
|
|
282
|
+
async function run(args) {
|
|
283
|
+
const command = args[0];
|
|
284
|
+
if (!command || command === "-h" || command === "--help") {
|
|
285
|
+
console.log(HelpText);
|
|
286
|
+
return 0;
|
|
287
|
+
}
|
|
288
|
+
if (command === "-v" || command === "--version") return printVersion();
|
|
289
|
+
const handler = Commands[command];
|
|
290
|
+
if (!handler) throw Error(`[faas] Unknown command: ${command}`);
|
|
291
|
+
return await handler(args.slice(1));
|
|
292
|
+
}
|
|
293
|
+
const main = createMain(run);
|
|
294
|
+
|
|
295
|
+
//#endregion
|
|
296
|
+
exports.main = main;
|
|
297
|
+
exports.run = run;
|