phecda-server 4.1.2-alpha.3 → 5.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.
- package/bin/cli.js +99 -93
- package/dist/{chunk-GY5KXMJJ.js → chunk-2AI7ID6X.js} +2 -2
- package/dist/{chunk-7HTK4DGR.js → chunk-ANH53I6B.js} +37 -31
- package/dist/{chunk-ALJSRZ4Z.js → chunk-C36XJ7D3.js} +11 -1
- package/dist/{chunk-DBYLTVRY.mjs → chunk-JJG37LHY.mjs} +1 -1
- package/dist/{chunk-WB437JJ2.mjs → chunk-KGMDCF26.mjs} +11 -1
- package/dist/{chunk-LT64YKXF.mjs → chunk-KKTRNKCF.mjs} +15 -9
- package/dist/{chunk-EP4EN3MM.mjs → chunk-MZBE4NIO.mjs} +1 -1
- package/dist/{chunk-ZV4O77YM.js → chunk-P5LJBZPN.js} +48 -48
- package/dist/{core-23c1392a.d.ts → core-39d78b79.d.ts} +3 -3
- package/dist/index.d.ts +8 -9
- package/dist/index.js +91 -97
- package/dist/index.mjs +55 -61
- package/dist/rpc/kafka/index.d.ts +21 -0
- package/dist/rpc/kafka/index.js +218 -0
- package/dist/rpc/kafka/index.mjs +218 -0
- package/dist/rpc/rabbitmq/index.d.ts +1 -1
- package/dist/rpc/rabbitmq/index.js +12 -12
- package/dist/rpc/rabbitmq/index.mjs +5 -5
- package/dist/rpc/redis/index.d.ts +1 -1
- package/dist/rpc/redis/index.js +11 -11
- package/dist/rpc/redis/index.mjs +4 -4
- package/dist/server/express/index.d.ts +1 -1
- package/dist/server/express/index.js +24 -24
- package/dist/server/express/index.mjs +3 -3
- package/dist/server/fastify/index.d.ts +1 -1
- package/dist/server/fastify/index.js +22 -22
- package/dist/server/fastify/index.mjs +3 -3
- package/dist/server/h3/index.d.ts +1 -1
- package/dist/server/h3/index.js +21 -21
- package/dist/server/h3/index.mjs +3 -3
- package/dist/server/koa/index.d.ts +1 -1
- package/dist/server/koa/index.js +24 -24
- package/dist/server/koa/index.mjs +3 -3
- package/dist/test.d.ts +2 -2
- package/dist/test.js +5 -5
- package/dist/test.mjs +2 -2
- package/package.json +11 -3
- package/register/index.mjs +27 -20
- package/register/loader.mjs +147 -112
- package/register/utils.mjs +7 -7
package/bin/cli.js
CHANGED
|
@@ -1,97 +1,109 @@
|
|
|
1
|
-
const { fork } = require(
|
|
1
|
+
const { fork } = require('child_process')
|
|
2
2
|
|
|
3
|
-
const fs = require(
|
|
4
|
-
const { posix } = require(
|
|
5
|
-
const pc = require(
|
|
6
|
-
const cmd = process.argv.slice(2)
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const { posix } = require('path')
|
|
5
|
+
const pc = require('picocolors')
|
|
6
|
+
const cmd = process.argv.slice(2)
|
|
7
7
|
|
|
8
|
-
let child
|
|
8
|
+
let child
|
|
9
9
|
|
|
10
|
-
let closePromise
|
|
10
|
+
let closePromise
|
|
11
|
+
const nodeVersion = parseFloat(process.version.slice(1))
|
|
12
|
+
|
|
13
|
+
if (nodeVersion < 18.18)
|
|
14
|
+
log(`Nodejs version less than 18.18(current is ${nodeVersion}) can't support hmr`, 'yellow')
|
|
11
15
|
|
|
12
16
|
function startChild() {
|
|
13
17
|
child = fork(cmd[0], {
|
|
14
|
-
env: { NODE_ENV:
|
|
15
|
-
stdio:
|
|
16
|
-
execArgv: [
|
|
17
|
-
|
|
18
|
+
env: { NODE_ENV: 'development', ...process.env },
|
|
19
|
+
stdio: 'inherit',
|
|
20
|
+
execArgv: [
|
|
21
|
+
nodeVersion < 18.18 ? '--loader=phecda-server/register/loader.mjs' : '--import=phecda-server/register',
|
|
22
|
+
...cmd.slice(1),
|
|
23
|
+
],
|
|
24
|
+
})
|
|
18
25
|
|
|
19
26
|
closePromise = new Promise((resolve) => {
|
|
20
|
-
child.once(
|
|
27
|
+
child.once('exit', (code) => {
|
|
21
28
|
if (code >= 2) {
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
// for relaunch
|
|
30
|
+
log('relaunch...')
|
|
31
|
+
startChild()
|
|
24
32
|
}
|
|
25
|
-
child = undefined
|
|
33
|
+
child = undefined
|
|
26
34
|
|
|
27
|
-
resolve()
|
|
28
|
-
})
|
|
29
|
-
})
|
|
35
|
+
resolve()
|
|
36
|
+
})
|
|
37
|
+
})
|
|
30
38
|
}
|
|
31
39
|
|
|
32
|
-
process.on(
|
|
33
|
-
process.exit()
|
|
34
|
-
})
|
|
40
|
+
process.on('SIGINT', () => {
|
|
41
|
+
process.exit()
|
|
42
|
+
})
|
|
35
43
|
|
|
36
44
|
function exit() {
|
|
37
|
-
log(
|
|
45
|
+
log('process exit')
|
|
38
46
|
|
|
39
47
|
if (child) {
|
|
40
|
-
child.kill()
|
|
41
|
-
process.exit(0)
|
|
42
|
-
}
|
|
43
|
-
|
|
48
|
+
child.kill()
|
|
49
|
+
process.exit(0)
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
process.exit(0)
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
|
|
47
|
-
function log(msg, color =
|
|
48
|
-
const date = new Date()
|
|
56
|
+
function log(msg, color = 'green') {
|
|
57
|
+
const date = new Date()
|
|
49
58
|
console.log(
|
|
50
|
-
`${pc.magenta(
|
|
51
|
-
`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}
|
|
52
|
-
)} ${pc[color](msg)}
|
|
53
|
-
)
|
|
59
|
+
`${pc.magenta('[phecda-server]')} ${pc.gray(
|
|
60
|
+
`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`,
|
|
61
|
+
)} ${pc[color](msg)}`,
|
|
62
|
+
)
|
|
54
63
|
}
|
|
55
64
|
|
|
56
|
-
startChild()
|
|
65
|
+
startChild()
|
|
57
66
|
|
|
58
|
-
log(
|
|
59
|
-
console.log(`${pc.green(
|
|
60
|
-
console.log(`${pc.green(
|
|
67
|
+
log('process start!')
|
|
68
|
+
console.log(`${pc.green('->')} press ${pc.green('e')} to exit`)
|
|
69
|
+
console.log(`${pc.green('->')} press ${pc.green('r')} to relaunch`)
|
|
61
70
|
console.log(
|
|
62
|
-
`${pc.green(
|
|
63
|
-
|
|
64
|
-
)} to create controller
|
|
65
|
-
)
|
|
71
|
+
`${pc.green('->')} press ${pc.green(
|
|
72
|
+
'c {moduleName} {dir}',
|
|
73
|
+
)} to create controller`,
|
|
74
|
+
)
|
|
66
75
|
console.log(
|
|
67
|
-
`${pc.green(
|
|
68
|
-
|
|
69
|
-
)} to create service
|
|
70
|
-
)
|
|
76
|
+
`${pc.green('->')} press ${pc.green(
|
|
77
|
+
's {moduleName} {dir}',
|
|
78
|
+
)} to create service`,
|
|
79
|
+
)
|
|
71
80
|
console.log(
|
|
72
|
-
`${pc.green(
|
|
73
|
-
)
|
|
81
|
+
`${pc.green('->')} press ${pc.green('m {moduleName} {dir}')} to create module`,
|
|
82
|
+
)
|
|
74
83
|
|
|
75
|
-
process.stdin.on(
|
|
76
|
-
const input = data.toString().trim().toLocaleLowerCase()
|
|
77
|
-
if (input ===
|
|
84
|
+
process.stdin.on('data', async (data) => {
|
|
85
|
+
const input = data.toString().trim().toLocaleLowerCase()
|
|
86
|
+
if (input === 'r') {
|
|
78
87
|
if (child) {
|
|
79
|
-
await child.kill()
|
|
80
|
-
if (closePromise)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
await child.kill()
|
|
89
|
+
if (closePromise)
|
|
90
|
+
await closePromise
|
|
91
|
+
log('relaunch...')
|
|
92
|
+
startChild()
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
log('relaunch...')
|
|
96
|
+
|
|
97
|
+
startChild()
|
|
87
98
|
}
|
|
88
99
|
}
|
|
89
|
-
if (input ===
|
|
100
|
+
if (input === 'e')
|
|
101
|
+
exit()
|
|
90
102
|
|
|
91
|
-
if (input.startsWith(
|
|
92
|
-
let [, module, dir] = input.split(
|
|
93
|
-
module = toCamelCase(module)
|
|
94
|
-
const path = posix.join(dir, `${module}.controller.ts`)
|
|
103
|
+
if (input.startsWith('c ')) {
|
|
104
|
+
let [, module, dir] = input.split(' ')
|
|
105
|
+
module = toCamelCase(module)
|
|
106
|
+
const path = posix.join(dir, `${module}.controller.ts`)
|
|
95
107
|
fs.writeFile(
|
|
96
108
|
path,
|
|
97
109
|
`
|
|
@@ -100,18 +112,16 @@ process.stdin.on("data", async (data) => {
|
|
|
100
112
|
}
|
|
101
113
|
`,
|
|
102
114
|
(err) => {
|
|
103
|
-
if (err)
|
|
104
|
-
log(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
);
|
|
115
|
+
if (err)
|
|
116
|
+
log('writeFile filled', 'red')
|
|
117
|
+
else log(`create controller at ${path}`)
|
|
118
|
+
},
|
|
119
|
+
)
|
|
110
120
|
}
|
|
111
|
-
if (input.startsWith(
|
|
112
|
-
let [, module, dir] = input.split(
|
|
113
|
-
module = toCamelCase(module)
|
|
114
|
-
const path = posix.join(dir, `${module}.service.ts`)
|
|
121
|
+
if (input.startsWith('s ')) {
|
|
122
|
+
let [, module, dir] = input.split(' ')
|
|
123
|
+
module = toCamelCase(module)
|
|
124
|
+
const path = posix.join(dir, `${module}.service.ts`)
|
|
115
125
|
fs.writeFile(
|
|
116
126
|
path,
|
|
117
127
|
`
|
|
@@ -122,19 +132,17 @@ process.stdin.on("data", async (data) => {
|
|
|
122
132
|
}
|
|
123
133
|
`,
|
|
124
134
|
(err) => {
|
|
125
|
-
if (err)
|
|
126
|
-
log(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
);
|
|
135
|
+
if (err)
|
|
136
|
+
log('writeFile filled', 'red')
|
|
137
|
+
else log(`create service at ${path}`)
|
|
138
|
+
},
|
|
139
|
+
)
|
|
132
140
|
}
|
|
133
141
|
|
|
134
|
-
if (input.startsWith(
|
|
135
|
-
let [, module, dir] = input.split(
|
|
136
|
-
module = toCamelCase(module)
|
|
137
|
-
const path = posix.join(dir, `${module}.module.ts`)
|
|
142
|
+
if (input.startsWith('m ')) {
|
|
143
|
+
let [, module, dir] = input.split(' ')
|
|
144
|
+
module = toCamelCase(module)
|
|
145
|
+
const path = posix.join(dir, `${module}.module.ts`)
|
|
138
146
|
fs.writeFile(
|
|
139
147
|
path,
|
|
140
148
|
`
|
|
@@ -145,16 +153,14 @@ process.stdin.on("data", async (data) => {
|
|
|
145
153
|
}
|
|
146
154
|
`,
|
|
147
155
|
(err) => {
|
|
148
|
-
if (err)
|
|
149
|
-
log(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
);
|
|
156
|
+
if (err)
|
|
157
|
+
log('writeFile filled', 'red')
|
|
158
|
+
else log(`create module at ${path}`)
|
|
159
|
+
},
|
|
160
|
+
)
|
|
155
161
|
}
|
|
156
|
-
})
|
|
162
|
+
})
|
|
157
163
|
|
|
158
164
|
function toCamelCase(str) {
|
|
159
|
-
return str.replace(/[-_]\w/g,
|
|
165
|
+
return str.replace(/[-_]\w/g, match => match.charAt(1).toUpperCase())
|
|
160
166
|
}
|
|
@@ -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
|
|
3
|
+
var _chunkC36XJ7D3js = require('./chunk-C36XJ7D3.js');
|
|
4
4
|
|
|
5
5
|
// src/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
|
-
|
|
11
|
+
_chunkC36XJ7D3js.__name.call(void 0, resolveDep, "resolveDep");
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkC36XJ7D3js = require('./chunk-C36XJ7D3.js');
|
|
7
7
|
|
|
8
8
|
// src/meta.ts
|
|
9
9
|
var Meta = class {
|
|
@@ -16,10 +16,10 @@ var Meta = class {
|
|
|
16
16
|
this.paramsType = paramsType;
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
_chunkC36XJ7D3js.__name.call(void 0, Meta, "Meta");
|
|
20
20
|
|
|
21
21
|
// src/compiler/rpc.ts
|
|
22
|
-
var Compiler = /* @__PURE__ */
|
|
22
|
+
var Compiler = /* @__PURE__ */ _chunkC36XJ7D3js.__name.call(void 0, (_class =class Compiler2 {
|
|
23
23
|
__init() {this.classMap = {}}
|
|
24
24
|
constructor() {;_class.prototype.__init.call(this);
|
|
25
25
|
}
|
|
@@ -55,10 +55,10 @@ function generateRPCCode(meta) {
|
|
|
55
55
|
compiler.addMethod(i);
|
|
56
56
|
return compiler.getContent();
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
_chunkC36XJ7D3js.__name.call(void 0, generateRPCCode, "generateRPCCode");
|
|
59
59
|
|
|
60
60
|
// src/compiler/http.ts
|
|
61
|
-
var Compiler3 = /* @__PURE__ */
|
|
61
|
+
var Compiler3 = /* @__PURE__ */ _chunkC36XJ7D3js.__name.call(void 0, (_class2 =class Compiler4 {
|
|
62
62
|
__init2() {this.classMap = {}}
|
|
63
63
|
constructor() {;_class2.prototype.__init2.call(this);
|
|
64
64
|
}
|
|
@@ -97,7 +97,7 @@ function generateHTTPCode(meta) {
|
|
|
97
97
|
compiler.addMethod(i);
|
|
98
98
|
return compiler.getContent();
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
_chunkC36XJ7D3js.__name.call(void 0, generateHTTPCode, "generateHTTPCode");
|
|
101
101
|
|
|
102
102
|
// src/core.ts
|
|
103
103
|
require('reflect-metadata');
|
|
@@ -108,7 +108,7 @@ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
|
108
108
|
function Injectable() {
|
|
109
109
|
return (target) => _phecdacore.Empty.call(void 0, target);
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
_chunkC36XJ7D3js.__name.call(void 0, Injectable, "Injectable");
|
|
112
112
|
var debug = _debug2.default.call(void 0, "phecda-server");
|
|
113
113
|
var emitter = new (0, _events2.default)();
|
|
114
114
|
async function Factory(Modules, opts = {}) {
|
|
@@ -121,9 +121,9 @@ async function Factory(Modules, opts = {}) {
|
|
|
121
121
|
if (!_phecdacore.getProperty.call(void 0, "watcher")) {
|
|
122
122
|
_phecdacore.injectProperty.call(void 0, "watcher", ({ eventName, instance, key, options }) => {
|
|
123
123
|
const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
|
|
124
|
-
if (!instance[
|
|
125
|
-
instance[
|
|
126
|
-
instance[
|
|
124
|
+
if (!instance[_chunkC36XJ7D3js.UNMOUNT_SYMBOL])
|
|
125
|
+
instance[_chunkC36XJ7D3js.UNMOUNT_SYMBOL] = [];
|
|
126
|
+
instance[_chunkC36XJ7D3js.UNMOUNT_SYMBOL].push(() => {
|
|
127
127
|
emitter.off(eventName, fn);
|
|
128
128
|
});
|
|
129
129
|
if (_optionalChain([options, 'optionalAccess', _2 => _2.once]))
|
|
@@ -137,8 +137,8 @@ async function Factory(Modules, opts = {}) {
|
|
|
137
137
|
return;
|
|
138
138
|
const instance = moduleMap.get(tag);
|
|
139
139
|
debug(`unmount module "${tag}"`);
|
|
140
|
-
if (_optionalChain([instance, 'optionalAccess', _3 => _3[
|
|
141
|
-
for (const cb of instance[
|
|
140
|
+
if (_optionalChain([instance, 'optionalAccess', _3 => _3[_chunkC36XJ7D3js.UNMOUNT_SYMBOL]])) {
|
|
141
|
+
for (const cb of instance[_chunkC36XJ7D3js.UNMOUNT_SYMBOL])
|
|
142
142
|
await cb();
|
|
143
143
|
}
|
|
144
144
|
debug(`del module "${tag}"`);
|
|
@@ -150,7 +150,13 @@ async function Factory(Modules, opts = {}) {
|
|
|
150
150
|
}
|
|
151
151
|
return instance;
|
|
152
152
|
}
|
|
153
|
-
|
|
153
|
+
_chunkC36XJ7D3js.__name.call(void 0, del, "del");
|
|
154
|
+
async function destroy() {
|
|
155
|
+
debug("destroy all");
|
|
156
|
+
for (const [tag] of moduleMap)
|
|
157
|
+
await del(tag);
|
|
158
|
+
}
|
|
159
|
+
_chunkC36XJ7D3js.__name.call(void 0, destroy, "destroy");
|
|
154
160
|
async function add(Module) {
|
|
155
161
|
const tag = _optionalChain([Module, 'access', _4 => _4.prototype, 'optionalAccess', _5 => _5.__TAG__]) || Module.name;
|
|
156
162
|
const oldInstance = await del(tag);
|
|
@@ -168,18 +174,18 @@ async function Factory(Modules, opts = {}) {
|
|
|
168
174
|
});
|
|
169
175
|
}
|
|
170
176
|
}
|
|
171
|
-
|
|
177
|
+
_chunkC36XJ7D3js.__name.call(void 0, add, "add");
|
|
172
178
|
async function buildNestModule(Module) {
|
|
173
179
|
const paramtypes = getParamTypes(Module);
|
|
174
180
|
let instance;
|
|
175
|
-
const tag =
|
|
181
|
+
const tag = _phecdacore.getTag.call(void 0, Module);
|
|
176
182
|
if (moduleMap.has(tag)) {
|
|
177
183
|
instance = moduleMap.get(tag);
|
|
178
184
|
if (!instance)
|
|
179
185
|
throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`);
|
|
180
186
|
if (constructorMap.get(tag) !== Module && !constructorSet.has(Module)) {
|
|
181
187
|
constructorSet.add(Module);
|
|
182
|
-
|
|
188
|
+
_chunkC36XJ7D3js.log.call(void 0, `Synonym module: Module taged "${tag}" has been loaded before, so phecda-server won't load Module "${Module.name}"`, "warn");
|
|
183
189
|
}
|
|
184
190
|
return {
|
|
185
191
|
instance,
|
|
@@ -187,6 +193,7 @@ async function Factory(Modules, opts = {}) {
|
|
|
187
193
|
};
|
|
188
194
|
}
|
|
189
195
|
moduleMap.set(tag, void 0);
|
|
196
|
+
debug(`instantiate module "${tag}"`);
|
|
190
197
|
if (paramtypes) {
|
|
191
198
|
const paramtypesInstances = [];
|
|
192
199
|
for (const i in paramtypes) {
|
|
@@ -196,15 +203,13 @@ async function Factory(Modules, opts = {}) {
|
|
|
196
203
|
moduleGraph.set(subTag, /* @__PURE__ */ new Set());
|
|
197
204
|
moduleGraph.get(subTag).add(tag);
|
|
198
205
|
}
|
|
199
|
-
debug(`instantiate module "${tag}"`);
|
|
200
206
|
instance = new Module(...paramtypesInstances);
|
|
201
207
|
} else {
|
|
202
|
-
debug(`instantiate module "${tag}"`);
|
|
203
208
|
instance = new Module();
|
|
204
209
|
}
|
|
205
210
|
meta.push(...getMetaFromInstance(instance, tag, Module.name));
|
|
206
211
|
debug(`init module "${tag}"`);
|
|
207
|
-
await _phecdacore.
|
|
212
|
+
await _phecdacore.registerSerial.call(void 0, instance);
|
|
208
213
|
debug(`add module "${tag}"`);
|
|
209
214
|
moduleMap.set(tag, instance);
|
|
210
215
|
constructorMap.set(tag, Module);
|
|
@@ -213,7 +218,7 @@ async function Factory(Modules, opts = {}) {
|
|
|
213
218
|
tag
|
|
214
219
|
};
|
|
215
220
|
}
|
|
216
|
-
|
|
221
|
+
_chunkC36XJ7D3js.__name.call(void 0, buildNestModule, "buildNestModule");
|
|
217
222
|
for (const Module of Modules)
|
|
218
223
|
await buildNestModule(Module);
|
|
219
224
|
function writeCode() {
|
|
@@ -226,12 +231,12 @@ async function Factory(Modules, opts = {}) {
|
|
|
226
231
|
_fs2.default.promises.writeFile(rpc, generateRPCCode(meta.map((item) => item.data)));
|
|
227
232
|
}
|
|
228
233
|
}
|
|
229
|
-
|
|
234
|
+
_chunkC36XJ7D3js.__name.call(void 0, writeCode, "writeCode");
|
|
230
235
|
writeCode();
|
|
231
|
-
if (
|
|
236
|
+
if (_chunkC36XJ7D3js.IS_DEV) {
|
|
232
237
|
if (!globalThis.__PS_HMR__)
|
|
233
238
|
globalThis.__PS_HMR__ = [];
|
|
234
|
-
_optionalChain([globalThis, 'access',
|
|
239
|
+
_optionalChain([globalThis, 'access', _6 => _6.__PS_HMR__, 'optionalAccess', _7 => _7.push, 'call', _8 => _8(async (files) => {
|
|
235
240
|
debug("reload files ");
|
|
236
241
|
for (const file of files) {
|
|
237
242
|
const module = await Promise.resolve().then(() => require(file));
|
|
@@ -248,13 +253,14 @@ async function Factory(Modules, opts = {}) {
|
|
|
248
253
|
meta,
|
|
249
254
|
constructorMap,
|
|
250
255
|
add,
|
|
251
|
-
del
|
|
256
|
+
del,
|
|
257
|
+
destroy
|
|
252
258
|
};
|
|
253
259
|
}
|
|
254
|
-
|
|
260
|
+
_chunkC36XJ7D3js.__name.call(void 0, Factory, "Factory");
|
|
255
261
|
function getMetaFromInstance(instance, tag, name) {
|
|
256
|
-
const vars = _phecdacore.getExposeKey.call(void 0, instance).filter((item) => item !==
|
|
257
|
-
const baseState = _phecdacore.getState.call(void 0, instance,
|
|
262
|
+
const vars = _phecdacore.getExposeKey.call(void 0, instance).filter((item) => item !== _phecdacore.SHARE_KEY);
|
|
263
|
+
const baseState = _phecdacore.getState.call(void 0, instance, _phecdacore.SHARE_KEY) || {};
|
|
258
264
|
initState(baseState);
|
|
259
265
|
return vars.map((i) => {
|
|
260
266
|
const meta = {};
|
|
@@ -262,7 +268,7 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
262
268
|
initState(state);
|
|
263
269
|
if (state.http) {
|
|
264
270
|
meta.http = {
|
|
265
|
-
route: (_optionalChain([baseState, 'access',
|
|
271
|
+
route: (_optionalChain([baseState, 'access', _9 => _9.http, 'optionalAccess', _10 => _10.route]) || "") + state.http.route,
|
|
266
272
|
type: state.http.type
|
|
267
273
|
};
|
|
268
274
|
}
|
|
@@ -314,11 +320,11 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
314
320
|
return new Meta(meta, _phecdacore.getHandler.call(void 0, instance, i), getParamTypes(instance, i) || []);
|
|
315
321
|
});
|
|
316
322
|
}
|
|
317
|
-
|
|
323
|
+
_chunkC36XJ7D3js.__name.call(void 0, getMetaFromInstance, "getMetaFromInstance");
|
|
318
324
|
function getParamTypes(Module, key) {
|
|
319
325
|
return Reflect.getMetadata("design:paramtypes", Module, key);
|
|
320
326
|
}
|
|
321
|
-
|
|
327
|
+
_chunkC36XJ7D3js.__name.call(void 0, getParamTypes, "getParamTypes");
|
|
322
328
|
function initState(state) {
|
|
323
329
|
if (!state.define)
|
|
324
330
|
state.define = {};
|
|
@@ -331,7 +337,7 @@ function initState(state) {
|
|
|
331
337
|
if (!state.interceptors)
|
|
332
338
|
state.interceptors = [];
|
|
333
339
|
}
|
|
334
|
-
|
|
340
|
+
_chunkC36XJ7D3js.__name.call(void 0, initState, "initState");
|
|
335
341
|
|
|
336
342
|
|
|
337
343
|
|
|
@@ -50,6 +50,16 @@ function setConfig(key, conf, force = true) {
|
|
|
50
50
|
_phecdacore.DataMap[key] = conf;
|
|
51
51
|
}
|
|
52
52
|
__name(setConfig, "setConfig");
|
|
53
|
+
function Mix(InternalClass, ExtendClass) {
|
|
54
|
+
return class extends ExtendClass {
|
|
55
|
+
constructor(...args) {
|
|
56
|
+
super(...args);
|
|
57
|
+
Object.assign(this, new InternalClass());
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
__name(Mix, "Mix");
|
|
62
|
+
|
|
53
63
|
|
|
54
64
|
|
|
55
65
|
|
|
@@ -67,4 +77,4 @@ __name(setConfig, "setConfig");
|
|
|
67
77
|
|
|
68
78
|
|
|
69
79
|
|
|
70
|
-
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.APP_SYMBOL = APP_SYMBOL; exports.IS_DEV = IS_DEV; exports.IS_STRICT = IS_STRICT; 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;
|
|
80
|
+
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.APP_SYMBOL = APP_SYMBOL; exports.IS_DEV = IS_DEV; exports.IS_STRICT = IS_STRICT; 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;
|
|
@@ -50,6 +50,15 @@ function setConfig(key, conf, force = true) {
|
|
|
50
50
|
DataMap[key] = conf;
|
|
51
51
|
}
|
|
52
52
|
__name(setConfig, "setConfig");
|
|
53
|
+
function Mix(InternalClass, ExtendClass) {
|
|
54
|
+
return class extends ExtendClass {
|
|
55
|
+
constructor(...args) {
|
|
56
|
+
super(...args);
|
|
57
|
+
Object.assign(this, new InternalClass());
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
__name(Mix, "Mix");
|
|
53
62
|
|
|
54
63
|
export {
|
|
55
64
|
__name,
|
|
@@ -66,5 +75,6 @@ export {
|
|
|
66
75
|
PS_IMPORT_RE,
|
|
67
76
|
log,
|
|
68
77
|
getConfig,
|
|
69
|
-
setConfig
|
|
78
|
+
setConfig,
|
|
79
|
+
Mix
|
|
70
80
|
};
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
UNMOUNT_SYMBOL,
|
|
4
4
|
__name,
|
|
5
5
|
log
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-KGMDCF26.mjs";
|
|
7
7
|
|
|
8
8
|
// src/meta.ts
|
|
9
9
|
var Meta = class {
|
|
@@ -103,7 +103,7 @@ __name(generateHTTPCode, "generateHTTPCode");
|
|
|
103
103
|
import "reflect-metadata";
|
|
104
104
|
import fs from "fs";
|
|
105
105
|
import EventEmitter from "node:events";
|
|
106
|
-
import { Empty, getExposeKey, getHandler, getProperty, getState, injectProperty, isPhecda,
|
|
106
|
+
import { Empty, SHARE_KEY, getExposeKey, getHandler, getProperty, getState, getTag, injectProperty, isPhecda, registerSerial } from "phecda-core";
|
|
107
107
|
import Debug from "debug";
|
|
108
108
|
function Injectable() {
|
|
109
109
|
return (target) => Empty(target);
|
|
@@ -151,6 +151,12 @@ async function Factory(Modules, opts = {}) {
|
|
|
151
151
|
return instance;
|
|
152
152
|
}
|
|
153
153
|
__name(del, "del");
|
|
154
|
+
async function destroy() {
|
|
155
|
+
debug("destroy all");
|
|
156
|
+
for (const [tag] of moduleMap)
|
|
157
|
+
await del(tag);
|
|
158
|
+
}
|
|
159
|
+
__name(destroy, "destroy");
|
|
154
160
|
async function add(Module) {
|
|
155
161
|
const tag = Module.prototype?.__TAG__ || Module.name;
|
|
156
162
|
const oldInstance = await del(tag);
|
|
@@ -172,7 +178,7 @@ async function Factory(Modules, opts = {}) {
|
|
|
172
178
|
async function buildNestModule(Module) {
|
|
173
179
|
const paramtypes = getParamTypes(Module);
|
|
174
180
|
let instance;
|
|
175
|
-
const tag = Module
|
|
181
|
+
const tag = getTag(Module);
|
|
176
182
|
if (moduleMap.has(tag)) {
|
|
177
183
|
instance = moduleMap.get(tag);
|
|
178
184
|
if (!instance)
|
|
@@ -187,6 +193,7 @@ async function Factory(Modules, opts = {}) {
|
|
|
187
193
|
};
|
|
188
194
|
}
|
|
189
195
|
moduleMap.set(tag, void 0);
|
|
196
|
+
debug(`instantiate module "${tag}"`);
|
|
190
197
|
if (paramtypes) {
|
|
191
198
|
const paramtypesInstances = [];
|
|
192
199
|
for (const i in paramtypes) {
|
|
@@ -196,15 +203,13 @@ async function Factory(Modules, opts = {}) {
|
|
|
196
203
|
moduleGraph.set(subTag, /* @__PURE__ */ new Set());
|
|
197
204
|
moduleGraph.get(subTag).add(tag);
|
|
198
205
|
}
|
|
199
|
-
debug(`instantiate module "${tag}"`);
|
|
200
206
|
instance = new Module(...paramtypesInstances);
|
|
201
207
|
} else {
|
|
202
|
-
debug(`instantiate module "${tag}"`);
|
|
203
208
|
instance = new Module();
|
|
204
209
|
}
|
|
205
210
|
meta.push(...getMetaFromInstance(instance, tag, Module.name));
|
|
206
211
|
debug(`init module "${tag}"`);
|
|
207
|
-
await
|
|
212
|
+
await registerSerial(instance);
|
|
208
213
|
debug(`add module "${tag}"`);
|
|
209
214
|
moduleMap.set(tag, instance);
|
|
210
215
|
constructorMap.set(tag, Module);
|
|
@@ -248,13 +253,14 @@ async function Factory(Modules, opts = {}) {
|
|
|
248
253
|
meta,
|
|
249
254
|
constructorMap,
|
|
250
255
|
add,
|
|
251
|
-
del
|
|
256
|
+
del,
|
|
257
|
+
destroy
|
|
252
258
|
};
|
|
253
259
|
}
|
|
254
260
|
__name(Factory, "Factory");
|
|
255
261
|
function getMetaFromInstance(instance, tag, name) {
|
|
256
|
-
const vars = getExposeKey(instance).filter((item) => item !==
|
|
257
|
-
const baseState = getState(instance,
|
|
262
|
+
const vars = getExposeKey(instance).filter((item) => item !== SHARE_KEY);
|
|
263
|
+
const baseState = getState(instance, SHARE_KEY) || {};
|
|
258
264
|
initState(baseState);
|
|
259
265
|
return vars.map((i) => {
|
|
260
266
|
const meta = {};
|