iridium
Version:
A custom lightweight ORM for MongoDB designed for power-users
38 lines (37 loc) • 1.57 kB
TypeScript
import { ObjectID, Binary } from "./BSON";
import { Model } from "./Model";
export interface Transforms {
/**
* A transform which is applied to the entire document.
*/
$document?: PropertyTransform<any>;
_id?: PropertyTransform<any>;
[property: string]: PropertyTransform<any> | undefined;
}
/**
* Converts the value of a property to and from its database representation.
*/
export interface PropertyTransform<T> {
/**
* Converts a property's value from its database representation into one
* suitable for the application.
* @param value The value stored in the MongoDB database document.
* @param property The name of the document property to which this transform is being applied.
* @param model The Iridium Model on which this transform is being applied
* @returns A derived value which is more useful to the application.
*/
fromDB(value: T, property: string, model: Model<any, any>): any;
/**
* Converts a property's value into a representation more suitable for
* the database.
* @param value The value used by the application.
* @param property The name of the document property to which this transform is being applied.
* @param model The Iridium Model on which this transform is being applied
* @returns The database optimized representation of the value.
*/
toDB(value: any, property: string, model: Model<any, any>): T;
}
export declare const DefaultTransforms: {
ObjectID: PropertyTransform<ObjectID>;
Binary: PropertyTransform<Binary>;
};