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,264 @@
|
|
|
1
|
+
// OpenAPI schemas (3.0 and 3.1) as sdkloom type expressions: t.* calls, models and unions, declared before use.
|
|
2
|
+
|
|
3
|
+
import { key, pascal, str, unique } from "./names.ts";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export function isRecord(value ) {
|
|
9
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const SCHEMA_REF = "#/components/schemas/";
|
|
13
|
+
|
|
14
|
+
/** Where a type is used: inside a model (bytes are not allowed there) or as a whole body or result. */
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Turns schemas into sdkloom code. Component schemas that are objects or unions become named constants, emitted in
|
|
19
|
+
* dependency order (a cycle is broken with a warning: sdkloom definitions cannot refer to themselves yet).
|
|
20
|
+
*/
|
|
21
|
+
export class Schemas {
|
|
22
|
+
/** Declarations in the order they must appear. */
|
|
23
|
+
declarations = [];
|
|
24
|
+
warnings = [];
|
|
25
|
+
#components ;
|
|
26
|
+
#declared = new Map ();
|
|
27
|
+
#inProgress = new Set ();
|
|
28
|
+
#inlining = new Set ();
|
|
29
|
+
#taken = new Set (["model", "union", "t", "sdk", "get", "post", "put", "patch", "del", "page"]);
|
|
30
|
+
/** Component schemas used as variants of a discriminated union: their models leave the discriminator out. */
|
|
31
|
+
#variantTags = new Map ();
|
|
32
|
+
|
|
33
|
+
constructor(components ) {
|
|
34
|
+
this.#components = components;
|
|
35
|
+
for (const schema of Object.values(components)) {
|
|
36
|
+
if (!isRecord(schema)) continue;
|
|
37
|
+
const discriminator = schema["discriminator"];
|
|
38
|
+
const variants = schema["oneOf"] ?? schema["anyOf"];
|
|
39
|
+
if (!isRecord(discriminator) || typeof discriminator["propertyName"] !== "string" || !Array.isArray(variants)) continue;
|
|
40
|
+
for (const variant of variants) {
|
|
41
|
+
const ref = isRecord(variant) ? variant["$ref"] : undefined;
|
|
42
|
+
if (typeof ref === "string" && ref.startsWith(SCHEMA_REF)) this.#variantTags.set(ref.slice(SCHEMA_REF.length), discriminator["propertyName"]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#warn(message ) {
|
|
48
|
+
this.warnings.push(message);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The `{ doc: … }` options of a schema with a description, as code ("" without one). */
|
|
52
|
+
#doc(schema ) {
|
|
53
|
+
const text = typeof schema["description"] === "string" ? schema["description"] : typeof schema["title"] === "string" ? schema["title"] : undefined;
|
|
54
|
+
return text === undefined || text.trim() === "" ? "" : `{ doc: ${str(text.trim())} }`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A schema with "null" removed from its types, and whether null was allowed (3.0 nullable or 3.1 type arrays). */
|
|
58
|
+
#withoutNull(schema ) {
|
|
59
|
+
const type = schema["type"];
|
|
60
|
+
if (Array.isArray(type) && type.includes("null")) {
|
|
61
|
+
const rest = type.filter((entry) => entry !== "null");
|
|
62
|
+
return { schema: { ...schema, type: rest.length === 1 ? (rest[0] ?? null) : rest }, nullable: true };
|
|
63
|
+
}
|
|
64
|
+
const options = schema["oneOf"] ?? schema["anyOf"];
|
|
65
|
+
if (Array.isArray(options) && options.length === 2 && options.some((option) => isRecord(option) && option["type"] === "null")) {
|
|
66
|
+
const other = options.find((option) => !(isRecord(option) && option["type"] === "null"));
|
|
67
|
+
if (isRecord(other)) return { schema: { ...other, ...(schema["description"] === undefined ? {} : { description: schema["description"] }) }, nullable: true };
|
|
68
|
+
}
|
|
69
|
+
return { schema, nullable: schema["nullable"] === true };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The code of a type: `t.string()`, `t.list(Pet)`, a model constant, … `hint` names inline models. */
|
|
73
|
+
type(input , hint , place = "field") {
|
|
74
|
+
if (!isRecord(input)) {
|
|
75
|
+
this.#warn(`${hint}: no schema; used a map of strings`);
|
|
76
|
+
return "t.map(t.string())";
|
|
77
|
+
}
|
|
78
|
+
const { schema, nullable } = this.#withoutNull(input);
|
|
79
|
+
const code = this.#nonNull(schema, hint, place);
|
|
80
|
+
return nullable ? `t.nullable(${code})` : code;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#nonNull(schema , hint , place ) {
|
|
84
|
+
const ref = schema["$ref"];
|
|
85
|
+
if (typeof ref === "string") return this.#ref(ref, hint, place);
|
|
86
|
+
const doc = this.#doc(schema);
|
|
87
|
+
if (Array.isArray(schema["allOf"])) {
|
|
88
|
+
const single = this.#singlePart(schema);
|
|
89
|
+
if (single !== undefined) return this.type(single, hint, place);
|
|
90
|
+
return this.#declareInline(hint, (constant) => this.#model(constant, this.#merge(schema), doc));
|
|
91
|
+
}
|
|
92
|
+
if (Array.isArray(schema["oneOf"]) || Array.isArray(schema["anyOf"])) return this.#union(schema, hint, place);
|
|
93
|
+
if (Array.isArray(schema["enum"])) {
|
|
94
|
+
const values = schema["enum"].filter((value) => typeof value === "string");
|
|
95
|
+
if (values.length === 0) {
|
|
96
|
+
this.#warn(`${hint}: only string enums are supported; used the base type`);
|
|
97
|
+
return this.#nonNull({ ...schema, enum: null }, hint, place);
|
|
98
|
+
}
|
|
99
|
+
return `t.enum([${values.map(str).join(", ")}]${doc === "" ? "" : `, ${doc}`})`;
|
|
100
|
+
}
|
|
101
|
+
const type = Array.isArray(schema["type"]) ? schema["type"][0] : schema["type"];
|
|
102
|
+
switch (type) {
|
|
103
|
+
case "string":
|
|
104
|
+
if (schema["format"] === "date-time") return `t.datetime(${doc})`;
|
|
105
|
+
if (schema["format"] === "binary") {
|
|
106
|
+
if (place === "body") return `t.bytes(${doc})`;
|
|
107
|
+
this.#warn(`${hint}: binary data inside a model is not supported; used a string (send files as multipart)`);
|
|
108
|
+
}
|
|
109
|
+
return `t.string(${doc})`;
|
|
110
|
+
case "integer":
|
|
111
|
+
return `t.int(${doc})`;
|
|
112
|
+
case "number":
|
|
113
|
+
return `t.number(${doc})`;
|
|
114
|
+
case "boolean":
|
|
115
|
+
return `t.bool(${doc})`;
|
|
116
|
+
case "array":
|
|
117
|
+
return `t.list(${this.type(schema["items"] ?? undefined, `${hint}Item`)}${doc === "" ? "" : `, ${doc}`})`;
|
|
118
|
+
case "object":
|
|
119
|
+
case undefined: {
|
|
120
|
+
const properties = schema["properties"];
|
|
121
|
+
if (isRecord(properties) && Object.keys(properties).length > 0) return this.#declareInline(hint, (constant) => this.#model(constant, schema, doc));
|
|
122
|
+
const extra = schema["additionalProperties"];
|
|
123
|
+
if (isRecord(extra)) return `t.map(${this.type(extra, `${hint}Value`)}${doc === "" ? "" : `, ${doc}`})`;
|
|
124
|
+
this.#warn(`${hint}: a free-form ${type === undefined ? "value" : "object"}; used a map of strings`);
|
|
125
|
+
return `t.map(t.string()${doc === "" ? "" : `, ${doc}`})`;
|
|
126
|
+
}
|
|
127
|
+
default:
|
|
128
|
+
this.#warn(`${hint}: unsupported type ${JSON.stringify(type)}; used a string`);
|
|
129
|
+
return `t.string(${doc})`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** A $ref: a component that is an object or union becomes its constant, anything else is inlined. */
|
|
134
|
+
#ref(ref , hint , place ) {
|
|
135
|
+
if (!ref.startsWith(SCHEMA_REF)) {
|
|
136
|
+
this.#warn(`${hint}: ${ref} is not a component schema; used a map of strings`);
|
|
137
|
+
return "t.map(t.string())";
|
|
138
|
+
}
|
|
139
|
+
const name = ref.slice(SCHEMA_REF.length);
|
|
140
|
+
const target = this.#components[name];
|
|
141
|
+
if (!isRecord(target)) {
|
|
142
|
+
this.#warn(`${hint}: ${ref} does not exist; used a map of strings`);
|
|
143
|
+
return "t.map(t.string())";
|
|
144
|
+
}
|
|
145
|
+
const { schema, nullable } = this.#withoutNull(target);
|
|
146
|
+
const union = (Array.isArray(schema["oneOf"]) || Array.isArray(schema["anyOf"])) && isRecord(schema["discriminator"]);
|
|
147
|
+
const named = isRecord(schema["properties"]) || (Array.isArray(schema["allOf"]) && this.#singlePart(schema) === undefined) || union;
|
|
148
|
+
if (!named) {
|
|
149
|
+
// Inlined (a list, a map, an enum…): a schema that contains itself cannot be inlined.
|
|
150
|
+
if (this.#inlining.has(name)) {
|
|
151
|
+
this.#warn(`${hint}: ${name} refers back to itself; sdkloom definitions cannot be recursive yet, so this reference is a map of strings`);
|
|
152
|
+
return "t.map(t.string())";
|
|
153
|
+
}
|
|
154
|
+
this.#inlining.add(name);
|
|
155
|
+
const code = this.type(target, pascal(name), place);
|
|
156
|
+
this.#inlining.delete(name);
|
|
157
|
+
return code;
|
|
158
|
+
}
|
|
159
|
+
const constant = this.#declareComponent(name, schema, hint);
|
|
160
|
+
return nullable ? `t.nullable(${constant})` : constant;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
#declareComponent(name , schema , hint ) {
|
|
164
|
+
const existing = this.#declared.get(name);
|
|
165
|
+
if (existing !== undefined) return existing;
|
|
166
|
+
if (this.#inProgress.has(name)) {
|
|
167
|
+
this.#warn(`${hint}: ${name} refers back to itself; sdkloom definitions cannot be recursive yet, so this reference is a map of strings`);
|
|
168
|
+
return "t.map(t.string())";
|
|
169
|
+
}
|
|
170
|
+
this.#inProgress.add(name);
|
|
171
|
+
const constant = unique(pascal(name), this.#taken);
|
|
172
|
+
const doc = this.#doc(schema);
|
|
173
|
+
const code =
|
|
174
|
+
Array.isArray(schema["oneOf"]) || Array.isArray(schema["anyOf"])
|
|
175
|
+
? this.#unionDeclaration(constant, schema, doc)
|
|
176
|
+
: this.#model(constant, Array.isArray(schema["allOf"]) ? this.#merge(schema) : schema, doc, this.#variantTags.get(name));
|
|
177
|
+
this.declarations.push(`const ${constant} = ${code};`);
|
|
178
|
+
this.#inProgress.delete(name);
|
|
179
|
+
this.#declared.set(name, constant);
|
|
180
|
+
return constant;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
#declareInline(hint , build ) {
|
|
184
|
+
const constant = unique(pascal(hint), this.#taken);
|
|
185
|
+
this.declarations.push(`const ${constant} = ${build(constant)};`);
|
|
186
|
+
return constant;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** An allOf whose parts declare no properties (one $ref to an enum, say) is that part, not an empty model. */
|
|
190
|
+
#singlePart(schema ) {
|
|
191
|
+
const parts = schema["allOf"];
|
|
192
|
+
if (!Array.isArray(parts) || Object.keys(this.#merge(schema)["properties"] ).length > 0) return undefined;
|
|
193
|
+
if (parts.length !== 1) this.#warn(`an allOf without properties in any part is read as its first part`);
|
|
194
|
+
const first = parts[0];
|
|
195
|
+
return isRecord(first) ? { ...first, ...(schema["description"] === undefined ? {} : { description: schema["description"] }) } : undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** allOf: the properties and required lists of every part (refs resolved), in order. */
|
|
199
|
+
#merge(schema ) {
|
|
200
|
+
const properties = {};
|
|
201
|
+
const required = [];
|
|
202
|
+
const add = (part ) => {
|
|
203
|
+
if (!isRecord(part)) return;
|
|
204
|
+
const ref = part["$ref"];
|
|
205
|
+
if (typeof ref === "string" && ref.startsWith(SCHEMA_REF)) {
|
|
206
|
+
add(this.#components[ref.slice(SCHEMA_REF.length)] ?? null);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (Array.isArray(part["allOf"])) part["allOf"].forEach(add);
|
|
210
|
+
if (isRecord(part["properties"])) Object.assign(properties, part["properties"]);
|
|
211
|
+
if (Array.isArray(part["required"])) required.push(...part["required"].filter((entry) => typeof entry === "string"));
|
|
212
|
+
};
|
|
213
|
+
add(schema);
|
|
214
|
+
return { ...schema, allOf: null, properties, required };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** `model("Name", { … })`: required properties as they are, the others optional. */
|
|
218
|
+
#model(constant , schema , doc , without ) {
|
|
219
|
+
const properties = isRecord(schema["properties"]) ? schema["properties"] : {};
|
|
220
|
+
const required = new Set(Array.isArray(schema["required"]) ? schema["required"].filter((entry) => typeof entry === "string") : []);
|
|
221
|
+
const fields = Object.entries(properties)
|
|
222
|
+
.filter(([name]) => name !== without)
|
|
223
|
+
.map(([name, property]) => {
|
|
224
|
+
const type = this.type(property, `${constant}${pascal(name)}`);
|
|
225
|
+
return `${key(name)}: ${required.has(name) ? type : `t.optional(${type})`}`;
|
|
226
|
+
});
|
|
227
|
+
return `model(${str(constant)}, { ${fields.join(", ")} }${doc === "" ? "" : `, ${doc}`})`;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** oneOf/anyOf with a discriminator over component models becomes a union; anything else falls back with a warning. */
|
|
231
|
+
#union(schema , hint , place ) {
|
|
232
|
+
const discriminator = schema["discriminator"];
|
|
233
|
+
if (isRecord(discriminator) && typeof discriminator["propertyName"] === "string") {
|
|
234
|
+
return this.#declareInline(hint, (constant) => this.#unionDeclaration(constant, schema, this.#doc(schema)));
|
|
235
|
+
}
|
|
236
|
+
const options = (schema["oneOf"] ?? schema["anyOf"]) ;
|
|
237
|
+
this.#warn(`${hint}: oneOf/anyOf without a discriminator is not supported; used its first option`);
|
|
238
|
+
return this.type(options[0] ?? null, hint, place);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
#unionDeclaration(constant , schema , doc ) {
|
|
242
|
+
const discriminator = schema["discriminator"] ;
|
|
243
|
+
const property = discriminator["propertyName"] ;
|
|
244
|
+
const mapping = isRecord(discriminator["mapping"]) ? discriminator["mapping"] : {};
|
|
245
|
+
// Mapping values are refs or bare schema names ("dog": "Dog"); the first tag for a schema wins.
|
|
246
|
+
const tagOf = new Map ();
|
|
247
|
+
for (const [tag, ref] of Object.entries(mapping)) {
|
|
248
|
+
const full = String(ref).startsWith("#/") ? String(ref) : `${SCHEMA_REF}${String(ref)}`;
|
|
249
|
+
if (!tagOf.has(full)) tagOf.set(full, tag);
|
|
250
|
+
}
|
|
251
|
+
const variants = [];
|
|
252
|
+
for (const variant of (schema["oneOf"] ?? schema["anyOf"]) ) {
|
|
253
|
+
const ref = isRecord(variant) ? variant["$ref"] : undefined;
|
|
254
|
+
if (typeof ref !== "string" || !ref.startsWith(SCHEMA_REF)) {
|
|
255
|
+
this.#warn(`${constant}: a union variant must be a component schema ($ref); left one out`);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const name = ref.slice(SCHEMA_REF.length);
|
|
259
|
+
this.#variantTags.set(name, property);
|
|
260
|
+
variants.push(`${key(tagOf.get(ref) ?? name)}: ${this.#ref(ref, constant, "field")}`);
|
|
261
|
+
}
|
|
262
|
+
return `union(${str(constant)}, ${str(property)}, { ${variants.join(", ")} }${doc === "" ? "" : `, ${doc}`})`;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Deterministic archives without dependencies: ustar tar (gzip via node:zlib) for npm, zip (deflate) for wheels and jars.
|
|
2
|
+
// Entries are sorted and every timestamp is fixed, so the same files always give the same bytes.
|
|
3
|
+
|
|
4
|
+
import { crc32, deflateRawSync, gzipSync } from "node:zlib";
|
|
5
|
+
|
|
6
|
+
const BLOCK = 512;
|
|
7
|
+
/** 1985-10-26T08:15:00Z, the fixed time npm itself writes into tarballs. */
|
|
8
|
+
const TAR_MTIME = 499162500;
|
|
9
|
+
const encoder = new TextEncoder();
|
|
10
|
+
|
|
11
|
+
function octal(value , length ) {
|
|
12
|
+
return value.toString(8).padStart(length - 1, "0");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function writeString(target , offset , length , value ) {
|
|
16
|
+
const bytes = encoder.encode(value);
|
|
17
|
+
if (bytes.length > length) throw new Error(`"${value}" does not fit in a ${length}-byte tar field`);
|
|
18
|
+
target.set(bytes, offset);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Splits a path into ustar's prefix (155 bytes) and name (100 bytes). */
|
|
22
|
+
function splitPath(path ) {
|
|
23
|
+
if (encoder.encode(path).length <= 100) return { prefix: "", name: path };
|
|
24
|
+
for (let index = path.indexOf("/"); index !== -1; index = path.indexOf("/", index + 1)) {
|
|
25
|
+
const prefix = path.slice(0, index);
|
|
26
|
+
const name = path.slice(index + 1);
|
|
27
|
+
if (encoder.encode(prefix).length <= 155 && encoder.encode(name).length <= 100) return { prefix, name };
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`path is too long for a tar archive: ${path}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function tarHeader(path , size ) {
|
|
33
|
+
const header = new Uint8Array(BLOCK);
|
|
34
|
+
const { prefix, name } = splitPath(path);
|
|
35
|
+
writeString(header, 0, 100, name);
|
|
36
|
+
writeString(header, 100, 8, octal(0o644, 8));
|
|
37
|
+
writeString(header, 108, 8, octal(0, 8));
|
|
38
|
+
writeString(header, 116, 8, octal(0, 8));
|
|
39
|
+
writeString(header, 124, 12, octal(size, 12));
|
|
40
|
+
writeString(header, 136, 12, octal(TAR_MTIME, 12));
|
|
41
|
+
header.fill(0x20, 148, 156);
|
|
42
|
+
header[156] = 0x30;
|
|
43
|
+
writeString(header, 257, 6, "ustar");
|
|
44
|
+
writeString(header, 263, 2, "00");
|
|
45
|
+
writeString(header, 345, 155, prefix);
|
|
46
|
+
const checksum = header.reduce((sum, byte) => sum + byte, 0);
|
|
47
|
+
writeString(header, 148, 8, `${octal(checksum, 7)}\0`);
|
|
48
|
+
return header;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function concat(parts ) {
|
|
52
|
+
const result = new Uint8Array(parts.reduce((size, part) => size + part.length, 0));
|
|
53
|
+
let offset = 0;
|
|
54
|
+
for (const part of parts) {
|
|
55
|
+
result.set(part, offset);
|
|
56
|
+
offset += part.length;
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function sorted(files ) {
|
|
62
|
+
return [...files].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A gzip-compressed ustar archive. */
|
|
66
|
+
export function tarGz(files ) {
|
|
67
|
+
const parts = [];
|
|
68
|
+
for (const [path, content] of sorted(files)) {
|
|
69
|
+
parts.push(tarHeader(path, content.length), content, new Uint8Array((BLOCK - (content.length % BLOCK)) % BLOCK));
|
|
70
|
+
}
|
|
71
|
+
parts.push(new Uint8Array(BLOCK * 2));
|
|
72
|
+
return gzipSync(concat(parts), { level: 9 });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function u16(value ) {
|
|
76
|
+
return new Uint8Array([value & 0xff, (value >>> 8) & 0xff]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function u32(value ) {
|
|
80
|
+
return new Uint8Array([value & 0xff, (value >>> 8) & 0xff, (value >>> 16) & 0xff, (value >>> 24) & 0xff]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 1980-01-01 00:00, the earliest DOS date, as zip time and date fields. */
|
|
84
|
+
const DOS_TIME = 0;
|
|
85
|
+
const DOS_DATE = (0 << 9) | (1 << 5) | 1;
|
|
86
|
+
const UTF8_FLAG = 0x0800;
|
|
87
|
+
|
|
88
|
+
/** A deflate zip archive (the format of wheels and jars). */
|
|
89
|
+
export function zip(files ) {
|
|
90
|
+
const locals = [];
|
|
91
|
+
const central = [];
|
|
92
|
+
let offset = 0;
|
|
93
|
+
for (const [path, content] of sorted(files)) {
|
|
94
|
+
const name = encoder.encode(path);
|
|
95
|
+
const compressed = deflateRawSync(content, { level: 9 });
|
|
96
|
+
const crc = crc32(content) >>> 0;
|
|
97
|
+
const common = [u16(UTF8_FLAG), u16(8), u16(DOS_TIME), u16(DOS_DATE), u32(crc), u32(compressed.length), u32(content.length), u16(name.length), u16(0)];
|
|
98
|
+
const local = concat([u32(0x04034b50), u16(20), ...common, name, compressed]);
|
|
99
|
+
central.push(concat([u32(0x02014b50), u16(20), u16(20), ...common, u16(0), u16(0), u16(0), u32(0o100644 << 16), u32(offset), name]));
|
|
100
|
+
locals.push(local);
|
|
101
|
+
offset += local.length;
|
|
102
|
+
}
|
|
103
|
+
const directory = concat(central);
|
|
104
|
+
const end = concat([u32(0x06054b50), u16(0), u16(0), u16(central.length), u16(central.length), u32(directory.length), u32(offset), u16(0)]);
|
|
105
|
+
return concat([...locals, directory, end]);
|
|
106
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// A .crate in the layout `cargo package` produces (https://doc.rust-lang.org/cargo/commands/cargo-package.html): a
|
|
2
|
+
// gzipped tar with every file under "<name>-<version>/", and the metadata crates.io reads from the publish request.
|
|
3
|
+
|
|
4
|
+
import { tarGz } from "./archive.ts";
|
|
5
|
+
import { missingFields, text, } from "./metadata.ts";
|
|
6
|
+
|
|
7
|
+
const PACKAGE_KEYS = [
|
|
8
|
+
["homepage", "homepage"],
|
|
9
|
+
["repository", "repository"],
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
/** A TOML basic string: JSON's escapes are valid TOML, plus DEL; lone surrogates cannot be written and are replaced. */
|
|
13
|
+
const toml = (value ) => JSON.stringify(value.toWellFormed()).replaceAll("\u007f", "\\u007F");
|
|
14
|
+
|
|
15
|
+
/** Cargo.toml with the registry metadata (description, license, homepage, repository, authors) filled in. */
|
|
16
|
+
export function crateManifest(cargoToml , metadata ) {
|
|
17
|
+
const lines = cargoToml.split("\n");
|
|
18
|
+
const set = (key , value ) => {
|
|
19
|
+
const index = lines.findIndex((line) => line.startsWith(`${key} = `));
|
|
20
|
+
if (index >= 0) lines[index] = `${key} = ${value}`;
|
|
21
|
+
else lines.splice(lines.indexOf("[dependencies]") - 1, 0, `${key} = ${value}`);
|
|
22
|
+
};
|
|
23
|
+
if (metadata.description !== undefined) set("description", toml(metadata.description));
|
|
24
|
+
if (metadata.license !== undefined) set("license", toml(metadata.license));
|
|
25
|
+
PACKAGE_KEYS.forEach(([field, key]) => {
|
|
26
|
+
const value = metadata[field];
|
|
27
|
+
if (typeof value === "string") set(key, toml(value));
|
|
28
|
+
});
|
|
29
|
+
if (metadata.authors !== undefined && metadata.authors.length > 0) set("authors", `[${metadata.authors.map(toml).join(", ")}]`);
|
|
30
|
+
return lines.join("\n");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function rustCrate(files , name , version , metadata ) {
|
|
34
|
+
const prefix = `${name}-${version}/`;
|
|
35
|
+
const entries = new Map(
|
|
36
|
+
[...files].map(([path, content]) => [`${prefix}${path}`, text(path === "Cargo.toml" ? crateManifest(content, metadata) : content)]),
|
|
37
|
+
);
|
|
38
|
+
return { fileName: `${name}-${version}.crate`, bytes: tarGz(entries), contents: [...entries.keys()].sort(), missing: missingFields(metadata, ["description", "license"]) };
|
|
39
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// A Go module zip in the layout the module proxy serves (https://go.dev/ref/mod#zip-files): every file under
|
|
2
|
+
// "<module>@v<version>/". Go modules are published by tagging the repository; this zip is what the proxy will serve.
|
|
3
|
+
|
|
4
|
+
import { zip } from "./archive.ts";
|
|
5
|
+
import { text, } from "./metadata.ts";
|
|
6
|
+
|
|
7
|
+
export function goModule(files , module , version ) {
|
|
8
|
+
const prefix = `${module}@v${version}/`;
|
|
9
|
+
const entries = new Map([...files].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([path, content]) => [`${prefix}${path}`, text(content)]));
|
|
10
|
+
return { fileName: `v${version}.zip`, bytes: zip(entries), contents: [...entries.keys()], missing: [] };
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { tarGz, zip } from "./archive.ts";
|
|
2
|
+
export { crateManifest, rustCrate } from "./crate.ts";
|
|
3
|
+
export { goModule } from "./gomodule.ts";
|
|
4
|
+
export { filesToSign, mavenBundle, mavenFiles, publishablePom, } from "./maven.ts";
|
|
5
|
+
export { missingFields, } from "./metadata.ts";
|
|
6
|
+
export { npmPackage, rewriteImports, tarballName, toJavaScript } from "./npm.ts";
|
|
7
|
+
export { nugetPackage, nuspec, } from "./nuget.ts";
|
|
8
|
+
export { cycloneDx, purl, } from "./sbom.ts";
|
|
9
|
+
export { pythonWheel, wheelName, } from "./wheel.ts";
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// A Maven Central bundle: pom, jar, sources jar and javadoc jar under the repository layout, each with md5 and sha1
|
|
2
|
+
// checksums (and .asc signatures when given), zipped the way the Central Portal upload API expects.
|
|
3
|
+
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { zip } from "./archive.ts";
|
|
6
|
+
import { missingFields, text, } from "./metadata.ts";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function xml(value ) {
|
|
25
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Adds what Central requires (url, licenses, developers, scm) to the generated pom. */
|
|
29
|
+
export function publishablePom(pom , artifactId , metadata ) {
|
|
30
|
+
const extra = [
|
|
31
|
+
` <name>${xml(artifactId)}</name>`,
|
|
32
|
+
...(metadata.homepage === undefined ? [] : [` <url>${xml(metadata.homepage)}</url>`]),
|
|
33
|
+
...(metadata.license === undefined ? [] : [" <licenses>", " <license>", ` <name>${xml(metadata.license)}</name>`, " </license>", " </licenses>"]),
|
|
34
|
+
...(metadata.authors === undefined || metadata.authors.length === 0
|
|
35
|
+
? []
|
|
36
|
+
: [" <developers>", ...metadata.authors.flatMap((author) => [" <developer>", ` <name>${xml(author)}</name>`, " </developer>"]), " </developers>"]),
|
|
37
|
+
...(metadata.repository === undefined ? [] : [" <scm>", ` <url>${xml(metadata.repository)}</url>`, ` <connection>scm:git:${xml(metadata.repository)}</connection>`, " </scm>"]),
|
|
38
|
+
];
|
|
39
|
+
return pom.replace(" <packaging>jar</packaging>", [" <packaging>jar</packaging>", ...extra].join("\n"));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function jar(entries , javaPackage ) {
|
|
43
|
+
const manifest = `Manifest-Version: 1.0\r\nCreated-By: sdkloom\r\nAutomatic-Module-Name: ${javaPackage}\r\n\r\n`;
|
|
44
|
+
return zip(new Map([["META-INF/MANIFEST.MF", text(manifest)], ...entries]));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const hex = (algorithm , content ) => createHash(algorithm).update(content).digest("hex");
|
|
48
|
+
|
|
49
|
+
/** The four files Central needs, by file name; sign these (deterministic, so signing before bundling is safe). */
|
|
50
|
+
export function mavenFiles(input , metadata ) {
|
|
51
|
+
const name = `${input.artifactId}-${input.version}`;
|
|
52
|
+
return new Map ([
|
|
53
|
+
[`${name}.pom`, text(publishablePom(input.pom, input.artifactId, metadata))],
|
|
54
|
+
[`${name}.jar`, jar(input.classes, input.javaPackage)],
|
|
55
|
+
[`${name}-sources.jar`, jar(new Map([...input.sources].map(([path, source]) => [path, text(source)])), input.javaPackage)],
|
|
56
|
+
[`${name}-javadoc.jar`, jar(input.javadoc, input.javaPackage)],
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function mavenBundle(input , metadata ) {
|
|
61
|
+
const base = `${input.groupId.replaceAll(".", "/")}/${input.artifactId}/${input.version}`;
|
|
62
|
+
const name = `${input.artifactId}-${input.version}`;
|
|
63
|
+
const files = mavenFiles(input, metadata);
|
|
64
|
+
const entries = new Map ();
|
|
65
|
+
for (const [file, content] of files) {
|
|
66
|
+
entries.set(`${base}/${file}`, content);
|
|
67
|
+
entries.set(`${base}/${file}.md5`, text(hex("md5", content)));
|
|
68
|
+
entries.set(`${base}/${file}.sha1`, text(hex("sha1", content)));
|
|
69
|
+
const signature = input.signatures?.get(file);
|
|
70
|
+
if (signature !== undefined) entries.set(`${base}/${file}.asc`, text(signature));
|
|
71
|
+
}
|
|
72
|
+
const unsigned = input.signatures === undefined || [...files.keys()].some((file) => !input.signatures?.has(file));
|
|
73
|
+
return {
|
|
74
|
+
fileName: `${name}-bundle.zip`,
|
|
75
|
+
bytes: zip(entries),
|
|
76
|
+
contents: [...entries.keys()].sort(),
|
|
77
|
+
missing: [...missingFields(metadata, ["license", "homepage", "repository", "authors"]), ...(unsigned ? ["signatures"] : [])],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The files Central wants signed, in the bundle's naming. */
|
|
82
|
+
export function filesToSign(input ) {
|
|
83
|
+
const name = `${input.artifactId}-${input.version}`;
|
|
84
|
+
return [`${name}.pom`, `${name}.jar`, `${name}-sources.jar`, `${name}-javadoc.jar`];
|
|
85
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// What registries show about a package, from sdkloom.config.ts. Maven Central rejects a pom without url, license,
|
|
2
|
+
// developers and scm, so missing fields are reported before anything is uploaded.
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export const text = (value ) => new TextEncoder().encode(value);
|
|
28
|
+
|
|
29
|
+
export function missingFields(metadata , required ) {
|
|
30
|
+
return required.filter((key) => {
|
|
31
|
+
const value = metadata[key];
|
|
32
|
+
return value === undefined || (Array.isArray(value) && value.length === 0);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// An npm tarball from the generated TypeScript SDK. Node does not strip types inside node_modules, so the package
|
|
2
|
+
// ships JavaScript (types stripped with Node's own stripTypeScriptTypes) next to the TypeScript sources, which serve
|
|
3
|
+
// as the type declarations. Relative imports are rewritten from .ts to .js in both.
|
|
4
|
+
|
|
5
|
+
import { stripTypeScriptTypes } from "node:module";
|
|
6
|
+
import { tarGz } from "./archive.ts";
|
|
7
|
+
import { missingFields, text, } from "./metadata.ts";
|
|
8
|
+
|
|
9
|
+
function stripTypes(source ) {
|
|
10
|
+
const original = process.emitWarning;
|
|
11
|
+
process.emitWarning = () => undefined;
|
|
12
|
+
try {
|
|
13
|
+
return stripTypeScriptTypes(source, { mode: "strip" });
|
|
14
|
+
} finally {
|
|
15
|
+
process.emitWarning = original;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** from "./runtime/http.ts" → from "./runtime/http.js" (relative specifiers only). */
|
|
20
|
+
export function rewriteImports(source ) {
|
|
21
|
+
return source.replace(/((?:from|import)\s*\(?\s*["'])(\.{1,2}\/[^"']+)\.ts(["'])/g, "$1$2.js$3");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The TypeScript SDK as plain JavaScript: every .ts file stripped of types with its imports pointing at .js. */
|
|
25
|
+
export function toJavaScript(files ) {
|
|
26
|
+
const result = new Map ();
|
|
27
|
+
for (const [path, content] of files) {
|
|
28
|
+
if (path.endsWith(".ts")) result.set(path.replace(/\.ts$/, ".js"), stripTypes(rewriteImports(content)));
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** "@acme/payments" → "acme-payments-1.2.0.tgz", the name npm pack gives. */
|
|
34
|
+
export function tarballName(name , version ) {
|
|
35
|
+
return `${name.replace(/^@/, "").replace("/", "-")}-${version}.tgz`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function npmPackage(files , metadata ) {
|
|
39
|
+
const manifestText = files.get("package.json");
|
|
40
|
+
if (manifestText === undefined) throw new Error("the TypeScript SDK has no package.json");
|
|
41
|
+
const manifest = JSON.parse(manifestText) ;
|
|
42
|
+
const exportsField = Object.fromEntries(
|
|
43
|
+
Object.entries(manifest.exports).map(([key, target]) => [key, { types: target, default: target.replace(/\.ts$/, ".js") }]),
|
|
44
|
+
);
|
|
45
|
+
const published = {
|
|
46
|
+
...manifest,
|
|
47
|
+
exports: exportsField,
|
|
48
|
+
...(metadata.license === undefined ? {} : { license: metadata.license }),
|
|
49
|
+
...(metadata.homepage === undefined ? {} : { homepage: metadata.homepage }),
|
|
50
|
+
...(metadata.repository === undefined ? {} : { repository: { type: "git", url: metadata.repository } }),
|
|
51
|
+
...(metadata.authors === undefined || metadata.authors.length === 0 ? {} : { author: metadata.authors[0] }),
|
|
52
|
+
};
|
|
53
|
+
const entries = new Map ([["package/package.json", text(`${JSON.stringify(published, null, 2)}\n`)]]);
|
|
54
|
+
for (const [path, content] of files) {
|
|
55
|
+
if (path === "package.json") continue;
|
|
56
|
+
if (path.endsWith(".ts")) {
|
|
57
|
+
const rewritten = rewriteImports(content);
|
|
58
|
+
entries.set(`package/${path}`, text(rewritten));
|
|
59
|
+
entries.set(`package/${path.replace(/\.ts$/, ".js")}`, text(stripTypes(rewritten)));
|
|
60
|
+
} else {
|
|
61
|
+
entries.set(`package/${path}`, text(content));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
fileName: tarballName(manifest.name, manifest.version),
|
|
66
|
+
bytes: tarGz(entries),
|
|
67
|
+
contents: [...entries.keys()].sort(),
|
|
68
|
+
missing: missingFields(metadata, ["license", "repository"]),
|
|
69
|
+
manifest: published,
|
|
70
|
+
};
|
|
71
|
+
}
|