UNPKG

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

116 lines (94 loc) 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _utils = require("../../utils"); 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; } // todo doc methods /** * @class Query */ class Query { constructor(ref, existingModifiers) { _defineProperty(this, "_reference", void 0); _defineProperty(this, "modifiers", void 0); this.modifiers = existingModifiers ? [...existingModifiers] : []; this._reference = ref; } /** * * @param name * @param key * @return {Reference|*} */ orderBy(name, key) { this.modifiers.push({ id: `orderBy-${name}:${key || ''}`, type: 'orderBy', name, key }); return this._reference; } /** * * @param name * @param limit * @return {Reference|*} */ limit(name, limit) { this.modifiers.push({ id: `limit-${name}:${limit}`, type: 'limit', name, limit }); return this._reference; } /** * * @param name * @param value * @param key * @return {Reference|*} */ filter(name, value, key) { this.modifiers.push({ id: `filter-${name}:${(0, _utils.objectToUniqueId)(value)}:${key || ''}`, type: 'filter', name, value, valueType: typeof value, key }); return this._reference; } /** * * @return {[*]} */ getModifiers() { return [...this.modifiers]; } /** * * @return {*} */ queryIdentifier() { // sort modifiers to enforce ordering const sortedModifiers = this.getModifiers().sort((a, b) => { if (a.id < b.id) return -1; if (a.id > b.id) return 1; return 0; }); // Convert modifiers to unique key let key = '{'; for (let i = 0; i < sortedModifiers.length; i++) { if (i !== 0) key += ','; key += sortedModifiers[i].id; } key += '}'; return key; } } exports.default = Query;