Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Canonical<T>

Abstract unit type that loads items recursively from a directory structure, assigning them normalized names ("canonical names"), and providing a way to fetch the resources by name.

example

The Config service is a Canonical derivative that loads files ending with .config.js from the app/config directory.

If, for example, there is a config file app/config/auth/Forms.config.js (in the generated code), it can be loaded by the canonical name auth:Forms.

Type parameters

  • T

Hierarchy

Index

Constructors

constructor

Properties

Protected appPath

appPath: string[] = []

The base path directory where the canonical definitions reside.

Protected Readonly canon

canon: Canon

Protected canonicalItem

canonicalItem: string = ''

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

example

middleware

Protected loadedItems

loadedItems: {} = {}

Object mapping canonical names to loaded file references.

Type declaration

  • [key: string]: T

Protected loadedNamespaces

loadedNamespaces: {} = {}

Object mapping canonical namespaces to resolver functions.

Type declaration

Protected Readonly logging

logging: Logging

status

status: UnitStatus = ...

The current status of the unit.

Protected suffix

suffix: string = '.js'

The file suffix of files in the base path that should be loaded.

Accessors

Private appClassApplication

canonicalItems

  • get canonicalItems(): string

path

Methods

all

  • all(namespace?: string): string[]
  • Return an array of all loaded canonical names.

    Parameters

    • Optional namespace: string

    Returns string[]

Protected app

Protected buildCanonicalDefinition

Protected container

down

  • down(): void | Promise<void>
  • 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

  • get(key: string): undefined | T

getBoundMethod

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

    Parameters

    • methodName: string

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

    function

      • (...args: any[]): any
      • Parameters

        • Rest ...args: any[]

        Returns any

initCanonicalItem

  • Called for each canonical item loaded from a file. This function should do any setup necessary and return the item that should be associated with the canonical name.

    Parameters

    Returns Promise<T>

Protected make

  • make<T>(target: any, ...parameters: any[]): T
  • Call the make() method on the global container.

    Type parameters

    • T

    Parameters

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

    Returns T

namespaces

  • namespaces(): string[]

registerNamespace

  • 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

up

  • up(): Promise<void>

Static resolve

Extollo Logo

extollo (v. latin) - to lift up, to elevate

Extollo is a free & libre application framework in TypeScript.