typesea 0.1.0 → 0.2.0

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 (285) hide show
  1. package/CHANGELOG.md +67 -6
  2. package/README.md +98 -17
  3. package/dist/adapters/index.d.ts +50 -8
  4. package/dist/adapters/index.d.ts.map +1 -1
  5. package/dist/adapters/index.js +169 -48
  6. package/dist/aot/index.d.ts +18 -2
  7. package/dist/aot/index.d.ts.map +1 -1
  8. package/dist/aot/index.js +93 -14
  9. package/dist/async/index.d.ts +28 -56
  10. package/dist/async/index.d.ts.map +1 -1
  11. package/dist/async/index.js +94 -37
  12. package/dist/builders/composite.d.ts +37 -6
  13. package/dist/builders/composite.d.ts.map +1 -1
  14. package/dist/builders/composite.js +84 -10
  15. package/dist/builders/index.d.ts +2 -0
  16. package/dist/builders/index.d.ts.map +1 -1
  17. package/dist/builders/index.js +2 -0
  18. package/dist/builders/modifier.d.ts +30 -5
  19. package/dist/builders/modifier.d.ts.map +1 -1
  20. package/dist/builders/modifier.js +38 -5
  21. package/dist/builders/object/guard.d.ts +18 -22
  22. package/dist/builders/object/guard.d.ts.map +1 -1
  23. package/dist/builders/object/guard.js +26 -26
  24. package/dist/builders/object/index.d.ts +2 -0
  25. package/dist/builders/object/index.d.ts.map +1 -1
  26. package/dist/builders/object/index.js +2 -0
  27. package/dist/builders/object/schema.d.ts +55 -9
  28. package/dist/builders/object/schema.d.ts.map +1 -1
  29. package/dist/builders/object/schema.js +92 -15
  30. package/dist/builders/object/types.d.ts +5 -31
  31. package/dist/builders/object/types.d.ts.map +1 -1
  32. package/dist/builders/object/types.js +2 -0
  33. package/dist/builders/scalar.d.ts +29 -8
  34. package/dist/builders/scalar.d.ts.map +1 -1
  35. package/dist/builders/scalar.js +33 -8
  36. package/dist/builders/table.d.ts +4 -0
  37. package/dist/builders/table.d.ts.map +1 -1
  38. package/dist/builders/table.js +4 -0
  39. package/dist/builders/types.d.ts +14 -4
  40. package/dist/builders/types.d.ts.map +1 -1
  41. package/dist/builders/types.js +2 -0
  42. package/dist/compile/check-composite.d.ts +22 -1
  43. package/dist/compile/check-composite.d.ts.map +1 -1
  44. package/dist/compile/check-composite.js +564 -24
  45. package/dist/compile/check-scalar.d.ts +78 -0
  46. package/dist/compile/check-scalar.d.ts.map +1 -1
  47. package/dist/compile/check-scalar.js +432 -1
  48. package/dist/compile/check.d.ts +12 -0
  49. package/dist/compile/check.d.ts.map +1 -1
  50. package/dist/compile/check.js +37 -0
  51. package/dist/compile/context.d.ts +47 -9
  52. package/dist/compile/context.d.ts.map +1 -1
  53. package/dist/compile/context.js +51 -8
  54. package/dist/compile/graph-predicate.d.ts +4 -2
  55. package/dist/compile/graph-predicate.d.ts.map +1 -1
  56. package/dist/compile/graph-predicate.js +1907 -171
  57. package/dist/compile/guard.d.ts +15 -24
  58. package/dist/compile/guard.d.ts.map +1 -1
  59. package/dist/compile/guard.js +158 -74
  60. package/dist/compile/index.d.ts +3 -1
  61. package/dist/compile/index.d.ts.map +1 -1
  62. package/dist/compile/index.js +2 -0
  63. package/dist/compile/issue.d.ts +110 -0
  64. package/dist/compile/issue.d.ts.map +1 -1
  65. package/dist/compile/issue.js +184 -1
  66. package/dist/compile/names.d.ts +12 -2
  67. package/dist/compile/names.d.ts.map +1 -1
  68. package/dist/compile/names.js +19 -3
  69. package/dist/compile/predicate.d.ts +24 -0
  70. package/dist/compile/predicate.d.ts.map +1 -1
  71. package/dist/compile/predicate.js +131 -5
  72. package/dist/compile/runtime.d.ts +80 -12
  73. package/dist/compile/runtime.d.ts.map +1 -1
  74. package/dist/compile/runtime.js +25 -6
  75. package/dist/compile/source.d.ts +10 -2
  76. package/dist/compile/source.d.ts.map +1 -1
  77. package/dist/compile/source.js +361 -26
  78. package/dist/compile/types.d.ts +20 -0
  79. package/dist/compile/types.d.ts.map +1 -1
  80. package/dist/compile/types.js +2 -0
  81. package/dist/decoder/index.d.ts +32 -46
  82. package/dist/decoder/index.d.ts.map +1 -1
  83. package/dist/decoder/index.js +102 -38
  84. package/dist/evaluate/check-composite.d.ts +59 -0
  85. package/dist/evaluate/check-composite.d.ts.map +1 -1
  86. package/dist/evaluate/check-composite.js +151 -3
  87. package/dist/evaluate/check-scalar.d.ts +16 -0
  88. package/dist/evaluate/check-scalar.d.ts.map +1 -1
  89. package/dist/evaluate/check-scalar.js +32 -0
  90. package/dist/evaluate/check.d.ts +7 -0
  91. package/dist/evaluate/check.d.ts.map +1 -1
  92. package/dist/evaluate/check.js +43 -0
  93. package/dist/evaluate/index.d.ts +2 -0
  94. package/dist/evaluate/index.d.ts.map +1 -1
  95. package/dist/evaluate/index.js +2 -0
  96. package/dist/evaluate/issue.d.ts +11 -1
  97. package/dist/evaluate/issue.d.ts.map +1 -1
  98. package/dist/evaluate/issue.js +15 -1
  99. package/dist/evaluate/predicate.d.ts +16 -5
  100. package/dist/evaluate/predicate.d.ts.map +1 -1
  101. package/dist/evaluate/predicate.js +20 -5
  102. package/dist/evaluate/shared.d.ts +59 -13
  103. package/dist/evaluate/shared.d.ts.map +1 -1
  104. package/dist/evaluate/shared.js +66 -8
  105. package/dist/evaluate/state.d.ts +35 -13
  106. package/dist/evaluate/state.d.ts.map +1 -1
  107. package/dist/evaluate/state.js +35 -2
  108. package/dist/guard/base.d.ts +79 -29
  109. package/dist/guard/base.d.ts.map +1 -1
  110. package/dist/guard/base.js +91 -29
  111. package/dist/guard/error.d.ts +10 -5
  112. package/dist/guard/error.d.ts.map +1 -1
  113. package/dist/guard/error.js +10 -5
  114. package/dist/guard/index.d.ts +2 -0
  115. package/dist/guard/index.d.ts.map +1 -1
  116. package/dist/guard/index.js +2 -0
  117. package/dist/guard/number.d.ts +26 -11
  118. package/dist/guard/number.d.ts.map +1 -1
  119. package/dist/guard/number.js +30 -11
  120. package/dist/guard/props.d.ts +27 -3
  121. package/dist/guard/props.d.ts.map +1 -1
  122. package/dist/guard/props.js +27 -3
  123. package/dist/guard/read.d.ts +62 -9
  124. package/dist/guard/read.d.ts.map +1 -1
  125. package/dist/guard/read.js +83 -10
  126. package/dist/guard/registry.d.ts +12 -2
  127. package/dist/guard/registry.d.ts.map +1 -1
  128. package/dist/guard/registry.js +15 -3
  129. package/dist/guard/string.d.ts +33 -13
  130. package/dist/guard/string.d.ts.map +1 -1
  131. package/dist/guard/string.js +37 -13
  132. package/dist/guard/types.d.ts +92 -40
  133. package/dist/guard/types.d.ts.map +1 -1
  134. package/dist/guard/types.js +2 -0
  135. package/dist/index.d.ts +1 -1
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/internal/index.d.ts +42 -6
  138. package/dist/internal/index.d.ts.map +1 -1
  139. package/dist/internal/index.js +51 -8
  140. package/dist/ir/builder.d.ts +16 -126
  141. package/dist/ir/builder.d.ts.map +1 -1
  142. package/dist/ir/builder.js +77 -137
  143. package/dist/ir/freeze.d.ts +4 -0
  144. package/dist/ir/freeze.d.ts.map +1 -1
  145. package/dist/ir/freeze.js +59 -0
  146. package/dist/ir/index.d.ts +3 -1
  147. package/dist/ir/index.d.ts.map +1 -1
  148. package/dist/ir/index.js +2 -0
  149. package/dist/ir/regexp.d.ts +2 -0
  150. package/dist/ir/regexp.d.ts.map +1 -1
  151. package/dist/ir/regexp.js +2 -0
  152. package/dist/ir/types.d.ts +90 -55
  153. package/dist/ir/types.d.ts.map +1 -1
  154. package/dist/ir/types.js +2 -0
  155. package/dist/ir/validate.d.ts +8 -1
  156. package/dist/ir/validate.d.ts.map +1 -1
  157. package/dist/ir/validate.js +477 -61
  158. package/dist/issue/index.d.ts +41 -9
  159. package/dist/issue/index.d.ts.map +1 -1
  160. package/dist/issue/index.js +61 -11
  161. package/dist/json-schema/emit-combinator.d.ts +44 -4
  162. package/dist/json-schema/emit-combinator.d.ts.map +1 -1
  163. package/dist/json-schema/emit-combinator.js +44 -4
  164. package/dist/json-schema/emit-composite.d.ts +10 -0
  165. package/dist/json-schema/emit-composite.d.ts.map +1 -1
  166. package/dist/json-schema/emit-composite.js +15 -1
  167. package/dist/json-schema/emit-scalar.d.ts +26 -3
  168. package/dist/json-schema/emit-scalar.d.ts.map +1 -1
  169. package/dist/json-schema/emit-scalar.js +70 -9
  170. package/dist/json-schema/emit-types.d.ts +11 -1
  171. package/dist/json-schema/emit-types.d.ts.map +1 -1
  172. package/dist/json-schema/emit-types.js +2 -0
  173. package/dist/json-schema/emit.d.ts +12 -1
  174. package/dist/json-schema/emit.d.ts.map +1 -1
  175. package/dist/json-schema/emit.js +12 -1
  176. package/dist/json-schema/freeze.d.ts +13 -2
  177. package/dist/json-schema/freeze.d.ts.map +1 -1
  178. package/dist/json-schema/freeze.js +41 -8
  179. package/dist/json-schema/index.d.ts +16 -2
  180. package/dist/json-schema/index.d.ts.map +1 -1
  181. package/dist/json-schema/index.js +23 -3
  182. package/dist/json-schema/issue.d.ts +4 -1
  183. package/dist/json-schema/issue.d.ts.map +1 -1
  184. package/dist/json-schema/issue.js +4 -1
  185. package/dist/json-schema/read.d.ts +24 -3
  186. package/dist/json-schema/read.d.ts.map +1 -1
  187. package/dist/json-schema/read.js +59 -12
  188. package/dist/json-schema/types.d.ts +38 -15
  189. package/dist/json-schema/types.d.ts.map +1 -1
  190. package/dist/json-schema/types.js +2 -0
  191. package/dist/kind/index.d.ts +15 -28
  192. package/dist/kind/index.d.ts.map +1 -1
  193. package/dist/kind/index.js +15 -10
  194. package/dist/lower/index.d.ts +6 -1
  195. package/dist/lower/index.d.ts.map +1 -1
  196. package/dist/lower/index.js +411 -44
  197. package/dist/message/index.d.ts +46 -10
  198. package/dist/message/index.d.ts.map +1 -1
  199. package/dist/message/index.js +88 -17
  200. package/dist/optimize/algebraic.d.ts +54 -0
  201. package/dist/optimize/algebraic.d.ts.map +1 -0
  202. package/dist/optimize/algebraic.js +314 -0
  203. package/dist/optimize/compact.d.ts +8 -1
  204. package/dist/optimize/compact.d.ts.map +1 -1
  205. package/dist/optimize/compact.js +13 -2
  206. package/dist/optimize/domain.d.ts +16 -0
  207. package/dist/optimize/domain.d.ts.map +1 -0
  208. package/dist/optimize/domain.js +615 -0
  209. package/dist/optimize/fold-boolean.d.ts +17 -2
  210. package/dist/optimize/fold-boolean.d.ts.map +1 -1
  211. package/dist/optimize/fold-boolean.js +59 -14
  212. package/dist/optimize/fold-common.d.ts +43 -8
  213. package/dist/optimize/fold-common.d.ts.map +1 -1
  214. package/dist/optimize/fold-common.js +37 -6
  215. package/dist/optimize/fold-constraints.d.ts +33 -0
  216. package/dist/optimize/fold-constraints.d.ts.map +1 -0
  217. package/dist/optimize/fold-constraints.js +484 -0
  218. package/dist/optimize/fold-scalar.d.ts +98 -13
  219. package/dist/optimize/fold-scalar.d.ts.map +1 -1
  220. package/dist/optimize/fold-scalar.js +98 -13
  221. package/dist/optimize/fold.d.ts +8 -1
  222. package/dist/optimize/fold.d.ts.map +1 -1
  223. package/dist/optimize/fold.js +22 -2
  224. package/dist/optimize/index.d.ts +9 -1
  225. package/dist/optimize/index.d.ts.map +1 -1
  226. package/dist/optimize/index.js +18 -3
  227. package/dist/optimize/map-node.d.ts +3 -1
  228. package/dist/optimize/map-node.d.ts.map +1 -1
  229. package/dist/optimize/map-node.js +45 -3
  230. package/dist/optimize/peephole.d.ts +16 -0
  231. package/dist/optimize/peephole.d.ts.map +1 -0
  232. package/dist/optimize/peephole.js +254 -0
  233. package/dist/optimize/remap.d.ts +2 -0
  234. package/dist/optimize/remap.d.ts.map +1 -1
  235. package/dist/optimize/remap.js +2 -0
  236. package/dist/optimize/rewrite.d.ts +13 -8
  237. package/dist/optimize/rewrite.d.ts.map +1 -1
  238. package/dist/optimize/rewrite.js +13 -8
  239. package/dist/plan/cache.d.ts +9 -3
  240. package/dist/plan/cache.d.ts.map +1 -1
  241. package/dist/plan/cache.js +21 -5
  242. package/dist/plan/index.d.ts +2 -0
  243. package/dist/plan/index.d.ts.map +1 -1
  244. package/dist/plan/index.js +2 -0
  245. package/dist/plan/predicate.d.ts +2 -0
  246. package/dist/plan/predicate.d.ts.map +1 -1
  247. package/dist/plan/predicate.js +268 -29
  248. package/dist/plan/schema-predicate.d.ts +6 -0
  249. package/dist/plan/schema-predicate.d.ts.map +1 -1
  250. package/dist/plan/schema-predicate.js +117 -13
  251. package/dist/plan/types.d.ts +2 -0
  252. package/dist/plan/types.d.ts.map +1 -1
  253. package/dist/plan/types.js +2 -0
  254. package/dist/result/index.d.ts +19 -5
  255. package/dist/result/index.d.ts.map +1 -1
  256. package/dist/result/index.js +10 -2
  257. package/dist/schema/common.d.ts +69 -6
  258. package/dist/schema/common.d.ts.map +1 -1
  259. package/dist/schema/common.js +104 -10
  260. package/dist/schema/freeze.d.ts +4 -0
  261. package/dist/schema/freeze.d.ts.map +1 -1
  262. package/dist/schema/freeze.js +18 -0
  263. package/dist/schema/index.d.ts +3 -0
  264. package/dist/schema/index.d.ts.map +1 -1
  265. package/dist/schema/index.js +3 -0
  266. package/dist/schema/lazy.d.ts +4 -0
  267. package/dist/schema/lazy.d.ts.map +1 -1
  268. package/dist/schema/lazy.js +4 -0
  269. package/dist/schema/literal.d.ts +7 -1
  270. package/dist/schema/literal.d.ts.map +1 -1
  271. package/dist/schema/literal.js +7 -1
  272. package/dist/schema/types.d.ts +20 -96
  273. package/dist/schema/types.d.ts.map +1 -1
  274. package/dist/schema/types.js +5 -1
  275. package/dist/schema/undefined.d.ts +17 -0
  276. package/dist/schema/undefined.d.ts.map +1 -0
  277. package/dist/schema/undefined.js +72 -0
  278. package/dist/schema/validate.d.ts +8 -1
  279. package/dist/schema/validate.d.ts.map +1 -1
  280. package/dist/schema/validate.js +146 -55
  281. package/docs/api.md +57 -0
  282. package/docs/assets/benchmark-headline.svg +163 -0
  283. package/docs/engine-notes.md +58 -15
  284. package/docs/index.html +130 -110
  285. package/package.json +65 -65
