1 | import { Application, Binding, BindingFromClassOptions, BindingScope, Component, Constructor, MixinTarget } from '@loopback/core';
|
2 | import { Class } from '../common-types';
|
3 | import { SchemaMigrationOptions } from '../datasource';
|
4 | import { Model } from '../model';
|
5 | import { juggler, Repository } from '../repositories';
|
6 | import * as loopbackContext from '@loopback/core';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | export declare function RepositoryMixin<T extends MixinTarget<Application>>(superClass: T): {
|
28 | new (...args: any[]): {
|
29 | |
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | repository<R extends Repository<any>>(repoClass: Class<R>, nameOrOptions?: string | BindingFromClassOptions | undefined): Binding<R>;
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 | getRepository<R_1 extends Repository<any>>(repo: Class<R_1>): Promise<R_1>;
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | dataSource<D extends juggler.DataSource>(dataSource: D | Class<D>, nameOrOptions?: string | BindingFromClassOptions | undefined): Binding<D>;
|
89 | |
90 |
|
91 |
|
92 |
|
93 | model<M extends Class<unknown>>(modelClass: M): Binding<M>;
|
94 | |
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | component<C extends Component = Component>(componentCtor: Constructor<C>, nameOrOptions?: string | BindingFromClassOptions | undefined): Binding<C>;
|
117 | |
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | mountComponentRepositories(componentInstanceOrClass: Class<unknown> | RepositoryComponent): void;
|
130 | |
131 |
|
132 |
|
133 |
|
134 |
|
135 | mountComponentModels(component: RepositoryComponent): void;
|
136 | |
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 | migrateSchema(options?: SchemaMigrationOptions): Promise<void>;
|
150 | readonly options: loopbackContext.ApplicationConfig;
|
151 | readonly state: string;
|
152 | controller: <T_1>(controllerCtor: loopbackContext.ControllerClass<T_1>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_1>;
|
153 | server: <T_2 extends loopbackContext.Server>(ctor: Constructor<T_2>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_2>;
|
154 | servers: <T_3 extends loopbackContext.Server>(ctors: Constructor<T_3>[]) => Binding<any>[];
|
155 | getServer: <T_4 extends loopbackContext.Server>(target: string | Constructor<T_4>) => Promise<T_4>;
|
156 | init: () => Promise<void>;
|
157 | onInit: (fn: () => loopbackContext.ValueOrPromise<void>) => Binding<loopbackContext.LifeCycleObserver>;
|
158 | start: () => Promise<void>;
|
159 | onStart: (fn: () => loopbackContext.ValueOrPromise<void>) => Binding<loopbackContext.LifeCycleObserver>;
|
160 | stop: () => Promise<void>;
|
161 | onStop: (fn: () => loopbackContext.ValueOrPromise<void>) => Binding<loopbackContext.LifeCycleObserver>;
|
162 | setMetadata: (metadata: loopbackContext.ApplicationMetadata) => void;
|
163 | lifeCycleObserver: <T_5 extends loopbackContext.LifeCycleObserver>(ctor: Constructor<T_5>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_5>;
|
164 | service: <S>(cls: loopbackContext.ServiceOrProviderClass<S>, nameOrOptions?: string | loopbackContext.ServiceOptions | undefined) => Binding<S>;
|
165 | interceptor: (interceptor: loopbackContext.Interceptor | Constructor<loopbackContext.Provider<loopbackContext.Interceptor>>, nameOrOptions?: string | loopbackContext.InterceptorBindingOptions | undefined) => Binding<loopbackContext.Interceptor>;
|
166 | readonly name: string;
|
167 | readonly subscriptionManager: loopbackContext.ContextSubscriptionManager;
|
168 | scope: BindingScope;
|
169 | readonly parent: loopbackContext.Context | undefined;
|
170 | emitEvent: <T_6 extends loopbackContext.ContextEvent>(type: string, event: T_6) => void;
|
171 | emitError: (err: unknown) => void;
|
172 | bind: <ValueType = any>(key: loopbackContext.BindingAddress<ValueType>) => Binding<ValueType>;
|
173 | add: (binding: Binding<unknown>) => Application;
|
174 | configure: <ConfigValueType = any>(key?: loopbackContext.BindingAddress<unknown> | undefined) => Binding<ConfigValueType>;
|
175 | getConfigAsValueOrPromise: <ConfigValueType_1>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => loopbackContext.ValueOrPromise<ConfigValueType_1 | undefined>;
|
176 | getConfig: <ConfigValueType_2>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => Promise<ConfigValueType_2 | undefined>;
|
177 | getConfigSync: <ConfigValueType_3>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => ConfigValueType_3 | undefined;
|
178 | unbind: (key: loopbackContext.BindingAddress<unknown>) => boolean;
|
179 | subscribe: (observer: loopbackContext.ContextEventObserver) => loopbackContext.Subscription;
|
180 | unsubscribe: (observer: loopbackContext.ContextEventObserver) => boolean;
|
181 | close: () => void;
|
182 | isSubscribed: (observer: loopbackContext.ContextObserver) => boolean;
|
183 | createView: <T_7 = unknown>(filter: loopbackContext.BindingFilter, comparator?: loopbackContext.BindingComparator | undefined, options?: Omit<loopbackContext.ResolutionOptions, "session"> | undefined) => loopbackContext.ContextView<T_7>;
|
184 | contains: (key: loopbackContext.BindingAddress<unknown>) => boolean;
|
185 | isBound: (key: loopbackContext.BindingAddress<unknown>) => boolean;
|
186 | getOwnerContext: (keyOrBinding: loopbackContext.BindingAddress<unknown> | Readonly<Binding<unknown>>) => loopbackContext.Context | undefined;
|
187 | getScopedContext: (scope: BindingScope.APPLICATION | BindingScope.SERVER | BindingScope.REQUEST) => loopbackContext.Context | undefined;
|
188 | getResolutionContext: (binding: Readonly<Binding<unknown>>) => loopbackContext.Context | undefined;
|
189 | isVisibleTo: (ctx: loopbackContext.Context) => boolean;
|
190 | find: <ValueType_1 = any>(pattern?: string | RegExp | loopbackContext.BindingFilter | undefined) => Readonly<Binding<ValueType_1>>[];
|
191 | findByTag: <ValueType_2 = any>(tagFilter: RegExp | loopbackContext.BindingTag) => Readonly<Binding<ValueType_2>>[];
|
192 | get: {
|
193 | <ValueType_3>(keyWithPath: loopbackContext.BindingAddress<ValueType_3>, session?: loopbackContext.ResolutionSession | undefined): Promise<ValueType_3>;
|
194 | <ValueType_4>(keyWithPath: loopbackContext.BindingAddress<ValueType_4>, options: loopbackContext.ResolutionOptions): Promise<ValueType_4 | undefined>;
|
195 | };
|
196 | getSync: {
|
197 | <ValueType_5>(keyWithPath: loopbackContext.BindingAddress<ValueType_5>, session?: loopbackContext.ResolutionSession | undefined): ValueType_5;
|
198 | <ValueType_6>(keyWithPath: loopbackContext.BindingAddress<ValueType_6>, options?: loopbackContext.ResolutionOptions | undefined): ValueType_6 | undefined;
|
199 | };
|
200 | getBinding: {
|
201 | <ValueType_7 = any>(key: loopbackContext.BindingAddress<ValueType_7>): Binding<ValueType_7>;
|
202 | <ValueType_8>(key: loopbackContext.BindingAddress<ValueType_8>, options?: {
|
203 | optional?: boolean | undefined;
|
204 | } | undefined): Binding<ValueType_8> | undefined;
|
205 | };
|
206 | findOrCreateBinding: <T_8>(key: loopbackContext.BindingAddress<T_8>, policy?: loopbackContext.BindingCreationPolicy | undefined) => Binding<T_8>;
|
207 | getValueOrPromise: <ValueType_9>(keyWithPath: loopbackContext.BindingAddress<ValueType_9>, optionsOrSession?: loopbackContext.ResolutionOptionsOrSession | undefined) => loopbackContext.ValueOrPromise<ValueType_9 | undefined>;
|
208 | toJSON: () => loopbackContext.JSONObject;
|
209 | inspect: (options?: loopbackContext.ContextInspectOptions | undefined) => loopbackContext.JSONObject;
|
210 | on: {
|
211 | (eventName: "bind" | "unbind", listener: loopbackContext.ContextEventListener): Application;
|
212 | (event: string | symbol, listener: (...args: any[]) => void): Application;
|
213 | };
|
214 | once: {
|
215 | (eventName: "bind" | "unbind", listener: loopbackContext.ContextEventListener): Application;
|
216 | (event: string | symbol, listener: (...args: any[]) => void): Application;
|
217 | };
|
218 | addListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
|
219 | removeListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
|
220 | off: (event: string | symbol, listener: (...args: any[]) => void) => Application;
|
221 | removeAllListeners: (event?: string | symbol | undefined) => Application;
|
222 | setMaxListeners: (n: number) => Application;
|
223 | getMaxListeners: () => number;
|
224 | listeners: (event: string | symbol) => Function[];
|
225 | rawListeners: (event: string | symbol) => Function[];
|
226 | emit: (event: string | symbol, ...args: any[]) => boolean;
|
227 | listenerCount: (type: string | symbol) => number;
|
228 | prependListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
|
229 | prependOnceListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
|
230 | eventNames: () => (string | symbol)[];
|
231 | };
|
232 | } & T;
|
233 |
|
234 |
|
235 |
|
236 |
|
237 | export interface RepositoryComponent {
|
238 | |
239 |
|
240 |
|
241 |
|
242 | repositories?: Class<Repository<Model>>[];
|
243 | |
244 |
|
245 |
|
246 |
|
247 | models?: Class<Model>[];
|
248 | }
|
249 |
|
250 |
|
251 |
|
252 | export interface ApplicationWithRepositories extends Application {
|
253 | repository<R extends Repository<any>>(repo: Class<R>, name?: string): Binding<R>;
|
254 | getRepository<R extends Repository<any>>(repo: Class<R>): Promise<R>;
|
255 | dataSource<D extends juggler.DataSource>(dataSource: Class<D> | D, name?: string): Binding<D>;
|
256 | model<M extends Class<unknown>>(modelClass: M): Binding<M>;
|
257 | component(component: Class<unknown>, name?: string): Binding;
|
258 | mountComponentRepositories(component: Class<unknown>): void;
|
259 | migrateSchema(options?: SchemaMigrationOptions): Promise<void>;
|
260 | }
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 | export declare class RepositoryMixinDoc {
|
269 | constructor(...args: any[]);
|
270 | /**
|
271 | * Add a repository to this application.
|
272 | *
|
273 | * @param repo - The repository to add.
|
274 | *
|
275 | * @example
|
276 | * ```ts
|
277 | *
|
278 | * class NoteRepo {
|
279 | * model: any;
|
280 | *
|
281 | * constructor() {
|
282 | * const ds: juggler.DataSource = new juggler.DataSource({
|
283 | * name: 'db',
|
284 | * connector: 'memory',
|
285 | * });
|
286 | *
|
287 | * this.model = ds.createModel(
|
288 | * 'note',
|
289 | * {title: 'string', content: 'string'},
|
290 | * {}
|
291 | * );
|
292 | * }
|
293 | * };
|
294 | *
|
295 | * app.repository(NoteRepo);
|
296 | * ```
|
297 | */
|
298 | repository(repo: Class<Repository<any>>): Binding;
|
299 | /**
|
300 | * Retrieve the repository instance from the given Repository class
|
301 | *
|
302 | * @param repo - The repository class to retrieve the instance of
|
303 | */
|
304 | getRepository<R extends Repository<any>>(repo: Class<R>): Promise<R>;
|
305 | /**
|
306 | * Add the dataSource to this application.
|
307 | *
|
308 | * @param dataSource - The dataSource to add.
|
309 | * @param name - The binding name of the datasource; defaults to dataSource.name
|
310 | *
|
311 | * @example
|
312 | * ```ts
|
313 | *
|
314 | * const ds: juggler.DataSource = new juggler.DataSource({
|
315 | * name: 'db',
|
316 | * connector: 'memory',
|
317 | * });
|
318 | *
|
319 | * app.dataSource(ds);
|
320 | *
|
321 | *
|
322 | * constructor(@inject('datasources.db') dataSource: DataSourceType) {
|
323 | *
|
324 | * }
|
325 | * ```
|
326 | */
|
327 | dataSource(dataSource: Class<juggler.DataSource> | juggler.DataSource, name?: string): Binding;
|
328 | /**
|
329 | * Add a component to this application. Also mounts
|
330 | * all the components repositories.
|
331 | *
|
332 | * @param component - The component to add.
|
333 | *
|
334 | * @example
|
335 | * ```ts
|
336 | *
|
337 | * export class ProductComponent {
|
338 | * controllers = [ProductController];
|
339 | * repositories = [ProductRepo, UserRepo];
|
340 | * providers = {
|
341 | * [AUTHENTICATION_STRATEGY]: AuthStrategy,
|
342 | * [AUTHORIZATION_ROLE]: Role,
|
343 | * };
|
344 | * };
|
345 | *
|
346 | * app.component(ProductComponent);
|
347 | * ```
|
348 | */
|
349 | component(component: Class<{}>): Binding;
|
350 | /**
|
351 | * Get an instance of a component and mount all it's
|
352 | * repositories. This function is intended to be used internally
|
353 | * by component()
|
354 | *
|
355 | * @param component - The component to mount repositories of
|
356 | */
|
357 | mountComponentRepository(component: Class<{}>): void;
|
358 | /**
|
359 | * Update or recreate the database schema for all repositories.
|
360 | *
|
361 | * **WARNING**: By default, `migrateSchema()` will attempt to preserve data
|
362 | * while updating the schema in your target database, but this is not
|
363 | * guaranteed to be safe.
|
364 | *
|
365 | * Please check the documentation for your specific connector(s) for
|
366 | * a detailed breakdown of behaviors for automigrate!
|
367 | *
|
368 | * @param options - Migration options, e.g. whether to update tables
|
369 | * preserving data or rebuild everything from scratch.
|
370 | */
|
371 | migrateSchema(options?: SchemaMigrationOptions): Promise<void>;
|
372 | }
|
373 | /**
|
374 | * Create a binding for the given model class
|
375 | * @param modelClass - Model class
|
376 | */
|
377 | export declare function createModelClassBinding<M extends Class<unknown>>(modelClass: M): Binding<M>;
|
378 |
|
\ | No newline at end of file |