typebox 1.2.3 → 1.2.4

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 (56) hide show
  1. package/build/type/action/_add_immutable.d.mts +11 -0
  2. package/build/type/action/_add_immutable.mjs +11 -0
  3. package/build/type/action/_add_optional.d.mts +11 -0
  4. package/build/type/action/_add_optional.mjs +11 -0
  5. package/build/type/action/_add_readonly.d.mts +11 -0
  6. package/build/type/action/_add_readonly.mjs +11 -0
  7. package/build/type/action/_remove_immutable.d.mts +11 -0
  8. package/build/type/action/_remove_immutable.mjs +11 -0
  9. package/build/type/action/_remove_optional.d.mts +11 -0
  10. package/build/type/action/_remove_optional.mjs +11 -0
  11. package/build/type/action/_remove_readonly.d.mts +11 -0
  12. package/build/type/action/_remove_readonly.mjs +11 -0
  13. package/build/type/action/index.d.mts +6 -2
  14. package/build/type/action/index.mjs +6 -2
  15. package/build/type/engine/evaluate/composite.d.mts +10 -6
  16. package/build/type/engine/evaluate/composite.mjs +10 -6
  17. package/build/type/engine/immutable/instantiate_add.d.mts +10 -0
  18. package/build/type/engine/immutable/instantiate_add.mjs +14 -0
  19. package/build/type/engine/immutable/instantiate_remove.d.mts +10 -0
  20. package/build/type/engine/immutable/instantiate_remove.mjs +14 -0
  21. package/build/type/engine/instantiate.d.mts +32 -15
  22. package/build/type/engine/instantiate.mjs +61 -61
  23. package/build/type/engine/optional/instantiate_add.d.mts +10 -0
  24. package/build/type/engine/optional/instantiate_add.mjs +14 -0
  25. package/build/type/engine/optional/instantiate_remove.d.mts +10 -0
  26. package/build/type/engine/optional/instantiate_remove.mjs +14 -0
  27. package/build/type/engine/partial/from_object.d.mts +2 -2
  28. package/build/type/engine/partial/from_object.mjs +2 -2
  29. package/build/type/engine/readonly/instantiate_add.d.mts +10 -0
  30. package/build/type/engine/readonly/instantiate_add.mjs +14 -0
  31. package/build/type/engine/readonly/instantiate_remove.d.mts +10 -0
  32. package/build/type/engine/readonly/instantiate_remove.mjs +14 -0
  33. package/build/type/engine/readonly_object/from_array.d.mts +2 -2
  34. package/build/type/engine/readonly_object/from_array.mjs +2 -2
  35. package/build/type/engine/readonly_object/from_object.d.mts +2 -2
  36. package/build/type/engine/readonly_object/from_object.mjs +2 -2
  37. package/build/type/engine/readonly_object/from_tuple.d.mts +2 -2
  38. package/build/type/engine/readonly_object/from_tuple.mjs +2 -2
  39. package/build/type/engine/required/from_object.d.mts +2 -2
  40. package/build/type/engine/required/from_object.mjs +2 -2
  41. package/build/type/engine/template_literal/is_pattern.mjs +1 -0
  42. package/build/type/script/mapping.d.mts +42 -42
  43. package/build/type/script/mapping.mjs +46 -46
  44. package/build/type/types/_immutable.d.mts +2 -9
  45. package/build/type/types/_immutable.mjs +2 -10
  46. package/build/type/types/_optional.d.mts +2 -9
  47. package/build/type/types/_optional.mjs +2 -11
  48. package/build/type/types/_readonly.d.mts +2 -9
  49. package/build/type/types/_readonly.mjs +2 -10
  50. package/build/type/types/deferred.d.mts +1 -0
  51. package/build/type/types/deferred.mjs +1 -1
  52. package/package.json +1 -1
  53. package/build/type/action/_optional.d.mts +0 -19
  54. package/build/type/action/_optional.mjs +0 -40
  55. package/build/type/action/_readonly.d.mts +0 -19
  56. package/build/type/action/_readonly.mjs +0 -40
@@ -2,8 +2,8 @@
2
2
  // deno-lint-ignore-file
3
3
  import { Memory } from '../../system/memory/index.mjs';
4
4
  import { Guard } from '../../guard/index.mjs';
5
- import * as C from '../action/index.mjs';
6
5
  import * as T from '../types/index.mjs';
