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,212 @@
1
+ // sdkloom C# kit: the transport that sends requests.
2
+
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+ using System.Net.Http;
7
+ using System.Threading;
8
+ using System.Threading.Tasks;
9
+
10
+ namespace Sdkloom.Runtime
11
+ {
12
+ // @block transport.httpclient
13
+ // @summary The default transport, on System.Net.Http.HttpClient: one shared client that follows no redirects and keeps no cookies, a per-request timeout that fails as a TransportException("timeout") while the caller's own cancellation stays an OperationCanceledException, non-2xx responses returned with their body, Content-Length: 0 for an empty POST, PUT or PATCH. Proxies and TLS come from the handler; pass your own HttpClient to change them.
14
+ // @versions >=3
15
+ // @source [1] https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient
16
+ // @quote [1] "HttpClient is intended to be instantiated once and reused throughout the life of an application."
17
+ // @source [2] https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.allowautoredirect
18
+ // @quote [2] "Gets or sets a value that indicates whether the handler should follow redirection responses."
19
+ // @source [3] https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtokensource.cancelafter
20
+ // @quote [3] "Schedules a cancel operation on this CancellationTokenSource after the specified number of milliseconds."
21
+ // @retrieved 2026-12-05
22
+ // @tests tests/TransportTests.cs
23
+ // @requirement SDKL-HTTP-004
24
+
25
+ /// <summary>How one request is sent.</summary>
26
+ public sealed class SendOptions
27
+ {
28
+ public SendOptions(long? timeoutMs, CancellationToken cancellationToken, bool stream = false)
29
+ {
30
+ TimeoutMs = timeoutMs;
31
+ CancellationToken = cancellationToken;
32
+ Stream = stream;
33
+ }
34
+
35
+ /// <summary>Bounds the whole exchange; for a stream, only the wait for the response headers.</summary>
36
+ public long? TimeoutMs { get; }
37
+
38
+ /// <summary>Hand a successful response's body over as it arrives, in HttpResponse.Stream (event streams).</summary>
39
+ public bool Stream { get; }
40
+
41
+ public CancellationToken CancellationToken { get; }
42
+ }
43
+
44
+ /// <summary>Sends one request and returns its response, whatever the status; it fails only without a response.</summary>
45
+ public interface ITransport
46
+ {
47
+ Task<HttpResponse> Send(HttpRequest request, SendOptions options);
48
+ }
49
+
50
+ /// <summary>The default transport, on HttpClient. A successful body is handed over as it arrives when the caller asks for a stream.</summary>
51
+ public sealed class HttpClientTransport : ITransport
52
+ {
53
+ private static readonly Lazy<HttpClient> Shared = new Lazy<HttpClient>(() =>
54
+ new HttpClient(new HttpClientHandler { AllowAutoRedirect = false, UseCookies = false }) { Timeout = System.Threading.Timeout.InfiniteTimeSpan });
55
+
56
+ private static readonly string[] Restricted = { "host", "connection", "content-length", "transfer-encoding" };
57
+ private static readonly string[] BodyMethods = { "POST", "PUT", "PATCH" };
58
+ private readonly HttpClient? _client;
59
+
60
+ /// <summary>Uses the given client, or one shared client that follows no redirects.</summary>
61
+ public HttpClientTransport(HttpClient? client = null)
62
+ {
63
+ _client = client;
64
+ }
65
+
66
+ public async Task<HttpResponse> Send(HttpRequest request, SendOptions options)
67
+ {
68
+ using var timeout = CancellationTokenSource.CreateLinkedTokenSource(options.CancellationToken);
69
+ // CancelAfter takes at most int.MaxValue milliseconds (about 24.8 days); anything longer is no limit.
70
+ if (options.TimeoutMs.HasValue && options.TimeoutMs.Value < int.MaxValue)
71
+ {
72
+ timeout.CancelAfter(TimeSpan.FromMilliseconds(Math.Max(1, options.TimeoutMs.Value)));
73
+ }
74
+
75
+ using var message = ToMessage(request);
76
+ try
77
+ {
78
+ if (options.Stream)
79
+ {
80
+ var streamed = await (_client ?? Shared.Value).SendAsync(message, HttpCompletionOption.ResponseHeadersRead, timeout.Token).ConfigureAwait(false);
81
+ var status = (int)streamed.StatusCode;
82
+ if (status >= 200 && status <= 299)
83
+ {
84
+ // The timeout covered the headers; disposing the body stream ends the request.
85
+ var stream = await streamed.Content.ReadAsStreamAsync().ConfigureAwait(false);
86
+ return new HttpResponse(status, HeadersOf(streamed), Array.Empty<byte>(), new ResponseStream(stream, streamed));
87
+ }
88
+
89
+ using (streamed)
90
+ {
91
+ return new HttpResponse(status, HeadersOf(streamed), await streamed.Content.ReadAsByteArrayAsync().ConfigureAwait(false));
92
+ }
93
+ }
94
+
95
+ using var response = await (_client ?? Shared.Value).SendAsync(message, HttpCompletionOption.ResponseContentRead, timeout.Token).ConfigureAwait(false);
96
+ var body = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
97
+ return new HttpResponse((int)response.StatusCode, HeadersOf(response), body);
98
+ }
99
+ catch (OperationCanceledException error) when (timeout.IsCancellationRequested && !options.CancellationToken.IsCancellationRequested)
100
+ {
101
+ throw new TransportException("timeout", error);
102
+ }
103
+ catch (HttpRequestException error)
104
+ {
105
+ throw new TransportException("network", error);
106
+ }
107
+ }
108
+
109
+ private static KeyValuePair<string, string>[] HeadersOf(HttpResponseMessage response) =>
110
+ response.Headers.Concat(response.Content.Headers)
111
+ .SelectMany(header => header.Value.Select(value => new KeyValuePair<string, string>(header.Key.ToLowerInvariant(), value)))
112
+ .ToArray();
113
+
114
+ /// <summary>A response body that also disposes its response, and reports failed reads as TransportException.</summary>
115
+ private sealed class ResponseStream : System.IO.Stream
116
+ {
117
+ private readonly System.IO.Stream _inner;
118
+ private readonly HttpResponseMessage _response;
119
+
120
+ public ResponseStream(System.IO.Stream inner, HttpResponseMessage response)
121
+ {
122
+ _inner = inner;
123
+ _response = response;
124
+ }
125
+
126
+ public override bool CanRead => true;
127
+
128
+ public override bool CanSeek => false;
129
+
130
+ public override bool CanWrite => false;
131
+
132
+ public override long Length => throw new NotSupportedException();
133
+
134
+ public override long Position
135
+ {
136
+ get => throw new NotSupportedException();
137
+ set => throw new NotSupportedException();
138
+ }
139
+
140
+ public override int Read(byte[] buffer, int offset, int count)
141
+ {
142
+ try
143
+ {
144
+ return _inner.Read(buffer, offset, count);
145
+ }
146
+ catch (System.IO.IOException error)
147
+ {
148
+ throw new TransportException("network", error);
149
+ }
150
+ }
151
+
152
+ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
153
+ {
154
+ try
155
+ {
156
+ return await _inner.ReadAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false);
157
+ }
158
+ catch (System.IO.IOException error)
159
+ {
160
+ throw new TransportException("network", error);
161
+ }
162
+ catch (HttpRequestException error)
163
+ {
164
+ throw new TransportException("network", error);
165
+ }
166
+ }
167
+
168
+ public override void Flush()
169
+ {
170
+ }
171
+
172
+ public override long Seek(long offset, System.IO.SeekOrigin origin) => throw new NotSupportedException();
173
+
174
+ public override void SetLength(long value) => throw new NotSupportedException();
175
+
176
+ public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException();
177
+
178
+ protected override void Dispose(bool disposing)
179
+ {
180
+ if (disposing)
181
+ {
182
+ _inner.Dispose();
183
+ _response.Dispose();
184
+ }
185
+
186
+ base.Dispose(disposing);
187
+ }
188
+ }
189
+
190
+ private static HttpRequestMessage ToMessage(HttpRequest request)
191
+ {
192
+ var message = new HttpRequestMessage(new HttpMethod(request.Method), request.Url);
193
+ if (request.Body != null || BodyMethods.Contains(request.Method))
194
+ {
195
+ message.Content = new ByteArrayContent(request.Body ?? Array.Empty<byte>());
196
+ }
197
+
198
+ foreach (var header in request.Headers.Where(header => !Restricted.Contains(header.Key.ToLowerInvariant())))
199
+ {
200
+ if (!message.Headers.TryAddWithoutValidation(header.Key, header.Value))
201
+ {
202
+ message.Content ??= new ByteArrayContent(Array.Empty<byte>());
203
+ message.Content.Headers.TryAddWithoutValidation(header.Key, header.Value);
204
+ }
205
+ }
206
+
207
+ return message;
208
+ }
209
+ }
210
+
211
+ // @end
212
+ }
@@ -0,0 +1,57 @@
1
+ // sdkloom C# kit: waiting for a long-running operation.
2
+
3
+ using System;
4
+ using System.Threading;
5
+ using System.Threading.Tasks;
6
+
7
+ namespace Sdkloom.Runtime
8
+ {
9
+ // @block lro.wait
10
+ // @summary Waits for a long-running operation: polls until the result says the work is done, sleeping on the client's clock between polls, observes cancellation, and throws WaitTimeoutException when the next poll would come after the deadline.
11
+ // @versions >=3
12
+ // @source [1] https://www.rfc-editor.org/rfc/rfc9110#section-15.3.3
13
+ // @quote [1] "The 202 (Accepted) status code indicates that the request has been accepted for processing, but the processing has not been completed."
14
+ // @retrieved 2026-12-06
15
+ // @tests tests/WaitTests.cs
16
+ // @requirement SDKL-WAIT-001
17
+
18
+ /// <summary>The work did not finish within the wait's timeout; Last is the last result read.</summary>
19
+ public sealed class WaitTimeoutException : SdkException
20
+ {
21
+ public WaitTimeoutException(string message, object? last)
22
+ : base(message)
23
+ {
24
+ Last = last;
25
+ }
26
+
27
+ public object? Last { get; }
28
+
29
+ public override string Name => "WaitTimeoutError";
30
+ }
31
+
32
+ /// <summary>Waiting for long-running operations.</summary>
33
+ public static class Waits
34
+ {
35
+ /// <summary>Polls until done(result); the first result comes from starting the work.</summary>
36
+ public static async Task<T> Until<T>(T first, Func<T, CancellationToken, Task<T>> poll, Func<T, bool> done, IClock clock, long intervalMs, long timeoutMs, CancellationToken cancellationToken = default)
37
+ {
38
+ var deadline = clock.Now() + timeoutMs;
39
+ var current = first;
40
+ while (!done(current))
41
+ {
42
+ if (clock.Now() + intervalMs > deadline)
43
+ {
44
+ throw new WaitTimeoutException("the work did not finish within " + timeoutMs + " ms", current);
45
+ }
46
+
47
+ cancellationToken.ThrowIfCancellationRequested();
48
+ await clock.Sleep(intervalMs, cancellationToken).ConfigureAwait(false);
49
+ current = await poll(current, cancellationToken).ConfigureAwait(false);
50
+ }
51
+
52
+ return current;
53
+ }
54
+ }
55
+
56
+ // @end
57
+ }
@@ -0,0 +1,148 @@
1
+ // sdkloom C# kit: verifying the signature of a webhook the API sent.
2
+
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Security.Cryptography;
6
+ using System.Text;
7
+ using System.Text.RegularExpressions;
8
+
9
+ namespace Sdkloom.Runtime
10
+ {
11
+ // @block webhooks.verify
12
+ // @summary Verifies a webhook's HMAC-SHA256 signature as the definition describes it (signed text from the body and headers, several signatures in one header, an optional timestamp tolerance against replays), comparing in constant time, and throws WebhookSignatureException.
13
+ // @versions >=3
14
+ // @source [1] https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md
15
+ // @quote [1] "When verifying symmetric signatures, use a constant time comparison function to compare the calculated with the expected signature."
16
+ // @quote [1] "The signature header is a space delimited list of signatures associated with this webhook."
17
+ // @source [2] https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.cryptographicoperations.fixedtimeequals
18
+ // @quote [2] "Determines the equality of two byte sequences in an amount of time that depends on the length of the sequences, but not their values."
19
+ // @retrieved 2026-12-05
20
+ // @tests tests/WebhooksTests.cs
21
+ // @requirement SDKL-HOOK-001
22
+
23
+ /// <summary>How a webhook is signed; the same fields as the definition's hmacSignature(). Null for absent options.</summary>
24
+ public sealed class WebhookSignature
25
+ {
26
+ public WebhookSignature(string header, string encoding, string? prefix, string? separator, string signed, string? timestampHeader, long toleranceSeconds, string secret, string? secretPrefix)
27
+ {
28
+ Header = header;
29
+ Encoding = encoding;
30
+ Prefix = prefix ?? "";
31
+ Separator = separator;
32
+ Signed = signed;
33
+ TimestampHeader = timestampHeader;
34
+ ToleranceSeconds = toleranceSeconds;
35
+ Secret = secret;
36
+ SecretPrefix = secretPrefix;
37
+ }
38
+
39
+ public string Header { get; }
40
+ public string Encoding { get; }
41
+ public string Prefix { get; }
42
+ public string? Separator { get; }
43
+ public string Signed { get; }
44
+ public string? TimestampHeader { get; }
45
+ public long ToleranceSeconds { get; }
46
+ public string Secret { get; }
47
+ public string? SecretPrefix { get; }
48
+ }
49
+
50
+ /// <summary>The webhook was not signed with the secret, or is too old or too new.</summary>
51
+ public sealed class WebhookSignatureException : SdkException
52
+ {
53
+ public WebhookSignatureException(string message)
54
+ : base(message)
55
+ {
56
+ }
57
+
58
+ public override string Name => "WebhookSignatureError";
59
+ }
60
+
61
+ /// <summary>Verifies webhook signatures.</summary>
62
+ public static class Webhooks
63
+ {
64
+ private static readonly Regex Placeholder = new Regex(@"\{([^{}]*)\}", RegexOptions.CultureInvariant);
65
+ private static readonly Regex Timestamp = new Regex("^[0-9]{1,15}$", RegexOptions.CultureInvariant);
66
+
67
+ private static string? Find(IEnumerable<KeyValuePair<string, string>> headers, string name)
68
+ {
69
+ foreach (var entry in headers)
70
+ {
71
+ if (string.Equals(entry.Key, name, StringComparison.OrdinalIgnoreCase))
72
+ {
73
+ return entry.Value;
74
+ }
75
+ }
76
+ return null;
77
+ }
78
+
79
+ /// <summary>Throws WebhookSignatureException unless one of the header's signatures is the HMAC of the signed text, made in time.</summary>
80
+ public static void Verify(WebhookSignature signature, byte[] body, IEnumerable<KeyValuePair<string, string>> headers, string secret, long nowSeconds)
81
+ {
82
+ if (signature.TimestampHeader != null)
83
+ {
84
+ var stamp = (Find(headers, signature.TimestampHeader) ?? "").Trim();
85
+ if (!Timestamp.IsMatch(stamp))
86
+ {
87
+ throw new WebhookSignatureException($"missing or invalid {signature.TimestampHeader} header");
88
+ }
89
+ if (Math.Abs(nowSeconds - long.Parse(stamp, System.Globalization.CultureInfo.InvariantCulture)) > signature.ToleranceSeconds)
90
+ {
91
+ throw new WebhookSignatureException($"the webhook was signed at {stamp}, more than {signature.ToleranceSeconds} s from now");
92
+ }
93
+ }
94
+ var given = Find(headers, signature.Header) ?? throw new WebhookSignatureException($"missing {signature.Header} header");
95
+ var message = new List<byte>();
96
+ var last = 0;
97
+ foreach (Match match in Placeholder.Matches(signature.Signed))
98
+ {
99
+ message.AddRange(System.Text.Encoding.UTF8.GetBytes(signature.Signed.Substring(last, match.Index - last)));
100
+ var name = match.Groups[1].Value;
101
+ message.AddRange(name == "body" ? body : System.Text.Encoding.UTF8.GetBytes(Find(headers, name) ?? throw new WebhookSignatureException($"missing {name} header")));
102
+ last = match.Index + match.Length;
103
+ }
104
+ message.AddRange(System.Text.Encoding.UTF8.GetBytes(signature.Signed.Substring(last)));
105
+ var keyText = signature.SecretPrefix != null && secret.StartsWith(signature.SecretPrefix, StringComparison.Ordinal) ? secret.Substring(signature.SecretPrefix.Length) : secret;
106
+ byte[] key;
107
+ try
108
+ {
109
+ key = signature.Secret == "base64" ? Convert.FromBase64String(keyText) : System.Text.Encoding.UTF8.GetBytes(keyText);
110
+ }
111
+ catch (FormatException)
112
+ {
113
+ throw new WebhookSignatureException("the secret is not valid base64");
114
+ }
115
+ byte[] digest;
116
+ using (var hmac = new HMACSHA256(key))
117
+ {
118
+ digest = hmac.ComputeHash(message.ToArray());
119
+ }
120
+ var expected = System.Text.Encoding.ASCII.GetBytes(signature.Encoding == "hex" ? Hex(digest) : Convert.ToBase64String(digest));
121
+ var candidates = signature.Separator == null ? new[] { given } : given.Split(new[] { signature.Separator }, StringSplitOptions.None);
122
+ var matched = false;
123
+ foreach (var candidate in candidates)
124
+ {
125
+ if (candidate.StartsWith(signature.Prefix, StringComparison.Ordinal))
126
+ {
127
+ matched |= CryptographicOperations.FixedTimeEquals(System.Text.Encoding.UTF8.GetBytes(candidate.Substring(signature.Prefix.Length)), expected);
128
+ }
129
+ }
130
+ if (!matched)
131
+ {
132
+ throw new WebhookSignatureException("no signature matches: the webhook was not signed with this secret, or was changed after signing");
133
+ }
134
+ }
135
+
136
+ private static string Hex(byte[] bytes)
137
+ {
138
+ var text = new StringBuilder(bytes.Length * 2);
139
+ foreach (var value in bytes)
140
+ {
141
+ text.Append(value.ToString("x2", System.Globalization.CultureInfo.InvariantCulture));
142
+ }
143
+ return text.ToString();
144
+ }
145
+ }
146
+
147
+ // @end
148
+ }
@@ -0,0 +1,128 @@
1
+ // @requirement SDKL-VERSION-001
2
+ using System;
3
+ using System.Collections.Generic;
4
+ using System.Linq;
5
+ using System.Threading;
6
+ using System.Threading.Tasks;
7
+
8
+ namespace Sdkloom.Runtime.Tests
9
+ {
10
+ public sealed class NotFoundException : ApiException
11
+ {
12
+ public NotFoundException(int status, Json body, HttpResponse response)
13
+ : base("NotFound", status, body, response)
14
+ {
15
+ }
16
+ }
17
+
18
+ public static class ClientTests
19
+ {
20
+ private static readonly KeyValuePair<string, Json>[] None = new KeyValuePair<string, Json>[0];
21
+
22
+ private static OperationSpec Spec(params string[] uses) =>
23
+ new OperationSpec("getThing", "GET", "/things/{id}", null, BodyKind.Json, new Dictionary<int, ErrorFactory> { [404] = (status, body, response) => new NotFoundException(status, body, response) }, uses);
24
+
25
+ private static ClientRuntime Runtime(MockTransport transport, IReadOnlyDictionary<string, MiddlewareEntry>? registry = null, IReadOnlyList<EventListener>? listeners = null) =>
26
+ new ClientRuntime("http://api.test", transport, new FakeClock(), new MiddlewareEntry[0], registry ?? new Dictionary<string, MiddlewareEntry>(), new MiddlewareEntry[0], listeners ?? new EventListener[0], null, new SdkInfo("things", "1.0.0", "csharp"));
27
+
28
+ private static CallArgs Args() => new CallArgs(new[] { new KeyValuePair<string, Json>("id", "a 1") }, None, new[] { new KeyValuePair<string, Json>("x-trace", Json.Null) }, null);
29
+
30
+ public static async Task SendsTheRequestAndReturnsA2xxResponse()
31
+ {
32
+ var transport = new MockTransport();
33
+ transport.Route("GET", "/things/{id}").ReplyJson(200, Json.Object(("id", "a 1")));
34
+
35
+ var response = await Call.Send(Runtime(transport), Spec(), Args(), new CallOptions { Headers = new[] { new KeyValuePair<string, string>("x-extra", "1") } }, CancellationToken.None);
36
+
37
+ var sent = transport.Calls().Single();
38
+ Check.Equal("http://api.test/things/a%201", sent.Url);
39
+ Check.Equal("application/json", sent.Header("accept"));
40
+ Check.Equal("1", sent.Header("x-extra"));
41
+ Check.Equal(null, sent.Header("x-trace"));
42
+ Check.Equal("{\"id\":\"a 1\"}", response.Json().ToJsonString());
43
+ }
44
+
45
+ public static async Task ANon2xxResponseBecomesTheDeclaredErrorOrApiException()
46
+ {
47
+ var transport = new MockTransport();
48
+ var route = transport.Route("GET", "/things/{id}");
49
+ route.ReplyJson(404, Json.Object(("message", "gone"))).Reply(503, System.Text.Encoding.UTF8.GetBytes("down"), new[] { new KeyValuePair<string, string>("x-request-id", "r1") });
50
+
51
+ var declared = await Check.ThrowsAsync<NotFoundException>(() => Call.Send(Runtime(transport), Spec(), Args(), null, CancellationToken.None));
52
+ var other = await Check.ThrowsAsync<ApiException>(() => Call.Send(Runtime(transport), Spec(), Args(), null, CancellationToken.None));
53
+
54
+ Check.Equal("NotFound: HTTP 404: {\"message\":\"gone\"}", declared.Message);
55
+ Check.Equal("{\"message\":\"gone\"}", declared.Body.ToJsonString());
56
+ Check.Equal(false, declared.Retryable);
57
+ Check.Equal("ApiError", other.Name);
58
+ Check.Equal("\"down\"", other.Body.ToJsonString());
59
+ Check.Equal("r1", other.RequestId);
60
+ Check.Equal(true, other.Retryable);
61
+ }
62
+
63
+ public static async Task MiddlewareRunsInOrderWithItsConfigAndCanRetry()
64
+ {
65
+ var transport = new MockTransport();
66
+ transport.Route("GET", "/things/{id}").Reply(500).ReplyJson(200, Json.Null);
67
+ var events = new List<string>();
68
+ Middleware retry = async (request, next, ctx) =>
69
+ {
70
+ var response = await next(request).ConfigureAwait(false);
71
+ for (var attempt = 1; attempt <= Js.ToLong(ctx.Config("max")) && response.Status >= 500; attempt++)
72
+ {
73
+ await ctx.Sleep(100).ConfigureAwait(false);
74
+ ctx.Emit("retry", Json.Object(("attempt", attempt)));
75
+ response = await next(request).ConfigureAwait(false);
76
+ }
77
+
78
+ return response;
79
+ };
80
+ var registry = new Dictionary<string, MiddlewareEntry> { ["retry"] = MiddlewareEntry.Of("retry", retry, new[] { new KeyValuePair<string, Json>("max", 2L) }) };
81
+ var runtime = Runtime(transport, registry, new EventListener[] { (name, fields) => events.Add(name + fields.ToJsonString()) });
82
+
83
+ var response = await Call.Send(runtime, Spec("retry"), Args(), null, CancellationToken.None);
84
+
85
+ Check.Equal(200, response.Status);
86
+ Check.Equal("retry{\"attempt\":1}", string.Join(";", events));
87
+ Check.Equal(100L, runtime.Clock.Now());
88
+ }
89
+
90
+ public static void AListenerThatThrowsIsReportedNotPropagated()
91
+ {
92
+ var seen = new List<string>();
93
+ EventListener broken = (name, fields) => throw new InvalidOperationException("boom");
94
+ EventListener good = (name, fields) => seen.Add(name + fields.ToJsonString());
95
+
96
+ Events.Emit(new[] { broken, good }, "x", Json.Object());
97
+
98
+ Check.Equal("x{};sdkloom.listener_error{\"event\":\"x\",\"error\":\"boom\"}", string.Join(";", seen));
99
+ }
100
+
101
+ public static void StateExpiresOnTheClock()
102
+ {
103
+ var clock = new FakeClock();
104
+ var state = new State(clock);
105
+ state.Set("token", "t", 1000);
106
+
107
+ Check.Equal("\"t\"", state.Get("token").ToJsonString());
108
+ clock.Advance(1000);
109
+ Check.True(state.Get("token").IsNull, "expired");
110
+ }
111
+
112
+ public static async Task AnUnknownMiddlewareFailsTheCall()
113
+ {
114
+ var error = await Check.ThrowsAsync<SdkException>(() => Call.Send(Runtime(new MockTransport()), Spec("missing"), Args(), null, CancellationToken.None));
115
+
116
+ Check.Equal("unknown middleware missing", error.Message);
117
+ }
118
+
119
+ public static void AnOperationNewerThanThePinnedApiVersionIsRefusedAndUnknownVersionsToo()
120
+ {
121
+ var version = new ApiVersion("api-version", "2024-06-20", new[] { "2024-06-20", "2025-01-01" });
122
+ version.Check("getOrder", "2024-06-20");
123
+ version.Check("getOrder", null);
124
+ Check.Equal("refundOrder needs API version 2025-01-01 or later; this client uses 2024-06-20", Check.Throws<SdkArgumentException>(() => version.Check("refundOrder", "2025-01-01")).Message);
125
+ Check.Throws<SdkArgumentException>(() => new ApiVersion("api-version", "1999", new[] { "2024-06-20" }).Check("getOrder", null));
126
+ }
127
+ }
128
+ }
@@ -0,0 +1,44 @@
1
+ using System.Collections.Generic;
2
+
3
+ namespace Sdkloom.Runtime.Tests
4
+ {
5
+ public static class HttpTests
6
+ {
7
+ private static KeyValuePair<string, Json> P(string name, Json value) => new KeyValuePair<string, Json>(name, value);
8
+
9
+ public static void HeadersAreCaseInsensitiveAndWithHeaderReplaces()
10
+ {
11
+ var request = new HttpRequest("GET", "http://x/").WithHeader("Accept", "a").WithHeader("accept", "b");
12
+
13
+ Check.Equal(1, request.Headers.Count);
14
+ Check.Equal("b", request.Header("ACCEPT"));
15
+ Check.Equal(null, request.WithoutHeader("accept").Header("accept"));
16
+ }
17
+
18
+ public static void ResponsesReadAsTextAndJson()
19
+ {
20
+ var response = new HttpResponse(200, null, System.Text.Encoding.UTF8.GetBytes("{\"a\":1}"));
21
+
22
+ Check.Equal("{\"a\":1}", response.Json().ToJsonString());
23
+ Check.True(new HttpResponse(204).Json().IsNull, "an empty body is null");
24
+ Check.Equal("{\"a\":1}", new HttpResponse(200, null, new byte[] { 0xEF, 0xBB, 0xBF, (byte)'{', (byte)'"', (byte)'a', (byte)'"', (byte)':', (byte)'1', (byte)'}' }).Json().ToJsonString());
25
+ }
26
+
27
+ public static void BuildsUrlsLikeTheOtherKits()
28
+ {
29
+ var url = Url.Build("https://api.example.com/v1/", "/orders/{id}/items", new[] { P("id", "a b/ç~") }, new[] { P("q", "x y*~"), P("n", Json.Null), P("tag", Json.Array("a", "b")), P("big", 2.0), P("flag", true) });
30
+
31
+ Check.Equal("https://api.example.com/v1/orders/a%20b%2F%C3%A7~/items?q=x+y*%7E&tag=a&tag=b&big=2&flag=true", url);
32
+ Check.Throws<SdkException>(() => Url.Build("http://x", "/a/{id}", new KeyValuePair<string, Json>[0], new KeyValuePair<string, Json>[0]));
33
+ }
34
+
35
+ public static void APathParameterOfDotsIsRefused()
36
+ {
37
+ foreach (var value in new[] { ".", ".." })
38
+ {
39
+ Check.Equal("ArgumentError", Check.Throws<SdkArgumentException>(() => Url.Build("https://a.test", "/f/{id}", new[] { P("id", value) }, new KeyValuePair<string, Json>[0])).Name);
40
+ }
41
+ Check.Equal("https://a.test/f/a..b", Url.Build("https://a.test", "/f/{id}", new[] { P("id", "a..b") }, new KeyValuePair<string, Json>[0]));
42
+ }
43
+ }
44
+ }