diff options
| author | altaf-creator <dev@altafcreator.com> | 2025-11-09 11:15:19 +0800 |
|---|---|---|
| committer | altaf-creator <dev@altafcreator.com> | 2025-11-09 11:15:19 +0800 |
| commit | 8eff962cab608341a6f2fedc640a0e32d96f26e2 (patch) | |
| tree | 05534d1a720ddc3691d346c69b4972555820a061 /frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote | |
pain
Diffstat (limited to 'frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote')
19 files changed, 1680 insertions, 0 deletions
diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/backoff.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/backoff.d.ts new file mode 100644 index 0000000..cb0bc76 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/backoff.d.ts @@ -0,0 +1,106 @@ +/** + * @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. + */ +import { AsyncQueue, TimerId } from '../util/async_queue'; +/** + * A helper for running delayed tasks following an exponential backoff curve + * between attempts. + * + * Each delay is made up of a "base" delay which follows the exponential + * backoff curve, and a +/- 50% "jitter" that is calculated and added to the + * base delay. This prevents clients from accidentally synchronizing their + * delays causing spikes of load to the backend. + */ +export declare class ExponentialBackoff { + /** + * The AsyncQueue to run backoff operations on. + */ + private readonly queue; + /** + * The ID to use when scheduling backoff operations on the AsyncQueue. + */ + private readonly timerId; + /** + * The initial delay (used as the base delay on the first retry attempt). + * Note that jitter will still be applied, so the actual delay could be as + * little as 0.5*initialDelayMs. + */ + private readonly initialDelayMs; + /** + * The multiplier to use to determine the extended base delay after each + * attempt. + */ + private readonly backoffFactor; + /** + * The maximum base delay after which no further backoff is performed. + * Note that jitter will still be applied, so the actual delay could be as + * much as 1.5*maxDelayMs. + */ + private readonly maxDelayMs; + private currentBaseMs; + private timerPromise; + /** The last backoff attempt, as epoch milliseconds. */ + private lastAttemptTime; + constructor( + /** + * The AsyncQueue to run backoff operations on. + */ + queue: AsyncQueue, + /** + * The ID to use when scheduling backoff operations on the AsyncQueue. + */ + timerId: TimerId, + /** + * The initial delay (used as the base delay on the first retry attempt). + * Note that jitter will still be applied, so the actual delay could be as + * little as 0.5*initialDelayMs. + */ + initialDelayMs?: number, + /** + * The multiplier to use to determine the extended base delay after each + * attempt. + */ + backoffFactor?: number, + /** + * The maximum base delay after which no further backoff is performed. + * Note that jitter will still be applied, so the actual delay could be as + * much as 1.5*maxDelayMs. + */ + maxDelayMs?: number); + /** + * Resets the backoff delay. + * + * The very next backoffAndWait() will have no delay. If it is called again + * (i.e. due to an error), initialDelayMs (plus jitter) will be used, and + * subsequent ones will increase according to the backoffFactor. + */ + reset(): void; + /** + * Resets the backoff delay to the maximum delay (e.g. for use after a + * RESOURCE_EXHAUSTED error). + */ + resetToMax(): void; + /** + * Returns a promise that resolves after currentDelayMs, and increases the + * delay for any subsequent attempts. If there was a pending backoff operation + * already, it will be canceled. + */ + backoffAndRun(op: () => Promise<void>): void; + skipBackoff(): void; + cancel(): void; + /** Returns a random value in the range [-currentBaseMs/2, currentBaseMs/2] */ + private jitterDelayMs; +} diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/bloom_filter.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/bloom_filter.d.ts new file mode 100644 index 0000000..d80eb83 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/bloom_filter.d.ts @@ -0,0 +1,34 @@ +/** + * @license + * Copyright 2022 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. + */ +export declare class BloomFilter { + readonly bitmap: Uint8Array; + readonly padding: number; + readonly hashCount: number; + readonly bitCount: number; + private readonly bitCountInInteger; + constructor(bitmap: Uint8Array, padding: number, hashCount: number); + private getBitIndex; + private isBitSet; + mightContain(value: string): boolean; + /** Create bloom filter for testing purposes only. */ + static create(bitCount: number, hashCount: number, contains: string[]): BloomFilter; + private insert; + private setBit; +} +export declare class BloomFilterError extends Error { + readonly name = "BloomFilterError"; +} diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/connection.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/connection.d.ts new file mode 100644 index 0000000..87afea6 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/connection.d.ts @@ -0,0 +1,99 @@ +/** + * @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. + */ +import { Token } from '../api/credentials'; +import { ResourcePath } from '../model/path'; +import { FirestoreError } from '../util/error'; +/** + * A connected RPC interface to a remote Datastore. + * + * Responsible for maintaining a connection to the backend (and informing when + * that connection state changes via onConnectionStateChange) and sending RPCs + * when possible. + * + * The Connection is not responsible for queueing RPCs to the backend when + * the connection is down. + * + * RPC messages are expected to be JavaScript objects representing the JSON that + * would be sent over the REST/JSON API to Datastore or used as input to + * creating the equivalent protocol buffers for GRPC. + */ +export interface Connection { + /** + * Invokes an RPC by name, given a request message as a JavaScript object + * representing the JSON to send. + * + * @param rpcName - the name of the RPC to invoke + * @param path - the path to invoke this RPC on. An array of path segments + * that will be encoded and joined with path separators when required. + * @param request - the Raw JSON object encoding of the request message + * @param token - the Token to use for the RPC. + * @returns a Promise containing the JSON object encoding of the response + */ + invokeRPC<Req, Resp>(rpcName: string, path: ResourcePath, request: Req, authToken: Token | null, appCheckToken: Token | null): Promise<Resp>; + /** + * Invokes a streaming RPC by name, given a request message as a JavaScript + * object representing the JSON to send. The responses will be consumed to + * completion and then returned as an array. + * + * @param rpcName - the name of the RPC to invoke + * @param path - the path to invoke this RPC on. An array of path segments + * that will be encoded and joined with path separators when required. + * @param request - the Raw JSON object encoding of the request message + * @param token - the Token to use for the RPC. + * @returns a Promise containing an array with the JSON object encodings of the + * responses + */ + invokeStreamingRPC<Req, Resp>(rpcName: string, path: ResourcePath, request: Req, authToken: Token | null, appCheckToken: Token | null, expectedResponseCount?: number): Promise<Resp[]>; + /** + * Opens a stream to the given stream RPC endpoint. Returns a stream which + * will try to open itself. + * @param rpcName - the name of the RPC to open the stream on + * @param token - the Token to use for the RPC. + */ + openStream<Req, Resp>(rpcName: string, authToken: Token | null, appCheckToken: Token | null): Stream<Req, Resp>; + /** + * Returns whether or not the implementation requires that the "path" of the resource + * (a document or a collection) be present in the request message. If true, then the + * request message must include the path. If false, then the request message must NOT + * include the path. + */ + readonly shouldResourcePathBeIncludedInRequest: boolean; + /** + * Closes and cleans up any resources associated with the connection. Actual + * resources cleaned are implementation specific. Failure to call `terminate` + * on a connection may result in resource leaks. + */ + terminate(): void; +} +/** + * A bidirectional stream that can be used to send an receive messages. + * + * A stream can be closed locally with close() or can be closed remotely or + * through network errors. onClose is guaranteed to be called. onOpen will be + * called once the stream is ready to send messages (which may or may not be + * before an actual connection to the backend has been established). The + * onConnected event is called when an actual, physical connection with the + * backend has been established, and may occur before or after the onOpen event. + */ +export interface Stream<I, O> { + onConnected(callback: () => void): void; + onOpen(callback: () => void): void; + onClose(callback: (err?: FirestoreError) => void): void; + onMessage(callback: (msg: O) => void): void; + send(msg: I): void; + close(): void; +} diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/connectivity_monitor.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/connectivity_monitor.d.ts new file mode 100644 index 0000000..e02b7d2 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/connectivity_monitor.d.ts @@ -0,0 +1,47 @@ +/** + * @license + * Copyright 2019 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 set of network states is deliberately simplified -- we only care about + * states such that transition between them should break currently + * established connections. + */ +export declare const enum NetworkStatus { + AVAILABLE = 0, + UNAVAILABLE = 1 +} +export type ConnectivityMonitorCallback = (status: NetworkStatus) => void; +/** + * A base class for monitoring changes in network connectivity; it is expected + * that each platform will have its own system-dependent implementation. + */ +export interface ConnectivityMonitor { + /** + * Adds a callback to be called when connectivity changes. + * + * Callbacks are not made on the initial state of connectivity, since this + * monitor is primarily used for resetting backoff in the remote store when + * connectivity changes. As such, the initial connectivity state is + * irrelevant here. + */ + addCallback(callback: ConnectivityMonitorCallback): void; + /** + * Stops monitoring connectivity. After this call completes, no further + * callbacks will be triggered. After shutdown() is called, no further calls + * are allowed on this instance. + */ + shutdown(): void; +} diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/connectivity_monitor_noop.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/connectivity_monitor_noop.d.ts new file mode 100644 index 0000000..42bb25c --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/connectivity_monitor_noop.d.ts @@ -0,0 +1,21 @@ +/** + * @license + * Copyright 2019 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. + */ +import { ConnectivityMonitor, NetworkStatus } from './connectivity_monitor'; +export declare class NoopConnectivityMonitor implements ConnectivityMonitor { + addCallback(callback: (status: NetworkStatus) => void): void; + shutdown(): void; +} diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/datastore.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/datastore.d.ts new file mode 100644 index 0000000..fe095c0 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/datastore.d.ts @@ -0,0 +1,44 @@ +/** + * @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. + */ +import { CredentialsProvider } from '../api/credentials'; +import { User } from '../auth/user'; +import { Aggregate } from '../core/aggregate'; +import { Query } from '../core/query'; +import { Document } from '../model/document'; +import { DocumentKey } from '../model/document_key'; +import { Mutation } from '../model/mutation'; +import { ApiClientObjectMap, Value } from '../protos/firestore_proto_api'; +import { AsyncQueue } from '../util/async_queue'; +import { Connection } from './connection'; +import { PersistentListenStream, PersistentWriteStream, WatchStreamListener, WriteStreamListener } from './persistent_stream'; +import { JsonProtoSerializer } from './serializer'; +/** + * Datastore and its related methods are a wrapper around the external Google + * Cloud Datastore grpc API, which provides an interface that is more convenient + * for the rest of the client SDK architecture to consume. + */ +export declare abstract class Datastore { + abstract terminate(): void; + abstract serializer: JsonProtoSerializer; +} +export declare function newDatastore(authCredentials: CredentialsProvider<User>, appCheckCredentials: CredentialsProvider<string>, connection: Connection, serializer: JsonProtoSerializer): Datastore; +export declare function invokeCommitRpc(datastore: Datastore, mutations: Mutation[]): Promise<void>; +export declare function invokeBatchGetDocumentsRpc(datastore: Datastore, keys: DocumentKey[]): Promise<Document[]>; +export declare function invokeRunQueryRpc(datastore: Datastore, query: Query): Promise<Document[]>; +export declare function invokeRunAggregationQueryRpc(datastore: Datastore, query: Query, aggregates: Aggregate[]): Promise<ApiClientObjectMap<Value>>; +export declare function newPersistentWriteStream(datastore: Datastore, queue: AsyncQueue, listener: WriteStreamListener): PersistentWriteStream; +export declare function newPersistentWatchStream(datastore: Datastore, queue: AsyncQueue, listener: WatchStreamListener): PersistentListenStream; diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/existence_filter.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/existence_filter.d.ts new file mode 100644 index 0000000..10ed5e5 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/existence_filter.d.ts @@ -0,0 +1,22 @@ +/** + * @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. + */ +import { BloomFilter as ProtoBloomFilter } from '../protos/firestore_proto_api'; +export declare class ExistenceFilter { + count: number; + unchangedNames?: ProtoBloomFilter | undefined; + constructor(count: number, unchangedNames?: ProtoBloomFilter | undefined); +} diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/internal_serializer.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/internal_serializer.d.ts new file mode 100644 index 0000000..cd1f08d --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/internal_serializer.d.ts @@ -0,0 +1,46 @@ +/** + * @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. + */ +import { AggregateSpec } from '../lite-api/aggregate_types'; +import { Query } from '../lite-api/reference'; +/** + * @internal + * @private + * + * This function is for internal use only. + * + * Returns the `QueryTarget` representation of the given query. Returns `null` + * if the Firestore client associated with the given query has not been + * initialized or has been terminated. + * + * @param query - The Query to convert to proto representation. + */ +export declare function _internalQueryToProtoQueryTarget(query: Query): any; +/** + * @internal + * @private + * + * This function is for internal use only. + * + * Returns `RunAggregationQueryRequest` which contains the proto representation + * of the given aggregation query request. Returns null if the Firestore client + * associated with the given query has not been initialized or has been + * terminated. + * + * @param query - The Query to convert to proto representation. + * @param aggregateSpec - The set of aggregations and their aliases. + */ +export declare function _internalAggregationQueryToProtoRunAggregationQueryRequest<AggregateSpecType extends AggregateSpec>(query: Query, aggregateSpec: AggregateSpecType): any; diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/number_serializer.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/number_serializer.d.ts new file mode 100644 index 0000000..cec4398 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/number_serializer.d.ts @@ -0,0 +1,36 @@ +/** + * @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. + */ +import { Value as ProtoValue } from '../protos/firestore_proto_api'; +/** Base interface for the Serializer implementation. */ +export interface Serializer { + readonly useProto3Json: boolean; +} +/** + * Returns an DoubleValue for `value` that is encoded based the serializer's + * `useProto3Json` setting. + */ +export declare function toDouble(serializer: Serializer, value: number): ProtoValue; +/** + * Returns an IntegerValue for `value`. + */ +export declare function toInteger(value: number): ProtoValue; +/** + * Returns a value for a number that's appropriate to put into a proto. + * The return value is an IntegerValue if it can safely represent the value, + * otherwise a DoubleValue is returned. + */ +export declare function toNumber(serializer: Serializer, value: number): ProtoValue; diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/online_state_tracker.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/online_state_tracker.d.ts new file mode 100644 index 0000000..8a9bf8d --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/online_state_tracker.d.ts @@ -0,0 +1,81 @@ +/** + * @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. + */ +import { OnlineState } from '../core/types'; +import { AsyncQueue } from '../util/async_queue'; +import { FirestoreError } from '../util/error'; +/** + * A component used by the RemoteStore to track the OnlineState (that is, + * whether or not the client as a whole should be considered to be online or + * offline), implementing the appropriate heuristics. + * + * In particular, when the client is trying to connect to the backend, we + * allow up to MAX_WATCH_STREAM_FAILURES within ONLINE_STATE_TIMEOUT_MS for + * a connection to succeed. If we have too many failures or the timeout elapses, + * then we set the OnlineState to Offline, and the client will behave as if + * it is offline (get()s will return cached data, etc.). + */ +export declare class OnlineStateTracker { + private asyncQueue; + private onlineStateHandler; + /** The current OnlineState. */ + private state; + /** + * A count of consecutive failures to open the stream. If it reaches the + * maximum defined by MAX_WATCH_STREAM_FAILURES, we'll set the OnlineState to + * Offline. + */ + private watchStreamFailures; + /** + * A timer that elapses after ONLINE_STATE_TIMEOUT_MS, at which point we + * transition from OnlineState.Unknown to OnlineState.Offline without waiting + * for the stream to actually fail (MAX_WATCH_STREAM_FAILURES times). + */ + private onlineStateTimer; + /** + * Whether the client should log a warning message if it fails to connect to + * the backend (initially true, cleared after a successful stream, or if we've + * logged the message already). + */ + private shouldWarnClientIsOffline; + constructor(asyncQueue: AsyncQueue, onlineStateHandler: (onlineState: OnlineState) => void); + /** + * Called by RemoteStore when a watch stream is started (including on each + * backoff attempt). + * + * If this is the first attempt, it sets the OnlineState to Unknown and starts + * the onlineStateTimer. + */ + handleWatchStreamStart(): void; + /** + * Updates our OnlineState as appropriate after the watch stream reports a + * failure. The first failure moves us to the 'Unknown' state. We then may + * allow multiple failures (based on MAX_WATCH_STREAM_FAILURES) before we + * actually transition to the 'Offline' state. + */ + handleWatchStreamFailure(error: FirestoreError): void; + /** + * Explicitly sets the OnlineState to the specified state. + * + * Note that this resets our timers / failure counters, etc. used by our + * Offline heuristics, so must not be used in place of + * handleWatchStreamStart() and handleWatchStreamFailure(). + */ + set(newState: OnlineState): void; + private setAndBroadcast; + private logClientOfflineWarningIfNecessary; + private clearOnlineStateTimer; +} diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/persistent_stream.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/persistent_stream.d.ts new file mode 100644 index 0000000..aacaf2d --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/persistent_stream.d.ts @@ -0,0 +1,308 @@ +/** + * @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. + */ +import { CredentialsProvider, Token } from '../api/credentials'; +import { User } from '../auth/user'; +import { SnapshotVersion } from '../core/snapshot_version'; +import { TargetId } from '../core/types'; +import { TargetData } from '../local/target_data'; +import { Mutation, MutationResult } from '../model/mutation'; +import { ListenRequest as ProtoListenRequest, ListenResponse as ProtoListenResponse, WriteRequest as ProtoWriteRequest, WriteResponse as ProtoWriteResponse } from '../protos/firestore_proto_api'; +import { AsyncQueue, TimerId } from '../util/async_queue'; +import { FirestoreError } from '../util/error'; +import { ExponentialBackoff } from './backoff'; +import { Connection, Stream } from './connection'; +import { JsonProtoSerializer } from './serializer'; +import { WatchChange } from './watch_change'; +export interface WriteRequest extends ProtoWriteRequest { + database?: string; +} +/** + * Provides a common interface that is shared by the listeners for stream + * events by the concrete implementation classes. + */ +export interface PersistentStreamListener { + /** + * Called after receiving an acknowledgement from the server, confirming that + * we are able to connect to it. + */ + onConnected: () => Promise<void>; + /** + * Called after the stream was established and can accept outgoing + * messages + */ + onOpen: () => Promise<void>; + /** + * Called after the stream has closed. If there was an error, the + * FirestoreError will be set. + */ + onClose: (err?: FirestoreError) => Promise<void>; +} +/** + * A PersistentStream is an abstract base class that represents a streaming RPC + * to the Firestore backend. It's built on top of the connections own support + * for streaming RPCs, and adds several critical features for our clients: + * + * - Exponential backoff on failure + * - Authentication via CredentialsProvider + * - Dispatching all callbacks into the shared worker queue + * - Closing idle streams after 60 seconds of inactivity + * + * Subclasses of PersistentStream implement serialization of models to and + * from the JSON representation of the protocol buffers for a specific + * streaming RPC. + * + * ## Starting and Stopping + * + * Streaming RPCs are stateful and need to be start()ed before messages can + * be sent and received. The PersistentStream will call the onOpen() function + * of the listener once the stream is ready to accept requests. + * + * Should a start() fail, PersistentStream will call the registered onClose() + * listener with a FirestoreError indicating what went wrong. + * + * A PersistentStream can be started and stopped repeatedly. + * + * Generic types: + * SendType: The type of the outgoing message of the underlying + * connection stream + * ReceiveType: The type of the incoming message of the underlying + * connection stream + * ListenerType: The type of the listener that will be used for callbacks + */ +export declare abstract class PersistentStream<SendType, ReceiveType, ListenerType extends PersistentStreamListener> { + private queue; + private idleTimerId; + private healthTimerId; + protected connection: Connection; + private authCredentialsProvider; + private appCheckCredentialsProvider; + protected listener: ListenerType; + private state; + /** + * A close count that's incremented every time the stream is closed; used by + * getCloseGuardedDispatcher() to invalidate callbacks that happen after + * close. + */ + private closeCount; + private idleTimer; + private healthCheck; + private stream; + protected backoff: ExponentialBackoff; + constructor(queue: AsyncQueue, connectionTimerId: TimerId, idleTimerId: TimerId, healthTimerId: TimerId, connection: Connection, authCredentialsProvider: CredentialsProvider<User>, appCheckCredentialsProvider: CredentialsProvider<string>, listener: ListenerType); + /** + * Count of response messages received. + */ + protected responseCount: number; + /** + * Returns true if start() has been called and no error has occurred. True + * indicates the stream is open or in the process of opening (which + * encompasses respecting backoff, getting auth tokens, and starting the + * actual RPC). Use isOpen() to determine if the stream is open and ready for + * outbound requests. + */ + isStarted(): boolean; + /** + * Returns true if the underlying RPC is open (the onOpen() listener has been + * called) and the stream is ready for outbound requests. + */ + isOpen(): boolean; + /** + * Starts the RPC. Only allowed if isStarted() returns false. The stream is + * not immediately ready for use: onOpen() will be invoked when the RPC is + * ready for outbound requests, at which point isOpen() will return true. + * + * When start returns, isStarted() will return true. + */ + start(): void; + /** + * Stops the RPC. This call is idempotent and allowed regardless of the + * current isStarted() state. + * + * When stop returns, isStarted() and isOpen() will both return false. + */ + stop(): Promise<void>; + /** + * After an error the stream will usually back off on the next attempt to + * start it. If the error warrants an immediate restart of the stream, the + * sender can use this to indicate that the receiver should not back off. + * + * Each error will call the onClose() listener. That function can decide to + * inhibit backoff if required. + */ + inhibitBackoff(): void; + /** + * Marks this stream as idle. If no further actions are performed on the + * stream for one minute, the stream will automatically close itself and + * notify the stream's onClose() handler with Status.OK. The stream will then + * be in a !isStarted() state, requiring the caller to start the stream again + * before further use. + * + * Only streams that are in state 'Open' can be marked idle, as all other + * states imply pending network operations. + */ + markIdle(): void; + /** Sends a message to the underlying stream. */ + protected sendRequest(msg: SendType): void; + /** Called by the idle timer when the stream should close due to inactivity. */ + private handleIdleCloseTimer; + /** Marks the stream as active again. */ + private cancelIdleCheck; + /** Cancels the health check delayed operation. */ + private cancelHealthCheck; + /** + * Closes the stream and cleans up as necessary: + * + * * closes the underlying GRPC stream; + * * calls the onClose handler with the given 'error'; + * * sets internal stream state to 'finalState'; + * * adjusts the backoff timer based on the error + * + * A new stream can be opened by calling start(). + * + * @param finalState - the intended state of the stream after closing. + * @param error - the error the connection was closed with. + */ + private close; + /** + * Can be overridden to perform additional cleanup before the stream is closed. + * Calling super.tearDown() is not required. + */ + protected tearDown(): void; + /** + * Used by subclasses to start the concrete RPC and return the underlying + * connection stream. + */ + protected abstract startRpc(authToken: Token | null, appCheckToken: Token | null): Stream<SendType, ReceiveType>; + /** + * Called when the stream receives first message. + * The function will be called on the right queue and must return a Promise. + * @param message - The message received from the stream. + */ + protected abstract onFirst(message: ReceiveType): Promise<void>; + /** + * Called on subsequent messages after the stream has received first message. + * The function will be called on the right queue and must return a Promise. + * @param message - The message received from the stream. + */ + protected abstract onNext(message: ReceiveType): Promise<void>; + private auth; + private startStream; + private performBackoff; + handleStreamClose(error?: FirestoreError): Promise<void>; + /** + * Returns a "dispatcher" function that dispatches operations onto the + * AsyncQueue but only runs them if closeCount remains unchanged. This allows + * us to turn auth / stream callbacks into no-ops if the stream is closed / + * re-opened, etc. + */ + private getCloseGuardedDispatcher; +} +/** Listener for the PersistentWatchStream */ +export interface WatchStreamListener extends PersistentStreamListener { + /** + * Called on a watchChange. The snapshot parameter will be MIN if the watch + * change did not have a snapshot associated with it. + */ + onWatchChange: (watchChange: WatchChange, snapshot: SnapshotVersion) => Promise<void>; +} +/** + * A PersistentStream that implements the Listen RPC. + * + * Once the Listen stream has called the onOpen() listener, any number of + * listen() and unlisten() calls can be made to control what changes will be + * sent from the server for ListenResponses. + */ +export declare class PersistentListenStream extends PersistentStream<ProtoListenRequest, ProtoListenResponse, WatchStreamListener> { + private serializer; + constructor(queue: AsyncQueue, connection: Connection, authCredentials: CredentialsProvider<User>, appCheckCredentials: CredentialsProvider<string>, serializer: JsonProtoSerializer, listener: WatchStreamListener); + protected startRpc(authToken: Token | null, appCheckToken: Token | null): Stream<ProtoListenRequest, ProtoListenResponse>; + protected onFirst(watchChangeProto: ProtoListenResponse): Promise<void>; + protected onNext(watchChangeProto: ProtoListenResponse): Promise<void>; + /** + * Registers interest in the results of the given target. If the target + * includes a resumeToken it will be included in the request. Results that + * affect the target will be streamed back as WatchChange messages that + * reference the targetId. + */ + watch(targetData: TargetData): void; + /** + * Unregisters interest in the results of the target associated with the + * given targetId. + */ + unwatch(targetId: TargetId): void; +} +/** Listener for the PersistentWriteStream */ +export interface WriteStreamListener extends PersistentStreamListener { + /** + * Called by the PersistentWriteStream upon a successful handshake response + * from the server, which is the receiver's cue to send any pending writes. + */ + onHandshakeComplete: () => Promise<void>; + /** + * Called by the PersistentWriteStream upon receiving a StreamingWriteResponse + * from the server that contains a mutation result. + */ + onMutationResult: (commitVersion: SnapshotVersion, results: MutationResult[]) => Promise<void>; +} +/** + * A Stream that implements the Write RPC. + * + * The Write RPC requires the caller to maintain special streamToken + * state in between calls, to help the server understand which responses the + * client has processed by the time the next request is made. Every response + * will contain a streamToken; this value must be passed to the next + * request. + * + * After calling start() on this stream, the next request must be a handshake, + * containing whatever streamToken is on hand. Once a response to this + * request is received, all pending mutations may be submitted. When + * submitting multiple batches of mutations at the same time, it's + * okay to use the same streamToken for the calls to writeMutations. + * + * TODO(b/33271235): Use proto types + */ +export declare class PersistentWriteStream extends PersistentStream<ProtoWriteRequest, ProtoWriteResponse, WriteStreamListener> { + private serializer; + constructor(queue: AsyncQueue, connection: Connection, authCredentials: CredentialsProvider<User>, appCheckCredentials: CredentialsProvider<string>, serializer: JsonProtoSerializer, listener: WriteStreamListener); + /** + * The last received stream token from the server, used to acknowledge which + * responses the client has processed. Stream tokens are opaque checkpoint + * markers whose only real value is their inclusion in the next request. + * + * PersistentWriteStream manages propagating this value from responses to the + * next request. + */ + private lastStreamToken; + /** + * Tracks whether or not a handshake has been successfully exchanged and + * the stream is ready to accept mutations. + */ + get handshakeComplete(): boolean; + start(): void; + protected tearDown(): void; + protected startRpc(authToken: Token | null, appCheckToken: Token | null): Stream<ProtoWriteRequest, ProtoWriteResponse>; + protected onFirst(responseProto: ProtoWriteResponse): Promise<void>; + protected onNext(responseProto: ProtoWriteResponse): Promise<void>; + /** + * Sends an initial streamToken to the server, performing the handshake + * required to make the StreamingWrite RPC work. Subsequent + * calls should wait until onHandshakeComplete was called. + */ + writeHandshake(): void; + /** Sends a group of mutations to the Firestore backend to apply. */ + writeMutations(mutations: Mutation[]): void; +} diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/remote_event.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/remote_event.d.ts new file mode 100644 index 0000000..9bafaf3 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/remote_event.d.ts @@ -0,0 +1,156 @@ +/** + * @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. + */ +import { SnapshotVersion } from '../core/snapshot_version'; +import { TargetId } from '../core/types'; +import { TargetPurpose } from '../local/target_data'; +import { DocumentKeySet, MutableDocumentMap } from '../model/collections'; +import { ByteString } from '../util/byte_string'; +import { SortedMap } from '../util/sorted_map'; +/** + * An event from the RemoteStore. It is split into targetChanges (changes to the + * state or the set of documents in our watched targets) and documentUpdates + * (changes to the actual documents). + */ +export declare class RemoteEvent { + /** + * The snapshot version this event brings us up to, or MIN if not set. + */ + readonly snapshotVersion: SnapshotVersion; + /** + * A map from target to changes to the target. See TargetChange. + */ + readonly targetChanges: Map<TargetId, TargetChange>; + /** + * A map of targets that is known to be inconsistent, and the purpose for + * re-listening. Listens for these targets should be re-established without + * resume tokens. + */ + readonly targetMismatches: SortedMap<TargetId, TargetPurpose>; + /** + * A set of which documents have changed or been deleted, along with the + * doc's new values (if not deleted). + */ + readonly documentUpdates: MutableDocumentMap; + /** + * A set of which document updates are due only to limbo resolution targets. + */ + readonly resolvedLimboDocuments: DocumentKeySet; + constructor( + /** + * The snapshot version this event brings us up to, or MIN if not set. + */ + snapshotVersion: SnapshotVersion, + /** + * A map from target to changes to the target. See TargetChange. + */ + targetChanges: Map<TargetId, TargetChange>, + /** + * A map of targets that is known to be inconsistent, and the purpose for + * re-listening. Listens for these targets should be re-established without + * resume tokens. + */ + targetMismatches: SortedMap<TargetId, TargetPurpose>, + /** + * A set of which documents have changed or been deleted, along with the + * doc's new values (if not deleted). + */ + documentUpdates: MutableDocumentMap, + /** + * A set of which document updates are due only to limbo resolution targets. + */ + resolvedLimboDocuments: DocumentKeySet); + /** + * HACK: Views require RemoteEvents in order to determine whether the view is + * CURRENT, but secondary tabs don't receive remote events. So this method is + * used to create a synthesized RemoteEvent that can be used to apply a + * CURRENT status change to a View, for queries executed in a different tab. + */ + static createSynthesizedRemoteEventForCurrentChange(targetId: TargetId, current: boolean, resumeToken: ByteString): RemoteEvent; +} +/** + * A TargetChange specifies the set of changes for a specific target as part of + * a RemoteEvent. These changes track which documents are added, modified or + * removed, as well as the target's resume token and whether the target is + * marked CURRENT. + * The actual changes *to* documents are not part of the TargetChange since + * documents may be part of multiple targets. + */ +export declare class TargetChange { + /** + * An opaque, server-assigned token that allows watching a query to be resumed + * after disconnecting without retransmitting all the data that matches the + * query. The resume token essentially identifies a point in time from which + * the server should resume sending results. + */ + readonly resumeToken: ByteString; + /** + * The "current" (synced) status of this target. Note that "current" + * has special meaning in the RPC protocol that implies that a target is + * both up-to-date and consistent with the rest of the watch stream. + */ + readonly current: boolean; + /** + * The set of documents that were newly assigned to this target as part of + * this remote event. + */ + readonly addedDocuments: DocumentKeySet; + /** + * The set of documents that were already assigned to this target but received + * an update during this remote event. + */ + readonly modifiedDocuments: DocumentKeySet; + /** + * The set of documents that were removed from this target as part of this + * remote event. + */ + readonly removedDocuments: DocumentKeySet; + constructor( + /** + * An opaque, server-assigned token that allows watching a query to be resumed + * after disconnecting without retransmitting all the data that matches the + * query. The resume token essentially identifies a point in time from which + * the server should resume sending results. + */ + resumeToken: ByteString, + /** + * The "current" (synced) status of this target. Note that "current" + * has special meaning in the RPC protocol that implies that a target is + * both up-to-date and consistent with the rest of the watch stream. + */ + current: boolean, + /** + * The set of documents that were newly assigned to this target as part of + * this remote event. + */ + addedDocuments: DocumentKeySet, + /** + * The set of documents that were already assigned to this target but received + * an update during this remote event. + */ + modifiedDocuments: DocumentKeySet, + /** + * The set of documents that were removed from this target as part of this + * remote event. + */ + removedDocuments: DocumentKeySet); + /** + * This method is used to create a synthesized TargetChanges that can be used to + * apply a CURRENT status change to a View (for queries executed in a different + * tab) or for new queries (to raise snapshots with correct CURRENT status). + */ + static createSynthesizedTargetChangeForCurrentChange(targetId: TargetId, current: boolean, resumeToken: ByteString): TargetChange; +} diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/remote_store.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/remote_store.d.ts new file mode 100644 index 0000000..c6c2416 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/remote_store.d.ts @@ -0,0 +1,85 @@ +/** + * @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. + */ +import { User } from '../auth/user'; +import { OnlineState, TargetId } from '../core/types'; +import { LocalStore } from '../local/local_store'; +import { TargetData } from '../local/target_data'; +import { AsyncQueue } from '../util/async_queue'; +import { ConnectivityMonitor } from './connectivity_monitor'; +import { Datastore } from './datastore'; +import { RemoteSyncer } from './remote_syncer'; +/** + * RemoteStore - An interface to remotely stored data, basically providing a + * wrapper around the Datastore that is more reliable for the rest of the + * system. + * + * RemoteStore is responsible for maintaining the connection to the server. + * - maintaining a list of active listens. + * - reconnecting when the connection is dropped. + * - resuming all the active listens on reconnect. + * + * RemoteStore handles all incoming events from the Datastore. + * - listening to the watch stream and repackaging the events as RemoteEvents + * - notifying SyncEngine of any changes to the active listens. + * + * RemoteStore takes writes from other components and handles them reliably. + * - pulling pending mutations from LocalStore and sending them to Datastore. + * - retrying mutations that failed because of network problems. + * - acking mutations to the SyncEngine once they are accepted or rejected. + */ +export interface RemoteStore { + /** + * SyncEngine to notify of watch and write events. This must be set + * immediately after construction. + */ + remoteSyncer: RemoteSyncer; +} +export declare function newRemoteStore(localStore: LocalStore, datastore: Datastore, asyncQueue: AsyncQueue, onlineStateHandler: (onlineState: OnlineState) => void, connectivityMonitor: ConnectivityMonitor): RemoteStore; +/** Re-enables the network. Idempotent. */ +export declare function remoteStoreEnableNetwork(remoteStore: RemoteStore): Promise<void>; +/** + * Temporarily disables the network. The network can be re-enabled using + * enableNetwork(). + */ +export declare function remoteStoreDisableNetwork(remoteStore: RemoteStore): Promise<void>; +export declare function remoteStoreShutdown(remoteStore: RemoteStore): Promise<void>; +/** + * Starts new listen for the given target. Uses resume token if provided. It + * is a no-op if the target of given `TargetData` is already being listened to. + */ +export declare function remoteStoreListen(remoteStore: RemoteStore, targetData: TargetData): void; +/** + * Removes the listen from server. It is a no-op if the given target id is + * not being listened to. + */ +export declare function remoteStoreUnlisten(remoteStore: RemoteStore, targetId: TargetId): void; +export declare function canUseNetwork(remoteStore: RemoteStore): boolean; +/** + * Attempts to fill our write pipeline with writes from the LocalStore. + * + * Called internally to bootstrap or refill the write pipeline and by + * SyncEngine whenever there are new mutations to process. + * + * Starts the write stream if necessary. + */ +export declare function fillWritePipeline(remoteStore: RemoteStore): Promise<void>; +export declare function outstandingWrites(remoteStore: RemoteStore): number; +export declare function remoteStoreHandleCredentialChange(remoteStore: RemoteStore, user: User): Promise<void>; +/** + * Toggles the network state when the client gains or loses its primary lease. + */ +export declare function remoteStoreApplyPrimaryState(remoteStore: RemoteStore, isPrimary: boolean): Promise<void>; diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/remote_syncer.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/remote_syncer.d.ts new file mode 100644 index 0000000..949bc21 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/remote_syncer.d.ts @@ -0,0 +1,68 @@ +/** + * @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. + */ +import { User } from '../auth/user'; +import { BatchId, TargetId } from '../core/types'; +import { DocumentKeySet } from '../model/collections'; +import { MutationBatchResult } from '../model/mutation_batch'; +import { FirestoreError } from '../util/error'; +import { RemoteEvent } from './remote_event'; +/** + * An interface that describes the actions the RemoteStore needs to perform on + * a cooperating synchronization engine. + */ +export interface RemoteSyncer { + /** + * Applies one remote event to the sync engine, notifying any views of the + * changes, and releasing any pending mutation batches that would become + * visible because of the snapshot version the remote event contains. + */ + applyRemoteEvent?(remoteEvent: RemoteEvent): Promise<void>; + /** + * Rejects the listen for the given targetID. This can be triggered by the + * backend for any active target. + * + * @param targetId - The targetID corresponds to one previously initiated by + * the user as part of TargetData passed to listen() on RemoteStore. + * @param error - A description of the condition that has forced the rejection. + * Nearly always this will be an indication that the user is no longer + * authorized to see the data matching the target. + */ + rejectListen?(targetId: TargetId, error: FirestoreError): Promise<void>; + /** + * Applies the result of a successful write of a mutation batch to the sync + * engine, emitting snapshots in any views that the mutation applies to, and + * removing the batch from the mutation queue. + */ + applySuccessfulWrite?(result: MutationBatchResult): Promise<void>; + /** + * Rejects the batch, removing the batch from the mutation queue, recomputing + * the local view of any documents affected by the batch and then, emitting + * snapshots with the reverted value. + */ + rejectFailedWrite?(batchId: BatchId, error: FirestoreError): Promise<void>; + /** + * Returns the set of remote document keys for the given target ID. This list + * includes the documents that were assigned to the target when we received + * the last snapshot. + */ + getRemoteKeysForTarget?(targetId: TargetId): DocumentKeySet; + /** + * Updates all local state to match the pending mutations for the given user. + * May be called repeatedly for the same user. + */ + handleCredentialChange?(user: User): Promise<void>; +} diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/rest_connection.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/rest_connection.d.ts new file mode 100644 index 0000000..1e58386 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/rest_connection.d.ts @@ -0,0 +1,53 @@ +/** + * @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. + */ +import { Token } from '../api/credentials'; +import { DatabaseId, DatabaseInfo } from '../core/database_info'; +import { ResourcePath } from '../model/path'; +import { StringMap } from '../util/types'; +import { Connection, Stream } from './connection'; +/** + * Base class for all Rest-based connections to the backend (WebChannel and + * HTTP). + */ +export declare abstract class RestConnection implements Connection { + private readonly databaseInfo; + protected readonly databaseId: DatabaseId; + protected readonly baseUrl: string; + private readonly databasePath; + private readonly requestParams; + get shouldResourcePathBeIncludedInRequest(): boolean; + constructor(databaseInfo: DatabaseInfo); + invokeRPC<Req, Resp>(rpcName: string, path: ResourcePath, req: Req, authToken: Token | null, appCheckToken: Token | null): Promise<Resp>; + invokeStreamingRPC<Req, Resp>(rpcName: string, path: ResourcePath, request: Req, authToken: Token | null, appCheckToken: Token | null, expectedResponseCount?: number): Promise<Resp[]>; + abstract openStream<Req, Resp>(rpcName: string, authToken: Token | null, appCheckToken: Token | null): Stream<Req, Resp>; + /** + * Modifies the headers for a request, adding any authorization token if + * present and any additional headers for the request. + */ + protected modifyHeadersForRequest(headers: StringMap, authToken: Token | null, appCheckToken: Token | null): void; + /** + * Performs an RPC request using an implementation specific networking layer. + */ + protected abstract performRPCRequest<Req, Resp>(rpcName: string, url: string, headers: StringMap, body: Req, _forwardCredentials: boolean): Promise<Resp>; + private makeUrl; + /** + * Closes and cleans up any resources associated with the connection. This + * implementation is a no-op because there are no resources associated + * with the RestConnection that need to be cleaned up. + */ + terminate(): void; +} diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/rpc_error.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/rpc_error.d.ts new file mode 100644 index 0000000..90d075c --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/rpc_error.d.ts @@ -0,0 +1,74 @@ +/** + * @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. + */ +import { Code } from '../util/error'; +/** + * Determines whether an error code represents a permanent error when received + * in response to a non-write operation. + * + * See isPermanentWriteError for classifying write errors. + */ +export declare function isPermanentError(code: Code): boolean; +/** + * Determines whether an error code represents a permanent error when received + * in response to a write operation. + * + * Write operations must be handled specially because as of b/119437764, ABORTED + * errors on the write stream should be retried too (even though ABORTED errors + * are not generally retryable). + * + * Note that during the initial handshake on the write stream an ABORTED error + * signals that we should discard our stream token (i.e. it is permanent). This + * means a handshake error should be classified with isPermanentError, above. + */ +export declare function isPermanentWriteError(code: Code): boolean; +/** + * Maps an error Code from a GRPC status identifier like 'NOT_FOUND'. + * + * @returns The Code equivalent to the given status string or undefined if + * there is no match. + */ +export declare function mapCodeFromRpcStatus(status: string): Code | undefined; +/** + * Maps an error Code from GRPC status code number, like 0, 1, or 14. These + * are not the same as HTTP status codes. + * + * @returns The Code equivalent to the given GRPC status code. Fails if there + * is no match. + */ +export declare function mapCodeFromRpcCode(code: number | undefined): Code; +/** + * Maps an RPC code from a Code. This is the reverse operation from + * mapCodeFromRpcCode and should really only be used in tests. + */ +export declare function mapRpcCodeFromCode(code: Code | undefined): number; +/** + * Converts an HTTP Status Code to the equivalent error code. + * + * @param status - An HTTP Status Code, like 200, 404, 503, etc. + * @returns The equivalent Code. Unknown status codes are mapped to + * Code.UNKNOWN. + */ +export declare function mapCodeFromHttpStatus(status?: number): Code; +/** + * Converts an HTTP response's error status to the equivalent error code. + * + * @param status - An HTTP error response status ("FAILED_PRECONDITION", + * "UNKNOWN", etc.) + * @returns The equivalent Code. Non-matching responses are mapped to + * Code.UNKNOWN. + */ +export declare function mapCodeFromHttpResponseErrorStatus(status: string): Code; diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/serializer.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/serializer.d.ts new file mode 100644 index 0000000..bb1aeb9 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/serializer.d.ts @@ -0,0 +1,124 @@ +/** + * @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. + */ +import { Aggregate } from '../core/aggregate'; +import { DatabaseId } from '../core/database_info'; +import { CompositeFilter, CompositeOperator, FieldFilter, Filter, Operator } from '../core/filter'; +import { Direction, OrderBy } from '../core/order_by'; +import { Query } from '../core/query'; +import { SnapshotVersion } from '../core/snapshot_version'; +import { Target } from '../core/target'; +import { Timestamp } from '../lite-api/timestamp'; +import { TargetData, TargetPurpose } from '../local/target_data'; +import { MutableDocument } from '../model/document'; +import { DocumentKey } from '../model/document_key'; +import { FieldMask } from '../model/field_mask'; +import { Mutation, MutationResult } from '../model/mutation'; +import { ObjectValue } from '../model/object_value'; +import { FieldPath, ResourcePath } from '../model/path'; +import { ApiClientObjectMap as ProtoApiClientObjectMap, BatchGetDocumentsResponse as ProtoBatchGetDocumentsResponse, CompositeFilterOp as ProtoCompositeFilterOp, Document as ProtoDocument, DocumentMask as ProtoDocumentMask, DocumentsTarget as ProtoDocumentsTarget, FieldFilterOp as ProtoFieldFilterOp, FieldReference as ProtoFieldReference, Filter as ProtoFilter, ListenResponse as ProtoListenResponse, Order as ProtoOrder, OrderDirection as ProtoOrderDirection, QueryTarget as ProtoQueryTarget, RunAggregationQueryRequest as ProtoRunAggregationQueryRequest, Target as ProtoTarget, Timestamp as ProtoTimestamp, Write as ProtoWrite, WriteResult as ProtoWriteResult } from '../protos/firestore_proto_api'; +import { ByteString } from '../util/byte_string'; +import { Serializer } from './number_serializer'; +import { WatchChange } from './watch_change'; +/** + * This class generates JsonObject values for the Datastore API suitable for + * sending to either GRPC stub methods or via the JSON/HTTP REST API. + * + * The serializer supports both Protobuf.js and Proto3 JSON formats. By + * setting `useProto3Json` to true, the serializer will use the Proto3 JSON + * format. + * + * For a description of the Proto3 JSON format check + * https://developers.google.com/protocol-buffers/docs/proto3#json + * + * TODO(klimt): We can remove the databaseId argument if we keep the full + * resource name in documents. + */ +export declare class JsonProtoSerializer implements Serializer { + readonly databaseId: DatabaseId; + readonly useProto3Json: boolean; + constructor(databaseId: DatabaseId, useProto3Json: boolean); +} +/** + * Returns a value for a Date that's appropriate to put into a proto. + */ +export declare function toTimestamp(serializer: JsonProtoSerializer, timestamp: Timestamp): ProtoTimestamp; +/** + * Returns a Timestamp typed object given protobuf timestamp value. + */ +export declare function fromTimestamp(date: ProtoTimestamp): Timestamp; +/** + * Returns a value for bytes that's appropriate to put in a proto. + * + * Visible for testing. + */ +export declare function toBytes(serializer: JsonProtoSerializer, bytes: ByteString): string | Uint8Array; +/** + * Returns a ByteString based on the proto string value. + */ +export declare function fromBytes(serializer: JsonProtoSerializer, value: string | Uint8Array | undefined): ByteString; +export declare function toVersion(serializer: JsonProtoSerializer, version: SnapshotVersion): ProtoTimestamp; +export declare function fromVersion(version: ProtoTimestamp): SnapshotVersion; +export declare function toResourceName(databaseId: DatabaseId, path: ResourcePath): string; +export declare function toResourcePath(databaseId: DatabaseId, path?: ResourcePath): ResourcePath; +export declare function toName(serializer: JsonProtoSerializer, key: DocumentKey): string; +export declare function fromName(serializer: JsonProtoSerializer, name: string): DocumentKey; +export declare function getEncodedDatabaseId(serializer: JsonProtoSerializer): string; +/** Creates a Document proto from key and fields (but no create/update time) */ +export declare function toMutationDocument(serializer: JsonProtoSerializer, key: DocumentKey, fields: ObjectValue): ProtoDocument; +export declare function toDocument(serializer: JsonProtoSerializer, document: MutableDocument): ProtoDocument; +export declare function fromDocument(serializer: JsonProtoSerializer, document: ProtoDocument, hasCommittedMutations?: boolean): MutableDocument; +export declare function fromBatchGetDocumentsResponse(serializer: JsonProtoSerializer, result: ProtoBatchGetDocumentsResponse): MutableDocument; +export declare function fromWatchChange(serializer: JsonProtoSerializer, change: ProtoListenResponse): WatchChange; +export declare function versionFromListenResponse(change: ProtoListenResponse): SnapshotVersion; +export declare function toMutation(serializer: JsonProtoSerializer, mutation: Mutation): ProtoWrite; +export declare function fromMutation(serializer: JsonProtoSerializer, proto: ProtoWrite): Mutation; +export declare function fromWriteResults(protos: ProtoWriteResult[] | undefined, commitTime?: ProtoTimestamp): MutationResult[]; +export declare function toDocumentsTarget(serializer: JsonProtoSerializer, target: Target): ProtoDocumentsTarget; +export declare function fromDocumentsTarget(documentsTarget: ProtoDocumentsTarget): Target; +export declare function toQueryTarget(serializer: JsonProtoSerializer, target: Target): { + queryTarget: ProtoQueryTarget; + parent: ResourcePath; +}; +export declare function toRunAggregationQueryRequest(serializer: JsonProtoSerializer, target: Target, aggregates: Aggregate[], skipAliasing?: boolean): { + request: ProtoRunAggregationQueryRequest; + aliasMap: Record<string, string>; + parent: ResourcePath; +}; +export declare function convertQueryTargetToQuery(target: ProtoQueryTarget): Query; +export declare function fromQueryTarget(target: ProtoQueryTarget): Target; +export declare function toListenRequestLabels(serializer: JsonProtoSerializer, targetData: TargetData): ProtoApiClientObjectMap<string> | null; +export declare function toLabel(purpose: TargetPurpose): string | null; +export declare function toTarget(serializer: JsonProtoSerializer, targetData: TargetData): ProtoTarget; +export declare function toDirection(dir: Direction): ProtoOrderDirection; +export declare function fromDirection(dir: ProtoOrderDirection | undefined): Direction | undefined; +export declare function toOperatorName(op: Operator): ProtoFieldFilterOp; +export declare function toCompositeOperatorName(op: CompositeOperator): ProtoCompositeFilterOp; +export declare function fromOperatorName(op: ProtoFieldFilterOp): Operator; +export declare function fromCompositeOperatorName(op: ProtoCompositeFilterOp): CompositeOperator; +export declare function toFieldPathReference(path: FieldPath): ProtoFieldReference; +export declare function fromFieldPathReference(fieldReference: ProtoFieldReference): FieldPath; +export declare function toPropertyOrder(orderBy: OrderBy): ProtoOrder; +export declare function fromPropertyOrder(orderBy: ProtoOrder): OrderBy; +export declare function toFilter(filter: Filter): ProtoFilter; +export declare function toCompositeFilter(filter: CompositeFilter): ProtoFilter; +export declare function toUnaryOrFieldFilter(filter: FieldFilter): ProtoFilter; +export declare function fromUnaryFilter(filter: ProtoFilter): Filter; +export declare function fromFieldFilter(filter: ProtoFilter): FieldFilter; +export declare function fromCompositeFilter(filter: ProtoFilter): CompositeFilter; +export declare function toDocumentMask(fieldMask: FieldMask): ProtoDocumentMask; +export declare function fromDocumentMask(proto: ProtoDocumentMask): FieldMask; +export declare function isValidResourceName(path: ResourcePath): boolean; diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/stream_bridge.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/stream_bridge.d.ts new file mode 100644 index 0000000..f17a080 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/stream_bridge.d.ts @@ -0,0 +1,45 @@ +/** + * @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. + */ +import { FirestoreError } from '../util/error'; +import { Stream } from './connection'; +/** + * Provides a simple helper class that implements the Stream interface to + * bridge to other implementations that are streams but do not implement the + * interface. The stream callbacks are invoked with the callOn... methods. + */ +export declare class StreamBridge<I, O> implements Stream<I, O> { + private wrappedOnConnected; + private wrappedOnOpen; + private wrappedOnClose; + private wrappedOnMessage; + private sendFn; + private closeFn; + constructor(args: { + sendFn: (msg: I) => void; + closeFn: () => void; + }); + onConnected(callback: () => void): void; + onOpen(callback: () => void): void; + onClose(callback: (err?: FirestoreError) => void): void; + onMessage(callback: (msg: O) => void): void; + close(): void; + send(msg: I): void; + callOnConnected(): void; + callOnOpen(): void; + callOnClose(err?: FirestoreError): void; + callOnMessage(msg: O): void; +} diff --git a/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/watch_change.d.ts b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/watch_change.d.ts new file mode 100644 index 0000000..1510515 --- /dev/null +++ b/frontend-old/node_modules/@firebase/firestore/dist/firestore/src/remote/watch_change.d.ts @@ -0,0 +1,231 @@ +/** + * @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. + */ +import { DatabaseId } from '../core/database_info'; +import { SnapshotVersion } from '../core/snapshot_version'; +import { TargetId } from '../core/types'; +import { TargetData } from '../local/target_data'; +import { DocumentKeySet } from '../model/collections'; +import { MutableDocument } from '../model/document'; +import { DocumentKey } from '../model/document_key'; +import { ByteString } from '../util/byte_string'; +import { FirestoreError } from '../util/error'; +import { ExistenceFilter } from './existence_filter'; +import { RemoteEvent } from './remote_event'; +/** + * Internal representation of the watcher API protocol buffers. + */ +export type WatchChange = DocumentWatchChange | WatchTargetChange | ExistenceFilterChange; +/** + * Represents a changed document and a list of target ids to which this change + * applies. + * + * If document has been deleted NoDocument will be provided. + */ +export declare class DocumentWatchChange { + /** The new document applies to all of these targets. */ + updatedTargetIds: TargetId[]; + /** The new document is removed from all of these targets. */ + removedTargetIds: TargetId[]; + /** The key of the document for this change. */ + key: DocumentKey; + /** + * The new document or NoDocument if it was deleted. Is null if the + * document went out of view without the server sending a new document. + */ + newDoc: MutableDocument | null; + constructor( + /** The new document applies to all of these targets. */ + updatedTargetIds: TargetId[], + /** The new document is removed from all of these targets. */ + removedTargetIds: TargetId[], + /** The key of the document for this change. */ + key: DocumentKey, + /** + * The new document or NoDocument if it was deleted. Is null if the + * document went out of view without the server sending a new document. + */ + newDoc: MutableDocument | null); +} +export declare class ExistenceFilterChange { + targetId: TargetId; + existenceFilter: ExistenceFilter; + constructor(targetId: TargetId, existenceFilter: ExistenceFilter); +} +export declare const enum WatchTargetChangeState { + NoChange = 0, + Added = 1, + Removed = 2, + Current = 3, + Reset = 4 +} +export declare class WatchTargetChange { + /** What kind of change occurred to the watch target. */ + state: WatchTargetChangeState; + /** The target IDs that were added/removed/set. */ + targetIds: TargetId[]; + /** + * An opaque, server-assigned token that allows watching a target to be + * resumed after disconnecting without retransmitting all the data that + * matches the target. The resume token essentially identifies a point in + * time from which the server should resume sending results. + */ + resumeToken: ByteString; + /** An RPC error indicating why the watch failed. */ + cause: FirestoreError | null; + constructor( + /** What kind of change occurred to the watch target. */ + state: WatchTargetChangeState, + /** The target IDs that were added/removed/set. */ + targetIds: TargetId[], + /** + * An opaque, server-assigned token that allows watching a target to be + * resumed after disconnecting without retransmitting all the data that + * matches the target. The resume token essentially identifies a point in + * time from which the server should resume sending results. + */ + resumeToken?: ByteString, + /** An RPC error indicating why the watch failed. */ + cause?: FirestoreError | null); +} +/** + * Interface implemented by RemoteStore to expose target metadata to the + * WatchChangeAggregator. + */ +export interface TargetMetadataProvider { + /** + * Returns the set of remote document keys for the given target ID as of the + * last raised snapshot. + */ + getRemoteKeysForTarget(targetId: TargetId): DocumentKeySet; + /** + * Returns the TargetData for an active target ID or 'null' if this target + * has become inactive + */ + getTargetDataForTarget(targetId: TargetId): TargetData | null; + /** + * Returns the database ID of the Firestore instance. + */ + getDatabaseId(): DatabaseId; +} +/** + * A helper class to accumulate watch changes into a RemoteEvent. + */ +export declare class WatchChangeAggregator { + private metadataProvider; + constructor(metadataProvider: TargetMetadataProvider); + /** The internal state of all tracked targets. */ + private targetStates; + /** Keeps track of the documents to update since the last raised snapshot. */ + private pendingDocumentUpdates; + private pendingDocumentUpdatesByTarget; + /** A mapping of document keys to their set of target IDs. */ + private pendingDocumentTargetMapping; + /** + * A map of targets with existence filter mismatches. These targets are + * known to be inconsistent and their listens needs to be re-established by + * RemoteStore. + */ + private pendingTargetResets; + /** + * Processes and adds the DocumentWatchChange to the current set of changes. + */ + handleDocumentChange(docChange: DocumentWatchChange): void; + /** Processes and adds the WatchTargetChange to the current set of changes. */ + handleTargetChange(targetChange: WatchTargetChange): void; + /** + * Iterates over all targetIds that the watch change applies to: either the + * targetIds explicitly listed in the change or the targetIds of all currently + * active targets. + */ + forEachTarget(targetChange: WatchTargetChange, fn: (targetId: TargetId) => void): void; + /** + * Handles existence filters and synthesizes deletes for filter mismatches. + * Targets that are invalidated by filter mismatches are added to + * `pendingTargetResets`. + */ + handleExistenceFilter(watchChange: ExistenceFilterChange): void; + /** + * Parse the bloom filter from the "unchanged_names" field of an existence + * filter. + */ + private parseBloomFilter; + /** + * Apply bloom filter to remove the deleted documents, and return the + * application status. + */ + private applyBloomFilter; + /** + * Filter out removed documents based on bloom filter membership result and + * return number of documents removed. + */ + private filterRemovedDocuments; + /** + * Converts the currently accumulated state into a remote event at the + * provided snapshot version. Resets the accumulated changes before returning. + */ + createRemoteEvent(snapshotVersion: SnapshotVersion): RemoteEvent; + /** + * Adds the provided document to the internal list of document updates and + * its document key to the given target's mapping. + */ + addDocumentToTarget(targetId: TargetId, document: MutableDocument): void; + /** + * Removes the provided document from the target mapping. If the + * document no longer matches the target, but the document's state is still + * known (e.g. we know that the document was deleted or we received the change + * that caused the filter mismatch), the new document can be provided + * to update the remote document cache. + */ + removeDocumentFromTarget(targetId: TargetId, key: DocumentKey, updatedDocument: MutableDocument | null): void; + removeTarget(targetId: TargetId): void; + /** + * Returns the current count of documents in the target. This includes both + * the number of documents that the LocalStore considers to be part of the + * target as well as any accumulated changes. + */ + private getCurrentDocumentCountForTarget; + /** + * Increment the number of acks needed from watch before we can consider the + * server to be 'in-sync' with the client's active targets. + */ + recordPendingTargetRequest(targetId: TargetId): void; + private ensureTargetState; + private ensureDocumentTargetMapping; + private ensureDocumentUpdateByTarget; + /** + * Verifies that the user is still interested in this target (by calling + * `getTargetDataForTarget()`) and that we are not waiting for pending ADDs + * from watch. + */ + protected isActiveTarget(targetId: TargetId): boolean; + /** + * Returns the TargetData for an active target (i.e. a target that the user + * is still interested in that has no outstanding target change requests). + */ + protected targetDataForActiveTarget(targetId: TargetId): TargetData | null; + /** + * Resets the state of a Watch target to its initial state (e.g. sets + * 'current' to false, clears the resume token and removes its target mapping + * from all documents). + */ + private resetTarget; + /** + * Returns whether the LocalStore considers the document to be part of the + * specified target. + */ + private targetContainsDocument; +} |
