88
99import {
1010 MetadataRegistry ,
11- Driver ,
11+ Driver ,
1212 ObjectConfig ,
1313 ObjectQLContext ,
1414 ObjectQLContextOptions ,
@@ -23,57 +23,30 @@ import {
2323 LoaderPlugin
2424} from '@objectql/types' ;
2525import { ObjectRepository } from './repository' ;
26+ // import { createDriverFromConnection } from './driver'; // REMOVE THIS
2627
28+ // import { loadRemoteFromUrl } from './remote';
2729import { executeActionHelper , registerActionHelper , ActionEntry } from './action' ;
2830import { registerHookHelper , triggerHookHelper , HookEntry } from './hook' ;
2931import { registerObjectHelper , getConfigsHelper } from './object' ;
3032import { convertIntrospectedSchemaToObjects } from './util' ;
3133
32- // Import ObjectStack engine for driver management
33- // Note: We use type casting when interfacing with ObjectStack to maintain
34- // backward compatibility with existing Driver implementations
35- import { ObjectQL as ObjectStackEngine } from '@objectstack/objectql' ;
36-
37- /**
38- * ObjectQL Application
39- *
40- * Integrates with @objectstack/objectql for driver management while
41- * maintaining backward compatibility with existing Driver implementations.
42- *
43- * Drivers implementing the extended Driver interface from @objectql/types
44- * are compatible with DriverInterface from @objectstack/spec through
45- * optional property extensions.
46- */
4734export class ObjectQL implements IObjectQL {
4835 public metadata : MetadataRegistry ;
49- // Uses Driver from @objectql /types which has been extended to be
50- // compatible with DriverInterface from @objectstack /spec
5136 private datasources : Record < string , Driver > = { } ;
5237 private remotes : string [ ] = [ ] ;
5338 private hooks : Record < string , HookEntry [ ] > = { } ;
5439 private actions : Record < string , ActionEntry > = { } ;
5540 private pluginsList : ObjectQLPlugin [ ] = [ ] ;
5641
57- // ObjectStack engine instance for driver management
58- private stackEngine : ObjectStackEngine ;
59-
6042 // Store config for lazy loading in init()
6143 private config : ObjectQLConfig ;
6244
6345 constructor ( config : ObjectQLConfig ) {
6446 this . config = config ;
6547 this . metadata = config . registry || new MetadataRegistry ( ) ;
6648 this . datasources = config . datasources || { } ;
67-
68- // Initialize ObjectStack engine for driver management
69- this . stackEngine = new ObjectStackEngine ( { } ) ;
70-
71- // Register drivers with ObjectStack engine
72- // Type casting is used here because Driver from @objectql /types is structurally
73- // compatible with DriverInterface from @objectstack /spec through optional extensions
74- for ( const [ name , driver ] of Object . entries ( this . datasources ) ) {
75- this . stackEngine . registerDriver ( driver as any , name === 'default' ) ;
76- }
49+ // this.remotes = config.remotes || [];
7750
7851 if ( config . connection ) {
7952 throw new Error ( "Connection strings are not supported in core directly. Use @objectql/platform-node's createDriverFromConnection or pass a driver instance to 'datasources'." ) ;
@@ -90,37 +63,9 @@ export class ObjectQL implements IObjectQL {
9063 }
9164 }
9265 }
93-
9466 use ( plugin : ObjectQLPlugin ) {
9567 this . pluginsList . push ( plugin ) ;
9668 }
97-
98- /**
99- * Get access to the ObjectStack engine for advanced driver features
100- *
101- * @returns The ObjectStack engine instance managing drivers
102- */
103- getStackEngine ( ) : ObjectStackEngine {
104- return this . stackEngine ;
105- }
106-
107- /**
108- * Register a new driver with ObjectStack engine
109- *
110- * @param name - The name of the datasource
111- * @param driver - Driver instance implementing Driver interface from @objectql/types
112- * @param isDefault - Whether this driver should be the default datasource
113- */
114- registerDriver ( name : string , driver : Driver , isDefault : boolean = false ) {
115- if ( this . datasources [ name ] ) {
116- console . warn ( `[ObjectQL] Driver '${ name } ' already exists. Overwriting...` ) ;
117- }
118- this . datasources [ name ] = driver ;
119- // Type casting for ObjectStack engine compatibility
120- // Driver from @objectql /types has been extended with optional properties
121- // to be compatible with DriverInterface from @objectstack /spec
122- this . stackEngine . registerDriver ( driver as any , isDefault ) ;
123- }
12469
12570 removePackage ( name : string ) {
12671 this . metadata . unregisterPackage ( name ) ;
@@ -261,19 +206,16 @@ export class ObjectQL implements IObjectQL {
261206 }
262207
263208 async close ( ) {
264- // Close ObjectStack engine (handles all driver lifecycle)
265- if ( this . stackEngine ) {
266- console . log ( '[ObjectQL] Closing engine...' ) ;
267- await this . stackEngine . destroy ( ) ;
209+ for ( const [ name , driver ] of Object . entries ( this . datasources ) ) {
210+ if ( driver . disconnect ) {
211+ console . log ( `Closing driver '${ name } '...` ) ;
212+ await driver . disconnect ( ) ;
213+ }
268214 }
269215 }
270216
271217 async init ( ) {
272- // 0. Initialize ObjectStack engine
273- console . log ( '[ObjectQL] Initializing engine...' ) ;
274- await this . stackEngine . init ( ) ;
275-
276- // 1. Init Plugins (This allows plugins to register custom loaders)
218+ // 0. Init Plugins (This allows plugins to register custom loaders)
277219 for ( const plugin of this . pluginsList ) {
278220 console . log ( `Initializing plugin '${ plugin . name } '...` ) ;
279221
0 commit comments