typebox 1.2.19 → 1.3.1

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.
Files changed (149) hide show
  1. package/build/compile/validator.d.mts +2 -7
  2. package/build/compile/validator.mjs +6 -36
  3. package/build/error/errors.d.mts +1 -7
  4. package/build/format/_idna.mjs +11 -3
  5. package/build/guard/emit.d.mts +0 -4
  6. package/build/guard/emit.mjs +0 -8
  7. package/build/guard/guard.d.mts +0 -4
  8. package/build/guard/guard.mjs +0 -8
  9. package/build/schema/engine/index.d.mts +0 -1
  10. package/build/schema/engine/index.mjs +0 -1
  11. package/build/schema/engine/schema.mjs +0 -5
  12. package/build/schema/engine/type.mjs +14 -18
  13. package/build/schema/types/index.d.mts +0 -1
  14. package/build/schema/types/index.mjs +0 -1
  15. package/build/system/locale/ar_001.mjs +0 -1
  16. package/build/system/locale/bn_BD.mjs +0 -1
  17. package/build/system/locale/cs_CZ.mjs +0 -1
  18. package/build/system/locale/de_DE.mjs +0 -1
  19. package/build/system/locale/el_GR.mjs +0 -1
  20. package/build/system/locale/en_US.mjs +0 -1
  21. package/build/system/locale/es_419.mjs +0 -1
  22. package/build/system/locale/es_AR.mjs +0 -1
  23. package/build/system/locale/es_ES.mjs +0 -1
  24. package/build/system/locale/es_MX.mjs +0 -1
  25. package/build/system/locale/fa_IR.mjs +0 -1
  26. package/build/system/locale/fil_PH.mjs +0 -1
  27. package/build/system/locale/fr_CA.mjs +0 -1
  28. package/build/system/locale/fr_FR.mjs +0 -1
  29. package/build/system/locale/ha_NG.mjs +0 -1
  30. package/build/system/locale/hi_IN.mjs +0 -1
  31. package/build/system/locale/hu_HU.mjs +0 -1
  32. package/build/system/locale/id_ID.mjs +0 -1
  33. package/build/system/locale/it_IT.mjs +0 -1
  34. package/build/system/locale/ja_JP.mjs +0 -1
  35. package/build/system/locale/ko_KR.mjs +0 -1
  36. package/build/system/locale/ms_MY.mjs +0 -1
  37. package/build/system/locale/nl_NL.mjs +0 -1
  38. package/build/system/locale/pl_PL.mjs +0 -1
  39. package/build/system/locale/pt_BR.mjs +0 -1
  40. package/build/system/locale/pt_PT.mjs +0 -1
  41. package/build/system/locale/ro_RO.mjs +0 -1
  42. package/build/system/locale/ru_RU.mjs +0 -1
  43. package/build/system/locale/sv_SE.mjs +0 -1
  44. package/build/system/locale/sw_TZ.mjs +0 -1
  45. package/build/system/locale/th_TH.mjs +0 -1
  46. package/build/system/locale/tr_TR.mjs +0 -1
  47. package/build/system/locale/uk_UA.mjs +0 -1
  48. package/build/system/locale/ur_PK.mjs +0 -1
  49. package/build/system/locale/vi_VN.mjs +0 -1
  50. package/build/system/locale/yo_NG.mjs +0 -1
  51. package/build/system/locale/zh_Hans.mjs +0 -1
  52. package/build/system/locale/zh_Hant.mjs +0 -1
  53. package/build/system/memory/clone.d.mts +2 -3
  54. package/build/system/memory/clone.mjs +73 -26
  55. package/build/type/action/index.d.mts +0 -1
  56. package/build/type/action/index.mjs +0 -1
  57. package/build/type/action/readonly_object.d.mts +0 -5
  58. package/build/type/action/readonly_object.mjs +0 -5
  59. package/build/type/action/with.d.mts +0 -10
  60. package/build/type/action/with.mjs +0 -8
  61. package/build/type/engine/cyclic/check.d.mts +1 -4
  62. package/build/type/engine/cyclic/check.mjs +9 -15
  63. package/build/type/engine/cyclic/dependencies.d.mts +1 -4
  64. package/build/type/engine/cyclic/dependencies.mjs +9 -15
  65. package/build/type/engine/cyclic/extends.d.mts +1 -4
  66. package/build/type/engine/cyclic/extends.mjs +8 -14
  67. package/build/type/engine/index.d.mts +0 -1
  68. package/build/type/engine/index.mjs +0 -1
  69. package/build/type/engine/instantiate.d.mts +1 -8
  70. package/build/type/engine/instantiate.mjs +38 -46
  71. package/build/type/engine/this/expand_this.d.mts +1 -4
  72. package/build/type/engine/this/expand_this.mjs +7 -13
  73. package/build/type/extends/extends_left.d.mts +1 -7
  74. package/build/type/extends/extends_left.mjs +23 -32
  75. package/build/type/script/mapping.d.mts +0 -12
  76. package/build/type/script/mapping.mjs +21 -25
  77. package/build/type/types/_refine.d.mts +0 -2
  78. package/build/type/types/_refine.mjs +1 -2
  79. package/build/type/types/index.d.mts +0 -4
  80. package/build/type/types/index.mjs +0 -4
  81. package/build/type/types/static.d.mts +1 -5
  82. package/build/typebox.d.mts +2 -7
  83. package/build/typebox.mjs +2 -7
  84. package/build/value/clean/from_type.mjs +8 -10
  85. package/build/value/clone/clone.mjs +1 -86
  86. package/build/value/convert/from_type.mjs +19 -21
  87. package/build/value/create/from_type.mjs +23 -31
  88. package/build/value/default/from_type.mjs +8 -10
  89. package/build/value/index.d.mts +0 -1
  90. package/build/value/index.mjs +0 -1
  91. package/build/value/repair/from_type.mjs +2 -12
  92. package/build/value/value.d.mts +0 -1
  93. package/build/value/value.mjs +0 -1
  94. package/package.json +1 -1
  95. package/readme.md +8 -5
  96. package/build/schema/engine/_guard.d.mts +0 -6
  97. package/build/schema/engine/_guard.mjs +0 -26
  98. package/build/schema/types/_guard.d.mts +0 -10
  99. package/build/schema/types/_guard.mjs +0 -16
  100. package/build/type/action/awaited.d.mts +0 -15
  101. package/build/type/action/awaited.mjs +0 -15
  102. package/build/type/engine/awaited/index.d.mts +0 -1
  103. package/build/type/engine/awaited/index.mjs +0 -1
  104. package/build/type/engine/awaited/instantiate.d.mts +0 -11
  105. package/build/type/engine/awaited/instantiate.mjs +0 -20
  106. package/build/type/extends/async_iterator.d.mts +0 -7
  107. package/build/type/extends/async_iterator.mjs +0 -9
  108. package/build/type/extends/iterator.d.mts +0 -7
  109. package/build/type/extends/iterator.mjs +0 -9
  110. package/build/type/extends/promise.d.mts +0 -7
  111. package/build/type/extends/promise.mjs +0 -9
  112. package/build/type/types/async_iterator.d.mts +0 -20
  113. package/build/type/types/async_iterator.mjs +0 -28
  114. package/build/type/types/base.d.mts +0 -50
  115. package/build/type/types/base.mjs +0 -84
  116. package/build/type/types/iterator.d.mts +0 -20
  117. package/build/type/types/iterator.mjs +0 -28
  118. package/build/type/types/promise.d.mts +0 -21
  119. package/build/type/types/promise.mjs +0 -29
  120. package/build/value/clean/from_base.d.mts +0 -2
  121. package/build/value/clean/from_base.mjs +0 -4
  122. package/build/value/convert/from_base.d.mts +0 -2
  123. package/build/value/convert/from_base.mjs +0 -4
  124. package/build/value/create/from_async_iterator.d.mts +0 -2
  125. package/build/value/create/from_async_iterator.mjs +0 -5
  126. package/build/value/create/from_base.d.mts +0 -2
  127. package/build/value/create/from_base.mjs +0 -4
  128. package/build/value/create/from_iterator.d.mts +0 -2
  129. package/build/value/create/from_iterator.mjs +0 -5
  130. package/build/value/create/from_promise.d.mts +0 -2
  131. package/build/value/create/from_promise.mjs +0 -5
  132. package/build/value/default/from_base.d.mts +0 -2
  133. package/build/value/default/from_base.mjs +0 -5
  134. package/build/value/mutate/error.d.mts +0 -3
  135. package/build/value/mutate/error.mjs +0 -6
  136. package/build/value/mutate/from_array.d.mts +0 -2
  137. package/build/value/mutate/from_array.mjs +0 -16
  138. package/build/value/mutate/from_object.d.mts +0 -2
  139. package/build/value/mutate/from_object.mjs +0 -40
  140. package/build/value/mutate/from_unknown.d.mts +0 -2
  141. package/build/value/mutate/from_unknown.mjs +0 -7
  142. package/build/value/mutate/from_value.d.mts +0 -2
  143. package/build/value/mutate/from_value.mjs +0 -12
  144. package/build/value/mutate/index.d.mts +0 -1
  145. package/build/value/mutate/index.mjs +0 -1
  146. package/build/value/mutate/mutate.d.mts +0 -11
  147. package/build/value/mutate/mutate.mjs +0 -41
  148. package/build/value/repair/from_base.d.mts +0 -2
  149. package/build/value/repair/from_base.mjs +0 -8
