Skip to content

Commit f08ffc3

Browse files
feat: improve client route type safety and add changeset entry
- Extract ApiRouteType from ApiRoutes keys for type-safe route resolution - Add 'discovery' route to client fallback map - Remove 'as any' type casting in client route access - Add changeset entry documenting all discovery routing changes Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/283e383b-284b-40fe-af98-c11f61a4c8a8 Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
1 parent 7e3bf60 commit f08ffc3

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
"@objectstack/spec": minor
3+
"@objectstack/client": minor
4+
"@objectstack/runtime": patch
5+
"@objectstack/express": patch
6+
"@objectstack/fastify": patch
7+
"@objectstack/hono": patch
8+
"@objectstack/nestjs": patch
9+
"@objectstack/nextjs": patch
10+
"@objectstack/nuxt": patch
11+
"@objectstack/sveltekit": patch
12+
---
13+
14+
Fix discovery API endpoint routing and protocol consistency.
15+
16+
**Discovery route standardization:**
17+
- All adapters (Express, Fastify, Hono, NestJS, Next.js, Nuxt, SvelteKit) now mount the discovery endpoint at `{prefix}/discovery` instead of `{prefix}` root.
18+
- `.well-known/objectstack` redirects now point to `{prefix}/discovery`.
19+
- Client `connect()` fallback URL changed from `/api/v1` to `/api/v1/discovery`.
20+
- Runtime dispatcher handles both `/discovery` (standard) and `/` (legacy) for backward compatibility.
21+
22+
**Schema & route alignment:**
23+
- Added `storage` (service: `file-storage`) and `feed` (service: `data`) routes to `DEFAULT_DISPATCHER_ROUTES`.
24+
- Added `feed` and `discovery` fields to `ApiRoutesSchema`.
25+
- Unified `GetDiscoveryResponseSchema` with `DiscoverySchema` as single source of truth.
26+
- Client `getRoute('feed')` fallback updated from `/api/v1/data` to `/api/v1/feed`.
27+
28+
**Type safety:**
29+
- Extracted `ApiRouteType` from `ApiRoutes` keys for type-safe client route resolution.
30+
- Removed `as any` type casting in client route access.

packages/client/src/index.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,17 @@ import {
8787
SubscribeResponse,
8888
UnsubscribeResponse,
8989
WellKnownCapabilities,
90+
ApiRoutes,
9091
} from '@objectstack/spec/api';
9192
import { Logger, createLogger } from '@objectstack/core';
9293

94+
/**
95+
* Route types that the client can resolve.
96+
* Covers all keys from `ApiRoutes` (the discovery schema) plus
97+
* client-specific virtual routes (`views`, `permissions`).
98+
*/
99+
export type ApiRouteType = keyof ApiRoutes | 'views' | 'permissions';
100+
93101
export interface ClientConfig {
94102
baseUrl: string;
95103
token?: string;
@@ -1677,16 +1685,18 @@ export class ObjectStackClient {
16771685
* Get the conventional route path for a given API endpoint type
16781686
* ObjectStack uses standard conventions: /api/v1/data, /api/v1/meta, /api/v1/ui
16791687
*/
1680-
private getRoute(type: 'data' | 'metadata' | 'ui' | 'auth' | 'analytics' | 'storage' | 'automation' | 'packages' | 'permissions' | 'realtime' | 'workflow' | 'views' | 'notifications' | 'ai' | 'i18n' | 'feed'): string {
1688+
private getRoute(type: ApiRouteType): string {
16811689
// 1. Use discovered routes if available
1682-
if (this.discoveryInfo?.routes && (this.discoveryInfo.routes as any)[type]) {
1683-
return (this.discoveryInfo.routes as any)[type];
1690+
const routes = this.discoveryInfo?.routes;
1691+
if (routes && type in routes) {
1692+
return routes[type as keyof ApiRoutes] as string;
16841693
}
16851694

16861695
// 2. Fallback to conventions
1687-
const routeMap: Record<string, string> = {
1696+
const routeMap: Record<ApiRouteType, string> = {
16881697
data: '/api/v1/data',
16891698
metadata: '/api/v1/meta',
1699+
discovery: '/api/v1/discovery',
16901700
ui: '/api/v1/ui',
16911701
auth: '/api/v1/auth',
16921702
analytics: '/api/v1/analytics',
@@ -1701,6 +1711,7 @@ export class ObjectStackClient {
17011711
ai: '/api/v1/ai',
17021712
i18n: '/api/v1/i18n',
17031713
feed: '/api/v1/feed',
1714+
graphql: '/graphql',
17041715
};
17051716

17061717
return routeMap[type] || `/api/v1/${type}`;

0 commit comments

Comments
 (0)