1 | import { Class } from './common-types';
|
2 | /**
|
3 | * A type resolver is a function that returns a class representing the type,
|
4 | * typically a Model or Entity (e.g. Product).
|
5 | *
|
6 | * We use type resolvers to break require() loops when defining relations.
|
7 | * The target model (class) is provided via a provider, thus deferring
|
8 | * the actual reference to the class itself until later, when both sides
|
9 | * of the relation are created as JavaScript classes.
|
10 | *
|
11 | * @typeParam Type - The type we are resolving, for example `Entity` or `Product`.
|
12 | * This parameter is required.
|
13 | *
|
14 | * @typeParam StaticMembers - The static properties available on the
|
15 | * type class. For example, all models have static `modelName` property.
|
16 | * When `StaticMembers` are not provided, we default to static properties of
|
17 | * a `Function` - `name`, `length`, `apply`, `call`, etc.
|
18 | * Please note the value returned by the resolver is described as having
|
19 | * arbitrary additional static properties (see how Class is defined).
|
20 | */
|
21 | export type TypeResolver<Type extends Object, StaticMembers = Function> = () => Class<Type> & StaticMembers;
|
22 | /**
|
23 | * A function that checks whether a function is a TypeResolver or not.
|
24 | * @param fn - The value to check.
|
25 | */
|
26 | export declare function isTypeResolver<T extends object>(fn: any): fn is TypeResolver<T>;
|
27 | /**
|
28 | * A boxed type for `null`
|
29 | */
|
30 | export declare function Null(): null;
|
31 | /**
|
32 | * Check if the provided function is a built-in type provided by JavaScript
|
33 | * and/or Node.js. E.g. `Number`, `Array`, `Buffer`, etc.
|
34 | */
|
35 | export declare function isBuiltinType(fn: Function): boolean;
|
36 | export type NonFunction<T> = T extends Function ? never : T;
|
37 | /**
|
38 | * Resolve a type value that may have been provided via TypeResolver.
|
39 | * @param fn - A type class or a type provider.
|
40 | * @returns The resolved type.
|
41 | */
|
42 | export declare function resolveType<T extends object>(fn: TypeResolver<T, {}> | Class<T> | Function): Class<T>;
|
43 | export declare function resolveType<T>(fn: NonFunction<T>): T;
|