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,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,38 @@ export class GraphBuilder {
237
166
  keys
238
167
  }));
239
168
  }
240
- /**
241
- * @brief array every.
242
- */
243
- arrayEvery(value, item) {
169
+ arrayEvery(value, item, checks, 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
+ checks,
177
+ itemGraph
250
178
  }));
251
179
  }
252
- /**
253
- * @brief tuple items.
254
- */
255
- tupleItems(value, items) {
180
+ tupleItems(value, items, itemGraphs) {
256
181
  return this.push((id) => ({
257
182
  id,
258
183
  tag: NodeTag.TupleItems,
259
184
  deps: [value],
260
185
  value,
261
- items
186
+ items,
187
+ itemGraphs
262
188
  }));
263
189
  }
264
- /**
265
- * @brief record every.
266
- */
267
- recordEvery(value, item) {
190
+ recordEvery(value, item, itemGraph) {
268
191
  return this.push((id) => ({
269
192
  id,
270
193
  tag: NodeTag.RecordEvery,
271
194
  deps: [value],
272
195
  value,
273
- item
196
+ item,
197
+ itemGraph
274
198
  }));
275
199
  }
276
- /**
277
- * @brief discriminant dispatch.
278
- */
279
- discriminantDispatch(value, key, literals, schemas) {
200
+ discriminantDispatch(value, key, literals, schemas, graphs) {
280
201
  return this.push((id) => ({
281
202
  id,
282
203
  tag: NodeTag.DiscriminantDispatch,
@@ -285,12 +206,45 @@ export class GraphBuilder {
285
206
  key,
286
207
  literals,
287
208
  schemas,
209
+ graphs,
288
210
  lookup: makeDiscriminantLookup(literals)
289
211
  }));
290
212
  }
291
- /**
292
- * @brief schema check.
293
- */
213
+ objectShape(value, entries, keys, mode, catchall, catchallGraph) {
214
+ return this.push((id) => ({
215
+ id,
216
+ tag: NodeTag.ObjectShape,
217
+ deps: [value],
218
+ value,
219
+ entries,
220
+ keys,
221
+ mode,
222
+ catchall,
223
+ catchallGraph,
224
+ allRequired: objectShapeAllRequired(entries)
225
+ }));
226
+ }
227
+ unionDispatch(value, options, graphs, masks) {
228
+ return this.push((id) => ({
229
+ id,
230
+ tag: NodeTag.UnionDispatch,
231
+ deps: [value],
232
+ value,
233
+ options,
234
+ graphs,
235
+ masks
236
+ }));
237
+ }
238
+ primitiveUnion(value, graphs, masks) {
239
+ return this.push((id) => ({
240
+ id,
241
+ tag: NodeTag.PrimitiveUnion,
242
+ deps: [value],
243
+ value,
244
+ graphs,
245
+ masks
246
+ }));
247
+ }
294
248
  schemaCheck(value, schema) {
295
249
  return this.push((id) => ({
296
250
  id,
@@ -300,9 +254,6 @@ export class GraphBuilder {
300
254
  schema
301
255
  }));
302
256
  }
303
- /**
304
- * @brief and.
305
- */
306
257
  and(values) {
307
258
  const first = values[0];
308
259
  if (first === undefined) {
@@ -319,9 +270,6 @@ export class GraphBuilder {
319
270
  values
320
271
  }));
321
272
  }
322
- /**
323
- * @brief or.
324
- */
325
273
  or(values) {
326
274
  const first = values[0];
327
275
  if (first === undefined) {
@@ -338,9 +286,6 @@ export class GraphBuilder {
338
286
  values
339
287
  }));
340
288
  }
341
- /**
342
- * @brief ret.
343
- */
344
289
  ret(control, value) {
345
290
  return this.push((id) => ({
346
291
  id,
@@ -350,9 +295,6 @@ export class GraphBuilder {
350
295
  value
351
296
  }));
352
297
  }
353
- /**
354
- * @brief finish.
355
- */
356
298
  finish(entry, result) {
357
299
  return freezeGraph({
358
300
  nodes: this.nodes.slice(),
@@ -360,9 +302,6 @@ export class GraphBuilder {
360
302
  result
361
303
  });
362
304
  }
363
- /**
364
- * @brief unary.
365
- */
366
305
  unary(tag, value) {
367
306
  const key = `unary:${String(tag)}:${String(value)}`;
368
307
  return this.intern(key, (id) => ({
@@ -372,9 +311,6 @@ export class GraphBuilder {
372
311
  value
373
312
  }));
374
313
  }
375
- /**
376
- * @brief numeric.
377
- */
378
314
  numeric(tag, left, right) {
379
315
  const key = `numeric:${String(tag)}:${String(left)}:${String(right)}`;
380
316
  return this.intern(key, (id) => ({
@@ -385,9 +321,6 @@ export class GraphBuilder {
385
321
  right
386
322
  }));
387
323
  }
388
- /**
389
- * @brief string bound.
390
- */
391
324
  stringBound(tag, value, bound) {
392
325
  const key = `stringBound:${String(tag)}:${String(value)}:${String(bound)}`;
393
326
  return this.intern(key, (id) => ({
@@ -398,9 +331,6 @@ export class GraphBuilder {
398
331
  bound
399
332
  }));
400
333
  }
401
- /**
402
- * @brief intern.
403
- */
404
334
  intern(key, make) {
405
335
  const cached = this.hash.get(key);
406
336
  if (cached !== undefined) {
@@ -412,9 +342,6 @@ export class GraphBuilder {
412
342
  this.hash.set(key, id);
413
343
  return id;
414
344
  }
415
- /**
416
- * @brief push.
417
- */
418
345
  push(make) {
419
346
  const id = this.nodes.length;
420
347
  const node = make(id);
@@ -423,23 +350,38 @@ export class GraphBuilder {
423
350
  }
424
351
  }
425
352
  /**
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.
353
+ * @brief Execute object shape all required.
354
+ * @details This helper keeps a local invariant explicit at the module boundary.
355
+ */
356
+ function objectShapeAllRequired(entries) {
357
+ for (let index = 0; index < entries.length; index += 1) {
358
+ const entry = entries[index];
359
+ if (entry?.presence !== PresenceTag.Required) {
360
+ return false;
361
+ }
362
+ }
363
+ return true;
364
+ }
365
+ /**
366
+ * @brief Build an intern key without letting adjacent regex fields merge.
367
+ * @details Source, flags, and diagnostic name are all user-controlled strings;
368
+ * length prefixes keep `["ab", "c"]` distinct from `["a", "bc"]` without
369
+ * allocating wrapper tuples in the hot builder path.
429
370
  */
430
371
  function makeRegexInternKey(value, source, flags, name) {
431
372
  return `regex:${String(value)}:${lengthPrefixed(source)}${lengthPrefixed(flags)}${lengthPrefixed(name)}`;
432
373
  }
433
374
  /**
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.
375
+ * @brief Encode one string segment for a flat composite key.
376
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
377
+ * compiler, or public introspection boundaries.
437
378
  */
438
379
  function lengthPrefixed(value) {
439
380
  return `${String(value.length)}:${value};`;
440
381
  }
441
382
  /**
442
- * @brief literal key.
383
+ * @brief Execute literal key.
384
+ * @details This helper keeps a local invariant explicit at the module boundary.
443
385
  */
444
386
  function literalKey(value) {
445
387
  if (value === null) {
@@ -467,7 +409,8 @@ function literalKey(value) {
467
409
  return "undefined";
468
410
  }
469
411
  /**
470
- * @brief make discriminant lookup.
412
+ * @brief Build discriminant lookup.
413
+ * @details This helper keeps a local invariant explicit at the module boundary.
471
414
  */
472
415
  function makeDiscriminantLookup(literals) {
473
416
  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,8 @@ function freezeGraphNode(node) {
32
38
  break;
33
39
  case NodeTag.ArrayEvery:
34
40
  freezeSchema(node.item);
41
+ Object.freeze(node.checks);
42
+ freezeGraph(node.itemGraph);
35
43
  break;
36
44
  case NodeTag.TupleItems:
37
45
  for (let index = 0; index < node.items.length; index += 1) {
@@ -39,11 +47,17 @@ function freezeGraphNode(node) {
39
47
  if (item !== undefined) {
40
48
  freezeSchema(item);
41
49
  }
50
+ const graph = node.itemGraphs[index];
51
+ if (graph !== undefined) {
52
+ freezeGraph(graph);
53
+ }
42
54
  }
43
55
  Object.freeze(node.items);
56
+ Object.freeze(node.itemGraphs);
44
57
  break;
45
58
  case NodeTag.RecordEvery:
46
59
  freezeSchema(node.item);
60
+ freezeGraph(node.itemGraph);
47
61
  break;
48
62
  case NodeTag.DiscriminantDispatch:
49
63
  Object.freeze(node.literals);
@@ -52,10 +66,58 @@ function freezeGraphNode(node) {
52
66
  if (schema !== undefined) {
53
67
  freezeSchema(schema);
54
68
  }
69
+ const graph = node.graphs[index];
70
+ if (graph !== undefined) {
71
+ freezeGraph(graph);
72
+ }
55
73
  }
56
74
  Object.freeze(node.schemas);
75
+ Object.freeze(node.graphs);
57
76
  Object.freeze(node.lookup);
58
77
  break;
78
+ case NodeTag.ObjectShape:
79
+ for (let index = 0; index < node.entries.length; index += 1) {
80
+ const entry = node.entries[index];
81
+ if (entry !== undefined) {
82
+ freezeSchema(entry.schema);
83
+ freezeGraph(entry.graph);
84
+ Object.freeze(entry);
85
+ }
86
+ }
87
+ if (node.catchall !== undefined) {
88
+ freezeSchema(node.catchall);
89
+ }
90
+ if (node.catchallGraph !== undefined) {
91
+ freezeGraph(node.catchallGraph);
92
+ }
93
+ Object.freeze(node.entries);
94
+ Object.freeze(node.keys);
95
+ break;
96
+ case NodeTag.UnionDispatch:
97
+ for (let index = 0; index < node.options.length; index += 1) {
98
+ const schema = node.options[index];
99
+ if (schema !== undefined) {
100
+ freezeSchema(schema);
101
+ }
102
+ const graph = node.graphs[index];
103
+ if (graph !== undefined) {
104
+ freezeGraph(graph);
105
+ }
106
+ }
107
+ Object.freeze(node.options);
108
+ Object.freeze(node.graphs);
109
+ Object.freeze(node.masks);
110
+ break;
111
+ case NodeTag.PrimitiveUnion:
112
+ for (let index = 0; index < node.graphs.length; index += 1) {
113
+ const graph = node.graphs[index];
114
+ if (graph !== undefined) {
115
+ freezeGraph(graph);
116
+ }
117
+ }
118
+ Object.freeze(node.graphs);
119
+ Object.freeze(node.masks);
120
+ break;
59
121
  case NodeTag.SchemaCheck:
60
122
  freezeSchema(node.schema);
61
123
  break;
@@ -70,6 +132,8 @@ function freezeGraphNode(node) {
70
132
  }
71
133
  /**
72
134
  * @brief freeze regex node.
135
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
136
+ * compiler, or public introspection boundaries.
73
137
  */
74
138
  function freezeRegexNode(node) {
75
139
  const regex = node.regex;
@@ -94,6 +158,8 @@ function freezeRegexNode(node) {
94
158
  }
95
159
  /**
96
160
  * @brief clone graph reg exp.
161
+ * @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
162
+ * compiler, or public introspection boundaries.
97
163
  */
98
164
  function cloneGraphRegExp(regex) {
99
165
  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 &&