typesea 0.1.0 → 0.3.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 (301) hide show
  1. package/CHANGELOG.md +85 -6
  2. package/README.md +143 -28
  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 +19 -3
  7. package/dist/aot/index.d.ts.map +1 -1
  8. package/dist/aot/index.js +115 -17
  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 +43 -9
  13. package/dist/builders/composite.d.ts.map +1 -1
  14. package/dist/builders/composite.js +100 -17
  15. package/dist/builders/index.d.ts +8 -5
  16. package/dist/builders/index.d.ts.map +1 -1
  17. package/dist/builders/index.js +7 -4
  18. package/dist/builders/modifier.d.ts +36 -5
  19. package/dist/builders/modifier.d.ts.map +1 -1
  20. package/dist/builders/modifier.js +52 -5
  21. package/dist/builders/object/guard.d.ts +72 -24
  22. package/dist/builders/object/guard.d.ts.map +1 -1
  23. package/dist/builders/object/guard.js +139 -29
  24. package/dist/builders/object/index.d.ts +4 -2
  25. package/dist/builders/object/index.d.ts.map +1 -1
  26. package/dist/builders/object/index.js +3 -1
  27. package/dist/builders/object/schema.d.ts +88 -11
  28. package/dist/builders/object/schema.d.ts.map +1 -1
  29. package/dist/builders/object/schema.js +290 -23
  30. package/dist/builders/object/types.d.ts +20 -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/runtime.d.ts +40 -0
  34. package/dist/builders/runtime.d.ts.map +1 -0
  35. package/dist/builders/runtime.js +150 -0
  36. package/dist/builders/scalar.d.ts +49 -9
  37. package/dist/builders/scalar.d.ts.map +1 -1
  38. package/dist/builders/scalar.js +87 -9
  39. package/dist/builders/table.d.ts +35 -5
  40. package/dist/builders/table.d.ts.map +1 -1
  41. package/dist/builders/table.js +35 -5
  42. package/dist/builders/types.d.ts +20 -4
  43. package/dist/builders/types.d.ts.map +1 -1
  44. package/dist/builders/types.js +2 -0
  45. package/dist/compile/check-composite.d.ts +25 -2
  46. package/dist/compile/check-composite.d.ts.map +1 -1
  47. package/dist/compile/check-composite.js +699 -27
  48. package/dist/compile/check-scalar.d.ts +88 -0
  49. package/dist/compile/check-scalar.d.ts.map +1 -1
  50. package/dist/compile/check-scalar.js +570 -3
  51. package/dist/compile/check.d.ts +12 -0
  52. package/dist/compile/check.d.ts.map +1 -1
  53. package/dist/compile/check.js +62 -3
  54. package/dist/compile/context.d.ts +47 -9
  55. package/dist/compile/context.d.ts.map +1 -1
  56. package/dist/compile/context.js +53 -8
  57. package/dist/compile/first.d.ts +26 -0
  58. package/dist/compile/first.d.ts.map +1 -0
  59. package/dist/compile/first.js +850 -0
  60. package/dist/compile/graph-predicate.d.ts +4 -2
  61. package/dist/compile/graph-predicate.d.ts.map +1 -1
  62. package/dist/compile/graph-predicate.js +2272 -165
  63. package/dist/compile/guard.d.ts +16 -24
  64. package/dist/compile/guard.d.ts.map +1 -1
  65. package/dist/compile/guard.js +202 -72
  66. package/dist/compile/index.d.ts +3 -1
  67. package/dist/compile/index.d.ts.map +1 -1
  68. package/dist/compile/index.js +2 -0
  69. package/dist/compile/issue.d.ts +110 -0
  70. package/dist/compile/issue.d.ts.map +1 -1
  71. package/dist/compile/issue.js +184 -1
  72. package/dist/compile/names.d.ts +12 -2
  73. package/dist/compile/names.d.ts.map +1 -1
  74. package/dist/compile/names.js +19 -3
  75. package/dist/compile/predicate.d.ts +24 -0
  76. package/dist/compile/predicate.d.ts.map +1 -1
  77. package/dist/compile/predicate.js +287 -10
  78. package/dist/compile/runtime.d.ts +100 -13
  79. package/dist/compile/runtime.d.ts.map +1 -1
  80. package/dist/compile/runtime.js +56 -6
  81. package/dist/compile/source.d.ts +10 -2
  82. package/dist/compile/source.d.ts.map +1 -1
  83. package/dist/compile/source.js +385 -26
  84. package/dist/compile/types.d.ts +22 -0
  85. package/dist/compile/types.d.ts.map +1 -1
  86. package/dist/compile/types.js +2 -0
  87. package/dist/decoder/index.d.ts +92 -46
  88. package/dist/decoder/index.d.ts.map +1 -1
  89. package/dist/decoder/index.js +266 -39
  90. package/dist/evaluate/check-composite.d.ts +111 -2
  91. package/dist/evaluate/check-composite.d.ts.map +1 -1
  92. package/dist/evaluate/check-composite.js +343 -8
  93. package/dist/evaluate/check-scalar.d.ts +25 -0
  94. package/dist/evaluate/check-scalar.d.ts.map +1 -1
  95. package/dist/evaluate/check-scalar.js +124 -3
  96. package/dist/evaluate/check.d.ts +7 -0
  97. package/dist/evaluate/check.d.ts.map +1 -1
  98. package/dist/evaluate/check.js +62 -4
  99. package/dist/evaluate/index.d.ts +2 -0
  100. package/dist/evaluate/index.d.ts.map +1 -1
  101. package/dist/evaluate/index.js +2 -0
  102. package/dist/evaluate/issue.d.ts +11 -1
  103. package/dist/evaluate/issue.d.ts.map +1 -1
  104. package/dist/evaluate/issue.js +15 -1
  105. package/dist/evaluate/predicate.d.ts +16 -5
  106. package/dist/evaluate/predicate.d.ts.map +1 -1
  107. package/dist/evaluate/predicate.js +20 -5
  108. package/dist/evaluate/shared.d.ts +78 -13
  109. package/dist/evaluate/shared.d.ts.map +1 -1
  110. package/dist/evaluate/shared.js +101 -8
  111. package/dist/evaluate/state.d.ts +35 -13
  112. package/dist/evaluate/state.d.ts.map +1 -1
  113. package/dist/evaluate/state.js +35 -2
  114. package/dist/guard/array.d.ts +48 -0
  115. package/dist/guard/array.d.ts.map +1 -0
  116. package/dist/guard/array.js +84 -0
  117. package/dist/guard/base.d.ts +111 -31
  118. package/dist/guard/base.d.ts.map +1 -1
  119. package/dist/guard/base.js +165 -32
  120. package/dist/guard/date.d.ts +34 -0
  121. package/dist/guard/date.d.ts.map +1 -0
  122. package/dist/guard/date.js +60 -0
  123. package/dist/guard/error.d.ts +10 -5
  124. package/dist/guard/error.d.ts.map +1 -1
  125. package/dist/guard/error.js +10 -5
  126. package/dist/guard/index.d.ts +4 -0
  127. package/dist/guard/index.d.ts.map +1 -1
  128. package/dist/guard/index.js +4 -0
  129. package/dist/guard/number.d.ts +86 -11
  130. package/dist/guard/number.d.ts.map +1 -1
  131. package/dist/guard/number.js +159 -11
  132. package/dist/guard/props.d.ts +27 -3
  133. package/dist/guard/props.d.ts.map +1 -1
  134. package/dist/guard/props.js +27 -3
  135. package/dist/guard/read.d.ts +115 -10
  136. package/dist/guard/read.d.ts.map +1 -1
  137. package/dist/guard/read.js +185 -10
  138. package/dist/guard/registry.d.ts +12 -2
  139. package/dist/guard/registry.d.ts.map +1 -1
  140. package/dist/guard/registry.js +15 -3
  141. package/dist/guard/string.d.ts +115 -13
  142. package/dist/guard/string.d.ts.map +1 -1
  143. package/dist/guard/string.js +250 -13
  144. package/dist/guard/types.d.ts +110 -40
  145. package/dist/guard/types.d.ts.map +1 -1
  146. package/dist/guard/types.js +2 -0
  147. package/dist/index.d.ts +5 -5
  148. package/dist/index.d.ts.map +1 -1
  149. package/dist/index.js +4 -4
  150. package/dist/internal/index.d.ts +42 -6
  151. package/dist/internal/index.d.ts.map +1 -1
  152. package/dist/internal/index.js +51 -8
  153. package/dist/ir/builder.d.ts +17 -127
  154. package/dist/ir/builder.d.ts.map +1 -1
  155. package/dist/ir/builder.js +80 -137
  156. package/dist/ir/freeze.d.ts +4 -0
  157. package/dist/ir/freeze.d.ts.map +1 -1
  158. package/dist/ir/freeze.js +66 -0
  159. package/dist/ir/index.d.ts +3 -1
  160. package/dist/ir/index.d.ts.map +1 -1
  161. package/dist/ir/index.js +2 -0
  162. package/dist/ir/regexp.d.ts +2 -0
  163. package/dist/ir/regexp.d.ts.map +1 -1
  164. package/dist/ir/regexp.js +2 -0
  165. package/dist/ir/types.d.ts +94 -56
  166. package/dist/ir/types.d.ts.map +1 -1
  167. package/dist/ir/types.js +2 -0
  168. package/dist/ir/validate.d.ts +8 -1
  169. package/dist/ir/validate.d.ts.map +1 -1
  170. package/dist/ir/validate.js +511 -61
  171. package/dist/issue/index.d.ts +42 -10
  172. package/dist/issue/index.d.ts.map +1 -1
  173. package/dist/issue/index.js +65 -11
  174. package/dist/json-schema/emit-combinator.d.ts +44 -4
  175. package/dist/json-schema/emit-combinator.d.ts.map +1 -1
  176. package/dist/json-schema/emit-combinator.js +44 -4
  177. package/dist/json-schema/emit-composite.d.ts +16 -2
  178. package/dist/json-schema/emit-composite.d.ts.map +1 -1
  179. package/dist/json-schema/emit-composite.js +81 -13
  180. package/dist/json-schema/emit-scalar.d.ts +26 -3
  181. package/dist/json-schema/emit-scalar.d.ts.map +1 -1
  182. package/dist/json-schema/emit-scalar.js +124 -10
  183. package/dist/json-schema/emit-types.d.ts +11 -1
  184. package/dist/json-schema/emit-types.d.ts.map +1 -1
  185. package/dist/json-schema/emit-types.js +2 -0
  186. package/dist/json-schema/emit.d.ts +12 -1
  187. package/dist/json-schema/emit.d.ts.map +1 -1
  188. package/dist/json-schema/emit.js +23 -3
  189. package/dist/json-schema/freeze.d.ts +13 -2
  190. package/dist/json-schema/freeze.d.ts.map +1 -1
  191. package/dist/json-schema/freeze.js +41 -8
  192. package/dist/json-schema/index.d.ts +16 -2
  193. package/dist/json-schema/index.d.ts.map +1 -1
  194. package/dist/json-schema/index.js +23 -3
  195. package/dist/json-schema/issue.d.ts +4 -1
  196. package/dist/json-schema/issue.d.ts.map +1 -1
  197. package/dist/json-schema/issue.js +4 -1
  198. package/dist/json-schema/read.d.ts +24 -3
  199. package/dist/json-schema/read.d.ts.map +1 -1
  200. package/dist/json-schema/read.js +59 -12
  201. package/dist/json-schema/types.d.ts +45 -16
  202. package/dist/json-schema/types.d.ts.map +1 -1
  203. package/dist/json-schema/types.js +2 -0
  204. package/dist/kind/index.d.ts +40 -28
  205. package/dist/kind/index.d.ts.map +1 -1
  206. package/dist/kind/index.js +41 -13
  207. package/dist/lower/index.d.ts +6 -1
  208. package/dist/lower/index.d.ts.map +1 -1
  209. package/dist/lower/index.js +462 -46
  210. package/dist/message/index.d.ts +64 -10
  211. package/dist/message/index.d.ts.map +1 -1
  212. package/dist/message/index.js +155 -17
  213. package/dist/optimize/algebraic.d.ts +54 -0
  214. package/dist/optimize/algebraic.d.ts.map +1 -0
  215. package/dist/optimize/algebraic.js +314 -0
  216. package/dist/optimize/compact.d.ts +8 -1
  217. package/dist/optimize/compact.d.ts.map +1 -1
  218. package/dist/optimize/compact.js +13 -2
  219. package/dist/optimize/domain.d.ts +16 -0
  220. package/dist/optimize/domain.d.ts.map +1 -0
  221. package/dist/optimize/domain.js +619 -0
  222. package/dist/optimize/fold-boolean.d.ts +17 -2
  223. package/dist/optimize/fold-boolean.d.ts.map +1 -1
  224. package/dist/optimize/fold-boolean.js +59 -14
  225. package/dist/optimize/fold-common.d.ts +43 -8
  226. package/dist/optimize/fold-common.d.ts.map +1 -1
  227. package/dist/optimize/fold-common.js +37 -6
  228. package/dist/optimize/fold-constraints.d.ts +33 -0
  229. package/dist/optimize/fold-constraints.d.ts.map +1 -0
  230. package/dist/optimize/fold-constraints.js +484 -0
  231. package/dist/optimize/fold-scalar.d.ts +98 -13
  232. package/dist/optimize/fold-scalar.d.ts.map +1 -1
  233. package/dist/optimize/fold-scalar.js +98 -13
  234. package/dist/optimize/fold.d.ts +8 -1
  235. package/dist/optimize/fold.d.ts.map +1 -1
  236. package/dist/optimize/fold.js +22 -2
  237. package/dist/optimize/index.d.ts +9 -1
  238. package/dist/optimize/index.d.ts.map +1 -1
  239. package/dist/optimize/index.js +18 -3
  240. package/dist/optimize/map-node.d.ts +3 -1
  241. package/dist/optimize/map-node.d.ts.map +1 -1
  242. package/dist/optimize/map-node.js +48 -3
  243. package/dist/optimize/peephole.d.ts +16 -0
  244. package/dist/optimize/peephole.d.ts.map +1 -0
  245. package/dist/optimize/peephole.js +254 -0
  246. package/dist/optimize/remap.d.ts +2 -0
  247. package/dist/optimize/remap.d.ts.map +1 -1
  248. package/dist/optimize/remap.js +2 -0
  249. package/dist/optimize/rewrite.d.ts +13 -8
  250. package/dist/optimize/rewrite.d.ts.map +1 -1
  251. package/dist/optimize/rewrite.js +13 -8
  252. package/dist/plan/cache.d.ts +9 -3
  253. package/dist/plan/cache.d.ts.map +1 -1
  254. package/dist/plan/cache.js +34 -6
  255. package/dist/plan/index.d.ts +2 -0
  256. package/dist/plan/index.d.ts.map +1 -1
  257. package/dist/plan/index.js +2 -0
  258. package/dist/plan/predicate.d.ts +2 -0
  259. package/dist/plan/predicate.d.ts.map +1 -1
  260. package/dist/plan/predicate.js +298 -29
  261. package/dist/plan/schema-predicate.d.ts +6 -0
  262. package/dist/plan/schema-predicate.d.ts.map +1 -1
  263. package/dist/plan/schema-predicate.js +382 -19
  264. package/dist/plan/types.d.ts +2 -0
  265. package/dist/plan/types.d.ts.map +1 -1
  266. package/dist/plan/types.js +2 -0
  267. package/dist/result/index.d.ts +19 -5
  268. package/dist/result/index.d.ts.map +1 -1
  269. package/dist/result/index.js +10 -2
  270. package/dist/schema/common.d.ts +69 -6
  271. package/dist/schema/common.d.ts.map +1 -1
  272. package/dist/schema/common.js +104 -10
  273. package/dist/schema/freeze.d.ts +4 -0
  274. package/dist/schema/freeze.d.ts.map +1 -1
  275. package/dist/schema/freeze.js +40 -0
  276. package/dist/schema/index.d.ts +5 -2
  277. package/dist/schema/index.d.ts.map +1 -1
  278. package/dist/schema/index.js +4 -1
  279. package/dist/schema/lazy.d.ts +4 -0
  280. package/dist/schema/lazy.d.ts.map +1 -1
  281. package/dist/schema/lazy.js +4 -0
  282. package/dist/schema/literal.d.ts +7 -1
  283. package/dist/schema/literal.d.ts.map +1 -1
  284. package/dist/schema/literal.js +7 -1
  285. package/dist/schema/types.d.ts +109 -100
  286. package/dist/schema/types.d.ts.map +1 -1
  287. package/dist/schema/types.js +13 -2
  288. package/dist/schema/undefined.d.ts +17 -0
  289. package/dist/schema/undefined.d.ts.map +1 -0
  290. package/dist/schema/undefined.js +77 -0
  291. package/dist/schema/validate.d.ts +8 -1
  292. package/dist/schema/validate.d.ts.map +1 -1
  293. package/dist/schema/validate.js +255 -57
  294. package/docs/api.md +128 -8
  295. package/docs/assets/benchmark-headline.svg +163 -0
  296. package/docs/engine-notes.md +62 -15
  297. package/docs/index.html +1340 -702
  298. package/docs/ko/api.md +375 -0
  299. package/docs/ko/engine-notes.md +156 -0
  300. package/docs/ko/readme.md +378 -0
  301. package/package.json +66 -65
