Skip to content

Commit def23a7

Browse files
Copilothotlong
andcommitted
docs: Update protocol plugins README with RuntimePlugin interface
- Document RuntimePlugin interface and RuntimeContext - Update plugin implementation pattern - Add Engine API documentation - Remove references to deprecated ObjectStackRuntimeProtocol Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 96f61be commit def23a7

2 files changed

Lines changed: 425 additions & 24 deletions

File tree

packages/protocols/README.md

Lines changed: 84 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
# ObjectStack Protocol Plugins
22

3-
This directory contains protocol plugin implementations for the ObjectStack ecosystem. Each protocol plugin implements the `RuntimePlugin` interface and uses the `ObjectStackRuntimeProtocol` bridge layer to interact with the kernel.
3+
This directory contains protocol plugin implementations for the ObjectStack ecosystem. Each protocol plugin implements the `RuntimePlugin` interface defined in `@objectql/types`.
44

55
## Architecture Overview
66

77
### Key Principles
88

9-
1. **Plugin Interface**: All protocols implement `RuntimePlugin` from `@objectstack/runtime`
10-
2. **Bridge Layer**: Must instantiate `ObjectStackRuntimeProtocol` for kernel interaction
11-
3. **No Direct DB Access**: All data operations go through the protocol bridge methods
12-
4. **Lifecycle Management**: Plugins initialize in `onStart` lifecycle hook
9+
1. **Plugin Interface**: All protocols implement `RuntimePlugin` from `@objectql/types`
10+
2. **Direct Engine Access**: Plugins access the kernel/engine directly through the RuntimeContext
11+
3. **No Direct DB Access**: All data operations go through kernel methods (find, create, update, delete)
12+
4. **Lifecycle Management**: Plugins follow install → onStart → onStop lifecycle
1313

14-
### Protocol Bridge Pattern
14+
### Plugin Implementation Pattern
1515

1616
```typescript
17-
import { RuntimePlugin, RuntimeContext, ObjectStackRuntimeProtocol } from '@objectstack/runtime';
17+
import type { RuntimePlugin, RuntimeContext } from '@objectql/types';
1818

1919
export class MyProtocolPlugin implements RuntimePlugin {
2020
name = '@objectql/protocol-my-protocol';
21-
private protocol?: ObjectStackRuntimeProtocol;
21+
version = '1.0.0';
22+
23+
private engine?: any;
2224

2325
async install(ctx: RuntimeContext): Promise<void> {
24-
// Initialize the protocol bridge
25-
this.protocol = new ObjectStackRuntimeProtocol(ctx.engine);
26+
// Store engine reference for later use
27+
this.engine = ctx.engine;
28+
29+
// Initialize plugin resources
30+
console.log('Plugin installed');
2631
}
2732

2833
async onStart(ctx: RuntimeContext): Promise<void> {
2934
// Start your protocol server
30-
// Use this.protocol.findData(), this.protocol.createData(), etc.
35+
// Use this.engine.find(), this.engine.create(), etc.
36+
console.log('Plugin started');
37+
}
38+
39+
async onStop(ctx: RuntimeContext): Promise<void> {
40+
// Cleanup resources
41+
console.log('Plugin stopped');
3142
}
3243
}
3344
```
@@ -101,14 +112,14 @@ await kernel.start();
101112

102113
### 3. GraphQL (`@objectql/protocol-graphql`)
103114

104-
GraphQL protocol implementation with Apollo Server integration.
115+
Full GraphQL implementation with automatic schema generation and Apollo Server integration.
105116

106117
**Features:**
107-
- Automatic schema generation from metadata
118+
- Automatic GraphQL schema generation from metadata
108119
- Query and mutation resolvers
109-
- GraphQL introspection and playground
110-
- Apollo Server 4.x integration
111-
- Type-safe operations
120+
- Apollo Server v4+ with Apollo Sandbox
121+
- Introspection support
122+
- Type-safe resolvers
112123

113124
**Usage:**
114125
```typescript
@@ -117,16 +128,15 @@ import { GraphQLPlugin } from '@objectql/protocol-graphql';
117128

118129
const kernel = new ObjectKernel([
119130
new GraphQLPlugin({
120-
port: 4000,
121-
introspection: true,
122-
playground: true
131+
port: 4000,
132+
introspection: true
123133
})
124134
]);
125135
await kernel.start();
126136

127-
// Access GraphQL playground: http://localhost:4000/
137+
// Access Apollo Sandbox: http://localhost:4000/
128138
// Query example:
129-
// {
139+
// query {
130140
// usersList(limit: 10) {
131141
// id
132142
// name
@@ -135,9 +145,9 @@ await kernel.start();
135145
// }
136146
```
137147

138-
**Reference**: Based on implementation by @hotlong
148+
## RuntimePlugin Interface
139149

140-
**Available RPC Methods:**
150+
All protocol plugins implement the `RuntimePlugin` interface from `@objectql/types`:
141151
- `object.find(objectName, query)` - Find records
142152
- `object.get(objectName, id)` - Get single record
143153
- `object.create(objectName, data)` - Create record
@@ -150,7 +160,57 @@ await kernel.start();
150160
- `system.listMethods()` - List available methods
151161
- `system.describe(method)` - Get method signature
152162

153-
## ObjectStackRuntimeProtocol API
163+
## RuntimePlugin Interface
164+
165+
All protocol plugins implement the `RuntimePlugin` interface from `@objectql/types`:
166+
167+
```typescript
168+
export interface RuntimePlugin {
169+
/** Unique plugin identifier */
170+
name: string;
171+
172+
/** Plugin version (optional) */
173+
version?: string;
174+
175+
/** Install hook - called during kernel initialization */
176+
install?(ctx: RuntimeContext): void | Promise<void>;
177+
178+
/** Start hook - called when kernel starts */
179+
onStart?(ctx: RuntimeContext): void | Promise<void>;
180+
181+
/** Stop hook - called when kernel stops */
182+
onStop?(ctx: RuntimeContext): void | Promise<void>;
183+
}
184+
```
185+
186+
### RuntimeContext
187+
188+
The RuntimeContext provides access to the kernel/engine:
189+
190+
```typescript
191+
export interface RuntimeContext {
192+
/** The ObjectStack kernel/engine instance */
193+
engine: any;
194+
}
195+
```
196+
197+
### Engine API
198+
199+
The engine provides the following methods for protocol plugins:
200+
201+
**Metadata Operations:**
202+
- `engine.metadata.getTypes()` - Get list of registered types
203+
- `engine.metadata.list(type)` - Get items of a specific type
204+
- `engine.metadata.get(type, name)` - Get a specific metadata item
205+
206+
**CRUD Operations:**
207+
- `engine.find(objectName, query)` - Find records
208+
- `engine.get(objectName, id)` - Get single record
209+
- `engine.create(objectName, data)` - Create record
210+
- `engine.update(objectName, id, data)` - Update record
211+
- `engine.delete(objectName, id)` - Delete record
212+
213+
## Creating a Custom Protocol Plugin
154214

155215
The bridge layer provides these methods for protocol implementations:
156216

0 commit comments

Comments
 (0)