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,145 @@
1
+ // sdkloom kit check <dir> [--allowed-sources <file>]
2
+
3
+ import { existsSync, readFileSync } from "node:fs";
4
+ import { extname, join, resolve } from "node:path";
5
+ import { checkKit, checkVersionPolicy, parseBlocks, verifySources, } from "@sdkloom/kit";
6
+ import { compareText, listFiles, plural, readJson, summary, toPosix, } from "../io.ts";
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+ const LANGUAGES = {
15
+ python: { commentPrefix: "#", extensions: [".py"] },
16
+ ruby: { commentPrefix: "#", extensions: [".rb"] },
17
+ typescript: { commentPrefix: "//", extensions: [".ts", ".mts", ".cts"] },
18
+ javascript: { commentPrefix: "//", extensions: [".js", ".mjs", ".cjs"] },
19
+ java: { commentPrefix: "//", extensions: [".java"] },
20
+ kotlin: { commentPrefix: "//", extensions: [".kt"] },
21
+ csharp: { commentPrefix: "//", extensions: [".cs"] },
22
+ go: { commentPrefix: "//", extensions: [".go"] },
23
+ rust: { commentPrefix: "//", extensions: [".rs"] },
24
+ swift: { commentPrefix: "//", extensions: [".swift"] },
25
+ };
26
+
27
+ const MANIFEST_FIELDS = ["name", "language", "version", "supports"] ;
28
+
29
+ function isRecord(value ) {
30
+ return typeof value === "object" && value !== null && !Array.isArray(value);
31
+ }
32
+
33
+ function readManifest(dir , display , io ) {
34
+ const result = readJson(join(dir, "kit.json"), `${display}/kit.json`);
35
+ if (!result.ok) {
36
+ io.err(result.message);
37
+ return null;
38
+ }
39
+ const value = result.value;
40
+ if (!isRecord(value) || MANIFEST_FIELDS.some((field) => typeof value[field] !== "string")) {
41
+ io.err(`${display}/kit.json: must have string fields ${MANIFEST_FIELDS.join(", ")}`);
42
+ return null;
43
+ }
44
+ return { name: String(value["name"]), language: String(value["language"]), version: String(value["version"]), supports: String(value["supports"]) };
45
+ }
46
+
47
+ function readAllowedSources(path , display , io ) {
48
+ const result = readJson(path, display);
49
+ if (!result.ok) {
50
+ io.err(result.message);
51
+ return null;
52
+ }
53
+ const sources = isRecord(result.value) ? result.value["sources"] : undefined;
54
+ if (!Array.isArray(sources) || !sources.every((entry) => typeof entry === "string")) {
55
+ io.err(`${display}: must have a "sources" list of strings`);
56
+ return null;
57
+ }
58
+ return sources;
59
+ }
60
+
61
+ export function parseKitSources(dir , syntax ) {
62
+ const results = listFiles(join(dir, "src"))
63
+ .filter((path) => syntax.extensions.includes(extname(path)))
64
+ .map((path) => parseBlocks(readFileSync(join(dir, "src", path), "utf8"), { commentPrefix: syntax.commentPrefix, file: `src/${path}` }));
65
+ return { blocks: results.flatMap((result) => [...result.blocks]), errors: results.flatMap((result) => [...result.errors]) };
66
+ }
67
+
68
+ function versionIssues(dir ) {
69
+ const path = join(dir, "versions.json");
70
+ if (!existsSync(path)) return [];
71
+ const result = readJson(path, "versions.json");
72
+ if (!result.ok) return [`versions.json VERSIONS ${result.message}`];
73
+ return checkVersionPolicy(result.value).map((message) => `versions.json VERSIONS ${message}`);
74
+ }
75
+
76
+ export function kitCheck(dirArg , allowedSourcesArg , io ) {
77
+ if (dirArg === undefined) {
78
+ io.err("kit check: missing <dir>");
79
+ return 2;
80
+ }
81
+ const dir = resolve(io.cwd, dirArg);
82
+ const display = toPosix(dirArg).replace(/\/+$/, "");
83
+
84
+ const manifest = readManifest(dir, display, io);
85
+ if (manifest === null) return 1;
86
+ const syntax = LANGUAGES[manifest.language];
87
+ if (syntax === undefined) {
88
+ io.err(`${display}/kit.json: unsupported language ${manifest.language}`);
89
+ return 1;
90
+ }
91
+
92
+ const allowedPath = allowedSourcesArg === undefined ? join(dir, "..", "allowed-sources.json") : resolve(io.cwd, allowedSourcesArg);
93
+ const allowedDisplay = allowedSourcesArg ?? `${display}/../allowed-sources.json`;
94
+ const allowedSources = readAllowedSources(allowedPath, allowedDisplay, io);
95
+ if (allowedSources === null) return 1;
96
+
97
+ const { blocks, errors } = parseKitSources(dir, syntax);
98
+ const issues = checkKit(manifest, blocks, {
99
+ allowedSources,
100
+ testExists: (ref) => existsSync(join(dir, ref.split("::")[0] ?? "")),
101
+ manifestFile: "kit.json",
102
+ });
103
+
104
+ const lines = [
105
+ ...[...errors].sort((a, b) => compareText(a.file, b.file) || a.line - b.line).map((error) => `${error.file}:${error.line} PARSE ${error.message}`),
106
+ ...issues.map((issue) => `${issue.file}:${issue.line} ${issue.code} ${issue.message}`),
107
+ ...versionIssues(dir),
108
+ ];
109
+ lines.forEach((line) => io.out(line));
110
+ io.out(summary(`kit ${manifest.name}: ${plural(blocks.length, "block")}`, lines.length));
111
+ return lines.length === 0 ? 0 : 1;
112
+ }
113
+
114
+ /** sdkloom kit sources <dir> [--verify]: lists every cited page, or fetches them and checks every quote word for word. */
115
+ export async function kitSources(dirArg , verify , io , fetcher = fetchText) {
116
+ if (dirArg === undefined) {
117
+ io.err("kit sources: missing <dir>");
118
+ return 2;
119
+ }
120
+ const dir = resolve(io.cwd, dirArg);
121
+ const display = toPosix(dirArg).replace(/\/+$/, "");
122
+ const manifest = readManifest(dir, display, io);
123
+ if (manifest === null) return 1;
124
+ const syntax = LANGUAGES[manifest.language];
125
+ if (syntax === undefined) {
126
+ io.err(`${display}/kit.json: unsupported language ${manifest.language}`);
127
+ return 1;
128
+ }
129
+ const { blocks } = parseKitSources(dir, syntax);
130
+ if (!verify) {
131
+ [...new Set(blocks.flatMap((block) => block.sources.map((source) => source.url)))].sort().forEach((url) => io.out(url));
132
+ return 0;
133
+ }
134
+ const results = await verifySources(blocks, fetcher);
135
+ results.filter((result) => result.status !== "found").forEach((result) => io.out(`${result.block} [${result.index}] ${result.status}: ${result.url}${result.detail === undefined ? "" : ` (${result.detail})`}`));
136
+ const count = (status ) => results.filter((result) => result.status === status).length;
137
+ io.out(`kit ${manifest.name}: ${count("found")} quotes found, ${count("missing")} missing, ${count("unreachable")} unreachable`);
138
+ return count("missing") + count("unreachable") === 0 ? 0 : 1;
139
+ }
140
+
141
+ async function fetchText(url ) {
142
+ const response = await fetch(url);
143
+ if (response.status < 200 || response.status > 299) throw new Error(`HTTP ${response.status}`);
144
+ return new TextDecoder().decode(new Uint8Array(await response.arrayBuffer()));
145
+ }
@@ -0,0 +1,81 @@
1
+ // sdkloom publish [--dry-run] [--yes] — packages every target (npm tarball, Python wheel, Maven Central bundle) with an
2
+ // SBOM into dist/, then uploads them. Uploading needs --yes, complete metadata, a token per registry and, for Maven
3
+ // Central, gpg signatures (SDKLOOM_GPG_KEY). Every check runs before the first upload.
4
+
5
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
6
+ import { tmpdir } from "node:os";
7
+ import { join } from "node:path";
8
+ import { cycloneDx, } from "@sdkloom/packager";
9
+ import { buildInMemory, SDKLOOM_VERSION, writeBuild } from "../build.ts";
10
+ import { plural, } from "../io.ts";
11
+ import { languageModule } from "../languages/index.ts";
12
+ import { loadProject } from "../project.ts";
13
+ import { messageOf, reportBuilt } from "./build.ts";
14
+
15
+ const DIST = "dist";
16
+
17
+ /** 12345 → "12.1 kB": what a user downloads. */
18
+ export function kilobytes(size ) {
19
+ return `${(size / 1024).toFixed(1)} kB`;
20
+ }
21
+
22
+ export async function publishCommand(io , dryRun , yes ) {
23
+ const workspace = mkdtempSync(join(tmpdir(), "sdkloom-publish-"));
24
+ try {
25
+ const project = await loadProject(io.cwd);
26
+ const result = buildInMemory(project);
27
+ writeBuild(io.cwd, result);
28
+ reportBuilt(result, io);
29
+ const metadata = { ...(result.ir.doc === undefined ? {} : { description: result.ir.doc }), ...(project.config.publish ?? {}) };
30
+ const packaged = result.targets.map((target) => languageModule(target.language).pack(project, target, metadata, join(workspace, target.name)));
31
+ for (const item of packaged) {
32
+ const dir = join(io.cwd, DIST, item.target.name);
33
+ rmSync(dir, { recursive: true, force: true });
34
+ mkdirSync(dir, { recursive: true });
35
+ writeFileSync(join(dir, item.artifact.fileName), item.artifact.bytes);
36
+ const kit = item.target.lockFile.kits[0];
37
+ writeFileSync(
38
+ join(dir, "bom.cdx.json"),
39
+ cycloneDx({
40
+ name: item.name,
41
+ version: project.config.version,
42
+ purl: item.purl,
43
+ ...(metadata.license === undefined ? {} : { license: metadata.license }),
44
+ kit: { name: kit?.name ?? item.target.language, version: kit?.version ?? "" },
45
+ lockSha256: item.target.lockFile.output.sha256,
46
+ sdkloomVersion: SDKLOOM_VERSION,
47
+ }),
48
+ );
49
+ io.out(`${DIST}/${item.target.name}/${item.artifact.fileName} (${plural(item.artifact.contents.length, "file")}, ${kilobytes(item.artifact.bytes.length)}) → ${item.upload.registry}`);
50
+ if (item.artifact.missing.length > 0) io.out(` missing for ${item.upload.registry}: ${item.artifact.missing.join(", ")}`);
51
+ }
52
+ if (dryRun) {
53
+ io.out("dry run: nothing uploaded");
54
+ return 0;
55
+ }
56
+ if (!yes) {
57
+ io.err("publishing uploads to public registries; run sdkloom publish --yes to do it (or --dry-run to only package)");
58
+ return 1;
59
+ }
60
+ const uploads = packaged.filter((item) => item.upload.manual === undefined);
61
+ const problems = uploads.flatMap((item) => [
62
+ ...item.artifact.missing.map((field) => `${item.target.name}: ${field === "signatures" ? "unsigned; set SDKLOOM_GPG_KEY to sign with gpg" : `add publish.${field} to sdkloom.config.ts`}`),
63
+ ...(process.env[item.upload.tokenVariable] === undefined ? [`${item.target.name}: set ${item.upload.tokenVariable}`] : []),
64
+ ]);
65
+ if (problems.length > 0) {
66
+ problems.forEach((problem) => io.err(problem));
67
+ io.err("nothing uploaded");
68
+ return 1;
69
+ }
70
+ packaged.filter((item) => item.upload.manual !== undefined).forEach((item) => io.out(`${item.target.name}: ${item.upload.manual ?? ""}`));
71
+ for (const item of uploads) {
72
+ io.out(`published ${item.name}@${project.config.version}: ${await item.upload.send(process.env[item.upload.tokenVariable] ?? "")}`);
73
+ }
74
+ return 0;
75
+ } catch (error ) {
76
+ io.err(messageOf(error));
77
+ return 1;
78
+ } finally {
79
+ rmSync(workspace, { recursive: true, force: true });
80
+ }
81
+ }
@@ -0,0 +1,49 @@
1
+ // sdkloom recipe list | recipe add <name> — copies a ready-made middleware into the project as source the author owns.
2
+
3
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+
6
+
7
+ const RECIPES_DIR = join(import.meta.dirname, "..", "..", "recipes");
8
+ const TARGET_DIR = join("sdk", "recipes");
9
+
10
+ function recipeNames() {
11
+ return readdirSync(RECIPES_DIR)
12
+ .filter((file) => file.endsWith(".ts"))
13
+ .map((file) => file.replace(/\.ts$/, ""))
14
+ .sort();
15
+ }
16
+
17
+ /** The `doc` option of the recipe's middleware(), e.g. "Retries 429 and 5xx responses with exponential backoff." */
18
+ function summary(name ) {
19
+ const text = readFileSync(join(RECIPES_DIR, `${name}.ts`), "utf8");
20
+ return /doc: "([^"]+)"/.exec(text)?.[1] ?? "";
21
+ }
22
+
23
+ export function recipeList(io ) {
24
+ const names = recipeNames();
25
+ const width = Math.max(...names.map((name) => name.length)) + 2;
26
+ io.out("Recipes (add one with: sdkloom recipe add <name>):");
27
+ names.forEach((name) => io.out(` ${name.padEnd(width)}${summary(name)}`));
28
+ return 0;
29
+ }
30
+
31
+ export function recipeAdd(name , io ) {
32
+ const names = recipeNames();
33
+ if (name === undefined || !names.includes(name)) {
34
+ io.err(`${name === undefined ? "name a recipe" : `unknown recipe ${name}`}; available: ${names.join(", ")}`);
35
+ return 1;
36
+ }
37
+ const target = join(io.cwd, TARGET_DIR, `${name}.ts`);
38
+ const display = `${TARGET_DIR.split("\\").join("/")}/${name}.ts`;
39
+ if (existsSync(target)) {
40
+ io.err(`${display} already exists; not overwriting it`);
41
+ return 1;
42
+ }
43
+ mkdirSync(join(io.cwd, TARGET_DIR), { recursive: true });
44
+ writeFileSync(target, readFileSync(join(RECIPES_DIR, `${name}.ts`), "utf8"));
45
+ io.out(`added ${display}. Use it in sdk/index.ts:`);
46
+ io.out(` import { ${name} } from "./recipes/${name}.ts";`);
47
+ io.out(` … use: [${name}] …`);
48
+ return 0;
49
+ }
@@ -0,0 +1,181 @@
1
+ // sdkloom record <operation> — calls the real API once through the generated TypeScript SDK and saves what happened as
2
+ // a scenario, so every language is tested against a real answer. Secret config values (t.secret) never reach the file:
3
+ // they are replaced by a placeholder everywhere, in the config, the request and the response, so the scenario still
4
+ // replays consistently.
5
+
6
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
7
+ import { join } from "node:path";
8
+ import { pathToFileURL } from "node:url";
9
+
10
+ import { buildInMemory, writeBuild } from "../build.ts";
11
+ import { listFiles, } from "../io.ts";
12
+ import { loadProject } from "../project.ts";
13
+ import { messageOf } from "./build.ts";
14
+
15
+ export const SECRET_PLACEHOLDER = "recorded-secret";
16
+ const DROPPED_RESPONSE_HEADERS = new Set(["date", "content-length", "connection", "keep-alive", "transfer-encoding", "server", "content-type", "content-encoding"]);
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+ function parseJson(text , flag ) {
41
+ if (text === undefined) return {};
42
+ const value = JSON.parse(text);
43
+ if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${flag} must be a JSON object`);
44
+ return value ;
45
+ }
46
+
47
+ function secretValues(ir , config ) {
48
+ return ir.middlewares
49
+ .flatMap((middleware) => middleware.config)
50
+ .filter((field) => field.type.kind === "primitive" && field.type.name === "secret")
51
+ .map((field) => config[field.name])
52
+ .filter((value) => typeof value === "string" && value !== "");
53
+ }
54
+
55
+ /** Every form a secret can take in the saved JSON: as is, JSON-escaped, URL-encoded and in Base64 (Basic auth). */
56
+ function forms(secret ) {
57
+ const placeholder = SECRET_PLACEHOLDER;
58
+ const base64 = (value ) => {
59
+ let binary = "";
60
+ new TextEncoder().encode(value).forEach((byte) => (binary += String.fromCharCode(byte)));
61
+ return btoa(binary);
62
+ };
63
+ return [
64
+ [JSON.stringify(secret).slice(1, -1), placeholder],
65
+ [secret, placeholder],
66
+ [encodeURIComponent(secret), placeholder],
67
+ [base64(secret), base64(placeholder)],
68
+ ];
69
+ }
70
+
71
+ /** Replaces every form of every secret, longest first, so a secret that contains another leaves nothing behind. */
72
+ function mask(text , secrets , basicUsers ) {
73
+ const pairs = [
74
+ ...secrets.flatMap(forms),
75
+ ...basicUsers.flatMap((user) => secrets.map((secret) => {
76
+ const encode = (value ) => {
77
+ let binary = "";
78
+ new TextEncoder().encode(value).forEach((byte) => (binary += String.fromCharCode(byte)));
79
+ return btoa(binary);
80
+ };
81
+ return [encode(`${user}:${secret}`), encode(`${user}:${SECRET_PLACEHOLDER}`)];
82
+ })),
83
+ ]
84
+ .filter(([from]) => from !== "")
85
+ .sort(([a], [b]) => b.length - a.length);
86
+ return pairs.reduce((masked, [from, to]) => masked.split(from).join(to), text);
87
+ }
88
+
89
+ function nextId(root , dir , operation ) {
90
+ const numbers = listFiles(join(root, dir)).map((path) => Number(/^(\d+)-/.exec(path)?.[1] ?? 0));
91
+ const kebab = operation.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[^A-Za-z0-9]+/g, "-").toLowerCase();
92
+ return `${String(Math.max(0, ...numbers) + 1).padStart(4, "0")}-${kebab}-recorded`;
93
+ }
94
+
95
+ export async function recordCommand(io , options ) {
96
+ try {
97
+ const project = await loadProject(io.cwd);
98
+ const result = buildInMemory(project);
99
+ const typescript = result.targets.find((target) => target.language === "typescript");
100
+ if (typescript === undefined) throw new Error("sdkloom record calls the API through the TypeScript SDK; add targets.typescript");
101
+ const operation = result.ir.operations.find((candidate) => candidate.name === options.operation);
102
+ if (operation === undefined) throw new Error(`name an operation to record: ${result.ir.operations.map((candidate) => candidate.name).join(", ")}`);
103
+ const args = parseJson(options.args, "--args");
104
+ const config = parseJson(options.config, "--config");
105
+ writeBuild(io.cwd, result);
106
+
107
+ const sdk = (await import(`${pathToFileURL(join(io.cwd, typescript.outDir, "src", "index.ts")).href}?record=${Date.now()}`)) ;
108
+ const fetchTransport = sdk["fetchTransport"] ;
109
+ const Client = sdk[`${result.ir.name}Client`] ;
110
+ const encodeJson = ((await import(`${pathToFileURL(join(io.cwd, typescript.outDir, "src", "runtime", "models.ts")).href}?record=${Date.now()}`)) ).encodeJson;
111
+ const real = fetchTransport();
112
+ const exchanges = [];
113
+ const recording = async (request, sendOptions) => {
114
+ const response = await real(request, sendOptions);
115
+ exchanges.push({ request, response });
116
+ return response;
117
+ };
118
+ const client = new Client({ ...config, ...(options.baseUrl === undefined ? {} : { baseUrl: options.baseUrl }), transport: recording });
119
+ const method = client[operation.name];
120
+ let expect ;
121
+ try {
122
+ const hasArgs = operation.params.length > 0 || operation.body !== undefined;
123
+ const value = await (hasArgs ? method?.call(client, args) : method?.call(client));
124
+ expect = { equals: value === undefined ? null : JSON.parse(new TextDecoder().decode(encodeJson(value))) };
125
+ } catch (error ) {
126
+ if (!(error instanceof Error) || exchanges.length === 0) throw error;
127
+ expect = { error: error.name };
128
+ }
129
+ const last = exchanges[exchanges.length - 1];
130
+ if (last === undefined) throw new Error("no request reached the API");
131
+ const secrets = secretValues(result.ir, config);
132
+ const request = last.request;
133
+ const url = new URL(request.url);
134
+ const server = result.ir.servers.find((candidate) => candidate.name === result.ir.defaultServer)?.url ?? url.origin;
135
+ const basePath = new URL(options.baseUrl ?? server).pathname.replace(/\/$/, "");
136
+ const requestBody = request.body instanceof Uint8Array && request.body.length > 0 ? new TextDecoder().decode(request.body) : undefined;
137
+ const responseText = new TextDecoder().decode(await last.response.bytes());
138
+ const responseHeaders = last.response.headers.filter(([name]) => !DROPPED_RESPONSE_HEADERS.has(name.toLowerCase()));
139
+ const scenarioDir = project.config.scenarios ?? "scenarios";
140
+ const id = nextId(io.cwd, scenarioDir, operation.name);
141
+ const isJson = (text ) => {
142
+ try {
143
+ JSON.parse(text);
144
+ return text !== "";
145
+ } catch {
146
+ return false;
147
+ }
148
+ };
149
+ const scenario = {
150
+ id,
151
+ name: `${operation.name} as the real API answered it`,
152
+ level: "MUST",
153
+ requirements: ["recorded"],
154
+ config: Object.fromEntries(Object.entries(config).map(([key, value]) => [key, typeof value === "string" && secrets.includes(value) ? SECRET_PLACEHOLDER : value])),
155
+ call: { op: operation.name, args },
156
+ expectRequest: {
157
+ method: request.method,
158
+ path: `${url.pathname.slice(basePath.length)}${url.search}`,
159
+ headers: Object.fromEntries(request.headers.map(([name, value]) => [name.toLowerCase(), value])),
160
+ ...(requestBody !== undefined && isJson(requestBody) ? { json: JSON.parse(requestBody) } : {}),
161
+ },
162
+ respond: {
163
+ status: last.response.status,
164
+ ...(responseHeaders.length === 0 ? {} : { headers: Object.fromEntries(responseHeaders) }),
165
+ ...(isJson(responseText) ? { json: JSON.parse(responseText) } : {}),
166
+ },
167
+ expect,
168
+ };
169
+ const users = Object.values(config).filter((value) => typeof value === "string" && !secrets.includes(value));
170
+ const text = mask(`${JSON.stringify(scenario, null, 2)}\n`, secrets, users);
171
+ const path = join(io.cwd, scenarioDir, `${id}.json`);
172
+ if (existsSync(path)) throw new Error(`${scenarioDir}/${id}.json already exists`);
173
+ mkdirSync(join(io.cwd, scenarioDir), { recursive: true });
174
+ writeFileSync(path, text);
175
+ io.out(`recorded ${operation.name} (HTTP ${last.response.status}) in ${scenarioDir}/${id}.json${secrets.length === 0 ? "" : `; ${secrets.length} secret value${secrets.length === 1 ? "" : "s"} replaced by "${SECRET_PLACEHOLDER}"`}`);
176
+ return 0;
177
+ } catch (error ) {
178
+ io.err(messageOf(error));
179
+ return 1;
180
+ }
181
+ }
@@ -0,0 +1,156 @@
1
+ // sdkloom serve — a local fake API built from the definition: every operation answers with example data, so other
2
+ // teams and every generated SDK can work against it before the real API exists.
3
+
4
+ import { createServer, } from "node:http";
5
+ import { extract } from "@sdkloom/core";
6
+
7
+
8
+ import { loadProject, } from "../project.ts";
9
+ import { messageOf } from "./build.ts";
10
+
11
+ /** Ask the fake server for a specific status, e.g. a declared error: `x-sdkloom-status: 404`. */
12
+ export const STATUS_HEADER = "x-sdkloom-status";
13
+ export const DEFAULT_PORT = 4010;
14
+
15
+
16
+
17
+
18
+
19
+
20
+ const PRIMITIVE = {
21
+ string: "string",
22
+ secret: "secret",
23
+ datetime: "2026-01-01T00:00:00Z",
24
+ decimal: "1.00",
25
+ int: 1,
26
+ number: 1.5,
27
+ bool: true,
28
+ };
29
+
30
+ /** A small valid example of a type: every field present, the first enum value and union variant, one list item. */
31
+ export function exampleValue(ir , node , stack = []) {
32
+ switch (node.kind) {
33
+ case "primitive":
34
+ return PRIMITIVE[node.name] ?? null;
35
+ case "enum":
36
+ return node.values[0] ?? "";
37
+ case "list": {
38
+ const item = exampleValue(ir, node.item, stack);
39
+ return item === null && node.item.kind === "ref" ? [] : [item];
40
+ }
41
+ case "map":
42
+ return { key: exampleValue(ir, node.value, stack) };
43
+ case "object":
44
+ return Object.fromEntries(
45
+ node.fields.flatMap((item ) => {
46
+ const recursive = item.type.kind === "ref" && stack.includes(item.type.name);
47
+ if (recursive && item.optional) return [];
48
+ return [[item.name, exampleValue(ir, item.type, stack)]];
49
+ }),
50
+ );
51
+ case "union": {
52
+ const first = node.variants[0];
53
+ if (first === undefined) return {};
54
+ return { ...(exampleValue(ir, { kind: "ref", name: first.type }, stack) ), [node.discriminator]: first.tag };
55
+ }
56
+ case "ref": {
57
+ if (stack.includes(node.name)) return null;
58
+ const named = ir.types.find((candidate) => candidate.name === node.name);
59
+ return named === undefined ? null : exampleValue(ir, named.type, [...stack, node.name]);
60
+ }
61
+ }
62
+ }
63
+
64
+ function matches(operation , method , path ) {
65
+ if (operation.method !== method) return false;
66
+ // {name} matches one segment, {+name} one or more.
67
+ const parts = operation.path.split(/(\{[^}]+\})/);
68
+ const pattern = new RegExp(`^${parts.map((part, index) => (index % 2 === 0 ? part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") : part.startsWith("{+") ? ".+" : "[^/]+")).join("")}$`);
69
+ return pattern.test(path);
70
+ }
71
+
72
+ function reply(response , status , body , binary = false) {
73
+ if (body === undefined) {
74
+ response.writeHead(status);
75
+ response.end();
76
+ } else if (binary) {
77
+ response.writeHead(status, { "content-type": "application/octet-stream" });
78
+ response.end(new TextEncoder().encode(String(body)));
79
+ } else {
80
+ response.writeHead(status, { "content-type": "application/json" });
81
+ response.end(JSON.stringify(body));
82
+ }
83
+ }
84
+
85
+ function answer(ir , request , response , log ) {
86
+ const method = request.method ?? "GET";
87
+ const path = (request.url ?? "/").split("?")[0] ?? "/";
88
+ // The most specific template wins: /orders/search before /orders/{id}, whatever the declaration order.
89
+ const operation = ir.operations
90
+ .filter((candidate) => matches(candidate, method, path))
91
+ .sort((a, b) => b.path.replace(/\{[^}]+\}/g, "").length - a.path.replace(/\{[^}]+\}/g, "").length)[0];
92
+ const asked = request.headers[STATUS_HEADER];
93
+ const status = typeof asked === "string" && /^\d{3}$/.test(asked) ? Number(asked) : undefined;
94
+ if (operation === undefined) {
95
+ log(`${method} ${path} → 404 (no operation)`);
96
+ reply(response, 404, { message: `no operation for ${method} ${path}` });
97
+ return;
98
+ }
99
+ if (status !== undefined && (status < 200 || status > 299)) {
100
+ const error = operation.errors.find((candidate) => candidate.status === status);
101
+ log(`${method} ${path} → ${status} (${error?.name ?? "error"}, ${operation.name})`);
102
+ reply(response, status, error?.type === undefined ? { message: `example ${error?.name ?? "error"}` } : exampleValue(ir, error.type));
103
+ return;
104
+ }
105
+ const result = operation.returns;
106
+ const binary = result?.kind === "primitive" && (result.name === "bytes" || result.name === "stream");
107
+ const success = status ?? (result === undefined ? 204 : 200);
108
+ log(`${method} ${path} → ${success} (${operation.name})`);
109
+ reply(response, success, result === undefined ? undefined : binary ? "example" : exampleValue(ir, result), binary);
110
+ }
111
+
112
+ export async function startServer(project , port , log = () => undefined) {
113
+ const { ir } = extract(project.definition);
114
+ const server = createServer((request, response) => {
115
+ request.on("data", () => undefined);
116
+ request.on("end", () => {
117
+ try {
118
+ answer(ir, request, response, log);
119
+ } catch (error ) {
120
+ log(`${request.method ?? "GET"} ${request.url ?? "/"} → 500 (${error instanceof Error ? error.message : String(error)})`);
121
+ reply(response, 500, { message: "the fake server could not build an example" });
122
+ }
123
+ });
124
+ });
125
+ await new Promise ((resolve) => server.listen(port, "127.0.0.1", () => resolve()));
126
+ const address = server.address();
127
+ const actual = typeof address === "object" && address !== null ? address.port : port;
128
+ return {
129
+ url: `http://127.0.0.1:${actual}`,
130
+ close: () =>
131
+ new Promise ((resolve) => {
132
+ server.closeAllConnections();
133
+ server.close(() => resolve());
134
+ }),
135
+ };
136
+ }
137
+
138
+ export async function serveCommand(io , portArg ) {
139
+ const port = portArg === undefined ? DEFAULT_PORT : Number(portArg);
140
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
141
+ io.err(`--port must be a number between 0 and 65535, got ${String(portArg)}`);
142
+ return 1;
143
+ }
144
+ try {
145
+ const project = await loadProject(io.cwd);
146
+ const server = await startServer(project, port, (line) => io.out(line));
147
+ const { ir } = extract(project.definition);
148
+ io.out(`fake ${ir.name} API on ${server.url} (example data; ask for a status with the ${STATUS_HEADER} header)`);
149
+ ir.operations.forEach((operation) => io.out(` ${operation.method.padEnd(6)} ${operation.path} ${operation.name}`));
150
+ io.out(`point an SDK at it with baseUrl ${server.url}; stop with Ctrl-C`);
151
+ return await new Promise (() => undefined);
152
+ } catch (error ) {
153
+ io.err(messageOf(error));
154
+ return 1;
155
+ }
156
+ }
@@ -0,0 +1,57 @@
1
+ // sdkloom spec check — every requirement has a test; every @requirement tag points to a real requirement.
2
+
3
+ import { readFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { checkRequirementLinks, extractRequirementTags, parseRequirements, } from "@sdkloom/spec";
6
+ import { listFiles, plural, readJson, summary, } from "../io.ts";
7
+
8
+ const REQUIREMENTS_DIR = "spec/requirements";
9
+ const KITS_DIR = "kits";
10
+ const CASES_DIR = "conformance/cases";
11
+
12
+ function kitReferences(root ) {
13
+ return listFiles(join(root, KITS_DIR)).flatMap((path) => {
14
+ const area = path.split("/")[1];
15
+ if (area !== "src" && area !== "tests") return [];
16
+ const file = `${KITS_DIR}/${path}`;
17
+ const kind = area === "src" ? "implementation" : "test";
18
+ const kit = path.split("/")[0] ?? "";
19
+ return extractRequirementTags(readFileSync(join(root, file), "utf8"), file).map((tag) => ({ ...tag, kind, kit }));
20
+ });
21
+ }
22
+
23
+ function caseReferences(root ) {
24
+ return listFiles(join(root, CASES_DIR))
25
+ .filter((path) => path.endsWith(".json"))
26
+ .flatMap((path) => {
27
+ const file = `${CASES_DIR}/${path}`;
28
+ const result = readJson(join(root, file), file);
29
+ const value = result.ok ? result.value : undefined;
30
+ const requirements = typeof value === "object" && value !== null ? (value )["requirements"] : undefined;
31
+ if (!Array.isArray(requirements)) return [];
32
+ return requirements
33
+ .filter((id) => typeof id === "string")
34
+ .map((id) => ({ id, file, line: 1, kind: "test" }));
35
+ });
36
+ }
37
+
38
+ export function specCheck(io ) {
39
+ const root = io.cwd;
40
+ const parsed = listFiles(join(root, REQUIREMENTS_DIR))
41
+ .filter((path) => path.endsWith(".md"))
42
+ .map((path) => {
43
+ const file = `${REQUIREMENTS_DIR}/${path}`;
44
+ return parseRequirements(readFileSync(join(root, file), "utf8"), file);
45
+ });
46
+ const requirements = parsed.flatMap((result) => result.requirements);
47
+
48
+ const lines = [
49
+ ...parsed.flatMap((result) => result.errors).map((error) => `${error.file}:${error.line} PARSE ${error.message}`),
50
+ ...checkRequirementLinks(requirements, [...kitReferences(root), ...caseReferences(root)]).map(
51
+ (issue) => `${issue.file}:${issue.line} ${issue.code} ${issue.message}`,
52
+ ),
53
+ ];
54
+ lines.forEach((line) => io.out(line));
55
+ io.out(summary(plural(requirements.length, "requirement"), lines.length));
56
+ return lines.length === 0 ? 0 : 1;
57
+ }