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,527 @@
|
|
|
1
|
+
// sdkloom Go kit: decoding and encoding JSON values.
|
|
2
|
+
package sdkruntime
|
|
3
|
+
|
|
4
|
+
import (
|
|
5
|
+
"bytes"
|
|
6
|
+
"encoding/json"
|
|
7
|
+
"fmt"
|
|
8
|
+
"io"
|
|
9
|
+
"math"
|
|
10
|
+
"regexp"
|
|
11
|
+
"sort"
|
|
12
|
+
"strconv"
|
|
13
|
+
"strings"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
// @block models.decode
|
|
17
|
+
// @summary Checks decoded JSON against the expected type; keeps object fields and enum values it does not know. Absent optional fields are unset, null is nil. Numbers stay exact until a type is chosen. Null for an optional field that cannot be null reads as absent: many servers send null for a field they leave out.
|
|
18
|
+
// @versions >=1.18
|
|
19
|
+
// @source [1] https://www.rfc-editor.org/rfc/rfc8259#section-4
|
|
20
|
+
// @quote [1] "An object structure is represented as a pair of curly brackets surrounding zero or more name/value pairs (or members)."
|
|
21
|
+
// @source [2] https://pkg.go.dev/encoding/json
|
|
22
|
+
// @quote [2] "UseNumber causes the Decoder to unmarshal a number into an interface value as a Number instead of as a float64."
|
|
23
|
+
// @retrieved 2026-12-05
|
|
24
|
+
// @tests tests/json_test.go
|
|
25
|
+
// @requirement SDKL-JSON-001
|
|
26
|
+
// @requirement SDKL-JSON-002
|
|
27
|
+
// @requirement SDKL-JSON-003
|
|
28
|
+
|
|
29
|
+
// Opt holds a value that may be absent, e.g. an optional field or parameter. The zero value is absent.
|
|
30
|
+
type Opt[T any] struct {
|
|
31
|
+
Value T
|
|
32
|
+
Set bool
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Some is a present value.
|
|
36
|
+
func Some[T any](value T) Opt[T] {
|
|
37
|
+
return Opt[T]{Value: value, Set: true}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Get returns the value and whether it is present.
|
|
41
|
+
func (o Opt[T]) Get() (T, bool) {
|
|
42
|
+
return o.Value, o.Set
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Or returns the value, or fallback when absent.
|
|
46
|
+
func (o Opt[T]) Or(fallback T) T {
|
|
47
|
+
if o.Set {
|
|
48
|
+
return o.Value
|
|
49
|
+
}
|
|
50
|
+
return fallback
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Ptr returns a pointer to value, for nullable fields.
|
|
54
|
+
func Ptr[T any](value T) *T {
|
|
55
|
+
return &value
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Decimal is an exact decimal number in plain notation, e.g. "10.50". It travels as a JSON string.
|
|
59
|
+
type Decimal string
|
|
60
|
+
|
|
61
|
+
// DecodeError reports where a JSON value did not match the expected type, e.g. "$.items[0].amount".
|
|
62
|
+
type DecodeError struct {
|
|
63
|
+
Path string
|
|
64
|
+
Message string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
func (e *DecodeError) Error() string {
|
|
68
|
+
return e.Path + ": " + e.Message
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Decoder turns a parsed JSON value at path into T.
|
|
72
|
+
type Decoder[T any] func(value any, path string) (T, error)
|
|
73
|
+
|
|
74
|
+
// ParseJSON parses JSON with exact numbers (json.Number).
|
|
75
|
+
func ParseJSON(data []byte) (any, error) {
|
|
76
|
+
decoder := json.NewDecoder(bytes.NewReader(data))
|
|
77
|
+
decoder.UseNumber()
|
|
78
|
+
var value any
|
|
79
|
+
if err := decoder.Decode(&value); err != nil {
|
|
80
|
+
return nil, err
|
|
81
|
+
}
|
|
82
|
+
// Only whitespace may follow; More() would accept a stray ] or }.
|
|
83
|
+
if _, err := decoder.Token(); err != io.EOF {
|
|
84
|
+
return nil, fmt.Errorf("invalid JSON: more than one value")
|
|
85
|
+
}
|
|
86
|
+
return value, nil
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
func describe(value any) string {
|
|
90
|
+
switch v := value.(type) {
|
|
91
|
+
case nil:
|
|
92
|
+
return "null"
|
|
93
|
+
case bool:
|
|
94
|
+
if v {
|
|
95
|
+
return "boolean true"
|
|
96
|
+
}
|
|
97
|
+
return "boolean false"
|
|
98
|
+
case string:
|
|
99
|
+
quoted, _ := json.Marshal(v)
|
|
100
|
+
return "string " + string(quoted)
|
|
101
|
+
case json.Number:
|
|
102
|
+
return "number " + v.String()
|
|
103
|
+
case float64:
|
|
104
|
+
return "number " + JsStr(v)
|
|
105
|
+
case []any:
|
|
106
|
+
return "array"
|
|
107
|
+
default:
|
|
108
|
+
return "object"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
func mismatch(path, expected string, value any) error {
|
|
113
|
+
return &DecodeError{Path: path, Message: "expected " + expected + ", got " + describe(value)}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// AsObject accepts a JSON object.
|
|
117
|
+
func AsObject(value any, path string) (map[string]any, error) {
|
|
118
|
+
if object, ok := value.(map[string]any); ok {
|
|
119
|
+
return object, nil
|
|
120
|
+
}
|
|
121
|
+
return nil, mismatch(path, "an object", value)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// AsString accepts a JSON string.
|
|
125
|
+
func AsString(value any, path string) (string, error) {
|
|
126
|
+
if text, ok := value.(string); ok {
|
|
127
|
+
return text, nil
|
|
128
|
+
}
|
|
129
|
+
return "", mismatch(path, "a string", value)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// AsEnum accepts any string, so a value the server adds later does not break the SDK.
|
|
133
|
+
func AsEnum(known ...string) Decoder[string] {
|
|
134
|
+
return func(value any, path string) (string, error) {
|
|
135
|
+
if text, ok := value.(string); ok {
|
|
136
|
+
return text, nil
|
|
137
|
+
}
|
|
138
|
+
return "", mismatch(path, "one of "+strings.Join(known, ", "), value)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// AsBoolean accepts true or false.
|
|
143
|
+
func AsBoolean(value any, path string) (bool, error) {
|
|
144
|
+
if flag, ok := value.(bool); ok {
|
|
145
|
+
return flag, nil
|
|
146
|
+
}
|
|
147
|
+
return false, mismatch(path, "a boolean", value)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
func number(value any) (float64, bool) {
|
|
151
|
+
switch v := value.(type) {
|
|
152
|
+
case json.Number:
|
|
153
|
+
parsed, err := v.Float64()
|
|
154
|
+
return parsed, err == nil
|
|
155
|
+
case float64:
|
|
156
|
+
return v, true
|
|
157
|
+
case int64:
|
|
158
|
+
return float64(v), true
|
|
159
|
+
case int:
|
|
160
|
+
return float64(v), true
|
|
161
|
+
default:
|
|
162
|
+
return 0, false
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// AsNumber accepts any JSON number.
|
|
167
|
+
func AsNumber(value any, path string) (float64, error) {
|
|
168
|
+
if parsed, ok := number(value); ok {
|
|
169
|
+
return parsed, nil
|
|
170
|
+
}
|
|
171
|
+
return 0, mismatch(path, "a number", value)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// AsInteger accepts a JSON number without a fraction (2.0 included) that fits in 64 bits.
|
|
175
|
+
func AsInteger(value any, path string) (int64, error) {
|
|
176
|
+
if text, ok := value.(json.Number); ok {
|
|
177
|
+
if parsed, err := strconv.ParseInt(text.String(), 10, 64); err == nil {
|
|
178
|
+
return parsed, nil
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if parsed, ok := number(value); ok && parsed == math.Trunc(parsed) && math.Abs(parsed) < 1<<63 {
|
|
182
|
+
return int64(parsed), nil
|
|
183
|
+
}
|
|
184
|
+
return 0, mismatch(path, "an integer", value)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
var decimalText = regexp.MustCompile(`^-?\d+(\.\d+)?$`)
|
|
188
|
+
|
|
189
|
+
// AsDecimal accepts a decimal string ("10.50") or a JSON number, and keeps every digit.
|
|
190
|
+
func AsDecimal(value any, path string) (Decimal, error) {
|
|
191
|
+
switch v := value.(type) {
|
|
192
|
+
case string:
|
|
193
|
+
if decimalText.MatchString(v) {
|
|
194
|
+
return Decimal(v), nil
|
|
195
|
+
}
|
|
196
|
+
case json.Number:
|
|
197
|
+
return Decimal(plainNumber(v.String())), nil
|
|
198
|
+
case float64:
|
|
199
|
+
return Decimal(JsStr(v)), nil
|
|
200
|
+
}
|
|
201
|
+
return "", mismatch(path, "a decimal", value)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// plainNumber writes "1E+3" as "1000" and "1.5e-2" as "0.015", digit for digit.
|
|
205
|
+
func plainNumber(text string) string {
|
|
206
|
+
mantissa, exponent := text, 0
|
|
207
|
+
if index := strings.IndexAny(text, "eE"); index >= 0 {
|
|
208
|
+
mantissa = text[:index]
|
|
209
|
+
exponent, _ = strconv.Atoi(text[index+1:])
|
|
210
|
+
}
|
|
211
|
+
negative := strings.HasPrefix(mantissa, "-")
|
|
212
|
+
mantissa = strings.TrimPrefix(mantissa, "-")
|
|
213
|
+
whole, fraction := mantissa, ""
|
|
214
|
+
if index := strings.IndexByte(mantissa, '.'); index >= 0 {
|
|
215
|
+
whole, fraction = mantissa[:index], mantissa[index+1:]
|
|
216
|
+
}
|
|
217
|
+
digits := whole + fraction
|
|
218
|
+
point := len(whole) + exponent
|
|
219
|
+
for point <= 0 {
|
|
220
|
+
digits = "0" + digits
|
|
221
|
+
point++
|
|
222
|
+
}
|
|
223
|
+
for point > len(digits) {
|
|
224
|
+
digits += "0"
|
|
225
|
+
}
|
|
226
|
+
result := strings.TrimLeft(digits[:point], "0")
|
|
227
|
+
if result == "" {
|
|
228
|
+
result = "0"
|
|
229
|
+
}
|
|
230
|
+
if rest := digits[point:]; rest != "" {
|
|
231
|
+
result += "." + rest
|
|
232
|
+
}
|
|
233
|
+
if negative && strings.Trim(result, "0.") != "" {
|
|
234
|
+
result = "-" + result
|
|
235
|
+
}
|
|
236
|
+
return result
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// AsList decodes a JSON array item by item.
|
|
240
|
+
func AsList[T any](item Decoder[T]) Decoder[[]T] {
|
|
241
|
+
return func(value any, path string) ([]T, error) {
|
|
242
|
+
values, ok := value.([]any)
|
|
243
|
+
if !ok {
|
|
244
|
+
return nil, mismatch(path, "an array", value)
|
|
245
|
+
}
|
|
246
|
+
result := make([]T, 0, len(values))
|
|
247
|
+
for index, entry := range values {
|
|
248
|
+
decoded, err := item(entry, path+"["+strconv.Itoa(index)+"]")
|
|
249
|
+
if err != nil {
|
|
250
|
+
return nil, err
|
|
251
|
+
}
|
|
252
|
+
result = append(result, decoded)
|
|
253
|
+
}
|
|
254
|
+
return result, nil
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// AsMap decodes a JSON object whose values all have one type.
|
|
259
|
+
func AsMap[T any](item Decoder[T]) Decoder[map[string]T] {
|
|
260
|
+
return func(value any, path string) (map[string]T, error) {
|
|
261
|
+
object, err := AsObject(value, path)
|
|
262
|
+
if err != nil {
|
|
263
|
+
return nil, err
|
|
264
|
+
}
|
|
265
|
+
result := make(map[string]T, len(object))
|
|
266
|
+
for key, entry := range object {
|
|
267
|
+
decoded, err := item(entry, path+"."+key)
|
|
268
|
+
if err != nil {
|
|
269
|
+
return nil, err
|
|
270
|
+
}
|
|
271
|
+
result[key] = decoded
|
|
272
|
+
}
|
|
273
|
+
return result, nil
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Nullable decodes null as nil and anything else with item.
|
|
278
|
+
func Nullable[T any](item Decoder[T]) Decoder[*T] {
|
|
279
|
+
return func(value any, path string) (*T, error) {
|
|
280
|
+
if value == nil {
|
|
281
|
+
return nil, nil
|
|
282
|
+
}
|
|
283
|
+
decoded, err := item(value, path)
|
|
284
|
+
if err != nil {
|
|
285
|
+
return nil, err
|
|
286
|
+
}
|
|
287
|
+
return &decoded, nil
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Required reads a field that must be present.
|
|
292
|
+
func Required[T any](object map[string]any, name, path string, decode Decoder[T]) (T, error) {
|
|
293
|
+
value, ok := object[name]
|
|
294
|
+
if !ok {
|
|
295
|
+
var zero T
|
|
296
|
+
return zero, &DecodeError{Path: path + "." + name, Message: "is required"}
|
|
297
|
+
}
|
|
298
|
+
return decode(value, path+"."+name)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Optional reads a field that may be absent. Many servers send null for a field they leave out: null that the decoder
|
|
302
|
+
// does not accept (the field cannot be null) reads as absent.
|
|
303
|
+
func Optional[T any](object map[string]any, name, path string, decode Decoder[T]) (Opt[T], error) {
|
|
304
|
+
value, ok := object[name]
|
|
305
|
+
if !ok {
|
|
306
|
+
return Opt[T]{}, nil
|
|
307
|
+
}
|
|
308
|
+
if value == nil {
|
|
309
|
+
if decoded, err := decode(nil, path+"."+name); err == nil {
|
|
310
|
+
return Some(decoded), nil
|
|
311
|
+
}
|
|
312
|
+
return Opt[T]{}, nil
|
|
313
|
+
}
|
|
314
|
+
decoded, err := decode(value, path+"."+name)
|
|
315
|
+
if err != nil {
|
|
316
|
+
return Opt[T]{}, err
|
|
317
|
+
}
|
|
318
|
+
return Some(decoded), nil
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Extra returns the fields of object that are not in known, so they can be sent back unchanged.
|
|
322
|
+
func Extra(object map[string]any, known ...string) map[string]any {
|
|
323
|
+
extra := map[string]any{}
|
|
324
|
+
for key, value := range object {
|
|
325
|
+
if !contains(known, key) {
|
|
326
|
+
extra[key] = value
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return extra
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
func contains(list []string, value string) bool {
|
|
333
|
+
for _, item := range list {
|
|
334
|
+
if item == value {
|
|
335
|
+
return true
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return false
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// @end
|
|
342
|
+
|
|
343
|
+
// @block models.encode
|
|
344
|
+
// @summary Serializes a value as compact UTF-8 JSON: models use ToJSON(), decimals become strings, unset optional fields are left out, numbers are written like JavaScript.
|
|
345
|
+
// @versions >=1.18
|
|
346
|
+
// @source [1] https://pkg.go.dev/encoding/json
|
|
347
|
+
// @quote [1] "SetEscapeHTML specifies whether problematic HTML characters should be escaped inside JSON quoted strings."
|
|
348
|
+
// @retrieved 2026-12-05
|
|
349
|
+
// @tests tests/json_test.go
|
|
350
|
+
// @requirement SDKL-JSON-004
|
|
351
|
+
|
|
352
|
+
// JSONValue is implemented by every generated model: its JSON form, extra fields included.
|
|
353
|
+
type JSONValue interface {
|
|
354
|
+
ToJSON() map[string]any
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
type absent struct{}
|
|
358
|
+
|
|
359
|
+
// Unset is what ToJSON writes for an optional field that is not set; EncodeJSON leaves it out.
|
|
360
|
+
var Unset any = absent{}
|
|
361
|
+
|
|
362
|
+
// ToPlain turns models and decimals into plain JSON data, leaving out unset fields.
|
|
363
|
+
func ToPlain(value any) any {
|
|
364
|
+
switch v := value.(type) {
|
|
365
|
+
case nil:
|
|
366
|
+
return nil
|
|
367
|
+
case JSONValue:
|
|
368
|
+
return ToPlain(v.ToJSON())
|
|
369
|
+
case Decimal:
|
|
370
|
+
return string(v)
|
|
371
|
+
case map[string]any:
|
|
372
|
+
plain := make(map[string]any, len(v))
|
|
373
|
+
for key, item := range v {
|
|
374
|
+
if _, skip := item.(absent); !skip {
|
|
375
|
+
plain[key] = ToPlain(item)
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return plain
|
|
379
|
+
case []any:
|
|
380
|
+
plain := make([]any, len(v))
|
|
381
|
+
for i, item := range v {
|
|
382
|
+
plain[i] = ToPlain(item)
|
|
383
|
+
}
|
|
384
|
+
return plain
|
|
385
|
+
default:
|
|
386
|
+
return v
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Plain is the JSON form of a value that needs no conversion (strings, numbers, booleans, models).
|
|
391
|
+
func Plain[T any](value T) any {
|
|
392
|
+
return value
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// EncodeList is the JSON form of a list.
|
|
396
|
+
func EncodeList[T any](items []T, encode func(T) any) []any {
|
|
397
|
+
if items == nil {
|
|
398
|
+
return []any{}
|
|
399
|
+
}
|
|
400
|
+
result := make([]any, len(items))
|
|
401
|
+
for i, item := range items {
|
|
402
|
+
result[i] = encode(item)
|
|
403
|
+
}
|
|
404
|
+
return result
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// EncodeMap is the JSON form of a map.
|
|
408
|
+
func EncodeMap[T any](entries map[string]T, encode func(T) any) map[string]any {
|
|
409
|
+
result := make(map[string]any, len(entries))
|
|
410
|
+
for key, item := range entries {
|
|
411
|
+
result[key] = encode(item)
|
|
412
|
+
}
|
|
413
|
+
return result
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// EncodeNullable is the JSON form of a nullable value: null for nil.
|
|
417
|
+
func EncodeNullable[T any](value *T, encode func(T) any) any {
|
|
418
|
+
if value == nil {
|
|
419
|
+
return nil
|
|
420
|
+
}
|
|
421
|
+
return encode(*value)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// OptValue is an optional value as a parameter or config value: nil when absent.
|
|
425
|
+
func OptValue[T any](value Opt[T]) any {
|
|
426
|
+
if !value.Set {
|
|
427
|
+
return nil
|
|
428
|
+
}
|
|
429
|
+
return value.Value
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// OptEncode is an optional value as JSON data: nil when absent.
|
|
433
|
+
func OptEncode[T any](value Opt[T], encode func(T) any) any {
|
|
434
|
+
if !value.Set {
|
|
435
|
+
return nil
|
|
436
|
+
}
|
|
437
|
+
return encode(value.Value)
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// EncodeJSON writes compact JSON without HTML escaping; object keys are sorted.
|
|
441
|
+
func EncodeJSON(value any) ([]byte, error) {
|
|
442
|
+
var buffer bytes.Buffer
|
|
443
|
+
if err := writeJSON(&buffer, ToPlain(value)); err != nil {
|
|
444
|
+
return nil, err
|
|
445
|
+
}
|
|
446
|
+
return buffer.Bytes(), nil
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
func writeString(buffer *bytes.Buffer, text string) error {
|
|
450
|
+
encoder := json.NewEncoder(buffer)
|
|
451
|
+
encoder.SetEscapeHTML(false)
|
|
452
|
+
if err := encoder.Encode(text); err != nil {
|
|
453
|
+
return err
|
|
454
|
+
}
|
|
455
|
+
// Encode ends with a newline.
|
|
456
|
+
buffer.Truncate(buffer.Len() - 1)
|
|
457
|
+
return nil
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
func writeJSON(buffer *bytes.Buffer, value any) error {
|
|
461
|
+
switch v := value.(type) {
|
|
462
|
+
case nil:
|
|
463
|
+
buffer.WriteString("null")
|
|
464
|
+
case bool:
|
|
465
|
+
buffer.WriteString(strconv.FormatBool(v))
|
|
466
|
+
case string:
|
|
467
|
+
return writeString(buffer, v)
|
|
468
|
+
case json.Number:
|
|
469
|
+
buffer.WriteString(v.String())
|
|
470
|
+
case int64:
|
|
471
|
+
buffer.WriteString(strconv.FormatInt(v, 10))
|
|
472
|
+
case int:
|
|
473
|
+
buffer.WriteString(strconv.Itoa(v))
|
|
474
|
+
case float64:
|
|
475
|
+
if math.IsNaN(v) || math.IsInf(v, 0) {
|
|
476
|
+
buffer.WriteString("null")
|
|
477
|
+
} else {
|
|
478
|
+
buffer.WriteString(JsStr(v))
|
|
479
|
+
}
|
|
480
|
+
case []any:
|
|
481
|
+
return writeList(buffer, v)
|
|
482
|
+
case map[string]any:
|
|
483
|
+
return writeObject(buffer, v)
|
|
484
|
+
default:
|
|
485
|
+
return fmt.Errorf("cannot encode %T as JSON", value)
|
|
486
|
+
}
|
|
487
|
+
return nil
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
func writeList(buffer *bytes.Buffer, items []any) error {
|
|
491
|
+
buffer.WriteByte('[')
|
|
492
|
+
for i, item := range items {
|
|
493
|
+
if i > 0 {
|
|
494
|
+
buffer.WriteByte(',')
|
|
495
|
+
}
|
|
496
|
+
if err := writeJSON(buffer, item); err != nil {
|
|
497
|
+
return err
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
buffer.WriteByte(']')
|
|
501
|
+
return nil
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
func writeObject(buffer *bytes.Buffer, object map[string]any) error {
|
|
505
|
+
keys := make([]string, 0, len(object))
|
|
506
|
+
for key := range object {
|
|
507
|
+
keys = append(keys, key)
|
|
508
|
+
}
|
|
509
|
+
sort.Strings(keys)
|
|
510
|
+
buffer.WriteByte('{')
|
|
511
|
+
for i, key := range keys {
|
|
512
|
+
if i > 0 {
|
|
513
|
+
buffer.WriteByte(',')
|
|
514
|
+
}
|
|
515
|
+
if err := writeString(buffer, key); err != nil {
|
|
516
|
+
return err
|
|
517
|
+
}
|
|
518
|
+
buffer.WriteByte(':')
|
|
519
|
+
if err := writeJSON(buffer, object[key]); err != nil {
|
|
520
|
+
return err
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
buffer.WriteByte('}')
|
|
524
|
+
return nil
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// @end
|