Skip to content

Commit e4e7d84

Browse files
Copilothotlong
andcommitted
feat: Add RuntimePlugin interface and update protocol plugins to implement it
- Define RuntimePlugin and RuntimeContext interfaces in @objectql/types - Update GraphQL, OData V4, and JSON-RPC plugins to implement RuntimePlugin - Replace ObjectStackProtocolImplementation with direct engine access - Add helper methods for metadata and CRUD operations in each plugin - Update package dependencies to use @objectql/types instead of @objectstack/runtime Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 2daebbe commit e4e7d84

8 files changed

Lines changed: 542 additions & 64 deletions

File tree

packages/foundation/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ export * from './workflow';
3737
export * from './report';
3838
export * from './form';
3939
export * from './formula';
40+
export * from './plugin';
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* ObjectQL Plugin System
3+
* Copyright (c) 2026-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* Runtime context passed to plugin lifecycle hooks
11+
*
12+
* This context provides access to the kernel/engine instance
13+
* and allows plugins to interact with the ObjectStack runtime.
14+
*/
15+
export interface RuntimeContext {
16+
/**
17+
* The ObjectStack kernel/engine instance
18+
*
19+
* This provides access to:
20+
* - metadata registry
21+
* - hook manager
22+
* - action manager
23+
* - CRUD operations
24+
*/
25+
engine: any; // Using 'any' to avoid circular dependency
26+
27+
/**
28+
* Get the kernel instance (alternative accessor)
29+
* Some implementations may use getKernel() instead of engine
30+
*/
31+
getKernel?: () => any;
32+
}
33+
34+
/**
35+
* RuntimePlugin Interface
36+
*
37+
* Defines the standard plugin contract for ObjectStack/ObjectQL ecosystem.
38+
* All plugins (protocol adapters, data drivers, feature extensions) should
39+
* implement this interface to ensure consistent lifecycle management.
40+
*
41+
* Lifecycle Order:
42+
* 1. install() - Called during kernel initialization
43+
* 2. onStart() - Called when kernel starts
44+
* 3. onStop() - Called when kernel stops/shuts down
45+
*
46+
* @example
47+
* ```typescript
48+
* export class MyPlugin implements RuntimePlugin {
49+
* name = '@myorg/my-plugin';
50+
* version = '1.0.0';
51+
*
52+
* async install(ctx: RuntimeContext): Promise<void> {
53+
* // Register hooks, load configuration
54+
* console.log('Plugin installed');
55+
* }
56+
*
57+
* async onStart(ctx: RuntimeContext): Promise<void> {
58+
* // Start servers, connect to services
59+
* console.log('Plugin started');
60+
* }
61+
*
62+
* async onStop(ctx: RuntimeContext): Promise<void> {
63+
* // Cleanup resources, disconnect
64+
* console.log('Plugin stopped');
65+
* }
66+
* }
67+
* ```
68+
*/
69+
export interface RuntimePlugin {
70+
/**
71+
* Unique plugin identifier
72+
*
73+
* Should follow npm package naming convention
74+
* Examples: '@objectql/plugin-security', '@myorg/my-plugin'
75+
*/
76+
name: string;
77+
78+
/**
79+
* Plugin version (semantic versioning)
80+
*
81+
* Optional but recommended for debugging and compatibility tracking
82+
* Example: '1.0.0', '2.1.3-beta'
83+
*/
84+
version?: string;
85+
86+
/**
87+
* Install hook - called during kernel initialization
88+
*
89+
* Use this phase to:
90+
* - Register hooks and event handlers
91+
* - Initialize plugin state
92+
* - Load configuration
93+
* - Register metadata (objects, fields, actions)
94+
* - Validate dependencies
95+
*
96+
* This is called BEFORE the kernel starts, so services may not be available yet.
97+
*
98+
* @param ctx - Runtime context with access to kernel/engine
99+
*/
100+
install?(ctx: RuntimeContext): void | Promise<void>;
101+
102+
/**
103+
* Start hook - called when kernel starts
104+
*
105+
* Use this phase to:
106+
* - Start background processes (servers, workers, schedulers)
107+
* - Connect to external services (databases, APIs, message queues)
108+
* - Initialize runtime resources
109+
* - Perform health checks
110+
*
111+
* This is called AFTER install() and AFTER all plugins are installed.
112+
*
113+
* @param ctx - Runtime context with access to kernel/engine
114+
*/
115+
onStart?(ctx: RuntimeContext): void | Promise<void>;
116+
117+
/**
118+
* Stop hook - called when kernel stops/shuts down
119+
*
120+
* Use this phase to:
121+
* - Stop background processes
122+
* - Disconnect from external services
123+
* - Cleanup resources (file handles, connections, timers)
124+
* - Flush pending operations
125+
* - Save state if needed
126+
*
127+
* This is called during graceful shutdown. Ensure cleanup completes quickly.
128+
*
129+
* @param ctx - Runtime context with access to kernel/engine
130+
*/
131+
onStop?(ctx: RuntimeContext): void | Promise<void>;
132+
}

packages/protocols/graphql/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"test:watch": "vitest"
1818
},
1919
"dependencies": {
20-
"@objectstack/runtime": "workspace:*",
2120
"@objectql/types": "workspace:*",
2221
"@apollo/server": "^4.10.0",
2322
"graphql": "^16.8.1"

0 commit comments

Comments
 (0)