@@ -49,11 +49,14 @@ export type LogLevel =
49
49
50
50
export function setLogLevel ( logLevel : LogLevel ) : void ;
51
51
52
- export interface FirestoreDataConverter < T > {
53
- toFirestore ( modelObject : T ) : DocumentData ;
54
- toFirestore ( modelObject : Partial < T > , options : SetOptions ) : DocumentData ;
55
-
56
- fromFirestore ( snapshot : QueryDocumentSnapshot , options : SnapshotOptions ) : T ;
52
+ export interface FirestoreDataConverter <
53
+ AppModelType ,
54
+ DbModelType extends DocumentData = DocumentData
55
+ > {
56
+ toFirestore ( modelObject : AppModelType ) : DocumentData ;
57
+ toFirestore ( modelObject : Partial < AppModelType > , options : SetOptions ) : DocumentData ;
58
+
59
+ fromFirestore ( snapshot : QueryDocumentSnapshot < AppModelType , DbModelType > , options : SnapshotOptions ) : AppModelType ;
57
60
}
58
61
59
62
export class FirebaseFirestore {
@@ -73,7 +76,7 @@ export class FirebaseFirestore {
73
76
74
77
collection ( collectionPath : string ) : CollectionReference < DocumentData > ;
75
78
76
- doc ( documentPath : string ) : DocumentReference < DocumentData > ;
79
+ doc ( documentPath : string ) : DocumentReference < DocumentData , DocumentData > ;
77
80
78
81
collectionGroup ( collectionId : string ) : Query < DocumentData > ;
79
82
@@ -185,14 +188,14 @@ export class Blob {
185
188
export class Transaction {
186
189
private constructor ( ) ;
187
190
188
- get < T > ( documentRef : DocumentReference < T > ) : Promise < DocumentSnapshot < T > > ;
191
+ get < T > ( documentRef : DocumentReference < AppModelType , DbModelType > ) : Promise < DocumentSnapshot < AppModelType , DbModelType > > ;
189
192
190
193
set < T > (
191
- documentRef : DocumentReference < T > ,
194
+ documentRef : DocumentReference < AppModelType , DbModelType > ,
192
195
data : Partial < T > ,
193
196
options : SetOptions
194
197
) : Transaction ;
195
- set < T > ( documentRef : DocumentReference < T > , data : T ) : Transaction ;
198
+ set < T > ( documentRef : DocumentReference < AppModelType , DbModelType > , data : T ) : Transaction ;
196
199
197
200
update ( documentRef : DocumentReference < any > , data : UpdateData ) : Transaction ;
198
201
update (
@@ -209,11 +212,11 @@ export class WriteBatch {
209
212
private constructor ( ) ;
210
213
211
214
set < T > (
212
- documentRef : DocumentReference < T > ,
215
+ documentRef : DocumentReference < AppModelType , DbModelType > ,
213
216
data : Partial < T > ,
214
217
options : SetOptions
215
218
) : WriteBatch ;
216
- set < T > ( documentRef : DocumentReference < T > , data : T ) : WriteBatch ;
219
+ set < T > ( documentRef : DocumentReference < AppModelType , DbModelType > , data : T ) : WriteBatch ;
217
220
218
221
update ( documentRef : DocumentReference < any > , data : UpdateData ) : WriteBatch ;
219
222
update (
@@ -241,17 +244,17 @@ export interface GetOptions {
241
244
readonly source ?: 'default' | 'server' | 'cache' ;
242
245
}
243
246
244
- export class DocumentReference < T = DocumentData > {
247
+ export class DocumentReference < AppModelType , DbModelType > {
245
248
private constructor ( ) ;
246
249
247
250
readonly id : string ;
248
251
readonly firestore : FirebaseFirestore ;
249
- readonly parent : CollectionReference < T > ;
252
+ readonly parent : CollectionReference < AppModelType , DbModelType > ;
250
253
readonly path : string ;
251
254
252
255
collection ( collectionPath : string ) : CollectionReference < DocumentData > ;
253
256
254
- isEqual ( other : DocumentReference < T > ) : boolean ;
257
+ isEqual ( other : DocumentReference < AppModelType , DbModelType > ) : boolean ;
255
258
256
259
set ( data : Partial < T > , options : SetOptions ) : Promise < void > ;
257
260
set ( data : T ) : Promise < void > ;
@@ -265,29 +268,29 @@ export class DocumentReference<T = DocumentData> {
265
268
266
269
delete ( ) : Promise < void > ;
267
270
268
- get ( options ?: GetOptions ) : Promise < DocumentSnapshot < T > > ;
271
+ get ( options ?: GetOptions ) : Promise < DocumentSnapshot < AppModelType , DbModelType > > ;
269
272
270
273
onSnapshot ( observer : {
271
- next ?: ( snapshot : DocumentSnapshot < T > ) => void ;
274
+ next ?: ( snapshot : DocumentSnapshot < AppModelType , DbModelType > ) => void ;
272
275
error ?: ( error : FirestoreError ) => void ;
273
276
complete ?: ( ) => void ;
274
277
} ) : ( ) => void ;
275
278
onSnapshot (
276
279
options : SnapshotListenOptions ,
277
280
observer : {
278
- next ?: ( snapshot : DocumentSnapshot < T > ) => void ;
281
+ next ?: ( snapshot : DocumentSnapshot < AppModelType , DbModelType > ) => void ;
279
282
error ?: ( error : FirestoreError ) => void ;
280
283
complete ?: ( ) => void ;
281
284
}
282
285
) : ( ) => void ;
283
286
onSnapshot (
284
- onNext : ( snapshot : DocumentSnapshot < T > ) => void ,
287
+ onNext : ( snapshot : DocumentSnapshot < AppModelType , DbModelType > ) => void ,
285
288
onError ?: ( error : FirestoreError ) => void ,
286
289
onCompletion ?: ( ) => void
287
290
) : ( ) => void ;
288
291
onSnapshot (
289
292
options : SnapshotListenOptions ,
290
- onNext : ( snapshot : DocumentSnapshot < T > ) => void ,
293
+ onNext : ( snapshot : DocumentSnapshot < AppModelType , DbModelType > ) => void ,
291
294
onError ?: ( error : FirestoreError ) => void ,
292
295
onCompletion ?: ( ) => void
293
296
) : ( ) => void ;
@@ -307,24 +310,23 @@ export interface SnapshotMetadata {
307
310
isEqual ( other : SnapshotMetadata ) : boolean ;
308
311
}
309
312
310
- export class DocumentSnapshot < T = DocumentData > {
313
+ export class DocumentSnapshot < AppModelType , DbModelType > {
311
314
protected constructor ( ) ;
312
315
313
316
readonly exists : boolean ;
314
- readonly ref : DocumentReference < T > ;
317
+ readonly ref : DocumentReference < AppModelType , DbModelType > ;
315
318
readonly id : string ;
316
319
readonly metadata : SnapshotMetadata ;
317
320
318
321
data ( options ?: SnapshotOptions ) : T | undefined ;
319
322
320
323
get ( fieldPath : string | FieldPath , options ?: SnapshotOptions ) : any ;
321
324
322
- isEqual ( other : DocumentSnapshot < T > ) : boolean ;
325
+ isEqual ( other : DocumentSnapshot < AppModelType , DbModelType > ) : boolean ;
323
326
}
324
327
325
- export class QueryDocumentSnapshot <
326
- T = DocumentData
327
- > extends DocumentSnapshot < T > {
328
+ export class QueryDocumentSnapshot < AppModelType , DbModelType >
329
+ extends DocumentSnapshot < AppModelType , DbModelType > {
328
330
private constructor ( ) ;
329
331
330
332
data ( options ?: SnapshotOptions ) : T ;
@@ -344,7 +346,7 @@ export type WhereFilterOp =
344
346
| 'array-contains-any'
345
347
| 'not-in' ;
346
348
347
- export class Query < T = DocumentData > {
349
+ export class Query < AppModelType = DocumentData , DbModelType extends DocumentData = DocumentData > {
348
350
protected constructor ( ) ;
349
351
350
352
readonly firestore : FirebaseFirestore ;
@@ -353,54 +355,54 @@ export class Query<T = DocumentData> {
353
355
fieldPath : string | FieldPath ,
354
356
opStr : WhereFilterOp ,
355
357
value : any
356
- ) : Query < T > ;
358
+ ) : Query < AppModelType , DbModelType > ;
357
359
358
360
orderBy (
359
361
fieldPath : string | FieldPath ,
360
362
directionStr ?: OrderByDirection
361
- ) : Query < T > ;
363
+ ) : Query < AppModelType , DbModelType > ;
362
364
363
- limit ( limit : number ) : Query < T > ;
365
+ limit ( limit : number ) : Query < AppModelType , DbModelType > ;
364
366
365
- limitToLast ( limit : number ) : Query < T > ;
367
+ limitToLast ( limit : number ) : Query < AppModelType , DbModelType > ;
366
368
367
- startAt ( snapshot : DocumentSnapshot < any > ) : Query < T > ;
368
- startAt ( ...fieldValues : any [ ] ) : Query < T > ;
369
+ startAt ( snapshot : DocumentSnapshot < AppModelType , DbModelType > ) : Query < AppModelType , DbModelType > ;
370
+ startAt ( ...fieldValues : any [ ] ) : Query < AppModelType , DbModelType > ;
369
371
370
- startAfter ( snapshot : DocumentSnapshot < any > ) : Query < T > ;
371
- startAfter ( ...fieldValues : any [ ] ) : Query < T > ;
372
+ startAfter ( snapshot : DocumentSnapshot < AppModelType , DbModelType > ) : Query < AppModelType , DbModelType > ;
373
+ startAfter ( ...fieldValues : any [ ] ) : Query < AppModelType , DbModelType > ;
372
374
373
- endBefore ( snapshot : DocumentSnapshot < any > ) : Query < T > ;
374
- endBefore ( ...fieldValues : any [ ] ) : Query < T > ;
375
+ endBefore ( snapshot : DocumentSnapshot < AppModelType , DbModelType > ) : Query < AppModelType , DbModelType > ;
376
+ endBefore ( ...fieldValues : any [ ] ) : Query < AppModelType , DbModelType > ;
375
377
376
- endAt ( snapshot : DocumentSnapshot < any > ) : Query < T > ;
377
- endAt ( ...fieldValues : any [ ] ) : Query < T > ;
378
+ endAt ( snapshot : DocumentSnapshot < AppModelType , DbModelType > ) : Query < AppModelType , DbModelType > ;
379
+ endAt ( ...fieldValues : any [ ] ) : Query < AppModelType , DbModelType > ;
378
380
379
- isEqual ( other : Query < T > ) : boolean ;
381
+ isEqual ( other : Query < AppModelType , DbModelType > ) : boolean ;
380
382
381
- get ( options ?: GetOptions ) : Promise < QuerySnapshot < T > > ;
383
+ get ( options ?: GetOptions ) : Promise < QuerySnapshot < AppModelType , DbModelType > > ;
382
384
383
385
onSnapshot ( observer : {
384
- next ?: ( snapshot : QuerySnapshot < T > ) => void ;
386
+ next ?: ( snapshot : QuerySnapshot < AppModelType , DbModelType > ) => void ;
385
387
error ?: ( error : FirestoreError ) => void ;
386
388
complete ?: ( ) => void ;
387
389
} ) : ( ) => void ;
388
390
onSnapshot (
389
391
options : SnapshotListenOptions ,
390
392
observer : {
391
- next ?: ( snapshot : QuerySnapshot < T > ) => void ;
393
+ next ?: ( snapshot : QuerySnapshot < AppModelType , DbModelType > ) => void ;
392
394
error ?: ( error : FirestoreError ) => void ;
393
395
complete ?: ( ) => void ;
394
396
}
395
397
) : ( ) => void ;
396
398
onSnapshot (
397
- onNext : ( snapshot : QuerySnapshot < T > ) => void ,
399
+ onNext : ( snapshot : QuerySnapshot < AppModelType , DbModelType > ) => void ,
398
400
onError ?: ( error : FirestoreError ) => void ,
399
401
onCompletion ?: ( ) => void
400
402
) : ( ) => void ;
401
403
onSnapshot (
402
404
options : SnapshotListenOptions ,
403
- onNext : ( snapshot : QuerySnapshot < T > ) => void ,
405
+ onNext : ( snapshot : QuerySnapshot < AppModelType , DbModelType > ) => void ,
404
406
onError ?: ( error : FirestoreError ) => void ,
405
407
onCompletion ?: ( ) => void
406
408
) : ( ) => void ;
@@ -409,44 +411,44 @@ export class Query<T = DocumentData> {
409
411
withConverter < U > ( converter : FirestoreDataConverter < U > ) : Query < U > ;
410
412
}
411
413
412
- export class QuerySnapshot < T = DocumentData > {
414
+ export class QuerySnapshot < AppModelType , DbModelType > {
413
415
private constructor ( ) ;
414
416
415
- readonly query : Query < T > ;
417
+ readonly query : Query < AppModelType , DbModelType > ;
416
418
readonly metadata : SnapshotMetadata ;
417
- readonly docs : Array < QueryDocumentSnapshot < T > > ;
419
+ readonly docs : Array < QueryDocumentSnapshot < AppModelType , DbModelType > > ;
418
420
readonly size : number ;
419
421
readonly empty : boolean ;
420
422
421
423
docChanges ( options ?: SnapshotListenOptions ) : Array < DocumentChange < T > > ;
422
424
423
425
forEach (
424
- callback : ( result : QueryDocumentSnapshot < T > ) => void ,
426
+ callback : ( result : QueryDocumentSnapshot < AppModelType , DbModelType > ) => void ,
425
427
thisArg ?: any
426
428
) : void ;
427
429
428
- isEqual ( other : QuerySnapshot < T > ) : boolean ;
430
+ isEqual ( other : QuerySnapshot < AppModelType , DbModelType > ) : boolean ;
429
431
}
430
432
431
433
export type DocumentChangeType = 'added' | 'removed' | 'modified' ;
432
434
433
- export interface DocumentChange < T = DocumentData > {
435
+ export interface DocumentChange < AppModelType , DbModelType > {
434
436
readonly type : DocumentChangeType ;
435
- readonly doc : QueryDocumentSnapshot < T > ;
437
+ readonly doc : QueryDocumentSnapshot < AppModelType , DbModelType > ;
436
438
readonly oldIndex : number ;
437
439
readonly newIndex : number ;
438
440
}
439
441
440
- export class CollectionReference < T = DocumentData > extends Query < T > {
442
+ export class CollectionReference < AppModelType = DocumentData , DbModelType extends DocumentData = DocumentData > extends Query < AppModelType , DbModelType > {
441
443
private constructor ( ) ;
442
444
443
445
readonly id : string ;
444
- readonly parent : DocumentReference < DocumentData > | null ;
446
+ readonly parent : DocumentReference < AppModelType , DbModelType > | null ;
445
447
readonly path : string ;
446
448
447
- doc ( documentPath ?: string ) : DocumentReference < T > ;
449
+ doc ( documentPath ?: string ) : DocumentReference < AppModelType , DbModelType > ;
448
450
449
- add ( data : T ) : Promise < DocumentReference < T > > ;
451
+ add ( data : T ) : Promise < DocumentReference < AppModelType , DbModelType > > ;
450
452
451
453
isEqual ( other : CollectionReference < T > ) : boolean ;
452
454
0 commit comments