@sinclair/typebox 0.32.0-dev-13 → 0.32.0-dev-14

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.
@@ -1,5 +1,5 @@
1
1
  import type { TSchema } from '../schema/index';
2
- import type { Ensure, Evaluate } from '../helpers/index';
2
+ import type { Ensure, Evaluate, Assert } from '../helpers/index';
3
3
  import { type TArray } from '../array/index';
4
4
  import { type TAsyncIterator } from '../async-iterator/index';
5
5
  import { type TConstructor } from '../constructor/index';
@@ -8,19 +8,22 @@ import { type TIndexPropertyKeys } from '../indexed/index';
8
8
  import { type TIntersect } from '../intersect/index';
9
9
  import { type TIterator } from '../iterator/index';
10
10
  import { type TLiteral, type TLiteralValue } from '../literal/index';
11
- import { type TNever } from '../never/index';
12
11
  import { type TObject, type TProperties, type ObjectOptions } from '../object/index';
13
12
  import { type TOptional } from '../optional/index';
14
13
  import { type TPromise } from '../promise/index';
15
14
  import { type TReadonly } from '../readonly/index';
16
15
  import { type TTuple } from '../tuple/index';
17
16
  import { type TUnion } from '../union/index';
18
- import type { TMappedResult } from './mapped-result';
17
+ import { type TMappedResult } from './mapped-result';
19
18
  import type { TMappedKey } from './mapped-key';
20
- type FromMappedResult<K extends PropertyKey, P extends TProperties> = (K extends keyof P ? FromSchemaType<K, P[K]> : TNever);
19
+ type FromMappedResult<K extends PropertyKey, P extends TProperties> = (K extends keyof P ? FromSchemaType<K, P[K]> : TMappedResult<P>);
21
20
  declare function FromMappedResult<K extends PropertyKey, P extends TProperties>(K: K, P: P): FromMappedResult<K, P>;
