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,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 { 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.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,58 @@ 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, itemGraph, state) {
182
208
  if (!Array.isArray(value)) {
183
209
  return false;
184
210
  }
211
+ if (schemaCanAcceptUndefined(item)) {
212
+ /*
213
+ * The graph alone cannot reveal whether holes are valid. The retained
214
+ * schema decides that question, then the graph validates only present
215
+ * own indexes.
216
+ */
217
+ return testPresentArrayIndexes(value, itemGraph, state);
218
+ }
185
219
  for (let index = 0; index < value.length; index += 1) {
186
220
  const slot = readArrayIndexValue(value, index);
187
221
  if (slot.accessor ||
188
- !executeSchemaPredicateWithState(item, slot.value, state)) {
222
+ !executeGraphPredicate(itemGraph, slot.value, state)) {
223
+ return false;
224
+ }
225
+ }
226
+ return true;
227
+ }
228
+ /**
229
+ * @brief test present array indexes.
230
+ * @details Holes are skipped only after the caller proved that undefined passes
231
+ * the item schema, preserving sparse-array semantics without scanning every hole.
232
+ * @param value Array already proven by the caller.
233
+ * @param itemGraph Optimized graph used for each present index.
234
+ * @param state Shared recursion and cycle state.
235
+ * @returns True when every present own index satisfies `itemGraph`.
236
+ */
237
+ function testPresentArrayIndexes(value, itemGraph, state) {
238
+ const keys = Object.getOwnPropertyNames(value);
239
+ for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
240
+ const key = keys[keyIndex];
241
+ if (key === undefined || !isArrayIndexKey(key, value.length)) {
242
+ continue;
243
+ }
244
+ /*
245
+ * Present descriptors still need the safe read path. Accessors fail
246
+ * before their getter can observe validation.
247
+ */
248
+ const slot = readArrayKeyValue(value, key);
249
+ if (slot.accessor ||
250
+ (slot.present && !executeGraphPredicate(itemGraph, slot.value, state))) {
189
251
  return false;
190
252
  }
191
253
  }
@@ -193,19 +255,21 @@ function testArrayEvery(value, item, state) {
193
255
  }
194
256
  /**
195
257
  * @brief test tuple items.
258
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
259
+ * preserving interpreter parity.
196
260
  */
