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
@@ -0,0 +1,11 @@
1
+ import { type TSchema, type TSchemaOptions } from '../types/schema.mjs';
2
+ import { type TDeferred } from '../types/deferred.mjs';
3
+ import { type TAddImmutableAction } from '../engine/immutable/instantiate_add.mjs';
4
+ /** Creates a deferred AddImmutable action. */
5
+ export type TAddImmutableDeferred<Type extends TSchema> = (TDeferred<'AddImmutable', [Type]>);
6
+ /** Creates a deferred AddImmutable action. */
7
+ export declare function AddImmutableDeferred<Type extends TSchema>(type: Type, options?: TSchemaOptions): TAddImmutableDeferred<Type>;
8
+ /** Applies an AddImmutable action to a type. */
9
+ export type TAddImmutable<Type extends TSchema> = (TAddImmutableAction<Type>);
10
+ /** Applies an AddImmutable action to a type. */
11
+ export declare function AddImmutable<Type extends TSchema>(type: Type, options?: TSchemaOptions): TAddImmutable<Type>;
@@ -0,0 +1,11 @@
1
+ // deno-fmt-ignore-file
2
+ import { Deferred } from '../types/deferred.mjs';
3
+ import { AddImmutableAction } from '../engine/immutable/instantiate_add.mjs';
4
+ /** Creates a deferred AddImmutable action. */
5
+ export function AddImmutableDeferred(type, options = {}) {
6
+ return Deferred('AddImmutable', [type], options);
7
+ }
8
+ /** Applies an AddImmutable action to a type. */
9
+ export function AddImmutable(type, options = {}) {
10
+ return AddImmutableAction(type, options);
11
+ }
@@ -0,0 +1,11 @@
1
+ import { type TSchema, type TSchemaOptions } from '../types/schema.mjs';
2
+ import { type TDeferred } from '../types/deferred.mjs';
3
+ import { type TAddOptionalAction } from '../engine/optional/instantiate_add.mjs';
4
+ /** Creates a deferred AddOptional action. */
5
+ export type TAddOptionalDeferred<Type extends TSchema> = (TDeferred<'AddOptional', [Type]>);
6
+ /** Creates a deferred AddOptional action. */
7
+ export declare function AddOptionalDeferred<Type extends TSchema>(type: Type, options?: TSchemaOptions): TAddOptionalDeferred<Type>;
8
+ /** Applies an AddOptional action to a type. */
9
+ export type TAddOptional<Type extends TSchema> = (TAddOptionalAction<Type>);
10
+ /** Applies an AddOptional action to a type. */
11
+ export declare function AddOptional<Type extends TSchema>(type: Type, options?: TSchemaOptions): TAddOptional<Type>;
@@ -0,0 +1,11 @@
1
+ // deno-fmt-ignore-file
2
+ import { Deferred } from '../types/deferred.mjs';
3
+ import { AddOptionalAction } from '../engine/optional/instantiate_add.mjs';
4
+ /** Creates a deferred AddOptional action. */
5
+ export function AddOptionalDeferred(type, options = {}) {
6
+ return Deferred('AddOptional', [type], options);
7
+ }
8
+ /** Applies an AddOptional action to a type. */
9
+ export function AddOptional(type, options = {}) {
10
+ return AddOptionalAction(type, options);
11
+ }
@@ -0,0 +1,11 @@
1
+ import { type TSchema, type TSchemaOptions } from '../types/schema.mjs';
2
+ import { type TDeferred } from '../types/deferred.mjs';
3
+ import { type TAddReadonlyAction } from '../engine/readonly/instantiate_add.mjs';
4
+ /** Creates a deferred AddReadonly action. */
5
+ export type TAddReadonlyDeferred<Type extends TSchema> = (TDeferred<'AddReadonly', [Type]>);
6
+ /** Creates a deferred AddReadonly action. */
7
+ export declare function AddReadonlyDeferred<Type extends TSchema>(type: Type, options?: TSchemaOptions): TAddReadonlyDeferred<Type>;
8
+ /** Applies an AddReadonly action to a type. */
9
+ export type TAddReadonly<Type extends TSchema> = (TAddReadonlyAction<Type>);
10
+ /** Applies an AddReadonly action to a type. */
11
+ export declare function AddReadonly<Type extends TSchema>(type: Type, options?: TSchemaOptions): TAddReadonly<Type>;
@@ -0,0 +1,11 @@
1
+ // deno-fmt-ignore-file
2
+ import { Deferred } from '../types/deferred.mjs';
3
+ import { AddReadonlyAction } from '../engine/readonly/instantiate_add.mjs';
4
+ /** Creates a deferred AddReadonly action. */
5
+ export function AddReadonlyDeferred(type, options = {}) {
6
+ return Deferred('AddReadonly', [type], options);
7
+ }
8
+ /** Applies an AddReadonly action to a type. */
9
+ export function AddReadonly(type, options = {}) {
10
+ return AddReadonlyAction(type, options);
11
+ }
@@ -0,0 +1,11 @@
1
+ import { type TSchema, type TSchemaOptions } from '../types/schema.mjs';
2
+ import { type TDeferred } from '../types/deferred.mjs';
3
+ import { type TRemoveImmutableAction } from '../engine/immutable/instantiate_remove.mjs';
4
+ /** Creates a deferred RemoveImmutable action. */
5
+ export type TRemoveImmutableDeferred<Type extends TSchema> = (TDeferred<'RemoveImmutable', [Type]>);
6
+ /** Creates a deferred RemoveImmutable action. */
7
+ export declare function RemoveImmutableDeferred<Type extends TSchema>(type: Type, options?: TSchemaOptions): TRemoveImmutableDeferred<Type>;
8
+ /** Applies an RemoveImmutable action to a type. */
9
+ export type TRemoveImmutable<Type extends TSchema> = (TRemoveImmutableAction<Type>);
10
+ /** Applies an RemoveImmutable action to a type. */
11
+ export declare function RemoveImmutable<Type extends TSchema>(type: Type, options?: TSchemaOptions): TRemoveImmutable<Type>;
@@ -0,0 +1,11 @@
1
+ // deno-fmt-ignore-file
2
+ import { Deferred } from '../types/deferred.mjs';
3
+ import { RemoveImmutableAction } from '../engine/immutable/instantiate_remove.mjs';
4
+ /** Creates a deferred RemoveImmutable action. */
5
+ export function RemoveImmutableDeferred(type, options = {}) {
6
+ return Deferred('RemoveImmutable', [type], options);
7
+ }
8
+ /** Applies an RemoveImmutable action to a type. */
9
+ export function RemoveImmutable(type, options = {}) {
10
+ return RemoveImmutableAction(type, options);
11
+ }
@@ -0,0 +1,11 @@
1
+ import { type TSchema, type TSchemaOptions } from '../types/schema.mjs';
2
+ import { type TDeferred } from '../types/deferred.mjs';
3
+ import { type TRemoveOptionalAction } from '../engine/optional/instantiate_remove.mjs';
4
+ /** Creates a deferred RemoveOptional action. */
5
+ export type TRemoveOptionalDeferred<Type extends TSchema> = (TDeferred<'RemoveOptional', [Type]>);
6
+ /** Creates a deferred RemoveOptional action. */
7
+ export declare function RemoveOptionalDeferred<Type extends TSchema>(type: Type, options?: TSchemaOptions): TRemoveOptionalDeferred<Type>;
8
+ /** Applies an RemoveOptional action to a type. */
9
+ export type TRemoveOptional<Type extends TSchema> = (TRemoveOptionalAction<Type>);
10
+ /** Applies an RemoveOptional action to a type. */
11
+ export declare function RemoveOptional<Type extends TSchema>(type: Type, options?: TSchemaOptions): TRemoveOptional<Type>;
@@ -0,0 +1,11 @@
1
+ // deno-fmt-ignore-file
2
+ import { Deferred } from '../types/deferred.mjs';
3
+ import { RemoveOptionalAction } from '../engine/optional/instantiate_remove.mjs';
4
+ /** Creates a deferred RemoveOptional action. */
5
+ export function RemoveOptionalDeferred(type, options = {}) {
6
+ return Deferred('RemoveOptional', [type], options);
7
+ }
8
+ /** Applies an RemoveOptional action to a type. */
9
+ export function RemoveOptional(type, options = {}) {
10
+ return RemoveOptionalAction(type, options);
11
+ }
@@ -0,0 +1,11 @@
1
+ import { type TSchema, type TSchemaOptions } from '../types/schema.mjs';
2
+ import { type TDeferred } from '../types/deferred.mjs';
3
+ import { type TRemoveReadonlyAction } from '../engine/readonly/instantiate_remove.mjs';
4
+ /** Creates a deferred RemoveReadonly action. */
5
+ export type TRemoveReadonlyDeferred<Type extends TSchema> = (TDeferred<'RemoveReadonly', [Type]>);
6
+ /** Creates a deferred RemoveReadonly action. */
7
+ export declare function RemoveReadonlyDeferred<Type extends TSchema>(type: Type, options?: TSchemaOptions): TRemoveReadonlyDeferred<Type>;
8
+ /** Applies an RemoveReadonly action to a type. */
9
+ export type TRemoveReadonly<Type extends TSchema> = (TRemoveReadonlyAction<Type>);
10
+ /** Applies an RemoveReadonly action to a type. */
11
+ export declare function RemoveReadonly<Type extends TSchema>(type: Type, options?: TSchemaOptions): TRemoveReadonly<Type>;
@@ -0,0 +1,11 @@
1
+ // deno-fmt-ignore-file
2
+ import { Deferred } from '../types/deferred.mjs';
3
+ import { RemoveReadonlyAction } from '../engine/readonly/instantiate_remove.mjs';
4
+ /** Creates a deferred RemoveReadonly action. */
5
+ export function RemoveReadonlyDeferred(type, options = {}) {
6
+ return Deferred('RemoveReadonly', [type], options);
7
+ }
8
+ /** Applies an RemoveReadonly action to a type. */
9
+ export function RemoveReadonly(type, options = {}) {
10
+ return RemoveReadonlyAction(type, options);
11
+ }
@@ -1,5 +1,9 @@
1
- export * from './_optional.mjs';
2
- export * from './_readonly.mjs';
1
+ export * from './_add_immutable.mjs';
2
+ export * from './_add_readonly.mjs';
3
+ export * from './_add_optional.mjs';
4
+ export * from './_remove_immutable.mjs';
5
+ export * from './_remove_readonly.mjs';
6
+ export * from './_remove_optional.mjs';
3
7
  export * from './awaited.mjs';
