@workerstack/clients 0.0.0-stage → 1.0.0-rc.23
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 +84 -5
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.io.IOException;
|
|
5
|
+
import java.io.InputStream;
|
|
6
|
+
import java.io.InterruptedIOException;
|
|
7
|
+
import java.time.Duration;
|
|
8
|
+
import java.util.Iterator;
|
|
9
|
+
import java.util.NoSuchElementException;
|
|
10
|
+
import java.util.concurrent.CancellationException;
|
|
11
|
+
import tools.jackson.core.JacksonException;
|
|
12
|
+
import tools.jackson.core.type.TypeReference;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* An open event stream, read once as an {@code Iterable} of {@link SseEvent}. Its connection is let
|
|
16
|
+
* go by its end: the server's end, an error (thrown once, then the end), {@link #close()} from any
|
|
17
|
+
* thread (a pending read then ends quietly), or an interrupt of the reading thread (a {@link
|
|
18
|
+
* CancellationException}). Open it in try-with-resources: a for-each break without one keeps the
|
|
19
|
+
* connection. No timeout bounds it once open.
|
|
20
|
+
*/
|
|
21
|
+
public final class EventStream<T> implements Iterable<SseEvent<T>>, AutoCloseable {
|
|
22
|
+
private final InputStream body;
|
|
23
|
+
private final Sse parser;
|
|
24
|
+
private final TypeReference<T> type;
|
|
25
|
+
private boolean taken;
|
|
26
|
+
private volatile boolean closed;
|
|
27
|
+
private boolean ended;
|
|
28
|
+
private SseEvent<T> pending;
|
|
29
|
+
private String lastEventId = "";
|
|
30
|
+
|
|
31
|
+
EventStream(InputStream body, TypeReference<T> type) {
|
|
32
|
+
this.body = body;
|
|
33
|
+
this.parser = new Sse(body);
|
|
34
|
+
this.type = type;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The id of the last event read, empty before any. */
|
|
38
|
+
public String lastEventId() {
|
|
39
|
+
return lastEventId;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The stream's one iterator; a second call throws IllegalStateException. */
|
|
43
|
+
@Override
|
|
44
|
+
public synchronized Iterator<SseEvent<T>> iterator() {
|
|
45
|
+
if (taken) {
|
|
46
|
+
throw new IllegalStateException("an EventStream is read once");
|
|
47
|
+
}
|
|
48
|
+
taken = true;
|
|
49
|
+
return new Iterator<>() {
|
|
50
|
+
@Override
|
|
51
|
+
public boolean hasNext() {
|
|
52
|
+
return advance();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Override
|
|
56
|
+
public SseEvent<T> next() {
|
|
57
|
+
if (!advance()) {
|
|
58
|
+
throw new NoSuchElementException("the event stream ended");
|
|
59
|
+
}
|
|
60
|
+
SseEvent<T> event = pending;
|
|
61
|
+
pending = null;
|
|
62
|
+
lastEventId = event.id() == null ? "" : event.id();
|
|
63
|
+
return event;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private boolean advance() {
|
|
69
|
+
if (pending != null) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
if (ended || closed) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
Sse.Event event = parser.next();
|
|
77
|
+
if (event == null) {
|
|
78
|
+
end();
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
pending = decoded(event);
|
|
82
|
+
return true;
|
|
83
|
+
} catch (InterruptedIOException e) {
|
|
84
|
+
end();
|
|
85
|
+
throw new CancellationException("the stream was canceled");
|
|
86
|
+
} catch (IOException e) {
|
|
87
|
+
if (closed) {
|
|
88
|
+
end();
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
end();
|
|
92
|
+
throw new ApiConnectionException("the event stream failed", e);
|
|
93
|
+
} catch (RuntimeException e) {
|
|
94
|
+
end();
|
|
95
|
+
throw e;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@SuppressWarnings("unchecked")
|
|
100
|
+
private SseEvent<T> decoded(Sse.Event event) {
|
|
101
|
+
Duration retry = event.retry() == null ? null : Duration.ofMillis(event.retry());
|
|
102
|
+
T data;
|
|
103
|
+
if (type.getType() == String.class) {
|
|
104
|
+
data = (T) event.data();
|
|
105
|
+
} else {
|
|
106
|
+
try {
|
|
107
|
+
data = Json.MAPPER.readValue(event.data(), type);
|
|
108
|
+
} catch (JacksonException e) {
|
|
109
|
+
throw new DecodeException("an event's data does not decode: " + e.getOriginalMessage(), e);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return new SseEvent<>(data, event.event(), event.id(), retry);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private void end() {
|
|
116
|
+
ended = true;
|
|
117
|
+
close();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Lets the connection go; a read pending on another thread ends quietly. Closing twice is one
|
|
122
|
+
* close.
|
|
123
|
+
*/
|
|
124
|
+
@Override
|
|
125
|
+
public void close() {
|
|
126
|
+
closed = true;
|
|
127
|
+
Pump.release(body);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.net.http.HttpClient;
|
|
5
|
+
import java.util.Map;
|
|
6
|
+
import java.util.function.Consumer;
|
|
7
|
+
import tools.jackson.core.type.TypeReference;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A client's exchange: its config, its one HTTP client (never following a redirect on its own), its
|
|
11
|
+
* credential.
|
|
12
|
+
*/
|
|
13
|
+
final class Exchange {
|
|
14
|
+
private final ClientConfig config;
|
|
15
|
+
private final HttpClient http;
|
|
16
|
+
private final Credential credential;
|
|
17
|
+
private final StaleTracker stale;
|
|
18
|
+
|
|
19
|
+
Exchange(ClientConfig config) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.http = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NEVER).build();
|
|
22
|
+
this.credential = new Credential(config);
|
|
23
|
+
this.stale = new StaleTracker(config.invalidation());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Runs one call: its answer, its error status included; every other failure throws. */
|
|
27
|
+
Answer run(Operation op, Call call, RequestOptions options) {
|
|
28
|
+
return new Flight(this, op, call, options).run();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Opens one stream call: its events, once an error status has not thrown. */
|
|
32
|
+
<T> EventStream<T> events(
|
|
33
|
+
Operation op,
|
|
34
|
+
Call call,
|
|
35
|
+
RequestOptions options,
|
|
36
|
+
Consumer<Map<String, String>> headers,
|
|
37
|
+
TypeReference<T> type) {
|
|
38
|
+
return new Flight(this, op, call, options).events(headers, type);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Flight dial(Operation op, Call call, RequestOptions options) {
|
|
42
|
+
Flight flight = new Flight(this, op, call, options);
|
|
43
|
+
flight.dial = true;
|
|
44
|
+
return flight;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ClientConfig config() {
|
|
48
|
+
return config;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
HttpClient http() {
|
|
52
|
+
return http;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Credential credential() {
|
|
56
|
+
return credential;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
StaleTracker stale() {
|
|
60
|
+
return stale;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.io.IOException;
|
|
5
|
+
import java.io.InputStream;
|
|
6
|
+
import java.io.InterruptedIOException;
|
|
7
|
+
import java.net.URI;
|
|
8
|
+
import java.net.http.HttpResponse;
|
|
9
|
+
import java.nio.ByteBuffer;
|
|
10
|
+
import java.time.Duration;
|
|
11
|
+
import java.util.List;
|
|
12
|
+
import java.util.Locale;
|
|
13
|
+
import java.util.Map;
|
|
14
|
+
import java.util.TreeMap;
|
|
15
|
+
import java.util.UUID;
|
|
16
|
+
import java.util.concurrent.CancellationException;
|
|
17
|
+
import java.util.concurrent.Flow;
|
|
18
|
+
import java.util.function.Consumer;
|
|
19
|
+
import java.util.function.Function;
|
|
20
|
+
import tools.jackson.core.type.TypeReference;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* One call's exchange: its hops, its auth retry, and its one deadline over all of them, which
|
|
24
|
+
* cancels the hop in flight when it lapses. Hooks run once per attempt, before its first hop; the
|
|
25
|
+
* SDK's own redirect loop then sends each hop from the hook's headers. A stream's open is the same
|
|
26
|
+
* exchange with its 2xx body left live: the deadline bounds the open up to the headers, and an
|
|
27
|
+
* error status's body is read at most 64 KiB.
|
|
28
|
+
*/
|
|
29
|
+
final class Flight {
|
|
30
|
+
/** The most of a refused stream open's body read: 64 KiB. */
|
|
31
|
+
private static final int ERROR_CAP = 64 * 1024;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* One hop's answer: its status, headers, decoded body, the URL that answered, a stream's live
|
|
35
|
+
* body.
|
|
36
|
+
*/
|
|
37
|
+
private record Hop(
|
|
38
|
+
int status, Map<String, String> headers, byte[] body, URI url, InputStream live) {}
|
|
39
|
+
|
|
40
|
+
/** One hop's response, and the URL it came from. */
|
|
41
|
+
private record Sent<B>(HttpResponse<B> response, URI url) {}
|
|
42
|
+
|
|
43
|
+
private final Exchange exchange;
|
|
44
|
+
private final ClientConfig config;
|
|
45
|
+
private final Operation op;
|
|
46
|
+
private final Call call;
|
|
47
|
+
private final RequestOptions options;
|
|
48
|
+
private final String route;
|
|
49
|
+
private final CallLog log;
|
|
50
|
+
private final Deadline deadline;
|
|
51
|
+
private final Hops hops;
|
|
52
|
+
|
|
53
|
+
/** The redirects this call has followed, across its attempts (C#'s _redirects). */
|
|
54
|
+
private int redirects;
|
|
55
|
+
|
|
56
|
+
/** This call's stale view, taken before its first hop (C#'s _meta). */
|
|
57
|
+
private StaleMeta meta = StaleMeta.NONE;
|
|
58
|
+
|
|
59
|
+
/** Whether this call opens a stream: its final 2xx body is left live. */
|
|
60
|
+
private boolean stream;
|
|
61
|
+
|
|
62
|
+
/** A realtime dial: a 401 does not refresh, an answer past the cap is no answer. */
|
|
63
|
+
boolean dial;
|
|
64
|
+
|
|
65
|
+
/** Whether the last hop's body passed the cap. */
|
|
66
|
+
private boolean over;
|
|
67
|
+
|
|
68
|
+
Flight(Exchange exchange, Operation op, Call call, RequestOptions options) {
|
|
69
|
+
this.exchange = exchange;
|
|
70
|
+
this.config = exchange.config();
|
|
71
|
+
this.op = op;
|
|
72
|
+
this.call = call;
|
|
73
|
+
this.options = options == null ? RequestOptions.NONE : options;
|
|
74
|
+
this.route = op.route();
|
|
75
|
+
this.log = new CallLog(config.onLog(), route);
|
|
76
|
+
Duration bound = this.options.timeout() != null ? this.options.timeout() : config.timeout();
|
|
77
|
+
this.deadline = bound == null || bound.isZero() ? null : new Deadline(bound, route);
|
|
78
|
+
this.hops = new Hops(exchange.http(), deadline, route);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
Answer run() {
|
|
82
|
+
return finish(exchanged());
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Opens the stream: an error status throws; a 2xx fills headersInto and raw, and settles stale.
|
|
87
|
+
*/
|
|
88
|
+
<T> EventStream<T> events(Consumer<Map<String, String>> headersInto, TypeReference<T> type) {
|
|
89
|
+
stream = true;
|
|
90
|
+
Hop hop = exchanged();
|
|
91
|
+
ApiException error = finish(hop).error();
|
|
92
|
+
if (error != null) {
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
if (headersInto != null) {
|
|
97
|
+
headersInto.accept(hop.headers());
|
|
98
|
+
}
|
|
99
|
+
return new EventStream<>(hop.live(), type);
|
|
100
|
+
} catch (RuntimeException e) {
|
|
101
|
+
Pump.release(hop.live());
|
|
102
|
+
throw e;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The call's final hop, logged as it starts and when it fails. */
|
|
107
|
+
private Hop exchanged() {
|
|
108
|
+
log.start();
|
|
109
|
+
try {
|
|
110
|
+
if (java.lang.Thread.currentThread().isInterrupted()) {
|
|
111
|
+
throw new CancellationException("the call was canceled");
|
|
112
|
+
}
|
|
113
|
+
return answer();
|
|
114
|
+
} catch (CancellationException e) {
|
|
115
|
+
log.canceled();
|
|
116
|
+
throw e;
|
|
117
|
+
} catch (HoneyException e) {
|
|
118
|
+
log.failed(e, null);
|
|
119
|
+
throw e;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private Hop answer() {
|
|
124
|
+
URI url = url();
|
|
125
|
+
meta =
|
|
126
|
+
exchange.stale().begin(op.method(), UrlPath.expand(op.template(), op.names(), call.path()));
|
|
127
|
+
Credential credential = exchange.credential();
|
|
128
|
+
String token = credential.token();
|
|
129
|
+
Hop hop = attempt(url, token, false);
|
|
130
|
+
boolean replayable = call.body() == null || call.body().replayable();
|
|
131
|
+
if (hop.status() == 401 && !dial && config.onAuthExpired() != null && replayable) {
|
|
132
|
+
String fresh = credential.refresh(token, config.onAuthExpired());
|
|
133
|
+
if (fresh != null) {
|
|
134
|
+
hop = attempt(url, fresh, true);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return hop;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private URI url() {
|
|
141
|
+
String origin = options.baseUrl() != null ? options.baseUrl() : config.baseUrl();
|
|
142
|
+
if (options.baseUrl() != null && !ClientConfig.absolute(origin)) {
|
|
143
|
+
throw new ConfigException("RequestOptions.baseUrl is not an absolute http(s) URL");
|
|
144
|
+
}
|
|
145
|
+
String path = UrlPath.expand(op.template(), op.names(), call.path());
|
|
146
|
+
String query = UrlQuery.encode(call.query());
|
|
147
|
+
String base = origin.replaceAll("/+$", "");
|
|
148
|
+
return URI.create(base + path + (query.isEmpty() ? "" : "?" + query));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private Hop attempt(URI url, String token, boolean retry) {
|
|
152
|
+
byte[] bytes = call.body() == null ? null : call.body().bytes();
|
|
153
|
+
RequestContext context = new RequestContext(op.method(), url, bytes, retry);
|
|
154
|
+
context.staleness(meta);
|
|
155
|
+
layer(context.headers(), token);
|
|
156
|
+
Hooks.onRequest(config.onRequest(), context);
|
|
157
|
+
if (stream) {
|
|
158
|
+
return opened(follow(leg(context), url, hops::open, Pump::discard), retry);
|
|
159
|
+
}
|
|
160
|
+
Sent<byte[]> sent = follow(leg(context), url, hops::send, response -> {});
|
|
161
|
+
byte[] body = Decode.body(sent.response(), config.maxResponseBytes(), deadline);
|
|
162
|
+
over = body == null;
|
|
163
|
+
if (over && dial) {
|
|
164
|
+
throw new ApiConnectionException(Decode.exceeds(config.maxResponseBytes()), null);
|
|
165
|
+
}
|
|
166
|
+
return answered(sent, over ? new byte[0] : body, retry, null);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* A stream hop: a 2xx's body live, decoded as it flows; any other's first 64 KiB, under the
|
|
171
|
+
* deadline.
|
|
172
|
+
*/
|
|
173
|
+
private Hop opened(Sent<Flow.Publisher<List<ByteBuffer>>> sent, boolean retry) {
|
|
174
|
+
int status = sent.response().statusCode();
|
|
175
|
+
boolean ok = status >= 200 && status < 300;
|
|
176
|
+
Pump pump = new Pump(ok ? null : deadline);
|
|
177
|
+
sent.response().body().subscribe(pump);
|
|
178
|
+
InputStream body = Decode.stream(pump, Decode.encoding(sent.response()));
|
|
179
|
+
if (ok) {
|
|
180
|
+
return answered(sent, new byte[0], retry, body);
|
|
181
|
+
}
|
|
182
|
+
try (body) {
|
|
183
|
+
return answered(sent, body.readNBytes(ERROR_CAP), retry, null);
|
|
184
|
+
} catch (InterruptedIOException e) {
|
|
185
|
+
throw new CancellationException("the call was canceled");
|
|
186
|
+
} catch (IOException e) {
|
|
187
|
+
throw new ApiConnectionException(route + ": " + e.getMessage(), e);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The hop after the response hooks, which see {@code body}; a throw lets {@code live} go first.
|
|
193
|
+
*/
|
|
194
|
+
private Hop answered(Sent<?> sent, byte[] body, boolean retry, InputStream live) {
|
|
195
|
+
ResponseContext answer =
|
|
196
|
+
new ResponseContext(
|
|
197
|
+
sent.response().statusCode(), joined(sent.response().headers().map()), body, retry);
|
|
198
|
+
answer.staleness(meta);
|
|
199
|
+
try {
|
|
200
|
+
Hooks.onResponse(config.onResponse(), answer);
|
|
201
|
+
} catch (RuntimeException e) {
|
|
202
|
+
Pump.release(live);
|
|
203
|
+
throw e;
|
|
204
|
+
}
|
|
205
|
+
return new Hop(answer.status(), answer.headers(), answer.body(), sent.url(), live);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** The first hop of an attempt, from the hook's headers and body. */
|
|
209
|
+
private Redirects.Leg leg(RequestContext context) {
|
|
210
|
+
byte[] body = context.body();
|
|
211
|
+
InputStream stream = body == null && call.body() != null ? call.body().stream() : null;
|
|
212
|
+
return new Redirects.Leg(
|
|
213
|
+
context.method(), context.url(), context.headers(), body, stream, false);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Sends {@code first}, then each hop the redirect rules allow, until an answer stands. The
|
|
218
|
+
* deadline is checked before each hop: a hop never leaves once it has lapsed.
|
|
219
|
+
*/
|
|
220
|
+
private <B> Sent<B> follow(
|
|
221
|
+
Redirects.Leg first,
|
|
222
|
+
URI start,
|
|
223
|
+
Function<Redirects.Leg, HttpResponse<B>> send,
|
|
224
|
+
Consumer<HttpResponse<B>> discard) {
|
|
225
|
+
Redirects rules = new Redirects(start, config.redirect());
|
|
226
|
+
Redirects.Leg leg = first;
|
|
227
|
+
while (true) {
|
|
228
|
+
HttpResponse<B> response = send.apply(leg);
|
|
229
|
+
Redirects.Leg next =
|
|
230
|
+
redirects < Redirects.MAX
|
|
231
|
+
? rules.next(leg, response.statusCode(), joined(response.headers().map()))
|
|
232
|
+
: null;
|
|
233
|
+
if (next == null) {
|
|
234
|
+
return new Sent<>(response, leg.url());
|
|
235
|
+
}
|
|
236
|
+
discard.accept(response);
|
|
237
|
+
redirects++;
|
|
238
|
+
leg = next;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Layers the request's headers into {@code layers}: base, config, call, options, then the
|
|
244
|
+
* credential last.
|
|
245
|
+
*/
|
|
246
|
+
private void layer(Map<String, String> layers, String token) {
|
|
247
|
+
layers.put("X-Request-Id", UUID.randomUUID().toString());
|
|
248
|
+
layers.put("Accept-Encoding", "gzip, deflate");
|
|
249
|
+
if (call.body() != null) {
|
|
250
|
+
layers.put("Content-Type", call.body().mediaType());
|
|
251
|
+
}
|
|
252
|
+
layers.putAll(config.headers());
|
|
253
|
+
if (op.accept() != null) {
|
|
254
|
+
layers.put("Accept", op.accept());
|
|
255
|
+
}
|
|
256
|
+
if (op.idempotent()) {
|
|
257
|
+
layers.put("Idempotency-Key", UUID.randomUUID().toString());
|
|
258
|
+
}
|
|
259
|
+
for (Call.Arg arg : call.headers()) {
|
|
260
|
+
String text = UrlQuery.text(arg.value());
|
|
261
|
+
if (text != null) {
|
|
262
|
+
layers.put(arg.name(), text);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
layers.putAll(options.headers());
|
|
266
|
+
if (token != null && !token.isEmpty()) {
|
|
267
|
+
layers.put(exchange.credential().header(), exchange.credential().prefix() + token);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
private static Map<String, String> joined(Map<String, List<String>> raw) {
|
|
272
|
+
Map<String, String> headers = new TreeMap<>();
|
|
273
|
+
raw.forEach(
|
|
274
|
+
(name, values) -> headers.put(name.toLowerCase(Locale.ROOT), String.join(", ", values)));
|
|
275
|
+
return headers;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
private Answer finish(Hop hop) {
|
|
279
|
+
log.received(hop.status());
|
|
280
|
+
RawResponse raw = options.raw() != null ? options.raw() : new RawResponse();
|
|
281
|
+
raw.fill(hop.status(), hop.headers(), hop.body(), hop.url());
|
|
282
|
+
ApiException error = null;
|
|
283
|
+
if (hop.status() < 200 || hop.status() >= 300) {
|
|
284
|
+
error = ApiException.of(new ApiException.Failure(hop.status(), hop.headers(), hop.body()));
|
|
285
|
+
log.failed(error, error.status());
|
|
286
|
+
}
|
|
287
|
+
if (hop.status() >= 200 && hop.status() < 300) {
|
|
288
|
+
exchange.stale().settle(meta, op.invalidates(), pathValues());
|
|
289
|
+
if (over) {
|
|
290
|
+
throw new DecodeException(Decode.exceeds(config.maxResponseBytes()), null);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return new Answer(route, raw, error, hop.body());
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* The call's path values by their template names: what a stale target's placeholders fill from.
|
|
298
|
+
*/
|
|
299
|
+
private Map<String, String> pathValues() {
|
|
300
|
+
Map<String, String> values = new TreeMap<>();
|
|
301
|
+
for (int i = 0; i < op.names().length; i++) {
|
|
302
|
+
values.put(op.names()[i], call.path()[i]);
|
|
303
|
+
}
|
|
304
|
+
return values;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Every error the SDK throws; the caller's own cancellation is a {@link
|
|
6
|
+
* java.util.concurrent.CancellationException}.
|
|
7
|
+
*/
|
|
8
|
+
public abstract class HoneyException extends RuntimeException {
|
|
9
|
+
private static final long serialVersionUID = 1L;
|
|
10
|
+
|
|
11
|
+
HoneyException(String message, Throwable cause) {
|
|
12
|
+
super(message, cause);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.util.List;
|
|
5
|
+
import java.util.concurrent.CancellationException;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Runs the hooks in order; a hook's own failure is the call's {@link HookException}, an SDK error
|
|
9
|
+
* passes as it is.
|
|
10
|
+
*/
|
|
11
|
+
final class Hooks {
|
|
12
|
+
private Hooks() {}
|
|
13
|
+
|
|
14
|
+
static void onRequest(List<RequestHook> hooks, RequestContext context) {
|
|
15
|
+
run(hooks, hook -> hook.apply(context));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static void onResponse(List<ResponseHook> hooks, ResponseContext context) {
|
|
19
|
+
run(hooks, hook -> hook.apply(context));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The error a failed {@code label} throws: an SDK error or a cancellation as it is, any other
|
|
24
|
+
* failure wrapped as the call's {@link HookException}.
|
|
25
|
+
*/
|
|
26
|
+
static RuntimeException failure(String label, java.lang.Exception e) {
|
|
27
|
+
if (e instanceof HoneyException || e instanceof CancellationException) {
|
|
28
|
+
return (RuntimeException) e;
|
|
29
|
+
}
|
|
30
|
+
return new HookException(label + ": " + e.getMessage(), e);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private static <H> void run(List<H> hooks, Apply<H> apply) {
|
|
34
|
+
for (H hook : hooks) {
|
|
35
|
+
try {
|
|
36
|
+
apply.apply(hook);
|
|
37
|
+
} catch (java.lang.Exception e) {
|
|
38
|
+
throw failure("hook", e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** One hook's call, which may throw. */
|
|
44
|
+
private interface Apply<H> {
|
|
45
|
+
void apply(H hook) throws java.lang.Exception;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.io.InputStream;
|
|
5
|
+
import java.net.http.HttpClient;
|
|
6
|
+
import java.net.http.HttpRequest;
|
|
7
|
+
import java.net.http.HttpResponse;
|
|
8
|
+
import java.net.http.HttpResponse.BodyHandlers;
|
|
9
|
+
import java.nio.ByteBuffer;
|
|
10
|
+
import java.util.List;
|
|
11
|
+
import java.util.Locale;
|
|
12
|
+
import java.util.Map;
|
|
13
|
+
import java.util.Set;
|
|
14
|
+
import java.util.concurrent.CancellationException;
|
|
15
|
+
import java.util.concurrent.CompletableFuture;
|
|
16
|
+
import java.util.concurrent.ExecutionException;
|
|
17
|
+
import java.util.concurrent.Flow;
|
|
18
|
+
import java.util.concurrent.TimeUnit;
|
|
19
|
+
import java.util.concurrent.TimeoutException;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* One call's hops on the wire: each request is built from its leg, checked, and sent under the
|
|
23
|
+
* call's one deadline. A lapsed deadline throws ApiTimeoutException before a hop leaves, and
|
|
24
|
+
* cancels the hop in flight when it lapses.
|
|
25
|
+
*/
|
|
26
|
+
final class Hops {
|
|
27
|
+
private static final Set<String> RESTRICTED =
|
|
28
|
+
Set.of("connection", "content-length", "expect", "host", "upgrade");
|
|
29
|
+
|
|
30
|
+
private final HttpClient http;
|
|
31
|
+
private final Deadline deadline;
|
|
32
|
+
private final String route;
|
|
33
|
+
|
|
34
|
+
Hops(HttpClient http, Deadline deadline, String route) {
|
|
35
|
+
this.http = http;
|
|
36
|
+
this.deadline = deadline;
|
|
37
|
+
this.route = route;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
HttpResponse<byte[]> send(Redirects.Leg leg) {
|
|
41
|
+
return transmit(request(leg), BodyHandlers.ofByteArray());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* {@code leg} sent with its body left unread: the deadline bounds the wait for its headers alone.
|
|
46
|
+
*/
|
|
47
|
+
HttpResponse<Flow.Publisher<List<ByteBuffer>>> open(Redirects.Leg leg) {
|
|
48
|
+
return transmit(request(leg), BodyHandlers.ofPublisher());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private HttpRequest request(Redirects.Leg leg) {
|
|
52
|
+
validate(leg.headers());
|
|
53
|
+
HttpRequest.Builder builder =
|
|
54
|
+
HttpRequest.newBuilder(leg.url()).version(HttpClient.Version.HTTP_1_1);
|
|
55
|
+
for (Map.Entry<String, String> header : leg.headers().entrySet()) {
|
|
56
|
+
try {
|
|
57
|
+
builder.header(header.getKey(), header.getValue());
|
|
58
|
+
} catch (IllegalArgumentException e) {
|
|
59
|
+
/* the JDK's refusal quotes the value, so it is never the cause: the header is named, its value kept out */
|
|
60
|
+
throw new ConfigException("the " + header.getKey() + " header cannot be sent");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return builder.method(leg.method(), publisher(leg)).build();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private static HttpRequest.BodyPublisher publisher(Redirects.Leg leg) {
|
|
67
|
+
if (leg.body() != null) {
|
|
68
|
+
return HttpRequest.BodyPublishers.ofByteArray(leg.body());
|
|
69
|
+
}
|
|
70
|
+
InputStream stream = leg.stream();
|
|
71
|
+
return stream == null
|
|
72
|
+
? HttpRequest.BodyPublishers.noBody()
|
|
73
|
+
: HttpRequest.BodyPublishers.ofInputStream(() -> stream);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The final map, checked after the hooks: a restricted name and a control character are the
|
|
78
|
+
* caller's to fix.
|
|
79
|
+
*/
|
|
80
|
+
static void validate(Map<String, String> headers) {
|
|
81
|
+
for (Map.Entry<String, String> header : headers.entrySet()) {
|
|
82
|
+
String name = header.getKey();
|
|
83
|
+
if (RESTRICTED.contains(name.toLowerCase(Locale.ROOT))) {
|
|
84
|
+
throw new ConfigException("the " + name + " header is restricted and cannot be sent");
|
|
85
|
+
}
|
|
86
|
+
if (header.getValue().chars().anyMatch(c -> c == '\r' || c == '\n' || c == 0)) {
|
|
87
|
+
throw new ConfigException("the " + name + " header's value cannot be sent");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private <T> HttpResponse<T> transmit(HttpRequest request, HttpResponse.BodyHandler<T> handler) {
|
|
93
|
+
checkDeadline();
|
|
94
|
+
CompletableFuture<HttpResponse<T>> sent = http.sendAsync(request, handler);
|
|
95
|
+
if (deadline != null) {
|
|
96
|
+
sent.orTimeout(deadline.remainingMillis(), TimeUnit.MILLISECONDS);
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
return sent.get();
|
|
100
|
+
} catch (ExecutionException e) {
|
|
101
|
+
throw failure(sent, e.getCause());
|
|
102
|
+
} catch (InterruptedException e) {
|
|
103
|
+
java.lang.Thread.currentThread().interrupt();
|
|
104
|
+
sent.cancel(true);
|
|
105
|
+
throw new CancellationException("the call was canceled");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Throws the deadline's timeout when it has lapsed: a hook that ran past it leaves no hop, or
|
|
111
|
+
* retry, to send (C#'s SendAsync on a canceled token throws at once).
|
|
112
|
+
*/
|
|
113
|
+
private void checkDeadline() {
|
|
114
|
+
if (deadline != null) {
|
|
115
|
+
deadline.check();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private RuntimeException failure(CompletableFuture<?> sent, Throwable cause) {
|
|
120
|
+
if (cause instanceof TimeoutException) {
|
|
121
|
+
sent.cancel(true);
|
|
122
|
+
return deadline.timeout(cause);
|
|
123
|
+
}
|
|
124
|
+
if (cause instanceof RuntimeException runtime) {
|
|
125
|
+
return runtime;
|
|
126
|
+
}
|
|
127
|
+
String detail = cause.getMessage();
|
|
128
|
+
if (detail == null) {
|
|
129
|
+
detail = cause.getClass().getSimpleName();
|
|
130
|
+
}
|
|
131
|
+
return new ApiConnectionException(route + ": " + detail, cause);
|
|
132
|
+
}
|
|
133
|
+
}
|