@workerstack/clients 0.0.0-stage → 1.0.0-rc.24
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 +21 -0
- package/README.md +619 -2
- package/bin/honey-clients.js +94 -0
- package/dist/cli.d.ts +102 -0
- package/dist/cli.js +190 -0
- package/dist/emit/cli/channels.d.ts +73 -0
- package/dist/emit/cli/channels.js +197 -0
- package/dist/emit/cli/commands.d.ts +27 -0
- package/dist/emit/cli/commands.js +187 -0
- package/dist/emit/cli/discovery.d.ts +35 -0
- package/dist/emit/cli/discovery.js +202 -0
- package/dist/emit/cli/flags.d.ts +59 -0
- package/dist/emit/cli/flags.js +186 -0
- package/dist/emit/cli/index.d.ts +1 -0
- package/dist/emit/cli/index.js +1 -0
- package/dist/emit/cli/install.d.ts +37 -0
- package/dist/emit/cli/install.js +88 -0
- package/dist/emit/cli/layout.d.ts +23 -0
- package/dist/emit/cli/layout.js +118 -0
- package/dist/emit/cli/module.d.ts +30 -0
- package/dist/emit/cli/module.js +186 -0
- package/dist/emit/cli/release.d.ts +40 -0
- package/dist/emit/cli/release.js +183 -0
- package/dist/emit/cli/skills.d.ts +11 -0
- package/dist/emit/cli/skills.js +56 -0
- package/dist/emit/csharp/errors.d.ts +7 -0
- package/dist/emit/csharp/errors.js +69 -0
- package/dist/emit/csharp/index.d.ts +1 -0
- package/dist/emit/csharp/index.js +1 -0
- package/dist/emit/csharp/json.d.ts +13 -0
- package/dist/emit/csharp/json.js +113 -0
- package/dist/emit/csharp/realtime.d.ts +10 -0
- package/dist/emit/csharp/realtime.js +33 -0
- package/dist/emit/csharp/sdk-answer.d.ts +48 -0
- package/dist/emit/csharp/sdk-answer.js +85 -0
- package/dist/emit/csharp/sdk-body.d.ts +10 -0
- package/dist/emit/csharp/sdk-body.js +87 -0
- package/dist/emit/csharp/sdk-client.d.ts +32 -0
- package/dist/emit/csharp/sdk-client.js +177 -0
- package/dist/emit/csharp/sdk-csproj.d.ts +36 -0
- package/dist/emit/csharp/sdk-csproj.js +136 -0
- package/dist/emit/csharp/sdk-doc.d.ts +12 -0
- package/dist/emit/csharp/sdk-doc.js +35 -0
- package/dist/emit/csharp/sdk-method.d.ts +26 -0
- package/dist/emit/csharp/sdk-method.js +187 -0
- package/dist/emit/csharp/sdk-plan.d.ts +38 -0
- package/dist/emit/csharp/sdk-plan.js +1 -0
- package/dist/emit/csharp/sdk.d.ts +40 -0
- package/dist/emit/csharp/sdk.js +105 -0
- package/dist/emit/csharp/sse.d.ts +18 -0
- package/dist/emit/csharp/sse.js +29 -0
- package/dist/emit/csharp/transport.d.ts +11 -0
- package/dist/emit/csharp/transport.js +67 -0
- package/dist/emit/csharp/types-enum.d.ts +19 -0
- package/dist/emit/csharp/types-enum.js +63 -0
- package/dist/emit/csharp/types-names.d.ts +33 -0
- package/dist/emit/csharp/types-names.js +182 -0
- package/dist/emit/csharp/types-record.d.ts +25 -0
- package/dist/emit/csharp/types-record.js +65 -0
- package/dist/emit/csharp/types-union.d.ts +27 -0
- package/dist/emit/csharp/types-union.js +113 -0
- package/dist/emit/csharp/types.d.ts +36 -0
- package/dist/emit/csharp/types.js +126 -0
- package/dist/emit/csharp/ws.d.ts +20 -0
- package/dist/emit/csharp/ws.js +14 -0
- package/dist/emit/go/errors.d.ts +7 -0
- package/dist/emit/go/errors.js +44 -0
- package/dist/emit/go/http.d.ts +11 -0
- package/dist/emit/go/http.js +50 -0
- package/dist/emit/go/index.d.ts +1 -0
- package/dist/emit/go/index.js +1 -0
- package/dist/emit/go/module-path.d.ts +2 -0
- package/dist/emit/go/module-path.js +27 -0
- package/dist/emit/go/sdk-answer.d.ts +28 -0
- package/dist/emit/go/sdk-answer.js +41 -0
- package/dist/emit/go/sdk-body.d.ts +24 -0
- package/dist/emit/go/sdk-body.js +76 -0
- package/dist/emit/go/sdk-client.d.ts +29 -0
- package/dist/emit/go/sdk-client.js +141 -0
- package/dist/emit/go/sdk-method.d.ts +68 -0
- package/dist/emit/go/sdk-method.js +172 -0
- package/dist/emit/go/sdk-mirror.d.ts +23 -0
- package/dist/emit/go/sdk-mirror.js +97 -0
- package/dist/emit/go/sdk-opts.d.ts +55 -0
- package/dist/emit/go/sdk-opts.js +100 -0
- package/dist/emit/go/sdk.d.ts +26 -0
- package/dist/emit/go/sdk.js +111 -0
- package/dist/emit/go/sse.d.ts +16 -0
- package/dist/emit/go/sse.js +26 -0
- package/dist/emit/go/types-codec.d.ts +15 -0
- package/dist/emit/go/types-codec.js +171 -0
- package/dist/emit/go/types-names.d.ts +14 -0
- package/dist/emit/go/types-names.js +64 -0
- package/dist/emit/go/types-struct.d.ts +29 -0
- package/dist/emit/go/types-struct.js +65 -0
- package/dist/emit/go/types-union.d.ts +17 -0
- package/dist/emit/go/types-union.js +84 -0
- package/dist/emit/go/types.d.ts +32 -0
- package/dist/emit/go/types.js +177 -0
- package/dist/emit/go/ws.d.ts +12 -0
- package/dist/emit/go/ws.js +70 -0
- package/dist/emit/java/gradle.d.ts +57 -0
- package/dist/emit/java/gradle.js +221 -0
- package/dist/emit/java/index.d.ts +2 -0
- package/dist/emit/java/index.js +2 -0
- package/dist/emit/java/json.d.ts +13 -0
- package/dist/emit/java/json.js +84 -0
- package/dist/emit/java/layout-ast.d.ts +146 -0
- package/dist/emit/java/layout-ast.js +102 -0
- package/dist/emit/java/layout-decl.d.ts +20 -0
- package/dist/emit/java/layout-decl.js +155 -0
- package/dist/emit/java/layout-doc.d.ts +55 -0
- package/dist/emit/java/layout-doc.js +166 -0
- package/dist/emit/java/layout-dot.d.ts +18 -0
- package/dist/emit/java/layout-dot.js +127 -0
- package/dist/emit/java/layout-strings.d.ts +8 -0
- package/dist/emit/java/layout-strings.js +76 -0
- package/dist/emit/java/layout-types.d.ts +11 -0
- package/dist/emit/java/layout-types.js +95 -0
- package/dist/emit/java/layout-visitor.d.ts +38 -0
- package/dist/emit/java/layout-visitor.js +232 -0
- package/dist/emit/java/layout.d.ts +61 -0
- package/dist/emit/java/layout.js +121 -0
- package/dist/emit/java/models-enum.d.ts +17 -0
- package/dist/emit/java/models-enum.js +51 -0
- package/dist/emit/java/models-names.d.ts +29 -0
- package/dist/emit/java/models-names.js +97 -0
- package/dist/emit/java/models-record.d.ts +24 -0
- package/dist/emit/java/models-record.js +79 -0
- package/dist/emit/java/models-union.d.ts +27 -0
- package/dist/emit/java/models-union.js +86 -0
- package/dist/emit/java/models.d.ts +28 -0
- package/dist/emit/java/models.js +118 -0
- package/dist/emit/java/realtime.d.ts +50 -0
- package/dist/emit/java/realtime.js +69 -0
- package/dist/emit/java/sdk-client.d.ts +66 -0
- package/dist/emit/java/sdk-client.js +207 -0
- package/dist/emit/java/sdk-decl.d.ts +11 -0
- package/dist/emit/java/sdk-decl.js +63 -0
- package/dist/emit/java/sdk-errors.d.ts +13 -0
- package/dist/emit/java/sdk-errors.js +141 -0
- package/dist/emit/java/sdk-headers.d.ts +12 -0
- package/dist/emit/java/sdk-headers.js +74 -0
- package/dist/emit/java/sdk-mirror.d.ts +14 -0
- package/dist/emit/java/sdk-mirror.js +107 -0
- package/dist/emit/java/sdk-models.d.ts +16 -0
- package/dist/emit/java/sdk-models.js +68 -0
- package/dist/emit/java/sdk-op.d.ts +57 -0
- package/dist/emit/java/sdk-op.js +216 -0
- package/dist/emit/java/sdk-params.d.ts +38 -0
- package/dist/emit/java/sdk-params.js +133 -0
- package/dist/emit/java/sdk-plan.d.ts +52 -0
- package/dist/emit/java/sdk-plan.js +1 -0
- package/dist/emit/java/sdk-record.d.ts +16 -0
- package/dist/emit/java/sdk-record.js +99 -0
- package/dist/emit/java/sdk.d.ts +49 -0
- package/dist/emit/java/sdk.js +216 -0
- package/dist/emit/java/sse.d.ts +35 -0
- package/dist/emit/java/sse.js +57 -0
- package/dist/emit/java/ws.d.ts +27 -0
- package/dist/emit/java/ws.js +31 -0
- package/dist/emit/mcp/annotations.d.ts +15 -0
- package/dist/emit/mcp/annotations.js +15 -0
- package/dist/emit/mcp/files.d.ts +18 -0
- package/dist/emit/mcp/files.js +42 -0
- package/dist/emit/mcp/index.d.ts +3 -0
- package/dist/emit/mcp/index.js +3 -0
- package/dist/emit/mcp/literal.d.ts +2 -0
- package/dist/emit/mcp/literal.js +33 -0
- package/dist/emit/mcp/mounted.d.ts +21 -0
- package/dist/emit/mcp/mounted.js +89 -0
- package/dist/emit/mcp/output-schema.d.ts +18 -0
- package/dist/emit/mcp/output-schema.js +38 -0
- package/dist/emit/mcp/registry.d.ts +23 -0
- package/dist/emit/mcp/registry.js +83 -0
- package/dist/emit/mcp/runtime.d.ts +10 -0
- package/dist/emit/mcp/runtime.js +47 -0
- package/dist/emit/mcp/schema.d.ts +19 -0
- package/dist/emit/mcp/schema.js +88 -0
- package/dist/emit/mcp/server.d.ts +30 -0
- package/dist/emit/mcp/server.js +246 -0
- package/dist/emit/mcp/tools.d.ts +51 -0
- package/dist/emit/mcp/tools.js +153 -0
- package/dist/emit/python/errors.d.ts +8 -0
- package/dist/emit/python/errors.js +68 -0
- package/dist/emit/python/index.d.ts +1 -0
- package/dist/emit/python/index.js +1 -0
- package/dist/emit/python/realtime.d.ts +10 -0
- package/dist/emit/python/realtime.js +33 -0
- package/dist/emit/python/sdk-answer.d.ts +49 -0
- package/dist/emit/python/sdk-answer.js +89 -0
- package/dist/emit/python/sdk-body.d.ts +11 -0
- package/dist/emit/python/sdk-body.js +40 -0
- package/dist/emit/python/sdk-client.d.ts +36 -0
- package/dist/emit/python/sdk-client.js +163 -0
- package/dist/emit/python/sdk-doc.d.ts +9 -0
- package/dist/emit/python/sdk-doc.js +32 -0
- package/dist/emit/python/sdk-imports.d.ts +14 -0
- package/dist/emit/python/sdk-imports.js +38 -0
- package/dist/emit/python/sdk-method.d.ts +29 -0
- package/dist/emit/python/sdk-method.js +183 -0
- package/dist/emit/python/sdk-plan.d.ts +33 -0
- package/dist/emit/python/sdk-plan.js +1 -0
- package/dist/emit/python/sdk-pyproject.d.ts +27 -0
- package/dist/emit/python/sdk-pyproject.js +103 -0
- package/dist/emit/python/sdk.d.ts +22 -0
- package/dist/emit/python/sdk.js +154 -0
- package/dist/emit/python/sse.d.ts +12 -0
- package/dist/emit/python/sse.js +23 -0
- package/dist/emit/python/transport.d.ts +15 -0
- package/dist/emit/python/transport.js +60 -0
- package/dist/emit/python/types-dict.d.ts +31 -0
- package/dist/emit/python/types-dict.js +45 -0
- package/dist/emit/python/types-names.d.ts +16 -0
- package/dist/emit/python/types-names.js +52 -0
- package/dist/emit/python/types-union.d.ts +32 -0
- package/dist/emit/python/types-union.js +46 -0
- package/dist/emit/python/types.d.ts +36 -0
- package/dist/emit/python/types.js +128 -0
- package/dist/emit/python/ws.d.ts +14 -0
- package/dist/emit/python/ws.js +16 -0
- package/dist/emit/rust/errors.d.ts +7 -0
- package/dist/emit/rust/errors.js +107 -0
- package/dist/emit/rust/http.d.ts +13 -0
- package/dist/emit/rust/http.js +67 -0
- package/dist/emit/rust/index.d.ts +1 -0
- package/dist/emit/rust/index.js +1 -0
- package/dist/emit/rust/realtime.d.ts +11 -0
- package/dist/emit/rust/realtime.js +29 -0
- package/dist/emit/rust/sdk-body.d.ts +19 -0
- package/dist/emit/rust/sdk-body.js +53 -0
- package/dist/emit/rust/sdk-cargo.d.ts +43 -0
- package/dist/emit/rust/sdk-cargo.js +178 -0
- package/dist/emit/rust/sdk-client.d.ts +25 -0
- package/dist/emit/rust/sdk-client.js +108 -0
- package/dist/emit/rust/sdk-method.d.ts +15 -0
- package/dist/emit/rust/sdk-method.js +119 -0
- package/dist/emit/rust/sdk-opts.d.ts +58 -0
- package/dist/emit/rust/sdk-opts.js +117 -0
- package/dist/emit/rust/sdk-plan.d.ts +33 -0
- package/dist/emit/rust/sdk-plan.js +1 -0
- package/dist/emit/rust/sdk.d.ts +23 -0
- package/dist/emit/rust/sdk.js +111 -0
- package/dist/emit/rust/sse.d.ts +19 -0
- package/dist/emit/rust/sse.js +20 -0
- package/dist/emit/rust/types-enum.d.ts +13 -0
- package/dist/emit/rust/types-enum.js +62 -0
- package/dist/emit/rust/types-names.d.ts +19 -0
- package/dist/emit/rust/types-names.js +66 -0
- package/dist/emit/rust/types-struct.d.ts +21 -0
- package/dist/emit/rust/types-struct.js +59 -0
- package/dist/emit/rust/types-union.d.ts +24 -0
- package/dist/emit/rust/types-union.js +97 -0
- package/dist/emit/rust/types.d.ts +34 -0
- package/dist/emit/rust/types.js +105 -0
- package/dist/emit/rust/ws.d.ts +21 -0
- package/dist/emit/rust/ws.js +20 -0
- package/dist/emit/shared/escape.d.ts +55 -0
- package/dist/emit/shared/escape.js +144 -0
- package/dist/emit/shared/format.d.ts +24 -0
- package/dist/emit/shared/format.js +23 -0
- package/dist/emit/shared/gofmt.d.ts +3 -0
- package/dist/emit/shared/gofmt.js +26 -0
- package/dist/emit/shared/lang.d.ts +60 -0
- package/dist/emit/shared/lang.js +233 -0
- package/dist/emit/shared/literals.d.ts +4 -0
- package/dist/emit/shared/literals.js +31 -0
- package/dist/emit/shared/metadata.d.ts +106 -0
- package/dist/emit/shared/metadata.js +130 -0
- package/dist/emit/shared/mirror.d.ts +22 -0
- package/dist/emit/shared/mirror.js +26 -0
- package/dist/emit/shared/ruff.d.ts +3 -0
- package/dist/emit/shared/ruff.js +31 -0
- package/dist/emit/shared/rustfmt.d.ts +3 -0
- package/dist/emit/shared/rustfmt.js +32 -0
- package/dist/emit/shared/status-keys.d.ts +7 -0
- package/dist/emit/shared/status-keys.js +67 -0
- package/dist/emit/shared/type-emitter.d.ts +19 -0
- package/dist/emit/shared/type-emitter.js +100 -0
- package/dist/emit/ts/app-client.d.ts +4 -0
- package/dist/emit/ts/app-client.js +68 -0
- package/dist/emit/ts/http.d.ts +20 -0
- package/dist/emit/ts/http.js +74 -0
- package/dist/emit/ts/package.d.ts +36 -0
- package/dist/emit/ts/package.js +126 -0
- package/dist/emit/ts/route-tree.d.ts +68 -0
- package/dist/emit/ts/route-tree.js +240 -0
- package/dist/emit/ts/sdk-types-preamble.d.ts +14 -0
- package/dist/emit/ts/sdk-types-preamble.js +123 -0
- package/dist/emit/ts/sdk-types.d.ts +13 -0
- package/dist/emit/ts/sdk-types.js +213 -0
- package/dist/emit/ts/sdk.d.ts +21 -0
- package/dist/emit/ts/sdk.js +173 -0
- package/dist/emit/ts/service-map.d.ts +40 -0
- package/dist/emit/ts/service-map.js +171 -0
- package/dist/emit/ts/tanstack-query.d.ts +12 -0
- package/dist/emit/ts/tanstack-query.js +156 -0
- package/dist/emit/ts/type-gen.d.ts +26 -0
- package/dist/emit/ts/type-gen.js +255 -0
- package/dist/emit/ts/webhooks.d.ts +19 -0
- package/dist/emit/ts/webhooks.js +81 -0
- package/dist/extract/chain.d.ts +34 -0
- package/dist/extract/chain.js +84 -0
- package/dist/extract/extract.d.ts +41 -0
- package/dist/extract/extract.js +191 -0
- package/dist/extract/serialize.d.ts +34 -0
- package/dist/extract/serialize.js +295 -0
- package/dist/extract/walk.d.ts +47 -0
- package/dist/extract/walk.js +109 -0
- package/dist/gen/args.d.ts +28 -0
- package/dist/gen/args.js +133 -0
- package/dist/gen/formatters.d.ts +62 -0
- package/dist/gen/formatters.js +146 -0
- package/dist/gen/process.d.ts +13 -0
- package/dist/gen/process.js +35 -0
- package/dist/gen/shipped.d.ts +17 -0
- package/dist/gen/shipped.js +55 -0
- package/dist/gen/targets.d.ts +93 -0
- package/dist/gen/targets.js +171 -0
- package/dist/gen/write.d.ts +33 -0
- package/dist/gen/write.js +118 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +15 -0
- package/dist/ir/build.d.ts +37 -0
- package/dist/ir/build.js +152 -0
- package/dist/ir/load.d.ts +11 -0
- package/dist/ir/load.js +112 -0
- package/dist/ir/model.d.ts +206 -0
- package/dist/ir/model.js +5 -0
- package/dist/ir/resolve-refs.d.ts +11 -0
- package/dist/ir/resolve-refs.js +66 -0
- package/dist/ir/resource-tree.d.ts +9 -0
- package/dist/ir/resource-tree.js +53 -0
- package/dist/ir/route-tree-intern.d.ts +18 -0
- package/dist/ir/route-tree-intern.js +174 -0
- package/dist/ir/schema.d.ts +11 -0
- package/dist/ir/schema.js +192 -0
- package/dist/ir/sdk-model.d.ts +86 -0
- package/dist/ir/sdk-model.js +204 -0
- package/dist/ir/slots.d.ts +42 -0
- package/dist/ir/slots.js +245 -0
- package/dist/runtime/cli/body.go +176 -0
- package/dist/runtime/cli/config.go +243 -0
- package/dist/runtime/cli/discovery.go +147 -0
- package/dist/runtime/cli/format.go +174 -0
- package/dist/runtime/cli/log.go +117 -0
- package/dist/runtime/cli/output.go +247 -0
- package/dist/runtime/cli/params.go +197 -0
- package/dist/runtime/cli/run.go +226 -0
- package/dist/runtime/cli/socket.go +60 -0
- package/dist/runtime/cli/stream.go +217 -0
- package/dist/runtime/cli/target.go +117 -0
- package/dist/runtime/csharp/Adapters.cs +183 -0
- package/dist/runtime/csharp/Auth.cs +56 -0
- package/dist/runtime/csharp/Body.cs +135 -0
- package/dist/runtime/csharp/Config.cs +161 -0
- package/dist/runtime/csharp/Envelope.cs +149 -0
- package/dist/runtime/csharp/Errors.cs +194 -0
- package/dist/runtime/csharp/Events.cs +155 -0
- package/dist/runtime/csharp/Exchange.cs +247 -0
- package/dist/runtime/csharp/Handler.cs +103 -0
- package/dist/runtime/csharp/Hooks.cs +128 -0
- package/dist/runtime/csharp/Invalidation.cs +102 -0
- package/dist/runtime/csharp/Json.cs +144 -0
- package/dist/runtime/csharp/Log.cs +48 -0
- package/dist/runtime/csharp/Operation.cs +33 -0
- package/dist/runtime/csharp/Path.cs +65 -0
- package/dist/runtime/csharp/Query.cs +72 -0
- package/dist/runtime/csharp/Realtime.cs +118 -0
- package/dist/runtime/csharp/RealtimeLoop.cs +236 -0
- package/dist/runtime/csharp/Redirect.cs +53 -0
- package/dist/runtime/csharp/Result.cs +57 -0
- package/dist/runtime/csharp/Sse.cs +122 -0
- package/dist/runtime/csharp/Stale.cs +151 -0
- package/dist/runtime/csharp/Transport.cs +143 -0
- package/dist/runtime/csharp/TransportLongPoll.cs +63 -0
- package/dist/runtime/csharp/TransportSse.cs +54 -0
- package/dist/runtime/csharp/TransportWs.cs +40 -0
- package/dist/runtime/csharp/Wire.cs +109 -0
- package/dist/runtime/csharp/Ws.cs +300 -0
- package/dist/runtime/csharp/WsDial.cs +127 -0
- package/dist/runtime/go/auth.go +127 -0
- package/dist/runtime/go/body.go +129 -0
- package/dist/runtime/go/config.go +75 -0
- package/dist/runtime/go/errors.go +185 -0
- package/dist/runtime/go/export.go +37 -0
- package/dist/runtime/go/hooks.go +53 -0
- package/dist/runtime/go/invalidation.go +112 -0
- package/dist/runtime/go/log.go +92 -0
- package/dist/runtime/go/nullable.go +64 -0
- package/dist/runtime/go/options.go +118 -0
- package/dist/runtime/go/path.go +156 -0
- package/dist/runtime/go/query.go +147 -0
- package/dist/runtime/go/realtime.go +239 -0
- package/dist/runtime/go/realtime_loop.go +208 -0
- package/dist/runtime/go/redirect.go +124 -0
- package/dist/runtime/go/request.go +222 -0
- package/dist/runtime/go/result.go +86 -0
- package/dist/runtime/go/sse.go +186 -0
- package/dist/runtime/go/stale.go +229 -0
- package/dist/runtime/go/stream.go +105 -0
- package/dist/runtime/go/transport.go +242 -0
- package/dist/runtime/go/transport_longpoll.go +121 -0
- package/dist/runtime/go/transport_sse.go +175 -0
- package/dist/runtime/go/ws.go +205 -0
- package/dist/runtime/java/Answer.java +107 -0
- package/dist/runtime/java/ApiException.java +110 -0
- package/dist/runtime/java/BinaryBody.java +36 -0
- package/dist/runtime/java/Body.java +105 -0
- package/dist/runtime/java/Call.java +23 -0
- package/dist/runtime/java/CallLog.java +51 -0
- package/dist/runtime/java/ClientConfig.java +233 -0
- package/dist/runtime/java/ConnectionState.java +12 -0
- package/dist/runtime/java/Credential.java +58 -0
- package/dist/runtime/java/Deadline.java +38 -0
- package/dist/runtime/java/Decode.java +181 -0
- package/dist/runtime/java/Envelope.java +141 -0
- package/dist/runtime/java/ErrorEnvelope.java +23 -0
- package/dist/runtime/java/EventStream.java +129 -0
- package/dist/runtime/java/Exchange.java +62 -0
- package/dist/runtime/java/FilePart.java +5 -0
- package/dist/runtime/java/Flight.java +306 -0
- package/dist/runtime/java/HoneyException.java +14 -0
- package/dist/runtime/java/Hooks.java +47 -0
- package/dist/runtime/java/Hops.java +133 -0
- package/dist/runtime/java/InvalidationConfig.java +73 -0
- package/dist/runtime/java/Json.java +23 -0
- package/dist/runtime/java/Keepalive.java +60 -0
- package/dist/runtime/java/LogEntry.java +14 -0
- package/dist/runtime/java/LongPollAdapter.java +68 -0
- package/dist/runtime/java/Operation.java +21 -0
- package/dist/runtime/java/Opt.java +121 -0
- package/dist/runtime/java/Pump.java +160 -0
- package/dist/runtime/java/RawResponse.java +48 -0
- package/dist/runtime/java/Realtime.java +152 -0
- package/dist/runtime/java/RealtimeLoop.java +371 -0
- package/dist/runtime/java/RedirectPolicy.java +13 -0
- package/dist/runtime/java/Redirects.java +126 -0
- package/dist/runtime/java/RequestContext.java +78 -0
- package/dist/runtime/java/RequestHook.java +9 -0
- package/dist/runtime/java/RequestOptions.java +91 -0
- package/dist/runtime/java/ResponseContext.java +70 -0
- package/dist/runtime/java/ResponseHook.java +12 -0
- package/dist/runtime/java/Result.java +32 -0
- package/dist/runtime/java/ResumableConnection.java +165 -0
- package/dist/runtime/java/SdkException.java +11 -0
- package/dist/runtime/java/Socket.java +301 -0
- package/dist/runtime/java/Sse.java +171 -0
- package/dist/runtime/java/SseAdapter.java +61 -0
- package/dist/runtime/java/SseEvent.java +10 -0
- package/dist/runtime/java/StaleMeta.java +16 -0
- package/dist/runtime/java/StaleTracker.java +287 -0
- package/dist/runtime/java/Transport.java +16 -0
- package/dist/runtime/java/TransportAdapter.java +14 -0
- package/dist/runtime/java/TransportConnection.java +15 -0
- package/dist/runtime/java/TransportKind.java +12 -0
- package/dist/runtime/java/TransportMessage.java +9 -0
- package/dist/runtime/java/TransportOptions.java +138 -0
- package/dist/runtime/java/TypedWebSocket.java +83 -0
- package/dist/runtime/java/UrlPath.java +49 -0
- package/dist/runtime/java/UrlQuery.java +99 -0
- package/dist/runtime/java/WsAdapter.java +52 -0
- package/dist/runtime/java/WsClose.java +47 -0
- package/dist/runtime/java/WsDial.java +148 -0
- package/dist/runtime/java/WsMessage.java +18 -0
- package/dist/runtime/mcp/call.ts +167 -0
- package/dist/runtime/mcp/files.ts +183 -0
- package/dist/runtime/mcp/guard.ts +176 -0
- package/dist/runtime/mcp/http.ts +159 -0
- package/dist/runtime/mcp/jsonrpc.ts +50 -0
- package/dist/runtime/mcp/listen.ts +76 -0
- package/dist/runtime/mcp/mount.ts +123 -0
- package/dist/runtime/mcp/protocol.ts +219 -0
- package/dist/runtime/mcp/reader.ts +57 -0
- package/dist/runtime/mcp/result.ts +85 -0
- package/dist/runtime/mcp/stdio.ts +79 -0
- package/dist/runtime/mcp/stream.ts +62 -0
- package/dist/runtime/python/__init__.py +2 -0
- package/dist/runtime/python/auth.py +67 -0
- package/dist/runtime/python/body.py +83 -0
- package/dist/runtime/python/config.py +139 -0
- package/dist/runtime/python/errors.py +213 -0
- package/dist/runtime/python/events.py +152 -0
- package/dist/runtime/python/exchange.py +298 -0
- package/dist/runtime/python/hooks.py +86 -0
- package/dist/runtime/python/invalidation.py +57 -0
- package/dist/runtime/python/log.py +60 -0
- package/dist/runtime/python/operation.py +25 -0
- package/dist/runtime/python/path.py +41 -0
- package/dist/runtime/python/query.py +48 -0
- package/dist/runtime/python/realtime.py +244 -0
- package/dist/runtime/python/redirect.py +93 -0
- package/dist/runtime/python/result.py +58 -0
- package/dist/runtime/python/send_async.py +189 -0
- package/dist/runtime/python/send_sync.py +105 -0
- package/dist/runtime/python/sse.py +81 -0
- package/dist/runtime/python/stale.py +94 -0
- package/dist/runtime/python/transport.py +157 -0
- package/dist/runtime/python/transport_longpoll.py +60 -0
- package/dist/runtime/python/transport_sse.py +60 -0
- package/dist/runtime/python/transport_ws.py +57 -0
- package/dist/runtime/python/ws.py +276 -0
- package/dist/runtime/rust/Cargo.lock +1763 -0
- package/dist/runtime/rust/answer.rs +120 -0
- package/dist/runtime/rust/auth.rs +80 -0
- package/dist/runtime/rust/body.rs +150 -0
- package/dist/runtime/rust/call.rs +200 -0
- package/dist/runtime/rust/config.rs +254 -0
- package/dist/runtime/rust/envelope.rs +84 -0
- package/dist/runtime/rust/errors.rs +235 -0
- package/dist/runtime/rust/events.rs +177 -0
- package/dist/runtime/rust/exchange.rs +287 -0
- package/dist/runtime/rust/hooks.rs +63 -0
- package/dist/runtime/rust/invalidation.rs +84 -0
- package/dist/runtime/rust/log.rs +88 -0
- package/dist/runtime/rust/nullable.rs +13 -0
- package/dist/runtime/rust/path.rs +83 -0
- package/dist/runtime/rust/query.rs +84 -0
- package/dist/runtime/rust/realtime.rs +182 -0
- package/dist/runtime/rust/realtime_loop.rs +177 -0
- package/dist/runtime/rust/redirect.rs +121 -0
- package/dist/runtime/rust/request.rs +178 -0
- package/dist/runtime/rust/result.rs +101 -0
- package/dist/runtime/rust/sse.rs +104 -0
- package/dist/runtime/rust/stale.rs +209 -0
- package/dist/runtime/rust/transport.rs +221 -0
- package/dist/runtime/rust/transport_longpoll.rs +108 -0
- package/dist/runtime/rust/transport_sse.rs +91 -0
- package/dist/runtime/rust/transport_ws.rs +75 -0
- package/dist/runtime/rust/ws.rs +322 -0
- package/dist/runtime/ts/app-types.ts +200 -0
- package/dist/runtime/ts/app.ts +104 -0
- package/dist/runtime/ts/config.ts +124 -0
- package/dist/runtime/ts/defaults.ts +48 -0
- package/dist/runtime/ts/error.ts +113 -0
- package/dist/runtime/ts/hooks.ts +92 -0
- package/dist/runtime/ts/http.ts +228 -0
- package/dist/runtime/ts/media-type.ts +36 -0
- package/dist/runtime/ts/path.ts +152 -0
- package/dist/runtime/ts/realtime-connection.ts +296 -0
- package/dist/runtime/ts/realtime-transports.ts +149 -0
- package/dist/runtime/ts/realtime.ts +293 -0
- package/dist/runtime/ts/redirect-policy.ts +17 -0
- package/dist/runtime/ts/redirects.ts +74 -0
- package/dist/runtime/ts/request.ts +239 -0
- package/dist/runtime/ts/response.ts +219 -0
- package/dist/runtime/ts/sdk-realtime.ts +10 -0
- package/dist/runtime/ts/sdk-sse.ts +55 -0
- package/dist/runtime/ts/sdk-ws.ts +21 -0
- package/dist/runtime/ts/sdk.ts +242 -0
- package/dist/runtime/ts/sse.ts +175 -0
- package/dist/runtime/ts/stale.ts +137 -0
- package/dist/runtime/ts/stream.ts +87 -0
- package/dist/runtime/ts/webhook.ts +116 -0
- package/dist/runtime/ts/ws.ts +155 -0
- package/dist/runtime/ts-tanstack-query/invalidate.ts +152 -0
- package/dist/runtime/ts-tanstack-query/query.ts +261 -0
- package/package.json +135 -5
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// Code generated by honey. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package sdk
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"context"
|
|
7
|
+
"encoding/json"
|
|
8
|
+
"errors"
|
|
9
|
+
"io"
|
|
10
|
+
"net"
|
|
11
|
+
"strings"
|
|
12
|
+
"sync"
|
|
13
|
+
"time"
|
|
14
|
+
"unicode/utf8"
|
|
15
|
+
|
|
16
|
+
"github.com/coder/websocket"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
// WebSocket close codes.
|
|
20
|
+
const (
|
|
21
|
+
WSStatusNormalClosure = websocket.StatusNormalClosure
|
|
22
|
+
WSStatusGoingAway = websocket.StatusGoingAway
|
|
23
|
+
WSStatusProtocolError = websocket.StatusProtocolError
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
// defaultWSReadLimit replaces the library's 32 KiB default, which closes the connection on any
|
|
27
|
+
// larger message.
|
|
28
|
+
const defaultWSReadLimit = 16 << 20
|
|
29
|
+
|
|
30
|
+
// maxCloseReason is the most bytes a close frame's reason may hold.
|
|
31
|
+
const maxCloseReason = 123
|
|
32
|
+
|
|
33
|
+
// keepAlive pings conn every `every` (zero: 20s; negative: never), closing it on a ping unanswered as long.
|
|
34
|
+
func keepAlive(conn *websocket.Conn, every time.Duration) func() {
|
|
35
|
+
ctx, stop := context.WithCancel(context.Background())
|
|
36
|
+
if every == 0 {
|
|
37
|
+
every = 20 * time.Second
|
|
38
|
+
}
|
|
39
|
+
if every < 0 {
|
|
40
|
+
return stop
|
|
41
|
+
}
|
|
42
|
+
go func() {
|
|
43
|
+
ticker := time.NewTicker(every)
|
|
44
|
+
defer ticker.Stop()
|
|
45
|
+
for {
|
|
46
|
+
select {
|
|
47
|
+
case <-ctx.Done():
|
|
48
|
+
return
|
|
49
|
+
case <-ticker.C:
|
|
50
|
+
}
|
|
51
|
+
ping, cancel := context.WithTimeout(ctx, every)
|
|
52
|
+
err := conn.Ping(ping)
|
|
53
|
+
cancel()
|
|
54
|
+
if err != nil {
|
|
55
|
+
if ctx.Err() == nil {
|
|
56
|
+
_ = conn.CloseNow()
|
|
57
|
+
}
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}()
|
|
62
|
+
return stop
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// TypedWebSocket is an operation's WebSocket: Send and Read, plus On handlers as the TypeScript
|
|
66
|
+
// client's escape hatch. Its dial runs no OnRequest or OnResponse hook, and a refused handshake's
|
|
67
|
+
// 401 is its error, with no OnAuthExpired refresh.
|
|
68
|
+
type TypedWebSocket struct {
|
|
69
|
+
conn *websocket.Conn
|
|
70
|
+
stop func()
|
|
71
|
+
mu sync.Mutex
|
|
72
|
+
handlers map[string][]func(data []byte)
|
|
73
|
+
closed bool
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// dialWebSocket opens the call's WebSocket with the client's auth, headers and redirect policy. A
|
|
77
|
+
// refused handshake with an error status is a typed error, as for any other call.
|
|
78
|
+
func dialWebSocket(ctx context.Context, cfg Config, c *call, opts []RequestOption) (*TypedWebSocket, error) {
|
|
79
|
+
rc := newRequestConfig(cfg, opts)
|
|
80
|
+
u, err := buildURL(rc.baseURL, c.path, c.query)
|
|
81
|
+
if err != nil {
|
|
82
|
+
return nil, err
|
|
83
|
+
}
|
|
84
|
+
dialOpts := &websocket.DialOptions{
|
|
85
|
+
HTTPClient: streamClient(cfg),
|
|
86
|
+
HTTPHeader: withRequestID(mergeHeaders(cfg, cfg.auth.current(cfg), "", c.headers, rc.headers)),
|
|
87
|
+
Subprotocols: c.protocols,
|
|
88
|
+
}
|
|
89
|
+
conn, resp, err := websocket.Dial(ctx, toWsURL(u), dialOpts)
|
|
90
|
+
if err != nil {
|
|
91
|
+
if resp != nil && resp.Body != nil {
|
|
92
|
+
body, _ := io.ReadAll(resp.Body)
|
|
93
|
+
rc.deliver(resp, body)
|
|
94
|
+
if apiErr := raiseForStatus(resp, body); apiErr != nil {
|
|
95
|
+
return nil, apiErr
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return nil, wrapTransportError(ctx, err)
|
|
99
|
+
}
|
|
100
|
+
rc.deliver(resp, nil)
|
|
101
|
+
return newTypedWebSocket(conn, cfg.WSKeepalive), nil
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
func newTypedWebSocket(conn *websocket.Conn, every time.Duration) *TypedWebSocket {
|
|
105
|
+
conn.SetReadLimit(defaultWSReadLimit)
|
|
106
|
+
return &TypedWebSocket{conn: conn, stop: keepAlive(conn, every), handlers: map[string][]func(data []byte){}}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// SetReadLimit sets the largest inbound message, in bytes (default 16 MiB).
|
|
110
|
+
func (w *TypedWebSocket) SetReadLimit(n int64) {
|
|
111
|
+
w.conn.SetReadLimit(n)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Send writes a []byte as a binary frame, a string as a text frame, and anything else as JSON text.
|
|
115
|
+
func (w *TypedWebSocket) Send(ctx context.Context, data any) error {
|
|
116
|
+
return writeFrame(ctx, w.conn, data)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
func writeFrame(ctx context.Context, conn *websocket.Conn, data any) error {
|
|
120
|
+
switch v := data.(type) {
|
|
121
|
+
case []byte:
|
|
122
|
+
return conn.Write(ctx, websocket.MessageBinary, v)
|
|
123
|
+
case string:
|
|
124
|
+
return conn.Write(ctx, websocket.MessageText, []byte(v))
|
|
125
|
+
}
|
|
126
|
+
encoded, err := json.Marshal(data)
|
|
127
|
+
if err != nil {
|
|
128
|
+
return err
|
|
129
|
+
}
|
|
130
|
+
return conn.Write(ctx, websocket.MessageText, encoded)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Close sends a close frame with code and reason, the reason cut at a rune boundary to fit 123
|
|
134
|
+
// bytes. On a conn already closed it returns nil.
|
|
135
|
+
func (w *TypedWebSocket) Close(code websocket.StatusCode, reason string) error {
|
|
136
|
+
for len(reason) > maxCloseReason {
|
|
137
|
+
_, size := utf8.DecodeLastRuneInString(reason)
|
|
138
|
+
reason = reason[:len(reason)-size]
|
|
139
|
+
}
|
|
140
|
+
w.stop()
|
|
141
|
+
err := w.conn.Close(code, reason)
|
|
142
|
+
w.fireClose(reason)
|
|
143
|
+
if errors.Is(err, net.ErrClosed) {
|
|
144
|
+
return nil
|
|
145
|
+
}
|
|
146
|
+
return err
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Read returns the next message. A close frame fires the "close" handlers with its reason; any
|
|
150
|
+
// other failure fires "error" with the error text.
|
|
151
|
+
func (w *TypedWebSocket) Read(ctx context.Context) ([]byte, error) {
|
|
152
|
+
_, msg, err := w.conn.Read(ctx)
|
|
153
|
+
if err != nil {
|
|
154
|
+
w.stop()
|
|
155
|
+
var ce websocket.CloseError
|
|
156
|
+
if errors.As(err, &ce) {
|
|
157
|
+
w.fireClose(ce.Reason)
|
|
158
|
+
} else {
|
|
159
|
+
w.fanout("error", []byte(err.Error()))
|
|
160
|
+
}
|
|
161
|
+
return nil, err
|
|
162
|
+
}
|
|
163
|
+
w.fanout("message", msg)
|
|
164
|
+
return msg, nil
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// On registers a handler for "message", "close" or "error". It receives the raw bytes; prefer a
|
|
168
|
+
// Read loop for typed dispatch. A "close" handler gets the reason; the code is in Read's error:
|
|
169
|
+
// websocket.CloseStatus(err).
|
|
170
|
+
func (w *TypedWebSocket) On(event string, handler func(data []byte)) {
|
|
171
|
+
w.mu.Lock()
|
|
172
|
+
defer w.mu.Unlock()
|
|
173
|
+
w.handlers[event] = append(w.handlers[event], handler)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
func (w *TypedWebSocket) fireClose(reason string) {
|
|
177
|
+
w.mu.Lock()
|
|
178
|
+
if w.closed {
|
|
179
|
+
w.mu.Unlock()
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
w.closed = true
|
|
183
|
+
w.mu.Unlock()
|
|
184
|
+
w.fanout("close", []byte(reason))
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
func (w *TypedWebSocket) fanout(event string, data []byte) {
|
|
188
|
+
w.mu.Lock()
|
|
189
|
+
handlers := append([]func([]byte){}, w.handlers[event]...)
|
|
190
|
+
w.mu.Unlock()
|
|
191
|
+
for _, h := range handlers {
|
|
192
|
+
h(data)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// toWsURL swaps an http(s) scheme for ws(s); a URL inside the query is untouched.
|
|
197
|
+
func toWsURL(u string) string {
|
|
198
|
+
if rest, ok := strings.CutPrefix(u, "https://"); ok {
|
|
199
|
+
return "wss://" + rest
|
|
200
|
+
}
|
|
201
|
+
if rest, ok := strings.CutPrefix(u, "http://"); ok {
|
|
202
|
+
return "ws://" + rest
|
|
203
|
+
}
|
|
204
|
+
return u
|
|
205
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.util.Locale;
|
|
5
|
+
import java.util.Map;
|
|
6
|
+
import java.util.function.Consumer;
|
|
7
|
+
import java.util.function.Function;
|
|
8
|
+
import tools.jackson.core.JacksonException;
|
|
9
|
+
import tools.jackson.core.type.TypeReference;
|
|
10
|
+
|
|
11
|
+
/** A call's answer. Each reader throws the error, or answers as the call's type. */
|
|
12
|
+
record Answer(String route, RawResponse raw, ApiException error, byte[] body) {
|
|
13
|
+
|
|
14
|
+
<T> T json(TypeReference<T> type) {
|
|
15
|
+
check();
|
|
16
|
+
return decode(type);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
String text() {
|
|
20
|
+
check();
|
|
21
|
+
return new String(body, java.nio.charset.StandardCharsets.UTF_8);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
byte[] bytes() {
|
|
25
|
+
check();
|
|
26
|
+
return body.clone();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
void none() {
|
|
30
|
+
check();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A safe twin's Result: {@code call} given a raw box; an answer it throws is the Err. */
|
|
34
|
+
static <T> Result<T> safe(RequestOptions options, Function<RequestOptions, T> call) {
|
|
35
|
+
RequestOptions given = options == null ? RequestOptions.NONE : options;
|
|
36
|
+
RawResponse raw = given.raw() != null ? given.raw() : new RawResponse();
|
|
37
|
+
try {
|
|
38
|
+
return new Result.Ok<>(call.apply(given.boxed(raw)), raw);
|
|
39
|
+
} catch (SdkException e) {
|
|
40
|
+
return new Result.Err<>(e, raw);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** {@link #safe} for a call with no body. */
|
|
45
|
+
static Result<Void> safeNone(RequestOptions options, Consumer<RequestOptions> call) {
|
|
46
|
+
return safe(
|
|
47
|
+
options,
|
|
48
|
+
o -> {
|
|
49
|
+
call.accept(o);
|
|
50
|
+
return null;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A declared response header's value, parsed: null when an optional header is absent. A missing
|
|
56
|
+
* required header, or one that does not parse, is a DecodeException.
|
|
57
|
+
*/
|
|
58
|
+
static <T> T header(
|
|
59
|
+
Map<String, String> headers,
|
|
60
|
+
String name,
|
|
61
|
+
boolean required,
|
|
62
|
+
String kind,
|
|
63
|
+
Function<String, T> parse) {
|
|
64
|
+
String value = headers.get(name.toLowerCase(Locale.ROOT));
|
|
65
|
+
if (value == null) {
|
|
66
|
+
if (required) {
|
|
67
|
+
throw new DecodeException("the " + name + " header is missing", null);
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
return parse.apply(value);
|
|
73
|
+
} catch (IllegalArgumentException e) {
|
|
74
|
+
throw new DecodeException("the " + name + " header is not a valid " + kind, null);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A boolean header: exactly {@code true} or {@code false}, anything else is an
|
|
80
|
+
* IllegalArgumentException.
|
|
81
|
+
*/
|
|
82
|
+
static Boolean flag(String value) {
|
|
83
|
+
if ("true".equals(value) || "false".equals(value)) {
|
|
84
|
+
return Boolean.valueOf(value);
|
|
85
|
+
}
|
|
86
|
+
throw new IllegalArgumentException("not a boolean: " + value);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private void check() {
|
|
90
|
+
if (error != null) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private <T> T decode(TypeReference<T> type) {
|
|
96
|
+
T value;
|
|
97
|
+
try {
|
|
98
|
+
value = Json.MAPPER.readValue(body, type);
|
|
99
|
+
} catch (JacksonException e) {
|
|
100
|
+
throw new DecodeException(route + ": the answer does not decode: " + e.getMessage(), e);
|
|
101
|
+
}
|
|
102
|
+
if (value == null) {
|
|
103
|
+
throw new DecodeException(route + ": the answer is null", null);
|
|
104
|
+
}
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.util.Map;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A status outside 2xx: one subclass per common status, {@link UnexpectedStatusException} for the
|
|
8
|
+
* rest. Its message is {@code HTTP <status>: <detail>}, or {@code HTTP <status>} without a detail.
|
|
9
|
+
* Java serialization keeps status, message, detail, body and key; headers() and envelope() return
|
|
10
|
+
* null. The SDK never serializes exceptions; -Xlint:serial only forces the declaration.
|
|
11
|
+
*/
|
|
12
|
+
public abstract class ApiException extends SdkException {
|
|
13
|
+
private static final long serialVersionUID = 1L;
|
|
14
|
+
|
|
15
|
+
private final int status;
|
|
16
|
+
private final transient Map<String, String> headers;
|
|
17
|
+
private final byte[] body;
|
|
18
|
+
private final transient ErrorEnvelope envelope;
|
|
19
|
+
private final String detail;
|
|
20
|
+
private final String key;
|
|
21
|
+
|
|
22
|
+
ApiException(Failure failure) {
|
|
23
|
+
this(failure, Envelope.parse(failure.body()));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private ApiException(Failure failure, ErrorEnvelope envelope) {
|
|
27
|
+
this(failure, envelope, Envelope.detail(envelope, failure.body()));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private ApiException(Failure failure, ErrorEnvelope envelope, String detail) {
|
|
31
|
+
super(
|
|
32
|
+
detail.isEmpty() ? "HTTP " + failure.status() : "HTTP " + failure.status() + ": " + detail,
|
|
33
|
+
null);
|
|
34
|
+
this.status = failure.status();
|
|
35
|
+
this.headers = failure.headers();
|
|
36
|
+
this.body = failure.body();
|
|
37
|
+
this.envelope = envelope;
|
|
38
|
+
this.detail = detail;
|
|
39
|
+
this.key = envelope.errorKey();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The HTTP status. */
|
|
43
|
+
public final int status() {
|
|
44
|
+
return status;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Each header by lower-case name. */
|
|
48
|
+
public final Map<String, String> headers() {
|
|
49
|
+
return headers;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The body as received. */
|
|
53
|
+
public final byte[] body() {
|
|
54
|
+
return body.clone();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The body's {@code error_key} as the server sent it, else null. */
|
|
58
|
+
public final String key() {
|
|
59
|
+
return key;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The body's envelope: empty for a body that is no JSON object. */
|
|
63
|
+
public final ErrorEnvelope envelope() {
|
|
64
|
+
return envelope;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public final String detail() {
|
|
68
|
+
return detail;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The body as {@code type}, through the SDK's mapper; a {@link DecodeException} when it does not
|
|
73
|
+
* decode.
|
|
74
|
+
*/
|
|
75
|
+
public final <T> T decodeBody(Class<T> type) {
|
|
76
|
+
T value;
|
|
77
|
+
try {
|
|
78
|
+
value = Json.MAPPER.readValue(body, type);
|
|
79
|
+
} catch (RuntimeException e) {
|
|
80
|
+
String what =
|
|
81
|
+
Envelope.isJson(body) ? "does not decode as " + type.getSimpleName() : "is not JSON";
|
|
82
|
+
throw new DecodeException("HTTP " + status + ": the body " + what, e);
|
|
83
|
+
}
|
|
84
|
+
if (value == null) {
|
|
85
|
+
throw new DecodeException("HTTP " + status + ": the body is null", null);
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The error an error status throws: its subclass, its message. */
|
|
91
|
+
static ApiException of(Failure failure) {
|
|
92
|
+
return switch (failure.status()) {
|
|
93
|
+
case 400 -> new BadRequestException(failure);
|
|
94
|
+
case 401 -> new UnauthorizedException(failure);
|
|
95
|
+
case 403 -> new ForbiddenException(failure);
|
|
96
|
+
case 404 -> new NotFoundException(failure);
|
|
97
|
+
case 409 -> new ConflictException(failure);
|
|
98
|
+
case 422 -> new UnprocessableEntityException(failure);
|
|
99
|
+
case 429 -> new RateLimitException(failure);
|
|
100
|
+
case 500 -> new InternalServerException(failure);
|
|
101
|
+
case 502 -> new BadGatewayException(failure);
|
|
102
|
+
case 503 -> new ServiceUnavailableException(failure);
|
|
103
|
+
case 504 -> new GatewayTimeoutException(failure);
|
|
104
|
+
default -> new UnexpectedStatusException(failure);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** What an error status carries: its status, headers and body. */
|
|
109
|
+
record Failure(int status, Map<String, String> headers, byte[] body) {}
|
|
110
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.io.InputStream;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A binary request body: sized bytes, resent on a retry, or a one-shot stream, sent chunked and
|
|
8
|
+
* never resent. Build one with {@link #of(byte[])} or {@link #of(InputStream)}.
|
|
9
|
+
*/
|
|
10
|
+
public final class BinaryBody {
|
|
11
|
+
private final byte[] bytes;
|
|
12
|
+
private final InputStream stream;
|
|
13
|
+
|
|
14
|
+
private BinaryBody(byte[] bytes, InputStream stream) {
|
|
15
|
+
this.bytes = bytes;
|
|
16
|
+
this.stream = stream;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A sized body of {@code bytes}, resent as it is. */
|
|
20
|
+
public static BinaryBody of(byte[] bytes) {
|
|
21
|
+
return new BinaryBody(bytes.clone(), null);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A one-shot body read from {@code stream}, sent chunked; never resent. */
|
|
25
|
+
public static BinaryBody of(InputStream stream) {
|
|
26
|
+
return new BinaryBody(null, stream);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
byte[] bytes() {
|
|
30
|
+
return bytes == null ? null : bytes.clone();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
InputStream stream() {
|
|
34
|
+
return stream;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.io.ByteArrayOutputStream;
|
|
5
|
+
import java.io.InputStream;
|
|
6
|
+
import java.nio.charset.StandardCharsets;
|
|
7
|
+
import java.util.ArrayList;
|
|
8
|
+
import java.util.List;
|
|
9
|
+
import java.util.UUID;
|
|
10
|
+
import tools.jackson.databind.JsonNode;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A request body as sent: its bytes or its one-shot stream, and its media type. A null value has no
|
|
14
|
+
* body.
|
|
15
|
+
*/
|
|
16
|
+
record Body(byte[] bytes, InputStream stream, String mediaType) {
|
|
17
|
+
/** Whether a retry may send it again: every body but a one-shot stream. */
|
|
18
|
+
boolean replayable() {
|
|
19
|
+
return stream == null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static Body json(Object value, String mediaType) {
|
|
23
|
+
return value == null ? null : new Body(Json.MAPPER.writeValueAsBytes(value), null, mediaType);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static Body text(String value, String mediaType) {
|
|
27
|
+
return value == null ? null : new Body(value.getBytes(StandardCharsets.UTF_8), null, mediaType);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static Body binary(BinaryBody value, String mediaType) {
|
|
31
|
+
if (value == null) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return new Body(value.bytes(), value.stream(), mediaType);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static Body form(Object value) {
|
|
38
|
+
if (value == null) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
List<Call.Arg> args = new ArrayList<>();
|
|
42
|
+
JsonNode node = Json.MAPPER.valueToTree(value);
|
|
43
|
+
for (var member : node.properties()) {
|
|
44
|
+
args.add(new Call.Arg(member.getKey(), member.getValue()));
|
|
45
|
+
}
|
|
46
|
+
byte[] bytes = UrlQuery.encode(args).getBytes(StandardCharsets.UTF_8);
|
|
47
|
+
return new Body(bytes, null, "application/x-www-form-urlencoded");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The multipart body of {@code parts} under a fresh {@code honey-<uuid>} boundary. */
|
|
51
|
+
static Body multipart(List<Part> parts) {
|
|
52
|
+
if (parts == null) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
String mark = "honey-" + UUID.randomUUID();
|
|
56
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
57
|
+
for (Part part : parts) {
|
|
58
|
+
for (Object item : part.items()) {
|
|
59
|
+
writePart(out, mark, part.name(), item);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
out.writeBytes(("--" + mark + "--\r\n").getBytes(StandardCharsets.UTF_8));
|
|
63
|
+
return new Body(out.toByteArray(), null, "multipart/form-data; boundary=" + mark);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private static void writePart(ByteArrayOutputStream out, String mark, String name, Object item) {
|
|
67
|
+
String head = "--" + mark + "\r\nContent-Disposition: form-data; name=\"" + quoted(name) + "\"";
|
|
68
|
+
if (item instanceof FilePart file) {
|
|
69
|
+
head +=
|
|
70
|
+
"; filename=\""
|
|
71
|
+
+ quoted(file.fileName())
|
|
72
|
+
+ "\"\r\nContent-Type: "
|
|
73
|
+
+ quoted(file.contentType());
|
|
74
|
+
out.writeBytes((head + "\r\n\r\n").getBytes(StandardCharsets.UTF_8));
|
|
75
|
+
out.writeBytes(file.data());
|
|
76
|
+
} else {
|
|
77
|
+
out.writeBytes((head + "\r\n\r\n").getBytes(StandardCharsets.UTF_8));
|
|
78
|
+
out.writeBytes(((String) item).getBytes(StandardCharsets.UTF_8));
|
|
79
|
+
}
|
|
80
|
+
out.writeBytes("\r\n".getBytes(StandardCharsets.UTF_8));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private static String quoted(String raw) {
|
|
84
|
+
return raw.replace("\r", "%0D").replace("\n", "%0A").replace("\"", "%22");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A multipart part: its wire name and its items, each a {@link FilePart} or a text. */
|
|
88
|
+
record Part(String name, List<Object> items) {
|
|
89
|
+
/** A text part: each item of an array, or the one value, as its text. */
|
|
90
|
+
static Part text(String name, Object value) {
|
|
91
|
+
JsonNode node = value == null ? null : Json.MAPPER.valueToTree(value);
|
|
92
|
+
return new Part(name, new ArrayList<Object>(UrlQuery.texts(node)));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** A file part, empty when unset. */
|
|
96
|
+
static Part file(String name, FilePart file) {
|
|
97
|
+
return new Part(name, file == null ? List.of() : List.<Object>of(file));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A part of each file in {@code files}. */
|
|
101
|
+
static Part files(String name, List<FilePart> files) {
|
|
102
|
+
return new Part(name, files == null ? List.of() : new ArrayList<Object>(files));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.util.List;
|
|
5
|
+
import tools.jackson.databind.JsonNode;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* One call's values: its path values in the operation's path order, its query and header args, and
|
|
9
|
+
* its body.
|
|
10
|
+
*/
|
|
11
|
+
record Call(String[] path, List<Arg> query, List<Arg> headers, Body body) {
|
|
12
|
+
/** One named argument: its value as the mapper writes it, null when unset. */
|
|
13
|
+
record Arg(String name, JsonNode value) {
|
|
14
|
+
static Arg of(String name, Object value) {
|
|
15
|
+
return new Arg(name, value == null ? null : Json.MAPPER.valueToTree(value));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A stream cursor's arg: nothing sent when it is unset or empty. */
|
|
19
|
+
static Arg cursor(String name, String value) {
|
|
20
|
+
return of(name, value == null || value.isEmpty() ? null : value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.util.function.Consumer;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A call's log lines, told to the client's log as they happen; a failing log never fails the call.
|
|
8
|
+
*/
|
|
9
|
+
final class CallLog {
|
|
10
|
+
private final Consumer<LogEntry> log;
|
|
11
|
+
private final String operation;
|
|
12
|
+
private final long start = System.nanoTime();
|
|
13
|
+
|
|
14
|
+
CallLog(Consumer<LogEntry> log, String operation) {
|
|
15
|
+
this.log = log;
|
|
16
|
+
this.operation = operation;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
void start() {
|
|
20
|
+
emit("debug", "request_start", 0, null, null);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void received(int status) {
|
|
24
|
+
emit(status >= 400 ? "warn" : "info", "response_received", elapsed(), status, null);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
void failed(Throwable error, java.lang.Integer status) {
|
|
28
|
+
String text = error.getClass().getSimpleName() + ": " + error.getMessage();
|
|
29
|
+
emit("error", "error", elapsed(), status, text);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
void canceled() {
|
|
33
|
+
emit("error", "error", elapsed(), null, "the call was canceled");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private long elapsed() {
|
|
37
|
+
return (System.nanoTime() - start) / 1_000_000;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private void emit(
|
|
41
|
+
String level, String event, long durationMs, java.lang.Integer status, String error) {
|
|
42
|
+
if (log == null) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
log.accept(new LogEntry(level, event, operation, durationMs, status, error));
|
|
47
|
+
} catch (RuntimeException e) {
|
|
48
|
+
/* a logger's failure is not the call's */
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|