|
1 | 1 | import { SchemaRegistry } from './kernel/registry'; |
2 | 2 | import { AppSchema, ManifestSchema, App, ObjectStackManifest } from '@objectstack/spec'; |
3 | 3 |
|
4 | | -// In a real monorepo scenario, we might use path aliases or require.resolve |
5 | | -// Here we use relative paths to demonstrate loading from the sibling packages |
| 4 | +// Import from packages |
6 | 5 | // @ts-ignore |
7 | | -import CrmApp from '../../crm/objectstack.config'; |
| 6 | +import CrmApp from '@objectstack/example-crm/objectstack.config'; |
8 | 7 | // @ts-ignore |
9 | | -import TodoApp from '../../todo/objectstack.config'; |
| 8 | +import TodoApp from '@objectstack/example-todo/objectstack.config'; |
10 | 9 | // @ts-ignore |
11 | | -import BiPlugin from '../../plugin-bi/objectstack.config'; |
| 10 | +import BiPluginManifest from '@objectstack/plugin-bi/objectstack.config'; |
| 11 | +import BiPluginRuntime from '@objectstack/plugin-bi'; |
12 | 12 |
|
13 | | -export function loadPlugins() { |
14 | | - const packages: any[] = [CrmApp, TodoApp, BiPlugin]; |
| 13 | +export async function loadPlugins() { |
| 14 | + const packages: any[] = [CrmApp, TodoApp, BiPluginManifest]; |
15 | 15 |
|
16 | 16 | for (const pkg of packages) { |
17 | 17 | if (!pkg) continue; |
18 | 18 |
|
19 | 19 | // Check if it's a Manifest (Plugin/Package) |
20 | 20 | if (pkg.type === 'plugin') { |
21 | 21 | const manifest = pkg as ObjectStackManifest; |
22 | | - console.log(`[Loader] Loading Plugin: ${manifest.id}`); |
| 22 | + console.log(`[Loader] Loading Plugin Manifest: ${manifest.id}`); |
23 | 23 |
|
24 | 24 | try { |
25 | | - const parsedPlugin = ManifestSchema.parse(manifest); |
26 | | - SchemaRegistry.registerPlugin(parsedPlugin); |
| 25 | + const parsedManifest = ManifestSchema.parse(manifest); |
| 26 | + SchemaRegistry.registerPlugin(parsedManifest); |
27 | 27 |
|
28 | | - if (parsedPlugin.contributes?.kinds) { |
29 | | - for (const kind of parsedPlugin.contributes.kinds) { |
| 28 | + // 1. Register Contributions (Static) |
| 29 | + if (parsedManifest.contributes?.kinds) { |
| 30 | + for (const kind of parsedManifest.contributes.kinds) { |
30 | 31 | SchemaRegistry.registerKind(kind); |
31 | 32 | } |
32 | 33 | } |
33 | 34 |
|
34 | | - // SIMULATION: Simulate the scanner loading a file matching the new Kind |
35 | | - // In a real system, this would be done by a file watcher detecting **/*.dataset.json |
36 | | - if (parsedPlugin.id === 'com.objectstack.bi') { |
| 35 | + // 2. Load Runtime (Dynamic Simulation) |
| 36 | + // In a real engine, this would use `import(manifest.extensions.runtime.entry)` |
| 37 | + if (manifest.id === 'com.objectstack.bi' && BiPluginRuntime) { |
| 38 | + const pluginDef = BiPluginRuntime.default || BiPluginRuntime; |
| 39 | + |
| 40 | + if (pluginDef.onEnable) { |
| 41 | + console.log(`[Loader] Executing Plugin Runtime: ${manifest.id}`); |
| 42 | + await pluginDef.onEnable({ |
| 43 | + logger: console, |
| 44 | + os: { |
| 45 | + // Mock System API |
| 46 | + registerService: (id: string, svc: any) => console.log(`[OS] Service Registered: ${id}`) |
| 47 | + }, |
| 48 | + ql: {}, // Mock ObjectQL |
| 49 | + services: { |
| 50 | + register: (id: string, svc: any) => console.log(`[Services] Registered ${id}`) |
| 51 | + } |
| 52 | + }); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + // 3. Simulate File Scanning (Mock) |
| 57 | + if (parsedManifest.id === 'com.objectstack.bi') { |
37 | 58 | SchemaRegistry.registerItem('bi.dataset', { |
38 | 59 | name: 'quarterly_sales', |
39 | 60 | label: 'Quarterly Sales Data', |
40 | 61 | source: 'sql_warehouse', |
41 | 62 | query: 'SELECT * FROM sales WHERE quarter = "Q4"' |
42 | 63 | }, 'name'); |
43 | | - console.log('[Loader] Simulated loading: quarterly_sales (bi.dataset)'); |
44 | 64 | } |
45 | 65 | } catch (e) { |
46 | 66 | console.error(`[Loader] Failed to load plugin ${manifest.id}`, e); |
|
0 commit comments