4
8
  export * from './capitalize.mjs';
5
9
  export * from './conditional.mjs';
@@ -1,5 +1,9 @@
1
- export * from './_optional.mjs';
2
- export * from './_readonly.mjs';
1
+ export * from './_add_immutable.mjs';
2
+ export * from './_add_readonly.mjs';
3
+ export * from './_add_optional.mjs';
4
+ export * from './_remove_immutable.mjs';
5
+ export * from './_remove_readonly.mjs';
6
+ export * from './_remove_optional.mjs';
3
7
  export * from './awaited.mjs';
4
8
  export * from './capitalize.mjs';
5
9
  export * from './conditional.mjs';
@@ -1,25 +1,29 @@
1
1
  import { type TUnreachable } from '../../../system/unreachable/index.mjs';
2
- import { type TReadonly, type TReadonlyAdd, type TReadonlyRemove } from '../../types/_readonly.mjs';
3
- import { type TOptional, type TOptionalAdd, type TOptionalRemove } from '../../types/_optional.mjs';
2
+ import { type TReadonly } from '../../types/_readonly.mjs';
3
+ import { type TOptional } from '../../types/_optional.mjs';
4
4
  import { type TSchema } from '../../types/schema.mjs';
5
5
  import { type TProperties } from '../../types/properties.mjs';
