Skip to content

Commit 2b80b2a

Browse files
committed
refactor: update package.json and app.ts to enhance metadata handling and improve object retrieval logic
1 parent 9dfb2bd commit 2b80b2a

4 files changed

Lines changed: 58 additions & 14 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "eslint packages",
1010
"format": "prettier --write \"packages/**/*.{ts,tsx,json,md}\"",
1111
"cli:dev": "ts-node packages/tools/cli/src/index.ts",
12-
"objectql": "node packages/tools/cli/dist/index.js",
12+
"objectql": "tsx packages/tools/cli/src/index.ts",
1313
"objectql:tracker": "pnpm objectql dev -d examples/showcase/project-tracker/src",
1414
"objectql:erp": "pnpm objectql dev -d examples/showcase/enterprise-erp/src",
1515
"check-versions": "node scripts/check-versions.js",
@@ -39,6 +39,7 @@
3939
"js-yaml": "^4.1.1",
4040
"supertest": "^7.2.2",
4141
"ts-jest": "^29.4.6",
42+
"tsx": "^4.21.0",
4243
"typescript": "^5.3.0",
4344
"typescript-eslint": "^8.53.0",
4445
"vite": "^7.3.1",

packages/foundation/core/src/app.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ export class ObjectQL implements IObjectQL {
9292

9393
// Stub legacy accessors
9494
(this.kernel as any).metadata = {
95-
register: (type: string, item: any) => SchemaRegistry.registerItem(type, item),
95+
register: (type: string, item: any) => SchemaRegistry.registerItem(type, item, item.id ? 'id' : 'name'),
9696
get: (type: string, name: string) => SchemaRegistry.getItem(type, name),
97+
getEntry: (type: string, name: string) => SchemaRegistry.getItem(type, name),
9798
list: (type: string) => SchemaRegistry.listItems(type),
9899
unregister: (type: string, name: string) => {
99100
// Access private static storage using any cast
@@ -318,14 +319,18 @@ export class ObjectQL implements IObjectQL {
318319
}
319320

320321
getObject(name: string): ObjectConfig | undefined {
321-
return (this.kernel as any).metadata.get('object', name) as ObjectConfig;
322+
const item = (this.kernel as any).metadata.get('object', name);
323+
return item?.content || item;
322324
}
323325

324326
getConfigs(): Record<string, ObjectConfig> {
325327
const result: Record<string, ObjectConfig> = {};
326-
const items = (this.kernel as any).metadata.list('object') as ObjectConfig[];
328+
const items = (this.kernel as any).metadata.list('object') || [];
327329
for (const item of items) {
328-
result[item.name] = item;
330+
const config = item.content || item;
331+
if (config?.name) {
332+
result[config.name] = config;
333+
}
329334
}
330335
return result;
331336
}
@@ -428,7 +433,8 @@ export class ObjectQL implements IObjectQL {
428433
}
429434
}
430435

431-
const objects = (this.kernel as any).metadata.list('object') as ObjectConfig[];
436+
const registryItems = (this.kernel as any).metadata.list('object');
437+
const objects = (registryItems || []).map((item: any) => item.content || item) as ObjectConfig[];
432438

433439
// Init Datasources
434440
// Let's pass all objects to all configured drivers.

packages/runtime/server/src/openapi.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ interface OpenAPISchema {
2121
}
2222

2323
export function generateOpenAPI(app: IObjectQL, routeConfig?: ApiRouteConfig): OpenAPISchema {
24-
const registry = (app as any).metadata; // Direct access or via interface
25-
const objects = registry.list('object') as ObjectConfig[];
24+
// Get objects using public API or fallback to registry unwrapping
25+
let objects: ObjectConfig[] = [];
26+
if (typeof (app as any).getConfigs === 'function') {
27+
objects = Object.values((app as any).getConfigs());
28+
} else {
29+
const registry = (app as any).metadata;
30+
const items = registry.list('object') || [];
31+
objects = items.map((item: any) => item.content || item);
32+
}
33+
2634
const routes = resolveApiRoutes(routeConfig);
2735

2836
const paths: Record<string, any> = {};

pnpm-lock.yaml

Lines changed: 35 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)