diff --git a/library/CHANGELOG.md b/library/CHANGELOG.md index c87c371bb..7ca3789d2 100644 --- a/library/CHANGELOG.md +++ b/library/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to the library will be documented in this file. - Add `words`, `maxWords`, `minWords` and `notWords` action - Add `args` and `returns` action to transform functions (issue #243) - Add `rfcEmail` action to validate RFC 5322 email addresses (pull request #912) +- Add `ltValue` action for less than validation (pull request #985) - Add new overload signature to `pipe` and `pipeAync` method to support unlimited pipe items of same input and output type (issue #852) - Add `@__NO_SIDE_EFFECTS__` notation to improve tree shaking (pull request #995) - Add `exactOptional` and `exactOptionalAsync` schema (PR #1013) diff --git a/library/src/actions/index.ts b/library/src/actions/index.ts index 095dd721e..f2470f50d 100644 --- a/library/src/actions/index.ts +++ b/library/src/actions/index.ts @@ -37,6 +37,7 @@ export * from './isoTimeSecond/index.ts'; export * from './isoTimestamp/index.ts'; export * from './isoWeek/index.ts'; export * from './length/index.ts'; +export * from './ltValue/index.ts'; export * from './mac/index.ts'; export * from './mac48/index.ts'; export * from './mac64/index.ts'; diff --git a/library/src/actions/ltValue/index.ts b/library/src/actions/ltValue/index.ts new file mode 100644 index 000000000..a1d18f20d --- /dev/null +++ b/library/src/actions/ltValue/index.ts @@ -0,0 +1 @@ +export * from './ltValue.ts'; diff --git a/library/src/actions/ltValue/ltValue.test-d.ts b/library/src/actions/ltValue/ltValue.test-d.ts new file mode 100644 index 000000000..213bd91f7 --- /dev/null +++ b/library/src/actions/ltValue/ltValue.test-d.ts @@ -0,0 +1,45 @@ +import { describe, expectTypeOf, test } from 'vitest'; +import type { InferInput, InferIssue, InferOutput } from '../../types/index.ts'; +import { ltValue, type LtValueAction, type LtValueIssue } from './ltValue.ts'; + +describe('ltValue', () => { + describe('should return action object', () => { + test('with undefined message', () => { + type Action = LtValueAction; + expectTypeOf(ltValue(10)).toEqualTypeOf(); + expectTypeOf( + ltValue(10, undefined) + ).toEqualTypeOf(); + }); + + test('with string message', () => { + expectTypeOf(ltValue(10, 'message')).toEqualTypeOf< + LtValueAction + >(); + }); + + test('with function message', () => { + expectTypeOf( + ltValue string>(10, () => 'message') + ).toEqualTypeOf string>>(); + }); + }); + + describe('should infer correct types', () => { + type Action = LtValueAction; + + test('of input', () => { + expectTypeOf>().toEqualTypeOf(); + }); + + test('of output', () => { + expectTypeOf>().toEqualTypeOf(); + }); + + test('of issue', () => { + expectTypeOf>().toEqualTypeOf< + LtValueIssue + >(); + }); + }); +}); diff --git a/library/src/actions/ltValue/ltValue.test.ts b/library/src/actions/ltValue/ltValue.test.ts new file mode 100644 index 000000000..e28513a80 --- /dev/null +++ b/library/src/actions/ltValue/ltValue.test.ts @@ -0,0 +1,641 @@ +import { describe, expect, test } from 'vitest'; +import type { NumberIssue } from '../../schemas/index.ts'; +import { _stringify } from '../../utils/index.ts'; +import { expectActionIssue, expectNoActionIssue } from '../../vitest/index.ts'; +import { ltValue, type LtValueAction } from './ltValue.ts'; + +describe('ltValue', () => { + describe('should return action object', () => { + const baseAction: Omit, 'message'> = { + kind: 'validation', + type: 'lt_value', + reference: ltValue, + expects: '<5', + requirement: 5, + async: false, + '~run': expect.any(Function), + }; + + test('with undefined message', () => { + const action: LtValueAction = { + ...baseAction, + message: undefined, + }; + expect(ltValue(5)).toStrictEqual(action); + expect(ltValue(5, undefined)).toStrictEqual(action); + }); + + test('with string message', () => { + expect(ltValue(5, 'message')).toStrictEqual({ + ...baseAction, + message: 'message', + } satisfies LtValueAction); + }); + + test('with function message', () => { + const message = () => 'message'; + expect(ltValue(5, message)).toStrictEqual({ + ...baseAction, + message, + } satisfies LtValueAction); + }); + }); + + describe('should return dataset without issues', () => { + test('for untyped inputs', () => { + const issues: [NumberIssue] = [ + { + kind: 'schema', + type: 'number', + input: null, + expected: 'number', + received: 'null', + message: 'message', + }, + ]; + expect( + ltValue(1)['~run']({ typed: false, value: null, issues }, {}) + ).toStrictEqual({ typed: false, value: null, issues }); + }); + + test('for valid bigints', () => { + expectNoActionIssue(ltValue(10n), [-9999n, 0n, 9n]); + }); + + test('for valid non-bigints', () => { + expectNoActionIssue(ltValue(10n), [ + '-10', + '', + ' ', + '0', + '9', + ' 9 ', + -10, + 0, + 9, + -Infinity, + -10.0, + 0.0, + 9.0, + 9.5, + false, + true, + new Date(-10), + new Date(0), + new Date(9), + ]); + + expectNoActionIssue(ltValue(1n), [ + '-1', + '', + ' ', + ' 0 ', + '0', + -1, + 0.0, + 0, + 0.5, + -Infinity, + false, + new Date(-1), + new Date(0), + ]); + + expectNoActionIssue(ltValue(0n), [ + '-1', + ' -1 ', + -0.5, + -1, + -1.0, + -Infinity, + new Date(-1), + ]); + }); + + test('for valid booleans', () => { + expectNoActionIssue(ltValue(true), [false]); + }); + + test('for valid non-booleans', () => { + expectNoActionIssue(ltValue(true), [ + '-1', + ' 0 ', + '0', + '0.5', + -1, + 0.0, + 0, + 0.5, + -Infinity, + new Date(-1), + new Date(0), + -1n, + 0n, + ]); + + expectNoActionIssue(ltValue(false), [ + '-1', + ' -1 ', + '-0.5', + -0.5, + -1, + -1.0, + -Infinity, + new Date(-1), + -1n, + ]); + }); + + test('for valid dates', () => { + const date = new Date(); + expectNoActionIssue(ltValue(date), [ + new Date(0), + new Date(+date - 999999), + new Date(+date - 1), + ]); + }); + + test('for valid non-dates', () => { + const date1 = new Date(10); + expectNoActionIssue(ltValue(date1), [ + '-10', + ' 9 ', + '9', + '9.5', + 9.5, + 9, + 9.0, + -Infinity, + false, + true, + -10n, + 0n, + 9n, + ]); + + const date2 = new Date(1); + expectNoActionIssue(ltValue(date2), [ + '-1', + '', + ' ', + ' 0 ', + '0', + '0.5', + -1, + 0.0, + 0, + 0.5, + -Infinity, + false, + -1n, + 0n, + ]); + + const date3 = new Date(0); + expectNoActionIssue(ltValue(date3), [ + '-1', + ' -1 ', + '-0.5', + -0.5, + -1, + -1.0, + -Infinity, + -1n, + ]); + }); + + test('for valid numbers', () => { + expectNoActionIssue(ltValue(10), [Number.MIN_VALUE, 0, 9, 9.5]); + }); + + test('for valid non-numbers', () => { + expectNoActionIssue(ltValue(10), [ + '-10', + ' 9 ', + '9', + '9.5', + '', + ' ', + false, + true, + new Date(-10), + new Date(0), + new Date(9), + -10n, + 0n, + 9n, + ]); + + expectNoActionIssue(ltValue(1), [ + '-1', + ' 0 ', + '0', + '0.5', + '', + ' ', + false, + new Date(-1), + new Date(0), + -1n, + 0n, + ]); + + expectNoActionIssue(ltValue(0), [ + '-1', + ' -1 ', + '-0.5', + new Date(-1), + -1n, + ]); + }); + + test('for valid strings', () => { + expectNoActionIssue(ltValue('2024'), ['', '1234', '2023']); + }); + + test('for valid non-strings', () => { + expectNoActionIssue(ltValue('10'), [ + -10, + 0, + 9.5, + 9, + 9.0, + -Infinity, + false, + true, + new Date(-10), + new Date(0), + new Date(9), + -10n, + 0n, + 9n, + ]); + + expectNoActionIssue(ltValue('1'), [ + -1, + 0, + 0.5, + -Infinity, + false, + new Date(-1), + new Date(0), + -1n, + 0n, + ]); + + expectNoActionIssue(ltValue('0'), [ + -0.5, + -1, + -1.0, + -Infinity, + new Date(-1), + -1n, + ]); + }); + }); + + describe('should return dataset with issues', () => { + const baseInfo = { + kind: 'validation', + type: 'lt_value', + message: 'message', + } as const; + + const getReceived = (value: unknown): string => + value instanceof Date ? value.toJSON() : _stringify(value); + + test('for invalid bigints', () => { + expectActionIssue( + ltValue(10n, 'message'), + { ...baseInfo, expected: '<10', requirement: 10n }, + [10n, 11n, 9999n] + ); + }); + + test('for invalid non-bigints', () => { + expectActionIssue( + ltValue(123n, 'message'), + { ...baseInfo, expected: '<123', requirement: 123n }, + [ + 'nan', + '122px', + '+ 122', + '122.0', + '123', + '124', + 123, + 124, + 124.0, + Infinity, + NaN, + new Date(123), + new Date(124), + ], + getReceived + ); + + expectActionIssue( + ltValue(1n, 'message'), + { ...baseInfo, expected: '<1', requirement: 1n }, + [ + 'nan', + '0px', + '+ 0', + '0.0', + '1', + 1, + 1.0, + 2, + Infinity, + NaN, + true, + new Date(1), + new Date(2), + ], + getReceived + ); + + expectActionIssue( + ltValue(0n, 'message'), + { ...baseInfo, expected: '<0', requirement: 0n }, + [ + 'nan', + '-1px', + '- 1', + '-1.0', + '0', + 0, + 0.0, + 1, + 1.0, + Infinity, + NaN, + false, + true, + new Date(0), + new Date(1), + ], + getReceived + ); + }); + + test('for invalid booleans', () => { + expectActionIssue( + ltValue(false, 'message'), + { ...baseInfo, expected: ' { + expectActionIssue( + ltValue(false, 'message'), + { ...baseInfo, expected: ' { + const date = new Date(); + expectActionIssue( + ltValue(date, 'message'), + { ...baseInfo, expected: `<${date.toJSON()}`, requirement: date }, + [date, new Date(+date + 1), new Date(+date + 999999)], + (value) => value.toJSON() + ); + }); + + test('for invalid non-dates', () => { + const date1 = new Date(123); + expectActionIssue( + ltValue(date1, 'message'), + { ...baseInfo, expected: `<${date1.toJSON()}`, requirement: date1 }, + [ + 'nan', + '122px', + '+ 122', + '123', + '124.0', + 123, + 124, + 124.0, + Infinity, + NaN, + 123n, + 124n, + ], + getReceived + ); + + const date2 = new Date(1); + expectActionIssue( + ltValue(date2, 'message'), + { ...baseInfo, expected: `<${date2.toJSON()}`, requirement: date2 }, + [ + 'nan', + '0px', + '+ 0', + '1', + '1.0', + 1, + 1.0, + 2, + Infinity, + NaN, + true, + 1n, + 2n, + ], + getReceived + ); + + const date3 = new Date(0); + expectActionIssue( + ltValue(date3, 'message'), + { ...baseInfo, expected: `<${date3.toJSON()}`, requirement: date3 }, + [ + 'nan', + '-1px', + '- 1', + '0', + '0.0', + 0, + 0.0, + 1, + 1.0, + Infinity, + NaN, + false, + true, + 0n, + 1n, + ], + getReceived + ); + }); + + test('for invalid numbers', () => { + expectActionIssue( + ltValue(10, 'message'), + { ...baseInfo, expected: '<10', requirement: 10 }, + [10, 11, 9999, Number.MAX_VALUE, NaN] + ); + }); + + test('for invalid non-numbers', () => { + expectActionIssue( + ltValue(123, 'message'), + { ...baseInfo, expected: '<123', requirement: 123 }, + [ + 'nan', + '122px', + '+ 122', + '123', + '124', + '124.0', + new Date(123), + new Date(124), + 123n, + 124n, + ], + getReceived + ); + + expectActionIssue( + ltValue(1, 'message'), + { ...baseInfo, expected: '<1', requirement: 1 }, + [ + 'nan', + '0px', + '+ 0', + '1', + '1.0', + true, + new Date(1), + new Date(2), + 1n, + 2n, + ], + getReceived + ); + + expectActionIssue( + ltValue(0, 'message'), + { ...baseInfo, expected: '<0', requirement: 0 }, + [ + 'nan', + '-1px', + '- 1', + '0', + '0.0', + false, + true, + new Date(0), + new Date(1), + 0n, + 1n, + ], + getReceived + ); + }); + + test('for invalid strings', () => { + expectActionIssue( + ltValue('2024', 'message'), + { ...baseInfo, expected: '<"2024"', requirement: '2024' }, + ['2024', '2025', '9999', 'XYZ'] + ); + }); + + test('for invalid non-strings', () => { + expectActionIssue( + ltValue('123', 'message'), + { ...baseInfo, expected: '<"123"', requirement: '123' }, + [ + 123, + 124, + 124.0, + Infinity, + NaN, + new Date(123), + new Date(124), + 123n, + 124n, + ], + getReceived + ); + + expectActionIssue( + ltValue('1', 'message'), + { ...baseInfo, expected: '<"1"', requirement: '1' }, + [1, 1.0, 2, Infinity, NaN, true, new Date(1), new Date(2), 1n, 2n], + getReceived + ); + + expectActionIssue( + ltValue('0', 'message'), + { ...baseInfo, expected: '<"0"', requirement: '0' }, + [ + 0, + 0.0, + 1, + 1.0, + Infinity, + NaN, + false, + true, + new Date(0), + new Date(1), + 0n, + 1n, + ], + getReceived + ); + }); + }); +}); diff --git a/library/src/actions/ltValue/ltValue.ts b/library/src/actions/ltValue/ltValue.ts new file mode 100644 index 000000000..d83f4f80f --- /dev/null +++ b/library/src/actions/ltValue/ltValue.ts @@ -0,0 +1,128 @@ +import type { + BaseIssue, + BaseValidation, + ErrorMessage, +} from '../../types/index.ts'; +import { _addIssue, _stringify } from '../../utils/index.ts'; +import type { ValueInput } from '../types.ts'; + +/** + * Less than value issue type. + */ +export interface LtValueIssue< + TInput extends ValueInput, + TRequirement extends TInput, +> extends BaseIssue { + /** + * The issue kind. + */ + readonly kind: 'validation'; + /** + * The issue type. + */ + readonly type: 'lt_value'; + /** + * The expected property. + */ + readonly expected: `<${string}`; + /** + * The less than value. + */ + readonly requirement: TRequirement; +} + +/** + * Less than value action type. + */ +export interface LtValueAction< + TInput extends ValueInput, + TRequirement extends TInput, + TMessage extends ErrorMessage> | undefined, +> extends BaseValidation> { + /** + * The action type. + */ + readonly type: 'lt_value'; + /** + * The action reference. + */ + readonly reference: typeof ltValue; + /** + * The expected property. + */ + readonly expects: `<${string}`; + /** + * The less than value. + */ + readonly requirement: TRequirement; + /** + * The error message. + */ + readonly message: TMessage; +} + +/** + * Creates a less than value validation action. + * + * @param requirement The less than value. + * + * @returns A less than value action. + */ +export function ltValue< + TInput extends ValueInput, + const TRequirement extends TInput, +>(requirement: TRequirement): LtValueAction; + +/** + * Creates a less than value validation action. + * + * @param requirement The less than value. + * @param message The error message. + * + * @returns A less than value action. + */ +export function ltValue< + TInput extends ValueInput, + const TRequirement extends TInput, + const TMessage extends + | ErrorMessage> + | undefined, +>( + requirement: TRequirement, + message: TMessage +): LtValueAction; + +// @__NO_SIDE_EFFECTS__ +export function ltValue( + requirement: ValueInput, + message?: ErrorMessage> +): LtValueAction< + ValueInput, + ValueInput, + ErrorMessage> | undefined +> { + return { + kind: 'validation', + type: 'lt_value', + reference: ltValue, + async: false, + expects: `<${ + requirement instanceof Date + ? requirement.toJSON() + : _stringify(requirement) + }`, + requirement, + message, + '~run'(dataset, config) { + if (dataset.typed && !(dataset.value < this.requirement)) { + _addIssue(this, 'value', dataset, config, { + received: + dataset.value instanceof Date + ? dataset.value.toJSON() + : _stringify(dataset.value), + }); + } + return dataset; + }, + }; +} diff --git a/website/src/routes/api/(actions)/ltValue/index.mdx b/website/src/routes/api/(actions)/ltValue/index.mdx new file mode 100644 index 000000000..18d29d351 --- /dev/null +++ b/website/src/routes/api/(actions)/ltValue/index.mdx @@ -0,0 +1,93 @@ +--- +title: ltValue +description: Creates a less than value validation action. +source: /actions/ltValue/ltValue.ts +contributors: + - EltonLobo07 +--- + +import { ApiList, Property } from '~/components'; +import { properties } from './properties'; + +# ltValue + +Creates a less than value validation action. + +```ts +const Action = v.ltValue(requirement, message); +``` + +## Generics + +- `TInput` +- `TRequirement` +- `TMessage` + +## Parameters + +- `requirement` +- `message` + +### Explanation + +With `ltValue` you can validate the value of a string, number, boolean or date. If the input does not match the `requirement`, you can use `message` to customize the error message. + +## Returns + +- `Action` + +## Examples + +The following examples show how `ltValue` can be used. + +### Number schema + +Schema to validate a number with a less than value. + +```ts +const NumberSchema = v.pipe( + v.number(), + v.ltValue(100, 'The number must be less than 100.') +); +``` + +### Date schema + +Schema to validate a date with a less than value. + +```ts +const DateSchema = v.pipe( + v.date(), + v.ltValue( + new Date('2000-01-01'), + 'The date must be less than 1st January 2000.' + ) +); +``` + +## Related + +The following APIs can be combined with `ltValue`. + +### Schemas + + + +### Methods + + + +### Utils + + diff --git a/website/src/routes/api/(actions)/ltValue/properties.ts b/website/src/routes/api/(actions)/ltValue/properties.ts new file mode 100644 index 000000000..78cad9d3e --- /dev/null +++ b/website/src/routes/api/(actions)/ltValue/properties.ts @@ -0,0 +1,83 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TInput: { + modifier: 'extends', + type: { + type: 'custom', + name: 'ValueInput', + href: '../ValueInput/', + }, + }, + TRequirement: { + modifier: 'extends', + type: { + type: 'custom', + name: 'TInput', + }, + }, + TMessage: { + modifier: 'extends', + type: { + type: 'union', + options: [ + { + type: 'custom', + name: 'ErrorMessage', + href: '../ErrorMessage/', + generics: [ + { + type: 'custom', + name: 'LtValueIssue', + href: '../LtValueIssue/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'TRequirement', + }, + ], + }, + ], + }, + 'undefined', + ], + }, + }, + requirement: { + type: { + type: 'custom', + name: 'TRequirement', + }, + }, + message: { + type: { + type: 'custom', + name: 'TMessage', + }, + }, + Action: { + type: { + type: 'custom', + name: 'LtValueAction', + href: '../LtValueAction/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'TRequirement', + }, + { + type: 'custom', + name: 'TMessage', + }, + ], + }, + }, +}; diff --git a/website/src/routes/api/(async)/customAsync/index.mdx b/website/src/routes/api/(async)/customAsync/index.mdx index fd2ac8f5d..d26b6ae42 100644 --- a/website/src/routes/api/(async)/customAsync/index.mdx +++ b/website/src/routes/api/(async)/customAsync/index.mdx @@ -145,6 +145,7 @@ The following APIs can be combined with `customAsync`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(async)/fallbackAsync/index.mdx b/website/src/routes/api/(async)/fallbackAsync/index.mdx index 1bb850ea5..da170dace 100644 --- a/website/src/routes/api/(async)/fallbackAsync/index.mdx +++ b/website/src/routes/api/(async)/fallbackAsync/index.mdx @@ -173,6 +173,7 @@ The following APIs can be combined with `fallbackAsync`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(async)/intersectAsync/index.mdx b/website/src/routes/api/(async)/intersectAsync/index.mdx index 57d262a63..4d2f5be7f 100644 --- a/website/src/routes/api/(async)/intersectAsync/index.mdx +++ b/website/src/routes/api/(async)/intersectAsync/index.mdx @@ -176,6 +176,7 @@ The following APIs can be combined with `intersectAsync`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(async)/lazyAsync/index.mdx b/website/src/routes/api/(async)/lazyAsync/index.mdx index e980b1dd9..0005c6aa6 100644 --- a/website/src/routes/api/(async)/lazyAsync/index.mdx +++ b/website/src/routes/api/(async)/lazyAsync/index.mdx @@ -208,6 +208,7 @@ The following APIs can be combined with `lazyAsync`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(async)/pipeAsync/index.mdx b/website/src/routes/api/(async)/pipeAsync/index.mdx index f484f3fed..a1c634747 100644 --- a/website/src/routes/api/(async)/pipeAsync/index.mdx +++ b/website/src/routes/api/(async)/pipeAsync/index.mdx @@ -212,6 +212,7 @@ The following APIs can be combined with `pipeAsync`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(async)/unionAsync/index.mdx b/website/src/routes/api/(async)/unionAsync/index.mdx index 3ceacb5de..53e822d1b 100644 --- a/website/src/routes/api/(async)/unionAsync/index.mdx +++ b/website/src/routes/api/(async)/unionAsync/index.mdx @@ -169,6 +169,7 @@ The following APIs can be combined with `unionAsync`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(methods)/config/index.mdx b/website/src/routes/api/(methods)/config/index.mdx index c19a1cf0f..f8b31aa70 100644 --- a/website/src/routes/api/(methods)/config/index.mdx +++ b/website/src/routes/api/(methods)/config/index.mdx @@ -4,6 +4,7 @@ description: Changes the local configuration of a schema. source: /methods/config/config.ts contributors: - fabian-hiller + - EltonLobo07 --- import { ApiList, Property } from '~/components'; @@ -190,6 +191,7 @@ The following APIs can be combined with `config`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(methods)/fallback/index.mdx b/website/src/routes/api/(methods)/fallback/index.mdx index 65340e36b..f566eb12d 100644 --- a/website/src/routes/api/(methods)/fallback/index.mdx +++ b/website/src/routes/api/(methods)/fallback/index.mdx @@ -7,6 +7,7 @@ contributors: - morinokami - sqmasep - FlorianDevPhynix + - EltonLobo07 --- import { Link } from '@builder.io/qwik-city'; @@ -189,6 +190,7 @@ The following APIs can be combined with `fallback`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(methods)/pipe/index.mdx b/website/src/routes/api/(methods)/pipe/index.mdx index 48e675999..403950ff7 100644 --- a/website/src/routes/api/(methods)/pipe/index.mdx +++ b/website/src/routes/api/(methods)/pipe/index.mdx @@ -7,6 +7,7 @@ contributors: - fabian-hiller - morinokami - jasperteo + - EltonLobo07 --- import { Link } from '@builder.io/qwik-city'; @@ -193,6 +194,7 @@ The following APIs can be combined with `pipe`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(schemas)/any/index.mdx b/website/src/routes/api/(schemas)/any/index.mdx index 780c16955..96fb4c49c 100644 --- a/website/src/routes/api/(schemas)/any/index.mdx +++ b/website/src/routes/api/(schemas)/any/index.mdx @@ -6,6 +6,7 @@ contributors: - fabian-hiller - morinokami - jasperteo + - EltonLobo07 --- import { Link } from '@builder.io/qwik-city'; @@ -122,6 +123,7 @@ The following APIs can be combined with `any`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(schemas)/bigint/index.mdx b/website/src/routes/api/(schemas)/bigint/index.mdx index a5087eab5..67bbb28f8 100644 --- a/website/src/routes/api/(schemas)/bigint/index.mdx +++ b/website/src/routes/api/(schemas)/bigint/index.mdx @@ -4,6 +4,7 @@ description: Creates a bigint schema. source: /schemas/bigint/bigint.ts contributors: - fabian-hiller + - EltonLobo07 --- import { ApiList, Property } from '~/components'; @@ -114,6 +115,7 @@ The following APIs can be combined with `bigint`. 'check', 'brand', 'description', + 'ltValue', 'maxValue', 'metadata', 'minValue', diff --git a/website/src/routes/api/(schemas)/boolean/index.mdx b/website/src/routes/api/(schemas)/boolean/index.mdx index 5a3c7b0b3..8da4d3c8b 100644 --- a/website/src/routes/api/(schemas)/boolean/index.mdx +++ b/website/src/routes/api/(schemas)/boolean/index.mdx @@ -5,6 +5,7 @@ source: /schemas/boolean/boolean.ts contributors: - fabian-hiller - wout-junius + - EltonLobo07 --- import { Link } from '@builder.io/qwik-city'; @@ -110,6 +111,7 @@ The following APIs can be combined with `boolean`. 'check', 'brand', 'description', + 'ltValue', 'maxValue', 'maxWords', 'metadata', diff --git a/website/src/routes/api/(schemas)/custom/index.mdx b/website/src/routes/api/(schemas)/custom/index.mdx index d584c6d27..cee5a2ba0 100644 --- a/website/src/routes/api/(schemas)/custom/index.mdx +++ b/website/src/routes/api/(schemas)/custom/index.mdx @@ -5,6 +5,7 @@ source: /schemas/custom/custom.ts contributors: - fabian-hiller - morinokami + - EltonLobo07 --- import { ApiList, Property } from '~/components'; @@ -150,6 +151,7 @@ The following APIs can be combined with `custom`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(schemas)/date/index.mdx b/website/src/routes/api/(schemas)/date/index.mdx index 6f9497091..788fe21ce 100644 --- a/website/src/routes/api/(schemas)/date/index.mdx +++ b/website/src/routes/api/(schemas)/date/index.mdx @@ -5,6 +5,7 @@ source: /schemas/date/date.ts contributors: - fabian-hiller - wout-junius + - EltonLobo07 --- import { ApiList, Property } from '~/components'; @@ -119,6 +120,7 @@ The following APIs can be combined with `date`. 'check', 'brand', 'description', + 'ltValue', 'maxValue', 'metadata', 'minValue', diff --git a/website/src/routes/api/(schemas)/instance/index.mdx b/website/src/routes/api/(schemas)/instance/index.mdx index 8b3e2f17f..1d1b7033d 100644 --- a/website/src/routes/api/(schemas)/instance/index.mdx +++ b/website/src/routes/api/(schemas)/instance/index.mdx @@ -4,6 +4,7 @@ description: Creates an instance schema. source: /schemas/instance/instance.ts contributors: - fabian-hiller + - EltonLobo07 --- import { ApiList, Property } from '~/components'; @@ -120,6 +121,7 @@ The following APIs can be combined with `instance`. 'check', 'brand', 'description', + 'ltValue', 'maxSize', 'maxValue', 'metadata', diff --git a/website/src/routes/api/(schemas)/intersect/index.mdx b/website/src/routes/api/(schemas)/intersect/index.mdx index 19dbc4a42..4a2cc6e73 100644 --- a/website/src/routes/api/(schemas)/intersect/index.mdx +++ b/website/src/routes/api/(schemas)/intersect/index.mdx @@ -173,6 +173,7 @@ The following APIs can be combined with `intersect`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(schemas)/lazy/index.mdx b/website/src/routes/api/(schemas)/lazy/index.mdx index 3960bc8f2..de1523ecd 100644 --- a/website/src/routes/api/(schemas)/lazy/index.mdx +++ b/website/src/routes/api/(schemas)/lazy/index.mdx @@ -236,6 +236,7 @@ The following APIs can be combined with `lazy`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(schemas)/number/index.mdx b/website/src/routes/api/(schemas)/number/index.mdx index d12a97629..d13d590c8 100644 --- a/website/src/routes/api/(schemas)/number/index.mdx +++ b/website/src/routes/api/(schemas)/number/index.mdx @@ -4,6 +4,7 @@ source: /schemas/number/number.ts contributors: - fabian-hiller - kazizi55 + - EltonLobo07 --- import { ApiList, Property } from '~/components'; @@ -124,6 +125,7 @@ The following APIs can be combined with `number`. 'description', 'finite', 'integer', + 'ltValue', 'maxValue', 'metadata', 'minValue', diff --git a/website/src/routes/api/(schemas)/string/index.mdx b/website/src/routes/api/(schemas)/string/index.mdx index 49de9bfa3..f4faed1a0 100644 --- a/website/src/routes/api/(schemas)/string/index.mdx +++ b/website/src/routes/api/(schemas)/string/index.mdx @@ -7,6 +7,7 @@ contributors: - morinokami - jasperteo - kazizi55 + - EltonLobo07 --- import { ApiList, Property } from '~/components'; @@ -168,6 +169,7 @@ The following APIs can be combined with `string`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(schemas)/union/index.mdx b/website/src/routes/api/(schemas)/union/index.mdx index 8b8a0d97b..9c8dfb47e 100644 --- a/website/src/routes/api/(schemas)/union/index.mdx +++ b/website/src/routes/api/(schemas)/union/index.mdx @@ -6,6 +6,7 @@ contributors: - fabian-hiller - morinokami - thundermiracle + - EltonLobo07 --- import { Link } from '@builder.io/qwik-city'; @@ -189,6 +190,7 @@ The following APIs can be combined with `union`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(schemas)/unknown/index.mdx b/website/src/routes/api/(schemas)/unknown/index.mdx index 7ae9bc982..3fd23b3eb 100644 --- a/website/src/routes/api/(schemas)/unknown/index.mdx +++ b/website/src/routes/api/(schemas)/unknown/index.mdx @@ -7,6 +7,7 @@ contributors: - morinokami - mwskwong - jasperteo + - EltonLobo07 --- import { ApiList, Property } from '~/components'; @@ -122,6 +123,7 @@ The following APIs can be combined with `unknown`. 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/api/(types)/LtValueAction/index.mdx b/website/src/routes/api/(types)/LtValueAction/index.mdx new file mode 100644 index 000000000..20f5518ae --- /dev/null +++ b/website/src/routes/api/(types)/LtValueAction/index.mdx @@ -0,0 +1,28 @@ +--- +title: LtValueAction +description: Less than value action type. +contributors: + - EltonLobo07 +--- + +import { Property } from '~/components'; +import { properties } from './properties'; + +# LtValueAction + +Less than value action type. + +## Generics + +- `TInput` +- `TRequirement` +- `TMessage` + +## Definition + +- `LtValueAction` + - `type` + - `reference` + - `expects` + - `requirement` + - `message` diff --git a/website/src/routes/api/(types)/LtValueAction/properties.ts b/website/src/routes/api/(types)/LtValueAction/properties.ts new file mode 100644 index 000000000..56975b6ba --- /dev/null +++ b/website/src/routes/api/(types)/LtValueAction/properties.ts @@ -0,0 +1,121 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TInput: { + modifier: 'extends', + type: { + type: 'custom', + name: 'ValueInput', + href: '../ValueInput/', + }, + }, + TRequirement: { + modifier: 'extends', + type: { + type: 'custom', + name: 'TInput', + }, + }, + TMessage: { + modifier: 'extends', + type: { + type: 'union', + options: [ + { + type: 'custom', + name: 'ErrorMessage', + href: '../ErrorMessage/', + generics: [ + { + type: 'custom', + name: 'LtValueIssue', + href: '../LtValueIssue/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'TRequirement', + }, + ], + }, + ], + }, + 'undefined', + ], + }, + }, + BaseValidation: { + modifier: 'extends', + type: { + type: 'custom', + name: 'BaseValidation', + href: '../BaseValidation/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'LtValueIssue', + href: '../LtValueIssue/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'TRequirement', + }, + ], + }, + ], + }, + }, + type: { + type: { + type: 'string', + value: 'lt_value', + }, + }, + reference: { + type: { + type: 'custom', + modifier: 'typeof', + name: 'ltValue', + href: '../ltValue/', + }, + }, + expects: { + type: { + type: 'template', + parts: [ + { + type: 'string', + value: '<', + }, + 'string', + ], + }, + }, + requirement: { + type: { + type: 'custom', + name: 'TRequirement', + }, + }, + message: { + type: { + type: 'custom', + name: 'TMessage', + }, + }, +}; diff --git a/website/src/routes/api/(types)/LtValueIssue/index.mdx b/website/src/routes/api/(types)/LtValueIssue/index.mdx new file mode 100644 index 000000000..dca8f4629 --- /dev/null +++ b/website/src/routes/api/(types)/LtValueIssue/index.mdx @@ -0,0 +1,26 @@ +--- +title: LtValueIssue +description: Less than value issue type. +contributors: + - EltonLobo07 +--- + +import { Property } from '~/components'; +import { properties } from './properties'; + +# LtValueIssue + +Less than value issue type. + +## Generics + +- `TInput` +- `TRequirement` + +## Definition + +- `LtValueIssue` + - `kind` + - `type` + - `expected` + - `requirement` diff --git a/website/src/routes/api/(types)/LtValueIssue/properties.ts b/website/src/routes/api/(types)/LtValueIssue/properties.ts new file mode 100644 index 000000000..f5c7fa1e0 --- /dev/null +++ b/website/src/routes/api/(types)/LtValueIssue/properties.ts @@ -0,0 +1,63 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TInput: { + modifier: 'extends', + type: { + type: 'custom', + name: 'ValueInput', + href: '../ValueInput/', + }, + }, + TRequirement: { + modifier: 'extends', + type: { + type: 'custom', + name: 'TInput', + }, + }, + BaseIssue: { + modifier: 'extends', + type: { + type: 'custom', + name: 'BaseIssue', + href: '../BaseIssue/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + ], + }, + }, + kind: { + type: { + type: 'string', + value: 'validation', + }, + }, + type: { + type: { + type: 'string', + value: 'lt_value', + }, + }, + expected: { + type: { + type: 'template', + parts: [ + { + type: 'string', + value: '<', + }, + 'string', + ], + }, + }, + requirement: { + type: { + type: 'custom', + name: 'TRequirement', + }, + }, +}; diff --git a/website/src/routes/api/menu.md b/website/src/routes/api/menu.md index fa8096268..7fb782b47 100644 --- a/website/src/routes/api/menu.md +++ b/website/src/routes/api/menu.md @@ -113,6 +113,7 @@ - [isoTimestamp](/api/isoTimestamp/) - [isoWeek](/api/isoWeek/) - [length](/api/length/) +- [ltValue](/api/ltValue) - [mac](/api/mac/) - [mac48](/api/mac48/) - [mac64](/api/mac64/) @@ -441,6 +442,8 @@ - [LooseTupleSchema](/api/LooseTupleSchema/) - [LooseTupleSchemaAsync](/api/LooseTupleSchemaAsync/) - [LiteralSchema](/api/LiteralSchema/) +- [LtValueAction](/api/LtValueAction/) +- [LtValueIssue](/api/LtValueIssue/) - [Mac48Action](/api/Mac48Action/) - [Mac48Issue](/api/Mac48Issue/) - [Mac64Action](/api/Mac64Action/) diff --git a/website/src/routes/guides/(main-concepts)/pipelines/index.mdx b/website/src/routes/guides/(main-concepts)/pipelines/index.mdx index d148a163e..e397cdca2 100644 --- a/website/src/routes/guides/(main-concepts)/pipelines/index.mdx +++ b/website/src/routes/guides/(main-concepts)/pipelines/index.mdx @@ -80,6 +80,7 @@ Pipeline validation actions examine the input and, if the input does not meet a 'isoTimestamp', 'isoWeek', 'length', + 'ltValue', 'mac', 'mac48', 'mac64', diff --git a/website/src/routes/guides/(migration)/migrate-from-zod/index.mdx b/website/src/routes/guides/(migration)/migrate-from-zod/index.mdx index 74d098346..b3c0d6d6f 100644 --- a/website/src/routes/guides/(migration)/migrate-from-zod/index.mdx +++ b/website/src/routes/guides/(migration)/migrate-from-zod/index.mdx @@ -77,7 +77,8 @@ Most of the names are the same as in Zod. However, there are some exceptions. Th | `input` | `InferInput` | | `instanceof` | `instance` | | `intersection` | `intersect` | -| `lt`, `lte` | `maxValue` | +| `lt` | `ltValue` | +| `lte` | `maxValue` | | `max` | `maxLength`, `maxSize`, `maxValue` | | `min` | `minLength`, `minSize`, `minValue` | | `nativeEnum` | `enum` |