@@ -20,38 +20,6 @@ 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-
5523/**
5624 * Unified Metadata API: List Items by Type
5725 * GET /api/v1/meta/objects
@@ -60,13 +28,14 @@ app.get('/api/v1/discovery', discoveryHandler);
6028app . get ( '/api/v1/meta/:type' , ( c ) => {
6129 const typePlural = c . req . param ( 'type' ) ;
6230
63- // Dynamic singularization:
64- // 1. Check hardcoded map (for exceptions like 'indexes' -> 'index' if needed)
65- // 2. Or fallback to removing trailing 's'
31+ // Simple singularization mapping (can be enhanced)
6632 const typeMap : Record < string , string > = {
67- // Add specific exceptions here if english pluralization rules fail
33+ 'objects' : 'object' ,
34+ 'apps' : 'app' ,
35+ 'flows' : 'flow' ,
36+ 'reports' : 'report'
6837 } ;
69- const type = typeMap [ typePlural ] || ( typePlural . endsWith ( 's' ) ? typePlural . slice ( 0 , - 1 ) : typePlural ) ;
38+ const type = typeMap [ typePlural ] || typePlural ;
7039
7140 const items = SchemaRegistry . listItems ( type ) ;
7241
@@ -93,8 +62,13 @@ app.get('/api/v1/meta/:type/:name', (c) => {
9362 const typePlural = c . req . param ( 'type' ) ;
9463 const name = c . req . param ( 'name' ) ;
9564
96- const typeMap : Record < string , string > = { } ;
97- const type = typeMap [ typePlural ] || ( typePlural . endsWith ( 's' ) ? typePlural . slice ( 0 , - 1 ) : typePlural ) ;
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 ;
9872
9973 const item = SchemaRegistry . getItem ( type , name ) ;
10074 if ( ! item ) return c . json ( { error : `Metadata not found: ${ type } /${ name } ` } , 404 ) ;
0 commit comments