phecda-server 7.0.0-alpha.1 → 7.0.0-alpha.11

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 (86) hide show
  1. package/assets/ps.json +1 -1
  2. package/assets/schema.json +55 -55
  3. package/bin/cli.mjs +33 -25
  4. package/dist/chunk-4LLLQOMF.js +152 -0
  5. package/dist/{chunk-7YQ57BQS.js → chunk-6OQ2SB5W.js} +137 -69
  6. package/dist/{chunk-GSPBHZBH.js → chunk-G7JFKM2M.js} +96 -80
  7. package/dist/{chunk-MBCHNDAY.js → chunk-KCPBITYZ.js} +24 -24
  8. package/dist/{chunk-HMVLXNV3.mjs → chunk-MUI6MTUO.mjs} +1 -1
  9. package/dist/chunk-NQ55PA2X.mjs +152 -0
  10. package/dist/{chunk-XYVMNY2X.mjs → chunk-YCES6ABN.mjs} +124 -56
  11. package/dist/{chunk-V7EI76QQ.mjs → chunk-Z7NAAE4M.mjs} +48 -32
  12. package/dist/{core-BIcUwV18.d.mts → core-CUTbX_IS.d.ts} +5 -3
  13. package/dist/{core-CYwEPfN4.d.ts → core-DIfgUKIU.d.mts} +5 -3
  14. package/dist/helper.d.mts +8 -6
  15. package/dist/helper.d.ts +8 -6
  16. package/dist/helper.js +8 -3
  17. package/dist/helper.mjs +10 -5
  18. package/dist/http/elysia/index.d.mts +4 -4
  19. package/dist/http/elysia/index.d.ts +4 -4
  20. package/dist/http/elysia/index.js +43 -44
  21. package/dist/http/elysia/index.mjs +9 -10
  22. package/dist/http/express/index.d.mts +4 -4
  23. package/dist/http/express/index.d.ts +4 -4
  24. package/dist/http/express/index.js +40 -41
  25. package/dist/http/express/index.mjs +9 -10
  26. package/dist/http/fastify/index.d.mts +4 -4
  27. package/dist/http/fastify/index.d.ts +4 -4
  28. package/dist/http/fastify/index.js +41 -42
  29. package/dist/http/fastify/index.mjs +9 -10
  30. package/dist/http/h3/index.d.mts +4 -4
  31. package/dist/http/h3/index.d.ts +4 -4
  32. package/dist/http/h3/index.js +41 -42
  33. package/dist/http/h3/index.mjs +9 -10
  34. package/dist/http/hono/index.d.mts +4 -4
  35. package/dist/http/hono/index.d.ts +4 -4
  36. package/dist/http/hono/index.js +37 -39
  37. package/dist/http/hono/index.mjs +5 -7
  38. package/dist/http/hyper-express/index.d.mts +4 -4
  39. package/dist/http/hyper-express/index.d.ts +4 -4
  40. package/dist/http/hyper-express/index.js +38 -39
  41. package/dist/http/hyper-express/index.mjs +8 -9
  42. package/dist/http/koa/index.d.mts +4 -4
  43. package/dist/http/koa/index.d.ts +4 -4
  44. package/dist/http/koa/index.js +40 -41
  45. package/dist/http/koa/index.mjs +9 -10
  46. package/dist/index.d.mts +44 -38
  47. package/dist/index.d.ts +44 -38
  48. package/dist/index.js +48 -42
  49. package/dist/index.mjs +21 -15
  50. package/dist/{meta-BXKLFTgG.d.mts → meta-CR-D39hQ.d.mts} +7 -5
  51. package/dist/{meta-BXKLFTgG.d.ts → meta-CR-D39hQ.d.ts} +7 -5
  52. package/dist/rpc/bullmq/index.d.mts +5 -5
  53. package/dist/rpc/bullmq/index.d.ts +5 -5
  54. package/dist/rpc/bullmq/index.js +15 -14
  55. package/dist/rpc/bullmq/index.mjs +4 -3
  56. package/dist/rpc/kafka/index.d.mts +4 -4
  57. package/dist/rpc/kafka/index.d.ts +4 -4
  58. package/dist/rpc/kafka/index.js +15 -14
  59. package/dist/rpc/kafka/index.mjs +3 -2
  60. package/dist/rpc/nats/index.d.mts +4 -4
  61. package/dist/rpc/nats/index.d.ts +4 -4
  62. package/dist/rpc/nats/index.js +14 -13
  63. package/dist/rpc/nats/index.mjs +4 -3
  64. package/dist/rpc/rabbitmq/index.d.mts +4 -4
  65. package/dist/rpc/rabbitmq/index.d.ts +4 -4
  66. package/dist/rpc/rabbitmq/index.js +16 -15
  67. package/dist/rpc/rabbitmq/index.mjs +4 -3
  68. package/dist/rpc/redis/index.d.mts +4 -4
  69. package/dist/rpc/redis/index.d.ts +4 -4
  70. package/dist/rpc/redis/index.js +14 -13
  71. package/dist/rpc/redis/index.mjs +4 -3
  72. package/dist/test.d.mts +3 -3
  73. package/dist/test.d.ts +3 -3
  74. package/dist/test.js +6 -6
  75. package/dist/test.mjs +2 -2
  76. package/dist/{types-h40T3cRG.d.mts → types-BF1TDbFV.d.ts} +4 -3
  77. package/dist/{types-BtbL49Zs.d.mts → types-DYRu0vic.d.ts} +4 -3
  78. package/dist/{types-VFzEM7LL.d.ts → types-DYviSl5B.d.mts} +4 -3
  79. package/dist/{types-m3IEDKjP.d.ts → types-DqH1qA-q.d.mts} +4 -3
  80. package/package.json +8 -6
  81. package/register/export.mjs +30 -0
  82. package/register/index.mjs +50 -40
  83. package/register/loader.mjs +110 -74
  84. package/register/utils.mjs +86 -56
  85. package/dist/chunk-J5CFUN4V.js +0 -73
  86. package/dist/chunk-WHJ5FALK.mjs +0 -73
