Skip to content

Latest commit

 

History

History
131 lines (101 loc) · 4.1 KB

File metadata and controls

131 lines (101 loc) · 4.1 KB

RuntimePlugin Interface Implementation - Summary

Issue

The GraphQL, OData V4, and JSON-RPC protocol plugins were not formally implementing a standard RuntimePlugin interface, leading to architectural inconsistency issues.

Solution

We have successfully implemented the RuntimePlugin interface specification and updated all three protocol plugins to conform to it.

Changes Made

1. RuntimePlugin Interface Definition (@objectql/types)

Created /packages/foundation/types/src/plugin.ts defining:

RuntimePlugin Interface

export interface RuntimePlugin {
  name: string;
  version?: string;
  install?(ctx: RuntimeContext): void | Promise<void>;
  onStart?(ctx: RuntimeContext): void | Promise<void>;
  onStop?(ctx: RuntimeContext): void | Promise<void>;
}

RuntimeContext Interface

export interface RuntimeContext {
  engine: any;
  getKernel?: () => any;
}

2. Protocol Plugin Updates

GraphQL Plugin (@objectql/protocol-graphql)

  • ✅ Implements RuntimePlugin interface
  • ✅ Removed dependency on @objectstack/runtime
  • ✅ Added helper methods for metadata and CRUD operations
  • ✅ Direct engine access via RuntimeContext

OData V4 Plugin (@objectql/protocol-odata-v4)

  • ✅ Implements RuntimePlugin interface
  • ✅ Removed dependency on @objectstack/runtime
  • ✅ Added helper methods for metadata and CRUD operations
  • ✅ Direct engine access via RuntimeContext

JSON-RPC Plugin (@objectql/protocol-json-rpc)

  • ✅ Implements RuntimePlugin interface
  • ✅ Removed dependency on @objectstack/runtime
  • ✅ Added helper methods for metadata and CRUD operations
  • ✅ Direct engine access via RuntimeContext

3. Package Dependencies

Updated all three plugin package.json files to:

  • Remove @objectstack/runtime dependency
  • Use only @objectql/types for interface definitions

4. Tests

Added comprehensive test suite in /packages/foundation/types/test/plugin.test.ts:

  • RuntimePlugin interface conformance tests
  • RuntimeContext functionality tests
  • Lifecycle hook execution order tests
  • Sync/async hook support tests

5. Documentation

Updated /packages/protocols/README.md:

  • Documented RuntimePlugin interface
  • Documented RuntimeContext
  • Updated plugin implementation pattern
  • Added Engine API documentation
  • Removed references to deprecated ObjectStackRuntimeProtocol

Architecture Compliance

✅ Standard Lifecycle Hooks

All plugins now implement:

  1. install(ctx) - Called during kernel initialization
  2. onStart(ctx) - Called when kernel starts
  3. onStop(ctx) - Called when kernel stops

✅ Consistent Interface

All plugins implement the same RuntimePlugin interface from @objectql/types, ensuring:

  • Uniform plugin architecture
  • Predictable lifecycle management
  • Easy plugin discovery and validation
  • Type-safe plugin development

✅ Direct Engine Access

Plugins no longer depend on a separate protocol bridge layer. Instead:

  • They access the kernel/engine directly via RuntimeContext
  • They implement their own helper methods for common operations
  • They maintain full control over their data access patterns

Impact

Architecture Consistency ✅

  • All protocol plugins follow the same interface
  • Clear lifecycle management
  • Consistent error handling

Plugin Extensibility ✅

  • Easy to add new protocol plugins
  • Clear contract to implement
  • Type-safe development

Maintenance Cost ✅

  • Reduced dependency on non-existent packages
  • Simpler architecture
  • Better testability

Testing Results

  • ✅ RuntimePlugin interface tests pass
  • ✅ Existing plugin lifecycle tests remain valid
  • ✅ No breaking changes to plugin APIs
  • ✅ TypeScript compilation successful (modulo external dependencies)

Next Steps

The implementation is complete and ready for use. Protocol plugins can now be:

  1. Instantiated with their configuration
  2. Passed to the kernel/runtime
  3. Initialized via the install hook
  4. Started via the onStart hook
  5. Stopped via the onStop hook

All three plugins (GraphQL, OData V4, JSON-RPC) are now fully compliant with the ObjectStack RuntimePlugin specification.