@@ -1,11 +0,0 @@
1
- import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
2
- import { type TProperties } from '../../types/properties.mjs';
3
- import { type TPromise } from '../../types/promise.mjs';
4
- import { type TAwaitedDeferred } from '../../action/awaited.mjs';
5
- import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
6
- type TAwaitedOperation<Type extends TSchema> = (Type extends TPromise<infer Type extends TSchema> ? TAwaitedOperation<Type> : Type);
7
- export type TAwaitedAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TAwaitedOperation<Type> : TAwaitedDeferred<Type>> = Result;
8
- export declare function AwaitedAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TAwaitedAction<Type>;
9
- export type TAwaitedInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAwaitedAction<InstantiateType>;
10
- export declare function AwaitedInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TAwaitedInstantiate<Context, State, Type>;
11
- export {};
@@ -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,2 +0,0 @@
1
- import type { TProperties, Base } from '../../type/index.mjs';
2
- export declare function FromBase(_context: TProperties, type: Base, value: unknown): unknown;
@@ -1,4 +0,0 @@
1
- // deno-fmt-ignore-file
2
- export function FromBase(_context, type, value) {
3
- return type.Clean(value);
4
- }
@@ -1,2 +0,0 @@
1
- import type { Base, TProperties } from '../../type/index.mjs';
2
- export declare function FromBase(_context: TProperties, type: Base, value: unknown): unknown;
@@ -1,4 +0,0 @@
1
- // deno-fmt-ignore-file
2
- export function FromBase(_context, type, value) {
3
- return type.Convert(value);
4
- }
@@ -1,2 +0,0 @@
1
- import type { TProperties, TAsyncIterator } from '../../type/index.mjs';
2
- export declare function FromAsyncIterator(_context: TProperties, _type: TAsyncIterator): unknown;
@@ -1,5 +0,0 @@
1
- // deno-fmt-ignore-file
2
- async function* CreateAsyncIterator() { }
3
- export function FromAsyncIterator(_context, _type) {
4
- return CreateAsyncIterator();
5
- }
@@ -1,2 +0,0 @@
1
- import type { TProperties, Base } from '../../type/index.mjs';
2
- export declare function FromBase(_context: TProperties, type: Base): unknown;
@@ -1,4 +0,0 @@
1
- // deno-fmt-ignore-file
2
- export function FromBase(_context, type) {
3
- return type.Create();
4
- }
@@ -1,2 +0,0 @@
1
- import type { TProperties, TIterator } from '../../type/index.mjs';
2
- export declare function FromIterator(_context: TProperties, _type: TIterator): unknown;
@@ -1,5 +0,0 @@
1
- // deno-fmt-ignore-file
2
- function* CreateIterator() { }
3
- export function FromIterator(_context, _type) {
4
- return CreateIterator();
5
- }
@@ -1,2 +0,0 @@
1
- import type { TProperties, TPromise } from '../../type/index.mjs';
2
- export declare function FromPromise(context: TProperties, type: TPromise): unknown;
@@ -1,5 +0,0 @@
1
- // deno-fmt-ignore-file
2
- import { FromType } from './from_type.mjs';
3
- export function FromPromise(context, type) {
4
- return Promise.resolve(FromType(context, type.item));
5
- }
@@ -1,2 +0,0 @@
1
- import type { TProperties, Base } from '../../type/index.mjs';
2
- export declare function FromBase(context: TProperties, type: Base, value: unknown): unknown;
@@ -1,5 +0,0 @@
1
- // deno-fmt-ignore-file
2
- // deno-lint-ignore-file
3
- export function FromBase(context, type, value) {
4
- return type.Default(value);
5
- }
@@ -1,3 +0,0 @@
1
- export declare class MutateError extends Error {
2
- constructor(message: string);
3
- }
@@ -1,6 +0,0 @@
1
- // deno-fmt-ignore-file
2
- export class MutateError extends Error {
3
- constructor(message) {
4
- super(message);
5
- }
6
- }
@@ -1,2 +0,0 @@
1
- import { type TMutable } from './mutate.mjs';
2
- export declare function FromArray(root: TMutable, path: string, current: unknown, next: unknown[]): void;
@@ -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,2 +0,0 @@
1
- import { type TMutable } from './mutate.mjs';
2
- export declare function FromObject(root: TMutable, path: string, current: unknown, next: Record<string, unknown>): void;
@@ -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,2 +0,0 @@
1
- import { type TMutable } from './mutate.mjs';
2
- export declare function FromUnknown(root: TMutable, path: string, current: unknown, next: unknown): void;
@@ -1,7 +0,0 @@
1
- // deno-fmt-ignore-file
2
- import { Pointer } from '../pointer/index.mjs';
3
- export function FromUnknown(root, path, current, next) {
4
- if (current === next)
5
- return;
6
- Pointer.Set(root, path, next);
7
- }
@@ -1,2 +0,0 @@
1
- import { type TMutable } from './mutate.mjs';
2
- export declare function FromValue(root: TMutable, path: string, current: unknown, next: unknown): void;
@@ -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
- }