22
- type FromMappedKey<K extends PropertyKey, _ extends PropertyKey[]> = (K extends TLiteralValue ? TLiteral<K> : TLiteral<'never'>);
23
- declare function FromMappedKey<K extends PropertyKey, P extends PropertyKey[]>(K: K, _: [...P]): TLiteral<TLiteralValue>;
21
+ type MappedKeyToMappedResultProperties<K extends PropertyKey, P extends PropertyKey[]> = (P extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? {
22
+ [_ in L]: TLiteral<Assert<L, TLiteralValue>>;
23
+ } & MappedKeyToMappedResultProperties<K, R> : {});
24
+ declare function MappedKeyToMappedResultProperties<K extends PropertyKey, P extends PropertyKey[]>(K: K, P: [...P]): MappedKeyToMappedResultProperties<K, P>;
25
+ type FromMappedKey<K extends PropertyKey, P extends PropertyKey[], R extends TProperties = MappedKeyToMappedResultProperties<K, P>> = (FromMappedResult<K, R>);
26
+ declare function FromMappedKey<K extends PropertyKey, P extends PropertyKey[]>(K: K, P: [...P]): FromMappedResult<K, MappedKeyToMappedResultProperties<K, P>>;
24
27
  type FromRest<K extends PropertyKey, T extends TSchema[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [FromSchemaType<K, L>, ...FromRest<K, R>] : [];
25
28
  declare function FromRest<K extends PropertyKey, T extends TSchema[]>(K: K, T: [...T]): FromRest<K, T>;
26
29
  type FromProperties<K extends PropertyKey, T extends TProperties, R extends TProperties = Evaluate<{
@@ -13,21 +13,28 @@ const index_7 = require("../indexed/index");
13
13
  const index_8 = require("../intersect/index");
14
14
  const index_9 = require("../iterator/index");
15
15
  const index_10 = require("../literal/index");
16
- const index_11 = require("../never/index");
17
- const index_12 = require("../object/index");
18
- const index_13 = require("../optional/index");
19
- const index_14 = require("../promise/index");
20
- const index_15 = require("../readonly/index");
21
- const index_16 = require("../tuple/index");
22
- const index_17 = require("../union/index");
16
+ const index_11 = require("../object/index");
17
+ const index_12 = require("../optional/index");
18
+ const index_13 = require("../promise/index");
19
+ const index_14 = require("../readonly/index");
20
+ const index_15 = require("../tuple/index");
21
+ const index_16 = require("../union/index");
22
+ const mapped_result_1 = require("./mapped-result");
23
23
  const type_3 = require("../guard/type");
24
24
  function FromMappedResult(K, P) {
25
25
  return (K in P
26
26
  ? FromSchemaType(K, P[K])
27
- : (0, index_11.Never)());
27
+ : (0, mapped_result_1.MappedResult)(P));
28
28
  }
29
- function FromMappedKey(K, _) {
30
- return (0, index_10.Literal)(K);
29
+ function MappedKeyToMappedResultProperties(K, P) {
30
+ const [L, ...R] = P;
31
+ return (P.length > 0
32
+ ? { [L]: (0, index_10.Literal)(L), ...MappedKeyToMappedResultProperties(K, R) }
33
+ : {});
34
+ }
35
+ function FromMappedKey(K, P) {
36
+ const R = MappedKeyToMappedResultProperties(K, P);
37
+ return FromMappedResult(K, R);
31
38
  }
32
39
  function FromRest(K, T) {
33
40
  const [L, ...R] = T;
@@ -41,8 +48,8 @@ function FromProperties(K, T) {
41
48
  }, {});
42
49
  }
43
50
  function FromSchemaType(K, T) {
44
- return ((0, type_3.TOptional)(T) ? (0, index_13.Optional)(FromSchemaType(K, (0, index_2.Discard)(T, [index_1.OptionalKind]))) :
45
- (0, type_3.TReadonly)(T) ? (0, index_15.Readonly)(FromSchemaType(K, (0, index_2.Discard)(T, [index_1.ReadonlyKind]))) :
51
+ return ((0, type_3.TOptional)(T) ? (0, index_12.Optional)(FromSchemaType(K, (0, index_2.Discard)(T, [index_1.OptionalKind]))) :
52
+ (0, type_3.TReadonly)(T) ? (0, index_14.Readonly)(FromSchemaType(K, (0, index_2.Discard)(T, [index_1.ReadonlyKind]))) :
46
53
  (0, type_3.TMappedResult)(T) ? FromMappedResult(K, T.properties) :
47
54
  (0, type_3.TMappedKey)(T) ? FromMappedKey(K, T.keys) :
48
55
  (0, type_3.TConstructor)(T) ? (0, index_5.Constructor)(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
@@ -50,11 +57,11 @@ function FromSchemaType(K, T) {
50
57
  (0, type_3.TAsyncIterator)(T) ? (0, index_4.AsyncIterator)(FromSchemaType(K, T.items)) :
51
58
  (0, type_3.TIterator)(T) ? (0, index_9.Iterator)(FromSchemaType(K, T.items)) :
52
59
  (0, type_3.TIntersect)(T) ? (0, index_8.Intersect)(FromRest(K, T.allOf)) :
53
- (0, type_3.TUnion)(T) ? (0, index_17.Union)(FromRest(K, T.anyOf)) :
54
- (0, type_3.TTuple)(T) ? (0, index_16.Tuple)(FromRest(K, T.items ?? [])) :
55
- (0, type_3.TObject)(T) ? (0, index_12.Object)(FromProperties(K, T.properties)) :
60
+ (0, type_3.TUnion)(T) ? (0, index_16.Union)(FromRest(K, T.anyOf)) :
61
+ (0, type_3.TTuple)(T) ? (0, index_15.Tuple)(FromRest(K, T.items ?? [])) :
62
+ (0, type_3.TObject)(T) ? (0, index_11.Object)(FromProperties(K, T.properties)) :
56
63
  (0, type_3.TArray)(T) ? (0, index_3.Array)(FromSchemaType(K, T.items)) :
57
- (0, type_3.TPromise)(T) ? (0, index_14.Promise)(FromSchemaType(K, T.item)) :
64
+ (0, type_3.TPromise)(T) ? (0, index_13.Promise)(FromSchemaType(K, T.item)) :
58
65
  T);
59
66
  }
60
67
  function FromMappedFunctionReturnType(K, T) {
@@ -67,6 +74,6 @@ function Mapped(key, map, options = {}) {
67
74
  const K = (0, type_1.TSchema)(key) ? (0, index_7.IndexPropertyKeys)(key) : key;
68
75
  const RT = map({ [index_1.Kind]: 'MappedKey', keys: K });
69
76
  const R = FromMappedFunctionReturnType(K, RT);
70
- return (0, type_2.CloneType)((0, index_12.Object)(R), options);
77
+ return (0, type_2.CloneType)((0, index_11.Object)(R), options);
71
78
  }
72
79
  exports.Mapped = Mapped;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.32.0-dev-13",
3
+ "version": "0.32.0-dev-14",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",