Skip to content

Commit 8fc9188

Browse files
committed
TS
1 parent a884049 commit 8fc9188

File tree

11 files changed

+115
-376
lines changed

11 files changed

+115
-376
lines changed

addon/adapters/cloud-firestore-modular.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { getOwner } from '@ember/application';
22
import { inject as service } from '@ember/service';
33
import Adapter from '@ember-data/adapter';
4-
import DS, { ModelSchema } from 'ember-data';
5-
import ModelRegistry from 'ember-data/types/registries/model';
4+
import DS, { type ModelSchema } from 'ember-data';
5+
import type ModelRegistry from 'ember-data/types/registries/model';
66
import RSVP from 'rsvp';
77
import Store from '@ember-data/store';
88

@@ -272,7 +272,7 @@ export default class CloudFirestoreAdapter extends Adapter {
272272
urlNodes.pop();
273273

274274
const db = getFirestore();
275-
const docRef = doc(db, urlNodes.join('/'), id);
275+
const docRef = doc(db, urlNodes.join('/'), id!);
276276
const modelName = relationship.type;
277277
const docSnapshot =
278278
relationship.options.isRealtime && !this.isFastBoot

addon/authenticators/firebase.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getOwner } from '@ember/application';
22

3-
import { Auth, User, UserCredential } from 'firebase/auth';
3+
import type { Auth, User, UserCredential } from 'firebase/auth';
44
import BaseAuthenticator from 'ember-simple-auth/authenticators/base';
55
import type FastBoot from 'ember-cli-fastboot/services/fastboot';
66

addon/instance-initializers/firebase-settings.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ApplicationInstance from '@ember/application/instance';
22

3-
import { FirebaseApp, FirebaseOptions } from 'firebase/app';
4-
import { Firestore, EmulatorMockTokenOptions } from 'firebase/firestore';
3+
import type { FirebaseApp, FirebaseError, FirebaseOptions } from 'firebase/app';
4+
import type { Firestore, EmulatorMockTokenOptions } from 'firebase/firestore';
55