@@ -1,31 +1,62 @@
1
1
  /**
2
2
  * @file composite.ts
3
3
  * @brief Composite guard builders.
4
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
5
+ * with stable metadata.
4
6
  */
5
7
  import { BaseGuard, type Guard, type Infer, type Presence } from "../guard/index.js";
6
8
  import type { DiscriminatedUnionCases, InferTuple, TupleShape, UnionInput } from "./types.js";
7
9
  /**
8
- * @brief array.
10
+ * @brief Build an array guard.
11
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
12
+ * with stable metadata.
13
+ * @param item Guard used for each logical array slot.
14
+ * @returns Fresh array guard.
9
15
  */
10
16
  export declare function array<TGuard extends Guard<unknown, Presence>>(item: TGuard): BaseGuard<Infer<TGuard>[]>;
11
17
  /**
12
- * @brief tuple.
18
+ * @brief Build a fixed-length tuple guard.
19
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
20
+ * with stable metadata.
21
+ * @param shape Ordered guard list for tuple indexes.
22
+ * @returns Fresh tuple guard preserving item order.
23
+ * @throws TypeError when shape is not an array-like tuple input.
13
24
  */
14
25
  export declare function tuple<const TShape extends TupleShape>(shape: TShape): BaseGuard<InferTuple<TShape>>;
