@lakutata/core 1.0.26 → 1.0.30
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/README.md +4 -0
- package/build/Application.d.ts +3 -0
- package/build/Application.js +16 -0
- package/build/Application.js.map +1 -1
- package/build/ApplicationManagement.js +5 -0
- package/build/ApplicationManagement.js.map +1 -1
- package/build/base/Container.js +16 -0
- package/build/base/Container.js.map +1 -1
- package/build/base/abstracts/Module.js.map +1 -1
- package/build/base/process/Process.d.ts +1 -1
- package/build/base/process/Process.js +2 -2
- package/build/base/process/Process.js.map +1 -1
- package/build/base/process/ProcessManager.d.ts +1 -1
- package/build/base/process/ProcessManager.js +2 -2
- package/build/base/process/ProcessManager.js.map +1 -1
- package/build/base/thread/Thread.d.ts +1 -1
- package/build/base/thread/Thread.js +2 -2
- package/build/base/thread/Thread.js.map +1 -1
- package/build/base/thread/ThreadManager.d.ts +1 -1
- package/build/base/thread/ThreadManager.js +2 -2
- package/build/base/thread/ThreadManager.js.map +1 -1
- package/build/interfaces/IApplicationConfig.d.ts +1 -0
- package/build/lib/multipleRunner/constants/Channel.d.ts +5 -0
- package/build/lib/multipleRunner/constants/Channel.js +9 -0
- package/build/lib/multipleRunner/constants/Channel.js.map +1 -0
- package/build/lib/multipleRunner/constants/MetadataKey.d.ts +2 -0
- package/build/lib/multipleRunner/constants/MetadataKey.js +6 -0
- package/build/lib/multipleRunner/constants/MetadataKey.js.map +1 -0
- package/build/lib/multipleRunner/containers/ContainerVolume.d.ts +4 -0
- package/build/lib/multipleRunner/containers/ContainerVolume.js +85 -0
- package/build/lib/multipleRunner/containers/ContainerVolume.js.map +1 -0
- package/build/lib/multipleRunner/definitions/interfaces/ClassConstructor.d.ts +3 -0
- package/build/lib/multipleRunner/definitions/interfaces/ClassConstructor.js +3 -0
- package/build/lib/multipleRunner/definitions/interfaces/ClassConstructor.js.map +1 -0
- package/build/lib/multipleRunner/definitions/interfaces/MultipleRunnerBaseClassConstructor.d.ts +4 -0
- package/build/lib/multipleRunner/definitions/interfaces/MultipleRunnerBaseClassConstructor.js +3 -0
- package/build/lib/multipleRunner/definitions/interfaces/MultipleRunnerBaseClassConstructor.js.map +1 -0
- package/build/lib/multipleRunner/definitions/interfaces/ProcessClassConstructor.d.ts +7 -0
- package/build/lib/multipleRunner/definitions/interfaces/ProcessClassConstructor.js +3 -0
- package/build/lib/multipleRunner/definitions/interfaces/ProcessClassConstructor.js.map +1 -0
- package/build/lib/multipleRunner/definitions/interfaces/ProxyClass.d.ts +3 -0
- package/build/lib/multipleRunner/definitions/interfaces/ProxyClass.js +3 -0
- package/build/lib/multipleRunner/definitions/interfaces/ProxyClass.js.map +1 -0
- package/build/lib/multipleRunner/definitions/interfaces/ThreadClassConstructor.d.ts +7 -0
- package/build/lib/multipleRunner/definitions/interfaces/ThreadClassConstructor.js +3 -0
- package/build/lib/multipleRunner/definitions/interfaces/ThreadClassConstructor.js.map +1 -0
- package/build/lib/multipleRunner/lib/Process.d.ts +5 -0
- package/build/lib/multipleRunner/lib/Process.js +44 -0
- package/build/lib/multipleRunner/lib/Process.js.map +1 -0
- package/build/lib/multipleRunner/lib/Thread.d.ts +5 -0
- package/build/lib/multipleRunner/lib/Thread.js +52 -0
- package/build/lib/multipleRunner/lib/Thread.js.map +1 -0
- package/build/lib/multipleRunner/lib/bridges/BaseBridge.d.ts +32 -0
- package/build/lib/multipleRunner/lib/bridges/BaseBridge.js +104 -0
- package/build/lib/multipleRunner/lib/bridges/BaseBridge.js.map +1 -0
- package/build/lib/multipleRunner/lib/bridges/ProcessBridge.d.ts +5 -0
- package/build/lib/multipleRunner/lib/bridges/ProcessBridge.js +20 -0
- package/build/lib/multipleRunner/lib/bridges/ProcessBridge.js.map +1 -0
- package/build/lib/multipleRunner/lib/bridges/ThreadBridge.d.ts +5 -0
- package/build/lib/multipleRunner/lib/bridges/ThreadBridge.js +17 -0
- package/build/lib/multipleRunner/lib/bridges/ThreadBridge.js.map +1 -0
- package/build/lib/multipleRunner/lib/cores/GenerateExecArgv.d.ts +2 -0
- package/build/lib/multipleRunner/lib/cores/GenerateExecArgv.js +35 -0
- package/build/lib/multipleRunner/lib/cores/GenerateExecArgv.js.map +1 -0
- package/build/lib/multipleRunner/lib/cores/IsElectron.d.ts +1 -0
- package/build/lib/multipleRunner/lib/cores/IsElectron.js +9 -0
- package/build/lib/multipleRunner/lib/cores/IsElectron.js.map +1 -0
- package/build/lib/multipleRunner/lib/cores/ProcessClass.d.ts +5 -0
- package/build/lib/multipleRunner/lib/cores/ProcessClass.js +12 -0
- package/build/lib/multipleRunner/lib/cores/ProcessClass.js.map +1 -0
- package/build/lib/multipleRunner/lib/cores/ThreadClass.d.ts +5 -0
- package/build/lib/multipleRunner/lib/cores/ThreadClass.js +12 -0
- package/build/lib/multipleRunner/lib/cores/ThreadClass.js.map +1 -0
- package/build/lib/multipleRunner/lib/cores/UniParentBridgeHandler.d.ts +2 -0
- package/build/lib/multipleRunner/lib/cores/UniParentBridgeHandler.js +104 -0
- package/build/lib/multipleRunner/lib/cores/UniParentBridgeHandler.js.map +1 -0
- package/build/lib/multipleRunner/lib/prototypes/MultipleRunnerBaseClass.d.ts +17 -0
- package/build/lib/multipleRunner/lib/prototypes/MultipleRunnerBaseClass.js +53 -0
- package/build/lib/multipleRunner/lib/prototypes/MultipleRunnerBaseClass.js.map +1 -0
- package/build/plugins/Formatter.d.ts +1 -0
- package/build/plugins/Formatter.js +8 -5
- package/build/plugins/Formatter.js.map +1 -1
- package/build/plugins/Logger.js +6 -2
- package/build/plugins/Logger.js.map +1 -1
- package/build/types/TPluginsConfig.d.ts +1 -0
- package/package.json +11 -11
- package/src/Application.ts +29 -0
- package/src/ApplicationManagement.ts +3 -0
- package/src/base/Container.ts +14 -1
- package/src/base/abstracts/Module.ts +2 -1
- package/src/base/process/Process.ts +1 -1
- package/src/base/process/ProcessManager.ts +2 -2
- package/src/base/thread/Thread.ts +1 -1
- package/src/base/thread/ThreadManager.ts +2 -2
- package/src/interfaces/IApplicationConfig.ts +1 -0
- package/src/lib/multipleRunner/constants/Channel.ts +5 -0
- package/src/lib/multipleRunner/constants/MetadataKey.ts +2 -0
- package/src/lib/multipleRunner/containers/ContainerVolume.ts +83 -0
- package/src/lib/multipleRunner/definitions/interfaces/ClassConstructor.ts +3 -0
- package/src/lib/multipleRunner/definitions/interfaces/MultipleRunnerBaseClassConstructor.ts +5 -0
- package/src/lib/multipleRunner/definitions/interfaces/ProcessClassConstructor.ts +10 -0
- package/src/lib/multipleRunner/definitions/interfaces/ProxyClass.ts +3 -0
- package/src/lib/multipleRunner/definitions/interfaces/ThreadClassConstructor.ts +10 -0
- package/src/lib/multipleRunner/lib/Process.ts +44 -0
- package/src/lib/multipleRunner/lib/Thread.ts +52 -0
- package/src/lib/multipleRunner/lib/bridges/BaseBridge.ts +115 -0
- package/src/lib/multipleRunner/lib/bridges/ProcessBridge.ts +18 -0
- package/src/lib/multipleRunner/lib/bridges/ThreadBridge.ts +15 -0
- package/src/lib/multipleRunner/lib/cores/GenerateExecArgv.ts +28 -0
- package/src/lib/multipleRunner/lib/cores/IsElectron.ts +3 -0
- package/src/lib/multipleRunner/lib/cores/ProcessClass.ts +8 -0
- package/src/lib/multipleRunner/lib/cores/ThreadClass.ts +8 -0
- package/src/lib/multipleRunner/lib/cores/UniParentBridgeHandler.ts +97 -0
- package/src/lib/multipleRunner/lib/prototypes/MultipleRunnerBaseClass.ts +66 -0
- package/src/plugins/Formatter.ts +10 -5
- package/src/plugins/Logger.ts +3 -2
- package/src/tests/Main.spec.ts +10 -6
- package/src/tests/threads/TestThread.ts +3 -1
- package/src/types/TPluginsConfig.ts +1 -1
- package/.idea/dbnavigator.xml +0 -558
|
@@ -14,24 +14,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Formatter = void 0;
|
|
16
16
|
const Plugin_1 = require("../base/Plugin");
|
|
17
|
-
const
|
|
17
|
+
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
18
18
|
const DependencyInjection_1 = require("../decorators/DependencyInjection");
|
|
19
19
|
class Formatter extends Plugin_1.Plugin {
|
|
20
20
|
constructor() {
|
|
21
21
|
super(...arguments);
|
|
22
22
|
this.dateFormat = 'YYYY-MM-DD HH:mm:ss';
|
|
23
23
|
}
|
|
24
|
+
get timezone() {
|
|
25
|
+
return process.env.TZ;
|
|
26
|
+
}
|
|
24
27
|
asTimestamp(inp = new Date()) {
|
|
25
|
-
return
|
|
28
|
+
return moment_timezone_1.default.tz(inp, this.timezone).unix();
|
|
26
29
|
}
|
|
27
30
|
asMillisecondTimestamp(inp = new Date()) {
|
|
28
|
-
return
|
|
31
|
+
return moment_timezone_1.default.tz(inp, this.timezone).valueOf();
|
|
29
32
|
}
|
|
30
33
|
asDate(inp) {
|
|
31
|
-
return
|
|
34
|
+
return moment_timezone_1.default.tz(inp, this.timezone).toDate();
|
|
32
35
|
}
|
|
33
36
|
asDateText(inp = new Date(), format) {
|
|
34
|
-
return
|
|
37
|
+
return moment_timezone_1.default.tz(inp, this.timezone).format(format ? format : this.dateFormat);
|
|
35
38
|
}
|
|
36
39
|
asPercent(value, decimals = 2) {
|
|
37
40
|
const val = +((value * 100).toFixed(decimals));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Formatter.js","sourceRoot":"","sources":["../../src/plugins/Formatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAqC;AACrC,
|
|
1
|
+
{"version":3,"file":"Formatter.js","sourceRoot":"","sources":["../../src/plugins/Formatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAqC;AACrC,sEAA4C;AAC5C,2EAA8D;AAQ9D,MAAa,SAAU,SAAQ,eAAM;IAArC;;QAYoB,eAAU,GAAW,qBAAqB,CAAA;IAiD9D,CAAC;IA3DA,IAAc,QAAQ;QACrB,OAAe,OAAO,CAAC,GAAG,CAAC,EAAE,CAAA;IAC9B,CAAC;IAeM,WAAW,CAAC,MAA8B,IAAI,IAAI,EAAE;QAC1D,OAAO,yBAAc,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAA;IACpD,CAAC;IAOM,sBAAsB,CAAC,MAA8B,IAAI,IAAI,EAAE;QACrE,OAAO,yBAAc,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAA;IACvD,CAAC;IAOM,MAAM,CAAC,GAA2B;QACxC,OAAO,yBAAc,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAA;IACtD,CAAC;IAQM,UAAU,CAAC,MAA8B,IAAI,IAAI,EAAE,EAAE,MAAe;QAC1E,OAAO,yBAAc,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACvF,CAAC;IAQM,SAAS,CAAC,KAAa,EAAE,WAAmB,CAAC;QACnD,MAAM,GAAG,GAAW,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;QACtD,OAAO,GAAG,GAAG,GAAG,CAAA;IACjB,CAAC;CACD;AAjDA;IADC,kCAAY,EAAE;;6CAC8C;AAZ9D,8BA6DC"}
|
package/build/plugins/Logger.js
CHANGED
|
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.Logger = void 0;
|
|
13
16
|
const Plugin_1 = require("../base/Plugin");
|
|
@@ -15,6 +18,7 @@ const winston_1 = require("winston");
|
|
|
15
18
|
const DependencyInjection_1 = require("../decorators/DependencyInjection");
|
|
16
19
|
const util_1 = require("util");
|
|
17
20
|
const transports_1 = require("winston/lib/winston/transports");
|
|
21
|
+
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
18
22
|
class Logger extends Plugin_1.Plugin {
|
|
19
23
|
constructor() {
|
|
20
24
|
super(...arguments);
|
|
@@ -22,8 +26,8 @@ class Logger extends Plugin_1.Plugin {
|
|
|
22
26
|
this.transports = [];
|
|
23
27
|
this.console = {
|
|
24
28
|
silent: false,
|
|
25
|
-
format: winston_1.format.combine(winston_1.format.timestamp(
|
|
26
|
-
return `${packet.timestamp} ${packet.level}: ${packet.message}`;
|
|
29
|
+
format: winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.colorize(), winston_1.format.printf(packet => {
|
|
30
|
+
return `${moment_timezone_1.default.tz(packet.timestamp, process.env.TZ).format('YYYY-MM-DD HH:mm:ss')} ${packet.level}: ${packet.message}`;
|
|
27
31
|
}))
|
|
28
32
|
};
|
|
29
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/plugins/Logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/plugins/Logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAqC;AACrC,qCAAiF;AACjF,2EAA8D;AAE9D,+BAAyC;AACzC,+DAAsE;AACtE,sEAA4C;AAQ5C,MAAa,MAAO,SAAQ,eAAM;IAAlC;;QAIoB,UAAK,GAAmF,OAAO,CAAA;QAM/F,eAAU,GAA4B,EAAE,CAAA;Q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AAW;QAC1B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAA;IAC9C,CAAC;CACD;AAlIA;IADC,kCAAY,EAAE;;qCACmG;AAGlH;IADC,kCAAY,EAAE;;oCACgB;AAG/B;IADC,kCAAY,EAAE;;0CAC4C;AAG3D;IADC,kCAAY,EAAE;;uCAUd;AAtBF,wBAsIC"}
|
|
@@ -2,5 +2,6 @@ import { IConstructor } from '../interfaces/IConstructor';
|
|
|
2
2
|
import { Plugin } from '../base/Plugin';
|
|
3
3
|
export declare type TPluginsConfig<TPlugin extends Plugin = Plugin> = ({
|
|
4
4
|
class: IConstructor<TPlugin>;
|
|
5
|
+
scope?: 'Transient' | 'Singleton';
|
|
5
6
|
[propertyKey: string]: any;
|
|
6
7
|
} | IConstructor<TPlugin>)[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakutata/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "Lakutata Framework Core",
|
|
5
5
|
"main": "./build/Core.js",
|
|
6
6
|
"types": "./build/Core.d.ts",
|
|
@@ -54,40 +54,40 @@
|
|
|
54
54
|
"license": "MIT",
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@thiagodelgado111/yup-phone": "^0.0.2",
|
|
57
|
-
"@types/lodash.mapvalues": "^4.6.6",
|
|
58
57
|
"bcryptjs": "^2.4.3",
|
|
59
|
-
"crypto-js": "^4.
|
|
60
|
-
"ergate": "^2.0.10",
|
|
58
|
+
"crypto-js": "^4.1.1",
|
|
61
59
|
"inversify": "^5.1.1",
|
|
62
|
-
"is-ssh": "^1.3.
|
|
60
|
+
"is-ssh": "^1.3.3",
|
|
63
61
|
"json-helpers": "^5.1.4",
|
|
64
62
|
"json5": "^2.2.0",
|
|
65
63
|
"lodash.mapvalues": "^4.6.0",
|
|
66
|
-
"memfs": "^3.
|
|
64
|
+
"memfs": "^3.4.0",
|
|
67
65
|
"merge-deep": "^3.0.3",
|
|
68
66
|
"moment": "^2.29.1",
|
|
67
|
+
"moment-timezone": "^0.5.34",
|
|
69
68
|
"msgpack5": "^5.3.2",
|
|
70
|
-
"needle": "^2.
|
|
69
|
+
"needle": "^2.9.1",
|
|
71
70
|
"node-rsa": "^1.1.1",
|
|
72
71
|
"p-timeout": "^4.1.0",
|
|
73
72
|
"pupa": "^2.1.1",
|
|
73
|
+
"random": "^3.0.6",
|
|
74
74
|
"reflect-metadata": "^0.1.13",
|
|
75
75
|
"string-random": "^0.1.3",
|
|
76
|
-
"v8-compile-cache": "^2.3.0",
|
|
77
76
|
"valid-data-url": "^3.0.1",
|
|
78
77
|
"winston": "^3.3.3",
|
|
79
78
|
"winston-transport": "^4.4.0",
|
|
80
|
-
"yup": "^0.32.
|
|
79
|
+
"yup": "^0.32.11"
|
|
81
80
|
},
|
|
82
81
|
"devDependencies": {
|
|
83
82
|
"@types/bcryptjs": "^2.4.2",
|
|
84
83
|
"@types/chai": "^4.2.14",
|
|
85
|
-
"@types/crypto-js": "^4.0.
|
|
84
|
+
"@types/crypto-js": "^4.0.2",
|
|
86
85
|
"@types/is-ssh": "^1.3.0",
|
|
86
|
+
"@types/lodash.mapvalues": "^4.6.6",
|
|
87
87
|
"@types/merge-deep": "^3.0.0",
|
|
88
88
|
"@types/mocha": "^8.2.2",
|
|
89
89
|
"@types/msgpack5": "^3.4.1",
|
|
90
|
-
"@types/needle": "^2.5.
|
|
90
|
+
"@types/needle": "^2.5.2",
|
|
91
91
|
"@types/node": "^15.12.2",
|
|
92
92
|
"@types/node-rsa": "^1.1.0",
|
|
93
93
|
"@types/valid-data-url": "^2.0.0",
|
package/src/Application.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {Logger} from './plugins/Logger'
|
|
|
13
13
|
import {format} from 'winston'
|
|
14
14
|
import {TProcessesConfig} from './types/TProcessesConfig'
|
|
15
15
|
import {TThreadsConfig} from './types/TThreadsConfig'
|
|
16
|
+
import momentTimezone from 'moment-timezone'
|
|
16
17
|
|
|
17
18
|
export class Application extends Module {
|
|
18
19
|
/**
|
|
@@ -125,6 +126,18 @@ export class Application extends Module {
|
|
|
125
126
|
*/
|
|
126
127
|
protected readonly workflows: TWorkflowsConfig = []
|
|
127
128
|
|
|
129
|
+
/**
|
|
130
|
+
* 程序时区
|
|
131
|
+
* @type {string}
|
|
132
|
+
* @protected
|
|
133
|
+
*/
|
|
134
|
+
protected tz: string = (() => {
|
|
135
|
+
if (!process.env.TZ) {
|
|
136
|
+
process.env.TZ = momentTimezone.tz.guess()
|
|
137
|
+
}
|
|
138
|
+
return process.env.TZ
|
|
139
|
+
})()
|
|
140
|
+
|
|
128
141
|
/**
|
|
129
142
|
* 初始化
|
|
130
143
|
* @returns {Promise<void>}
|
|
@@ -137,6 +150,22 @@ export class Application extends Module {
|
|
|
137
150
|
})
|
|
138
151
|
}
|
|
139
152
|
|
|
153
|
+
/**
|
|
154
|
+
* 获取程序时区
|
|
155
|
+
* @returns {string}
|
|
156
|
+
*/
|
|
157
|
+
public getTimezone() {
|
|
158
|
+
return this.tz
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 设置程序时区
|
|
163
|
+
* @param {string} tz
|
|
164
|
+
*/
|
|
165
|
+
public setTimezone(tz: string) {
|
|
166
|
+
this.tz = tz
|
|
167
|
+
}
|
|
168
|
+
|
|
140
169
|
/**
|
|
141
170
|
* 获取应用程序ID
|
|
142
171
|
* @returns {string}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import momentTimezone from 'moment-timezone'
|
|
2
|
+
|
|
1
3
|
require('events').captureRejections = true
|
|
2
4
|
import {IApplicationConfig} from './interfaces/IApplicationConfig'
|
|
3
5
|
import {Application} from './Application'
|
|
@@ -19,6 +21,7 @@ export async function createApp(config: IApplicationConfig): Promise<Application
|
|
|
19
21
|
process.title = config.id
|
|
20
22
|
process.env.appId = config.id
|
|
21
23
|
process.env.appName = config.name
|
|
24
|
+
process.env.TZ = config.timezone ? config.timezone : momentTimezone.tz.guess()
|
|
22
25
|
await coreContainer.initialize()
|
|
23
26
|
return coreContainer.getModule(Application)
|
|
24
27
|
} catch (e) {
|
package/src/base/Container.ts
CHANGED
|
@@ -83,12 +83,25 @@ export class Container<TObject extends BaseObject = BaseObject, TPlugin extends
|
|
|
83
83
|
* @param {IConstructor<TPlugin>} pluginConstructor
|
|
84
84
|
* @param {string} identifier
|
|
85
85
|
* @param {object} config
|
|
86
|
-
* @param {"Transient" | "Singleton"} scope
|
|
87
86
|
*/
|
|
88
87
|
public bindPlugin(pluginConstructor: IConstructor<TPlugin>, identifier: string, config: object): void {
|
|
88
|
+
const scope = config['scope'] ? config['scope'] : 'Transient'
|
|
89
89
|
const pluginConfiguration = config ? config : {}
|
|
90
90
|
if (this.pluginIoC.isBound(identifier)) return
|
|
91
91
|
const binding = this.pluginIoC.bind(identifier).to(pluginConstructor)
|
|
92
|
+
switch (scope) {
|
|
93
|
+
case 'Transient': {
|
|
94
|
+
binding.inTransientScope()
|
|
95
|
+
}
|
|
96
|
+
break
|
|
97
|
+
case 'Singleton': {
|
|
98
|
+
binding.inSingletonScope()
|
|
99
|
+
}
|
|
100
|
+
break
|
|
101
|
+
default: {
|
|
102
|
+
binding.inTransientScope()
|
|
103
|
+
}
|
|
104
|
+
}
|
|
92
105
|
binding.onActivation((context, injectable) => {
|
|
93
106
|
const onActivationFunc = function (this: TPlugin) {
|
|
94
107
|
const pluginConfigurationKeys = Object.keys(pluginConfiguration)
|
|
@@ -160,12 +160,13 @@ export abstract class Module extends BaseObject {
|
|
|
160
160
|
* @protected
|
|
161
161
|
*/
|
|
162
162
|
protected bindPlugins(): void {
|
|
163
|
+
//todo 可能需要合并一下多个相同插件的配置
|
|
163
164
|
if (!this.plugins) return
|
|
164
165
|
const reversedPlugins = this.plugins.reverse()
|
|
165
166
|
const registeredPluginSet = new Set()
|
|
166
167
|
for (const pluginConstructorOrConfig of reversedPlugins) {
|
|
167
168
|
let pluginConstructor
|
|
168
|
-
let pluginConfig: object = {}
|
|
169
|
+
let pluginConfig: object & { scope?: 'Transient' | 'Singleton' } = {}
|
|
169
170
|
if (typeof pluginConstructorOrConfig === 'object') {
|
|
170
171
|
pluginConstructor = pluginConstructorOrConfig.class
|
|
171
172
|
for (const configKey of Object.keys(pluginConstructorOrConfig)) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {Process} from './Process'
|
|
2
|
-
import {ProxyClass} from 'ergate'
|
|
3
2
|
import {IProcessConstructor} from '../../interfaces/IProcessConstructor'
|
|
4
|
-
import {Process as processCreate} from 'ergate'
|
|
5
3
|
import {ProcessException} from '../../exceptions/ProcessException'
|
|
4
|
+
import {ProxyClass} from '../../lib/multipleRunner/definitions/interfaces/ProxyClass'
|
|
5
|
+
import {Process as processCreate} from '../../lib/multipleRunner/lib/Process'
|
|
6
6
|
|
|
7
7
|
export class ProcessManager<TProcess extends Process = Process> {
|
|
8
8
|
protected readonly processMap: Map<IProcessConstructor<TProcess>, TProcess & ProxyClass> = new Map()
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {Thread} from './Thread'
|
|
2
2
|
import {IThreadConstructor} from '../../interfaces/IThreadConstructor'
|
|
3
|
-
import {Thread as threadCreate} from 'ergate'
|
|
4
3
|
import {ThreadException} from '../../exceptions/ThreadException'
|
|
5
|
-
import {ProxyClass} from '
|
|
4
|
+
import {ProxyClass} from '../../lib/multipleRunner/definitions/interfaces/ProxyClass'
|
|
5
|
+
import {Thread as threadCreate} from '../../lib/multipleRunner/lib/Thread'
|
|
6
6
|
|
|
7
7
|
export class ThreadManager<TThread extends Thread = Thread> {
|
|
8
8
|
protected readonly threadMap: Map<IThreadConstructor<TThread>, TThread & ProxyClass> = new Map()
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const READY: string = '_____%$ready$%_____'
|
|
2
|
+
export const SETUP_ERROR: string = '_____%$setup_error$%_____'
|
|
3
|
+
export const INVOKE: string = '__%$invoke$%__'
|
|
4
|
+
export const SET_PROPERTY: string = '_____%$set_property$%_____'
|
|
5
|
+
export const PROPERTY_CHANGE: string = '_____%$property_change$%_____'
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {Volume} from 'memfs'
|
|
2
|
+
|
|
3
|
+
export const BASE_RUNTIME_CONTAINER_FILE: string = '/multipleRunner/container/base/BaseRuntimeContainer.js'
|
|
4
|
+
export const PROCESS_RUNTIME_CONTAINER_FILE: string = '/multipleRunner/container/ProcessRuntimeContainer.js'
|
|
5
|
+
export const THREAD_RUNTIME_CONTAINER_FILE: string = '/multipleRunner/container/ThreadRuntimeContainer.js'
|
|
6
|
+
|
|
7
|
+
export const ContainerVolume = Volume.fromJSON({
|
|
8
|
+
[BASE_RUNTIME_CONTAINER_FILE]: `
|
|
9
|
+
module.exports.BaseRuntimeContainer = function (bridge) {
|
|
10
|
+
bridge.on('create', (name, path) => {
|
|
11
|
+
const module = require(path)[name]
|
|
12
|
+
const moduleInstance = new module(bridge)
|
|
13
|
+
moduleInstance.setup().then(() => {
|
|
14
|
+
const properties = {}
|
|
15
|
+
const moduleInstancePropertiesObject = {}
|
|
16
|
+
for (const propertyName of Object.keys(moduleInstance)) {
|
|
17
|
+
properties[propertyName] = typeof moduleInstance[propertyName]
|
|
18
|
+
if (propertyName !== '__bridge__')
|
|
19
|
+
moduleInstancePropertiesObject[propertyName] = moduleInstance[propertyName]
|
|
20
|
+
}
|
|
21
|
+
const moduleInstanceProxy = new Proxy(moduleInstance, {
|
|
22
|
+
set(target, p, value) {
|
|
23
|
+
moduleInstance[p] = value
|
|
24
|
+
bridge.propertyChange(p.toString(), value)
|
|
25
|
+
return true
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
bridge.onSet((property, value) => {
|
|
29
|
+
moduleInstanceProxy[property] = value
|
|
30
|
+
})
|
|
31
|
+
bridge.ready(properties, JSON.parse(JSON.stringify(moduleInstancePropertiesObject)))
|
|
32
|
+
bridge.onInvoke(async (method, args) => {
|
|
33
|
+
const _args = []
|
|
34
|
+
const callbackSignature = /^__________%\\$CALLBACK\\[\\d+]\\$%__________$/
|
|
35
|
+
for (const arg of args) {
|
|
36
|
+
if (typeof arg === 'string' && callbackSignature.test(arg)) {
|
|
37
|
+
_args.push((...args) => {
|
|
38
|
+
bridge.onCallback(arg, args)
|
|
39
|
+
})
|
|
40
|
+
} else {
|
|
41
|
+
_args.push(arg)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return await moduleInstanceProxy[method].apply(moduleInstanceProxy, _args)
|
|
45
|
+
})
|
|
46
|
+
}).catch(setupError => {
|
|
47
|
+
bridge.setupError(setupError)
|
|
48
|
+
process.exit(1)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
`,
|
|
53
|
+
[PROCESS_RUNTIME_CONTAINER_FILE]: `
|
|
54
|
+
const reversedArgvs = process.argv.reverse()
|
|
55
|
+
require(reversedArgvs[0])
|
|
56
|
+
const {ProcessBridge} = require(reversedArgvs[0])
|
|
57
|
+
const {BaseRuntimeContainer} = require(reversedArgvs[1])
|
|
58
|
+
BaseRuntimeContainer(new ProcessBridge(process))
|
|
59
|
+
`,
|
|
60
|
+
[THREAD_RUNTIME_CONTAINER_FILE]: `
|
|
61
|
+
const reversedArgvs = process.argv.reverse()
|
|
62
|
+
if(reversedArgvs[3]!=='undefined'){
|
|
63
|
+
try{require(reversedArgvs[3])}catch(e){}
|
|
64
|
+
}
|
|
65
|
+
const {parentPort} = require('worker_threads')
|
|
66
|
+
let _ThreadBridge
|
|
67
|
+
try{
|
|
68
|
+
const {ThreadBridge} = require(reversedArgvs[0])
|
|
69
|
+
_ThreadBridge = ThreadBridge
|
|
70
|
+
}catch(e){
|
|
71
|
+
const tsNodeRegExp=new RegExp("ts-node")
|
|
72
|
+
for(const reversedArgv of reversedArgvs){
|
|
73
|
+
if(tsNodeRegExp.test(reversedArgv)){
|
|
74
|
+
require(reversedArgv)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const {ThreadBridge} = require(reversedArgvs[0])
|
|
78
|
+
_ThreadBridge = ThreadBridge
|
|
79
|
+
}
|
|
80
|
+
const {BaseRuntimeContainer} = require(reversedArgvs[1])
|
|
81
|
+
BaseRuntimeContainer(new _ThreadBridge(parentPort))
|
|
82
|
+
`
|
|
83
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {ProcessClass} from '../../lib/cores/ProcessClass'
|
|
2
|
+
import {ClassConstructor} from './ClassConstructor'
|
|
3
|
+
|
|
4
|
+
export interface ProcessClassConstructor<T extends ProcessClass> extends ClassConstructor<T> {
|
|
5
|
+
new(...args: any[]): T
|
|
6
|
+
|
|
7
|
+
CLASS_PATH: string
|
|
8
|
+
|
|
9
|
+
CLASS_NAME: string
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {ThreadClass} from '../../lib/cores/ThreadClass'
|
|
2
|
+
import {ClassConstructor} from './ClassConstructor'
|
|
3
|
+
|
|
4
|
+
export interface ThreadClassConstructor<T extends ThreadClass> extends ClassConstructor<T> {
|
|
5
|
+
new(...args: any[]): T
|
|
6
|
+
|
|
7
|
+
CLASS_PATH: string
|
|
8
|
+
|
|
9
|
+
CLASS_NAME: string
|
|
10
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import 'reflect-metadata'
|
|
2
|
+
import {ProcessClassConstructor} from '../definitions/interfaces/ProcessClassConstructor'
|
|
3
|
+
import {ChildProcess, fork} from 'child_process'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import {GenerateExecArgv} from './cores/GenerateExecArgv'
|
|
6
|
+
import {ProcessBridge} from './bridges/ProcessBridge'
|
|
7
|
+
import {ProcessClass} from './cores/ProcessClass'
|
|
8
|
+
import {UniParentBridgeHandler} from './cores/UniParentBridgeHandler'
|
|
9
|
+
import {ProxyClass} from '../definitions/interfaces/ProxyClass'
|
|
10
|
+
import {
|
|
11
|
+
BASE_RUNTIME_CONTAINER_FILE,
|
|
12
|
+
ContainerVolume,
|
|
13
|
+
PROCESS_RUNTIME_CONTAINER_FILE
|
|
14
|
+
} from '../containers/ContainerVolume'
|
|
15
|
+
import fs from 'fs'
|
|
16
|
+
import os from 'os'
|
|
17
|
+
|
|
18
|
+
export async function Process<T extends ProcessClass>(processClassConstructor: ProcessClassConstructor<T>): Promise<T & ProxyClass> {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
ProcessProxy(processClassConstructor, (setupError, instance) => {
|
|
21
|
+
if (setupError) {
|
|
22
|
+
reject(setupError)
|
|
23
|
+
} else {
|
|
24
|
+
resolve(<T & ProxyClass>instance)
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function ProcessProxy<T extends ProcessClass>(processClassConstructor: ProcessClassConstructor<T>, callback: (setupError: Error, instance: T) => void) {
|
|
31
|
+
const className: string = processClassConstructor.CLASS_NAME
|
|
32
|
+
const classPath: string = processClassConstructor.CLASS_PATH
|
|
33
|
+
const tmpProcessRuntimeContainerFilename: string = path.resolve(os.tmpdir(), `./PRC_TMP_${Date.now()}.tmp`)
|
|
34
|
+
const tmpBaseRuntimeContainerFilename: string = path.resolve(os.tmpdir(), `./PBRC_TMP_${Date.now()}.tmp`)
|
|
35
|
+
fs.writeFileSync(tmpBaseRuntimeContainerFilename, ContainerVolume.readFileSync(BASE_RUNTIME_CONTAINER_FILE).toString())
|
|
36
|
+
fs.writeFileSync(tmpProcessRuntimeContainerFilename, ContainerVolume.readFileSync(PROCESS_RUNTIME_CONTAINER_FILE).toString())
|
|
37
|
+
const childProcess: ChildProcess = fork(tmpProcessRuntimeContainerFilename, [
|
|
38
|
+
tmpBaseRuntimeContainerFilename,
|
|
39
|
+
require.resolve(path.resolve(__dirname, './bridges/ProcessBridge'))
|
|
40
|
+
], {
|
|
41
|
+
execArgv: GenerateExecArgv(classPath)
|
|
42
|
+
})
|
|
43
|
+
UniParentBridgeHandler(new ProcessBridge(childProcess), className, classPath, processClassConstructor, callback)
|
|
44
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import 'reflect-metadata'
|
|
2
|
+
import {ThreadClassConstructor} from '../definitions/interfaces/ThreadClassConstructor'
|
|
3
|
+
import {ThreadClass} from './cores/ThreadClass'
|
|
4
|
+
import {Worker} from 'worker_threads'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
import {ThreadBridge} from './bridges/ThreadBridge'
|
|
7
|
+
import {GenerateExecArgv} from './cores/GenerateExecArgv'
|
|
8
|
+
import {UniParentBridgeHandler} from './cores/UniParentBridgeHandler'
|
|
9
|
+
import {ProxyClass} from '../definitions/interfaces/ProxyClass'
|
|
10
|
+
import os from 'os'
|
|
11
|
+
import fs from 'fs'
|
|
12
|
+
import {
|
|
13
|
+
BASE_RUNTIME_CONTAINER_FILE,
|
|
14
|
+
ContainerVolume,
|
|
15
|
+
THREAD_RUNTIME_CONTAINER_FILE
|
|
16
|
+
} from '../containers/ContainerVolume'
|
|
17
|
+
import {Process} from './Process'
|
|
18
|
+
import {isElectron} from './cores/IsElectron'
|
|
19
|
+
|
|
20
|
+
export async function Thread<T extends ThreadClass>(threadClassConstructor: ThreadClassConstructor<T>): Promise<T & ProxyClass> {
|
|
21
|
+
if (isElectron()) {
|
|
22
|
+
return await Process(threadClassConstructor as any) as any
|
|
23
|
+
} else {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
ThreadProxy(threadClassConstructor, (setupError, instance) => {
|
|
26
|
+
if (setupError) {
|
|
27
|
+
reject(setupError)
|
|
28
|
+
} else {
|
|
29
|
+
resolve(<T & ProxyClass>instance)
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function ThreadProxy<T extends ThreadClass>(threadClassConstructor: ThreadClassConstructor<T>, callback: (setupError: Error, instance: T) => void) {
|
|
37
|
+
const className: string = threadClassConstructor.CLASS_NAME
|
|
38
|
+
const classPath: string = threadClassConstructor.CLASS_PATH
|
|
39
|
+
const tmpBaseRuntimeContainerFilename: string = path.resolve(os.tmpdir(), `./TBRC_TMP_${Date.now()}.tmp`)
|
|
40
|
+
fs.writeFileSync(tmpBaseRuntimeContainerFilename, ContainerVolume.readFileSync(BASE_RUNTIME_CONTAINER_FILE).toString())
|
|
41
|
+
const exeArgv = GenerateExecArgv(classPath).reverse()
|
|
42
|
+
const worker: Worker = new Worker(ContainerVolume.readFileSync(THREAD_RUNTIME_CONTAINER_FILE).toString(), {
|
|
43
|
+
eval: true,
|
|
44
|
+
argv: [
|
|
45
|
+
exeArgv.length > 0 ? exeArgv[0] : 'undefined',
|
|
46
|
+
tmpBaseRuntimeContainerFilename,
|
|
47
|
+
require.resolve(path.resolve(__dirname, './bridges/ThreadBridge'))
|
|
48
|
+
]
|
|
49
|
+
})
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
UniParentBridgeHandler(new ThreadBridge(worker), className, classPath, threadClassConstructor, callback)
|
|
52
|
+
}
|