197
- function testTupleItems(value, items, state) {
198
- if (!Array.isArray(value) || value.length !== items.length) {
261
+ function testTupleItems(value, itemGraphs, state) {
262
+ if (!Array.isArray(value) || value.length !== itemGraphs.length) {
199
263
  return false;
200
264
  }
201
- for (let index = 0; index < items.length; index += 1) {
202
- const item = items[index];
203
- if (item === undefined) {
265
+ for (let index = 0; index < itemGraphs.length; index += 1) {
266
+ const itemGraph = itemGraphs[index];
267
+ if (itemGraph === undefined) {
204
268
  return false;
205
269
  }
206
270
  const slot = readArrayIndexValue(value, index);
207
271
  if (slot.accessor ||
208
- !executeSchemaPredicateWithState(item, slot.value, state)) {
272
+ !executeGraphPredicate(itemGraph, slot.value, state)) {
209
273
  return false;
210
274
  }
211
275
  }
@@ -213,8 +277,10 @@ function testTupleItems(value, items, state) {
213
277
  }
214
278
  /**
215
279
  * @brief test record every.
280
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
281
+ * preserving interpreter parity.
216
282
  */
217
- function testRecordEvery(value, item, state) {
283
+ function testRecordEvery(value, itemGraph, state) {
218
284
  if (!isPlainRecord(value)) {
219
285
  return false;
220
286
  }
@@ -227,7 +293,7 @@ function testRecordEvery(value, item, state) {
227
293
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
228
294
  if (descriptor === undefined ||
229
295
  !Object.prototype.hasOwnProperty.call(descriptor, "value") ||
230
- !executeSchemaPredicateWithState(item, descriptor.value, state)) {
296
+ !executeGraphPredicate(itemGraph, descriptor.value, state)) {
231
297
  return false;
232
298
  }
233
299
  }
@@ -235,8 +301,10 @@ function testRecordEvery(value, item, state) {
235
301
  }
236
302
  /**
237
303
  * @brief test discriminant dispatch.
304
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
305
+ * preserving interpreter parity.
238
306
  */
239
- function testDiscriminantDispatch(value, key, schemas, lookup, state) {
307
+ function testDiscriminantDispatch(value, key, graphs, lookup, state) {
240
308
  if (!isPlainRecord(value)) {
241
309
  return false;
242
310
  }
@@ -252,34 +320,170 @@ function testDiscriminantDispatch(value, key, schemas, lookup, state) {
252
320
  if (index === undefined) {
253
321
  return false;
254
322
  }
255
- const schema = schemas[index];
256
- return schema !== undefined &&
257
- executeSchemaPredicateWithState(schema, value, state);
323
+ const graph = graphs[index];
324
+ return graph !== undefined && executeGraphPredicate(graph, value, state);
258
325
  }
259
326
  /**
260
- * @brief read array index value.
327
+ * @brief test object shape.
328
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
329
+ * preserving interpreter parity.
330
+ */
331
+ function testObjectShape(value, entries, keys, mode, allRequired, state) {
332
+ if (!isPlainRecord(value)) {
333
+ return false;
334
+ }
335
+ for (let index = 0; index < entries.length; index += 1) {
336
+ const entry = entries[index];
337
+ if (entry === undefined) {
338
+ return false;
339
+ }
340
+ const descriptor = Object.getOwnPropertyDescriptor(value, entry.key);
341
+ if (descriptor === undefined) {
342
+ if (entry.presence === PresenceTag.Optional &&
343
+ !Object.prototype.hasOwnProperty.call(value, entry.key)) {
344
+ continue;
345
+ }
346
+ return false;
347
+ }
348
+ if (!Object.prototype.hasOwnProperty.call(descriptor, "value") ||
349
+ !executeGraphPredicate(entry.graph, descriptor.value, state)) {
350
+ return false;
351
+ }
352
+ }
353
+ if (mode !== ObjectModeTag.Strict) {
354
+ return true;
355
+ }
356
+ if (allRequired) {
357
+ return Object.getOwnPropertyNames(value).length === entries.length &&
358
+ Object.getOwnPropertySymbols(value).length === 0;
359
+ }
360
+ const present = Reflect.ownKeys(value);
361
+ for (let index = 0; index < present.length; index += 1) {
362
+ const key = present[index];
363
+ if (typeof key !== "string" || !keys.includes(key)) {
364
+ return false;
365
+ }
366
+ }
367
+ return true;
368
+ }
369
+ /**
370
+ * @brief union mask.
371
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
372
+ * preserving interpreter parity.
373
+ */
374
+ const UnionMask = {
375
+ String: 1 << 0,
376
+ Number: 1 << 1,
377
+ Boolean: 1 << 2,
378
+ BigInt: 1 << 3,
379
+ Symbol: 1 << 4,
380
+ Undefined: 1 << 5,
381
+ Null: 1 << 6,
382
+ Array: 1 << 7,
383
+ Object: 1 << 8,
384
+ Function: 1 << 9,
385
+ Any: (1 << 10) - 1
386
+ };
387
+ /**
388
+ * @brief test union dispatch.
389
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
390
+ * preserving interpreter parity.
391
+ */
392
+ function testUnionDispatch(value, graphs, masks, state) {
393
+ const valueMask = valueUnionMask(value);
394
+ for (let index = 0; index < graphs.length; index += 1) {
395
+ const graph = graphs[index];
396
+ const mask = masks[index];
397
+ if (graph !== undefined &&
398
+ mask !== undefined &&
399
+ (mask & valueMask) !== 0 &&
400
+ executeGraphPredicate(graph, value, state)) {
401
+ return true;
402
+ }
403
+ }
404
+ return false;
405
+ }
406
+ /**
407
+ * @brief value union mask.
408
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
409
+ * preserving interpreter parity.
410
+ */
411
+ function valueUnionMask(value) {
412
+ if (value === null) {
413
+ return UnionMask.Null;
414
+ }
415
+ if (Array.isArray(value)) {
416
+ return UnionMask.Array;
417
+ }
418
+ switch (typeof value) {
419
+ case "string":
420
+ return UnionMask.String;
421
+ case "number":
422
+ return UnionMask.Number;
423
+ case "boolean":
424
+ return UnionMask.Boolean;
425
+ case "bigint":
426
+ return UnionMask.BigInt;
427
+ case "symbol":
428
+ return UnionMask.Symbol;
429
+ case "undefined":
430
+ return UnionMask.Undefined;
431
+ case "object":
432
+ return UnionMask.Object;
433
+ case "function":
434
+ return UnionMask.Function;
435
+ default:
436
+ return UnionMask.Any;
437
+ }
438
+ }
439
+ /**
440
+ * @brief Read one array index for graph predicate execution.
441
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
442
+ * preserving interpreter parity.
443
+ * @param value Array being inspected.
444
+ * @param index Numeric index.
445
+ * @returns Descriptor-derived slot record including accessor status.
261
446
  */
262
447
  function readArrayIndexValue(value, index) {
263
- const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
448
+ return readArrayKeyValue(value, String(index));
449
+ }
450
+ /**
451
+ * @brief Read one canonical array index key without invoking accessors.
452
+ * @param value Array being inspected.
453
+ * @param key Canonical array index key.
454
+ * @returns Slot record distinguishing holes, data slots, and accessor slots.
455
+ * @details Graph predicates must preserve safe-mode behavior, so an accessor is
456
+ * reported as present but unreadable instead of being invoked.
457
+ */
458
+ function readArrayKeyValue(value, key) {
459
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
264
460
  if (descriptor === undefined) {
265
461
  return {
266
462
  accessor: false,
463
+ present: false,
267
464
  value: undefined
268
465
  };
269
466
  }
270
467
  if (!Object.prototype.hasOwnProperty.call(descriptor, "value")) {
271
468
  return {
272
469
  accessor: true,
470
+ present: true,
273
471
  value: undefined
274
472
  };
275
473
  }
276
474
  return {
277
475
  accessor: false,
476
+ present: true,
278
477
  value: descriptor.value
279
478
  };
280
479
  }
281
480
  /**
282
- * @brief read own data value.
481
+ * @brief Read one own data property from an object or function host.
482
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
483
+ * preserving interpreter parity.
484
+ * @param value Candidate property host.
485
+ * @param key Property key to inspect.
486
+ * @returns Stored value, or undefined when absent or accessor-backed.
283
487
  */
284
488
  function readOwnDataValue(value, key) {
285
489
  if (!isPropertyHost(value)) {
@@ -293,14 +497,24 @@ function readOwnDataValue(value, key) {
293
497
  return descriptor.value;
294
498
  }
295
499
  /**
296
- * @brief has own property.
500
+ * @brief Test whether a value owns a property without reading it.
501
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
502
+ * preserving interpreter parity.
503
+ * @param value Candidate property host.
504
+ * @param key Property key to inspect.
505
+ * @returns True when the key exists directly on the value.
297
506
  */
298
507
  function hasOwnProperty(value, key) {
299
508
  return isPropertyHost(value) &&
300
509
  Object.prototype.hasOwnProperty.call(value, key);
301
510
  }
302
511
  /**
303
- * @brief has own data property.
512
+ * @brief Test whether a value owns a stable data property.
513
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
514
+ * preserving interpreter parity.
515
+ * @param value Candidate property host.
516
+ * @param key Property key to inspect.
517
+ * @returns True when the key is present as a data descriptor.
304
518
  */
305
519
  function hasOwnDataProperty(value, key) {
306
520
  if (!isPropertyHost(value)) {
@@ -312,6 +526,8 @@ function hasOwnDataProperty(value, key) {
312
526
  }
313
527
  /**
314
528
  * @brief test strict keys.
529
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
530
+ * preserving interpreter parity.
315
531
  */
316
532
  function testStrictKeys(value, keys) {
317
533
  if (!isPlainRecord(value)) {
@@ -328,6 +544,8 @@ function testStrictKeys(value, keys) {
328
544
  }
329
545
  /**
330
546
  * @brief compare number.
547
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
548
+ * preserving interpreter parity.
331
549
  */
332
550
  function compareNumber(left, right, gte) {
333
551
  if (typeof left !== "number" || typeof right !== "number") {
@@ -337,6 +555,8 @@ function compareNumber(left, right, gte) {
337
555
  }
338
556
  /**
339
557
  * @brief test string bound.
558
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
559
+ * preserving interpreter parity.
340
560
  */
341
561
  function testStringBound(value, bound, min) {
342
562
  if (typeof value !== "string") {
@@ -346,6 +566,8 @@ function testStringBound(value, bound, min) {
346
566
  }
347
567
  /**
348
568
  * @brief test regex.
569
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
570
+ * preserving interpreter parity.
349
571
  */
350
572
  function testRegex(value, regex) {
351
573
  if (typeof value !== "string") {
@@ -357,25 +579,39 @@ function testRegex(value, regex) {
357
579
  return result;
358
580
  }
359
581
  /**
360
- * @brief is finite number.
582
+ * @brief Test the numeric domain accepted by TypeSea number schemas.
583
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
584
+ * preserving interpreter parity.
585
+ * @param value Candidate runtime value.
586
+ * @returns True for finite JavaScript numbers.
361
587
  */
362
588
  function isFiniteNumber(value) {
363
589
  return typeof value === "number" && Number.isFinite(value);
364
590
  }
365
591
  /**
366
- * @brief is plain record.
592
+ * @brief Test whether a value can satisfy object-like schema nodes.
593
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
594
+ * preserving interpreter parity.
595
+ * @param value Candidate runtime value.
596
+ * @returns True for non-null, non-array objects.
367
597
  */
368
598
  function isPlainRecord(value) {
369
599
  return typeof value === "object" && value !== null && !Array.isArray(value);
370
600
  }
371
601
  /**
372
- * @brief is property host.
602
+ * @brief Test whether descriptor APIs can inspect the value.
603
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
604
+ * preserving interpreter parity.
605
+ * @param value Candidate runtime value.
606
+ * @returns True for objects and functions.
373
607
  */
374
608
  function isPropertyHost(value) {
375
609
  return (typeof value === "object" && value !== null) || typeof value === "function";
376
610
  }
377
611
  /**
378
612
  * @brief acquire graph frame.
613
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
614
+ * preserving interpreter parity.
379
615
  */
380
616
  function acquireGraphFrame(state, nodeCount) {
381
617
  const index = state.graphDepth;
@@ -403,12 +639,15 @@ function acquireGraphFrame(state, nodeCount) {
403
639
  }
404
640
  /**
405
641
  * @brief release graph frame.
642
+ * @details Plan helpers keep schema-specialized execution aligned with optimized IR while
643
+ * preserving interpreter parity.
406
644
  */
407
645
  function releaseGraphFrame(state) {
408
646
  state.graphDepth -= 1;
409
647
  }
410
648
  /**
411
- * @brief is strict true.
649
+ * @brief Check strict true.
650
+ * @details This helper keeps a local invariant explicit at the module boundary.
412
651
  */
413
652
  function isStrictTrue(value) {
414
653
  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;AASH,OAAO,EAKH,KAAK,MAAM,EACd,MAAM,oBAAoB,CAAC;AAU5B,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,CAoDT"}