15
26
  /**
16
- * @brief record.
27
+ * @brief Build a string-keyed record guard.
28
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
29
+ * with stable metadata.
30
+ * @param value Guard used for each enumerable own record value.
31
+ * @returns Fresh record guard.
17
32
  */
18
33
  export declare function record<TGuard extends Guard<unknown, Presence>>(value: TGuard): BaseGuard<Readonly<Record<string, Infer<TGuard>>>>;
19
34
  /**
20
- * @brief union.
35
+ * @brief Build a union guard from one or more guards.
36
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
37
+ * with stable metadata.
38
+ * @param guards Non-empty guard list.
39
+ * @returns Fresh union guard.
40
+ * @throws TypeError when called without guards.
21
41
  */
22
42
  export declare function union<const TGuards extends UnionInput>(...guards: TGuards): BaseGuard<Infer<TGuards[number]>>;
23
43
  /**
24
- * @brief intersect.
44
+ * @brief Build an intersection guard.
45
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
46
+ * with stable metadata.
47
+ * @param left Left-hand guard.
48
+ * @param right Right-hand guard.
49
+ * @returns Fresh guard requiring both schemas to accept the value.
25
50
  */
26
51
  export declare function intersect<TLeft extends Guard<unknown, Presence>, TRight extends Guard<unknown, Presence>>(left: TLeft, right: TRight): BaseGuard<Infer<TLeft> & Infer<TRight>>;
