Skip to content

Commit 5c19750

Browse files
committed
refactor: remove MetadataLoader and ObjectQL plugin integration; add AppPlugin and DataPlugin
1 parent 26726e3 commit 5c19750

File tree

6 files changed

+75
-290
lines changed

6 files changed

+75
-290
lines changed

packages/kernel/src/loader.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.

packages/kernel/src/objectos.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import { ObjectQL } from '@objectql/core';
2-
import { MetadataLoader } from './loader';
3-
import { registerObjectQLPlugins } from './plugins/objectql';
2+
import { AppPlugin } from './plugins/app';
3+
import { DataPlugin } from './plugins/data';
44

55
export class ObjectOS extends ObjectQL {
6-
public readonly componentLoader: MetadataLoader;
76

87
constructor(config: { datasources?: any, packages?: string[] } = {}) {
98
super({
109
datasources: config.datasources || {},
11-
packages: config.packages
10+
packages: config.packages,
11+
plugins: [AppPlugin, DataPlugin]
1212
});
13-
14-
this.componentLoader = new MetadataLoader(this.metadata as any);
15-
registerObjectQLPlugins(this.componentLoader);
1613
}
1714

1815
async init(options?: any) {

packages/kernel/src/plugins/app.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as yaml from 'js-yaml';
2+
3+
export const AppPlugin = {
4+
name: 'objectos-app-loader',
5+
setup(app: any) {
6+
app.addLoader({
7+
name: 'app',
8+
glob: ['**/*.app.yml', '**/*.app.yaml'],
9+
handler: (ctx: any) => {
10+
try {
11+
const doc = yaml.load(ctx.content) as any;
12+
const id = doc.code || doc.id || doc.name;
13+
if (id) {
14+
ctx.registry.register('app', {
15+
type: 'app',
16+
id: id,
17+
path: ctx.file,
18+
package: ctx.packageName,
19+
content: doc
20+
});
21+
}
22+
} catch (e) {
23+
console.error(`Error loading app from ${ctx.file}:`, e);
24+
}
25+
}
26+
});
27+
}
28+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as yaml from 'js-yaml';
2+
import * as path from 'path';
3+
4+
export const DataPlugin = {
5+
name: 'objectos-data-loader',
6+
setup(app: any) {
7+
app.addLoader({
8+
name: 'data',
9+
glob: ['**/*.data.yml', '**/*.data.yaml'],
10+
handler: (ctx: any) => {
11+
try {
12+
const content = ctx.content;
13+
const data = yaml.load(content);
14+
if (!Array.isArray(data)) return;
15+
16+
const basename = path.basename(ctx.file);
17+
const objectName = basename.replace(/\.data\.ya?ml$/, '');
18+
19+
const entry = ctx.registry.getEntry('object', objectName);
20+
if (entry) {
21+
const config = entry.content as any;
22+
config.data = data;
23+
} else {
24+
console.warn(`Found data for unknown object '${objectName}' in ${ctx.file}`);
25+
}
26+
} catch (e) {
27+
console.error(`Error loading data from ${ctx.file}:`, e);
28+
}
29+
}
30+
});
31+
}
32+
}

packages/kernel/src/plugins/objectql.ts

Lines changed: 0 additions & 193 deletions
This file was deleted.

tsconfig.base.code-workspace

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
},
6+
{
7+
"path": "../objectql"
8+
}
9+
],
10+
"settings": {}
11+
}

0 commit comments

Comments
 (0)