phecda-server 5.1.1 → 5.2.0
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/ps.json +25 -0
- package/assets/tsconfig.json +21 -0
- package/bin/cli.mjs +41 -80
- package/dist/{chunk-HMPTPTFL.js → chunk-5BVUCNMA.js} +2 -2
- package/dist/{chunk-FSBD5R22.js → chunk-BSE2DSDK.js} +64 -66
- package/dist/{chunk-2HKQPZDT.mjs → chunk-CKQW3FDK.mjs} +3 -3
- package/dist/{chunk-665MB62T.mjs → chunk-JE6BBDXW.mjs} +63 -65
- package/dist/{chunk-UU6RHGRF.mjs → chunk-V3WIKOP3.mjs} +10 -4
- package/dist/{chunk-3BV2GRS7.js → chunk-VMLHTEW3.js} +22 -16
- package/dist/core-7f6d2be6.d.ts +27 -0
- package/dist/{helper-fcbf6aa8.d.ts → helper-49c7213c.d.ts} +1 -1
- package/dist/{helper-6133f78f.d.ts → helper-5d755442.d.ts} +1 -1
- package/dist/helper.d.ts +25 -0
- package/dist/helper.js +21 -0
- package/dist/helper.mjs +21 -0
- package/dist/index.d.ts +5 -25
- package/dist/index.js +24 -42
- package/dist/index.mjs +5 -23
- package/dist/rpc/bullmq/index.d.ts +3 -2
- package/dist/rpc/bullmq/index.js +6 -6
- package/dist/rpc/bullmq/index.mjs +1 -1
- package/dist/rpc/kafka/index.d.ts +3 -2
- package/dist/rpc/kafka/index.js +5 -5
- package/dist/rpc/kafka/index.mjs +1 -1
- package/dist/rpc/nats/index.d.ts +3 -2
- package/dist/rpc/nats/index.js +5 -5
- package/dist/rpc/nats/index.mjs +1 -1
- package/dist/rpc/rabbitmq/index.d.ts +3 -2
- package/dist/rpc/rabbitmq/index.js +6 -6
- package/dist/rpc/rabbitmq/index.mjs +1 -1
- package/dist/rpc/redis/index.d.ts +3 -2
- package/dist/rpc/redis/index.js +6 -6
- package/dist/rpc/redis/index.mjs +1 -1
- package/dist/server/elysia/index.d.ts +3 -2
- package/dist/server/elysia/index.js +15 -15
- package/dist/server/elysia/index.mjs +2 -2
- package/dist/server/express/index.d.ts +3 -2
- package/dist/server/express/index.js +14 -14
- package/dist/server/express/index.mjs +1 -1
- package/dist/server/fastify/index.d.ts +3 -2
- package/dist/server/fastify/index.js +15 -15
- package/dist/server/fastify/index.mjs +2 -2
- package/dist/server/h3/index.d.ts +3 -2
- package/dist/server/h3/index.js +12 -12
- package/dist/server/h3/index.mjs +1 -1
- package/dist/server/hono/index.d.ts +3 -2
- package/dist/server/hono/index.js +13 -13
- package/dist/server/hono/index.mjs +1 -1
- package/dist/server/hyper-express/index.d.ts +3 -2
- package/dist/server/hyper-express/index.js +13 -13
- package/dist/server/hyper-express/index.mjs +1 -1
- package/dist/server/koa/index.d.ts +3 -2
- package/dist/server/koa/index.js +14 -14
- package/dist/server/koa/index.mjs +1 -1
- package/dist/test.d.ts +2 -1
- package/dist/test.js +2 -2
- package/dist/test.mjs +1 -1
- package/dist/{core-39f27fe8.d.ts → types-81be0ba3.d.ts} +2 -25
- package/package.json +61 -53
- package/register/loader.mjs +26 -13
- package/register/utils.mjs +6 -31
- /package/{bin → assets}/schema.json +0 -0
package/assets/ps.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://unpkg.com/phecda-server/bin/schema.json",
|
|
3
|
+
"resolve": [
|
|
4
|
+
{
|
|
5
|
+
"source": "controller",
|
|
6
|
+
"importer": "http",
|
|
7
|
+
"path": ".ps/http.js"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"source": "rpc",
|
|
11
|
+
"importer": "client",
|
|
12
|
+
"path": ".ps/rpc.js"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"unimport": {
|
|
16
|
+
"dirs": ["."],
|
|
17
|
+
"dirsScanOptions":{
|
|
18
|
+
"filePatterns":["*.{service,controller,module,rpc,edge,guard,interceptor,extension,pipe,filter,plugin}.ts"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"virtualFile":{},
|
|
22
|
+
"moduleFile": []
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"useDefineForClassFields": false,
|
|
5
|
+
"experimentalDecorators": true,
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"module": "esnext",
|
|
8
|
+
"lib": ["esnext", "DOM"],
|
|
9
|
+
"strictPropertyInitialization": false,
|
|
10
|
+
"moduleResolution": "Node",
|
|
11
|
+
"strict": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"noImplicitReturns": true,
|
|
18
|
+
"skipLibCheck": true
|
|
19
|
+
},
|
|
20
|
+
"include": [".","./ps.d.ts"]
|
|
21
|
+
}
|
package/bin/cli.mjs
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
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, join, resolve } from 'path'
|
|
4
7
|
import pc from 'picocolors'
|
|
5
8
|
import cac from 'cac'
|
|
6
9
|
import fse from 'fs-extra'
|
|
7
10
|
import { log } from '../dist/index.mjs'
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
const cli = cac('phecda')
|
|
13
|
+
.option('-c,--config <config>', 'config file', {
|
|
14
|
+
default: 'ps.json',
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
18
|
+
|
|
11
19
|
const require = createRequire(import.meta.url)
|
|
12
20
|
let child
|
|
13
21
|
|
|
@@ -66,75 +74,36 @@ process.on('SIGINT', () => {
|
|
|
66
74
|
process.exit()
|
|
67
75
|
})
|
|
68
76
|
|
|
69
|
-
cli
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"useDefineForClassFields": false,
|
|
79
|
-
"experimentalDecorators": true,
|
|
80
|
-
"emitDecoratorMetadata": true,
|
|
81
|
-
"module": "esnext",
|
|
82
|
-
"lib": ["esnext", "DOM"],
|
|
83
|
-
"strictPropertyInitialization": false,
|
|
84
|
-
"moduleResolution": "Node",
|
|
85
|
-
"strict": true,
|
|
86
|
-
"resolveJsonModule": true,
|
|
87
|
-
"esModuleInterop": true,
|
|
88
|
-
"noEmit": true,
|
|
89
|
-
"noUnusedLocals": true,
|
|
90
|
-
"noUnusedParameters": true,
|
|
91
|
-
"noImplicitReturns": true,
|
|
92
|
-
"skipLibCheck": true
|
|
93
|
-
},
|
|
94
|
-
"include": ["src","./ps.d.ts"]
|
|
95
|
-
}
|
|
96
|
-
`,
|
|
97
|
-
)
|
|
98
|
-
}
|
|
77
|
+
cli
|
|
78
|
+
.command('init [workdir]', 'init config file')
|
|
79
|
+
.allowUnknownOptions()
|
|
80
|
+
.option('-t,--tsconfig <tsconfig>', 'init tsconfig file', {
|
|
81
|
+
default: 'tsconfig.json',
|
|
82
|
+
})
|
|
83
|
+
.action(async (workdir, options) => {
|
|
84
|
+
const tsconfigPath = join(workdir, options.tsconfig)
|
|
85
|
+
const psconfigPath = join(workdir, options.config)
|
|
99
86
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
options.config,
|
|
105
|
-
`{
|
|
106
|
-
"$schema": "node_modules/phecda-server/bin/schema.json",
|
|
107
|
-
"resolve": [
|
|
108
|
-
{
|
|
109
|
-
"source": "controller",
|
|
110
|
-
"importer": "http",
|
|
111
|
-
"path": ".ps/http.js"
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
"source": "rpc",
|
|
115
|
-
"importer": "client",
|
|
116
|
-
"path": ".ps/rpc.js"
|
|
117
|
-
}
|
|
118
|
-
],
|
|
119
|
-
"unimport": {
|
|
120
|
-
"dirs": [],
|
|
121
|
-
"dirsScanOptions":{
|
|
122
|
-
"filePatterns":["*.{service,controller,module,rpc,edge,guard,interceptor,extension,pipe,filter,plugin}.ts"]
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
"virtualFile":{},
|
|
126
|
-
"moduleFile": []
|
|
127
|
-
|
|
87
|
+
if (!fse.existsSync(tsconfigPath)) {
|
|
88
|
+
log(`create ${tsconfigPath}`)
|
|
89
|
+
|
|
90
|
+
await fse.copyFile(resolve(__dirname, '../assets/tsconfig.json'), tsconfigPath)
|
|
128
91
|
}
|
|
129
|
-
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
|
|
92
|
+
|
|
93
|
+
if (!fse.existsSync(psconfigPath)) {
|
|
94
|
+
log(`create ${psconfigPath}`)
|
|
95
|
+
|
|
96
|
+
await fse.copyFile(resolve(__dirname, '../assets/ps.json'), psconfigPath)
|
|
97
|
+
}
|
|
98
|
+
})
|
|
133
99
|
|
|
134
100
|
cli
|
|
135
|
-
.command('[
|
|
101
|
+
.command('<file> [workdir]', 'run file')
|
|
102
|
+
.allowUnknownOptions()
|
|
136
103
|
.alias('run')
|
|
137
|
-
.action((file, options) => {
|
|
104
|
+
.action((file, workdir, options) => {
|
|
105
|
+
if (workdir)
|
|
106
|
+
process.env.PS_WORKDIR = workdir
|
|
138
107
|
process.env.PS_CONFIG_FILE = options.config
|
|
139
108
|
|
|
140
109
|
log('process start!')
|
|
@@ -165,23 +134,15 @@ cli
|
|
|
165
134
|
})
|
|
166
135
|
|
|
167
136
|
cli
|
|
168
|
-
.command('generate [
|
|
169
|
-
.
|
|
137
|
+
.command('generate <file> [workdir]', 'generate code(mainly for ci)')
|
|
138
|
+
.allowUnknownOptions()
|
|
139
|
+
.action((file, workdir, options) => {
|
|
140
|
+
if (workdir)
|
|
141
|
+
process.env.PS_WORKDIR = workdir
|
|
170
142
|
process.env.PS_GENERATE = 'true'
|
|
171
143
|
process.env.PS_CONFIG_FILE = options.config
|
|
172
144
|
startChild(file, options['--'])
|
|
173
145
|
})
|
|
174
|
-
// if (cmd[0] === 'init') {
|
|
175
|
-
|
|
176
|
-
// }
|
|
177
|
-
// else if (cmd[0] === 'code') {
|
|
178
|
-
// process.env.PS_GENERATE = 'true'
|
|
179
|
-
// cmd.splice(0, 1)
|
|
180
|
-
// startChild(file,options['--'])
|
|
181
|
-
// }
|
|
182
|
-
// else {
|
|
183
|
-
|
|
184
|
-
// }
|
|
185
146
|
|
|
186
147
|
cli.help()
|
|
187
148
|
cli.version(require('../package.json').version)
|
|
@@ -171,7 +171,7 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
171
171
|
const vars = _phecdacore.getExposeKey.call(void 0, instance).filter((item) => typeof item === "string");
|
|
172
172
|
const baseState = _phecdacore.getState.call(void 0, instance);
|
|
173
173
|
initState(baseState);
|
|
174
|
-
const
|
|
174
|
+
const ctxs = _phecdacore.getState.call(void 0, instance).ctxs;
|
|
175
175
|
return vars.filter((i) => typeof instance[i] === "function").map((i) => {
|
|
176
176
|
const state = _phecdacore.getState.call(void 0, instance, i);
|
|
177
177
|
const meta = {
|
|
@@ -184,7 +184,6 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
184
184
|
if (typeof tag !== "string")
|
|
185
185
|
_chunkZP7HNASUjs.log.call(void 0, `can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
|
|
186
186
|
initState(state);
|
|
187
|
-
meta.ctx = ctx;
|
|
188
187
|
meta.controller = baseState.controller;
|
|
189
188
|
meta[baseState.controller] = {
|
|
190
189
|
...baseState[baseState.controller],
|
|
@@ -200,6 +199,7 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
200
199
|
if (i2.index === 0)
|
|
201
200
|
break;
|
|
202
201
|
}
|
|
202
|
+
meta.ctxs = ctxs;
|
|
203
203
|
meta.params = params;
|
|
204
204
|
meta.filter = state.filter || baseState.filter;
|
|
205
205
|
meta.define = {
|
|
@@ -8,6 +8,15 @@
|
|
|
8
8
|
|
|
9
9
|
var _chunkZP7HNASUjs = require('./chunk-ZP7HNASU.js');
|
|
10
10
|
|
|
11
|
+
// src/helper.ts
|
|
12
|
+
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
13
|
+
|
|
14
|
+
// src/context.ts
|
|
15
|
+
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
16
|
+
|
|
17
|
+
// src/pipe.ts
|
|
18
|
+
var _phecdacore = require('phecda-core');
|
|
19
|
+
|
|
11
20
|
// src/exception/base.ts
|
|
12
21
|
var Exception = class extends Error {
|
|
13
22
|
|
|
@@ -39,7 +48,6 @@ var ValidateException = class extends Exception {
|
|
|
39
48
|
_chunkZP7HNASUjs.__name.call(void 0, ValidateException, "ValidateException");
|
|
40
49
|
|
|
41
50
|
// src/pipe.ts
|
|
42
|
-
var _phecdacore = require('phecda-core');
|
|
43
51
|
var defaultPipe = /* @__PURE__ */ _chunkZP7HNASUjs.__name.call(void 0, ({ arg, reflect, index }) => {
|
|
44
52
|
if (_phecdacore.isPhecda.call(void 0, reflect)) {
|
|
45
53
|
const instance = _phecdacore.plainToClass.call(void 0, reflect, arg);
|
|
@@ -182,66 +190,6 @@ var WorkerException = class extends Exception {
|
|
|
182
190
|
};
|
|
183
191
|
_chunkZP7HNASUjs.__name.call(void 0, WorkerException, "WorkerException");
|
|
184
192
|
|
|
185
|
-
// src/hmr.ts
|
|
186
|
-
function HMR(cb) {
|
|
187
|
-
if (_chunkZP7HNASUjs.IS_HMR)
|
|
188
|
-
_optionalChain([globalThis, 'access', _ => _.__PS_HMR__, 'optionalAccess', _2 => _2.push, 'call', _3 => _3(cb)]);
|
|
189
|
-
}
|
|
190
|
-
_chunkZP7HNASUjs.__name.call(void 0, HMR, "HMR");
|
|
191
|
-
|
|
192
|
-
// src/server/helper.ts
|
|
193
|
-
function resolveDep(ret, key) {
|
|
194
|
-
if (key)
|
|
195
|
-
return _optionalChain([ret, 'optionalAccess', _4 => _4[key]]);
|
|
196
|
-
return ret;
|
|
197
|
-
}
|
|
198
|
-
_chunkZP7HNASUjs.__name.call(void 0, resolveDep, "resolveDep");
|
|
199
|
-
function argToReq(params, args, headers) {
|
|
200
|
-
const req = {
|
|
201
|
-
body: {},
|
|
202
|
-
query: {},
|
|
203
|
-
params: {},
|
|
204
|
-
headers
|
|
205
|
-
};
|
|
206
|
-
params.forEach((param) => {
|
|
207
|
-
if (param.key)
|
|
208
|
-
req[param.type][param.key] = args[param.index];
|
|
209
|
-
else
|
|
210
|
-
req[param.type] = args[param.index];
|
|
211
|
-
});
|
|
212
|
-
return req;
|
|
213
|
-
}
|
|
214
|
-
_chunkZP7HNASUjs.__name.call(void 0, argToReq, "argToReq");
|
|
215
|
-
|
|
216
|
-
// src/rpc/helper.ts
|
|
217
|
-
var _os = require('os');
|
|
218
|
-
function genClientQueue(key) {
|
|
219
|
-
return `PS-${key ? `${key}-` : ""}${_os.hostname.call(void 0, )}-${process.pid}`;
|
|
220
|
-
}
|
|
221
|
-
_chunkZP7HNASUjs.__name.call(void 0, genClientQueue, "genClientQueue");
|
|
222
|
-
|
|
223
|
-
// src/decorators/helper.ts
|
|
224
|
-
function shallowClone(obj) {
|
|
225
|
-
return {
|
|
226
|
-
...obj
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
_chunkZP7HNASUjs.__name.call(void 0, shallowClone, "shallowClone");
|
|
230
|
-
function mergeObject(...args) {
|
|
231
|
-
return Object.assign({}, ...args);
|
|
232
|
-
}
|
|
233
|
-
_chunkZP7HNASUjs.__name.call(void 0, mergeObject, "mergeObject");
|
|
234
|
-
function mergeArray(...args) {
|
|
235
|
-
return args.filter((item) => !!item).flat();
|
|
236
|
-
}
|
|
237
|
-
_chunkZP7HNASUjs.__name.call(void 0, mergeArray, "mergeArray");
|
|
238
|
-
|
|
239
|
-
// src/helper.ts
|
|
240
|
-
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
241
|
-
|
|
242
|
-
// src/context.ts
|
|
243
|
-
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
244
|
-
|
|
245
193
|
// src/filter.ts
|
|
246
194
|
var defaultFilter = /* @__PURE__ */ _chunkZP7HNASUjs.__name.call(void 0, (e) => {
|
|
247
195
|
if (!(e instanceof Exception)) {
|
|
@@ -272,7 +220,7 @@ var _Context = class {
|
|
|
272
220
|
async run(opts, successCb, failCb) {
|
|
273
221
|
const { meta, moduleMap } = this.data;
|
|
274
222
|
const { globalGuards = [], globalFilter, globalInterceptors = [], globalPipe } = opts;
|
|
275
|
-
const { paramsType, data: { guards, interceptors, params, tag, func,
|
|
223
|
+
const { paramsType, data: { guards, interceptors, params, tag, func, ctxs, filter } } = meta;
|
|
276
224
|
try {
|
|
277
225
|
await this.useGuard([
|
|
278
226
|
...globalGuards,
|
|
@@ -293,8 +241,9 @@ var _Context = class {
|
|
|
293
241
|
};
|
|
294
242
|
}));
|
|
295
243
|
const instance = moduleMap.get(tag);
|
|
296
|
-
if (
|
|
297
|
-
instance[ctx] = this.data;
|
|
244
|
+
if (ctxs) {
|
|
245
|
+
ctxs.forEach((ctx) => instance[ctx] = this.data);
|
|
246
|
+
}
|
|
298
247
|
const returnData = await instance[func](...args);
|
|
299
248
|
const i2 = await this.usePostInterceptor(returnData);
|
|
300
249
|
if (i2 !== void 0)
|
|
@@ -425,6 +374,56 @@ function addInterceptor(key, handler) {
|
|
|
425
374
|
}
|
|
426
375
|
_chunkZP7HNASUjs.__name.call(void 0, addInterceptor, "addInterceptor");
|
|
427
376
|
|
|
377
|
+
// src/hmr.ts
|
|
378
|
+
function HMR(cb) {
|
|
379
|
+
if (_chunkZP7HNASUjs.IS_HMR)
|
|
380
|
+
_optionalChain([globalThis, 'access', _ => _.__PS_HMR__, 'optionalAccess', _2 => _2.push, 'call', _3 => _3(cb)]);
|
|
381
|
+
}
|
|
382
|
+
_chunkZP7HNASUjs.__name.call(void 0, HMR, "HMR");
|
|
383
|
+
|
|
384
|
+
// src/server/helper.ts
|
|
385
|
+
function resolveDep(ret, key) {
|
|
386
|
+
if (key)
|
|
387
|
+
return _optionalChain([ret, 'optionalAccess', _4 => _4[key]]);
|
|
388
|
+
return ret;
|
|
389
|
+
}
|
|
390
|
+
_chunkZP7HNASUjs.__name.call(void 0, resolveDep, "resolveDep");
|
|
391
|
+
function argToReq(params, args, headers) {
|
|
392
|
+
const req = {
|
|
393
|
+
body: {},
|
|
394
|
+
query: {},
|
|
395
|
+
params: {},
|
|
396
|
+
headers
|
|
397
|
+
};
|
|
398
|
+
params.forEach((param) => {
|
|
399
|
+
if (param.key)
|
|
400
|
+
req[param.type][param.key] = args[param.index];
|
|
401
|
+
else
|
|
402
|
+
req[param.type] = args[param.index];
|
|
403
|
+
});
|
|
404
|
+
return req;
|
|
405
|
+
}
|
|
406
|
+
_chunkZP7HNASUjs.__name.call(void 0, argToReq, "argToReq");
|
|
407
|
+
|
|
408
|
+
// src/rpc/helper.ts
|
|
409
|
+
var _os = require('os');
|
|
410
|
+
function genClientQueue(key) {
|
|
411
|
+
return `PS-${key ? `${key}-` : ""}${_os.hostname.call(void 0, )}-${process.pid}`;
|
|
412
|
+
}
|
|
413
|
+
_chunkZP7HNASUjs.__name.call(void 0, genClientQueue, "genClientQueue");
|
|
414
|
+
|
|
415
|
+
// src/decorators/helper.ts
|
|
416
|
+
function shallowClone(obj) {
|
|
417
|
+
return {
|
|
418
|
+
...obj
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
_chunkZP7HNASUjs.__name.call(void 0, shallowClone, "shallowClone");
|
|
422
|
+
function mergeObject(...args) {
|
|
423
|
+
return Object.assign({}, ...args);
|
|
424
|
+
}
|
|
425
|
+
_chunkZP7HNASUjs.__name.call(void 0, mergeObject, "mergeObject");
|
|
426
|
+
|
|
428
427
|
// src/helper.ts
|
|
429
428
|
function createControllerMetaMap(meta, filter) {
|
|
430
429
|
const metaMap = /* @__PURE__ */ new Map();
|
|
@@ -560,5 +559,4 @@ _chunkZP7HNASUjs.__name.call(void 0, detectAopDep, "detectAopDep");
|
|
|
560
559
|
|
|
561
560
|
|
|
562
561
|
|
|
563
|
-
|
|
564
|
-
exports.Exception = Exception; exports.ValidateException = ValidateException; exports.defaultPipe = defaultPipe; exports.UndefinedException = UndefinedException; exports.ForbiddenException = ForbiddenException; exports.BadRequestException = BadRequestException; exports.NotFoundException = NotFoundException; exports.ConflictException = ConflictException; exports.BadGatewayException = BadGatewayException; exports.InvalidInputException = InvalidInputException; exports.UnsupportedMediaTypeException = UnsupportedMediaTypeException; exports.PayloadLargeException = PayloadLargeException; exports.TimeoutException = TimeoutException; exports.UnauthorizedException = UnauthorizedException; exports.ServiceUnavailableException = ServiceUnavailableException; exports.FrameworkException = FrameworkException; exports.TimerException = TimerException; exports.WorkerException = WorkerException; exports.HMR = HMR; exports.resolveDep = resolveDep; exports.argToReq = argToReq; exports.genClientQueue = genClientQueue; exports.shallowClone = shallowClone; exports.mergeObject = mergeObject; exports.mergeArray = mergeArray; exports.createControllerMetaMap = createControllerMetaMap; exports.detectAopDep = detectAopDep; exports.Context = Context; exports.addPlugin = addPlugin; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addInterceptor = addInterceptor;
|
|
562
|
+
exports.Exception = Exception; exports.ValidateException = ValidateException; exports.defaultPipe = defaultPipe; exports.UndefinedException = UndefinedException; exports.ForbiddenException = ForbiddenException; exports.BadRequestException = BadRequestException; exports.NotFoundException = NotFoundException; exports.ConflictException = ConflictException; exports.BadGatewayException = BadGatewayException; exports.InvalidInputException = InvalidInputException; exports.UnsupportedMediaTypeException = UnsupportedMediaTypeException; exports.PayloadLargeException = PayloadLargeException; exports.TimeoutException = TimeoutException; exports.UnauthorizedException = UnauthorizedException; exports.ServiceUnavailableException = ServiceUnavailableException; exports.FrameworkException = FrameworkException; exports.TimerException = TimerException; exports.WorkerException = WorkerException; exports.HMR = HMR; exports.resolveDep = resolveDep; exports.argToReq = argToReq; exports.genClientQueue = genClientQueue; exports.shallowClone = shallowClone; exports.mergeObject = mergeObject; exports.createControllerMetaMap = createControllerMetaMap; exports.detectAopDep = detectAopDep; exports.Context = Context; exports.addPlugin = addPlugin; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addInterceptor = addInterceptor;
|
|
@@ -19,7 +19,7 @@ __name(Meta, "Meta");
|
|
|
19
19
|
// src/core.ts
|
|
20
20
|
import "reflect-metadata";
|
|
21
21
|
import EventEmitter from "node:events";
|
|
22
|
-
import {
|
|
22
|
+
import { getExposeKey, getInject, getState, getTag, invokeHandler, isPhecda, setInject } from "phecda-core";
|
|
23
23
|
import Debug from "debug";
|
|
24
24
|
var debug = Debug("phecda-server(Factory)");
|
|
25
25
|
var emitter = new EventEmitter();
|
|
@@ -171,7 +171,7 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
171
171
|
const vars = getExposeKey(instance).filter((item) => typeof item === "string");
|
|
172
172
|
const baseState = getState(instance);
|
|
173
173
|
initState(baseState);
|
|
174
|
-
const
|
|
174
|
+
const ctxs = getState(instance).ctxs;
|
|
175
175
|
return vars.filter((i) => typeof instance[i] === "function").map((i) => {
|
|
176
176
|
const state = getState(instance, i);
|
|
177
177
|
const meta = {
|
|
@@ -184,7 +184,6 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
184
184
|
if (typeof tag !== "string")
|
|
185
185
|
log(`can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
|
|
186
186
|
initState(state);
|
|
187
|
-
meta.ctx = ctx;
|
|
188
187
|
meta.controller = baseState.controller;
|
|
189
188
|
meta[baseState.controller] = {
|
|
190
189
|
...baseState[baseState.controller],
|
|
@@ -200,6 +199,7 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
200
199
|
if (i2.index === 0)
|
|
201
200
|
break;
|
|
202
201
|
}
|
|
202
|
+
meta.ctxs = ctxs;
|
|
203
203
|
meta.params = params;
|
|
204
204
|
meta.filter = state.filter || baseState.filter;
|
|
205
205
|
meta.define = {
|
|
@@ -8,6 +8,15 @@ import {
|
|
|
8
8
|
log
|
|
9
9
|
} from "./chunk-VLV3AO3H.mjs";
|
|
10
10
|
|
|
11
|
+
// src/helper.ts
|
|
12
|
+
import pc from "picocolors";
|
|
13
|
+
|
|
14
|
+
// src/context.ts
|
|
15
|
+
import Debug from "debug";
|
|
16
|
+
|
|
17
|
+
// src/pipe.ts
|
|
18
|
+
import { isPhecda, plainToClass, transformInstance } from "phecda-core";
|
|
19
|
+
|
|
11
20
|
// src/exception/base.ts
|
|
12
21
|
var Exception = class extends Error {
|
|
13
22
|
message;
|
|
@@ -39,7 +48,6 @@ var ValidateException = class extends Exception {
|
|
|
39
48
|
__name(ValidateException, "ValidateException");
|
|
40
49
|
|
|
41
50
|
// src/pipe.ts
|
|
42
|
-
import { isPhecda, plainToClass, transformInstance } from "phecda-core";
|
|
43
51
|
var defaultPipe = /* @__PURE__ */ __name(({ arg, reflect, index }) => {
|
|
44
52
|
if (isPhecda(reflect)) {
|
|
45
53
|
const instance = plainToClass(reflect, arg);
|
|
@@ -182,66 +190,6 @@ var WorkerException = class extends Exception {
|
|
|
182
190
|
};
|
|
183
191
|
__name(WorkerException, "WorkerException");
|
|
184
192
|
|
|
185
|
-
// src/hmr.ts
|
|
186
|
-
function HMR(cb) {
|
|
187
|
-
if (IS_HMR)
|
|
188
|
-
globalThis.__PS_HMR__?.push(cb);
|
|
189
|
-
}
|
|
190
|
-
__name(HMR, "HMR");
|
|
191
|
-
|
|
192
|
-
// src/server/helper.ts
|
|
193
|
-
function resolveDep(ret, key) {
|
|
194
|
-
if (key)
|
|
195
|
-
return ret?.[key];
|
|
196
|
-
return ret;
|
|
197
|
-
}
|
|
198
|
-
__name(resolveDep, "resolveDep");
|
|
199
|
-
function argToReq(params, args, headers) {
|
|
200
|
-
const req = {
|
|
201
|
-
body: {},
|
|
202
|
-
query: {},
|
|
203
|
-
params: {},
|
|
204
|
-
headers
|
|
205
|
-
};
|
|
206
|
-
params.forEach((param) => {
|
|
207
|
-
if (param.key)
|
|
208
|
-
req[param.type][param.key] = args[param.index];
|
|
209
|
-
else
|
|
210
|
-
req[param.type] = args[param.index];
|
|
211
|
-
});
|
|
212
|
-
return req;
|
|
213
|
-
}
|
|
214
|
-
__name(argToReq, "argToReq");
|
|
215
|
-
|
|
216
|
-
// src/rpc/helper.ts
|
|
217
|
-
import { hostname } from "os";
|
|
218
|
-
function genClientQueue(key) {
|
|
219
|
-
return `PS-${key ? `${key}-` : ""}${hostname()}-${process.pid}`;
|
|
220
|
-
}
|
|
221
|
-
__name(genClientQueue, "genClientQueue");
|
|
222
|
-
|
|
223
|
-
// src/decorators/helper.ts
|
|
224
|
-
function shallowClone(obj) {
|
|
225
|
-
return {
|
|
226
|
-
...obj
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
__name(shallowClone, "shallowClone");
|
|
230
|
-
function mergeObject(...args) {
|
|
231
|
-
return Object.assign({}, ...args);
|
|
232
|
-
}
|
|
233
|
-
__name(mergeObject, "mergeObject");
|
|
234
|
-
function mergeArray(...args) {
|
|
235
|
-
return args.filter((item) => !!item).flat();
|
|
236
|
-
}
|
|
237
|
-
__name(mergeArray, "mergeArray");
|
|
238
|
-
|
|
239
|
-
// src/helper.ts
|
|
240
|
-
import pc from "picocolors";
|
|
241
|
-
|
|
242
|
-
// src/context.ts
|
|
243
|
-
import Debug from "debug";
|
|
244
|
-
|
|
245
193
|
// src/filter.ts
|
|
246
194
|
var defaultFilter = /* @__PURE__ */ __name((e) => {
|
|
247
195
|
if (!(e instanceof Exception)) {
|
|
@@ -272,7 +220,7 @@ var _Context = class {
|
|
|
272
220
|
async run(opts, successCb, failCb) {
|
|
273
221
|
const { meta, moduleMap } = this.data;
|
|
274
222
|
const { globalGuards = [], globalFilter, globalInterceptors = [], globalPipe } = opts;
|
|
275
|
-
const { paramsType, data: { guards, interceptors, params, tag, func,
|
|
223
|
+
const { paramsType, data: { guards, interceptors, params, tag, func, ctxs, filter } } = meta;
|
|
276
224
|
try {
|
|
277
225
|
await this.useGuard([
|
|
278
226
|
...globalGuards,
|
|
@@ -293,8 +241,9 @@ var _Context = class {
|
|
|
293
241
|
};
|
|
294
242
|
}));
|
|
295
243
|
const instance = moduleMap.get(tag);
|
|
296
|
-
if (
|
|
297
|
-
instance[ctx] = this.data;
|
|
244
|
+
if (ctxs) {
|
|
245
|
+
ctxs.forEach((ctx) => instance[ctx] = this.data);
|
|
246
|
+
}
|
|
298
247
|
const returnData = await instance[func](...args);
|
|
299
248
|
const i2 = await this.usePostInterceptor(returnData);
|
|
300
249
|
if (i2 !== void 0)
|
|
@@ -425,6 +374,56 @@ function addInterceptor(key, handler) {
|
|
|
425
374
|
}
|
|
426
375
|
__name(addInterceptor, "addInterceptor");
|
|
427
376
|
|
|
377
|
+
// src/hmr.ts
|
|
378
|
+
function HMR(cb) {
|
|
379
|
+
if (IS_HMR)
|
|
380
|
+
globalThis.__PS_HMR__?.push(cb);
|
|
381
|
+
}
|
|
382
|
+
__name(HMR, "HMR");
|
|
383
|
+
|
|
384
|
+
// src/server/helper.ts
|
|
385
|
+
function resolveDep(ret, key) {
|
|
386
|
+
if (key)
|
|
387
|
+
return ret?.[key];
|
|
388
|
+
return ret;
|
|
389
|
+
}
|
|
390
|
+
__name(resolveDep, "resolveDep");
|
|
391
|
+
function argToReq(params, args, headers) {
|
|
392
|
+
const req = {
|
|
393
|
+
body: {},
|
|
394
|
+
query: {},
|
|
395
|
+
params: {},
|
|
396
|
+
headers
|
|
397
|
+
};
|
|
398
|
+
params.forEach((param) => {
|
|
399
|
+
if (param.key)
|
|
400
|
+
req[param.type][param.key] = args[param.index];
|
|
401
|
+
else
|
|
402
|
+
req[param.type] = args[param.index];
|
|
403
|
+
});
|
|
404
|
+
return req;
|
|
405
|
+
}
|
|
406
|
+
__name(argToReq, "argToReq");
|
|
407
|
+
|
|
408
|
+
// src/rpc/helper.ts
|
|
409
|
+
import { hostname } from "os";
|
|
410
|
+
function genClientQueue(key) {
|
|
411
|
+
return `PS-${key ? `${key}-` : ""}${hostname()}-${process.pid}`;
|
|
412
|
+
}
|
|
413
|
+
__name(genClientQueue, "genClientQueue");
|
|
414
|
+
|
|
415
|
+
// src/decorators/helper.ts
|
|
416
|
+
function shallowClone(obj) {
|
|
417
|
+
return {
|
|
418
|
+
...obj
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
__name(shallowClone, "shallowClone");
|
|
422
|
+
function mergeObject(...args) {
|
|
423
|
+
return Object.assign({}, ...args);
|
|
424
|
+
}
|
|
425
|
+
__name(mergeObject, "mergeObject");
|
|
426
|
+
|
|
428
427
|
// src/helper.ts
|
|
429
428
|
function createControllerMetaMap(meta, filter) {
|
|
430
429
|
const metaMap = /* @__PURE__ */ new Map();
|
|
@@ -552,7 +551,6 @@ export {
|
|
|
552
551
|
genClientQueue,
|
|
553
552
|
shallowClone,
|
|
554
553
|
mergeObject,
|
|
555
|
-
mergeArray,
|
|
556
554
|
createControllerMetaMap,
|
|
557
555
|
detectAopDep,
|
|
558
556
|
Context,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
mergeObject,
|
|
3
3
|
shallowClone
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-JE6BBDXW.mjs";
|
|
5
5
|
import {
|
|
6
6
|
__name
|
|
7
7
|
} from "./chunk-VLV3AO3H.mjs";
|
|
@@ -222,14 +222,20 @@ function Rpc() {
|
|
|
222
222
|
}
|
|
223
223
|
__name(Rpc, "Rpc");
|
|
224
224
|
|
|
225
|
-
// src/decorators/
|
|
226
|
-
import { Empty, getState as getState5,
|
|
225
|
+
// src/decorators/ctx.ts
|
|
226
|
+
import { Empty, SHARE_KEY, getState as getState5, setPropertyState as setPropertyState5 } from "phecda-core";
|
|
227
227
|
function Injectable() {
|
|
228
228
|
return (target) => Empty(target);
|
|
229
229
|
}
|
|
230
230
|
__name(Injectable, "Injectable");
|
|
231
231
|
var Ctx = /* @__PURE__ */ __name((target, key) => {
|
|
232
|
-
|
|
232
|
+
setPropertyState5(target, SHARE_KEY, (state) => {
|
|
233
|
+
if (!state.ctxs)
|
|
234
|
+
state.ctxs = /* @__PURE__ */ new Set([
|
|
235
|
+
...getState5(target)?.ctxs || []
|
|
236
|
+
]);
|
|
237
|
+
state.ctxs.add(key);
|
|
238
|
+
});
|
|
233
239
|
}, "Ctx");
|
|
234
240
|
function Define(key, value) {
|
|
235
241
|
return (target, k, index) => {
|