typesea 0.1.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 (271) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +21 -0
  3. package/README.md +320 -0
  4. package/dist/adapters/index.d.ts +152 -0
  5. package/dist/adapters/index.d.ts.map +1 -0
  6. package/dist/adapters/index.js +396 -0
  7. package/dist/aot/index.d.ts +33 -0
  8. package/dist/aot/index.d.ts.map +1 -0
  9. package/dist/aot/index.js +295 -0
  10. package/dist/async/index.d.ts +111 -0
  11. package/dist/async/index.d.ts.map +1 -0
  12. package/dist/async/index.js +221 -0
  13. package/dist/builders/composite.d.ts +31 -0
  14. package/dist/builders/composite.d.ts.map +1 -0
  15. package/dist/builders/composite.js +165 -0
  16. package/dist/builders/index.d.ts +11 -0
  17. package/dist/builders/index.d.ts.map +1 -0
  18. package/dist/builders/index.js +9 -0
  19. package/dist/builders/modifier.d.ts +26 -0
  20. package/dist/builders/modifier.d.ts.map +1 -0
  21. package/dist/builders/modifier.js +67 -0
  22. package/dist/builders/object/guard.d.ts +62 -0
  23. package/dist/builders/object/guard.d.ts.map +1 -0
  24. package/dist/builders/object/guard.js +113 -0
  25. package/dist/builders/object/index.d.ts +7 -0
  26. package/dist/builders/object/index.d.ts.map +1 -0
  27. package/dist/builders/object/index.js +5 -0
  28. package/dist/builders/object/schema.d.ts +44 -0
  29. package/dist/builders/object/schema.d.ts.map +1 -0
  30. package/dist/builders/object/schema.js +257 -0
  31. package/dist/builders/object/types.d.ts +63 -0
  32. package/dist/builders/object/types.d.ts.map +1 -0
  33. package/dist/builders/object/types.js +5 -0
  34. package/dist/builders/scalar.d.ts +39 -0
  35. package/dist/builders/scalar.d.ts.map +1 -0
  36. package/dist/builders/scalar.js +63 -0
  37. package/dist/builders/table.d.ts +53 -0
  38. package/dist/builders/table.d.ts.map +1 -0
  39. package/dist/builders/table.js +48 -0
  40. package/dist/builders/types.d.ts +26 -0
  41. package/dist/builders/types.d.ts.map +1 -0
  42. package/dist/builders/types.js +5 -0
  43. package/dist/compile/check-composite.d.ts +34 -0
  44. package/dist/compile/check-composite.d.ts.map +1 -0
  45. package/dist/compile/check-composite.js +117 -0
  46. package/dist/compile/check-scalar.d.ts +24 -0
  47. package/dist/compile/check-scalar.d.ts.map +1 -0
  48. package/dist/compile/check-scalar.js +73 -0
  49. package/dist/compile/check.d.ts +15 -0
  50. package/dist/compile/check.d.ts.map +1 -0
  51. package/dist/compile/check.js +98 -0
  52. package/dist/compile/context.d.ts +35 -0
  53. package/dist/compile/context.d.ts.map +1 -0
  54. package/dist/compile/context.js +72 -0
  55. package/dist/compile/graph-predicate.d.ts +19 -0
  56. package/dist/compile/graph-predicate.d.ts.map +1 -0
  57. package/dist/compile/graph-predicate.js +460 -0
  58. package/dist/compile/guard.d.ts +41 -0
  59. package/dist/compile/guard.d.ts.map +1 -0
  60. package/dist/compile/guard.js +180 -0
  61. package/dist/compile/index.d.ts +8 -0
  62. package/dist/compile/index.d.ts.map +1 -0
  63. package/dist/compile/index.js +6 -0
  64. package/dist/compile/issue.d.ts +18 -0
  65. package/dist/compile/issue.d.ts.map +1 -0
  66. package/dist/compile/issue.js +28 -0
  67. package/dist/compile/names.d.ts +16 -0
  68. package/dist/compile/names.d.ts.map +1 -0
  69. package/dist/compile/names.js +82 -0
  70. package/dist/compile/predicate.d.ts +23 -0
  71. package/dist/compile/predicate.d.ts.map +1 -0
  72. package/dist/compile/predicate.js +317 -0
  73. package/dist/compile/runtime.d.ts +55 -0
  74. package/dist/compile/runtime.d.ts.map +1 -0
  75. package/dist/compile/runtime.js +63 -0
  76. package/dist/compile/source.d.ts +11 -0
  77. package/dist/compile/source.d.ts.map +1 -0
  78. package/dist/compile/source.js +51 -0
  79. package/dist/compile/types.d.ts +52 -0
  80. package/dist/compile/types.d.ts.map +1 -0
  81. package/dist/compile/types.js +5 -0
  82. package/dist/decoder/index.d.ts +106 -0
  83. package/dist/decoder/index.d.ts.map +1 -0
  84. package/dist/decoder/index.js +262 -0
  85. package/dist/evaluate/check-composite.d.ts +39 -0
  86. package/dist/evaluate/check-composite.d.ts.map +1 -0
  87. package/dist/evaluate/check-composite.js +184 -0
  88. package/dist/evaluate/check-scalar.d.ts +20 -0
  89. package/dist/evaluate/check-scalar.d.ts.map +1 -0
  90. package/dist/evaluate/check-scalar.js +81 -0
  91. package/dist/evaluate/check.d.ts +11 -0
  92. package/dist/evaluate/check.d.ts.map +1 -0
  93. package/dist/evaluate/check.js +126 -0
  94. package/dist/evaluate/index.d.ts +7 -0
  95. package/dist/evaluate/index.d.ts.map +1 -0
  96. package/dist/evaluate/index.js +6 -0
  97. package/dist/evaluate/issue.d.ts +10 -0
  98. package/dist/evaluate/issue.d.ts.map +1 -0
  99. package/dist/evaluate/issue.js +11 -0
  100. package/dist/evaluate/predicate.d.ts +26 -0
  101. package/dist/evaluate/predicate.d.ts.map +1 -0
  102. package/dist/evaluate/predicate.js +37 -0
  103. package/dist/evaluate/shared.d.ts +59 -0
  104. package/dist/evaluate/shared.d.ts.map +1 -0
  105. package/dist/evaluate/shared.js +96 -0
  106. package/dist/evaluate/state.d.ts +65 -0
  107. package/dist/evaluate/state.d.ts.map +1 -0
  108. package/dist/evaluate/state.js +66 -0
  109. package/dist/guard/base.d.ts +72 -0
  110. package/dist/guard/base.d.ts.map +1 -0
  111. package/dist/guard/base.js +136 -0
  112. package/dist/guard/error.d.ts +19 -0
  113. package/dist/guard/error.d.ts.map +1 -0
  114. package/dist/guard/error.js +22 -0
  115. package/dist/guard/index.d.ts +10 -0
  116. package/dist/guard/index.d.ts.map +1 -0
  117. package/dist/guard/index.js +8 -0
  118. package/dist/guard/number.d.ts +32 -0
  119. package/dist/guard/number.d.ts.map +1 -0
  120. package/dist/guard/number.js +71 -0
  121. package/dist/guard/props.d.ts +18 -0
  122. package/dist/guard/props.d.ts.map +1 -0
  123. package/dist/guard/props.js +35 -0
  124. package/dist/guard/read.d.ts +42 -0
  125. package/dist/guard/read.d.ts.map +1 -0
  126. package/dist/guard/read.js +114 -0
  127. package/dist/guard/registry.d.ts +15 -0
  128. package/dist/guard/registry.d.ts.map +1 -0
  129. package/dist/guard/registry.js +21 -0
  130. package/dist/guard/string.d.ts +36 -0
  131. package/dist/guard/string.d.ts.map +1 -0
  132. package/dist/guard/string.js +95 -0
  133. package/dist/guard/types.d.ts +103 -0
  134. package/dist/guard/types.d.ts.map +1 -0
  135. package/dist/guard/types.js +5 -0
  136. package/dist/index.d.ts +14 -0
  137. package/dist/index.d.ts.map +1 -0
  138. package/dist/index.js +10 -0
  139. package/dist/internal/index.d.ts +34 -0
  140. package/dist/internal/index.d.ts.map +1 -0
  141. package/dist/internal/index.js +56 -0
  142. package/dist/ir/builder.d.ts +173 -0
  143. package/dist/ir/builder.d.ts.map +1 -0
  144. package/dist/ir/builder.js +481 -0
  145. package/dist/ir/freeze.d.ts +10 -0
  146. package/dist/ir/freeze.d.ts.map +1 -0
  147. package/dist/ir/freeze.js +102 -0
  148. package/dist/ir/index.d.ts +9 -0
  149. package/dist/ir/index.d.ts.map +1 -0
  150. package/dist/ir/index.js +7 -0
  151. package/dist/ir/regexp.d.ts +6 -0
  152. package/dist/ir/regexp.d.ts.map +1 -0
  153. package/dist/ir/regexp.js +12 -0
  154. package/dist/ir/types.d.ts +215 -0
  155. package/dist/ir/types.d.ts.map +1 -0
  156. package/dist/ir/types.js +5 -0
  157. package/dist/ir/validate.d.ts +10 -0
  158. package/dist/ir/validate.d.ts.map +1 -0
  159. package/dist/ir/validate.js +271 -0
  160. package/dist/issue/index.d.ts +44 -0
  161. package/dist/issue/index.d.ts.map +1 -0
  162. package/dist/issue/index.js +152 -0
  163. package/dist/json-schema/emit-combinator.d.ts +28 -0
  164. package/dist/json-schema/emit-combinator.d.ts.map +1 -0
  165. package/dist/json-schema/emit-combinator.js +96 -0
  166. package/dist/json-schema/emit-composite.d.ts +28 -0
  167. package/dist/json-schema/emit-composite.d.ts.map +1 -0
  168. package/dist/json-schema/emit-composite.js +127 -0
  169. package/dist/json-schema/emit-scalar.d.ts +25 -0
  170. package/dist/json-schema/emit-scalar.d.ts.map +1 -0
  171. package/dist/json-schema/emit-scalar.js +104 -0
  172. package/dist/json-schema/emit-types.d.ts +12 -0
  173. package/dist/json-schema/emit-types.d.ts.map +1 -0
  174. package/dist/json-schema/emit-types.js +5 -0
  175. package/dist/json-schema/emit.d.ts +12 -0
  176. package/dist/json-schema/emit.d.ts.map +1 -0
  177. package/dist/json-schema/emit.js +62 -0
  178. package/dist/json-schema/freeze.d.ts +14 -0
  179. package/dist/json-schema/freeze.d.ts.map +1 -0
  180. package/dist/json-schema/freeze.js +114 -0
  181. package/dist/json-schema/index.d.ts +20 -0
  182. package/dist/json-schema/index.d.ts.map +1 -0
  183. package/dist/json-schema/index.js +76 -0
  184. package/dist/json-schema/issue.d.ts +11 -0
  185. package/dist/json-schema/issue.d.ts.map +1 -0
  186. package/dist/json-schema/issue.js +14 -0
  187. package/dist/json-schema/read.d.ts +29 -0
  188. package/dist/json-schema/read.d.ts.map +1 -0
  189. package/dist/json-schema/read.js +87 -0
  190. package/dist/json-schema/types.d.ts +106 -0
  191. package/dist/json-schema/types.d.ts.map +1 -0
  192. package/dist/json-schema/types.js +5 -0
  193. package/dist/kind/index.d.ts +119 -0
  194. package/dist/kind/index.d.ts.map +1 -0
  195. package/dist/kind/index.js +94 -0
  196. package/dist/lower/index.d.ts +7 -0
  197. package/dist/lower/index.d.ts.map +1 -0
  198. package/dist/lower/index.js +199 -0
  199. package/dist/message/index.d.ts +51 -0
  200. package/dist/message/index.d.ts.map +1 -0
  201. package/dist/message/index.js +269 -0
  202. package/dist/optimize/compact.d.ts +10 -0
  203. package/dist/optimize/compact.d.ts.map +1 -0
  204. package/dist/optimize/compact.js +60 -0
  205. package/dist/optimize/fold-boolean.d.ts +15 -0
  206. package/dist/optimize/fold-boolean.d.ts.map +1 -0
  207. package/dist/optimize/fold-boolean.js +75 -0
  208. package/dist/optimize/fold-common.d.ts +45 -0
  209. package/dist/optimize/fold-common.d.ts.map +1 -0
  210. package/dist/optimize/fold-common.js +71 -0
  211. package/dist/optimize/fold-scalar.d.ts +59 -0
  212. package/dist/optimize/fold-scalar.d.ts.map +1 -0
  213. package/dist/optimize/fold-scalar.js +174 -0
  214. package/dist/optimize/fold.d.ts +10 -0
  215. package/dist/optimize/fold.d.ts.map +1 -0
  216. package/dist/optimize/fold.js +103 -0
  217. package/dist/optimize/index.d.ts +10 -0
  218. package/dist/optimize/index.d.ts.map +1 -0
  219. package/dist/optimize/index.js +23 -0
  220. package/dist/optimize/map-node.d.ts +21 -0
  221. package/dist/optimize/map-node.d.ts.map +1 -0
  222. package/dist/optimize/map-node.js +222 -0
  223. package/dist/optimize/remap.d.ts +30 -0
  224. package/dist/optimize/remap.d.ts.map +1 -0
  225. package/dist/optimize/remap.js +46 -0
  226. package/dist/optimize/rewrite.d.ts +22 -0
  227. package/dist/optimize/rewrite.d.ts.map +1 -0
  228. package/dist/optimize/rewrite.js +34 -0
  229. package/dist/plan/cache.d.ts +20 -0
  230. package/dist/plan/cache.d.ts.map +1 -0
  231. package/dist/plan/cache.js +122 -0
  232. package/dist/plan/index.d.ts +8 -0
  233. package/dist/plan/index.d.ts.map +1 -0
  234. package/dist/plan/index.js +6 -0
  235. package/dist/plan/predicate.d.ts +27 -0
  236. package/dist/plan/predicate.d.ts.map +1 -0
  237. package/dist/plan/predicate.js +415 -0
  238. package/dist/plan/schema-predicate.d.ts +15 -0
  239. package/dist/plan/schema-predicate.d.ts.map +1 -0
  240. package/dist/plan/schema-predicate.js +277 -0
  241. package/dist/plan/types.d.ts +18 -0
  242. package/dist/plan/types.d.ts.map +1 -0
  243. package/dist/plan/types.js +5 -0
  244. package/dist/result/index.d.ts +27 -0
  245. package/dist/result/index.d.ts.map +1 -0
  246. package/dist/result/index.js +20 -0
  247. package/dist/schema/common.d.ts +30 -0
  248. package/dist/schema/common.d.ts.map +1 -0
  249. package/dist/schema/common.js +102 -0
  250. package/dist/schema/freeze.d.ts +10 -0
  251. package/dist/schema/freeze.d.ts.map +1 -0
  252. package/dist/schema/freeze.js +163 -0
  253. package/dist/schema/index.d.ts +11 -0
  254. package/dist/schema/index.d.ts.map +1 -0
  255. package/dist/schema/index.js +9 -0
  256. package/dist/schema/lazy.d.ts +10 -0
  257. package/dist/schema/lazy.d.ts.map +1 -0
  258. package/dist/schema/lazy.js +25 -0
  259. package/dist/schema/literal.d.ts +10 -0
  260. package/dist/schema/literal.d.ts.map +1 -0
  261. package/dist/schema/literal.js +17 -0
  262. package/dist/schema/types.d.ts +243 -0
  263. package/dist/schema/types.d.ts.map +1 -0
  264. package/dist/schema/types.js +9 -0
  265. package/dist/schema/validate.d.ts +10 -0
  266. package/dist/schema/validate.d.ts.map +1 -0
  267. package/dist/schema/validate.js +268 -0
  268. package/docs/api.md +301 -0
  269. package/docs/engine-notes.md +153 -0
  270. package/docs/index.html +1242 -0
  271. package/package.json +68 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compile/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,iBAAiB,EACjB,OAAO,EACR,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,wBAAwB,EACzB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,cAAc,EACd,aAAa,EACb,oBAAoB,EACrB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @file compile/index.ts
