sdkloom 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (383) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +239 -2
  3. package/kits/allowed-sources.json +24 -0
  4. package/kits/csharp/kit.json +6 -0
  5. package/kits/csharp/src/Runtime/Client.cs +295 -0
  6. package/kits/csharp/src/Runtime/Context.cs +216 -0
  7. package/kits/csharp/src/Runtime/Errors.cs +121 -0
  8. package/kits/csharp/src/Runtime/Http.cs +218 -0
  9. package/kits/csharp/src/Runtime/Json.cs +650 -0
  10. package/kits/csharp/src/Runtime/Lang.cs +212 -0
  11. package/kits/csharp/src/Runtime/Models.cs +206 -0
  12. package/kits/csharp/src/Runtime/Multipart.cs +108 -0
  13. package/kits/csharp/src/Runtime/Pagination.cs +122 -0
  14. package/kits/csharp/src/Runtime/Sse.cs +197 -0
  15. package/kits/csharp/src/Runtime/Testing.cs +375 -0
  16. package/kits/csharp/src/Runtime/Transport.cs +212 -0
  17. package/kits/csharp/src/Runtime/Wait.cs +57 -0
  18. package/kits/csharp/src/Runtime/Webhooks.cs +148 -0
  19. package/kits/csharp/tests/ClientTests.cs +128 -0
  20. package/kits/csharp/tests/HttpTests.cs +44 -0
  21. package/kits/csharp/tests/JsonTests.cs +132 -0
  22. package/kits/csharp/tests/LangTests.cs +57 -0
  23. package/kits/csharp/tests/MultipartTests.cs +31 -0
  24. package/kits/csharp/tests/PaginationTests.cs +93 -0
  25. package/kits/csharp/tests/SseTests.cs +122 -0
  26. package/kits/csharp/tests/TestRunner.cs +93 -0
  27. package/kits/csharp/tests/TestingTests.cs +80 -0
  28. package/kits/csharp/tests/TransportTests.cs +145 -0
  29. package/kits/csharp/tests/WaitTests.cs +39 -0
  30. package/kits/csharp/tests/WebhooksTests.cs +46 -0
  31. package/kits/csharp/versions.json +12 -0
  32. package/kits/go/kit.json +6 -0
  33. package/kits/go/src/sdkruntime/client.go +322 -0
  34. package/kits/go/src/sdkruntime/context.go +207 -0
  35. package/kits/go/src/sdkruntime/errors.go +74 -0
  36. package/kits/go/src/sdkruntime/http.go +261 -0
  37. package/kits/go/src/sdkruntime/json.go +527 -0
  38. package/kits/go/src/sdkruntime/lang.go +462 -0
  39. package/kits/go/src/sdkruntime/multipart.go +75 -0
  40. package/kits/go/src/sdkruntime/pagination.go +150 -0
  41. package/kits/go/src/sdkruntime/sse.go +267 -0
  42. package/kits/go/src/sdkruntime/testing.go +343 -0
  43. package/kits/go/src/sdkruntime/transport.go +168 -0
  44. package/kits/go/src/sdkruntime/wait.go +49 -0
  45. package/kits/go/src/sdkruntime/webhooks.go +129 -0
  46. package/kits/go/tests/client_test.go +185 -0
  47. package/kits/go/tests/http_test.go +78 -0
  48. package/kits/go/tests/json_test.go +127 -0
  49. package/kits/go/tests/lang_test.go +98 -0
  50. package/kits/go/tests/multipart_test.go +29 -0
  51. package/kits/go/tests/pagination_test.go +69 -0
  52. package/kits/go/tests/sse_test.go +129 -0
  53. package/kits/go/tests/testing_test.go +121 -0
  54. package/kits/go/tests/transport_test.go +133 -0
  55. package/kits/go/tests/wait_test.go +46 -0
  56. package/kits/go/tests/webhooks_test.go +62 -0
  57. package/kits/go/versions.json +12 -0
  58. package/kits/java/kit.json +6 -0
  59. package/kits/java/src/dev/sdkloom/runtime/ApiException.java +63 -0
  60. package/kits/java/src/dev/sdkloom/runtime/ArgumentException.java +24 -0
  61. package/kits/java/src/dev/sdkloom/runtime/Assert.java +72 -0
  62. package/kits/java/src/dev/sdkloom/runtime/ClientRuntime.java +220 -0
  63. package/kits/java/src/dev/sdkloom/runtime/Clock.java +39 -0
  64. package/kits/java/src/dev/sdkloom/runtime/Context.java +79 -0
  65. package/kits/java/src/dev/sdkloom/runtime/Decode.java +200 -0
  66. package/kits/java/src/dev/sdkloom/runtime/DecodeException.java +26 -0
  67. package/kits/java/src/dev/sdkloom/runtime/Decoder.java +16 -0
  68. package/kits/java/src/dev/sdkloom/runtime/Emitter.java +56 -0
  69. package/kits/java/src/dev/sdkloom/runtime/ErrorFactory.java +18 -0
  70. package/kits/java/src/dev/sdkloom/runtime/EventListener.java +20 -0
  71. package/kits/java/src/dev/sdkloom/runtime/EventStream.java +232 -0
  72. package/kits/java/src/dev/sdkloom/runtime/FakeClock.java +37 -0
  73. package/kits/java/src/dev/sdkloom/runtime/Headers.java +42 -0
  74. package/kits/java/src/dev/sdkloom/runtime/HttpRequest.java +88 -0
  75. package/kits/java/src/dev/sdkloom/runtime/HttpResponse.java +69 -0
  76. package/kits/java/src/dev/sdkloom/runtime/JdkTransport.java +97 -0
  77. package/kits/java/src/dev/sdkloom/runtime/Js.java +230 -0
  78. package/kits/java/src/dev/sdkloom/runtime/Json.java +281 -0
  79. package/kits/java/src/dev/sdkloom/runtime/JsonValue.java +15 -0
  80. package/kits/java/src/dev/sdkloom/runtime/Links.java +62 -0
  81. package/kits/java/src/dev/sdkloom/runtime/Middleware.java +16 -0
  82. package/kits/java/src/dev/sdkloom/runtime/MiddlewareEntry.java +43 -0
  83. package/kits/java/src/dev/sdkloom/runtime/MockRoute.java +111 -0
  84. package/kits/java/src/dev/sdkloom/runtime/MockTransport.java +62 -0
  85. package/kits/java/src/dev/sdkloom/runtime/MultipartForm.java +111 -0
  86. package/kits/java/src/dev/sdkloom/runtime/Next.java +16 -0
  87. package/kits/java/src/dev/sdkloom/runtime/OperationInfo.java +35 -0
  88. package/kits/java/src/dev/sdkloom/runtime/OperationMock.java +105 -0
  89. package/kits/java/src/dev/sdkloom/runtime/OperationSpec.java +125 -0
  90. package/kits/java/src/dev/sdkloom/runtime/Pages.java +55 -0
  91. package/kits/java/src/dev/sdkloom/runtime/Pipeline.java +29 -0
  92. package/kits/java/src/dev/sdkloom/runtime/RawResult.java +31 -0
  93. package/kits/java/src/dev/sdkloom/runtime/RecordedEvent.java +36 -0
  94. package/kits/java/src/dev/sdkloom/runtime/SdkInfo.java +38 -0
  95. package/kits/java/src/dev/sdkloom/runtime/SendOptions.java +34 -0
  96. package/kits/java/src/dev/sdkloom/runtime/ServerSentEvent.java +58 -0
  97. package/kits/java/src/dev/sdkloom/runtime/State.java +58 -0
  98. package/kits/java/src/dev/sdkloom/runtime/Test.java +21 -0
  99. package/kits/java/src/dev/sdkloom/runtime/TestRunner.java +63 -0
  100. package/kits/java/src/dev/sdkloom/runtime/Transport.java +16 -0
  101. package/kits/java/src/dev/sdkloom/runtime/TransportException.java +30 -0
  102. package/kits/java/src/dev/sdkloom/runtime/UrlConnectionTransport.java +195 -0
  103. package/kits/java/src/dev/sdkloom/runtime/Urls.java +116 -0
  104. package/kits/java/src/dev/sdkloom/runtime/Waits.java +53 -0
  105. package/kits/java/src/dev/sdkloom/runtime/WebhookSignatureException.java +24 -0
  106. package/kits/java/src/dev/sdkloom/runtime/Webhooks.java +146 -0
  107. package/kits/java/tests/dev/sdkloom/runtime/ClientTest.java +266 -0
  108. package/kits/java/tests/dev/sdkloom/runtime/EventStreamTest.java +131 -0
  109. package/kits/java/tests/dev/sdkloom/runtime/HttpTest.java +95 -0
  110. package/kits/java/tests/dev/sdkloom/runtime/JdkTransportTest.java +12 -0
  111. package/kits/java/tests/dev/sdkloom/runtime/JsTest.java +102 -0
  112. package/kits/java/tests/dev/sdkloom/runtime/JsonTest.java +87 -0
  113. package/kits/java/tests/dev/sdkloom/runtime/LinksTest.java +22 -0
  114. package/kits/java/tests/dev/sdkloom/runtime/MultipartFormTest.java +30 -0
  115. package/kits/java/tests/dev/sdkloom/runtime/PagesTest.java +75 -0
  116. package/kits/java/tests/dev/sdkloom/runtime/TestData.java +53 -0
  117. package/kits/java/tests/dev/sdkloom/runtime/TestingTest.java +156 -0
  118. package/kits/java/tests/dev/sdkloom/runtime/TransportContract.java +201 -0
  119. package/kits/java/tests/dev/sdkloom/runtime/UrlConnectionTransportTest.java +49 -0
  120. package/kits/java/tests/dev/sdkloom/runtime/WaitsTest.java +43 -0
  121. package/kits/java/tests/dev/sdkloom/runtime/WebhooksTest.java +45 -0
  122. package/kits/java/versions.json +41 -0
  123. package/kits/python/kit.json +6 -0
  124. package/kits/python/src/sdkloom_runtime/__init__.py +1 -0
  125. package/kits/python/src/sdkloom_runtime/client.py +232 -0
  126. package/kits/python/src/sdkloom_runtime/compat.py +195 -0
  127. package/kits/python/src/sdkloom_runtime/context.py +134 -0
  128. package/kits/python/src/sdkloom_runtime/errors.py +65 -0
  129. package/kits/python/src/sdkloom_runtime/http.py +192 -0
  130. package/kits/python/src/sdkloom_runtime/lang.py +207 -0
  131. package/kits/python/src/sdkloom_runtime/models.py +221 -0
  132. package/kits/python/src/sdkloom_runtime/multipart.py +69 -0
  133. package/kits/python/src/sdkloom_runtime/pagination.py +61 -0
  134. package/kits/python/src/sdkloom_runtime/pipeline.py +39 -0
  135. package/kits/python/src/sdkloom_runtime/sse.py +121 -0
  136. package/kits/python/src/sdkloom_runtime/testing.py +224 -0
  137. package/kits/python/src/sdkloom_runtime/transport.py +120 -0
  138. package/kits/python/src/sdkloom_runtime/wait.py +44 -0
  139. package/kits/python/src/sdkloom_runtime/webhooks.py +84 -0
  140. package/kits/python/tests/support.py +28 -0
  141. package/kits/python/tests/test_client.py +275 -0
  142. package/kits/python/tests/test_compat.py +87 -0
  143. package/kits/python/tests/test_http.py +94 -0
  144. package/kits/python/tests/test_lang.py +104 -0
  145. package/kits/python/tests/test_models.py +110 -0
  146. package/kits/python/tests/test_multipart.py +37 -0
  147. package/kits/python/tests/test_pagination.py +70 -0
  148. package/kits/python/tests/test_sse.py +61 -0
  149. package/kits/python/tests/test_testing.py +130 -0
  150. package/kits/python/tests/test_transport.py +124 -0
  151. package/kits/python/tests/test_wait.py +46 -0
  152. package/kits/python/tests/test_webhooks.py +57 -0
  153. package/kits/python/versions.json +33 -0
  154. package/kits/rust/kit.json +6 -0
  155. package/kits/rust/src/runtime/client.rs +212 -0
  156. package/kits/rust/src/runtime/context.rs +182 -0
  157. package/kits/rust/src/runtime/crypto.rs +84 -0
  158. package/kits/rust/src/runtime/errors.rs +147 -0
  159. package/kits/rust/src/runtime/http.rs +248 -0
  160. package/kits/rust/src/runtime/json.rs +424 -0
  161. package/kits/rust/src/runtime/lang.rs +296 -0
  162. package/kits/rust/src/runtime/mod.rs +30 -0
  163. package/kits/rust/src/runtime/models.rs +266 -0
  164. package/kits/rust/src/runtime/multipart.rs +81 -0
  165. package/kits/rust/src/runtime/pagination.rs +117 -0
  166. package/kits/rust/src/runtime/sse.rs +195 -0
  167. package/kits/rust/src/runtime/testing.rs +308 -0
  168. package/kits/rust/src/runtime/transport.rs +324 -0
  169. package/kits/rust/src/runtime/wait.rs +29 -0
  170. package/kits/rust/src/runtime/webhooks.rs +142 -0
  171. package/kits/rust/tests/client.rs +152 -0
  172. package/kits/rust/tests/http.rs +44 -0
  173. package/kits/rust/tests/json.rs +82 -0
  174. package/kits/rust/tests/lang.rs +74 -0
  175. package/kits/rust/tests/multipart.rs +21 -0
  176. package/kits/rust/tests/pagination.rs +61 -0
  177. package/kits/rust/tests/sse.rs +77 -0
  178. package/kits/rust/tests/testing.rs +90 -0
  179. package/kits/rust/tests/transport.rs +218 -0
  180. package/kits/rust/tests/wait.rs +32 -0
  181. package/kits/rust/tests/webhooks.rs +73 -0
  182. package/kits/rust/versions.json +6 -0
  183. package/kits/typescript/kit.json +6 -0
  184. package/kits/typescript/src/client.ts +223 -0
  185. package/kits/typescript/src/context.ts +108 -0
  186. package/kits/typescript/src/errors.ts +63 -0
  187. package/kits/typescript/src/helpers.ts +49 -0
  188. package/kits/typescript/src/http.ts +192 -0
  189. package/kits/typescript/src/models.ts +139 -0
  190. package/kits/typescript/src/multipart.ts +66 -0
  191. package/kits/typescript/src/pagination.ts +54 -0
  192. package/kits/typescript/src/pipeline.ts +25 -0
  193. package/kits/typescript/src/sse.ts +102 -0
  194. package/kits/typescript/src/testing.ts +217 -0
  195. package/kits/typescript/src/transport.ts +101 -0
  196. package/kits/typescript/src/wait.ts +36 -0
  197. package/kits/typescript/src/webhooks.ts +168 -0
  198. package/kits/typescript/tests/client.test.ts +269 -0
  199. package/kits/typescript/tests/helpers.test.ts +27 -0
  200. package/kits/typescript/tests/http.test.ts +80 -0
  201. package/kits/typescript/tests/models.test.ts +71 -0
  202. package/kits/typescript/tests/multipart.test.ts +28 -0
  203. package/kits/typescript/tests/pagination.test.ts +76 -0
  204. package/kits/typescript/tests/sse.test.ts +82 -0
  205. package/kits/typescript/tests/testing.test.ts +103 -0
  206. package/kits/typescript/tests/transport.test.ts +127 -0
  207. package/kits/typescript/tests/wait.test.ts +31 -0
  208. package/kits/typescript/tests/webhooks.test.ts +53 -0
  209. package/kits/typescript/versions.json +15 -0
  210. package/package.json +37 -4
  211. package/packages/cli/recipes/apiKeyHeader.ts +16 -0
  212. package/packages/cli/recipes/apiVersionHeader.ts +16 -0
  213. package/packages/cli/recipes/basic.ts +13 -0
  214. package/packages/cli/recipes/bearer.ts +10 -0
  215. package/packages/cli/recipes/hmacSign.ts +23 -0
  216. package/packages/cli/recipes/idempotencyKey.ts +19 -0
  217. package/packages/cli/recipes/oauthClientCredentials.ts +50 -0
  218. package/packages/cli/recipes/retry.ts +42 -0
  219. package/packages/cli/recipes/timing.ts +12 -0
  220. package/packages/cli/recipes/userAgent.ts +8 -0
  221. package/packages/cli/src/build.js +93 -0
  222. package/packages/cli/src/commands/build.js +31 -0
  223. package/packages/cli/src/commands/conformance-check.js +50 -0
  224. package/packages/cli/src/commands/contract.js +181 -0
  225. package/packages/cli/src/commands/diff.js +113 -0
  226. package/packages/cli/src/commands/doctor.js +43 -0
  227. package/packages/cli/src/commands/import-openapi.js +42 -0
  228. package/packages/cli/src/commands/init.js +27 -0
  229. package/packages/cli/src/commands/kit-check.js +145 -0
  230. package/packages/cli/src/commands/publish.js +81 -0
  231. package/packages/cli/src/commands/recipe.js +49 -0
  232. package/packages/cli/src/commands/record.js +181 -0
  233. package/packages/cli/src/commands/serve.js +156 -0
  234. package/packages/cli/src/commands/spec-check.js +57 -0
  235. package/packages/cli/src/commands/test.js +177 -0
  236. package/packages/cli/src/commands/variants.js +32 -0
  237. package/packages/cli/src/commands/verify.js +57 -0
  238. package/packages/cli/src/commands/version.js +63 -0
  239. package/packages/cli/src/containers.js +82 -0
  240. package/packages/cli/src/coverage.js +72 -0
  241. package/packages/cli/src/git.js +25 -0
  242. package/packages/cli/src/io.js +50 -0
  243. package/packages/cli/src/java/ScenarioHarness.java +297 -0
  244. package/packages/cli/src/java/SchemaRoundTrip.java +63 -0
  245. package/packages/cli/src/java.js +70 -0
  246. package/packages/cli/src/js/harness.mjs +120 -0
  247. package/packages/cli/src/kits.js +103 -0
  248. package/packages/cli/src/languages/csharp.js +274 -0
  249. package/packages/cli/src/languages/go.js +185 -0
  250. package/packages/cli/src/languages/index.js +18 -0
  251. package/packages/cli/src/languages/java.js +187 -0
  252. package/packages/cli/src/languages/python.js +120 -0
  253. package/packages/cli/src/languages/rust.js +189 -0
  254. package/packages/cli/src/languages/types.js +93 -0
  255. package/packages/cli/src/languages/typescript.js +112 -0
  256. package/packages/cli/src/main.js +13 -0
  257. package/packages/cli/src/packaging.js +39 -0
  258. package/packages/cli/src/portability.js +45 -0
  259. package/packages/cli/src/profiles.js +55 -0
  260. package/packages/cli/src/project.js +56 -0
  261. package/packages/cli/src/python/scenario_harness.py +162 -0
  262. package/packages/cli/src/python/schema_roundtrip.py +42 -0
  263. package/packages/cli/src/registries.js +214 -0
  264. package/packages/cli/src/resolve-core.js +39 -0
  265. package/packages/cli/src/run.js +133 -0
  266. package/packages/cli/src/runtimes.js +61 -0
  267. package/packages/cli/src/scenarios-java.js +82 -0
  268. package/packages/cli/src/scenarios-javascript.js +54 -0
  269. package/packages/cli/src/scenarios-python.js +90 -0
  270. package/packages/cli/src/scenarios.js +183 -0
  271. package/packages/cli/src/schema.js +84 -0
  272. package/packages/cli/src/templates.js +85 -0
  273. package/packages/cli/src/toolchains.js +68 -0
  274. package/packages/cli/src/transpiled-tests.js +92 -0
  275. package/packages/codegen/src/canonical-json.js +31 -0
  276. package/packages/codegen/src/capabilities.js +50 -0
  277. package/packages/codegen/src/code-writer.js +54 -0
  278. package/packages/codegen/src/file-tree.js +25 -0
  279. package/packages/codegen/src/hash.js +6 -0
  280. package/packages/codegen/src/index.js +16 -0
  281. package/packages/codegen/src/lock.js +106 -0
  282. package/packages/conformance/src/case.js +143 -0
  283. package/packages/conformance/src/checks.js +40 -0
  284. package/packages/conformance/src/index.js +3 -0
  285. package/packages/conformance/src/matrix.js +48 -0
  286. package/packages/conformance/src/suite.js +48 -0
  287. package/packages/differ/src/diff.js +500 -0
  288. package/packages/differ/src/index.js +3 -0
  289. package/packages/differ/src/notes.js +112 -0
  290. package/packages/differ/src/support.js +34 -0
  291. package/packages/gen-csharp/src/emit-client.js +397 -0
  292. package/packages/gen-csharp/src/emit-harness.js +333 -0
  293. package/packages/gen-csharp/src/emit-mock.js +111 -0
  294. package/packages/gen-csharp/src/emit-models.js +119 -0
  295. package/packages/gen-csharp/src/emit-webhooks.js +57 -0
  296. package/packages/gen-csharp/src/generate.js +245 -0
  297. package/packages/gen-csharp/src/index.js +5 -0
  298. package/packages/gen-csharp/src/names.js +284 -0
  299. package/packages/gen-go/src/emit-client.js +405 -0
  300. package/packages/gen-go/src/emit-harness.js +294 -0
  301. package/packages/gen-go/src/emit-mock.js +112 -0
  302. package/packages/gen-go/src/emit-models.js +146 -0
  303. package/packages/gen-go/src/emit-webhooks.js +58 -0
  304. package/packages/gen-go/src/generate.js +205 -0
  305. package/packages/gen-go/src/index.js +5 -0
  306. package/packages/gen-go/src/names.js +197 -0
  307. package/packages/gen-java/src/emit-client.js +441 -0
  308. package/packages/gen-java/src/emit-models.js +342 -0
  309. package/packages/gen-java/src/emit-testing.js +123 -0
  310. package/packages/gen-java/src/emit-webhooks.js +70 -0
  311. package/packages/gen-java/src/generate.js +244 -0
  312. package/packages/gen-java/src/index.js +4 -0
  313. package/packages/gen-java/src/names.js +197 -0
  314. package/packages/gen-python/src/emit-client.js +272 -0
  315. package/packages/gen-python/src/emit-models.js +139 -0
  316. package/packages/gen-python/src/emit-testing.js +93 -0
  317. package/packages/gen-python/src/emit-webhooks.js +48 -0
  318. package/packages/gen-python/src/generate.js +237 -0
  319. package/packages/gen-python/src/index.js +2 -0
  320. package/packages/gen-python/src/names.js +161 -0
  321. package/packages/gen-python/src/style.js +67 -0
  322. package/packages/gen-rust/src/emit-client.js +379 -0
  323. package/packages/gen-rust/src/emit-harness.js +278 -0
  324. package/packages/gen-rust/src/emit-mock.js +121 -0
  325. package/packages/gen-rust/src/emit-models.js +117 -0
  326. package/packages/gen-rust/src/emit-webhooks.js +58 -0
  327. package/packages/gen-rust/src/generate.js +243 -0
  328. package/packages/gen-rust/src/index.js +5 -0
  329. package/packages/gen-rust/src/names.js +223 -0
  330. package/packages/gen-typescript/src/emit-client.js +434 -0
  331. package/packages/gen-typescript/src/emit-models.js +93 -0
  332. package/packages/gen-typescript/src/emit-package.js +90 -0
  333. package/packages/gen-typescript/src/emit-testing.js +138 -0
  334. package/packages/gen-typescript/src/emit-webhooks.js +52 -0
  335. package/packages/gen-typescript/src/generate.js +70 -0
  336. package/packages/gen-typescript/src/index.js +3 -0
  337. package/packages/gen-typescript/src/naming.js +64 -0
  338. package/packages/gen-typescript/src/runtime.js +81 -0
  339. package/packages/gen-typescript/src/types.js +136 -0
  340. package/packages/ir/src/api-surface.js +22 -0
  341. package/packages/ir/src/checks.js +52 -0
  342. package/packages/ir/src/index.js +32 -0
  343. package/packages/ir/src/ir.js +214 -0
  344. package/packages/ir/src/pages.js +18 -0
  345. package/packages/ir/src/validate-ir.js +462 -0
  346. package/packages/ir/src/validate-types.js +140 -0
  347. package/packages/kit/src/block-parser.js +196 -0
  348. package/packages/kit/src/index.js +15 -0
  349. package/packages/kit/src/kit-check.js +203 -0
  350. package/packages/kit/src/sources.js +53 -0
  351. package/packages/kit/src/version-policy.js +133 -0
  352. package/packages/kit/src/version-range.js +132 -0
  353. package/packages/openapi/src/import.js +292 -0
  354. package/packages/openapi/src/index.js +1 -0
  355. package/packages/openapi/src/names.js +50 -0
  356. package/packages/openapi/src/schemas.js +264 -0
  357. package/packages/packager/src/archive.js +106 -0
  358. package/packages/packager/src/crate.js +39 -0
  359. package/packages/packager/src/gomodule.js +11 -0
  360. package/packages/packager/src/index.js +9 -0
  361. package/packages/packager/src/maven.js +85 -0
  362. package/packages/packager/src/metadata.js +34 -0
  363. package/packages/packager/src/npm.js +71 -0
  364. package/packages/packager/src/nuget.js +78 -0
  365. package/packages/packager/src/sbom.js +56 -0
  366. package/packages/packager/src/wheel.js +62 -0
  367. package/packages/spec/src/index.js +11 -0
  368. package/packages/spec/src/requirements.js +139 -0
  369. package/packages/transpile/src/ast.js +51 -0
  370. package/packages/transpile/src/check.js +669 -0
  371. package/packages/transpile/src/emit-csharp.js +469 -0
  372. package/packages/transpile/src/emit-go.js +529 -0
  373. package/packages/transpile/src/emit-java.js +360 -0
  374. package/packages/transpile/src/emit-python.js +320 -0
  375. package/packages/transpile/src/emit-rust.js +499 -0
  376. package/packages/transpile/src/errors.js +15 -0
  377. package/packages/transpile/src/index.js +13 -0
  378. package/packages/transpile/src/lexer.js +161 -0
  379. package/packages/transpile/src/parser.js +543 -0
  380. package/packages/transpile/src/tests/ast.js +46 -0
  381. package/packages/transpile/src/tests/parse.js +376 -0
  382. package/packages/transpile/src/tests/translate.js +849 -0
  383. package/packages/transpile/src/transpile.js +57 -0
