Revision 0.33.9 (#984)

* Generate Interior Intersect Errors

* Version

* ChangeLog
This commit is contained in:
sinclairzx81
2024-09-03 07:17:46 +09:00
committed by GitHub
parent ed4c89a9ab
commit d387b2adb7
5 changed files with 44 additions and 15 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
### 0.33.0
- [Revision 0.33.9](https://github.com/sinclairzx81/typebox/pull/984)
- [887](https://github.com/sinclairzx81/typebox/issues/887) Generate Nested Intersect Errors
- [Revision 0.33.8](https://github.com/sinclairzx81/typebox/pull/983)
- [982](https://github.com/sinclairzx81/typebox/issues/982) Prevent Intersect Transform Encode callback from being called twice
- [974](https://github.com/sinclairzx81/typebox/issues/974) Make strict the Encode and Decode return type
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "@sinclair/typebox",
"version": "0.33.8",
"version": "0.33.9",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@sinclair/typebox",
"version": "0.33.8",
"version": "0.33.9",
"license": "MIT",
"devDependencies": {
"@arethetypeswrong/cli": "^0.13.2",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@sinclair/typebox",
"version": "0.33.8",
"version": "0.33.9",
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
"keywords": [
"typescript",
+7 -4
View File
@@ -312,13 +312,16 @@ function* FromInteger(schema: TInteger, references: TSchema[], path: string, val
}
}
function* FromIntersect(schema: TIntersect, references: TSchema[], path: string, value: any): IterableIterator<ValueError> {
let hasError = false
for (const inner of schema.allOf) {
const next = Visit(inner, references, path, value).next()
if (!next.done) {
yield Create(ValueErrorType.Intersect, schema, path, value)
yield next.value
for (const error of Visit(inner, references, path, value)) {
hasError = true
yield error
}
}
if (hasError) {
return yield Create(ValueErrorType.Intersect, schema, path, value)
}
if (schema.unevaluatedProperties === false) {
const keyCheck = new RegExp(KeyOfPattern(schema))
for (const valueKey of Object.getOwnPropertyNames(value)) {
+32 -7
View File
@@ -4,21 +4,46 @@ import { Resolve } from './resolve'
import { Assert } from '../../assert'
describe('errors/type/Intersect', () => {
const T = Type.Intersect([Type.Object({ x: Type.Number() }), Type.Object({ y: Type.Number() })])
it('Should pass 0', () => {
const T = Type.Intersect([Type.Object({ x: Type.Number() }), Type.Object({ y: Type.Number() })])
const R = Resolve(T, { x: 1, y: 1 })
Assert.IsEqual(R.length, 0)
})
it('Should pass 1', () => {
const T = Type.Intersect([Type.Object({ x: Type.Number() }), Type.Object({ y: Type.Number() })])
const R = Resolve(T, { x: 1 })
Assert.IsEqual(R.length, 2)
Assert.IsEqual(R[0].type, ValueErrorType.Intersect)
Assert.IsEqual(R[1].type, ValueErrorType.ObjectRequiredProperty)
Assert.IsEqual(R.length, 3)
Assert.IsEqual(R[0].type, ValueErrorType.ObjectRequiredProperty)
Assert.IsEqual(R[1].type, ValueErrorType.Number)
Assert.IsEqual(R[2].type, ValueErrorType.Intersect)
})
it('Should pass 2', () => {
const T = Type.Intersect([Type.Object({ x: Type.Number() }), Type.Object({ y: Type.Number() })])
const R = Resolve(T, { y: 1 })
Assert.IsEqual(R.length, 2)
Assert.IsEqual(R[0].type, ValueErrorType.Intersect)
Assert.IsEqual(R[1].type, ValueErrorType.ObjectRequiredProperty)
Assert.IsEqual(R.length, 3)
Assert.IsEqual(R[0].type, ValueErrorType.ObjectRequiredProperty)
Assert.IsEqual(R[1].type, ValueErrorType.Number)
Assert.IsEqual(R[2].type, ValueErrorType.Intersect)
})
// ----------------------------------------------------------------
// https://github.com/sinclairzx81/typebox/issues/887
// ----------------------------------------------------------------
it('Should pass 3', () => {
const A = Type.Intersect([Type.Object({ x: Type.Number() }), Type.Object({ y: Type.Number() })])
const B = Type.Intersect([Type.Object({ x: Type.Number() }), Type.Object({ z: Type.Number() })])
const T = Type.Intersect([A, B])
const R = Resolve(T, {})
Assert.IsEqual(R.length, 11)
Assert.IsEqual(R[0].type, ValueErrorType.ObjectRequiredProperty)
Assert.IsEqual(R[1].type, ValueErrorType.Number)
Assert.IsEqual(R[2].type, ValueErrorType.ObjectRequiredProperty)
Assert.IsEqual(R[3].type, ValueErrorType.Number)
Assert.IsEqual(R[4].type, ValueErrorType.Intersect)
Assert.IsEqual(R[5].type, ValueErrorType.ObjectRequiredProperty)
Assert.IsEqual(R[6].type, ValueErrorType.Number)
Assert.IsEqual(R[7].type, ValueErrorType.ObjectRequiredProperty)
Assert.IsEqual(R[8].type, ValueErrorType.Number)
Assert.IsEqual(R[9].type, ValueErrorType.Intersect)
Assert.IsEqual(R[10].type, ValueErrorType.Intersect)
})
})