/** * Data transformation utilities for converting between internal formats * (ReadonlyMap and array) and storage object format, plus collection * file grouping utilities. */ /** * Convert an array of entities with id fields to an object keyed by id. * This provides O(1) lookups in storage files. * * @param items - Array of entities, each must have an 'id' field * @returns Object keyed by entity id * * @example * arrayToObject([ * { id: 'user-1', name: 'Alice' }, * { id: 'user-2', name: 'Bob' } * ]) * // Returns: { * // 'user-1': { id: 'user-1', name: 'Alice' }, * // 'user-2': { id: 'user-2', name: 'Bob' } * // } */ export declare function arrayToObject(items: readonly T[]): Record; /** * Convert an object keyed by id back to an array of entities. * * @param obj - Object keyed by entity id * @returns Array of entities * * @example * objectToArray({ * 'user-1': { id: 'user-1', name: 'Alice' }, * 'user-2': { id: 'user-2', name: 'Bob' } * }) * // Returns: [ * // { id: 'user-1', name: 'Alice' }, * // { id: 'user-2', name: 'Bob' } * // ] */ export declare function objectToArray(obj: Record): T[]; /** * Collection configuration that may include a file path for persistence */ type CollectionConfig = { readonly file?: string; readonly [key: string]: unknown; }; /** * Group collections by their configured file paths. * Collections without a file path are not included in the result. * * @param config - Database configuration with collection definitions * @returns Map from file path to array of collection names that use that file * * @example * groupByFile({ * users: { schema: UserSchema, file: '/data/users.json' }, * products: { schema: ProductSchema, file: '/data/db.json' }, * categories: { schema: CategorySchema, file: '/data/db.json' }, * sessions: { schema: SessionSchema } // no file = in-memory only * }) * // Returns: Map { * // '/data/users.json' => ['users'], * // '/data/db.json' => ['products', 'categories'] * // } */ export declare function groupByFile>(config: Config): Map; /** * Get all unique file paths from a database configuration. * * @param config - Database configuration with collection definitions * @returns Array of unique file paths used by collections */ export declare function getConfigFilePaths>(config: Config): string[]; /** * Check if a collection is configured for persistence. * * @param config - Database configuration * @param collectionName - Name of the collection to check * @returns True if the collection has a file path configured */ export declare function isCollectionPersistent>(config: Config, collectionName: keyof Config): boolean; /** * Extract collections that should be stored in a specific file. * * @param data - Full dataset with all collections * @param collectionsForFile - Array of collection names to extract * @returns Object containing only the specified collections in object format */ export declare function extractCollectionsForFile>(data: T, collectionsForFile: readonly string[]): Record>; /** * Merge file data back into the main dataset. * Converts object format back to array format for each collection. * * @param data - Current dataset to update * @param fileData - Data loaded from file (in object format) * @param collectionsFromFile - Array of collection names to update * @returns Updated dataset with arrays */ export declare function mergeFileDataIntoDataset>(data: T, fileData: Record>, collectionsFromFile: readonly string[]): T; /** * Convert an array of entities to a ReadonlyMap keyed by entity ID. * * @param items - Array of entities, each must have an 'id' field * @returns ReadonlyMap keyed by entity id * * @example * arrayToMap([ * { id: 'user-1', name: 'Alice' }, * { id: 'user-2', name: 'Bob' } * ]) * // Returns: Map { 'user-1' => { id: 'user-1', name: 'Alice' }, 'user-2' => { id: 'user-2', name: 'Bob' } } */ export declare function arrayToMap(items: readonly T[]): ReadonlyMap; /** * Convert a ReadonlyMap to a Record keyed by entity ID (the on-disk object format). * * @param map - ReadonlyMap of entities keyed by ID * @returns Record keyed by entity id * * @example * mapToObject(new Map([ * ['user-1', { id: 'user-1', name: 'Alice' }], * ['user-2', { id: 'user-2', name: 'Bob' }], * ])) * // Returns: { 'user-1': { id: 'user-1', name: 'Alice' }, 'user-2': { id: 'user-2', name: 'Bob' } } */ export declare function mapToObject(map: ReadonlyMap): Record; /** * Convert a Record keyed by entity ID to a ReadonlyMap. * Inverse of mapToObject. * * @param obj - Record keyed by entity id * @returns ReadonlyMap keyed by entity id * * @example * objectToMap({ * 'user-1': { id: 'user-1', name: 'Alice' }, * 'user-2': { id: 'user-2', name: 'Bob' }, * }) * // Returns: Map { 'user-1' => { id: 'user-1', name: 'Alice' }, 'user-2' => { id: 'user-2', name: 'Bob' } } */ export declare function objectToMap(obj: Readonly>): ReadonlyMap; /** * Convert a ReadonlyMap to an array of its values. * * @param map - ReadonlyMap of entities * @returns Array of entity values */ export declare function mapToArray(map: ReadonlyMap): readonly T[]; /** * Extract collections from ReadonlyMap-based state for file storage. * * Takes a Record of collection name → ReadonlyMap and a list of collection * names to include, returning nested Record format suitable for serialization. * * @param stateMaps - Record mapping collection names to their ReadonlyMap state * @param collectionsForFile - Collection names to extract * @returns Nested Record: { collectionName: { id: entity, ... }, ... } */ export declare function extractCollectionsFromMaps(stateMaps: Readonly>>, collectionsForFile: readonly string[]): Record>; /** * Merge file data (nested Record format) back into ReadonlyMap-based state. * * Takes existing state maps, file data in Record format, and collection names, * returning updated state maps with the file data merged in. * * @param stateMaps - Current state: Record of collection name → ReadonlyMap * @param fileData - Data from file: { collectionName: { id: entity, ... }, ... } * @param collectionsFromFile - Collection names to update from file data * @returns Updated state maps */ export declare function mergeFileDataIntoMaps(stateMaps: Readonly>>, fileData: Readonly>>>, collectionsFromFile: readonly string[]): Record>; export {}; //# sourceMappingURL=transforms.d.ts.map