Skip to content

Commit 4ef33a1

Browse files
committed
refactor: update validation and formula middleware to use context hooks
1 parent 6c88981 commit 4ef33a1

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

packages/foundation/core/src/formula-plugin.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class FormulaPlugin implements Plugin {
6767

6868
// Register formula evaluation middleware if auto-evaluation is enabled
6969
if (this.config.autoEvaluateOnQuery !== false) {
70-
this.registerFormulaMiddleware(kernel);
70+
this.registerFormulaMiddleware(ctx);
7171
}
7272

7373
console.log(`[${this.name}] Formula plugin installed`);
@@ -107,11 +107,11 @@ export class FormulaPlugin implements Plugin {
107107
* Register formula evaluation middleware
108108
* @private
109109
*/
110-
private registerFormulaMiddleware(kernel: KernelWithFormulas): void {
111-
// Check if kernel supports middleware hooks
112-
if (typeof (kernel as any).use === 'function') {
110+
private registerFormulaMiddleware(ctx: PluginContext): void {
111+
// Check if context supports hook registration
112+
if (typeof (ctx as any).hook === 'function') {
113113
// Register middleware to evaluate formulas after queries
114-
(kernel as any).use('afterQuery', async (context: any) => {
114+
(ctx as any).hook('afterQuery', async (context: any) => {
115115
// Formula evaluation logic would go here
116116
// This would automatically compute formula fields after data is retrieved
117117
if (context.results && context.metadata?.fields) {

packages/foundation/core/src/validator-plugin.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ export class ValidatorPlugin implements Plugin {
7575

7676
// Register validation middleware for queries (if enabled)
7777
if (this.config.enableQueryValidation !== false) {
78-
this.registerQueryValidation(kernel);
78+
this.registerQueryValidation(ctx);
7979
}
8080

8181
// Register validation middleware for mutations (if enabled)
8282
if (this.config.enableMutationValidation !== false) {
83-
this.registerMutationValidation(kernel);
83+
this.registerMutationValidation(ctx);
8484
}
8585

8686
console.log(`[${this.name}] Validator plugin installed`);
@@ -90,10 +90,10 @@ export class ValidatorPlugin implements Plugin {
9090
* Register query validation middleware
9191
* @private
9292
*/
93-
private registerQueryValidation(kernel: KernelWithValidator): void {
94-
// Check if kernel supports middleware hooks
95-
if (typeof (kernel as any).use === 'function') {
96-
(kernel as any).use('beforeQuery', async (context: any) => {
93+
private registerQueryValidation(ctx: PluginContext): void {
94+
// Check if context supports hook registration
95+
if (typeof (ctx as any).hook === 'function') {
96+
(ctx as any).hook('beforeQuery', async (context: any) => {
9797
// Query validation logic
9898
// In a real implementation, this would validate query parameters
9999
// For now, this is a placeholder that demonstrates the integration pattern
@@ -112,10 +112,10 @@ export class ValidatorPlugin implements Plugin {
112112
* Register mutation validation middleware
113113
* @private
114114
*/
115-
private registerMutationValidation(kernel: KernelWithValidator): void {
116-
// Check if kernel supports middleware hooks
117-
if (typeof (kernel as any).use === 'function') {
118-
(kernel as any).use('beforeMutation', async (context: any) => {
115+
private registerMutationValidation(ctx: PluginContext): void {
116+
// Check if context supports hook registration
117+
if (typeof (ctx as any).hook === 'function') {
118+
(ctx as any).hook('beforeMutation', async (context: any) => {
119119
// Mutation validation logic
120120
// This would validate data before create/update operations
121121
if (context.data && context.metadata?.validation_rules) {

0 commit comments

Comments
 (0)