From dd620f0dc72976a76952c9506babdef9c33ffd7b Mon Sep 17 00:00:00 2001 From: Nico Franke Date: Thu, 24 Aug 2023 01:38:25 +0200 Subject: [PATCH] refactor(valibot-validator): update to latest valibot version (#135) * chore(valibot-validator): update valibot version * refactor(valibot-validator): use updated safeParse result * chore: add changeset --- .changeset/fuzzy-spoons-crash.md | 5 +++++ packages/valibot-validator/package.json | 4 ++-- packages/valibot-validator/src/index.ts | 10 +++++----- packages/valibot-validator/test/index.test.ts | 2 +- yarn.lock | 8 ++++---- 5 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 .changeset/fuzzy-spoons-crash.md diff --git a/.changeset/fuzzy-spoons-crash.md b/.changeset/fuzzy-spoons-crash.md new file mode 100644 index 00000000..8692fcf3 --- /dev/null +++ b/.changeset/fuzzy-spoons-crash.md @@ -0,0 +1,5 @@ +--- +'@hono/valibot-validator': minor +--- + +update valibot version diff --git a/packages/valibot-validator/package.json b/packages/valibot-validator/package.json index e7bd1c86..4e927d19 100644 --- a/packages/valibot-validator/package.json +++ b/packages/valibot-validator/package.json @@ -29,10 +29,10 @@ "homepage": "https://github.com/honojs/middleware", "peerDependencies": { "hono": "3.*", - "valibot": "^0.12.0" + "valibot": "^0.13.1" }, "devDependencies": { "hono": "^3.1.0", - "valibot": "^0.12.0" + "valibot": "^0.13.1" } } diff --git a/packages/valibot-validator/src/index.ts b/packages/valibot-validator/src/index.ts index b8b9afc4..987324b0 100644 --- a/packages/valibot-validator/src/index.ts +++ b/packages/valibot-validator/src/index.ts @@ -1,10 +1,10 @@ import type { Context, MiddlewareHandler, Env, ValidationTargets } from 'hono' import { validator } from 'hono/validator' -import type { BaseSchema, Input, Output, ValiError } from 'valibot' +import type { BaseSchema, Input, Output, SafeParseResult } from 'valibot' import { safeParse } from 'valibot' -type Hook = ( - result: { success: true; data: T } | { success: false; error: ValiError }, +type Hook = ( + result: SafeParseResult, c: Context ) => Response | Promise | void | Promise @@ -23,7 +23,7 @@ export const vValidator = < >( target: Target, schema: T, - hook?: Hook, E, P> + hook?: Hook ): MiddlewareHandler => validator(target, (value, c) => { const result = safeParse(schema, value) @@ -39,6 +39,6 @@ export const vValidator = < return c.json(result, 400) } - const data = result.data as Output + const data = result.output as Output return data }) diff --git a/packages/valibot-validator/test/index.test.ts b/packages/valibot-validator/test/index.test.ts index f8aa109e..24fb2e27 100644 --- a/packages/valibot-validator/test/index.test.ts +++ b/packages/valibot-validator/test/index.test.ts @@ -90,7 +90,7 @@ describe('With Hook', () => { if (!result.success) { return c.text('Invalid!', 400) } - const data = result.data + const data = result.output return c.text(`${data.id} is valid!`) }), (c) => { diff --git a/yarn.lock b/yarn.lock index e6b301db..220f6f11 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11929,10 +11929,10 @@ vali-date@^1.0.0: resolved "https://registry.yarnpkg.com/vali-date/-/vali-date-1.0.0.tgz#1b904a59609fb328ef078138420934f6b86709a6" integrity sha512-sgECfZthyaCKW10N0fm27cg8HYTFK5qMWgypqkXMQ4Wbl/zZKx7xZICgcoxIIE+WFAP/MBL2EFwC/YvLxw3Zeg== -valibot@^0.12.0: - version "0.12.0" - resolved "https://registry.yarnpkg.com/valibot/-/valibot-0.12.0.tgz#3206191f4af551768bfddf041f40ad3b3d3037df" - integrity sha512-EGx/uDUpRa9wB9NkD7fsktc02rvXWlJzDTC/ihbE+NybhzAsMhns2OOdNv2R4BtdGnDvaCEGi/DbgR5RvgCS8A== +valibot@^0.13.1: + version "0.13.1" + resolved "https://registry.yarnpkg.com/valibot/-/valibot-0.13.1.tgz#34196211c5b4293829a9e4e6b0cf29a9227f410b" + integrity sha512-SG2W1RHqE2LShl3p6tyERt6I+G6PQa9ZFVfkyNKXz01HBzL+tBeH5kXw/5AQeAzPJSjI3djVGBl1CyozA1kyBQ== valid-url@^1: version "1.0.9"