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,297 @@
1
+ // Runs sdkloom scenarios against a generated Java SDK. JDK only; the SDK is reached through reflection.
2
+ //
3
+ // Reads a plan as JSON on stdin and prints one observation per scenario as JSON on stdout:
4
+ // what the local server received and what the client call returned or threw.
5
+
6
+ import com.sun.net.httpserver.HttpServer;
7
+ import java.io.ByteArrayInputStream;
8
+ import java.io.IOException;
9
+ import java.io.InputStream;
10
+ import java.io.OutputStream;
11
+ import java.lang.reflect.InvocationTargetException;
12
+ import java.lang.reflect.Method;
13
+ import java.math.BigDecimal;
14
+ import java.net.InetSocketAddress;
15
+ import java.nio.charset.StandardCharsets;
16
+ import java.util.ArrayList;
17
+ import java.util.LinkedHashMap;
18
+ import java.util.List;
19
+ import java.util.Map;
20
+
21
+ public final class ScenarioHarness {
22
+
23
+ /** InputStream.readAllBytes needs Java 9; the harness also runs Java 8 variants. */
24
+ private static byte[] readAll(java.io.InputStream stream) throws java.io.IOException {
25
+ java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
26
+ byte[] chunk = new byte[8192];
27
+ for (int read = stream.read(chunk); read != -1; read = stream.read(chunk)) {
28
+ out.write(chunk, 0, read);
29
+ }
30
+ return out.toByteArray();
31
+ }
32
+ private ScenarioHarness() {
33
+ }
34
+
35
+ public static void main(String[] args) throws Exception {
36
+ Class<?> json = Class.forName(args[0]);
37
+ Map<String, Object> plan = asMap(call(json, "parse", new String(readAll(System.in), StandardCharsets.UTF_8)));
38
+ List<Object> observations = new ArrayList<>();
39
+ for (Object scenario : (List<?>) plan.get("scenarios")) {
40
+ observations.add(observe(json, plan, asMap(scenario)));
41
+ }
42
+ System.out.print(call(json, "write", observations));
43
+ }
44
+
45
+ @SuppressWarnings("unchecked")
46
+ private static Map<String, Object> asMap(Object value) {
47
+ return (Map<String, Object>) value;
48
+ }
49
+
50
+ private static Object call(Class<?> type, String name, Object argument) throws Exception {
51
+ for (Method method : type.getMethods()) {
52
+ if (method.getName().equals(name) && method.getParameterCount() == 1) {
53
+ return method.invoke(null, argument);
54
+ }
55
+ }
56
+ throw new NoSuchMethodException(type.getName() + "." + name);
57
+ }
58
+
59
+ /** A webhook case: verify and read the body with the SDK's <Name>Webhooks.verify<Hook>. */
60
+ private static Object webhook(Map<String, Object> scenario) {
61
+ Map<String, Object> hook = asMap(scenario.get("webhook"));
62
+ Map<String, Object> outcome = new LinkedHashMap<>();
63
+ try {
64
+ Map<String, String> headers = new LinkedHashMap<>();
65
+ asMap(hook.get("headers")).forEach((name, value) -> headers.put(name, String.valueOf(value)));
66
+ Method verify = Class.forName((String) hook.get("class")).getMethod((String) hook.get("verify"), byte[].class, Map.class, String.class, long.class);
67
+ Object value = verify.invoke(null, String.valueOf(hook.get("body")).getBytes(StandardCharsets.UTF_8), headers, hook.get("secret"), ((BigDecimal) hook.get("now")).longValueExact());
68
+ outcome.put("ok", true);
69
+ outcome.put("value", value);
70
+ } catch (Exception error) {
71
+ Throwable cause = error instanceof InvocationTargetException ? error.getCause() : error;
72
+ outcome.put("ok", false);
73
+ outcome.put("error", errorName(cause));
74
+ outcome.put("message", String.valueOf(cause.getMessage()));
75
+ }
76
+ Map<String, Object> observation = new LinkedHashMap<>();
77
+ observation.put("id", scenario.get("id"));
78
+ observation.put("outcome", outcome);
79
+ return observation;
80
+ }
81
+
82
+ /** A logic case: call <Name>Logic.<name>; any failure is reported as Error, as in every language. */
83
+ private static Object logic(Map<String, Object> scenario) {
84
+ Map<String, Object> logic = asMap(scenario.get("logic"));
85
+ Map<String, Object> outcome = new LinkedHashMap<>();
86
+ try {
87
+ Method method = null;
88
+ for (Method candidate : Class.forName((String) logic.get("class")).getMethods()) {
89
+ if (candidate.getName().equals(logic.get("method"))) method = candidate;
90
+ }
91
+ if (method == null) throw new NoSuchMethodException(String.valueOf(logic.get("method")));
92
+ List<?> given = (List<?>) logic.get("args");
93
+ Class<?>[] types = method.getParameterTypes();
94
+ Object[] args = new Object[types.length];
95
+ for (int index = 0; index < types.length; index++) {
96
+ Object value = given.get(index);
97
+ if (types[index] == long.class) value = ((BigDecimal) value).longValueExact();
98
+ else if (types[index] == double.class) value = ((BigDecimal) value).doubleValue();
99
+ args[index] = value;
100
+ }
101
+ outcome.put("ok", true);
102
+ outcome.put("value", method.invoke(null, args));
103
+ } catch (Exception error) {
104
+ Throwable cause = error instanceof InvocationTargetException ? error.getCause() : error;
105
+ outcome.put("ok", false);
106
+ outcome.put("error", "Error");
107
+ outcome.put("message", String.valueOf(cause.getMessage()));
108
+ }
109
+ Map<String, Object> observation = new LinkedHashMap<>();
110
+ observation.put("id", scenario.get("id"));
111
+ observation.put("outcome", outcome);
112
+ return observation;
113
+ }
114
+
115
+ private static Object observe(Class<?> json, Map<String, Object> plan, Map<String, Object> scenario) throws Exception {
116
+ if (scenario.containsKey("webhook")) {
117
+ return webhook(scenario);
118
+ }
119
+ if (scenario.containsKey("logic")) {
120
+ return logic(scenario);
121
+ }
122
+ // Answers in order, the last one repeats; every request is recorded.
123
+ List<Object> requests = java.util.Collections.synchronizedList(new ArrayList<>());
124
+ List<?> answers = (List<?>) scenario.get("answers");
125
+ HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
126
+ server.createContext("/", (exchange) -> {
127
+ byte[] body = readAll(exchange.getRequestBody());
128
+ Map<String, Object> headers = new LinkedHashMap<>();
129
+ exchange.getRequestHeaders().forEach((name, values) -> headers.put(name.toLowerCase(java.util.Locale.ROOT), String.join(", ", values)));
130
+ Map<String, Object> respond = asMap(answers.get(Math.min(requests.size(), answers.size() - 1)));
131
+ Map<String, Object> received = new LinkedHashMap<>();
132
+ requests.add(received);
133
+ received.put("method", exchange.getRequestMethod());
134
+ received.put("url", exchange.getRequestURI().getRawPath() + (exchange.getRequestURI().getRawQuery() == null ? "" : "?" + exchange.getRequestURI().getRawQuery()));
135
+ received.put("headers", headers);
136
+ received.put("body", new String(body, StandardCharsets.UTF_8));
137
+ byte[] payload = new byte[0];
138
+ if (respond.get("text") != null) {
139
+ payload = ((String) respond.get("text")).getBytes(StandardCharsets.UTF_8);
140
+ } else if (respond.get("json") != null) {
141
+ exchange.getResponseHeaders().add("content-type", "application/json");
142
+ try {
143
+ payload = ((String) call(json, "write", respond.get("json"))).getBytes(StandardCharsets.UTF_8);
144
+ } catch (Exception error) {
145
+ throw new IOException(error);
146
+ }
147
+ }
148
+ Object extra = respond.get("headers");
149
+ if (extra != null) {
150
+ asMap(extra).forEach((name, value) -> exchange.getResponseHeaders().add(name, String.valueOf(value)));
151
+ }
152
+ exchange.sendResponseHeaders(((BigDecimal) respond.get("status")).intValue(), payload.length == 0 ? -1 : payload.length);
153
+ try (OutputStream out = exchange.getResponseBody()) {
154
+ out.write(payload);
155
+ }
156
+ });
157
+ server.start();
158
+ Map<String, Object> outcome = new LinkedHashMap<>();
159
+ try {
160
+ Object client = client(plan, scenario, "http://127.0.0.1:" + server.getAddress().getPort());
161
+ Object value = invoke(client, scenario);
162
+ if (Boolean.TRUE.equals(scenario.get("events"))) {
163
+ // Server-sent events: every event the stream delivers, read through ServerSentEvent's accessors.
164
+ List<Object> events = new ArrayList<>();
165
+ for (Object event : (Iterable<?>) value) {
166
+ Map<String, Object> entry = new LinkedHashMap<>();
167
+ for (String field : new String[] {"event", "id", "data"}) {
168
+ entry.put(field, event.getClass().getMethod(field).invoke(event));
169
+ }
170
+ events.add(entry);
171
+ }
172
+ value = events;
173
+ } else if (Boolean.TRUE.equals(scenario.get("all"))) {
174
+ // The operation's iterator over every page, e.g. listPaymentsAll.
175
+ List<Object> items = new ArrayList<>();
176
+ for (Object item : (Iterable<?>) value) {
177
+ items.add(item);
178
+ }
179
+ value = items;
180
+ }
181
+ outcome.put("ok", true);
182
+ outcome.put("value", value instanceof byte[] ? new String((byte[]) value, StandardCharsets.UTF_8) : value);
183
+ } catch (Exception error) {
184
+ // One scenario's failure, including a setup problem, must not stop the others.
185
+ Throwable cause = error instanceof InvocationTargetException ? error.getCause() : error;
186
+ outcome.put("ok", false);
187
+ outcome.put("error", errorName(cause));
188
+ outcome.put("message", String.valueOf(cause.getMessage()));
189
+ } finally {
190
+ server.stop(0);
191
+ }
192
+ Map<String, Object> observation = new LinkedHashMap<>();
193
+ observation.put("id", scenario.get("id"));
194
+ observation.put("outcome", outcome);
195
+ if (!requests.isEmpty()) {
196
+ observation.put("received", requests.get(0));
197
+ observation.put("requests", new ArrayList<>(requests));
198
+ }
199
+ return observation;
200
+ }
201
+
202
+ private static String errorName(Throwable error) {
203
+ try {
204
+ return String.valueOf(error.getClass().getMethod("name").invoke(error));
205
+ } catch (ReflectiveOperationException missing) {
206
+ return error.getClass().getSimpleName().replaceAll("Exception$", "Error");
207
+ }
208
+ }
209
+
210
+ private static Object client(Map<String, Object> plan, Map<String, Object> scenario, String baseUrl) throws Exception {
211
+ Object builder = Class.forName((String) plan.get("client")).getMethod("builder").invoke(null);
212
+ for (Map.Entry<String, Object> entry : asMap(scenario.get("config")).entrySet()) {
213
+ set(builder, entry.getKey(), entry.getValue());
214
+ }
215
+ set(builder, "baseUrl", baseUrl);
216
+ set(builder, "timeoutMs", scenario.get("timeoutMs"));
217
+ return builder.getClass().getMethod("build").invoke(builder);
218
+ }
219
+
220
+ private static void set(Object builder, String name, Object value) throws Exception {
221
+ for (Method method : builder.getClass().getMethods()) {
222
+ if (method.getName().equals(name) && method.getParameterCount() == 1) {
223
+ method.invoke(builder, convert(value, method.getParameterTypes()[0]));
224
+ return;
225
+ }
226
+ }
227
+ throw new IllegalArgumentException("no builder option " + name);
228
+ }
229
+
230
+ private static Object invoke(Object client, Map<String, Object> scenario) throws Exception {
231
+ List<Object> values = new ArrayList<>((List<?>) scenario.get("positional"));
232
+ if (scenario.containsKey("body")) {
233
+ values.add(scenario.get("body"));
234
+ }
235
+ Object params = scenario.get("params");
236
+ if (params != null) {
237
+ Map<String, Object> spec = asMap(params);
238
+ Object builder = Class.forName((String) spec.get("class")).getMethod("builder").invoke(null);
239
+ for (Map.Entry<String, Object> entry : asMap(spec.get("values")).entrySet()) {
240
+ set(builder, entry.getKey(), entry.getValue());
241
+ }
242
+ values.add(builder.getClass().getMethod("build").invoke(builder));
243
+ }
244
+ for (Method method : client.getClass().getMethods()) {
245
+ if (method.getName().equals(scenario.get("method")) && method.getParameterCount() == values.size()) {
246
+ Object[] arguments = new Object[values.size()];
247
+ for (int i = 0; i < arguments.length; i++) {
248
+ arguments[i] = convert(values.get(i), method.getParameterTypes()[i]);
249
+ }
250
+ return method.invoke(client, arguments);
251
+ }
252
+ }
253
+ throw new IllegalArgumentException("no method " + scenario.get("method") + " taking " + values.size() + " arguments");
254
+ }
255
+
256
+ private static Object convert(Object value, Class<?> type) throws Exception {
257
+ if (value == null || type.isInstance(value)) {
258
+ return value;
259
+ }
260
+ if (type == Long.class || type == long.class) {
261
+ return ((BigDecimal) value).longValueExact();
262
+ }
263
+ if (type == Double.class || type == double.class) {
264
+ return ((BigDecimal) value).doubleValue();
265
+ }
266
+ if (type == BigDecimal.class) {
267
+ return new BigDecimal(String.valueOf(value));
268
+ }
269
+ if (type == String.class) {
270
+ return value instanceof BigDecimal ? ((BigDecimal) value).toPlainString() : String.valueOf(value);
271
+ }
272
+ if (type == InputStream.class) {
273
+ return new ByteArrayInputStream(String.valueOf(value).getBytes(StandardCharsets.UTF_8));
274
+ }
275
+ if (type == byte[].class) {
276
+ return String.valueOf(value).getBytes(StandardCharsets.UTF_8);
277
+ }
278
+ if (type.getSimpleName().equals("MultipartForm")) {
279
+ // A multipart body is described as parts; files are sent as UTF-8 bytes.
280
+ Object form = type.getConstructor().newInstance();
281
+ for (Object item : (List<?>) asMap(value).get("parts")) {
282
+ Map<String, Object> part = asMap(item);
283
+ String name = String.valueOf(part.get("name"));
284
+ String text = String.valueOf(part.get("value"));
285
+ if (part.get("filename") == null) {
286
+ form = type.getMethod("field", String.class, String.class).invoke(form, name, text);
287
+ } else {
288
+ Object contentType = part.get("contentType");
289
+ form = type.getMethod("file", String.class, String.class, String.class, byte[].class).invoke(form, name, String.valueOf(part.get("filename")), contentType == null ? "application/octet-stream" : String.valueOf(contentType), text.getBytes(StandardCharsets.UTF_8));
290
+ }
291
+ }
292
+ return form;
293
+ }
294
+ Method fromJson = type.getMethod("fromJson", Object.class);
295
+ return fromJson.invoke(null, value);
296
+ }
297
+ }
@@ -0,0 +1,63 @@
1
+ // Decodes and re-encodes schema samples with a generated Java SDK. JDK only; the SDK is reached through reflection.
2
+ //
3
+ // Reads {"package", "cases": [{"id", "type", "union", "value"}]} as JSON on stdin and prints
4
+ // [{"id", "outcome": {"ok", "value"} | {"ok", "error", "message"}}] as JSON on stdout.
5
+
6
+ import java.lang.reflect.InvocationTargetException;
7
+ import java.lang.reflect.Method;
8
+ import java.nio.charset.StandardCharsets;
9
+ import java.util.ArrayList;
10
+ import java.util.LinkedHashMap;
11
+ import java.util.List;
12
+ import java.util.Map;
13
+
14
+ public final class SchemaRoundTrip {
15
+
16
+ /** InputStream.readAllBytes needs Java 9; the harness also runs Java 8 variants. */
17
+ private static byte[] readAll(java.io.InputStream stream) throws java.io.IOException {
18
+ java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
19
+ byte[] chunk = new byte[8192];
20
+ for (int read = stream.read(chunk); read != -1; read = stream.read(chunk)) {
21
+ out.write(chunk, 0, read);
22
+ }
23
+ return out.toByteArray();
24
+ }
25
+ private SchemaRoundTrip() {
26
+ }
27
+
28
+ @SuppressWarnings("unchecked")
29
+ public static void main(String[] args) throws Exception {
30
+ Class<?> json = Class.forName(args[0]);
31
+ Map<String, Object> plan = (Map<String, Object>) json.getMethod("parse", String.class)
32
+ .invoke(null, new String(readAll(System.in), StandardCharsets.UTF_8));
33
+ List<Object> results = new ArrayList<>();
34
+ for (Object item : (List<?>) plan.get("cases")) {
35
+ Map<String, Object> scenario = (Map<String, Object>) item;
36
+ Map<String, Object> outcome = new LinkedHashMap<>();
37
+ try {
38
+ outcome.put("value", roundTrip((String) plan.get("package"), scenario));
39
+ outcome.put("ok", true);
40
+ } catch (Exception error) {
41
+ Throwable cause = error instanceof InvocationTargetException ? error.getCause() : error;
42
+ outcome.put("ok", false);
43
+ outcome.put("error", cause.getClass().getSimpleName());
44
+ outcome.put("message", String.valueOf(cause.getMessage()));
45
+ }
46
+ Map<String, Object> result = new LinkedHashMap<>();
47
+ result.put("id", scenario.get("id"));
48
+ result.put("outcome", outcome);
49
+ results.add(result);
50
+ }
51
+ System.out.print(json.getMethod("write", Object.class).invoke(null, results));
52
+ }
53
+
54
+ private static Object roundTrip(String pkg, Map<String, Object> scenario) throws Exception {
55
+ Class<?> type = Class.forName(pkg + "." + scenario.get("type"));
56
+ Object decoded = type.getMethod("fromJson", Object.class).invoke(null, scenario.get("value"));
57
+ if (Boolean.TRUE.equals(scenario.get("union"))) {
58
+ return type.getMethod("encode", type).invoke(null, decoded);
59
+ }
60
+ Method toJson = type.getMethod("toJson");
61
+ return toJson.invoke(decoded);
62
+ }
63
+ }
@@ -0,0 +1,70 @@
1
+ // Compiling and running Java with the JDK on the PATH: generated SDKs, scenario harness and author tests.
2
+
3
+ import { spawnSync } from "node:child_process";
4
+ import { mkdirSync } from "node:fs";
5
+ import { join, sep } from "node:path";
6
+ import { listFiles } from "./io.ts";
7
+
8
+ export const JAVAC = process.env["SDKLOOM_JAVAC"] ?? "javac";
9
+ export const JAVA = process.env["SDKLOOM_JAVA"] ?? "java";
10
+ /** The default package supports Java 11+, so it is compiled for 11 whatever JDK runs the build; variants pass their own release. */
11
+ export const JAVA_RELEASE = "11";
12
+ const PATH_SEPARATOR = sep === "\\" ? ";" : ":";
13
+ const RUN_TIMEOUT_MS = 300_000;
14
+
15
+
16
+
17
+
18
+
19
+
20
+ /** Every .java file under the given directories, as absolute paths. */
21
+ export function javaSources(...dirs ) {
22
+ return dirs.flatMap((dir) => listFiles(dir).filter((path) => path.endsWith(".java")).map((path) => join(dir, path)));
23
+ }
24
+
25
+ /** "dev/sdkloom/runtime/HttpTest.java" → "dev.sdkloom.runtime.HttpTest" */
26
+ export function className(relativePath ) {
27
+ return relativePath.replace(/\.java$/, "").split("/").join(".");
28
+ }
29
+
30
+ export function classpath(entries ) {
31
+ return entries.join(PATH_SEPARATOR);
32
+ }
33
+
34
+ function result(spawned , tool ) {
35
+ if (spawned.error !== undefined) return { ok: false, output: `could not run ${tool}: ${spawned.error.message}` };
36
+ return { ok: spawned.status === 0, output: `${spawned.stdout}${spawned.stderr}` };
37
+ }
38
+
39
+ /** Compiles sources for the given Java release (default 11) into the classes directory. */
40
+ export function compileJava(sources , classes , extraClasspath = [], release = JAVA_RELEASE) {
41
+ mkdirSync(classes, { recursive: true });
42
+ // Recent JDKs warn that release 8 is obsolete; the warning is not news to someone building a Java 8 variant.
43
+ const args = ["--release", release, "-Xlint:-options", "-encoding", "UTF-8", "-d", classes, ...(extraClasspath.length > 0 ? ["-cp", classpath(extraClasspath)] : []), ...sources];
44
+ return result(spawnSync(JAVAC, args, { encoding: "utf8", timeout: RUN_TIMEOUT_MS }), JAVAC);
45
+ }
46
+
47
+ /** The java launcher of a JDK home. */
48
+ export function javaIn(home ) {
49
+ return join(home, "bin", "java");
50
+ }
51
+
52
+ /** Runs a class with the given java launcher (default: SDKLOOM_JAVA or java on the PATH). */
53
+ export function runJava(cp , mainClass , args , input , java = [JAVA]) {
54
+ const spawned = spawnSync(java[0] ?? JAVA, [...java.slice(1), "-cp", classpath(cp), mainClass, ...args], { encoding: "utf8", timeout: RUN_TIMEOUT_MS, ...(input === undefined ? {} : { input }) });
55
+ return { ...result(spawned, java.join(" ")), stdout: spawned.error === undefined ? spawned.stdout : "" };
56
+ }
57
+
58
+ export const JAVADOC = process.env["SDKLOOM_JAVADOC"] ?? "javadoc";
59
+
60
+ /**
61
+ * HTML documentation, as Maven Central requires next to every jar. Source files are passed one by one: recent javadoc
62
+ * versions crash on -subpackages with --release 8.
63
+ */
64
+ export function javadoc(sources , out , release = JAVA_RELEASE) {
65
+ const spawned = spawnSync(JAVADOC, ["-quiet", "-Xdoclint:none", "--release", release, "-encoding", "UTF-8", "-d", out, ...sources], {
66
+ encoding: "utf8",
67
+ timeout: RUN_TIMEOUT_MS,
68
+ });
69
+ return result(spawned, JAVADOC);
70
+ }
@@ -0,0 +1,120 @@
1
+ // Runs sdkloom scenarios and schema round-trips against the generated TypeScript SDK compiled to JavaScript, on any
2
+ // Node.js version the SDK supports (18+). Plain JavaScript on purpose: older Node versions cannot strip types.
3
+ //
4
+ // Reads a plan as JSON on stdin and prints one observation per case as JSON on stdout.
5
+
6
+ import { createServer } from "node:http";
7
+ import { pathToFileURL } from "node:url";
8
+ import { join } from "node:path";
9
+
10
+ const read = async () => {
11
+ const chunks = [];
12
+ for await (const chunk of process.stdin) chunks.push(chunk);
13
+ return JSON.parse(Buffer.concat(chunks).toString("utf8"));
14
+ };
15
+
16
+ const plan = await read();
17
+ const sdk = await import(pathToFileURL(join(plan.sdk, "index.js")).href);
18
+ const models = await import(pathToFileURL(join(plan.sdk, "models.js")).href);
19
+ const { encodeJson } = await import(pathToFileURL(join(plan.sdk, "runtime", "models.js")).href);
20
+
21
+ const wire = (value) => {
22
+ if (value === undefined || value === null) return null;
23
+ if (value instanceof Uint8Array) return new TextDecoder().decode(value);
24
+ return JSON.parse(new TextDecoder().decode(encodeJson(value)));
25
+ };
26
+
27
+ const failure = (error) => (error instanceof Error ? { ok: false, error: error.name, message: error.message } : { ok: false, error: String(error), message: "" });
28
+
29
+ /** The answers in order; the last one repeats. */
30
+ const answerFor = (answers, index) => answers[Math.min(index, answers.length - 1)];
31
+
32
+ /** A webhook case: verify and read the body with the SDK's verify<Name>Webhook. */
33
+ function webhook(item) {
34
+ const hook = item.webhook;
35
+ const verify = sdk[hook.verify];
36
+ if (typeof verify !== "function") return { id: item.id, outcome: { ok: false, error: "UnknownWebhook", message: hook.verify } };
37
+ try {
38
+ return { id: item.id, outcome: { ok: true, value: wire(verify(new TextEncoder().encode(hook.body), hook.headers, hook.secret, { nowSeconds: hook.now })) } };
39
+ } catch (error) {
40
+ return { id: item.id, outcome: failure(error) };
41
+ }
42
+ }
43
+
44
+ /** A logic case: call the SDK's logic function with its inputs. */
45
+ function logic(item) {
46
+ const fn = sdk[item.logic.name];
47
+ if (typeof fn !== "function") return { id: item.id, outcome: { ok: false, error: "UnknownLogic", message: item.logic.name } };
48
+ try {
49
+ return { id: item.id, outcome: { ok: true, value: wire(fn(item.logic.args)) } };
50
+ } catch (error) {
51
+ // Any failure is reported as Error, as in every language.
52
+ return { id: item.id, outcome: { ok: false, error: "Error", message: error instanceof Error ? error.message : String(error) } };
53
+ }
54
+ }
55
+
56
+ async function scenario(item) {
57
+ if (item.webhook !== undefined) return webhook(item);
58
+ if (item.logic !== undefined) return logic(item);
59
+ const requests = [];
60
+ const server = createServer((request, response) => {
61
+ const chunks = [];
62
+ request.on("data", (chunk) => chunks.push(chunk));
63
+ request.on("end", () => {
64
+ const answer = answerFor(item.answers, requests.length);
65
+ requests.push({ method: request.method, url: request.url, headers: request.headers, body: Buffer.concat(chunks).toString("utf8") });
66
+ const json = answer.json;
67
+ response.writeHead(answer.status, { ...(json === undefined ? {} : { "content-type": "application/json" }), ...(answer.headers ?? {}) });
68
+ response.end(answer.text ?? (json === undefined ? "" : JSON.stringify(json)));
69
+ });
70
+ });
71
+ await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
72
+ try {
73
+ const Client = sdk[plan.client];
74
+ const client = new Client({ ...(item.config ?? {}), baseUrl: `http://127.0.0.1:${server.address().port}`, timeoutMs: 5000 });
75
+ let outcome;
76
+ // A multipart body is described in the scenario as parts; files are sent as UTF-8 bytes.
77
+ if (item.multipart && item.args?.body !== undefined) {
78
+ const parts = item.args.body.parts.map((part) => ({ ...part, value: part.filename === undefined ? part.value : new TextEncoder().encode(part.value) }));
79
+ item = { ...item, args: { ...item.args, body: new sdk.MultipartForm(parts) } };
80
+ }
81
+ // all: the operation's iterator over every page, e.g. listPaymentsAll.
82
+ const method = item.all ? `${item.op}All` : item.wait ? `${item.op}AndWait` : item.op;
83
+ if (typeof client[method] !== "function") return { id: item.id, outcome: { ok: false, error: "UnknownOperation", message: method } };
84
+ try {
85
+ if (item.events) {
86
+ // Server-sent events: every event the stream delivers, with its data as JSON.
87
+ const events = [];
88
+ for await (const event of item.hasArgs ? client[method](item.args) : client[method]()) events.push({ event: event.event, id: event.id, data: wire(event.data) });
89
+ outcome = { ok: true, value: events };
90
+ } else if (item.all) {
91
+ const items = [];
92
+ for await (const entry of item.hasArgs ? client[method](item.args) : client[method]()) items.push(wire(entry));
93
+ outcome = { ok: true, value: items };
94
+ } else {
95
+ const value = item.hasArgs ? await client[method](item.args) : await client[method]();
96
+ outcome = { ok: true, value: wire(value) };
97
+ }
98
+ } catch (error) {
99
+ outcome = failure(error);
100
+ }
101
+ return { id: item.id, outcome, ...(requests.length === 0 ? {} : { received: requests[0], requests }) };
102
+ } finally {
103
+ server.closeAllConnections?.();
104
+ await new Promise((resolve) => server.close(resolve));
105
+ }
106
+ }
107
+
108
+ function roundTrip(item) {
109
+ const decode = models[`decode${item.type}`];
110
+ if (decode === undefined) return { id: item.id, outcome: { ok: false, error: "MissingDecoder", message: `decode${item.type}` } };
111
+ try {
112
+ return { id: item.id, outcome: { ok: true, value: wire(decode(item.value)) } };
113
+ } catch (error) {
114
+ return { id: item.id, outcome: failure(error) };
115
+ }
116
+ }
117
+
118
+ const results = [];
119
+ for (const item of plan.cases) results.push(plan.mode === "roundtrip" ? roundTrip(item) : await scenario(item));
120
+ process.stdout.write(JSON.stringify(results));
@@ -0,0 +1,103 @@
1
+ // What every language target shares: kit files and lines, the lock entry, and the shape of a built target.
2
+
3
+ import { readFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { createLock, } from "@sdkloom/codegen";
6
+
7
+ import { listFiles } from "./io.ts";
8
+ import { DEFAULT_PROFILE, included, kitProfiles, } from "./profiles.ts";
9
+ import { ProjectError } from "./project.ts";
10
+
11
+ export const SDKLOOM_VERSION = "0.1.0";
12
+ export const LOCK_FILE = "sdkloom.lock.json";
13
+ export const API_FILE = "api.json";
14
+ export const PYTHON_MIDDLEWARE_FILE = "custom/python/middleware.py";
15
+ export const JAVA_MIDDLEWARE_FILE = "custom/java/Middlewares.java";
16
+ export const GO_MIDDLEWARE_FILE = "custom/go/middleware.go";
17
+ export const RUST_MIDDLEWARE_FILE = "custom/rust/middleware.rs";
18
+ export const CSHARP_MIDDLEWARE_FILE = "custom/csharp/Middleware.cs";
19
+ export const KITS_DIR = join(import.meta.dirname, "..", "..", "..", "kits");
20
+ export const PYTHON_RUNTIME = join("src", "sdkloom_runtime");
21
+ export const JAVA_RUNTIME = join("src", "dev", "sdkloom", "runtime");
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ export function manifest(language ) {
33
+ return JSON.parse(readFileSync(join(KITS_DIR, language, "kit.json"), "utf8")) ;
34
+ }
35
+
36
+ /** The default line and variants of a language's kit (kits/<lang>/versions.json). */
37
+ export function profilesOf(language ) {
38
+ return kitProfiles(join(KITS_DIR, language), manifest(language).supports);
39
+ }
40
+
41
+ export function loadKit(language , dir , extension , profile ) {
42
+ const root = join(KITS_DIR, language);
43
+ const { name, version, supports } = manifest(language);
44
+ const files = listFiles(join(root, dir))
45
+ .filter((path) => path.endsWith(extension) && included(profile, path))
46
+ .map((path) => ({ path, text: readFileSync(join(root, dir, path), "utf8") }));
47
+ // The default line keeps the manifest's range; a variant states its own.
48
+ return { name, version, supports: profile.name === DEFAULT_PROFILE ? supports : profile.range, files };
49
+ }
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+ export function lockOf(language , ir , kit , output ) {
73
+ return createLock({
74
+ sdkloom: SDKLOOM_VERSION,
75
+ profile: `${language}@${kit.supports}`,
76
+ ir,
77
+ kits: [{ name: kit.name, version: kit.version, content: kit.files.map((file) => `${file.path}\n${file.text}`).join("\n") }],
78
+ blocks: output.blocks,
79
+ files: output.files,
80
+ trace: output.trace,
81
+ });
82
+ }
83
+
84
+ /** "@acme/payments-sdk" → "payments_sdk" */
85
+ export function defaultModule(packageName ) {
86
+ return packageName.replace(/^@[^/]+\//, "").replace(/[^A-Za-z0-9]+/g, "_").replace(/^_+|_+$/g, "").toLowerCase();
87
+ }
88
+
89
+ /** The kit line of a variant named in the config, or a clear error listing the ones that exist. */
90
+ export function variantProfile(language , variant ) {
91
+ const { variants } = profilesOf(language);
92
+ const found = variants.get(variant);
93
+ if (found === undefined) {
94
+ const known = [...variants.keys()];
95
+ throw new ProjectError(`targets.${language}.variants.${variant}: the ${language} kit has no such variant${known.length === 0 ? "" : `; available: ${known.join(", ")}`}`);
96
+ }
97
+ return found;
98
+ }
99
+
100
+ /** The default target and every variant the config names: same API, same version, own name. */
101
+ export function withVariants (variants , build ) {
102
+ return [undefined, ...Object.keys(variants ?? {})].map(build);
103
+ }