27
52
  /**
28
- * @brief discriminated union.
53
+ * @brief Build a union whose branch can be selected by one literal property.
54
+ * @details This shape lowers to a dispatch table instead of a linear union
55
+ * scan, which is the fast path object unions should use.
56
+ * @param key Discriminant object key.
57
+ * @param cases Record from discriminant literal to branch guard.
58
+ * @returns Fresh discriminated-union guard.
59
+ * @throws TypeError when cases are empty or branch schemas do not require the tag.
29
60
  */
30
61
  export declare function discriminatedUnion<const TKey extends string, const TCases extends Readonly<Record<string, Guard<unknown, Presence>>>>(key: TKey, cases: TCases & DiscriminatedUnionCases<TKey, TCases>): BaseGuard<Infer<TCases[keyof TCases]>>;
31
62
  //# sourceMappingURL=composite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"composite.d.ts","sourceRoot":"","sources":["../../src/builders/composite.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EACL,SAAS,EACT,KAAK,KAAK,EACV,KAAK,KAAK,EACV,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAM3B,OAAO,KAAK,EACV,uBAAuB,EACvB,UAAU,EACV,UAAU,EACV,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,KAAK,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAC3D,IAAI,EAAE,MAAM,GACX,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAK5B;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,CAAC,MAAM,SAAS,UAAU,EACnD,KAAK,EAAE,MAAM,GACZ,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAc/B;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ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,EAAE,MAAM,GAAG,uBAAuB,CAAC,IAAI,EAAE,MAAM,CAAC,GACtD,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,CAAC,CAAC,CAiCxC"}
@@ -1,12 +1,18 @@
1
1
  /**
2
2
  * @file composite.ts
3
3
  * @brief Composite guard builders.
4
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
5
+ * with stable metadata.
4
6
  */
5
7
  import { PresenceTag, SchemaTag } from "../kind/index.js";
6
8
  import { BaseGuard } from "../guard/index.js";
7
9
  import { isRecord, readGuardSchema } from "../internal/index.js";
8
10
  /**
9
- * @brief array.
11
+ * @brief Build an array guard.
12
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
13
+ * with stable metadata.
14
+ * @param item Guard used for each logical array slot.
15
+ * @returns Fresh array guard.
10
16
  */
