phecda-server 5.0.0-beta.33 → 5.0.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/bin/cli.mjs +32 -35
- package/dist/{chunk-73I24DQB.mjs → chunk-5VMFQOJ7.mjs} +89 -0
- package/dist/{chunk-PPWMPM3L.js → chunk-5YYZLGGN.js} +91 -2
- package/dist/{chunk-UKGE77X6.mjs → chunk-C7MN5B36.mjs} +9 -19
- package/dist/{chunk-QA2ACJXC.js → chunk-VMXI3KFJ.js} +20 -30
- package/dist/{core-eb319626.d.ts → core-eb646fe5.d.ts} +5 -10
- package/dist/{helper-1ec9374b.d.ts → helper-88b19c66.d.ts} +1 -1
- package/dist/index.d.ts +23 -23
- package/dist/index.js +32 -28
- package/dist/index.mjs +17 -13
- package/dist/rpc/bullmq/index.d.ts +1 -1
- package/dist/rpc/bullmq/index.js +24 -48
- package/dist/rpc/bullmq/index.mjs +22 -46
- package/dist/rpc/kafka/index.d.ts +1 -1
- package/dist/rpc/kafka/index.js +25 -58
- package/dist/rpc/kafka/index.mjs +23 -56
- package/dist/rpc/nats/index.d.ts +1 -1
- package/dist/rpc/nats/index.js +24 -47
- package/dist/rpc/nats/index.mjs +21 -44
- package/dist/rpc/rabbitmq/index.d.ts +1 -1
- package/dist/rpc/rabbitmq/index.js +35 -60
- package/dist/rpc/rabbitmq/index.mjs +33 -58
- package/dist/rpc/redis/index.d.ts +1 -1
- package/dist/rpc/redis/index.js +25 -50
- package/dist/rpc/redis/index.mjs +23 -48
- package/dist/server/elysia/index.d.ts +4 -3
- package/dist/server/elysia/index.js +32 -84
- package/dist/server/elysia/index.mjs +21 -73
- package/dist/server/express/index.d.ts +3 -2
- package/dist/server/express/index.js +36 -86
- package/dist/server/express/index.mjs +26 -76
- package/dist/server/fastify/index.d.ts +4 -3
- package/dist/server/fastify/index.js +36 -88
- package/dist/server/fastify/index.mjs +25 -77
- package/dist/server/h3/index.d.ts +2 -1
- package/dist/server/h3/index.js +29 -81
- package/dist/server/h3/index.mjs +19 -71
- package/dist/server/hono/index.d.ts +3 -2
- package/dist/server/hono/index.js +38 -86
- package/dist/server/hono/index.mjs +28 -76
- package/dist/server/hyper-express/index.d.ts +3 -2
- package/dist/server/hyper-express/index.js +36 -91
- package/dist/server/hyper-express/index.mjs +26 -81
- package/dist/server/koa/index.d.ts +3 -2
- package/dist/server/koa/index.js +34 -84
- package/dist/server/koa/index.mjs +24 -74
- package/dist/test.d.ts +1 -1
- package/package.json +6 -4
- package/register/loader.mjs +12 -2
- package/dist/chunk-CMPQPS47.mjs +0 -14
- package/dist/chunk-INIUC4CX.js +0 -14
- package/dist/chunk-MAXJYJDI.js +0 -15
- package/dist/chunk-N3H5Q64U.mjs +0 -32
- package/dist/chunk-SKQSX262.js +0 -32
- package/dist/chunk-WCX6N5VH.mjs +0 -15
package/bin/cli.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
import { fork } from 'child_process'
|
|
3
|
-
import fs from 'fs'
|
|
4
3
|
import { createRequire } from 'module'
|
|
5
4
|
import pc from 'picocolors'
|
|
6
5
|
import cac from 'cac'
|
|
6
|
+
import fse from 'fs-extra'
|
|
7
7
|
import { log } from '../dist/index.mjs'
|
|
8
8
|
const cli = cac('phecda')
|
|
9
9
|
const require = createRequire(import.meta.url)
|
|
@@ -64,11 +64,12 @@ process.on('SIGINT', () => {
|
|
|
64
64
|
process.exit()
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
cli.command('init', 'init config file').action(() => {
|
|
68
|
-
|
|
67
|
+
cli.command('init', 'init config file').action(async () => {
|
|
68
|
+
if (!fse.existsSync('tsconfig.json')) {
|
|
69
|
+
log('init tsconfig.json')
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
await fse.outputFile(
|
|
72
|
+
'tsconfig.json',
|
|
72
73
|
`{
|
|
73
74
|
"compilerOptions": {
|
|
74
75
|
"target": "esnext",
|
|
@@ -81,7 +82,6 @@ cli.command('init', 'init config file').action(() => {
|
|
|
81
82
|
"moduleResolution": "Node",
|
|
82
83
|
"strict": true,
|
|
83
84
|
"resolveJsonModule": true,
|
|
84
|
-
"isolatedModules": true,
|
|
85
85
|
"esModuleInterop": true,
|
|
86
86
|
"noEmit": true,
|
|
87
87
|
"noUnusedLocals": true,
|
|
@@ -92,37 +92,34 @@ cli.command('init', 'init config file').action(() => {
|
|
|
92
92
|
"include": ["src","./ps.d.ts"]
|
|
93
93
|
}
|
|
94
94
|
`,
|
|
95
|
-
|
|
95
|
+
)
|
|
96
|
+
}
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
},
|
|
122
|
-
"moduleFile": []
|
|
98
|
+
if (!fse.existsSync('ps.json')) {
|
|
99
|
+
log('init ps.json')
|
|
100
|
+
|
|
101
|
+
await fse.outputFile(
|
|
102
|
+
'ps.json',
|
|
103
|
+
`{
|
|
104
|
+
"$schema": "node_modules/phecda-server/bin/schema.json",
|
|
105
|
+
"resolve": [
|
|
106
|
+
{
|
|
107
|
+
"source": "controller",
|
|
108
|
+
"importer": "http",
|
|
109
|
+
"path": ".ps/http.ts"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"source": "rpc",
|
|
113
|
+
"importer": "client",
|
|
114
|
+
"path": ".ps/rpc.ts"
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"unimport":false,
|
|
118
|
+
"moduleFile": []
|
|
119
|
+
}
|
|
120
|
+
`,
|
|
121
|
+
)
|
|
123
122
|
}
|
|
124
|
-
`,
|
|
125
|
-
)
|
|
126
123
|
})
|
|
127
124
|
|
|
128
125
|
cli
|
|
@@ -182,6 +182,60 @@ var WorkerException = class extends Exception {
|
|
|
182
182
|
};
|
|
183
183
|
__name(WorkerException, "WorkerException");
|
|
184
184
|
|
|
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
|
+
|
|
185
239
|
// src/context.ts
|
|
186
240
|
import pc from "picocolors";
|
|
187
241
|
import Debug from "debug";
|
|
@@ -229,6 +283,34 @@ var _Context = class {
|
|
|
229
283
|
if (IS_HMR)
|
|
230
284
|
data._context = this;
|
|
231
285
|
}
|
|
286
|
+
async run(successCb, failCb) {
|
|
287
|
+
const { meta, moduleMap } = this.data;
|
|
288
|
+
const { paramsType, data: { guards, interceptors, params, tag, func, ctx, filter } } = meta;
|
|
289
|
+
try {
|
|
290
|
+
await this.useGuard(guards);
|
|
291
|
+
const i1 = await this.useInterceptor(interceptors);
|
|
292
|
+
if (i1 !== void 0)
|
|
293
|
+
return successCb(i1);
|
|
294
|
+
const args = await this.usePipe(params.map((param) => {
|
|
295
|
+
return {
|
|
296
|
+
arg: resolveDep(this.data[param.type], param.key),
|
|
297
|
+
reflect: paramsType[param.index],
|
|
298
|
+
...param
|
|
299
|
+
};
|
|
300
|
+
}));
|
|
301
|
+
const instance = moduleMap.get(tag);
|
|
302
|
+
if (ctx)
|
|
303
|
+
instance[ctx] = this.data;
|
|
304
|
+
const returnData = await instance[func](...args);
|
|
305
|
+
const i2 = await this.usePostInterceptor(returnData);
|
|
306
|
+
if (i2 !== void 0)
|
|
307
|
+
return successCb(i2);
|
|
308
|
+
return successCb(returnData);
|
|
309
|
+
} catch (e) {
|
|
310
|
+
const err = await this.useFilter(e, filter);
|
|
311
|
+
return failCb(err);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
232
314
|
usePipe(args) {
|
|
233
315
|
return Promise.all(args.map((item) => {
|
|
234
316
|
if (item.pipe && !_Context.pipeRecord[item.pipe]) {
|
|
@@ -429,6 +511,13 @@ export {
|
|
|
429
511
|
FrameworkException,
|
|
430
512
|
TimerException,
|
|
431
513
|
WorkerException,
|
|
514
|
+
HMR,
|
|
515
|
+
resolveDep,
|
|
516
|
+
argToReq,
|
|
517
|
+
genClientQueue,
|
|
518
|
+
shallowClone,
|
|
519
|
+
mergeObject,
|
|
520
|
+
mergeArray,
|
|
432
521
|
Context,
|
|
433
522
|
addPlugin,
|
|
434
523
|
addPipe,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _class;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -182,6 +182,60 @@ var WorkerException = class extends Exception {
|
|
|
182
182
|
};
|
|
183
183
|
_chunkYR5Q5F2Kjs.__name.call(void 0, WorkerException, "WorkerException");
|
|
184
184
|
|
|
185
|
+
// src/hmr.ts
|
|
186
|
+
function HMR(cb) {
|
|
187
|
+
if (_chunkYR5Q5F2Kjs.IS_HMR)
|
|
188
|
+
_optionalChain([globalThis, 'access', _ => _.__PS_HMR__, 'optionalAccess', _2 => _2.push, 'call', _3 => _3(cb)]);
|
|
189
|
+
}
|
|
190
|
+
_chunkYR5Q5F2Kjs.__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
|
+
_chunkYR5Q5F2Kjs.__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
|
+
_chunkYR5Q5F2Kjs.__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
|
+
_chunkYR5Q5F2Kjs.__name.call(void 0, genClientQueue, "genClientQueue");
|
|
222
|
+
|
|
223
|
+
// src/decorators/helper.ts
|
|
224
|
+
function shallowClone(obj) {
|
|
225
|
+
return {
|
|
226
|
+
...obj
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
_chunkYR5Q5F2Kjs.__name.call(void 0, shallowClone, "shallowClone");
|
|
230
|
+
function mergeObject(...args) {
|
|
231
|
+
return Object.assign({}, ...args);
|
|
232
|
+
}
|
|
233
|
+
_chunkYR5Q5F2Kjs.__name.call(void 0, mergeObject, "mergeObject");
|
|
234
|
+
function mergeArray(...args) {
|
|
235
|
+
return args.filter((item) => !!item).flat();
|
|
236
|
+
}
|
|
237
|
+
_chunkYR5Q5F2Kjs.__name.call(void 0, mergeArray, "mergeArray");
|
|
238
|
+
|
|
185
239
|
// src/context.ts
|
|
186
240
|
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
187
241
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
@@ -229,6 +283,34 @@ var _Context = class {
|
|
|
229
283
|
if (_chunkYR5Q5F2Kjs.IS_HMR)
|
|
230
284
|
data._context = this;
|
|
231
285
|
}
|
|
286
|
+
async run(successCb, failCb) {
|
|
287
|
+
const { meta, moduleMap } = this.data;
|
|
288
|
+
const { paramsType, data: { guards, interceptors, params, tag, func, ctx, filter } } = meta;
|
|
289
|
+
try {
|
|
290
|
+
await this.useGuard(guards);
|
|
291
|
+
const i1 = await this.useInterceptor(interceptors);
|
|
292
|
+
if (i1 !== void 0)
|
|
293
|
+
return successCb(i1);
|
|
294
|
+
const args = await this.usePipe(params.map((param) => {
|
|
295
|
+
return {
|
|
296
|
+
arg: resolveDep(this.data[param.type], param.key),
|
|
297
|
+
reflect: paramsType[param.index],
|
|
298
|
+
...param
|
|
299
|
+
};
|
|
300
|
+
}));
|
|
301
|
+
const instance = moduleMap.get(tag);
|
|
302
|
+
if (ctx)
|
|
303
|
+
instance[ctx] = this.data;
|
|
304
|
+
const returnData = await instance[func](...args);
|
|
305
|
+
const i2 = await this.usePostInterceptor(returnData);
|
|
306
|
+
if (i2 !== void 0)
|
|
307
|
+
return successCb(i2);
|
|
308
|
+
return successCb(returnData);
|
|
309
|
+
} catch (e) {
|
|
310
|
+
const err = await this.useFilter(e, filter);
|
|
311
|
+
return failCb(err);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
232
314
|
usePipe(args) {
|
|
233
315
|
return Promise.all(args.map((item) => {
|
|
234
316
|
if (item.pipe && !_Context.pipeRecord[item.pipe]) {
|
|
@@ -436,4 +518,11 @@ _chunkYR5Q5F2Kjs.__name.call(void 0, detectAopDep, "detectAopDep");
|
|
|
436
518
|
|
|
437
519
|
|
|
438
520
|
|
|
439
|
-
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
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.Context = Context; exports.addPlugin = addPlugin; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addInterceptor = addInterceptor; exports.detectAopDep = detectAopDep;
|
|
@@ -1,23 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mergeObject,
|
|
3
|
+
shallowClone
|
|
4
|
+
} from "./chunk-5VMFQOJ7.mjs";
|
|
1
5
|
import {
|
|
2
6
|
__name
|
|
3
7
|
} from "./chunk-ITTD2GBR.mjs";
|
|
4
8
|
|
|
5
9
|
// src/decorators/param.ts
|
|
6
10
|
import { getState, setPropertyState } from "phecda-core";
|
|
7
|
-
|
|
8
|
-
// src/decorators/utils.ts
|
|
9
|
-
function shallowClone(obj) {
|
|
10
|
-
return {
|
|
11
|
-
...obj
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
__name(shallowClone, "shallowClone");
|
|
15
|
-
function mergeObject(...args) {
|
|
16
|
-
return Object.assign({}, ...args);
|
|
17
|
-
}
|
|
18
|
-
__name(mergeObject, "mergeObject");
|
|
19
|
-
|
|
20
|
-
// src/decorators/param.ts
|
|
21
11
|
function BaseParam(data) {
|
|
22
12
|
return (target, k, index) => {
|
|
23
13
|
if (!k)
|
|
@@ -67,11 +57,11 @@ function Param(key) {
|
|
|
67
57
|
});
|
|
68
58
|
}
|
|
69
59
|
__name(Param, "Param");
|
|
70
|
-
function Arg() {
|
|
71
|
-
|
|
72
|
-
type: "
|
|
73
|
-
key:
|
|
74
|
-
});
|
|
60
|
+
function Arg(target, k, index) {
|
|
61
|
+
BaseParam({
|
|
62
|
+
type: "args",
|
|
63
|
+
key: `${index}`
|
|
64
|
+
})(target, k, index);
|
|
75
65
|
}
|
|
76
66
|
__name(Arg, "Arg");
|
|
77
67
|
|
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var _chunkYR5Q5F2Kjs = require('./chunk-YR5Q5F2K.js');
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
var _phecdacore = require('phecda-core');
|
|
4
|
+
var _chunk5YYZLGGNjs = require('./chunk-5YYZLGGN.js');
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
...obj
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
_chunkYR5Q5F2Kjs.__name.call(void 0, shallowClone, "shallowClone");
|
|
15
|
-
function mergeObject(...args) {
|
|
16
|
-
return Object.assign({}, ...args);
|
|
17
|
-
}
|
|
18
|
-
_chunkYR5Q5F2Kjs.__name.call(void 0, mergeObject, "mergeObject");
|
|
6
|
+
|
|
7
|
+
var _chunkYR5Q5F2Kjs = require('./chunk-YR5Q5F2K.js');
|
|
19
8
|
|
|
20
9
|
// src/decorators/param.ts
|
|
10
|
+
var _phecdacore = require('phecda-core');
|
|
21
11
|
function BaseParam(data) {
|
|
22
12
|
return (target, k, index) => {
|
|
23
13
|
if (!k)
|
|
@@ -26,7 +16,7 @@ function BaseParam(data) {
|
|
|
26
16
|
if (!state.params)
|
|
27
17
|
state.params = [
|
|
28
18
|
..._optionalChain([_phecdacore.getState.call(void 0, target, k), 'optionalAccess', _ => _.params]) || []
|
|
29
|
-
].map(shallowClone);
|
|
19
|
+
].map(_chunk5YYZLGGNjs.shallowClone);
|
|
30
20
|
const existItem = state.params.find((item) => item.index === index);
|
|
31
21
|
if (existItem)
|
|
32
22
|
Object.assign(existItem, data);
|
|
@@ -67,11 +57,11 @@ function Param(key) {
|
|
|
67
57
|
});
|
|
68
58
|
}
|
|
69
59
|
_chunkYR5Q5F2Kjs.__name.call(void 0, Param, "Param");
|
|
70
|
-
function Arg() {
|
|
71
|
-
|
|
72
|
-
type: "
|
|
73
|
-
key:
|
|
74
|
-
});
|
|
60
|
+
function Arg(target, k, index) {
|
|
61
|
+
BaseParam({
|
|
62
|
+
type: "args",
|
|
63
|
+
key: `${index}`
|
|
64
|
+
})(target, k, index);
|
|
75
65
|
}
|
|
76
66
|
_chunkYR5Q5F2Kjs.__name.call(void 0, Arg, "Arg");
|
|
77
67
|
|
|
@@ -149,7 +139,7 @@ _chunkYR5Q5F2Kjs.__name.call(void 0, Pipe, "Pipe");
|
|
|
149
139
|
function Route(route, type) {
|
|
150
140
|
return (target, k) => {
|
|
151
141
|
_phecdacore.setPropertyState.call(void 0, target, k, (state) => {
|
|
152
|
-
state.http = mergeObject(state.http || _optionalChain([_phecdacore.getState.call(void 0, target, k), 'optionalAccess', _5 => _5.http]), {
|
|
142
|
+
state.http = _chunk5YYZLGGNjs.mergeObject.call(void 0, state.http || _optionalChain([_phecdacore.getState.call(void 0, target, k), 'optionalAccess', _5 => _5.http]), {
|
|
153
143
|
route,
|
|
154
144
|
type
|
|
155
145
|
});
|
|
@@ -161,9 +151,9 @@ function Header(headers) {
|
|
|
161
151
|
return (target, k) => {
|
|
162
152
|
_phecdacore.setPropertyState.call(void 0, target, k, (state) => {
|
|
163
153
|
if (!state.http)
|
|
164
|
-
state.http = mergeObject(_optionalChain([_phecdacore.getState.call(void 0, target, k), 'optionalAccess', _6 => _6.http]));
|
|
165
|
-
state.http = mergeObject(state.http, {
|
|
166
|
-
headers: mergeObject(_optionalChain([state, 'access', _7 => _7.http, 'optionalAccess', _8 => _8.headers]), headers)
|
|
154
|
+
state.http = _chunk5YYZLGGNjs.mergeObject.call(void 0, _optionalChain([_phecdacore.getState.call(void 0, target, k), 'optionalAccess', _6 => _6.http]));
|
|
155
|
+
state.http = _chunk5YYZLGGNjs.mergeObject.call(void 0, state.http, {
|
|
156
|
+
headers: _chunk5YYZLGGNjs.mergeObject.call(void 0, _optionalChain([state, 'access', _7 => _7.http, 'optionalAccess', _8 => _8.headers]), headers)
|
|
167
157
|
});
|
|
168
158
|
});
|
|
169
159
|
};
|
|
@@ -193,7 +183,7 @@ function Controller(prefix = "") {
|
|
|
193
183
|
return (target) => {
|
|
194
184
|
_phecdacore.setPropertyState.call(void 0, target, void 0, (state) => {
|
|
195
185
|
state.controller = "http";
|
|
196
|
-
state.http = mergeObject(state.http || _optionalChain([_phecdacore.getState.call(void 0, target), 'optionalAccess', _9 => _9.http]), {
|
|
186
|
+
state.http = _chunk5YYZLGGNjs.mergeObject.call(void 0, state.http || _optionalChain([_phecdacore.getState.call(void 0, target), 'optionalAccess', _9 => _9.http]), {
|
|
197
187
|
prefix
|
|
198
188
|
});
|
|
199
189
|
});
|
|
@@ -206,7 +196,7 @@ _chunkYR5Q5F2Kjs.__name.call(void 0, Controller, "Controller");
|
|
|
206
196
|
function Event(isEvent = true) {
|
|
207
197
|
return (target, k) => {
|
|
208
198
|
_phecdacore.setPropertyState.call(void 0, target, k, (state) => {
|
|
209
|
-
state.rpc = mergeObject(state.rpc || _optionalChain([_phecdacore.getState.call(void 0, target, k), 'optionalAccess', _10 => _10.rpc]), {
|
|
199
|
+
state.rpc = _chunk5YYZLGGNjs.mergeObject.call(void 0, state.rpc || _optionalChain([_phecdacore.getState.call(void 0, target, k), 'optionalAccess', _10 => _10.rpc]), {
|
|
210
200
|
isEvent
|
|
211
201
|
});
|
|
212
202
|
});
|
|
@@ -216,7 +206,7 @@ _chunkYR5Q5F2Kjs.__name.call(void 0, Event, "Event");
|
|
|
216
206
|
function Queue(queue = "") {
|
|
217
207
|
return (target, k) => {
|
|
218
208
|
_phecdacore.setPropertyState.call(void 0, target, k, (state) => {
|
|
219
|
-
state.rpc = mergeObject(state.rpc || _optionalChain([_phecdacore.getState.call(void 0, target, k), 'optionalAccess', _11 => _11.rpc]), {
|
|
209
|
+
state.rpc = _chunk5YYZLGGNjs.mergeObject.call(void 0, state.rpc || _optionalChain([_phecdacore.getState.call(void 0, target, k), 'optionalAccess', _11 => _11.rpc]), {
|
|
220
210
|
queue
|
|
221
211
|
});
|
|
222
212
|
});
|
|
@@ -249,10 +239,10 @@ function Define(key, value) {
|
|
|
249
239
|
if (!state.params)
|
|
250
240
|
state.params = [
|
|
251
241
|
...parentState
|
|
252
|
-
].map(shallowClone);
|
|
242
|
+
].map(_chunk5YYZLGGNjs.shallowClone);
|
|
253
243
|
const existItem = state.params.find((item) => item.index === index);
|
|
254
244
|
if (existItem)
|
|
255
|
-
existItem.define = mergeObject(existItem.define, {
|
|
245
|
+
existItem.define = _chunk5YYZLGGNjs.mergeObject.call(void 0, existItem.define, {
|
|
256
246
|
[key]: value
|
|
257
247
|
});
|
|
258
248
|
else
|
|
@@ -268,7 +258,7 @@ function Define(key, value) {
|
|
|
268
258
|
_phecdacore.setPropertyState.call(void 0, target, k, (state) => {
|
|
269
259
|
const parentState = _optionalChain([_phecdacore.getState.call(void 0, target, k), 'optionalAccess', _13 => _13.define]);
|
|
270
260
|
if (!state.define)
|
|
271
|
-
state.define = mergeObject(parentState);
|
|
261
|
+
state.define = _chunk5YYZLGGNjs.mergeObject.call(void 0, parentState);
|
|
272
262
|
state.define[key] = value;
|
|
273
263
|
});
|
|
274
264
|
};
|
|
@@ -77,7 +77,7 @@ type ToClientFn<Func extends AnyFunction> = (...p: Parameters<Func>) => Promise<
|
|
|
77
77
|
type PickFunc<Instance> = Pick<Instance, PickFuncKeys<Instance>>;
|
|
78
78
|
type OmitFunction<Instance> = Omit<Instance, PickFuncKeys<Instance>>;
|
|
79
79
|
interface BaseContext {
|
|
80
|
-
meta:
|
|
80
|
+
meta: ControllerMeta;
|
|
81
81
|
moduleMap: Record<string, any>;
|
|
82
82
|
type: string;
|
|
83
83
|
tag: string;
|
|
@@ -91,17 +91,12 @@ interface HttpContext extends BaseContext {
|
|
|
91
91
|
params: Record<string, string>;
|
|
92
92
|
body: Record<string, any>;
|
|
93
93
|
headers: IncomingHttpHeaders;
|
|
94
|
-
data: any;
|
|
95
94
|
}
|
|
96
95
|
interface RpcContext extends BaseContext {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
args: any[];
|
|
102
|
-
id: string;
|
|
103
|
-
queue: string;
|
|
104
|
-
};
|
|
96
|
+
args: any[];
|
|
97
|
+
id: string;
|
|
98
|
+
queue: string;
|
|
99
|
+
isEvent?: boolean;
|
|
105
100
|
}
|
|
106
101
|
interface BaseError {
|
|
107
102
|
[ERROR_SYMBOL]: true;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { B as BaseContext, M as Meta, G as Generator, C as ControllerMetaData, a as MetaData, U as UNMOUNT_SYMBOL, b as BaseError } from './core-
|
|
2
|
-
export { f as BaseRequestType, e as BaseReturn, j as ControllerMeta, g as CustomResponse, k as ERROR_SYMBOL, E as Emitter, h as ExtractResponse, F as Factory, H as HttpContext, I as IS_HMR, l as IS_ONLY_GENERATE, m as IS_STRICT, L as LOG_LEVEL, O as OmitFunction, n as PS_EXIT_CODE, P as PickFunc, R as RpcContext, S as ServiceMetaData, d as ToClientFn, c as ToClientInstance, T as ToClientMap, i as emitter } from './core-
|
|
1
|
+
import { B as BaseContext, M as Meta, G as Generator, C as ControllerMetaData, a as MetaData, U as UNMOUNT_SYMBOL, b as BaseError } from './core-eb646fe5.js';
|
|
2
|
+
export { f as BaseRequestType, e as BaseReturn, j as ControllerMeta, g as CustomResponse, k as ERROR_SYMBOL, E as Emitter, h as ExtractResponse, F as Factory, H as HttpContext, I as IS_HMR, l as IS_ONLY_GENERATE, m as IS_STRICT, L as LOG_LEVEL, O as OmitFunction, n as PS_EXIT_CODE, P as PickFunc, R as RpcContext, S as ServiceMetaData, d as ToClientFn, c as ToClientInstance, T as ToClientMap, i as emitter } from './core-eb646fe5.js';
|
|
3
3
|
import { Construct, AbConstruct } from 'phecda-core';
|
|
4
4
|
export * from 'phecda-core';
|
|
5
|
+
export { S as ServerOptions, a as argToReq, r as resolveDep } from './helper-88b19c66.js';
|
|
5
6
|
export { a as RpcClientOptions, R as RpcServerOptions, g as genClientQueue } from './helper-9e206c66.js';
|
|
6
|
-
export { S as ServerOptions, a as argToReq, r as resolveDep } from './helper-1ec9374b.js';
|
|
7
7
|
import 'http';
|
|
8
8
|
|
|
9
9
|
declare class Histroy {
|
|
@@ -89,9 +89,7 @@ declare class WorkerException extends Exception {
|
|
|
89
89
|
constructor(message: string);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
type InterceptorType<C extends BaseContext = any> = (ctx: C) => (any | ((ret: any) => any));
|
|
94
|
-
type PipeType<C extends BaseContext = any> = (arg: {
|
|
92
|
+
interface PipeArg {
|
|
95
93
|
arg: any;
|
|
96
94
|
pipe?: string;
|
|
97
95
|
key: string;
|
|
@@ -99,7 +97,10 @@ type PipeType<C extends BaseContext = any> = (arg: {
|
|
|
99
97
|
index: number;
|
|
100
98
|
reflect: any;
|
|
101
99
|
define: Record<string, any>;
|
|
102
|
-
}
|
|
100
|
+
}
|
|
101
|
+
type GuardType<C extends BaseContext = any> = ((ctx: C) => Promise<boolean> | boolean);
|
|
102
|
+
type InterceptorType<C extends BaseContext = any> = (ctx: C) => (any | ((ret: any) => any));
|
|
103
|
+
type PipeType<C extends BaseContext = any> = (arg: PipeArg, ctx: C) => Promise<any>;
|
|
103
104
|
type FilterType<C extends BaseContext = any, E extends Exception = any> = (err: E | Error, ctx?: C) => Error | any;
|
|
104
105
|
declare class Context<Data extends BaseContext> {
|
|
105
106
|
data: Data;
|
|
@@ -111,21 +112,14 @@ declare class Context<Data extends BaseContext> {
|
|
|
111
112
|
static guardRecord: Record<PropertyKey, GuardType>;
|
|
112
113
|
static interceptorRecord: Record<PropertyKey, InterceptorType>;
|
|
113
114
|
static pluginRecord: Record<PropertyKey, any>;
|
|
114
|
-
postInterceptors
|
|
115
|
+
private postInterceptors;
|
|
115
116
|
constructor(data: Data);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
index: number;
|
|
123
|
-
reflect: any;
|
|
124
|
-
}[]): Promise<any[]>;
|
|
125
|
-
useFilter(arg: any, filter?: string): any;
|
|
126
|
-
useGuard(guards: string[]): Promise<void>;
|
|
127
|
-
usePostInterceptor(data: any): Promise<any>;
|
|
128
|
-
useInterceptor(interceptors: string[]): Promise<any>;
|
|
117
|
+
run<ReturnData = any, ReturnErr = any>(successCb: (data: any) => ReturnData, failCb: (err: any) => ReturnErr): Promise<ReturnData | ReturnErr>;
|
|
118
|
+
private usePipe;
|
|
119
|
+
private useFilter;
|
|
120
|
+
private useGuard;
|
|
121
|
+
private usePostInterceptor;
|
|
122
|
+
private useInterceptor;
|
|
129
123
|
static usePlugin(plugins: string[]): any[];
|
|
130
124
|
}
|
|
131
125
|
declare function addPlugin<T>(key: PropertyKey, handler: T): void;
|
|
@@ -170,7 +164,7 @@ declare function Body(key?: string): ParameterDecorator;
|
|
|
170
164
|
declare function Head(key: string): ParameterDecorator;
|
|
171
165
|
declare function Query(key?: string): ParameterDecorator;
|
|
172
166
|
declare function Param(key: string): ParameterDecorator;
|
|
173
|
-
declare function Arg():
|
|
167
|
+
declare function Arg(target: any, k: string, index: number): void;
|
|
174
168
|
|
|
175
169
|
declare function Guard(...guards: string[]): (target: any, k?: PropertyKey) => void;
|
|
176
170
|
declare function Plugin(...plugins: string[]): (target: any, k?: PropertyKey) => void;
|
|
@@ -265,4 +259,10 @@ declare function getConfig<C = any>(key: string, defaultConf?: C): C;
|
|
|
265
259
|
declare function setConfig<C = any>(key: string, conf: C, force?: boolean): void;
|
|
266
260
|
declare function Mix<C1 extends Construct | AbConstruct, C2 extends Construct>(InternalClass: C1, ExtendClass: C2): new (...args: ConstructorParameters<C2>) => InstanceType<C1> & InstanceType<C2>;
|
|
267
261
|
|
|
268
|
-
|
|
262
|
+
declare function HMR(cb: (...args: any) => any): void;
|
|
263
|
+
|
|
264
|
+
declare function shallowClone(obj: any): any;
|
|
265
|
+
declare function mergeObject(...args: any[]): any;
|
|
266
|
+
declare function mergeArray(...args: any[]): any[];
|
|
267
|
+
|
|
268
|
+
export { Arg, BadGatewayException, BadRequestException, BaseContext, BaseError, BaseParam, Body, ConflictException, Context, Controller, ControllerMetaData, Ctx, Define, Delete, Dev, Event, Exception, Filter, FilterType, ForbiddenException, FrameworkException, Generator, Get, Guard, GuardType, HMR, HTTPGenerator, Head, Header, Injectable, Interceptor, InterceptorType, InvalidInputException, Meta, MetaData, Mix, NotFoundException, PExtension, PFilter, PGuard, PInterceptor, PPipe, PPlugin, Param, Patch, PayloadLargeException, Pipe, PipeArg, PipeType, Plugin, Post, Put, Query, Queue, RPCGenerator, Route, Rpc, ServiceUnavailableException, TimeoutException, TimerException, UNMOUNT_SYMBOL, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, WorkerException, addFilter, addGuard, addInterceptor, addPipe, addPlugin, defaultPipe, detectAopDep, getConfig, log, mergeArray, mergeObject, setConfig, shallowClone };
|