@@ -15,6 +15,7 @@ import {
1515 IObjectQL ,
1616 ObjectQLConfig ,
1717 ObjectQLPlugin ,
18+ PluginDefinition ,
1819 HookName ,
1920 HookHandler ,
2021 HookContext ,
@@ -37,7 +38,7 @@ export class ObjectQL implements IObjectQL {
3738 private remotes : string [ ] = [ ] ;
3839 private hooks : Record < string , HookEntry [ ] > = { } ;
3940 private actions : Record < string , ActionEntry > = { } ;
40- private pluginsList : ObjectQLPlugin [ ] = [ ] ;
41+ private pluginsList : Array < ObjectQLPlugin | PluginDefinition > = [ ] ;
4142
4243 // Store config for lazy loading in init()
4344 private config : ObjectQLConfig ;
@@ -63,7 +64,7 @@ export class ObjectQL implements IObjectQL {
6364 }
6465 }
6566 }
66- use ( plugin : ObjectQLPlugin ) {
67+ use ( plugin : ObjectQLPlugin | PluginDefinition ) {
6768 this . pluginsList . push ( plugin ) ;
6869 }
6970
@@ -214,10 +215,87 @@ export class ObjectQL implements IObjectQL {
214215 }
215216 }
216217
218+ /**
219+ * Create a PluginContext from the current IObjectQL instance.
220+ * This adapts the IObjectQL interface to the PluginContext expected by @objectstack/spec plugins.
221+ *
222+ * @private
223+ */
224+ private createPluginContext ( app : IObjectQL ) : any {
225+ // TODO: Implement full PluginContext conversion
226+ // For now, provide a minimal adapter that maps IObjectQL to PluginContext
227+ return {
228+ ql : {
229+ object : ( name : string ) => {
230+ // Return a repository-like interface
231+ return app . createContext ( ) . object ( name ) ;
232+ } ,
233+ query : async ( soql : string ) => {
234+ // TODO: Implement SOQL query execution
235+ throw new Error ( 'SOQL queries not yet implemented in adapter' ) ;
236+ }
237+ } ,
238+ os : {
239+ getCurrentUser : async ( ) => {
240+ // TODO: Get from context
241+ return null ;
242+ } ,
243+ getConfig : async ( key : string ) => {
244+ // TODO: Implement config access
245+ return null ;
246+ }
247+ } ,
248+ logger : {
249+ debug : ( ...args : any [ ] ) => console . debug ( '[Plugin]' , ...args ) ,
250+ info : ( ...args : any [ ] ) => console . info ( '[Plugin]' , ...args ) ,
251+ warn : ( ...args : any [ ] ) => console . warn ( '[Plugin]' , ...args ) ,
252+ error : ( ...args : any [ ] ) => console . error ( '[Plugin]' , ...args ) ,
253+ } ,
254+ storage : {
255+ get : async ( key : string ) => {
256+ // TODO: Implement plugin storage
257+ return null ;
258+ } ,
259+ set : async ( key : string , value : any ) => {
260+ // TODO: Implement plugin storage
261+ } ,
262+ delete : async ( key : string ) => {
263+ // TODO: Implement plugin storage
264+ }
265+ } ,
266+ i18n : {
267+ t : ( key : string , params ?: any ) => key , // Fallback: return key
268+ getLocale : ( ) => 'en'
269+ } ,
270+ metadata : app . metadata ,
271+ events : {
272+ // TODO: Implement event bus
273+ } ,
274+ app : {
275+ router : {
276+ get : ( path : string , handler : Function ) => {
277+ // TODO: Implement router registration
278+ } ,
279+ post : ( path : string , handler : Function ) => {
280+ // TODO: Implement router registration
281+ } ,
282+ use : ( pathOrHandler : string | Function , handler ?: Function ) => {
283+ // TODO: Implement middleware registration
284+ }
285+ } ,
286+ scheduler : undefined // Optional in spec
287+ }
288+ } ;
289+ }
290+
217291 async init ( ) {
218292 // 0. Init Plugins (This allows plugins to register custom loaders)
219293 for ( const plugin of this . pluginsList ) {
220- console . log ( `Initializing plugin '${ plugin . name } '...` ) ;
294+ // Type guard: check if it's a legacy plugin or new PluginDefinition
295+ const isLegacyPlugin = 'setup' in plugin && typeof plugin . setup === 'function' ;
296+ const pluginId = isLegacyPlugin ? ( plugin as ObjectQLPlugin ) . name : ( plugin as PluginDefinition ) . id || 'unknown' ;
297+
298+ console . log ( `Initializing plugin '${ pluginId } '...` ) ;
221299
222300 let app : IObjectQL = this ;
223301 const pkgName = ( plugin as any ) . _packageName ;
@@ -239,7 +317,21 @@ export class ObjectQL implements IObjectQL {
239317 } ) ;
240318 }
241319
242- await plugin . setup ( app ) ;
320+ if ( isLegacyPlugin ) {
321+ // Legacy plugin with setup() method
322+ await ( plugin as ObjectQLPlugin ) . setup ( app ) ;
323+ } else {
324+ // New plugin with lifecycle hooks
325+ const newPlugin = plugin as PluginDefinition ;
326+
327+ // Call onEnable hook if it exists
328+ if ( newPlugin . onEnable ) {
329+ // TODO: Build proper PluginContext from IObjectQL
330+ // For now, we'll create a minimal context adapter
331+ const context = this . createPluginContext ( app ) ;
332+ await newPlugin . onEnable ( context ) ;
333+ }
334+ }
243335 }
244336
245337 // Packages, Presets, Source, Objects loading logic removed from Core.
0 commit comments