@learnlink/firestore-toolbox
Version:
NPM package for easier cleaning and management of Firestore data. Backup, copy, convert, migrate, sort and move data between different accounts.
43 lines (42 loc) • 2.57 kB
TypeScript
import { firestore } from "firebase-admin";
/**
* Lets you specify a collection, a property name and a value,
* and populate all documents in the collection with the property.
*
* @param {string} collectionName
* @param {string} propertyName
* @param {Object|string|number} propertyValue
* @returns {Promise<Object[]>} Array containing all the responses from Firestore.
*/
export declare function addPropertyToAllDocumentsInCollection(firestoreInstance: firestore.Firestore, collectionName: string, propertyName: string, propertyValue: object | string | number): Promise<string[]>;
/**
* Convert the type of a specific field with a specific type to a new type.
* Also possible to pass in a new Initial value to initate the new type in the field
* If unspecified it will set the new value of the field to be the "empty" equivalent (e.g "" for strings and 0 for number types)
* @param firestoreInstance
* @param collectionName
* @param propertyName
* @param fromType
* @param toType
* @param newInitialValue
*/
export declare function convertPropertyType(firestoreInstance: firestore.Firestore, collectionName: string, propertyName: string, fromType: string, toType: string, newInitialValue?: any): Promise<string[]>;
/**
*
* @param {string} collectionName
* @param {Array} idList
* @returns {Promise<Object[]>} Array containing all the responses from Firestore.
*/
export declare function deleteDocumentsFromCollection(firestoreInstance: firestore.Firestore, collectionName: string, idList: string[]): Promise<firestore.WriteResult[]>;
export declare function deletePropFromAllDocumentsInCollection(firestoreInstance: firestore.Firestore, collectionName: string, propertyName: string): Promise<string[]>;
export declare function replaceValuesForAllDocumentsWhere(firestoreInstance: firestore.Firestore, collectionName: string, propertyName: string, comparison: "<" | "<=" | "==" | ">=" | ">" | "array-contains" | "in" | "array-contains-any", equalTo: string | number, newValue: string | number): Promise<any[]>;
/**
* Renames a collection by running through the current collection, copying all documents
* to a collection given the new name, and deleting all the documents from the old
* collection that where successfully copied to the new collection.
*
* @param {string} currentName
* @param {string} newName
* @returns {Promise<[]>} Promise that resolves with a string-array of all docIDs moved.
*/
export declare function renameCollection(firestoreInstance: firestore.Firestore, currentName: string, newName: string): Promise<void>;