@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.
Files changed (73) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/lib/_cjs/cli/api_generator.js +295 -0
  3. package/lib/_cjs/cli/build_util.js +146 -0
  4. package/lib/_cjs/cli/cli.js +190 -0
  5. package/lib/_cjs/cli/deploy_util.js +61 -0
  6. package/lib/_cjs/cli/env_util.js +145 -0
  7. package/lib/_cjs/cli/register.js +8 -0
  8. package/lib/_cjs/cli/template_util.js +77 -0
  9. package/lib/_cjs/cli/templates/handlers.ts +3 -0
  10. package/lib/_cjs/cli/templates/hooks.ts +2 -0
  11. package/lib/_cjs/cli/templates/models.ts +22 -0
  12. package/lib/_cjs/cli/templates/package.json +3 -0
  13. package/lib/_cjs/cli/templates/routes.ts +26 -0
  14. package/lib/_cjs/cli/templates/tasks.ts +2 -0
  15. package/lib/_cjs/core/define_bus.js +28 -0
  16. package/lib/_cjs/core/define_handler.js +43 -0
  17. package/lib/_cjs/core/define_hook.js +10 -0
  18. package/lib/_cjs/core/define_server.js +12 -0
  19. package/lib/_cjs/core/define_task.js +30 -0
  20. package/lib/_cjs/core/handler.js +90 -0
  21. package/lib/_cjs/core/http_error.js +9 -0
  22. package/lib/_cjs/core/http_method.js +12 -0
  23. package/lib/_cjs/core/server.js +145 -0
  24. package/lib/_cjs/core/types.js +18 -0
  25. package/lib/_cjs/index.js +179 -0
  26. package/lib/_cjs/plugins/base.js +3 -0
  27. package/lib/_cjs/plugins/cors.js +44 -0
  28. package/lib/_cjs/plugins/file_parser.js +24 -0
  29. package/lib/_cjs/plugins/ws_parser.js +24 -0
  30. package/lib/_cjs/plugins/xml_parser.js +61 -0
  31. package/lib/_cjs/services/base.js +3 -0
  32. package/lib/_cjs/services/cache.js +231 -0
  33. package/lib/_cjs/services/captcha.js +45 -0
  34. package/lib/_cjs/services/dispose.js +33 -0
  35. package/lib/_cjs/services/jwt.js +59 -0
  36. package/lib/_cjs/services/redis.js +18 -0
  37. package/lib/_cjs/x.js +20 -0
  38. package/lib/cli/api_generator.js +269 -332
  39. package/lib/cli/build_util.d.ts +1 -0
  40. package/lib/cli/build_util.js +108 -130
  41. package/lib/cli/cli.js +161 -208
  42. package/lib/cli/deploy_util.js +37 -41
  43. package/lib/cli/env_util.js +112 -120
  44. package/lib/cli/register.js +5 -7
  45. package/lib/cli/template_util.js +50 -49
  46. package/lib/core/define_bus.js +22 -14
  47. package/lib/core/define_handler.js +31 -36
  48. package/lib/core/define_hook.js +4 -8
  49. package/lib/core/define_server.js +6 -10
  50. package/lib/core/define_task.js +20 -25
  51. package/lib/core/handler.js +78 -74
  52. package/lib/core/http_error.js +2 -8
  53. package/lib/core/http_method.js +7 -10
  54. package/lib/core/server.js +125 -139
  55. package/lib/core/types.js +11 -2
  56. package/lib/index.js +23 -39
  57. package/lib/plugins/base.js +1 -2
  58. package/lib/plugins/cors.js +30 -36
  59. package/lib/plugins/file_parser.d.ts +1 -1
  60. package/lib/plugins/file_parser.js +12 -16
  61. package/lib/plugins/ws_parser.d.ts +1 -1
  62. package/lib/plugins/ws_parser.js +12 -16
  63. package/lib/plugins/xml_parser.d.ts +1 -1
  64. package/lib/plugins/xml_parser.js +47 -43
  65. package/lib/services/base.js +1 -2
  66. package/lib/services/cache.js +213 -190
  67. package/lib/services/captcha.js +32 -33
  68. package/lib/services/dispose.d.ts +1 -1
  69. package/lib/services/dispose.js +22 -23
  70. package/lib/services/jwt.js +45 -48
  71. package/lib/services/redis.js +8 -14
  72. package/lib/x.js +12 -15
  73. package/package.json +5 -3
