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,269 @@
1
+ // @requirement SDKL-ERR-001
2
+ // @requirement SDKL-VERSION-001
3
+ // @requirement SDKL-PIPE-001
4
+ // @requirement SDKL-PIPE-002
5
+ // @requirement SDKL-JSON-002
6
+ import { test } from "node:test";
7
+ import assert from "node:assert/strict";
8
+ import { callOperation, entry, type ClientRuntime, type OperationSpec } from "../src/client.ts";
9
+ import { createState, systemClock, type Clock } from "../src/context.ts";
10
+ import { ApiError } from "../src/errors.ts";
11
+ import { HttpRequest, HttpResponse } from "../src/http.ts";
12
+ import { asObject, asString, DecodeError } from "../src/models.ts";
13
+ import type { SendOptions, Transport } from "../src/transport.ts";
14
+
15
+ interface Order {
16
+ readonly id: string;
17
+ }
18
+
19
+ class NotFoundError extends ApiError {}
20
+
21
+ const CLOCK: Clock = { now: () => 0, sleep: async () => undefined };
22
+
23
+ const GET_ORDER: OperationSpec<Order> = {
24
+ name: "getOrder",
25
+ method: "GET",
26
+ path: "/orders/{id}",
27
+ params: [
28
+ { name: "id", in: "path" },
29
+ { name: "expand", in: "query" },
30
+ { name: "x-trace", in: "header" },
31
+ ],
32
+ result: "json",
33
+ decode: (value, path) => {
34
+ const object = asObject(value, path);
35
+ return { ...object, id: asString(object["id"], `${path}.id`) };
36
+ },
37
+ errors: { 404: (status, body, response) => new NotFoundError(status, body, response, "NotFound") },
38
+ use: [],
39
+ };
40
+
41
+ function json(status: number, value: unknown, headers: readonly (readonly [string, string])[] = []): HttpResponse {
42
+ return new HttpResponse(status, headers, new TextEncoder().encode(JSON.stringify(value)));
43
+ }
44
+
45
+ function runtime(transport: Transport, overrides: Partial<ClientRuntime> = {}): ClientRuntime {
46
+ return {
47
+ baseUrl: "https://api.test/v1",
48
+ transport,
49
+ middleware: [],
50
+ registry: {},
51
+ userMiddleware: [],
52
+ clock: CLOCK,
53
+ state: createState(CLOCK),
54
+ listeners: [],
55
+ timeoutMs: 30_000,
56
+ ...overrides,
57
+ };
58
+ }
59
+
60
+ test("middleware learns which SDK it runs in from ctx.sdk", async () => {
61
+ const seen: unknown[] = [];
62
+ const spy = entry("spy", async (request, next, ctx) => {
63
+ seen.push(ctx.sdk);
64
+ return next(request);
65
+ }, {});
66
+ const spec = { name: "op", method: "GET", path: "/op", params: [], use: [], errors: {} } as const;
67
+ const ok = async (): Promise<HttpResponse> => new HttpResponse(204, [], new Uint8Array());
68
+
69
+ await callOperation(runtime(ok, { middleware: [spy], sdk: { name: "@acme/payments", version: "1.2.3", language: "typescript" } }), spec, {});
70
+ await callOperation(runtime(ok, { middleware: [spy] }), spec, {});
71
+
72
+ assert.deepEqual(seen, [{ name: "@acme/payments", version: "1.2.3", language: "typescript" }, { name: "", version: "", language: "typescript" }]);
73
+ });
74
+
75
+ test("builds the request from the arguments and decodes the result", async () => {
76
+ const seen: HttpRequest[] = [];
77
+ const transport: Transport = async (request) => {
78
+ seen.push(request);
79
+ return json(200, { id: "o1", extra: true });
80
+ };
81
+ const result = await callOperation(runtime(transport), GET_ORDER, { id: "a b", expand: ["x"], "x-trace": "t1" });
82
+
83
+ assert.deepEqual(result.data, { id: "o1", extra: true });
84
+ assert.equal(result.response.status, 200);
85
+ assert.equal(seen[0]?.url, "https://api.test/v1/orders/a%20b?expand=x");
86
+ assert.equal(seen[0]?.header("x-trace"), "t1");
87
+ assert.equal(seen[0]?.header("accept"), "application/json");
88
+ });
89
+
90
+ test("sends a JSON body with its content type", async () => {
91
+ const seen: HttpRequest[] = [];
92
+ const spec: OperationSpec<undefined> = { name: "createOrder", method: "POST", path: "/orders", params: [], body: "json", errors: {}, use: [] };
93
+ await callOperation(
94
+ runtime(async (request) => {
95
+ seen.push(request);
96
+ return new HttpResponse(204, [], new Uint8Array());
97
+ }),
98
+ spec,
99
+ { body: { amount: "1.00" } },
100
+ );
101
+
102
+ assert.equal(seen[0]?.header("content-type"), "application/json");
103
+ assert.equal(new TextDecoder().decode(seen[0]?.body as Uint8Array), '{"amount":"1.00"}');
104
+ });
105
+
106
+ test("maps declared statuses to named errors and the rest to ApiError", async () => {
107
+ const answer = (status: number): Transport => async () => json(status, { message: "no" }, [["x-request-id", "req_1"]]);
108
+
109
+ await assert.rejects(callOperation(runtime(answer(404)), GET_ORDER, { id: "1" }), (error: unknown) => {
110
+ assert.ok(error instanceof NotFoundError);
111
+ assert.equal(error.status, 404);
112
+ assert.deepEqual(error.body, { message: "no" });
113
+ assert.equal(error.requestId, "req_1");
114
+ assert.equal(error.retryable, false);
115
+ return true;
116
+ });
117
+ await assert.rejects(callOperation(runtime(answer(503)), GET_ORDER, { id: "1" }), (error: unknown) => {
118
+ assert.ok(error instanceof ApiError && !(error instanceof NotFoundError));
119
+ assert.equal(error.retryable, true);
120
+ return true;
121
+ });
122
+ await assert.rejects(callOperation(runtime(answer(429)), GET_ORDER, { id: "1" }), (error: unknown) => error instanceof ApiError && error.retryable);
123
+ });
124
+
125
+ test("a result that does not match the type fails with its path", async () => {
126
+ await assert.rejects(
127
+ callOperation(
128
+ runtime(async () => json(200, { id: 7 })),
129
+ GET_ORDER,
130
+ { id: "1" },
131
+ ),
132
+ (error: unknown) => error instanceof DecodeError && error.path === "$.id",
133
+ );
134
+ });
135
+
136
+ test("runs SDK, operation and user middleware in order around the transport", async () => {
137
+ const order: string[] = [];
138
+ const trace = (name: string) =>
139
+ entry<{ readonly label: string }>(name, async (request, next, ctx) => {
140
+ order.push(`${ctx.config.label}>`);
141
+ const response = await next(request);
142
+ order.push(`<${ctx.config.label}`);
143
+ return response;
144
+ }, { label: name });
145
+ const spec: OperationSpec<Order> = { ...GET_ORDER, use: ["b"] };
146
+ const client = runtime(
147
+ async () => {
148
+ order.push("transport");
149
+ return json(200, { id: "1" });
150
+ },
151
+ { middleware: [trace("a")], registry: { b: trace("b") }, userMiddleware: [trace("c")] },
152
+ );
153
+ await callOperation(client, spec, { id: "1" });
154
+
155
+ assert.deepEqual(order, ["a>", "b>", "c>", "transport", "<c", "<b", "<a"]);
156
+ });
157
+
158
+ test("a middleware may call next more than once and sees the operation", async () => {
159
+ let calls = 0;
160
+ const operations: string[] = [];
161
+ const retry = entry("retry", async (request, next, ctx) => {
162
+ operations.push(ctx.operation.name);
163
+ const first = await next(request);
164
+ return first.status === 503 ? next(request) : first;
165
+ }, {});
166
+ const client = runtime(
167
+ async () => {
168
+ calls += 1;
169
+ return calls === 1 ? json(503, {}) : json(200, { id: "1" });
170
+ },
171
+ { middleware: [retry] },
172
+ );
173
+ const result = await callOperation(client, GET_ORDER, { id: "1" });
174
+
175
+ assert.equal(calls, 2);
176
+ assert.equal(result.data.id, "1");
177
+ assert.deepEqual(operations, ["getOrder"]);
178
+ });
179
+
180
+ test("a throwing event listener never breaks the call", async () => {
181
+ const events: string[] = [];
182
+ const emitter = entry("emitter", async (request, next, ctx) => {
183
+ ctx.emit("custom.event", { ok: true });
184
+ return next(request);
185
+ }, {});
186
+ const client = runtime(async () => json(200, { id: "1" }), {
187
+ middleware: [emitter],
188
+ listeners: [
189
+ () => {
190
+ throw new Error("listener failed");
191
+ },
192
+ (name) => events.push(name),
193
+ ],
194
+ });
195
+ await callOperation(client, GET_ORDER, { id: "1" });
196
+
197
+ assert.deepEqual(events, ["custom.event", "sdkloom.listener_error"]);
198
+ });
199
+
200
+ test("call options override timeout, signal, headers and base URL", async () => {
201
+ const seen: { request: HttpRequest; options: SendOptions }[] = [];
202
+ const controller = new AbortController();
203
+ const client = runtime(async (request, options) => {
204
+ seen.push({ request, options });
205
+ return json(200, { id: "1" });
206
+ });
207
+ await callOperation(client, GET_ORDER, { id: "1" });
208
+ await callOperation(client, GET_ORDER, { id: "1" }, { timeoutMs: 5, signal: controller.signal, headers: { "x-extra": "1" }, baseUrl: "https://other.test" });
209
+
210
+ assert.equal(seen[0]?.options.timeoutMs, 30_000);
211
+ assert.equal(seen[1]?.options.timeoutMs, 5);
212
+ assert.equal(seen[1]?.options.signal, controller.signal);
213
+ assert.equal(seen[1]?.request.header("x-extra"), "1");
214
+ assert.equal(seen[1]?.request.url, "https://other.test/orders/1");
215
+ });
216
+
217
+ test("state entries expire after their time to live", () => {
218
+ let now = 1_000;
219
+ const clock: Clock = { now: () => now, sleep: async () => undefined };
220
+ const state = createState(clock);
221
+ state.set("token", "a", { ttlMs: 100 });
222
+ state.set("forever", "b");
223
+
224
+ assert.equal(state.get("token"), "a");
225
+ now = 1_100;
226
+ assert.equal(state.get("token"), undefined);
227
+ assert.equal(state.get("forever"), "b");
228
+ state.delete("forever");
229
+ assert.equal(state.get("forever"), undefined);
230
+ assert.equal(state.get("missing"), undefined);
231
+ });
232
+
233
+ test("the system clock reads real time and sleeps", async () => {
234
+ const before = systemClock.now();
235
+ await systemClock.sleep(5);
236
+ assert.ok(systemClock.now() >= before);
237
+ });
238
+
239
+ test("returns bytes and stream results and collects stream bodies", async () => {
240
+ async function* upload(): AsyncGenerator<Uint8Array> {
241
+ yield new Uint8Array([1]);
242
+ yield new Uint8Array([2]);
243
+ }
244
+ const seen: HttpRequest[] = [];
245
+ const transport: Transport = async (request) => {
246
+ seen.push(request);
247
+ return new HttpResponse(200, [], new Uint8Array([9, 8]));
248
+ };
249
+ const bytesSpec: OperationSpec<Uint8Array> = { name: "download", method: "GET", path: "/f", params: [], result: "bytes", errors: {}, use: [] };
250
+ const streamSpec: OperationSpec<AsyncIterable<Uint8Array>> = { name: "stream", method: "POST", path: "/s", params: [], body: "stream", result: "stream", errors: {}, use: [] };
251
+
252
+ assert.deepEqual((await callOperation(runtime(transport), bytesSpec, {})).data, new Uint8Array([9, 8]));
253
+ const chunks: Uint8Array[] = [];
254
+ for await (const chunk of (await callOperation(runtime(transport), streamSpec, { body: upload() })).data) chunks.push(chunk);
255
+ assert.deepEqual(chunks, [new Uint8Array([9, 8])]);
256
+ assert.deepEqual(seen[1]?.body, new Uint8Array([1, 2]));
257
+ assert.equal(seen[1]?.header("content-type"), "application/octet-stream");
258
+ });
259
+
260
+ test("an API version is sent on every request, and an operation newer than the pinned version is refused before sending", async () => {
261
+ const { checkApiVersion } = await import("../src/client.ts");
262
+ const version = { header: "api-version", value: "2024-06-20", values: ["2024-06-20", "2025-01-01"] };
263
+
264
+ assert.doesNotThrow(() => checkApiVersion(version, "getOrder", "2024-06-20"));
265
+ assert.doesNotThrow(() => checkApiVersion(version, "getOrder", undefined));
266
+ assert.throws(() => checkApiVersion(version, "refundOrder", "2025-01-01"), (error: unknown) => error instanceof Error && error.name === "ArgumentError" && error.message === "refundOrder needs API version 2025-01-01 or later; this client uses 2024-06-20");
267
+ assert.throws(() => checkApiVersion({ ...version, value: "1999" }, "getOrder", undefined), /unknown API version 1999; this SDK knows 2024-06-20, 2025-01-01/);
268
+ assert.doesNotThrow(() => checkApiVersion(undefined, "getOrder", "anything"));
269
+ });
@@ -0,0 +1,27 @@
1
+ // @requirement SDKL-HELP-001
2
+ import { test } from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { hmacSha256Base64, hmacSha256Hex, randomUUID } from "../src/helpers.ts";
5
+ import { HttpRequest } from "../src/http.ts";
6
+
7
+ test("randomUUID makes distinct version 4 UUIDs", () => {
8
+ const ids = new Set(Array.from({ length: 100 }, () => randomUUID()));
9
+
10
+ assert.equal(ids.size, 100);
11
+ for (const id of ids) assert.match(id, /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
12
+ });
13
+
14
+ test("hmacSha256Hex and hmacSha256Base64 match RFC 4231 test case 2", () => {
15
+ assert.equal(hmacSha256Hex("Jefe", "what do ya want for nothing?"), "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843");
16
+ assert.equal(hmacSha256Base64("Jefe", "what do ya want for nothing?"), "W9zBRr9gdU5qBCQmCJV1x1oAPwidJzmDnexYuWTsOEM=");
17
+ assert.equal(hmacSha256Hex("ключ", "é"), hmacSha256Hex("ключ", "é"));
18
+ });
19
+
20
+ test("a request's text is its UTF-8 body, empty without one, and a stream cannot be read", () => {
21
+ async function* chunks(): AsyncGenerator<Uint8Array> {
22
+ yield new Uint8Array([1]);
23
+ }
24
+ assert.equal(new HttpRequest("POST", "https://a.example").withBody("{\"é\":1}").text(), "{\"é\":1}");
25
+ assert.equal(new HttpRequest("GET", "https://a.example").text(), "");
26
+ assert.throws(() => new HttpRequest("POST", "https://a.example", [], chunks()).text(), /is a stream/);
27
+ });
@@ -0,0 +1,80 @@
1
+ // @requirement SDKL-HTTP-001
2
+ // @requirement SDKL-HTTP-002
3
+ // @requirement SDKL-HTTP-003
4
+ import { test } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { buildUrl, HttpRequest, HttpResponse } from "../src/http.ts";
7
+
8
+ test("headers are matched case-insensitively and replaced, not duplicated", () => {
9
+ const request = new HttpRequest("GET", "https://a.test/x").withHeader("Accept", "a").withHeader("accept", "b");
10
+
11
+ assert.equal(request.header("ACCEPT"), "b");
12
+ assert.deepEqual(request.headers, [["accept", "b"]]);
13
+ });
14
+
15
+ test("requests are immutable", () => {
16
+ const original = new HttpRequest("GET", "https://a.test/x");
17
+ const changed = original.withHeader("x", "1").withUrl("https://b.test/").withoutHeader("x").withBody(new Uint8Array([1]));
18
+
19
+ assert.deepEqual(original.headers, []);
20
+ assert.equal(original.url, "https://a.test/x");
21
+ assert.equal(original.body, undefined);
22
+ assert.equal(changed.url, "https://b.test/");
23
+ assert.equal(changed.header("x"), undefined);
24
+ assert.deepEqual(changed.body, new Uint8Array([1]));
25
+ });
26
+
27
+ test("buildUrl percent-encodes path parameters and keeps query order", () => {
28
+ const url = buildUrl("https://api.test/v1/", "/orders/{id}/items", { id: "a b/c" }, [
29
+ ["b", "2"],
30
+ ["a", ["x", "y"]],
31
+ ["skip", undefined],
32
+ ["flag", true],
33
+ ]);
34
+
35
+ assert.equal(url, "https://api.test/v1/orders/a%20b%2Fc/items?b=2&a=x&a=y&flag=true");
36
+ });
37
+
38
+ test("buildUrl encodes exactly like the Python kit", () => {
39
+ assert.equal(buildUrl("https://a.test", "/p/{v}", { v: "!'()*~-_." }, [["q", "a b*~!"]]), "https://a.test/p/!'()*~-_.?q=a+b*%7E%21");
40
+ });
41
+
42
+ test("buildUrl fails on a missing path parameter", () => {
43
+ assert.throws(() => buildUrl("https://a.test", "/x/{id}", {}, []), /missing path parameter id/);
44
+ });
45
+
46
+ test("response bodies can be read more than once as bytes, text or JSON", async () => {
47
+ async function* chunks(): AsyncGenerator<Uint8Array> {
48
+ yield new TextEncoder().encode('{"a"');
49
+ yield new TextEncoder().encode(":1}");
50
+ }
51
+ const response = new HttpResponse(200, [["Content-Type", "application/json"]], chunks());
52
+
53
+ assert.equal(await response.text(), '{"a":1}');
54
+ assert.deepEqual(await response.json(), { a: 1 });
55
+ assert.equal((await response.bytes()).length, 7);
56
+ assert.equal(response.header("content-type"), "application/json");
57
+ });
58
+
59
+ test("an empty body has no JSON value", async () => {
60
+ assert.equal(await new HttpResponse(204, [], new Uint8Array()).json(), undefined);
61
+ });
62
+
63
+ test("numbers in the URL are written like String(number), as the Python and Java kits write them", () => {
64
+ const url = buildUrl("https://a.test", "/n/{id}", { id: 7 }, [["x", 1.5], ["y", 2.0], ["z", 1e-7], ["w", 1e23]]);
65
+
66
+ assert.equal(url, "https://a.test/n/7?x=1.5&y=2&z=1e-7&w=1e%2B23");
67
+ });
68
+
69
+ test("a path parameter of . or .. is refused: URL parsers read it as a step up the path, even percent-encoded", () => {
70
+ for (const id of [".", ".."]) {
71
+ assert.throws(() => buildUrl("https://api.test", "/files/{id}", { id }, []), (error: unknown) => error instanceof Error && error.name === "ArgumentError" && /cannot be/.test(error.message));
72
+ }
73
+ assert.equal(new URL("https://api.test/files/%2E%2E").pathname, "/", "why encoding is not enough");
74
+ assert.equal(buildUrl("https://api.test", "/files/{id}", { id: "a..b" }, []), "https://api.test/files/a..b");
75
+ });
76
+
77
+ test("a {+name} placeholder keeps the value's slashes and encodes each segment; dot segments are refused", () => {
78
+ assert.equal(buildUrl("https://a.test", "/files/{+path}", { path: "docs/a b/ç.txt" }, []), "https://a.test/files/docs/a%20b/%C3%A7.txt");
79
+ assert.throws(() => buildUrl("https://a.test", "/files/{+path}", { path: "docs/../secret" }, []), /cannot be "\.\."/);
80
+ });
@@ -0,0 +1,71 @@
1
+ // @requirement SDKL-JSON-001
2
+ // @requirement SDKL-JSON-002
3
+ // @requirement SDKL-JSON-003
4
+ // @requirement SDKL-JSON-004
5
+ import { test } from "node:test";
6
+ import assert from "node:assert/strict";
7
+ import { asArray, asBoolean, asDecimal, asEnum, asInteger, asMap, asNumber, asObject, asString, encodeJson, field } from "../src/models.ts";
8
+
9
+ test("asObject keeps fields it does not know", () => {
10
+ assert.deepEqual(asObject({ a: 1, extra: "x" }, "$"), { a: 1, extra: "x" });
11
+ });
12
+
13
+ test("asEnum keeps values it does not know", () => {
14
+ assert.equal(asEnum("EUR", "$.currency", ["TRY", "USD"]), "EUR");
15
+ });
16
+
17
+ test("asEnum still requires a string", () => {
18
+ assert.throws(() => asEnum(1, "$.currency", ["TRY", "USD"]), /\$\.currency: expected one of TRY, USD, got number 1/);
19
+ });
20
+
21
+ test("primitive decoders report the path, the expected type and the actual value", () => {
22
+ assert.throws(() => asString(1, "$.id"), /\$\.id: expected a string, got number 1/);
23
+ assert.throws(() => asInteger(1.5, "$.n"), /\$\.n: expected an integer, got number 1\.5/);
24
+ assert.throws(() => asNumber("1", "$.n"), /\$\.n: expected a number, got string "1"/);
25
+ assert.throws(() => asBoolean(null, "$.b"), /\$\.b: expected a boolean, got null/);
26
+ assert.throws(() => asObject([], "$"), /\$: expected an object, got array/);
27
+ assert.equal(asNumber(1.5, "$"), 1.5);
28
+ assert.equal(asBoolean(false, "$"), false);
29
+ });
30
+
31
+ test("asDecimal accepts strings and JSON numbers", () => {
32
+ assert.equal(asDecimal("10.50", "$"), "10.50");
33
+ assert.equal(asDecimal(10.5, "$"), "10.5");
34
+ assert.throws(() => asDecimal("1e3x", "$.amount"), /\$\.amount: expected a decimal, got string "1e3x"/);
35
+ });
36
+
37
+ test("asArray and asMap decode every item with its path", () => {
38
+ assert.deepEqual(asArray([1, 2], "$.l", asInteger), [1, 2]);
39
+ assert.throws(() => asArray([1, "x"], "$.l", asInteger), /\$\.l\[1\]: expected an integer/);
40
+ assert.deepEqual(asMap({ a: 1 }, "$.m", asInteger), { a: 1 });
41
+ assert.throws(() => asMap({ a: "x" }, "$.m", asInteger), /\$\.m\.a: expected an integer/);
42
+ });
43
+
44
+ test("field enforces optional and nullable separately", () => {
45
+ const object = asObject({ a: null }, "$");
46
+
47
+ assert.equal(field(object, "a", "$", asString, { optional: false, nullable: true }), null);
48
+ // Many servers send null for a field they leave out: for an optional field that cannot be null it reads as absent.
49
+ assert.equal(field(object, "a", "$", asString, { optional: true, nullable: false }), undefined);
50
+ assert.throws(() => field(object, "a", "$", asString, { optional: false, nullable: false }), /\$\.a: expected a string, got null/);
51
+ assert.equal(field(object, "b", "$", asString, { optional: true, nullable: false }), undefined);
52
+ assert.throws(() => field(object, "b", "$", asString, { optional: false, nullable: true }), /\$\.b: is required/);
53
+ });
54
+
55
+ test("encodeJson sends unknown union variants back exactly as they were received", () => {
56
+ const raw = { type: "wallet", provider: "acme", nested: { a: [1, null] } };
57
+ const value = { id: "p1", method: { type: "$unknown", unknownTag: "wallet", raw }, methods: [{ type: "$unknown", unknownTag: "wallet", raw }] };
58
+
59
+ assert.deepEqual(JSON.parse(new TextDecoder().decode(encodeJson(value))), { id: "p1", method: raw, methods: [raw] });
60
+ });
61
+
62
+ test("encodeJson finds unknown union variants whatever the discriminator is called", () => {
63
+ const raw = { kind: "wallet", provider: "acme" };
64
+ const value = { method: { kind: "$unknown", unknownTag: "wallet", raw } };
65
+
66
+ assert.deepEqual(JSON.parse(new TextDecoder().decode(encodeJson(value))), { method: raw });
67
+ });
68
+
69
+ test("encodeJson drops undefined fields and returns UTF-8 bytes", () => {
70
+ assert.equal(new TextDecoder().decode(encodeJson({ a: 1, b: undefined, c: "ş" })), '{"a":1,"c":"ş"}');
71
+ });
@@ -0,0 +1,28 @@
1
+ // @requirement SDKL-HTTP-005
2
+ import { test } from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { encodeMultipart, MultipartForm } from "../src/multipart.ts";
5
+
6
+ test("encodes fields and files in order with their dispositions, a content type for files and the closing boundary", () => {
7
+ const form = new MultipartForm().field("title", "Q4 ü").file("report", "q4 \"final\".csv", "text/csv", new TextEncoder().encode("a,b\r\n1,2"));
8
+ const { content, type } = encodeMultipart(form, "b0undary");
9
+
10
+ assert.equal(type, "multipart/form-data; boundary=b0undary");
11
+ assert.equal(
12
+ new TextDecoder().decode(content),
13
+ '--b0undary\r\nContent-Disposition: form-data; name="title"\r\n\r\nQ4 ü\r\n' +
14
+ '--b0undary\r\nContent-Disposition: form-data; name="report"; filename="q4 %22final%22.csv"\r\nContent-Type: text/csv\r\n\r\na,b\r\n1,2\r\n' +
15
+ "--b0undary--\r\n",
16
+ );
17
+ });
18
+
19
+ test("a form is immutable and the default boundary is random", () => {
20
+ const empty = new MultipartForm();
21
+ const one = empty.field("a", "1");
22
+ const first = encodeMultipart(one).type;
23
+
24
+ assert.equal(empty.parts.length, 0);
25
+ assert.equal(one.parts.length, 1);
26
+ assert.match(first, /^multipart\/form-data; boundary=sdkloom-[0-9a-f-]{36}$/);
27
+ assert.ok(first !== encodeMultipart(one).type);
28
+ });
@@ -0,0 +1,76 @@
1
+ // @requirement SDKL-PAGE-001
2
+ import { test } from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { paginate } from "../src/pagination.ts";
5
+
6
+ interface Page {
7
+ readonly items: readonly number[];
8
+ readonly next?: string;
9
+ }
10
+
11
+ const PAGES: Readonly<Record<string, Page>> = { "": { items: [1, 2], next: "b" }, b: { items: [3], next: "c" }, c: { items: [] } };
12
+
13
+ test("yields every item, page by page, until next returns undefined", async () => {
14
+ const fetched: string[] = [];
15
+ const items: number[] = [];
16
+ const pages = paginate(
17
+ { cursor: "" },
18
+ async (params) => {
19
+ fetched.push(params.cursor);
20
+ return PAGES[params.cursor] ?? { items: [] };
21
+ },
22
+ (page) => page.items,
23
+ (params, page) => (page.next === undefined ? undefined : { ...params, cursor: page.next }),
24
+ );
25
+ for await (const item of pages) items.push(item);
26
+
27
+ assert.deepEqual(items, [1, 2, 3]);
28
+ assert.deepEqual(fetched, ["", "b", "c"]);
29
+ });
30
+
31
+ test("fetches lazily: nothing before the first item is asked for, and stopping early stops fetching", async () => {
32
+ let calls = 0;
33
+ const pages = paginate(
34
+ 0,
35
+ async (offset) => {
36
+ calls += 1;
37
+ return [offset, offset + 1];
38
+ },
39
+ (page) => page,
40
+ (offset, _page, items) => offset + items.length,
41
+ );
42
+ assert.equal(calls, 0);
43
+ for await (const item of pages) if (item === 2) break;
44
+ assert.equal(calls, 2);
45
+ });
46
+
47
+ test("an error fetching a page ends the iteration with that error", async () => {
48
+ const pages = paginate(
49
+ 1,
50
+ async (page) => {
51
+ if (page === 2) throw new Error("page 2 failed");
52
+ return [page];
53
+ },
54
+ (page) => page,
55
+ (page) => page + 1,
56
+ );
57
+ const seen: number[] = [];
58
+ await assert.rejects(async () => {
59
+ for await (const item of pages) seen.push(item);
60
+ }, /page 2 failed/);
61
+ assert.deepEqual(seen, [1]);
62
+ });
63
+
64
+ test("nextLink reads rel=next from a Link header, quoted or not, among several relation types, in any case", async () => {
65
+ const { nextLink } = await import("../src/pagination.ts");
66
+ const { resolveUrl } = await import("../src/client.ts");
67
+
68
+ assert.equal(nextLink('<https://a.test/x?page=2&s=a,b>; rel="next", <https://a.test/x?page=9>; rel="last"'), "https://a.test/x?page=2&s=a,b");
69
+ assert.equal(nextLink('<https://a.test/x?page=1>; rel="prev first", <https://a.test/x?page=3>; REL="Next last"'), "https://a.test/x?page=3");
70
+ assert.equal(nextLink("</x?page=4>; title=more; rel=next"), "/x?page=4");
71
+ assert.equal(nextLink('<https://a.test/x?page=1>; rel="prev"'), undefined);
72
+ assert.equal(nextLink(undefined), undefined);
73
+ assert.equal(resolveUrl("https://a.test/v1/", "/v1/x?page=2"), "https://a.test/v1/x?page=2");
74
+ assert.equal(resolveUrl("https://a.test/v1", "x?page=2"), "https://a.test/v1/x?page=2");
75
+ assert.equal(resolveUrl("https://a.test/v1", "https://b.test/y"), "https://b.test/y");
76
+ });
@@ -0,0 +1,82 @@
1
+ // @requirement SDKL-SSE-001
2
+ import { test } from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { DecodeError } from "../src/models.ts";
5
+ import { decodeEvents, encodeEvents, parseEvents, type ServerSentEvent } from "../src/sse.ts";
6
+
7
+ async function* chunksOf(...parts: string[]): AsyncGenerator<Uint8Array> {
8
+ for (const part of parts) yield new TextEncoder().encode(part);
9
+ }
10
+
11
+ async function all<T>(events: AsyncIterable<T>): Promise<T[]> {
12
+ const found: T[] = [];
13
+ for await (const event of events) found.push(event);
14
+ return found;
15
+ }
16
+
17
+ test("parses events with types, multi-line data, ids that carry over, comments and every line ending", async () => {
18
+ const stream = "\uFEFF: comment\r\nevent: created\r\ndata: {\"a\":1}\r\nid: 7\r\n\r\ndata:first\ndata: second\n\nretry: 10\rdata: spaced\r\r";
19
+
20
+ assert.deepEqual(await all(parseEvents(chunksOf(stream))), [
21
+ { event: "created", id: "7", data: '{"a":1}' },
22
+ { event: "message", id: "7", data: "first\nsecond" },
23
+ { event: "message", id: "7", data: " spaced" },
24
+ ]);
25
+ });
26
+
27
+ test("lines and characters split across chunks, a CR then LF in the next chunk, and an unfinished event at the end", async () => {
28
+ const euro = new TextEncoder().encode("data: €\r\n\r\n");
29
+ async function* split(): AsyncGenerator<Uint8Array> {
30
+ yield euro.slice(0, 7);
31
+ yield euro.slice(7, 10);
32
+ yield euro.slice(10);
33
+ yield new TextEncoder().encode("data: dropped\n");
34
+ }
35
+
36
+ assert.deepEqual(await all(parseEvents(split())), [{ event: "message", id: "", data: "€" }]);
37
+ });
38
+
39
+ test("an event with no data is not dispatched, and a field without a colon has an empty value", async () => {
40
+ assert.deepEqual(await all(parseEvents(chunksOf("event: ping\n\ndata\n\nid\ndata: x\n\n"))), [
41
+ { event: "message", id: "", data: "" },
42
+ { event: "message", id: "", data: "x" },
43
+ ]);
44
+ });
45
+
46
+ test("yields an event as soon as its blank line arrives, before the stream ends", async () => {
47
+ let ended = false;
48
+ async function* slow(): AsyncGenerator<Uint8Array> {
49
+ yield new TextEncoder().encode("data: one\n\n");
50
+ await new Promise<void>((resolve) => setTimeout(() => resolve(), 20));
51
+ ended = true;
52
+ yield new TextEncoder().encode("data: two\n\n");
53
+ }
54
+ const events = parseEvents(slow());
55
+
56
+ assert.equal((await events.next()).value?.data, "one");
57
+ assert.equal(ended, false);
58
+ assert.equal((await events.next()).value?.data, "two");
59
+ });
60
+
61
+ test("decodes JSON data with the decoder, keeps text without one, and fails on data that is not JSON", async () => {
62
+ const typed = decodeEvents(parseEvents(chunksOf('data: {"n": 2}\n\n')), (value) => (value as { n: number }).n * 10);
63
+ const text = decodeEvents(parseEvents(chunksOf("data: plain\n\n")), undefined);
64
+ const broken = decodeEvents(parseEvents(chunksOf("data: {nope\n\n")), (value) => value);
65
+
66
+ assert.deepEqual(await all(typed), [{ event: "message", id: "", data: 20 }]);
67
+ assert.deepEqual(await all(text), [{ event: "message", id: "", data: "plain" } satisfies ServerSentEvent<string>]);
68
+ await assert.rejects(all(broken), (error: unknown) => error instanceof DecodeError && error.message.startsWith("$: the event data is not JSON"));
69
+ });
70
+
71
+ test("encodeEvents writes what parseEvents reads back", async () => {
72
+ const events = [
73
+ { event: "created", id: "1", data: { amount: "10.00", note: "two\nlines" } },
74
+ { event: "message", id: "", data: "first line\nsecond line" },
75
+ ];
76
+ const parsed = await all(parseEvents(chunksOf(encodeEvents(events))));
77
+
78
+ assert.deepEqual(parsed, [
79
+ { event: "created", id: "1", data: '{"amount":"10.00","note":"two\\nlines"}' },
80
+ { event: "message", id: "1", data: "first line\nsecond line" },
81
+ ]);
82
+ });