@push.rocks/smartdata
Version:
An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.
31 lines (30 loc) • 1.42 kB
TypeScript
import { SmartdataCollection } from './classes.collection.js';
import { SmartdataDb } from './classes.db.js';
/**
* Per-SmartdataDb collection cache.
*
* Historically this class keyed its cache by class name alone, which meant
* the first SmartdataDb to request a collection of a given class name
* "won" — every subsequent call from a different SmartdataDb instance
* received the cached collection bound to the first db. That silently
* broke multi-tenant SaaS apps (one db per tenant), tests instantiating
* multiple SmartdataDbs in sequence, and any in-process db cluster switch.
*
* The cache is now keyed by `(SmartdataDb instance, className)` using a
* WeakMap of db → Map<className, SmartdataCollection>. Entries are GC'd
* with their parent db automatically.
*/
export declare class CollectionFactory {
private perDbCollections;
getCollection: (nameArg: string, dbArg: SmartdataDb) => SmartdataCollection<any>;
/**
* @deprecated Internal back-compat shim. The previous field was a public
* Record<className, SmartdataCollection> but was not part of the
* documented public API. WeakMap is not iterable, so this getter returns
* an empty object — anyone actually relying on the old shape would get
* clean nothing rather than wrong-db data. Will be removed in 8.0.
*/
get collections(): {
[key: string]: SmartdataCollection<any>;
};
}