Skip to content

Commit

Permalink
fix: type errors coming from validatorJs
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Jan 27, 2024
1 parent 2fb440f commit 5c89c2e
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,12 +947,12 @@ export interface Rules {
* Value must be valid as per uuid format. Optionally you can
* define a uuid version
*/
uuid(options?: { version?: validatorJs.default.UUIDVersion }): Rule
uuid(options?: { version?: validatorJs.UUIDVersion }): Rule

/**
* Value must pass the mobile regex rule
*/
mobile(options?: { strict?: boolean; locale?: validatorJs.default.MobilePhoneLocale[] }): Rule
mobile(options?: { strict?: boolean; locale?: validatorJs.MobilePhoneLocale[] }): Rule

/**
* Length of string or array must be below or same as the defined length
Expand Down
4 changes: 2 additions & 2 deletions src/validations/string/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const DEFAULT_MESSAGE = 'email validation failed'
* Shape of compiled options. It is a merged copy of
* sanitization and validation options
*/
type CompiledOptions = validatorJs.default.IsEmailOptions & {
sanitize?: validatorJs.default.NormalizeEmailOptions
type CompiledOptions = validatorJs.IsEmailOptions & {
sanitize?: validatorJs.NormalizeEmailOptions
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/validations/string/mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const DEFAULT_MESSAGE = 'mobile validation failed'
*/
export const mobile: SyncValidation<{
strict: boolean
locale?: validatorJs.default.MobilePhoneLocale[]
locale?: validatorJs.MobilePhoneLocale[]
}> = {
compile: wrapCompile(RULE_NAME, ['string'], ([options]) => {
options = Object.assign({}, options)
Expand Down
6 changes: 3 additions & 3 deletions src/validations/string/normalize_email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ const RULE_NAME = 'normalizeEmail'
/**
* Normalize email address
*/
export const normalizeEmail: SyncValidation<validatorJs.default.NormalizeEmailOptions> = {
export const normalizeEmail: SyncValidation<validatorJs.NormalizeEmailOptions> = {
compile: wrapCompile(RULE_NAME, ['string'], (args) => {
const options = Object.assign({}, args[0]) as EmailNormalizationOptions

return {
compiledOptions: Object.keys(options).reduce((result, key) => {
const validatorKey = string.snakeCase(
key
) as keyof validatorJs.default.NormalizeEmailOptions
) as keyof validatorJs.NormalizeEmailOptions
result[validatorKey] = options[key as keyof EmailNormalizationOptions]
return result
}, {} as validatorJs.default.NormalizeEmailOptions),
}, {} as validatorJs.NormalizeEmailOptions),
}
}),
validate(value, compiledOptions, { mutate }) {
Expand Down
2 changes: 1 addition & 1 deletion src/validations/string/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type CompiledOptions = {
normalizeProtocol?: boolean
stripWWW?: boolean
}
validationOptions: validatorJs.default.IsURLOptions
validationOptions: validatorJs.IsURLOptions
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/validations/string/uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const RULE_NAME = 'uuid'
* Validation signature for the "uuid" rule. Non-string values are
* ignored.
*/
export const uuid: SyncValidation<{ version?: validatorJs.default.UUIDVersion }> = {
export const uuid: SyncValidation<{ version?: validatorJs.UUIDVersion }> = {
compile: wrapCompile(RULE_NAME, ['string'], ([options]) => {
return {
compiledOptions: {
Expand Down
2 changes: 1 addition & 1 deletion tests/validations/mobile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { MessagesBag } from '../../src/messages_bag/index.js'
import { ApiErrorReporter } from '../../src/error_reporter/index.js'
import { mobile } from '../../src/validations/string/mobile.js'

function compile(options?: { strict?: boolean; locale?: validator.default.MobilePhoneLocale[] }) {
function compile(options?: { strict?: boolean; locale?: validator.MobilePhoneLocale[] }) {
return mobile.compile('literal', 'string', rules.mobile(options).options, {})
}

Expand Down
2 changes: 1 addition & 1 deletion tests/validations/uuid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { test } from '@japa/runner'
import { UUIDVersion } from 'class-validator'
import { UUIDVersion } from 'validator'

import { rules } from '../../src/rules/index.js'
import { validate } from '../fixtures/rules/index.js'
Expand Down

0 comments on commit 5c89c2e

Please sign in to comment.