UNPKG

@goatlab/fluent

Version:

Readable query Interface & API generator for TS and Node

88 lines (87 loc) 3.2 kB
import { SchemaObject as JsonSchema } from 'openapi3-ts'; import { AnyObject, DataObject, Options, PrototypeOf } from './common-types'; import { BelongsToDefinition, HasManyDefinition, HasOneDefinition, RelationMetadata } from './relation.types'; import { TypeResolver } from './type-resolver'; import { Type } from './type'; export interface JsonSchemaWithExtensions extends JsonSchema { [attributes: string]: any; } export declare type PropertyType = string | Function | object | Type<any> | TypeResolver<Model>; export interface PropertyDefinition { type: PropertyType; id?: boolean | number; hidden?: boolean; json?: PropertyForm; jsonSchema?: JsonSchemaWithExtensions; store?: PropertyForm; itemType?: PropertyType; [attribute: string]: any; } export interface ModelSettings { description?: string; forceId?: boolean; hiddenProperties?: string[]; scope?: object; strict?: boolean | 'filter'; [name: string]: any; } export interface PropertyForm { in?: boolean; out?: boolean; name?: string; } export declare type RelationDefinitionMap = { [relationName: string]: RelationMetadata; }; export interface ModelDefinitionSyntax { name: string; properties?: { [name: string]: PropertyDefinition | PropertyType; }; settings?: ModelSettings; relations?: RelationDefinitionMap; jsonSchema?: JsonSchemaWithExtensions; [attribute: string]: any; } export declare class ModelDefinition { readonly name: string; properties: { [name: string]: PropertyDefinition; }; settings: ModelSettings; relations: RelationDefinitionMap; [attribute: string]: any; constructor(nameOrDef: string | ModelDefinitionSyntax); addProperty(name: string, definitionOrType: PropertyDefinition | PropertyType): this; addSetting(name: string, value: any): this; addRelation(definition: RelationMetadata): this; belongsTo(name: string, definition: Omit<BelongsToDefinition, 'name' | 'type' | 'targetsMany'>): this; hasOne(name: string, definition: Omit<HasOneDefinition, 'name' | 'type' | 'targetsMany'>): this; hasMany(name: string, definition: Omit<HasManyDefinition, 'name' | 'type' | 'targetsMany'>): this; idProperties(): string[]; } export declare class Model { static get modelName(): string; static definition: ModelDefinition; toJSON(): Object; toObject(options?: Options): Object; constructor(data?: DataObject<Model>); } export interface Persistable { } export declare abstract class ValueObject extends Model implements Persistable { } export declare class Entity extends Model implements Persistable { static getIdProperties(): string[]; static getIdOf(entityOrData: AnyObject): any; getId(): any; getIdObject(): Object; static buildWhereForId(id: any): any; } export declare class Event { source: any; type: string; } export declare type EntityData = DataObject<Entity>; export declare type EntityResolver<T extends Entity> = TypeResolver<T, typeof Entity>; export declare function rejectNavigationalPropertiesInData<M extends typeof Entity>(modelClass: M, data: DataObject<PrototypeOf<M>>): void;