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,29 +1,26 @@
1
1
  /**
2
2
  * @file builder.ts
3
3
  * @brief Dense graph builder with structural node interning.
4
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
5
+ * compiler, or public introspection boundaries.
4
6
  */
5
- import { NodeTag } from "../kind/index.js";
7
+ import { NodeTag, PresenceTag } from "../kind/index.js";
6
8
  import { freezeGraph } from "./freeze.js";
7
9
  import { isPlainRegExp } from "./regexp.js";
8
10
  /**
9
- * @brief graph builder.
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 Dense Sea-of-Nodes graph construction arena.
12
+ * @details The builder interns pure scalar nodes so later optimization passes see
13
+ * one canonical id for equivalent predicates. Composite nodes are deliberately
14
+ * appended instead: their embedded child graphs and schema payloads are owned
15
+ * values, and pointer-level interning would make aliasing harder to audit.
12
16
  */
13
17
  export class GraphBuilder {
14
18
  nodes;
15
19
  hash;
16
- /**
17
- * @brief constructor.
18
- * @post The receiver is initialized according to the class invariant before it can be observed.
19
- */
20
20
  constructor() {
21
21
  this.nodes = [];
22
22
  this.hash = new Map();
23
23
  }
24
- /**
25
- * @brief start.
26
- */
27
24
  start() {
28
25
  return this.intern("start", (id) => ({
29
26
  id,
@@ -31,9 +28,6 @@ export class GraphBuilder {
31
28
  deps: []
32
29
  }));
33
30
  }
34
- /**
35
- * @brief param.
36
- */
37
31
  param(name) {
38
32
  return this.intern(`param:${name}`, (id) => ({
39
33
  id,
@@ -42,10 +36,8 @@ export class GraphBuilder {
42
36
  name
43
37
  }));
44
38
  }
45
- /**
46
- * @brief constant.
47
- */
48
39
  constant(value) {
40
+ /* Symbols are identity values; interning them by text would be unsound. */
49
41
  if (typeof value === "symbol") {
50
42
  return this.push((id) => ({
51
43
  id,
@@ -62,9 +54,6 @@ export class GraphBuilder {
62
54
  value
63
55
  }));
64
56
  }
65
- /**
66
- * @brief get prop.
67
- */
68
57
  getProp(object, key) {
69
58
  const hashKey = `getProp:${String(object)}:${key}`;
70
59
  return this.intern(hashKey, (id) => ({
@@ -75,75 +64,39 @@ export class GraphBuilder {
75
64
  key
76
65
  }));
77
66
  }
78
- /**
79
- * @brief is string.
80
- */
81
67
  isString(value) {
82
68
  return this.unary(NodeTag.IsString, value);
83
69
  }
84
- /**
85
- * @brief is number.
86
- */
87
70
  isNumber(value) {
88
71
  return this.unary(NodeTag.IsNumber, value);
89
72
  }
90
- /**
91
- * @brief is boolean.
92
- */
93
73
  isBoolean(value) {
94
74
  return this.unary(NodeTag.IsBoolean, value);
95
75
  }
96
- /**
97
- * @brief is big int.
98
- */
99
76
  isBigInt(value) {
100
77
  return this.unary(NodeTag.IsBigInt, value);
101
78
  }
102
- /**
103
- * @brief is symbol.
104
- */
105
79
  isSymbol(value) {
106
80
  return this.unary(NodeTag.IsSymbol, value);
107
81
  }
108
- /**
109
- * @brief is object.
110
- */
111
82
  isObject(value) {
112
83
  return this.unary(NodeTag.IsObject, value);
113
84
  }
114
- /**
115
- * @brief is array.
116
- */
117
85
  isArray(value) {
118
86
  return this.unary(NodeTag.IsArray, value);
119
87
  }
120
- /**
121
- * @brief is undefined.
122
- */
123
88
  isUndefined(value) {
124
89
  return this.unary(NodeTag.IsUndefined, value);
125
90
  }
126
- /**
127
- * @brief is null.
128
- */
129
91
  isNull(value) {
130
92
  return this.unary(NodeTag.IsNull, value);
131
93
  }
132
- /**
133
- * @brief is integer.
134
- */
135
94
  isInteger(value) {
136
95
  return this.unary(NodeTag.IsInteger, value);
137
96
  }
138
- /**
139
- * @brief not.
140
- */
141
97
  not(value) {
142
98
  return this.unary(NodeTag.Not, value);
143
99
  }
144
- /**
145
- * @brief equals.
146
- */
147
100
  equals(left, right) {
148
101
  const key = `eq:${String(left)}:${String(right)}`;
149
102
  return this.intern(key, (id) => ({
@@ -154,33 +107,18 @@ export class GraphBuilder {
154
107
  right
155
108
  }));
156
109
  }
157
- /**
158
- * @brief gte.
159
- */
160
110
  gte(left, right) {
161
111
  return this.numeric(NodeTag.Gte, left, right);
162
112
  }
163
- /**
164
- * @brief lte.
165
- */
166
113
  lte(left, right) {
167
114
  return this.numeric(NodeTag.Lte, left, right);
168
115
  }
169
- /**
170
- * @brief string min.
171
- */
172
116
  stringMin(value, bound) {
173
117
  return this.stringBound(NodeTag.StringMin, value, bound);
174
118
  }
175
- /**
176
- * @brief string max.
177
- */
178
119
  stringMax(value, bound) {
179
120
  return this.stringBound(NodeTag.StringMax, value, bound);
180
121
  }
181
- /**
182
- * @brief regex.
183
- */
184
122
  regex(value, regex, name) {
185
123
  if (!isPlainRegExp(regex)) {
186
124
  throw new TypeError("regex node must use a plain RegExp");
@@ -198,9 +136,6 @@ export class GraphBuilder {
198
136
  name
199
137
  }));
200
138
  }
201
- /**
202
- * @brief has own.
203
- */
204
139
  hasOwn(object, key) {
205
140
  const hashKey = `hasOwn:${String(object)}:${key}`;
206
141
  return this.intern(hashKey, (id) => ({
@@ -211,9 +146,6 @@ export class GraphBuilder {
211
146
  key
212
147
  }));
213
148
  }
214
- /**
215
- * @brief has own data.
216
- */
217
149
  hasOwnData(object, key) {
218
150
  const hashKey = `hasOwnData:${String(object)}:${key}`;
219
151
  return this.intern(hashKey, (id) => ({
@@ -224,9 +156,6 @@ export class GraphBuilder {
224
156
  key
225
157
  }));
226
158
  }
227
- /**
228
- * @brief strict keys.
229
- */
230
159
  strictKeys(object, keys) {
231
160
  const hashKey = `strictKeys:${String(object)}:${JSON.stringify(keys)}`;
232
161
  return this.intern(hashKey, (id) => ({
@@ -237,46 +166,37 @@ export class GraphBuilder {
237
166
  keys
238
167
  }));
239
168
  }
240
- /**
241
- * @brief array every.
242
- */
243
- arrayEvery(value, item) {
169
+ arrayEvery(value, item, itemGraph) {
244
170
  return this.push((id) => ({
245
171
  id,
246
172
  tag: NodeTag.ArrayEvery,
247
173
  deps: [value],
248
174
  value,
249
- item
175
+ item,
176
+ itemGraph
250
177
  }));
251
178
  }
252
- /**
253
- * @brief tuple items.
254
- */
255
- tupleItems(value, items) {
179
+ tupleItems(value, items, itemGraphs) {
256
180
  return this.push((id) => ({
257
181
  id,
258
182
  tag: NodeTag.TupleItems,
259
183
  deps: [value],
260
184
  value,
261
- items
185
+ items,
186
+ itemGraphs
262
187
  }));
263
188
  }
264
- /**
265
- * @brief record every.
266
- */
267
- recordEvery(value, item) {
189
+ recordEvery(value, item, itemGraph) {
268
190
  return this.push((id) => ({
269
191
  id,
270
192
  tag: NodeTag.RecordEvery,
271
193
  deps: [value],
272
194
  value,
273
- item
195
+ item,
196
+ itemGraph
274
197
  }));
275
198
  }
276
- /**
277
- * @brief discriminant dispatch.
278
- */
279
- discriminantDispatch(value, key, literals, schemas) {
199
+ discriminantDispatch(value, key, literals, schemas, graphs) {
280
200
  return this.push((id) => ({
281
201
  id,
282
202
  tag: NodeTag.DiscriminantDispatch,
@@ -285,12 +205,43 @@ export class GraphBuilder {
285
205
  key,
286
206
  literals,
287
207
  schemas,
208
+ graphs,
288
209
  lookup: makeDiscriminantLookup(literals)
289
210
  }));
290
211
  }
291
- /**
292
- * @brief schema check.
293
- */
212
+ objectShape(value, entries, keys, mode) {
213
+ return this.push((id) => ({
214
+ id,
215
+ tag: NodeTag.ObjectShape,
216
+ deps: [value],
217
+ value,
218
+ entries,
219
+ keys,
220
+ mode,
221
+ allRequired: objectShapeAllRequired(entries)
222
+ }));
223
+ }
224
+ unionDispatch(value, options, graphs, masks) {
225
+ return this.push((id) => ({
226
+ id,
227
+ tag: NodeTag.UnionDispatch,
228
+ deps: [value],
229
+ value,
230
+ options,
231
+ graphs,
232
+ masks
233
+ }));
234
+ }
235
+ primitiveUnion(value, graphs, masks) {
236
+ return this.push((id) => ({
237
+ id,
238
+ tag: NodeTag.PrimitiveUnion,
239
+ deps: [value],
240
+ value,
241
+ graphs,
242
+ masks
243
+ }));
244
+ }
294
245
  schemaCheck(value, schema) {
295
246
  return this.push((id) => ({
296
247
  id,
@@ -300,9 +251,6 @@ export class GraphBuilder {
300
251
  schema
301
252
  }));
302
253
  }
303
- /**
304
- * @brief and.
305
- */
306
254
  and(values) {
307
255
  const first = values[0];
308
256
  if (first === undefined) {
@@ -319,9 +267,6 @@ export class GraphBuilder {
319
267
  values
320
268
  }));
321
269
  }
322
- /**
323
- * @brief or.
324
- */
325
270
  or(values) {
326
271
  const first = values[0];
327
272
  if (first === undefined) {
@@ -338,9 +283,6 @@ export class GraphBuilder {
338
283
  values
339
284
  }));
340
285
  }
341
- /**
342
- * @brief ret.
343
- */
344
286
  ret(control, value) {
345
287
  return this.push((id) => ({
346
288
  id,
@@ -350,9 +292,6 @@ export class GraphBuilder {
350
292
  value
351
293
  }));
352
294
  }
353
- /**
354
- * @brief finish.
355
- */
356
295
  finish(entry, result) {
357
296
  return freezeGraph({
358
297
  nodes: this.nodes.slice(),
@@ -360,9 +299,6 @@ export class GraphBuilder {
360
299
  result
361
300
  });
362
301
  }
363
- /**
364
- * @brief unary.
365
- */
366
302
  unary(tag, value) {
367
303
  const key = `unary:${String(tag)}:${String(value)}`;
368
304
  return this.intern(key, (id) => ({
@@ -372,9 +308,6 @@ export class GraphBuilder {
372
308
  value
373
309
  }));
374
310
  }
375
- /**
376
- * @brief numeric.
377
- */
378
311
  numeric(tag, left, right) {
379
312
  const key = `numeric:${String(tag)}:${String(left)}:${String(right)}`;
380
313
  return this.intern(key, (id) => ({
@@ -385,9 +318,6 @@ export class GraphBuilder {
385
318
  right
386
319
  }));
387
320
  }
388
- /**
389
- * @brief string bound.
390
- */
391
321
  stringBound(tag, value, bound) {
392
322
  const key = `stringBound:${String(tag)}:${String(value)}:${String(bound)}`;
393
323
  return this.intern(key, (id) => ({
@@ -398,9 +328,6 @@ export class GraphBuilder {
398
328
  bound
399
329
  }));
400
330
  }
401
- /**
402
- * @brief intern.
403
- */
404
331
  intern(key, make) {
405
332
  const cached = this.hash.get(key);
406
333
  if (cached !== undefined) {
@@ -412,9 +339,6 @@ export class GraphBuilder {
412
339
  this.hash.set(key, id);
413
340
  return id;
414
341
  }
415
- /**
416
- * @brief push.
417
- */
418
342
  push(make) {
419
343
  const id = this.nodes.length;
420
344
  const node = make(id);
@@ -423,23 +347,38 @@ export class GraphBuilder {
423
347
  }
424
348
  }
425
349
  /**
426
- * @brief make regex intern key.
427
- * @details Encodes each string segment with its byte-length-independent character length before concatenation.
428
- * @returns Collision-resistant intern key for one regex predicate identity.
350
+ * @brief Execute object shape all required.
351
+ * @details This helper keeps a local invariant explicit at the module boundary.
352
+ */
353
+ function objectShapeAllRequired(entries) {
354
+ for (let index = 0; index < entries.length; index += 1) {
355
+ const entry = entries[index];
356
+ if (entry?.presence !== PresenceTag.Required) {
357
+ return false;
358
+ }
359
+ }
360
+ return true;
361
+ }
362
+ /**
363
+ * @brief Build an intern key without letting adjacent regex fields merge.
364
+ * @details Source, flags, and diagnostic name are all user-controlled strings;
365
+ * length prefixes keep `["ab", "c"]` distinct from `["a", "bc"]` without
366
+ * allocating wrapper tuples in the hot builder path.
429
367
  */
430
368
  function makeRegexInternKey(value, source, flags, name) {
431
369
  return `regex:${String(value)}:${lengthPrefixed(source)}${lengthPrefixed(flags)}${lengthPrefixed(name)}`;
432
370
  }
433
371
  /**
434
- * @brief length prefixed.
435
- * @details Preserves string tuple boundaries without allocating wrapper arrays or nested maps.
436
- * @returns Encoded string segment suitable for intern table keys.
372
+ * @brief Encode one string segment for a flat composite key.
373
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
374
+ * compiler, or public introspection boundaries.
437
375
  */
438
376
  function lengthPrefixed(value) {
439
377
  return `${String(value.length)}:${value};`;
440
378
  }
441
379
  /**
442
- * @brief literal key.
380
+ * @brief Execute literal key.
381
+ * @details This helper keeps a local invariant explicit at the module boundary.
443
382
  */
444
383
  function literalKey(value) {
445
384
  if (value === null) {
@@ -467,7 +406,8 @@ function literalKey(value) {
467
406
  return "undefined";
468
407
  }
469
408
  /**
470
- * @brief make discriminant lookup.
409
+ * @brief Build discriminant lookup.
410
+ * @details This helper keeps a local invariant explicit at the module boundary.
471
411
  */
472
412
  function makeDiscriminantLookup(literals) {
473
413
  const lookup = Object.create(null);
@@ -1,10 +1,14 @@
1
1
  /**
2
2
  * @file freeze.ts
3
3
  * @brief Immutable graph finalization.
4
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
5
+ * compiler, or public introspection boundaries.
4
6
  */
5
7
  import type { Graph } from "./types.js";
6
8
  /**
7
9
  * @brief freeze graph.
10
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
11
+ * compiler, or public introspection boundaries.
8
12
  */
9
13
  export declare function freezeGraph(graph: Graph): Graph;
10
14
  //# sourceMappingURL=freeze.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"freeze.d.ts","sourceRoot":"","sources":["../../src/ir/freeze.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,KAAK,EAAwB,MAAM,YAAY,CAAC;AAE9D;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAS/C"}
1
+ {"version":3,"file":"freeze.d.ts","sourceRoot":"","sources":["../../src/ir/freeze.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,KAAK,EAAwB,MAAM,YAAY,CAAC;AAE9D;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAS/C"}
package/dist/ir/freeze.js CHANGED
@@ -1,12 +1,16 @@
1
1
  /**
2
2
  * @file freeze.ts
3
3
  * @brief Immutable graph finalization.
4
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
5
+ * compiler, or public introspection boundaries.
4
6
  */
5
7
  import { NodeTag } from "../kind/index.js";
6
8
  import { freezeSchema } from "../schema/index.js";
7
9
  import { isPlainRegExp } from "./regexp.js";
8
10
  /**
9
11
  * @brief freeze graph.
12
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
13
+ * compiler, or public introspection boundaries.
10
14
  */
11
15
  export function freezeGraph(graph) {
12
16
  for (let index = 0; index < graph.nodes.length; index += 1) {
@@ -20,6 +24,8 @@ export function freezeGraph(graph) {
20
24
  }
21
25
  /**
22
26
  * @brief freeze graph node.
27
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
28
+ * compiler, or public introspection boundaries.
23
29
  */
24
30
  function freezeGraphNode(node) {
25
31
  Object.freeze(node.deps);
@@ -32,6 +38,7 @@ function freezeGraphNode(node) {
32
38
  break;
33
39
  case NodeTag.ArrayEvery:
34
40
  freezeSchema(node.item);
41
+ freezeGraph(node.itemGraph);
35
42
  break;
36
43
  case NodeTag.TupleItems:
37
44
  for (let index = 0; index < node.items.length; index += 1) {
@@ -39,11 +46,17 @@ function freezeGraphNode(node) {
39
46
  if (item !== undefined) {
40
47
  freezeSchema(item);
41
48
  }
49
+ const graph = node.itemGraphs[index];
50
+ if (graph !== undefined) {
51
+ freezeGraph(graph);
52
+ }
42
53
  }
43
54
  Object.freeze(node.items);
55
+ Object.freeze(node.itemGraphs);
44
56
  break;
45
57
  case NodeTag.RecordEvery:
46
58
  freezeSchema(node.item);
59
+ freezeGraph(node.itemGraph);
47
60
  break;
48
61
  case NodeTag.DiscriminantDispatch:
49
62
  Object.freeze(node.literals);
@@ -52,10 +65,52 @@ function freezeGraphNode(node) {
52
65
  if (schema !== undefined) {
53
66
  freezeSchema(schema);
54
67
  }
68
+ const graph = node.graphs[index];
69
+ if (graph !== undefined) {
70
+ freezeGraph(graph);
71
+ }
55
72
  }
56
73
  Object.freeze(node.schemas);
74
+ Object.freeze(node.graphs);
57
75
  Object.freeze(node.lookup);
58
76
  break;
77
+ case NodeTag.ObjectShape:
78
+ for (let index = 0; index < node.entries.length; index += 1) {
79
+ const entry = node.entries[index];
80
+ if (entry !== undefined) {
81
+ freezeSchema(entry.schema);
82
+ freezeGraph(entry.graph);
83
+ Object.freeze(entry);
84
+ }
85
+ }
86
+ Object.freeze(node.entries);
87
+ Object.freeze(node.keys);
88
+ break;
89
+ case NodeTag.UnionDispatch:
90
+ for (let index = 0; index < node.options.length; index += 1) {
91
+ const schema = node.options[index];
92
+ if (schema !== undefined) {
93
+ freezeSchema(schema);
94
+ }
95
+ const graph = node.graphs[index];
96
+ if (graph !== undefined) {
97
+ freezeGraph(graph);
98
+ }
99
+ }
100
+ Object.freeze(node.options);
101
+ Object.freeze(node.graphs);
102
+ Object.freeze(node.masks);
103
+ break;
104
+ case NodeTag.PrimitiveUnion:
105
+ for (let index = 0; index < node.graphs.length; index += 1) {
106
+ const graph = node.graphs[index];
107
+ if (graph !== undefined) {
108
+ freezeGraph(graph);
109
+ }
110
+ }
111
+ Object.freeze(node.graphs);
112
+ Object.freeze(node.masks);
113
+ break;
59
114
  case NodeTag.SchemaCheck:
60
115
  freezeSchema(node.schema);
61
116
  break;
@@ -70,6 +125,8 @@ function freezeGraphNode(node) {
70
125
  }
71
126
  /**
72
127
  * @brief freeze regex node.
128
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
129
+ * compiler, or public introspection boundaries.
73
130
  */
74
131
  function freezeRegexNode(node) {
75
132
  const regex = node.regex;
@@ -94,6 +151,8 @@ function freezeRegexNode(node) {
94
151
  }
95
152
  /**
96
153
  * @brief clone graph reg exp.
154
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
155
+ * compiler, or public introspection boundaries.
97
156
  */
98
157
  function cloneGraphRegExp(regex) {
99
158
  const cloned = new RegExp(regex.source, regex.flags);
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * @file index.ts
3
3
  * @brief Public IR module aggregation.
4
+ * @details This barrel keeps public import paths stable while implementation files remain
5
+ * split by responsibility.
4
6
  */
5
7
  export { GraphBuilder } from "./builder.js";
6
8
  export { freezeGraph } from "./freeze.js";
7
9
  export { isGraphValue } from "./validate.js";
8
- export type { ArrayEveryNode, BooleanFoldNode, ConstNode, DiscriminantDispatchLookup, DiscriminantDispatchNode, EqualsNode, GetPropNode, Graph, GraphNode, HasOwnDataNode, HasOwnNode, NodeId, NumericCompareNode, ParamNode, RecordEveryNode, RegexNode, ReturnNode, SchemaCheckNode, StartNode, StrictKeysNode, StringBoundNode, TupleItemsNode, UnaryPredicateNode } from "./types.js";
10
+ export type { ArrayEveryNode, BooleanFoldNode, ConstNode, DiscriminantDispatchLookup, DiscriminantDispatchNode, EqualsNode, GetPropNode, Graph, GraphNode, HasOwnDataNode, HasOwnNode, NodeId, ObjectShapeEntry, ObjectShapeNode, NumericCompareNode, ParamNode, PrimitiveUnionNode, RecordEveryNode, RegexNode, ReturnNode, SchemaCheckNode, StartNode, StrictKeysNode, StringBoundNode, TupleItemsNode, UnionDispatchMask, UnionDispatchNode, UnaryPredicateNode } from "./types.js";
9
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ir/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,YAAY,EACV,cAAc,EACd,eAAe,EACf,SAAS,EACT,0BAA0B,EAC1B,wBAAwB,EACxB,UAAU,EACV,WAAW,EACX,KAAK,EACL,SAAS,EACT,cAAc,EACd,UAAU,EACV,MAAM,EACN,kBAAkB,EAClB,SAAS,EACT,eAAe,EACf,SAAS,EACT,UAAU,EACV,eAAe,EACf,SAAS,EACT,cAAc,EACd,eAAe,EACf,cAAc,EACd,kBAAkB,EACnB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ir/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,YAAY,EACR,cAAc,EACd,eAAe,EACf,SAAS,EACT,0BAA0B,EAC1B,wBAAwB,EACxB,UAAU,EACV,WAAW,EACX,KAAK,EACL,SAAS,EACT,cAAc,EACd,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,UAAU,EACV,eAAe,EACf,SAAS,EACT,cAAc,EACd,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EACrB,MAAM,YAAY,CAAC"}
package/dist/ir/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file index.ts
3
3
  * @brief Public IR module aggregation.
4
+ * @details This barrel keeps public import paths stable while implementation files remain
5
+ * split by responsibility.
4
6
  */
5
7
  export { GraphBuilder } from "./builder.js";
6
8
  export { freezeGraph } from "./freeze.js";
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file regexp.ts
3
3
  * @brief RegExp shape guard for graph nodes.
4
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
5
+ * compiler, or public introspection boundaries.
4
6
  */
5
7
  export declare function isPlainRegExp(value: unknown): value is RegExp;
6
8
  //# sourceMappingURL=regexp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../src/ir/regexp.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAO7D"}
1
+ {"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../src/ir/regexp.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAO7D"}
package/dist/ir/regexp.js CHANGED
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file regexp.ts
3
3
  * @brief RegExp shape guard for graph nodes.
4
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
5
+ * compiler, or public introspection boundaries.
4
6
  */
5
7
  export function isPlainRegExp(value) {
6
8
  return value instanceof RegExp &&