Skip to content

Commit 8b05bd4

Browse files
committed
feat: add MetadataPlugin for dynamic metadata loading and register demo object
1 parent ef211e0 commit 8b05bd4

4 files changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: metadata_demo
2+
label: Metadata Demo Object
3+
fields:
4+
name:
5+
type: text
6+
label: Name

examples/host/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@objectstack/driver-memory": "workspace:*",
1212
"@objectstack/example-crm": "workspace:*",
1313
"@objectstack/example-todo": "workspace:*",
14+
"@objectstack/metadata": "workspace:*",
1415
"@objectstack/objectql": "workspace:*",
1516
"@objectstack/plugin-bi": "workspace:*",
1617
"@objectstack/plugin-hono-server": "workspace:*",

examples/host/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { ObjectKernel, DriverPlugin, AppPlugin } from '@objectstack/runtime';
22
import { InMemoryDriver } from '@objectstack/driver-memory';
33
import { ObjectQLPlugin } from '@objectstack/objectql';
44
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
5+
import { MetadataPlugin } from './metadata-plugin';
6+
import path from 'path';
57

68
import CrmApp from '@objectstack/example-crm/objectstack.config';
79
import TodoApp from '@objectstack/example-todo/objectstack.config';
@@ -14,6 +16,10 @@ import BiPluginManifest from '@objectstack/plugin-bi/objectstack.config';
1416
const kernel = new ObjectKernel();
1517

1618
kernel
19+
// Register Metadata Plugin (File System Loader)
20+
// Best Practice: Load metadata early so it's available for other plugins
21+
.use(new MetadataPlugin(path.resolve(__dirname, '../metadata')))
22+
1723
// Register ObjectQL engine
1824
.use(new ObjectQLPlugin())
1925

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Plugin, PluginContext } from '@objectstack/core';
2+
import { MetadataManager } from '@objectstack/metadata';
3+
import path from 'path';
4+
5+
export class MetadataPlugin implements Plugin {
6+
name = 'metadata-loader';
7+
private manager: MetadataManager;
8+
9+
constructor(private rootDir: string) {
10+
this.manager = new MetadataManager({
11+
rootDir: this.rootDir,
12+
watch: true,
13+
formats: ['yaml', 'json', 'typescript']
14+
});
15+
}
16+
17+
async init(ctx: PluginContext) {
18+
ctx.logger.info('Initializing Metadata Manager', { root: this.rootDir });
19+
20+
// Register Metadata Manager as a service
21+
// This allows other plugins to query raw metadata or listen to changes
22+
ctx.registerService('metadata', this.manager);
23+
}
24+
25+
async start(ctx: PluginContext) {
26+
ctx.logger.info('Loading metadata...');
27+
28+
// Example: Load all objects from the 'objects' directory
29+
// and register them with the App or ObjectQL service
30+
// Note: In a real implementation, we would recursively load all supported types
31+
32+
// We can access the ObjectQL service if it's registered
33+
// const ql = ctx.getService('objectql');
34+
}
35+
}

0 commit comments

Comments
 (0)