Skip to content

Commit 727ce9b

Browse files
committed
Refactor HookContext import from spec package
Removes the local HookContext interface definition and imports HookContext and HookEvent directly from '@objectstack/spec/data' to ensure consistency and reduce duplication.
1 parent aca7541 commit 727ce9b

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

packages/objectql/src/index.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
import { QueryAST } from '@objectstack/spec/data';
1+
import { QueryAST, HookContext, HookEvent } from '@objectstack/spec/data';
22
import { ObjectStackManifest } from '@objectstack/spec/system';
33
import { DriverInterface, DriverOptions } from '@objectstack/spec/driver';
44
import { SchemaRegistry } from './registry';
55

66
// Export Registry for consumers
77
export { SchemaRegistry } from './registry';
88

9-
/**
10-
* Hook Context
11-
*/
12-
export interface HookContext {
13-
object: string;
14-
driver: DriverInterface;
15-
method: 'find' | 'insert' | 'update' | 'delete' | 'count';
16-
args: any; // The arguments passed to the method (can be modified)
17-
result?: any; // The result of the operation (for after hooks)
18-
error?: any; // The error if one occurred (for error hooks)
19-
}
20-
219
export type HookHandler = (context: HookContext) => Promise<void> | void;
2210

2311
/**
@@ -242,23 +230,23 @@ export class ObjectQL {
242230
// Trigger Before Hook
243231
const hookContext: HookContext = {
244232
object,
245-
driver,
246-
method: 'find',
247-
args: { ast, options } // Hooks can modify AST here
233+
event: 'beforeFind',
234+
input: { ast, options }, // Hooks can modify AST here
235+
ql: this
248236
};
249237
await this.triggerHooks('beforeFind', hookContext);
250238

251239
try {
252-
const result = await driver.find(object, hookContext.args.ast, hookContext.args.options);
240+
const result = await driver.find(object, hookContext.input.ast, hookContext.input.options);
253241

254242
// Trigger After Hook
243+
hookContext.event = 'afterFind';
255244
hookContext.result = result;
256245
await this.triggerHooks('afterFind', hookContext);
257246

258247
return hookContext.result;
259248
} catch (e) {
260-
hookContext.error = e;
261-
// await this.triggerHooks('error', hookContext);
249+
// hookContext.error = e;
262250
throw e;
263251
}
264252
}

0 commit comments

Comments
 (0)