typebox 1.0.30 → 1.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  import { type TUnreachable } from '../../../system/unreachable/index.mjs';
2
2
  import { type TSchema } from '../../types/schema.mjs';
3
3
  import { type TProperties } from '../../types/properties.mjs';
4
- import { type TEvaluateIntersect } from '../evaluate/evaluate.mjs';
4
+ import { type TEvaluateUnion } from '../evaluate/evaluate.mjs';
5
5
  import { type TFromType } from './from-type.mjs';
6
6
  type TCollapseUnionProperties<Left extends TProperties, Right extends TProperties, SharedKeys extends PropertyKey = keyof Left & keyof Right, Result extends TProperties = {
7
- [Key in SharedKeys]: TEvaluateIntersect<[Left[Key], Right[Key]]>;
7
+ [Key in SharedKeys]: TEvaluateUnion<[Left[Key], Right[Key]]>;
8
8
  }> = Result;
9
9
  type TReduceVariants<Types extends TSchema[], Result extends TProperties> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TReduceVariants<Right, TCollapseUnionProperties<Result, TFromType<Left>>> : Result);
10
10
  export type TFromUnion<Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TReduceVariants<Right, TFromType<Left>> : TUnreachable);
@@ -2,12 +2,12 @@
2
2
  import { Unreachable } from '../../../system/unreachable/index.mjs';
3
3
  import { Guard } from '../../../guard/index.mjs';
4
4
  import { IsSchema } from '../../types/schema.mjs';
5
- import { EvaluateIntersect } from '../evaluate/evaluate.mjs';
5
+ import { EvaluateUnion } from '../evaluate/evaluate.mjs';
6
6
  import { FromType } from './from-type.mjs';
7
7
  function CollapseUnionProperties(left, right) {
8
8
  const sharedKeys = Guard.Keys(left).filter((key) => key in right);
9
9
  const result = sharedKeys.reduce((result, key) => {
10
- return { ...result, [key]: EvaluateIntersect([left[key], right[key]]) };
10
+ return { ...result, [key]: EvaluateUnion([left[key], right[key]]) };
11
11
  }, {});
12
12
  return result;
13
13
  }
@@ -0,0 +1,2 @@
1
+ import type { TProperties, Base } from '../../type/index.mjs';
2
+ export declare function FromBase(context: TProperties, type: Base, value: unknown): unknown;
@@ -0,0 +1,8 @@
1
+ // deno-fmt-ignore-file
2
+ import { FromUnknown } from './from-unknown.mjs';
3
+ // ------------------------------------------------------------------
4
+ // FromBase
5
+ // ------------------------------------------------------------------
6
+ export function FromBase(context, type, value) {
7
+ return FromUnknown(context, type, value);
8
+ }
@@ -2,6 +2,7 @@
2
2
  import { Guard, GlobalsGuard } from '../../guard/index.mjs';
3
3
  import * as T from '../../type/index.mjs';
4
4
  import { FromArray } from './from-array.mjs';
5
+ import { FromBase } from './from-base.mjs';
5
6
  import { FromEnum } from './from-enum.mjs';
6
7
  import { FromIntersect } from './from-intersect.mjs';
7
8
  import { FromObject } from './from-object.mjs';
@@ -44,6 +45,10 @@ function AssertRepairableType(context, type, value) {
44
45
  // FromType
45
46
  // ------------------------------------------------------------------
46
47
  export function FromType(context, type, value) {
48
+ // Intercept Base
49
+ if (T.IsBase(type))
50
+ return FromBase(context, type, value);
51
+ // Standard Repair
47
52
  AssertRepairableValue(context, type, value);
48
53
  AssertRepairableType(context, type, value);
49
54
  return (T.IsArray(type) ? FromArray(context, type, value) :
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
3
  "description": "A Runtime Type System for JavaScript",
4
- "version": "1.0.30",
4
+ "version": "1.0.32",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"