sdkloom 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (383) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +239 -2
  3. package/kits/allowed-sources.json +24 -0
  4. package/kits/csharp/kit.json +6 -0
  5. package/kits/csharp/src/Runtime/Client.cs +295 -0
  6. package/kits/csharp/src/Runtime/Context.cs +216 -0
  7. package/kits/csharp/src/Runtime/Errors.cs +121 -0
  8. package/kits/csharp/src/Runtime/Http.cs +218 -0
  9. package/kits/csharp/src/Runtime/Json.cs +650 -0
  10. package/kits/csharp/src/Runtime/Lang.cs +212 -0
  11. package/kits/csharp/src/Runtime/Models.cs +206 -0
  12. package/kits/csharp/src/Runtime/Multipart.cs +108 -0
  13. package/kits/csharp/src/Runtime/Pagination.cs +122 -0
  14. package/kits/csharp/src/Runtime/Sse.cs +197 -0
  15. package/kits/csharp/src/Runtime/Testing.cs +375 -0
  16. package/kits/csharp/src/Runtime/Transport.cs +212 -0
  17. package/kits/csharp/src/Runtime/Wait.cs +57 -0
  18. package/kits/csharp/src/Runtime/Webhooks.cs +148 -0
  19. package/kits/csharp/tests/ClientTests.cs +128 -0
  20. package/kits/csharp/tests/HttpTests.cs +44 -0
  21. package/kits/csharp/tests/JsonTests.cs +132 -0
  22. package/kits/csharp/tests/LangTests.cs +57 -0
  23. package/kits/csharp/tests/MultipartTests.cs +31 -0
  24. package/kits/csharp/tests/PaginationTests.cs +93 -0
  25. package/kits/csharp/tests/SseTests.cs +122 -0
  26. package/kits/csharp/tests/TestRunner.cs +93 -0
  27. package/kits/csharp/tests/TestingTests.cs +80 -0
  28. package/kits/csharp/tests/TransportTests.cs +145 -0
  29. package/kits/csharp/tests/WaitTests.cs +39 -0
  30. package/kits/csharp/tests/WebhooksTests.cs +46 -0
  31. package/kits/csharp/versions.json +12 -0
  32. package/kits/go/kit.json +6 -0
  33. package/kits/go/src/sdkruntime/client.go +322 -0
  34. package/kits/go/src/sdkruntime/context.go +207 -0
  35. package/kits/go/src/sdkruntime/errors.go +74 -0
  36. package/kits/go/src/sdkruntime/http.go +261 -0
  37. package/kits/go/src/sdkruntime/json.go +527 -0
  38. package/kits/go/src/sdkruntime/lang.go +462 -0
  39. package/kits/go/src/sdkruntime/multipart.go +75 -0
  40. package/kits/go/src/sdkruntime/pagination.go +150 -0
  41. package/kits/go/src/sdkruntime/sse.go +267 -0
  42. package/kits/go/src/sdkruntime/testing.go +343 -0
  43. package/kits/go/src/sdkruntime/transport.go +168 -0
  44. package/kits/go/src/sdkruntime/wait.go +49 -0
  45. package/kits/go/src/sdkruntime/webhooks.go +129 -0
  46. package/kits/go/tests/client_test.go +185 -0
  47. package/kits/go/tests/http_test.go +78 -0
  48. package/kits/go/tests/json_test.go +127 -0
  49. package/kits/go/tests/lang_test.go +98 -0
  50. package/kits/go/tests/multipart_test.go +29 -0
  51. package/kits/go/tests/pagination_test.go +69 -0
  52. package/kits/go/tests/sse_test.go +129 -0
  53. package/kits/go/tests/testing_test.go +121 -0
  54. package/kits/go/tests/transport_test.go +133 -0
  55. package/kits/go/tests/wait_test.go +46 -0
  56. package/kits/go/tests/webhooks_test.go +62 -0
  57. package/kits/go/versions.json +12 -0
  58. package/kits/java/kit.json +6 -0
  59. package/kits/java/src/dev/sdkloom/runtime/ApiException.java +63 -0
  60. package/kits/java/src/dev/sdkloom/runtime/ArgumentException.java +24 -0
  61. package/kits/java/src/dev/sdkloom/runtime/Assert.java +72 -0
  62. package/kits/java/src/dev/sdkloom/runtime/ClientRuntime.java +220 -0
  63. package/kits/java/src/dev/sdkloom/runtime/Clock.java +39 -0
  64. package/kits/java/src/dev/sdkloom/runtime/Context.java +79 -0
  65. package/kits/java/src/dev/sdkloom/runtime/Decode.java +200 -0
  66. package/kits/java/src/dev/sdkloom/runtime/DecodeException.java +26 -0
  67. package/kits/java/src/dev/sdkloom/runtime/Decoder.java +16 -0
  68. package/kits/java/src/dev/sdkloom/runtime/Emitter.java +56 -0
  69. package/kits/java/src/dev/sdkloom/runtime/ErrorFactory.java +18 -0
  70. package/kits/java/src/dev/sdkloom/runtime/EventListener.java +20 -0
  71. package/kits/java/src/dev/sdkloom/runtime/EventStream.java +232 -0
  72. package/kits/java/src/dev/sdkloom/runtime/FakeClock.java +37 -0
  73. package/kits/java/src/dev/sdkloom/runtime/Headers.java +42 -0
  74. package/kits/java/src/dev/sdkloom/runtime/HttpRequest.java +88 -0
  75. package/kits/java/src/dev/sdkloom/runtime/HttpResponse.java +69 -0
  76. package/kits/java/src/dev/sdkloom/runtime/JdkTransport.java +97 -0
  77. package/kits/java/src/dev/sdkloom/runtime/Js.java +230 -0
  78. package/kits/java/src/dev/sdkloom/runtime/Json.java +281 -0
  79. package/kits/java/src/dev/sdkloom/runtime/JsonValue.java +15 -0
  80. package/kits/java/src/dev/sdkloom/runtime/Links.java +62 -0
  81. package/kits/java/src/dev/sdkloom/runtime/Middleware.java +16 -0
  82. package/kits/java/src/dev/sdkloom/runtime/MiddlewareEntry.java +43 -0
  83. package/kits/java/src/dev/sdkloom/runtime/MockRoute.java +111 -0
  84. package/kits/java/src/dev/sdkloom/runtime/MockTransport.java +62 -0
  85. package/kits/java/src/dev/sdkloom/runtime/MultipartForm.java +111 -0
  86. package/kits/java/src/dev/sdkloom/runtime/Next.java +16 -0
  87. package/kits/java/src/dev/sdkloom/runtime/OperationInfo.java +35 -0
  88. package/kits/java/src/dev/sdkloom/runtime/OperationMock.java +105 -0
  89. package/kits/java/src/dev/sdkloom/runtime/OperationSpec.java +125 -0
  90. package/kits/java/src/dev/sdkloom/runtime/Pages.java +55 -0
  91. package/kits/java/src/dev/sdkloom/runtime/Pipeline.java +29 -0
  92. package/kits/java/src/dev/sdkloom/runtime/RawResult.java +31 -0
  93. package/kits/java/src/dev/sdkloom/runtime/RecordedEvent.java +36 -0
  94. package/kits/java/src/dev/sdkloom/runtime/SdkInfo.java +38 -0
  95. package/kits/java/src/dev/sdkloom/runtime/SendOptions.java +34 -0
  96. package/kits/java/src/dev/sdkloom/runtime/ServerSentEvent.java +58 -0
  97. package/kits/java/src/dev/sdkloom/runtime/State.java +58 -0
  98. package/kits/java/src/dev/sdkloom/runtime/Test.java +21 -0
  99. package/kits/java/src/dev/sdkloom/runtime/TestRunner.java +63 -0
  100. package/kits/java/src/dev/sdkloom/runtime/Transport.java +16 -0
  101. package/kits/java/src/dev/sdkloom/runtime/TransportException.java +30 -0
  102. package/kits/java/src/dev/sdkloom/runtime/UrlConnectionTransport.java +195 -0
  103. package/kits/java/src/dev/sdkloom/runtime/Urls.java +116 -0
  104. package/kits/java/src/dev/sdkloom/runtime/Waits.java +53 -0
  105. package/kits/java/src/dev/sdkloom/runtime/WebhookSignatureException.java +24 -0
  106. package/kits/java/src/dev/sdkloom/runtime/Webhooks.java +146 -0
  107. package/kits/java/tests/dev/sdkloom/runtime/ClientTest.java +266 -0
  108. package/kits/java/tests/dev/sdkloom/runtime/EventStreamTest.java +131 -0
  109. package/kits/java/tests/dev/sdkloom/runtime/HttpTest.java +95 -0
  110. package/kits/java/tests/dev/sdkloom/runtime/JdkTransportTest.java +12 -0
  111. package/kits/java/tests/dev/sdkloom/runtime/JsTest.java +102 -0
  112. package/kits/java/tests/dev/sdkloom/runtime/JsonTest.java +87 -0
  113. package/kits/java/tests/dev/sdkloom/runtime/LinksTest.java +22 -0
  114. package/kits/java/tests/dev/sdkloom/runtime/MultipartFormTest.java +30 -0
  115. package/kits/java/tests/dev/sdkloom/runtime/PagesTest.java +75 -0
  116. package/kits/java/tests/dev/sdkloom/runtime/TestData.java +53 -0
  117. package/kits/java/tests/dev/sdkloom/runtime/TestingTest.java +156 -0
  118. package/kits/java/tests/dev/sdkloom/runtime/TransportContract.java +201 -0
  119. package/kits/java/tests/dev/sdkloom/runtime/UrlConnectionTransportTest.java +49 -0
  120. package/kits/java/tests/dev/sdkloom/runtime/WaitsTest.java +43 -0
  121. package/kits/java/tests/dev/sdkloom/runtime/WebhooksTest.java +45 -0
  122. package/kits/java/versions.json +41 -0
  123. package/kits/python/kit.json +6 -0
  124. package/kits/python/src/sdkloom_runtime/__init__.py +1 -0
  125. package/kits/python/src/sdkloom_runtime/client.py +232 -0
  126. package/kits/python/src/sdkloom_runtime/compat.py +195 -0
  127. package/kits/python/src/sdkloom_runtime/context.py +134 -0
  128. package/kits/python/src/sdkloom_runtime/errors.py +65 -0
  129. package/kits/python/src/sdkloom_runtime/http.py +192 -0
  130. package/kits/python/src/sdkloom_runtime/lang.py +207 -0
  131. package/kits/python/src/sdkloom_runtime/models.py +221 -0
  132. package/kits/python/src/sdkloom_runtime/multipart.py +69 -0
  133. package/kits/python/src/sdkloom_runtime/pagination.py +61 -0
  134. package/kits/python/src/sdkloom_runtime/pipeline.py +39 -0
  135. package/kits/python/src/sdkloom_runtime/sse.py +121 -0
  136. package/kits/python/src/sdkloom_runtime/testing.py +224 -0
  137. package/kits/python/src/sdkloom_runtime/transport.py +120 -0
  138. package/kits/python/src/sdkloom_runtime/wait.py +44 -0
  139. package/kits/python/src/sdkloom_runtime/webhooks.py +84 -0
  140. package/kits/python/tests/support.py +28 -0
  141. package/kits/python/tests/test_client.py +275 -0
  142. package/kits/python/tests/test_compat.py +87 -0
  143. package/kits/python/tests/test_http.py +94 -0
  144. package/kits/python/tests/test_lang.py +104 -0
  145. package/kits/python/tests/test_models.py +110 -0
  146. package/kits/python/tests/test_multipart.py +37 -0
  147. package/kits/python/tests/test_pagination.py +70 -0
  148. package/kits/python/tests/test_sse.py +61 -0
  149. package/kits/python/tests/test_testing.py +130 -0
  150. package/kits/python/tests/test_transport.py +124 -0
  151. package/kits/python/tests/test_wait.py +46 -0
  152. package/kits/python/tests/test_webhooks.py +57 -0
  153. package/kits/python/versions.json +33 -0
  154. package/kits/rust/kit.json +6 -0
  155. package/kits/rust/src/runtime/client.rs +212 -0
  156. package/kits/rust/src/runtime/context.rs +182 -0
  157. package/kits/rust/src/runtime/crypto.rs +84 -0
  158. package/kits/rust/src/runtime/errors.rs +147 -0
  159. package/kits/rust/src/runtime/http.rs +248 -0
  160. package/kits/rust/src/runtime/json.rs +424 -0
  161. package/kits/rust/src/runtime/lang.rs +296 -0
  162. package/kits/rust/src/runtime/mod.rs +30 -0
  163. package/kits/rust/src/runtime/models.rs +266 -0
  164. package/kits/rust/src/runtime/multipart.rs +81 -0
  165. package/kits/rust/src/runtime/pagination.rs +117 -0
  166. package/kits/rust/src/runtime/sse.rs +195 -0
  167. package/kits/rust/src/runtime/testing.rs +308 -0
  168. package/kits/rust/src/runtime/transport.rs +324 -0
  169. package/kits/rust/src/runtime/wait.rs +29 -0
  170. package/kits/rust/src/runtime/webhooks.rs +142 -0
  171. package/kits/rust/tests/client.rs +152 -0
  172. package/kits/rust/tests/http.rs +44 -0
  173. package/kits/rust/tests/json.rs +82 -0
  174. package/kits/rust/tests/lang.rs +74 -0
  175. package/kits/rust/tests/multipart.rs +21 -0
  176. package/kits/rust/tests/pagination.rs +61 -0
  177. package/kits/rust/tests/sse.rs +77 -0
  178. package/kits/rust/tests/testing.rs +90 -0
  179. package/kits/rust/tests/transport.rs +218 -0
  180. package/kits/rust/tests/wait.rs +32 -0
  181. package/kits/rust/tests/webhooks.rs +73 -0
  182. package/kits/rust/versions.json +6 -0
  183. package/kits/typescript/kit.json +6 -0
  184. package/kits/typescript/src/client.ts +223 -0
  185. package/kits/typescript/src/context.ts +108 -0
  186. package/kits/typescript/src/errors.ts +63 -0
  187. package/kits/typescript/src/helpers.ts +49 -0
  188. package/kits/typescript/src/http.ts +192 -0
  189. package/kits/typescript/src/models.ts +139 -0
  190. package/kits/typescript/src/multipart.ts +66 -0
  191. package/kits/typescript/src/pagination.ts +54 -0
  192. package/kits/typescript/src/pipeline.ts +25 -0
  193. package/kits/typescript/src/sse.ts +102 -0
  194. package/kits/typescript/src/testing.ts +217 -0
  195. package/kits/typescript/src/transport.ts +101 -0
  196. package/kits/typescript/src/wait.ts +36 -0
  197. package/kits/typescript/src/webhooks.ts +168 -0
  198. package/kits/typescript/tests/client.test.ts +269 -0
  199. package/kits/typescript/tests/helpers.test.ts +27 -0
  200. package/kits/typescript/tests/http.test.ts +80 -0
  201. package/kits/typescript/tests/models.test.ts +71 -0
  202. package/kits/typescript/tests/multipart.test.ts +28 -0
  203. package/kits/typescript/tests/pagination.test.ts +76 -0
  204. package/kits/typescript/tests/sse.test.ts +82 -0
  205. package/kits/typescript/tests/testing.test.ts +103 -0
  206. package/kits/typescript/tests/transport.test.ts +127 -0
  207. package/kits/typescript/tests/wait.test.ts +31 -0
  208. package/kits/typescript/tests/webhooks.test.ts +53 -0
  209. package/kits/typescript/versions.json +15 -0
  210. package/package.json +37 -4
  211. package/packages/cli/recipes/apiKeyHeader.ts +16 -0
  212. package/packages/cli/recipes/apiVersionHeader.ts +16 -0
  213. package/packages/cli/recipes/basic.ts +13 -0
  214. package/packages/cli/recipes/bearer.ts +10 -0
  215. package/packages/cli/recipes/hmacSign.ts +23 -0
  216. package/packages/cli/recipes/idempotencyKey.ts +19 -0
  217. package/packages/cli/recipes/oauthClientCredentials.ts +50 -0
  218. package/packages/cli/recipes/retry.ts +42 -0
  219. package/packages/cli/recipes/timing.ts +12 -0
  220. package/packages/cli/recipes/userAgent.ts +8 -0
  221. package/packages/cli/src/build.js +93 -0
  222. package/packages/cli/src/commands/build.js +31 -0
  223. package/packages/cli/src/commands/conformance-check.js +50 -0
  224. package/packages/cli/src/commands/contract.js +181 -0
  225. package/packages/cli/src/commands/diff.js +113 -0
  226. package/packages/cli/src/commands/doctor.js +43 -0
  227. package/packages/cli/src/commands/import-openapi.js +42 -0
  228. package/packages/cli/src/commands/init.js +27 -0
  229. package/packages/cli/src/commands/kit-check.js +145 -0
  230. package/packages/cli/src/commands/publish.js +81 -0
  231. package/packages/cli/src/commands/recipe.js +49 -0
  232. package/packages/cli/src/commands/record.js +181 -0
  233. package/packages/cli/src/commands/serve.js +156 -0
  234. package/packages/cli/src/commands/spec-check.js +57 -0
  235. package/packages/cli/src/commands/test.js +177 -0
  236. package/packages/cli/src/commands/variants.js +32 -0
  237. package/packages/cli/src/commands/verify.js +57 -0
  238. package/packages/cli/src/commands/version.js +63 -0
  239. package/packages/cli/src/containers.js +82 -0
  240. package/packages/cli/src/coverage.js +72 -0
  241. package/packages/cli/src/git.js +25 -0
  242. package/packages/cli/src/io.js +50 -0
  243. package/packages/cli/src/java/ScenarioHarness.java +297 -0
  244. package/packages/cli/src/java/SchemaRoundTrip.java +63 -0
  245. package/packages/cli/src/java.js +70 -0
  246. package/packages/cli/src/js/harness.mjs +120 -0
  247. package/packages/cli/src/kits.js +103 -0
  248. package/packages/cli/src/languages/csharp.js +274 -0
  249. package/packages/cli/src/languages/go.js +185 -0
  250. package/packages/cli/src/languages/index.js +18 -0
  251. package/packages/cli/src/languages/java.js +187 -0
  252. package/packages/cli/src/languages/python.js +120 -0
  253. package/packages/cli/src/languages/rust.js +189 -0
  254. package/packages/cli/src/languages/types.js +93 -0
  255. package/packages/cli/src/languages/typescript.js +112 -0
  256. package/packages/cli/src/main.js +13 -0
  257. package/packages/cli/src/packaging.js +39 -0
  258. package/packages/cli/src/portability.js +45 -0
  259. package/packages/cli/src/profiles.js +55 -0
  260. package/packages/cli/src/project.js +56 -0
  261. package/packages/cli/src/python/scenario_harness.py +162 -0
  262. package/packages/cli/src/python/schema_roundtrip.py +42 -0
  263. package/packages/cli/src/registries.js +214 -0
  264. package/packages/cli/src/resolve-core.js +39 -0
  265. package/packages/cli/src/run.js +133 -0
  266. package/packages/cli/src/runtimes.js +61 -0
  267. package/packages/cli/src/scenarios-java.js +82 -0
  268. package/packages/cli/src/scenarios-javascript.js +54 -0
  269. package/packages/cli/src/scenarios-python.js +90 -0
  270. package/packages/cli/src/scenarios.js +183 -0
  271. package/packages/cli/src/schema.js +84 -0
  272. package/packages/cli/src/templates.js +85 -0
  273. package/packages/cli/src/toolchains.js +68 -0
  274. package/packages/cli/src/transpiled-tests.js +92 -0
  275. package/packages/codegen/src/canonical-json.js +31 -0
  276. package/packages/codegen/src/capabilities.js +50 -0
  277. package/packages/codegen/src/code-writer.js +54 -0
  278. package/packages/codegen/src/file-tree.js +25 -0
  279. package/packages/codegen/src/hash.js +6 -0
  280. package/packages/codegen/src/index.js +16 -0
  281. package/packages/codegen/src/lock.js +106 -0
  282. package/packages/conformance/src/case.js +143 -0
  283. package/packages/conformance/src/checks.js +40 -0
  284. package/packages/conformance/src/index.js +3 -0
  285. package/packages/conformance/src/matrix.js +48 -0
  286. package/packages/conformance/src/suite.js +48 -0
  287. package/packages/differ/src/diff.js +500 -0
  288. package/packages/differ/src/index.js +3 -0
  289. package/packages/differ/src/notes.js +112 -0
  290. package/packages/differ/src/support.js +34 -0
  291. package/packages/gen-csharp/src/emit-client.js +397 -0
  292. package/packages/gen-csharp/src/emit-harness.js +333 -0
  293. package/packages/gen-csharp/src/emit-mock.js +111 -0
  294. package/packages/gen-csharp/src/emit-models.js +119 -0
  295. package/packages/gen-csharp/src/emit-webhooks.js +57 -0
  296. package/packages/gen-csharp/src/generate.js +245 -0
  297. package/packages/gen-csharp/src/index.js +5 -0
  298. package/packages/gen-csharp/src/names.js +284 -0
  299. package/packages/gen-go/src/emit-client.js +405 -0
  300. package/packages/gen-go/src/emit-harness.js +294 -0
  301. package/packages/gen-go/src/emit-mock.js +112 -0
  302. package/packages/gen-go/src/emit-models.js +146 -0
  303. package/packages/gen-go/src/emit-webhooks.js +58 -0
  304. package/packages/gen-go/src/generate.js +205 -0
  305. package/packages/gen-go/src/index.js +5 -0
  306. package/packages/gen-go/src/names.js +197 -0
  307. package/packages/gen-java/src/emit-client.js +441 -0
  308. package/packages/gen-java/src/emit-models.js +342 -0
  309. package/packages/gen-java/src/emit-testing.js +123 -0
  310. package/packages/gen-java/src/emit-webhooks.js +70 -0
  311. package/packages/gen-java/src/generate.js +244 -0
  312. package/packages/gen-java/src/index.js +4 -0
  313. package/packages/gen-java/src/names.js +197 -0
  314. package/packages/gen-python/src/emit-client.js +272 -0
  315. package/packages/gen-python/src/emit-models.js +139 -0
  316. package/packages/gen-python/src/emit-testing.js +93 -0
  317. package/packages/gen-python/src/emit-webhooks.js +48 -0
  318. package/packages/gen-python/src/generate.js +237 -0
  319. package/packages/gen-python/src/index.js +2 -0
  320. package/packages/gen-python/src/names.js +161 -0
  321. package/packages/gen-python/src/style.js +67 -0
  322. package/packages/gen-rust/src/emit-client.js +379 -0
  323. package/packages/gen-rust/src/emit-harness.js +278 -0
  324. package/packages/gen-rust/src/emit-mock.js +121 -0
  325. package/packages/gen-rust/src/emit-models.js +117 -0
  326. package/packages/gen-rust/src/emit-webhooks.js +58 -0
  327. package/packages/gen-rust/src/generate.js +243 -0
  328. package/packages/gen-rust/src/index.js +5 -0
  329. package/packages/gen-rust/src/names.js +223 -0
  330. package/packages/gen-typescript/src/emit-client.js +434 -0
  331. package/packages/gen-typescript/src/emit-models.js +93 -0
  332. package/packages/gen-typescript/src/emit-package.js +90 -0
  333. package/packages/gen-typescript/src/emit-testing.js +138 -0
  334. package/packages/gen-typescript/src/emit-webhooks.js +52 -0
  335. package/packages/gen-typescript/src/generate.js +70 -0
  336. package/packages/gen-typescript/src/index.js +3 -0
  337. package/packages/gen-typescript/src/naming.js +64 -0
  338. package/packages/gen-typescript/src/runtime.js +81 -0
  339. package/packages/gen-typescript/src/types.js +136 -0
  340. package/packages/ir/src/api-surface.js +22 -0
  341. package/packages/ir/src/checks.js +52 -0
  342. package/packages/ir/src/index.js +32 -0
  343. package/packages/ir/src/ir.js +214 -0
  344. package/packages/ir/src/pages.js +18 -0
  345. package/packages/ir/src/validate-ir.js +462 -0
  346. package/packages/ir/src/validate-types.js +140 -0
  347. package/packages/kit/src/block-parser.js +196 -0
  348. package/packages/kit/src/index.js +15 -0
  349. package/packages/kit/src/kit-check.js +203 -0
  350. package/packages/kit/src/sources.js +53 -0
  351. package/packages/kit/src/version-policy.js +133 -0
  352. package/packages/kit/src/version-range.js +132 -0
  353. package/packages/openapi/src/import.js +292 -0
  354. package/packages/openapi/src/index.js +1 -0
  355. package/packages/openapi/src/names.js +50 -0
  356. package/packages/openapi/src/schemas.js +264 -0
  357. package/packages/packager/src/archive.js +106 -0
  358. package/packages/packager/src/crate.js +39 -0
  359. package/packages/packager/src/gomodule.js +11 -0
  360. package/packages/packager/src/index.js +9 -0
  361. package/packages/packager/src/maven.js +85 -0
  362. package/packages/packager/src/metadata.js +34 -0
  363. package/packages/packager/src/npm.js +71 -0
  364. package/packages/packager/src/nuget.js +78 -0
  365. package/packages/packager/src/sbom.js +56 -0
  366. package/packages/packager/src/wheel.js +62 -0
  367. package/packages/spec/src/index.js +11 -0
  368. package/packages/spec/src/requirements.js +139 -0
  369. package/packages/transpile/src/ast.js +51 -0
  370. package/packages/transpile/src/check.js +669 -0
  371. package/packages/transpile/src/emit-csharp.js +469 -0
  372. package/packages/transpile/src/emit-go.js +529 -0
  373. package/packages/transpile/src/emit-java.js +360 -0
  374. package/packages/transpile/src/emit-python.js +320 -0
  375. package/packages/transpile/src/emit-rust.js +499 -0
  376. package/packages/transpile/src/errors.js +15 -0
  377. package/packages/transpile/src/index.js +13 -0
  378. package/packages/transpile/src/lexer.js +161 -0
  379. package/packages/transpile/src/parser.js +543 -0
  380. package/packages/transpile/src/tests/ast.js +46 -0
  381. package/packages/transpile/src/tests/parse.js +376 -0
  382. package/packages/transpile/src/tests/translate.js +849 -0
  383. package/packages/transpile/src/transpile.js +57 -0
