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,84 @@
1
+ # sdkloom Python kit: verifying the signature of a webhook the API sent.
2
+
3
+ from __future__ import absolute_import, division, unicode_literals
4
+
5
+ import base64
6
+ import hashlib
7
+ import hmac
8
+ import re
9
+
10
+ try: # type names for annotations; Python 2.7 has no typing module
11
+ from typing import Any, Mapping, Optional, Union # noqa: F401
12
+ except ImportError: # pragma: no cover - Python 2.7
13
+ pass
14
+
15
+ # @block webhooks.verify
16
+ # @summary Verifies a webhook's HMAC-SHA256 signature as the definition describes it (signed text from the body and headers, several signatures in one header, an optional timestamp tolerance against replays), comparing in constant time, and raises WebhookSignatureError.
17
+ # @versions >=2.7
18
+ # @source [1] https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md
19
+ # @quote [1] "When verifying symmetric signatures, use a constant time comparison function to compare the calculated with the expected signature."
20
+ # @quote [1] "The signature header is a space delimited list of signatures associated with this webhook."
21
+ # @source [2] https://docs.python.org/3/library/hmac.html#hmac.compare_digest
22
+ # @quote [2] "This function uses an approach designed to prevent timing analysis by avoiding content-based short circuiting behaviour, making it appropriate for cryptography."
23
+ # @retrieved 2026-12-05
24
+ # @tests tests/test_webhooks.py
25
+ # @requirement SDKL-HOOK-001
26
+
27
+ _PLACEHOLDER = re.compile(r"(\{[^{}]*\})")
28
+ _TIMESTAMP = re.compile(r"^[0-9]{1,15}$")
29
+
30
+
31
+ class WebhookSignatureError(ValueError):
32
+ """The webhook was not signed with the secret, or is too old or too new."""
33
+
34
+ name = "WebhookSignatureError"
35
+
36
+
37
+ def _header(headers, name):
38
+ # type: (Any, str) -> Optional[str]
39
+ """A header by name, case-insensitively, from a dict or anything with items() (http.server, WSGI adapters)."""
40
+ for key, value in headers.items():
41
+ if key.lower() == name:
42
+ return value
43
+ return None
44
+
45
+
46
+ def verify_webhook(signature, body, headers, secret, now_seconds):
47
+ # type: (Mapping[str, Any], Union[bytes, str], Any, str, int) -> None
48
+ """Raises WebhookSignatureError unless one of the header's signatures is the HMAC of the signed text, made in time."""
49
+ raw = body if isinstance(body, bytes) else body.encode("utf-8")
50
+ timestamp = signature.get("timestamp")
51
+ if timestamp is not None:
52
+ stamp = (_header(headers, timestamp["header"]) or "").strip()
53
+ if not _TIMESTAMP.match(stamp):
54
+ raise WebhookSignatureError("missing or invalid " + timestamp["header"] + " header")
55
+ if abs(now_seconds - int(stamp)) > timestamp["toleranceSeconds"]:
56
+ raise WebhookSignatureError("the webhook was signed at %s, more than %d s from now" % (stamp, timestamp["toleranceSeconds"]))
57
+ given = _header(headers, signature["header"])
58
+ if given is None:
59
+ raise WebhookSignatureError("missing " + signature["header"] + " header")
60
+ message = b""
61
+ for piece in _PLACEHOLDER.split(signature["signed"]):
62
+ if piece == "{body}":
63
+ message += raw
64
+ elif piece.startswith("{") and piece.endswith("}"):
65
+ value = _header(headers, piece[1:-1])
66
+ if value is None:
67
+ raise WebhookSignatureError("missing " + piece[1:-1] + " header")
68
+ message += value.encode("utf-8")
69
+ else:
70
+ message += piece.encode("utf-8")
71
+ prefix = signature.get("secretPrefix")
72
+ key_text = secret[len(prefix):] if prefix and secret.startswith(prefix) else secret
73
+ key = base64.b64decode(key_text) if signature["secret"] == "base64" else key_text.encode("utf-8")
74
+ digest = hmac.new(key, message, hashlib.sha256).digest()
75
+ expected = digest.hex() if hasattr(digest, "hex") else digest.encode("hex") # Python 2.7 has no bytes.hex
76
+ if signature["encoding"] == "base64":
77
+ expected = base64.b64encode(digest).decode("ascii")
78
+ sign_prefix = signature.get("prefix") or ""
79
+ separator = signature.get("separator")
80
+ candidates = given.split(separator) if separator else [given]
81
+ found = [hmac.compare_digest(candidate[len(sign_prefix):].encode("utf-8"), expected.encode("ascii")) for candidate in candidates if candidate.startswith(sign_prefix)]
82
+ if True not in found:
83
+ raise WebhookSignatureError("no signature matches: the webhook was not signed with this secret, or was changed after signing")
84
+ # @end
@@ -0,0 +1,28 @@
1
+ """Shared by the kit's tests: the kit's src/ on the import path, and unittest names that differ on Python 2.7."""
2
+ from __future__ import absolute_import, division, unicode_literals
3
+
4
+ import os
5
+ import sys
6
+ import unittest
7
+
8
+ sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "src"))
9
+
10
+ if not hasattr(unittest.TestCase, "assertRaisesRegex"): # Python 2.7
11
+ unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
12
+ unittest.TestCase.assertRegex = unittest.TestCase.assertRegexpMatches
13
+
14
+ try:
15
+ from http.server import BaseHTTPRequestHandler, HTTPServer
16
+ from socketserver import ThreadingMixIn
17
+ except ImportError: # Python 2.7
18
+ from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer # noqa: F401
19
+ from SocketServer import ThreadingMixIn
20
+
21
+
22
+ class ThreadingHTTPServer(ThreadingMixIn, HTTPServer):
23
+ """http.server.ThreadingHTTPServer, which needs Python 3.7."""
24
+
25
+ daemon_threads = True
26
+
27
+ def handle_error(self, request, client_address):
28
+ """Quiet: some tests hang up on purpose."""
@@ -0,0 +1,275 @@
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
+ from __future__ import absolute_import, division, unicode_literals
7
+
8
+ import json
9
+ import threading
10
+ import unittest
11
+
12
+ import support # noqa: E402,F401 - puts the kit on the path
13
+
14
+ from sdkloom_runtime.compat import replace # noqa: E402
15
+ from sdkloom_runtime.client import CallOptions, ClientRuntime, OperationSpec, ParamSpec, call_operation, entry # noqa: E402
16
+ from sdkloom_runtime.context import SdkInfo, SystemClock, State # noqa: E402
17
+ from sdkloom_runtime.errors import ApiError # noqa: E402
18
+ from sdkloom_runtime.http import HttpResponse # noqa: E402
19
+ from sdkloom_runtime.models import DecodeError, as_object, as_string # noqa: E402
20
+
21
+
22
+ class NotFoundError(ApiError):
23
+ pass
24
+
25
+
26
+ class FixedClock:
27
+ def __init__(self, now=0):
28
+ self.value = now
29
+
30
+ def now(self):
31
+ return self.value
32
+
33
+ def sleep(self, ms):
34
+ self.value += ms
35
+
36
+
37
+ def decode_order(value, path):
38
+ obj = as_object(value, path)
39
+ return {"id": as_string(obj.get("id"), path + ".id"), "raw": obj}
40
+
41
+
42
+ GET_ORDER = OperationSpec(
43
+ name="getOrder",
44
+ method="GET",
45
+ path="/orders/{id}",
46
+ params=(ParamSpec("id", "path"), ParamSpec("expand", "query"), ParamSpec("x-trace", "header")),
47
+ result="json",
48
+ decode=decode_order,
49
+ errors={404: lambda status, body, response: NotFoundError(status, body, response, "NotFound")},
50
+ )
51
+
52
+
53
+ def answer(status, value=None, headers=()):
54
+ return HttpResponse(status, tuple(headers), b"" if value is None else json.dumps(value).encode("utf-8"))
55
+
56
+
57
+ def runtime(transport, **overrides):
58
+ clock = FixedClock()
59
+ values = dict(base_url="https://api.test/v1", transport=transport, clock=clock, state=State(clock), timeout_ms=30000)
60
+ values.update(overrides)
61
+ return ClientRuntime(**values)
62
+
63
+
64
+ class SdkInfoTests(unittest.TestCase):
65
+ def test_middleware_learns_which_sdk_it_runs_in(self):
66
+ seen = []
67
+
68
+ def spy(request, call_next, ctx):
69
+ seen.append(ctx.sdk)
70
+ return call_next(request)
71
+
72
+ spec = OperationSpec(name="op", method="GET", path="/op")
73
+ ok = lambda request, options: answer(204) # noqa: E731
74
+ call_operation(runtime(ok, middleware=(entry("spy", spy, {}),), sdk=SdkInfo("acme-payments", "1.2.3", "python")), spec, {})
75
+ call_operation(runtime(ok, middleware=(entry("spy", spy, {}),)), spec, {})
76
+
77
+ self.assertEqual(seen, [SdkInfo("acme-payments", "1.2.3", "python"), SdkInfo("", "", "python")])
78
+
79
+
80
+ class CallTests(unittest.TestCase):
81
+ def test_builds_the_request_and_decodes_the_result(self):
82
+ seen = []
83
+
84
+ def transport(request, options):
85
+ seen.append(request)
86
+ return answer(200, {"id": "o1"})
87
+
88
+ result = call_operation(runtime(transport), GET_ORDER, {"id": "a b", "expand": ["x"], "x-trace": "t1"})
89
+
90
+ self.assertEqual(result.data["id"], "o1")
91
+ self.assertEqual(result.response.status, 200)
92
+ self.assertEqual(seen[0].url, "https://api.test/v1/orders/a%20b?expand=x")
93
+ self.assertEqual(seen[0].header("x-trace"), "t1")
94
+ self.assertEqual(seen[0].header("accept"), "application/json")
95
+
96
+ def test_header_values_are_written_like_the_other_languages(self):
97
+ seen = []
98
+ spec = OperationSpec(name="flag", method="GET", path="/flag", params=(ParamSpec("x-flag", "header"), ParamSpec("x-amount", "header"), ParamSpec("x-rate", "header")))
99
+ call_operation(runtime(lambda request, options: seen.append(request) or answer(204)), spec, {"x-flag": True, "x-amount": 2.0, "x-rate": 0.5})
100
+
101
+ self.assertEqual(seen[0].header("x-flag"), "true")
102
+ self.assertEqual(seen[0].header("x-amount"), "2")
103
+ self.assertEqual(seen[0].header("x-rate"), "0.5")
104
+
105
+ def test_sends_a_json_body(self):
106
+ seen = []
107
+ spec = OperationSpec(name="createOrder", method="POST", path="/orders", body="json")
108
+ call_operation(runtime(lambda request, options: seen.append(request) or answer(204)), spec, {"body": {"amount": "1.00"}})
109
+
110
+ self.assertEqual(seen[0].header("content-type"), "application/json")
111
+ self.assertEqual(seen[0].body, b'{"amount":"1.00"}')
112
+
113
+ def test_maps_statuses_to_errors(self):
114
+ def failing(status):
115
+ return lambda request, options: answer(status, {"message": "no"}, [("x-request-id", "req_1")])
116
+
117
+ with self.assertRaises(NotFoundError) as caught:
118
+ call_operation(runtime(failing(404)), GET_ORDER, {"id": "1"})
119
+ self.assertEqual(caught.exception.status, 404)
120
+ self.assertEqual(caught.exception.body, {"message": "no"})
121
+ self.assertEqual(caught.exception.request_id, "req_1")
122
+ self.assertFalse(caught.exception.retryable)
123
+ for status in (429, 503):
124
+ with self.assertRaises(ApiError) as caught:
125
+ call_operation(runtime(failing(status)), GET_ORDER, {"id": "1"})
126
+ self.assertTrue(caught.exception.retryable)
127
+ self.assertNotIsInstance(caught.exception, NotFoundError)
128
+
129
+ def test_a_result_with_the_wrong_shape_fails_with_its_path(self):
130
+ with self.assertRaises(DecodeError) as caught:
131
+ call_operation(runtime(lambda request, options: answer(200, {"id": 7})), GET_ORDER, {"id": "1"})
132
+ self.assertEqual(caught.exception.path, "$.id")
133
+
134
+ def test_runs_middleware_in_order_around_the_transport(self):
135
+ order = []
136
+
137
+ def trace(request, call_next, ctx):
138
+ order.append(ctx.config["label"] + ">")
139
+ response = call_next(request)
140
+ order.append("<" + ctx.config["label"])
141
+ return response
142
+
143
+ def transport(request, options):
144
+ order.append("transport")
145
+ return answer(200, {"id": "1"})
146
+
147
+ client = runtime(
148
+ transport,
149
+ middleware=(entry("a", trace, {"label": "a"}),),
150
+ registry={"b": entry("b", trace, {"label": "b"})},
151
+ user_middleware=(entry("c", trace, {"label": "c"}),),
152
+ )
153
+ call_operation(client, replace(GET_ORDER, use=("b",)), {"id": "1"})
154
+
155
+ self.assertEqual(order, ["a>", "b>", "c>", "transport", "<c", "<b", "<a"])
156
+
157
+ def test_middleware_may_call_next_twice_and_sees_the_operation(self):
158
+ calls = []
159
+ operations = []
160
+
161
+ def retry(request, call_next, ctx):
162
+ operations.append(ctx.operation.name)
163
+ first = call_next(request)
164
+ return call_next(request) if first.status == 503 else first
165
+
166
+ def transport(request, options):
167
+ calls.append(request)
168
+ return answer(503) if len(calls) == 1 else answer(200, {"id": "1"})
169
+
170
+ result = call_operation(runtime(transport, middleware=(entry("retry", retry, {}),)), GET_ORDER, {"id": "1"})
171
+
172
+ self.assertEqual(len(calls), 2)
173
+ self.assertEqual(result.data["id"], "1")
174
+ self.assertEqual(operations, ["getOrder"])
175
+
176
+ def test_a_throwing_listener_never_breaks_the_call(self):
177
+ events = []
178
+
179
+ def emitter(request, call_next, ctx):
180
+ ctx.emit("custom.event", {"ok": True})
181
+ return call_next(request)
182
+
183
+ def broken(name, fields):
184
+ raise RuntimeError("listener failed")
185
+
186
+ client = runtime(lambda request, options: answer(200, {"id": "1"}), middleware=(entry("e", emitter, {}),), listeners=(broken, lambda name, fields: events.append(name)))
187
+ call_operation(client, GET_ORDER, {"id": "1"})
188
+
189
+ self.assertEqual(events, ["custom.event", "sdkloom.listener_error"])
190
+
191
+ def test_call_options_override_timeout_headers_and_base_url(self):
192
+ seen = []
193
+
194
+ def transport(request, options):
195
+ seen.append((request, options))
196
+ return answer(200, {"id": "1"})
197
+
198
+ call_operation(runtime(transport), GET_ORDER, {"id": "1"})
199
+ call_operation(runtime(transport), GET_ORDER, {"id": "1"}, CallOptions(timeout_ms=5, headers={"x-extra": "1"}, base_url="https://other.test"))
200
+
201
+ self.assertEqual(seen[0][1].timeout_ms, 30000)
202
+ self.assertEqual(seen[1][1].timeout_ms, 5)
203
+ self.assertEqual(seen[1][0].header("x-extra"), "1")
204
+ self.assertEqual(seen[1][0].url, "https://other.test/orders/1")
205
+
206
+ def test_returns_bytes_and_streams_and_collects_stream_bodies(self):
207
+ seen = []
208
+
209
+ def transport(request, options):
210
+ seen.append(request)
211
+ return HttpResponse(200, (), b"\x09\x08")
212
+
213
+ download = OperationSpec(name="download", method="GET", path="/f", result="bytes")
214
+ stream = OperationSpec(name="stream", method="POST", path="/s", body="stream", result="stream")
215
+
216
+ self.assertEqual(call_operation(runtime(transport), download, {}).data, b"\x09\x08")
217
+ self.assertEqual(list(call_operation(runtime(transport), stream, {"body": iter([b"\x01", b"\x02"])}).data), [b"\x09\x08"])
218
+ self.assertEqual(seen[1].body, b"\x01\x02")
219
+ self.assertEqual(seen[1].header("content-type"), "application/octet-stream")
220
+
221
+
222
+ class ContextTests(unittest.TestCase):
223
+ def test_state_entries_expire_after_their_time_to_live(self):
224
+ clock = FixedClock(1000)
225
+ state = State(clock)
226
+ state.set("token", "a", ttl_ms=100)
227
+ state.set("forever", "b")
228
+
229
+ self.assertEqual(state.get("token"), "a")
230
+ clock.value = 1100
231
+ self.assertIsNone(state.get("token"))
232
+ self.assertEqual(state.get("forever"), "b")
233
+ state.delete("forever")
234
+ self.assertIsNone(state.get("forever"))
235
+
236
+ def test_state_is_safe_to_share_between_threads(self):
237
+ state = State(FixedClock())
238
+
239
+ def work(index):
240
+ for step in range(200):
241
+ state.set("k%d" % index, step)
242
+
243
+ threads = [threading.Thread(target=work, args=(index,)) for index in range(8)]
244
+ for thread in threads:
245
+ thread.start()
246
+ for thread in threads:
247
+ thread.join()
248
+ self.assertEqual([state.get("k%d" % index) for index in range(8)], [199] * 8)
249
+
250
+ def test_the_system_clock_reads_time_and_sleeps(self):
251
+ clock = SystemClock()
252
+ before = clock.now()
253
+ clock.sleep(5)
254
+ self.assertGreaterEqual(clock.now(), before + 4)
255
+
256
+
257
+
258
+ class ApiVersionTest(unittest.TestCase):
259
+ def test_an_operation_newer_than_the_pinned_version_is_refused_and_unknown_versions_too(self):
260
+ from sdkloom_runtime.client import ApiVersion, check_api_version
261
+ from sdkloom_runtime.http import ArgumentError
262
+
263
+ version = ApiVersion("api-version", "2024-06-20", ("2024-06-20", "2025-01-01"))
264
+ check_api_version(version, "getOrder", "2024-06-20")
265
+ check_api_version(version, "getOrder", None)
266
+ check_api_version(None, "getOrder", "anything")
267
+ with self.assertRaises(ArgumentError) as raised:
268
+ check_api_version(version, "refundOrder", "2025-01-01")
269
+ self.assertEqual(str(raised.exception), "refundOrder needs API version 2025-01-01 or later; this client uses 2024-06-20")
270
+ with self.assertRaises(ArgumentError):
271
+ check_api_version(ApiVersion("api-version", "1999", version.values), "getOrder", None)
272
+
273
+
274
+ if __name__ == "__main__":
275
+ unittest.main()
@@ -0,0 +1,87 @@
1
+ # -*- coding: utf-8 -*-
2
+ # @requirement SDKL-HTTP-004
3
+ from __future__ import absolute_import, division, unicode_literals
4
+
5
+ import unittest
6
+
7
+ import support # noqa: E402,F401 - puts the kit on the path
8
+
9
+ from sdkloom_runtime.compat import Record, factory, is_integer, is_text, json_loads, message_of, number_text, quote, replace, to_text # noqa: E402
10
+ from sdkloom_runtime.http import build_url # noqa: E402
11
+ from sdkloom_runtime.models import encode_json # noqa: E402
12
+
13
+
14
+ class Point(Record):
15
+ _fields = ("x", "y", "tags")
16
+ _defaults = {"y": 0, "tags": factory(list)}
17
+
18
+
19
+ class Tagged(Record):
20
+ _fields = ("name", "extra")
21
+ _defaults = {"extra": factory(dict)}
22
+ _hidden = ("extra",)
23
+
24
+
25
+ class RecordTests(unittest.TestCase):
26
+ def test_hidden_fields_are_kept_but_not_compared_or_shown(self):
27
+ tagged = Tagged("a", {"x": 1})
28
+
29
+ self.assertEqual(tagged.extra, {"x": 1})
30
+ self.assertEqual(tagged, Tagged("a"))
31
+ self.assertTrue(repr(tagged).startswith("Tagged(name=") and "extra" not in repr(tagged))
32
+
33
+ def test_fields_defaults_equality_and_repr(self):
34
+ point = Point(1, tags=["a"])
35
+
36
+ self.assertEqual((point.x, point.y, point.tags), (1, 0, ["a"]))
37
+ self.assertEqual(point, Point(x=1, y=0, tags=["a"]))
38
+ self.assertNotEqual(point, Point(2))
39
+ self.assertFalse(point != Point(1, 0, ["a"]))
40
+ self.assertEqual(repr(Point(1, 2, [])), "Point(x=1, y=2, tags=[])")
41
+
42
+ def test_factories_give_every_instance_its_own_value(self):
43
+ self.assertIsNot(Point(1).tags, Point(1).tags)
44
+
45
+ def test_records_are_immutable_and_changed_with_replace(self):
46
+ point = Point(1)
47
+
48
+ with self.assertRaises(AttributeError):
49
+ point.x = 2
50
+ moved = replace(point, x=2)
51
+
52
+ self.assertEqual((point.x, moved.x, moved.y), (1, 2, 0))
53
+ self.assertEqual(hash(Point(1, 2, ())), hash(Point(1, 2, ())))
54
+
55
+ def test_wrong_arguments_are_refused(self):
56
+ with self.assertRaisesRegex(TypeError, "missing x"):
57
+ Point()
58
+ with self.assertRaisesRegex(TypeError, "unexpected argument z"):
59
+ Point(1, z=2)
60
+ with self.assertRaisesRegex(TypeError, "two values for x"):
61
+ Point(1, x=2)
62
+ with self.assertRaisesRegex(TypeError, "at most 3 arguments"):
63
+ Point(1, 2, 3, 4)
64
+
65
+
66
+ class TextTests(unittest.TestCase):
67
+ def test_native_strings_with_utf8_work_like_text(self):
68
+ # On Python 2.7 "café".encode("utf-8") is what a file without unicode_literals holds; on 3 these are bytes and stay so.
69
+ native = "café".encode("utf-8") if str is bytes else "café"
70
+
71
+ self.assertEqual(to_text(native), "café")
72
+ self.assertEqual(encode_json({"name": native}), '{"name":"café"}'.encode("utf-8"))
73
+ self.assertEqual(build_url("https://a.test", "/p/{id}", {"id": native}, [("q", native)]), "https://a.test/p/caf%C3%A9?q=caf%C3%A9")
74
+ self.assertEqual(message_of(ValueError(native)), "café")
75
+
76
+ def test_text_numbers_and_json_behave_the_same_on_every_version(self):
77
+ self.assertTrue(is_text("a") and not is_text(1))
78
+ self.assertTrue(is_integer(10 ** 20) and not is_integer(True))
79
+ self.assertEqual(number_text(0.1 + 0.2), "0.30000000000000004")
80
+ self.assertEqual(list(json_loads('{"b":1,"a":2}').keys()), ["b", "a"])
81
+ for constant in ["NaN", "Infinity", "-Infinity"]:
82
+ self.assertRaises(ValueError, json_loads, constant)
83
+ self.assertEqual(quote("ş ~", safe=""), "%C5%9F%20~")
84
+
85
+
86
+ if __name__ == "__main__":
87
+ unittest.main()
@@ -0,0 +1,94 @@
1
+ # @requirement SDKL-HTTP-001
2
+ # @requirement SDKL-HTTP-002
3
+ # @requirement SDKL-HTTP-003
4
+ from __future__ import absolute_import, division, unicode_literals
5
+
6
+ import unittest
7
+ from decimal import Decimal
8
+
9
+ import support # noqa: E402,F401 - puts the kit on the path
10
+
11
+ from sdkloom_runtime.http import ArgumentError, HttpRequest, HttpResponse, build_url # noqa: E402
12
+
13
+
14
+ class RequestTests(unittest.TestCase):
15
+ def test_headers_are_case_insensitive_and_replaced(self):
16
+ request = HttpRequest("GET", "https://a.test/x").with_header("Accept", "a").with_header("accept", "b")
17
+
18
+ self.assertEqual(request.header("ACCEPT"), "b")
19
+ self.assertEqual(request.headers, (("accept", "b"),))
20
+
21
+ def test_requests_are_immutable(self):
22
+ original = HttpRequest("GET", "https://a.test/x")
23
+ changed = original.with_header("x", "1").with_url("https://b.test/").without_header("x").with_body(b"\x01")
24
+
25
+ self.assertEqual(original.headers, ())
26
+ self.assertEqual(original.url, "https://a.test/x")
27
+ self.assertIsNone(original.body)
28
+ self.assertEqual(changed.url, "https://b.test/")
29
+ self.assertIsNone(changed.header("x"))
30
+ self.assertEqual(changed.body, b"\x01")
31
+
32
+
33
+ class UrlTests(unittest.TestCase):
34
+ def test_build_url_encodes_path_parameters_and_keeps_query_order(self):
35
+ url = build_url("https://api.test/v1/", "/orders/{id}/items", {"id": "a b/c"}, [("b", "2"), ("a", ["x", "y"]), ("skip", None), ("flag", True)])
36
+
37
+ self.assertEqual(url, "https://api.test/v1/orders/a%20b%2Fc/items?b=2&a=x&a=y&flag=true")
38
+
39
+ def test_a_path_parameter_of_dots_is_refused(self):
40
+ for value in (".", ".."):
41
+ with self.assertRaisesRegex(ArgumentError, "cannot be"):
42
+ build_url("https://api.test", "/files/{id}", {"id": value}, [])
43
+ self.assertEqual(ArgumentError.name, "ArgumentError")
44
+ self.assertEqual(build_url("https://api.test", "/files/{id}", {"id": "a..b"}, []), "https://api.test/files/a..b")
45
+
46
+ def test_encoding_matches_the_typescript_kit(self):
47
+ url = build_url("https://a.test", "/p/{v}", {"v": "!'()*~-_."}, [("q", "a b*~!")])
48
+
49
+ self.assertEqual(url, "https://a.test/p/!'()*~-_.?q=a+b*%7E%21")
50
+
51
+ def test_numbers_look_the_same_in_every_language(self):
52
+ url = build_url("https://a.test", "/n/{id}", {"id": 7}, [("x", 1.5), ("y", 2.0), ("d", Decimal("1E+3")), ("z", 1e-7), ("w", 1e23)])
53
+
54
+ self.assertEqual(url, "https://a.test/n/7?x=1.5&y=2&d=1000&z=1e-7&w=1e%2B23")
55
+
56
+ def test_missing_path_parameter(self):
57
+ with self.assertRaisesRegex(ValueError, "missing path parameter id"):
58
+ build_url("https://a.test", "/x/{id}", {}, [])
59
+
60
+
61
+ class ResponseTests(unittest.TestCase):
62
+ def test_reads_text_json_and_headers(self):
63
+ response = HttpResponse(200, (("Content-Type", "application/json"),), b'{"a":1}')
64
+
65
+ self.assertEqual(response.text(), '{"a":1}')
66
+ self.assertEqual(response.json(), {"a": 1})
67
+ self.assertEqual(response.json(), {"a": 1})
68
+ self.assertEqual(response.header("content-type"), "application/json")
69
+
70
+ def test_an_empty_body_has_no_json_value(self):
71
+ self.assertIsNone(HttpResponse(204, (), b"").json())
72
+
73
+
74
+
75
+ class ReservedExpansionTest(unittest.TestCase):
76
+ def test_a_reserved_placeholder_keeps_slashes_and_encodes_each_segment(self):
77
+ self.assertEqual(build_url("https://a.test", "/files/{+path}", {"path": "docs/a b/\u00e7.txt"}, []), "https://a.test/files/docs/a%20b/%C3%A7.txt")
78
+ with self.assertRaises(ArgumentError):
79
+ build_url("https://a.test", "/files/{+path}", {"path": "docs/../secret"}, [])
80
+
81
+ def test_a_reserved_route_matches_one_or_more_segments(self):
82
+ from sdkloom_runtime.http import HttpRequest
83
+ from sdkloom_runtime.testing import MockTransport
84
+ from sdkloom_runtime.transport import SendOptions
85
+
86
+ transport = MockTransport()
87
+ transport.route("GET", "/files/{+path}/meta").reply(status=200)
88
+ self.assertEqual(transport.send(HttpRequest("GET", "https://a.test/files/a/b/meta"), SendOptions()).status, 200)
89
+ with self.assertRaises(AssertionError):
90
+ transport.send(HttpRequest("GET", "https://a.test/files/meta"), SendOptions())
91
+
92
+
93
+ if __name__ == "__main__":
94
+ unittest.main()
@@ -0,0 +1,104 @@
1
+ # -*- coding: utf-8 -*-
2
+ # @requirement SDKL-XPILE-001
3
+ # @requirement SDKL-HELP-001
4
+ from __future__ import absolute_import, division, unicode_literals
5
+
6
+ import math
7
+ import unittest
8
+
9
+ import support # noqa: E402,F401 - puts the kit on the path
10
+
11
+ from sdkloom_runtime.lang import js_btoa, js_div, js_get, js_hmac_sha256_base64, js_hmac_sha256_hex, js_mod, js_number, js_pow, js_random_uuid, js_same, js_str # noqa: E402
12
+
13
+ INF = float("inf") # math.inf needs Python 3.5
14
+
15
+
16
+ class StringTests(unittest.TestCase):
17
+ def test_converts_values_like_javascript_string(self):
18
+ cases = [(None, "null"), (True, "true"), (False, "false"), (2, "2"), (2.0, "2"), (-0.0, "0"), (0.5, "0.5"), (1e21, "1e+21"), (1e-7, "1e-7"), (1e-5, "0.00001"), (-2.5e-6, "-0.0000025"),
19
+ (123456789012.5, "123456789012.5"), (0.1 + 0.2, "0.30000000000000004"), (8.700326121778885e16, "87003261217788850"), (1e23, "1e+23"), (float("nan"), "NaN"), (float("inf"), "Infinity"),
20
+ (float("-inf"), "-Infinity"), ("ş", "ş"), ([1, "a", None], "1,a,"), ({"a": 1}, "[object Object]")]
21
+ for value, expected in cases:
22
+ self.assertEqual(js_str(value), expected, value)
23
+
24
+
25
+ class NumberTests(unittest.TestCase):
26
+ def test_parses_text_like_javascript_number(self):
27
+ self.assertEqual(js_number(" 12 "), 12)
28
+ self.assertEqual(js_number(""), 0)
29
+ self.assertEqual(js_number("1e3"), 1000)
30
+ self.assertEqual(js_number("0x10"), 16)
31
+ self.assertEqual(js_number("-1.5"), -1.5)
32
+ self.assertEqual(js_number("Infinity"), INF)
33
+ self.assertTrue(math.isnan(js_number("12px")))
34
+ self.assertTrue(math.isnan(js_number("inf")))
35
+
36
+
37
+ class RemainderTests(unittest.TestCase):
38
+ def test_the_sign_follows_the_dividend(self):
39
+ self.assertEqual(js_mod(-7, 3), -1)
40
+ self.assertEqual(js_mod(7, -3), 1)
41
+ self.assertEqual(js_mod(7.5, 2), 1.5)
42
+ self.assertIsInstance(js_mod(7, 3), int)
43
+ self.assertTrue(math.isnan(js_mod(1, 0)))
44
+
45
+
46
+ class OperatorTests(unittest.TestCase):
47
+ def test_strict_equality_keeps_booleans_apart_from_numbers(self):
48
+ self.assertFalse(js_same(True, 1))
49
+ self.assertFalse(js_same(0, False))
50
+ self.assertTrue(js_same(2, 2.0))
51
+ self.assertTrue(js_same(None, None))
52
+ self.assertTrue(js_same("a", "a"))
53
+
54
+ def test_division_and_powers_follow_ieee_instead_of_raising(self):
55
+ self.assertEqual(js_div(1, 0), INF)
56
+ self.assertEqual(js_div(-1, 0), -INF)
57
+ self.assertEqual(js_div(1, -0.0), -INF)
58
+ self.assertTrue(math.isnan(js_div(0, 0)))
59
+ self.assertEqual(js_div(7, 2), 3.5)
60
+ self.assertEqual(js_pow(0, -1), INF)
61
+ self.assertEqual(js_pow(2, -1), 0.5)
62
+ self.assertTrue(math.isnan(js_pow(-8, 1 / 3)))
63
+
64
+
65
+ class Base64Tests(unittest.TestCase):
66
+ def test_encodes_single_byte_text_like_btoa_and_rejects_the_rest(self):
67
+ self.assertEqual(js_btoa("user:pass"), "dXNlcjpwYXNz")
68
+ self.assertEqual(js_btoa("\u00ff"), "/w==")
69
+ with self.assertRaisesRegex(ValueError, "InvalidCharacterError"):
70
+ js_btoa("\u015f")
71
+
72
+
73
+ class FieldTests(unittest.TestCase):
74
+ def test_reads_object_fields_and_fails_on_null_like_javascript(self):
75
+ self.assertEqual(js_get({"token": "t"}, "token"), "t")
76
+ self.assertIsNone(js_get({"token": "t"}, "other"))
77
+ self.assertIsNone(js_get([1], "token"))
78
+ with self.assertRaisesRegex(TypeError, "Cannot read properties of null \\(reading 'token'\\)"):
79
+ js_get(None, "token")
80
+
81
+
82
+
83
+ class HelpersTest(unittest.TestCase):
84
+ def test_random_uuid_makes_distinct_version_4_uuids(self):
85
+ import re
86
+
87
+ ids = set(js_random_uuid() for _ in range(100))
88
+ self.assertEqual(len(ids), 100)
89
+ for value in ids:
90
+ self.assertTrue(re.match(r"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", value), value)
91
+
92
+ def test_hmac_helpers_match_rfc_4231_test_case_2(self):
93
+ self.assertEqual(js_hmac_sha256_hex("Jefe", "what do ya want for nothing?"), "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843")
94
+ self.assertEqual(js_hmac_sha256_base64("Jefe", "what do ya want for nothing?"), "W9zBRr9gdU5qBCQmCJV1x1oAPwidJzmDnexYuWTsOEM=")
95
+
96
+ def test_a_request_text_is_its_utf8_body(self):
97
+ from sdkloom_runtime.http import HttpRequest
98
+
99
+ self.assertEqual(HttpRequest("POST", "https://a.example", (), '{"\u00e9":1}'.encode("utf-8")).text(), '{"\u00e9":1}')
100
+ self.assertEqual(HttpRequest("GET", "https://a.example").text(), "")
101
+
102
+
103
+ if __name__ == "__main__":
104
+ unittest.main()