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,192 @@
1
+ # sdkloom Python kit: HTTP request and response values, URL building.
2
+ from __future__ import absolute_import, division, unicode_literals
3
+
4
+ import re
5
+ from decimal import Decimal
6
+
7
+ from .compat import Record, json_loads, quote, quote_plus, replace, text_type, to_text
8
+ from .lang import js_str
9
+
10
+ try: # type names for annotations in generated code and type checkers; Python 2.7 has no typing module
11
+ from typing import Any, Iterator, Mapping, Optional, Sequence, Tuple, Union # noqa: F401
12
+ except ImportError: # pragma: no cover
13
+ pass
14
+
15
+ # @block http.request
16
+ # @summary An immutable HTTP request whose header names are matched case-insensitively.
17
+ # @versions >=2.7
18
+ # @source [1] https://www.rfc-editor.org/rfc/rfc9110#section-5.1
19
+ # @quote [1] "Field names are case-insensitive"
20
+ # @retrieved 2026-12-05
21
+ # @tests tests/test_http.py
22
+ # @requirement SDKL-HTTP-001
23
+ def find_header(headers, name):
24
+ # type: (Tuple[Tuple[str, str], ...], str) -> Optional[str]
25
+ key = name.lower()
26
+ for candidate, value in headers:
27
+ if candidate.lower() == key:
28
+ return value
29
+ return None
30
+
31
+
32
+ def _without_header(headers, name):
33
+ # type: (Tuple[Tuple[str, str], ...], str) -> Tuple[Tuple[str, str], ...]
34
+ key = name.lower()
35
+ return tuple(item for item in headers if item[0].lower() != key)
36
+
37
+
38
+ class HttpRequest(Record):
39
+ """method, url, headers (a tuple of (name, value) pairs) and body (bytes or None)."""
40
+
41
+ _fields = ("method", "url", "headers", "body")
42
+ _defaults = {"headers": (), "body": None}
43
+
44
+ def header(self, name):
45
+ # type: (str) -> Optional[str]
46
+ return find_header(self.headers, name)
47
+
48
+ def with_header(self, name, value):
49
+ # type: (str, str) -> HttpRequest
50
+ return replace(self, headers=_without_header(self.headers, name) + ((name, value),))
51
+
52
+ def without_header(self, name):
53
+ # type: (str) -> HttpRequest
54
+ return replace(self, headers=_without_header(self.headers, name))
55
+
56
+ def with_url(self, url):
57
+ # type: (str) -> HttpRequest
58
+ return replace(self, url=url)
59
+
60
+ def with_body(self, body):
61
+ # type: (Optional[bytes]) -> HttpRequest
62
+ return replace(self, body=body)
63
+
64
+ def text(self):
65
+ # type: () -> str
66
+ """The body as UTF-8 text, "" without one."""
67
+ return self.body.decode("utf-8") if self.body else ""
68
+
69
+ # @end
70
+
71
+ # @block http.response
72
+ # @summary A received HTTP response whose body can be read as bytes, text or JSON any number of times, or chunk by chunk as it arrives when the transport streamed it.
73
+ # @versions >=2.7
74
+ # @source [1] https://docs.python.org/3/library/json.html#json.loads
75
+ # @quote [1] "deserialize s (a str, bytes or bytearray instance containing a JSON document) to a Python object"
76
+ # @retrieved 2026-12-05
77
+ # @tests tests/test_http.py
78
+ # @requirement SDKL-HTTP-003
79
+ class HttpResponse(Record):
80
+ """status, headers (a tuple of (name, value) pairs) and body (bytes).
81
+
82
+ A streamed response (an event stream) has an empty body and its bytes in stream, an iterator of chunks that is read
83
+ once, as they arrive.
84
+ """
85
+
86
+ _fields = ("status", "headers", "body", "stream")
87
+ _defaults = {"stream": None}
88
+ _hidden = ("stream",)
89
+
90
+ def chunks(self):
91
+ # type: () -> Iterator[bytes]
92
+ """The body as it arrives: the stream's chunks, or the buffered body as one chunk."""
93
+ if self.stream is None:
94
+ return iter([self.body])
95
+ return iter(self.stream)
96
+
97
+ def header(self, name):
98
+ # type: (str) -> Optional[str]
99
+ return find_header(self.headers, name)
100
+
101
+ def text(self):
102
+ # type: () -> str
103
+ return self.body.decode("utf-8")
104
+
105
+ def json(self):
106
+ # type: () -> Any
107
+ text = self.text()
108
+ return None if text == "" else json_loads(text)
109
+ # @end
110
+
111
+ # @block http.url
112
+ # @summary Builds a request URL: percent-encodes path parameters and appends query parameters in order, exactly like the TypeScript kit. A path parameter of "." or ".." is refused with an ArgumentError: URL parsers read it as a step up the path, even percent-encoded. A {+name} placeholder (RFC 6570 reserved expansion, limited to "/") takes a value that spans segments, each encoded on its own.
113
+ # @versions >=2.7
114
+ # @source [1] https://www.rfc-editor.org/rfc/rfc3986#section-2.1
115
+ # @quote [1] "A percent-encoding mechanism is used to represent a data octet in a component when that octet's corresponding character is outside the allowed set or is being used as a delimiter of, or within, the component."
116
+ # @source [2] https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote
117
+ # @quote [2] "Replace special characters in string using the %xx escape."
118
+ # @source [3] https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode
119
+ # @quote [3] "Convert a mapping object or a sequence of two-element tuples, which may contain str or bytes objects, to a percent-encoded ASCII text string."
120
+ # @source [4] https://www.rfc-editor.org/rfc/rfc3986#section-3.3
121
+ # @quote [4] "also known as dot-segments, are defined for relative reference within the path name hierarchy."
122
+ # @source [5] https://www.rfc-editor.org/rfc/rfc6570#section-3.2.3
123
+ # @quote [5] "is identical to simple string expansion except that the substituted values may also contain pct-encoded triplets and characters in the reserved set."
124
+ # @retrieved 2026-12-05
125
+ # @tests tests/test_http.py
126
+ # @requirement SDKL-HTTP-002
127
+ _PLACEHOLDER = re.compile(r"\{([^{}]+)\}")
128
+ # Characters encodeURIComponent leaves alone in addition to Python's always-safe set.
129
+ _PATH_SAFE = "!'()*"
130
+
131
+
132
+
133
+ def scalar(value):
134
+ # type: (Union[str, int, float, bool, Decimal]) -> str
135
+ """Writes a parameter value exactly like the TypeScript and Java kits: true/false, 2 (not 2.0), 1000 (not 1E+3)."""
136
+ if isinstance(value, bool):
137
+ return "true" if value else "false"
138
+ if isinstance(value, float):
139
+ # String(number) as JavaScript writes it: 2 (not 2.0), 1e-7 (not 1e-07), the shortest digits.
140
+ return js_str(value)
141
+ if isinstance(value, Decimal):
142
+ return text_type(format(value, "f"))
143
+ return text_type(to_text(value))
144
+
145
+
146
+ def _form(text):
147
+ # type: (str) -> str
148
+ # application/x-www-form-urlencoded as browsers write it: "~" is encoded, "*" is not.
149
+ return quote_plus(text, safe="*").replace("~", "%7E")
150
+
151
+
152
+ class ArgumentError(ValueError):
153
+ """A call argument the SDK cannot send, found before any request is made."""
154
+
155
+ name = "ArgumentError"
156
+
157
+
158
+ def path_segment(name, value):
159
+ # type: (str, Any) -> str
160
+ """A path parameter as one encoded segment.
161
+
162
+ "." and ".." are refused: URL parsers treat them, even percent-encoded, as steps up the path.
163
+ """
164
+ text = scalar(value)
165
+ if text in (".", ".."):
166
+ raise ArgumentError('path parameter ' + name + ' cannot be "' + text + '": a URL would read it as a step up the path')
167
+ return quote(text, safe=_PATH_SAFE)
168
+
169
+
170
+ def build_url(base, template, path_params, query):
171
+ # type: (str, str, Mapping[str, Any], Sequence[Tuple[str, Any]]) -> str
172
+ def substitute(match):
173
+ # type: (Any) -> str
174
+ # {+name} (RFC 6570 reserved expansion, limited to "/"): the value may span segments, each encoded on its own.
175
+ reserved = match.group(1).startswith("+")
176
+ name = match.group(1)[1:] if reserved else match.group(1)
177
+ if name not in path_params:
178
+ raise ArgumentError("missing path parameter " + name)
179
+ if reserved:
180
+ return "/".join(path_segment(name, segment) for segment in scalar(path_params[name]).split("/"))
181
+ return path_segment(name, path_params[name])
182
+
183
+ path = _PLACEHOLDER.sub(substitute, template)
184
+ pairs = []
185
+ for name, value in query:
186
+ if value is None:
187
+ continue
188
+ items = value if isinstance(value, (list, tuple)) else [value]
189
+ pairs.extend(_form(name) + "=" + _form(scalar(item)) for item in items)
190
+ query_string = "&".join(pairs)
191
+ return base.rstrip("/") + path + ("?" + query_string if query_string else "")
192
+ # @end
@@ -0,0 +1,207 @@
1
+ # sdkloom Python kit: JavaScript semantics that transpiled middleware relies on.
2
+ from __future__ import absolute_import, division, unicode_literals
3
+
4
+ import base64
5
+ import binascii
6
+ import hashlib
7
+ import hmac
8
+ import math
9
+ import re
10
+ import uuid
11
+ from decimal import Decimal
12
+
13
+ from .compat import integer_types, is_text, message_of, number_text, quote, text_type, to_text
14
+
15
+ try: # type names for type checkers; Python 2.7 has no typing module
16
+ from typing import Any, Union # noqa: F401
17
+
18
+ Number = Union[int, float]
19
+ except ImportError: # pragma: no cover
20
+ pass
21
+
22
+ # math.inf and math.nan need Python 3.5.
23
+ _INF = float("inf")
24
+ _NAN = float("nan")
25
+
26
+ # @block lang.js
27
+ # @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.
28
+ # @versions >=2.7
29
+ # @source [1] https://tc39.es/ecma262/multipage/abstract-operations.html#sec-tostring
30
+ # @quote [1] "The abstract operation ToString takes argument arg (an ECMAScript language value) and returns either a normal completion containing a String or a throw completion."
31
+ # @source [2] https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-tostring
32
+ # @quote [2] "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."
33
+ # @source [3] https://tc39.es/ecma262/multipage/abstract-operations.html#sec-stringtonumber
34
+ # @quote [3] "The abstract operation StringToNumber specifies how to convert a String value to a Number value, using the following grammar."
35
+ # @source [4] https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-remainder
36
+ # @quote [4] "The sign of the result is the sign of the dividend."
37
+ # @source [5] https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa
38
+ # @quote [5] "The string contained a character that did not fit in a single byte."
39
+ # @retrieved 2026-12-05
40
+ # @tests tests/test_lang.py
41
+ # @requirement SDKL-XPILE-001
42
+ _MAX_PLAIN = 1e21
43
+ _MIN_PLAIN = 1e-6
44
+ _DECIMAL = re.compile(r"^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$")
45
+
46
+
47
+ def _number_to_string(value):
48
+ # type: (float) -> str
49
+ if math.isnan(value):
50
+ return "NaN"
51
+ if math.isinf(value):
52
+ return "Infinity" if value > 0 else "-Infinity"
53
+ if value == 0:
54
+ return "0"
55
+ if value.is_integer() and abs(value) < _MAX_PLAIN:
56
+ # The shortest digits padded with zeros, like JavaScript: 87003261217788850, not 87003261217788848.
57
+ return text_type(int(Decimal(number_text(value))))
58
+ if abs(value) >= _MAX_PLAIN or abs(value) < _MIN_PLAIN:
59
+ mantissa, _, exponent = number_text(value).partition("e")
60
+ sign = "-" if exponent.startswith("-") else "+"
61
+ return mantissa + "e" + sign + exponent.lstrip("+-").lstrip("0")
62
+ # repr gives the shortest digits that round-trip, like JavaScript; only the notation differs.
63
+ return text_type(format(Decimal(number_text(value)), "f"))
64
+
65
+
66
+ def js_str(value):
67
+ # type: (Any) -> str
68
+ """String(value) as JavaScript writes it. Absent values (None) become "null"."""
69
+ if value is None:
70
+ return "null"
71
+ if isinstance(value, bool):
72
+ return "true" if value else "false"
73
+ if isinstance(value, integer_types):
74
+ return text_type(value)
75
+ if isinstance(value, float):
76
+ return _number_to_string(value)
77
+ if is_text(value):
78
+ return text_type(to_text(value))
79
+ if isinstance(value, (list, tuple)):
80
+ return ",".join("" if item is None else js_str(item) for item in value)
81
+ return "[object Object]"
82
+
83
+
84
+ def js_number(text):
85
+ # type: (Any) -> Number
86
+ """Number(text) as JavaScript parses it: trimmed, "" is 0, hex is allowed, anything else is NaN."""
87
+ stripped = js_str(text).strip()
88
+ if stripped == "":
89
+ return 0
90
+ if re.match(r"^0[xX][0-9a-fA-F]+$", stripped):
91
+ return int(stripped, 16)
92
+ if stripped in ("Infinity", "+Infinity", "-Infinity"):
93
+ return -_INF if stripped.startswith("-") else _INF
94
+ if not _DECIMAL.match(stripped):
95
+ return _NAN
96
+ number = float(stripped)
97
+ return int(number) if number.is_integer() and abs(number) < _MAX_PLAIN and not re.search(r"[.eE]", stripped) else number
98
+
99
+
100
+ def js_mod(left, right):
101
+ # type: (Number, Number) -> Number
102
+ """a % b as JavaScript computes it: the result takes the sign of the dividend."""
103
+ if right == 0:
104
+ return _NAN
105
+ if isinstance(left, integer_types) and isinstance(right, integer_types):
106
+ remainder = abs(left) % abs(right)
107
+ return -remainder if left < 0 else remainder
108
+ return math.fmod(left, right)
109
+
110
+
111
+ def js_btoa(text):
112
+ # type: (str) -> str
113
+ """btoa(text): Base64 of a string whose characters each fit in one byte, like JavaScript."""
114
+ if any(ord(char) > 0xFF for char in text):
115
+ raise ValueError("InvalidCharacterError: the string contains a character that does not fit in a single byte")
116
+ return base64.b64encode(text.encode("latin-1")).decode("ascii")
117
+
118
+
119
+ def js_encode_uri_component(text):
120
+ # type: (str) -> str
121
+ """encodeURIComponent(text): letters, digits and - _ . ! ~ * ' ( ) stay; everything else is UTF-8 percent-encoded."""
122
+ return quote(text, safe="!'()*")
123
+
124
+
125
+ def js_same(left, right):
126
+ # type: (Any, Any) -> bool
127
+ """left === right: booleans never equal numbers, numbers compare by value, None equals None."""
128
+ if isinstance(left, bool) or isinstance(right, bool):
129
+ return isinstance(left, bool) and isinstance(right, bool) and left == right
130
+ return bool(left == right)
131
+
132
+
133
+ def js_div(left, right):
134
+ # type: (Number, Number) -> Number
135
+ """left / right with IEEE results: division by zero gives Infinity or NaN instead of an error."""
136
+ if right == 0:
137
+ if left == 0 or (isinstance(left, float) and math.isnan(left)):
138
+ return _NAN
139
+ negative = (left < 0) != (math.copysign(1.0, right) < 0)
140
+ return -_INF if negative else _INF
141
+ return left / right
142
+
143
+
144
+ def js_pow(base, exponent):
145
+ # type: (Number, Number) -> Number
146
+ """base ** exponent as JavaScript computes it: 0 ** -1 is Infinity and roots of negatives are NaN, not errors."""
147
+ try:
148
+ result = base ** exponent
149
+ except ZeroDivisionError:
150
+ return _INF
151
+ except OverflowError:
152
+ return _INF
153
+ except ValueError: # Python 2.7: a negative base with a fractional exponent
154
+ return _NAN
155
+ return _NAN if isinstance(result, complex) else result
156
+
157
+
158
+ def js_message(error):
159
+ # type: (BaseException) -> str
160
+ """error.message: the text of a caught error, also when it is not ASCII on Python 2.7."""
161
+ return message_of(error)
162
+
163
+
164
+ def js_get(value, name):
165
+ # type: (Any, str) -> Any
166
+ """value.name for a JSON value: a missing field is None; reading from null fails like JavaScript."""
167
+ if value is None:
168
+ raise TypeError("Cannot read properties of null (reading '" + name + "')")
169
+ if isinstance(value, dict):
170
+ return value.get(name)
171
+ return None
172
+ # @end
173
+
174
+ # @block middleware.helpers
175
+ # @summary random_uuid makes a version 4 UUID from the operating system's random source; the HMAC helpers sign UTF-8 text with a UTF-8 key, in hex or Base64.
176
+ # @versions >=2.7
177
+ # @source [1] https://docs.python.org/3/library/uuid.html#uuid.uuid4
178
+ # @quote [1] "uuid4() creates a random UUID."
179
+ # @source [2] https://docs.python.org/3/library/hmac.html#hmac.new
180
+ # @quote [2] "Return a new hmac object."
181
+ # @retrieved 2026-12-06
182
+ # @tests tests/test_lang.py
183
+ # @requirement SDKL-HELP-001
184
+
185
+
186
+ def js_random_uuid():
187
+ # type: () -> str
188
+ """randomUUID(): a random version 4 UUID in lower case."""
189
+ return text_type(uuid.uuid4())
190
+
191
+
192
+ def _hmac_sha256(key, text):
193
+ # type: (str, str) -> bytes
194
+ return hmac.new(to_text(key).encode("utf-8"), to_text(text).encode("utf-8"), hashlib.sha256).digest()
195
+
196
+
197
+ def js_hmac_sha256_hex(key, text):
198
+ # type: (str, str) -> str
199
+ """hmacSha256Hex(key, text): HMAC-SHA256 of UTF-8 text with a UTF-8 key, in lower-case hex."""
200
+ return text_type(binascii.hexlify(_hmac_sha256(key, text)).decode("ascii"))
201
+
202
+
203
+ def js_hmac_sha256_base64(key, text):
204
+ # type: (str, str) -> str
205
+ """hmacSha256Base64(key, text): HMAC-SHA256 of UTF-8 text with a UTF-8 key, in Base64."""
206
+ return base64.b64encode(_hmac_sha256(key, text)).decode("ascii")
207
+ # @end
@@ -0,0 +1,221 @@
1
+ # sdkloom Python kit: decoding and encoding JSON values.
2
+ from __future__ import absolute_import, division, unicode_literals
3
+
4
+ import json as _json
5
+ import re
6
+ from decimal import Decimal
7
+
8
+ from .compat import integer_types, is_text, number_text, ordered_dict, text_type, to_text
9
+
10
+ try: # type names for annotations in generated code and type checkers; Python 2.7 has no typing module
11
+ from typing import Any, Callable, Dict, List, Mapping, Sequence, TypeVar # noqa: F401
12
+
13
+ T = TypeVar("T")
14
+ except ImportError: # pragma: no cover
15
+ pass
16
+
17
+ # @block models.decode
18
+ # @summary Checks decoded JSON against the expected type; keeps object fields and enum values it does not know. Absent optional fields are UNSET, null is None. Null for an optional field that cannot be null reads as absent: many servers send null for a field they leave out.
19
+ # @versions >=2.7
20
+ # @source [1] https://www.rfc-editor.org/rfc/rfc8259#section-4
21
+ # @quote [1] "An object structure is represented as a pair of curly brackets surrounding zero or more name/value pairs (or members)."
22
+ # @source [2] https://docs.python.org/3/library/decimal.html
23
+ # @quote [2] "The decimal module provides support for fast correctly rounded decimal floating-point arithmetic."
24
+ # @retrieved 2026-12-05
25
+ # @tests tests/test_models.py
26
+ # @requirement SDKL-JSON-001
27
+ # @requirement SDKL-JSON-002
28
+ # @requirement SDKL-JSON-003
29
+ try:
30
+ Decoder = Callable[[Any, str], T]
31
+ except NameError: # pragma: no cover - Python 2.7
32
+ Decoder = object
33
+
34
+
35
+ class _Unset(object):
36
+ """Marks a field that was not sent. Falsy, so `if value:` treats it like None."""
37
+
38
+ _instance = None
39
+
40
+ def __new__(cls):
41
+ # type: () -> _Unset
42
+ if cls._instance is None:
43
+ cls._instance = super(_Unset, cls).__new__(cls)
44
+ return cls._instance
45
+
46
+ def __bool__(self):
47
+ # type: () -> bool
48
+ return False
49
+
50
+ __nonzero__ = __bool__ # Python 2.7
51
+
52
+ def __repr__(self):
53
+ # type: () -> str
54
+ return "UNSET"
55
+
56
+ def __copy__(self):
57
+ # type: () -> _Unset
58
+ return self
59
+
60
+ def __deepcopy__(self, memo):
61
+ # type: (Any) -> _Unset
62
+ return self
63
+
64
+
65
+ UNSET = _Unset() # type: Any
66
+
67
+
68
+ class DecodeError(ValueError):
69
+ def __init__(self, path, message):
70
+ # type: (str, str) -> None
71
+ super(DecodeError, self).__init__(path + ": " + message)
72
+ self.path = path
73
+
74
+
75
+ def _describe(value):
76
+ # type: (Any) -> str
77
+ if value is None:
78
+ return "null"
79
+ if isinstance(value, bool):
80
+ return "boolean " + ("true" if value else "false")
81
+ if is_text(value):
82
+ return "string " + text_type(_json.dumps(value, ensure_ascii=False))
83
+ if isinstance(value, float):
84
+ return "number " + number_text(value)
85
+ if isinstance(value, integer_types):
86
+ return "number " + text_type(value)
87
+ if isinstance(value, list):
88
+ return "array"
89
+ return "object"
90
+
91
+
92
+ def _mismatch(path, expected, value):
93
+ # type: (str, str, Any) -> DecodeError
94
+ return DecodeError(path, "expected " + expected + ", got " + _describe(value))
95
+
96
+
97
+ _DECIMAL = re.compile(r"^-?\d+(\.\d+)?$")
98
+
99
+
100
+ def as_object(value, path):
101
+ # type: (Any, str) -> Dict[str, Any]
102
+ if not isinstance(value, dict):
103
+ raise _mismatch(path, "an object", value)
104
+ return value
105
+
106
+
107
+ def as_string(value, path):
108
+ # type: (Any, str) -> str
109
+ if not is_text(value):
110
+ raise _mismatch(path, "a string", value)
111
+ return value
112
+
113
+
114
+ def _is_number(value):
115
+ # type: (Any) -> bool
116
+ return isinstance(value, integer_types + (float,)) and not isinstance(value, bool)
117
+
118
+
119
+ def as_number(value, path):
120
+ # type: (Any, str) -> float
121
+ if not _is_number(value):
122
+ raise _mismatch(path, "a number", value)
123
+ return value
124
+
125
+
126
+ def as_integer(value, path):
127
+ # type: (Any, str) -> int
128
+ if _is_number(value) and float(value).is_integer():
129
+ return int(value)
130
+ raise _mismatch(path, "an integer", value)
131
+
132
+
133
+ def as_boolean(value, path):
134
+ # type: (Any, str) -> bool
135
+ if not isinstance(value, bool):
136
+ raise _mismatch(path, "a boolean", value)
137
+ return value
138
+
139
+
140
+ def as_decimal(value, path):
141
+ # type: (Any, str) -> Decimal
142
+ """Decimals travel as strings to keep every digit; plain JSON numbers are accepted too."""
143
+ if _is_number(value):
144
+ return Decimal(number_text(value) if isinstance(value, float) else text_type(value))
145
+ if is_text(value) and _DECIMAL.match(value):
146
+ return Decimal(value)
147
+ raise _mismatch(path, "a decimal", value)
148
+
149
+
150
+ def as_enum(value, path, known):
151
+ # type: (Any, str, Sequence[str]) -> str
152
+ """Any string is accepted so a value added by the server later does not break the SDK."""
153
+ if not is_text(value):
154
+ raise _mismatch(path, "one of " + ", ".join(known), value)
155
+ return value
156
+
157
+
158
+ def as_list(value, path, item):
159
+ # type: (Any, str, Decoder[T]) -> List[T]
160
+ if not isinstance(value, list):
161
+ raise _mismatch(path, "an array", value)
162
+ return [item(entry, path + "[" + text_type(index) + "]") for index, entry in enumerate(value)]
163
+
164
+
165
+ def as_map(value, path, item):
166
+ # type: (Any, str, Decoder[T]) -> Dict[str, T]
167
+ return ordered_dict((key, item(entry, path + "." + key)) for key, entry in as_object(value, path).items())
168
+
169
+
170
+ def field(obj, name, path, decode, optional, nullable):
171
+ # type: (Mapping[str, Any], str, str, Decoder[T], bool, bool) -> Any
172
+ """Reads one field: absent is allowed only when optional (UNSET), null when nullable (None).
173
+
174
+ Many servers send null for a field they leave out, so null for an optional field that cannot be null is UNSET.
175
+ """
176
+ field_path = path + "." + name
177
+ if name not in obj:
178
+ if optional:
179
+ return UNSET
180
+ raise DecodeError(field_path, "is required")
181
+ value = obj[name]
182
+ if value is None and nullable:
183
+ return None
184
+ if value is None and optional:
185
+ return UNSET
186
+ return decode(value, field_path)
187
+ # @end
188
+
189
+ # @block models.encode
190
+ # @summary Serializes a value as compact UTF-8 JSON: models use to_json(), decimals become strings, UNSET fields are left out.
191
+ # @versions >=2.7
192
+ # @source [1] https://docs.python.org/3/library/json.html#json.dumps
193
+ # @quote [1] "Serialize obj to a JSON formatted str using this conversion table."
194
+ # @retrieved 2026-12-05
195
+ # @tests tests/test_models.py
196
+ # @requirement SDKL-JSON-004
197
+ def to_plain(value):
198
+ # type: (Any) -> Any
199
+ if hasattr(value, "to_json"):
200
+ return to_plain(value.to_json())
201
+ if isinstance(value, Decimal):
202
+ return text_type(value)
203
+ if isinstance(value, dict):
204
+ return ordered_dict((to_text(key), to_plain(item)) for key, item in value.items() if item is not UNSET)
205
+ if isinstance(value, (list, tuple)):
206
+ return [to_plain(item) for item in value]
207
+ return to_text(value)
208
+
209
+
210
+ def with_tag(data, key, tag):
211
+ # type: (Mapping[str, Any], str, str) -> Dict[str, Any]
212
+ """The JSON form of a union variant: its fields, then its tag."""
213
+ tagged = ordered_dict(data)
214
+ tagged[key] = tag
215
+ return tagged
216
+
217
+
218
+ def encode_json(value):
219
+ # type: (Any) -> bytes
220
+ return text_type(_json.dumps(to_plain(value), separators=(",", ":"), ensure_ascii=False)).encode("utf-8")
221
+ # @end
@@ -0,0 +1,69 @@
1
+ # sdkloom Python kit: multipart/form-data request bodies.
2
+
3
+ from __future__ import absolute_import, division, unicode_literals
4
+
5
+ import uuid
6
+
7
+ from .compat import Record, to_text
8
+
9
+ try: # type names for annotations; Python 2.7 has no typing module
10
+ from typing import Optional, Tuple, Union # noqa: F401
11
+ except ImportError: # pragma: no cover - Python 2.7
12
+ pass
13
+
14
+ # @block http.multipart
15
+ # @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.
16
+ # @versions >=2.7
17
+ # @source [1] https://www.rfc-editor.org/rfc/rfc7578#section-4.2
18
+ # @quote [1] "Each part MUST contain a Content-Disposition header field"
19
+ # @source [2] https://www.rfc-editor.org/rfc/rfc7578#section-4.1
20
+ # @quote [2] "As with other multipart types, the parts are delimited with a boundary delimiter"
21
+ # @retrieved 2026-12-06
22
+ # @tests tests/test_multipart.py
23
+ # @requirement SDKL-HTTP-005
24
+
25
+
26
+ class MultipartPart(Record):
27
+ """name, value (text for a field, bytes for a file), filename and content_type (files only)."""
28
+
29
+ _fields = ("name", "value", "filename", "content_type")
30
+ _defaults = {"filename": None, "content_type": None}
31
+
32
+
33
+ class MultipartForm(Record):
34
+ """Text fields and files, in order: MultipartForm().field("title", "Q4").file("report", "q4.pdf", "application/pdf", data)."""
35
+
36
+ _fields = ("parts",)
37
+ _defaults = {"parts": ()}
38
+
39
+ def field(self, name, value):
40
+ # type: (str, str) -> MultipartForm
41
+ """A copy with a text field added."""
42
+ return MultipartForm(tuple(self.parts) + (MultipartPart(name, value),))
43
+
44
+ def file(self, name, filename, content_type, data):
45
+ # type: (str, str, str, bytes) -> MultipartForm
46
+ """A copy with a file added."""
47
+ return MultipartForm(tuple(self.parts) + (MultipartPart(name, bytes(data), filename, content_type),))
48
+
49
+
50
+ def _quoted(text):
51
+ # type: (str) -> str
52
+ return '"' + to_text(text).replace('"', "%22").replace("\r", "%0D").replace("\n", "%0A") + '"'
53
+
54
+
55
+ def encode_multipart(form, boundary=None):
56
+ # type: (MultipartForm, Optional[str]) -> Tuple[bytes, str]
57
+ """The body bytes and the Content-Type header with its boundary."""
58
+ boundary = boundary or "sdkloom-" + str(uuid.uuid4())
59
+ chunks = []
60
+ for part in form.parts:
61
+ head = "--" + boundary + "\r\nContent-Disposition: form-data; name=" + _quoted(part.name)
62
+ if part.filename is not None:
63
+ head += "; filename=" + _quoted(part.filename) + "\r\nContent-Type: " + (part.content_type or "application/octet-stream")
64
+ chunks.append((head + "\r\n\r\n").encode("utf-8"))
65
+ chunks.append(part.value if isinstance(part.value, (bytes, bytearray)) and part.filename is not None else to_text(part.value).encode("utf-8"))
66
+ chunks.append(b"\r\n")
67
+ chunks.append(("--" + boundary + "--\r\n").encode("utf-8"))
68
+ return b"".join(bytes(chunk) for chunk in chunks), "multipart/form-data; boundary=" + boundary
69
+ # @end