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.
- package/LICENSE +202 -0
- package/README.md +239 -2
- package/kits/allowed-sources.json +24 -0
- package/kits/csharp/kit.json +6 -0
- package/kits/csharp/src/Runtime/Client.cs +295 -0
- package/kits/csharp/src/Runtime/Context.cs +216 -0
- package/kits/csharp/src/Runtime/Errors.cs +121 -0
- package/kits/csharp/src/Runtime/Http.cs +218 -0
- package/kits/csharp/src/Runtime/Json.cs +650 -0
- package/kits/csharp/src/Runtime/Lang.cs +212 -0
- package/kits/csharp/src/Runtime/Models.cs +206 -0
- package/kits/csharp/src/Runtime/Multipart.cs +108 -0
- package/kits/csharp/src/Runtime/Pagination.cs +122 -0
- package/kits/csharp/src/Runtime/Sse.cs +197 -0
- package/kits/csharp/src/Runtime/Testing.cs +375 -0
- package/kits/csharp/src/Runtime/Transport.cs +212 -0
- package/kits/csharp/src/Runtime/Wait.cs +57 -0
- package/kits/csharp/src/Runtime/Webhooks.cs +148 -0
- package/kits/csharp/tests/ClientTests.cs +128 -0
- package/kits/csharp/tests/HttpTests.cs +44 -0
- package/kits/csharp/tests/JsonTests.cs +132 -0
- package/kits/csharp/tests/LangTests.cs +57 -0
- package/kits/csharp/tests/MultipartTests.cs +31 -0
- package/kits/csharp/tests/PaginationTests.cs +93 -0
- package/kits/csharp/tests/SseTests.cs +122 -0
- package/kits/csharp/tests/TestRunner.cs +93 -0
- package/kits/csharp/tests/TestingTests.cs +80 -0
- package/kits/csharp/tests/TransportTests.cs +145 -0
- package/kits/csharp/tests/WaitTests.cs +39 -0
- package/kits/csharp/tests/WebhooksTests.cs +46 -0
- package/kits/csharp/versions.json +12 -0
- package/kits/go/kit.json +6 -0
- package/kits/go/src/sdkruntime/client.go +322 -0
- package/kits/go/src/sdkruntime/context.go +207 -0
- package/kits/go/src/sdkruntime/errors.go +74 -0
- package/kits/go/src/sdkruntime/http.go +261 -0
- package/kits/go/src/sdkruntime/json.go +527 -0
- package/kits/go/src/sdkruntime/lang.go +462 -0
- package/kits/go/src/sdkruntime/multipart.go +75 -0
- package/kits/go/src/sdkruntime/pagination.go +150 -0
- package/kits/go/src/sdkruntime/sse.go +267 -0
- package/kits/go/src/sdkruntime/testing.go +343 -0
- package/kits/go/src/sdkruntime/transport.go +168 -0
- package/kits/go/src/sdkruntime/wait.go +49 -0
- package/kits/go/src/sdkruntime/webhooks.go +129 -0
- package/kits/go/tests/client_test.go +185 -0
- package/kits/go/tests/http_test.go +78 -0
- package/kits/go/tests/json_test.go +127 -0
- package/kits/go/tests/lang_test.go +98 -0
- package/kits/go/tests/multipart_test.go +29 -0
- package/kits/go/tests/pagination_test.go +69 -0
- package/kits/go/tests/sse_test.go +129 -0
- package/kits/go/tests/testing_test.go +121 -0
- package/kits/go/tests/transport_test.go +133 -0
- package/kits/go/tests/wait_test.go +46 -0
- package/kits/go/tests/webhooks_test.go +62 -0
- package/kits/go/versions.json +12 -0
- package/kits/java/kit.json +6 -0
- package/kits/java/src/dev/sdkloom/runtime/ApiException.java +63 -0
- package/kits/java/src/dev/sdkloom/runtime/ArgumentException.java +24 -0
- package/kits/java/src/dev/sdkloom/runtime/Assert.java +72 -0
- package/kits/java/src/dev/sdkloom/runtime/ClientRuntime.java +220 -0
- package/kits/java/src/dev/sdkloom/runtime/Clock.java +39 -0
- package/kits/java/src/dev/sdkloom/runtime/Context.java +79 -0
- package/kits/java/src/dev/sdkloom/runtime/Decode.java +200 -0
- package/kits/java/src/dev/sdkloom/runtime/DecodeException.java +26 -0
- package/kits/java/src/dev/sdkloom/runtime/Decoder.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/Emitter.java +56 -0
- package/kits/java/src/dev/sdkloom/runtime/ErrorFactory.java +18 -0
- package/kits/java/src/dev/sdkloom/runtime/EventListener.java +20 -0
- package/kits/java/src/dev/sdkloom/runtime/EventStream.java +232 -0
- package/kits/java/src/dev/sdkloom/runtime/FakeClock.java +37 -0
- package/kits/java/src/dev/sdkloom/runtime/Headers.java +42 -0
- package/kits/java/src/dev/sdkloom/runtime/HttpRequest.java +88 -0
- package/kits/java/src/dev/sdkloom/runtime/HttpResponse.java +69 -0
- package/kits/java/src/dev/sdkloom/runtime/JdkTransport.java +97 -0
- package/kits/java/src/dev/sdkloom/runtime/Js.java +230 -0
- package/kits/java/src/dev/sdkloom/runtime/Json.java +281 -0
- package/kits/java/src/dev/sdkloom/runtime/JsonValue.java +15 -0
- package/kits/java/src/dev/sdkloom/runtime/Links.java +62 -0
- package/kits/java/src/dev/sdkloom/runtime/Middleware.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/MiddlewareEntry.java +43 -0
- package/kits/java/src/dev/sdkloom/runtime/MockRoute.java +111 -0
- package/kits/java/src/dev/sdkloom/runtime/MockTransport.java +62 -0
- package/kits/java/src/dev/sdkloom/runtime/MultipartForm.java +111 -0
- package/kits/java/src/dev/sdkloom/runtime/Next.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationInfo.java +35 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationMock.java +105 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationSpec.java +125 -0
- package/kits/java/src/dev/sdkloom/runtime/Pages.java +55 -0
- package/kits/java/src/dev/sdkloom/runtime/Pipeline.java +29 -0
- package/kits/java/src/dev/sdkloom/runtime/RawResult.java +31 -0
- package/kits/java/src/dev/sdkloom/runtime/RecordedEvent.java +36 -0
- package/kits/java/src/dev/sdkloom/runtime/SdkInfo.java +38 -0
- package/kits/java/src/dev/sdkloom/runtime/SendOptions.java +34 -0
- package/kits/java/src/dev/sdkloom/runtime/ServerSentEvent.java +58 -0
- package/kits/java/src/dev/sdkloom/runtime/State.java +58 -0
- package/kits/java/src/dev/sdkloom/runtime/Test.java +21 -0
- package/kits/java/src/dev/sdkloom/runtime/TestRunner.java +63 -0
- package/kits/java/src/dev/sdkloom/runtime/Transport.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/TransportException.java +30 -0
- package/kits/java/src/dev/sdkloom/runtime/UrlConnectionTransport.java +195 -0
- package/kits/java/src/dev/sdkloom/runtime/Urls.java +116 -0
- package/kits/java/src/dev/sdkloom/runtime/Waits.java +53 -0
- package/kits/java/src/dev/sdkloom/runtime/WebhookSignatureException.java +24 -0
- package/kits/java/src/dev/sdkloom/runtime/Webhooks.java +146 -0
- package/kits/java/tests/dev/sdkloom/runtime/ClientTest.java +266 -0
- package/kits/java/tests/dev/sdkloom/runtime/EventStreamTest.java +131 -0
- package/kits/java/tests/dev/sdkloom/runtime/HttpTest.java +95 -0
- package/kits/java/tests/dev/sdkloom/runtime/JdkTransportTest.java +12 -0
- package/kits/java/tests/dev/sdkloom/runtime/JsTest.java +102 -0
- package/kits/java/tests/dev/sdkloom/runtime/JsonTest.java +87 -0
- package/kits/java/tests/dev/sdkloom/runtime/LinksTest.java +22 -0
- package/kits/java/tests/dev/sdkloom/runtime/MultipartFormTest.java +30 -0
- package/kits/java/tests/dev/sdkloom/runtime/PagesTest.java +75 -0
- package/kits/java/tests/dev/sdkloom/runtime/TestData.java +53 -0
- package/kits/java/tests/dev/sdkloom/runtime/TestingTest.java +156 -0
- package/kits/java/tests/dev/sdkloom/runtime/TransportContract.java +201 -0
- package/kits/java/tests/dev/sdkloom/runtime/UrlConnectionTransportTest.java +49 -0
- package/kits/java/tests/dev/sdkloom/runtime/WaitsTest.java +43 -0
- package/kits/java/tests/dev/sdkloom/runtime/WebhooksTest.java +45 -0
- package/kits/java/versions.json +41 -0
- package/kits/python/kit.json +6 -0
- package/kits/python/src/sdkloom_runtime/__init__.py +1 -0
- package/kits/python/src/sdkloom_runtime/client.py +232 -0
- package/kits/python/src/sdkloom_runtime/compat.py +195 -0
- package/kits/python/src/sdkloom_runtime/context.py +134 -0
- package/kits/python/src/sdkloom_runtime/errors.py +65 -0
- package/kits/python/src/sdkloom_runtime/http.py +192 -0
- package/kits/python/src/sdkloom_runtime/lang.py +207 -0
- package/kits/python/src/sdkloom_runtime/models.py +221 -0
- package/kits/python/src/sdkloom_runtime/multipart.py +69 -0
- package/kits/python/src/sdkloom_runtime/pagination.py +61 -0
- package/kits/python/src/sdkloom_runtime/pipeline.py +39 -0
- package/kits/python/src/sdkloom_runtime/sse.py +121 -0
- package/kits/python/src/sdkloom_runtime/testing.py +224 -0
- package/kits/python/src/sdkloom_runtime/transport.py +120 -0
- package/kits/python/src/sdkloom_runtime/wait.py +44 -0
- package/kits/python/src/sdkloom_runtime/webhooks.py +84 -0
- package/kits/python/tests/support.py +28 -0
- package/kits/python/tests/test_client.py +275 -0
- package/kits/python/tests/test_compat.py +87 -0
- package/kits/python/tests/test_http.py +94 -0
- package/kits/python/tests/test_lang.py +104 -0
- package/kits/python/tests/test_models.py +110 -0
- package/kits/python/tests/test_multipart.py +37 -0
- package/kits/python/tests/test_pagination.py +70 -0
- package/kits/python/tests/test_sse.py +61 -0
- package/kits/python/tests/test_testing.py +130 -0
- package/kits/python/tests/test_transport.py +124 -0
- package/kits/python/tests/test_wait.py +46 -0
- package/kits/python/tests/test_webhooks.py +57 -0
- package/kits/python/versions.json +33 -0
- package/kits/rust/kit.json +6 -0
- package/kits/rust/src/runtime/client.rs +212 -0
- package/kits/rust/src/runtime/context.rs +182 -0
- package/kits/rust/src/runtime/crypto.rs +84 -0
- package/kits/rust/src/runtime/errors.rs +147 -0
- package/kits/rust/src/runtime/http.rs +248 -0
- package/kits/rust/src/runtime/json.rs +424 -0
- package/kits/rust/src/runtime/lang.rs +296 -0
- package/kits/rust/src/runtime/mod.rs +30 -0
- package/kits/rust/src/runtime/models.rs +266 -0
- package/kits/rust/src/runtime/multipart.rs +81 -0
- package/kits/rust/src/runtime/pagination.rs +117 -0
- package/kits/rust/src/runtime/sse.rs +195 -0
- package/kits/rust/src/runtime/testing.rs +308 -0
- package/kits/rust/src/runtime/transport.rs +324 -0
- package/kits/rust/src/runtime/wait.rs +29 -0
- package/kits/rust/src/runtime/webhooks.rs +142 -0
- package/kits/rust/tests/client.rs +152 -0
- package/kits/rust/tests/http.rs +44 -0
- package/kits/rust/tests/json.rs +82 -0
- package/kits/rust/tests/lang.rs +74 -0
- package/kits/rust/tests/multipart.rs +21 -0
- package/kits/rust/tests/pagination.rs +61 -0
- package/kits/rust/tests/sse.rs +77 -0
- package/kits/rust/tests/testing.rs +90 -0
- package/kits/rust/tests/transport.rs +218 -0
- package/kits/rust/tests/wait.rs +32 -0
- package/kits/rust/tests/webhooks.rs +73 -0
- package/kits/rust/versions.json +6 -0
- package/kits/typescript/kit.json +6 -0
- package/kits/typescript/src/client.ts +223 -0
- package/kits/typescript/src/context.ts +108 -0
- package/kits/typescript/src/errors.ts +63 -0
- package/kits/typescript/src/helpers.ts +49 -0
- package/kits/typescript/src/http.ts +192 -0
- package/kits/typescript/src/models.ts +139 -0
- package/kits/typescript/src/multipart.ts +66 -0
- package/kits/typescript/src/pagination.ts +54 -0
- package/kits/typescript/src/pipeline.ts +25 -0
- package/kits/typescript/src/sse.ts +102 -0
- package/kits/typescript/src/testing.ts +217 -0
- package/kits/typescript/src/transport.ts +101 -0
- package/kits/typescript/src/wait.ts +36 -0
- package/kits/typescript/src/webhooks.ts +168 -0
- package/kits/typescript/tests/client.test.ts +269 -0
- package/kits/typescript/tests/helpers.test.ts +27 -0
- package/kits/typescript/tests/http.test.ts +80 -0
- package/kits/typescript/tests/models.test.ts +71 -0
- package/kits/typescript/tests/multipart.test.ts +28 -0
- package/kits/typescript/tests/pagination.test.ts +76 -0
- package/kits/typescript/tests/sse.test.ts +82 -0
- package/kits/typescript/tests/testing.test.ts +103 -0
- package/kits/typescript/tests/transport.test.ts +127 -0
- package/kits/typescript/tests/wait.test.ts +31 -0
- package/kits/typescript/tests/webhooks.test.ts +53 -0
- package/kits/typescript/versions.json +15 -0
- package/package.json +37 -4
- package/packages/cli/recipes/apiKeyHeader.ts +16 -0
- package/packages/cli/recipes/apiVersionHeader.ts +16 -0
- package/packages/cli/recipes/basic.ts +13 -0
- package/packages/cli/recipes/bearer.ts +10 -0
- package/packages/cli/recipes/hmacSign.ts +23 -0
- package/packages/cli/recipes/idempotencyKey.ts +19 -0
- package/packages/cli/recipes/oauthClientCredentials.ts +50 -0
- package/packages/cli/recipes/retry.ts +42 -0
- package/packages/cli/recipes/timing.ts +12 -0
- package/packages/cli/recipes/userAgent.ts +8 -0
- package/packages/cli/src/build.js +93 -0
- package/packages/cli/src/commands/build.js +31 -0
- package/packages/cli/src/commands/conformance-check.js +50 -0
- package/packages/cli/src/commands/contract.js +181 -0
- package/packages/cli/src/commands/diff.js +113 -0
- package/packages/cli/src/commands/doctor.js +43 -0
- package/packages/cli/src/commands/import-openapi.js +42 -0
- package/packages/cli/src/commands/init.js +27 -0
- package/packages/cli/src/commands/kit-check.js +145 -0
- package/packages/cli/src/commands/publish.js +81 -0
- package/packages/cli/src/commands/recipe.js +49 -0
- package/packages/cli/src/commands/record.js +181 -0
- package/packages/cli/src/commands/serve.js +156 -0
- package/packages/cli/src/commands/spec-check.js +57 -0
- package/packages/cli/src/commands/test.js +177 -0
- package/packages/cli/src/commands/variants.js +32 -0
- package/packages/cli/src/commands/verify.js +57 -0
- package/packages/cli/src/commands/version.js +63 -0
- package/packages/cli/src/containers.js +82 -0
- package/packages/cli/src/coverage.js +72 -0
- package/packages/cli/src/git.js +25 -0
- package/packages/cli/src/io.js +50 -0
- package/packages/cli/src/java/ScenarioHarness.java +297 -0
- package/packages/cli/src/java/SchemaRoundTrip.java +63 -0
- package/packages/cli/src/java.js +70 -0
- package/packages/cli/src/js/harness.mjs +120 -0
- package/packages/cli/src/kits.js +103 -0
- package/packages/cli/src/languages/csharp.js +274 -0
- package/packages/cli/src/languages/go.js +185 -0
- package/packages/cli/src/languages/index.js +18 -0
- package/packages/cli/src/languages/java.js +187 -0
- package/packages/cli/src/languages/python.js +120 -0
- package/packages/cli/src/languages/rust.js +189 -0
- package/packages/cli/src/languages/types.js +93 -0
- package/packages/cli/src/languages/typescript.js +112 -0
- package/packages/cli/src/main.js +13 -0
- package/packages/cli/src/packaging.js +39 -0
- package/packages/cli/src/portability.js +45 -0
- package/packages/cli/src/profiles.js +55 -0
- package/packages/cli/src/project.js +56 -0
- package/packages/cli/src/python/scenario_harness.py +162 -0
- package/packages/cli/src/python/schema_roundtrip.py +42 -0
- package/packages/cli/src/registries.js +214 -0
- package/packages/cli/src/resolve-core.js +39 -0
- package/packages/cli/src/run.js +133 -0
- package/packages/cli/src/runtimes.js +61 -0
- package/packages/cli/src/scenarios-java.js +82 -0
- package/packages/cli/src/scenarios-javascript.js +54 -0
- package/packages/cli/src/scenarios-python.js +90 -0
- package/packages/cli/src/scenarios.js +183 -0
- package/packages/cli/src/schema.js +84 -0
- package/packages/cli/src/templates.js +85 -0
- package/packages/cli/src/toolchains.js +68 -0
- package/packages/cli/src/transpiled-tests.js +92 -0
- package/packages/codegen/src/canonical-json.js +31 -0
- package/packages/codegen/src/capabilities.js +50 -0
- package/packages/codegen/src/code-writer.js +54 -0
- package/packages/codegen/src/file-tree.js +25 -0
- package/packages/codegen/src/hash.js +6 -0
- package/packages/codegen/src/index.js +16 -0
- package/packages/codegen/src/lock.js +106 -0
- package/packages/conformance/src/case.js +143 -0
- package/packages/conformance/src/checks.js +40 -0
- package/packages/conformance/src/index.js +3 -0
- package/packages/conformance/src/matrix.js +48 -0
- package/packages/conformance/src/suite.js +48 -0
- package/packages/differ/src/diff.js +500 -0
- package/packages/differ/src/index.js +3 -0
- package/packages/differ/src/notes.js +112 -0
- package/packages/differ/src/support.js +34 -0
- package/packages/gen-csharp/src/emit-client.js +397 -0
- package/packages/gen-csharp/src/emit-harness.js +333 -0
- package/packages/gen-csharp/src/emit-mock.js +111 -0
- package/packages/gen-csharp/src/emit-models.js +119 -0
- package/packages/gen-csharp/src/emit-webhooks.js +57 -0
- package/packages/gen-csharp/src/generate.js +245 -0
- package/packages/gen-csharp/src/index.js +5 -0
- package/packages/gen-csharp/src/names.js +284 -0
- package/packages/gen-go/src/emit-client.js +405 -0
- package/packages/gen-go/src/emit-harness.js +294 -0
- package/packages/gen-go/src/emit-mock.js +112 -0
- package/packages/gen-go/src/emit-models.js +146 -0
- package/packages/gen-go/src/emit-webhooks.js +58 -0
- package/packages/gen-go/src/generate.js +205 -0
- package/packages/gen-go/src/index.js +5 -0
- package/packages/gen-go/src/names.js +197 -0
- package/packages/gen-java/src/emit-client.js +441 -0
- package/packages/gen-java/src/emit-models.js +342 -0
- package/packages/gen-java/src/emit-testing.js +123 -0
- package/packages/gen-java/src/emit-webhooks.js +70 -0
- package/packages/gen-java/src/generate.js +244 -0
- package/packages/gen-java/src/index.js +4 -0
- package/packages/gen-java/src/names.js +197 -0
- package/packages/gen-python/src/emit-client.js +272 -0
- package/packages/gen-python/src/emit-models.js +139 -0
- package/packages/gen-python/src/emit-testing.js +93 -0
- package/packages/gen-python/src/emit-webhooks.js +48 -0
- package/packages/gen-python/src/generate.js +237 -0
- package/packages/gen-python/src/index.js +2 -0
- package/packages/gen-python/src/names.js +161 -0
- package/packages/gen-python/src/style.js +67 -0
- package/packages/gen-rust/src/emit-client.js +379 -0
- package/packages/gen-rust/src/emit-harness.js +278 -0
- package/packages/gen-rust/src/emit-mock.js +121 -0
- package/packages/gen-rust/src/emit-models.js +117 -0
- package/packages/gen-rust/src/emit-webhooks.js +58 -0
- package/packages/gen-rust/src/generate.js +243 -0
- package/packages/gen-rust/src/index.js +5 -0
- package/packages/gen-rust/src/names.js +223 -0
- package/packages/gen-typescript/src/emit-client.js +434 -0
- package/packages/gen-typescript/src/emit-models.js +93 -0
- package/packages/gen-typescript/src/emit-package.js +90 -0
- package/packages/gen-typescript/src/emit-testing.js +138 -0
- package/packages/gen-typescript/src/emit-webhooks.js +52 -0
- package/packages/gen-typescript/src/generate.js +70 -0
- package/packages/gen-typescript/src/index.js +3 -0
- package/packages/gen-typescript/src/naming.js +64 -0
- package/packages/gen-typescript/src/runtime.js +81 -0
- package/packages/gen-typescript/src/types.js +136 -0
- package/packages/ir/src/api-surface.js +22 -0
- package/packages/ir/src/checks.js +52 -0
- package/packages/ir/src/index.js +32 -0
- package/packages/ir/src/ir.js +214 -0
- package/packages/ir/src/pages.js +18 -0
- package/packages/ir/src/validate-ir.js +462 -0
- package/packages/ir/src/validate-types.js +140 -0
- package/packages/kit/src/block-parser.js +196 -0
- package/packages/kit/src/index.js +15 -0
- package/packages/kit/src/kit-check.js +203 -0
- package/packages/kit/src/sources.js +53 -0
- package/packages/kit/src/version-policy.js +133 -0
- package/packages/kit/src/version-range.js +132 -0
- package/packages/openapi/src/import.js +292 -0
- package/packages/openapi/src/index.js +1 -0
- package/packages/openapi/src/names.js +50 -0
- package/packages/openapi/src/schemas.js +264 -0
- package/packages/packager/src/archive.js +106 -0
- package/packages/packager/src/crate.js +39 -0
- package/packages/packager/src/gomodule.js +11 -0
- package/packages/packager/src/index.js +9 -0
- package/packages/packager/src/maven.js +85 -0
- package/packages/packager/src/metadata.js +34 -0
- package/packages/packager/src/npm.js +71 -0
- package/packages/packager/src/nuget.js +78 -0
- package/packages/packager/src/sbom.js +56 -0
- package/packages/packager/src/wheel.js +62 -0
- package/packages/spec/src/index.js +11 -0
- package/packages/spec/src/requirements.js +139 -0
- package/packages/transpile/src/ast.js +51 -0
- package/packages/transpile/src/check.js +669 -0
- package/packages/transpile/src/emit-csharp.js +469 -0
- package/packages/transpile/src/emit-go.js +529 -0
- package/packages/transpile/src/emit-java.js +360 -0
- package/packages/transpile/src/emit-python.js +320 -0
- package/packages/transpile/src/emit-rust.js +499 -0
- package/packages/transpile/src/errors.js +15 -0
- package/packages/transpile/src/index.js +13 -0
- package/packages/transpile/src/lexer.js +161 -0
- package/packages/transpile/src/parser.js +543 -0
- package/packages/transpile/src/tests/ast.js +46 -0
- package/packages/transpile/src/tests/parse.js +376 -0
- package/packages/transpile/src/tests/translate.js +849 -0
- package/packages/transpile/src/transpile.js +57 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// The runtimes a target is tested on: one per version its kit lists in versions.json ("python@3.8", "python@3.15"),
|
|
2
|
+
// each with the interpreter, JDK or Node.js found on this machine, or none.
|
|
3
|
+
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { containerCommand, containersAvailable, ensureImage } from "./containers.ts";
|
|
6
|
+
|
|
7
|
+
import { languageModule } from "./languages/index.ts";
|
|
8
|
+
|
|
9
|
+
import { resolveToolchain, toolchainVariable } from "./toolchains.ts";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/** One runtime per version the target's kit line tests; target is "java" or "java-jdk8". */
|
|
31
|
+
export function runtimesFor(language , target , profile , options = {}) {
|
|
32
|
+
const spec = languageModule(language).toolchain;
|
|
33
|
+
if (profile.test.length === 0) return [{ language, target, label: target, command: [spec.fallback], hint: "" }];
|
|
34
|
+
return profile.test.map((version) => {
|
|
35
|
+
const label = `${target}@${version}`;
|
|
36
|
+
const found = resolveToolchain(language, version);
|
|
37
|
+
if (found !== undefined) return { language, target, label, command: [spec.executable(found.command)], hint: "" };
|
|
38
|
+
const hint = `install it, set ${toolchainVariable(spec, version)}, or run with --container`;
|
|
39
|
+
if (options.container === undefined) return { language, target, label, command: undefined, hint };
|
|
40
|
+
if (!containersAvailable()) return { language, target, label, command: undefined, hint: `${hint} (no container engine answered)` };
|
|
41
|
+
const image = spec.image(version);
|
|
42
|
+
if (options.container.pull !== false && !ensureImage(image)) return { language, target, label, command: undefined, hint: `${hint} (could not pull ${image})` };
|
|
43
|
+
return { language, target, label, command: containerCommand(language, version, options.container.projectRoot), hint: "", image };
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/** Runs a runtime's command (its argv prefix) with more arguments. */
|
|
50
|
+
export function spawnCommand(
|
|
51
|
+
command ,
|
|
52
|
+
args ,
|
|
53
|
+
options = {},
|
|
54
|
+
) {
|
|
55
|
+
return spawnSync(command[0] ?? "", [...command.slice(1), ...args], { encoding: "utf8", ...options });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The runtimes that are installed; the others show as not run. */
|
|
59
|
+
export function installed(runtimes ) {
|
|
60
|
+
return runtimes.flatMap((runtime) => (runtime.command === undefined ? [] : [{ ...runtime, command: runtime.command }]));
|
|
61
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Runs scenarios against the generated Java SDK: a JDK-only harness reaches the SDK through reflection.
|
|
2
|
+
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { basename, join } from "node:path";
|
|
5
|
+
import { camel, logicClass, paramsClass, webhookMethod, webhooksClass } from "@sdkloom/gen-java";
|
|
6
|
+
|
|
7
|
+
import { compileJava, runJava, } from "./java.ts";
|
|
8
|
+
import { answersOf, } from "./scenarios.ts";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const HARNESS = join(import.meta.dirname, "java", "ScenarioHarness.java");
|
|
12
|
+
const ROUND_TRIP = join(import.meta.dirname, "java", "SchemaRoundTrip.java");
|
|
13
|
+
const SCENARIO_TIMEOUT_MS = 5_000;
|
|
14
|
+
|
|
15
|
+
/** The harness is compiled once per run, then started with every JDK under test. */
|
|
16
|
+
function compileOnce(source , classes , sdkClasses , release ) {
|
|
17
|
+
const compiledClass = join(classes, basename(source).replace(/\.java$/, ".class"));
|
|
18
|
+
return existsSync(compiledClass) ? { ok: true, output: "" } : compileJava([source], classes, [sdkClasses], release);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function planCase(scenario , operation , pkg ) {
|
|
22
|
+
const args = scenario.call.args;
|
|
23
|
+
const named = operation.params.filter((param) => param.in !== "path");
|
|
24
|
+
const given = named.filter((param) => param.name in args);
|
|
25
|
+
|
|
26
|
+
const needsParams = given.length > 0 || named.some((param) => !param.optional);
|
|
27
|
+
return {
|
|
28
|
+
id: scenario.id,
|
|
29
|
+
timeoutMs: SCENARIO_TIMEOUT_MS,
|
|
30
|
+
config: Object.fromEntries(Object.entries(scenario.config ?? {}).map(([key, value]) => [camel(key), value])),
|
|
31
|
+
positional: operation.params.filter((param) => param.in === "path").map((param) => args[param.name]),
|
|
32
|
+
...(operation.body === undefined ? {} : { body: args["body"] }),
|
|
33
|
+
...(needsParams ? { params: { class: `${pkg}.${paramsClass(operation)}`, values: Object.fromEntries(given.map((param) => [camel(param.name), args[param.name]])) } } : {}),
|
|
34
|
+
method: scenario.call.all === true ? `${camel(operation.name)}All` : scenario.call.wait === true ? `${camel(operation.name)}AndWait` : camel(operation.name),
|
|
35
|
+
all: scenario.call.all ?? false,
|
|
36
|
+
events: operation.events !== undefined,
|
|
37
|
+
answers: answersOf(scenario),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Compiles the harness against the compiled SDK classes and runs every scenario in one JVM. */
|
|
42
|
+
export function observeJava(java , sdkClasses , harnessClasses , pkg , ir , scenarios , release ) {
|
|
43
|
+
const observations = new Map ();
|
|
44
|
+
const runnable = scenarios.flatMap((scenario) => {
|
|
45
|
+
const hook = scenario.webhook;
|
|
46
|
+
// A webhook case calls the SDK's <Name>Webhooks.verify<Hook> instead of an operation.
|
|
47
|
+
if (hook !== undefined) return [{ id: scenario.id, webhook: { ...hook, class: `${pkg}.${webhooksClass(ir)}`, verify: webhookMethod(hook.name) } }];
|
|
48
|
+
// A logic case calls <Name>Logic.<name> with the inputs in declared order.
|
|
49
|
+
const logic = scenario.logic;
|
|
50
|
+
if (logic !== undefined) {
|
|
51
|
+
const inputs = ir.logic?.find((candidate) => candidate.name === logic.name)?.input ?? [];
|
|
52
|
+
return [{ id: scenario.id, logic: { class: `${pkg}.${logicClass(ir)}`, method: logic.name, args: inputs.map((field) => logic.args[field.name] ?? null) } }];
|
|
53
|
+
}
|
|
54
|
+
const operation = ir.operations.find((candidate) => candidate.name === scenario.call.op);
|
|
55
|
+
if (operation === undefined) {
|
|
56
|
+
observations.set(scenario.id, { outcome: { ok: false, error: "UnknownOperation", message: scenario.call.op } });
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
return [planCase(scenario, operation, pkg)];
|
|
60
|
+
});
|
|
61
|
+
if (runnable.length === 0) return observations;
|
|
62
|
+
|
|
63
|
+
const compiled = compileOnce(HARNESS, harnessClasses, sdkClasses, release);
|
|
64
|
+
if (!compiled.ok) throw new Error(`could not compile the Java scenario harness:\n${compiled.output}`);
|
|
65
|
+
const plan = JSON.stringify({ client: `${pkg}.${ir.name}Client`, scenarios: runnable });
|
|
66
|
+
const run = runJava([sdkClasses, harnessClasses], "ScenarioHarness", [`${pkg}.runtime.Json`], plan, java);
|
|
67
|
+
if (!run.ok) throw new Error(`could not run the Java scenarios:\n${run.output}`);
|
|
68
|
+
const reported = JSON.parse(run.stdout) ;
|
|
69
|
+
reported.forEach(({ id, ...observation }) => observations.set(id, observation));
|
|
70
|
+
return observations;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Decodes and re-encodes every schema sample with the compiled Java SDK. */
|
|
74
|
+
export function roundTripJava(java , sdkClasses , toolClasses , pkg , samples , release ) {
|
|
75
|
+
const compiled = compileOnce(ROUND_TRIP, toolClasses, sdkClasses, release);
|
|
76
|
+
if (!compiled.ok) throw new Error(`could not compile the Java schema round-trip:\n${compiled.output}`);
|
|
77
|
+
const plan = JSON.stringify({ package: pkg, cases: samples.map(({ id, type, union, value }) => ({ id, type, union, value })) });
|
|
78
|
+
const run = runJava([sdkClasses, toolClasses], "SchemaRoundTrip", [`${pkg}.runtime.Json`], plan, java);
|
|
79
|
+
if (!run.ok) throw new Error(`could not run the Java schema round-trip:\n${run.output}`);
|
|
80
|
+
const reported = JSON.parse(run.stdout) ;
|
|
81
|
+
return new Map(reported.map((entry) => [entry.id, entry.outcome]));
|
|
82
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Runs scenarios against the generated TypeScript SDK as the JavaScript npm ships, on every Node.js version under test.
|
|
2
|
+
|
|
3
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
|
|
6
|
+
import { toJavaScript } from "@sdkloom/packager";
|
|
7
|
+
|
|
8
|
+
import { spawnCommand } from "./runtimes.ts";
|
|
9
|
+
import { answersOf, } from "./scenarios.ts";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const HARNESS = join(import.meta.dirname, "js", "harness.mjs");
|
|
13
|
+
const RUN_TIMEOUT_MS = 120_000;
|
|
14
|
+
const SOURCE_DIR = "src/";
|
|
15
|
+
|
|
16
|
+
/** Writes the TypeScript SDK's src/ as plain ES modules into dir; returns dir. */
|
|
17
|
+
export function writeJavaScript(target , dir ) {
|
|
18
|
+
const sources = new Map([...target.files].filter(([path]) => path.startsWith(SOURCE_DIR)).map(([path, text]) => [path.slice(SOURCE_DIR.length), text]));
|
|
19
|
+
for (const [path, text] of toJavaScript(sources)) {
|
|
20
|
+
mkdirSync(dirname(join(dir, path)), { recursive: true });
|
|
21
|
+
writeFileSync(join(dir, path), text);
|
|
22
|
+
}
|
|
23
|
+
writeFileSync(join(dir, "package.json"), `${JSON.stringify({ type: "module" })}\n`);
|
|
24
|
+
return dir;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function runHarness(node , plan , what ) {
|
|
28
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => key !== "NODE_TEST_CONTEXT"));
|
|
29
|
+
const result = spawnCommand(node, [HARNESS], { input: JSON.stringify(plan), env, timeout: RUN_TIMEOUT_MS });
|
|
30
|
+
if (result.error !== undefined || result.status !== 0) {
|
|
31
|
+
const reason = result.error?.message ?? result.stderr.trim().split("\n").at(-1) ?? `exit ${String(result.status)}`;
|
|
32
|
+
throw new Error(`could not run the JavaScript ${what} with ${node.join(" ")}: ${reason}`);
|
|
33
|
+
}
|
|
34
|
+
return result.stdout;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function observeJavaScript(node , sdk , ir , scenarios ) {
|
|
38
|
+
const cases = scenarios.map((scenario) => {
|
|
39
|
+
const operation = ir.operations.find((candidate) => candidate.name === scenario.call.op);
|
|
40
|
+
const hasArgs = operation !== undefined && (operation.params.length > 0 || operation.body !== undefined);
|
|
41
|
+
const hook = scenario.webhook;
|
|
42
|
+
const verify = hook === undefined ? undefined : `verify${hook.name.charAt(0).toUpperCase()}${hook.name.slice(1)}Webhook`;
|
|
43
|
+
return { id: scenario.id, op: scenario.call.op, args: scenario.call.args, all: scenario.call.all ?? false, wait: scenario.call.wait ?? false, events: operation?.events !== undefined, multipart: operation?.body?.kind === "primitive" && operation.body.name === "multipart", hasArgs, config: scenario.config ?? {}, answers: answersOf(scenario), ...(hook === undefined ? {} : { webhook: { ...hook, verify } }), ...(scenario.logic === undefined ? {} : { logic: scenario.logic }) };
|
|
44
|
+
});
|
|
45
|
+
const reported = JSON.parse(runHarness(node, { mode: "scenarios", sdk, client: `${ir.name}Client`, cases }, "scenarios")) ;
|
|
46
|
+
return new Map(reported.map(({ id, ...observation }) => [id, observation]));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Decodes and re-encodes every schema sample with the JavaScript SDK. */
|
|
50
|
+
export function roundTripJavaScript(node , sdk , samples ) {
|
|
51
|
+
const cases = samples.map(({ id, type, value }) => ({ id, type, value }));
|
|
52
|
+
const reported = JSON.parse(runHarness(node, { mode: "roundtrip", sdk, cases }, "schema round-trip")) ;
|
|
53
|
+
return new Map(reported.map((entry) => [entry.id, entry.outcome]));
|
|
54
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Runs scenarios against the generated Python SDK: a stdlib harness serves each scenario and makes the call.
|
|
2
|
+
|
|
3
|
+
import { spawnCommand } from "./runtimes.ts";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { snake } from "@sdkloom/gen-python";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import { answersOf, } from "./scenarios.ts";
|
|
9
|
+
|
|
10
|
+
const HARNESS = join(import.meta.dirname, "python", "scenario_harness.py");
|
|
11
|
+
const ROUND_TRIP = join(import.meta.dirname, "python", "schema_roundtrip.py");
|
|
12
|
+
const SCENARIO_TIMEOUT_MS = 5_000;
|
|
13
|
+
const RUN_TIMEOUT_MS = 120_000;
|
|
14
|
+
|
|
15
|
+
/** The interpreter used when a kit names no versions to test. */
|
|
16
|
+
export const PYTHON = process.env["SDKLOOM_PYTHON"] ?? "python3";
|
|
17
|
+
|
|
18
|
+
/** Environment for every Python process sdkloom starts: no bytecode caches next to generated files. */
|
|
19
|
+
export function pythonEnv(extra = {}) {
|
|
20
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => key !== "NODE_TEST_CONTEXT"));
|
|
21
|
+
return { ...env, PYTHONDONTWRITEBYTECODE: "1", PYTHONIOENCODING: "utf-8", ...extra };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** How the harness turns a scenario's JSON body into the typed value the Python client takes. */
|
|
25
|
+
function bodyDecoder(ir , node ) {
|
|
26
|
+
// A multipart body is described as parts; the harness builds the MultipartForm.
|
|
27
|
+
if (node.kind === "primitive" && node.name === "multipart") return ["$multipart"];
|
|
28
|
+
if (node.kind !== "ref") return null;
|
|
29
|
+
const named = ir.types.find((candidate) => candidate.name === node.name);
|
|
30
|
+
if (named?.type.kind === "union") return [`decode_${snake(node.name)}`];
|
|
31
|
+
return named?.type.kind === "object" ? [node.name, "from_json"] : null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function planCase(ir , scenario , operation ) {
|
|
35
|
+
const args = scenario.call.args;
|
|
36
|
+
const named = operation.params.filter((param) => param.in !== "path" && param.name in args);
|
|
37
|
+
return {
|
|
38
|
+
id: scenario.id,
|
|
39
|
+
client: `${ir.name}Client`,
|
|
40
|
+
timeout_ms: SCENARIO_TIMEOUT_MS,
|
|
41
|
+
config: Object.fromEntries(Object.entries(scenario.config ?? {}).map(([key, value]) => [snake(key), value])),
|
|
42
|
+
method: snake(operation.name),
|
|
43
|
+
positional: operation.params.filter((param) => param.in === "path").map((param) => args[param.name]),
|
|
44
|
+
keywords: Object.fromEntries(named.map((param) => [snake(param.name), args[param.name]])),
|
|
45
|
+
...(operation.body === undefined ? {} : { body: { value: args["body"], decode: bodyDecoder(ir, operation.body) } }),
|
|
46
|
+
answers: answersOf(scenario),
|
|
47
|
+
all: scenario.call.all ?? false,
|
|
48
|
+
wait: scenario.call.wait ?? false,
|
|
49
|
+
events: operation.events !== undefined,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function runPython(python , script , plan , what ) {
|
|
54
|
+
const result = spawnCommand(python, [script], { input: JSON.stringify(plan), env: pythonEnv(), timeout: RUN_TIMEOUT_MS });
|
|
55
|
+
if (result.error !== undefined || result.status !== 0) {
|
|
56
|
+
const reason = result.error?.message ?? result.stderr.trim().split("\n").at(-1) ?? `exit ${String(result.status)}`;
|
|
57
|
+
throw new Error(`could not run the Python ${what} with ${python.join(" ")}: ${reason}`);
|
|
58
|
+
}
|
|
59
|
+
return result.stdout;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Decodes and re-encodes every schema sample with the generated Python SDK. */
|
|
63
|
+
export function roundTripPython(python , root , outDir , module , samples ) {
|
|
64
|
+
const cases = samples.map((sample) => ({ id: sample.id, type: sample.type, union: sample.union, snake: snake(sample.type), value: sample.value }));
|
|
65
|
+
const reported = JSON.parse(runPython(python, ROUND_TRIP, { sdk: join(root, outDir), module, cases }, "schema round-trip")) ;
|
|
66
|
+
return new Map(reported.map((entry) => [entry.id, entry.outcome]));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function observePython(python , root , outDir , module , ir , scenarios ) {
|
|
70
|
+
const observations = new Map ();
|
|
71
|
+
const runnable = scenarios.flatMap((scenario) => {
|
|
72
|
+
const hook = scenario.webhook;
|
|
73
|
+
// A webhook case calls the SDK's verify_<name>_webhook instead of an operation.
|
|
74
|
+
if (hook !== undefined) return [{ id: scenario.id, webhook: { ...hook, verify: `verify_${snake(hook.name)}_webhook` } }];
|
|
75
|
+
// A logic case calls the SDK's logic function with its inputs as keyword arguments.
|
|
76
|
+
const logic = scenario.logic;
|
|
77
|
+
if (logic !== undefined) return [{ id: scenario.id, logic: { name: snake(logic.name), args: Object.fromEntries(Object.entries(logic.args).map(([name, value]) => [snake(name), value])) } }];
|
|
78
|
+
const operation = ir.operations.find((candidate) => candidate.name === scenario.call.op);
|
|
79
|
+
if (operation === undefined) {
|
|
80
|
+
observations.set(scenario.id, { outcome: { ok: false, error: "UnknownOperation", message: scenario.call.op } });
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
return [planCase(ir, scenario, operation)];
|
|
84
|
+
});
|
|
85
|
+
if (runnable.length === 0) return observations;
|
|
86
|
+
|
|
87
|
+
const reported = JSON.parse(runPython(python, HARNESS, { sdk: join(root, outDir), module, scenarios: runnable }, "scenarios")) ;
|
|
88
|
+
reported.forEach(({ id, ...observation }) => observations.set(id, observation));
|
|
89
|
+
return observations;
|
|
90
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// JSON scenarios: loading them and judging what a generated SDK did against what the scenario expects.
|
|
2
|
+
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { canonicalJson } from "@sdkloom/codegen";
|
|
6
|
+
import { validateCase } from "@sdkloom/conformance";
|
|
7
|
+
import { listFiles } from "./io.ts";
|
|
8
|
+
|
|
9
|
+
/** One part of a multipart/form-data body: a text field, or a file when it has a filename. */
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/** The parts of a multipart/form-data body (RFC 7578), read with the boundary of its Content-Type; undefined if it is not one. */
|
|
27
|
+
export function parseMultipart(body , contentType ) {
|
|
28
|
+
const boundary = /boundary=("?)([^";]+)\1/.exec(contentType ?? "")?.[2];
|
|
29
|
+
if (boundary === undefined || !/^multipart\/form-data/i.test(contentType ?? "")) return undefined;
|
|
30
|
+
const sections = body.split(`--${boundary}`);
|
|
31
|
+
if (sections.at(-1)?.startsWith("--") !== true) return undefined;
|
|
32
|
+
return sections.slice(1, -1).map((section) => {
|
|
33
|
+
const text = section.replace(/^\r\n/, "").replace(/\r\n$/, "");
|
|
34
|
+
const split = text.indexOf("\r\n\r\n");
|
|
35
|
+
const head = split < 0 ? text : text.slice(0, split);
|
|
36
|
+
const value = split < 0 ? "" : text.slice(split + 4);
|
|
37
|
+
const disposition = /^content-disposition:(.*)$/im.exec(head)?.[1] ?? "";
|
|
38
|
+
const param = (name ) => new RegExp(`;\\s*${name}="([^"]*)"`, "i").exec(disposition)?.[1];
|
|
39
|
+
const type = /^content-type:\s*(.*)$/im.exec(head)?.[1]?.trim();
|
|
40
|
+
const filename = param("filename");
|
|
41
|
+
return { name: param("name") ?? "", value, ...(filename === undefined ? {} : { filename }), ...(type === undefined ? {} : { contentType: type }) };
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
/** A request the API sent to the SDK's user: the SDK verifies its signature at `now` and reads its body. */
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
/** The answers a harness serves, in order; the last one repeats. */
|
|
88
|
+
export function answersOf(scenario ) {
|
|
89
|
+
return Array.isArray(scenario.respond) ? scenario.respond : [scenario.respond ];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** A scenario as the plan of a generated harness (Go, Rust, C#): the call, the answers, or the webhook to verify. */
|
|
93
|
+
export function harnessCase(scenario ) {
|
|
94
|
+
if (scenario.webhook !== undefined) return { id: scenario.id, webhook: scenario.webhook };
|
|
95
|
+
if (scenario.logic !== undefined) return { id: scenario.id, logic: scenario.logic };
|
|
96
|
+
return { id: scenario.id, op: scenario.call.op, args: scenario.call.args, all: scenario.call.all ?? false, wait: scenario.call.wait ?? false, config: scenario.config ?? {}, answers: answersOf(scenario) };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** A scenario file: either a valid scenario or the reasons it is invalid. */
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
/** What the server received, as seen by any language's harness. Header names are lower case. */
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
export function loadScenarios(root , dir ) {
|
|
128
|
+
return listFiles(join(root, dir))
|
|
129
|
+
.filter((path) => path.endsWith(".json"))
|
|
130
|
+
.map((path) => {
|
|
131
|
+
const id = path.replace(/\.json$/, "");
|
|
132
|
+
const value = JSON.parse(readFileSync(join(root, dir, path), "utf8"));
|
|
133
|
+
const issues = validateCase(value);
|
|
134
|
+
if (issues.length > 0) return { id, name: id, issues };
|
|
135
|
+
const loaded = value ;
|
|
136
|
+
// A webhook or logic case has no call or response; empty ones keep the rest of the pipeline uniform.
|
|
137
|
+
const scenario = loaded.webhook === undefined && loaded.logic === undefined ? loaded : { ...loaded, call: { op: "", args: {} }, respond: { status: 200 } };
|
|
138
|
+
return { id: scenario.id, name: scenario.name, scenario, issues: [] };
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function sameJson(a , b ) {
|
|
143
|
+
if (a === undefined || b === undefined) return a === b;
|
|
144
|
+
return canonicalJson(a) === canonicalJson(b);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function requestProblems(expected , received , label = "") {
|
|
148
|
+
if (expected === undefined) return [];
|
|
149
|
+
if (received === undefined) return [`${label}no request reached the server`];
|
|
150
|
+
const body = () => (received.body === "" ? undefined : JSON.parse(received.body));
|
|
151
|
+
const contentType = received.headers["content-type"];
|
|
152
|
+
const form = expected.multipart === undefined ? undefined : parseMultipart(received.body, Array.isArray(contentType) ? contentType[0] : (contentType ));
|
|
153
|
+
return [
|
|
154
|
+
...(received.method === expected.method ? [] : [`expected a ${expected.method} request, got ${received.method}`]),
|
|
155
|
+
...(received.url === expected.path ? [] : [`expected path ${expected.path}, got ${received.url}`]),
|
|
156
|
+
...Object.entries(expected.headers ?? {})
|
|
157
|
+
.filter(([name, value]) => received.headers[name.toLowerCase()] !== value)
|
|
158
|
+
.map(([name, value]) => `expected header ${name}: ${value}, got ${String(received.headers[name.toLowerCase()])}`),
|
|
159
|
+
...(expected.json === undefined || sameJson(body(), expected.json) ? [] : [`expected request body ${JSON.stringify(expected.json)}, got ${received.body}`]),
|
|
160
|
+
...(expected.multipart === undefined || sameJson(form ?? null, expected.multipart) ? [] : [`expected form parts ${JSON.stringify(expected.multipart)}, got ${JSON.stringify(form ?? received.body)}`]),
|
|
161
|
+
].map((problem) => `${label}${problem}`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function resultProblems(expect , outcome ) {
|
|
165
|
+
if (expect.error !== undefined) {
|
|
166
|
+
if (outcome.ok) return [`expected error ${expect.error}, got a result`];
|
|
167
|
+
return outcome.error === expect.error ? [] : [`expected error ${expect.error}, got ${outcome.error}`];
|
|
168
|
+
}
|
|
169
|
+
if (!outcome.ok) return [`expected a result, got ${outcome.error}: ${outcome.message}`];
|
|
170
|
+
return sameJson(outcome.value ?? null, expect.equals) ? [] : [`expected result ${JSON.stringify(expect.equals)}, got ${JSON.stringify(outcome.value ?? null)}`];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function judge(scenario , observation ) {
|
|
174
|
+
const all = scenario.expectRequests ?? [];
|
|
175
|
+
const requests = observation.requests ?? (observation.received === undefined ? [] : [observation.received]);
|
|
176
|
+
const counted = all.length === 0 || requests.length === all.length ? [] : [`expected ${all.length} requests, got ${requests.length}`];
|
|
177
|
+
return [
|
|
178
|
+
...requestProblems(scenario.expectRequest, observation.received ?? requests[0]),
|
|
179
|
+
...counted,
|
|
180
|
+
...all.flatMap((expected, index) => requestProblems(expected, requests[index], `request ${index + 1}: `)),
|
|
181
|
+
...resultProblems(scenario.expect, observation.outcome),
|
|
182
|
+
];
|
|
183
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Schema round-trip: deterministic samples for every model and union, decoded and re-encoded by each generated SDK.
|
|
2
|
+
// A sample must come back unchanged in every language: unicode, long decimals, null, unknown fields and variants.
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const TEXT = 'çğüşöı 🚀 "quoted" \\ tab\t';
|
|
16
|
+
const EXTRA = { sdkloomExtra: { nested: [1, "x", null, true] } };
|
|
17
|
+
const UNKNOWN_TAG = "sdkloom-unknown";
|
|
18
|
+
|
|
19
|
+
const PRIMITIVE = {
|
|
20
|
+
string: TEXT,
|
|
21
|
+
secret: "s3cr3t",
|
|
22
|
+
datetime: "2026-12-05T10:00:00.123+03:00",
|
|
23
|
+
decimal: "-12345678901234567890.10",
|
|
24
|
+
int: 42,
|
|
25
|
+
number: 0.5,
|
|
26
|
+
bool: false,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function sampleOf(ir , node , path , stack ) {
|
|
30
|
+
switch (node.kind) {
|
|
31
|
+
case "primitive": {
|
|
32
|
+
const value = PRIMITIVE[node.name];
|
|
33
|
+
if (value === undefined) throw new Error(`${path}: ${node.name} has no JSON sample`);
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
case "enum":
|
|
37
|
+
return node.values[0] ?? "";
|
|
38
|
+
case "list":
|
|
39
|
+
return [sampleOf(ir, node.item, `${path}[]`, stack)];
|
|
40
|
+
case "map":
|
|
41
|
+
return { "key ü": sampleOf(ir, node.value, `${path}{}`, stack) };
|
|
42
|
+
case "ref": {
|
|
43
|
+
if (stack.includes(node.name)) throw new Error(`${path}: recursive type ${node.name} needs an optional field to stop at`);
|
|
44
|
+
const named = ir.types.find((candidate) => candidate.name === node.name);
|
|
45
|
+
if (named === undefined) throw new Error(`${path}: unknown type ${node.name}`);
|
|
46
|
+
return sampleOf(ir, named.type, node.name, [...stack, node.name]);
|
|
47
|
+
}
|
|
48
|
+
case "object":
|
|
49
|
+
return objectSample(ir, node.fields, path, stack, false);
|
|
50
|
+
case "union": {
|
|
51
|
+
const first = node.variants[0];
|
|
52
|
+
if (first === undefined) throw new Error(`${path}: a union needs a variant`);
|
|
53
|
+
return { ...(sampleOf(ir, { kind: "ref", name: first.type }, path, stack) ), [node.discriminator]: first.tag };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Every field present; nullable fields are null. Top-level samples also carry an unknown field. */
|
|
59
|
+
function objectSample(ir , fields , path , stack , extra ) {
|
|
60
|
+
const entries = fields.flatMap((item) => {
|
|
61
|
+
if (item.nullable) return [[item.name, null]];
|
|
62
|
+
const recursive = item.type.kind === "ref" && stack.includes(item.type.name);
|
|
63
|
+
if (recursive && item.optional) return [];
|
|
64
|
+
return [[item.name, sampleOf(ir, item.type, `${path}.${item.name}`, stack)]];
|
|
65
|
+
});
|
|
66
|
+
return { ...Object.fromEntries(entries), ...(extra ? EXTRA : {}) };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function schemaSamples(ir ) {
|
|
70
|
+
return ir.types.flatMap((named) => {
|
|
71
|
+
const type = named.type;
|
|
72
|
+
if (type.kind === "object") {
|
|
73
|
+
return [{ id: named.name, type: named.name, union: false, value: objectSample(ir, type.fields, named.name, [named.name], true) }];
|
|
74
|
+
}
|
|
75
|
+
if (type.kind !== "union") return [];
|
|
76
|
+
const variants = type.variants.map((variant) => {
|
|
77
|
+
const target = ir.types.find((candidate) => candidate.name === variant.type);
|
|
78
|
+
if (target?.type.kind !== "object") throw new Error(`types.${named.name}: variant ${variant.tag} must be an object type`);
|
|
79
|
+
const fields = objectSample(ir, target.type.fields, `${named.name}.${variant.tag}`, [named.name, variant.type], true);
|
|
80
|
+
return { id: `${named.name}.${variant.tag}`, type: named.name, union: true, value: { ...fields, [type.discriminator]: variant.tag } };
|
|
81
|
+
});
|
|
82
|
+
return [...variants, { id: `${named.name}.unknown`, type: named.name, union: true, value: { [type.discriminator]: UNKNOWN_TAG, ...EXTRA } }];
|
|
83
|
+
});
|
|
84
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Files created by `sdkloom init`: a small, working petstore SDK project.
|
|
2
|
+
|
|
3
|
+
const CONFIG = [
|
|
4
|
+
'import { defineConfig } from "@sdkloom/core";',
|
|
5
|
+
"",
|
|
6
|
+
"export default defineConfig({",
|
|
7
|
+
' name: "petstore",',
|
|
8
|
+
' version: "0.1.0",',
|
|
9
|
+
' source: "sdk/index.ts",',
|
|
10
|
+
' targets: { typescript: { package: "petstore-sdk" } },',
|
|
11
|
+
"});",
|
|
12
|
+
"",
|
|
13
|
+
].join("\n");
|
|
14
|
+
|
|
15
|
+
const DEFINITION = [
|
|
16
|
+
'import { get, middleware, model, post, sdk, t } from "@sdkloom/core";',
|
|
17
|
+
"",
|
|
18
|
+
'const Pet = model("Pet", { id: t.string({ doc: "Pet id." }), name: t.string(), tag: t.optional(t.string()) }, { doc: "A pet." });',
|
|
19
|
+
'const NewPet = model("NewPet", { name: t.string(), tag: t.optional(t.string()) });',
|
|
20
|
+
"",
|
|
21
|
+
'const bearer = middleware("bearer", { config: { apiKey: t.secret({ doc: "API key." }) } }, async (req, next, ctx) =>',
|
|
22
|
+
' next(req.withHeader("authorization", `Bearer ${ctx.config.apiKey}`)),',
|
|
23
|
+
");",
|
|
24
|
+
"",
|
|
25
|
+
'export default sdk("Petstore", {',
|
|
26
|
+
' doc: "A small pet store API.",',
|
|
27
|
+
' servers: { production: "https://petstore.example.com/v1" },',
|
|
28
|
+
" use: [bearer],",
|
|
29
|
+
" operations: {",
|
|
30
|
+
' getPet: get("/pets/{id}", { path: { id: t.string() }, returns: Pet, errors: { 404: "NotFound" }, doc: "Returns one pet." }),',
|
|
31
|
+
' listPets: get("/pets", { query: { limit: t.optional(t.int()) }, returns: t.list(Pet), doc: "Lists pets." }),',
|
|
32
|
+
' createPet: post("/pets", { body: NewPet, returns: Pet, doc: "Adds a pet." }),',
|
|
33
|
+
" },",
|
|
34
|
+
"});",
|
|
35
|
+
"",
|
|
36
|
+
].join("\n");
|
|
37
|
+
|
|
38
|
+
const TESTS = [
|
|
39
|
+
'import { test } from "node:test";',
|
|
40
|
+
'import assert from "node:assert/strict";',
|
|
41
|
+
'import { NotFoundError } from "../generated/typescript/src/index.ts";',
|
|
42
|
+
'import { examples, mockClient } from "../generated/typescript/src/testing.ts";',
|
|
43
|
+
"",
|
|
44
|
+
'test("getPet returns the pet and sends the API key", async () => {',
|
|
45
|
+
' const { client, mock } = mockClient({ apiKey: "secret" });',
|
|
46
|
+
' mock.getPet.returns(examples.Pet({ id: "p1", name: "Rex" }));',
|
|
47
|
+
"",
|
|
48
|
+
' const pet = await client.getPet({ id: "p1" });',
|
|
49
|
+
"",
|
|
50
|
+
' assert.equal(pet.name, "Rex");',
|
|
51
|
+
' assert.equal(mock.getPet.calls[0]?.header("authorization"), "Bearer secret");',
|
|
52
|
+
"});",
|
|
53
|
+
"",
|
|
54
|
+
'test("getPet turns a 404 into NotFoundError", async () => {',
|
|
55
|
+
" const { client, mock } = mockClient();",
|
|
56
|
+
' mock.getPet.fails(404, { message: "no such pet" });',
|
|
57
|
+
"",
|
|
58
|
+
' await assert.rejects(client.getPet({ id: "missing" }), NotFoundError);',
|
|
59
|
+
"});",
|
|
60
|
+
"",
|
|
61
|
+
].join("\n");
|
|
62
|
+
|
|
63
|
+
const SCENARIO = `${JSON.stringify(
|
|
64
|
+
{
|
|
65
|
+
id: "0001-get-pet",
|
|
66
|
+
name: "getPet encodes the id in the path and decodes the pet",
|
|
67
|
+
level: "MUST",
|
|
68
|
+
requirements: ["PETSTORE-GET-PET"],
|
|
69
|
+
config: { apiKey: "test" },
|
|
70
|
+
call: { op: "getPet", args: { id: "p 1" } },
|
|
71
|
+
expectRequest: { method: "GET", path: "/pets/p%201", headers: { authorization: "Bearer test" } },
|
|
72
|
+
respond: { status: 200, json: { id: "p 1", name: "Rex" } },
|
|
73
|
+
expect: { equals: { id: "p 1", name: "Rex" } },
|
|
74
|
+
},
|
|
75
|
+
null,
|
|
76
|
+
2,
|
|
77
|
+
)}\n`;
|
|
78
|
+
|
|
79
|
+
export const TEMPLATE_FILES = [
|
|
80
|
+
[".gitignore", "generated/\ndist/\n"],
|
|
81
|
+
["sdkloom.config.ts", CONFIG],
|
|
82
|
+
["sdk/index.ts", DEFINITION],
|
|
83
|
+
["tests/pets.test.ts", TESTS],
|
|
84
|
+
["scenarios/0001-get-pet.json", SCENARIO],
|
|
85
|
+
];
|