@@ -20,6 +20,38 @@ console.log('--- Plugins Loaded ---');
2020
2121// 3. Define Unified Routes
2222
23+ /**
24+ * Discovery Endpoint
25+ * Allows clients to dynamically discover API routes and capabilities.
26+ */
27+ const discoveryHandler = ( c : any ) => {
28+ return c . json ( {
29+ name : "ObjectStack Example Server" ,
30+ version : "0.1.0" ,
31+ environment : "development" ,
32+ routes : {
33+ data : "/api/v1/data" ,
34+ metadata : "/api/v1/meta" ,
35+ auth : "/api/v1/auth" , // Not implemented yet
36+ actions : "/api/v1/actions" ,
37+ storage : "/api/v1/storage" , // Not implemented yet
38+ } ,
39+ features : {
40+ graphql : false ,
41+ search : true ,
42+ files : false
43+ } ,
44+ locale : {
45+ default : "en-US" ,
46+ supported : [ "en-US" , "zh-CN" ] ,
47+ timezone : "UTC"
48+ }
49+ } ) ;
50+ } ;
51+
52+ app . get ( '/.well-known/objectstack' , discoveryHandler ) ;
53+ app . get ( '/api/v1/discovery' , discoveryHandler ) ;
54+
2355/**
2456 * Unified Metadata API: List Items by Type
2557 * GET /api/v1/meta/objects
@@ -28,14 +60,13 @@ console.log('--- Plugins Loaded ---');
2860app . get ( '/api/v1/meta/:type' , ( c ) => {
2961 const typePlural = c . req . param ( 'type' ) ;
3062
31- // Simple singularization mapping (can be enhanced)
63+ // Dynamic singularization:
64+ // 1. Check hardcoded map (for exceptions like 'indexes' -> 'index' if needed)
65+ // 2. Or fallback to removing trailing 's'
3266 const typeMap : Record < string , string > = {
33- 'objects' : 'object' ,
34- 'apps' : 'app' ,
35- 'flows' : 'flow' ,
36- 'reports' : 'report'
67+ // Add specific exceptions here if english pluralization rules fail
3768 } ;
38- const type = typeMap [ typePlural ] || typePlural ;
69+ const type = typeMap [ typePlural ] || ( typePlural . endsWith ( 's' ) ? typePlural . slice ( 0 , - 1 ) : typePlural ) ;
3970
4071 const items = SchemaRegistry . listItems ( type ) ;
4172
@@ -62,13 +93,8 @@ app.get('/api/v1/meta/:type/:name', (c) => {
6293 const typePlural = c . req . param ( 'type' ) ;
6394 const name = c . req . param ( 'name' ) ;
6495
65- const typeMap : Record < string , string > = {
66- 'objects' : 'object' ,
67- 'apps' : 'app' ,
68- 'flows' : 'flow' ,
69- 'reports' : 'report'
70- } ;
71- const type = typeMap [ typePlural ] || typePlural ;
96+ const typeMap : Record < string , string > = { } ;
97+ const type = typeMap [ typePlural ] || ( typePlural . endsWith ( 's' ) ? typePlural . slice ( 0 , - 1 ) : typePlural ) ;
7298
7399 const item = SchemaRegistry . getItem ( type , name ) ;
74100 if ( ! item ) return c . json ( { error : `Metadata not found: ${ type } /${ name } ` } , 404 ) ;
0 commit comments