bigal 12.1.5 → 13.0.0-beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/devcontainer.json +16 -0
- package/.husky/pre-commit +4 -0
- package/.prettierrc.cjs +34 -0
- package/CHANGELOG.md +5 -0
- package/dist/index.cjs +2626 -0
- package/dist/index.d.cts +892 -0
- package/dist/index.d.mts +892 -0
- package/dist/index.d.ts +892 -0
- package/dist/index.mjs +2605 -0
- package/eslint.config.mjs +25 -0
- package/package.json +44 -35
- package/tsconfig.build.json +7 -0
- package/Entity.d.ts +0 -16
- package/Entity.js +0 -13
- package/Entity.js.map +0 -1
- package/IReadonlyRepository.d.ts +0 -36
- package/IReadonlyRepository.js +0 -3
- package/IReadonlyRepository.js.map +0 -1
- package/IRepository.d.ts +0 -99
- package/IRepository.js +0 -3
- package/IRepository.js.map +0 -1
- package/ReadonlyRepository.d.ts +0 -69
- package/ReadonlyRepository.js +0 -687
- package/ReadonlyRepository.js.map +0 -1
- package/Repository.d.ts +0 -69
- package/Repository.js +0 -171
- package/Repository.js.map +0 -1
- package/SqlHelper.d.ts +0 -144
- package/SqlHelper.js +0 -1081
- package/SqlHelper.js.map +0 -1
- package/decorators/ColumnBaseOptions.d.ts +0 -10
- package/decorators/ColumnBaseOptions.js +0 -3
- package/decorators/ColumnBaseOptions.js.map +0 -1
- package/decorators/ColumnCollectionOptions.d.ts +0 -15
- package/decorators/ColumnCollectionOptions.js +0 -3
- package/decorators/ColumnCollectionOptions.js.map +0 -1
- package/decorators/ColumnModelOptions.d.ts +0 -7
- package/decorators/ColumnModelOptions.js +0 -3
- package/decorators/ColumnModelOptions.js.map +0 -1
- package/decorators/ColumnTypeOptions.d.ts +0 -21
- package/decorators/ColumnTypeOptions.js +0 -3
- package/decorators/ColumnTypeOptions.js.map +0 -1
- package/decorators/TableOptions.d.ts +0 -14
- package/decorators/TableOptions.js +0 -3
- package/decorators/TableOptions.js.map +0 -1
- package/decorators/column.d.ts +0 -9
- package/decorators/column.js +0 -93
- package/decorators/column.js.map +0 -1
- package/decorators/createDateColumn.d.ts +0 -6
- package/decorators/createDateColumn.js +0 -50
- package/decorators/createDateColumn.js.map +0 -1
- package/decorators/index.d.ts +0 -6
- package/decorators/index.js +0 -23
- package/decorators/index.js.map +0 -1
- package/decorators/primaryColumn.d.ts +0 -8
- package/decorators/primaryColumn.js +0 -66
- package/decorators/primaryColumn.js.map +0 -1
- package/decorators/table.d.ts +0 -5
- package/decorators/table.js +0 -40
- package/decorators/table.js.map +0 -1
- package/decorators/updateDateColumn.d.ts +0 -6
- package/decorators/updateDateColumn.js +0 -51
- package/decorators/updateDateColumn.js.map +0 -1
- package/decorators/versionColumn.d.ts +0 -6
- package/decorators/versionColumn.js +0 -51
- package/decorators/versionColumn.js.map +0 -1
- package/errors/QueryError.d.ts +0 -8
- package/errors/QueryError.js +0 -13
- package/errors/QueryError.js.map +0 -1
- package/errors/index.d.ts +0 -1
- package/errors/index.js +0 -18
- package/errors/index.js.map +0 -1
- package/index.d.ts +0 -35
- package/index.js +0 -220
- package/index.js.map +0 -1
- package/metadata/ColumnBaseMetadata.d.ts +0 -93
- package/metadata/ColumnBaseMetadata.js +0 -19
- package/metadata/ColumnBaseMetadata.js.map +0 -1
- package/metadata/ColumnCollectionMetadata.d.ts +0 -36
- package/metadata/ColumnCollectionMetadata.js +0 -63
- package/metadata/ColumnCollectionMetadata.js.map +0 -1
- package/metadata/ColumnMetadata.d.ts +0 -4
- package/metadata/ColumnMetadata.js +0 -3
- package/metadata/ColumnMetadata.js.map +0 -1
- package/metadata/ColumnModelMetadata.d.ts +0 -18
- package/metadata/ColumnModelMetadata.js +0 -43
- package/metadata/ColumnModelMetadata.js.map +0 -1
- package/metadata/ColumnModifierMetadata.d.ts +0 -46
- package/metadata/ColumnModifierMetadata.js +0 -3
- package/metadata/ColumnModifierMetadata.js.map +0 -1
- package/metadata/ColumnTypeMetadata.d.ts +0 -43
- package/metadata/ColumnTypeMetadata.js +0 -26
- package/metadata/ColumnTypeMetadata.js.map +0 -1
- package/metadata/MetadataStorage.d.ts +0 -13
- package/metadata/MetadataStorage.js +0 -19
- package/metadata/MetadataStorage.js.map +0 -1
- package/metadata/ModelMetadata.d.ts +0 -36
- package/metadata/ModelMetadata.js +0 -81
- package/metadata/ModelMetadata.js.map +0 -1
- package/metadata/index.d.ts +0 -10
- package/metadata/index.js +0 -33
- package/metadata/index.js.map +0 -1
- package/query/Comparer.d.ts +0 -1
- package/query/Comparer.js +0 -3
- package/query/Comparer.js.map +0 -1
- package/query/CountArgs.d.ts +0 -7
- package/query/CountArgs.js +0 -3
- package/query/CountArgs.js.map +0 -1
- package/query/CountResult.d.ts +0 -5
- package/query/CountResult.js +0 -3
- package/query/CountResult.js.map +0 -1
- package/query/CreateOptions.d.ts +0 -9
- package/query/CreateOptions.js +0 -3
- package/query/CreateOptions.js.map +0 -1
- package/query/CreateUpdateOptions.d.ts +0 -4
- package/query/CreateUpdateOptions.js +0 -3
- package/query/CreateUpdateOptions.js.map +0 -1
- package/query/DeleteOptions.d.ts +0 -12
- package/query/DeleteOptions.js +0 -3
- package/query/DeleteOptions.js.map +0 -1
- package/query/DestroyResult.d.ts +0 -5
- package/query/DestroyResult.js +0 -3
- package/query/DestroyResult.js.map +0 -1
- package/query/DoNotReturnRecords.d.ts +0 -3
- package/query/DoNotReturnRecords.js +0 -3
- package/query/DoNotReturnRecords.js.map +0 -1
- package/query/FindArgs.d.ts +0 -6
- package/query/FindArgs.js +0 -3
- package/query/FindArgs.js.map +0 -1
- package/query/FindOneArgs.d.ts +0 -11
- package/query/FindOneArgs.js +0 -3
- package/query/FindOneArgs.js.map +0 -1
- package/query/FindOneResult.d.ts +0 -12
- package/query/FindOneResult.js +0 -3
- package/query/FindOneResult.js.map +0 -1
- package/query/FindResult.d.ts +0 -15
- package/query/FindResult.js +0 -3
- package/query/FindResult.js.map +0 -1
- package/query/OnConflictOptions.d.ts +0 -25
- package/query/OnConflictOptions.js +0 -3
- package/query/OnConflictOptions.js.map +0 -1
- package/query/PaginateOptions.d.ts +0 -4
- package/query/PaginateOptions.js +0 -3
- package/query/PaginateOptions.js.map +0 -1
- package/query/PopulateArgs.d.ts +0 -13
- package/query/PopulateArgs.js +0 -3
- package/query/PopulateArgs.js.map +0 -1
- package/query/ReturnSelect.d.ts +0 -5
- package/query/ReturnSelect.js +0 -3
- package/query/ReturnSelect.js.map +0 -1
- package/query/Sort.d.ts +0 -15
- package/query/Sort.js +0 -3
- package/query/Sort.js.map +0 -1
- package/query/WhereQuery.d.ts +0 -21
- package/query/WhereQuery.js +0 -3
- package/query/WhereQuery.js.map +0 -1
- package/query/index.d.ts +0 -15
- package/query/index.js +0 -32
- package/query/index.js.map +0 -1
- package/types/ClassLike.d.ts +0 -8
- package/types/ClassLike.js +0 -3
- package/types/ClassLike.js.map +0 -1
- package/types/CreateUpdateParams.d.ts +0 -9
- package/types/CreateUpdateParams.js +0 -3
- package/types/CreateUpdateParams.js.map +0 -1
- package/types/EntityPrimitiveOrId.d.ts +0 -2
- package/types/EntityPrimitiveOrId.js +0 -3
- package/types/EntityPrimitiveOrId.js.map +0 -1
- package/types/ExcludeEntityCollections.d.ts +0 -5
- package/types/ExcludeEntityCollections.js +0 -3
- package/types/ExcludeEntityCollections.js.map +0 -1
- package/types/ExcludeFunctions.d.ts +0 -4
- package/types/ExcludeFunctions.js +0 -3
- package/types/ExcludeFunctions.js.map +0 -1
- package/types/GetValueType.d.ts +0 -1
- package/types/GetValueType.js +0 -3
- package/types/GetValueType.js.map +0 -1
- package/types/IncludeFunctions.d.ts +0 -4
- package/types/IncludeFunctions.js +0 -3
- package/types/IncludeFunctions.js.map +0 -1
- package/types/IsValueOfType.d.ts +0 -1
- package/types/IsValueOfType.js +0 -3
- package/types/IsValueOfType.js.map +0 -1
- package/types/OmitEntityCollections.d.ts +0 -7
- package/types/OmitEntityCollections.js +0 -3
- package/types/OmitEntityCollections.js.map +0 -1
- package/types/OmitFunctions.d.ts +0 -7
- package/types/OmitFunctions.js +0 -3
- package/types/OmitFunctions.js.map +0 -1
- package/types/PickAsType.d.ts +0 -3
- package/types/PickAsType.js +0 -3
- package/types/PickAsType.js.map +0 -1
- package/types/PickByValueType.d.ts +0 -5
- package/types/PickByValueType.js +0 -3
- package/types/PickByValueType.js.map +0 -1
- package/types/PickFunctions.d.ts +0 -4
- package/types/PickFunctions.js +0 -3
- package/types/PickFunctions.js.map +0 -1
- package/types/Populated.d.ts +0 -9
- package/types/Populated.js +0 -3
- package/types/Populated.js.map +0 -1
- package/types/QueryResult.d.ts +0 -9
- package/types/QueryResult.js +0 -3
- package/types/QueryResult.js.map +0 -1
- package/types/QueryResultOptionalPopulated.d.ts +0 -9
- package/types/QueryResultOptionalPopulated.js +0 -3
- package/types/QueryResultOptionalPopulated.js.map +0 -1
- package/types/QueryResultPopulated.d.ts +0 -9
- package/types/QueryResultPopulated.js +0 -3
- package/types/QueryResultPopulated.js.map +0 -1
- package/types/index.d.ts +0 -17
- package/types/index.js +0 -34
- package/types/index.js.map +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,892 @@
|
|
|
1
|
+
import { Pool } from 'postgres-pool';
|
|
2
|
+
|
|
3
|
+
interface ClassLike {
|
|
4
|
+
/**
|
|
5
|
+
* Returns the name of the function. Function names are read-only and can not be changed.
|
|
6
|
+
*/
|
|
7
|
+
readonly constructor: {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Removes all entity collection properties. To be used as a re-map key function
|
|
14
|
+
*/
|
|
15
|
+
type ExcludeEntityCollections<T, K extends PropertyKey> = T extends NotEntityBrand[] | undefined ? K : T extends Entity[] | undefined ? never : K;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Removes all functions and entity collection properties. To be used as a re-map key function
|
|
19
|
+
*/
|
|
20
|
+
type ExcludeFunctions<T, K extends PropertyKey> = T extends Function ? never : K;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Changes all Entity value properties to Primitive (string|number) | Pick<Entity, 'id'>
|
|
24
|
+
*/
|
|
25
|
+
type CreateUpdateParams<T extends Entity> = {
|
|
26
|
+
[K in keyof T as ExcludeEntityCollections<NonNullable<T[K]>, ExcludeFunctions<T[K], K>>]?: T[K] extends NotEntityBrand | undefined ? T[K] : Extract<T[K], Entity> extends undefined ? T[K] : Exclude<T[K], Entity> | Pick<Extract<T[K], Entity>, 'id'>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type EntityPrimitiveOrId<T> = T extends [] ? T extends (infer U)[] ? EntityPrimitiveOrId<U>[] : T : Extract<NonNullable<T>, Entity> extends undefined ? T : Exclude<NonNullable<T>, Entity> | Pick<Extract<NonNullable<T>, Entity>, 'id'>;
|
|
30
|
+
|
|
31
|
+
type GetValueType<T, TValueType> = T extends TValueType[] ? T extends (infer U)[] ? Extract<U, TValueType> : never : T extends TValueType ? T : never;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns the key name if the property type is a function
|
|
35
|
+
*/
|
|
36
|
+
type IncludeFunctions<T, K extends PropertyKey> = T extends Function ? K : never;
|
|
37
|
+
|
|
38
|
+
type IsValueOfType<T, K extends PropertyKey, TValueType> = T extends TValueType | TValueType[] | undefined ? K : never;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Removes all entity collection properties
|
|
42
|
+
*/
|
|
43
|
+
type OmitEntityCollections<T> = {
|
|
44
|
+
[K in keyof T as ExcludeEntityCollections<T[K], K>]: T[K];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Removes all functions
|
|
49
|
+
*/
|
|
50
|
+
type OmitFunctions<T> = {
|
|
51
|
+
[K in keyof T as ExcludeFunctions<T[K], K>]: T[K];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type PickAsType<T, K extends keyof T, TValue> = {
|
|
55
|
+
[P in K]: Extract<T[P], TValue>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type PickByValueType<T, TValueType> = {
|
|
59
|
+
[K in keyof T as IsValueOfType<T[K], K, TValueType>]: GetValueType<T[K], TValueType>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
type PickFunctions<T> = {
|
|
63
|
+
[K in keyof T as IncludeFunctions<T[K], K>]: T[K];
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Changes all properties with Entity values to Primitive (string|number). Removes any properties that with values
|
|
68
|
+
* of Entity arrays
|
|
69
|
+
*/
|
|
70
|
+
type QueryResult<T extends Entity> = Extract<{
|
|
71
|
+
[K in keyof T as ExcludeEntityCollections<NonNullable<T[K]>, K>]: T[K] extends NotEntityBrand | undefined ? T[K] : Exclude<T[K], Entity>;
|
|
72
|
+
}, T>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Removes primitives from specified properties and make non-optional. Allow singular Entity properties to be null.
|
|
76
|
+
*/
|
|
77
|
+
type Populated<T extends Entity, K extends keyof T, TPropertyType extends Entity, TPropertyKeys extends keyof TPropertyType> = {
|
|
78
|
+
[P in K]-?: Extract<T[P], Entity | Entity[]> extends Entity ? undefined extends T[P] ? QueryResult<Pick<TPropertyType, TPropertyKeys | keyof PickFunctions<TPropertyType> | 'id'>> | null : QueryResult<Pick<TPropertyType, TPropertyKeys | keyof PickFunctions<TPropertyType> | 'id'>> : QueryResult<Pick<TPropertyType, TPropertyKeys | keyof PickFunctions<TPropertyType> | 'id'>>[];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Allows a QueryResult type with specific populated properties
|
|
83
|
+
*/
|
|
84
|
+
type QueryResultPopulated<T extends Entity, K extends keyof T> = Omit<QueryResult<T>, K> & {
|
|
85
|
+
[P in K]-?: Extract<T[P], Entity | Entity[]> extends Entity ? undefined extends T[P] ? QueryResult<GetValueType<T[P], Entity>> | null : QueryResult<GetValueType<T[P], Entity>> : QueryResult<GetValueType<T[P], Entity>>[];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Allows a QueryResult type with specific properties optionally populated. If the property is populated, only the id property is needed
|
|
90
|
+
*/
|
|
91
|
+
type QueryResultOptionalPopulated<T extends Entity, K extends keyof T> = Omit<QueryResult<T>, K> & {
|
|
92
|
+
[P in K]-?: T[P] extends [] ? undefined extends T[P] ? EntityPrimitiveOrId<T[P]> | null : EntityPrimitiveOrId<T[P]> : EntityPrimitiveOrId<T[P]>;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
type EntityFieldValue = boolean[] | Date | number[] | Record<string, unknown> | string[] | boolean | number | string | unknown | null;
|
|
96
|
+
declare abstract class Entity {
|
|
97
|
+
abstract id: unknown;
|
|
98
|
+
static beforeCreate(values: CreateUpdateParams<Entity>): CreateUpdateParams<Entity> | Promise<CreateUpdateParams<Entity>>;
|
|
99
|
+
static beforeUpdate(values: CreateUpdateParams<Entity>): CreateUpdateParams<Entity> | Promise<CreateUpdateParams<Entity>>;
|
|
100
|
+
}
|
|
101
|
+
interface NotEntityBrand {
|
|
102
|
+
_notEntityBrand: void;
|
|
103
|
+
}
|
|
104
|
+
type NotEntity<T> = NotEntityBrand & T;
|
|
105
|
+
interface EntityStatic<T extends Entity> {
|
|
106
|
+
beforeCreate?: (values: CreateUpdateParams<any>) => CreateUpdateParams<any> | Promise<CreateUpdateParams<any>>;
|
|
107
|
+
beforeUpdate?: (values: CreateUpdateParams<any>) => CreateUpdateParams<any> | Promise<CreateUpdateParams<any>>;
|
|
108
|
+
new (): T;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
interface ColumnBaseMetadataOptions {
|
|
112
|
+
/**
|
|
113
|
+
* Name of class with @table decorator
|
|
114
|
+
*/
|
|
115
|
+
target: string;
|
|
116
|
+
/**
|
|
117
|
+
* Column name in the database
|
|
118
|
+
*/
|
|
119
|
+
name: string;
|
|
120
|
+
/**
|
|
121
|
+
* Class property to which the column is applied
|
|
122
|
+
*/
|
|
123
|
+
propertyName: string;
|
|
124
|
+
/**
|
|
125
|
+
* Indicates if a value is required for creates.
|
|
126
|
+
*/
|
|
127
|
+
required?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Indicates if column is inserted by default. Default is true
|
|
130
|
+
*/
|
|
131
|
+
insert?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Indicates if column value is updated by "save" operation. Default is true
|
|
134
|
+
*/
|
|
135
|
+
update?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Indicates if this column is a primary key.
|
|
138
|
+
* Same can be achieved when @primaryColumn decorator is used
|
|
139
|
+
*/
|
|
140
|
+
primary?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Value will be equal to `new Date()` when the row is inserted into the table
|
|
143
|
+
* Same can be achieved when @createDateColumn decorator is used
|
|
144
|
+
*/
|
|
145
|
+
createDate?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Value will be equal to `new Date()` when the row is updated
|
|
148
|
+
* Same can be achieved when @updateDateColumn decorator is used
|
|
149
|
+
*/
|
|
150
|
+
updateDate?: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Value will be set to 1 when the row is inserted. Value will be incremented by one when the row is updated
|
|
153
|
+
* Same can be achieved when @versionColumn decorator is used
|
|
154
|
+
*/
|
|
155
|
+
version?: boolean;
|
|
156
|
+
}
|
|
157
|
+
declare abstract class ColumnBaseMetadata {
|
|
158
|
+
/**
|
|
159
|
+
* Name of class with @table decorator
|
|
160
|
+
*/
|
|
161
|
+
target: string;
|
|
162
|
+
/**
|
|
163
|
+
* Column name in the database
|
|
164
|
+
*/
|
|
165
|
+
name: string;
|
|
166
|
+
/**
|
|
167
|
+
* Class property to which the column is applied
|
|
168
|
+
*/
|
|
169
|
+
propertyName: string;
|
|
170
|
+
/**
|
|
171
|
+
* Indicates if a value is required for creates.
|
|
172
|
+
*/
|
|
173
|
+
required: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Indicates if column is inserted by default. Default is true
|
|
176
|
+
*/
|
|
177
|
+
insert: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Indicates if column value is updated by "save" operation. Default is true
|
|
180
|
+
*/
|
|
181
|
+
update: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Indicates if this column is a primary key.
|
|
184
|
+
* Same can be achieved when @primaryColumn decorator is used
|
|
185
|
+
*/
|
|
186
|
+
primary: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Value will be equal to `new Date()` when the row is inserted into the table
|
|
189
|
+
* Same can be achieved when @createDateColumn decorator is used
|
|
190
|
+
*/
|
|
191
|
+
createDate: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Value will be equal to `new Date()` when the row is updated
|
|
194
|
+
* Same can be achieved when @updateDateColumn decorator is used
|
|
195
|
+
*/
|
|
196
|
+
updateDate: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Value will be set to 1 when the row is inserted. Value will be incremented by one when the row is updated
|
|
199
|
+
* Same can be achieved when @versionColumn decorator is used
|
|
200
|
+
*/
|
|
201
|
+
version: boolean;
|
|
202
|
+
protected constructor({ target, name, propertyName, required, insert, update, primary, createDate, updateDate, version, }: ColumnBaseMetadataOptions);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
interface ColumnCollectionMetadataOptions extends ColumnBaseMetadataOptions {
|
|
206
|
+
/**
|
|
207
|
+
* Type of the items in the collection
|
|
208
|
+
*/
|
|
209
|
+
collection: string | (() => string);
|
|
210
|
+
/**
|
|
211
|
+
* Property name of the on the collection item type
|
|
212
|
+
*/
|
|
213
|
+
via: string;
|
|
214
|
+
/**
|
|
215
|
+
* Name of the junction table for multi-multi associations
|
|
216
|
+
*/
|
|
217
|
+
through?: string | (() => string);
|
|
218
|
+
}
|
|
219
|
+
declare class ColumnCollectionMetadata extends ColumnBaseMetadata {
|
|
220
|
+
private _collectionString?;
|
|
221
|
+
private _collectionFn?;
|
|
222
|
+
private _throughString?;
|
|
223
|
+
private _throughFn?;
|
|
224
|
+
/**
|
|
225
|
+
* Type of the items in the collection
|
|
226
|
+
*/
|
|
227
|
+
get collection(): string;
|
|
228
|
+
/**
|
|
229
|
+
* Property name of the on the collection item type
|
|
230
|
+
*/
|
|
231
|
+
via: string;
|
|
232
|
+
/**
|
|
233
|
+
* Name of the junction table for multi-multi associations
|
|
234
|
+
*/
|
|
235
|
+
get through(): string | undefined;
|
|
236
|
+
constructor({ target, //
|
|
237
|
+
name, propertyName, required, insert, update, primary, createDate, updateDate, version, collection, via, through, }: ColumnCollectionMetadataOptions);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
interface ColumnModelMetadataOptions extends ColumnBaseMetadataOptions {
|
|
241
|
+
/**
|
|
242
|
+
* Name of the model represented by this column id
|
|
243
|
+
*/
|
|
244
|
+
model: string | (() => string);
|
|
245
|
+
}
|
|
246
|
+
declare class ColumnModelMetadata extends ColumnBaseMetadata {
|
|
247
|
+
private _modelString?;
|
|
248
|
+
private _modelFn?;
|
|
249
|
+
/**
|
|
250
|
+
* Name of the model represented by this column id
|
|
251
|
+
*/
|
|
252
|
+
get model(): string;
|
|
253
|
+
constructor({ target, //
|
|
254
|
+
name, propertyName, required, insert, update, primary, createDate, updateDate, version, model, }: ColumnModelMetadataOptions);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
interface ColumnTypeMetadataOptions extends ColumnBaseMetadataOptions {
|
|
258
|
+
/**
|
|
259
|
+
* Type of sql column
|
|
260
|
+
*/
|
|
261
|
+
type: 'array' | 'binary' | 'boolean' | 'boolean[]' | 'date' | 'datetime' | 'float' | 'float[]' | 'integer' | 'integer[]' | 'json' | 'string' | 'string[]';
|
|
262
|
+
/**
|
|
263
|
+
* Default database value
|
|
264
|
+
*/
|
|
265
|
+
defaultsTo?: boolean[] | number[] | string[] | boolean | number | string | (() => Date | Record<string, unknown> | boolean | number | string) | [];
|
|
266
|
+
/**
|
|
267
|
+
* Array of possible enumerated values
|
|
268
|
+
*/
|
|
269
|
+
enum?: string[];
|
|
270
|
+
/**
|
|
271
|
+
* If set, enforces a maximum length check on the column
|
|
272
|
+
*
|
|
273
|
+
* Applies to types: string | string[]
|
|
274
|
+
*/
|
|
275
|
+
maxLength?: number;
|
|
276
|
+
}
|
|
277
|
+
declare class ColumnTypeMetadata extends ColumnBaseMetadata {
|
|
278
|
+
/**
|
|
279
|
+
* Type of the column
|
|
280
|
+
*/
|
|
281
|
+
type: 'array' | 'binary' | 'boolean' | 'boolean[]' | 'date' | 'datetime' | 'float' | 'float[]' | 'integer' | 'integer[]' | 'json' | 'string' | 'string[]';
|
|
282
|
+
/**
|
|
283
|
+
* Default database value
|
|
284
|
+
*/
|
|
285
|
+
defaultsTo?: boolean[] | number[] | string[] | boolean | number | string | (() => Date | Record<string, unknown> | boolean | number | string) | [];
|
|
286
|
+
/**
|
|
287
|
+
* Array of possible enumerated values
|
|
288
|
+
*/
|
|
289
|
+
enum?: string[];
|
|
290
|
+
/**
|
|
291
|
+
* If set, enforces a maximum length check on the column
|
|
292
|
+
*
|
|
293
|
+
* Applies to types: string | string[]
|
|
294
|
+
*/
|
|
295
|
+
maxLength?: number;
|
|
296
|
+
constructor(options: ColumnTypeMetadataOptions);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
type ColumnMetadata = ColumnCollectionMetadata | ColumnModelMetadata | ColumnTypeMetadata;
|
|
300
|
+
|
|
301
|
+
interface ColumnModifierMetadata {
|
|
302
|
+
/**
|
|
303
|
+
* Name of class with @table decorator
|
|
304
|
+
*/
|
|
305
|
+
target: string;
|
|
306
|
+
/**
|
|
307
|
+
* Column name in the database
|
|
308
|
+
*/
|
|
309
|
+
name?: string;
|
|
310
|
+
/**
|
|
311
|
+
* Class property to which the column is applied
|
|
312
|
+
*/
|
|
313
|
+
propertyName: string;
|
|
314
|
+
/**
|
|
315
|
+
* Indicates if a value is required for creates.
|
|
316
|
+
*/
|
|
317
|
+
required?: boolean;
|
|
318
|
+
/**
|
|
319
|
+
* Indicates if this column is a primary key.
|
|
320
|
+
* Same can be achieved when @primaryColumn decorator is used
|
|
321
|
+
*/
|
|
322
|
+
primary?: boolean;
|
|
323
|
+
/**
|
|
324
|
+
* Value will be equal to `new Date()` when the row is inserted into the table
|
|
325
|
+
* Same can be achieved when @createDateColumn decorator is used
|
|
326
|
+
*/
|
|
327
|
+
createDate?: boolean;
|
|
328
|
+
/**
|
|
329
|
+
* Value will be equal to `new Date()` when the row is updated
|
|
330
|
+
* Same can be achieved when @updateDateColumn decorator is used
|
|
331
|
+
*/
|
|
332
|
+
updateDate?: boolean;
|
|
333
|
+
/**
|
|
334
|
+
* Value will be set to 1 when the row is inserted. Value will be incremented by one when the row is updated
|
|
335
|
+
* Same can be achieved when @versionColumn decorator is used
|
|
336
|
+
*/
|
|
337
|
+
version?: boolean;
|
|
338
|
+
/**
|
|
339
|
+
* Type of sql column
|
|
340
|
+
*/
|
|
341
|
+
type?: 'array' | 'binary' | 'boolean' | 'boolean[]' | 'date' | 'datetime' | 'float' | 'float[]' | 'integer' | 'integer[]' | 'json' | 'string' | 'string[]';
|
|
342
|
+
/**
|
|
343
|
+
* Name of the model represented by this column id
|
|
344
|
+
*/
|
|
345
|
+
model?: string | (() => string);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
type Column = ColumnCollectionMetadata | ColumnModelMetadata | ColumnTypeMetadata;
|
|
349
|
+
type ColumnByStringId = Record<string, Column>;
|
|
350
|
+
interface ModelMetadataOptions<T extends Entity> {
|
|
351
|
+
name: string;
|
|
352
|
+
type: EntityStatic<T>;
|
|
353
|
+
connection?: string;
|
|
354
|
+
tableName?: string;
|
|
355
|
+
readonly?: boolean;
|
|
356
|
+
}
|
|
357
|
+
declare class ModelMetadata<T extends Entity> {
|
|
358
|
+
private _columns;
|
|
359
|
+
private _primaryKeyColumn;
|
|
360
|
+
private _createDateColumns;
|
|
361
|
+
private _updateDateColumns;
|
|
362
|
+
private _versionDateColumns;
|
|
363
|
+
set columns(columns: readonly Column[]);
|
|
364
|
+
get columns(): readonly Column[];
|
|
365
|
+
get primaryKeyColumn(): Column | undefined;
|
|
366
|
+
get createDateColumns(): readonly Column[];
|
|
367
|
+
get updateDateColumns(): readonly Column[];
|
|
368
|
+
get versionColumns(): readonly Column[];
|
|
369
|
+
name: string;
|
|
370
|
+
type: EntityStatic<T>;
|
|
371
|
+
connection?: string;
|
|
372
|
+
tableName: string;
|
|
373
|
+
readonly: boolean;
|
|
374
|
+
columnsByColumnName: ColumnByStringId;
|
|
375
|
+
columnsByPropertyName: ColumnByStringId;
|
|
376
|
+
constructor({ name, //
|
|
377
|
+
type, connection, tableName, readonly, }: ModelMetadataOptions<T>);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* This represents an object to store all of the decorator data. Since there can be multiple decorators per
|
|
382
|
+
* class/property, things will be reconciled when entities are initialized
|
|
383
|
+
*/
|
|
384
|
+
declare class MetadataStorage<T extends Entity> {
|
|
385
|
+
readonly models: ModelMetadata<T>[];
|
|
386
|
+
readonly columns: ColumnMetadata[];
|
|
387
|
+
readonly columnModifiers: ColumnModifierMetadata[];
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
declare function getMetadataStorage<T extends Entity>(): MetadataStorage<T>;
|
|
391
|
+
|
|
392
|
+
type ExcludeUndefined<T> = Exclude<T, undefined>;
|
|
393
|
+
type LiteralValues<TValue> = (TValue | null)[] | TValue | null;
|
|
394
|
+
type WhereClauseValue<TValue> = TValue extends NotEntityBrand | undefined ? Exclude<TValue, NotEntityBrand | undefined> : Extract<TValue, Entity> extends undefined ? LiteralValues<ExcludeUndefined<TValue>> : (ExcludeUndefined<Exclude<TValue, Entity>> | null)[] | (Pick<Extract<ExcludeUndefined<TValue>, Entity>, 'id'> | null)[] | ExcludeUndefined<Exclude<TValue, Entity>> | Pick<Extract<ExcludeUndefined<TValue>, Entity>, 'id'> | null;
|
|
395
|
+
type StringConstraint<TValue extends string> = {
|
|
396
|
+
[P in 'contains' | 'endsWith' | 'like' | 'startsWith']?: LiteralValues<ExcludeUndefined<TValue>>;
|
|
397
|
+
};
|
|
398
|
+
type NumberOrDateConstraint<TValue extends Date | number> = {
|
|
399
|
+
[P in '<' | '<=' | '>' | '>=']?: LiteralValues<ExcludeUndefined<TValue>>;
|
|
400
|
+
};
|
|
401
|
+
type NegatableConstraint<TValue> = TValue | {
|
|
402
|
+
'!': TValue;
|
|
403
|
+
};
|
|
404
|
+
type WhereQueryStatement<TValue> = [TValue] extends [string] ? NegatableConstraint<StringConstraint<TValue> | WhereClauseValue<TValue>> : TValue extends string ? NegatableConstraint<StringConstraint<TValue> | WhereClauseValue<TValue>> : TValue extends Date | number ? NegatableConstraint<NumberOrDateConstraint<TValue> | WhereClauseValue<TValue>> : NegatableConstraint<WhereClauseValue<TValue>>;
|
|
405
|
+
type WhereQuery<T extends Entity> = {
|
|
406
|
+
[K in keyof T as ExcludeEntityCollections<T[K], ExcludeFunctions<T[K], K>>]?: K extends 'id' ? WhereQueryStatement<T | T[K]> : T[K] extends (infer U)[] | undefined ? WhereQueryStatement<ExcludeUndefined<U>> : NegatableConstraint<LiteralValues<ExcludeUndefined<T[K]>>> | WhereQueryStatement<ExcludeUndefined<T[K]>>;
|
|
407
|
+
} & {
|
|
408
|
+
or?: WhereQuery<T>[];
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
interface CountResult<TEntity extends Entity> extends PromiseLike<number> {
|
|
412
|
+
where(args: WhereQuery<TEntity>): CountResult<TEntity> | number;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
interface DoNotReturnRecords {
|
|
416
|
+
returnRecords: false;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
interface ReturnSelect$1<T extends Entity, K extends keyof OmitFunctions<OmitEntityCollections<T>> = keyof OmitFunctions<OmitEntityCollections<T>>> {
|
|
420
|
+
returnSelect: (K & string)[];
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
type CreateUpdateOptions<T extends Entity> = DoNotReturnRecords | ReturnSelect$1<T>;
|
|
424
|
+
|
|
425
|
+
interface ReturnSelect<T extends Entity, K extends keyof T> {
|
|
426
|
+
returnSelect: (K & string & keyof OmitFunctions<OmitEntityCollections<T>>)[];
|
|
427
|
+
returnRecords?: true;
|
|
428
|
+
}
|
|
429
|
+
interface ReturnRecords<T extends Entity, K extends keyof T> {
|
|
430
|
+
returnRecords: true;
|
|
431
|
+
returnSelect?: (K & string & keyof OmitFunctions<OmitEntityCollections<T>>)[];
|
|
432
|
+
}
|
|
433
|
+
type DeleteOptions<T extends Entity, K extends keyof T = keyof T> = ReturnRecords<T, K> | ReturnSelect<T, K>;
|
|
434
|
+
|
|
435
|
+
interface DestroyResult<TEntity extends Entity, TReturn> extends PromiseLike<TReturn> {
|
|
436
|
+
where(args: WhereQuery<TEntity>): DestroyResult<TEntity, TReturn>;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
type SortString<T extends Entity> = `${string & keyof OmitFunctions<OmitEntityCollections<T>>} ASC` | `${string & keyof OmitFunctions<OmitEntityCollections<T>>} asc` | `${string & keyof OmitFunctions<OmitEntityCollections<T>>} DESC` | `${string & keyof OmitFunctions<OmitEntityCollections<T>>} desc` | `${string & keyof OmitFunctions<OmitEntityCollections<T>>}`;
|
|
440
|
+
type ValidateMultipleSorts<T extends Entity, TNextSortPart extends string, TPreviouslyValidatedSortString extends string, TSortString extends string> = TNextSortPart extends `, ${SortString<T>}${infer TRestSortPart}` ? TRestSortPart extends '' ? TSortString : ValidateMultipleSorts<T, TRestSortPart, TNextSortPart extends `${infer TValidatedSortPart}${TRestSortPart}` ? `${TPreviouslyValidatedSortString}${TValidatedSortPart}` : never, TSortString> : `${TPreviouslyValidatedSortString}, ${SortString<T>}`;
|
|
441
|
+
type MultipleSortString<T extends Entity, TSortString extends string = string> = TSortString extends `${SortString<T>}${infer TRestSortPart}` ? TRestSortPart extends '' ? TSortString : ValidateMultipleSorts<T, TRestSortPart, TSortString extends `${infer TPreviouslyValidatedSortString}${TRestSortPart}` ? TPreviouslyValidatedSortString : never, TSortString> : SortString<T>;
|
|
442
|
+
type SortObjectValue = -1 | 'asc' | 'desc' | 1;
|
|
443
|
+
type SortObject<T extends Entity> = {
|
|
444
|
+
[K in keyof T as ExcludeFunctions<OmitEntityCollections<T>, K>]?: SortObjectValue;
|
|
445
|
+
};
|
|
446
|
+
type Sort<T extends Entity> = MultipleSortString<T> | SortObject<T>;
|
|
447
|
+
interface OrderBy<T extends Entity> {
|
|
448
|
+
propertyName: string & keyof OmitFunctions<OmitEntityCollections<T>>;
|
|
449
|
+
descending?: boolean;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
interface FindOneArgs<T extends Entity, K extends keyof T = string & keyof OmitFunctions<OmitEntityCollections<T>> & keyof T> {
|
|
453
|
+
select?: (K & string & keyof OmitFunctions<OmitEntityCollections<T>>)[];
|
|
454
|
+
where?: WhereQuery<T>;
|
|
455
|
+
sort?: Sort<T>;
|
|
456
|
+
pool?: Pool;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
interface FindArgs<T extends Entity, K extends keyof T = keyof T> extends FindOneArgs<T, K> {
|
|
460
|
+
skip?: number;
|
|
461
|
+
limit?: number;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
interface PopulateArgs<T extends Entity, K extends keyof T> {
|
|
465
|
+
where?: WhereQuery<T>;
|
|
466
|
+
select?: (K & string & keyof OmitFunctions<OmitEntityCollections<T>>)[];
|
|
467
|
+
sort?: Sort<T>;
|
|
468
|
+
skip?: number;
|
|
469
|
+
limit?: number;
|
|
470
|
+
pool?: Pool;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
interface FindOneResult<T extends Entity, TReturn> extends PromiseLike<TReturn | null> {
|
|
474
|
+
where(args: WhereQuery<T>): FindOneResult<T, TReturn>;
|
|
475
|
+
populate<TProperty extends string & keyof PickByValueType<T, Entity> & keyof T, TPopulateType extends GetValueType<T[TProperty], Entity>, TPopulateSelectKeys extends string & keyof TPopulateType>(propertyName: TProperty, options?: PopulateArgs<TPopulateType, TPopulateSelectKeys>): FindOneResult<T, Omit<TReturn, TProperty> & Populated<T, TProperty, TPopulateType, TPopulateSelectKeys>>;
|
|
476
|
+
sort(value?: Sort<T>): FindOneResult<T, TReturn>;
|
|
477
|
+
UNSAFE_withOriginalFieldType<TProperty extends string & keyof PickByValueType<T, Entity> & keyof T>(propertyName: TProperty): FindOneResult<T, Omit<TReturn, TProperty> & Pick<T, TProperty>>;
|
|
478
|
+
UNSAFE_withFieldValue<TProperty extends string & keyof T, TValue extends T[TProperty]>(propertyName: TProperty, value: TValue): FindOneResult<T, Omit<TReturn, TProperty> & PickAsType<T, TProperty, TValue>>;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
interface PaginateOptions {
|
|
482
|
+
limit: number;
|
|
483
|
+
page: number;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
interface FindResult<T extends Entity, TReturn> extends PromiseLike<TReturn[]> {
|
|
487
|
+
where(args: WhereQuery<T>): FindResult<T, TReturn>;
|
|
488
|
+
populate<TProperty extends string & keyof PickByValueType<T, Entity> & keyof T, TPopulateType extends GetValueType<T[TProperty], Entity>, TPopulateSelectKeys extends string & keyof TPopulateType>(propertyName: TProperty, options?: PopulateArgs<TPopulateType, TPopulateSelectKeys>): FindResult<T, Omit<TReturn, TProperty> & Populated<T, TProperty, TPopulateType, TPopulateSelectKeys>>;
|
|
489
|
+
sort(value?: Sort<T>): FindResult<T, TReturn>;
|
|
490
|
+
limit(value: number): FindResult<T, TReturn>;
|
|
491
|
+
skip(value: number): FindResult<T, TReturn>;
|
|
492
|
+
paginate(options: PaginateOptions): FindResult<T, TReturn>;
|
|
493
|
+
UNSAFE_withOriginalFieldType<TProperty extends string & keyof PickByValueType<T, Entity> & keyof T>(propertyName: TProperty): FindResult<T, Omit<TReturn, TProperty> & Pick<T, TProperty>>;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
interface CountArgs<T extends Entity> {
|
|
497
|
+
where?: WhereQuery<T>;
|
|
498
|
+
pool?: Pool;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
interface IReadonlyRepository<T extends Entity> {
|
|
502
|
+
readonly model: ModelMetadata<T>;
|
|
503
|
+
/**
|
|
504
|
+
* Gets a single object
|
|
505
|
+
* @param {object} [args] - Arguments
|
|
506
|
+
* @param {string[]} [args.select] - Array of model property names to return from the query.
|
|
507
|
+
* @param {object} [args.where] - Object representing the where query
|
|
508
|
+
* @param {string|object|string[]|object[]} [args.sort] - Property name(s) to sort by
|
|
509
|
+
* @param {object} [args.pool] - Override the db pool to use for the query
|
|
510
|
+
*/
|
|
511
|
+
findOne<K extends string & keyof T, TReturn = QueryResult<Pick<T, K | 'id'>>>(args: FindOneArgs<T, K> | WhereQuery<T>): FindOneResult<T, TReturn>;
|
|
512
|
+
/**
|
|
513
|
+
* Gets a collection of objects
|
|
514
|
+
* @param {object} [args] - Arguments
|
|
515
|
+
* @param {string[]} [args.select] - Array of model property names to return from the query.
|
|
516
|
+
* @param {object} [args.where] - Object representing the where query
|
|
517
|
+
* @param {string|object|string[]|object[]} [args.sort] - Property name(s) to sort by
|
|
518
|
+
* @param {string|number} [args.skip] - Number of records to skip
|
|
519
|
+
* @param {string|number} [args.limit] - Number of results to return
|
|
520
|
+
* @param {object} [args.pool] - Override the db pool to use for the query
|
|
521
|
+
*/
|
|
522
|
+
find<K extends string & keyof T, TReturn = QueryResult<Pick<T, K | 'id'>>>(args: FindArgs<T, K> | WhereQuery<T>): FindResult<T, TReturn>;
|
|
523
|
+
/**
|
|
524
|
+
* Gets a count of rows matching the where query
|
|
525
|
+
* @param {object} [args] - Arguments
|
|
526
|
+
* @param {object} [args.where] - Object representing the where query
|
|
527
|
+
* @param {object} [args.pool] - Override the db pool to use for the query
|
|
528
|
+
* @returns {number} Number of records matching the where criteria
|
|
529
|
+
*/
|
|
530
|
+
count(args?: CountArgs<T> | WhereQuery<T>): CountResult<T>;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
type OnConflictTargets<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> = K[] | {
|
|
534
|
+
columns: K[];
|
|
535
|
+
where: WhereQuery<T>;
|
|
536
|
+
};
|
|
537
|
+
interface OnConflictIgnoreOptions<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> {
|
|
538
|
+
onConflict: {
|
|
539
|
+
action: 'ignore';
|
|
540
|
+
targets: OnConflictTargets<T, K>;
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
interface OnConflictMergeOptions<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> {
|
|
544
|
+
onConflict: {
|
|
545
|
+
action: 'merge';
|
|
546
|
+
targets: OnConflictTargets<T, K>;
|
|
547
|
+
merge?: K[] | {
|
|
548
|
+
columns?: K[];
|
|
549
|
+
where: WhereQuery<T>;
|
|
550
|
+
};
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
type OnConflictOptions<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> = OnConflictIgnoreOptions<T, K> | OnConflictMergeOptions<T, K>;
|
|
554
|
+
|
|
555
|
+
type CreateOnConflictOptions<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> = OnConflictOptions<T, K> & Partial<DoNotReturnRecords | ReturnSelect$1<T>>;
|
|
556
|
+
type CreateOptionalOnConflictOptions<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> = Partial<OnConflictOptions<T, K>> & (DoNotReturnRecords | ReturnSelect$1<T>);
|
|
557
|
+
type CreateOptions<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> = CreateOnConflictOptions<T, K> | CreateOptionalOnConflictOptions<T, K>;
|
|
558
|
+
|
|
559
|
+
interface IRepository<T extends Entity> extends IReadonlyRepository<T> {
|
|
560
|
+
/**
|
|
561
|
+
* Creates an object using the specified values
|
|
562
|
+
* @param {object} values - Values to insert as multiple new objects.
|
|
563
|
+
* @param {object} [options]
|
|
564
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
565
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
566
|
+
* @returns {object}
|
|
567
|
+
*/
|
|
568
|
+
create(values: CreateUpdateParams<T>, options?: OnConflictOptions<T> | (Partial<OnConflictOptions<T>> & ReturnSelect$1<T>)): Promise<QueryResult<T>>;
|
|
569
|
+
/**
|
|
570
|
+
* Creates an object or objects using the specified values
|
|
571
|
+
* @param {object|object[]} values - Values to insert as multiple new objects.
|
|
572
|
+
* @param {object} options
|
|
573
|
+
* @param {boolean} options.returnRecords - Determines if inserted records should be returned
|
|
574
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
575
|
+
* @returns {void}
|
|
576
|
+
*/
|
|
577
|
+
create(values: CreateUpdateParams<T> | CreateUpdateParams<T>[], options: DoNotReturnRecords & Partial<OnConflictOptions<T>>): Promise<void>;
|
|
578
|
+
/**
|
|
579
|
+
* Creates objects using the specified values
|
|
580
|
+
* @param {object[]} values - Values to insert as multiple new objects.
|
|
581
|
+
* @param {object} [options]
|
|
582
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
583
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
584
|
+
* @returns {object[]}
|
|
585
|
+
*/
|
|
586
|
+
create(values: CreateUpdateParams<T>[], options?: (OnConflictOptions<T> & Partial<ReturnSelect$1<T>>) | (Partial<OnConflictOptions<T>> & ReturnSelect$1<T>)): Promise<QueryResult<T>[]>;
|
|
587
|
+
/**
|
|
588
|
+
* Creates an object using the specified values
|
|
589
|
+
* @param {object|object[]} values - Values to insert as a new object. If an array is specified, multiple rows will be inserted
|
|
590
|
+
* @param {object} [options]
|
|
591
|
+
* @param {boolean} [options.returnRecords=true] - Determines if inserted records should be returned
|
|
592
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
593
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
594
|
+
* @returns {object|object[]|void} Return value from the db
|
|
595
|
+
*/
|
|
596
|
+
create(values: CreateUpdateParams<T> | CreateUpdateParams<T>[], options?: CreateOptions<T>): Promise<QueryResult<T>[]> | Promise<QueryResult<T>> | Promise<void>;
|
|
597
|
+
/**
|
|
598
|
+
* Updates object(s) matching the where query, with the specified values
|
|
599
|
+
* @param {object} where - Object representing the where query
|
|
600
|
+
* @param {object} values - Values to update
|
|
601
|
+
* @param {object} options
|
|
602
|
+
* @param {boolean} options.returnRecords - Determines if inserted records should be returned
|
|
603
|
+
* @param {{returnRecords: false}} options
|
|
604
|
+
* @returns {void}
|
|
605
|
+
*/
|
|
606
|
+
update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options: DoNotReturnRecords): Promise<void>;
|
|
607
|
+
/**
|
|
608
|
+
* Updates object(s) matching the where query, with the specified values
|
|
609
|
+
* @param {object} where - Object representing the where query
|
|
610
|
+
* @param {object} values - Values to update
|
|
611
|
+
* @param {object} [options] - Values to update
|
|
612
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
613
|
+
* @returns {object[]}
|
|
614
|
+
*/
|
|
615
|
+
update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options?: ReturnSelect$1<T>): Promise<QueryResult<T>[]>;
|
|
616
|
+
/**
|
|
617
|
+
* Updates object(s) matching the where query, with the specified values
|
|
618
|
+
* @param {object} where - Object representing the where query
|
|
619
|
+
* @param {object} values - Values to update
|
|
620
|
+
* @param {object} [options]
|
|
621
|
+
* @param {boolean} [options.returnRecords=true] - Determines if inserted records should be returned
|
|
622
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
623
|
+
* @returns {object[]|void} Return values from the db or `true` if returnRecords=false
|
|
624
|
+
*/
|
|
625
|
+
update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options?: CreateUpdateOptions<T>): Promise<QueryResult<T>[]> | Promise<void>;
|
|
626
|
+
/**
|
|
627
|
+
* Destroys object(s) matching the where query
|
|
628
|
+
* @param {object} [where] - Object representing the where query
|
|
629
|
+
* @returns {void}
|
|
630
|
+
*/
|
|
631
|
+
destroy(where?: WhereQuery<T>): DestroyResult<T, void>;
|
|
632
|
+
/**
|
|
633
|
+
* Destroys object(s) matching the where query
|
|
634
|
+
* @param {object} where - Object representing the where query
|
|
635
|
+
* @param {object} options - Determines if inserted records should be returned
|
|
636
|
+
* @param {boolean} [options.returnRecords] - Determines if inserted records should be returned
|
|
637
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
638
|
+
* @returns {object[]}
|
|
639
|
+
*/
|
|
640
|
+
destroy(where: WhereQuery<T>, options: DeleteOptions<T>): DestroyResult<T, QueryResult<T>[]>;
|
|
641
|
+
/**
|
|
642
|
+
* Destroys object(s) matching the where query
|
|
643
|
+
* @param {object} where - Object representing the where query
|
|
644
|
+
* @param {object} [options]
|
|
645
|
+
* @param {boolean} [options.returnRecords=false] - Determines if inserted records should be returned
|
|
646
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
647
|
+
* @returns {object[]|void} `void` or records affected if returnRecords=true
|
|
648
|
+
*/
|
|
649
|
+
destroy<TOptions extends DeleteOptions<T> = DeleteOptions<T>>(where: WhereQuery<T>, options?: TOptions): TOptions extends DeleteOptions<T> ? Promise<void> : DestroyResult<T, QueryResult<T>[]>;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
interface IRepositoryOptions<T extends Entity> {
|
|
653
|
+
modelMetadata: ModelMetadata<T>;
|
|
654
|
+
type: EntityStatic<T>;
|
|
655
|
+
repositoriesByModelNameLowered: Record<string, IReadonlyRepository<Entity> | IRepository<Entity>>;
|
|
656
|
+
pool: Pool;
|
|
657
|
+
readonlyPool?: Pool;
|
|
658
|
+
}
|
|
659
|
+
interface Populate {
|
|
660
|
+
propertyName: string;
|
|
661
|
+
where?: WhereQuery<Entity>;
|
|
662
|
+
select?: string[];
|
|
663
|
+
sort?: SortObject<Entity> | string;
|
|
664
|
+
skip?: number;
|
|
665
|
+
limit?: number;
|
|
666
|
+
pool?: Pool;
|
|
667
|
+
}
|
|
668
|
+
declare class ReadonlyRepository<T extends Entity> implements IReadonlyRepository<T> {
|
|
669
|
+
private readonly _modelMetadata;
|
|
670
|
+
protected _type: EntityStatic<T>;
|
|
671
|
+
protected _pool: Pool;
|
|
672
|
+
protected _readonlyPool: Pool;
|
|
673
|
+
protected _repositoriesByModelNameLowered: Record<string, IReadonlyRepository<Entity> | IRepository<Entity>>;
|
|
674
|
+
protected _floatProperties: string[];
|
|
675
|
+
protected _intProperties: string[];
|
|
676
|
+
constructor({ modelMetadata, type, pool, readonlyPool, repositoriesByModelNameLowered }: IRepositoryOptions<T>);
|
|
677
|
+
get model(): ModelMetadata<T>;
|
|
678
|
+
/**
|
|
679
|
+
* Gets a single object
|
|
680
|
+
* @param {object} [args] - Arguments
|
|
681
|
+
* @param {string[]} [args.select] - Array of model property names to return from the query.
|
|
682
|
+
* @param {object} [args.where] - Object representing the where query
|
|
683
|
+
* @param {string|object} [args.sort] - Property name(s) to sort by
|
|
684
|
+
*/
|
|
685
|
+
findOne<K extends string & keyof T, TReturn = QueryResult<Pick<T, K | keyof PickFunctions<T> | 'id'>>>(args?: FindOneArgs<T, K> | WhereQuery<T>): FindOneResult<T, TReturn>;
|
|
686
|
+
/**
|
|
687
|
+
* Gets a collection of objects
|
|
688
|
+
* @param {object} [args] - Arguments
|
|
689
|
+
* @param {string[]} [args.select] - Array of model property names to return from the query.
|
|
690
|
+
* @param {object} [args.where] - Object representing the where query
|
|
691
|
+
* @param {string|object} [args.sort] - Property name(s) to sort by
|
|
692
|
+
* @param {string|number} [args.skip] - Number of records to skip
|
|
693
|
+
* @param {string|number} [args.limit] - Number of results to return
|
|
694
|
+
*/
|
|
695
|
+
find<K extends string & keyof T, TReturn = QueryResult<Pick<T, K | keyof PickFunctions<T> | 'id'>>>(args?: FindArgs<T, K> | WhereQuery<T>): FindResult<T, TReturn>;
|
|
696
|
+
/**
|
|
697
|
+
* Gets a count of rows matching the where query
|
|
698
|
+
* @param {object} [args] - Arguments
|
|
699
|
+
* @param {object} [args.where] - Object representing the where query
|
|
700
|
+
* @param {object} [args.pool] - Override the db pool to use for the query
|
|
701
|
+
* @returns {number} Number of records matching the where criteria
|
|
702
|
+
*/
|
|
703
|
+
count(args?: CountArgs<T> | WhereQuery<T>): CountResult<T>;
|
|
704
|
+
protected _buildInstance(row: Partial<QueryResult<T>>): QueryResult<T>;
|
|
705
|
+
protected _buildInstances(rows: Partial<QueryResult<T>>[]): QueryResult<T>[];
|
|
706
|
+
protected _convertSortsToOrderBy(sorts: SortObject<T> | string): OrderBy<T>[];
|
|
707
|
+
protected populateFields(entities: QueryResult<T>[], populates: Populate[]): Promise<void>;
|
|
708
|
+
private populateSingleAssociation;
|
|
709
|
+
private populateOneManyCollection;
|
|
710
|
+
private populateManyManyCollection;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
declare class Repository<T extends Entity> extends ReadonlyRepository<T> implements IRepository<T> {
|
|
714
|
+
/**
|
|
715
|
+
* Creates an object using the specified values
|
|
716
|
+
* @param {object} values - Values to insert as multiple new objects.
|
|
717
|
+
* @param {object} [options]
|
|
718
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
719
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
720
|
+
* @returns {object}
|
|
721
|
+
*/
|
|
722
|
+
create(values: CreateUpdateParams<T>, options?: OnConflictOptions<T> | (Partial<OnConflictOptions<T>> & ReturnSelect$1<T>)): Promise<QueryResult<T>>;
|
|
723
|
+
/**
|
|
724
|
+
* Creates an object or objects using the specified values
|
|
725
|
+
* @param {object|object[]} values - Values to insert as multiple new objects.
|
|
726
|
+
* @param {object} options
|
|
727
|
+
* @param {boolean} options.returnRecords - Determines if inserted records should be returned
|
|
728
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
729
|
+
* @returns {void}
|
|
730
|
+
*/
|
|
731
|
+
create(values: CreateUpdateParams<T> | CreateUpdateParams<T>[], options: DoNotReturnRecords & Partial<OnConflictOptions<T>>): Promise<void>;
|
|
732
|
+
/**
|
|
733
|
+
* Creates objects using the specified values
|
|
734
|
+
* @param {object[]} values - Values to insert as multiple new objects.
|
|
735
|
+
* @param {object} [options]
|
|
736
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
737
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
738
|
+
* @returns {object[]}
|
|
739
|
+
*/
|
|
740
|
+
create(values: CreateUpdateParams<T>[], options?: (OnConflictOptions<T> & Partial<ReturnSelect$1<T>>) | (Partial<OnConflictOptions<T>> & ReturnSelect$1<T>)): Promise<QueryResult<T>[]>;
|
|
741
|
+
/**
|
|
742
|
+
* Updates object(s) matching the where query, with the specified values
|
|
743
|
+
* @param {object} where - Object representing the where query
|
|
744
|
+
* @param {object} values - Values to update
|
|
745
|
+
* @param {object} options
|
|
746
|
+
* @param {boolean} options.returnRecords - Determines if inserted records should be returned
|
|
747
|
+
* @returns {void}
|
|
748
|
+
*/
|
|
749
|
+
update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options: DoNotReturnRecords): Promise<void>;
|
|
750
|
+
/**
|
|
751
|
+
* Updates object(s) matching the where query, with the specified values
|
|
752
|
+
* @param {object} where - Object representing the where query
|
|
753
|
+
* @param {object} values - Values to update
|
|
754
|
+
* @param {object} [options] - Values to update
|
|
755
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
756
|
+
* @returns {object[]}
|
|
757
|
+
*/
|
|
758
|
+
update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options?: ReturnSelect$1<T>): Promise<QueryResult<T>[]>;
|
|
759
|
+
/**
|
|
760
|
+
* Destroys object(s) matching the where query
|
|
761
|
+
* @param {object} [where] - Object representing the where query
|
|
762
|
+
* @returns {void}
|
|
763
|
+
*/
|
|
764
|
+
destroy(where?: WhereQuery<T>): DestroyResult<T, void>;
|
|
765
|
+
/**
|
|
766
|
+
* Destroys object(s) matching the where query
|
|
767
|
+
* @param {object} where - Object representing the where query
|
|
768
|
+
* @param {object} options - Determines if inserted records should be returned
|
|
769
|
+
* @param {boolean} [options.returnRecords] - Determines if inserted records should be returned
|
|
770
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
771
|
+
* @returns {object[]}
|
|
772
|
+
*/
|
|
773
|
+
destroy(where: WhereQuery<T>, options: DeleteOptions<T>): DestroyResult<T, QueryResult<T>[]>;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
interface ColumnBaseOptions {
|
|
777
|
+
/**
|
|
778
|
+
* Column name in the database
|
|
779
|
+
*/
|
|
780
|
+
name?: string;
|
|
781
|
+
/**
|
|
782
|
+
* Indicates if a value is required for creates.
|
|
783
|
+
*/
|
|
784
|
+
required?: boolean;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
interface ColumnCollectionOptions extends ColumnBaseOptions {
|
|
788
|
+
/**
|
|
789
|
+
* Type of the items in the collection
|
|
790
|
+
*/
|
|
791
|
+
collection: string | (() => string);
|
|
792
|
+
/**
|
|
793
|
+
* Property name of the on the collection item type
|
|
794
|
+
*/
|
|
795
|
+
via: string;
|
|
796
|
+
/**
|
|
797
|
+
* Name of the junction table for multi-multi associations
|
|
798
|
+
*/
|
|
799
|
+
through?: string | (() => string);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
interface ColumnModelOptions extends ColumnBaseOptions {
|
|
803
|
+
/**
|
|
804
|
+
* Type of the entity represented by this column id
|
|
805
|
+
*/
|
|
806
|
+
model: string | (() => string);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
interface ColumnTypeOptions extends ColumnBaseOptions {
|
|
810
|
+
/**
|
|
811
|
+
* Type of the column
|
|
812
|
+
*/
|
|
813
|
+
type: 'array' | 'binary' | 'boolean' | 'boolean[]' | 'date' | 'datetime' | 'float' | 'float[]' | 'integer' | 'integer[]' | 'json' | 'string' | 'string[]';
|
|
814
|
+
/**
|
|
815
|
+
* Default database value
|
|
816
|
+
*/
|
|
817
|
+
defaultsTo?: boolean[] | number[] | string[] | boolean | number | string | (() => Date | Record<string, unknown> | boolean | number | string) | [];
|
|
818
|
+
/**
|
|
819
|
+
* Array of possible enumerated values
|
|
820
|
+
*/
|
|
821
|
+
enum?: string[];
|
|
822
|
+
/**
|
|
823
|
+
* If set, enforces a maximum length check on the column
|
|
824
|
+
*
|
|
825
|
+
* Applies to types: string | string[]
|
|
826
|
+
*/
|
|
827
|
+
maxLength?: number;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
type ColumnOptions$1 = ColumnCollectionOptions | ColumnModelOptions | ColumnTypeOptions;
|
|
831
|
+
type ReturnFunctionType$5 = (object: ClassLike, propertyName: string) => void;
|
|
832
|
+
declare function column(options?: ColumnOptions$1): ReturnFunctionType$5;
|
|
833
|
+
declare function column(dbColumnName: string, options?: ColumnOptions$1): ReturnFunctionType$5;
|
|
834
|
+
|
|
835
|
+
type ReturnFunctionType$4 = (object: ClassLike, propertyName: string) => void;
|
|
836
|
+
declare function createDateColumn(options?: ColumnTypeOptions): ReturnFunctionType$4;
|
|
837
|
+
declare function createDateColumn(dbColumnName: string, options?: ColumnTypeOptions): ReturnFunctionType$4;
|
|
838
|
+
|
|
839
|
+
type ColumnOptions = ColumnModelOptions | ColumnTypeOptions;
|
|
840
|
+
type ReturnFunctionType$3 = (object: ClassLike, propertyName: string) => void;
|
|
841
|
+
declare function primaryColumn(options?: ColumnOptions): ReturnFunctionType$3;
|
|
842
|
+
declare function primaryColumn(dbColumnName: string, options?: ColumnOptions): ReturnFunctionType$3;
|
|
843
|
+
|
|
844
|
+
interface TableOptions {
|
|
845
|
+
/**
|
|
846
|
+
* Table name in the database
|
|
847
|
+
*/
|
|
848
|
+
name?: string;
|
|
849
|
+
/**
|
|
850
|
+
* Connection name to use for queries
|
|
851
|
+
*/
|
|
852
|
+
connection?: string;
|
|
853
|
+
/**
|
|
854
|
+
* Indicates if create, update, delete statements should be available
|
|
855
|
+
*/
|
|
856
|
+
readonly?: boolean;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
type ReturnFunctionType$2 = (object: any) => void;
|
|
860
|
+
declare function table(options?: TableOptions): ReturnFunctionType$2;
|
|
861
|
+
declare function table(dbName: string, options: TableOptions): ReturnFunctionType$2;
|
|
862
|
+
|
|
863
|
+
type ReturnFunctionType$1 = (object: ClassLike, propertyName: string) => void;
|
|
864
|
+
declare function updateDateColumn(options?: ColumnTypeOptions): ReturnFunctionType$1;
|
|
865
|
+
declare function updateDateColumn(dbColumnName: string, options?: ColumnTypeOptions): ReturnFunctionType$1;
|
|
866
|
+
|
|
867
|
+
type ReturnFunctionType = (object: ClassLike, propertyName: string) => void;
|
|
868
|
+
declare function versionColumn(options?: ColumnTypeOptions): ReturnFunctionType;
|
|
869
|
+
declare function versionColumn(dbColumnName: string, options?: ColumnTypeOptions): ReturnFunctionType;
|
|
870
|
+
|
|
871
|
+
interface IConnection {
|
|
872
|
+
pool: Pool;
|
|
873
|
+
readonlyPool?: Pool;
|
|
874
|
+
}
|
|
875
|
+
interface InitializeOptions extends IConnection {
|
|
876
|
+
models: EntityStatic<Entity>[];
|
|
877
|
+
connections?: Record<string, IConnection>;
|
|
878
|
+
expose?: (repository: ReadonlyRepository<Entity> | Repository<Entity>, tableMetadata: ModelMetadata<Entity>) => void;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Initializes BigAl
|
|
882
|
+
* @param {object[]} models - Model classes - used to force decorator evaluation for all models
|
|
883
|
+
* @param {object[]} modelSchemas - Model definitions
|
|
884
|
+
* @param {object} pool - Postgres Pool
|
|
885
|
+
* @param {object} [readonlyPool] - Postgres Pool for `find` and `findOne` operations. If not defined, `pool` will be used
|
|
886
|
+
* @param {object} [connections] - Key: name of the connection; Value: { pool, readonlyPool }
|
|
887
|
+
* @param {Function} [expose] - Used to expose model classes
|
|
888
|
+
* @returns {object} Repositories by model name
|
|
889
|
+
*/
|
|
890
|
+
declare function initialize({ models, pool, readonlyPool, connections, expose }: InitializeOptions): Record<string, IReadonlyRepository<Entity> | IRepository<Entity>>;
|
|
891
|
+
|
|
892
|
+
export { type ClassLike, ColumnBaseMetadata, type ColumnBaseMetadataOptions, ColumnCollectionMetadata, type ColumnCollectionMetadataOptions, type ColumnMetadata, ColumnModelMetadata, type ColumnModelMetadataOptions, type ColumnModifierMetadata, ColumnTypeMetadata, type ColumnTypeMetadataOptions, type CreateUpdateParams, Entity, type EntityFieldValue, type EntityPrimitiveOrId, type EntityStatic, type ExcludeEntityCollections, type ExcludeFunctions, type GetValueType, type IConnection, type IReadonlyRepository, type IRepository, type IRepositoryOptions, type IncludeFunctions, type InitializeOptions, type IsValueOfType, ModelMetadata, type ModelMetadataOptions, type NotEntity, type NotEntityBrand, type OmitEntityCollections, type OmitFunctions, type PickAsType, type PickByValueType, type PickFunctions, type Populated, type QueryResult, type QueryResultOptionalPopulated, type QueryResultPopulated, ReadonlyRepository, Repository, column, createDateColumn, getMetadataStorage, initialize, primaryColumn, table, updateDateColumn, versionColumn };
|