package/assets/ps.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "unimport": {
16
16
  "dirs": ["."],
17
17
  "dirsScanOptions": {
18
- "filePatterns": ["*.{service,controller,module,rpc,edge,guard,extension,pipe,filter,addon}.ts"]
18
+ "filePatterns": ["*.{service,controller,module,rpc,solo,guard,extension,pipe,filter,addon}.ts"]
19
19
  }
20
20
  },
21
21
  "virtualFile": {},
@@ -1,55 +1,55 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "type": "object",
4
- "properties": {
5
- "resolve": {
6
- "type": "array",
7
- "items": {
8
- "type": "object",
9
- "properties": {
10
- "source": {
11
- "type": "string",
12
- "description": "The middle name of the imported file."
13
- },
14
- "importer": {
15
- "type": "string",
16
- "description": "The middle name of the importer file."
17
- },
18
- "path": {
19
- "type": "string",
20
-
21
- "description": "Redirect path"
22
- },
23
- "filename": {
24
- "type": "string",
25
- "optional": true,
26
-
27
- "description": "generate split chunk,only work in vite"
28
- }
29
- },
30
- "required": ["source", "path", "importer"]
31
- },
32
- "description": "Resolve and redirect modules path"
33
- },
34
- "moduleFile": {
35
- "type": "array",
36
- "items": {
37
- "type": "string"
38
- },
39
- "description": "Including the module's file middle name, such as controller mapping to xx.controller.ts"
40
- },
41
- "virtualFile": {
42
- "type": "object",
43
- "additionalProperties": {
44
- "type": "string"
45
- },
46
- "description": "Virtual module, just like in Vite."
47
- },
48
- "unimport": {
49
- "type": "object",
50
- "description": "Includes the arguments passed to unimport and 'dtsPath' that specifies the location for generating type files."
51
- }
52
- },
53
-
54
- "required": ["resolve"]
55
- }
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "resolve": {
6
+ "type": "array",
7
+ "items": {
8
+ "type": "object",
9
+ "properties": {
10
+ "source": {
11
+ "type": "string",
12
+ "description": "The middle name of the imported file."
13
+ },
14
+ "importer": {
15
+ "type": "string",
16
+ "description": "The middle name of the importer file."
17
+ },
18
+ "path": {
19
+ "type": "string",
20
+
21
+ "description": "Redirect path"
22
+ },
23
+ "filename": {
24
+ "type": "string",
25
+ "optional": true,
26
+
27
+ "description": "generate split chunk,only work in vite"
28
+ }
29
+ },
30
+ "required": ["source", "path", "importer"]
31
+ },
32
+ "description": "Resolve and redirect modules path"
33
+ },
34
+ "moduleFile": {
35
+ "type": "array",
36
+ "items": {
37
+ "type": "string"
38
+ },
39
+ "description": "Including the module's file middle name, such as controller mapping to xx.controller.ts"
40
+ },
41
+ "virtualFile": {
42
+ "type": "object",
43
+ "additionalProperties": {
44
+ "type": "string"
45
+ },
46
+ "description": "Virtual module, just like in Vite."
47
+ },
48
+ "unimport": {
49
+ "type": "object",
50
+ "description": "Includes the arguments passed to unimport"
51
+ }
52
+ },
53
+
54
+ "required": ["resolve"]
55
+ }
package/bin/cli.mjs CHANGED
@@ -3,11 +3,18 @@ import { fork } from 'child_process'
3
3
  import { createRequire } from 'module'
