phecda-server 7.0.0-alpha.9 → 7.0.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/assets/schema.json +12 -9
- package/bin/cli.mjs +95 -36
- package/dist/{chunk-5RBTN33A.js → chunk-4LLLQOMF.js} +10 -5
- package/dist/{chunk-7ZGYJ5OW.mjs → chunk-AIAO6SV6.mjs} +10 -34
- package/dist/{chunk-V5EYXVJT.js → chunk-DPPDWBYO.js} +53 -25
- package/dist/{chunk-CVPZWDXU.mjs → chunk-E7EAPAGM.mjs} +10 -20
- package/dist/{chunk-ODVWOXVB.mjs → chunk-MKRHYZCL.mjs} +30 -2
- package/dist/{chunk-FXTJ3BJ6.mjs → chunk-NQ55PA2X.mjs} +9 -4
- package/dist/{chunk-FX3LDQII.js → chunk-XKK2SQ7W.js} +60 -70
- package/dist/{chunk-KJUD2BKE.js → chunk-ZWPOWMZP.js} +25 -49
- package/dist/{core-D_cz0tKa.d.ts → core-DbqWh47p.d.mts} +3 -2
- package/dist/{core-BDkhrEyf.d.mts → core-Rq7BhPHE.d.ts} +3 -2
- package/dist/helper.d.mts +3 -5
- package/dist/helper.d.ts +3 -5
- package/dist/helper.js +3 -5
- package/dist/helper.mjs +2 -4
- package/dist/http/elysia/index.d.mts +4 -4
- package/dist/http/elysia/index.d.ts +4 -4
- package/dist/http/elysia/index.js +41 -40
- package/dist/http/elysia/index.mjs +4 -3
- package/dist/http/express/index.d.mts +3 -3
- package/dist/http/express/index.d.ts +3 -3
- package/dist/http/express/index.js +38 -37
- package/dist/http/express/index.mjs +3 -2
- package/dist/http/fastify/index.d.mts +3 -3
- package/dist/http/fastify/index.d.ts +3 -3
- package/dist/http/fastify/index.js +39 -38
- package/dist/http/fastify/index.mjs +4 -3
- package/dist/http/h3/index.d.mts +3 -3
- package/dist/http/h3/index.d.ts +3 -3
- package/dist/http/h3/index.js +39 -38
- package/dist/http/h3/index.mjs +3 -2
- package/dist/http/hono/index.d.mts +3 -3
- package/dist/http/hono/index.d.ts +3 -3
- package/dist/http/hono/index.js +35 -34
- package/dist/http/hono/index.mjs +3 -2
- package/dist/http/hyper-express/index.d.mts +3 -3
- package/dist/http/hyper-express/index.d.ts +3 -3
- package/dist/http/hyper-express/index.js +36 -35
- package/dist/http/hyper-express/index.mjs +3 -2
- package/dist/http/koa/index.d.mts +3 -3
- package/dist/http/koa/index.d.ts +3 -3
- package/dist/http/koa/index.js +38 -37
- package/dist/http/koa/index.mjs +3 -2
- package/dist/index.d.mts +76 -12
- package/dist/index.d.ts +76 -12
- package/dist/index.js +102 -49
- package/dist/index.mjs +66 -13
- package/dist/{meta-BX5jhe4Z.d.mts → meta-BoS1E-Nz.d.mts} +6 -23
- package/dist/{meta-BX5jhe4Z.d.ts → meta-BoS1E-Nz.d.ts} +6 -23
- package/dist/rpc/bullmq/index.d.mts +4 -6
- package/dist/rpc/bullmq/index.d.ts +4 -6
- package/dist/rpc/bullmq/index.js +12 -80
- package/dist/rpc/bullmq/index.mjs +4 -72
- package/dist/rpc/electron/index.d.mts +13 -0
- package/dist/rpc/electron/index.d.ts +13 -0
- package/dist/rpc/electron/index.js +72 -0
- package/dist/rpc/electron/index.mjs +72 -0
- package/dist/rpc/kafka/index.d.mts +4 -9
- package/dist/rpc/kafka/index.d.ts +4 -9
- package/dist/rpc/kafka/index.js +11 -90
- package/dist/rpc/kafka/index.mjs +4 -83
- package/dist/rpc/nats/index.d.mts +4 -6
- package/dist/rpc/nats/index.d.ts +4 -6
- package/dist/rpc/nats/index.js +12 -72
- package/dist/rpc/nats/index.mjs +3 -63
- package/dist/rpc/rabbitmq/index.d.mts +4 -6
- package/dist/rpc/rabbitmq/index.d.ts +4 -6
- package/dist/rpc/rabbitmq/index.js +13 -79
- package/dist/rpc/rabbitmq/index.mjs +4 -70
- package/dist/rpc/redis/index.d.mts +4 -9
- package/dist/rpc/redis/index.d.ts +4 -9
- package/dist/rpc/redis/index.js +11 -78
- package/dist/rpc/redis/index.mjs +4 -71
- package/dist/rpc/web-ext/index.d.mts +2 -0
- package/dist/rpc/web-ext/index.d.ts +2 -0
- package/dist/rpc/web-ext/index.js +1 -0
- package/dist/rpc/web-ext/index.mjs +0 -0
- package/dist/rpc/ws/index.d.mts +14 -0
- package/dist/rpc/ws/index.d.ts +14 -0
- package/dist/rpc/ws/index.js +73 -0
- package/dist/rpc/ws/index.mjs +73 -0
- package/dist/test.d.mts +7 -3
- package/dist/test.d.ts +7 -3
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/dist/types-CInz3bD0.d.ts +14 -0
- package/dist/types-E-rqlg3-.d.mts +14 -0
- package/dist/{types-DKVhyZk_.d.mts → types-SCJZFCYt.d.mts} +1 -1
- package/dist/{types-CMeuFoyd.d.ts → types-xruyYmyu.d.ts} +1 -1
- package/package.json +24 -8
- package/register/export.mjs +30 -0
- package/register/index.mjs +2 -3
- package/register/loader.mjs +83 -90
- package/register/utils.mjs +36 -6
- package/assets/ps.json +0 -24
- package/assets/tsconfig.json +0 -21
- package/dist/types-B-rUM9Fm.d.mts +0 -19
- package/dist/types-MxxtkZXw.d.ts +0 -19
package/assets/schema.json
CHANGED
|
@@ -38,16 +38,19 @@
|
|
|
38
38
|
},
|
|
39
39
|
"description": "Including the module's file middle name, such as controller mapping to xx.controller.ts"
|
|
40
40
|
},
|
|
41
|
-
|
|
42
|
-
"type": "object",
|
|
43
|
-
"additionalProperties": {
|
|
44
|
-
"type": "string"
|
|
45
|
-
},
|
|
46
|
-
"description": "Virtual module, just like in Vite."
|
|
47
|
-
},
|
|
41
|
+
|
|
48
42
|
"unimport": {
|
|
49
|
-
"
|
|
50
|
-
|
|
43
|
+
"oneOf": [
|
|
44
|
+
{
|
|
45
|
+
"type": "object",
|
|
46
|
+
"description": "Includes the arguments passed to unimport"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"type": "boolean",
|
|
50
|
+
"enum": [false],
|
|
51
|
+
"description": "Disable unimport"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
51
54
|
}
|
|
52
55
|
},
|
|
53
56
|
|
package/bin/cli.mjs
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
import { fork } from 'child_process'
|
|
3
3
|
import { createRequire } from 'module'
|
|
4
|
-
import { fileURLToPath } from 'url'
|
|
5
|
-
|
|
6
|
-
import { dirname, resolve } from 'path'
|
|
7
4
|
import pc from 'picocolors'
|
|
8
5
|
import cac from 'cac'
|
|
9
6
|
import fse from 'fs-extra'
|
|
10
|
-
import { log } from '../dist/index.mjs'
|
|
7
|
+
import { log as psLog } from '../dist/index.mjs'
|
|
8
|
+
|
|
9
|
+
const log = (...args) => {
|
|
10
|
+
if (process.env.PS_BAN_CLI_LOG)
|
|
11
|
+
return
|
|
12
|
+
|
|
13
|
+
psLog(...args)
|
|
14
|
+
}
|
|
11
15
|
|
|
12
16
|
const cli = cac('phecda').option('-c,--config <config>', 'config file', {
|
|
13
17
|
default: 'ps.json',
|
|
18
|
+
}).option('-n,--node-args <node-args>', 'args that will be passed to nodejs', {
|
|
19
|
+
default: '',
|
|
14
20
|
})
|
|
15
21
|
|
|
16
|
-
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
17
|
-
|
|
18
22
|
const require = createRequire(import.meta.url)
|
|
19
23
|
let child
|
|
20
24
|
|
|
@@ -29,33 +33,25 @@ if (nodeVersion < 18.19) {
|
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
function startChild(file, args) {
|
|
32
|
-
child = fork(file, {
|
|
36
|
+
child = globalThis.PS_CREATE_CHILD?.() || fork(file, {
|
|
33
37
|
env: { ...process.env },
|
|
34
38
|
stdio: 'inherit',
|
|
35
39
|
execArgv: [
|
|
40
|
+
...args,
|
|
36
41
|
nodeVersion < 18.19
|
|
37
42
|
? '--loader=phecda-server/register/loader.mjs'
|
|
38
43
|
: '--import=phecda-server/register',
|
|
39
|
-
...args,
|
|
40
44
|
],
|
|
41
45
|
})
|
|
42
46
|
|
|
43
47
|
closePromise = new Promise((resolve) => {
|
|
44
48
|
child.once('exit', (code) => {
|
|
45
|
-
if (code ===
|
|
46
|
-
log('only generate code')
|
|
47
|
-
process.exit(0)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (code === 5) {
|
|
51
|
-
log('Does not comply with strict mode', 'error')
|
|
52
|
-
process.exit(0)
|
|
53
|
-
}
|
|
54
|
-
if (code >= 2) {
|
|
55
|
-
// for relaunch
|
|
56
|
-
log('relaunch...')
|
|
49
|
+
if (code === 4171)
|
|
57
50
|
startChild(file, args)
|
|
58
|
-
|
|
51
|
+
|
|
52
|
+
if (code === 4172)
|
|
53
|
+
return process.exit()
|
|
54
|
+
|
|
59
55
|
child = undefined
|
|
60
56
|
|
|
61
57
|
resolve()
|
|
@@ -80,7 +76,7 @@ process.on('SIGINT', () => {
|
|
|
80
76
|
|
|
81
77
|
cli
|
|
82
78
|
.command('init [root]', 'init config file')
|
|
83
|
-
.allowUnknownOptions()
|
|
79
|
+
// .allowUnknownOptions()
|
|
84
80
|
.option('-t,--tsconfig <tsconfig>', 'init tsconfig file', {
|
|
85
81
|
default: 'tsconfig.json',
|
|
86
82
|
})
|
|
@@ -88,22 +84,82 @@ cli
|
|
|
88
84
|
if (root)
|
|
89
85
|
process.chdir(root)
|
|
90
86
|
|
|
87
|
+
let hasUnimport
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
await import('unimport')
|
|
91
|
+
hasUnimport = true
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
catch (e) {
|
|
95
|
+
hasUnimport = false
|
|
96
|
+
}
|
|
97
|
+
|
|
91
98
|
const tsconfigPath = options.tsconfig
|
|
92
|
-
const psconfigPath = options.config
|
|
99
|
+
const psconfigPath = process.env.PS_CONFIG_FILE || options.config
|
|
93
100
|
|
|
94
101
|
if (!fse.existsSync(tsconfigPath)) {
|
|
95
102
|
log(`create ${tsconfigPath}`)
|
|
96
103
|
|
|
97
|
-
await fse.
|
|
98
|
-
resolve(__dirname, '../assets/tsconfig.json'),
|
|
104
|
+
await fse.outputJSON(
|
|
99
105
|
tsconfigPath,
|
|
106
|
+
{
|
|
107
|
+
compilerOptions: {
|
|
108
|
+
target: 'esnext',
|
|
109
|
+
useDefineForClassFields: false,
|
|
110
|
+
experimentalDecorators: true,
|
|
111
|
+
emitDecoratorMetadata: true,
|
|
112
|
+
module: 'esnext',
|
|
113
|
+
lib: ['esnext', 'DOM'],
|
|
114
|
+
paths: {
|
|
115
|
+
|
|
116
|
+
},
|
|
117
|
+
strictPropertyInitialization: false,
|
|
118
|
+
moduleResolution: 'bundler',
|
|
119
|
+
strict: true,
|
|
120
|
+
resolveJsonModule: true,
|
|
121
|
+
esModuleInterop: true,
|
|
122
|
+
noEmit: true,
|
|
123
|
+
noUnusedLocals: true,
|
|
124
|
+
noUnusedParameters: true,
|
|
125
|
+
noImplicitReturns: true,
|
|
126
|
+
skipLibCheck: true,
|
|
127
|
+
},
|
|
128
|
+
include: ['.', hasUnimport ? (process.env.PS_DTS_PATH || 'ps.d.ts') : undefined],
|
|
129
|
+
},
|
|
130
|
+
|
|
100
131
|
)
|
|
101
132
|
}
|
|
102
133
|
|
|
103
134
|
if (!fse.existsSync(psconfigPath)) {
|
|
104
135
|
log(`create ${psconfigPath}`)
|
|
105
136
|
|
|
106
|
-
await fse.
|
|
137
|
+
await fse.outputJSON(psconfigPath, {
|
|
138
|
+
$schema: './node_modules/phecda-server/assets/schema.json',
|
|
139
|
+
resolve: [
|
|
140
|
+
{
|
|
141
|
+
source: 'controller',
|
|
142
|
+
importer: 'http',
|
|
143
|
+
path: '.ps/http.js',
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
source: 'rpc',
|
|
147
|
+
importer: 'client',
|
|
148
|
+
path: '.ps/rpc.js',
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
unimport: hasUnimport && {
|
|
152
|
+
dirs: [
|
|
153
|
+
'.',
|
|
154
|
+
],
|
|
155
|
+
dirsScanOptions: {
|
|
156
|
+
filePatterns: [
|
|
157
|
+
'*.{service,controller,module,rpc,solo,guard,extension,pipe,filter,addon}.ts',
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
moduleFile: [],
|
|
162
|
+
})
|
|
107
163
|
}
|
|
108
164
|
|
|
109
165
|
log('init finish')
|
|
@@ -112,12 +168,13 @@ cli
|
|
|
112
168
|
cli
|
|
113
169
|
.command('<file> [root]', 'run file')
|
|
114
170
|
.alias('run')
|
|
115
|
-
.allowUnknownOptions()
|
|
116
|
-
.
|
|
117
|
-
.option('-p,--prod [prod]', 'prod mode', {
|
|
171
|
+
// .allowUnknownOptions()
|
|
172
|
+
.option('-p,--prod', 'prod mode', {
|
|
118
173
|
default: false,
|
|
119
174
|
})
|
|
120
175
|
.action((file, root, options) => {
|
|
176
|
+
const nodeArgs = options.nodeArgs.split(' ').filter(Boolean)
|
|
177
|
+
|
|
121
178
|
if (root)
|
|
122
179
|
process.chdir(root)
|
|
123
180
|
|
|
@@ -126,11 +183,11 @@ cli
|
|
|
126
183
|
else
|
|
127
184
|
process.env.NODE_ENV = 'development'
|
|
128
185
|
|
|
129
|
-
process.env.PS_CONFIG_FILE = options.config
|
|
186
|
+
process.env.PS_CONFIG_FILE = process.env.PS_CONFIG_FILE || options.config
|
|
130
187
|
|
|
131
188
|
log('process start!')
|
|
132
189
|
|
|
133
|
-
startChild(file,
|
|
190
|
+
startChild(file, nodeArgs)
|
|
134
191
|
console.log(`${pc.green('->')} press ${pc.green('e')} to exit`)
|
|
135
192
|
console.log(`${pc.green('->')} press ${pc.green('r')} to relaunch`)
|
|
136
193
|
console.log(`${pc.green('->')} press ${pc.green('c')} to clear terminal`)
|
|
@@ -143,12 +200,12 @@ cli
|
|
|
143
200
|
if (closePromise)
|
|
144
201
|
await closePromise
|
|
145
202
|
log('relaunch...')
|
|
146
|
-
startChild(file,
|
|
203
|
+
startChild(file, nodeArgs)
|
|
147
204
|
}
|
|
148
205
|
else {
|
|
149
206
|
log('relaunch...')
|
|
150
207
|
|
|
151
|
-
startChild(file,
|
|
208
|
+
startChild(file, nodeArgs)
|
|
152
209
|
}
|
|
153
210
|
}
|
|
154
211
|
if (input === 'e')
|
|
@@ -161,13 +218,15 @@ cli
|
|
|
161
218
|
|
|
162
219
|
cli
|
|
163
220
|
.command('generate <file> [root]', 'generate code(mainly for ci)')
|
|
164
|
-
.allowUnknownOptions()
|
|
221
|
+
// .allowUnknownOptions()
|
|
165
222
|
.action((file, root, options) => {
|
|
223
|
+
const nodeArgs = options.nodeArgs.split(' ').filter(Boolean)
|
|
224
|
+
|
|
166
225
|
if (root)
|
|
167
226
|
process.chdir(root)
|
|
168
227
|
process.env.PS_GENERATE = 'true'
|
|
169
|
-
process.env.PS_CONFIG_FILE = options.config
|
|
170
|
-
startChild(file,
|
|
228
|
+
process.env.PS_CONFIG_FILE = process.env.PS_CONFIG_FILE || options.config
|
|
229
|
+
startChild(file, nodeArgs)
|
|
171
230
|
})
|
|
172
231
|
|
|
173
232
|
cli.help()
|
|
@@ -6,10 +6,11 @@ var ERROR_SYMBOL = "__PS_ERROR__";
|
|
|
6
6
|
var IS_DEV = process.env.NODE_ENV === "development";
|
|
7
7
|
var IS_ONLY_GENERATE = !!process.env.PS_GENERATE;
|
|
8
8
|
var IS_STRICT = !!process.env.PS_STRICT;
|
|
9
|
+
var IS_PURE = !!process.env.PS_PURE;
|
|
9
10
|
var LOG_LEVEL = Number(process.env.PS_LOG_LEVEL || 0);
|
|
10
11
|
var PS_EXIT_CODE = /* @__PURE__ */ function(PS_EXIT_CODE2) {
|
|
11
|
-
PS_EXIT_CODE2[PS_EXIT_CODE2["RELAUNCH"] =
|
|
12
|
-
PS_EXIT_CODE2[PS_EXIT_CODE2["
|
|
12
|
+
PS_EXIT_CODE2[PS_EXIT_CODE2["RELAUNCH"] = 4171] = "RELAUNCH";
|
|
13
|
+
PS_EXIT_CODE2[PS_EXIT_CODE2["EXIT"] = 4172] = "EXIT";
|
|
13
14
|
return PS_EXIT_CODE2;
|
|
14
15
|
}({});
|
|
15
16
|
|
|
@@ -81,7 +82,7 @@ ${JSON.stringify(message, (key, value) => typeof value === "bigint" ? value.toSt
|
|
|
81
82
|
log(msg, level, ctx) {
|
|
82
83
|
if (!this.isAllowLog(level)) return;
|
|
83
84
|
msg = this.stringifyMessage(msg, level);
|
|
84
|
-
const pidMsg = this.colorize(`[phecda-server] ${process.pid}`, level);
|
|
85
|
+
const pidMsg = this.colorize(`[${process.env.PS_APP_NAME || "phecda-server"}] ${process.pid}`, level);
|
|
85
86
|
const ctxMsg = ctx ? this.colorize(_picocolors2.default.bold(`[${ctx}] `), level) : "";
|
|
86
87
|
const timeDiff = this.diffTimestamp();
|
|
87
88
|
const levelMsg = this.colorize(level.toUpperCase().padStart(7, " "), level);
|
|
@@ -124,7 +125,10 @@ async function RELOAD(oldModels, newModels) {
|
|
|
124
125
|
}
|
|
125
126
|
__name(RELOAD, "RELOAD");
|
|
126
127
|
function RELAUNCH() {
|
|
127
|
-
if (IS_DEV)
|
|
128
|
+
if (IS_DEV) {
|
|
129
|
+
log("relaunch...");
|
|
130
|
+
process.exit(PS_EXIT_CODE.RELAUNCH);
|
|
131
|
+
}
|
|
128
132
|
}
|
|
129
133
|
__name(RELAUNCH, "RELAUNCH");
|
|
130
134
|
|
|
@@ -144,4 +148,5 @@ __name(RELAUNCH, "RELAUNCH");
|
|
|
144
148
|
|
|
145
149
|
|
|
146
150
|
|
|
147
|
-
|
|
151
|
+
|
|
152
|
+
exports.__name = __name; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.IS_DEV = IS_DEV; exports.IS_ONLY_GENERATE = IS_ONLY_GENERATE; exports.IS_STRICT = IS_STRICT; exports.IS_PURE = IS_PURE; exports.LOG_LEVEL = LOG_LEVEL; exports.PS_EXIT_CODE = PS_EXIT_CODE; exports.setLogger = setLogger; exports.getLogger = getLogger; exports.log = log; exports.runMiddleware = runMiddleware; exports.Mixin = _tsmixer.Mixin; exports.HMR = HMR; exports.RELOAD = RELOAD; exports.RELAUNCH = RELAUNCH;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HMR,
|
|
3
3
|
IS_ONLY_GENERATE,
|
|
4
|
+
PS_EXIT_CODE,
|
|
4
5
|
__name,
|
|
5
6
|
log
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-NQ55PA2X.mjs";
|
|
7
8
|
|
|
8
9
|
// src/meta.ts
|
|
9
10
|
var Meta = class {
|
|
@@ -20,7 +21,7 @@ var Meta = class {
|
|
|
20
21
|
|
|
21
22
|
// src/core.ts
|
|
22
23
|
import "reflect-metadata";
|
|
23
|
-
import EventEmitter from "
|
|
24
|
+
import EventEmitter from "events";
|
|
24
25
|
import { getInject, getMergedMeta, getMetaKey, getMetaParams, getTag, invokeInit, invokeUnmount, setInject } from "phecda-core";
|
|
25
26
|
import Debug from "debug";
|
|
26
27
|
var debug = Debug("phecda-server(Factory)");
|
|
@@ -63,7 +64,10 @@ var ServerPhecda = class {
|
|
|
63
64
|
for (const model of models) await this.buildDepModule(model);
|
|
64
65
|
this.hmr();
|
|
65
66
|
this.generateCode().then(() => {
|
|
66
|
-
if (IS_ONLY_GENERATE)
|
|
67
|
+
if (IS_ONLY_GENERATE) {
|
|
68
|
+
log("Only generate code");
|
|
69
|
+
process.exit(PS_EXIT_CODE.EXIT);
|
|
70
|
+
}
|
|
67
71
|
});
|
|
68
72
|
}
|
|
69
73
|
generateCode = /* @__PURE__ */ __name(async () => {
|
|
@@ -79,37 +83,6 @@ var ServerPhecda = class {
|
|
|
79
83
|
this.generateCode();
|
|
80
84
|
});
|
|
81
85
|
}
|
|
82
|
-
// async add(Model: Construct) {
|
|
83
|
-
// const tag = getTag(Model)
|
|
84
|
-
// const oldInstance = await this.del(tag)
|
|
85
|
-
// const { module: newModule } = await this.buildDepModule(Model)
|
|
86
|
-
// if (oldInstance && this.dependenceGraph.has(tag)) {
|
|
87
|
-
// debug(`replace module "${String(tag)}"`);
|
|
88
|
-
// [...this.dependenceGraph.get(tag)!].forEach((tag) => {
|
|
89
|
-
// const module = this.moduleMap.get(tag)
|
|
90
|
-
// for (const key in module) {
|
|
91
|
-
// if (module[key] === oldInstance)
|
|
92
|
-
// module[key] = newModule
|
|
93
|
-
// }
|
|
94
|
-
// })
|
|
95
|
-
// }
|
|
96
|
-
// }
|
|
97
|
-
// async del(modelOrTag: Construct | PropertyKey) {
|
|
98
|
-
// const tag = typeof modelOrTag === 'function' ? getTag(modelOrTag) : modelOrTag
|
|
99
|
-
// if (!this.moduleMap.has(tag))
|
|
100
|
-
// return
|
|
101
|
-
// const module = this.moduleMap.get(tag)
|
|
102
|
-
// debug(`unmount module "${String(tag)}"`)
|
|
103
|
-
// await invokeUnmount(module)
|
|
104
|
-
// debug(`del module "${String(tag)}"`)
|
|
105
|
-
// this.moduleMap.delete(tag)
|
|
106
|
-
// this.modelMap.delete(module)
|
|
107
|
-
// for (let i = this.meta.length - 1; i >= 0; i--) {
|
|
108
|
-
// if (this.meta[i].data.tag === tag)
|
|
109
|
-
// this.meta.splice(i, 1)
|
|
110
|
-
// }
|
|
111
|
-
// return module
|
|
112
|
-
// }
|
|
113
86
|
async destroy() {
|
|
114
87
|
debug("destroy all");
|
|
115
88
|
this.replace(Object.values(this.modelMap), []);
|
|
@@ -231,6 +204,9 @@ var ServerPhecda = class {
|
|
|
231
204
|
if (!this.has(tag)) throw new Error(`module "${tag.toString()}" doesn't exist`);
|
|
232
205
|
return this.moduleMap.get(tag);
|
|
233
206
|
}
|
|
207
|
+
getModel(tag) {
|
|
208
|
+
return this.modelMap.get(this.get(tag));
|
|
209
|
+
}
|
|
234
210
|
};
|
|
235
211
|
async function Factory(models, opts = {}) {
|
|
236
212
|
const phecda = new ServerPhecda(opts);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk4LLLQOMFjs = require('./chunk-4LLLQOMF.js');
|
|
4
4
|
|
|
5
5
|
// src/decorators/param.ts
|
|
6
6
|
var _phecdacore = require('phecda-core');
|
|
@@ -10,42 +10,56 @@ function BaseParam(data) {
|
|
|
10
10
|
_phecdacore.setMeta.call(void 0, target, property, index, data);
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
_chunk4LLLQOMFjs.__name.call(void 0, BaseParam, "BaseParam");
|
|
14
14
|
function Body(key = "") {
|
|
15
15
|
return BaseParam({
|
|
16
16
|
type: "body",
|
|
17
17
|
key
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Body, "Body");
|
|
21
21
|
function Head(key) {
|
|
22
22
|
return BaseParam({
|
|
23
23
|
type: "headers",
|
|
24
24
|
key: key.toLowerCase()
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Head, "Head");
|
|
28
28
|
function Query(key = "") {
|
|
29
29
|
return BaseParam({
|
|
30
30
|
type: "query",
|
|
31
31
|
key
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Query, "Query");
|
|
35
35
|
function Param(key) {
|
|
36
36
|
return BaseParam({
|
|
37
37
|
type: "params",
|
|
38
38
|
key
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Param, "Param");
|
|
42
42
|
function Arg(target, k, index) {
|
|
43
43
|
BaseParam({
|
|
44
44
|
type: "args",
|
|
45
45
|
key: `${index}`
|
|
46
46
|
})(target, k, index);
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Arg, "Arg");
|
|
49
|
+
function OneFile(key = "") {
|
|
50
|
+
return BaseParam({
|
|
51
|
+
type: "file",
|
|
52
|
+
key
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
_chunk4LLLQOMFjs.__name.call(void 0, OneFile, "OneFile");
|
|
56
|
+
function ManyFiles(key = "") {
|
|
57
|
+
return BaseParam({
|
|
58
|
+
type: "files",
|
|
59
|
+
key
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
_chunk4LLLQOMFjs.__name.call(void 0, ManyFiles, "ManyFiles");
|
|
49
63
|
|
|
50
64
|
// src/decorators/aop.ts
|
|
51
65
|
|
|
@@ -56,7 +70,7 @@ function Guard(...guards) {
|
|
|
56
70
|
});
|
|
57
71
|
};
|
|
58
72
|
}
|
|
59
|
-
|
|
73
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Guard, "Guard");
|
|
60
74
|
function Addon(...addons) {
|
|
61
75
|
return (target, property) => {
|
|
62
76
|
_phecdacore.setMeta.call(void 0, target, property, void 0, {
|
|
@@ -64,7 +78,7 @@ function Addon(...addons) {
|
|
|
64
78
|
});
|
|
65
79
|
};
|
|
66
80
|
}
|
|
67
|
-
|
|
81
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Addon, "Addon");
|
|
68
82
|
function Filter(filter) {
|
|
69
83
|
return (target, property) => {
|
|
70
84
|
_phecdacore.setMeta.call(void 0, target, property, void 0, {
|
|
@@ -72,7 +86,7 @@ function Filter(filter) {
|
|
|
72
86
|
});
|
|
73
87
|
};
|
|
74
88
|
}
|
|
75
|
-
|
|
89
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Filter, "Filter");
|
|
76
90
|
function Pipe(pipe) {
|
|
77
91
|
return (target, property, index) => {
|
|
78
92
|
if (typeof index === "number") {
|
|
@@ -86,7 +100,7 @@ function Pipe(pipe) {
|
|
|
86
100
|
});
|
|
87
101
|
};
|
|
88
102
|
}
|
|
89
|
-
|
|
103
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Pipe, "Pipe");
|
|
90
104
|
|
|
91
105
|
// src/decorators/http.ts
|
|
92
106
|
|
|
@@ -100,7 +114,7 @@ function Route(route, type) {
|
|
|
100
114
|
});
|
|
101
115
|
};
|
|
102
116
|
}
|
|
103
|
-
|
|
117
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Route, "Route");
|
|
104
118
|
function Header(headers) {
|
|
105
119
|
return (target, property) => {
|
|
106
120
|
_phecdacore.setMeta.call(void 0, target, property, void 0, {
|
|
@@ -110,31 +124,31 @@ function Header(headers) {
|
|
|
110
124
|
});
|
|
111
125
|
};
|
|
112
126
|
}
|
|
113
|
-
|
|
127
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Header, "Header");
|
|
114
128
|
function Get(route = "") {
|
|
115
129
|
return Route(route, "get");
|
|
116
130
|
}
|
|
117
|
-
|
|
131
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Get, "Get");
|
|
118
132
|
function Post(route = "") {
|
|
119
133
|
return Route(route, "post");
|
|
120
134
|
}
|
|
121
|
-
|
|
135
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Post, "Post");
|
|
122
136
|
function Put(route = "") {
|
|
123
137
|
return Route(route, "put");
|
|
124
138
|
}
|
|
125
|
-
|
|
139
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Put, "Put");
|
|
126
140
|
function Search(route = "") {
|
|
127
141
|
return Route(route, "search");
|
|
128
142
|
}
|
|
129
|
-
|
|
143
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Search, "Search");
|
|
130
144
|
function Patch(route = "") {
|
|
131
145
|
return Route(route, "patch");
|
|
132
146
|
}
|
|
133
|
-
|
|
147
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Patch, "Patch");
|
|
134
148
|
function Delete(route = "") {
|
|
135
149
|
return Route(route, "delete");
|
|
136
150
|
}
|
|
137
|
-
|
|
151
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Delete, "Delete");
|
|
138
152
|
function Controller(prefix = "") {
|
|
139
153
|
return (target) => {
|
|
140
154
|
_phecdacore.setMeta.call(void 0, target, void 0, void 0, {
|
|
@@ -145,7 +159,7 @@ function Controller(prefix = "") {
|
|
|
145
159
|
});
|
|
146
160
|
};
|
|
147
161
|
}
|
|
148
|
-
|
|
162
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Controller, "Controller");
|
|
149
163
|
|
|
150
164
|
// src/decorators/rpc.ts
|
|
151
165
|
|
|
@@ -159,7 +173,7 @@ function Queue(queue = "", isEvent) {
|
|
|
159
173
|
});
|
|
160
174
|
};
|
|
161
175
|
}
|
|
162
|
-
|
|
176
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Queue, "Queue");
|
|
163
177
|
function Rpc() {
|
|
164
178
|
return (target) => {
|
|
165
179
|
_phecdacore.setMeta.call(void 0, target, void 0, void 0, {
|
|
@@ -167,11 +181,11 @@ function Rpc() {
|
|
|
167
181
|
});
|
|
168
182
|
};
|
|
169
183
|
}
|
|
170
|
-
|
|
184
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Rpc, "Rpc");
|
|
171
185
|
|
|
172
186
|
// src/decorators/ctx.ts
|
|
173
187
|
|
|
174
|
-
var Ctx = /* @__PURE__ */
|
|
188
|
+
var Ctx = /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (target, property) => {
|
|
175
189
|
_phecdacore.setMeta.call(void 0, target, _phecdacore.SHARE_KEY, void 0, {
|
|
176
190
|
ctxs: [
|
|
177
191
|
property
|
|
@@ -200,7 +214,21 @@ function Define(key, value) {
|
|
|
200
214
|
}
|
|
201
215
|
};
|
|
202
216
|
}
|
|
203
|
-
|
|
217
|
+
_chunk4LLLQOMFjs.__name.call(void 0, Define, "Define");
|
|
218
|
+
|
|
219
|
+
// src/decorators/openapi.ts
|
|
220
|
+
|
|
221
|
+
function ApiDoc(config) {
|
|
222
|
+
return function(target, propertyKey, _descriptor) {
|
|
223
|
+
_phecdacore.setMeta.call(void 0, target, propertyKey, void 0, {
|
|
224
|
+
openapi: config
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
_chunk4LLLQOMFjs.__name.call(void 0, ApiDoc, "ApiDoc");
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
204
232
|
|
|
205
233
|
|
|
206
234
|
|
|
@@ -226,4 +254,4 @@ _chunk5RBTN33Ajs.__name.call(void 0, Define, "Define");
|
|
|
226
254
|
|
|
227
255
|
|
|
228
256
|
|
|
229
|
-
exports.BaseParam = BaseParam; exports.Body = Body; exports.Head = Head; exports.Query = Query; exports.Param = Param; exports.Arg = Arg; exports.Guard = Guard; exports.Addon = Addon; exports.Filter = Filter; exports.Pipe = Pipe; exports.Route = Route; exports.Header = Header; exports.Get = Get; exports.Post = Post; exports.Put = Put; exports.Search = Search; exports.Patch = Patch; exports.Delete = Delete; exports.Controller = Controller; exports.Queue = Queue; exports.Rpc = Rpc; exports.Ctx = Ctx; exports.Define = Define;
|
|
257
|
+
exports.BaseParam = BaseParam; exports.Body = Body; exports.Head = Head; exports.Query = Query; exports.Param = Param; exports.Arg = Arg; exports.OneFile = OneFile; exports.ManyFiles = ManyFiles; exports.Guard = Guard; exports.Addon = Addon; exports.Filter = Filter; exports.Pipe = Pipe; exports.Route = Route; exports.Header = Header; exports.Get = Get; exports.Post = Post; exports.Put = Put; exports.Search = Search; exports.Patch = Patch; exports.Delete = Delete; exports.Controller = Controller; exports.Queue = Queue; exports.Rpc = Rpc; exports.Ctx = Ctx; exports.Define = Define; exports.ApiDoc = ApiDoc;
|
|
@@ -2,11 +2,12 @@ import {
|
|
|
2
2
|
ERROR_SYMBOL,
|
|
3
3
|
HMR,
|
|
4
4
|
IS_DEV,
|
|
5
|
+
IS_PURE,
|
|
5
6
|
IS_STRICT,
|
|
6
7
|
LOG_LEVEL,
|
|
7
8
|
__name,
|
|
8
9
|
log
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-NQ55PA2X.mjs";
|
|
10
11
|
|
|
11
12
|
// src/helper.ts
|
|
12
13
|
import pc2 from "picocolors";
|
|
@@ -232,16 +233,13 @@ var Context = class _Context {
|
|
|
232
233
|
static guardRecord = {};
|
|
233
234
|
static addonRecord = {};
|
|
234
235
|
ctx;
|
|
235
|
-
canGetCtx
|
|
236
|
+
// protected canGetCtx = true
|
|
236
237
|
constructor(data) {
|
|
237
238
|
this.data = data;
|
|
238
|
-
this.canGetCtx = true;
|
|
239
239
|
if (IS_DEV)
|
|
240
240
|
data._context = this;
|
|
241
|
-
const that = this;
|
|
242
241
|
this.ctx = new Proxy(data, {
|
|
243
242
|
get(target, p) {
|
|
244
|
-
if (IS_DEV && !that.canGetCtx) throw new FrameworkException("ctx must be obtained within the same request cycle in controller");
|
|
245
243
|
if (!(p in target)) log(`attribute "${p}" does not exist on ctx, which might be due to a missing AOP role (such as a guard).`, "warn", data.tag);
|
|
246
244
|
return target[p];
|
|
247
245
|
},
|
|
@@ -292,13 +290,7 @@ ${pc.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
|
292
290
|
reflect: paramsType[item.index],
|
|
293
291
|
...item
|
|
294
292
|
}, this.ctx)));
|
|
295
|
-
if (IS_DEV) {
|
|
296
|
-
Promise.resolve().then(() => {
|
|
297
|
-
this.canGetCtx = false;
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
293
|
res = await instance[func](...args);
|
|
301
|
-
this.canGetCtx = true;
|
|
302
294
|
} else {
|
|
303
295
|
let nextPromise;
|
|
304
296
|
async function next() {
|
|
@@ -385,13 +377,6 @@ function resolveDep(ret, key) {
|
|
|
385
377
|
}
|
|
386
378
|
__name(resolveDep, "resolveDep");
|
|
387
379
|
|
|
388
|
-
// src/rpc/helper.ts
|
|
389
|
-
import { hostname } from "os";
|
|
390
|
-
function genClientQueue(key) {
|
|
391
|
-
return `PS-${key ? `${key}-` : ""}${hostname()}-${process.pid}`;
|
|
392
|
-
}
|
|
393
|
-
__name(genClientQueue, "genClientQueue");
|
|
394
|
-
|
|
395
380
|
// src/decorators/helper.ts
|
|
396
381
|
function shallowClone(obj) {
|
|
397
382
|
return {
|
|
@@ -425,6 +410,7 @@ function createControllerMetaMap(meta, filter) {
|
|
|
425
410
|
}
|
|
426
411
|
__name(createControllerMetaMap, "createControllerMetaMap");
|
|
427
412
|
function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
413
|
+
if (IS_PURE) return;
|
|
428
414
|
const addonSet = /* @__PURE__ */ new Set();
|
|
429
415
|
const guardSet = /* @__PURE__ */ new Set();
|
|
430
416
|
const pipeSet = /* @__PURE__ */ new Set();
|
|
@@ -443,6 +429,8 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
443
429
|
guardSet.add(item);
|
|
444
430
|
});
|
|
445
431
|
meta.forEach(({ data }) => {
|
|
432
|
+
if (!data.controller) return;
|
|
433
|
+
if (typeof data.tag !== "string") warningSet.add(`Tag of controller "${data.name}" should be a string`);
|
|
446
434
|
if (data.controller !== controller) {
|
|
447
435
|
if (data[controller]) warningSet.add(`Should use ${controller} controller to decorate class "${data.name}"`);
|
|
448
436
|
return;
|
|
@@ -467,7 +455,10 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
467
455
|
...filterSet
|
|
468
456
|
].filter((i) => !Context.filterRecord[i]);
|
|
469
457
|
function exit() {
|
|
470
|
-
if (IS_STRICT)
|
|
458
|
+
if (IS_STRICT) {
|
|
459
|
+
log("Does not meet strict mode requirements", "error");
|
|
460
|
+
process.exit(1);
|
|
461
|
+
}
|
|
471
462
|
}
|
|
472
463
|
__name(exit, "exit");
|
|
473
464
|
if (missAddons.length) {
|
|
@@ -534,7 +525,6 @@ export {
|
|
|
534
525
|
addGuard,
|
|
535
526
|
addAddon,
|
|
536
527
|
resolveDep,
|
|
537
|
-
genClientQueue,
|
|
538
528
|
shallowClone,
|
|
539
529
|
mergeObject,
|
|
540
530
|
createControllerMetaMap,
|