@nesvet/n
Version:
Various utilities
34 lines • 1.35 kB
TypeScript
export type Projection = Record<string, 0 | 1>;
/**
* A class for projecting objects in MongoDB style.
* Supports field inclusion/exclusion based on a fixed projection.
*/
export declare class Projector {
#private;
/**
* Creates a new MongoProjector instance with a fixed projection.
* @param projection The projection object (keys are paths, values are 0 or 1).
*/
constructor(projection: Projection);
/**
* Clears the path cache.
*/
clearPathCache(): void;
/**
* Applies the projection to an object, returning a new object with selected fields.
* @param obj The input object.
* @param strict If true, throws errors for inaccessible paths.
* @returns The projected object.
* @throws Error If the input object is null or not an object, or if strict mode detects issues.
*/
project<T extends Record<string, any>>(obj: T, strict?: boolean): Partial<T>;
/**
* Applies the projection to an array of objects.
* @param docs The array of input objects.
* @param strict If true, throws errors for inaccessible paths.
* @returns An array of projected objects.
* @throws Error If the input is not an array.
*/
projectMany<T extends Record<string, any>>(docs: T[], strict?: boolean): Partial<T>[];
}
//# sourceMappingURL=Projector.d.ts.map