From 89479ae6001a0c499b8ab2a5bbe27e739cebbe3e Mon Sep 17 00:00:00 2001 From: OpenInt Bot Date: Sun, 22 Dec 2024 22:51:46 -0800 Subject: [PATCH] refactor: httpMethod --- packages/fetch-links/link.ts | 24 ++++++++++++++---------- packages/fetch-links/package.json | 1 + packages/runtime/createClient.ts | 12 +----------- pnpm-lock.yaml | 3 +++ 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/packages/fetch-links/link.ts b/packages/fetch-links/link.ts index c32e1af..d27861b 100644 --- a/packages/fetch-links/link.ts +++ b/packages/fetch-links/link.ts @@ -1,13 +1,17 @@ -/** TODO: Leverage typescript helper instead. */ -export type HTTPMethod = - | 'GET' - | 'PUT' - | 'POST' - | 'DELETE' - | 'OPTIONS' - | 'HEAD' - | 'PATCH' - | 'TRACE' +import type {HttpMethod} from 'openapi-typescript-helpers' + +export const HTTP_METHODS = [ + 'GET', + 'PUT', + 'POST', + 'DELETE', + 'OPTIONS', + 'HEAD', + 'PATCH', + 'TRACE', +] satisfies ReadonlyArray> + +export type HTTPMethod = (typeof HTTP_METHODS)[number] /** * The BetterRequest object is an extension of the native [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) diff --git a/packages/fetch-links/package.json b/packages/fetch-links/package.json index 580064f..950b91e 100644 --- a/packages/fetch-links/package.json +++ b/packages/fetch-links/package.json @@ -43,6 +43,7 @@ "devDependencies": { "axios": "^1.6.2", "concurrently": "^8.2.2", + "openapi-typescript-helpers": "^0.0.15", "type-fest": "^4.28.0" }, "publishConfig": { diff --git a/packages/runtime/createClient.ts b/packages/runtime/createClient.ts index 4faad38..a1cec2a 100644 --- a/packages/runtime/createClient.ts +++ b/packages/runtime/createClient.ts @@ -16,6 +16,7 @@ import { applyLinks, authLink, fetchLink, + HTTP_METHODS, // type HTTPMethod, type Link, } from '@opensdks/fetch-links' @@ -39,17 +40,6 @@ export type OpenAPIClient = ReturnType< // to get a list of servers and all that? // Really do feel that they should be generated as well.. -const HTTP_METHODS = [ - 'GET', - 'PUT', - 'POST', - 'DELETE', - 'OPTIONS', - 'HEAD', - 'PATCH', - 'TRACE', -] satisfies ReadonlyArray> - export function createClient< Paths extends {}, Media extends MediaType = MediaType, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3383d65..e885aa0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -177,6 +177,9 @@ importers: concurrently: specifier: ^8.2.2 version: 8.2.2 + openapi-typescript-helpers: + specifier: ^0.0.15 + version: 0.0.15 type-fest: specifier: ^4.28.0 version: 4.28.0