Skip to content

Commit d96a506

Browse files
committed
refactor: timestamp
1 parent 808207d commit d96a506

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

Diff for: src/firestore/utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import {
55
DocumentData,
66
GeoPoint,
77
FirestoreDataConverter,
8+
Timestamp,
89
} from 'firebase/firestore'
9-
import { isTimestamp, isObject, isDocumentRef, TODO } from '../shared'
10+
import { isObject, isDocumentRef, TODO } from '../shared'
1011
import { VueFirestoreDocumentData } from '.'
1112

1213
export type FirestoreReference = Query | DocumentReference | CollectionReference
@@ -80,8 +81,7 @@ export function extractRefs(
8081
// TODO: check and remove
8182
// Firestore < 4.13
8283
ref instanceof Date ||
83-
// TODO: instanceof Timestamp?
84-
isTimestamp(ref) ||
84+
ref instanceof Timestamp ||
8585
// TODO: same?
8686
isGeoPoint(ref)
8787
) {

Diff for: src/shared.ts

+10-18
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export const noop = () => {}
1616

1717
export const isClient = typeof window !== 'undefined'
1818

19-
// TODO: replace any with unknown or T generics if possible and worth
20-
2119
export interface OperationsType {
2220
set<T extends object = Record<any, unknown>>(
2321
target: T,
@@ -52,7 +50,7 @@ export type TODO = any
5250
* @param obj
5351
* @param path
5452
*/
55-
export function walkGet(obj: Record<string, any>, path: string): any {
53+
export function walkGet(obj: Record<string, TODO>, path: string): TODO {
5654
return path.split('.').reduce((target, key) => target && target[key], obj)
5755
}
5856

@@ -91,24 +89,16 @@ export function walkSet<T extends object = Record<any, unknown>>(
9189
* Checks if a variable is an object
9290
* @param o
9391
*/
94-
export function isObject(o: any): o is Record<any, unknown> {
95-
return o && typeof o === 'object'
96-
}
97-
98-
/**
99-
* Checks if a variable is a Date
100-
* @param o
101-
*/
102-
export function isTimestamp(o: any): o is Timestamp {
103-
return o.toDate
92+
export function isObject(o: unknown): o is Record<any, unknown> {
93+
return !!o && typeof o === 'object'
10494
}
10595

10696
/**
10797
* Checks if a variable is a Firestore Document Reference
10898
* @param o
10999
*/
110100
export function isDocumentRef<T = DocumentData>(
111-
o: any
101+
o: unknown
112102
): o is DocumentReference<T> {
113103
return isObject(o) && o.type === 'document'
114104
}
@@ -118,13 +108,13 @@ export function isDocumentRef<T = DocumentData>(
118108
* @param o
119109
*/
120110
export function isCollectionRef<T = DocumentData>(
121-
o: any
111+
o: unknown
122112
): o is CollectionReference<T> {
123113
return isObject(o) && o.type === 'collection'
124114
}
125115

126116
export function isFirestoreDataReference<T = unknown>(
127-
source: any
117+
source: unknown
128118
): source is CollectionReference<T> | DocumentReference<T> {
129119
return isDocumentRef(source) || isCollectionRef(source)
130120
}
@@ -155,12 +145,14 @@ export function getDataSourcePath(
155145
}
156146

157147
export function isDatabaseReference(
158-
source: any
148+
source: unknown
159149
): source is DatabaseReference | DatabaseQuery {
160150
return isObject(source) && 'ref' in source
161151
}
162152

163-
export function isStorageReference(source: any): source is StorageReference {
153+
export function isStorageReference(
154+
source: unknown
155+
): source is StorageReference {
164156
return isObject(source) && typeof source.bucket === 'string'
165157
}
166158

0 commit comments

Comments
 (0)