Skip to content

Commit

Permalink
chore: extend support for firebase 6.x.x
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSolati committed May 16, 2019
1 parent 6268211 commit d0080f1
Show file tree
Hide file tree
Showing 10 changed files with 4,975 additions and 5,041 deletions.
9,909 changes: 4,920 additions & 4,989 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 17 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,30 @@
"dependencies": {
"@firebase/firestore-types": "x.x.x",
"@google-cloud/firestore": "x.x.x",
"@types/node": "x.x.x"
"@types/node": "x.x.x",
"firebase": "5.x.x || 6.x.x"
},
"devDependencies": {
"@firebase/util": "^0.x.x",
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.5",
"@types/mocha": "^5.2.6",
"chai": "^4.2.0",
"coveralls": "^3.0.2",
"firebase": "5.x.x",
"firebase-tools": "^6.3.1",
"coveralls": "^3.0.3",
"firebase-tools": "^6.9.2",
"generate-changelog": "^1.7.1",
"jsdom": "^13.2.0",
"jsdom-global": "^3.0.2",
"mocha": "^5.2.0",
"nyc": "^13.1.0",
"rollup": "^1.1.2",
"rollup-plugin-commonjs": "^9.2.0",
"jsdom": "15.1.0",
"jsdom-global": "3.0.2",
"mocha": "^6.1.4",
"nyc": "^14.1.1",
"protobufjs": "github:geofirestore/protobuf.js",
"rollup": "^1.12.1",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-copier": "^1.1.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-typescript2": "^0.19.2",
"rollup-plugin-node-resolve": "^5.0.0",
"rollup-plugin-typescript2": "^0.21.0",
"rollup-plugin-uglify": "^6.0.2",
"ts-node": "^8.0.2",
"tslint": "^5.12.1",
"ts-node": "^8.1.0",
"tslint": "^5.16.0",
"typedoc": "^0.14.2",
"typescript": "3.x.x"
},
Expand Down
6 changes: 3 additions & 3 deletions src/GeoDocumentReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ export class GeoDocumentReference {
other: GeoDocumentReference | GeoFirestoreTypes.cloud.DocumentReference | GeoFirestoreTypes.web.DocumentReference
): boolean {
if (other instanceof GeoDocumentReference) {
return (this._document as GeoFirestoreTypes.web.DocumentReference)
.isEqual(other['_document'] as GeoFirestoreTypes.web.DocumentReference);
return (this._document as GeoFirestoreTypes.cloud.DocumentReference)
.isEqual(other['_document'] as GeoFirestoreTypes.cloud.DocumentReference);
}
return (this._document as GeoFirestoreTypes.web.DocumentReference).isEqual(other as GeoFirestoreTypes.web.DocumentReference);
return (this._document as GeoFirestoreTypes.cloud.DocumentReference).isEqual(other as GeoFirestoreTypes.cloud.DocumentReference);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/GeoFirestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ export class GeoFirestore {
public runTransaction(
updateFunction: (transaction: GeoFirestoreTypes.cloud.Transaction | GeoFirestoreTypes.web.Transaction) => Promise<any>
): Promise<any> {
return (this._firestore as GeoFirestoreTypes.web.Firestore).runTransaction(updateFunction);
return (this._firestore as GeoFirestoreTypes.cloud.Firestore).runTransaction(updateFunction);
}
}
29 changes: 15 additions & 14 deletions src/GeoFirestoreTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as FirestoreTypes from '@firebase/firestore-types';
import '@google-cloud/firestore/types/firestore';
import '@types/node';
import * as firebase from 'firebase/app';

export namespace GeoFirestoreTypes {
export interface Document {
Expand Down Expand Up @@ -36,19 +37,19 @@ export namespace GeoFirestoreTypes {
export interface UpdateData { [fieldPath: string]: any; coordinates?: cloud.GeoPoint | web.GeoPoint; }
export type WhereFilterOp = '<' | '<=' | '==' | '>=' | '>' | 'array-contains';
export namespace web {
export type CollectionReference = FirestoreTypes.CollectionReference;
export type DocumentChange = FirestoreTypes.DocumentChange;
export type DocumentReference = FirestoreTypes.DocumentReference;
export type DocumentSnapshot = FirestoreTypes.DocumentSnapshot;
export type Firestore = FirestoreTypes.FirebaseFirestore;
export type FieldPath = FirestoreTypes.FieldPath;
export type GetOptions = FirestoreTypes.GetOptions;
export type GeoPoint = FirestoreTypes.GeoPoint;
export type Query = FirestoreTypes.Query;
export type QuerySnapshot = FirestoreTypes.QuerySnapshot;
export type QueryDocumentSnapshot = FirestoreTypes.QueryDocumentSnapshot;
export type Transaction = FirestoreTypes.Transaction;
export type WriteBatch = FirestoreTypes.WriteBatch;
export type CollectionReference = FirestoreTypes.CollectionReference | firebase.firestore.CollectionReference;
export type DocumentChange = FirestoreTypes.DocumentChange | firebase.firestore.DocumentChange;
export type DocumentReference = FirestoreTypes.DocumentReference | firebase.firestore.DocumentReference;
export type DocumentSnapshot = FirestoreTypes.DocumentSnapshot | firebase.firestore.DocumentSnapshot;
export type Firestore = FirestoreTypes.FirebaseFirestore | firebase.firestore.Firestore;
export type FieldPath = FirestoreTypes.FieldPath | firebase.firestore.FieldPath;
export type GetOptions = FirestoreTypes.GetOptions | firebase.firestore.GetOptions;
export type GeoPoint = FirestoreTypes.GeoPoint | firebase.firestore.GeoPoint;
export type Query = FirestoreTypes.Query | firebase.firestore.Query;
export type QueryDocumentSnapshot = FirestoreTypes.QueryDocumentSnapshot | firebase.firestore.QueryDocumentSnapshot;
export type QuerySnapshot = FirestoreTypes.QuerySnapshot | firebase.firestore.QuerySnapshot;
export type Transaction = FirestoreTypes.Transaction | firebase.firestore.Transaction;
export type WriteBatch = FirestoreTypes.WriteBatch | firebase.firestore.WriteBatch;
}
export namespace cloud {
export type CollectionReference = FirebaseFirestore.CollectionReference;
Expand All @@ -59,8 +60,8 @@ export namespace GeoFirestoreTypes {
export type FieldPath = FirebaseFirestore.FieldPath;
export type GeoPoint = FirebaseFirestore.GeoPoint;
export type Query = FirebaseFirestore.Query;
export type QuerySnapshot = FirebaseFirestore.QuerySnapshot;
export type QueryDocumentSnapshot = FirebaseFirestore.QueryDocumentSnapshot;
export type QuerySnapshot = FirebaseFirestore.QuerySnapshot;
export type Transaction = FirebaseFirestore.Transaction;
export type WriteBatch = FirebaseFirestore.WriteBatch;
}
Expand Down
4 changes: 2 additions & 2 deletions src/GeoQuerySnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class GeoQuerySnapshot {
validateLocation(_center);
}

this._docs = (_querySnapshot as GeoFirestoreTypes.web.QuerySnapshot).docs
.map((snapshot: GeoFirestoreTypes.web.QueryDocumentSnapshot) => generateGeoQueryDocumentSnapshot(snapshot, _center));
this._docs = (_querySnapshot as GeoFirestoreTypes.cloud.QuerySnapshot).docs
.map((snapshot: GeoFirestoreTypes.cloud.QueryDocumentSnapshot) => generateGeoQueryDocumentSnapshot(snapshot, _center));
}

/** An array of all the documents in the GeoQuerySnapshot. */
Expand Down
16 changes: 8 additions & 8 deletions src/GeoTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class GeoTransaction {
documentRef: GeoDocumentReference | GeoFirestoreTypes.cloud.DocumentReference | GeoFirestoreTypes.web.DocumentReference
): GeoTransaction {
const ref = ((documentRef instanceof GeoDocumentReference) ?
documentRef['_document'] : documentRef) as GeoFirestoreTypes.web.DocumentReference;
(this._transaction as GeoFirestoreTypes.web.Transaction).delete(ref);
documentRef['_document'] : documentRef) as GeoFirestoreTypes.cloud.DocumentReference;
(this._transaction as GeoFirestoreTypes.cloud.Transaction).delete(ref);
return this;
}

Expand All @@ -39,8 +39,8 @@ export class GeoTransaction {
documentRef: GeoDocumentReference | GeoFirestoreTypes.cloud.DocumentReference | GeoFirestoreTypes.web.DocumentReference
): Promise<GeoDocumentSnapshot> {
const ref = ((documentRef instanceof GeoDocumentReference) ?
documentRef['_document'] : documentRef) as GeoFirestoreTypes.web.DocumentReference;
return (this._transaction as GeoFirestoreTypes.web.Transaction).get(ref).then(snpashot => new GeoDocumentSnapshot(snpashot));
documentRef['_document'] : documentRef) as GeoFirestoreTypes.cloud.DocumentReference;
return (this._transaction as GeoFirestoreTypes.cloud.Transaction).get(ref).then(snpashot => new GeoDocumentSnapshot(snpashot));
}

/**
Expand All @@ -59,8 +59,8 @@ export class GeoTransaction {
options?: GeoFirestoreTypes.SetOptions
): GeoTransaction {
const ref = ((documentRef instanceof GeoDocumentReference) ?
documentRef['_document'] : documentRef) as GeoFirestoreTypes.web.DocumentReference;
(this._transaction as GeoFirestoreTypes.web.Transaction).set(
documentRef['_document'] : documentRef) as GeoFirestoreTypes.cloud.DocumentReference;
(this._transaction as GeoFirestoreTypes.cloud.Transaction).set(
ref,
encodeSetDocument(data, options),
sanitizeSetOptions(options)
Expand All @@ -84,8 +84,8 @@ export class GeoTransaction {
customKey?: string
): GeoTransaction {
const ref = ((documentRef instanceof GeoDocumentReference) ?
documentRef['_document'] : documentRef) as GeoFirestoreTypes.web.DocumentReference;
(this._transaction as GeoFirestoreTypes.web.Transaction).update(ref, encodeUpdateDocument(data, customKey));
documentRef['_document'] : documentRef) as GeoFirestoreTypes.cloud.DocumentReference;
(this._transaction as GeoFirestoreTypes.cloud.Transaction).update(ref, encodeUpdateDocument(data, customKey));
return this;
}
}
12 changes: 6 additions & 6 deletions src/GeoWriteBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class GeoWriteBatch {
options?: GeoFirestoreTypes.SetOptions
): GeoWriteBatch {
const ref = ((documentRef instanceof GeoDocumentReference) ?
documentRef['_document'] : documentRef) as GeoFirestoreTypes.web.DocumentReference;
(this._writeBatch as GeoFirestoreTypes.web.WriteBatch).set(
documentRef['_document'] : documentRef) as GeoFirestoreTypes.cloud.DocumentReference;
(this._writeBatch as GeoFirestoreTypes.cloud.WriteBatch).set(
ref,
encodeSetDocument(data, options),
sanitizeSetOptions(options)
Expand All @@ -58,8 +58,8 @@ export class GeoWriteBatch {
customKey?: string
): GeoWriteBatch {
const ref = ((documentRef instanceof GeoDocumentReference) ?
documentRef['_document'] : documentRef) as GeoFirestoreTypes.web.DocumentReference;
(this._writeBatch as GeoFirestoreTypes.web.WriteBatch).update(ref, encodeUpdateDocument(data, customKey));
documentRef['_document'] : documentRef) as GeoFirestoreTypes.cloud.DocumentReference;
(this._writeBatch as GeoFirestoreTypes.cloud.WriteBatch).update(ref, encodeUpdateDocument(data, customKey));
return this;
}

Expand All @@ -73,8 +73,8 @@ export class GeoWriteBatch {
documentRef: GeoDocumentReference | GeoFirestoreTypes.cloud.DocumentReference | GeoFirestoreTypes.web.DocumentReference
): GeoWriteBatch {
const ref = ((documentRef instanceof GeoDocumentReference) ?
documentRef['_document'] : documentRef) as GeoFirestoreTypes.web.DocumentReference;
(this._writeBatch as GeoFirestoreTypes.web.WriteBatch).delete(ref);
documentRef['_document'] : documentRef) as GeoFirestoreTypes.cloud.DocumentReference;
(this._writeBatch as GeoFirestoreTypes.cloud.WriteBatch).delete(ref);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export function geohashQueries(center: GeoFirestoreTypes.cloud.GeoPoint | GeoFir
validateLocation(center);
const queryBits = Math.max(1, boundingBoxBits(center, radius));
const geohashPrecision = Math.ceil(queryBits / BITS_PER_CHAR);
const coordinates = boundingBoxCoordinates(center, radius);
const coordinates: GeoFirestoreTypes.cloud.GeoPoint | GeoFirestoreTypes.web.GeoPoint[] = boundingBoxCoordinates(center, radius);
const queries = coordinates.map((coordinate) => {
return geohashQuery(encodeGeohash(coordinate, geohashPrecision), queryBits);
});
Expand Down
4 changes: 2 additions & 2 deletions test/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export const validQueryCriterias: GeoFirestoreTypes.QueryCriteria[] = [
];

// Create global constiables to hold the Firebasestore and GeoFirestore constiables
export let firestore: GeoFirestoreTypes.web.Firestore;
export let collection: GeoFirestoreTypes.web.CollectionReference;
export let firestore: firebase.firestore.Firestore;
export let collection: firebase.firestore.CollectionReference;
export let geofirestore: GeoFirestore;
export let geocollection: GeoCollectionReference;

Expand Down

0 comments on commit d0080f1

Please sign in to comment.