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