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,462 @@
1
+ // sdkloom Go kit: JavaScript semantics that transpiled middleware relies on.
2
+ package sdkruntime
3
+
4
+ import (
5
+ "crypto/hmac"
6
+ "crypto/rand"
7
+ "crypto/sha256"
8
+ "encoding/base64"
9
+ "encoding/hex"
10
+ "encoding/json"
11
+ "errors"
12
+ "fmt"
13
+ "math"
14
+ "reflect"
15
+ "regexp"
16
+ "strconv"
17
+ "strings"
18
+ )
19
+
20
+ // @block lang.js
21
+ // @summary String(value), Number(text), btoa(text), ===, /, **, the % remainder, error.message and JSON field reads with JavaScript's results, so transpiled middleware behaves like its TypeScript source.
22
+ // @versions >=1.18
23
+ // @source [1] https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-tostring
24
+ // @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."
25
+ // @source [2] https://pkg.go.dev/strconv
26
+ // @quote [2] "The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly."
27
+ // @source [3] https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-remainder
28
+ // @quote [3] "The sign of the result is the sign of the dividend."
29
+ // @source [4] https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa
30
+ // @quote [4] "The string contained a character that did not fit in a single byte."
31
+ // @retrieved 2026-12-05
32
+ // @tests tests/lang_test.go
33
+ // @requirement SDKL-XPILE-001
34
+
35
+ // JsNumberString writes a float64 as JavaScript's String(number) does: shortest digits, plain between 1e-7 and 1e21.
36
+ func JsNumberString(value float64) string {
37
+ switch {
38
+ case math.IsNaN(value):
39
+ return "NaN"
40
+ case math.IsInf(value, 1):
41
+ return "Infinity"
42
+ case math.IsInf(value, -1):
43
+ return "-Infinity"
44
+ case value == 0:
45
+ return "0"
46
+ }
47
+ sign := ""
48
+ if value < 0 {
49
+ sign, value = "-", -value
50
+ }
51
+ scientific := strconv.FormatFloat(value, 'e', -1, 64)
52
+ mark := strings.IndexByte(scientific, 'e')
53
+ digits := strings.Replace(scientific[:mark], ".", "", 1)
54
+ exponent, _ := strconv.Atoi(scientific[mark+1:])
55
+ if value >= 1e21 || value < 1e-6 {
56
+ mantissa := digits[:1]
57
+ if len(digits) > 1 {
58
+ mantissa += "." + digits[1:]
59
+ }
60
+ if exponent >= 0 {
61
+ return sign + mantissa + "e+" + strconv.Itoa(exponent)
62
+ }
63
+ return sign + mantissa + "e-" + strconv.Itoa(-exponent)
64
+ }
65
+ point := exponent + 1
66
+ if point <= 0 {
67
+ return sign + "0." + strings.Repeat("0", -point) + digits
68
+ }
69
+ if point >= len(digits) {
70
+ return sign + digits + strings.Repeat("0", point-len(digits))
71
+ }
72
+ return sign + digits[:point] + "." + digits[point:]
73
+ }
74
+
75
+ // JsStr is String(value). Absent values (nil) become "null", lists join with commas.
76
+ func JsStr(value any) string {
77
+ switch v := value.(type) {
78
+ case nil:
79
+ return "null"
80
+ case bool:
81
+ if v {
82
+ return "true"
83
+ }
84
+ return "false"
85
+ case string:
86
+ return v
87
+ case *string:
88
+ if v == nil {
89
+ return "null"
90
+ }
91
+ return *v
92
+ case Decimal:
93
+ return plainNumber(string(v))
94
+ case int:
95
+ return strconv.Itoa(v)
96
+ case int64:
97
+ return strconv.FormatInt(v, 10)
98
+ case int32:
99
+ return strconv.FormatInt(int64(v), 10)
100
+ case float64:
101
+ return JsNumberString(v)
102
+ case float32:
103
+ return JsNumberString(float64(v))
104
+ case json.Number:
105
+ if parsed, err := strconv.ParseInt(v.String(), 10, 64); err == nil {
106
+ return strconv.FormatInt(parsed, 10)
107
+ }
108
+ parsed, _ := v.Float64()
109
+ return JsNumberString(parsed)
110
+ case []any:
111
+ parts := make([]string, len(v))
112
+ for i, item := range v {
113
+ if item != nil {
114
+ parts[i] = JsStr(item)
115
+ }
116
+ }
117
+ return strings.Join(parts, ",")
118
+ default:
119
+ return "[object Object]"
120
+ }
121
+ }
122
+
123
+ var (
124
+ hexText = regexp.MustCompile(`^0[xX][0-9a-fA-F]+$`)
125
+ decimalForm = regexp.MustCompile(`^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$`)
126
+ )
127
+
128
+ // jsSpace is what String.prototype.trim removes: white space and line terminators, including no-break space and BOM.
129
+ func jsSpace(r rune) bool {
130
+ switch r {
131
+ case '\t', '\n', '\v', '\f', '\r', ' ', 0xA0, 0x1680, 0x2028, 0x2029, 0x202F, 0x205F, 0x3000, 0xFEFF:
132
+ return true
133
+ }
134
+ return r >= 0x2000 && r <= 0x200A
135
+ }
136
+
137
+ // JsNumber is Number(text): trimmed, "" is 0, hex is allowed, anything else is NaN.
138
+ func JsNumber(text any) float64 {
139
+ trimmed := strings.TrimFunc(JsStr(text), jsSpace)
140
+ switch {
141
+ case trimmed == "":
142
+ return 0
143
+ case hexText.MatchString(trimmed):
144
+ parsed, err := strconv.ParseUint(trimmed[2:], 16, 64)
145
+ if err != nil {
146
+ return math.Inf(1)
147
+ }
148
+ return float64(parsed)
149
+ case trimmed == "Infinity" || trimmed == "+Infinity":
150
+ return math.Inf(1)
151
+ case trimmed == "-Infinity":
152
+ return math.Inf(-1)
153
+ case !decimalForm.MatchString(trimmed):
154
+ return math.NaN()
155
+ }
156
+ parsed, err := strconv.ParseFloat(trimmed, 64)
157
+ if err != nil && !errors.Is(err, strconv.ErrRange) {
158
+ return math.NaN()
159
+ }
160
+ return parsed
161
+ }
162
+
163
+ // JsMod is a % b for integers: the result takes the sign of the dividend. Division by zero is an error in Go, NaN in JavaScript.
164
+ func JsMod(left, right int64) float64 {
165
+ if right == 0 {
166
+ return math.NaN()
167
+ }
168
+ return float64(left % right)
169
+ }
170
+
171
+ // JsModFloat is a % b for numbers.
172
+ func JsModFloat(left, right float64) float64 {
173
+ return math.Mod(left, right)
174
+ }
175
+
176
+ // JsBtoa is btoa(text): Base64 of a string whose characters each fit in one byte.
177
+ func JsBtoa(text string) (string, error) {
178
+ bytes := make([]byte, 0, len(text))
179
+ for _, r := range text {
180
+ if r > 0xFF {
181
+ return "", errors.New("InvalidCharacterError: the string contains a character that does not fit in a single byte")
182
+ }
183
+ bytes = append(bytes, byte(r))
184
+ }
185
+ return base64.StdEncoding.EncodeToString(bytes), nil
186
+ }
187
+
188
+ // JsSame is left === right on JSON values: booleans never equal numbers, numbers compare by value, nil equals nil.
189
+ func JsSame(left, right any) bool {
190
+ leftNumber, leftIsNumber := numeric(left)
191
+ rightNumber, rightIsNumber := numeric(right)
192
+ if leftIsNumber || rightIsNumber {
193
+ return leftIsNumber && rightIsNumber && leftNumber == rightNumber
194
+ }
195
+ if left == nil || right == nil {
196
+ return left == nil && right == nil
197
+ }
198
+ leftText, leftIsText := left.(string)
199
+ rightText, rightIsText := right.(string)
200
+ if leftIsText || rightIsText {
201
+ return leftIsText && rightIsText && leftText == rightText
202
+ }
203
+ leftFlag, leftIsFlag := left.(bool)
204
+ rightFlag, rightIsFlag := right.(bool)
205
+ if leftIsFlag || rightIsFlag {
206
+ return leftIsFlag && rightIsFlag && leftFlag == rightFlag
207
+ }
208
+ return reflect.ValueOf(left).Kind() == reflect.ValueOf(right).Kind() && reflect.DeepEqual(left, right)
209
+ }
210
+
211
+ func numeric(value any) (float64, bool) {
212
+ switch v := value.(type) {
213
+ case int:
214
+ return float64(v), true
215
+ case int64:
216
+ return float64(v), true
217
+ case float64:
218
+ return v, true
219
+ case json.Number:
220
+ parsed, err := v.Float64()
221
+ return parsed, err == nil
222
+ }
223
+ return 0, false
224
+ }
225
+
226
+ // JsDiv is left / right with IEEE results.
227
+ func JsDiv(left, right float64) float64 {
228
+ return left / right
229
+ }
230
+
231
+ // JsPow is base ** exponent as JavaScript computes it.
232
+ func JsPow(base, exponent float64) float64 {
233
+ if math.IsNaN(exponent) || (math.Abs(base) == 1 && math.IsInf(exponent, 0)) {
234
+ return math.NaN()
235
+ }
236
+ return math.Pow(base, exponent)
237
+ }
238
+
239
+ // JsGet is value.name for a JSON value: a missing field is nil; reading from null fails like JavaScript.
240
+ func JsGet(value any, name string) (any, error) {
241
+ if value == nil {
242
+ return nil, errors.New("Cannot read properties of null (reading '" + name + "')")
243
+ }
244
+ if object, ok := value.(map[string]any); ok {
245
+ return object[name], nil
246
+ }
247
+ return nil, nil
248
+ }
249
+
250
+ // JsMessage is error.message.
251
+ func JsMessage(err error) string {
252
+ return err.Error()
253
+ }
254
+
255
+ // thrown carries an error through a panic, so transpiled middleware can throw and catch like JavaScript.
256
+ type thrown struct {
257
+ err error
258
+ }
259
+
260
+ // Must returns value, or throws err: the panic is turned back into an error by Recover or caught by Caught.
261
+ func Must[T any](value T, err error) T {
262
+ if err != nil {
263
+ panic(thrown{err: err})
264
+ }
265
+ return value
266
+ }
267
+
268
+ // Throw is `throw new Error(message)`.
269
+ func Throw(message string) any {
270
+ return thrown{err: errors.New(message)}
271
+ }
272
+
273
+ // Caught turns what a transpiled try caught back into an error.
274
+ func Caught(recovered any) error {
275
+ switch v := recovered.(type) {
276
+ case thrown:
277
+ return v.err
278
+ case error:
279
+ return v
280
+ default:
281
+ return errors.New(JsStr(fmt.Sprint(v)))
282
+ }
283
+ }
284
+
285
+ // Recover ends a transpiled middleware: whatever it threw becomes its error.
286
+ func Recover(err *error) {
287
+ if recovered := recover(); recovered != nil {
288
+ *err = Caught(recovered)
289
+ }
290
+ }
291
+
292
+ func typeError(expected string, value any) error {
293
+ return fmt.Errorf("TypeError: expected %s, got %s", expected, describe(value))
294
+ }
295
+
296
+ // ToInt64 reads a value that must be an integer (a config field, a JSON number).
297
+ func ToInt64(value any) int64 {
298
+ switch v := value.(type) {
299
+ case int64:
300
+ return v
301
+ case int:
302
+ return int64(v)
303
+ case json.Number:
304
+ if parsed, err := v.Int64(); err == nil {
305
+ return parsed
306
+ }
307
+ case float64:
308
+ if v == math.Trunc(v) {
309
+ return int64(v)
310
+ }
311
+ }
312
+ panic(thrown{err: typeError("an integer", value)})
313
+ }
314
+
315
+ // ToFloat64 reads a value that must be a number.
316
+ func ToFloat64(value any) float64 {
317
+ if parsed, ok := numeric(value); ok {
318
+ return parsed
319
+ }
320
+ panic(thrown{err: typeError("a number", value)})
321
+ }
322
+
323
+ // ToStr reads a value that must be a string.
324
+ func ToStr(value any) string {
325
+ if text, ok := value.(string); ok {
326
+ return text
327
+ }
328
+ panic(thrown{err: typeError("a string", value)})
329
+ }
330
+
331
+ // ToBool reads a value that must be a boolean.
332
+ func ToBool(value any) bool {
333
+ if flag, ok := value.(bool); ok {
334
+ return flag
335
+ }
336
+ panic(thrown{err: typeError("a boolean", value)})
337
+ }
338
+
339
+ // ToMap reads a value that must be a JSON object.
340
+ func ToMap(value any) map[string]any {
341
+ if object, ok := value.(map[string]any); ok {
342
+ return object
343
+ }
344
+ panic(thrown{err: typeError("an object", value)})
345
+ }
346
+
347
+ // ToList reads a value that must be a JSON array.
348
+ func ToList(value any) []any {
349
+ if list, ok := value.([]any); ok {
350
+ return list
351
+ }
352
+ panic(thrown{err: typeError("an array", value)})
353
+ }
354
+
355
+ // ToRequest reads a value that must be a request.
356
+ func ToRequest(value any) Request {
357
+ if request, ok := value.(Request); ok {
358
+ return request
359
+ }
360
+ panic(thrown{err: typeError("a request", value)})
361
+ }
362
+
363
+ // ToResponse reads a value that must be a response.
364
+ func ToResponse(value any) Response {
365
+ if response, ok := value.(Response); ok {
366
+ return response
367
+ }
368
+ panic(thrown{err: typeError("a response", value)})
369
+ }
370
+
371
+ // ToAny returns value unchanged.
372
+ func ToAny(value any) any {
373
+ return value
374
+ }
375
+
376
+ // FromPtr is a header value as transpiled middleware sees it: absent is nil.
377
+ func FromPtr(value *string) any {
378
+ if value == nil {
379
+ return nil
380
+ }
381
+ return *value
382
+ }
383
+
384
+ // Iterate is `for (const item of list)`.
385
+ func Iterate(value any) []any {
386
+ if value == nil {
387
+ panic(thrown{err: errors.New("TypeError: null is not iterable")})
388
+ }
389
+ return ToList(value)
390
+ }
391
+
392
+ // Number is an integer or a float, for Min and Max.
393
+ type Number interface {
394
+ ~int64 | ~float64
395
+ }
396
+
397
+ // Min is Math.min of two numbers.
398
+ func Min[T Number](a, b T) T {
399
+ if b < a {
400
+ return b
401
+ }
402
+ return a
403
+ }
404
+
405
+ // Max is Math.max of two numbers.
406
+ func Max[T Number](a, b T) T {
407
+ if b > a {
408
+ return b
409
+ }
410
+ return a
411
+ }
412
+
413
+ // AbsInt is Math.abs of an integer.
414
+ func AbsInt(value int64) int64 {
415
+ if value < 0 {
416
+ return -value
417
+ }
418
+ return value
419
+ }
420
+
421
+ // @end
422
+
423
+ // @block middleware.helpers
424
+ // @summary RandomUUID makes a version 4 UUID from crypto/rand; the HMAC helpers sign UTF-8 text with a UTF-8 key, in hex or Base64.
425
+ // @versions >=1.18
426
+ // @source [1] https://pkg.go.dev/crypto/rand
427
+ // @quote [1] "Package rand implements a cryptographically secure random number generator."
428
+ // @source [2] https://www.rfc-editor.org/rfc/rfc9562#section-5.4
429
+ // @quote [2] "UUIDv4 is meant for generating UUIDs from truly random or pseudorandom numbers."
430
+ // @retrieved 2026-12-06
431
+ // @tests tests/lang_test.go
432
+ // @requirement SDKL-HELP-001
433
+
434
+ // RandomUUID is randomUUID(): a random version 4 UUID in lower case.
435
+ func RandomUUID() string {
436
+ var bytes [16]byte
437
+ if _, err := rand.Read(bytes[:]); err != nil {
438
+ panic(err)
439
+ }
440
+ bytes[6] = bytes[6]&0x0f | 0x40
441
+ bytes[8] = bytes[8]&0x3f | 0x80
442
+ text := hex.EncodeToString(bytes[:])
443
+ return text[:8] + "-" + text[8:12] + "-" + text[12:16] + "-" + text[16:20] + "-" + text[20:]
444
+ }
445
+
446
+ func hmacSha256(key, text string) []byte {
447
+ mac := hmac.New(sha256.New, []byte(key))
448
+ mac.Write([]byte(text))
449
+ return mac.Sum(nil)
450
+ }
451
+
452
+ // HmacSha256Hex is hmacSha256Hex(key, text): HMAC-SHA256 of UTF-8 text with a UTF-8 key, in lower-case hex.
453
+ func HmacSha256Hex(key, text string) string {
454
+ return hex.EncodeToString(hmacSha256(key, text))
455
+ }
456
+
457
+ // HmacSha256Base64 is hmacSha256Base64(key, text): HMAC-SHA256 of UTF-8 text with a UTF-8 key, in Base64.
458
+ func HmacSha256Base64(key, text string) string {
459
+ return base64.StdEncoding.EncodeToString(hmacSha256(key, text))
460
+ }
461
+
462
+ // @end
@@ -0,0 +1,75 @@
1
+ // sdkloom Go kit: multipart/form-data request bodies.
2
+ package sdkruntime
3
+
4
+ import (
5
+ "bytes"
6
+ "strings"
7
+ )
8
+
9
+ // @block http.multipart
10
+ // @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.
11
+ // @versions >=1.18
12
+ // @source [1] https://www.rfc-editor.org/rfc/rfc7578#section-4.2
13
+ // @quote [1] "Each part MUST contain a Content-Disposition header field"
14
+ // @source [2] https://www.rfc-editor.org/rfc/rfc7578#section-4.1
15
+ // @quote [2] "As with other multipart types, the parts are delimited with a boundary delimiter"
16
+ // @retrieved 2026-12-06
17
+ // @tests tests/multipart_test.go
18
+ // @requirement SDKL-HTTP-005
19
+
20
+ // MultipartPart is a text field, or a file when Filename is set.
21
+ type MultipartPart struct {
22
+ Name string
23
+ Value []byte
24
+ Filename string
25
+ ContentType string
26
+ }
27
+
28
+ // MultipartForm holds text fields and files in order: MultipartForm{}.Field("title", "Q4").File("report", "q4.pdf", "application/pdf", data).
29
+ type MultipartForm struct {
30
+ Parts []MultipartPart
31
+ }
32
+
33
+ // Field returns a copy with a text field added.
34
+ func (f MultipartForm) Field(name, value string) MultipartForm {
35
+ return f.with(MultipartPart{Name: name, Value: []byte(value)})
36
+ }
37
+
38
+ // File returns a copy with a file added.
39
+ func (f MultipartForm) File(name, filename, contentType string, data []byte) MultipartForm {
40
+ return f.with(MultipartPart{Name: name, Value: append([]byte(nil), data...), Filename: filename, ContentType: contentType})
41
+ }
42
+
43
+ func (f MultipartForm) with(part MultipartPart) MultipartForm {
44
+ parts := append(append([]MultipartPart(nil), f.Parts...), part)
45
+ return MultipartForm{Parts: parts}
46
+ }
47
+
48
+ var formQuoting = strings.NewReplacer(`"`, "%22", "\r", "%0D", "\n", "%0A")
49
+
50
+ // Encode returns the body for this boundary.
51
+ func (f MultipartForm) Encode(boundary string) []byte {
52
+ var out bytes.Buffer
53
+ for _, part := range f.Parts {
54
+ out.WriteString("--" + boundary + "\r\nContent-Disposition: form-data; name=\"" + formQuoting.Replace(part.Name) + "\"")
55
+ if part.Filename != "" {
56
+ contentType := part.ContentType
57
+ if contentType == "" {
58
+ contentType = "application/octet-stream"
59
+ }
60
+ out.WriteString("; filename=\"" + formQuoting.Replace(part.Filename) + "\"\r\nContent-Type: " + contentType)
61
+ }
62
+ out.WriteString("\r\n\r\n")
63
+ out.Write(part.Value)
64
+ out.WriteString("\r\n")
65
+ }
66
+ out.WriteString("--" + boundary + "--\r\n")
67
+ return out.Bytes()
68
+ }
69
+
70
+ // MultipartBoundary returns a random boundary.
71
+ func MultipartBoundary() string {
72
+ return "sdkloom-" + RandomUUID()
73
+ }
74
+
75
+ // @end
@@ -0,0 +1,150 @@
1
+ // sdkloom Go kit: iterating over every item of a paginated operation.
2
+ package sdkruntime
3
+
4
+ import (
5
+ "context"
6
+ "regexp"
7
+ "strings"
8
+ )
9
+
10
+ // @block pagination.iterate
11
+ // @summary Walks the pages of a paginated operation lazily, like bufio.Scanner: Next fetches pages as needed and reports whether there is an item, Item returns it, Err reports why iteration stopped early.
12
+ // @versions >=1.18
13
+ // @source [1] https://pkg.go.dev/bufio#Scanner
14
+ // @quote [1] "Scanner provides a convenient interface for reading data such as a file of newline-delimited lines of text."
15
+ // @retrieved 2026-12-05
16
+ // @tests tests/pagination_test.go
17
+ // @requirement SDKL-PAGE-001
18
+
19
+ // Pager iterates over every item of every page:
20
+ //
21
+ // pager := client.ListPaymentsAll(ctx, params)
22
+ // for pager.Next() {
23
+ // use(pager.Item())
24
+ // }
25
+ // if err := pager.Err(); err != nil { … }
26
+ type Pager[T any] struct {
27
+ fetch func() ([]T, error)
28
+ items []T
29
+ current T
30
+ err error
31
+ done bool
32
+ }
33
+
34
+ // NewPager starts at the first call's parameters; next returns the following call's parameters, or false after the
35
+ // last page. Nothing is fetched until Next is called.
36
+ func NewPager[P, R, T any](ctx context.Context, first P, fetch func(context.Context, P) (R, error), items func(R) []T, next func(P, R, []T) (P, bool)) *Pager[T] {
37
+ params, more := first, true
38
+ return &Pager[T]{fetch: func() ([]T, error) {
39
+ if !more {
40
+ return nil, nil
41
+ }
42
+ page, err := fetch(ctx, params)
43
+ if err != nil {
44
+ return nil, err
45
+ }
46
+ found := items(page)
47
+ params, more = next(params, page, found)
48
+ if len(found) == 0 && more {
49
+ // An empty page that still names a next one: keep going.
50
+ return []T{}, nil
51
+ }
52
+ return found, nil
53
+ }}
54
+ }
55
+
56
+ // Next advances to the next item, fetching pages as needed; it returns false at the end or after an error.
57
+ func (p *Pager[T]) Next() bool {
58
+ for len(p.items) == 0 {
59
+ if p.done {
60
+ return false
61
+ }
62
+ found, err := p.fetch()
63
+ if err != nil {
64
+ p.err, p.done = err, true
65
+ return false
66
+ }
67
+ if found == nil {
68
+ p.done = true
69
+ return false
70
+ }
71
+ p.items = found
72
+ }
73
+ p.current, p.items = p.items[0], p.items[1:]
74
+ return true
75
+ }
76
+
77
+ // Item is the item Next moved to.
78
+ func (p *Pager[T]) Item() T {
79
+ return p.current
80
+ }
81
+
82
+ // Err is the error that ended the iteration, or nil.
83
+ func (p *Pager[T]) Err() error {
84
+ return p.err
85
+ }
86
+
87
+ // All reads every remaining item.
88
+ func (p *Pager[T]) All() ([]T, error) {
89
+ var all []T
90
+ for p.Next() {
91
+ all = append(all, p.Item())
92
+ }
93
+ return all, p.Err()
94
+ }
95
+
96
+ // @end
97
+
98
+ // @block pagination.link
99
+ // @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.
100
+ // @versions >=1.18
101
+ // @source [1] https://www.rfc-editor.org/rfc/rfc8288#section-3
102
+ // @quote [1] "The Link header field provides a means for serialising one or more links into HTTP headers."
103
+ // @quote [1] "The rel parameter can, however, contain multiple link relation types."
104
+ // @quote [1] "MUST be compared character by character in a case-insensitive fashion."
105
+ // @retrieved 2026-12-06
106
+ // @tests tests/pagination_test.go
107
+ // @requirement SDKL-PAGE-001
108
+
109
+ var (
110
+ linkValue = regexp.MustCompile(`<([^>]*)>([^,]*)`)
111
+ absoluteURL = regexp.MustCompile(`(?i)^https?://`)
112
+ originOf = regexp.MustCompile(`(?i)^(https?://[^/]+)`)
113
+ )
114
+
115
+ // NextLink returns the URL of the link with relation type "next" in a Link header, or "".
116
+ func NextLink(header *string) string {
117
+ if header == nil {
118
+ return ""
119
+ }
120
+ for _, match := range linkValue.FindAllStringSubmatch(*header, -1) {
121
+ for _, param := range strings.Split(match[2], ";") {
122
+ name, value, found := strings.Cut(param, "=")
123
+ if !found || !strings.EqualFold(strings.TrimSpace(name), "rel") {
124
+ continue
125
+ }
126
+ for _, kind := range strings.Fields(strings.ToLower(strings.Trim(strings.TrimSpace(value), `"`))) {
127
+ if kind == "next" {
128
+ return match[1]
129
+ }
130
+ }
131
+ break
132
+ }
133
+ }
134
+ return ""
135
+ }
136
+
137
+ // ResolveURL resolves a URL from the API against the base URL: absolute as is, "/path" on the base's origin, else
138
+ // after it.
139
+ func ResolveURL(base, url string) string {
140
+ switch {
141
+ case absoluteURL.MatchString(url):
142
+ return url
143
+ case strings.HasPrefix(url, "/"):
144
+ return originOf.FindString(base) + url
145
+ default:
146
+ return strings.TrimRight(base, "/") + "/" + url
147
+ }
148
+ }
149
+
150
+ // @end