phecda-server 5.0.0-beta.26 → 5.0.0-beta.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/bin/cli.js +10 -78
  2. package/dist/{chunk-LEP6MMFD.js → chunk-AXVIBJIO.js} +3 -3
  3. package/dist/{chunk-3HC6NOU4.mjs → chunk-CUQYRXDG.mjs} +3 -176
  4. package/dist/{chunk-XDKIHIO7.js → chunk-H2HJGEP3.js} +2 -2
  5. package/dist/{chunk-JCJY474C.js → chunk-L3LQEK6K.js} +11 -3
  6. package/dist/{chunk-NGIT3MFT.js → chunk-O5LFW6ZX.js} +72 -54
  7. package/dist/{chunk-A5ZVLFVC.mjs → chunk-QFLHLRZZ.mjs} +20 -2
  8. package/dist/{chunk-CWWDF2XM.mjs → chunk-S6AGWZHN.mjs} +11 -3
  9. package/dist/{chunk-Q22XENNV.mjs → chunk-TH3UGMLB.mjs} +1 -1
  10. package/dist/chunk-TTX62TN2.js +256 -0
  11. package/dist/{chunk-NFXZ2GOU.js → chunk-UJ22UWCG.js} +3 -3
  12. package/dist/{chunk-JLCVUZMA.js → chunk-VHNOSAEH.js} +39 -37
  13. package/dist/{chunk-MNU4PVTO.mjs → chunk-XFQLK4PF.mjs} +1 -1
  14. package/dist/{chunk-R32D5D5N.mjs → chunk-YYCBQHC6.mjs} +20 -18
  15. package/dist/{chunk-CBOR4TIF.mjs → chunk-Z7HN4EP5.mjs} +1 -1
  16. package/dist/{core-cee9c690.d.ts → core-7ca25b11.d.ts} +9 -4
  17. package/dist/{helper-290e001c.d.ts → helper-c0bd32b2.d.ts} +1 -1
  18. package/dist/index.d.ts +13 -5
  19. package/dist/index.js +165 -8
  20. package/dist/index.mjs +177 -20
  21. package/dist/rpc/bullmq/index.d.ts +1 -1
  22. package/dist/rpc/bullmq/index.js +26 -26
  23. package/dist/rpc/bullmq/index.mjs +15 -15
  24. package/dist/rpc/kafka/index.d.ts +1 -1
  25. package/dist/rpc/kafka/index.js +23 -23
  26. package/dist/rpc/kafka/index.mjs +12 -12
  27. package/dist/rpc/nats/index.d.ts +1 -1
  28. package/dist/rpc/nats/index.js +21 -21
  29. package/dist/rpc/nats/index.mjs +11 -11
  30. package/dist/rpc/rabbitmq/index.d.ts +1 -1
  31. package/dist/rpc/rabbitmq/index.js +39 -36
  32. package/dist/rpc/rabbitmq/index.mjs +27 -24
  33. package/dist/rpc/redis/index.d.ts +1 -1
  34. package/dist/rpc/redis/index.js +23 -23
  35. package/dist/rpc/redis/index.mjs +12 -12
  36. package/dist/server/express/index.d.ts +2 -2
  37. package/dist/server/express/index.js +41 -39
  38. package/dist/server/express/index.mjs +19 -17
  39. package/dist/server/fastify/index.d.ts +2 -3
  40. package/dist/server/fastify/index.js +44 -46
  41. package/dist/server/fastify/index.mjs +21 -23
  42. package/dist/server/h3/index.d.ts +1 -1
  43. package/dist/server/h3/index.js +38 -36
  44. package/dist/server/h3/index.mjs +19 -17
  45. package/dist/server/hyper-express/index.d.ts +2 -2
  46. package/dist/server/hyper-express/index.js +41 -39
  47. package/dist/server/hyper-express/index.mjs +19 -17
  48. package/dist/server/koa/index.d.ts +2 -2
  49. package/dist/server/koa/index.js +41 -39
  50. package/dist/server/koa/index.mjs +19 -17
  51. package/dist/test.d.ts +1 -1
  52. package/dist/test.js +9 -9
  53. package/dist/test.mjs +5 -5
  54. package/package.json +1 -1
  55. package/register/loader.mjs +0 -2
  56. package/dist/chunk-4PPLKCJH.js +0 -429
