@depup/typebox 1.3.11-depup.0 → 1.3.14-depup.0
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.
- package/README.md +2 -2
- package/build/format/date.d.mts +1 -1
- package/build/format/date.mjs +1 -1
- package/build/format/date_time.d.mts +2 -2
- package/build/format/date_time.mjs +3 -3
- package/build/format/email.d.mts +1 -1
- package/build/format/email.mjs +2 -2
- package/build/format/hostname.mjs +2 -10
- package/build/format/idn_email.d.mts +1 -1
- package/build/format/idn_email.mjs +3 -3
- package/build/format/idn_hostname.d.mts +1 -0
- package/build/format/idn_hostname.mjs +3 -11
- package/build/format/idna/format/bidi.d.mts +3 -0
- package/build/format/idna/format/bidi.mjs +98 -0
- package/build/format/idna/format/puny.d.mts +3 -0
- package/build/format/idna/format/puny.mjs +144 -0
- package/build/format/idna/hostname.d.mts +1 -0
- package/build/format/idna/hostname.mjs +16 -0
- package/build/format/idna/idn-hostname.d.mts +1 -0
- package/build/format/idna/idn-hostname.mjs +23 -0
- package/build/format/idna/index.d.mts +2 -0
- package/build/format/idna/index.mjs +2 -0
- package/build/format/idna/label/ascii.d.mts +1 -0
- package/build/format/idna/label/ascii.mjs +9 -0
- package/build/format/idna/label/puny.d.mts +1 -0
- package/build/format/idna/label/puny.mjs +28 -0
- package/build/format/idna/label/unicode.d.mts +1 -0
- package/build/format/idna/label/unicode.mjs +106 -0
- package/build/format/idna/pattern/pattern.d.mts +30 -0
- package/build/format/idna/pattern/pattern.mjs +70 -0
- package/build/format/ipv4.d.mts +0 -1
- package/build/format/ipv4.mjs +2 -32
- package/build/format/ipv6.mjs +2 -61
- package/build/format/iri.d.mts +2 -2
- package/build/format/iri.mjs +26 -8
- package/build/format/iri_reference.d.mts +2 -2
- package/build/format/iri_reference.mjs +9 -55
- package/build/format/regex.d.mts +1 -2
- package/build/format/regex.mjs +2 -6
- package/build/format/time.d.mts +2 -2
- package/build/format/time.mjs +19 -14
- package/build/format/uri.d.mts +1 -1
- package/build/format/uri.mjs +3 -130
- package/build/format/uri_reference.d.mts +1 -1
- package/build/format/uri_reference.mjs +2 -3
- package/build/format/uri_template.d.mts +2 -3
- package/build/format/uri_template.mjs +4 -5
- package/build/format/url.d.mts +3 -3
- package/build/format/url.mjs +4 -5
- package/build/guard/guard.mjs +2 -2
- package/build/guard/string.d.mts +2 -2
- package/build/guard/string.mjs +7 -7
- package/build/schema/engine/_regexp.d.mts +2 -0
- package/build/schema/engine/_regexp.mjs +4 -0
- package/build/schema/engine/_stack.mjs +1 -1
- package/build/schema/engine/additionalProperties.mjs +4 -3
- package/build/schema/engine/pattern.mjs +3 -2
- package/build/schema/engine/patternProperties.mjs +4 -3
- package/build/schema/engine/schema.mjs +13 -4
- package/build/schema/resolve/ref.d.mts +1 -0
- package/build/schema/resolve/ref.mjs +13 -3
- package/build/schema/types/index.d.mts +0 -2
- package/build/schema/types/index.mjs +0 -2
- package/build/system/memory/clone.mjs +1 -1
- package/build/system/memory/discard.mjs +2 -1
- package/build/type/engine/evaluate/broaden.d.mts +5 -5
- package/build/type/engine/evaluate/broaden.mjs +20 -26
- package/build/type/engine/evaluate/compare.d.mts +6 -10
- package/build/type/engine/evaluate/compare.mjs +9 -13
- package/build/type/engine/evaluate/composite.d.mts +7 -4
- package/build/type/engine/evaluate/composite.mjs +12 -19
- package/build/type/engine/evaluate/distribute.d.mts +4 -20
- package/build/type/engine/evaluate/distribute.mjs +8 -20
- package/build/type/engine/evaluate/evaluate.d.mts +4 -4
- package/build/type/engine/evaluate/evaluate.mjs +11 -8
- package/build/type/engine/evaluate/flatten.d.mts +1 -1
- package/build/type/engine/evaluate/flatten.mjs +3 -4
- package/build/type/engine/evaluate/narrow.d.mts +17 -2
- package/build/type/engine/evaluate/narrow.mjs +26 -6
- package/build/type/engine/exclude/operation.mjs +3 -4
- package/build/type/engine/extract/operation.d.mts +1 -1
- package/build/type/engine/extract/operation.mjs +3 -4
- package/build/type/engine/priority/priority.d.mts +2 -2
- package/build/type/engine/priority/priority.mjs +3 -4
- package/build/type/script/parser.mjs +8 -1
- package/changes.json +1 -1
- package/package.json +3 -3
- package/readme.md +10 -8
- package/build/format/_idna.d.mts +0 -2
- package/build/format/_idna.mjs +0 -246
- package/build/format/_puny.d.mts +0 -1
- package/build/format/_puny.mjs +0 -77
- package/build/schema/types/contentEncoding.d.mts +0 -9
- package/build/schema/types/contentEncoding.mjs +0 -13
- package/build/schema/types/contentMediaType.d.mts +0 -9
- package/build/schema/types/contentMediaType.mjs +0 -13
|
@@ -2,36 +2,24 @@
|
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
3
|
import { Guard } from '../../../guard/index.mjs';
|
|
4
4
|
import { IsUnion } from '../../types/union.mjs';
|
|
5
|
-
import { IsObject } from '../../types/object.mjs';
|
|
6
|
-
import { IsTuple } from '../../types/tuple.mjs';
|
|
7
|
-
import { Composite } from './composite.mjs';
|
|
8
5
|
import { Narrow } from './narrow.mjs';
|
|
9
|
-
import { EvaluateType } from './evaluate.mjs';
|
|
10
6
|
import { EvaluateIntersect } from './evaluate.mjs';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function IsUnionOperand(left, right) {
|
|
15
|
-
const isUnionLeft = IsUnion(left);
|
|
16
|
-
const isUnionRight = IsUnion(right);
|
|
17
|
-
const result = isUnionLeft || isUnionRight;
|
|
7
|
+
import { EvaluateType } from './evaluate.mjs';
|
|
8
|
+
function ShouldEvaluate(left, right) {
|
|
9
|
+
const result = IsUnion(left) || IsUnion(right);
|
|
18
10
|
return result;
|
|
19
11
|
}
|
|
20
12
|
function DistributeOperation(left, right) {
|
|
21
13
|
const evaluatedLeft = EvaluateType(left);
|
|
22
14
|
const evaluatedRight = EvaluateType(right);
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
isObjectLeft && IsObjectRight ? Composite(evaluatedLeft, evaluatedRight) :
|
|
28
|
-
isObjectLeft && !IsObjectRight ? evaluatedLeft :
|
|
29
|
-
!isObjectLeft && IsObjectRight ? evaluatedRight :
|
|
30
|
-
Narrow(evaluatedLeft, evaluatedRight));
|
|
15
|
+
const shouldEvaluate = ShouldEvaluate(evaluatedLeft, evaluatedRight);
|
|
16
|
+
const result = shouldEvaluate
|
|
17
|
+
? EvaluateIntersect([evaluatedLeft, evaluatedRight])
|
|
18
|
+
: Narrow(evaluatedLeft, evaluatedRight);
|
|
31
19
|
return result;
|
|
32
20
|
}
|
|
33
21
|
function DistributeType(type, types, result = []) {
|
|
34
|
-
return Guard.ShiftLeft(types, (left, right) => DistributeType(type, right, [...result, DistributeOperation(
|
|
22
|
+
return Guard.ShiftLeft(types, (left, right) => DistributeType(type, right, [...result, DistributeOperation(left, type)]), () => Guard.IsEqual(result.length, 0)
|
|
35
23
|
? [type]
|
|
36
24
|
: result);
|
|
37
25
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TDependent } from '../../types/dependent.mjs';
|
|
3
3
|
import { type TEnum, type TEnumValue } from '../../types/enum.mjs';
|
|
4
|
-
import { type TLiteral } from '../../types/literal.mjs';
|
|
5
4
|
import { type TIntersect } from '../../types/intersect.mjs';
|
|
5
|
+
import { type TLiteral } from '../../types/literal.mjs';
|
|
6
6
|
import { type TNever } from '../../types/never.mjs';
|
|
7
7
|
import { type TTemplateLiteral } from '../../types/template_literal.mjs';
|
|
8
8
|
import { type TUnion } from '../../types/union.mjs';
|
|
@@ -10,11 +10,11 @@ import { type TDistribute } from './distribute.mjs';
|
|
|
10
10
|
import { type TBroaden } from './broaden.mjs';
|
|
11
11
|
import { type TExcludeOperation } from '../exclude/operation.mjs';
|
|
12
12
|
import { type TTemplateLiteralDecode } from '../template_literal/decode.mjs';
|
|
13
|
-
export type TEvaluateDependent<If extends TSchema, Then extends TSchema, Else extends TSchema,
|
|
13
|
+
export type TEvaluateDependent<If extends TSchema, Then extends TSchema, Else extends TSchema, Intersected extends TSchema = TEvaluateIntersect<[If, Then]>, Excluded extends TSchema = TExcludeOperation<Else, If>, Result extends TSchema = TEvaluateUnion<[Intersected, Excluded]>> = Result;
|
|
14
14
|
export declare function EvaluateDependent<If extends TSchema, Then extends TSchema, Else extends TSchema>(if_: If, then_: Then, else_: Else): TEvaluateDependent<If, Then, Else>;
|
|
15
15
|
export type TEvaluateEnum<Values extends TEnumValue[], Result extends TSchema[] = []> = (Values extends [infer Left extends TEnumValue, ...infer Right extends TEnumValue[]] ? TEvaluateEnum<Right, [...Result, TLiteral<Left>]> : TEvaluateUnion<Result>);
|
|
16
|
-
export declare function EvaluateEnum<Values extends TEnumValue[]>(values: [...Values]): TEvaluateEnum<Values>;
|
|
17
|
-
export type TEvaluateIntersect<Types extends TSchema[], Distribution extends TSchema[] = TDistribute<Types>, Broadend extends TSchema[] = TBroaden<Distribution>, Result extends TSchema =
|
|
16
|
+
export declare function EvaluateEnum<Values extends TEnumValue[]>(values: [...Values], result?: TSchema[]): TEvaluateEnum<Values>;
|
|
17
|
+
export type TEvaluateIntersect<Types extends TSchema[], Distribution extends TSchema[] = TDistribute<Types>, Broadend extends TSchema[] = TBroaden<Distribution>, Result extends TSchema = TEvaluateUnion<Broadend>> = Result;
|
|
18
18
|
export declare function EvaluateIntersect<Types extends TSchema[]>(types: [...Types]): TEvaluateIntersect<Types>;
|
|
19
19
|
export type TEvaluateTemplateLiteral<Pattern extends string, Evaluated extends TSchema = TTemplateLiteralDecode<Pattern>, Result extends TSchema = TEvaluateType<Evaluated>> = Result;
|
|
20
20
|
export declare function EvaluateTemplateLiteral<Pattern extends string>(pattern: Pattern): TEvaluateTemplateLiteral<Pattern>;
|
|
@@ -2,29 +2,31 @@
|
|
|
2
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
3
3
|
import { IsDependent } from '../../types/dependent.mjs';
|
|
4
4
|
import { IsEnum } from '../../types/enum.mjs';
|
|
5
|
+
import { IsIntersect } from '../../types/intersect.mjs';
|
|
5
6
|
import { Literal } from '../../types/literal.mjs';
|
|
6
|
-
import { IsIntersect, Intersect } from '../../types/intersect.mjs';
|
|
7
7
|
import { Never } from '../../types/never.mjs';
|
|
8
8
|
import { IsTemplateLiteral } from '../../types/template_literal.mjs';
|
|
9
9
|
import { Union, IsUnion } from '../../types/union.mjs';
|
|
10
|
+
// ------------------------------------------------------------------
|
|
11
|
+
// Infrastructure
|
|
12
|
+
// ------------------------------------------------------------------
|
|
10
13
|
import { Distribute } from './distribute.mjs';
|
|
11
14
|
import { Broaden } from './broaden.mjs';
|
|
12
15
|
import { ExcludeOperation } from '../exclude/operation.mjs';
|
|
13
16
|
import { TemplateLiteralDecode } from '../template_literal/decode.mjs';
|
|
14
17
|
export function EvaluateDependent(if_, then_, else_) {
|
|
15
|
-
const
|
|
18
|
+
const intersected = EvaluateIntersect([if_, then_]);
|
|
16
19
|
const excluded = ExcludeOperation(else_, if_);
|
|
17
|
-
const result = EvaluateUnion([
|
|
20
|
+
const result = EvaluateUnion([intersected, excluded]);
|
|
18
21
|
return result;
|
|
19
22
|
}
|
|
20
|
-
export function EvaluateEnum(values) {
|
|
21
|
-
|
|
22
|
-
return EvaluateUnion(result);
|
|
23
|
+
export function EvaluateEnum(values, result = []) {
|
|
24
|
+
return Guard.ShiftLeft(values, (left, right) => EvaluateEnum(right, [...result, Literal(left)]), () => EvaluateUnion(result));
|
|
23
25
|
}
|
|
24
26
|
export function EvaluateIntersect(types) {
|
|
25
27
|
const distribution = Distribute(types);
|
|
26
28
|
const broadend = Broaden(distribution);
|
|
27
|
-
const result =
|
|
29
|
+
const result = EvaluateUnion(broadend);
|
|
28
30
|
return result;
|
|
29
31
|
}
|
|
30
32
|
export function EvaluateTemplateLiteral(pattern) {
|
|
@@ -38,12 +40,13 @@ export function EvaluateUnion(types) {
|
|
|
38
40
|
return result;
|
|
39
41
|
}
|
|
40
42
|
export function EvaluateType(type) {
|
|
41
|
-
|
|
43
|
+
const result = (IsDependent(type) ? EvaluateDependent(type.if, type.then, type.else) :
|
|
42
44
|
IsEnum(type) ? EvaluateEnum(type.enum) :
|
|
43
45
|
IsIntersect(type) ? EvaluateIntersect(type.allOf) :
|
|
44
46
|
IsTemplateLiteral(type) ? EvaluateTemplateLiteral(type.pattern) :
|
|
45
47
|
IsUnion(type) ? EvaluateUnion(type.anyOf) :
|
|
46
48
|
type);
|
|
49
|
+
return result;
|
|
47
50
|
}
|
|
48
51
|
export function EvaluateUnionFast(types) {
|
|
49
52
|
const result = (Guard.IsEqual(types.length, 1) ? types[0] :
|
|
@@ -2,5 +2,5 @@ import { type TSchema } from '../../types/schema.mjs';
|
|
|
2
2
|
import { type TUnion } from '../../types/union.mjs';
|
|
3
3
|
type TFlattenType<Type extends TSchema, Result extends TSchema[] = Type extends TUnion<infer Types extends TSchema[]> ? TFlatten<Types> : [Type]> = Result;
|
|
4
4
|
export type TFlatten<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFlatten<Right, [...Result, ...TFlattenType<Left>]> : Result);
|
|
5
|
-
export declare function Flatten<Types extends TSchema[]>(types: [...Types]): TFlatten<Types>;
|
|
5
|
+
export declare function Flatten<Types extends TSchema[]>(types: [...Types], result?: TSchema[]): TFlatten<Types>;
|
|
6
6
|
export {};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
+
import { Guard } from '../../../guard/index.mjs';
|
|
2
3
|
import { IsUnion } from '../../types/union.mjs';
|
|
3
4
|
function FlattenType(type) {
|
|
4
5
|
const result = IsUnion(type) ? Flatten(type.anyOf) : [type];
|
|
5
6
|
return result;
|
|
6
7
|
}
|
|
7
|
-
export function Flatten(types) {
|
|
8
|
-
return
|
|
9
|
-
return [...result, ...FlattenType(type)];
|
|
10
|
-
}, []);
|
|
8
|
+
export function Flatten(types, result = []) {
|
|
9
|
+
return Guard.ShiftLeft(types, (left, right) => Flatten(right, [...result, ...FlattenType(left)]), () => result);
|
|
11
10
|
}
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TAny } from '../../types/any.mjs';
|
|
2
3
|
import { type TNever } from '../../types/never.mjs';
|
|
3
|
-
import { type
|
|
4
|
-
|
|
4
|
+
import { type TUnknown } from '../../types/unknown.mjs';
|
|
5
|
+
import { type TCompare, type TCompareResult, CompareResultLeftInside, CompareResultRightInside, CompareResultEqual } from './compare.mjs';
|
|
6
|
+
import { type TComposite, type TCanComposite } from './composite.mjs';
|
|
7
|
+
type TNarrowCompareRule<Left extends TSchema, Right extends TSchema, Result extends TCompareResult = TCompare<Left, Right>> = (Result extends typeof CompareResultLeftInside ? Left : Result extends typeof CompareResultRightInside ? Right : Result extends typeof CompareResultEqual ? Right : TNever);
|
|
8
|
+
type TNarrowCompositeRule<Left extends TSchema, Right extends TSchema, CanCompositeLeft extends boolean = TCanComposite<Left>, CanCompositeRight extends boolean = TCanComposite<Right>> = ([
|
|
9
|
+
CanCompositeLeft,
|
|
10
|
+
CanCompositeRight
|
|
11
|
+
] extends [true, true] ? TComposite<Left, Right> : [
|
|
12
|
+
CanCompositeLeft,
|
|
13
|
+
CanCompositeRight
|
|
14
|
+
] extends [true, false] ? Left : [
|
|
15
|
+
CanCompositeLeft,
|
|
16
|
+
CanCompositeRight
|
|
17
|
+
] extends [false, true] ? Right : TNarrowCompareRule<Left, Right>);
|
|
18
|
+
export type TNarrow<Left extends TSchema, Right extends TSchema> = (Left extends TNever ? TNever : Left extends TAny ? TAny : Left extends TUnknown ? Right : Right extends TNever ? TNever : Right extends TAny ? TAny : Right extends TUnknown ? Left : TNarrowCompositeRule<Left, Right>);
|
|
5
19
|
export declare function Narrow<Left extends TSchema, Right extends TSchema>(left: Left, right: Right): TNarrow<Left, Right>;
|
|
20
|
+
export {};
|
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { IsAny } from '../../types/any.mjs';
|
|
4
|
+
import { Never, IsNever } from '../../types/never.mjs';
|
|
5
|
+
import { IsUnknown } from '../../types/unknown.mjs';
|
|
6
|
+
import { Compare, CompareResultLeftInside, CompareResultRightInside, CompareResultEqual } from './compare.mjs';
|
|
7
|
+
import { Composite, CanComposite } from './composite.mjs';
|
|
8
|
+
function NarrowCompareRule(left, right) {
|
|
6
9
|
const result = Compare(left, right);
|
|
7
|
-
return (Guard.IsEqual(result,
|
|
8
|
-
Guard.IsEqual(result,
|
|
9
|
-
Guard.IsEqual(result,
|
|
10
|
+
return (Guard.IsEqual(result, CompareResultLeftInside) ? left :
|
|
11
|
+
Guard.IsEqual(result, CompareResultRightInside) ? right :
|
|
12
|
+
Guard.IsEqual(result, CompareResultEqual) ? right :
|
|
10
13
|
Never());
|
|
11
14
|
}
|
|
15
|
+
function NarrowCompositeRule(left, right) {
|
|
16
|
+
const canCompositeLeft = CanComposite(left);
|
|
17
|
+
const canCompositeRight = CanComposite(right);
|
|
18
|
+
return (canCompositeLeft && canCompositeRight ? Composite(left, right) :
|
|
19
|
+
canCompositeLeft && !canCompositeRight ? left :
|
|
20
|
+
!canCompositeLeft && canCompositeRight ? right :
|
|
21
|
+
NarrowCompareRule(left, right));
|
|
22
|
+
}
|
|
23
|
+
export function Narrow(left, right) {
|
|
24
|
+
return (IsNever(left) ? left :
|
|
25
|
+
IsAny(left) ? left :
|
|
26
|
+
IsUnknown(left) ? right :
|
|
27
|
+
IsNever(right) ? right :
|
|
28
|
+
IsAny(right) ? right :
|
|
29
|
+
IsUnknown(right) ? left :
|
|
30
|
+
NarrowCompositeRule(left, right));
|
|
31
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// deno-lint-ignore-file ban-types
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
|
+
import { Guard } from '../../../guard/index.mjs';
|
|
3
4
|
import { IsUnion } from '../../types/union.mjs';
|
|
4
5
|
import { Extends, ExtendsResult } from '../../extends/index.mjs';
|
|
5
6
|
import { EvaluateType } from '../evaluate/evaluate.mjs';
|
|
@@ -9,10 +10,8 @@ function ExcludeType(left, right) {
|
|
|
9
10
|
const result = ExtendsResult.IsExtendsTrueLike(check) ? [] : [left];
|
|
10
11
|
return result;
|
|
11
12
|
}
|
|
12
|
-
function ExcludeUnion(
|
|
13
|
-
return
|
|
14
|
-
return [...result, ...ExcludeType(head, right)];
|
|
15
|
-
}, []);
|
|
13
|
+
function ExcludeUnion(left, right, result = []) {
|
|
14
|
+
return Guard.ShiftLeft(left, (head, tail) => ExcludeUnion(tail, right, [...result, ...ExcludeType(head, right)]), () => result);
|
|
16
15
|
}
|
|
17
16
|
export function ExcludeOperation(left, right) {
|
|
18
17
|
const evaluated = EvaluateType(left);
|
|
@@ -4,7 +4,7 @@ import { type TExtends, ExtendsResult } from '../../extends/index.mjs';
|
|
|
4
4
|
import { type TEvaluateType } from '../evaluate/evaluate.mjs';
|
|
5
5
|
import { type TEvaluateUnion } from '../evaluate/evaluate.mjs';
|
|
6
6
|
type TExtractType<Left extends TSchema, Right extends TSchema, Check extends ExtendsResult.TResult = TExtends<{}, Left, Right>, Result extends TSchema[] = Check extends ExtendsResult.TExtendsTrueLike ? [Left] : []> = Result;
|
|
7
|
-
type TExtractUnion<
|
|
7
|
+
type TExtractUnion<Left extends TSchema[], Right extends TSchema, Result extends TSchema[] = []> = (Left extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtractUnion<Tail, Right, [...Result, ...TExtractType<Head, Right>]> : Result);
|
|
8
8
|
export type TExtractOperation<Left extends TSchema, Right extends TSchema, Evaluated extends TSchema = TEvaluateType<Left>, Canonical extends TSchema[] = Evaluated extends TUnion<infer Types extends TSchema[]> ? Types : [Evaluated], Remaining extends TSchema[] = TExtractUnion<Canonical, Right>, Result extends TSchema = TEvaluateUnion<Remaining>> = Result;
|
|
9
9
|
export declare function ExtractOperation<Left extends TSchema, Right extends TSchema>(left: Left, right: Right): TExtractOperation<Left, Right>;
|
|
10
10
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// deno-lint-ignore-file ban-types
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
|
+
import { Guard } from '../../../guard/index.mjs';
|
|
3
4
|
import { IsUnion } from '../../types/union.mjs';
|
|
4
5
|
import { Extends, ExtendsResult } from '../../extends/index.mjs';
|
|
5
6
|
import { EvaluateType } from '../evaluate/evaluate.mjs';
|
|
@@ -9,10 +10,8 @@ function ExtractType(left, right) {
|
|
|
9
10
|
const result = ExtendsResult.IsExtendsTrueLike(check) ? [left] : [];
|
|
10
11
|
return result;
|
|
11
12
|
}
|
|
12
|
-
function ExtractUnion(
|
|
13
|
-
return
|
|
14
|
-
return [...result, ...ExtractType(head, right)];
|
|
15
|
-
}, []);
|
|
13
|
+
function ExtractUnion(left, right, result = []) {
|
|
14
|
+
return Guard.ShiftLeft(left, (head, tail) => ExtractUnion(tail, right, [...result, ...ExtractType(head, right)]), () => result);
|
|
16
15
|
}
|
|
17
16
|
export function ExtractOperation(left, right) {
|
|
18
17
|
const evaluated = EvaluateType(left);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
-
import { type TCompare, type TCompareResult } from '../evaluate/compare.mjs';
|
|
3
|
-
type TComparer<Left extends TSchema, Right extends TSchema, CompareResult extends TCompareResult = TCompare<Left, Right>, Result extends 0 | 1 = (CompareResult extends
|
|
2
|
+
import { type TCompare, type TCompareResult, CompareResultRightInside, CompareResultDisjoint } from '../evaluate/compare.mjs';
|
|
3
|
+
type TComparer<Left extends TSchema, Right extends TSchema, CompareResult extends TCompareResult = TCompare<Left, Right>, Result extends 0 | 1 = (CompareResult extends typeof CompareResultRightInside ? 1 : CompareResult extends typeof CompareResultDisjoint ? 1 : 0)> = Result;
|
|
4
4
|
type TInsert<Type extends TSchema, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TComparer<Type, Left> extends 1 ? TInsert<Type, Right, [...Result, Left]> : [...Result, Type, ...Types] : [...Result, Type]);
|
|
5
5
|
type TSort<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TSort<Right, TInsert<Left, Result>> : Result);
|
|
6
6
|
/**
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
3
|
-
import { Compare } from '../evaluate/compare.mjs';
|
|
3
|
+
import { Compare, CompareResultRightInside, CompareResultDisjoint } from '../evaluate/compare.mjs';
|
|
4
4
|
function Comparer(left, right) {
|
|
5
5
|
const compareResult = Compare(left, right);
|
|
6
|
-
|
|
7
|
-
Guard.IsEqual(compareResult,
|
|
6
|
+
return (Guard.IsEqual(compareResult, CompareResultRightInside) ? 1 :
|
|
7
|
+
Guard.IsEqual(compareResult, CompareResultDisjoint) ? 1 :
|
|
8
8
|
0);
|
|
9
|
-
return result;
|
|
10
9
|
}
|
|
11
10
|
function Insert(type, types, result = []) {
|
|
12
11
|
return Guard.ShiftLeft(types, (left, right) => Guard.IsEqual(Comparer(type, left), 1)
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
// deno-lint-ignore-file
|
|
3
|
-
//
|
|
3
|
+
// ------------------------------------------------------------------
|
|
4
|
+
//
|
|
5
|
+
// This module was auto-generated by TypeBox's parser compiler
|
|
6
|
+
// infrastructure (ParseBox). The source grammar is located at:
|
|
7
|
+
//
|
|
8
|
+
// Source: ./design/syntax/syntax.ts
|
|
9
|
+
//
|
|
10
|
+
// ------------------------------------------------------------------
|
|
4
11
|
import * as S from './mapping.mjs';
|
|
5
12
|
import * as Token from './token/index.mjs';
|
|
6
13
|
const If = (result, left, right = () => []) => result.length === 2 ? left(result) : right();
|
package/changes.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@depup/typebox",
|
|
3
3
|
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript (with updated dependencies)",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.14-depup.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typebox",
|
|
7
7
|
"depup",
|
|
@@ -94,8 +94,8 @@
|
|
|
94
94
|
"changes": {},
|
|
95
95
|
"depsUpdated": 0,
|
|
96
96
|
"originalPackage": "typebox",
|
|
97
|
-
"originalVersion": "1.3.
|
|
98
|
-
"processedAt": "2026-08-
|
|
97
|
+
"originalVersion": "1.3.14",
|
|
98
|
+
"processedAt": "2026-08-16T00:27:33.089Z",
|
|
99
99
|
"smokeTest": "passed"
|
|
100
100
|
}
|
|
101
101
|
}
|
package/readme.md
CHANGED
|
@@ -113,11 +113,11 @@ type User = Type.Static<typeof User> // type User = {
|
|
|
113
113
|
|
|
114
114
|
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkBDGAC0YgBMBXAG1WoBjCADsAzvGZs4AXkREAdAGVBUYGBgAKAAaU4cQmjgA1VIJjQALLLgBvOGQBccEdxDFUUADRwkz1+6ePgBe-m4e3nAA7mGBUHAAvnoGRCZmFlAAzDb2Ti7hQb6xESHFnonJhuim5tAATDkOZZF++XEV2gCU1HRwAOJQTGCswIJiHDz8QqIS-YPDo+NyyGjKqupaUqw+uvpVabCoZDnJ+pBiwDDAos41GZZepy7QIEy8t+nQmY-6+twAbh9alA6skkntUn1UDhUDAoEgTr84P9PFdBKgxB9DmQANoAXR+v2AIk4owxzXxYMqqSknmAb0RvyY7mAqBEMCB90J+lJGAw3DEqE5Vm5cDEaEEfCYUGFUEsVIhRgYGPYclsTwA5tCQLD4c4oTC4UhRa8YHS3s5aWo3lSutR9sqxKr5KslDAWKMADxVCAYOZDEZjHF4R2sPB4gB8+l6DpVjKRCcTSeTKZTvX0WsNerscAUecSotTReLJfTcFN5veObzCgqJfrDeTvQSQA) | [Example 2](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkBDGAC0YgBMBXAG1WoBjCADsAzvABqqQTGgAWOAF5ERAHQB5YgCsZMABQBvOGQBcqtGoBy3EMVRR9ASgA0cJOeSWbdh87cAXp7qPvaOrnAA7sHetmHOcAC+TpTC4lJ60ADMyhaomjp6RiYx+aF+ER551nEVgaU1vuFJKWkScNKy0ABMuV75WrqyxWbV5eFuVf2N8U4t1HRwAOJQTGCswIJiHDz8QqLt0rCoZH3qg0WGlHBwkGLAMMCi5p1yUPIu13Ai0CBMvC9MlAsp8btwAG6ArpQbqUZKpA7wJaoHCoGBQJBnSwXYZXG7ghyPQSoMQNACCUFWSH0RxgJ1cX2AIk4mxJ5MpTGp03GzhS8La8GYdKgwH+WIGhVxXyYdmAqBEMChbw+XxZGAw3DEqCVClBcDEaEEfCYUB170+-MRjBJ7BU0xxBjxcAA5iiQGiMeZkaj0Ug9X9haKAYwWA4g3CUpRCGhrWJbdUAMowFibAA80ZRGFjrAAfDd8wXC4sM9nck7CxXK1XqzX84sbq6fZ64MY1G2knra13u1363AA2H-uZW+3El8exPJ3X6IkgA)
|
|
115
115
|
|
|
116
|
-
TypeBox includes a
|
|
116
|
+
TypeBox includes a micro TypeScript engine that can transform TypeScript definitions to JSON Schema. The engine is fully type-safe and supports many programmable constructs including Conditional, Mapped, Indexed, Generics, Distributive Generics, and more.
|
|
117
117
|
|
|
118
118
|
### Example
|
|
119
119
|
|
|
120
|
-
Syntax highlighting is available via the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=sinclairzx81.typebox-script)
|
|
120
|
+
Syntax highlighting is available via the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=sinclairzx81.typebox-script).
|
|
121
121
|
|
|
122
122
|
```typescript
|
|
123
123
|
import Type from 'typebox'
|
|
@@ -229,9 +229,9 @@ const result = Vector.Parse({ x: 1, y: 0, z: 0 }) // const result: {
|
|
|
229
229
|
|
|
230
230
|
### Coverage
|
|
231
231
|
|
|
232
|
-
|
|
232
|
+
[JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite) | [JSON Schema Compliance Suite](https://github.com/sinclairzx81/json-schema-compliance-suite)
|
|
233
233
|
|
|
234
|
-
|
|
234
|
+
TypeBox supports all major JSON Schema draft versions and tracks compliance against the official JSON Schema Test Suite. It also maintains a separate JavaScript compliance suite to track ecosystem adoption as JSON Schema moves toward the Version 1 candidate. The following table shows TypeBox specification coverage.
|
|
235
235
|
|
|
236
236
|
| Spec | 3 | 4 | 6 | 7 | 2019-09 | 2020-12 | v1 |
|
|
237
237
|
|:-----|:--|:--|:--|:--|:--|:--|:--|
|
|
@@ -281,10 +281,13 @@ The following table shows specification coverage implemented by TypeBox.
|
|
|
281
281
|
| unevaluatedProperties | - | - | - | - | ✅ | ✅ | 128/129 |
|
|
282
282
|
| uniqueItems | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
283
283
|
|
|
284
|
-
|
|
285
284
|
### Performance
|
|
286
285
|
|
|
287
|
-
|
|
286
|
+
TypeBox tracks comparative performance against AJV8 as the de facto JSON Schema performance standard. For broader comparative benchmarks, refer to the community maintained projects below.
|
|
287
|
+
|
|
288
|
+
[Runtime Benchmarks](https://moltar.github.io/typescript-runtime-type-benchmarks/) | [Schema Benchmarks](https://schemabenchmarks.dev/)
|
|
289
|
+
|
|
290
|
+
The following table shows compilation performance for various JSON Schema structures. These benchmarks measure the time required to JIT compile schematics, with faster compilation resulting in faster application startup.
|
|
288
291
|
|
|
289
292
|
```python
|
|
290
293
|
┌──────────────────────┬─────────────┬─────────────┐
|
|
@@ -316,8 +319,7 @@ The following table shows compile performance for various JSON Schema structures
|
|
|
316
319
|
└──────────────────────┴─────────────┴─────────────┘
|
|
317
320
|
```
|
|
318
321
|
|
|
319
|
-
|
|
320
|
-
The following tables shows validation performance for various JSON Schema structures using AJV8 as a basis for comparison.
|
|
322
|
+
The following tables shows validation performance for various JSON Schema structures. These benchmarks measure overall validation throughput for JIT compiled schematics.
|
|
321
323
|
|
|
322
324
|
```python
|
|
323
325
|
┌──────────────────────┬──────────────┬──────────────┐
|
package/build/format/_idna.d.mts
DELETED
package/build/format/_idna.mjs
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { Unreachable } from '../system/unreachable/index.mjs';
|
|
2
|
-
import * as Puny from './_puny.mjs';
|
|
3
|
-
// ------------------------------------------------------------------
|
|
4
|
-
// Unicode General Category Helper (RFC 5892)
|
|
5
|
-
// ------------------------------------------------------------------
|
|
6
|
-
function IsNonspacingMark(cp) {
|
|
7
|
-
return /\p{Mn}/u.test(String.fromCodePoint(cp));
|
|
8
|
-
}
|
|
9
|
-
function IsSpacingCombiningMark(cp) {
|
|
10
|
-
return /\p{Mc}/u.test(String.fromCodePoint(cp));
|
|
11
|
-
}
|
|
12
|
-
function IsEnclosingMark(cp) {
|
|
13
|
-
return /\p{Me}/u.test(String.fromCodePoint(cp));
|
|
14
|
-
}
|
|
15
|
-
function IsCombiningMark(cp) {
|
|
16
|
-
return IsNonspacingMark(cp) || IsSpacingCombiningMark(cp) || IsEnclosingMark(cp);
|
|
17
|
-
}
|
|
18
|
-
// ------------------------------------------------------------------
|
|
19
|
-
// RFC 5892 §2.6 DISALLOWED exceptions
|
|
20
|
-
//
|
|
21
|
-
// https://tools.ietf.org/html/rfc5892#section-2.6
|
|
22
|
-
// ------------------------------------------------------------------
|
|
23
|
-
const RFC5892_DISALLOWED = new Set([
|
|
24
|
-
0x0640, // ARABIC TATWEEL
|
|
25
|
-
0x07fa, // NKO LAJANYALAN
|
|
26
|
-
0x302e, // HANGUL SINGLE DOT TONE MARK
|
|
27
|
-
0x302f, // HANGUL DOUBLE DOT TONE MARK
|
|
28
|
-
0x3031, // VERTICAL KANA REPEAT MARK
|
|
29
|
-
0x3032, // VERTICAL KANA REPEAT WITH VOICED ITERATION MARK
|
|
30
|
-
0x3033, // VERTICAL KANA REPEAT MARK UPPER HALF
|
|
31
|
-
0x3034, // VERTICAL KANA REPEAT WITH VOICED ITERATION MARK UPPER HALF
|
|
32
|
-
0x3035, // VERTICAL KANA REPEAT MARK LOWER HALF
|
|
33
|
-
0x303b // VERTICAL IDEOGRAPHIC ITERATION MARK
|
|
34
|
-
]);
|
|
35
|
-
// ------------------------------------------------------------------
|
|
36
|
-
// A set of Virama (halant) code points used to validate CONTEXTJ
|
|
37
|
-
// rules (RFC 5892 Appendix A.1). These characters allow a subsequent
|
|
38
|
-
// Zero Width Non-Joiner (U+200C) or Zero Width Joiner (U+200D) to
|
|
39
|
-
// be valid in a label.
|
|
40
|
-
// ------------------------------------------------------------------
|
|
41
|
-
const VIRAMA_CPS = new Set([
|
|
42
|
-
0x094d,
|
|
43
|
-
0x09cd,
|
|
44
|
-
0x0a4d,
|
|
45
|
-
0x0acd,
|
|
46
|
-
0x0b4d,
|
|
47
|
-
0x0bcd,
|
|
48
|
-
0x0c4d,
|
|
49
|
-
0x0ccd,
|
|
50
|
-
0x0d3b,
|
|
51
|
-
0x0d3c,
|
|
52
|
-
0x0d4d,
|
|
53
|
-
0x0dca,
|
|
54
|
-
0x1b44,
|
|
55
|
-
0x1baa,
|
|
56
|
-
0x1bab,
|
|
57
|
-
0xa9c0,
|
|
58
|
-
0x11046,
|
|
59
|
-
0x1107f,
|
|
60
|
-
0x110b9,
|
|
61
|
-
0x11133,
|
|
62
|
-
0x11134,
|
|
63
|
-
0x111c0,
|
|
64
|
-
0x11235,
|
|
65
|
-
0x1134d,
|
|
66
|
-
0x11442,
|
|
67
|
-
0x114c2,
|
|
68
|
-
0x115bf,
|
|
69
|
-
0x1163f,
|
|
70
|
-
0x116b6,
|
|
71
|
-
0x11c3f,
|
|
72
|
-
0x11d44,
|
|
73
|
-
0x11d45
|
|
74
|
-
]);
|
|
75
|
-
// ------------------------------------------------------------------
|
|
76
|
-
// Guards for CONTEXTO rules (RFC 5892 Appendix A)
|
|
77
|
-
// ------------------------------------------------------------------
|
|
78
|
-
function IsGreek(cp) {
|
|
79
|
-
return /\p{Script=Greek}/u.test(String.fromCodePoint(cp));
|
|
80
|
-
}
|
|
81
|
-
function IsHebrew(cp) {
|
|
82
|
-
return /\p{Script=Hebrew}/u.test(String.fromCodePoint(cp));
|
|
83
|
-
}
|
|
84
|
-
function IsHiragana(cp) {
|
|
85
|
-
return /\p{Script=Hiragana}/u.test(String.fromCodePoint(cp));
|
|
86
|
-
}
|
|
87
|
-
function IsKatakana(cp) {
|
|
88
|
-
return /\p{Script=Katakana}/u.test(String.fromCodePoint(cp));
|
|
89
|
-
}
|
|
90
|
-
function IsHan(cp) {
|
|
91
|
-
return /\p{Script=Han}/u.test(String.fromCodePoint(cp));
|
|
92
|
-
}
|
|
93
|
-
function IsArabicIndicDigit(cp) {
|
|
94
|
-
return cp >= 0x0660 && cp <= 0x0669;
|
|
95
|
-
}
|
|
96
|
-
function IsExtendedArabicIndicDigit(cp) {
|
|
97
|
-
return cp >= 0x06f0 && cp <= 0x06f9;
|
|
98
|
-
}
|
|
99
|
-
function IsVirama(cp) {
|
|
100
|
-
return VIRAMA_CPS.has(cp);
|
|
101
|
-
}
|
|
102
|
-
// ------------------------------------------------------------------
|
|
103
|
-
// IsUnicodeLabel
|
|
104
|
-
// ------------------------------------------------------------------
|
|
105
|
-
function IsUnicodeLabel(value) {
|
|
106
|
-
// deno-coverage-ignore-start - unable to reach via format guards
|
|
107
|
-
if (value.length === 0)
|
|
108
|
-
return Unreachable(); // false
|
|
109
|
-
// deno-coverage-ignore-stop
|
|
110
|
-
// Use spread to handle surrogate pairs and provide O(1) neighbor access
|
|
111
|
-
const cps = [...value].map((c) => c.codePointAt(0));
|
|
112
|
-
const len = cps.length;
|
|
113
|
-
// RFC 5891 §4.2.3.2: Hyphen rules
|
|
114
|
-
if (cps[0] === 0x2d || cps[len - 1] === 0x2d)
|
|
115
|
-
return false;
|
|
116
|
-
if (len >= 4 && cps[2] === 0x2d && cps[3] === 0x2d)
|
|
117
|
-
return false;
|
|
118
|
-
// RFC 5891 §4.2.3.2 - Must not begin with a combining mark
|
|
119
|
-
if (IsCombiningMark(cps[0]))
|
|
120
|
-
return false;
|
|
121
|
-
let hasJapanese = false;
|
|
122
|
-
let hasArabicIndic = false;
|
|
123
|
-
let hasExtendedArabicIndic = false;
|
|
124
|
-
for (let i = 0; i < len; i++) {
|
|
125
|
-
const cp = cps[i];
|
|
126
|
-
// 1. DISALLOWED exceptions
|
|
127
|
-
if (RFC5892_DISALLOWED.has(cp))
|
|
128
|
-
return false;
|
|
129
|
-
// 2. Collect Flags
|
|
130
|
-
if (IsHiragana(cp) || IsKatakana(cp) || IsHan(cp))
|
|
131
|
-
hasJapanese = true;
|
|
132
|
-
if (IsArabicIndicDigit(cp))
|
|
133
|
-
hasArabicIndic = true;
|
|
134
|
-
if (IsExtendedArabicIndicDigit(cp))
|
|
135
|
-
hasExtendedArabicIndic = true;
|
|
136
|
-
// 3. CONTEXTO / CONTEXTJ Neighbor Rules
|
|
137
|
-
const prev = cps[i - 1], next = cps[i + 1];
|
|
138
|
-
switch (cp) {
|
|
139
|
-
case 0x00b7:
|
|
140
|
-
if (prev !== 0x006c || next !== 0x006c)
|
|
141
|
-
return false;
|
|
142
|
-
break; // MIDDLE DOT (Catalan)
|
|
143
|
-
case 0x0375:
|
|
144
|
-
if (next === undefined || !IsGreek(next))
|
|
145
|
-
return false;
|
|
146
|
-
break; // Greek KERAIA
|
|
147
|
-
case 0x05f3:
|
|
148
|
-
case 0x05f4:
|
|
149
|
-
if (prev === undefined || !IsHebrew(prev))
|
|
150
|
-
return false;
|
|
151
|
-
break; // Hebrew GERESH
|
|
152
|
-
case 0x200c: // ZWNJ - RFC 5892 Appendix A.1
|
|
153
|
-
// Note: Full validation requires a Unicode joining type table. We reject
|
|
154
|
-
// only when preceded by ASCII (U+0000-U+007F), which can never satisfy
|
|
155
|
-
// the Virama or cursive-joining rules.
|
|
156
|
-
if (prev === undefined || (prev < 0x0080 && !IsVirama(prev)))
|
|
157
|
-
return false;
|
|
158
|
-
break;
|
|
159
|
-
case 0x200d: // ZWJ - RFC 5892 Appendix A.2
|
|
160
|
-
if (prev === undefined || !IsVirama(prev))
|
|
161
|
-
return false;
|
|
162
|
-
break;
|
|
163
|
-
case 0x30fb: /* Checked at end via hasJapanese */
|
|
164
|
-
break; // KATAKANA MIDDLE DOT
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
// 4. Global Context Validations (Post-loop)
|
|
168
|
-
// RFC 5892 Appendix A.7 - Katakana Middle Dot requirement
|
|
169
|
-
if (value.includes('\u30fb') && !hasJapanese)
|
|
170
|
-
return false;
|
|
171
|
-
// RFC 5892 Appendix A.8/A.9 - Mixing Arabic Digits
|
|
172
|
-
if (hasArabicIndic && hasExtendedArabicIndic)
|
|
173
|
-
return false;
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
// ------------------------------------------------------------------
|
|
177
|
-
// IsAsciiLabel
|
|
178
|
-
// ------------------------------------------------------------------
|
|
179
|
-
function IsAsciiLabel(value) {
|
|
180
|
-
// Must not start or end with a hyphen
|
|
181
|
-
if (value.charCodeAt(0) === 45 || value.charCodeAt(value.length - 1) === 45)
|
|
182
|
-
return false;
|
|
183
|
-
// RFC 5891 §4.2.3.1 : "--" at positions 3-4 is reserved for A-labels only
|
|
184
|
-
if (value.length >= 4 && value.charCodeAt(2) === 45 && value.charCodeAt(3) === 45)
|
|
185
|
-
return false;
|
|
186
|
-
// All characters must be alphanumeric or hyphen
|
|
187
|
-
for (let i = 0; i < value.length; i++) {
|
|
188
|
-
const ch = value.charCodeAt(i);
|
|
189
|
-
if (!((ch >= 97 && ch <= 122) || // a-z
|
|
190
|
-
(ch >= 65 && ch <= 90) || // A-Z
|
|
191
|
-
(ch >= 48 && ch <= 57) || // 0-9
|
|
192
|
-
ch === 45 // '-'
|
|
193
|
-
))
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
// ------------------------------------------------------------------
|
|
199
|
-
// IsPunyLabel
|
|
200
|
-
// ------------------------------------------------------------------
|
|
201
|
-
function IsPuny(value) {
|
|
202
|
-
return value.toLowerCase().startsWith('xn--');
|
|
203
|
-
}
|
|
204
|
-
function IsPunyLabel(value) {
|
|
205
|
-
try {
|
|
206
|
-
const payload = value.slice(4).toLowerCase();
|
|
207
|
-
// 1. Structural Validation (RFC 3492 syntax)
|
|
208
|
-
//
|
|
209
|
-
// If the payload contains a hyphen, it MUST be a delimiter separating basic
|
|
210
|
-
// ASCII characters from the variable-length integers. A payload consisting
|
|
211
|
-
// of ONLY a hyphen or starting with multiple hyphens without basic ASCII
|
|
212
|
-
// characters (like "-9uc") is fundamentally malformed.
|
|
213
|
-
//
|
|
214
|
-
const lastHyphen = payload.lastIndexOf('-');
|
|
215
|
-
if (lastHyphen === 0) {
|
|
216
|
-
// Catches "-9uc" right here because the delimiter is at index 0, meaning 0
|
|
217
|
-
// basic ASCII characters preceded it, which is non-canonical.
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
// 2. Decode the payload
|
|
221
|
-
const decoded = Puny.Decode(payload);
|
|
222
|
-
if (!decoded)
|
|
223
|
-
return false;
|
|
224
|
-
// 3. Validate the output rules against RFC 5892
|
|
225
|
-
return IsUnicodeLabel(decoded);
|
|
226
|
-
}
|
|
227
|
-
catch {
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
// ------------------------------------------------------------------
|
|
232
|
-
// IsIdnLabel
|
|
233
|
-
// ------------------------------------------------------------------
|
|
234
|
-
export function IsIdnLabel(value) {
|
|
235
|
-
if (value.length === 0 || value.length > 63)
|
|
236
|
-
return false;
|
|
237
|
-
return IsPuny(value) ? IsPunyLabel(value) : IsUnicodeLabel(value);
|
|
238
|
-
}
|
|
239
|
-
// ------------------------------------------------------------------
|
|
240
|
-
// IsLabel
|
|
241
|
-
// ------------------------------------------------------------------
|
|
242
|
-
export function IsLabel(value) {
|
|
243
|
-
if (value.length === 0 || value.length > 63)
|
|
244
|
-
return false;
|
|
245
|
-
return IsPuny(value) ? IsPunyLabel(value) : IsAsciiLabel(value);
|
|
246
|
-
}
|