Skip to content

Commit fcb1370

Browse files
committed
优化插件注册逻辑,支持模块导入,更新对象注册和贡献处理;修复默认路由和类型映射
1 parent 93f45a2 commit fcb1370

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
lines changed

examples/objectql/src/engine.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,34 @@ export class ObjectQL {
3333
async use(manifestPart: any, runtimePart?: any) {
3434
// 1. Validate / Register Manifest
3535
if (manifestPart) {
36+
// 1. Handle Module Imports (commonjs/esm interop)
37+
// If the passed object is a module namespace with a default export, use that.
38+
const manifest = manifestPart.default || manifestPart;
39+
3640
// In a real scenario, we might strictly parse this using Zod
3741
// For now, simple ID check
38-
const id = manifestPart.id;
42+
const id = manifest.id || manifest.name;
3943
if (!id) {
40-
console.warn('[ObjectQL] Plugin manifest missing ID', manifestPart);
41-
return;
44+
console.warn(`[ObjectQL] Plugin manifest missing ID (keys: ${Object.keys(manifest)})`, manifest);
45+
// Don't return, try to proceed if it looks like an App (Apps might use 'name' instead of 'id')
46+
// return;
4247
}
4348

4449
console.log(`[ObjectQL] Loading Plugin: ${id}`);
45-
SchemaRegistry.registerPlugin(manifestPart as ObjectStackManifest);
50+
SchemaRegistry.registerPlugin(manifest as ObjectStackManifest);
51+
52+
// Register Objects from App/Plugin
53+
if (manifest.objects) {
54+
for (const obj of manifest.objects) {
55+
// Ensure object name is registered globally
56+
SchemaRegistry.registerObject(obj);
57+
console.log(`[ObjectQL] Registered Object: ${obj.name}`);
58+
}
59+
}
4660

4761
// Register contributions
48-
if (manifestPart.contributes?.kinds) {
49-
for (const kind of manifestPart.contributes.kinds) {
62+
if (manifest.contributes?.kinds) {
63+
for (const kind of manifest.contributes.kinds) {
5064
SchemaRegistry.registerKind(kind);
5165
}
5266
}

examples/server/public/index.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
.badge { padding: 4px 8px; border-radius: 12px; font-size: 12px; }
1414
.badge-done { background: #e3fcef; color: #0d7f56; }
1515
.badge-todo { background: #fff8c5; color: #9a6700; }
16+
.badge-true { background: #e3fcef; color: #0d7f56; }
17+
.badge-false { background: #fff8c5; color: #9a6700; }
1618
</style>
1719
</head>
1820
<body>
@@ -83,9 +85,13 @@
8385
let cellContent = val;
8486

8587
// 根据 Schema 类型或 View 组件进行特殊渲染
86-
if ((col.widget === 'badge' || fieldConfig.type === 'select') && val) {
88+
if ((col.widget === 'badge' || fieldConfig.type === 'select' || typeof val === 'boolean') && val !== undefined) {
8789
const badgeClass = `badge-${String(val).toLowerCase()}`;
8890
cellContent = `<span class="badge ${badgeClass}">${val}</span>`;
91+
} else if (fieldConfig.type === 'date' && val) {
92+
cellContent = new Date(val).toLocaleDateString();
93+
} else if (fieldConfig.type === 'rating') {
94+
cellContent = '★'.repeat(Number(val)) + '☆'.repeat(3 - Number(val));
8995
}
9096

9197
html += `<td>${cellContent}</td>`;
@@ -101,8 +107,8 @@
101107
// 启动应用
102108
const ui = new ObjectUIRenderer('app');
103109
// 'Todo' 是 TodoApp 里的对象名 (注意大小写,SchemaRegistry 也许是敏感的,取决于 TodoApp 定义)
104-
// 假设 TodoApp 定义的是 'Todo'
105-
ui.renderList('Todo');
110+
// TodoApp 定义的是 'todo_task'
111+
ui.renderList('todo_task');
106112

107113
</script>
108114
</body>

examples/server/src/index.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import { DataEngine } from './kernel/engine';
1010
const app = new Hono();
1111
const dataEngine = new DataEngine(); // Engine loads plugins internally now
1212

13+
app.use('*', logger());
14+
app.use('*', cors());
15+
16+
// Default Route: Serve Client Lite
17+
app.get('/', serveStatic({ root: './public', path: 'index.html' }));
18+
app.get('/index.html', serveStatic({ root: './public', path: 'index.html' }));
19+
1320
// 3. Define Unified Routes
1421

1522
/**
@@ -85,16 +92,16 @@ app.get('/api/v1/meta/:type/:name', (c) => {
8592
const typePlural = c.req.param('type');
8693
const name = c.req.param('name');
8794

88-
// const typeMap: Record<string, string> = {
89-
// 'objects': 'object',
90-
// 'apps': 'app',
91-
// 'flows': 'flow',
92-
// 'reports': 'report',
93-
// 'plugins': 'plugin',
94-
// 'kinds': 'kind'
95-
// };
96-
// const type = typeMap[typePlural] || typePlural;
97-
const type = typePlural; // Direct pass-through
95+
const typeMap: Record<string, string> = {
96+
'objects': 'object',
97+
'apps': 'app',
98+
'flows': 'flow',
99+
'reports': 'report',
100+
'plugins': 'plugin',
101+
'kinds': 'kind'
102+
};
103+
const type = typeMap[typePlural] || typePlural;
104+
// const type = typePlural; // Direct pass-through
98105

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

0 commit comments

Comments
 (0)