Class: bootcomponent = new BootComponent()

BootComponent is used to export the default list of Booter's made available by this module as well as bind the BootStrapper to the app so it can be used to run the Booters.

Properties
Name Type Description
booters

BootComponent is used to export the default list of Booter's made available by this module as well as bind the BootStrapper to the app so it can be used to run the Booters.

constructor(app: Application) : BootComponent

Arguments
Name Type Description
app Application

Application instance

Class: baseartifactbooter = new BaseArtifactBooter()

This class serves as a base class for Booters which follow a pattern of configure, discover files in a folder(s) using explicit folder / extensions or a glob pattern and lastly identifying exported classes from such files and performing an action on such files such as binding them.

Any Booter extending this base class is expected to

  1. Set the 'options' property to a object of ArtifactOptions type. (Each extending class should provide defaults for the ArtifactOptions and use Object.assign to merge the properties with user provided Options).
  2. Provide it's own logic for 'load' after calling 'await super.load()' to actually boot the Artifact classes.

Currently supports the following boot phases: configure, discover, load

Properties
Name Type Description
classes Array

This class serves as a base class for Booters which follow a pattern of configure, discover files in a folder(s) using explicit folder / extensions or a glob pattern and lastly identifying exported classes from such files and performing an action on such files such as binding them.

Any Booter extending this base class is expected to

  1. Set the 'options' property to a object of ArtifactOptions type. (Each extending class should provide defaults for the ArtifactOptions and use Object.assign to merge the properties with user provided Options).
  2. Provide it's own logic for 'load' after calling 'await super.load()' to actually boot the Artifact classes.

Currently supports the following boot phases: configure, discover, load

dirs

This class serves as a base class for Booters which follow a pattern of configure, discover files in a folder(s) using explicit folder / extensions or a glob pattern and lastly identifying exported classes from such files and performing an action on such files such as binding them.

Any Booter extending this base class is expected to

  1. Set the 'options' property to a object of ArtifactOptions type. (Each extending class should provide defaults for the ArtifactOptions and use Object.assign to merge the properties with user provided Options).
  2. Provide it's own logic for 'load' after calling 'await super.load()' to actually boot the Artifact classes.

Currently supports the following boot phases: configure, discover, load

discovered

This class serves as a base class for Booters which follow a pattern of configure, discover files in a folder(s) using explicit folder / extensions or a glob pattern and lastly identifying exported classes from such files and performing an action on such files such as binding them.

Any Booter extending this base class is expected to

  1. Set the 'options' property to a object of ArtifactOptions type. (Each extending class should provide defaults for the ArtifactOptions and use Object.assign to merge the properties with user provided Options).
  2. Provide it's own logic for 'load' after calling 'await super.load()' to actually boot the Artifact classes.

Currently supports the following boot phases: configure, discover, load

extensions

This class serves as a base class for Booters which follow a pattern of configure, discover files in a folder(s) using explicit folder / extensions or a glob pattern and lastly identifying exported classes from such files and performing an action on such files such as binding them.

Any Booter extending this base class is expected to

  1. Set the 'options' property to a object of ArtifactOptions type. (Each extending class should provide defaults for the ArtifactOptions and use Object.assign to merge the properties with user provided Options).
  2. Provide it's own logic for 'load' after calling 'await super.load()' to actually boot the Artifact classes.

Currently supports the following boot phases: configure, discover, load

glob string

This class serves as a base class for Booters which follow a pattern of configure, discover files in a folder(s) using explicit folder / extensions or a glob pattern and lastly identifying exported classes from such files and performing an action on such files such as binding them.

Any Booter extending this base class is expected to

  1. Set the 'options' property to a object of ArtifactOptions type. (Each extending class should provide defaults for the ArtifactOptions and use Object.assign to merge the properties with user provided Options).
  2. Provide it's own logic for 'load' after calling 'await super.load()' to actually boot the Artifact classes.

Currently supports the following boot phases: configure, discover, load

options ArtifactOptions

Options being used by the Booter.

projectRoot string

This class serves as a base class for Booters which follow a pattern of configure, discover files in a folder(s) using explicit folder / extensions or a glob pattern and lastly identifying exported classes from such files and performing an action on such files such as binding them.

Any Booter extending this base class is expected to

  1. Set the 'options' property to a object of ArtifactOptions type. (Each extending class should provide defaults for the ArtifactOptions and use Object.assign to merge the properties with user provided Options).
  2. Provide it's own logic for 'load' after calling 'await super.load()' to actually boot the Artifact classes.

Currently supports the following boot phases: configure, discover, load

configure() : Promise

Configure the Booter by initializing the 'dirs', 'extensions' and 'glob' properties.

NOTE: All properties are configured even if all aren't used.

discover() : Promise

