phecda-server 7.1.4 → 8.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/dist/{chunk-MKRHYZCL.mjs → chunk-FI5756JX.mjs} +2 -2
- package/dist/{chunk-YRS4ECPT.js → chunk-OLNN4U3O.js} +12 -8
- package/dist/{chunk-5MAGRSEM.mjs → chunk-PFPOEZHH.mjs} +12 -8
- package/dist/{chunk-DPPDWBYO.js → chunk-UYZSUBX4.js} +2 -2
- package/dist/{chunk-P3CS65OP.mjs → chunk-VAHCYYCB.mjs} +32 -17
- package/dist/{chunk-OV3UJLGP.js → chunk-YJ3QHGTC.js} +32 -17
- package/dist/{core-B5yKYkMJ.d.mts → core-BTSHIAyB.d.ts} +2 -1
- package/dist/{core-BRuvL6hY.d.ts → core-D1YYphEn.d.mts} +2 -1
- package/dist/helper.d.mts +1 -1
- package/dist/helper.d.ts +1 -1
- package/dist/helper.js +2 -2
- package/dist/helper.mjs +1 -1
- package/dist/http/elysia/index.d.mts +3 -3
- package/dist/http/elysia/index.d.ts +3 -3
- package/dist/http/elysia/index.js +30 -30
- package/dist/http/elysia/index.mjs +15 -15
- package/dist/http/express/index.d.mts +3 -3
- package/dist/http/express/index.d.ts +3 -3
- package/dist/http/express/index.js +27 -27
- package/dist/http/express/index.mjs +14 -14
- package/dist/http/fastify/index.d.mts +3 -3
- package/dist/http/fastify/index.d.ts +3 -3
- package/dist/http/fastify/index.js +29 -29
- package/dist/http/fastify/index.mjs +15 -15
- package/dist/http/h3/index.d.mts +3 -3
- package/dist/http/h3/index.d.ts +3 -3
- package/dist/http/h3/index.js +28 -28
- package/dist/http/h3/index.mjs +14 -14
- package/dist/http/hono/index.d.mts +3 -3
- package/dist/http/hono/index.d.ts +3 -3
- package/dist/http/hono/index.js +26 -26
- package/dist/http/hono/index.mjs +14 -14
- 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 +26 -26
- package/dist/http/hyper-express/index.mjs +14 -14
- package/dist/http/koa/index.d.mts +3 -3
- package/dist/http/koa/index.d.ts +3 -3
- package/dist/http/koa/index.js +27 -27
- package/dist/http/koa/index.mjs +14 -14
- package/dist/index.d.mts +20 -13
- package/dist/index.d.ts +20 -13
- package/dist/index.js +112 -71
- package/dist/index.mjs +69 -28
- package/dist/{meta-C_eDyXnK.d.ts → meta-DNF6Fl27.d.mts} +11 -9
- package/dist/{meta-C_eDyXnK.d.mts → meta-DNF6Fl27.d.ts} +11 -9
- package/dist/rpc/bullmq/index.d.mts +3 -3
- package/dist/rpc/bullmq/index.d.ts +3 -3
- package/dist/rpc/bullmq/index.js +16 -16
- package/dist/rpc/bullmq/index.mjs +11 -11
- package/dist/rpc/electron/index.d.mts +3 -3
- package/dist/rpc/electron/index.d.ts +3 -3
- package/dist/rpc/electron/index.js +11 -11
- package/dist/rpc/electron/index.mjs +7 -7
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +14 -14
- package/dist/rpc/kafka/index.mjs +9 -9
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +14 -14
- package/dist/rpc/nats/index.mjs +9 -9
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +14 -14
- package/dist/rpc/rabbitmq/index.mjs +9 -9
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +14 -14
- package/dist/rpc/redis/index.mjs +9 -9
- package/dist/rpc/ws/index.d.mts +3 -3
- package/dist/rpc/ws/index.d.ts +3 -3
- package/dist/rpc/ws/index.js +10 -10
- package/dist/rpc/ws/index.mjs +6 -6
- package/dist/test.d.mts +2 -2
- package/dist/test.d.ts +2 -2
- package/dist/test.js +5 -5
- package/dist/test.mjs +4 -4
- package/dist/{types-7-m2wEkP.d.mts → types-BOZ8yE2L.d.mts} +1 -1
- package/dist/{types-BuvMT1ta.d.ts → types-Cosv4nol.d.ts} +1 -1
- package/dist/{types-BKHBmSQN.d.mts → types-DtiHAXQB.d.mts} +1 -1
- package/dist/{types-B6aU8oT-.d.ts → types-YJ55P7A_.d.ts} +1 -1
- package/package.json +3 -4
- package/register/export.mjs +5 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } 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; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } 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; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9;
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkOLNN4U3Ojs = require('./chunk-OLNN4U3O.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
@@ -34,7 +34,7 @@ var _chunkYRS4ECPTjs = require('./chunk-YRS4ECPT.js');
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
var
|
|
37
|
+
var _chunkUYZSUBX4js = require('./chunk-UYZSUBX4.js');
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
|
|
@@ -60,7 +60,7 @@ var _chunkDPPDWBYOjs = require('./chunk-DPPDWBYO.js');
|
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
var
|
|
63
|
+
var _chunkYJ3QHGTCjs = require('./chunk-YJ3QHGTC.js');
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
|
|
@@ -102,7 +102,7 @@ var ServerBase = (_class = class extends _phecdacore.Base {constructor(...args2)
|
|
|
102
102
|
static {
|
|
103
103
|
_chunk4LLLQOMFjs.__name.call(void 0, this, "ServerBase");
|
|
104
104
|
}
|
|
105
|
-
__init() {this.emitter = exports.emitter =
|
|
105
|
+
__init() {this.emitter = exports.emitter = _chunkOLNN4U3Ojs.emitter}
|
|
106
106
|
log(msg, level = "log") {
|
|
107
107
|
_chunk4LLLQOMFjs.log.call(void 0, msg, level, this.tag);
|
|
108
108
|
}
|
|
@@ -114,7 +114,7 @@ var HttpBase = class extends ServerBase {
|
|
|
114
114
|
|
|
115
115
|
};
|
|
116
116
|
_ts_decorate([
|
|
117
|
-
|
|
117
|
+
_chunkUYZSUBX4js.Ctx,
|
|
118
118
|
_ts_metadata("design:type", typeof Ctx === "undefined" ? Object : Ctx)
|
|
119
119
|
], HttpBase.prototype, "context", void 0);
|
|
120
120
|
var RpcBase = class extends ServerBase {
|
|
@@ -124,7 +124,7 @@ var RpcBase = class extends ServerBase {
|
|
|
124
124
|
|
|
125
125
|
};
|
|
126
126
|
_ts_decorate([
|
|
127
|
-
|
|
127
|
+
_chunkUYZSUBX4js.Ctx,
|
|
128
128
|
_ts_metadata("design:type", typeof Ctx === "undefined" ? Object : Ctx)
|
|
129
129
|
], RpcBase.prototype, "context", void 0);
|
|
130
130
|
|
|
@@ -138,9 +138,9 @@ var PFilter = class extends ServerBase {
|
|
|
138
138
|
constructor(tag) {
|
|
139
139
|
super();
|
|
140
140
|
this.key = tag || _phecdacore.getTag.call(void 0, this);
|
|
141
|
-
|
|
141
|
+
_chunkYJ3QHGTCjs.addFilter.call(void 0, this.key, this.use.bind(this));
|
|
142
142
|
this.onUnmount(() => {
|
|
143
|
-
delete
|
|
143
|
+
delete _chunkYJ3QHGTCjs.Context.filterRecord[this.key];
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
};
|
|
@@ -156,9 +156,9 @@ var PGuard = (_class2 = class extends ServerBase {
|
|
|
156
156
|
constructor(tag) {
|
|
157
157
|
super();_class2.prototype.__init2.call(this);;
|
|
158
158
|
this.key = tag || _phecdacore.getTag.call(void 0, this);
|
|
159
|
-
|
|
159
|
+
_chunkYJ3QHGTCjs.addGuard.call(void 0, this.key, this.use.bind(this), this.priority);
|
|
160
160
|
this.onUnmount(() => {
|
|
161
|
-
delete
|
|
161
|
+
delete _chunkYJ3QHGTCjs.Context.guardRecord[this.key];
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
}, _class2);
|
|
@@ -173,9 +173,9 @@ var PPipe = class extends ServerBase {
|
|
|
173
173
|
constructor(tag) {
|
|
174
174
|
super();
|
|
175
175
|
this.key = tag || _phecdacore.getTag.call(void 0, this);
|
|
176
|
-
|
|
176
|
+
_chunkYJ3QHGTCjs.addPipe.call(void 0, this.key, this.use.bind(this));
|
|
177
177
|
this.onUnmount(() => {
|
|
178
|
-
delete
|
|
178
|
+
delete _chunkYJ3QHGTCjs.Context.pipeRecord[this.key];
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
};
|
|
@@ -191,9 +191,9 @@ var PAddon = (_class3 = class extends ServerBase {
|
|
|
191
191
|
constructor(tag) {
|
|
192
192
|
super();_class3.prototype.__init3.call(this);;
|
|
193
193
|
this.key = tag || _phecdacore.getTag.call(void 0, this);
|
|
194
|
-
|
|
194
|
+
_chunkYJ3QHGTCjs.addAddon.call(void 0, this.key, this.use.bind(this), this.priority);
|
|
195
195
|
this.onUnmount(() => {
|
|
196
|
-
delete
|
|
196
|
+
delete _chunkYJ3QHGTCjs.Context.addonRecord[this.key];
|
|
197
197
|
});
|
|
198
198
|
}
|
|
199
199
|
}, _class3);
|
|
@@ -211,27 +211,27 @@ var PExtension = class extends ServerBase {
|
|
|
211
211
|
super();
|
|
212
212
|
const key = this.key = tag || _phecdacore.getTag.call(void 0, this);
|
|
213
213
|
if (this.pipe) {
|
|
214
|
-
|
|
214
|
+
_chunkYJ3QHGTCjs.addPipe.call(void 0, key, this.pipe.bind(this));
|
|
215
215
|
this.onUnmount(() => {
|
|
216
|
-
delete
|
|
216
|
+
delete _chunkYJ3QHGTCjs.Context.pipeRecord[key];
|
|
217
217
|
});
|
|
218
218
|
}
|
|
219
219
|
if (this.addon) {
|
|
220
|
-
|
|
220
|
+
_chunkYJ3QHGTCjs.addAddon.call(void 0, key, this.addon.bind(this), this.addonPriority);
|
|
221
221
|
this.onUnmount(() => {
|
|
222
|
-
delete
|
|
222
|
+
delete _chunkYJ3QHGTCjs.Context.addonRecord[key];
|
|
223
223
|
});
|
|
224
224
|
}
|
|
225
225
|
if (this.guard) {
|
|
226
|
-
|
|
226
|
+
_chunkYJ3QHGTCjs.addGuard.call(void 0, key, this.guard.bind(this), this.guardPriority);
|
|
227
227
|
this.onUnmount(() => {
|
|
228
|
-
delete
|
|
228
|
+
delete _chunkYJ3QHGTCjs.Context.guardRecord[key];
|
|
229
229
|
});
|
|
230
230
|
}
|
|
231
231
|
if (this.filter) {
|
|
232
|
-
|
|
232
|
+
_chunkYJ3QHGTCjs.addFilter.call(void 0, key, this.filter.bind(this));
|
|
233
233
|
this.onUnmount(() => {
|
|
234
|
-
delete
|
|
234
|
+
delete _chunkYJ3QHGTCjs.Context.filterRecord[key];
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
237
|
}
|
|
@@ -239,29 +239,30 @@ var PExtension = class extends ServerBase {
|
|
|
239
239
|
|
|
240
240
|
// src/generator/utils.ts
|
|
241
241
|
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
242
|
-
var Generator = class {
|
|
242
|
+
var Generator = (_class4 = class {
|
|
243
243
|
static {
|
|
244
244
|
_chunk4LLLQOMFjs.__name.call(void 0, this, "Generator");
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
constructor(path) {
|
|
247
|
+
constructor(path) {;_class4.prototype.__init4.call(this);
|
|
248
248
|
if (path) this._path = path;
|
|
249
249
|
}
|
|
250
|
+
__init4() {this.ext = ".js"}
|
|
250
251
|
get path() {
|
|
251
|
-
return this._path || `.ps/${this.name.toLowerCase()}.
|
|
252
|
+
return this._path || `.ps/${this.name.toLowerCase()}${this.ext}`;
|
|
252
253
|
}
|
|
253
254
|
async output(meta) {
|
|
254
255
|
await _fsextra2.default.outputFile(this.path, this.generateCode(meta));
|
|
255
256
|
}
|
|
256
|
-
};
|
|
257
|
+
}, _class4);
|
|
257
258
|
|
|
258
259
|
// src/generator/rpc.ts
|
|
259
|
-
var RPCGenerator = (
|
|
260
|
+
var RPCGenerator = (_class5 = class extends Generator {constructor(...args3) { super(...args3); _class5.prototype.__init5.call(this);_class5.prototype.__init6.call(this); }
|
|
260
261
|
static {
|
|
261
262
|
_chunk4LLLQOMFjs.__name.call(void 0, this, "RPCGenerator");
|
|
262
263
|
}
|
|
263
|
-
|
|
264
|
-
|
|
264
|
+
__init5() {this.name = "RPC"}
|
|
265
|
+
__init6() {this.classMap = {}}
|
|
265
266
|
getContent() {
|
|
266
267
|
let content = "";
|
|
267
268
|
for (const name in this.classMap) {
|
|
@@ -273,12 +274,12 @@ var RPCGenerator = (_class4 = class extends Generator {constructor(...args3) { s
|
|
|
273
274
|
return content;
|
|
274
275
|
}
|
|
275
276
|
addMethod(args) {
|
|
276
|
-
const { rpc, name,
|
|
277
|
+
const { rpc, name, method, tag } = args;
|
|
277
278
|
if (!rpc) return;
|
|
278
279
|
if (!this.classMap[name]) this.classMap[name] = {};
|
|
279
|
-
this.classMap[name][
|
|
280
|
-
${
|
|
281
|
-
return {tag:'${tag}',
|
|
280
|
+
this.classMap[name][method] = `
|
|
281
|
+
${method}(){
|
|
282
|
+
return {tag:'${tag}',method:"${method}",isEvent:${!!rpc.isEvent},queue:"${rpc.queue || ""}"}
|
|
282
283
|
|
|
283
284
|
}
|
|
284
285
|
`;
|
|
@@ -289,15 +290,15 @@ var RPCGenerator = (_class4 = class extends Generator {constructor(...args3) { s
|
|
|
289
290
|
});
|
|
290
291
|
return this.getContent();
|
|
291
292
|
}
|
|
292
|
-
},
|
|
293
|
+
}, _class5);
|
|
293
294
|
|
|
294
295
|
// src/generator/http.ts
|
|
295
|
-
var HTTPGenerator = (
|
|
296
|
+
var HTTPGenerator = (_class6 = class extends Generator {constructor(...args4) { super(...args4); _class6.prototype.__init7.call(this);_class6.prototype.__init8.call(this); }
|
|
296
297
|
static {
|
|
297
298
|
_chunk4LLLQOMFjs.__name.call(void 0, this, "HTTPGenerator");
|
|
298
299
|
}
|
|
299
|
-
|
|
300
|
-
|
|
300
|
+
__init7() {this.name = "HTTP"}
|
|
301
|
+
__init8() {this.classMap = {}}
|
|
301
302
|
getContent() {
|
|
302
303
|
let content = "";
|
|
303
304
|
for (const name in this.classMap) {
|
|
@@ -309,17 +310,18 @@ var HTTPGenerator = (_class5 = class extends Generator {constructor(...args4) {
|
|
|
309
310
|
return content;
|
|
310
311
|
}
|
|
311
312
|
addMethod(args) {
|
|
312
|
-
const { http, name,
|
|
313
|
-
if (!_optionalChain([http, 'optionalAccess', _2 => _2.
|
|
314
|
-
const url =
|
|
313
|
+
const { http, name, method, params, tag } = args;
|
|
314
|
+
if (!_optionalChain([http, 'optionalAccess', _2 => _2.method])) return;
|
|
315
|
+
const url = _chunkYJ3QHGTCjs.joinUrl.call(void 0, http.prefix, http.route).replace(/\/\:([^\/]*)/g, (_, js) => `/{{${js}}}`);
|
|
315
316
|
if (!this.classMap[name]) this.classMap[name] = {};
|
|
316
|
-
this.classMap[name][
|
|
317
|
-
${
|
|
318
|
-
|
|
319
|
-
|
|
317
|
+
this.classMap[name][method] = `
|
|
318
|
+
${method}(...args){
|
|
319
|
+
let url="${url}"
|
|
320
|
+
const ret={tag:"${tag}",method:"${method}",body:{},headers:{},query:{},params:{}}
|
|
320
321
|
${params.reduce((p, c, i) => `${p}ret.${c.type}${c.key ? `['${c.key}']` : ""}=args[${i}]
|
|
321
|
-
${c.type === "params" ? `
|
|
322
|
+
${c.type === "params" ? `url=url.replace('{{${c.key}}}',args[${i}])` : ""}
|
|
322
323
|
`, "")}
|
|
324
|
+
ret.http={method:"${http.method}",url}
|
|
323
325
|
return ret
|
|
324
326
|
}
|
|
325
327
|
`;
|
|
@@ -330,16 +332,17 @@ return ret
|
|
|
330
332
|
});
|
|
331
333
|
return this.getContent();
|
|
332
334
|
}
|
|
333
|
-
},
|
|
335
|
+
}, _class6);
|
|
334
336
|
|
|
335
337
|
// src/generator/openapi.ts
|
|
336
338
|
|
|
337
|
-
var OpenAPIGenerator = (
|
|
339
|
+
var OpenAPIGenerator = (_class7 = class extends Generator {constructor(...args5) { super(...args5); _class7.prototype.__init9.call(this);_class7.prototype.__init10.call(this);_class7.prototype.__init11.call(this); }
|
|
338
340
|
static {
|
|
339
341
|
_chunk4LLLQOMFjs.__name.call(void 0, this, "OpenAPIGenerator");
|
|
340
342
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
+
__init9() {this.ext = ".json"}
|
|
344
|
+
__init10() {this.name = "OpenAPI"}
|
|
345
|
+
__init11() {this.paths = {}}
|
|
343
346
|
getContent() {
|
|
344
347
|
return JSON.stringify({
|
|
345
348
|
openapi: "3.0.0",
|
|
@@ -351,13 +354,14 @@ var OpenAPIGenerator = (_class6 = class extends Generator {constructor(...args5)
|
|
|
351
354
|
paths: this.paths
|
|
352
355
|
});
|
|
353
356
|
}
|
|
354
|
-
addMethod(args) {
|
|
355
|
-
const { http, tag,
|
|
356
|
-
if (!_optionalChain([http, 'optionalAccess', _3 => _3.
|
|
357
|
-
const
|
|
357
|
+
addMethod(args, model) {
|
|
358
|
+
const { http, tag, method } = args;
|
|
359
|
+
if (!_optionalChain([http, 'optionalAccess', _3 => _3.method])) return;
|
|
360
|
+
const config = _phecdacore.getMergedMeta.call(void 0, model, method).openapi;
|
|
361
|
+
if (!config) return;
|
|
362
|
+
const path = _chunkYJ3QHGTCjs.joinUrl.call(void 0, http.prefix, http.route);
|
|
358
363
|
if (!this.paths[path]) this.paths[path] = {};
|
|
359
|
-
|
|
360
|
-
this.paths[path][http.type] = {
|
|
364
|
+
this.paths[path][http.method] = {
|
|
361
365
|
summary: config.summary,
|
|
362
366
|
description: config.description,
|
|
363
367
|
tags: config.tags || [
|
|
@@ -370,35 +374,35 @@ var OpenAPIGenerator = (_class6 = class extends Generator {constructor(...args5)
|
|
|
370
374
|
};
|
|
371
375
|
}
|
|
372
376
|
generateCode(meta) {
|
|
373
|
-
meta.forEach(({ data }) => {
|
|
374
|
-
if (data.controller === "http") this.addMethod(data);
|
|
377
|
+
meta.forEach(({ data, model }) => {
|
|
378
|
+
if (data.controller === "http") this.addMethod(data, model);
|
|
375
379
|
});
|
|
376
380
|
return this.getContent();
|
|
377
381
|
}
|
|
378
|
-
},
|
|
382
|
+
}, _class7);
|
|
379
383
|
|
|
380
384
|
// src/generator/doc.ts
|
|
381
|
-
var DocGenerator = (
|
|
385
|
+
var DocGenerator = (_class8 = class extends Generator {
|
|
382
386
|
static {
|
|
383
387
|
_chunk4LLLQOMFjs.__name.call(void 0, this, "DocGenerator");
|
|
384
388
|
}
|
|
385
|
-
|
|
386
|
-
|
|
389
|
+
__init12() {this.name = "DOC"}
|
|
390
|
+
__init13() {this.classMap = {}}
|
|
387
391
|
constructor(path) {
|
|
388
|
-
super(path || ".ps/doc.json");
|
|
392
|
+
super(path || ".ps/doc.json");_class8.prototype.__init12.call(this);_class8.prototype.__init13.call(this);;
|
|
389
393
|
}
|
|
390
394
|
getContent() {
|
|
391
395
|
return JSON.stringify(this.classMap);
|
|
392
396
|
}
|
|
393
397
|
addMethod(data) {
|
|
394
|
-
const { name,
|
|
395
|
-
if (!
|
|
398
|
+
const { name, method, meta } = data;
|
|
399
|
+
if (!meta.doc) return;
|
|
396
400
|
if (!this.classMap[name]) this.classMap[name] = {};
|
|
397
|
-
this.classMap[name][
|
|
398
|
-
doc:
|
|
399
|
-
params: data.params.filter((item) => item.
|
|
401
|
+
this.classMap[name][method] = {
|
|
402
|
+
doc: meta.doc,
|
|
403
|
+
params: data.params.filter((item) => item.meta.doc).map((item) => {
|
|
400
404
|
return {
|
|
401
|
-
doc: item.
|
|
405
|
+
doc: item.meta.doc,
|
|
402
406
|
index: item.index
|
|
403
407
|
};
|
|
404
408
|
})
|
|
@@ -410,7 +414,43 @@ var DocGenerator = (_class7 = class extends Generator {
|
|
|
410
414
|
});
|
|
411
415
|
return this.getContent();
|
|
412
416
|
}
|
|
413
|
-
},
|
|
417
|
+
}, _class8);
|
|
418
|
+
|
|
419
|
+
// src/generator/graph.ts
|
|
420
|
+
|
|
421
|
+
var GraphGenerator = (_class9 = class extends Generator {constructor(...args6) { super(...args6); _class9.prototype.__init14.call(this);_class9.prototype.__init15.call(this); }
|
|
422
|
+
static {
|
|
423
|
+
_chunk4LLLQOMFjs.__name.call(void 0, this, "GraphGenerator");
|
|
424
|
+
}
|
|
425
|
+
__init14() {this.ext = ".mmd"}
|
|
426
|
+
__init15() {this.name = "Graph"}
|
|
427
|
+
generateCode(meta) {
|
|
428
|
+
const edges = /* @__PURE__ */ new Set();
|
|
429
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
430
|
+
meta.forEach(({ model }) => {
|
|
431
|
+
const from = String(_phecdacore.getTag.call(void 0, model));
|
|
432
|
+
nodes.add(from);
|
|
433
|
+
const paramTypes = Reflect.getMetadata("design:paramtypes", model) || [];
|
|
434
|
+
paramTypes.forEach((dep) => {
|
|
435
|
+
const to = String(_phecdacore.getTag.call(void 0, dep));
|
|
436
|
+
if (to && to !== from) {
|
|
437
|
+
nodes.add(to);
|
|
438
|
+
edges.add(`${to} --> ${from}`);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
let result = "graph TD\n";
|
|
443
|
+
nodes.forEach((n) => {
|
|
444
|
+
result += ` ${String(n)}
|
|
445
|
+
`;
|
|
446
|
+
});
|
|
447
|
+
edges.forEach((e) => {
|
|
448
|
+
result += ` ${e}
|
|
449
|
+
`;
|
|
450
|
+
});
|
|
451
|
+
return result;
|
|
452
|
+
}
|
|
453
|
+
}, _class9);
|
|
414
454
|
|
|
415
455
|
// src/index.ts
|
|
416
456
|
|
|
@@ -497,4 +537,5 @@ var DocGenerator = (_class7 = class extends Generator {
|
|
|
497
537
|
|
|
498
538
|
|
|
499
539
|
|
|
500
|
-
|
|
540
|
+
|
|
541
|
+
exports.Addon = _chunkUYZSUBX4js.Addon; exports.ApiDoc = _chunkUYZSUBX4js.ApiDoc; exports.Arg = _chunkUYZSUBX4js.Arg; exports.BadGatewayException = _chunkYJ3QHGTCjs.BadGatewayException; exports.BadRequestException = _chunkYJ3QHGTCjs.BadRequestException; exports.BaseParam = _chunkUYZSUBX4js.BaseParam; exports.Body = _chunkUYZSUBX4js.Body; exports.ConflictException = _chunkYJ3QHGTCjs.ConflictException; exports.Context = _chunkYJ3QHGTCjs.Context; exports.Controller = _chunkUYZSUBX4js.Controller; exports.Ctx = _chunkUYZSUBX4js.Ctx; exports.CustomResponse = CustomResponse; exports.Define = _chunkUYZSUBX4js.Define; exports.Delete = _chunkUYZSUBX4js.Delete; exports.DocGenerator = DocGenerator; exports.ERROR_SYMBOL = _chunk4LLLQOMFjs.ERROR_SYMBOL; exports.Exception = _chunkYJ3QHGTCjs.Exception; exports.Factory = _chunkOLNN4U3Ojs.Factory; exports.Filter = _chunkUYZSUBX4js.Filter; exports.ForbiddenException = _chunkYJ3QHGTCjs.ForbiddenException; exports.FrameworkException = _chunkYJ3QHGTCjs.FrameworkException; exports.Generator = Generator; exports.Get = _chunkUYZSUBX4js.Get; exports.GraphGenerator = GraphGenerator; exports.Guard = _chunkUYZSUBX4js.Guard; exports.HTTPGenerator = HTTPGenerator; exports.Head = _chunkUYZSUBX4js.Head; exports.Header = _chunkUYZSUBX4js.Header; exports.HttpBase = HttpBase; exports.IS_DEV = _chunk4LLLQOMFjs.IS_DEV; exports.IS_ONLY_GENERATE = _chunk4LLLQOMFjs.IS_ONLY_GENERATE; exports.IS_PURE = _chunk4LLLQOMFjs.IS_PURE; exports.IS_STRICT = _chunk4LLLQOMFjs.IS_STRICT; exports.InvalidInputException = _chunkYJ3QHGTCjs.InvalidInputException; exports.LOG_LEVEL = _chunk4LLLQOMFjs.LOG_LEVEL; exports.ManyFiles = _chunkUYZSUBX4js.ManyFiles; exports.Meta = _chunkOLNN4U3Ojs.Meta; exports.Mixin = _chunk4LLLQOMFjs.Mixin; exports.NotFoundException = _chunkYJ3QHGTCjs.NotFoundException; exports.OneFile = _chunkUYZSUBX4js.OneFile; exports.OpenAPIGenerator = OpenAPIGenerator; exports.PAddon = PAddon; exports.PExtension = PExtension; exports.PFilter = PFilter; exports.PGuard = PGuard; exports.PPipe = PPipe; exports.PS_EXIT_CODE = _chunk4LLLQOMFjs.PS_EXIT_CODE; exports.Param = _chunkUYZSUBX4js.Param; exports.Patch = _chunkUYZSUBX4js.Patch; exports.PayloadLargeException = _chunkYJ3QHGTCjs.PayloadLargeException; exports.Pipe = _chunkUYZSUBX4js.Pipe; exports.Post = _chunkUYZSUBX4js.Post; exports.Put = _chunkUYZSUBX4js.Put; exports.Query = _chunkUYZSUBX4js.Query; exports.Queue = _chunkUYZSUBX4js.Queue; exports.RPCGenerator = RPCGenerator; exports.Route = _chunkUYZSUBX4js.Route; exports.Rpc = _chunkUYZSUBX4js.Rpc; exports.RpcBase = RpcBase; exports.Search = _chunkUYZSUBX4js.Search; exports.ServerBase = ServerBase; exports.ServerPhecda = _chunkOLNN4U3Ojs.ServerPhecda; exports.ServiceUnavailableException = _chunkYJ3QHGTCjs.ServiceUnavailableException; exports.TimeoutException = _chunkYJ3QHGTCjs.TimeoutException; exports.TimerException = _chunkYJ3QHGTCjs.TimerException; exports.UnauthorizedException = _chunkYJ3QHGTCjs.UnauthorizedException; exports.UndefinedException = _chunkYJ3QHGTCjs.UndefinedException; exports.UnsupportedMediaTypeException = _chunkYJ3QHGTCjs.UnsupportedMediaTypeException; exports.ValidateException = _chunkYJ3QHGTCjs.ValidateException; exports.WorkerException = _chunkYJ3QHGTCjs.WorkerException; exports.addAddon = _chunkYJ3QHGTCjs.addAddon; exports.addFilter = _chunkYJ3QHGTCjs.addFilter; exports.addGuard = _chunkYJ3QHGTCjs.addGuard; exports.addPipe = _chunkYJ3QHGTCjs.addPipe; exports.defaultPipe = _chunkYJ3QHGTCjs.defaultPipe; exports.defaultServerInject = _chunkOLNN4U3Ojs.defaultServerInject; exports.emitter = _chunkOLNN4U3Ojs.emitter; exports.getLogger = _chunk4LLLQOMFjs.getLogger; exports.log = _chunk4LLLQOMFjs.log; exports.phecdaNamespace = _chunkOLNN4U3Ojs.phecdaNamespace; exports.runMiddleware = _chunk4LLLQOMFjs.runMiddleware; exports.setLogger = _chunk4LLLQOMFjs.setLogger; exports.useS = _chunkOLNN4U3Ojs.useS;
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
emitter,
|
|
7
7
|
phecdaNamespace,
|
|
8
8
|
useS
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-PFPOEZHH.mjs";
|
|
10
10
|
import {
|
|
11
11
|
Addon,
|
|
12
12
|
ApiDoc,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
Route,
|
|
35
35
|
Rpc,
|
|
36
36
|
Search
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-FI5756JX.mjs";
|
|
38
38
|
import {
|
|
39
39
|
BadGatewayException,
|
|
40
40
|
BadRequestException,
|
|
@@ -60,7 +60,7 @@ import {
|
|
|
60
60
|
addPipe,
|
|
61
61
|
defaultPipe,
|
|
62
62
|
joinUrl
|
|
63
|
-
} from "./chunk-
|
|
63
|
+
} from "./chunk-VAHCYYCB.mjs";
|
|
64
64
|
import {
|
|
65
65
|
ERROR_SYMBOL,
|
|
66
66
|
IS_DEV,
|
|
@@ -247,8 +247,9 @@ var Generator = class {
|
|
|
247
247
|
constructor(path) {
|
|
248
248
|
if (path) this._path = path;
|
|
249
249
|
}
|
|
250
|
+
ext = ".js";
|
|
250
251
|
get path() {
|
|
251
|
-
return this._path || `.ps/${this.name.toLowerCase()}.
|
|
252
|
+
return this._path || `.ps/${this.name.toLowerCase()}${this.ext}`;
|
|
252
253
|
}
|
|
253
254
|
async output(meta) {
|
|
254
255
|
await fse.outputFile(this.path, this.generateCode(meta));
|
|
@@ -273,12 +274,12 @@ var RPCGenerator = class extends Generator {
|
|
|
273
274
|
return content;
|
|
274
275
|
}
|
|
275
276
|
addMethod(args) {
|
|
276
|
-
const { rpc, name,
|
|
277
|
+
const { rpc, name, method, tag } = args;
|
|
277
278
|
if (!rpc) return;
|
|
278
279
|
if (!this.classMap[name]) this.classMap[name] = {};
|
|
279
|
-
this.classMap[name][
|
|
280
|
-
${
|
|
281
|
-
return {tag:'${tag}',
|
|
280
|
+
this.classMap[name][method] = `
|
|
281
|
+
${method}(){
|
|
282
|
+
return {tag:'${tag}',method:"${method}",isEvent:${!!rpc.isEvent},queue:"${rpc.queue || ""}"}
|
|
282
283
|
|
|
283
284
|
}
|
|
284
285
|
`;
|
|
@@ -309,17 +310,18 @@ var HTTPGenerator = class extends Generator {
|
|
|
309
310
|
return content;
|
|
310
311
|
}
|
|
311
312
|
addMethod(args) {
|
|
312
|
-
const { http, name,
|
|
313
|
-
if (!http?.
|
|
313
|
+
const { http, name, method, params, tag } = args;
|
|
314
|
+
if (!http?.method) return;
|
|
314
315
|
const url = joinUrl(http.prefix, http.route).replace(/\/\:([^\/]*)/g, (_, js) => `/{{${js}}}`);
|
|
315
316
|
if (!this.classMap[name]) this.classMap[name] = {};
|
|
316
|
-
this.classMap[name][
|
|
317
|
-
${
|
|
318
|
-
|
|
319
|
-
|
|
317
|
+
this.classMap[name][method] = `
|
|
318
|
+
${method}(...args){
|
|
319
|
+
let url="${url}"
|
|
320
|
+
const ret={tag:"${tag}",method:"${method}",body:{},headers:{},query:{},params:{}}
|
|
320
321
|
${params.reduce((p, c, i) => `${p}ret.${c.type}${c.key ? `['${c.key}']` : ""}=args[${i}]
|
|
321
|
-
${c.type === "params" ? `
|
|
322
|
+
${c.type === "params" ? `url=url.replace('{{${c.key}}}',args[${i}])` : ""}
|
|
322
323
|
`, "")}
|
|
324
|
+
ret.http={method:"${http.method}",url}
|
|
323
325
|
return ret
|
|
324
326
|
}
|
|
325
327
|
`;
|
|
@@ -338,6 +340,7 @@ var OpenAPIGenerator = class extends Generator {
|
|
|
338
340
|
static {
|
|
339
341
|
__name(this, "OpenAPIGenerator");
|
|
340
342
|
}
|
|
343
|
+
ext = ".json";
|
|
341
344
|
name = "OpenAPI";
|
|
342
345
|
paths = {};
|
|
343
346
|
getContent() {
|
|
@@ -351,13 +354,14 @@ var OpenAPIGenerator = class extends Generator {
|
|
|
351
354
|
paths: this.paths
|
|
352
355
|
});
|
|
353
356
|
}
|
|
354
|
-
addMethod(args) {
|
|
355
|
-
const { http, tag,
|
|
356
|
-
if (!http?.
|
|
357
|
+
addMethod(args, model) {
|
|
358
|
+
const { http, tag, method } = args;
|
|
359
|
+
if (!http?.method) return;
|
|
360
|
+
const config = getMergedMeta(model, method).openapi;
|
|
361
|
+
if (!config) return;
|
|
357
362
|
const path = joinUrl(http.prefix, http.route);
|
|
358
363
|
if (!this.paths[path]) this.paths[path] = {};
|
|
359
|
-
|
|
360
|
-
this.paths[path][http.type] = {
|
|
364
|
+
this.paths[path][http.method] = {
|
|
361
365
|
summary: config.summary,
|
|
362
366
|
description: config.description,
|
|
363
367
|
tags: config.tags || [
|
|
@@ -370,8 +374,8 @@ var OpenAPIGenerator = class extends Generator {
|
|
|
370
374
|
};
|
|
371
375
|
}
|
|
372
376
|
generateCode(meta) {
|
|
373
|
-
meta.forEach(({ data }) => {
|
|
374
|
-
if (data.controller === "http") this.addMethod(data);
|
|
377
|
+
meta.forEach(({ data, model }) => {
|
|
378
|
+
if (data.controller === "http") this.addMethod(data, model);
|
|
375
379
|
});
|
|
376
380
|
return this.getContent();
|
|
377
381
|
}
|
|
@@ -391,14 +395,14 @@ var DocGenerator = class extends Generator {
|
|
|
391
395
|
return JSON.stringify(this.classMap);
|
|
392
396
|
}
|
|
393
397
|
addMethod(data) {
|
|
394
|
-
const { name,
|
|
395
|
-
if (!
|
|
398
|
+
const { name, method, meta } = data;
|
|
399
|
+
if (!meta.doc) return;
|
|
396
400
|
if (!this.classMap[name]) this.classMap[name] = {};
|
|
397
|
-
this.classMap[name][
|
|
398
|
-
doc:
|
|
399
|
-
params: data.params.filter((item) => item.
|
|
401
|
+
this.classMap[name][method] = {
|
|
402
|
+
doc: meta.doc,
|
|
403
|
+
params: data.params.filter((item) => item.meta.doc).map((item) => {
|
|
400
404
|
return {
|
|
401
|
-
doc: item.
|
|
405
|
+
doc: item.meta.doc,
|
|
402
406
|
index: item.index
|
|
403
407
|
};
|
|
404
408
|
})
|
|
@@ -412,6 +416,42 @@ var DocGenerator = class extends Generator {
|
|
|
412
416
|
}
|
|
413
417
|
};
|
|
414
418
|
|
|
419
|
+
// src/generator/graph.ts
|
|
420
|
+
import { getTag as getTag6 } from "phecda-core";
|
|
421
|
+
var GraphGenerator = class extends Generator {
|
|
422
|
+
static {
|
|
423
|
+
__name(this, "GraphGenerator");
|
|
424
|
+
}
|
|
425
|
+
ext = ".mmd";
|
|
426
|
+
name = "Graph";
|
|
427
|
+
generateCode(meta) {
|
|
428
|
+
const edges = /* @__PURE__ */ new Set();
|
|
429
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
430
|
+
meta.forEach(({ model }) => {
|
|
431
|
+
const from = String(getTag6(model));
|
|
432
|
+
nodes.add(from);
|
|
433
|
+
const paramTypes = Reflect.getMetadata("design:paramtypes", model) || [];
|
|
434
|
+
paramTypes.forEach((dep) => {
|
|
435
|
+
const to = String(getTag6(dep));
|
|
436
|
+
if (to && to !== from) {
|
|
437
|
+
nodes.add(to);
|
|
438
|
+
edges.add(`${to} --> ${from}`);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
let result = "graph TD\n";
|
|
443
|
+
nodes.forEach((n) => {
|
|
444
|
+
result += ` ${String(n)}
|
|
445
|
+
`;
|
|
446
|
+
});
|
|
447
|
+
edges.forEach((e) => {
|
|
448
|
+
result += ` ${e}
|
|
449
|
+
`;
|
|
450
|
+
});
|
|
451
|
+
return result;
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
|
|
415
455
|
// src/index.ts
|
|
416
456
|
export * from "phecda-core";
|
|
417
457
|
export {
|
|
@@ -438,6 +478,7 @@ export {
|
|
|
438
478
|
FrameworkException,
|
|
439
479
|
Generator,
|
|
440
480
|
Get,
|
|
481
|
+
GraphGenerator,
|
|
441
482
|
Guard,
|
|
442
483
|
HTTPGenerator,
|
|
443
484
|
Head,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Events } from 'phecda-core';
|
|
1
|
+
import { Events, Construct } from 'phecda-core';
|
|
2
2
|
|
|
3
3
|
declare const ERROR_SYMBOL = "__PS_ERROR__";
|
|
4
4
|
declare const IS_DEV: boolean;
|
|
@@ -23,7 +23,7 @@ interface BaseCtx {
|
|
|
23
23
|
moduleMap: Record<string, any>;
|
|
24
24
|
type: string;
|
|
25
25
|
tag: string;
|
|
26
|
-
|
|
26
|
+
method: string;
|
|
27
27
|
category: string;
|
|
28
28
|
[key: string]: any;
|
|
29
29
|
}
|
|
@@ -39,24 +39,24 @@ interface BaseError {
|
|
|
39
39
|
message: string;
|
|
40
40
|
description: string;
|
|
41
41
|
}
|
|
42
|
-
type
|
|
42
|
+
type BaseRequestMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options';
|
|
43
43
|
declare class CustomResponse<Value> {
|
|
44
44
|
_ps_response: Value;
|
|
45
45
|
}
|
|
46
46
|
type ExtractResponse<Class extends CustomResponse<any>> = Class extends CustomResponse<infer Value> ? Value : never;
|
|
47
47
|
|
|
48
48
|
interface ServiceMetaData {
|
|
49
|
-
|
|
49
|
+
method: string;
|
|
50
50
|
name: string;
|
|
51
51
|
tag: string;
|
|
52
52
|
define?: any;
|
|
53
|
-
|
|
53
|
+
meta: any;
|
|
54
54
|
[key: string]: any;
|
|
55
55
|
}
|
|
56
56
|
interface ControllerMetaData extends ServiceMetaData {
|
|
57
57
|
controller: string;
|
|
58
58
|
http?: {
|
|
59
|
-
|
|
59
|
+
method: BaseRequestMethod;
|
|
60
60
|
prefix: string;
|
|
61
61
|
route: string;
|
|
62
62
|
headers?: Record<string, string>;
|
|
@@ -72,7 +72,7 @@ interface ControllerMetaData extends ServiceMetaData {
|
|
|
72
72
|
key: string;
|
|
73
73
|
pipe?: string;
|
|
74
74
|
define: Record<string, any>;
|
|
75
|
-
|
|
75
|
+
meta: any;
|
|
76
76
|
}[];
|
|
77
77
|
guards: string[];
|
|
78
78
|
pipe?: string;
|
|
@@ -83,10 +83,12 @@ type MetaData = ControllerMetaData | ServiceMetaData;
|
|
|
83
83
|
declare class Meta {
|
|
84
84
|
data: MetaData;
|
|
85
85
|
paramsType: any[];
|
|
86
|
-
|
|
86
|
+
module: any;
|
|
87
|
+
model: Construct;
|
|
88
|
+
constructor(data: MetaData, paramsType: any[], module: any, model: Construct);
|
|
87
89
|
}
|
|
88
90
|
interface ControllerMeta extends Meta {
|
|
89
91
|
data: ControllerMetaData;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
export { type BaseCtx as B, CustomResponse as C, type DefaultOptions as D, type Emitter as E, IS_DEV as I, LOG_LEVEL as L, Meta as M, PS_EXIT_CODE as P, type ServiceMetaData as S, type ControllerMeta as a, type ControllerMetaData as b, type BaseError as c, type
|
|
94
|
+
export { type BaseCtx as B, CustomResponse as C, type DefaultOptions as D, type Emitter as E, IS_DEV as I, LOG_LEVEL as L, Meta as M, PS_EXIT_CODE as P, type ServiceMetaData as S, type ControllerMeta as a, type ControllerMetaData as b, type BaseError as c, type BaseRequestMethod as d, type ExtractResponse as e, type MetaData as f, ERROR_SYMBOL as g, IS_ONLY_GENERATE as h, IS_STRICT as i, IS_PURE as j };
|