From 9cde0a47c75bd7dca84de14a00fde8a4bb3c85c7 Mon Sep 17 00:00:00 2001 From: mpppk Date: Sat, 14 Dec 2024 14:48:19 +0900 Subject: [PATCH] Fix withValidation example --- pkgs/examples/simple/withValidation.ts | 13 ++++++++----- pkgs/typed-api-spec/src/core/index.ts | 3 +++ pkgs/typed-api-spec/src/fetch/validation.ts | 6 +++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pkgs/examples/simple/withValidation.ts b/pkgs/examples/simple/withValidation.ts index 23b03d2..7dd66fa 100644 --- a/pkgs/examples/simple/withValidation.ts +++ b/pkgs/examples/simple/withValidation.ts @@ -1,6 +1,7 @@ import { newZodValidator, ZodApiEndpoints } from "@notainc/typed-api-spec/zod"; -import { ValidateError, withValidation } from "@notainc/typed-api-spec/fetch"; -import { z, ZodError } from "zod"; +import { withValidation } from "@notainc/typed-api-spec/fetch"; +import { z } from "zod"; +import { SpecValidatorError } from "@notainc/typed-api-spec/fetch"; const GITHUB_API_ORIGIN = "https://api.github.com"; @@ -47,9 +48,11 @@ const main = async () => { `${GITHUB_API_ORIGIN}/repos/nota/typed-api-spec/topics?page=1`, { headers: { Accept: "application/vnd.github+json" } }, ); - } catch (e: unknown) { - if (e instanceof ValidateError) { - console.log("error thrown", (e.error as ZodError).format()); + } catch (e) { + if (e instanceof SpecValidatorError) { + console.log("error thrown", e.error); + } else { + throw e; } } } diff --git a/pkgs/typed-api-spec/src/core/index.ts b/pkgs/typed-api-spec/src/core/index.ts index d43c7be..d3507ba 100644 --- a/pkgs/typed-api-spec/src/core/index.ts +++ b/pkgs/typed-api-spec/src/core/index.ts @@ -3,3 +3,6 @@ export * from "./query-string"; export * from "./spec"; export * from "./type"; export * from "./url"; +export * from "./validator/validate"; +export * from "./validator/request"; +export * from "./validator/response"; diff --git a/pkgs/typed-api-spec/src/fetch/validation.ts b/pkgs/typed-api-spec/src/fetch/validation.ts index 59f02de..9e4190a 100644 --- a/pkgs/typed-api-spec/src/fetch/validation.ts +++ b/pkgs/typed-api-spec/src/fetch/validation.ts @@ -5,13 +5,13 @@ import { AnySpecValidator, RequestSpecValidatorGenerator, runSpecValidator, -} from "../core/validator/request"; +} from "../core"; import { AnyResponseSpecValidator, ResponseSpecValidatorGenerator, runResponseSpecValidator, -} from "../core/validator/response"; -import { ValidatorInputError } from "../core/validator/validate"; +} from "../core"; +import { ValidatorInputError } from "../core"; const dummyHost = "https://example.com";