typebox 1.2.17 → 1.2.19
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/build/format/_idna.mjs +21 -2
- package/build/type/engine/indexed/instantiate.d.mts +1 -1
- package/build/type/engine/indexed/instantiate.mjs +4 -2
- package/build/type/engine/instantiate.d.mts +7 -5
- package/build/type/engine/instantiate.mjs +33 -31
- package/build/type/engine/keyof/instantiate.d.mts +1 -1
- package/build/type/engine/keyof/instantiate.mjs +4 -1
- package/package.json +1 -1
package/build/format/_idna.mjs
CHANGED
|
@@ -192,10 +192,29 @@ function IsPuny(value) {
|
|
|
192
192
|
}
|
|
193
193
|
function IsPunyLabel(value) {
|
|
194
194
|
try {
|
|
195
|
-
|
|
195
|
+
const payload = value.slice(4).toLowerCase();
|
|
196
|
+
// 1. Structural Validation (RFC 3492 syntax)
|
|
197
|
+
//
|
|
198
|
+
// If the payload contains a hyphen, it MUST be a delimiter separating basic
|
|
199
|
+
// ASCII characters from the variable-length integers. A payload consisting
|
|
200
|
+
// of ONLY a hyphen or starting with multiple hyphens without basic ASCII
|
|
201
|
+
// characters (like "-9uc") is fundamentally malformed.
|
|
202
|
+
//
|
|
203
|
+
const lastHyphen = payload.lastIndexOf('-');
|
|
204
|
+
if (lastHyphen === 0) {
|
|
205
|
+
// Catches "-9uc" right here because the delimiter is at index 0, meaning 0
|
|
206
|
+
// basic ASCII characters preceded it, which is non-canonical.
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
// 2. Decode the payload
|
|
210
|
+
const decoded = Puny.Decode(payload);
|
|
211
|
+
if (!decoded)
|
|
212
|
+
return false;
|
|
213
|
+
// 3. Validate the output rules against RFC 5892
|
|
214
|
+
return IsUnicodeLabel(decoded);
|
|
196
215
|
}
|
|
197
216
|
catch {
|
|
198
|
-
return false;
|
|
217
|
+
return false;
|
|
199
218
|
}
|
|
200
219
|
}
|
|
201
220
|
// ------------------------------------------------------------------
|
|
@@ -8,7 +8,7 @@ import { type TState, type TInstantiateType, type TCanInstantiate } from '../ins
|
|
|
8
8
|
import { type TIndexDeferred } from '../../action/indexed.mjs';
|
|
9
9
|
import { type TCollapseToObject } from '../object/index.mjs';
|
|
10
10
|
import { type TFromType } from './from_type.mjs';
|
|
11
|
-
type TNormalizeType<Type extends TSchema, Result extends TSchema = (Type extends TCyclic
|
|
11
|
+
type TNormalizeType<Type extends TSchema, Result extends TSchema = (Type extends TCyclic ? TCollapseToObject<Type> : Type extends TDependent ? TCollapseToObject<Type> : Type extends TIntersect ? TCollapseToObject<Type> : Type extends TUnion ? TCollapseToObject<Type> : Type)> = Result;
|
|
12
12
|
export type TIndexAction<Type extends TSchema, Indexer extends TSchema, Result extends TSchema = TCanInstantiate<[Type, Indexer]> extends true ? TFromType<TNormalizeType<Type>, Indexer> : TIndexDeferred<Type, Indexer>> = Result;
|
|
13
13
|
export declare function IndexAction<Type extends TSchema, Indexer extends TSchema>(type: Type, indexer: Indexer, options: TSchemaOptions): TIndexAction<Type, Indexer>;
|
|
14
14
|
export type TIndexInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, Indexer extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>, InstantiatedIndexer extends TSchema = TInstantiateType<Context, State, Indexer>> = TIndexAction<InstantiatedType, InstantiatedIndexer>;
|
|
@@ -9,8 +9,10 @@ import { IndexDeferred } from '../../action/indexed.mjs';
|
|
|
9
9
|
import { CollapseToObject } from '../object/index.mjs';
|
|
10
10
|
import { FromType } from './from_type.mjs';
|
|
11
11
|
function NormalizeType(type) {
|
|
12
|
-
const result = (IsCyclic(type) ||
|
|
13
|
-
type)
|
|
12
|
+
const result = (IsCyclic(type) ||
|
|
13
|
+
IsDependent(type) ||
|
|
14
|
+
IsIntersect(type) ||
|
|
15
|
+
IsUnion(type)) ? CollapseToObject(type) : type;
|
|
14
16
|
return result;
|
|
15
17
|
}
|
|
16
18
|
export function IndexAction(type, indexer, options) {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { type TAddImmutableAction } from './immutable/instantiate_add.mjs';
|
|
2
|
+
import { type TAddReadonlyAction } from './readonly/instantiate_add.mjs';
|
|
3
|
+
import { type TAddOptionalAction } from './optional/instantiate_add.mjs';
|
|
1
4
|
import { type TSchema } from '../types/schema.mjs';
|
|
2
5
|
import { type TArray } from '../types/array.mjs';
|
|
3
6
|
import { type TAsyncIterator } from '../types/async_iterator.mjs';
|
|
@@ -71,6 +74,7 @@ export type TInstantiateElements<Context extends TProperties, State extends TSta
|
|
|
71
74
|
export declare function InstantiateElements<Context extends TProperties, State extends TState, Types extends TSchema[]>(context: Context, state: State, types: [...Types]): TInstantiateElements<Context, State, Types>;
|
|
72
75
|
export type TInstantiateTypes<Context extends TProperties, State extends TState, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TInstantiateTypes<Context, State, Right, [...Result, TInstantiateType<Context, State, Left>]> : Result);
|
|
73
76
|
export declare function InstantiateTypes<Context extends TProperties, State extends TState, Types extends TSchema[]>(context: Context, state: State, types: [...Types]): TInstantiateTypes<Context, State, Types>;
|
|
77
|
+
type TWithModifiers<Type extends TSchema, InstantiatedType extends TSchema, WithOptional extends TSchema = Type extends TOptional ? TAddOptionalAction<InstantiatedType> : InstantiatedType, WithReadonly extends TSchema = Type extends TReadonly ? TAddReadonlyAction<WithOptional> : WithOptional, WithImmutable extends TSchema = Type extends TImmutable ? TAddImmutableAction<WithReadonly> : WithReadonly> = WithImmutable;
|
|
74
78
|
type TInstantiateDeferred<Context extends TProperties, State extends TState, Action extends string, Parameters extends TSchema[]> = ([
|
|
75
79
|
Action,
|
|
76
80
|
Parameters
|
|
@@ -171,11 +175,9 @@ type TInstantiateDeferred<Context extends TProperties, State extends TState, Act
|
|
|
171
175
|
Action,
|
|
172
176
|
Parameters
|
|
173
177
|
] extends ['With', [infer Type extends TSchema, infer Options extends TSchema]] ? TWithInstantiate<Context, State, Type, Options> : TDeferred<Action, Parameters>);
|
|
174
|
-
|
|
175
|
-
export
|
|
176
|
-
|
|
177
|
-
export type TInstantiateType<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateImmediate<Context, State, Type>, WithModifiers extends TSchema = Type extends TDeferred ? InstantiatedType : TWithModifiers<Type, InstantiatedType>> = WithModifiers;
|
|
178
|
-
export declare function InstantiateType<Context extends TProperties, State extends TState, Type extends TSchema>(context: TProperties, state: TState, type: Type): TInstantiateType<Context, State, Type>;
|
|
178
|
+
type TInstantiateImmediate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = (Type extends TRef<infer Ref extends string> ? TRefInstantiate<Context, State, Type, Ref> : Type extends TArray<infer Type extends TSchema> ? TArray<TInstantiateType<Context, State, Type>> : Type extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TInstantiateType<Context, State, Type>> : Type extends TCall<infer Target extends TSchema, infer Parameters extends TSchema[]> ? TCallInstantiate<Context, State, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, InstanceType>> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, ReturnType>> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TDependent<TInstantiateType<Context, State, If>, TInstantiateType<Context, State, Then>, TInstantiateType<Context, State, Else>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TInstantiateTypes<Context, State, Types>> : Type extends TIterator<infer Type extends TSchema> ? TIterator<TInstantiateType<Context, State, Type>> : Type extends TObject<infer Properties extends TProperties> ? TObject<TInstantiateProperties<Context, State, Properties>> : Type extends TPromise<infer Type extends TSchema> ? TPromise<TInstantiateType<Context, State, Type>> : Type extends TRecord<infer Key extends string, infer Type extends TSchema> ? TRecord<Key, TInstantiateType<Context, State, Type>> : Type extends TRest<infer Type extends TSchema> ? TRest<TInstantiateType<Context, State, Type>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TInstantiateElements<Context, State, Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TInstantiateTypes<Context, State, Types>> : Type), WithModifiers extends TSchema = TWithModifiers<Type, InstantiatedType>> = WithModifiers;
|
|
179
|
+
export type TInstantiateType<Context extends TProperties, State extends TState, Type extends TSchema, Result extends TSchema = Type extends TDeferred<infer Action extends string, infer Types extends TSchema[]> ? TInstantiateDeferred<Context, State, Action, Types> : TInstantiateImmediate<Context, State, Type>> = Result;
|
|
180
|
+
export declare function InstantiateType<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type): TInstantiateImmediate<Context, State, Type>;
|
|
179
181
|
/** Instantiates computed schematics using the given context and type. */
|
|
180
182
|
export type TInstantiate<Context extends TProperties, Type extends TSchema> = (TInstantiateType<Context, TState<[], []>, Type>);
|
|
181
183
|
/** Instantiates computed schematics using the given context and type. */
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
// deno-lint-ignore-file
|
|
3
3
|
import { Guard } from '../../guard/index.mjs';
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
|
-
//
|
|
5
|
+
// Modifiers
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
|
-
import {
|
|
7
|
+
import { AddImmutableAction } from './immutable/instantiate_add.mjs';
|
|
8
|
+
import { AddReadonlyAction } from './readonly/instantiate_add.mjs';
|
|
9
|
+
import { AddOptionalAction } from './optional/instantiate_add.mjs';
|
|
8
10
|
import { _Array_, IsArray, ArrayOptions } from '../types/array.mjs';
|
|
9
11
|
import { AsyncIterator, IsAsyncIterator, AsyncIteratorOptions } from '../types/async_iterator.mjs';
|
|
10
12
|
import { Constructor, IsConstructor, ConstructorOptions } from '../types/constructor.mjs';
|
|
@@ -30,9 +32,9 @@ import { AddReadonlyInstantiate } from './readonly/instantiate_add.mjs';
|
|
|
30
32
|
import { RemoveReadonlyInstantiate } from './readonly/instantiate_remove.mjs';
|
|
31
33
|
import { AddOptionalInstantiate } from './optional/instantiate_add.mjs';
|
|
32
34
|
import { RemoveOptionalInstantiate } from './optional/instantiate_remove.mjs';
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
35
|
+
import { IsOptional } from '../types/_optional.mjs';
|
|
36
|
+
import { IsImmutable } from '../types/_immutable.mjs';
|
|
37
|
+
import { IsReadonly } from '../types/_readonly.mjs';
|
|
36
38
|
// ------------------------------------------------------------------
|
|
37
39
|
// Instantiate
|
|
38
40
|
// ------------------------------------------------------------------
|
|
@@ -87,9 +89,15 @@ export function InstantiateElements(context, state, types) {
|
|
|
87
89
|
export function InstantiateTypes(context, state, types) {
|
|
88
90
|
return types.map(type => InstantiateType(context, state, type));
|
|
89
91
|
}
|
|
92
|
+
function WithModifiers(type, instantiatedType) {
|
|
93
|
+
const withOptional = IsOptional(type) ? AddOptionalAction(instantiatedType, {}) : instantiatedType;
|
|
94
|
+
const withReadonly = IsReadonly(type) ? AddReadonlyAction(withOptional, {}) : withOptional;
|
|
95
|
+
const withImmutable = IsImmutable(type) ? AddImmutableAction(withReadonly, {}) : withReadonly;
|
|
96
|
+
return withImmutable;
|
|
97
|
+
}
|
|
90
98
|
function InstantiateDeferred(context, state, action, parameters, options) {
|
|
91
99
|
return (
|
|
92
|
-
//
|
|
100
|
+
// Modifiers
|
|
93
101
|
Guard.IsEqual(action, 'AddImmutable') ? AddImmutableInstantiate(context, state, parameters[0], options) :
|
|
94
102
|
Guard.IsEqual(action, 'RemoveImmutable') ? RemoveImmutableInstantiate(context, state, parameters[0], options) :
|
|
95
103
|
Guard.IsEqual(action, 'AddReadonly') ? AddReadonlyInstantiate(context, state, parameters[0], options) :
|
|
@@ -126,37 +134,31 @@ function InstantiateDeferred(context, state, action, parameters, options) {
|
|
|
126
134
|
Guard.IsEqual(action, 'With') ? WithInstantiate(context, state, parameters[0], parameters[1]) :
|
|
127
135
|
Deferred(action, parameters, options));
|
|
128
136
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const result = (IsRef(type) ? RefInstantiate(context, state, type, type.$ref) :
|
|
137
|
+
function InstantiateImmediate(context, state, type) {
|
|
138
|
+
const instantiatedType = (IsRef(type) ? RefInstantiate(context, state, type, type.$ref) :
|
|
132
139
|
IsArray(type) ? _Array_(InstantiateType(context, state, type.items), ArrayOptions(type)) :
|
|
133
140
|
IsAsyncIterator(type) ? AsyncIterator(InstantiateType(context, state, type.iteratorItems), AsyncIteratorOptions(type)) :
|
|
134
141
|
IsCall(type) ? CallInstantiate(context, state, type.target, type.arguments) :
|
|
135
142
|
IsConstructor(type) ? Constructor(InstantiateTypes(context, state, type.parameters), InstantiateType(context, state, type.instanceType), ConstructorOptions(type)) :
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
function WithModifiers(type, instantiatedType) {
|
|
151
|
-
const withImmutable = IsImmutable(type) ? Immutable(instantiatedType) : instantiatedType;
|
|
152
|
-
const withReadonly = IsReadonly(type) ? Readonly(withImmutable) : withImmutable;
|
|
153
|
-
const withOptional = IsOptional(type) ? Optional(withReadonly) : withReadonly;
|
|
154
|
-
return withOptional;
|
|
143
|
+
IsFunction(type) ? _Function_(InstantiateTypes(context, state, type.parameters), InstantiateType(context, state, type.returnType), FunctionOptions(type)) :
|
|
144
|
+
IsDependent(type) ? Dependent(InstantiateType(context, state, type.if), InstantiateType(context, state, type.then), InstantiateType(context, state, type.else), DependentOptions(type)) :
|
|
145
|
+
IsIntersect(type) ? Intersect(InstantiateTypes(context, state, type.allOf), IntersectOptions(type)) :
|
|
146
|
+
IsIterator(type) ? Iterator(InstantiateType(context, state, type.iteratorItems), IteratorOptions(type)) :
|
|
147
|
+
IsObject(type) ? Object(InstantiateProperties(context, state, type.properties), ObjectOptions(type)) :
|
|
148
|
+
IsPromise(type) ? _Promise_(InstantiateType(context, state, type.item), PromiseOptions(type)) :
|
|
149
|
+
IsRecord(type) ? RecordFromPattern(RecordPattern(type), InstantiateType(context, state, RecordValue(type))) :
|
|
150
|
+
IsRest(type) ? Rest(InstantiateType(context, state, type.items)) :
|
|
151
|
+
IsTuple(type) ? Tuple(InstantiateElements(context, state, type.items), TupleOptions(type)) :
|
|
152
|
+
IsUnion(type) ? Union(InstantiateTypes(context, state, type.anyOf), UnionOptions(type)) :
|
|
153
|
+
type);
|
|
154
|
+
const withModifiers = WithModifiers(type, instantiatedType);
|
|
155
|
+
return withModifiers;
|
|
155
156
|
}
|
|
156
157
|
export function InstantiateType(context, state, type) {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
const result = IsDeferred(type)
|
|
159
|
+
? InstantiateDeferred(context, state, type.action, type.parameters, type.options)
|
|
160
|
+
: InstantiateImmediate(context, state, type);
|
|
161
|
+
return result;
|
|
160
162
|
}
|
|
161
163
|
/** Instantiates computed schematics using the given context and type. */
|
|
162
164
|
export function Instantiate(context, type) {
|
|
@@ -8,7 +8,7 @@ import { type TKeyOfDeferred } from '../../action/keyof.mjs';
|
|
|
8
8
|
import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
|
|
9
9
|
import { type TCollapseToObject } from '../object/index.mjs';
|
|
10
10
|
import { type TFromType } from './from_type.mjs';
|
|
11
|
-
type TNormalizeType<Type extends TSchema, Result extends TSchema = (Type extends TCyclic
|
|
11
|
+
type TNormalizeType<Type extends TSchema, Result extends TSchema = (Type extends TCyclic ? TCollapseToObject<Type> : Type extends TDependent ? TCollapseToObject<Type> : Type extends TIntersect ? TCollapseToObject<Type> : Type extends TUnion ? TCollapseToObject<Type> : Type)> = Result;
|
|
12
12
|
export type TKeyOfAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType<TNormalizeType<Type>> : TKeyOfDeferred<Type>> = Result;
|
|
13
13
|
export declare function KeyOfAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TKeyOfAction<Type>;
|
|
14
14
|
export type TKeyOfInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TKeyOfAction<InstantiatedType>;
|
|
@@ -12,7 +12,10 @@ import { CollapseToObject } from '../object/index.mjs';
|
|
|
12
12
|
// ------------------------------------------------------------------
|
|
13
13
|
import { FromType } from './from_type.mjs';
|
|
14
14
|
function NormalizeType(type) {
|
|
15
|
-
const result = (IsCyclic(type) ||
|
|
15
|
+
const result = (IsCyclic(type) ||
|
|
16
|
+
IsDependent(type) ||
|
|
17
|
+
IsIntersect(type) ||
|
|
18
|
+
IsUnion(type)) ? CollapseToObject(type) : type;
|
|
16
19
|
return result;
|
|
17
20
|
}
|
|
18
21
|
export function KeyOfAction(type, options) {
|