6
+ import * as S from '../action/index.mjs';
7
7
  function IntrinsicOrCall(ref, parameters) {
8
8
  // deno-coverage-ignore-start
9
9
  //
@@ -12,27 +12,27 @@ function IntrinsicOrCall(ref, parameters) {
12
12
  Guard.IsEqual(ref, 'AsyncIterator') ? T.AsyncIterator(parameters[0]) :
13
13
  Guard.IsEqual(ref, 'Iterator') ? T.Iterator(parameters[0]) :
14
14
  Guard.IsEqual(ref, 'Promise') ? T.Promise(parameters[0]) :
15
- Guard.IsEqual(ref, 'Awaited') ? C.AwaitedDeferred(parameters[0]) :
16
- Guard.IsEqual(ref, 'Capitalize') ? C.CapitalizeDeferred(parameters[0]) :
17
- Guard.IsEqual(ref, 'ConstructorParameters') ? C.ConstructorParametersDeferred(parameters[0]) :
18
- Guard.IsEqual(ref, 'Evaluate') ? C.EvaluateDeferred(parameters[0]) :
19
- Guard.IsEqual(ref, 'Exclude') ? C.ExcludeDeferred(parameters[0], parameters[1]) :
20
- Guard.IsEqual(ref, 'Extract') ? C.ExtractDeferred(parameters[0], parameters[1]) :
21
- Guard.IsEqual(ref, 'Index') ? C.IndexDeferred(parameters[0], parameters[1]) :
22
- Guard.IsEqual(ref, 'InstanceType') ? C.InstanceTypeDeferred(parameters[0]) :
23
- Guard.IsEqual(ref, 'Lowercase') ? C.LowercaseDeferred(parameters[0]) :
24
- Guard.IsEqual(ref, 'NonNullable') ? C.NonNullableDeferred(parameters[0]) :
25
- Guard.IsEqual(ref, 'Omit') ? C.OmitDeferred(parameters[0], parameters[1]) :
26
- Guard.IsEqual(ref, 'Parameters') ? C.ParametersDeferred(parameters[0]) :
27
- Guard.IsEqual(ref, 'Partial') ? C.PartialDeferred(parameters[0]) :
28
- Guard.IsEqual(ref, 'Pick') ? C.PickDeferred(parameters[0], parameters[1]) :
29
- Guard.IsEqual(ref, 'Readonly') ? C.ReadonlyObjectDeferred(parameters[0]) :
30
- Guard.IsEqual(ref, 'KeyOf') ? C.KeyOfDeferred(parameters[0]) :
15
+ Guard.IsEqual(ref, 'Awaited') ? S.AwaitedDeferred(parameters[0]) :
16
+ Guard.IsEqual(ref, 'Capitalize') ? S.CapitalizeDeferred(parameters[0]) :
17
+ Guard.IsEqual(ref, 'ConstructorParameters') ? S.ConstructorParametersDeferred(parameters[0]) :
18
+ Guard.IsEqual(ref, 'Evaluate') ? S.EvaluateDeferred(parameters[0]) :
19
+ Guard.IsEqual(ref, 'Exclude') ? S.ExcludeDeferred(parameters[0], parameters[1]) :
20
+ Guard.IsEqual(ref, 'Extract') ? S.ExtractDeferred(parameters[0], parameters[1]) :
21
+ Guard.IsEqual(ref, 'Index') ? S.IndexDeferred(parameters[0], parameters[1]) :
22
+ Guard.IsEqual(ref, 'InstanceType') ? S.InstanceTypeDeferred(parameters[0]) :
23
+ Guard.IsEqual(ref, 'Lowercase') ? S.LowercaseDeferred(parameters[0]) :
24
+ Guard.IsEqual(ref, 'NonNullable') ? S.NonNullableDeferred(parameters[0]) :
25
+ Guard.IsEqual(ref, 'Omit') ? S.OmitDeferred(parameters[0], parameters[1]) :
26
+ Guard.IsEqual(ref, 'Parameters') ? S.ParametersDeferred(parameters[0]) :
27
+ Guard.IsEqual(ref, 'Partial') ? S.PartialDeferred(parameters[0]) :
28
+ Guard.IsEqual(ref, 'Pick') ? S.PickDeferred(parameters[0], parameters[1]) :
29
+ Guard.IsEqual(ref, 'Readonly') ? S.ReadonlyObjectDeferred(parameters[0]) :
30
+ Guard.IsEqual(ref, 'KeyOf') ? S.KeyOfDeferred(parameters[0]) :
31
31
  Guard.IsEqual(ref, 'Record') ? T.RecordDeferred(parameters[0], parameters[1]) :
32
- Guard.IsEqual(ref, 'Required') ? C.RequiredDeferred(parameters[0]) :
33
- Guard.IsEqual(ref, 'ReturnType') ? C.ReturnTypeDeferred(parameters[0]) :
34
- Guard.IsEqual(ref, 'Uncapitalize') ? C.UncapitalizeDeferred(parameters[0]) :
35
- Guard.IsEqual(ref, 'Uppercase') ? C.UppercaseDeferred(parameters[0]) :
32
+ Guard.IsEqual(ref, 'Required') ? S.RequiredDeferred(parameters[0]) :
33
+ Guard.IsEqual(ref, 'ReturnType') ? S.ReturnTypeDeferred(parameters[0]) :
34
+ Guard.IsEqual(ref, 'Uncapitalize') ? S.UncapitalizeDeferred(parameters[0]) :
35
+ Guard.IsEqual(ref, 'Uppercase') ? S.UppercaseDeferred(parameters[0]) :
36
36
  T.CallConstruct(T.Ref(ref), parameters));
37
37
  // deno-coverage-ignore-stop
38
38
  }
