pretur.spec
Version:
MDA model specification builder for code generation
66 lines (65 loc) • 2.46 kB
TypeScript
import { Spec, SpecType } from './spec';
export declare type NormalType = 'INTEGER' | 'BIGINT' | 'BOOLEAN' | 'DATE' | 'DOUBLE' | 'STRING' | 'OBJECT';
export declare type RangeType = 'INTEGER' | 'BIGINT' | 'DATE';
export interface ArraySubtypeNormal {
type: NormalType;
}
export interface ArraySubtypeDecimal {
type: 'DECIMAL';
precision?: number;
scale?: number;
}
export interface ArraySubtypeRange {
type: 'RANGE';
subtype: RangeType;
}
export interface ArraySubtypeMultidimensional {
type: 'ARRAY';
subtype: ArraySubtype;
}
export declare type ArraySubtype = ArraySubtypeNormal | ArraySubtypeDecimal | ArraySubtypeRange | ArraySubtypeMultidimensional;
export interface AttributeBase<T, K extends keyof T = keyof T> {
name: K;
virtual?: boolean;
required?: boolean;
unique?: boolean;
primary?: boolean;
autoIncrement?: boolean;
mutable?: boolean;
defaultValue?: T[K];
}
export interface NormalAttribute<T, K extends keyof T = keyof T> extends AttributeBase<T, K> {
type: NormalType;
}
export interface DecimalAttribute<T, K extends keyof T = keyof T> extends AttributeBase<T, K> {
type: 'DECIMAL';
precision?: number;
scale?: number;
}
export interface EnumAttribute<T, K extends keyof T = keyof T> extends AttributeBase<T, K> {
type: 'ENUM';
typename: string;
values: T[K][];
}
export interface RangeAttribute<T, K extends keyof T = keyof T> extends AttributeBase<T, K> {
type: 'RANGE';
subtype: RangeType;
}
export interface ArrayAttribute<T, K extends keyof T = keyof T> extends AttributeBase<T, K> {
type: 'ARRAY';
subtype: ArraySubtype;
}
export declare type Attribute<T = any, K extends keyof T = keyof T> = NormalAttribute<T, K> | DecimalAttribute<T, K> | EnumAttribute<T, K> | RangeAttribute<T, K> | ArrayAttribute<T, K>;
export interface PrimaryKeyOptions<T, K extends keyof T> {
name: K;
type?: NormalType;
autoIncrement?: boolean;
mutable?: boolean;
}
export declare function validateAttribute(attribute: Attribute): void;
export declare function appendAttribute<T extends SpecType>(spec: Spec<T>, attribute: Attribute<T['fields']>): void;
export interface AttributeBuilder<F> {
<K extends keyof F>(options: Attribute<F, K>): void;
primaryKey<K extends keyof F>(options?: PrimaryKeyOptions<F, K>): void;
}
export declare function createAttributeBuilder<T extends SpecType>(spec: Spec<T>): AttributeBuilder<T['fields']>;