@@ -10,6 +10,17 @@ import type { RuntimePlugin, RuntimeContext } from '@objectstack/runtime';
1010import type { ObjectStackKernel } from '@objectstack/runtime' ;
1111import { ValidatorPlugin , ValidatorPluginConfig } from './validator-plugin' ;
1212import { FormulaPlugin , FormulaPluginConfig } from './formula-plugin' ;
13+ import { QueryService } from './query/query-service' ;
14+ import { QueryAnalyzer } from './query/query-analyzer' ;
15+ import type { Driver } from '@objectql/types' ;
16+
17+ /**
18+ * Extended ObjectStack Kernel with ObjectQL services
19+ */
20+ interface ExtendedKernel extends ObjectStackKernel {
21+ queryService ?: QueryService ;
22+ queryAnalyzer ?: QueryAnalyzer ;
23+ }
1324
1425/**
1526 * Configuration for the ObjectQL Plugin
@@ -50,6 +61,18 @@ export interface ObjectQLPluginConfig {
5061 * @default true
5162 */
5263 enableAI ?: boolean ;
64+
65+ /**
66+ * Enable query service and analyzer
67+ * @default true
68+ */
69+ enableQueryService ?: boolean ;
70+
71+ /**
72+ * Datasources for query service
73+ * Required if enableQueryService is true
74+ */
75+ datasources ?: Record < string , Driver > ;
5376}
5477
5578/**
@@ -70,6 +93,7 @@ export class ObjectQLPlugin implements RuntimePlugin {
7093 enableValidator : true ,
7194 enableFormulas : true ,
7295 enableAI : true ,
96+ enableQueryService : true ,
7397 ...config
7498 } ;
7599 }
@@ -81,6 +105,25 @@ export class ObjectQLPlugin implements RuntimePlugin {
81105 async install ( ctx : RuntimeContext ) : Promise < void > {
82106 console . log ( `[${ this . name } ] Installing plugin...` ) ;
83107
108+ const kernel = ctx . engine as ExtendedKernel ;
109+
110+ // Register QueryService and QueryAnalyzer if enabled
111+ if ( this . config . enableQueryService !== false && this . config . datasources ) {
112+ const queryService = new QueryService (
113+ this . config . datasources ,
114+ kernel . metadata
115+ ) ;
116+ kernel . queryService = queryService ;
117+
118+ const queryAnalyzer = new QueryAnalyzer (
119+ queryService ,
120+ kernel . metadata
121+ ) ;
122+ kernel . queryAnalyzer = queryAnalyzer ;
123+
124+ console . log ( `[${ this . name } ] QueryService and QueryAnalyzer registered` ) ;
125+ }
126+
84127 // Register components based on configuration
85128 if ( this . config . enableRepository !== false ) {
86129 await this . registerRepository ( ctx . engine ) ;
0 commit comments