@@ -189,7 +189,7 @@ export function WithMapping(input) {
189
189
  function FactorIndexArray(Type, indexArray) {
190
190
  return indexArray.reduce((result, left) => {
191
191
  const _left = left;
192
- return (Guard.IsEqual(_left.length, 1) ? C.IndexDeferred(result, _left[0]) :
192
+ return (Guard.IsEqual(_left.length, 1) ? S.IndexDeferred(result, _left[0]) :
193
193
  Guard.IsEqual(_left.length, 0) ? T.Array(result) :
194
194
  Unreachable());
195
195
  }, Type);
@@ -197,18 +197,18 @@ function FactorIndexArray(Type, indexArray) {
197
197
  // deno-coverage-ignore-stop
198
198
  function FactorExtends(type, extend) {
199
199
  return Guard.IsEqual(extend.length, 3)
200
- ? C.ConditionalDeferred(type, extend[0], extend[1], extend[2])
200
+ ? S.ConditionalDeferred(type, extend[0], extend[1], extend[2])
201
201
  : type;
202
202
  }
203
203
  function FactorWith(type, withClause) {
204
204
  return Guard.IsArray(withClause) && Guard.IsEqual(withClause.length, 0)
205
205
  ? type
206
- : C.WithDeferred(type, withClause);
206
+ : S.WithDeferred(type, withClause);
207
207
  }
208
208
  export function FactorMapping(input) {
209
209
  const [keyOf, type, indexArray, extend, withClause] = input;
210
210
  return FactorWith(keyOf
211
- ? FactorExtends(C.KeyOfDeferred(FactorIndexArray(type, indexArray)), extend)
211
+ ? FactorExtends(S.KeyOfDeferred(FactorIndexArray(type, indexArray)), extend)
212
212
  : FactorExtends(FactorIndexArray(type, indexArray), extend), withClause);
213
213
  }
214
214
  // deno-coverage-ignore-start
@@ -244,7 +244,7 @@ export function ExprMapping(input) {
244
244
  return ExprBinaryMapping(left, rest);
245
245
  }
246
246
  export function ExprReadonlyMapping(input) {
247
- return T.ImmutableAdd(input[1]);
247
+ return S.AddImmutableDeferred(input[1]);
248
248
  }
249
249
  export function ExprPipeMapping(input) {
250
250
  return input[1];
@@ -290,9 +290,9 @@ export function OptionalMapping(input) {
290
290
  export function PropertyMapping(input) {
291
291
  const [isReadonly, key, isOptional, _colon, type] = input;
292
292
  return {
293
- [key]: (isReadonly && isOptional ? T.ReadonlyAdd(T.OptionalAdd(type)) :
294
- isReadonly && !isOptional ? T.ReadonlyAdd(type) :
295
- !isReadonly && isOptional ? T.OptionalAdd(type) :
293
+ [key]: (isReadonly && isOptional ? S.AddReadonlyDeferred(S.AddOptionalDeferred(type)) :
294
+ isReadonly && !isOptional ? S.AddReadonlyDeferred(type) :
295
+ !isReadonly && isOptional ? S.AddOptionalDeferred(type) :
296
296
  type)
297
297
  };
298
298
  }
@@ -321,19 +321,19 @@ export function _Object_Mapping(input) {
321
321
  }
322
322
  // deno-coverage-ignore-start
323
323
  export function ElementNamedMapping(input) {
324
- return (Guard.IsEqual(input.length, 5) ? T.ReadonlyAdd(T.OptionalAdd(input[4])) :
324
+ return (Guard.IsEqual(input.length, 5) ? S.AddReadonlyDeferred(S.AddOptionalDeferred(input[4])) :
325
325
  Guard.IsEqual(input.length, 3) ? input[2] :
326
- Guard.IsEqual(input.length, 4) ? (Guard.IsEqual(input[2], 'readonly') ? T.ReadonlyAdd(input[3]) : T.OptionalAdd(input[3])) :
326
+ Guard.IsEqual(input.length, 4) ? (Guard.IsEqual(input[2], 'readonly') ? S.AddReadonlyDeferred(input[3]) : S.AddOptionalDeferred(input[3])) :
327
327
  Unreachable());
328
328
  }
329
329
  export function ElementReadonlyOptionalMapping(input) {
330
- return T.ReadonlyAdd(T.OptionalAdd(input[1]));
330
+ return S.AddReadonlyDeferred(S.AddOptionalDeferred(input[1]));
331
331
  }
332
332
  export function ElementReadonlyMapping(input) {
333
- return T.ReadonlyAdd(input[1]);
333
+ return S.AddReadonlyDeferred(input[1]);
334
334
  }
335
335
  export function ElementOptionalMapping(input) {
336
- return T.OptionalAdd(input[0]);
336
+ return S.AddOptionalDeferred(input[0]);
337
337
  }
338
338
  export function ElementBaseMapping(input) {
339
339
  return input;
@@ -351,13 +351,13 @@ export function _Tuple_Mapping(input) {
351
351
  return T.Tuple(input[1]);
352
352
  }
353
353
  export function ParameterReadonlyOptionalMapping(input) {
354
- return T.ReadonlyAdd(T.OptionalAdd(input[4]));
354
+ return S.AddReadonlyDeferred(S.AddOptionalDeferred(input[4]));
355
355
  }
356
356
  export function ParameterReadonlyMapping(input) {
357
- return T.ReadonlyAdd(input[3]);
357
+ return S.AddReadonlyDeferred(input[3]);
358
358
  }
359
359
  export function ParameterOptionalMapping(input) {
360
- return T.OptionalAdd(input[3]);
360
+ return S.AddOptionalDeferred(input[3]);
361
361
  }
362
362
  export function ParameterTypeMapping(input) {
363
363
  return input[2];
@@ -381,8 +381,8 @@ export function _Constructor_Mapping(input) {
381
381
  return T.Constructor(input[2], input[5]);
382
382
  }
383
383
  function ApplyReadonly(state, type) {
384
- return (Guard.IsEqual(state, 'remove') ? C.ReadonlyRemoveAction(type) :
385
- Guard.IsEqual(state, 'add') ? C.ReadonlyAddAction(type) :
384
+ return (Guard.IsEqual(state, 'remove') ? S.RemoveReadonlyDeferred(type) :
385
+ Guard.IsEqual(state, 'add') ? S.AddReadonlyDeferred(type) :
386
386
  type);
387
387
  }
388
388
  export function MappedReadonlyMapping(input) {
@@ -392,8 +392,8 @@ export function MappedReadonlyMapping(input) {
392
392
  'none');
393
393
  }
394
394
  function ApplyOptional(state, type) {
395
- return (Guard.IsEqual(state, 'remove') ? C.OptionalRemoveAction(type) :
396
- Guard.IsEqual(state, 'add') ? C.OptionalAddAction(type) :
395
+ return (Guard.IsEqual(state, 'remove') ? S.RemoveOptionalDeferred(type) :
396
+ Guard.IsEqual(state, 'add') ? S.AddOptionalDeferred(type) :
397
397
  type);
398
398
  }
399
399
  export function MappedOptionalMapping(input) {
@@ -407,8 +407,8 @@ export function MappedAsMapping(input) {
407
407
  }
408
408
  export function _Mapped_Mapping(input) {
409
409
  return (Guard.IsArray(input[6]) && Guard.IsEqual(input[6].length, 1)
410
- ? C.MappedDeferred(T.Identifier(input[3]), input[5], input[6][0], ApplyReadonly(input[1], ApplyOptional(input[8], input[10])))
411
- : C.MappedDeferred(T.Identifier(input[3]), input[5], T.Ref(input[3]), ApplyReadonly(input[1], ApplyOptional(input[8], input[10]))));
410
+ ? S.MappedDeferred(T.Identifier(input[3]), input[5], input[6][0], ApplyReadonly(input[1], ApplyOptional(input[8], input[10])))
411
+ : S.MappedDeferred(T.Identifier(input[3]), input[5], T.Ref(input[3]), ApplyReadonly(input[1], ApplyOptional(input[8], input[10]))));
412
412
  }
413
413
  export function ReferenceMapping(input) {
414
414
  return T.Ref(input);
@@ -497,13 +497,13 @@ export function InterfaceDeclarationGenericMapping(input) {
497
497
  const heritage = input[3];
498
498
  const [properties, patternProperties] = input[4];
499
499
  const options = Guard.IsEqual(Guard.Keys(patternProperties).length, 0) ? {} : { patternProperties };
500
- return { [input[1]]: T.Generic(parameters, C.InterfaceDeferred(heritage, properties, options)) };
500
+ return { [input[1]]: T.Generic(parameters, S.InterfaceDeferred(heritage, properties, options)) };
501
501
  }
502
502
  export function InterfaceDeclarationMapping(input) {
503
503
  const heritage = input[2];
504
504
  const [properties, patternProperties] = input[3];
505
505
  const options = Guard.IsEqual(Guard.Keys(patternProperties).length, 0) ? {} : { patternProperties };
506
- return { [input[1]]: C.InterfaceDeferred(heritage, properties, options) };
506
+ return { [input[1]]: S.InterfaceDeferred(heritage, properties, options) };
507
507
  }
508
508
  export function TypeAliasDeclarationGenericMapping(input) {
509
509
  return { [input[1]]: T.Generic(input[2], input[4]) };
@@ -526,7 +526,7 @@ export function ModuleDeclarationMapping(input) {
526
526
  export function ModuleMapping(input) {
527
527
  const moduleDeclaration = input[0];
528
528
  const moduleDeclarationList = input[1];
529
- return C.ModuleDeferred(Memory.Assign(moduleDeclaration, moduleDeclarationList[0]));
529
+ return S.ModuleDeferred(Memory.Assign(moduleDeclaration, moduleDeclarationList[0]));
530
530
  }
531
531
  export function ScriptMapping(input) {
532
532
  return input;
@@ -1,16 +1,9 @@
1
1
  import { type TSchema } from './schema.mjs';
2
- /** Removes Immutable from the given type. */
3
- export type TImmutableRemove<Type extends TSchema, Result extends TSchema = Type extends TImmutable<infer Type extends TSchema> ? Type : Type> = Result;
4
- /** Removes Immutable from the given type. */
5
- export declare function ImmutableRemove<Type extends TSchema>(type: Type): TImmutableRemove<Type>;
6
- /** Adds Immutable to the given type. */
7
- export type TImmutableAdd<Type extends TSchema = TSchema> = ('~immutable' extends keyof Type ? Type : TImmutable<Type>);
8
- /** Adds Immutable to the given type. */
9
- export declare function ImmutableAdd<Type extends TSchema>(type: Type): TImmutableAdd<Type>;
2
+ import { type TAddImmutable } from '../action/_add_immutable.mjs';
10
3
  export type TImmutable<Type extends TSchema = TSchema> = (Type & {
11
4
  '~immutable': true;
12
5
  });
13
6
  /** Applies an Immutable modifier to the given type. */
14
- export declare function Immutable<Type extends TSchema>(type: Type): TImmutableAdd<Type>;
7
+ export declare function Immutable<Type extends TSchema>(type: Type): TAddImmutable<Type>;
15
8
  /** Returns true if the given value is a TImmutable */
16
9
  export declare function IsImmutable(value: unknown): value is TImmutable<TSchema>;
@@ -1,21 +1,13 @@
1
1
  // deno-fmt-ignore-file
2
- import { Memory } from '../../system/memory/index.mjs';
3
2
  import { Guard } from '../../guard/index.mjs';
4
3
  import { IsSchema } from './schema.mjs';
5
- /** Removes Immutable from the given type. */
6
- export function ImmutableRemove(type) {
7
- return Memory.Discard(type, ['~immutable']);
8
- }
9
- /** Adds Immutable to the given type. */
10
- export function ImmutableAdd(type) {
11
- return Memory.Update(type, { '~immutable': true }, {});
12
- }
4
+ import { AddImmutable } from '../action/_add_immutable.mjs';
13
5
  // ------------------------------------------------------------------
14
6
  // Factory
15
7
  // ------------------------------------------------------------------
16
8
  /** Applies an Immutable modifier to the given type. */
17
9
  export function Immutable(type) {
18
- return ImmutableAdd(type);
10
+ return AddImmutable(type);
19
11
  }
20
12
  // ------------------------------------------------------------------
21
13
  // Guard
@@ -1,16 +1,9 @@
1
1
  import { type TSchema } from './schema.mjs';
2
- /** Removes Optional from the given type. */
3
- export type TOptionalRemove<Type extends TSchema, Result extends TSchema = Type extends TOptional<infer Type extends TSchema> ? Type : Type> = Result;
4
- /** Removes Optional from the given type. */
5
- export declare function OptionalRemove<Type extends TSchema>(type: Type): TOptionalRemove<Type>;
6
- /** Adds Optional to the given type. */
7
- export type TOptionalAdd<Type extends TSchema = TSchema, Result extends TSchema = '~optional' extends keyof Type ? Type : TOptional<Type>> = Result;
8
- /** Adds Optional to the given type. */
9
- export declare function OptionalAdd<Type extends TSchema>(type: Type): TOptionalAdd<Type>;
2
+ import { type TAddOptional } from '../action/_add_optional.mjs';
10
3
  export type TOptional<Type extends TSchema = TSchema> = (Type & {
11
4
  '~optional': true;
12
5
  });
13
6
  /** Applies an Optional modifier to the given type. */
14
- export declare function Optional<Type extends TSchema>(type: Type): TOptionalAdd<Type>;
7
+ export declare function Optional<Type extends TSchema>(type: Type): TAddOptional<Type>;
15
8
  /** Returns true if the given value is TOptional */
16
9
  export declare function IsOptional(value: unknown): value is TOptional<TSchema>;
@@ -1,22 +1,13 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { Guard } from '../../guard/index.mjs';
3
- import { Memory } from '../../system/memory/index.mjs';
4
3
  import { IsSchema } from './schema.mjs';
5
- /** Removes Optional from the given type. */
6
- export function OptionalRemove(type) {
7
- const result = Memory.Discard(type, ['~optional']);
8
- return result;
9
- }
10
- /** Adds Optional to the given type. */
11
- export function OptionalAdd(type) {
12
- return Memory.Update(type, { '~optional': true }, {});
13
- }
4
+ import { AddOptional } from '../action/_add_optional.mjs';
14
5
  // ------------------------------------------------------------------
15
6
  // Factory
16
7
  // ------------------------------------------------------------------
17
8
  /** Applies an Optional modifier to the given type. */
18
9
  export function Optional(type) {
19
- return OptionalAdd(type);
10
+ return AddOptional(type);
20
11
  }
21
12
  // ------------------------------------------------------------------
22
13
  // Guard
@@ -1,16 +1,9 @@
1
1
  import { type TSchema } from './schema.mjs';
2
- /** Removes a Readonly property modifier from the given type. */
3
- export type TReadonlyRemove<Type extends TSchema, Result extends TSchema = Type extends TReadonly<infer Type extends TSchema> ? Type : Type> = Result;
4
- /** Removes a Readonly property modifier from the given type. */
5
- export declare function ReadonlyRemove<Type extends TSchema>(type: Type): TReadonlyRemove<Type>;
6
- /** Adds a Readonly property modifier to the given type. */
7
- export type TReadonlyAdd<Type extends TSchema = TSchema> = ('~readonly' extends keyof Type ? Type : TReadonly<Type>);
8
- /** Adds a Readonly property modifier to the given type. */
9
- export declare function ReadonlyAdd<Type extends TSchema>(type: Type): TReadonlyAdd<Type>;
2
+ import { type TAddReadonly } from '../action/_add_readonly.mjs';
10
3
  export type TReadonly<Type extends TSchema = TSchema> = (Type & {
11
4
  '~readonly': true;
12
5
  });
13
6
  /** Applies an Readonly property modifier to the given type. */
14
- export declare function Readonly<Type extends TSchema>(type: Type): TReadonlyAdd<Type>;
7
+ export declare function Readonly<Type extends TSchema>(type: Type): TAddReadonly<Type>;
15
8
  /** Returns true if the given value is a TReadonly */
16
9
  export declare function IsReadonly(value: unknown): value is TReadonly<TSchema>;
@@ -1,21 +1,13 @@
1
1
  // deno-fmt-ignore-file
2
- import { Memory } from '../../system/memory/index.mjs';
3
2
  import { Guard } from '../../guard/index.mjs';
4
3
  import { IsSchema } from './schema.mjs';
5
- /** Removes a Readonly property modifier from the given type. */
6
- export function ReadonlyRemove(type) {
7
- return Memory.Discard(type, ['~readonly']);
8
- }
9
- /** Adds a Readonly property modifier to the given type. */
10
- export function ReadonlyAdd(type) {
11
- return Memory.Update(type, { '~readonly': true }, {});
12
- }
4
+ import { AddReadonly } from '../action/_add_readonly.mjs';
13
5
  // ------------------------------------------------------------------
14
6
  // Factory
15
7
  // ------------------------------------------------------------------
16
8
  /** Applies an Readonly property modifier to the given type. */
17
9
  export function Readonly(type) {
18
- return ReadonlyAdd(type);
10
+ return AddReadonly(type);
19
11
  }
20
12
  // ------------------------------------------------------------------
21
13
  // Guard
@@ -2,6 +2,7 @@ import { type TSchema, type TSchemaOptions } from './schema.mjs';
2
2
  /** Represents a deferred action. */
3
3
  export interface TDeferred<Action extends string = string, Types extends TSchema[] = TSchema[]> extends TSchema {
4
4
  '~kind': 'Deferred';
5
+ type: 'deferred';
5
6
  action: Action;
6
7
  parameters: Types;
7
8
  options: TSchemaOptions;
@@ -5,7 +5,7 @@ import { IsKind } from './schema.mjs';
5
5
  // ------------------------------------------------------------------
6
6
  /** Creates a Deferred action. */
7
7
  export function Deferred(action, parameters, options) {
8
- return Memory.Create({ '~kind': 'Deferred' }, { action, parameters, options }, {});
8
+ return Memory.Create({ '~kind': 'Deferred' }, { type: 'deferred', action, parameters, options }, {});
9
9
  }
10
10
  // ------------------------------------------------------------------
11
11
  // Guard
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
3
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
4
- "version": "1.2.3",
4
+ "version": "1.2.4",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"
@@ -1,19 +0,0 @@
1
- import { type TSchema } from '../types/schema.mjs';
2
- /** Represents a operation to apply Optional to a property */
3
- export interface TOptionalAddAction<Type extends TSchema = TSchema> extends TSchema {
4
- '~kind': 'OptionalAddAction';
5
- type: Type;
6
- }
7
- /** Creates an OptionalAddAction. */
8
- export declare function OptionalAddAction<Type extends TSchema>(type: Type): TOptionalAddAction<Type>;
9
- /** Returns true if this value is a OptionalAddAction. */
10
- export declare function IsOptionalAddAction(value: unknown): value is TOptionalAddAction;
11
- /** Represents a operation to remove Optional from a property */
12
- export interface TOptionalRemoveAction<Type extends TSchema = TSchema> extends TSchema {
13
- '~kind': 'OptionalRemoveAction';
14
- type: Type;
15
- }
16
- /** Creates a OptionalRemoveAction. */
17
- export declare function OptionalRemoveAction<Type extends TSchema>(type: Type): TOptionalRemoveAction<Type>;
18
- /** Returns true if this value is a OptionalRemoveAction. */
19
- export declare function IsOptionalRemoveAction(value: unknown): value is TOptionalRemoveAction;
@@ -1,40 +0,0 @@
1
- // deno-fmt-ignore-file
2
- import { Memory } from '../../system/memory/index.mjs';
3
- import { Guard } from '../../guard/index.mjs';
4
- import { IsSchema } from '../types/schema.mjs';
5
- // ------------------------------------------------------------------
6
- // Action
7
- // ------------------------------------------------------------------
8
- /** Creates an OptionalAddAction. */
9
- export function OptionalAddAction(type) {
10
- return Memory.Create({ ['~kind']: 'OptionalAddAction' }, { type }, {});
11
- }
12
- // ------------------------------------------------------------------
13
- // Guard
14
- // ------------------------------------------------------------------
15
- /** Returns true if this value is a OptionalAddAction. */
16
- export function IsOptionalAddAction(value) {
17
- return Guard.IsObject(value)
18
- && Guard.HasPropertyKey(value, '~kind')
19
- && Guard.HasPropertyKey(value, 'type')
20
- && Guard.IsEqual(value['~kind'], 'OptionalAddAction')
21
- && IsSchema(value.type);
22
- }
23
- // ------------------------------------------------------------------
24
- // Factory
25
- // ------------------------------------------------------------------
26
- /** Creates a OptionalRemoveAction. */
27
- export function OptionalRemoveAction(type) {
28
- return Memory.Create({ ['~kind']: 'OptionalRemoveAction' }, { type }, {});
29
- }
30
- // ------------------------------------------------------------------
31
- // Guard
32
- // ------------------------------------------------------------------
33
- /** Returns true if this value is a OptionalRemoveAction. */
34
- export function IsOptionalRemoveAction(value) {
35
- return Guard.IsObject(value)
36
- && Guard.HasPropertyKey(value, '~kind')
37
- && Guard.HasPropertyKey(value, 'type')
38
- && Guard.IsEqual(value['~kind'], 'OptionalRemoveAction')
39
- && IsSchema(value.type);
40
- }
@@ -1,19 +0,0 @@
1
- import { type TSchema } from '../types/schema.mjs';
2
- /** Represents an operation to apply Readonly to a property. */
3
- export interface TReadonlyAddAction<Type extends TSchema = TSchema> extends TSchema {
4
- '~kind': 'ReadonlyAddAction';
5
- type: Type;
6
- }
7
- /** Creates a ReadonlyAddAction. */
8
- export declare function ReadonlyAddAction<Type extends TSchema>(type: Type): TReadonlyAddAction<Type>;
9
- /** Returns true if this value is a ReadonlyAddAction. */
10
- export declare function IsReadonlyAddAction(value: unknown): value is TReadonlyAddAction;
11
- /** Represents an action to remove Readonly from a property. */
12
- export interface TReadonlyRemoveAction<Type extends TSchema = TSchema> extends TSchema {
13
- '~kind': 'ReadonlyRemoveAction';
14
- type: Type;
15
- }
16
- /** Creates a ReadonlyRemoveAction. */
17
- export declare function ReadonlyRemoveAction<Type extends TSchema>(type: Type): TReadonlyRemoveAction<Type>;
18
- /** Returns true if this value is a ReadonlyRemoveAction. */
19
- export declare function IsReadonlyRemoveAction(value: unknown): value is TReadonlyRemoveAction;
@@ -1,40 +0,0 @@
1
- // deno-fmt-ignore-file
2
- import { Memory } from '../../system/memory/index.mjs';
3
- import { Guard } from '../../guard/index.mjs';
4
- import { IsSchema } from '../types/schema.mjs';
5
- // ------------------------------------------------------------------
6
- // Action
7
- // ------------------------------------------------------------------
8
- /** Creates a ReadonlyAddAction. */
9
- export function ReadonlyAddAction(type) {
10
- return Memory.Create({ ['~kind']: 'ReadonlyAddAction' }, { type }, {});
11
- }
12
- // ------------------------------------------------------------------
13
- // Guard
14
- // ------------------------------------------------------------------
15
- /** Returns true if this value is a ReadonlyAddAction. */
16
- export function IsReadonlyAddAction(value) {
17
- return Guard.IsObject(value)
18
- && Guard.HasPropertyKey(value, '~kind')
19
- && Guard.HasPropertyKey(value, 'type')
20
- && Guard.IsEqual(value['~kind'], 'ReadonlyAddAction')
21
- && IsSchema(value.type);
22
- }
23
- // ------------------------------------------------------------------
24
- // Factory
25
- // ------------------------------------------------------------------
26
- /** Creates a ReadonlyRemoveAction. */
27
- export function ReadonlyRemoveAction(type) {
28
- return Memory.Create({ ['~kind']: 'ReadonlyRemoveAction' }, { type }, {});
29
- }
30
- // ------------------------------------------------------------------
31
- // Guard
32
- // ------------------------------------------------------------------
33
- /** Returns true if this value is a ReadonlyRemoveAction. */
34
- export function IsReadonlyRemoveAction(value) {
35
- return Guard.IsObject(value)
36
- && Guard.HasPropertyKey(value, '~kind')
37
- && Guard.HasPropertyKey(value, 'type')
38
- && Guard.IsEqual(value['~kind'], 'ReadonlyRemoveAction')
39
- && IsSchema(value.type);
40
- }