From 6a0b6473d3d28cd20df3c17f85e625362443a399 Mon Sep 17 00:00:00 2001 From: Patrick McLaughlin Date: Wed, 27 Sep 2023 10:10:46 -0400 Subject: [PATCH] fix: remove import of type from `superagent` --- packages/superagent-wrapper/src/request.ts | 4 ++-- packages/superagent-wrapper/src/routes.ts | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/superagent-wrapper/src/request.ts b/packages/superagent-wrapper/src/request.ts index 41c675a1..b269948a 100644 --- a/packages/superagent-wrapper/src/request.ts +++ b/packages/superagent-wrapper/src/request.ts @@ -51,12 +51,12 @@ type SuperagentLike = { [K in h.Method]: (url: string) => Req; }; -type Response = { +export type Response = { body: unknown; status: number; }; -interface SuperagentRequest extends Promise { +export interface SuperagentRequest extends Promise { ok(callback: (response: Res) => boolean): this; query(params: Record): this; set(name: string, value: string): this; diff --git a/packages/superagent-wrapper/src/routes.ts b/packages/superagent-wrapper/src/routes.ts index 7b9d31eb..852e1029 100644 --- a/packages/superagent-wrapper/src/routes.ts +++ b/packages/superagent-wrapper/src/routes.ts @@ -1,15 +1,21 @@ import * as h from '@api-ts/io-ts-http'; -import type { SuperAgentRequest } from 'superagent'; +import type { SuperagentRequest, Response } from './request'; import { requestForRoute, BoundRequestFactory, RequestFactory } from './request'; -export type ApiClient = { +export type ApiClient< + Req extends SuperagentRequest, + Spec extends h.ApiSpec, +> = { [A in keyof Spec]: { [B in keyof Spec[A] & h.Method]: BoundRequestFactory>; }; }; -export const buildApiClient = ( +export const buildApiClient = < + Req extends SuperagentRequest, + Spec extends h.ApiSpec, +>( requestFactory: RequestFactory, spec: Spec, ): ApiClient => {