@zenflux/core 0.1.7 → 0.1.8

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.
Files changed (65) hide show
  1. package/dist/src/bases/controller-base.d.ts +4 -4
  2. package/dist/src/bases/index.d.ts +2 -2
  3. package/dist/src/clients/http.d.ts +3 -3
  4. package/dist/src/command-bases/command-base.d.ts +3 -3
  5. package/dist/src/command-bases/command-internal.d.ts +1 -1
  6. package/dist/src/command-bases/command-public.d.ts +1 -1
  7. package/dist/src/command-bases/command-restful.d.ts +1 -1
  8. package/dist/src/command-bases/index.d.ts +4 -4
  9. package/dist/src/errors/command-already-registered.d.ts +1 -1
  10. package/dist/src/errors/controller-already-registered.d.ts +1 -1
  11. package/dist/src/errors/controller-already-set.d.ts +1 -1
  12. package/dist/src/errors/force-method-implementation.d.ts +1 -1
  13. package/dist/src/errors/index-public.d.ts +1 -1
  14. package/dist/src/errors/index.d.ts +5 -5
  15. package/dist/src/exports-index.d.ts +5 -5
  16. package/dist/src/exports.d.ts +1 -1
  17. package/dist/src/index.d.ts +2 -2
  18. package/dist/src/interfaces/index.d.ts +4 -4
  19. package/dist/src/managers/commands.d.ts +4 -4
  20. package/dist/src/managers/controllers.d.ts +2 -2
  21. package/dist/src/managers/export.d.ts +5 -5
  22. package/dist/src/managers/index.d.ts +4 -4
  23. package/dist/src/managers/internal.d.ts +1 -1
  24. package/dist/src/managers/restful.d.ts +5 -5
  25. package/dist/zenflux-core.cjs +4 -4
  26. package/dist/zenflux-core.d.ts +448 -3
  27. package/dist/zenflux-core.mjs +4 -4
  28. package/package.json +11 -2
  29. package/src/bases/controller-base.ts +5 -5
  30. package/src/bases/index.ts +6 -2
  31. package/src/bases/initialize-base.ts +32 -0
  32. package/src/bases/object-base.ts +15 -43
  33. package/src/clients/http.ts +3 -3
  34. package/src/command-bases/command-base.ts +4 -4
  35. package/src/command-bases/command-internal.ts +1 -1
  36. package/src/command-bases/command-public.ts +1 -1
  37. package/src/command-bases/command-restful.ts +3 -3
  38. package/src/command-bases/index.ts +5 -4
  39. package/src/errors/command-already-registered.ts +1 -1
  40. package/src/errors/controller-already-registered.ts +1 -1
  41. package/src/errors/controller-already-set.ts +1 -1
  42. package/src/errors/error-with-metadata.ts +14 -0
  43. package/src/errors/force-method-implementation.ts +3 -11
  44. package/src/errors/index-public.ts +1 -1
  45. package/src/errors/index.ts +9 -5
  46. package/src/exports-index.ts +5 -5
  47. package/src/exports.ts +6 -5
  48. package/src/index.ts +3 -2
  49. package/src/interfaces/index.ts +5 -4
  50. package/src/interfaces/logger.ts +3 -2
  51. package/src/managers/commands.ts +6 -6
  52. package/src/managers/controllers.ts +3 -3
  53. package/src/managers/export.ts +5 -5
  54. package/src/managers/index.ts +5 -4
  55. package/src/managers/internal.ts +1 -1
  56. package/src/managers/restful.ts +5 -5
  57. package/src/modules/debugger.ts +113 -0
  58. package/src/modules/event-bus/event-bus.ts +204 -0
  59. package/src/modules/logger/config.ts +44 -0
  60. package/src/modules/logger/index.ts +82 -0
  61. package/src/modules/mcp-server/mcp-server.ts +139 -0
  62. package/src/modules/mcp-server/mcp-service.ts +80 -0
  63. package/src/modules/service/service-base.ts +55 -0
  64. package/src/modules/service/service-locator.ts +205 -0
  65. package/src/modules/service/service-with-dependencies-base.ts +51 -0
