phecda-server 5.0.0-beta.25 → 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 (59) hide show
  1. package/bin/cli.js +10 -78
  2. package/dist/{chunk-XCXOCS2Z.js → chunk-AXVIBJIO.js} +3 -3
  3. package/dist/chunk-CUQYRXDG.mjs +256 -0
  4. package/dist/chunk-H2HJGEP3.js +14 -0
  5. package/dist/{chunk-PC6CFB6S.js → chunk-L3LQEK6K.js} +11 -5
  6. package/dist/{chunk-CGZDB67F.js → chunk-O5LFW6ZX.js} +72 -54
  7. package/dist/{chunk-5SGIQCRQ.mjs → chunk-QFLHLRZZ.mjs} +20 -2
  8. package/dist/{chunk-6UJL6PS3.mjs → chunk-S6AGWZHN.mjs} +12 -6
  9. package/dist/{chunk-LISNM5WU.mjs → chunk-TH3UGMLB.mjs} +1 -1
  10. package/dist/chunk-TTX62TN2.js +256 -0
  11. package/dist/{chunk-FJN6EM6U.js → chunk-UJ22UWCG.js} +3 -3
  12. package/dist/{chunk-LBYIXY22.js → chunk-VHNOSAEH.js} +41 -39
  13. package/dist/chunk-XFQLK4PF.mjs +14 -0
  14. package/dist/{chunk-WGVYHYYO.mjs → chunk-YYCBQHC6.mjs} +23 -21
  15. package/dist/{chunk-H2R7D4JG.mjs → chunk-Z7HN4EP5.mjs} +1 -1
  16. package/dist/{core-b5a99f34.d.ts → core-7ca25b11.d.ts} +10 -5
  17. package/dist/helper-9e206c66.d.ts +12 -0
  18. package/dist/{helper-705abda7.d.ts → helper-c0bd32b2.d.ts} +1 -1
  19. package/dist/index.d.ts +16 -8
  20. package/dist/index.js +67 -262
  21. package/dist/index.mjs +44 -239
  22. package/dist/rpc/bullmq/index.d.ts +18 -0
  23. package/dist/rpc/bullmq/index.js +225 -0
  24. package/dist/rpc/bullmq/index.mjs +225 -0
  25. package/dist/rpc/kafka/index.d.ts +4 -6
  26. package/dist/rpc/kafka/index.js +60 -55
  27. package/dist/rpc/kafka/index.mjs +51 -46
  28. package/dist/rpc/nats/index.d.ts +16 -0
  29. package/dist/rpc/nats/index.js +205 -0
  30. package/dist/rpc/nats/index.mjs +205 -0
  31. package/dist/rpc/rabbitmq/index.d.ts +4 -6
  32. package/dist/rpc/rabbitmq/index.js +111 -101
  33. package/dist/rpc/rabbitmq/index.mjs +101 -91
  34. package/dist/rpc/redis/index.d.ts +4 -6
  35. package/dist/rpc/redis/index.js +50 -44
  36. package/dist/rpc/redis/index.mjs +40 -34
  37. package/dist/server/express/index.d.ts +2 -2
  38. package/dist/server/express/index.js +41 -39
  39. package/dist/server/express/index.mjs +19 -17
  40. package/dist/server/fastify/index.d.ts +5 -4
  41. package/dist/server/fastify/index.js +50 -40
  42. package/dist/server/fastify/index.mjs +28 -18
  43. package/dist/server/h3/index.d.ts +1 -1
  44. package/dist/server/h3/index.js +38 -36
  45. package/dist/server/h3/index.mjs +19 -17
  46. package/dist/server/hyper-express/index.d.ts +2 -2
  47. package/dist/server/hyper-express/index.js +41 -39
  48. package/dist/server/hyper-express/index.mjs +19 -17
  49. package/dist/server/koa/index.d.ts +2 -2
  50. package/dist/server/koa/index.js +41 -39
  51. package/dist/server/koa/index.mjs +19 -17
  52. package/dist/test.d.ts +1 -1
  53. package/dist/test.js +9 -9
  54. package/dist/test.mjs +5 -5
  55. package/package.json +17 -2
  56. package/register/loader.mjs +48 -31
  57. package/dist/chunk-QEMKN5MI.js +0 -13
  58. package/dist/chunk-WUQB4ETW.mjs +0 -13
  59. package/dist/helper-fcb2f1d7.d.ts +0 -7
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 _chunkPC6CFB6Sjs = require('./chunk-PC6CFB6S.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
- _chunkPC6CFB6Sjs.__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
- _chunkPC6CFB6Sjs.__name.call(void 0, argToReq, "argToReq");
27
+ _chunkL3LQEK6Kjs.__name.call(void 0, argToReq, "argToReq");
28
28
 
29
29
 
30
30
 
@@ -0,0 +1,256 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-S6AGWZHN.mjs";
4
+
5
+ // src/decorators/param.ts
6
+ import { getOwnState, setState, setStateKey } from "phecda-core";
7
+ function BaseParam(type, key) {
8
+ return (target, k, index) => {
9
+ setStateKey(target, k);
10
+ const state = getOwnState(target, k);
11
+ if (!state.params)
12
+ state.params = [];
13
+ const existItem = state.params.find((item) => item.index === index);
14
+ if (existItem)
15
+ Object.assign(existItem, {
16
+ type,
17
+ key
18
+ });
19
+ else
20
+ state.params.push({
21
+ type,
22
+ key,
23
+ index
24
+ });
25
+ setState(target, k, state);
26
+ };
27
+ }
28
+ __name(BaseParam, "BaseParam");
29
+ function Pipe(key, opts) {
30
+ return (target, k, index) => {
31
+ setStateKey(target, k);
32
+ const state = getOwnState(target, k);
33
+ if (!state.params)
34
+ state.params = [];
35
+ const existItem = state.params.find((item) => item.index === index);
36
+ if (existItem)
37
+ Object.assign(existItem, {
38
+ pipe: key,
39
+ pipeOpts: opts
40
+ });
41
+ else
42
+ state.params.push({
43
+ pipe: key,
44
+ pipeOpts: opts,
45
+ index
46
+ });
47
+ setState(target, k, state);
48
+ };
49
+ }
50
+ __name(Pipe, "Pipe");
51
+ function Body(key = "") {
52
+ return BaseParam("body", key);
53
+ }
54
+ __name(Body, "Body");
55
+ function Head(key) {
56
+ return BaseParam("headers", key.toLowerCase());
57
+ }
58
+ __name(Head, "Head");
59
+ function Query(key = "") {
60
+ return BaseParam("query", key);
61
+ }
62
+ __name(Query, "Query");
63
+ function Param(key) {
64
+ return BaseParam("params", key);
65
+ }
66
+ __name(Param, "Param");
67
+ function Arg() {
68
+ return BaseParam("params", "");
69
+ }
70
+ __name(Arg, "Arg");
71
+
72
+ // src/decorators/route.ts
73
+ import { SHARE_KEY, getOwnState as getOwnState2, setState as setState2, setStateKey as setStateKey2 } from "phecda-core";
74
+ function Route(route, type) {
75
+ return (target, key) => {
76
+ if (!key)
77
+ key = SHARE_KEY;
78
+ target = key === SHARE_KEY ? target.prototype : target;
79
+ setStateKey2(target, key);
80
+ const state = getOwnState2(target, key);
81
+ state.http = {
82
+ route,
83
+ type
84
+ };
85
+ setState2(target, key, state);
86
+ };
87
+ }
88
+ __name(Route, "Route");
89
+ function Get(route = "") {
90
+ return Route(route, "get");
91
+ }
92
+ __name(Get, "Get");
93
+ function Post(route = "") {
94
+ return Route(route, "post");
95
+ }
96
+ __name(Post, "Post");
97
+ function Put(route = "") {
98
+ return Route(route, "put");
99
+ }
100
+ __name(Put, "Put");
101
+ function Patch(route = "") {
102
+ return Route(route, "patch");
103
+ }
104
+ __name(Patch, "Patch");
105
+ function Delete(route = "") {
106
+ return Route(route, "delete");
107
+ }
108
+ __name(Delete, "Delete");
109
+ function Controller(route = "") {
110
+ return Route(route);
111
+ }
112
+ __name(Controller, "Controller");
113
+ function Event(isEvent = true) {
114
+ return (target, key) => {
115
+ if (!key)
116
+ key = SHARE_KEY;
117
+ target = key === SHARE_KEY ? target.prototype : target;
118
+ setStateKey2(target, key);
119
+ const state = getOwnState2(target, key);
120
+ if (!state.rpc)
121
+ state.rpc = {};
122
+ state.rpc.isEvent = isEvent;
123
+ setState2(target, key, state);
124
+ };
125
+ }
126
+ __name(Event, "Event");
127
+ function Queue(queue) {
128
+ return (target, key) => {
129
+ if (!key)
130
+ key = SHARE_KEY;
131
+ target = key === SHARE_KEY ? target.prototype : target;
132
+ setStateKey2(target, key);
133
+ const state = getOwnState2(target, key) || {};
134
+ if (!state.rpc)
135
+ state.rpc = {};
136
+ state.rpc.queue = queue;
137
+ setState2(target, key, state);
138
+ };
139
+ }
140
+ __name(Queue, "Queue");
141
+
142
+ // src/decorators/aop.ts
143
+ import { SHARE_KEY as SHARE_KEY2, getOwnState as getOwnState3, setState as setState3, setStateKey as setStateKey3 } from "phecda-core";
144
+ function Guard(...guards) {
145
+ return (target, key) => {
146
+ if (!key)
147
+ key = SHARE_KEY2;
148
+ target = key === SHARE_KEY2 ? target.prototype : target;
149
+ setStateKey3(target, key);
150
+ const state = getOwnState3(target, key);
151
+ if (!state.guards)
152
+ state.guards = [];
153
+ state.guards.push(...guards);
154
+ setState3(target, key, state);
155
+ };
156
+ }
157
+ __name(Guard, "Guard");
158
+ function Plugin(...plugins) {
159
+ return (target, key) => {
160
+ if (!key)
161
+ key = SHARE_KEY2;
162
+ target = key === SHARE_KEY2 ? target.prototype : target;
163
+ setStateKey3(target, key);
164
+ const state = getOwnState3(target, key);
165
+ if (!state.plugins)
166
+ state.plugins = [];
167
+ state.plugins.push(...plugins);
168
+ setState3(target, key, state);
169
+ };
170
+ }
171
+ __name(Plugin, "Plugin");
172
+ function Interceptor(...interceptors) {
173
+ return (target, key) => {
174
+ if (!key)
175
+ key = SHARE_KEY2;
176
+ target = key === SHARE_KEY2 ? target.prototype : target;
177
+ setStateKey3(target, key);
178
+ const state = getOwnState3(target, key);
179
+ if (!state.interceptors)
180
+ state.interceptors = [];
181
+ state.interceptors.push(...interceptors);
182
+ setState3(target, key, state);
183
+ };
184
+ }
185
+ __name(Interceptor, "Interceptor");
186
+ function Filter(filter) {
187
+ return (target, key) => {
188
+ if (!key)
189
+ key = SHARE_KEY2;
190
+ target = key === SHARE_KEY2 ? target.prototype : target;
191
+ setStateKey3(target, key);
192
+ const state = getOwnState3(target, key);
193
+ state.filter = filter;
194
+ setState3(target, key, state);
195
+ };
196
+ }
197
+ __name(Filter, "Filter");
198
+
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";
201
+ function Header(name, value) {
202
+ return (target, k) => {
203
+ setStateKey4(target, k);
204
+ const state = getOwnState4(target, k);
205
+ if (!state.header)
206
+ state.header = {};
207
+ state.header[name] = value;
208
+ setState4(target, k, state);
209
+ };
210
+ }
211
+ __name(Header, "Header");
212
+ function Ctx(target, key) {
213
+ set(target, "context", key);
214
+ }
215
+ __name(Ctx, "Ctx");
216
+ function Define(key, value) {
217
+ return (target, k) => {
218
+ if (!k) {
219
+ k = SHARE_KEY3;
220
+ target = target.prototype;
221
+ }
222
+ setStateKey4(target, k);
223
+ const state = getOwnState4(target, k);
224
+ if (!state.define)
225
+ state.define = {};
226
+ state.define[key] = value;
227
+ setState4(target, k, state);
228
+ };
229
+ }
230
+ __name(Define, "Define");
231
+
232
+ export {
233
+ BaseParam,
234
+ Pipe,
235
+ Body,
236
+ Head,
237
+ Query,
238
+ Param,
239
+ Arg,
240
+ Route,
241
+ Get,
242
+ Post,
243
+ Put,
244
+ Patch,
245
+ Delete,
246
+ Controller,
247
+ Event,
248
+ Queue,
249
+ Guard,
250
+ Plugin,
251
+ Interceptor,
252
+ Filter,
253
+ Header,
254
+ Ctx,
255
+ Define
256
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkL3LQEK6Kjs = require('./chunk-L3LQEK6K.js');
4
+
5
+ // src/rpc/helper.ts
6
+ var _os = require('os');
7
+ function genClientQueue(key) {
8
+ return `PS-${key ? `${key}-` : ""}${_os.hostname.call(void 0, )}-${process.pid}`;
9
+ }
10
+ _chunkL3LQEK6Kjs.__name.call(void 0, genClientQueue, "genClientQueue");
11
+
12
+
13
+
14
+ exports.genClientQueue = genClientQueue;
@@ -12,12 +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 PS_FILE_RE = /\.(controller|service|module|extension|ext|guard|interceptor|plugin|filter|pipe|edge)\.ts$/i;
20
- var PS_IMPORT_RE = /\.(controller|extension|ext|guard|interceptor|plugin|filter|pipe|edge)\.ts$/i;
19
+ var IS_LOG_BAN = !!process.env.PS_LOG_BAN || IS_ONLY_CODE;
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 = {}));
21
26
 
22
27
  // src/utils.ts
23
28
  var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
@@ -81,4 +86,5 @@ __name(Mix, "Mix");
81
86
 
82
87
 
83
88
 
84
- 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.PS_IMPORT_RE = PS_IMPORT_RE; exports.log = log; exports.getConfig = getConfig; exports.setConfig = setConfig; exports.Mix = Mix;
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;