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