4
4
  import { fileURLToPath } from 'url'
5
5
 
6
- import { dirname, join, resolve } from 'path'
6
+ import { dirname, resolve } from 'path'
7
7
  import pc from 'picocolors'
8
8
  import cac from 'cac'
9
9
  import fse from 'fs-extra'
10
- import { log } from '../dist/index.mjs'
10
+ import { log as psLog } from '../dist/index.mjs'
11
+
12
+ const log = (...args) => {
13
+ if (process.env.PS_BAN_CLI_LOG)
14
+ return
15
+
16
+ psLog(...args)
17
+ }
11
18
 
12
19
  const cli = cac('phecda').option('-c,--config <config>', 'config file', {
13
20
  default: 'ps.json',
@@ -30,7 +37,7 @@ if (nodeVersion < 18.19) {
30
37
 
31
38
  function startChild(file, args) {
32
39
  child = fork(file, {
33
- env: { NODE_ENV: 'development', ...process.env },
40
+ env: { ...process.env },
34
41
  stdio: 'inherit',
35
42
  execArgv: [
36
43
  nodeVersion < 18.19
@@ -42,20 +49,12 @@ function startChild(file, args) {
42
49
 
43
50
  closePromise = new Promise((resolve) => {
44
51
  child.once('exit', (code) => {
45
- if (code === 4) {
46
- log('only generate code')
47
- process.exit(0)
48
- }
49
-
50
- if (code === 5) {
51
- log('Does not comply with strict mode', 'error')
52
- process.exit(0)
53
- }
54
- if (code >= 2) {
55
- // for relaunch
56
- log('relaunch...')
52
+ if (code === 4171)
57
53
  startChild(file, args)
58
- }
54
+
55
+ if (code === 4172)
56
+ return process.exit()
57
+
59
58
  child = undefined
60
59
 
61
60
  resolve()
@@ -85,11 +84,11 @@ cli
85
84
  default: 'tsconfig.json',
86
85
  })
87
86
  .action(async (root, options) => {
88
- if (!root)
89
- root = ''
87
+ if (root)
88
+ process.chdir(root)
90
89
 
91
- const tsconfigPath = join(root, options.tsconfig)
92
- const psconfigPath = join(root, options.config)
90
+ const tsconfigPath = options.tsconfig
91
+ const psconfigPath = process.env.PS_CONFIG_FILE || options.config
93
92
 
94
93
  if (!fse.existsSync(tsconfigPath)) {
95
94
  log(`create ${tsconfigPath}`)
@@ -113,17 +112,26 @@ cli
113
112
  .command('<file> [root]', 'run file')
114
113
  .alias('run')
115
114
  .allowUnknownOptions()
116
- .alias('run')
115
+ .option('-p,--prod [prod]', 'prod mode', {
116
+ default: false,
117
+ })
117
118
  .action((file, root, options) => {
118
119
  if (root)
119
- process.env.PS_WORKDIR = root
120
- process.env.PS_CONFIG_FILE = options.config
120
+ process.chdir(root)
121
+
122
+ if (options.prod)
123
+ process.env.NODE_ENV = 'production'
124
+ else
125
+ process.env.NODE_ENV = 'development'
126
+
127
+ process.env.PS_CONFIG_FILE = process.env.PS_CONFIG_FILE || options.config
121
128
 
122
129
  log('process start!')
123
130
 
124
131
  startChild(file, options['--'])
125
132
  console.log(`${pc.green('->')} press ${pc.green('e')} to exit`)
126
133
  console.log(`${pc.green('->')} press ${pc.green('r')} to relaunch`)
134
+ console.log(`${pc.green('->')} press ${pc.green('c')} to clear terminal`)
127
135
 
128
136
  process.stdin.on('data', async (data) => {
129
137
  const input = data.toString().trim().toLocaleLowerCase()
@@ -154,9 +162,9 @@ cli
154
162
  .allowUnknownOptions()
155
163
  .action((file, root, options) => {
156
164
  if (root)
157
- process.env.PS_WORKDIR = root
165
+ process.chdir(root)
158
166
  process.env.PS_GENERATE = 'true'
159
- process.env.PS_CONFIG_FILE = options.config
167
+ process.env.PS_CONFIG_FILE = process.env.PS_CONFIG_FILE || options.config
160
168
  startChild(file, options['--'])
161
169
  })
162
170
 
@@ -0,0 +1,152 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _class;var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/common.ts
5
+ var ERROR_SYMBOL = "__PS_ERROR__";
6
+ var IS_DEV = process.env.NODE_ENV === "development";
7
+ var IS_ONLY_GENERATE = !!process.env.PS_GENERATE;
8
+ var IS_STRICT = !!process.env.PS_STRICT;
9
+ var IS_PURE = !!process.env.PS_PURE;
10
+ var LOG_LEVEL = Number(process.env.PS_LOG_LEVEL || 0);
11
+ var PS_EXIT_CODE = /* @__PURE__ */ function(PS_EXIT_CODE2) {
12
+ PS_EXIT_CODE2[PS_EXIT_CODE2["RELAUNCH"] = 4171] = "RELAUNCH";
13
+ PS_EXIT_CODE2[PS_EXIT_CODE2["EXIT"] = 4172] = "EXIT";
14
+ return PS_EXIT_CODE2;
15
+ }({});
16
+
17
+ // src/utils.ts
18
+ var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
19
+ var _tsmixer = require('ts-mixer');
20
+ var isObject = /* @__PURE__ */ __name((fn) => fn !== null && typeof fn === "object", "isObject");
21
+ var isPlainObject = /* @__PURE__ */ __name((fn) => {
22
+ if (!isObject(fn)) return false;
23
+ const proto = Object.getPrototypeOf(fn);
24
+ if (proto === null) return true;
25
+ const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
26
+ return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
27
+ }, "isPlainObject");
28
+ var InternalLogger = (_class = class InternalLogger2 {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this); }
29
+ static {
30
+ __name(this, "InternalLogger");
31
+ }
32
+
33
+ __init() {this.color = {
34
+ debug: "bgMagenta",
35
+ error: "red",
36
+ info: "gray",
37
+ warn: "yellow",
38
+ log: "green"
39
+ }}
40
+ __init2() {this.dateFormatter = new Intl.DateTimeFormat(void 0, {
41
+ year: "numeric",
42
+ hour: "numeric",
43
+ minute: "numeric",
44
+ second: "numeric",
45
+ day: "2-digit",
46
+ month: "2-digit"
47
+ })}
48
+ diffTimestamp() {
49
+ const now = Date.now();
50
+ if (!this.time) return "";
51
+ const diff = now - this.time;
52
+ this.time = now;
53
+ return diff ? _picocolors2.default.yellow(` +${diff}`) : "";
54
+ }
55
+ colorize(message, logLevel) {
56
+ return _picocolors2.default[this.color[logLevel]](message);
57
+ }
58
+ isAllowLog(level) {
59
+ const logLevel = {
60
+ debug: -1,
61
+ info: 0,
62
+ log: 1,
63
+ warn: 2,
64
+ error: 3
65
+ }[level];
66
+ if (logLevel < LOG_LEVEL) return false;
67
+ return true;
68
+ }
69
+ stringifyMessage(message, logLevel) {
70
+ if (typeof message === "function") {
71
+ const messageAsStr = Function.prototype.toString.call(message);
72
+ const isClass = messageAsStr.startsWith("class ");
73
+ if (isClass) {
74
+ return this.stringifyMessage(message.name, logLevel);
75
+ }
76
+ return this.stringifyMessage(message(), logLevel);
77
+ }
78
+ return isPlainObject(message) || Array.isArray(message) ? `${this.colorize("Object:", logLevel)}
79
+ ${JSON.stringify(message, (key, value) => typeof value === "bigint" ? value.toString() : value, 2)}
80
+ ` : this.colorize(message, logLevel);
81
+ }
82
+ log(msg, level, ctx) {
83
+ if (!this.isAllowLog(level)) return;
84
+ msg = this.stringifyMessage(msg, level);
85
+ const pidMsg = this.colorize(`[${process.env.PS_APP_NAME || "phecda-server"}] ${process.pid}`, level);
86
+ const ctxMsg = ctx ? this.colorize(_picocolors2.default.bold(`[${ctx}] `), level) : "";
87
+ const timeDiff = this.diffTimestamp();
88
+ const levelMsg = this.colorize(level.toUpperCase().padStart(7, " "), level);
89
+ process.stdout.write(`${pidMsg} ${this.dateFormatter.format(Date.now())} ${levelMsg} ${ctxMsg}${msg}${timeDiff}
90
+ `);
91
+ }
92
+ }, _class);
93
+ var _logger = new InternalLogger();
94
+ function setLogger(logger) {
95
+ _logger = logger;
96
+ }
97
+ __name(setLogger, "setLogger");
98
+ function getLogger() {
99
+ return _logger;
100
+ }
101
+ __name(getLogger, "getLogger");
102
+ function log(msg, level = "log", ctx) {
103
+ _logger.log(msg, level, ctx);
104
+ }
105
+ __name(log, "log");
106
+ function runMiddleware(ctx, middleware) {
107
+ return new Promise((resolve) => {
108
+ middleware(ctx.getRequest(), ctx.getResponse(), resolve);
109
+ });
110
+ }
111
+ __name(runMiddleware, "runMiddleware");
112
+
113
+ // src/hmr.ts
114
+ function HMR(cb) {
115
+ if (IS_DEV) {
116
+ if (!globalThis.__PS_HMR__) globalThis.__PS_HMR__ = [];
117
+ globalThis.__PS_HMR__.push(cb);
118
+ }
119
+ }
120
+ __name(HMR, "HMR");
121
+ async function RELOAD(oldModels, newModels) {
122
+ log("reload module...");
123
+ for (const cb of globalThis.__PS_HMR__) await cb(oldModels, newModels);
124
+ log("reload done");
125
+ }
126
+ __name(RELOAD, "RELOAD");
127
+ function RELAUNCH() {
128
+ if (IS_DEV) {
129
+ log("relaunch...");
130
+ process.exit(PS_EXIT_CODE.RELAUNCH);
131
+ }
132
+ }
133
+ __name(RELAUNCH, "RELAUNCH");
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+ exports.__name = __name; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.IS_DEV = IS_DEV; exports.IS_ONLY_GENERATE = IS_ONLY_GENERATE; exports.IS_STRICT = IS_STRICT; exports.IS_PURE = IS_PURE; exports.LOG_LEVEL = LOG_LEVEL; exports.PS_EXIT_CODE = PS_EXIT_CODE; exports.setLogger = setLogger; exports.getLogger = getLogger; exports.log = log; exports.runMiddleware = runMiddleware; exports.Mixin = _tsmixer.Mixin; exports.HMR = HMR; exports.RELOAD = RELOAD; exports.RELAUNCH = RELAUNCH;