import { Application, Binding, BindingFromClassOptions, BindingScope, Component, Constructor, MixinTarget } from '@loopback/core'; import { Class } from '../common-types'; import { SchemaMigrationOptions } from '../datasource'; import { Model } from '../model'; import { juggler, Repository } from '../repositories'; /** * A mixin class for Application that creates a .repository() * function to register a repository automatically. Also overrides * component function to allow it to register repositories automatically. * * @example * ```ts * class MyApplication extends RepositoryMixin(Application) {} * ``` * * Please note: the members in the mixin function are documented in a dummy class * called RepositoryMixinDoc * * @param superClass - Application class * @returns A new class that extends the super class with repository related * methods * * @typeParam T - Type of the application class as the target for the mixin * */ export declare function RepositoryMixin>(superClass: T): { new (...args: any[]): { /** * Add a repository to this application. * * @param repoClass - The repository to add. * @param nameOrOptions - Name or options for the binding * * @example * ```ts * * class NoteRepo { * model: any; * * constructor() { * const ds: juggler.DataSource = new juggler.DataSource({ * name: 'db', * connector: 'memory', * }); * * this.model = ds.createModel( * 'note', * {title: 'string', content: 'string'}, * {} * ); * } * }; * * app.repository(NoteRepo); * ``` */ repository>(repoClass: Class, nameOrOptions?: string | BindingFromClassOptions): Binding; /** * Retrieve the repository instance from the given Repository class * * @param repo - The repository class to retrieve the instance of */ getRepository>(repo: Class): Promise; /** * Add the dataSource to this application. * * @param dataSource - The dataSource to add. * @param nameOrOptions - The binding name or options of the datasource; * defaults to dataSource.name * * @example * ```ts * * const ds: juggler.DataSource = new juggler.DataSource({ * name: 'db', * connector: 'memory', * }); * * app.dataSource(ds); * * // The datasource can be injected with * constructor(@inject('datasources.db') dataSource: DataSourceType) { * * } * ``` */ dataSource(dataSource: D | Class, nameOrOptions?: string | BindingFromClassOptions): Binding; /** * Register a model class as a binding in the target context * @param modelClass - Model class */ model>(modelClass: M): Binding; /** * Add a component to this application. Also mounts * all the components repositories. * * @param component - The component to add. * @param nameOrOptions - Name or options for the binding. * * @example * ```ts * * export class ProductComponent { * controllers = [ProductController]; * repositories = [ProductRepo, UserRepo]; * providers = { * [AUTHENTICATION_STRATEGY]: AuthStrategy, * [AUTHORIZATION_ROLE]: Role, * }; * }; * * app.component(ProductComponent); * ``` */ component(componentCtor: Constructor, nameOrOptions?: string | BindingFromClassOptions): Binding; /** * Get an instance of a component and mount all it's * repositories. This function is intended to be used internally * by `component()`. * * NOTE: Calling `mountComponentRepositories` with a component class * constructor is deprecated. You should instantiate the component * yourself and provide the component instance instead. * * @param componentInstanceOrClass - The component to mount repositories of * @internal */ mountComponentRepositories(componentInstanceOrClass: Class | RepositoryComponent): void; /** * Bind all model classes provided by a component. * @param component * @internal */ mountComponentModels(component: RepositoryComponent): void; /** * Update or recreate the database schema for all repositories. * * **WARNING**: By default, `migrateSchema()` will attempt to preserve data * while updating the schema in your target database, but this is not * guaranteed to be safe. * * Please check the documentation for your specific connector(s) for * a detailed breakdown of behaviors for automigrate! * * @param options - Migration options, e.g. whether to update tables * preserving data or rebuild everything from scratch. */ migrateSchema(options?: SchemaMigrationOptions): Promise; readonly options: import("@loopback/core").ApplicationConfig; readonly state: string; controller: (controllerCtor: import("@loopback/core").ControllerClass, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding; server: (ctor: Constructor, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding; servers: (ctors: Constructor[]) => Binding[]; getServer: (target: string | Constructor) => Promise; init: () => Promise; onInit: (fn: () => import("@loopback/core").ValueOrPromise) => Binding; start: () => Promise; onStart: (fn: () => import("@loopback/core").ValueOrPromise) => Binding; stop: () => Promise; onStop: (fn: () => import("@loopback/core").ValueOrPromise) => Binding; setMetadata: (metadata: import("@loopback/core").ApplicationMetadata) => void; lifeCycleObserver: (ctor: Constructor, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding; service: (cls: import("@loopback/core").ServiceOrProviderClass, nameOrOptions?: string | import("@loopback/core").ServiceOptions | undefined) => Binding; interceptor: (interceptor: import("@loopback/core").Interceptor | Constructor>, nameOrOptions?: string | import("@loopback/core").InterceptorBindingOptions | undefined) => Binding; readonly name: string; readonly subscriptionManager: import("@loopback/core").ContextSubscriptionManager; scope: BindingScope; readonly parent: import("@loopback/core").Context | undefined; emitEvent: (type: string, event: T_6) => void; emitError: (err: unknown) => void; bind: (key: import("@loopback/core").BindingAddress) => Binding; add: (binding: Binding) => Application; configure: (key?: import("@loopback/core").BindingAddress | undefined) => Binding; getConfigAsValueOrPromise: (key: import("@loopback/core").BindingAddress, propertyPath?: string | undefined, resolutionOptions?: import("@loopback/core").ResolutionOptions | undefined) => import("@loopback/core").ValueOrPromise; getConfig: (key: import("@loopback/core").BindingAddress, propertyPath?: string | undefined, resolutionOptions?: import("@loopback/core").ResolutionOptions | undefined) => Promise; getConfigSync: (key: import("@loopback/core").BindingAddress, propertyPath?: string | undefined, resolutionOptions?: import("@loopback/core").ResolutionOptions | undefined) => ConfigValueType_3 | undefined; unbind: (key: import("@loopback/core").BindingAddress) => boolean; subscribe: (observer: import("@loopback/core").ContextEventObserver) => import("@loopback/core").Subscription; unsubscribe: (observer: import("@loopback/core").ContextEventObserver) => boolean; close: () => void; isSubscribed: (observer: import("@loopback/core").ContextObserver) => boolean; createView: (filter: import("@loopback/core").BindingFilter, comparator?: import("@loopback/core").BindingComparator | undefined, options?: Omit | undefined) => import("@loopback/core").ContextView; contains: (key: import("@loopback/core").BindingAddress) => boolean; isBound: (key: import("@loopback/core").BindingAddress) => boolean; getOwnerContext: (keyOrBinding: import("@loopback/core").BindingAddress | Readonly>) => import("@loopback/core").Context | undefined; getScopedContext: (scope: BindingScope.APPLICATION | BindingScope.SERVER | BindingScope.REQUEST) => import("@loopback/core").Context | undefined; getResolutionContext: (binding: Readonly>) => import("@loopback/core").Context | undefined; isVisibleTo: (ctx: import("@loopback/core").Context) => boolean; find: (pattern?: string | RegExp | import("@loopback/core").BindingFilter | undefined) => Readonly>[]; findByTag: (tagFilter: RegExp | import("@loopback/core").BindingTag) => Readonly>[]; get: { (keyWithPath: import("@loopback/core").BindingAddress, session?: import("@loopback/core").ResolutionSession | undefined): Promise; (keyWithPath: import("@loopback/core").BindingAddress, options: import("@loopback/core").ResolutionOptions): Promise; }; getSync: { (keyWithPath: import("@loopback/core").BindingAddress, session?: import("@loopback/core").ResolutionSession | undefined): ValueType_5; (keyWithPath: import("@loopback/core").BindingAddress, options?: import("@loopback/core").ResolutionOptions | undefined): ValueType_6 | undefined; }; getBinding: { (key: import("@loopback/core").BindingAddress): Binding; (key: import("@loopback/core").BindingAddress, options?: { optional?: boolean | undefined; } | undefined): Binding | undefined; }; findOrCreateBinding: (key: import("@loopback/core").BindingAddress, policy?: import("@loopback/core").BindingCreationPolicy | undefined) => Binding; getValueOrPromise: (keyWithPath: import("@loopback/core").BindingAddress, optionsOrSession?: import("@loopback/core").ResolutionOptionsOrSession | undefined) => import("@loopback/core").ValueOrPromise; toJSON: () => import("@loopback/core").JSONObject; inspect: (options?: import("@loopback/core").ContextInspectOptions | undefined) => import("@loopback/core").JSONObject; on: { (eventName: "bind" | "unbind", listener: import("@loopback/core").ContextEventListener): Application; (event: string | symbol, listener: (...args: any[]) => void): Application; }; once: { (eventName: "bind" | "unbind", listener: import("@loopback/core").ContextEventListener): Application; (event: string | symbol, listener: (...args: any[]) => void): Application; }; addListener: (event: string | symbol, listener: (...args: any[]) => void) => Application; removeListener: (event: string | symbol, listener: (...args: any[]) => void) => Application; off: (event: string | symbol, listener: (...args: any[]) => void) => Application; removeAllListeners: (event?: string | symbol | undefined) => Application; setMaxListeners: (n: number) => Application; getMaxListeners: () => number; listeners: (event: string | symbol) => Function[]; rawListeners: (event: string | symbol) => Function[]; emit: (event: string | symbol, ...args: any[]) => boolean; listenerCount: (event: string | symbol) => number; prependListener: (event: string | symbol, listener: (...args: any[]) => void) => Application; prependOnceListener: (event: string | symbol, listener: (...args: any[]) => void) => Application; eventNames: () => (string | symbol)[]; }; } & T; /** * This interface describes additional Component properties * allowing components to contribute Repository-related artifacts. */ export interface RepositoryComponent { /** * An optional list of Repository classes to bind for dependency injection * via `app.repository()` API. */ repositories?: Class>[]; /** * An optional list of Model classes to bind for dependency injection * via `app.model()` API. */ models?: Class[]; } /** * Interface for an Application mixed in with RepositoryMixin */ export interface ApplicationWithRepositories extends Application { repository>(repo: Class, name?: string): Binding; getRepository>(repo: Class): Promise; dataSource(dataSource: Class | D, name?: string): Binding; model>(modelClass: M): Binding; component(component: Class, name?: string): Binding; mountComponentRepositories(component: Class): void; migrateSchema(options?: SchemaMigrationOptions): Promise; } /** * A dummy class created to generate the tsdoc for the members in repository * mixin. Please don't use it. * * The members are implemented in function * RepositoryMixin */ export declare class RepositoryMixinDoc { constructor(...args: any[]); /** * Add a repository to this application. * * @param repo - The repository to add. * * @example * ```ts * * class NoteRepo { * model: any; * * constructor() { * const ds: juggler.DataSource = new juggler.DataSource({ * name: 'db', * connector: 'memory', * }); * * this.model = ds.createModel( * 'note', * {title: 'string', content: 'string'}, * {} * ); * } * }; * * app.repository(NoteRepo); * ``` */ repository(repo: Class>): Binding; /** * Retrieve the repository instance from the given Repository class * * @param repo - The repository class to retrieve the instance of */ getRepository>(repo: Class): Promise; /** * Add the dataSource to this application. * * @param dataSource - The dataSource to add. * @param name - The binding name of the datasource; defaults to dataSource.name * * @example * ```ts * * const ds: juggler.DataSource = new juggler.DataSource({ * name: 'db', * connector: 'memory', * }); * * app.dataSource(ds); * * // The datasource can be injected with * constructor(@inject('datasources.db') dataSource: DataSourceType) { * * } * ``` */ dataSource(dataSource: Class | juggler.DataSource, name?: string): Binding; /** * Add a component to this application. Also mounts * all the components repositories. * * @param component - The component to add. * * @example * ```ts * * export class ProductComponent { * controllers = [ProductController]; * repositories = [ProductRepo, UserRepo]; * providers = { * [AUTHENTICATION_STRATEGY]: AuthStrategy, * [AUTHORIZATION_ROLE]: Role, * }; * }; * * app.component(ProductComponent); * ``` */ component(component: Class<{}>): Binding; /** * Get an instance of a component and mount all it's * repositories. This function is intended to be used internally * by component() * * @param component - The component to mount repositories of */ mountComponentRepository(component: Class<{}>): void; /** * Update or recreate the database schema for all repositories. * * **WARNING**: By default, `migrateSchema()` will attempt to preserve data * while updating the schema in your target database, but this is not * guaranteed to be safe. * * Please check the documentation for your specific connector(s) for * a detailed breakdown of behaviors for automigrate! * * @param options - Migration options, e.g. whether to update tables * preserving data or rebuild everything from scratch. */ migrateSchema(options?: SchemaMigrationOptions): Promise; } /** * Create a binding for the given model class * @param modelClass - Model class */ export declare function createModelClassBinding>(modelClass: M): Binding;