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,25 +1,48 @@
1
1
  /**
2
2
  * @file emit-scalar.ts
3
3
  * @brief Scalar TypeSea schema to JSON Schema emitters.
4
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
5
+ * report a structured export issue.
4
6
  */
5
7
  import { SchemaTag } from "../kind/index.js";
6
8
  import type { PathSegment } from "../issue/index.js";
7
9
  import { type LiteralValue, type Schema } from "../schema/index.js";
8
10
  import type { JsonSchema, JsonSchemaExportIssue } from "./types.js";
9
11
  /**
10
- * @brief emit string.
12
+ * @brief Emit TypeSea string checks into JSON Schema string keywords.
13
+ * @details Repeated min and max checks collapse to the strongest bounds.
14
+ * Regular expressions are emitted only when their flags can be preserved by the
15
+ * JSON Schema `pattern` keyword; unsupported flags are reported as issues.
16
+ * @param schema String schema to emit.
17
+ * @param path Mutable issue path stack owned by the export walk.
18
+ * @param issues Mutable export issue buffer.
19
+ * @returns JSON Schema string object.
11
20
  */
12
21
  export declare function emitString(schema: Extract<Schema, {
13
22
  readonly tag: typeof SchemaTag.String;
14
23
  }>, path: PathSegment[], issues: JsonSchemaExportIssue[]): JsonSchema;
15
24
  /**
16
- * @brief emit number.
25
+ * @brief Emit TypeSea number checks into JSON Schema number keywords.
26
+ * @details Integer checks narrow the emitted type, while finite lower and upper
27
+ * bounds collapse to the strongest minimum and maximum. Non-finite bounds are
28
+ * rejected because JSON Schema cannot preserve them portably.
29
+ * @param schema Number schema to emit.
30
+ * @param path Mutable issue path stack owned by the export walk.
31
+ * @param issues Mutable export issue buffer.
32
+ * @returns JSON Schema number object, or undefined when bounds are unsupported.
17
33
  */
18
34
  export declare function emitNumber(schema: Extract<Schema, {
19
35
  readonly tag: typeof SchemaTag.Number;
20
36
  }>, path: PathSegment[], issues: JsonSchemaExportIssue[]): JsonSchema | undefined;
21
37
  /**
22
- * @brief emit literal.
38
+ * @brief Emit a literal schema as a JSON Schema `const` value.
39
+ * @details Only JSON-compatible literals are accepted. Undefined, bigint,
40
+ * symbol, NaN, infinity, and negative zero have no faithful JSON Schema literal
41
+ * encoding, so they become export issues instead of weakened output.
42
+ * @param value Literal value carried by the TypeSea schema.
43
+ * @param path Mutable issue path stack owned by the export walk.
44
+ * @param issues Mutable export issue buffer.
45
+ * @returns JSON Schema const object, or undefined for unsupported literals.
23
46
  */
24
47
  export declare function emitLiteral(value: LiteralValue, path: PathSegment[], issues: JsonSchemaExportIssue[]): JsonSchema | undefined;
25
48
  //# sourceMappingURL=emit-scalar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"emit-scalar.d.ts","sourceRoot":"","sources":["../../src/json-schema/emit-scalar.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEL,SAAS,EAEV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACV,UAAU,EACV,qBAAqB,EAEtB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,MAAM,CAAA;CAAE,CAAC,EAClE,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,GAC9B,UAAU,CAkCZ;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,MAAM,CAAA;CAAE,CAAC,EAClE,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,GAC9B,UAAU,GAAG,SAAS,CAiCxB;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,GAC9B,UAAU,GAAG,SAAS,CAyBxB"}
