@jayfong/x-server 3.0.0 → 3.1.1
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/lib/cli/api_generator.d.mts +1 -0
- package/lib/cli/api_generator.mjs +27 -3
- package/lib/cli/build_util.d.mts +0 -2
- package/lib/cli/build_util.mjs +21 -76
- package/lib/cli/cli.mjs +11 -21
- package/lib/cli/deploy_util.mjs +1 -1
- package/lib/cli/dev_util.d.mts +4 -2
- package/lib/cli/dev_util.mjs +2 -2
- package/lib/cli/env_util.mjs +1 -1
- package/lib/cli/template_util.mjs +1 -1
- package/lib/cli/templates/routes.ts +1 -2
- package/lib/core/define_task.mjs +6 -2
- package/lib/core/handler.mjs +4 -4
- package/lib/services/ai.mjs +1 -1
- package/lib/services/file_store.mjs +1 -1
- package/lib/services/mail.d.mts +3 -3
- package/lib/services/mail.mjs +2 -2
- package/package.json +17 -22
- package/lib/cli/esbuild_register.d.mts +0 -1
- package/lib/cli/esbuild_register.mjs +0 -7
|
@@ -45,6 +45,7 @@ export declare class ApiGenerator {
|
|
|
45
45
|
debug: createDebug.Debugger;
|
|
46
46
|
categoryUrlRe: RegExp;
|
|
47
47
|
checker: ts.TypeChecker;
|
|
48
|
+
private resolveCategorySymbols;
|
|
48
49
|
start(): Promise<void>;
|
|
49
50
|
getComment(symbol?: ts.Symbol): Comment;
|
|
50
51
|
getApiDto({ type, keySymbol }: {
|
|
@@ -15,10 +15,34 @@ var ApiGenerator = class {
|
|
|
15
15
|
debug = createDebug("api");
|
|
16
16
|
categoryUrlRe = /^.+\/src\/handlers\/(?:index\.ts|(.*)\/index\.ts|(.*)\.ts)$/;
|
|
17
17
|
checker;
|
|
18
|
+
resolveCategorySymbols(program, checker, entrySourceFile, sourcePath) {
|
|
19
|
+
const moduleSymbol = checker.getSymbolAtLocation(entrySourceFile);
|
|
20
|
+
const directCategorySymbols = checker.getExportsOfModule(moduleSymbol).filter((categorySymbol) => {
|
|
21
|
+
return checker.getTypeOfSymbol(categorySymbol).getProperties().length > 0;
|
|
22
|
+
});
|
|
23
|
+
if (directCategorySymbols.length > 0) return directCategorySymbols;
|
|
24
|
+
const resolvedSymbols = [];
|
|
25
|
+
for (const statement of entrySourceFile.statements) {
|
|
26
|
+
if (!ts.isExportDeclaration(statement) || !statement.moduleSpecifier || !ts.isStringLiteral(statement.moduleSpecifier)) continue;
|
|
27
|
+
const targetPath = path.resolve(path.dirname(sourcePath), statement.moduleSpecifier.text);
|
|
28
|
+
const resolvedSourceFile = [
|
|
29
|
+
targetPath,
|
|
30
|
+
`${targetPath}.ts`,
|
|
31
|
+
`${targetPath}.tsx`,
|
|
32
|
+
`${targetPath}/index.ts`,
|
|
33
|
+
`${targetPath}/index.tsx`
|
|
34
|
+
].map((candidatePath) => program.getSourceFile(candidatePath)).find(Boolean);
|
|
35
|
+
if (!resolvedSourceFile) continue;
|
|
36
|
+
const resolvedSymbol = checker.getSymbolAtLocation(resolvedSourceFile);
|
|
37
|
+
if (!resolvedSymbol) continue;
|
|
38
|
+
if (checker.getTypeOfSymbol(resolvedSymbol).getProperties().length > 0) resolvedSymbols.push(resolvedSymbol);
|
|
39
|
+
}
|
|
40
|
+
return resolvedSymbols;
|
|
41
|
+
}
|
|
18
42
|
async start() {
|
|
19
43
|
this.debug("启动项目...");
|
|
20
44
|
const tsConfigPath = path.join(this.cwd, "tsconfig.json");
|
|
21
|
-
const handlersPath = path.join(this.cwd, "node_modules
|
|
45
|
+
const handlersPath = path.join(this.cwd, "node_modules/@a/x/handlers.ts");
|
|
22
46
|
const entryFile = path.join(this.cwd, "src/generated/handlers.ts");
|
|
23
47
|
const moProject = new mo.Project({ tsConfigFilePath: tsConfigPath });
|
|
24
48
|
moProject.createSourceFile(entryFile, await fs.readFile(handlersPath, "utf-8"));
|
|
@@ -26,11 +50,11 @@ var ApiGenerator = class {
|
|
|
26
50
|
const checker = program.getTypeChecker();
|
|
27
51
|
this.checker = checker;
|
|
28
52
|
const entrySourceFile = program.getSourceFile(entryFile);
|
|
29
|
-
const
|
|
30
|
-
const categorySymbols = checker.getExportsOfModule(moduleSymbol);
|
|
53
|
+
const categorySymbols = this.resolveCategorySymbols(program, checker, entrySourceFile, handlersPath);
|
|
31
54
|
const apiData = [];
|
|
32
55
|
for (const categorySymbol of categorySymbols) {
|
|
33
56
|
const handlerSymbols = checker.getTypeOfSymbol(categorySymbol).getProperties();
|
|
57
|
+
if (!handlerSymbols.length) continue;
|
|
34
58
|
const categorySourceFilePath = handlerSymbols[0].getDeclarations()[0].getSourceFile().fileName;
|
|
35
59
|
if (/@dev[/.]/.test(categorySourceFilePath)) continue;
|
|
36
60
|
if (this.options.include?.length) {
|
package/lib/cli/build_util.d.mts
CHANGED
package/lib/cli/build_util.mjs
CHANGED
|
@@ -1,49 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dedent, uniq } from "vtils";
|
|
1
|
+
import { dedent, omitStrict } from "vtils";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import fs from "fs-extra";
|
|
5
4
|
import compressing from "compressing";
|
|
6
5
|
import * as esbuild from "esbuild";
|
|
7
|
-
import
|
|
6
|
+
import macrosPlugin from "unplugin-macros/esbuild";
|
|
8
7
|
// src/cli/build_util.ts
|
|
9
8
|
var BuildUtil = class {
|
|
10
9
|
static async build(options) {
|
|
11
10
|
const mainFile = path.join(options.cwd, "src/main.ts");
|
|
12
11
|
const pkgFile = path.join(options.cwd, "package.json");
|
|
13
12
|
const pkgContent = await fs.readJson(pkgFile);
|
|
13
|
+
pkgContent.name = options.appId;
|
|
14
14
|
const distDir = path.join(options.cwd, options.channel ? `dist/${options.channel}` : "dist");
|
|
15
15
|
const tempDir = path.join(options.cwd, options.channel ? `temp/${options.channel}` : "temp");
|
|
16
16
|
const distMainFile = path.join(distDir, "main.js");
|
|
17
17
|
const distPkgFile = path.join(distDir, "package.json");
|
|
18
18
|
const distNvmrcFile = path.join(distDir, ".nvmrc");
|
|
19
|
+
const distNpmrcFile = path.join(distDir, ".npmrc");
|
|
20
|
+
const distPnpmWorkspaceFile = path.join(distDir, "pnpm-workspace.yaml");
|
|
21
|
+
const distPnpmLockFile = path.join(distDir, "pnpm-lock.yaml");
|
|
19
22
|
const distPm2File = path.join(distDir, "pm2.config.js");
|
|
20
|
-
const distNoInstallFile = path.join(distDir, "no_install.lock");
|
|
21
23
|
const distBundleFile = path.join(tempDir, `app.${pkgContent.version}.tgz`);
|
|
22
24
|
await fs.ensureDir(distDir);
|
|
23
25
|
await fs.ensureDir(tempDir);
|
|
24
|
-
const external = uniq([...options.external || [], "bull"]);
|
|
25
|
-
const externalWithVersions = (await Promise.all(external.map(async (item) => {
|
|
26
|
-
try {
|
|
27
|
-
const itemPkgFile = path.join(process.cwd(), `node_modules/${item}/package.json`);
|
|
28
|
-
return {
|
|
29
|
-
name: item,
|
|
30
|
-
version: (await fs.readJson(itemPkgFile)).version
|
|
31
|
-
};
|
|
32
|
-
} catch {
|
|
33
|
-
return {
|
|
34
|
-
name: item,
|
|
35
|
-
version: ""
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}))).filter((item) => !!item.version);
|
|
39
|
-
try {
|
|
40
|
-
const hexoidPackageJsonFile = __require.resolve("hexoid/package.json");
|
|
41
|
-
const pkg = await fs.readJson(hexoidPackageJsonFile);
|
|
42
|
-
delete pkg.module;
|
|
43
|
-
await fs.writeJson(hexoidPackageJsonFile, pkg);
|
|
44
|
-
} catch {}
|
|
45
26
|
if (!options.noEmptyDistDir) await fs.emptyDir(distDir);
|
|
46
|
-
const { default: macrosPlugin } = await import("unplugin-macros/esbuild");
|
|
47
27
|
await esbuild.build({
|
|
48
28
|
entryPoints: [mainFile],
|
|
49
29
|
bundle: true,
|
|
@@ -51,36 +31,14 @@ var BuildUtil = class {
|
|
|
51
31
|
platform: "node",
|
|
52
32
|
mainFields: ["module", "main"],
|
|
53
33
|
target: `node${process.version.slice(1)}`,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
format: "cjs",
|
|
34
|
+
minify: options.minify ?? false,
|
|
35
|
+
format: "esm",
|
|
57
36
|
sourcemap: false,
|
|
58
37
|
treeShaking: true,
|
|
59
38
|
banner: { js: [...Object.keys(options.inlineEnvs || {}).map((key) => `process.env[${JSON.stringify(key)}]=${JSON.stringify(options.inlineEnvs[key])};`), `process.env["X_SERVER_ENVS"]=${JSON.stringify(JSON.stringify(options.inlineEnvs || {}))};`].join("\n") },
|
|
60
39
|
plugins: [{
|
|
61
|
-
name: "
|
|
40
|
+
name: "custom",
|
|
62
41
|
async setup(build) {
|
|
63
|
-
build.onLoad({ filter: /\/svg-captcha\/lib\/option-manager\.js$/ }, async (args) => {
|
|
64
|
-
let js = await fs.readFile(args.path, "utf-8");
|
|
65
|
-
js = js.replace("../fonts/Comismsh.ttf", "./assets/svg-captcha/fonts/Comismsh.ttf");
|
|
66
|
-
await fs.copy(path.dirname(__require.resolve("svg-captcha/fonts/LICENSE.md")), path.join(distDir, "assets/svg-captcha/fonts"));
|
|
67
|
-
return {
|
|
68
|
-
contents: js,
|
|
69
|
-
loader: "js"
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
build.onLoad({ filter: /\/vm2\/lib\/vm\.js$/ }, async (args) => {
|
|
73
|
-
let js = await fs.readFile(args.path, "utf-8");
|
|
74
|
-
const jsDir = path.dirname(args.path);
|
|
75
|
-
const assetsDir = path.join(distDir, "assets/vm2");
|
|
76
|
-
await fs.ensureDir(assetsDir);
|
|
77
|
-
js = js.replace(/__dirname/g, "\"./assets/vm2\"");
|
|
78
|
-
await Promise.all([fs.copyFile(path.join(jsDir, "bridge.js"), path.join(assetsDir, "bridge.js")), fs.copyFile(path.join(jsDir, "setup-sandbox.js"), path.join(assetsDir, "setup-sandbox.js"))]);
|
|
79
|
-
return {
|
|
80
|
-
contents: js,
|
|
81
|
-
loader: "js"
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
42
|
build.onLoad({ filter: /@dev[/.]/ }, async () => {
|
|
85
43
|
return {
|
|
86
44
|
contents: "module.exports = {}",
|
|
@@ -110,46 +68,33 @@ var BuildUtil = class {
|
|
|
110
68
|
await fs.copy(multipleSchemaDir, distMultipleSchemaDir);
|
|
111
69
|
}
|
|
112
70
|
}
|
|
113
|
-
|
|
114
|
-
res[item.name] = item.version;
|
|
115
|
-
return res;
|
|
116
|
-
}, {});
|
|
117
|
-
const distPkgContent = {
|
|
118
|
-
name: options.appId,
|
|
119
|
-
version: pkgContent.version,
|
|
120
|
-
dependencies: deps
|
|
121
|
-
};
|
|
122
|
-
await fs.writeJSON(distPkgFile, distPkgContent);
|
|
71
|
+
await fs.writeJson(distPkgFile, omitStrict(pkgContent, ["devDependencies", "scripts"]), { spaces: 2 });
|
|
123
72
|
const nvmrcFile = path.join(options.cwd, ".nvmrc");
|
|
124
73
|
const hasNvmrc = await fs.pathExists(nvmrcFile);
|
|
125
|
-
|
|
74
|
+
await fs.writeFile(distNvmrcFile, hasNvmrc ? await fs.readFile(nvmrcFile) : process.version.slice(1).split(".")[0]);
|
|
75
|
+
const npmrcFile = path.join(options.cwd, ".npmrc");
|
|
76
|
+
if (await fs.pathExists(npmrcFile)) await fs.copyFile(npmrcFile, distNpmrcFile);
|
|
77
|
+
const pnpmWorkspaceFile = path.join(options.cwd, "pnpm-workspace.yaml");
|
|
78
|
+
if (await fs.pathExists(pnpmWorkspaceFile)) await fs.copyFile(pnpmWorkspaceFile, distPnpmWorkspaceFile);
|
|
79
|
+
const pnpmLockFile = path.join(options.cwd, "pnpm-lock.yaml");
|
|
80
|
+
if (await fs.pathExists(pnpmLockFile)) await fs.copyFile(pnpmLockFile, distPnpmLockFile);
|
|
126
81
|
await fs.writeFile(distPm2File, dedent`
|
|
127
82
|
module.exports = {
|
|
128
83
|
apps: [
|
|
129
84
|
{
|
|
130
|
-
name: ${JSON.stringify(
|
|
85
|
+
name: ${JSON.stringify(pkgContent.name)},
|
|
131
86
|
script: './main.js',
|
|
132
87
|
interpreter: 'node',
|
|
133
88
|
interpreter_args: ${JSON.stringify(options.pm2NodeArgs || [])},
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
},
|
|
138
|
-
` : ""}
|
|
89
|
+
env: {
|
|
90
|
+
PATH: \`\${require('child_process').execSync('fnm exec which node').toString().trim().replace(/\\/node$/, '')}:\${process.env.PATH}\`,
|
|
91
|
+
},
|
|
139
92
|
${options.pm2MaxMemoryRestart ? `max_memory_restart: '${options.pm2MaxMemoryRestart}',` : ""}
|
|
140
93
|
${options.pm2CronRestart ? `cron_restart: '${options.pm2CronRestart}',` : ""}
|
|
141
94
|
},
|
|
142
95
|
],
|
|
143
96
|
}
|
|
144
97
|
`);
|
|
145
|
-
if (externalWithVersions.length) {
|
|
146
|
-
if (options.noInstall) await fs.writeFile(distNoInstallFile, "");
|
|
147
|
-
else await exec("tyn", {
|
|
148
|
-
cwd: distDir,
|
|
149
|
-
stdio: "inherit",
|
|
150
|
-
env: { yarn_disable_self_update_check: "true" }
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
98
|
await compressing.tgz.compressDir(distDir, distBundleFile);
|
|
154
99
|
}
|
|
155
100
|
};
|
package/lib/cli/cli.mjs
CHANGED
|
@@ -9,8 +9,8 @@ import * as vtils from "vtils";
|
|
|
9
9
|
import { StringTemplate, castArray, debounce } from "vtils";
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
import fs from "fs-extra";
|
|
12
|
-
import
|
|
13
|
-
import
|
|
12
|
+
import { watch } from "chokidar";
|
|
13
|
+
import { execa } from "execa";
|
|
14
14
|
import { generateManyIndex } from "vscode-generate-index-standalone";
|
|
15
15
|
import yargs from "yargs";
|
|
16
16
|
import { hideBin } from "yargs/helpers";
|
|
@@ -76,11 +76,12 @@ yargs(hideBin(process.argv)).command("dev", "开始开发", (_) => _.positional(
|
|
|
76
76
|
file: "src/main.ts",
|
|
77
77
|
cwd: process.cwd()
|
|
78
78
|
});
|
|
79
|
+
lastRun.catch(vtils.noop);
|
|
79
80
|
};
|
|
80
81
|
await TemplateUtil.init(process.cwd());
|
|
81
82
|
const xsignoreFile = path.join(process.cwd(), ".xsignore");
|
|
82
83
|
const xsignoreContent = await fs.pathExists(xsignoreFile) ? (await fs.readFile(xsignoreFile, "utf-8")).trim().split(/[\r\n]+/g).filter((v) => v && !v.startsWith("#")) : [];
|
|
83
|
-
|
|
84
|
+
watch([
|
|
84
85
|
"src",
|
|
85
86
|
".env",
|
|
86
87
|
".env*"
|
|
@@ -104,7 +105,7 @@ yargs(hideBin(process.argv)).command("dev", "开始开发", (_) => _.positional(
|
|
|
104
105
|
cwd: process.cwd(),
|
|
105
106
|
patterns: [
|
|
106
107
|
"src/**/index.ts",
|
|
107
|
-
"node_modules
|
|
108
|
+
"node_modules/@a/x/*.ts",
|
|
108
109
|
"!src/handlers/**/*",
|
|
109
110
|
...argv.index || []
|
|
110
111
|
],
|
|
@@ -124,20 +125,11 @@ yargs(hideBin(process.argv)).command("dev", "开始开发", (_) => _.positional(
|
|
|
124
125
|
}, 30));
|
|
125
126
|
}
|
|
126
127
|
});
|
|
127
|
-
}).command("build", "构建", (_) => _.positional("
|
|
128
|
-
alias: "e",
|
|
129
|
-
describe: "不应该被打的包",
|
|
130
|
-
type: "string",
|
|
131
|
-
array: true
|
|
132
|
-
}).positional("minify", {
|
|
128
|
+
}).command("build", "构建", (_) => _.positional("minify", {
|
|
133
129
|
alias: "m",
|
|
134
130
|
describe: "是否压缩",
|
|
135
131
|
type: "boolean",
|
|
136
|
-
default:
|
|
137
|
-
}).positional("local-install", {
|
|
138
|
-
describe: "是否本地安装外部依赖",
|
|
139
|
-
type: "boolean",
|
|
140
|
-
default: true
|
|
132
|
+
default: false
|
|
141
133
|
}).positional("channel", {
|
|
142
134
|
alias: "h",
|
|
143
135
|
describe: "渠道",
|
|
@@ -168,7 +160,6 @@ yargs(hideBin(process.argv)).command("dev", "开始开发", (_) => _.positional(
|
|
|
168
160
|
concurrency: argv.concurrency,
|
|
169
161
|
cb: async (channel) => {
|
|
170
162
|
process.env.NODE_ENV = "production";
|
|
171
|
-
const externals = castArray(argv.external || []).flatMap((item) => item.split(",")).filter(Boolean);
|
|
172
163
|
const envFiles = EnvUtil.getFile(process.env.NODE_ENV, channel);
|
|
173
164
|
const envMap = await EnvUtil.parseFileAsMap({
|
|
174
165
|
cwd: process.cwd(),
|
|
@@ -185,7 +176,7 @@ yargs(hideBin(process.argv)).command("dev", "开始开发", (_) => _.positional(
|
|
|
185
176
|
await TemplateUtil.init(process.cwd());
|
|
186
177
|
await generateManyIndex({
|
|
187
178
|
cwd: process.cwd(),
|
|
188
|
-
patterns: ["src
|
|
179
|
+
patterns: ["src/@a/x/*.ts"],
|
|
189
180
|
replaceFile: true,
|
|
190
181
|
onSuccess: (filePath) => {
|
|
191
182
|
console.log(`✔️ 索引文件已更新: ${filePath}`);
|
|
@@ -194,10 +185,8 @@ yargs(hideBin(process.argv)).command("dev", "开始开发", (_) => _.positional(
|
|
|
194
185
|
await BuildUtil.build({
|
|
195
186
|
appId: envMap.APP_ID,
|
|
196
187
|
cwd: process.cwd(),
|
|
197
|
-
external: externals,
|
|
198
188
|
inlineEnvs: envMap,
|
|
199
189
|
minify: argv.minify,
|
|
200
|
-
noInstall: argv["local-install"] === false,
|
|
201
190
|
channel,
|
|
202
191
|
excludeFiles: (argv.exclude ? castArray(argv.exclude) : []).map((item) => {
|
|
203
192
|
return StringTemplate.render(item, {
|
|
@@ -284,7 +273,8 @@ yargs(hideBin(process.argv)).command("dev", "开始开发", (_) => _.positional(
|
|
|
284
273
|
const schemaDir = path.join(process.cwd(), "src/db/schema");
|
|
285
274
|
const schemaArg = await fs.pathExists(schemaDir) ? "src/db" : "src/db/schema.prisma";
|
|
286
275
|
const prismaArgs = argv._.slice(1);
|
|
287
|
-
await
|
|
276
|
+
await execa("pnpm", [
|
|
277
|
+
"exec",
|
|
288
278
|
"prisma",
|
|
289
279
|
...prismaArgs,
|
|
290
280
|
"--schema",
|
|
@@ -321,7 +311,7 @@ yargs(hideBin(process.argv)).command("dev", "开始开发", (_) => _.positional(
|
|
|
321
311
|
channel
|
|
322
312
|
});
|
|
323
313
|
process.env.DATABASE_URL = process.env.DATABASE_ACTION_URL || process.env.DATABASE_URL;
|
|
324
|
-
if (!argv.script) await
|
|
314
|
+
if (!argv.script) await execa("pnpm", ["exec", "select-run"], {
|
|
325
315
|
cwd: process.cwd(),
|
|
326
316
|
stdio: "inherit"
|
|
327
317
|
});
|
package/lib/cli/deploy_util.mjs
CHANGED
|
@@ -32,7 +32,7 @@ var DeployUtil = class {
|
|
|
32
32
|
set -ex
|
|
33
33
|
tar -zxf ${remoteAppFile} -C ${appDir}
|
|
34
34
|
cd "${appDir}/${options.channel || "dist"}"
|
|
35
|
-
|
|
35
|
+
pnpm install
|
|
36
36
|
${options.cmd || ""}
|
|
37
37
|
pm2 startOrReload pm2.config.js
|
|
38
38
|
`, {
|
package/lib/cli/dev_util.d.mts
CHANGED
package/lib/cli/dev_util.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __require } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
-
import
|
|
2
|
+
import { execa } from "execa";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
// src/cli/dev_util.ts
|
|
@@ -11,7 +11,7 @@ var DevUtil = class {
|
|
|
11
11
|
const tsxCjsFile = tsxPkgFile.replace("/package.json", "/dist/cli.cjs");
|
|
12
12
|
const tsxMjsFile = tsxPkgFile.replace("/package.json", "/dist/cli.mjs");
|
|
13
13
|
const tsxFile = fs.existsSync(tsxMjsFile) ? tsxMjsFile : fs.existsSync(tsxCjsFile) ? tsxCjsFile : tsxJsFile;
|
|
14
|
-
return
|
|
14
|
+
return execa("node", [
|
|
15
15
|
"-r",
|
|
16
16
|
cssRegisterFile,
|
|
17
17
|
tsxFile,
|
package/lib/cli/env_util.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { asyncLimit, castArray, dedent, difference, escapeRegExp, get, isPlainObject, uniq } from "vtils";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import fs from "fs-extra";
|
|
4
|
-
import globby from "globby";
|
|
4
|
+
import { globby } from "globby";
|
|
5
5
|
import { pinyin } from "pinyin-pro";
|
|
6
6
|
import { parse } from "yaml";
|
|
7
7
|
// src/cli/env_util.ts
|
|
@@ -2,7 +2,7 @@ import { camelCase, dedent, snakeCase, upperFirst } from "vtils";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import fs from "fs-extra";
|
|
4
4
|
import { generateManyIndex } from "vscode-generate-index-standalone";
|
|
5
|
-
import globby from "globby";
|
|
5
|
+
import { globby } from "globby";
|
|
6
6
|
// src/cli/template_util.ts
|
|
7
7
|
var TemplateUtil = class {
|
|
8
8
|
/**
|
|
@@ -52,10 +52,9 @@ export const routes: XServer.Route[] = basePathWithHandlers.reduce<
|
|
|
52
52
|
XServer.Route[]
|
|
53
53
|
>((res, item) => {
|
|
54
54
|
const validHandlerNames = Object.keys(item[1]).filter(
|
|
55
|
-
name => !name.startsWith('_') && name !== 'default',
|
|
55
|
+
name => !name.startsWith('_') && name !== 'default' && name !== 'module.exports',
|
|
56
56
|
);
|
|
57
57
|
for (const handlerName of validHandlerNames) {
|
|
58
|
-
if (handlerName === 'module.exports') continue;
|
|
59
58
|
const path = item[1][handlerName].options.requestPath || handlerName;
|
|
60
59
|
const paths = Array.isArray(path) ? path : [path];
|
|
61
60
|
for (const path of paths) {
|
package/lib/core/define_task.mjs
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { x } from "../x.mjs";
|
|
2
|
-
import { ms } from "vtils";
|
|
2
|
+
import { ms, omitStrict } from "vtils";
|
|
3
3
|
import assert from "node:assert";
|
|
4
4
|
import Queue$1 from "bull";
|
|
5
5
|
// src/core/define_task.ts
|
|
6
6
|
function defineTask(options) {
|
|
7
7
|
const queue = new Queue$1(options.name, {
|
|
8
8
|
redis: {
|
|
9
|
-
...x.redis.options,
|
|
9
|
+
...omitStrict(x.redis.options, [
|
|
10
|
+
"Connector",
|
|
11
|
+
"retryStrategy",
|
|
12
|
+
"natMap"
|
|
13
|
+
]),
|
|
10
14
|
maxRetriesPerRequest: null,
|
|
11
15
|
enableReadyCheck: false
|
|
12
16
|
},
|
package/lib/core/handler.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { DisposeService } from "../services/dispose.mjs";
|
|
|
3
3
|
import { ctxStorage } from "./ctx_storage.mjs";
|
|
4
4
|
import { HttpRedirect } from "./http_redirect.mjs";
|
|
5
5
|
import { Server } from "./server.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { xr } from "@jayfong/x-request";
|
|
7
7
|
import LZString from "lz-string";
|
|
8
8
|
import { DataPacker, asyncLimit, base64UrlEncode, rot13, toSingleLineString } from "vtils";
|
|
9
9
|
import * as vae from "vtils/vae";
|
|
@@ -62,13 +62,13 @@ var Handler = class Handler {
|
|
|
62
62
|
return res == null ? {} : res;
|
|
63
63
|
} catch (err) {
|
|
64
64
|
if (HttpError.isHttpError(err)) throw err;
|
|
65
|
-
if (err
|
|
65
|
+
if (xr.isRequestError(err)) console.error("网络请求错误", {
|
|
66
66
|
error: `${err.code || ""}__${err.name || ""}__${err.message || ""}`,
|
|
67
67
|
response: err.response?.body && err.options.responseType !== "buffer" ? toSingleLineString(String(err.response.body), 100) : "",
|
|
68
68
|
method: err.options.method,
|
|
69
|
-
url: err.options.url
|
|
69
|
+
url: err.options.url?.toString() || "",
|
|
70
70
|
headers: JSON.stringify(err.options.headers || {}),
|
|
71
|
-
query:
|
|
71
|
+
query: err.options.searchParams?.toString() || "",
|
|
72
72
|
body: (err.options.json ? JSON.stringify(err.options.json) : err.options.form ? new URLSearchParams(err.options.form).toString() : err.options.body?.toString()) || ""
|
|
73
73
|
});
|
|
74
74
|
else console.error("服务器错误", err);
|
package/lib/services/ai.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { x } from "../x.mjs";
|
|
2
|
-
import { isUrl, ms } from "vtils";
|
|
3
2
|
import { xr } from "@jayfong/x-request";
|
|
3
|
+
import { isUrl, ms } from "vtils";
|
|
4
4
|
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
5
5
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
6
6
|
import mime from "mime";
|
package/lib/services/mail.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseService } from "./base.mjs";
|
|
2
|
-
import
|
|
2
|
+
import { SendMailOptions } from "nodemailer";
|
|
3
3
|
export interface MailServiceOptions {
|
|
4
4
|
host: string;
|
|
5
5
|
port: number;
|
|
@@ -7,13 +7,13 @@ export interface MailServiceOptions {
|
|
|
7
7
|
user: string;
|
|
8
8
|
pass: string;
|
|
9
9
|
}
|
|
10
|
-
export interface MailServiceSendOptions extends
|
|
10
|
+
export interface MailServiceSendOptions extends SendMailOptions {}
|
|
11
11
|
export declare class MailService implements BaseService {
|
|
12
12
|
private options;
|
|
13
13
|
serviceName: string;
|
|
14
14
|
private transporter;
|
|
15
15
|
constructor(options: MailServiceOptions);
|
|
16
|
-
send(options: MailServiceSendOptions): Promise<
|
|
16
|
+
send(options: MailServiceSendOptions): Promise<import("nodemailer").SentMessageInfo>;
|
|
17
17
|
}
|
|
18
18
|
declare module '../x.mjs' {
|
|
19
19
|
interface X {
|
package/lib/services/mail.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { x } from "../x.mjs";
|
|
2
|
-
import
|
|
2
|
+
import { createTransport } from "nodemailer";
|
|
3
3
|
// src/services/mail.ts
|
|
4
4
|
var MailService = class {
|
|
5
5
|
options;
|
|
@@ -10,7 +10,7 @@ var MailService = class {
|
|
|
10
10
|
}
|
|
11
11
|
async send(options) {
|
|
12
12
|
if (!this.transporter) {
|
|
13
|
-
this.transporter =
|
|
13
|
+
this.transporter = createTransport({
|
|
14
14
|
host: this.options.host,
|
|
15
15
|
port: this.options.port,
|
|
16
16
|
secure: this.options.secure,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-server",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"sideEffects": true,
|
|
6
6
|
"type": "module",
|
|
@@ -19,45 +19,44 @@
|
|
|
19
19
|
"@fastify/formbody": "^9.0.1",
|
|
20
20
|
"@fastify/multipart": "^10.1.8",
|
|
21
21
|
"@fastify/websocket": "^11.3.7",
|
|
22
|
-
"@jayfong/x-request": "^3.
|
|
22
|
+
"@jayfong/x-request": "^3.1.1",
|
|
23
23
|
"@paralleldrive/cuid2": "^3.3.0",
|
|
24
24
|
"@prisma/adapter-mariadb": "^7.10.1",
|
|
25
25
|
"@prisma/client": "^7.10.1",
|
|
26
26
|
"@types/busboy": "^0.3.2",
|
|
27
27
|
"@types/http-errors": "^2.0.5",
|
|
28
|
+
"@types/json-schema": "^7.0.11",
|
|
28
29
|
"@types/jsonwebtoken": "^8.5.8",
|
|
29
30
|
"@types/nodemailer": "^6.4.4",
|
|
30
31
|
"@types/ws": "^8.18.2",
|
|
31
32
|
"alipay-sdk": "^4.14.0",
|
|
32
|
-
"bufferutil": "^4.0.6",
|
|
33
33
|
"bull": "^4.16.5",
|
|
34
|
-
"chokidar": "^
|
|
34
|
+
"chokidar": "^6.0.0",
|
|
35
35
|
"comment-parser": "^1.3.1",
|
|
36
36
|
"compressing": "^1.5.1",
|
|
37
37
|
"cron": "^4.4.0",
|
|
38
38
|
"cuid": "^2.1.8",
|
|
39
39
|
"debug": "^4.3.4",
|
|
40
40
|
"esbuild": "^0.28.2",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"exit-hook": "^2.2.1",
|
|
41
|
+
"execa": "^10.2.1",
|
|
42
|
+
"exit-hook": "^5.1.0",
|
|
44
43
|
"fast-escape-html": "^1.1.0",
|
|
45
44
|
"fast-xml-parser": "^5.12.0",
|
|
46
45
|
"fastify": "^5.12.8",
|
|
47
|
-
"fs-extra": "^
|
|
48
|
-
"globby": "^
|
|
49
|
-
"got": "^11.8.2",
|
|
46
|
+
"fs-extra": "^11.4.1",
|
|
47
|
+
"globby": "^16.2.4",
|
|
50
48
|
"http-errors": "^2.0.1",
|
|
51
|
-
"inquirer": "^
|
|
49
|
+
"inquirer": "^14.3.0",
|
|
52
50
|
"inquirer-autocomplete-standalone": "^0.8.1",
|
|
53
|
-
"ioredis": "^
|
|
54
|
-
"jsonwebtoken": "^
|
|
55
|
-
"lru-cache": "^
|
|
51
|
+
"ioredis": "^6.0.0",
|
|
52
|
+
"jsonwebtoken": "^9.0.3",
|
|
53
|
+
"lru-cache": "^11.5.3",
|
|
56
54
|
"lz-string": "^1.4.4",
|
|
57
55
|
"mime": "^4.1.2",
|
|
58
56
|
"mini-svg-data-uri": "^1.4.4",
|
|
59
|
-
"node-ssh": "^13.1
|
|
60
|
-
"nodemailer": "^
|
|
57
|
+
"node-ssh": "^13.2.1",
|
|
58
|
+
"nodemailer": "^10.5.0",
|
|
59
|
+
"openapi-types": "^12.1.3",
|
|
61
60
|
"pino-pretty": "^13.2.0",
|
|
62
61
|
"pinyin-pro": "^3.26.0",
|
|
63
62
|
"pirates": "^4.0.6",
|
|
@@ -68,16 +67,13 @@
|
|
|
68
67
|
"supports-color": "^8",
|
|
69
68
|
"svg-captcha": "^1.4.0",
|
|
70
69
|
"tencentcloud-sdk-nodejs-sms": "^4.0.681",
|
|
71
|
-
"ts-morph": "^
|
|
70
|
+
"ts-morph": "^28.0.0",
|
|
72
71
|
"tsx": "^4.23.15",
|
|
73
72
|
"unplugin-macros": "^0.16.0",
|
|
74
|
-
"utf-8-validate": "^5.0.9",
|
|
75
73
|
"vscode-generate-index-standalone": "^1.7.1",
|
|
76
74
|
"vtils": "^4.138.0",
|
|
77
75
|
"yaml": "^2.9.1",
|
|
78
|
-
"yargs": "^18.2.0"
|
|
79
|
-
"@types/json-schema": "^7.0.11",
|
|
80
|
-
"openapi-types": "^12.1.3"
|
|
76
|
+
"yargs": "^18.2.0"
|
|
81
77
|
},
|
|
82
78
|
"devDependencies": {
|
|
83
79
|
"@types/debug": "^4.1.7",
|
|
@@ -103,7 +99,6 @@
|
|
|
103
99
|
"./cli/deploy_util": "./lib/cli/deploy_util.mjs",
|
|
104
100
|
"./cli/dev_util": "./lib/cli/dev_util.mjs",
|
|
105
101
|
"./cli/env_util": "./lib/cli/env_util.mjs",
|
|
106
|
-
"./cli/esbuild_register": "./lib/cli/esbuild_register.mjs",
|
|
107
102
|
"./cli/template_util": "./lib/cli/template_util.mjs",
|
|
108
103
|
"./core/ctx_storage": "./lib/core/ctx_storage.mjs",
|
|
109
104
|
"./core/define_bus": "./lib/core/define_bus.mjs",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|