typebox 1.0.59 → 1.0.61
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.
|
@@ -39,7 +39,7 @@ export type StaticEvaluate<T> = {
|
|
|
39
39
|
export type StaticDirection = 'Encode' | 'Decode';
|
|
40
40
|
export type StaticType<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema> = (Type extends TCodec<infer Type extends TSchema, infer Decoded extends unknown> ? StaticCodec<Stack, Direction, Context, This, Type, Decoded> : Type extends TAny ? StaticAny : Type extends TArray<infer Items extends TSchema> ? StaticArray<Stack, Direction, Context, This, Type, Items> : Type extends TAsyncIterator<infer Type extends TSchema> ? StaticAsyncIterator<Stack, Direction, Context, This, Type> : Type extends Base<infer Value extends unknown> ? StaticBase<Value> : Type extends TBigInt ? StaticBigInt : Type extends TBoolean ? StaticBoolean : Type extends TConstructor<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? StaticConstructor<Stack, Direction, Context, This, Parameters, ReturnType> : Type extends TEnum<infer Values extends TEnumValue[]> ? StaticEnum<Values> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? StaticFunction<Stack, Direction, Context, This, Parameters, ReturnType> : Type extends TInteger ? StaticInteger : Type extends TIntersect<infer Types extends TSchema[]> ? StaticIntersect<Stack, Direction, Context, This, Types> : Type extends TIterator<infer Types extends TSchema> ? StaticIterator<Stack, Direction, Context, This, Types> : Type extends TLiteral<infer Value extends TLiteralValue> ? StaticLiteral<Value> : Type extends TNever ? StaticNever : Type extends TNull ? StaticNull : Type extends TNumber ? StaticNumber : Type extends TObject<infer Properties extends TProperties> ? StaticObject<Stack, Direction, Context, This, Properties> : Type extends TPromise<infer Type extends TSchema> ? StaticPromise<Stack, Direction, Context, This, Type> : Type extends TRecord<infer Key extends string, infer Value extends TSchema> ? StaticRecord<Stack, Direction, Context, This, Key, Value> : Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? StaticCyclic<Stack, Direction, Context, This, Defs, Ref> : Type extends TRef<infer Ref extends string> ? StaticRef<Stack, Direction, Context, This, Ref> : Type extends TString ? StaticString : Type extends TSymbol ? StaticSymbol : Type extends TTemplateLiteral<infer Pattern extends string> ? StaticTemplateLiteral<Pattern> : Type extends TThis ? StaticThis<Stack, Direction, Context, This> : Type extends TTuple<infer Items extends TSchema[]> ? StaticTuple<Stack, Direction, Context, This, Type, Items> : Type extends TUndefined ? StaticUndefined : Type extends TUnion<infer Types extends TSchema[]> ? StaticUnion<Stack, Direction, Context, This, Types> : Type extends TUnknown ? StaticUnknown : Type extends TUnsafe<infer Type extends unknown> ? StaticUnsafe<Type> : Type extends TVoid ? StaticVoid : XStatic<Type>);
|
|
41
41
|
/** Infers a static type from a TypeBox type using Parse logic. */
|
|
42
|
-
export type StaticParse<Type extends TSchema, Context extends TProperties = {}, Result extends unknown = StaticType<[], '
|
|
42
|
+
export type StaticParse<Type extends TSchema, Context extends TProperties = {}, Result extends unknown = StaticType<[], 'Encode', Context, {}, Type>> = Result;
|
|
43
43
|
/** Infers a static type from a TypeBox type using Decode logic. */
|
|
44
44
|
export type StaticDecode<Type extends TSchema, Context extends TProperties = {}, Result extends unknown = StaticType<[], 'Decode', Context, {}, Type>> = Result;
|
|
45
45
|
/** Infers a static type from a TypeBox type using Encode logic. */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type TProperties, type TObject } from '../../type/index.mjs';
|
|
2
2
|
export declare function FromObject(context: TProperties, type: TObject, value: unknown): unknown;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
// deno-lint-ignore-file
|
|
3
|
+
import { IsOptional } from '../../type/index.mjs';
|
|
3
4
|
import { Guard } from '../../guard/index.mjs';
|
|
4
5
|
import { FromType } from './from-type.mjs';
|
|
5
6
|
import { IsAdditionalProperties } from '../../schema/types/index.mjs';
|
|
@@ -9,12 +10,13 @@ export function FromObject(context, type, value) {
|
|
|
9
10
|
const knownPropertyKeys = Guard.Keys(type.properties);
|
|
10
11
|
// Properties
|
|
11
12
|
for (const key of knownPropertyKeys) {
|
|
12
|
-
//
|
|
13
|
-
// yielded a non undefined result. Here we interpret an undefined result as
|
|
14
|
-
// a non assignable property and continue.
|
|
13
|
+
// Resolve Value for Property
|
|
15
14
|
const propertyValue = FromType(context, type.properties[key], value[key]);
|
|
16
|
-
|
|
15
|
+
// Ambiguious Undefined: If the value is undefined, the type is optional there's no default. ignore.
|
|
16
|
+
const isUnassignableUndefined = Guard.IsUndefined(propertyValue) && (IsOptional(type.properties[key]) || !Guard.HasPropertyKey(type.properties[key], 'default'));
|
|
17
|
+
if (isUnassignableUndefined)
|
|
17
18
|
continue;
|
|
19
|
+
// Assign
|
|
18
20
|
value[key] = FromType(context, type.properties[key], value[key]);
|
|
19
21
|
}
|
|
20
22
|
// return if not additional properties
|