import { NohmModel } from './model'; export type TPropertyTypeNames = | 'string' | 'bool' | 'boolean' | 'integer' | 'int' | 'float' | 'number' | 'date' | 'time' | 'timestamp' | 'json'; export const stringProperty: TPropertyTypeNames = 'string'; export const boolProperty: TPropertyTypeNames = 'bool'; export const integerProperty: TPropertyTypeNames = 'integer'; export const floatProperty: TPropertyTypeNames = 'float'; export const numberProperty: TPropertyTypeNames = 'number'; export const dateProperty: TPropertyTypeNames = 'date'; export const timeProperty: TPropertyTypeNames = 'time'; export const timestampProperty: TPropertyTypeNames = 'timestamp'; export const jsonProperty: TPropertyTypeNames = 'json'; export interface IDictionary { [index: string]: any; } export type PropertyBehavior = ( this: TModel, newValue: string, key: string, oldValue: string, ) => any; export interface IStaticMethods { new (): T; load

(id: any): Promise

; loadMany

(id: Array): Promise>; findAndLoad

( searches?: Partial< { [key in keyof TProps]: | string | number | boolean | Partial; } >, ): Promise>; sort( sortOptions: ISortOptions, ids?: Array | false, ): Promise>; find( searches: Partial< { [key in keyof TProps]: | string | number | boolean | Partial; } >, ): Promise>; remove(id: any): Promise; } export type validatiorFunction = (value: any, options: any) => Promise; export interface IValidationObject { name: string; options: { [index: string]: any }; validator: validatiorFunction; } export type TValidationDefinition = | string | { name: string; options: any } | validatiorFunction; export interface IModelPropertyDefinition { /** * Whether the property should be indexed. Depending on type this creates different keys/collections. * Does not work for all types. TODO: specify here which types. * * @type {boolean} * @memberof IModelPropertyDefinition */ index?: boolean; defaultValue?: any; load_pure?: boolean; type: TPropertyTypeNames | PropertyBehavior; unique?: boolean; validations?: Array; } export type TTypedDefinitions = { [props in keyof TProps]: IModelPropertyDefinition; }; export interface IModelPropertyDefinitions { [propName: string]: IModelPropertyDefinition; } export type TIdGenerators = 'default' | 'increment'; export interface IModelOptions { metaCallback?: (error: string | Error | null, version?: string) => any; methods?: { [name: string]: (this: NohmModel, ...args: Array) => any; }; properties: IModelPropertyDefinitions; publish?: boolean; idGenerator?: TIdGenerators | (() => any); } export interface ISaveOptions { silent?: boolean; skip_validation_and_unique_indexes?: boolean; } export interface IProperty { value: any; __updated: boolean; __oldValue: any; __numericIndex: boolean; // this is static but private so for now it might be better here than in definitions } export interface IPropertyDiff { key: TKeys; before: any; after: any; } export interface IValidationResult { key: string; valid: boolean; errors?: Array; } export interface IRelationChange { action: 'link' | 'unlink'; callback?: (...args: Array) => any; object: NohmModel; options: ILinkOptionsWithName; } export interface ILinkOptions { error?: (err: Error | string, otherObject: NohmModel) => any; name?: string; silent?: boolean; } export interface ILinkOptionsWithName extends ILinkOptions { name: string; } export interface ILinkSaveResult { success: boolean; child: NohmModel; parent: NohmModel; error: null | Error; } export interface IUnlinkKeyMapItem { ownIdsKey: string; otherIdsKey: string; } export interface ISearchOption { endpoints: '()' | '[]' | '[)' | '(]' | '(' | ')'; limit: number; min: number | '-inf' | '+inf'; max: number | '-inf' | '+inf'; offset: number; } export type TKey = keyof TProps; export interface IStructuredSearch { type: 'undefined' | 'unique' | 'set' | 'zset'; options: Partial; key: keyof TProps; value: any; } export interface ISortOptions { alpha?: 'ALPHA' | ''; direction?: 'ASC' | 'DESC'; field?: keyof TProps; limit?: Array; } export type TLinkCallback = ( action: string, ownModelName: string, relationName: string, other: T, ) => void; export interface IDefaultEventPayload { target: { id: null | string; modelName: string; properties: TProps & { id: string }; }; } export interface IChangeEventPayload { target: { id: string; modelName: string; properties: TProps; diff: Array>>; }; } export interface IRelationChangeEventPayload { child: IDefaultEventPayload['target']; parent: IDefaultEventPayload['target']; relation: string; }