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,296 @@
1
+ // sdkloom Rust kit: JavaScript semantics that transpiled middleware relies on.
2
+
3
+ use super::errors::Error;
4
+ use super::http::path_segment;
5
+ use super::json::{number_string, Json};
6
+
7
+ // @block lang.js
8
+ // @summary String(value), Number(text), btoa(text), encodeURIComponent(text), ===, /, **, the % remainder, error.message and JSON field reads with JavaScript's results, so transpiled middleware behaves like its TypeScript source.
9
+ // @versions >=1.70
10
+ // @source [1] https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-tostring
11
+ // @quote [1] "The abstract operation Number::toString takes arguments x (a Number) and radix (an integer in the inclusive interval from 2 to 36) and returns a String."
12
+ // @source [2] https://tc39.es/ecma262/multipage/abstract-operations.html#sec-stringtonumber
13
+ // @quote [2] "The abstract operation StringToNumber specifies how to convert a String value to a Number value, using the following grammar."
14
+ // @source [3] https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-remainder
15
+ // @quote [3] "The sign of the result is the sign of the dividend."
16
+ // @source [4] https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa
17
+ // @quote [4] "The string contained a character that did not fit in a single byte."
18
+ // @retrieved 2026-12-05
19
+ // @tests tests/lang.rs
20
+ // @requirement SDKL-XPILE-001
21
+
22
+ impl From<i64> for Json {
23
+ fn from(value: i64) -> Json {
24
+ Json::int(value)
25
+ }
26
+ }
27
+
28
+ impl From<f64> for Json {
29
+ /// A non-finite number keeps its text ("NaN", "Infinity") so String() still prints it.
30
+ fn from(value: f64) -> Json {
31
+ Json::Number(number_string(value))
32
+ }
33
+ }
34
+
35
+ impl From<bool> for Json {
36
+ fn from(value: bool) -> Json {
37
+ Json::Bool(value)
38
+ }
39
+ }
40
+
41
+ impl From<&str> for Json {
42
+ fn from(value: &str) -> Json {
43
+ Json::String(value.to_string())
44
+ }
45
+ }
46
+
47
+ impl From<String> for Json {
48
+ fn from(value: String) -> Json {
49
+ Json::String(value)
50
+ }
51
+ }
52
+
53
+ impl From<Vec<Json>> for Json {
54
+ fn from(value: Vec<Json>) -> Json {
55
+ Json::Array(value)
56
+ }
57
+ }
58
+
59
+ impl From<Option<String>> for Json {
60
+ fn from(value: Option<String>) -> Json {
61
+ value.map(Json::String).unwrap_or(Json::Null)
62
+ }
63
+ }
64
+
65
+ /// String(value). Absent values (null) become "null", arrays join with commas, objects are "[object Object]".
66
+ pub fn js_str(value: &Json) -> String {
67
+ match value {
68
+ Json::Null => "null".to_string(),
69
+ Json::Bool(flag) => flag.to_string(),
70
+ Json::String(text) => text.clone(),
71
+ Json::Number(text) => match text.parse::<i64>() {
72
+ Ok(integer) if !text.contains(['.', 'e', 'E']) => integer.to_string(),
73
+ _ => match text.parse::<f64>() {
74
+ Ok(number) => number_string(number),
75
+ Err(_) => text.clone(),
76
+ },
77
+ },
78
+ Json::Array(items) => items.iter().map(|item| if item.is_null() { String::new() } else { js_str(item) }).collect::<Vec<_>>().join(","),
79
+ Json::Object(_) => "[object Object]".to_string(),
80
+ }
81
+ }
82
+
83
+ /// What String.prototype.trim removes: white space and line terminators, including no-break space and BOM.
84
+ fn js_space(c: char) -> bool {
85
+ matches!(c, '\t' | '\n' | '\u{b}' | '\u{c}' | '\r' | ' ' | '\u{a0}' | '\u{1680}' | '\u{2028}' | '\u{2029}' | '\u{202f}' | '\u{205f}' | '\u{3000}' | '\u{feff}') || ('\u{2000}'..='\u{200a}').contains(&c)
86
+ }
87
+
88
+ /// Number(text): trimmed, "" is 0, hex is allowed, anything else is NaN.
89
+ pub fn js_number(text: &str) -> f64 {
90
+ let trimmed = text.trim_matches(js_space);
91
+ if trimmed.is_empty() {
92
+ return 0.0;
93
+ }
94
+ if let Some(hex) = trimmed.strip_prefix("0x").or_else(|| trimmed.strip_prefix("0X")) {
95
+ return if !hex.is_empty() && hex.bytes().all(|b| b.is_ascii_hexdigit()) { u64::from_str_radix(hex, 16).map(|v| v as f64).unwrap_or(f64::INFINITY) } else { f64::NAN };
96
+ }
97
+ match trimmed {
98
+ "Infinity" | "+Infinity" => return f64::INFINITY,
99
+ "-Infinity" => return f64::NEG_INFINITY,
100
+ _ => {}
101
+ }
102
+ let body = trimmed.strip_prefix(['+', '-']).unwrap_or(trimmed);
103
+ let (mantissa, exponent) = body.split_once(['e', 'E']).unwrap_or((body, ""));
104
+ let exponent_ok = exponent.is_empty() && !body.contains(['e', 'E']) || {
105
+ let digits = exponent.strip_prefix(['+', '-']).unwrap_or(exponent);
106
+ !digits.is_empty() && digits.bytes().all(|b| b.is_ascii_digit())
107
+ };
108
+ let (whole, fraction) = mantissa.split_once('.').unwrap_or((mantissa, ""));
109
+ let mantissa_ok = (!whole.is_empty() || !fraction.is_empty()) && whole.bytes().all(|b| b.is_ascii_digit()) && fraction.bytes().all(|b| b.is_ascii_digit());
110
+ if !mantissa_ok || !exponent_ok {
111
+ return f64::NAN;
112
+ }
113
+ trimmed.parse::<f64>().unwrap_or(f64::NAN)
114
+ }
115
+
116
+ /// Math.random(): a number in [0, 1). The standard library has no random numbers, so this is a xorshift generator
117
+ /// seeded from the clock and a counter; good enough for jitter, not for secrets.
118
+ pub fn js_random() -> f64 {
119
+ use std::sync::atomic::{AtomicU64, Ordering};
120
+ static STATE: AtomicU64 = AtomicU64::new(0);
121
+ let step = |mut x: u64| {
122
+ if x == 0 {
123
+ x = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_nanos() as u64).unwrap_or(0x9E37_79B9_7F4A_7C15) | 1;
124
+ }
125
+ x ^= x << 13;
126
+ x ^= x >> 7;
127
+ x ^= x << 17;
128
+ x
129
+ };
130
+ // One atomic update, so two threads never draw the same number.
131
+ let mut current = STATE.load(Ordering::Relaxed);
132
+ loop {
133
+ let next = step(current);
134
+ match STATE.compare_exchange_weak(current, next, Ordering::Relaxed, Ordering::Relaxed) {
135
+ Ok(_) => return (next >> 11) as f64 / (1u64 << 53) as f64,
136
+ Err(actual) => current = actual,
137
+ }
138
+ }
139
+ }
140
+
141
+ /// a % b for integers: the result takes the sign of the dividend; % 0 fails.
142
+ pub fn js_rem(left: i64, right: i64) -> Result<i64, Error> {
143
+ left.checked_rem(right).ok_or_else(|| Error::thrown("division by zero"))
144
+ }
145
+
146
+ /// encodeURIComponent(text): letters, digits and - _ . ! ~ * ' ( ) stay; everything else is UTF-8 percent-encoded.
147
+ pub fn js_encode_uri_component(text: &str) -> String {
148
+ path_segment(text)
149
+ }
150
+
151
+ /// btoa(text): Base64 of a string whose characters each fit in one byte.
152
+ pub fn js_btoa(text: &str) -> Result<String, Error> {
153
+ const ALPHABET: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
154
+ let mut bytes = Vec::new();
155
+ for c in text.chars() {
156
+ let code = c as u32;
157
+ if code > 0xFF {
158
+ return Err(Error::thrown("InvalidCharacterError: the string contains a character that does not fit in a single byte"));
159
+ }
160
+ bytes.push(code as u8);
161
+ }
162
+ let mut out = String::new();
163
+ for chunk in bytes.chunks(3) {
164
+ let n = (u32::from(chunk[0]) << 16) | (u32::from(*chunk.get(1).unwrap_or(&0)) << 8) | u32::from(*chunk.get(2).unwrap_or(&0));
165
+ out.push(ALPHABET[(n >> 18) as usize & 63] as char);
166
+ out.push(ALPHABET[(n >> 12) as usize & 63] as char);
167
+ out.push(if chunk.len() > 1 { ALPHABET[(n >> 6) as usize & 63] as char } else { '=' });
168
+ out.push(if chunk.len() > 2 { ALPHABET[n as usize & 63] as char } else { '=' });
169
+ }
170
+ Ok(out)
171
+ }
172
+
173
+ /// left === right on JSON values: numbers compare by value, booleans never equal numbers, null equals null.
174
+ pub fn js_same(left: &Json, right: &Json) -> bool {
175
+ match (left, right) {
176
+ (Json::Number(_), Json::Number(_)) => left.as_f64() == right.as_f64(),
177
+ _ => left == right,
178
+ }
179
+ }
180
+
181
+ /// left / right with IEEE results.
182
+ pub fn js_div(left: f64, right: f64) -> f64 {
183
+ left / right
184
+ }
185
+
186
+ /// base ** exponent as JavaScript computes it.
187
+ pub fn js_pow(base: f64, exponent: f64) -> f64 {
188
+ if exponent.is_nan() || (base.abs() == 1.0 && exponent.is_infinite()) {
189
+ f64::NAN
190
+ } else {
191
+ base.powf(exponent)
192
+ }
193
+ }
194
+
195
+ /// value.name for a JSON value: a missing field is null; reading from null fails like JavaScript.
196
+ pub fn js_get(value: &Json, name: &str) -> Result<Json, Error> {
197
+ match value {
198
+ Json::Null => Err(Error::thrown(format!("Cannot read properties of null (reading '{}')", name))),
199
+ Json::Object(_) => Ok(value.get(name).cloned().unwrap_or(Json::Null)),
200
+ _ => Ok(Json::Null),
201
+ }
202
+ }
203
+
204
+ /// error.message.
205
+ pub fn js_message(error: &Error) -> String {
206
+ error.to_string()
207
+ }
208
+
209
+ fn type_error(expected: &str, value: &Json) -> Error {
210
+ Error::thrown(format!("TypeError: expected {}, got {}", expected, value.to_json_string()))
211
+ }
212
+
213
+ /// A value that must be an integer (a config field, a JSON number).
214
+ pub fn to_i64(value: &Json) -> Result<i64, Error> {
215
+ value.as_i64().ok_or_else(|| type_error("an integer", value))
216
+ }
217
+
218
+ pub fn to_f64(value: &Json) -> Result<f64, Error> {
219
+ value.as_f64().ok_or_else(|| type_error("a number", value))
220
+ }
221
+
222
+ pub fn to_string(value: &Json) -> Result<String, Error> {
223
+ value.as_str().map(str::to_string).ok_or_else(|| type_error("a string", value))
224
+ }
225
+
226
+ pub fn to_bool(value: &Json) -> Result<bool, Error> {
227
+ value.as_bool().ok_or_else(|| type_error("a boolean", value))
228
+ }
229
+
230
+ /// A value that must be a JSON object.
231
+ pub fn to_object(value: &Json) -> Result<Json, Error> {
232
+ match value {
233
+ Json::Object(_) => Ok(value.clone()),
234
+ _ => Err(type_error("an object", value)),
235
+ }
236
+ }
237
+
238
+ /// `for (const item of list)`.
239
+ pub fn to_list(value: &Json) -> Result<Vec<Json>, Error> {
240
+ match value {
241
+ Json::Array(items) => Ok(items.clone()),
242
+ Json::Null => Err(Error::thrown("TypeError: null is not iterable")),
243
+ _ => Err(type_error("an array", value)),
244
+ }
245
+ }
246
+
247
+ // @end
248
+
249
+ // @block middleware.helpers
250
+ // @summary js_random_uuid makes a version 4 UUID from /dev/urandom where it exists, else from SipHash keyed by the standard library's random per-process keys (not for secrets); the HMAC helpers sign UTF-8 text with a UTF-8 key, in hex or Base64.
251
+ // @versions >=1.70
252
+ // @source [1] https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html
253
+ // @quote [1] "A particular instance RandomState will create the same instances of Hasher, but the hashers created by two different RandomState instances are unlikely to produce the same result for the same values."
254
+ // @source [2] https://www.rfc-editor.org/rfc/rfc9562#section-5.4
255
+ // @quote [2] "UUIDv4 is meant for generating UUIDs from truly random or pseudorandom numbers."
256
+ // @retrieved 2026-12-06
257
+ // @tests tests/lang.rs
258
+ // @requirement SDKL-HELP-001
259
+
260
+ fn random_bytes() -> [u8; 16] {
261
+ use std::io::Read;
262
+ let mut bytes = [0u8; 16];
263
+ if std::fs::File::open("/dev/urandom").and_then(|mut file| file.read_exact(&mut bytes)).is_ok() {
264
+ return bytes;
265
+ }
266
+ use std::hash::{BuildHasher, Hasher};
267
+ static COUNTER: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
268
+ for half in 0..2 {
269
+ let mut hasher = std::collections::hash_map::RandomState::new().build_hasher();
270
+ hasher.write_u64(COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed));
271
+ hasher.write_u128(std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|elapsed| elapsed.as_nanos()).unwrap_or(0));
272
+ bytes[half * 8..half * 8 + 8].copy_from_slice(&hasher.finish().to_be_bytes());
273
+ }
274
+ bytes
275
+ }
276
+
277
+ /// randomUUID(): a random version 4 UUID in lower case.
278
+ pub fn js_random_uuid() -> String {
279
+ let mut bytes = random_bytes();
280
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
281
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
282
+ let text = super::webhooks::hex(&bytes);
283
+ format!("{}-{}-{}-{}-{}", &text[..8], &text[8..12], &text[12..16], &text[16..20], &text[20..])
284
+ }
285
+
286
+ /// hmacSha256Hex(key, text): HMAC-SHA256 of UTF-8 text with a UTF-8 key, in lower-case hex.
287
+ pub fn js_hmac_sha256_hex(key: &str, text: &str) -> String {
288
+ super::webhooks::hex(&super::crypto::hmac_sha256(key.as_bytes(), text.as_bytes()))
289
+ }
290
+
291
+ /// hmacSha256Base64(key, text): HMAC-SHA256 of UTF-8 text with a UTF-8 key, in Base64.
292
+ pub fn js_hmac_sha256_base64(key: &str, text: &str) -> String {
293
+ super::webhooks::base64_encode(&super::crypto::hmac_sha256(key.as_bytes(), text.as_bytes()))
294
+ }
295
+
296
+ // @end
@@ -0,0 +1,30 @@
1
+ //! sdkloom Rust kit: the runtime vendored into every generated Rust SDK. Standard library only.
2
+
3
+ pub mod client;
4
+ pub mod context;
5
+ pub mod crypto;
6
+ pub mod errors;
7
+ pub mod http;
8
+ pub mod json;
9
+ pub mod lang;
10
+ pub mod models;
11
+ pub mod multipart;
12
+ pub mod pagination;
13
+ pub mod sse;
14
+ pub mod testing;
15
+ pub mod transport;
16
+ pub mod wait;
17
+ pub mod webhooks;
18
+
19
+ pub use client::{call, entry, ApiVersion, Args, CallOptions, Kind, Middleware, MiddlewareEntry, Next, OperationSpec, RawResult, Runtime};
20
+ pub use context::{Clock, Context, EventListener, OperationInfo, SdkInfo, State, SystemClock};
21
+ pub use errors::{ApiError, DecodeError, Error, ErrorFactory, TransportError};
22
+ pub use http::{BodyStream, Request, Response};
23
+ pub use json::Json;
24
+ pub use models::{Decimal, ToJson};
25
+ pub use multipart::MultipartForm;
26
+ pub use pagination::{next_link, resolve_url, Pager};
27
+ pub use sse::{EventStream, ServerSentEvent};
28
+ pub use testing::{DecodeFn, FakeClock, MockRoute, MockTransport, OperationMock, RecordedEvent};
29
+ pub use transport::{SendOptions, StdTransport, Transport};
30
+ pub use webhooks::{verify_webhook, WebhookSignature};
@@ -0,0 +1,266 @@
1
+ // sdkloom Rust kit: decoding JSON into typed values and writing them back.
2
+
3
+ use super::errors::DecodeError;
4
+ use super::json::Json;
5
+ use std::collections::BTreeMap;
6
+
7
+ // @block models.decode
8
+ // @summary Checks decoded JSON against the expected type; keeps object fields and enum values it does not know. Absent optional fields are None, null is None for nullable ones; optional and nullable together is Option<Option<T>>. Null for an optional field that cannot be null reads as absent: many servers send null for a field they leave out.
9
+ // @versions >=1.70
10
+ // @source [1] https://www.rfc-editor.org/rfc/rfc8259#section-4
11
+ // @quote [1] "An object structure is represented as a pair of curly brackets surrounding zero or more name/value pairs (or members)."
12
+ // @source [2] https://doc.rust-lang.org/std/option/index.html
13
+ // @quote [2] "Type Option represents an optional value: every Option is either Some and contains a value, or None, and does not."
14
+ // @retrieved 2026-12-05
15
+ // @tests tests/json.rs
16
+ // @requirement SDKL-JSON-001
17
+ // @requirement SDKL-JSON-002
18
+ // @requirement SDKL-JSON-003
19
+
20
+ /// An exact decimal number in plain notation, e.g. "10.50". It travels as a JSON string.
21
+ #[derive(Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
22
+ pub struct Decimal(pub String);
23
+
24
+ impl Decimal {
25
+ pub fn new(text: &str) -> Decimal {
26
+ Decimal(text.to_string())
27
+ }
28
+ }
29
+
30
+ fn describe(value: &Json) -> String {
31
+ match value {
32
+ Json::Null => "null".to_string(),
33
+ Json::Bool(flag) => format!("boolean {}", flag),
34
+ Json::String(_) => format!("string {}", value.to_json_string()),
35
+ Json::Number(text) => format!("number {}", text),
36
+ Json::Array(_) => "array".to_string(),
37
+ Json::Object(_) => "object".to_string(),
38
+ }
39
+ }
40
+
41
+ fn mismatch(path: &str, expected: &str, value: &Json) -> DecodeError {
42
+ DecodeError::new(path, &format!("expected {}, got {}", expected, describe(value)))
43
+ }
44
+
45
+ pub fn as_object<'a>(value: &'a Json, path: &str) -> Result<&'a Vec<(String, Json)>, DecodeError> {
46
+ match value {
47
+ Json::Object(fields) => Ok(fields),
48
+ _ => Err(mismatch(path, "an object", value)),
49
+ }
50
+ }
51
+
52
+ pub fn as_string(value: &Json, path: &str) -> Result<String, DecodeError> {
53
+ value.as_str().map(str::to_string).ok_or_else(|| mismatch(path, "a string", value))
54
+ }
55
+
56
+ /// Any string, so a value the server adds later does not break the SDK.
57
+ pub fn as_enum(value: &Json, path: &str, known: &[&str]) -> Result<String, DecodeError> {
58
+ value.as_str().map(str::to_string).ok_or_else(|| mismatch(path, &format!("one of {}", known.join(", ")), value))
59
+ }
60
+
61
+ pub fn as_boolean(value: &Json, path: &str) -> Result<bool, DecodeError> {
62
+ value.as_bool().ok_or_else(|| mismatch(path, "a boolean", value))
63
+ }
64
+
65
+ pub fn as_number(value: &Json, path: &str) -> Result<f64, DecodeError> {
66
+ value.as_f64().ok_or_else(|| mismatch(path, "a number", value))
67
+ }
68
+
69
+ /// A number without a fraction (2.0 included) that fits in 64 bits.
70
+ pub fn as_integer(value: &Json, path: &str) -> Result<i64, DecodeError> {
71
+ value.as_i64().ok_or_else(|| mismatch(path, "an integer", value))
72
+ }
73
+
74
+ fn is_decimal_text(text: &str) -> bool {
75
+ let digits = text.strip_prefix('-').unwrap_or(text);
76
+ let (whole, fraction) = digits.split_once('.').unwrap_or((digits, "0"));
77
+ !whole.is_empty() && !fraction.is_empty() && whole.bytes().all(|b| b.is_ascii_digit()) && fraction.bytes().all(|b| b.is_ascii_digit())
78
+ }
79
+
80
+ /// Exponents a decimal may have: beyond this, writing the number out would take unbounded memory.
81
+ const MAX_DECIMAL_EXPONENT: i64 = 400;
82
+
83
+ /// "1E+3" → "1000", "1.5e-2" → "0.015": exponent notation written out, digit for digit. Exponents are bounded by the
84
+ /// caller (as_decimal).
85
+ pub fn plain_number(text: &str) -> String {
86
+ let (mantissa, exponent) = match text.find(['e', 'E']) {
87
+ Some(index) => (&text[..index], text[index + 1..].parse::<i64>().unwrap_or(0)),
88
+ None => (text, 0),
89
+ };
90
+ let negative = mantissa.starts_with('-');
91
+ let mantissa = mantissa.trim_start_matches('-');
92
+ let (whole, fraction) = mantissa.split_once('.').unwrap_or((mantissa, ""));
93
+ let mut digits = format!("{}{}", whole, fraction);
94
+ let mut point = whole.len() as i64 + exponent;
95
+ if point <= 0 {
96
+ digits = format!("{}{}", "0".repeat((1 - point) as usize), digits);
97
+ point = 1;
98
+ }
99
+ if point as usize > digits.len() {
100
+ digits.push_str(&"0".repeat(point as usize - digits.len()));
101
+ }
102
+ let (head, rest) = digits.split_at(point as usize);
103
+ let mut result = head.trim_start_matches('0').to_string();
104
+ if result.is_empty() {
105
+ result.push('0');
106
+ }
107
+ if !rest.is_empty() {
108
+ result.push('.');
109
+ result.push_str(rest);
110
+ }
111
+ if negative && result.chars().any(|c| c != '0' && c != '.') {
112
+ result.insert(0, '-');
113
+ }
114
+ result
115
+ }
116
+
117
+ fn exponent_of(text: &str) -> i64 {
118
+ text.find(['e', 'E']).map(|index| text[index + 1..].parse::<i64>().unwrap_or(i64::MAX)).unwrap_or(0)
119
+ }
120
+
121
+ /// A decimal string ("10.50") or a JSON number; every digit is kept.
122
+ pub fn as_decimal(value: &Json, path: &str) -> Result<Decimal, DecodeError> {
123
+ match value {
124
+ Json::String(text) if is_decimal_text(text) => Ok(Decimal(text.clone())),
125
+ Json::Number(text) if exponent_of(text).abs() <= MAX_DECIMAL_EXPONENT => Ok(Decimal(plain_number(text))),
126
+ _ => Err(mismatch(path, "a decimal", value)),
127
+ }
128
+ }
129
+
130
+ pub fn as_list<T>(value: &Json, path: &str, item: impl Fn(&Json, &str) -> Result<T, DecodeError>) -> Result<Vec<T>, DecodeError> {
131
+ match value {
132
+ Json::Array(items) => items.iter().enumerate().map(|(index, entry)| item(entry, &format!("{}[{}]", path, index))).collect(),
133
+ _ => Err(mismatch(path, "an array", value)),
134
+ }
135
+ }
136
+
137
+ pub fn as_map<T>(value: &Json, path: &str, item: impl Fn(&Json, &str) -> Result<T, DecodeError>) -> Result<BTreeMap<String, T>, DecodeError> {
138
+ as_object(value, path)?.iter().map(|(key, entry)| Ok((key.clone(), item(entry, &format!("{}.{}", path, key))?))).collect()
139
+ }
140
+
141
+ /// null as None, anything else decoded.
142
+ pub fn nullable<T>(value: &Json, path: &str, item: impl Fn(&Json, &str) -> Result<T, DecodeError>) -> Result<Option<T>, DecodeError> {
143
+ if value.is_null() {
144
+ Ok(None)
145
+ } else {
146
+ item(value, path).map(Some)
147
+ }
148
+ }
149
+
150
+ /// A field that must be present.
151
+ pub fn required<T>(object: &Json, name: &str, path: &str, decode: impl Fn(&Json, &str) -> Result<T, DecodeError>) -> Result<T, DecodeError> {
152
+ let at = format!("{}.{}", path, name);
153
+ match object.get(name) {
154
+ Some(value) => decode(value, &at),
155
+ None => Err(DecodeError::new(&at, "is required")),
156
+ }
157
+ }
158
+
159
+ /// A field that may be absent.
160
+ /// Many servers send null for a field they leave out: null that the decoder does not accept (the field cannot be null)
161
+ /// reads as absent.
162
+ pub fn optional<T>(object: &Json, name: &str, path: &str, decode: impl Fn(&Json, &str) -> Result<T, DecodeError>) -> Result<Option<T>, DecodeError> {
163
+ match object.get(name) {
164
+ Some(Json::Null) => Ok(decode(&Json::Null, &format!("{}.{}", path, name)).ok()),
165
+ Some(value) => decode(value, &format!("{}.{}", path, name)).map(Some),
166
+ None => Ok(None),
167
+ }
168
+ }
169
+
170
+ /// The fields the SDK does not know, kept so they can be sent back unchanged.
171
+ pub fn extra(object: &Json, known: &[&str]) -> Vec<(String, Json)> {
172
+ match object {
173
+ Json::Object(fields) => fields.iter().filter(|(key, _)| !known.contains(&key.as_str())).cloned().collect(),
174
+ _ => Vec::new(),
175
+ }
176
+ }
177
+
178
+ // @end
179
+
180
+ // @block models.encode
181
+ // @summary The JSON form of typed values: models implement ToJson, decimals become strings, None is null, numbers are written like JavaScript.
182
+ // @versions >=1.70
183
+ // @source [1] https://doc.rust-lang.org/std/fmt/trait.LowerExp.html
184
+ // @quote [1] "e formatting."
185
+ // @retrieved 2026-12-05
186
+ // @tests tests/json.rs
187
+ // @requirement SDKL-JSON-004
188
+
189
+ /// The JSON form of a value; every generated model implements it.
190
+ pub trait ToJson {
191
+ fn to_json(&self) -> Json;
192
+ }
193
+
194
+ impl ToJson for Json {
195
+ fn to_json(&self) -> Json {
196
+ self.clone()
197
+ }
198
+ }
199
+
200
+ impl ToJson for String {
201
+ fn to_json(&self) -> Json {
202
+ Json::String(self.clone())
203
+ }
204
+ }
205
+
206
+ impl ToJson for str {
207
+ fn to_json(&self) -> Json {
208
+ Json::String(self.to_string())
209
+ }
210
+ }
211
+
212
+ impl ToJson for i64 {
213
+ fn to_json(&self) -> Json {
214
+ Json::int(*self)
215
+ }
216
+ }
217
+
218
+ impl ToJson for f64 {
219
+ fn to_json(&self) -> Json {
220
+ Json::float(*self)
221
+ }
222
+ }
223
+
224
+ impl ToJson for bool {
225
+ fn to_json(&self) -> Json {
226
+ Json::Bool(*self)
227
+ }
228
+ }
229
+
230
+ impl ToJson for Decimal {
231
+ fn to_json(&self) -> Json {
232
+ Json::String(self.0.clone())
233
+ }
234
+ }
235
+
236
+ impl<T: ToJson> ToJson for Vec<T> {
237
+ fn to_json(&self) -> Json {
238
+ Json::Array(self.iter().map(ToJson::to_json).collect())
239
+ }
240
+ }
241
+
242
+ impl<T: ToJson> ToJson for BTreeMap<String, T> {
243
+ fn to_json(&self) -> Json {
244
+ Json::Object(self.iter().map(|(key, value)| (key.clone(), value.to_json())).collect())
245
+ }
246
+ }
247
+
248
+ impl<T: ToJson> ToJson for Option<T> {
249
+ fn to_json(&self) -> Json {
250
+ self.as_ref().map(ToJson::to_json).unwrap_or(Json::Null)
251
+ }
252
+ }
253
+
254
+ impl<T: ToJson + ?Sized> ToJson for Box<T> {
255
+ fn to_json(&self) -> Json {
256
+ (**self).to_json()
257
+ }
258
+ }
259
+
260
+ impl<T: ToJson + ?Sized> ToJson for &T {
261
+ fn to_json(&self) -> Json {
262
+ (**self).to_json()
263
+ }
264
+ }
265
+
266
+ // @end
@@ -0,0 +1,81 @@
1
+ // sdkloom Rust kit: multipart/form-data request bodies.
2
+
3
+ // @block http.multipart
4
+ // @summary A multipart/form-data body (RFC 7578) built from text fields and files, immutable; encoded with a random boundary, one part per field with a Content-Disposition naming it (and the file name for files), quotes and line breaks in names percent-encoded.
5
+ // @versions >=1.70
6
+ // @source [1] https://www.rfc-editor.org/rfc/rfc7578#section-4.2
7
+ // @quote [1] "Each part MUST contain a Content-Disposition header field"
8
+ // @source [2] https://www.rfc-editor.org/rfc/rfc7578#section-4.1
9
+ // @quote [2] "As with other multipart types, the parts are delimited with a boundary delimiter"
10
+ // @retrieved 2026-12-06
11
+ // @tests tests/multipart.rs
12
+ // @requirement SDKL-HTTP-005
13
+
14
+ /// A text field, or a file when filename is set.
15
+ #[derive(Clone, Debug, PartialEq)]
16
+ pub struct MultipartPart {
17
+ pub name: String,
18
+ pub value: Vec<u8>,
19
+ pub filename: Option<String>,
20
+ pub content_type: Option<String>,
21
+ }
22
+
23
+ /// Text fields and files in order: `MultipartForm::default().field("title", "Q4").file("report", "q4.pdf", "application/pdf", data)`.
24
+ #[derive(Clone, Debug, Default, PartialEq)]
25
+ pub struct MultipartForm {
26
+ pub parts: Vec<MultipartPart>,
27
+ }
28
+
29
+ fn quoted(text: &str) -> String {
30
+ format!("\"{}\"", text.replace('"', "%22").replace('\r', "%0D").replace('\n', "%0A"))
31
+ }
32
+
33
+ impl MultipartForm {
34
+ /// A copy with a text field added.
35
+ pub fn field(&self, name: &str, value: &str) -> MultipartForm {
36
+ self.with(MultipartPart { name: name.to_string(), value: value.as_bytes().to_vec(), filename: None, content_type: None })
37
+ }
38
+
39
+ /// A copy with a file added.
40
+ pub fn file(&self, name: &str, filename: &str, content_type: &str, data: &[u8]) -> MultipartForm {
41
+ self.with(MultipartPart { name: name.to_string(), value: data.to_vec(), filename: Some(filename.to_string()), content_type: Some(content_type.to_string()) })
42
+ }
43
+
44
+ fn with(&self, part: MultipartPart) -> MultipartForm {
45
+ let mut parts = self.parts.clone();
46
+ parts.push(part);
47
+ MultipartForm { parts }
48
+ }
49
+
50
+ /// The body for this boundary.
51
+ pub fn encode(&self, boundary: &str) -> Vec<u8> {
52
+ let mut out = Vec::new();
53
+ for part in &self.parts {
54
+ let mut head = format!("--{}\r\nContent-Disposition: form-data; name={}", boundary, quoted(&part.name));
55
+ if let Some(filename) = &part.filename {
56
+ head.push_str(&format!("; filename={}\r\nContent-Type: {}", quoted(filename), part.content_type.as_deref().unwrap_or("application/octet-stream")));
57
+ }
58
+ head.push_str("\r\n\r\n");
59
+ out.extend_from_slice(head.as_bytes());
60
+ out.extend_from_slice(&part.value);
61
+ out.extend_from_slice(b"\r\n");
62
+ }
63
+ out.extend_from_slice(format!("--{}--\r\n", boundary).as_bytes());
64
+ out
65
+ }
66
+
67
+ /// The body with a random boundary; the client reads the boundary back from its first line.
68
+ pub fn to_body(&self) -> Vec<u8> {
69
+ self.encode(&format!("sdkloom-{}", super::lang::js_random_uuid()))
70
+ }
71
+ }
72
+
73
+ /// The boundary of an encoded body: its first line without the leading "--" (and the trailing "--" of an empty form).
74
+ pub fn boundary_of(body: &[u8]) -> String {
75
+ let first = body.split(|byte| *byte == b'\r').next().unwrap_or(&[]);
76
+ let text = String::from_utf8_lossy(first);
77
+ let text = text.strip_prefix("--").unwrap_or(&text);
78
+ text.strip_suffix("--").unwrap_or(text).to_string()
79
+ }
80
+
81
+ // @end