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,379 @@
|
|
|
1
|
+
// src/client.rs: Options, Client, one method per operation, RawClient, params structs, specs and error names.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { pagedItems, } from "@sdkloom/ir";
|
|
5
|
+
import { rustName } from "@sdkloom/transpile";
|
|
6
|
+
import { constant, decoder, doc, fieldType, pascal, pathParamName, rust, rustType, snake, str } from "./names.ts";
|
|
7
|
+
|
|
8
|
+
/** Options every client has besides middleware configuration. */
|
|
9
|
+
export const CLIENT_OPTIONS = ["server", "base_url", "transport", "timeout_ms", "middleware", "on_event", "clock", "proxy"];
|
|
10
|
+
|
|
11
|
+
export function configFields(ir ) {
|
|
12
|
+
const fields = new Map ();
|
|
13
|
+
for (const middleware of ir.middlewares) {
|
|
14
|
+
for (const item of middleware.config) {
|
|
15
|
+
if (CLIENT_OPTIONS.includes(snake(item.name))) throw new Error(`config field ${item.name} of middleware ${middleware.name} collides with a client option`);
|
|
16
|
+
if (!fields.has(item.name)) fields.set(item.name, item);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return [...fields.values()];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export function kindOf(node ) {
|
|
25
|
+
if (node === undefined) return undefined;
|
|
26
|
+
return node.kind === "primitive" && (node.name === "bytes" || node.name === "stream" || node.name === "multipart") ? node.name : "json";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The Rust type an operation returns: () for nothing, Vec<u8> for bytes and streams, else the decoded type. */
|
|
30
|
+
export function resultType(operation ) {
|
|
31
|
+
if (operation.events !== undefined) return `EventStream<${rustType(operation.events)}>`;
|
|
32
|
+
const kind = kindOf(operation.returns);
|
|
33
|
+
if (kind === undefined) return "()";
|
|
34
|
+
if (kind !== "json") return "Vec<u8>";
|
|
35
|
+
return rustType(operation.returns );
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** An event stream whose data stays text: no decoder, the data is a String. */
|
|
39
|
+
export function textEvents(node ) {
|
|
40
|
+
return node.kind === "primitive" && node.name === "string";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function paramsType(operation ) {
|
|
44
|
+
return `${pascal(operation.name)}Params`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function named(operation ) {
|
|
48
|
+
return operation.params.filter((param) => param.in !== "path");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Path parameters by value (&str for strings), the body by reference, then a params struct when there are others. */
|
|
52
|
+
function argument(node ) {
|
|
53
|
+
const type = rustType(node);
|
|
54
|
+
return type === "String" ? "&str" : type;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function signature(operation ) {
|
|
58
|
+
const path = operation.params.filter((param) => param.in === "path");
|
|
59
|
+
const parts = [
|
|
60
|
+
...path.map((param) => `${pathParamName(param.name)}: ${argument(param.type)}`),
|
|
61
|
+
...(operation.body === undefined ? [] : [`body: ${kindOf(operation.body) === "json" || kindOf(operation.body) === "multipart" ? `&${rustType(operation.body)}` : "&[u8]"}`]),
|
|
62
|
+
...(named(operation).length === 0 ? [] : [`params: &${paramsType(operation)}`]),
|
|
63
|
+
];
|
|
64
|
+
const call = [...path.map((param) => pathParamName(param.name)), ...(operation.body === undefined ? [] : ["body"]), ...(named(operation).length === 0 ? [] : ["params"])];
|
|
65
|
+
return { declaration: ["&self", ...parts].join(", "), call: call.join(", ") };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function specName(operation ) {
|
|
69
|
+
return `SPEC_${constant(operation.name)}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function errorFactory(name ) {
|
|
73
|
+
return `error_${snake(name)}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function emitParams(writer , operation ) {
|
|
77
|
+
if (named(operation).length === 0) return;
|
|
78
|
+
doc(writer, [`The query and header parameters of ${snake(operation.name)}; start from Default.`]);
|
|
79
|
+
writer.line("#[derive(Clone, Debug, Default, PartialEq)]");
|
|
80
|
+
writer.line(`pub struct ${paramsType(operation)} {`).indent((body) => {
|
|
81
|
+
named(operation).forEach((param) => {
|
|
82
|
+
doc(body, param.doc === undefined ? [] : [param.doc]);
|
|
83
|
+
body.line(`pub ${snake(param.name)}: ${fieldType({ type: param.type, optional: param.optional, nullable: false })},`);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
writer.line("}").line();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const KIND = { json: "Kind::Json", bytes: "Kind::Bytes", stream: "Kind::Stream", multipart: "Kind::Multipart" };
|
|
90
|
+
|
|
91
|
+
function emitSpec(writer , operation ) {
|
|
92
|
+
const body = kindOf(operation.body);
|
|
93
|
+
const result = kindOf(operation.returns);
|
|
94
|
+
const resultKind = operation.events !== undefined ? "Some(Kind::Events)" : result === undefined ? "None" : `Some(${KIND[result]})`;
|
|
95
|
+
writer.line(`static ${specName(operation)}: OperationSpec = OperationSpec {`).indent((spec) => {
|
|
96
|
+
spec.line(`name: ${str(operation.name)},`);
|
|
97
|
+
spec.line(`method: ${str(operation.method)},`);
|
|
98
|
+
spec.line(`path: ${str(operation.path)},`);
|
|
99
|
+
spec.line(`body: ${body === undefined ? "None" : `Some(${KIND[body]})`},`);
|
|
100
|
+
spec.line(`result: ${resultKind},`);
|
|
101
|
+
spec.line(`errors: &[${operation.errors.map((error) => `(${error.status}, ${errorFactory(error.name)})`).join(", ")}],`);
|
|
102
|
+
spec.line(`uses: &[${operation.use.map(str).join(", ")}],`);
|
|
103
|
+
spec.line(`since: ${operation.since === undefined ? "None" : `Some(${str(operation.since)})`},`);
|
|
104
|
+
});
|
|
105
|
+
writer.line("};").line();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function operationDoc(operation ) {
|
|
109
|
+
return [
|
|
110
|
+
operation.doc ?? snake(operation.name),
|
|
111
|
+
"",
|
|
112
|
+
`HTTP: ${operation.method} ${operation.path}`,
|
|
113
|
+
...(operation.since === undefined ? [] : [`Since API version ${operation.since}.`]),
|
|
114
|
+
...(operation.events === undefined ? [] : ["", `Server-sent events, read as they arrive: \`for event in client.${snake(operation.name)}(…)? { let event = event?; … }\`. Drop the stream to stop early.`]),
|
|
115
|
+
...(operation.stability === "stable" ? [] : [`Stability: ${operation.stability}`]),
|
|
116
|
+
...operation.errors.map((error) => `Fails with errors::${constant(error.name)} for HTTP ${error.status}.`),
|
|
117
|
+
"Fails with an ApiError for any other non-2xx response.",
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function args(operation ) {
|
|
122
|
+
const path = operation.params.filter((param) => param.in === "path");
|
|
123
|
+
const query = operation.params.filter((param) => param.in === "query");
|
|
124
|
+
const headers = operation.params.filter((param) => param.in === "header");
|
|
125
|
+
const value = (param ) => `params.${snake(param.name)}.to_json()`;
|
|
126
|
+
const kind = kindOf(operation.body);
|
|
127
|
+
const body = kind === undefined ? "None" : kind === "json" ? "Some(body.to_json().to_json_string().into_bytes())" : kind === "multipart" ? "Some(body.to_body())" : "Some(body.to_vec())";
|
|
128
|
+
return [
|
|
129
|
+
"Args {",
|
|
130
|
+
` path: vec![${path.map((param) => `(${str(param.name)}, ${pathParamName(param.name)}.to_json())`).join(", ")}],`,
|
|
131
|
+
` query: vec![${query.map((param) => `(${str(param.name)}, ${value(param)})`).join(", ")}],`,
|
|
132
|
+
` headers: vec![${headers.map((param) => `(${str(param.name)}, ${value(param)})`).join(", ")}],`,
|
|
133
|
+
` body: ${body},`,
|
|
134
|
+
"}",
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function emitRaw(writer , ir , operation ) {
|
|
139
|
+
const type = resultType(operation);
|
|
140
|
+
const { declaration } = signature(operation);
|
|
141
|
+
doc(writer, [`${snake(operation.name)} with the response, so the HTTP status and headers are available; options change this call.`]);
|
|
142
|
+
writer.line(`pub fn ${snake(operation.name)}(${declaration.replace("&self", "&self, options: &CallOptions")}) -> Result<RawResult<${type}>, Error> {`).indent((fn) => {
|
|
143
|
+
const lines = args(operation);
|
|
144
|
+
fn.line(`let args = ${lines[0]}`);
|
|
145
|
+
lines.slice(1, -1).forEach((line) => fn.line(line));
|
|
146
|
+
fn.line("};");
|
|
147
|
+
fn.line(`let response = call(&self.runtime, &${specName(operation)}, args, options)?;`);
|
|
148
|
+
const kind = kindOf(operation.returns);
|
|
149
|
+
if (operation.events !== undefined) {
|
|
150
|
+
const stream = textEvents(operation.events) ? "EventStream::text(&response)" : `EventStream::json(&response, ${decoder(ir, operation.events, `operations.${operation.name}.events`)})`;
|
|
151
|
+
fn.line(`Ok(RawResult { data: ${stream}, response })`);
|
|
152
|
+
} else if (kind === undefined) fn.line("Ok(RawResult { data: (), response })");
|
|
153
|
+
else if (kind !== "json") fn.line("Ok(RawResult { data: response.body.clone(), response })");
|
|
154
|
+
else {
|
|
155
|
+
fn.line("let value = response.json()?;");
|
|
156
|
+
fn.line(`let data = (${decoder(ir, operation.returns , `operations.${operation.name}.returns`)})(&value, "$")?;`);
|
|
157
|
+
fn.line("Ok(RawResult { data, response })");
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
writer.line("}").line();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function emitMethod(writer , operation ) {
|
|
164
|
+
const { declaration, call } = signature(operation);
|
|
165
|
+
doc(writer, operationDoc(operation));
|
|
166
|
+
if (operation.deprecated !== undefined) writer.line(`#[deprecated(note = ${str(operation.deprecated)})]`);
|
|
167
|
+
writer.line(`pub fn ${snake(operation.name)}(${declaration}) -> Result<${resultType(operation)}, Error> {`).indent((fn) => {
|
|
168
|
+
fn.line(`self.raw().${snake(operation.name)}(${["&CallOptions::default()", ...(call === "" ? [] : [call])].join(", ")}).map(|result| result.data)`);
|
|
169
|
+
});
|
|
170
|
+
writer.line("}").line();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** <name>_all: a Pager over every item of every page, fetched as the caller iterates (kit block pagination.iterate). */
|
|
174
|
+
/** <name>_and_wait: starts the work, then polls until it is done (kit block lro.wait). */
|
|
175
|
+
function emitWait(writer , ir , operation , wait ) {
|
|
176
|
+
const name = snake(operation.name);
|
|
177
|
+
const type = resultType(operation);
|
|
178
|
+
const poll = ir.operations.find((candidate) => candidate.name === wait.poll);
|
|
179
|
+
if (poll === undefined) throw new Error(`operations.${operation.name}.wait: no operation ${wait.poll}`);
|
|
180
|
+
const { declaration, call } = signature(operation);
|
|
181
|
+
const pollArgs = [`¤t.${snake(wait.from)}`, ...(poll.params.some((param) => param.in !== "path") ? [`&${paramsType(poll)}::default()`] : [])];
|
|
182
|
+
doc(writer, [
|
|
183
|
+
`${name}, then ${snake(wait.poll)} every ${wait.intervalMs} ms until ${snake(wait.field)} is ${wait.done.join(" or ")}; the finished result.`,
|
|
184
|
+
"",
|
|
185
|
+
`Fails with Error::WaitTimeout when the work is not done within ${wait.timeoutMs} ms.`,
|
|
186
|
+
]);
|
|
187
|
+
writer.line(`pub fn ${name}_and_wait(${declaration}) -> Result<${type}, Error> {`).indent((fn) => {
|
|
188
|
+
fn.line(`let first = self.${name}(${call})?;`);
|
|
189
|
+
fn.line(`let done = [${wait.done.map(str).join(", ")}];`);
|
|
190
|
+
fn.line(`wait_until(first, |current| self.${snake(wait.poll)}(${pollArgs.join(", ")}), |current| done.contains(¤t.${snake(wait.field)}.as_str()), self.runtime.clock.as_ref(), ${wait.intervalMs}, ${wait.timeoutMs})`);
|
|
191
|
+
});
|
|
192
|
+
writer.line("}").line();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function emitIterator(writer , ir , operation , paginate ) {
|
|
196
|
+
const returns = operation.returns;
|
|
197
|
+
const page = returns?.kind === "ref" ? ir.types.find((named) => named.name === returns.name) : undefined;
|
|
198
|
+
const fields = page?.type.kind === "object" ? page.type.fields : [];
|
|
199
|
+
const { item, field: itemsField } = pagedItems(ir, operation);
|
|
200
|
+
const name = snake(operation.name);
|
|
201
|
+
const params = paramsType(operation);
|
|
202
|
+
const { declaration, call } = signature(operation);
|
|
203
|
+
// Every borrowed argument lives as long as the pager: it calls the operation again for each page.
|
|
204
|
+
const borrowed = declaration.replaceAll("&self", "&'a self").replace(/: &(?!')/g, ": &'a ");
|
|
205
|
+
const items = `page.${snake(itemsField ?? "")}`;
|
|
206
|
+
doc(writer, [`Every item of every ${name} page, fetched as you iterate: \`for item in client.${name}_all(…) { let item = item?; … }\`.`]);
|
|
207
|
+
if (operation.deprecated !== undefined) writer.line(`#[deprecated(note = ${str(operation.deprecated)})]`);
|
|
208
|
+
if (paginate.kind === "link") {
|
|
209
|
+
// The Link header names the next page: the same operation is called at that URL.
|
|
210
|
+
writer.line(`pub fn ${name}_all<'a>(${borrowed}) -> Pager<'a, ${rustType(item)}> {`).indent((fn) => {
|
|
211
|
+
const args = ["&options", ...(call === "" ? [] : [call])].join(", ");
|
|
212
|
+
fn.line("Pager::new(None, move |url: &Option<String>| {").indent((inner) => {
|
|
213
|
+
inner.line("let options = CallOptions { url: url.clone(), ..CallOptions::default() };");
|
|
214
|
+
inner.line(`self.raw().${name}(${args})`);
|
|
215
|
+
});
|
|
216
|
+
fn.line(`}, |_url: &Option<String>, page: RawResult<${resultType(operation)}>| {`).indent((inner) => {
|
|
217
|
+
inner.line('let next = next_link(page.response.header("link").as_deref());');
|
|
218
|
+
inner.line(`(page.data${itemsField === undefined ? "" : `.${snake(itemsField)}`}, next.map(Some))`);
|
|
219
|
+
});
|
|
220
|
+
fn.line("})");
|
|
221
|
+
});
|
|
222
|
+
writer.line("}").line();
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
writer.line(`pub fn ${name}_all<'a>(${borrowed}) -> Pager<'a, ${rustType(item)}> {`).indent((fn) => {
|
|
226
|
+
fn.line(`Pager::new(params.clone(), move |current: &${params}| self.${name}(${call.replace(/\bparams\b/, "current")}), |current: &${params}, page: ${resultType(operation)}| {`).indent((step) => {
|
|
227
|
+
const param = snake(paginate.param);
|
|
228
|
+
if (paginate.kind === "cursor") {
|
|
229
|
+
const next = fields.find((entry) => entry.name === paginate.next);
|
|
230
|
+
if (next === undefined) throw new Error(`operations.${operation.name}.paginate: no field ${paginate.next}`);
|
|
231
|
+
const read = `page.${snake(paginate.next)}`;
|
|
232
|
+
const cursor = next.optional && next.nullable ? `${read}.clone().flatten()` : next.optional || next.nullable ? `${read}.clone()` : `Some(${read}.clone())`;
|
|
233
|
+
step.line(`let next = match ${cursor} {`).indent((arms) => {
|
|
234
|
+
arms.line(`Some(cursor) if !cursor.is_empty() => Some(${params} { ${param}: Some(cursor), ..current.clone() }),`);
|
|
235
|
+
arms.line("_ => None,");
|
|
236
|
+
});
|
|
237
|
+
step.line("};");
|
|
238
|
+
} else {
|
|
239
|
+
step.line(`let count = ${items}.len() as i64;`);
|
|
240
|
+
const short = paginate.limit === undefined ? "" : ` || current.${snake(paginate.limit)}.map(|limit| count < limit).unwrap_or(false)`;
|
|
241
|
+
step.line(`let next = if count == 0${short} { None } else { Some(${params} { ${param}: Some(current.${param}.unwrap_or(0) + count), ..current.clone() }) };`);
|
|
242
|
+
}
|
|
243
|
+
step.line(`(${items}, next)`);
|
|
244
|
+
});
|
|
245
|
+
fn.line("})");
|
|
246
|
+
});
|
|
247
|
+
writer.line("}").line();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function configEntry(ir , name ) {
|
|
251
|
+
const middleware = ir.middlewares.find((candidate) => candidate.name === name);
|
|
252
|
+
if (middleware === undefined) throw new Error(`unknown middleware ${name}`);
|
|
253
|
+
const config = middleware.config.map((item) => `(${str(item.name)}.to_string(), options.${snake(item.name)}.to_json())`);
|
|
254
|
+
return `entry(${str(name)}, middleware::${rustName(name)}, vec![${config.join(", ")}])`;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function emitClient(writer , ir , sdk ) {
|
|
258
|
+
doc(writer, ["How a Client is configured; start from Options::default() and set what you need."]);
|
|
259
|
+
writer.line("#[derive(Clone, Default)]").line("pub struct Options {").indent((body) => {
|
|
260
|
+
configFields(ir).forEach((item) => {
|
|
261
|
+
doc(body, item.doc === undefined ? [] : [item.doc]);
|
|
262
|
+
body.line(`pub ${snake(item.name)}: ${fieldType({ type: item.type, optional: item.optional, nullable: false })},`);
|
|
263
|
+
});
|
|
264
|
+
doc(body, ["A key of SERVERS; DEFAULT_SERVER when None."]);
|
|
265
|
+
body.line("pub server: Option<String>,");
|
|
266
|
+
doc(body, ["Replaces the server's URL, e.g. for a proxy or a test server."]);
|
|
267
|
+
body.line("pub base_url: Option<String>,");
|
|
268
|
+
doc(body, ["Sends requests; HTTP/1.1 over std::net when None (http only: give a TLS transport for https)."]);
|
|
269
|
+
body.line("pub transport: Option<Arc<dyn Transport>>,");
|
|
270
|
+
doc(body, ["Limits each call; DEFAULT_TIMEOUT_MS when None."]);
|
|
271
|
+
body.line("pub timeout_ms: Option<i64>,");
|
|
272
|
+
doc(body, ["Runs after the SDK's own middleware, in order."]);
|
|
273
|
+
body.line("pub middleware: Vec<MiddlewareEntry>,");
|
|
274
|
+
doc(body, ["Receives every event middleware emits."]);
|
|
275
|
+
body.line("pub on_event: Option<EventListener>,");
|
|
276
|
+
doc(body, ["Measures time and waits; the system clock when None."]);
|
|
277
|
+
body.line("pub clock: Option<Arc<dyn Clock>>,");
|
|
278
|
+
doc(body, ["\"http://host:port\" of an HTTP proxy (default transport only)."]);
|
|
279
|
+
body.line("pub proxy: Option<String>,");
|
|
280
|
+
const versions = ir.apiVersions;
|
|
281
|
+
if (versions !== undefined) {
|
|
282
|
+
if (configFields(ir).some((item) => snake(item.name) === "api_version")) throw new Error("a middleware config field apiVersion collides with the api_version client option of apiVersions");
|
|
283
|
+
doc(body, [`The API version to use, sent as ${versions.header}: ${versions.values.join(", ")}. Defaults to ${versions.values.at(-1) ?? ""}, the newest.`]);
|
|
284
|
+
body.line("pub api_version: Option<String>,");
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
writer.line("}").line();
|
|
288
|
+
|
|
289
|
+
const opLevel = [...new Set(ir.operations.flatMap((operation) => operation.use))].sort();
|
|
290
|
+
doc(writer, [ir.doc ?? ir.name, "", "Thread-safe: build one and share it (it is cheap to clone)."]);
|
|
291
|
+
writer.line("#[derive(Clone)]").line("pub struct Client {").indent((body) => body.line("runtime: Runtime,")).line("}").line();
|
|
292
|
+
doc(writer, ["The same operations, returning the response too and taking per-call options."]);
|
|
293
|
+
writer.line("pub struct RawClient<'a> {").indent((body) => body.line("runtime: &'a Runtime,")).line("}").line();
|
|
294
|
+
|
|
295
|
+
writer.line("#[allow(deprecated)]").line("impl Client {").indent((body) => {
|
|
296
|
+
doc(body, ["Builds a client; fails for an unknown server."]);
|
|
297
|
+
body.line("pub fn new(options: Options) -> Result<Client, Error> {").indent((fn) => {
|
|
298
|
+
fn.line("let server = options.server.clone().unwrap_or_else(|| DEFAULT_SERVER.to_string());");
|
|
299
|
+
fn.line("let base_url = match &options.base_url {").indent((arms) => {
|
|
300
|
+
arms.line("Some(url) => url.clone(),");
|
|
301
|
+
arms.line(`None => SERVERS.iter().find(|(name, _)| *name == server).map(|(_, url)| url.to_string()).ok_or_else(|| Error::thrown(format!("unknown server {}", server)))?,`);
|
|
302
|
+
});
|
|
303
|
+
fn.line("};");
|
|
304
|
+
fn.line("let transport: Arc<dyn Transport> = match &options.transport {").indent((arms) => {
|
|
305
|
+
arms.line("Some(transport) => transport.clone(),");
|
|
306
|
+
arms.line("None => Arc::new(StdTransport { proxy: options.proxy.clone() }),");
|
|
307
|
+
});
|
|
308
|
+
fn.line("};");
|
|
309
|
+
fn.line("let clock: Arc<dyn Clock> = options.clock.clone().unwrap_or_else(|| Arc::new(SystemClock::new()));");
|
|
310
|
+
fn.line("let runtime = Runtime {").indent((fields) => {
|
|
311
|
+
fields.line("base_url,");
|
|
312
|
+
fields.line("transport,");
|
|
313
|
+
fields.line("clock: clock.clone(),");
|
|
314
|
+
fields.line("state: Arc::new(State::new(clock)),");
|
|
315
|
+
fields.line(`middleware: vec![${ir.use.map((name) => configEntry(ir, name)).join(", ")}],`);
|
|
316
|
+
fields.line(`registry: HashMap::from([${opLevel.map((name) => `(${str(name)}.to_string(), ${configEntry(ir, name)})`).join(", ")}]),`);
|
|
317
|
+
fields.line("user_middleware: options.middleware.clone(),");
|
|
318
|
+
fields.line("listeners: options.on_event.clone().into_iter().collect(),");
|
|
319
|
+
fields.line("timeout_ms: Some(options.timeout_ms.unwrap_or(DEFAULT_TIMEOUT_MS)),");
|
|
320
|
+
fields.line(`sdk: SdkInfo { name: ${str(sdk.name)}.to_string(), version: ${str(sdk.version)}.to_string(), language: "rust".to_string() },`);
|
|
321
|
+
const versions = ir.apiVersions;
|
|
322
|
+
fields.line(
|
|
323
|
+
versions === undefined
|
|
324
|
+
? "api_version: None,"
|
|
325
|
+
: `api_version: Some(ApiVersion { header: ${str(versions.header)}.to_string(), value: options.api_version.clone().unwrap_or_else(|| ${str(versions.values.at(-1) ?? "")}.to_string()), values: vec![${versions.values.map((value) => `${str(value)}.to_string()`).join(", ")}] }),`,
|
|
326
|
+
);
|
|
327
|
+
});
|
|
328
|
+
fn.line("};");
|
|
329
|
+
fn.line("Ok(Client { runtime })");
|
|
330
|
+
});
|
|
331
|
+
body.line("}").line();
|
|
332
|
+
doc(body, ["The operations that also return the response."]);
|
|
333
|
+
body.line("pub fn raw(&self) -> RawClient<'_> {").indent((fn) => fn.line("RawClient { runtime: &self.runtime }")).line("}").line();
|
|
334
|
+
ir.operations.forEach((operation) => {
|
|
335
|
+
emitMethod(body, operation);
|
|
336
|
+
if (operation.paginate !== undefined) emitIterator(body, ir, operation, operation.paginate);
|
|
337
|
+
if (operation.wait !== undefined) emitWait(body, ir, operation, operation.wait);
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
writer.line("}").line();
|
|
341
|
+
|
|
342
|
+
writer.line("#[allow(deprecated)]").line("impl<'a> RawClient<'a> {").indent((body) => ir.operations.forEach((operation) => emitRaw(body, ir, operation)));
|
|
343
|
+
writer.line("}").line();
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Method names a Client already has. */
|
|
347
|
+
const TAKEN = ["new", "raw", "clone"];
|
|
348
|
+
|
|
349
|
+
export function emitClientFile(ir , header , sdk ) {
|
|
350
|
+
ir.operations.forEach((operation) => {
|
|
351
|
+
if (TAKEN.includes(snake(operation.name))) throw new Error(`operation ${operation.name} would clash with the client's ${snake(operation.name)} method; rename the operation`);
|
|
352
|
+
});
|
|
353
|
+
const writer = rust().line(header).line("#![allow(unused_imports)]").line();
|
|
354
|
+
writer.line("use crate::middleware;");
|
|
355
|
+
writer.line("use crate::models::*;");
|
|
356
|
+
writer.line("use crate::runtime::models::*;");
|
|
357
|
+
writer.line("use crate::runtime::{call, entry, ApiVersion, Args, CallOptions, Clock, Decimal, Error, EventListener, EventStream, Json, Kind, MiddlewareEntry, MultipartForm, OperationSpec, Pager, RawResult, Response, Runtime, SdkInfo, State, StdTransport, SystemClock, ToJson, Transport};");
|
|
358
|
+
writer.line("use crate::runtime::pagination::next_link;");
|
|
359
|
+
writer.line("use crate::runtime::wait::wait_until;");
|
|
360
|
+
writer.line("use std::collections::{BTreeMap, HashMap};").line("use std::sync::Arc;").line();
|
|
361
|
+
|
|
362
|
+
doc(writer, ["The API's servers by name."]);
|
|
363
|
+
writer.line(`pub const SERVERS: &[(&str, &str)] = &[${ir.servers.map((server) => `(${str(server.name)}, ${str(server.url)})`).join(", ")}];`).line();
|
|
364
|
+
doc(writer, ["Used when Options::server is None."]);
|
|
365
|
+
writer.line(`pub const DEFAULT_SERVER: &str = ${str(ir.defaultServer)};`).line();
|
|
366
|
+
doc(writer, ["Limits a call when Options::timeout_ms is None."]);
|
|
367
|
+
writer.line("pub const DEFAULT_TIMEOUT_MS: i64 = 60000;").line();
|
|
368
|
+
|
|
369
|
+
const declared = [...new Set(ir.operations.flatMap((operation) => operation.errors.map((error) => error.name)))].sort();
|
|
370
|
+
doc(writer, ["Names of the declared errors, for Error::is, e.g. `error.is(errors::NOT_FOUND)`."]);
|
|
371
|
+
writer.line("pub mod errors {").indent((body) => declared.forEach((name) => body.line(`pub const ${constant(name)}: &str = ${str(name)};`))).line("}").line();
|
|
372
|
+
declared.forEach((name) =>
|
|
373
|
+
writer.line(`fn ${errorFactory(name)}(status: u16, body: Json, response: Response) -> Error {`).indent((fn) => fn.line(`Error::api_error(${str(name)}, status, body, response)`)).line("}").line(),
|
|
374
|
+
);
|
|
375
|
+
ir.operations.forEach((operation) => emitParams(writer, operation));
|
|
376
|
+
ir.operations.forEach((operation) => emitSpec(writer, operation));
|
|
377
|
+
emitClient(writer, ir, sdk);
|
|
378
|
+
return writer.toString();
|
|
379
|
+
}
|