1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-06-17 17:06:00 +00:00
This commit is contained in:
MatteZ02
2020-03-03 22:30:50 +02:00
parent edfcc6f474
commit 30022c7634
11800 changed files with 1984416 additions and 1 deletions

View File

@ -0,0 +1,46 @@
/**
* @license
* Copyright 2017 Google Inc.
*
* 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 { CollectionReference, DocumentReference, DocumentSnapshot, Firestore, Query, QuerySnapshot } from '../../src/api/database';
import { DocumentKeySet } from '../../src/model/collections';
import { JsonObject } from '../../src/model/field_value';
/**
* A mock Firestore. Will not work for integration test.
*/
export declare const FIRESTORE: Firestore;
export declare function firestore(): Firestore;
export declare function collectionReference(path: string): CollectionReference;
export declare function documentReference(path: string): DocumentReference;
export declare function documentSnapshot(path: string, data: JsonObject<unknown> | null, fromCache: boolean): DocumentSnapshot;
export declare function query(path: string): Query;
/**
* A convenience method for creating a particular query snapshot for tests.
*
* @param path To be used in constructing the query.
* @param oldDocs Provides the prior set of documents in the QuerySnapshot. Each entry maps to a
* document, with the key being the document id, and the value being the document contents.
* @param docsToAdd Specifies data to be added into the query snapshot as of now. Each entry maps
* to a document, with the key being the document id, and the value being the document contents.
* @param mutatedKeys The list of document with pending writes.
* @param fromCache Whether the query snapshot is cache result.
* @param syncStateChanged Whether the sync state has changed.
* @return A query snapshot that consists of both sets of documents.
*/
export declare function querySnapshot(path: string, oldDocs: {
[key: string]: JsonObject<unknown>;
}, docsToAdd: {
[key: string]: JsonObject<unknown>;
}, mutatedKeys: DocumentKeySet, fromCache: boolean, syncStateChanged: boolean): QuerySnapshot;

View File

@ -0,0 +1,25 @@
/**
* @license
* Copyright 2017 Google Inc.
*
* 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.
*/
/**
* Duck-typed interface for objects that have an isEqual() method.
*
* Note: This is copied from src/util/misc.ts to avoid importing private types.
*/
export interface Equatable<T> {
isEqual(other: T): boolean;
}
export declare function addEqualityMatcher(): void;

View File

