Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit abcfef0

Browse files
committed
Merge branch 'develop' into next
2 parents 81aa868 + 233d206 commit abcfef0

5 files changed

Lines changed: 182 additions & 17 deletions

File tree

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"name": "@adonisjs/validator",
3-
"version": "13.0.2-3",
43
"description": "Validator for adonis framework",
4+
"version": "13.0.2-3",
5+
"engines": {
6+
"node": ">=18.16.0"
7+
},
58
"main": "build/index.js",
69
"type": "module",
710
"files": [
@@ -14,9 +17,6 @@
1417
"./validator_provider": "./build/providers/validator_provider.js",
1518
"./types": "./build/src/types.js"
1619
},
17-
"engines": {
18-
"node": ">=18.16.0"
19-
},
2020
"scripts": {
2121
"pretest": "npm run lint",
2222
"test": "c8 npm run quick:test",
@@ -75,22 +75,26 @@
7575
"peerDependencies": {
7676
"@adonisjs/core": "^6.2.0"
7777
},
78-
"keywords": [
79-
"validator",
80-
"schema-validation",
81-
"adonisjs",
82-
"adonisjs-validator"
83-
],
84-
"license": "MIT",
8578
"author": "virk,adonisjs",
79+
"license": "MIT",
80+
"homepage": "https://github.com/adonisjs/validator#readme",
8681
"repository": {
8782
"type": "git",
8883
"url": "git+https://github.com/adonisjs/validator.git"
8984
},
9085
"bugs": {
9186
"url": "https://github.com/adonisjs/validator/issues"
9287
},
93-
"homepage": "https://github.com/adonisjs/validator#readme",
88+
"keywords": [
89+
"validator",
90+
"schema-validation",
91+
"adonisjs",
92+
"adonisjs-validator"
93+
],
94+
"eslintConfig": {
95+
"extends": "@adonisjs/eslint-config/package"
96+
},
97+
"prettier": "@adonisjs/prettier-config",
9498
"commitlint": {
9599
"extends": [
96100
"@commitlint/config-conventional"
@@ -116,9 +120,5 @@
116120
"test_factories/**",
117121
".yalc/**"
118122
]
119-
},
120-
"eslintConfig": {
121-
"extends": "@adonisjs/eslint-config/package"
122-
},
123-
"prettier": "@adonisjs/prettier-config"
123+
}
124124
}

src/schema/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@ number.nullableAndOptional = function nullableAndOptionalNumber(rules?: Rule[])
118118
>
119119
}
120120

121+
/**
122+
* bigint schema type
123+
*/
124+
function bigint(rules?: Rule[]) {
125+
return getLiteralType('bigint', false, false, undefined, rules || []) as ReturnType<BigIntType>
126+
}
127+
bigint.optional = function optionalBigInt(rules?: Rule[]) {
128+
return getLiteralType('bigint', true, false, undefined, rules || []) as ReturnType<
129+
BigIntType['optional']
130+
>
131+
}
132+
bigint.nullable = function nullableBigInt(rules?: Rule[]) {
133+
return getLiteralType('bigint', false, true, undefined, rules || []) as ReturnType<
134+
BigIntType['nullable']
135+
>
136+
}
137+
bigint.nullableAndOptional = function nullableAndOptionalBigInt(rules?: Rule[]) {
138+
return getLiteralType('bigint', true, true, undefined, rules || []) as ReturnType<
139+
BigIntType['nullableAndOptional']
140+
>
141+
}
142+
121143
/**
122144
* Date schema type
123145
*/
@@ -385,6 +407,7 @@ export const schema: Schema = {
385407
string,
386408
boolean,
387409
number,
410+
bigint,
388411
date,
389412
object,
390413
array,

src/validations/primitives/number.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ export const number: SyncValidation = {
4747
return
4848
}
4949

50+
if (castedValue === Infinity || castedValue === -Infinity) {
51+
errorReporter.report(pointer, RULE_NAME, DEFAULT_MESSAGE, arrayExpressionPointer)
52+
return
53+
}
54+
5055
/**
5156
* Mutate the value
5257
*/

tests/schema.spec.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,116 @@ test.group('Schema | Number', () => {
475475
})
476476
})
477477

