Skip to content

Commit bfe329f

Browse files
Copilothotlong
andcommitted
Update documentation files and fix mini-kernel build
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent e677937 commit bfe329f

File tree

1 file changed

+13
-47
lines changed

1 file changed

+13
-47
lines changed

packages/runtime/src/mini-kernel.ts

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin, PluginContext, RuntimePlugin, RuntimeContext } from './types.js';
1+
import { Plugin, PluginContext } from './types.js';
22
import { SchemaRegistry, ObjectQL } from '@objectstack/objectql';
33

44
/**
@@ -16,7 +16,7 @@ import { SchemaRegistry, ObjectQL } from '@objectstack/objectql';
1616
* - Plugins are loaded as equal building blocks
1717
*/
1818
export class ObjectKernel {
19-
private plugins: Map<string, Plugin | RuntimePlugin> = new Map();
19+
private plugins: Map<string, Plugin> = new Map();
2020
private services: Map<string, any> = new Map();
2121
private hooks: Map<string, Array<(...args: any[]) => void | Promise<void>>> = new Map();
2222
private state: 'idle' | 'initializing' | 'running' | 'stopped' = 'idle';
@@ -59,7 +59,7 @@ export class ObjectKernel {
5959
* Register a plugin
6060
* @param plugin - Plugin instance
6161
*/
62-
use(plugin: Plugin | RuntimePlugin) {
62+
use(plugin: Plugin) {
6363
if (this.state !== 'idle') {
6464
throw new Error('[Kernel] Cannot register plugins after bootstrap has started');
6565
}
@@ -77,8 +77,8 @@ export class ObjectKernel {
7777
* Resolve plugin dependencies using topological sort
7878
* @returns Ordered list of plugins
7979
*/
80-
private resolveDependencies(): (Plugin | RuntimePlugin)[] {
81-
const resolved: (Plugin | RuntimePlugin)[] = [];
80+
private resolveDependencies(): Plugin[] {
81+
const resolved: Plugin[] = [];
8282
const visited = new Set<string>();
8383
const visiting = new Set<string>();
8484

@@ -96,8 +96,8 @@ export class ObjectKernel {
9696

9797
visiting.add(pluginName);
9898

99-
// Visit dependencies first (for new Plugin interface)
100-
const deps = this.isNewPlugin(plugin) ? plugin.dependencies || [] : [];
99+
// Visit dependencies first
100+
const deps = plugin.dependencies || [];
101101
for (const dep of deps) {
102102
if (!this.plugins.has(dep)) {
103103
throw new Error(`[Kernel] Dependency '${dep}' not found for plugin '${pluginName}'`);
@@ -118,13 +118,6 @@ export class ObjectKernel {
118118
return resolved;
119119
}
120120

121-
/**
122-
* Type guard to check if plugin uses new interface
123-
*/
124-
private isNewPlugin(plugin: Plugin | RuntimePlugin): plugin is Plugin {
125-
return 'init' in plugin;
126-
}
127-
128121
/**
129122
* Bootstrap the kernel
130123
* 1. Resolve dependencies (topological sort)
@@ -146,44 +139,17 @@ export class ObjectKernel {
146139
// Phase 1: Init - Plugins register services
147140
this.context.logger.log('[Kernel] Phase 1: Init plugins...');
148141
for (const plugin of orderedPlugins) {
149-
if (this.isNewPlugin(plugin)) {
150-
this.context.logger.log(`[Kernel] Init: ${plugin.name}`);
151-
await plugin.init(this.context);
152-
} else {
153-
// Legacy RuntimePlugin support
154-
this.context.logger.log(`[Kernel] Init (legacy): ${plugin.name}`);
155-
if (plugin.install) {
156-
await plugin.install({ engine: this as any });
157-
}
158-
// Also handle old manifest-style plugins
159-
if ('objects' in plugin) {
160-
SchemaRegistry.registerPlugin(plugin as any);
161-
const objects = (plugin as any).objects;
162-
if (objects) {
163-
for (const obj of objects) {
164-
SchemaRegistry.registerObject(obj);
165-
this.context.logger.log(`[Kernel] Registered Object: ${obj.name}`);
166-
}
167-
}
168-
}
169-
}
142+
this.context.logger.log(`[Kernel] Init: ${plugin.name}`);
143+
await plugin.init(this.context);
170144
}
171145

172146
// Phase 2: Start - Plugins execute business logic
173147
this.context.logger.log('[Kernel] Phase 2: Start plugins...');
174148
this.state = 'running';
175149
for (const plugin of orderedPlugins) {
176-
if (this.isNewPlugin(plugin)) {
177-
if (plugin.start) {
178-
this.context.logger.log(`[Kernel] Start: ${plugin.name}`);
179-
await plugin.start(this.context);
180-
}
181-
} else {
182-
// Legacy RuntimePlugin support
183-
if (plugin.onStart) {
184-
this.context.logger.log(`[Kernel] Start (legacy): ${plugin.name}`);
185-
await plugin.onStart({ engine: this as any });
186-
}
150+
if (plugin.start) {
151+
this.context.logger.log(`[Kernel] Start: ${plugin.name}`);
152+
await plugin.start(this.context);
187153
}
188154
}
189155

@@ -208,7 +174,7 @@ export class ObjectKernel {
208174

209175
const orderedPlugins = Array.from(this.plugins.values()).reverse();
210176
for (const plugin of orderedPlugins) {
211-
if (this.isNewPlugin(plugin) && plugin.destroy) {
177+
if (plugin.destroy) {
212178
this.context.logger.log(`[Kernel] Destroy: ${plugin.name}`);
213179
await plugin.destroy();
214180
}

0 commit comments

Comments
 (0)