UNPKG

4.78 kBTypeScriptView Raw
1import { AnyObject, Entity, EntityCrudRepository, Filter, InclusionFilter, Options } from '..';
2/**
3 * Finds model instances that contain any of the provided foreign key values.
4 *
5 * @param targetRepository - The target repository where the related model instances are found
6 * @param fkName - Name of the foreign key
7 * @param fkValues - One value or array of values of the foreign key to be included
8 * @param scope - Additional scope constraints
9 * @param options - Options for the operations
10 */
11export declare function findByForeignKeys<Target extends Entity, TargetRelations extends object, ForeignKey extends StringKeyOf<Target>>(targetRepository: EntityCrudRepository<Target, unknown, TargetRelations>, fkName: ForeignKey, fkValues: Target[ForeignKey][] | Target[ForeignKey], scope?: Filter<Target> & {
12 totalLimit?: number;
13}, options?: Options): Promise<(Target & TargetRelations)[]>;
14export type StringKeyOf<T> = Extract<keyof T, string>;
15/**
16 * Returns model instances that include related models that have a registered
17 * resolver.
18 *
19 * @param targetRepository - The target repository where the model instances are found
20 * @param entities - An array of entity instances or data
21 * @param include -Inclusion filter
22 * @param options - Options for the operations
23 */
24export declare function includeRelatedModels<T extends Entity, Relations extends object = {}>(targetRepository: EntityCrudRepository<T, unknown, Relations>, entities: T[], include?: InclusionFilter[], options?: Options): Promise<(T & Relations)[]>;
25/**
26 * Returns an array of instances. The order of arrays is based on
27 * the order of sourceIds
28 *
29 * @param sourceIds - One value or array of values of the target key
30 * @param targetEntities - target entities that satisfy targetKey's value (ids).
31 * @param targetKey - name of the target key
32 *
33 */
34export declare function flattenTargetsOfOneToOneRelation<Target extends Entity>(sourceIds: unknown[], targetEntities: Target[], targetKey: StringKeyOf<Target>): (Target | undefined)[];
35/**
36 * Returns an array of instances. The order of arrays is based on
37 * as a result of one to many relation. The order of arrays is based on
38 * the order of sourceIds
39 *
40 * @param sourceIds - One value or array of values of the target key
41 * @param targetEntities - target entities that satisfy targetKey's value (ids).
42 * @param targetKey - name of the target key
43 *
44 */
45export declare function flattenTargetsOfOneToManyRelation<Target extends Entity>(sourceIds: unknown[], targetEntities: Target[], targetKey: StringKeyOf<Target>): (Target[] | undefined)[];
46/**
47 * Returns an array of instances from the target map. The order of arrays is based on
48 * the order of sourceIds
49 *
50 * @param sourceIds - One value or array of values (of the target key)
51 * @param targetMap - a map that matches sourceIds with instances
52 */
53export declare function flattenMapByKeys<T>(sourceIds: unknown[], targetMap: Map<unknown, T>): (T | undefined)[];
54/**
55 * Returns a map which maps key values(ids) to instances. The instances can be
56 * grouped by different strategies.
57 *
58 * @param list - an array of instances
59 * @param keyName - key name of the source
60 * @param reducer - a strategy to reduce inputs to single item or array
61 */
62export declare function buildLookupMap<Key, InType extends object, OutType = InType>(list: InType[], keyName: StringKeyOf<InType>, reducer: (accumulator: OutType | undefined, current: InType) => OutType): Map<Key, OutType>;
63/**
64 * Returns value of a keyName. Aims to resolve ObjectId problem of Mongo.
65 *
66 * @param model - target model
67 * @param keyName - target key that gets the value from
68 */
69export declare function getKeyValue(model: AnyObject, keyName: string): unknown;
70/**
71 * Workaround for MongoDB, where the connector returns ObjectID
72 * values even for properties configured with "type: string".
73 *
74 * @param rawKey
75 */
76export declare function normalizeKey(rawKey: unknown): unknown;
77/**
78 * Returns an array of instances. For HasMany relation usage.
79 *
80 * @param acc
81 * @param it
82 */
83export declare function reduceAsArray<T>(acc: T[] | undefined, it: T): T[];
84/**
85 * Returns a single of an instance. For HasOne and BelongsTo relation usage.
86 *
87 * @param _acc
88 * @param it
89 */
90export declare function reduceAsSingleItem<T>(_acc: T | undefined, it: T): T;
91/**
92 * Dedupe an array
93 * @param input - an array of sourceIds
94 * @returns an array with unique items
95 */
96export declare function deduplicate<T>(input: T[]): T[];
97/**
98 * Checks if the value is BsonType (mongodb)
99 * It uses a general way to check the type ,so that it can detect
100 * different versions of bson that might be used in the code base.
101 * Might need to update in the future.
102 *
103 * @param value
104 */
105export declare function isBsonType(value: unknown): value is object;