Skip to content

Commit d4fe21b

Browse files
committed
feat(objectql): add service status report and enhance schema validation in registry
1 parent 77d3ce7 commit d4fe21b

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

packages/objectql/src/engine.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
DataEngineCountOptions
99
} from '@objectstack/spec/data';
1010
import { DriverInterface, IDataEngine, Logger, createLogger } from '@objectstack/core';
11+
import { CoreServiceName } from '@objectstack/spec/system';
1112
import { SchemaRegistry } from './registry.js';
1213

1314
export type HookHandler = (context: HookContext) => Promise<void> | void;
@@ -26,6 +27,9 @@ export interface ObjectQLHostContext {
2627
* ObjectQL Engine
2728
*
2829
* Implements the IDataEngine interface for data persistence.
30+
* Acts as the reference implementation for:
31+
* - CoreServiceName.data (CRUD)
32+
* - CoreServiceName.metadata (Schema Registry)
2933
*/
3034
export class ObjectQL implements IDataEngine {
3135
private drivers = new Map<string, DriverInterface>();
@@ -50,6 +54,19 @@ export class ObjectQL implements IDataEngine {
5054
this.logger.info('ObjectQL Engine Instance Created');
5155
}
5256

57+
/**
58+
* Service Status Report
59+
* Used by Kernel to verify health and capabilities.
60+
*/
61+
getStatus() {
62+
return {
63+
name: CoreServiceName.enum.data,
64+
status: 'running',
65+
version: '0.9.0',
66+
features: ['crud', 'query', 'aggregate', 'transactions', 'metadata']
67+
};
68+
}
69+
5370
/**
5471
* Expose the SchemaRegistry for plugins to register metadata
5572
*/

packages/objectql/src/registry.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { ServiceObject } from '@objectstack/spec/data';
2-
import { ObjectStackManifest } from '@objectstack/spec/system';
1+
import { ServiceObject, ObjectSchema } from '@objectstack/spec/data';
2+
import { ObjectStackManifest, ManifestSchema } from '@objectstack/spec/system';
3+
import { AppSchema } from '@objectstack/spec/ui';
34

45
/**
56
* Global Schema Registry
@@ -22,13 +23,40 @@ export class SchemaRegistry {
2223
const collection = this.metadata.get(type)!;
2324
const key = String(item[keyField]);
2425

26+
// Validation Hook
27+
try {
28+
this.validate(type, item);
29+
} catch (e: any) {
30+
console.error(`[Registry] Validation failed for ${type} ${key}: ${e.message}`);
31+
// For now, warn but don't crash, allowing partial/legacy loads
32+
// throw e;
33+
}
34+
2535
if (collection.has(key)) {
2636
console.warn(`[Registry] Overwriting ${type}: ${key}`);
2737
}
2838
collection.set(key, item);
2939
console.log(`[Registry] Registered ${type}: ${key}`);
3040
}
3141

42+
/**
43+
* Validate Metadata against Spec Zod Schemas
44+
*/
45+
static validate(type: string, item: any) {
46+
if (type === 'object') {
47+
return ObjectSchema.parse(item);
48+
}
49+
if (type === 'app') {
50+
// AppSchema might rely on Zod, imported via UI protocol
51+
return AppSchema.parse(item);
52+
}
53+
if (type === 'plugin') {
54+
return ManifestSchema.parse(item);
55+
}
56+
// Add more validations as needed
57+
return true;
58+
}
59+
3260
/**
3361
* Universal Unregister Method
3462
*/

0 commit comments

Comments
 (0)