@jayfong/x-server 1.10.2 → 1.11.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/CHANGELOG.md +21 -0
- package/lib/_cjs/cli/api_generator.js +295 -0
- package/lib/_cjs/cli/build_util.js +146 -0
- package/lib/_cjs/cli/cli.js +190 -0
- package/lib/_cjs/cli/deploy_util.js +61 -0
- package/lib/_cjs/cli/env_util.js +145 -0
- package/lib/_cjs/cli/register.js +8 -0
- package/lib/_cjs/cli/template_util.js +77 -0
- package/lib/_cjs/cli/templates/handlers.ts +3 -0
- package/lib/_cjs/cli/templates/hooks.ts +2 -0
- package/lib/_cjs/cli/templates/models.ts +22 -0
- package/lib/_cjs/cli/templates/package.json +3 -0
- package/lib/_cjs/cli/templates/routes.ts +26 -0
- package/lib/_cjs/cli/templates/tasks.ts +2 -0
- package/lib/_cjs/core/define_bus.js +28 -0
- package/lib/_cjs/core/define_handler.js +43 -0
- package/lib/_cjs/core/define_hook.js +10 -0
- package/lib/_cjs/core/define_server.js +12 -0
- package/lib/_cjs/core/define_task.js +30 -0
- package/lib/_cjs/core/handler.js +90 -0
- package/lib/_cjs/core/http_error.js +9 -0
- package/lib/_cjs/core/http_method.js +12 -0
- package/lib/_cjs/core/server.js +145 -0
- package/lib/_cjs/core/types.js +18 -0
- package/lib/_cjs/index.js +179 -0
- package/lib/_cjs/plugins/base.js +3 -0
- package/lib/_cjs/plugins/cors.js +44 -0
- package/lib/_cjs/plugins/file_parser.js +24 -0
- package/lib/_cjs/plugins/ws_parser.js +24 -0
- package/lib/_cjs/plugins/xml_parser.js +61 -0
- package/lib/_cjs/services/base.js +3 -0
- package/lib/_cjs/services/cache.js +231 -0
- package/lib/_cjs/services/captcha.js +45 -0
- package/lib/_cjs/services/dispose.js +33 -0
- package/lib/_cjs/services/jwt.js +59 -0
- package/lib/_cjs/services/redis.js +18 -0
- package/lib/_cjs/x.js +20 -0
- package/lib/cli/api_generator.js +269 -332
- package/lib/cli/build_util.d.ts +1 -0
- package/lib/cli/build_util.js +108 -130
- package/lib/cli/cli.js +161 -208
- package/lib/cli/deploy_util.js +37 -41
- package/lib/cli/env_util.js +112 -120
- package/lib/cli/register.js +5 -7
- package/lib/cli/template_util.js +50 -49
- package/lib/core/define_bus.js +22 -14
- package/lib/core/define_handler.js +31 -36
- package/lib/core/define_hook.js +4 -8
- package/lib/core/define_server.js +6 -10
- package/lib/core/define_task.js +20 -25
- package/lib/core/handler.js +78 -74
- package/lib/core/http_error.js +2 -8
- package/lib/core/http_method.js +7 -10
- package/lib/core/server.js +125 -139
- package/lib/core/types.js +11 -2
- package/lib/index.js +23 -39
- package/lib/plugins/base.js +1 -2
- package/lib/plugins/cors.js +30 -36
- package/lib/plugins/file_parser.d.ts +1 -1
- package/lib/plugins/file_parser.js +12 -16
- package/lib/plugins/ws_parser.d.ts +1 -1
- package/lib/plugins/ws_parser.js +12 -16
- package/lib/plugins/xml_parser.d.ts +1 -1
- package/lib/plugins/xml_parser.js +47 -43
- package/lib/services/base.js +1 -2
- package/lib/services/cache.js +213 -190
- package/lib/services/captcha.js +32 -33
- package/lib/services/dispose.d.ts +1 -1
- package/lib/services/dispose.js +22 -23
- package/lib/services/jwt.js +45 -48
- package/lib/services/redis.js +8 -14
- package/lib/x.js +12 -15
- package/package.json +5 -3
package/lib/cli/deploy_util.js
CHANGED
|
@@ -1,51 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
const appName = pkgContent.name;
|
|
25
|
-
const appDir = `./${appName}`;
|
|
26
|
-
await ssh.execCommand((0, vtils_1.dedent) `
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { dedent } from 'vtils';
|
|
4
|
+
import { NodeSSH } from 'node-ssh';
|
|
5
|
+
export class DeployUtil {
|
|
6
|
+
static async deploy(options) {
|
|
7
|
+
const pkgContent = await fs.readJson(path.join(options.cwd, 'package.json'));
|
|
8
|
+
const appFile = path.join(options.cwd, `temp/app.${pkgContent.version}.tgz`);
|
|
9
|
+
|
|
10
|
+
if (!(await fs.pathExists(appFile))) {
|
|
11
|
+
throw new Error('请先构建');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ssh = new NodeSSH();
|
|
15
|
+
await ssh.connect({
|
|
16
|
+
host: options.host,
|
|
17
|
+
username: options.user,
|
|
18
|
+
privateKey: options.key
|
|
19
|
+
});
|
|
20
|
+
const appName = pkgContent.name;
|
|
21
|
+
const appDir = `./${appName}`;
|
|
22
|
+
await ssh.execCommand(dedent`
|
|
27
23
|
set -ex
|
|
28
24
|
mkdir -p app_files/${appName}
|
|
29
25
|
rm -rf ${appDir}
|
|
30
26
|
mkdir ${appDir}
|
|
31
27
|
`, {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
cwd: options.dir,
|
|
29
|
+
onStdout: buf => console.log(buf.toString()),
|
|
30
|
+
onStderr: buf => console.log(buf.toString())
|
|
31
|
+
});
|
|
32
|
+
const remoteAppFile = `${options.dir}/app_files/${appName}/${path.basename(appFile)}`;
|
|
33
|
+
await ssh.putFile(appFile, remoteAppFile);
|
|
34
|
+
await ssh.execCommand(dedent`
|
|
39
35
|
set -ex
|
|
40
36
|
tar -zxvf ${remoteAppFile} -C ${appDir}
|
|
41
37
|
cd ${appDir}/dist
|
|
42
38
|
pm2 startOrReload pm2.config.js
|
|
43
39
|
`, {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
cwd: options.cwd,
|
|
41
|
+
onStdout: buf => console.log(buf.toString()),
|
|
42
|
+
onStderr: buf => console.log(buf.toString())
|
|
43
|
+
});
|
|
44
|
+
ssh.dispose();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
package/lib/cli/env_util.js
CHANGED
|
@@ -1,139 +1,131 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const vtils_1 = require("vtils");
|
|
10
|
-
class EnvUtil {
|
|
11
|
-
static normalizeValue(value) {
|
|
12
|
-
if (value.includes(' || ')) {
|
|
13
|
-
const [devValue, prodValue] = value.split(/\s+\|\|\s+/);
|
|
14
|
-
return (0, vtils_1.devOrProd)(() => EnvUtil.normalizeValue(devValue), () => EnvUtil.normalizeValue(prodValue));
|
|
15
|
-
}
|
|
16
|
-
return value === 'true'
|
|
17
|
-
? true
|
|
18
|
-
: value === 'false'
|
|
19
|
-
? false
|
|
20
|
-
: (value.startsWith('[') && value.endsWith(']')) ||
|
|
21
|
-
(value.startsWith('{') && value.endsWith('}'))
|
|
22
|
-
? JSON.parse(value)
|
|
23
|
-
: (0, vtils_1.isNumeric)(value)
|
|
24
|
-
? Number(value)
|
|
25
|
-
: value;
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { dedent, devOrProd, isNumeric } from 'vtils';
|
|
4
|
+
export class EnvUtil {
|
|
5
|
+
static normalizeValue(value) {
|
|
6
|
+
if (value.includes(' || ')) {
|
|
7
|
+
const [devValue, prodValue] = value.split(/\s+\|\|\s+/);
|
|
8
|
+
return devOrProd(() => EnvUtil.normalizeValue(devValue), () => EnvUtil.normalizeValue(prodValue));
|
|
26
9
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
else if (isSingleQuoted || isDoubleQuoted) {
|
|
66
|
-
val = val.substring(1, end);
|
|
67
|
-
// if double quoted, expand newlines
|
|
68
|
-
if (isDoubleQuoted) {
|
|
69
|
-
val = val.replace(EnvUtil.RE_NEWLINES, EnvUtil.NEWLINE);
|
|
70
|
-
}
|
|
71
|
-
val = (0, vtils_1.dedent)(val);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// remove surrounding whitespace
|
|
75
|
-
val = (0, vtils_1.dedent)(val).trim();
|
|
76
|
-
}
|
|
77
|
-
envs.push({
|
|
78
|
-
key: key,
|
|
79
|
-
value: EnvUtil.normalizeValue(val),
|
|
80
|
-
comment: lastComment,
|
|
81
|
-
});
|
|
82
|
-
lastComment = '';
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
const commentArr = line.match(EnvUtil.COMMENT_MATCH);
|
|
86
|
-
if (commentArr) {
|
|
87
|
-
lastComment = commentArr[1];
|
|
88
|
-
}
|
|
10
|
+
|
|
11
|
+
return value === 'true' ? true : value === 'false' ? false : value.startsWith('[') && value.endsWith(']') || value.startsWith('{') && value.endsWith('}') ? JSON.parse(value) : isNumeric(value) ? Number(value) : value;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static parseContent(src) {
|
|
15
|
+
const envs = []; // https://github.com/andreialecu/dotenv/blob/feat-multiline/lib/main.js
|
|
16
|
+
|
|
17
|
+
const multilineLineBreaks = true; // convert Buffers before splitting into lines and processing
|
|
18
|
+
|
|
19
|
+
const lines = src.toString().split(EnvUtil.NEWLINES_MATCH);
|
|
20
|
+
let lastComment = '';
|
|
21
|
+
|
|
22
|
+
for (let idx = 0; idx < lines.length; idx++) {
|
|
23
|
+
let line = lines[idx]; // matching "KEY' and 'VAL' in 'KEY=VAL'
|
|
24
|
+
|
|
25
|
+
const keyValueArr = line.match(EnvUtil.RE_INI_KEY_VAL); // matched?
|
|
26
|
+
|
|
27
|
+
if (keyValueArr != null) {
|
|
28
|
+
const key = keyValueArr[1]; // default undefined or missing values to empty string
|
|
29
|
+
|
|
30
|
+
let val = keyValueArr[2] || '';
|
|
31
|
+
let end = val.length - 1;
|
|
32
|
+
const isDoubleQuoted = val[0] === '"' && val[end] === '"';
|
|
33
|
+
const isSingleQuoted = val[0] === "'" && val[end] === "'";
|
|
34
|
+
const isMultilineDoubleQuoted = val[0] === '"' && (val.length === 1 || val[end] !== '"');
|
|
35
|
+
const isMultilineSingleQuoted = val[0] === "'" && (val.length === 1 || val[end] !== "'"); // if parsing line breaks and the value starts with a quote
|
|
36
|
+
|
|
37
|
+
if (multilineLineBreaks && (isMultilineDoubleQuoted || isMultilineSingleQuoted)) {
|
|
38
|
+
const quoteChar = isMultilineDoubleQuoted ? '"' : "'";
|
|
39
|
+
val = val.substring(1);
|
|
40
|
+
|
|
41
|
+
while (idx++ < lines.length - 1) {
|
|
42
|
+
line = lines[idx];
|
|
43
|
+
end = line.length - 1;
|
|
44
|
+
|
|
45
|
+
if (line[end] === quoteChar) {
|
|
46
|
+
val += EnvUtil.NEWLINE + line.substring(0, end);
|
|
47
|
+
break;
|
|
89
48
|
}
|
|
49
|
+
|
|
50
|
+
val += EnvUtil.NEWLINE + line;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
val = dedent(val); // if single or double quoted, remove quotes
|
|
54
|
+
} else if (isSingleQuoted || isDoubleQuoted) {
|
|
55
|
+
val = val.substring(1, end); // if double quoted, expand newlines
|
|
56
|
+
|
|
57
|
+
if (isDoubleQuoted) {
|
|
58
|
+
val = val.replace(EnvUtil.RE_NEWLINES, EnvUtil.NEWLINE);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
val = dedent(val);
|
|
62
|
+
} else {
|
|
63
|
+
// remove surrounding whitespace
|
|
64
|
+
val = dedent(val).trim();
|
|
90
65
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
66
|
+
|
|
67
|
+
envs.push({
|
|
68
|
+
key: key,
|
|
69
|
+
value: EnvUtil.normalizeValue(val),
|
|
70
|
+
comment: lastComment
|
|
71
|
+
});
|
|
72
|
+
lastComment = '';
|
|
73
|
+
} else {
|
|
74
|
+
const commentArr = line.match(EnvUtil.COMMENT_MATCH);
|
|
75
|
+
|
|
76
|
+
if (commentArr) {
|
|
77
|
+
lastComment = commentArr[1];
|
|
99
78
|
}
|
|
100
|
-
|
|
79
|
+
}
|
|
101
80
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
81
|
+
|
|
82
|
+
return envs;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static async parseFile(options) {
|
|
86
|
+
const envFile = path.join(options.cwd, options.file);
|
|
87
|
+
|
|
88
|
+
if (await fs.pathExists(envFile)) {
|
|
89
|
+
const envContent = await fs.readFile(envFile, 'utf-8');
|
|
90
|
+
const envs = EnvUtil.parseContent(envContent);
|
|
91
|
+
return envs;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static async importFile(options) {
|
|
98
|
+
for (const env of await EnvUtil.parseFile(options)) {
|
|
99
|
+
process.env[env.key] = env.value;
|
|
106
100
|
}
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static makeTypes(envs) {
|
|
104
|
+
return dedent`
|
|
109
105
|
declare namespace NodeJS {
|
|
110
106
|
interface ProcessEnv {
|
|
111
107
|
/** 当前环境 */
|
|
112
108
|
NODE_ENV: 'development' | 'production';
|
|
113
|
-
${envs
|
|
114
|
-
.map(env => (0, vtils_1.dedent) `
|
|
109
|
+
${envs.map(env => dedent`
|
|
115
110
|
${env.comment ? `/** ${env.comment} */` : ''}
|
|
116
|
-
${env.key}: ${
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
? `Array<${typeof env.value[0]}>`
|
|
120
|
-
: typeof env.value};
|
|
121
|
-
`)
|
|
122
|
-
.join('\n')}
|
|
111
|
+
${env.key}: ${// TODO: 优化类型推断
|
|
112
|
+
Array.isArray(env.value) ? `Array<${typeof env.value[0]}>` : typeof env.value};
|
|
113
|
+
`).join('\n')}
|
|
123
114
|
}
|
|
124
115
|
}
|
|
125
116
|
`;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static async outputTypes(options) {
|
|
120
|
+
const envs = await EnvUtil.parseFile(options);
|
|
121
|
+
const outFile = path.join(options.cwd, options.outFile);
|
|
122
|
+
const types = EnvUtil.makeTypes(envs);
|
|
123
|
+
await fs.outputFile(outFile, types);
|
|
124
|
+
}
|
|
125
|
+
|
|
133
126
|
}
|
|
134
|
-
exports.EnvUtil = EnvUtil;
|
|
135
127
|
EnvUtil.NEWLINE = '\n';
|
|
136
128
|
EnvUtil.RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*(.*)?\s*$/;
|
|
137
129
|
EnvUtil.RE_NEWLINES = /\\n/g;
|
|
138
130
|
EnvUtil.NEWLINES_MATCH = /\r\n|\n|\r/;
|
|
139
|
-
EnvUtil.COMMENT_MATCH = /^#\s*(.+?)\s*$/;
|
|
131
|
+
EnvUtil.COMMENT_MATCH = /^#\s*(.+?)\s*$/;
|
package/lib/cli/register.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
(
|
|
5
|
-
|
|
6
|
-
hookMatcher: filename => filename.includes('/.x/') || !filename.includes('/node_modules/'),
|
|
7
|
-
});
|
|
1
|
+
import { register } from 'esbuild-register/dist/node';
|
|
2
|
+
register({
|
|
3
|
+
hookIgnoreNodeModules: false,
|
|
4
|
+
hookMatcher: filename => filename.includes('/.x/') || !filename.includes('/node_modules/')
|
|
5
|
+
});
|
package/lib/cli/template_util.js
CHANGED
|
@@ -1,56 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const modelNames = [
|
|
36
|
-
...prismaClientFileContent
|
|
37
|
-
.match(/(?<=const ModelName:).+?(?=\})/s)[0]
|
|
38
|
-
.matchAll(/(\S+?):/g),
|
|
39
|
-
].map(match => (0, vtils_1.camelCase)(match[1]));
|
|
40
|
-
await Promise.all(modelNames.map(async (modelName) => {
|
|
41
|
-
const model_name = (0, vtils_1.snakeCase)(modelName);
|
|
42
|
-
const ModelName = (0, vtils_1.upperFirst)(modelName);
|
|
43
|
-
const modelFile = path_1.default.join(modelsDir, `${model_name}.ts`);
|
|
44
|
-
if (!(await fs_extra_1.default.pathExists(modelFile))) {
|
|
45
|
-
await fs_extra_1.default.outputFile(modelFile, (0, vtils_1.dedent) `
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { camelCase, dedent, snakeCase, upperFirst } from 'vtils';
|
|
4
|
+
import { generateManyIndex } from 'vscode-generate-index-standalone';
|
|
5
|
+
export class TemplateUtil {
|
|
6
|
+
/**
|
|
7
|
+
* 初始化辅助包。
|
|
8
|
+
*/
|
|
9
|
+
static async initHelperPackage(cwd) {
|
|
10
|
+
const fromDir = path.join(__dirname, 'templates');
|
|
11
|
+
const toDir = path.join(cwd, 'node_modules/.x');
|
|
12
|
+
await fs.copy(fromDir, toDir, {
|
|
13
|
+
overwrite: true
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 初始化模型。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
static async initModels(cwd) {
|
|
22
|
+
const modelsDir = path.join(cwd, 'src/models');
|
|
23
|
+
const indexFile = path.join(modelsDir, 'index.ts');
|
|
24
|
+
const indexFile2 = path.join(cwd, 'node_modules/.x/models.ts');
|
|
25
|
+
const prismaClientFile = path.join(cwd, 'node_modules/.prisma/client/index.d.ts');
|
|
26
|
+
const prismaClientFileContent = await fs.readFile(prismaClientFile, 'utf8');
|
|
27
|
+
const modelNames = [...prismaClientFileContent.match(/(?<=const ModelName:).+?(?=\})/s)[0].matchAll(/(\S+?):/g)].map(match => camelCase(match[1]));
|
|
28
|
+
await Promise.all(modelNames.map(async modelName => {
|
|
29
|
+
const model_name = snakeCase(modelName);
|
|
30
|
+
const ModelName = upperFirst(modelName);
|
|
31
|
+
const modelFile = path.join(modelsDir, `${model_name}.ts`);
|
|
32
|
+
|
|
33
|
+
if (!(await fs.pathExists(modelFile))) {
|
|
34
|
+
await fs.outputFile(modelFile, dedent`
|
|
46
35
|
import { ${ModelName}BaseModel } from '@jayfong/x-server'
|
|
47
36
|
|
|
48
37
|
export class ${ModelName}Model extends ${ModelName}BaseModel {}
|
|
49
38
|
|
|
50
39
|
export const ${modelName}Model = new ${ModelName}Model()
|
|
51
40
|
`);
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
}
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
if (!(await fs.pathExists(indexFile))) {
|
|
45
|
+
await fs.outputFile(indexFile, dedent`
|
|
46
|
+
// @index(['./**/*.ts', '!**/*.test.ts', '!**/_*'], f => \`export * from '\${f.path}'\`)
|
|
47
|
+
// @endindex
|
|
48
|
+
`);
|
|
54
49
|
}
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
|
|
51
|
+
await generateManyIndex({
|
|
52
|
+
patterns: [indexFile, indexFile2],
|
|
53
|
+
replaceFile: true
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
package/lib/core/define_bus.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
|
|
3
|
+
class EventBus extends EventEmitter {
|
|
4
|
+
onReturnOff(event, listener) {
|
|
5
|
+
this.on(event, listener);
|
|
6
|
+
return () => this.off(event, listener);
|
|
7
|
+
}
|
|
8
|
+
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
|
|
11
|
+
export function defineBus() {
|
|
12
|
+
const eventEmitter = new EventBus();
|
|
13
|
+
return eventEmitter;
|
|
14
|
+
} // strict-event-emitter-types
|
|
15
|
+
// https://github.com/bterlson/strict-event-emitter-types/blob/9ed45fc68a69f0b7f85ce4e5fe11ff53cc6a009e/src/index.ts
|
|
16
|
+
// the overridden signatures need to be assignment compatible, but
|
|
17
|
+
// due to how tuple types work[0] it's not possible to be assignment
|
|
18
|
+
// compatible anymore. This hack fixes it with a unique symbol that
|
|
19
|
+
// won't ever show up in parameter help etc.
|
|
20
|
+
//
|
|
21
|
+
// Unfortunately, this has the result of giving a poor error message when
|
|
22
|
+
// you mix up types.
|
|
23
|
+
// 0: https://github.com/Microsoft/TypeScript/issues/26013)
|
|
@@ -1,41 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
...options,
|
|
8
|
-
requestMethod: 'POST',
|
|
9
|
-
});
|
|
10
|
-
return handler;
|
|
1
|
+
import { Handler } from "./handler";
|
|
2
|
+
export function defineHandler(options) {
|
|
3
|
+
const handler = new Handler({ ...options,
|
|
4
|
+
requestMethod: 'POST'
|
|
5
|
+
});
|
|
6
|
+
return handler;
|
|
11
7
|
}
|
|
12
|
-
exports.defineHandler = defineHandler;
|
|
13
8
|
defineHandler.POST = defineHandler;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
|
|
10
|
+
defineHandler.GET = options => {
|
|
11
|
+
const handler = new Handler({ ...options,
|
|
12
|
+
requestMethod: 'GET'
|
|
13
|
+
});
|
|
14
|
+
return handler;
|
|
20
15
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
|
|
17
|
+
defineHandler.FILE = options => {
|
|
18
|
+
const handler = new Handler({ ...options,
|
|
19
|
+
requestMethod: 'FILE'
|
|
20
|
+
});
|
|
21
|
+
return handler;
|
|
27
22
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
defineHandler.XML = (options) => {
|
|
36
|
-
const handler = new handler_1.Handler({
|
|
37
|
-
...options,
|
|
38
|
-
requestMethod: 'XML',
|
|
39
|
-
});
|
|
40
|
-
return handler;
|
|
23
|
+
|
|
24
|
+
defineHandler.WS = options => {
|
|
25
|
+
const handler = new Handler({ ...options,
|
|
26
|
+
requestMethod: 'WS'
|
|
27
|
+
});
|
|
28
|
+
return handler;
|
|
41
29
|
};
|
|
30
|
+
|
|
31
|
+
defineHandler.XML = options => {
|
|
32
|
+
const handler = new Handler({ ...options,
|
|
33
|
+
requestMethod: 'XML'
|
|
34
|
+
});
|
|
35
|
+
return handler;
|
|
36
|
+
};
|
package/lib/core/define_hook.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function defineHook(hook) {
|
|
6
|
-
handler_1.Handler.addHook(hook);
|
|
7
|
-
}
|
|
8
|
-
exports.defineHook = defineHook;
|
|
1
|
+
import { Handler } from "./handler";
|
|
2
|
+
export function defineHook(hook) {
|
|
3
|
+
Handler.addHook(hook);
|
|
4
|
+
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
await server.start();
|
|
8
|
-
return server;
|
|
9
|
-
}
|
|
10
|
-
exports.defineServer = defineServer;
|
|
1
|
+
import { Server } from "./server";
|
|
2
|
+
export async function defineServer(options) {
|
|
3
|
+
const server = new Server(options);
|
|
4
|
+
await server.start();
|
|
5
|
+
return server;
|
|
6
|
+
}
|