Skip to content

Commit 58df19f

Browse files
Copilothotlong
andcommitted
fix: unify i18n service discovery and handler resolution logic
- Make getDiscoveryInfo() async using resolveService() fallback chain - Populate locale from actual i18n service instead of hardcoded values - Update all framework adapters and plugins to await getDiscoveryInfo() - Add discovery-handler consistency tests - Update CHANGELOG.md Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent d0bd7ac commit 58df19f

14 files changed

Lines changed: 196 additions & 44 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- **i18n service registration & state inconsistency** — Discovery API (`getDiscoveryInfo`) now uses
12+
the same async `resolveService()` fallback chain that request handlers (`handleI18n`) use, ensuring
13+
the reported service status is always consistent with actual runtime availability.
14+
- Discovery `locale` field is now populated from the actual i18n service (`getDefaultLocale`,
15+
`getLocales`) instead of being hardcoded, so clients get accurate locale information.
16+
- Updated all framework adapters (Hono, Express, Fastify, Next.js, NestJS, Nuxt, SvelteKit),
17+
the dispatcher plugin, and the MSW plugin to `await` the now-async `getDiscoveryInfo()`.
18+
1019
### Changed
1120
- Updated ROADMAP.md for v3.0 release preparation with full codebase scan results
1221
- Audited all @deprecated items: 14 in spec, 9 in runtime packages (23 total)

packages/adapters/express/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export function createExpressRouter(options: ExpressAdapterOptions): Router {
7171
};
7272

7373
// --- Discovery ---
74-
router.get('/', (_req: Request, res: Response) => {
75-
res.json({ data: dispatcher.getDiscoveryInfo(prefix) });
74+
router.get('/', async (_req: Request, res: Response) => {
75+
res.json({ data: await dispatcher.getDiscoveryInfo(prefix) });
7676
});
7777

7878
// --- Auth ---

packages/adapters/fastify/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export async function objectStackPlugin(fastify: FastifyInstance, options: Fasti
7070

7171
// --- Discovery ---
7272
fastify.get(`${prefix}`, async (_request: FastifyRequest, reply: FastifyReply) => {
73-
return reply.send({ data: dispatcher.getDiscoveryInfo(prefix) });
73+
return reply.send({ data: await dispatcher.getDiscoveryInfo(prefix) });
7474
});
7575

7676
// --- .well-known ---

packages/adapters/hono/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ export function createHonoApp(options: ObjectStackHonoOptions): Hono {
7272
};
7373

7474
// --- Discovery ---
75-
app.get(`${prefix}`, (c) => {
76-
return c.json({ data: dispatcher.getDiscoveryInfo(prefix) });
75+
app.get(`${prefix}`, async (c) => {
76+
return c.json({ data: await dispatcher.getDiscoveryInfo(prefix) });
7777
});
7878

7979
// --- .well-known ---

packages/adapters/nestjs/src/__mocks__/runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { vi } from 'vitest';
33

44
export class HttpDispatcher {
5-
getDiscoveryInfo = vi.fn().mockReturnValue({ version: '1.0' });
5+
getDiscoveryInfo = vi.fn().mockResolvedValue({ version: '1.0' });
66
handleGraphQL = vi.fn().mockResolvedValue({ data: {} });
77
handleAuth = vi.fn().mockResolvedValue({ handled: true, response: { status: 200, body: { ok: true } } });
88
handleMetadata = vi.fn().mockResolvedValue({ handled: true, response: { status: 200, body: [] } });

packages/adapters/nestjs/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ export class ObjectStackController {
9595

9696
// --- Discovery Endpoint ---
9797
@Get()
98-
discovery() {
99-
return { data: this.service.dispatcher.getDiscoveryInfo('/api') };
98+
async discovery() {
99+
return { data: await this.service.dispatcher.getDiscoveryInfo('/api') };
100100
}
101101

102102
@Post('graphql')

packages/adapters/nestjs/src/nestjs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ describe('ObjectStackController', () => {
136136
});
137137

138138
describe('discovery()', () => {
139-
it('returns discovery info from the dispatcher', () => {
140-
const result = controller.discovery();
139+
it('returns discovery info from the dispatcher', async () => {
140+
const result = await controller.discovery();
141141
expect(result).toEqual({ data: { version: '1.0' } });
142142
expect(service.dispatcher.getDiscoveryInfo).toHaveBeenCalledWith('/api');
143143
});

packages/adapters/nextjs/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function createRouteHandler(options: NextAdapterOptions) {
6060

6161
// --- 0. Discovery Endpoint ---
6262
if (segments.length === 0 && method === 'GET') {
63-
return NextResponse.json({ data: dispatcher.getDiscoveryInfo(options.prefix || '/api') });
63+
return NextResponse.json({ data: await dispatcher.getDiscoveryInfo(options.prefix || '/api') });
6464
}
6565

6666
try {

packages/adapters/nuxt/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ export function createH3Router(options: NuxtAdapterOptions): Router {
8282
// --- Discovery ---
8383
router.get(
8484
`${prefix}`,
85-
defineEventHandler(() => {
86-
return { data: dispatcher.getDiscoveryInfo(prefix) };
85+
defineEventHandler(async () => {
86+
return { data: await dispatcher.getDiscoveryInfo(prefix) };
8787
}),
8888
);
8989

packages/adapters/sveltekit/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function createRequestHandler(options: SvelteKitAdapterOptions) {
9797

9898
// --- Discovery ---
9999
if (segments.length === 0 && method === 'GET') {
100-
return new Response(JSON.stringify({ data: dispatcher.getDiscoveryInfo(prefix) }), {
100+
return new Response(JSON.stringify({ data: await dispatcher.getDiscoveryInfo(prefix) }), {
101101
status: 200,
102102
headers: { 'Content-Type': 'application/json' },
103103
});

0 commit comments

Comments
 (0)