Skip to content

Commit 01355c5

Browse files
authored
Version 1.0.81 (#1527)
* Instantitate Intersect in Value * ChangeLog * Version
1 parent b1ee3a6 commit 01355c5

8 files changed

Lines changed: 58 additions & 15 deletions

File tree

changelog/1.0.0.md

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

55
### Version Updates
6+
- [Revision 1.0.81](https://github.com/sinclairzx81/typebox/pull/1527)
7+
- Instantiate Intersect with Context in Value Operations
68
- [Revision 1.0.80](https://github.com/sinclairzx81/typebox/pull/1524)
79
- Retain Ref Options on Instantiate
810
- [Revision 1.0.79](https://github.com/sinclairzx81/typebox/pull/1518)

src/value/clean/from-intersect.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@ THE SOFTWARE.
2828

2929
// deno-fmt-ignore-file
3030

31-
import { type TProperties, type TSchema, type TIntersect, Evaluate, IsObject, Options } from '../../type/index.ts'
31+
import { type TProperties, type TSchema, type TIntersect, Evaluate, Instantiate, IsObject, Options } from '../../type/index.ts'
3232
import { Guard } from '../../guard/index.ts'
3333
import { FromType } from './from-type.ts'
3434

3535
// ------------------------------------------------------------------
3636
// EvaluateIntersection
3737
// ------------------------------------------------------------------
38-
function EvaluateIntersection(type: TIntersect): TSchema {
38+
function EvaluateIntersection(context: TProperties, type: TIntersect): TSchema {
3939
// Note: reinterpret unevaluatedProperties as additionalProperties
4040
const additionalProperties =
4141
Guard.HasPropertyKey(type, 'unevaluatedProperties')
4242
? { additionalProperties: type.unevaluatedProperties }
4343
: {}
44-
const evaluated = Evaluate(type)
44+
const instantiated = Instantiate(context, type)
45+
const evaluated = Evaluate(instantiated)
4546
return IsObject(evaluated)
4647
? Options(evaluated, additionalProperties)
4748
: evaluated
@@ -51,7 +52,7 @@ function EvaluateIntersection(type: TIntersect): TSchema {
5152
// ------------------------------------------------------------------
5253
export function FromIntersect(context: TProperties, type: TIntersect, value: unknown): unknown {
5354
// Note: Evaluate and route back to FromType in evaluated form (likely an Object)
54-
const evaluated = EvaluateIntersection(type)
55+
const evaluated = EvaluateIntersection(context, type)
5556
return FromType(context, evaluated, value)
5657
}
5758

src/value/convert/from-intersect.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ THE SOFTWARE.
2828

2929
// deno-fmt-ignore-file
3030

31-
import { type TIntersect, type TProperties, Evaluate } from '../../type/index.ts'
31+
import { type TIntersect, type TProperties, Evaluate, Instantiate } from '../../type/index.ts'
3232
import { FromType } from './from-type.ts'
3333

3434
export function FromIntersect(context: TProperties, type: TIntersect, value: unknown): unknown {
35-
const evaluatedType = Evaluate(type)
36-
return FromType(context, evaluatedType, value)
35+
const instantiated = Instantiate(context, type)
36+
const evaluated = Evaluate(instantiated)
37+
return FromType(context, evaluated, value)
3738
}

src/value/create/from-intersect.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ THE SOFTWARE.
2828

2929
// deno-fmt-ignore-file
3030

31-
import { type TProperties, type TIntersect, Evaluate } from '../../type/index.ts'
31+
import { type TProperties, type TIntersect, Evaluate, Instantiate } from '../../type/index.ts'
3232
import { FromType } from './from-type.ts'
3333

3434
export function FromIntersect(context: TProperties, type: TIntersect): unknown {
35-
return FromType(context, Evaluate(type))
35+
const instantiated = Instantiate(context, type)
36+
const evaluated = Evaluate(instantiated)
37+
return FromType(context, evaluated)
3638
}

src/value/default/from-intersect.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ THE SOFTWARE.
2929
// deno-fmt-ignore-file
3030
// deno-lint-ignore-file
3131

32-
import { TProperties, TIntersect, Evaluate } from '../../type/index.ts'
32+
import { TProperties, TIntersect, Evaluate, Instantiate } from '../../type/index.ts'
3333
import { FromType } from './from-type.ts'
3434

3535
export function FromIntersect(context: TProperties, type: TIntersect, value: unknown): unknown {
36-
const evaluted = Evaluate(type)
37-
return FromType(context, evaluted, value)
36+
const instantiated = Instantiate(context, type)
37+
const evaluated = Evaluate(instantiated)
38+
return FromType(context, evaluated, value)
3839
}

src/value/repair/from-intersect.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ THE SOFTWARE.
2828

2929
// deno-fmt-ignore-file
3030

31-
import { type TProperties, type TIntersect, Evaluate } from '../../type/index.ts'
31+
import { type TProperties, type TIntersect, Instantiate, Evaluate } from '../../type/index.ts'
3232
import { FromType } from './from-type.ts'
3333

3434
export function FromIntersect(context: TProperties, type: TIntersect, value: unknown): unknown {
35-
const evaluated = Evaluate(type)
35+
const instantiated = Instantiate(context, type)
36+
const evaluated = Evaluate(instantiated)
3637
return FromType(context, evaluated, value)
3738
}

tasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Range } from './task/range/index.ts'
88
import { Metrics } from './task/metrics/index.ts'
99
import { Task } from 'tasksmith'
1010

11-
const Version = '1.0.80'
11+
const Version = '1.0.81'
1212

1313
// ------------------------------------------------------------------
1414
// Build
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Value } from 'typebox/value'
2+
import { Type } from 'typebox'
3+
import { Assert } from 'test'
4+
5+
const Test = Assert.Context('Value.Default.Module')
6+
7+
// ------------------------------------------------------------------
8+
// https://github.com/sinclairzx81/typebox/issues/1526
9+
// ------------------------------------------------------------------
10+
Test('Should Module 1', () => {
11+
const { Event } = Type.Module({
12+
base: Type.Object({
13+
id: Type.Optional(Type.String()),
14+
blocking: Type.Optional(Type.Boolean({ default: true }))
15+
}),
16+
Event: Type.Union([
17+
Type.Intersect([
18+
Type.Ref('base'),
19+
Type.Object({
20+
type: Type.Literal('audio'),
21+
src: Type.String()
22+
})
23+
]),
24+
Type.Intersect([
25+
Type.Ref('base'),
26+
Type.Object({
27+
type: Type.Literal('for'),
28+
do: Type.Ref('Event')
29+
})
30+
])
31+
])
32+
})
33+
const Result = Value.Default(Event, { type: 'audio', src: 'test.mp3' })
34+
Assert.IsEqual(Result, { type: 'audio', src: 'test.mp3', blocking: true })
35+
})

0 commit comments

Comments
 (0)