@vinejs/vine
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -1,110 +0,8 @@ | ||
import { MessagesProviderContact, ErrorReporterContract, FieldContext } from '@vinejs/compiler/types'; | ||
import { a as Validation } from '../types-8973fb04.js'; | ||
import { S as SimpleErrorReporter } from '../simple_error_reporter-8927be32.js'; | ||
import 'normalize-url'; | ||
import 'validator/lib/isURL.js'; | ||
import 'validator/lib/isEmail.js'; | ||
import 'validator/lib/normalizeEmail.js'; | ||
import 'validator/lib/isMobilePhone.js'; | ||
import 'validator/lib/isPostalCode.js'; | ||
import 'validator'; | ||
import 'validator/lib/isIBAN.js'; | ||
import { FieldFactory } from './field.js'; | ||
import { ValidatorFactory } from './validator.js'; | ||
/** | ||
* Exposes API to create a dummy field context | ||
*/ | ||
declare class FieldFactory { | ||
create(fieldName: string, value: any, messagesProvider?: MessagesProviderContact, errorReporter?: ErrorReporterContract): { | ||
value: any; | ||
isArrayMember: false; | ||
parent: any; | ||
data: { | ||
[x: string]: any; | ||
}; | ||
name: any; | ||
wildCardPath: string; | ||
isDefined: boolean; | ||
isValid: true; | ||
meta: {}; | ||
mutate(newValue: any): FieldContext; | ||
report(message: string, rule: string, context: FieldContext, args: Record<string, any> | undefined): void; | ||
}; | ||
} | ||
/** | ||
* Exposes APIs for writing validation assertions | ||
*/ | ||
declare class ValidationResult { | ||
#private; | ||
constructor(outputValue: any, reporter: SimpleErrorReporter); | ||
/** | ||
* Returns the validation result output | ||
*/ | ||
getOutput(): any; | ||
/** | ||
* Returns an array of errors reported to the | ||
* error reporter | ||
*/ | ||
getErrors(): { | ||
message: string; | ||
field: string; | ||
rule: string; | ||
index?: number | undefined; | ||
meta?: Record<string, any> | undefined; | ||
}[]; | ||
/** | ||
* Assert one or more validation errors have occurred | ||
*/ | ||
assertSucceeded(): void; | ||
/** | ||
* Assert the output value of validation. The output value is | ||
* same as the input value, unless "mutate" method is called | ||
*/ | ||
assertOutput(expectedOutput: any): void; | ||
/** | ||
* Assert one or more validation errors have occurred | ||
*/ | ||
assertFailed(): void; | ||
/** | ||
* Assert the number of errors have occurred | ||
*/ | ||
assertErrorsCount(count: number): void; | ||
/** | ||
* Assert error messages to include a given error message | ||
*/ | ||
assertError(message: string): void; | ||
} | ||
/** | ||
* Validator factory exposes the API to execute validations | ||
* during tests | ||
*/ | ||
declare class ValidatorFactory { | ||
#private; | ||
constructor(field?: Partial<FieldContext>, bail?: boolean); | ||
/** | ||
* Define field context for the validation | ||
*/ | ||
withContext(field: Partial<FieldContext>): ValidatorFactory; | ||
/** | ||
* Toggle bail mode for the validation | ||
*/ | ||
bail(state: boolean): ValidatorFactory; | ||
/** | ||
* Executes a validation against the provided value | ||
*/ | ||
execute(validation: Validation<any> | Validation<any>[], value: any): ValidationResult; | ||
/** | ||
* Executes an async validation against the provided | ||
* value | ||
*/ | ||
executeAsync(validation: Validation<any> | Validation<any>[], value: any): Promise<ValidationResult>; | ||
} | ||
/** | ||
* Validator factory is used for unit testing validation | ||
* rules. | ||
*/ | ||
declare const validator: ValidatorFactory; | ||
declare const fieldContext: FieldFactory; | ||
export { fieldContext, validator }; | ||
export declare const validator: ValidatorFactory; | ||
export declare const fieldContext: FieldFactory; |
@@ -5,4 +5,4 @@ import { | ||
helpers | ||
} from "../chunk-W377YOUX.js"; | ||
import "../chunk-QPO2OBYN.js"; | ||
} from "../chunk-U7IQLI4H.js"; | ||
import "../chunk-CSAU5B4Q.js"; | ||
@@ -209,1 +209,2 @@ // factories/field.ts | ||
}; | ||
//# sourceMappingURL=main.js.map |
1487
build/index.d.ts
@@ -1,1465 +0,24 @@ | ||
import * as isIBAN from 'validator/lib/isIBAN.js'; | ||
import * as validator from 'validator'; | ||
import * as validator_lib_isURL_js from 'validator/lib/isURL.js'; | ||
import * as validator_lib_isEmail_js from 'validator/lib/isEmail.js'; | ||
import { V as Validator, a as Validation, F as FieldOptions, P as Parser, R as RuleBuilder, b as PARSE, c as ParserOptions, C as ConstructableSchema, O as OTYPE, d as COTYPE, T as Transformer, S as SchemaTypes, U as UnionNoMatchCallback, e as UNIQUE_NAME, I as IS_OF_TYPE, M as MobileOptions, f as CreditCardOptions, g as PassportOptions, h as PostalCodeOptions, A as AlphaOptions, i as AlphaNumericOptions, E as EnumLike, j as ErrorReporterContract, k as MetaDataValidator, l as ValidationOptions, m as Infer, n as ValidationError, o as ValidationMessages, p as ValidationFields } from './types-8973fb04.js'; | ||
export { s as symbols } from './types-8973fb04.js'; | ||
import Macroable from '@poppinss/macroable'; | ||
import * as _vinejs_compiler_types from '@vinejs/compiler/types'; | ||
import { RefsStore, LiteralNode, FieldContext, ConditionalFn, UnionNode, CompilerNodes, TupleNode, ArrayNode, ObjectGroupNode, ObjectNode, RecordNode, MessagesProviderContact } from '@vinejs/compiler/types'; | ||
import * as normalize_url from 'normalize-url'; | ||
import { NormalizeEmailOptions } from 'validator/lib/normalizeEmail.js'; | ||
export { S as SimpleErrorReporter } from './simple_error_reporter-8927be32.js'; | ||
import 'validator/lib/isMobilePhone.js'; | ||
import 'validator/lib/isPostalCode.js'; | ||
/** | ||
* Returns args for the validation function. | ||
*/ | ||
type GetArgs<T> = undefined extends T ? [options?: T] : [options: T]; | ||
/** | ||
* Convert a validator function to a rule that you can apply | ||
* to any schema type using the `schema.use` method. | ||
*/ | ||
declare function createRule<Options = undefined>(validator: Validator<Options>, metaData?: { | ||
implicit?: boolean; | ||
isAsync?: boolean; | ||
}): (...options: GetArgs<Options>) => Validation<Options>; | ||
/** | ||
* Base schema type with only modifiers applicable on all the schema types. | ||
*/ | ||
declare abstract class BaseModifiersType$1<Output, CamelCaseOutput> extends Macroable implements ConstructableSchema<Output, CamelCaseOutput> { | ||
/** | ||
* Each subtype should implement the compile method that returns | ||
* one of the known compiler nodes | ||
*/ | ||
abstract [PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): LiteralNode; | ||
/** | ||
* The child class must implement the clone method | ||
*/ | ||
abstract clone(): this; | ||
/** | ||
* The output value of the field. The property points to a type only | ||
* and not the real value. | ||
*/ | ||
[OTYPE]: Output; | ||
[COTYPE]: CamelCaseOutput; | ||
/** | ||
* Mark the field under validation as optional. An optional | ||
* field allows both null and undefined values. | ||
*/ | ||
optional(): OptionalModifier$1<this>; | ||
/** | ||
* Mark the field under validation to be null. The null value will | ||
* be written to the output as well. | ||
* | ||
* If `optional` and `nullable` are used together, then both undefined | ||
* and null values will be allowed. | ||
*/ | ||
nullable(): NullableModifier$1<this>; | ||
/** | ||
* Apply transform on the final validated value. The transform method may | ||
* convert the value to any new datatype. | ||
*/ | ||
transform<TransformedOutput>(transformer: Transformer<this, TransformedOutput>): TransformModifier<this, TransformedOutput>; | ||
} | ||
/** | ||
* Modifies the schema type to allow null values | ||
*/ | ||
declare class NullableModifier$1<Schema extends BaseModifiersType$1<any, any>> extends BaseModifiersType$1<Schema[typeof OTYPE] | null, Schema[typeof COTYPE] | null> { | ||
#private; | ||
constructor(parent: Schema); | ||
/** | ||
* Creates a fresh instance of the underlying schema type | ||
* and wraps it inside the nullable modifier | ||
*/ | ||
clone(): this; | ||
/** | ||
* Compiles to compiler node | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): LiteralNode; | ||
} | ||
/** | ||
* Modifies the schema type to allow undefined values | ||
*/ | ||
declare class OptionalModifier$1<Schema extends BaseModifiersType$1<any, any>> extends BaseModifiersType$1<Schema[typeof OTYPE] | undefined, Schema[typeof COTYPE] | undefined> { | ||
#private; | ||
constructor(parent: Schema); | ||
/** | ||
* Creates a fresh instance of the underlying schema type | ||
* and wraps it inside the optional modifier | ||
*/ | ||
clone(): this; | ||
/** | ||
* Compiles to compiler node | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): LiteralNode; | ||
} | ||
/** | ||
* Modifies the schema type to allow custom transformed values | ||
*/ | ||
declare class TransformModifier<Schema extends BaseModifiersType$1<any, any>, Output> extends BaseModifiersType$1<Output, Output> { | ||
#private; | ||
/** | ||
* The output value of the field. The property points to a type only | ||
* and not the real value. | ||
*/ | ||
[OTYPE]: Output; | ||
[COTYPE]: Output; | ||
constructor(transform: Transformer<Schema, Output>, parent: Schema); | ||
/** | ||
* Creates a fresh instance of the underlying schema type | ||
* and wraps it inside the transform modifier. | ||
*/ | ||
clone(): this; | ||
/** | ||
* Compiles to compiler node | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): LiteralNode; | ||
} | ||
/** | ||
* The base type for creating a custom literal type. Literal type | ||
* is a schema type that has no children elements. | ||
*/ | ||
declare abstract class BaseLiteralType<Output, CamelCaseOutput> extends BaseModifiersType$1<Output, CamelCaseOutput> { | ||
/** | ||
* The child class must implement the clone method | ||
*/ | ||
abstract clone(): this; | ||
/** | ||
* Field options | ||
*/ | ||
protected options: FieldOptions; | ||
/** | ||
* Set of validations to run | ||
*/ | ||
protected validations: Validation<any>[]; | ||
constructor(options?: Partial<FieldOptions>, validations?: Validation<any>[]); | ||
/** | ||
* Shallow clones the validations. Since, there are no API's to mutate | ||
* the validation options, we can safely copy them by reference. | ||
*/ | ||
protected cloneValidations(): Validation<any>[]; | ||
/** | ||
* Shallow clones the options | ||
*/ | ||
protected cloneOptions(): FieldOptions; | ||
/** | ||
* Compiles validations | ||
*/ | ||
protected compileValidations(refs: RefsStore): { | ||
ruleFnId: `ref://${number}`; | ||
implicit: boolean; | ||
isAsync: boolean; | ||
}[]; | ||
/** | ||
* Define a method to parse the input value. The method | ||
* is invoked before any validation and hence you must | ||
* perform type-checking to know the value you are | ||
* working it. | ||
*/ | ||
parse(callback: Parser): this; | ||
/** | ||
* Push a validation to the validations chain. | ||
*/ | ||
use(validation: Validation<any> | RuleBuilder): this; | ||
/** | ||
* Enable/disable the bail mode. In bail mode, the field validations | ||
* are stopped after the first error. | ||
*/ | ||
bail(state: boolean): this; | ||
/** | ||
* Compiles the schema type to a compiler node | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): LiteralNode; | ||
} | ||
/** | ||
* VineAny represents a value that can be anything | ||
*/ | ||
declare class VineAny extends BaseLiteralType<any, any> { | ||
constructor(options?: Partial<FieldOptions>, validations?: Validation<any>[]); | ||
/** | ||
* Clones the VineAny schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone(): this; | ||
} | ||
/** | ||
* VineEnum represents a enum data type that performs validation | ||
* against a pre-defined choices list. | ||
*/ | ||
declare class VineEnum<const Values extends readonly unknown[]> extends BaseLiteralType<Values[number], Values[number]> { | ||
#private; | ||
/** | ||
* Default collection of enum rules | ||
*/ | ||
static rules: { | ||
enum: (options: { | ||
choices: readonly any[] | ((field: FieldContext) => readonly any[]); | ||
}) => Validation<{ | ||
choices: readonly any[] | ((field: FieldContext) => readonly any[]); | ||
}>; | ||
}; | ||
/** | ||
* Returns the enum choices | ||
*/ | ||
getChoices(): Values | ((field: FieldContext) => Values); | ||
constructor(values: Values | ((field: FieldContext) => Values), options?: FieldOptions, validations?: Validation<any>[]); | ||
/** | ||
* Clones the VineEnum schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone(): this; | ||
} | ||
/** | ||
* Represents a union conditional type. A conditional is a predicate | ||
* with a schema | ||
*/ | ||
declare class UnionConditional<Schema extends SchemaTypes> { | ||
#private; | ||
[OTYPE]: Schema[typeof OTYPE]; | ||
[COTYPE]: Schema[typeof COTYPE]; | ||
constructor(conditional: ConditionalFn<Record<string, unknown>>, schema: Schema); | ||
/** | ||
* Compiles to a union conditional | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): UnionNode['conditions'][number]; | ||
} | ||
/** | ||
* Vine union represents a union data type. A union is a collection | ||
* of conditionals and each condition has an associated schema | ||
*/ | ||
declare class VineUnion<Conditional extends UnionConditional<SchemaTypes>> implements ConstructableSchema<Conditional[typeof OTYPE], Conditional[typeof COTYPE]> { | ||
#private; | ||
[OTYPE]: Conditional[typeof OTYPE]; | ||
[COTYPE]: Conditional[typeof COTYPE]; | ||
constructor(conditionals: Conditional[]); | ||
/** | ||
* Define a fallback method to invoke when all of the union conditions | ||
* fail. You may use this method to report an error. | ||
*/ | ||
otherwise(callback: UnionNoMatchCallback<Record<string, unknown>>): this; | ||
/** | ||
* Clones the VineUnion schema type. | ||
*/ | ||
clone(): this; | ||
/** | ||
* Compiles to a union | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): UnionNode; | ||
} | ||
/** | ||
* Create a new union schema type. A union is a collection of conditionals | ||
* and schema associated with it. | ||
*/ | ||
declare function union<Conditional extends UnionConditional<any>>(conditionals: Conditional[]): VineUnion<Conditional>; | ||
declare namespace union { | ||
var _a: <Schema extends SchemaTypes>(conditon: (value: Record<string, unknown>, field: FieldContext) => any, schema: Schema) => UnionConditional<Schema>; | ||
var _b: <Schema extends SchemaTypes>(schema: Schema) => UnionConditional<Schema>; | ||
export { _a as if, _b as else }; | ||
} | ||
/** | ||
* Base schema type with only modifiers applicable on all the schema types. | ||
*/ | ||
declare abstract class BaseModifiersType<Output, CamelCaseOutput> extends Macroable implements ConstructableSchema<Output, CamelCaseOutput> { | ||
/** | ||
* Each subtype should implement the compile method that returns | ||
* one of the known compiler nodes | ||
*/ | ||
abstract [PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): CompilerNodes; | ||
/** | ||
* The child class must implement the clone method | ||
*/ | ||
abstract clone(): this; | ||
/** | ||
* The output value of the field. The property points to a type only | ||
* and not the real value. | ||
*/ | ||
[OTYPE]: Output; | ||
[COTYPE]: CamelCaseOutput; | ||
/** | ||
* Mark the field under validation as optional. An optional | ||
* field allows both null and undefined values. | ||
*/ | ||
optional(): OptionalModifier<this>; | ||
/** | ||
* Mark the field under validation to be null. The null value will | ||
* be written to the output as well. | ||
* | ||
* If `optional` and `nullable` are used together, then both undefined | ||
* and null values will be allowed. | ||
*/ | ||
nullable(): NullableModifier<this>; | ||
} | ||
/** | ||
* Modifies the schema type to allow null values | ||
*/ | ||
declare class NullableModifier<Schema extends BaseModifiersType<any, any>> extends BaseModifiersType<Schema[typeof OTYPE] | null, Schema[typeof COTYPE] | null> { | ||
#private; | ||
constructor(parent: Schema); | ||
/** | ||
* Creates a fresh instance of the underlying schema type | ||
* and wraps it inside the nullable modifier | ||
*/ | ||
clone(): this; | ||
/** | ||
* Compiles to compiler node | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): CompilerNodes; | ||
} | ||
/** | ||
* Modifies the schema type to allow undefined values | ||
*/ | ||
declare class OptionalModifier<Schema extends BaseModifiersType<any, any>> extends BaseModifiersType<Schema[typeof OTYPE] | undefined, Schema[typeof COTYPE] | undefined> { | ||
#private; | ||
constructor(parent: Schema); | ||
/** | ||
* Creates a fresh instance of the underlying schema type | ||
* and wraps it inside the optional modifier | ||
*/ | ||
clone(): this; | ||
/** | ||
* Compiles to compiler node | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): CompilerNodes; | ||
} | ||
/** | ||
* The BaseSchema class abstracts the repetitive parts of creating | ||
* a custom schema type. | ||
*/ | ||
declare abstract class BaseType<Output, CamelCaseOutput> extends BaseModifiersType<Output, CamelCaseOutput> { | ||
/** | ||
* Field options | ||
*/ | ||
protected options: FieldOptions; | ||
/** | ||
* Set of validations to run | ||
*/ | ||
protected validations: Validation<any>[]; | ||
constructor(options?: FieldOptions, validations?: Validation<any>[]); | ||
/** | ||
* Shallow clones the validations. Since, there are no API's to mutate | ||
* the validation options, we can safely copy them by reference. | ||
*/ | ||
protected cloneValidations(): Validation<any>[]; | ||
/** | ||
* Shallow clones the options | ||
*/ | ||
protected cloneOptions(): FieldOptions; | ||
/** | ||
* Compiles validations | ||
*/ | ||
protected compileValidations(refs: RefsStore): { | ||
ruleFnId: `ref://${number}`; | ||
implicit: boolean; | ||
isAsync: boolean; | ||
}[]; | ||
/** | ||
* Define a method to parse the input value. The method | ||
* is invoked before any validation and hence you must | ||
* perform type-checking to know the value you are | ||
* working it. | ||
*/ | ||
parse(callback: Parser): this; | ||
/** | ||
* Push a validation to the validations chain. | ||
*/ | ||
use(validation: Validation<any> | RuleBuilder): this; | ||
/** | ||
* Enable/disable the bail mode. In bail mode, the field validations | ||
* are stopped after the first error. | ||
*/ | ||
bail(state: boolean): this; | ||
} | ||
/** | ||
* VineTuple is an array with known length and may have different | ||
* schema type for each array element. | ||
*/ | ||
declare class VineTuple<Schema extends SchemaTypes[], Output extends any[], CamelCaseOutput extends any[]> extends BaseType<Output, CamelCaseOutput> { | ||
#private; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME]: string; | ||
/** | ||
* Checks if the value is of array type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE]: (value: unknown) => boolean; | ||
constructor(schemas: [...Schema], options?: FieldOptions, validations?: Validation<any>[]); | ||
/** | ||
* Copy unknown properties to the final output. | ||
*/ | ||
allowUnknownProperties<Value>(): VineTuple<Schema, [ | ||
...Output, | ||
...Value[] | ||
], [ | ||
...CamelCaseOutput, | ||
...Value[] | ||
]>; | ||
/** | ||
* Clone object | ||
*/ | ||
clone(): this; | ||
/** | ||
* Compiles to array data type | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): TupleNode; | ||
} | ||
/** | ||
* VineArray represents an array schema type in the validation | ||
* pipeline | ||
*/ | ||
declare class VineArray<Schema extends SchemaTypes> extends BaseType<Schema[typeof OTYPE][], Schema[typeof COTYPE][]> { | ||
#private; | ||
/** | ||
* Default collection of array rules | ||
*/ | ||
static rules: { | ||
compact: (options?: undefined) => Validation<undefined>; | ||
notEmpty: (options?: undefined) => Validation<undefined>; | ||
distinct: (options: { | ||
fields?: string | string[] | undefined; | ||
}) => Validation<{ | ||
fields?: string | string[] | undefined; | ||
}>; | ||
minLength: (options: { | ||
min: number; | ||
}) => Validation<{ | ||
min: number; | ||
}>; | ||
maxLength: (options: { | ||
max: number; | ||
}) => Validation<{ | ||
max: number; | ||
}>; | ||
fixedLength: (options: { | ||
size: number; | ||
}) => Validation<{ | ||
size: number; | ||
}>; | ||
}; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME]: string; | ||
/** | ||
* Checks if the value is of array type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE]: (value: unknown) => boolean; | ||
constructor(schema: Schema, options?: FieldOptions, validations?: Validation<any>[]); | ||
/** | ||
* Enforce a minimum length on an array field | ||
*/ | ||
minLength(expectedLength: number): this; | ||
/** | ||
* Enforce a maximum length on an array field | ||
*/ | ||
maxLength(expectedLength: number): this; | ||
/** | ||
* Enforce a fixed length on an array field | ||
*/ | ||
fixedLength(expectedLength: number): this; | ||
/** | ||
* Ensure the array is not empty | ||
*/ | ||
notEmpty(): this; | ||
/** | ||
* Ensure array elements are distinct/unique | ||
*/ | ||
distinct(fields?: string | string[]): this; | ||
/** | ||
* Removes empty strings, null and undefined values from the array | ||
*/ | ||
compact(): this; | ||
/** | ||
* Clones the VineArray schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone(): this; | ||
/** | ||
* Compiles to array data type | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): ArrayNode; | ||
} | ||
/** | ||
* Group conditional represents a sub-set of object wrapped | ||
* inside a conditional | ||
*/ | ||
declare class GroupConditional<Properties extends Record<string, SchemaTypes>, Output, CamelCaseOutput> { | ||
#private; | ||
[OTYPE]: Output; | ||
[COTYPE]: CamelCaseOutput; | ||
constructor(conditional: ConditionalFn<Record<string, unknown>>, properties: Properties); | ||
/** | ||
* Compiles to a union conditional | ||
*/ | ||
[PARSE](refs: RefsStore, options: ParserOptions): ObjectGroupNode['conditions'][number]; | ||
} | ||
/** | ||
* Object group represents a group with multiple conditionals, where each | ||
* condition returns a set of object properties to merge into the | ||
* existing object. | ||
*/ | ||
declare class ObjectGroup<Conditional extends GroupConditional<any, any, any>> { | ||
#private; | ||
[OTYPE]: Conditional[typeof OTYPE]; | ||
[COTYPE]: Conditional[typeof COTYPE]; | ||
constructor(conditionals: Conditional[]); | ||
/** | ||
* Clones the ObjectGroup schema type. | ||
*/ | ||
clone(): this; | ||
/** | ||
* Define a fallback method to invoke when all of the group conditions | ||
* fail. You may use this method to report an error. | ||
*/ | ||
otherwise(callback: UnionNoMatchCallback<Record<string, unknown>>): this; | ||
/** | ||
* Compiles the group | ||
*/ | ||
[PARSE](refs: RefsStore, options: ParserOptions): ObjectGroupNode; | ||
} | ||
/** | ||
* Converts schema properties to camelCase | ||
*/ | ||
declare class VineCamelCaseObject<Schema extends VineObject<any, any, any>> extends BaseModifiersType<Schema[typeof COTYPE], Schema[typeof COTYPE]> { | ||
#private; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME]: string; | ||
/** | ||
* Checks if the value is of object type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE]: (value: unknown) => boolean; | ||
constructor(schema: Schema); | ||
/** | ||
* Clone object | ||
*/ | ||
clone(): this; | ||
/** | ||
* Compiles the schema type to a compiler node | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): ObjectNode; | ||
} | ||
/** | ||
* VineObject represents an object value in the validation | ||
* schema. | ||
*/ | ||
declare class VineObject<Properties extends Record<string, SchemaTypes>, Output, CamelCaseOutput> extends BaseType<Output, CamelCaseOutput> { | ||
#private; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME]: string; | ||
/** | ||
* Checks if the value is of object type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE]: (value: unknown) => boolean; | ||
constructor(properties: Properties, options?: FieldOptions, validations?: Validation<any>[]); | ||
/** | ||
* Returns a clone copy of the object properties. The object groups | ||
* are not copied to keep the implementations simple and easy to | ||
* reason about. | ||
*/ | ||
getProperties(): Properties; | ||
/** | ||
* Copy unknown properties to the final output. | ||
*/ | ||
allowUnknownProperties<Value>(): VineObject<Properties, Output & { | ||
[K: string]: Value; | ||
}, CamelCaseOutput & { | ||
[K: string]: Value; | ||
}>; | ||
/** | ||
* Merge a union to the object groups. The union can be a "vine.union" | ||
* with objects, or a "vine.object.union" with properties. | ||
*/ | ||
merge<Group extends ObjectGroup<GroupConditional<any, any, any>>>(group: Group): VineObject<Properties, Output & Group[typeof OTYPE], CamelCaseOutput & Group[typeof COTYPE]>; | ||
/** | ||
* Clone object | ||
*/ | ||
clone(): this; | ||
/** | ||
* Applies camelcase transform | ||
*/ | ||
toCamelCase(): VineCamelCaseObject<this>; | ||
/** | ||
* Compiles the schema type to a compiler node | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): ObjectNode; | ||
} | ||
/** | ||
* Register a callback to validate the object keys | ||
*/ | ||
declare const validateKeysRule: (options: (keys: string[], field: FieldContext) => void) => Validation<(keys: string[], field: FieldContext) => void>; | ||
/** | ||
* VineRecord represents an object of key-value pair in which | ||
* keys are unknown | ||
*/ | ||
declare class VineRecord<Schema extends SchemaTypes> extends BaseType<{ | ||
[K: string]: Schema[typeof OTYPE]; | ||
}, { | ||
[K: string]: Schema[typeof COTYPE]; | ||
}> { | ||
#private; | ||
/** | ||
* Default collection of record rules | ||
*/ | ||
static rules: { | ||
maxLength: (options: { | ||
max: number; | ||
}) => Validation<{ | ||
max: number; | ||
}>; | ||
minLength: (options: { | ||
min: number; | ||
}) => Validation<{ | ||
min: number; | ||
}>; | ||
fixedLength: (options: { | ||
size: number; | ||
}) => Validation<{ | ||
size: number; | ||
}>; | ||
validateKeys: (options: (keys: string[], field: _vinejs_compiler_types.FieldContext) => void) => Validation<(keys: string[], field: _vinejs_compiler_types.FieldContext) => void>; | ||
}; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME]: string; | ||
/** | ||
* Checks if the value is of object type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE]: (value: unknown) => boolean; | ||
constructor(schema: Schema, options?: FieldOptions, validations?: Validation<any>[]); | ||
/** | ||
* Enforce a minimum length on an object field | ||
*/ | ||
minLength(expectedLength: number): this; | ||
/** | ||
* Enforce a maximum length on an object field | ||
*/ | ||
maxLength(expectedLength: number): this; | ||
/** | ||
* Enforce a fixed length on an object field | ||
*/ | ||
fixedLength(expectedLength: number): this; | ||
/** | ||
* Register a callback to validate the object keys | ||
*/ | ||
validateKeys(...args: Parameters<typeof validateKeysRule>): this; | ||
/** | ||
* Clones the VineRecord schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone(): this; | ||
/** | ||
* Compiles to record data type | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): RecordNode; | ||
} | ||
/** | ||
* Validates the value to be a valid email address | ||
*/ | ||
declare const emailRule: (options?: validator_lib_isEmail_js.IsEmailOptions | undefined) => Validation<validator_lib_isEmail_js.IsEmailOptions | undefined>; | ||
/** | ||
* Validates the value to be a valid mobile number | ||
*/ | ||
declare const mobileRule: (options?: MobileOptions | ((field: FieldContext) => MobileOptions | undefined) | undefined) => Validation<MobileOptions | ((field: FieldContext) => MobileOptions | undefined) | undefined>; | ||
/** | ||
* Validates the value to be a valid URL | ||
*/ | ||
declare const urlRule: (options?: validator_lib_isURL_js.IsURLOptions | undefined) => Validation<validator_lib_isURL_js.IsURLOptions | undefined>; | ||
/** | ||
* Normalize a URL | ||
*/ | ||
declare const normalizeUrlRule: (options?: normalize_url.Options | undefined) => Validation<normalize_url.Options | undefined>; | ||
/** | ||
* Validates the value to be a valid credit card number | ||
*/ | ||
declare const creditCardRule: (options?: CreditCardOptions | ((field: FieldContext) => CreditCardOptions | void | undefined) | undefined) => Validation<CreditCardOptions | ((field: FieldContext) => CreditCardOptions | void | undefined) | undefined>; | ||
/** | ||
* Validates the value to be a valid passport number | ||
*/ | ||
declare const passportRule: (options: PassportOptions | ((field: FieldContext) => PassportOptions)) => Validation<PassportOptions | ((field: FieldContext) => PassportOptions)>; | ||
/** | ||
* Validates the value to be a valid postal code | ||
*/ | ||
declare const postalCodeRule: (options?: PostalCodeOptions | ((field: FieldContext) => PostalCodeOptions | void | undefined) | undefined) => Validation<PostalCodeOptions | ((field: FieldContext) => PostalCodeOptions | void | undefined) | undefined>; | ||
/** | ||
* Validates the value to be a valid UUID | ||
*/ | ||
declare const uuidRule: (options?: { | ||
version?: (1 | 2 | 4 | 3 | 5)[] | undefined; | ||
} | undefined) => Validation<{ | ||
version?: (1 | 2 | 4 | 3 | 5)[] | undefined; | ||
} | undefined>; | ||
/** | ||
* VineString represents a string value in the validation schema. | ||
*/ | ||
declare class VineString extends BaseLiteralType<string, string> { | ||
static rules: { | ||
in: (options: { | ||
choices: string[] | ((field: FieldContext) => string[]); | ||
}) => Validation<{ | ||
choices: string[] | ((field: FieldContext) => string[]); | ||
}>; | ||
jwt: (options?: undefined) => Validation<undefined>; | ||
url: (options?: validator_lib_isURL_js.IsURLOptions | undefined) => Validation<validator_lib_isURL_js.IsURLOptions | undefined>; | ||
iban: (options?: undefined) => Validation<undefined>; | ||
uuid: (options?: { | ||
version?: (1 | 2 | 4 | 3 | 5)[] | undefined; | ||
} | undefined) => Validation<{ | ||
version?: (1 | 2 | 4 | 3 | 5)[] | undefined; | ||
} | undefined>; | ||
trim: (options?: undefined) => Validation<undefined>; | ||
email: (options?: validator_lib_isEmail_js.IsEmailOptions | undefined) => Validation<validator_lib_isEmail_js.IsEmailOptions | undefined>; | ||
alpha: (options?: AlphaOptions | undefined) => Validation<AlphaOptions | undefined>; | ||
ascii: (options?: undefined) => Validation<undefined>; | ||
notIn: (options: { | ||
list: string[] | ((field: FieldContext) => string[]); | ||
}) => Validation<{ | ||
list: string[] | ((field: FieldContext) => string[]); | ||
}>; | ||
regex: (options: RegExp) => Validation<RegExp>; | ||
escape: (options?: undefined) => Validation<undefined>; | ||
sameAs: (options: { | ||
otherField: string; | ||
}) => Validation<{ | ||
otherField: string; | ||
}>; | ||
mobile: (options?: MobileOptions | ((field: FieldContext) => MobileOptions | undefined) | undefined) => Validation<MobileOptions | ((field: FieldContext) => MobileOptions | undefined) | undefined>; | ||
string: (options?: undefined) => Validation<undefined>; | ||
hexCode: (options?: undefined) => Validation<undefined>; | ||
passport: (options: PassportOptions | ((field: FieldContext) => PassportOptions)) => Validation<PassportOptions | ((field: FieldContext) => PassportOptions)>; | ||
endsWith: (options: { | ||
substring: string; | ||
}) => Validation<{ | ||
substring: string; | ||
}>; | ||
confirmed: (options?: { | ||
confirmationField: string; | ||
} | undefined) => Validation<{ | ||
confirmationField: string; | ||
} | undefined>; | ||
activeUrl: (options?: undefined) => Validation<undefined>; | ||
minLength: (options: { | ||
min: number; | ||
}) => Validation<{ | ||
min: number; | ||
}>; | ||
notSameAs: (options: { | ||
otherField: string; | ||
}) => Validation<{ | ||
otherField: string; | ||
}>; | ||
maxLength: (options: { | ||
max: number; | ||
}) => Validation<{ | ||
max: number; | ||
}>; | ||
ipAddress: (options?: { | ||
version: 4 | 6; | ||
} | undefined) => Validation<{ | ||
version: 4 | 6; | ||
} | undefined>; | ||
creditCard: (options?: CreditCardOptions | ((field: FieldContext) => void | CreditCardOptions | undefined) | undefined) => Validation<CreditCardOptions | ((field: FieldContext) => void | CreditCardOptions | undefined) | undefined>; | ||
postalCode: (options?: PostalCodeOptions | ((field: FieldContext) => void | PostalCodeOptions | undefined) | undefined) => Validation<PostalCodeOptions | ((field: FieldContext) => void | PostalCodeOptions | undefined) | undefined>; | ||
startsWith: (options: { | ||
substring: string; | ||
}) => Validation<{ | ||
substring: string; | ||
}>; | ||
toUpperCase: (options?: string | string[] | undefined) => Validation<string | string[] | undefined>; | ||
toLowerCase: (options?: string | string[] | undefined) => Validation<string | string[] | undefined>; | ||
toCamelCase: (options?: undefined) => Validation<undefined>; | ||
fixedLength: (options: { | ||
size: number; | ||
}) => Validation<{ | ||
size: number; | ||
}>; | ||
coordinates: (options?: undefined) => Validation<undefined>; | ||
normalizeUrl: (options?: normalize_url.Options | undefined) => Validation<normalize_url.Options | undefined>; | ||
alphaNumeric: (options?: AlphaOptions | undefined) => Validation<AlphaOptions | undefined>; | ||
normalizeEmail: (options?: validator.default.NormalizeEmailOptions | undefined) => Validation<validator.default.NormalizeEmailOptions | undefined>; | ||
}; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME]: string; | ||
/** | ||
* Checks if the value is of string type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE]: (value: unknown) => boolean; | ||
constructor(options?: FieldOptions, validations?: Validation<any>[]); | ||
/** | ||
* Validates the value to be a valid URL | ||
*/ | ||
url(...args: Parameters<typeof urlRule>): this; | ||
/** | ||
* Validates the value to be an active URL | ||
*/ | ||
activeUrl(): this; | ||
/** | ||
* Validates the value to be a valid email address | ||
*/ | ||
email(...args: Parameters<typeof emailRule>): this; | ||
/** | ||
* Validates the value to be a valid mobile number | ||
*/ | ||
mobile(...args: Parameters<typeof mobileRule>): this; | ||
/** | ||
* Validates the value to be a valid IP address. | ||
*/ | ||
ipAddress(version?: 4 | 6): this; | ||
/** | ||
* Validates the value to be a valid hex color code | ||
*/ | ||
hexCode(): this; | ||
/** | ||
* Validates the value to be an active URL | ||
*/ | ||
regex(expression: RegExp): this; | ||
/** | ||
* Validates the value to contain only letters | ||
*/ | ||
alpha(options?: AlphaOptions): this; | ||
/** | ||
* Validates the value to contain only letters and | ||
* numbers | ||
*/ | ||
alphaNumeric(options?: AlphaNumericOptions): this; | ||
/** | ||
* Enforce a minimum length on a string field | ||
*/ | ||
minLength(expectedLength: number): this; | ||
/** | ||
* Enforce a maximum length on a string field | ||
*/ | ||
maxLength(expectedLength: number): this; | ||
/** | ||
* Enforce a fixed length on a string field | ||
*/ | ||
fixedLength(expectedLength: number): this; | ||
/** | ||
* Ensure the field under validation is confirmed by | ||
* having another field with the same name. | ||
*/ | ||
confirmed(options?: { | ||
confirmationField: string; | ||
}): this; | ||
/** | ||
* Trims whitespaces around the string value | ||
*/ | ||
trim(): this; | ||
/** | ||
* Normalizes the email address | ||
*/ | ||
normalizeEmail(options?: NormalizeEmailOptions): this; | ||
/** | ||
* Converts the field value to UPPERCASE. | ||
*/ | ||
toUpperCase(): this; | ||
/** | ||
* Converts the field value to lowercase. | ||
*/ | ||
toLowerCase(): this; | ||
/** | ||
* Converts the field value to camelCase. | ||
*/ | ||
toCamelCase(): this; | ||
/** | ||
* Escape string for HTML entities | ||
*/ | ||
escape(): this; | ||
/** | ||
* Normalize a URL | ||
*/ | ||
normalizeUrl(...args: Parameters<typeof normalizeUrlRule>): this; | ||
/** | ||
* Ensure the value starts with the pre-defined substring | ||
*/ | ||
startsWith(substring: string): this; | ||
/** | ||
* Ensure the value ends with the pre-defined substring | ||
*/ | ||
endsWith(substring: string): this; | ||
/** | ||
* Ensure the value ends with the pre-defined substring | ||
*/ | ||
sameAs(otherField: string): this; | ||
/** | ||
* Ensure the value ends with the pre-defined substring | ||
*/ | ||
notSameAs(otherField: string): this; | ||
/** | ||
* Ensure the field's value under validation is a subset of the pre-defined list. | ||
*/ | ||
in(choices: string[] | ((field: FieldContext) => string[])): this; | ||
/** | ||
* Ensure the field's value under validation is not inside the pre-defined list. | ||
*/ | ||
notIn(list: string[] | ((field: FieldContext) => string[])): this; | ||
/** | ||
* Validates the value to be a valid credit card number | ||
*/ | ||
creditCard(...args: Parameters<typeof creditCardRule>): this; | ||
/** | ||
* Validates the value to be a valid passport number | ||
*/ | ||
passport(...args: Parameters<typeof passportRule>): this; | ||
/** | ||
* Validates the value to be a valid postal code | ||
*/ | ||
postalCode(...args: Parameters<typeof postalCodeRule>): this; | ||
/** | ||
* Validates the value to be a valid UUID | ||
*/ | ||
uuid(...args: Parameters<typeof uuidRule>): this; | ||
/** | ||
* Validates the value contains ASCII characters only | ||
*/ | ||
ascii(): this; | ||
/** | ||
* Validates the value to be a valid IBAN number | ||
*/ | ||
iban(): this; | ||
/** | ||
* Validates the value to be a valid JWT token | ||
*/ | ||
jwt(): this; | ||
/** | ||
* Ensure the value is a string with latitude and longitude coordinates | ||
*/ | ||
coordinates(): this; | ||
/** | ||
* Clones the VineString schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone(): this; | ||
} | ||
/** | ||
* VineNumber represents a numeric value in the validation schema. | ||
*/ | ||
declare class VineNumber extends BaseLiteralType<number, number> { | ||
protected options: FieldOptions & { | ||
strict?: boolean; | ||
}; | ||
/** | ||
* Default collection of number rules | ||
*/ | ||
static rules: { | ||
max: (options: { | ||
max: number; | ||
}) => Validation<{ | ||
max: number; | ||
}>; | ||
min: (options: { | ||
min: number; | ||
}) => Validation<{ | ||
min: number; | ||
}>; | ||
range: (options: { | ||
min: number; | ||
max: number; | ||
}) => Validation<{ | ||
min: number; | ||
max: number; | ||
}>; | ||
number: (options: { | ||
strict?: boolean | undefined; | ||
}) => Validation<{ | ||
strict?: boolean | undefined; | ||
}>; | ||
decimal: (options: { | ||
range: [number, (number | undefined)?]; | ||
}) => Validation<{ | ||
range: [number, (number | undefined)?]; | ||
}>; | ||
negative: (options?: undefined) => Validation<undefined>; | ||
positive: (options?: undefined) => Validation<undefined>; | ||
withoutDecimals: (options?: undefined) => Validation<undefined>; | ||
}; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME]: string; | ||
/** | ||
* Checks if the value is of number type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE]: (value: unknown) => boolean; | ||
constructor(options?: Partial<FieldOptions> & { | ||
strict?: boolean; | ||
}, validations?: Validation<any>[]); | ||
/** | ||
* Enforce a minimum value for the number input | ||
*/ | ||
min(value: number): this; | ||
/** | ||
* Enforce a maximum value for the number input | ||
*/ | ||
max(value: number): this; | ||
/** | ||
* Enforce value to be within the range of minimum and maximum output. | ||
*/ | ||
range(value: [min: number, max: number]): this; | ||
/** | ||
* Enforce the value be a positive number | ||
*/ | ||
positive(): this; | ||
/** | ||
* Enforce the value be a negative number | ||
*/ | ||
negative(): this; | ||
/** | ||
* Enforce the value to have fixed or range | ||
* of decimal places | ||
*/ | ||
decimal(range: number | [number, number]): this; | ||
/** | ||
* Enforce the value to be an integer (aka without decimals) | ||
*/ | ||
withoutDecimals(): this; | ||
/** | ||
* Clones the VineNumber schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone(): this; | ||
} | ||
/** | ||
* VineBoolean represents a boolean value in the validation schema. | ||
*/ | ||
declare class VineBoolean extends BaseLiteralType<boolean, boolean> { | ||
/** | ||
* Default collection of boolean rules | ||
*/ | ||
static rules: { | ||
boolean: (options: { | ||
strict?: boolean | undefined; | ||
}) => Validation<{ | ||
strict?: boolean | undefined; | ||
}>; | ||
}; | ||
protected options: FieldOptions & { | ||
strict?: boolean; | ||
}; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME]: string; | ||
/** | ||
* Checks if the value is of boolean type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE]: (value: unknown) => boolean; | ||
constructor(options?: Partial<FieldOptions> & { | ||
strict?: boolean; | ||
}, validations?: Validation<any>[]); | ||
/** | ||
* Clones the VineBoolean schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone(): this; | ||
} | ||
/** | ||
* VineLiteral represents a type that matches an exact value | ||
*/ | ||
declare class VineLiteral<Value> extends BaseLiteralType<Value, Value> { | ||
#private; | ||
/** | ||
* Default collection of literal rules | ||
*/ | ||
static rules: { | ||
equals: (options: { | ||
expectedValue: any; | ||
}) => Validation<{ | ||
expectedValue: any; | ||
}>; | ||
}; | ||
constructor(value: Value, options?: FieldOptions, validations?: Validation<any>[]); | ||
/** | ||
* Clones the VineLiteral schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone(): this; | ||
} | ||
/** | ||
* Copy-pasted from | ||
* https://github.com/ts-essentials/ts-essentials/blob/3f5d46a203cad06728fbf2a089a5b39bd473bf4e/lib/camel-case/index.ts | ||
* | ||
* Since, we need just one helper, I decided to not pull in the entire package and just copy-paste | ||
* the types | ||
*/ | ||
type IsStringLiteral<Type> = Type extends string ? (string extends Type ? false : true) : false; | ||
type WordInPascalCase<Type> = Capitalize<WordInCamelCase<Uncapitalize<Type & string>>>; | ||
type WordInCamelCase<Type, Character extends string = ''> = Type extends `${Character}${infer NextCharacter}${infer _}` ? NextCharacter extends Capitalize<NextCharacter> ? Character : WordInCamelCase<Type, `${Character}${NextCharacter}`> : Character; | ||
type Separator = '_' | '-'; | ||
type IncludesSeparator<Type> = Type extends `${string}${Separator}${string}` ? true : false; | ||
type IsOneWord<Type> = Type extends Lowercase<Type & string> ? true : Type extends Uppercase<Type & string> ? true : false; | ||
type IsCamelCase<Type> = Type extends Uncapitalize<Type & string> ? true : false; | ||
type IsPascalCase<Type> = Type extends Capitalize<Type & string> ? true : false; | ||
/** snake_case, CONSTANT_CASE, kebab-case or COBOL-CASE */ | ||
type SeparatorCaseParser<Type, Tuple extends readonly any[] = []> = Type extends `${infer Word}${Separator}${infer Tail}` ? SeparatorCaseParser<Tail, [...Tuple, Lowercase<Word>]> : Type extends `${infer Word}` ? [...Tuple, Lowercase<Word>] : Tuple; | ||
type CamelCaseParser<Type, Tuple extends readonly any[] = []> = Type extends '' ? Tuple : Type extends `${WordInCamelCase<Type & string>}${infer Tail}` ? Type extends `${infer Word}${Tail}` ? CamelCaseParser<Uncapitalize<Tail>, [...Tuple, Lowercase<Word>]> : never : never; | ||
type PascalCaseParser<Type, Tuple extends readonly any[] = []> = Type extends '' ? Tuple : Type extends `${WordInPascalCase<Type & string>}${infer Tail}` ? Type extends `${infer Word}${Tail}` ? PascalCaseParser<Tail, [...Tuple, Lowercase<Word>]> : never : never; | ||
type SplitAnyCase<Type> = IncludesSeparator<Type> extends true ? SeparatorCaseParser<Type> : IsOneWord<Type> extends true ? [Lowercase<Type & string>] : IsCamelCase<Type> extends true ? CamelCaseParser<Type> : IsPascalCase<Type> extends true ? PascalCaseParser<Type> : []; | ||
type PascalCapitalizer<Type, Tuple extends readonly any[] = []> = Type extends [ | ||
infer Head, | ||
...infer Tail | ||
] ? Head extends string ? PascalCapitalizer<Tail, [...Tuple, Capitalize<Head>]> : PascalCapitalizer<Tail, Tuple> : Tuple; | ||
type CamelCapitalizer<Type> = Type extends [infer First, ...infer Tail] ? PascalCapitalizer<Tail, [First]> : []; | ||
type Join<Type, JoinedString extends string = ''> = Type extends [infer Head, ...infer Tail] ? Head extends string ? Join<Tail, `${JoinedString}${Head}`> : Join<Tail> : JoinedString; | ||
type CamelCase<Type> = IsStringLiteral<Type> extends true ? Join<CamelCapitalizer<SplitAnyCase<Type>>> : Type; | ||
/** | ||
* VineAccepted represents a checkbox input that must be checked | ||
*/ | ||
declare class VineAccepted extends BaseLiteralType<true, true> { | ||
/** | ||
* Default collection of accepted rules | ||
*/ | ||
static rules: { | ||
accepted: (options?: undefined) => Validation<undefined>; | ||
}; | ||
constructor(options?: Partial<FieldOptions>, validations?: Validation<any>[]); | ||
/** | ||
* Clones the VineAccepted schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone(): this; | ||
} | ||
/** | ||
* Create an object group. Groups are used to conditionally merge properties | ||
* to an existing object. | ||
*/ | ||
declare function group<Conditional extends GroupConditional<any, any, any>>(conditionals: Conditional[]): ObjectGroup<Conditional>; | ||
declare namespace group { | ||
var _a: <Properties extends Record<string, SchemaTypes>>(conditon: (value: Record<string, unknown>, field: FieldContext) => any, properties: Properties) => GroupConditional<Properties, { [K in keyof Properties]: Properties[K][typeof OTYPE]; }, { [K_1 in keyof Properties as CamelCase<K_1 & string>]: Properties[K_1][typeof COTYPE]; }>; | ||
var _b: <Properties extends Record<string, SchemaTypes>>(properties: Properties) => GroupConditional<Properties, { [K in keyof Properties]: Properties[K][typeof OTYPE]; }, { [K_1 in keyof Properties as CamelCase<K_1 & string>]: Properties[K_1][typeof COTYPE]; }>; | ||
export { _a as if, _b as else }; | ||
} | ||
/** | ||
* VineNativeEnum represents a enum data type that performs validation | ||
* against a pre-defined choices list. | ||
* | ||
* The choices list is derived from TypeScript enum data type or an | ||
* object | ||
*/ | ||
declare class VineNativeEnum<Values extends EnumLike> extends BaseLiteralType<Values[keyof Values], Values[keyof Values]> { | ||
#private; | ||
/** | ||
* Default collection of enum rules | ||
*/ | ||
static rules: { | ||
enum: (options: { | ||
choices: readonly any[] | ((field: _vinejs_compiler_types.FieldContext) => readonly any[]); | ||
}) => Validation<{ | ||
choices: readonly any[] | ((field: _vinejs_compiler_types.FieldContext) => readonly any[]); | ||
}>; | ||
}; | ||
constructor(values: Values, options?: FieldOptions, validations?: Validation<any>[]); | ||
/** | ||
* Clones the VineNativeEnum schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone(): this; | ||
} | ||
/** | ||
* Vine union represents a union data type. A union is a collection | ||
* of conditionals and each condition has an associated schema | ||
*/ | ||
declare class VineUnionOfTypes<Schema extends SchemaTypes> implements ConstructableSchema<Schema[typeof OTYPE], Schema[typeof COTYPE]> { | ||
#private; | ||
[OTYPE]: Schema[typeof OTYPE]; | ||
[COTYPE]: Schema[typeof COTYPE]; | ||
constructor(schemas: Schema[]); | ||
/** | ||
* Define a fallback method to invoke when all of the union conditions | ||
* fail. You may use this method to report an error. | ||
*/ | ||
otherwise(callback: UnionNoMatchCallback<Record<string, unknown>>): this; | ||
/** | ||
* Clones the VineUnionOfTypes schema type. | ||
*/ | ||
clone(): this; | ||
/** | ||
* Compiles to a union | ||
*/ | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): UnionNode; | ||
} | ||
/** | ||
* Schema builder exposes methods to construct a Vine schema. You may | ||
* add custom methods to it using macros. | ||
*/ | ||
declare class SchemaBuilder extends Macroable { | ||
/** | ||
* Define a sub-object as a union | ||
*/ | ||
group: typeof group; | ||
/** | ||
* Define a union value | ||
*/ | ||
union: typeof union; | ||
/** | ||
* Define a string value | ||
*/ | ||
string(): VineString; | ||
/** | ||
* Define a boolean value | ||
*/ | ||
boolean(options?: { | ||
strict: boolean; | ||
}): VineBoolean; | ||
/** | ||
* Validate a checkbox to be checked | ||
*/ | ||
accepted(): VineAccepted; | ||
/** | ||
* Define a number value | ||
*/ | ||
number(options?: { | ||
strict: boolean; | ||
}): VineNumber; | ||
/** | ||
* Define a schema type in which the input value | ||
* matches the pre-defined value | ||
*/ | ||
literal<const Value>(value: Value): VineLiteral<Value>; | ||
/** | ||
* Define an object with known properties. You may call "allowUnknownProperties" | ||
* to merge unknown properties. | ||
*/ | ||
object<Properties extends Record<string, SchemaTypes>>(properties: Properties): VineObject<Properties, { [K in keyof Properties]: Properties[K][typeof OTYPE]; }, { [K_1 in keyof Properties as CamelCase<K_1 & string>]: Properties[K_1][typeof COTYPE]; }>; | ||
/** | ||
* Define an array field and validate its children elements. | ||
*/ | ||
array<Schema extends SchemaTypes>(schema: Schema): VineArray<Schema>; | ||
/** | ||
* Define an array field with known length and each children | ||
* element may have its own schema. | ||
*/ | ||
tuple<Schema extends SchemaTypes[]>(schemas: [...Schema]): VineTuple<Schema, { [K in keyof Schema]: Schema[K][typeof OTYPE]; }, { [K_1 in keyof Schema]: Schema[K_1][typeof COTYPE]; }>; | ||
/** | ||
* Define an object field with key-value pair. The keys in | ||
* a record are unknown and values can be of a specific | ||
* schema type. | ||
*/ | ||
record<Schema extends SchemaTypes>(schema: Schema): VineRecord<Schema>; | ||
/** | ||
* Define a field whose value matches the enum choices. | ||
*/ | ||
enum<const Values extends readonly unknown[]>(values: Values | ((field: FieldContext) => Values)): VineEnum<Values>; | ||
enum<Values extends EnumLike>(values: Values): VineNativeEnum<Values>; | ||
/** | ||
* Allow the field value to be anything | ||
*/ | ||
any(): VineAny; | ||
/** | ||
* Define a union of unique schema types. | ||
*/ | ||
unionOfTypes<Schema extends SchemaTypes>(schemas: Schema[]): VineUnionOfTypes<Schema>; | ||
} | ||
/** | ||
* Vine Validator exposes the API to validate data using a pre-compiled | ||
* schema. | ||
*/ | ||
declare class VineValidator<Schema extends SchemaTypes, MetaData extends undefined | Record<string, any>> { | ||
#private; | ||
/** | ||
* Reference to static types | ||
*/ | ||
[OTYPE]: Schema[typeof OTYPE]; | ||
/** | ||
* Messages provider to use on the validator | ||
*/ | ||
messagesProvider: MessagesProviderContact; | ||
/** | ||
* Error reporter to use on the validator | ||
*/ | ||
errorReporter: () => ErrorReporterContract; | ||
constructor(schema: Schema, options: { | ||
convertEmptyStringsToNull: boolean; | ||
metaDataValidator?: MetaDataValidator; | ||
messagesProvider: MessagesProviderContact; | ||
errorReporter: () => ErrorReporterContract; | ||
}); | ||
/** | ||
* Validate data against a schema. Optionally, you can share metaData with | ||
* the validator | ||
* | ||
* ```ts | ||
* await validator.validate(data) | ||
* await validator.validate(data, { meta: {} }) | ||
* | ||
* await validator.validate(data, { | ||
* meta: { userId: auth.user.id }, | ||
* errorReporter, | ||
* messagesProvider | ||
* }) | ||
* ``` | ||
*/ | ||
validate(data: any, ...[options]: [undefined] extends MetaData ? [options?: ValidationOptions<MetaData> | undefined] : [options: ValidationOptions<MetaData>]): Promise<Infer<Schema>>; | ||
} | ||
/** | ||
* Validate user input with type-safety using a pre-compiled schema. | ||
*/ | ||
declare class Vine extends SchemaBuilder { | ||
/** | ||
* Messages provider to use on the validator | ||
*/ | ||
messagesProvider: MessagesProviderContact; | ||
/** | ||
* Error reporter to use on the validator | ||
*/ | ||
errorReporter: () => ErrorReporterContract; | ||
/** | ||
* Control whether or not to convert empty strings to null | ||
*/ | ||
convertEmptyStringsToNull: boolean; | ||
/** | ||
* Helpers to perform type-checking or cast types keeping | ||
* HTML forms serialization behavior in mind. | ||
*/ | ||
helpers: { | ||
exists(value: any): boolean; | ||
isMissing(value: any): boolean; | ||
isTrue(value: any): boolean; | ||
isFalse(value: any): boolean; | ||
isString(value: unknown): value is string; | ||
isObject<Value>(value: unknown): value is Record<PropertyKey, Value>; | ||
hasKeys(value: Record<string, any>, keys: string[]): boolean; | ||
isArray<Value_1>(value: unknown): value is Value_1[]; | ||
isNumeric(value: any): boolean; | ||
asNumber(value: any): number; | ||
asBoolean(value: any): boolean | null; | ||
isEmail: typeof validator_lib_isEmail_js.default; | ||
isURL: typeof validator_lib_isURL_js.default; | ||
isAlpha: typeof validator.default.isAlpha; | ||
isAlphaNumeric: typeof validator.default.isAlphanumeric; | ||
isIP: typeof validator.default.isIP; | ||
isUUID: typeof validator.default.isUUID; | ||
isAscii: typeof validator.default.isAscii; | ||
isCreditCard: typeof validator.default.isCreditCard; | ||
isIBAN: typeof isIBAN.default; | ||
isJWT: typeof validator.default.isJWT; | ||
isLatLong: typeof validator.default.isLatLong; | ||
isMobilePhone: typeof validator.default.isMobilePhone; | ||
isPassportNumber: typeof validator.default.isPassportNumber; | ||
isPostalCode: typeof validator.default.isPostalCode; | ||
isSlug: typeof validator.default.isSlug; | ||
isDecimal: typeof validator.default.isDecimal; | ||
mobileLocales: validator.default.MobilePhoneLocale[]; | ||
postalCountryCodes: validator.default.PostalCodeLocale[]; | ||
passportCountryCodes: readonly ["AM", "AR", "AT", "AU", "AZ", "BE", "BG", "BR", "BY", "CA", "CH", "CY", "CZ", "DE", "DK", "DZ", "ES", "FI", "FR", "GB", "GR", "HR", "HU", "IE", "IN", "ID", "IR", "IS", "IT", "JM", "JP", "KR", "KZ", "LI", "LT", "LU", "LV", "LY", "MT", "MZ", "MY", "MX", "NL", "NZ", "PH", "PK", "PL", "PT", "RO", "RU", "SE", "SL", "SK", "TH", "TR", "UA", "US"]; | ||
isHexColor: (value: string) => boolean; | ||
isActiveURL: (url: string) => Promise<boolean>; | ||
isDistinct: (dataSet: any[], fields?: string | string[] | undefined) => boolean; | ||
}; | ||
/** | ||
* Convert a validation function to a Vine schema rule | ||
*/ | ||
createRule: typeof createRule; | ||
/** | ||
* Pre-compiles a schema into a validation function. | ||
* | ||
* ```ts | ||
* const validate = vine.compile(schema) | ||
* await validate({ data }) | ||
* ``` | ||
*/ | ||
compile<Schema extends SchemaTypes>(schema: Schema): VineValidator<Schema, Record<string, any> | undefined>; | ||
/** | ||
* Define a callback to validate the metadata given to the validator | ||
* at runtime | ||
*/ | ||
withMetaData<MetaData extends Record<string, any>>(callback?: MetaDataValidator): { | ||
compile: <Schema extends SchemaTypes>(schema: Schema) => VineValidator<Schema, MetaData>; | ||
}; | ||
/** | ||
* Validate data against a schema. Optionally, you can define | ||
* error messages, fields, a custom messages provider, | ||
* or an error reporter. | ||
* | ||
* ```ts | ||
* await vine.validate({ schema, data }) | ||
* await vine.validate({ schema, data, messages, fields }) | ||
* | ||
* await vine.validate({ schema, data, messages, fields }, { | ||
* errorReporter | ||
* }) | ||
* ``` | ||
*/ | ||
validate<Schema extends SchemaTypes>(options: { | ||
/** | ||
* Schema to use for validation | ||
*/ | ||
schema: Schema; | ||
/** | ||
* Data to validate | ||
*/ | ||
data: any; | ||
} & ValidationOptions<Record<string, any> | undefined>): Promise<Infer<Schema>>; | ||
} | ||
/** | ||
* Create an instance of validation error | ||
*/ | ||
declare const E_VALIDATION_ERROR: typeof ValidationError; | ||
declare const main_E_VALIDATION_ERROR: typeof E_VALIDATION_ERROR; | ||
declare namespace main { | ||
export { | ||
main_E_VALIDATION_ERROR as E_VALIDATION_ERROR, | ||
}; | ||
} | ||
/** | ||
* Default messages provider performs messages lookup inside | ||
* a collection of key-value pair. | ||
*/ | ||
declare class SimpleMessagesProvider implements MessagesProviderContact { | ||
#private; | ||
constructor(messages: ValidationMessages, fields: ValidationFields); | ||
/** | ||
* Returns a validation message for a given field + rule. | ||
*/ | ||
getMessage(rawMessage: string, rule: string, field: FieldContext, args?: Record<string, any>): string; | ||
} | ||
import { Vine } from './src/vine/main.js'; | ||
export { Vine }; | ||
export * as symbols from './src/symbols.js'; | ||
export * as errors from './src/errors/main.js'; | ||
export { VineAny } from './src/schema/any/main.js'; | ||
export { VineEnum } from './src/schema/enum/main.js'; | ||
export { VineTuple } from './src/schema/tuple/main.js'; | ||
export { VineUnion } from './src/schema/union/main.js'; | ||
export { VineArray } from './src/schema/array/main.js'; | ||
export { VineValidator } from './src/vine/validator.js'; | ||
export { VineString } from './src/schema/string/main.js'; | ||
export { VineNumber } from './src/schema/number/main.js'; | ||
export { VineDate } from './src/schema/date/main.js'; | ||
export { VineRecord } from './src/schema/record/main.js'; | ||
export { VineObject } from './src/schema/object/main.js'; | ||
export { VineLiteral } from './src/schema/literal/main.js'; | ||
export { VineBoolean } from './src/schema/boolean/main.js'; | ||
export { VineAccepted } from './src/schema/accepted/main.js'; | ||
export { BaseLiteralType } from './src/schema/base/literal.js'; | ||
export { BaseType, BaseModifiersType } from './src/schema/base/main.js'; | ||
export { SimpleErrorReporter } from './src/reporters/simple_error_reporter.js'; | ||
export { SimpleMessagesProvider } from './src/messages_provider/simple_messages_provider.js'; | ||
declare const vine: Vine; | ||
export { BaseLiteralType, BaseModifiersType, BaseType, SimpleMessagesProvider, Vine, VineAccepted, VineAny, VineArray, VineBoolean, VineEnum, VineLiteral, VineNumber, VineObject, VineRecord, VineString, VineTuple, VineUnion, VineValidator, vine as default, main as errors }; | ||
export default vine; |
2301
build/index.js
import { | ||
fields, | ||
messages | ||
} from "./chunk-OQONERRF.js"; | ||
BaseLiteralType, | ||
BaseModifiersType, | ||
BaseType, | ||
Vine, | ||
VineAccepted, | ||
VineAny, | ||
VineArray, | ||
VineBoolean, | ||
VineDate, | ||
VineEnum, | ||
VineLiteral, | ||
VineNumber, | ||
VineObject, | ||
VineRecord, | ||
VineString, | ||
VineTuple, | ||
VineUnion, | ||
VineValidator, | ||
symbols_exports, | ||
vine_default | ||
} from "./chunk-OGE7BNTQ.js"; | ||
import "./chunk-LKAXJ6BU.js"; | ||
import { | ||
SimpleErrorReporter, | ||
SimpleMessagesProvider, | ||
helpers, | ||
main_exports | ||
} from "./chunk-W377YOUX.js"; | ||
import { | ||
__export | ||
} from "./chunk-QPO2OBYN.js"; | ||
// src/vine/create_rule.ts | ||
function createRule(validator, metaData) { | ||
const rule = { | ||
validator, | ||
isAsync: metaData?.isAsync || validator.constructor.name === "AsyncFunction", | ||
implicit: metaData?.implicit ?? false | ||
}; | ||
return function(...options) { | ||
return { | ||
rule, | ||
options: options[0] | ||
}; | ||
}; | ||
} | ||
// src/schema/builder.ts | ||
import Macroable3 from "@poppinss/macroable"; | ||
// src/schema/base/literal.ts | ||
import camelcase from "camelcase"; | ||
import Macroable from "@poppinss/macroable"; | ||
// src/symbols.ts | ||
var symbols_exports = {}; | ||
__export(symbols_exports, { | ||
COTYPE: () => COTYPE, | ||
IS_OF_TYPE: () => IS_OF_TYPE, | ||
OTYPE: () => OTYPE, | ||
PARSE: () => PARSE, | ||
UNIQUE_NAME: () => UNIQUE_NAME, | ||
VALIDATION: () => VALIDATION | ||
}); | ||
var UNIQUE_NAME = Symbol.for("schema_nme"); | ||
var IS_OF_TYPE = Symbol.for("is_of_type"); | ||
var PARSE = Symbol.for("parse"); | ||
var OTYPE = Symbol.for("opaque_type"); | ||
var COTYPE = Symbol.for("camelcase_opaque_type"); | ||
var VALIDATION = Symbol.for("to_validation"); | ||
// src/schema/base/literal.ts | ||
var BaseModifiersType = class extends Macroable { | ||
/** | ||
* Mark the field under validation as optional. An optional | ||
* field allows both null and undefined values. | ||
*/ | ||
optional() { | ||
return new OptionalModifier(this); | ||
} | ||
/** | ||
* Mark the field under validation to be null. The null value will | ||
* be written to the output as well. | ||
* | ||
* If `optional` and `nullable` are used together, then both undefined | ||
* and null values will be allowed. | ||
*/ | ||
nullable() { | ||
return new NullableModifier(this); | ||
} | ||
/** | ||
* Apply transform on the final validated value. The transform method may | ||
* convert the value to any new datatype. | ||
*/ | ||
transform(transformer) { | ||
return new TransformModifier(transformer, this); | ||
} | ||
}; | ||
var NullableModifier = class _NullableModifier extends BaseModifiersType { | ||
#parent; | ||
constructor(parent) { | ||
super(); | ||
this.#parent = parent; | ||
} | ||
/** | ||
* Creates a fresh instance of the underlying schema type | ||
* and wraps it inside the nullable modifier | ||
*/ | ||
clone() { | ||
return new _NullableModifier(this.#parent.clone()); | ||
} | ||
/** | ||
* Compiles to compiler node | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
const output = this.#parent[PARSE](propertyName, refs, options); | ||
output.allowNull = true; | ||
return output; | ||
} | ||
}; | ||
var OptionalModifier = class _OptionalModifier extends BaseModifiersType { | ||
#parent; | ||
constructor(parent) { | ||
super(); | ||
this.#parent = parent; | ||
} | ||
/** | ||
* Creates a fresh instance of the underlying schema type | ||
* and wraps it inside the optional modifier | ||
*/ | ||
clone() { | ||
return new _OptionalModifier(this.#parent.clone()); | ||
} | ||
/** | ||
* Compiles to compiler node | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
const output = this.#parent[PARSE](propertyName, refs, options); | ||
output.isOptional = true; | ||
return output; | ||
} | ||
}; | ||
var TransformModifier = class _TransformModifier extends BaseModifiersType { | ||
#parent; | ||
#transform; | ||
constructor(transform, parent) { | ||
super(); | ||
this.#transform = transform; | ||
this.#parent = parent; | ||
} | ||
/** | ||
* Creates a fresh instance of the underlying schema type | ||
* and wraps it inside the transform modifier. | ||
*/ | ||
clone() { | ||
return new _TransformModifier(this.#transform, this.#parent.clone()); | ||
} | ||
/** | ||
* Compiles to compiler node | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
const output = this.#parent[PARSE](propertyName, refs, options); | ||
output.transformFnId = refs.trackTransformer(this.#transform); | ||
return output; | ||
} | ||
}; | ||
var BaseLiteralType = class extends BaseModifiersType { | ||
/** | ||
* Field options | ||
*/ | ||
options; | ||
/** | ||
* Set of validations to run | ||
*/ | ||
validations; | ||
constructor(options, validations) { | ||
super(); | ||
this.options = { | ||
bail: true, | ||
allowNull: false, | ||
isOptional: false, | ||
...options | ||
}; | ||
this.validations = validations || []; | ||
} | ||
/** | ||
* Shallow clones the validations. Since, there are no API's to mutate | ||
* the validation options, we can safely copy them by reference. | ||
*/ | ||
cloneValidations() { | ||
return this.validations.map((validation) => { | ||
return { | ||
options: validation.options, | ||
rule: validation.rule | ||
}; | ||
}); | ||
} | ||
/** | ||
* Shallow clones the options | ||
*/ | ||
cloneOptions() { | ||
return { ...this.options }; | ||
} | ||
/** | ||
* Compiles validations | ||
*/ | ||
compileValidations(refs) { | ||
return this.validations.map((validation) => { | ||
return { | ||
ruleFnId: refs.track({ | ||
validator: validation.rule.validator, | ||
options: validation.options | ||
}), | ||
implicit: validation.rule.implicit, | ||
isAsync: validation.rule.isAsync | ||
}; | ||
}); | ||
} | ||
/** | ||
* Define a method to parse the input value. The method | ||
* is invoked before any validation and hence you must | ||
* perform type-checking to know the value you are | ||
* working it. | ||
*/ | ||
parse(callback) { | ||
this.options.parse = callback; | ||
return this; | ||
} | ||
/** | ||
* Push a validation to the validations chain. | ||
*/ | ||
use(validation) { | ||
this.validations.push(VALIDATION in validation ? validation[VALIDATION]() : validation); | ||
return this; | ||
} | ||
/** | ||
* Enable/disable the bail mode. In bail mode, the field validations | ||
* are stopped after the first error. | ||
*/ | ||
bail(state) { | ||
this.options.bail = state; | ||
return this; | ||
} | ||
/** | ||
* Compiles the schema type to a compiler node | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
return { | ||
type: "literal", | ||
fieldName: propertyName, | ||
propertyName: options.toCamelCase ? camelcase(propertyName) : propertyName, | ||
bail: this.options.bail, | ||
allowNull: this.options.allowNull, | ||
isOptional: this.options.isOptional, | ||
parseFnId: this.options.parse ? refs.trackParser(this.options.parse) : void 0, | ||
validations: this.compileValidations(refs) | ||
}; | ||
} | ||
}; | ||
// src/schema/any/main.ts | ||
var VineAny = class _VineAny extends BaseLiteralType { | ||
constructor(options, validations) { | ||
super(options, validations); | ||
} | ||
/** | ||
* Clones the VineAny schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone() { | ||
return new _VineAny(this.cloneOptions(), this.cloneValidations()); | ||
} | ||
}; | ||
// src/schema/enum/rules.ts | ||
var enumRule = createRule((value, options, field) => { | ||
const choices = typeof options.choices === "function" ? options.choices(field) : options.choices; | ||
if (!choices.includes(value)) { | ||
field.report(messages.enum, "enum", field, { choices }); | ||
} | ||
}); | ||
// src/schema/enum/main.ts | ||
var VineEnum = class _VineEnum extends BaseLiteralType { | ||
/** | ||
* Default collection of enum rules | ||
*/ | ||
static rules = { | ||
enum: enumRule | ||
}; | ||
#values; | ||
/** | ||
* Returns the enum choices | ||
*/ | ||
getChoices() { | ||
return this.#values; | ||
} | ||
constructor(values, options, validations) { | ||
super(options, validations || [enumRule({ choices: values })]); | ||
this.#values = values; | ||
} | ||
/** | ||
* Clones the VineEnum schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone() { | ||
return new _VineEnum(this.#values, this.cloneOptions(), this.cloneValidations()); | ||
} | ||
}; | ||
// src/schema/union/main.ts | ||
import camelcase2 from "camelcase"; | ||
var VineUnion = class _VineUnion { | ||
#conditionals; | ||
#otherwiseCallback = (_, field) => { | ||
field.report(messages.union, "union", field); | ||
}; | ||
constructor(conditionals) { | ||
this.#conditionals = conditionals; | ||
} | ||
/** | ||
* Define a fallback method to invoke when all of the union conditions | ||
* fail. You may use this method to report an error. | ||
*/ | ||
otherwise(callback) { | ||
this.#otherwiseCallback = callback; | ||
return this; | ||
} | ||
/** | ||
* Clones the VineUnion schema type. | ||
*/ | ||
clone() { | ||
const cloned = new _VineUnion(this.#conditionals); | ||
cloned.otherwise(this.#otherwiseCallback); | ||
return cloned; | ||
} | ||
/** | ||
* Compiles to a union | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
return { | ||
type: "union", | ||
fieldName: propertyName, | ||
propertyName: options.toCamelCase ? camelcase2(propertyName) : propertyName, | ||
elseConditionalFnRefId: refs.trackConditional(this.#otherwiseCallback), | ||
conditions: this.#conditionals.map( | ||
(conditional) => conditional[PARSE](propertyName, refs, options) | ||
) | ||
}; | ||
} | ||
}; | ||
// src/schema/union/conditional.ts | ||
var UnionConditional = class { | ||
/** | ||
* Properties to merge when conditonal is true | ||
*/ | ||
#schema; | ||
/** | ||
* Conditional to evaluate | ||
*/ | ||
#conditional; | ||
constructor(conditional, schema) { | ||
this.#schema = schema; | ||
this.#conditional = conditional; | ||
} | ||
/** | ||
* Compiles to a union conditional | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
return { | ||
conditionalFnRefId: refs.trackConditional(this.#conditional), | ||
schema: this.#schema[PARSE](propertyName, refs, options) | ||
}; | ||
} | ||
}; | ||
// src/schema/union/builder.ts | ||
function union(conditionals) { | ||
return new VineUnion(conditionals); | ||
} | ||
union.if = function unionIf(conditon, schema) { | ||
return new UnionConditional(conditon, schema); | ||
}; | ||
union.else = function unionElse(schema) { | ||
return new UnionConditional(() => true, schema); | ||
}; | ||
// src/schema/tuple/main.ts | ||
import camelcase3 from "camelcase"; | ||
// src/schema/base/main.ts | ||
import Macroable2 from "@poppinss/macroable"; | ||
var BaseModifiersType2 = class extends Macroable2 { | ||
/** | ||
* Mark the field under validation as optional. An optional | ||
* field allows both null and undefined values. | ||
*/ | ||
optional() { | ||
return new OptionalModifier2(this); | ||
} | ||
/** | ||
* Mark the field under validation to be null. The null value will | ||
* be written to the output as well. | ||
* | ||
* If `optional` and `nullable` are used together, then both undefined | ||
* and null values will be allowed. | ||
*/ | ||
nullable() { | ||
return new NullableModifier2(this); | ||
} | ||
}; | ||
var NullableModifier2 = class _NullableModifier extends BaseModifiersType2 { | ||
#parent; | ||
constructor(parent) { | ||
super(); | ||
this.#parent = parent; | ||
} | ||
/** | ||
* Creates a fresh instance of the underlying schema type | ||
* and wraps it inside the nullable modifier | ||
*/ | ||
clone() { | ||
return new _NullableModifier(this.#parent.clone()); | ||
} | ||
/** | ||
* Compiles to compiler node | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
const output = this.#parent[PARSE](propertyName, refs, options); | ||
if (output.type !== "union") { | ||
output.allowNull = true; | ||
} | ||
return output; | ||
} | ||
}; | ||
var OptionalModifier2 = class _OptionalModifier extends BaseModifiersType2 { | ||
#parent; | ||
constructor(parent) { | ||
super(); | ||
this.#parent = parent; | ||
} | ||
/** | ||
* Creates a fresh instance of the underlying schema type | ||
* and wraps it inside the optional modifier | ||
*/ | ||
clone() { | ||
return new _OptionalModifier(this.#parent.clone()); | ||
} | ||
/** | ||
* Compiles to compiler node | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
const output = this.#parent[PARSE](propertyName, refs, options); | ||
if (output.type !== "union") { | ||
output.isOptional = true; | ||
} | ||
return output; | ||
} | ||
}; | ||
var BaseType = class extends BaseModifiersType2 { | ||
/** | ||
* Field options | ||
*/ | ||
options; | ||
/** | ||
* Set of validations to run | ||
*/ | ||
validations; | ||
constructor(options, validations) { | ||
super(); | ||
this.options = options || { | ||
bail: true, | ||
allowNull: false, | ||
isOptional: false | ||
}; | ||
this.validations = validations || []; | ||
} | ||
/** | ||
* Shallow clones the validations. Since, there are no API's to mutate | ||
* the validation options, we can safely copy them by reference. | ||
*/ | ||
cloneValidations() { | ||
return this.validations.map((validation) => { | ||
return { | ||
options: validation.options, | ||
rule: validation.rule | ||
}; | ||
}); | ||
} | ||
/** | ||
* Shallow clones the options | ||
*/ | ||
cloneOptions() { | ||
return { ...this.options }; | ||
} | ||
/** | ||
* Compiles validations | ||
*/ | ||
compileValidations(refs) { | ||
return this.validations.map((validation) => { | ||
return { | ||
ruleFnId: refs.track({ | ||
validator: validation.rule.validator, | ||
options: validation.options | ||
}), | ||
implicit: validation.rule.implicit, | ||
isAsync: validation.rule.isAsync | ||
}; | ||
}); | ||
} | ||
/** | ||
* Define a method to parse the input value. The method | ||
* is invoked before any validation and hence you must | ||
* perform type-checking to know the value you are | ||
* working it. | ||
*/ | ||
parse(callback) { | ||
this.options.parse = callback; | ||
return this; | ||
} | ||
/** | ||
* Push a validation to the validations chain. | ||
*/ | ||
use(validation) { | ||
this.validations.push(VALIDATION in validation ? validation[VALIDATION]() : validation); | ||
return this; | ||
} | ||
/** | ||
* Enable/disable the bail mode. In bail mode, the field validations | ||
* are stopped after the first error. | ||
*/ | ||
bail(state) { | ||
this.options.bail = state; | ||
return this; | ||
} | ||
}; | ||
// src/schema/tuple/main.ts | ||
var VineTuple = class _VineTuple extends BaseType { | ||
#schemas; | ||
/** | ||
* Whether or not to allow unknown properties | ||
*/ | ||
#allowUnknownProperties = false; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME] = "vine.array"; | ||
/** | ||
* Checks if the value is of array type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE] = (value) => { | ||
return Array.isArray(value); | ||
}; | ||
constructor(schemas, options, validations) { | ||
super(options, validations); | ||
this.#schemas = schemas; | ||
} | ||
/** | ||
* Copy unknown properties to the final output. | ||
*/ | ||
allowUnknownProperties() { | ||
this.#allowUnknownProperties = true; | ||
return this; | ||
} | ||
/** | ||
* Clone object | ||
*/ | ||
clone() { | ||
const cloned = new _VineTuple( | ||
this.#schemas.map((schema) => schema.clone()), | ||
this.cloneOptions(), | ||
this.cloneValidations() | ||
); | ||
if (this.#allowUnknownProperties) { | ||
cloned.allowUnknownProperties(); | ||
} | ||
return cloned; | ||
} | ||
/** | ||
* Compiles to array data type | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
return { | ||
type: "tuple", | ||
fieldName: propertyName, | ||
propertyName: options.toCamelCase ? camelcase3(propertyName) : propertyName, | ||
bail: this.options.bail, | ||
allowNull: this.options.allowNull, | ||
isOptional: this.options.isOptional, | ||
allowUnknownProperties: this.#allowUnknownProperties, | ||
parseFnId: this.options.parse ? refs.trackParser(this.options.parse) : void 0, | ||
validations: this.compileValidations(refs), | ||
properties: this.#schemas.map((schema, index) => schema[PARSE](String(index), refs, options)) | ||
}; | ||
} | ||
}; | ||
// src/schema/array/main.ts | ||
import camelcase4 from "camelcase"; | ||
// src/schema/array/rules.ts | ||
var minLengthRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (value.length < options.min) { | ||
field.report(messages["array.minLength"], "array.minLength", field, options); | ||
} | ||
}); | ||
var maxLengthRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (value.length > options.max) { | ||
field.report(messages["array.maxLength"], "array.maxLength", field, options); | ||
} | ||
}); | ||
var fixedLengthRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (value.length !== options.size) { | ||
field.report(messages["array.fixedLength"], "array.fixedLength", field, options); | ||
} | ||
}); | ||
var notEmptyRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (value.length <= 0) { | ||
field.report(messages.notEmpty, "notEmpty", field); | ||
} | ||
}); | ||
var distinctRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!helpers.isDistinct(value, options.fields)) { | ||
field.report(messages.distinct, "distinct", field, options); | ||
} | ||
}); | ||
var compactRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
field.mutate( | ||
value.filter((item) => helpers.exists(item) && item !== ""), | ||
field | ||
); | ||
}); | ||
// src/schema/array/main.ts | ||
var VineArray = class _VineArray extends BaseType { | ||
/** | ||
* Default collection of array rules | ||
*/ | ||
static rules = { | ||
compact: compactRule, | ||
notEmpty: notEmptyRule, | ||
distinct: distinctRule, | ||
minLength: minLengthRule, | ||
maxLength: maxLengthRule, | ||
fixedLength: fixedLengthRule | ||
}; | ||
#schema; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME] = "vine.array"; | ||
/** | ||
* Checks if the value is of array type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE] = (value) => { | ||
return Array.isArray(value); | ||
}; | ||
constructor(schema, options, validations) { | ||
super(options, validations); | ||
this.#schema = schema; | ||
} | ||
/** | ||
* Enforce a minimum length on an array field | ||
*/ | ||
minLength(expectedLength) { | ||
return this.use(minLengthRule({ min: expectedLength })); | ||
} | ||
/** | ||
* Enforce a maximum length on an array field | ||
*/ | ||
maxLength(expectedLength) { | ||
return this.use(maxLengthRule({ max: expectedLength })); | ||
} | ||
/** | ||
* Enforce a fixed length on an array field | ||
*/ | ||
fixedLength(expectedLength) { | ||
return this.use(fixedLengthRule({ size: expectedLength })); | ||
} | ||
/** | ||
* Ensure the array is not empty | ||
*/ | ||
notEmpty() { | ||
return this.use(notEmptyRule()); | ||
} | ||
/** | ||
* Ensure array elements are distinct/unique | ||
*/ | ||
distinct(fields2) { | ||
return this.use(distinctRule({ fields: fields2 })); | ||
} | ||
/** | ||
* Removes empty strings, null and undefined values from the array | ||
*/ | ||
compact() { | ||
return this.use(compactRule()); | ||
} | ||
/** | ||
* Clones the VineArray schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone() { | ||
return new _VineArray(this.#schema.clone(), this.cloneOptions(), this.cloneValidations()); | ||
} | ||
/** | ||
* Compiles to array data type | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
return { | ||
type: "array", | ||
fieldName: propertyName, | ||
propertyName: options.toCamelCase ? camelcase4(propertyName) : propertyName, | ||
bail: this.options.bail, | ||
allowNull: this.options.allowNull, | ||
isOptional: this.options.isOptional, | ||
each: this.#schema[PARSE]("*", refs, options), | ||
parseFnId: this.options.parse ? refs.trackParser(this.options.parse) : void 0, | ||
validations: this.compileValidations(refs) | ||
}; | ||
} | ||
}; | ||
// src/schema/object/main.ts | ||
import camelcase5 from "camelcase"; | ||
var VineCamelCaseObject = class _VineCamelCaseObject extends BaseModifiersType2 { | ||
#schema; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME] = "types.object"; | ||
/** | ||
* Checks if the value is of object type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE] = (value) => { | ||
return value !== null && typeof value === "object" && !Array.isArray(value); | ||
}; | ||
constructor(schema) { | ||
super(); | ||
this.#schema = schema; | ||
} | ||
/** | ||
* Clone object | ||
*/ | ||
clone() { | ||
return new _VineCamelCaseObject(this.#schema.clone()); | ||
} | ||
/** | ||
* Compiles the schema type to a compiler node | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
options.toCamelCase = true; | ||
return this.#schema[PARSE](propertyName, refs, options); | ||
} | ||
}; | ||
var VineObject = class _VineObject extends BaseType { | ||
/** | ||
* Object properties | ||
*/ | ||
#properties; | ||
/** | ||
* Object groups to merge based on conditionals | ||
*/ | ||
#groups = []; | ||
/** | ||
* Whether or not to allow unknown properties | ||
*/ | ||
#allowUnknownProperties = false; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME] = "vine.object"; | ||
/** | ||
* Checks if the value is of object type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE] = (value) => { | ||
return value !== null && typeof value === "object" && !Array.isArray(value); | ||
}; | ||
constructor(properties, options, validations) { | ||
super(options, validations); | ||
this.#properties = properties; | ||
} | ||
/** | ||
* Returns a clone copy of the object properties. The object groups | ||
* are not copied to keep the implementations simple and easy to | ||
* reason about. | ||
*/ | ||
getProperties() { | ||
return Object.keys(this.#properties).reduce((result, key) => { | ||
result[key] = this.#properties[key].clone(); | ||
return result; | ||
}, {}); | ||
} | ||
/** | ||
* Copy unknown properties to the final output. | ||
*/ | ||
allowUnknownProperties() { | ||
this.#allowUnknownProperties = true; | ||
return this; | ||
} | ||
/** | ||
* Merge a union to the object groups. The union can be a "vine.union" | ||
* with objects, or a "vine.object.union" with properties. | ||
*/ | ||
merge(group2) { | ||
this.#groups.push(group2); | ||
return this; | ||
} | ||
/** | ||
* Clone object | ||
*/ | ||
clone() { | ||
const cloned = new _VineObject( | ||
this.getProperties(), | ||
this.cloneOptions(), | ||
this.cloneValidations() | ||
); | ||
this.#groups.forEach((group2) => cloned.merge(group2)); | ||
if (this.#allowUnknownProperties) { | ||
cloned.allowUnknownProperties(); | ||
} | ||
return cloned; | ||
} | ||
/** | ||
* Applies camelcase transform | ||
*/ | ||
toCamelCase() { | ||
return new VineCamelCaseObject(this); | ||
} | ||
/** | ||
* Compiles the schema type to a compiler node | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
return { | ||
type: "object", | ||
fieldName: propertyName, | ||
propertyName: options.toCamelCase ? camelcase5(propertyName) : propertyName, | ||
bail: this.options.bail, | ||
allowNull: this.options.allowNull, | ||
isOptional: this.options.isOptional, | ||
parseFnId: this.options.parse ? refs.trackParser(this.options.parse) : void 0, | ||
allowUnknownProperties: this.#allowUnknownProperties, | ||
validations: this.compileValidations(refs), | ||
properties: Object.keys(this.#properties).map((property) => { | ||
return this.#properties[property][PARSE](property, refs, options); | ||
}), | ||
groups: this.#groups.map((group2) => { | ||
return group2[PARSE](refs, options); | ||
}) | ||
}; | ||
} | ||
}; | ||
// src/schema/record/main.ts | ||
import camelcase6 from "camelcase"; | ||
// src/schema/record/rules.ts | ||
var minLengthRule2 = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (Object.keys(value).length < options.min) { | ||
field.report(messages["record.minLength"], "record.minLength", field, options); | ||
} | ||
}); | ||
var maxLengthRule2 = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (Object.keys(value).length > options.max) { | ||
field.report(messages["record.maxLength"], "record.maxLength", field, options); | ||
} | ||
}); | ||
var fixedLengthRule2 = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (Object.keys(value).length !== options.size) { | ||
field.report(messages["record.fixedLength"], "record.fixedLength", field, options); | ||
} | ||
}); | ||
var validateKeysRule = createRule( | ||
(value, callback, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
callback(Object.keys(value), field); | ||
} | ||
); | ||
// src/schema/record/main.ts | ||
var VineRecord = class _VineRecord extends BaseType { | ||
/** | ||
* Default collection of record rules | ||
*/ | ||
static rules = { | ||
maxLength: maxLengthRule2, | ||
minLength: minLengthRule2, | ||
fixedLength: fixedLengthRule2, | ||
validateKeys: validateKeysRule | ||
}; | ||
#schema; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME] = "vine.object"; | ||
/** | ||
* Checks if the value is of object type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE] = (value) => { | ||
return value !== null && typeof value === "object" && !Array.isArray(value); | ||
}; | ||
constructor(schema, options, validations) { | ||
super(options, validations); | ||
this.#schema = schema; | ||
} | ||
/** | ||
* Enforce a minimum length on an object field | ||
*/ | ||
minLength(expectedLength) { | ||
return this.use(minLengthRule2({ min: expectedLength })); | ||
} | ||
/** | ||
* Enforce a maximum length on an object field | ||
*/ | ||
maxLength(expectedLength) { | ||
return this.use(maxLengthRule2({ max: expectedLength })); | ||
} | ||
/** | ||
* Enforce a fixed length on an object field | ||
*/ | ||
fixedLength(expectedLength) { | ||
return this.use(fixedLengthRule2({ size: expectedLength })); | ||
} | ||
/** | ||
* Register a callback to validate the object keys | ||
*/ | ||
validateKeys(...args) { | ||
return this.use(validateKeysRule(...args)); | ||
} | ||
/** | ||
* Clones the VineRecord schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone() { | ||
return new _VineRecord( | ||
this.#schema.clone(), | ||
this.cloneOptions(), | ||
this.cloneValidations() | ||
); | ||
} | ||
/** | ||
* Compiles to record data type | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
return { | ||
type: "record", | ||
fieldName: propertyName, | ||
propertyName: options.toCamelCase ? camelcase6(propertyName) : propertyName, | ||
bail: this.options.bail, | ||
allowNull: this.options.allowNull, | ||
isOptional: this.options.isOptional, | ||
each: this.#schema[PARSE]("*", refs, options), | ||
parseFnId: this.options.parse ? refs.trackParser(this.options.parse) : void 0, | ||
validations: this.compileValidations(refs) | ||
}; | ||
} | ||
}; | ||
// src/schema/string/rules.ts | ||
import normalizeEmail from "validator/lib/normalizeEmail.js"; | ||
import escape from "validator/lib/escape.js"; | ||
import camelcase7 from "camelcase"; | ||
import normalizeUrl from "normalize-url"; | ||
var stringRule = createRule((value, _, field) => { | ||
if (typeof value !== "string") { | ||
field.report(messages.string, "string", field); | ||
} | ||
}); | ||
var emailRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!helpers.isEmail(value, options)) { | ||
field.report(messages.email, "email", field); | ||
} | ||
}); | ||
var mobileRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
const normalizedOptions = options && typeof options === "function" ? options(field) : options; | ||
const locales = normalizedOptions?.locale || "any"; | ||
if (!helpers.isMobilePhone(value, locales, normalizedOptions)) { | ||
field.report(messages.mobile, "mobile", field); | ||
} | ||
}); | ||
var ipAddressRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!helpers.isIP(value, options?.version)) { | ||
field.report(messages.ipAddress, "ipAddress", field); | ||
} | ||
}); | ||
var regexRule = createRule((value, expression, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!expression.test(value)) { | ||
field.report(messages.regex, "regex", field); | ||
} | ||
}); | ||
var hexCodeRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!helpers.isHexColor(value)) { | ||
field.report(messages.hexCode, "hexCode", field); | ||
} | ||
}); | ||
var urlRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!helpers.isURL(value, options)) { | ||
field.report(messages.url, "url", field); | ||
} | ||
}); | ||
var activeUrlRule = createRule(async (value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!await helpers.isActiveURL(value)) { | ||
field.report(messages.activeUrl, "activeUrl", field); | ||
} | ||
}); | ||
var alphaRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
let characterSet = "a-zA-Z"; | ||
if (options) { | ||
if (options.allowSpaces) { | ||
characterSet += "\\s"; | ||
} | ||
if (options.allowDashes) { | ||
characterSet += "-"; | ||
} | ||
if (options.allowUnderscores) { | ||
characterSet += "_"; | ||
} | ||
} | ||
const expression = new RegExp(`^[${characterSet}]+$`); | ||
if (!expression.test(value)) { | ||
field.report(messages.alpha, "alpha", field); | ||
} | ||
}); | ||
var alphaNumericRule = createRule( | ||
(value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
let characterSet = "a-zA-Z0-9"; | ||
if (options) { | ||
if (options.allowSpaces) { | ||
characterSet += "\\s"; | ||
} | ||
if (options.allowDashes) { | ||
characterSet += "-"; | ||
} | ||
if (options.allowUnderscores) { | ||
characterSet += "_"; | ||
} | ||
} | ||
const expression = new RegExp(`^[${characterSet}]+$`); | ||
if (!expression.test(value)) { | ||
field.report(messages.alphaNumeric, "alphaNumeric", field); | ||
} | ||
} | ||
); | ||
var minLengthRule3 = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (value.length < options.min) { | ||
field.report(messages.minLength, "minLength", field, options); | ||
} | ||
}); | ||
var maxLengthRule3 = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (value.length > options.max) { | ||
field.report(messages.maxLength, "maxLength", field, options); | ||
} | ||
}); | ||
var fixedLengthRule3 = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (value.length !== options.size) { | ||
field.report(messages.fixedLength, "fixedLength", field, options); | ||
} | ||
}); | ||
var endsWithRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!value.endsWith(options.substring)) { | ||
field.report(messages.endsWith, "endsWith", field, options); | ||
} | ||
}); | ||
var startsWithRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!value.startsWith(options.substring)) { | ||
field.report(messages.startsWith, "startsWith", field, options); | ||
} | ||
}); | ||
var sameAsRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
const input = field.parent[options.otherField]; | ||
if (input !== value) { | ||
field.report(messages.sameAs, "sameAs", field, options); | ||
return; | ||
} | ||
}); | ||
var notSameAsRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
const input = field.parent[options.otherField]; | ||
if (input === value) { | ||
field.report(messages.notSameAs, "notSameAs", field, options); | ||
return; | ||
} | ||
}); | ||
var confirmedRule = createRule( | ||
(value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
const otherField = options?.confirmationField || `${field.name}_confirmation`; | ||
const input = field.parent[otherField]; | ||
if (input !== value) { | ||
field.report(messages.confirmed, "confirmed", field, { otherField }); | ||
return; | ||
} | ||
} | ||
); | ||
var trimRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
field.mutate(value.trim(), field); | ||
}); | ||
var normalizeEmailRule = createRule( | ||
(value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
field.mutate(normalizeEmail.default(value, options), field); | ||
} | ||
); | ||
var toUpperCaseRule = createRule( | ||
(value, locales, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
field.mutate(value.toLocaleUpperCase(locales), field); | ||
} | ||
); | ||
var toLowerCaseRule = createRule( | ||
(value, locales, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
field.mutate(value.toLocaleLowerCase(locales), field); | ||
} | ||
); | ||
var toCamelCaseRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
field.mutate(camelcase7(value), field); | ||
}); | ||
var escapeRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
field.mutate(escape.default(value), field); | ||
}); | ||
var normalizeUrlRule = createRule( | ||
(value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
field.mutate(normalizeUrl(value, options), field); | ||
} | ||
); | ||
var inRule = createRule( | ||
(value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
const choices = typeof options.choices === "function" ? options.choices(field) : options.choices; | ||
if (!choices.includes(value)) { | ||
field.report(messages.in, "in", field, options); | ||
return; | ||
} | ||
} | ||
); | ||
var notInRule = createRule( | ||
(value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
const list = typeof options.list === "function" ? options.list(field) : options.list; | ||
if (list.includes(value)) { | ||
field.report(messages.notIn, "notIn", field, options); | ||
return; | ||
} | ||
} | ||
); | ||
var creditCardRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
const providers = options ? typeof options === "function" ? options(field)?.provider || [] : options.provider : []; | ||
if (!providers.length) { | ||
if (!helpers.isCreditCard(value)) { | ||
field.report(messages.creditCard, "creditCard", field, { | ||
providersList: "credit" | ||
}); | ||
} | ||
} else { | ||
const matchesAnyProvider = providers.find( | ||
(provider) => helpers.isCreditCard(value, { provider }) | ||
); | ||
if (!matchesAnyProvider) { | ||
field.report(messages.creditCard, "creditCard", field, { | ||
providers, | ||
providersList: providers.join("/") | ||
}); | ||
} | ||
} | ||
}); | ||
var passportRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
const countryCodes = typeof options === "function" ? options(field).countryCode : options.countryCode; | ||
const matchesAnyCountryCode = countryCodes.find( | ||
(countryCode) => helpers.isPassportNumber(value, countryCode) | ||
); | ||
if (!matchesAnyCountryCode) { | ||
field.report(messages.passport, "passport", field, { countryCodes }); | ||
} | ||
}); | ||
var postalCodeRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
const countryCodes = options ? typeof options === "function" ? options(field)?.countryCode || [] : options.countryCode : []; | ||
if (!countryCodes.length) { | ||
if (!helpers.isPostalCode(value, "any")) { | ||
field.report(messages.postalCode, "postalCode", field); | ||
} | ||
} else { | ||
const matchesAnyCountryCode = countryCodes.find( | ||
(countryCode) => helpers.isPostalCode(value, countryCode) | ||
); | ||
if (!matchesAnyCountryCode) { | ||
field.report(messages.postalCode, "postalCode", field, { countryCodes }); | ||
} | ||
} | ||
}); | ||
var uuidRule = createRule( | ||
(value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!options || !options.version) { | ||
if (!helpers.isUUID(value)) { | ||
field.report(messages.uuid, "uuid", field); | ||
} | ||
} else { | ||
const matchesAnyVersion = options.version.find( | ||
(version) => helpers.isUUID(value, version) | ||
); | ||
if (!matchesAnyVersion) { | ||
field.report(messages.uuid, "uuid", field, options); | ||
} | ||
} | ||
} | ||
); | ||
var asciiRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!helpers.isAscii(value)) { | ||
field.report(messages.ascii, "ascii", field); | ||
} | ||
}); | ||
var ibanRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!helpers.isIBAN(value)) { | ||
field.report(messages.iban, "iban", field); | ||
} | ||
}); | ||
var jwtRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!helpers.isJWT(value)) { | ||
field.report(messages.jwt, "jwt", field); | ||
} | ||
}); | ||
var coordinatesRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!helpers.isLatLong(value)) { | ||
field.report(messages.coordinates, "coordinates", field); | ||
} | ||
}); | ||
// src/schema/string/main.ts | ||
var VineString = class _VineString extends BaseLiteralType { | ||
static rules = { | ||
in: inRule, | ||
jwt: jwtRule, | ||
url: urlRule, | ||
iban: ibanRule, | ||
uuid: uuidRule, | ||
trim: trimRule, | ||
email: emailRule, | ||
alpha: alphaRule, | ||
ascii: asciiRule, | ||
notIn: notInRule, | ||
regex: regexRule, | ||
escape: escapeRule, | ||
sameAs: sameAsRule, | ||
mobile: mobileRule, | ||
string: stringRule, | ||
hexCode: hexCodeRule, | ||
passport: passportRule, | ||
endsWith: endsWithRule, | ||
confirmed: confirmedRule, | ||
activeUrl: activeUrlRule, | ||
minLength: minLengthRule3, | ||
notSameAs: notSameAsRule, | ||
maxLength: maxLengthRule3, | ||
ipAddress: ipAddressRule, | ||
creditCard: creditCardRule, | ||
postalCode: postalCodeRule, | ||
startsWith: startsWithRule, | ||
toUpperCase: toUpperCaseRule, | ||
toLowerCase: toLowerCaseRule, | ||
toCamelCase: toCamelCaseRule, | ||
fixedLength: fixedLengthRule3, | ||
coordinates: coordinatesRule, | ||
normalizeUrl: normalizeUrlRule, | ||
alphaNumeric: alphaNumericRule, | ||
normalizeEmail: normalizeEmailRule | ||
}; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME] = "vine.string"; | ||
/** | ||
* Checks if the value is of string type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE] = (value) => { | ||
return typeof value === "string"; | ||
}; | ||
constructor(options, validations) { | ||
super(options, validations || [stringRule()]); | ||
} | ||
/** | ||
* Validates the value to be a valid URL | ||
*/ | ||
url(...args) { | ||
return this.use(urlRule(...args)); | ||
} | ||
/** | ||
* Validates the value to be an active URL | ||
*/ | ||
activeUrl() { | ||
return this.use(activeUrlRule()); | ||
} | ||
/** | ||
* Validates the value to be a valid email address | ||
*/ | ||
email(...args) { | ||
return this.use(emailRule(...args)); | ||
} | ||
/** | ||
* Validates the value to be a valid mobile number | ||
*/ | ||
mobile(...args) { | ||
return this.use(mobileRule(...args)); | ||
} | ||
/** | ||
* Validates the value to be a valid IP address. | ||
*/ | ||
ipAddress(version) { | ||
return this.use(ipAddressRule(version ? { version } : void 0)); | ||
} | ||
/** | ||
* Validates the value to be a valid hex color code | ||
*/ | ||
hexCode() { | ||
return this.use(hexCodeRule()); | ||
} | ||
/** | ||
* Validates the value to be an active URL | ||
*/ | ||
regex(expression) { | ||
return this.use(regexRule(expression)); | ||
} | ||
/** | ||
* Validates the value to contain only letters | ||
*/ | ||
alpha(options) { | ||
return this.use(alphaRule(options)); | ||
} | ||
/** | ||
* Validates the value to contain only letters and | ||
* numbers | ||
*/ | ||
alphaNumeric(options) { | ||
return this.use(alphaNumericRule(options)); | ||
} | ||
/** | ||
* Enforce a minimum length on a string field | ||
*/ | ||
minLength(expectedLength) { | ||
return this.use(minLengthRule3({ min: expectedLength })); | ||
} | ||
/** | ||
* Enforce a maximum length on a string field | ||
*/ | ||
maxLength(expectedLength) { | ||
return this.use(maxLengthRule3({ max: expectedLength })); | ||
} | ||
/** | ||
* Enforce a fixed length on a string field | ||
*/ | ||
fixedLength(expectedLength) { | ||
return this.use(fixedLengthRule3({ size: expectedLength })); | ||
} | ||
/** | ||
* Ensure the field under validation is confirmed by | ||
* having another field with the same name. | ||
*/ | ||
confirmed(options) { | ||
return this.use(confirmedRule(options)); | ||
} | ||
/** | ||
* Trims whitespaces around the string value | ||
*/ | ||
trim() { | ||
return this.use(trimRule()); | ||
} | ||
/** | ||
* Normalizes the email address | ||
*/ | ||
normalizeEmail(options) { | ||
return this.use(normalizeEmailRule(options)); | ||
} | ||
/** | ||
* Converts the field value to UPPERCASE. | ||
*/ | ||
toUpperCase() { | ||
return this.use(toUpperCaseRule()); | ||
} | ||
/** | ||
* Converts the field value to lowercase. | ||
*/ | ||
toLowerCase() { | ||
return this.use(toLowerCaseRule()); | ||
} | ||
/** | ||
* Converts the field value to camelCase. | ||
*/ | ||
toCamelCase() { | ||
return this.use(toCamelCaseRule()); | ||
} | ||
/** | ||
* Escape string for HTML entities | ||
*/ | ||
escape() { | ||
return this.use(escapeRule()); | ||
} | ||
/** | ||
* Normalize a URL | ||
*/ | ||
normalizeUrl(...args) { | ||
return this.use(normalizeUrlRule(...args)); | ||
} | ||
/** | ||
* Ensure the value starts with the pre-defined substring | ||
*/ | ||
startsWith(substring) { | ||
return this.use(startsWithRule({ substring })); | ||
} | ||
/** | ||
* Ensure the value ends with the pre-defined substring | ||
*/ | ||
endsWith(substring) { | ||
return this.use(endsWithRule({ substring })); | ||
} | ||
/** | ||
* Ensure the value ends with the pre-defined substring | ||
*/ | ||
sameAs(otherField) { | ||
return this.use(sameAsRule({ otherField })); | ||
} | ||
/** | ||
* Ensure the value ends with the pre-defined substring | ||
*/ | ||
notSameAs(otherField) { | ||
return this.use(notSameAsRule({ otherField })); | ||
} | ||
/** | ||
* Ensure the field's value under validation is a subset of the pre-defined list. | ||
*/ | ||
in(choices) { | ||
return this.use(inRule({ choices })); | ||
} | ||
/** | ||
* Ensure the field's value under validation is not inside the pre-defined list. | ||
*/ | ||
notIn(list) { | ||
return this.use(notInRule({ list })); | ||
} | ||
/** | ||
* Validates the value to be a valid credit card number | ||
*/ | ||
creditCard(...args) { | ||
return this.use(creditCardRule(...args)); | ||
} | ||
/** | ||
* Validates the value to be a valid passport number | ||
*/ | ||
passport(...args) { | ||
return this.use(passportRule(...args)); | ||
} | ||
/** | ||
* Validates the value to be a valid postal code | ||
*/ | ||
postalCode(...args) { | ||
return this.use(postalCodeRule(...args)); | ||
} | ||
/** | ||
* Validates the value to be a valid UUID | ||
*/ | ||
uuid(...args) { | ||
return this.use(uuidRule(...args)); | ||
} | ||
/** | ||
* Validates the value contains ASCII characters only | ||
*/ | ||
ascii() { | ||
return this.use(asciiRule()); | ||
} | ||
/** | ||
* Validates the value to be a valid IBAN number | ||
*/ | ||
iban() { | ||
return this.use(ibanRule()); | ||
} | ||
/** | ||
* Validates the value to be a valid JWT token | ||
*/ | ||
jwt() { | ||
return this.use(jwtRule()); | ||
} | ||
/** | ||
* Ensure the value is a string with latitude and longitude coordinates | ||
*/ | ||
coordinates() { | ||
return this.use(coordinatesRule()); | ||
} | ||
/** | ||
* Clones the VineString schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone() { | ||
return new _VineString(this.cloneOptions(), this.cloneValidations()); | ||
} | ||
}; | ||
// src/schema/number/rules.ts | ||
var numberRule = createRule((value, options, field) => { | ||
const valueAsNumber = options.strict ? value : helpers.asNumber(value); | ||
if (typeof valueAsNumber !== "number" || Number.isNaN(valueAsNumber) || valueAsNumber === Number.POSITIVE_INFINITY || valueAsNumber === Number.NEGATIVE_INFINITY) { | ||
field.report(messages.number, "number", field); | ||
return; | ||
} | ||
field.mutate(valueAsNumber, field); | ||
}); | ||
var minRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (value < options.min) { | ||
field.report(messages.min, "min", field, options); | ||
} | ||
}); | ||
var maxRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (value > options.max) { | ||
field.report(messages.max, "max", field, options); | ||
} | ||
}); | ||
var rangeRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (value < options.min || value > options.max) { | ||
field.report(messages.range, "range", field, options); | ||
} | ||
}); | ||
var positiveRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (value < 0) { | ||
field.report(messages.positive, "positive", field); | ||
} | ||
}); | ||
var negativeRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (value >= 0) { | ||
field.report(messages.negative, "negative", field); | ||
} | ||
}); | ||
var decimalRule = createRule((value, options, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!helpers.isDecimal(String(value), { | ||
force_decimal: options.range[0] !== 0, | ||
decimal_digits: options.range.join(",") | ||
})) { | ||
field.report(messages.decimal, "decimal", field, { digits: options.range.join("-") }); | ||
} | ||
}); | ||
var withoutDecimalsRule = createRule((value, _, field) => { | ||
if (!field.isValid) { | ||
return; | ||
} | ||
if (!Number.isInteger(value)) { | ||
field.report(messages.withoutDecimals, "withoutDecimals", field); | ||
} | ||
}); | ||
// src/schema/number/main.ts | ||
var VineNumber = class _VineNumber extends BaseLiteralType { | ||
/** | ||
* Default collection of number rules | ||
*/ | ||
static rules = { | ||
max: maxRule, | ||
min: minRule, | ||
range: rangeRule, | ||
number: numberRule, | ||
decimal: decimalRule, | ||
negative: negativeRule, | ||
positive: positiveRule, | ||
withoutDecimals: withoutDecimalsRule | ||
}; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME] = "vine.number"; | ||
/** | ||
* Checks if the value is of number type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE] = (value) => { | ||
const valueAsNumber = helpers.asNumber(value); | ||
return !Number.isNaN(valueAsNumber); | ||
}; | ||
constructor(options, validations) { | ||
super(options, validations || [numberRule(options || {})]); | ||
} | ||
/** | ||
* Enforce a minimum value for the number input | ||
*/ | ||
min(value) { | ||
return this.use(minRule({ min: value })); | ||
} | ||
/** | ||
* Enforce a maximum value for the number input | ||
*/ | ||
max(value) { | ||
return this.use(maxRule({ max: value })); | ||
} | ||
/** | ||
* Enforce value to be within the range of minimum and maximum output. | ||
*/ | ||
range(value) { | ||
return this.use(rangeRule({ min: value[0], max: value[1] })); | ||
} | ||
/** | ||
* Enforce the value be a positive number | ||
*/ | ||
positive() { | ||
return this.use(positiveRule()); | ||
} | ||
/** | ||
* Enforce the value be a negative number | ||
*/ | ||
negative() { | ||
return this.use(negativeRule()); | ||
} | ||
/** | ||
* Enforce the value to have fixed or range | ||
* of decimal places | ||
*/ | ||
decimal(range) { | ||
return this.use(decimalRule({ range: Array.isArray(range) ? range : [range] })); | ||
} | ||
/** | ||
* Enforce the value to be an integer (aka without decimals) | ||
*/ | ||
withoutDecimals() { | ||
return this.use(withoutDecimalsRule()); | ||
} | ||
/** | ||
* Clones the VineNumber schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone() { | ||
return new _VineNumber(this.cloneOptions(), this.cloneValidations()); | ||
} | ||
}; | ||
// src/schema/boolean/rules.ts | ||
var booleanRule = createRule((value, options, field) => { | ||
const valueAsBoolean = options.strict === true ? value : helpers.asBoolean(value); | ||
if (typeof valueAsBoolean !== "boolean") { | ||
field.report(messages.boolean, "boolean", field); | ||
return; | ||
} | ||
field.mutate(valueAsBoolean, field); | ||
}); | ||
// src/schema/boolean/main.ts | ||
var VineBoolean = class _VineBoolean extends BaseLiteralType { | ||
/** | ||
* Default collection of boolean rules | ||
*/ | ||
static rules = { | ||
boolean: booleanRule | ||
}; | ||
/** | ||
* The property must be implemented for "unionOfTypes" | ||
*/ | ||
[UNIQUE_NAME] = "vine.boolean"; | ||
/** | ||
* Checks if the value is of boolean type. The method must be | ||
* implemented for "unionOfTypes" | ||
*/ | ||
[IS_OF_TYPE] = (value) => { | ||
const valueAsBoolean = this.options.strict === true ? value : helpers.asBoolean(value); | ||
return typeof valueAsBoolean === "boolean"; | ||
}; | ||
constructor(options, validations) { | ||
super(options, validations || [booleanRule(options || {})]); | ||
} | ||
/** | ||
* Clones the VineBoolean schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone() { | ||
return new _VineBoolean(this.cloneOptions(), this.cloneValidations()); | ||
} | ||
}; | ||
// src/schema/literal/rules.ts | ||
var equalsRule = createRule((value, options, field) => { | ||
let input = value; | ||
if (typeof options.expectedValue === "boolean") { | ||
input = helpers.asBoolean(value); | ||
} else if (typeof options.expectedValue === "number") { | ||
input = helpers.asNumber(value); | ||
} | ||
if (input !== options.expectedValue) { | ||
field.report(messages.literal, "literal", field, options); | ||
return; | ||
} | ||
field.mutate(input, field); | ||
}); | ||
// src/schema/literal/main.ts | ||
var VineLiteral = class _VineLiteral extends BaseLiteralType { | ||
/** | ||
* Default collection of literal rules | ||
*/ | ||
static rules = { | ||
equals: equalsRule | ||
}; | ||
#value; | ||
constructor(value, options, validations) { | ||
super(options, validations || [equalsRule({ expectedValue: value })]); | ||
this.#value = value; | ||
} | ||
/** | ||
* Clones the VineLiteral schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone() { | ||
return new _VineLiteral(this.#value, this.cloneOptions(), this.cloneValidations()); | ||
} | ||
}; | ||
// src/schema/accepted/rules.ts | ||
var ACCEPTED_VALUES = ["on", "1", "yes", "true", true, 1]; | ||
var acceptedRule = createRule((value, _, field) => { | ||
if (!ACCEPTED_VALUES.includes(value)) { | ||
field.report(messages.accepted, "accepted", field); | ||
} | ||
}); | ||
// src/schema/accepted/main.ts | ||
var VineAccepted = class _VineAccepted extends BaseLiteralType { | ||
/** | ||
* Default collection of accepted rules | ||
*/ | ||
static rules = { | ||
accepted: acceptedRule | ||
}; | ||
constructor(options, validations) { | ||
super(options, validations || [acceptedRule()]); | ||
} | ||
/** | ||
* Clones the VineAccepted schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone() { | ||
return new _VineAccepted(this.cloneOptions(), this.cloneValidations()); | ||
} | ||
}; | ||
// src/schema/object/group.ts | ||
var ObjectGroup = class _ObjectGroup { | ||
#conditionals; | ||
#otherwiseCallback = (_, field) => { | ||
field.report(messages.unionGroup, "unionGroup", field); | ||
}; | ||
constructor(conditionals) { | ||
this.#conditionals = conditionals; | ||
} | ||
/** | ||
* Clones the ObjectGroup schema type. | ||
*/ | ||
clone() { | ||
const cloned = new _ObjectGroup(this.#conditionals); | ||
cloned.otherwise(this.#otherwiseCallback); | ||
return cloned; | ||
} | ||
/** | ||
* Define a fallback method to invoke when all of the group conditions | ||
* fail. You may use this method to report an error. | ||
*/ | ||
otherwise(callback) { | ||
this.#otherwiseCallback = callback; | ||
return this; | ||
} | ||
/** | ||
* Compiles the group | ||
*/ | ||
[PARSE](refs, options) { | ||
return { | ||
type: "group", | ||
elseConditionalFnRefId: refs.trackConditional(this.#otherwiseCallback), | ||
conditions: this.#conditionals.map((conditional) => conditional[PARSE](refs, options)) | ||
}; | ||
} | ||
}; | ||
// src/schema/object/conditional.ts | ||
var GroupConditional = class { | ||
/** | ||
* Properties to merge when conditonal is true | ||
*/ | ||
#properties; | ||
/** | ||
* Conditional to evaluate | ||
*/ | ||
#conditional; | ||
constructor(conditional, properties) { | ||
this.#properties = properties; | ||
this.#conditional = conditional; | ||
} | ||
/** | ||
* Compiles to a union conditional | ||
*/ | ||
[PARSE](refs, options) { | ||
return { | ||
schema: { | ||
type: "sub_object", | ||
properties: Object.keys(this.#properties).map((property) => { | ||
return this.#properties[property][PARSE](property, refs, options); | ||
}), | ||
groups: [] | ||
// Compiler allows nested groups, but we are not implementing it | ||
}, | ||
conditionalFnRefId: refs.trackConditional(this.#conditional) | ||
}; | ||
} | ||
}; | ||
// src/schema/object/group_builder.ts | ||
function group(conditionals) { | ||
return new ObjectGroup(conditionals); | ||
} | ||
group.if = function groupIf(conditon, properties) { | ||
return new GroupConditional(conditon, properties); | ||
}; | ||
group.else = function groupElse(properties) { | ||
return new GroupConditional(() => true, properties); | ||
}; | ||
// src/schema/enum/native_enum.ts | ||
var VineNativeEnum = class _VineNativeEnum extends BaseLiteralType { | ||
/** | ||
* Default collection of enum rules | ||
*/ | ||
static rules = { | ||
enum: enumRule | ||
}; | ||
#values; | ||
constructor(values, options, validations) { | ||
super(options, validations || [enumRule({ choices: Object.values(values) })]); | ||
this.#values = values; | ||
} | ||
/** | ||
* Clones the VineNativeEnum schema type. The applied options | ||
* and validations are copied to the new instance | ||
*/ | ||
clone() { | ||
return new _VineNativeEnum(this.#values, this.cloneOptions(), this.cloneValidations()); | ||
} | ||
}; | ||
// src/schema/union_of_types/main.ts | ||
import camelcase8 from "camelcase"; | ||
var VineUnionOfTypes = class _VineUnionOfTypes { | ||
#schemas; | ||
#otherwiseCallback = (_, field) => { | ||
field.report(messages.unionOfTypes, "unionOfTypes", field); | ||
}; | ||
constructor(schemas) { | ||
this.#schemas = schemas; | ||
} | ||
/** | ||
* Define a fallback method to invoke when all of the union conditions | ||
* fail. You may use this method to report an error. | ||
*/ | ||
otherwise(callback) { | ||
this.#otherwiseCallback = callback; | ||
return this; | ||
} | ||
/** | ||
* Clones the VineUnionOfTypes schema type. | ||
*/ | ||
clone() { | ||
const cloned = new _VineUnionOfTypes(this.#schemas); | ||
cloned.otherwise(this.#otherwiseCallback); | ||
return cloned; | ||
} | ||
/** | ||
* Compiles to a union | ||
*/ | ||
[PARSE](propertyName, refs, options) { | ||
return { | ||
type: "union", | ||
fieldName: propertyName, | ||
propertyName: options.toCamelCase ? camelcase8(propertyName) : propertyName, | ||
elseConditionalFnRefId: refs.trackConditional(this.#otherwiseCallback), | ||
conditions: this.#schemas.map((schema) => { | ||
return { | ||
conditionalFnRefId: refs.trackConditional((value, field) => { | ||
return schema[IS_OF_TYPE](value, field); | ||
}), | ||
schema: schema[PARSE](propertyName, refs, options) | ||
}; | ||
}) | ||
}; | ||
} | ||
}; | ||
// src/schema/builder.ts | ||
var SchemaBuilder = class extends Macroable3 { | ||
/** | ||
* Define a sub-object as a union | ||
*/ | ||
group = group; | ||
/** | ||
* Define a union value | ||
*/ | ||
union = union; | ||
/** | ||
* Define a string value | ||
*/ | ||
string() { | ||
return new VineString(); | ||
} | ||
/** | ||
* Define a boolean value | ||
*/ | ||
boolean(options) { | ||
return new VineBoolean(options); | ||
} | ||
/** | ||
* Validate a checkbox to be checked | ||
*/ | ||
accepted() { | ||
return new VineAccepted(); | ||
} | ||
/** | ||
* Define a number value | ||
*/ | ||
number(options) { | ||
return new VineNumber(options); | ||
} | ||
/** | ||
* Define a schema type in which the input value | ||
* matches the pre-defined value | ||
*/ | ||
literal(value) { | ||
return new VineLiteral(value); | ||
} | ||
/** | ||
* Define an object with known properties. You may call "allowUnknownProperties" | ||
* to merge unknown properties. | ||
*/ | ||
object(properties) { | ||
return new VineObject(properties); | ||
} | ||
/** | ||
* Define an array field and validate its children elements. | ||
*/ | ||
array(schema) { | ||
return new VineArray(schema); | ||
} | ||
/** | ||
* Define an array field with known length and each children | ||
* element may have its own schema. | ||
*/ | ||
tuple(schemas) { | ||
return new VineTuple(schemas); | ||
} | ||
/** | ||
* Define an object field with key-value pair. The keys in | ||
* a record are unknown and values can be of a specific | ||
* schema type. | ||
*/ | ||
record(schema) { | ||
return new VineRecord(schema); | ||
} | ||
enum(values) { | ||
if (Array.isArray(values) || typeof values === "function") { | ||
return new VineEnum(values); | ||
} | ||
return new VineNativeEnum(values); | ||
} | ||
/** | ||
* Allow the field value to be anything | ||
*/ | ||
any() { | ||
return new VineAny(); | ||
} | ||
/** | ||
* Define a union of unique schema types. | ||
*/ | ||
unionOfTypes(schemas) { | ||
const schemasInUse = /* @__PURE__ */ new Set(); | ||
schemas.forEach((schema) => { | ||
if (!schema[IS_OF_TYPE] || !schema[UNIQUE_NAME]) { | ||
throw new Error( | ||
`Cannot use "${schema.constructor.name}". The schema type is not compatible for use with "vine.unionOfTypes"` | ||
); | ||
} | ||
if (schemasInUse.has(schema[UNIQUE_NAME])) { | ||
throw new Error( | ||
`Cannot use duplicate schema "${schema[UNIQUE_NAME]}". "vine.unionOfTypes" needs distinct schema types only` | ||
); | ||
} | ||
schemasInUse.add(schema[UNIQUE_NAME]); | ||
}); | ||
schemasInUse.clear(); | ||
return new VineUnionOfTypes(schemas); | ||
} | ||
}; | ||
// src/vine/validator.ts | ||
import { Compiler, refsBuilder } from "@vinejs/compiler"; | ||
var COMPILER_ERROR_MESSAGES = { | ||
required: messages.required, | ||
array: messages.array, | ||
object: messages.object | ||
}; | ||
var VineValidator = class { | ||
/** | ||
* Validator to use to validate metadata | ||
*/ | ||
#metaDataValidator; | ||
/** | ||
* Messages provider to use on the validator | ||
*/ | ||
messagesProvider; | ||
/** | ||
* Error reporter to use on the validator | ||
*/ | ||
errorReporter; | ||
/** | ||
* Parses schema to compiler nodes. | ||
*/ | ||
#parse(schema) { | ||
const refs = refsBuilder(); | ||
return { | ||
compilerNode: { | ||
type: "root", | ||
schema: schema[PARSE]("", refs, { toCamelCase: false }) | ||
}, | ||
refs: refs.toJSON() | ||
}; | ||
} | ||
/** | ||
* Refs computed from the compiled output | ||
*/ | ||
#refs; | ||
/** | ||
* Compiled validator function | ||
*/ | ||
#validateFn; | ||
constructor(schema, options) { | ||
const { compilerNode, refs } = this.#parse(schema); | ||
this.#refs = refs; | ||
this.#validateFn = new Compiler(compilerNode, { | ||
convertEmptyStringsToNull: options.convertEmptyStringsToNull, | ||
messages: COMPILER_ERROR_MESSAGES | ||
}).compile(); | ||
this.errorReporter = options.errorReporter; | ||
this.messagesProvider = options.messagesProvider; | ||
this.#metaDataValidator = options.metaDataValidator; | ||
} | ||
/** | ||
* Validate data against a schema. Optionally, you can share metaData with | ||
* the validator | ||
* | ||
* ```ts | ||
* await validator.validate(data) | ||
* await validator.validate(data, { meta: {} }) | ||
* | ||
* await validator.validate(data, { | ||
* meta: { userId: auth.user.id }, | ||
* errorReporter, | ||
* messagesProvider | ||
* }) | ||
* ``` | ||
*/ | ||
validate(data, ...[options]) { | ||
if (options?.meta && this.#metaDataValidator) { | ||
this.#metaDataValidator(options.meta); | ||
} | ||
const errorReporter = options?.errorReporter || this.errorReporter; | ||
const messagesProvider = options?.messagesProvider || this.messagesProvider; | ||
return this.#validateFn( | ||
data, | ||
options?.meta || {}, | ||
this.#refs, | ||
messagesProvider, | ||
errorReporter() | ||
); | ||
} | ||
}; | ||
// src/vine/main.ts | ||
var Vine = class extends SchemaBuilder { | ||
/** | ||
* Messages provider to use on the validator | ||
*/ | ||
messagesProvider = new SimpleMessagesProvider(messages, fields); | ||
/** | ||
* Error reporter to use on the validator | ||
*/ | ||
errorReporter = () => new SimpleErrorReporter(); | ||
/** | ||
* Control whether or not to convert empty strings to null | ||
*/ | ||
convertEmptyStringsToNull = false; | ||
/** | ||
* Helpers to perform type-checking or cast types keeping | ||
* HTML forms serialization behavior in mind. | ||
*/ | ||
helpers = helpers; | ||
/** | ||
* Convert a validation function to a Vine schema rule | ||
*/ | ||
createRule = createRule; | ||
/** | ||
* Pre-compiles a schema into a validation function. | ||
* | ||
* ```ts | ||
* const validate = vine.compile(schema) | ||
* await validate({ data }) | ||
* ``` | ||
*/ | ||
compile(schema) { | ||
return new VineValidator(schema, { | ||
convertEmptyStringsToNull: this.convertEmptyStringsToNull, | ||
messagesProvider: this.messagesProvider, | ||
errorReporter: this.errorReporter | ||
}); | ||
} | ||
/** | ||
* Define a callback to validate the metadata given to the validator | ||
* at runtime | ||
*/ | ||
withMetaData(callback) { | ||
return { | ||
compile: (schema) => { | ||
return new VineValidator(schema, { | ||
convertEmptyStringsToNull: this.convertEmptyStringsToNull, | ||
messagesProvider: this.messagesProvider, | ||
errorReporter: this.errorReporter, | ||
metaDataValidator: callback | ||
}); | ||
} | ||
}; | ||
} | ||
/** | ||
* Validate data against a schema. Optionally, you can define | ||
* error messages, fields, a custom messages provider, | ||
* or an error reporter. | ||
* | ||
* ```ts | ||
* await vine.validate({ schema, data }) | ||
* await vine.validate({ schema, data, messages, fields }) | ||
* | ||
* await vine.validate({ schema, data, messages, fields }, { | ||
* errorReporter | ||
* }) | ||
* ``` | ||
*/ | ||
validate(options) { | ||
const validator = this.compile(options.schema); | ||
return validator.validate(options.data, options); | ||
} | ||
}; | ||
// index.ts | ||
var vine = new Vine(); | ||
var vine_default = vine; | ||
} from "./chunk-U7IQLI4H.js"; | ||
import "./chunk-CSAU5B4Q.js"; | ||
export { | ||
BaseLiteralType, | ||
BaseModifiersType2 as BaseModifiersType, | ||
BaseModifiersType, | ||
BaseType, | ||
@@ -2290,2 +41,3 @@ SimpleErrorReporter, | ||
VineBoolean, | ||
VineDate, | ||
VineEnum, | ||
@@ -2304,1 +56,2 @@ VineLiteral, | ||
}; | ||
//# sourceMappingURL=index.js.map |
/** | ||
* Collection of default error messages to use | ||
*/ | ||
declare const messages: { | ||
export declare const messages: { | ||
required: string; | ||
@@ -61,2 +61,16 @@ string: string; | ||
unionOfTypes: string; | ||
date: string; | ||
'date.equals': string; | ||
'date.after': string; | ||
'date.before': string; | ||
'date.afterOrEqual': string; | ||
'date.beforeOrEqual': string; | ||
'date.sameAs': string; | ||
'date.notSameAs': string; | ||
'date.afterField': string; | ||
'date.afterOrSameAs': string; | ||
'date.beforeField': string; | ||
'date.beforeOrSameAs': string; | ||
'date.weekend': string; | ||
'date.weekday': string; | ||
}; | ||
@@ -66,6 +80,4 @@ /** | ||
*/ | ||
declare const fields: { | ||
export declare const fields: { | ||
'': string; | ||
}; | ||
export { fields, messages }; |
import { | ||
fields, | ||
messages | ||
} from "../chunk-OQONERRF.js"; | ||
import "../chunk-QPO2OBYN.js"; | ||
} from "../chunk-LKAXJ6BU.js"; | ||
import "../chunk-CSAU5B4Q.js"; | ||
export { | ||
@@ -10,1 +10,2 @@ fields, | ||
}; | ||
//# sourceMappingURL=defaults.js.map |
@@ -1,10 +0,214 @@ | ||
export { ConditionalFn, FieldContext, MessagesProviderContact, RefIdentifier, Refs } from '@vinejs/compiler/types'; | ||
import 'normalize-url'; | ||
import 'validator/lib/isURL.js'; | ||
import 'validator/lib/isEmail.js'; | ||
export { NormalizeEmailOptions } from 'validator/lib/normalizeEmail.js'; | ||
import 'validator/lib/isMobilePhone.js'; | ||
import 'validator/lib/isPostalCode.js'; | ||
export { i as AlphaNumericOptions, A as AlphaOptions, C as ConstructableSchema, f as CreditCardOptions, q as EmailOptions, E as EnumLike, j as ErrorReporterContract, F as FieldOptions, m as Infer, k as MetaDataValidator, M as MobileOptions, N as NormalizeUrlOptions, P as Parser, c as ParserOptions, g as PassportOptions, h as PostalCodeOptions, R as RuleBuilder, S as SchemaTypes, T as Transformer, r as URLOptions, U as UnionNoMatchCallback, a as Validation, p as ValidationFields, o as ValidationMessages, l as ValidationOptions, t as ValidationRule, V as Validator } from '../types-8973fb04.js'; | ||
import 'validator'; | ||
import 'validator/lib/isIBAN.js'; | ||
import type dayjs from 'dayjs'; | ||
import type { Options as UrlOptions } from 'normalize-url'; | ||
import type { IsURLOptions } from 'validator/lib/isURL.js'; | ||
import type { IsEmailOptions } from 'validator/lib/isEmail.js'; | ||
import type { PostalCodeLocale } from 'validator/lib/isPostalCode.js'; | ||
import type { NormalizeEmailOptions } from 'validator/lib/normalizeEmail.js'; | ||
import type { IsMobilePhoneOptions, MobilePhoneLocale } from 'validator/lib/isMobilePhone.js'; | ||
import type { ParseFn, RefsStore, TransformFn, FieldContext, CompilerNodes, MessagesProviderContact, ErrorReporterContract as BaseReporter } from '@vinejs/compiler/types'; | ||
import type { helpers } from './vine/helpers.js'; | ||
import type { ValidationError } from './errors/validation_error.js'; | ||
import type { OTYPE, COTYPE, PARSE, VALIDATION, UNIQUE_NAME, IS_OF_TYPE } from './symbols.js'; | ||
/** | ||
* Options accepted by the mobile number validation | ||
*/ | ||
export type MobileOptions = { | ||
locale?: MobilePhoneLocale[]; | ||
} & IsMobilePhoneOptions; | ||
/** | ||
* Options accepted by the email address validation | ||
*/ | ||
export type EmailOptions = IsEmailOptions; | ||
/** | ||
* Options accepted by the normalize email | ||
*/ | ||
export { NormalizeEmailOptions }; | ||
/** | ||
* Options accepted by the URL validation | ||
*/ | ||
export type URLOptions = IsURLOptions; | ||
/** | ||
* Options accepted by the credit card validation | ||
*/ | ||
export type CreditCardOptions = { | ||
provider: ('amex' | 'dinersclub' | 'discover' | 'jcb' | 'mastercard' | 'unionpay' | 'visa')[]; | ||
}; | ||
/** | ||
* Options accepted by the passport validation | ||
*/ | ||
export type PassportOptions = { | ||
countryCode: (typeof helpers)['passportCountryCodes'][number][]; | ||
}; | ||
/** | ||
* Options accepted by the postal code validation | ||
*/ | ||
export type PostalCodeOptions = { | ||
countryCode: PostalCodeLocale[]; | ||
}; | ||
/** | ||
* Options accepted by the alpha rule | ||
*/ | ||
export type AlphaOptions = { | ||
allowSpaces?: boolean; | ||
allowUnderscores?: boolean; | ||
allowDashes?: boolean; | ||
}; | ||
export type NormalizeUrlOptions = UrlOptions; | ||
/** | ||
* Options accepted by the alpha numeric rule | ||
*/ | ||
export type AlphaNumericOptions = AlphaOptions; | ||
/** | ||
* Re-exporting selected types from compiler | ||
*/ | ||
export type { Refs, FieldContext, RefIdentifier, ConditionalFn, MessagesProviderContact, } from '@vinejs/compiler/types'; | ||
/** | ||
* Representation of a native enum like type | ||
*/ | ||
export type EnumLike = { | ||
[K: string]: string | number; | ||
[number: number]: string; | ||
}; | ||
/** | ||
* Representation of fields and messages accepted by the messages | ||
* provider | ||
*/ | ||
export type ValidationMessages = Record<string, string>; | ||
export type ValidationFields = Record<string, string>; | ||
/** | ||
* Constructable schema type refers to any type that can be | ||
* constructed for type inference and compiler output | ||
*/ | ||
export interface ConstructableSchema<Output, CamelCaseOutput> { | ||
[OTYPE]: Output; | ||
[COTYPE]: CamelCaseOutput; | ||
[PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): CompilerNodes; | ||
clone(): this; | ||
/** | ||
* Implement if you want schema type to be used with the unionOfTypes | ||
*/ | ||
[UNIQUE_NAME]?: string; | ||
[IS_OF_TYPE]?: (value: unknown, field: FieldContext) => boolean; | ||
} | ||
export type SchemaTypes = ConstructableSchema<any, any>; | ||
/** | ||
* Representation of a function that performs validation. | ||
* The function receives the following arguments. | ||
* | ||
* - the current value of the input field | ||
* - runtime options | ||
* - field context | ||
*/ | ||
export type Validator<Options extends any> = (value: unknown, options: Options, field: FieldContext) => any | Promise<any>; | ||
/** | ||
* A validation rule is a combination of a validator and | ||
* some metadata required at the time of compiling the | ||
* rule. | ||
* | ||
* Think of this type as "Validator" + "metaData" | ||
*/ | ||
export type ValidationRule<Options extends any> = { | ||
validator: Validator<Options>; | ||
isAsync: boolean; | ||
implicit: boolean; | ||
}; | ||
/** | ||
* Validation is a combination of a validation rule and the options | ||
* to supply to validator at the time of validating the field. | ||
* | ||
* Think of this type as "ValidationRule" + "options" | ||
*/ | ||
export type Validation<Options extends any> = { | ||
/** | ||
* Options to pass to the validator function. | ||
*/ | ||
options?: Options; | ||
/** | ||
* The rule to use | ||
*/ | ||
rule: ValidationRule<Options>; | ||
}; | ||
/** | ||
* A rule builder is an object that implements the "VALIDATION" | ||
* method and returns [[Validation]] type | ||
*/ | ||
export interface RuleBuilder { | ||
[VALIDATION](): Validation<any>; | ||
} | ||
/** | ||
* The transform function to mutate the output value | ||
*/ | ||
export type Transformer<Schema extends SchemaTypes, Output> = TransformFn<Exclude<Schema[typeof OTYPE], undefined>, Output>; | ||
/** | ||
* The parser function to mutate the input value | ||
*/ | ||
export type Parser = ParseFn; | ||
/** | ||
* A set of options accepted by the field | ||
*/ | ||
export type FieldOptions = { | ||
allowNull: boolean; | ||
bail: boolean; | ||
isOptional: boolean; | ||
parse?: Parser; | ||
}; | ||
/** | ||
* A set of options accepted by the date field | ||
*/ | ||
export type DateFieldOptions = { | ||
formats?: dayjs.OptionType; | ||
}; | ||
/** | ||
* A set of options accepted by the equals rule | ||
* on the date field | ||
*/ | ||
export type DateEqualsOptions = { | ||
compare?: dayjs.OpUnitType; | ||
format?: dayjs.OptionType; | ||
}; | ||
/** | ||
* Options accepted when compiling schema types. | ||
*/ | ||
export type ParserOptions = { | ||
toCamelCase: boolean; | ||
}; | ||
/** | ||
* Method to invoke when union has no match | ||
*/ | ||
export type UnionNoMatchCallback<Input> = (value: Input, field: FieldContext) => any; | ||
/** | ||
* Error reporters must implement the reporter contract interface | ||
*/ | ||
export interface ErrorReporterContract extends BaseReporter { | ||
createError(): ValidationError; | ||
} | ||
/** | ||
* The validator function to validate metadata given to a validation | ||
* pipeline | ||
*/ | ||
export type MetaDataValidator = (meta: Record<string, any>) => void; | ||
/** | ||
* Options accepted during the validate call. | ||
*/ | ||
export type ValidationOptions<MetaData extends Record<string, any> | undefined> = { | ||
/** | ||
* Messages provider is used to resolve error messages during | ||
* the validation lifecycle | ||
*/ | ||
messagesProvider?: MessagesProviderContact; | ||
/** | ||
* Validation errors are reported directly to an error reporter. The reporter | ||
* can decide how to format and output errors. | ||
*/ | ||
errorReporter?: () => ErrorReporterContract; | ||
} & ([undefined] extends MetaData ? { | ||
meta?: MetaData; | ||
} : { | ||
meta: MetaData; | ||
}); | ||
/** | ||
* Infers the schema type | ||
*/ | ||
export type Infer<Schema extends { | ||
[OTYPE]: any; | ||
}> = Schema[typeof OTYPE]; |
{ | ||
"name": "@vinejs/vine", | ||
"description": "Form data validation library for Node.js", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"engines": { | ||
@@ -11,3 +11,6 @@ "node": ">=18.16.0" | ||
"files": [ | ||
"build" | ||
"build", | ||
"!build/benchmarks", | ||
"!build/bin", | ||
"!build/tests" | ||
], | ||
@@ -23,14 +26,15 @@ "exports": { | ||
"test": "c8 npm run quick:test", | ||
"quick:test": "node --loader=ts-node/esm --enable-source-maps bin/test.ts", | ||
"clean": "del-cli build", | ||
"prebenchmark": "npm run build", | ||
"benchmark": "node build/benchmarks/flat_object.js && node build/benchmarks/nested_object.js && node build/benchmarks/array.js && node build/benchmarks/union.js", | ||
"typecheck": "tsc --noEmit", | ||
"compile": "npm run lint && npm run clean && tsup-node", | ||
"precompile": "npm run lint && npm run clean", | ||
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration", | ||
"build": "npm run compile", | ||
"release": "np", | ||
"version": "npm run build", | ||
"prepublishOnly": "npm run build", | ||
"lint": "eslint . --ext=.ts", | ||
"format": "prettier --write .", | ||
"sync-labels": "github-label-sync --labels .github/labels.json vinejs/vine", | ||
"quick:test": "node --loader=ts-node/esm --enable-source-maps bin/test.ts" | ||
"benchmark": "node build/benchmarks/flat_object.js && node build/benchmarks/nested_object.js && node build/benchmarks/array.js && node build/benchmarks/union.js", | ||
"sync-labels": "github-label-sync --labels .github/labels.json vinejs/vine" | ||
}, | ||
@@ -41,30 +45,33 @@ "devDependencies": { | ||
"@adonisjs/tsconfig": "^1.1.8", | ||
"@commitlint/cli": "^17.6.7", | ||
"@commitlint/config-conventional": "^17.6.7", | ||
"@japa/assert": "^2.0.0-1", | ||
"@japa/expect-type": "^2.0.0-0", | ||
"@japa/runner": "^3.0.0-6", | ||
"@swc/core": "^1.3.70", | ||
"@types/node": "^20.4.2", | ||
"@commitlint/cli": "^18.4.3", | ||
"@commitlint/config-conventional": "^18.4.3", | ||
"@japa/assert": "^2.0.1", | ||
"@japa/expect-type": "^2.0.0", | ||
"@japa/runner": "^3.0.5", | ||
"@swc/core": "^1.3.99", | ||
"@types/dlv": "^1.1.4", | ||
"@types/node": "^20.9.3", | ||
"benchmark": "^2.1.4", | ||
"c8": "^8.0.1", | ||
"del-cli": "^5.0.0", | ||
"eslint": "^8.45.0", | ||
"del-cli": "^5.1.0", | ||
"eslint": "^8.54.0", | ||
"github-label-sync": "^2.3.1", | ||
"husky": "^8.0.3", | ||
"np": "^8.0.4", | ||
"prettier": "^3.0.0", | ||
"prettier": "^3.1.0", | ||
"ts-node": "^10.9.1", | ||
"tsup": "^7.1.0", | ||
"typescript": "^5.1.6", | ||
"yup": "^1.2.0", | ||
"zod": "^3.21.4" | ||
"tsup": "^8.0.1", | ||
"typescript": "5.2.2", | ||
"yup": "^1.3.2", | ||
"zod": "^3.22.4" | ||
}, | ||
"dependencies": { | ||
"@poppinss/macroable": "^1.0.0-7", | ||
"@types/validator": "^13.7.17", | ||
"@vinejs/compiler": "^2.2.0", | ||
"camelcase": "^7.0.1", | ||
"@poppinss/macroable": "^1.0.0", | ||
"@types/validator": "^13.11.7", | ||
"@vinejs/compiler": "^2.3.0", | ||
"camelcase": "^8.0.0", | ||
"dayjs": "^1.11.10", | ||
"dlv": "^1.1.3", | ||
"normalize-url": "^8.0.0", | ||
"validator": "^13.9.0" | ||
"validator": "^13.11.0" | ||
}, | ||
@@ -122,3 +129,7 @@ "author": "virk,vinejs", | ||
"./factories/main.ts", | ||
"./src/types.ts" | ||
"./src/types.ts", | ||
"./benchmarks/flat_object.ts", | ||
"./benchmarks/nested_object.ts", | ||
"./benchmarks/array.ts", | ||
"./benchmarks/union.ts" | ||
], | ||
@@ -128,5 +139,6 @@ "outDir": "./build", | ||
"format": "esm", | ||
"dts": true, | ||
"dts": false, | ||
"sourcemap": true, | ||
"target": "esnext" | ||
} | ||
} |
@@ -15,3 +15,3 @@ # @vinejs/vine | ||
[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![snyk-image]][snyk-url] | ||
[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] | ||
@@ -46,4 +46,4 @@ </div> | ||
[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/vinejs/vine/test.yml?style=for-the-badge | ||
[gh-workflow-url]: https://github.com/vinejs/vine/actions/workflows/test.yml 'Github action' | ||
[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/vinejs/vine/checks.yml?style=for-the-badge | ||
[gh-workflow-url]: https://github.com/vinejs/vine/actions/workflows/checks.yml 'Github action' | ||
[npm-image]: https://img.shields.io/npm/v/@vinejs/vine/latest.svg?style=for-the-badge&logo=npm | ||
@@ -54,3 +54,1 @@ [npm-url]: https://www.npmjs.com/package/@vinejs/vine/v/latest 'npm' | ||
[license-image]: https://img.shields.io/github/license/vinejs/vine?style=for-the-badge | ||
[snyk-image]: https://img.shields.io/snyk/vulnerabilities/github/vinejs/vine?label=Snyk%20Vulnerabilities&style=for-the-badge | ||
[snyk-url]: https://snyk.io/test/github/vinejs/vine?targetFile=package.json 'snyk' |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
416065
67
6316
8
24
52
+ Addeddayjs@^1.11.10
+ Addeddlv@^1.1.3
+ Addedcamelcase@8.0.0(transitive)
+ Addeddayjs@1.11.13(transitive)
+ Addeddlv@1.1.3(transitive)
- Removedcamelcase@7.0.1(transitive)
Updated@poppinss/macroable@^1.0.0
Updated@types/validator@^13.11.7
Updated@vinejs/compiler@^2.3.0
Updatedcamelcase@^8.0.0
Updatedvalidator@^13.11.0