@skmtc/core 0.39.0 → 0.41.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 (373) hide show
  1. package/esm/context/CoreContext.js +22 -8
  2. package/esm/context/GenerateContext.d.ts +6 -5
  3. package/esm/context/GenerateContext.js +112 -38
  4. package/esm/context/ParseContext.d.ts +18 -1
  5. package/esm/context/ParseContext.js +102 -3
  6. package/esm/context/generateTypes.d.ts +33 -4
  7. package/esm/context/generateTypes.js +4 -0
  8. package/esm/context/toGenerationFailure.d.ts +21 -0
  9. package/esm/context/toGenerationFailure.js +38 -0
  10. package/esm/context/tryParseAt.d.ts +4 -1
  11. package/esm/context/tryParseAt.js +10 -3
  12. package/esm/dsl/CustomValue.d.ts +4 -0
  13. package/esm/dsl/CustomValue.js +8 -0
  14. package/esm/dsl/Definition.d.ts +10 -0
  15. package/esm/dsl/Definition.js +14 -0
  16. package/esm/dsl/PendingDefinition.d.ts +47 -0
  17. package/esm/dsl/PendingDefinition.js +83 -0
  18. package/esm/dsl/model/ModelDriver.d.ts +55 -1
  19. package/esm/dsl/model/ModelDriver.js +228 -51
  20. package/esm/dsl/model/toModelEntry.d.ts +1 -1
  21. package/esm/dsl/model/toModelEntry.js +1 -1
  22. package/esm/dsl/model/types.d.ts +1 -1
  23. package/esm/dsl/operation/gql/GqlOperationDriver.js +1 -4
  24. package/esm/dsl/webhook/WebhookDriver.js +1 -4
  25. package/esm/enrichments/parseEnrichmentUmbrella.d.ts +5 -6
  26. package/esm/enrichments/parseEnrichmentUmbrella.js +23 -8
  27. package/esm/enrichments/parseEnrichmentValue.d.ts +17 -0
  28. package/esm/enrichments/parseEnrichmentValue.js +32 -0
  29. package/esm/enrichments/readEnrichments.d.ts +5 -5
  30. package/esm/enrichments/readEnrichments.js +17 -7
  31. package/esm/helpers/collateExamples.js +15 -5
  32. package/esm/helpers/refFns.d.ts +6 -2
  33. package/esm/helpers/refFns.js +24 -7
  34. package/esm/mod.d.ts +2 -0
  35. package/esm/mod.js +2 -0
  36. package/esm/oas/array/Array.d.ts +19 -0
  37. package/esm/oas/array/Array.js +47 -0
  38. package/esm/oas/boolean/Boolean.d.ts +19 -0
  39. package/esm/oas/boolean/Boolean.js +51 -8
  40. package/esm/oas/example/Example.d.ts +4 -0
  41. package/esm/oas/example/Example.js +8 -0
  42. package/esm/oas/header/Header.d.ts +4 -0
  43. package/esm/oas/header/Header.js +8 -0
  44. package/esm/oas/integer/Integer.d.ts +19 -0
  45. package/esm/oas/integer/Integer.js +49 -0
  46. package/esm/oas/link/Link.d.ts +4 -0
  47. package/esm/oas/link/Link.js +8 -0
  48. package/esm/oas/number/Number.d.ts +19 -0
  49. package/esm/oas/number/Number.js +49 -0
  50. package/esm/oas/object/Object.d.ts +19 -0
  51. package/esm/oas/object/Object.js +68 -18
  52. package/esm/oas/operation/Operation.d.ts +8 -1
  53. package/esm/oas/operation/Operation.js +18 -5
  54. package/esm/oas/operation/toEffectiveParameters.d.ts +24 -0
  55. package/esm/oas/operation/toEffectiveParameters.js +42 -0
  56. package/esm/oas/parameter/Parameter.d.ts +4 -0
  57. package/esm/oas/parameter/Parameter.js +8 -0
  58. package/esm/oas/ref/DanglingRefError.d.ts +22 -0
  59. package/esm/oas/ref/DanglingRefError.js +33 -0
  60. package/esm/oas/ref/Ref.d.ts +152 -25
  61. package/esm/oas/ref/Ref.js +414 -26
  62. package/esm/oas/requestBody/RequestBody.d.ts +4 -0
  63. package/esm/oas/requestBody/RequestBody.js +8 -0
  64. package/esm/oas/response/Response.d.ts +4 -0
  65. package/esm/oas/response/Response.js +8 -0
  66. package/esm/oas/schema/siblings.d.ts +127 -0
  67. package/esm/oas/schema/siblings.js +250 -0
  68. package/esm/oas/securitySchemes/SecurityScheme.d.ts +16 -0
  69. package/esm/oas/securitySchemes/SecurityScheme.js +32 -0
  70. package/esm/oas/string/String.d.ts +19 -0
  71. package/esm/oas/string/String.js +47 -0
  72. package/esm/oas/union/Union.d.ts +32 -0
  73. package/esm/oas/union/Union.js +111 -0
  74. package/esm/oas/unknown/Unknown.d.ts +18 -0
  75. package/esm/oas/unknown/Unknown.js +38 -0
  76. package/esm/oas/void/Void.d.ts +4 -0
  77. package/esm/oas/void/Void.js +8 -0
  78. package/esm/oas/webhook/Webhook.d.ts +2 -2
  79. package/esm/oas/webhook/Webhook.js +4 -5
  80. package/esm/parse/allOfSystem.d.ts +32 -0
  81. package/esm/parse/allOfSystem.js +30 -0
  82. package/esm/parse/anyOfSystem.d.ts +68 -0
  83. package/esm/parse/anyOfSystem.js +107 -0
  84. package/esm/parse/securityRequirements.d.ts +6 -0
  85. package/esm/parse/securityRequirements.js +8 -0
  86. package/esm/parse/toSiblingKeywords.d.ts +28 -0
  87. package/esm/parse/toSiblingKeywords.js +109 -0
  88. package/esm/parse/v3-0/_merge-all-of/decompose-union.d.ts +8 -0
  89. package/esm/parse/v3-0/_merge-all-of/decompose-union.js +9 -1
  90. package/esm/parse/v3-0/_merge-all-of/generic-merge.d.ts +2 -3
  91. package/esm/parse/v3-0/_merge-all-of/generic-merge.js +2 -2
  92. package/esm/parse/v3-0/_merge-all-of/merge-array-constraints.d.ts +2 -2
  93. package/esm/parse/v3-0/_merge-all-of/merge-array-constraints.js +5 -5
  94. package/esm/parse/v3-0/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  95. package/esm/parse/v3-0/_merge-all-of/merge-boolean-constraints.js +2 -2
  96. package/esm/parse/v3-0/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  97. package/esm/parse/v3-0/_merge-all-of/merge-integer-constraints.js +2 -2
  98. package/esm/parse/v3-0/_merge-all-of/merge-intersection.d.ts +3 -2
  99. package/esm/parse/v3-0/_merge-all-of/merge-intersection.js +2 -2
  100. package/esm/parse/v3-0/_merge-all-of/merge-number-constraints.d.ts +2 -2
  101. package/esm/parse/v3-0/_merge-all-of/merge-number-constraints.js +2 -2
  102. package/esm/parse/v3-0/_merge-all-of/merge-object-constraints.d.ts +2 -2
  103. package/esm/parse/v3-0/_merge-all-of/merge-object-constraints.js +3 -3
  104. package/esm/parse/v3-0/_merge-all-of/merge-properties.d.ts +2 -2
  105. package/esm/parse/v3-0/_merge-all-of/merge-properties.js +2 -2
  106. package/esm/parse/v3-0/_merge-all-of/merge-string-constraints.d.ts +2 -2
  107. package/esm/parse/v3-0/_merge-all-of/merge-string-constraints.js +3 -3
  108. package/esm/parse/v3-0/_merge-all-of/merge-union.d.ts +10 -3
  109. package/esm/parse/v3-0/_merge-all-of/merge-union.js +50 -12
  110. package/esm/parse/v3-0/_merge-all-of/merge.d.ts +2 -2
  111. package/esm/parse/v3-0/_merge-all-of/merge.js +78 -27
  112. package/esm/parse/v3-0/_merge-all-of/nullable-merge.d.ts +4 -0
  113. package/esm/parse/v3-0/_merge-all-of/nullable-merge.js +9 -7
  114. package/esm/parse/v3-0/_merge-all-of/types.d.ts +33 -0
  115. package/esm/parse/v3-0/mediaType/toMediaTypeItemV3.js +4 -3
  116. package/esm/parse/v3-0/parameter/toParameterV3.js +4 -3
  117. package/esm/parse/v3-0/ref/toRefV31.d.ts +7 -1
  118. package/esm/parse/v3-0/ref/toRefV31.js +6 -3
  119. package/esm/parse/v3-0/schema/toSchemasV3.js +107 -15
  120. package/esm/parse/v3-1/_merge-all-of/decompose-union.d.ts +7 -1
  121. package/esm/parse/v3-1/_merge-all-of/decompose-union.js +8 -2
  122. package/esm/parse/v3-1/_merge-all-of/generic-merge.d.ts +2 -3
  123. package/esm/parse/v3-1/_merge-all-of/generic-merge.js +2 -2
  124. package/esm/parse/v3-1/_merge-all-of/merge-array-constraints.d.ts +3 -2
  125. package/esm/parse/v3-1/_merge-all-of/merge-array-constraints.js +5 -5
  126. package/esm/parse/v3-1/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  127. package/esm/parse/v3-1/_merge-all-of/merge-boolean-constraints.js +2 -2
  128. package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  129. package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -2
  130. package/esm/parse/v3-1/_merge-all-of/merge-intersection.d.ts +3 -2
  131. package/esm/parse/v3-1/_merge-all-of/merge-intersection.js +2 -2
  132. package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.d.ts +2 -2
  133. package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -2
  134. package/esm/parse/v3-1/_merge-all-of/merge-object-constraints.d.ts +2 -2
  135. package/esm/parse/v3-1/_merge-all-of/merge-object-constraints.js +3 -3
  136. package/esm/parse/v3-1/_merge-all-of/merge-properties.d.ts +2 -2
  137. package/esm/parse/v3-1/_merge-all-of/merge-properties.js +2 -2
  138. package/esm/parse/v3-1/_merge-all-of/merge-string-constraints.d.ts +2 -2
  139. package/esm/parse/v3-1/_merge-all-of/merge-string-constraints.js +3 -3
  140. package/esm/parse/v3-1/_merge-all-of/merge-union.d.ts +10 -3
  141. package/esm/parse/v3-1/_merge-all-of/merge-union.js +54 -15
  142. package/esm/parse/v3-1/_merge-all-of/merge.d.ts +3 -2
  143. package/esm/parse/v3-1/_merge-all-of/merge.js +88 -29
  144. package/esm/parse/v3-1/_merge-all-of/nullable-merge.d.ts +4 -0
  145. package/esm/parse/v3-1/_merge-all-of/nullable-merge.js +9 -7
  146. package/esm/parse/v3-1/_merge-all-of/types.d.ts +37 -0
  147. package/esm/parse/v3-1/mediaType/toMediaTypeItemV3.js +4 -3
  148. package/esm/parse/v3-1/parameter/toParameterV3.js +4 -3
  149. package/esm/parse/v3-1/ref/toRefV31.d.ts +7 -1
  150. package/esm/parse/v3-1/ref/toRefV31.js +6 -3
  151. package/esm/parse/v3-1/schema/toSchemasV3.js +111 -16
  152. package/esm/parse/v3-2/_merge-all-of/decompose-union.d.ts +7 -1
  153. package/esm/parse/v3-2/_merge-all-of/decompose-union.js +8 -2
  154. package/esm/parse/v3-2/_merge-all-of/generic-merge.d.ts +2 -3
  155. package/esm/parse/v3-2/_merge-all-of/generic-merge.js +2 -2
  156. package/esm/parse/v3-2/_merge-all-of/merge-array-constraints.d.ts +3 -2
  157. package/esm/parse/v3-2/_merge-all-of/merge-array-constraints.js +5 -5
  158. package/esm/parse/v3-2/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  159. package/esm/parse/v3-2/_merge-all-of/merge-boolean-constraints.js +2 -2
  160. package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  161. package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -2
  162. package/esm/parse/v3-2/_merge-all-of/merge-intersection.d.ts +3 -2
  163. package/esm/parse/v3-2/_merge-all-of/merge-intersection.js +2 -2
  164. package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.d.ts +2 -2
  165. package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -2
  166. package/esm/parse/v3-2/_merge-all-of/merge-object-constraints.d.ts +2 -2
  167. package/esm/parse/v3-2/_merge-all-of/merge-object-constraints.js +3 -3
  168. package/esm/parse/v3-2/_merge-all-of/merge-properties.d.ts +2 -2
  169. package/esm/parse/v3-2/_merge-all-of/merge-properties.js +2 -2
  170. package/esm/parse/v3-2/_merge-all-of/merge-string-constraints.d.ts +2 -2
  171. package/esm/parse/v3-2/_merge-all-of/merge-string-constraints.js +3 -3
  172. package/esm/parse/v3-2/_merge-all-of/merge-union.d.ts +10 -3
  173. package/esm/parse/v3-2/_merge-all-of/merge-union.js +54 -15
  174. package/esm/parse/v3-2/_merge-all-of/merge.d.ts +3 -2
  175. package/esm/parse/v3-2/_merge-all-of/merge.js +88 -29
  176. package/esm/parse/v3-2/_merge-all-of/nullable-merge.d.ts +4 -0
  177. package/esm/parse/v3-2/_merge-all-of/nullable-merge.js +9 -7
  178. package/esm/parse/v3-2/_merge-all-of/types.d.ts +37 -0
  179. package/esm/parse/v3-2/mediaType/toMediaTypeItemV3.js +4 -3
  180. package/esm/parse/v3-2/parameter/toParameterV3.js +4 -3
  181. package/esm/parse/v3-2/ref/toRefV31.d.ts +7 -1
  182. package/esm/parse/v3-2/ref/toRefV31.js +6 -3
  183. package/esm/parse/v3-2/schema/toSchemasV3.js +111 -16
  184. package/esm/types/OasBase.d.ts +1 -1
  185. package/esm/types/Settings.d.ts +44 -0
  186. package/esm/types/Settings.js +9 -0
  187. package/package.json +5 -1
  188. package/script/context/CoreContext.js +22 -8
  189. package/script/context/GenerateContext.d.ts +6 -5
  190. package/script/context/GenerateContext.js +112 -38
  191. package/script/context/ParseContext.d.ts +18 -1
  192. package/script/context/ParseContext.js +102 -3
  193. package/script/context/generateTypes.d.ts +33 -4
  194. package/script/context/generateTypes.js +4 -0
  195. package/script/context/toGenerationFailure.d.ts +21 -0
  196. package/script/context/toGenerationFailure.js +43 -0
  197. package/script/context/tryParseAt.d.ts +4 -1
  198. package/script/context/tryParseAt.js +10 -3
  199. package/script/dsl/CustomValue.d.ts +4 -0
  200. package/script/dsl/CustomValue.js +8 -0
  201. package/script/dsl/Definition.d.ts +10 -0
  202. package/script/dsl/Definition.js +14 -0
  203. package/script/dsl/PendingDefinition.d.ts +47 -0
  204. package/script/dsl/PendingDefinition.js +87 -0
  205. package/script/dsl/model/ModelDriver.d.ts +55 -1
  206. package/script/dsl/model/ModelDriver.js +231 -52
  207. package/script/dsl/model/toModelEntry.d.ts +1 -1
  208. package/script/dsl/model/toModelEntry.js +1 -1
  209. package/script/dsl/model/types.d.ts +1 -1
  210. package/script/dsl/operation/gql/GqlOperationDriver.js +1 -4
  211. package/script/dsl/webhook/WebhookDriver.js +1 -4
  212. package/script/enrichments/parseEnrichmentUmbrella.d.ts +5 -6
  213. package/script/enrichments/parseEnrichmentUmbrella.js +23 -41
  214. package/script/enrichments/parseEnrichmentValue.d.ts +17 -0
  215. package/script/enrichments/parseEnrichmentValue.js +69 -0
  216. package/script/enrichments/readEnrichments.d.ts +5 -5
  217. package/script/enrichments/readEnrichments.js +17 -40
  218. package/script/helpers/collateExamples.js +15 -5
  219. package/script/helpers/refFns.d.ts +6 -2
  220. package/script/helpers/refFns.js +24 -7
  221. package/script/mod.d.ts +2 -0
  222. package/script/mod.js +2 -0
  223. package/script/oas/array/Array.d.ts +19 -0
  224. package/script/oas/array/Array.js +47 -0
  225. package/script/oas/boolean/Boolean.d.ts +19 -0
  226. package/script/oas/boolean/Boolean.js +51 -8
  227. package/script/oas/example/Example.d.ts +4 -0
  228. package/script/oas/example/Example.js +8 -0
  229. package/script/oas/header/Header.d.ts +4 -0
  230. package/script/oas/header/Header.js +8 -0
  231. package/script/oas/integer/Integer.d.ts +19 -0
  232. package/script/oas/integer/Integer.js +49 -0
  233. package/script/oas/link/Link.d.ts +4 -0
  234. package/script/oas/link/Link.js +8 -0
  235. package/script/oas/number/Number.d.ts +19 -0
  236. package/script/oas/number/Number.js +49 -0
  237. package/script/oas/object/Object.d.ts +19 -0
  238. package/script/oas/object/Object.js +68 -18
  239. package/script/oas/operation/Operation.d.ts +8 -1
  240. package/script/oas/operation/Operation.js +18 -5
  241. package/script/oas/operation/toEffectiveParameters.d.ts +24 -0
  242. package/script/oas/operation/toEffectiveParameters.js +47 -0
  243. package/script/oas/parameter/Parameter.d.ts +4 -0
  244. package/script/oas/parameter/Parameter.js +8 -0
  245. package/script/oas/ref/DanglingRefError.d.ts +22 -0
  246. package/script/oas/ref/DanglingRefError.js +37 -0
  247. package/script/oas/ref/Ref.d.ts +152 -25
  248. package/script/oas/ref/Ref.js +414 -26
  249. package/script/oas/requestBody/RequestBody.d.ts +4 -0
  250. package/script/oas/requestBody/RequestBody.js +8 -0
  251. package/script/oas/response/Response.d.ts +4 -0
  252. package/script/oas/response/Response.js +8 -0
  253. package/script/oas/schema/siblings.d.ts +127 -0
  254. package/script/oas/schema/siblings.js +305 -0
  255. package/script/oas/securitySchemes/SecurityScheme.d.ts +16 -0
  256. package/script/oas/securitySchemes/SecurityScheme.js +32 -0
  257. package/script/oas/string/String.d.ts +19 -0
  258. package/script/oas/string/String.js +47 -0
  259. package/script/oas/union/Union.d.ts +32 -0
  260. package/script/oas/union/Union.js +111 -0
  261. package/script/oas/unknown/Unknown.d.ts +18 -0
  262. package/script/oas/unknown/Unknown.js +38 -0
  263. package/script/oas/void/Void.d.ts +4 -0
  264. package/script/oas/void/Void.js +8 -0
  265. package/script/oas/webhook/Webhook.d.ts +2 -2
  266. package/script/oas/webhook/Webhook.js +4 -5
  267. package/script/parse/allOfSystem.d.ts +32 -0
  268. package/script/parse/allOfSystem.js +35 -0
  269. package/script/parse/anyOfSystem.d.ts +68 -0
  270. package/script/parse/anyOfSystem.js +116 -0
  271. package/script/parse/securityRequirements.d.ts +6 -0
  272. package/script/parse/securityRequirements.js +8 -0
  273. package/script/parse/toSiblingKeywords.d.ts +28 -0
  274. package/script/parse/toSiblingKeywords.js +146 -0
  275. package/script/parse/v3-0/_merge-all-of/decompose-union.d.ts +8 -0
  276. package/script/parse/v3-0/_merge-all-of/decompose-union.js +11 -2
  277. package/script/parse/v3-0/_merge-all-of/generic-merge.d.ts +2 -3
  278. package/script/parse/v3-0/_merge-all-of/generic-merge.js +2 -2
  279. package/script/parse/v3-0/_merge-all-of/merge-array-constraints.d.ts +2 -2
  280. package/script/parse/v3-0/_merge-all-of/merge-array-constraints.js +5 -5
  281. package/script/parse/v3-0/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  282. package/script/parse/v3-0/_merge-all-of/merge-boolean-constraints.js +2 -2
  283. package/script/parse/v3-0/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  284. package/script/parse/v3-0/_merge-all-of/merge-integer-constraints.js +2 -2
  285. package/script/parse/v3-0/_merge-all-of/merge-intersection.d.ts +3 -2
  286. package/script/parse/v3-0/_merge-all-of/merge-intersection.js +2 -2
  287. package/script/parse/v3-0/_merge-all-of/merge-number-constraints.d.ts +2 -2
  288. package/script/parse/v3-0/_merge-all-of/merge-number-constraints.js +2 -2
  289. package/script/parse/v3-0/_merge-all-of/merge-object-constraints.d.ts +2 -2
  290. package/script/parse/v3-0/_merge-all-of/merge-object-constraints.js +3 -3
  291. package/script/parse/v3-0/_merge-all-of/merge-properties.d.ts +2 -2
  292. package/script/parse/v3-0/_merge-all-of/merge-properties.js +2 -2
  293. package/script/parse/v3-0/_merge-all-of/merge-string-constraints.d.ts +2 -2
  294. package/script/parse/v3-0/_merge-all-of/merge-string-constraints.js +3 -3
  295. package/script/parse/v3-0/_merge-all-of/merge-union.d.ts +10 -3
  296. package/script/parse/v3-0/_merge-all-of/merge-union.js +52 -13
  297. package/script/parse/v3-0/_merge-all-of/merge.d.ts +2 -2
  298. package/script/parse/v3-0/_merge-all-of/merge.js +77 -26
  299. package/script/parse/v3-0/_merge-all-of/nullable-merge.d.ts +4 -0
  300. package/script/parse/v3-0/_merge-all-of/nullable-merge.js +9 -7
  301. package/script/parse/v3-0/_merge-all-of/types.d.ts +33 -0
  302. package/script/parse/v3-0/mediaType/toMediaTypeItemV3.js +4 -3
  303. package/script/parse/v3-0/parameter/toParameterV3.js +4 -3
  304. package/script/parse/v3-0/ref/toRefV31.d.ts +7 -1
  305. package/script/parse/v3-0/ref/toRefV31.js +6 -3
  306. package/script/parse/v3-0/schema/toSchemasV3.js +107 -15
  307. package/script/parse/v3-1/_merge-all-of/decompose-union.d.ts +7 -1
  308. package/script/parse/v3-1/_merge-all-of/decompose-union.js +8 -2
  309. package/script/parse/v3-1/_merge-all-of/generic-merge.d.ts +2 -3
  310. package/script/parse/v3-1/_merge-all-of/generic-merge.js +2 -2
  311. package/script/parse/v3-1/_merge-all-of/merge-array-constraints.d.ts +3 -2
  312. package/script/parse/v3-1/_merge-all-of/merge-array-constraints.js +5 -5
  313. package/script/parse/v3-1/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  314. package/script/parse/v3-1/_merge-all-of/merge-boolean-constraints.js +2 -2
  315. package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  316. package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -2
  317. package/script/parse/v3-1/_merge-all-of/merge-intersection.d.ts +3 -2
  318. package/script/parse/v3-1/_merge-all-of/merge-intersection.js +2 -2
  319. package/script/parse/v3-1/_merge-all-of/merge-number-constraints.d.ts +2 -2
  320. package/script/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -2
  321. package/script/parse/v3-1/_merge-all-of/merge-object-constraints.d.ts +2 -2
  322. package/script/parse/v3-1/_merge-all-of/merge-object-constraints.js +3 -3
  323. package/script/parse/v3-1/_merge-all-of/merge-properties.d.ts +2 -2
  324. package/script/parse/v3-1/_merge-all-of/merge-properties.js +2 -2
  325. package/script/parse/v3-1/_merge-all-of/merge-string-constraints.d.ts +2 -2
  326. package/script/parse/v3-1/_merge-all-of/merge-string-constraints.js +3 -3
  327. package/script/parse/v3-1/_merge-all-of/merge-union.d.ts +10 -3
  328. package/script/parse/v3-1/_merge-all-of/merge-union.js +56 -16
  329. package/script/parse/v3-1/_merge-all-of/merge.d.ts +3 -2
  330. package/script/parse/v3-1/_merge-all-of/merge.js +87 -28
  331. package/script/parse/v3-1/_merge-all-of/nullable-merge.d.ts +4 -0
  332. package/script/parse/v3-1/_merge-all-of/nullable-merge.js +9 -7
  333. package/script/parse/v3-1/_merge-all-of/types.d.ts +37 -0
  334. package/script/parse/v3-1/mediaType/toMediaTypeItemV3.js +4 -3
  335. package/script/parse/v3-1/parameter/toParameterV3.js +4 -3
  336. package/script/parse/v3-1/ref/toRefV31.d.ts +7 -1
  337. package/script/parse/v3-1/ref/toRefV31.js +6 -3
  338. package/script/parse/v3-1/schema/toSchemasV3.js +111 -16
  339. package/script/parse/v3-2/_merge-all-of/decompose-union.d.ts +7 -1
  340. package/script/parse/v3-2/_merge-all-of/decompose-union.js +8 -2
  341. package/script/parse/v3-2/_merge-all-of/generic-merge.d.ts +2 -3
  342. package/script/parse/v3-2/_merge-all-of/generic-merge.js +2 -2
  343. package/script/parse/v3-2/_merge-all-of/merge-array-constraints.d.ts +3 -2
  344. package/script/parse/v3-2/_merge-all-of/merge-array-constraints.js +5 -5
  345. package/script/parse/v3-2/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  346. package/script/parse/v3-2/_merge-all-of/merge-boolean-constraints.js +2 -2
  347. package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  348. package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -2
  349. package/script/parse/v3-2/_merge-all-of/merge-intersection.d.ts +3 -2
  350. package/script/parse/v3-2/_merge-all-of/merge-intersection.js +2 -2
  351. package/script/parse/v3-2/_merge-all-of/merge-number-constraints.d.ts +2 -2
  352. package/script/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -2
  353. package/script/parse/v3-2/_merge-all-of/merge-object-constraints.d.ts +2 -2
  354. package/script/parse/v3-2/_merge-all-of/merge-object-constraints.js +3 -3
  355. package/script/parse/v3-2/_merge-all-of/merge-properties.d.ts +2 -2
  356. package/script/parse/v3-2/_merge-all-of/merge-properties.js +2 -2
  357. package/script/parse/v3-2/_merge-all-of/merge-string-constraints.d.ts +2 -2
  358. package/script/parse/v3-2/_merge-all-of/merge-string-constraints.js +3 -3
  359. package/script/parse/v3-2/_merge-all-of/merge-union.d.ts +10 -3
  360. package/script/parse/v3-2/_merge-all-of/merge-union.js +56 -16
  361. package/script/parse/v3-2/_merge-all-of/merge.d.ts +3 -2
  362. package/script/parse/v3-2/_merge-all-of/merge.js +87 -28
  363. package/script/parse/v3-2/_merge-all-of/nullable-merge.d.ts +4 -0
  364. package/script/parse/v3-2/_merge-all-of/nullable-merge.js +9 -7
  365. package/script/parse/v3-2/_merge-all-of/types.d.ts +37 -0
  366. package/script/parse/v3-2/mediaType/toMediaTypeItemV3.js +4 -3
  367. package/script/parse/v3-2/parameter/toParameterV3.js +4 -3
  368. package/script/parse/v3-2/ref/toRefV31.d.ts +7 -1
  369. package/script/parse/v3-2/ref/toRefV31.js +6 -3
  370. package/script/parse/v3-2/schema/toSchemasV3.js +111 -16
  371. package/script/types/OasBase.d.ts +1 -1
  372. package/script/types/Settings.d.ts +44 -0
  373. package/script/types/Settings.js +10 -1
