1 | import { Binding, BindingSpec, Constructor } from '@loopback/core';
|
2 | /**
|
3 | * Type definition for ArtifactOptions. These are the options supported by
|
4 | * this Booter.
|
5 | */
|
6 | export type ArtifactOptions = {
|
7 | /**
|
8 | * Array of directories to check for artifacts.
|
9 | * Paths must be relative. Defaults to ['controllers']
|
10 | */
|
11 | dirs?: string | string[];
|
12 | /**
|
13 | * Array of file extensions to match artifact
|
14 | * files in dirs. Defaults to ['.controller.js']
|
15 | */
|
16 | extensions?: string | string[];
|
17 | /**
|
18 | * A flag to control if artifact discovery should check nested
|
19 | * folders or not. Default to true
|
20 | */
|
21 | nested?: boolean;
|
22 | /**
|
23 | * A `glob` string to use when searching for files. This takes
|
24 | * precedence over other options.
|
25 | */
|
26 | glob?: string;
|
27 | };
|
28 | /**
|
29 | * Defines the requirements to implement a Booter for LoopBack applications:
|
30 | * - configure()
|
31 | * - discover()
|
32 | * - load()
|
33 | *
|
34 | * A Booter will run through the above methods in order.
|
35 | */
|
36 | export interface Booter {
|
37 | /**
|
38 | * Configure phase of the Booter. It should set options / defaults in this phase.
|
39 | */
|
40 | configure?(): Promise<void>;
|
41 | /**
|
42 | * Discover phase of the Booter. It should search for artifacts in this phase.
|
43 | */
|
44 | discover?(): Promise<void>;
|
45 | /**
|
46 | * Load phase of the Booter. It should bind the artifacts in this phase.
|
47 | */
|
48 | load?(): Promise<void>;
|
49 | }
|
50 | /**
|
51 | * Export of an array of all the Booter phases supported by the interface
|
52 | * above, in the order they should be run.
|
53 | */
|
54 | export declare const BOOTER_PHASES: string[];
|
55 | /**
|
56 | * Options to configure `Bootstrapper`
|
57 | */
|
58 | export type BootOptions = {
|
59 | controllers?: ArtifactOptions;
|
60 | repositories?: ArtifactOptions;
|
61 | /**
|
62 | * Additional Properties
|
63 | */
|
64 | [prop: string]: any;
|
65 | };
|
66 | /**
|
67 | * Options for boot() execution
|
68 | */
|
69 | export type BootExecutionOptions = {
|
70 | /**
|
71 | * Optional array of Booter Classes to bind to the application before running bootstrapper.
|
72 | */
|
73 | booters?: Constructor<Booter>[];
|
74 | /**
|
75 | * Filter Object for Bootstrapper
|
76 | */
|
77 | filter?: {
|
78 | /**
|
79 | * Names of booters that should be run by Bootstrapper
|
80 | */
|
81 | booters?: string[];
|
82 | /**
|
83 | * Names of phases that should be run by Bootstrapper
|
84 | */
|
85 | phases?: string[];
|
86 | };
|
87 | /**
|
88 | * Additional Properties
|
89 | */
|
90 | [prop: string]: any;
|
91 | };
|
92 | /**
|
93 | * Interface to describe the additions made available to an Application
|
94 | * that uses BootMixin.
|
95 | */
|
96 | export interface Bootable {
|
97 | /**
|
98 | * Root directory for the project to be booted
|
99 | */
|
100 | projectRoot: string;
|
101 | /**
|
102 | * Options for boot
|
103 | */
|
104 | bootOptions?: BootOptions;
|
105 | /**
|
106 | * Boot up the project
|
107 | */
|
108 | boot(): Promise<void>;
|
109 | /**
|
110 | * Register booters
|
111 | * @param booterClasses - A list of booter classes
|
112 | */
|
113 | booters(...booterClasses: Constructor<Booter>[]): Binding[];
|
114 | }
|
115 | /**
|
116 | * `@booter` decorator to mark a class as a `Booter` and specify the artifact
|
117 | * namespace for the configuration of the booter
|
118 | *
|
119 | * @example
|
120 | * ```ts
|
121 | * @booter('controllers')
|
122 | * export class ControllerBooter extends BaseArtifactBooter {
|
123 | * constructor(
|
124 | * @inject(CoreBindings.APPLICATION_INSTANCE) public app: Application,
|
125 | * @inject(BootBindings.PROJECT_ROOT) projectRoot: string,
|
126 | * @config()
|
127 | * public controllerConfig: ArtifactOptions = {},
|
128 | * ) {
|
129 | * // ...
|
130 | * }
|
131 | * }
|
132 | * ```
|
133 | *
|
134 | * @param artifactNamespace - Namespace for the artifact. It will be used to
|
135 | * inject configuration from boot options. For example, the Booter class
|
136 | * decorated with `@booter('controllers')` can receive its configuration via
|
137 | * `@config()` from the `controllers` property of boot options.
|
138 | *
|
139 | * @param specs - Extra specs for the binding
|
140 | */
|
141 | export declare function booter(artifactNamespace: string, ...specs: BindingSpec[]): ClassDecorator;
|
142 | /**
|
143 | * Interface to describe an object that may have an array of `booters`.
|
144 | */
|
145 | export interface InstanceWithBooters {
|
146 | booters?: Constructor<Booter>[];
|
147 | }
|