import { RepoSnapshot, Snapshot } from './types'; /** * @param name The name of the collection. * @param idField The property of an object containing a unique identifier, normally a uuid. * Optional; defaults to 'id'. */ export declare class Collection { private name; private keyName; constructor(name: string); idToKey: (id: string) => string; keyToId: (key: string) => string; /** * Returns true if the given string is a key for this collection * @param maybeKey */ isCollectionKey(maybeKey: string): boolean; /** * Iterates over all keys for the collection when given the current redux state. * @param state The plain JSON representation of the state. */ keys(state?: RepoSnapshot): Generator; /** * Given the collection's name, returns the `keyName` used internally for tracking the collection. * * @param {string} collectionName The collection name, e.g. `teachers` * @return The key name used internally for the collection (e.g. `__teachers`) */ static getKeyName(collectionName: string): string; /** * Given a collection's `keyName`, returns the collection's name. * * @param {string} keyName The key name used internally for the collection (e.g. `__teachers`) * @return The collection name, e.g. `teachers` */ static getCollectionName(keyName: string): string; /** * Normalizes a state object into a map of objects that can be turned into Automerge documents. * * This is intended to solve two problems: * * 1. Automerge's overhead makes it inefficient to deal with very large arrays (over 10,000 or so * elements), so we treat these as collections and create one document per element. * 2. Scalars and arrays can't be turned into Automerge documents; so we gather any non-collection * elements from the root and store them in a special "global" document. * * For example: * * ```js * // denormalized state (exposed to application) * { * visibilityFilter: 'all', * todos: { * abc123: {}, * qrs666: {}, * }, * } * * // normalized state (for storage) * { * __global: { visibilityFilter: 'all' }, // 🡐 Automerge doc * __todos__abc123: {}, // 🡐 Automerge doc * __todos__qrs666: {}, // 🡐 Automerge doc * } *``` * @see denormalize * @param state The object to be normalized. * @param collections An array containing the names of all elements in `state` to be treated as * collections. * @returns the normalized state */ static normalize(state: Snapshot, collections: string[]): Snapshot; /** * Reverses the operation of `normalize`. * @see normalize * @param state The normalized state to denormalize * @param collections An array containing the names of all collections used in normalizing `state`. */ static denormalize(state: Snapshot, collections: string[]): Snapshot; }