Skip to content

Commit dba0de3

Browse files
authored
Version 1.0.42 (#1418)
* Update Pointer, Add RecursiveRef, RecursiveAnchor, Fix Ref * ChangeLog * Version
1 parent 684be28 commit dba0de3

37 files changed

Lines changed: 889 additions & 540 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Install Deno
1515
uses: denoland/setup-deno@v2
1616
with:
17-
deno-version: canary
17+
deno-version: 2.5.4
1818
# Build
1919
- name: Test Library
2020
run: deno task test

changelog/1.0.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
---
44

55
### Version Updates
6+
- [Revision 1.0.42](https://github.com/sinclairzx81/typebox/pull/1418)
7+
- Add RecursiveRef, RecursiveAnchor Guards
8+
- Revise Json Pointer Module
9+
- Support Ref / Anchor for Draft 7
610
- [Revision 1.0.41](https://github.com/sinclairzx81/typebox/pull/1416)
711
- Support Sub Schema Value Recovery on Repair
812
- [Revision 1.0.40](https://github.com/sinclairzx81/typebox/pull/1415)

design/website/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<meta property="og:type" content="https://sinclairzx81.github.io/typebox">
1111
<title>TypeBox</title>
1212
<link rel="icon" href="resources/image/favicon.ico" type="image/x-icon">
13-
<link href="index.css" rel="stylesheet"></link>
13+
<link href="index.css" rel="stylesheet">
1414
<script type="module" src="index.js"></script>
1515
<script async src="https://www.googletagmanager.com/gtag/js?id=G-EYTCZ4PD6T"></script>
1616
<script>

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<meta property="og:type" content="https://sinclairzx81.github.io/typebox">
1111
<title>TypeBox</title>
1212
<link rel="icon" href="resources/image/favicon.ico" type="image/x-icon">
13-
<link href="index.css" rel="stylesheet"></link>
13+
<link href="index.css" rel="stylesheet">
1414
<script type="module" src="index.js"></script>
1515
<script async src="https://www.googletagmanager.com/gtag/js?id=G-EYTCZ4PD6T"></script>
1616
<script>

src/guard/emit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function Constant(value: bigint | boolean | null | number | string | unde
183183
return G.IsString(value) ? JSON.stringify(value) : `${value}`
184184
}
185185
export function Ternary(condition: string, true_: string, false_: string): string {
186-
return `${condition} ? ${true_} : ${false_}`
186+
return `(${condition} ? ${true_} : ${false_})`
187187
}
188188
// ------------------------------------------------------------------
189189
// Statements

src/schema/deref/deref.ts

Lines changed: 0 additions & 108 deletions
This file was deleted.

src/schema/engine/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export * from './patternProperties.ts'
7070
export * from './prefixItems.ts'
7171
export * from './properties.ts'
7272
export * from './propertyNames.ts'
73+
export * from './recursiveRef.ts'
7374
export * from './ref.ts'
7475
export * from './required.ts'
7576
export * from './type.ts'

src/schema/engine/recursiveRef.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*--------------------------------------------------------------------------
2+
3+
TypeBox
4+
5+
The MIT License (MIT)
6+
7+
Copyright (c) 2017-2025 Haydn Paterson
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in
17+
all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
26+
27+
---------------------------------------------------------------------------*/
28+
29+
// deno-fmt-ignore-file
30+
31+
import * as F from './_functions.ts'
32+
import * as S from '../types/index.ts'
33+
import { BaseContext, BuildContext, CheckContext, ErrorContext } from './_context.ts'
34+
import { CheckSchema, ErrorSchema } from './schema.ts'
35+
import { Resolver } from '../resolver/index.ts'
36+
37+
// ------------------------------------------------------------------
38+
// Resolve
39+
// ------------------------------------------------------------------
40+
function Resolve(context: BaseContext, schema: S.XRecursiveRef): S.XSchema {
41+
// note: it is safe to coerce to XSchema here as it wouldn't be possible
42+
// to enter a ref resolution if the root schema was boolean.
43+
const schemaRoot = context.GetSchema() as S.XSchemaObject
44+
const dereferenced = Resolver.RecursiveRef(schemaRoot, schema)
45+
return S.IsSchema(dereferenced) ? dereferenced : false
46+
}
47+
// ------------------------------------------------------------------
48+
// Build
49+
// ------------------------------------------------------------------
50+
export function BuildRecursiveRef(context: BuildContext, schema: S.XRecursiveRef, value: string): string {
51+
const target = Resolve(context, schema)
52+
return F.CreateFunction(context, target, value)
53+
}
54+
// ------------------------------------------------------------------
55+
// Check
56+
// ------------------------------------------------------------------
57+
export function CheckRecursiveRef(context: CheckContext, schema: S.XRecursiveRef, value: unknown): boolean {
58+
const target = Resolve(context, schema)
59+
return (S.IsSchema(target) && CheckSchema(context, target, value))
60+
}
61+
// ------------------------------------------------------------------
62+
// Error
63+
// ------------------------------------------------------------------
64+
export function ErrorRecursiveRef(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XRecursiveRef, value: unknown): boolean {
65+
const target = Resolve(context, schema)
66+
return (S.IsSchema(target) && ErrorSchema(context, '#', instancePath, target, value))
67+
}

src/schema/engine/ref.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import * as S from '../types/index.ts'
3333
import { Guard as G } from '../../guard/index.ts'
3434
import { BaseContext, BuildContext, CheckContext, ErrorContext } from './_context.ts'
3535
import { CheckSchema, ErrorSchema } from './schema.ts'
36-
import { Deref } from '../deref/index.ts'
36+
import { Resolver } from '../resolver/index.ts'
3737

3838
// ------------------------------------------------------------------
3939
// Resolve
@@ -47,8 +47,8 @@ function Resolve(context: BaseContext, schema: S.XRef): S.XSchema {
4747
if (G.HasPropertyKey(schemaContext, schema.$ref)) {
4848
return schemaContext[schema.$ref]
4949
}
50-
// inline referential schema
51-
const dereferenced = Deref(schemaRoot, { $ref: schema.$ref })
50+
// referential schema
51+
const dereferenced = Resolver.Ref(schemaRoot, schema.$ref)
5252
return S.IsSchema(dereferenced) ? dereferenced : false
5353
}
5454
// ------------------------------------------------------------------

src/schema/engine/schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import { BuildPatternProperties, CheckPatternProperties, ErrorPatternProperties
6969
import { BuildPrefixItems, CheckPrefixItems, ErrorPrefixItems } from './prefixItems.ts'
7070
import { BuildProperties, CheckProperties, ErrorProperties } from './properties.ts'
7171
import { BuildPropertyNames, CheckPropertyNames, ErrorPropertyNames } from './propertyNames.ts'
72+
import { BuildRecursiveRef, CheckRecursiveRef, ErrorRecursiveRef } from './recursiveRef.ts'
7273
import { BuildRef, CheckRef, ErrorRef } from './ref.ts'
7374
import { BuildRequired, CheckRequired, ErrorRequired } from './required.ts'
7475
import { BuildType, CheckType, ErrorType } from './type.ts'
@@ -213,6 +214,7 @@ export function BuildSchema(context: BuildContext, schema: S.XSchema, value: str
213214
const guarded = E.Or(E.Not(E.Or(E.IsNumber(value), E.IsBigInt(value))), reduced)
214215
conditions.push(HasNumberType(schema) ? reduced : guarded)
215216
}
217+
if (S.IsRecursiveRef(schema)) conditions.push(BuildRecursiveRef(context, schema, value))
216218
if (S.IsRef(schema)) conditions.push(BuildRef(context, schema, value))
217219
if (S.IsGuard(schema)) conditions.push(BuildGuard(context, schema, value))
218220
if (S.IsConst(schema)) conditions.push(BuildConst(context, schema, value))
@@ -269,6 +271,7 @@ export function CheckSchema(context: CheckContext, schema: S.XSchema, value: unk
269271
(!S.IsMinimum(schema) || CheckMinimum(context, schema, value)) &&
270272
(!S.IsMultipleOf(schema) || CheckMultipleOf(context, schema, value))
271273
)) &&
274+
(!S.IsRecursiveRef(schema) || CheckRecursiveRef(context, schema, value)) &&
272275
(!S.IsRef(schema) || CheckRef(context, schema, value)) &&
273276
(!S.IsGuard(schema) || CheckGuard(context, schema, value)) &&
274277
(!S.IsConst(schema) || CheckConst(context, schema, value)) &&
@@ -326,6 +329,7 @@ export function ErrorSchema(context: ErrorContext, schemaPath: string, instanceP
326329
+(!S.IsMinimum(schema) || ErrorMinimum(context, schemaPath, instancePath, schema, value)) &
327330
+(!S.IsMultipleOf(schema) || ErrorMultipleOf(context, schemaPath, instancePath, schema, value))
328331
)) &
332+
+(!S.IsRecursiveRef(schema) || ErrorRecursiveRef(context, schemaPath, instancePath, schema, value)) &
329333
+(!S.IsRef(schema) || ErrorRef(context, schemaPath, instancePath, schema, value)) &
330334
+(!S.IsGuard(schema) || ErrorGuard(context, schemaPath, instancePath, schema, value)) &
331335
+(!S.IsConst(schema) || ErrorConst(context, schemaPath, instancePath, schema, value)) &

0 commit comments

Comments
 (0)