6
6
  import { type TObject } from '../../types/object.mjs';
7
7
  import { type TNever } from '../../types/never.mjs';
8
8
  import { type TTuple } from '../../types/tuple.mjs';
9
+ import { type TAddReadonly } from '../../action/_add_readonly.mjs';
10
+ import { type TAddOptional } from '../../action/_add_optional.mjs';
11
+ import { type TRemoveReadonly } from '../../action/_remove_readonly.mjs';
12
+ import { type TRemoveOptional } from '../../action/_remove_optional.mjs';
9
13
  import { type TTupleElementsToProperties } from '../tuple/to_object.mjs';
10
14
  import { type TEvaluateIntersect } from './evaluate.mjs';
11
15
  type TIsReadonlyProperty<Left extends TSchema, Right extends TSchema> = (Left extends TReadonly<Left> ? Right extends TReadonly<Right> ? true : false : false);
12
16
  type TIsOptionalProperty<Left extends TSchema, Right extends TSchema> = (Left extends TOptional<Left> ? Right extends TOptional<Right> ? true : false : false);
13
- type TCompositeProperty<Left extends TSchema, Right extends TSchema, IsReadonly extends boolean = TIsReadonlyProperty<Left, Right>, IsOptional extends boolean = TIsOptionalProperty<Left, Right>, Evaluated extends TSchema = TEvaluateIntersect<[Left, Right]>, Property extends TSchema = TReadonlyRemove<TOptionalRemove<Evaluated>>> = ([
17
+ type TCompositeProperty<Left extends TSchema, Right extends TSchema, IsReadonly extends boolean = TIsReadonlyProperty<Left, Right>, IsOptional extends boolean = TIsOptionalProperty<Left, Right>, Evaluated extends TSchema = TEvaluateIntersect<[Left, Right]>, Property extends TSchema = TRemoveReadonly<TRemoveOptional<Evaluated>>> = ([
14
18
  IsReadonly,
15
19
  IsOptional
16
- ] extends [true, true] ? TReadonlyAdd<TOptionalAdd<Property>> : [
20
+ ] extends [true, true] ? TAddReadonly<TAddOptional<Property>> : [
17
21
  IsReadonly,
18
22
  IsOptional
19
- ] extends [true, false] ? TReadonlyAdd<Property> : [
23
+ ] extends [true, false] ? TAddReadonly<Property> : [
20
24
  IsReadonly,
21
25
  IsOptional
22
- ] extends [false, true] ? TOptionalAdd<Property> : Property);
26
+ ] extends [false, true] ? TAddOptional<Property> : Property);
23
27
  type TCompositePropertyKey<Left extends TProperties, Right extends TProperties, Key extends PropertyKey, Result extends TSchema = (Key extends keyof Left ? Key extends keyof Right ? TCompositeProperty<Left[Key], Right[Key]> : Left[Key] : Key extends keyof Right ? Right[Key] : TNever)> = Result;
