Page Contents

Home > @loopback/boot

boot package

A convention based project Bootstrapper and Booters for LoopBack Applications.

Remarks

A Booter is a class that can be bound to an Application and is called to perform a task before the Application is started. A Booter may have multiple phases to complete its task. The task for a convention based Booter is to discover and bind Artifacts (Controllers, Repositories, Models, etc.).

An example task of a Booter may be to discover and bind all artifacts of a given type.

A Bootstrapper is needed to manage the Booters and execute them. This is provided in this package. For ease of use, everything needed is packages using a BootMixin. This Mixin will add convenience methods such as boot and booter, as well as properties needed for Bootstrapper such as projectRoot. The Mixin also adds the BootComponent to your Application which binds the Bootstrapper and default Booters made available by this package.

Classes

Class Description
ApplicationMetadataBooter Configure the application with metadata from package.json
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 to1. 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.
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.
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.
ControllerBooter A class that extends BaseArtifactBooter to boot the ‘Controller’ artifact type. Discovered controllers are bound using app.controller().Supported phases: configure, discover, load
DataSourceBooter A class that extends BaseArtifactBooter to boot the ‘DataSource’ artifact type. Discovered DataSources are bound using app.dataSource().Supported phases: configure, discover, load
InterceptorProviderBooter A class that extends BaseArtifactBooter to boot the ‘InterceptorProvider’ artifact type.Supported phases: configure, discover, load
LifeCycleObserverBooter A class that extends BaseArtifactBooter to boot the ‘LifeCycleObserver’ artifact type.Supported phases: configure, discover, load
ModelApiBooter  
ModelBooter A class that extends BaseArtifactBooter to boot the ‘Model’ artifact type.Supported phases: configure, discover, load
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
ServiceBooter A class that extends BaseArtifactBooter to boot the ‘Service’ artifact type. Discovered services are bound using app.service().Supported phases: configure, discover, load

Functions

Function Description
bindBooter(ctx, booterCls) Method which binds a given Booter to a given Context with the Prefix and Tags expected by the Bootstrapper
booter(artifactNamespace, specs) @booter decorator to mark a class as a Booter and specify the artifact namespace for the configuration of the booter
BootMixin(superClass) 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[]
createBooterForComponentApplication(componentApp, filter) Create a booter that boots the component application. Bindings that exist in the component application before boot are skipped. Locked bindings in the main application will not be overridden.
createComponentApplicationBooterBinding(componentApp, filter) Create a binding to register a booter that boots the component application. Bindings that exist in the component application before boot are skipped. Locked bindings in the main application will not be overridden.
discoverFiles(pattern, root) Returns all files matching the given glob pattern relative to root
isClass(target) Given a function, returns true if it is a class, false otherwise.
loadClassesFromFiles(files, projectRootDir) 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.

Interfaces

Interface Description
Bootable Interface to describe the additions made available to an Application that uses BootMixin.
Booter Defines the requirements to implement a Booter for LoopBack applications: - configure() - discover() - load()A Booter will run through the above methods in order.
InstanceWithBooters Interface to describe an object that may have an array of booters.

Namespaces

Namespace Description
BootBindings Namespace for boot related binding keys
BootTags Namespace for boot related tags

Variables

Variable Description
_bindBooter  
bindingKeysExcludedFromSubApp Binding keys excluded from a sub application. These bindings booted from the sub application won’t be added to the main application.
BOOTER_PHASES Export of an array of all the Booter phases supported by the interface above, in the order they should be run.
ControllerDefaults Default ArtifactOptions for ControllerBooter.
DataSourceDefaults Default ArtifactOptions for DataSourceBooter.
InterceptorProviderDefaults Default ArtifactOptions for InterceptorProviderBooter.
LifeCycleObserverDefaults Default ArtifactOptions for DataSourceBooter.
ModelDefaults Default ArtifactOptions for DataSourceBooter.
RepositoryDefaults Default ArtifactOptions for RepositoryBooter.
RestDefaults Default ArtifactOptions for ControllerBooter.
ServiceDefaults Default ArtifactOptions for DataSourceBooter.

Type Aliases

Type Alias Description
ArtifactOptions Type definition for ArtifactOptions. These are the options supported by this Booter.
BootExecutionOptions Options for boot() execution
BootOptions Options to configure Bootstrapper