@lakutata/core 1.0.25 → 1.0.29
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/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 +1 -1
- package/build/plugins/Logger.js.map +1 -1
- package/package.json +12 -11
- package/src/Application.ts +29 -0
- package/src/ApplicationManagement.ts +3 -0
- 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 +1 -1
- package/src/tests/Main.spec.ts +6 -2
- package/src/tests/threads/TestThread.ts +3 -1
- package/.idea/dbnavigator.xml +0 -558
|
@@ -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/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
|
@@ -27,7 +27,7 @@ export class Logger extends Plugin {
|
|
|
27
27
|
protected readonly console: ConsoleTransportOptions = {
|
|
28
28
|
silent: false,
|
|
29
29
|
format: format.combine(
|
|
30
|
-
format.timestamp(
|
|
30
|
+
format.timestamp(),
|
|
31
31
|
format.colorize(),
|
|
32
32
|
format.printf(packet => {
|
|
33
33
|
return `${packet.timestamp} ${packet.level}: ${packet.message}`
|
package/src/tests/Main.spec.ts
CHANGED
|
@@ -29,6 +29,7 @@ import {TestException} from './exceptions/TestException'
|
|
|
29
29
|
const config: IApplicationConfig = {
|
|
30
30
|
id: 'test.app',
|
|
31
31
|
name: 'test app',
|
|
32
|
+
timezone: 'US/Alpine',
|
|
32
33
|
processes: [TestProcess],
|
|
33
34
|
threads: [TestThread],
|
|
34
35
|
plugins: [
|
|
@@ -38,7 +39,7 @@ import {TestException} from './exceptions/TestException'
|
|
|
38
39
|
},
|
|
39
40
|
{
|
|
40
41
|
class: Formatter,
|
|
41
|
-
dateFormat: 'YYYY'
|
|
42
|
+
dateFormat: 'YYYY-MM-DD HH:mm:ss'
|
|
42
43
|
},
|
|
43
44
|
{
|
|
44
45
|
class: Logger,
|
|
@@ -147,7 +148,10 @@ import {TestException} from './exceptions/TestException'
|
|
|
147
148
|
app.Logger.debug('this is debug')
|
|
148
149
|
// new TestThread()
|
|
149
150
|
const tt = app.Threads.get(TestThread)
|
|
150
|
-
await tt.test()
|
|
151
|
+
const threadResult = await tt.test('a', 'b', 'c', (timestamp: number) => {
|
|
152
|
+
console.log('fn', timestamp)
|
|
153
|
+
})
|
|
154
|
+
console.log('==========> threadResult:', threadResult)
|
|
151
155
|
await app.Threads.destroy(TestThread)
|
|
152
156
|
const tp = app.Processes.get(TestProcess)
|
|
153
157
|
await tp.procTest()
|
|
@@ -5,7 +5,9 @@ export class TestThread extends Thread {
|
|
|
5
5
|
console.log('this is test thread')
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
public async test() {
|
|
8
|
+
public async test(a, b, c, callback) {
|
|
9
9
|
console.log('this is thread test function')
|
|
10
|
+
callback(Date.now())
|
|
11
|
+
return a + b + c + 'sfsdfasdfasdfasdfasdfasdf'
|
|
10
12
|
}
|
|
11
13
|
}
|