typebox 1.2.19 → 1.3.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/build/compile/validator.d.mts +2 -7
- package/build/compile/validator.mjs +6 -36
- package/build/error/errors.d.mts +1 -7
- package/build/guard/emit.d.mts +0 -4
- package/build/guard/emit.mjs +0 -8
- package/build/guard/guard.d.mts +0 -4
- package/build/guard/guard.mjs +0 -8
- package/build/schema/engine/index.d.mts +0 -1
- package/build/schema/engine/index.mjs +0 -1
- package/build/schema/engine/schema.mjs +0 -5
- package/build/schema/engine/type.mjs +14 -18
- package/build/schema/types/index.d.mts +0 -1
- package/build/schema/types/index.mjs +0 -1
- package/build/system/locale/ar_001.mjs +0 -1
- package/build/system/locale/bn_BD.mjs +0 -1
- package/build/system/locale/cs_CZ.mjs +0 -1
- package/build/system/locale/de_DE.mjs +0 -1
- package/build/system/locale/el_GR.mjs +0 -1
- package/build/system/locale/en_US.mjs +0 -1
- package/build/system/locale/es_419.mjs +0 -1
- package/build/system/locale/es_AR.mjs +0 -1
- package/build/system/locale/es_ES.mjs +0 -1
- package/build/system/locale/es_MX.mjs +0 -1
- package/build/system/locale/fa_IR.mjs +0 -1
- package/build/system/locale/fil_PH.mjs +0 -1
- package/build/system/locale/fr_CA.mjs +0 -1
- package/build/system/locale/fr_FR.mjs +0 -1
- package/build/system/locale/ha_NG.mjs +0 -1
- package/build/system/locale/hi_IN.mjs +0 -1
- package/build/system/locale/hu_HU.mjs +0 -1
- package/build/system/locale/id_ID.mjs +0 -1
- package/build/system/locale/it_IT.mjs +0 -1
- package/build/system/locale/ja_JP.mjs +0 -1
- package/build/system/locale/ko_KR.mjs +0 -1
- package/build/system/locale/ms_MY.mjs +0 -1
- package/build/system/locale/nl_NL.mjs +0 -1
- package/build/system/locale/pl_PL.mjs +0 -1
- package/build/system/locale/pt_BR.mjs +0 -1
- package/build/system/locale/pt_PT.mjs +0 -1
- package/build/system/locale/ro_RO.mjs +0 -1
- package/build/system/locale/ru_RU.mjs +0 -1
- package/build/system/locale/sv_SE.mjs +0 -1
- package/build/system/locale/sw_TZ.mjs +0 -1
- package/build/system/locale/th_TH.mjs +0 -1
- package/build/system/locale/tr_TR.mjs +0 -1
- package/build/system/locale/uk_UA.mjs +0 -1
- package/build/system/locale/ur_PK.mjs +0 -1
- package/build/system/locale/vi_VN.mjs +0 -1
- package/build/system/locale/yo_NG.mjs +0 -1
- package/build/system/locale/zh_Hans.mjs +0 -1
- package/build/system/locale/zh_Hant.mjs +0 -1
- package/build/system/memory/clone.d.mts +2 -3
- package/build/system/memory/clone.mjs +72 -26
- package/build/type/action/index.d.mts +0 -1
- package/build/type/action/index.mjs +0 -1
- package/build/type/action/readonly_object.d.mts +0 -5
- package/build/type/action/readonly_object.mjs +0 -5
- package/build/type/action/with.d.mts +0 -10
- package/build/type/action/with.mjs +0 -8
- package/build/type/engine/cyclic/check.d.mts +1 -4
- package/build/type/engine/cyclic/check.mjs +9 -15
- package/build/type/engine/cyclic/dependencies.d.mts +1 -4
- package/build/type/engine/cyclic/dependencies.mjs +9 -15
- package/build/type/engine/cyclic/extends.d.mts +1 -4
- package/build/type/engine/cyclic/extends.mjs +8 -14
- package/build/type/engine/index.d.mts +0 -1
- package/build/type/engine/index.mjs +0 -1
- package/build/type/engine/instantiate.d.mts +1 -8
- package/build/type/engine/instantiate.mjs +38 -46
- package/build/type/engine/this/expand_this.d.mts +1 -4
- package/build/type/engine/this/expand_this.mjs +7 -13
- package/build/type/extends/extends_left.d.mts +1 -7
- package/build/type/extends/extends_left.mjs +23 -32
- package/build/type/script/mapping.d.mts +0 -12
- package/build/type/script/mapping.mjs +21 -25
- package/build/type/types/_refine.d.mts +0 -2
- package/build/type/types/_refine.mjs +1 -2
- package/build/type/types/index.d.mts +0 -4
- package/build/type/types/index.mjs +0 -4
- package/build/type/types/static.d.mts +1 -5
- package/build/typebox.d.mts +2 -7
- package/build/typebox.mjs +2 -7
- package/build/value/clean/from_type.mjs +8 -10
- package/build/value/clone/clone.mjs +1 -86
- package/build/value/convert/from_type.mjs +19 -21
- package/build/value/create/from_type.mjs +23 -31
- package/build/value/default/from_type.mjs +8 -10
- package/build/value/index.d.mts +0 -1
- package/build/value/index.mjs +0 -1
- package/build/value/repair/from_type.mjs +2 -12
- package/build/value/value.d.mts +0 -1
- package/build/value/value.mjs +0 -1
- package/package.json +1 -1
- package/readme.md +1 -1
- package/build/schema/engine/_guard.d.mts +0 -6
- package/build/schema/engine/_guard.mjs +0 -26
- package/build/schema/types/_guard.d.mts +0 -10
- package/build/schema/types/_guard.mjs +0 -16
- package/build/type/action/awaited.d.mts +0 -15
- package/build/type/action/awaited.mjs +0 -15
- package/build/type/engine/awaited/index.d.mts +0 -1
- package/build/type/engine/awaited/index.mjs +0 -1
- package/build/type/engine/awaited/instantiate.d.mts +0 -11
- package/build/type/engine/awaited/instantiate.mjs +0 -20
- package/build/type/extends/async_iterator.d.mts +0 -7
- package/build/type/extends/async_iterator.mjs +0 -9
- package/build/type/extends/iterator.d.mts +0 -7
- package/build/type/extends/iterator.mjs +0 -9
- package/build/type/extends/promise.d.mts +0 -7
- package/build/type/extends/promise.mjs +0 -9
- package/build/type/types/async_iterator.d.mts +0 -20
- package/build/type/types/async_iterator.mjs +0 -28
- package/build/type/types/base.d.mts +0 -50
- package/build/type/types/base.mjs +0 -84
- package/build/type/types/iterator.d.mts +0 -20
- package/build/type/types/iterator.mjs +0 -28
- package/build/type/types/promise.d.mts +0 -21
- package/build/type/types/promise.mjs +0 -29
- package/build/value/clean/from_base.d.mts +0 -2
- package/build/value/clean/from_base.mjs +0 -4
- package/build/value/convert/from_base.d.mts +0 -2
- package/build/value/convert/from_base.mjs +0 -4
- package/build/value/create/from_async_iterator.d.mts +0 -2
- package/build/value/create/from_async_iterator.mjs +0 -5
- package/build/value/create/from_base.d.mts +0 -2
- package/build/value/create/from_base.mjs +0 -4
- package/build/value/create/from_iterator.d.mts +0 -2
- package/build/value/create/from_iterator.mjs +0 -5
- package/build/value/create/from_promise.d.mts +0 -2
- package/build/value/create/from_promise.mjs +0 -5
- package/build/value/default/from_base.d.mts +0 -2
- package/build/value/default/from_base.mjs +0 -5
- package/build/value/mutate/error.d.mts +0 -3
- package/build/value/mutate/error.mjs +0 -6
- package/build/value/mutate/from_array.d.mts +0 -2
- package/build/value/mutate/from_array.mjs +0 -16
- package/build/value/mutate/from_object.d.mts +0 -2
- package/build/value/mutate/from_object.mjs +0 -40
- package/build/value/mutate/from_unknown.d.mts +0 -2
- package/build/value/mutate/from_unknown.mjs +0 -7
- package/build/value/mutate/from_value.d.mts +0 -2
- package/build/value/mutate/from_value.mjs +0 -12
- package/build/value/mutate/index.d.mts +0 -1
- package/build/value/mutate/index.mjs +0 -1
- package/build/value/mutate/mutate.d.mts +0 -11
- package/build/value/mutate/mutate.mjs +0 -41
- package/build/value/repair/from_base.d.mts +0 -2
- package/build/value/repair/from_base.mjs +0 -8
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
import { Memory } from '../../../system/memory/index.mjs';
|
|
3
|
-
import { IsPromise } from '../../types/promise.mjs';
|
|
4
|
-
import { AwaitedDeferred } from '../../action/awaited.mjs';
|
|
5
|
-
import { InstantiateType, CanInstantiate } from '../instantiate.mjs';
|
|
6
|
-
function AwaitedOperation(type) {
|
|
7
|
-
return (IsPromise(type)
|
|
8
|
-
? AwaitedOperation(type.item)
|
|
9
|
-
: type);
|
|
10
|
-
}
|
|
11
|
-
export function AwaitedAction(type, options) {
|
|
12
|
-
const result = CanInstantiate([type])
|
|
13
|
-
? Memory.Update(AwaitedOperation(type), {}, options)
|
|
14
|
-
: AwaitedDeferred(type, options);
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
17
|
-
export function AwaitedInstantiate(context, state, type, options) {
|
|
18
|
-
const instantiatedType = InstantiateType(context, state, type);
|
|
19
|
-
return AwaitedAction(instantiatedType, options);
|
|
20
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type TSchema } from '../types/schema.mjs';
|
|
2
|
-
import { type TProperties } from '../types/properties.mjs';
|
|
3
|
-
import { type TAsyncIterator } from '../types/async_iterator.mjs';
|
|
4
|
-
import { type TExtendsRight } from './extends_right.mjs';
|
|
5
|
-
import { type TExtendsLeft } from './extends_left.mjs';
|
|
6
|
-
export type TExtendsAsyncIterator<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Right extends TAsyncIterator<infer Type extends TSchema> ? TExtendsLeft<Inferred, Left, Type> : TExtendsRight<Inferred, TAsyncIterator<Left>, Right>);
|
|
7
|
-
export declare function ExtendsAsyncIterator<Inferred extends TProperties, Left extends TSchema, Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtendsAsyncIterator<Inferred, Left, Right>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
import { AsyncIterator, IsAsyncIterator } from '../types/async_iterator.mjs';
|
|
3
|
-
import { ExtendsRight } from './extends_right.mjs';
|
|
4
|
-
import { ExtendsLeft } from './extends_left.mjs';
|
|
5
|
-
export function ExtendsAsyncIterator(inferred, left, right) {
|
|
6
|
-
return (IsAsyncIterator(right)
|
|
7
|
-
? ExtendsLeft(inferred, left, right.iteratorItems)
|
|
8
|
-
: ExtendsRight(inferred, AsyncIterator(left), right));
|
|
9
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type TSchema } from '../types/schema.mjs';
|
|
2
|
-
import { type TProperties } from '../types/properties.mjs';
|
|
3
|
-
import { type TIterator } from '../types/iterator.mjs';
|
|
4
|
-
import { type TExtendsRight } from './extends_right.mjs';
|
|
5
|
-
import { type TExtendsLeft } from './extends_left.mjs';
|
|
6
|
-
export type TExtendsIterator<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Right extends TIterator<infer Type extends TSchema> ? TExtendsLeft<Inferred, Left, Type> : TExtendsRight<Inferred, TIterator<Left>, Right>);
|
|
7
|
-
export declare function ExtendsIterator<Inferred extends TProperties, Left extends TSchema, Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtendsIterator<Inferred, Left, Right>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
import { Iterator, IsIterator } from '../types/iterator.mjs';
|
|
3
|
-
import { ExtendsRight } from './extends_right.mjs';
|
|
4
|
-
import { ExtendsLeft } from './extends_left.mjs';
|
|
5
|
-
export function ExtendsIterator(inferred, left, right) {
|
|
6
|
-
return (IsIterator(right)
|
|
7
|
-
? ExtendsLeft(inferred, left, right.iteratorItems)
|
|
8
|
-
: ExtendsRight(inferred, Iterator(left), right));
|
|
9
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type TSchema } from '../types/schema.mjs';
|
|
2
|
-
import { type TProperties } from '../types/properties.mjs';
|
|
3
|
-
import { type TPromise } from '../types/promise.mjs';
|
|
4
|
-
import { type TExtendsRight } from './extends_right.mjs';
|
|
5
|
-
import { type TExtendsLeft } from './extends_left.mjs';
|
|
6
|
-
export type TExtendsPromise<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Right extends TPromise<infer Type extends TSchema> ? TExtendsLeft<Inferred, Left, Type> : TExtendsRight<Inferred, TPromise<Left>, Right>);
|
|
7
|
-
export declare function ExtendsPromise<Inferred extends TProperties, Left extends TSchema, Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtendsPromise<Inferred, Left, Right>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
import { Promise, IsPromise } from '../types/promise.mjs';
|
|
3
|
-
import { ExtendsRight } from './extends_right.mjs';
|
|
4
|
-
import { ExtendsLeft } from './extends_left.mjs';
|
|
5
|
-
export function ExtendsPromise(inferred, left, right) {
|
|
6
|
-
return (IsPromise(right)
|
|
7
|
-
? ExtendsLeft(inferred, left, right.item)
|
|
8
|
-
: ExtendsRight(inferred, Promise(left), right));
|
|
9
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type StaticType, type StaticDirection } from './static.mjs';
|
|
2
|
-
import { type TSchema, type TSchemaOptions } from './schema.mjs';
|
|
3
|
-
import { type TProperties } from './properties.mjs';
|
|
4
|
-
export type StaticAsyncIterator<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = AsyncIterableIterator<StaticType<Stack, Direction, Context, This, Type>>> = Result;
|
|
5
|
-
/** Represents a AsyncIterator. */
|
|
6
|
-
export interface TAsyncIterator<Type extends TSchema = TSchema> extends TSchema {
|
|
7
|
-
'~kind': 'AsyncIterator';
|
|
8
|
-
type: 'asyncIterator';
|
|
9
|
-
iteratorItems: Type;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Creates a AsyncIterator type.
|
|
13
|
-
*
|
|
14
|
-
* @deprecated This type is being removed in the next version of TypeBox. A fallback will be provided under examples.
|
|
15
|
-
*/
|
|
16
|
-
export declare function AsyncIterator<Type extends TSchema>(iteratorItems: Type, options?: TSchemaOptions): TAsyncIterator<Type>;
|
|
17
|
-
/** Returns true if the given value is a TAsyncIterator */
|
|
18
|
-
export declare function IsAsyncIterator(value: unknown): value is TAsyncIterator;
|
|
19
|
-
/** Extracts options from a TAsyncIterator. */
|
|
20
|
-
export declare function AsyncIteratorOptions(type: TAsyncIterator): TSchemaOptions;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
import { Memory } from '../../system/memory/index.mjs';
|
|
3
|
-
import { IsKind } from './schema.mjs';
|
|
4
|
-
// ------------------------------------------------------------------
|
|
5
|
-
// Factory
|
|
6
|
-
// ------------------------------------------------------------------
|
|
7
|
-
/**
|
|
8
|
-
* Creates a AsyncIterator type.
|
|
9
|
-
*
|
|
10
|
-
* @deprecated This type is being removed in the next version of TypeBox. A fallback will be provided under examples.
|
|
11
|
-
*/
|
|
12
|
-
export function AsyncIterator(iteratorItems, options) {
|
|
13
|
-
return Memory.Create({ '~kind': 'AsyncIterator' }, { type: 'asyncIterator', iteratorItems }, options);
|
|
14
|
-
}
|
|
15
|
-
// ------------------------------------------------------------------
|
|
16
|
-
// Guard
|
|
17
|
-
// ------------------------------------------------------------------
|
|
18
|
-
/** Returns true if the given value is a TAsyncIterator */
|
|
19
|
-
export function IsAsyncIterator(value) {
|
|
20
|
-
return IsKind(value, 'AsyncIterator');
|
|
21
|
-
}
|
|
22
|
-
// ------------------------------------------------------------------
|
|
23
|
-
// Options
|
|
24
|
-
// ------------------------------------------------------------------
|
|
25
|
-
/** Extracts options from a TAsyncIterator. */
|
|
26
|
-
export function AsyncIteratorOptions(type) {
|
|
27
|
-
return Memory.Discard(type, ['~kind', 'type', 'iteratorItems']);
|
|
28
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { type TSchema } from './schema.mjs';
|
|
2
|
-
import { type XGuard, type XGuardInterface } from '../../schema/types/index.mjs';
|
|
3
|
-
export type StaticBase<Value extends unknown> = Value;
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated Use Type.Refine() + Type.Unsafe() instead.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* **Reason:** It is noted that JavaScript class instances do not behave like
|
|
9
|
-
* plain objects during structural clone or when the TB compositor needs to
|
|
10
|
-
* assign dynamic modifier properties (such as '~optional').
|
|
11
|
-
*
|
|
12
|
-
* Because the TypeBox compositor needs to transform schematics via object clone /
|
|
13
|
-
* property spread, these operations can result in class instance types losing
|
|
14
|
-
* methods on the prototype (via clone), which can lead to unexpected structures being
|
|
15
|
-
* returned. This has led to special-case (non-clone) handling for Base which needs
|
|
16
|
-
* to be removed as it has proven orthogonal to the TypeBox 1.x design.
|
|
17
|
-
*
|
|
18
|
-
* The Base type was introduced in 1.x to try integrate / embed Standard Schema into JSON
|
|
19
|
-
* Schema; however, support for integrated Standard Schema embedding will not be continued
|
|
20
|
-
* in TypeBox. This type will be removed in the next minor revision of TypeBox.
|
|
21
|
-
*
|
|
22
|
-
* ```typescript
|
|
23
|
-
* // (Deprecated)
|
|
24
|
-
* class DateType extends Type.Base<Date> { Check(value) { return value instanceof Date } }
|
|
25
|
-
*
|
|
26
|
-
* // (Future)
|
|
27
|
-
* const DateType = Type.Refine(Type.Unsafe<Date>({}), value => value instanceof Date)
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export declare class Base<Value extends unknown = unknown> implements TSchema, XGuard<Value> {
|
|
31
|
-
readonly '~kind': 'Base';
|
|
32
|
-
readonly '~guard': XGuardInterface<Value>;
|
|
33
|
-
constructor();
|
|
34
|
-
/** Checks a value or returns false if invalid */
|
|
35
|
-
Check(_value: unknown): _value is Value;
|
|
36
|
-
/** Returns errors for a value. Return an empty array if valid. */
|
|
37
|
-
Errors(_value: unknown): object[];
|
|
38
|
-
/** Converts a value into this type */
|
|
39
|
-
Convert(value: unknown): unknown;
|
|
40
|
-
/** Cleans a value according to this type */
|
|
41
|
-
Clean(value: unknown): unknown;
|
|
42
|
-
/** Returns a default value for this type */
|
|
43
|
-
Default(value: unknown): unknown;
|
|
44
|
-
/** Creates a new instance of this type */
|
|
45
|
-
Create(): Value;
|
|
46
|
-
/** Clones this type */
|
|
47
|
-
Clone(): Base;
|
|
48
|
-
}
|
|
49
|
-
/** Returns true if the given value is a Base type. */
|
|
50
|
-
export declare function IsBase(value: unknown): value is Base;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
import { Settings } from '../../system/settings/index.mjs';
|
|
3
|
-
import { IsKind } from './schema.mjs';
|
|
4
|
-
// ------------------------------------------------------------------
|
|
5
|
-
// Type.Base<...>
|
|
6
|
-
// ------------------------------------------------------------------
|
|
7
|
-
function BaseProperty(value) {
|
|
8
|
-
return {
|
|
9
|
-
enumerable: Settings.Get().enumerableKind,
|
|
10
|
-
writable: false,
|
|
11
|
-
configurable: false,
|
|
12
|
-
value
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* @deprecated Use Type.Refine() + Type.Unsafe() instead.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* **Reason:** It is noted that JavaScript class instances do not behave like
|
|
20
|
-
* plain objects during structural clone or when the TB compositor needs to
|
|
21
|
-
* assign dynamic modifier properties (such as '~optional').
|
|
22
|
-
*
|
|
23
|
-
* Because the TypeBox compositor needs to transform schematics via object clone /
|
|
24
|
-
* property spread, these operations can result in class instance types losing
|
|
25
|
-
* methods on the prototype (via clone), which can lead to unexpected structures being
|
|
26
|
-
* returned. This has led to special-case (non-clone) handling for Base which needs
|
|
27
|
-
* to be removed as it has proven orthogonal to the TypeBox 1.x design.
|
|
28
|
-
*
|
|
29
|
-
* The Base type was introduced in 1.x to try integrate / embed Standard Schema into JSON
|
|
30
|
-
* Schema; however, support for integrated Standard Schema embedding will not be continued
|
|
31
|
-
* in TypeBox. This type will be removed in the next minor revision of TypeBox.
|
|
32
|
-
*
|
|
33
|
-
* ```typescript
|
|
34
|
-
* // (Deprecated)
|
|
35
|
-
* class DateType extends Type.Base<Date> { Check(value) { return value instanceof Date } }
|
|
36
|
-
*
|
|
37
|
-
* // (Future)
|
|
38
|
-
* const DateType = Type.Refine(Type.Unsafe<Date>({}), value => value instanceof Date)
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export class Base {
|
|
42
|
-
constructor() {
|
|
43
|
-
globalThis.Object.defineProperty(this, '~kind', BaseProperty('Base'));
|
|
44
|
-
globalThis.Object.defineProperty(this, '~guard', BaseProperty({
|
|
45
|
-
check: (value) => this.Check(value),
|
|
46
|
-
errors: (value) => this.Errors(value)
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
/** Checks a value or returns false if invalid */
|
|
50
|
-
Check(_value) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
/** Returns errors for a value. Return an empty array if valid. */
|
|
54
|
-
Errors(_value) {
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
/** Converts a value into this type */
|
|
58
|
-
Convert(value) {
|
|
59
|
-
return value;
|
|
60
|
-
}
|
|
61
|
-
/** Cleans a value according to this type */
|
|
62
|
-
Clean(value) {
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
/** Returns a default value for this type */
|
|
66
|
-
Default(value) {
|
|
67
|
-
return value;
|
|
68
|
-
}
|
|
69
|
-
/** Creates a new instance of this type */
|
|
70
|
-
Create() {
|
|
71
|
-
throw new Error('Create not implemented');
|
|
72
|
-
}
|
|
73
|
-
/** Clones this type */
|
|
74
|
-
Clone() {
|
|
75
|
-
throw Error('Clone not implemented');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
// ------------------------------------------------------------------
|
|
79
|
-
// Guard
|
|
80
|
-
// ------------------------------------------------------------------
|
|
81
|
-
/** Returns true if the given value is a Base type. */
|
|
82
|
-
export function IsBase(value) {
|
|
83
|
-
return IsKind(value, 'Base');
|
|
84
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type StaticType, type StaticDirection } from './static.mjs';
|
|
2
|
-
import { type TSchema, type TSchemaOptions } from './schema.mjs';
|
|
3
|
-
import { type TProperties } from './properties.mjs';
|
|
4
|
-
export type StaticIterator<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = IterableIterator<StaticType<Stack, Direction, Context, This, Type>>> = Result;
|
|
5
|
-
/** Represents an Iterator. */
|
|
6
|
-
export interface TIterator<Type extends TSchema = TSchema> extends TSchema {
|
|
7
|
-
'~kind': 'Iterator';
|
|
8
|
-
type: 'iterator';
|
|
9
|
-
iteratorItems: Type;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Creates a Iterator type.
|
|
13
|
-
*
|
|
14
|
-
* @deprecated This type is being removed in the next version of TypeBox. A fallback will be provided under examples.
|
|
15
|
-
*/
|
|
16
|
-
export declare function Iterator<Type extends TSchema>(iteratorItems: Type, options?: TSchemaOptions): TIterator<Type>;
|
|
17
|
-
/** Returns true if the given value is TIterator. */
|
|
18
|
-
export declare function IsIterator(value: unknown): value is TIterator;
|
|
19
|
-
/** Extracts options from a TIterator. */
|
|
20
|
-
export declare function IteratorOptions(type: TIterator): TSchemaOptions;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
import { Memory } from '../../system/memory/index.mjs';
|
|
3
|
-
import { IsKind } from './schema.mjs';
|
|
4
|
-
// ------------------------------------------------------------------
|
|
5
|
-
// Factory
|
|
6
|
-
// ------------------------------------------------------------------
|
|
7
|
-
/**
|
|
8
|
-
* Creates a Iterator type.
|
|
9
|
-
*
|
|
10
|
-
* @deprecated This type is being removed in the next version of TypeBox. A fallback will be provided under examples.
|
|
11
|
-
*/
|
|
12
|
-
export function Iterator(iteratorItems, options) {
|
|
13
|
-
return Memory.Create({ '~kind': 'Iterator' }, { type: 'iterator', iteratorItems }, options);
|
|
14
|
-
}
|
|
15
|
-
// ------------------------------------------------------------------
|
|
16
|
-
// Guard
|
|
17
|
-
// ------------------------------------------------------------------
|
|
18
|
-
/** Returns true if the given value is TIterator. */
|
|
19
|
-
export function IsIterator(value) {
|
|
20
|
-
return IsKind(value, 'Iterator');
|
|
21
|
-
}
|
|
22
|
-
// ------------------------------------------------------------------
|
|
23
|
-
// Options
|
|
24
|
-
// ------------------------------------------------------------------
|
|
25
|
-
/** Extracts options from a TIterator. */
|
|
26
|
-
export function IteratorOptions(type) {
|
|
27
|
-
return Memory.Discard(type, ['~kind', 'type', 'iteratorItems']);
|
|
28
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type StaticType, type StaticDirection } from './static.mjs';
|
|
2
|
-
import { type TSchema, type TSchemaOptions } from './schema.mjs';
|
|
3
|
-
import { type TProperties } from './properties.mjs';
|
|
4
|
-
export type StaticPromise<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = Promise<StaticType<Stack, Direction, Context, This, Type>>> = Result;
|
|
5
|
-
/** Represents a Promise type. */
|
|
6
|
-
export interface TPromise<Type extends TSchema = TSchema> extends TSchema {
|
|
7
|
-
'~kind': 'Promise';
|
|
8
|
-
type: 'promise';
|
|
9
|
-
item: Type;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Creates a Promise type.
|
|
13
|
-
*
|
|
14
|
-
* @deprecated This type is being removed in the next version of TypeBox. A fallback will be provided under examples.
|
|
15
|
-
*/
|
|
16
|
-
export declare function _Promise_<Type extends TSchema>(item: Type, options?: TSchemaOptions): TPromise<Type>;
|
|
17
|
-
export { _Promise_ as Promise };
|
|
18
|
-
/** Returns true if the given type is TPromise. */
|
|
19
|
-
export declare function IsPromise(value: unknown): value is TPromise;
|
|
20
|
-
/** Extracts options from a TPromise. */
|
|
21
|
-
export declare function PromiseOptions(type: TPromise): TSchemaOptions;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
import { Memory } from '../../system/memory/index.mjs';
|
|
3
|
-
import { IsKind } from './schema.mjs';
|
|
4
|
-
// ------------------------------------------------------------------
|
|
5
|
-
// Factory
|
|
6
|
-
// ------------------------------------------------------------------
|
|
7
|
-
/**
|
|
8
|
-
* Creates a Promise type.
|
|
9
|
-
*
|
|
10
|
-
* @deprecated This type is being removed in the next version of TypeBox. A fallback will be provided under examples.
|
|
11
|
-
*/
|
|
12
|
-
export function _Promise_(item, options) {
|
|
13
|
-
return Memory.Create({ ['~kind']: 'Promise' }, { type: 'promise', item }, options);
|
|
14
|
-
}
|
|
15
|
-
export { _Promise_ as Promise };
|
|
16
|
-
// ------------------------------------------------------------------
|
|
17
|
-
// Guard
|
|
18
|
-
// ------------------------------------------------------------------
|
|
19
|
-
/** Returns true if the given type is TPromise. */
|
|
20
|
-
export function IsPromise(value) {
|
|
21
|
-
return IsKind(value, 'Promise');
|
|
22
|
-
}
|
|
23
|
-
// ------------------------------------------------------------------
|
|
24
|
-
// Options
|
|
25
|
-
// ------------------------------------------------------------------
|
|
26
|
-
/** Extracts options from a TPromise. */
|
|
27
|
-
export function PromiseOptions(type) {
|
|
28
|
-
return Memory.Discard(type, ['~kind', 'type', 'item']);
|
|
29
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
import { Guard } from '../../guard/index.mjs';
|
|
3
|
-
import { Clone } from '../clone/index.mjs';
|
|
4
|
-
import { Pointer } from '../pointer/index.mjs';
|
|
5
|
-
import { FromValue } from './from_value.mjs';
|
|
6
|
-
export function FromArray(root, path, current, next) {
|
|
7
|
-
if (!Guard.IsArray(current)) {
|
|
8
|
-
Pointer.Set(root, path, Clone(next));
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
for (let index = 0; index < next.length; index++) {
|
|
12
|
-
FromValue(root, `${path}/${index}`, current[index], next[index]);
|
|
13
|
-
}
|
|
14
|
-
current.splice(next.length);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
import { Guard } from '../../guard/index.mjs';
|
|
3
|
-
import { Pointer } from '../pointer/index.mjs';
|
|
4
|
-
import { Clone } from '../clone/index.mjs';
|
|
5
|
-
import { FromValue } from './from_value.mjs';
|
|
6
|
-
// ------------------------------------------------------------------
|
|
7
|
-
// AssertKey
|
|
8
|
-
// ------------------------------------------------------------------
|
|
9
|
-
function AssertKey(key) {
|
|
10
|
-
if (Guard.IsUnsafePropertyKey(key))
|
|
11
|
-
throw Error('Attempted to Mutate with unsafe property key');
|
|
12
|
-
}
|
|
13
|
-
// ------------------------------------------------------------------
|
|
14
|
-
// AssertKey
|
|
15
|
-
// ------------------------------------------------------------------
|
|
16
|
-
export function FromObject(root, path, current, next) {
|
|
17
|
-
if (!Guard.IsObjectNotArray(current)) {
|
|
18
|
-
Pointer.Set(root, path, Clone(next));
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
const currentKeys = Guard.Keys(current);
|
|
22
|
-
const nextKeys = Guard.Keys(next);
|
|
23
|
-
for (const currentKey of currentKeys) {
|
|
24
|
-
AssertKey(currentKey);
|
|
25
|
-
if (!nextKeys.includes(currentKey)) {
|
|
26
|
-
delete current[currentKey];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
for (const nextKey of nextKeys) {
|
|
30
|
-
AssertKey(nextKey);
|
|
31
|
-
if (!currentKeys.includes(nextKey)) {
|
|
32
|
-
current[nextKey] = next[nextKey];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
for (const nextKey of nextKeys) {
|
|
36
|
-
AssertKey(nextKey);
|
|
37
|
-
FromValue(root, `${path}/${nextKey}`, current[nextKey], next[nextKey]);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
import { Guard } from '../../guard/index.mjs';
|
|
3
|
-
import { FromArray } from './from_array.mjs';
|
|
4
|
-
import { FromObject } from './from_object.mjs';
|
|
5
|
-
import { FromUnknown } from './from_unknown.mjs';
|
|
6
|
-
export function FromValue(root, path, current, next) {
|
|
7
|
-
if (Guard.IsArray(next))
|
|
8
|
-
return FromArray(root, path, current, next);
|
|
9
|
-
if (Guard.IsObject(next))
|
|
10
|
-
return FromObject(root, path, current, next);
|
|
11
|
-
return FromUnknown(root, path, current, next);
|
|
12
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './mutate.mjs';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './mutate.mjs';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type TMutable = {
|
|
2
|
-
[key: string]: unknown;
|
|
3
|
-
} | unknown[];
|
|
4
|
-
/**
|
|
5
|
-
* Performs a deep structural assignment, applying values from next to current while retaining internal references. This function
|
|
6
|
-
* is written for use in infrastructure that interprets reference changes as a signal to perform some action (i.e. React redraw), this
|
|
7
|
-
* function can mitigate this by applying mutable updates deep within a value, ensuring parent references are retained.
|
|
8
|
-
*
|
|
9
|
-
* @deprecated This function is being removed in the next version but will be retained as a reference under examples.
|
|
10
|
-
*/
|
|
11
|
-
export declare function Mutate(current: TMutable, next: TMutable): void;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// deno-fmt-ignore-file
|
|
2
|
-
import { Guard, GlobalsGuard } from '../../guard/index.mjs';
|
|
3
|
-
import { MutateError } from './error.mjs';
|
|
4
|
-
import { FromValue } from './from_value.mjs';
|
|
5
|
-
// ------------------------------------------------------------------
|
|
6
|
-
// IsNonMutableValue
|
|
7
|
-
// ------------------------------------------------------------------
|
|
8
|
-
function IsNonMutableValue(value) {
|
|
9
|
-
return GlobalsGuard.IsTypeArray(value)
|
|
10
|
-
|| GlobalsGuard.IsDate(value)
|
|
11
|
-
|| GlobalsGuard.IsMap(value)
|
|
12
|
-
|| GlobalsGuard.IsSet(value)
|
|
13
|
-
|| Guard.IsNumber(value)
|
|
14
|
-
|| Guard.IsString(value)
|
|
15
|
-
|| Guard.IsBoolean(value)
|
|
16
|
-
|| Guard.IsSymbol(value);
|
|
17
|
-
}
|
|
18
|
-
// ------------------------------------------------------------------
|
|
19
|
-
// IsTrueObject
|
|
20
|
-
// ------------------------------------------------------------------
|
|
21
|
-
function IsMismatchedValue(left, right) {
|
|
22
|
-
return ((Guard.IsObjectNotArray(left) && Guard.IsArray(right)) ||
|
|
23
|
-
(Guard.IsArray(left) && Guard.IsObjectNotArray(right)));
|
|
24
|
-
}
|
|
25
|
-
// ------------------------------------------------------------------
|
|
26
|
-
// Mutate
|
|
27
|
-
// ------------------------------------------------------------------
|
|
28
|
-
/**
|
|
29
|
-
* Performs a deep structural assignment, applying values from next to current while retaining internal references. This function
|
|
30
|
-
* is written for use in infrastructure that interprets reference changes as a signal to perform some action (i.e. React redraw), this
|
|
31
|
-
* function can mitigate this by applying mutable updates deep within a value, ensuring parent references are retained.
|
|
32
|
-
*
|
|
33
|
-
* @deprecated This function is being removed in the next version but will be retained as a reference under examples.
|
|
34
|
-
*/
|
|
35
|
-
export function Mutate(current, next) {
|
|
36
|
-
if (IsNonMutableValue(current) || IsNonMutableValue(next))
|
|
37
|
-
throw new MutateError('Only object and array types can be mutated at the root level');
|
|
38
|
-
if (IsMismatchedValue(current, next))
|
|
39
|
-
throw new MutateError('Cannot assign due type mismatch of assignable values');
|
|
40
|
-
FromValue(current, '', current, next);
|
|
41
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
}
|