Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/scripts/generate_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ function routeToRegistryEntry(route: RouteInfo): string {
return ` '${route.routeName}': {
methods: [${route.methods.map((m) => `'${m}'`).join(', ')}],
pattern: '${route.pattern}',
domain: 'root',
tokens: [],
types: placeholder as {
body: ${route.body}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/backend/generate_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function generateRuntimeRegistryEntry(route: ScannedRoute): string {
return ` '${routeName}': {
methods: ${JSON.stringify(route.methods)},
pattern: '${route.pattern}',
domain: '${route.domain}',
tokens: ${JSON.stringify(sanitizedTokens)},
types: placeholder as Registry['${routeName}']['types'],
}`
Expand Down Expand Up @@ -260,6 +261,7 @@ function generateTypesRegistryEntry(route: ScannedRoute): string {
return ` '${routeName}': {
methods: ${JSON.stringify(route.methods)}
pattern: '${route.pattern}'
domain: '${route.domain}'
types: {
body: ${bodyType}
paramsTuple: [${paramsTuple}]
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/client/tuyau.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Tuyau<
* Creates a URL builder instance for generating URLs based on the route registry
*/
#createUrlBuilder() {
const rootEntries = this.#entries.map(([name, entry]) => ({ name, domain: 'root', ...entry }))
const rootEntries = this.#entries.map(([name, entry]) => ({ name, ...entry }))
return createUrlBuilder({ root: rootEntries }, buildSearchParams as any)
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/client/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface SchemaEndpoint {
*/
export interface AdonisEndpoint extends SchemaEndpoint {
tokens: ClientRouteMatchItTokens[]
domain: string
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/core/tests/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ test.group('Client | Chained', () => {
'users.index': {
methods: ['GET'] as 'GET'[],
pattern: '/users',
domain: 'root',
tokens: [{ old: '/users', type: 0 as const, val: 'users', end: '' }],
types: {} as any as {
body: {}
Expand Down
12 changes: 12 additions & 0 deletions packages/core/tests/client_extras.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ test.group('Client | urlFor', () => {
})
})

test.group('Client | Registry domain', () => {
test('route definition includes domain property', ({ assert }) => {
const route = registry.routes['api.v1.teste']
assert.equal(route.domain, 'api')
})

test('route without explicit domain defaults to root', ({ assert }) => {
const route = registry.routes['users.index']
assert.equal(route.domain, 'root')
})
})

test.group('Client | Errors', () => {
test('throws error for non-existent pattern', async ({ assert }) => {
const tuyau = createTuyau({ baseUrl: 'http://localhost:3333', registry })
Expand Down
Loading