UNPKG

@firestore-emulator/server

Version:

This package is the implementation of the Firestore emulator. It is a Node.js

190 lines 8.1 kB
import { Document as v1Document } from "@firestore-emulator/proto/dist/google/firestore/v1/document"; import type { ListenRequest as v1ListenRequest } from "@firestore-emulator/proto/dist/google/firestore/v1/firestore"; import { ListenResponse as v1ListenResponse } from "@firestore-emulator/proto/dist/google/firestore/v1/firestore"; import type { StructuredQuery as v1StructuredQuery } from "@firestore-emulator/proto/dist/google/firestore/v1/query"; import type { DocumentTransformFieldTransform as v1DocumentTransformFieldTransform, Write as v1Write } from "@firestore-emulator/proto/dist/google/firestore/v1/write"; import { WriteResult as v1WriteResult } from "@firestore-emulator/proto/dist/google/firestore/v1/write"; import { Timestamp } from "@firestore-emulator/proto/dist/google/protobuf/timestamp"; import type { TypeSafeEventEmitter } from "typesafe-event-emitter"; import type { FirestoreStateDocumentFields } from "./field"; interface Events { "add-collection": { collection: FirestoreStateCollection; }; "add-database": { database: FirestoreStateDatabase; }; "add-document": { document: FirestoreStateDocument; }; "add-project": { project: FirestoreStateProject; }; "clear-all-projects": Record<string, never>; "create-document": { document: FirestoreStateDocument; }; "delete-document": { document: FirestoreStateDocument; }; "update-document": { document: FirestoreStateDocument; }; } export interface HasCollections { getCollection(collectionName: string): FirestoreStateCollection; getPath(): string; } type FirestoreStateDocumentMetadata = { createdAt: null; hasExist: false; updatedAt: null; } | { createdAt: Date; hasExist: true; updatedAt: Date; }; export declare class FirestoreStateDocument implements HasCollections { private emitter; readonly database: FirestoreStateDatabase; readonly parent: FirestoreStateCollection; readonly name: string; private fields; private collections; metadata: FirestoreStateDocumentMetadata; constructor(emitter: TypeSafeEventEmitter<Events>, database: FirestoreStateDatabase, parent: FirestoreStateCollection, name: string, fields: Record<string, FirestoreStateDocumentFields>, collections: Record<string, FirestoreStateCollection>); iterateFromRoot(): FirestoreStateDocument[]; hasChild(): boolean; getCollection(collectionName: string): FirestoreStateCollection; toV1Document(): v1Document; toV1DocumentObject(): ReturnType<typeof v1Document.prototype.toObject>; toJSON(): { collections: Record<string, ReturnType<FirestoreStateCollection["toJSON"]>>; fields: Record<string, ReturnType<FirestoreStateDocumentFields["toJSON"]>>; path: string; }; create(date: Date, fields: Record<string, FirestoreStateDocumentFields>): void; update(date: Date, fields: Record<string, FirestoreStateDocumentFields>, updateMask?: string[]): void; set(date: Date, fields: Record<string, FirestoreStateDocumentFields>, updateMask?: string[]): void; delete(): void; getField(path: string): FirestoreStateDocumentFields | undefined; getPath(): string; getDocumentPath(): string; v1Transform(date: Date, transforms: v1DocumentTransformFieldTransform[]): void; } export declare class FirestoreStateCollection { private emitter; readonly database: FirestoreStateDatabase; readonly parent: FirestoreStateDocument | FirestoreStateDatabase; readonly name: string; private documents; constructor(emitter: TypeSafeEventEmitter<Events>, database: FirestoreStateDatabase, parent: FirestoreStateDocument | FirestoreStateDatabase, name: string, documents: Record<string, FirestoreStateDocument>); getDocument(documentName: string): FirestoreStateDocument; hasChild(): boolean; getAllDocuments(): FirestoreStateDocument[]; toJSON(): { documents: { [k: string]: { collections: Record<string, ReturnType<FirestoreStateCollection["toJSON"]>>; fields: Record<string, ReturnType<FirestoreStateDocumentFields["toJSON"]>>; path: string; }; }; path: string; }; getPath(): string; getDocumentPath(): string; } export declare class FirestoreStateDatabase implements HasCollections { private emitter; readonly project: FirestoreStateProject; readonly name: string; private collections; constructor(emitter: TypeSafeEventEmitter<Events>, project: FirestoreStateProject, name: string, collections: Record<string, FirestoreStateCollection>); getCollection(collectionName: string): FirestoreStateCollection; toJSON(): { collections: { [k: string]: { documents: { [k: string]: { collections: Record<string, ReturnType<FirestoreStateCollection["toJSON"]>>; fields: Record<string, ReturnType<FirestoreStateDocumentFields["toJSON"]>>; path: string; }; }; path: string; }; }; path: string; }; getPath(): string; } export declare class FirestoreStateProject { private emitter; readonly name: string; private databases; constructor(emitter: TypeSafeEventEmitter<Events>, name: string, databases: Record<string, FirestoreStateDatabase>); toJSON(): { databases: { [k: string]: { collections: { [k: string]: { documents: { [k: string]: { collections: Record<string, ReturnType<FirestoreStateCollection["toJSON"]>>; fields: Record<string, ReturnType<FirestoreStateDocumentFields["toJSON"]>>; path: string; }; }; path: string; }; }; path: string; }; }; path: string; }; getPath(): string; getDatabase(databaseName: string): FirestoreStateDatabase; } export declare const TimestampFromDate: (date: Date) => Timestamp; export declare const DateFromTimestamp: (timestamp: Timestamp) => Date; export declare const TimestampFromNow: () => Timestamp; export declare class FirestoreState { private projects; readonly emitter: TypeSafeEventEmitter<Events>; constructor(projects?: Record<string, FirestoreStateProject>); toJSON(): { projects: { [k: string]: { databases: { [k: string]: { collections: { [k: string]: { documents: { [k: string]: { collections: Record<string, ReturnType<FirestoreStateCollection["toJSON"]>>; fields: Record<string, ReturnType<FirestoreStateDocumentFields["toJSON"]>>; path: string; }; }; path: string; }; }; path: string; }; }; path: string; }; }; }; getProject(projectName: string): FirestoreStateProject; getCollection(path: string): FirestoreStateCollection; getDocument(path: string): FirestoreStateDocument; clear(): void; writeV1Document(date: Date, write: v1Write): v1WriteResult; v1Query(parent: string, query: v1StructuredQuery): FirestoreStateDocument[]; v1Listen(listen: v1ListenRequest, callback: (response: v1ListenResponse) => void, onEnd: (handler: () => void) => void): void; } export {}; //# sourceMappingURL=index.d.ts.map