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,56 @@
|
|
|
1
|
+
// Loads an SDK project: sdkloom.config.ts and the definition it points to.
|
|
2
|
+
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export const CONFIG_FILE = "sdkloom.config.ts";
|
|
9
|
+
|
|
10
|
+
export class ProjectError extends Error {
|
|
11
|
+
constructor(message ) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "ProjectError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function isRecord(value ) {
|
|
24
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let loads = 0;
|
|
28
|
+
|
|
29
|
+
/** Imports a module's default export, bypassing the module cache so edits are picked up. */
|
|
30
|
+
async function importDefault(path ) {
|
|
31
|
+
loads += 1;
|
|
32
|
+
const module = (await import(`${pathToFileURL(path).href}?load=${loads}`)) ;
|
|
33
|
+
return module.default;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function checkConfig(value ) {
|
|
37
|
+
if (!isRecord(value)) throw new ProjectError(`${CONFIG_FILE} must export default defineConfig({ ... })`);
|
|
38
|
+
for (const key of ["name", "version", "source"]) {
|
|
39
|
+
if (typeof value[key] !== "string") throw new ProjectError(`${CONFIG_FILE}: "${key}" must be a string`);
|
|
40
|
+
}
|
|
41
|
+
if (!isRecord(value["targets"])) throw new ProjectError(`${CONFIG_FILE}: "targets" must be an object`);
|
|
42
|
+
return value ;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function loadProject(root ) {
|
|
46
|
+
const configPath = join(root, CONFIG_FILE);
|
|
47
|
+
if (!existsSync(configPath)) throw new ProjectError(`${CONFIG_FILE} not found in ${root}; run "sdkloom init" to create a project`);
|
|
48
|
+
const config = checkConfig(await importDefault(configPath));
|
|
49
|
+
|
|
50
|
+
const sourcePath = join(root, config.source);
|
|
51
|
+
if (!existsSync(sourcePath)) throw new ProjectError(`${config.source} not found (set by "source" in ${CONFIG_FILE})`);
|
|
52
|
+
const definition = await importDefault(sourcePath);
|
|
53
|
+
if (!isRecord(definition) || definition["kind"] !== "sdk") throw new ProjectError(`${config.source} must export default sdk(...)`);
|
|
54
|
+
|
|
55
|
+
return { root, config, definition: definition };
|
|
56
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""Runs sdkloom scenarios against a generated Python SDK. Standard library only; Python 2.7 and 3.
|
|
2
|
+
|
|
3
|
+
Reads a plan as JSON on stdin and prints one observation per scenario as JSON on stdout:
|
|
4
|
+
what the local server received and what the client call returned or raised.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import absolute_import, division, unicode_literals
|
|
8
|
+
|
|
9
|
+
import importlib
|
|
10
|
+
import json
|
|
11
|
+
import sys
|
|
12
|
+
import threading
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
16
|
+
from socketserver import ThreadingMixIn
|
|
17
|
+
except ImportError: # Python 2.7
|
|
18
|
+
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
|
19
|
+
from SocketServer import ThreadingMixIn
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
text = unicode # noqa: F821 - Python 2.7, where str is bytes
|
|
23
|
+
except NameError:
|
|
24
|
+
text = str
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ThreadingHTTPServer(ThreadingMixIn, HTTPServer):
|
|
28
|
+
daemon_threads = True
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _serve(answers):
|
|
32
|
+
"""Answers requests in order (the last answer repeats) and records every request."""
|
|
33
|
+
seen = []
|
|
34
|
+
|
|
35
|
+
class Handler(BaseHTTPRequestHandler):
|
|
36
|
+
def _handle(self):
|
|
37
|
+
length = int(self.headers.get("content-length") or 0)
|
|
38
|
+
body = self.rfile.read(length) if length else b""
|
|
39
|
+
respond = answers[min(len(seen), len(answers) - 1)]
|
|
40
|
+
seen.append({
|
|
41
|
+
"method": self.command,
|
|
42
|
+
"url": self.path,
|
|
43
|
+
"headers": {name.lower(): value for name, value in self.headers.items()},
|
|
44
|
+
"body": body.decode("utf-8", "replace"),
|
|
45
|
+
})
|
|
46
|
+
if respond.get("text") is not None:
|
|
47
|
+
payload = respond["text"].encode("utf-8")
|
|
48
|
+
else:
|
|
49
|
+
payload = b"" if respond.get("json") is None else json.dumps(respond["json"]).encode("utf-8")
|
|
50
|
+
self.send_response(respond["status"])
|
|
51
|
+
if respond.get("json") is not None:
|
|
52
|
+
self.send_header("content-type", "application/json")
|
|
53
|
+
for name, value in (respond.get("headers") or {}).items():
|
|
54
|
+
self.send_header(name, value)
|
|
55
|
+
self.send_header("content-length", str(len(payload)))
|
|
56
|
+
self.end_headers()
|
|
57
|
+
self.wfile.write(payload)
|
|
58
|
+
|
|
59
|
+
do_GET = do_POST = do_PUT = do_PATCH = do_DELETE = do_HEAD = _handle
|
|
60
|
+
|
|
61
|
+
def log_message(self, *args):
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
|
|
65
|
+
thread = threading.Thread(target=server.serve_forever)
|
|
66
|
+
thread.daemon = True
|
|
67
|
+
thread.start()
|
|
68
|
+
return server, seen
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _resolve(module, path):
|
|
72
|
+
value = module
|
|
73
|
+
for name in path:
|
|
74
|
+
value = getattr(value, name)
|
|
75
|
+
return value
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _webhook(sdk, plain, case):
|
|
79
|
+
"""A webhook case: verify and read the body with the SDK's verify_<name>_webhook."""
|
|
80
|
+
hook = case["webhook"]
|
|
81
|
+
try:
|
|
82
|
+
value = getattr(sdk, hook["verify"])(hook["body"].encode("utf-8"), hook["headers"], hook["secret"], hook["now"])
|
|
83
|
+
outcome = {"ok": True, "value": plain(value)}
|
|
84
|
+
except Exception as error: # noqa: BLE001 - one scenario's failure must not stop the others
|
|
85
|
+
outcome = {"ok": False, "error": getattr(error, "name", None) or type(error).__name__, "message": text(error)}
|
|
86
|
+
return {"id": case["id"], "outcome": outcome}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _logic(sdk, plain, case):
|
|
90
|
+
"""A logic case: call the SDK's logic function; any failure is reported as Error, as in every language."""
|
|
91
|
+
logic = case["logic"]
|
|
92
|
+
try:
|
|
93
|
+
outcome = {"ok": True, "value": plain(getattr(sdk, logic["name"])(**logic["args"]))}
|
|
94
|
+
except Exception as error: # noqa: BLE001 - one scenario's failure must not stop the others
|
|
95
|
+
outcome = {"ok": False, "error": "Error", "message": text(error)}
|
|
96
|
+
return {"id": case["id"], "outcome": outcome}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _observe(sdk, models, plain, case):
|
|
100
|
+
if "webhook" in case:
|
|
101
|
+
return _webhook(sdk, plain, case)
|
|
102
|
+
if "logic" in case:
|
|
103
|
+
return _logic(sdk, plain, case)
|
|
104
|
+
server, seen = _serve(case["answers"])
|
|
105
|
+
try:
|
|
106
|
+
base_url = "http://127.0.0.1:%d" % server.server_address[1]
|
|
107
|
+
try:
|
|
108
|
+
client = getattr(sdk, case["client"])(base_url=base_url, timeout_ms=case["timeout_ms"], **case["config"])
|
|
109
|
+
positional = list(case["positional"])
|
|
110
|
+
body = case.get("body")
|
|
111
|
+
if body is not None:
|
|
112
|
+
if body["decode"] == ["$multipart"]:
|
|
113
|
+
form = sdk.MultipartForm()
|
|
114
|
+
for part in body["value"]["parts"]:
|
|
115
|
+
if part.get("filename") is None:
|
|
116
|
+
form = form.field(part["name"], part["value"])
|
|
117
|
+
else:
|
|
118
|
+
form = form.file(part["name"], part["filename"], part.get("contentType") or "application/octet-stream", part["value"].encode("utf-8"))
|
|
119
|
+
positional.append(form)
|
|
120
|
+
else:
|
|
121
|
+
positional.append(_resolve(models, body["decode"])(body["value"]) if body["decode"] else body["value"])
|
|
122
|
+
if case.get("events"):
|
|
123
|
+
# Server-sent events: every event the stream delivers, with its data as JSON.
|
|
124
|
+
events = getattr(client, case["method"])(*positional, **case["keywords"])
|
|
125
|
+
outcome = {"ok": True, "value": [{"event": event.event, "id": event.id, "data": plain(event.data)} for event in events]}
|
|
126
|
+
elif case.get("all"):
|
|
127
|
+
# The operation's iterator over every page, e.g. list_payments_all.
|
|
128
|
+
items = getattr(client, case["method"] + "_all")(*positional, **case["keywords"])
|
|
129
|
+
outcome = {"ok": True, "value": [plain(item) for item in items]}
|
|
130
|
+
else:
|
|
131
|
+
method = case["method"] + ("_and_wait" if case.get("wait") else "")
|
|
132
|
+
value = getattr(client, method)(*positional, **case["keywords"])
|
|
133
|
+
outcome = {"ok": True, "value": plain(value)}
|
|
134
|
+
except Exception as error: # noqa: BLE001 - one scenario's failure must not stop the others
|
|
135
|
+
outcome = {"ok": False, "error": getattr(error, "name", None) or type(error).__name__, "message": text(error)}
|
|
136
|
+
finally:
|
|
137
|
+
server.shutdown()
|
|
138
|
+
server.server_close()
|
|
139
|
+
observation = {"id": case["id"], "outcome": outcome}
|
|
140
|
+
if seen:
|
|
141
|
+
observation["received"] = seen[0]
|
|
142
|
+
observation["requests"] = list(seen)
|
|
143
|
+
return observation
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def main():
|
|
147
|
+
plan = json.load(sys.stdin)
|
|
148
|
+
sys.path.insert(0, str(plan["sdk"]))
|
|
149
|
+
sdk = importlib.import_module(str(plan["module"]))
|
|
150
|
+
models = importlib.import_module(str(plan["module"] + ".models"))
|
|
151
|
+
to_plain = importlib.import_module(str(plan["module"] + "._runtime.models")).to_plain
|
|
152
|
+
|
|
153
|
+
def plain(value):
|
|
154
|
+
# A bytes result is compared as UTF-8 text, like the other languages' harnesses do.
|
|
155
|
+
if isinstance(value, (bytes, bytearray)) and not isinstance(value, str):
|
|
156
|
+
return bytes(value).decode("utf-8", "replace")
|
|
157
|
+
return to_plain(value)
|
|
158
|
+
json.dump([_observe(sdk, models, plain, case) for case in plan["scenarios"]], sys.stdout, default=text)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
if __name__ == "__main__":
|
|
162
|
+
main()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Decodes and re-encodes schema samples with a generated Python SDK. Standard library only; Python 2.7 and 3.
|
|
2
|
+
|
|
3
|
+
Reads {"sdk", "module", "cases": [{"id", "type", "union", "snake", "value"}]} as JSON on stdin and prints
|
|
4
|
+
[{"id", "outcome": {"ok", "value"} | {"ok", "error", "message"}}] as JSON on stdout.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import absolute_import, division, unicode_literals
|
|
8
|
+
|
|
9
|
+
import importlib
|
|
10
|
+
import json
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
text = unicode # noqa: F821 - Python 2.7, where str is bytes
|
|
15
|
+
except NameError:
|
|
16
|
+
text = str
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def round_trip(models, plain, case):
|
|
20
|
+
if case["union"]:
|
|
21
|
+
decoded = getattr(models, "decode_" + case["snake"])(case["value"])
|
|
22
|
+
return plain(getattr(models, "encode_" + case["snake"])(decoded))
|
|
23
|
+
return plain(getattr(models, case["type"]).from_json(case["value"]).to_json())
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def main():
|
|
27
|
+
plan = json.load(sys.stdin)
|
|
28
|
+
sys.path.insert(0, str(plan["sdk"]))
|
|
29
|
+
models = importlib.import_module(str(plan["module"] + ".models"))
|
|
30
|
+
plain = importlib.import_module(str(plan["module"] + "._runtime.models")).to_plain
|
|
31
|
+
results = []
|
|
32
|
+
for case in plan["cases"]:
|
|
33
|
+
try:
|
|
34
|
+
outcome = {"ok": True, "value": round_trip(models, plain, case)}
|
|
35
|
+
except Exception as error: # noqa: BLE001 - every failure is reported, not raised
|
|
36
|
+
outcome = {"ok": False, "error": type(error).__name__, "message": text(error)}
|
|
37
|
+
results.append({"id": case["id"], "outcome": outcome})
|
|
38
|
+
json.dump(results, sys.stdout, default=text)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
main()
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// Uploads to npm, PyPI, Maven Central, crates.io and NuGet with fetch, using each registry's documented HTTP API. Registry URLs can be
|
|
2
|
+
// overridden (SDKLOOM_NPM_REGISTRY, SDKLOOM_PYPI_URL, SDKLOOM_MAVEN_CENTRAL_URL,
|
|
3
|
+
// SDKLOOM_CRATES_URL, SDKLOOM_NUGET_URL) for private registries and tests.
|
|
4
|
+
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const DEFAULTS = {
|
|
18
|
+
npm: "https://registry.npmjs.org",
|
|
19
|
+
pypi: "https://upload.pypi.org/legacy/",
|
|
20
|
+
central: "https://central.sonatype.com",
|
|
21
|
+
crates: "https://crates.io",
|
|
22
|
+
nuget: "https://www.nuget.org/api/v2/package",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function base64(bytes ) {
|
|
26
|
+
let binary = "";
|
|
27
|
+
bytes.forEach((byte) => (binary += String.fromCharCode(byte)));
|
|
28
|
+
return btoa(binary);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function check(response , what ) {
|
|
32
|
+
const body = new TextDecoder().decode(new Uint8Array(await response.arrayBuffer()));
|
|
33
|
+
if (response.status < 200 || response.status > 299) throw new Error(`${what} failed with HTTP ${response.status}: ${body.slice(0, 500)}`);
|
|
34
|
+
return body;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** multipart/form-data with text fields and one file. */
|
|
38
|
+
function multipart(fields , file , boundary ) {
|
|
39
|
+
const encoder = new TextEncoder();
|
|
40
|
+
const parts = [];
|
|
41
|
+
for (const [name, value] of fields) parts.push(encoder.encode(`--${boundary}\r\nContent-Disposition: form-data; name="${name}"\r\n\r\n${value}\r\n`));
|
|
42
|
+
parts.push(encoder.encode(`--${boundary}\r\nContent-Disposition: form-data; name="${file.field}"; filename="${file.name}"\r\nContent-Type: application/octet-stream\r\n\r\n`), file.bytes, encoder.encode(`\r\n--${boundary}--\r\n`));
|
|
43
|
+
const result = new Uint8Array(parts.reduce((size, part) => size + part.length, 0));
|
|
44
|
+
let offset = 0;
|
|
45
|
+
parts.forEach((part) => {
|
|
46
|
+
result.set(part, offset);
|
|
47
|
+
offset += part.length;
|
|
48
|
+
});
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const BOUNDARY = "----sdkloom-upload-boundary";
|
|
53
|
+
|
|
54
|
+
export function npmUpload(artifact , manifest ) {
|
|
55
|
+
const registry = (process.env["SDKLOOM_NPM_REGISTRY"] ?? DEFAULTS.npm).replace(/\/$/, "");
|
|
56
|
+
const escaped = manifest.name.replace("/", "%2f");
|
|
57
|
+
return {
|
|
58
|
+
language: "typescript",
|
|
59
|
+
registry,
|
|
60
|
+
tokenVariable: "NPM_TOKEN",
|
|
61
|
+
send: async (token) => {
|
|
62
|
+
const document = {
|
|
63
|
+
_id: manifest.name,
|
|
64
|
+
name: manifest.name,
|
|
65
|
+
"dist-tags": { latest: manifest.version },
|
|
66
|
+
versions: {
|
|
67
|
+
[manifest.version]: {
|
|
68
|
+
...manifest,
|
|
69
|
+
_id: `${manifest.name}@${manifest.version}`,
|
|
70
|
+
dist: {
|
|
71
|
+
shasum: createHash("sha1").update(artifact.bytes).digest("hex"),
|
|
72
|
+
integrity: `sha512-${createHash("sha512").update(artifact.bytes).digest("base64")}`,
|
|
73
|
+
tarball: `${registry}/${manifest.name}/-/${artifact.fileName}`,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
access: "public",
|
|
78
|
+
_attachments: { [artifact.fileName]: { content_type: "application/octet-stream", data: base64(artifact.bytes), length: artifact.bytes.length } },
|
|
79
|
+
};
|
|
80
|
+
const response = await fetch(`${registry}/${escaped}`, {
|
|
81
|
+
method: "PUT",
|
|
82
|
+
headers: [["authorization", `Bearer ${token}`], ["content-type", "application/json"]],
|
|
83
|
+
body: new TextEncoder().encode(JSON.stringify(document)),
|
|
84
|
+
});
|
|
85
|
+
await check(response, `npm publish of ${manifest.name}@${manifest.version}`);
|
|
86
|
+
return `${registry}/${manifest.name}`;
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function pypiUpload(artifact , name , version , pythonTag = "py3") {
|
|
92
|
+
const url = process.env["SDKLOOM_PYPI_URL"] ?? DEFAULTS.pypi;
|
|
93
|
+
return {
|
|
94
|
+
language: "python",
|
|
95
|
+
registry: url,
|
|
96
|
+
tokenVariable: "PYPI_TOKEN",
|
|
97
|
+
send: async (token) => {
|
|
98
|
+
const fields = [
|
|
99
|
+
[":action", "file_upload"],
|
|
100
|
+
["protocol_version", "1"],
|
|
101
|
+
["metadata_version", "2.1"],
|
|
102
|
+
["name", name],
|
|
103
|
+
["version", version],
|
|
104
|
+
["filetype", "bdist_wheel"],
|
|
105
|
+
["pyversion", pythonTag],
|
|
106
|
+
["sha256_digest", createHash("sha256").update(artifact.bytes).digest("hex")],
|
|
107
|
+
];
|
|
108
|
+
const response = await fetch(url, {
|
|
109
|
+
method: "POST",
|
|
110
|
+
headers: [["authorization", `Basic ${btoa(`__token__:${token}`)}`], ["content-type", `multipart/form-data; boundary=${BOUNDARY}`]],
|
|
111
|
+
body: multipart(fields, { field: "content", name: artifact.fileName, bytes: artifact.bytes }, BOUNDARY),
|
|
112
|
+
});
|
|
113
|
+
await check(response, `PyPI upload of ${artifact.fileName}`);
|
|
114
|
+
return `https://pypi.org/project/${name}/${version}/`;
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function centralUpload(artifact , coordinates ) {
|
|
120
|
+
const url = (process.env["SDKLOOM_MAVEN_CENTRAL_URL"] ?? DEFAULTS.central).replace(/\/$/, "");
|
|
121
|
+
return {
|
|
122
|
+
language: "java",
|
|
123
|
+
registry: url,
|
|
124
|
+
tokenVariable: "MAVEN_CENTRAL_TOKEN",
|
|
125
|
+
send: async (token) => {
|
|
126
|
+
const response = await fetch(`${url}/api/v1/publisher/upload?publishingType=USER_MANAGED&name=${encodeURIComponent(coordinates)}`, {
|
|
127
|
+
method: "POST",
|
|
128
|
+
headers: [["authorization", `Bearer ${token}`], ["content-type", `multipart/form-data; boundary=${BOUNDARY}`]],
|
|
129
|
+
body: multipart([], { field: "bundle", name: artifact.fileName, bytes: artifact.bytes }, BOUNDARY),
|
|
130
|
+
});
|
|
131
|
+
const deployment = await check(response, `Maven Central upload of ${coordinates}`);
|
|
132
|
+
return `deployment ${deployment.trim()} (publish it at ${url}/publishing/deployments)`;
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** What crates.io reads from the publish request instead of the .crate's Cargo.toml. */
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
function u32le(value ) {
|
|
151
|
+
return new Uint8Array([value & 0xff, (value >>> 8) & 0xff, (value >>> 16) & 0xff, (value >>> 24) & 0xff]);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** The body of PUT /api/v1/crates/new: JSON length, JSON, .crate length, .crate (all lengths u32 little-endian). */
|
|
155
|
+
export function cratePublishBody(metadata , crate ) {
|
|
156
|
+
const json = new TextEncoder().encode(
|
|
157
|
+
JSON.stringify({
|
|
158
|
+
deps: [],
|
|
159
|
+
features: {},
|
|
160
|
+
authors: [],
|
|
161
|
+
keywords: [],
|
|
162
|
+
categories: [],
|
|
163
|
+
badges: {},
|
|
164
|
+
links: null,
|
|
165
|
+
readme_file: "README.md",
|
|
166
|
+
...metadata,
|
|
167
|
+
}),
|
|
168
|
+
);
|
|
169
|
+
const parts = [u32le(json.length), json, u32le(crate.length), crate];
|
|
170
|
+
const body = new Uint8Array(parts.reduce((size, part) => size + part.length, 0));
|
|
171
|
+
let offset = 0;
|
|
172
|
+
parts.forEach((part) => {
|
|
173
|
+
body.set(part, offset);
|
|
174
|
+
offset += part.length;
|
|
175
|
+
});
|
|
176
|
+
return body;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function cratesUpload(artifact , metadata ) {
|
|
180
|
+
const url = (process.env["SDKLOOM_CRATES_URL"] ?? DEFAULTS.crates).replace(/\/$/, "");
|
|
181
|
+
return {
|
|
182
|
+
language: "rust",
|
|
183
|
+
registry: url,
|
|
184
|
+
tokenVariable: "CARGO_REGISTRY_TOKEN",
|
|
185
|
+
send: async (token) => {
|
|
186
|
+
const response = await fetch(`${url}/api/v1/crates/new`, {
|
|
187
|
+
method: "PUT",
|
|
188
|
+
headers: [["authorization", token], ["content-type", "application/octet-stream"]],
|
|
189
|
+
body: cratePublishBody(metadata, artifact.bytes),
|
|
190
|
+
});
|
|
191
|
+
await check(response, `crates.io publish of ${metadata.name} ${metadata.vers}`);
|
|
192
|
+
return url === DEFAULTS.crates ? `https://crates.io/crates/${metadata.name}/${metadata.vers}` : `${metadata.name} ${metadata.vers} on ${url}`;
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** NuGet's push API: PUT the .nupkg as multipart/form-data with the API key in X-NuGet-ApiKey. */
|
|
198
|
+
export function nugetUpload(artifact , id , version ) {
|
|
199
|
+
const url = process.env["SDKLOOM_NUGET_URL"] ?? DEFAULTS.nuget;
|
|
200
|
+
return {
|
|
201
|
+
language: "csharp",
|
|
202
|
+
registry: url,
|
|
203
|
+
tokenVariable: "NUGET_API_KEY",
|
|
204
|
+
send: async (token) => {
|
|
205
|
+
const response = await fetch(url, {
|
|
206
|
+
method: "PUT",
|
|
207
|
+
headers: [["X-NuGet-ApiKey", token], ["content-type", `multipart/form-data; boundary=${BOUNDARY}`]],
|
|
208
|
+
body: multipart([], { field: "package", name: artifact.fileName, bytes: artifact.bytes }, BOUNDARY),
|
|
209
|
+
});
|
|
210
|
+
await check(response, `NuGet push of ${id} ${version}`);
|
|
211
|
+
return url === DEFAULTS.nuget ? `https://www.nuget.org/packages/${id}/${version}` : `${id} ${version} on ${url}`;
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Module resolution for the sdkloom command, registered before anything else loads (main.ts imports it first, and the
|
|
2
|
+
// processes that run an author's TypeScript tests get it with --import):
|
|
3
|
+
//
|
|
4
|
+
// - An SDK project outside this repository may import @sdkloom/core without installing it: when the project's own
|
|
5
|
+
// node_modules has no copy, the one next to this command is used.
|
|
6
|
+
// - In the published npm package the sources are JavaScript (Node does not strip types inside node_modules) but keep
|
|
7
|
+
// their imports as written: "./run.ts" and "@sdkloom/ir". Inside the package those resolve to the .js files in the
|
|
8
|
+
// repository's layout. Specifiers are mapped here instead of being rewritten in the text, so code that writes
|
|
9
|
+
// TypeScript for SDK authors (templates, generators) is shipped exactly as it is.
|
|
10
|
+
|
|
11
|
+
import { registerHooks } from "node:module";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { pathToFileURL } from "node:url";
|
|
14
|
+
|
|
15
|
+
const CORE = "@sdkloom/core";
|
|
16
|
+
/** The package (or repository) root: this file is packages/cli/src/resolve-core.{ts,js}. */
|
|
17
|
+
const ROOT = pathToFileURL(`${join(import.meta.dirname, "..", "..", "..")}/`).href;
|
|
18
|
+
const PUBLISHED = import.meta.url.endsWith(".js");
|
|
19
|
+
|
|
20
|
+
/** The specifier to resolve instead, for an import made by a file of the published package; undefined to keep it. */
|
|
21
|
+
export function publishedSpecifier(specifier , parentURL , root = ROOT) {
|
|
22
|
+
if (parentURL === undefined || !parentURL.startsWith(root) || /(^|\/)node_modules\//.test(parentURL.slice(root.length))) return undefined;
|
|
23
|
+
if (/^\.{1,2}\//.test(specifier) && specifier.endsWith(".ts")) return `${specifier.slice(0, -3)}.js`;
|
|
24
|
+
const name = /^@sdkloom\/([a-z-]+)$/.exec(specifier)?.[1];
|
|
25
|
+
return name !== undefined && name !== "core" ? `${root}packages/${name}/src/index.js` : undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
registerHooks({
|
|
29
|
+
resolve(specifier, context, nextResolve) {
|
|
30
|
+
const mapped = PUBLISHED ? publishedSpecifier(specifier, context.parentURL) : undefined;
|
|
31
|
+
if (mapped !== undefined) return nextResolve(mapped, context);
|
|
32
|
+
try {
|
|
33
|
+
return nextResolve(specifier, context);
|
|
34
|
+
} catch (error ) {
|
|
35
|
+
if (specifier !== CORE && !specifier.startsWith(`${CORE}/`)) throw error;
|
|
36
|
+
return nextResolve(specifier, { ...context, parentURL: import.meta.url });
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Entry point of the sdkloom CLI, kept free of process globals so it can be tested.
|
|
2
|
+
|
|
3
|
+
import { parseArgs, } from "node:util";
|
|
4
|
+
import { buildCommand } from "./commands/build.ts";
|
|
5
|
+
import { conformanceCheck } from "./commands/conformance-check.ts";
|
|
6
|
+
import { diffCommand } from "./commands/diff.ts";
|
|
7
|
+
import { publishCommand } from "./commands/publish.ts";
|
|
8
|
+
import { contractCommand } from "./commands/contract.ts";
|
|
9
|
+
import { importOpenApiCommand } from "./commands/import-openapi.ts";
|
|
10
|
+
import { initCommand } from "./commands/init.ts";
|
|
11
|
+
import { kitCheck, kitSources } from "./commands/kit-check.ts";
|
|
12
|
+
import { recipeAdd, recipeList } from "./commands/recipe.ts";
|
|
13
|
+
import { recordCommand } from "./commands/record.ts";
|
|
14
|
+
import { serveCommand } from "./commands/serve.ts";
|
|
15
|
+
import { specCheck } from "./commands/spec-check.ts";
|
|
16
|
+
import { testCommand } from "./commands/test.ts";
|
|
17
|
+
import { doctorCommand } from "./commands/doctor.ts";
|
|
18
|
+
import { variantsCommand } from "./commands/variants.ts";
|
|
19
|
+
import { verifyCommand } from "./commands/verify.ts";
|
|
20
|
+
import { versionCommand } from "./commands/version.ts";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const USAGE = [
|
|
26
|
+
"Usage: sdkloom <command>",
|
|
27
|
+
"",
|
|
28
|
+
"Commands:",
|
|
29
|
+
" init Create a small SDK project here",
|
|
30
|
+
" build [--check] Generate the SDK; --check verifies without writing",
|
|
31
|
+
" test [--strict] [--container] Build, run scenarios and your tests on every tested version",
|
|
32
|
+
" verify Every check before a release: build, tests, version, packages",
|
|
33
|
+
" doctor Supported versions, runtimes found here, end-of-life notes",
|
|
34
|
+
" variants <language> Packages for older versions a language kit offers",
|
|
35
|
+
" diff [--against <git ref>] [--behavior] API changes since the last release, per language;",
|
|
36
|
+
" --behavior also runs that release's scenarios and tests",
|
|
37
|
+
" version [--bump <kind>] [--date YYYY-MM-DD] Set the next version, write CHANGELOG and migration guide",
|
|
38
|
+
" publish [--dry-run] [--yes] Package every SDK with an SBOM into dist/ and upload it",
|
|
39
|
+
" record <operation> [--args <json>] [--config <json>] [--base-url <url>]",
|
|
40
|
+
" Call the real API once and save the answer as a scenario",
|
|
41
|
+
" contract --base-url <url> [--args <json>] [--config <json>]",
|
|
42
|
+
" Call every read operation of a real API and check its answers fit the definition",
|
|
43
|
+
" serve [--port 4010] Run a fake API with example data for every operation",
|
|
44
|
+
" import openapi <file.json> [--out <file>] Write an sdkloom definition (sdk/index.ts) from an OpenAPI 3.x document",
|
|
45
|
+
" recipe list Show ready-made middleware",
|
|
46
|
+
" recipe add <name> Copy a recipe into sdk/recipes as your own source",
|
|
47
|
+
" kit check <dir> [--allowed-sources <file>] Validate a language kit",
|
|
48
|
+
" kit sources <dir> [--verify] List cited pages; --verify fetches them and checks every quote",
|
|
49
|
+
" spec check Check requirements against @requirement tags",
|
|
50
|
+
" conformance check Validate the conformance suite",
|
|
51
|
+
" help Show this help",
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const EXIT_USAGE = 2;
|
|
55
|
+
|
|
56
|
+
function usageError(message , io ) {
|
|
57
|
+
io.err(message);
|
|
58
|
+
USAGE.forEach((line) => io.err(line));
|
|
59
|
+
return EXIT_USAGE;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function run(argv , io ) {
|
|
63
|
+
let parsed ;
|
|
64
|
+
try {
|
|
65
|
+
parsed = parseArgs({
|
|
66
|
+
args: argv,
|
|
67
|
+
options: { "allowed-sources": { type: "string" }, check: { type: "boolean" }, port: { type: "string" }, against: { type: "string" }, bump: { type: "string" }, date: { type: "string" }, "dry-run": { type: "boolean" }, behavior: { type: "boolean" }, verify: { type: "boolean" }, args: { type: "string" }, config: { type: "string" }, "base-url": { type: "string" }, yes: { type: "boolean" }, strict: { type: "boolean" }, container: { type: "boolean" }, out: { type: "string" } },
|
|
68
|
+
allowPositionals: true,
|
|
69
|
+
strict: true,
|
|
70
|
+
});
|
|
71
|
+
} catch (error ) {
|
|
72
|
+
return usageError(error instanceof Error ? error.message : String(error), io);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const [command, subcommand, target] = parsed.positionals;
|
|
76
|
+
const allowedSources = parsed.values["allowed-sources"];
|
|
77
|
+
|
|
78
|
+
switch (command) {
|
|
79
|
+
case undefined:
|
|
80
|
+
case "help":
|
|
81
|
+
USAGE.forEach((line) => io.out(line));
|
|
82
|
+
return 0;
|
|
83
|
+
case "init":
|
|
84
|
+
return initCommand(io);
|
|
85
|
+
case "build":
|
|
86
|
+
return buildCommand(io, parsed.values["check"] === true);
|
|
87
|
+
case "test":
|
|
88
|
+
return testCommand(io, parsed.values["strict"] === true, parsed.values["container"] === true);
|
|
89
|
+
case "diff":
|
|
90
|
+
return diffCommand(io, typeof parsed.values["against"] === "string" ? parsed.values["against"] : undefined, parsed.values["behavior"] === true);
|
|
91
|
+
case "version":
|
|
92
|
+
return versionCommand(io, typeof parsed.values["bump"] === "string" ? parsed.values["bump"] : undefined, typeof parsed.values["date"] === "string" ? parsed.values["date"] : undefined);
|
|
93
|
+
case "verify":
|
|
94
|
+
return verifyCommand(io);
|
|
95
|
+
case "doctor":
|
|
96
|
+
return doctorCommand(io);
|
|
97
|
+
case "variants":
|
|
98
|
+
return variantsCommand(subcommand, io);
|
|
99
|
+
case "publish":
|
|
100
|
+
return publishCommand(io, parsed.values["dry-run"] === true, parsed.values["yes"] === true);
|
|
101
|
+
case "contract": {
|
|
102
|
+
const text = (name ) => (typeof parsed.values[name] === "string" ? (parsed.values[name] ) : undefined);
|
|
103
|
+
return contractCommand(io, { args: text("args"), config: text("config"), baseUrl: text("base-url") });
|
|
104
|
+
}
|
|
105
|
+
case "record": {
|
|
106
|
+
const text = (name ) => (typeof parsed.values[name] === "string" ? (parsed.values[name] ) : undefined);
|
|
107
|
+
return recordCommand(io, { operation: subcommand, args: text("args"), config: text("config"), baseUrl: text("base-url") });
|
|
108
|
+
}
|
|
109
|
+
case "serve":
|
|
110
|
+
return serveCommand(io, typeof parsed.values["port"] === "string" ? parsed.values["port"] : undefined);
|
|
111
|
+
default:
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
switch ([command, subcommand].filter((part) => part !== undefined).join(" ")) {
|
|
116
|
+
case "kit sources":
|
|
117
|
+
return kitSources(target, parsed.values["verify"] === true, io);
|
|
118
|
+
case "kit check":
|
|
119
|
+
return kitCheck(target, typeof allowedSources === "string" ? allowedSources : undefined, io);
|
|
120
|
+
case "spec check":
|
|
121
|
+
return specCheck(io);
|
|
122
|
+
case "conformance check":
|
|
123
|
+
return conformanceCheck(io);
|
|
124
|
+
case "recipe list":
|
|
125
|
+
return recipeList(io);
|
|
126
|
+
case "recipe add":
|
|
127
|
+
return recipeAdd(target, io);
|
|
128
|
+
case "import openapi":
|
|
129
|
+
return importOpenApiCommand(target, typeof parsed.values["out"] === "string" ? parsed.values["out"] : undefined, io);
|
|
130
|
+
default:
|
|
131
|
+
return usageError(`unknown command: ${[command, subcommand].filter((part) => part !== undefined).join(" ")}`, io);
|
|
132
|
+
}
|
|
133
|
+
}
|