pretur.spec
Version:
MDA model specification builder for code generation
74 lines (73 loc) • 2.71 kB
TypeScript
import { NormalType } from './attribute';
import { Spec, SpecType } from './spec';
export declare type ModificationActions = 'RESTRICT' | 'CASCADE' | 'NO ACTION' | 'SET NULL' | 'SET DEFAULT';
export declare type RelationType = 'SUPERCLASS' | 'SUBCLASS' | 'MASTER' | 'DETAIL' | 'RECURSIVE' | 'MANY_TO_MANY' | 'INJECTIVE';
export interface Relation<T extends SpecType> {
type: RelationType;
target: {
scope: string;
model: string;
};
through?: {
scope: string;
model: string;
};
alias: keyof T['records'] | keyof T['sets'];
key: string;
required?: boolean;
onDelete: ModificationActions;
onUpdate: ModificationActions;
}
export interface ForeignKey<N extends string> {
name: N;
type?: NormalType;
required?: boolean;
unique?: boolean;
primary?: boolean;
mutable?: boolean;
elide?: boolean;
}
export interface Inheritor<S extends SpecType, T extends SpecType> {
target: Spec<T>;
alias: keyof S['records'];
}
export interface InheritorsOptions<S extends SpecType, T extends SpecType> {
sharedExistingUniqueField: keyof (S['fields'] | T['fields']);
aliasOnSubclasses: keyof T['records'];
typeIdentifierFieldName: keyof S['fields'];
typeIdentifierRequired?: boolean;
inheritors: Inheritor<S, T>[];
}
export interface MasterOptions<S extends SpecType, T extends SpecType> {
target: Spec<T>;
alias: keyof S['records'];
ownAliasOnTarget: keyof T['sets'];
foreignKey: ForeignKey<keyof S['fields']>;
required?: boolean;
onDelete?: ModificationActions;
onUpdate?: ModificationActions;
}
export interface InjectiveOptions<S extends SpecType, T extends SpecType> {
target: Spec<T>;
alias: keyof S['records'];
ownAliasOnTarget: keyof T['records'];
foreignKey: ForeignKey<keyof S['fields']>;
required?: boolean;
onDelete?: ModificationActions;
onUpdate?: ModificationActions;
}
export interface RecursiveOptions<S extends SpecType> {
alias: keyof S['records'] | keyof S['sets'];
key: keyof S['fields'];
keyType?: NormalType;
onDelete?: ModificationActions;
onUpdate?: ModificationActions;
}
export declare function appendRelation<T extends SpecType>(spec: Spec<T>, relation: Relation<T>): void;
export interface RelationsBuilder<S extends SpecType> {
inheritors<T extends SpecType>(options: InheritorsOptions<S, T>): void;
injective<T extends SpecType>(options: InjectiveOptions<S, T>): void;
master<T extends SpecType>(options: MasterOptions<S, T>): void;
recursive(options: RecursiveOptions<S>): void;
}
export declare function createRelationBuilder<S extends SpecType>(spec: Spec<S>): RelationsBuilder<S>;