Skip to content

Commit

Permalink
chore: Update valibot to version 0.31.0 (#553)
Browse files Browse the repository at this point in the history
* chore: Update valibot to version 0.31.0

* Modify update valibot to version 0.31.0

* Modify update yarn.lock to valibot 0.31.0

* Add CHANGELOG using changesets
  • Loading branch information
chimame authored Jun 9, 2024
1 parent ce63598 commit 7375c09
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-panthers-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/valibot-validator': minor
---

changed supported version of valibot to 0.31.0 or later
4 changes: 2 additions & 2 deletions packages/valibot-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"homepage": "https://github.com/honojs/middleware",
"peerDependencies": {
"hono": ">=3.9.0",
"valibot": ">=0.13.1 <1"
"valibot": ">=0.31.0 <1"
},
"devDependencies": {
"hono": "^4.0.10",
"jest": "^29.7.0",
"rimraf": "^5.0.5",
"valibot": "^0.24.1"
"valibot": "^0.31.0"
}
}
14 changes: 7 additions & 7 deletions packages/valibot-validator/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import type { Context, MiddlewareHandler, Env, ValidationTargets, Input as HonoInput } from 'hono'
import type { Context, Env, Input as HonoInput, MiddlewareHandler, ValidationTargets } from 'hono'
import { validator } from 'hono/validator'
import type { BaseSchema, BaseSchemaAsync, Input, Output, SafeParseResult } from 'valibot'
import type { GenericSchema, GenericSchemaAsync, InferInput, InferOutput, SafeParseResult } from 'valibot'
import { safeParseAsync } from 'valibot'

type Hook<T extends BaseSchema | BaseSchemaAsync, E extends Env, P extends string> = (
type Hook<T extends GenericSchema | GenericSchemaAsync, E extends Env, P extends string> = (
result: SafeParseResult<T>,
c: Context<E, P>
) => Response | Promise<Response> | void | Promise<Response | void>

type HasUndefined<T> = undefined extends T ? true : false

export const vValidator = <
T extends BaseSchema | BaseSchemaAsync,
T extends GenericSchema | GenericSchemaAsync,
Target extends keyof ValidationTargets,
E extends Env,
P extends string,
In = Input<T>,
Out = Output<T>,
In = InferInput<T>,
Out = InferOutput<T>,
I extends HonoInput = {
in: HasUndefined<In> extends true
? {
Expand Down Expand Up @@ -56,6 +56,6 @@ export const vValidator = <
return c.json(result, 400)
}

const data = result.output as Output<T>
const data = result.output as InferOutput<T>
return data
})
14 changes: 7 additions & 7 deletions packages/valibot-validator/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Hono } from 'hono'
import type { Equal, Expect } from 'hono/utils/types'
import { number, object, string, optional, numberAsync, objectAsync, stringAsync, optionalAsync } from 'valibot'
import { number, object, objectAsync, optional, optionalAsync, string } from 'valibot'
import { vValidator } from '../src'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -167,14 +167,14 @@ describe('Async', () => {
const app = new Hono()

const schemaAsync = objectAsync({
name: stringAsync(),
age: numberAsync(),
name: string(),
age: number(),
})

const querySchemaAsync = optionalAsync(
objectAsync({
search: optionalAsync(stringAsync()),
page: optionalAsync(numberAsync()),
search: optionalAsync(string()),
page: optionalAsync(number()),
})
)

Expand Down Expand Up @@ -264,8 +264,8 @@ describe('With Hook Async', () => {
const app = new Hono()

const schemaAsync = objectAsync({
id: numberAsync(),
title: stringAsync(),
id: number(),
title: string(),
})

app.post(
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2155,10 +2155,10 @@ __metadata:
hono: "npm:^4.0.10"
jest: "npm:^29.7.0"
rimraf: "npm:^5.0.5"
valibot: "npm:^0.24.1"
valibot: "npm:^0.31.0"
peerDependencies:
hono: ">=3.9.0"
valibot: ">=0.13.1 <1"
valibot: ">=0.31.0 <1"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -18181,10 +18181,10 @@ __metadata:
languageName: node
linkType: hard

"valibot@npm:^0.24.1":
version: 0.24.1
resolution: "valibot@npm:0.24.1"
checksum: 637c3641bc800506982ea507c55b65154653ea1f38bf3c7ad6c0fc3dd3bead4644e2172ddd8cade2821c280886dd9d99b36e7a778607cae7dfab107de74c5547
"valibot@npm:^0.31.0":
version: 0.31.1
resolution: "valibot@npm:0.31.1"
checksum: 666abefeffe1b92e324bc1f35e9052929365d9646f324197d21a506ada07e605958853e04144996b698c866cc327be78138712a5b79e1dbe98caf52229b49fc0
languageName: node
linkType: hard

Expand Down

0 comments on commit 7375c09

Please sign in to comment.