1- import { ServiceObject , App } from '@objectstack/spec' ;
1+ import { ServiceObject , App , ObjectStackManifest } from '@objectstack/spec' ;
22
33/**
44 * Global Schema Registry
55 * Unified storage for all metadata types (Objects, Apps, Flows, Layouts, etc.)
66 */
77export class SchemaRegistry {
8- // Nested Map: Type -> Name -> MetadataItem
8+ // Nested Map: Type -> Name/ID -> MetadataItem
99 private static metadata = new Map < string , Map < string , any > > ( ) ;
1010
1111 /**
1212 * Universal Register Method
13+ * @param type The category of metadata (e.g., 'object', 'app', 'plugin')
14+ * @param item The metadata item itself
15+ * @param keyField The property to use as the unique key (default: 'name')
1316 */
14- static registerItem < T extends { name : string } > ( type : string , item : T ) {
17+ static registerItem < T > ( type : string , item : T , keyField : keyof T = 'name' as keyof T ) {
1518 if ( ! this . metadata . has ( type ) ) {
1619 this . metadata . set ( type , new Map ( ) ) ;
1720 }
1821 const collection = this . metadata . get ( type ) ! ;
22+ const key = String ( item [ keyField ] ) ;
1923
20- if ( collection . has ( item . name ) ) {
21- console . warn ( `[Registry] Overwriting ${ type } : ${ item . name } ` ) ;
24+ if ( collection . has ( key ) ) {
25+ console . warn ( `[Registry] Overwriting ${ type } : ${ key } ` ) ;
2226 }
23- collection . set ( item . name , item ) ;
24- console . log ( `[Registry] Registered ${ type } : ${ item . name } ` ) ;
27+ collection . set ( key , item ) ;
28+ console . log ( `[Registry] Registered ${ type } : ${ key } ` ) ;
2529 }
2630
2731 /**
@@ -46,7 +50,7 @@ export class SchemaRegistry {
4650 * Object Helpers
4751 */
4852 static registerObject ( schema : ServiceObject ) {
49- this . registerItem ( 'object' , schema ) ;
53+ this . registerItem ( 'object' , schema , 'name' ) ;
5054 }
5155
5256 static getObject ( name : string ) : ServiceObject | undefined {
@@ -61,7 +65,7 @@ export class SchemaRegistry {
6165 * App Helpers
6266 */
6367 static registerApp ( app : App ) {
64- this . registerItem ( 'app' , app ) ;
68+ this . registerItem ( 'app' , app , 'name' ) ;
6569 }
6670
6771 static getApp ( name : string ) : App | undefined {
@@ -71,4 +75,26 @@ export class SchemaRegistry {
7175 static getAllApps ( ) : App [ ] {
7276 return this . listItems < App > ( 'app' ) ;
7377 }
78+
79+ /**
80+ * Plugin Helpers
81+ */
82+ static registerPlugin ( manifest : ObjectStackManifest ) {
83+ this . registerItem ( 'plugin' , manifest , 'id' ) ;
84+ }
85+
86+ static getAllPlugins ( ) : ObjectStackManifest [ ] {
87+ return this . listItems < ObjectStackManifest > ( 'plugin' ) ;
88+ }
89+
90+ /**
91+ * Kind (Metadata Type) Helpers
92+ */
93+ static registerKind ( kind : { id : string , globs : string [ ] } ) {
94+ this . registerItem ( 'kind' , kind , 'id' ) ;
95+ }
96+
97+ static getAllKinds ( ) : { id : string , globs : string [ ] } [ ] {
98+ return this . listItems ( 'kind' ) ;
99+ }
74100}
0 commit comments