@sinclair/typebox 0.34.16 → 0.34.17

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 (68) hide show
  1. package/build/cjs/compiler/compiler.js +5 -0
  2. package/build/cjs/errors/errors.js +3 -0
  3. package/build/cjs/index.d.ts +3 -0
  4. package/build/cjs/index.js +3 -0
  5. package/build/cjs/syntax/runtime.d.ts +3 -1
  6. package/build/cjs/syntax/runtime.js +33 -3
  7. package/build/cjs/syntax/static.d.ts +22 -2
  8. package/build/cjs/type/argument/argument.d.ts +9 -0
  9. package/build/cjs/type/argument/argument.js +10 -0
  10. package/build/cjs/type/argument/index.d.ts +1 -0
  11. package/build/cjs/type/argument/index.js +18 -0
  12. package/build/cjs/type/guard/kind.d.ts +9 -6
  13. package/build/cjs/type/guard/kind.js +6 -0
  14. package/build/cjs/type/guard/type.d.ts +9 -6
  15. package/build/cjs/type/guard/type.js +9 -0
  16. package/build/cjs/type/index.d.ts +2 -0
  17. package/build/cjs/type/index.js +2 -0
  18. package/build/cjs/type/instantiate/index.d.ts +1 -0
  19. package/build/cjs/type/instantiate/index.js +18 -0
  20. package/build/cjs/type/instantiate/instantiate.d.ts +25 -0
  21. package/build/cjs/type/instantiate/instantiate.js +32 -0
  22. package/build/cjs/type/record/record.d.ts +16 -1
  23. package/build/cjs/type/record/record.js +53 -23
  24. package/build/cjs/type/remap/index.d.ts +1 -0
  25. package/build/cjs/type/remap/index.js +18 -0
  26. package/build/cjs/type/remap/remap.d.ts +19 -0
  27. package/build/cjs/type/remap/remap.js +35 -0
  28. package/build/cjs/type/type/javascript.d.ts +6 -0
  29. package/build/cjs/type/type/javascript.js +44 -34
  30. package/build/cjs/type/type/type.d.ts +3 -0
  31. package/build/cjs/type/type/type.js +123 -117
  32. package/build/cjs/value/check/check.js +5 -0
  33. package/build/cjs/value/create/create.js +5 -0
  34. package/build/esm/compiler/compiler.mjs +5 -0
  35. package/build/esm/errors/errors.mjs +3 -0
  36. package/build/esm/index.d.mts +3 -0
  37. package/build/esm/index.mjs +3 -0
  38. package/build/esm/syntax/runtime.d.mts +3 -1
  39. package/build/esm/syntax/runtime.mjs +33 -3
  40. package/build/esm/syntax/static.d.mts +22 -2
  41. package/build/esm/type/argument/argument.d.mts +9 -0
  42. package/build/esm/type/argument/argument.mjs +6 -0
  43. package/build/esm/type/argument/index.d.mts +1 -0
  44. package/build/esm/type/argument/index.mjs +1 -0
  45. package/build/esm/type/guard/kind.d.mts +9 -6
  46. package/build/esm/type/guard/kind.mjs +5 -0
  47. package/build/esm/type/guard/type.d.mts +9 -6
  48. package/build/esm/type/guard/type.mjs +8 -0
  49. package/build/esm/type/index.d.mts +2 -0
  50. package/build/esm/type/index.mjs +2 -0
  51. package/build/esm/type/instantiate/index.d.mts +1 -0
  52. package/build/esm/type/instantiate/index.mjs +1 -0
  53. package/build/esm/type/instantiate/instantiate.d.mts +25 -0
  54. package/build/esm/type/instantiate/instantiate.mjs +28 -0
  55. package/build/esm/type/record/record.d.mts +16 -1
  56. package/build/esm/type/record/record.mjs +35 -8
  57. package/build/esm/type/remap/index.d.mts +1 -0
  58. package/build/esm/type/remap/index.mjs +1 -0
  59. package/build/esm/type/remap/remap.d.mts +19 -0
  60. package/build/esm/type/remap/remap.mjs +31 -0
  61. package/build/esm/type/type/javascript.d.mts +6 -0
  62. package/build/esm/type/type/javascript.mjs +10 -0
  63. package/build/esm/type/type/type.d.mts +3 -0
  64. package/build/esm/type/type/type.mjs +3 -0
  65. package/build/esm/value/check/check.mjs +5 -0
  66. package/build/esm/value/create/create.mjs +5 -0
  67. package/package.json +1 -1
  68. package/readme.md +36 -39
@@ -209,6 +209,9 @@ var TypeCompiler;
209
209
  function* FromAny(schema, references, value) {
210
210
  yield 'true';
211
211
  }
