openapi-typesafe 1.0.0-rc.0 → 1.0.0-rc.1

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 (404) hide show
  1. package/dist/adapters/redocly-loader/redocly-config-source.cjs +21 -2
  2. package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -1
  3. package/dist/adapters/redocly-loader/redocly-config-source.mjs +22 -3
  4. package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -1
  5. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +15 -5
  6. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
  7. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +15 -5
  8. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
  9. package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs +3 -0
  10. package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs.map +1 -1
  11. package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs +3 -0
  12. package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs.map +1 -1
  13. package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs +15 -9
  14. package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs.map +1 -1
  15. package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs +15 -9
  16. package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs.map +1 -1
  17. package/dist/api/discriminator-conflict-warnings.cjs +25 -0
  18. package/dist/api/discriminator-conflict-warnings.cjs.map +1 -0
  19. package/dist/api/discriminator-conflict-warnings.mjs +23 -0
  20. package/dist/api/discriminator-conflict-warnings.mjs.map +1 -0
  21. package/dist/api/discriminator-enum-names.cjs +19 -0
  22. package/dist/api/discriminator-enum-names.cjs.map +1 -0
  23. package/dist/api/discriminator-enum-names.mjs +17 -0
  24. package/dist/api/discriminator-enum-names.mjs.map +1 -0
  25. package/dist/api/discriminator-enum-parent.cjs +59 -0
  26. package/dist/api/discriminator-enum-parent.cjs.map +1 -0
  27. package/dist/api/discriminator-enum-parent.mjs +57 -0
  28. package/dist/api/discriminator-enum-parent.mjs.map +1 -0
  29. package/dist/api/discriminator-enum.cjs +25 -0
  30. package/dist/api/discriminator-enum.cjs.map +1 -1
  31. package/dist/api/discriminator-enum.mjs +25 -1
  32. package/dist/api/discriminator-enum.mjs.map +1 -1
  33. package/dist/api/discriminator-other-owners.cjs +67 -0
  34. package/dist/api/discriminator-other-owners.cjs.map +1 -0
  35. package/dist/api/discriminator-other-owners.mjs +64 -0
  36. package/dist/api/discriminator-other-owners.mjs.map +1 -0
  37. package/dist/api/discriminator-patch.cjs +88 -0
  38. package/dist/api/discriminator-patch.cjs.map +1 -0
  39. package/dist/api/discriminator-patch.mjs +82 -0
  40. package/dist/api/discriminator-patch.mjs.map +1 -0
  41. package/dist/api/discriminator-scan.cjs +50 -65
  42. package/dist/api/discriminator-scan.cjs.map +1 -1
  43. package/dist/api/discriminator-scan.mjs +44 -59
  44. package/dist/api/discriminator-scan.mjs.map +1 -1
  45. package/dist/api/document-run.cjs +18 -3
  46. package/dist/api/document-run.cjs.map +1 -1
  47. package/dist/api/document-run.mjs +19 -4
  48. package/dist/api/document-run.mjs.map +1 -1
  49. package/dist/api/enum-values-warnings.cjs +16 -0
  50. package/dist/api/enum-values-warnings.cjs.map +1 -0
  51. package/dist/api/enum-values-warnings.mjs +14 -0
  52. package/dist/api/enum-values-warnings.mjs.map +1 -0
  53. package/dist/api/path-template-warnings.cjs +21 -0
  54. package/dist/api/path-template-warnings.cjs.map +1 -0
  55. package/dist/api/path-template-warnings.mjs +19 -0
  56. package/dist/api/path-template-warnings.mjs.map +1 -0
  57. package/dist/api/transform-context.cjs +3 -1
  58. package/dist/api/transform-context.cjs.map +1 -1
  59. package/dist/api/transform-context.mjs +3 -1
  60. package/dist/api/transform-context.mjs.map +1 -1
  61. package/dist/api/transform-schema.cjs +52 -3
  62. package/dist/api/transform-schema.cjs.map +1 -1
  63. package/dist/api/transform-schema.mjs +53 -4
  64. package/dist/api/transform-schema.mjs.map +1 -1
  65. package/dist/api/unsupported-feature-warnings.cjs +6 -1
  66. package/dist/api/unsupported-feature-warnings.cjs.map +1 -1
  67. package/dist/api/unsupported-feature-warnings.mjs +6 -1
  68. package/dist/api/unsupported-feature-warnings.mjs.map +1 -1
  69. package/dist/application/print/type-printer.cjs +5 -0
  70. package/dist/application/print/type-printer.cjs.map +1 -1
  71. package/dist/application/print/type-printer.mjs +5 -0
  72. package/dist/application/print/type-printer.mjs.map +1 -1
  73. package/dist/application/transform/document/assignability.cjs +144 -0
  74. package/dist/application/transform/document/assignability.cjs.map +1 -0
  75. package/dist/application/transform/document/assignability.mjs +138 -0
  76. package/dist/application/transform/document/assignability.mjs.map +1 -0
  77. package/dist/application/transform/document/components.cjs +2 -2
  78. package/dist/application/transform/document/components.cjs.map +1 -1
  79. package/dist/application/transform/document/components.mjs +4 -4
  80. package/dist/application/transform/document/components.mjs.map +1 -1
  81. package/dist/application/transform/document/declared-types.cjs +66 -0
  82. package/dist/application/transform/document/declared-types.cjs.map +1 -0
  83. package/dist/application/transform/document/declared-types.mjs +63 -0
  84. package/dist/application/transform/document/declared-types.mjs.map +1 -0
  85. package/dist/application/transform/document/document.cjs +32 -9
  86. package/dist/application/transform/document/document.cjs.map +1 -1
  87. package/dist/application/transform/document/document.mjs +34 -11
  88. package/dist/application/transform/document/document.mjs.map +1 -1
  89. package/dist/application/transform/document/exploded-query.cjs +46 -0
  90. package/dist/application/transform/document/exploded-query.cjs.map +1 -0
  91. package/dist/application/transform/document/exploded-query.mjs +43 -0
  92. package/dist/application/transform/document/exploded-query.mjs.map +1 -0
  93. package/dist/application/transform/document/global-type-references.cjs +63 -0
  94. package/dist/application/transform/document/global-type-references.cjs.map +1 -0
  95. package/dist/application/transform/document/global-type-references.mjs +61 -0
  96. package/dist/application/transform/document/global-type-references.mjs.map +1 -0
  97. package/dist/application/transform/document/list-assignability.cjs +54 -0
  98. package/dist/application/transform/document/list-assignability.cjs.map +1 -0
  99. package/dist/application/transform/document/list-assignability.mjs +52 -0
  100. package/dist/application/transform/document/list-assignability.mjs.map +1 -0
  101. package/dist/application/transform/document/parameters.cjs +40 -8
  102. package/dist/application/transform/document/parameters.cjs.map +1 -1
  103. package/dist/application/transform/document/parameters.mjs +41 -9
  104. package/dist/application/transform/document/parameters.mjs.map +1 -1
  105. package/dist/application/transform/document/path-key-overlaps.cjs +83 -33
  106. package/dist/application/transform/document/path-key-overlaps.cjs.map +1 -1
  107. package/dist/application/transform/document/path-key-overlaps.mjs +83 -33
  108. package/dist/application/transform/document/path-key-overlaps.mjs.map +1 -1
  109. package/dist/application/transform/document/path-template-replace.cjs +48 -0
  110. package/dist/application/transform/document/path-template-replace.cjs.map +1 -0
  111. package/dist/application/transform/document/path-template-replace.mjs +45 -0
  112. package/dist/application/transform/document/path-template-replace.mjs.map +1 -0
  113. package/dist/application/transform/document/paths.cjs +54 -28
  114. package/dist/application/transform/document/paths.cjs.map +1 -1
  115. package/dist/application/transform/document/paths.mjs +53 -29
  116. package/dist/application/transform/document/paths.mjs.map +1 -1
  117. package/dist/application/transform/document/root-type-aliases.cjs +15 -14
  118. package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
  119. package/dist/application/transform/document/root-type-aliases.mjs +15 -13
  120. package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
  121. package/dist/application/transform/document/template-key-match.cjs +128 -0
  122. package/dist/application/transform/document/template-key-match.cjs.map +1 -0
  123. package/dist/application/transform/document/template-key-match.mjs +125 -0
  124. package/dist/application/transform/document/template-key-match.mjs.map +1 -0
  125. package/dist/application/transform/document/type-assignability.cjs +192 -0
  126. package/dist/application/transform/document/type-assignability.cjs.map +1 -0
  127. package/dist/application/transform/document/type-assignability.mjs +190 -0
  128. package/dist/application/transform/document/type-assignability.mjs.map +1 -0
  129. package/dist/application/transform/document/type-key.cjs +70 -0
  130. package/dist/application/transform/document/type-key.cjs.map +1 -0
  131. package/dist/application/transform/document/type-key.mjs +68 -0
  132. package/dist/application/transform/document/type-key.mjs.map +1 -0
  133. package/dist/application/transform/document/type-resolution.cjs +131 -0
  134. package/dist/application/transform/document/type-resolution.cjs.map +1 -0
  135. package/dist/application/transform/document/type-resolution.mjs +125 -0
  136. package/dist/application/transform/document/type-resolution.mjs.map +1 -0
  137. package/dist/application/transform/footer/document-footer.cjs +66 -4
  138. package/dist/application/transform/footer/document-footer.cjs.map +1 -1
  139. package/dist/application/transform/footer/document-footer.mjs +67 -5
  140. package/dist/application/transform/footer/document-footer.mjs.map +1 -1
  141. package/dist/application/transform/footer/enum-naming.cjs +17 -0
  142. package/dist/application/transform/footer/enum-naming.cjs.map +1 -1
  143. package/dist/application/transform/footer/enum-naming.mjs +17 -1
  144. package/dist/application/transform/footer/enum-naming.mjs.map +1 -1
  145. package/dist/application/transform/footer/enum-values-check.cjs +129 -0
  146. package/dist/application/transform/footer/enum-values-check.cjs.map +1 -0
  147. package/dist/application/transform/footer/enum-values-check.mjs +127 -0
  148. package/dist/application/transform/footer/enum-values-check.mjs.map +1 -0
  149. package/dist/application/transform/footer/evaluation.cjs +33 -0
  150. package/dist/application/transform/footer/evaluation.cjs.map +1 -0
  151. package/dist/application/transform/footer/evaluation.mjs +26 -0
  152. package/dist/application/transform/footer/evaluation.mjs.map +1 -0
  153. package/dist/application/transform/footer/shared-enum-names.cjs +60 -0
  154. package/dist/application/transform/footer/shared-enum-names.cjs.map +1 -0
  155. package/dist/application/transform/footer/shared-enum-names.mjs +57 -0
  156. package/dist/application/transform/footer/shared-enum-names.mjs.map +1 -0
  157. package/dist/application/transform/footer/type-evaluation.cjs +246 -0
  158. package/dist/application/transform/footer/type-evaluation.cjs.map +1 -0
  159. package/dist/application/transform/footer/type-evaluation.mjs +244 -0
  160. package/dist/application/transform/footer/type-evaluation.mjs.map +1 -0
  161. package/dist/application/transform/footer/type-rules.cjs +172 -0
  162. package/dist/application/transform/footer/type-rules.cjs.map +1 -0
  163. package/dist/application/transform/footer/type-rules.mjs +166 -0
  164. package/dist/application/transform/footer/type-rules.mjs.map +1 -0
  165. package/dist/application/transform/ref-pointer/generated-location.cjs +138 -0
  166. package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -0
  167. package/dist/application/transform/ref-pointer/generated-location.mjs +136 -0
  168. package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -0
  169. package/dist/application/transform/ref-pointer/generated-shape.cjs +171 -0
  170. package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -0
  171. package/dist/application/transform/ref-pointer/generated-shape.mjs +162 -0
  172. package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -0
  173. package/dist/application/transform/ref-pointer/inline-cycles.cjs +44 -0
  174. package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -0
  175. package/dist/application/transform/ref-pointer/inline-cycles.mjs +42 -0
  176. package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -0
  177. package/dist/application/transform/ref-pointer/original-index.cjs +62 -0
  178. package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -0
  179. package/dist/application/transform/ref-pointer/original-index.mjs +60 -0
  180. package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -0
  181. package/dist/application/transform/ref-pointer/pointer-type.cjs +60 -0
  182. package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -0
  183. package/dist/application/transform/ref-pointer/pointer-type.mjs +57 -0
  184. package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -0
  185. package/dist/application/transform/ref-pointer/pointer-walk.cjs +66 -0
  186. package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -0
  187. package/dist/application/transform/ref-pointer/pointer-walk.mjs +56 -0
  188. package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -0
  189. package/dist/application/transform/ref-pointer/typed-walk.cjs +124 -0
  190. package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -0
  191. package/dist/application/transform/ref-pointer/typed-walk.mjs +122 -0
  192. package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -0
  193. package/dist/application/transform/ref-type.cjs +7 -2
  194. package/dist/application/transform/ref-type.cjs.map +1 -1
  195. package/dist/application/transform/ref-type.mjs +3 -2
  196. package/dist/application/transform/ref-type.mjs.map +1 -1
  197. package/dist/application/transform/schema/access-flags.cjs +38 -0
  198. package/dist/application/transform/schema/access-flags.cjs.map +1 -0
  199. package/dist/application/transform/schema/access-flags.mjs +36 -0
  200. package/dist/application/transform/schema/access-flags.mjs.map +1 -0
  201. package/dist/application/transform/schema/array-type.cjs +32 -1
  202. package/dist/application/transform/schema/array-type.cjs.map +1 -1
  203. package/dist/application/transform/schema/array-type.mjs +33 -2
  204. package/dist/application/transform/schema/array-type.mjs.map +1 -1
  205. package/dist/application/transform/schema/composition-type.cjs +50 -15
  206. package/dist/application/transform/schema/composition-type.cjs.map +1 -1
  207. package/dist/application/transform/schema/composition-type.mjs +50 -15
  208. package/dist/application/transform/schema/composition-type.mjs.map +1 -1
  209. package/dist/application/transform/schema/core-type.cjs +3 -1
  210. package/dist/application/transform/schema/core-type.cjs.map +1 -1
  211. package/dist/application/transform/schema/core-type.mjs +3 -1
  212. package/dist/application/transform/schema/core-type.mjs.map +1 -1
  213. package/dist/application/transform/schema/discriminated-union.cjs +30 -0
  214. package/dist/application/transform/schema/discriminated-union.cjs.map +1 -0
  215. package/dist/application/transform/schema/discriminated-union.mjs +27 -0
  216. package/dist/application/transform/schema/discriminated-union.mjs.map +1 -0
  217. package/dist/application/transform/schema/discriminator-property.cjs +3 -2
  218. package/dist/application/transform/schema/discriminator-property.cjs.map +1 -1
  219. package/dist/application/transform/schema/discriminator-property.mjs +3 -2
  220. package/dist/application/transform/schema/discriminator-property.mjs.map +1 -1
  221. package/dist/application/transform/schema/enum-rule.cjs +66 -10
  222. package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
  223. package/dist/application/transform/schema/enum-rule.mjs +67 -12
  224. package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
  225. package/dist/application/transform/schema/inherited-discriminator.cjs +29 -0
  226. package/dist/application/transform/schema/inherited-discriminator.cjs.map +1 -0
  227. package/dist/application/transform/schema/inherited-discriminator.mjs +26 -0
  228. package/dist/application/transform/schema/inherited-discriminator.mjs.map +1 -0
  229. package/dist/application/transform/schema/object-type.cjs +38 -25
  230. package/dist/application/transform/schema/object-type.cjs.map +1 -1
  231. package/dist/application/transform/schema/object-type.mjs +39 -27
  232. package/dist/application/transform/schema/object-type.mjs.map +1 -1
  233. package/dist/application/transform/schema/required-variants.cjs +45 -0
  234. package/dist/application/transform/schema/required-variants.cjs.map +1 -0
  235. package/dist/application/transform/schema/required-variants.mjs +42 -0
  236. package/dist/application/transform/schema/required-variants.mjs.map +1 -0
  237. package/dist/application/transform/schema/schema-transform.cjs +2 -2
  238. package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
  239. package/dist/application/transform/schema/schema-transform.mjs +2 -2
  240. package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
  241. package/dist/application/transform/schema-comment.cjs +51 -5
  242. package/dist/application/transform/schema-comment.cjs.map +1 -1
  243. package/dist/application/transform/schema-comment.mjs +50 -6
  244. package/dist/application/transform/schema-comment.mjs.map +1 -1
  245. package/dist/application/transform/type-combinators.mjs +1 -1
  246. package/dist/cli/cli-arguments.cjs +11 -3
  247. package/dist/cli/cli-arguments.cjs.map +1 -1
  248. package/dist/cli/cli-arguments.mjs +11 -3
  249. package/dist/cli/cli-arguments.mjs.map +1 -1
  250. package/dist/cli/cli-errors.cjs +3 -2
  251. package/dist/cli/cli-errors.cjs.map +1 -1
  252. package/dist/cli/cli-errors.mjs +3 -2
  253. package/dist/cli/cli-errors.mjs.map +1 -1
  254. package/dist/cli/cli-output.cjs +8 -3
  255. package/dist/cli/cli-output.cjs.map +1 -1
  256. package/dist/cli/cli-output.mjs +9 -4
  257. package/dist/cli/cli-output.mjs.map +1 -1
  258. package/dist/cli/main.cjs +5 -0
  259. package/dist/cli/main.cjs.map +1 -1
  260. package/dist/cli/main.mjs +5 -0
  261. package/dist/cli/main.mjs.map +1 -1
  262. package/dist/cli/redocly-apis.cjs +7 -3
  263. package/dist/cli/redocly-apis.cjs.map +1 -1
  264. package/dist/cli/redocly-apis.mjs +8 -4
  265. package/dist/cli/redocly-apis.mjs.map +1 -1
  266. package/dist/cli/ref-limits.cjs +1 -1
  267. package/dist/cli/ref-limits.cjs.map +1 -1
  268. package/dist/cli/ref-limits.mjs +2 -2
  269. package/dist/cli/ref-limits.mjs.map +1 -1
  270. package/dist/cli/run-cli.cjs +15 -2
  271. package/dist/cli/run-cli.cjs.map +1 -1
  272. package/dist/cli/run-cli.mjs +16 -3
  273. package/dist/cli/run-cli.mjs.map +1 -1
  274. package/dist/domain/errors.cjs +2 -0
  275. package/dist/domain/errors.cjs.map +1 -1
  276. package/dist/domain/errors.mjs +2 -0
  277. package/dist/domain/errors.mjs.map +1 -1
  278. package/dist/domain/ir/constructors.cjs +5 -1
  279. package/dist/domain/ir/constructors.cjs.map +1 -1
  280. package/dist/domain/ir/constructors.mjs +5 -2
  281. package/dist/domain/ir/constructors.mjs.map +1 -1
  282. package/dist/domain/openapi/admitted-values.cjs +75 -0
  283. package/dist/domain/openapi/admitted-values.cjs.map +1 -0
  284. package/dist/domain/openapi/admitted-values.mjs +72 -0
  285. package/dist/domain/openapi/admitted-values.mjs.map +1 -0
  286. package/dist/domain/openapi/discriminated-union.cjs +68 -0
  287. package/dist/domain/openapi/discriminated-union.cjs.map +1 -0
  288. package/dist/domain/openapi/discriminated-union.mjs +62 -0
  289. package/dist/domain/openapi/discriminated-union.mjs.map +1 -0
  290. package/dist/domain/openapi/discriminator-conflicts.cjs +143 -0
  291. package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -0
  292. package/dist/domain/openapi/discriminator-conflicts.mjs +141 -0
  293. package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -0
  294. package/dist/domain/openapi/parameter-object.cjs.map +1 -1
  295. package/dist/domain/openapi/parameter-object.mjs.map +1 -1
  296. package/dist/domain/openapi/path-templates.cjs +23 -0
  297. package/dist/domain/openapi/path-templates.cjs.map +1 -0
  298. package/dist/domain/openapi/path-templates.mjs +21 -0
  299. package/dist/domain/openapi/path-templates.mjs.map +1 -0
  300. package/dist/domain/output-fixes.cjs +36 -1
  301. package/dist/domain/output-fixes.cjs.map +1 -1
  302. package/dist/domain/output-fixes.mjs +36 -1
  303. package/dist/domain/output-fixes.mjs.map +1 -1
  304. package/dist/domain/warnings.cjs +15 -0
  305. package/dist/domain/warnings.cjs.map +1 -0
  306. package/dist/domain/warnings.mjs +12 -0
  307. package/dist/domain/warnings.mjs.map +1 -0
  308. package/dist/index.d.cts +29 -0
  309. package/dist/index.d.mts +29 -0
  310. package/dist/index.d.ts +29 -0
  311. package/dist/transform/components-object.cjs +2 -1
  312. package/dist/transform/components-object.cjs.map +1 -1
  313. package/dist/transform/components-object.mjs +2 -1
  314. package/dist/transform/components-object.mjs.map +1 -1
  315. package/package.json +1 -1
  316. package/src/adapters/redocly-loader/redocly-config-source.ts +41 -6
  317. package/src/adapters/redocly-loader/redocly-schema-loader.ts +22 -6
  318. package/src/adapters/type-ast-bridge/ir-to-typescript.ts +3 -0
  319. package/src/adapters/type-ast-bridge/typescript-to-ir.ts +26 -12
  320. package/src/api/discriminator-conflict-warnings.ts +43 -0
  321. package/src/api/discriminator-enum-names.ts +26 -0
  322. package/src/api/discriminator-enum-parent.ts +129 -0
  323. package/src/api/discriminator-enum.ts +39 -0
  324. package/src/api/discriminator-other-owners.ts +97 -0
  325. package/src/api/discriminator-patch.ts +147 -0
  326. package/src/api/discriminator-scan.ts +78 -90
  327. package/src/api/document-run.ts +24 -6
  328. package/src/api/enum-values-warnings.ts +21 -0
  329. package/src/api/path-template-warnings.ts +27 -0
  330. package/src/api/transform-context.ts +7 -1
  331. package/src/api/transform-schema.ts +88 -4
  332. package/src/api/unsupported-feature-warnings.ts +8 -1
  333. package/src/application/ports/redocly-config-source.ts +5 -1
  334. package/src/application/print/type-printer.ts +6 -0
  335. package/src/application/transform/document/assignability.ts +203 -0
  336. package/src/application/transform/document/components.ts +6 -6
  337. package/src/application/transform/document/declared-types.ts +93 -0
  338. package/src/application/transform/document/document.ts +71 -13
  339. package/src/application/transform/document/exploded-query.ts +91 -0
  340. package/src/application/transform/document/global-type-references.ts +78 -0
  341. package/src/application/transform/document/list-assignability.ts +87 -0
  342. package/src/application/transform/document/parameters.ts +76 -11
  343. package/src/application/transform/document/path-key-overlaps.ts +148 -59
  344. package/src/application/transform/document/path-template-replace.ts +90 -0
  345. package/src/application/transform/document/paths.ts +99 -37
  346. package/src/application/transform/document/root-type-aliases.ts +29 -28
  347. package/src/application/transform/document/template-key-match.ts +183 -0
  348. package/src/application/transform/document/type-assignability.ts +268 -0
  349. package/src/application/transform/document/type-key.ts +80 -0
  350. package/src/application/transform/document/type-resolution.ts +163 -0
  351. package/src/application/transform/footer/document-footer.ts +91 -6
  352. package/src/application/transform/footer/enum-naming.ts +29 -0
  353. package/src/application/transform/footer/enum-values-check.ts +171 -0
  354. package/src/application/transform/footer/evaluation.ts +47 -0
  355. package/src/application/transform/footer/shared-enum-names.ts +86 -0
  356. package/src/application/transform/footer/type-evaluation.ts +294 -0
  357. package/src/application/transform/footer/type-rules.ts +269 -0
  358. package/src/application/transform/ref-pointer/generated-location.ts +211 -0
  359. package/src/application/transform/ref-pointer/generated-shape.ts +275 -0
  360. package/src/application/transform/ref-pointer/inline-cycles.ts +56 -0
  361. package/src/application/transform/ref-pointer/original-index.ts +95 -0
  362. package/src/application/transform/ref-pointer/pointer-type.ts +92 -0
  363. package/src/application/transform/ref-pointer/pointer-walk.ts +96 -0
  364. package/src/application/transform/ref-pointer/typed-walk.ts +192 -0
  365. package/src/application/transform/ref-type.ts +11 -6
  366. package/src/application/transform/schema/access-flags.ts +63 -0
  367. package/src/application/transform/schema/array-type.ts +66 -5
  368. package/src/application/transform/schema/composition-type.ts +96 -24
  369. package/src/application/transform/schema/core-type.ts +8 -4
  370. package/src/application/transform/schema/discriminated-union.ts +58 -0
  371. package/src/application/transform/schema/discriminator-property.ts +8 -3
  372. package/src/application/transform/schema/enum-rule.ts +136 -13
  373. package/src/application/transform/schema/inherited-discriminator.ts +54 -0
  374. package/src/application/transform/schema/object-type.ts +51 -33
  375. package/src/application/transform/schema/required-variants.ts +88 -0
  376. package/src/application/transform/schema/schema-context.ts +26 -0
  377. package/src/application/transform/schema/schema-transform.ts +2 -2
  378. package/src/application/transform/schema-comment.ts +84 -4
  379. package/src/cli/cli-arguments.ts +13 -3
  380. package/src/cli/cli-dependencies.ts +5 -0
  381. package/src/cli/cli-errors.ts +4 -2
  382. package/src/cli/cli-output.ts +18 -4
  383. package/src/cli/main.ts +6 -0
  384. package/src/cli/redocly-apis.ts +8 -4
  385. package/src/cli/ref-limits.ts +2 -2
  386. package/src/cli/run-cli.ts +20 -3
  387. package/src/domain/errors.ts +2 -0
  388. package/src/domain/ir/constructors.ts +6 -1
  389. package/src/domain/ir/nodes.ts +2 -1
  390. package/src/domain/openapi/admitted-values.ts +113 -0
  391. package/src/domain/openapi/discriminated-union.ts +109 -0
  392. package/src/domain/openapi/discriminator-conflicts.ts +251 -0
  393. package/src/domain/openapi/parameter-object.ts +4 -0
  394. package/src/domain/openapi/path-templates.ts +31 -0
  395. package/src/domain/openapi/schema-object.ts +2 -0
  396. package/src/domain/output-fixes.ts +43 -2
  397. package/src/domain/warnings.ts +20 -0
  398. package/src/transform/components-object.ts +3 -1
  399. package/src/types/generator-options.ts +11 -0
  400. package/dist/application/transform/document/path-item-conflicts.cjs +0 -51
  401. package/dist/application/transform/document/path-item-conflicts.cjs.map +0 -1
  402. package/dist/application/transform/document/path-item-conflicts.mjs +0 -49
  403. package/dist/application/transform/document/path-item-conflicts.mjs.map +0 -1
  404. package/src/application/transform/document/path-item-conflicts.ts +0 -79
