Skip to content
Merged
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
4 changes: 2 additions & 2 deletions packages/superagent-wrapper/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ type SuperagentLike<Req> = {
[K in h.Method]: (url: string) => Req;
};

type Response = {
export type Response = {
body: unknown;
status: number;
};

interface SuperagentRequest<Res extends Response> extends Promise<Res> {
export interface SuperagentRequest<Res extends Response> extends Promise<Res> {
ok(callback: (response: Res) => boolean): this;
query(params: Record<string, string | string[]>): this;
set(name: string, value: string): this;
Expand Down
12 changes: 9 additions & 3 deletions packages/superagent-wrapper/src/routes.ts
Original file line number Diff line number Diff line change
@@ -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<Req extends SuperAgentRequest, Spec extends h.ApiSpec> = {
export type ApiClient<
Req extends SuperagentRequest<Response>,
Spec extends h.ApiSpec,
> = {
[A in keyof Spec]: {
[B in keyof Spec[A] & h.Method]: BoundRequestFactory<Req, NonNullable<Spec[A][B]>>;
};
};

export const buildApiClient = <Req extends SuperAgentRequest, Spec extends h.ApiSpec>(
export const buildApiClient = <
Req extends SuperagentRequest<Response>,
Spec extends h.ApiSpec,
>(
requestFactory: RequestFactory<Req>,
spec: Spec,
): ApiClient<Req, Spec> => {
Expand Down