Class CanonicalInstantiable<T>

Variant of the Canonical unit whose files export classes which are instantiated using the global container.

Type Parameters

  • T

Hierarchy

Constructors

Properties

appPath: string[] = []

The base path directory where the canonical definitions reside.

canon: Canon
canonicalItem: string = ''

The singular, programmatic name of one of these canonical items.

Example

middleware
loadedItems: {
    [key: string]: T;
} = {}

Object mapping canonical names to loaded file references.

Type declaration

  • [key: string]: T
loadedNamespaces: {
    [key: string]: CanonicalResolver<T>;
} = {}

Object mapping canonical namespaces to resolver functions.

Type declaration

logging: Logging
status: UnitStatus = UnitStatus.Stopped

The current status of the unit.

suffix: string = ''

The file suffix of files in the base path that should be loaded. This should EXCLUDE .js or .ts. These file extensions are determined by the framework depending on the Node runtime.

Example

.service

Example

.middleware

Accessors

  • get canonicalItems(): string
  • Get the plural name of the canonical items provided by this unit.

    Returns string

Methods

  • Return an array of all loaded canonical names.

    Parameters

    • Optional namespace: string

    Returns string[]

  • This method is called to stop the unit when the application is shutting down. Here, you should do any teardown required to stop the package cleanly.

    IN PARTICULAR take care to free blocking resources that could prevent the process from exiting without a kill.

    Returns void | Promise<void>

  • Get the method with the given name from this class, bound to this class.

    Returns

    function

    Parameters

    • methodName: string

    Returns ((...args: any[]) => any)

      • (...args: any[]): any
      • Get the method with the given name from this class, bound to this class.

        Returns

        function

        Parameters

        • Rest ...args: any[]

        Returns any

  • Call the make() method on the global container.

    Type Parameters

    • T

    Parameters

    • target: any
    • Rest ...parameters: any[]

    Returns T

  • Register a namespace resolver with the canonical unit.

    Namespaces are canonical names that start with a particular key, beginning with the @ character, which resolve their resources using a resolver function.

    Example

    const items = {
    'foo:bar': 123,
    'bob': 456,
    }

    const resolver = (key: string) => items[key]

    canonical.registerNamespace('@mynamespace', resolver)

    Now, the items in the @mynamespace namespace can be accessed like so:

    canonical.get('@mynamespace:foo:bar')  // => 123
    canonical.get('@mynamespace:bob') // => 456

    Parameters

    Returns void

  • This method is called to start the unit when the application is booting. Here, you should do any setup required to get the package up and running.

    Returns Promise<void>