478+
test.group('Schema | BigInt', () => {
479+
test('define schema with bigint rule', ({ assert }) => {
480+
assert.deepEqual(
481+
schema.create({
482+
username: schema.bigint(),
483+
}).tree,
484+
{
485+
username: {
486+
type: 'literal',
487+
subtype: 'bigint',
488+
optional: false,
489+
nullable: false,
490+
rules: [
491+
{
492+
name: 'required',
493+
allowUndefineds: true,
494+
async: false,
495+
compiledOptions: [],
496+
},
497+
{
498+
name: 'bigint',
499+
allowUndefineds: false,
500+
async: false,
501+
compiledOptions: [],
502+
},
503+
],
504+
},
505+
}
506+
)
507+
})
508+
509+
test('define schema with optional bigint rule', ({ assert }) => {
510+
assert.deepEqual(
511+
schema.create({
512+
username: schema.bigint.optional(),
513+
}).tree,
514+
{
515+
username: {
516+
type: 'literal',
517+
subtype: 'bigint',
518+
optional: true,
519+
nullable: false,
520+
rules: [
521+
{
522+
name: 'bigint',
523+
allowUndefineds: false,
524+
async: false,
525+
compiledOptions: [],
526+
},
527+
],
528+
},
529+
}
530+
)
531+
})
532+
533+
test('define schema with nullable bigint rule', ({ assert }) => {
534+
assert.deepEqual(
535+
schema.create({
536+
username: schema.bigint.nullable(),
537+
}).tree,
538+
{
539+
username: {
540+
type: 'literal',
541+
subtype: 'bigint',
542+
optional: false,
543+
nullable: true,
544+
rules: [
545+
{
546+
name: 'nullable',
547+
allowUndefineds: true,
548+
async: false,
549+
compiledOptions: [],
550+
},
551+
{
552+
name: 'bigint',
553+
allowUndefineds: false,
554+
async: false,
555+
compiledOptions: [],
556+
},
557+
],
558+
},
559+
}
560+
)
561+
})
562+
563+
test('define schema with both optional and nullable bigint rule', ({ assert }) => {
564+
assert.deepEqual(
565+
schema.create({
566+
username: schema.bigint.nullableAndOptional(),
567+
}).tree,
568+
{
569+
username: {
570+
type: 'literal',
571+
subtype: 'bigint',
572+
optional: true,
573+
nullable: true,
574+
rules: [
575+
{
576+
name: 'bigint',
577+
allowUndefineds: false,
578+
async: false,
579+
compiledOptions: [],
580+
},
581+
],
582+
},
583+
}
584+
)
585+
})
586+
})
587+
478588
test.group('Schema | Date', () => {
479589
test('define schema with date rule', ({ assert }) => {
480590
assert.deepEqual(

tests/validations/number.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,33 @@ function compile() {
2121
test.group('Number', () => {
2222
validate(number, test, 'helloworld', 10, compile())
2323

24+
test('report error when value is near Infinity', ({ assert }) => {
25+
const reporter = new ApiErrorReporter(new MessagesBag({}), false)
26+
number.validate(
27+
'-3177777777777777777777777777777777777777777777777777777777777777777777777770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999991111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',
28+
compile().compiledOptions,
29+
{
30+
errorReporter: reporter,
31+
field: 'age',
32+
pointer: 'age',
33+
tip: {},
34+
root: {},
35+
refs: {},
36+
mutate: () => {},
37+
}
38+
)
39+
40+
assert.deepEqual(reporter.toJSON(), {
41+
errors: [
42+
{
43+
field: 'age',
44+
rule: 'number',
45+
message: 'number validation failed',
46+
},
47+
],
48+
})
49+
})
50+
2451
test('report error when value is not a valid number', ({ assert }) => {
2552
const reporter = new ApiErrorReporter(new MessagesBag({}), false)
2653
number.validate(null, compile().compiledOptions, {

0 commit comments

Comments
 (0)