monguito
Version:
MongoDB Abstract Repository implementation for Node.js
55 lines (54 loc) • 1.62 kB
TypeScript
import { Schema } from 'mongoose';
import { Entity } from './entity';
/**
* Models a domain type instance constructor.
*/
type Constructor<T> = new (...args: any) => T;
/**
* Models an abstract domain type instance constructor.
*/
type AbsConstructor<T> = abstract new (...args: any) => T;
/**
* Models some domain type data.
*/
type DomainTypeData<T> = {
type: Constructor<T> | AbsConstructor<T>;
schema: Schema;
};
/**
* Models some domain leaf type data.
*/
type DomainLeafTypeData<T> = {
type: Constructor<T>;
schema: Schema;
};
/**
* Models some domain intermediate type data.
*/
type DomainIntermediateTypeData<T> = {
type: Constructor<T> | AbsConstructor<T>;
schema: Schema;
subtypes: (DomainIntermediateTypeData<T> | DomainLeafTypeData<T>)[];
};
/**
* Domain model specification.
*/
export interface DomainModel<T extends Entity> extends DomainTypeData<T> {
subtypes?: (DomainIntermediateTypeData<T> | DomainLeafTypeData<T>)[];
}
/**
* Domain model implementation.
*/
export declare class DomainTree<T extends Entity> implements DomainModel<T> {
readonly type: Constructor<T> | AbsConstructor<T>;
readonly schema: Schema;
readonly subtypes: (DomainIntermediateTypeData<T> | DomainLeafTypeData<T>)[];
constructor(domainModel: DomainModel<T>);
getSubtypeTree(): DomainModel<T>[];
getSubtypeData(type: string): DomainModel<T> | undefined;
getSubtypeConstructor(type: string): Constructor<T> | undefined;
getSupertypeConstructor(): Constructor<T> | undefined;
getSupertypeName(): string;
has(type: string): boolean;
}
export {};