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,6 +1,8 @@
1
1
  /**
2
2
  * @file base.ts
3
3
  * @brief Base guard implementation.
4
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
5
+ * existing guard instance.
4
6
  */
5
7
  import { SchemaTag } from "../kind/index.js";
6
8
  import { checkSchema, isSchema } from "../evaluate/index.js";
@@ -10,37 +12,62 @@ import { checkRefinementInput, readConstructorSchema, readGuardSchema } from "./
10
12
  import { defineReadonlyProperty, isStrictTrue } from "./props.js";
11
13
  import { registerConstructedGuard } from "./registry.js";
12
14
  /**
13
- * @brief base guard.
14
- * @details Owns its state directly; methods expose receiver checks and explicit result flow.
15
- * @invariant Construction leaves the instance in a fully usable state before it escapes.
15
+ * @brief Schema-backed guard base.
16
+ * @details Methods accept an unknown receiver on purpose. Public JavaScript can
17
+ * detach or forge methods, so every entry point re-reads the runtime schema
18
+ * before executing validation.
19
+ * @invariant The stored schema is immutable after construction.
16
20
  */
17
21
  export class BaseGuard {
18
22
  /**
19
- * @brief constructor.
20
- * @post The receiver is initialized according to the class invariant before it can be observed.
23
+ * @brief Construct a schema-backed guard.
24
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
25
+ * existing guard instance.
26
+ * @param schema Runtime schema owned by the guard.
27
+ * @post The schema slot is frozen and the receiver is registered for fast checks.
21
28
  */
22
29
  constructor(schema) {
23
30
  defineReadonlyProperty(this, "schema", readConstructorSchema(schema), true);
24
31
  registerConstructedGuard(this);
25
32
  if (new.target === BaseGuard) {
33
+ /*
34
+ * Direct BaseGuard instances have no subclass state. Freeze them here
35
+ * so user code cannot mutate the public validation object after setup.
36
+ */
26
37
  Object.freeze(this);
27
38
  }
28
39
  }
29
40
  /**
30
- * @brief is.
31
- */
41
+ * @brief Test whether a value satisfies this guard.
42
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
43
+ * existing guard instance.
44
+ * @param value Candidate runtime value.
45
+ * @returns True when the value is accepted by the guard schema.
46
+ */
32
47
  is(value) {
48
+ /*
49
+ * Methods may be detached from their instance in JavaScript. Re-reading
50
+ * the schema from `this` makes receiver forgery fail before validation.
51
+ */
33
52
  return isSchema(readGuardSchema(this, "guard receiver"), value);
34
53
  }
35
54
  /**
36
- * @brief check.
37
- */
55
+ * @brief Validate a value and return explicit diagnostics.
56
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
57
+ * existing guard instance.
58
+ * @param value Candidate runtime value.
59
+ * @returns Result carrying the value on success or frozen issues on failure.
60
+ */
38
61
  check(value) {
39
62
  return checkSchema(readGuardSchema(this, "guard receiver"), value);
40
63
  }
41
64
  /**
42
- * @brief assert.
43
- */
65
+ * @brief Validate a value and throw TypeSeaAssertionError on failure.
66
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
67
+ * existing guard instance.
68
+ * @param value Candidate runtime value.
69
+ * @throws TypeSeaAssertionError when validation fails.
70
+ */
44
71
  assert(value) {
45
72
  const result = checkSchema(readGuardSchema(this, "guard receiver"), value);
46
73
  if (!result.ok) {
@@ -48,14 +75,20 @@ export class BaseGuard {
48
75
  }
49
76
  }
50
77
  /**
51
- * @brief graph.
52
- */
78
+ * @brief Return the optimized validation graph for introspection.
79
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
80
+ * existing guard instance.
81
+ * @returns Sea-of-Nodes graph derived from the guard schema.
82
+ */
53
83
  graph() {
54
84
  return makeValidationPlan(readGuardSchema(this, "guard receiver")).graph;
55
85
  }
56
86
  /**
57
- * @brief optional.
58
- */
87
+ * @brief Mark this guard as optional in object shapes.
88
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
89
+ * existing guard instance.
90
+ * @returns Fresh guard whose runtime value also allows absent object keys.
91
+ */
59
92
  optional() {
60
93
  return new BaseGuard({
61
94
  tag: SchemaTag.Optional,
@@ -63,8 +96,11 @@ export class BaseGuard {
63
96
  });
64
97
  }
65
98
  /**
66
- * @brief undefinedable.
67
- */
99
+ * @brief Allow the explicit undefined value.
100
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
101
+ * existing guard instance.
102
+ * @returns Fresh guard wrapping this schema in Undefinedable.
103
+ */
68
104
  undefinedable() {
69
105
  return new BaseGuard({
70
106
  tag: SchemaTag.Undefinedable,
@@ -72,8 +108,11 @@ export class BaseGuard {
72
108
  });
73
109
  }
74
110
  /**
75
- * @brief nullable.
76
- */
111
+ * @brief Allow the explicit null value.
112
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
113
+ * existing guard instance.
114
+ * @returns Fresh guard wrapping this schema in Nullable.
115
+ */
77
116
  nullable() {
78
117
  return new BaseGuard({
79
118
  tag: SchemaTag.Nullable,
@@ -81,8 +120,11 @@ export class BaseGuard {
81
120
  });
82
121
  }
83
122
  /**
84
- * @brief array.
85
- */
123
+ * @brief Build an array guard using this guard as the item schema.
124
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
125
+ * existing guard instance.
126
+ * @returns Fresh array guard.
127
+ */
86
128
  array() {
87
129
  return new BaseGuard({
88
130
  tag: SchemaTag.Array,
@@ -90,8 +132,11 @@ export class BaseGuard {
90
132
  });
91
133
  }
92
134
  /**
93
- * @brief brand.
94
- */
135
+ * @brief Attach a compile-time brand without changing runtime validation.
136
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
137
+ * existing guard instance.
138
+ * @returns Fresh branded guard with the same runtime schema.
139
+ */
95
140
  brand() {
96
141
  return new BaseGuard({
97
142
  tag: SchemaTag.Brand,
@@ -100,20 +145,33 @@ export class BaseGuard {
100
145
  });
101
146
  }
102
147
  /**
103
- * @brief refine.
104
- */
148
+ * @brief Append a user refinement predicate after this guard succeeds.
149
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
150
+ * existing guard instance.
151
+ * @param predicate Function that must return the boolean literal true.
152
+ * @param name Diagnostic name for refinement failure.
153
+ * @returns Fresh refined guard.
154
+ */
105
155
  refine(predicate, name) {
106
156
  checkRefinementInput(predicate, name);
107
157
  return new BaseGuard({
108
158
  tag: SchemaTag.Refine,
109
159
  inner: readGuardSchema(this, "refine inner"),
160
+ /*
161
+ * The predicate is wrapped so only strict true succeeds. Truthy
162
+ * non-boolean values stay failures, matching the interpreter helper.
163
+ */
110
164
  predicate: (value) => isStrictTrue(predicate(value)),
111
165
  name
112
166
  });
113
167
  }
114
168
  /**
115
- * @brief or.
116
- */
169
+ * @brief Build a union of this guard and another guard.
170
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
171
+ * existing guard instance.
172
+ * @param other Right-hand guard.
173
+ * @returns Fresh union guard preserving both runtime schemas.
174
+ */
117
175
  or(other) {
118
176
  return new BaseGuard({
119
177
  tag: SchemaTag.Union,
@@ -124,8 +182,12 @@ export class BaseGuard {
124
182
  });
125
183
  }
126
184
  /**
127
- * @brief intersect.
128
- */
185
+ * @brief Build an intersection of this guard and another guard.
186
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
187
+ * existing guard instance.
188
+ * @param other Right-hand guard.
189
+ * @returns Fresh intersection guard requiring both schemas to pass.
190
+ */
129
191
  intersect(other) {
130
192
  return new BaseGuard({
131
193
  tag: SchemaTag.Intersection,
@@ -1,18 +1,23 @@
1
1
  /**
2
2
  * @file error.ts
3
3
  * @brief TypeSea assertion error.
4
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
5
+ * existing guard instance.
4
6
  */
5
7
  import type { Issue } from "../issue/index.js";
6
8
  /**
7
- * @brief type sea assertion error.
8
- * @details Owns its state directly; methods expose receiver checks and explicit result flow.
9
- * @invariant Construction leaves the instance in a fully usable state before it escapes.
9
+ * @brief Error thrown by assert() after validation has already produced issues.
10
+ * @details The issue array is copied before publication so callers cannot mutate
11
+ * diagnostic state through the error object.
10
12
  */
11
13
  export declare class TypeSeaAssertionError extends Error {
12
14
  readonly issues: readonly Issue[];
13
15
  /**
14
- * @brief constructor.
15
- * @post The receiver is initialized according to the class invariant before it can be observed.
16
+ * @brief Construct an assertion error from validation issues.
17
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
18
+ * existing guard instance.
19
+ * @param issues Issues produced by checkSchema.
20
+ * @post Published issues are copied and exposed through a readonly property.
16
21
  */
17
22
  constructor(issues: readonly Issue[]);
18
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/guard/error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI/C;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,SAAwB,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAEjD;;;OAGG;gBACgB,MAAM,EAAE,SAAS,KAAK,EAAE;CAK5C"}
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/guard/error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI/C;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC5C,SAAwB,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAEjD;;;;;;OAMG;gBACgB,MAAM,EAAE,SAAS,KAAK,EAAE;CAK9C"}
@@ -1,18 +1,23 @@
1
1
  /**
2
2
  * @file error.ts
3
3
  * @brief TypeSea assertion error.
4
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
5
+ * existing guard instance.
4
6
  */
5
7
  import { copyIssueArray } from "../issue/index.js";
6
8
  import { defineReadonlyProperty } from "./props.js";
7
9
  /**
8
- * @brief type sea assertion error.
9
- * @details Owns its state directly; methods expose receiver checks and explicit result flow.
10
- * @invariant Construction leaves the instance in a fully usable state before it escapes.
10
+ * @brief Error thrown by assert() after validation has already produced issues.
11
+ * @details The issue array is copied before publication so callers cannot mutate
12
+ * diagnostic state through the error object.
11
13
  */
12
14
  export class TypeSeaAssertionError extends Error {
13
15
  /**
14
- * @brief constructor.
15
- * @post The receiver is initialized according to the class invariant before it can be observed.
16
+ * @brief Construct an assertion error from validation issues.
17
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
18
+ * existing guard instance.
19
+ * @param issues Issues produced by checkSchema.
20
+ * @post Published issues are copied and exposed through a readonly property.
16
21
  */
17
22
  constructor(issues) {
18
23
  super("TypeSea assertion failed");
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file index.ts
3
3
  * @brief Public guard module aggregation.
4
+ * @details This barrel keeps public import paths stable while implementation files remain
5
+ * split by responsibility.
4
6
  */
5
7
  export { BaseGuard } from "./base.js";
6
8
  export { TypeSeaAssertionError } from "./error.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guard/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EACV,KAAK,EACL,KAAK,EACL,aAAa,EACb,UAAU,EACV,KAAK,EACL,QAAQ,EACR,YAAY,EACb,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guard/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EACR,KAAK,EACL,KAAK,EACL,aAAa,EACb,UAAU,EACV,KAAK,EACL,QAAQ,EACR,YAAY,EACf,MAAM,YAAY,CAAC"}
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file index.ts
3
3
  * @brief Public guard module aggregation.
4
+ * @details This barrel keeps public import paths stable while implementation files remain
5
+ * split by responsibility.
4
6
  */
5
7
  export { BaseGuard } from "./base.js";
6
8
  export { TypeSeaAssertionError } from "./error.js";
@@ -1,32 +1,47 @@
1
1
  /**
2
2
  * @file number.ts
3
3
  * @brief Number guard implementation.
4
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
5
+ * existing guard instance.
4
6
  */
5
7
  import type { NumberSchema } from "../schema/index.js";
6
8
  import { BaseGuard } from "./base.js";
7
9
  import type { Presence } from "./types.js";
8
10
  /**
9
- * @brief number guard.
10
- * @details Owns its state directly; methods expose receiver checks and explicit result flow.
11
- * @invariant Construction leaves the instance in a fully usable state before it escapes.
11
+ * @brief Persistent builder for finite number predicates.
12
+ * @details Bounds are normalized before entering the schema so the evaluator
13
+ * and compiler never have to defend against NaN or infinities later.
12
14
  */
13
15
  export declare class NumberGuard<TPresence extends Presence = "required"> extends BaseGuard<number, TPresence> {
14
16
  /**
15
- * @brief constructor.
16
- * @post The receiver is initialized according to the class invariant before it can be observed.
17
+ * @brief Construct a frozen number guard.
18
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
19
+ * existing guard instance.
20
+ * @param schema Number schema backing this guard.
17
21
  */
18
22
  constructor(schema: NumberSchema);
19
23
  /**
20
- * @brief int.
21
- */
24
+ * @brief Require finite numbers to be integers.
25
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
26
+ * existing guard instance.
27
+ * @returns Fresh NumberGuard with an appended integer check.
28
+ */
22
29
  int(): NumberGuard<TPresence>;
23
30
  /**
24
- * @brief gte.
25
- */
31
+ * @brief Add an inclusive lower bound.
32
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
33
+ * existing guard instance.
34
+ * @param value Finite lower bound.
35
+ * @returns Fresh NumberGuard with an appended gte check.
36
+ */
26
37
  gte(value: number): NumberGuard<TPresence>;
27
38
  /**
28
- * @brief lte.
29
- */
39
+ * @brief Add an inclusive upper bound.
40
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
41
+ * existing guard instance.
42
+ * @param value Finite upper bound.
43
+ * @returns Fresh NumberGuard with an appended lte check.
44
+ */
30
45
  lte(value: number): NumberGuard<TPresence>;
31
46
  }
32
47
  //# sourceMappingURL=number.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/guard/number.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAMtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;GAIG;AACH,qBAAa,WAAW,CACtB,SAAS,SAAS,QAAQ,GAAG,UAAU,CACvC,SAAQ,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC;IAEpC;;;OAGG;gBACgB,MAAM,EAAE,YAAY;IAKvC;;WAEO;IACA,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC;IAapC;;aAES;IACF,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC;IAejD;;aAES;IACF,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC;CAclD"}
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/guard/number.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAMtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;GAIG;AACH,qBAAa,WAAW,CACpB,SAAS,SAAS,QAAQ,GAAG,UAAU,CACzC,SAAQ,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC;IAElC;;;;;OAKG;gBACgB,MAAM,EAAE,YAAY;IAKvC;;;;;OAKG;IACI,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC;IAapC;;;;;;OAMG;IACI,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC;IAmBjD;;;;;;OAMG;IACI,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC;CAcpD"}
@@ -1,27 +1,34 @@
1
1
  /**
2
2
  * @file number.ts
3
3
  * @brief Number guard implementation.
4
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
5
+ * existing guard instance.
4
6
  */
5
7
  import { NumberCheckTag, SchemaTag } from "../kind/index.js";
6
8
  import { BaseGuard } from "./base.js";
7
9
  import { checkFiniteNumberBound, readNumberConstructorSchema, readNumberMethodSchema } from "./read.js";
8
10
  /**
9
- * @brief number guard.
10
- * @details Owns its state directly; methods expose receiver checks and explicit result flow.
11
- * @invariant Construction leaves the instance in a fully usable state before it escapes.
11
+ * @brief Persistent builder for finite number predicates.
12
+ * @details Bounds are normalized before entering the schema so the evaluator
13
+ * and compiler never have to defend against NaN or infinities later.
12
14
  */
13
15
  export class NumberGuard extends BaseGuard {
14
16
  /**
15
- * @brief constructor.
16
- * @post The receiver is initialized according to the class invariant before it can be observed.
17
+ * @brief Construct a frozen number guard.
18
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
19
+ * existing guard instance.
20
+ * @param schema Number schema backing this guard.
17
21
  */
18
22
  constructor(schema) {
19
23
  super(readNumberConstructorSchema(schema));
20
24
  Object.freeze(this);
21
25
  }
22
26
  /**
23
- * @brief int.
24
- */
27
+ * @brief Require finite numbers to be integers.
28
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
29
+ * existing guard instance.
30
+ * @returns Fresh NumberGuard with an appended integer check.
31
+ */
25
32
  int() {
26
33
  const schema = readNumberMethodSchema(this, "number int receiver");
27
34
  return new NumberGuard({
@@ -35,11 +42,19 @@ export class NumberGuard extends BaseGuard {
35
42
  });
36
43
  }
37
44
  /**
38
- * @brief gte.
39
- */
45
+ * @brief Add an inclusive lower bound.
46
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
47
+ * existing guard instance.
48
+ * @param value Finite lower bound.
49
+ * @returns Fresh NumberGuard with an appended gte check.
50
+ */
40
51
  gte(value) {
41
52
  const schema = readNumberMethodSchema(this, "number gte receiver");
42
53
  const bound = checkFiniteNumberBound(value, "gte");
54
+ /*
55
+ * Bounds are normalized before schema construction so interpreters and
56
+ * compilers never need to handle NaN or infinity inside hot validation.
57
+ */
43
58
  return new NumberGuard({
44
59
  tag: SchemaTag.Number,
45
60
  checks: [
@@ -52,8 +67,12 @@ export class NumberGuard extends BaseGuard {
52
67
  });
53
68
  }
54
69
  /**
55
- * @brief lte.
56
- */
70
+ * @brief Add an inclusive upper bound.
71
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
72
+ * existing guard instance.
73
+ * @param value Finite upper bound.
74
+ * @returns Fresh NumberGuard with an appended lte check.
75
+ */
57
76
  lte(value) {
58
77
  const schema = readNumberMethodSchema(this, "number lte receiver");
59
78
  const bound = checkFiniteNumberBound(value, "lte");
@@ -1,18 +1,42 @@
1
1
  /**
2
2
  * @file props.ts
3
3
  * @brief Guard object shape helpers.
4
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
5
+ * existing guard instance.
6
+ */
7
+ /**
8
+ * @brief Define one immutable public property.
9
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
10
+ * existing guard instance.
11
+ * @param target Object receiving the property.
12
+ * @param key Property key.
13
+ * @param value Stored property value.
14
+ * @param enumerable Whether the property should appear in enumeration.
15
+ * @post The property is non-configurable and non-writable.
4
16
  */
5
17
  export declare function defineReadonlyProperty(target: object, key: string, value: unknown, enumerable: boolean): void;
6
18
  /**
7
- * @brief is strict true.
19
+ * @brief Test for the only accepted refinement success value.
20
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
21
+ * existing guard instance.
22
+ * @param value Predicate return value.
23
+ * @returns True only for the boolean literal true.
8
24
  */
9
25
  export declare function isStrictTrue(value: unknown): boolean;
10
26
  /**
11
- * @brief is record.
27
+ * @brief Test whether a value is a non-array object record.
28
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
29
+ * existing guard instance.
30
+ * @param value Candidate runtime value.
31
+ * @returns True for object values that can carry string properties.
12
32
  */
13
33
  export declare function isRecord(value: unknown): value is Readonly<Record<string, unknown>>;
14
34
  /**
15
- * @brief is plain reg exp.
35
+ * @brief Accept only unmodified RegExp instances for schema storage.
36
+ * @details User-owned exec/test/source/flags overrides can change validation
37
+ * behavior after construction, so they are rejected at the API boundary.
38
+ * @param value Candidate pattern.
39
+ * @returns True for plain RegExp instances without own behavioral overrides.
16
40
  */
17
41
  export declare function isPlainRegExp(value: unknown): value is RegExp;
18
42
  //# sourceMappingURL=props.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/guard/props.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,EACd,UAAU,EAAE,OAAO,GAClB,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAEnF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAO7D"}
1
+ {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/guard/props.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAClC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,EACd,UAAU,EAAE,OAAO,GACpB,IAAI,CAON;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAEnF;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAO7D"}
@@ -1,6 +1,18 @@
1
1
  /**
2
2
  * @file props.ts
3
3
  * @brief Guard object shape helpers.
4
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
5
+ * existing guard instance.
6
+ */
7
+ /**
8
+ * @brief Define one immutable public property.
9
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
10
+ * existing guard instance.
11
+ * @param target Object receiving the property.
12
+ * @param key Property key.
13
+ * @param value Stored property value.
14
+ * @param enumerable Whether the property should appear in enumeration.
15
+ * @post The property is non-configurable and non-writable.
4
16
  */
5
17
  export function defineReadonlyProperty(target, key, value, enumerable) {
6
18
  Object.defineProperty(target, key, {
@@ -11,19 +23,31 @@ export function defineReadonlyProperty(target, key, value, enumerable) {
11
23
  });
12
24
  }
13
25
  /**
14
- * @brief is strict true.
26
+ * @brief Test for the only accepted refinement success value.
27
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
28
+ * existing guard instance.
29
+ * @param value Predicate return value.
30
+ * @returns True only for the boolean literal true.
15
31
  */
16
32
  export function isStrictTrue(value) {
17
33
  return value === true;
18
34
  }
19
35
  /**
20
- * @brief is record.
36
+ * @brief Test whether a value is a non-array object record.
37
+ * @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
38
+ * existing guard instance.
39
+ * @param value Candidate runtime value.
40
+ * @returns True for object values that can carry string properties.
21
41
  */
22
42
  export function isRecord(value) {
23
43
  return typeof value === "object" && value !== null && !Array.isArray(value);
24
44
  }
25
45
  /**
26
- * @brief is plain reg exp.
46
+ * @brief Accept only unmodified RegExp instances for schema storage.
47
+ * @details User-owned exec/test/source/flags overrides can change validation
48
+ * behavior after construction, so they are rejected at the API boundary.
49
+ * @param value Candidate pattern.
50
+ * @returns True for plain RegExp instances without own behavioral overrides.
27
51
  */
28
52
  export function isPlainRegExp(value) {
29
53
  return value instanceof RegExp &&