1
- import { getOwner } from '@ember/application ' ;
1
+ import { getOwner } from '@ember/owner ' ;
2
2
import { service } from '@ember/service' ;
3
3
import Adapter from '@ember-data/adapter' ;
4
- import type DS from 'ember-data' ;
5
- import { type ModelSchema } from 'ember-data' ;
6
- import type ModelRegistry from 'ember-data/types/registries/model' ;
4
+ import type { ModelSchema } from '@ember-data/store/types' ;
5
+ import type { AdapterPayload } from '@ember-data/legacy-compat' ;
6
+ import type { Snapshot as _Snapshot } from '@ember-data/legacy-compat/legacy-network-handler/snapshot' ;
7
+ import type { SnapshotRecordArray as _SnapshotRecordArray } from '@ember-data/legacy-compat/-private' ;
8
+ import type { Collection } from '@ember-data/store/-private/record-arrays/identifier-array' ;
9
+ import type {
10
+ LegacyBelongsToField ,
11
+ LegacyHasManyField ,
12
+ } from '@warp-drive/core-types/schema/fields' ;
13
+ import type Model from 'ember-data/model' ;
7
14
import RSVP from 'rsvp' ;
8
15
import type Store from '@ember-data/store' ;
9
16
@@ -41,30 +48,27 @@ export interface AdapterOption {
41
48
[ key : string ] : unknown ;
42
49
}
43
50
44
- interface Snapshot extends DS . Snapshot {
51
+ interface Snapshot extends _Snapshot {
45
52
adapterOptions : AdapterOption ;
46
53
}
47
54
48
- interface SnapshotRecordArray
49
- extends DS . SnapshotRecordArray < keyof ModelRegistry > {
55
+ interface SnapshotRecordArray extends _SnapshotRecordArray {
50
56
adapterOptions : AdapterOption ;
51
57
}
52
58
53
- interface BelongsToRelationshipMeta {
54
- type : keyof ModelRegistry ;
59
+ type BelongsToRelationshipMeta = LegacyBelongsToField & {
55
60
options : { isRealtime ?: boolean } ;
56
- }
61
+ } ;
57
62
58
- interface HasManyRelationshipMeta {
63
+ type HasManyRelationshipMeta = LegacyHasManyField & {
59
64
key : string ;
60
- type : string ;
61
65
options : {
62
66
isRealtime ?: boolean ;
63
67
64
68
buildReference ?( db : Firestore , record : unknown ) : CollectionReference ;
65
69
filter ?( db : CollectionReference | Query , record : unknown ) : Query ;
66
70
} ;
67
- }
71
+ } ;
68
72
69
73
export default class CloudFirestoreAdapter extends Adapter {
70
74
@service ( '-firestore-data-manager' )
@@ -73,9 +77,9 @@ export default class CloudFirestoreAdapter extends Adapter {
73
77
protected referenceKeyName = 'referenceTo' ;
74
78
75
79
protected get isFastBoot ( ) : boolean {
76
- const fastboot = getOwner ( this ) . lookup ( 'service:fastboot' ) ;
80
+ const fastboot = getOwner ( this ) ? .lookup ( 'service:fastboot' ) ;
77
81
78
- return fastboot && fastboot . isFastBoot ;
82
+ return ! ! fastboot && fastboot . isFastBoot ;
79
83
}
80
84
81
85
public generateIdForRecord ( _store : Store , type : unknown ) : string {
@@ -89,21 +93,21 @@ export default class CloudFirestoreAdapter extends Adapter {
89
93
store : Store ,
90
94
type : ModelSchema ,
91
95
snapshot : Snapshot ,
92
- ) : RSVP . Promise < unknown > {
96
+ ) : Promise < AdapterPayload > {
93
97
return this . updateRecord ( store , type , snapshot ) ;
94
98
}
95
99
96
100
public updateRecord (
97
101
_store : Store ,
98
102
type : ModelSchema ,
99
103
snapshot : Snapshot ,
100
- ) : RSVP . Promise < unknown > {
104
+ ) : Promise < AdapterPayload > {
101
105
return new RSVP . Promise ( ( resolve , reject ) => {
102
106
const collectionRef = this . buildCollectionRef (
103
107
type . modelName ,
104
108
snapshot . adapterOptions ,
105
109
) ;
106
- const docRef = doc ( collectionRef , snapshot . id ) ;
110
+ const docRef = doc ( collectionRef , snapshot . id ! ) ;
107
111
const batch = this . buildWriteBatch ( docRef , snapshot ) ;
108
112
109
113
batch
@@ -131,14 +135,14 @@ export default class CloudFirestoreAdapter extends Adapter {
131
135
_store : Store ,
132
136
type : ModelSchema ,
133
137
snapshot : Snapshot ,
134
- ) : RSVP . Promise < unknown > {
138
+ ) : Promise < AdapterPayload > {
135
139
return new RSVP . Promise ( ( resolve , reject ) => {
136
140
const db = getFirestore ( ) ;
137
141
const collectionRef = this . buildCollectionRef (
138
142
type . modelName ,
139
143
snapshot . adapterOptions ,
140
144
) ;
141
- const docRef = doc ( collectionRef , snapshot . id ) ;
145
+ const docRef = doc ( collectionRef , snapshot . id ! ) ;
142
146
const batch = writeBatch ( db ) ;
143
147
144
148
batch . delete ( docRef ) ;
@@ -160,7 +164,7 @@ export default class CloudFirestoreAdapter extends Adapter {
160
164
type : ModelSchema ,
161
165
id : string ,
162
166
snapshot : Snapshot ,
163
- ) : RSVP . Promise < unknown > {
167
+ ) : Promise < AdapterPayload > {
164
168
return new RSVP . Promise ( async ( resolve , reject ) => {
165
169
try {
166
170
const colRef = this . buildCollectionRef (
@@ -194,9 +198,9 @@ export default class CloudFirestoreAdapter extends Adapter {
194
198
public findAll (
195
199
_store : Store ,
196
200
type : ModelSchema ,
197
- _sinceToken : string ,
198
- snapshotRecordArray ? : SnapshotRecordArray ,
199
- ) : RSVP . Promise < unknown > {
201
+ _sinceToken : null ,
202
+ snapshotRecordArray : SnapshotRecordArray ,
203
+ ) : Promise < AdapterPayload > {
200
204
return new RSVP . Promise ( async ( resolve , reject ) => {
201
205
try {
202
206
const db = getFirestore ( ) ;
@@ -223,12 +227,13 @@ export default class CloudFirestoreAdapter extends Adapter {
223
227
} ) ;
224
228
}
225
229
230
+ // @ts -expect-error ember data types 3 arg
226
231
public query (
227
232
_store : Store ,
228
233
type : ModelSchema ,
229
234
queryOption : AdapterOption ,
230
- recordArray : DS . AdapterPopulatedRecordArray < unknown > ,
231
- ) : RSVP . Promise < unknown > {
235
+ recordArray : Collection ,
236
+ ) : Promise < AdapterPayload > {
232
237
return new RSVP . Promise ( async ( resolve , reject ) => {
233
238
try {
234
239
const colRef = this . buildCollectionRef ( type . modelName , queryOption ) ;
@@ -264,7 +269,7 @@ export default class CloudFirestoreAdapter extends Adapter {
264
269
_snapshot : Snapshot ,
265
270
url : string ,
266
271
relationship : BelongsToRelationshipMeta ,
267
- ) : RSVP . Promise < unknown > {
272
+ ) : Promise < AdapterPayload > {
268
273
return new RSVP . Promise ( async ( resolve , reject ) => {
269
274
try {
270
275
const urlNodes = url . split ( '/' ) ;
@@ -303,7 +308,7 @@ export default class CloudFirestoreAdapter extends Adapter {
303
308
snapshot : Snapshot ,
304
309
url : string ,
305
310
relationship : HasManyRelationshipMeta ,
306
- ) : RSVP . Promise < unknown > {
311
+ ) : Promise < AdapterPayload > {
307
312
return new RSVP . Promise ( async ( resolve , reject ) => {
308
313
try {
309
314
const queryRef = this . buildHasManyCollectionRef (
@@ -315,7 +320,7 @@ export default class CloudFirestoreAdapter extends Adapter {
315
320
const config = {
316
321
queryRef,
317
322
modelName : snapshot . modelName ,
318
- id : snapshot . id ,
323
+ id : snapshot . id ! ,
319
324
field : relationship . key ,
320
325
referenceKeyName : this . referenceKeyName ,
321
326
} ;
@@ -339,7 +344,7 @@ export default class CloudFirestoreAdapter extends Adapter {
339
344
}
340
345
341
346
protected buildCollectionRef (
342
- modelName : keyof ModelRegistry ,
347
+ modelName : string ,
343
348
adapterOptions ?: AdapterOption ,
344
349
) : CollectionReference {
345
350
const db = getFirestore ( ) ;
@@ -402,7 +407,7 @@ export default class CloudFirestoreAdapter extends Adapter {
402
407
) ;
403
408
}
404
409
405
- const modelClass = store . modelFor ( snapshot . modelName ) ;
410
+ const modelClass = store . modelFor ( snapshot . modelName ) as typeof Model ;
406
411
const cardinality = modelClass . determineRelationshipType (
407
412
relationship ,
408
413
store ,
@@ -420,7 +425,7 @@ export default class CloudFirestoreAdapter extends Adapter {
420
425
const collectionRef = collection ( db , url ) ;
421
426
const queryRef = query (
422
427
collectionRef ,
423
- where ( inverse . name , '==' , snapshotDocRef ) ,
428
+ where ( inverse ? .name as string , '==' , snapshotDocRef ) ,
424
429
) ;
425
430
426
431
return (
@@ -436,9 +441,3 @@ export default class CloudFirestoreAdapter extends Adapter {
436
441
) ;
437
442
}
438
443
}
439
-
440
- declare module 'ember-data/types/registries/adapter' {
441
- export default interface AdapterRegistry {
442
- 'cloud-firestore-modular' : CloudFirestoreAdapter ;
443
- }
444
- }
0 commit comments