-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmini-kernel-example.ts
More file actions
75 lines (65 loc) · 2.21 KB
/
Copy pathmini-kernel-example.ts
File metadata and controls
75 lines (65 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* MiniKernel Architecture Example
*
* This example demonstrates the new ObjectKernel (MiniKernel) architecture
* where ObjectQL, Drivers, and HTTP Server are all equal plugins.
*/
import { ObjectKernel, ObjectQLPlugin, DriverPlugin } from '@objectstack/runtime';
// Mock driver for demonstration
const mockDriver = {
name: 'memory-driver',
version: '1.0.0',
capabilities: {
crud: true,
query: true,
},
async connect() {
console.log('[MockDriver] Connected');
},
async disconnect() {
console.log('[MockDriver] Disconnected');
},
async find(objectName: string, query: any) {
console.log(`[MockDriver] Finding in ${objectName}:`, query);
return [];
},
async findOne(objectName: string, id: string) {
console.log(`[MockDriver] Finding one in ${objectName}:`, id);
return null;
},
async create(objectName: string, data: any) {
console.log(`[MockDriver] Creating in ${objectName}:`, data);
return { id: 'mock-id', ...data };
},
async update(objectName: string, id: string, data: any) {
console.log(`[MockDriver] Updating ${objectName}/${id}:`, data);
return { id, ...data };
},
async delete(objectName: string, id: string) {
console.log(`[MockDriver] Deleting ${objectName}/${id}`);
return { id };
},
registerDriver(driver: any) {
// Mock implementation
},
};
async function main() {
console.log('🚀 Starting MiniKernel Example\n');
// Create kernel instance
const kernel = new ObjectKernel();
// Register plugins in any order - kernel will resolve dependencies
kernel
.use(new DriverPlugin(mockDriver, 'memory')) // Depends on ObjectQL
.use(new ObjectQLPlugin()); // No dependencies
// Bootstrap the kernel
await kernel.bootstrap();
// Access services
console.log('\n📦 Accessing Services:');
const objectql = kernel.getService('objectql');
console.log('✅ ObjectQL service available:', !!objectql);
console.log('\n✅ MiniKernel example completed successfully!\n');
// Shutdown
await kernel.shutdown();
}
// Run example
main().catch(console.error);