UNPKG

11.5 kBTypeScriptView Raw
1import { Binding, BindingFilter, BindingFromClassOptions, BindingScope, Constructor, Context, Application, Component, MixinTarget } from '@loopback/core';
2import { Bootable, Booter, BootOptions, InstanceWithBooters } from '../types';
3import * as loopbackContext from '@loopback/core';
4export { Binding };
5/**
6 * Mixin for @loopback/boot. This Mixin provides the following:
7 * - Implements the Bootable Interface as follows.
8 * - Add a `projectRoot` property to the Class
9 * - Adds an optional `bootOptions` property to the Class that can be used to
10 * store the Booter conventions.
11 * - Adds the `BootComponent` to the Class (which binds the Bootstrapper and default Booters)
12 * - Provides the `boot()` convenience method to call Bootstrapper.boot()
13 * - Provides the `booter()` convenience method to bind a Booter(s) to the Application
14 * - Override `component()` to call `mountComponentBooters`
15 * - Adds `mountComponentBooters` which binds Booters to the application from `component.booters[]`
16 *
17 * @param superClass - Application class
18 * @returns A new class that extends the super class with boot related methods
19 *
20 * @typeParam T - Type of the application class as the target for the mixin
21 */
22export declare function BootMixin<T extends MixinTarget<Application>>(superClass: T): {
23 new (...args: any[]): {
24 projectRoot: string;
25 bootOptions?: BootOptions | undefined;
26 booted: boolean;
27 /**
28 * Override to detect and warn about starting without booting.
29 */
30 start(): Promise<void>;
31 /**
32 * Convenience method to call bootstrapper.boot() by resolving bootstrapper
33 */
34 boot(): Promise<void>;
35 /**
36 * Given a N number of Booter Classes, this method binds them using the
37 * prefix and tag expected by the Bootstrapper.
38 *
39 * @param booterCls - Booter classes to bind to the Application
40 *
41 * @example
42 * ```ts
43 * app.booters(MyBooter, MyOtherBooter)
44 * ```
45 */
46 booters(...booterCls: Constructor<Booter>[]): Binding[];
47 /**
48 * Register a booter to boot a sub-application. See
49 * {@link createComponentApplicationBooterBinding} for more details.
50 *
51 * @param subApp - A sub-application with artifacts to be booted
52 * @param filter - A binding filter to select what bindings from the sub
53 * application should be added to the main application.
54 */
55 applicationBooter(subApp: Application & Bootable, filter?: BindingFilter | undefined): Binding<Booter>;
56 /**
57 * Override to ensure any Booter's on a Component are also mounted.
58 *
59 * @param component - The component to add.
60 *
61 * @example
62 * ```ts
63 *
64 * export class ProductComponent {
65 * booters = [ControllerBooter, RepositoryBooter];
66 * providers = {
67 * [AUTHENTICATION_STRATEGY]: AuthStrategy,
68 * [AUTHORIZATION_ROLE]: Role,
69 * };
70 * };
71 *
72 * app.component(ProductComponent);
73 * ```
74 */
75 component<C extends Component = Component>(componentCtor: Constructor<C>, nameOrOptions?: string | BindingFromClassOptions | undefined): Binding<C>;
76 /**
77 * Get an instance of a component and mount all it's
78 * booters. This function is intended to be used internally
79 * by component()
80 *
81 * @param component - The component to mount booters of
82 */
83 mountComponentBooters(componentInstanceOrClass: Constructor<unknown> | InstanceWithBooters): void;
84 readonly options: loopbackContext.ApplicationConfig;
85 readonly state: string;
86 controller: <T_1>(controllerCtor: loopbackContext.ControllerClass<T_1>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_1>;
87 server: <T_2 extends loopbackContext.Server>(ctor: Constructor<T_2>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_2>;
88 servers: <T_3 extends loopbackContext.Server>(ctors: Constructor<T_3>[]) => Binding<any>[];
89 getServer: <T_4 extends loopbackContext.Server>(target: string | Constructor<T_4>) => Promise<T_4>;
90 init: () => Promise<void>;
91 onInit: (fn: () => loopbackContext.ValueOrPromise<void>) => Binding<loopbackContext.LifeCycleObserver>;
92 onStart: (fn: () => loopbackContext.ValueOrPromise<void>) => Binding<loopbackContext.LifeCycleObserver>;
93 stop: () => Promise<void>;
94 onStop: (fn: () => loopbackContext.ValueOrPromise<void>) => Binding<loopbackContext.LifeCycleObserver>;
95 setMetadata: (metadata: loopbackContext.ApplicationMetadata) => void;
96 lifeCycleObserver: <T_5 extends loopbackContext.LifeCycleObserver>(ctor: Constructor<T_5>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_5>;
97 service: <S>(cls: loopbackContext.ServiceOrProviderClass<S>, nameOrOptions?: string | loopbackContext.ServiceOptions | undefined) => Binding<S>;
98 interceptor: (interceptor: loopbackContext.Interceptor | Constructor<loopbackContext.Provider<loopbackContext.Interceptor>>, nameOrOptions?: string | loopbackContext.InterceptorBindingOptions | undefined) => Binding<loopbackContext.Interceptor>;
99 readonly name: string;
100 readonly subscriptionManager: loopbackContext.ContextSubscriptionManager;
101 scope: BindingScope;
102 readonly parent: Context | undefined;
103 emitEvent: <T_6 extends loopbackContext.ContextEvent>(type: string, event: T_6) => void;
104 emitError: (err: unknown) => void;
105 bind: <ValueType = any>(key: loopbackContext.BindingAddress<ValueType>) => Binding<ValueType>;
106 add: (binding: Binding<unknown>) => Application;
107 configure: <ConfigValueType = any>(key?: loopbackContext.BindingAddress<unknown> | undefined) => Binding<ConfigValueType>;
108 getConfigAsValueOrPromise: <ConfigValueType_1>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => loopbackContext.ValueOrPromise<ConfigValueType_1 | undefined>;
109 getConfig: <ConfigValueType_2>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => Promise<ConfigValueType_2 | undefined>;
110 getConfigSync: <ConfigValueType_3>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => ConfigValueType_3 | undefined;
111 unbind: (key: loopbackContext.BindingAddress<unknown>) => boolean;
112 subscribe: (observer: loopbackContext.ContextEventObserver) => loopbackContext.Subscription;
113 unsubscribe: (observer: loopbackContext.ContextEventObserver) => boolean;
114 close: () => void;
115 isSubscribed: (observer: loopbackContext.ContextObserver) => boolean;
116 createView: <T_7 = unknown>(filter: BindingFilter, comparator?: loopbackContext.BindingComparator | undefined, options?: Omit<loopbackContext.ResolutionOptions, "session"> | undefined) => loopbackContext.ContextView<T_7>;
117 contains: (key: loopbackContext.BindingAddress<unknown>) => boolean;
118 isBound: (key: loopbackContext.BindingAddress<unknown>) => boolean;
119 getOwnerContext: (keyOrBinding: Readonly<Binding<unknown>> | loopbackContext.BindingAddress<unknown>) => Context | undefined;
120 getScopedContext: (scope: BindingScope.APPLICATION | BindingScope.SERVER | BindingScope.REQUEST) => Context | undefined;
121 getResolutionContext: (binding: Readonly<Binding<unknown>>) => Context | undefined;
122 isVisibleTo: (ctx: Context) => boolean;
123 find: <ValueType_1 = any>(pattern?: string | RegExp | BindingFilter | undefined) => Readonly<Binding<ValueType_1>>[];
124 findByTag: <ValueType_2 = any>(tagFilter: RegExp | loopbackContext.BindingTag) => Readonly<Binding<ValueType_2>>[];
125 get: {
126 <ValueType_3>(keyWithPath: loopbackContext.BindingAddress<ValueType_3>, session?: loopbackContext.ResolutionSession | undefined): Promise<ValueType_3>;
127 <ValueType_4>(keyWithPath: loopbackContext.BindingAddress<ValueType_4>, options: loopbackContext.ResolutionOptions): Promise<ValueType_4 | undefined>;
128 };
129 getSync: {
130 <ValueType_5>(keyWithPath: loopbackContext.BindingAddress<ValueType_5>, session?: loopbackContext.ResolutionSession | undefined): ValueType_5;
131 <ValueType_6>(keyWithPath: loopbackContext.BindingAddress<ValueType_6>, options?: loopbackContext.ResolutionOptions | undefined): ValueType_6 | undefined;
132 };
133 getBinding: {
134 <ValueType_7 = any>(key: loopbackContext.BindingAddress<ValueType_7>): Binding<ValueType_7>;
135 <ValueType_8>(key: loopbackContext.BindingAddress<ValueType_8>, options?: {
136 optional?: boolean | undefined;
137 } | undefined): Binding<ValueType_8> | undefined;
138 };
139 findOrCreateBinding: <T_8>(key: loopbackContext.BindingAddress<T_8>, policy?: loopbackContext.BindingCreationPolicy | undefined) => Binding<T_8>;
140 getValueOrPromise: <ValueType_9>(keyWithPath: loopbackContext.BindingAddress<ValueType_9>, optionsOrSession?: loopbackContext.ResolutionOptionsOrSession | undefined) => loopbackContext.ValueOrPromise<ValueType_9 | undefined>;
141 toJSON: () => loopbackContext.JSONObject;
142 inspect: (options?: loopbackContext.ContextInspectOptions | undefined) => loopbackContext.JSONObject;
143 on: {
144 (eventName: "bind" | "unbind", listener: loopbackContext.ContextEventListener): Application;
145 (event: string | symbol, listener: (...args: any[]) => void): Application;
146 };
147 once: {
148 (eventName: "bind" | "unbind", listener: loopbackContext.ContextEventListener): Application;
149 (event: string | symbol, listener: (...args: any[]) => void): Application;
150 };
151 addListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
152 removeListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
153 off: (event: string | symbol, listener: (...args: any[]) => void) => Application;
154 removeAllListeners: (event?: string | symbol | undefined) => Application;
155 setMaxListeners: (n: number) => Application;
156 getMaxListeners: () => number;
157 listeners: (event: string | symbol) => Function[];
158 rawListeners: (event: string | symbol) => Function[];
159 emit: (event: string | symbol, ...args: any[]) => boolean;
160 listenerCount: (type: string | symbol) => number;
161 prependListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
162 prependOnceListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
163 eventNames: () => (string | symbol)[];
164 };
165} & T;
166/**
167 * Method which binds a given Booter to a given Context with the Prefix and
168 * Tags expected by the Bootstrapper
169 *
170 * @param ctx - The Context to bind the Booter Class
171 * @param booterCls - Booter class to be bound
172 */
173export declare function bindBooter(ctx: Context, booterCls: Constructor<Booter>): Binding;
174export declare const _bindBooter: typeof bindBooter;