@@ -3,16 +3,16 @@
3
3
  *
4
4
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
5
5
  */
6
- import { E_HTTP_METHOD_TYPE } from "@zenflux/core/src/interfaces";
6
+ import { E_HTTP_METHOD_TYPE } from "../interfaces";
7
7
 
8
- import { ObjectBase } from "@zenflux/core/src/bases/object-base";
8
+ import { ObjectBase } from "../bases/object-base";
9
9
 
10
10
  import type {
11
11
  ILogger,
12
12
  TErrorHandlerCallbackType,
13
13
  TResponseFilterCallbackType,
14
14
  TResponseHandlerCallbackType
15
- } from "@zenflux/core/src/interfaces";
15
+ } from "../interfaces";
16
16
 
17
17
  // noinspection ExceptionCaughtLocallyJS
18
18
 
@@ -5,12 +5,12 @@
5
5
  * TODO
6
6
  * - Add validateArgs method or find something better.
7
7
  */
8
- import { ObjectBase } from "@zenflux/core/src/bases";
9
- import { ControllerAlreadySet, ForceMethodImplementation } from "@zenflux/core/src/errors";
8
+ import { ObjectBase } from "../bases";
9
+ import { ControllerAlreadySet, ForceMethodImplementation } from "../errors";
10
10
 
11
- import type { ControllerBase } from "@zenflux/core/src/bases";
11
+ import type { ControllerBase } from "../bases";
12
12
 
13
- import type { ICommandArgsInterface, ICommandOptionsInterface, ILogger } from "@zenflux/core/src/interfaces";
13
+ import type { ICommandArgsInterface, ICommandOptionsInterface, ILogger } from "../interfaces";
14
14
 
