@@ -24,6 +24,18 @@ import {ICountOptions} from '../interfaces/ICountOptions';
24
24
type ForTypeOf < T > = { [ P in keyof T ] : T [ P ] } ;
25
25
type NonAbstractTypeOfModel < T > = ( new ( ) => T ) & ForTypeOf < typeof Model > ;
26
26
27
+ type Diff < T extends string , U extends string > = ( { [ P in T ] : P } & { [ P in U ] : never } & { [ x : string ] : never } ) [ T ] ;
28
+ type Omit < T , K extends keyof T > = { [ P in Diff < keyof T , K > ] : T [ P ] } ;
29
+
30
+ type GetAttributes < T extends Model < T > > =
31
+ Partial < Omit < T , keyof Model < any > > > | {
32
+ id ?: number | any ;
33
+ createdAt ?: Date | any ;
34
+ updatedAt ?: Date | any ;
35
+ deletedAt ?: Date | any ;
36
+ version ?: number | any ;
37
+ } ;
38
+
27
39
export declare abstract class Model < T > extends Hooks {
28
40
29
41
constructor ( values ?: any , options ?: IBuildOptions ) ;
@@ -293,29 +305,29 @@ export declare abstract class Model<T> extends Hooks {
293
305
/**
294
306
* Builds a new model instance. Values is an object of key value pairs, must be defined but can be empty.
295
307
*/
296
- static build < T extends Model < T > > ( this : ( new ( ) => T ) , record ?: any , options ?: IBuildOptions ) : T ;
308
+ static build < T extends Model < T > > ( this : ( new ( ) => T ) , record ?: GetAttributes < T > , options ?: IBuildOptions ) : T ;
297
309
static build < T extends Model < T > , A > ( this : ( new ( ) => T ) , record ?: A , options ?: IBuildOptions ) : T ;
298
310
299
311
/**
300
312
* Undocumented bulkBuild
301
313
*/
302
- static bulkBuild < T extends Model < T > > ( this : ( new ( ) => T ) , records : any [ ] , options ?: IBuildOptions ) : T [ ] ;
314
+ static bulkBuild < T extends Model < T > > ( this : ( new ( ) => T ) , records : GetAttributes < T > [ ] , options ?: IBuildOptions ) : T [ ] ;
303
315
static bulkBuild < T extends Model < T > , A > ( this : ( new ( ) => T ) , records : A [ ] , options ?: IBuildOptions ) : T [ ] ;
304
316
305
317
/**
306
318
* Builds a new model instance and calls save on it.
307
319
*/
308
- static create < T extends Model < T > > ( this : ( new ( ) => T ) , values ?: any , options ?: ICreateOptions ) : Promise < T > ;
320
+ static create < T extends Model < T > > ( this : ( new ( ) => T ) , values ?: GetAttributes < T > , options ?: ICreateOptions ) : Promise < T > ;
309
321
static create < T extends Model < T > , A > ( this : ( new ( ) => T ) , values ?: A , options ?: ICreateOptions ) : Promise < T > ;
310
322
311
323
/**
312
324
* Find a row that matches the query, or build (but don't save) the row if none is found.
313
325
* The successfull result of the promise will be (instance, initialized) - Make sure to use .spread()
314
326
*/
315
- static findOrInitialize < T extends Model < T > > ( this : ( new ( ) => T ) , options : IFindOrInitializeOptions < any > ) : Promise < [ T , boolean ] > ;
327
+ static findOrInitialize < T extends Model < T > > ( this : ( new ( ) => T ) , options : IFindOrInitializeOptions < GetAttributes < T > > ) : Promise < [ T , boolean ] > ;
316
328
static findOrInitialize < T extends Model < T > , A > ( this : ( new ( ) => T ) , options : IFindOrInitializeOptions < A > ) : Promise < [ T , boolean ] > ;
317
329
318
- static findOrBuild < T extends Model < T > > ( this : ( new ( ) => T ) , options : IFindOrInitializeOptions < any > ) : Promise < [ T , boolean ] > ;
330
+ static findOrBuild < T extends Model < T > > ( this : ( new ( ) => T ) , options : IFindOrInitializeOptions < GetAttributes < T > > ) : Promise < [ T , boolean ] > ;
319
331
static findOrBuild < T extends Model < T > , A > ( this : ( new ( ) => T ) , options : IFindOrInitializeOptions < A > ) : Promise < [ T , boolean ] > ;
320
332
321
333
/**
@@ -329,14 +341,14 @@ export declare abstract class Model<T> extends Hooks {
329
341
* an instance of sequelize.TimeoutError will be thrown instead. If a transaction is created, a savepoint
330
342
* will be created instead, and any unique constraint violation will be handled internally.
331
343
*/
332
- static findOrCreate < T extends Model < T > > ( this : ( new ( ) => T ) , options : IFindOrInitializeOptions < any > ) : Promise < [ T , boolean ] > ;
344
+ static findOrCreate < T extends Model < T > > ( this : ( new ( ) => T ) , options : IFindOrInitializeOptions < GetAttributes < T > > ) : Promise < [ T , boolean ] > ;
333
345
static findOrCreate < T extends Model < T > , A > ( this : ( new ( ) => T ) , options : IFindOrInitializeOptions < A > ) : Promise < [ T , boolean ] > ;
334
346
335
347
/**
336
348
* A more performant findOrCreate that will not work under a transaction (at least not in postgres)
337
349
* Will execute a find call, if empty then attempt to create, if unique constraint then attempt to find again
338
350
*/
339
- static findCreateFind < T extends Model < T > > ( this : ( new ( ) => T ) , options : IFindCreateFindOptions < any > ) : Promise < [ T , boolean ] > ;
351
+ static findCreateFind < T extends Model < T > > ( this : ( new ( ) => T ) , options : IFindCreateFindOptions < GetAttributes < T > > ) : Promise < [ T , boolean ] > ;
340
352
static findCreateFind < T extends Model < T > , A > ( this : ( new ( ) => T ) , options : IFindCreateFindOptions < A > ) : Promise < [ T , boolean ] > ;
341
353
342
354
/**
@@ -373,7 +385,7 @@ export declare abstract class Model<T> extends Hooks {
373
385
*
374
386
* @param records List of objects (key/value pairs) to create instances from
375
387
*/
376
- static bulkCreate < T extends Model < T > > ( this : ( new ( ) => T ) , records : any [ ] , options ?: BulkCreateOptions ) : Promise < T [ ] > ;
388
+ static bulkCreate < T extends Model < T > > ( this : ( new ( ) => T ) , records : GetAttributes < T > [ ] , options ?: BulkCreateOptions ) : Promise < T [ ] > ;
377
389
static bulkCreate < T extends Model < T > , A > ( this : ( new ( ) => T ) , records : A [ ] , options ?: BulkCreateOptions ) : Promise < T [ ] > ;
378
390
379
391
/**
@@ -398,7 +410,7 @@ export declare abstract class Model<T> extends Hooks {
398
410
* elements. The first element is always the number of affected rows, while the second element is the actual
399
411
* affected rows (only supported in postgres with `options.returning` true.)
400
412
*/
401
- static update < T extends Model < T > > ( this : ( new ( ) => T ) , values : any , options : UpdateOptions ) : Promise < [ number , Array < T > ] > ;
413
+ static update < T extends Model < T > > ( this : ( new ( ) => T ) , values : GetAttributes < T > , options : UpdateOptions ) : Promise < [ number , Array < T > ] > ;
402
414
static update < T extends Model < T > , A > ( this : ( new ( ) => T ) , values : A , options : UpdateOptions ) : Promise < [ number , Array < T > ] > ;
403
415
/**
404
416
* Run a describe query on the table. The result will be return to the listener as a hash of attributes and
0 commit comments