@@ -0,0 +1,244 @@
1
+ import { OPAQUE, absorbed, unionType, propertyKey, MISSING, NEVER } from './evaluation.mjs';
2
+ import { markerObject, omitted, extracted, isNeverIntersection, declaredFirst } from './type-rules.mjs';
3
+
4
+ const MAX_EXPANSIONS = 200;
5
+ const DEEP_PREFIX = "FlattenedDeepRequired<";
6
+ const MAX_DISTRIBUTED = 64;
7
+ const NULLISH = /* @__PURE__ */ new Set(["null", "undefined"]);
8
+ class TypeEvaluator {
9
+ declared = /* @__PURE__ */ new Map();
10
+ expansions = 0;
11
+ constructor(declarations) {
12
+ for (const declaration of declarations) {
13
+ if (declaration.kind === "interface") {
14
+ this.declared.set(declaration.name, { kind: "object", members: declaration.members });
15
+ } else if (declaration.kind === "typeAlias") {
16
+ this.declared.set(declaration.name, declaration.type);
17
+ }
18
+ }
19
+ }
20
+ /** Evaluate a type written in the footer; the expansion budget starts again. */
21
+ evaluate(type) {
22
+ this.expansions = 0;
23
+ return this.expand({ kind: "type", type, deep: false });
24
+ }
25
+ /** The type with references, `readonly` and indexed access resolved at the top. */
26
+ expand(value) {
27
+ const { type } = value;
28
+ switch (type.kind) {
29
+ case "readonly":
30
+ return this.expand({ ...value, type: type.type });
31
+ case "indexedAccess":
32
+ return this.indexedAccess(value, type.object, type.index);
33
+ case "reference":
34
+ return this.reference(value, type.name, type.typeArguments);
35
+ case "raw":
36
+ case "tuple":
37
+ return OPAQUE;
38
+ default:
39
+ return value;
40
+ }
41
+ }
42
+ indexedAccess(value, object, index) {
43
+ const owner = this.expand({ ...value, type: object });
44
+ return owner.kind === "type" ? this.index(owner, index) : owner;
45
+ }
46
+ reference(value, name, args) {
47
+ if (this.expansions++ > MAX_EXPANSIONS) {
48
+ return OPAQUE;
49
+ }
50
+ if (name.startsWith(DEEP_PREFIX) && name.endsWith(">")) {
51
+ const root = this.declared.get(name.slice(DEEP_PREFIX.length, -1));
52
+ return root === void 0 ? OPAQUE : this.expand({ kind: "type", type: root, deep: true });
53
+ }
54
+ const declared = args.length === 0 ? this.declared.get(name) : void 0;
55
+ if (declared !== void 0) {
56
+ return this.expand({ ...value, type: declared });
57
+ }
58
+ const [first, second] = args;
59
+ if (first === void 0) {
60
+ return OPAQUE;
61
+ }
62
+ const argument = this.expand({ ...value, type: first });
63
+ if (argument.kind !== "type") {
64
+ return argument;
65
+ }
66
+ return this.helper(name, argument, second);
67
+ }
68
+ helper(name, argument, second) {
69
+ switch (name) {
70
+ case "NonNullable":
71
+ return this.withoutNullish(argument);
72
+ case "WithRequired":
73
+ case "Readonly":
74
+ return argument;
75
+ case "Extract":
76
+ return second === void 0 ? OPAQUE : this.extract(argument, second);
77
+ case "Omit":
78
+ return second === void 0 ? OPAQUE : omitted(this, argument, second);
79
+ default:
80
+ return markerObject(name, argument) ?? OPAQUE;
81
+ }
82
+ }
83
+ /**
84
+ * The members of a union, each expanded; an intersection with unions in it is distributed over
85
+ * them (`A & (B | C)` is `(A & B) | (A & C)`), as TypeScript normalizes it. A type that is not a
86
+ * union is its only member. A union with an `any` or `unknown` member is that keyword alone.
87
+ */
88
+ membersOf(value) {
89
+ const expanded = this.expand(value);
90
+ if (expanded.kind !== "type") {
91
+ return [expanded];
92
+ }
93
+ const { type } = expanded;
94
+ if (type.kind === "union") {
95
+ return absorbed(
96
+ type.types.flatMap((member) => this.membersOf({ ...expanded, type: member }))
97
+ );
98
+ }
99
+ return type.kind === "intersection" ? this.distributed(expanded, type.types) : [expanded];
100
+ }
101
+ distributed(value, parts) {
102
+ const memberLists = parts.map((part) => this.membersOf({ ...value, type: part }));
103
+ const size = memberLists.reduce((product, list) => product * list.length, 1);
104
+ if (size > MAX_DISTRIBUTED || memberLists.some((list) => list.some((m) => m.kind !== "type"))) {
105
+ return [OPAQUE];
106
+ }
107
+ let combinations = [[]];
108
+ for (const list of memberLists) {
109
+ combinations = combinations.flatMap((done) => list.map((member) => [...done, member.type]));
110
+ }
111
+ return combinations.map((types) => ({ ...value, type: intersectionType(types) }));
112
+ }
113
+ withoutNullish(value) {
114
+ const members = this.membersOf(value);
115
+ if (members.some((member) => member.kind !== "type")) {
116
+ return OPAQUE;
117
+ }
118
+ const kept = members.filter((member) => !isNullish(member.type));
119
+ return { ...value, type: unionType(kept.map((member) => member.type)) };
120
+ }
121
+ /** `Extract<T, { key: unknown }>` keeps the members that have `key`; other probes are opaque. */
122
+ extract(value, probe) {
123
+ const [member] = probe.kind === "object" ? probe.members : [];
124
+ if (probe.kind !== "object" || probe.members.length !== 1 || member?.kind !== "property") {
125
+ return OPAQUE;
126
+ }
127
+ return extracted(this, value, propertyKey(member.name));
128
+ }
129
+ /** `value[index]` for a string literal, `string` or `number` index. */
130
+ index(value, index) {
131
+ const owner = this.expand(value);
132
+ if (owner.kind !== "type") {
133
+ return owner;
134
+ }
135
+ if (this.membersOf(owner).length > 1) {
136
+ return this.unionIndex(owner, index);
137
+ }
138
+ const { type } = owner;
139
+ switch (type.kind) {
140
+ case "object":
141
+ return this.memberType(owner, type.members, index);
142
+ case "intersection":
143
+ return this.partsIndex(owner, type.types, index);
144
+ case "union":
145
+ return this.unionIndex(owner, index);
146
+ case "array":
147
+ return isNumberIndex(index) ? this.flattened(owner, type.element) : builtInIndex(index);
148
+ case "keyword":
149
+ return type.keyword === "never" ? owner : builtInIndex(index);
150
+ default:
151
+ return builtInIndex(index);
152
+ }
153
+ }
154
+ memberType(owner, members, index) {
155
+ const key = indexKey(index);
156
+ const property = members.find(
157
+ (member) => member.kind === "property" && key !== null && propertyKey(member.name) === key
158
+ );
159
+ if (property !== void 0) {
160
+ return this.flattened(owner, property.type);
161
+ }
162
+ const signature = members.find((member) => member.kind === "indexSignature");
163
+ if (signature !== void 0) {
164
+ return this.flattened(owner, signature.type);
165
+ }
166
+ return key === null || isObjectBuiltIn(key) ? OPAQUE : MISSING;
167
+ }
168
+ partsIndex(owner, parts, index) {
169
+ if (isNeverIntersection(this, owner, parts)) {
170
+ return { ...owner, type: NEVER };
171
+ }
172
+ const found = parts.map((type) => this.index({ ...owner, type }, index));
173
+ if (found.some((part) => part.kind === "opaque")) {
174
+ return OPAQUE;
175
+ }
176
+ const read = parts.map((type, at) => ({ type, found: found[at] }));
177
+ const types = declaredFirst(this, owner, indexKey(index), read).flatMap(
178
+ (part) => part.kind === "type" ? [part.type] : []
179
+ );
180
+ return types.length === 0 ? MISSING : { ...owner, type: intersectionType(types) };
181
+ }
182
+ unionIndex(owner, index) {
183
+ const found = this.membersOf(owner).map(
184
+ (member) => member.kind === "type" ? this.index(member, index) : member
185
+ );
186
+ if (found.some((member) => member.kind === "missing")) {
187
+ return MISSING;
188
+ }
189
+ if (found.some((member) => member.kind === "opaque")) {
190
+ return OPAQUE;
191
+ }
192
+ return { ...owner, type: unionType(found.map((member) => member.type)) };
193
+ }
194
+ /**
195
+ * A member read through `FlattenedDeepRequired`: a value that is only arrays (and `undefined` or
196
+ * `null`) is replaced by its elements, anything else loses `undefined` and `null`.
197
+ */
198
+ flattened(owner, type) {
199
+ const member = { ...owner, type };
200
+ if (!owner.deep) {
201
+ return this.expand(member);
202
+ }
203
+ const members = this.membersOf(member);
204
+ if (members.some((candidate) => candidate.kind !== "type")) {
205
+ return OPAQUE;
206
+ }
207
+ const present = members.filter((candidate) => !isNullish(candidate.type));
208
+ const elements = present.map((candidate) => arrayElement(candidate.type));
209
+ if (present.length > 0 && elements.every((element) => element !== null)) {
210
+ return this.expand({ ...owner, type: unionType(elements) });
211
+ }
212
+ return { ...owner, type: unionType(present.map((candidate) => candidate.type)) };
213
+ }
214
+ }
215
+ function isNullish(type) {
216
+ return type.kind === "keyword" && NULLISH.has(type.keyword);
217
+ }
218
+ function arrayElement(type) {
219
+ return type.kind === "array" ? type.element : null;
220
+ }
221
+ function intersectionType(types) {
222
+ return types.length === 1 ? types[0] : { kind: "intersection", types };
223
+ }
224
+ function indexKey(index) {
225
+ if (index.kind === "stringLiteral") {
226
+ return index.value;
227
+ }
228
+ return index.kind === "numberLiteral" ? String(index.value) : null;
229
+ }
230
+ function isNumberIndex(index) {
231
+ const key = indexKey(index);
232
+ return index.kind === "keyword" && index.keyword === "number" || /^\d+$/.test(key ?? "");
233
+ }
234
+ function isObjectBuiltIn(key) {
235
+ return key in {};
236
+ }
237
+ function builtInIndex(index) {
238
+ const key = indexKey(index);
239
+ const isBuiltIn = key === null || key in String.prototype || key in Array.prototype;
240
+ return isBuiltIn || key in Number.prototype ? OPAQUE : MISSING;
241
+ }
242
+
243
+ export { TypeEvaluator };
244
+ //# sourceMappingURL=type-evaluation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-evaluation.mjs","sources":["../../../../src/application/transform/footer/type-evaluation.ts"],"sourcesContent":["import type { IrDeclaration, IrMember, IrType } from \"../../../domain/ir/nodes.js\";\nimport {\n absorbed,\n type Evaluated,\n type Evaluation,\n MISSING,\n NEVER,\n OPAQUE,\n propertyKey,\n unionType,\n} from \"./evaluation.js\";\nimport {\n declaredFirst,\n extracted,\n isNeverIntersection,\n markerObject,\n omitted,\n} from \"./type-rules.js\";\n\n/**\n * A small evaluator of the generated types, as TypeScript reads them, for the `--enum-values`\n * check (ADR-027). It follows the declarations of the document and the helper types the generator\n * writes (`NonNullable`, `Extract`, `WithRequired`, `Omit`, `Record`, `FlattenedDeepRequired`). Its\n * answers are sure: a key is `missing` only where TypeScript reports it, and every type it does\n * not model is `opaque`, which never counts as an error.\n */\n\n/** How many references one evaluation expands; a deeper one is opaque. */\nconst MAX_EXPANSIONS = 200;\nconst DEEP_PREFIX = \"FlattenedDeepRequired<\";\n/** How many members distributing an intersection may give; more is opaque. */\nconst MAX_DISTRIBUTED = 64;\nconst NULLISH: ReadonlySet<string> = new Set([\"null\", \"undefined\"]);\n\nexport class TypeEvaluator {\n private readonly declared = new Map<string, IrType>();\n private expansions = 0;\n\n constructor(declarations: readonly IrDeclaration[]) {\n for (const declaration of declarations) {\n if (declaration.kind === \"interface\") {\n this.declared.set(declaration.name, { kind: \"object\", members: declaration.members });\n } else if (declaration.kind === \"typeAlias\") {\n this.declared.set(declaration.name, declaration.type);\n }\n }\n }\n\n /** Evaluate a type written in the footer; the expansion budget starts again. */\n evaluate(type: IrType): Evaluation {\n this.expansions = 0;\n return this.expand({ kind: \"type\", type, deep: false });\n }\n\n /** The type with references, `readonly` and indexed access resolved at the top. */\n expand(value: Evaluated): Evaluation {\n const { type } = value;\n switch (type.kind) {\n case \"readonly\":\n return this.expand({ ...value, type: type.type });\n case \"indexedAccess\":\n return this.indexedAccess(value, type.object, type.index);\n case \"reference\":\n return this.reference(value, type.name, type.typeArguments);\n case \"raw\":\n case \"tuple\":\n return OPAQUE;\n default:\n return value;\n }\n }\n\n private indexedAccess(value: Evaluated, object: IrType, index: IrType): Evaluation {\n const owner = this.expand({ ...value, type: object });\n return owner.kind === \"type\" ? this.index(owner, index) : owner;\n }\n\n private reference(value: Evaluated, name: string, args: readonly IrType[]): Evaluation {\n // Only references cost budget: re-expanding an already expanded value (as the checks after\n // `evaluate` do) is free, so a large evaluation does not leave its checks opaque.\n if (this.expansions++ > MAX_EXPANSIONS) {\n return OPAQUE;\n }\n if (name.startsWith(DEEP_PREFIX) && name.endsWith(\">\")) {\n const root = this.declared.get(name.slice(DEEP_PREFIX.length, -1));\n return root === undefined ? OPAQUE : this.expand({ kind: \"type\", type: root, deep: true });\n }\n const declared = args.length === 0 ? this.declared.get(name) : undefined;\n if (declared !== undefined) {\n return this.expand({ ...value, type: declared });\n }\n const [first, second] = args;\n if (first === undefined) {\n return OPAQUE;\n }\n const argument = this.expand({ ...value, type: first });\n if (argument.kind !== \"type\") {\n return argument;\n }\n return this.helper(name, argument, second);\n }\n\n private helper(name: string, argument: Evaluated, second: IrType | undefined): Evaluation {\n switch (name) {\n case \"NonNullable\":\n return this.withoutNullish(argument);\n case \"WithRequired\":\n case \"Readonly\":\n return argument;\n case \"Extract\":\n return second === undefined ? OPAQUE : this.extract(argument, second);\n case \"Omit\":\n return second === undefined ? OPAQUE : omitted(this, argument, second);\n default:\n return markerObject(name, argument) ?? OPAQUE;\n }\n }\n\n /**\n * The members of a union, each expanded; an intersection with unions in it is distributed over\n * them (`A & (B | C)` is `(A & B) | (A & C)`), as TypeScript normalizes it. A type that is not a\n * union is its only member. A union with an `any` or `unknown` member is that keyword alone.\n */\n membersOf(value: Evaluated): readonly Evaluation[] {\n const expanded = this.expand(value);\n if (expanded.kind !== \"type\") {\n return [expanded];\n }\n const { type } = expanded;\n if (type.kind === \"union\") {\n return absorbed(\n type.types.flatMap((member) => this.membersOf({ ...expanded, type: member })),\n );\n }\n return type.kind === \"intersection\" ? this.distributed(expanded, type.types) : [expanded];\n }\n\n private distributed(value: Evaluated, parts: readonly IrType[]): readonly Evaluation[] {\n const memberLists = parts.map((part) => this.membersOf({ ...value, type: part }));\n const size = memberLists.reduce((product, list) => product * list.length, 1);\n if (size > MAX_DISTRIBUTED || memberLists.some((list) => list.some((m) => m.kind !== \"type\"))) {\n return [OPAQUE];\n }\n let combinations: IrType[][] = [[]];\n for (const list of memberLists as Evaluated[][]) {\n combinations = combinations.flatMap((done) => list.map((member) => [...done, member.type]));\n }\n return combinations.map((types) => ({ ...value, type: intersectionType(types) }));\n }\n\n private withoutNullish(value: Evaluated): Evaluation {\n const members = this.membersOf(value);\n if (members.some((member) => member.kind !== \"type\")) {\n return OPAQUE;\n }\n const kept = (members as Evaluated[]).filter((member) => !isNullish(member.type));\n return { ...value, type: unionType(kept.map((member) => member.type)) };\n }\n\n /** `Extract<T, { key: unknown }>` keeps the members that have `key`; other probes are opaque. */\n private extract(value: Evaluated, probe: IrType): Evaluation {\n const [member] = probe.kind === \"object\" ? probe.members : [];\n if (probe.kind !== \"object\" || probe.members.length !== 1 || member?.kind !== \"property\") {\n return OPAQUE;\n }\n return extracted(this, value, propertyKey(member.name));\n }\n\n /** `value[index]` for a string literal, `string` or `number` index. */\n index(value: Evaluated, index: IrType): Evaluation {\n const owner = this.expand(value);\n if (owner.kind !== \"type\") {\n return owner;\n }\n if (this.membersOf(owner).length > 1) {\n return this.unionIndex(owner, index);\n }\n const { type } = owner;\n switch (type.kind) {\n case \"object\":\n return this.memberType(owner, type.members, index);\n case \"intersection\":\n return this.partsIndex(owner, type.types, index);\n case \"union\":\n return this.unionIndex(owner, index);\n case \"array\":\n return isNumberIndex(index) ? this.flattened(owner, type.element) : builtInIndex(index);\n case \"keyword\":\n return type.keyword === \"never\" ? owner : builtInIndex(index);\n default:\n return builtInIndex(index);\n }\n }\n\n private memberType(owner: Evaluated, members: readonly IrMember[], index: IrType): Evaluation {\n const key = indexKey(index);\n const property = members.find(\n (member) => member.kind === \"property\" && key !== null && propertyKey(member.name) === key,\n );\n if (property !== undefined) {\n return this.flattened(owner, property.type);\n }\n const signature = members.find((member) => member.kind === \"indexSignature\");\n if (signature !== undefined) {\n return this.flattened(owner, signature.type);\n }\n return key === null || isObjectBuiltIn(key) ? OPAQUE : MISSING;\n }\n\n private partsIndex(owner: Evaluated, parts: readonly IrType[], index: IrType): Evaluation {\n if (isNeverIntersection(this, owner, parts)) {\n return { ...owner, type: NEVER };\n }\n const found = parts.map((type) => this.index({ ...owner, type }, index));\n if (found.some((part) => part.kind === \"opaque\")) {\n return OPAQUE;\n }\n const read = parts.map((type, at) => ({ type, found: found[at] as Evaluation }));\n const types = declaredFirst(this, owner, indexKey(index), read).flatMap((part) =>\n part.kind === \"type\" ? [part.type] : [],\n );\n return types.length === 0 ? MISSING : { ...owner, type: intersectionType(types) };\n }\n\n private unionIndex(owner: Evaluated, index: IrType): Evaluation {\n const found = this.membersOf(owner).map((member) =>\n member.kind === \"type\" ? this.index(member, index) : member,\n );\n if (found.some((member) => member.kind === \"missing\")) {\n return MISSING;\n }\n if (found.some((member) => member.kind === \"opaque\")) {\n return OPAQUE;\n }\n return { ...owner, type: unionType((found as Evaluated[]).map((member) => member.type)) };\n }\n\n /**\n * A member read through `FlattenedDeepRequired`: a value that is only arrays (and `undefined` or\n * `null`) is replaced by its elements, anything else loses `undefined` and `null`.\n */\n private flattened(owner: Evaluated, type: IrType): Evaluation {\n const member: Evaluated = { ...owner, type };\n if (!owner.deep) {\n return this.expand(member);\n }\n const members = this.membersOf(member);\n if (members.some((candidate) => candidate.kind !== \"type\")) {\n return OPAQUE;\n }\n const present = (members as Evaluated[]).filter((candidate) => !isNullish(candidate.type));\n const elements = present.map((candidate) => arrayElement(candidate.type));\n if (present.length > 0 && elements.every((element) => element !== null)) {\n return this.expand({ ...owner, type: unionType(elements as IrType[]) });\n }\n return { ...owner, type: unionType(present.map((candidate) => candidate.type)) };\n }\n}\n\nfunction isNullish(type: IrType): boolean {\n return type.kind === \"keyword\" && NULLISH.has(type.keyword);\n}\n\n/** The element of an expanded member; expanding already dropped `readonly`. */\nfunction arrayElement(type: IrType): IrType | null {\n return type.kind === \"array\" ? type.element : null;\n}\n\nfunction intersectionType(types: readonly IrType[]): IrType {\n return types.length === 1 ? (types[0] as IrType) : { kind: \"intersection\", types };\n}\n\nfunction indexKey(index: IrType): string | null {\n if (index.kind === \"stringLiteral\") {\n return index.value;\n }\n return index.kind === \"numberLiteral\" ? String(index.value) : null;\n}\n\nfunction isNumberIndex(index: IrType): boolean {\n const key = indexKey(index);\n return (index.kind === \"keyword\" && index.keyword === \"number\") || /^\\d+$/.test(key ?? \"\");\n}\n\nfunction isObjectBuiltIn(key: string): boolean {\n return key in {};\n}\n\n/** A key of a primitive or an array: a built-in member is opaque, any other key is missing. */\nfunction builtInIndex(index: IrType): Evaluation {\n const key = indexKey(index);\n const isBuiltIn = key === null || key in String.prototype || key in Array.prototype;\n return isBuiltIn || key in Number.prototype ? OPAQUE : MISSING;\n}\n"],"names":[],"mappings":";;;AA4BA,MAAM,cAAA,GAAiB,GAAA;AACvB,MAAM,WAAA,GAAc,wBAAA;AAEpB,MAAM,eAAA,GAAkB,EAAA;AACxB,MAAM,0BAA+B,IAAI,GAAA,CAAI,CAAC,MAAA,EAAQ,WAAW,CAAC,CAAA;AAE3D,MAAM,aAAA,CAAc;AAAA,EACR,QAAA,uBAAe,GAAA,EAAoB;AAAA,EAC5C,UAAA,GAAa,CAAA;AAAA,EAErB,YAAY,YAAA,EAAwC;AAClD,IAAA,KAAA,MAAW,eAAe,YAAA,EAAc;AACtC,MAAA,IAAI,WAAA,CA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AAsB;AAC7C,EAAA,OAAO,OAAO,EAAC;AACjB;AAGA,SAAS,aAAa,KAAA,EAA2B;AAC/C,EAAA,MAAM,GAAA,GAAM,SAAS,KAAK,CAAA;AAC1B,EAAA,MAAM,YAAY,GAAA,KAAQ,IAAA,IAAQ,OAAO,MAAA,CAAO,SAAA,IAAa,OAAO,KAAA,CAAM,SAAA;AAC1E,EAAA,OAAO,SAAA,IAAa,GAAA,IAAO,MAAA,CAAO,SAAA,GAAY,MAAA,GAAS,OAAA;AACzD;;"}
@@ -0,0 +1,172 @@
1
+ 'use strict';
2
+
3
+ const constructors = require('../../../domain/ir/constructors.cjs');
4
+ const propertyName = require('../../../domain/ir/property-name.cjs');
5
+ const evaluation = require('./evaluation.cjs');
6
+
7
+ function objectParts(types, value, parts) {
8
+ return parts.flatMap((part) => {
9
+ const members = types.membersOf({ ...value, type: part });
10
+ const [only] = members;
11
+ if (members.length !== 1 || only?.kind !== "type") {
12
+ return [null];
13
+ }
14
+ if (only.type.kind === "intersection") {
15
+ return objectParts(types, only, only.type.types);
16
+ }
17
+ return [only.type.kind === "object" ? only.type : null];
18
+ });
19
+ }
20
+ function unitOf(type) {
21
+ switch (type.kind) {
22
+ case "stringLiteral":
23
+ return `s:${type.value}`;
24
+ case "numberLiteral":
25
+ return `n:${type.value}`;
26
+ case "booleanLiteral":
27
+ return `b:${type.value}`;
28
+ case "keyword":
29
+ return type.keyword === "null" || type.keyword === "undefined" ? type.keyword : null;
30
+ default:
31
+ return null;
32
+ }
33
+ }
34
+ function unitsOf(types, value, type) {
35
+ const units = types.membersOf({ ...value, type }).map((member) => {
36
+ return member.kind === "type" ? unitOf(member.type) : null;
37
+ });
38
+ return units.includes(null) ? null : new Set(units);
39
+ }
40
+ function propertiesNamed(objects, key) {
41
+ return objects.flatMap((object) => {
42
+ const members = object.members;
43
+ return members.filter(
44
+ (member) => member.kind === "property" && evaluation.propertyKey(member.name) === key
45
+ );
46
+ });
47
+ }
48
+ function isNeverProperty(types, value, found) {
49
+ if (found.length < 2 || found.every((property) => property.isOptional)) {
50
+ return false;
51
+ }
52
+ const sets = found.map((property) => unitsOf(types, value, property.type));
53
+ if (sets.includes(null)) {
54
+ return false;
55
+ }
56
+ const [first, ...rest] = sets;
57
+ const shared = [...first].filter((unit) => rest.every((set) => set.has(unit)));
58
+ return shared.length === 0;
59
+ }
60
+ function isNullishObject(types, value, parts) {
61
+ const singles = parts.map((part) => {
62
+ const members = types.membersOf({ ...value, type: part });
63
+ const [only] = members;
64
+ return members.length === 1 && only?.kind === "type" ? only.type : null;
65
+ });
66
+ const isNullish = (type) => type?.kind === "keyword" && (type.keyword === "null" || type.keyword === "undefined");
67
+ return singles.some(isNullish) && singles.some((type) => type?.kind === "object");
68
+ }
69
+ function isNeverIntersection(types, value, parts) {
70
+ if (isNullishObject(types, value, parts)) {
71
+ return true;
72
+ }
73
+ const objects = objectParts(types, value, parts).filter((part) => part !== null);
74
+ if (objects.length < 2) {
75
+ return false;
76
+ }
77
+ const keys = new Set(
78
+ objects.flatMap(
79
+ (object) => object.members.flatMap(
80
+ (member) => member.kind === "property" ? [evaluation.propertyKey(member.name)] : []
81
+ )
82
+ )
83
+ );
84
+ const valueOfKeys = { ...value, deep: false };
85
+ return [...keys].some(
86
+ (key) => isNeverProperty(types, valueOfKeys, propertiesNamed(objects, key))
87
+ );
88
+ }
89
+ function isSignatureOnly(types, value, key) {
90
+ const members = types.membersOf(value);
91
+ const [only] = members;
92
+ if (key === null || members.length !== 1 || only?.kind !== "type" || only.type.kind !== "object") {
93
+ return false;
94
+ }
95
+ const { members: declared } = only.type;
96
+ const hasSignature = declared.some((member) => member.kind === "indexSignature");
97
+ return hasSignature && propertiesNamed([only.type], key).length === 0;
98
+ }
99
+ function declaredFirst(types, value, key, parts) {
100
+ const bySignature = parts.map(({ type }) => isSignatureOnly(types, { ...value, type }, key));
101
+ const isDeclared = parts.some(({ found }, at) => found.kind === "type" && !bySignature[at]);
102
+ return parts.filter((_, at) => !(isDeclared && bySignature[at])).map(({ found }) => found);
103
+ }
104
+ function hasKey(value, key) {
105
+ const { type } = value;
106
+ if (type.kind === "intersection") {
107
+ return type.types.some((part) => hasKey({ ...value, type: part }, key));
108
+ }
109
+ if (type.kind !== "object") {
110
+ return false;
111
+ }
112
+ return propertiesNamed([type], key).some((property) => value.deep || !property.isOptional);
113
+ }
114
+ function extracted(types, value, key) {
115
+ const members = types.membersOf(value);
116
+ if (members.some((member) => member.kind !== "type")) {
117
+ return evaluation.OPAQUE;
118
+ }
119
+ const kept = members.filter((member) => hasKey(member, key));
120
+ if (kept.length === 0) {
121
+ return evaluation.MISSING;
122
+ }
123
+ return { ...value, type: evaluation.unionType(kept.map((member) => member.type)) };
124
+ }
125
+ function omittedKeys(types, value, keys) {
126
+ const members = types.membersOf({ ...value, type: keys });
127
+ const names = members.map(
128
+ (member) => member.kind === "type" && member.type.kind === "stringLiteral" ? member.type.value : null
129
+ );
130
+ return names.includes(null) ? null : new Set(names);
131
+ }
132
+ function hasSharedProperty(members) {
133
+ const names = members.flatMap(
134
+ (member) => member.kind === "property" ? [evaluation.propertyKey(member.name)] : []
135
+ );
136
+ return new Set(names).size !== names.length;
137
+ }
138
+ function omitted(types, value, keys) {
139
+ const names = omittedKeys(types, value, keys);
140
+ const objects = objectParts(types, value, [value.type]);
141
+ if (names === null || objects.length === 0 || objects.includes(null)) {
142
+ return evaluation.OPAQUE;
143
+ }
144
+ const members = objects.flatMap((object) => object.members);
145
+ if (hasSharedProperty(members)) {
146
+ return evaluation.OPAQUE;
147
+ }
148
+ const signatures = members.filter((member) => member.kind === "indexSignature");
149
+ const kept = signatures.length > 0 ? signatures : members.filter(
150
+ (member) => member.kind !== "property" || !names.has(evaluation.propertyKey(member.name))
151
+ );
152
+ return { ...value, type: { kind: "object", members: kept } };
153
+ }
154
+ const READ_WRITE_MARKER_KEYS = /* @__PURE__ */ new Map([
155
+ ["$Read", "$read"],
156
+ ["$Write", "$write"]
157
+ ]);
158
+ function markerObject(name, argument) {
159
+ const key = READ_WRITE_MARKER_KEYS.get(name);
160
+ if (key === void 0) {
161
+ return null;
162
+ }
163
+ const member = constructors.irProperty(propertyName.toPropertyName(key), argument.type, { isReadonly: true });
164
+ return { ...argument, type: constructors.irObject([member]) };
165
+ }
166
+
167
+ exports.declaredFirst = declaredFirst;
168
+ exports.extracted = extracted;
169
+ exports.isNeverIntersection = isNeverIntersection;
170
+ exports.markerObject = markerObject;
171
+ exports.omitted = omitted;
172
+ //# sourceMappingURL=type-rules.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-rules.cjs","sources":["../../../../src/application/transform/footer/type-rules.ts"],"sourcesContent":["import { irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrMember,\n IrObjectType,\n IrPropertySignature,\n IrType,\n} from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {\n type Evaluated,\n type Evaluation,\n MISSING,\n OPAQUE,\n propertyKey,\n unionType,\n} from \"./evaluation.js\";\n\n/**\n * Rules of TypeScript about intersections, `Omit` and `Extract` that the `--enum-values` check\n * needs (ADR-027). They read the types as written, before `FlattenedDeepRequired`.\n */\n\n/** The part of the evaluator these rules use. */\nexport interface TypeExpansion {\n membersOf(value: Evaluated): readonly Evaluation[];\n}\n\n/** A unit value of a type: a literal, `null` or `undefined`. */\ntype Unit = string;\n\n/**\n * The parts an intersection is made of, nested intersections flattened: each object type, or\n * `null` for a part that is not one.\n */\nfunction objectParts(\n types: TypeExpansion,\n value: Evaluated,\n parts: readonly IrType[],\n): (IrObjectType | null)[] {\n return parts.flatMap((part) => {\n const members = types.membersOf({ ...value, type: part });\n const [only] = members;\n if (members.length !== 1 || only?.kind !== \"type\") {\n return [null];\n }\n if (only.type.kind === \"intersection\") {\n return objectParts(types, only, only.type.types);\n }\n return [only.type.kind === \"object\" ? only.type : null];\n });\n}\n\nfunction unitOf(type: IrType): Unit | null {\n switch (type.kind) {\n case \"stringLiteral\":\n return `s:${type.value}`;\n case \"numberLiteral\":\n return `n:${type.value}`;\n case \"booleanLiteral\":\n return `b:${type.value}`;\n case \"keyword\":\n return type.keyword === \"null\" || type.keyword === \"undefined\" ? type.keyword : null;\n default:\n return null;\n }\n}\n\n/** The unit values of a type made only of units, or `null` where it has other values. */\nfunction unitsOf(types: TypeExpansion, value: Evaluated, type: IrType): ReadonlySet<Unit> | null {\n const units = types.membersOf({ ...value, type }).map((member) => {\n return member.kind === \"type\" ? unitOf(member.type) : null;\n });\n return units.includes(null) ? null : new Set(units as Unit[]);\n}\n\nfunction propertiesNamed(objects: readonly IrObjectType[], key: string): IrPropertySignature[] {\n return objects.flatMap((object) => {\n const members: readonly IrMember[] = object.members;\n return members.filter(\n (member): member is IrPropertySignature =>\n member.kind === \"property\" && propertyKey(member.name) === key,\n );\n });\n}\n\n/** Whether properties of the same name share no unit value, one of them required. */\nfunction isNeverProperty(\n types: TypeExpansion,\n value: Evaluated,\n found: IrPropertySignature[],\n): boolean {\n if (found.length < 2 || found.every((property) => property.isOptional)) {\n return false;\n }\n const sets = found.map((property) => unitsOf(types, value, property.type));\n if (sets.includes(null)) {\n return false;\n }\n // At least two properties, so at least two sets.\n const [first, ...rest] = sets as [ReadonlySet<Unit>, ...ReadonlySet<Unit>[]];\n const shared = [...first].filter((unit) => rest.every((set) => set.has(unit)));\n return shared.length === 0;\n}\n\n/** Whether an intersection has `null` or `undefined` next to an object: `null & { a: 1 }`. */\nfunction isNullishObject(types: TypeExpansion, value: Evaluated, parts: readonly IrType[]) {\n const singles = parts.map((part) => {\n const members = types.membersOf({ ...value, type: part });\n const [only] = members;\n return members.length === 1 && only?.kind === \"type\" ? only.type : null;\n });\n const isNullish = (type: IrType | null) =>\n type?.kind === \"keyword\" && (type.keyword === \"null\" || type.keyword === \"undefined\");\n return singles.some(isNullish) && singles.some((type) => type?.kind === \"object\");\n}\n\n/**\n * Whether TypeScript reduces an intersection to `never`: `null` or `undefined` meets an object,\n * or objects share a property with literal types that have no value in common, one of them\n * requiring it (`{ a: \"x\" } & { a: \"y\" }`). Other properties are left alone, so the answer is\n * sure where it is yes.\n */\nexport function isNeverIntersection(\n types: TypeExpansion,\n value: Evaluated,\n parts: readonly IrType[],\n): boolean {\n if (isNullishObject(types, value, parts)) {\n return true;\n }\n const objects = objectParts(types, value, parts).filter((part) => part !== null);\n if (objects.length < 2) {\n return false;\n }\n const keys = new Set(\n objects.flatMap((object) =>\n object.members.flatMap((member) =>\n member.kind === \"property\" ? [propertyKey(member.name)] : [],\n ),\n ),\n );\n const valueOfKeys = { ...value, deep: false };\n return [...keys].some((key) =>\n isNeverProperty(types, valueOfKeys, propertiesNamed(objects, key)),\n );\n}\n\n/** Whether `key` reaches only an index signature of this object: it declares no such property. */\nfunction isSignatureOnly(types: TypeExpansion, value: Evaluated, key: string | null): boolean {\n const members = types.membersOf(value);\n const [only] = members;\n if (\n key === null ||\n members.length !== 1 ||\n only?.kind !== \"type\" ||\n only.type.kind !== \"object\"\n ) {\n return false;\n }\n const { members: declared } = only.type;\n const hasSignature = declared.some((member) => member.kind === \"indexSignature\");\n return hasSignature && propertiesNamed([only.type], key).length === 0;\n}\n\n/**\n * The parts of an intersection indexed by `index`, as TypeScript reads them: where one part\n * declares the property, the index signatures of the others do not take part\n * (`{ a: X } & { [key: string]: Y }` gives `X` for `a`).\n */\nexport function declaredFirst(\n types: TypeExpansion,\n value: Evaluated,\n key: string | null,\n parts: readonly { readonly type: IrType; readonly found: Evaluation }[],\n): Evaluation[] {\n const bySignature = parts.map(({ type }) => isSignatureOnly(types, { ...value, type }, key));\n const isDeclared = parts.some(({ found }, at) => found.kind === \"type\" && !bySignature[at]);\n return parts.filter((_, at) => !(isDeclared && bySignature[at])).map(({ found }) => found);\n}\n\n/**\n * Whether a member of `membersOf` has `key` as a property that `{ key: unknown }` accepts: written\n * and, outside `FlattenedDeepRequired`, required. An index signature does not count, as in\n * TypeScript. Such a member is expanded, parts included, so it is an object, an intersection of\n * members, or a primitive or array type, which has no such property; a type the evaluator cannot\n * read makes `membersOf` opaque instead.\n */\nfunction hasKey(value: Evaluated, key: string): boolean {\n const { type } = value;\n if (type.kind === \"intersection\") {\n return type.types.some((part) => hasKey({ ...value, type: part }, key));\n }\n if (type.kind !== \"object\") {\n return false;\n }\n return propertiesNamed([type], key).some((property) => value.deep || !property.isOptional);\n}\n\n/**\n * `Extract<T, { key: unknown }>`: the members of `T` that have `key`. When none has it the\n * result is `never`; it is `missing` here, as the location then types nothing.\n */\nexport function extracted(types: TypeExpansion, value: Evaluated, key: string): Evaluation {\n const members = types.membersOf(value);\n if (members.some((member) => member.kind !== \"type\")) {\n return OPAQUE;\n }\n const kept = (members as Evaluated[]).filter((member) => hasKey(member, key));\n if (kept.length === 0) {\n return MISSING;\n }\n return { ...value, type: unionType(kept.map((member) => member.type)) };\n}\n\nfunction omittedKeys(types: TypeExpansion, value: Evaluated, keys: IrType): Set<string> | null {\n const members = types.membersOf({ ...value, type: keys });\n const names = members.map((member) =>\n member.kind === \"type\" && member.type.kind === \"stringLiteral\" ? member.type.value : null,\n );\n return names.includes(null) ? null : new Set(names as string[]);\n}\n\n/** Whether two members name the same property: merging them would need their intersection. */\nfunction hasSharedProperty(members: readonly IrMember[]): boolean {\n const names = members.flatMap((member) =>\n member.kind === \"property\" ? [propertyKey(member.name)] : [],\n );\n return new Set(names).size !== names.length;\n}\n\n/**\n * `Omit<T, K>` for literal keys `K` over an object or an intersection of objects. A string index\n * signature makes `keyof T` all strings, so only the index signatures are left.\n */\nexport function omitted(types: TypeExpansion, value: Evaluated, keys: IrType): Evaluation {\n const names = omittedKeys(types, value, keys);\n const objects = objectParts(types, value, [value.type]);\n if (names === null || objects.length === 0 || objects.includes(null)) {\n return OPAQUE;\n }\n const members = (objects as IrObjectType[]).flatMap((object) => object.members);\n if (hasSharedProperty(members)) {\n return OPAQUE;\n }\n const signatures = members.filter((member) => member.kind === \"indexSignature\");\n const kept =\n signatures.length > 0\n ? signatures\n : members.filter(\n (member) => member.kind !== \"property\" || !names.has(propertyKey(member.name)),\n );\n return { ...value, type: { kind: \"object\", members: kept } };\n}\n\n/** The `--read-write-markers` types and their one member (`READ_WRITE_MARKER_TYPES`). */\nconst READ_WRITE_MARKER_KEYS: ReadonlyMap<string, string> = new Map([\n [\"$Read\", \"$read\"],\n [\"$Write\", \"$write\"],\n]);\n\n/** `$Read<T>` is `{ readonly $read: T }`: an object, which holds no enum value. */\nexport function markerObject(name: string, argument: Evaluated): Evaluated | null {\n const key = READ_WRITE_MARKER_KEYS.get(name);\n if (key === undefined) {\n return null;\n }\n const member = irProperty(toPropertyName(key), argument.type, { isReadonly: true });\n return { ...argument, type: irObject([member]) };\n}\n"],"names":["propertyKey","OPAQUE","MISSING","unionType","irProperty","toPropertyName","irObject"],"mappings":";;;;;;AAkCA,SAAS,WAAA,CACP,KAAA,EACA,KAAA,EACA,KAAA,EACyB;AACzB,EAAA,OAAO,KAAA,CAAM,OAAA,CAAQ,CAAC,IAAA,KAAS;AAC7B,IAAA,MAAM,OAAA,GAAU,MAAM,SAAA,CAAU,EAAE,GAAG,KAAA,EAAO,IAAA,EAAM,MAAM,CAAA;AACxD,IAAA,MAAM,CAAC,IAAI,CAAA,GAAI,OAAA;AACf,IAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,CAAA,IAAK,IAAA,EAAM,SAAS,MAAA,EAAQ;AACjD,MAAA,OAAO,CAAC,IAAI,CAAA;AAAA,IACd;AACA,IAAA,IAAI,IAAA,CAAK,IAAA,CAAK,IAAA,KAAS,cAAA,EAAgB;AACrC,MAAA,OAAO,WAAA,CAAY,KAAA,EAAO,IAAA,EAAM,IAAA,CAAK,KAAK,KAAK,CAAA;AAAA,IACjD;AACA,IAAA,OAAO,CAAC,IAAA,CAAK,IAAA,CAAK,SAAS,QAAA,GAAW,IAAA,CAAK,OAAO,IAAI,CAAA;AAAA,EACxD,CAAC,CAAA;AACH;AAEA,SAAS,OAAO,IAAA,EAA2B;AACzC,EAAA,QAAQ,KAAK,IAAA;AAAM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AAO,IAAA,KAAS,UAAA,IAAc,CAAC,KAAA,CAAM,GAAA,CAAID,sBAAA,CAAY,MAAA,CAAO,IAAI,CAAC;AAAA,GAC/E;AACN,EAAA,OAAO,EAAE,GAAG,KAAA,EAAO,IAAA,EAAM,EAAE,IAAA,EAAM,QAAA,EAAU,OAAA,EAAS,IAAA,EAAK,EAAE;AAC7D;AAGA,MAAM,sBAAA,uBAA0D,GAAA,CAAI;AAAA,EAClE,CAAC,SAAS,OAAO,CAAA;AAAA,EACjB,CAAC,UAAU,QAAQ;AACrB,CAAC,CAAA;AAGM,SAAS,YAAA,CAAa,MAAc,QAAA,EAAuC;AAChF,EAAA,MAAM,GAAA,GAAM,sBAAA,CAAuB,GAAA,CAAI,IAAI,CAAA;AAC3C,EAAA,IAAI,QAAQ,MAAA,EAAW;AACrB,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,MAAA,GAASI,uBAAA,CAAWC,2BAAA,CAAe,GAAG,CAAA,EAAG,SAAS,IAAA,EAAM,EAAE,UAAA,EAAY,IAAA,EAAM,CAAA;AAClF,EAAA,OAAO,EAAE,GAAG,QAAA,EAAU,IAAA,EAAMC,sBAAS,CAAC,MAAM,CAAC,CAAA,EAAE;AACjD;;;;;;"}
@@ -0,0 +1,166 @@
1
+ import { irProperty, irObject } from '../../../domain/ir/constructors.mjs';
2
+ import { toPropertyName } from '../../../domain/ir/property-name.mjs';
3
+ import { OPAQUE, propertyKey, MISSING, unionType } from './evaluation.mjs';
4
+
5
+ function objectParts(types, value, parts) {
6
+ return parts.flatMap((part) => {
7
+ const members = types.membersOf({ ...value, type: part });
8
+ const [only] = members;
9
+ if (members.length !== 1 || only?.kind !== "type") {
10
+ return [null];
11
+ }
12
+ if (only.type.kind === "intersection") {
13
+ return objectParts(types, only, only.type.types);
14
+ }
15
+ return [only.type.kind === "object" ? only.type : null];
16
+ });
17
+ }
18
+ function unitOf(type) {
19
+ switch (type.kind) {
20
+ case "stringLiteral":
21
+ return `s:${type.value}`;
22
+ case "numberLiteral":
23
+ return `n:${type.value}`;
24
+ case "booleanLiteral":
25
+ return `b:${type.value}`;
26
+ case "keyword":
27
+ return type.keyword === "null" || type.keyword === "undefined" ? type.keyword : null;
28
+ default:
29
+ return null;
30
+ }
31
+ }
32
+ function unitsOf(types, value, type) {
33
+ const units = types.membersOf({ ...value, type }).map((member) => {
34
+ return member.kind === "type" ? unitOf(member.type) : null;
35
+ });
36
+ return units.includes(null) ? null : new Set(units);
37
+ }
38
+ function propertiesNamed(objects, key) {
39
+ return objects.flatMap((object) => {
40
+ const members = object.members;
41
+ return members.filter(
42
+ (member) => member.kind === "property" && propertyKey(member.name) === key
43
+ );
44
+ });
45
+ }
46
+ function isNeverProperty(types, value, found) {
47
+ if (found.length < 2 || found.every((property) => property.isOptional)) {
48
+ return false;
49
+ }
50
+ const sets = found.map((property) => unitsOf(types, value, property.type));
51
+ if (sets.includes(null)) {
52
+ return false;
53
+ }
54
+ const [first, ...rest] = sets;
55
+ const shared = [...first].filter((unit) => rest.every((set) => set.has(unit)));
56
+ return shared.length === 0;
57
+ }
58
+ function isNullishObject(types, value, parts) {
59
+ const singles = parts.map((part) => {
60
+ const members = types.membersOf({ ...value, type: part });
61
+ const [only] = members;
62
+ return members.length === 1 && only?.kind === "type" ? only.type : null;
63
+ });
64
+ const isNullish = (type) => type?.kind === "keyword" && (type.keyword === "null" || type.keyword === "undefined");
65
+ return singles.some(isNullish) && singles.some((type) => type?.kind === "object");
66
+ }
67
+ function isNeverIntersection(types, value, parts) {
68
+ if (isNullishObject(types, value, parts)) {
69
+ return true;
70
+ }
71
+ const objects = objectParts(types, value, parts).filter((part) => part !== null);
72
+ if (objects.length < 2) {
73
+ return false;
74
+ }
75
+ const keys = new Set(
76
+ objects.flatMap(
77
+ (object) => object.members.flatMap(
78
+ (member) => member.kind === "property" ? [propertyKey(member.name)] : []
79
+ )
80
+ )
81
+ );
82
+ const valueOfKeys = { ...value, deep: false };
83
+ return [...keys].some(
84
+ (key) => isNeverProperty(types, valueOfKeys, propertiesNamed(objects, key))
85
+ );
86
+ }
87
+ function isSignatureOnly(types, value, key) {
88
+ const members = types.membersOf(value);
89
+ const [only] = members;
90
+ if (key === null || members.length !== 1 || only?.kind !== "type" || only.type.kind !== "object") {
91
+ return false;
92
+ }
93
+ const { members: declared } = only.type;
94
+ const hasSignature = declared.some((member) => member.kind === "indexSignature");
95
+ return hasSignature && propertiesNamed([only.type], key).length === 0;
96
+ }
97
+ function declaredFirst(types, value, key, parts) {
98
+ const bySignature = parts.map(({ type }) => isSignatureOnly(types, { ...value, type }, key));
99
+ const isDeclared = parts.some(({ found }, at) => found.kind === "type" && !bySignature[at]);
100
+ return parts.filter((_, at) => !(isDeclared && bySignature[at])).map(({ found }) => found);
101
+ }
102
+ function hasKey(value, key) {
103
+ const { type } = value;
104
+ if (type.kind === "intersection") {
105
+ return type.types.some((part) => hasKey({ ...value, type: part }, key));
106
+ }
107
+ if (type.kind !== "object") {
108
+ return false;
109
+ }
110
+ return propertiesNamed([type], key).some((property) => value.deep || !property.isOptional);
111
+ }
112
+ function extracted(types, value, key) {
113
+ const members = types.membersOf(value);
114
+ if (members.some((member) => member.kind !== "type")) {
115
+ return OPAQUE;
116
+ }
117
+ const kept = members.filter((member) => hasKey(member, key));
118
+ if (kept.length === 0) {
119
+ return MISSING;
120
+ }
121
+ return { ...value, type: unionType(kept.map((member) => member.type)) };
122
+ }
123
+ function omittedKeys(types, value, keys) {
124
+ const members = types.membersOf({ ...value, type: keys });
125
+ const names = members.map(
126
+ (member) => member.kind === "type" && member.type.kind === "stringLiteral" ? member.type.value : null
127
+ );
128
+ return names.includes(null) ? null : new Set(names);
129
+ }
130
+ function hasSharedProperty(members) {
131
+ const names = members.flatMap(
132
+ (member) => member.kind === "property" ? [propertyKey(member.name)] : []
133
+ );
134
+ return new Set(names).size !== names.length;
135
+ }
136
+ function omitted(types, value, keys) {
137
+ const names = omittedKeys(types, value, keys);
138
+ const objects = objectParts(types, value, [value.type]);
139
+ if (names === null || objects.length === 0 || objects.includes(null)) {
140
+ return OPAQUE;
141
+ }
142
+ const members = objects.flatMap((object) => object.members);
143
+ if (hasSharedProperty(members)) {
144
+ return OPAQUE;
145
+ }
146
+ const signatures = members.filter((member) => member.kind === "indexSignature");
147
+ const kept = signatures.length > 0 ? signatures : members.filter(
148
+ (member) => member.kind !== "property" || !names.has(propertyKey(member.name))
149
+ );
150
+ return { ...value, type: { kind: "object", members: kept } };
151
+ }
152
+ const READ_WRITE_MARKER_KEYS = /* @__PURE__ */ new Map([
153
+ ["$Read", "$read"],
154
+ ["$Write", "$write"]
155
+ ]);
156
+ function markerObject(name, argument) {
157
+ const key = READ_WRITE_MARKER_KEYS.get(name);
158
+ if (key === void 0) {
159
+ return null;
160
+ }
161
+ const member = irProperty(toPropertyName(key), argument.type, { isReadonly: true });
162
+ return { ...argument, type: irObject([member]) };
163
+ }
164
+
165
+ export { declaredFirst, extracted, isNeverIntersection, markerObject, omitted };
166
+ //# sourceMappingURL=type-rules.mjs.map