15
15
  export abstract class CommandBase extends ObjectBase {
16
16
  private static controller: ControllerBase;
@@ -2,7 +2,7 @@
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  * @description CommandInternal, is used when part of the logic needed to be in the command but not represent a user action.
4
4
  */
5
- import { CommandBase } from "@zenflux/core/src/command-bases/command-base";
5
+ import { CommandBase } from "./command-base";
6
6
 
7
7
  export class CommandInternal extends CommandBase {
8
8
  public static getName() {
@@ -2,7 +2,7 @@
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  * @description CommandPublic represents a USER action, every class which inherit from this class will USER action.
4
4
  * */
5
- import { CommandBase } from "@zenflux/core/src/command-bases/command-base";
5
+ import { CommandBase } from "./command-base";
6
6
 
7
7
  export class CommandPublic extends CommandBase {
8
8
  public static getName() {
@@ -2,11 +2,11 @@
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  * @description Each rest command should represent a final REST endpoint.
4
4
  */
5
- import { CommandBase } from "@zenflux/core/src/command-bases/command-base";
5
+ import { CommandBase } from "./command-base";
6
6
 
7
- import { ForceMethodImplementation } from "@zenflux/core/src/errors";
7
+ import { ForceMethodImplementation } from "../errors";
8
8
 
9
- import * as managers from "@zenflux/core/src/managers/export";
9
+ import * as managers from "../managers/export";
10
10
 
11
11
  export abstract class CommandRestful extends CommandBase {
12
12
  public static getName() {
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- export { CommandPublic } from "@zenflux/core/src/command-bases/command-public";
5
- export { CommandRestful } from "@zenflux/core/src/command-bases/command-restful";
6
- export { CommandBase } from "@zenflux/core/src/command-bases/command-base";
7
- export { CommandInternal } from "@zenflux/core/src/command-bases/command-internal";
4
+
5
+ export { CommandPublic } from "./command-public";
6
+ export { CommandRestful } from "./command-restful";
7
+ export { CommandBase } from "./command-base";
8
+ export { CommandInternal } from "./command-internal";
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- import type { CommandBase } from "@zenflux/core/src/command-bases/command-base";
4
+ import type { CommandBase } from "../command-bases/command-base";
5
5
 
6
6
  /**
7
7
  * @internal
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- import type { ControllerBase } from "@zenflux/core/src/bases";
4
+ import type { ControllerBase } from "../bases";
5
5
 
6
6
  /**
7
7
  * @internal
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- import type { ControllerBase } from "@zenflux/core/src/bases";
4
+ import type { ControllerBase } from "../bases";
5
5
 
6
6
  /**
7
7
  * @internal
@@ -0,0 +1,14 @@
1
+ import util from "node:util";
2
+
3
+ export class ErrorWithMetadata extends Error {
4
+ public metadata: any;
5
+
6
+ public constructor( message: string, metadata: any | null = null ) {
7
+ super( message );
8
+ this.metadata = metadata;
9
+
10
+ this.message = null !== metadata ? `${ message } - Metadata: ${ util.inspect( metadata ) }` : message;
11
+
12
+ Object.setPrototypeOf( this, new.target.prototype );
13
+ }
14
+ }
@@ -1,23 +1,15 @@
1
- import type { ObjectBase } from "@zenflux/core/src/bases";
1
+ import type { ObjectBase } from "../bases";
2
2
 
3
- /**
4
- * @internal
5
- */
6
3
  export class ForceMethodBase extends Error {
7
4
  public constructor( className: string, methodName: string ) {
8
- super(
9
- `ForceMethod implementation: at: '${ className }' method: '${ methodName }'`
10
- );
5
+ super( `ForceMethod implementation: at '${ className }' method: '${ methodName }'` );
11
6
  }
12
7
  }
13
8
 
14
- /**
15
- * @public
16
- */
17
9
  export class ForceMethodImplementation extends Error {
18
10
  public constructor( context: ObjectBase | typeof ObjectBase | string, methodName: string ) {
19
11
  super(
20
- `ForceMethod implementation: at: '${ "string" === typeof context ? context : context.getName() }' method: '${ methodName }'`
12
+ `ForceMethod implementation: at '${ "string" === typeof context ? context : context.getName() }' method: '${ methodName }'`
21
13
  );
22
14
  }
23
15
  }
@@ -1 +1 @@
1
- export { ForceMethodImplementation } from "@zenflux/core/src/errors/force-method-implementation";
1
+ export { ForceMethodImplementation } from "./force-method-implementation";
@@ -1,5 +1,9 @@
1
- export { CommandAlreadyRegistered } from "@zenflux/core/src/errors/command-already-registered";
2
- export { CommandNotFound } from "@zenflux/core/src/errors/command-not-found";
3
- export { ControllerAlreadyRegistered } from "@zenflux/core/src/errors/controller-already-registered";
4
- export { ControllerAlreadySet } from "@zenflux/core/src/errors/controller-already-set";
5
- export { ForceMethodImplementation } from "@zenflux/core/src/errors/force-method-implementation";
1
+ /**
2
+ * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
+ */
4
+
5
+ export { CommandAlreadyRegistered } from "./command-already-registered";
6
+ export { CommandNotFound } from "./command-not-found";
7
+ export { ControllerAlreadyRegistered } from "./controller-already-registered";
8
+ export { ControllerAlreadySet } from "./controller-already-set";
9
+ export { ForceMethodImplementation, ForceMethodBase } from "./force-method-implementation";
@@ -1,8 +1,8 @@
1
- import * as bases from "@zenflux/core/src/bases";
2
- import * as commandBases from "@zenflux/core/src/command-bases";
3
- import * as errors from "@zenflux/core/src/errors/index-public";
4
- import * as interfaces from "@zenflux/core/src/interfaces";
5
- import * as managers from "@zenflux/core/src/managers/export";
1
+ import * as bases from "./bases";
2
+ import * as commandBases from "./command-bases";
3
+ import * as errors from "./errors/index-public";
4
+ import * as interfaces from "./interfaces";
5
+ import * as managers from "./managers/export";
6
6
 
7
7
  export {
8
8
  bases,
package/src/exports.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
4
  // @ts-ignore - TODO handle error in jest
5
- import { bases, commandBases, errors, interfaces, managers, } from "@zenflux/core/src/exports-index";
5
+ import { bases, commandBases, errors, interfaces, managers, } from "./exports-index";
6
6
 
7
- import * as pkg from "@zenflux/core/package.json" assert { type: "json" };
7
+ import * as pkg from "../package.json" assert { type: "json" };
8
8
 
9
9
  declare global {
10
10
  var __ZEN_CORE__IS_INITIALIZED__: boolean;
@@ -15,7 +15,7 @@ export const classes = {
15
15
  /* eslint-disable @typescript-eslint/explicit-member-accessibility */
16
16
 
17
17
  Logger: class NullLogger implements interfaces.ILogger {
18
- constructor( owner: typeof bases.ObjectBase, params: any = {} ) {
18
+ constructor( owner: typeof bases.ObjectBase | bases.ObjectBase | string, params: any = {} ) {
19
19
  }
20
20
 
21
21
  log( caller: interfaces.TCaller, message: string, ... params: any[] ) {}
@@ -23,9 +23,10 @@ export const classes = {
23
23
  error( caller: interfaces.TCaller, message: string, ... params: any[] ) {}
24
24
  info( caller: interfaces.TCaller, message: string, ... params: any[] ) {}
25
25
  debug( caller: interfaces.TCaller, message: string, ... params: any[] ) {}
26
+ addMessagePrefix( prefix: string ) {}
26
27
  startsEmpty( caller: interfaces.TCaller ) {}
27
- startsWith( caller: interfaces.TCaller, params: object ) {}
28
- dump( caller: interfaces.TCaller, data: any ) {}
28
+ startsWith( caller: interfaces.TCaller, params: object | string ) {}
29
+ dump( caller: interfaces.TCaller, data: any, notice?: string ) {}
29
30
  drop( caller: interfaces.TCaller, according: { [ key: string ]: string }, data: any ) {}
30
31
  }
31
32
 
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- import * as ZenCore from "@zenflux/core/src/exports";
4
+
5
+ import * as ZenCore from "./exports";
5
6
 
6
7
  // TODO: Only in development mode
7
8
  if ( ! globalThis?.zCore ) {
@@ -12,6 +13,6 @@ declare global {
12
13
  var zCore: typeof ZenCore;
13
14
  }
14
15
 
15
- export * from "@zenflux/core/src/exports-index";
16
+ export * from "./exports-index";
16
17
 
17
18
  export default ZenCore;
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- export type * from "@zenflux/core/src/interfaces/commands";
5
- export type * from "@zenflux/core/src/interfaces/config";
6
- export type * from "@zenflux/core/src/interfaces/logger";
7
- export * from "@zenflux/core/src/interfaces/restful";
4
+
5
+ export type * from "./commands";
6
+ export type * from "./config";
7
+ export type * from "./logger";
8
+ export * from "./restful";
@@ -9,10 +9,11 @@ export interface ILogger {
9
9
  error( caller: TCaller, message: string, ...params: any[] ): void;
10
10
  info( caller: TCaller, message: string, ...params: any[] ): void;
11
11
  debug( caller: TCaller, message: string, ...params: any[] ): void;
12
+ addMessagePrefix( prefix: string ): void;
12
13
 
13
14
  startsEmpty( caller: TCaller ): void;
14
- startsWith( caller: TCaller, params: object ): void;
15
+ startsWith( caller: TCaller, params: object | string ): void;
15
16
 
16
- dump( caller: TCaller, params: { [ key: string ]: object|string } ): void;
17
+ dump( caller: TCaller, params: { [ key: string ]: object|string }, notice?: string ): void;
17
18
  drop( caller: TCaller, according: { [ key: string ]: string }, data: any ): void;
18
19
  }
@@ -2,10 +2,10 @@
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  * @description Responsible for manging/running/hooking commands.
4
4
  */
5
- import { ObjectBase } from "@zenflux/core/src/bases/object-base";
5
+ import { ObjectBase } from "../bases/object-base";
6
6
 
7
- import { CommandNotFound } from "@zenflux/core/src/errors/command-not-found";
8
- import { CommandAlreadyRegistered } from "@zenflux/core/src/errors/command-already-registered";
7
+ import { CommandNotFound } from "../errors/command-not-found";
8
+ import { CommandAlreadyRegistered } from "../errors/command-already-registered";
9
9
 
10
10
  import type {
11
11
  TCommandCallbackType,
@@ -17,10 +17,10 @@ import type {
17
17
  ICommandOptionsInterface,
18
18
 
19
19
  ILogger,
20
- } from "@zenflux/core/src/interfaces";
20
+ } from "../interfaces";
21
21
 
22
- import type { ControllerBase } from "@zenflux/core/src/bases/controller-base";
23
- import type { CommandBase } from "@zenflux/core/src/command-bases/command-base";
22
+ import type { ControllerBase } from "../bases/controller-base";
23
+ import type { CommandBase } from "../command-bases/command-base";
24
24
 
25
25
  export class Commands extends ObjectBase {
26
26
  public static readonly trace:string[] = [];
@@ -2,11 +2,11 @@
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  * @description Responsible for manging controllers, each controller is global singleton instance.
4
4
  */
5
- import { ControllerAlreadyRegistered } from "@zenflux/core/src/errors/controller-already-registered";
5
+ import { ControllerAlreadyRegistered } from "../errors/controller-already-registered";
6
6
 
7
- import { ObjectBase } from "@zenflux/core/src/bases/object-base";
7
+ import { ObjectBase } from "../bases/object-base";
8
8
 
9
- import type { ControllerBase } from "@zenflux/core/src/bases/controller-base";
9
+ import type { ControllerBase } from "../bases/controller-base";
10
10
 
11
11
  export class Controllers extends ObjectBase {
12
12
  private controllers: { [ key: string ]: ControllerBase } = {};
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- import { Commands } from "@zenflux/core/src/managers/commands";
5
- import { Controllers } from "@zenflux/core/src/managers/controllers";
6
- import { Restful } from "@zenflux/core/src/managers/restful";
7
- import { Internal } from "@zenflux/core/src/managers/internal";
4
+ import { Commands } from "./commands";
5
+ import { Controllers } from "./controllers";
6
+ import { Restful } from "./restful";
7
+ import { Internal } from "./internal";
8
8
 
9
- import type { IAPIConfig } from "@zenflux/core/src/interfaces";
9
+ import type { IAPIConfig } from "../interfaces";
10
10
 
11
11
  export const afterInitializeCallbacks: ( () => void )[] = [];
12
12
 
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  */
4
- export { Commands } from "@zenflux/core/src/managers/commands";
5
- export { Controllers } from "@zenflux/core/src/managers/controllers";
6
- export { Restful } from "@zenflux/core/src/managers/restful";
7
- export { Internal } from "@zenflux/core/src/managers/internal";
4
+
5
+ export { Commands } from "./commands";
6
+ export { Controllers } from "./controllers";
7
+ export { Restful } from "./restful";
8
+ export { Internal } from "./internal";
@@ -2,7 +2,7 @@
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  * @description Responsible for manging internal commands, To serve commands that are not triggered by user.
4
4
  */
5
- import { Commands } from "@zenflux/core/src/managers/commands";
5
+ import { Commands } from "./commands";
6
6
 
7
7
  export class Internal extends Commands {
8
8
  public static getName() {
@@ -2,16 +2,16 @@
2
2
  * @author Leonid Vinikov <leonidvinikov@gmail.com>
3
3
  * @description Responsible for manging restful commands which are wrappers for HTTP requests.
4
4
  */
5
- import { Commands } from "@zenflux/core/src/managers/commands";
5
+ import { Commands } from "./commands";
6
6
 
7
- import { Http } from "@zenflux/core/src/clients/http";
7
+ import { Http } from "../clients/http";
8
8
 
9
9
  import {
10
10
  E_RESPONSE_HANDLER_TYPE,
11
11
  E_HTTP_METHOD_TYPE
12
- } from "@zenflux/core/src/interfaces";
12
+ } from "../interfaces";
13
13
 
14
- import type { CommandRestful } from "@zenflux/core/src/command-bases";
14
+ import type { CommandRestful } from "../command-bases";
15
15
 
16
16
  import type {
17
17
  IAPIConfig,
@@ -22,7 +22,7 @@ import type {
22
22
  TPossibleHandlersType,
23
23
  TResponseFilterCallbackType,
24
24
  TResponseHandlerCallbackType
25
- } from "@zenflux/core/src/interfaces";
25
+ } from "../interfaces";
26
26
 
27
27
  export class Restful extends Commands {
28
28
  private static client: Http;
@@ -0,0 +1,113 @@
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
+ import type { PermissionOverwriteManager, PermissionOverwrites } from "discord.js";
12
+
13
+ // Define options interface for Debugger
14
+ interface DebuggerOptions {
15
+ skipEventBusHook?: boolean;
16
+ }
17
+
18
+ export class Debugger extends ObjectBase {
19
+ private logger!: Logger;
20
+
21
+ declare private finalizationRegistry;
22
+
23
+ public static getName() {
24
+ return "ZenFlux/Core/Modules/Debugger";
25
+ }
26
+
27
+ public constructor(
28
+ owner: ObjectBase | typeof ObjectBase | string,
29
+ prefix?: string,
30
+ private shouldDebug = Logger.isDebugEnabled(),
31
+ options?: DebuggerOptions // Add options parameter
32
+ ) {
33
+ super();
34
+
35
+ if ( shouldDebug ) {
36
+ // Pass logger options down if skipEventBusHook is set
37
+ const loggerOptions = options?.skipEventBusHook ? { skipEventBusHook: true } : undefined;
38
+ this.logger = new Logger( owner, loggerOptions );
39
+
40
+ if ( prefix ) {
41
+ this.logger.addMessagePrefix( prefix );
42
+ }
43
+ } else {
44
+ // Bypass all the methods
45
+ this.log = () => {};
46
+ this.dumpDown = () => {};
47
+ this.debugPermission = () => {};
48
+ this.debugPermissions = () => {};
49
+ this.enableCleanupDebug = () => {};
50
+ }
51
+ }
52
+
53
+ public enableCleanupDebug( handle: ObjectBase, id: string = "" ) {
54
+ if ( !this.finalizationRegistry ) {
55
+ this.finalizationRegistry = new FinalizationRegistry( ( id: string ) => {
56
+ this.log( this.constructor, `FinalizationRegistry: ${ id }` );
57
+ } );
58
+ }
59
+
60
+ if ( !id ) {
61
+ id = handle.getName() + ":" + handle.getUniqueId();
62
+ }
63
+
64
+ this.log( this.enableCleanupDebug, `Initialized: '${ id }'` );
65
+
66
+ this.finalizationRegistry.register( handle, id );
67
+ }
68
+
69
+ public log( source: Function, message: string, ...args: any[] ) {
70
+ if ( args && args.length > 0 ) {
71
+ return this.logger.debug( source, message, ...args );
72
+ }
73
+
74
+ this.logger.debug( source, message );
75
+ }
76
+
77
+ public dumpDown( source: Function, object: any, objectName: string = "" ) {
78
+ this.log(
79
+ source,
80
+ `${ objectName ? objectName + ":" : "" } ` + "🔽" + "\n" + pc.green( util.inspect( object, false, null, true ) )
81
+ );
82
+ }
83
+
84
+ public debugPermission( source: Function, overwrite: PermissionOverwrites ) {
85
+ let { id, allow, deny, type } = overwrite;
86
+
87
+ this.log(
88
+ source,
89
+ JSON.stringify( {
90
+ id,
91
+ allow: allow.toArray(),
92
+ deny: deny.toArray(),
93
+ type
94
+ } )
95
+ );
96
+ }
97
+
98
+ public debugPermissions( source: Function, permissionOverwrites: PermissionOverwriteManager ) {
99
+ for ( const overwrite of permissionOverwrites.cache.values() ) {
100
+ this.debugPermission( source, overwrite );
101
+ }
102
+ }
103
+
104
+ public isEnabled() {
105
+ return this.shouldDebug;
106
+ }
107
+ }
108
+
109
+ export function createDebugger( owner: ObjectBase | typeof ObjectBase | string, ownerType: string, prefix?: string ) {
110
+ const ownerName = typeof owner === "string" ? owner : owner.getName();
111
+
112
+ return new Debugger( owner, prefix, isDebugEnabled( ownerType, ownerName ) );
113
+ }