@@ -14,14 +14,14 @@ import {
1414 ObjectQLContextOptions ,
1515 IObjectQL ,
1616 ObjectQLConfig ,
17- ObjectQLPlugin ,
1817 HookName ,
1918 HookHandler ,
2019 HookContext ,
2120 ActionHandler ,
2221 ActionContext ,
2322 LoaderPlugin
2423} from '@objectql/types' ;
24+ import type { PluginDefinition } from '@objectstack/spec' ;
2525import { ObjectRepository } from './repository' ;
2626// import { createDriverFromConnection } from './driver'; // REMOVE THIS
2727
@@ -37,7 +37,7 @@ export class ObjectQL implements IObjectQL {
3737 private remotes : string [ ] = [ ] ;
3838 private hooks : Record < string , HookEntry [ ] > = { } ;
3939 private actions : Record < string , ActionEntry > = { } ;
40- private pluginsList : ObjectQLPlugin [ ] = [ ] ;
40+ private pluginsList : PluginDefinition [ ] = [ ] ;
4141
4242 // Store config for lazy loading in init()
4343 private config : ObjectQLConfig ;
@@ -63,7 +63,7 @@ export class ObjectQL implements IObjectQL {
6363 }
6464 }
6565 }
66- use ( plugin : ObjectQLPlugin ) {
66+ use ( plugin : PluginDefinition ) {
6767 this . pluginsList . push ( plugin ) ;
6868 }
6969
@@ -214,32 +214,111 @@ export class ObjectQL implements IObjectQL {
214214 }
215215 }
216216
217+ /**
218+ * Create a PluginContext from the current IObjectQL instance.
219+ * This adapts the IObjectQL interface to the PluginContext expected by @objectstack/spec plugins.
220+ *
221+ * **Current Implementation Status:**
222+ * - ✅ ql.object() - Fully functional, provides repository interface for data access
223+ * - ❌ ql.query() - Not implemented, throws error with guidance
224+ * - ❌ os.getCurrentUser() - Stub, returns null
225+ * - ❌ os.getConfig() - Stub, returns null
226+ * - ✅ logger - Functional, logs to console with [Plugin] prefix
227+ * - ❌ storage - Stub, no persistence implemented
228+ * - ✅ i18n - Basic fallback implementation
229+ * - ✅ metadata - Direct access to MetadataRegistry
230+ * - ❌ events - Empty object, event bus not implemented
231+ * - ❌ app.router - Stub methods, no actual routing
232+ * - ❌ app.scheduler - Not implemented (optional in spec)
233+ *
234+ * @private
235+ * @returns Minimal PluginContext adapter for current plugin system capabilities
236+ */
237+ private createPluginContext ( ) : import ( '@objectstack/spec' ) . PluginContextData {
238+ // TODO: Implement full PluginContext conversion
239+ // For now, provide a minimal adapter that maps IObjectQL to PluginContext
240+ return {
241+ ql : {
242+ object : ( name : string ) => {
243+ // Return a repository-like interface
244+ // Cast to ObjectQL to access createContext
245+ return ( this as ObjectQL ) . createContext ( { } ) . object ( name ) ;
246+ } ,
247+ query : async ( soql : string ) => {
248+ // TODO: Implement SOQL query execution
249+ // This requires implementing a SOQL parser and converter
250+ // For now, throw a descriptive error to guide users
251+ throw new Error (
252+ 'SOQL queries are not yet supported in plugin context adapter. ' +
253+ 'Please use context.ql.object(name).find() instead for data access.'
254+ ) ;
255+ }
256+ } ,
257+ os : {
258+ getCurrentUser : async ( ) => {
259+ // TODO: Get from context
260+ return null ;
261+ } ,
262+ getConfig : async ( key : string ) => {
263+ // TODO: Implement config access
264+ return null ;
265+ }
266+ } ,
267+ logger : {
268+ debug : ( ...args : any [ ] ) => console . debug ( '[Plugin]' , ...args ) ,
269+ info : ( ...args : any [ ] ) => console . info ( '[Plugin]' , ...args ) ,
270+ warn : ( ...args : any [ ] ) => console . warn ( '[Plugin]' , ...args ) ,
271+ error : ( ...args : any [ ] ) => console . error ( '[Plugin]' , ...args ) ,
272+ } ,
273+ storage : {
274+ get : async ( key : string ) => {
275+ // TODO: Implement plugin storage
276+ return null ;
277+ } ,
278+ set : async ( key : string , value : any ) => {
279+ // TODO: Implement plugin storage
280+ } ,
281+ delete : async ( key : string ) => {
282+ // TODO: Implement plugin storage
283+ }
284+ } ,
285+ i18n : {
286+ t : ( key : string , params ?: any ) => key , // Fallback: return key
287+ getLocale : ( ) => 'en'
288+ } ,
289+ metadata : this . metadata ,
290+ events : {
291+ // TODO: Implement event bus
292+ } ,
293+ app : {
294+ router : {
295+ get : ( path : string , handler : ( ...args : unknown [ ] ) => unknown , ...args : unknown [ ] ) => {
296+ // TODO: Implement router registration
297+ } ,
298+ post : ( path : string , handler : ( ...args : unknown [ ] ) => unknown , ...args : unknown [ ] ) => {
299+ // TODO: Implement router registration
300+ } ,
301+ use : ( path : string | undefined , handler : ( ...args : unknown [ ] ) => unknown , ...args : unknown [ ] ) => {
302+ // TODO: Implement middleware registration
303+ }
304+ } ,
305+ scheduler : undefined // Optional in spec
306+ }
307+ } ;
308+ }
309+
217310 async init ( ) {
218311 // 0. Init Plugins (This allows plugins to register custom loaders)
219312 for ( const plugin of this . pluginsList ) {
220- console . log ( `Initializing plugin ' ${ plugin . name } '...` ) ;
313+ const pluginId = plugin . id || 'unknown' ;
221314
222- let app : IObjectQL = this ;
223- const pkgName = ( plugin as any ) . _packageName ;
224-
225- if ( pkgName ) {
226- app = new Proxy ( this , {
227- get ( target , prop ) {
228- if ( prop === 'on' ) {
229- return ( event : HookName , obj : string , handler : HookHandler ) =>
230- target . on ( event , obj , handler , pkgName ) ;
231- }
232- if ( prop === 'registerAction' ) {
233- return ( obj : string , act : string , handler : ActionHandler ) =>
234- target . registerAction ( obj , act , handler , pkgName ) ;
235- }
236- const value = ( target as any ) [ prop ] ;
237- return typeof value === 'function' ? value . bind ( target ) : value ;
238- }
239- } ) ;
315+ console . log ( `Initializing plugin '${ pluginId } '...` ) ;
316+
317+ // Call onEnable hook if it exists
318+ if ( plugin . onEnable ) {
319+ const context = this . createPluginContext ( ) ;
320+ await plugin . onEnable ( context ) ;
240321 }
241-
242- await plugin . setup ( app ) ;
243322 }
244323
245324 // Packages, Presets, Source, Objects loading logic removed from Core.
0 commit comments