@@ -0,0 +1,462 @@
1
+ // Validates a whole IR document. Returns "<path>: <message>" strings, sorted; empty means valid.
2
+
3
+ import {
4
+ checkBoolean,
5
+ checkNameList,
6
+ checkOneOf,
7
+ checkOptionalText,
8
+ createDuplicateTracker,
9
+ IDENTIFIER,
10
+ isNonEmptyString,
11
+ isRecord,
12
+ listAt,
13
+
14
+ } from "./checks.ts";
15
+
16
+ import { checkFields, checkTypeNode, } from "./validate-types.ts";
17
+
18
+
19
+
20
+
21
+
22
+
23
+ const METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
24
+ const LOCATIONS = ["path", "query", "header"];
25
+ const STABILITIES = ["stable", "beta", "experimental"];
26
+ const PLACEHOLDER = /\{([^{}]+)\}/g;
27
+ const MIN_ERROR_STATUS = 400;
28
+ const MAX_ERROR_STATUS = 599;
29
+
30
+ function checkServers(value , report ) {
31
+ const servers = listAt(value, "servers", report);
32
+ if (Array.isArray(value) && servers.length === 0) report("servers", "must list at least one server");
33
+ const names = new Set ();
34
+ const track = createDuplicateTracker("server", report);
35
+ servers.forEach((server, index) => {
36
+ const path = `servers[${index}]`;
37
+ if (!isRecord(server)) {
38
+ report(path, "must be an object");
39
+ return;
40
+ }
41
+ if (isNonEmptyString(server["name"])) {
42
+ track(server["name"], `${path}.name`);
43
+ names.add(server["name"]);
44
+ } else {
45
+ report(`${path}.name`, "must be a non-empty string");
46
+ }
47
+ const url = server["url"];
48
+ const valid = typeof url === "string" && URL.canParse(url) && ["http:", "https:"].includes(new URL(url).protocol);
49
+ if (!valid) report(`${path}.url`, "must be an http or https URL");
50
+ });
51
+ return names;
52
+ }
53
+
54
+ /** Collects named types (name → kind) and reports bad or duplicate names. */
55
+ function collectTypes(value , report ) {
56
+ const kinds = new Map ();
57
+ const track = createDuplicateTracker("type", report);
58
+ listAt(value, "types", report).forEach((namedType, index) => {
59
+ if (!isRecord(namedType)) return;
60
+ const name = namedType["name"];
61
+ if (typeof name !== "string" || !IDENTIFIER.test(name)) {
62
+ report(`types[${index}].name`, "must be an identifier");
63
+ return;
64
+ }
65
+ track(name, `types[${index}].name`);
66
+ if (!kinds.has(name)) kinds.set(name, isRecord(namedType["type"]) ? namedType["type"]["kind"] : undefined);
67
+ });
68
+ return kinds;
69
+ }
70
+
71
+ function checkTypes(value , context ) {
72
+ if (!Array.isArray(value)) return;
73
+ value.forEach((namedType , index) => {
74
+ const path = `types[${index}]`;
75
+ if (!isRecord(namedType)) {
76
+ context.report(path, "must be an object");
77
+ return;
78
+ }
79
+ checkTypeNode(namedType["type"], `${path}.type`, context);
80
+ checkOptionalText(namedType, "doc", path, context.report);
81
+ checkOptionalText(namedType, "deprecated", path, context.report);
82
+ });
83
+ }
84
+
85
+ function checkParams(operation , path , context ) {
86
+ const pathParams = [];
87
+ const trackers = new Map(LOCATIONS.map((location) => [location, createDuplicateTracker(`${location} parameter`, context.report)]));
88
+
89
+ listAt(operation["params"], `${path}.params`, context.report).forEach((param, index) => {
90
+ const paramPath = `${path}.params[${index}]`;
91
+ if (!isRecord(param)) {
92
+ context.report(paramPath, "must be an object");
93
+ return;
94
+ }
95
+ const name = param["name"];
96
+ const location = param["in"];
97
+ checkOneOf(location, LOCATIONS, `${paramPath}.in`, context.report);
98
+ if (!isNonEmptyString(name)) context.report(`${paramPath}.name`, "must be a non-empty string");
99
+ else trackers.get(location )?.(name, `${paramPath}.name`);
100
+
101
+ checkTypeNode(param["type"], `${paramPath}.type`, context);
102
+ checkBoolean(param, "optional", paramPath, context.report);
103
+ checkOptionalText(param, "doc", paramPath, context.report);
104
+ if (location === "path" && isNonEmptyString(name)) {
105
+ if (param["optional"] === true) context.report(`${paramPath}.optional`, "path parameters cannot be optional");
106
+ pathParams.push({ name, path: paramPath, type: param["type"] });
107
+ }
108
+ });
109
+
110
+ const route = operation["path"];
111
+ if (typeof route !== "string") return;
112
+ // {+name}: RFC 6570 reserved expansion (limited to "/"), for a string that may span path segments.
113
+ const found = [...route.matchAll(PLACEHOLDER)].map((match) => match[1] ?? "");
114
+ const reserved = new Set(found.filter((name) => name.startsWith("+")).map((name) => name.slice(1)));
115
+ const placeholders = new Set(found.map((name) => name.replace(/^\+/, "")));
116
+ pathParams
117
+ .filter((param) => reserved.has(param.name))
118
+ .filter((param) => !(isRecord(param.type) && param.type["kind"] === "primitive" && param.type["name"] === "string"))
119
+ .forEach((param) => context.report(param.path, `{+${param.name}} spans path segments, so ${param.name} must be a string`));
120
+ const declared = new Set(pathParams.map((param) => param.name));
121
+ [...placeholders]
122
+ .filter((name) => !declared.has(name))
123
+ .forEach((name) => context.report(`${path}.path`, `{${name}} has no path parameter`));
124
+ pathParams
125
+ .filter((param) => !placeholders.has(param.name))
126
+ .forEach((param) => context.report(param.path, `path parameter ${param.name} does not appear in the path`));
127
+ }
128
+
129
+ function checkErrors(value , path , context ) {
130
+ const track = createDuplicateTracker("status", context.report);
131
+ listAt(value, path, context.report).forEach((error, index) => {
132
+ const errorPath = `${path}[${index}]`;
133
+ if (!isRecord(error)) {
134
+ context.report(errorPath, "must be an object");
135
+ return;
136
+ }
137
+ const status = error["status"];
138
+ const validStatus = typeof status === "number" && Number.isInteger(status) && status >= MIN_ERROR_STATUS && status <= MAX_ERROR_STATUS;
139
+ if (validStatus) track(String(status), `${errorPath}.status`);
140
+ else context.report(`${errorPath}.status`, `must be an integer from ${MIN_ERROR_STATUS} to ${MAX_ERROR_STATUS}`);
141
+ if (typeof error["name"] !== "string" || !IDENTIFIER.test(error["name"])) context.report(`${errorPath}.name`, "must be an identifier");
142
+ if ("type" in error) checkTypeNode(error["type"], `${errorPath}.type`, context);
143
+ });
144
+ }
145
+
146
+ function checkMiddlewares(value , context ) {
147
+ const names = new Set ();
148
+ const track = createDuplicateTracker("middleware", context.report);
149
+ listAt(value, "middlewares", context.report).forEach((middleware, index) => {
150
+ const path = `middlewares[${index}]`;
151
+ if (!isRecord(middleware)) {
152
+ context.report(path, "must be an object");
153
+ return;
154
+ }
155
+ const name = middleware["name"];
156
+ if (typeof name === "string" && IDENTIFIER.test(name)) {
157
+ track(name, `${path}.name`);
158
+ names.add(name);
159
+ } else {
160
+ context.report(`${path}.name`, "must be an identifier");
161
+ }
162
+ checkFields(middleware["config"], `${path}.config`, context);
163
+ checkOptionalText(middleware, "doc", path, context.report);
164
+ });
165
+ return names;
166
+ }
167
+
168
+ /** Checks a `use` list: non-empty names that refer to declared middleware. */
169
+ function checkUse(value , path , known , report ) {
170
+ checkNameList(value, path, report);
171
+ if (!Array.isArray(value)) return;
172
+ value.forEach((name , index) => {
173
+ if (isNonEmptyString(name) && !known.has(name)) report(`${path}[${index}]`, `unknown middleware ${name}`);
174
+ });
175
+ }
176
+
177
+ function checkOperation(operation , path , context ) {
178
+ checkOneOf(operation["method"], METHODS, `${path}.method`, context.report);
179
+ const route = operation["path"];
180
+ if (typeof route !== "string" || !route.startsWith("/")) context.report(`${path}.path`, "must start with /");
181
+ checkParams(operation, path, context);
182
+ if ("body" in operation) checkTypeNode(operation["body"], `${path}.body`, context, { allowStream: true, allowMultipart: true });
183
+ if ("returns" in operation) checkTypeNode(operation["returns"], `${path}.returns`, context, { allowStream: true });
184
+ if ("events" in operation) {
185
+ checkTypeNode(operation["events"], `${path}.events`, context);
186
+ if ("returns" in operation) context.report(`${path}.events`, "an operation returns either a result or events, not both");
187
+ if ("paginate" in operation) context.report(`${path}.events`, "an event stream cannot be paginated");
188
+ }
189
+ checkErrors(operation["errors"], `${path}.errors`, context);
190
+ checkOneOf(operation["stability"], STABILITIES, `${path}.stability`, context.report);
191
+ checkUse(operation["use"], `${path}.use`, context.middlewares, context.report);
192
+ checkOptionalText(operation, "doc", path, context.report);
193
+ checkOptionalText(operation, "deprecated", path, context.report);
194
+ }
195
+
196
+
197
+
198
+ /** The fields of a named object type, or undefined. */
199
+ function objectFields(types , name ) {
200
+ if (!Array.isArray(types)) return undefined;
201
+ const named = types.find((entry ) => isRecord(entry) && entry["name"] === name);
202
+ if (!isRecord(named) || !isRecord(named["type"]) || named["type"]["kind"] !== "object") return undefined;
203
+ const fields = named["type"]["fields"];
204
+ return Array.isArray(fields) ? fields.filter(isRecord) : undefined;
205
+ }
206
+
207
+ function isPrimitive(field , name ) {
208
+ const type = field?.["type"];
209
+ return isRecord(type) && type["kind"] === "primitive" && type["name"] === name;
210
+ }
211
+
212
+ /** paginate: the result is a model with a list field of items, and the chaining parameter is an optional query parameter. */
213
+ function checkPagination(operation , path , types , report ) {
214
+ const at = `${path}.paginate`;
215
+ const paginate = operation["paginate"];
216
+ if (!isRecord(paginate)) {
217
+ report(at, "must be an object");
218
+ return;
219
+ }
220
+ checkOneOf(paginate["kind"], ["cursor", "offset", "link"], `${at}.kind`, report);
221
+ const returns = operation["returns"];
222
+ if (paginate["kind"] === "link" && !("items" in paginate)) {
223
+ if (!isRecord(returns) || returns["kind"] !== "list") report(at, "without items, a Link-header paginated operation must return a list");
224
+ return;
225
+ }
226
+ const fields = isRecord(returns) && returns["kind"] === "ref" ? objectFields(types, returns["name"]) : undefined;
227
+ if (fields === undefined) {
228
+ report(at, "needs an operation that returns a model (one page)");
229
+ return;
230
+ }
231
+ const field = (name ) => fields.find((entry) => entry["name"] === name);
232
+ const items = field(paginate["items"]);
233
+ if (items === undefined || !isRecord(items["type"]) || items["type"]["kind"] !== "list" || items["optional"] === true || items["nullable"] === true) {
234
+ report(`${at}.items`, "must name a required list field of the page");
235
+ }
236
+ const params = Array.isArray(operation["params"]) ? operation["params"].filter(isRecord) : [];
237
+ const queryParam = (name , type ) => params.some((param) => param["name"] === name && param["in"] === "query" && isPrimitive(param, type));
238
+ if (paginate["kind"] === "cursor") {
239
+ if (!isPrimitive(field(paginate["next"]), "string")) report(`${at}.next`, "must name a string field of the page");
240
+ if (!queryParam(paginate["param"], "string")) report(`${at}.param`, "must name a string query parameter");
241
+ }
242
+ if (paginate["kind"] === "offset") {
243
+ if (!queryParam(paginate["param"], "int")) report(`${at}.param`, "must name an int query parameter");
244
+ if ("limit" in paginate && !queryParam(paginate["limit"], "int")) report(`${at}.limit`, "must name an int query parameter");
245
+ }
246
+ const chained = params.find((param) => param["name"] === paginate["param"]);
247
+ if (chained !== undefined && chained["optional"] !== true) report(`${at}.param`, "must be optional: the first page is fetched without it");
248
+ }
249
+
250
+ /** wait: poll names an operation that returns the same model and takes one path parameter, the id read from the result. */
251
+ function checkWait(operation , path , operations , types , report ) {
252
+ const at = `${path}.wait`;
253
+ const wait = operation["wait"];
254
+ if (!isRecord(wait)) {
255
+ report(at, "must be an object");
256
+ return;
257
+ }
258
+ const poll = operations.find((candidate) => isRecord(candidate) && candidate["name"] === wait["poll"]);
259
+ if (!isRecord(poll)) {
260
+ report(`${at}.poll`, "must name an operation");
261
+ return;
262
+ }
263
+ const returns = operation["returns"];
264
+ if (!isRecord(returns) || returns["kind"] !== "ref" || JSON.stringify(returns) !== JSON.stringify(poll["returns"])) {
265
+ report(`${at}.poll`, "must return the same model as the operation it waits for");
266
+ return;
267
+ }
268
+ const fields = objectFields(types, returns["name"]) ?? [];
269
+ const field = (name ) => fields.find((entry) => entry["name"] === name && entry["optional"] !== true && entry["nullable"] !== true);
270
+ const text = (entry ) => isPrimitive(entry, "string") || (isRecord(entry?.["type"]) && entry["type"]["kind"] === "enum");
271
+ if (!text(field(wait["from"]))) report(`${at}.from`, "must name a required string field of the result");
272
+ if (!text(field(wait["field"]))) report(`${at}.field`, "must name a required string or enum field of the result");
273
+ const params = Array.isArray(poll["params"]) ? poll["params"].filter(isRecord) : [];
274
+ const required = params.filter((param) => param["optional"] !== true);
275
+ if (required.length !== 1 || required[0]?.["name"] !== wait["param"] || required[0]?.["in"] !== "path") {
276
+ report(`${at}.param`, `must be the only required parameter of ${String(wait["poll"])}, a path parameter`);
277
+ }
278
+ const done = wait["done"];
279
+ if (!Array.isArray(done) || done.length === 0 || !done.every(isNonEmptyString)) report(`${at}.done`, "must list the field values that mean the work is finished");
280
+ for (const name of ["intervalMs", "timeoutMs"]) {
281
+ const ms = wait[name];
282
+ if (typeof ms !== "number" || !Number.isInteger(ms) || ms <= 0) report(`${at}.${name}`, "must be a positive integer");
283
+ }
284
+ }
285
+
286
+ /** apiVersions: a lower-case header and distinct versions, oldest first; every operation's since is one of them. */
287
+ function checkApiVersions(ir , report ) {
288
+ const versions = ir["apiVersions"];
289
+ const known = new Set ();
290
+ if (versions !== undefined) {
291
+ if (!isRecord(versions)) {
292
+ report("apiVersions", "must be an object");
293
+ return;
294
+ }
295
+ if (typeof versions["header"] !== "string" || !HEADER_NAME.test(versions["header"])) report("apiVersions.header", "must be a lower-case header name");
296
+ const values = versions["values"];
297
+ if (!Array.isArray(values) || values.length === 0 || !values.every(isNonEmptyString)) report("apiVersions.values", "must list the versions, oldest first");
298
+ else {
299
+ values.forEach((value) => {
300
+ if (known.has(value)) report("apiVersions.values", `${String(value)} is listed twice`);
301
+ known.add(value);
302
+ });
303
+ }
304
+ }
305
+ listAt(ir["operations"], "operations", () => {}).forEach((operation, index) => {
306
+ if (!isRecord(operation) || !("since" in operation)) return;
307
+ if (versions === undefined) report(`operations[${index}].since`, "needs apiVersions");
308
+ else if (!known.has(operation["since"])) report(`operations[${index}].since`, "must be one of apiVersions.values");
309
+ });
310
+ }
311
+
312
+ function checkOperations(value , context , types ) {
313
+ const track = createDuplicateTracker("operation", context.report);
314
+ const names = new Set(listAt(value, "operations", () => {}).map((operation) => (isRecord(operation) ? operation["name"] : undefined)));
315
+ listAt(value, "operations", context.report).forEach((operation, index) => {
316
+ const path = `operations[${index}]`;
317
+ if (!isRecord(operation)) {
318
+ context.report(path, "must be an object");
319
+ return;
320
+ }
321
+ const name = operation["name"];
322
+ if (typeof name === "string" && IDENTIFIER.test(name)) track(name, `${path}.name`);
323
+ else context.report(`${path}.name`, "must be an identifier");
324
+ checkOperation(operation, path, context);
325
+ if ("wait" in operation) {
326
+ checkWait(operation, path, Array.isArray(value) ? value : [], types, context.report);
327
+ // SDKs add <name>AndWait.
328
+ if (names.has(`${String(name)}AndWait`)) context.report(`${path}.wait`, `${String(name)}AndWait would clash with the operation of that name`);
329
+ }
330
+ if ("paginate" in operation) {
331
+ checkPagination(operation, path, types, context.report);
332
+ // SDKs add <name>All, the iterator over every item.
333
+ if (names.has(`${String(name)}All`)) context.report(`${path}.paginate`, `the iterator ${String(name)}All would clash with the operation of that name`);
334
+ }
335
+ });
336
+ }
337
+
338
+ const HEADER_NAME = /^[a-z0-9!#$%&'*+.^_`|~-]+$/;
339
+
340
+ function checkSignature(signature , path , report ) {
341
+ if (!isRecord(signature)) {
342
+ report(path, "must be an object");
343
+ return;
344
+ }
345
+ checkOneOf(signature["kind"], ["hmac"], `${path}.kind`, report);
346
+ checkOneOf(signature["algorithm"], ["sha256"], `${path}.algorithm`, report);
347
+ checkOneOf(signature["encoding"], ["hex", "base64"], `${path}.encoding`, report);
348
+ checkOneOf(signature["secret"], ["text", "base64"], `${path}.secret`, report);
349
+ const header = signature["header"];
350
+ if (typeof header !== "string" || !HEADER_NAME.test(header)) report(`${path}.header`, "must be a lower-case header name");
351
+ const signed = signature["signed"];
352
+ if (typeof signed !== "string" || !signed.includes("{body}")) {
353
+ report(`${path}.signed`, "must include {body}");
354
+ } else {
355
+ for (const match of signed.matchAll(/\{([^{}]*)\}/g)) {
356
+ const name = match[1] ?? "";
357
+ if (name !== "body" && !HEADER_NAME.test(name)) report(`${path}.signed`, `{${name}} is not {body} or a lower-case header name`);
358
+ }
359
+ }
360
+ for (const key of ["prefix", "separator", "secretPrefix"]) {
361
+ if (key in signature && typeof signature[key] !== "string") report(`${path}.${key}`, "must be a string");
362
+ }
363
+ if ("timestamp" in signature) {
364
+ const timestamp = signature["timestamp"];
365
+ if (!isRecord(timestamp) || typeof timestamp["header"] !== "string" || !HEADER_NAME.test(timestamp["header"])) report(`${path}.timestamp.header`, "must be a lower-case header name");
366
+ const tolerance = isRecord(timestamp) ? timestamp["toleranceSeconds"] : undefined;
367
+ if (typeof tolerance !== "number" || !Number.isInteger(tolerance) || tolerance <= 0) report(`${path}.timestamp.toleranceSeconds`, "must be a positive integer");
368
+ }
369
+ }
370
+
371
+ function checkWebhooks(value , context ) {
372
+ if (value === undefined) return;
373
+ const track = createDuplicateTracker("webhook", context.report);
374
+ listAt(value, "webhooks", context.report).forEach((hook, index) => {
375
+ const path = `webhooks[${index}]`;
376
+ if (!isRecord(hook)) {
377
+ context.report(path, "must be an object");
378
+ return;
379
+ }
380
+ const name = hook["name"];
381
+ if (typeof name === "string" && IDENTIFIER.test(name)) track(name, `${path}.name`);
382
+ else context.report(`${path}.name`, "must be an identifier");
383
+ checkTypeNode(hook["payload"], `${path}.payload`, context);
384
+ checkSignature(hook["signature"], `${path}.signature`, context.report);
385
+ checkOptionalText(hook, "doc", path, context.report);
386
+ });
387
+ }
388
+
389
+ const LOGIC_TYPES = new Set(["int", "number", "string", "bool"]);
390
+
391
+ function isLogicType(node ) {
392
+ return isRecord(node) && node["kind"] === "primitive" && typeof node["name"] === "string" && LOGIC_TYPES.has(node["name"]);
393
+ }
394
+
395
+ /** Names generated SDKs already use next to the logic functions (Python modules, Go constructors, runtime exports). */
396
+ const RESERVED_LOGIC_NAMES = ["client", "newclient", "models", "errors", "entry", "logic", "middleware", "webhooks", "testing", "runtime", "servers", "options", "apierror", "transporterror", "decodeerror"];
397
+
398
+ /** A name as every target spells it: feeCents, fee_cents and FeeCents are one name. */
399
+ const spelled = (name ) => name.toLowerCase().replace(/_/g, "");
400
+
401
+ /** Logic functions: identifiers, required int/number/string/bool inputs and such a result. */
402
+ function checkLogic(value , context , root ) {
403
+ if (value === undefined) return;
404
+ const named = (key ) => (Array.isArray(root[key]) ? (root[key] ).flatMap((entry) => (isRecord(entry) && typeof entry["name"] === "string" ? [entry["name"]] : [])) : []);
405
+ const taken = new Map ([
406
+ ...RESERVED_LOGIC_NAMES.map((name) => [name, "a name the generated SDKs use"]),
407
+ [spelled(`${String(root["name"])}client`), "the client"],
408
+ ...named("types").map((name) => [spelled(name), `type ${name}`]),
409
+ ...named("middlewares").map((name) => [spelled(name), `middleware ${name}`]),
410
+ ...named("operations").map((name) => [spelled(name), `operation ${name}`]),
411
+ ...named("webhooks").map((name) => [spelled(name), `webhook ${name}`]),
412
+ ]);
413
+ const track = createDuplicateTracker("logic function", context.report);
414
+ listAt(value, "logic", context.report).forEach((entry, index) => {
415
+ const path = `logic[${index}]`;
416
+ if (!isRecord(entry)) {
417
+ context.report(path, "must be an object");
418
+ return;
419
+ }
420
+ const name = entry["name"];
421
+ if (typeof name === "string" && IDENTIFIER.test(name)) track(name, `${path}.name`);
422
+ else context.report(`${path}.name`, "must be an identifier");
423
+ const clash = typeof name === "string" ? taken.get(spelled(name)) : undefined;
424
+ if (clash !== undefined) context.report(`${path}.name`, `${String(name)} would clash with ${clash} in some languages; rename the logic function`);
425
+ checkFields(entry["input"], `${path}.input`, context);
426
+ listAt(entry["input"], `${path}.input`, () => undefined).forEach((field, fieldIndex) => {
427
+ if (!isRecord(field)) return;
428
+ if (field["optional"] === true || field["nullable"] === true || !isLogicType(field["type"])) {
429
+ context.report(`${path}.input[${fieldIndex}]`, "a logic input is a required int, number, string or bool");
430
+ }
431
+ });
432
+ if (!isLogicType(entry["returns"])) context.report(`${path}.returns`, "a logic function returns an int, number, string or bool");
433
+ checkOptionalText(entry, "doc", path, context.report);
434
+ });
435
+ }
436
+
437
+ export function validateIr(value ) {
438
+ if (!isRecord(value)) return ["$: must be an object"];
439
+
440
+ const issues = [];
441
+ const report = (path, message) => {
442
+ issues.push(`${path}: ${message}`);
443
+ };
444
+
445
+ if (value["irVersion"] !== 0) report("irVersion", "must be 0");
446
+ if (typeof value["name"] !== "string" || !IDENTIFIER.test(value["name"])) report("name", "must be an identifier");
447
+ checkOptionalText(value, "doc", "", report);
448
+
449
+ const servers = checkServers(value["servers"], report);
450
+ const defaultServer = value["defaultServer"];
451
+ if (typeof defaultServer !== "string" || !servers.has(defaultServer)) report("defaultServer", `unknown server ${String(defaultServer)}`);
452
+ const typeContext = { report, kinds: collectTypes(value["types"], report) };
453
+ const context = { ...typeContext, middlewares: checkMiddlewares(value["middlewares"], typeContext) };
454
+ checkUse(value["use"], "use", context.middlewares, report);
455
+ checkTypes(value["types"], context);
456
+ checkOperations(value["operations"], context, value["types"]);
457
+ checkWebhooks(value["webhooks"], context);
458
+ checkLogic(value["logic"], context, value);
459
+ checkApiVersions(value, context.report);
460
+
461
+ return issues.sort();
462
+ }
@@ -0,0 +1,140 @@
1
+ // Validates IR type nodes (docs/02-architecture.md, IR section).
2
+
3
+ import {
4
+ checkBoolean,
5
+ checkOptionalText,
6
+ createDuplicateTracker,
7
+ isNonEmptyString,
8
+ isRecord,
9
+ listAt,
10
+
11
+ } from "./checks.ts";
12
+
13
+
14
+ const PRIMITIVES = new Set ([
15
+ "string",
16
+ "int",
17
+ "number",
18
+ "bool",
19
+ "decimal",
20
+ "datetime",
21
+ "bytes",
22
+ "stream",
23
+ "multipart",
24
+ "secret",
25
+ ]);
26
+
27
+
28
+
29
+    
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+ function checkPrimitive(node , path , context , options ) {
41
+ const name = node["name"];
42
+ if (typeof name !== "string" || !PRIMITIVES.has(name)) {
43
+ context.report(path, `unknown primitive ${String(name)}`);
44
+ } else if (name === "stream" && options.allowStream !== true) {
45
+ context.report(path, "stream is only allowed as an operation body or result");
46
+ } else if (name === "multipart" && options.allowMultipart !== true) {
47
+ context.report(path, "multipart is only allowed as an operation body");
48
+ }
49
+ }
50
+
51
+ function checkEnum(node , path , context ) {
52
+ const values = listAt(node["values"], `${path}.values`, context.report);
53
+ if (Array.isArray(node["values"]) && values.length === 0) context.report(`${path}.values`, "must list at least one value");
54
+ const track = createDuplicateTracker("value", context.report);
55
+ values.forEach((value, index) => {
56
+ const valuePath = `${path}.values[${index}]`;
57
+ if (isNonEmptyString(value)) track(value, valuePath);
58
+ else context.report(valuePath, "must be a non-empty string");
59
+ });
60
+ }
61
+
62
+ function checkObject(node , path , context ) {
63
+ checkFields(node["fields"], `${path}.fields`, context);
64
+ }
65
+
66
+ /** Checks a list of fields (object fields or middleware config) at `path`. */
67
+ export function checkFields(value , path , context ) {
68
+ const track = createDuplicateTracker("field", context.report);
69
+ listAt(value, path, context.report).forEach((field, index) => {
70
+ const fieldPath = `${path}[${index}]`;
71
+ if (!isRecord(field)) {
72
+ context.report(fieldPath, "must be an object");
73
+ return;
74
+ }
75
+ if (isNonEmptyString(field["name"])) track(field["name"], `${fieldPath}.name`);
76
+ else context.report(`${fieldPath}.name`, "must be a non-empty string");
77
+ checkTypeNode(field["type"], `${fieldPath}.type`, context);
78
+ checkBoolean(field, "optional", fieldPath, context.report);
79
+ checkBoolean(field, "nullable", fieldPath, context.report);
80
+ checkOptionalText(field, "doc", fieldPath, context.report);
81
+ checkOptionalText(field, "deprecated", fieldPath, context.report);
82
+ });
83
+ }
84
+
85
+ function checkUnion(node , path , context ) {
86
+ if (!isNonEmptyString(node["discriminator"])) context.report(`${path}.discriminator`, "must be a non-empty string");
87
+ const track = createDuplicateTracker("tag", context.report);
88
+ const variants = listAt(node["variants"], `${path}.variants`, context.report);
89
+ if (Array.isArray(node["variants"]) && variants.length === 0) context.report(`${path}.variants`, "must list at least one variant");
90
+ variants.forEach((variant, index) => {
91
+ const variantPath = `${path}.variants[${index}]`;
92
+ if (!isRecord(variant)) {
93
+ context.report(variantPath, "must be an object");
94
+ return;
95
+ }
96
+ if (isNonEmptyString(variant["tag"])) track(variant["tag"], `${variantPath}.tag`);
97
+ else context.report(`${variantPath}.tag`, "must be a non-empty string");
98
+
99
+ const typeName = variant["type"];
100
+ if (typeof typeName !== "string" || !context.kinds.has(typeName)) {
101
+ context.report(`${variantPath}.type`, `unknown type ${String(typeName)}`);
102
+ } else if (context.kinds.get(typeName) !== "object") {
103
+ context.report(`${variantPath}.type`, `${typeName} is not an object type`);
104
+ }
105
+ });
106
+ }
107
+
108
+ export function checkTypeNode(node , path , context , options = {}) {
109
+ if (!isRecord(node)) {
110
+ context.report(path, "must be a type");
111
+ return;
112
+ }
113
+ switch (node["kind"]) {
114
+ case "primitive":
115
+ checkPrimitive(node, path, context, options);
116
+ return;
117
+ case "enum":
118
+ checkEnum(node, path, context);
119
+ return;
120
+ case "list":
121
+ checkTypeNode(node["item"], `${path}.item`, context);
122
+ return;
123
+ case "map":
124
+ checkTypeNode(node["value"], `${path}.value`, context);
125
+ return;
126
+ case "object":
127
+ checkObject(node, path, context);
128
+ return;
129
+ case "union":
130
+ checkUnion(node, path, context);
131
+ return;
132
+ case "ref": {
133
+ const name = node["name"];
134
+ if (typeof name !== "string" || !context.kinds.has(name)) context.report(path, `unknown type ${String(name)}`);
135
+ return;
136
+ }
137
+ default:
138
+ context.report(path, `unknown kind ${String(node["kind"])}`);
139
+ }
140
+ }