Skip to content

Commit

Permalink
🔧 fix(treaty2): incorrect fetch on path collection
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Mar 11, 2024
1 parent bfec8c7 commit cd8b04e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
23 changes: 6 additions & 17 deletions example/a.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { Elysia, t } from 'elysia'
import { treaty } from '../src'

export const app = new Elysia({ prefix: '/level' })
.get('/a', '2')
.get('/:id', ({ params: { id } }) => id)
.get('/:id/a', ({ params: { id } }) => id)
const testRouter = new Elysia()
.group('/test/:testId', (app) => app.get('/test', () => 'hi'))
.listen(3005)

type Res = typeof app._routes
const testTreaty = treaty<typeof testRouter>('http://localhost:3005')

const api = treaty<typeof app>('localhost:3000')

type A = {
a: 'a'
// ':b': 'b'
}

type C = Extract<keyof A, `:${string}`> extends string ? true : false

type B = Extract<keyof A, `:${string}`> extends infer Path extends string
? Path
: never
console.log(await testTreaty.test({ testId: '1' }).test.get())
// Error: undefined is not an object (evaluating 'testTreaty.test({ testId: "1" }).test.get')
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elysiajs/eden",
"version": "1.0.0-rc.3",
"version": "1.0.0-rc.4",
"description": "Fully type-safe Elysia client",
"author": {
"name": "saltyAom",
Expand Down
8 changes: 4 additions & 4 deletions src/treaty2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const createProxy = (
elysia
)
},
apply(_, __, [body, options = {}]) {
apply(_, __, [body, options]) {
if (
!body ||
options ||
Expand Down Expand Up @@ -118,7 +118,7 @@ const createProxy = (
typeof config.headers === 'function' &&
!(headers instanceof Headers)
) {
const temp = config.headers(path, options)
const temp = config.headers(path, options ?? {})

if (temp) {
// @ts-expect-error
Expand All @@ -132,7 +132,7 @@ const createProxy = (
config.headers.every((x) => typeof x === 'function')
)
for (const value of config.headers as Function[]) {
const temp = value(path, options)
const temp = value(path, options ?? {})

if (temp)
headers = {
Expand Down Expand Up @@ -181,7 +181,7 @@ const createProxy = (
return false
})
: typeof headers === 'function'
? headers(path, options)
? headers(path, options ?? {})
: headers?.contentType) ||
options?.headers?.contentType

Expand Down

0 comments on commit cd8b04e

Please sign in to comment.