typesea 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/CHANGELOG.md +67 -6
  2. package/README.md +98 -17
  3. package/dist/adapters/index.d.ts +50 -8
  4. package/dist/adapters/index.d.ts.map +1 -1
  5. package/dist/adapters/index.js +169 -48
  6. package/dist/aot/index.d.ts +18 -2
  7. package/dist/aot/index.d.ts.map +1 -1
  8. package/dist/aot/index.js +93 -14
  9. package/dist/async/index.d.ts +28 -56
  10. package/dist/async/index.d.ts.map +1 -1
  11. package/dist/async/index.js +94 -37
  12. package/dist/builders/composite.d.ts +37 -6
  13. package/dist/builders/composite.d.ts.map +1 -1
  14. package/dist/builders/composite.js +84 -10
  15. package/dist/builders/index.d.ts +2 -0
  16. package/dist/builders/index.d.ts.map +1 -1
  17. package/dist/builders/index.js +2 -0
  18. package/dist/builders/modifier.d.ts +30 -5
  19. package/dist/builders/modifier.d.ts.map +1 -1
  20. package/dist/builders/modifier.js +38 -5
  21. package/dist/builders/object/guard.d.ts +18 -22
  22. package/dist/builders/object/guard.d.ts.map +1 -1
  23. package/dist/builders/object/guard.js +26 -26
  24. package/dist/builders/object/index.d.ts +2 -0
  25. package/dist/builders/object/index.d.ts.map +1 -1
  26. package/dist/builders/object/index.js +2 -0
  27. package/dist/builders/object/schema.d.ts +55 -9
  28. package/dist/builders/object/schema.d.ts.map +1 -1
  29. package/dist/builders/object/schema.js +92 -15
  30. package/dist/builders/object/types.d.ts +5 -31
  31. package/dist/builders/object/types.d.ts.map +1 -1
  32. package/dist/builders/object/types.js +2 -0
  33. package/dist/builders/scalar.d.ts +29 -8
  34. package/dist/builders/scalar.d.ts.map +1 -1
  35. package/dist/builders/scalar.js +33 -8
  36. package/dist/builders/table.d.ts +4 -0
  37. package/dist/builders/table.d.ts.map +1 -1
  38. package/dist/builders/table.js +4 -0
  39. package/dist/builders/types.d.ts +14 -4
  40. package/dist/builders/types.d.ts.map +1 -1
  41. package/dist/builders/types.js +2 -0
  42. package/dist/compile/check-composite.d.ts +22 -1
  43. package/dist/compile/check-composite.d.ts.map +1 -1
  44. package/dist/compile/check-composite.js +564 -24
  45. package/dist/compile/check-scalar.d.ts +78 -0
  46. package/dist/compile/check-scalar.d.ts.map +1 -1
  47. package/dist/compile/check-scalar.js +432 -1
  48. package/dist/compile/check.d.ts +12 -0
  49. package/dist/compile/check.d.ts.map +1 -1
  50. package/dist/compile/check.js +37 -0
  51. package/dist/compile/context.d.ts +47 -9
  52. package/dist/compile/context.d.ts.map +1 -1
  53. package/dist/compile/context.js +51 -8
  54. package/dist/compile/graph-predicate.d.ts +4 -2
  55. package/dist/compile/graph-predicate.d.ts.map +1 -1
  56. package/dist/compile/graph-predicate.js +1907 -171
  57. package/dist/compile/guard.d.ts +15 -24
  58. package/dist/compile/guard.d.ts.map +1 -1
  59. package/dist/compile/guard.js +158 -74
  60. package/dist/compile/index.d.ts +3 -1
  61. package/dist/compile/index.d.ts.map +1 -1
  62. package/dist/compile/index.js +2 -0
  63. package/dist/compile/issue.d.ts +110 -0
  64. package/dist/compile/issue.d.ts.map +1 -1
  65. package/dist/compile/issue.js +184 -1
  66. package/dist/compile/names.d.ts +12 -2
  67. package/dist/compile/names.d.ts.map +1 -1
  68. package/dist/compile/names.js +19 -3
  69. package/dist/compile/predicate.d.ts +24 -0
  70. package/dist/compile/predicate.d.ts.map +1 -1
  71. package/dist/compile/predicate.js +131 -5
  72. package/dist/compile/runtime.d.ts +80 -12
  73. package/dist/compile/runtime.d.ts.map +1 -1
  74. package/dist/compile/runtime.js +25 -6
  75. package/dist/compile/source.d.ts +10 -2
  76. package/dist/compile/source.d.ts.map +1 -1
  77. package/dist/compile/source.js +361 -26
  78. package/dist/compile/types.d.ts +20 -0
  79. package/dist/compile/types.d.ts.map +1 -1
  80. package/dist/compile/types.js +2 -0
  81. package/dist/decoder/index.d.ts +32 -46
  82. package/dist/decoder/index.d.ts.map +1 -1
  83. package/dist/decoder/index.js +102 -38
  84. package/dist/evaluate/check-composite.d.ts +59 -0
  85. package/dist/evaluate/check-composite.d.ts.map +1 -1
  86. package/dist/evaluate/check-composite.js +151 -3
  87. package/dist/evaluate/check-scalar.d.ts +16 -0
  88. package/dist/evaluate/check-scalar.d.ts.map +1 -1
  89. package/dist/evaluate/check-scalar.js +32 -0
  90. package/dist/evaluate/check.d.ts +7 -0
  91. package/dist/evaluate/check.d.ts.map +1 -1
  92. package/dist/evaluate/check.js +43 -0
  93. package/dist/evaluate/index.d.ts +2 -0
  94. package/dist/evaluate/index.d.ts.map +1 -1
  95. package/dist/evaluate/index.js +2 -0
  96. package/dist/evaluate/issue.d.ts +11 -1
  97. package/dist/evaluate/issue.d.ts.map +1 -1
  98. package/dist/evaluate/issue.js +15 -1
  99. package/dist/evaluate/predicate.d.ts +16 -5
  100. package/dist/evaluate/predicate.d.ts.map +1 -1
  101. package/dist/evaluate/predicate.js +20 -5
  102. package/dist/evaluate/shared.d.ts +59 -13
  103. package/dist/evaluate/shared.d.ts.map +1 -1
  104. package/dist/evaluate/shared.js +66 -8
  105. package/dist/evaluate/state.d.ts +35 -13
  106. package/dist/evaluate/state.d.ts.map +1 -1
  107. package/dist/evaluate/state.js +35 -2
  108. package/dist/guard/base.d.ts +79 -29
  109. package/dist/guard/base.d.ts.map +1 -1
  110. package/dist/guard/base.js +91 -29
  111. package/dist/guard/error.d.ts +10 -5
  112. package/dist/guard/error.d.ts.map +1 -1
  113. package/dist/guard/error.js +10 -5
  114. package/dist/guard/index.d.ts +2 -0
  115. package/dist/guard/index.d.ts.map +1 -1
  116. package/dist/guard/index.js +2 -0
  117. package/dist/guard/number.d.ts +26 -11
  118. package/dist/guard/number.d.ts.map +1 -1
  119. package/dist/guard/number.js +30 -11
  120. package/dist/guard/props.d.ts +27 -3
  121. package/dist/guard/props.d.ts.map +1 -1
  122. package/dist/guard/props.js +27 -3
  123. package/dist/guard/read.d.ts +62 -9
  124. package/dist/guard/read.d.ts.map +1 -1
  125. package/dist/guard/read.js +83 -10
  126. package/dist/guard/registry.d.ts +12 -2
  127. package/dist/guard/registry.d.ts.map +1 -1
  128. package/dist/guard/registry.js +15 -3
  129. package/dist/guard/string.d.ts +33 -13
  130. package/dist/guard/string.d.ts.map +1 -1
  131. package/dist/guard/string.js +37 -13
  132. package/dist/guard/types.d.ts +92 -40
  133. package/dist/guard/types.d.ts.map +1 -1
  134. package/dist/guard/types.js +2 -0
  135. package/dist/index.d.ts +1 -1
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/internal/index.d.ts +42 -6
  138. package/dist/internal/index.d.ts.map +1 -1
  139. package/dist/internal/index.js +51 -8
  140. package/dist/ir/builder.d.ts +16 -126
  141. package/dist/ir/builder.d.ts.map +1 -1
  142. package/dist/ir/builder.js +77 -137
  143. package/dist/ir/freeze.d.ts +4 -0
  144. package/dist/ir/freeze.d.ts.map +1 -1
  145. package/dist/ir/freeze.js +59 -0
  146. package/dist/ir/index.d.ts +3 -1
  147. package/dist/ir/index.d.ts.map +1 -1
  148. package/dist/ir/index.js +2 -0
  149. package/dist/ir/regexp.d.ts +2 -0
  150. package/dist/ir/regexp.d.ts.map +1 -1
  151. package/dist/ir/regexp.js +2 -0
  152. package/dist/ir/types.d.ts +90 -55
  153. package/dist/ir/types.d.ts.map +1 -1
  154. package/dist/ir/types.js +2 -0
  155. package/dist/ir/validate.d.ts +8 -1
  156. package/dist/ir/validate.d.ts.map +1 -1
  157. package/dist/ir/validate.js +477 -61
  158. package/dist/issue/index.d.ts +41 -9
  159. package/dist/issue/index.d.ts.map +1 -1
  160. package/dist/issue/index.js +61 -11
  161. package/dist/json-schema/emit-combinator.d.ts +44 -4
  162. package/dist/json-schema/emit-combinator.d.ts.map +1 -1
  163. package/dist/json-schema/emit-combinator.js +44 -4
  164. package/dist/json-schema/emit-composite.d.ts +10 -0
  165. package/dist/json-schema/emit-composite.d.ts.map +1 -1
  166. package/dist/json-schema/emit-composite.js +15 -1
  167. package/dist/json-schema/emit-scalar.d.ts +26 -3
  168. package/dist/json-schema/emit-scalar.d.ts.map +1 -1
  169. package/dist/json-schema/emit-scalar.js +70 -9
  170. package/dist/json-schema/emit-types.d.ts +11 -1
  171. package/dist/json-schema/emit-types.d.ts.map +1 -1
  172. package/dist/json-schema/emit-types.js +2 -0
  173. package/dist/json-schema/emit.d.ts +12 -1
  174. package/dist/json-schema/emit.d.ts.map +1 -1
  175. package/dist/json-schema/emit.js +12 -1
  176. package/dist/json-schema/freeze.d.ts +13 -2
  177. package/dist/json-schema/freeze.d.ts.map +1 -1
  178. package/dist/json-schema/freeze.js +41 -8
  179. package/dist/json-schema/index.d.ts +16 -2
  180. package/dist/json-schema/index.d.ts.map +1 -1
  181. package/dist/json-schema/index.js +23 -3
  182. package/dist/json-schema/issue.d.ts +4 -1
  183. package/dist/json-schema/issue.d.ts.map +1 -1
  184. package/dist/json-schema/issue.js +4 -1
  185. package/dist/json-schema/read.d.ts +24 -3
  186. package/dist/json-schema/read.d.ts.map +1 -1
  187. package/dist/json-schema/read.js +59 -12
  188. package/dist/json-schema/types.d.ts +38 -15
  189. package/dist/json-schema/types.d.ts.map +1 -1
  190. package/dist/json-schema/types.js +2 -0
  191. package/dist/kind/index.d.ts +15 -28
  192. package/dist/kind/index.d.ts.map +1 -1
  193. package/dist/kind/index.js +15 -10
  194. package/dist/lower/index.d.ts +6 -1
  195. package/dist/lower/index.d.ts.map +1 -1
  196. package/dist/lower/index.js +411 -44
  197. package/dist/message/index.d.ts +46 -10
  198. package/dist/message/index.d.ts.map +1 -1
  199. package/dist/message/index.js +88 -17
  200. package/dist/optimize/algebraic.d.ts +54 -0
  201. package/dist/optimize/algebraic.d.ts.map +1 -0
  202. package/dist/optimize/algebraic.js +314 -0
  203. package/dist/optimize/compact.d.ts +8 -1
  204. package/dist/optimize/compact.d.ts.map +1 -1
  205. package/dist/optimize/compact.js +13 -2
  206. package/dist/optimize/domain.d.ts +16 -0
  207. package/dist/optimize/domain.d.ts.map +1 -0
  208. package/dist/optimize/domain.js +615 -0
  209. package/dist/optimize/fold-boolean.d.ts +17 -2
  210. package/dist/optimize/fold-boolean.d.ts.map +1 -1
  211. package/dist/optimize/fold-boolean.js +59 -14
  212. package/dist/optimize/fold-common.d.ts +43 -8
  213. package/dist/optimize/fold-common.d.ts.map +1 -1
  214. package/dist/optimize/fold-common.js +37 -6
  215. package/dist/optimize/fold-constraints.d.ts +33 -0
  216. package/dist/optimize/fold-constraints.d.ts.map +1 -0
  217. package/dist/optimize/fold-constraints.js +484 -0
  218. package/dist/optimize/fold-scalar.d.ts +98 -13
  219. package/dist/optimize/fold-scalar.d.ts.map +1 -1
  220. package/dist/optimize/fold-scalar.js +98 -13
  221. package/dist/optimize/fold.d.ts +8 -1
  222. package/dist/optimize/fold.d.ts.map +1 -1
  223. package/dist/optimize/fold.js +22 -2
  224. package/dist/optimize/index.d.ts +9 -1
  225. package/dist/optimize/index.d.ts.map +1 -1
  226. package/dist/optimize/index.js +18 -3
  227. package/dist/optimize/map-node.d.ts +3 -1
  228. package/dist/optimize/map-node.d.ts.map +1 -1
  229. package/dist/optimize/map-node.js +45 -3
  230. package/dist/optimize/peephole.d.ts +16 -0
  231. package/dist/optimize/peephole.d.ts.map +1 -0
  232. package/dist/optimize/peephole.js +254 -0
  233. package/dist/optimize/remap.d.ts +2 -0
  234. package/dist/optimize/remap.d.ts.map +1 -1
  235. package/dist/optimize/remap.js +2 -0
  236. package/dist/optimize/rewrite.d.ts +13 -8
  237. package/dist/optimize/rewrite.d.ts.map +1 -1
  238. package/dist/optimize/rewrite.js +13 -8
  239. package/dist/plan/cache.d.ts +9 -3
  240. package/dist/plan/cache.d.ts.map +1 -1
  241. package/dist/plan/cache.js +21 -5
  242. package/dist/plan/index.d.ts +2 -0
  243. package/dist/plan/index.d.ts.map +1 -1
  244. package/dist/plan/index.js +2 -0
  245. package/dist/plan/predicate.d.ts +2 -0
  246. package/dist/plan/predicate.d.ts.map +1 -1
  247. package/dist/plan/predicate.js +268 -29
  248. package/dist/plan/schema-predicate.d.ts +6 -0
  249. package/dist/plan/schema-predicate.d.ts.map +1 -1
  250. package/dist/plan/schema-predicate.js +117 -13
  251. package/dist/plan/types.d.ts +2 -0
  252. package/dist/plan/types.d.ts.map +1 -1
  253. package/dist/plan/types.js +2 -0
  254. package/dist/result/index.d.ts +19 -5
  255. package/dist/result/index.d.ts.map +1 -1
  256. package/dist/result/index.js +10 -2
  257. package/dist/schema/common.d.ts +69 -6
  258. package/dist/schema/common.d.ts.map +1 -1
  259. package/dist/schema/common.js +104 -10
  260. package/dist/schema/freeze.d.ts +4 -0
  261. package/dist/schema/freeze.d.ts.map +1 -1
  262. package/dist/schema/freeze.js +18 -0
  263. package/dist/schema/index.d.ts +3 -0
  264. package/dist/schema/index.d.ts.map +1 -1
  265. package/dist/schema/index.js +3 -0
  266. package/dist/schema/lazy.d.ts +4 -0
  267. package/dist/schema/lazy.d.ts.map +1 -1
  268. package/dist/schema/lazy.js +4 -0
  269. package/dist/schema/literal.d.ts +7 -1
  270. package/dist/schema/literal.d.ts.map +1 -1
  271. package/dist/schema/literal.js +7 -1
  272. package/dist/schema/types.d.ts +20 -96
  273. package/dist/schema/types.d.ts.map +1 -1
  274. package/dist/schema/types.js +5 -1
  275. package/dist/schema/undefined.d.ts +17 -0
  276. package/dist/schema/undefined.d.ts.map +1 -0
  277. package/dist/schema/undefined.js +72 -0
  278. package/dist/schema/validate.d.ts +8 -1
  279. package/dist/schema/validate.d.ts.map +1 -1
  280. package/dist/schema/validate.js +146 -55
  281. package/docs/api.md +57 -0
  282. package/docs/assets/benchmark-headline.svg +163 -0
  283. package/docs/engine-notes.md +58 -15
  284. package/docs/index.html +130 -110
  285. package/package.json +65 -65
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file compile/check.ts
3
3
  * @brief Diagnostic validator function table emitter.
