diff --git a/docs/examples.md b/docs/examples.md index d505b9b1a..80271bc94 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -78,66 +78,53 @@ try {
-feature-fetch by builder.group +feature-fetch by builder.group + +`feature-fetch` fits when you want OpenAPI-typed requests with explicit success and error branches. It types path strings, params, request bodies, and response data from generated `paths`. Each request returns `[ok, error, data]`, so failures stay visible at the call site and success branches narrow data. Retry, cache, hooks, and middleware can be added when the client needs production behavior. ::: code-group ```ts [test/my-project.ts] -import { createOpenApiFetchClient } from 'feature-fetch'; -import type { paths } from './my-openapi-3-schema'; // generated by openapi-typescript +import { + createOpenApiFetchClient, + hasStatusCode, + retryFeature, +} from "feature-fetch"; +import type { paths } from "./my-openapi-3-schema"; // generated by openapi-typescript -// Create the OpenAPI fetch client -const fetchClient = createOpenApiFetchClient({ - prefixUrl: 'https://myapi.dev/v1' -}); +const api = createOpenApiFetchClient({ + baseUrl: "https://myapi.dev/v1", +}).with(retryFeature({ maxRetries: 3 })); -// Send a GET request -const response = await fetchClient.get('/blogposts/{post_id}', { +const [isPostOk, postErr, post] = await api.get("/blogposts/{post_id}", { pathParams: { - post_id: '123', + post_id: "123", }, }); -// Handle the response (Approach 1: Standard if-else) -if (response.isOk()) { - const data = response.value.data; - console.log(data); // Handle successful response +if (isPostOk) { + console.log(post); // typed from the 2XX response schema +} else if (hasStatusCode(postErr, 404)) { + console.error("Post not found"); } else { - const error = response.error; - if (error instanceof NetworkError) { - console.error('Network error:', error.message); - } else if (error instanceof RequestError) { - console.error('Request error:', error.message, 'Status:', error.status); - } else { - console.error('Service error:', error.message); - } + console.error(postErr.message); // NetworkError | HttpError | FetchError } -// Send a PUT request -const putResponse = await fetchClient.put('/blogposts', { +const [isUpdateOk, updateErr] = await api.put("/blogposts", { body: { - title: 'My New Post', + title: "My New Post", // checked against the request body schema }, }); -// Handle the response (Approach 2: Try-catch) -try { - const putData = putResponse.unwrap().data; - console.log(putData); // Handle the successful response -} catch (error) { - // Handle the error - if (error instanceof NetworkError) { - console.error('Network error:', error.message); - } else if (error instanceof RequestError) { - console.error('Request error:', error.message, 'Status:', error.status); - } else { - console.error('Service error:', error.message); - } +if (!isUpdateOk) { + console.error(updateErr.message); } ``` ::: +[Full example](https://github.com/builder-group/community/tree/develop/examples/feature-fetch/vanilla/basic) +
@@ -259,126 +246,86 @@ TypeChecking in server environments can be tricky, as you’re often querying da ## Hono with [`openapi-ts-router`](https://github.com/builder-group/community/tree/develop/packages/openapi-ts-router) -[`openapi-ts-router`](https://github.com/builder-group/community/tree/develop/packages/openapi-ts-router) provides full type-safety and runtime validation for your HonoAPI routes by wrapping a [Hono router](https://hono.dev/docs/api/routing): - -::: tip Good to Know - -While TypeScript ensures compile-time type safety, runtime validation is equally important. `openapi-ts-router` integrates with Zod/Valibot to provide both: -- Types verify your code matches the OpenAPI spec during development -- Validators ensure incoming requests match the spec at runtime - -::: +[`openapi-ts-router`](https://github.com/builder-group/community/tree/develop/packages/openapi-ts-router) fits when server code should stay aligned with the OpenAPI document. It wraps a [Hono router](https://hono.dev/docs/api/routing) and lets route registration use OpenAPI path strings such as `/pet/{petId}`. TypeScript rejects unknown paths, wrong methods, missing required schemas, and JSON success responses that do not match the schema. Validate request parts with any [Standard Schema](https://standardschema.dev/) library, then read parsed values from `c.req.valid()`. ::: code-group ```ts [src/router.ts] -import { Hono } from 'hono'; -import { createHonoOpenApiRouter } from 'openapi-ts-router'; -import { zValidator } from 'validation-adapters/zod'; -import * as z from 'zod'; -import { paths } from './gen/v1'; // OpenAPI-generated types -import { PetSchema } from './schemas'; // Custom reusable schema for validation - -export const router = new Hono(); -export const openApiRouter = createHonoOpenApiRouter(router); - -// GET /pet/{petId} -openApiRouter.get('/pet/{petId}', { - pathValidator: zValidator( - z.object({ - petId: z.number() // Validate that petId is a number - }) - ), +import { Hono } from "hono"; +import { createHonoOpenApiRouter } from "openapi-ts-router/hono"; +import * as z from "zod"; +import type { paths } from "./my-openapi-3-schema"; // generated by openapi-typescript + +const app = new Hono(); +const openApiRouter = createHonoOpenApiRouter(app); + +openApiRouter.get("/pet/{petId}", { + pathSchema: z.object({ + petId: z.number(), + }), handler: (c) => { - const { petId } = c.req.valid('param'); // Access validated params - return c.json({ name: 'Falko', photoUrls: [] }); - } + const { petId } = c.req.valid("param"); + return c.json({ name: `Pet ${petId}`, photoUrls: [] }); + }, }); -// POST /pet -openApiRouter.post('/pet', { - bodyValidator: zValidator(PetSchema), // Validate request body using PetSchema +openApiRouter.post("/pet", { + bodySchema: z.object({ + name: z.string(), + photoUrls: z.array(z.string()), + }), handler: (c) => { - const { name, photoUrls } = c.req.valid('json'); // Access validated body data - return c.json({ name, photoUrls }); - } + const { name, photoUrls } = c.req.valid("json"); + return c.json({ name, photoUrls }); + }, }); - -// TypeScript will error if route/method doesn't exist in OpenAPI spec -// or if response doesn't match defined schema ``` ::: [Full example](https://github.com/builder-group/community/tree/develop/examples/openapi-ts-router/hono/petstore) -**Key benefits:** -- Full type safety for routes, methods, params, body and responses -- Runtime validation using Zod/Valibot -- Catches API spec mismatches at compile time -- Zero manual type definitions needed - ## Express with [`openapi-ts-router`](https://github.com/builder-group/community/tree/develop/packages/openapi-ts-router) -[`openapi-ts-router`](https://github.com/builder-group/community/tree/develop/packages/openapi-ts-router) provides full type-safety and runtime validation for your Express API routes by wrapping a [Express router](https://expressjs.com/en/5x/api.html#router): - -::: tip Good to Know - -While TypeScript ensures compile-time type safety, runtime validation is equally important. `openapi-ts-router` integrates with Zod/Valibot to provide both: -- Types verify your code matches the OpenAPI spec during development -- Validators ensure incoming requests match the spec at runtime - -::: +[`openapi-ts-router`](https://github.com/builder-group/community/tree/develop/packages/openapi-ts-router) fits when an existing Express API should stay aligned with the OpenAPI document. It wraps an [Express router](https://expressjs.com/en/5x/api.html#router) and lets route registration use OpenAPI path strings such as `/pet/{petId}`. TypeScript rejects unknown paths, wrong methods, missing required schemas, and JSON success responses that do not match the schema. Validate request parts with any [Standard Schema](https://standardschema.dev/) library, then read parsed values from `req.valid`. Mount `express.json()` before this router when validating JSON bodies. ::: code-group ```ts [src/router.ts] -import { Router } from 'express'; -import { createExpressOpenApiRouter } from 'openapi-ts-router'; -import * as z from 'zod'; -import { zValidator } from 'validation-adapters/zod'; -import { paths } from './gen/v1'; // OpenAPI-generated types -import { PetSchema } from './schemas'; // Custom reusable schema for validation - -export const router: Router = Router(); -export const openApiRouter = createExpressOpenApiRouter(router); - -// GET /pet/{petId} -openApiRouter.get('/pet/{petId}', { - pathValidator: zValidator( - z.object({ - petId: z.number() // Validate that petId is a number - }) - ), +import { Router } from "express"; +import { createExpressOpenApiRouter } from "openapi-ts-router/express"; +import * as z from "zod"; +import type { paths } from "./my-openapi-3-schema"; // generated by openapi-typescript + +const router = Router(); +const openApiRouter = createExpressOpenApiRouter(router); + +openApiRouter.get("/pet/{petId}", { + pathSchema: z.object({ + petId: z.number(), + }), handler: (req, res) => { - const { petId } = req.params; // Access validated params - res.send({ name: 'Falko', photoUrls: [] }); - } + const { petId } = req.valid.path; + res.json({ name: `Pet ${petId}`, photoUrls: [] }); + }, }); -// POST /pet -openApiRouter.post('/pet', { - bodyValidator: zValidator(PetSchema), // Validate request body using PetSchema +openApiRouter.post("/pet", { + bodySchema: z.object({ + name: z.string(), + photoUrls: z.array(z.string()), + }), handler: (req, res) => { - const { name, photoUrls } = req.body; // Access validated body data - res.send({ name, photoUrls }); - } + const { name, photoUrls } = req.valid.body; + res.json({ name, photoUrls }); + }, }); - -// TypeScript will error if route/method doesn't exist in OpenAPI spec -// or if response doesn't match defined schema ``` ::: [Full example](https://github.com/builder-group/community/tree/develop/examples/openapi-ts-router/express/petstore) -**Key benefits:** -- Full type safety for routes, methods, params, body and responses -- Runtime validation using Zod/Valibot -- Catches API spec mismatches at compile time -- Zero manual type definitions needed - ## Mock-Service-Worker (MSW) If you are using [Mock Service Worker (MSW)](https://mswjs.io) to define your API mocks, you can use a **small, automatically-typed wrapper** around MSW, which enables you to address conflicts in your API mocks easily when your OpenAPI specification changes. Ultimately, you can have the same level of confidence in your application's API client **and** API mocks. diff --git a/docs/introduction.md b/docs/introduction.md index cff0f2ac2..7643f9778 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -105,8 +105,9 @@ type ErrorResponse = From here, you can use these types for any of the following (but not limited to): -- Using an OpenAPI-supported fetch client (like [openapi-fetch](/openapi-fetch/)) +- Calling APIs from generated `paths` (like [openapi-fetch](/openapi-fetch/) or [feature-fetch](/examples#data-fetching)) - Asserting types for other API requestBodies and responses - Building core business logic based on API types +- Implementing server routes that compile against generated `paths` (like [openapi-ts-router](/examples#hono-with-openapi-ts-router)) - Validating mock test data is up-to-date with the current schema - Packaging API types into any npm packages you publish (such as client SDKs, etc.) diff --git a/docs/ja/examples.md b/docs/ja/examples.md index 53d50269d..9c6bc4cc1 100644 --- a/docs/ja/examples.md +++ b/docs/ja/examples.md @@ -80,66 +80,53 @@ try {
-feature-fetch by builder.group +feature-fetch by builder.group + +`feature-fetch` は、OpenAPI で型付けされた request と、明示的な success/error 分岐が欲しい場合に向いています。生成された `paths` から path strings、params、request body、response data を型付けします。各リクエストは `[ok, error, data]` を返すため、失敗時の処理が呼び出し箇所に残り、成功分岐では data の型が絞り込まれます。retry、cache、hooks、middleware は client に production 向けの挙動が必要になったときに追加できます。 ::: code-group ```ts [test/my-project.ts] -import { createOpenApiFetchClient } from "feature-fetch"; +import { + createOpenApiFetchClient, + hasStatusCode, + retryFeature, +} from "feature-fetch"; import type { paths } from "./my-openapi-3-schema"; // openapi-typescriptで生成された型 -// OpenAPI fetch クライアントを作成 -const fetchClient = createOpenApiFetchClient({ - prefixUrl: "https://myapi.dev/v1", -}); +const api = createOpenApiFetchClient({ + baseUrl: "https://myapi.dev/v1", +}).with(retryFeature({ maxRetries: 3 })); -// GET リクエストを送信 -const response = await fetchClient.get("/blogposts/{post_id}", { +const [isPostOk, postErr, post] = await api.get("/blogposts/{post_id}", { pathParams: { post_id: "123", }, }); -// レスポンスを処理する(アプローチ1:標準のif-else) -if (response.isOk()) { - const data = response.value.data; - console.log(data); // 成功したレスポンスを処理 +if (isPostOk) { + console.log(post); // 2XX response schema から型付けされる +} else if (hasStatusCode(postErr, 404)) { + console.error("Post not found"); } else { - const error = response.error; - if (error instanceof NetworkError) { - console.error("Network error:", error.message); - } else if (error instanceof RequestError) { - console.error("Request error:", error.message, "Status:", error.status); - } else { - console.error("Service error:", error.message); - } + console.error(postErr.message); // NetworkError | HttpError | FetchError } -// PUT リクエストを送信 -const putResponse = await fetchClient.put("/blogposts", { +const [isUpdateOk, updateErr] = await api.put("/blogposts", { body: { - title: "My New Post", + title: "My New Post", // request body schema と照合される }, }); -// レスポンスを処理する(アプローチ2:try-catch) -try { - const putData = putResponse.unwrap().data; - console.log(putData); // 成功したレスポンスを処理 -} catch (error) { - // エラーを処理 - if (error instanceof NetworkError) { - console.error("Network error:", error.message); - } else if (error instanceof RequestError) { - console.error("Request error:", error.message, "Status:", error.status); - } else { - console.error("Service error:", error.message); - } +if (!isUpdateOk) { + console.error(updateErr.message); } ``` ::: +[完全な例](https://github.com/builder-group/community/tree/develop/examples/feature-fetch/vanilla/basic) +
@@ -264,46 +251,36 @@ export default app; ## Hono と [`openapi-ts-router`](https://github.com/builder-group/community/tree/develop/packages/openapi-ts-router) -[Honoの例](#hono) のように、各ルートをジェネリックで手動で型付けする代わりに、[`openapi-ts-router`](https://github.com/builder-group/community/tree/develop/packages/openapi-ts-router) は、[Hono router](https://hono.dev/docs/api/routing) をラップして完全な型安全性を提供し、バリデーターを使用してOpenAPIスキーマを強制します。 - -::: tip 知っておくと良いこと - -TypeScriptの型はコンパイル時の安全性を保証しますが、実行時のスキーマ検証を強制するものではありません。実行時の検証を確保するためには、ZodやValibotなどのバリデーションライブラリと統合する必要があります。バリデーションルールを手動で定義する必要がありますが、それらは型安全であり、ルールが正しく定義されていることを保証します。 - -::: +[`openapi-ts-router`](https://github.com/builder-group/community/tree/develop/packages/openapi-ts-router) は、server code を OpenAPI document に沿って実装したい場合に向いています。[Hono router](https://hono.dev/docs/api/routing) をラップし、route registration では `/pet/{petId}` のような OpenAPI path strings をそのまま使えます。生成された `paths` に存在しない path や method、必須 schema の不足、schema に合わない JSON success response は TypeScript が拒否します。[Standard Schema](https://standardschema.dev/) library で request の各部分を検証し、handler では parse 済みの値を `c.req.valid()` から読み取れます。 ::: code-group ```ts [src/router.ts] -import { createHonoOpenApiRouter } from "openapi-ts-router"; import { Hono } from "hono"; -import { zValidator } from "validation-adapters/zod"; +import { createHonoOpenApiRouter } from "openapi-ts-router/hono"; import * as z from "zod"; +import type { paths } from "./my-openapi-3-schema"; // openapi-typescriptで生成された型 -import { paths } from "./gen/v1"; // openapi-typescriptで生成された型 -import { PetSchema } from "./schemas"; // 検証用の再利用可能なカスタムZodスキーマ - -export const router = new Hono(); -export const openApiRouter = createHonoOpenApiRouter(router); +const app = new Hono(); +const openApiRouter = createHonoOpenApiRouter(app); -// GET /pet/{petId} openApiRouter.get("/pet/{petId}", { - pathValidator: zValidator( - z.object({ - petId: z.number(), // petIdが数値であることを検証 - }) - ), + pathSchema: z.object({ + petId: z.number(), + }), handler: (c) => { - const { petId } = c.req.valid("param"); // 検証済みのパラメータにアクセス - return c.json({ name: "Falko", photoUrls: [] }); + const { petId } = c.req.valid("param"); + return c.json({ name: `Pet ${petId}`, photoUrls: [] }); }, }); -// POST /pet openApiRouter.post("/pet", { - bodyValidator: zValidator(PetSchema), // PetSchemaを使用してリクエストボディを検証 + bodySchema: z.object({ + name: z.string(), + photoUrls: z.array(z.string()), + }), handler: (c) => { - const { name, photoUrls } = c.req.valid("json"); // 検証済みのボディデータにアクセス + const { name, photoUrls } = c.req.valid("json"); return c.json({ name, photoUrls }); }, }); @@ -315,47 +292,37 @@ openApiRouter.post("/pet", { ## Express と [`openapi-ts-router`](https://github.com/builder-group/community/tree/develop/packages/openapi-ts-router) -[`openapi-ts-router`](https://github.com/builder-group/community/tree/develop/packages/openapi-ts-router) は、[Express ルーター](https://expressjs.com/en/5x/api.html#router) をラップして、完全な型安全性を提供し、バリデーターを使用して OpenAPI スキーマを強制します。 - -::: tip 知っておくと良いこと - -TypeScriptの型はコンパイル時の安全性を保証しますが、実行時のスキーマ検証を強制するものではありません。実行時の検証を確保するためには、ZodやValibotなどのバリデーションライブラリと統合する必要があります。バリデーションルールを手動で定義する必要がありますが、それらは型安全であり、ルールが正しく定義されていることを保証します。 - -::: +[`openapi-ts-router`](https://github.com/builder-group/community/tree/develop/packages/openapi-ts-router) は、既存の Express API を OpenAPI document に沿って実装したい場合に向いています。[Express router](https://expressjs.com/en/5x/api.html#router) をラップし、route registration では `/pet/{petId}` のような OpenAPI path strings をそのまま使えます。生成された `paths` に存在しない path や method、必須 schema の不足、schema に合わない JSON success response は TypeScript が拒否します。[Standard Schema](https://standardschema.dev/) library で request の各部分を検証し、handler では parse 済みの値を `req.valid` から読み取れます。JSON body を検証する場合は、この router の前に `express.json()` を mount してください。 ::: code-group ```ts [src/router.ts] -import { createExpressOpenApiRouter } from "openapi-ts-router"; import { Router } from "express"; -import * as v from "valibot"; -import { vValidator } from "validation-adapters/valibot"; - -import { paths } from "./gen/v1"; // openapi-typescriptで生成された型 -import { PetSchema } from "./schemas"; // 検証用の再利用可能なカスタムZodスキーマ +import { createExpressOpenApiRouter } from "openapi-ts-router/express"; +import * as z from "zod"; +import type { paths } from "./my-openapi-3-schema"; // openapi-typescriptで生成された型 -export const router: Router = Router(); -export const openApiRouter = createExpressOpenApiRouter(router); +const router = Router(); +const openApiRouter = createExpressOpenApiRouter(router); -// GET /pet/{petId} openApiRouter.get("/pet/{petId}", { - pathValidator: vValidator( - v.object({ - petId: v.number(), // petIdが数値であることを検証 - }) - ), + pathSchema: z.object({ + petId: z.number(), + }), handler: (req, res) => { - const { petId } = req.params; // 検証済みのパラメータにアクセス - res.send({ name: "Falko", photoUrls: [] }); + const { petId } = req.valid.path; + res.json({ name: `Pet ${petId}`, photoUrls: [] }); }, }); -// POST /pet openApiRouter.post("/pet", { - bodyValidator: vValidator(PetSchema), // PetSchemaを使用してリクエストボディを検証 + bodySchema: z.object({ + name: z.string(), + photoUrls: z.array(z.string()), + }), handler: (req, res) => { - const { name, photoUrls } = req.body; // 検証済みのボディデータにアクセス - res.send({ name, photoUrls }); + const { name, photoUrls } = req.valid.body; + res.json({ name, photoUrls }); }, }); ``` diff --git a/docs/ja/introduction.md b/docs/ja/introduction.md index f93bd8148..8f4f1a574 100644 --- a/docs/ja/introduction.md +++ b/docs/ja/introduction.md @@ -105,8 +105,9 @@ type ErrorResponse = ここから、これらの型を以下の用途で使用できます(ただし、これに限定されません): -- OpenAPI対応のfetchクライアントを使用する(例:[openapi-fetch](/ja/openapi-fetch/)) +- 生成された `paths` からAPIを呼び出す(例:[openapi-fetch](/ja/openapi-fetch/) や [feature-fetch](/ja/examples)) - 他のAPIリクエストボディやレスポンスの型のアサート - API型に基づいたコアビジネスロジックの構築 +- 生成された `paths` に対して server routes を実装する(例:[openapi-ts-router](/ja/examples)) - モックテストデータが現在のスキーマと一致していることを確認する - 任意のnpmパッケージ(クライアントSDKなど)にAPI型をパッケージ化する diff --git a/docs/ja/openapi-fetch/index.md b/docs/ja/openapi-fetch/index.md index 0536f6df5..0f39a34cb 100644 --- a/docs/ja/openapi-fetch/index.md +++ b/docs/ja/openapi-fetch/index.md @@ -15,7 +15,7 @@ openapi-fetchは、あなたのOpenAPIスキーマを取り込み、型安全な | superagent | `55 kB` | `50k` ops/s (6倍遅い) | | openapi-typescript-codegen | `367 kB` | `100k` ops/s (3倍遅い) | -_\* [ベンチマークはおおよそのものです](https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-fetch/test/index.bench.js) 。実際のパフォーマンスはマシンやブラウザによって異なる場合があります。ライブラリ間の相対的なパフォーマンスはより信頼性があります。_ +_\* [ベンチマークはおおよそのものです](https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-fetch/test/bench/index.bench.js) 。実際のパフォーマンスはマシンやブラウザによって異なる場合があります。ライブラリ間の相対的なパフォーマンスはより信頼性があります。_ このシンタックスは、React QueryやApollo Clientのような人気のライブラリにインスパイアされたものでありながら、すべての装飾を省き、6 kbというコンパクトなパッケージに収まっています。 diff --git a/docs/openapi-fetch/index.md b/docs/openapi-fetch/index.md index 844eb9dbc..7ed4a7286 100644 --- a/docs/openapi-fetch/index.md +++ b/docs/openapi-fetch/index.md @@ -15,7 +15,7 @@ openapi-fetch is a type-safe fetch client that pulls in your OpenAPI schema. Wei | superagent | `55 kB` | `50k` ops/s (6× slower) | | openapi-typescript-codegen | `367 kB` | `100k` ops/s (3× slower) | -_\* [Benchmarks are approximate](https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-fetch/test/index.bench.js) to just show rough baseline and will differ among machines and browsers. The relative performance between libraries is more reliable._ +_\* [Benchmarks are approximate](https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-fetch/test/bench/index.bench.js) to just show rough baseline and will differ among machines and browsers. The relative performance between libraries is more reliable._ The syntax is inspired by popular libraries like react-query or Apollo client, but without all the bells and whistles and in a 6 kb package. diff --git a/packages/openapi-fetch/README.md b/packages/openapi-fetch/README.md index 255edf976..c5fda8562 100644 --- a/packages/openapi-fetch/README.md +++ b/packages/openapi-fetch/README.md @@ -11,7 +11,7 @@ openapi-fetch is a type-safe fetch client that pulls in your OpenAPI schema. Wei | superagent | `55 kB` | `50k` ops/s (6× slower) | | openapi-typescript-codegen | `367 kB` | `100k` ops/s (3× slower) | -_\* [Benchmarks are approximate](https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-fetch/test/index.bench.js) to just show rough baseline and will differ among machines and browsers. The relative performance between libraries is more reliable._ +_\* [Benchmarks are approximate](https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-fetch/test/bench/index.bench.js) to just show rough baseline and will differ among machines and browsers. The relative performance between libraries is more reliable._ The syntax is inspired by popular libraries like react-query or Apollo client, but without all the bells and whistles and in a 6 kb package. diff --git a/packages/openapi-fetch/package.json b/packages/openapi-fetch/package.json index 3ed673fe6..f955f96c8 100644 --- a/packages/openapi-fetch/package.json +++ b/packages/openapi-fetch/package.json @@ -65,7 +65,7 @@ "axios": "1.16.0", "execa": "catalog:", "express": "5.2.1", - "feature-fetch": "0.0.55", + "feature-fetch": "0.1.0", "node-forge": "1.4.0", "openapi-typescript": "workspace:^", "openapi-typescript-codegen": "0.30.0", diff --git a/packages/openapi-fetch/test/bench/index.bench.js b/packages/openapi-fetch/test/bench/index.bench.js index 06112be26..7afcb412b 100644 --- a/packages/openapi-fetch/test/bench/index.bench.js +++ b/packages/openapi-fetch/test/bench/index.bench.js @@ -46,7 +46,7 @@ describe("setup", () => { }); bench("feature-fetch", async () => { - createApiFetchClient({ prefixUrl: BASE_URL }); + createApiFetchClient({ baseUrl: BASE_URL }); }); // superagent: N/A @@ -63,7 +63,7 @@ describe("get (only URL)", () => { const axiosInstance = axios.create({ baseURL: BASE_URL, }); - const featureFetch = createApiFetchClient({ prefixUrl: BASE_URL }); + const featureFetch = createApiFetchClient({ baseUrl: BASE_URL }); bench("openapi-fetch", async () => { await openapiFetch.GET("/url"); @@ -113,7 +113,7 @@ describe("get (headers)", () => { baseURL: BASE_URL, }); const featureFetch = createApiFetchClient({ - prefixUrl: BASE_URL, + baseUrl: BASE_URL, headers: { "x-base-header": "123" }, }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3d3b87bc5..10b905394 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -85,8 +85,8 @@ importers: specifier: 5.2.1 version: 5.2.1 feature-fetch: - specifier: 0.0.55 - version: 0.0.55(graphql@16.13.2) + specifier: 0.1.0 + version: 0.1.0(graphql@16.13.2) node-forge: specifier: 1.4.0 version: 1.4.0 @@ -538,12 +538,6 @@ packages: cpu: [x64] os: [win32] - '@blgc/types@0.0.22': - resolution: {integrity: sha512-BCW/N9/Z0KpakL9iT2hi49U//lAQGWU5GcK724BZ1NdmjQsXsJQfimCOOcrvjEuSY+mBUexpzx3ngXBmMJOnUg==} - - '@blgc/utils@0.0.62': - resolution: {integrity: sha512-5hLMykKIrZs2FoGW/vE50A5btgM5szJF/nWmPbA6io0wKAHYusvksAB+hh4YkudjX+VBlC7k/Ii3SgXw+RjjLQ==} - '@braidai/lang@1.1.2': resolution: {integrity: sha512-qBcknbBufNHlui137Hft8xauQMTZDKdophmLFv05r2eNmdIv/MlPuP4TdUknHG68UdWLgVZwgxVe735HzJNIwA==} @@ -2831,8 +2825,11 @@ packages: picomatch: optional: true - feature-fetch@0.0.55: - resolution: {integrity: sha512-5BvKcpZld4+YLtRo88vIUsCTwvxnr74cK61SVJjD7TDdUs8cmdKQ7i1ACi3KWCqKtBW7GV6QhTCQWLDioYOUZQ==} + feature-core@0.0.2: + resolution: {integrity: sha512-1HRPj1lYzcoiJlBo4HVnMiBGOXREvCB12C6wjG22YKN3YHzNFB9PiSxknPncJTP03KV/p6ZUQ7PAd7TWSXOn7A==} + + feature-fetch@0.1.0: + resolution: {integrity: sha512-7eNBWIddV35GLK0JE0CB7IV3Ta5Ea6vACkXvEOncWwPzx1jRxctNdhBb+gGHlvr0ahk0kxZvJ8ww9ZT9tL5IKg==} fflate@0.8.2: resolution: {integrity: sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==} @@ -3461,6 +3458,9 @@ packages: resolution: {integrity: sha512-aBp1cR5FTNxp4HA8bb2ST53aIqEiJgoOMyXiyzKi6YF7vogW8KkyyUQ1FeDz8D05uspxFrKvFbkVU2YiiKkULA==} engines: {node: '>= 12.0.0', npm: '>= 7.0.0'} + openapi-typescript-helpers@0.1.0: + resolution: {integrity: sha512-OKTGPthhivLw/fHz6c3OPtg72vi86qaMlqbJuVJ23qOvQ+53uw1n7HdmkJFibloF7QEjDrDkzJiOJuockM/ljw==} + outdent@0.5.0: resolution: {integrity: sha512-/jHxFIzoMXdqPzTaCpFzAAWhpkSjZPF4Vsn6jAfNpmbH/ymsmd7Qc6VE9BGn0L6YMj6uwpQLxCECpus4ukKS9Q==} @@ -4225,8 +4225,8 @@ packages: tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} - tuple-result@0.0.12: - resolution: {integrity: sha512-psArZjDjcqmBKLE1IpmgtleT+Vd9xxjk6f6zGMWt/UfiAArQifBIEBNN/sIdJFEF26x/JTmpqYYjCXRvgBj7XQ==} + tuple-result@0.1.0: + resolution: {integrity: sha512-FXtn9q3niXDO1QKrSjwAJayft+L7/US6DL3TDKifawh0iID+JrVqQaYxn/N+yka/yo1CFfN1o5gkFCZpb/jK6Q==} turbo@2.9.9: resolution: {integrity: sha512-3xfzXE/yTjhh0S5dIWlE+3E+J9A09REpLI1ZqVh2+HrNZoVzZn0pkvjiRgVK/Ev3PF9XnaTwCntTx+CADWXcyA==} @@ -4906,10 +4906,6 @@ snapshots: '@biomejs/cli-win32-x64@2.4.14': optional: true - '@blgc/types@0.0.22': {} - - '@blgc/utils@0.0.62': {} - '@braidai/lang@1.1.2': {} '@changesets/apply-release-plan@7.1.1': @@ -7017,12 +7013,14 @@ snapshots: optionalDependencies: picomatch: 4.0.4 - feature-fetch@0.0.55(graphql@16.13.2): + feature-core@0.0.2: {} + + feature-fetch@0.1.0(graphql@16.13.2): dependencies: '@0no-co/graphql.web': 1.2.0(graphql@16.13.2) - '@blgc/types': 0.0.22 - '@blgc/utils': 0.0.62 - tuple-result: 0.0.12 + feature-core: 0.0.2 + openapi-typescript-helpers: 0.1.0 + tuple-result: 0.1.0 transitivePeerDependencies: - graphql @@ -7668,6 +7666,8 @@ snapshots: openapi-typescript-fetch@2.2.1: {} + openapi-typescript-helpers@0.1.0: {} + outdent@0.5.0: {} outvariant@1.4.3: {} @@ -8463,7 +8463,7 @@ snapshots: tslib@2.8.1: {} - tuple-result@0.0.12: {} + tuple-result@0.1.0: {} turbo@2.9.9: optionalDependencies: