@@ -14,7 +14,6 @@ import {
1414 ObjectQLContextOptions ,
1515 IObjectQL ,
1616 ObjectQLConfig ,
17- ObjectQLPlugin ,
1817 PluginDefinition ,
1918 HookName ,
2019 HookHandler ,
@@ -38,7 +37,7 @@ export class ObjectQL implements IObjectQL {
3837 private remotes : string [ ] = [ ] ;
3938 private hooks : Record < string , HookEntry [ ] > = { } ;
4039 private actions : Record < string , ActionEntry > = { } ;
41- private pluginsList : Array < ObjectQLPlugin | PluginDefinition > = [ ] ;
40+ private pluginsList : PluginDefinition [ ] = [ ] ;
4241
4342 // Store config for lazy loading in init()
4443 private config : ObjectQLConfig ;
@@ -64,7 +63,7 @@ export class ObjectQL implements IObjectQL {
6463 }
6564 }
6665 }
67- use ( plugin : ObjectQLPlugin | PluginDefinition ) {
66+ use ( plugin : PluginDefinition ) {
6867 this . pluginsList . push ( plugin ) ;
6968 }
7069
@@ -221,7 +220,7 @@ export class ObjectQL implements IObjectQL {
221220 *
222221 * @private
223222 */
224- private createPluginContext ( app : IObjectQL ) : import ( '@objectstack/spec' ) . PluginContextData {
223+ private createPluginContext ( ) : import ( '@objectstack/spec' ) . PluginContextData {
225224 // TODO: Implement full PluginContext conversion
226225 // For now, provide a minimal adapter that maps IObjectQL to PluginContext
227226 return {
@@ -273,7 +272,7 @@ export class ObjectQL implements IObjectQL {
273272 t : ( key : string , params ?: any ) => key , // Fallback: return key
274273 getLocale : ( ) => 'en'
275274 } ,
276- metadata : app . metadata ,
275+ metadata : this . metadata ,
277276 events : {
278277 // TODO: Implement event bus
279278 } ,
@@ -297,46 +296,14 @@ export class ObjectQL implements IObjectQL {
297296 async init ( ) {
298297 // 0. Init Plugins (This allows plugins to register custom loaders)
299298 for ( const plugin of this . pluginsList ) {
300- // Type guard: check if it's a legacy plugin or new PluginDefinition
301- const isLegacyPlugin = 'setup' in plugin && typeof plugin . setup === 'function' ;
302- const pluginId = isLegacyPlugin ? ( plugin as ObjectQLPlugin ) . name : ( plugin as PluginDefinition ) . id || 'unknown' ;
299+ const pluginId = plugin . id || 'unknown' ;
303300
304301 console . log ( `Initializing plugin '${ pluginId } '...` ) ;
305302
306- let app : IObjectQL = this ;
307- const pkgName = ( plugin as any ) . _packageName ;
308-
309- if ( pkgName ) {
310- app = new Proxy ( this , {
311- get ( target , prop ) {
312- if ( prop === 'on' ) {
313- return ( event : HookName , obj : string , handler : HookHandler ) =>
314- target . on ( event , obj , handler , pkgName ) ;
315- }
316- if ( prop === 'registerAction' ) {
317- return ( obj : string , act : string , handler : ActionHandler ) =>
318- target . registerAction ( obj , act , handler , pkgName ) ;
319- }
320- const value = ( target as any ) [ prop ] ;
321- return typeof value === 'function' ? value . bind ( target ) : value ;
322- }
323- } ) ;
324- }
325-
326- if ( isLegacyPlugin ) {
327- // Legacy plugin with setup() method
328- await ( plugin as ObjectQLPlugin ) . setup ( app ) ;
329- } else {
330- // New plugin with lifecycle hooks
331- const newPlugin = plugin as PluginDefinition ;
332-
333- // Call onEnable hook if it exists
334- if ( newPlugin . onEnable ) {
335- // TODO: Build proper PluginContext from IObjectQL
336- // For now, we'll create a minimal context adapter
337- const context = this . createPluginContext ( app ) ;
338- await newPlugin . onEnable ( context ) ;
339- }
303+ // Call onEnable hook if it exists
304+ if ( plugin . onEnable ) {
305+ const context = this . createPluginContext ( ) ;
306+ await plugin . onEnable ( context ) ;
340307 }
341308 }
342309
0 commit comments