From cd8b04ea38bd1acdee5fd2c3a68a2016420bce82 Mon Sep 17 00:00:00 2001 From: saltyaom Date: Mon, 11 Mar 2024 20:30:44 +0700 Subject: [PATCH] :wrench: fix(treaty2): incorrect fetch on path collection --- example/a.ts | 23 ++++++----------------- package.json | 2 +- src/treaty2/index.ts | 8 ++++---- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/example/a.ts b/example/a.ts index f68a8b3..a3df4c0 100644 --- a/example/a.ts +++ b/example/a.ts @@ -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('http://localhost:3005') -const api = treaty('localhost:3000') - -type A = { - a: 'a' - // ':b': 'b' -} - -type C = Extract extends string ? true : false - -type B = Extract 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') diff --git a/package.json b/package.json index 362a4f7..dc2c2ae 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/treaty2/index.ts b/src/treaty2/index.ts index 9e25b02..9a2d088 100644 --- a/src/treaty2/index.ts +++ b/src/treaty2/index.ts @@ -75,7 +75,7 @@ const createProxy = ( elysia ) }, - apply(_, __, [body, options = {}]) { + apply(_, __, [body, options]) { if ( !body || options || @@ -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 @@ -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 = { @@ -181,7 +181,7 @@ const createProxy = ( return false }) : typeof headers === 'function' - ? headers(path, options) + ? headers(path, options ?? {}) : headers?.contentType) || options?.headers?.contentType