@zenflux/core 0.1.11 → 0.1.13
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/dist/zenflux-core.cjs +5 -5
- package/dist/zenflux-core.mjs +5 -5
- package/package.json +3 -4
- package/src/bases/controller-base.ts +0 -96
- package/src/bases/index.ts +0 -6
- package/src/bases/initialize-base.ts +0 -32
- package/src/bases/object-base.ts +0 -55
- package/src/clients/http.ts +0 -152
- package/src/command-bases/command-base.ts +0 -82
- package/src/command-bases/command-internal.ts +0 -11
- package/src/command-bases/command-public.ts +0 -12
- package/src/command-bases/command-restful.ts +0 -55
- package/src/command-bases/index.ts +0 -8
- package/src/errors/command-already-registered.ts +0 -13
- package/src/errors/command-not-found.ts +0 -12
- package/src/errors/controller-already-registered.ts +0 -13
- package/src/errors/controller-already-set.ts +0 -13
- package/src/errors/error-with-metadata.ts +0 -14
- package/src/errors/force-method-implementation.ts +0 -15
- package/src/errors/index-public.ts +0 -1
- package/src/errors/index.ts +0 -10
- package/src/exports-index.ts +0 -13
- package/src/exports.ts +0 -58
- package/src/index.ts +0 -18
- package/src/interfaces/commands.ts +0 -17
- package/src/interfaces/config.ts +0 -23
- package/src/interfaces/index.ts +0 -8
- package/src/interfaces/logger.ts +0 -19
- package/src/interfaces/restful.ts +0 -23
- package/src/managers/commands.ts +0 -268
- package/src/managers/controllers.ts +0 -40
- package/src/managers/export.ts +0 -30
- package/src/managers/index.ts +0 -8
- package/src/managers/internal.ts +0 -11
- package/src/managers/restful.ts +0 -117
- package/src/modules/debugger.ts +0 -89
- package/src/modules/event-bus/event-bus.ts +0 -204
- package/src/modules/logger/config.ts +0 -44
- package/src/modules/logger/implementation.ts +0 -287
- package/src/modules/logger/index.ts +0 -2
- package/src/modules/logger/logger-browser-infra.ts +0 -344
- package/src/modules/logger/types/picocolors.d.ts +0 -15
- package/src/modules/logger/utils/index.ts +0 -3
- package/src/modules/logger/utils/object.ts +0 -19
- package/src/modules/logger/utils/rgb.ts +0 -34
- package/src/modules/mcp-server/mcp-server.ts +0 -139
- package/src/modules/mcp-server/mcp-service.ts +0 -80
- package/src/modules/service/service-base.ts +0 -55
- package/src/modules/service/service-locator.ts +0 -205
- package/src/modules/service/service-with-dependencies-base.ts +0 -51
package/src/managers/export.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Leonid Vinikov <leonidvinikov@gmail.com>
|
|
3
|
-
*/
|
|
4
|
-
import { Commands } from "./commands";
|
|
5
|
-
import { Controllers } from "./controllers";
|
|
6
|
-
import { Restful } from "./restful";
|
|
7
|
-
import { Internal } from "./internal";
|
|
8
|
-
|
|
9
|
-
import type { IAPIConfig } from "../interfaces";
|
|
10
|
-
|
|
11
|
-
export const afterInitializeCallbacks: ( () => void )[] = [];
|
|
12
|
-
|
|
13
|
-
export function initialize( config: IAPIConfig ) {
|
|
14
|
-
commands = new Commands();
|
|
15
|
-
controllers = new Controllers();
|
|
16
|
-
restful = new Restful( config );
|
|
17
|
-
internal = new Internal();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function destroy() {
|
|
21
|
-
commands = {} as Commands;
|
|
22
|
-
controllers = {} as Controllers;
|
|
23
|
-
restful = {} as Restful;
|
|
24
|
-
internal = {} as Internal;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export let commands = {} as Commands;
|
|
28
|
-
export let controllers = {} as Controllers;
|
|
29
|
-
export let restful = {} as Restful;
|
|
30
|
-
export let internal = {} as Internal;
|
package/src/managers/index.ts
DELETED
package/src/managers/internal.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Leonid Vinikov <leonidvinikov@gmail.com>
|
|
3
|
-
* @description Responsible for manging internal commands, To serve commands that are not triggered by user.
|
|
4
|
-
*/
|
|
5
|
-
import { Commands } from "./commands";
|
|
6
|
-
|
|
7
|
-
export class Internal extends Commands {
|
|
8
|
-
public static getName() {
|
|
9
|
-
return "ZenFlux/Core/Managers/Internal";
|
|
10
|
-
}
|
|
11
|
-
}
|
package/src/managers/restful.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Leonid Vinikov <leonidvinikov@gmail.com>
|
|
3
|
-
* @description Responsible for manging restful commands which are wrappers for HTTP requests.
|
|
4
|
-
*/
|
|
5
|
-
import { Commands } from "./commands";
|
|
6
|
-
|
|
7
|
-
import { Http } from "../clients/http";
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
E_RESPONSE_HANDLER_TYPE,
|
|
11
|
-
E_HTTP_METHOD_TYPE
|
|
12
|
-
} from "../interfaces";
|
|
13
|
-
|
|
14
|
-
import type { CommandRestful } from "../command-bases";
|
|
15
|
-
|
|
16
|
-
import type {
|
|
17
|
-
IAPIConfig,
|
|
18
|
-
ICommandArgsInterface,
|
|
19
|
-
ICommandOptionsInterface,
|
|
20
|
-
|
|
21
|
-
TErrorHandlerCallbackType,
|
|
22
|
-
TPossibleHandlersType,
|
|
23
|
-
TResponseFilterCallbackType,
|
|
24
|
-
TResponseHandlerCallbackType
|
|
25
|
-
} from "../interfaces";
|
|
26
|
-
|
|
27
|
-
export class Restful extends Commands {
|
|
28
|
-
private static client: Http;
|
|
29
|
-
|
|
30
|
-
public currentHttpMethod: E_HTTP_METHOD_TYPE;
|
|
31
|
-
|
|
32
|
-
public static getName() {
|
|
33
|
-
return "ZenFlux/Core/Managers/Restful";
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public constructor( Config: IAPIConfig ) {
|
|
37
|
-
super();
|
|
38
|
-
|
|
39
|
-
Restful.client = new Http( Config.baseURL, Config.requestInit );
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public getClient() {
|
|
43
|
-
return Restful.client;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public get( command: string, args: ICommandArgsInterface = {}, options: ICommandOptionsInterface = {} ) {
|
|
47
|
-
this.currentHttpMethod = E_HTTP_METHOD_TYPE.GET;
|
|
48
|
-
|
|
49
|
-
return super.run( command, args, options );
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public update( command: string, args: ICommandArgsInterface = {}, options: {} = {} ) {
|
|
53
|
-
this.currentHttpMethod = E_HTTP_METHOD_TYPE.PATCH;
|
|
54
|
-
|
|
55
|
-
return super.run( command, args, options );
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public delete( command: string, args: ICommandArgsInterface = {}, options: {} = {} ) {
|
|
59
|
-
this.currentHttpMethod = E_HTTP_METHOD_TYPE.DELETE;
|
|
60
|
-
|
|
61
|
-
return super.run( command, args, options );
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public create( command: string, args: ICommandArgsInterface = {}, options: {} = {} ) {
|
|
65
|
-
this.currentHttpMethod = E_HTTP_METHOD_TYPE.POST;
|
|
66
|
-
|
|
67
|
-
return super.run( command, args, options );
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
protected async runInstance( command: CommandRestful, args: ICommandArgsInterface = {}, options: {} = {} ) {
|
|
71
|
-
if ( ! this.currentHttpMethod ) {
|
|
72
|
-
throw new Error( "Cannot run directly use one of the http methods: \"get\", \"update\", \"delete, \"create" );
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// New args.
|
|
76
|
-
const newArgs = {
|
|
77
|
-
type: this.currentHttpMethod,
|
|
78
|
-
args: {
|
|
79
|
-
query: {},
|
|
80
|
-
data: {},
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
if ( E_HTTP_METHOD_TYPE.GET === this.currentHttpMethod ) {
|
|
85
|
-
newArgs.args.query = args;
|
|
86
|
-
} else {
|
|
87
|
-
newArgs.args.data = args;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
args.result = await super.runInstance( command, newArgs, options );
|
|
91
|
-
|
|
92
|
-
// Clear method type.
|
|
93
|
-
this.currentHttpMethod = E_HTTP_METHOD_TYPE.__EMPTY__;
|
|
94
|
-
|
|
95
|
-
return args.result;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Handlers on return true will swallow the request.
|
|
100
|
-
*/
|
|
101
|
-
public setHandler( type: E_RESPONSE_HANDLER_TYPE, callback: TPossibleHandlersType ) {
|
|
102
|
-
switch ( type ) {
|
|
103
|
-
case E_RESPONSE_HANDLER_TYPE.ERROR_HANDLER:
|
|
104
|
-
Restful.client.setErrorHandler( callback as TErrorHandlerCallbackType );
|
|
105
|
-
break;
|
|
106
|
-
case E_RESPONSE_HANDLER_TYPE.RESPONSE_FILTER:
|
|
107
|
-
Restful.client.setResponseFilter( callback as TResponseFilterCallbackType );
|
|
108
|
-
break;
|
|
109
|
-
case E_RESPONSE_HANDLER_TYPE.RESPONSE_HANDLER:
|
|
110
|
-
Restful.client.setResponseHandler( callback as TResponseHandlerCallbackType );
|
|
111
|
-
break;
|
|
112
|
-
|
|
113
|
-
default:
|
|
114
|
-
throw new Error( `Unknown handler type: '${ type }'` );
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
package/src/modules/debugger.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import * as util from "util";
|
|
2
|
-
|
|
3
|
-
import { isDebugEnabled } from "@zenflux/utils/src/environment";
|
|
4
|
-
|
|
5
|
-
import pc from "picocolors";
|
|
6
|
-
|
|
7
|
-
import { Logger } from "./logger";
|
|
8
|
-
|
|
9
|
-
import { ObjectBase } from "../bases/object-base";
|
|
10
|
-
|
|
11
|
-
// Define options interface for Debugger
|
|
12
|
-
interface DebuggerOptions {
|
|
13
|
-
skipEventBusHook?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class Debugger extends ObjectBase {
|
|
17
|
-
private logger!: Logger;
|
|
18
|
-
|
|
19
|
-
declare private finalizationRegistry;
|
|
20
|
-
|
|
21
|
-
public static getName() {
|
|
22
|
-
return "ZenFlux/Core/Modules/Debugger";
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public constructor(
|
|
26
|
-
owner: ObjectBase | typeof ObjectBase | string,
|
|
27
|
-
prefix?: string,
|
|
28
|
-
private shouldDebug = Logger.isDebugEnabled(),
|
|
29
|
-
options?: DebuggerOptions // Add options parameter
|
|
30
|
-
) {
|
|
31
|
-
super();
|
|
32
|
-
|
|
33
|
-
if ( shouldDebug ) {
|
|
34
|
-
// Pass logger options down if skipEventBusHook is set
|
|
35
|
-
const loggerOptions = options?.skipEventBusHook ? { skipEventBusHook: true } : undefined;
|
|
36
|
-
this.logger = new Logger( owner, loggerOptions );
|
|
37
|
-
|
|
38
|
-
if ( prefix ) {
|
|
39
|
-
this.logger.addMessagePrefix( prefix );
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
// Bypass all the methods
|
|
43
|
-
this.log = () => {};
|
|
44
|
-
this.dumpDown = () => {};
|
|
45
|
-
this.enableCleanupDebug = () => {};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public enableCleanupDebug( handle: ObjectBase, id: string = "" ) {
|
|
50
|
-
if ( !this.finalizationRegistry ) {
|
|
51
|
-
this.finalizationRegistry = new FinalizationRegistry( ( id: string ) => {
|
|
52
|
-
this.log( this.constructor, `FinalizationRegistry: ${ id }` );
|
|
53
|
-
} );
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if ( !id ) {
|
|
57
|
-
id = handle.getName() + ":" + handle.getUniqueId();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.log( this.enableCleanupDebug, `Initialized: '${ id }'` );
|
|
61
|
-
|
|
62
|
-
this.finalizationRegistry.register( handle, id );
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public log( source: Function, message: string, ...args: any[] ) {
|
|
66
|
-
if ( args && args.length > 0 ) {
|
|
67
|
-
return this.logger.debug( source, message, ...args );
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this.logger.debug( source, message );
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public dumpDown( source: Function, object: any, objectName: string = "" ) {
|
|
74
|
-
this.log(
|
|
75
|
-
source,
|
|
76
|
-
`${ objectName ? objectName + ":" : "" } ` + "🔽" + "\n" + pc.green( util.inspect( object, false, null, true ) )
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public isEnabled() {
|
|
81
|
-
return this.shouldDebug;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function createDebugger( owner: ObjectBase | typeof ObjectBase | string, ownerType: string, prefix?: string ) {
|
|
86
|
-
const ownerName = typeof owner === "string" ? owner : owner.getName();
|
|
87
|
-
|
|
88
|
-
return new Debugger( owner, prefix, isDebugEnabled( ownerType, ownerName ) );
|
|
89
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import EventEmitter from "events";
|
|
2
|
-
|
|
3
|
-
import { ObjectBase } from "../../bases/object-base";
|
|
4
|
-
|
|
5
|
-
export class EventBus extends ObjectBase {
|
|
6
|
-
protected static instance: EventBus | null = null;
|
|
7
|
-
|
|
8
|
-
private objects = new Map<
|
|
9
|
-
string,
|
|
10
|
-
{
|
|
11
|
-
object: ObjectBase | ObjectBase[];
|
|
12
|
-
methods: Function[];
|
|
13
|
-
}
|
|
14
|
-
>();
|
|
15
|
-
|
|
16
|
-
private eventEmitter = new EventEmitter();
|
|
17
|
-
|
|
18
|
-
private lastEmittedEvents = new Map<string, any[]>();
|
|
19
|
-
|
|
20
|
-
public static getName() {
|
|
21
|
-
return "ZenFlux/Core/Modules/EventBus";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public static getInstance(): EventBus {
|
|
25
|
-
if ( !EventBus.instance ) {
|
|
26
|
-
EventBus.instance = new EventBus();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return EventBus.instance;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public static get $() {
|
|
33
|
-
return EventBus.getInstance();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public getObjectNames() {
|
|
37
|
-
return Array.from( this.objects.keys() );
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public getEventNames() {
|
|
41
|
-
this.eventEmitter.eventNames();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public getEventName( objectName: string, methodName: string ) {
|
|
45
|
-
return `${ objectName }::${ methodName }`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public on( objectName: string, methodName: string, callback: ( ...args: any[] ) => void ) {
|
|
49
|
-
// Validate that event exists
|
|
50
|
-
if ( !this.objects.has( objectName ) ) {
|
|
51
|
-
throw new Error( `Object ${ objectName } is not registered` );
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this.eventEmitter.on( this.getEventName( objectName, methodName ), callback );
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Function onCalledBeforeDoInvoke(): The difference between this function and on()
|
|
59
|
-
* is that this function will call the callback if the event already happened.
|
|
60
|
-
*/
|
|
61
|
-
public onCalledBeforeDoInvoke( objectName: string, methodName: string, callback: ( ...args: any[] ) => void ) {
|
|
62
|
-
this.on( objectName, methodName, callback );
|
|
63
|
-
|
|
64
|
-
// If event already happened, call the callback
|
|
65
|
-
if ( this.objects.has( objectName ) ) {
|
|
66
|
-
const objectEntry = this.objects.get( objectName );
|
|
67
|
-
|
|
68
|
-
if ( objectEntry ) {
|
|
69
|
-
// We don't need to iterate through objects anymore, just check if the event has been emitted
|
|
70
|
-
const method = objectEntry.methods.find( ( method ) => method.name === methodName );
|
|
71
|
-
|
|
72
|
-
if ( method && this.lastEmittedEvents.has( this.getEventName( objectName, methodName ) ) ) {
|
|
73
|
-
callback( ...this.lastEmittedEvents.get( this.getEventName( objectName, methodName ) )! );
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public off( objectName: string, methodName: string, callback: ( ...args: any[] ) => void ) {
|
|
80
|
-
this.eventEmitter.off( this.getEventName( objectName, methodName ), callback );
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public register<T extends ObjectBase>( object: T, methods: Function[] ) {
|
|
84
|
-
if ( this.objects.has( object.getName() ) ) {
|
|
85
|
-
throw new Error( `Error in: '${ this.getName() }', object: '${ object.getName() }' is already registered` );
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this.objects.set( object.getName(), {
|
|
89
|
-
object,
|
|
90
|
-
methods
|
|
91
|
-
} );
|
|
92
|
-
|
|
93
|
-
this.hook( object, methods );
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
public registerMultiInstances<T extends ObjectBase>( object: T, methods: Function[] ) {
|
|
97
|
-
const objectName = object.getName();
|
|
98
|
-
|
|
99
|
-
// If we already have an entry for this name, check if we need to convert to array
|
|
100
|
-
if ( this.objects.has( objectName ) ) {
|
|
101
|
-
const existingEntry = this.objects.get( objectName )!;
|
|
102
|
-
|
|
103
|
-
// If object is already an array, append to it
|
|
104
|
-
if ( Array.isArray( existingEntry.object ) ) {
|
|
105
|
-
( existingEntry.object as ObjectBase[] ).push( object );
|
|
106
|
-
}
|
|
107
|
-
// Otherwise, convert to array containing both existing and new objects
|
|
108
|
-
else {
|
|
109
|
-
existingEntry.object = [ existingEntry.object as ObjectBase, object ];
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
// Otherwise, create a new entry with the object directly (not in an array)
|
|
113
|
-
else {
|
|
114
|
-
this.objects.set( objectName, {
|
|
115
|
-
object,
|
|
116
|
-
methods
|
|
117
|
-
} );
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Hook the object
|
|
121
|
-
this.hook( object, methods );
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
public unregister( objectName: string ) {
|
|
125
|
-
const entry = this.objects.get( objectName );
|
|
126
|
-
|
|
127
|
-
if ( !entry ) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Handle both single object and array cases
|
|
132
|
-
if ( Array.isArray( entry.object ) ) {
|
|
133
|
-
( entry.object as ObjectBase[] ).forEach( obj => {
|
|
134
|
-
this.unhookObject( obj, entry.methods );
|
|
135
|
-
} );
|
|
136
|
-
} else {
|
|
137
|
-
this.unhookObject( entry.object as ObjectBase, entry.methods );
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
this.objects.delete( objectName );
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Helper method to unhook a single object
|
|
144
|
-
private unhookObject( object: ObjectBase, methods: Function[] ) {
|
|
145
|
-
methods.forEach( ( method ) => {
|
|
146
|
-
this.ensureFunction( object, method );
|
|
147
|
-
|
|
148
|
-
this.eventEmitter.removeAllListeners( this.getEventName( object.getName(), method.name ) );
|
|
149
|
-
|
|
150
|
-
( object as any )[ method.name ] = method;
|
|
151
|
-
} );
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
private unhook( entry: { object: ObjectBase | ObjectBase[]; methods: Function[] } ) {
|
|
155
|
-
if ( Array.isArray( entry.object ) ) {
|
|
156
|
-
( entry.object as ObjectBase[] ).forEach( obj => {
|
|
157
|
-
this.unhookObject( obj, entry.methods );
|
|
158
|
-
} );
|
|
159
|
-
} else {
|
|
160
|
-
this.unhookObject( entry.object as ObjectBase, entry.methods );
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private emit<T extends ObjectBase>( object: T, method: Function, ...args: any[] ) {
|
|
165
|
-
const eventName = this.getEventName( object.getName(), method.name );
|
|
166
|
-
|
|
167
|
-
this.lastEmittedEvents.set( eventName, args );
|
|
168
|
-
|
|
169
|
-
return this.eventEmitter.emit( eventName, ...args );
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private hook<T extends ObjectBase>( object: T, methods: Function[] ) {
|
|
173
|
-
methods.forEach( ( method ) => {
|
|
174
|
-
this.ensureFunction( object, method );
|
|
175
|
-
|
|
176
|
-
const originalMethod = method;
|
|
177
|
-
|
|
178
|
-
const eventBusHook = async( ...args: any[] ) => {
|
|
179
|
-
const result = await originalMethod.apply( object, args );
|
|
180
|
-
|
|
181
|
-
this.emit( object, method, ...args );
|
|
182
|
-
|
|
183
|
-
return result;
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
// TODO: Use better design pattern to handle losing of function names.
|
|
187
|
-
( object as any )[ method.name ] = new Proxy( eventBusHook, {
|
|
188
|
-
get( target, prop ) {
|
|
189
|
-
if ( prop === "name" ) {
|
|
190
|
-
return method.name;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return target[ prop as keyof typeof target ];
|
|
194
|
-
}
|
|
195
|
-
} );
|
|
196
|
-
} );
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
private ensureFunction<T extends ObjectBase>( object: T, method: Function ) {
|
|
200
|
-
if ( "function" !== typeof method ) {
|
|
201
|
-
throw new Error( `Method ${ method } is not a function on ${ object.getName() }` );
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import process from "process";
|
|
2
|
-
|
|
3
|
-
const DEFAULT_LOG_LEVEL = "5";
|
|
4
|
-
|
|
5
|
-
export function getLoggerDefaultLevel(): string {
|
|
6
|
-
return DEFAULT_LOG_LEVEL;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function getLoggerLogLevel(): number {
|
|
10
|
-
return parseInt( process.env.LOGGER_LOG_LEVEL || DEFAULT_LOG_LEVEL, 10 );
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getLoggerLogLevelString(): string {
|
|
14
|
-
switch ( getLoggerLogLevel() ) {
|
|
15
|
-
case 0:
|
|
16
|
-
return "NONE";
|
|
17
|
-
case 1:
|
|
18
|
-
return "ERROR";
|
|
19
|
-
case 2:
|
|
20
|
-
return "WARN";
|
|
21
|
-
case 3:
|
|
22
|
-
return "ADMIN";
|
|
23
|
-
case 4:
|
|
24
|
-
return "INFO";
|
|
25
|
-
case 5:
|
|
26
|
-
return "LOG";
|
|
27
|
-
case 6:
|
|
28
|
-
return "DEBUG";
|
|
29
|
-
default:
|
|
30
|
-
return "UNKNOWN";
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function isLoggerDebugEnabled(): boolean {
|
|
35
|
-
return getLoggerLogLevel() >= 6;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function isLoggerDisabled(): boolean {
|
|
39
|
-
return process.env.LOGGER_DISABLED === "true";
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function isLoggerPreviousSourceDisabled(): boolean {
|
|
43
|
-
return process.env.LOGGER_LOG_PREVIOUS_CALLER_SOURCE_DISABLED === "true";
|
|
44
|
-
}
|