@lakutata/core 1.0.27 → 1.0.31
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 +4 -0
- package/build/Application.js +20 -7
- package/build/Application.js.map +1 -1
- package/build/ApplicationManagement.js +5 -0
- package/build/ApplicationManagement.js.map +1 -1
- package/build/base/BaseObject.js +1 -1
- package/build/base/BaseObject.js.map +1 -1
- package/build/base/Container.js +16 -0
- package/build/base/Container.js.map +1 -1
- package/build/base/ValidatorClass.d.ts +1 -0
- package/build/base/ValidatorClass.js +70 -53
- package/build/base/ValidatorClass.js.map +1 -1
- package/build/base/abstracts/Exception.js +5 -2
- package/build/base/abstracts/Exception.js.map +1 -1
- package/build/base/abstracts/Module.js +8 -8
- package/build/base/abstracts/Module.js.map +1 -1
- package/build/base/abstracts/Workflow.js +1 -1
- package/build/base/abstracts/Workflow.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/decorators/MethodValidation.js.map +1 -1
- package/build/interfaces/IApplicationConfig.d.ts +1 -0
- package/build/interfaces/ShellJsInterfaces.d.ts +162 -0
- package/build/interfaces/ShellJsInterfaces.js +3 -0
- package/build/interfaces/ShellJsInterfaces.js.map +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/Crypto.js +2 -2
- package/build/plugins/Crypto.js.map +1 -1
- package/build/plugins/Formatter.d.ts +1 -0
- package/build/plugins/Formatter.js +9 -6
- package/build/plugins/Formatter.js.map +1 -1
- package/build/plugins/HttpRequest.js +8 -8
- package/build/plugins/HttpRequest.js.map +1 -1
- package/build/plugins/Logger.js +15 -6
- package/build/plugins/Logger.js.map +1 -1
- package/build/plugins/MessagePack.js +2 -2
- package/build/plugins/MessagePack.js.map +1 -1
- package/build/plugins/Security.js +24 -24
- package/build/plugins/Security.js.map +1 -1
- package/build/plugins/Shell.d.ts +39 -0
- package/build/plugins/Shell.js +58 -0
- package/build/plugins/Shell.js.map +1 -0
- package/build/types/TPluginsConfig.d.ts +1 -0
- package/build/utils/Delay.js +1 -1
- package/build/utils/Delay.js.map +1 -1
- package/build/utils/Timeout.js +1 -1
- package/build/utils/Timeout.js.map +1 -1
- package/build/utils/ValidDataUrl.d.ts +1 -0
- package/build/utils/ValidDataUrl.js +8 -0
- package/build/utils/ValidDataUrl.js.map +1 -0
- package/package.json +14 -14
- package/src/Application.ts +33 -11
- package/src/ApplicationManagement.ts +4 -1
- package/src/base/Container.ts +14 -1
- package/src/base/ValidatorClass.ts +44 -7
- package/src/base/abstracts/Exception.ts +2 -2
- 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/decorators/MethodValidation.ts +6 -6
- package/src/interfaces/IApplicationConfig.ts +1 -0
- package/src/interfaces/ShellJsInterfaces.ts +858 -0
- package/src/lib/minified/ShellJs.min.js +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/Crypto.ts +3 -3
- package/src/plugins/Formatter.ts +10 -5
- package/src/plugins/Logger.ts +8 -2
- package/src/plugins/Shell.ts +371 -0
- package/src/tests/Main.spec.ts +11 -6
- package/src/tests/threads/TestThread.ts +3 -1
- package/src/types/TPluginsConfig.ts +1 -1
- package/src/utils/ValidDataUrl.ts +8 -0
- package/.idea/dbnavigator.xml +0 -558
package/build/utils/Delay.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Delay.js","sourceRoot":"","sources":["../../src/utils/Delay.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AAO1B,KAAK,UAAU,KAAK,CAAC,YAAoB;IAC/C,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC5B,mBAAU,
|
|
1
|
+
{"version":3,"file":"Delay.js","sourceRoot":"","sources":["../../src/utils/Delay.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AAO1B,KAAK,UAAU,KAAK,CAAC,YAAoB;IAC/C,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC5B,IAAA,mBAAU,EAAC,GAAG,EAAE;YACf,OAAO,EAAE,CAAA;QACV,CAAC,EAAE,YAAY,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;AACH,CAAC;AAND,sBAMC"}
|
package/build/utils/Timeout.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.timeout = void 0;
|
|
|
7
7
|
const p_timeout_1 = __importDefault(require("p-timeout"));
|
|
8
8
|
const TimeoutException_1 = require("../exceptions/TimeoutException");
|
|
9
9
|
async function timeout(p, milliseconds, messageOrFallback) {
|
|
10
|
-
return p_timeout_1.default(p, milliseconds, async () => {
|
|
10
|
+
return (0, p_timeout_1.default)(p, milliseconds, async () => {
|
|
11
11
|
if (messageOrFallback) {
|
|
12
12
|
switch (typeof messageOrFallback) {
|
|
13
13
|
case 'function':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Timeout.js","sourceRoot":"","sources":["../../src/utils/Timeout.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAgC;AAEhC,qEAA+D;AASxD,KAAK,UAAU,OAAO,CAAI,CAAa,EAAE,YAAoB,EAAE,iBAA+D;IACpI,OAAO,mBAAQ,
|
|
1
|
+
{"version":3,"file":"Timeout.js","sourceRoot":"","sources":["../../src/utils/Timeout.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAgC;AAEhC,qEAA+D;AASxD,KAAK,UAAU,OAAO,CAAI,CAAa,EAAE,YAAoB,EAAE,iBAA+D;IACpI,OAAO,IAAA,mBAAQ,EAAC,CAAC,EAAE,YAAY,EAAE,KAAK,IAAI,EAAE;QAC3C,IAAI,iBAAiB,EAAE;YACtB,QAAQ,OAAO,iBAAiB,EAAE;gBACjC,KAAK,UAAU;oBACd,OAAO,CAAC,MAAM,iBAAiB,EAAE,CAAQ,CAAA;gBAC1C,KAAK,QAAQ;oBACZ,MAAM,IAAI,mCAAgB,CAAC,iBAAiB,CAAC,CAAA;gBAC9C,KAAK,QAAQ;oBACZ,MAAM,iBAAiB,CAAA;aACxB;SACD;aAAM;YACN,MAAM,IAAI,mCAAgB,CAAC,2BAA2B,YAAY,eAAe,CAAC,CAAA;SAClF;IACF,CAAC,CAAC,CAAA;AACH,CAAC;AAfD,0BAeC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validDataUrl(candidate: string): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validDataUrl = void 0;
|
|
4
|
+
function validDataUrl(candidate) {
|
|
5
|
+
return /^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(candidate);
|
|
6
|
+
}
|
|
7
|
+
exports.validDataUrl = validDataUrl;
|
|
8
|
+
//# sourceMappingURL=ValidDataUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidDataUrl.js","sourceRoot":"","sources":["../../src/utils/ValidDataUrl.ts"],"names":[],"mappings":";;;AAKA,SAAgB,YAAY,CAAC,SAAiB;IAC7C,OAAO,uIAAuI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;AAC/J,CAAC;AAFD,oCAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakutata/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.31",
|
|
4
4
|
"description": "Lakutata Framework Core",
|
|
5
5
|
"main": "./build/Core.js",
|
|
6
6
|
"types": "./build/Core.d.ts",
|
|
@@ -53,41 +53,41 @@
|
|
|
53
53
|
"author": "alex.ma",
|
|
54
54
|
"license": "MIT",
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@thiagodelgado111/yup-phone": "^0.0.2",
|
|
57
|
-
"@types/lodash.mapvalues": "^4.6.6",
|
|
58
56
|
"bcryptjs": "^2.4.3",
|
|
59
|
-
"crypto-js": "^4.
|
|
60
|
-
"
|
|
57
|
+
"crypto-js": "^4.1.1",
|
|
58
|
+
"google-libphonenumber": "^3.2.25",
|
|
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
|
-
"pupa": "^
|
|
72
|
+
"pupa": "^3.1.0",
|
|
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
|
-
"valid-data-url": "^3.0.1",
|
|
78
76
|
"winston": "^3.3.3",
|
|
79
77
|
"winston-transport": "^4.4.0",
|
|
80
|
-
"yup": "^0.32.
|
|
78
|
+
"yup": "^0.32.11"
|
|
81
79
|
},
|
|
82
80
|
"devDependencies": {
|
|
83
81
|
"@types/bcryptjs": "^2.4.2",
|
|
84
82
|
"@types/chai": "^4.2.14",
|
|
85
|
-
"@types/crypto-js": "^4.0.
|
|
83
|
+
"@types/crypto-js": "^4.0.2",
|
|
84
|
+
"@types/google-libphonenumber": "^7.4.23",
|
|
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
|
@@ -10,9 +10,10 @@ import {MessagePack} from './plugins/MessagePack'
|
|
|
10
10
|
import {JSON} from './plugins/JSON'
|
|
11
11
|
import {TWorkflowsConfig} from './types/TWorkflowsConfig'
|
|
12
12
|
import {Logger} from './plugins/Logger'
|
|
13
|
-
import {format} from 'winston'
|
|
14
13
|
import {TProcessesConfig} from './types/TProcessesConfig'
|
|
15
14
|
import {TThreadsConfig} from './types/TThreadsConfig'
|
|
15
|
+
import momentTimezone from 'moment-timezone'
|
|
16
|
+
import {Shell} from './plugins/Shell'
|
|
16
17
|
|
|
17
18
|
export class Application extends Module {
|
|
18
19
|
/**
|
|
@@ -64,6 +65,9 @@ export class Application extends Module {
|
|
|
64
65
|
{
|
|
65
66
|
class: JSON
|
|
66
67
|
},
|
|
68
|
+
{
|
|
69
|
+
class: Shell
|
|
70
|
+
},
|
|
67
71
|
{
|
|
68
72
|
class: Formatter,
|
|
69
73
|
dateFormat: 'YYYY-MM-DD HH:mm:ss'
|
|
@@ -76,16 +80,6 @@ export class Application extends Module {
|
|
|
76
80
|
appId: process.env.appId,
|
|
77
81
|
appName: process.env.appName
|
|
78
82
|
},
|
|
79
|
-
console: {
|
|
80
|
-
silent: false,
|
|
81
|
-
format: format.combine(
|
|
82
|
-
format.timestamp({format: 'YYYY-MM-DD HH:mm:ss'}),
|
|
83
|
-
format.colorize(),
|
|
84
|
-
format.printf(packet => {
|
|
85
|
-
return `${packet.timestamp} ${packet.level}: ${packet.message}`
|
|
86
|
-
})
|
|
87
|
-
)
|
|
88
|
-
},
|
|
89
83
|
transports: []
|
|
90
84
|
}
|
|
91
85
|
]
|
|
@@ -125,6 +119,18 @@ export class Application extends Module {
|
|
|
125
119
|
*/
|
|
126
120
|
protected readonly workflows: TWorkflowsConfig = []
|
|
127
121
|
|
|
122
|
+
/**
|
|
123
|
+
* 程序时区
|
|
124
|
+
* @type {string}
|
|
125
|
+
* @protected
|
|
126
|
+
*/
|
|
127
|
+
protected tz: string = (() => {
|
|
128
|
+
if (!process.env.TZ) {
|
|
129
|
+
process.env.TZ = momentTimezone.tz.guess()
|
|
130
|
+
}
|
|
131
|
+
return process.env.TZ
|
|
132
|
+
})()
|
|
133
|
+
|
|
128
134
|
/**
|
|
129
135
|
* 初始化
|
|
130
136
|
* @returns {Promise<void>}
|
|
@@ -137,6 +143,22 @@ export class Application extends Module {
|
|
|
137
143
|
})
|
|
138
144
|
}
|
|
139
145
|
|
|
146
|
+
/**
|
|
147
|
+
* 获取程序时区
|
|
148
|
+
* @returns {string}
|
|
149
|
+
*/
|
|
150
|
+
public getTimezone() {
|
|
151
|
+
return this.tz
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 设置程序时区
|
|
156
|
+
* @param {string} tz
|
|
157
|
+
*/
|
|
158
|
+
public setTimezone(tz: string) {
|
|
159
|
+
this.tz = tz
|
|
160
|
+
}
|
|
161
|
+
|
|
140
162
|
/**
|
|
141
163
|
* 获取应用程序ID
|
|
142
164
|
* @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,10 +21,11 @@ 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) {
|
|
25
|
-
throw new FatalException(e.message)
|
|
28
|
+
throw new FatalException((e as Error).message)
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
|
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)
|
|
@@ -25,11 +25,11 @@ import {OptionalArraySchema} from 'yup/lib/array'
|
|
|
25
25
|
import Reference, {ReferenceOptions} from 'yup/lib/Reference'
|
|
26
26
|
import mapValues from 'lodash/mapValues'
|
|
27
27
|
import {ValidationException} from '../exceptions/ValidationException'
|
|
28
|
-
import phoneValidationMethod, {YUP_METHOD as PHONE_METHOD} from '@thiagodelgado111/yup-phone'
|
|
29
28
|
import isSsh from 'is-ssh'
|
|
30
|
-
import validDataUrl from 'valid-data-url'
|
|
31
29
|
import {MixedSchema} from 'yup/lib/mixed'
|
|
32
30
|
import {BaseObject} from './BaseObject'
|
|
31
|
+
import gPhoneNumber from 'google-libphonenumber'
|
|
32
|
+
import {validDataUrl} from '../utils/ValidDataUrl'
|
|
33
33
|
|
|
34
34
|
declare module 'yup' {
|
|
35
35
|
interface StringSchema {
|
|
@@ -44,13 +44,15 @@ declare module 'yup' {
|
|
|
44
44
|
dataUrl(): StringSchema
|
|
45
45
|
|
|
46
46
|
url(option?: { acceptParams?: boolean; protocol?: string[] | string; blackHostnameList?: string[]; whiteHostnameList?: string[] }): StringSchema
|
|
47
|
+
|
|
48
|
+
phone(countryCode?: string, strict?: boolean): StringSchema
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
interface ObjectSchema<TShape extends ObjectShape, TContext extends AnyObject = AnyObject, TIn extends Maybe<TypeOfShape<TShape>> = TypeOfShape<TShape>, TOut extends Maybe<AssertsShape<TShape>> = AssertsShape<TShape> | Optionals<TIn>> extends BaseSchema<TIn, TContext, TOut> {
|
|
50
52
|
structure(valueSchema: AnySchema): OptionalObjectSchema<TShape, Record<string, any>, TypeOfShape<TShape>>
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
const PHONE_METHOD = 'phone'
|
|
54
56
|
const IPV4_METHOD = 'ipv4'
|
|
55
57
|
const IPV6_METHOD = 'ipv6'
|
|
56
58
|
const IP_ALL_METHOD = 'ip'
|
|
@@ -515,7 +517,42 @@ export class ValidatorClass extends BaseObject {
|
|
|
515
517
|
|
|
516
518
|
constructor() {
|
|
517
519
|
super()
|
|
518
|
-
addMethod(string, PHONE_METHOD,
|
|
520
|
+
addMethod(string, PHONE_METHOD, function (this: StringSchema, countryCode?: string, strict: boolean = false) {
|
|
521
|
+
const phoneUtil = gPhoneNumber.PhoneNumberUtil.getInstance()
|
|
522
|
+
const CLDR_REGION_CODE_SIZE = 2
|
|
523
|
+
const isValidCountryCode = (countryCode: any): boolean => typeof countryCode === 'string' && countryCode.length === CLDR_REGION_CODE_SIZE
|
|
524
|
+
const errMsg = isValidCountryCode(countryCode)
|
|
525
|
+
? `\${path} must be a valid phone number for region ${countryCode}`
|
|
526
|
+
: '${path} must be a valid phone number.'
|
|
527
|
+
|
|
528
|
+
return this.test(<any>{
|
|
529
|
+
name: PHONE_METHOD,
|
|
530
|
+
message: errMsg,
|
|
531
|
+
test(value: string) {
|
|
532
|
+
if (this.schema._nullable && value === null) {
|
|
533
|
+
return this.resolve(true)
|
|
534
|
+
}
|
|
535
|
+
if (!isValidCountryCode(countryCode)) {
|
|
536
|
+
countryCode = 'US'
|
|
537
|
+
strict = false
|
|
538
|
+
}
|
|
539
|
+
let isValid
|
|
540
|
+
try {
|
|
541
|
+
const phoneNumber = phoneUtil.parseAndKeepRawInput(value, countryCode)
|
|
542
|
+
if (!phoneUtil.isPossibleNumber(phoneNumber)) {
|
|
543
|
+
return false
|
|
544
|
+
}
|
|
545
|
+
const regionCodeFromPhoneNumber = phoneUtil.getRegionCodeForNumber(phoneNumber)
|
|
546
|
+
isValid = strict
|
|
547
|
+
? phoneUtil.isValidNumberForRegion(phoneNumber, countryCode)
|
|
548
|
+
: phoneUtil.isValidNumberForRegion(phoneNumber, regionCodeFromPhoneNumber)
|
|
549
|
+
} catch (error) {
|
|
550
|
+
isValid = false
|
|
551
|
+
}
|
|
552
|
+
return this.resolve(isValid)
|
|
553
|
+
}
|
|
554
|
+
})
|
|
555
|
+
})
|
|
519
556
|
addMethod(string, IPV4_METHOD, function (this: StringSchema, message = 'Invalid IP address') {
|
|
520
557
|
return this.matches(/(^(\d{1,3}\.){3}(\d{1,3})$)/, {
|
|
521
558
|
message,
|
|
@@ -668,7 +705,7 @@ export class ValidatorClass extends BaseObject {
|
|
|
668
705
|
try {
|
|
669
706
|
return await schema.validate(data, {strict: true})
|
|
670
707
|
} catch (e) {
|
|
671
|
-
throw this.generateException(ValidationException,e.message)
|
|
708
|
+
throw this.generateException(ValidationException, (e as Error).message)
|
|
672
709
|
}
|
|
673
710
|
}
|
|
674
711
|
|
|
@@ -682,7 +719,7 @@ export class ValidatorClass extends BaseObject {
|
|
|
682
719
|
try {
|
|
683
720
|
return schema.validateSync(data, {strict: true})
|
|
684
721
|
} catch (e) {
|
|
685
|
-
throw this.generateException(ValidationException,e.message)
|
|
722
|
+
throw this.generateException(ValidationException, (e as Error).message)
|
|
686
723
|
}
|
|
687
724
|
}
|
|
688
725
|
|
|
@@ -705,4 +742,4 @@ export class ValidatorClass extends BaseObject {
|
|
|
705
742
|
public isValidSync<SchemaType extends AnySchema, DataType = any>(schema: SchemaType, data: DataType): boolean {
|
|
706
743
|
return schema.isValidSync(data, {strict: true})
|
|
707
744
|
}
|
|
708
|
-
}
|
|
745
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import pupa
|
|
1
|
+
import pupa from 'pupa'
|
|
2
2
|
import {format} from 'util'
|
|
3
3
|
|
|
4
4
|
export abstract class Exception extends Error {
|
|
@@ -57,4 +57,4 @@ export abstract class Exception extends Error {
|
|
|
57
57
|
protected templates(): string[] {
|
|
58
58
|
return []
|
|
59
59
|
}
|
|
60
|
-
}
|
|
60
|
+
}
|
|
@@ -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()
|
|
@@ -26,7 +26,7 @@ export const Return = (returnSchema: AnySchema, options: { strict?: boolean, str
|
|
|
26
26
|
const methodResult = returnSchema.validateSync(originalAsyncMethodResult, options)
|
|
27
27
|
resolve(methodResult)
|
|
28
28
|
} catch (e) {
|
|
29
|
-
reject(new InvalidMethodReturnException(e.message))
|
|
29
|
+
reject(new InvalidMethodReturnException((e as Error).message))
|
|
30
30
|
}
|
|
31
31
|
}).catch(reject)
|
|
32
32
|
})
|
|
@@ -35,9 +35,9 @@ export const Return = (returnSchema: AnySchema, options: { strict?: boolean, str
|
|
|
35
35
|
return returnSchema.validateSync(originalMethodResult, options)
|
|
36
36
|
} catch (e) {
|
|
37
37
|
if (target['generateException']) {
|
|
38
|
-
throw target['generateException'](InvalidMethodReturnException, e.message)
|
|
38
|
+
throw target['generateException'](InvalidMethodReturnException, (e as Error).message)
|
|
39
39
|
} else {
|
|
40
|
-
throw new InvalidMethodReturnException(e.message)
|
|
40
|
+
throw new InvalidMethodReturnException((e as Error).message)
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -68,13 +68,13 @@ export const Accept = (argumentSchemas: AnySchema | AnySchema[], options: { stri
|
|
|
68
68
|
}
|
|
69
69
|
} catch (e) {
|
|
70
70
|
if (target['generateException']) {
|
|
71
|
-
throw target['generateException'](InvalidMethodAcceptException, e.message)
|
|
71
|
+
throw target['generateException'](InvalidMethodAcceptException, (e as Error).message)
|
|
72
72
|
} else {
|
|
73
|
-
throw new InvalidMethodAcceptException(e.message)
|
|
73
|
+
throw new InvalidMethodAcceptException((e as Error).message)
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
return originalMethod.apply(this, args)
|
|
77
77
|
}
|
|
78
78
|
return descriptor
|
|
79
79
|
}
|
|
80
|
-
}
|
|
80
|
+
}
|