4
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
5
+ * stable across runtime and AOT emission.
4
6
  */
5
7
  import { SchemaTag } from "../kind/index.js";
6
8
  import { emitArrayCheck, emitDiscriminatedUnionCheck, emitObjectCheck, emitRecordCheck, emitTupleCheck } from "./check-composite.js";
@@ -10,12 +12,22 @@ import { emitIssue } from "./issue.js";
10
12
  import { emitUnion } from "./predicate.js";
11
13
  /**
12
14
  * @brief emit check function.
15
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
16
+ * stable across runtime and AOT emission.
17
+ * @param schema Schema whose diagnostics should be emitted.
18
+ * @param context Shared code-generation context.
19
+ * @returns Generated diagnostic function name.
20
+ * @invariant The same schema object maps to one diagnostic function per bundle.
13
21
  */
14
22
  export function emitCheckFunction(schema, context) {
15
23
  const cached = context.checkFunctionNames.get(schema);
16
24
  if (cached !== undefined) {
17
25
  return cached;
18
26
  }
27
+ /*
28
+ * Insert the placeholder before emitting the body. Recursive schemas can
29
+ * request this same function while the current body is still being built.
30
+ */
19
31
  const name = `c${String(context.checkFunctions.length)}`;
20
32
  const source = {
21
33
  name,
@@ -28,6 +40,10 @@ export function emitCheckFunction(schema, context) {
28
40
  }
29
41
  /**
30
42
  * @brief emit check functions.
43
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
44
+ * stable across runtime and AOT emission.
45
+ * @param context Shared code-generation context with accumulated check sources.
46
+ * @returns Concatenated JavaScript function declarations.
31
47
  */
32
48
  export function emitCheckFunctions(context) {
33
49
  const chunks = new Array(context.checkFunctions.length);
@@ -42,6 +58,14 @@ export function emitCheckFunctions(context) {
42
58
  }
43
59
  /**
44
60
  * @brief emit check body.
61
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
62
+ * stable across runtime and AOT emission.
63
+ * @param schema Schema represented by this diagnostic body.
64
+ * @param value Generated expression for the candidate value.
65
+ * @param path Generated expression for the mutable path stack.
66
+ * @param issues Generated expression for the issue buffer.
67
+ * @param context Shared code-generation context.
68
+ * @returns JavaScript source for diagnostic collection.
45
69
  */
46
70
  function emitCheckBody(schema, value, path, issues, context) {
47
71
  switch (schema.tag) {
@@ -87,11 +111,24 @@ function emitCheckBody(schema, value, path, issues, context) {
87
111
  return emitCheckCall(schema.inner, value, path, issues, context);
88
112
  case SchemaTag.Lazy:
89
113
  case SchemaTag.Refine:
114
+ /*
115
+ * Lazy and refine schemas execute runtime logic that cannot be safely
116
+ * inlined into generated source. The `m` helper calls the interpreter
117
+ * diagnostic path through the dynamic schema side table.
118
+ */
90
119
  return `m(${String(pushSchema(context, schema))},${value},${path},${issues});`;
91
120
  }
92
121
  }
93
122
  /**
94
123
  * @brief emit check call.
124
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
125
+ * stable across runtime and AOT emission.
126
+ * @param schema Child schema to dispatch to.
127
+ * @param value Generated expression for the child value.
128
+ * @param path Generated expression for the mutable path stack.
129
+ * @param issues Generated expression for the issue buffer.
130
+ * @param context Shared code-generation context.
131
+ * @returns JavaScript source for invoking the child diagnostic function.
95
132
  */
96
133
  function emitCheckCall(schema, value, path, issues, context) {
97
134
  return `${emitCheckFunction(schema, context)}(${value},${path},${issues});`;
@@ -1,35 +1,73 @@
1
1
  /**
2
2
  * @file compile/context.ts
3
3
  * @brief Generated-source emitter side-table context.
4
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
5
+ * stable across runtime and AOT emission.
4
6
  */
5
7
  import type { LiteralValue, Schema } from "../schema/index.js";
6
- import type { EmitContext } from "./types.js";
8
+ import type { CompileMode, EmitContext } from "./types.js";
7
9
  /**
8
- * @brief create emit context.
10
+ * @brief Create one mutable source-emission context.
11
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
12
+ * stable across runtime and AOT emission.
13
+ * @param mode Compile mode that controls safety and allocation tradeoffs.
14
+ * @returns Fresh side-table context consumed by predicate and diagnostic emitters.
15
+ * @invariant Side tables are append-only during one bundle emission.
9
16
  */
10
- export declare function createEmitContext(): EmitContext;
17
+ export declare function createEmitContext(mode: CompileMode): EmitContext;
11
18
  /**
12
- * @brief push literal.
19
+ * @brief Append a literal to the generated factory side table.
20
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
21
+ * stable across runtime and AOT emission.
22
+ * @param context Mutable emission context.
23
+ * @param value Literal value referenced by generated source.
24
+ * @returns Index used by generated code to read `l[index]`.
13
25
  */
14
26
  export declare function pushLiteral(context: EmitContext, value: LiteralValue): number;
15
27
  /**
16
- * @brief push regex.
28
+ * @brief Append a regular expression to the generated factory side table.
29
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
30
+ * stable across runtime and AOT emission.
31
+ * @param context Mutable emission context.
32
+ * @param value Source RegExp from the schema.
33
+ * @returns Index used by generated code to read `r[index]`.
34
+ * @post The stored RegExp is cloned so generated validation does not mutate user state.
17
35
  */
18
36
  export declare function pushRegex(context: EmitContext, value: RegExp): number;
19
37
  /**
20
- * @brief push keyset.
38
+ * @brief Append a keyset to the generated factory side table.
39
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
40
+ * stable across runtime and AOT emission.
41
+ * @param context Mutable emission context.
42
+ * @param value Frozen or caller-owned key list used by object checks.
43
+ * @returns Index used by generated code to read `k[index]`.
21
44
  */
22
45
  export declare function pushKeyset(context: EmitContext, value: readonly string[]): number;
23
46
  /**
24
- * @brief string ref.
47
+ * @brief Return a generated expression for a string side-table entry.
48
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
49
+ * stable across runtime and AOT emission.
50
+ * @param context Mutable emission context.
51
+ * @param value String value to intern.
52
+ * @returns Generated expression of the form `u[index]`.
25
53
  */
26
54
  export declare function stringRef(context: EmitContext, value: string): string;
27
55
  /**
28
- * @brief push string.
56
+ * @brief Intern a string in the generated factory side table.
57
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
58
+ * stable across runtime and AOT emission.
59
+ * @param context Mutable emission context.
60
+ * @param value String value referenced by generated source.
61
+ * @returns Stable side-table index for the string.
29
62
  */
30
63
  export declare function pushString(context: EmitContext, value: string): number;
31
64
  /**
32
- * @brief push schema.
65
+ * @brief Append a dynamic schema to the generated factory side table.
66
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
67
+ * stable across runtime and AOT emission.
68
+ * @param context Mutable emission context.
69
+ * @param value Schema used by fallback or lazy generated paths.
70
+ * @returns Index used by generated code to read `d[index]`.
33
71
  */
34
72
  export declare function pushSchema(context: EmitContext, value: Schema): number;
35
73
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/compile/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,WAAW,CAa/C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,CAI7E;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAIrE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAIjF;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAStE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAItE"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/compile/context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3D;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAchE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,CAI7E;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAIrE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAIjF;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAatE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAItE"}
@@ -1,12 +1,20 @@
1
1
  /**
2
2
  * @file compile/context.ts
3
3
  * @brief Generated-source emitter side-table context.
4
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
5
+ * stable across runtime and AOT emission.
4
6
  */
5
7
  /**
6
- * @brief create emit context.
8
+ * @brief Create one mutable source-emission context.
9
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
10
+ * stable across runtime and AOT emission.
11
+ * @param mode Compile mode that controls safety and allocation tradeoffs.
12
+ * @returns Fresh side-table context consumed by predicate and diagnostic emitters.
13
+ * @invariant Side tables are append-only during one bundle emission.
7
14
  */
8
- export function createEmitContext() {
15
+ export function createEmitContext(mode) {
9
16
  return {
17
+ mode,
10
18
  literals: [],
11
19
  regexps: [],
12
20
  keysets: [],
@@ -20,7 +28,12 @@ export function createEmitContext() {
20
28
  };
21
29
  }
22
30
  /**
23
- * @brief push literal.
31
+ * @brief Append a literal to the generated factory side table.
32
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
33
+ * stable across runtime and AOT emission.
34
+ * @param context Mutable emission context.
35
+ * @param value Literal value referenced by generated source.
36
+ * @returns Index used by generated code to read `l[index]`.
24
37
  */
25
38
  export function pushLiteral(context, value) {
26
39
  const index = context.literals.length;
@@ -28,7 +41,13 @@ export function pushLiteral(context, value) {
28
41
  return index;
29
42
  }
30
43
  /**
31
- * @brief push regex.
44
+ * @brief Append a regular expression to the generated factory side table.
45
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
46
+ * stable across runtime and AOT emission.
47
+ * @param context Mutable emission context.
48
+ * @param value Source RegExp from the schema.
49
+ * @returns Index used by generated code to read `r[index]`.
50
+ * @post The stored RegExp is cloned so generated validation does not mutate user state.
32
51
  */
33
52
  export function pushRegex(context, value) {
34
53
  const index = context.regexps.length;
@@ -36,7 +55,12 @@ export function pushRegex(context, value) {
36
55
  return index;
37
56
  }
38
57
  /**
39
- * @brief push keyset.
58
+ * @brief Append a keyset to the generated factory side table.
59
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
60
+ * stable across runtime and AOT emission.
61
+ * @param context Mutable emission context.
62
+ * @param value Frozen or caller-owned key list used by object checks.
63
+ * @returns Index used by generated code to read `k[index]`.
40
64
  */
41
65
  export function pushKeyset(context, value) {
42
66
  const index = context.keysets.length;
@@ -44,26 +68,45 @@ export function pushKeyset(context, value) {
44
68
  return index;
45
69
  }
46
70
  /**
47
- * @brief string ref.
71
+ * @brief Return a generated expression for a string side-table entry.
72
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
73
+ * stable across runtime and AOT emission.
74
+ * @param context Mutable emission context.
75
+ * @param value String value to intern.
76
+ * @returns Generated expression of the form `u[index]`.
48
77
  */
49
78
  export function stringRef(context, value) {
50
79
  return `u[${String(pushString(context, value))}]`;
51
80
  }
52
81
  /**
53
- * @brief push string.
82
+ * @brief Intern a string in the generated factory side table.
83
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
84
+ * stable across runtime and AOT emission.
85
+ * @param context Mutable emission context.
86
+ * @param value String value referenced by generated source.
87
+ * @returns Stable side-table index for the string.
54
88
  */
55
89
  export function pushString(context, value) {
56
90
  const cached = context.stringIndexes.get(value);
57
91
  if (cached !== undefined) {
58
92
  return cached;
59
93
  }
94
+ /*
95
+ * String interning keeps generated source small and lets repeated object
96
+ * keys reuse the same frozen path segment cache.
97
+ */
60
98
  const index = context.strings.length;
61
99
  context.strings.push(value);
62
100
  context.stringIndexes.set(value, index);
63
101
  return index;
64
102
  }
65
103
  /**
66
- * @brief push schema.
104
+ * @brief Append a dynamic schema to the generated factory side table.
105
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
106
+ * stable across runtime and AOT emission.
107
+ * @param context Mutable emission context.
108
+ * @param value Schema used by fallback or lazy generated paths.
109
+ * @returns Index used by generated code to read `d[index]`.
67
110
  */
68
111
  export function pushSchema(context, value) {
69
112
  const index = context.schemas.length;
@@ -1,15 +1,17 @@
1
1
  /**
2
2
  * @file graph-predicate.ts
3
3
  * @brief Predicate source emitter backed by optimized Sea-of-Nodes graphs.
4
+ * @details Generated-source helpers keep the side-table ABI and JavaScript source shape
5
+ * stable across runtime and AOT emission.
4
6
  */
5
- import type { Schema } from "../schema/index.js";
7
+ import { type Schema } from "../schema/index.js";
6
8
  import type { EmitContext } from "./types.js";
7
9
  /**
8
10
  * @brief emit graph function.
9
11
  * @details Emits one predicate function from the optimized graph owned by a schema plan.
10
12
  * @returns Generated function name.
11
13
  */
12
- export declare function emitGraphFunction(schema: Schema, context: EmitContext): string;
14
+ export declare function emitGraphFunction(schema: Schema, context: EmitContext, preferredName?: string): string;
13
15
  /**
14
16
  * @brief emit graph functions.
15
17
  * @details Serializes every graph predicate function accumulated in the context.
@@ -1 +1 @@
1
- {"version":3,"file":"graph-predicate.d.ts","sourceRoot":"","sources":["../../src/compile/graph-predicate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,KAAK,EAAgB,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAQ/D,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,YAAY,CAAC;AAoB9D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,GACnB,MAAM,CAoBR;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAS/D"}
1
+ {"version":3,"file":"graph-predicate.d.ts","sourceRoot":"","sources":["../../src/compile/graph-predicate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,OAAO,EAGH,KAAK,MAAM,EACd,MAAM,oBAAoB,CAAC;AAQ5B,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,YAAY,CAAC;AA8G9D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,EACpB,aAAa,CAAC,EAAE,MAAM,GACvB,MAAM,CAoBR;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAS/D"}