@ -0,0 +1,151 @@
/**
* @license
* Copyright 2017 Google Inc.
*
* 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 * as firestore from '@firebase/firestore-types';
import { Blob } from '../../src/api/blob';
import { DocumentKeyReference } from '../../src/api/user_data_converter';
import { DatabaseId } from '../../src/core/database_info';
import { Bound, FieldFilter, OrderBy } from '../../src/core/query';
import { SnapshotVersion } from '../../src/core/snapshot_version';
import { ProtoByteString, TargetId } from '../../src/core/types';
import { LimboDocumentChange, View, ViewChange } from '../../src/core/view';
import { LocalViewChanges } from '../../src/local/local_view_changes';
import { TargetData, TargetPurpose } from '../../src/local/target_data';
import { DocumentKeySet, MaybeDocumentMap } from '../../src/model/collections';
import { Document, DocumentOptions, MaybeDocument, NoDocument, UnknownDocument } from '../../src/model/document';
import { DocumentComparator } from '../../src/model/document_comparator';
import { DocumentKey } from '../../src/model/document_key';
import { DocumentSet } from '../../src/model/document_set';
import { FieldValue, JsonObject, ObjectValue } from '../../src/model/field_value';
import { DeleteMutation, FieldMask, MutationResult, PatchMutation, Precondition, SetMutation, TransformMutation } from '../../src/model/mutation';
import { FieldPath, ResourcePath } from '../../src/model/path';
import { RemoteEvent, TargetChange } from '../../src/remote/remote_event';
import { Dict } from '../../src/util/obj';
import { SortedMap } from '../../src/util/sorted_map';
import { SortedSet } from '../../src/util/sorted_set';
export declare type TestSnapshotVersion = number;
/**
* A string sentinel that can be used with patchMutation() to mark a field for
* deletion.
*/
export declare const DELETE_SENTINEL = "<DELETE>";
export declare function version(v: TestSnapshotVersion): SnapshotVersion;
export declare function ref(dbIdStr: string, keyStr: string, offset?: number): DocumentKeyReference;
export declare function doc(keyStr: string, ver: TestSnapshotVersion, json: JsonObject<unknown>, options?: DocumentOptions): Document;
export declare function deletedDoc(keyStr: string, ver: TestSnapshotVersion, options?: DocumentOptions): NoDocument;
export declare function unknownDoc(keyStr: string, ver: TestSnapshotVersion): UnknownDocument;
export declare function removedDoc(keyStr: string): NoDocument;
export declare function wrap(value: unknown): FieldValue;
export declare function wrapObject(obj: JsonObject<unknown>): ObjectValue;
export declare function dbId(project: string, database?: string): DatabaseId;
export declare function key(path: string): DocumentKey;
export declare function keys(...documents: Array<MaybeDocument | string>): DocumentKeySet;
export declare function path(path: string, offset?: number): ResourcePath;
export declare function field(path: string): FieldPath;
export declare function mask(...paths: string[]): FieldMask;
export declare function blob(...bytes: number[]): Blob;
export declare function filter(path: string, op: string, value: unknown): FieldFilter;
export declare function setMutation(keyStr: string, json: JsonObject<unknown>): SetMutation;
export declare function patchMutation(keyStr: string, json: JsonObject<unknown>, precondition?: Precondition): PatchMutation;
export declare function deleteMutation(keyStr: string): DeleteMutation;
/**
* Creates a TransformMutation by parsing any FieldValue sentinels in the
* provided data. The data is expected to use dotted-notation for nested fields
* (i.e. { "foo.bar": FieldValue.foo() } and must not contain any non-sentinel
* data.
*/
export declare function transformMutation(keyStr: string, data: Dict<unknown>): TransformMutation;
export declare function mutationResult(testVersion: TestSnapshotVersion): MutationResult;
export declare function bound(values: Array<[string, {}, firestore.OrderByDirection]>, before: boolean): Bound;
export declare function targetData(targetId: TargetId, queryPurpose: TargetPurpose, path: string): TargetData;
export declare function noChangeEvent(targetId: number, snapshotVersion: number, resumeToken?: ProtoByteString): RemoteEvent;
export declare function docAddedRemoteEvent(docOrDocs: MaybeDocument | MaybeDocument[], updatedInTargets?: TargetId[], removedFromTargets?: TargetId[], activeTargets?: TargetId[]): RemoteEvent;
export declare function docUpdateRemoteEvent(doc: MaybeDocument, updatedInTargets?: TargetId[], removedFromTargets?: TargetId[], limboTargets?: TargetId[]): RemoteEvent;
export declare function updateMapping(snapshotVersion: SnapshotVersion, added: Array<Document | string>, modified: Array<Document | string>, removed: Array<MaybeDocument | string>, current?: boolean): TargetChange;
export declare function addTargetMapping(...docsOrKeys: Array<Document | string>): TargetChange;
export declare function ackTarget(...docsOrKeys: Array<Document | string>): TargetChange;
export declare function limboChanges(changes: {
added?: Document[];
removed?: Document[];
}): LimboDocumentChange[];
export declare function localViewChanges(targetId: TargetId, fromCache: boolean, changes: {
added?: string[];
removed?: string[];
}): LocalViewChanges;
/** Creates a resume token to match the given snapshot version. */
export declare function resumeTokenForSnapshot(snapshotVersion: SnapshotVersion): ProtoByteString;
export declare function orderBy(path: string, op?: string): OrderBy;
/**
* Converts a sorted map to an array with inorder traversal
*/
export declare function mapAsArray<K, V>(sortedMap: SortedMap<K, V>): Array<{
key: K;
value: V;
}>;
/**
* Converts a list of documents or document keys to a sorted map. A document
* key is used to represent a deletion and maps to null.
*/
export declare function documentUpdates(...docsOrKeys: Array<Document | DocumentKey>): MaybeDocumentMap;
/**
* Short for view.applyChanges(view.computeDocChanges(documentUpdates(docs))).
*/
export declare function applyDocChanges(view: View, ...docsOrKeys: Array<Document | DocumentKey>): ViewChange;
/**
* Constructs a document set.
*/
export declare function documentSet(comp: DocumentComparator, ...docs: Document[]): DocumentSet;
export declare function documentSet(...docs: Document[]): DocumentSet;
/**
* Constructs a document key set.
*/
export declare function keySet(...keys: DocumentKey[]): DocumentKeySet;
/** Converts a DocumentSet to an array. */
export declare function documentSetAsArray(docs: DocumentSet): Document[];
export declare class DocComparator {
static byField(...fields: string[]): DocumentComparator;
}
/**
* Two helper functions to simplify testing isEqual() method.
*/
export declare function expectEqual(left: any, right: any, message?: string): void;
export declare function expectNotEqual(left: any, right: any, message?: string): void;
export declare function expectEqualArrays(left: unknown[], right: unknown[], message?: string): void;
/**
* Checks that an ordered array of elements yields the correct pair-wise
* comparison result for the supplied comparator
*/
export declare function expectCorrectComparisons<T extends unknown>(array: T[], comp: (left: T, right: T) => number): void;
/**
* Takes an array of "equality group" arrays and asserts that the comparator
* returns the same as comparing the indexes of the "equality groups"
* (0 for items in the same group).
*/
export declare function expectCorrectComparisonGroups<T extends unknown>(groups: T[][], comp: (left: T, right: T) => number): void;
/** Compares SortedSet to an array */
export declare function expectSetToEqual<T>(set: SortedSet<T>, arr: T[]): void;
/**
* Takes an array of array of elements and compares each of the elements
* to every other element.
*
* Elements in the same inner array are expect to be equal with regard to
* the provided equality function to all other elements from the same array
* (including itself) and unequal to all other elements from the other array
*/
export declare function expectEqualitySets<T>(elems: T[][], equalityFn: (v1: T, v2: T) => boolean): void;
/** Returns the number of keys in this object. */
export declare function size(obj: JsonObject<unknown>): number;
export declare function expectFirestoreError(err: Error): void;

