Skip to content

Commit 86fc690

Browse files
committed
feat: 简化元数据 API 的类型处理,直接传递类型参数,移除不必要的映射
1 parent 0460127 commit 86fc690

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

examples/server/src/index.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,7 @@ console.log('--- Plugins Loaded ---');
2828
app.get('/api/v1/meta/:type', (c) => {
2929
const typePlural = c.req.param('type');
3030

31-
// Simple singularization mapping (can be enhanced)
32-
const typeMap: Record<string, string> = {
33-
'objects': 'object',
34-
'apps': 'app',
35-
'flows': 'flow',
36-
'reports': 'report',
37-
'plugins': 'plugin',
38-
'kinds': 'kind'
39-
};
40-
const type = typeMap[typePlural] || typePlural;
31+
const type = typePlural; // Direct pass-through for exact match with Registry keys
4132

4233
const items = SchemaRegistry.listItems(type);
4334

@@ -66,15 +57,16 @@ app.get('/api/v1/meta/:type/:name', (c) => {
6657
const typePlural = c.req.param('type');
6758
const name = c.req.param('name');
6859

69-
const typeMap: Record<string, string> = {
70-
'objects': 'object',
71-
'apps': 'app',
72-
'flows': 'flow',
73-
'reports': 'report',
74-
'plugins': 'plugin',
75-
'kinds': 'kind'
76-
};
77-
const type = typeMap[typePlural] || typePlural;
60+
// const typeMap: Record<string, string> = {
61+
// 'objects': 'object',
62+
// 'apps': 'app',
63+
// 'flows': 'flow',
64+
// 'reports': 'report',
65+
// 'plugins': 'plugin',
66+
// 'kinds': 'kind'
67+
// };
68+
// const type = typeMap[typePlural] || typePlural;
69+
const type = typePlural; // Direct pass-through
7870

7971
const item = SchemaRegistry.getItem(type, name);
8072
if (!item) return c.json({ error: `Metadata not found: ${type}/${name}` }, 404);

examples/server/src/loader.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ export function loadPlugins() {
2828
SchemaRegistry.registerKind(kind);
2929
}
3030
}
31+
32+
// SIMULATION: Simulate the scanner loading a file matching the new Kind
33+
// In a real system, this would be done by a file watcher detecting **/*.dataset.json
34+
if (parsedPlugin.id === 'com.objectstack.bi') {
35+
SchemaRegistry.registerItem('bi.dataset', {
36+
name: 'quarterly_sales',
37+
label: 'Quarterly Sales Data',
38+
source: 'sql_warehouse',
39+
query: 'SELECT * FROM sales WHERE quarter = "Q4"'
40+
}, 'name');
41+
console.log('[Loader] Simulated loading: quarterly_sales (bi.dataset)');
42+
}
43+
3144
continue;
3245
}
3346

0 commit comments

Comments
 (0)