Skip to content

Commit

Permalink
feat(vinejs): add binding on VineNumber in vinejs.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul committed Feb 5, 2024
1 parent cb78f1a commit 02c153f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/bindings/vinejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
* file that was distributed with this source code.
*/

import vine, { VineString } from '@vinejs/vine'
import vine, { VineNumber, VineString } from '@vinejs/vine'
import type { Database } from '../database/main.js'

/**
* Defines the "unique" and "exists" validation rules with
* VineJS.
*/
export function defineValidationRules(db: Database) {
const uniqueRule = vine.createRule<Parameters<VineString['unique']>[0]>(
const uniqueRule = vine.createRule<Parameters<VineString['unique'] | VineNumber['unique']>[0]>(
async (value, checker, field) => {
if (!field.isValid) {
return
Expand All @@ -28,7 +28,7 @@ export function defineValidationRules(db: Database) {
}
)

const existsRule = vine.createRule<Parameters<VineString['exists']>[0]>(
const existsRule = vine.createRule<Parameters<VineString['exists'] | VineNumber['exists']>[0]>(
async (value, checker, field) => {
if (!field.isValid) {
return
Expand All @@ -47,4 +47,10 @@ export function defineValidationRules(db: Database) {
VineString.macro('exists', function (this: VineString, checker) {
return this.use(existsRule(checker))
})
VineNumber.macro('unique', function (this: VineNumber, checker) {
return this.use(uniqueRule(checker))
})
VineNumber.macro('exists', function (this: VineNumber, checker) {
return this.use(existsRule(checker))
})
}

0 comments on commit 02c153f

Please sign in to comment.