@imbricate/core
Version:
Imbricate Core, Notebook for Engineers
79 lines (78 loc) • 3.38 kB
TypeScript
/**
* @author WMXPY
* @namespace Database
* @description Schema
*/
import { ImbricatePropertyVariant } from "../property/definition";
import { IMBRICATE_PROPERTY_TYPE } from "../property/type";
export type ImbricateDatabaseSchemaProperty<T extends IMBRICATE_PROPERTY_TYPE> = {
readonly propertyIdentifier: string;
} & ImbricateDatabaseSchemaPropertyForCreation<T>;
export type ImbricateDatabaseSchemaPropertyOptionsReferenceDatabase = {
readonly originUniqueIdentifier: string;
readonly databaseUniqueIdentifier: string;
};
export type ImbricateDatabaseSchemaPropertyOptionsLabelOption = {
readonly labelIdentifier: string;
readonly labelName: string;
readonly labelColor: string;
};
export type ImbricateDatabaseSchemaPropertyOptionsBinary = {
/**
* Allow multiple binary files
*/
readonly allowMultiple: boolean;
};
export type ImbricateDatabaseSchemaPropertyOptionsLabel = {
/**
* Allow multiple labels
*/
readonly allowMultiple: boolean;
/**
* Label Options
*/
readonly labelOptions: ImbricateDatabaseSchemaPropertyOptionsLabelOption[];
};
export type ImbricateDatabaseSchemaPropertyOptionsReference = {
/**
* Allow multiple references
*/
readonly allowMultiple: boolean;
/**
* Allow references from these databases
* If empty, allow references from all databases
*/
readonly databases: ImbricateDatabaseSchemaPropertyOptionsReferenceDatabase[];
};
export type ImbricateDatabaseSchemaPropertyOptions<T extends IMBRICATE_PROPERTY_TYPE> = T extends IMBRICATE_PROPERTY_TYPE.BINARY ? ImbricateDatabaseSchemaPropertyOptionsBinary : T extends IMBRICATE_PROPERTY_TYPE.BOOLEAN ? {} : T extends IMBRICATE_PROPERTY_TYPE.STRING ? {} : T extends IMBRICATE_PROPERTY_TYPE.NUMBER ? {} : T extends IMBRICATE_PROPERTY_TYPE.MARKDOWN ? {} : T extends IMBRICATE_PROPERTY_TYPE.JSON ? {} : T extends IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT ? {} : T extends IMBRICATE_PROPERTY_TYPE.DATE ? {} : T extends IMBRICATE_PROPERTY_TYPE.LABEL ? ImbricateDatabaseSchemaPropertyOptionsLabel : T extends IMBRICATE_PROPERTY_TYPE.REFERENCE ? ImbricateDatabaseSchemaPropertyOptionsReference : never;
export type ImbricateDatabaseSchemaPropertyForCreation<T extends IMBRICATE_PROPERTY_TYPE> = {
readonly propertyName: string;
readonly propertyType: T;
readonly propertyVariant: ImbricatePropertyVariant;
readonly propertyOptions: ImbricateDatabaseSchemaPropertyOptions<T>;
readonly isPrimaryKey?: boolean;
};
export type ImbricateDatabaseSchema = {
readonly properties: Array<ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>>;
};
export type ImbricateDatabaseSchemaForCreation = {
readonly properties: Array<ImbricateDatabaseSchemaPropertyForCreation<IMBRICATE_PROPERTY_TYPE>>;
};
/**
* Validate a schema property
*
* @param property property to validate
*
* @returns a string error message if validation failed
* null if validation passed
*/
export declare const validateImbricateSchemaProperty: (property: ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>) => string | null;
/**
* Validate a schema
*
* @param schema database schema to validate
*
* @returns a string error message if validation failed
* null if validation passed
*/
export declare const validateImbricateSchema: (schema: ImbricateDatabaseSchema) => string | null;