@@ -3,6 +3,8 @@ import { toModelGeneratorKey } from '../GeneratorKeys.js';
3
3
  import { DEFAULT_VARIANT } from '../../types/Variant.js';
4
4
  import { readProjectionOptions, toValueOptions } from '../../types/ProjectionOptions.js';
5
5
  import isEqual from 'lodash-es/isEqual.js';
6
+ import { CodeFileBase } from '../CodeFileBase.js';
7
+ import { PendingDefinition } from '../PendingDefinition.js';
6
8
  /**
7
9
  * Driver for the model insertion lifecycle.
8
10
  *
@@ -13,7 +15,11 @@ import isEqual from 'lodash-es/isEqual.js';
13
15
  * from the projection's `exportPath`.
14
16
  */
15
17
  export class ModelDriver {
16
- constructor(args) {
18
+ /**
19
+ * @param settings - The model's content settings, when the caller has
20
+ * already built them with the same `args` (`toModelRef` does).
21
+ */
22
+ constructor(args, settings = toModelSettings(args)) {
17
23
  Object.defineProperty(this, "context", {
18
24
  enumerable: true,
19
25
  configurable: true,
@@ -84,38 +90,19 @@ export class ModelDriver {
84
90
  this.noExport = noExport;
85
91
  this.variant = variant;
86
92
  this.options = readProjectionOptions(args);
87
- this.context.modelDepth[`${projection.id}:${refName}`] = 0;
88
- assertPeerVariantExists({
89
- context,
90
- generatorId: projection.id,
91
- refName,
92
- variant
93
- });
94
- assertPeerSupported({ context, projection, refName, variant });
95
- this.settings = this.context.toModelContentSettings({
96
- refName,
97
- projection,
98
- variant,
99
- options: this.options
100
- });
93
+ this.settings = settings;
101
94
  this.definition = this.apply({ destinationPath });
102
- this.context.modelDepth[`${projection.id}:${refName}`] = 0;
103
95
  }
104
96
  apply({ destinationPath } = {}) {
105
97
  const { identifier, exportPath } = this.settings;
106
98
  const definition = this.getDefinition({ identifier, exportPath });
107
- if (destinationPath &&
108
- normalizeWorkspacePath(exportPath) !== normalizeWorkspacePath(destinationPath)) {
109
- // Cross-file import of the peer's identifier from its export path.
110
- // The language builds the import object (`toImport`) and creates the
111
- // destination file on first write (caller-side); the engine stores
112
- // via the pure-data `context.register`.
113
- this.ensureFile(destinationPath);
114
- this.context.register({
115
- imports: [this.projection.lang.toImport({ identifier, module: exportPath })],
116
- destinationPath
117
- });
118
- }
99
+ stitchModelImport({
100
+ context: this.context,
101
+ lang: this.projection.lang,
102
+ identifier,
103
+ exportPath,
104
+ destinationPath
105
+ });
119
106
  return definition;
120
107
  }
121
108
  /**
@@ -125,39 +112,78 @@ export class ModelDriver {
125
112
  * cache-hit path). Returns the normalized path.
126
113
  */
127
114
  ensureFile(path) {
128
- const normalizedPath = normalizeWorkspacePath(path);
129
- if (!this.context.getFile(normalizedPath)) {
130
- this.context.addFile(this.projection.lang.createFile({ path: normalizedPath, settings: this.context.settings }));
115
+ return ensureFile({ context: this.context, lang: this.projection.lang, path });
116
+ }
117
+ /** The code File at `path`, created through the projection's language on first use. */
118
+ ensureCodeFile(path) {
119
+ const file = this.context.getFile(this.ensureFile(path));
120
+ if (!(file instanceof CodeFileBase)) {
121
+ throw new Error(`File at '${path}' is not a code file: a model Definition cannot go there.`);
131
122
  }
132
- return normalizedPath;
123
+ return file;
133
124
  }
134
125
  getDefinition({ identifier, exportPath }) {
135
- const cachedDefinition = this.context.findDefinition({
136
- name: identifier.name,
137
- exportPath
126
+ const generatorKey = toModelGeneratorKey({
127
+ generatorId: this.projection.id,
128
+ refName: this.refName,
129
+ variant: this.settings.variant
138
130
  });
139
- if (this.affirmDefinition(cachedDefinition, exportPath)) {
140
- return cachedDefinition;
131
+ const pending = findPending({ context: this.context, name: identifier.name, exportPath });
132
+ if (pending !== undefined) {
133
+ assertSamePending({
134
+ pending,
135
+ name: identifier.name,
136
+ exportPath,
137
+ generatorKey,
138
+ options: this.options,
139
+ projection: this.projection
140
+ });
141
+ throw new Error(`'${identifier.name}' in file '${exportPath}' is being constructed further up the stack. A reference back to it goes through toModelRef, which returns it suspended; a second projection would never finish.`);
141
142
  }
142
- const value = new this.projection({
143
+ const found = this.context.findDefinition({ name: identifier.name, exportPath });
144
+ if (found !== undefined) {
145
+ if (this.affirmDefinition(found, exportPath)) {
146
+ return found;
147
+ }
148
+ throw new Error(`Registered definition mismatch: '${identifier.name}' in file '${exportPath}' was built by another projection class with the same generator key '${generatorKey}'. Two copies of one generator package, or two projection classes under one generator id, claim it.`);
149
+ }
150
+ // While the constructor runs, the model is on the context's pending
151
+ // stack: an insert of it from inside the constructor (a cycle) finds it
152
+ // there, not a cache miss.
153
+ const marker = new PendingDefinition({
154
+ identifier,
155
+ exportPath: normalizeWorkspacePath(exportPath),
156
+ generatorKey,
157
+ options: this.options,
158
+ projection: this.projection
159
+ });
160
+ const value = whilePending({ context: this.context, marker }, () => new this.projection({
143
161
  refName: this.refName,
144
162
  context: this.context,
145
163
  settings: this.settings,
146
164
  destinationPath: this.settings.exportPath,
147
165
  rootRef: this.rootRef,
148
166
  options: this.options
149
- });
167
+ }));
150
168
  const definition = this.projection.lang.toDefinition({
151
169
  context: this.context,
152
170
  identifier,
153
171
  value,
154
172
  noExport: this.noExport
155
173
  });
156
- this.ensureFile(exportPath);
157
- this.context.register({
158
- definitions: [definition],
159
- destinationPath: exportPath
160
- });
174
+ definition.reaches = marker.reaches;
175
+ // Added once the constructor returned, so the Definition renders after
176
+ // the models it refers to, and a constructor that throws adds no file.
177
+ const taken = this.context.findDefinition({ name: identifier.name, exportPath });
178
+ if (taken !== undefined) {
179
+ assertSameKey({
180
+ name: identifier.name,
181
+ exportPath,
182
+ cachedKey: taken.generatorKey,
183
+ generatorKey
184
+ });
185
+ }
186
+ this.ensureCodeFile(exportPath).addDefinition(definition);
161
187
  return definition;
162
188
  }
163
189
  affirmDefinition(definition, exportPath) {
@@ -169,21 +195,172 @@ export class ModelDriver {
169
195
  refName: this.refName,
170
196
  variant: this.settings.variant
171
197
  });
172
- if (currentKey !== definition.generatorKey) {
173
- throw new Error(`Registered definition mismatch: '${definition.identifier.name}' in file '${exportPath}'. Cached key '${definition.generatorKey}' does not match new key '${currentKey}'`);
174
- }
198
+ assertSameKey({
199
+ name: definition.identifier.name,
200
+ exportPath,
201
+ cachedKey: definition.generatorKey,
202
+ generatorKey: currentKey
203
+ });
175
204
  if (!(definition.value instanceof this.projection)) {
176
205
  return false;
177
206
  }
178
207
  // Options are identity, like the variant, but cannot ride the key: a hit
179
208
  // is checked against the options its value was built with.
180
- const cachedOptions = toValueOptions(definition.value);
181
- if (!isEqual(cachedOptions, this.options)) {
182
- throw new Error(`Registered definition mismatch: '${definition.identifier.name}' in file '${exportPath}'. Cached options ${JSON.stringify(cachedOptions)} do not match new options ${JSON.stringify(this.options)}. Fold options into toIdentifierName.`);
183
- }
209
+ assertSameOptions({
210
+ name: definition.identifier.name,
211
+ exportPath,
212
+ cachedOptions: toValueOptions(definition.value),
213
+ options: this.options
214
+ });
184
215
  return true;
185
216
  }
186
217
  }
218
+ /** Two generators, subjects or variants that claim one name in one file collide: `Registered definition mismatch`. */
219
+ const assertSameKey = ({ name, exportPath, cachedKey, generatorKey }) => {
220
+ if (cachedKey !== generatorKey) {
221
+ throw new Error(`Registered definition mismatch: '${name}' in file '${exportPath}'. Cached key '${cachedKey}' does not match new key '${generatorKey}'`);
222
+ }
223
+ };
224
+ /** One name in one file built with other caller options collides too: options are identity. */
225
+ const assertSameOptions = ({ name, exportPath, cachedOptions, options }) => {
226
+ if (!isEqual(cachedOptions, options)) {
227
+ throw new Error(`Registered definition mismatch: '${name}' in file '${exportPath}'. Cached options ${JSON.stringify(cachedOptions)} do not match new options ${JSON.stringify(options)}. Fold options into toIdentifierName.`);
228
+ }
229
+ };
230
+ /** Run `construct` with `marker` on top of the context's pending stack, popped however `construct` ends. */
231
+ const whilePending = ({ context, marker }, construct) => {
232
+ context.pendingStack.push(marker);
233
+ try {
234
+ return construct();
235
+ }
236
+ finally {
237
+ context.pendingStack.pop();
238
+ marker.pending = false;
239
+ }
240
+ };
241
+ /**
242
+ * The model under construction named `name` in `exportPath`, if any. The
243
+ * pending stack holds exactly the models whose constructors are running, so
244
+ * the search is as long as the chain of models being built.
245
+ */
246
+ const findPending = ({ context, name, exportPath }) => {
247
+ const path = normalizeWorkspacePath(exportPath);
248
+ return context.pendingStack.find(pending => pending.identifier.name === name && pending.exportPath === path);
249
+ };
250
+ /** A model under construction is this model only with the same key, projection class and options. */
251
+ const assertSamePending = ({ pending, name, exportPath, generatorKey, options, projection }) => {
252
+ assertSameKey({ name, exportPath, cachedKey: pending.generatorKey, generatorKey });
253
+ if (pending.projection !== projection) {
254
+ throw new Error(`Registered definition mismatch: '${name}' in file '${exportPath}' is being built by another projection class with the same generator key '${generatorKey}'. Two copies of one generator package, or two projection classes under one generator id, claim it.`);
255
+ }
256
+ assertSameOptions({ name, exportPath, cachedOptions: pending.options, options });
257
+ };
258
+ /** Ensure the file at `path` exists, creating it through `lang` on first write. Returns the normalized path. */
259
+ const ensureFile = ({ context, lang, path }) => {
260
+ const normalizedPath = normalizeWorkspacePath(path);
261
+ if (!context.getFile(normalizedPath)) {
262
+ context.addFile(lang.createFile({ path: normalizedPath, settings: context.settings }));
263
+ }
264
+ return normalizedPath;
265
+ };
266
+ /**
267
+ * Import a model's identifier from its export path into `destinationPath`,
268
+ * unless the two are one file. The language builds the import object
269
+ * (`toImport`) and creates the destination file on first write; the engine
270
+ * stores it via the pure-data `context.register`.
271
+ */
272
+ const stitchModelImport = ({ context, lang, identifier, exportPath, destinationPath }) => {
273
+ if (!destinationPath ||
274
+ normalizeWorkspacePath(exportPath) === normalizeWorkspacePath(destinationPath)) {
275
+ return;
276
+ }
277
+ ensureFile({ context, lang, path: destinationPath });
278
+ context.register({
279
+ imports: [lang.toImport({ identifier, module: exportPath })],
280
+ destinationPath
281
+ });
282
+ };
283
+ /** The models `definition`'s construction reached that are still pending. */
284
+ const toOpenReaches = (definition) => [...(definition.reaches ?? [])].filter(reached => reached.pending);
285
+ /**
286
+ * Whether anything referred back to the model of `settings` while its
287
+ * projection was being constructed: the model is recursive, on its own or in
288
+ * a cycle with others. Call it from the projection's constructor, after the
289
+ * value is built, while the model is still pending.
290
+ */
291
+ export const isReferencedBack = ({ context, settings }) => {
292
+ const pending = findPending({
293
+ context,
294
+ name: settings.identifier.name,
295
+ exportPath: settings.exportPath
296
+ });
297
+ return pending !== undefined && pending.backReferences > 0;
298
+ };
299
+ /** A model's content settings, once the peer is known to have the variant and to support the model. */
300
+ const toModelSettings = (args) => {
301
+ const { context, projection, refName, variant = DEFAULT_VARIANT } = args;
302
+ assertPeerVariantExists({ context, generatorId: projection.id, refName, variant });
303
+ assertPeerSupported({ context, projection, refName, variant });
304
+ return context.toModelContentSettings({
305
+ refName,
306
+ projection,
307
+ variant,
308
+ options: readProjectionOptions(args)
309
+ });
310
+ };
311
+ /**
312
+ * Reference a model from a ref snippet. A pending model (its projection is
313
+ * being constructed further up the stack) is a back-reference: its marker
314
+ * counts it, so its projection can tell that it is recursive
315
+ * ({@link isReferencedBack}), and its import is stitched into
316
+ * `destinationPath` as for any reference. The import matters when the
317
+ * back-reference crosses files: in a cycle of two or more models, the model
318
+ * that refers back lives in another file. Any other model goes through the
319
+ * {@link ModelDriver}.
320
+ */
321
+ export const toModelRef = (args) => {
322
+ const { context, projection, refName, destinationPath, variant = DEFAULT_VARIANT } = args;
323
+ const settings = toModelSettings(args);
324
+ const pending = findPending({
325
+ context,
326
+ name: settings.identifier.name,
327
+ exportPath: settings.exportPath
328
+ });
329
+ if (pending !== undefined) {
330
+ assertSamePending({
331
+ pending,
332
+ name: settings.identifier.name,
333
+ exportPath: settings.exportPath,
334
+ generatorKey: toModelGeneratorKey({ generatorId: projection.id, refName, variant }),
335
+ options: readProjectionOptions(args),
336
+ projection
337
+ });
338
+ pending.backReferences++;
339
+ // The model whose constructor is running reached a pending model.
340
+ context.pendingStack.at(-1)?.reaches.add(pending);
341
+ stitchModelImport({
342
+ context,
343
+ lang: projection.lang,
344
+ identifier: settings.identifier,
345
+ exportPath: settings.exportPath,
346
+ destinationPath
347
+ });
348
+ return { suspended: true, settings };
349
+ }
350
+ const driver = new ModelDriver(args, settings);
351
+ // What the model reached that is still pending, the source reaches too:
352
+ // through this reference. Constructed now or found in the cache, the
353
+ // Definition carries what its construction reached.
354
+ const open = toOpenReaches(driver.definition);
355
+ const source = context.pendingStack.at(-1);
356
+ open.forEach(reached => source?.reaches.add(reached));
357
+ return {
358
+ suspended: false,
359
+ settings: driver.settings,
360
+ definition: driver.definition,
361
+ inCycle: open.length > 0
362
+ };
363
+ };
187
364
  /**
188
365
  * Guard the peer-variant-mismatch invariant for model insertions.
189
366
  *
@@ -45,7 +45,7 @@ export type ModelEntry<EnrichmentType = undefined> = {
45
45
  * @param args.isSupported - Optional capability gate; a model whose predicate
46
46
  * returns `false` is recorded `notSupported` and its `transform` is skipped.
47
47
  * Resolve the schema inside the predicate when needed
48
- * (`context.resolveSchemaRefOnce(refName, id)`). Defaults to supporting every model.
48
+ * (`context.resolveSchemaRefOnce(refName)`). Defaults to supporting every model.
49
49
  * @param args.toPreviewModule - Optional function to generate preview modules
50
50
  * @param args.toEnrichmentSchema - Optional function to provide enrichment validation
51
51
  * @param args.toEnrichmentRequest - Optional function to request enrichments
@@ -15,7 +15,7 @@
15
15
  * @param args.isSupported - Optional capability gate; a model whose predicate
16
16
  * returns `false` is recorded `notSupported` and its `transform` is skipped.
17
17
  * Resolve the schema inside the predicate when needed
18
- * (`context.resolveSchemaRefOnce(refName, id)`). Defaults to supporting every model.
18
+ * (`context.resolveSchemaRefOnce(refName)`). Defaults to supporting every model.
19
19
  * @param args.toPreviewModule - Optional function to generate preview modules
20
20
  * @param args.toEnrichmentSchema - Optional function to provide enrichment validation
21
21
  * @param args.toEnrichmentRequest - Optional function to request enrichments
@@ -46,7 +46,7 @@ export type TransformModelArgs = {
46
46
  * entry/dispatch boundary. The capability counterpart of
47
47
  * {@link TransformModelArgs}: it carries the resolved enrichment umbrella so
48
48
  * the predicate can gate on user config, but no schema — the predicate
49
- * resolves the schema itself (`context.resolveSchemaRefOnce(refName, id)`)
49
+ * resolves the schema itself (`context.resolveSchemaRefOnce(refName)`)
50
50
  * when it needs it, mirroring how `transform` works.
51
51
  */
52
52
  export type IsSupportedModelArgs = {
@@ -125,10 +125,7 @@ export class GqlOperationDriver {
125
125
  return normalizedPath;
126
126
  }
127
127
  getDefinition({ identifier, exportPath }) {
128
- const cachedDefinition = this.context.findDefinition({
129
- name: identifier.name,
130
- exportPath
131
- });
128
+ const cachedDefinition = this.context.findDefinition({ name: identifier.name, exportPath });
132
129
  if (this.affirmDefinition(cachedDefinition, exportPath)) {
133
130
  return cachedDefinition;
134
131
  }
@@ -118,10 +118,7 @@ export class WebhookDriver {
118
118
  return normalizedPath;
119
119
  }
120
120
  getDefinition({ identifier, exportPath }) {
121
- const cachedDefinition = this.context.findDefinition({
122
- name: identifier.name,
123
- exportPath
124
- });
121
+ const cachedDefinition = this.context.findDefinition({ name: identifier.name, exportPath });
125
122
  if (this.affirmDefinition(cachedDefinition, exportPath)) {
126
123
  return cachedDefinition;
127
124
  }
@@ -18,9 +18,9 @@
18
18
  * declares only the fields it reads — keys other generators own are
19
19
  * expected, not typos.
20
20
  *
21
- * A wrong-typed value still throws exactly as before — the `v.parse` at
22
- * the end is unchanged, and unknown-key detection runs first so a
23
- * throwing leaf doesn't hide a dropped key.
21
+ * A wrong-typed value throws ({@link parseEnrichmentValue}), naming each
22
+ * wrong value's place in `client.json`. Unknown-key detection runs first,
23
+ * so a throwing leaf doesn't hide a dropped key.
24
24
  *
25
25
  * @module parseEnrichmentUmbrella
26
26
  */
@@ -54,9 +54,8 @@ type ParseEnrichmentUmbrellaArgs<EnrichmentType> = {
54
54
  * umbrella, recording the reads for the consumption audit and reporting
55
55
  * schema-dropped keys.
56
56
  *
57
- * @throws on a wrong-typed value, exactly like the raw `v.parse` this
58
- * wraps — the generator's item is then recorded as `error` and the run
59
- * continues (fail-open).
57
+ * @throws on a wrong-typed value. The generator's item is recorded as
58
+ * `error`, and the run fails once every generator has run.
60
59
  */
61
60
  export declare const parseEnrichmentUmbrella: <EnrichmentType>({ context, generatorId, subjectSegments, schema }: ParseEnrichmentUmbrellaArgs<EnrichmentType>) => EnrichmentType;
62
61
  export {};
@@ -18,24 +18,23 @@
18
18
  * declares only the fields it reads — keys other generators own are
19
19
  * expected, not typos.
20
20
  *
21
- * A wrong-typed value still throws exactly as before — the `v.parse` at
22
- * the end is unchanged, and unknown-key detection runs first so a
23
- * throwing leaf doesn't hide a dropped key.
21
+ * A wrong-typed value throws ({@link parseEnrichmentValue}), naming each
22
+ * wrong value's place in `client.json`. Unknown-key detection runs first,
23
+ * so a throwing leaf doesn't hide a dropped key.
24
24
  *
25
25
  * @module parseEnrichmentUmbrella
26
26
  */
27
- import * as v from 'valibot';
28
27
  import { GENERATOR_ENRICHMENT_KEY, STACK_ENRICHMENT_KEY } from '../types/Enrichments.js';
29
28
  import { findUnknownKeys } from './findUnknownKeys.js';
30
29
  import { formatEnrichmentPath } from './EnrichmentWarning.js';
30
+ import { parseEnrichmentValue } from './parseEnrichmentValue.js';
31
31
  /**
32
32
  * Assemble and parse one `{ subject, generator, stack }` enrichment
33
33
  * umbrella, recording the reads for the consumption audit and reporting
34
34
  * schema-dropped keys.
35
35
  *
36
- * @throws on a wrong-typed value, exactly like the raw `v.parse` this
37
- * wraps — the generator's item is then recorded as `error` and the run
38
- * continues (fail-open).
36
+ * @throws on a wrong-typed value. The generator's item is recorded as
37
+ * `error`, and the run fails once every generator has run.
39
38
  */
40
39
  export const parseEnrichmentUmbrella = ({ context, generatorId, subjectSegments, schema }) => {
41
40
  const raw = {
@@ -62,5 +61,21 @@ export const parseEnrichmentUmbrella = ({ context, generatorId, subjectSegments,
62
61
  ...(suggestion !== undefined ? { suggestion } : {})
63
62
  });
64
63
  }
65
- return v.parse(schema, raw);
64
+ return parseEnrichmentValue({
65
+ schema,
66
+ value: raw,
67
+ generatorId,
68
+ toRoutingPath: ([scope, ...leafPath]) => {
69
+ switch (scope) {
70
+ case 'subject':
71
+ return [generatorId, ...subjectSegments, ...leafPath];
72
+ case 'generator':
73
+ return [generatorId, GENERATOR_ENRICHMENT_KEY, ...leafPath];
74
+ case 'stack':
75
+ return [STACK_ENRICHMENT_KEY, ...leafPath];
76
+ default:
77
+ return [generatorId];
78
+ }
79
+ }
80
+ });
66
81
  };
@@ -0,0 +1,17 @@
1
+ import * as v from 'valibot';
2
+ type ParseEnrichmentValueArgs<EnrichmentType> = {
3
+ schema: v.GenericSchema<EnrichmentType>;
4
+ value: unknown;
5
+ /** The generator whose schema reads `value`; `undefined` for the shared `_stack` bag. */
6
+ generatorId: string | undefined;
7
+ /** The `client.json#settings.enrichments` routing path of the value at `path` inside `value`. */
8
+ toRoutingPath: (path: readonly string[]) => string[];
9
+ };
10
+ /**
11
+ * `value` parsed through a generator's enrichment schema. Enrichments are
12
+ * typed configuration, so a value that does not match throws, and the run
13
+ * fails. The message lists every value that does not match, at its place in
14
+ * `client.json`, so the user can fix them all in one pass.
15
+ */
16
+ export declare const parseEnrichmentValue: <EnrichmentType>({ schema, value, generatorId, toRoutingPath }: ParseEnrichmentValueArgs<EnrichmentType>) => EnrichmentType;
17
+ export {};
@@ -0,0 +1,32 @@
1
+ import * as v from 'valibot';
2
+ import { formatEnrichmentPath } from './EnrichmentWarning.js';
3
+ /**
4
+ * `value` parsed through a generator's enrichment schema. Enrichments are
5
+ * typed configuration, so a value that does not match throws, and the run
6
+ * fails. The message lists every value that does not match, at its place in
7
+ * `client.json`, so the user can fix them all in one pass.
8
+ */
9
+ export const parseEnrichmentValue = ({ schema, value, generatorId, toRoutingPath }) => {
10
+ const result = v.safeParse(schema, value);
11
+ if (result.success) {
12
+ return result.output;
13
+ }
14
+ const lines = result.issues.map(issue => {
15
+ const path = (issue.path ?? []).map(item => String(item.key));
16
+ const at = formatEnrichmentPath(toRoutingPath(path));
17
+ return `- '${at}': ${toFix(issue, generatorId)}`;
18
+ });
19
+ const header = generatorId === undefined
20
+ ? 'Stack enrichments do not match the schema a generator reads them with.'
21
+ : `Enrichments for '${generatorId}' do not match its enrichment schema.`;
22
+ throw new Error([`${header} Fix them in client.json (settings.enrichments):`, ...lines].join('\n'));
23
+ };
24
+ /** What to do about one value: a scope the generator does not read takes no value at all. */
25
+ const toFix = (issue, generatorId) => {
26
+ if (issue.expected !== 'undefined') {
27
+ return issue.message;
28
+ }
29
+ return generatorId === undefined
30
+ ? 'No generator reads a value here. Remove the value.'
31
+ : `'${generatorId}' reads no enrichments here. Remove the value.`;
32
+ };
@@ -23,7 +23,7 @@
23
23
  *
24
24
  * @module readEnrichments
25
25
  */
26
- import * as v from 'valibot';
26
+ import type * as v from 'valibot';
27
27
  import type { ClientSettings } from '../types/Settings.js';
28
28
  /**
29
29
  * Minimal structural view of the read context. Any `GenerateContext`
@@ -46,9 +46,9 @@ type EnrichmentReadContext = {
46
46
  * `v.object({...})` (a missing block then throws); one with all-optional
47
47
  * config passes `v.optional(v.object({...}))`.
48
48
  *
49
- * @throws on a malformed block. The generator's item is then recorded as
50
- * `error` and the run continues (fail-open), exactly like a bad subject
51
- * leaf.
49
+ * @throws on a malformed block, naming each wrong value's place in
50
+ * `client.json`. The item is recorded as `error`, and the run fails once
51
+ * every generator has run, exactly as for a bad subject leaf.
52
52
  */
53
53
  export declare const toGeneratorEnrichment: <EnrichmentType>(context: EnrichmentReadContext, generatorId: string, schema: v.GenericSchema<EnrichmentType>) => EnrichmentType;
54
54
  /**
@@ -62,7 +62,7 @@ export declare const toGeneratorEnrichment: <EnrichmentType>(context: Enrichment
62
62
  * `v.object` ignores unknown keys, so fields other generators consume
63
63
  * don't interfere. The return type is inferred from `schema`.
64
64
  *
65
- * @throws on a malformed block (fail-open, as above).
65
+ * @throws on a malformed block, as above.
66
66
  */
67
67
  export declare const toStackEnrichment: <EnrichmentType>(context: EnrichmentReadContext, schema: v.GenericSchema<EnrichmentType>) => EnrichmentType;
68
68
  export {};
@@ -23,8 +23,8 @@
23
23
  *
24
24
  * @module readEnrichments
25
25
  */
26
- import * as v from 'valibot';
27
26
  import { GENERATOR_ENRICHMENT_KEY, STACK_ENRICHMENT_KEY } from '../types/Enrichments.js';
27
+ import { parseEnrichmentValue } from './parseEnrichmentValue.js';
28
28
  /**
29
29
  * Read this generator's **generator-scoped** enrichment — the
30
30
  * run-constant leaf at
@@ -38,11 +38,16 @@ import { GENERATOR_ENRICHMENT_KEY, STACK_ENRICHMENT_KEY } from '../types/Enrichm
38
38
  * `v.object({...})` (a missing block then throws); one with all-optional
39
39
  * config passes `v.optional(v.object({...}))`.
40
40
  *
41
- * @throws on a malformed block. The generator's item is then recorded as
42
- * `error` and the run continues (fail-open), exactly like a bad subject
43
- * leaf.
41
+ * @throws on a malformed block, naming each wrong value's place in
42
+ * `client.json`. The item is recorded as `error`, and the run fails once
43
+ * every generator has run, exactly as for a bad subject leaf.
44
44
  */
45
- export const toGeneratorEnrichment = (context, generatorId, schema) => v.parse(schema, context.settings?.enrichments?.[generatorId]?.[GENERATOR_ENRICHMENT_KEY]);
45
+ export const toGeneratorEnrichment = (context, generatorId, schema) => parseEnrichmentValue({
46
+ schema,
47
+ value: context.settings?.enrichments?.[generatorId]?.[GENERATOR_ENRICHMENT_KEY],
48
+ generatorId,
49
+ toRoutingPath: path => [generatorId, GENERATOR_ENRICHMENT_KEY, ...path]
50
+ });
46
51
  /**
47
52
  * Read the **stack-scoped** enrichment — the run-constant leaf at
48
53
  * `client.json#settings.enrichments._stack`, validated through the
@@ -54,6 +59,11 @@ export const toGeneratorEnrichment = (context, generatorId, schema) => v.parse(s
54
59
  * `v.object` ignores unknown keys, so fields other generators consume
55
60
  * don't interfere. The return type is inferred from `schema`.
56
61
  *
57
- * @throws on a malformed block (fail-open, as above).
62
+ * @throws on a malformed block, as above.
58
63
  */
59
- export const toStackEnrichment = (context, schema) => v.parse(schema, context.settings?.enrichments?.[STACK_ENRICHMENT_KEY]);
64
+ export const toStackEnrichment = (context, schema) => parseEnrichmentValue({
65
+ schema,
66
+ value: context.settings?.enrichments?.[STACK_ENRICHMENT_KEY],
67
+ generatorId: undefined,
68
+ toRoutingPath: path => [STACK_ENRICHMENT_KEY, ...path]
69
+ });
@@ -1,5 +1,6 @@
1
1
  import "../_dnt.polyfills.js";
2
2
  import { isEmpty } from './isEmpty.js';
3
+ import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
3
4
  /**
4
5
  * Recursively collates and builds example values from OpenAPI schemas.
5
6
  *
@@ -165,11 +166,20 @@ export const collateExamples = ({ objectSchema, depth, seen }) => {
165
166
  if (seen?.has(objectSchema.$ref)) {
166
167
  return undefined;
167
168
  }
168
- return collateExamples({
169
- objectSchema: objectSchema.resolve(),
170
- depth: depth + 1,
171
- seen: new Set(seen ?? []).add(objectSchema.$ref)
172
- });
169
+ try {
170
+ return collateExamples({
171
+ objectSchema: objectSchema.resolve(),
172
+ depth: depth + 1,
173
+ seen: new Set(seen ?? []).add(objectSchema.$ref)
174
+ });
175
+ }
176
+ catch (error) {
177
+ // A dangling reference names no schema, so it has no example either.
178
+ if (DanglingRefError.is(error)) {
179
+ return undefined;
180
+ }
181
+ throw error;
182
+ }
173
183
  }
174
184
  case 'object': {
175
185
  if (objectSchema.example) {