11
17
  export function array(item) {
12
18
  return new BaseGuard({
@@ -15,13 +21,22 @@ export function array(item) {
15
21
  });
16
22
  }
17
23
  /**
18
- * @brief tuple.
24
+ * @brief Build a fixed-length tuple guard.
25
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
26
+ * with stable metadata.
27
+ * @param shape Ordered guard list for tuple indexes.
28
+ * @returns Fresh tuple guard preserving item order.
29
+ * @throws TypeError when shape is not an array-like tuple input.
19
30
  */
20
31
  export function tuple(shape) {
21
32
  const rawShape = shape;
22
33
  if (!Array.isArray(rawShape)) {
23
34
  throw new TypeError("tuple shape must be an array");
24
35
  }
36
+ /*
37
+ * Tuple indexes are read in order and stored as schemas, not guard objects,
38
+ * so later validation cannot observe mutation on user-held guard wrappers.
39
+ */
25
40
  const items = new Array(shape.length);
26
41
  for (let index = 0; index < shape.length; index += 1) {
27
42
  const guard = shape[index];
@@ -33,7 +48,11 @@ export function tuple(shape) {
33
48
  });
34
49
  }
35
50
  /**
36
- * @brief record.
51
+ * @brief Build a string-keyed record guard.
52
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
53
+ * with stable metadata.
54
+ * @param value Guard used for each enumerable own record value.
55
+ * @returns Fresh record guard.
37
56
  */
38
57
  export function record(value) {
39
58
  return new BaseGuard({
@@ -42,12 +61,21 @@ export function record(value) {
42
61
  });
43
62
  }
44
63
  /**
45
- * @brief union.
64
+ * @brief Build a union guard from one or more guards.
65
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
66
+ * with stable metadata.
67
+ * @param guards Non-empty guard list.
68
+ * @returns Fresh union guard.
69
+ * @throws TypeError when called without guards.
46
70
  */
47
71
  export function union(...guards) {
48
72
  if (guards.length === 0) {
49
73
  throw new TypeError("union requires at least one guard");
50
74
  }
75
+ /*
76
+ * Preserve option order. Diagnostics and generated dispatch use this order
77
+ * when probing branches and constructing graph children.
78
+ */
51
79
  const options = new Array(guards.length);
52
80
  for (let index = 0; index < guards.length; index += 1) {
53
81
  const guard = guards[index];
@@ -59,7 +87,12 @@ export function union(...guards) {
59
87
  });
60
88
  }
61
89
  /**
62
- * @brief intersect.
90
+ * @brief Build an intersection guard.
91
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
92
+ * with stable metadata.
93
+ * @param left Left-hand guard.
94
+ * @param right Right-hand guard.
95
+ * @returns Fresh guard requiring both schemas to accept the value.
63
96
  */
64
97
  export function intersect(left, right) {
65
98
  return new BaseGuard({
@@ -69,7 +102,13 @@ export function intersect(left, right) {
69
102
  });
70
103
  }
71
104
  /**
72
- * @brief discriminated union.
105
+ * @brief Build a union whose branch can be selected by one literal property.
106
+ * @details This shape lowers to a dispatch table instead of a linear union
107
+ * scan, which is the fast path object unions should use.
108
+ * @param key Discriminant object key.
109
+ * @param cases Record from discriminant literal to branch guard.
110
+ * @returns Fresh discriminated-union guard.
111
+ * @throws TypeError when cases are empty or branch schemas do not require the tag.
73
112
  */
74
113
  export function discriminatedUnion(key, cases) {
75
114
  if (typeof key !== "string") {
@@ -82,6 +121,10 @@ export function discriminatedUnion(key, cases) {
82
121
  if (entries.length === 0) {
83
122
  throw new TypeError("discriminated union requires at least one case");
84
123
  }
124
+ /*
125
+ * Object.entries defines the dispatch order. The literal string is taken
126
+ * from the case key and must be required by the branch schema below.
127
+ */
85
128
  const unionCases = new Array(entries.length);
86
129
  for (let index = 0; index < entries.length; index += 1) {
87
130
  const pair = entries[index];
@@ -102,7 +145,15 @@ export function discriminatedUnion(key, cases) {
102
145
  });
103
146
  }
104
147
  /**
105
- * @brief read discriminated union case schema.
148
+ * @brief Extract and validate one discriminated-union branch schema.
149
+ * @details A branch is accepted only when its object schema itself proves the
150
+ * discriminant literal. Without that proof, dispatch by table key could select
151
+ * a branch whose validator later accepts a different tag shape.
152
+ * @param guard Branch guard from the cases table.
153
+ * @param key Discriminant key shared by all cases.
154
+ * @param literal Literal value assigned to this case.
155
+ * @returns Branch schema after discriminant proof.
156
+ * @throws TypeError when the branch does not require its literal tag.
106
157
  */
107
158
  function readDiscriminatedUnionCaseSchema(guard, key, literal) {
108
159
  const schema = readGuardSchema(guard, `case ${literal}`);
@@ -112,7 +163,15 @@ function readDiscriminatedUnionCaseSchema(guard, key, literal) {
112
163
  return schema;
113
164
  }
114
165
  /**
115
- * @brief case requires discriminant.
166
+ * @brief Prove that a branch structurally requires the requested tag literal.
167
+ * @details Dispatch tables are only sound when accepting a branch implies that
168
+ * the discriminant key is present and equal to its table literal. The proof is
169
+ * intentionally structural and refuses schemas whose tag requirement is hidden
170
+ * behind runtime-only logic.
171
+ * @param schema Branch schema to inspect.
172
+ * @param key Discriminant key.
173
+ * @param literal Required literal value.
174
+ * @returns True when the branch structurally requires `key: literal`.
116
175
  */
117
176
  function caseRequiresDiscriminant(schema, key, literal) {
118
177
  const objectSchema = unwrapCaseObjectSchema(schema);
@@ -131,13 +190,22 @@ function caseRequiresDiscriminant(schema, key, literal) {
131
190
  return false;
132
191
  }
133
192
  /**
134
- * @brief unwrap case object schema.
193
+ * @brief Find the object schema that can prove a discriminant requirement.
194
+ * @details Brand and refinement wrappers do not change object shape, and either
195
+ * side of an intersection may supply the tag field. Other schema forms cannot
196
+ * provide the required object-field proof.
197
+ * @param schema Branch schema possibly wrapped by brand/refine/intersection.
198
+ * @returns Object schema used for discriminant inspection, or undefined.
135
199
  */
136
200
  function unwrapCaseObjectSchema(schema) {
137
201
  switch (schema.tag) {
138
202
  case SchemaTag.Object:
139
203
  return schema;
140
204
  case SchemaTag.Intersection:
205
+ /*
206
+ * A discriminant can be supplied by either side of an intersection.
207
+ * Search both sides before rejecting the case.
208
+ */
141
209
  return unwrapCaseObjectSchema(schema.left) ?? unwrapCaseObjectSchema(schema.right);
142
210
  case SchemaTag.Brand:
143
211
  case SchemaTag.Refine:
@@ -147,7 +215,13 @@ function unwrapCaseObjectSchema(schema) {
147
215
  }
148
216
  }
149
217
  /**
150
- * @brief schema requires literal.
218
+ * @brief Prove that a discriminant field schema accepts only one literal.
219
+ * @details Intersections may prove the literal from either side, while brand
220
+ * and refinement wrappers preserve the underlying literal requirement. Broader
221
+ * schemas are rejected because they would make table dispatch unsound.
222
+ * @param schema Schema attached to the discriminant property.
223
+ * @param literal Literal value required by the case.
224
+ * @returns True when the schema accepts only the requested literal.
151
225
  */
152
226
  function schemaRequiresLiteral(schema, literal) {
153
227
  switch (schema.tag) {
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file index.ts
3
3
  * @brief Public builder module aggregation.
4
+ * @details This barrel keeps public import paths stable while implementation files remain
5
+ * split by responsibility.
4
6
  */
5
7
  export { array, discriminatedUnion, intersect, record, tuple, union } from "./composite.js";
6
8
  export { lazy, nullable, optional, refine, undefinedable } from "./modifier.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/builders/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,KAAK,EACL,kBAAkB,EAClB,SAAS,EACT,MAAM,EACN,KAAK,EACL,KAAK,EACN,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,WAAW,EACX,MAAM,EACN,MAAM,EACN,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,EACX,YAAY,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,CAAC,EAAE,MAAM,YAAY,CAAC;AAC/B,YAAY,EACV,UAAU,EACV,UAAU,EACX,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/builders/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACH,KAAK,EACL,kBAAkB,EAClB,SAAS,EACT,MAAM,EACN,KAAK,EACL,KAAK,EACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACH,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,aAAa,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EACH,WAAW,EACX,MAAM,EACN,MAAM,EACN,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,EACX,YAAY,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,CAAC,EAAE,MAAM,YAAY,CAAC;AAC/B,YAAY,EACR,UAAU,EACV,UAAU,EACb,MAAM,YAAY,CAAC"}
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file index.ts
3
3
  * @brief Public builder module aggregation.
4
+ * @details This barrel keeps public import paths stable while implementation files remain
5
+ * split by responsibility.
4
6
  */
5
7
  export { array, discriminatedUnion, intersect, record, tuple, union } from "./composite.js";
6
8
  export { lazy, nullable, optional, refine, undefinedable } from "./modifier.js";
@@ -1,26 +1,51 @@
1
1
  /**
2
2
  * @file modifier.ts
3
3
  * @brief Presence, lazy, and refinement guard builders.
4
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
5
+ * with stable metadata.
4
6
  */
5
7
  import { BaseGuard, type Guard, type GuardPresence, type GuardValue, type Infer, type Presence } from "../guard/index.js";
6
8
  /**
7
- * @brief optional.
9
+ * @brief Mark a guard optional for object shape construction.
10
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
11
+ * with stable metadata.
12
+ * @param guard Guard whose value type is preserved.
13
+ * @returns Fresh optional guard.
8
14
  */
9
15
  export declare function optional<TGuard extends Guard<unknown, Presence>>(guard: TGuard): BaseGuard<GuardValue<TGuard>, "optional">;
10
16
  /**
11
- * @brief undefinedable.
17
+ * @brief Allow explicit undefined as a value.
18
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
19
+ * with stable metadata.
20
+ * @param guard Guard to wrap.
21
+ * @returns Fresh undefinedable guard preserving original presence.
12
22
  */
13
23
  export declare function undefinedable<TGuard extends Guard<unknown, Presence>>(guard: TGuard): BaseGuard<GuardValue<TGuard> | undefined, GuardPresence<TGuard>>;
14
24
  /**
15
- * @brief nullable.
25
+ * @brief Allow explicit null as a value.
26
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
27
+ * with stable metadata.
28
+ * @param guard Guard to wrap.
29
+ * @returns Fresh nullable guard preserving original presence.
16
30
  */
17
31
  export declare function nullable<TGuard extends Guard<unknown, Presence>>(guard: TGuard): BaseGuard<GuardValue<TGuard> | null, GuardPresence<TGuard>>;
18
32
  /**
19
- * @brief lazy.
33
+ * @brief Resolve recursive schemas once and reuse the frozen schema handle.
34
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
35
+ * with stable metadata.
36
+ * @param get Resolver returning the recursive guard.
37
+ * @returns Fresh lazy guard.
38
+ * @throws TypeError when the resolver is not callable.
20
39
  */
21
40
  export declare function lazy<TGuard extends Guard<unknown, Presence>>(get: () => TGuard): BaseGuard<Infer<TGuard>>;
22
41
  /**
23
- * @brief refine.
42
+ * @brief Attach a boolean refinement while preserving TypeSea's strict true contract.
43
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
44
+ * with stable metadata.
45
+ * @param guard Guard that must pass before the predicate runs.
46
+ * @param predicate User predicate that must return the boolean literal true.
47
+ * @param name Diagnostic name for refinement failures.
48
+ * @returns Fresh refined guard.
24
49
  */
25
50
  export declare function refine<TGuard extends Guard<unknown, Presence>>(guard: TGuard, predicate: (value: Infer<TGuard>) => boolean, name: string): BaseGuard<GuardValue<TGuard>, GuardPresence<TGuard>>;
26
51
  //# sourceMappingURL=modifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"modifier.d.ts","sourceRoot":"","sources":["../../src/builders/modifier.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,SAAS,EACT,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAI3B;;GAEG;AACH,wBAAgB,QAAQ,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAC9D,KAAK,EAAE,MAAM,GACZ,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAK3C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EACnE,KAAK,EAAE,MAAM,GACZ,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,aAAa,CAAC,MAAM,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AS,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAKlE;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAC5D,KAAK,EAAE,MAAM,GACd,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAK7D;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EACxD,GAAG,EAAE,MAAM,MAAM,GAClB,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAgB1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAC1D,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,OAAO,EAC5C,IAAI,EAAE,MAAM,GACb,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAkBtD"}
@@ -1,12 +1,18 @@
1
1
  /**
2
2
  * @file modifier.ts
3
3
  * @brief Presence, lazy, and refinement guard builders.
4
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
5
+ * with stable metadata.
4
6
  */
5
7
  import { SchemaTag } from "../kind/index.js";
6
8
  import { BaseGuard } from "../guard/index.js";
7
9
  import { isStrictTrue, readGuardSchema } from "../internal/index.js";
8
10
  /**
9
- * @brief optional.
11
+ * @brief Mark a guard optional for object shape construction.
12
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
13
+ * with stable metadata.
14
+ * @param guard Guard whose value type is preserved.
15
+ * @returns Fresh optional guard.
10
16
  */
11
17
  export function optional(guard) {
12
18
  return new BaseGuard({
@@ -15,7 +21,11 @@ export function optional(guard) {
15
21
  });
16
22
  }
17
23
  /**
18
- * @brief undefinedable.
24
+ * @brief Allow explicit undefined as a value.
25
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
26
+ * with stable metadata.
27
+ * @param guard Guard to wrap.
28
+ * @returns Fresh undefinedable guard preserving original presence.
19
29
  */
20
30
  export function undefinedable(guard) {
21
31
  return new BaseGuard({
@@ -24,7 +34,11 @@ export function undefinedable(guard) {
24
34
  });
25
35
  }
26
36
  /**
27
- * @brief nullable.
37
+ * @brief Allow explicit null as a value.
38
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
39
+ * with stable metadata.
40
+ * @param guard Guard to wrap.
41
+ * @returns Fresh nullable guard preserving original presence.
28
42
  */
29
43
  export function nullable(guard) {
30
44
  return new BaseGuard({
@@ -33,7 +47,12 @@ export function nullable(guard) {
33
47
  });
34
48
  }
35
49
  /**
36
- * @brief lazy.
50
+ * @brief Resolve recursive schemas once and reuse the frozen schema handle.
51
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
52
+ * with stable metadata.
53
+ * @param get Resolver returning the recursive guard.
54
+ * @returns Fresh lazy guard.
55
+ * @throws TypeError when the resolver is not callable.
37
56
  */
38
57
  export function lazy(get) {
39
58
  if (typeof get !== "function") {
@@ -43,13 +62,23 @@ export function lazy(get) {
43
62
  return new BaseGuard({
44
63
  tag: SchemaTag.Lazy,
45
64
  get: () => {
65
+ /*
66
+ * Cache the resolved schema rather than the guard wrapper. This keeps
67
+ * recursive validation stable after the first successful resolution.
68
+ */
46
69
  cached ??= readGuardSchema(get(), "lazy result");
47
70
  return cached;
48
71
  }
49
72
  });
50
73
  }
51
74
  /**
52
- * @brief refine.
75
+ * @brief Attach a boolean refinement while preserving TypeSea's strict true contract.
76
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
77
+ * with stable metadata.
78
+ * @param guard Guard that must pass before the predicate runs.
79
+ * @param predicate User predicate that must return the boolean literal true.
80
+ * @param name Diagnostic name for refinement failures.
81
+ * @returns Fresh refined guard.
53
82
  */
54
83
  export function refine(guard, predicate, name) {
55
84
  if (typeof predicate !== "function") {
@@ -61,6 +90,10 @@ export function refine(guard, predicate, name) {
61
90
  return new BaseGuard({
62
91
  tag: SchemaTag.Refine,
63
92
  inner: readGuardSchema(guard, "refine inner"),
93
+ /*
94
+ * Truthy non-boolean values are rejected. This keeps refinement behavior
95
+ * identical between interpreted and compiled validation paths.
96
+ */
64
97
  predicate: (value) => isStrictTrue(predicate(value)),
65
98
  name
66
99
  });
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file guard.ts
3
3
  * @brief Object guard class and object builder API.
4
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
5
+ * with stable metadata.
4
6
  */
5
7
  import type { ObjectSchema } from "../../schema/index.js";
6
8
  import { ObjectModeTag } from "../../kind/index.js";
@@ -8,55 +10,49 @@ import { BaseGuard } from "../../guard/index.js";
8
10
  import type { ObjectGuardMode, ObjectShape, InferObject, MergeObjectShapes, OmitObjectShape, PartialObjectShape, PickObjectShape, StringKeyOf } from "./types.js";
9
11
  /**
10
12
  * @brief Guard subclass with object-specific shape operations.
13
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
14
+ * with stable metadata.
11
15
  *
12
16
  * @invariant Methods preserve the original object mode. Strict schemas stay
13
17
  * strict after shape edits; passthrough schemas stay passthrough.
14
18
  */
15
19
  export declare class ObjectGuard<TShape extends ObjectShape, TMode extends ObjectGuardMode> extends BaseGuard<InferObject<TShape>> {
16
- /**
17
- * @brief constructor.
18
- * @post The receiver is initialized according to the class invariant before it can be observed.
19
- */
20
20
  constructor(schema: ObjectSchema);
21
- /**
22
- * @brief extend.
23
- */
24
21
  extend<const TExtension extends ObjectShape>(extension: TExtension): ObjectGuard<MergeObjectShapes<TShape, TExtension>, TMode>;
25
- /**
26
- * @brief pick.
27
- */
28
22
  pick<const TKeys extends readonly StringKeyOf<TShape>[]>(keys: TKeys): ObjectGuard<PickObjectShape<TShape, TKeys[number]>, TMode>;
29
- /**
30
- * @brief omit.
31
- */
32
23
  omit<const TKeys extends readonly StringKeyOf<TShape>[]>(keys: TKeys): ObjectGuard<OmitObjectShape<TShape, TKeys[number]>, TMode>;
33
- /**
34
- * @brief partial.
35
- */
36
24
  partial(): ObjectGuard<PartialObjectShape<TShape>, TMode>;
37
25
  }
38
26
  /**
39
- * @brief object.
27
+ * @brief Build an object guard that accepts unspecified enumerable keys.
28
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
29
+ * with stable metadata.
40
30
  */
41
31
  export declare function object<const TShape extends ObjectShape>(shape: TShape): ObjectGuard<TShape, typeof ObjectModeTag.Passthrough>;
42
32
  /**
43
- * @brief strict object.
33
+ * @brief Build an object guard that rejects unspecified own keys.
34
+ * @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
35
+ * with stable metadata.
44
36
  */
45
37
  export declare function strictObject<const TShape extends ObjectShape>(shape: TShape): ObjectGuard<TShape, typeof ObjectModeTag.Strict>;
46
38
  /**
47
- * @brief extend.
39
+ * @brief Execute extend.
40
+ * @details This helper keeps a local invariant explicit at the module boundary.
48
41
  */
49
42
  export declare function extend<const TShape extends ObjectShape, TMode extends ObjectGuardMode, const TExtension extends ObjectShape>(guard: ObjectGuard<TShape, TMode>, extension: TExtension): ObjectGuard<MergeObjectShapes<TShape, TExtension>, TMode>;
50
43
  /**
51
- * @brief pick.
44
+ * @brief Execute pick.
45
+ * @details This helper keeps a local invariant explicit at the module boundary.
52
46
  */
53
47
  export declare function pick<const TShape extends ObjectShape, TMode extends ObjectGuardMode, const TKeys extends readonly StringKeyOf<TShape>[]>(guard: ObjectGuard<TShape, TMode>, keys: TKeys): ObjectGuard<PickObjectShape<TShape, TKeys[number]>, TMode>;
54
48
  /**
55
- * @brief omit.
49
+ * @brief Execute omit.
50
+ * @details This helper keeps a local invariant explicit at the module boundary.
56
51
  */
57
52
  export declare function omit<const TShape extends ObjectShape, TMode extends ObjectGuardMode, const TKeys extends readonly StringKeyOf<TShape>[]>(guard: ObjectGuard<TShape, TMode>, keys: TKeys): ObjectGuard<OmitObjectShape<TShape, TKeys[number]>, TMode>;
58
53
  /**
59
- * @brief partial.
54
+ * @brief Execute partial.
55
+ * @details This helper keeps a local invariant explicit at the module boundary.
60
56
  */
61
57
  export declare function partial<const TShape extends ObjectShape, TMode extends ObjectGuardMode>(guard: ObjectGuard<TShape, TMode>): ObjectGuard<PartialObjectShape<TShape>, TMode>;
62
58
  //# sourceMappingURL=guard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../../src/builders/object/guard.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,WAAW,EACZ,MAAM,YAAY,CAAC;AAYpB;;;;;GAKG;AACH,qBAAa,WAAW,CACtB,MAAM,SAAS,WAAW,EAC1B,KAAK,SAAS,eAAe,CAC7B,SAAQ,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAEtC;;;OAGG;gBACgB,MAAM,EAAE,YAAY;IAKvC;;aAES;IACF,MAAM,CAAC,KAAK,CAAC,UAAU,SAAS,WAAW,EAChD,SAAS,EAAE,UAAU,GACpB,WAAW,CAAC,iBAAiB,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,KAAK,CAAC;IAI5D;;aAES;IACF,IAAI,CAAC,KAAK,CAAC,KAAK,SAAS,SAAS,WAAW,CAAC,MAAM,CAAC,EAAE,EAC5D,IAAI,EAAE,KAAK,GACV,WAAW,CAAC,eAAe,CAAC,MA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