@@ -1,9 +1,12 @@
1
1
  /**
2
2
  * @file predicate.ts
3
3
  * @brief Sea-of-Nodes predicate executor.
4
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
5
+ * preserving interpreter parity.
4
6
  */
5
- import { NodeTag, SchemaTag } from "../kind/index.js";
6
- import { resolveLazySchema } from "../schema/index.js";
7
+ import { ArrayCheckTag, NodeTag, ObjectModeTag, PresenceTag, SchemaTag } from "../kind/index.js";
8
+ import { resolveLazySchema, schemaCanAcceptUndefined } from "../schema/index.js";
9
+ import { isArrayIndexKey } from "../evaluate/shared.js";
7
10
  import { enterValidation, leaveValidation, makeValidationState } from "../evaluate/state.js";
8
11
  import { makeValidationPlan, schemaRequiresTracking } from "./cache.js";
9
12
  import { executeSchemaKernel } from "./schema-predicate.js";
@@ -49,6 +52,8 @@ export function executeGraphPredicate(graph, value, state) {
49
52
  }
50
53
  /**
51
54
  * @brief execute schema predicate inner.
55
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
56
+ * preserving interpreter parity.
52
57
  */
53
58
  function executeSchemaPredicateInner(schema, value, state) {
54
59
  switch (schema.tag) {
@@ -65,6 +70,8 @@ function executeSchemaPredicateInner(schema, value, state) {
65
70
  }
66
71
  /**
67
72
  * @brief evaluate node.
73
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
74
+ * preserving interpreter parity.
68
75
  */
69
76
  function evaluateNode(graph, id, input, values, seen, epoch, state) {
70
77
  if (seen[id] === epoch) {
@@ -80,6 +87,8 @@ function evaluateNode(graph, id, input, values, seen, epoch, state) {
80
87
  }
81
88
  /**
82
89
  * @brief evaluate graph node.
90
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
91
+ * preserving interpreter parity.
83
92
  */
84
93
  function evaluateGraphNode(graph, node, input, values, seen, epoch, state) {
85
94
  switch (node.tag) {
@@ -132,13 +141,19 @@ function evaluateGraphNode(graph, node, input, values, seen, epoch, state) {
132
141
  case NodeTag.StrictKeys:
133
142
  return testStrictKeys(evaluateNode(graph, node.object, input, values, seen, epoch, state), node.keys);
134
143
  case NodeTag.ArrayEvery:
135
- return testArrayEvery(evaluateNode(graph, node.value, input, values, seen, epoch, state), node.item, state);
144
+ return testArrayEvery(evaluateNode(graph, node.value, input, values, seen, epoch, state), node.item, node.checks, node.itemGraph, state);
136
145
  case NodeTag.TupleItems:
137
- return testTupleItems(evaluateNode(graph, node.value, input, values, seen, epoch, state), node.items, state);
146
+ return testTupleItems(evaluateNode(graph, node.value, input, values, seen, epoch, state), node.itemGraphs, state);
138
147
  case NodeTag.RecordEvery:
139
- return testRecordEvery(evaluateNode(graph, node.value, input, values, seen, epoch, state), node.item, state);
148
+ return testRecordEvery(evaluateNode(graph, node.value, input, values, seen, epoch, state), node.itemGraph, state);
140
149
  case NodeTag.DiscriminantDispatch:
141
- return testDiscriminantDispatch(evaluateNode(graph, node.value, input, values, seen, epoch, state), node.key, node.schemas, node.lookup, state);
150
+ return testDiscriminantDispatch(evaluateNode(graph, node.value, input, values, seen, epoch, state), node.key, node.graphs, node.lookup, state);
151
+ case NodeTag.ObjectShape:
152
+ return testObjectShape(evaluateNode(graph, node.value, input, values, seen, epoch, state), node.entries, node.keys, node.mode, node.allRequired, state);
153
+ case NodeTag.UnionDispatch:
154
+ return testUnionDispatch(evaluateNode(graph, node.value, input, values, seen, epoch, state), node.graphs, node.masks, state);
155
+ case NodeTag.PrimitiveUnion:
156
+ return testUnionDispatch(evaluateNode(graph, node.value, input, values, seen, epoch, state), node.graphs, node.masks, state);
142
157
  case NodeTag.SchemaCheck:
143
158
  return executeSchemaPredicateWithState(node.schema, evaluateNode(graph, node.value, input, values, seen, epoch, state), state);
144
159
  case NodeTag.And:
@@ -151,6 +166,8 @@ function evaluateGraphNode(graph, node, input, values, seen, epoch, state) {
151
166
  }
152
167
  /**
153
168
  * @brief evaluate and.
169
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
170
+ * preserving interpreter parity.
154
171
  */
155
172
  function evaluateAnd(graph, ids, input, values, seen, epoch, state) {
156
173
  for (let index = 0; index < ids.length; index += 1) {
@@ -164,6 +181,8 @@ function evaluateAnd(graph, ids, input, values, seen, epoch, state) {
164
181
  }
165
182
  /**
166
183
  * @brief evaluate or.
184
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
185
+ * preserving interpreter parity.
167
186
  */
168
187
  function evaluateOr(graph, ids, input, values, seen, epoch, state) {
169
188
  for (let index = 0; index < ids.length; index += 1) {
@@ -177,15 +196,88 @@ function evaluateOr(graph, ids, input, values, seen, epoch, state) {
177
196
  }
178
197
  /**
179
198
  * @brief test array every.
199
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
200
+ * preserving interpreter parity.
201
+ * @param value Candidate value supplied to the graph executor.
202
+ * @param item Source schema retained by the ArrayEvery node.
203
+ * @param itemGraph Optimized graph used for each validated slot.
204
+ * @param state Shared recursion and cycle state.
205
+ * @returns True when every relevant slot satisfies `itemGraph`.
180
206
  */
181
- function testArrayEvery(value, item, state) {
207
+ function testArrayEvery(value, item, checks, itemGraph, state) {
182
208
  if (!Array.isArray(value)) {
183
209
  return false;
184
210
  }
211
+ if (!testArrayLengthChecks(value.length, checks)) {
212
+ return false;
213
+ }
214
+ if (schemaCanAcceptUndefined(item)) {
215
+ /*
216
+ * The graph alone cannot reveal whether holes are valid. The retained
217
+ * schema decides that question, then the graph validates only present
218
+ * own indexes.
219
+ */
220
+ return testPresentArrayIndexes(value, itemGraph, state);
221
+ }
185
222
  for (let index = 0; index < value.length; index += 1) {
186
223
  const slot = readArrayIndexValue(value, index);
187
224
  if (slot.accessor ||
188
- !executeSchemaPredicateWithState(item, slot.value, state)) {
225
+ !executeGraphPredicate(itemGraph, slot.value, state)) {
226
+ return false;
227
+ }
228
+ }
229
+ return true;
230
+ }
231
+ /**
232
+ * @brief Test array length checks attached to an ArrayEvery node.
233
+ * @param length Runtime array length.
234
+ * @param checks Normalized length check vector.
235
+ * @returns True when every bound accepts the length.
236
+ */
237
+ function testArrayLengthChecks(length, checks) {
238
+ for (let index = 0; index < checks.length; index += 1) {
239
+ const check = checks[index];
240
+ if (check === undefined) {
241
+ return false;
242
+ }
243
+ switch (check.tag) {
244
+ case ArrayCheckTag.Min:
245
+ if (length < check.value) {
246
+ return false;
247
+ }
248
+ break;
249
+ case ArrayCheckTag.Max:
250
+ if (length > check.value) {
251
+ return false;
252
+ }
253
+ break;
254
+ }
255
+ }
256
+ return true;
257
+ }
258
+ /**
259
+ * @brief test present array indexes.
260
+ * @details Holes are skipped only after the caller proved that undefined passes
261
+ * the item schema, preserving sparse-array semantics without scanning every hole.
262
+ * @param value Array already proven by the caller.
263
+ * @param itemGraph Optimized graph used for each present index.
264
+ * @param state Shared recursion and cycle state.
265
+ * @returns True when every present own index satisfies `itemGraph`.
266
+ */
267
+ function testPresentArrayIndexes(value, itemGraph, state) {
268
+ const keys = Object.getOwnPropertyNames(value);
269
+ for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
270
+ const key = keys[keyIndex];
271
+ if (key === undefined || !isArrayIndexKey(key, value.length)) {
272
+ continue;
273
+ }
274
+ /*
275
+ * Present descriptors still need the safe read path. Accessors fail
276
+ * before their getter can observe validation.
277
+ */
278
+ const slot = readArrayKeyValue(value, key);
279
+ if (slot.accessor ||
280
+ (slot.present && !executeGraphPredicate(itemGraph, slot.value, state))) {
189
281
  return false;
190
282
  }
191
283
  }
@@ -193,19 +285,21 @@ function testArrayEvery(value, item, state) {
193
285
  }
194
286
  /**
195
287
  * @brief test tuple items.
288
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
289
+ * preserving interpreter parity.
196
290
  */
197
- function testTupleItems(value, items, state) {
198
- if (!Array.isArray(value) || value.length !== items.length) {
291
+ function testTupleItems(value, itemGraphs, state) {
292
+ if (!Array.isArray(value) || value.length !== itemGraphs.length) {
199
293
  return false;
200
294
  }
201
- for (let index = 0; index < items.length; index += 1) {
202
- const item = items[index];
203
- if (item === undefined) {
295
+ for (let index = 0; index < itemGraphs.length; index += 1) {
296
+ const itemGraph = itemGraphs[index];
297
+ if (itemGraph === undefined) {
204
298
  return false;
205
299
  }
206
300
  const slot = readArrayIndexValue(value, index);
207
301
  if (slot.accessor ||
208
- !executeSchemaPredicateWithState(item, slot.value, state)) {
302
+ !executeGraphPredicate(itemGraph, slot.value, state)) {
209
303
  return false;
210
304
  }
211
305
  }
@@ -213,8 +307,10 @@ function testTupleItems(value, items, state) {
213
307
  }
214
308
  /**
215
309
  * @brief test record every.
310
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
311
+ * preserving interpreter parity.
216
312
  */
217
- function testRecordEvery(value, item, state) {
313
+ function testRecordEvery(value, itemGraph, state) {
218
314
  if (!isPlainRecord(value)) {
219
315
  return false;
220
316
  }
@@ -227,7 +323,7 @@ function testRecordEvery(value, item, state) {
227
323
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
228
324
  if (descriptor === undefined ||
229
325
  !Object.prototype.hasOwnProperty.call(descriptor, "value") ||
230
- !executeSchemaPredicateWithState(item, descriptor.value, state)) {
326
+ !executeGraphPredicate(itemGraph, descriptor.value, state)) {
231
327
  return false;
232
328
  }
233
329
  }
@@ -235,8 +331,10 @@ function testRecordEvery(value, item, state) {
235
331
  }
236
332
  /**
237
333
  * @brief test discriminant dispatch.
334
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
335
+ * preserving interpreter parity.
238
336
  */
239
- function testDiscriminantDispatch(value, key, schemas, lookup, state) {
337
+ function testDiscriminantDispatch(value, key, graphs, lookup, state) {
240
338
  if (!isPlainRecord(value)) {
241
339
  return false;
242
340
  }
@@ -252,34 +350,170 @@ function testDiscriminantDispatch(value, key, schemas, lookup, state) {
252
350
  if (index === undefined) {
253
351
  return false;
254
352
  }
255
- const schema = schemas[index];
256
- return schema !== undefined &&
257
- executeSchemaPredicateWithState(schema, value, state);
353
+ const graph = graphs[index];
354
+ return graph !== undefined && executeGraphPredicate(graph, value, state);
258
355
  }
259
356
  /**
260
- * @brief read array index value.
357
+ * @brief test object shape.
358
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
359
+ * preserving interpreter parity.
360
+ */
361
+ function testObjectShape(value, entries, keys, mode, allRequired, state) {
362
+ if (!isPlainRecord(value)) {
363
+ return false;
364
+ }
365
+ for (let index = 0; index < entries.length; index += 1) {
366
+ const entry = entries[index];
367
+ if (entry === undefined) {
368
+ return false;
369
+ }
370
+ const descriptor = Object.getOwnPropertyDescriptor(value, entry.key);
371
+ if (descriptor === undefined) {
372
+ if (entry.presence === PresenceTag.Optional &&
373
+ !Object.prototype.hasOwnProperty.call(value, entry.key)) {
374
+ continue;
375
+ }
376
+ return false;
377
+ }
378
+ if (!Object.prototype.hasOwnProperty.call(descriptor, "value") ||
379
+ !executeGraphPredicate(entry.graph, descriptor.value, state)) {
380
+ return false;
381
+ }
382
+ }
383
+ if (mode !== ObjectModeTag.Strict) {
384
+ return true;
385
+ }
386
+ if (allRequired) {
387
+ return Object.getOwnPropertyNames(value).length === entries.length &&
388
+ Object.getOwnPropertySymbols(value).length === 0;
389
+ }
390
+ const present = Reflect.ownKeys(value);
391
+ for (let index = 0; index < present.length; index += 1) {
392
+ const key = present[index];
393
+ if (typeof key !== "string" || !keys.includes(key)) {
394
+ return false;
395
+ }
396
+ }
397
+ return true;
398
+ }
399
+ /**
400
+ * @brief union mask.
401
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
402
+ * preserving interpreter parity.
403
+ */
404
+ const UnionMask = {
405
+ String: 1 << 0,
406
+ Number: 1 << 1,
407
+ Boolean: 1 << 2,
408
+ BigInt: 1 << 3,
409
+ Symbol: 1 << 4,
410
+ Undefined: 1 << 5,
411
+ Null: 1 << 6,
412
+ Array: 1 << 7,
413
+ Object: 1 << 8,
414
+ Function: 1 << 9,
415
+ Any: (1 << 10) - 1
416
+ };
417
+ /**
418
+ * @brief test union dispatch.
419
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
420
+ * preserving interpreter parity.
421
+ */
422
+ function testUnionDispatch(value, graphs, masks, state) {
423
+ const valueMask = valueUnionMask(value);
424
+ for (let index = 0; index < graphs.length; index += 1) {
425
+ const graph = graphs[index];
426
+ const mask = masks[index];
427
+ if (graph !== undefined &&
428
+ mask !== undefined &&
429
+ (mask & valueMask) !== 0 &&
430
+ executeGraphPredicate(graph, value, state)) {
431
+ return true;
432
+ }
433
+ }
434
+ return false;
435
+ }
436
+ /**
437
+ * @brief value union mask.
438
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
439
+ * preserving interpreter parity.
440
+ */
441
+ function valueUnionMask(value) {
442
+ if (value === null) {
443
+ return UnionMask.Null;
444
+ }
445
+ if (Array.isArray(value)) {
446
+ return UnionMask.Array;
447
+ }
448
+ switch (typeof value) {
449
+ case "string":
450
+ return UnionMask.String;
451
+ case "number":
452
+ return UnionMask.Number;
453
+ case "boolean":
454
+ return UnionMask.Boolean;
455
+ case "bigint":
456
+ return UnionMask.BigInt;
457
+ case "symbol":
458
+ return UnionMask.Symbol;
459
+ case "undefined":
460
+ return UnionMask.Undefined;
461
+ case "object":
462
+ return UnionMask.Object;
463
+ case "function":
464
+ return UnionMask.Function;
465
+ default:
466
+ return UnionMask.Any;
467
+ }
468
+ }
469
+ /**
470
+ * @brief Read one array index for graph predicate execution.
471
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
472
+ * preserving interpreter parity.
473
+ * @param value Array being inspected.
474
+ * @param index Numeric index.
475
+ * @returns Descriptor-derived slot record including accessor status.
261
476
  */
262
477
  function readArrayIndexValue(value, index) {
263
- const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
478
+ return readArrayKeyValue(value, String(index));
479
+ }
480
+ /**
481
+ * @brief Read one canonical array index key without invoking accessors.
482
+ * @param value Array being inspected.
483
+ * @param key Canonical array index key.
484
+ * @returns Slot record distinguishing holes, data slots, and accessor slots.
485
+ * @details Graph predicates must preserve safe-mode behavior, so an accessor is
486
+ * reported as present but unreadable instead of being invoked.
487
+ */
488
+ function readArrayKeyValue(value, key) {
489
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
264
490
  if (descriptor === undefined) {
265
491
  return {
266
492
  accessor: false,
493
+ present: false,
267
494
  value: undefined
268
495
  };
269
496
  }
270
497
  if (!Object.prototype.hasOwnProperty.call(descriptor, "value")) {
271
498
  return {
272
499
  accessor: true,
500
+ present: true,
273
501
  value: undefined
274
502
  };
275
503
  }
276
504
  return {
277
505
  accessor: false,
506
+ present: true,
278
507
  value: descriptor.value
279
508
  };
280
509
  }
281
510
  /**
282
- * @brief read own data value.
511
+ * @brief Read one own data property from an object or function host.
512
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
513
+ * preserving interpreter parity.
514
+ * @param value Candidate property host.
515
+ * @param key Property key to inspect.
516
+ * @returns Stored value, or undefined when absent or accessor-backed.
283
517
  */
284
518
  function readOwnDataValue(value, key) {
285
519
  if (!isPropertyHost(value)) {
@@ -293,14 +527,24 @@ function readOwnDataValue(value, key) {
293
527
  return descriptor.value;
294
528
  }
295
529
  /**
296
- * @brief has own property.
530
+ * @brief Test whether a value owns a property without reading it.
531
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
532
+ * preserving interpreter parity.
533
+ * @param value Candidate property host.
534
+ * @param key Property key to inspect.
535
+ * @returns True when the key exists directly on the value.
297
536
  */
298
537
  function hasOwnProperty(value, key) {
299
538
  return isPropertyHost(value) &&
300
539
  Object.prototype.hasOwnProperty.call(value, key);
301
540
  }
302
541
  /**
303
- * @brief has own data property.
542
+ * @brief Test whether a value owns a stable data property.
543
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
544
+ * preserving interpreter parity.
545
+ * @param value Candidate property host.
546
+ * @param key Property key to inspect.
547
+ * @returns True when the key is present as a data descriptor.
304
548
  */
305
549
  function hasOwnDataProperty(value, key) {
306
550
  if (!isPropertyHost(value)) {
@@ -312,6 +556,8 @@ function hasOwnDataProperty(value, key) {
312
556
  }
313
557
  /**
314
558
  * @brief test strict keys.
559
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
560
+ * preserving interpreter parity.
315
561
  */
316
562
  function testStrictKeys(value, keys) {
317
563
  if (!isPlainRecord(value)) {
@@ -328,6 +574,8 @@ function testStrictKeys(value, keys) {
328
574
  }
329
575
  /**
330
576
  * @brief compare number.
577
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
578
+ * preserving interpreter parity.
331
579
  */
332
580
  function compareNumber(left, right, gte) {
333
581
  if (typeof left !== "number" || typeof right !== "number") {
@@ -337,6 +585,8 @@ function compareNumber(left, right, gte) {
337
585
  }
338
586
  /**
339
587
  * @brief test string bound.
588
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
589
+ * preserving interpreter parity.
340
590
  */
341
591
  function testStringBound(value, bound, min) {
342
592
  if (typeof value !== "string") {
@@ -346,6 +596,8 @@ function testStringBound(value, bound, min) {
346
596
  }
347
597
  /**
348
598
  * @brief test regex.
599
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
600
+ * preserving interpreter parity.
349
601
  */
350
602
  function testRegex(value, regex) {
351
603
  if (typeof value !== "string") {
@@ -357,25 +609,39 @@ function testRegex(value, regex) {
357
609
  return result;
358
610
  }
359
611
  /**
360
- * @brief is finite number.
612
+ * @brief Test the numeric domain accepted by TypeSea number schemas.
613
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
614
+ * preserving interpreter parity.
615
+ * @param value Candidate runtime value.
616
+ * @returns True for finite JavaScript numbers.
361
617
  */
362
618
  function isFiniteNumber(value) {
363
619
  return typeof value === "number" && Number.isFinite(value);
364
620
  }
365
621
  /**
366
- * @brief is plain record.
622
+ * @brief Test whether a value can satisfy object-like schema nodes.
623
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
624
+ * preserving interpreter parity.
625
+ * @param value Candidate runtime value.
626
+ * @returns True for non-null, non-array objects.
367
627
  */
368
628
  function isPlainRecord(value) {
369
629
  return typeof value === "object" && value !== null && !Array.isArray(value);
370
630
  }
371
631
  /**
372
- * @brief is property host.
632
+ * @brief Test whether descriptor APIs can inspect the value.
633
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
634
+ * preserving interpreter parity.
635
+ * @param value Candidate runtime value.
636
+ * @returns True for objects and functions.
373
637
  */
374
638
  function isPropertyHost(value) {
375
639
  return (typeof value === "object" && value !== null) || typeof value === "function";
376
640
  }
377
641
  /**
378
642
  * @brief acquire graph frame.
643
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
644
+ * preserving interpreter parity.
379
645
  */
380
646
  function acquireGraphFrame(state, nodeCount) {
381
647
  const index = state.graphDepth;
@@ -403,12 +669,15 @@ function acquireGraphFrame(state, nodeCount) {
403
669
  }
404
670
  /**
405
671
  * @brief release graph frame.
672
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
673
+ * preserving interpreter parity.
406
674
  */
407
675
  function releaseGraphFrame(state) {
408
676
  state.graphDepth -= 1;
409
677
  }
410
678
  /**
411
- * @brief is strict true.
679
+ * @brief Check strict true.
680
+ * @details This helper keeps a local invariant explicit at the module boundary.
412
681
  */
413
682
  function isStrictTrue(value) {
414
683
  return value === true;
@@ -1,15 +1,21 @@
1
1
  /**
2
2
  * @file schema-predicate.ts
3
3
  * @brief Schema-specialized predicate kernels for validation plans.
4
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
5
+ * preserving interpreter parity.
4
6
  */
5
7
  import { type Schema } from "../schema/index.js";
6
8
  import type { ValidationState } from "../evaluate/state.js";
7
9
  /**
8
10
  * @brief child predicate runner.
11
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
12
+ * preserving interpreter parity.
9
13
  */
10
14
  export type ChildPredicateRunner = (schema: Schema, value: unknown, state: ValidationState) => boolean;
11
15
  /**
12
16
  * @brief execute schema kernel.
17
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
18
+ * preserving interpreter parity.
13
19
  */
14
20
  export declare function executeSchemaKernel(schema: Schema, value: unknown, state: ValidationState, runChild: ChildPredicateRunner): boolean;
15
21
  //# sourceMappingURL=schema-predicate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema-predicate.d.ts","sourceRoot":"","sources":["../../src/plan/schema-predicate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAIL,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAS5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CACjC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,eAAe,KACnB,OAAO,CAAC;AAEb;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,oBAAoB,GAC7B,OAAO,CAoDT"}
1
+ {"version":3,"file":"schema-predicate.d.ts","sourceRoot":"","sources":["../../src/plan/schema-predicate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,EAYH,KAAK,MAAM,EACd,MAAM,oBAAoB,CAAC;AAa5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAC/B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,eAAe,KACrB,OAAO,CAAC;AAEb;;;;GAIG;AACH,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,oBAAoB,GAC/B,OAAO,CA8DT"}