UNPKG

3.52 kBTypeScriptView Raw
1import { Class } from '../common-types';
2import { DataSource } from '../datasource';
3import { Entity, Model } from '../model';
4import { Repository } from '../repositories';
5import { juggler } from '../repositories/legacy-juggler-bridge';
6/**
7 * Type definition for decorators returned by `@repository` decorator factory
8 */
9export declare type RepositoryDecorator = (target: Object, key?: string, descriptorOrIndex?: TypedPropertyDescriptor<any> | number) => void;
10/**
11 * Metadata for a repository
12 */
13export declare class RepositoryMetadata {
14 /**
15 * Name of the predefined repository
16 */
17 name?: string;
18 /**
19 * Name of the model
20 */
21 modelName?: string;
22 /**
23 * Class of the model
24 */
25 modelClass?: typeof Entity;
26 /**
27 * Name of the data source
28 */
29 dataSourceName?: string;
30 /**
31 * Instance of the data source
32 */
33 dataSource?: juggler.DataSource | DataSource;
34 /**
35 * Constructor for RepositoryMetadata
36 *
37 * @param modelOrRepo - Name or class of the model. If the value is a string and
38 * `dataSource` is not present, it will treated as the name of a predefined
39 * repository
40 * @param dataSource - Name or instance of the data source
41 *
42 * For example:
43 *
44 * - new RepositoryMetadata(repoName);
45 * - new RepositoryMetadata(modelName, dataSourceName);
46 * - new RepositoryMetadata(modelClass, dataSourceInstance);
47 * - new RepositoryMetadata(modelName, dataSourceInstance);
48 * - new RepositoryMetadata(modelClass, dataSourceName);
49 */
50 constructor(modelOrRepo: string | typeof Entity, dataSource?: string | juggler.DataSource | DataSource);
51}
52/**
53 * Decorator for repository injections on properties or method arguments
54 *
55 * @example
56 * ```ts
57 * class CustomerController {
58 * @repository(CustomerRepository) public custRepo: CustomerRepository;
59 *
60 * constructor(
61 * @repository(ProductRepository) public prodRepo: ProductRepository,
62 * ) {}
63 * // ...
64 * }
65 * ```
66 *
67 * @param repositoryName - Name of the repo
68 */
69export declare function repository(repositoryName: string | Class<Repository<Model>>): RepositoryDecorator;
70/**
71 * Decorator for DefaultCrudRepository generation and injection on properties
72 * or method arguments based on the given model and dataSource (or their names)
73 *
74 * @example
75 * ```ts
76 * class CustomerController {
77 * @repository('Customer', 'mySqlDataSource')
78 * public custRepo: DefaultCrudRepository<
79 * Customer,
80 * typeof Customer.prototype.id
81 * >;
82 *
83 * constructor(
84 * @repository(Product, mySqlDataSource)
85 * public prodRepo: DefaultCrudRepository<
86 * Product,
87 * typeof Product.prototype.id
88 * >,
89 * ) {}
90 * // ...
91 * }
92 * ```
93 *
94 * @param model - Name/class of the model
95 * @param dataSource - Name/instance of the dataSource
96 */
97export declare function repository(model: string | typeof Entity, dataSource: string | juggler.DataSource): RepositoryDecorator;
98export declare namespace repository {
99 /**
100 * Decorator used to inject a Getter for a repository
101 * Mainly intended for usage with repository injections on relation repository
102 * factory
103 * @param nameOrClass - The repository class (ProductRepository) or a string name ('ProductRepository').
104 */
105 function getter(nameOrClass: string | Class<Repository<Model>>): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
106}
107
\No newline at end of file