package/bin/cli.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const { fork } = require('child_process')
2
2
 
3
3
  const fs = require('fs')
4
- const { posix } = require('path')
5
4
  const pc = require('picocolors')
6
5
  const cmd = process.argv.slice(2)
7
6
 
@@ -31,6 +30,10 @@ function startChild() {
31
30
 
32
31
  closePromise = new Promise((resolve) => {
33
32
  child.once('exit', (code) => {
33
+ if (code === 4) {
34
+ log('only generate code')
35
+ process.exit(0)
36
+ }
34
37
  if (code >= 2) {
35
38
  // for relaunch
36
39
  log('relaunch...')
@@ -67,6 +70,7 @@ function log(msg, color = 'green') {
67
70
  )} ${pc[color](msg)}`,
68
71
  )
69
72
  }
73
+
70
74
  if (cmd[0] === 'init') {
71
75
  fs.writeFileSync('tsconfig.json', `{
72
76
  "compilerOptions": {
@@ -94,24 +98,16 @@ if (cmd[0] === 'init') {
94
98
 
95
99
  log('init tsconfig.json!')
96
100
  }
101
+ else if (cmd[0] === 'code') {
102
+ process.env.PS_CODE = 'true'
103
+ cmd.splice(0, 1)
104
+ startChild()
105
+ }
97
106
  else {
98
107
  startChild()
99
108
  log('process start!')
100
109
  console.log(`${pc.green('->')} press ${pc.green('e')} to exit`)
101
110
  console.log(`${pc.green('->')} press ${pc.green('r')} to relaunch`)
102
- console.log(
103
- `${pc.green('->')} press ${pc.green(
104
- 'c {moduleName} {dir}',
105
- )} to create controller`,
106
- )
107
- console.log(
108
- `${pc.green('->')} press ${pc.green(
109
- 's {moduleName} {dir}',
110
- )} to create service`,
111
- )
112
- console.log(
113
- `${pc.green('->')} press ${pc.green('m {moduleName} {dir}')} to create module`,
114
- )
115
111
 
116
112
  process.stdin.on('data', async (data) => {
117
113
  const input = data.toString().trim().toLocaleLowerCase()
@@ -131,69 +127,5 @@ else {
131
127
  }
132
128
  if (input === 'e')
133
129
  exit()
134
-
135
- if (input.startsWith('c ')) {
136
- let [, module, dir] = input.split(' ')
137
- module = toCamelCase(module)
138
- const path = posix.join(dir, `${module}.controller.ts`)
139
- fs.writeFile(
140
- path,
141
- `
142
- export class ${module[0].toUpperCase()}${module.slice(1)}Controller{
143
-
144
- }
145
- `,
146
- (err) => {
147
- if (err)
148
- log('writeFile filled', 'red')
149
- else log(`create controller at ${path}`)
150
- },
151
- )
152
- }
153
- if (input.startsWith('s ')) {
154
- let [, module, dir] = input.split(' ')
155
- module = toCamelCase(module)
156
- const path = posix.join(dir, `${module}.service.ts`)
157
- fs.writeFile(
158
- path,
159
- `
160
- import {Tag} from 'phecda-server'
161
- @Tag('${module}')
162
- export class ${module[0].toUpperCase()}${module.slice(1)}Service{
163
-
164
- }
165
- `,
166
- (err) => {
167
- if (err)
168
- log('writeFile filled', 'red')
169
- else log(`create service at ${path}`)
170
- },
171
- )
172
- }
173
-
174
- if (input.startsWith('m ')) {
175
- let [, module, dir] = input.split(' ')
176
- module = toCamelCase(module)
177
- const path = posix.join(dir, `${module}.module.ts`)
178
- fs.writeFile(
179
- path,
180
- `
181
- import {Tag} from 'phecda-server'
182
- @Tag('${module}')
183
- export class ${module[0].toUpperCase()}${module.slice(1)}Module{
184
-
185
- }
186
- `,
187
- (err) => {
188
- if (err)
189
- log('writeFile filled', 'red')
190
- else log(`create module at ${path}`)
191
- },
192
- )
193
- }
194
130
  })
195
131
  }
196
-
197
- function toCamelCase(str) {
198
- return str.replace(/[-_]\w/g, match => match.charAt(1).toUpperCase())
199
- }
@@ -1,6 +1,6 @@
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 _chunkJCJY474Cjs = require('./chunk-JCJY474C.js');
3
+ var _chunkL3LQEK6Kjs = require('./chunk-L3LQEK6K.js');
4
4
 
5
5
  // src/server/helper.ts
6
6
  function resolveDep(ret, key) {
@@ -8,7 +8,7 @@ function resolveDep(ret, key) {
8
8
  return _optionalChain([ret, 'optionalAccess', _ => _[key]]);
9
9
  return ret;
10
10
  }
11
- _chunkJCJY474Cjs.__name.call(void 0, resolveDep, "resolveDep");
11
+ _chunkL3LQEK6Kjs.__name.call(void 0, resolveDep, "resolveDep");
12
12
  function argToReq(params, args, headers) {
13
13
  const req = {
14
14
  body: {},
@@ -24,7 +24,7 @@ function argToReq(params, args, headers) {
24
24
  });
25
25
  return req;
26
26
  }
27
- _chunkJCJY474Cjs.__name.call(void 0, argToReq, "argToReq");
27
+ _chunkL3LQEK6Kjs.__name.call(void 0, argToReq, "argToReq");
28
28
 
29
29
 
30
30
 
@@ -1,18 +1,6 @@
1
1
  import {
2
- Context,
3
- addFilter,
4
- addGuard,
5
- addInterceptor,
6
- addPipe,
7
- addPlugin
8
- } from "./chunk-A5ZVLFVC.mjs";
9
- import {
10
- UNMOUNT_SYMBOL,
11
2
  __name
12
- } from "./chunk-CWWDF2XM.mjs";
13
-
14
- // src/decorators/index.ts
15
- import { SHARE_KEY as SHARE_KEY3, getOwnState as getOwnState4, set, setState as setState4, setStateKey as setStateKey4 } from "phecda-core";
3
+ } from "./chunk-S6AGWZHN.mjs";
16
4
 
17
5
  // src/decorators/param.ts
18
6
  import { getOwnState, setState, setStateKey } from "phecda-core";
@@ -209,6 +197,7 @@ function Filter(filter) {
209
197
  __name(Filter, "Filter");
210
198
 
211
199
  // src/decorators/index.ts
200
+ import { SHARE_KEY as SHARE_KEY3, getOwnState as getOwnState4, set, setState as setState4, setStateKey as setStateKey4 } from "phecda-core";
212
201
  function Header(name, value) {
213
202
  return (target, k) => {
214
203
  setStateKey4(target, k);
@@ -240,161 +229,6 @@ function Define(key, value) {
240
229
  }
241
230
  __name(Define, "Define");
242
231
 
243
- // src/index.ts
244
- export * from "phecda-core";
245
-
246
- // src/modules/dev.ts
247
- import { Empty, Unmount } from "phecda-core";
248
- var __decorate = function(decorators, target, key, desc) {
249
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
250
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
251
- r = Reflect.decorate(decorators, target, key, desc);
252
- else
253
- for (var i = decorators.length - 1; i >= 0; i--)
254
- if (d = decorators[i])
255
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
256
- return c > 3 && r && Object.defineProperty(target, key, r), r;
257
- };
258
- var __metadata = function(k, v) {
259
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
260
- return Reflect.metadata(k, v);
261
- };
262
- var Dev = /* @__PURE__ */ __name(class Dev2 {
263
- [UNMOUNT_SYMBOL] = [];
264
- context;
265
- onUnmount(cb) {
266
- this[UNMOUNT_SYMBOL].push(cb);
267
- }
268
- async unmount() {
269
- for (const cb of this[UNMOUNT_SYMBOL])
270
- await cb();
271
- }
272
- }, "Dev");
273
- __decorate([
274
- Unmount,
275
- __metadata("design:type", Function),
276
- __metadata("design:paramtypes", [])
277
- ], Dev.prototype, "unmount", null);
278
- Dev = __decorate([
279
- Empty
280
- ], Dev);
281
-
282
- // src/modules/filter.ts
283
- import { getTag } from "phecda-core";
284
- var PFilter = class extends Dev {
285
- key;
286
- constructor(tag) {
287
- super();
288
- this.key = tag || getTag(this);
289
- addFilter(this.key, this.use.bind(this));
290
- this.onUnmount(() => {
291
- delete Context.filterRecord[this.key];
292
- });
293
- }
294
- };
295
- __name(PFilter, "PFilter");
296
-
297
- // src/modules/guard.ts
298
- import { getTag as getTag2 } from "phecda-core";
299
- var PGuard = class extends Dev {
300
- key;
301
- constructor(tag) {
302
- super();
303
- this.key = tag || getTag2(this);
304
- addGuard(this.key, this.use.bind(this));
305
- this.onUnmount(() => {
306
- delete Context.guardRecord[this.key];
307
- });
308
- }
309
- };
310
- __name(PGuard, "PGuard");
311
-
312
- // src/modules/interceptor.ts
313
- import { getTag as getTag3 } from "phecda-core";
314
- var PInterceptor = class extends Dev {
315
- key;
316
- constructor(tag) {
317
- super();
318
- this.key = tag || getTag3(this);
319
- this.onUnmount(() => {
320
- delete Context.interceptorRecord[this.key];
321
- });
322
- addInterceptor(this.key, this.use.bind(this));
323
- }
324
- };
325
- __name(PInterceptor, "PInterceptor");
326
-
327
- // src/modules/pipe.ts
328
- import { getTag as getTag4 } from "phecda-core";
329
- var PPipe = class extends Dev {
330
- key;
331
- constructor(tag) {
332
- super();
333
- this.key = tag || getTag4(this);
334
- addPipe(this.key, this.use.bind(this));
335
- this.onUnmount(() => {
336
- delete Context.pipeRecord[this.key];
337
- });
338
- }
339
- };
340
- __name(PPipe, "PPipe");
341
-
342
- // src/modules/plugin.ts
343
- import { getTag as getTag5 } from "phecda-core";
344
- var PPlugin = class extends Dev {
345
- key;
346
- constructor(tag) {
347
- super();
348
- this.key = tag || getTag5(this);
349
- addPlugin(this.key, this.use.bind(this));
350
- this.onUnmount(() => {
351
- delete Context.pluginRecord[this.key];
352
- });
353
- }
354
- };
355
- __name(PPlugin, "PPlugin");
356
-
357
- // src/modules/extension.ts
358
- import { getTag as getTag6 } from "phecda-core";
359
- var PExtension = class extends Dev {
360
- key;
361
- constructor(tag) {
362
- super();
363
- const key = this.key = tag || getTag6(this);
364
- if (this.pipe) {
365
- addPipe(key, this.pipe.bind(this));
366
- this.onUnmount(() => {
367
- delete Context.pipeRecord[key];
368
- });
369
- }
370
- if (this.plugin) {
371
- addPlugin(key, this.plugin.bind(this));
372
- this.onUnmount(() => {
373
- delete Context.pluginRecord[key];
374
- });
375
- }
376
- if (this.intercept) {
377
- addInterceptor(key, this.intercept.bind(this));
378
- this.onUnmount(() => {
379
- delete Context.interceptorRecord[key];
380
- });
381
- }
382
- if (this.guard) {
383
- addGuard(key, this.guard.bind(this));
384
- this.onUnmount(() => {
385
- delete Context.guardRecord[key];
386
- });
387
- }
388
- if (this.filter) {
389
- addFilter(key, this.filter.bind(this));
390
- this.onUnmount(() => {
391
- delete Context.filterRecord[key];
392
- });
393
- }
394
- }
395
- };
396
- __name(PExtension, "PExtension");
397
-
398
232
  export {
399
233
  BaseParam,
400
234
  Pipe,
@@ -418,12 +252,5 @@ export {
418
252
  Filter,
419
253
  Header,
420
254
  Ctx,
421
- Define,
422
- Dev,
423
- PFilter,
424
- PGuard,
425
- PInterceptor,
426
- PPipe,
427
- PPlugin,
428
- PExtension
255
+ Define
429
256
  };
@@ -1,13 +1,13 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkJCJY474Cjs = require('./chunk-JCJY474C.js');
3
+ var _chunkL3LQEK6Kjs = require('./chunk-L3LQEK6K.js');
4
4
 
5
5
  // src/rpc/helper.ts
6
6
  var _os = require('os');
7
7
  function genClientQueue(key) {
8
8
  return `PS-${key ? `${key}-` : ""}${_os.hostname.call(void 0, )}-${process.pid}`;
9
9
  }
10
- _chunkJCJY474Cjs.__name.call(void 0, genClientQueue, "genClientQueue");
10
+ _chunkL3LQEK6Kjs.__name.call(void 0, genClientQueue, "genClientQueue");
11
11
 
12
12
 
13
13
 
@@ -12,11 +12,17 @@ var UNMOUNT_SYMBOL = "__PS_UNMOUNT__";
12
12
  var MODULE_SYMBOL = "__PS_MODULE__";
13
13
  var META_SYMBOL = "__PS_META__";
14
14
  var PS_SYMBOL = "__PS__";
15
+ var ERROR_SYMBOL = "__PS_ERROR__";
15
16
  var IS_DEV = process.env.NODE_ENV === "development";
17
+ var IS_ONLY_CODE = !!process.env.PS_CODE;
16
18
  var IS_STRICT = !!process.env.PS_STRICT;
17
- var IS_LOG_BAN = !!process.env.PS_LOG_BAN;
18
- var ERROR_SYMBOL = "__PS_ERROR__";
19
+ var IS_LOG_BAN = !!process.env.PS_LOG_BAN || IS_ONLY_CODE;
19
20
  var PS_FILE_RE = /[^.](?:\.controller|service|module|extension|ext|guard|interceptor|plugin|filter|pipe|edge)\.ts$/i;
21
+ var PS_EXIT_CODE;
22
+ (function(PS_EXIT_CODE2) {
23
+ PS_EXIT_CODE2[PS_EXIT_CODE2["RELAUNCH"] = 2] = "RELAUNCH";
24
+ PS_EXIT_CODE2[PS_EXIT_CODE2["CODE"] = 4] = "CODE";
25
+ })(PS_EXIT_CODE || (PS_EXIT_CODE = exports.PS_EXIT_CODE = {}));
20
26
 
21
27
  // src/utils.ts
22
28
  var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
@@ -79,4 +85,6 @@ __name(Mix, "Mix");
79
85
 
80
86
 
81
87
 
82
- exports.__name = __name; exports.__publicField = __publicField; exports.MERGE_SYMBOL = MERGE_SYMBOL; exports.UNMOUNT_SYMBOL = UNMOUNT_SYMBOL; exports.MODULE_SYMBOL = MODULE_SYMBOL; exports.META_SYMBOL = META_SYMBOL; exports.PS_SYMBOL = PS_SYMBOL; exports.IS_DEV = IS_DEV; exports.IS_STRICT = IS_STRICT; exports.IS_LOG_BAN = IS_LOG_BAN; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.PS_FILE_RE = PS_FILE_RE; exports.log = log; exports.getConfig = getConfig; exports.setConfig = setConfig; exports.Mix = Mix;
88
+
89
+
90
+ exports.__name = __name; exports.__publicField = __publicField; exports.MERGE_SYMBOL = MERGE_SYMBOL; exports.UNMOUNT_SYMBOL = UNMOUNT_SYMBOL; exports.MODULE_SYMBOL = MODULE_SYMBOL; exports.META_SYMBOL = META_SYMBOL; exports.PS_SYMBOL = PS_SYMBOL; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.IS_DEV = IS_DEV; exports.IS_ONLY_CODE = IS_ONLY_CODE; exports.IS_STRICT = IS_STRICT; exports.IS_LOG_BAN = IS_LOG_BAN; exports.PS_FILE_RE = PS_FILE_RE; exports.PS_EXIT_CODE = PS_EXIT_CODE; exports.log = log; exports.getConfig = getConfig; exports.setConfig = setConfig; exports.Mix = Mix;