3
+ * @brief Public compile module barrel.
4
+ */
5
+ export { CompiledBaseGuard, compile } from "./guard.js";
6
+ export { emitCompiledSourceBundle } from "./source.js";
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @file compile/issue.ts
3
+ * @brief Diagnostic issue source snippets.
4
+ */
5
+ import type { EmitContext } from "./types.js";
6
+ /**
7
+ * @brief emit pattern issue.
8
+ */
9
+ export declare function emitPatternIssue(value: string, path: string, issues: string, regex: RegExp, name: string, context: EmitContext): string;
10
+ /**
11
+ * @brief emit issue.
12
+ */
13
+ export declare function emitIssue(issues: string, path: string, code: string, expected: string, actualExpression: string): string;
14
+ /**
15
+ * @brief emit issue expr.
16
+ */
17
+ export declare function emitIssueExpr(issues: string, path: string, code: string, expectedExpression: string, actualExpression: string): string;
18
+ //# sourceMappingURL=issue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue.d.ts","sourceRoot":"","sources":["../../src/compile/issue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,WAAW,GACnB,MAAM,CAWR;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAQR;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,kBAAkB,EAAE,MAAM,EAC1B,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAER"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @file compile/issue.ts
3
+ * @brief Diagnostic issue source snippets.
4
+ */
5
+ import { UUID_PATTERN } from "../schema/index.js";
6
+ import { pushRegex, stringRef } from "./context.js";
7
+ import { stringLiteral } from "./names.js";
8
+ /**
9
+ * @brief emit pattern issue.
10
+ */
11
+ export function emitPatternIssue(value, path, issues, regex, name, context) {
12
+ const source = regex === UUID_PATTERN ? UUID_PATTERN : regex;
13
+ const index = pushRegex(context, source);
14
+ const access = `r[${String(index)}]`;
15
+ return `if(((${access}.lastIndex=0),!${access}.test(${value}))){${emitIssueExpr(issues, path, "expected_pattern", stringRef(context, name), stringLiteral("string"))}}`;
16
+ }
17
+ /**
18
+ * @brief emit issue.
19
+ */
20
+ export function emitIssue(issues, path, code, expected, actualExpression) {
21
+ return emitIssueExpr(issues, path, code, stringLiteral(expected), actualExpression);
22
+ }
23
+ /**
24
+ * @brief emit issue expr.
25
+ */
26
+ export function emitIssueExpr(issues, path, code, expectedExpression, actualExpression) {
27
+ return `q(${issues},${path},${stringLiteral(code)},${expectedExpression},${actualExpression});`;
28
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @file compile-names.ts
3
+ * @brief Generated function-name and string literal helpers.
4
+ *
5
+ * @invariant User-provided names never enter generated source until they are
6
+ * reduced to a strict-mode-safe identifier with a fixed length bound.
7
+ */
8
+ /**
9
+ * @brief safe function name.
10
+ */
11
+ export declare function safeFunctionName(value: string): string;
12
+ /**
13
+ * @brief string literal.
14
+ */
15
+ export declare function stringLiteral(value: string): string;
16
+ //# sourceMappingURL=names.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../../src/compile/names.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAYtD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @file compile-names.ts
3
+ * @brief Generated function-name and string literal helpers.
4
+ *
5
+ * @invariant User-provided names never enter generated source until they are
6
+ * reduced to a strict-mode-safe identifier with a fixed length bound.
7
+ */
8
+ const MAX_GENERATED_FUNCTION_NAME_LENGTH = 96;
9
+ /**
10
+ * @brief safe function name.
11
+ */
12
+ export function safeFunctionName(value) {
13
+ const replaced = value.replace(/[^$_a-zA-Z0-9]/gu, "_");
14
+ const bounded = replaced.length > MAX_GENERATED_FUNCTION_NAME_LENGTH
15
+ ? replaced.slice(0, MAX_GENERATED_FUNCTION_NAME_LENGTH)
16
+ : replaced;
17
+ if (/^[$_a-zA-Z]/u.test(bounded) && !reservedFunctionNames.has(bounded)) {
18
+ return bounded;
19
+ }
20
+ const prefixed = `_${bounded}`;
21
+ return prefixed.length > MAX_GENERATED_FUNCTION_NAME_LENGTH
22
+ ? prefixed.slice(0, MAX_GENERATED_FUNCTION_NAME_LENGTH)
23
+ : prefixed;
24
+ }
25
+ /**
26
+ * @brief string literal.
27
+ */
28
+ export function stringLiteral(value) {
29
+ return JSON.stringify(value);
30
+ }
31
+ /**
32
+ * @brief reserved function names.
33
+ */
34
+ const reservedFunctionNames = new Set([
35
+ "arguments",
36
+ "await",
37
+ "break",
38
+ "ca" + "tch",
39
+ "class",
40
+ "const",
41
+ "continue",
42
+ "debugger",
43
+ "default",
44
+ "delete",
45
+ "do",
46
+ "else",
47
+ "enum",
48
+ "eval",
49
+ "export",
50
+ "extends",
51
+ "false",
52
+ "finally",
53
+ "for",
54
+ "function",
55
+ "if",
56
+ "implements",
57
+ "import",
58
+ "in",
59
+ "instanceof",
60
+ "interface",
61
+ "let",
62
+ "new",
63
+ "null",
64
+ "package",
65
+ "private",
66
+ "protected",
67
+ "public",
68
+ "return",
69
+ "static",
70
+ "super",
71
+ "switch",
72
+ "this",
73
+ "throw",
74
+ "true",
75
+ "tr" + "y",
76
+ "typeof",
77
+ "var",
78
+ "void",
79
+ "while",
80
+ "with",
81
+ "yield"
82
+ ]);
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @file compile/predicate.ts
3
+ * @brief Boolean validator source emitter.
4
+ */
5
+ import { type Schema } from "../schema/index.js";
6
+ import type { EmitContext } from "./types.js";
7
+ /**
8
+ * @brief emit function.
9
+ */
10
+ export declare function emitFunction(schema: Schema, context: EmitContext): string;
11
+ /**
12
+ * @brief emit functions.
13
+ */
14
+ export declare function emitFunctions(context: EmitContext): string;
15
+ /**
16
+ * @brief emit expression.
17
+ */
18
+ export declare function emitExpression(schema: Schema, value: string, context: EmitContext): string;
19
+ /**
20
+ * @brief emit union.
21
+ */
22
+ export declare function emitUnion(options: readonly Schema[], value: string, context: EmitContext): string;
23
+ //# sourceMappingURL=predicate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicate.d.ts","sourceRoot":"","sources":["../../src/compile/predicate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAGL,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAO5B,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,YAAY,CAAC;AAE9D;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAczE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAU1D;AAsBD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,WAAW,GACnB,MAAM,CA+CR;AA0PD;;GAEG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,WAAW,GACnB,MAAM,CAYR"}
@@ -0,0 +1,317 @@
1
+ /**
2
+ * @file compile/predicate.ts
3
+ * @brief Boolean validator source emitter.
4
+ */
5
+ import { NumberCheckTag, ObjectModeTag, PresenceTag, SchemaTag, StringCheckTag } from "../kind/index.js";
6
+ import { UUID_PATTERN } from "../schema/index.js";
7
+ import { pushLiteral, pushRegex, pushSchema, stringRef } from "./context.js";
8
+ /**
9
+ * @brief emit function.
10
+ */
11
+ export function emitFunction(schema, context) {
12
+ const cached = context.functionNames.get(schema);
13
+ if (cached !== undefined) {
14
+ return cached;
15
+ }
16
+ const name = `p${String(context.functions.length)}`;
17
+ const source = {
18
+ name,
19
+ body: ""
20
+ };
21
+ context.functionNames.set(schema, name);
22
+ context.functions.push(source);
23
+ source.body = emitBody(schema, "v", context);
24
+ return name;
25
+ }
26
+ /**
27
+ * @brief emit functions.
28
+ */
29
+ export function emitFunctions(context) {
30
+ const chunks = new Array(context.functions.length);
31
+ for (let index = 0; index < context.functions.length; index += 1) {
32
+ const source = context.functions[index];
33
+ if (source === undefined) {
34
+ continue;
35
+ }
36
+ chunks[index] = `function ${source.name}(v){${source.body}}`;
37
+ }
38
+ return chunks.join("");
39
+ }
40
+ /**
41
+ * @brief emit body.
42
+ */
43
+ function emitBody(schema, value, context) {
44
+ switch (schema.tag) {
45
+ case SchemaTag.Array:
46
+ return emitArrayBody(schema.item, value, context);
47
+ case SchemaTag.Tuple:
48
+ return emitTupleBody(schema.items, value, context);
49
+ case SchemaTag.Record:
50
+ return emitRecordBody(schema.value, value, context);
51
+ case SchemaTag.Object:
52
+ return emitObjectBody(schema, value, context);
53
+ case SchemaTag.DiscriminatedUnion:
54
+ return emitDiscriminatedUnionBody(schema.key, schema.cases, value, context);
55
+ default:
56
+ return `return ${emitExpression(schema, value, context)};`;
57
+ }
58
+ }
59
+ /**
60
+ * @brief emit expression.
61
+ */
62
+ export function emitExpression(schema, value, context) {
63
+ switch (schema.tag) {
64
+ case SchemaTag.Unknown:
65
+ return "true";
66
+ case SchemaTag.Never:
67
+ return "false";
68
+ case SchemaTag.String:
69
+ return emitString(schema, value, context);
70
+ case SchemaTag.Number:
71
+ return emitNumber(schema, value);
72
+ case SchemaTag.BigInt:
73
+ return `(typeof ${value}==="bigint")`;
74
+ case SchemaTag.Symbol:
75
+ return `(typeof ${value}==="symbol")`;
76
+ case SchemaTag.Boolean:
77
+ return `(typeof ${value}==="boolean")`;
78
+ case SchemaTag.Literal:
79
+ return `Object.is(${value},l[${String(pushLiteral(context, schema.value))}])`;
80
+ case SchemaTag.Array:
81
+ return `${emitFunction(schema, context)}(${value})`;
82
+ case SchemaTag.Tuple:
83
+ return `${emitFunction(schema, context)}(${value})`;
84
+ case SchemaTag.Record:
85
+ return `${emitFunction(schema, context)}(${value})`;
86
+ case SchemaTag.Object:
87
+ return `${emitFunction(schema, context)}(${value})`;
88
+ case SchemaTag.Union:
89
+ return emitUnion(schema.options, value, context);
90
+ case SchemaTag.Intersection:
91
+ return `(${emitExpression(schema.left, value, context)}&&${emitExpression(schema.right, value, context)})`;
92
+ case SchemaTag.Optional:
93
+ case SchemaTag.Undefinedable:
94
+ return `(${value}===undefined||${emitExpression(schema.inner, value, context)})`;
95
+ case SchemaTag.Nullable:
96
+ return `(${value}===null||${emitExpression(schema.inner, value, context)})`;
97
+ case SchemaTag.DiscriminatedUnion:
98
+ return `${emitFunction(schema, context)}(${value})`;
99
+ case SchemaTag.Brand:
100
+ return emitExpression(schema.inner, value, context);
101
+ case SchemaTag.Lazy:
102
+ case SchemaTag.Refine:
103
+ return `d(${String(pushSchema(context, schema))},${value})`;
104
+ }
105
+ }
106
+ /**
107
+ * @brief emit array body.
108
+ */
109
+ function emitArrayBody(item, value, context) {
110
+ const itemFunction = emitFunction(item, context);
111
+ return [
112
+ `if(!Array.isArray(${value}))return false;`,
113
+ `for(let i=0;i<${value}.length;i+=1){`,
114
+ `const d=gp(${value},i);`,
115
+ `if(d!==undefined&&!h.call(d,"value"))return false;`,
116
+ `if(!${itemFunction}(d===undefined?undefined:d.value))return false;`,
117
+ "}",
118
+ "return true;"
119
+ ].join("");
120
+ }
121
+ /**
122
+ * @brief emit record body.
123
+ */
124
+ function emitRecordBody(item, value, context) {
125
+ const itemFunction = emitFunction(item, context);
126
+ return [
127
+ `if(!o(${value}))return false;`,
128
+ `const ks=Object.keys(${value});`,
129
+ "for(let i=0;i<ks.length;i+=1){",
130
+ "const key=ks[i];",
131
+ `const d=key===undefined?undefined:gp(${value},key);`,
132
+ `if(d===undefined||!h.call(d,"value")||!${itemFunction}(d.value))return false;`,
133
+ "}",
134
+ "return true;"
135
+ ].join("");
136
+ }
137
+ /**
138
+ * @brief emit tuple body.
139
+ * @details Emits tuple validation as straight-line descriptor reads and early returns.
140
+ * @returns Generated tuple predicate body.
141
+ */
142
+ function emitTupleBody(items, value, context) {
143
+ const chunks = [
144
+ `if(!Array.isArray(${value})||${value}.length!==${String(items.length)})return false;`
145
+ ];
146
+ for (let index = 0; index < items.length; index += 1) {
147
+ const item = items[index];
148
+ if (item === undefined) {
149
+ continue;
150
+ }
151
+ const descriptor = `d${String(index)}`;
152
+ const itemValue = `v${String(index)}`;
153
+ chunks.push(`const ${descriptor}=gp(${value},${String(index)});`, `if(${descriptor}!==undefined&&!h.call(${descriptor},"value"))return false;`, `const ${itemValue}=${descriptor}===undefined?undefined:${descriptor}.value;`, `if(!${emitExpression(item, itemValue, context)})return false;`);
154
+ }
155
+ chunks.push("return true;");
156
+ return chunks.join("");
157
+ }
158
+ /**
159
+ * @brief emit object body.
160
+ * @details Emits object validation as Ajv-style straight-line code with local descriptor variables.
161
+ * @returns Generated object predicate body.
162
+ */
163
+ function emitObjectBody(schema, value, context) {
164
+ const chunks = [`if(!o(${value}))return false;`];
165
+ chunks.push(emitStrictObjectKeyBody(schema, value, context));
166
+ const entries = schema.entries;
167
+ for (let index = 0; index < entries.length; index += 1) {
168
+ const entry = entries[index];
169
+ if (entry === undefined) {
170
+ continue;
171
+ }
172
+ const key = stringRef(context, entry.key);
173
+ const descriptor = `d${String(index)}`;
174
+ const itemValue = `v${String(index)}`;
175
+ chunks.push(`const ${descriptor}=gp(${value},${key});`);
176
+ if (entry.presence === PresenceTag.Optional) {
177
+ chunks.push(`if(${descriptor}!==undefined){`, `if(!h.call(${descriptor},"value"))return false;`, `const ${itemValue}=${descriptor}.value;`, `if(!${emitExpression(entry.schema, itemValue, context)})return false;`, `}else if(h.call(${value},${key}))return false;`);
178
+ }
179
+ else {
180
+ chunks.push(`if(${descriptor}===undefined||!h.call(${descriptor},"value"))return false;`, `const ${itemValue}=${descriptor}.value;`, `if(!${emitExpression(entry.schema, itemValue, context)})return false;`);
181
+ }
182
+ }
183
+ chunks.push("return true;");
184
+ return chunks.join("");
185
+ }
186
+ /**
187
+ * @brief emit strict object key body.
188
+ * @details Emits a low-allocation known-key check specialized for one object shape.
189
+ * @returns Generated strict-key prelude, or an empty string for passthrough objects.
190
+ */
191
+ function emitStrictObjectKeyBody(schema, value, context) {
192
+ if (schema.mode !== ObjectModeTag.Strict) {
193
+ return "";
194
+ }
195
+ const entries = schema.entries;
196
+ const comparisons = [];
197
+ for (let index = 0; index < entries.length; index += 1) {
198
+ const entry = entries[index];
199
+ if (entry !== undefined) {
200
+ comparisons.push(`key!==${stringRef(context, entry.key)}`);
201
+ }
202
+ }
203
+ if (comparisons.length === 0) {
204
+ return `if(Reflect.ownKeys(${value}).length!==0)return false;`;
205
+ }
206
+ return [
207
+ `const xs=Reflect.ownKeys(${value});`,
208
+ "for(let i=0;i<xs.length;i+=1){",
209
+ "const key=xs[i];",
210
+ `if(typeof key!=="string"||(${comparisons.join("&&")}))return false;`,
211
+ "}"
212
+ ].join("");
213
+ }
214
+ /**
215
+ * @brief emit discriminated union body.
216
+ * @details Emits discriminant selection once and dispatches to branch validators.
217
+ * @returns Generated discriminated-union predicate body.
218
+ */
219
+ function emitDiscriminatedUnionBody(key, cases, value, context) {
220
+ const keyRef = stringRef(context, key);
221
+ const chunks = [
222
+ `if(!o(${value}))return false;`,
223
+ `const d=gp(${value},${keyRef});`,
224
+ `if(d===undefined||!h.call(d,"value"))return false;`,
225
+ "const dv=d.value;",
226
+ `if(typeof dv!=="string")return false;`
227
+ ];
228
+ for (let index = 0; index < cases.length; index += 1) {
229
+ const unionCase = cases[index];
230
+ if (unionCase === undefined) {
231
+ continue;
232
+ }
233
+ chunks.push(`if(Object.is(dv,l[${String(pushLiteral(context, unionCase.literal))}]))return ${emitExpression(unionCase.schema, value, context)};`);
234
+ }
235
+ chunks.push("return false;");
236
+ return chunks.join("");
237
+ }
238
+ /**
239
+ * @brief emit string.
240
+ */
241
+ function emitString(schema, value, context) {
242
+ const parts = [`(typeof ${value}==="string")`];
243
+ const checks = schema.checks;
244
+ for (let index = 0; index < checks.length; index += 1) {
245
+ const check = checks[index];
246
+ if (check === undefined) {
247
+ continue;
248
+ }
249
+ switch (check.tag) {
250
+ case StringCheckTag.Min:
251
+ parts.push(`(${value}.length>=${String(check.value)})`);
252
+ break;
253
+ case StringCheckTag.Max:
254
+ parts.push(`(${value}.length<=${String(check.value)})`);
255
+ break;
256
+ case StringCheckTag.Regex:
257
+ parts.push(emitRegex(value, check.regex, context));
258
+ break;
259
+ case StringCheckTag.Uuid:
260
+ parts.push(emitRegex(value, UUID_PATTERN, context));
261
+ break;
262
+ }
263
+ }
264
+ return `(${parts.join("&&")})`;
265
+ }
266
+ /**
267
+ * @brief emit number.
268
+ */
269
+ function emitNumber(schema, value) {
270
+ const parts = [
271
+ `(typeof ${value}==="number")`,
272
+ `Number.isFinite(${value})`
273
+ ];
274
+ const checks = schema.checks;
275
+ for (let index = 0; index < checks.length; index += 1) {
276
+ const check = checks[index];
277
+ if (check === undefined) {
278
+ continue;
279
+ }
280
+ switch (check.tag) {
281
+ case NumberCheckTag.Integer:
282
+ parts.push(`Number.isInteger(${value})`);
283
+ break;
284
+ case NumberCheckTag.Gte:
285
+ parts.push(`(${value}>=${String(check.value)})`);
286
+ break;
287
+ case NumberCheckTag.Lte:
288
+ parts.push(`(${value}<=${String(check.value)})`);
289
+ break;
290
+ }
291
+ }
292
+ return `(${parts.join("&&")})`;
293
+ }
294
+ /**
295
+ * @brief emit union.
296
+ */
297
+ export function emitUnion(options, value, context) {
298
+ const parts = [];
299
+ for (let index = 0; index < options.length; index += 1) {
300
+ const option = options[index];
301
+ if (option !== undefined) {
302
+ parts.push(emitExpression(option, value, context));
303
+ }
304
+ }
305
+ if (parts.length === 0) {
306
+ return "false";
307
+ }
308
+ return `(${parts.join("||")})`;
309
+ }
310
+ /**
311
+ * @brief emit regex.
312
+ */
313
+ function emitRegex(value, regex, context) {
314
+ const index = pushRegex(context, regex);
315
+ const access = `r[${String(index)}]`;
316
+ return `((${access}.lastIndex=0),${access}.test(${value}))`;
317
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @file compile-runtime.ts
3
+ * @brief Runtime support passed into generated validator factories.
4
+ *
5
+ * @section side_tables Side-table ABI
6
+ * Generated validators receive literals, regexps, keysets, strings, and
7
+ * dynamic schema fallbacks as indexed tables. The emitted source contains only
8
+ * numeric table slots and compact helper names.
9
+ */
10
+ import type { Issue, PathSegment } from "../issue/index.js";
11
+ import type { LiteralValue, Schema } from "../schema/index.js";
12
+ /**
13
+ * @brief boolean predicate.
14
+ */
15
+ export type BooleanPredicate = (value: unknown) => boolean;
16
+ /**
17
+ * @brief issue collector root.
18
+ */
19
+ export type IssueCollectorRoot = (value: unknown) => readonly Issue[];
20
+ /**
21
+ * @brief dynamic check.
22
+ */
23
+ export type DynamicCheck = (schemaIndex: number, value: unknown) => boolean;
24
+ /**
25
+ * @brief dynamic issue check.
26
+ */
27
+ export type DynamicIssueCheck = (schemaIndex: number, value: unknown, path: readonly PathSegment[], issues: Issue[]) => void;
28
+ /**
29
+ * @brief strict keys check.
30
+ */
31
+ export type StrictKeysCheck = (value: unknown, keys: readonly string[]) => boolean;
32
+ /**
33
+ * @brief runtime bundle.
34
+ */
35
+ export interface RuntimeBundle {
36
+ readonly is: BooleanPredicate;
37
+ readonly check: IssueCollectorRoot;
38
+ }
39
+ /**
40
+ * @brief is factory.
41
+ */
42
+ export type IsFactory = (literals: readonly LiteralValue[], regexps: readonly RegExp[], keysets: readonly (readonly string[])[], strings: readonly string[], dynamicCheck: DynamicCheck, dynamicIssueCheck: DynamicIssueCheck, strictKeys: StrictKeysCheck) => RuntimeBundle;
43
+ /**
44
+ * @brief make dynamic check.
45
+ */
46
+ export declare function makeDynamicCheck(schemas: readonly Schema[]): DynamicCheck;
47
+ /**
48
+ * @brief make dynamic issue check.
49
+ */
50
+ export declare function makeDynamicIssueCheck(schemas: readonly Schema[]): DynamicIssueCheck;
51
+ /**
52
+ * @brief strict keys.
53
+ */
54
+ export declare function strictKeys(value: unknown, keys: readonly string[]): boolean;
55
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/compile/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,SAAS,KAAK,EAAE,CAAC;AAEtE;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,SAAS,WAAW,EAAE,EAC5B,MAAM,EAAE,KAAK,EAAE,KACZ,IAAI,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,SAAS,MAAM,EAAE,KACpB,OAAO,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,gBAAgB,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,CACtB,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,OAAO,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EACvC,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,YAAY,EAAE,YAAY,EAC1B,iBAAiB,EAAE,iBAAiB,EACpC,UAAU,EAAE,eAAe,KACxB,aAAa,CAAC;AAEnB;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,YAAY,CAKzE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,iBAAiB,CA6BnB;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB,OAAO,CAYT"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @file compile-runtime.ts
3
+ * @brief Runtime support passed into generated validator factories.
4
+ *
5
+ * @section side_tables Side-table ABI
6
+ * Generated validators receive literals, regexps, keysets, strings, and
7
+ * dynamic schema fallbacks as indexed tables. The emitted source contains only
8
+ * numeric table slots and compact helper names.
9
+ */
10
+ import { checkSchema, isSchema } from "../evaluate/index.js";
11
+ /**
12
+ * @brief make dynamic check.
13
+ */
14
+ export function makeDynamicCheck(schemas) {
15
+ return (schemaIndex, value) => {
16
+ const schema = schemas[schemaIndex];
17
+ return schema !== undefined && isSchema(schema, value);
18
+ };
19
+ }
20
+ /**
21
+ * @brief make dynamic issue check.
22
+ */
23
+ export function makeDynamicIssueCheck(schemas) {
24
+ return (schemaIndex, value, path, issues) => {
25
+ const schema = schemas[schemaIndex];
26
+ if (schema === undefined) {
27
+ return;
28
+ }
29
+ const result = checkSchema(schema, value);
30
+ if (result.ok) {
31
+ return;
32
+ }
33
+ const nested = result.error;
34
+ for (let index = 0; index < nested.length; index += 1) {
35
+ const issue = nested[index];
36
+ if (issue !== undefined) {
37
+ issues.push({
38
+ path: path.concat(issue.path),
39
+ code: issue.code,
40
+ expected: issue.expected,
41
+ actual: issue.actual,
42
+ message: issue.message
43
+ });
44
+ }
45
+ }
46
+ };
47
+ }
48
+ /**
49
+ * @brief strict keys.
50
+ */
51
+ export function strictKeys(value, keys) {
52
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
53
+ return false;
54
+ }
55
+ const present = Reflect.ownKeys(value);
56
+ for (let index = 0; index < present.length; index += 1) {
57
+ const key = present[index];
58
+ if (typeof key !== "string" || !keys.includes(key)) {
59
+ return false;
60
+ }
61
+ }
62
+ return true;
63
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @file compile/source.ts
3
+ * @brief Generated validator source bundle assembly.
4
+ */
5
+ import type { Schema } from "../schema/index.js";
6
+ import type { CompiledSourceBundle } from "./types.js";
7
+ /**
8
+ * @brief emit compiled source bundle.
9
+ */
10
+ export declare function emitCompiledSourceBundle(schema: Schema, name: string): CompiledSourceBundle;
11
+ //# sourceMappingURL=source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/compile/source.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAKjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX,oBAAoB,CAuCtB"}