Skip to content

Commit 84c7401

Browse files
committed
Refactor ObjectKernel integration; update plugin usage and documentation across runtime and objectql packages
1 parent bf44131 commit 84c7401

File tree

4 files changed

+83
-21
lines changed

4 files changed

+83
-21
lines changed

content/docs/developers/mini-kernel.mdx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,44 @@ The MiniKernel architecture enables:
4141

4242
The kernel manages plugin lifecycle and provides core services.
4343

44-
**Location:** `packages/runtime/src/mini-kernel.ts`
44+
**Location:** `packages/core/src/kernel.ts`
4545

4646
**API:**
4747
```typescript
48-
import { ObjectKernel } from '@objectstack/runtime';
48+
import { ObjectKernel } from '@objectstack/core';
49+
import { ObjectQLPlugin, DriverPlugin } from '@objectstack/runtime';
4950

5051
const kernel = new ObjectKernel();
5152

5253
// Register plugins
53-
kernel.use(plugin);
54+
kernel.use(new ObjectQLPlugin())
55+
.use(new DriverPlugin(driver, 'memory'));
5456

5557
// Start the kernel
5658
await kernel.bootstrap();
5759

5860
// Access services
59-
const ql = kernel.getService('objectql');
61+
const ql = kernel.context.getService('objectql'); // Or via getKernel() if exposed
6062

6163
// Shutdown
62-
await kernel.shutdown();
64+
// await kernel.shutdown(); // (Future)
6365
```
6466

6567
### 2. Plugin Interface
6668

6769
All plugins must implement the Plugin interface.
6870

69-
**Location:** `packages/runtime/src/types.ts`
71+
**Location:** `packages/core/src/types.ts`
7072

7173
**Definition:**
7274
```typescript
7375
interface Plugin {
7476
name: string;
77+
version?: string;
7578
dependencies?: string[];
76-
init(ctx: PluginContext): Promise<void>;
77-
start?(ctx: PluginContext): Promise<void>;
78-
destroy?(): Promise<void>;
79+
init?(ctx: PluginContext): Promise<void> | void;
80+
start?(ctx: PluginContext): Promise<void> | void;
81+
destroy?(): Promise<void> | void;
7982
}
8083
```
8184

packages/core/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# @objectstack/core
2+
3+
The Microkernel for the ObjectStack Operating System.
4+
5+
## Overview
6+
7+
This package defines the fundamental runtime mechanics of the ObjectStack architecture:
8+
1. **Dependency Injection (DI)**: A `services` registry.
9+
2. **Plugin Lifecycle**: `init` (Registration) -> `start` (Execution).
10+
3. **Event Bus**: Simple hook system (`hook`, `trigger`).
11+
12+
It is completely agnostic of "Data", "HTTP", or "Apps". It only knows `Plugin` and `Service`.
13+
14+
## Installation
15+
16+
```bash
17+
npm install @objectstack/core
18+
```
19+
20+
## Usage
21+
22+
```typescript
23+
import { ObjectKernel, Plugin, PluginContext } from '@objectstack/core';
24+
25+
// 1. Define a Plugin
26+
class MyPlugin implements Plugin {
27+
name = 'my-plugin';
28+
29+
async init(ctx: PluginContext) {
30+
ctx.registerService('my-service', { hello: 'world' });
31+
}
32+
}
33+
34+
// 2. Boot Kernel
35+
const kernel = new ObjectKernel();
36+
kernel.use(new MyPlugin());
37+
await kernel.bootstrap();
38+
39+
// 3. Use Service
40+
const service = kernel.context.getService('my-service');
41+
```

packages/objectql/README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212

1313
## Usage
1414

15+
### 1. Standalone Usage
16+
1517
```typescript
1618
import { ObjectQL } from '@objectstack/objectql';
17-
import { MemoryDriver } from '@objectstack/driver-memory'; // Example driver
19+
import { InMemoryDriver } from '@objectstack/driver-memory'; // Note: Package name might export InMemoryDriver now
1820

1921
async function main() {
2022
// 1. Initialize Engine
2123
const ql = new ObjectQL();
2224

2325
// 2. Register Drivers
24-
const memDriver = new MemoryDriver({ name: 'default' });
26+
const memDriver = new InMemoryDriver({ name: 'default' });
2527
ql.registerDriver(memDriver, true);
2628

2729
// 3. Load Schema (via Plugin/Manifest)
@@ -61,6 +63,26 @@ async function main() {
6163
}
6264
```
6365

66+
### 2. Using with ObjectKernel (Recommended)
67+
68+
When building full applications, use the `ObjectKernel` to manage plugins and configuration.
69+
70+
```typescript
71+
import { ObjectKernel } from '@objectstack/core';
72+
import { ObjectQLPlugin, DriverPlugin } from '@objectstack/runtime';
73+
import { InMemoryDriver } from '@objectstack/driver-memory';
74+
75+
const kernel = new ObjectKernel();
76+
77+
// Register Engine and Drivers as Kernel Plugins
78+
kernel.use(new ObjectQLPlugin())
79+
.use(new DriverPlugin(new InMemoryDriver(), 'default'));
80+
81+
await kernel.bootstrap();
82+
83+
// The engine automatically discovers drivers and apps registered in the kernel.
84+
```
85+
6486
## Architecture
6587

6688
- **SchemaRegistry**: Central store for all metadata (Objects, Apps, Config).

packages/runtime/README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
# @objectstack/runtime
22

3-
ObjectStack Core Runtime & Query Engine
3+
ObjectStack Standard System Library
44

55
## Overview
66

7-
The runtime package provides the `ObjectKernel` (MiniKernel) - a highly modular, plugin-based microkernel that orchestrates ObjectStack applications. It manages the application lifecycle through a standardized plugin system with dependency injection and event hooks.
8-
9-
The package also defines **capability contract interfaces** (`IHttpServer`, `IDataEngine`) that enable plugins to interact with common services without depending on concrete implementations, following the **Dependency Inversion Principle**.
7+
The runtime package provides the **Standard Library** for the ObjectStack Operating System. It bridges the pure **ObjectKernel** (from `@objectstack/core`) with the **Data Engine** (`@objectstack/objectql`) and provides essential infrastructure adapters.
108

119
### Architecture Highlights
1210

13-
- **MiniKernel Design**: Business logic is completely separated into plugins
11+
- **Standard Library**: Contains essential plugins (`AppManifestPlugin`, `DriverPlugin`)
12+
- **Core Integration**: Re-exports `ObjectKernel` for convenience
1413
- **Capability Contracts**: Abstract interfaces for HTTP server and data persistence
15-
- **Dependency Injection**: Service registry for inter-plugin communication
16-
- **Event/Hook System**: Publish-subscribe mechanism for loose coupling
17-
- **Lifecycle Management**: Standardized init/start/destroy phases
18-
- **Dependency Resolution**: Automatic topological sorting based on plugin dependencies
1914

2015
## Installation
2116

@@ -28,7 +23,8 @@ npm install @objectstack/runtime
2823
### Basic Setup (Recommended)
2924

3025
```typescript
31-
import { ObjectKernel, ObjectQLPlugin, DriverPlugin } from '@objectstack/runtime';
26+
import { ObjectKernel } from '@objectstack/core';
27+
import { ObjectQLPlugin, DriverPlugin, AppManifestPlugin } from '@objectstack/runtime';
3228
import { InMemoryDriver } from '@objectstack/driver-memory';
3329

3430
const kernel = new ObjectKernel();

0 commit comments

Comments
 (0)