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,274 @@
1
+ // C#: one netstandard2.1 project with the vendored kit; tested on each .NET SDK (8, 10, …) by a harness program generated
2
+ // for the SDK. One dotnet installation hosts several SDKs, so each test project pins its SDK with global.json and NuGet
3
+ // is switched off: nothing is downloaded.
4
+
5
+ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
6
+ import { homedir } from "node:os";
7
+ import { dirname, join } from "node:path";
8
+ import { defaultNamespace, emitHarness, generateCSharp, } from "@sdkloom/gen-csharp";
9
+ import { nugetPackage, purl } from "@sdkloom/packager";
10
+ import { listFiles, toPosix } from "../io.ts";
11
+ import { CSHARP_MIDDLEWARE_FILE, loadKit, lockOf, profilesOf, SDKLOOM_VERSION, } from "../kits.ts";
12
+ import { printOutput } from "../packaging.ts";
13
+ import { nugetUpload } from "../registries.ts";
14
+ import { installed, spawnCommand, } from "../runtimes.ts";
15
+ import { resolveToolchain } from "../toolchains.ts";
16
+ import { harnessCase, } from "../scenarios.ts";
17
+
18
+
19
+ /** Native C# tests live in <tests>/csharp/: public static methods of classes whose names end in "Tests". */
20
+ const CSHARP_TESTS = "csharp";
21
+ const RUN_TIMEOUT_MS = 600_000;
22
+ const FRAMEWORK = "netstandard2.1";
23
+ const NO_NUGET = '<?xml version="1.0" encoding="utf-8"?><configuration><packageSources><clear /></packageSources></configuration>\n';
24
+
25
+ export function loadCSharpKit() {
26
+ return loadKit("csharp", join("src", "Runtime"), ".cs", profilesOf("csharp").base);
27
+ }
28
+
29
+ function dotnetEnv() {
30
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => key !== "NODE_TEST_CONTEXT"));
31
+ return { ...env, DOTNET_NOLOGO: "1", DOTNET_CLI_TELEMETRY_OPTOUT: "1", DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "1" };
32
+ }
33
+
34
+ /** "csharp@8" → "8". */
35
+ function versionOf(runtime ) {
36
+ const at = runtime.label.lastIndexOf("@");
37
+ if (at < 0) throw new Error(`${runtime.label}: kits/csharp/versions.json must list the .NET versions to test`);
38
+ return runtime.label.slice(at + 1);
39
+ }
40
+
41
+ /** The project file of the generated SDK, e.g. Acme.Payments.csproj. */
42
+ function projectFile(target ) {
43
+ return `${target.packageName}.csproj`;
44
+ }
45
+
46
+ /**
47
+ * A copy of the generated SDK in the run's workspace: building it writes bin/ and obj/, which must not land in the
48
+ * output directory (sdkloom build --check would report them).
49
+ */
50
+ function sdkCopy(ws , target ) {
51
+ return ws.once(`csharp-sdk:${target.name}`, () => {
52
+ const dir = ws.path(`csharp-sdk-${target.name}`);
53
+ target.files.forEach((text, path) => {
54
+ mkdirSync(dirname(join(dir, path)), { recursive: true });
55
+ writeFileSync(join(dir, path), text);
56
+ });
57
+ return join(dir, projectFile(target));
58
+ });
59
+ }
60
+
61
+ function xmlAttribute(value ) {
62
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll('"', "&quot;");
63
+ }
64
+
65
+ /** A console project on net<version>.0 that references the SDK, with its SDK version pinned and NuGet switched off. */
66
+ function consumer(dir , version , sdk , sources ) {
67
+ mkdirSync(dir, { recursive: true });
68
+ const project = join(dir, "App.csproj");
69
+ writeFileSync(
70
+ project,
71
+ `<Project Sdk="Microsoft.NET.Sdk">\n <PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net${version}.0</TargetFramework><Nullable>enable</Nullable></PropertyGroup>\n <ItemGroup><ProjectReference Include="${xmlAttribute(toPosix(sdk))}" /></ItemGroup>\n</Project>\n`,
72
+ );
73
+ writeFileSync(join(dir, "global.json"), `{"sdk":{"version":"${version}.0.100","rollForward":"latestFeature"}}\n`);
74
+ writeFileSync(join(dir, "nuget.config"), NO_NUGET);
75
+ sources.forEach((text, path) => {
76
+ mkdirSync(dirname(join(dir, path)), { recursive: true });
77
+ writeFileSync(join(dir, path), text);
78
+ });
79
+ return project;
80
+ }
81
+
82
+ /** Builds a project into <dir>/out; in a container the paths are absolute and the image has one SDK. */
83
+ function build(runtime , project ) {
84
+ return spawnCommand(runtime.command, ["build", project, "-o", join(dirname(project), "out"), "-v", "q", "-nologo"], { cwd: dirname(project), env: dotnetEnv(), timeout: RUN_TIMEOUT_MS });
85
+ }
86
+
87
+ /** The harness for one runtime, built once per run; building it checks the SDK compiles on that version. */
88
+ function harness(column ) {
89
+ const { target, runtime, ir, ws } = column;
90
+ return ws.once(`csharp:${runtime.label}`, () => {
91
+ const project = consumer(ws.path(`csharp-harness-${runtime.label}`), versionOf(runtime), sdkCopy(ws, target), new Map([["Program.cs", emitHarness(ir, target.module ?? "")]]));
92
+ const built = build(runtime, project);
93
+ if (built.status !== 0) throw new Error(`the generated C# SDK does not build with ${runtime.label}:\n${`${built.stdout}${built.stderr}`.trim()}`);
94
+ return join(dirname(project), "out", "App.dll");
95
+ });
96
+ }
97
+
98
+ function runHarness(column , plan ) {
99
+ const result = spawnCommand(column.runtime.command, [harness(column)], { input: JSON.stringify(plan), env: dotnetEnv(), timeout: RUN_TIMEOUT_MS });
100
+ if (result.status !== 0) throw new Error(`the C# harness failed: ${`${result.stderr}`.trim().split("\n").at(-1) ?? ""}`);
101
+ return JSON.parse(result.stdout) ;
102
+ }
103
+
104
+ const TEST_RUNNER = `// Runs every public static method of the *Tests classes; generated by sdkloom.
105
+ using System;
106
+ using System.Linq;
107
+ using System.Reflection;
108
+ using System.Threading.Tasks;
109
+
110
+ public static class SdkloomTestRunner
111
+ {
112
+ public static async Task<int> Main()
113
+ {
114
+ var tests = typeof(SdkloomTestRunner).Assembly.GetTypes()
115
+ .Where(type => type.Name.EndsWith("Tests", StringComparison.Ordinal))
116
+ .OrderBy(type => type.FullName, StringComparer.Ordinal)
117
+ .SelectMany(type => type.GetMethods(BindingFlags.Public | BindingFlags.Static).Where(method => method.GetParameters().Length == 0).OrderBy(method => method.Name, StringComparer.Ordinal))
118
+ .ToList();
119
+ var failed = 0;
120
+ foreach (var test in tests)
121
+ {
122
+ try
123
+ {
124
+ if (test.Invoke(null, null) is Task task)
125
+ {
126
+ await task;
127
+ }
128
+
129
+ Console.WriteLine("ok " + test.DeclaringType!.Name + "." + test.Name);
130
+ }
131
+ catch (Exception error)
132
+ {
133
+ failed++;
134
+ Console.WriteLine("FAIL " + test.DeclaringType!.Name + "." + test.Name + ": " + ((error as TargetInvocationException)?.InnerException ?? error));
135
+ }
136
+ }
137
+
138
+ Console.WriteLine(failed == 0 ? "Ran " + tests.Count + " tests\\nOK" : failed + " of " + tests.Count + " tests failed");
139
+ return failed == 0 ? 0 : 1;
140
+ }
141
+ }
142
+ `;
143
+
144
+ function nativeTests(suite , runtimes ) {
145
+ const { root, dir, target, ws, io } = suite;
146
+ const testDir = join(root, dir, CSHARP_TESTS);
147
+ const tests = listFiles(testDir).filter((path) => path.endsWith(".cs"));
148
+ if (tests.length === 0) {
149
+ io.out(`no C# tests in ${toPosix(join(dir, CSHARP_TESTS))}/`);
150
+ return true;
151
+ }
152
+ const sources = new Map([["SdkloomTestRunner.cs", TEST_RUNNER], ...tests.map((path) => [join("tests", path), readFileSync(join(testDir, path), "utf8")])]);
153
+ return runtimes
154
+ .map((runtime) => {
155
+ io.out(`C# tests on ${runtime.label}`);
156
+ const project = consumer(ws.path(`csharp-tests-${runtime.label}`), versionOf(runtime), sdkCopy(ws, target), sources);
157
+ const built = build(runtime, project);
158
+ if (built.status !== 0) {
159
+ printOutput(`${built.stdout}${built.stderr}`, io.out);
160
+ return false;
161
+ }
162
+ const run = spawnCommand(runtime.command, [join(dirname(project), "out", "App.dll")], { env: dotnetEnv(), timeout: RUN_TIMEOUT_MS });
163
+ printOutput(`${run.stdout}${run.stderr}`, io.out);
164
+ return run.status === 0;
165
+ })
166
+ .every(Boolean);
167
+ }
168
+
169
+ /**
170
+ * Compiles the SDK's library deterministically. The bytes depend on the compiler too, so the oldest tested .NET SDK that
171
+ * is installed builds it: the same sources and the same SDK give the same package.
172
+ */
173
+ function compileLibrary(target , workspace ) {
174
+ const versions = profilesOf("csharp").base.test;
175
+ const found = versions.map((version) => resolveToolchain("csharp", version)).find((toolchain) => toolchain !== undefined);
176
+ const dotnet = found?.command ?? "dotnet";
177
+ mkdirSync(workspace, { recursive: true });
178
+ // The compiler sees resolved paths (/private/var/… on macOS), so PathMap must name the real directory.
179
+ const dir = join(realpathSync(workspace), "csharp");
180
+ target.files.forEach((text, path) => {
181
+ mkdirSync(dirname(join(dir, path)), { recursive: true });
182
+ writeFileSync(join(dir, path), text);
183
+ });
184
+ writeFileSync(join(dir, "nuget.config"), NO_NUGET);
185
+ if (found !== undefined) writeFileSync(join(dir, "global.json"), `{"sdk":{"version":"${found.version}.0.100","rollForward":"latestFeature"}}\n`);
186
+ const out = join(realpathSync(workspace), "csharp-out");
187
+ const args = ["build", join(dir, projectFile(target)), "-c", "Release", "-o", out, "-v", "q", "-nologo", "-p:ContinuousIntegrationBuild=true", "-p:Deterministic=true", `-p:PathMap=${dir}=/_/`];
188
+ const built = spawnCommand([dotnet], args, { cwd: dir, env: dotnetEnv(), timeout: RUN_TIMEOUT_MS });
189
+ if (built.status !== 0) throw new Error(`the generated C# SDK does not build:\n${`${built.stdout}${built.stderr}`.trim()}`);
190
+ return new Uint8Array(readFileSync(join(out, `${target.packageName}.dll`)));
191
+ }
192
+
193
+ function dotnetInstallations() {
194
+ return [
195
+ ...(process.env["DOTNET_ROOT"] === undefined ? [] : [join(process.env["DOTNET_ROOT"], "dotnet")]),
196
+ join(homedir(), ".dotnet", "dotnet"),
197
+ "/usr/local/share/dotnet/dotnet",
198
+ "/usr/share/dotnet/dotnet",
199
+ "dotnet",
200
+ ].filter((path) => path === "dotnet" || existsSync(path));
201
+ }
202
+
203
+ export const csharpLanguage = {
204
+ language: "csharp",
205
+ toolchain: {
206
+ variable: "SDKLOOM_DOTNET",
207
+ versionArgs: ["--list-sdks"],
208
+ parseVersion: (output) => /^(\d+\.\d+\.\d+)/m.exec(output)?.[1],
209
+ parseVersions: (output) => [...output.matchAll(/^(\d+\.\d+\.\d+)/gm)].map((match) => match[1] ?? ""),
210
+ candidates: () => dotnetInstallations(),
211
+ executable: (candidate) => candidate,
212
+ fallback: "dotnet",
213
+ image: (version) => `mcr.microsoft.com/dotnet/sdk:${version}.0`,
214
+ tool: "dotnet",
215
+ },
216
+
217
+ build: ({ project, ir, middlewareSources, logicSources }) => {
218
+ const target = project.config.targets.csharp;
219
+ if (target === undefined) return [];
220
+ const kit = loadCSharpKit();
221
+ const middlewarePath = join(project.root, CSHARP_MIDDLEWARE_FILE);
222
+ const namespace = target.namespace ?? defaultNamespace(target.package);
223
+ const output = generateCSharp({
224
+ ir,
225
+ middlewareSources,
226
+ logicSources,
227
+ kit,
228
+ packageId: target.package,
229
+ namespace,
230
+ version: project.config.version,
231
+ sdkloomVersion: SDKLOOM_VERSION,
232
+ source: project.config.source,
233
+ ...(project.config.publish?.license === undefined ? {} : { license: project.config.publish.license }),
234
+ ...(existsSync(middlewarePath) ? { middleware: readFileSync(middlewarePath, "utf8") } : {}),
235
+ });
236
+ const built = {
237
+ language: "csharp",
238
+ name: "csharp",
239
+ profile: profilesOf("csharp").base,
240
+ packageName: target.package,
241
+ outDir: target.outDir ?? "generated/csharp",
242
+ files: output.files,
243
+ lockFile: lockOf("csharp", ir, kit, output),
244
+ module: namespace,
245
+ };
246
+ return [built];
247
+ },
248
+
249
+ observe: (column, scenarios) => {
250
+ const cases = scenarios.map(harnessCase);
251
+ const reported = runHarness(column, { mode: "scenarios", cases }) ;
252
+ return new Map(reported.map(({ id, ...observation }) => [id, observation]));
253
+ },
254
+ roundTrip: (column, samples) => {
255
+ const reported = runHarness(column, { mode: "roundtrip", cases: samples.map(({ id, type, value }) => ({ id, type, value })) }) ;
256
+ return new Map(reported.map((entry) => [entry.id, entry.outcome]));
257
+ },
258
+
259
+ authorTests: (suite) => {
260
+ const native = nativeTests(suite, installed(suite.runtimes));
261
+ if (listFiles(join(suite.root, suite.dir)).some((path) => path.endsWith(".test.ts") && !path.includes("/"))) {
262
+ suite.io.out(`${suite.dir}/*.test.ts → csharp: not transpiled yet; C# runs the scenarios, schema round-trips and ${toPosix(join(suite.dir, CSHARP_TESTS))}/`);
263
+ }
264
+ return native;
265
+ },
266
+ testFile: /(^|\/)csharp\/.*\.cs$/,
267
+
268
+ pack: (project, target, metadata, workspace) => {
269
+ const version = project.config.version;
270
+ const library = compileLibrary(target, workspace);
271
+ const artifact = nugetPackage({ id: target.packageName, version, framework: FRAMEWORK, library, readme: target.files.get("README.md") ?? "" }, metadata);
272
+ return { target, artifact, name: target.packageName, purl: purl("csharp", target.packageName, version), upload: nugetUpload(artifact, target.packageName, version) };
273
+ },
274
+ };
@@ -0,0 +1,185 @@
1
+ // Go: one module with the SDK package, the vendored kit and a mock package; tested with each Go toolchain by a typed
2
+ // harness program generated for the SDK.
3
+
4
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
5
+ import { homedir } from "node:os";
6
+ import { join } from "node:path";
7
+ import { defaultPackage, emitHarness, generateGo, } from "@sdkloom/gen-go";
8
+ import { goModule, purl } from "@sdkloom/packager";
9
+ import { listFiles, toPosix } from "../io.ts";
10
+ import { GO_MIDDLEWARE_FILE, loadKit, lockOf, profilesOf, SDKLOOM_VERSION, } from "../kits.ts";
11
+ import { printOutput } from "../packaging.ts";
12
+ import { installed, spawnCommand, } from "../runtimes.ts";
13
+ import { harnessCase, } from "../scenarios.ts";
14
+
15
+
16
+ /** Native Go tests live in <tests>/go/. */
17
+ const GO_TESTS = "go";
18
+ const RUN_TIMEOUT_MS = 300_000;
19
+
20
+ export function loadGoKit() {
21
+ return loadKit("go", join("src", "sdkruntime"), ".go", profilesOf("go").base);
22
+ }
23
+
24
+ /** Go must not download a newer toolchain, fetch modules or pick up a workspace: the SDK has no dependencies. */
25
+ function goEnv() {
26
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => key !== "NODE_TEST_CONTEXT"));
27
+ return { ...env, GOTOOLCHAIN: "local", GOFLAGS: "-mod=mod", GOPROXY: "off", GOWORK: "off" };
28
+ }
29
+
30
+ function packageOf(target ) {
31
+ return /^package (\w+)$/m.exec(target.files.get("client.go") ?? "")?.[1] ?? defaultPackage(target.module ?? "");
32
+ }
33
+
34
+ /**
35
+ * The version a consumer requires before replacing the module with its directory. Go checks it against the path:
36
+ * a module path ending in /v2 or later needs that major version (https://go.dev/ref/mod#major-version-suffixes).
37
+ */
38
+ export function placeholderVersion(module ) {
39
+ const major = /\/v(\d+)$/.exec(module)?.[1];
40
+ return major !== undefined && Number(major) >= 2 ? `v${major}.0.0` : "v0.0.0";
41
+ }
42
+
43
+ /** A module that uses the generated SDK from its output directory. */
44
+ function consumer(dir , name , root , target ) {
45
+ mkdirSync(dir, { recursive: true });
46
+ writeFileSync(join(dir, "go.mod"), `module ${name}\n\ngo 1.18\n\nrequire ${target.module ?? ""} ${placeholderVersion(target.module ?? "")}\n\nreplace ${target.module ?? ""} => ${JSON.stringify(toPosix(join(root, target.outDir)))}\n`);
47
+ }
48
+
49
+ /** The harness binary for one runtime, built once per run; Go checks the SDK compiles on that version on the way. */
50
+ function harness(column ) {
51
+ const { root, target, runtime, ir, ws } = column;
52
+ return ws.once(`go:${runtime.label}`, () => {
53
+ const dir = ws.path(`go-harness-${runtime.label}`);
54
+ consumer(dir, "sdkloomharness", root, target);
55
+ writeFileSync(join(dir, "main.go"), emitHarness(ir, target.module ?? "", packageOf(target)));
56
+ const binary = join(dir, "harness");
57
+ const built = spawnCommand(runtime.command, ["build", "-o", binary, "."], { cwd: dir, env: goEnv(), timeout: RUN_TIMEOUT_MS });
58
+ if (built.status !== 0) throw new Error(`the generated Go SDK does not build with ${runtime.label}:\n${`${built.stdout}${built.stderr}`.trim()}`);
59
+ // Built in a container, the binary is for the container's platform: run it there, in place of the go tool.
60
+ return runtime.image === undefined ? [binary] : [...runtime.command.slice(0, -1), binary];
61
+ });
62
+ }
63
+
64
+ function runHarness(column , plan ) {
65
+ const result = spawnCommand(harness(column), [], { input: JSON.stringify(plan), timeout: RUN_TIMEOUT_MS });
66
+ if (result.status !== 0) throw new Error(`the Go harness failed: ${`${result.stderr}`.trim().split("\n").at(-1) ?? ""}`);
67
+ return JSON.parse(result.stdout) ;
68
+ }
69
+
70
+ function nativeTests(suite , runtimes ) {
71
+ const { root, dir, target, ws, io } = suite;
72
+ const testDir = join(root, dir, GO_TESTS);
73
+ const tests = listFiles(testDir).filter((path) => path.endsWith("_test.go"));
74
+ if (tests.length === 0) {
75
+ io.out(`no Go tests in ${toPosix(join(dir, GO_TESTS))}/`);
76
+ return true;
77
+ }
78
+ const module = ws.path("go-tests");
79
+ consumer(module, "sdkloomtests", root, target);
80
+ listFiles(testDir).forEach((path) => {
81
+ mkdirSync(join(module, path, ".."), { recursive: true });
82
+ writeFileSync(join(module, path), readFileSync(join(testDir, path)));
83
+ });
84
+ return runtimes
85
+ .map((runtime) => {
86
+ io.out(`Go tests on ${runtime.label}`);
87
+ const run = spawnCommand(runtime.command, ["test", "./..."], { cwd: module, env: goEnv(), timeout: RUN_TIMEOUT_MS });
88
+ printOutput(`${run.stdout}${run.stderr}`, io.out);
89
+ return run.status === 0;
90
+ })
91
+ .every(Boolean);
92
+ }
93
+
94
+ function children(dir ) {
95
+ return existsSync(dir) ? readdirSync(dir).map((name) => join(dir, name)) : [];
96
+ }
97
+
98
+ export const goLanguage = {
99
+ language: "go",
100
+ toolchain: {
101
+ variable: "SDKLOOM_GO",
102
+ versionArgs: ["version"],
103
+ parseVersion: (output) => /go version go(\d+\.\d+(?:\.\d+)?)/.exec(output)?.[1],
104
+ candidates: (version) => [
105
+ // golang.org/dl downloads land in ~/sdk/go<version>.
106
+ ...children(join(homedir(), "sdk"))
107
+ .filter((path) => path.split("/").at(-1)?.startsWith(`go${version}`) === true)
108
+ .map((path) => join(path, "bin", "go")),
109
+ "go",
110
+ "/usr/local/go/bin/go",
111
+ ],
112
+ executable: (candidate) => candidate,
113
+ fallback: "go",
114
+ image: (version) => `golang:${version}`,
115
+ tool: "go",
116
+ },
117
+
118
+ build: ({ project, ir, middlewareSources, logicSources }) => {
119
+ const target = project.config.targets.go;
120
+ if (target === undefined) return [];
121
+ const kit = loadGoKit();
122
+ const middlewarePath = join(project.root, GO_MIDDLEWARE_FILE);
123
+ const output = generateGo({
124
+ ir,
125
+ middlewareSources,
126
+ logicSources,
127
+ kit,
128
+ module: target.module,
129
+ packageName: target.package ?? defaultPackage(target.module),
130
+ version: project.config.version,
131
+ sdkloomVersion: SDKLOOM_VERSION,
132
+ source: project.config.source,
133
+ ...(existsSync(middlewarePath) ? { middleware: readFileSync(middlewarePath, "utf8") } : {}),
134
+ });
135
+ const built = {
136
+ language: "go",
137
+ name: "go",
138
+ profile: profilesOf("go").base,
139
+ packageName: target.module,
140
+ outDir: target.outDir ?? "generated/go",
141
+ files: output.files,
142
+ lockFile: lockOf("go", ir, kit, output),
143
+ module: target.module,
144
+ };
145
+ return [built];
146
+ },
147
+
148
+ observe: (column, scenarios) => {
149
+ const cases = scenarios.map(harnessCase);
150
+ const reported = runHarness(column, { mode: "scenarios", cases }) ;
151
+ return new Map(reported.map(({ id, ...observation }) => [id, observation]));
152
+ },
153
+ roundTrip: (column, samples) => {
154
+ const reported = runHarness(column, { mode: "roundtrip", cases: samples.map(({ id, type, value }) => ({ id, type, value })) }) ;
155
+ return new Map(reported.map((entry) => [entry.id, entry.outcome]));
156
+ },
157
+
158
+ authorTests: (suite) => {
159
+ const native = nativeTests(suite, installed(suite.runtimes));
160
+ if (listFiles(join(suite.root, suite.dir)).some((path) => path.endsWith(".test.ts") && !path.includes("/"))) {
161
+ suite.io.out(`${suite.dir}/*.test.ts → go: not transpiled yet; Go runs the scenarios, schema round-trips and ${toPosix(join(suite.dir, GO_TESTS))}/`);
162
+ }
163
+ return native;
164
+ },
165
+ testFile: /_test\.go$/,
166
+
167
+ pack: (project, target) => {
168
+ const version = project.config.version;
169
+ const module = target.module ?? "";
170
+ const artifact = goModule(new Map(target.files), module, version);
171
+ return {
172
+ target,
173
+ artifact,
174
+ name: module,
175
+ purl: purl("go", module, version),
176
+ upload: {
177
+ language: "go",
178
+ registry: "https://proxy.golang.org",
179
+ tokenVariable: "",
180
+ send: () => Promise.reject(new Error("Go modules are published with a git tag")),
181
+ manual: `Go modules are not uploaded: commit ${target.outDir} to the repository of ${module} and push the tag v${version}; the module proxy then serves ${artifact.fileName}`,
182
+ },
183
+ };
184
+ },
185
+ };
@@ -0,0 +1,18 @@
1
+ // Every language sdkloom generates, in the order targets are built and shown.
2
+
3
+
4
+ import { csharpLanguage } from "./csharp.ts";
5
+ import { goLanguage } from "./go.ts";
6
+ import { java } from "./java.ts";
7
+ import { python } from "./python.ts";
8
+ import { rustLanguage } from "./rust.ts";
9
+
10
+ import { typescript } from "./typescript.ts";
11
+
12
+ export const LANGUAGE_MODULES = [typescript, python, java, goLanguage, rustLanguage, csharpLanguage];
13
+
14
+ export function languageModule(language ) {
15
+ const found = LANGUAGE_MODULES.find((candidate) => candidate.language === language);
16
+ if (found === undefined) throw new Error(`internal: no module for ${language}`);
17
+ return found;
18
+ }
@@ -0,0 +1,187 @@
1
+ // Java: the default artifact for 11+ and the jdk8 variant, compiled for the release of their kit line and run on each JDK.
2
+
3
+ import { existsSync, mkdirSync, readdirSync, readFileSync } from "node:fs";
4
+ import { homedir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { generateJava, } from "@sdkloom/gen-java";
7
+ import { mavenBundle, mavenFiles, purl } from "@sdkloom/packager";
8
+ import { listFiles, toPosix } from "../io.ts";
9
+ import { className, compileJava, JAVA, JAVA_RELEASE, javadoc, javaIn, javaSources, runJava } from "../java.ts";
10
+ import { JAVA_MIDDLEWARE_FILE, JAVA_RUNTIME, loadKit, lockOf, profilesOf, SDKLOOM_VERSION, variantProfile, withVariants, } from "../kits.ts";
11
+ import { printOutput, readTree, sign } from "../packaging.ts";
12
+
13
+ import { centralUpload } from "../registries.ts";
14
+ import { installed, } from "../runtimes.ts";
15
+ import { observeJava, roundTripJava } from "../scenarios-java.ts";
16
+ import { runTranspiledJava } from "../transpiled-tests.ts";
17
+
18
+
19
+ /** Native Java tests live in <tests>/java/. */
20
+ const JAVA_TESTS = "java";
21
+
22
+ export function loadJavaKit(profile = profilesOf("java").base) {
23
+ return { ...loadKit("java", JAVA_RUNTIME, ".java", profile), release: profile.strategies["release"] ?? "11", transport: profile.strategies["transport"] ?? "JdkTransport" };
24
+ }
25
+
26
+ function releaseOf(target ) {
27
+ return target.profile.strategies["release"] ?? JAVA_RELEASE;
28
+ }
29
+
30
+ function children(dir ) {
31
+ return existsSync(dir) ? readdirSync(dir).map((name) => join(dir, name)) : [];
32
+ }
33
+
34
+ /** The SDK's classes, compiled once per run for the target's release; undefined (with the output printed) when it does not compile. */
35
+ function classes(root , target , ws , out ) {
36
+ return ws.once(`java:${target.name}`, () => {
37
+ const dir = ws.path(`${target.name}-classes`);
38
+ const result = compileJava(javaSources(join(root, target.outDir, "src", "main", "java")), dir, [], releaseOf(target));
39
+ if (!result.ok) out(`the generated Java SDK (${target.name}) does not compile:\n${result.output.trimEnd()}`);
40
+ return result.ok ? dir : undefined;
41
+ });
42
+ }
43
+
44
+ function compiled(column ) {
45
+ return classes(column.root, column.target, column.ws, column.io.out);
46
+ }
47
+
48
+ function nativeTests(suite , sdk , runtimes ) {
49
+ const { root, dir, target, ws, io } = suite;
50
+ const testDir = join(root, dir, JAVA_TESTS);
51
+ const tests = listFiles(testDir).filter((path) => path.endsWith("Test.java"));
52
+ if (tests.length === 0) {
53
+ io.out(`no Java tests in ${toPosix(join(dir, JAVA_TESTS))}/`);
54
+ return true;
55
+ }
56
+ const built = compileJava(javaSources(testDir), ws.path("tests"), [sdk]);
57
+ if (!built.ok) {
58
+ printOutput(built.output, io.out);
59
+ return false;
60
+ }
61
+ return runtimes
62
+ .map((runtime) => {
63
+ io.out(`Java tests on ${runtime.label}`);
64
+ const run = runJava([sdk, ws.path("tests")], `${target.module ?? ""}.runtime.TestRunner`, tests.map(className), undefined, runtime.command);
65
+ printOutput(run.output, io.out);
66
+ return run.ok;
67
+ })
68
+ .every(Boolean);
69
+ }
70
+
71
+ export const java = {
72
+ language: "java",
73
+ toolchain: {
74
+ variable: "SDKLOOM_JAVA_HOME",
75
+ versionArgs: ["-version"],
76
+ parseVersion: (output) => {
77
+ const quoted = /version "([^"]+)"/.exec(output)?.[1];
78
+ if (quoted === undefined) return undefined;
79
+ const legacy = /^1\.(\d+)\.(\d+)(?:_(\d+))?/.exec(quoted);
80
+ return legacy === null ? quoted.split(/[-+]/)[0] : `${legacy[1]}.${legacy[2]}.${legacy[3] ?? "0"}`;
81
+ },
82
+ candidates: () => [
83
+ ...children(join(homedir(), ".sdkman", "candidates", "java")).filter((path) => !path.endsWith("current")),
84
+ ...children("/Library/Java/JavaVirtualMachines").map((path) => join(path, "Contents", "Home")),
85
+ ...children("/usr/lib/jvm"),
86
+ ...(process.env["JAVA_HOME"] === undefined ? [] : [process.env["JAVA_HOME"] ?? ""]),
87
+ ],
88
+ executable: javaIn,
89
+ fallback: JAVA,
90
+ image: (version) => `eclipse-temurin:${version}-jdk`,
91
+ tool: "java",
92
+ },
93
+
94
+ build: ({ project, ir, middlewareSources, logicSources }) => {
95
+ const target = project.config.targets.java;
96
+ if (target === undefined) return [];
97
+ const middlewarePath = join(project.root, JAVA_MIDDLEWARE_FILE);
98
+ const middleware = existsSync(middlewarePath) ? readFileSync(middlewarePath, "utf8") : undefined;
99
+ const segments = target.package.split(".");
100
+ const groupId = target.groupId ?? (segments.slice(0, -1).join(".") || target.package);
101
+ const baseArtifact = target.artifactId ?? segments.at(-1) ?? target.package;
102
+ return withVariants(target.variants, (variant) => {
103
+ const profile = variant === undefined ? profilesOf("java").base : variantProfile("java", variant);
104
+ const kit = loadJavaKit(profile);
105
+ const settings = variant === undefined ? undefined : target.variants?.[variant];
106
+ const artifactId = variant === undefined ? baseArtifact : (settings?.artifactId ?? `${baseArtifact}-${variant}`);
107
+ const output = generateJava({
108
+ ir,
109
+ middlewareSources,
110
+ logicSources,
111
+ kit,
112
+ javaPackage: target.package,
113
+ groupId,
114
+ artifactId,
115
+ version: project.config.version,
116
+ sdkloomVersion: SDKLOOM_VERSION,
117
+ source: project.config.source,
118
+ ...(middleware === undefined ? {} : { middleware }),
119
+ });
120
+ const outDir = target.outDir ?? "generated/java";
121
+ return {
122
+ language: "java",
123
+ name: variant === undefined ? "java" : `java-${variant}`,
124
+ profile,
125
+ packageName: `${groupId}:${artifactId}`,
126
+ outDir: variant === undefined ? outDir : (settings?.outDir ?? `${outDir}-${variant}`),
127
+ files: output.files,
128
+ lockFile: lockOf("java", ir, kit, output),
129
+ module: target.package,
130
+ };
131
+ });
132
+ },
133
+
134
+ observe: (column, scenarios) => {
135
+ const sdk = compiled(column);
136
+ const release = releaseOf(column.target);
137
+ return sdk === undefined ? new Map() : observeJava(column.runtime.command, sdk, column.ws.path(`harness-${release}`), column.target.module ?? "", column.ir, scenarios, release);
138
+ },
139
+ roundTrip: (column, samples) => {
140
+ const sdk = compiled(column);
141
+ const release = releaseOf(column.target);
142
+ return sdk === undefined ? new Map() : roundTripJava(column.runtime.command, sdk, column.ws.path(`schema-${release}`), column.target.module ?? "", samples, release);
143
+ },
144
+
145
+ /** A variant differs only in its transport, which scenarios cover; Java test code needs Java 11, so it runs on the default artifact. */
146
+ authorTests: (suite) => {
147
+ const { target, io } = suite;
148
+ if (target.name !== "java") {
149
+ io.out(`${target.name}: author tests run on the default package; scenarios and round-trips ran on ${target.name}`);
150
+ return true;
151
+ }
152
+ const sdk = classes(suite.root, target, suite.ws, io.out);
153
+ if (sdk === undefined) return false;
154
+ const native = nativeTests(suite, sdk, installed(suite.runtimes));
155
+ return runTranspiledJava(suite.root, suite.dir, suite.ir, target, { sdk, compile: () => true }, suite.ws.path("java"), suite.runtimes, io) && native;
156
+ },
157
+ testFile: /Test\.java$/,
158
+
159
+ pack: (project, target, metadata, workspace) => {
160
+ const version = project.config.version;
161
+ const javaPackage = target.module ?? "";
162
+ const [groupId = "", artifactId = ""] = target.packageName.split(":");
163
+ const release = releaseOf(target);
164
+ const sourceRoot = join(project.root, target.outDir, "src", "main", "java");
165
+ const classDir = join(workspace, "classes");
166
+ const built = compileJava(javaSources(sourceRoot), classDir, [], release);
167
+ if (!built.ok) throw new Error(`the generated Java SDK does not compile:\n${built.output}`);
168
+ const docs = join(workspace, "javadoc");
169
+ const documented = javadoc(javaSources(sourceRoot), docs, release);
170
+ if (!documented.ok) throw new Error(`javadoc failed:\n${documented.output}`);
171
+ const input = {
172
+ groupId,
173
+ artifactId,
174
+ version,
175
+ javaPackage,
176
+ pom: target.files.get("pom.xml") ?? "",
177
+ classes: readTree(classDir, (path) => path.endsWith(".class")),
178
+ sources: new Map([...readTree(sourceRoot, (path) => path.endsWith(".java"))].map(([path, bytes]) => [path, new TextDecoder().decode(bytes)])),
179
+ javadoc: readTree(docs, (path) => /\.(html|css|js|png|svg)$/.test(path)),
180
+ };
181
+ const signingDir = join(workspace, "signing");
182
+ mkdirSync(signingDir, { recursive: true });
183
+ const signatures = sign(mavenFiles(input, metadata), signingDir);
184
+ const artifact = mavenBundle({ ...input, ...(signatures === undefined ? {} : { signatures }) }, metadata);
185
+ return { target, artifact, upload: centralUpload(artifact, `${groupId}:${artifactId}:${version}`), name: `${groupId}:${artifactId}`, purl: purl("java", artifactId, version, groupId) };
186
+ },
187
+ };