export interface CounterSnapshot { exists: boolean; data: () => number; } import { DocumentReference, WriteResult } from "firebase-admin/firestore"; export declare class Counter { private doc; private field; /** * Constructs a sharded counter object that references to a field * in a document that is a counter. * * @param doc A reference to a document with a counter field. * @param field A path to a counter field in the above document. */ constructor(doc: DocumentReference, field: string); /** * Get latency compensated view of the counter. * * All local increments will be reflected in the counter even if the main * counter hasn't been updated yet. */ get(options?: any): Promise; /** * Listen to latency compensated view of the counter. * * All local increments to this counter will be immediately visible in the * snapshot. */ onSnapshot(observable: (next: CounterSnapshot) => void): void; /** * Increment the counter by a given value. * * e.g. * const counter = new sharded.Counter(db.doc("path/document"), "counter"); * counter.incrementBy(1); */ incrementBy(val: number): Promise; /** * Access the assigned shard directly. Useful to update multiple counters * at the same time, batches or transactions. * * e.g. * const counter = new sharded.Counter(db.doc("path/counter"), ""); * const shardRef = counter.shard(); * shardRef.set({"counter1", firestore.FieldValue.Increment(1), * "counter2", firestore.FieldValue.Increment(1)); */ shard(): DocumentReference; }