@lakutata/core 1.0.28 → 1.0.32
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/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/minified/ShellJs.d.ts +2 -0
- package/build/lib/minified/ShellJs.js +3699 -0
- package/build/lib/minified/ShellJs.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 +6 -5
- 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 +1 -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/decorators/MethodValidation.ts +6 -6
- package/src/interfaces/IApplicationConfig.ts +1 -0
- package/src/interfaces/ShellJsInterfaces.ts +858 -0
- package/src/lib/minified/ShellJs.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
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {EventEmitter} from 'events'
|
|
2
|
+
import random from 'random'
|
|
3
|
+
import {INVOKE, PROPERTY_CHANGE, READY, SET_PROPERTY, SETUP_ERROR} from '../../constants/Channel'
|
|
4
|
+
|
|
5
|
+
export class BaseBridge {
|
|
6
|
+
protected readonly eventEmitter: EventEmitter = new EventEmitter()
|
|
7
|
+
protected readonly bridge: any
|
|
8
|
+
|
|
9
|
+
constructor(bridgeObject: any) {
|
|
10
|
+
this.bridge = bridgeObject
|
|
11
|
+
this.bridge.on('message', data => {
|
|
12
|
+
this.eventEmitter.emit.apply(this.eventEmitter, [data.channel].concat(data.args) as any)
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public off(channel: string) {
|
|
17
|
+
this.eventEmitter.removeAllListeners(channel)
|
|
18
|
+
return this
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public on(channel: string, listener: (...args: any[]) => void) {
|
|
22
|
+
this.eventEmitter.on.apply(this.eventEmitter, [channel, listener])
|
|
23
|
+
return this
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public once(channel: string, listener: (...args: any[]) => void) {
|
|
27
|
+
this.eventEmitter.once.apply(this.eventEmitter, [channel, listener])
|
|
28
|
+
return this
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public send(channel: string, ...args: any[]) {
|
|
32
|
+
throw new Error('Method did not implemented')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public ready(properties: { [key: string]: any }, propertyValues: { [key: string]: any }) {
|
|
36
|
+
this.send(READY, properties, propertyValues)
|
|
37
|
+
return this
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public onReady(callback: (properties: { [key: string]: any }, propertyValues: { [key: string]: any }) => void) {
|
|
41
|
+
this.once(READY, callback)
|
|
42
|
+
return this
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public error(error: Error) {
|
|
46
|
+
this.send('error', error.message)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public setupError(error: Error) {
|
|
50
|
+
this.send(SETUP_ERROR, error.message)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public async invoke(method: string, args: Array<any>) {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
const invokeId: string = `ts_${Date.now()}_rnd_${random.int(100, 999999)}`
|
|
56
|
+
const responseChannelName: string = `__%$invoke_res_${invokeId}$%__`
|
|
57
|
+
this.once(responseChannelName, (errMsg: string, result: any) => {
|
|
58
|
+
if (errMsg) {
|
|
59
|
+
reject(new Error(errMsg))
|
|
60
|
+
} else {
|
|
61
|
+
resolve(result)
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
this.send(INVOKE, method, args, responseChannelName)
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public onInvoke(handler: (method: string, args: Array<any>) => Promise<any>): void {
|
|
69
|
+
this.on(INVOKE, (method: string, args: Array<any>, responseChannelName: string) => {
|
|
70
|
+
handler(method, args).then(result => {
|
|
71
|
+
this.send(responseChannelName, null, result)
|
|
72
|
+
}).catch(invokeError => {
|
|
73
|
+
this.send(responseChannelName, invokeError.message, undefined)
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public set(property: string, value: any) {
|
|
79
|
+
this.send(SET_PROPERTY, property, value)
|
|
80
|
+
return this
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public onSet(handler: (property: string, value: any) => void) {
|
|
84
|
+
this.on(SET_PROPERTY, handler)
|
|
85
|
+
return this
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public propertyChange(property: string, value: any) {
|
|
89
|
+
this.send(PROPERTY_CHANGE, property, value)
|
|
90
|
+
this.send('property-changed', property, value)
|
|
91
|
+
return this
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public onPropertyChanged(handler: (property: string, value: any) => void) {
|
|
95
|
+
this.on(PROPERTY_CHANGE, handler)
|
|
96
|
+
return this
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public callbackHandler(thisArg: any, handler: (...args: any[]) => any): string {
|
|
100
|
+
const callbackEvtName: string = `__________%$CALLBACK[${Date.now()}]$%__________`
|
|
101
|
+
this.once(callbackEvtName, (...args: any[]) => {
|
|
102
|
+
handler.apply(thisArg, args)
|
|
103
|
+
})
|
|
104
|
+
return callbackEvtName
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public onCallback(callbackEvtName: string, args: any[]) {
|
|
108
|
+
this.send.apply(this, [callbackEvtName].concat(args) as any)
|
|
109
|
+
return this
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public async terminate(): Promise<void> {
|
|
113
|
+
throw new Error('Method did not implemented')
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {BaseBridge} from './BaseBridge'
|
|
2
|
+
|
|
3
|
+
export class ProcessBridge extends BaseBridge {
|
|
4
|
+
|
|
5
|
+
public send(channel: string, ...args: any[]) {
|
|
6
|
+
this.bridge.send({
|
|
7
|
+
channel: channel,
|
|
8
|
+
args: args
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public async terminate(): Promise<void> {
|
|
13
|
+
return new Promise(resolve => {
|
|
14
|
+
this.bridge.once('close', resolve)
|
|
15
|
+
this.bridge.kill()
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {BaseBridge} from './BaseBridge'
|
|
2
|
+
|
|
3
|
+
export class ThreadBridge extends BaseBridge {
|
|
4
|
+
|
|
5
|
+
public send(channel: string, ...args: any[]) {
|
|
6
|
+
this.bridge.postMessage({
|
|
7
|
+
channel: channel,
|
|
8
|
+
args: args
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public async terminate(): Promise<void> {
|
|
13
|
+
await this.bridge.terminate()
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import 'reflect-metadata'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
|
|
4
|
+
export function GenerateExecArgv(modulePath: string): Array<string> {
|
|
5
|
+
const moduleExtName: string = path.extname(modulePath).toUpperCase()
|
|
6
|
+
switch (moduleExtName) {
|
|
7
|
+
case '.TS': {
|
|
8
|
+
require('ts-node')
|
|
9
|
+
const registerRegEx = /ts-node\/register/
|
|
10
|
+
const CMs = require('module')._cache
|
|
11
|
+
for (const cmPath of Object.keys(CMs)) {
|
|
12
|
+
if (registerRegEx.test(cmPath)) {
|
|
13
|
+
return [
|
|
14
|
+
'-r',
|
|
15
|
+
cmPath
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return []
|
|
20
|
+
}
|
|
21
|
+
case '.JS': {
|
|
22
|
+
return []
|
|
23
|
+
}
|
|
24
|
+
default: {
|
|
25
|
+
throw new Error('Invalid module type')
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {BaseBridge} from '../bridges/BaseBridge'
|
|
2
|
+
import {SETUP_ERROR} from '../../constants/Channel'
|
|
3
|
+
|
|
4
|
+
export function UniParentBridgeHandler<T>(bridge: BaseBridge, className: string, classPath: string, classConstructor: any, callback: (setupError: Error, proxyInstance: T) => void): void {
|
|
5
|
+
const reservedMethodNames: Array<string> = ['off', 'on', 'once', 'emit', 'terminate']
|
|
6
|
+
bridge.on(SETUP_ERROR, (setupErrorMsg => {
|
|
7
|
+
callback(new Error(setupErrorMsg), null as any)
|
|
8
|
+
})).onReady((properties: { [key: string]: any }, propertyValues: { [key: string]: any }) => {
|
|
9
|
+
bridge.onPropertyChanged((property, value) => {
|
|
10
|
+
propertyValues[property] = value
|
|
11
|
+
})
|
|
12
|
+
const proxyHandler: any = new Proxy({}, {
|
|
13
|
+
get(target: T, p: PropertyKey): any {
|
|
14
|
+
if (reservedMethodNames.indexOf(p.toString()) > -1) {
|
|
15
|
+
switch (p.toString()) {
|
|
16
|
+
case 'off': {
|
|
17
|
+
return new Proxy((...args: any[]) => {
|
|
18
|
+
}, {
|
|
19
|
+
apply(applyTarget: (...args: any[]) => void, thisArg: any, argArray?: any): any {
|
|
20
|
+
bridge.off.apply(bridge, argArray)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
case 'on': {
|
|
25
|
+
return new Proxy((...args: any[]) => {
|
|
26
|
+
}, {
|
|
27
|
+
apply(applyTarget: (...args: any[]) => void, thisArg: any, argArray?: any): any {
|
|
28
|
+
bridge.on.apply(bridge, argArray)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
case 'once': {
|
|
33
|
+
return new Proxy((...args: any[]) => {
|
|
34
|
+
}, {
|
|
35
|
+
apply(applyTarget: (...args: any[]) => void, thisArg: any, argArray?: any): any {
|
|
36
|
+
bridge.once.apply(bridge, argArray)
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
case 'emit': {
|
|
41
|
+
return new Proxy((...args: any[]) => {
|
|
42
|
+
}, {
|
|
43
|
+
apply(applyTarget: (...args: any[]) => void, thisArg: any, argArray?: any): any {
|
|
44
|
+
bridge.send.apply(bridge, argArray)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
case 'terminate': {
|
|
49
|
+
return new Proxy((...args: any[]) => {
|
|
50
|
+
}, {
|
|
51
|
+
apply(applyTarget: (...args: any[]) => void, thisArg: any, argArray?: any): any {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
bridge.terminate().then(resolve).catch(reject)
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
default:
|
|
59
|
+
return undefined
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
const method = classConstructor.prototype[p]
|
|
63
|
+
const isPropertyMethod: boolean = properties[p.toString()] === 'function'
|
|
64
|
+
if (method || isPropertyMethod) {
|
|
65
|
+
return new Proxy(isPropertyMethod ? (...args: any[]) => {
|
|
66
|
+
} : method, {
|
|
67
|
+
apply(target, thisArg: any, argArray?: any): any {
|
|
68
|
+
const _argArray: any[] = []
|
|
69
|
+
for (const _arg of argArray) {
|
|
70
|
+
if (typeof _arg !== 'function') {
|
|
71
|
+
_argArray.push(_arg)
|
|
72
|
+
} else {
|
|
73
|
+
_argArray.push(bridge.callbackHandler(thisArg, _arg))
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
bridge.invoke(p.toString(), _argArray).then(resolve).catch(reject)
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
} else if (properties[p.toString()]) {
|
|
82
|
+
return propertyValues[p.toString()]
|
|
83
|
+
} else {
|
|
84
|
+
return undefined
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
set(target: {}, p: PropertyKey, value: any, receiver: any): boolean {
|
|
89
|
+
bridge.set(p.toString(), value)
|
|
90
|
+
return true
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
bridge.off(SETUP_ERROR)
|
|
94
|
+
callback(null as any, proxyHandler)
|
|
95
|
+
})
|
|
96
|
+
bridge.send('create', className, classPath)
|
|
97
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import 'reflect-metadata'
|
|
2
|
+
import {BaseBridge} from '../bridges/BaseBridge'
|
|
3
|
+
import {MULTIPLE_RUNNER_CLASS_NAME, MULTIPLE_RUNNER__CLASS_PATH} from '../../constants/MetadataKey'
|
|
4
|
+
|
|
5
|
+
export class MultipleRunnerBaseClass {
|
|
6
|
+
private readonly __bridge__: BaseBridge
|
|
7
|
+
|
|
8
|
+
public static get CLASS_PATH(): string {
|
|
9
|
+
if (!Reflect.getMetadata(MULTIPLE_RUNNER__CLASS_PATH, this)) {
|
|
10
|
+
const cachedModules = require('module')._cache
|
|
11
|
+
for (const modulePath of Object.keys(cachedModules)) {
|
|
12
|
+
const cachedModule = cachedModules[modulePath]
|
|
13
|
+
if (typeof cachedModule === 'object') {
|
|
14
|
+
const exports = cachedModule.exports
|
|
15
|
+
if (exports && typeof exports === 'object') {
|
|
16
|
+
for (const exportName of Object.keys(exports)) {
|
|
17
|
+
if (typeof exports[exportName] === 'function') {
|
|
18
|
+
if (exports[exportName] === this) {
|
|
19
|
+
Reflect.defineMetadata(MULTIPLE_RUNNER__CLASS_PATH, modulePath, this)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return Reflect.getMetadata(MULTIPLE_RUNNER__CLASS_PATH, this)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public static get CLASS_NAME(): string {
|
|
31
|
+
if (!Reflect.getMetadata(MULTIPLE_RUNNER_CLASS_NAME, this)) {
|
|
32
|
+
Reflect.defineMetadata(MULTIPLE_RUNNER_CLASS_NAME, this.name, this)
|
|
33
|
+
}
|
|
34
|
+
return Reflect.getMetadata(MULTIPLE_RUNNER_CLASS_NAME, this)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
constructor(bridge: BaseBridge) {
|
|
38
|
+
this.__bridge__ = bridge
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected async setup(): Promise<void> {
|
|
42
|
+
//Empty setup method
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public off(event: string): void {
|
|
46
|
+
this.__bridge__.off(event)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public on(event: 'property-changed', handler: (property: string, value: any) => void): void
|
|
50
|
+
public on(event: 'error', handler: (error: Error) => void): void
|
|
51
|
+
public on(event: string, handler: (...args: any[]) => void): void
|
|
52
|
+
public on(event: string, handler: (...args: any[]) => void): void {
|
|
53
|
+
this.__bridge__.on(event, handler)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public once(event: 'property-changed', handler: (property: string, value: any) => void): void
|
|
57
|
+
public once(event: 'error', handler: (error: Error) => void): void
|
|
58
|
+
public once(event: string, handler: (...args: any[]) => void): void
|
|
59
|
+
public once(event: string, handler: (...args: any[]) => void): void {
|
|
60
|
+
this.__bridge__.once(event, handler)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public emit(event: string, ...args: any[]): void {
|
|
64
|
+
this.__bridge__.send.apply(this.__bridge__, [event].concat(args) as any)
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/plugins/Crypto.ts
CHANGED
|
@@ -118,12 +118,12 @@ export class Crypto extends Plugin {
|
|
|
118
118
|
try {
|
|
119
119
|
if (key.isPrivate() && !decryptResult) decryptResult = key.decrypt(bufferData).toString()
|
|
120
120
|
} catch (e) {
|
|
121
|
-
decryptException = new CryptoException(e.message)
|
|
121
|
+
decryptException = new CryptoException((e as Error).message)
|
|
122
122
|
}
|
|
123
123
|
try {
|
|
124
124
|
if (key.isPublic() && !decryptResult) decryptResult = key.decryptPublic(bufferData).toString()
|
|
125
125
|
} catch (e) {
|
|
126
|
-
decryptException = new CryptoException(e.message)
|
|
126
|
+
decryptException = new CryptoException((e as Error).message)
|
|
127
127
|
}
|
|
128
128
|
if (decryptResult) {
|
|
129
129
|
return decryptResult
|
|
@@ -137,4 +137,4 @@ export class Crypto extends Plugin {
|
|
|
137
137
|
return decryptedData
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
}
|
|
140
|
+
}
|
package/src/plugins/Formatter.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Plugin} from '../base/Plugin'
|
|
2
|
-
import
|
|
2
|
+
import momentTimezone from 'moment-timezone'
|
|
3
3
|
import {Configurable} from '../decorators/DependencyInjection'
|
|
4
4
|
|
|
5
5
|
declare module '../Core' {
|
|
@@ -9,6 +9,11 @@ declare module '../Core' {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export class Formatter extends Plugin {
|
|
12
|
+
|
|
13
|
+
protected get timezone(): string {
|
|
14
|
+
return <string>process.env.TZ
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* 默认时间格式
|
|
14
19
|
* @type {string}
|
|
@@ -23,7 +28,7 @@ export class Formatter extends Plugin {
|
|
|
23
28
|
* @returns {number}
|
|
24
29
|
*/
|
|
25
30
|
public asTimestamp(inp: string | number | Date = new Date()): number {
|
|
26
|
-
return
|
|
31
|
+
return momentTimezone.tz(inp, this.timezone).unix()
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
/**
|
|
@@ -32,7 +37,7 @@ export class Formatter extends Plugin {
|
|
|
32
37
|
* @returns {number}
|
|
33
38
|
*/
|
|
34
39
|
public asMillisecondTimestamp(inp: string | number | Date = new Date()): number {
|
|
35
|
-
return
|
|
40
|
+
return momentTimezone.tz(inp, this.timezone).valueOf()
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
/**
|
|
@@ -41,7 +46,7 @@ export class Formatter extends Plugin {
|
|
|
41
46
|
* @returns {Date}
|
|
42
47
|
*/
|
|
43
48
|
public asDate(inp: string | number | Date): Date {
|
|
44
|
-
return
|
|
49
|
+
return momentTimezone.tz(inp, this.timezone).toDate()
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
/**
|
|
@@ -51,7 +56,7 @@ export class Formatter extends Plugin {
|
|
|
51
56
|
* @returns {string}
|
|
52
57
|
*/
|
|
53
58
|
public asDateText(inp: Date | string | number = new Date(), format?: string): string {
|
|
54
|
-
return
|
|
59
|
+
return momentTimezone.tz(inp, this.timezone).format(format ? format : this.dateFormat)
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
/**
|
package/src/plugins/Logger.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {Plugin} from '../base/Plugin'
|
|
2
|
-
import {createLogger, Logger as WinstonLogger, transports
|
|
2
|
+
import {createLogger, Logger as WinstonLogger, transports} from 'winston'
|
|
3
3
|
import {Configurable} from '../decorators/DependencyInjection'
|
|
4
4
|
import * as Transport from 'winston-transport'
|
|
5
5
|
import {format as utilFormat} from 'util'
|
|
6
6
|
import {ConsoleTransportOptions} from 'winston/lib/winston/transports'
|
|
7
|
+
import momentTimezone from 'moment-timezone'
|
|
8
|
+
import {TimestampOptions, format} from 'logform'
|
|
7
9
|
|
|
8
10
|
declare module '../Core' {
|
|
9
11
|
interface Application {
|
|
@@ -27,7 +29,11 @@ export class Logger extends Plugin {
|
|
|
27
29
|
protected readonly console: ConsoleTransportOptions = {
|
|
28
30
|
silent: false,
|
|
29
31
|
format: format.combine(
|
|
30
|
-
format.timestamp({
|
|
32
|
+
format.timestamp({
|
|
33
|
+
format: () => {
|
|
34
|
+
return momentTimezone.tz(Date.now(), <string>process.env.TZ).format('YYYY-MM-DD HH:mm:ss')
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
31
37
|
format.colorize(),
|
|
32
38
|
format.printf(packet => {
|
|
33
39
|
return `${packet.timestamp} ${packet.level}: ${packet.message}`
|