react-native-firebase-compiled
Version:
A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Functions, Messaging (FCM), Remote Config, Sto
104 lines (73 loc) • 2.65 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _DocumentReference = _interopRequireDefault(require("./DocumentReference"));
var _Query = _interopRequireDefault(require("./Query"));
var _utils = require("../../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* @class CollectionReference
*/
class CollectionReference {
constructor(firestore, collectionPath) {
_defineProperty(this, "_collectionPath", void 0);
_defineProperty(this, "_firestore", void 0);
_defineProperty(this, "_query", void 0);
this._collectionPath = collectionPath;
this._firestore = firestore;
this._query = new _Query.default(firestore, collectionPath);
}
get firestore() {
return this._firestore;
}
get id() {
return this._collectionPath.id;
}
get parent() {
const parentPath = this._collectionPath.parent();
return parentPath ? new _DocumentReference.default(this._firestore, parentPath) : null;
}
add(data) {
const documentRef = this.doc();
return documentRef.set(data).then(() => Promise.resolve(documentRef));
}
doc(documentPath) {
const newPath = documentPath || (0, _utils.firestoreAutoId)();
const path = this._collectionPath.child(newPath);
if (!path.isDocument) {
throw new Error('Argument "documentPath" must point to a document.');
}
return new _DocumentReference.default(this._firestore, path);
} // From Query
endAt(...snapshotOrVarArgs) {
return this._query.endAt(snapshotOrVarArgs);
}
endBefore(...snapshotOrVarArgs) {
return this._query.endBefore(snapshotOrVarArgs);
}
get(options) {
return this._query.get(options);
}
limit(limit) {
return this._query.limit(limit);
}
onSnapshot(optionsOrObserverOrOnNext, observerOrOnNextOrOnError, onError) {
return this._query.onSnapshot(optionsOrObserverOrOnNext, observerOrOnNextOrOnError, onError);
}
orderBy(fieldPath, directionStr) {
return this._query.orderBy(fieldPath, directionStr);
}
startAfter(...snapshotOrVarArgs) {
return this._query.startAfter(snapshotOrVarArgs);
}
startAt(...snapshotOrVarArgs) {
return this._query.startAt(snapshotOrVarArgs);
}
where(fieldPath, opStr, value) {
return this._query.where(fieldPath, opStr, value);
}
}
exports.default = CollectionReference;