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,63 @@
1
+ // sdkloom TypeScript kit: errors.
2
+
3
+ import type { HttpResponse } from "./http.ts";
4
+
5
+ // @block errors.api_error
6
+ // @summary The error for a non-2xx response; carries status, decoded body and request id, and marks 429 and 5xx as retryable.
7
+ // @versions >=18
8
+ // @source [1] https://www.rfc-editor.org/rfc/rfc9110#section-15.5
9
+ // @quote [1] "The 4xx (Client Error) class of status code indicates that the client seems to have erred."
10
+ // @source [2] https://www.rfc-editor.org/rfc/rfc9110#section-15.6
11
+ // @quote [2] "The 5xx (Server Error) class of status code indicates that the server is aware that it has erred or is incapable of performing the requested method."
12
+ // @retrieved 2026-12-05
13
+ // @tests tests/client.test.ts
14
+ // @requirement SDKL-ERR-001
15
+ const TOO_MANY_REQUESTS = 429;
16
+ const FIRST_SERVER_ERROR = 500;
17
+
18
+ export class ApiError extends Error {
19
+ readonly status: number;
20
+ readonly body: unknown;
21
+ readonly response: HttpResponse;
22
+ readonly requestId: string | undefined;
23
+
24
+ constructor(status: number, body: unknown, response: HttpResponse, name = "ApiError") {
25
+ super(`${name}: HTTP ${status}`);
26
+ this.name = name;
27
+ this.status = status;
28
+ this.body = body;
29
+ this.response = response;
30
+ this.requestId = response.header("x-request-id");
31
+ }
32
+
33
+ /** True for 429 and 5xx: sending the same request again may succeed. */
34
+ get retryable(): boolean {
35
+ return this.status === TOO_MANY_REQUESTS || this.status >= FIRST_SERVER_ERROR;
36
+ }
37
+ }
38
+
39
+ export type ErrorFactory = (status: number, body: unknown, response: HttpResponse) => ApiError;
40
+ // @end
41
+
42
+ // @block errors.transport_error
43
+ // @summary The error for a request that got no HTTP response: a network failure, a timeout or a cancellation.
44
+ // @versions >=18
45
+ // @source [1] https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch
46
+ // @quote [1] "The fetch() method of the Window interface starts the process of fetching a resource from the network, returning a promise that is fulfilled once the response is available."
47
+ // @source [2] https://developer.mozilla.org/en-US/docs/Web/API/AbortController
48
+ // @quote [2] "The AbortController interface represents a controller object that allows you to abort one or more Web requests as and when desired."
49
+ // @retrieved 2026-12-05
50
+ // @tests tests/transport.test.ts
51
+ // @requirement SDKL-HTTP-004
52
+ export type TransportFailure = "network" | "timeout" | "aborted";
53
+
54
+ export class TransportError extends Error {
55
+ readonly reason: TransportFailure;
56
+
57
+ constructor(reason: TransportFailure, cause?: unknown) {
58
+ super(`request failed: ${reason}`, { cause });
59
+ this.name = "TransportError";
60
+ this.reason = reason;
61
+ }
62
+ }
63
+ // @end
@@ -0,0 +1,49 @@
1
+ // sdkloom TypeScript kit: helpers middleware may call (imported from @sdkloom/core when the middleware is written).
2
+
3
+ import { hmacSha256 } from "./webhooks.ts";
4
+
5
+ // @block middleware.helpers
6
+ // @summary randomUUID() makes a version 4 UUID from the platform's cryptographic random source (Math.random only where none exists); hmacSha256Hex and hmacSha256Base64 sign UTF-8 text with a UTF-8 key.
7
+ // @versions >=18
8
+ // @source [1] https://www.rfc-editor.org/rfc/rfc9562#section-5.4
9
+ // @quote [1] "UUIDv4 is meant for generating UUIDs from truly random or pseudorandom numbers."
10
+ // @source [2] https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
11
+ // @quote [2] "The Crypto.getRandomValues() method lets you get cryptographically strong random values."
12
+ // @retrieved 2026-12-06
13
+ // @tests tests/helpers.test.ts
14
+ // @requirement SDKL-HELP-001
15
+
16
+ interface WebCrypto {
17
+ getRandomValues?(array: Uint8Array): Uint8Array;
18
+ }
19
+
20
+ function randomBytes(count: number): Uint8Array {
21
+ const bytes = new Uint8Array(count);
22
+ const crypto = (globalThis as { readonly crypto?: WebCrypto }).crypto;
23
+ if (crypto?.getRandomValues !== undefined) return crypto.getRandomValues(bytes);
24
+ return bytes.map(() => Math.floor(Math.random() * 256));
25
+ }
26
+
27
+ const hex = (bytes: Uint8Array): string => Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
28
+
29
+ /** A random version 4 UUID in lower case, e.g. "3f2b8c1e-7d4a-4f6b-9a2e-5c8d1b0e7f3a". */
30
+ export function randomUUID(): string {
31
+ const bytes = randomBytes(16);
32
+ bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40;
33
+ bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;
34
+ const text = hex(bytes);
35
+ return `${text.slice(0, 8)}-${text.slice(8, 12)}-${text.slice(12, 16)}-${text.slice(16, 20)}-${text.slice(20)}`;
36
+ }
37
+
38
+ const utf8 = (text: string): Uint8Array => new TextEncoder().encode(text);
39
+
40
+ /** HMAC-SHA256 of the text, in lower-case hex. */
41
+ export function hmacSha256Hex(key: string, text: string): string {
42
+ return hex(hmacSha256(utf8(key), utf8(text)));
43
+ }
44
+
45
+ /** HMAC-SHA256 of the text, in Base64. */
46
+ export function hmacSha256Base64(key: string, text: string): string {
47
+ return btoa(String.fromCharCode(...hmacSha256(utf8(key), utf8(text))));
48
+ }
49
+ // @end
@@ -0,0 +1,192 @@
1
+ // sdkloom TypeScript kit: HTTP request and response values, URL building.
2
+
3
+ // @block http.request
4
+ // @summary An immutable HTTP request whose header names are matched case-insensitively.
5
+ // @versions >=18
6
+ // @source [1] https://www.rfc-editor.org/rfc/rfc9110#section-5.1
7
+ // @quote [1] "Field names are case-insensitive"
8
+ // @retrieved 2026-12-05
9
+ // @tests tests/http.test.ts
10
+ // @requirement SDKL-HTTP-001
11
+ export type HeaderList = readonly (readonly [string, string])[];
12
+ export type RequestBody = Uint8Array | AsyncIterable<Uint8Array>;
13
+
14
+ export function findHeader(headers: HeaderList, name: string): string | undefined {
15
+ const key = name.toLowerCase();
16
+ return headers.find(([candidate]) => candidate.toLowerCase() === key)?.[1];
17
+ }
18
+
19
+ function withoutHeaderName(headers: HeaderList, name: string): HeaderList {
20
+ const key = name.toLowerCase();
21
+ return headers.filter(([candidate]) => candidate.toLowerCase() !== key);
22
+ }
23
+
24
+ export class HttpRequest {
25
+ readonly method: string;
26
+ readonly url: string;
27
+ readonly headers: HeaderList;
28
+ readonly body: RequestBody | undefined;
29
+
30
+ constructor(method: string, url: string, headers: HeaderList = [], body?: RequestBody) {
31
+ this.method = method;
32
+ this.url = url;
33
+ this.headers = headers;
34
+ this.body = body;
35
+ }
36
+
37
+ header(name: string): string | undefined {
38
+ return findHeader(this.headers, name);
39
+ }
40
+
41
+ withHeader(name: string, value: string): HttpRequest {
42
+ return new HttpRequest(this.method, this.url, [...withoutHeaderName(this.headers, name), [name, value]], this.body);
43
+ }
44
+
45
+ withoutHeader(name: string): HttpRequest {
46
+ return new HttpRequest(this.method, this.url, withoutHeaderName(this.headers, name), this.body);
47
+ }
48
+
49
+ withUrl(url: string): HttpRequest {
50
+ return new HttpRequest(this.method, url, this.headers, this.body);
51
+ }
52
+
53
+ /** A copy with another body; text is sent as UTF-8. */
54
+ withBody(body: RequestBody | string | undefined): HttpRequest {
55
+ return new HttpRequest(this.method, this.url, this.headers, typeof body === "string" ? new TextEncoder().encode(body) : body);
56
+ }
57
+
58
+ /** The body as UTF-8 text, "" without one; a streamed body cannot be read without consuming it, so it fails. */
59
+ text(): string {
60
+ if (this.body === undefined) return "";
61
+ if (this.body instanceof Uint8Array) return new TextDecoder().decode(this.body);
62
+ throw new Error("the request body is a stream; it cannot be read as text");
63
+ }
64
+ }
65
+ // @end
66
+
67
+ // @block http.response
68
+ // @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.
69
+ // @versions >=18
70
+ // @source [1] https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder
71
+ // @quote [1] "A decoder takes an array of bytes as input and returns a JavaScript string."
72
+ // @source [2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
73
+ // @quote [2] "The JSON.parse() static method parses a JSON string, constructing the JavaScript value or object described by the string."
74
+ // @retrieved 2026-12-05
75
+ // @tests tests/http.test.ts
76
+ // @requirement SDKL-HTTP-003
77
+ export async function collectBytes(body: RequestBody): Promise<Uint8Array> {
78
+ if (body instanceof Uint8Array) return body;
79
+ const chunks: Uint8Array[] = [];
80
+ for await (const chunk of body) chunks.push(chunk);
81
+ const result = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));
82
+ chunks.reduce((offset, chunk) => {
83
+ result.set(chunk, offset);
84
+ return offset + chunk.length;
85
+ }, 0);
86
+ return result;
87
+ }
88
+
89
+ export class HttpResponse {
90
+ readonly status: number;
91
+ readonly headers: HeaderList;
92
+ readonly #body: RequestBody;
93
+ #bytes: Promise<Uint8Array> | undefined;
94
+
95
+ constructor(status: number, headers: HeaderList, body: RequestBody) {
96
+ this.status = status;
97
+ this.headers = headers;
98
+ this.#body = body;
99
+ }
100
+
101
+ header(name: string): string | undefined {
102
+ return findHeader(this.headers, name);
103
+ }
104
+
105
+ bytes(): Promise<Uint8Array> {
106
+ this.#bytes ??= collectBytes(this.#body);
107
+ return this.#bytes;
108
+ }
109
+
110
+ /** The body as it arrives, for a streamed response; a buffered body comes as one chunk. Read it once. */
111
+ async *chunks(): AsyncGenerator<Uint8Array, void, undefined> {
112
+ if (this.#body instanceof Uint8Array || this.#bytes !== undefined) {
113
+ yield await this.bytes();
114
+ return;
115
+ }
116
+ yield* this.#body;
117
+ }
118
+
119
+ async text(): Promise<string> {
120
+ return new TextDecoder().decode(await this.bytes());
121
+ }
122
+
123
+ async json(): Promise<unknown> {
124
+ const text = await this.text();
125
+ return text === "" ? undefined : (JSON.parse(text) as unknown);
126
+ }
127
+ }
128
+ // @end
129
+
130
+ // @block http.url
131
+ // @summary Builds a request URL: percent-encodes path parameters and appends query parameters in order. 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.
132
+ // @versions >=18
133
+ // @source [1] https://www.rfc-editor.org/rfc/rfc3986#section-2.1
134
+ // @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."
135
+ // @source [2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
136
+ // @quote [2] "Compared to encodeURI(), this function encodes more characters, including those that are part of the URI syntax."
137
+ // @source [3] https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
138
+ // @quote [3] "The URLSearchParams interface defines utility methods to work with the query string of a URL."
139
+ // @source [4] https://www.rfc-editor.org/rfc/rfc3986#section-3.3
140
+ // @quote [4] "also known as dot-segments, are defined for relative reference within the path name hierarchy."
141
+ // @source [5] https://www.rfc-editor.org/rfc/rfc6570#section-3.2.3
142
+ // @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."
143
+ // @retrieved 2026-12-05
144
+ // @tests tests/http.test.ts
145
+ // @requirement SDKL-HTTP-002
146
+ export type QueryScalar = string | number | boolean;
147
+ export type QueryValue = QueryScalar | readonly QueryScalar[] | undefined;
148
+
149
+ const PLACEHOLDER = /\{([^{}]+)\}/g;
150
+
151
+ /** A call argument the SDK cannot send, found before any request is made. */
152
+ export class ArgumentError extends Error {
153
+ constructor(message: string) {
154
+ super(message);
155
+ this.name = "ArgumentError";
156
+ }
157
+ }
158
+
159
+ /**
160
+ * A path parameter as one encoded segment. "." and ".." are refused: URL parsers treat them, even percent-encoded, as
161
+ * steps up the path, so the request would reach another resource.
162
+ */
163
+ export function pathSegment(name: string, value: QueryScalar): string {
164
+ const text = String(value);
165
+ if (text === "." || text === "..") throw new ArgumentError(`path parameter ${name} cannot be "${text}": a URL would read it as a step up the path`);
166
+ return encodeURIComponent(text);
167
+ }
168
+
169
+ export function buildUrl(
170
+ base: string,
171
+ template: string,
172
+ pathParams: Readonly<Record<string, QueryScalar>>,
173
+ query: readonly (readonly [string, QueryValue])[],
174
+ ): string {
175
+ const path = template.replace(PLACEHOLDER, (_match: string, placeholder: string) => {
176
+ // {+name} (RFC 6570 reserved expansion, limited to "/"): the value may span segments, each encoded on its own.
177
+ const reserved = placeholder.startsWith("+");
178
+ const name = reserved ? placeholder.slice(1) : placeholder;
179
+ const value = pathParams[name];
180
+ if (value === undefined) throw new ArgumentError(`missing path parameter ${name}`);
181
+ return reserved ? String(value).split("/").map((segment) => pathSegment(name, segment)).join("/") : pathSegment(name, value);
182
+ });
183
+ const search = new URLSearchParams();
184
+ for (const [name, value] of query) {
185
+ if (value === undefined) continue;
186
+ const items: readonly QueryScalar[] = typeof value === "object" ? value : [value];
187
+ items.forEach((item) => search.append(name, String(item)));
188
+ }
189
+ const queryString = search.toString();
190
+ return `${base.replace(/\/+$/, "")}${path}${queryString === "" ? "" : `?${queryString}`}`;
191
+ }
192
+ // @end
@@ -0,0 +1,139 @@
1
+ // sdkloom TypeScript kit: decoding and encoding JSON values.
2
+
3
+ // @block models.decode
4
+ // @summary Checks decoded JSON against the expected type; keeps object fields and enum values it does not know. Null for an optional field that cannot be null reads as absent: many servers send null for a field they leave out.
5
+ // @versions >=18
6
+ // @source [1] https://www.rfc-editor.org/rfc/rfc8259#section-4
7
+ // @quote [1] "An object structure is represented as a pair of curly brackets surrounding zero or more name/value pairs (or members)."
8
+ // @retrieved 2026-12-05
9
+ // @tests tests/models.test.ts
10
+ // @requirement SDKL-JSON-001
11
+ // @requirement SDKL-JSON-002
12
+ // @requirement SDKL-JSON-003
13
+ export type JsonObject = { readonly [key: string]: unknown };
14
+ export type Decoder<T> = (value: unknown, path: string) => T;
15
+
16
+ export class DecodeError extends Error {
17
+ readonly path: string;
18
+
19
+ constructor(path: string, message: string) {
20
+ super(`${path}: ${message}`);
21
+ this.name = "DecodeError";
22
+ this.path = path;
23
+ }
24
+ }
25
+
26
+ function describe(value: unknown): string {
27
+ if (value === null) return "null";
28
+ if (Array.isArray(value)) return "array";
29
+ if (typeof value === "string") return `string ${JSON.stringify(value)}`;
30
+ if (typeof value === "object") return "object";
31
+ return `${typeof value} ${String(value)}`;
32
+ }
33
+
34
+ function mismatch(path: string, expected: string, value: unknown): DecodeError {
35
+ return new DecodeError(path, `expected ${expected}, got ${describe(value)}`);
36
+ }
37
+
38
+ const DECIMAL = /^-?\d+(\.\d+)?$/;
39
+
40
+ export function asObject(value: unknown, path: string): JsonObject {
41
+ if (typeof value !== "object" || value === null || Array.isArray(value)) throw mismatch(path, "an object", value);
42
+ return value as JsonObject;
43
+ }
44
+
45
+ export function asString(value: unknown, path: string): string {
46
+ if (typeof value !== "string") throw mismatch(path, "a string", value);
47
+ return value;
48
+ }
49
+
50
+ export function asNumber(value: unknown, path: string): number {
51
+ if (typeof value !== "number" || !Number.isFinite(value)) throw mismatch(path, "a number", value);
52
+ return value;
53
+ }
54
+
55
+ export function asInteger(value: unknown, path: string): number {
56
+ if (typeof value !== "number" || !Number.isInteger(value)) throw mismatch(path, "an integer", value);
57
+ return value;
58
+ }
59
+
60
+ export function asBoolean(value: unknown, path: string): boolean {
61
+ if (typeof value !== "boolean") throw mismatch(path, "a boolean", value);
62
+ return value;
63
+ }
64
+
65
+ /** Decimals travel as strings to keep every digit; plain JSON numbers are accepted too. */
66
+ export function asDecimal(value: unknown, path: string): string {
67
+ if (typeof value === "number" && Number.isFinite(value)) return String(value);
68
+ if (typeof value === "string" && DECIMAL.test(value)) return value;
69
+ throw mismatch(path, "a decimal", value);
70
+ }
71
+
72
+ /** Any string is accepted so a value added by the server later does not break the SDK. */
73
+ export function asEnum<V extends string>(value: unknown, path: string, known: readonly V[]): V | (string & {}) {
74
+ if (typeof value !== "string") throw mismatch(path, `one of ${known.join(", ")}`, value);
75
+ return value;
76
+ }
77
+
78
+ export function asArray<T>(value: unknown, path: string, item: Decoder<T>): T[] {
79
+ if (!Array.isArray(value)) throw mismatch(path, "an array", value);
80
+ return value.map((entry: unknown, index) => item(entry, `${path}[${index}]`));
81
+ }
82
+
83
+ export function asMap<T>(value: unknown, path: string, item: Decoder<T>): Record<string, T> {
84
+ const object = asObject(value, path);
85
+ return Object.fromEntries(Object.entries(object).map(([key, entry]) => [key, item(entry, `${path}.${key}`)]));
86
+ }
87
+
88
+ /**
89
+ * The object without the given keys. Generated decoders keep fields they do not know by spreading the object, then set
90
+ * the known ones; an optional field read as absent (null where it cannot be null) must not come back through the spread.
91
+ */
92
+ export function omit(object: JsonObject, keys: readonly string[]): JsonObject {
93
+ return Object.fromEntries(Object.entries(object).filter(([key]) => !keys.includes(key)));
94
+ }
95
+
96
+ export interface FieldFlags {
97
+ readonly optional: boolean;
98
+ readonly nullable: boolean;
99
+ }
100
+
101
+ /**
102
+ * Reads one field: absent is allowed only when optional, null when nullable. Many servers send null for a field they
103
+ * leave out, so null for an optional field that cannot be null reads as absent.
104
+ */
105
+ export function field<T>(object: JsonObject, name: string, path: string, decode: Decoder<T>, flags: FieldFlags): T | undefined | null {
106
+ const fieldPath = `${path}.${name}`;
107
+ const value = object[name];
108
+ if (value === undefined) {
109
+ if (flags.optional) return undefined;
110
+ throw new DecodeError(fieldPath, "is required");
111
+ }
112
+ if (value === null && flags.nullable) return null;
113
+ if (value === null && flags.optional) return undefined;
114
+ return decode(value, fieldPath);
115
+ }
116
+ // @end
117
+
118
+ // @block models.encode
119
+ // @summary Serializes a value as UTF-8 JSON; fields set to undefined are left out and unknown union variants are written back exactly as received.
120
+ // @versions >=18
121
+ // @source [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
122
+ // @quote [1] "The JSON.stringify() static method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified."
123
+ // @source [2] https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder
124
+ // @quote [2] "The TextEncoder interface enables you to encode a JavaScript string using UTF-8."
125
+ // @retrieved 2026-12-05
126
+ // @tests tests/models.test.ts
127
+ // @requirement SDKL-JSON-001
128
+ // @requirement SDKL-JSON-004
129
+ function isUnknownVariant(value: unknown): value is { readonly raw: unknown } {
130
+ if (typeof value !== "object" || value === null) return false;
131
+ const candidate = value as Readonly<Record<string, unknown>>;
132
+ // The tag field is the union's discriminator ("type", "kind", ...), so any field may carry the "$unknown" marker.
133
+ return typeof candidate["unknownTag"] === "string" && typeof candidate["raw"] === "object" && Object.values(candidate).includes("$unknown");
134
+ }
135
+
136
+ export function encodeJson(value: unknown): Uint8Array {
137
+ return new TextEncoder().encode(JSON.stringify(value, (_key, item: unknown) => (isUnknownVariant(item) ? item.raw : item)));
138
+ }
139
+ // @end
@@ -0,0 +1,66 @@
1
+ // sdkloom TypeScript kit: multipart/form-data request bodies.
2
+
3
+ import { randomUUID } from "./helpers.ts";
4
+
5
+ // @block http.multipart
6
+ // @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.
7
+ // @versions >=18
8
+ // @source [1] https://www.rfc-editor.org/rfc/rfc7578#section-4.2
9
+ // @quote [1] "Each part MUST contain a Content-Disposition header field"
10
+ // @source [2] https://www.rfc-editor.org/rfc/rfc7578#section-4.1
11
+ // @quote [2] "As with other multipart types, the parts are delimited with a boundary delimiter"
12
+ // @retrieved 2026-12-06
13
+ // @tests tests/multipart.test.ts
14
+ // @requirement SDKL-HTTP-005
15
+
16
+ export interface MultipartPart {
17
+ readonly name: string;
18
+ readonly value: string | Uint8Array;
19
+ readonly filename?: string;
20
+ readonly contentType?: string;
21
+ }
22
+
23
+ /** Text fields and files, in order: new MultipartForm().field("title", "Q4").file("report", "q4.pdf", "application/pdf", bytes). */
24
+ export class MultipartForm {
25
+ readonly parts: readonly MultipartPart[];
26
+
27
+ constructor(parts: readonly MultipartPart[] = []) {
28
+ this.parts = parts;
29
+ }
30
+
31
+ /** A copy with a text field added. */
32
+ field(name: string, value: string): MultipartForm {
33
+ return new MultipartForm([...this.parts, { name, value }]);
34
+ }
35
+
36
+ /** A copy with a file added. */
37
+ file(name: string, filename: string, contentType: string, data: Uint8Array): MultipartForm {
38
+ return new MultipartForm([...this.parts, { name, value: data, filename, contentType }]);
39
+ }
40
+ }
41
+
42
+ /** A name or file name inside quotes: " CR and LF percent-encoded, as browsers send them. */
43
+ function quoted(text: string): string {
44
+ return `"${text.replace(/"/g, "%22").replace(/\r/g, "%0D").replace(/\n/g, "%0A")}"`;
45
+ }
46
+
47
+ /** The body bytes and the Content-Type header with its boundary. */
48
+ export function encodeMultipart(form: MultipartForm, boundary = `sdkloom-${randomUUID()}`): { readonly content: Uint8Array; readonly type: string } {
49
+ const encoder = new TextEncoder();
50
+ const chunks: Uint8Array[] = [];
51
+ for (const part of form.parts) {
52
+ const disposition = `Content-Disposition: form-data; name=${quoted(part.name)}${part.filename === undefined ? "" : `; filename=${quoted(part.filename)}`}`;
53
+ const type = part.filename === undefined ? "" : `\r\nContent-Type: ${part.contentType ?? "application/octet-stream"}`;
54
+ chunks.push(encoder.encode(`--${boundary}\r\n${disposition}${type}\r\n\r\n`));
55
+ chunks.push(typeof part.value === "string" ? encoder.encode(part.value) : part.value);
56
+ chunks.push(encoder.encode("\r\n"));
57
+ }
58
+ chunks.push(encoder.encode(`--${boundary}--\r\n`));
59
+ const content = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));
60
+ chunks.reduce((offset, chunk) => {
61
+ content.set(chunk, offset);
62
+ return offset + chunk.length;
63
+ }, 0);
64
+ return { content, type: `multipart/form-data; boundary=${boundary}` };
65
+ }
66
+ // @end
@@ -0,0 +1,54 @@
1
+ // sdkloom TypeScript kit: iterating over every item of a paginated operation.
2
+
3
+ // @block pagination.iterate
4
+ // @summary Walks the pages of a paginated operation lazily: fetches a page, yields its items, asks for the next call's parameters (undefined ends), so callers write one for await loop.
5
+ // @versions >=18
6
+ // @source [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function*
7
+ // @quote [1] "The async function* declaration creates a binding of a new async generator function to a given name."
8
+ // @retrieved 2026-12-05
9
+ // @tests tests/pagination.test.ts
10
+ // @requirement SDKL-PAGE-001
11
+
12
+ /** The parameters of the next call, or undefined after the last page. */
13
+ export type NextPage<P, R, T> = (params: P, page: R, items: readonly T[]) => P | undefined;
14
+
15
+ /** Every item of every page, fetched one page at a time as the caller iterates. */
16
+ export async function* paginate<P, R, T>(first: P, fetch: (params: P) => Promise<R>, items: (page: R) => readonly T[], next: NextPage<P, R, T>): AsyncGenerator<T, void, undefined> {
17
+ let params: P | undefined = first;
18
+ while (params !== undefined) {
19
+ const page = await fetch(params);
20
+ const found = items(page);
21
+ yield* found;
22
+ params = next(params, page, found);
23
+ }
24
+ }
25
+ // @end
26
+
27
+ // @block pagination.link
28
+ // @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".
29
+ // @versions >=18
30
+ // @source [1] https://www.rfc-editor.org/rfc/rfc8288#section-3
31
+ // @quote [1] "The Link header field provides a means for serialising one or more links into HTTP headers."
32
+ // @quote [1] "The rel parameter can, however, contain multiple link relation types."
33
+ // @quote [1] "MUST be compared character by character in a case-insensitive fashion."
34
+ // @retrieved 2026-12-06
35
+ // @tests tests/pagination.test.ts
36
+ // @requirement SDKL-PAGE-001
37
+
38
+ /** The URL of the link with relation type "next" in a Link header, or undefined. */
39
+ export function nextLink(header: string | undefined): string | undefined {
40
+ if (header === undefined) return undefined;
41
+ for (const value of header.match(/<[^>]*>[^,]*/g) ?? []) {
42
+ const target = value.slice(1, value.indexOf(">"));
43
+ const params = value.slice(value.indexOf(">") + 1).split(";");
44
+ for (const param of params) {
45
+ const [name, raw] = param.split("=").map((part) => part.trim());
46
+ if (name?.toLowerCase() !== "rel" || raw === undefined) continue;
47
+ const types = raw.replace(/^"|"$/g, "").toLowerCase().split(/\s+/);
48
+ if (types.includes("next")) return target;
49
+ break;
50
+ }
51
+ }
52
+ return undefined;
53
+ }
54
+ // @end
@@ -0,0 +1,25 @@
1
+ // sdkloom TypeScript kit: the middleware pipeline.
2
+
3
+ import type { HttpRequest, HttpResponse } from "./http.ts";
4
+
5
+ // @block pipeline.run
6
+ // @summary Runs handlers in order around a final step; each handler may call next zero or more times.
7
+ // @versions >=18
8
+ // @source [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
9
+ // @quote [1] "The await keyword is permitted within the function body, enabling asynchronous, promise-based behavior to be written in a cleaner style and avoiding the need to explicitly configure promise chains."
10
+ // @retrieved 2026-12-05
11
+ // @tests tests/client.test.ts
12
+ // @requirement SDKL-PIPE-001
13
+ export type Next = (request: HttpRequest) => Promise<HttpResponse>;
14
+ export type Handler = (request: HttpRequest, next: Next) => Promise<HttpResponse>;
15
+
16
+ export function runPipeline(handlers: readonly Handler[], request: HttpRequest, last: Next): Promise<HttpResponse> {
17
+ const step =
18
+ (index: number): Next =>
19
+ (current) => {
20
+ const handler = handlers[index];
21
+ return handler === undefined ? last(current) : handler(current, step(index + 1));
22
+ };
23
+ return step(0)(request);
24
+ }
25
+ // @end