simplyfire
Version:
A lightweight firestore api for firebase cloud functions & Angular.
142 lines (135 loc) • 6.21 kB
TypeScript
import * as _firebase_firestore from '@firebase/firestore';
import { Firestore, SetOptions as SetOptions$1, DocumentData as DocumentData$1, Transaction as Transaction$1, QuerySnapshot as QuerySnapshot$1, DocumentChangeType } from '@angular/fire/firestore';
import { Observable } from 'rxjs';
import { FieldPath, WhereFilterOp, OrderByDirection, DocumentSnapshot, CollectionReference, DocumentData, Query, QuerySnapshot, DocumentReference, SetOptions, Transaction, WriteBatch, FieldValue } from '@firebase/firestore-types';
import * as i0 from '@angular/core';
type QueryWhere = [fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown];
type QueryOrderBy = [fieldPath: string | FieldPath, directionStr?: OrderByDirection];
type QueryLeftJoin = [idField: string, collection: string, alias: string];
type QueryCursor = [snapshot: DocumentSnapshot<unknown>] | unknown[];
declare class QueryBuilder {
private _where;
private _orderBy;
private _leftJoins;
private _limit?;
private _limitToLast?;
private _startAt?;
private _startAfter?;
private _endAt?;
private _endBefore?;
get joins(): QueryLeftJoin[];
where(...where: QueryWhere): this;
orderBy(...orderBy: QueryOrderBy): this;
leftJoin(...leftJoin: QueryLeftJoin): void;
limit(limit: number): this;
limitToLast(limitToLast: number): this;
startAt(...startAt: QueryCursor): this;
startAfter(...startAfter: QueryCursor): this;
endAt(...endAt: QueryCursor): this;
endBefore(...endBefore: QueryCursor): this;
exec(ref: CollectionReference<DocumentData> | any, queryOps?: {
[key: string]: any;
}): Query<DocumentData> | any;
private execQueryForCloud;
}
declare abstract class AbstractFirestoreApi {
BATCH_MAX_WRITES: number;
abstract collection<T = any>(path: string, qb?: QueryBuilder, maxAge?: number): Promise<T[]>;
abstract collectionGroup<T = any>(collectionId: string, qb?: QueryBuilder, maxAge?: number): Promise<T[]>;
abstract collectionSnapshot(path: string, qb?: QueryBuilder): Promise<QuerySnapshot<DocumentData>>;
abstract doc<T = any>(path: string, maxAge?: number): Promise<T>;
abstract docRef(docPath: string): DocumentReference<DocumentData>;
abstract upsert(collection: string, data: {
[key: string]: any;
}, opts?: SetOptions): Promise<string>;
abstract update(docPath: string, data: {
[key: string]: any;
}): Promise<void>;
abstract delete(docPath: string): Promise<void>;
abstract bulkUpsert(collection: string, data: DocumentData[] | {
data: DocumentData;
qb?: QueryBuilder;
}, opts?: SetOptions): Promise<string[]>;
abstract bulkDelete(collection: string, qb?: QueryBuilder): Promise<string[]>;
abstract runTransaction(updateFunction: (transaction: Transaction) => Promise<unknown>): Promise<unknown>;
abstract get batch(): WriteBatch;
abstract get serverTimestamp(): FieldValue;
abstract increment(n?: number): FieldValue;
abstract createId(collection?: string): string;
getValueFromSnapshot<T = any>(snapshot: DocumentSnapshot): T;
}
declare class FirestoreService extends AbstractFirestoreApi {
private injector;
private run;
get firestore(): Firestore;
private cache;
collection<T = any>(path: string, qb?: QueryBuilder, maxAge?: number): Promise<T[]>;
collectionGroup<T = any>(collectionId: string, qb?: QueryBuilder, maxAge?: number): Promise<T[]>;
doc<T = any>(path: string, maxAge?: number): Promise<T>;
docRef(path: string): any;
upsert(collectionPath: string, data: {
[key: string]: any;
}, opts?: SetOptions$1): Promise<string>;
update(docPath: string, data: {
[key: string]: any;
}): Promise<void>;
delete(docPath: string): Promise<void>;
bulkUpsert(path: string, data: DocumentData$1[] | {
data: DocumentData$1;
qb?: QueryBuilder;
}, opts?: SetOptions$1): Promise<string[]>;
bulkDelete(path: string, qb?: QueryBuilder, maxSize?: number): Promise<string[]>;
/**
* write batch
*/
get batch(): any;
/**
* firestore timestamp
*/
get serverTimestamp(): _firebase_firestore.FieldValue;
/**
* FieldValue increment
*/
increment(n?: number): _firebase_firestore.FieldValue;
/**
* Returns a generated Firestore Document Id.
*/
createId(colPath?: string): string;
runTransaction(updateFunction: (transaction: Transaction$1 | any) => Promise<unknown>): Promise<unknown>;
collectionValueChanges<T = any>(path: string, qb?: QueryBuilder): Observable<T[]>;
collectionGroupValueChanges<T = any>(collectionId: string, qb?: QueryBuilder): Observable<T[]>;
collectionSnapshot(path: string, qb?: QueryBuilder): Promise<QuerySnapshot$1<any> | any>;
collectionSnapshotChanges<T = any>(path: string, qb?: QueryBuilder, events?: DocumentChangeType[]): Observable<T[]>;
collectionGroupSnapshotChanges<T = any>(collectionId: string, qb?: QueryBuilder, events?: DocumentChangeType[]): Observable<T[]>;
docValueChanges<T = any>(path: string): Observable<T>;
/**
* @experimental
*
* Cache collection data in memory
*/
collectionWithCache<T = any>(path: string, qb?: QueryBuilder, maxAge?: number): Observable<T[]>;
/**
* @experimental
*
* Cache collectionGroup data in memory
*/
collectionGroupWithCache<T = any>(collectionId: string, qb?: QueryBuilder, maxAge?: number): Observable<T[]>;
/**
* @experimental
*
* Cache document data in memory
*/
docWithCache(path: string, maxAge?: number): Observable<any>;
/**
* @experimental
*
* Delete cached data from the memory
*/
deleteCache(path: string, qb?: QueryBuilder): boolean;
private fetchFromCache;
static ɵfac: i0.ɵɵFactoryDeclaration<FirestoreService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<FirestoreService>;
}
declare const arrayToChunks: (list: any[], size: number) => any[][];
declare const flatten: (source: Observable<any[]>) => Observable<any>;
export { AbstractFirestoreApi, FirestoreService, QueryBuilder, arrayToChunks, flatten };