@@ -10,6 +10,13 @@ import type { RuntimePlugin, RuntimeContext, ObjectStackKernel } from '@objectst
1010import { FormulaEngine } from './formula-engine' ;
1111import type { FormulaEngineConfig } from '@objectql/types' ;
1212
13+ /**
14+ * Extended ObjectStack Kernel with formula engine capability
15+ */
16+ interface KernelWithFormulas extends ObjectStackKernel {
17+ formulaEngine ?: FormulaEngine ;
18+ }
19+
1320/**
1421 * Configuration for the Formula Plugin
1522 */
@@ -49,12 +56,12 @@ export class FormulaPlugin implements RuntimePlugin {
4956 * Registers formula evaluation capabilities
5057 */
5158 async install ( ctx : RuntimeContext ) : Promise < void > {
52- const kernel = ctx . engine as ObjectStackKernel ;
59+ const kernel = ctx . engine as KernelWithFormulas ;
5360
5461 console . log ( `[${ this . name } ] Installing formula plugin...` ) ;
5562
5663 // Make formula engine accessible from the kernel for direct usage
57- ( kernel as any ) . formulaEngine = this . engine ;
64+ kernel . formulaEngine = this . engine ;
5865
5966 // Register formula provider if the kernel supports it
6067 this . registerFormulaProvider ( kernel ) ;
@@ -71,13 +78,10 @@ export class FormulaPlugin implements RuntimePlugin {
7178 * Register the formula provider with the kernel
7279 * @private
7380 */
74- private registerFormulaProvider ( kernel : ObjectStackKernel ) : void {
81+ private registerFormulaProvider ( kernel : KernelWithFormulas ) : void {
7582 // Check if kernel supports formula provider registration
76- // Note: Using type assertion since registerFormulaProvider may not be in the interface
77- const kernelWithFormulas = kernel as any ;
78-
79- if ( typeof kernelWithFormulas . registerFormulaProvider === 'function' ) {
80- kernelWithFormulas . registerFormulaProvider ( {
83+ if ( typeof ( kernel as any ) . registerFormulaProvider === 'function' ) {
84+ ( kernel as any ) . registerFormulaProvider ( {
8185 evaluate : ( formula : string , context : any ) => {
8286 // Delegate to the formula engine
8387 // Note: In a real implementation, we would need to properly construct
@@ -96,24 +100,19 @@ export class FormulaPlugin implements RuntimePlugin {
96100 return this . engine . extractMetadata ( fieldName , expression , dataType ) ;
97101 }
98102 } ) ;
99- } else {
100- // If the kernel doesn't support formula provider registration yet,
101- // we still register the engine for direct access
102- kernelWithFormulas . formulaEngine = this . engine ;
103103 }
104+ // Note: formulaEngine is already registered in install() method above
104105 }
105106
106107 /**
107108 * Register formula evaluation middleware
108109 * @private
109110 */
110- private registerFormulaMiddleware ( kernel : ObjectStackKernel ) : void {
111+ private registerFormulaMiddleware ( kernel : KernelWithFormulas ) : void {
111112 // Check if kernel supports middleware hooks
112- const kernelWithHooks = kernel as any ;
113-
114- if ( typeof kernelWithHooks . use === 'function' ) {
113+ if ( typeof ( kernel as any ) . use === 'function' ) {
115114 // Register middleware to evaluate formulas after queries
116- kernelWithHooks . use ( 'afterQuery' , async ( context : any ) => {
115+ ( kernel as any ) . use ( 'afterQuery' , async ( context : any ) => {
117116 // Formula evaluation logic would go here
118117 // This would automatically compute formula fields after data is retrieved
119118 if ( context . results && context . metadata ?. fields ) {
0 commit comments