@@ -71,7 +71,7 @@ export class ObjectRepository {
7171 }
7272
7373
74- async find ( query : UnifiedQuery = { } ) : Promise < any [ ] > {
74+ async find ( query : UnifiedQuery = { } ) : Promise < Record < string , unknown > [ ] > {
7575 const hookCtx : RetrievalHookContext = {
7676 ...this . context ,
7777 objectName : this . objectName ,
@@ -84,17 +84,18 @@ export class ObjectRepository {
8484 await this . app . triggerHook ( 'beforeFind' , this . objectName , hookCtx ) ;
8585
8686 // Execute via kernel (delegates to QueryService)
87- const kernelResult = await ( this . getKernel ( ) as any ) . find ( this . objectName , hookCtx . query || { } ) ;
87+ const kernel = this . getKernel ( ) as unknown as { find ( objectName : string , query : Record < string , unknown > ) : Promise < { value : Record < string , unknown > [ ] } > } ;
88+ const kernelResult = await kernel . find ( this . objectName , ( hookCtx . query || { } ) as Record < string , unknown > ) ;
8889 const results = kernelResult . value ;
8990
9091 // Formula evaluation moved to FormulaPlugin hook
9192 hookCtx . result = results ;
9293 await this . app . triggerHook ( 'afterFind' , this . objectName , hookCtx ) ;
9394
94- return hookCtx . result as any [ ] ;
95+ return hookCtx . result as Record < string , unknown > [ ] ;
9596 }
9697
97- async findOne ( idOrQuery : string | number | UnifiedQuery ) : Promise < any > {
98+ async findOne ( idOrQuery : string | number | UnifiedQuery ) : Promise < Record < string , unknown > | null > {
9899 if ( typeof idOrQuery === 'string' || typeof idOrQuery === 'number' ) {
99100 const hookCtx : RetrievalHookContext = {
100101 ...this . context ,
@@ -108,30 +109,30 @@ export class ObjectRepository {
108109 await this . app . triggerHook ( 'beforeFind' , this . objectName , hookCtx ) ;
109110
110111 // Use kernel.get() for direct ID lookup
111- const result = await ( this . getKernel ( ) as any ) . get ( this . objectName , String ( idOrQuery ) ) ;
112+ const kernel = this . getKernel ( ) as unknown as { get ( objectName : string , id : string ) : Promise < Record < string , unknown > | null > } ;
113+ const result = await kernel . get ( this . objectName , String ( idOrQuery ) ) ;
112114
113115 // Formula evaluation moved to FormulaPlugin hook
114- hookCtx . result = result ;
116+ hookCtx . result = result ? [ result ] : [ ] ;
115117 await this . app . triggerHook ( 'afterFind' , this . objectName , hookCtx ) ;
116- return hookCtx . result ;
118+ const resultArray = hookCtx . result as Record < string , unknown > [ ] ;
119+ return resultArray [ 0 ] || null ;
117120 } else {
118121 const results = await this . find ( idOrQuery ) ;
119122 return results [ 0 ] || null ;
120123 }
121124 }
122125
123- async count ( filters : any ) : Promise < number > {
126+ async count ( filters : Record < string , unknown > | unknown [ ] | undefined ) : Promise < number > {
124127 // Normalize filters to UnifiedQuery format
125128 // If filters is an array, wrap it in a query object
126129 // If filters is already a UnifiedQuery (has UnifiedQuery-specific properties), use it as-is
127130 let query : UnifiedQuery ;
128131 if ( Array . isArray ( filters ) ) {
129132 query = { where : filters } ;
130- } else if ( filters && typeof filters === 'object' && ( filters . fields || filters . orderBy || filters . limit !== undefined || filters . offset !== undefined ) ) {
131- // It's already a UnifiedQuery object
132- query = filters ;
133+ } else if ( filters && typeof filters === 'object' && ( ( filters as Record < string , unknown > ) . fields || ( filters as Record < string , unknown > ) . orderBy || ( filters as Record < string , unknown > ) . limit !== undefined || ( filters as Record < string , unknown > ) . offset !== undefined ) ) {
134+ query = filters as UnifiedQuery ;
133135 } else if ( filters ) {
134- // It's a raw filter object, wrap it
135136 query = { where : filters } ;
136137 } else {
137138 query = { } ;
@@ -150,11 +151,10 @@ export class ObjectRepository {
150151
151152 // Execute via kernel (delegates to QueryService)
152153 let result : number ;
153- const kernel = this . getKernel ( ) as any ;
154+ const kernel = this . getKernel ( ) as unknown as { count ? ( objectName : string , query : Record < string , unknown > ) : Promise < number > } ;
154155 if ( typeof kernel . count === 'function' ) {
155- result = await kernel . count ( this . objectName , hookCtx . query || { } ) ;
156+ result = await kernel . count ( this . objectName , ( hookCtx . query || { } ) as Record < string , unknown > ) ;
156157 } else {
157- // Fallback to driver if kernel doesn't support count
158158 result = await this . getDriver ( ) . count ( this . objectName , hookCtx . query || { } ) ;
159159 }
160160
@@ -163,7 +163,7 @@ export class ObjectRepository {
163163 return hookCtx . result as number ;
164164 }
165165
166- async create ( doc : any ) : Promise < any > {
166+ async create ( doc : Record < string , unknown > ) : Promise < Record < string , unknown > > {
167167 const hookCtx : MutationHookContext = {
168168 ...this . context ,
169169 objectName : this . objectName ,
@@ -176,20 +176,19 @@ export class ObjectRepository {
176176 await this . app . triggerHook ( 'beforeCreate' , this . objectName , hookCtx ) ;
177177 const finalDoc = hookCtx . data || doc ;
178178
179- if ( this . context . userId ) finalDoc . created_by = this . context . userId ;
180- if ( this . context . spaceId ) finalDoc . space_id = this . context . spaceId ;
181-
182- // Validation moved to ValidatorPlugin hook
179+ if ( this . context . userId ) ( finalDoc as Record < string , unknown > ) . created_by = this . context . userId ;
180+ if ( this . context . spaceId ) ( finalDoc as Record < string , unknown > ) . space_id = this . context . spaceId ;
183181
184182 // Execute via kernel
185- const result = await ( this . getKernel ( ) as any ) . create ( this . objectName , finalDoc , this . getOptions ( ) ) ;
183+ const kernel = this . getKernel ( ) as unknown as { create ( objectName : string , doc : Record < string , unknown > , options : Record < string , unknown > ) : Promise < Record < string , unknown > > } ;
184+ const result = await kernel . create ( this . objectName , finalDoc as Record < string , unknown > , this . getOptions ( ) ) ;
186185
187186 hookCtx . result = result ;
188187 await this . app . triggerHook ( 'afterCreate' , this . objectName , hookCtx ) ;
189- return hookCtx . result ;
188+ return hookCtx . result as Record < string , unknown > ;
190189 }
191190
192- async update ( id : string | number , doc : any , _options ?: any ) : Promise < any > {
191+ async update ( id : string | number , doc : Record < string , unknown > , _options ?: Record < string , unknown > ) : Promise < Record < string , unknown > > {
193192 const previousData = await this . findOne ( id ) ;
194193 const hookCtx : UpdateHookContext = {
195194 ...this . context ,
@@ -200,22 +199,21 @@ export class ObjectRepository {
200199 user : this . getUserFromContext ( ) ,
201200 id,
202201 data : doc ,
203- previousData,
202+ previousData : previousData as Record < string , unknown > | undefined ,
204203 isModified : ( field ) => hookCtx . data ? Object . prototype . hasOwnProperty . call ( hookCtx . data , field ) : false
205204 } ;
206205 await this . app . triggerHook ( 'beforeUpdate' , this . objectName , hookCtx ) ;
207206
208- // Validation moved to ValidatorPlugin hook
209-
210207 // Execute via kernel
211- const result = await ( this . getKernel ( ) as any ) . update ( this . objectName , String ( id ) , hookCtx . data , this . getOptions ( ) ) ;
208+ const kernel = this . getKernel ( ) as unknown as { update ( objectName : string , id : string , data : unknown , options : Record < string , unknown > ) : Promise < Record < string , unknown > > } ;
209+ const result = await kernel . update ( this . objectName , String ( id ) , hookCtx . data , this . getOptions ( ) ) ;
212210
213211 hookCtx . result = result ;
214212 await this . app . triggerHook ( 'afterUpdate' , this . objectName , hookCtx ) ;
215- return hookCtx . result ;
213+ return hookCtx . result as Record < string , unknown > ;
216214 }
217215
218- async delete ( id : string | number ) : Promise < any > {
216+ async delete ( id : string | number ) : Promise < Record < string , unknown > > {
219217 const previousData = await this . findOne ( id ) ;
220218 const hookCtx : MutationHookContext = {
221219 ...this . context ,
@@ -225,80 +223,74 @@ export class ObjectRepository {
225223 api : this . getHookAPI ( ) ,
226224 user : this . getUserFromContext ( ) ,
227225 id,
228- previousData
226+ previousData : previousData as Record < string , unknown > | undefined
229227 } ;
230228 await this . app . triggerHook ( 'beforeDelete' , this . objectName , hookCtx ) ;
231229
232230 // Execute via kernel
233- const result = await ( this . getKernel ( ) as any ) . delete ( this . objectName , String ( id ) , this . getOptions ( ) ) ;
231+ const kernel = this . getKernel ( ) as unknown as { delete ( objectName : string , id : string , options : Record < string , unknown > ) : Promise < Record < string , unknown > > } ;
232+ const result = await kernel . delete ( this . objectName , String ( id ) , this . getOptions ( ) ) ;
234233
235234 hookCtx . result = result ;
236235 await this . app . triggerHook ( 'afterDelete' , this . objectName , hookCtx ) ;
237- return hookCtx . result ;
236+ return hookCtx . result as Record < string , unknown > ;
238237 }
239238
240- async aggregate ( query : any ) : Promise < any > {
239+ async aggregate ( query : Record < string , unknown > ) : Promise < unknown [ ] > {
241240 const driver = this . getDriver ( ) ;
242241 if ( ! driver . aggregate ) throw new ObjectQLError ( { code : 'DRIVER_UNSUPPORTED_OPERATION' , message : "Driver does not support aggregate" } ) ;
243242
244243 return driver . aggregate ( this . objectName , query , this . getOptions ( ) ) ;
245244 }
246245
247- async distinct ( field : string , filters ?: any ) : Promise < any [ ] > {
246+ async distinct ( field : string , filters ?: Record < string , unknown > ) : Promise < unknown [ ] > {
248247 const driver = this . getDriver ( ) ;
249248 if ( ! driver . distinct ) throw new ObjectQLError ( { code : 'DRIVER_UNSUPPORTED_OPERATION' , message : "Driver does not support distinct" } ) ;
250249
251250 return driver . distinct ( this . objectName , field , filters , this . getOptions ( ) ) ;
252251 }
253252
254- async findOneAndUpdate ( filters : any , update : any , options ?: any ) : Promise < any > {
253+ async findOneAndUpdate ( filters : Record < string , unknown > , update : Record < string , unknown > , options ?: Record < string , unknown > ) : Promise < Record < string , unknown > | null > {
255254 const driver = this . getDriver ( ) ;
256255 if ( ! driver . findOneAndUpdate ) throw new ObjectQLError ( { code : 'DRIVER_UNSUPPORTED_OPERATION' , message : "Driver does not support findOneAndUpdate" } ) ;
257256 return driver . findOneAndUpdate ( this . objectName , filters , update , this . getOptions ( options ) ) ;
258257 }
259258
260- async createMany ( data : any [ ] ) : Promise < any > {
259+ async createMany ( data : Record < string , unknown > [ ] ) : Promise < Record < string , unknown > [ ] > {
261260 const _driver = this . getDriver ( ) ;
262261
263- // Always use fallback to ensure validation and hooks are executed
264- // This maintains ObjectQL's metadata-driven architecture where
265- // validation rules, hooks, and permissions are enforced consistently
266- const results = [ ] ;
262+ const results : Record < string , unknown > [ ] = [ ] ;
267263 for ( const item of data ) {
268264 results . push ( await this . create ( item ) ) ;
269265 }
270266 return results ;
271267 }
272268
273- async updateMany ( filters : any , data : any ) : Promise < any > {
274- // Find all matching records and update them individually
275- // to ensure validation and hooks are executed
269+ async updateMany ( filters : Record < string , unknown > , data : Record < string , unknown > ) : Promise < number > {
276270 const records = await this . find ( { where : filters } ) ;
277271 let count = 0 ;
278272 for ( const record of records ) {
279273 if ( record && record . _id ) {
280- await this . update ( record . _id , data ) ;
274+ await this . update ( record . _id as string | number , data ) ;
281275 count ++ ;
282276 }
283277 }
284278 return count ;
285279 }
286280
287- async deleteMany ( filters : any ) : Promise < any > {
288- // Find all matching records and delete them individually
289- // to ensure hooks are executed
281+ async deleteMany ( filters : Record < string , unknown > ) : Promise < number > {
290282 const records = await this . find ( { where : filters } ) ;
291283 let count = 0 ;
292284 for ( const record of records ) {
293285 if ( record && record . _id ) {
294- await this . delete ( record . _id ) ;
286+ await this . delete ( record . _id as string | number ) ;
295287 count ++ ;
296288 }
297289 }
298290 return count ;
299291 }
300292
301- async execute ( actionName : string , id : string | number | undefined , params : any ) : Promise < any > {
293+ async execute ( actionName : string , id : string | number | undefined , params : Record < string , unknown > ) : Promise < unknown > {
302294 const api : HookAPI = {
303295 find : ( obj , q ) => this . context . object ( obj ) . find ( q ) ,
304296 findOne : ( obj , id ) => this . context . object ( obj ) . findOne ( id ) ,
0 commit comments