@@ -1,51 +1,47 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DeployUtil = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const path_1 = __importDefault(require("path"));
9
- const vtils_1 = require("vtils");
10
- const node_ssh_1 = require("node-ssh");
11
- class DeployUtil {
12
- static async deploy(options) {
13
- const pkgContent = await fs_extra_1.default.readJson(path_1.default.join(options.cwd, 'package.json'));
14
- const appFile = path_1.default.join(options.cwd, `temp/app.${pkgContent.version}.tgz`);
15
- if (!(await fs_extra_1.default.pathExists(appFile))) {
16
- throw new Error('请先构建');
17
- }
18
- const ssh = new node_ssh_1.NodeSSH();
19
- await ssh.connect({
20
- host: options.host,
21
- username: options.user,
22
- privateKey: options.key,
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
- cwd: options.dir,
33
- onStdout: buf => console.log(buf.toString()),
34
- onStderr: buf => console.log(buf.toString()),
35
- });
36
- const remoteAppFile = `${options.dir}/app_files/${appName}/${path_1.default.basename(appFile)}`;
37
- await ssh.putFile(appFile, remoteAppFile);
38
- await ssh.execCommand((0, vtils_1.dedent) `
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
- cwd: options.cwd,
45
- onStdout: buf => console.log(buf.toString()),
46
- onStderr: buf => console.log(buf.toString()),
47
- });
48
- ssh.dispose();
49
- }
50
- }
51
- exports.DeployUtil = DeployUtil;
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
+ }
@@ -1,139 +1,131 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.EnvUtil = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const node_path_1 = __importDefault(require("node:path"));
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
- static parseContent(src) {
28
- const envs = [];
29
- // https://github.com/andreialecu/dotenv/blob/feat-multiline/lib/main.js
30
- const multilineLineBreaks = true;
31
- // convert Buffers before splitting into lines and processing
32
- const lines = src.toString().split(EnvUtil.NEWLINES_MATCH);
33
- let lastComment = '';
34
- for (let idx = 0; idx < lines.length; idx++) {
35
- let line = lines[idx];
36
- // matching "KEY' and 'VAL' in 'KEY=VAL'
37
- const keyValueArr = line.match(EnvUtil.RE_INI_KEY_VAL);
38
- // matched?
39
- if (keyValueArr != null) {
40
- const key = keyValueArr[1];
41
- // default undefined or missing values to empty string
42
- let val = keyValueArr[2] || '';
43
- let end = val.length - 1;
44
- const isDoubleQuoted = val[0] === '"' && val[end] === '"';
45
- const isSingleQuoted = val[0] === "'" && val[end] === "'";
46
- const isMultilineDoubleQuoted = val[0] === '"' && (val.length === 1 || val[end] !== '"');
47
- const isMultilineSingleQuoted = val[0] === "'" && (val.length === 1 || val[end] !== "'");
48
- // if parsing line breaks and the value starts with a quote
49
- if (multilineLineBreaks &&
50
- (isMultilineDoubleQuoted || isMultilineSingleQuoted)) {
51
- const quoteChar = isMultilineDoubleQuoted ? '"' : "'";
52
- val = val.substring(1);
53
- while (idx++ < lines.length - 1) {
54
- line = lines[idx];
55
- end = line.length - 1;
56
- if (line[end] === quoteChar) {
57
- val += EnvUtil.NEWLINE + line.substring(0, end);
58
- break;
59
- }
60
- val += EnvUtil.NEWLINE + line;
61
- }
62
- val = (0, vtils_1.dedent)(val);
63
- // if single or double quoted, remove quotes
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
- return envs;
92
- }
93
- static async parseFile(options) {
94
- const envFile = node_path_1.default.join(options.cwd, options.file);
95
- if (await fs_extra_1.default.pathExists(envFile)) {
96
- const envContent = await fs_extra_1.default.readFile(envFile, 'utf-8');
97
- const envs = EnvUtil.parseContent(envContent);
98
- return envs;
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
- return [];
79
+ }
101
80
  }
102
- static async importFile(options) {
103
- for (const env of await EnvUtil.parseFile(options)) {
104
- process.env[env.key] = env.value;
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
- static makeTypes(envs) {
108
- return (0, vtils_1.dedent) `
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
- // TODO: 优化类型推断
118
- Array.isArray(env.value)
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
- static async outputTypes(options) {
128
- const envs = await EnvUtil.parseFile(options);
129
- const outFile = node_path_1.default.join(options.cwd, options.outFile);
130
- const types = EnvUtil.makeTypes(envs);
131
- await fs_extra_1.default.outputFile(outFile, types);
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*$/;
@@ -1,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const node_1 = require("esbuild-register/dist/node");
4
- (0, node_1.register)({
5
- hookIgnoreNodeModules: false,
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
+ });
@@ -1,56 +1,57 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TemplateUtil = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const path_1 = __importDefault(require("path"));
9
- const vtils_1 = require("vtils");
10
- class TemplateUtil {
11
- /**
12
- * 初始化辅助包。
13
- */
14
- static async initHelperPackage(cwd) {
15
- const fromDir = path_1.default.join(__dirname, 'templates');
16
- const toDir = path_1.default.join(cwd, 'node_modules/.x');
17
- await fs_extra_1.default.copy(fromDir, toDir, {
18
- overwrite: true,
19
- });
20
- }
21
- /**
22
- * 初始化模型。
23
- */
24
- static async initModels(cwd) {
25
- const modelsDir = path_1.default.join(cwd, 'src/models');
26
- const indexFile = path_1.default.join(modelsDir, 'index.ts');
27
- if (!(await fs_extra_1.default.pathExists(indexFile))) {
28
- await fs_extra_1.default.outputFile(indexFile, (0, vtils_1.dedent) `
29
- // @index(['./**/*.ts', '!**/*.test.ts', '!**/_*'], f => \`export * from '\${f.path}'\`)
30
- // @endindex
31
- `);
32
- }
33
- const prismaClientFile = path_1.default.join(cwd, 'node_modules/.prisma/client/index.d.ts');
34
- const prismaClientFileContent = await fs_extra_1.default.readFile(prismaClientFile, 'utf8');
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
- exports.TemplateUtil = TemplateUtil;
50
+
51
+ await generateManyIndex({
52
+ patterns: [indexFile, indexFile2],
53
+ replaceFile: true
54
+ });
55
+ }
56
+
57
+ }
@@ -1,15 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineBus = void 0;
4
- const node_events_1 = require("node:events");
5
- class EventBus extends node_events_1.EventEmitter {
6
- onReturnOff(event, listener) {
7
- this.on(event, listener);
8
- return () => this.off(event, listener);
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
- function defineBus() {
12
- const eventEmitter = new EventBus();
13
- return eventEmitter;
14
- }
15
- exports.defineBus = defineBus;
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineHandler = void 0;
4
- const handler_1 = require("./handler");
5
- function defineHandler(options) {
6
- const handler = new handler_1.Handler({
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
- defineHandler.GET = (options) => {
15
- const handler = new handler_1.Handler({
16
- ...options,
17
- requestMethod: 'GET',
18
- });
19
- return handler;
9
+
10
+ defineHandler.GET = options => {
11
+ const handler = new Handler({ ...options,
12
+ requestMethod: 'GET'
13
+ });
14
+ return handler;
20
15
  };
21
- defineHandler.FILE = (options) => {
22
- const handler = new handler_1.Handler({
23
- ...options,
24
- requestMethod: 'FILE',
25
- });
26
- return handler;
16
+
17
+ defineHandler.FILE = options => {
18
+ const handler = new Handler({ ...options,
19
+ requestMethod: 'FILE'
20
+ });
21
+ return handler;
27
22
  };
28
- defineHandler.WS = (options) => {
29
- const handler = new handler_1.Handler({
30
- ...options,
31
- requestMethod: 'WS',
32
- });
33
- return handler;
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
+ };
@@ -1,8 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineHook = void 0;
4
- const handler_1 = require("./handler");
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineServer = void 0;
4
- const server_1 = require("./server");
5
- async function defineServer(options) {
6
- const server = new server_1.Server(options);
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
+ }