bigal 16.0.0-beta.3 → 16.0.0
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 +1 -1
- package/.vite-hooks/pre-commit +1 -0
- package/CHANGELOG.md +25 -11
- package/CLAUDE.md +4 -4
- package/README.md +29 -43
- package/dist/index.cjs +3274 -4277
- package/dist/index.d.cts +1511 -1425
- package/dist/index.d.mts +1511 -1425
- package/dist/index.mjs +3265 -4244
- package/docs/.vitepress/config.ts +0 -1
- package/docs/advanced/bigal-vs-raw-sql.md +23 -23
- package/docs/advanced/known-issues.md +26 -21
- package/docs/getting-started.md +35 -29
- package/docs/guide/crud-operations.md +42 -61
- package/docs/guide/models.md +97 -396
- package/docs/guide/querying.md +82 -98
- package/docs/guide/relationships.md +125 -90
- package/docs/guide/subqueries-and-joins.md +39 -32
- package/docs/guide/views.md +51 -79
- package/docs/index.md +31 -27
- package/docs/package.json +3 -2
- package/docs/pnpm-lock.yaml +2338 -0
- package/docs/pnpm-workspace.yaml +3 -0
- package/docs/reference/api.md +86 -383
- package/docs/reference/configuration.md +26 -113
- package/package.json +59 -78
- package/pnpm-workspace.yaml +14 -0
- package/release.config.mjs +1 -1
- package/skills/using-bigal/SKILL.md +213 -276
- package/vite.config.ts +83 -0
- package/.husky/pre-commit +0 -4
- package/.oxfmtrc.json +0 -38
- package/.oxlintrc.json +0 -219
- package/dist/index.d.ts +0 -1527
- package/docs/guide/migration-v16.md +0 -594
- package/docs/package-lock.json +0 -3753
- package/scripts/migrate-v16.ts +0 -578
- package/skills/upgrade-v16/SKILL.md +0 -296
package/dist/index.d.mts
CHANGED
|
@@ -1,1527 +1,1613 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
propertyName: string;
|
|
14
|
-
/**
|
|
15
|
-
* Indicates if a value is required for creates.
|
|
16
|
-
*/
|
|
17
|
-
required?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Indicates if column is inserted by default. Default is true
|
|
20
|
-
*/
|
|
21
|
-
insert?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Indicates if column value is updated by "save" operation. Default is true
|
|
24
|
-
*/
|
|
25
|
-
update?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Indicates if this column is a primary key.
|
|
28
|
-
* Same can be achieved when @primaryColumn decorator is used
|
|
29
|
-
*/
|
|
30
|
-
primary?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Value will be equal to `new Date()` when the row is inserted into the table
|
|
33
|
-
* Same can be achieved when @createDateColumn decorator is used
|
|
34
|
-
*/
|
|
35
|
-
createDate?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Value will be equal to `new Date()` when the row is updated
|
|
38
|
-
* Same can be achieved when @updateDateColumn decorator is used
|
|
39
|
-
*/
|
|
40
|
-
updateDate?: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Value will be set to 1 when the row is inserted. Value will be incremented by one when the row is updated
|
|
43
|
-
* Same can be achieved when @versionColumn decorator is used
|
|
44
|
-
*/
|
|
45
|
-
version?: boolean;
|
|
46
|
-
}
|
|
47
|
-
declare abstract class ColumnBaseMetadata {
|
|
48
|
-
/**
|
|
49
|
-
* Name of class with @table decorator
|
|
50
|
-
*/
|
|
51
|
-
target: string;
|
|
52
|
-
/**
|
|
53
|
-
* Column name in the database
|
|
54
|
-
*/
|
|
55
|
-
name: string;
|
|
56
|
-
/**
|
|
57
|
-
* Class property to which the column is applied
|
|
58
|
-
*/
|
|
59
|
-
propertyName: string;
|
|
60
|
-
/**
|
|
61
|
-
* Indicates if a value is required for creates.
|
|
62
|
-
*/
|
|
63
|
-
required: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Indicates if column is inserted by default. Default is true
|
|
66
|
-
*/
|
|
67
|
-
insert: boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Indicates if column value is updated by "save" operation. Default is true
|
|
70
|
-
*/
|
|
71
|
-
update: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Indicates if this column is a primary key.
|
|
74
|
-
* Same can be achieved when @primaryColumn decorator is used
|
|
75
|
-
*/
|
|
76
|
-
primary: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* Value will be equal to `new Date()` when the row is inserted into the table
|
|
79
|
-
* Same can be achieved when @createDateColumn decorator is used
|
|
80
|
-
*/
|
|
81
|
-
createDate: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Value will be equal to `new Date()` when the row is updated
|
|
84
|
-
* Same can be achieved when @updateDateColumn decorator is used
|
|
85
|
-
*/
|
|
86
|
-
updateDate: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Value will be set to 1 when the row is inserted. Value will be incremented by one when the row is updated
|
|
89
|
-
* Same can be achieved when @versionColumn decorator is used
|
|
90
|
-
*/
|
|
91
|
-
version: boolean;
|
|
92
|
-
protected constructor({ target, name, propertyName, required, insert, update, primary, createDate, updateDate, version, }: ColumnBaseMetadataOptions);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
interface ColumnCollectionMetadataOptions extends ColumnBaseMetadataOptions {
|
|
96
|
-
/**
|
|
97
|
-
* Type of the items in the collection
|
|
98
|
-
*/
|
|
99
|
-
collection: string | (() => string);
|
|
100
|
-
/**
|
|
101
|
-
* Property name of the on the collection item type
|
|
102
|
-
*/
|
|
103
|
-
via: string;
|
|
104
|
-
/**
|
|
105
|
-
* Name of the junction table for multi-multi associations
|
|
106
|
-
*/
|
|
107
|
-
through?: string | (() => string);
|
|
108
|
-
}
|
|
109
|
-
declare class ColumnCollectionMetadata extends ColumnBaseMetadata {
|
|
110
|
-
private _collectionString?;
|
|
111
|
-
private _collectionFn?;
|
|
112
|
-
private _throughString?;
|
|
113
|
-
private _throughFn?;
|
|
114
|
-
/**
|
|
115
|
-
* Type of the items in the collection
|
|
116
|
-
* @returns Name of collection
|
|
117
|
-
*/
|
|
118
|
-
get collection(): string;
|
|
119
|
-
/**
|
|
120
|
-
* Property name of the on the collection item type
|
|
121
|
-
*/
|
|
122
|
-
via: string;
|
|
123
|
-
/**
|
|
124
|
-
* Name of the junction table for multi-multi associations
|
|
125
|
-
* @returns Name of junction table
|
|
126
|
-
*/
|
|
127
|
-
get through(): string | undefined;
|
|
128
|
-
constructor({ target, //
|
|
129
|
-
name, propertyName, required, insert, update, primary, createDate, updateDate, version, collection, via, through, }: ColumnCollectionMetadataOptions);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
interface ColumnModelMetadataOptions extends ColumnBaseMetadataOptions {
|
|
133
|
-
/**
|
|
134
|
-
* Name of the model represented by this column id
|
|
135
|
-
*/
|
|
136
|
-
model: string | (() => string);
|
|
137
|
-
}
|
|
138
|
-
declare class ColumnModelMetadata extends ColumnBaseMetadata {
|
|
139
|
-
private _modelString?;
|
|
140
|
-
private _modelFn?;
|
|
141
|
-
/**
|
|
142
|
-
* Name of the model represented by this column id
|
|
143
|
-
* @returns Name of model
|
|
144
|
-
*/
|
|
145
|
-
get model(): string;
|
|
146
|
-
constructor({ target, //
|
|
147
|
-
name, propertyName, required, insert, update, primary, createDate, updateDate, version, model, }: ColumnModelMetadataOptions);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
interface ColumnTypeMetadataOptions extends ColumnBaseMetadataOptions {
|
|
151
|
-
/**
|
|
152
|
-
* Type of sql column
|
|
153
|
-
*/
|
|
154
|
-
type: 'array' | 'binary' | 'boolean' | 'boolean[]' | 'date' | 'datetime' | 'float' | 'float[]' | 'integer' | 'integer[]' | 'json' | 'string' | 'string[]' | 'uuid' | 'uuid[]';
|
|
155
|
-
/**
|
|
156
|
-
* Default database value
|
|
157
|
-
*/
|
|
158
|
-
defaultsTo?: boolean[] | number[] | string[] | boolean | number | string | (() => Date | Record<string, unknown> | boolean | number | string) | [];
|
|
159
|
-
/**
|
|
160
|
-
* Array of possible enumerated values
|
|
161
|
-
*/
|
|
162
|
-
enum?: readonly string[];
|
|
163
|
-
/**
|
|
164
|
-
* If set, enforces a maximum length check on the column
|
|
165
|
-
*
|
|
166
|
-
* Applies to types: string | string[]
|
|
167
|
-
*/
|
|
168
|
-
maxLength?: number;
|
|
169
|
-
}
|
|
170
|
-
declare class ColumnTypeMetadata extends ColumnBaseMetadata {
|
|
171
|
-
/**
|
|
172
|
-
* Type of the column
|
|
173
|
-
*/
|
|
174
|
-
type: 'array' | 'binary' | 'boolean' | 'boolean[]' | 'date' | 'datetime' | 'float' | 'float[]' | 'integer' | 'integer[]' | 'json' | 'string' | 'string[]' | 'uuid' | 'uuid[]';
|
|
175
|
-
/**
|
|
176
|
-
* Default database value
|
|
177
|
-
*/
|
|
178
|
-
defaultsTo?: boolean[] | number[] | string[] | boolean | number | string | (() => Date | Record<string, unknown> | boolean | number | string) | [];
|
|
179
|
-
/**
|
|
180
|
-
* Array of possible enumerated values
|
|
181
|
-
*/
|
|
182
|
-
enum?: readonly string[];
|
|
183
|
-
/**
|
|
184
|
-
* If set, enforces a maximum length check on the column
|
|
185
|
-
*
|
|
186
|
-
* Applies to types: string | string[]
|
|
187
|
-
*/
|
|
188
|
-
maxLength?: number;
|
|
189
|
-
constructor(options: ColumnTypeMetadataOptions);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
type ColumnMetadata$1 = ColumnCollectionMetadata | ColumnModelMetadata | ColumnTypeMetadata;
|
|
193
|
-
|
|
194
|
-
interface ColumnModifierMetadata {
|
|
195
|
-
/**
|
|
196
|
-
* Name of class with @table decorator
|
|
197
|
-
*/
|
|
198
|
-
target: string;
|
|
199
|
-
/**
|
|
200
|
-
* Column name in the database
|
|
201
|
-
*/
|
|
202
|
-
name?: string;
|
|
203
|
-
/**
|
|
204
|
-
* Class property to which the column is applied
|
|
205
|
-
*/
|
|
206
|
-
propertyName: string;
|
|
207
|
-
/**
|
|
208
|
-
* Indicates if a value is required for creates.
|
|
209
|
-
*/
|
|
210
|
-
required?: boolean;
|
|
211
|
-
/**
|
|
212
|
-
* Indicates if this column is a primary key.
|
|
213
|
-
* Same can be achieved when @primaryColumn decorator is used
|
|
214
|
-
*/
|
|
215
|
-
primary?: boolean;
|
|
216
|
-
/**
|
|
217
|
-
* Value will be equal to `new Date()` when the row is inserted into the table
|
|
218
|
-
* Same can be achieved when @createDateColumn decorator is used
|
|
219
|
-
*/
|
|
220
|
-
createDate?: boolean;
|
|
221
|
-
/**
|
|
222
|
-
* Value will be equal to `new Date()` when the row is updated
|
|
223
|
-
* Same can be achieved when @updateDateColumn decorator is used
|
|
224
|
-
*/
|
|
225
|
-
updateDate?: boolean;
|
|
226
|
-
/**
|
|
227
|
-
* Value will be set to 1 when the row is inserted. Value will be incremented by one when the row is updated
|
|
228
|
-
* Same can be achieved when @versionColumn decorator is used
|
|
229
|
-
*/
|
|
230
|
-
version?: boolean;
|
|
231
|
-
/**
|
|
232
|
-
* Type of sql column
|
|
233
|
-
*/
|
|
234
|
-
type?: 'array' | 'binary' | 'boolean' | 'boolean[]' | 'date' | 'datetime' | 'float' | 'float[]' | 'integer' | 'integer[]' | 'json' | 'string' | 'string[]';
|
|
235
|
-
/**
|
|
236
|
-
* Name of the model represented by this column id
|
|
237
|
-
*/
|
|
238
|
-
model?: string | (() => string);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
type Column = ColumnCollectionMetadata | ColumnModelMetadata | ColumnTypeMetadata;
|
|
242
|
-
type ColumnByStringId$1 = Record<string, Column>;
|
|
243
|
-
interface ModelMetadataOptions<_T extends Record<string, unknown>> {
|
|
244
|
-
name: string;
|
|
245
|
-
type?: {
|
|
246
|
-
new (): unknown;
|
|
247
|
-
};
|
|
248
|
-
connection?: string;
|
|
249
|
-
schema?: string;
|
|
250
|
-
tableName?: string;
|
|
251
|
-
readonly?: boolean;
|
|
252
|
-
}
|
|
253
|
-
declare class ModelMetadata<_T extends Record<string, unknown>> {
|
|
254
|
-
private _columns;
|
|
255
|
-
private _primaryKeyColumn;
|
|
256
|
-
private _createDateColumns;
|
|
257
|
-
private _updateDateColumns;
|
|
258
|
-
private _versionDateColumns;
|
|
259
|
-
set columns(columns: readonly Column[]);
|
|
260
|
-
get columns(): readonly Column[];
|
|
261
|
-
get primaryKeyColumn(): Column | undefined;
|
|
262
|
-
get createDateColumns(): readonly Column[];
|
|
263
|
-
get updateDateColumns(): readonly Column[];
|
|
264
|
-
get versionColumns(): readonly Column[];
|
|
265
|
-
get qualifiedTableName(): string;
|
|
266
|
-
name: string;
|
|
267
|
-
type?: {
|
|
268
|
-
new (): unknown;
|
|
269
|
-
};
|
|
270
|
-
connection?: string;
|
|
271
|
-
schema?: string;
|
|
272
|
-
tableName: string;
|
|
273
|
-
readonly: boolean;
|
|
274
|
-
columnsByColumnName: ColumnByStringId$1;
|
|
275
|
-
columnsByPropertyName: ColumnByStringId$1;
|
|
276
|
-
constructor({ name, //
|
|
277
|
-
type, connection, schema, tableName, readonly, }: ModelMetadataOptions<_T>);
|
|
278
|
-
}
|
|
279
|
-
|
|
1
|
+
//#region src/types/ClassLike.d.ts
|
|
2
|
+
interface ClassLike {
|
|
3
|
+
/**
|
|
4
|
+
* Returns the name of the function. Function names are read-only and can not be changed.
|
|
5
|
+
*/
|
|
6
|
+
readonly constructor: {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/types/PoolLike.d.ts
|
|
280
12
|
/**
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
13
|
+
* Represents a row returned from a PostgreSQL query.
|
|
14
|
+
* Compatible with pg's QueryResultRow type.
|
|
15
|
+
*/
|
|
284
16
|
interface QueryResultRow {
|
|
285
|
-
|
|
17
|
+
[column: string]: any;
|
|
286
18
|
}
|
|
287
19
|
interface PoolQueryResult<TRow extends QueryResultRow> {
|
|
288
|
-
|
|
289
|
-
|
|
20
|
+
rows: TRow[];
|
|
21
|
+
rowCount: number | null;
|
|
290
22
|
}
|
|
291
23
|
/**
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
24
|
+
* Minimal interface for a PostgreSQL connection pool.
|
|
25
|
+
* This interface is compatible with postgres-pool, node-postgres (pg),
|
|
26
|
+
* `@neondatabase/serverless`, and other pg-compatible drivers.
|
|
27
|
+
*/
|
|
296
28
|
interface PoolLike {
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Makes all properties optional for create/update operations.
|
|
302
|
-
* BelongsTo fields already accept both FK values and entity objects via `EntityOrId` in InferSelect.
|
|
303
|
-
*/
|
|
304
|
-
type CreateUpdateParams<T extends Record<string, unknown>> = {
|
|
305
|
-
[K in keyof T]?: T[K];
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Accepts either a FK value or an entity object with a matching `id` property.
|
|
310
|
-
* BigAl extracts the primary key at runtime when an object is provided.
|
|
311
|
-
*
|
|
312
|
-
* @example
|
|
313
|
-
* ```ts
|
|
314
|
-
* // Both are valid for a belongsTo field:
|
|
315
|
-
* product.store = 5; // FK value
|
|
316
|
-
* product.store = { id: 5, name: 'Acme' }; // Entity object
|
|
317
|
-
* ```
|
|
318
|
-
*/
|
|
319
|
-
type EntityOrId<TFk> = TFk | (Record<string, unknown> & {
|
|
320
|
-
id: TFk;
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
interface BelongsToConfig<TFkType = number, TModelName extends string = string> {
|
|
324
|
-
brand: 'belongsTo';
|
|
325
|
-
fkType: TFkType;
|
|
326
|
-
modelName: TModelName;
|
|
327
|
-
}
|
|
328
|
-
declare class BelongsToBuilder<TFkType = number, TModelName extends string = string> {
|
|
329
|
-
readonly _: BelongsToConfig<TFkType, TModelName>;
|
|
330
|
-
/** Explicit FK column name, or empty string to auto-derive from property key */
|
|
331
|
-
dbColumnName: string;
|
|
332
|
-
readonly modelRef: string;
|
|
333
|
-
constructor(modelRef: string, dbColumnName?: string);
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Defines a many-to-one (belongsTo) relationship.
|
|
337
|
-
*
|
|
338
|
-
* The FK column name is auto-derived as `snakeCase(propertyKey) + '_id'` by `table()`.
|
|
339
|
-
* Pass an explicit name to override: `belongsTo('Store', { name: 'shop_id' })`.
|
|
340
|
-
*
|
|
341
|
-
* @param {string} modelRef - Model name string (resolved at initialize() time)
|
|
342
|
-
* @param {string | object} [options] - FK column name string or options object with `name`
|
|
343
|
-
*/
|
|
344
|
-
declare function belongsTo<TFkType = number, TModelName extends string = string>(modelRef: TModelName, options?: string | {
|
|
345
|
-
name: string;
|
|
346
|
-
}): BelongsToBuilder<TFkType, TModelName>;
|
|
347
|
-
|
|
348
|
-
interface ColumnBuilderConfig<TData = unknown, TNotNull extends boolean = boolean, THasDefault extends boolean = boolean, TIsPrimaryKey extends boolean = boolean, TIsAutoSet extends boolean = boolean> {
|
|
349
|
-
brand: 'column';
|
|
350
|
-
data: TData;
|
|
351
|
-
notNull: TNotNull;
|
|
352
|
-
hasDefault: THasDefault;
|
|
353
|
-
isPrimaryKey: TIsPrimaryKey;
|
|
354
|
-
isAutoSet: TIsAutoSet;
|
|
355
|
-
}
|
|
356
|
-
interface ColumnBuilderRuntimeConfig {
|
|
357
|
-
dbColumnName: string;
|
|
358
|
-
columnType: string;
|
|
359
|
-
isNotNull: boolean;
|
|
360
|
-
hasDefaultValue: boolean;
|
|
361
|
-
isPrimaryKey: boolean;
|
|
362
|
-
isAutoSet: boolean;
|
|
363
|
-
isUnique: boolean;
|
|
364
|
-
isCreateDate: boolean;
|
|
365
|
-
isUpdateDate: boolean;
|
|
366
|
-
isVersion: boolean;
|
|
367
|
-
defaultValue: unknown;
|
|
368
|
-
maxLength: number | undefined;
|
|
369
|
-
}
|
|
370
|
-
declare class ColumnBuilder<TConfig extends ColumnBuilderConfig = ColumnBuilderConfig> {
|
|
371
|
-
readonly _: TConfig;
|
|
372
|
-
readonly config: ColumnBuilderRuntimeConfig;
|
|
373
|
-
constructor(columnType: string, dbColumnName?: string);
|
|
374
|
-
notNull(): ColumnBuilder<TConfig & {
|
|
375
|
-
notNull: true;
|
|
376
|
-
}>;
|
|
377
|
-
default(value: TConfig['data']): ColumnBuilder<TConfig & {
|
|
378
|
-
hasDefault: true;
|
|
379
|
-
}>;
|
|
380
|
-
primaryKey(): ColumnBuilder<TConfig & {
|
|
381
|
-
notNull: true;
|
|
382
|
-
hasDefault: true;
|
|
383
|
-
isPrimaryKey: true;
|
|
384
|
-
}>;
|
|
385
|
-
unique(): ColumnBuilder<TConfig>;
|
|
386
|
-
version(): ColumnBuilder<TConfig & {
|
|
387
|
-
notNull: true;
|
|
388
|
-
}>;
|
|
389
|
-
toColumnTypeMetadataOptions(propertyName: string, tableName: string): ColumnTypeMetadataOptions;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
interface HasManyConfig<TModelName extends string = string> {
|
|
393
|
-
brand: 'hasMany';
|
|
394
|
-
modelName: TModelName;
|
|
395
|
-
}
|
|
396
|
-
interface HasManyThroughIntermediate<TModelName extends string = string> {
|
|
397
|
-
via(propertyName: string): HasManyBuilder<TModelName>;
|
|
398
|
-
}
|
|
399
|
-
declare class HasManyBuilder<TModelName extends string = string> {
|
|
400
|
-
readonly _: HasManyConfig<TModelName>;
|
|
401
|
-
readonly modelRef: string;
|
|
402
|
-
viaPropertyName: string | undefined;
|
|
403
|
-
throughRef: string | undefined;
|
|
404
|
-
constructor(modelRef: string);
|
|
405
|
-
via(propertyName: string): HasManyBuilder<TModelName>;
|
|
406
|
-
through(throughRef: string): HasManyThroughIntermediate<TModelName>;
|
|
29
|
+
query<TRow extends QueryResultRow = QueryResultRow>(text: string, values?: readonly unknown[]): Promise<PoolQueryResult<TRow>>;
|
|
407
30
|
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/types/ExcludeEntityCollections.d.ts
|
|
408
33
|
/**
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Any value that can appear in a schema definition object passed to `table()`.
|
|
417
|
-
*/
|
|
418
|
-
type SchemaEntry = BelongsToBuilder<unknown> | ColumnBuilder<ColumnBuilderConfig> | HasManyBuilder;
|
|
419
|
-
/**
|
|
420
|
-
* A schema definition is a record of property names to schema entries.
|
|
421
|
-
*/
|
|
422
|
-
type SchemaDefinition = Record<string, SchemaEntry>;
|
|
423
|
-
/** Keys for columns and belongsTo (actual database columns) */
|
|
424
|
-
type ColumnKeys<TSchema extends SchemaDefinition> = {
|
|
425
|
-
[K in keyof TSchema]: TSchema[K] extends HasManyBuilder ? never : K;
|
|
426
|
-
}[keyof TSchema];
|
|
427
|
-
/** Keys for hasMany relationships (collections, available for populate) */
|
|
428
|
-
type CollectionKeys<TSchema extends SchemaDefinition> = {
|
|
429
|
-
[K in keyof TSchema]: TSchema[K] extends HasManyBuilder ? K : never;
|
|
430
|
-
}[keyof TSchema];
|
|
431
|
-
/** All keys from the schema (columns + collections). Used for external consumers. */
|
|
432
|
-
type SelectKeys<TSchema extends SchemaDefinition> = keyof TSchema & string;
|
|
433
|
-
/**
|
|
434
|
-
* Keys that are required on insert: notNull columns that have no default, are not primary keys, and are not auto-set.
|
|
435
|
-
* BelongsTo FK columns are always required on insert (they represent a foreign key value).
|
|
436
|
-
*/
|
|
437
|
-
type RequiredInsertKeys<TSchema extends SchemaDefinition> = {
|
|
438
|
-
[K in keyof TSchema]: TSchema[K] extends HasManyBuilder ? never : TSchema[K] extends BelongsToBuilder<unknown> ? K : TSchema[K] extends ColumnBuilder<infer TConf> ? TConf extends {
|
|
439
|
-
notNull: true;
|
|
440
|
-
} ? TConf extends {
|
|
441
|
-
hasDefault: true;
|
|
442
|
-
} ? never : TConf extends {
|
|
443
|
-
isPrimaryKey: true;
|
|
444
|
-
} ? never : TConf extends {
|
|
445
|
-
isAutoSet: true;
|
|
446
|
-
} ? never : K : never : never;
|
|
447
|
-
}[keyof TSchema];
|
|
448
|
-
/**
|
|
449
|
-
* Keys that are optional on insert: nullable columns, columns with defaults, primary keys, and auto-set columns.
|
|
450
|
-
* HasMany keys are excluded entirely.
|
|
451
|
-
*/
|
|
452
|
-
type OptionalInsertKeys<TSchema extends SchemaDefinition> = Exclude<ColumnKeys<TSchema>, RequiredInsertKeys<TSchema>>;
|
|
453
|
-
/**
|
|
454
|
-
* Extracts the TypeScript select type for a single schema entry.
|
|
455
|
-
* - ColumnBuilder: `TData` if notNull, otherwise `TData | null`
|
|
456
|
-
* - BelongsToBuilder: `EntityOrId<TFk>` - accepts FK value or entity object with matching id.
|
|
457
|
-
* Use `QueryResult` to narrow back to just the FK type for query results.
|
|
458
|
-
* - HasManyBuilder: never (excluded at the key level)
|
|
459
|
-
*/
|
|
460
|
-
type InferSelectColumn<TEntry extends SchemaEntry> = TEntry extends ColumnBuilder<infer TConf> ? (TConf extends {
|
|
461
|
-
notNull: true;
|
|
462
|
-
} ? TConf['data'] : TConf['data'] | null) : TEntry extends BelongsToBuilder<infer TFk> ? EntityOrId<TFk> : never;
|
|
463
|
-
/**
|
|
464
|
-
* Extracts the TypeScript insert type for a single schema entry.
|
|
465
|
-
* Same widening as select: belongsTo accepts FK value or entity object.
|
|
466
|
-
*/
|
|
467
|
-
type InferInsertColumn<TEntry extends SchemaEntry> = TEntry extends ColumnBuilder<infer TConf> ? (TConf extends {
|
|
468
|
-
notNull: true;
|
|
469
|
-
} ? TConf['data'] : TConf['data'] | null) : TEntry extends BelongsToBuilder<infer TFk> ? EntityOrId<TFk> : never;
|
|
34
|
+
* Removes all entity collection properties. To be used as a re-map key function
|
|
35
|
+
*/
|
|
36
|
+
type ExcludeEntityCollections<T, K extends PropertyKey> = T extends NotEntityBrand[] | undefined ? K : T extends Entity[] | undefined ? never : K;
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/types/ExcludeFunctions.d.ts
|
|
470
39
|
/**
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
* Use `QueryResult` to narrow for query results (strips hasMany, narrows belongsTo to FK).
|
|
474
|
-
*/
|
|
475
|
-
type InferSelect<TSchema extends SchemaDefinition> = {
|
|
476
|
-
[K in ColumnKeys<TSchema>]: InferSelectColumn<TSchema[K]>;
|
|
477
|
-
} & {
|
|
478
|
-
[K in CollectionKeys<TSchema>]?: Record<string, unknown>[];
|
|
479
|
-
};
|
|
480
|
-
/**
|
|
481
|
-
* Infers the insert (write) type from a schema definition.
|
|
482
|
-
* Required keys are non-nullable columns without defaults.
|
|
483
|
-
* Optional keys include nullable columns, columns with defaults, primary keys, and auto-set columns.
|
|
484
|
-
* HasMany relationships are excluded entirely.
|
|
485
|
-
*/
|
|
486
|
-
type InferInsert<TSchema extends SchemaDefinition> = {
|
|
487
|
-
[K in RequiredInsertKeys<TSchema>]: InferInsertColumn<TSchema[K]>;
|
|
488
|
-
} & {
|
|
489
|
-
[K in OptionalInsertKeys<TSchema>]?: InferInsertColumn<TSchema[K]>;
|
|
490
|
-
};
|
|
491
|
-
/** Keys in the schema that are BelongsToBuilder (many-to-one FK columns) */
|
|
492
|
-
type BelongsToKeys<TSchema extends SchemaDefinition> = {
|
|
493
|
-
[K in keyof TSchema]: TSchema[K] extends BelongsToBuilder<unknown> ? K : never;
|
|
494
|
-
}[keyof TSchema];
|
|
495
|
-
/** Keys in the schema that are HasManyBuilder (collection relationships) */
|
|
496
|
-
type HasManyKeys<TSchema extends SchemaDefinition> = {
|
|
497
|
-
[K in keyof TSchema]: TSchema[K] extends HasManyBuilder ? K : never;
|
|
498
|
-
}[keyof TSchema];
|
|
499
|
-
/** Keys in the schema that are any relationship (belongsTo or hasMany) */
|
|
500
|
-
type RelationshipKeys<TSchema extends SchemaDefinition> = BelongsToKeys<TSchema> | HasManyKeys<TSchema>;
|
|
501
|
-
/** Keys that are populate-able (both belongsTo and hasMany). Falls back to all string keys when schema is default. */
|
|
502
|
-
type PopulatableKeys<TSchema extends SchemaDefinition> = SchemaDefinition extends TSchema ? string : RelationshipKeys<TSchema>;
|
|
503
|
-
/** Extracts the branded model name string from a schema entry */
|
|
504
|
-
type ModelNameOf<TEntry extends SchemaEntry> = TEntry extends BelongsToBuilder<unknown, infer TName> ? TName : TEntry extends HasManyBuilder<infer TName> ? TName : never;
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* Excludes hasMany collection keys from K when a concrete TSchema is provided.
|
|
508
|
-
* Falls back to passing through all keys when TSchema is the default.
|
|
509
|
-
*/
|
|
510
|
-
type ExcludeEntityCollections<K extends PropertyKey, TSchema extends SchemaDefinition = SchemaDefinition> = SchemaDefinition extends TSchema ? K : K extends HasManyKeys<TSchema> ? never : K;
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* Removes all functions and entity collection properties. To be used as a re-map key function
|
|
514
|
-
*/
|
|
40
|
+
* Removes all functions and entity collection properties. To be used as a re-map key function
|
|
41
|
+
*/
|
|
515
42
|
type ExcludeFunctions<T, K extends PropertyKey> = T extends Function ? never : K;
|
|
516
|
-
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/types/CreateUpdateParams.d.ts
|
|
45
|
+
/**
|
|
46
|
+
* Changes all Entity value properties to Primitive (string|number) | Pick<Entity, 'id'>
|
|
47
|
+
*/
|
|
48
|
+
type CreateUpdateParams<T extends Entity> = { [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"> };
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/types/EntityPrimitiveOrId.d.ts
|
|
51
|
+
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">;
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/types/GetValueType.d.ts
|
|
517
54
|
type GetValueType<T, TValueType> = T extends TValueType[] ? T extends (infer U)[] ? Extract<U, TValueType> : never : T extends TValueType ? T : never;
|
|
518
|
-
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/types/IncludeFunctions.d.ts
|
|
519
57
|
/**
|
|
520
|
-
|
|
521
|
-
|
|
58
|
+
* Returns the key name if the property type is a function
|
|
59
|
+
*/
|
|
522
60
|
type IncludeFunctions<T, K extends PropertyKey> = T extends Function ? K : never;
|
|
523
|
-
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/types/IsValueOfType.d.ts
|
|
524
63
|
type IsValueOfType<T, K extends PropertyKey, TValueType> = T extends TValueType | TValueType[] | undefined ? K : never;
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
* When TSchema is the default (SchemaDefinition), falls back to all string keys.
|
|
531
|
-
*/
|
|
532
|
-
type ModelRelationshipKeys<T extends Record<string, unknown>, TSchema extends SchemaDefinition = SchemaDefinition> = SchemaDefinition extends TSchema ? string & keyof T : string & RelationshipKeys<TSchema> & keyof T;
|
|
533
|
-
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/types/ModelRelationshipKeys.d.ts
|
|
66
|
+
type ModelRelationshipKeys<T extends Entity> = { [K in keyof T]: Extract<T[K], Entity> extends never ? never : K }[keyof T] & string;
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/types/OmitEntityCollections.d.ts
|
|
534
69
|
/**
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
70
|
+
* Removes all entity collection properties
|
|
71
|
+
*/
|
|
72
|
+
type OmitEntityCollections<T> = { [K in keyof T as ExcludeEntityCollections<T[K], K>]: T[K] };
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/types/OmitFunctions.d.ts
|
|
541
75
|
/**
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
type OmitFunctions<T> = {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
};
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
type PickFunctions<T> = {
|
|
557
|
-
[K in keyof T as IncludeFunctions<T[K], K>]: T[K];
|
|
558
|
-
};
|
|
559
|
-
|
|
560
|
-
type ColumnMetadata = ColumnCollectionMetadata | ColumnModelMetadata | ColumnTypeMetadata;
|
|
561
|
-
type ColumnByStringId = Record<string, ColumnMetadata>;
|
|
562
|
-
interface ModelHooks<TInsert, TSelect = TInsert> {
|
|
563
|
-
beforeCreate?: (values: TInsert) => Promise<TInsert> | TInsert;
|
|
564
|
-
afterCreate?: (result: TSelect) => Promise<void> | void;
|
|
565
|
-
beforeUpdate?: (values: Partial<TInsert>) => Partial<TInsert> | Promise<Partial<TInsert>>;
|
|
566
|
-
afterUpdate?: (result: TSelect) => Promise<void> | void;
|
|
567
|
-
beforeDestroy?: (where: Record<string, unknown>) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
568
|
-
afterDestroy?: (result: {
|
|
569
|
-
rowCount: number;
|
|
570
|
-
}) => Promise<void> | void;
|
|
571
|
-
afterFind?: (results: TSelect[]) => Promise<TSelect[]> | TSelect[];
|
|
572
|
-
}
|
|
573
|
-
/** A filter definition: a static where clause or a function that returns one dynamically */
|
|
574
|
-
type FilterDefinition = (() => Record<string, unknown>) | Record<string, unknown>;
|
|
575
|
-
interface TableOptions<TInsert, TSelect = TInsert> {
|
|
576
|
-
/** Unique model name for relationship lookups. Defaults to the table name. */
|
|
577
|
-
modelName?: string;
|
|
578
|
-
schema?: string;
|
|
579
|
-
readonly?: boolean;
|
|
580
|
-
connection?: string;
|
|
581
|
-
hooks?: ModelHooks<TInsert, TSelect>;
|
|
582
|
-
/** Named filters applied automatically to every query. Override per-query via `filters` option. */
|
|
583
|
-
filters?: Record<string, FilterDefinition>;
|
|
584
|
-
}
|
|
585
|
-
interface TableDefinition<TName extends string = string, TSchema extends SchemaDefinition = SchemaDefinition> {
|
|
586
|
-
/** Unique model name used for relationship lookups. Defaults to tableName. */
|
|
587
|
-
readonly modelName: string;
|
|
588
|
-
readonly tableName: TName;
|
|
589
|
-
readonly dbSchema: string | undefined;
|
|
590
|
-
readonly isReadonly: boolean;
|
|
591
|
-
readonly connection: string | undefined;
|
|
592
|
-
readonly schema: TSchema;
|
|
593
|
-
readonly hooks: ModelHooks<InferInsert<TSchema>, InferSelect<TSchema>> | undefined;
|
|
594
|
-
readonly filters: Record<string, FilterDefinition> | undefined;
|
|
595
|
-
readonly columnsByPropertyName: Readonly<ColumnByStringId>;
|
|
596
|
-
readonly columnsByColumnName: Readonly<ColumnByStringId>;
|
|
597
|
-
readonly columns: readonly ColumnMetadata[];
|
|
598
|
-
readonly primaryKeyColumn: ColumnMetadata | undefined;
|
|
599
|
-
readonly createDateColumns: readonly ColumnMetadata[];
|
|
600
|
-
readonly updateDateColumns: readonly ColumnMetadata[];
|
|
601
|
-
readonly versionColumns: readonly ColumnMetadata[];
|
|
602
|
-
readonly belongsToEntries: readonly BelongsToEntry[];
|
|
603
|
-
readonly hasManyEntries: readonly HasManyEntry[];
|
|
604
|
-
}
|
|
605
|
-
interface BelongsToEntry {
|
|
606
|
-
readonly propertyName: string;
|
|
607
|
-
readonly builder: BelongsToBuilder<unknown>;
|
|
608
|
-
}
|
|
609
|
-
interface HasManyEntry {
|
|
610
|
-
readonly propertyName: string;
|
|
611
|
-
readonly builder: HasManyBuilder;
|
|
612
|
-
}
|
|
613
|
-
declare function table<TName extends string, TSchema extends SchemaDefinition>(tableName: TName, schemaDefinition: TSchema, options?: TableOptions<InferInsert<TSchema>, InferSelect<TSchema>>): TableDefinition<TName, TSchema>;
|
|
76
|
+
* Removes all functions
|
|
77
|
+
*/
|
|
78
|
+
type OmitFunctions<T> = { [K in keyof T as ExcludeFunctions<T[K], K>]: T[K] };
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/types/PickAsType.d.ts
|
|
81
|
+
type PickAsType<T, K extends keyof T, TValue> = { [P in K]: Extract<T[P], TValue> };
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/types/PickByValueType.d.ts
|
|
84
|
+
type PickByValueType<T, TValueType> = { [K in keyof T as IsValueOfType<T[K], K, TValueType>]: GetValueType<T[K], TValueType> };
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/types/PickFunctions.d.ts
|
|
87
|
+
type PickFunctions<T> = { [K in keyof T as IncludeFunctions<T[K], K>]: T[K] };
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/types/PlainObject.d.ts
|
|
614
90
|
/**
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
declare function view<TName extends string, TSchema extends SchemaDefinition>(viewName: TName, schemaDefinition: TSchema, options?: Omit<TableOptions<InferInsert<TSchema>, InferSelect<TSchema>>, 'readonly'>): TableDefinition<TName, TSchema>;
|
|
623
|
-
|
|
91
|
+
* Recursively converts entity types to plain object types.
|
|
92
|
+
* This is primarily for documentation/intent - at runtime, this strips the prototype chain.
|
|
93
|
+
* Preserves Date objects as-is since they're serializable by most frameworks.
|
|
94
|
+
*/
|
|
95
|
+
type PlainObject<T> = T extends Date ? Date : T extends (infer U)[] ? PlainObject<U>[] : T extends object ? { [K in keyof T]: PlainObject<T[K]> } : T;
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/types/QueryResult.d.ts
|
|
624
98
|
/**
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
* - `QueryResult<typeof Product>` - from a model definition or repository
|
|
632
|
-
* - `QueryResult<ProductRow>` - from a plain row type (backward compat)
|
|
633
|
-
*/
|
|
634
|
-
type AnyTableDef$2 = TableDefinition<string, any>;
|
|
635
|
-
/** Narrows belongsTo fields to FK type and excludes hasMany */
|
|
636
|
-
type NarrowForQuery<TSchema extends SchemaDefinition> = {
|
|
637
|
-
[K in Exclude<keyof InferSelect<TSchema>, HasManyKeys<TSchema>>]: K extends BelongsToKeys<TSchema> ? TSchema[K & keyof TSchema] extends BelongsToBuilder<infer TFk> ? TFk : InferSelect<TSchema>[K] : InferSelect<TSchema>[K];
|
|
638
|
-
};
|
|
639
|
-
/** Structural match for repositories - carries schema via phantom `_schema` property */
|
|
640
|
-
interface HasSchema$1<TSchema extends SchemaDefinition = SchemaDefinition> {
|
|
641
|
-
readonly _schema?: TSchema;
|
|
642
|
-
}
|
|
643
|
-
type ResolveFromSchema<TSchema extends SchemaDefinition> = SchemaDefinition extends TSchema ? never : NarrowForQuery<TSchema>;
|
|
644
|
-
type QueryResult<T extends AnyTableDef$2 | HasSchema$1 | Record<string, unknown>, TSchema extends SchemaDefinition = SchemaDefinition> = T extends TableDefinition<string, infer TInferredSchema> ? NarrowForQuery<TInferredSchema> : T extends {
|
|
645
|
-
_schema?: infer TRepoSchema extends SchemaDefinition;
|
|
646
|
-
} ? ResolveFromSchema<TRepoSchema> extends never ? SchemaDefinition extends TSchema ? T : Omit<T, HasManyKeys<TSchema> & keyof T> : ResolveFromSchema<TRepoSchema> : SchemaDefinition extends TSchema ? T : Omit<T, HasManyKeys<TSchema> & keyof T>;
|
|
647
|
-
|
|
99
|
+
* Changes all properties with Entity values to Primitive (string|number). Removes any properties that with values
|
|
100
|
+
* of Entity arrays
|
|
101
|
+
*/
|
|
102
|
+
type QueryResult<T extends Entity> = Extract<{ [K in keyof T as ExcludeEntityCollections<NonNullable<T[K]>, K>]: T[K] extends NotEntityBrand | undefined ? T[K] : Exclude<T[K], Entity> }, T>;
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/types/Populated.d.ts
|
|
648
105
|
/**
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
};
|
|
655
|
-
|
|
106
|
+
* Removes primitives from specified properties and make non-optional. Allow singular Entity properties to be null.
|
|
107
|
+
*/
|
|
108
|
+
type Populated<T extends Entity, K extends keyof T, TPropertyType extends Entity, TPropertyKeys extends keyof TPropertyType> = { [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">>[] };
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/types/QueryResultPopulated.d.ts
|
|
656
111
|
/**
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
};
|
|
663
|
-
|
|
664
|
-
type AnyModel$5 = TableDefinition<string, any>;
|
|
112
|
+
* Allows a QueryResult type with specific populated properties
|
|
113
|
+
*/
|
|
114
|
+
type QueryResultPopulated<T extends Entity, K extends keyof T> = Omit<QueryResult<T>, K> & { [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>>[] };
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/types/QueryResultOptionalPopulated.d.ts
|
|
665
117
|
/**
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
type
|
|
118
|
+
* Allows a QueryResult type with specific properties optionally populated. If the property is populated, only the id property is needed
|
|
119
|
+
*/
|
|
120
|
+
type QueryResultOptionalPopulated<T extends Entity, K extends keyof T> = Omit<QueryResult<T>, K> & { [P in K]-?: T[P] extends [] ? undefined extends T[P] ? EntityPrimitiveOrId<T[P]> | null : EntityPrimitiveOrId<T[P]> : EntityPrimitiveOrId<T[P]> };
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/Entity.d.ts
|
|
123
|
+
type EntityFieldValue = boolean[] | Date | number[] | Record<string, unknown> | string[] | boolean | number | string | unknown | null;
|
|
124
|
+
declare abstract class Entity {
|
|
125
|
+
abstract id: unknown;
|
|
126
|
+
static beforeCreate(values: CreateUpdateParams<Entity>): CreateUpdateParams<Entity> | Promise<CreateUpdateParams<Entity>>;
|
|
127
|
+
static beforeUpdate(values: CreateUpdateParams<Entity>): CreateUpdateParams<Entity> | Promise<CreateUpdateParams<Entity>>;
|
|
128
|
+
}
|
|
129
|
+
interface NotEntityBrand {
|
|
130
|
+
_notEntityBrand: void;
|
|
131
|
+
}
|
|
132
|
+
type NotEntity<T> = NotEntityBrand & T;
|
|
133
|
+
interface EntityStatic<T extends Entity> {
|
|
134
|
+
beforeCreate?: (values: CreateUpdateParams<any>) => CreateUpdateParams<any> | Promise<CreateUpdateParams<any>>;
|
|
135
|
+
beforeUpdate?: (values: CreateUpdateParams<any>) => CreateUpdateParams<any> | Promise<CreateUpdateParams<any>>;
|
|
136
|
+
new (): T;
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/metadata/ColumnBaseMetadata.d.ts
|
|
140
|
+
interface ColumnBaseMetadataOptions {
|
|
141
|
+
/**
|
|
142
|
+
* Name of class with @table decorator
|
|
143
|
+
*/
|
|
144
|
+
target: string;
|
|
145
|
+
/**
|
|
146
|
+
* Column name in the database
|
|
147
|
+
*/
|
|
148
|
+
name: string;
|
|
149
|
+
/**
|
|
150
|
+
* Class property to which the column is applied
|
|
151
|
+
*/
|
|
152
|
+
propertyName: string;
|
|
153
|
+
/**
|
|
154
|
+
* Indicates if a value is required for creates.
|
|
155
|
+
*/
|
|
156
|
+
required?: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Indicates if column is inserted by default. Default is true
|
|
159
|
+
*/
|
|
160
|
+
insert?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Indicates if column value is updated by "save" operation. Default is true
|
|
163
|
+
*/
|
|
164
|
+
update?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Indicates if this column is a primary key.
|
|
167
|
+
* Same can be achieved when @primaryColumn decorator is used
|
|
168
|
+
*/
|
|
169
|
+
primary?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Value will be equal to `new Date()` when the row is inserted into the table
|
|
172
|
+
* Same can be achieved when @createDateColumn decorator is used
|
|
173
|
+
*/
|
|
174
|
+
createDate?: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Value will be equal to `new Date()` when the row is updated
|
|
177
|
+
* Same can be achieved when @updateDateColumn decorator is used
|
|
178
|
+
*/
|
|
179
|
+
updateDate?: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Value will be set to 1 when the row is inserted. Value will be incremented by one when the row is updated
|
|
182
|
+
* Same can be achieved when @versionColumn decorator is used
|
|
183
|
+
*/
|
|
184
|
+
version?: boolean;
|
|
185
|
+
}
|
|
186
|
+
declare abstract class ColumnBaseMetadata {
|
|
187
|
+
/**
|
|
188
|
+
* Name of class with @table decorator
|
|
189
|
+
*/
|
|
190
|
+
target: string;
|
|
191
|
+
/**
|
|
192
|
+
* Column name in the database
|
|
193
|
+
*/
|
|
194
|
+
name: string;
|
|
195
|
+
/**
|
|
196
|
+
* Class property to which the column is applied
|
|
197
|
+
*/
|
|
198
|
+
propertyName: string;
|
|
199
|
+
/**
|
|
200
|
+
* Indicates if a value is required for creates.
|
|
201
|
+
*/
|
|
202
|
+
required: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Indicates if column is inserted by default. Default is true
|
|
205
|
+
*/
|
|
206
|
+
insert: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Indicates if column value is updated by "save" operation. Default is true
|
|
209
|
+
*/
|
|
210
|
+
update: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Indicates if this column is a primary key.
|
|
213
|
+
* Same can be achieved when @primaryColumn decorator is used
|
|
214
|
+
*/
|
|
215
|
+
primary: boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Value will be equal to `new Date()` when the row is inserted into the table
|
|
218
|
+
* Same can be achieved when @createDateColumn decorator is used
|
|
219
|
+
*/
|
|
220
|
+
createDate: boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Value will be equal to `new Date()` when the row is updated
|
|
223
|
+
* Same can be achieved when @updateDateColumn decorator is used
|
|
224
|
+
*/
|
|
225
|
+
updateDate: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Value will be set to 1 when the row is inserted. Value will be incremented by one when the row is updated
|
|
228
|
+
* Same can be achieved when @versionColumn decorator is used
|
|
229
|
+
*/
|
|
230
|
+
version: boolean;
|
|
231
|
+
protected constructor({
|
|
232
|
+
target,
|
|
233
|
+
name,
|
|
234
|
+
propertyName,
|
|
235
|
+
required,
|
|
236
|
+
insert,
|
|
237
|
+
update,
|
|
238
|
+
primary,
|
|
239
|
+
createDate,
|
|
240
|
+
updateDate,
|
|
241
|
+
version
|
|
242
|
+
}: ColumnBaseMetadataOptions);
|
|
243
|
+
}
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/metadata/ColumnCollectionMetadata.d.ts
|
|
246
|
+
interface ColumnCollectionMetadataOptions extends ColumnBaseMetadataOptions {
|
|
247
|
+
/**
|
|
248
|
+
* Type of the items in the collection
|
|
249
|
+
*/
|
|
250
|
+
collection: string | (() => string);
|
|
251
|
+
/**
|
|
252
|
+
* Property name of the on the collection item type
|
|
253
|
+
*/
|
|
254
|
+
via: string;
|
|
255
|
+
/**
|
|
256
|
+
* Name of the junction table for multi-multi associations
|
|
257
|
+
*/
|
|
258
|
+
through?: string | (() => string);
|
|
259
|
+
}
|
|
260
|
+
declare class ColumnCollectionMetadata extends ColumnBaseMetadata {
|
|
261
|
+
private _collectionString?;
|
|
262
|
+
private _collectionFn?;
|
|
263
|
+
private _throughString?;
|
|
264
|
+
private _throughFn?;
|
|
265
|
+
/**
|
|
266
|
+
* Type of the items in the collection
|
|
267
|
+
* @returns Name of collection
|
|
268
|
+
*/
|
|
269
|
+
get collection(): string;
|
|
270
|
+
/**
|
|
271
|
+
* Property name of the on the collection item type
|
|
272
|
+
*/
|
|
273
|
+
via: string;
|
|
274
|
+
/**
|
|
275
|
+
* Name of the junction table for multi-multi associations
|
|
276
|
+
* @returns Name of junction table
|
|
277
|
+
*/
|
|
278
|
+
get through(): string | undefined;
|
|
279
|
+
constructor({
|
|
280
|
+
target,
|
|
281
|
+
name,
|
|
282
|
+
propertyName,
|
|
283
|
+
required,
|
|
284
|
+
insert,
|
|
285
|
+
update,
|
|
286
|
+
primary,
|
|
287
|
+
createDate,
|
|
288
|
+
updateDate,
|
|
289
|
+
version,
|
|
290
|
+
collection,
|
|
291
|
+
via,
|
|
292
|
+
through
|
|
293
|
+
}: ColumnCollectionMetadataOptions);
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/metadata/ColumnModelMetadata.d.ts
|
|
297
|
+
interface ColumnModelMetadataOptions extends ColumnBaseMetadataOptions {
|
|
298
|
+
/**
|
|
299
|
+
* Name of the model represented by this column id
|
|
300
|
+
*/
|
|
301
|
+
model: string | (() => string);
|
|
302
|
+
}
|
|
303
|
+
declare class ColumnModelMetadata extends ColumnBaseMetadata {
|
|
304
|
+
private _modelString?;
|
|
305
|
+
private _modelFn?;
|
|
306
|
+
/**
|
|
307
|
+
* Name of the model represented by this column id
|
|
308
|
+
* @returns Name of model
|
|
309
|
+
*/
|
|
310
|
+
get model(): string;
|
|
311
|
+
constructor({
|
|
312
|
+
target,
|
|
313
|
+
name,
|
|
314
|
+
propertyName,
|
|
315
|
+
required,
|
|
316
|
+
insert,
|
|
317
|
+
update,
|
|
318
|
+
primary,
|
|
319
|
+
createDate,
|
|
320
|
+
updateDate,
|
|
321
|
+
version,
|
|
322
|
+
model
|
|
323
|
+
}: ColumnModelMetadataOptions);
|
|
324
|
+
}
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/metadata/ColumnTypeMetadata.d.ts
|
|
327
|
+
interface ColumnTypeMetadataOptions extends ColumnBaseMetadataOptions {
|
|
328
|
+
/**
|
|
329
|
+
* Type of sql column
|
|
330
|
+
*/
|
|
331
|
+
type: "array" | "binary" | "boolean" | "boolean[]" | "date" | "datetime" | "float" | "float[]" | "integer" | "integer[]" | "json" | "string" | "string[]" | "uuid" | "uuid[]" | "vector";
|
|
332
|
+
/**
|
|
333
|
+
* Default database value
|
|
334
|
+
*/
|
|
335
|
+
defaultsTo?: boolean[] | number[] | string[] | boolean | number | string | (() => Date | Record<string, unknown> | boolean | number | string) | [];
|
|
336
|
+
/**
|
|
337
|
+
* Number of dimensions for the column. Informational only - BigAl does not issue DDL
|
|
338
|
+
*
|
|
339
|
+
* Applies to types: vector
|
|
340
|
+
*/
|
|
341
|
+
dimensions?: number;
|
|
342
|
+
/**
|
|
343
|
+
* Array of possible enumerated values
|
|
344
|
+
*/
|
|
345
|
+
enum?: readonly string[];
|
|
346
|
+
/**
|
|
347
|
+
* If set, enforces a maximum length check on the column
|
|
348
|
+
*
|
|
349
|
+
* Applies to types: string | string[]
|
|
350
|
+
*/
|
|
351
|
+
maxLength?: number;
|
|
352
|
+
}
|
|
353
|
+
declare class ColumnTypeMetadata extends ColumnBaseMetadata {
|
|
354
|
+
/**
|
|
355
|
+
* Type of the column
|
|
356
|
+
*/
|
|
357
|
+
type: "array" | "binary" | "boolean" | "boolean[]" | "date" | "datetime" | "float" | "float[]" | "integer" | "integer[]" | "json" | "string" | "string[]" | "uuid" | "uuid[]" | "vector";
|
|
358
|
+
/**
|
|
359
|
+
* Default database value
|
|
360
|
+
*/
|
|
361
|
+
defaultsTo?: boolean[] | number[] | string[] | boolean | number | string | (() => Date | Record<string, unknown> | boolean | number | string) | [];
|
|
362
|
+
/**
|
|
363
|
+
* Number of dimensions for the column. Informational only - BigAl does not issue DDL
|
|
364
|
+
*
|
|
365
|
+
* Applies to types: vector
|
|
366
|
+
*/
|
|
367
|
+
dimensions?: number;
|
|
368
|
+
/**
|
|
369
|
+
* Array of possible enumerated values
|
|
370
|
+
*/
|
|
371
|
+
enum?: readonly string[];
|
|
372
|
+
/**
|
|
373
|
+
* If set, enforces a maximum length check on the column
|
|
374
|
+
*
|
|
375
|
+
* Applies to types: string | string[]
|
|
376
|
+
*/
|
|
377
|
+
maxLength?: number;
|
|
378
|
+
constructor(options: ColumnTypeMetadataOptions);
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/metadata/ColumnMetadata.d.ts
|
|
382
|
+
type ColumnMetadata = ColumnCollectionMetadata | ColumnModelMetadata | ColumnTypeMetadata;
|
|
383
|
+
//#endregion
|
|
384
|
+
//#region src/metadata/ColumnModifierMetadata.d.ts
|
|
385
|
+
interface ColumnModifierMetadata {
|
|
386
|
+
/**
|
|
387
|
+
* Name of class with @table decorator
|
|
388
|
+
*/
|
|
389
|
+
target: string;
|
|
390
|
+
/**
|
|
391
|
+
* Column name in the database
|
|
392
|
+
*/
|
|
393
|
+
name?: string;
|
|
394
|
+
/**
|
|
395
|
+
* Class property to which the column is applied
|
|
396
|
+
*/
|
|
397
|
+
propertyName: string;
|
|
398
|
+
/**
|
|
399
|
+
* Indicates if a value is required for creates.
|
|
400
|
+
*/
|
|
401
|
+
required?: boolean;
|
|
402
|
+
/**
|
|
403
|
+
* Indicates if this column is a primary key.
|
|
404
|
+
* Same can be achieved when @primaryColumn decorator is used
|
|
405
|
+
*/
|
|
406
|
+
primary?: boolean;
|
|
407
|
+
/**
|
|
408
|
+
* Value will be equal to `new Date()` when the row is inserted into the table
|
|
409
|
+
* Same can be achieved when @createDateColumn decorator is used
|
|
410
|
+
*/
|
|
411
|
+
createDate?: boolean;
|
|
412
|
+
/**
|
|
413
|
+
* Value will be equal to `new Date()` when the row is updated
|
|
414
|
+
* Same can be achieved when @updateDateColumn decorator is used
|
|
415
|
+
*/
|
|
416
|
+
updateDate?: boolean;
|
|
417
|
+
/**
|
|
418
|
+
* Value will be set to 1 when the row is inserted. Value will be incremented by one when the row is updated
|
|
419
|
+
* Same can be achieved when @versionColumn decorator is used
|
|
420
|
+
*/
|
|
421
|
+
version?: boolean;
|
|
422
|
+
/**
|
|
423
|
+
* Type of sql column
|
|
424
|
+
*/
|
|
425
|
+
type?: "array" | "binary" | "boolean" | "boolean[]" | "date" | "datetime" | "float" | "float[]" | "integer" | "integer[]" | "json" | "string" | "string[]" | "vector";
|
|
426
|
+
/**
|
|
427
|
+
* Name of the model represented by this column id
|
|
428
|
+
*/
|
|
429
|
+
model?: string | (() => string);
|
|
430
|
+
}
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/metadata/ModelMetadata.d.ts
|
|
433
|
+
type Column = ColumnCollectionMetadata | ColumnModelMetadata | ColumnTypeMetadata;
|
|
434
|
+
type ColumnByStringId = Record<string, Column>;
|
|
435
|
+
interface ModelMetadataOptions<T extends Entity> {
|
|
436
|
+
name: string;
|
|
437
|
+
type: EntityStatic<T>;
|
|
438
|
+
connection?: string;
|
|
439
|
+
schema?: string;
|
|
440
|
+
tableName?: string;
|
|
441
|
+
readonly?: boolean;
|
|
442
|
+
}
|
|
443
|
+
declare class ModelMetadata<T extends Entity> {
|
|
444
|
+
private _columns;
|
|
445
|
+
private _primaryKeyColumn;
|
|
446
|
+
private _createDateColumns;
|
|
447
|
+
private _updateDateColumns;
|
|
448
|
+
private _versionDateColumns;
|
|
449
|
+
set columns(columns: readonly Column[]);
|
|
450
|
+
get columns(): readonly Column[];
|
|
451
|
+
get primaryKeyColumn(): Column | undefined;
|
|
452
|
+
get createDateColumns(): readonly Column[];
|
|
453
|
+
get updateDateColumns(): readonly Column[];
|
|
454
|
+
get versionColumns(): readonly Column[];
|
|
455
|
+
get qualifiedTableName(): string;
|
|
456
|
+
name: string;
|
|
457
|
+
type: EntityStatic<T>;
|
|
458
|
+
connection?: string;
|
|
459
|
+
schema?: string;
|
|
460
|
+
tableName: string;
|
|
461
|
+
readonly: boolean;
|
|
462
|
+
columnsByColumnName: ColumnByStringId;
|
|
463
|
+
columnsByPropertyName: ColumnByStringId;
|
|
464
|
+
constructor({
|
|
465
|
+
name,
|
|
466
|
+
type,
|
|
467
|
+
connection,
|
|
468
|
+
schema,
|
|
469
|
+
tableName,
|
|
470
|
+
readonly
|
|
471
|
+
}: ModelMetadataOptions<T>);
|
|
472
|
+
}
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/metadata/MetadataStorage.d.ts
|
|
672
475
|
/**
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
476
|
+
* This represents an object to store all of the decorator data. Since there can be multiple decorators per
|
|
477
|
+
* class/property, things will be reconciled when entities are initialized
|
|
478
|
+
*/
|
|
479
|
+
declare class MetadataStorage<T extends Entity> {
|
|
480
|
+
readonly models: ModelMetadata<T>[];
|
|
481
|
+
readonly columns: ColumnMetadata[];
|
|
482
|
+
readonly columnModifiers: ColumnModifierMetadata[];
|
|
483
|
+
}
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/metadata/index.d.ts
|
|
486
|
+
declare function getMetadataStorage<T extends Entity>(): MetadataStorage<T>;
|
|
487
|
+
//#endregion
|
|
488
|
+
//#region src/query/Sort.d.ts
|
|
489
|
+
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>>);
|
|
490
|
+
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>}`;
|
|
491
|
+
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>;
|
|
492
|
+
type SortObjectValue = -1 | "asc" | "desc" | 1;
|
|
493
|
+
type VectorDistanceMetric = "cosine" | "innerProduct" | "l1" | "l2";
|
|
494
|
+
interface VectorDistanceSort {
|
|
495
|
+
nearestTo: number[];
|
|
496
|
+
metric?: VectorDistanceMetric;
|
|
497
|
+
}
|
|
498
|
+
type SortObject<T extends Entity> = { [K in keyof T as ExcludeFunctions<OmitEntityCollections<T>, K>]?: SortObjectValue | VectorDistanceSort };
|
|
499
|
+
type Sort<T extends Entity> = MultipleSortString<T> | SortObject<T>;
|
|
500
|
+
interface OrderBy<T extends Entity> {
|
|
501
|
+
propertyName: string & keyof OmitFunctions<OmitEntityCollections<T>>;
|
|
502
|
+
descending?: boolean;
|
|
503
|
+
vectorDistance?: {
|
|
504
|
+
vector: number[];
|
|
505
|
+
metric: VectorDistanceMetric;
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/query/DoNotReturnRecords.d.ts
|
|
678
510
|
interface DoNotReturnRecords {
|
|
679
|
-
|
|
511
|
+
returnRecords: false;
|
|
680
512
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/query/OnConflictOptions.d.ts
|
|
515
|
+
type OnConflictTargets<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> = K[] | {
|
|
516
|
+
columns: K[];
|
|
517
|
+
where: WhereQuery<T>;
|
|
685
518
|
};
|
|
686
|
-
interface OnConflictIgnoreOptions<T extends
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
}
|
|
692
|
-
interface OnConflictMergeOptions<T extends
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
};
|
|
519
|
+
interface OnConflictIgnoreOptions<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> {
|
|
520
|
+
onConflict: {
|
|
521
|
+
action: "ignore";
|
|
522
|
+
targets: OnConflictTargets<T, K>;
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
interface OnConflictMergeOptions<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> {
|
|
526
|
+
onConflict: {
|
|
527
|
+
action: "merge";
|
|
528
|
+
targets: OnConflictTargets<T, K>;
|
|
529
|
+
merge?: K[] | {
|
|
530
|
+
columns?: K[];
|
|
531
|
+
where: WhereQuery<T>;
|
|
700
532
|
};
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
type OnConflictOptions<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> = OnConflictIgnoreOptions<T, K> | OnConflictMergeOptions<T, K>;
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region src/query/ReturnSelect.d.ts
|
|
538
|
+
interface ReturnSelect<T extends Entity, K extends keyof OmitFunctions<OmitEntityCollections<T>> = keyof OmitFunctions<OmitEntityCollections<T>>> {
|
|
539
|
+
returnSelect: (K & string)[];
|
|
540
|
+
}
|
|
541
|
+
//#endregion
|
|
542
|
+
//#region src/query/CreateOptions.d.ts
|
|
543
|
+
type CreateOnConflictOptions<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> = OnConflictOptions<T, K> & Partial<DoNotReturnRecords | ReturnSelect<T>>;
|
|
544
|
+
type CreateOptionalOnConflictOptions<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> = Partial<OnConflictOptions<T, K>> & (DoNotReturnRecords | ReturnSelect<T>);
|
|
545
|
+
type CreateOptions<T extends Entity, K extends string & keyof OmitFunctions<OmitEntityCollections<T>> = string & keyof OmitFunctions<OmitEntityCollections<T>>> = CreateOnConflictOptions<T, K> | CreateOptionalOnConflictOptions<T, K>;
|
|
546
|
+
//#endregion
|
|
547
|
+
//#region src/query/Comparer.d.ts
|
|
548
|
+
type Comparer = "!" | "<" | "<=" | ">" | ">=" | "and" | "contains" | "endsWith" | "like" | "or" | "startsWith";
|
|
549
|
+
//#endregion
|
|
550
|
+
//#region src/query/CountResult.d.ts
|
|
551
|
+
interface CountResult<TEntity extends Entity> extends PromiseLike<number> {
|
|
552
|
+
where(args: WhereQuery<TEntity>): CountResult<TEntity> | number;
|
|
553
|
+
}
|
|
554
|
+
//#endregion
|
|
555
|
+
//#region src/query/CreateResult.d.ts
|
|
556
|
+
/**
|
|
557
|
+
* Result of a create operation that returns a plain object (after calling toJSON())
|
|
558
|
+
*/
|
|
559
|
+
interface CreateResultJSON<T extends Entity> extends PromiseLike<PlainObject<QueryResult<T>>> {
|
|
560
|
+
/**
|
|
561
|
+
* Returns results as plain objects instead of entity class instances.
|
|
562
|
+
* Useful for when data must be serializable.
|
|
563
|
+
*/
|
|
564
|
+
toJSON(): CreateResultJSON<T>;
|
|
701
565
|
}
|
|
702
|
-
type OnConflictOptions<T extends Record<string, unknown>, K extends string & keyof OmitFunctions<T> = string & keyof OmitFunctions<T>> = OnConflictIgnoreOptions<T, K> | OnConflictMergeOptions<T, K>;
|
|
703
|
-
|
|
704
|
-
interface ReturnSelect$1<T extends Record<string, unknown>, K extends keyof OmitFunctions<T> = keyof OmitFunctions<T>> {
|
|
705
|
-
returnSelect: (K & string)[];
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
type CreateOnConflictOptions<T extends Record<string, unknown>, K extends string & keyof OmitFunctions<T> = string & keyof OmitFunctions<T>> = OnConflictOptions<T, K> & Partial<DoNotReturnRecords | ReturnSelect$1<T>>;
|
|
709
|
-
type CreateOptionalOnConflictOptions<T extends Record<string, unknown>, K extends string & keyof OmitFunctions<T> = string & keyof OmitFunctions<T>> = Partial<OnConflictOptions<T, K>> & (DoNotReturnRecords | ReturnSelect$1<T>);
|
|
710
|
-
type CreateOptions<T extends Record<string, unknown>, K extends string & keyof OmitFunctions<T> = string & keyof OmitFunctions<T>> = CreateOnConflictOptions<T, K> | CreateOptionalOnConflictOptions<T, K>;
|
|
711
|
-
|
|
712
|
-
type Comparer = '!' | '<' | '<=' | '>' | '>=' | 'and' | 'contains' | 'endsWith' | 'like' | 'or' | 'startsWith';
|
|
713
|
-
|
|
714
|
-
interface CountResult<TEntity extends Record<string, unknown>> extends PromiseLike<number> {
|
|
715
|
-
where(args: WhereQuery<TEntity>): CountResult<TEntity> | number;
|
|
716
|
-
}
|
|
717
|
-
|
|
718
566
|
/**
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
interface
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
567
|
+
* Result of a create operation that returns multiple plain objects (after calling toJSON())
|
|
568
|
+
*/
|
|
569
|
+
interface CreateResultArrayJSON<T extends Entity> extends PromiseLike<PlainObject<QueryResult<T>>[]> {
|
|
570
|
+
/**
|
|
571
|
+
* Returns results as plain objects instead of entity class instances.
|
|
572
|
+
* Useful for when data must be serializable.
|
|
573
|
+
*/
|
|
574
|
+
toJSON(): CreateResultArrayJSON<T>;
|
|
727
575
|
}
|
|
728
576
|
/**
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
interface
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
577
|
+
* Result of a create operation that returns a single record
|
|
578
|
+
*/
|
|
579
|
+
interface CreateResult<T extends Entity> extends PromiseLike<QueryResult<T>> {
|
|
580
|
+
/**
|
|
581
|
+
* Returns results as plain objects instead of entity class instances.
|
|
582
|
+
* Useful for when data must be serializable.
|
|
583
|
+
*/
|
|
584
|
+
toJSON(): CreateResultJSON<T>;
|
|
737
585
|
}
|
|
738
|
-
|
|
586
|
+
/**
|
|
587
|
+
* Result of a create operation that returns multiple records
|
|
588
|
+
*/
|
|
589
|
+
interface CreateResultArray<T extends Entity> extends PromiseLike<QueryResult<T>[]> {
|
|
590
|
+
/**
|
|
591
|
+
* Returns results as plain objects instead of entity class instances.
|
|
592
|
+
* Useful for when data must be serializable.
|
|
593
|
+
*/
|
|
594
|
+
toJSON(): CreateResultArrayJSON<T>;
|
|
595
|
+
}
|
|
596
|
+
//#endregion
|
|
597
|
+
//#region src/query/ScalarSubquery.d.ts
|
|
739
598
|
declare class ScalarSubquery<TValue> {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
}
|
|
746
|
-
|
|
599
|
+
private readonly _resultType;
|
|
600
|
+
readonly _aggregate: "avg" | "count" | "max" | "min" | "sum";
|
|
601
|
+
readonly _aggregateColumn?: string;
|
|
602
|
+
readonly _subquery: SubqueryBuilder<Entity>;
|
|
603
|
+
constructor(parentSubquery: SubqueryBuilder<Entity>, aggregate: "avg" | "count" | "max" | "min" | "sum", column?: string);
|
|
604
|
+
}
|
|
605
|
+
//#endregion
|
|
606
|
+
//#region src/query/SelectBuilder.d.ts
|
|
747
607
|
interface SelectAggregateExpression {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
608
|
+
_type: "aggregate";
|
|
609
|
+
fn: "avg" | "count" | "max" | "min" | "sum";
|
|
610
|
+
column?: string;
|
|
611
|
+
distinct: boolean;
|
|
612
|
+
alias: string;
|
|
753
613
|
}
|
|
754
614
|
interface AggregateBuilder {
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
}
|
|
761
|
-
declare class SelectBuilder<T extends
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
}
|
|
769
|
-
|
|
615
|
+
distinct(): AggregateBuilder;
|
|
616
|
+
as<TAlias extends string>(alias: TAlias): SelectAggregateExpression & {
|
|
617
|
+
readonly alias: TAlias;
|
|
618
|
+
};
|
|
619
|
+
readonly _expression: SelectAggregateExpression;
|
|
620
|
+
}
|
|
621
|
+
declare class SelectBuilder<T extends Entity> {
|
|
622
|
+
count(column?: string & keyof T): AggregateBuilder;
|
|
623
|
+
sum(column: string & keyof T): AggregateBuilder;
|
|
624
|
+
avg(column: string & keyof T): AggregateBuilder;
|
|
625
|
+
max(column: string & keyof T): AggregateBuilder;
|
|
626
|
+
min(column: string & keyof T): AggregateBuilder;
|
|
627
|
+
protected _createAggregateBuilder(fn: SelectAggregateExpression["fn"], column?: string): AggregateBuilder;
|
|
628
|
+
}
|
|
629
|
+
//#endregion
|
|
630
|
+
//#region src/query/SubqueryBuilder.d.ts
|
|
770
631
|
/**
|
|
771
|
-
|
|
772
|
-
|
|
632
|
+
* An aggregate expression with a typed alias from `.as()`.
|
|
633
|
+
*/
|
|
773
634
|
type TypedAggregateExpression<TAlias extends string> = SelectAggregateExpression & {
|
|
774
|
-
|
|
635
|
+
readonly alias: TAlias;
|
|
775
636
|
};
|
|
776
637
|
/**
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
type AggregateCallback<T extends
|
|
638
|
+
* A callback that creates an aggregate with a typed alias.
|
|
639
|
+
*/
|
|
640
|
+
type AggregateCallback<T extends Entity, TAlias extends string> = (builder: SelectBuilder<T>) => TypedAggregateExpression<TAlias>;
|
|
780
641
|
/**
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
type ExtractItemAlias<T extends
|
|
642
|
+
* Extracts the alias type from a select item.
|
|
643
|
+
*/
|
|
644
|
+
type ExtractItemAlias<T extends Entity, TItem> = TItem extends string & keyof T ? TItem : TItem extends AggregateCallback<T, infer A> ? A : TItem extends TypedAggregateExpression<infer A> ? A : never;
|
|
784
645
|
/**
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
type ExtractAllAliases<T extends
|
|
788
|
-
[K in keyof TItems]: ExtractItemAlias<T, TItems[K]>;
|
|
789
|
-
}[number];
|
|
646
|
+
* Extracts all alias types from an array of select items using mapped type.
|
|
647
|
+
*/
|
|
648
|
+
type ExtractAllAliases<T extends Entity, TItems extends readonly unknown[]> = { [K in keyof TItems]: ExtractItemAlias<T, TItems[K]> }[number];
|
|
790
649
|
/**
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
type TypedSelectItem<T extends
|
|
794
|
-
type SelectItem<T extends
|
|
650
|
+
* Valid select items for type-safe column tracking.
|
|
651
|
+
*/
|
|
652
|
+
type TypedSelectItem<T extends Entity> = AggregateCallback<T, string> | TypedAggregateExpression<string> | (string & keyof T);
|
|
653
|
+
type SelectItem<T extends Entity> = ((builder: SelectBuilder<T>) => AggregateBuilder | SelectAggregateExpression) | (string & keyof T);
|
|
795
654
|
interface HavingComparer {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
655
|
+
"<"?: number;
|
|
656
|
+
"<="?: number;
|
|
657
|
+
">"?: number;
|
|
658
|
+
">="?: number;
|
|
659
|
+
"!="?: number;
|
|
801
660
|
}
|
|
802
661
|
type HavingCondition = Record<string, HavingComparer | number>;
|
|
803
662
|
/**
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
663
|
+
* Structural type that accepts any SubqueryBuilder<T, TColumns> regardless of T or TColumns.
|
|
664
|
+
* Uses `unknown` for generic-dependent properties to allow variance.
|
|
665
|
+
* Only includes data properties, not methods, to avoid method return type variance issues.
|
|
666
|
+
*/
|
|
808
667
|
interface SubqueryBuilderLike {
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
668
|
+
_repository: unknown;
|
|
669
|
+
_select?: string[];
|
|
670
|
+
_selectExpressions?: SelectAggregateExpression[];
|
|
671
|
+
_where?: unknown;
|
|
672
|
+
_sort?: unknown;
|
|
673
|
+
_limit?: number;
|
|
674
|
+
_groupBy?: string[];
|
|
675
|
+
_having?: HavingCondition;
|
|
676
|
+
_distinctOn?: string[];
|
|
818
677
|
}
|
|
819
678
|
/**
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
679
|
+
* Structural type for typed subquery builders that tracks selected columns.
|
|
680
|
+
* Used by join operations to enable type-safe sorting on subquery columns.
|
|
681
|
+
*/
|
|
823
682
|
interface TypedSubqueryBuilder<TColumns extends string = never> extends SubqueryBuilderLike {
|
|
824
|
-
|
|
825
|
-
}
|
|
826
|
-
declare class SubqueryBuilder<T extends
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
683
|
+
readonly _columns?: TColumns;
|
|
684
|
+
}
|
|
685
|
+
declare class SubqueryBuilder<T extends Entity, TColumns extends string = never> implements TypedSubqueryBuilder<TColumns> {
|
|
686
|
+
readonly _repository: IReadonlyRepository<T> | IRepository<T>;
|
|
687
|
+
_select?: string[];
|
|
688
|
+
_selectExpressions?: SelectAggregateExpression[];
|
|
689
|
+
_where?: WhereQuery<T>;
|
|
690
|
+
_sort?: SortObject<T> | string;
|
|
691
|
+
_limit?: number;
|
|
692
|
+
_groupBy?: (string & keyof T)[];
|
|
693
|
+
_having?: HavingCondition;
|
|
694
|
+
_distinctOn?: (string & keyof T)[];
|
|
695
|
+
readonly _columns?: TColumns;
|
|
696
|
+
constructor(repository: IReadonlyRepository<T> | IRepository<T>);
|
|
697
|
+
/**
|
|
698
|
+
* Select columns and/or aggregate expressions for the subquery with type-safe column tracking.
|
|
699
|
+
* @returns New SubqueryBuilder with the select applied and column types tracked
|
|
700
|
+
* @example
|
|
701
|
+
* // Type-safe select with callback aggregates
|
|
702
|
+
* subquery(ProductRepository)
|
|
703
|
+
* .select(['store', (sb) => sb.count().as('productCount')])
|
|
704
|
+
* .groupBy(['store']);
|
|
705
|
+
*
|
|
706
|
+
* // Can then sort type-safely after joining:
|
|
707
|
+
* StoreRepository.find()
|
|
708
|
+
* .join(productCounts, 'stats', { on: { id: 'store' } })
|
|
709
|
+
* .sort('stats.productCount desc') // No type cast needed!
|
|
710
|
+
*/
|
|
711
|
+
select<const TItems extends readonly TypedSelectItem<T>[]>(columns: TItems): SubqueryBuilder<T, ExtractAllAliases<T, TItems>>;
|
|
712
|
+
/**
|
|
713
|
+
* Select columns and/or aggregate expressions for the subquery (untyped signature).
|
|
714
|
+
* Note: Using aggregate callbacks that return `AggregateBuilder` instead of calling `.as()`
|
|
715
|
+
* does not enable type-safe sorting.
|
|
716
|
+
* @returns New SubqueryBuilder with the select applied
|
|
717
|
+
*/
|
|
718
|
+
select(columns: SelectItem<T>[]): SubqueryBuilder<T>;
|
|
719
|
+
/**
|
|
720
|
+
* Group the subquery results by one or more columns.
|
|
721
|
+
* @param {(string & keyof T)[]} columns - Columns to group by
|
|
722
|
+
* @returns New SubqueryBuilder with the groupBy applied
|
|
723
|
+
* @example
|
|
724
|
+
* subquery(ProductRepository)
|
|
725
|
+
* .select(['storeId', (sb) => sb.count().as('productCount')])
|
|
726
|
+
* .groupBy(['storeId'])
|
|
727
|
+
*/
|
|
728
|
+
groupBy(columns: (string & keyof T)[]): SubqueryBuilder<T, TColumns>;
|
|
729
|
+
/**
|
|
730
|
+
* Filter groups based on aggregate values (used with groupBy).
|
|
731
|
+
* @param {HavingCondition} condition - Having condition to apply
|
|
732
|
+
* @returns New SubqueryBuilder with the having condition applied
|
|
733
|
+
* @example
|
|
734
|
+
* subquery(ProductRepository)
|
|
735
|
+
* .select(['storeId', (sb) => sb.count().as('productCount')])
|
|
736
|
+
* .groupBy(['storeId'])
|
|
737
|
+
* .having({ productCount: { '>': 5 } })
|
|
738
|
+
*/
|
|
739
|
+
having(condition: HavingCondition): SubqueryBuilder<T, TColumns>;
|
|
740
|
+
where(query: WhereQuery<T>): SubqueryBuilder<T, TColumns>;
|
|
741
|
+
sort(value: Sort<T>): SubqueryBuilder<T, TColumns>;
|
|
742
|
+
limit(maxRows: number): SubqueryBuilder<T, TColumns>;
|
|
743
|
+
/**
|
|
744
|
+
* Selects distinct rows based on the specified columns (PostgreSQL DISTINCT ON).
|
|
745
|
+
* The sort() clause must start with the same columns in the same order.
|
|
746
|
+
* @param {string[]} columns - Column names for DISTINCT ON clause
|
|
747
|
+
* @returns New SubqueryBuilder with the distinctOn applied
|
|
748
|
+
* @example
|
|
749
|
+
* subquery(ProductRepository)
|
|
750
|
+
* .distinctOn(['store'])
|
|
751
|
+
* .select(['store', 'name', 'createdAt'])
|
|
752
|
+
* .sort('store')
|
|
753
|
+
* .sort('createdAt desc');
|
|
754
|
+
*/
|
|
755
|
+
distinctOn(columns: (string & keyof T)[]): SubqueryBuilder<T, TColumns>;
|
|
756
|
+
count(): ScalarSubquery<number>;
|
|
757
|
+
sum(column: string & keyof T): ScalarSubquery<number>;
|
|
758
|
+
avg(column: string & keyof T): ScalarSubquery<number>;
|
|
759
|
+
max<K extends string & keyof T>(column: K): ScalarSubquery<T[K]>;
|
|
760
|
+
min<K extends string & keyof T>(column: K): ScalarSubquery<T[K]>;
|
|
761
|
+
private cloneBuilder;
|
|
762
|
+
}
|
|
763
|
+
//#endregion
|
|
764
|
+
//#region src/query/JoinDefinition.d.ts
|
|
765
|
+
type JoinType = "inner" | "left";
|
|
766
|
+
interface ModelJoinDefinition<T extends Entity = Entity> {
|
|
767
|
+
propertyName: string;
|
|
768
|
+
alias: string;
|
|
769
|
+
type: JoinType;
|
|
770
|
+
on?: WhereQuery<T>;
|
|
771
|
+
relatedModel?: ModelMetadata<T>;
|
|
772
|
+
foreignKeyColumn?: string;
|
|
773
|
+
relatedPrimaryKey?: string;
|
|
914
774
|
}
|
|
915
775
|
/**
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
776
|
+
* ON condition for subquery joins - maps main table column to subquery column
|
|
777
|
+
* @example { id: 'storeId' } means main.id = subquery.storeId
|
|
778
|
+
*/
|
|
919
779
|
type SubqueryJoinOnCondition = Record<string, string>;
|
|
920
780
|
interface SubqueryJoinDefinition {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
781
|
+
subquery: SubqueryBuilderLike;
|
|
782
|
+
alias: string;
|
|
783
|
+
type: JoinType;
|
|
784
|
+
on: SubqueryJoinOnCondition;
|
|
925
785
|
}
|
|
926
|
-
type JoinDefinition<T extends
|
|
786
|
+
type JoinDefinition<T extends Entity = Entity> = ModelJoinDefinition<T> | SubqueryJoinDefinition;
|
|
927
787
|
declare function isSubqueryJoin(join: JoinDefinition): join is SubqueryJoinDefinition;
|
|
928
|
-
|
|
788
|
+
//#endregion
|
|
789
|
+
//#region src/query/JoinedWhereQuery.d.ts
|
|
929
790
|
type ExcludeUndefined$1<T> = Exclude<T, undefined>;
|
|
930
|
-
interface JoinInfo<TProperty extends string = string, TAlias extends string = string, TEntity extends
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
791
|
+
interface JoinInfo<TProperty extends string = string, TAlias extends string = string, TEntity extends Entity = Entity> {
|
|
792
|
+
property: TProperty;
|
|
793
|
+
alias: TAlias;
|
|
794
|
+
entity: TEntity;
|
|
934
795
|
}
|
|
935
796
|
/**
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
797
|
+
* Join info for subquery joins - tracks alias and available column names.
|
|
798
|
+
* Distinguished from JoinInfo by the _brand discriminator.
|
|
799
|
+
*/
|
|
939
800
|
interface SubqueryJoinInfo<TAlias extends string = string, TColumns extends string = string> {
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
801
|
+
alias: TAlias;
|
|
802
|
+
columns: TColumns;
|
|
803
|
+
_brand: "subquery";
|
|
943
804
|
}
|
|
944
805
|
/**
|
|
945
|
-
|
|
946
|
-
|
|
806
|
+
* Union type for any join info (model or subquery).
|
|
807
|
+
*/
|
|
947
808
|
type AnyJoinInfo = JoinInfo | SubqueryJoinInfo;
|
|
948
809
|
/**
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
type ModelJoinAliases<TJoins extends AnyJoinInfo> = Extract<TJoins, JoinInfo>[
|
|
810
|
+
* Extracts aliases from model JoinInfo only.
|
|
811
|
+
*/
|
|
812
|
+
type ModelJoinAliases<TJoins extends AnyJoinInfo> = Extract<TJoins, JoinInfo>["alias"];
|
|
952
813
|
type GetJoinedEntity<TJoins extends JoinInfo, TAlias extends string> = Extract<TJoins, {
|
|
953
|
-
|
|
954
|
-
}>[
|
|
955
|
-
type JoinedPropertyConstraint<TJoinedEntity extends
|
|
814
|
+
alias: TAlias;
|
|
815
|
+
}>["entity"];
|
|
816
|
+
type JoinedPropertyConstraint<TJoinedEntity extends Entity, TPropertyValue> = WhereQuery<TJoinedEntity> | WhereQueryStatement<ExcludeUndefined$1<TPropertyValue>>;
|
|
956
817
|
/**
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
type JoinedWhereQuery<T extends
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
and?: JoinedWhereQuery<T, TJoins>[];
|
|
970
|
-
or?: JoinedWhereQuery<T, TJoins>[];
|
|
818
|
+
* WhereQuery that supports nested where clauses for joined relationships.
|
|
819
|
+
* Note: Subquery joins do not support where clause filtering by alias.
|
|
820
|
+
* @example
|
|
821
|
+
* .join('store', 'primaryStore')
|
|
822
|
+
* .where({ primaryStore: { name: 'Acme' } })
|
|
823
|
+
*
|
|
824
|
+
* .join('store')
|
|
825
|
+
* .where({ store: { name: 'Acme' } })
|
|
826
|
+
*/
|
|
827
|
+
type JoinedWhereQuery<T extends Entity, TJoins extends AnyJoinInfo = never> = WhereQuery<T> & ([TJoins] extends [never] ? {} : [Extract<TJoins, JoinInfo>] extends [never] ? {} : { [K in ModelJoinAliases<TJoins>]?: JoinedPropertyConstraint<GetJoinedEntity<Extract<TJoins, JoinInfo>, K>, GetJoinedEntity<Extract<TJoins, JoinInfo>, K>> }) & {
|
|
828
|
+
and?: JoinedWhereQuery<T, TJoins>[];
|
|
829
|
+
or?: JoinedWhereQuery<T, TJoins>[];
|
|
971
830
|
};
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
type ValidateMultipleSorts<T extends Record<string, unknown>, 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>}`;
|
|
975
|
-
type MultipleSortString<T extends Record<string, unknown>, 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>;
|
|
976
|
-
type SortObjectValue = -1 | 'asc' | 'desc' | 1;
|
|
977
|
-
interface VectorDistanceSort {
|
|
978
|
-
nearestTo: number[];
|
|
979
|
-
metric?: VectorDistanceMetric;
|
|
980
|
-
}
|
|
981
|
-
type SortObject<T extends Record<string, unknown>> = {
|
|
982
|
-
[K in keyof T as ExcludeFunctions<T[K], K>]?: SortObjectValue | VectorDistanceSort;
|
|
983
|
-
};
|
|
984
|
-
type Sort<T extends Record<string, unknown>> = MultipleSortString<T> | SortObject<T>;
|
|
985
|
-
type VectorDistanceMetric = 'cosine' | 'innerProduct' | 'l1' | 'l2';
|
|
986
|
-
interface OrderBy<T extends Record<string, unknown>> {
|
|
987
|
-
propertyName: string & keyof OmitFunctions<T>;
|
|
988
|
-
descending?: boolean;
|
|
989
|
-
vectorDistance?: {
|
|
990
|
-
vector: number[];
|
|
991
|
-
metric: VectorDistanceMetric;
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
|
|
831
|
+
//#endregion
|
|
832
|
+
//#region src/query/JoinedSort.d.ts
|
|
995
833
|
/**
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
type AnyJoinAliases<TJoins extends AnyJoinInfo> = TJoins[
|
|
834
|
+
* Extracts all aliases from a union of join info types.
|
|
835
|
+
*/
|
|
836
|
+
type AnyJoinAliases<TJoins extends AnyJoinInfo> = TJoins["alias"];
|
|
999
837
|
/**
|
|
1000
|
-
|
|
1001
|
-
|
|
838
|
+
* Gets available columns for any join type (model or subquery).
|
|
839
|
+
*/
|
|
1002
840
|
type GetJoinColumns<TJoins extends AnyJoinInfo, TAlias extends string> = Extract<TJoins, {
|
|
1003
|
-
|
|
841
|
+
alias: TAlias;
|
|
1004
842
|
}> extends SubqueryJoinInfo<TAlias, infer TColumns> ? TColumns : Extract<TJoins, {
|
|
1005
|
-
|
|
1006
|
-
}> extends JoinInfo<string, TAlias, infer TEntity> ? string & keyof OmitFunctions<TEntity
|
|
843
|
+
alias: TAlias;
|
|
844
|
+
}> extends JoinInfo<string, TAlias, infer TEntity> ? string & keyof OmitFunctions<OmitEntityCollections<TEntity>> : never;
|
|
1007
845
|
/**
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
846
|
+
* Creates column path strings for any join type.
|
|
847
|
+
* For model joins: uses entity property names
|
|
848
|
+
* For subquery joins: uses tracked column names
|
|
849
|
+
*/
|
|
1012
850
|
type AnyJoinedColumnPath<TJoins extends AnyJoinInfo, TAlias extends AnyJoinAliases<TJoins> = AnyJoinAliases<TJoins>> = TAlias extends string ? `${TAlias}.${GetJoinColumns<TJoins, TAlias>}` : never;
|
|
1013
851
|
/**
|
|
1014
|
-
|
|
1015
|
-
|
|
852
|
+
* Sort strings for joined columns (model or subquery joins).
|
|
853
|
+
*/
|
|
1016
854
|
type JoinedSortString<TJoins extends AnyJoinInfo> = AnyJoinedColumnPath<TJoins> | `${AnyJoinedColumnPath<TJoins>} ASC` | `${AnyJoinedColumnPath<TJoins>} asc` | `${AnyJoinedColumnPath<TJoins>} DESC` | `${AnyJoinedColumnPath<TJoins>} desc`;
|
|
1017
855
|
/**
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
type JoinedSort<T extends
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
856
|
+
* Sort type that supports both base entity columns and joined columns (from model or subquery joins).
|
|
857
|
+
*/
|
|
858
|
+
type JoinedSort<T extends Entity, TJoins extends AnyJoinInfo = never> = [TJoins] extends [never] ? Sort<T> : JoinedSortString<TJoins> | Sort<T>;
|
|
859
|
+
//#endregion
|
|
860
|
+
//#region src/query/CreateUpdateOptions.d.ts
|
|
861
|
+
type CreateUpdateOptions<T extends Entity> = DoNotReturnRecords | ReturnSelect<T>;
|
|
862
|
+
//#endregion
|
|
863
|
+
//#region src/query/DeleteOptions.d.ts
|
|
864
|
+
interface ReturnSelect$1<T extends Entity, K extends keyof T> {
|
|
865
|
+
returnSelect: (K & string & keyof OmitFunctions<OmitEntityCollections<T>>)[];
|
|
866
|
+
returnRecords?: true;
|
|
867
|
+
}
|
|
868
|
+
interface ReturnRecords<T extends Entity, K extends keyof T> {
|
|
869
|
+
returnRecords: true;
|
|
870
|
+
returnSelect?: (K & string & keyof OmitFunctions<OmitEntityCollections<T>>)[];
|
|
871
|
+
}
|
|
872
|
+
type DeleteOptions<T extends Entity, K extends keyof T = keyof T> = ReturnRecords<T, K> | ReturnSelect$1<T, K>;
|
|
873
|
+
//#endregion
|
|
874
|
+
//#region src/query/DestroyResult.d.ts
|
|
1034
875
|
/**
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
interface
|
|
1038
|
-
|
|
1039
|
-
/** Returns the generated SQL and parameters without executing the query. */
|
|
1040
|
-
toSQL(): {
|
|
1041
|
-
params: readonly unknown[];
|
|
1042
|
-
sql: string;
|
|
1043
|
-
};
|
|
876
|
+
* Result of a destroy operation that returns plain objects (after calling toJSON())
|
|
877
|
+
*/
|
|
878
|
+
interface DestroyResultJSON<TEntity extends Entity, TReturn> extends PromiseLike<PlainObject<TReturn>[]> {
|
|
879
|
+
where(args: WhereQuery<TEntity>): DestroyResultJSON<TEntity, TReturn>;
|
|
1044
880
|
}
|
|
1045
881
|
/**
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
interface
|
|
1049
|
-
|
|
1050
|
-
/** Returns the generated SQL and parameters without executing the query. */
|
|
1051
|
-
toSQL(): {
|
|
1052
|
-
params: readonly unknown[];
|
|
1053
|
-
sql: string;
|
|
1054
|
-
};
|
|
882
|
+
* Result of a destroy operation that does not return records
|
|
883
|
+
*/
|
|
884
|
+
interface DestroyResult<TEntity extends Entity, TReturn> extends PromiseLike<TReturn> {
|
|
885
|
+
where(args: WhereQuery<TEntity>): DestroyResult<TEntity, TReturn>;
|
|
1055
886
|
}
|
|
1056
|
-
|
|
1057
887
|
/**
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
interface
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
888
|
+
* Result of a destroy operation that returns records (includes toJSON method)
|
|
889
|
+
*/
|
|
890
|
+
interface DestroyResultWithRecords<TEntity extends Entity, TReturn> extends PromiseLike<TReturn[]> {
|
|
891
|
+
where(args: WhereQuery<TEntity>): DestroyResultWithRecords<TEntity, TReturn>;
|
|
892
|
+
/**
|
|
893
|
+
* Returns results as plain objects instead of entity class instances.
|
|
894
|
+
* Useful for when data must be serializable.
|
|
895
|
+
*/
|
|
896
|
+
toJSON(): DestroyResultJSON<TEntity, TReturn>;
|
|
897
|
+
}
|
|
898
|
+
//#endregion
|
|
899
|
+
//#region src/query/UpdateResult.d.ts
|
|
900
|
+
/**
|
|
901
|
+
* Result of an update operation that returns plain objects (after calling toJSON())
|
|
902
|
+
*/
|
|
903
|
+
interface UpdateResultJSON<T extends Entity> extends PromiseLike<PlainObject<QueryResult<T>>[]> {
|
|
904
|
+
/**
|
|
905
|
+
* Returns results as plain objects instead of entity class instances.
|
|
906
|
+
* Useful for when data must be serializable.
|
|
907
|
+
*/
|
|
908
|
+
toJSON(): UpdateResultJSON<T>;
|
|
1066
909
|
}
|
|
1067
|
-
|
|
1068
|
-
interface FindOneArgs<T extends Record<string, unknown>, K extends keyof T = string & keyof OmitFunctions<T> & keyof T> {
|
|
1069
|
-
select?: (K & string & keyof OmitFunctions<T>)[];
|
|
1070
|
-
where?: WhereQuery<T>;
|
|
1071
|
-
sort?: Sort<T>;
|
|
1072
|
-
pool?: PoolLike;
|
|
1073
|
-
/** Control global filters. false = disable all, { filterName: false } = disable specific filter */
|
|
1074
|
-
filters?: Record<string, false> | false;
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
interface FindArgs<T extends Record<string, unknown>, K extends keyof T = keyof T> extends FindOneArgs<T, K> {
|
|
1078
|
-
skip?: number;
|
|
1079
|
-
limit?: number;
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
910
|
/**
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
911
|
+
* Result of an update operation that returns records
|
|
912
|
+
*/
|
|
913
|
+
interface UpdateResult<T extends Entity> extends PromiseLike<QueryResult<T>[]> {
|
|
914
|
+
/**
|
|
915
|
+
* Returns results as plain objects instead of entity class instances.
|
|
916
|
+
* Useful for when data must be serializable.
|
|
917
|
+
*/
|
|
918
|
+
toJSON(): UpdateResultJSON<T>;
|
|
919
|
+
}
|
|
920
|
+
//#endregion
|
|
921
|
+
//#region src/query/FindOneArgs.d.ts
|
|
922
|
+
interface FindOneArgs<T extends Entity, K extends keyof T = string & keyof OmitFunctions<OmitEntityCollections<T>> & keyof T> {
|
|
923
|
+
select?: (K & string & keyof OmitFunctions<OmitEntityCollections<T>>)[];
|
|
924
|
+
where?: WhereQuery<T>;
|
|
925
|
+
sort?: Sort<T>;
|
|
926
|
+
pool?: PoolLike;
|
|
927
|
+
}
|
|
928
|
+
//#endregion
|
|
929
|
+
//#region src/query/FindArgs.d.ts
|
|
930
|
+
interface FindArgs<T extends Entity, K extends keyof T = keyof T> extends FindOneArgs<T, K> {
|
|
931
|
+
skip?: number;
|
|
932
|
+
limit?: number;
|
|
933
|
+
}
|
|
934
|
+
//#endregion
|
|
935
|
+
//#region src/query/PopulateArgs.d.ts
|
|
936
|
+
/**
|
|
937
|
+
* Options for filtering and sorting by junction table columns in through relationships.
|
|
938
|
+
* Uses looser typing since the junction table entity type is determined at runtime.
|
|
939
|
+
*/
|
|
1086
940
|
interface ThroughArgs {
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
}
|
|
1092
|
-
interface PopulateArgs<T extends
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
interface
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
941
|
+
/** Filter applied to the junction table query */
|
|
942
|
+
where?: Record<string, unknown>;
|
|
943
|
+
/** Sort applied to the junction table query - determines final ordering of populated items */
|
|
944
|
+
sort?: SortObject<Entity> | string;
|
|
945
|
+
}
|
|
946
|
+
interface PopulateArgs<T extends Entity, K extends keyof T> {
|
|
947
|
+
where?: WhereQuery<T>;
|
|
948
|
+
select?: (K & string & keyof OmitFunctions<OmitEntityCollections<T>>)[];
|
|
949
|
+
sort?: Sort<T>;
|
|
950
|
+
skip?: number;
|
|
951
|
+
limit?: number;
|
|
952
|
+
pool?: PoolLike;
|
|
953
|
+
/**
|
|
954
|
+
* Options for filtering/sorting by junction table columns.
|
|
955
|
+
* Only applicable to many-to-many relationships that use `through`.
|
|
956
|
+
*/
|
|
957
|
+
through?: ThroughArgs;
|
|
958
|
+
}
|
|
959
|
+
//#endregion
|
|
960
|
+
//#region src/query/FindOneResult.d.ts
|
|
961
|
+
interface FindOneResultJSON<T extends Entity, TReturn, TJoins extends JoinInfo = never> extends PromiseLike<PlainObject<TReturn> | null> {
|
|
962
|
+
select<TKeys extends string & keyof OmitFunctions<QueryResult<T>>>(keys: TKeys[]): FindOneResultJSON<T, Pick<QueryResult<T>, TKeys>, TJoins>;
|
|
963
|
+
where(args: JoinedWhereQuery<T, TJoins>): FindOneResultJSON<T, TReturn, TJoins>;
|
|
964
|
+
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>): FindOneResultJSON<T, Omit<TReturn, TProperty> & Populated<T, TProperty, TPopulateType, TPopulateSelectKeys>, TJoins>;
|
|
965
|
+
join<TProperty extends ModelRelationshipKeys<T>, TAlias extends string = TProperty>(propertyName: TProperty, alias?: TAlias): FindOneResultJSON<T, TReturn, JoinInfo<TProperty, TAlias, GetValueType<T[TProperty], Entity>> | TJoins>;
|
|
966
|
+
leftJoin<TProperty extends ModelRelationshipKeys<T>, TAlias extends string = TProperty>(propertyName: TProperty, alias?: TAlias, on?: WhereQuery<GetValueType<T[TProperty], Entity>>): FindOneResultJSON<T, TReturn, JoinInfo<TProperty, TAlias, GetValueType<T[TProperty], Entity>> | TJoins>;
|
|
967
|
+
sort(value?: JoinedSort<T, TJoins>): FindOneResultJSON<T, TReturn, TJoins>;
|
|
968
|
+
UNSAFE_withOriginalFieldType<TProperty extends string & keyof PickByValueType<T, Entity> & keyof T>(propertyName: TProperty): FindOneResultJSON<T, Omit<TReturn, TProperty> & Pick<T, TProperty>, TJoins>;
|
|
969
|
+
UNSAFE_withFieldValue<TProperty extends string & keyof T, TValue extends T[TProperty]>(propertyName: TProperty, value: TValue): FindOneResultJSON<T, Omit<TReturn, TProperty> & PickAsType<T, TProperty, TValue>, TJoins>;
|
|
970
|
+
}
|
|
971
|
+
interface FindOneResult<T extends Entity, TReturn, TJoins extends JoinInfo = never> extends PromiseLike<TReturn | null> {
|
|
972
|
+
select<TKeys extends string & keyof OmitFunctions<QueryResult<T>>>(keys: TKeys[]): FindOneResult<T, Pick<QueryResult<T>, TKeys>, TJoins>;
|
|
973
|
+
where(args: JoinedWhereQuery<T, TJoins>): FindOneResult<T, TReturn, TJoins>;
|
|
974
|
+
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>, TJoins>;
|
|
975
|
+
join<TProperty extends ModelRelationshipKeys<T>, TAlias extends string = TProperty>(propertyName: TProperty, alias?: TAlias): FindOneResult<T, TReturn, JoinInfo<TProperty, TAlias, GetValueType<T[TProperty], Entity>> | TJoins>;
|
|
976
|
+
leftJoin<TProperty extends ModelRelationshipKeys<T>, TAlias extends string = TProperty>(propertyName: TProperty, alias?: TAlias, on?: WhereQuery<GetValueType<T[TProperty], Entity>>): FindOneResult<T, TReturn, JoinInfo<TProperty, TAlias, GetValueType<T[TProperty], Entity>> | TJoins>;
|
|
977
|
+
sort(value?: JoinedSort<T, TJoins>): FindOneResult<T, TReturn, TJoins>;
|
|
978
|
+
UNSAFE_withOriginalFieldType<TProperty extends string & keyof PickByValueType<T, Entity> & keyof T>(propertyName: TProperty): FindOneResult<T, Omit<TReturn, TProperty> & Pick<T, TProperty>, TJoins>;
|
|
979
|
+
UNSAFE_withFieldValue<TProperty extends string & keyof T, TValue extends T[TProperty]>(propertyName: TProperty, value: TValue): FindOneResult<T, Omit<TReturn, TProperty> & PickAsType<T, TProperty, TValue>, TJoins>;
|
|
980
|
+
/**
|
|
981
|
+
* Returns result as a plain object instead of an entity class instance.
|
|
982
|
+
* Useful for when data must be serializable.
|
|
983
|
+
*/
|
|
984
|
+
toJSON(): FindOneResultJSON<T, TReturn, TJoins>;
|
|
985
|
+
}
|
|
986
|
+
//#endregion
|
|
987
|
+
//#region src/query/PaginateOptions.d.ts
|
|
1125
988
|
interface PaginateOptions {
|
|
1126
|
-
|
|
1127
|
-
|
|
989
|
+
limit: number;
|
|
990
|
+
page: number;
|
|
1128
991
|
}
|
|
1129
|
-
|
|
992
|
+
//#endregion
|
|
993
|
+
//#region src/query/FindWithCountResult.d.ts
|
|
1130
994
|
interface FindWithCountResult<TReturn> {
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1134
|
-
interface
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
995
|
+
results: TReturn[];
|
|
996
|
+
totalCount: number;
|
|
997
|
+
}
|
|
998
|
+
interface FindQueryWithCountJSON<T extends Entity, TReturn, TJoins extends AnyJoinInfo = never> extends PromiseLike<FindWithCountResult<PlainObject<TReturn>>> {
|
|
999
|
+
select<TKeys extends string & keyof OmitFunctions<QueryResult<T>>>(keys: TKeys[]): FindQueryWithCountJSON<T, Pick<QueryResult<T>, TKeys>, TJoins>;
|
|
1000
|
+
where(args: JoinedWhereQuery<T, TJoins>): FindQueryWithCountJSON<T, TReturn, TJoins>;
|
|
1001
|
+
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>): FindQueryWithCountJSON<T, Omit<TReturn, TProperty> & Populated<T, TProperty, TPopulateType, TPopulateSelectKeys>, TJoins>;
|
|
1002
|
+
join<TProperty extends ModelRelationshipKeys<T>, TAlias extends string = TProperty>(propertyName: TProperty, alias?: TAlias): FindQueryWithCountJSON<T, TReturn, JoinInfo<TProperty, TAlias, GetValueType<T[TProperty], Entity>> | TJoins>;
|
|
1003
|
+
join<TAlias extends string, TColumns extends string>(subquery: TypedSubqueryBuilder<TColumns>, alias: TAlias, options: {
|
|
1004
|
+
on: SubqueryJoinOnCondition;
|
|
1005
|
+
}): FindQueryWithCountJSON<T, TReturn, SubqueryJoinInfo<TAlias, TColumns> | TJoins>;
|
|
1006
|
+
join(subquery: SubqueryBuilderLike, alias: string, options: {
|
|
1007
|
+
on: SubqueryJoinOnCondition;
|
|
1008
|
+
}): FindQueryWithCountJSON<T, TReturn, TJoins>;
|
|
1009
|
+
leftJoin<TProperty extends ModelRelationshipKeys<T>, TAlias extends string = TProperty>(propertyName: TProperty, alias?: TAlias, on?: WhereQuery<GetValueType<T[TProperty], Entity>>): FindQueryWithCountJSON<T, TReturn, JoinInfo<TProperty, TAlias, GetValueType<T[TProperty], Entity>> | TJoins>;
|
|
1010
|
+
leftJoin<TAlias extends string, TColumns extends string>(subquery: TypedSubqueryBuilder<TColumns>, alias: TAlias, options: {
|
|
1011
|
+
on: SubqueryJoinOnCondition;
|
|
1012
|
+
}): FindQueryWithCountJSON<T, TReturn, SubqueryJoinInfo<TAlias, TColumns> | TJoins>;
|
|
1013
|
+
leftJoin(subquery: SubqueryBuilderLike, alias: string, options: {
|
|
1014
|
+
on: SubqueryJoinOnCondition;
|
|
1015
|
+
}): FindQueryWithCountJSON<T, TReturn, TJoins>;
|
|
1016
|
+
sort(value?: JoinedSort<T, TJoins>): FindQueryWithCountJSON<T, TReturn, TJoins>;
|
|
1017
|
+
limit(value: number): FindQueryWithCountJSON<T, TReturn, TJoins>;
|
|
1018
|
+
skip(value: number): FindQueryWithCountJSON<T, TReturn, TJoins>;
|
|
1019
|
+
paginate(options: PaginateOptions): FindQueryWithCountJSON<T, TReturn, TJoins>;
|
|
1020
|
+
}
|
|
1021
|
+
interface FindQueryWithCount<T extends Entity, TReturn, TJoins extends AnyJoinInfo = never> extends PromiseLike<FindWithCountResult<TReturn>> {
|
|
1022
|
+
select<TKeys extends string & keyof OmitFunctions<QueryResult<T>>>(keys: TKeys[]): FindQueryWithCount<T, Pick<QueryResult<T>, TKeys>, TJoins>;
|
|
1023
|
+
where(args: JoinedWhereQuery<T, TJoins>): FindQueryWithCount<T, TReturn, TJoins>;
|
|
1024
|
+
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>): FindQueryWithCount<T, Omit<TReturn, TProperty> & Populated<T, TProperty, TPopulateType, TPopulateSelectKeys>, TJoins>;
|
|
1025
|
+
join<TProperty extends ModelRelationshipKeys<T>, TAlias extends string = TProperty>(propertyName: TProperty, alias?: TAlias): FindQueryWithCount<T, TReturn, JoinInfo<TProperty, TAlias, GetValueType<T[TProperty], Entity>> | TJoins>;
|
|
1026
|
+
join<TAlias extends string, TColumns extends string>(subquery: TypedSubqueryBuilder<TColumns>, alias: TAlias, options: {
|
|
1027
|
+
on: SubqueryJoinOnCondition;
|
|
1028
|
+
}): FindQueryWithCount<T, TReturn, SubqueryJoinInfo<TAlias, TColumns> | TJoins>;
|
|
1029
|
+
join(subquery: SubqueryBuilderLike, alias: string, options: {
|
|
1030
|
+
on: SubqueryJoinOnCondition;
|
|
1031
|
+
}): FindQueryWithCount<T, TReturn, TJoins>;
|
|
1032
|
+
leftJoin<TProperty extends ModelRelationshipKeys<T>, TAlias extends string = TProperty>(propertyName: TProperty, alias?: TAlias, on?: WhereQuery<GetValueType<T[TProperty], Entity>>): FindQueryWithCount<T, TReturn, JoinInfo<TProperty, TAlias, GetValueType<T[TProperty], Entity>> | TJoins>;
|
|
1033
|
+
leftJoin<TAlias extends string, TColumns extends string>(subquery: TypedSubqueryBuilder<TColumns>, alias: TAlias, options: {
|
|
1034
|
+
on: SubqueryJoinOnCondition;
|
|
1035
|
+
}): FindQueryWithCount<T, TReturn, SubqueryJoinInfo<TAlias, TColumns> | TJoins>;
|
|
1036
|
+
leftJoin(subquery: SubqueryBuilderLike, alias: string, options: {
|
|
1037
|
+
on: SubqueryJoinOnCondition;
|
|
1038
|
+
}): FindQueryWithCount<T, TReturn, TJoins>;
|
|
1039
|
+
sort(value?: JoinedSort<T, TJoins>): FindQueryWithCount<T, TReturn, TJoins>;
|
|
1040
|
+
limit(value: number): FindQueryWithCount<T, TReturn, TJoins>;
|
|
1041
|
+
skip(value: number): FindQueryWithCount<T, TReturn, TJoins>;
|
|
1042
|
+
paginate(options: PaginateOptions): FindQueryWithCount<T, TReturn, TJoins>;
|
|
1043
|
+
/**
|
|
1044
|
+
* Returns results as plain objects instead of entity class instances.
|
|
1045
|
+
* Useful for when data must be serializable.
|
|
1046
|
+
*/
|
|
1047
|
+
toJSON(): FindQueryWithCountJSON<T, TReturn, TJoins>;
|
|
1048
|
+
}
|
|
1049
|
+
//#endregion
|
|
1050
|
+
//#region src/query/FindResult.d.ts
|
|
1051
|
+
interface FindResultJSON<T extends Entity, TReturn, TJoins extends AnyJoinInfo = never> extends PromiseLike<PlainObject<TReturn>[]> {
|
|
1052
|
+
select<TKeys extends string & keyof OmitFunctions<QueryResult<T>>>(keys: TKeys[]): FindResultJSON<T, Pick<QueryResult<T>, TKeys>, TJoins>;
|
|
1053
|
+
where(args: JoinedWhereQuery<T, TJoins>): FindResultJSON<T, TReturn, TJoins>;
|
|
1054
|
+
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>): FindResultJSON<T, Omit<TReturn, TProperty> & Populated<T, TProperty, TPopulateType, TPopulateSelectKeys>, TJoins>;
|
|
1055
|
+
join<TProperty extends ModelRelationshipKeys<T>, TAlias extends string = TProperty>(propertyName: TProperty, alias?: TAlias): FindResultJSON<T, TReturn, JoinInfo<TProperty, TAlias, GetValueType<T[TProperty], Entity>> | TJoins>;
|
|
1056
|
+
/**
|
|
1057
|
+
* Join a subquery with type-safe column tracking.
|
|
1058
|
+
* Use `agg()` helper when building the subquery to enable type-safe sorting.
|
|
1059
|
+
* @example
|
|
1060
|
+
* const counts = subquery(ProductRepository)
|
|
1061
|
+
* .select(['store', agg(s => s.count(), 'productCount')])
|
|
1062
|
+
* .groupBy(['store']);
|
|
1063
|
+
* StoreRepository.find()
|
|
1064
|
+
* .join(counts, 'stats', { on: { id: 'store' } })
|
|
1065
|
+
* .sort('stats.productCount desc') // Type-safe!
|
|
1066
|
+
*/
|
|
1067
|
+
join<TAlias extends string, TColumns extends string>(subquery: TypedSubqueryBuilder<TColumns>, alias: TAlias, options: {
|
|
1068
|
+
on: SubqueryJoinOnCondition;
|
|
1069
|
+
}): FindResultJSON<T, TReturn, SubqueryJoinInfo<TAlias, TColumns> | TJoins>;
|
|
1070
|
+
/** @deprecated Use `agg()` helper for type-safe subquery column sorting */
|
|
1071
|
+
join(subquery: SubqueryBuilderLike, alias: string, options: {
|
|
1072
|
+
on: SubqueryJoinOnCondition;
|
|
1073
|
+
}): FindResultJSON<T, TReturn, TJoins>;
|
|
1074
|
+
leftJoin<TProperty extends ModelRelationshipKeys<T>, TAlias extends string = TProperty>(propertyName: TProperty, alias?: TAlias, on?: WhereQuery<GetValueType<T[TProperty], Entity>>): FindResultJSON<T, TReturn, JoinInfo<TProperty, TAlias, GetValueType<T[TProperty], Entity>> | TJoins>;
|
|
1075
|
+
/**
|
|
1076
|
+
* Left join a subquery with type-safe column tracking.
|
|
1077
|
+
* Use `agg()` helper when building the subquery to enable type-safe sorting.
|
|
1078
|
+
*/
|
|
1079
|
+
leftJoin<TAlias extends string, TColumns extends string>(subquery: TypedSubqueryBuilder<TColumns>, alias: TAlias, options: {
|
|
1080
|
+
on: SubqueryJoinOnCondition;
|
|
1081
|
+
}): FindResultJSON<T, TReturn, SubqueryJoinInfo<TAlias, TColumns> | TJoins>;
|
|
1082
|
+
/** @deprecated Use `agg()` helper for type-safe subquery column sorting */
|
|
1083
|
+
leftJoin(subquery: SubqueryBuilderLike, alias: string, options: {
|
|
1084
|
+
on: SubqueryJoinOnCondition;
|
|
1085
|
+
}): FindResultJSON<T, TReturn, TJoins>;
|
|
1086
|
+
/**
|
|
1087
|
+
* Selects distinct rows based on the specified columns (PostgreSQL DISTINCT ON).
|
|
1088
|
+
* The ORDER BY clause must start with the same columns in the same order.
|
|
1089
|
+
* Cannot be combined with withCount().
|
|
1090
|
+
* @param columns - Column names for DISTINCT ON clause
|
|
1091
|
+
*/
|
|
1092
|
+
distinctOn(columns: (string & keyof OmitFunctions<OmitEntityCollections<T>>)[]): FindResultJSON<T, TReturn, TJoins>;
|
|
1093
|
+
sort(value?: JoinedSort<T, TJoins>): FindResultJSON<T, TReturn, TJoins>;
|
|
1094
|
+
limit(value: number): FindResultJSON<T, TReturn, TJoins>;
|
|
1095
|
+
skip(value: number): FindResultJSON<T, TReturn, TJoins>;
|
|
1096
|
+
paginate(options: PaginateOptions): FindResultJSON<T, TReturn, TJoins>;
|
|
1097
|
+
withCount(): FindQueryWithCountJSON<T, TReturn, TJoins>;
|
|
1098
|
+
UNSAFE_withOriginalFieldType<TProperty extends string & keyof PickByValueType<T, Entity> & keyof T>(propertyName: TProperty): FindResultJSON<T, Omit<TReturn, TProperty> & Pick<T, TProperty>, TJoins>;
|
|
1099
|
+
}
|
|
1100
|
+
interface FindResult<T extends Entity, TReturn, TJoins extends AnyJoinInfo = never> extends PromiseLike<TReturn[]> {
|
|
1101
|
+
select<TKeys extends string & keyof OmitFunctions<QueryResult<T>>>(keys: TKeys[]): FindResult<T, Pick<QueryResult<T>, TKeys>, TJoins>;
|
|
1102
|
+
where(args: JoinedWhereQuery<T, TJoins>): FindResult<T, TReturn, TJoins>;
|
|
1103
|
+
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>, TJoins>;
|
|
1104
|
+
join<TProperty extends ModelRelationshipKeys<T>, TAlias extends string = TProperty>(propertyName: TProperty, alias?: TAlias): FindResult<T, TReturn, JoinInfo<TProperty, TAlias, GetValueType<T[TProperty], Entity>> | TJoins>;
|
|
1105
|
+
/**
|
|
1106
|
+
* Join a subquery with type-safe column tracking.
|
|
1107
|
+
* Use `agg()` helper when building the subquery to enable type-safe sorting.
|
|
1108
|
+
* @example
|
|
1109
|
+
* const counts = subquery(ProductRepository)
|
|
1110
|
+
* .select(['store', agg(s => s.count(), 'productCount')])
|
|
1111
|
+
* .groupBy(['store']);
|
|
1112
|
+
* StoreRepository.find()
|
|
1113
|
+
* .join(counts, 'stats', { on: { id: 'store' } })
|
|
1114
|
+
* .sort('stats.productCount desc') // Type-safe!
|
|
1115
|
+
*/
|
|
1116
|
+
join<TAlias extends string, TColumns extends string>(subquery: TypedSubqueryBuilder<TColumns>, alias: TAlias, options: {
|
|
1117
|
+
on: SubqueryJoinOnCondition;
|
|
1118
|
+
}): FindResult<T, TReturn, SubqueryJoinInfo<TAlias, TColumns> | TJoins>;
|
|
1119
|
+
/** @deprecated Use `agg()` helper for type-safe subquery column sorting */
|
|
1120
|
+
join(subquery: SubqueryBuilderLike, alias: string, options: {
|
|
1121
|
+
on: SubqueryJoinOnCondition;
|
|
1122
|
+
}): FindResult<T, TReturn, TJoins>;
|
|
1123
|
+
leftJoin<TProperty extends ModelRelationshipKeys<T>, TAlias extends string = TProperty>(propertyName: TProperty, alias?: TAlias, on?: WhereQuery<GetValueType<T[TProperty], Entity>>): FindResult<T, TReturn, JoinInfo<TProperty, TAlias, GetValueType<T[TProperty], Entity>> | TJoins>;
|
|
1124
|
+
/**
|
|
1125
|
+
* Left join a subquery with type-safe column tracking.
|
|
1126
|
+
* Use `agg()` helper when building the subquery to enable type-safe sorting.
|
|
1127
|
+
*/
|
|
1128
|
+
leftJoin<TAlias extends string, TColumns extends string>(subquery: TypedSubqueryBuilder<TColumns>, alias: TAlias, options: {
|
|
1129
|
+
on: SubqueryJoinOnCondition;
|
|
1130
|
+
}): FindResult<T, TReturn, SubqueryJoinInfo<TAlias, TColumns> | TJoins>;
|
|
1131
|
+
/** @deprecated Use `agg()` helper for type-safe subquery column sorting */
|
|
1132
|
+
leftJoin(subquery: SubqueryBuilderLike, alias: string, options: {
|
|
1133
|
+
on: SubqueryJoinOnCondition;
|
|
1134
|
+
}): FindResult<T, TReturn, TJoins>;
|
|
1135
|
+
/**
|
|
1136
|
+
* Selects distinct rows based on the specified columns (PostgreSQL DISTINCT ON).
|
|
1137
|
+
* The ORDER BY clause must start with the same columns in the same order.
|
|
1138
|
+
* Cannot be combined with withCount().
|
|
1139
|
+
* @param columns - Column names for DISTINCT ON clause
|
|
1140
|
+
*/
|
|
1141
|
+
distinctOn(columns: (string & keyof OmitFunctions<OmitEntityCollections<T>>)[]): FindResult<T, TReturn, TJoins>;
|
|
1142
|
+
sort(value?: JoinedSort<T, TJoins>): FindResult<T, TReturn, TJoins>;
|
|
1143
|
+
limit(value: number): FindResult<T, TReturn, TJoins>;
|
|
1144
|
+
skip(value: number): FindResult<T, TReturn, TJoins>;
|
|
1145
|
+
paginate(options: PaginateOptions): FindResult<T, TReturn, TJoins>;
|
|
1146
|
+
withCount(): FindQueryWithCount<T, TReturn, TJoins>;
|
|
1147
|
+
UNSAFE_withOriginalFieldType<TProperty extends string & keyof PickByValueType<T, Entity> & keyof T>(propertyName: TProperty): FindResult<T, Omit<TReturn, TProperty> & Pick<T, TProperty>, TJoins>;
|
|
1148
|
+
/**
|
|
1149
|
+
* Returns results as plain objects instead of entity class instances.
|
|
1150
|
+
* Useful for when data must be serializable.
|
|
1151
|
+
*/
|
|
1152
|
+
toJSON(): FindResultJSON<T, TReturn, TJoins>;
|
|
1153
|
+
}
|
|
1154
|
+
//#endregion
|
|
1155
|
+
//#region src/IRepository.d.ts
|
|
1156
|
+
interface IRepository<T extends Entity> extends IReadonlyRepository<T> {
|
|
1157
|
+
/**
|
|
1158
|
+
* Creates an object using the specified values
|
|
1159
|
+
* @param {object} values - Values to insert as multiple new objects.
|
|
1160
|
+
* @param {object} [options]
|
|
1161
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
1162
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
1163
|
+
* @returns {object}
|
|
1164
|
+
*/
|
|
1165
|
+
create(values: CreateUpdateParams<T>, options?: OnConflictOptions<T> | (Partial<OnConflictOptions<T>> & ReturnSelect<T>)): CreateResult<T>;
|
|
1166
|
+
/**
|
|
1167
|
+
* Creates an object or objects using the specified values
|
|
1168
|
+
* @param {object|object[]} values - Values to insert as multiple new objects.
|
|
1169
|
+
* @param {object} options
|
|
1170
|
+
* @param {boolean} options.returnRecords - Determines if inserted records should be returned
|
|
1171
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
1172
|
+
* @returns {void}
|
|
1173
|
+
*/
|
|
1174
|
+
create(values: CreateUpdateParams<T> | CreateUpdateParams<T>[], options: DoNotReturnRecords & Partial<OnConflictOptions<T>>): Promise<void>;
|
|
1175
|
+
/**
|
|
1176
|
+
* Creates objects using the specified values
|
|
1177
|
+
* @param {object[]} values - Values to insert as multiple new objects.
|
|
1178
|
+
* @param {object} [options]
|
|
1179
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
1180
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
1181
|
+
* @returns {object[]}
|
|
1182
|
+
*/
|
|
1183
|
+
create(values: CreateUpdateParams<T>[], options?: (OnConflictOptions<T> & Partial<ReturnSelect<T>>) | (Partial<OnConflictOptions<T>> & ReturnSelect<T>)): CreateResultArray<T>;
|
|
1184
|
+
/**
|
|
1185
|
+
* Creates an object using the specified values
|
|
1186
|
+
* @param {object|object[]} values - Values to insert as a new object. If an array is specified, multiple rows will be inserted
|
|
1187
|
+
* @param {object} [options]
|
|
1188
|
+
* @param {boolean} [options.returnRecords=true] - Determines if inserted records should be returned
|
|
1189
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
1190
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
1191
|
+
* @returns {object|object[]|void} Return value from the db
|
|
1192
|
+
*/
|
|
1193
|
+
create(values: CreateUpdateParams<T> | CreateUpdateParams<T>[], options?: CreateOptions<T>): CreateResult<T> | CreateResultArray<T> | Promise<void>;
|
|
1194
|
+
/**
|
|
1195
|
+
* Updates object(s) matching the where query, with the specified values
|
|
1196
|
+
* @param {object} where - Object representing the where query
|
|
1197
|
+
* @param {object} values - Values to update
|
|
1198
|
+
* @param {object} options
|
|
1199
|
+
* @param {boolean} options.returnRecords - Determines if inserted records should be returned
|
|
1200
|
+
* @param {{returnRecords: false}} options
|
|
1201
|
+
* @returns {void}
|
|
1202
|
+
*/
|
|
1203
|
+
update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options: DoNotReturnRecords): Promise<void>;
|
|
1204
|
+
/**
|
|
1205
|
+
* Updates object(s) matching the where query, with the specified values
|
|
1206
|
+
* @param {object} where - Object representing the where query
|
|
1207
|
+
* @param {object} values - Values to update
|
|
1208
|
+
* @param {object} [options] - Values to update
|
|
1209
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
1210
|
+
* @returns {object[]}
|
|
1211
|
+
*/
|
|
1212
|
+
update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options?: ReturnSelect<T>): UpdateResult<T>;
|
|
1213
|
+
/**
|
|
1214
|
+
* Updates object(s) matching the where query, with the specified values
|
|
1215
|
+
* @param {object} where - Object representing the where query
|
|
1216
|
+
* @param {object} values - Values to update
|
|
1217
|
+
* @param {object} [options]
|
|
1218
|
+
* @param {boolean} [options.returnRecords=true] - Determines if inserted records should be returned
|
|
1219
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
1220
|
+
* @returns {object[]|void} Return values from the db or `true` if returnRecords=false
|
|
1221
|
+
*/
|
|
1222
|
+
update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options?: CreateUpdateOptions<T>): Promise<void> | UpdateResult<T>;
|
|
1223
|
+
/**
|
|
1224
|
+
* Destroys object(s) matching the where query
|
|
1225
|
+
* @param {object} [where] - Object representing the where query
|
|
1226
|
+
* @returns {void}
|
|
1227
|
+
*/
|
|
1228
|
+
destroy(where?: WhereQuery<T>): DestroyResult<T, void>;
|
|
1229
|
+
/**
|
|
1230
|
+
* Destroys object(s) matching the where query
|
|
1231
|
+
* @param {object} where - Object representing the where query
|
|
1232
|
+
* @param {object} options - Determines if inserted records should be returned
|
|
1233
|
+
* @param {boolean} [options.returnRecords] - Determines if inserted records should be returned
|
|
1234
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
1235
|
+
* @returns {object[]}
|
|
1236
|
+
*/
|
|
1237
|
+
destroy(where: WhereQuery<T>, options: DeleteOptions<T>): DestroyResultWithRecords<T, QueryResult<T>>;
|
|
1238
|
+
}
|
|
1239
|
+
//#endregion
|
|
1240
|
+
//#region src/query/Subquery.d.ts
|
|
1241
|
+
declare function subquery<T extends Entity>(repository: IReadonlyRepository<T> | IRepository<T>): SubqueryBuilder<T>;
|
|
1242
|
+
//#endregion
|
|
1243
|
+
//#region src/query/WhereQuery.d.ts
|
|
1304
1244
|
type ExcludeUndefined<T> = Exclude<T, undefined>;
|
|
1305
1245
|
type LiteralValues<TValue> = (TValue | null)[] | TValue | null;
|
|
1306
|
-
type WhereClauseValue<TValue> = LiteralValues<ExcludeUndefined<TValue
|
|
1307
|
-
type StringConstraint<TValue extends string> = Partial<Record<
|
|
1246
|
+
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;
|
|
1247
|
+
type StringConstraint<TValue extends string> = Partial<Record<"contains" | "endsWith" | "like" | "startsWith", LiteralValues<ExcludeUndefined<TValue>>>>;
|
|
1308
1248
|
type JsonPropertyValue = boolean | number | string | null;
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
type
|
|
1314
|
-
|
|
1249
|
+
interface JsonPropertyConstraint {
|
|
1250
|
+
[key: string]: JsonPropertyConstraint | JsonPropertyValue | JsonPropertyValue[] | Partial<Record<"!" | "<" | "<=" | ">" | ">=", JsonPropertyValue>> | undefined;
|
|
1251
|
+
}
|
|
1252
|
+
type JsonConstraint<TValue> = Partial<Record<"contains", ExcludeUndefined<TValue> | LiteralValues<ExcludeUndefined<TValue>>>>;
|
|
1253
|
+
type NumberOrDateConstraint<TValue extends Date | number> = Partial<Record<"<" | "<=" | ">" | ">=", LiteralValues<ExcludeUndefined<TValue>>>>;
|
|
1254
|
+
interface VectorDistanceConstraint {
|
|
1255
|
+
nearestTo: number[];
|
|
1256
|
+
metric?: VectorDistanceMetric;
|
|
1257
|
+
/**
|
|
1258
|
+
* Distance bound(s) combined with AND. Required: pgvector distance operators return a number, so a where
|
|
1259
|
+
* constraint without a bound would not be a boolean expression. Use `sort({ column: { nearestTo } })` to
|
|
1260
|
+
* order by distance instead.
|
|
1261
|
+
*/
|
|
1262
|
+
distance: Partial<Record<"<" | "<=" | ">" | ">=", number>>;
|
|
1263
|
+
}
|
|
1315
1264
|
interface SubqueryInConstraint {
|
|
1316
|
-
|
|
1265
|
+
in: SubqueryBuilderLike;
|
|
1317
1266
|
}
|
|
1318
|
-
type ScalarSubqueryConstraint<TValue> = Partial<Record<
|
|
1267
|
+
type ScalarSubqueryConstraint<TValue> = Partial<Record<"<" | "<=" | ">" | ">=", ScalarSubquery<TValue | undefined> | ScalarSubquery<TValue>>>;
|
|
1319
1268
|
type NumberOrDateConstraintWithSubquery<TValue extends Date | number> = NumberOrDateConstraint<TValue> | ScalarSubqueryConstraint<TValue>;
|
|
1320
1269
|
type NegatableConstraint<TValue> = TValue | {
|
|
1321
|
-
|
|
1270
|
+
"!": TValue;
|
|
1322
1271
|
};
|
|
1323
1272
|
type WhereQueryStatement<TValue> = [TValue] extends [string] ? NegatableConstraint<StringConstraint<TValue> | SubqueryInConstraint | WhereClauseValue<TValue>> : TValue extends string ? NegatableConstraint<StringConstraint<TValue> | SubqueryInConstraint | WhereClauseValue<TValue>> : TValue extends Date | number ? NegatableConstraint<NumberOrDateConstraintWithSubquery<TValue> | SubqueryInConstraint | WhereClauseValue<TValue>> : NegatableConstraint<JsonConstraint<TValue> | JsonPropertyConstraint | SubqueryInConstraint | WhereClauseValue<TValue>>;
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
type WhereQueryRecord<T extends Record<string, unknown>> = {
|
|
1330
|
-
[K in keyof T as ExcludeEntityCollections<ExcludeFunctions<T[K], K>>]?: K extends 'id' ? NegatableConstraint<WhereClauseValue<T>> | WhereQueryStatement<T[K]> : T[K] extends (infer U)[] | undefined ? WhereQueryStatement<ExcludeUndefined<U>> : NegatableConstraint<LiteralValues<ExcludeUndefined<T[K]>>> | WhereQueryStatement<ExcludeUndefined<T[K]>>;
|
|
1331
|
-
} & {
|
|
1332
|
-
and?: WhereQueryRecord<T>[];
|
|
1333
|
-
or?: WhereQueryRecord<T>[];
|
|
1334
|
-
exists?: SubqueryBuilderLike;
|
|
1335
|
-
'!'?: Pick<WhereQueryRecord<T>, 'exists'>;
|
|
1273
|
+
type WhereQuery<T extends Entity> = { [K in keyof T as ExcludeEntityCollections<T[K], ExcludeFunctions<T[K], K>>]?: K extends "id" ? NegatableConstraint<WhereClauseValue<T>> | WhereQueryStatement<T[K]> : T[K] extends (infer U)[] | undefined ? [U] extends [number] ? VectorDistanceConstraint | WhereQueryStatement<ExcludeUndefined<U>> : WhereQueryStatement<ExcludeUndefined<U>> : NegatableConstraint<LiteralValues<ExcludeUndefined<T[K]>>> | WhereQueryStatement<ExcludeUndefined<T[K]>> } & {
|
|
1274
|
+
and?: WhereQuery<T>[];
|
|
1275
|
+
or?: WhereQuery<T>[];
|
|
1276
|
+
exists?: SubqueryBuilderLike;
|
|
1277
|
+
"!"?: Pick<WhereQuery<T>, "exists">;
|
|
1336
1278
|
};
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1279
|
+
//#endregion
|
|
1280
|
+
//#region src/query/CountArgs.d.ts
|
|
1281
|
+
interface CountArgs<T extends Entity> {
|
|
1282
|
+
where?: WhereQuery<T>;
|
|
1283
|
+
pool?: PoolLike;
|
|
1284
|
+
}
|
|
1285
|
+
//#endregion
|
|
1286
|
+
//#region src/IReadonlyRepository.d.ts
|
|
1287
|
+
interface IReadonlyRepository<T extends Entity> {
|
|
1288
|
+
readonly model: ModelMetadata<T>;
|
|
1289
|
+
/**
|
|
1290
|
+
* Gets a single object
|
|
1291
|
+
* @param {object} [args] - Arguments
|
|
1292
|
+
* @param {string[]} [args.select] - Array of model property names to return from the query.
|
|
1293
|
+
* @param {object} [args.where] - Object representing the where query
|
|
1294
|
+
* @param {string|object|string[]|object[]} [args.sort] - Property name(s) to sort by
|
|
1295
|
+
* @param {object} [args.pool] - Override the db pool to use for the query
|
|
1296
|
+
*/
|
|
1297
|
+
findOne<K extends string & keyof T, TReturn = QueryResult<Pick<T, K | "id">>>(args: FindOneArgs<T, K> | WhereQuery<T>): FindOneResult<T, TReturn>;
|
|
1298
|
+
/**
|
|
1299
|
+
* Gets a collection of objects
|
|
1300
|
+
* @param {object} [args] - Arguments
|
|
1301
|
+
* @param {string[]} [args.select] - Array of model property names to return from the query.
|
|
1302
|
+
* @param {object} [args.where] - Object representing the where query
|
|
1303
|
+
* @param {string|object|string[]|object[]} [args.sort] - Property name(s) to sort by
|
|
1304
|
+
* @param {string|number} [args.skip] - Number of records to skip
|
|
1305
|
+
* @param {string|number} [args.limit] - Number of results to return
|
|
1306
|
+
* @param {object} [args.pool] - Override the db pool to use for the query
|
|
1307
|
+
*/
|
|
1308
|
+
find<K extends string & keyof T, TReturn = QueryResult<Pick<T, K | "id">>>(args: FindArgs<T, K> | WhereQuery<T>): FindResult<T, TReturn>;
|
|
1309
|
+
/**
|
|
1310
|
+
* Gets a count of rows matching the where query
|
|
1311
|
+
* @param {object} [args] - Arguments
|
|
1312
|
+
* @param {object} [args.where] - Object representing the where query
|
|
1313
|
+
* @param {object} [args.pool] - Override the db pool to use for the query
|
|
1314
|
+
* @returns {number} Number of records matching the where criteria
|
|
1315
|
+
*/
|
|
1316
|
+
count(args?: CountArgs<T> | WhereQuery<T>): CountResult<T>;
|
|
1317
|
+
}
|
|
1318
|
+
//#endregion
|
|
1319
|
+
//#region src/ReadonlyRepository.d.ts
|
|
1320
|
+
interface IRepositoryOptions<T extends Entity> {
|
|
1321
|
+
modelMetadata: ModelMetadata<T>;
|
|
1322
|
+
type: EntityStatic<T>;
|
|
1323
|
+
repositoriesByModelNameLowered: Record<string, IReadonlyRepository<Entity> | IRepository<Entity>>;
|
|
1324
|
+
pool: PoolLike;
|
|
1325
|
+
readonlyPool?: PoolLike;
|
|
1326
|
+
}
|
|
1327
|
+
interface Populate {
|
|
1328
|
+
propertyName: string;
|
|
1329
|
+
where?: WhereQuery<Entity>;
|
|
1330
|
+
select?: string[];
|
|
1331
|
+
sort?: SortObject<Entity> | string;
|
|
1332
|
+
skip?: number;
|
|
1333
|
+
limit?: number;
|
|
1334
|
+
pool?: PoolLike;
|
|
1335
|
+
asPlainObjects?: boolean;
|
|
1336
|
+
through?: {
|
|
1337
|
+
where?: Record<string, unknown>;
|
|
1338
|
+
sort?: SortObject<Entity> | string;
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1341
|
+
declare class ReadonlyRepository<T extends Entity> implements IReadonlyRepository<T> {
|
|
1342
|
+
private readonly _modelMetadata;
|
|
1343
|
+
protected _type: EntityStatic<T>;
|
|
1344
|
+
protected _pool: PoolLike;
|
|
1345
|
+
protected _readonlyPool: PoolLike;
|
|
1346
|
+
protected _repositoriesByModelNameLowered: Record<string, IReadonlyRepository<Entity> | IRepository<Entity>>;
|
|
1347
|
+
protected _floatProperties: string[];
|
|
1348
|
+
protected _intProperties: string[];
|
|
1349
|
+
protected _vectorProperties: string[];
|
|
1350
|
+
constructor({
|
|
1351
|
+
modelMetadata,
|
|
1352
|
+
type,
|
|
1353
|
+
pool,
|
|
1354
|
+
readonlyPool,
|
|
1355
|
+
repositoriesByModelNameLowered
|
|
1356
|
+
}: IRepositoryOptions<T>);
|
|
1357
|
+
get model(): ModelMetadata<T>;
|
|
1358
|
+
/**
|
|
1359
|
+
* Gets a single object
|
|
1360
|
+
* @param {object} [args] - Arguments
|
|
1361
|
+
* @param {string[]} [args.select] - Array of model property names to return from the query.
|
|
1362
|
+
* @param {object} [args.where] - Object representing the where query
|
|
1363
|
+
* @param {string|object} [args.sort] - Property name(s) to sort by
|
|
1364
|
+
* @returns Database record or null
|
|
1365
|
+
*/
|
|
1366
|
+
findOne<K extends string & keyof T, TReturn = QueryResult<Pick<T, K | keyof PickFunctions<T> | "id">>>(args?: FindOneArgs<T, K> | WhereQuery<T>): FindOneResult<T, TReturn>;
|
|
1367
|
+
/**
|
|
1368
|
+
* Gets a collection of objects
|
|
1369
|
+
* @param {object} [args] - Arguments
|
|
1370
|
+
* @param {string[]} [args.select] - Array of model property names to return from the query.
|
|
1371
|
+
* @param {object} [args.where] - Object representing the where query
|
|
1372
|
+
* @param {string|object} [args.sort] - Property name(s) to sort by
|
|
1373
|
+
* @param {string|number} [args.skip] - Number of records to skip
|
|
1374
|
+
* @param {string|number} [args.limit] - Number of results to return
|
|
1375
|
+
* @returns Database records
|
|
1376
|
+
*/
|
|
1377
|
+
find<K extends string & keyof T, TReturn = QueryResult<Pick<T, K | keyof PickFunctions<T> | "id">>>(args?: FindArgs<T, K> | WhereQuery<T>): FindResult<T, TReturn>;
|
|
1378
|
+
/**
|
|
1379
|
+
* Gets a count of rows matching the where query
|
|
1380
|
+
* @param {object} [args] - Arguments
|
|
1381
|
+
* @param {object} [args.where] - Object representing the where query
|
|
1382
|
+
* @param {object} [args.pool] - Override the db pool to use for the query
|
|
1383
|
+
* @returns {number} Number of records matching the where criteria
|
|
1384
|
+
*/
|
|
1385
|
+
count(args?: CountArgs<T> | WhereQuery<T>): CountResult<T>;
|
|
1386
|
+
protected _buildInstance(row: Partial<QueryResult<T>>): QueryResult<T>;
|
|
1387
|
+
protected _buildInstances(rows: Partial<QueryResult<T>>[]): QueryResult<T>[];
|
|
1388
|
+
protected _buildPlainObject(row: Partial<QueryResult<T>>): QueryResult<T>;
|
|
1389
|
+
protected _buildPlainObjects(rows: Partial<QueryResult<T>>[]): QueryResult<T>[];
|
|
1390
|
+
protected _parseVectorString(value: string): number[] | undefined;
|
|
1391
|
+
protected _convertSortsToOrderBy(sorts: SortObject<T> | string): OrderBy<T>[];
|
|
1392
|
+
protected populateFields(entities: QueryResult<T>[], populates: Populate[]): Promise<void>;
|
|
1393
|
+
private populateSingleAssociation;
|
|
1394
|
+
private populateOneManyCollection;
|
|
1395
|
+
private populateManyManyCollection;
|
|
1396
|
+
}
|
|
1397
|
+
//#endregion
|
|
1398
|
+
//#region src/Repository.d.ts
|
|
1399
|
+
declare class Repository<T extends Entity> extends ReadonlyRepository<T> implements IRepository<T> {
|
|
1400
|
+
/**
|
|
1401
|
+
* Creates an object using the specified values
|
|
1402
|
+
* @param {object} values - Values to insert as multiple new objects.
|
|
1403
|
+
* @param {object} [options]
|
|
1404
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
1405
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
1406
|
+
* @returns {object}
|
|
1407
|
+
*/
|
|
1408
|
+
create(values: CreateUpdateParams<T>, options?: OnConflictOptions<T> | (Partial<OnConflictOptions<T>> & ReturnSelect<T>)): CreateResult<T>;
|
|
1409
|
+
/**
|
|
1410
|
+
* Creates an object or objects using the specified values
|
|
1411
|
+
* @param {object|object[]} values - Values to insert as multiple new objects.
|
|
1412
|
+
* @param {object} options
|
|
1413
|
+
* @param {boolean} options.returnRecords - Determines if inserted records should be returned
|
|
1414
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
1415
|
+
* @returns {void}
|
|
1416
|
+
*/
|
|
1417
|
+
create(values: CreateUpdateParams<T> | CreateUpdateParams<T>[], options: DoNotReturnRecords & Partial<OnConflictOptions<T>>): Promise<void>;
|
|
1418
|
+
/**
|
|
1419
|
+
* Creates objects using the specified values
|
|
1420
|
+
* @param {object[]} values - Values to insert as multiple new objects.
|
|
1421
|
+
* @param {object} [options]
|
|
1422
|
+
* @param {object} [options.onConflict] - Options to handle conflicts due to a unique constraint or exclusion constraint error during insert
|
|
1423
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
1424
|
+
* @returns {object[]}
|
|
1425
|
+
*/
|
|
1426
|
+
create(values: CreateUpdateParams<T>[], options?: (OnConflictOptions<T> & Partial<ReturnSelect<T>>) | (Partial<OnConflictOptions<T>> & ReturnSelect<T>)): CreateResultArray<T>;
|
|
1427
|
+
/**
|
|
1428
|
+
* Updates object(s) matching the where query, with the specified values
|
|
1429
|
+
* @param {object} where - Object representing the where query
|
|
1430
|
+
* @param {object} values - Values to update
|
|
1431
|
+
* @param {object} options
|
|
1432
|
+
* @param {boolean} options.returnRecords - Determines if inserted records should be returned
|
|
1433
|
+
* @returns {void}
|
|
1434
|
+
*/
|
|
1435
|
+
update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options: DoNotReturnRecords): Promise<void>;
|
|
1436
|
+
/**
|
|
1437
|
+
* Updates object(s) matching the where query, with the specified values
|
|
1438
|
+
* @param {object} where - Object representing the where query
|
|
1439
|
+
* @param {object} values - Values to update
|
|
1440
|
+
* @param {object} [options] - Values to update
|
|
1441
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
1442
|
+
* @returns {object[]}
|
|
1443
|
+
*/
|
|
1444
|
+
update(where: WhereQuery<T>, values: CreateUpdateParams<T>, options?: ReturnSelect<T>): UpdateResult<T>;
|
|
1445
|
+
/**
|
|
1446
|
+
* Destroys object(s) matching the where query
|
|
1447
|
+
* @param {object} [where] - Object representing the where query
|
|
1448
|
+
* @returns {void}
|
|
1449
|
+
*/
|
|
1450
|
+
destroy(where?: WhereQuery<T>): DestroyResult<T, void>;
|
|
1451
|
+
/**
|
|
1452
|
+
* Destroys object(s) matching the where query
|
|
1453
|
+
* @param {object} where - Object representing the where query
|
|
1454
|
+
* @param {object} options - Determines if inserted records should be returned
|
|
1455
|
+
* @param {boolean} [options.returnRecords] - Determines if inserted records should be returned
|
|
1456
|
+
* @param {string[]} [options.returnSelect] - Array of model property names to return from the query.
|
|
1457
|
+
* @returns {object[]}
|
|
1458
|
+
*/
|
|
1459
|
+
destroy(where: WhereQuery<T>, options: DeleteOptions<T>): DestroyResultWithRecords<T, QueryResult<T>>;
|
|
1460
|
+
}
|
|
1461
|
+
//#endregion
|
|
1462
|
+
//#region src/decorators/ColumnBaseOptions.d.ts
|
|
1463
|
+
interface ColumnBaseOptions {
|
|
1464
|
+
/**
|
|
1465
|
+
* Column name in the database
|
|
1466
|
+
*/
|
|
1467
|
+
name?: string;
|
|
1468
|
+
/**
|
|
1469
|
+
* Indicates if a value is required for creates.
|
|
1470
|
+
*/
|
|
1471
|
+
required?: boolean;
|
|
1472
|
+
}
|
|
1473
|
+
//#endregion
|
|
1474
|
+
//#region src/decorators/ColumnCollectionOptions.d.ts
|
|
1475
|
+
interface ColumnCollectionOptions extends ColumnBaseOptions {
|
|
1476
|
+
/**
|
|
1477
|
+
* Type of the items in the collection
|
|
1478
|
+
*/
|
|
1479
|
+
collection: string | (() => string);
|
|
1480
|
+
/**
|
|
1481
|
+
* Property name of the on the collection item type
|
|
1482
|
+
*/
|
|
1483
|
+
via: string;
|
|
1484
|
+
/**
|
|
1485
|
+
* Name of the junction table for multi-multi associations
|
|
1486
|
+
*/
|
|
1487
|
+
through?: string | (() => string);
|
|
1488
|
+
}
|
|
1489
|
+
//#endregion
|
|
1490
|
+
//#region src/decorators/ColumnModelOptions.d.ts
|
|
1491
|
+
interface ColumnModelOptions extends ColumnBaseOptions {
|
|
1492
|
+
/**
|
|
1493
|
+
* Type of the entity represented by this column id
|
|
1494
|
+
*/
|
|
1495
|
+
model: string | (() => string);
|
|
1496
|
+
}
|
|
1497
|
+
//#endregion
|
|
1498
|
+
//#region src/decorators/ColumnTypeOptions.d.ts
|
|
1499
|
+
interface ColumnTypeOptions extends ColumnBaseOptions {
|
|
1500
|
+
/**
|
|
1501
|
+
* Type of the column
|
|
1502
|
+
*/
|
|
1503
|
+
type: "array" | "binary" | "boolean" | "boolean[]" | "date" | "datetime" | "float" | "float[]" | "integer" | "integer[]" | "json" | "string" | "string[]" | "uuid" | "uuid[]" | "vector";
|
|
1504
|
+
/**
|
|
1505
|
+
* Default database value
|
|
1506
|
+
*/
|
|
1507
|
+
defaultsTo?: boolean[] | number[] | string[] | boolean | number | string | (() => Date | Record<string, unknown> | boolean | number | string) | [];
|
|
1508
|
+
/**
|
|
1509
|
+
* Number of dimensions for the column. Informational only - BigAl does not issue DDL
|
|
1510
|
+
*
|
|
1511
|
+
* Applies to types: vector
|
|
1512
|
+
*/
|
|
1513
|
+
dimensions?: number;
|
|
1514
|
+
/**
|
|
1515
|
+
* Array of possible enumerated values
|
|
1516
|
+
*/
|
|
1517
|
+
enum?: readonly string[];
|
|
1518
|
+
/**
|
|
1519
|
+
* If set, enforces a maximum length check on the column
|
|
1520
|
+
*
|
|
1521
|
+
* Applies to types: string | string[]
|
|
1522
|
+
*/
|
|
1523
|
+
maxLength?: number;
|
|
1524
|
+
}
|
|
1525
|
+
//#endregion
|
|
1526
|
+
//#region src/decorators/column.d.ts
|
|
1527
|
+
type ColumnOptions$1 = ColumnCollectionOptions | ColumnModelOptions | ColumnTypeOptions;
|
|
1528
|
+
type ReturnFunctionType$5 = (object: ClassLike, propertyName: string) => void;
|
|
1529
|
+
declare function column(options?: ColumnOptions$1): ReturnFunctionType$5;
|
|
1530
|
+
declare function column(dbColumnName: string, options?: ColumnOptions$1): ReturnFunctionType$5;
|
|
1531
|
+
//#endregion
|
|
1532
|
+
//#region src/decorators/createDateColumn.d.ts
|
|
1533
|
+
type ReturnFunctionType$4 = (object: ClassLike, propertyName: string) => void;
|
|
1534
|
+
declare function createDateColumn(options?: ColumnTypeOptions): ReturnFunctionType$4;
|
|
1535
|
+
declare function createDateColumn(dbColumnName: string, options?: ColumnTypeOptions): ReturnFunctionType$4;
|
|
1536
|
+
//#endregion
|
|
1537
|
+
//#region src/decorators/primaryColumn.d.ts
|
|
1538
|
+
type ColumnOptions = ColumnModelOptions | ColumnTypeOptions;
|
|
1539
|
+
type ReturnFunctionType$3 = (object: ClassLike, propertyName: string) => void;
|
|
1540
|
+
declare function primaryColumn(options?: ColumnOptions): ReturnFunctionType$3;
|
|
1541
|
+
declare function primaryColumn(dbColumnName: string, options?: ColumnOptions): ReturnFunctionType$3;
|
|
1542
|
+
//#endregion
|
|
1543
|
+
//#region src/decorators/TableOptions.d.ts
|
|
1544
|
+
interface TableOptions {
|
|
1545
|
+
/**
|
|
1546
|
+
* Table name in the database
|
|
1547
|
+
*/
|
|
1548
|
+
name?: string;
|
|
1549
|
+
/**
|
|
1550
|
+
* Schema table belongs to in the database
|
|
1551
|
+
*/
|
|
1552
|
+
schema?: string;
|
|
1553
|
+
/**
|
|
1554
|
+
* Connection name to use for queries
|
|
1555
|
+
*/
|
|
1556
|
+
connection?: string;
|
|
1557
|
+
/**
|
|
1558
|
+
* Indicates if create, update, delete statements should be available
|
|
1559
|
+
*/
|
|
1560
|
+
readonly?: boolean;
|
|
1561
|
+
}
|
|
1562
|
+
//#endregion
|
|
1563
|
+
//#region src/decorators/table.d.ts
|
|
1564
|
+
type ReturnFunctionType$2 = (object: any) => void;
|
|
1565
|
+
declare function table(options?: TableOptions): ReturnFunctionType$2;
|
|
1566
|
+
declare function table(dbName: string, options: TableOptions): ReturnFunctionType$2;
|
|
1567
|
+
//#endregion
|
|
1568
|
+
//#region src/decorators/updateDateColumn.d.ts
|
|
1569
|
+
type ReturnFunctionType$1 = (object: ClassLike, propertyName: string) => void;
|
|
1570
|
+
declare function updateDateColumn(options?: ColumnTypeOptions): ReturnFunctionType$1;
|
|
1571
|
+
declare function updateDateColumn(dbColumnName: string, options?: ColumnTypeOptions): ReturnFunctionType$1;
|
|
1572
|
+
//#endregion
|
|
1573
|
+
//#region src/decorators/versionColumn.d.ts
|
|
1574
|
+
type ReturnFunctionType = (object: ClassLike, propertyName: string) => void;
|
|
1575
|
+
declare function versionColumn(options?: ColumnTypeOptions): ReturnFunctionType;
|
|
1576
|
+
declare function versionColumn(dbColumnName: string, options?: ColumnTypeOptions): ReturnFunctionType;
|
|
1577
|
+
//#endregion
|
|
1578
|
+
//#region src/errors/QueryError.d.ts
|
|
1579
|
+
declare class QueryError<T extends Entity> extends Error {
|
|
1580
|
+
model: ModelMetadata<T>;
|
|
1581
|
+
where: WhereQuery<T> | undefined;
|
|
1582
|
+
constructor(message: string, model: ModelMetadata<T>, where?: WhereQuery<T>);
|
|
1583
|
+
}
|
|
1584
|
+
//#endregion
|
|
1585
|
+
//#region src/index.d.ts
|
|
1386
1586
|
interface IConnection {
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
}
|
|
1390
|
-
interface OnQueryEvent {
|
|
1391
|
-
sql: string;
|
|
1392
|
-
params: readonly unknown[];
|
|
1393
|
-
duration: number;
|
|
1394
|
-
error?: Error;
|
|
1395
|
-
model: string;
|
|
1396
|
-
operation: 'count' | 'create' | 'destroy' | 'find' | 'findOne' | 'update';
|
|
1397
|
-
}
|
|
1398
|
-
type OnQueryCallback = (event: OnQueryEvent) => void;
|
|
1399
|
-
type AnyModel = TableDefinition<string, any>;
|
|
1400
|
-
/** Infers the repository type for a model, threading the full models map for populate resolution */
|
|
1401
|
-
type InferRepository<TModels extends Record<string, AnyModel>, T extends AnyModel> = T extends TableDefinition<string, infer TSchema> ? T['isReadonly'] extends true ? IReadonlyRepository<InferSelect<TSchema>, TSchema, TModels> : IRepository<InferSelect<TSchema>, TSchema, TModels> : never;
|
|
1402
|
-
/** Maps a named models object to a typed repositories object */
|
|
1403
|
-
type RepositoryMap<TModels extends Record<string, AnyModel>> = {
|
|
1404
|
-
[K in keyof TModels]: InferRepository<TModels, TModels[K]>;
|
|
1405
|
-
};
|
|
1406
|
-
interface InitializeOptionsArray extends IConnection {
|
|
1407
|
-
models: AnyModel[];
|
|
1408
|
-
connections?: Record<string, IConnection>;
|
|
1409
|
-
onQuery?: OnQueryCallback;
|
|
1410
|
-
}
|
|
1411
|
-
interface InitializeOptionsObject<TModels extends Record<string, AnyModel>> extends IConnection {
|
|
1412
|
-
models: TModels;
|
|
1413
|
-
connections?: Record<string, IConnection>;
|
|
1414
|
-
onQuery?: OnQueryCallback;
|
|
1587
|
+
pool: PoolLike;
|
|
1588
|
+
readonlyPool?: PoolLike;
|
|
1415
1589
|
}
|
|
1416
|
-
interface
|
|
1417
|
-
|
|
1418
|
-
|
|
1590
|
+
interface InitializeOptions extends IConnection {
|
|
1591
|
+
models: EntityStatic<Entity>[];
|
|
1592
|
+
connections?: Record<string, IConnection>;
|
|
1593
|
+
expose?: (repository: ReadonlyRepository<Entity> | Repository<Entity>, tableMetadata: ModelMetadata<Entity>) => void;
|
|
1419
1594
|
}
|
|
1420
|
-
type InitializeResultWithRepos<TModels extends Record<string, AnyModel>> = InitializeResult & RepositoryMap<TModels>;
|
|
1421
|
-
/**
|
|
1422
|
-
* Creates a BigAl instance with a named models object.
|
|
1423
|
-
* Returns typed repositories directly: `const { Product, Store } = initialize({ models: { Product, Store }, pool })`.
|
|
1424
|
-
*
|
|
1425
|
-
* @param {InitializeOptionsObject} options - Pool, models object, and optional config
|
|
1426
|
-
*/
|
|
1427
|
-
declare function initialize<TModels extends Record<string, AnyModel>>(options: InitializeOptionsObject<TModels>): InitializeResultWithRepos<TModels>;
|
|
1428
|
-
/**
|
|
1429
|
-
* Creates a BigAl instance with a models array.
|
|
1430
|
-
* Use `getRepository(model)` to obtain typed repositories.
|
|
1431
|
-
*
|
|
1432
|
-
* @param {InitializeOptionsArray} options - Pool, models array, and optional config
|
|
1433
|
-
*/
|
|
1434
|
-
declare function initialize(options: InitializeOptionsArray): InitializeResult;
|
|
1435
|
-
|
|
1436
|
-
declare class QueryError<T extends Record<string, unknown>> extends Error {
|
|
1437
|
-
model: ModelMetadata<T>;
|
|
1438
|
-
where: WhereQuery<T> | undefined;
|
|
1439
|
-
constructor(message: string, model: ModelMetadata<T>, where?: WhereQuery<T>);
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
type SerialConfig = ColumnBuilderConfig<number, true, true, true>;
|
|
1443
|
-
type BigSerialConfig = ColumnBuilderConfig<number, true, true, true>;
|
|
1444
|
-
type IntegerConfig = ColumnBuilderConfig<number>;
|
|
1445
|
-
type BigIntConfig = ColumnBuilderConfig<number>;
|
|
1446
|
-
type SmallIntConfig = ColumnBuilderConfig<number>;
|
|
1447
|
-
type RealConfig = ColumnBuilderConfig<number>;
|
|
1448
|
-
type DoublePrecisionConfig = ColumnBuilderConfig<number>;
|
|
1449
|
-
type BooleanColumnConfig = ColumnBuilderConfig<boolean>;
|
|
1450
|
-
type TimestampConfig = ColumnBuilderConfig<Date>;
|
|
1451
|
-
type TimestampTzConfig = ColumnBuilderConfig<Date>;
|
|
1452
|
-
type DateColumnConfig = ColumnBuilderConfig<Date>;
|
|
1453
|
-
type UuidConfig = ColumnBuilderConfig<string>;
|
|
1454
|
-
type ByteaConfig = ColumnBuilderConfig<Buffer>;
|
|
1455
|
-
type TextArrayConfig = ColumnBuilderConfig<string[]>;
|
|
1456
|
-
type IntegerArrayConfig = ColumnBuilderConfig<number[]>;
|
|
1457
|
-
type BooleanArrayConfig = ColumnBuilderConfig<boolean[]>;
|
|
1458
|
-
type CreatedAtConfig = ColumnBuilderConfig<Date, true, true, false, true>;
|
|
1459
|
-
type UpdatedAtConfig = ColumnBuilderConfig<Date, true, true, false, true>;
|
|
1460
|
-
interface ColumnOptions {
|
|
1461
|
-
name?: string;
|
|
1462
|
-
}
|
|
1463
|
-
interface VarcharOptions extends ColumnOptions {
|
|
1464
|
-
length?: number;
|
|
1465
|
-
}
|
|
1466
|
-
declare function serial(options?: ColumnOptions): ColumnBuilder<SerialConfig>;
|
|
1467
|
-
declare function bigserial(options?: ColumnOptions): ColumnBuilder<BigSerialConfig>;
|
|
1468
|
-
declare function text<T extends string = string>(options?: ColumnOptions): ColumnBuilder<ColumnBuilderConfig<T>>;
|
|
1469
|
-
declare function varchar<T extends string = string>(options?: VarcharOptions): ColumnBuilder<ColumnBuilderConfig<T>>;
|
|
1470
|
-
declare function integer(options?: ColumnOptions): ColumnBuilder<IntegerConfig>;
|
|
1471
|
-
declare function bigint(options?: ColumnOptions): ColumnBuilder<BigIntConfig>;
|
|
1472
|
-
declare function smallint(options?: ColumnOptions): ColumnBuilder<SmallIntConfig>;
|
|
1473
|
-
declare function real(options?: ColumnOptions): ColumnBuilder<RealConfig>;
|
|
1474
|
-
/** Alias for `real()`. Maps to PostgreSQL REAL (single-precision floating point). */
|
|
1475
|
-
declare const float: typeof real;
|
|
1476
|
-
declare function double(options?: ColumnOptions): ColumnBuilder<DoublePrecisionConfig>;
|
|
1477
|
-
declare function booleanColumn(options?: ColumnOptions): ColumnBuilder<BooleanColumnConfig>;
|
|
1478
|
-
declare function timestamp(options?: ColumnOptions): ColumnBuilder<TimestampConfig>;
|
|
1479
|
-
declare function timestamptz(options?: ColumnOptions): ColumnBuilder<TimestampTzConfig>;
|
|
1480
|
-
declare function dateColumn(options?: ColumnOptions): ColumnBuilder<DateColumnConfig>;
|
|
1481
|
-
declare function json<T = Record<string, unknown>>(options?: ColumnOptions): ColumnBuilder<ColumnBuilderConfig<T>>;
|
|
1482
|
-
declare function jsonb<T = Record<string, unknown>>(options?: ColumnOptions): ColumnBuilder<ColumnBuilderConfig<T>>;
|
|
1483
|
-
declare function uuid(options?: ColumnOptions): ColumnBuilder<UuidConfig>;
|
|
1484
|
-
declare function bytea(options?: ColumnOptions): ColumnBuilder<ByteaConfig>;
|
|
1485
|
-
declare function textArray(options?: ColumnOptions): ColumnBuilder<TextArrayConfig>;
|
|
1486
|
-
declare function integerArray(options?: ColumnOptions): ColumnBuilder<IntegerArrayConfig>;
|
|
1487
|
-
declare function booleanArray(options?: ColumnOptions): ColumnBuilder<BooleanArrayConfig>;
|
|
1488
|
-
declare function createdAt(options?: ColumnOptions): ColumnBuilder<CreatedAtConfig>;
|
|
1489
|
-
declare function updatedAt(options?: ColumnOptions): ColumnBuilder<UpdatedAtConfig>;
|
|
1490
|
-
interface VectorOptions extends ColumnOptions {
|
|
1491
|
-
dimensions: number;
|
|
1492
|
-
}
|
|
1493
|
-
type VectorConfig = ColumnBuilderConfig<number[]>;
|
|
1494
|
-
declare function vector(options: VectorOptions): ColumnBuilder<VectorConfig>;
|
|
1495
|
-
|
|
1496
|
-
type AnyTableDef = TableDefinition<string, any>;
|
|
1497
|
-
/**
|
|
1498
|
-
* A typed read-write repository for a model. Provides find, findOne, create,
|
|
1499
|
-
* update, destroy, and populate operations with full type safety.
|
|
1500
|
-
*
|
|
1501
|
-
* @example
|
|
1502
|
-
* ```typescript
|
|
1503
|
-
* import type { Repository } from 'bigal';
|
|
1504
|
-
*
|
|
1505
|
-
* function processProducts(repo: Repository<typeof Product>) {
|
|
1506
|
-
* const products = await repo.find().where({ name: 'Widget' });
|
|
1507
|
-
* }
|
|
1508
|
-
* ```
|
|
1509
|
-
*/
|
|
1510
|
-
type Repository<T extends AnyTableDef> = T extends TableDefinition<string, infer TSchema> ? IRepository<InferSelect<TSchema>, TSchema> : never;
|
|
1511
1595
|
/**
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1596
|
+
* Initializes BigAl
|
|
1597
|
+
* @param {object[]} models - Model classes - used to force decorator evaluation for all models
|
|
1598
|
+
* @param {object[]} modelSchemas - Model definitions
|
|
1599
|
+
* @param {object} pool - Postgres Pool
|
|
1600
|
+
* @param {object} [readonlyPool] - Postgres Pool for `find` and `findOne` operations. If not defined, `pool` will be used
|
|
1601
|
+
* @param {object} [connections] - Key: name of the connection; Value: { pool, readonlyPool }
|
|
1602
|
+
* @param {Function} [expose] - Used to expose model classes
|
|
1603
|
+
* @returns {object} Repositories by model name
|
|
1604
|
+
*/
|
|
1605
|
+
declare function initialize({
|
|
1606
|
+
models,
|
|
1607
|
+
pool,
|
|
1608
|
+
readonlyPool,
|
|
1609
|
+
connections,
|
|
1610
|
+
expose
|
|
1611
|
+
}: InitializeOptions): Record<string, IReadonlyRepository<Entity> | IRepository<Entity>>;
|
|
1612
|
+
//#endregion
|
|
1613
|
+
export { type AggregateBuilder, type AggregateCallback, AnyJoinInfo, ClassLike, ColumnBaseMetadata, ColumnBaseMetadataOptions, ColumnCollectionMetadata, ColumnCollectionMetadataOptions, ColumnMetadata, ColumnModelMetadata, ColumnModelMetadataOptions, ColumnModifierMetadata, ColumnTypeMetadata, ColumnTypeMetadataOptions, Comparer, CountResult, CreateResult, CreateResultArray, CreateResultArrayJSON, CreateResultJSON, CreateUpdateOptions, CreateUpdateParams, DeleteOptions, DestroyResult, DestroyResultJSON, DestroyResultWithRecords, DoNotReturnRecords, Entity, EntityFieldValue, EntityPrimitiveOrId, EntityStatic, ExcludeEntityCollections, ExcludeFunctions, FindArgs, FindOneArgs, FindOneResult, FindOneResultJSON, FindQueryWithCount, FindQueryWithCountJSON, FindResult, FindResultJSON, FindWithCountResult, GetValueType, type HavingComparer, type HavingCondition, IConnection, IReadonlyRepository, IRepository, IRepositoryOptions, IncludeFunctions, InitializeOptions, IsValueOfType, JoinDefinition, JoinInfo, JoinType, JoinedSort, JoinedWhereQuery, JsonConstraint, JsonPropertyConstraint, JsonPropertyValue, LiteralValues, ModelJoinDefinition, ModelMetadata, ModelMetadataOptions, ModelRelationshipKeys, MultipleSortString, NegatableConstraint, NotEntity, NotEntityBrand, NumberOrDateConstraint, NumberOrDateConstraintWithSubquery, OmitEntityCollections, OmitFunctions, OrderBy, PaginateOptions, PickAsType, PickByValueType, PickFunctions, PlainObject, PoolLike, PoolQueryResult, PopulateArgs, Populated, QueryError, QueryResult, QueryResultOptionalPopulated, QueryResultPopulated, QueryResultRow, ReadonlyRepository, Repository, ReturnSelect, ScalarSubquery, ScalarSubqueryConstraint, type SelectAggregateExpression, SelectBuilder, type SelectItem, Sort, SortObject, SortObjectValue, SortString, StringConstraint, SubqueryBuilder, type SubqueryBuilderLike, SubqueryInConstraint, SubqueryJoinDefinition, SubqueryJoinInfo, SubqueryJoinOnCondition, ThroughArgs, type TypedAggregateExpression, type TypedSelectItem, type TypedSubqueryBuilder, UpdateResult, UpdateResultJSON, VectorDistanceConstraint, VectorDistanceMetric, VectorDistanceSort, WhereClauseValue, WhereQuery, WhereQueryStatement, column, createDateColumn, getMetadataStorage, initialize, isSubqueryJoin, primaryColumn, subquery, table, updateDateColumn, versionColumn };
|