24
28
  type TCompositeProperties<Left extends TProperties, Right extends TProperties, Result extends TProperties = {
25
29
  [Key in keyof (Right & Left)]: TCompositePropertyKey<Left, Right, Key>;
@@ -2,11 +2,15 @@
2
2
  // deno-lint-ignore-file
3
3
  import { Unreachable } from '../../../system/unreachable/index.mjs';
4
4
  import { Guard } from '../../../guard/index.mjs';
5
- import { ReadonlyAdd, ReadonlyRemove, IsReadonly } from '../../types/_readonly.mjs';
6
- import { OptionalAdd, OptionalRemove, IsOptional } from '../../types/_optional.mjs';
5
+ import { IsReadonly } from '../../types/_readonly.mjs';
6
+ import { IsOptional } from '../../types/_optional.mjs';
7
7
  import { Object, IsObject } from '../../types/object.mjs';
8
8
  import { Never } from '../../types/never.mjs';
9
9
  import { IsTuple } from '../../types/tuple.mjs';
10
+ import { AddReadonly } from '../../action/_add_readonly.mjs';
11
+ import { AddOptional } from '../../action/_add_optional.mjs';
12
+ import { RemoveReadonly } from '../../action/_remove_readonly.mjs';
13
+ import { RemoveOptional } from '../../action/_remove_optional.mjs';
10
14
  import { TupleElementsToProperties } from '../tuple/to_object.mjs';
11
15
  import { EvaluateIntersect } from './evaluate.mjs';
12
16
  function IsReadonlyProperty(left, right) {
@@ -20,10 +24,10 @@ function CompositeProperty(left, right) {
20
24
  const isOptional = IsOptionalProperty(left, right);
21
25
  const evaluated = EvaluateIntersect([left, right]);
22
26
  // Modifiers need to be discarded and re-applied
23
- const property = ReadonlyRemove(OptionalRemove(evaluated));
24
- return (isReadonly && isOptional ? ReadonlyAdd(OptionalAdd(property)) :
25
- isReadonly && !isOptional ? ReadonlyAdd(property) :
26
- !isReadonly && isOptional ? OptionalAdd(property) :
27
+ const property = RemoveReadonly(RemoveOptional(evaluated));
28
+ return (isReadonly && isOptional ? AddReadonly(AddOptional(property)) :
29
+ isReadonly && !isOptional ? AddReadonly(property) :
30
+ !isReadonly && isOptional ? AddOptional(property) :
27
31
  property);
28
32
  }
29
33
  function CompositePropertyKey(left, right, key) {
@@ -0,0 +1,10 @@
1
+ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
2
+ import { type TProperties } from '../../types/properties.mjs';
3
+ import { type TImmutable } from '../../types/_immutable.mjs';
4
+ import { type TState, type TInstantiateType } from '../instantiate.mjs';
5
+ type TAddImmutableOperation<Type extends TSchema, Result extends TSchema = '~immutable' extends keyof Type ? Type : TImmutable<Type>> = Result;
6
+ export type TAddImmutableAction<Type extends TSchema, Result extends TSchema = TAddImmutableOperation<Type>> = Result;
7
+ export declare function AddImmutableAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TAddImmutableAction<Type>;
8
+ export type TAddImmutableInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAddImmutableAction<InstantiateType>;
9
+ export declare function AddImmutableInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TAddImmutableInstantiate<Context, State, Type>;
10
+ export {};
@@ -0,0 +1,14 @@
1
+ // deno-fmt-ignore-file
2
+ import { Memory } from '../../../system/memory/index.mjs';
3
+ import { InstantiateType } from '../instantiate.mjs';
4
+ function AddImmutableOperation(type) {
5
+ return Memory.Update(type, { '~immutable': true }, {});
6
+ }
7
+ export function AddImmutableAction(type, options) {
8
+ const result = Memory.Update(AddImmutableOperation(type), {}, options);
9
+ return result;
10
+ }
11
+ export function AddImmutableInstantiate(context, state, type, options) {
12
+ const instantiatedType = InstantiateType(context, state, type);
13
+ return AddImmutableAction(instantiatedType, options);
14
+ }
@@ -0,0 +1,10 @@
1
+ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
2
+ import { type TProperties } from '../../types/properties.mjs';
3
+ import { type TImmutable } from '../../types/_immutable.mjs';
4
+ import { type TState, type TInstantiateType } from '../instantiate.mjs';
5
+ type TRemoveImmutableOperation<Type extends TSchema, Result extends TSchema = Type extends TImmutable<infer Type extends TSchema> ? Type : Type> = Result;
6
+ export type TRemoveImmutableAction<Type extends TSchema, Result extends TSchema = TRemoveImmutableOperation<Type>> = Result;
7
+ export declare function RemoveImmutableAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TRemoveImmutableAction<Type>;
8
+ export type TRemoveImmutableInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TRemoveImmutableAction<InstantiateType>;
9
+ export declare function RemoveImmutableInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TRemoveImmutableInstantiate<Context, State, Type>;
10
+ export {};
@@ -0,0 +1,14 @@
1
+ // deno-fmt-ignore-file
2
+ import { Memory } from '../../../system/memory/index.mjs';
3
+ import { InstantiateType } from '../instantiate.mjs';
4
+ function RemoveImmutableOperation(type) {
5
+ return Memory.Discard(type, ['~immutable']);
6
+ }
7
+ export function RemoveImmutableAction(type, options) {
8
+ const result = Memory.Update(RemoveImmutableOperation(type), {}, options);
9
+ return result;
10
+ }
11
+ export function RemoveImmutableInstantiate(context, state, type, options) {
12
+ const instantiatedType = InstantiateType(context, state, type);
13
+ return RemoveImmutableAction(instantiatedType, options);
14
+ }
@@ -1,6 +1,3 @@
1
- import { type TImmutable } from '../types/_immutable.mjs';
2
- import { type TOptional, type TOptionalAdd, type TOptionalRemove } from '../types/_optional.mjs';
3
- import { type TReadonly, type TReadonlyAdd, type TReadonlyRemove } from '../types/_readonly.mjs';
4
1
  import { type TSchema } from '../types/schema.mjs';
5
2
  import { type TArray } from '../types/array.mjs';
6
3
  import { type TAsyncIterator } from '../types/async_iterator.mjs';
@@ -20,8 +17,15 @@ import { type TTuple } from '../types/tuple.mjs';
20
17
  import { type TUnion } from '../types/union.mjs';
21
18
  import { type TRef } from '../types/ref.mjs';
22
19
  import { type TRest } from '../types/rest.mjs';
23
- import { type TReadonlyAddAction, type TReadonlyRemoveAction } from '../action/_readonly.mjs';
24
- import { type TOptionalAddAction, type TOptionalRemoveAction } from '../action/_optional.mjs';
20
+ import { type TAddImmutableInstantiate } from './immutable/instantiate_add.mjs';
21
+ import { type TRemoveImmutableInstantiate } from './immutable/instantiate_remove.mjs';
22
+ import { type TAddReadonlyInstantiate } from './readonly/instantiate_add.mjs';
23
+ import { type TRemoveReadonlyInstantiate } from './readonly/instantiate_remove.mjs';
24
+ import { type TAddOptionalInstantiate } from './optional/instantiate_add.mjs';
25
+ import { type TRemoveOptionalInstantiate } from './optional/instantiate_remove.mjs';
26
+ import { type TOptional } from '../types/_optional.mjs';
27
+ import { type TImmutable } from '../types/_immutable.mjs';
28
+ import { type TReadonly } from '../types/_readonly.mjs';
25
29
  import { type TAwaitedInstantiate } from './awaited/instantiate.mjs';
26
30
  import { type TCallInstantiate } from './call/instantiate.mjs';
27
31
  import { type TCapitalizeInstantiate } from './intrinsics/instantiate.mjs';
@@ -59,14 +63,6 @@ export interface TState<CallStack extends string[] = string[], Visited extends s
59
63
  export declare function State<CallStack extends string[], Visited extends string[]>(callstack: CallStack, visited: Visited): TState<CallStack, Visited>;
60
64
  export type TCanInstantiate<Types extends TSchema[]> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TRef ? false : TCanInstantiate<Right> : true;
61
65
  export declare function CanInstantiate<Types extends TSchema[]>(types: [...Types]): TCanInstantiate<Types>;
62
- type ModifierAction = 'add' | 'remove' | 'none';
63
- type TModifierActions<Type extends TSchema, Readonly extends ModifierAction, Optional extends ModifierAction> = (Type extends TReadonlyRemoveAction<infer Type extends TSchema> ? TModifierActions<Type, 'remove', Optional> : Type extends TOptionalRemoveAction<infer Type extends TSchema> ? TModifierActions<Type, Readonly, 'remove'> : Type extends TReadonlyAddAction<infer Type extends TSchema> ? TModifierActions<Type, 'add', Optional> : Type extends TOptionalAddAction<infer Type extends TSchema> ? TModifierActions<Type, Readonly, 'add'> : [
64
- Type,
65
- Readonly,
66
- Optional
67
- ]);
68
- type TApplyReadonly<Action extends ModifierAction, Type extends TSchema> = (Action extends 'remove' ? TReadonlyRemove<Type> : Action extends 'add' ? TReadonlyAdd<Type> : Type);
69
- type TApplyOptional<Action extends ModifierAction, Type extends TSchema> = (Action extends 'remove' ? TOptionalRemove<Type> : Action extends 'add' ? TOptionalAdd<Type> : Type);
70
66
  export type TInstantiateProperties<Context extends TProperties, State extends TState, Properties extends TProperties, Result extends TProperties = {
71
67
  [Key in keyof Properties]: TInstantiateType<Context, State, Properties[Key]>;
72
68
  }> = Result;
@@ -78,6 +74,24 @@ export declare function InstantiateTypes<Context extends TProperties, State exte
78
74
  type TInstantiateDeferred<Context extends TProperties, State extends TState, Action extends string, Parameters extends TSchema[]> = ([
79
75
  Action,
80
76
  Parameters
77
+ ] extends ['AddImmutable', [infer Type extends TSchema]] ? TAddImmutableInstantiate<Context, State, Type> : [
78
+ Action,
79
+ Parameters
80
+ ] extends ['RemoveImmutable', [infer Type extends TSchema]] ? TRemoveImmutableInstantiate<Context, State, Type> : [
81
+ Action,
82
+ Parameters
83
+ ] extends ['AddReadonly', [infer Type extends TSchema]] ? TAddReadonlyInstantiate<Context, State, Type> : [
84
+ Action,
85
+ Parameters
86
+ ] extends ['RemoveReadonly', [infer Type extends TSchema]] ? TRemoveReadonlyInstantiate<Context, State, Type> : [
87
+ Action,
88
+ Parameters
89
+ ] extends ['AddOptional', [infer Type extends TSchema]] ? TAddOptionalInstantiate<Context, State, Type> : [
90
+ Action,
91
+ Parameters
92
+ ] extends ['RemoveOptional', [infer Type extends TSchema]] ? TRemoveOptionalInstantiate<Context, State, Type> : [
93
+ Action,
94
+ Parameters
81
95
  ] extends ['Awaited', [infer Type extends TSchema]] ? TAwaitedInstantiate<Context, State, Type> : [
82
96
  Action,
83
97
  Parameters
@@ -157,8 +171,11 @@ type TInstantiateDeferred<Context extends TProperties, State extends TState, Act
157
171
  Action,
158
172
  Parameters
159
173
  ] extends ['With', [infer Type extends TSchema, infer Options extends TSchema]] ? TWithInstantiate<Context, State, Type, Options> : TDeferred<Action, Parameters>);
160
- export type TInstantiateType<Context extends TProperties, State extends TState, Input extends TSchema, Immutable extends boolean = Input extends TImmutable ? true : false, Modifiers extends [TSchema, ModifierAction, ModifierAction] = TModifierActions<Input, Input extends TReadonly<Input> ? 'add' : 'none', Input extends TOptional<Input> ? 'add' : 'none'>, Type extends TSchema = Modifiers[0], Instantiated extends TSchema = (Type extends TRef<infer Ref extends string> ? TRefInstantiate<Context, State, Type, Ref> : Type extends TArray<infer Type extends TSchema> ? TArray<TInstantiateType<Context, State, Type>> : Type extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TInstantiateType<Context, State, Type>> : Type extends TCall<infer Target extends TSchema, infer Parameters extends TSchema[]> ? TCallInstantiate<Context, State, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, InstanceType>> : Type extends TDeferred<infer Action extends string, infer Types extends TSchema[]> ? TInstantiateDeferred<Context, State, Action, Types> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, ReturnType>> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TDependent<TInstantiateType<Context, State, If>, TInstantiateType<Context, State, Then>, TInstantiateType<Context, State, Else>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TInstantiateTypes<Context, State, Types>> : Type extends TIterator<infer Type extends TSchema> ? TIterator<TInstantiateType<Context, State, Type>> : Type extends TObject<infer Properties extends TProperties> ? TObject<TInstantiateProperties<Context, State, Properties>> : Type extends TPromise<infer Type extends TSchema> ? TPromise<TInstantiateType<Context, State, Type>> : Type extends TRecord<infer Key extends string, infer Type extends TSchema> ? TRecord<Key, TInstantiateType<Context, State, Type>> : Type extends TRest<infer Type extends TSchema> ? TRest<TInstantiateType<Context, State, Type>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TInstantiateElements<Context, State, Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TInstantiateTypes<Context, State, Types>> : Type), WithImmutable extends TSchema = Immutable extends true ? TImmutable<Instantiated> : Instantiated, WithModifiers extends TSchema = TApplyReadonly<Modifiers[1], TApplyOptional<Modifiers[2], WithImmutable>>> = WithModifiers;
161
- export declare function InstantiateType<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, input: Type): TInstantiateType<Context, State, Type>;
174
+ export type TInstantiateImmediate<Context extends TProperties, State extends TState, Type extends TSchema, Result extends TSchema = (Type extends TRef<infer Ref extends string> ? TRefInstantiate<Context, State, Type, Ref> : Type extends TArray<infer Type extends TSchema> ? TArray<TInstantiateType<Context, State, Type>> : Type extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TInstantiateType<Context, State, Type>> : Type extends TCall<infer Target extends TSchema, infer Parameters extends TSchema[]> ? TCallInstantiate<Context, State, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, InstanceType>> : Type extends TDeferred<infer Action extends string, infer Types extends TSchema[]> ? TInstantiateDeferred<Context, State, Action, Types> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, ReturnType>> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TDependent<TInstantiateType<Context, State, If>, TInstantiateType<Context, State, Then>, TInstantiateType<Context, State, Else>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TInstantiateTypes<Context, State, Types>> : Type extends TIterator<infer Type extends TSchema> ? TIterator<TInstantiateType<Context, State, Type>> : Type extends TObject<infer Properties extends TProperties> ? TObject<TInstantiateProperties<Context, State, Properties>> : Type extends TPromise<infer Type extends TSchema> ? TPromise<TInstantiateType<Context, State, Type>> : Type extends TRecord<infer Key extends string, infer Type extends TSchema> ? TRecord<Key, TInstantiateType<Context, State, Type>> : Type extends TRest<infer Type extends TSchema> ? TRest<TInstantiateType<Context, State, Type>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TInstantiateElements<Context, State, Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TInstantiateTypes<Context, State, Types>> : Type)> = Result;
175
+ export declare function InstantiateImmediate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type): TInstantiateImmediate<Context, State, Type>;
176
+ type TWithModifiers<Type extends TSchema, InstantiatedType extends TSchema, WithImmutable extends TSchema = Type extends TImmutable ? TImmutable<InstantiatedType> : InstantiatedType, WithReadonly extends TSchema = Type extends TReadonly ? TReadonly<WithImmutable> : WithImmutable, WithOptional extends TSchema = Type extends TOptional ? TOptional<WithReadonly> : WithReadonly> = WithOptional;
177
+ export type TInstantiateType<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateImmediate<Context, State, Type>, WithModifiers extends TSchema = Type extends TDeferred ? InstantiatedType : TWithModifiers<Type, InstantiatedType>> = WithModifiers;
178
+ export declare function InstantiateType<Context extends TProperties, State extends TState, Type extends TSchema>(context: TProperties, state: TState, type: Type): TInstantiateType<Context, State, Type>;
162
179
  /** Instantiates computed schematics using the given context and type. */
163
180
  export type TInstantiate<Context extends TProperties, Type extends TSchema> = (TInstantiateType<Context, TState<[], []>, Type>);
164
181
  /** Instantiates computed schematics using the given context and type. */
@@ -2,12 +2,6 @@
2
2
  // deno-lint-ignore-file
3
3
  import { Guard } from '../../guard/index.mjs';
4
4
  // ------------------------------------------------------------------
5
- // Modifiers
6
- // ------------------------------------------------------------------
7
- import { IsImmutable, Immutable } from '../types/_immutable.mjs';
8
- import { IsOptional, OptionalAdd, OptionalRemove } from '../types/_optional.mjs';
9
- import { IsReadonly, ReadonlyAdd, ReadonlyRemove } from '../types/_readonly.mjs';
10
- // ------------------------------------------------------------------
11
5
  // Types
12
6
  // ------------------------------------------------------------------
13
7
  import { IsBase } from '../types/base.mjs';
@@ -28,10 +22,17 @@ import { Union, IsUnion, UnionOptions } from '../types/union.mjs';
28
22
  import { IsRef } from '../types/ref.mjs';
29
23
  import { Rest, IsRest } from '../types/rest.mjs';
30
24
  // ------------------------------------------------------------------
31
- // Modifier Actions
25
+ // Modifier Instantiate
32
26
  // ------------------------------------------------------------------
33
- import { IsReadonlyAddAction, IsReadonlyRemoveAction } from '../action/_readonly.mjs';
34
- import { IsOptionalAddAction, IsOptionalRemoveAction } from '../action/_optional.mjs';
27
+ import { AddImmutableInstantiate } from './immutable/instantiate_add.mjs';
28
+ import { RemoveImmutableInstantiate } from './immutable/instantiate_remove.mjs';
29
+ import { AddReadonlyInstantiate } from './readonly/instantiate_add.mjs';
30
+ import { RemoveReadonlyInstantiate } from './readonly/instantiate_remove.mjs';
31
+ import { AddOptionalInstantiate } from './optional/instantiate_add.mjs';
32
+ import { RemoveOptionalInstantiate } from './optional/instantiate_remove.mjs';
33
+ import { Optional, IsOptional } from '../types/_optional.mjs';
34
+ import { Immutable, IsImmutable } from '../types/_immutable.mjs';
35
+ import { Readonly, IsReadonly } from '../types/_readonly.mjs';
35
36
  // ------------------------------------------------------------------
36
37
  // Instantiate
37
38
  // ------------------------------------------------------------------
@@ -73,23 +74,6 @@ export function CanInstantiate(types) {
73
74
  ? false
74
75
  : CanInstantiate(right), () => true);
75
76
  }
76
- function ModifierActions(type, readonly, optional) {
77
- return (IsReadonlyRemoveAction(type) ? ModifierActions(type.type, 'remove', optional) :
78
- IsOptionalRemoveAction(type) ? ModifierActions(type.type, readonly, 'remove') :
79
- IsReadonlyAddAction(type) ? ModifierActions(type.type, 'add', optional) :
80
- IsOptionalAddAction(type) ? ModifierActions(type.type, readonly, 'add') :
81
- [type, readonly, optional]);
82
- }
83
- function ApplyReadonly(action, type) {
84
- return (Guard.IsEqual(action, 'remove') ? ReadonlyRemove(type) :
85
- Guard.IsEqual(action, 'add') ? ReadonlyAdd(type) :
86
- type);
87
- }
88
- function ApplyOptional(action, type) {
89
- return (Guard.IsEqual(action, 'remove') ? OptionalRemove(type) :
90
- Guard.IsEqual(action, 'add') ? OptionalAdd(type) :
91
- type);
92
- }
93
77
  export function InstantiateProperties(context, state, properties) {
94
78
  return Guard.Keys(properties).reduce((result, key) => {
95
79
  return { ...result, [key]: InstantiateType(context, state, properties[key]) };
@@ -104,40 +88,47 @@ export function InstantiateTypes(context, state, types) {
104
88
  return types.map(type => InstantiateType(context, state, type));
105
89
  }
106
90
  function InstantiateDeferred(context, state, action, parameters, options) {
107
- return (Guard.IsEqual(action, 'Awaited') ? AwaitedInstantiate(context, state, parameters[0], options) :
108
- Guard.IsEqual(action, 'Capitalize') ? CapitalizeInstantiate(context, state, parameters[0], options) :
109
- Guard.IsEqual(action, 'Conditional') ? ConditionalInstantiate(context, state, parameters[0], parameters[1], parameters[2], parameters[3], options) :
110
- Guard.IsEqual(action, 'ConstructorParameters') ? ConstructorParametersInstantiate(context, state, parameters[0], options) :
111
- Guard.IsEqual(action, 'Evaluate') ? EvaluateInstantiate(context, state, parameters[0], options) :
112
- Guard.IsEqual(action, 'Exclude') ? ExcludeInstantiate(context, state, parameters[0], parameters[1], options) :
113
- Guard.IsEqual(action, 'Extract') ? ExtractInstantiate(context, state, parameters[0], parameters[1], options) :
114
- Guard.IsEqual(action, 'Index') ? IndexInstantiate(context, state, parameters[0], parameters[1], options) :
115
- Guard.IsEqual(action, 'InstanceType') ? InstanceTypeInstantiate(context, state, parameters[0], options) :
116
- Guard.IsEqual(action, 'Interface') ? InterfaceInstantiate(context, state, parameters[0], parameters[1], options) :
117
- Guard.IsEqual(action, 'KeyOf') ? KeyOfInstantiate(context, state, parameters[0], options) :
118
- Guard.IsEqual(action, 'Lowercase') ? LowercaseInstantiate(context, state, parameters[0], options) :
119
- Guard.IsEqual(action, 'Mapped') ? MappedInstantiate(context, state, parameters[0], parameters[1], parameters[2], parameters[3], options) :
120
- Guard.IsEqual(action, 'Module') ? ModuleInstantiate(context, state, parameters[0], options) :
121
- Guard.IsEqual(action, 'NonNullable') ? NonNullableInstantiate(context, state, parameters[0], options) :
122
- Guard.IsEqual(action, 'Pick') ? PickInstantiate(context, state, parameters[0], parameters[1], options) :
123
- Guard.IsEqual(action, 'Parameters') ? ParametersInstantiate(context, state, parameters[0], options) :
124
- Guard.IsEqual(action, 'Partial') ? PartialInstantiate(context, state, parameters[0], options) :
125
- Guard.IsEqual(action, 'Omit') ? OmitInstantiate(context, state, parameters[0], parameters[1], options) :
126
- Guard.IsEqual(action, 'ReadonlyObject') ? ReadonlyObjectInstantiate(context, state, parameters[0], options) :
127
- Guard.IsEqual(action, 'Record') ? RecordInstantiate(context, state, parameters[0], parameters[1], options) :
128
- Guard.IsEqual(action, 'Required') ? RequiredInstantiate(context, state, parameters[0], options) :
129
- Guard.IsEqual(action, 'ReturnType') ? ReturnTypeInstantiate(context, state, parameters[0], options) :
130
- Guard.IsEqual(action, 'TemplateLiteral') ? TemplateLiteralInstantiate(context, state, parameters[0], options) :
131
- Guard.IsEqual(action, 'Uncapitalize') ? UncapitalizeInstantiate(context, state, parameters[0], options) :
132
- Guard.IsEqual(action, 'Uppercase') ? UppercaseInstantiate(context, state, parameters[0], options) :
133
- Guard.IsEqual(action, 'With') ? WithInstantiate(context, state, parameters[0], parameters[1]) :
134
- Deferred(action, parameters, options));
91
+ return (
92
+ // Modifier Actions
93
+ Guard.IsEqual(action, 'AddImmutable') ? AddImmutableInstantiate(context, state, parameters[0], options) :
94
+ Guard.IsEqual(action, 'RemoveImmutable') ? RemoveImmutableInstantiate(context, state, parameters[0], options) :
95
+ Guard.IsEqual(action, 'AddReadonly') ? AddReadonlyInstantiate(context, state, parameters[0], options) :
96
+ Guard.IsEqual(action, 'RemoveReadonly') ? RemoveReadonlyInstantiate(context, state, parameters[0], options) :
97
+ Guard.IsEqual(action, 'AddOptional') ? AddOptionalInstantiate(context, state, parameters[0], options) :
98
+ Guard.IsEqual(action, 'RemoveOptional') ? RemoveOptionalInstantiate(context, state, parameters[0], options) :
99
+ // Actions
100
+ Guard.IsEqual(action, 'Awaited') ? AwaitedInstantiate(context, state, parameters[0], options) :
101
+ Guard.IsEqual(action, 'Capitalize') ? CapitalizeInstantiate(context, state, parameters[0], options) :
102
+ Guard.IsEqual(action, 'Conditional') ? ConditionalInstantiate(context, state, parameters[0], parameters[1], parameters[2], parameters[3], options) :
103
+ Guard.IsEqual(action, 'ConstructorParameters') ? ConstructorParametersInstantiate(context, state, parameters[0], options) :
104
+ Guard.IsEqual(action, 'Evaluate') ? EvaluateInstantiate(context, state, parameters[0], options) :
105
+ Guard.IsEqual(action, 'Exclude') ? ExcludeInstantiate(context, state, parameters[0], parameters[1], options) :
106
+ Guard.IsEqual(action, 'Extract') ? ExtractInstantiate(context, state, parameters[0], parameters[1], options) :
107
+ Guard.IsEqual(action, 'Index') ? IndexInstantiate(context, state, parameters[0], parameters[1], options) :
108
+ Guard.IsEqual(action, 'InstanceType') ? InstanceTypeInstantiate(context, state, parameters[0], options) :
109
+ Guard.IsEqual(action, 'Interface') ? InterfaceInstantiate(context, state, parameters[0], parameters[1], options) :
110
+ Guard.IsEqual(action, 'KeyOf') ? KeyOfInstantiate(context, state, parameters[0], options) :
111
+ Guard.IsEqual(action, 'Lowercase') ? LowercaseInstantiate(context, state, parameters[0], options) :
112
+ Guard.IsEqual(action, 'Mapped') ? MappedInstantiate(context, state, parameters[0], parameters[1], parameters[2], parameters[3], options) :
113
+ Guard.IsEqual(action, 'Module') ? ModuleInstantiate(context, state, parameters[0], options) :
114
+ Guard.IsEqual(action, 'NonNullable') ? NonNullableInstantiate(context, state, parameters[0], options) :
115
+ Guard.IsEqual(action, 'Pick') ? PickInstantiate(context, state, parameters[0], parameters[1], options) :
116
+ Guard.IsEqual(action, 'Parameters') ? ParametersInstantiate(context, state, parameters[0], options) :
117
+ Guard.IsEqual(action, 'Partial') ? PartialInstantiate(context, state, parameters[0], options) :
118
+ Guard.IsEqual(action, 'Omit') ? OmitInstantiate(context, state, parameters[0], parameters[1], options) :
119
+ Guard.IsEqual(action, 'ReadonlyObject') ? ReadonlyObjectInstantiate(context, state, parameters[0], options) :
120
+ Guard.IsEqual(action, 'Record') ? RecordInstantiate(context, state, parameters[0], parameters[1], options) :
121
+ Guard.IsEqual(action, 'Required') ? RequiredInstantiate(context, state, parameters[0], options) :
122
+ Guard.IsEqual(action, 'ReturnType') ? ReturnTypeInstantiate(context, state, parameters[0], options) :
123
+ Guard.IsEqual(action, 'TemplateLiteral') ? TemplateLiteralInstantiate(context, state, parameters[0], options) :
124
+ Guard.IsEqual(action, 'Uncapitalize') ? UncapitalizeInstantiate(context, state, parameters[0], options) :
125
+ Guard.IsEqual(action, 'Uppercase') ? UppercaseInstantiate(context, state, parameters[0], options) :
126
+ Guard.IsEqual(action, 'With') ? WithInstantiate(context, state, parameters[0], parameters[1]) :
127
+ Deferred(action, parameters, options));
135
128
  }
136
- export function InstantiateType(context, state, input) {
137
- const immutable = IsImmutable(input);
138
- const modifiers = ModifierActions(input, IsReadonly(input) ? 'add' : 'none', IsOptional(input) ? 'add' : 'none');
139
- const type = IsBase(modifiers[0]) ? modifiers[0].Clone() : modifiers[0];
140
- const instantiated = (IsRef(type) ? RefInstantiate(context, state, type, type.$ref) :
129
+ export function InstantiateImmediate(context, state, type) {
130
+ type = (IsBase(type) ? type.Clone() : type);
131
+ const result = (IsRef(type) ? RefInstantiate(context, state, type, type.$ref) :
141
132
  IsArray(type) ? _Array_(InstantiateType(context, state, type.items), ArrayOptions(type)) :
142
133
  IsAsyncIterator(type) ? AsyncIterator(InstantiateType(context, state, type.iteratorItems), AsyncIteratorOptions(type)) :
143
134
  IsCall(type) ? CallInstantiate(context, state, type.target, type.arguments) :
@@ -154,8 +145,17 @@ export function InstantiateType(context, state, input) {
154
145
  IsTuple(type) ? Tuple(InstantiateElements(context, state, type.items), TupleOptions(type)) :
155
146
  IsUnion(type) ? Union(InstantiateTypes(context, state, type.anyOf), UnionOptions(type)) :
156
147
  type);
157
- const withImmutable = immutable ? Immutable(instantiated) : instantiated;
158
- const withModifiers = ApplyReadonly(modifiers[1], ApplyOptional(modifiers[2], withImmutable));
148
+ return result;
149
+ }
150
+ function WithModifiers(type, instantiatedType) {
151
+ const withImmutable = IsImmutable(type) ? Immutable(instantiatedType) : instantiatedType;
152
+ const withReadonly = IsReadonly(type) ? Readonly(withImmutable) : withImmutable;
153
+ const withOptional = IsOptional(type) ? Optional(withReadonly) : withReadonly;
154
+ return withOptional;
155
+ }
156
+ export function InstantiateType(context, state, type) {
157
+ const instantiatedType = InstantiateImmediate(context, state, type);
158
+ const withModifiers = IsDeferred(type) ? instantiatedType : WithModifiers(type, instantiatedType);
159
159
  return withModifiers;
160
160
  }
161
161
  /** Instantiates computed schematics using the given context and type. */
@@ -0,0 +1,10 @@
1
+ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
2
+ import { type TProperties } from '../../types/properties.mjs';
3
+ import { type TOptional } from '../../types/_optional.mjs';
4
+ import { type TState, type TInstantiateType } from '../instantiate.mjs';
5
+ type TAddOptionalOperation<Type extends TSchema, Result extends TSchema = `~optional` extends keyof Type ? Type : TOptional<Type>> = Result;
6
+ export type TAddOptionalAction<Type extends TSchema, Result extends TSchema = TAddOptionalOperation<Type>> = Result;
7
+ export declare function AddOptionalAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TAddOptionalAction<Type>;
8
+ export type TAddOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAddOptionalAction<InstantiateType>;
9
+ export declare function AddOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TAddOptionalInstantiate<Context, State, Type>;
10
+ export {};
@@ -0,0 +1,14 @@
1
+ // deno-fmt-ignore-file
2
+ import { Memory } from '../../../system/memory/index.mjs';
3
+ import { InstantiateType } from '../instantiate.mjs';
4
+ function AddOptionalOperation(type) {
5
+ return Memory.Update(type, { '~optional': true }, {});
6
+ }
7
+ export function AddOptionalAction(type, options) {
8
+ const result = Memory.Update(AddOptionalOperation(type), {}, options);
9
+ return result;
10
+ }
11
+ export function AddOptionalInstantiate(context, state, type, options) {
12
+ const instantiatedType = InstantiateType(context, state, type);
13
+ return AddOptionalAction(instantiatedType, options);
14
+ }