@@ -43,7 +43,8 @@ import {
4343 generateFieldValidatorSchema ,
4444 DatabaseServiceSettings ,
4545 DatabaseMethods ,
46- DatabaseLocalVariables
46+ DatabaseLocalVariables ,
47+ HookCustomFunctionArgument
4748} from "@moleculer/database" ;
4849
4950// =============================================================================
@@ -155,12 +156,12 @@ const customField: CustomFieldDefinition = {
155156// Test field definitions with lifecycle hooks
156157const fieldWithHooks : FieldDefinition = {
157158 type : "string" ,
158- onCreate : ( value : any , entity : any , field : FieldDefinition , ctx : Context ) => value || "default" ,
159- onUpdate : ( value : any , entity : any , field : FieldDefinition , ctx : Context ) => value ,
160- onReplace : ( value : any , entity : any , field : FieldDefinition , ctx : Context ) => value ,
161- onRemove : ( value : any , entity : any , field : FieldDefinition , ctx : Context ) => null ,
159+ onCreate : ( { value } ) => value || "default" ,
160+ onUpdate : ( { value } ) => value ,
161+ onReplace : ( { value } ) => value ,
162+ onRemove : ( ) => null ,
162163 get : ( value : any , entity : any , field : FieldDefinition , ctx : Context ) => value ,
163- set : ( value : any , entity : any , field : FieldDefinition , ctx : Context ) => value ,
164+ set : ( { value } ) => value ,
164165 validate : async ( value : any , entity : any , field : FieldDefinition , ctx : Context ) => {
165166 return typeof value === "string" && value . length > 0 ;
166167 }
@@ -850,7 +851,7 @@ const multiTenantServiceSchema: ServiceSchema<
850851 tenantId : {
851852 type : "string" ,
852853 required : true ,
853- set : ( value : any , entity : any , field : FieldDefinition , ctx : Context ) => {
854+ set : ( { value , ctx } ) => {
854855 return ( ctx . meta as any ) ?. tenantId || value ;
855856 }
856857 }
@@ -896,7 +897,7 @@ const complexFields: Fields = {
896897 trim : true ,
897898 lowercase : true ,
898899 alphanum : false ,
899- set : ( value : any ) => value ?. toString ( ) . toLowerCase ( ) . replace ( / \s + / g, "-" )
900+ set : ( { value } ) => value ?. toString ( ) . toLowerCase ( ) . replace ( / \s + / g, "-" )
900901 } ,
901902
902903 // Number field with validation
@@ -975,18 +976,18 @@ const complexFields: Fields = {
975976 auditInfo : {
976977 type : "object" ,
977978 readonly : true ,
978- onCreate : ( value : any , entity : any , field : FieldDefinition , ctx : Context ) => ( {
979+ onCreate : ( { ctx } : HookCustomFunctionArgument ) => ( {
979980 createdBy : ( ctx . meta as any ) ?. user ?. id ,
980981 createdAt : Date . now ( ) ,
981982 version : 1
982983 } ) ,
983- onUpdate : ( value : any , entity : any , field : FieldDefinition , ctx : Context ) => ( {
984+ onUpdate : ( { value , ctx } : HookCustomFunctionArgument ) => ( {
984985 ...value ,
985986 updatedBy : ( ctx . meta as any ) ?. user ?. id ,
986987 updatedAt : Date . now ( ) ,
987988 version : ( value . version || 0 ) + 1
988989 } ) ,
989- onRemove : ( value : any , entity : any , field : FieldDefinition , ctx : Context ) => ( {
990+ onRemove : ( { value , ctx } : HookCustomFunctionArgument ) => ( {
990991 ...value ,
991992 deletedBy : ( ctx . meta as any ) ?. user ?. id ,
992993 deletedAt : Date . now ( )
0 commit comments