@firebase/firestore
Version:
The Cloud Firestore component of the Firebase JS SDK.
1,266 lines (1,192 loc) • 749 kB
JavaScript
import { __extends as t, __spreadArray as e, __awaiter as n, __generator as r } from "tslib";
import { _getProvider as i, getApp as o, _removeServiceInstance as s, SDK_VERSION as u, _registerComponent as a, registerVersion as c } from "@firebase/app";
import { Component as h } from "@firebase/component";
import { Logger as f, LogLevel as l } from "@firebase/logger";
import { getUA as d, isMobileCordova as p, isReactNative as y, isElectron as v, isIE as m, isUWP as g, isBrowserExtension as w, createMockUserToken as b, getModularInstance as I } from "@firebase/util";
import { XhrIo as T, EventType as E, ErrorCode as S, createWebChannelTransport as _, getStatEventTarget as N, FetchXmlHttpFactory as D, WebChannel as A, Event as k, Stat as C } from "@firebase/webchannel-wrapper";
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ var x = "8.6.7", R = /** @class */ function() {
function t(t, e) {
var n = this;
this.previousValue = t, e && (e.sequenceNumberHandler = function(t) {
return n.t(t);
}, this.i = function(t) {
return e.writeSequenceNumber(t);
});
}
return t.prototype.t = function(t) {
return this.previousValue = Math.max(t, this.previousValue), this.previousValue;
}, t.prototype.next = function() {
var t = ++this.previousValue;
return this.i && this.i(t), t;
}, t;
}();
/**
* @license
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* `ListenSequence` is a monotonic sequence. It is initialized with a minimum value to
* exceed. All subsequent calls to next will return increasing values. If provided with a
* `SequenceNumberSyncer`, it will additionally bump its next value when told of a new value, as
* well as write out sequence numbers that it produces via `next()`.
*/ R.o = -1;
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var L = {
// Causes are copied from:
// https://github.com/grpc/grpc/blob/bceec94ea4fc5f0085d81235d8e1c06798dc341a/include/grpc%2B%2B/impl/codegen/status_code_enum.h
/** Not an error; returned on success. */
OK: "ok",
/** The operation was cancelled (typically by the caller). */
CANCELLED: "cancelled",
/** Unknown error or an error from a different error domain. */
UNKNOWN: "unknown",
/**
* Client specified an invalid argument. Note that this differs from
* FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments that are
* problematic regardless of the state of the system (e.g., a malformed file
* name).
*/
INVALID_ARGUMENT: "invalid-argument",
/**
* Deadline expired before operation could complete. For operations that
* change the state of the system, this error may be returned even if the
* operation has completed successfully. For example, a successful response
* from a server could have been delayed long enough for the deadline to
* expire.
*/
DEADLINE_EXCEEDED: "deadline-exceeded",
/** Some requested entity (e.g., file or directory) was not found. */
NOT_FOUND: "not-found",
/**
* Some entity that we attempted to create (e.g., file or directory) already
* exists.
*/
ALREADY_EXISTS: "already-exists",
/**
* The caller does not have permission to execute the specified operation.
* PERMISSION_DENIED must not be used for rejections caused by exhausting
* some resource (use RESOURCE_EXHAUSTED instead for those errors).
* PERMISSION_DENIED must not be used if the caller can not be identified
* (use UNAUTHENTICATED instead for those errors).
*/
PERMISSION_DENIED: "permission-denied",
/**
* The request does not have valid authentication credentials for the
* operation.
*/
UNAUTHENTICATED: "unauthenticated",
/**
* Some resource has been exhausted, perhaps a per-user quota, or perhaps the
* entire file system is out of space.
*/
RESOURCE_EXHAUSTED: "resource-exhausted",
/**
* Operation was rejected because the system is not in a state required for
* the operation's execution. For example, directory to be deleted may be
* non-empty, an rmdir operation is applied to a non-directory, etc.
*
* A litmus test that may help a service implementor in deciding
* between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE:
* (a) Use UNAVAILABLE if the client can retry just the failing call.
* (b) Use ABORTED if the client should retry at a higher-level
* (e.g., restarting a read-modify-write sequence).
* (c) Use FAILED_PRECONDITION if the client should not retry until
* the system state has been explicitly fixed. E.g., if an "rmdir"
* fails because the directory is non-empty, FAILED_PRECONDITION
* should be returned since the client should not retry unless
* they have first fixed up the directory by deleting files from it.
* (d) Use FAILED_PRECONDITION if the client performs conditional
* REST Get/Update/Delete on a resource and the resource on the
* server does not match the condition. E.g., conflicting
* read-modify-write on the same resource.
*/
FAILED_PRECONDITION: "failed-precondition",
/**
* The operation was aborted, typically due to a concurrency issue like
* sequencer check failures, transaction aborts, etc.
*
* See litmus test above for deciding between FAILED_PRECONDITION, ABORTED,
* and UNAVAILABLE.
*/
ABORTED: "aborted",
/**
* Operation was attempted past the valid range. E.g., seeking or reading
* past end of file.
*
* Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed
* if the system state changes. For example, a 32-bit file system will
* generate INVALID_ARGUMENT if asked to read at an offset that is not in the
* range [0,2^32-1], but it will generate OUT_OF_RANGE if asked to read from
* an offset past the current file size.
*
* There is a fair bit of overlap between FAILED_PRECONDITION and
* OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific error)
* when it applies so that callers who are iterating through a space can
* easily look for an OUT_OF_RANGE error to detect when they are done.
*/
OUT_OF_RANGE: "out-of-range",
/** Operation is not implemented or not supported/enabled in this service. */
UNIMPLEMENTED: "unimplemented",
/**
* Internal errors. Means some invariants expected by underlying System has
* been broken. If you see one of these errors, Something is very broken.
*/
INTERNAL: "internal",
/**
* The service is currently unavailable. This is a most likely a transient
* condition and may be corrected by retrying with a backoff.
*
* See litmus test above for deciding between FAILED_PRECONDITION, ABORTED,
* and UNAVAILABLE.
*/
UNAVAILABLE: "unavailable",
/** Unrecoverable data loss or corruption. */
DATA_LOSS: "data-loss"
}, O = /** @class */ function(e) {
/** @hideconstructor */
function n(
/**
* The backend error code associated with this error.
*/
t,
/**
* A custom error description.
*/
n) {
var r = this;
return (r = e.call(this, n) || this).code = t, r.message = n,
/** The custom name for all FirestoreErrors. */
r.name = "FirebaseError",
// HACK: We write a toString property directly because Error is not a real
// class and so inheritance does not work correctly. We could alternatively
// do the same "back-door inheritance" trick that FirebaseError does.
r.toString = function() {
return r.name + ": [code=" + r.code + "]: " + r.message;
}, r;
}
return t(n, e), n;
}(Error), P = new f("@firebase/firestore");
/** An error returned by a Firestore operation. */
// Helper methods are needed because variables can't be exported as read/write
function M() {
return P.logLevel;
}
/**
* Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
*
* @param logLevel - The verbosity you set for activity and error logging. Can
* be any of the following values:
*
* <ul>
* <li>`debug` for the most verbose logging level, primarily for
* debugging.</li>
* <li>`error` to log errors only.</li>
* <li><code>`silent` to turn off logging.</li>
* </ul>
*/ function F(t) {
P.setLogLevel(t);
}
function V(t) {
for (var n = [], r = 1; r < arguments.length; r++) n[r - 1] = arguments[r];
if (P.logLevel <= l.DEBUG) {
var i = n.map(B);
P.debug.apply(P, e([ "Firestore (" + x + "): " + t ], i));
}
}
function q(t) {
for (var n = [], r = 1; r < arguments.length; r++) n[r - 1] = arguments[r];
if (P.logLevel <= l.ERROR) {
var i = n.map(B);
P.error.apply(P, e([ "Firestore (" + x + "): " + t ], i));
}
}
function U(t) {
for (var n = [], r = 1; r < arguments.length; r++) n[r - 1] = arguments[r];
if (P.logLevel <= l.WARN) {
var i = n.map(B);
P.warn.apply(P, e([ "Firestore (" + x + "): " + t ], i));
}
}
/**
* Converts an additional log parameter to a string representation.
*/ function B(t) {
if ("string" == typeof t) return t;
try {
return e = t, JSON.stringify(e);
} catch (e) {
// Converting to JSON failed, just log the object directly
return t;
}
var e;
}
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Unconditionally fails, throwing an Error with the given message.
* Messages are stripped in production builds.
*
* Returns `never` and can be used in expressions:
* @example
* let futureVar = fail('not implemented yet');
*/ function j(t) {
void 0 === t && (t = "Unexpected state");
// Log the failure in addition to throw an exception, just in case the
// exception is swallowed.
var e = "FIRESTORE (" + x + ") INTERNAL ASSERTION FAILED: " + t;
// NOTE: We don't use FirestoreError here because these are internal failures
// that cannot be handled by the user. (Also it would create a circular
// dependency between the error and assert modules which doesn't work.)
throw q(e), new Error(e)
/**
* Fails if the given assertion condition is false, throwing an Error with the
* given message if it did.
*
* Messages are stripped in production builds.
*/;
}
function K(t, e) {
t || j();
}
/**
* Casts `obj` to `T`. In non-production builds, verifies that `obj` is an
* instance of `T` before casting.
*/ function G(t,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
e) {
return t;
}
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Generates `nBytes` of random bytes.
*
* If `nBytes < 0` , an error will be thrown.
*/ function Q(t) {
// Polyfills for IE and WebWorker by using `self` and `msCrypto` when `crypto` is not available.
var e =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
"undefined" != typeof self && (self.crypto || self.msCrypto), n = new Uint8Array(t);
if (e && "function" == typeof e.getRandomValues) e.getRandomValues(n); else
// Falls back to Math.random
for (var r = 0; r < t; r++) n[r] = Math.floor(256 * Math.random());
return n;
}
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ var z = /** @class */ function() {
function t() {}
return t.u = function() {
for (
// Alphanumeric characters
var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", e = Math.floor(256 / t.length) * t.length, n = ""
// The largest byte value that is a multiple of `char.length`.
; n.length < 20; ) for (var r = Q(40), i = 0; i < r.length; ++i)
// Only accept values that are [0, maxMultiple), this ensures they can
// be evenly mapped to indices of `chars` via a modulo operation.
n.length < 20 && r[i] < e && (n += t.charAt(r[i] % t.length));
return n;
}, t;
}();
function W(t, e) {
return t < e ? -1 : t > e ? 1 : 0;
}
/** Helper to compare arrays using isEqual(). */ function H(t, e, n) {
return t.length === e.length && t.every((function(t, r) {
return n(t, e[r]);
}));
}
/**
* Returns the immediate lexicographically-following string. This is useful to
* construct an inclusive range for indexeddb iterators.
*/ function Y(t) {
// Return the input string, with an additional NUL byte appended.
return t + "\0";
}
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// The earliest date supported by Firestore timestamps (0001-01-01T00:00:00Z).
/**
* A `Timestamp` represents a point in time independent of any time zone or
* calendar, represented as seconds and fractions of seconds at nanosecond
* resolution in UTC Epoch time.
*
* It is encoded using the Proleptic Gregorian Calendar which extends the
* Gregorian calendar backwards to year one. It is encoded assuming all minutes
* are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second
* table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
* 9999-12-31T23:59:59.999999999Z.
*
* For examples and further specifications, refer to the
* {@link https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto | Timestamp definition}.
*/ var X = /** @class */ function() {
/**
* Creates a new timestamp.
*
* @param seconds - The number of seconds of UTC time since Unix epoch
* 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
* 9999-12-31T23:59:59Z inclusive.
* @param nanoseconds - The non-negative fractions of a second at nanosecond
* resolution. Negative second values with fractions must still have
* non-negative nanoseconds values that count forward in time. Must be
* from 0 to 999,999,999 inclusive.
*/
function t(
/**
* The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
*/
t,
/**
* The fractions of a second at nanosecond resolution.*
*/
e) {
if (this.seconds = t, this.nanoseconds = e, e < 0) throw new O(L.INVALID_ARGUMENT, "Timestamp nanoseconds out of range: " + e);
if (e >= 1e9) throw new O(L.INVALID_ARGUMENT, "Timestamp nanoseconds out of range: " + e);
if (t < -62135596800) throw new O(L.INVALID_ARGUMENT, "Timestamp seconds out of range: " + t);
// This will break in the year 10,000.
if (t >= 253402300800) throw new O(L.INVALID_ARGUMENT, "Timestamp seconds out of range: " + t);
}
/**
* Creates a new timestamp with the current date, with millisecond precision.
*
* @returns a new timestamp representing the current date.
*/ return t.now = function() {
return t.fromMillis(Date.now());
},
/**
* Creates a new timestamp from the given date.
*
* @param date - The date to initialize the `Timestamp` from.
* @returns A new `Timestamp` representing the same point in time as the given
* date.
*/
t.fromDate = function(e) {
return t.fromMillis(e.getTime());
},
/**
* Creates a new timestamp from the given number of milliseconds.
*
* @param milliseconds - Number of milliseconds since Unix epoch
* 1970-01-01T00:00:00Z.
* @returns A new `Timestamp` representing the same point in time as the given
* number of milliseconds.
*/
t.fromMillis = function(e) {
var n = Math.floor(e / 1e3);
return new t(n, Math.floor(1e6 * (e - 1e3 * n)));
},
/**
* Converts a `Timestamp` to a JavaScript `Date` object. This conversion
* causes a loss of precision since `Date` objects only support millisecond
* precision.
*
* @returns JavaScript `Date` object representing the same point in time as
* this `Timestamp`, with millisecond precision.
*/
t.prototype.toDate = function() {
return new Date(this.toMillis());
},
/**
* Converts a `Timestamp` to a numeric timestamp (in milliseconds since
* epoch). This operation causes a loss of precision.
*
* @returns The point in time corresponding to this timestamp, represented as
* the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
*/
t.prototype.toMillis = function() {
return 1e3 * this.seconds + this.nanoseconds / 1e6;
}, t.prototype._compareTo = function(t) {
return this.seconds === t.seconds ? W(this.nanoseconds, t.nanoseconds) : W(this.seconds, t.seconds);
},
/**
* Returns true if this `Timestamp` is equal to the provided one.
*
* @param other - The `Timestamp` to compare against.
* @returns true if this `Timestamp` is equal to the provided one.
*/
t.prototype.isEqual = function(t) {
return t.seconds === this.seconds && t.nanoseconds === this.nanoseconds;
},
/** Returns a textual representation of this Timestamp. */ t.prototype.toString = function() {
return "Timestamp(seconds=" + this.seconds + ", nanoseconds=" + this.nanoseconds + ")";
},
/** Returns a JSON-serializable representation of this Timestamp. */ t.prototype.toJSON = function() {
return {
seconds: this.seconds,
nanoseconds: this.nanoseconds
};
},
/**
* Converts this object to a primitive string, which allows Timestamp objects
* to be compared using the `>`, `<=`, `>=` and `>` operators.
*/
t.prototype.valueOf = function() {
// This method returns a string of the form <seconds>.<nanoseconds> where
// <seconds> is translated to have a non-negative value and both <seconds>
// and <nanoseconds> are left-padded with zeroes to be a consistent length.
// Strings with this format then have a lexiographical ordering that matches
// the expected ordering. The <seconds> translation is done to avoid having
// a leading negative sign (i.e. a leading '-' character) in its string
// representation, which would affect its lexiographical ordering.
var t = this.seconds - -62135596800;
// Note: Up to 12 decimal digits are required to represent all valid
// 'seconds' values.
return String(t).padStart(12, "0") + "." + String(this.nanoseconds).padStart(9, "0");
}, t;
}(), $ = /** @class */ function() {
function t(t) {
this.timestamp = t;
}
return t.fromTimestamp = function(e) {
return new t(e);
}, t.min = function() {
return new t(new X(0, 0));
}, t.prototype.compareTo = function(t) {
return this.timestamp._compareTo(t.timestamp);
}, t.prototype.isEqual = function(t) {
return this.timestamp.isEqual(t.timestamp);
},
/** Returns a number representation of the version for use in spec tests. */ t.prototype.toMicroseconds = function() {
// Convert to microseconds.
return 1e6 * this.timestamp.seconds + this.timestamp.nanoseconds / 1e3;
}, t.prototype.toString = function() {
return "SnapshotVersion(" + this.timestamp.toString() + ")";
}, t.prototype.toTimestamp = function() {
return this.timestamp;
}, t;
}();
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* A version of a document in Firestore. This corresponds to the version
* timestamp, such as update_time or read_time.
*/
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function J(t) {
var e = 0;
for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && e++;
return e;
}
function Z(t, e) {
for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && e(n, t[n]);
}
function tt(t) {
for (var e in t) if (Object.prototype.hasOwnProperty.call(t, e)) return !1;
return !0;
}
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Path represents an ordered sequence of string segments.
*/ var et = /** @class */ function() {
function t(t, e, n) {
void 0 === e ? e = 0 : e > t.length && j(), void 0 === n ? n = t.length - e : n > t.length - e && j(),
this.segments = t, this.offset = e, this.len = n;
}
return Object.defineProperty(t.prototype, "length", {
get: function() {
return this.len;
},
enumerable: !1,
configurable: !0
}), t.prototype.isEqual = function(e) {
return 0 === t.comparator(this, e);
}, t.prototype.child = function(e) {
var n = this.segments.slice(this.offset, this.limit());
return e instanceof t ? e.forEach((function(t) {
n.push(t);
})) : n.push(e), this.construct(n);
},
/** The index of one past the last segment of the path. */ t.prototype.limit = function() {
return this.offset + this.length;
}, t.prototype.popFirst = function(t) {
return t = void 0 === t ? 1 : t, this.construct(this.segments, this.offset + t, this.length - t);
}, t.prototype.popLast = function() {
return this.construct(this.segments, this.offset, this.length - 1);
}, t.prototype.firstSegment = function() {
return this.segments[this.offset];
}, t.prototype.lastSegment = function() {
return this.get(this.length - 1);
}, t.prototype.get = function(t) {
return this.segments[this.offset + t];
}, t.prototype.isEmpty = function() {
return 0 === this.length;
}, t.prototype.isPrefixOf = function(t) {
if (t.length < this.length) return !1;
for (var e = 0; e < this.length; e++) if (this.get(e) !== t.get(e)) return !1;
return !0;
}, t.prototype.isImmediateParentOf = function(t) {
if (this.length + 1 !== t.length) return !1;
for (var e = 0; e < this.length; e++) if (this.get(e) !== t.get(e)) return !1;
return !0;
}, t.prototype.forEach = function(t) {
for (var e = this.offset, n = this.limit(); e < n; e++) t(this.segments[e]);
}, t.prototype.toArray = function() {
return this.segments.slice(this.offset, this.limit());
}, t.comparator = function(t, e) {
for (var n = Math.min(t.length, e.length), r = 0; r < n; r++) {
var i = t.get(r), o = e.get(r);
if (i < o) return -1;
if (i > o) return 1;
}
return t.length < e.length ? -1 : t.length > e.length ? 1 : 0;
}, t;
}(), nt = /** @class */ function(e) {
function n() {
return null !== e && e.apply(this, arguments) || this;
}
return t(n, e), n.prototype.construct = function(t, e, r) {
return new n(t, e, r);
}, n.prototype.canonicalString = function() {
// NOTE: The client is ignorant of any path segments containing escape
// sequences (e.g. __id123__) and just passes them through raw (they exist
// for legacy reasons and should not be used frequently).
return this.toArray().join("/");
}, n.prototype.toString = function() {
return this.canonicalString();
},
/**
* Creates a resource path from the given slash-delimited string. If multiple
* arguments are provided, all components are combined. Leading and trailing
* slashes from all components are ignored.
*/
n.fromString = function() {
for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
// NOTE: The client is ignorant of any path segments containing escape
// sequences (e.g. __id123__) and just passes them through raw (they exist
// for legacy reasons and should not be used frequently).
for (var r = [], i = 0, o = t; i < o.length; i++) {
var s = o[i];
if (s.indexOf("//") >= 0) throw new O(L.INVALID_ARGUMENT, "Invalid segment (" + s + "). Paths must not contain // in them.");
// Strip leading and traling slashed.
r.push.apply(r, s.split("/").filter((function(t) {
return t.length > 0;
})));
}
return new n(r);
}, n.emptyPath = function() {
return new n([]);
}, n;
}(et), rt = /^[_a-zA-Z][_a-zA-Z0-9]*$/, it = /** @class */ function(e) {
function n() {
return null !== e && e.apply(this, arguments) || this;
}
return t(n, e), n.prototype.construct = function(t, e, r) {
return new n(t, e, r);
},
/**
* Returns true if the string could be used as a segment in a field path
* without escaping.
*/
n.isValidIdentifier = function(t) {
return rt.test(t);
}, n.prototype.canonicalString = function() {
return this.toArray().map((function(t) {
return t = t.replace(/\\/g, "\\\\").replace(/`/g, "\\`"), n.isValidIdentifier(t) || (t = "`" + t + "`"),
t;
})).join(".");
}, n.prototype.toString = function() {
return this.canonicalString();
},
/**
* Returns true if this field references the key of a document.
*/
n.prototype.isKeyField = function() {
return 1 === this.length && "__name__" === this.get(0);
},
/**
* The field designating the key of a document.
*/
n.keyField = function() {
return new n([ "__name__" ]);
},
/**
* Parses a field string from the given server-formatted string.
*
* - Splitting the empty string is not allowed (for now at least).
* - Empty segments within the string (e.g. if there are two consecutive
* separators) are not allowed.
*
* TODO(b/37244157): we should make this more strict. Right now, it allows
* non-identifier path components, even if they aren't escaped.
*/
n.fromServerFormat = function(t) {
for (var e = [], r = "", i = 0, o = function() {
if (0 === r.length) throw new O(L.INVALID_ARGUMENT, "Invalid field path (" + t + "). Paths must not be empty, begin with '.', end with '.', or contain '..'");
e.push(r), r = "";
}, s = !1; i < t.length; ) {
var u = t[i];
if ("\\" === u) {
if (i + 1 === t.length) throw new O(L.INVALID_ARGUMENT, "Path has trailing escape character: " + t);
var a = t[i + 1];
if ("\\" !== a && "." !== a && "`" !== a) throw new O(L.INVALID_ARGUMENT, "Path has invalid escape sequence: " + t);
r += a, i += 2;
} else "`" === u ? (s = !s, i++) : "." !== u || s ? (r += u, i++) : (o(), i++);
}
if (o(), s) throw new O(L.INVALID_ARGUMENT, "Unterminated ` in path: " + t);
return new n(e);
}, n.emptyPath = function() {
return new n([]);
}, n;
}(et), ot = /** @class */ function() {
function t(t) {
this.fields = t,
// TODO(dimond): validation of FieldMask
// Sort the field mask to support `FieldMask.isEqual()` and assert below.
t.sort(it.comparator)
/**
* Verifies that `fieldPath` is included by at least one field in this field
* mask.
*
* This is an O(n) operation, where `n` is the size of the field mask.
*/;
}
return t.prototype.covers = function(t) {
for (var e = 0, n = this.fields; e < n.length; e++) {
if (n[e].isPrefixOf(t)) return !0;
}
return !1;
}, t.prototype.isEqual = function(t) {
return H(this.fields, t.fields, (function(t, e) {
return t.isEqual(e);
}));
}, t;
}(), st = /** @class */ function() {
function t(t) {
this.binaryString = t;
}
return t.fromBase64String = function(e) {
return new t(atob(e));
}, t.fromUint8Array = function(e) {
return new t(
/**
* Helper function to convert an Uint8array to a binary string.
*/
function(t) {
for (var e = "", n = 0; n < t.length; ++n) e += String.fromCharCode(t[n]);
return e;
}(e));
}, t.prototype.toBase64 = function() {
return t = this.binaryString, btoa(t);
/** Converts a binary string to a Base64 encoded string. */ var t;
}, t.prototype.toUint8Array = function() {
return function(t) {
for (var e = new Uint8Array(t.length), n = 0; n < t.length; n++) e[n] = t.charCodeAt(n);
return e;
}(this.binaryString);
}, t.prototype.approximateByteSize = function() {
return 2 * this.binaryString.length;
}, t.prototype.compareTo = function(t) {
return W(this.binaryString, t.binaryString);
}, t.prototype.isEqual = function(t) {
return this.binaryString === t.binaryString;
}, t;
}();
/**
* A slash-separated path for navigating resources (documents and collections)
* within Firestore.
*/ st.EMPTY_BYTE_STRING = new st("");
var ut = new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);
/**
* Converts the possible Proto values for a timestamp value into a "seconds and
* nanos" representation.
*/ function at(t) {
// The json interface (for the browser) will return an iso timestamp string,
// while the proto js library (for node) will return a
// google.protobuf.Timestamp instance.
if (K(!!t), "string" == typeof t) {
// The date string can have higher precision (nanos) than the Date class
// (millis), so we do some custom parsing here.
// Parse the nanos right out of the string.
var e = 0, n = ut.exec(t);
if (K(!!n), n[1]) {
// Pad the fraction out to 9 digits (nanos).
var r = n[1];
r = (r + "000000000").substr(0, 9), e = Number(r);
}
// Parse the date to get the seconds.
var i = new Date(t);
return {
seconds: Math.floor(i.getTime() / 1e3),
nanos: e
};
}
return {
seconds: ct(t.seconds),
nanos: ct(t.nanos)
};
}
/**
* Converts the possible Proto types for numbers into a JavaScript number.
* Returns 0 if the value is not numeric.
*/ function ct(t) {
// TODO(bjornick): Handle int64 greater than 53 bits.
return "number" == typeof t ? t : "string" == typeof t ? Number(t) : 0;
}
/** Converts the possible Proto types for Blobs into a ByteString. */ function ht(t) {
return "string" == typeof t ? st.fromBase64String(t) : st.fromUint8Array(t);
}
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Represents a locally-applied ServerTimestamp.
*
* Server Timestamps are backed by MapValues that contain an internal field
* `__type__` with a value of `server_timestamp`. The previous value and local
* write time are stored in its `__previous_value__` and `__local_write_time__`
* fields respectively.
*
* Notes:
* - ServerTimestampValue instances are created as the result of applying a
* transform. They can only exist in the local view of a document. Therefore
* they do not need to be parsed or serialized.
* - When evaluated locally (e.g. for snapshot.data()), they by default
* evaluate to `null`. This behavior can be configured by passing custom
* FieldValueOptions to value().
* - With respect to other ServerTimestampValues, they sort by their
* localWriteTime.
*/ function ft(t) {
var e, n;
return "server_timestamp" === (null === (n = ((null === (e = null == t ? void 0 : t.mapValue) || void 0 === e ? void 0 : e.fields) || {}).__type__) || void 0 === n ? void 0 : n.stringValue);
}
/**
* Creates a new ServerTimestamp proto value (using the internal format).
*/
/**
* Returns the value of the field before this ServerTimestamp was set.
*
* Preserving the previous values allows the user to display the last resoled
* value until the backend responds with the timestamp.
*/ function lt(t) {
var e = t.mapValue.fields.__previous_value__;
return ft(e) ? lt(e) : e;
}
/**
* Returns the local time at which this timestamp was first set.
*/ function dt(t) {
var e = at(t.mapValue.fields.__local_write_time__.timestampValue);
return new X(e.seconds, e.nanos);
}
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** Sentinel value that sorts before any Mutation Batch ID. */
/**
* Returns whether a variable is either undefined or null.
*/ function pt(t) {
return null == t;
}
/** Returns whether the value represents -0. */ function yt(t) {
// Detect if the value is -0.0. Based on polyfill from
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
return 0 === t && 1 / t == -1 / 0;
}
/**
* Returns whether a value is an integer and in the safe integer range
* @param value - The value to test for being an integer and in the safe range
*/ function vt(t) {
return "number" == typeof t && Number.isInteger(t) && !yt(t) && t <= Number.MAX_SAFE_INTEGER && t >= Number.MIN_SAFE_INTEGER;
}
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ var mt = /** @class */ function() {
function t(t) {
this.path = t;
}
return t.fromPath = function(e) {
return new t(nt.fromString(e));
}, t.fromName = function(e) {
return new t(nt.fromString(e).popFirst(5));
},
/** Returns true if the document is in the specified collectionId. */ t.prototype.hasCollectionId = function(t) {
return this.path.length >= 2 && this.path.get(this.path.length - 2) === t;
}, t.prototype.isEqual = function(t) {
return null !== t && 0 === nt.comparator(this.path, t.path);
}, t.prototype.toString = function() {
return this.path.toString();
}, t.comparator = function(t, e) {
return nt.comparator(t.path, e.path);
}, t.isDocumentKey = function(t) {
return t.length % 2 == 0;
},
/**
* Creates and returns a new document key with the given segments.
*
* @param segments - The segments of the path to the document
* @returns A new instance of DocumentKey
*/
t.fromSegments = function(e) {
return new t(new nt(e.slice()));
}, t;
}();
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** Extracts the backend's type order for the provided value. */ function gt(t) {
return "nullValue" in t ? 0 /* NullValue */ : "booleanValue" in t ? 1 /* BooleanValue */ : "integerValue" in t || "doubleValue" in t ? 2 /* NumberValue */ : "timestampValue" in t ? 3 /* TimestampValue */ : "stringValue" in t ? 5 /* StringValue */ : "bytesValue" in t ? 6 /* BlobValue */ : "referenceValue" in t ? 7 /* RefValue */ : "geoPointValue" in t ? 8 /* GeoPointValue */ : "arrayValue" in t ? 9 /* ArrayValue */ : "mapValue" in t ? ft(t) ? 4 /* ServerTimestampValue */ : 10 /* ObjectValue */ : j();
}
/** Tests `left` and `right` for equality based on the backend semantics. */ function wt(t, e) {
var n = gt(t);
if (n !== gt(e)) return !1;
switch (n) {
case 0 /* NullValue */ :
return !0;
case 1 /* BooleanValue */ :
return t.booleanValue === e.booleanValue;
case 4 /* ServerTimestampValue */ :
return dt(t).isEqual(dt(e));
case 3 /* TimestampValue */ :
return function(t, e) {
if ("string" == typeof t.timestampValue && "string" == typeof e.timestampValue && t.timestampValue.length === e.timestampValue.length)
// Use string equality for ISO 8601 timestamps
return t.timestampValue === e.timestampValue;
var n = at(t.timestampValue), r = at(e.timestampValue);
return n.seconds === r.seconds && n.nanos === r.nanos;
}(t, e);
case 5 /* StringValue */ :
return t.stringValue === e.stringValue;
case 6 /* BlobValue */ :
return function(t, e) {
return ht(t.bytesValue).isEqual(ht(e.bytesValue));
}(t, e);
case 7 /* RefValue */ :
return t.referenceValue === e.referenceValue;
case 8 /* GeoPointValue */ :
return function(t, e) {
return ct(t.geoPointValue.latitude) === ct(e.geoPointValue.latitude) && ct(t.geoPointValue.longitude) === ct(e.geoPointValue.longitude);
}(t, e);
case 2 /* NumberValue */ :
return function(t, e) {
if ("integerValue" in t && "integerValue" in e) return ct(t.integerValue) === ct(e.integerValue);
if ("doubleValue" in t && "doubleValue" in e) {
var n = ct(t.doubleValue), r = ct(e.doubleValue);
return n === r ? yt(n) === yt(r) : isNaN(n) && isNaN(r);
}
return !1;
}(t, e);
case 9 /* ArrayValue */ :
return H(t.arrayValue.values || [], e.arrayValue.values || [], wt);
case 10 /* ObjectValue */ :
return function(t, e) {
var n = t.mapValue.fields || {}, r = e.mapValue.fields || {};
if (J(n) !== J(r)) return !1;
for (var i in n) if (n.hasOwnProperty(i) && (void 0 === r[i] || !wt(n[i], r[i]))) return !1;
return !0;
}(t, e);
default:
return j();
}
}
function bt(t, e) {
return void 0 !== (t.values || []).find((function(t) {
return wt(t, e);
}));
}
function It(t, e) {
var n = gt(t), r = gt(e);
if (n !== r) return W(n, r);
switch (n) {
case 0 /* NullValue */ :
return 0;
case 1 /* BooleanValue */ :
return W(t.booleanValue, e.booleanValue);
case 2 /* NumberValue */ :
return function(t, e) {
var n = ct(t.integerValue || t.doubleValue), r = ct(e.integerValue || e.doubleValue);
return n < r ? -1 : n > r ? 1 : n === r ? 0 :
// one or both are NaN.
isNaN(n) ? isNaN(r) ? 0 : -1 : 1;
}(t, e);
case 3 /* TimestampValue */ :
return Tt(t.timestampValue, e.timestampValue);
case 4 /* ServerTimestampValue */ :
return Tt(dt(t), dt(e));
case 5 /* StringValue */ :
return W(t.stringValue, e.stringValue);
case 6 /* BlobValue */ :
return function(t, e) {
var n = ht(t), r = ht(e);
return n.compareTo(r);
}(t.bytesValue, e.bytesValue);
case 7 /* RefValue */ :
return function(t, e) {
for (var n = t.split("/"), r = e.split("/"), i = 0; i < n.length && i < r.length; i++) {
var o = W(n[i], r[i]);
if (0 !== o) return o;
}
return W(n.length, r.length);
}(t.referenceValue, e.referenceValue);
case 8 /* GeoPointValue */ :
return function(t, e) {
var n = W(ct(t.latitude), ct(e.latitude));
return 0 !== n ? n : W(ct(t.longitude), ct(e.longitude));
}(t.geoPointValue, e.geoPointValue);
case 9 /* ArrayValue */ :
return function(t, e) {
for (var n = t.values || [], r = e.values || [], i = 0; i < n.length && i < r.length; ++i) {
var o = It(n[i], r[i]);
if (o) return o;
}
return W(n.length, r.length);
}(t.arrayValue, e.arrayValue);
case 10 /* ObjectValue */ :
return function(t, e) {
var n = t.fields || {}, r = Object.keys(n), i = e.fields || {}, o = Object.keys(i);
// Even though MapValues are likely sorted correctly based on their insertion
// order (e.g. when received from the backend), local modifications can bring
// elements out of order. We need to re-sort the elements to ensure that
// canonical IDs are independent of insertion order.
r.sort(), o.sort();
for (var s = 0; s < r.length && s < o.length; ++s) {
var u = W(r[s], o[s]);
if (0 !== u) return u;
var a = It(n[r[s]], i[o[s]]);
if (0 !== a) return a;
}
return W(r.length, o.length);
}(t.mapValue, e.mapValue);
default:
throw j();
}
}
function Tt(t, e) {
if ("string" == typeof t && "string" == typeof e && t.length === e.length) return W(t, e);
var n = at(t), r = at(e), i = W(n.seconds, r.seconds);
return 0 !== i ? i : W(n.nanos, r.nanos);
}
function Et(t) {
return St(t);
}
function St(t) {
return "nullValue" in t ? "null" : "booleanValue" in t ? "" + t.booleanValue : "integerValue" in t ? "" + t.integerValue : "doubleValue" in t ? "" + t.doubleValue : "timestampValue" in t ? function(t) {
var e = at(t);
return "time(" + e.seconds + "," + e.nanos + ")";
}(t.timestampValue) : "stringValue" in t ? t.stringValue : "bytesValue" in t ? ht(t.bytesValue).toBase64() : "referenceValue" in t ? (n = t.referenceValue,
mt.fromName(n).toString()) : "geoPointValue" in t ? "geo(" + (e = t.geoPointValue).latitude + "," + e.longitude + ")" : "arrayValue" in t ? function(t) {
for (var e = "[", n = !0, r = 0, i = t.values || []; r < i.length; r++) {
n ? n = !1 : e += ",", e += St(i[r]);
}
return e + "]";
}(t.arrayValue) : "mapValue" in t ? function(t) {
for (
// Iteration order in JavaScript is not guaranteed. To ensure that we generate
// matching canonical IDs for identical maps, we need to sort the keys.
var e = "{", n = !0, r = 0, i = Object.keys(t.fields || {}).sort(); r < i.length; r++) {
var o = i[r];
n ? n = !1 : e += ",", e += o + ":" + St(t.fields[o]);
}
return e + "}";
}(t.mapValue) : j();
var e, n;
}
function _t(t, e) {
return {
referenceValue: "projects/" + t.projectId + "/databases/" + t.database + "/documents/" + e.path.canonicalString()
};
}
/** Returns true if `value` is an IntegerValue . */ function Nt(t) {
return !!t && "integerValue" in t;
}
/** Returns true if `value` is a DoubleValue. */
/** Returns true if `value` is an ArrayValue. */ function Dt(t) {
return !!t && "arrayValue" in t;
}
/** Returns true if `value` is a NullValue. */ function At(t) {
return !!t && "nullValue" in t;
}
/** Returns true if `value` is NaN. */ function kt(t) {
return !!t && "doubleValue" in t && isNaN(Number(t.doubleValue));
}
/** Returns true if `va