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,117 @@
1
+ // sdkloom Rust kit: iterating over every item of a paginated operation.
2
+
3
+ use super::errors::Error;
4
+ use std::collections::VecDeque;
5
+
6
+ // @block pagination.iterate
7
+ // @summary Walks the pages of a paginated operation lazily as an Iterator of Result: fetches a page when its items run out, splits it into items and the next call's parameters (None ends), and ends after the first error.
8
+ // @versions >=1.70
9
+ // @source [1] https://doc.rust-lang.org/std/iter/trait.Iterator.html
10
+ // @quote [1] "A trait for dealing with iterators."
11
+ // @retrieved 2026-12-05
12
+ // @tests tests/pagination.rs
13
+ // @requirement SDKL-PAGE-001
14
+
15
+ type NextPage<'a, T> = Box<dyn FnMut() -> Option<Result<Vec<T>, Error>> + 'a>;
16
+
17
+ /// Every item of every page: `for item in client.list_payments_all(&params) { let item = item?; … }`.
18
+ pub struct Pager<'a, T> {
19
+ next_page: NextPage<'a, T>,
20
+ buffer: VecDeque<T>,
21
+ done: bool,
22
+ }
23
+
24
+ impl<'a, T> Pager<'a, T> {
25
+ /// Starts at the first call's parameters; step splits a page into its items and the next call's parameters.
26
+ /// Nothing is fetched until the first item is asked for.
27
+ pub fn new<P: 'a, R: 'a>(first: P, fetch: impl Fn(&P) -> Result<R, Error> + 'a, step: impl Fn(&P, R) -> (Vec<T>, Option<P>) + 'a) -> Pager<'a, T> {
28
+ let mut params = Some(first);
29
+ let next_page = move || {
30
+ let current = params.take()?;
31
+ Some(fetch(&current).map(|page| {
32
+ let (items, next) = step(&current, page);
33
+ params = next;
34
+ items
35
+ }))
36
+ };
37
+ Pager { next_page: Box::new(next_page), buffer: VecDeque::new(), done: false }
38
+ }
39
+ }
40
+
41
+ impl<'a, T> Iterator for Pager<'a, T> {
42
+ type Item = Result<T, Error>;
43
+
44
+ fn next(&mut self) -> Option<Result<T, Error>> {
45
+ loop {
46
+ if let Some(item) = self.buffer.pop_front() {
47
+ return Some(Ok(item));
48
+ }
49
+ if self.done {
50
+ return None;
51
+ }
52
+ match (self.next_page)() {
53
+ None => {
54
+ self.done = true;
55
+ return None;
56
+ }
57
+ Some(Err(error)) => {
58
+ self.done = true;
59
+ return Some(Err(error));
60
+ }
61
+ Some(Ok(items)) => self.buffer.extend(items),
62
+ }
63
+ }
64
+ }
65
+ }
66
+
67
+ // @end
68
+
69
+ // @block pagination.link
70
+ // @summary Finds the next page's URL in a Link header (RFC 8288): splits link-values at commas outside <...>, reads the rel parameter (quoted or not, several relation types allowed, compared case-insensitively) and returns the target of rel="next"; resolves it against the base URL.
71
+ // @versions >=1.70
72
+ // @source [1] https://www.rfc-editor.org/rfc/rfc8288#section-3
73
+ // @quote [1] "The Link header field provides a means for serialising one or more links into HTTP headers."
74
+ // @quote [1] "The rel parameter can, however, contain multiple link relation types."
75
+ // @quote [1] "MUST be compared character by character in a case-insensitive fashion."
76
+ // @retrieved 2026-12-06
77
+ // @tests tests/pagination.rs
78
+ // @requirement SDKL-PAGE-001
79
+
80
+ /// The URL of the link with relation type "next" in a Link header, or None.
81
+ pub fn next_link(header: Option<&str>) -> Option<String> {
82
+ let mut rest = header?;
83
+ while let Some(open) = rest.find('<') {
84
+ let close = open + rest[open..].find('>')?;
85
+ let target = &rest[open + 1..close];
86
+ let after = &rest[close + 1..];
87
+ let params_end = after.find(',').unwrap_or(after.len());
88
+ for param in after[..params_end].split(';') {
89
+ let Some((name, value)) = param.split_once('=') else { continue };
90
+ if !name.trim().eq_ignore_ascii_case("rel") {
91
+ continue;
92
+ }
93
+ if value.trim().trim_matches('"').split_whitespace().any(|kind| kind.eq_ignore_ascii_case("next")) {
94
+ return Some(target.to_string());
95
+ }
96
+ break;
97
+ }
98
+ rest = &after[params_end..];
99
+ }
100
+ None
101
+ }
102
+
103
+ /// A URL from the API resolved against the base URL: absolute as is, "/path" on the base's origin, else after it.
104
+ pub fn resolve_url(base: &str, url: &str) -> String {
105
+ let lower = url.to_ascii_lowercase();
106
+ if lower.starts_with("http://") || lower.starts_with("https://") {
107
+ return url.to_string();
108
+ }
109
+ if url.starts_with('/') {
110
+ let scheme_end = base.find("://").map(|at| at + 3).unwrap_or(0);
111
+ let origin_end = base[scheme_end..].find('/').map(|at| scheme_end + at).unwrap_or(base.len());
112
+ return format!("{}{}", &base[..origin_end], url);
113
+ }
114
+ format!("{}/{}", base.trim_end_matches('/'), url)
115
+ }
116
+
117
+ // @end
@@ -0,0 +1,195 @@
1
+ // sdkloom Rust kit: reading a stream of server-sent events.
2
+
3
+ use super::errors::{DecodeError, Error};
4
+ use super::http::{BodyStream, Response};
5
+ use super::json::Json;
6
+ use std::io::{ErrorKind, Read};
7
+
8
+ // @block sse.parse
9
+ // @summary Reads a text/event-stream response as it arrives as an Iterator of Result: splits lines on CRLF, LF or CR (also across reads), collects event, data and id fields, dispatches on a blank line, drops an unfinished event at the end, and decodes each event's data (JSON for a typed stream, text for a string stream).
10
+ // @versions >=1.70
11
+ // @source [1] https://html.spec.whatwg.org/multipage/server-sent-events.html
12
+ // @quote [1] "Event streams in this format must always be encoded as UTF-8."
13
+ // @quote [1] "Once the end of the file is reached, any pending data must be discarded."
14
+ // @quote [1] "If value starts with a U+0020 SPACE"
15
+ // @source [2] https://doc.rust-lang.org/std/io/trait.Read.html#tymethod.read
16
+ // @quote [2] "Pull some bytes from this source into the specified buffer, returning how many bytes were read."
17
+ // @retrieved 2026-12-06
18
+ // @tests tests/sse.rs
19
+ // @requirement SDKL-SSE-001
20
+
21
+ /// One server-sent event: its type ("message" unless the server named one), the last event ID and its data.
22
+ #[derive(Clone, Debug, PartialEq)]
23
+ pub struct ServerSentEvent<T> {
24
+ pub event: String,
25
+ pub id: String,
26
+ pub data: T,
27
+ }
28
+
29
+ type ReadData<T> = Box<dyn Fn(String) -> Result<T, Error> + Send>;
30
+
31
+ /// Events as they arrive: `for event in client.watch_events(&params)? { let event = event?; … }`. Dropping it ends
32
+ /// the request.
33
+ pub struct EventStream<T> {
34
+ body: BodyStream,
35
+ read: ReadData<T>,
36
+ chunk: Vec<u8>,
37
+ buffer: Vec<u8>,
38
+ position: usize,
39
+ line: Vec<u8>,
40
+ cr_last: bool,
41
+ first: bool,
42
+ kind: String,
43
+ data: Option<String>,
44
+ last_id: String,
45
+ done: bool,
46
+ }
47
+
48
+ impl EventStream<String> {
49
+ /// Events whose data stays text.
50
+ pub fn text(response: &Response) -> EventStream<String> {
51
+ EventStream::with(response, Box::new(Ok))
52
+ }
53
+ }
54
+
55
+ impl<T: 'static> EventStream<T> {
56
+ /// Events whose data is JSON read with decode.
57
+ pub fn json(response: &Response, decode: fn(&Json, &str) -> Result<T, DecodeError>) -> EventStream<T> {
58
+ EventStream::with(
59
+ response,
60
+ Box::new(move |data: String| {
61
+ let value = Json::parse(&data).map_err(|message| DecodeError::new("$", &format!("the event data is not JSON: {}", message)))?;
62
+ Ok(decode(&value, "$")?)
63
+ }),
64
+ )
65
+ }
66
+
67
+ fn with(response: &Response, read: ReadData<T>) -> EventStream<T> {
68
+ EventStream {
69
+ body: response.body_reader(),
70
+ read,
71
+ chunk: vec![0; 8192],
72
+ buffer: Vec::new(),
73
+ position: 0,
74
+ line: Vec::new(),
75
+ cr_last: false,
76
+ first: true,
77
+ kind: String::new(),
78
+ data: None,
79
+ last_id: String::new(),
80
+ done: false,
81
+ }
82
+ }
83
+
84
+ fn text_of_line(&mut self) -> String {
85
+ let mut line = std::mem::take(&mut self.line);
86
+ if self.first {
87
+ self.first = false;
88
+ // One leading byte order mark is not part of the stream.
89
+ if line.starts_with(&[0xEF, 0xBB, 0xBF]) {
90
+ line.drain(..3);
91
+ }
92
+ }
93
+ String::from_utf8_lossy(&line).into_owned()
94
+ }
95
+
96
+ /// Handles one line; Some when it was the blank line ending an event.
97
+ fn handle(&mut self, text: String) -> Option<Result<ServerSentEvent<T>, Error>> {
98
+ if text.is_empty() {
99
+ let data = match self.data.take() {
100
+ Some(data) => data,
101
+ None => {
102
+ self.kind.clear();
103
+ return None;
104
+ }
105
+ };
106
+ let data = data.strip_suffix('\n').map(str::to_string).unwrap_or(data);
107
+ let event = if self.kind.is_empty() { "message".to_string() } else { std::mem::take(&mut self.kind) };
108
+ return Some((self.read)(data).map(|data| ServerSentEvent { event, id: self.last_id.clone(), data }));
109
+ }
110
+ if text.starts_with(':') {
111
+ return None;
112
+ }
113
+ let (field, value) = match text.split_once(':') {
114
+ Some((field, value)) => (field.to_string(), value.strip_prefix(' ').unwrap_or(value).to_string()),
115
+ None => (text, String::new()),
116
+ };
117
+ match field.as_str() {
118
+ "event" => self.kind = value,
119
+ "data" => {
120
+ let data = self.data.get_or_insert_with(String::new);
121
+ data.push_str(&value);
122
+ data.push('\n');
123
+ }
124
+ "id" if !value.contains('\0') => self.last_id = value,
125
+ _ => {}
126
+ }
127
+ None
128
+ }
129
+ }
130
+
131
+ impl<T: 'static> Iterator for EventStream<T> {
132
+ type Item = Result<ServerSentEvent<T>, Error>;
133
+
134
+ fn next(&mut self) -> Option<Self::Item> {
135
+ while !self.done {
136
+ if self.position == self.buffer.len() {
137
+ let count = match self.body.read(&mut self.chunk) {
138
+ Ok(count) => count,
139
+ Err(error) => {
140
+ self.done = true;
141
+ let reason = if matches!(error.kind(), ErrorKind::TimedOut | ErrorKind::WouldBlock) { "timeout" } else { "network" };
142
+ return Some(Err(Error::transport(reason, error)));
143
+ }
144
+ };
145
+ if count == 0 {
146
+ self.done = true;
147
+ return None;
148
+ }
149
+ self.buffer = self.chunk[..count].to_vec();
150
+ self.position = 0;
151
+ }
152
+ let value = self.buffer[self.position];
153
+ self.position += 1;
154
+ if self.cr_last {
155
+ self.cr_last = false;
156
+ if value == b'\n' {
157
+ continue;
158
+ }
159
+ }
160
+ if value == b'\r' || value == b'\n' {
161
+ self.cr_last = value == b'\r';
162
+ let text = self.text_of_line();
163
+ if let Some(event) = self.handle(text) {
164
+ if event.is_err() {
165
+ self.done = true;
166
+ }
167
+ return Some(event);
168
+ }
169
+ continue;
170
+ }
171
+ self.line.push(value);
172
+ }
173
+ None
174
+ }
175
+ }
176
+
177
+ /// Writes events in the event-stream format (mocks and tests); each data is already text (JSON for a typed stream).
178
+ pub fn encode_events(events: &[ServerSentEvent<String>]) -> String {
179
+ let mut out = String::new();
180
+ for event in events {
181
+ if event.event != "message" && !event.event.is_empty() {
182
+ out.push_str(&format!("event: {}\n", event.event));
183
+ }
184
+ if !event.id.is_empty() {
185
+ out.push_str(&format!("id: {}\n", event.id));
186
+ }
187
+ for part in event.data.replace("\r\n", "\n").replace('\r', "\n").split('\n') {
188
+ out.push_str(&format!("data: {}\n", part));
189
+ }
190
+ out.push('\n');
191
+ }
192
+ out
193
+ }
194
+
195
+ // @end
@@ -0,0 +1,308 @@
1
+ // sdkloom Rust kit: test helpers shipped inside every generated SDK.
2
+
3
+ use super::context::Clock;
4
+ use super::errors::{DecodeError, Error};
5
+ use super::http::{Request, Response};
6
+ use super::json::Json;
7
+ use super::sse::{encode_events, ServerSentEvent};
8
+ use super::transport::{SendOptions, Transport};
9
+ use std::sync::{Arc, Mutex};
10
+
11
+ // @block testing.mock_transport
12
+ // @summary A transport for tests: answers requests from routes registered by method and path template, records every call and fails requests no route answers.
13
+ // @versions >=1.70
14
+ // @source [1] https://doc.rust-lang.org/std/sync/struct.Mutex.html
15
+ // @quote [1] "A mutual exclusion primitive useful for protecting shared data"
16
+ // @retrieved 2026-12-05
17
+ // @tests tests/testing.rs
18
+ // @requirement SDKL-MOCK-001
19
+
20
+ enum Answer {
21
+ Response(Response),
22
+ Error(Error),
23
+ }
24
+
25
+ type Predicate = Arc<dyn Fn(&Request) -> bool + Send + Sync>;
26
+
27
+ struct Route {
28
+ method: String,
29
+ template: String,
30
+ predicate: Option<Predicate>,
31
+ answers: Vec<Answer>,
32
+ calls: Vec<Request>,
33
+ }
34
+
35
+ /// Answers requests from routes; routes added later take priority. Thread-safe.
36
+ #[derive(Default)]
37
+ pub struct MockTransport {
38
+ routes: Mutex<Vec<Route>>,
39
+ calls: Mutex<Vec<Request>>,
40
+ }
41
+
42
+ /// A route of a MockTransport, by its index.
43
+ #[derive(Clone)]
44
+ pub struct MockRoute {
45
+ transport: Arc<MockTransport>,
46
+ index: usize,
47
+ }
48
+
49
+ fn path_of(url: &str) -> &str {
50
+ let rest = url.split_once("://").map(|(_, rest)| rest).unwrap_or(url);
51
+ let path = rest.find('/').map(|index| &rest[index..]).unwrap_or("/");
52
+ path.split('?').next().unwrap_or(path)
53
+ }
54
+
55
+ /// {name} matches one non-empty segment, {+name} one or more.
56
+ fn matches_segments(wanted: &[&str], actual: &[&str]) -> bool {
57
+ match wanted.split_first() {
58
+ None => actual.is_empty(),
59
+ Some((want, rest)) if want.starts_with("{+") && want.ends_with('}') => (1..=actual.len()).any(|taken| matches_segments(rest, &actual[taken..])),
60
+ Some((want, rest)) => match actual.split_first() {
61
+ Some((have, others)) => ((want.starts_with('{') && want.ends_with('}') && !have.is_empty()) || want == have) && matches_segments(rest, others),
62
+ None => false,
63
+ },
64
+ }
65
+ }
66
+
67
+ fn matches_template(template: &str, path: &str) -> bool {
68
+ let wanted: Vec<&str> = template.split('/').collect();
69
+ let actual: Vec<&str> = path.split('/').collect();
70
+ matches_segments(&wanted, &actual)
71
+ }
72
+
73
+ impl MockTransport {
74
+ pub fn new() -> Arc<MockTransport> {
75
+ Arc::new(MockTransport::default())
76
+ }
77
+
78
+ /// Registers a route; predicate None answers every matching request.
79
+ pub fn route(self: &Arc<Self>, method: &str, template: &str, predicate: Option<Predicate>) -> MockRoute {
80
+ let mut routes = self.routes.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
81
+ routes.push(Route { method: method.to_string(), template: template.to_string(), predicate, answers: Vec::new(), calls: Vec::new() });
82
+ MockRoute { transport: self.clone(), index: routes.len() - 1 }
83
+ }
84
+
85
+ /// Every request sent.
86
+ pub fn calls(&self) -> Vec<Request> {
87
+ self.calls.lock().unwrap_or_else(|poisoned| poisoned.into_inner()).clone()
88
+ }
89
+ }
90
+
91
+ impl Transport for MockTransport {
92
+ fn send(&self, request: &Request, _options: &SendOptions) -> Result<Response, Error> {
93
+ self.calls.lock().unwrap_or_else(|poisoned| poisoned.into_inner()).push(request.clone());
94
+ let mut routes = self.routes.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
95
+ let path = path_of(&request.url);
96
+ // Routes added later take priority, and a route with answers beats one without.
97
+ let matching: Vec<usize> = (0..routes.len()).rev().filter(|&index| {
98
+ let route = &routes[index];
99
+ route.method == request.method && matches_template(&route.template, path) && route.predicate.as_ref().map(|test| test(request)).unwrap_or(true)
100
+ }).collect();
101
+ let chosen = matching.iter().copied().find(|&index| !routes[index].answers.is_empty()).or_else(|| matching.first().copied());
102
+ let found = chosen.map(|index| &mut routes[index]);
103
+ let route = found.ok_or_else(|| Error::thrown(format!("no mock for {} {}", request.method, path)))?;
104
+ route.calls.push(request.clone());
105
+ if route.answers.is_empty() {
106
+ return Err(Error::thrown(format!("mock for {} {} has no answer", route.method, route.template)));
107
+ }
108
+ let index = (route.calls.len() - 1).min(route.answers.len() - 1);
109
+ match &route.answers[index] {
110
+ Answer::Response(response) => Ok(response.clone()),
111
+ Answer::Error(error) => Err(error.clone()),
112
+ }
113
+ }
114
+ }
115
+
116
+ impl MockRoute {
117
+ fn with_route<T>(&self, change: impl FnOnce(&mut Route) -> T) -> T {
118
+ let mut routes = self.transport.routes.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
119
+ change(&mut routes[self.index])
120
+ }
121
+
122
+ /// Adds an answer with a raw body; answers are used in order and the last one repeats.
123
+ pub fn reply(&self, status: u16, body: Vec<u8>, headers: Vec<(String, String)>) -> &MockRoute {
124
+ self.with_route(|route| route.answers.push(Answer::Response(Response::new(status, headers, body))));
125
+ self
126
+ }
127
+
128
+ /// Adds an answer with a JSON body.
129
+ pub fn reply_json(&self, status: u16, value: &Json) -> &MockRoute {
130
+ self.reply(status, value.to_json_string().into_bytes(), vec![("content-type".to_string(), "application/json".to_string())])
131
+ }
132
+
133
+ /// Makes the call fail without a response.
134
+ pub fn reply_error(&self, error: Error) -> &MockRoute {
135
+ self.with_route(|route| route.answers.push(Answer::Error(error)));
136
+ self
137
+ }
138
+
139
+ /// The requests this route answered.
140
+ pub fn calls(&self) -> Vec<Request> {
141
+ self.with_route(|route| route.calls.clone())
142
+ }
143
+
144
+ fn narrow(&self, predicate: Predicate) -> MockRoute {
145
+ let (method, template) = self.with_route(|route| (route.method.clone(), route.template.clone()));
146
+ self.transport.route(&method, &template, Some(predicate))
147
+ }
148
+ }
149
+
150
+ // @end
151
+
152
+ // @block testing.operation_mock
153
+ // @summary A typed mock for one operation: returns() turns values into their wire form and checks them against the response type, fails() and raises() simulate errors, calls() records requests.
154
+ // @versions >=1.70
155
+ // @source [1] https://doc.rust-lang.org/std/sync/struct.Arc.html
156
+ // @quote [1] "A thread-safe reference-counting pointer."
157
+ // @retrieved 2026-12-05
158
+ // @tests tests/testing.rs
159
+ // @requirement SDKL-MOCK-002
160
+
161
+ /// Decodes a JSON value at a path into T; generated per model.
162
+ pub type DecodeFn<T> = fn(&Json, &str) -> Result<T, DecodeError>;
163
+
164
+ /// Mocks one operation whose result is T.
165
+ pub struct OperationMock<T> {
166
+ pub name: &'static str,
167
+ route: MockRoute,
168
+ decode: Option<DecodeFn<T>>,
169
+ encode: Option<fn(&T) -> Json>,
170
+ }
171
+
172
+ impl<T> OperationMock<T> {
173
+ /// Used by generated mocks: decode checks values given to returns(), encode writes them (with a union tag, say).
174
+ pub fn new(name: &'static str, route: MockRoute, decode: Option<DecodeFn<T>>, encode: Option<fn(&T) -> Json>) -> OperationMock<T> {
175
+ OperationMock { name, route, decode, encode }
176
+ }
177
+
178
+ /// Answers with a success; the value is checked against the operation's response type first.
179
+ pub fn returns(&self, value: T) -> &Self {
180
+ match self.encode {
181
+ None => {
182
+ self.route.reply(200, Vec::new(), Vec::new());
183
+ }
184
+ Some(encode) => {
185
+ let wire = encode(&value);
186
+ if let Some(decode) = self.decode {
187
+ if let Err(error) = decode(&wire, "$") {
188
+ panic!("{} mock: {}: {}", self.name, error.path, error.message);
189
+ }
190
+ }
191
+ self.route.reply_json(200, &wire);
192
+ }
193
+ }
194
+ self
195
+ }
196
+
197
+ /// Answers with raw bytes, for operations that return bytes.
198
+ pub fn returns_bytes(&self, body: Vec<u8>) -> &Self {
199
+ self.route.reply(200, body, Vec::new());
200
+ self
201
+ }
202
+
203
+ /// Answers an event stream with these events. Each data is checked and written as JSON; a stream without a decoder
204
+ /// (string data) writes the text as it is.
205
+ pub fn emits(&self, events: Vec<ServerSentEvent<T>>) -> &Self {
206
+ let written: Vec<ServerSentEvent<String>> = events
207
+ .iter()
208
+ .map(|event| {
209
+ let wire = self.encode.map(|encode| encode(&event.data)).unwrap_or(Json::Null);
210
+ let data = match (self.decode, &wire) {
211
+ (None, Json::String(text)) => text.clone(),
212
+ (Some(decode), _) => {
213
+ if let Err(error) = decode(&wire, "$") {
214
+ panic!("{} mock: {}: {}", self.name, error.path, error.message);
215
+ }
216
+ wire.to_json_string()
217
+ }
218
+ (None, _) => wire.to_json_string(),
219
+ };
220
+ ServerSentEvent { event: event.event.clone(), id: event.id.clone(), data }
221
+ })
222
+ .collect();
223
+ self.route.reply(200, encode_events(&written).into_bytes(), vec![("content-type".to_string(), "text/event-stream".to_string())]);
224
+ self
225
+ }
226
+
227
+ /// Answers with an empty success, for operations without a result.
228
+ pub fn returns_nothing(&self) -> &Self {
229
+ self.route.reply(200, Vec::new(), Vec::new());
230
+ self
231
+ }
232
+
233
+ /// Answers with an HTTP error status and an optional JSON body.
234
+ pub fn fails(&self, status: u16, body: Option<Json>) -> &Self {
235
+ match body {
236
+ Some(value) => self.route.reply_json(status, &value),
237
+ None => self.route.reply(status, Vec::new(), Vec::new()),
238
+ };
239
+ self
240
+ }
241
+
242
+ /// Makes the call fail without a response, e.g. a network error.
243
+ pub fn raises(&self, error: Error) -> &Self {
244
+ self.route.reply_error(error);
245
+ self
246
+ }
247
+
248
+ /// Reads naturally between answers: mock.get_payment.fails(503, None).then().returns(value).
249
+ pub fn then(&self) -> &Self {
250
+ self
251
+ }
252
+
253
+ /// A mock for the same operation that only answers requests matching predicate.
254
+ pub fn when(&self, predicate: impl Fn(&Request) -> bool + Send + Sync + 'static) -> OperationMock<T> {
255
+ OperationMock { name: self.name, route: self.route.narrow(Arc::new(predicate)), decode: self.decode, encode: self.encode }
256
+ }
257
+
258
+ /// The requests this operation received.
259
+ pub fn calls(&self) -> Vec<Request> {
260
+ self.route.calls()
261
+ }
262
+ }
263
+
264
+ // @end
265
+
266
+ // @block testing.fake_clock
267
+ // @summary A clock for tests that moves only when slept or advanced, so retries and expiries run instantly.
268
+ // @versions >=1.70
269
+ // @source [1] https://doc.rust-lang.org/std/thread/fn.sleep.html
270
+ // @quote [1] "Puts the current thread to sleep for at least the specified amount of time."
271
+ // @retrieved 2026-12-05
272
+ // @tests tests/testing.rs
273
+ // @requirement SDKL-MOCK-002
274
+
275
+ /// Moves only when slept or advanced. Thread-safe.
276
+ #[derive(Default)]
277
+ pub struct FakeClock {
278
+ now: Mutex<i64>,
279
+ }
280
+
281
+ impl FakeClock {
282
+ pub fn new(start: i64) -> Arc<FakeClock> {
283
+ Arc::new(FakeClock { now: Mutex::new(start) })
284
+ }
285
+
286
+ pub fn advance(&self, ms: i64) {
287
+ *self.now.lock().unwrap_or_else(|poisoned| poisoned.into_inner()) += ms;
288
+ }
289
+ }
290
+
291
+ impl Clock for FakeClock {
292
+ fn now(&self) -> i64 {
293
+ *self.now.lock().unwrap_or_else(|poisoned| poisoned.into_inner())
294
+ }
295
+
296
+ fn sleep(&self, ms: i64) {
297
+ self.advance(ms);
298
+ }
299
+ }
300
+
301
+ /// One event a mock client recorded.
302
+ #[derive(Clone, Debug, PartialEq)]
303
+ pub struct RecordedEvent {
304
+ pub name: String,
305
+ pub fields: Json,
306
+ }
307
+
308
+ // @end