212
+ function* FromArgument(schema, references, value) {
213
+ yield 'true';
214
+ }
212
215
  function* FromArray(schema, references, value) {
213
216
  yield `Array.isArray(${value})`;
214
217
  const [parameter, accumulator] = [CreateParameter('value', 'any'), CreateParameter('acc', 'number')];
@@ -493,6 +496,8 @@ var TypeCompiler;
493
496
  switch (schema_[index_7.Kind]) {
494
497
  case 'Any':
495
498
  return yield* FromAny(schema_, references_, value);
499
+ case 'Argument':
500
+ return yield* FromArgument(schema_, references_, value);
496
501
  case 'Array':
497
502
  return yield* FromArray(schema_, references_, value);
498
503
  case 'AsyncIterator':
@@ -145,6 +145,7 @@ function Create(errorType, schema, path, value, errors = []) {
145
145
  // Types
146
146
  // --------------------------------------------------------------------------
147
147
  function* FromAny(schema, references, path, value) { }
148
+ function* FromArgument(schema, references, path, value) { }
148
149
  function* FromArray(schema, references, path, value) {
149
150
  if (!(0, index_10.IsArray)(value)) {
150
151
  return yield Create(ValueErrorType.Array, schema, path, value);
@@ -521,6 +522,8 @@ function* Visit(schema, references, path, value) {
521
522
  switch (schema_[index_8.Kind]) {
522
523
  case 'Any':
523
524
  return yield* FromAny(schema_, references_, path, value);
525
+ case 'Argument':
526
+ return yield* FromArgument(schema_, references_, path, value);
524
527
  case 'Array':
525
528
  return yield* FromArray(schema_, references_, path, value);
526
529
  case 'AsyncIterator':
@@ -9,6 +9,7 @@ export * from './type/sets/index';
9
9
  export * from './type/symbols/index';
10
10
  export * from './type/any/index';
11
11
  export * from './type/array/index';
12
+ export * from './type/argument/index';
12
13
  export * from './type/async-iterator/index';
13
14
  export * from './type/awaited/index';
14
15
  export * from './type/bigint/index';
@@ -25,6 +26,7 @@ export * from './type/extract/index';
25
26
  export * from './type/function/index';
26
27
  export * from './type/indexed/index';
27
28
  export * from './type/instance-type/index';
29
+ export * from './type/instantiate/index';
28
30
  export * from './type/integer/index';
29
31
  export * from './type/intersect/index';
30
32
  export * from './type/iterator/index';
@@ -50,6 +52,7 @@ export * from './type/record/index';
50
52
  export * from './type/recursive/index';
51
53
  export * from './type/ref/index';
52
54
  export * from './type/regexp/index';
55
+ export * from './type/remap/index';
53
56
  export * from './type/required/index';
54
57
  export * from './type/rest/index';
55
58
  export * from './type/return-type/index';
@@ -32,6 +32,7 @@ __exportStar(require("./type/symbols/index"), exports);
32
32
  // ------------------------------------------------------------------
33
33
  __exportStar(require("./type/any/index"), exports);
34
34
  __exportStar(require("./type/array/index"), exports);
35
+ __exportStar(require("./type/argument/index"), exports);
35
36
  __exportStar(require("./type/async-iterator/index"), exports);
36
37
  __exportStar(require("./type/awaited/index"), exports);
37
38
  __exportStar(require("./type/bigint/index"), exports);
@@ -48,6 +49,7 @@ __exportStar(require("./type/extract/index"), exports);
48
49
  __exportStar(require("./type/function/index"), exports);
49
50
  __exportStar(require("./type/indexed/index"), exports);
50
51
  __exportStar(require("./type/instance-type/index"), exports);
52
+ __exportStar(require("./type/instantiate/index"), exports);
51
53
  __exportStar(require("./type/integer/index"), exports);
52
54
  __exportStar(require("./type/intersect/index"), exports);
53
55
  __exportStar(require("./type/iterator/index"), exports);
@@ -73,6 +75,7 @@ __exportStar(require("./type/record/index"), exports);
73
75
  __exportStar(require("./type/recursive/index"), exports);
74
76
  __exportStar(require("./type/ref/index"), exports);
75
77
  __exportStar(require("./type/regexp/index"), exports);
78
+ __exportStar(require("./type/remap/index"), exports);
76
79
  __exportStar(require("./type/required/index"), exports);
77
80
  __exportStar(require("./type/rest/index"), exports);
78
81
  __exportStar(require("./type/return-type/index"), exports);
@@ -2,7 +2,7 @@ import { Runtime } from '../parser/index';
2
2
  import * as t from '../type/index';
3
3
  export declare const Module: Runtime.Module<{
4
4
  Literal: Runtime.IUnion<t.TLiteral<string> | t.TLiteral<number> | t.TLiteral<boolean>>;
5
- Keyword: Runtime.IUnion<t.TAny | t.TNever | t.TString | t.TBoolean | t.TNumber | t.TInteger | t.TBigInt | t.TNull | t.TSymbol | t.TUndefined | t.TUnknown | t.TVoid>;
5
+ Keyword: Runtime.IUnion<t.TAny | t.TBoolean | t.TBigInt | t.TNever | t.TString | t.TNumber | t.TInteger | t.TNull | t.TSymbol | t.TUndefined | t.TUnknown | t.TVoid>;
6
6
  KeyOf: Runtime.IUnion<boolean>;
7
7
  IndexArray: Runtime.IUnion<unknown[]>;
8
8
  Extends: Runtime.IUnion<unknown[]>;
@@ -31,6 +31,7 @@ export declare const Module: Runtime.Module<{
31
31
  Mapped: Runtime.ITuple<t.TLiteral<"Mapped types not supported">>;
32
32
  AsyncIterator: Runtime.ITuple<t.TAsyncIterator<t.TSchema>>;
33
33
  Iterator: Runtime.ITuple<t.TIterator<t.TSchema>>;
34
+ Argument: Runtime.ITuple<t.TNever | t.TArgument<number>>;
34
35
  Awaited: Runtime.ITuple<t.TSchema>;
35
36
  Array: Runtime.ITuple<t.TArray<t.TSchema>>;
36
37
  Record: Runtime.ITuple<t.TNever>;
@@ -51,5 +52,6 @@ export declare const Module: Runtime.Module<{
51
52
  Uncapitalize: Runtime.ITuple<t.TSchema>;
52
53
  Date: Runtime.IConst<t.TDate>;
53
54
  Uint8Array: Runtime.IConst<t.TUint8Array>;
55
+ GenericReference: Runtime.ITuple<t.TSchema>;
54
56
  Reference: Runtime.IIdent<t.TSchema>;
55
57
  }>;
@@ -34,16 +34,28 @@ function DestructureRight(values) {
34
34
  : [values, undefined];
35
35
  }
36
36
  // ------------------------------------------------------------------
37
- // Deref
37
+ // Dereference
38
38
  // ------------------------------------------------------------------
39
- const Deref = (context, key) => {
39
+ const Dereference = (context, key) => {
40
40
  return key in context ? context[key] : t.Ref(key);
41
41
  };
42
42
  // ------------------------------------------------------------------
43
+ // GenericReference
44
+ // ------------------------------------------------------------------
45
+ function GenericReferenceMapping(results, context) {
46
+ const target = Dereference(context, results[0]);
47
+ return t.Instantiate(target, results[2]);
48
+ }
49
+ const GenericReference = index_1.Runtime.Tuple([index_1.Runtime.Ident(), index_1.Runtime.Const(LAngle), index_1.Runtime.Ref('Elements'), index_1.Runtime.Const(RAngle)], (results, context) => GenericReferenceMapping(results, context));
50
+ // ------------------------------------------------------------------
43
51
  // Reference
44
52
  // ------------------------------------------------------------------
53
+ function ReferenceMapping(result, context) {
54
+ const target = Dereference(context, result);
55
+ return target;
56
+ }
45
57
  // prettier-ignore
46
- const Reference = index_1.Runtime.Ident((value, context) => Deref(context, value));
58
+ const Reference = index_1.Runtime.Ident((result, context) => ReferenceMapping(result, context));
47
59
  // ------------------------------------------------------------------
48
60
  // Literal
49
61
  // ------------------------------------------------------------------
@@ -135,6 +147,7 @@ const Base = index_1.Runtime.Union([
135
147
  index_1.Runtime.Ref('FunctionParameters'),
136
148
  index_1.Runtime.Ref('InstanceType'),
137
149
  index_1.Runtime.Ref('ReturnType'),
150
+ index_1.Runtime.Ref('Argument'),
138
151
  index_1.Runtime.Ref('Awaited'),
139
152
  index_1.Runtime.Ref('Array'),
140
153
  index_1.Runtime.Ref('Record'),
@@ -151,6 +164,7 @@ const Base = index_1.Runtime.Union([
151
164
  index_1.Runtime.Ref('Uncapitalize'),
152
165
  index_1.Runtime.Ref('Date'),
153
166
  index_1.Runtime.Ref('Uint8Array'),
167
+ index_1.Runtime.Ref('GenericReference'),
154
168
  index_1.Runtime.Ref('Reference')
155
169
  ])])
156
170
  ], BaseMapping);
@@ -417,6 +431,20 @@ const ReturnType = index_1.Runtime.Tuple([
417
431
  index_1.Runtime.Const(RAngle),
418
432
  ], value => t.ReturnType(value[2]));
419
433
  // ------------------------------------------------------------------
434
+ // Argument
435
+ // ------------------------------------------------------------------
436
+ // prettier-ignore
437
+ const Argument = index_1.Runtime.Tuple([
438
+ index_1.Runtime.Const('Argument'),
439
+ index_1.Runtime.Const(LAngle),
440
+ index_1.Runtime.Ref('Type'),
441
+ index_1.Runtime.Const(RAngle),
442
+ ], results => {
443
+ return t.KindGuard.IsLiteralNumber(results[2])
444
+ ? t.Argument(Math.trunc(results[2].const))
445
+ : t.Never();
446
+ });
447
+ // ------------------------------------------------------------------
420
448
  // Awaited
421
449
  // ------------------------------------------------------------------
422
450
  // prettier-ignore
@@ -610,6 +638,7 @@ exports.Module = new index_1.Runtime.Module({
610
638
  Mapped,
611
639
  AsyncIterator,
612
640
  Iterator,
641
+ Argument,
613
642
  Awaited,
614
643
  Array,
615
644
  Record,
@@ -630,5 +659,6 @@ exports.Module = new index_1.Runtime.Module({
630
659
  Uncapitalize,
631
660
  Date,
632
661
  Uint8Array,
662
+ GenericReference,
633
663
  Reference,
634
664
  });
@@ -41,9 +41,18 @@ type Delimit<Parser extends Static.IParser, Delimiter extends Static.IParser> =
41
41
  Static.Tuple<[Parser, DelimitTail<Parser, Delimiter>]>,
42
42
  Static.Tuple<[]>
43
43
  ], DelimitMapping>);
44
- type Deref<Context extends t.TProperties, Ref extends string> = (Ref extends keyof Context ? Context[Ref] : t.TRef<Ref>);
44
+ type Dereference<Context extends t.TProperties, Ref extends string> = (Ref extends keyof Context ? Context[Ref] : t.TRef<Ref>);
45
+ interface GenericReferenceMapping extends Static.IMapping {
46
+ output: this['context'] extends t.TProperties ? this['input'] extends [infer Reference extends string, LAngle, infer Parameters extends t.TSchema[], RAngle] ? t.TInstantiate<Dereference<this['context'], Reference>, [...Parameters]> : never : never;
47
+ }
48
+ type GenericReference = Static.Tuple<[
49
+ Static.Ident,
50
+ Static.Const<LAngle>,
51
+ Elements,
52
+ Static.Const<RAngle>
53
+ ], GenericReferenceMapping>;
45
54
  interface ReferenceMapping extends Static.IMapping {
46
- output: this['context'] extends t.TProperties ? this['input'] extends string ? Deref<this['context'], this['input']> : never : never;
55
+ output: this['context'] extends t.TProperties ? this['input'] extends string ? Dereference<this['context'], this['input']> : never : never;
47
56
  }
48
57
  type Reference = Static.Ident<ReferenceMapping>;
49
58
  interface LiteralBooleanMapping extends Static.IMapping {
@@ -119,6 +128,7 @@ type Base = Static.Union<[
119
128
  Iterator,
120
129
  ConstructorParameters,
121
130
  FunctionParameters,
131
+ Argument,
122
132
  InstanceType,
123
133
  ReturnType,
124
134
  Awaited,
@@ -137,6 +147,7 @@ type Base = Static.Union<[
137
147
  Uncapitalize,
138
148
  Date,
139
149
  Uint8Array,
150
+ GenericReference,
140
151
  Reference
141
152
  ]>
142
153
  ]>
@@ -337,6 +348,15 @@ type ReturnType = Static.Tuple<[
337
348
  Type,
338
349
  Static.Const<RAngle>
339
350
  ], ReturnTypeMapping>;
351
+ interface ArgumentMapping extends Static.IMapping {
352
+ output: this['input'] extends ['Argument', LAngle, infer Type extends t.TSchema, RAngle] ? Type extends t.TLiteral<infer Index extends number> ? t.TArgument<Index> : t.TNever : never;
353
+ }
354
+ type Argument = Static.Tuple<[
355
+ Static.Const<'Argument'>,
356
+ Static.Const<LAngle>,
357
+ Type,
358
+ Static.Const<RAngle>
359
+ ], ArgumentMapping>;
340
360
  interface AwaitedMapping extends Static.IMapping {
341
361
  output: this['input'] extends ['Awaited', LAngle, infer Type extends t.TSchema, RAngle] ? t.TAwaited<Type> : never;
342
362
  }
@@ -0,0 +1,9 @@
1
+ import type { TSchema } from '../schema/index';
2
+ import { Kind } from '../symbols/index';
3
+ export interface TArgument<Index extends number = number> extends TSchema {
4
+ [Kind]: 'Argument';
5
+ static: unknown;
6
+ index: Index;
7
+ }
8
+ /** `[JavaScript]` Creates an Argument Type. */
9
+ export declare function Argument<Index extends number>(index: Index): TArgument<Index>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Argument = Argument;
5
+ const type_1 = require("../create/type");
6
+ const index_1 = require("../symbols/index");
7
+ /** `[JavaScript]` Creates an Argument Type. */
8
+ function Argument(index) {
9
+ return (0, type_1.CreateType)({ [index_1.Kind]: 'Argument', index });
10
+ }
@@ -0,0 +1 @@
1
+ export * from './argument';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./argument"), exports);
@@ -1,14 +1,11 @@
1
1
  import { Kind, Hint, TransformKind } from '../symbols/index';
2
2
  import { TransformOptions } from '../transform/index';
3
- import type { TTemplateLiteral } from '../template-literal/index';
3
+ import type { TAny } from '../any/index';
4
+ import type { TArgument } from '../argument/index';
4
5
  import type { TArray } from '../array/index';
6
+ import type { TAsyncIterator } from '../async-iterator/index';
5
7
  import type { TBoolean } from '../boolean/index';
6
8
  import type { TComputed } from '../computed/index';
7
- import type { TRecord } from '../record/index';
8
- import type { TString } from '../string/index';
9
- import type { TUnion } from '../union/index';
10
- import type { TAny } from '../any/index';
11
- import type { TAsyncIterator } from '../async-iterator/index';
12
9
  import type { TBigInt } from '../bigint/index';
13
10
  import type { TConstructor } from '../constructor/index';
14
11
  import type { TFunction } from '../function/index';
@@ -26,14 +23,18 @@ import type { TObject, TProperties } from '../object/index';
26
23
  import type { TOptional } from '../optional/index';
27
24
  import type { TPromise } from '../promise/index';
28
25
  import type { TReadonly } from '../readonly/index';
26
+ import type { TRecord } from '../record/index';
29
27
  import type { TRef } from '../ref/index';
30
28
  import type { TRegExp } from '../regexp/index';
31
29
  import type { TSchema } from '../schema/index';
30
+ import type { TString } from '../string/index';
32
31
  import type { TSymbol } from '../symbol/index';
32
+ import type { TTemplateLiteral } from '../template-literal/index';
33
33
  import type { TTuple } from '../tuple/index';
34
34
  import type { TUint8Array } from '../uint8array/index';
35
35
  import type { TUndefined } from '../undefined/index';
36
36
  import type { TUnknown } from '../unknown/index';
37
+ import type { TUnion } from '../union/index';
37
38
  import type { TUnsafe } from '../unsafe/index';
38
39
  import type { TVoid } from '../void/index';
39
40
  import type { TDate } from '../date/index';
@@ -44,6 +45,8 @@ export declare function IsReadonly<T extends TSchema>(value: T): value is TReado
44
45
  export declare function IsOptional<T extends TSchema>(value: T): value is TOptional<T>;
45
46
  /** `[Kind-Only]` Returns true if the given value is TAny */
46
47
  export declare function IsAny(value: unknown): value is TAny;
48
+ /** `[Kind-Only]` Returns true if the given value is TArgument */
49
+ export declare function IsArgument(value: unknown): value is TArgument;
47
50
  /** `[Kind-Only]` Returns true if the given value is TArray */
48
51
  export declare function IsArray(value: unknown): value is TArray;
49
52
  /** `[Kind-Only]` Returns true if the given value is TAsyncIterator */
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.IsReadonly = IsReadonly;
5
5
  exports.IsOptional = IsOptional;
6
6
  exports.IsAny = IsAny;
7
+ exports.IsArgument = IsArgument;
7
8
  exports.IsArray = IsArray;
8
9
  exports.IsAsyncIterator = IsAsyncIterator;
9
10
  exports.IsBigInt = IsBigInt;
@@ -63,6 +64,10 @@ function IsOptional(value) {
63
64
  function IsAny(value) {
64
65
  return IsKindOf(value, 'Any');
65
66
  }
67
+ /** `[Kind-Only]` Returns true if the given value is TArgument */
68
+ function IsArgument(value) {
69
+ return IsKindOf(value, 'Argument');
70
+ }
66
71
  /** `[Kind-Only]` Returns true if the given value is TArray */
67
72
  function IsArray(value) {
68
73
  return IsKindOf(value, 'Array');
@@ -243,6 +248,7 @@ function IsKind(value) {
243
248
  function IsSchema(value) {
244
249
  // prettier-ignore
245
250
  return (IsAny(value) ||
251
+ IsArgument(value) ||
246
252
  IsArray(value) ||
247
253
  IsBoolean(value) ||
248
254
  IsBigInt(value) ||
@@ -1,15 +1,12 @@
1
1
  import { Kind, Hint, TransformKind } from '../symbols/index';
2
2
  import { TypeBoxError } from '../error/index';
3
3
  import { TransformOptions } from '../transform/index';
4
- import type { TTemplateLiteral } from '../template-literal/index';
4
+ import type { TAny } from '../any/index';
5
+ import type { TArgument } from '../argument/index';
5
6
  import type { TArray } from '../array/index';
7
+ import type { TAsyncIterator } from '../async-iterator/index';
6
8
  import type { TBoolean } from '../boolean/index';
7
9
  import type { TComputed } from '../computed/index';
8
- import type { TRecord } from '../record/index';
9
- import type { TString } from '../string/index';
10
- import type { TUnion } from '../union/index';
11
- import type { TAny } from '../any/index';
12
- import type { TAsyncIterator } from '../async-iterator/index';
13
10
  import type { TBigInt } from '../bigint/index';
14
11
  import type { TConstructor } from '../constructor/index';
15
12
  import type { TFunction } from '../function/index';
@@ -27,13 +24,17 @@ import type { TObject, TProperties } from '../object/index';
27
24
  import type { TOptional } from '../optional/index';
28
25
  import type { TPromise } from '../promise/index';
29
26
  import type { TReadonly } from '../readonly/index';
27
+ import type { TRecord } from '../record/index';
30
28
  import type { TRef } from '../ref/index';
31
29
  import type { TRegExp } from '../regexp/index';
32
30
  import type { TSchema } from '../schema/index';
31
+ import type { TString } from '../string/index';
33
32
  import type { TSymbol } from '../symbol/index';
33
+ import type { TTemplateLiteral } from '../template-literal/index';
34
34
  import type { TTuple } from '../tuple/index';
35
35
  import type { TUint8Array } from '../uint8array/index';
36
36
  import type { TUndefined } from '../undefined/index';
37
+ import type { TUnion } from '../union/index';
37
38
  import type { TUnknown } from '../unknown/index';
38
39
  import type { TUnsafe } from '../unsafe/index';
39
40
  import type { TVoid } from '../void/index';
@@ -47,6 +48,8 @@ export declare function IsReadonly<T extends TSchema>(value: T): value is TReado
47
48
  export declare function IsOptional<T extends TSchema>(value: T): value is TOptional<T>;
48
49
  /** Returns true if the given value is TAny */
49
50
  export declare function IsAny(value: unknown): value is TAny;
51
+ /** Returns true if the given value is TArgument */
52
+ export declare function IsArgument(value: unknown): value is TArgument;
50
53
  /** Returns true if the given value is TArray */
51
54
  export declare function IsArray(value: unknown): value is TArray;
52
55
  /** Returns true if the given value is TAsyncIterator */
@@ -5,6 +5,7 @@ exports.TypeGuardUnknownTypeError = void 0;
5
5
  exports.IsReadonly = IsReadonly;
6
6
  exports.IsOptional = IsOptional;
7
7
  exports.IsAny = IsAny;
8
+ exports.IsArgument = IsArgument;
8
9
  exports.IsArray = IsArray;
9
10
  exports.IsAsyncIterator = IsAsyncIterator;
10
11
  exports.IsBigInt = IsBigInt;
@@ -58,6 +59,7 @@ class TypeGuardUnknownTypeError extends index_2.TypeBoxError {
58
59
  }
59
60
  exports.TypeGuardUnknownTypeError = TypeGuardUnknownTypeError;
60
61
  const KnownTypes = [
62
+ 'Argument',
61
63
  'Any',
62
64
  'Array',
63
65
  'AsyncIterator',
@@ -157,6 +159,12 @@ function IsAny(value) {
157
159
  return (IsKindOf(value, 'Any') &&
158
160
  IsOptionalString(value.$id));
159
161
  }
162
+ /** Returns true if the given value is TArgument */
163
+ function IsArgument(value) {
164
+ // prettier-ignore
165
+ return (IsKindOf(value, 'Argument') &&
166
+ ValueGuard.IsNumber(value.index));
167
+ }
160
168
  /** Returns true if the given value is TArray */
161
169
  function IsArray(value) {
162
170
  return (IsKindOf(value, 'Array') &&
@@ -517,6 +525,7 @@ function IsKind(value) {
517
525
  function IsSchema(value) {
518
526
  // prettier-ignore
519
527
  return (ValueGuard.IsObject(value)) && (IsAny(value) ||
528
+ IsArgument(value) ||
520
529
  IsArray(value) ||
521
530
  IsBoolean(value) ||
522
531
  IsBigInt(value) ||
@@ -1,4 +1,5 @@
1
1
  export * from './any/index';
2
+ export * from './argument/index';
2
3
  export * from './array/index';
3
4
  export * from './async-iterator/index';
4
5
  export * from './awaited/index';
@@ -21,6 +22,7 @@ export * from './guard/index';
21
22
  export * from './helpers/index';
22
23
  export * from './indexed/index';
23
24
  export * from './instance-type/index';
25
+ export * from './instantiate/index';
24
26
  export * from './integer/index';
25
27
  export * from './intersect/index';
26
28
  export * from './intrinsic/index';
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./any/index"), exports);
19
+ __exportStar(require("./argument/index"), exports);
19
20
  __exportStar(require("./array/index"), exports);
20
21
  __exportStar(require("./async-iterator/index"), exports);
21
22
  __exportStar(require("./awaited/index"), exports);
@@ -38,6 +39,7 @@ __exportStar(require("./guard/index"), exports);
38
39
  __exportStar(require("./helpers/index"), exports);
39
40
  __exportStar(require("./indexed/index"), exports);
40
41
  __exportStar(require("./instance-type/index"), exports);
42
+ __exportStar(require("./instantiate/index"), exports);
41
43
  __exportStar(require("./integer/index"), exports);
42
44
  __exportStar(require("./intersect/index"), exports);
43
45
  __exportStar(require("./intrinsic/index"), exports);
@@ -0,0 +1 @@
1
+ export * from './instantiate';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./instantiate"), exports);
@@ -0,0 +1,25 @@
1
+ import type { TSchema } from '../schema/index';
2
+ import type { TArgument } from '../argument/index';
3
+ import { type TNever } from '../never/index';
4
+ import { type TReadonlyOptional } from '../readonly-optional/index';
5
+ import { type TReadonly } from '../readonly/index';
6
+ import { type TOptional } from '../optional/index';
7
+ import { type TRemap, type TMapping as TRemapMapping } from '../remap/index';
8
+ type TInstantiateArgument<Argument extends TArgument, Type extends TSchema, IsArgumentReadonly extends number = Argument extends TReadonly<TSchema> ? 1 : 0, IsArgumentOptional extends number = Argument extends TOptional<TSchema> ? 1 : 0, Result extends TSchema = ([
9
+ IsArgumentReadonly,
10
+ IsArgumentOptional
11
+ ] extends [1, 1] ? TReadonlyOptional<Type> : [
12
+ IsArgumentReadonly,
13
+ IsArgumentOptional
14
+ ] extends [0, 1] ? TOptional<Type> : [
15
+ IsArgumentReadonly,
16
+ IsArgumentOptional
17
+ ] extends [1, 0] ? TReadonly<Type> : Type)> = Result;
18
+ interface TInstantiateArguments<Arguments extends TSchema[]> extends TRemapMapping {
19
+ output: (this['input'] extends TArgument<infer Index extends number> ? Index extends keyof Arguments ? Arguments[Index] extends TSchema ? TInstantiateArgument<this['input'], Arguments[Index]> : TNever : TNever : this['input']);
20
+ }
21
+ /** `[JavaScript]` Instantiates a type with the given parameters */
22
+ export type TInstantiate<Type extends TSchema, Arguments extends TSchema[]> = (TRemap<Type, TInstantiateArguments<Arguments>>);
23
+ /** `[JavaScript]` Instantiates a type with the given parameters */
24
+ export declare function Instantiate<Type extends TSchema, Arguments extends TSchema[]>(type: Type, args: [...Arguments]): TInstantiate<Type, Arguments>;
25
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Instantiate = Instantiate;
5
+ const index_1 = require("../never/index");
6
+ const index_2 = require("../readonly-optional/index");
7
+ const index_3 = require("../readonly/index");
8
+ const index_4 = require("../optional/index");
9
+ const index_5 = require("../remap/index");
10
+ const KindGuard = require("../guard/kind");
11
+ // prettier-ignore
12
+ function InstantiateArgument(argument, type) {
13
+ const isReadonly = KindGuard.IsReadonly(argument);
14
+ const isOptional = KindGuard.IsOptional(argument);
15
+ return (isReadonly && isOptional ? (0, index_2.ReadonlyOptional)(type) :
16
+ isReadonly && !isOptional ? (0, index_3.Readonly)(type) :
17
+ !isReadonly && isOptional ? (0, index_4.Optional)(type) :
18
+ type);
19
+ }
20
+ /** `[JavaScript]` Instantiates a type with the given parameters */
21
+ // prettier-ignore
22
+ function Instantiate(type, args) {
23
+ return (0, index_5.Remap)(type, (type) => {
24
+ return KindGuard.IsArgument(type)
25
+ ? type.index in args
26
+ ? KindGuard.IsSchema(args[type.index])
27
+ ? InstantiateArgument(type, args[type.index])
28
+ : (0, index_1.Never)()
29
+ : (0, index_1.Never)()
30
+ : type;
31
+ });
32
+ }
@@ -3,6 +3,7 @@ import type { TSchema } from '../schema/index';
3
3
  import type { Static } from '../static/index';
4
4
  import type { Evaluate, Ensure, Assert } from '../helpers/index';
5
5
  import { type TAny } from '../any/index';
6
+ import { type TBoolean } from '../boolean/index';
6
7
  import { type TComputed } from '../computed/index';
7
8
  import { type TEnumRecord, type TEnum } from '../enum/index';
8
9
  import { type TInteger } from '../integer/index';
@@ -38,6 +39,10 @@ type TFromRegExpKey<_Key extends TRegExp, Type extends TSchema> = (Ensure<TRecor
38
39
  type TFromStringKey<_Key extends TString, Type extends TSchema> = (Ensure<TRecord<TString, Type>>);
39
40
  type TFromAnyKey<_Key extends TAny, Type extends TSchema> = (Ensure<TRecord<TAny, Type>>);
40
41
  type TFromNeverKey<_Key extends TNever, Type extends TSchema> = (Ensure<TRecord<TNever, Type>>);
42
+ type TFromBooleanKey<_Key extends TBoolean, Type extends TSchema> = (Ensure<TObject<{
43
+ true: Type;
44
+ false: Type;
45
+ }>>);
41
46
  type TFromIntegerKey<_Key extends TSchema, Type extends TSchema> = (Ensure<TRecord<TNumber, Type>>);
42
47
  type TFromNumberKey<_Key extends TSchema, Type extends TSchema> = (Ensure<TRecord<TNumber, Type>>);
43
48
  type RecordStatic<Key extends TSchema, Type extends TSchema, P extends unknown[]> = (Evaluate<{
@@ -52,7 +57,17 @@ export interface TRecord<Key extends TSchema = TSchema, Type extends TSchema = T
52
57
  };
53
58
  additionalProperties: TAdditionalProperties;
54
59
  }
55
- export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [Key, TComputed<Target, Parameters>]> : Key extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [TComputed<Target, Parameters>, Type]> : Key extends TRef<infer Ref extends string> ? TComputed<'Record', [TRef<Ref>, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer Enum extends TEnumRecord> ? TFromEnumKey<Enum, Type> : Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Type> : Key extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteralKey<Value, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : TNever);
60
+ export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [Key, TComputed<Target, Parameters>]> : Key extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [TComputed<Target, Parameters>, Type]> : Key extends TRef<infer Ref extends string> ? TComputed<'Record', [TRef<Ref>, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer Enum extends TEnumRecord> ? TFromEnumKey<Enum, Type> : Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Type> : Key extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteralKey<Value, Type> : Key extends TBoolean ? TFromBooleanKey<Key, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : TNever);
56
61
  /** `[Json]` Creates a Record type */
57
62
  export declare function Record<Key extends TSchema, Type extends TSchema>(key: Key, type: Type, options?: ObjectOptions): TRecordOrObject<Key, Type>;
63
+ /** Gets the Records Pattern */
64
+ export declare function RecordPattern(record: TRecord): string;
65
+ /** Gets the Records Key Type */
66
+ export type TRecordKey<Type extends TRecord> = (Type extends TRecord<infer Key extends TSchema, TSchema> ? (Key extends TNumber ? TNumber : Key extends TString ? TString : TString) : TString);
67
+ /** Gets the Records Key Type */
68
+ export declare function RecordKey<Type extends TRecord>(type: Type): TRecordKey<Type>;
69
+ /** Gets a Record Value Type */
70
+ export type TRecordValue<Type extends TRecord> = (Type extends TRecord<TSchema, infer Value extends TSchema> ? Value : TNever);
71
+ /** Gets a Record Value Type */
72
+ export declare function RecordValue<Type extends TRecord>(type: Type): TRecordValue<Type>;
58
73
  export {};