1
+ {"version":3,"file":"emit-scalar.d.ts","sourceRoot":"","sources":["../../src/json-schema/emit-scalar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEH,SAAS,EAEZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAMH,KAAK,YAAY,EACjB,KAAK,MAAM,EACd,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACR,UAAU,EACV,qBAAqB,EAExB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACtB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,MAAM,CAAA;CAAE,CAAC,EAClE,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,GAChC,UAAU,CAiEZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACtB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,MAAM,CAAA;CAAE,CAAC,EAClE,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,GAChC,UAAU,GAAG,SAAS,CA8DxB;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACvB,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,GAChC,UAAU,GAAG,SAAS,CAyBxB"}
@@ -1,15 +1,25 @@
1
1
  /**
2
2
  * @file emit-scalar.ts
3
3
  * @brief Scalar TypeSea schema to JSON Schema emitters.
4
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
5
+ * report a structured export issue.
4
6
  */
5
7
  import { NumberCheckTag, SchemaTag, StringCheckTag } from "../kind/index.js";
6
- import { UUID_PATTERN } from "../schema/index.js";
8
+ import { IPV4_PATTERN, IPV6_PATTERN, ISO_DATETIME_PATTERN, ISO_DATE_PATTERN, UUID_PATTERN } from "../schema/index.js";
7
9
  import { pushJsonSchemaIssue } from "./issue.js";
8
10
  /**
9
- * @brief emit string.
11
+ * @brief Emit TypeSea string checks into JSON Schema string keywords.
12
+ * @details Repeated min and max checks collapse to the strongest bounds.
13
+ * Regular expressions are emitted only when their flags can be preserved by the
14
+ * JSON Schema `pattern` keyword; unsupported flags are reported as issues.
15
+ * @param schema String schema to emit.
16
+ * @param path Mutable issue path stack owned by the export walk.
17
+ * @param issues Mutable export issue buffer.
18
+ * @returns JSON Schema string object.
10
19
  */
11
20
  export function emitString(schema, path, issues) {
12
21
  const result = { type: "string" };
22
+ const patterns = [];
13
23
  const checks = schema.checks;
14
24
  for (let index = 0; index < checks.length; index += 1) {
15
25
  const check = checks[index];
@@ -18,29 +28,66 @@ export function emitString(schema, path, issues) {
18
28
  }
19
29
  switch (check.tag) {
20
30
  case StringCheckTag.Min:
21
- result.minLength = check.value;
31
+ result.minLength = result.minLength === undefined
32
+ ? check.value
33
+ : Math.max(result.minLength, check.value);
22
34
  break;
23
35
  case StringCheckTag.Max:
24
- result.maxLength = check.value;
36
+ result.maxLength = result.maxLength === undefined
37
+ ? check.value
38
+ : Math.min(result.maxLength, check.value);
25
39
  break;
26
40
  case StringCheckTag.Regex:
27
41
  if (check.regex.flags.length !== 0) {
28
42
  pushJsonSchemaIssue(path, issues, "unsupported_regex_flags", "JSON Schema pattern cannot preserve RegExp flags");
29
43
  }
30
44
  else {
31
- result.pattern = check.regex.source;
45
+ patterns.push(check.regex.source);
32
46
  }
33
47
  break;
34
48
  case StringCheckTag.Uuid:
35
49
  result.format = "uuid";
36
- result.pattern = UUID_PATTERN.source;
50
+ patterns.push(UUID_PATTERN.source);
51
+ break;
52
+ case StringCheckTag.Email:
53
+ result.format = "email";
54
+ break;
55
+ case StringCheckTag.Url:
56
+ result.format = "uri";
57
+ break;
58
+ case StringCheckTag.IsoDate:
59
+ result.format = "date";
60
+ patterns.push(ISO_DATE_PATTERN.source);
61
+ break;
62
+ case StringCheckTag.IsoDateTime:
63
+ result.format = "date-time";
64
+ patterns.push(ISO_DATETIME_PATTERN.source);
65
+ break;
66
+ case StringCheckTag.Ulid:
67
+ patterns.push("^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$");
68
+ break;
69
+ case StringCheckTag.Ipv4:
70
+ result.format = "ipv4";
71
+ patterns.push(IPV4_PATTERN.source);
72
+ break;
73
+ case StringCheckTag.Ipv6:
74
+ result.format = "ipv6";
75
+ patterns.push(IPV6_PATTERN.source);
37
76
  break;
38
77
  }
39
78
  }
79
+ appendStringPatterns(result, patterns);
40
80
  return result;
41
81
  }
42
82
  /**
43
- * @brief emit number.
83
+ * @brief Emit TypeSea number checks into JSON Schema number keywords.
84
+ * @details Integer checks narrow the emitted type, while finite lower and upper
85
+ * bounds collapse to the strongest minimum and maximum. Non-finite bounds are
86
+ * rejected because JSON Schema cannot preserve them portably.
87
+ * @param schema Number schema to emit.
88
+ * @param path Mutable issue path stack owned by the export walk.
89
+ * @param issues Mutable export issue buffer.
90
+ * @returns JSON Schema number object, or undefined when bounds are unsupported.
44
91
  */
45
92
  export function emitNumber(schema, path, issues) {
46
93
  const before = issues.length;
@@ -60,7 +107,9 @@ export function emitNumber(schema, path, issues) {
60
107
  pushJsonSchemaIssue(path, issues, "unsupported_number_bound", "Number bounds must be finite");
61
108
  }
62
109
  else {
63
- result.minimum = check.value;
110
+ result.minimum = result.minimum === undefined
111
+ ? check.value
112
+ : Math.max(result.minimum, check.value);
64
113
  }
65
114
  break;
66
115
  case NumberCheckTag.Lte:
@@ -68,7 +117,37 @@ export function emitNumber(schema, path, issues) {
68
117
  pushJsonSchemaIssue(path, issues, "unsupported_number_bound", "Number bounds must be finite");
69
118
  }
70
119
  else {
71
- result.maximum = check.value;
120
+ result.maximum = result.maximum === undefined
121
+ ? check.value
122
+ : Math.min(result.maximum, check.value);
123
+ }
124
+ break;
125
+ case NumberCheckTag.Gt:
126
+ if (!Number.isFinite(check.value)) {
127
+ pushJsonSchemaIssue(path, issues, "unsupported_number_bound", "Number bounds must be finite");
128
+ }
129
+ else {
130
+ result.exclusiveMinimum = result.exclusiveMinimum === undefined
131
+ ? check.value
132
+ : Math.max(result.exclusiveMinimum, check.value);
133
+ }
134
+ break;
135
+ case NumberCheckTag.Lt:
136
+ if (!Number.isFinite(check.value)) {
137
+ pushJsonSchemaIssue(path, issues, "unsupported_number_bound", "Number bounds must be finite");
138
+ }
139
+ else {
140
+ result.exclusiveMaximum = result.exclusiveMaximum === undefined
141
+ ? check.value
142
+ : Math.min(result.exclusiveMaximum, check.value);
143
+ }
144
+ break;
145
+ case NumberCheckTag.MultipleOf:
146
+ if (!Number.isFinite(check.value) || check.value <= 0) {
147
+ pushJsonSchemaIssue(path, issues, "unsupported_number_bound", "multipleOf must be positive and finite");
148
+ }
149
+ else {
150
+ result.multipleOf = result.multipleOf ?? check.value;
72
151
  }
73
152
  break;
74
153
  }
@@ -79,7 +158,14 @@ export function emitNumber(schema, path, issues) {
79
158
  return result;
80
159
  }
81
160
  /**
82
- * @brief emit literal.
161
+ * @brief Emit a literal schema as a JSON Schema `const` value.
162
+ * @details Only JSON-compatible literals are accepted. Undefined, bigint,
163
+ * symbol, NaN, infinity, and negative zero have no faithful JSON Schema literal
164
+ * encoding, so they become export issues instead of weakened output.
165
+ * @param value Literal value carried by the TypeSea schema.
166
+ * @param path Mutable issue path stack owned by the export walk.
167
+ * @param issues Mutable export issue buffer.
168
+ * @returns JSON Schema const object, or undefined for unsupported literals.
83
169
  */
84
170
  export function emitLiteral(value, path, issues) {
85
171
  if (value === undefined) {
@@ -102,3 +188,31 @@ export function emitLiteral(value, path, issues) {
102
188
  }
103
189
  return { const: value };
104
190
  }
191
+ /**
192
+ * @brief Append JSON Schema pattern constraints without weakening repeated checks.
193
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
194
+ * report a structured export issue.
195
+ * @param result Mutable string schema output.
196
+ * @param patterns Ordered TypeSea pattern sources.
197
+ * @post One pattern stays inline; multiple patterns become an `allOf` chain.
198
+ */
199
+ function appendStringPatterns(result, patterns) {
200
+ if (patterns.length === 0) {
201
+ return;
202
+ }
203
+ if (patterns.length === 1) {
204
+ const pattern = patterns[0];
205
+ if (pattern !== undefined) {
206
+ result.pattern = pattern;
207
+ }
208
+ return;
209
+ }
210
+ const schemas = new Array(patterns.length);
211
+ for (let index = 0; index < patterns.length; index += 1) {
212
+ const pattern = patterns[index];
213
+ if (pattern !== undefined) {
214
+ schemas[index] = { pattern };
215
+ }
216
+ }
217
+ result.allOf = schemas;
218
+ }
@@ -1,12 +1,22 @@
1
1
  /**
2
2
  * @file emit-types.ts
3
3
  * @brief Internal JSON Schema emitter contracts.
4
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
5
+ * report a structured export issue.
4
6
  */
5
7
  import type { PathSegment } from "../issue/index.js";
6
8
  import type { Schema } from "../schema/index.js";
7
9
  import type { JsonSchema, JsonSchemaDialect, JsonSchemaExportIssue } from "./types.js";
8
10
  /**
9
- * @brief json schema emitter.
11
+ * @brief Recursive emitter callback shared by JSON Schema emitter modules.
12
+ * @details Child emitters receive the same path stack and issue buffer as their
13
+ * parent, which avoids allocating intermediate diagnostic collections during a
14
+ * deep schema walk.
15
+ * @param schema Schema node to convert.
16
+ * @param path Mutable issue path stack owned by the export walk.
17
+ * @param issues Mutable export issue buffer.
18
+ * @param dialect Target JSON Schema dialect.
19
+ * @returns JSON Schema fragment, boolean schema, or undefined on failure.
10
20
  */
11
21
  export type JsonSchemaEmitter = (schema: Schema, path: PathSegment[], issues: JsonSchemaExportIssue[], dialect: JsonSchemaDialect) => JsonSchema | undefined;
12
22
  //# sourceMappingURL=emit-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"emit-types.d.ts","sourceRoot":"","sources":["../../src/json-schema/emit-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,OAAO,EAAE,iBAAiB,KACvB,UAAU,GAAG,SAAS,CAAC"}
1
+ {"version":3,"file":"emit-types.d.ts","sourceRoot":"","sources":["../../src/json-schema/emit-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EACR,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACxB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC5B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,OAAO,EAAE,iBAAiB,KACzB,UAAU,GAAG,SAAS,CAAC"}
@@ -1,5 +1,7 @@
1
1
  /**
2
2
  * @file emit-types.ts
3
3
  * @brief Internal JSON Schema emitter contracts.
4
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
5
+ * report a structured export issue.
4
6
  */
5
7
  export {};
@@ -1,12 +1,23 @@
1
1
  /**
2
2
  * @file emit.ts
3
3
  * @brief TypeSea schema to JSON Schema emitter dispatcher.
4
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
5
+ * report a structured export issue.
4
6
  */
5
7
  import type { PathSegment } from "../issue/index.js";
6
8
  import type { Schema } from "../schema/index.js";
7
9
  import type { JsonSchema, JsonSchemaDialect, JsonSchemaExportIssue } from "./types.js";
8
10
  /**
9
- * @brief emit schema.
11
+ * @brief Dispatch one TypeSea schema node to the matching JSON Schema emitter.
12
+ * @details Unsupported runtime-only features are reported as structured export
13
+ * issues instead of being erased. That fail-closed policy prevents the exporter
14
+ * from producing a schema that appears equivalent while accepting a different
15
+ * value set.
16
+ * @param schema Schema node currently being emitted.
17
+ * @param path Mutable issue path stack owned by the export walk.
18
+ * @param issues Mutable export issue buffer.
19
+ * @param dialect Target JSON Schema dialect.
20
+ * @returns JSON Schema fragment, boolean schema, or undefined on failure.
10
21
  */
11
22
  export declare function emitSchema(schema: Schema, path: PathSegment[], issues: JsonSchemaExportIssue[], dialect: JsonSchemaDialect): JsonSchema | undefined;
12
23
  //# sourceMappingURL=emit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/json-schema/emit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAmBjD,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,OAAO,EAAE,iBAAiB,GACzB,UAAU,GAAG,SAAS,CA2DxB"}
1
+ {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/json-schema/emit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAmBjD,OAAO,KAAK,EACR,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACxB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,OAAO,EAAE,iBAAiB,GAC3B,UAAU,GAAG,SAAS,CAyExB"}
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file emit.ts
3
3
  * @brief TypeSea schema to JSON Schema emitter dispatcher.
4
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
5
+ * report a structured export issue.
4
6
  */
5
7
  import { SchemaTag } from "../kind/index.js";
6
8
  import { emitDiscriminatedUnion, emitIntersection, emitNullable, emitUnion } from "./emit-combinator.js";
@@ -8,7 +10,16 @@ import { emitArray, emitObject, emitRecord, emitTuple } from "./emit-composite.j
8
10
  import { emitLiteral, emitNumber, emitString } from "./emit-scalar.js";
9
11
  import { pushJsonSchemaIssue } from "./issue.js";
10
12
  /**
11
- * @brief emit schema.
13
+ * @brief Dispatch one TypeSea schema node to the matching JSON Schema emitter.
14
+ * @details Unsupported runtime-only features are reported as structured export
15
+ * issues instead of being erased. That fail-closed policy prevents the exporter
16
+ * from producing a schema that appears equivalent while accepting a different
17
+ * value set.
18
+ * @param schema Schema node currently being emitted.
19
+ * @param path Mutable issue path stack owned by the export walk.
20
+ * @param issues Mutable export issue buffer.
21
+ * @param dialect Target JSON Schema dialect.
22
+ * @returns JSON Schema fragment, boolean schema, or undefined on failure.
12
23
  */
13
24
  export function emitSchema(schema, path, issues, dialect) {
14
25
  switch (schema.tag) {
@@ -20,6 +31,9 @@ export function emitSchema(schema, path, issues, dialect) {
20
31
  return emitString(schema, path, issues);
21
32
  case SchemaTag.Number:
22
33
  return emitNumber(schema, path, issues);
34
+ case SchemaTag.Date:
35
+ pushJsonSchemaIssue(path, issues, "unsupported_date", "JSON Schema cannot represent JavaScript Date objects");
36
+ return undefined;
23
37
  case SchemaTag.BigInt:
24
38
  pushJsonSchemaIssue(path, issues, "unsupported_bigint", "JSON Schema has no bigint type");
25
39
  return undefined;
@@ -31,11 +45,17 @@ export function emitSchema(schema, path, issues, dialect) {
31
45
  case SchemaTag.Literal:
32
46
  return emitLiteral(schema.value, path, issues);
33
47
  case SchemaTag.Array:
34
- return emitArray(schema.item, path, issues, emitSchema, dialect);
48
+ return emitArray(schema, path, issues, emitSchema, dialect);
35
49
  case SchemaTag.Tuple:
36
- return emitTuple(schema.items, path, issues, emitSchema, dialect);
50
+ return emitTuple(schema, path, issues, emitSchema, dialect);
37
51
  case SchemaTag.Record:
38
52
  return emitRecord(schema.value, path, issues, emitSchema, dialect);
53
+ case SchemaTag.Map:
54
+ case SchemaTag.Set:
55
+ case SchemaTag.InstanceOf:
56
+ case SchemaTag.Property:
57
+ pushJsonSchemaIssue(path, issues, "unsupported_runtime_object", "JSON Schema cannot preserve this JavaScript runtime object contract");
58
+ return undefined;
39
59
  case SchemaTag.Object:
40
60
  return emitObject(schema, path, issues, emitSchema, dialect);
41
61
  case SchemaTag.Union:
@@ -1,14 +1,25 @@
1
1
  /**
2
2
  * @file freeze.ts
3
3
  * @brief Immutable JSON Schema export results.
4
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
5
+ * report a structured export issue.
4
6
  */
5
7
  import type { JsonSchema, JsonSchemaExportIssue } from "./types.js";
6
8
  /**
7
- * @brief freeze json schema.
9
+ * @brief Deep-freeze a JSON Schema export result before publication.
10
+ * @details Exported schemas may be shared across framework adapters. Freezing
11
+ * prevents later mutation from changing validation semantics after a schema was
12
+ * handed to another subsystem.
13
+ * @param schema JSON Schema fragment or boolean schema.
14
+ * @returns The same schema value after recursive hardening.
8
15
  */
9
16
  export declare function freezeJsonSchema(schema: JsonSchema): JsonSchema;
10
17
  /**
11
- * @brief freeze json schema issues.
18
+ * @brief Freeze JSON Schema export issues and their path arrays.
19
+ * @details Paths are mutable during traversal for stack efficiency, then frozen
20
+ * at the boundary so callers cannot rewrite diagnostic locations later.
21
+ * @param issues Export issues collected during emission.
22
+ * @returns The same issue array after recursive hardening.
12
23
  */
13
24
  export declare function freezeJsonSchemaIssues(issues: readonly JsonSchemaExportIssue[]): readonly JsonSchemaExportIssue[];
14
25
  //# sourceMappingURL=freeze.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"freeze.d.ts","sourceRoot":"","sources":["../../src/json-schema/freeze.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,qBAAqB,EAEtB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAK/D;AA8GD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,qBAAqB,EAAE,GACvC,SAAS,qBAAqB,EAAE,CASlC"}
1
+ {"version":3,"file":"freeze.d.ts","sourceRoot":"","sources":["../../src/json-schema/freeze.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACR,UAAU,EACV,qBAAqB,EAExB,MAAM,YAAY,CAAC;AAEpB;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAK/D;AAoID;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAClC,MAAM,EAAE,SAAS,qBAAqB,EAAE,GACzC,SAAS,qBAAqB,EAAE,CASlC"}
@@ -1,9 +1,16 @@
1
1
  /**
2
2
  * @file freeze.ts
3
3
  * @brief Immutable JSON Schema export results.
4
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
5
+ * report a structured export issue.
4
6
  */
5
7
  /**
6
- * @brief freeze json schema.
8
+ * @brief Deep-freeze a JSON Schema export result before publication.
9
+ * @details Exported schemas may be shared across framework adapters. Freezing
10
+ * prevents later mutation from changing validation semantics after a schema was
11
+ * handed to another subsystem.
12
+ * @param schema JSON Schema fragment or boolean schema.
13
+ * @returns The same schema value after recursive hardening.
7
14
  */
8
15
  export function freezeJsonSchema(schema) {
9
16
  if (typeof schema === "boolean") {
@@ -12,7 +19,13 @@ export function freezeJsonSchema(schema) {
12
19
  return freezeJsonSchemaInner(schema, new WeakSet());
13
20
  }
14
21
  /**
15
- * @brief freeze json schema inner.
22
+ * @brief Recursively freeze one object-shaped JSON Schema fragment.
23
+ * @details A WeakSet protects against repeated references introduced by callers
24
+ * or future emitters. Current emission is tree-shaped, but this guard keeps the
25
+ * hardener robust at the module boundary.
26
+ * @param schema Object-shaped JSON Schema fragment.
27
+ * @param frozen Objects already processed by this hardening walk.
28
+ * @returns The same object after nested values are frozen.
16
29
  */
17
30
  function freezeJsonSchemaInner(schema, frozen) {
18
31
  if (frozen.has(schema)) {
@@ -52,8 +65,12 @@ function freezeJsonSchemaInner(schema, frozen) {
52
65
  return Object.freeze(schema);
53
66
  }
54
67
  /**
55
- * @brief freeze json schema items.
56
- * @details Handles both homogeneous `items` schemas and draft-07 tuple item arrays.
68
+ * @brief Freeze the dialect-dependent `items` payload.
69
+ * @details Draft-07 tuple output stores an array under `items`, while newer
70
+ * dialects use object-shaped homogeneous item schemas. Both representations are
71
+ * hardened here before the parent schema is frozen.
72
+ * @param items JSON Schema `items` payload to harden.
73
+ * @param frozen Objects already processed by this hardening walk.
57
74
  */
58
75
  function freezeJsonSchemaItems(items, frozen) {
59
76
  if (Array.isArray(items)) {
@@ -64,7 +81,11 @@ function freezeJsonSchemaItems(items, frozen) {
64
81
  freezeJsonSchemaValue(schema, frozen);
65
82
  }
66
83
  /**
67
- * @brief freeze json schema value.
84
+ * @brief Freeze one nested JSON Schema value when it is object-shaped.
85
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
86
+ * report a structured export issue.
87
+ * @param schema Boolean or object-shaped JSON Schema fragment.
88
+ * @param frozen Objects already processed by this hardening walk.
68
89
  */
69
90
  function freezeJsonSchemaValue(schema, frozen) {
70
91
  if (typeof schema !== "boolean") {
@@ -72,7 +93,11 @@ function freezeJsonSchemaValue(schema, frozen) {
72
93
  }
73
94
  }
74
95
  /**
75
- * @brief freeze json schema array.
96
+ * @brief Freeze an array of nested schema fragments.
97
+ * @details Elements are hardened before the array itself so no mutable child is
98
+ * reachable through the frozen container.
99
+ * @param schemas Array of JSON Schema fragments.
100
+ * @param frozen Objects already processed by this hardening walk.
76
101
  */
77
102
  function freezeJsonSchemaArray(schemas, frozen) {
78
103
  for (let index = 0; index < schemas.length; index += 1) {
@@ -84,7 +109,11 @@ function freezeJsonSchemaArray(schemas, frozen) {
84
109
  Object.freeze(schemas);
85
110
  }
86
111
  /**
87
- * @brief freeze json schema properties.
112
+ * @brief Freeze an object-property schema table.
113
+ * @details Property tables are traversed by own enumerable keys because JSON
114
+ * Schema object maps are data dictionaries, not prototype-based classes.
115
+ * @param properties Property-name to schema table.
116
+ * @param frozen Objects already processed by this hardening walk.
88
117
  */
89
118
  function freezeJsonSchemaProperties(properties, frozen) {
90
119
  const keys = Object.keys(properties);
@@ -100,7 +129,11 @@ function freezeJsonSchemaProperties(properties, frozen) {
100
129
  Object.freeze(properties);
101
130
  }
102
131
  /**
103
- * @brief freeze json schema issues.
132
+ * @brief Freeze JSON Schema export issues and their path arrays.
133
+ * @details Paths are mutable during traversal for stack efficiency, then frozen
134
+ * at the boundary so callers cannot rewrite diagnostic locations later.
135
+ * @param issues Export issues collected during emission.
136
+ * @returns The same issue array after recursive hardening.
104
137
  */
105
138
  export function freezeJsonSchemaIssues(issues) {
106
139
  for (let index = 0; index < issues.length; index += 1) {
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file index.ts
3
3
  * @brief Public JSON Schema export module.
4
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
5
+ * report a structured export issue.
4
6
  */
5
7
  import { type AsyncDecoder } from "../async/index.js";
6
8
  import { type Decoder } from "../decoder/index.js";
@@ -10,11 +12,23 @@ import type { Schema } from "../schema/index.js";
10
12
  import type { JsonSchema, JsonSchemaExportIssue, JsonSchemaOptions } from "./types.js";
11
13
  export type { JsonSchema, JsonSchemaDialect, JsonSchemaExportCode, JsonSchemaExportIssue, JsonSchemaObject, JsonSchemaOptions, JsonSchemaPrimitive, JsonSchemaTypeName } from "./types.js";
12
14
  /**
13
- * @brief to json schema.
15
+ * @brief Export the schema behind a guard or decoder as JSON Schema.
16
+ * @details Decoder values are rejected before emission because transform logic
17
+ * has no lossless JSON Schema representation. This keeps the exporter honest:
18
+ * it returns a schema only when the runtime validator can be expressed without
19
+ * hidden TypeSea execution.
20
+ * @param guard Guard or decoder value provided by public callers.
21
+ * @param options Optional dialect and schema id configuration.
22
+ * @returns Export result with either a frozen JSON Schema document or issues.
14
23
  */
15
24
  export declare function toJsonSchema<TValue>(guard: Guard<TValue, Presence> | Decoder<TValue> | AsyncDecoder<TValue>, options?: Partial<JsonSchemaOptions>): Result<JsonSchema, readonly JsonSchemaExportIssue[]>;
16
25
  /**
17
- * @brief schema to json schema.
26
+ * @brief Export a raw TypeSea schema into a JSON Schema document.
27
+ * @details This internal-facing helper skips guard extraction but still routes
28
+ * through the same emitter and issue accumulator as the public guard API.
29
+ * @param schema Schema value that already passed TypeSea construction checks.
30
+ * @param options Optional dialect and schema id configuration.
31
+ * @returns Export result with a frozen JSON Schema document or diagnostics.
18
32
  */
19
33
  export declare function schemaToJsonSchema(schema: Schema, options?: Partial<JsonSchemaOptions>): Result<JsonSchema, readonly JsonSchemaExportIssue[]>;
20
34
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/json-schema/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAajD,OAAO,KAAK,EACV,UAAU,EAEV,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,UAAU,EACV,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EACjC,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,EACvE,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACnC,MAAM,CAAC,UAAU,EAAE,SAAS,qBAAqB,EAAE,CAAC,CAsBtD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACnC,MAAM,CAAC,UAAU,EAAE,SAAS,qBAAqB,EAAE,CAAC,CAEtD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/json-schema/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAajD,OAAO,KAAK,EACR,UAAU,EAEV,qBAAqB,EACrB,iBAAiB,EACpB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACR,UAAU,EACV,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EACrB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAC/B,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,EACvE,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACrC,MAAM,CAAC,UAAU,EAAE,SAAS,qBAAqB,EAAE,CAAC,CAsBtD;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACrC,MAAM,CAAC,UAAU,EAAE,SAAS,qBAAqB,EAAE,CAAC,CAEtD"}
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file index.ts
3
3
  * @brief Public JSON Schema export module.
4
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
5
+ * report a structured export issue.
4
6
  */
5
7
  import { isAsyncDecoderValue } from "../async/index.js";
6
8
  import { isDecoderValue } from "../decoder/index.js";
@@ -9,7 +11,14 @@ import { emitSchema } from "./emit.js";
9
11
  import { freezeJsonSchema, freezeJsonSchemaIssues } from "./freeze.js";
10
12
  import { JSON_SCHEMA_2020_12_ID, JSON_SCHEMA_DRAFT_07_ID, readJsonSchemaGuardSchema, readJsonSchemaOptions, readJsonSchemaSchema } from "./read.js";
11
13
  /**
12
- * @brief to json schema.
14
+ * @brief Export the schema behind a guard or decoder as JSON Schema.
15
+ * @details Decoder values are rejected before emission because transform logic
16
+ * has no lossless JSON Schema representation. This keeps the exporter honest:
17
+ * it returns a schema only when the runtime validator can be expressed without
18
+ * hidden TypeSea execution.
19
+ * @param guard Guard or decoder value provided by public callers.
20
+ * @param options Optional dialect and schema id configuration.
21
+ * @returns Export result with either a frozen JSON Schema document or issues.
13
22
  */
14
23
  export function toJsonSchema(guard, options) {
15
24
  if (isAsyncDecoderValue(guard)) {
@@ -35,13 +44,24 @@ export function toJsonSchema(guard, options) {
35
44
  return exportJsonSchema(readJsonSchemaGuardSchema(guard), options);
36
45
  }
37
46
  /**
38
- * @brief schema to json schema.
47
+ * @brief Export a raw TypeSea schema into a JSON Schema document.
48
+ * @details This internal-facing helper skips guard extraction but still routes
49
+ * through the same emitter and issue accumulator as the public guard API.
50
+ * @param schema Schema value that already passed TypeSea construction checks.
51
+ * @param options Optional dialect and schema id configuration.
52
+ * @returns Export result with a frozen JSON Schema document or diagnostics.
39
53
  */
40
54
  export function schemaToJsonSchema(schema, options) {
41
55
  return exportJsonSchema(readJsonSchemaSchema(schema), options);
42
56
  }
43
57
  /**
44
- * @brief export json schema.
58
+ * @brief Run the JSON Schema emitter and attach the dialect marker.
59
+ * @details The emitter writes structural failures into `issues` instead of
60
+ * throwing so callers can inspect every unsupported node discovered during the
61
+ * walk. Boolean schemas are wrapped to preserve a document-shaped top level.
62
+ * @param schema TypeSea schema selected for export.
63
+ * @param options User supplied export options, still unresolved.
64
+ * @returns Frozen JSON Schema document on success, or frozen export issues.
45
65
  */
46
66
  function exportJsonSchema(schema, options) {
47
67
  const config = readJsonSchemaOptions(options);
@@ -1,11 +1,14 @@
1
1
  /**
2
2
  * @file issue.ts
3
3
  * @brief JSON Schema export issue construction.
4
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
5
+ * report a structured export issue.
4
6
  */
5
7
  import type { PathSegment } from "../issue/index.js";
6
8
  import type { JsonSchemaExportCode, JsonSchemaExportIssue } from "./types.js";
7
9
  /**
8
- * @brief push json schema issue.
10
+ * @brief Execute push json schema issue.
11
+ * @details This helper keeps a local invariant explicit at the module boundary.
9
12
  */
10
13
  export declare function pushJsonSchemaIssue(path: readonly PathSegment[], issues: JsonSchemaExportIssue[], code: JsonSchemaExportCode, message: string): void;
11
14
  //# sourceMappingURL=issue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"issue.d.ts","sourceRoot":"","sources":["../../src/json-schema/issue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,SAAS,WAAW,EAAE,EAC5B,MAAM,EAAE,qBAAqB,EAAE,EAC/B,IAAI,EAAE,oBAAoB,EAC1B,OAAO,EAAE,MAAM,GACd,IAAI,CAMN"}
1
+ {"version":3,"file":"issue.d.ts","sourceRoot":"","sources":["../../src/json-schema/issue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EACR,oBAAoB,EACpB,qBAAqB,EACxB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,wBAAgB,mBAAmB,CAC/B,IAAI,EAAE,SAAS,WAAW,EAAE,EAC5B,MAAM,EAAE,qBAAqB,EAAE,EAC/B,IAAI,EAAE,oBAAoB,EAC1B,OAAO,EAAE,MAAM,GAChB,IAAI,CAMN"}
@@ -1,9 +1,12 @@
1
1
  /**
2
2
  * @file issue.ts
3
3
  * @brief JSON Schema export issue construction.
4
+ * @details JSON Schema helpers emit only representations that preserve TypeSea semantics or
5
+ * report a structured export issue.
4
6
  */
5
7
  /**
6
- * @brief push json schema issue.
8
+ * @brief Execute push json schema issue.
9
+ * @details This helper keeps a local invariant explicit at the module boundary.
7
10
  */
8
11
  export function pushJsonSchemaIssue(path, issues, code, message) {
9
12
  issues.push({