mvom
Version:
Multivalue Object Mapper
46 lines (45 loc) • 2.58 kB
TypeScript
import { TransformDataError } from './errors';
import type Schema from './Schema';
import type { InferDocumentObject } from './Schema';
import type { DbServerDelimiters, DeepOptionalNullable, MvRecord } from './types';
/** Type of data property for constructing a document dependent upon the schema */
export type DocumentData<TSchema extends Schema | null> = DeepOptionalNullable<InferDocumentObject<TSchema>>;
export interface DocumentConstructorOptions<TSchema extends Schema | null> {
data?: DocumentData<TSchema>;
record?: MvRecord;
isSubdocument?: boolean;
}
export interface BuildForeignKeyDefinitionsResult {
filename: string[];
entityName: string;
entityIds: string[];
}
/**
* An intersection type that combines the `Document` class instance with the
* inferred shape of the document object based on the schema definition.
*/
export type DocumentCompositeValue<TSchema extends Schema | null> = Document<TSchema> & InferDocumentObject<TSchema>;
/** A document object */
declare class Document<TSchema extends Schema | null> {
#private;
[key: string]: unknown;
_raw: TSchema extends Schema ? never : MvRecord;
/** Array of any errors which occurred during transformation from the database */
_transformationErrors: TransformDataError[];
protected constructor(schema: TSchema, options: DocumentConstructorOptions<TSchema>);
/** Create a new Subdocument instance from a record array */
static createSubdocumentFromRecord<TSchema extends Schema | null>(schema: TSchema, record: MvRecord): DocumentCompositeValue<TSchema>;
/** Create a new Subdocument instance from data */
static createSubdocumentFromData<TSchema extends Schema>(schema: TSchema, data: DocumentData<TSchema>): DocumentCompositeValue<TSchema>;
/** Create a new Document instance from a record string */
static createDocumentFromRecordString<TSchema extends Schema | null>(schema: TSchema, recordString: string, dbServerDelimiters: DbServerDelimiters): DocumentCompositeValue<TSchema>;
/** Convert a multivalue string to an array */
static convertMvStringToArray(recordString: string, dbServerDelimiters: DbServerDelimiters): MvRecord;
/** Transform document structure to multivalue array structure */
transformDocumentToRecord(): MvRecord;
/** Build a list of foreign key definitions to be used by the database for foreign key validation */
buildForeignKeyDefinitions(): BuildForeignKeyDefinitionsResult[];
/** Validate document for errors */
validate(): Map<string, string[]>;
}
export default Document;