octonom
Version:
Object Document Mapper for any database
28 lines (27 loc) • 1.59 kB
TypeScript
import { ISanitizeOptions, ISchema, ISchemaInstance, ISchemaOptions, ISchemaParentInstance, IToObjectOptions, PopulateReference } from './schema';
export interface IArrayInstance<T> extends ISchemaParentInstance<T[]> {
instanceArray: Array<ISchemaInstance<T>>;
rawArray: T[];
}
export declare type ArrayInstance<T> = IArrayInstance<T>;
export interface IArrayOptions<T = any> extends ISchemaOptions<ArrayInstance<T>> {
elementSchema: ISchema<T, ISchemaInstance<T>>;
minLength?: number;
maxLength?: number;
callParentHooks?: boolean;
}
/** Creates a proxy array that a user can interact with.
* All change operations on the array are intercepted for reflecting the changes
* in instanceArray and calling the beforeChange/afterChange handlers.
* Note: this is a bit lengthy since we need to cover the full js array API.
*/
export declare function proxifyArray<T>(array: T[], instanceArray: Array<ISchemaInstance<T>>, parentInstance: ISchemaParentInstance, elementSchema: ISchema<T, ISchemaInstance<T>>): T[];
export declare class ArraySchema<T> implements ISchema<T[], ArrayInstance<T>, T[]> {
readonly options: IArrayOptions<T>;
constructor(options: IArrayOptions<T>);
create(value: any, sanitizeOptions?: ISanitizeOptions): ArrayInstance<T>;
populate(instance: ArrayInstance<T>, populateReference: PopulateReference): Promise<T[]>;
toObject(instance: ArrayInstance<T>, options?: IToObjectOptions): T[];
validate(instance: ArrayInstance<T>): Promise<void>;
protected sanitize(value: any, sanitizeOptions: ISanitizeOptions): any[];
}