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,138 @@
1
+ // src/testing.ts: a typed mockClient() and deterministic examples for every model.
2
+
3
+ import { createCodeWriter, } from "@sdkloom/codegen";
4
+
5
+ import { clientName, configFields } from "./emit-client.ts";
6
+ import { MODEL_HELPERS } from "./emit-models.ts";
7
+ import { docComment, importLine, propertyKey, quote, usedNames } from "./naming.ts";
8
+ import { bodyKind, decoderExpr, exampleExpr, resultType, textEvents, tsType } from "./types.ts";
9
+
10
+ const MOCK_BASE_URL = "http://mock.sdkloom.invalid";
11
+
12
+ /** The value mock clients pass for required configuration. */
13
+ function placeholder(field ) {
14
+ const type = field.type;
15
+ if (type.kind === "enum") return quote(type.values[0] ?? "");
16
+ if (type.kind !== "primitive") throw new Error(`config field ${field.name}: mockClient() cannot invent a ${type.kind} value`);
17
+ if (type.name === "int" || type.name === "number") return "0";
18
+ if (type.name === "bool") return "false";
19
+ if (type.name === "string" || type.name === "secret" || type.name === "decimal" || type.name === "datetime") return quote("test");
20
+ throw new Error(`config field ${field.name}: mockClient() cannot invent a ${type.name} value`);
21
+ }
22
+
23
+ /** Mocks for stream results answer with bytes, like the transport does. */
24
+ function mockType(operation ) {
25
+ if (operation.events !== undefined) return `readonly ServerSentEvent<${tsType(operation.events)}>[]`;
26
+ const kind = bodyKind(operation.returns);
27
+ return kind === "stream" || kind === "bytes" ? "Uint8Array" : resultType(operation.returns);
28
+ }
29
+
30
+ function mockExpr(operation ) {
31
+ const route = `transport.route(${quote(operation.method)}, ${quote(operation.path)})`;
32
+ if (operation.events !== undefined) {
33
+ const check = textEvents(operation.events) ? "undefined" : decoderExpr(operation.events, `operations.${operation.name}.events`);
34
+ return `new OperationMock<${mockType(operation)}>(${quote(operation.name)}, ${route}, ${check}, "events")`;
35
+ }
36
+ const decoder =
37
+ bodyKind(operation.returns) === "json" && operation.returns !== undefined
38
+ ? `, ${decoderExpr(operation.returns, `operations.${operation.name}.returns`)}`
39
+ : "";
40
+ return `new OperationMock<${mockType(operation)}>(${quote(operation.name)}, ${route}${decoder})`;
41
+ }
42
+
43
+ function emitExamples(writer , ir ) {
44
+ const signatureOf = (named ) => (named.type.kind === "object" ? `(overrides?: Partial<${named.name}>)` : "()");
45
+ docComment(writer, ["Small, valid example values; pass overrides for the fields a test cares about."]);
46
+ writer.line(`export interface ${ir.name}Examples {`).indent((body) => ir.types.forEach((named) => body.line(`${named.name}${signatureOf(named)}: ${named.name};`)));
47
+ writer.line("}").line();
48
+
49
+ writer.line(`export const examples: ${ir.name}Examples = {`).indent((body) => {
50
+ for (const named of ir.types) {
51
+ const type = named.type;
52
+ if (type.kind === "object") {
53
+ body.line(`${named.name}: (overrides = {}) => ({`).indent((fields) => {
54
+ type.fields
55
+ .filter((field) => !field.optional)
56
+ .forEach((field) => fields.line(`${propertyKey(field.name)}: ${field.nullable ? "null" : exampleExpr(field.type, `types.${named.name}.${field.name}`)},`));
57
+ fields.line("...overrides,");
58
+ });
59
+ body.line("}),");
60
+ } else if (type.kind === "union") {
61
+ const first = type.variants[0];
62
+ if (first === undefined) throw new Error(`types.${named.name}: a union needs a variant`);
63
+ body.line(`${named.name}: () => ({ ...examples.${first.type}(), ${propertyKey(type.discriminator)}: ${quote(first.tag)} }),`);
64
+ }
65
+ }
66
+ });
67
+ writer.line("};");
68
+ }
69
+
70
+ export function emitTesting(ir , header ) {
71
+ const client = clientName(ir);
72
+ const body = createCodeWriter();
73
+ body.line("export interface RecordedEvent {").indent((fields) => {
74
+ fields.line("readonly name: string;");
75
+ fields.line("readonly fields: EventFields;");
76
+ });
77
+ body.line("}").line();
78
+
79
+ body.line(`export interface ${ir.name}Mock {`).indent((fields) => {
80
+ ir.operations.forEach((operation) => fields.line(`readonly ${operation.name}: OperationMock<${mockType(operation)}>;`));
81
+ fields.line("readonly transport: MockTransport;");
82
+ fields.line("readonly clock: FakeClock;");
83
+ fields.line("readonly events: readonly RecordedEvent[];");
84
+ });
85
+ body.line("}").line();
86
+
87
+ body.line(`const MOCK_BASE_URL = ${quote(MOCK_BASE_URL)};`).line();
88
+ docComment(body, [
89
+ `Creates a ${client} whose requests are answered by typed mocks instead of the network.`,
90
+ "Middleware still runs, the clock is fake and events are recorded, so tests exercise real SDK behaviour.",
91
+ ]);
92
+ body
93
+ .line(`export function mockClient(options: Partial<${ir.name}Options> = {}): { readonly client: ${client}; readonly mock: ${ir.name}Mock } {`)
94
+ .indent((fn) => {
95
+ fn.line("const transport = new MockTransport();");
96
+ fn.line("const clock = new FakeClock();");
97
+ fn.line("const events: RecordedEvent[] = [];");
98
+ fn.line(`const client = new ${client}({`).indent((args) => {
99
+ configFields(ir)
100
+ .filter((field) => !field.optional)
101
+ .forEach((field) => args.line(`${propertyKey(field.name)}: ${placeholder(field)},`));
102
+ args.line("...options,");
103
+ args.line("baseUrl: MOCK_BASE_URL,");
104
+ args.line("transport: transport.send,");
105
+ args.line("clock,");
106
+ args.line("onEvent: (name, fields) => {").indent((listener) => {
107
+ listener.line("events.push({ name, fields });");
108
+ listener.line("options.onEvent?.(name, fields);");
109
+ });
110
+ args.line("},");
111
+ });
112
+ fn.line("});");
113
+ fn.line(`const mock: ${ir.name}Mock = {`).indent((mock) => {
114
+ ir.operations.forEach((operation) => mock.line(`${operation.name}: ${mockExpr(operation)},`));
115
+ mock.line("transport,");
116
+ mock.line("clock,");
117
+ mock.line("events,");
118
+ });
119
+ fn.line("};");
120
+ fn.line("return { client, mock };");
121
+ })
122
+ .line("}")
123
+ .line();
124
+ emitExamples(body, ir);
125
+ const text = body.toString();
126
+
127
+ const writer = createCodeWriter().line(header).line();
128
+ writer.line('import { FakeClock, MockTransport, OperationMock } from "./runtime/testing.ts";');
129
+ writer.line('import type { EventFields } from "./runtime/context.ts";');
130
+ importLine(writer, "./runtime/sse.ts", [], usedNames(text, ["ServerSentEvent"]));
131
+ importLine(writer, "./runtime/models.ts", usedNames(text, MODEL_HELPERS), []);
132
+ importLine(writer, "./client.ts", [client], [`${ir.name}Options`]);
133
+ const typeNames = ir.types.map((named) => named.name);
134
+ importLine(writer, "./models.ts", usedNames(text, typeNames.map((name) => `decode${name}`)), usedNames(text, typeNames));
135
+ writer.line().line('export { FakeClock, MockTransport, OperationMock } from "./runtime/testing.ts";').line();
136
+ text.split("\n").forEach((line) => writer.line(line));
137
+ return writer.toString();
138
+ }
@@ -0,0 +1,52 @@
1
+ // src/webhooks.ts: verify<Name>Webhook per webhook, which checks the signature (kit block webhooks.verify) and decodes
2
+ // the body into the payload type.
3
+
4
+ import { createCodeWriter } from "@sdkloom/codegen";
5
+
6
+ import { docComment, pascal, usedNames } from "./naming.ts";
7
+ import { decoderExpr, tsType } from "./types.ts";
8
+
9
+ export function webhookFunction(hook ) {
10
+ return `verify${pascal(hook.name)}Webhook`;
11
+ }
12
+
13
+ function signatureLiteral(hook ) {
14
+ const { kind: _kind, algorithm: _algorithm, ...signature } = hook.signature;
15
+ return JSON.stringify(signature);
16
+ }
17
+
18
+ export function emitWebhooks(ir , header ) {
19
+ const hooks = ir.webhooks ?? [];
20
+ const body = createCodeWriter();
21
+ hooks.forEach((hook) => {
22
+ const constant = `${hook.name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toUpperCase()}_SIGNATURE`;
23
+ body.line(`const ${constant}: WebhookSignature = ${signatureLiteral(hook)};`).line();
24
+ docComment(body, [
25
+ ...(hook.doc === undefined ? [] : [hook.doc, ""]),
26
+ `Verifies a ${hook.name} webhook and reads its body. Pass the raw body, exactly as received, and the request headers.`,
27
+ "@throws {WebhookSignatureError} when the signature does not match the secret or the webhook is too old",
28
+ "@throws {DecodeError} when the body does not match the payload type",
29
+ ]);
30
+ body
31
+ .line(`export function ${webhookFunction(hook)}(body: Uint8Array | string, headers: WebhookHeaders, secret: string, options: { readonly nowSeconds?: number } = {}): ${tsType(hook.payload)} {`)
32
+ .indent((fn) => {
33
+ fn.line(`verifyWebhook(${constant}, body, headers, secret, options.nowSeconds ?? Math.floor(Date.now() / 1000));`);
34
+ fn.line('const text = typeof body === "string" ? body : new TextDecoder().decode(body);');
35
+ fn.line(`return (${decoderExpr(hook.payload, `webhooks.${hook.name}.payload`)})(JSON.parse(text) as unknown, "$");`);
36
+ })
37
+ .line("}")
38
+ .line();
39
+ });
40
+ const text = body.toString();
41
+ const typeNames = ir.types.map((named) => named.name);
42
+ const writer = createCodeWriter().line(header).line();
43
+ writer.line('import { verifyWebhook, type WebhookHeaders, type WebhookSignature } from "./runtime/webhooks.ts";');
44
+ const decoders = usedNames(text, typeNames.map((name) => `decode${name}`));
45
+ const types = usedNames(text, typeNames);
46
+ if (decoders.length + types.length > 0) writer.line(`import { ${[...decoders, ...types.map((name) => `type ${name}`)].join(", ")} } from "./models.ts";`);
47
+ const helpers = usedNames(text, ["asArray", "asBoolean", "asDecimal", "asEnum", "asInteger", "asMap", "asNumber", "asObject", "asString"]);
48
+ if (helpers.length > 0) writer.line(`import { ${helpers.join(", ")} } from "./runtime/models.ts";`);
49
+ writer.line();
50
+ text.split("\n").forEach((line) => writer.line(line));
51
+ return writer.toString().replace(/\n+$/, "\n");
52
+ }
@@ -0,0 +1,70 @@
1
+ // Generates the TypeScript SDK as an in-memory file tree.
2
+
3
+ import { createFileTree, } from "@sdkloom/codegen";
4
+
5
+ import { emitClient, emitErrors, emitLogic, emitMiddleware } from "./emit-client.ts";
6
+ import { emitModels } from "./emit-models.ts";
7
+ import { emitWebhooks } from "./emit-webhooks.ts";
8
+ import { emitIndex, emitPackageJson, emitReadme } from "./emit-package.ts";
9
+ import { emitTesting } from "./emit-testing.ts";
10
+ import { toLockBlock, vendorKitFile, } from "./runtime.ts";
11
+
12
+
13
+
14
+
15
+  
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+ function byPath(a , b ) {
32
+ if (a.path === b.path) return 0;
33
+ return a.path < b.path ? -1 : 1;
34
+ }
35
+
36
+ export function generateTypeScript(input ) {
37
+ const { ir } = input;
38
+ const header = `// Generated by sdkloom ${input.sdkloomVersion} from ${input.source}. Do not edit: run \`sdkloom build\` to regenerate.`;
39
+ const files = [];
40
+ const trace = new Map ();
41
+ const add = (path , text , from ) => {
42
+ files.push([path, text]);
43
+ trace.set(path, from);
44
+ };
45
+
46
+ const blocks = [];
47
+ for (const file of [...input.kit.files].sort(byPath)) {
48
+ const vendored = vendorKitFile(file, input.kit, header);
49
+ add(`src/runtime/${file.path}`, vendored.text, vendored.blocks.map((block) => `block:${block.id}`));
50
+ blocks.push(...vendored.blocks.map(toLockBlock));
51
+ }
52
+
53
+ const types = ir.types.map((named) => `ir:types.${named.name}`);
54
+ const operations = ir.operations.map((operation) => `ir:operations.${operation.name}`);
55
+ const info = { packageName: input.packageName, version: input.version, sdkloomVersion: input.sdkloomVersion, source: input.source, nodeVersions: input.kit.supports };
56
+
57
+ add("src/models.ts", emitModels(ir, header), types);
58
+ add("src/errors.ts", emitErrors(ir, header), operations);
59
+ add("src/middleware.ts", emitMiddleware(ir, input.middlewareSources, header), ir.middlewares.map((entry) => `middleware:${entry.name}`));
60
+ add("src/client.ts", emitClient(ir, header, { name: input.packageName, version: input.version }), ["ir:servers", ...operations]);
61
+ add("src/testing.ts", emitTesting(ir, header), [...types, ...operations]);
62
+ if ((ir.webhooks ?? []).length > 0) add("src/webhooks.ts", emitWebhooks(ir, header), (ir.webhooks ?? []).map((hook) => `ir:webhooks.${hook.name}`));
63
+ const logic = ir.logic ?? [];
64
+ if (logic.length > 0) add("src/logic.ts", emitLogic(ir, input.logicSources ?? new Map(), header), logic.map((entry) => `ir:logic.${entry.name}`));
65
+ add("src/index.ts", emitIndex(header, (ir.webhooks ?? []).length > 0, logic.length > 0), ["ir"]);
66
+ add("package.json", emitPackageJson(ir, info), ["config"]);
67
+ add("README.md", emitReadme(ir, info), ["config", "ir"]);
68
+
69
+ return { files: createFileTree(files), trace, blocks };
70
+ }
@@ -0,0 +1,3 @@
1
+ export { generateTypeScript, } from "./generate.ts";
2
+
3
+ export { webhookFunction } from "./emit-webhooks.ts";
@@ -0,0 +1,64 @@
1
+ // Names and comments in generated TypeScript.
2
+
3
+
4
+
5
+ const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
6
+ const COMMENT_LINE = /^\s*(\/\*\*|\*|\/\/)/;
7
+
8
+ export function quote(text ) {
9
+ return JSON.stringify(text);
10
+ }
11
+
12
+ /** An object key: bare when it is an identifier, quoted otherwise ("x-request-id"). */
13
+ export function propertyKey(name ) {
14
+ return IDENTIFIER.test(name) ? name : quote(name);
15
+ }
16
+
17
+ export function pascal(name ) {
18
+ return name
19
+ .split(/[^A-Za-z0-9]+/)
20
+ .filter((part) => part !== "")
21
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
22
+ .join("");
23
+ }
24
+
25
+ /** getOrder → GET_ORDER */
26
+ export function constantName(name ) {
27
+ return name
28
+ .replace(/([a-z0-9])([A-Z])/g, "$1_$2")
29
+ .replace(/[^A-Za-z0-9]+/g, "_")
30
+ .toUpperCase();
31
+ }
32
+
33
+ export function errorClassName(name ) {
34
+ return name.endsWith("Error") ? name : `${name}Error`;
35
+ }
36
+
37
+ export function memberDoc(doc , deprecated ) {
38
+ return [...(doc === undefined ? [] : [doc]), ...(deprecated === undefined ? [] : [`@deprecated ${deprecated}`])];
39
+ }
40
+
41
+ /** Writes a JSDoc block; nothing when there is no text. */
42
+ export function docComment(writer , lines ) {
43
+ const content = lines.flatMap((line) => line.split("\n")).map((line) => line.replaceAll("*/", "*\\/"));
44
+ const last = content.findLastIndex((line) => line.trim() !== "");
45
+ if (last === -1) return;
46
+ writer.line("/**");
47
+ content.slice(0, last + 1).forEach((line) => writer.line(line === "" ? " *" : ` * ${line}`));
48
+ writer.line(" */");
49
+ }
50
+
51
+ /** Which of `names` appear in code (comments are ignored), in the given order. */
52
+ export function usedNames(text , names ) {
53
+ const code = text
54
+ .split("\n")
55
+ .filter((line) => !COMMENT_LINE.test(line))
56
+ .join("\n");
57
+ return names.filter((name) => new RegExp(`(^|[^A-Za-z0-9_$.])${name.replace(/\$/g, "\\$")}(?![A-Za-z0-9_$])`).test(code));
58
+ }
59
+
60
+ /** `import { a, type B } from "path";` for the names that are used; nothing when none are. */
61
+ export function importLine(writer , from , values , types ) {
62
+ const specifiers = [...values, ...types.map((name) => `type ${name}`)];
63
+ if (specifiers.length > 0) writer.line(`import { ${specifiers.join(", ")} } from ${quote(from)};`);
64
+ }
@@ -0,0 +1,81 @@
1
+ // Copies kit files into the SDK, turning block metadata into documentation.
2
+
3
+ import { createCodeWriter, sha256, } from "@sdkloom/codegen";
4
+ import { parseBlocks, } from "@sdkloom/kit";
5
+ import { docComment } from "./naming.ts";
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+ const TAG_LINE = /^\s*\/\/\s*@([a-z][a-z-]*)\b/;
21
+ const QUOTE_INDENT = " ";
22
+ const SHORT_HASH = 12;
23
+
24
+ function blockDoc(block , kit ) {
25
+ const sources = block.sources.flatMap((source) => [
26
+ ` [${source.index}] ${source.url}`,
27
+ ...block.quotes.filter((quote) => quote.index === source.index).map((quote) => `${QUOTE_INDENT}"${quote.text}"`),
28
+ ]);
29
+ return [
30
+ block.summary ?? "",
31
+ "",
32
+ `Supported versions: Node.js ${block.versions ?? kit.supports}`,
33
+ ...(block.security === undefined ? [] : [`Security: ${block.security}`]),
34
+ "",
35
+ "Sources:",
36
+ ...sources,
37
+ ` Retrieved: ${block.retrieved ?? "unknown"}`,
38
+ "",
39
+ `Provenance: block ${block.id} · kit ${kit.name} ${kit.version} · sha256:${sha256(block.code).slice(0, SHORT_HASH)}`,
40
+ ];
41
+ }
42
+
43
+
44
+
45
+
46
+
47
+
48
+ export function vendorKitFile(file , kit , header ) {
49
+ const parsed = parseBlocks(file.text, { commentPrefix: "//", file: file.path });
50
+ if (parsed.errors.length > 0) {
51
+ throw new Error(`kit file ${file.path} is invalid: ${parsed.errors.map((error) => `line ${error.line}: ${error.message}`).join("; ")}`);
52
+ }
53
+
54
+ const writer = createCodeWriter();
55
+ writer.line(header).line();
56
+ let blockIndex = 0;
57
+ let inMetadata = false;
58
+ for (const line of file.text.split("\n")) {
59
+ const tag = TAG_LINE.exec(line)?.[1];
60
+ if (tag === "block") {
61
+ const block = parsed.blocks[blockIndex];
62
+ blockIndex += 1;
63
+ inMetadata = true;
64
+ if (block !== undefined) docComment(writer, blockDoc(block, kit));
65
+ continue;
66
+ }
67
+ if (tag === "end" || (inMetadata && tag !== undefined)) continue;
68
+ inMetadata = false;
69
+ writer.line(line);
70
+ }
71
+ return { text: writer.toString(), blocks: parsed.blocks };
72
+ }
73
+
74
+ export function toLockBlock(block ) {
75
+ return {
76
+ id: block.id,
77
+ versions: block.versions ?? "*",
78
+ code: block.code,
79
+ ...(block.strategy === undefined ? {} : { strategy: block.strategy }),
80
+ };
81
+ }
@@ -0,0 +1,136 @@
1
+ // Maps IR types to TypeScript types, decoders and example values.
2
+
3
+
4
+ import { quote } from "./naming.ts";
5
+
6
+ /** Discriminator value used for union variants the SDK does not know yet. */
7
+ export const UNKNOWN_VARIANT = "$unknown";
8
+
9
+ const TS_TYPE = {
10
+ string: "string",
11
+ secret: "string",
12
+ datetime: "string",
13
+ decimal: "string",
14
+ int: "number",
15
+ number: "number",
16
+ bool: "boolean",
17
+ bytes: "Uint8Array",
18
+ stream: "AsyncIterable<Uint8Array>",
19
+ multipart: "MultipartForm",
20
+ };
21
+
22
+ const JSON_DECODER = {
23
+ string: "asString",
24
+ secret: "asString",
25
+ datetime: "asString",
26
+ decimal: "asDecimal",
27
+ int: "asInteger",
28
+ number: "asNumber",
29
+ bool: "asBoolean",
30
+ };
31
+
32
+ const EXAMPLE = {
33
+ string: quote("string"),
34
+ secret: quote("secret"),
35
+ datetime: quote("2026-01-01T00:00:00Z"),
36
+ decimal: quote("1.00"),
37
+ int: "1",
38
+ number: "1.5",
39
+ bool: "true",
40
+ };
41
+
42
+ function onlyAtTopLevel(name , path ) {
43
+ throw new Error(`${path}: ${name} values are only supported as an operation body or result`);
44
+ }
45
+
46
+ function inline(path ) {
47
+ throw new Error(`${path}: inline object and union types are not supported; use model() or union()`);
48
+ }
49
+
50
+ function wrap(type ) {
51
+ return type.includes(" | ") ? `(${type})` : type;
52
+ }
53
+
54
+ export function tsType(node ) {
55
+ switch (node.kind) {
56
+ case "primitive":
57
+ return TS_TYPE[node.name];
58
+ case "enum":
59
+ return [...node.values.map(quote), "(string & {})"].join(" | ");
60
+ case "list":
61
+ return `readonly ${wrap(tsType(node.item))}[]`;
62
+ case "map":
63
+ return `Readonly<Record<string, ${tsType(node.value)}>>`;
64
+ case "ref":
65
+ return node.name;
66
+ case "object":
67
+ case "union":
68
+ return inline("type");
69
+ }
70
+ }
71
+
72
+ /** A decoder expression `(value, path) => T` for a JSON value of this type. */
73
+ export function decoderExpr(node , path ) {
74
+ switch (node.kind) {
75
+ case "primitive":
76
+ return JSON_DECODER[node.name] ?? onlyAtTopLevel(node.name, path);
77
+ case "enum":
78
+ return `(value: unknown, path: string) => asEnum(value, path, [${node.values.map(quote).join(", ")}])`;
79
+ case "list":
80
+ return `(value: unknown, path: string) => asArray(value, path, ${decoderExpr(node.item, path)})`;
81
+ case "map":
82
+ return `(value: unknown, path: string) => asMap(value, path, ${decoderExpr(node.value, path)})`;
83
+ case "ref":
84
+ return `decode${node.name}`;
85
+ case "object":
86
+ case "union":
87
+ return inline(path);
88
+ }
89
+ }
90
+
91
+ /** A small, valid, deterministic example value. Lists and maps start empty. */
92
+ export function exampleExpr(node , path ) {
93
+ switch (node.kind) {
94
+ case "primitive":
95
+ return EXAMPLE[node.name] ?? onlyAtTopLevel(node.name, path);
96
+ case "enum":
97
+ return quote(node.values[0] ?? "");
98
+ case "list":
99
+ return "[]";
100
+ case "map":
101
+ return "{}";
102
+ case "ref":
103
+ return `examples.${node.name}()`;
104
+ case "object":
105
+ case "union":
106
+ return inline(path);
107
+ }
108
+ }
109
+
110
+
111
+
112
+ export function bodyKind(node ) {
113
+ if (node === undefined) return undefined;
114
+ if (node.kind === "primitive" && (node.name === "stream" || node.name === "bytes" || node.name === "multipart")) return node.name;
115
+ return "json";
116
+ }
117
+
118
+ /** An event stream whose data stays text: no decoder, the data is a string. */
119
+ export function textEvents(node ) {
120
+ return node.kind === "primitive" && node.name === "string";
121
+ }
122
+
123
+ /** What an operation's raw call resolves to: its result, or the stream of its events. */
124
+ export function operationResultType(operation ) {
125
+ return operation.events === undefined ? resultType(operation.returns) : `AsyncIterable<ServerSentEvent<${tsType(operation.events)}>>`;
126
+ }
127
+
128
+ /** TypeScript type of an operation result. */
129
+ export function resultType(node ) {
130
+ return node === undefined ? "undefined" : tsType(node);
131
+ }
132
+
133
+ /** TypeScript type accepted as an operation body. */
134
+ export function bodyType(node ) {
135
+ return node.kind === "primitive" && node.name === "stream" ? "Uint8Array | AsyncIterable<Uint8Array>" : tsType(node);
136
+ }
@@ -0,0 +1,22 @@
1
+ // The public surface of an SDK, written to api.json and compared between versions.
2
+
3
+
4
+
5
+ const DOCUMENTATION = new Set(["doc"]);
6
+
7
+ function strip(value ) {
8
+ if (Array.isArray(value)) return value.map(strip);
9
+ if (typeof value === "object" && value !== null) {
10
+ return Object.fromEntries(
11
+ Object.entries(value)
12
+ .filter(([key]) => !DOCUMENTATION.has(key))
13
+ .map(([key, item]) => [key, strip(item)]),
14
+ );
15
+ }
16
+ return value;
17
+ }
18
+
19
+ /** Everything callers depend on. Documentation is left out, so editing docs is not an API change. */
20
+ export function apiSurface(ir ) {
21
+ return strip(ir);
22
+ }
@@ -0,0 +1,52 @@
1
+ // Small helpers shared by the IR validators. Every check reports "<path>: <message>".
2
+
3
+
4
+
5
+ export const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
6
+
7
+ export function isRecord(value ) {
8
+ return typeof value === "object" && value !== null && !Array.isArray(value);
9
+ }
10
+
11
+ export function isNonEmptyString(value ) {
12
+ return typeof value === "string" && value !== "";
13
+ }
14
+
15
+ export function join(path , key ) {
16
+ return path === "" ? key : `${path}.${key}`;
17
+ }
18
+
19
+ /** Returns the list, or reports and returns [] when the value is not an array. */
20
+ export function listAt(value , path , report ) {
21
+ if (Array.isArray(value)) return value;
22
+ report(path, "must be a list");
23
+ return [];
24
+ }
25
+
26
+ export function checkOptionalText(record , key , path , report ) {
27
+ if (key in record && typeof record[key] !== "string") report(join(path, key), "must be a string");
28
+ }
29
+
30
+ export function checkBoolean(record , key , path , report ) {
31
+ if (typeof record[key] !== "boolean") report(join(path, key), "must be a boolean");
32
+ }
33
+
34
+ export function checkOneOf(value , allowed , path , report ) {
35
+ if (typeof value !== "string" || !allowed.includes(value)) report(path, `must be one of ${allowed.join(", ")}`);
36
+ }
37
+
38
+ /** Reports every entry that is not a non-empty string. */
39
+ export function checkNameList(value , path , report ) {
40
+ listAt(value, path, report).forEach((entry, index) => {
41
+ if (!isNonEmptyString(entry)) report(`${path}[${index}]`, "must be a non-empty string");
42
+ });
43
+ }
44
+
45
+ /** Tracks names and reports the second and later occurrences of each. */
46
+ export function createDuplicateTracker(label , report ) {
47
+ const seen = new Set ();
48
+ return (name, path) => {
49
+ if (seen.has(name)) report(path, `duplicate ${label} ${name}`);
50
+ seen.add(name);
51
+ };
52
+ }
@@ -0,0 +1,32 @@
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+ export { apiSurface } from "./api-surface.ts";
31
+ export { validateIr } from "./validate-ir.ts";
32
+ export { pagedItems } from "./pages.ts";