Discover files based on the 'glob' property relative to the 'projectRoot'. Discovered artifact files matching the pattern are saved to the 'discovered' property.

load() : Promise

Filters the exports of 'discovered' files to only be Classes (in case function / types are exported) as an artifact is a Class. The filtered artifact Classes are saved in the 'classes' property.

NOTE: Booters extending this class should call this method (await super.load()) and then process the artifact classes as appropriate.

Function: discoverFiles

discoverFiles(pattern: string, root: string) : Promise

Returns all files matching the given glob pattern relative to root

Returns:

Array of discovered files

Arguments
Name Type Description
pattern string

A glob pattern

root string

Root folder to start searching for matching files

Function: isClass

isClass(target: any) : boolean

Given a function, returns true if it is a class, false otherwise.

Returns:

True if target is a class. False otherwise.

Arguments
Name Type Description
target any

The function to check if it's a class or not.

Function: loadClassesFromFiles

loadClassesFromFiles(files: undefined) :

Returns an Array of Classes from given files. Works by requiring the file, identifying the exports from the file by getting the keys of the file and then testing each exported member to see if it's a class or not.

Returns:

[]} An array of Class constructors from a file

Arguments
Name Type Description
files

An array of string of absolute file paths

Class: controllerbooter = new ControllerBooter()

A class that extends BaseArtifactBooter to boot the 'Controller' artifact type. Discovered controllers are bound using app.controller().

Supported phases: configure, discover, load

Properties
Name Type Description
app Application

A class that extends BaseArtifactBooter to boot the 'Controller' artifact type. Discovered controllers are bound using app.controller().

Supported phases: configure, discover, load

controllerConfig ArtifactOptions

A class that extends BaseArtifactBooter to boot the 'Controller' artifact type. Discovered controllers are bound using app.controller().

Supported phases: configure, discover, load

projectRoot string

A class that extends BaseArtifactBooter to boot the 'Controller' artifact type. Discovered controllers are bound using app.controller().

Supported phases: configure, discover, load

constructor(app: Application, projectRoot: string, controllerConfig: ArtifactOptions) : ControllerBooter

Arguments
Name Type Description
app Application

A class that extends BaseArtifactBooter to boot the 'Controller' artifact type. Discovered controllers are bound using app.controller().

Supported phases: configure, discover, load

projectRoot string

A class that extends BaseArtifactBooter to boot the 'Controller' artifact type. Discovered controllers are bound using app.controller().

Supported phases: configure, discover, load

controllerConfig ArtifactOptions

A class that extends BaseArtifactBooter to boot the 'Controller' artifact type. Discovered controllers are bound using app.controller().

Supported phases: configure, discover, load

load() : Promise

Uses super method to get a list of Artifact classes. Boot each class by binding it to the application using app.controller(controller);.

Object literal: ControllerDefaults

Default ArtifactOptions for ControllerBooter.

Variables
Name Type Description
dirs

Default ArtifactOptions for ControllerBooter.

extensions

Default ArtifactOptions for ControllerBooter.

nested true

Default ArtifactOptions for ControllerBooter.

Class: repositorybooter = new RepositoryBooter()

A class that extends BaseArtifactBooter to boot the 'Repository' artifact type. Discovered repositories are bound using app.repository() which must be added to an Application using the RepositoryMixin from @loopback/repository.

Supported phases: configure, discover, load

Properties
Name Type Description
app AppWithRepository

A class that extends BaseArtifactBooter to boot the 'Repository' artifact type. Discovered repositories are bound using app.repository() which must be added to an Application using the RepositoryMixin from @loopback/repository.

Supported phases: configure, discover, load

projectRoot string

A class that extends BaseArtifactBooter to boot the 'Repository' artifact type. Discovered repositories are bound using app.repository() which must be added to an Application using the RepositoryMixin from @loopback/repository.

Supported phases: configure, discover, load

repositoryOptions ArtifactOptions

A class that extends BaseArtifactBooter to boot the 'Repository' artifact type. Discovered repositories are bound using app.repository() which must be added to an Application using the RepositoryMixin from @loopback/repository.

Supported phases: configure, discover, load

constructor(app: AppWithRepository, projectRoot: string, repositoryOptions: ArtifactOptions) : RepositoryBooter

Arguments
Name Type Description
app AppWithRepository

A class that extends BaseArtifactBooter to boot the 'Repository' artifact type. Discovered repositories are bound using app.repository() which must be added to an Application using the RepositoryMixin from @loopback/repository.

Supported phases: configure, discover, load

projectRoot string

A class that extends BaseArtifactBooter to boot the 'Repository' artifact type. Discovered repositories are bound using app.repository() which must be added to an Application using the RepositoryMixin from @loopback/repository.

Supported phases: configure, discover, load

repositoryOptions ArtifactOptions