@@ -0,0 +1,212 @@
1
+ // sdkloom C# kit: JavaScript semantics that transpiled middleware relies on.
2
+
3
+ using System;
4
+ using System.Globalization;
5
+ using System.Linq;
6
+ using System.Text;
7
+ using System.Threading;
8
+
9
+ namespace Sdkloom.Runtime
10
+ {
11
+ // @block lang.js
12
+ // @summary String(value), Number(text), btoa(text), randomUUID(), hmacSha256Hex and hmacSha256Base64 (UTF-8 key and text), ===, /, **, the % remainder, error.message and JSON field reads with JavaScript's results, so transpiled middleware behaves like its TypeScript source.
13
+ // @versions >=3
14
+ // @source [1] https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-tostring
15
+ // @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."
16
+ // @source [2] https://tc39.es/ecma262/multipage/abstract-operations.html#sec-stringtonumber
17
+ // @quote [2] "The abstract operation StringToNumber specifies how to convert a String value to a Number value, using the following grammar."
18
+ // @source [3] https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-remainder
19
+ // @quote [3] "The sign of the result is the sign of the dividend."
20
+ // @source [4] https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa
21
+ // @quote [4] "The string contained a character that did not fit in a single byte."
22
+ // @source [5] https://learn.microsoft.com/en-us/dotnet/api/system.guid.newguid
23
+ // @quote [5] "Initializes a new instance of the Guid structure."
24
+ // @retrieved 2026-12-05
25
+ // @tests tests/LangTests.cs
26
+ // @requirement SDKL-XPILE-001
27
+
28
+ /// <summary>JavaScript operations on JSON values, as transpiled middleware uses them.</summary>
29
+ public static class Js
30
+ {
31
+ private static readonly ThreadLocal<Random> Generator = new ThreadLocal<Random>(() => new Random(Guid.NewGuid().GetHashCode()));
32
+
33
+ /// <summary>String(value). null becomes "null", arrays join with commas, objects are "[object Object]".</summary>
34
+ public static string Str(Json value)
35
+ {
36
+ switch (value.Kind)
37
+ {
38
+ case JsonKind.Null: return "null";
39
+ case JsonKind.Bool: return value.AsBool() == true ? "true" : "false";
40
+ case JsonKind.String: return value.AsString() ?? "";
41
+ case JsonKind.Number:
42
+ var text = value.NumberString ?? "";
43
+ if (text.IndexOfAny(new[] { '.', 'e', 'E' }) < 0 && long.TryParse(text, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var integer))
44
+ {
45
+ return integer.ToString(CultureInfo.InvariantCulture);
46
+ }
47
+
48
+ return double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var number) ? NumberText.Of(number) : text;
49
+ case JsonKind.Array: return string.Join(",", value.Items.Select(item => item.IsNull ? "" : Str(item)));
50
+ default: return "[object Object]";
51
+ }
52
+ }
53
+
54
+ public static string Str(string value) => value;
55
+
56
+ public static string Str(long value) => value.ToString(CultureInfo.InvariantCulture);
57
+
58
+ public static string Str(double value) => NumberText.Of(value);
59
+
60
+ public static string Str(bool value) => value ? "true" : "false";
61
+
62
+ /// <summary>What String.prototype.trim removes: white space and line terminators, including no-break space and BOM.</summary>
63
+ private static bool IsSpace(char c) =>
64
+ c == 0x09 || c == 0x0A || c == 0x0B || c == 0x0C || c == 0x0D || c == 0x20 || c == 0xA0 || c == 0x1680 || (c >= 0x2000 && c <= 0x200A)
65
+ || c == 0x2028 || c == 0x2029 || c == 0x202F || c == 0x205F || c == 0x3000 || c == 0xFEFF;
66
+
67
+ private static bool AllDigits(string text) => text.All(c => c >= '0' && c <= '9');
68
+
69
+ /// <summary>Number(text): trimmed, "" is 0, hex is allowed, anything else is NaN.</summary>
70
+ public static double Number(string text)
71
+ {
72
+ var start = 0;
73
+ var end = text.Length;
74
+ while (start < end && IsSpace(text[start]))
75
+ {
76
+ start++;
77
+ }
78
+
79
+ while (end > start && IsSpace(text[end - 1]))
80
+ {
81
+ end--;
82
+ }
83
+
84
+ var trimmed = text.Substring(start, end - start);
85
+ if (trimmed.Length == 0)
86
+ {
87
+ return 0;
88
+ }
89
+
90
+ if (trimmed.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
91
+ {
92
+ var hex = trimmed.Substring(2);
93
+ return hex.Length > 0 && hex.All(Uri.IsHexDigit) ? hex.Aggregate(0.0, (sum, digit) => (sum * 16) + Convert.ToInt32(digit.ToString(), 16)) : double.NaN;
94
+ }
95
+
96
+ switch (trimmed)
97
+ {
98
+ case "Infinity":
99
+ case "+Infinity":
100
+ return double.PositiveInfinity;
101
+ case "-Infinity":
102
+ return double.NegativeInfinity;
103
+ }
104
+
105
+ var body = trimmed.TrimStart('+', '-');
106
+ if (trimmed.Length - body.Length > 1)
107
+ {
108
+ return double.NaN;
109
+ }
110
+
111
+ var e = body.IndexOfAny(new[] { 'e', 'E' });
112
+ var mantissa = e < 0 ? body : body.Substring(0, e);
113
+ var exponent = e < 0 ? null : body.Substring(e + 1).TrimStart('+', '-');
114
+ var exponentOk = exponent == null || (exponent.Length > 0 && AllDigits(exponent) && body.Length - e - 1 - exponent.Length <= 1);
115
+ var dot = mantissa.IndexOf('.');
116
+ var whole = dot < 0 ? mantissa : mantissa.Substring(0, dot);
117
+ var fraction = dot < 0 ? "" : mantissa.Substring(dot + 1);
118
+ var mantissaOk = (whole.Length > 0 || fraction.Length > 0) && AllDigits(whole) && AllDigits(fraction);
119
+ return mantissaOk && exponentOk && double.TryParse(trimmed, NumberStyles.Float, CultureInfo.InvariantCulture, out var result) ? result : double.NaN;
120
+ }
121
+
122
+ public static double Number(Json value) => value.Kind == JsonKind.String ? Number(value.AsString() ?? "") : value.AsDouble() ?? (value.Kind == JsonKind.Bool ? (value.AsBool() == true ? 1 : 0) : value.IsNull ? 0 : double.NaN);
123
+
124
+ /// <summary>Math.random(): a number in [0, 1); good enough for jitter, not for secrets.</summary>
125
+ public static double Random() => Generator.Value!.NextDouble();
126
+
127
+ /// <summary>a % b for integers: the result takes the sign of the dividend; % 0 fails.</summary>
128
+ public static long Rem(long left, long right) => right == 0 ? throw new SdkException("division by zero") : right == -1 ? 0 : left % right;
129
+
130
+ /// <summary>btoa(text): Base64 of a string whose characters each fit in one byte.</summary>
131
+ public static string Btoa(string text)
132
+ {
133
+ if (text.Any(c => c > 0xFF))
134
+ {
135
+ throw new SdkException("InvalidCharacterError: the string contains a character that does not fit in a single byte");
136
+ }
137
+
138
+ return Convert.ToBase64String(text.Select(c => (byte)c).ToArray());
139
+ }
140
+
141
+ /// <summary>left === right on JSON values: numbers compare by value, booleans never equal numbers, null equals null.</summary>
142
+ public static bool Same(Json left, Json right) =>
143
+ left.Kind == JsonKind.Number && right.Kind == JsonKind.Number ? left.AsDouble() == right.AsDouble() : left.Equals(right);
144
+
145
+ /// <summary>left / right with IEEE results.</summary>
146
+ public static double Div(double left, double right) => left / right;
147
+
148
+ /// <summary>base ** exponent as JavaScript computes it.</summary>
149
+ public static double Pow(double value, double exponent) =>
150
+ double.IsNaN(exponent) || (Math.Abs(value) == 1 && double.IsInfinity(exponent)) ? double.NaN : Math.Pow(value, exponent);
151
+
152
+ /// <summary>value.name for a JSON value: a missing field is null; reading from null fails like JavaScript.</summary>
153
+ public static Json Get(Json value, string name)
154
+ {
155
+ if (value.IsNull)
156
+ {
157
+ throw new SdkException("Cannot read properties of null (reading '" + name + "')");
158
+ }
159
+
160
+ return value.Get(name) ?? Json.Null;
161
+ }
162
+
163
+ /// <summary>error.message.</summary>
164
+ public static string Message(Exception error) => error.Message;
165
+
166
+ private static SdkException TypeError(string expected, Json value) => new SdkException("TypeError: expected " + expected + ", got " + value.ToJsonString());
167
+
168
+ /// <summary>A value that must be an integer (a config field, a JSON number).</summary>
169
+ public static long ToLong(Json value) => value.AsLong() ?? throw TypeError("an integer", value);
170
+
171
+ public static double ToDouble(Json value) => value.AsDouble() ?? throw TypeError("a number", value);
172
+
173
+ public static string ToStr(Json value) => value.AsString() ?? throw TypeError("a string", value);
174
+
175
+ public static bool ToBool(Json value) => value.AsBool() ?? throw TypeError("a boolean", value);
176
+
177
+ /// <summary>A value that must be a JSON object.</summary>
178
+ public static Json ToObject(Json value) => value.Kind == JsonKind.Object ? value : throw TypeError("an object", value);
179
+
180
+ /// <summary>for (const item of list).</summary>
181
+ public static System.Collections.Generic.IReadOnlyList<Json> ToList(Json value)
182
+ {
183
+ if (value.IsNull)
184
+ {
185
+ throw new SdkException("TypeError: null is not iterable");
186
+ }
187
+
188
+ return value.Kind == JsonKind.Array ? value.Items : throw TypeError("an array", value);
189
+ }
190
+
191
+ /// <summary>A UTF-8 string as bytes, for request bodies.</summary>
192
+ public static byte[] Utf8(string text) => Encoding.UTF8.GetBytes(text);
193
+
194
+ /// <summary>randomUUID(): a random version 4 UUID in lower case.</summary>
195
+ public static string RandomUuid() => Guid.NewGuid().ToString("D", CultureInfo.InvariantCulture);
196
+
197
+ private static byte[] HmacSha256(string key, string text)
198
+ {
199
+ using var hmac = new System.Security.Cryptography.HMACSHA256(Encoding.UTF8.GetBytes(key));
200
+ return hmac.ComputeHash(Encoding.UTF8.GetBytes(text));
201
+ }
202
+
203
+ /// <summary>hmacSha256Hex(key, text): HMAC-SHA256 of UTF-8 text with a UTF-8 key, in lower-case hex.</summary>
204
+ public static string HmacSha256Hex(string key, string text) =>
205
+ string.Concat(HmacSha256(key, text).Select(value => value.ToString("x2", CultureInfo.InvariantCulture)));
206
+
207
+ /// <summary>hmacSha256Base64(key, text): HMAC-SHA256 of UTF-8 text with a UTF-8 key, in Base64.</summary>
208
+ public static string HmacSha256Base64(string key, string text) => Convert.ToBase64String(HmacSha256(key, text));
209
+ }
210
+
211
+ // @end
212
+ }
@@ -0,0 +1,206 @@
1
+ // sdkloom C# kit: decoding JSON into typed values and writing them back.
2
+
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Globalization;
6
+ using System.Linq;
7
+
8
+ namespace Sdkloom.Runtime
9
+ {
10
+ // @block models.decode
11
+ // @summary Checks decoded JSON against the expected type; keeps object fields and enum values it does not know. Absent optional fields and null nullable ones are null; a field both optional and nullable is a Maybe that tells absent from null. Null for an optional field that cannot be null reads as absent: many servers send null for a field they leave out.
12
+ // @versions >=3
13
+ // @source [1] https://www.rfc-editor.org/rfc/rfc8259#section-4
14
+ // @quote [1] "An object structure is represented as a pair of curly brackets surrounding zero or more name/value pairs (or members)."
15
+ // @source [2] https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types
16
+ // @quote [2] "The decimal type is appropriate when the required degree of precision is determined by the number of digits to the right of the decimal point."
17
+ // @retrieved 2026-12-05
18
+ // @tests tests/JsonTests.cs
19
+ // @requirement SDKL-JSON-001
20
+ // @requirement SDKL-JSON-002
21
+ // @requirement SDKL-JSON-003
22
+
23
+ /// <summary>A value that may be absent: tells an absent field from one that is null.</summary>
24
+ public readonly struct Maybe<T>
25
+ {
26
+ public Maybe(T value)
27
+ {
28
+ IsSet = true;
29
+ Value = value;
30
+ }
31
+
32
+ public bool IsSet { get; }
33
+
34
+ public T Value { get; }
35
+
36
+ public static implicit operator Maybe<T>(T value) => new Maybe<T>(value);
37
+ }
38
+
39
+ /// <summary>Decoders: each checks one JSON value at a path such as "$.items[0]" and fails with a DecodeException.</summary>
40
+ public static class Decode
41
+ {
42
+ private static string Describe(Json value)
43
+ {
44
+ switch (value.Kind)
45
+ {
46
+ case JsonKind.Null: return "null";
47
+ case JsonKind.Bool: return "boolean " + value.ToJsonString();
48
+ case JsonKind.String: return "string " + value.ToJsonString();
49
+ case JsonKind.Number: return "number " + value.ToJsonString();
50
+ case JsonKind.Array: return "array";
51
+ default: return "object";
52
+ }
53
+ }
54
+
55
+ private static DecodeException Mismatch(string path, string expected, Json value) => new DecodeException(path, "expected " + expected + ", got " + Describe(value));
56
+
57
+ public static Json Object(Json value, string path) => value.Kind == JsonKind.Object ? value : throw Mismatch(path, "an object", value);
58
+
59
+ public static string String(Json value, string path) => value.AsString() ?? throw Mismatch(path, "a string", value);
60
+
61
+ /// <summary>Any string, so a value the server adds later does not break the SDK.</summary>
62
+ public static string Enum(Json value, string path, params string[] known) => value.AsString() ?? throw Mismatch(path, "one of " + string.Join(", ", known), value);
63
+
64
+ public static bool Boolean(Json value, string path) => value.AsBool() ?? throw Mismatch(path, "a boolean", value);
65
+
66
+ public static double Number(Json value, string path) => value.AsDouble() ?? throw Mismatch(path, "a number", value);
67
+
68
+ /// <summary>A number without a fraction (2.0 included) that fits in 64 bits.</summary>
69
+ public static long Integer(Json value, string path) => value.AsLong() ?? throw Mismatch(path, "an integer", value);
70
+
71
+ private static bool IsDecimalText(string text)
72
+ {
73
+ var digits = text.StartsWith("-", StringComparison.Ordinal) ? text.Substring(1) : text;
74
+ var parts = digits.Split('.');
75
+ return parts.Length <= 2 && parts.All(part => part.Length > 0 && part.All(c => c >= '0' && c <= '9'));
76
+ }
77
+
78
+ /// <summary>
79
+ /// A decimal string ("10.50") or a JSON number; the scale is kept ("10.50" stays 10.50m). A value System.Decimal
80
+ /// cannot hold exactly (more than 28 significant digits, or too small) fails instead of being rounded.
81
+ /// </summary>
82
+ public static decimal Decimal(Json value, string path)
83
+ {
84
+ var text = value.Kind == JsonKind.String && IsDecimalText(value.AsString() ?? "") ? value.AsString() : value.NumberString;
85
+ if (text != null && decimal.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
86
+ {
87
+ if (SignificantDigits(result.ToString(CultureInfo.InvariantCulture)) == SignificantDigits(text))
88
+ {
89
+ return result;
90
+ }
91
+
92
+ throw Mismatch(path, "a decimal with at most 28 significant digits", value);
93
+ }
94
+
95
+ throw Mismatch(path, "a decimal", value);
96
+ }
97
+
98
+ /// <summary>The digits that carry the value: "-001.2300e2" → "123" (sign, point, exponent, outer zeros dropped).</summary>
99
+ private static string SignificantDigits(string text)
100
+ {
101
+ var mantissa = text.Split('e', 'E')[0];
102
+ return new string(mantissa.Where(char.IsDigit).ToArray()).Trim('0');
103
+ }
104
+
105
+ public static IReadOnlyList<T> List<T>(Json value, string path, Func<Json, string, T> item)
106
+ {
107
+ if (value.Kind != JsonKind.Array)
108
+ {
109
+ throw Mismatch(path, "an array", value);
110
+ }
111
+
112
+ return value.Items.Select((entry, index) => item(entry, path + "[" + index.ToString(CultureInfo.InvariantCulture) + "]")).ToArray();
113
+ }
114
+
115
+ public static IReadOnlyDictionary<string, T> Map<T>(Json value, string path, Func<Json, string, T> item)
116
+ {
117
+ var result = new Dictionary<string, T>();
118
+ foreach (var field in Object(value, path).Fields)
119
+ {
120
+ result[field.Key] = item(field.Value, path + "." + field.Key);
121
+ }
122
+
123
+ return result;
124
+ }
125
+
126
+ /// <summary>null as null, anything else decoded; for reference types.</summary>
127
+ public static Func<Json, string, T?> NullableRef<T>(Func<Json, string, T> item)
128
+ where T : class => (value, path) => value.IsNull ? null : item(value, path);
129
+
130
+ /// <summary>null as null, anything else decoded; for value types.</summary>
131
+ public static Func<Json, string, T?> NullableValue<T>(Func<Json, string, T> item)
132
+ where T : struct => (value, path) => value.IsNull ? (T?)null : item(value, path);
133
+
134
+ /// <summary>A field that must be present.</summary>
135
+ public static T Required<T>(Json obj, string name, string path, Func<Json, string, T> decode)
136
+ {
137
+ var at = path + "." + name;
138
+ var value = obj.Get(name) ?? throw new DecodeException(at, "is required");
139
+ return decode(value, at);
140
+ }
141
+
142
+ /// <summary>
143
+ /// A field that may be absent; absent is null. Many servers send null for a field they leave out, so null reads
144
+ /// as absent too. For reference types.
145
+ /// </summary>
146
+ public static T? OptionalRef<T>(Json obj, string name, string path, Func<Json, string, T> decode)
147
+ where T : class
148
+ {
149
+ var value = obj.Get(name);
150
+ return value == null || value.IsNull ? null : decode(value, path + "." + name);
151
+ }
152
+
153
+ /// <summary>A field that may be absent; absent and null are null. For value types.</summary>
154
+ public static T? OptionalValue<T>(Json obj, string name, string path, Func<Json, string, T> decode)
155
+ where T : struct
156
+ {
157
+ var value = obj.Get(name);
158
+ return value == null || value.IsNull ? (T?)null : decode(value, path + "." + name);
159
+ }
160
+
161
+ /// <summary>A field that may be absent and may be null: absent is a Maybe without a value.</summary>
162
+ public static Maybe<T> Optional<T>(Json obj, string name, string path, Func<Json, string, T> decode)
163
+ {
164
+ var value = obj.Get(name);
165
+ return value == null ? default : new Maybe<T>(decode(value, path + "." + name));
166
+ }
167
+
168
+ /// <summary>The fields the SDK does not know, kept so they can be sent back unchanged.</summary>
169
+ public static IReadOnlyList<KeyValuePair<string, Json>> Extra(Json obj, params string[] known) =>
170
+ obj.Fields.Where(field => Array.IndexOf(known, field.Key) < 0).ToArray();
171
+ }
172
+
173
+ // @end
174
+
175
+ // @block models.encode
176
+ // @summary The JSON form of typed values: models implement IToJson, decimals become strings with their scale, null is null, numbers are written like JavaScript.
177
+ // @versions >=3
178
+ // @source [1] https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.invariantculture
179
+ // @quote [1] "The invariant culture is culture-insensitive; it's associated with the English language but not with any country/region."
180
+ // @retrieved 2026-12-05
181
+ // @tests tests/JsonTests.cs
182
+ // @requirement SDKL-JSON-004
183
+
184
+ /// <summary>The JSON form of a value; every generated model implements it.</summary>
185
+ public interface IToJson
186
+ {
187
+ Json ToJson();
188
+ }
189
+
190
+ /// <summary>Encoders for values that are not models.</summary>
191
+ public static class Encode
192
+ {
193
+ public static Json Decimal(decimal value) => Json.Str(value.ToString(CultureInfo.InvariantCulture));
194
+
195
+ public static Json List<T>(IEnumerable<T> items, Func<T, Json> item) => Json.Array(items.Select(item));
196
+
197
+ public static Json Map<T>(IEnumerable<KeyValuePair<string, T>> fields, Func<T, Json> item) =>
198
+ Json.Object(fields.Select(field => new KeyValuePair<string, Json>(field.Key, item(field.Value))));
199
+
200
+ /// <summary>A model's fields: known ones in order, then the ones the SDK did not know; absent optional fields are left out.</summary>
201
+ public static Json Object(IReadOnlyList<KeyValuePair<string, Json>> extra, params (string Name, Json? Value)[] fields) =>
202
+ Json.Object(extra.Concat(fields.Where(field => field.Value != null).Select(field => new KeyValuePair<string, Json>(field.Name, field.Value!))));
203
+ }
204
+
205
+ // @end
206
+ }
@@ -0,0 +1,108 @@
1
+ // sdkloom C# kit: multipart/form-data request bodies.
2
+
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.IO;
6
+ using System.Linq;
7
+ using System.Text;
8
+
9
+ namespace Sdkloom.Runtime
10
+ {
11
+ // @block http.multipart
12
+ // @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.
13
+ // @versions >=3
14
+ // @source [1] https://www.rfc-editor.org/rfc/rfc7578#section-4.2
15
+ // @quote [1] "Each part MUST contain a Content-Disposition header field"
16
+ // @source [2] https://www.rfc-editor.org/rfc/rfc7578#section-4.1
17
+ // @quote [2] "As with other multipart types, the parts are delimited with a boundary delimiter"
18
+ // @retrieved 2026-12-06
19
+ // @tests tests/MultipartTests.cs
20
+ // @requirement SDKL-HTTP-005
21
+
22
+ /// <summary>A text field, or a file when Filename is set.</summary>
23
+ public sealed class MultipartPart
24
+ {
25
+ public MultipartPart(string name, byte[] value, string? filename = null, string? contentType = null)
26
+ {
27
+ Name = name;
28
+ Value = value;
29
+ Filename = filename;
30
+ ContentType = contentType;
31
+ }
32
+
33
+ public string Name { get; }
34
+
35
+ public byte[] Value { get; }
36
+
37
+ public string? Filename { get; }
38
+
39
+ public string? ContentType { get; }
40
+ }
41
+
42
+ /// <summary>Text fields and files in order: new MultipartForm().Field("title", "Q4").File("report", "q4.pdf", "application/pdf", data).</summary>
43
+ public sealed class MultipartForm
44
+ {
45
+ public MultipartForm()
46
+ : this(Array.Empty<MultipartPart>())
47
+ {
48
+ }
49
+
50
+ private MultipartForm(IReadOnlyList<MultipartPart> parts)
51
+ {
52
+ Parts = parts;
53
+ }
54
+
55
+ public IReadOnlyList<MultipartPart> Parts { get; }
56
+
57
+ /// <summary>A copy with a text field added.</summary>
58
+ public MultipartForm Field(string name, string value) => With(new MultipartPart(name, Encoding.UTF8.GetBytes(value)));
59
+
60
+ /// <summary>A copy with a file added.</summary>
61
+ public MultipartForm File(string name, string filename, string contentType, byte[] data) => With(new MultipartPart(name, (byte[])data.Clone(), filename, contentType));
62
+
63
+ private MultipartForm With(MultipartPart part) => new MultipartForm(Parts.Concat(new[] { part }).ToArray());
64
+
65
+ private static string Quoted(string text) => "\"" + text.Replace("\"", "%22").Replace("\r", "%0D").Replace("\n", "%0A") + "\"";
66
+
67
+ /// <summary>The body for this boundary.</summary>
68
+ public byte[] Encode(string boundary)
69
+ {
70
+ using var output = new MemoryStream();
71
+ void Write(string text)
72
+ {
73
+ var bytes = Encoding.UTF8.GetBytes(text);
74
+ output.Write(bytes, 0, bytes.Length);
75
+ }
76
+
77
+ foreach (var part in Parts)
78
+ {
79
+ Write("--" + boundary + "\r\nContent-Disposition: form-data; name=" + Quoted(part.Name));
80
+ if (part.Filename != null)
81
+ {
82
+ Write("; filename=" + Quoted(part.Filename) + "\r\nContent-Type: " + (part.ContentType ?? "application/octet-stream"));
83
+ }
84
+
85
+ Write("\r\n\r\n");
86
+ output.Write(part.Value, 0, part.Value.Length);
87
+ Write("\r\n");
88
+ }
89
+
90
+ Write("--" + boundary + "--\r\n");
91
+ return output.ToArray();
92
+ }
93
+
94
+ /// <summary>The body with a random boundary; the client reads the boundary back from its first line.</summary>
95
+ public byte[] ToBody() => Encode("sdkloom-" + Js.RandomUuid());
96
+
97
+ /// <summary>The boundary of an encoded body: its first line without the leading "--" (and the trailing "--" of an empty form).</summary>
98
+ public static string BoundaryOf(byte[] body)
99
+ {
100
+ var end = Array.IndexOf(body, (byte)'\r');
101
+ var first = Encoding.UTF8.GetString(body, 0, end < 0 ? body.Length : end);
102
+ first = first.StartsWith("--", StringComparison.Ordinal) ? first.Substring(2) : first;
103
+ return first.EndsWith("--", StringComparison.Ordinal) ? first.Substring(0, first.Length - 2) : first;
104
+ }
105
+ }
106
+
107
+ // @end
108
+ }
@@ -0,0 +1,122 @@
1
+ // sdkloom C# kit: iterating over every item of a paginated operation.
2
+
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Runtime.CompilerServices;
6
+ using System.Threading;
7
+ using System.Threading.Tasks;
8
+
9
+ namespace Sdkloom.Runtime
10
+ {
11
+ // @block pagination.iterate
12
+ // @summary Walks the pages of a paginated operation lazily as an IAsyncEnumerable: fetches a page when its items run out, asks for the next call's parameters (a Maybe without a value ends), and observes cancellation between pages.
13
+ // @versions >=3
14
+ // @source [1] https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1
15
+ // @quote [1] "Exposes an enumerator that provides asynchronous iteration over values of a specified type."
16
+ // @retrieved 2026-12-05
17
+ // @tests tests/PaginationTests.cs
18
+ // @requirement SDKL-PAGE-001
19
+
20
+ /// <summary>Iteration over every item of a paginated operation.</summary>
21
+ public static class Pages
22
+ {
23
+ /// <summary>
24
+ /// Every item of every page, fetched one page at a time as the caller iterates:
25
+ /// <c>await foreach (var item in client.ListPaymentsAllAsync(...))</c>.
26
+ /// </summary>
27
+ public static async IAsyncEnumerable<T> Iterate<TParams, TPage, T>(
28
+ TParams first,
29
+ Func<TParams, CancellationToken, Task<TPage>> fetch,
30
+ Func<TPage, IReadOnlyList<T>> items,
31
+ Func<TParams, TPage, IReadOnlyList<T>, Maybe<TParams>> next,
32
+ [EnumeratorCancellation] CancellationToken cancellationToken = default)
33
+ {
34
+ var current = new Maybe<TParams>(first);
35
+ while (current.IsSet)
36
+ {
37
+ cancellationToken.ThrowIfCancellationRequested();
38
+ var page = await fetch(current.Value, cancellationToken).ConfigureAwait(false);
39
+ var found = items(page);
40
+ foreach (var item in found)
41
+ {
42
+ yield return item;
43
+ }
44
+
45
+ current = next(current.Value, page, found);
46
+ }
47
+ }
48
+ }
49
+
50
+ // @end
51
+
52
+ // @block pagination.link
53
+ // @summary Finds the next page's URL in a Link header (RFC 8288): splits link-values at commas outside <...>, reads the rel parameter (quoted or not, several relation types allowed, compared case-insensitively) and returns the target of rel="next"; resolves it against the base URL.
54
+ // @versions >=3
55
+ // @source [1] https://www.rfc-editor.org/rfc/rfc8288#section-3
56
+ // @quote [1] "The Link header field provides a means for serialising one or more links into HTTP headers."
57
+ // @quote [1] "The rel parameter can, however, contain multiple link relation types."
58
+ // @quote [1] "MUST be compared character by character in a case-insensitive fashion."
59
+ // @retrieved 2026-12-06
60
+ // @tests tests/PaginationTests.cs
61
+ // @requirement SDKL-PAGE-001
62
+
63
+ /// <summary>Following Link headers to the next page.</summary>
64
+ public static class Links
65
+ {
66
+ private static readonly System.Text.RegularExpressions.Regex LinkValue = new System.Text.RegularExpressions.Regex("<([^>]*)>([^,]*)", System.Text.RegularExpressions.RegexOptions.CultureInvariant);
67
+
68
+ /// <summary>The URL of the link with relation type "next" in a Link header, or null.</summary>
69
+ public static string? Next(string? header)
70
+ {
71
+ if (header == null)
72
+ {
73
+ return null;
74
+ }
75
+
76
+ foreach (System.Text.RegularExpressions.Match match in LinkValue.Matches(header))
77
+ {
78
+ foreach (var param in match.Groups[2].Value.Split(';'))
79
+ {
80
+ var equals = param.IndexOf('=');
81
+ if (equals < 0 || !string.Equals(param.Substring(0, equals).Trim(), "rel", StringComparison.OrdinalIgnoreCase))
82
+ {
83
+ continue;
84
+ }
85
+
86
+ var kinds = param.Substring(equals + 1).Trim().Trim('"').Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
87
+ foreach (var kind in kinds)
88
+ {
89
+ if (string.Equals(kind, "next", StringComparison.OrdinalIgnoreCase))
90
+ {
91
+ return match.Groups[1].Value;
92
+ }
93
+ }
94
+
95
+ break;
96
+ }
97
+ }
98
+
99
+ return null;
100
+ }
101
+
102
+ /// <summary>A URL from the API resolved against the base URL: absolute as is, "/path" on the base's origin, else after it.</summary>
103
+ public static string Resolve(string baseUrl, string url)
104
+ {
105
+ if (url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
106
+ {
107
+ return url;
108
+ }
109
+
110
+ if (url.StartsWith("/", StringComparison.Ordinal))
111
+ {
112
+ var schemeEnd = baseUrl.IndexOf("://", StringComparison.Ordinal);
113
+ var originEnd = schemeEnd < 0 ? -1 : baseUrl.IndexOf('/', schemeEnd + 3);
114
+ return (originEnd < 0 ? baseUrl : baseUrl.Substring(0, originEnd)) + url;
115
+ }
116
+
117
+ return baseUrl.TrimEnd('/') + "/" + url;
118
+ }
119
+ }
120
+
121
+ // @end
122
+ }