Skip to content

Commit

Permalink
fixup!
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Pilar <[email protected]>
  • Loading branch information
Tomas Pilar committed Dec 5, 2023
1 parent 03ef7c6 commit b4c41ea
Show file tree
Hide file tree
Showing 7 changed files with 1,020 additions and 365 deletions.
22 changes: 5 additions & 17 deletions src/api/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import createClient, { FetchOptions } from 'openapi-fetch';

import { paths } from './schema.js';
import { FilterKeys } from '../utils/types.js';

import { components, paths } from './schema.js';

export type ApiClient = ReturnType<typeof createClient<paths>>;

Expand All @@ -10,23 +12,9 @@ export function createApiClient(
return createClient<paths>(...params);
}

type FilterKeys<Obj, Matchers> = {
[K in keyof Obj]: K extends Matchers ? Obj[K] : never;
}[keyof Obj];

type NestedOmit<T, K extends PropertyKey> = {
[P in keyof T as P extends K ? never : P]: NestedOmit<
T[P],
K extends `${Exclude<P, symbol>}.${infer R}` ? R : never
>;
};

type RawClientOptions<
export type ApiClientOptions<
METHOD extends keyof ApiClient,
PATH extends Parameters<ApiClient[METHOD]>[0],
> = FetchOptions<FilterKeys<paths[PATH], Lowercase<METHOD>>>;

export type ClientOptions<
METHOD extends keyof ApiClient,
PATH extends Parameters<ApiClient[METHOD]>[0],
> = NestedOmit<RawClientOptions<METHOD, PATH>, 'params.query.version'>;
export type ApiError = components['schemas'][keyof components['schemas']];
Loading

0 comments on commit b4c41ea

Please sign in to comment.