View File

@ -0,0 +1,17 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* 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 {};

View File

@ -0,0 +1,28 @@
/**
* @license
* Copyright 2017 Google Inc.
*
* 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 interface Resolver<R> {
(value?: R | Promise<R>): void;
}
export interface Rejecter {
(reason?: Error): void;
}
export declare class Deferred<R> {
promise: Promise<R>;
resolve: Resolver<R>;
reject: Rejecter;
constructor();
}

View File

@ -0,0 +1,85 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* 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, DatabaseInfo } from '../../src/core/database_info';
import { ProtoByteString } from '../../src/core/types';
import { Platform } from '../../src/platform/platform';
import { Connection } from '../../src/remote/connection';
import { JsonProtoSerializer } from '../../src/remote/serializer';
import { ConnectivityMonitor } from './../../src/remote/connectivity_monitor';
/**
* `Window` fake that implements the event and storage API that is used by
* Firestore.
*/
export declare class FakeWindow {
private readonly fakeStorageArea;
private readonly fakeIndexedDb;
private storageListeners;
constructor(sharedFakeStorage: SharedFakeWebStorage, fakeIndexedDb?: IDBFactory);
get localStorage(): Storage;
get indexedDB(): IDBFactory | null;
addEventListener(type: string, listener: EventListener): void;
removeEventListener(type: string, listener: EventListener): void;
}
/**
* `Document` fake that implements the `visibilitychange` API used by Firestore.
*/
export declare class FakeDocument {
private _visibilityState;
private visibilityListener;
get visibilityState(): VisibilityState;
addEventListener(type: string, listener: EventListener): void;
removeEventListener(type: string, listener: EventListener): void;
raiseVisibilityEvent(visibility: VisibilityState): void;
}
/**
* `WebStorage` mock that implements the WebStorage behavior for multiple
* clients. To get a client-specific storage area that implements the WebStorage
* API, invoke `getStorageArea(storageListener)`.
*/
export declare class SharedFakeWebStorage {
private readonly data;
private readonly activeClients;
getStorageArea(storageListener: EventListener): Storage;
private clear;
private getItem;
private key;
private removeItem;
private setItem;
private get length();
private raiseStorageEvent;
}
/**
* Implementation of `Platform` that allows faking of `document` and `window`.
*/
export declare class TestPlatform implements Platform {
private readonly basePlatform;
private readonly mockStorage;
readonly mockDocument: FakeDocument | null;
readonly mockWindow: FakeWindow | null;
constructor(basePlatform: Platform, mockStorage: SharedFakeWebStorage);
get document(): Document | null;
get window(): Window | null;
get base64Available(): boolean;
get emptyByteString(): ProtoByteString;
raiseVisibilityEvent(visibility: VisibilityState): void;
loadConnection(databaseInfo: DatabaseInfo): Promise<Connection>;
newConnectivityMonitor(): ConnectivityMonitor;
newSerializer(databaseId: DatabaseId): JsonProtoSerializer;
formatJSON(value: unknown): string;
atob(encoded: string): string;
btoa(raw: string): string;
}