66
import { initializeApp } from 'ember-cloud-firestore-adapter/firebase/app';
77
import {
@@ -141,7 +141,7 @@ export function initialize(appInstance: ApplicationInstance): void {
141141
try {
142142
setupModularInstance(addonConfig);
143143
} catch (e) {
144-
if (e.code !== 'failed-precondition') {
144+
if ((e as FirebaseError).code !== 'failed-precondition') {
145145
throw new Error(
146146
`There was a problem with initializing Firebase. Check if you've configured the addon properly. | Error: ${e}`,
147147
);

addon/serializers/cloud-firestore-modular.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { isNone } from '@ember/utils';
7-
import DS, { ModelSchema } from 'ember-data';
7+
import DS, { type ModelSchema } from 'ember-data';
88
import JSONSerializer from '@ember-data/serializer/json';
99
import Store from '@ember-data/store';
1010

@@ -134,9 +134,9 @@ export default class CloudFirestoreSerializer extends JSONSerializer {
134134
...super.serialize(snapshot, options),
135135
};
136136

137-
snapshot.eachRelationship((name: string, relationship) => {
137+
snapshot.eachRelationship((name, relationship) => {
138138
if (relationship.kind === 'hasMany') {
139-
delete json[name];
139+
delete json[name as string];
140140
}
141141
});
142142

addon/services/-firestore-data-manager.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { next } from '@ember/runloop';
22
import DS from 'ember-data';
3-
import ModelRegistry from 'ember-data/types/registries/model';
3+
import type ModelRegistry from 'ember-data/types/registries/model';
44
import Service, { inject as service } from '@ember/service';
55
import StoreService from '@ember-data/store';
66

7-
import {
7+
import type {
88
CollectionReference,
99
DocumentReference,
1010
DocumentSnapshot,
@@ -96,7 +96,7 @@ export default class FirestoreDataManager extends Service {
9696
await this.setupDocRealtimeUpdates(modelName, docRef);
9797
}
9898

99-
return this.docListeners[listenerKey].snapshot;
99+
return this.docListeners[listenerKey]?.snapshot!;
100100
}
101101

102102
public async findAllRealtime(
@@ -109,7 +109,7 @@ export default class FirestoreDataManager extends Service {
109109
await this.setupColRealtimeUpdates(modelName, colRef);
110110
}
111111

112-
return this.colListeners[listenerKey].snapshot;
112+
return this.colListeners[listenerKey]?.snapshot!;
113113
}
114114

115115
public async queryRealtime(
@@ -120,7 +120,7 @@ export default class FirestoreDataManager extends Service {
120120
let unsubscribe: Unsubscribe | undefined;
121121

122122
if (this.queryListeners[queryId]) {
123-
unsubscribe = this.queryListeners[queryId].unsubscribe;
123+
unsubscribe = this.queryListeners[queryId]?.unsubscribe;
124124
delete this.queryListeners[queryId];
125125
}
126126

@@ -130,7 +130,7 @@ export default class FirestoreDataManager extends Service {
130130
unsubscribe();
131131
}
132132

133-
return this.queryListeners[queryId].snapshots;
133+
return this.queryListeners[queryId]?.snapshots!;
134134
}
135135

136136
public async findHasManyRealtime(
@@ -141,7 +141,7 @@ export default class FirestoreDataManager extends Service {
141141
let unsubscribe: Unsubscribe | undefined;
142142

143143
if (this.hasManyListeners[queryId]) {
144-
unsubscribe = this.hasManyListeners[queryId].unsubscribe;
144+
unsubscribe = this.hasManyListeners[queryId]?.unsubscribe;
145145
delete this.hasManyListeners[queryId];
146146
}
147147

@@ -151,7 +151,7 @@ export default class FirestoreDataManager extends Service {
151151
unsubscribe();
152152
}
153153

154-
return this.hasManyListeners[queryId].snapshots;
154+
return this.hasManyListeners[queryId]?.snapshots!;
155155
}
156156

157157
public async queryWithReferenceTo(
@@ -320,7 +320,7 @@ export default class FirestoreDataManager extends Service {
320320
listenerKey: string,
321321
): void {
322322
if (docSnapshot.exists()) {
323-
this.docListeners[listenerKey].snapshot = docSnapshot;
323+
this.docListeners[listenerKey]!.snapshot = docSnapshot;
324324
this.pushRecord(modelName, docSnapshot);
325325
} else {
326326
this.unloadRecord(modelName, docSnapshot.id, listenerKey);
@@ -332,7 +332,7 @@ export default class FirestoreDataManager extends Service {
332332
listenerKey: string,
333333
querySnapshot: QuerySnapshot,
334334
): void {
335-
this.colListeners[listenerKey].snapshot = querySnapshot;
335+
this.colListeners[listenerKey]!.snapshot = querySnapshot;
336336

337337
querySnapshot.forEach((docSnapshot) => {
338338
this.pushRecord(modelName, docSnapshot);
@@ -378,7 +378,7 @@ export default class FirestoreDataManager extends Service {
378378
// multiple times. Race condition can happen where queryId no longer exists inside
379379
// queryListeners so we have this check.
380380
if (Object.prototype.hasOwnProperty.call(this.queryListeners, queryId)) {
381-
const { unsubscribe } = this.queryListeners[queryId];
381+
const { unsubscribe } = this.queryListeners[queryId]!;
382382

383383
delete this.queryListeners[queryId];
384384
recordArray.update().then(() => unsubscribe());
@@ -479,22 +479,22 @@ export default class FirestoreDataManager extends Service {
479479

480480
private destroyListener(type: string, key: string): void {
481481
if (type === 'doc' && this.docListeners[key]) {
482-
this.docListeners[key].unsubscribe();
482+
this.docListeners[key]?.unsubscribe();
483483
delete this.docListeners[key];
484484
}
485485

486486
if (type === 'col' && this.colListeners[key]) {
487-
this.colListeners[key].unsubscribe();
487+
this.colListeners[key]?.unsubscribe();
488488
delete this.colListeners[key];
489489
}
490490

491491
if (type === 'query' && this.queryListeners[key]) {
492-
this.queryListeners[key].unsubscribe();
492+
this.queryListeners[key]?.unsubscribe();
493493
delete this.queryListeners[key];
494494
}
495495

496496
if (type === 'hasMany' && this.hasManyListeners[key]) {
497-
this.hasManyListeners[key].unsubscribe();
497+
this.hasManyListeners[key]?.unsubscribe();
498498
delete this.hasManyListeners[key];
499499
}
500500
}

0 commit comments

Comments
 (0)