A class that extends BaseArtifactBooter to boot the 'Repository' artifact type. Discovered repositories are bound using app.repository() which must be added to an Application using the RepositoryMixin from @loopback/repository.

Supported phases: configure, discover, load

load() : Promise

Uses super method to get a list of Artifact classes. Boot each class by binding it to the application using app.repository(repository); if present.

Object literal: RepositoryDefaults

Default ArtifactOptions for RepositoryBooter.

Variables
Name Type Description
dirs

Default ArtifactOptions for RepositoryBooter.

extensions

Default ArtifactOptions for RepositoryBooter.

nested true

Default ArtifactOptions for RepositoryBooter.

Class: bootstrapper = new Bootstrapper()

The Bootstrapper class provides the boot function that is responsible for finding and executing the Booters in an application based on given options.

NOTE: Bootstrapper should be bound as a SINGLETON so it can be cached as it does not maintain any state of it's own.

constructor(app: undefined, projectRoot: string, bootOptions: BootOptions) : Bootstrapper

Arguments
Name Type Description
app

The Bootstrapper class provides the boot function that is responsible for finding and executing the Booters in an application based on given options.

NOTE: Bootstrapper should be bound as a SINGLETON so it can be cached as it does not maintain any state of it's own.

projectRoot string

The Bootstrapper class provides the boot function that is responsible for finding and executing the Booters in an application based on given options.

NOTE: Bootstrapper should be bound as a SINGLETON so it can be cached as it does not maintain any state of it's own.

bootOptions BootOptions

The Bootstrapper class provides the boot function that is responsible for finding and executing the Booters in an application based on given options.

NOTE: Bootstrapper should be bound as a SINGLETON so it can be cached as it does not maintain any state of it's own.

boot(execOptions: BootExecutionOptions, ctx: Context) : Promise

Function is responsible for calling all registered Booter classes that are bound to the Application instance. Each phase of an instance must complete before the next phase is started.

Arguments
Name Type Description
execOptions BootExecutionOptions

Execution options for boot. These determine the phases and booters that are run.

ctx Context

The Bootstrapper class provides the boot function that is responsible for finding and executing the Booters in an application based on given options.

NOTE: Bootstrapper should be bound as a SINGLETON so it can be cached as it does not maintain any state of it's own.

Interface: Bootable

Interface to describe the additions made available to an Application that uses BootMixin.

Properties
Name Type Description
bootOptions BootOptions

Interface to describe the additions made available to an Application that uses BootMixin.

projectRoot string

Interface to describe the additions made available to an Application that uses BootMixin.

boot() : Promise

booters(booterCls: undefined) :

Arguments
Name Type Description
booterCls

Interface to describe the additions made available to an Application that uses BootMixin.

Interface: Booter

Defines the requirements to implement a Booter for LoopBack applications: configure() : Promise discover() : Promise load(): Promise

A Booter will run through the above methods in order.

configure() : Promise

Configure phase of the Booter. It should set options / defaults in this phase.

discover() : Promise

Discover phase of the Booter. It should search for artifacts in this phase.

load() : Promise

Load phase of the Booter. It should bind the artifacts in this phase.

Type alias: BootExecutionOptions(prop: string): any

Additional Properties

Arguments
Name Type Description
prop string

Type alias: BootOptions(prop: string): any

Type Object for Options passed into .boot()

Returns:

Arguments
Name Type Description
prop string

Function: BootMixin

BootMixin(superClass: T) :

Mixin for @loopback/boot. This Mixin provides the following:

  • Implements the Bootable Interface as follows.
  • Add a projectRoot property to the Class
  • Adds an optional bootOptions property to the Class that can be used to store the Booter conventions.
  • Adds the BootComponent to the Class (which binds the Bootstrapper and default Booters)
  • Provides the boot() convenience method to call Bootstrapper.boot()
  • Provides the booter() convenience method to bind a Booter(s) to the Application
  • Override component() to call mountComponentBooters
  • Adds mountComponentBooters which binds Booters to the application from component.booters[]

** NOTE ** Trying to constrain the type of this Mixin (or any Mixin) will cause errors. For example, constraining this Mixin to type Application require all types using by Application to be imported (including it's dependencies such as ResolutionSession). Another issue was that if a Mixin that is type constrained is used with another Mixin that is not, it will result in an error. Example (class MyApp extends BootMixin(RepositoryMixin(Application))) {}; ** END OF NOTE **

Arguments
Name Type Description
superClass T

Function: _bindBooter

_bindBooter(ctx: Context, booterCls: Constructor) : Binding

Method which binds a given Booter to a given Context with the Prefix and Tags expected by the Bootstrapper

Arguments
Name Type Description
ctx Context

The Context to bind the Booter Class

booterCls Constructor

Booter class to be bound