@fxjs/orm
Advanced tools
Comparing version 1.15.0-alpha.2 to 1.15.0-alpha.3
{ | ||
"name": "@fxjs/orm", | ||
"version": "1.15.0-alpha.2", | ||
"version": "1.15.0-alpha.3", | ||
"description": "", | ||
@@ -77,3 +77,3 @@ "main": "lib", | ||
}, | ||
"gitHead": "35101688ca1b26d0ff5ed8eb58938021a52e5d44" | ||
"gitHead": "a139f47dbb76430b70dd07d8c001d575fe97d2cc" | ||
} |
@@ -23,4 +23,4 @@ import { FxDbDriverNS, IDbDriver } from "@fxjs/db-driver"; | ||
export declare function tryGetAssociationItemFromModel(extend_name: string, _model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem; | ||
export declare function prependHook(hooks: FxOrmModel.Hooks, hookName: FxOrmModel.keyofHooks, preLogic: FxOrmHook.HookActionCallback | FxOrmHook.HookResultCallback): void; | ||
export declare function preReplaceHook(m: FxOrmModel.Model, opts: FxOrmModel.ModelDefineOptions, hookName: FxOrmModel.keyofHooks, cb: (this: FxOrmInstance.Instance, inst: FxOrmInstance.Instance) => void): void; | ||
export declare function prependHook(hooks: FxOrmModel.Hooks, hookName: keyof FxOrmModel.Hooks, preLogic: FxOrmHook.HookActionCallback | FxOrmHook.HookResultCallback): void; | ||
export declare function preReplaceHook(m: FxOrmModel.Model, opts: FxOrmModel.ModelDefineOptions, hookName: keyof FxOrmModel.Hooks, cb: (this: FxOrmInstance.Instance, inst: FxOrmInstance.Instance) => void): void; | ||
export declare const hookTrigger: FxOrmHook.HookTrigger<any, any>; | ||
@@ -27,0 +27,0 @@ export declare const hookWait: FxOrmHook.HookWait<FxOrmInstance.Instance<Record<string, FxOrmInstance.FieldRuntimeType>, Record<string, (...args: any) => any>>, any>; |
@@ -140,3 +140,3 @@ /// <reference types="@fibjs/types" /> | ||
} | ||
export interface ModelConstructorOptions { | ||
export interface ModelConstructorOptions<TProperties extends Record<string, FxOrmInstance.FieldRuntimeType> = Record<string, FxOrmInstance.FieldRuntimeType>> { | ||
name: string; | ||
@@ -148,3 +148,3 @@ db: FxOrmNS.ORM; | ||
table: string; | ||
properties: Record<string, FxOrmProperty.NormalizedProperty>; | ||
properties: Record<keyof TProperties, FxOrmProperty.NormalizedProperty>; | ||
__for_extension: boolean; | ||
@@ -159,6 +159,4 @@ indexes: string[]; | ||
cascadeRemove: boolean; | ||
hooks: Hooks; | ||
methods: { | ||
[method_name: string]: Function; | ||
}; | ||
hooks: Hooks<FxOrmInstance.Instance<TProperties>>; | ||
methods: Record<string, (this: FxOrmInstance.Instance<TProperties>, ...args: any) => any>; | ||
validations: FxOrmValidators.IValidatorHash; | ||
@@ -171,35 +169,34 @@ ievents: FxOrmInstance.InstanceConstructorOptions['events']; | ||
*/ | ||
table?: ModelConstructorOptions['table']; | ||
collection?: ModelConstructorOptions['table']; | ||
table?: ModelConstructorOptions<TProperties>['table']; | ||
collection?: ModelConstructorOptions<TProperties>['table']; | ||
/** | ||
* @dirty would be deprecated | ||
*/ | ||
__for_extension?: ModelConstructorOptions['__for_extension']; | ||
indexes?: ModelConstructorOptions['indexes']; | ||
id?: ModelConstructorOptions['keys']; | ||
autoSave?: ModelConstructorOptions['autoSave']; | ||
autoFetch?: ModelConstructorOptions['autoFetch']; | ||
autoFetchLimit?: ModelConstructorOptions['autoFetchLimit']; | ||
hooks?: ModelConstructorOptions['hooks']; | ||
validations?: ModelConstructorOptions['validations']; | ||
__for_extension?: ModelConstructorOptions<TProperties>['__for_extension']; | ||
indexes?: ModelConstructorOptions<TProperties>['indexes']; | ||
id?: ModelConstructorOptions<TProperties>['keys']; | ||
autoSave?: ModelConstructorOptions<TProperties>['autoSave']; | ||
autoFetch?: ModelConstructorOptions<TProperties>['autoFetch']; | ||
autoFetchLimit?: ModelConstructorOptions<TProperties>['autoFetchLimit']; | ||
hooks?: ModelConstructorOptions<TProperties>['hooks']; | ||
validations?: ModelConstructorOptions<TProperties>['validations']; | ||
methods?: Record<string, (this: FxOrmInstance.Instance<TProperties>, ...args: any) => any>; | ||
identityCache?: ModelConstructorOptions['identityCache']; | ||
cascadeRemove?: ModelConstructorOptions['cascadeRemove']; | ||
ievents?: ModelConstructorOptions['ievents']; | ||
identityCache?: ModelConstructorOptions<TProperties>['identityCache']; | ||
cascadeRemove?: ModelConstructorOptions<TProperties>['cascadeRemove']; | ||
ievents?: ModelConstructorOptions<TProperties>['ievents']; | ||
useSelfSettings?: boolean; | ||
[extensibleProperty: string]: any; | ||
} | ||
export interface Hooks { | ||
beforeValidation?: FxOrmCommon.Arraible<FxOrmHook.HookActionCallback>; | ||
afterValidation?: FxOrmCommon.Arraible<FxOrmHook.HookResultCallback>; | ||
beforeCreate?: FxOrmCommon.Arraible<FxOrmHook.HookActionCallback>; | ||
afterCreate?: FxOrmCommon.Arraible<FxOrmHook.HookResultCallback>; | ||
beforeSave?: FxOrmCommon.Arraible<FxOrmHook.HookActionCallback>; | ||
afterSave?: FxOrmCommon.Arraible<FxOrmHook.HookResultCallback>; | ||
afterLoad?: FxOrmCommon.Arraible<FxOrmHook.HookActionCallback>; | ||
afterAutoFetch?: FxOrmCommon.Arraible<FxOrmHook.HookActionCallback>; | ||
beforeRemove?: FxOrmCommon.Arraible<FxOrmHook.HookActionCallback>; | ||
afterRemove?: FxOrmCommon.Arraible<FxOrmHook.HookResultCallback>; | ||
export interface Hooks<TThis = FxOrmInstance.Instance> { | ||
beforeValidation?: FxOrmCommon.Arraible<FxOrmHook.HookActionCallback<TThis>>; | ||
afterValidation?: FxOrmCommon.Arraible<FxOrmHook.HookResultCallback<TThis>>; | ||
beforeCreate?: FxOrmCommon.Arraible<FxOrmHook.HookActionCallback<TThis>>; | ||
afterCreate?: FxOrmCommon.Arraible<FxOrmHook.HookResultCallback<TThis>>; | ||
beforeSave?: FxOrmCommon.Arraible<FxOrmHook.HookActionCallback<TThis>>; | ||
afterSave?: FxOrmCommon.Arraible<FxOrmHook.HookResultCallback<TThis>>; | ||
afterLoad?: FxOrmCommon.Arraible<FxOrmHook.HookActionCallback<TThis>>; | ||
afterAutoFetch?: FxOrmCommon.Arraible<FxOrmHook.HookActionCallback<TThis>>; | ||
beforeRemove?: FxOrmCommon.Arraible<FxOrmHook.HookActionCallback<TThis>>; | ||
afterRemove?: FxOrmCommon.Arraible<FxOrmHook.HookResultCallback<TThis>>; | ||
} | ||
export type keyofHooks = keyof Hooks; | ||
export interface ModelHookPatchOptions extends FxOrmHook.HookPatchOptions { | ||
@@ -249,8 +246,8 @@ } | ||
} | ||
export type PrimitiveConstructor = String | StringConstructor | Boolean | BooleanConstructor | Number | NumberConstructor | Date | DateConstructor | Object | ObjectConstructor; | ||
export type PrimitiveConstructor = StringConstructor | BooleanConstructor | NumberConstructor | DateConstructor | ObjectConstructor; | ||
export type ComplexModelPropertyDefinition = ModelPropertyDefinition | (PrimitiveConstructor & { | ||
name: string; | ||
}) | [...(string | number)[]] | (PropertyTypeEnum | string); | ||
export type GetPrimitiveFromConstructor<T extends PrimitiveConstructor = PrimitiveConstructor> = T extends String | StringConstructor ? string : T extends Number | NumberConstructor ? number : T extends Boolean | BooleanConstructor ? boolean : T extends Date | DateConstructor ? number | Date : T extends Object | ObjectConstructor | Class_Buffer ? any : never; | ||
type PropertyTypeEnum = import('@fxjs/orm-property').IProperty['PropertyType']; | ||
export type GetPrimitiveFromConstructor<T extends PrimitiveConstructor = PrimitiveConstructor> = T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BooleanConstructor ? boolean : T extends DateConstructor ? number | Date : T extends ObjectConstructor | Class_Buffer ? any : never; | ||
type PropertyTypeEnum = 'text' | 'integer' | 'number' | 'serial' | 'boolean' | 'date' | 'binary' | 'object' | 'enum' | 'point'; | ||
type GetPrimitiveFromOrmPropertyType<T extends PropertyTypeEnum = PropertyTypeEnum> = T extends 'text' ? string : T extends 'enum' ? any[] : T extends 'integer' | 'number' | 'serial' ? number : T extends 'boolean' ? boolean : T extends 'date' ? number | Date : T extends 'binary' | 'object' | 'point' | 'enum' ? any : never; | ||
@@ -263,3 +260,3 @@ /** | ||
} | ||
export type GetPropertiesTypeFromDefinition<T extends ComplexModelPropertyDefinition> = T extends string ? (T extends PropertyTypeEnum ? GetPrimitiveFromOrmPropertyType<PropertyTypeEnum> : string) : T extends [...infer S] ? S[number] : T extends ModelPropertyDefinition ? T['type'] extends 'enum' ? Exclude<T['values'], void>[number] : T['type'] extends PropertyTypeEnum ? GetPrimitiveFromOrmPropertyType<T['type'] & PropertyTypeEnum> : GlobalCustomModelType[T['type']] extends void ? unknown : GlobalCustomModelType[T['type']] : T extends FxOrmModel.PrimitiveConstructor ? FxOrmModel.GetPrimitiveFromConstructor<T> : unknown; | ||
export type GetPropertiesTypeFromDefinition<T extends ComplexModelPropertyDefinition> = T extends string ? (T extends PropertyTypeEnum ? GetPrimitiveFromOrmPropertyType<T> : GlobalCustomModelType[T] extends void ? never : GlobalCustomModelType[T]) : T extends [...infer S] ? S[number] : T extends ModelPropertyDefinition ? T['type'] extends 'enum' ? Exclude<T['values'], void>[number] : T['type'] extends PropertyTypeEnum ? GetPrimitiveFromOrmPropertyType<T['type'] & PropertyTypeEnum> : (GlobalCustomModelType[T['type']] extends void ? never : GlobalCustomModelType[T['type']]) : T extends PrimitiveConstructor ? GetPrimitiveFromConstructor<T> : unknown; | ||
export type GetPropertiesType<T extends Record<string, ComplexModelPropertyDefinition>> = { | ||
@@ -266,0 +263,0 @@ [K in keyof T]: FxOrmModel.GetPropertiesTypeFromDefinition<T[K]>; |
404473
8676