@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,152 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.net.URI;
|
|
5
|
+
import java.time.Duration;
|
|
6
|
+
import java.util.ArrayList;
|
|
7
|
+
import java.util.List;
|
|
8
|
+
import java.util.Map;
|
|
9
|
+
import java.util.function.Supplier;
|
|
10
|
+
import tools.jackson.core.type.TypeReference;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A realtime call's entry and its dials (C#'s RealtimeAsync and Dial): the WebSocket upgrade with
|
|
14
|
+
* the cursor as query params, through WsDial (no hook, no log); the event stream through the
|
|
15
|
+
* exchange, the cursor's id as Last-Event-ID and its token as reconnect_token; a poll through the
|
|
16
|
+
* exchange with the cursor as query params, held up to 60 s whatever the client's timeout; a send
|
|
17
|
+
* POSTed as JSON. Each dial has a RawResponse of its own; the call's raw holds the answer the
|
|
18
|
+
* connection last opened with.
|
|
19
|
+
*/
|
|
20
|
+
final class Realtime {
|
|
21
|
+
private static final Duration POLL_LIMIT = Duration.ofSeconds(60);
|
|
22
|
+
|
|
23
|
+
private final Exchange exchange;
|
|
24
|
+
private final Operation op;
|
|
25
|
+
private final Call call;
|
|
26
|
+
private final RequestOptions options;
|
|
27
|
+
private volatile String used;
|
|
28
|
+
|
|
29
|
+
private Realtime(Exchange exchange, Operation op, Call call, RequestOptions options) {
|
|
30
|
+
this.exchange = exchange;
|
|
31
|
+
this.op = op;
|
|
32
|
+
this.call = call;
|
|
33
|
+
this.options = options;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The call's connection over WebSocket, else SSE, else long-poll, opened within 30 s. */
|
|
37
|
+
static <T> ResumableConnection<T> open(
|
|
38
|
+
Exchange exchange,
|
|
39
|
+
Operation op,
|
|
40
|
+
Call call,
|
|
41
|
+
RequestOptions given,
|
|
42
|
+
TransportOptions transport,
|
|
43
|
+
TypeReference<T> type) {
|
|
44
|
+
Realtime dial = new Realtime(exchange, op, call, given == null ? RequestOptions.NONE : given);
|
|
45
|
+
List<TransportAdapter> chain =
|
|
46
|
+
List.of(new WsAdapter(dial), new SseAdapter(dial), new LongPollAdapter(dial));
|
|
47
|
+
ResumableConnection<T> connection =
|
|
48
|
+
new ResumableConnection<>(dial.url(call), chain, type, transport, RealtimeLoop.OPEN_LIMIT);
|
|
49
|
+
connection.open();
|
|
50
|
+
return connection;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** {@code at}'s URL: the origin, the expanded path and the encoded query. */
|
|
54
|
+
String url(Call at) {
|
|
55
|
+
String origin = options.baseUrl() != null ? options.baseUrl() : exchange.config().baseUrl();
|
|
56
|
+
String query = UrlQuery.encode(at.query());
|
|
57
|
+
return origin.replaceAll("/+$", "")
|
|
58
|
+
+ UrlPath.expand(op.template(), op.names(), at.path())
|
|
59
|
+
+ (query.isEmpty() ? "" : "?" + query);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
TypedWebSocket socket(TransportOptions cursor) {
|
|
63
|
+
RawResponse raw = new RawResponse();
|
|
64
|
+
TypedWebSocket socket =
|
|
65
|
+
WsDial.open(exchange, op, cursored(cursor), with(raw, null), cursor.protocols());
|
|
66
|
+
opened(raw);
|
|
67
|
+
return socket;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
EventStream<String> stream(TransportOptions cursor) {
|
|
71
|
+
Operation sse =
|
|
72
|
+
new Operation(
|
|
73
|
+
op.method(),
|
|
74
|
+
op.template(),
|
|
75
|
+
op.names(),
|
|
76
|
+
"text/event-stream",
|
|
77
|
+
op.idempotent(),
|
|
78
|
+
op.invalidates());
|
|
79
|
+
Call at =
|
|
80
|
+
new Call(
|
|
81
|
+
call.path(),
|
|
82
|
+
plus(call.query(), Call.Arg.cursor("reconnect_token", cursor.reconnectToken())),
|
|
83
|
+
plus(call.headers(), Call.Arg.cursor("Last-Event-ID", cursor.lastEventId())),
|
|
84
|
+
call.body());
|
|
85
|
+
RawResponse raw = new RawResponse();
|
|
86
|
+
EventStream<String> stream =
|
|
87
|
+
exchange.dial(sse, at, with(raw, null)).events(null, new TypeReference<String>() {});
|
|
88
|
+
opened(raw);
|
|
89
|
+
return stream;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The long-poll connection's open, which dials nothing: 200 and the poll's URL. */
|
|
93
|
+
void polling(TransportOptions cursor) {
|
|
94
|
+
RawResponse raw = new RawResponse();
|
|
95
|
+
raw.fill(200, Map.of(), new byte[0], URI.create(url(cursored(cursor))));
|
|
96
|
+
opened(raw);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** One poll with the cursor as it stands. */
|
|
100
|
+
Answer poll(TransportOptions cursor) {
|
|
101
|
+
return exchange.dial(op, cursored(cursor), with(new RawResponse(), POLL_LIMIT)).run();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** {@code text} POSTed as JSON on the call's path, query and headers; its error status thrown. */
|
|
105
|
+
void post(String text) {
|
|
106
|
+
Operation post = new Operation("POST", op.template(), op.names(), null, false);
|
|
107
|
+
Call at =
|
|
108
|
+
new Call(call.path(), call.query(), call.headers(), Body.text(text, "application/json"));
|
|
109
|
+
Answer answer = exchange.run(post, at, with(new RawResponse(), null));
|
|
110
|
+
if (answer.error() != null) {
|
|
111
|
+
throw answer.error();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
boolean refresh() {
|
|
116
|
+
Supplier<String> hook = exchange.config().onAuthExpired();
|
|
117
|
+
return hook != null && exchange.credential().refresh(used, hook) != null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* the call's own raw: the answer the connection last opened with, its body never read */
|
|
121
|
+
private void opened(RawResponse raw) {
|
|
122
|
+
if (options.raw() != null) {
|
|
123
|
+
options.raw().fill(raw.status(), raw.headers(), new byte[0], raw.url());
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private Call cursored(TransportOptions cursor) {
|
|
128
|
+
List<Call.Arg> query =
|
|
129
|
+
plus(call.query(), Call.Arg.cursor("last_event_id", cursor.lastEventId()));
|
|
130
|
+
return new Call(
|
|
131
|
+
call.path(),
|
|
132
|
+
plus(query, Call.Arg.cursor("reconnect_token", cursor.reconnectToken())),
|
|
133
|
+
call.headers(),
|
|
134
|
+
call.body());
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private static List<Call.Arg> plus(List<Call.Arg> args, Call.Arg arg) {
|
|
138
|
+
List<Call.Arg> all = new ArrayList<>(args);
|
|
139
|
+
all.add(arg);
|
|
140
|
+
return all;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private RequestOptions with(RawResponse raw, Duration timeout) {
|
|
144
|
+
used = exchange.credential().token();
|
|
145
|
+
return RequestOptions.builder()
|
|
146
|
+
.timeout(timeout != null ? timeout : options.timeout())
|
|
147
|
+
.headers(options.headers())
|
|
148
|
+
.baseUrl(options.baseUrl())
|
|
149
|
+
.raw(raw)
|
|
150
|
+
.build();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.io.UncheckedIOException;
|
|
5
|
+
import java.time.Duration;
|
|
6
|
+
import java.util.List;
|
|
7
|
+
import java.util.concurrent.CancellationException;
|
|
8
|
+
import java.util.concurrent.CompletableFuture;
|
|
9
|
+
import java.util.concurrent.ThreadLocalRandom;
|
|
10
|
+
import java.util.concurrent.TimeUnit;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* {@link ResumableConnection}'s loop (C#'s RealtimeLoop), its behavior documented there. Only the
|
|
14
|
+
* reading thread reconnects; close() from any thread ends it.
|
|
15
|
+
*/
|
|
16
|
+
final class RealtimeLoop {
|
|
17
|
+
/** How long an open of the chain may take: the method's and each reconnect's. */
|
|
18
|
+
static final Duration OPEN_LIMIT = Duration.ofSeconds(30);
|
|
19
|
+
|
|
20
|
+
private final List<TransportAdapter> adapters;
|
|
21
|
+
private final TransportOptions options;
|
|
22
|
+
private final String url;
|
|
23
|
+
private final Duration openLimit;
|
|
24
|
+
private final Object wake = new Object();
|
|
25
|
+
private volatile ConnectionState state = ConnectionState.DISCONNECTED;
|
|
26
|
+
private volatile TransportConnection conn;
|
|
27
|
+
private volatile TransportAdapter proven;
|
|
28
|
+
private volatile boolean closing;
|
|
29
|
+
/* the last open's bound: close() stops it while it still opens */
|
|
30
|
+
private volatile Bound pending;
|
|
31
|
+
private RuntimeException failure = new ApiConnectionException("the connection ended", null);
|
|
32
|
+
private Duration retry;
|
|
33
|
+
private int attempts;
|
|
34
|
+
|
|
35
|
+
/** This open's best refusal; whether nothing is read yet; whether a 401 may still refresh. */
|
|
36
|
+
private boolean refused;
|
|
37
|
+
|
|
38
|
+
private RuntimeException best;
|
|
39
|
+
private boolean fresh;
|
|
40
|
+
private boolean armed;
|
|
41
|
+
|
|
42
|
+
interface Dialed {
|
|
43
|
+
Realtime dial();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
RealtimeLoop(
|
|
47
|
+
List<TransportAdapter> adapters, TransportOptions options, String url, Duration openLimit) {
|
|
48
|
+
this.adapters = adapters;
|
|
49
|
+
this.options = options;
|
|
50
|
+
this.url = url;
|
|
51
|
+
this.openLimit = openLimit;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
ConnectionState state() {
|
|
55
|
+
return state;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
TransportKind proven() {
|
|
59
|
+
TransportAdapter adapter = proven;
|
|
60
|
+
return adapter == null ? null : adapter.kind();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Opens the first adapter in order that opens; the last failure when none does. */
|
|
64
|
+
void connect() {
|
|
65
|
+
armed = true;
|
|
66
|
+
chain();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* the chain in order; refused only when every adapter refused, else its last transient failure */
|
|
70
|
+
private void chain() {
|
|
71
|
+
boolean every = !adapters.isEmpty();
|
|
72
|
+
RuntimeException top = null;
|
|
73
|
+
RuntimeException flaky = null;
|
|
74
|
+
refused = false;
|
|
75
|
+
for (TransportAdapter adapter : adapters) {
|
|
76
|
+
TransportConnection opened;
|
|
77
|
+
try {
|
|
78
|
+
opened = adapter.connect(url, options);
|
|
79
|
+
} catch (RuntimeException e) {
|
|
80
|
+
if (!fails(e)) {
|
|
81
|
+
throw e;
|
|
82
|
+
}
|
|
83
|
+
if (refreshed(adapter, e)) {
|
|
84
|
+
chain();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (rank(e) == 0) {
|
|
88
|
+
every = false;
|
|
89
|
+
flaky = e;
|
|
90
|
+
} else if (rank(e) > rank(top)) {
|
|
91
|
+
top = e;
|
|
92
|
+
}
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (closing) {
|
|
96
|
+
quietly(opened);
|
|
97
|
+
throw new CancellationException("the connection was closed");
|
|
98
|
+
}
|
|
99
|
+
conn = opened;
|
|
100
|
+
proven = adapter;
|
|
101
|
+
state = ConnectionState.CONNECTED;
|
|
102
|
+
refused = every;
|
|
103
|
+
best = top;
|
|
104
|
+
fresh = true;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
refused = every;
|
|
108
|
+
failure = flaky != null ? flaky : top != null ? top : failure;
|
|
109
|
+
throw failure;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* connect() under the open bound (R4), which close() also ends: either one interrupts this thread
|
|
114
|
+
* only while it still opens, and the opener alone clears what they set; a caller's interrupt is
|
|
115
|
+
* never taken. A close ends it as CancellationException, the bound as ApiTimeoutException.
|
|
116
|
+
*/
|
|
117
|
+
void open() {
|
|
118
|
+
armed = true;
|
|
119
|
+
bounded();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
private void bounded() {
|
|
123
|
+
Bound bound = new Bound(java.lang.Thread.currentThread());
|
|
124
|
+
pending = bound;
|
|
125
|
+
if (closing) {
|
|
126
|
+
bound.stop("close");
|
|
127
|
+
}
|
|
128
|
+
CompletableFuture<Void> timer = new CompletableFuture<>();
|
|
129
|
+
timer
|
|
130
|
+
.completeOnTimeout(null, openLimit.toMillis(), TimeUnit.MILLISECONDS)
|
|
131
|
+
.thenRun(() -> bound.stop("bound"));
|
|
132
|
+
RuntimeException failed = null;
|
|
133
|
+
try {
|
|
134
|
+
chain();
|
|
135
|
+
} catch (RuntimeException e) {
|
|
136
|
+
failed = e;
|
|
137
|
+
}
|
|
138
|
+
String by = bound.disarm();
|
|
139
|
+
timer.complete(null);
|
|
140
|
+
if (by == null) {
|
|
141
|
+
if (failed != null) {
|
|
142
|
+
throw failed;
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (failed == null) {
|
|
147
|
+
TransportConnection late = conn;
|
|
148
|
+
conn = null;
|
|
149
|
+
proven = null;
|
|
150
|
+
state = ConnectionState.DISCONNECTED;
|
|
151
|
+
quietly(late);
|
|
152
|
+
}
|
|
153
|
+
java.lang.Thread.interrupted();
|
|
154
|
+
throw ended(by, failed);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private RuntimeException ended(String by, Throwable cause) {
|
|
158
|
+
if (by.equals("close")) {
|
|
159
|
+
return new CancellationException("the connection was closed");
|
|
160
|
+
}
|
|
161
|
+
long ms = openLimit.toMillis();
|
|
162
|
+
String limit = ms % 1000 == 0 ? ms / 1000 + " s" : ms + " ms";
|
|
163
|
+
return new ApiTimeoutException("no transport opened within " + limit, cause);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** An open's end by the bound or a close: it interrupts the opener only while it still opens. */
|
|
167
|
+
private static final class Bound {
|
|
168
|
+
private final java.lang.Thread opener;
|
|
169
|
+
private boolean opening = true;
|
|
170
|
+
private String by;
|
|
171
|
+
|
|
172
|
+
Bound(java.lang.Thread opener) {
|
|
173
|
+
this.opener = opener;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
synchronized void stop(String reason) {
|
|
177
|
+
if (opening && by == null) {
|
|
178
|
+
by = reason;
|
|
179
|
+
opener.interrupt();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Ends the open; what stopped it first, null for nothing. */
|
|
184
|
+
synchronized String disarm() {
|
|
185
|
+
opening = false;
|
|
186
|
+
return by;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* The next message; null once DISCONNECTED. An interrupt drops the transport, leaves the
|
|
192
|
+
* connection RECONNECTING with its cursor, and throws CancellationException, the flag kept.
|
|
193
|
+
*/
|
|
194
|
+
TransportMessage next() {
|
|
195
|
+
try {
|
|
196
|
+
if (java.lang.Thread.currentThread().isInterrupted()) {
|
|
197
|
+
throw new CancellationException("the read was canceled");
|
|
198
|
+
}
|
|
199
|
+
while (state != ConnectionState.DISCONNECTED && !closing) {
|
|
200
|
+
TransportConnection open = conn;
|
|
201
|
+
if (open == null) {
|
|
202
|
+
reconnect();
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
TransportMessage message;
|
|
206
|
+
RuntimeException ended = new ApiConnectionException("the connection ended", null);
|
|
207
|
+
try {
|
|
208
|
+
message = open.receive();
|
|
209
|
+
} catch (RuntimeException e) {
|
|
210
|
+
if (!fails(e)) {
|
|
211
|
+
throw e;
|
|
212
|
+
}
|
|
213
|
+
message = null;
|
|
214
|
+
ended = e;
|
|
215
|
+
}
|
|
216
|
+
if (closing) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
if (message != null) {
|
|
220
|
+
attempts = 0;
|
|
221
|
+
fresh = false;
|
|
222
|
+
if (message.retry() != null) {
|
|
223
|
+
retry = message.retry();
|
|
224
|
+
}
|
|
225
|
+
return message;
|
|
226
|
+
}
|
|
227
|
+
TransportAdapter was = proven;
|
|
228
|
+
drop(open, ended);
|
|
229
|
+
if (fresh && refused && rank(ended) > 0) {
|
|
230
|
+
// a lazy long-poll's refused first read: the open's refusal
|
|
231
|
+
if (refreshed(was, ended)) {
|
|
232
|
+
bounded();
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
state = ConnectionState.DISCONNECTED;
|
|
236
|
+
throw rank(ended) > rank(best) ? ended : best;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
} catch (CancellationException e) {
|
|
241
|
+
if (closing) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
TransportConnection open = conn;
|
|
245
|
+
if (open != null) {
|
|
246
|
+
drop(open, failure);
|
|
247
|
+
}
|
|
248
|
+
throw e;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
void send(String text) {
|
|
253
|
+
TransportConnection open = conn;
|
|
254
|
+
if (open == null) {
|
|
255
|
+
throw new ApiConnectionException("the connection is not open", null);
|
|
256
|
+
}
|
|
257
|
+
open.send(text);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
void close() {
|
|
261
|
+
closing = true;
|
|
262
|
+
state = ConnectionState.DISCONNECTED;
|
|
263
|
+
Bound opening = pending;
|
|
264
|
+
if (opening != null) {
|
|
265
|
+
opening.stop("close");
|
|
266
|
+
}
|
|
267
|
+
TransportConnection open = conn;
|
|
268
|
+
conn = null;
|
|
269
|
+
synchronized (wake) {
|
|
270
|
+
wake.notifyAll();
|
|
271
|
+
}
|
|
272
|
+
if (open != null) {
|
|
273
|
+
quietly(open);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Reopens the chain after a backoff, up to maxReconnectAttempts in a row: min(base × 2^attempts,
|
|
279
|
+
* the open bound, 30 s), slept in its upper half (base: the last SSE retry, else reconnectDelay);
|
|
280
|
+
* giving up is DISCONNECTED and the last failure.
|
|
281
|
+
*/
|
|
282
|
+
private void reconnect() {
|
|
283
|
+
while (attempts < options.maxReconnectAttempts()) {
|
|
284
|
+
long base = (retry != null ? retry : options.reconnectDelay()).toMillis();
|
|
285
|
+
long full = Math.min(base << Math.min(attempts, 20), openLimit.toMillis());
|
|
286
|
+
backoff(full / 2 + (long) (full / 2.0 * ThreadLocalRandom.current().nextDouble()));
|
|
287
|
+
if (closing) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
attempts++;
|
|
291
|
+
try {
|
|
292
|
+
open();
|
|
293
|
+
return;
|
|
294
|
+
} catch (HoneyException e) {
|
|
295
|
+
failure = e;
|
|
296
|
+
if (refused) {
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
state = ConnectionState.DISCONNECTED;
|
|
302
|
+
throw failure;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** Waits {@code ms}, or until close(); an interrupt is the reader's cancel. */
|
|
306
|
+
private void backoff(long ms) {
|
|
307
|
+
long end = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(ms);
|
|
308
|
+
synchronized (wake) {
|
|
309
|
+
long left;
|
|
310
|
+
while (!closing && (left = end - System.nanoTime()) > 0) {
|
|
311
|
+
try {
|
|
312
|
+
TimeUnit.NANOSECONDS.timedWait(wake, left);
|
|
313
|
+
} catch (InterruptedException e) {
|
|
314
|
+
java.lang.Thread.currentThread().interrupt();
|
|
315
|
+
throw new CancellationException("the read was canceled");
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
private void drop(TransportConnection open, RuntimeException ended) {
|
|
322
|
+
if (closing) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
conn = null;
|
|
326
|
+
proven = null;
|
|
327
|
+
failure = ended;
|
|
328
|
+
state = ConnectionState.RECONNECTING;
|
|
329
|
+
quietly(open);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
private static void quietly(TransportConnection open) {
|
|
333
|
+
try {
|
|
334
|
+
open.close();
|
|
335
|
+
} catch (RuntimeException e) {
|
|
336
|
+
/* a dead transport's close is not the connection's failure */
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** A deterministic refusal's rank, the most specific highest; 0 for a transient failure. */
|
|
341
|
+
private static int rank(RuntimeException e) {
|
|
342
|
+
return !(e instanceof ApiException a)
|
|
343
|
+
? 0
|
|
344
|
+
: switch (a.status()) {
|
|
345
|
+
case 401 -> 6;
|
|
346
|
+
case 403 -> 5;
|
|
347
|
+
case 422 -> 4;
|
|
348
|
+
case 400 -> 3;
|
|
349
|
+
case 410 -> 2;
|
|
350
|
+
case 404, 405 -> 1;
|
|
351
|
+
default -> 0;
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** A 401's one refresh per open: whether the chain restarts. */
|
|
356
|
+
private boolean refreshed(TransportAdapter adapter, RuntimeException e) {
|
|
357
|
+
if (!armed || rank(e) != 6 || !(adapter instanceof Dialed dialed)) {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
armed = false;
|
|
361
|
+
return dialed.dial().refresh();
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* What an adapter's open or read throws when that transport failed; anything else is the
|
|
366
|
+
* caller's.
|
|
367
|
+
*/
|
|
368
|
+
private static boolean fails(RuntimeException e) {
|
|
369
|
+
return e instanceof HoneyException || e instanceof UncheckedIOException;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Which redirects a call follows. {@link #SAME_ORIGIN} (the default) follows a hop to the origin
|
|
6
|
+
* the call was sent to; {@link #ALL} follows a hop to any origin, stripped to the safe headers;
|
|
7
|
+
* {@link #NONE} answers every 3xx as it is. A call follows at most ten hops.
|
|
8
|
+
*/
|
|
9
|
+
public enum RedirectPolicy {
|
|
10
|
+
SAME_ORIGIN,
|
|
11
|
+
ALL,
|
|
12
|
+
NONE
|
|
13
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.io.InputStream;
|
|
5
|
+
import java.net.URI;
|
|
6
|
+
import java.util.Locale;
|
|
7
|
+
import java.util.Map;
|
|
8
|
+
import java.util.Set;
|
|
9
|
+
import java.util.TreeMap;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The SDK's own redirect rules, which HttpClient never applies (its {@code Redirect.NEVER}): which
|
|
13
|
+
* 3xx answer is followed, and the hop it makes. A hop that crosses an origin keeps only the safe
|
|
14
|
+
* headers, and that stays true on every later hop. A GET hop carries no body.
|
|
15
|
+
*/
|
|
16
|
+
final class Redirects {
|
|
17
|
+
/** The most redirects one call follows. */
|
|
18
|
+
static final int MAX = 10;
|
|
19
|
+
|
|
20
|
+
private static final Set<java.lang.Integer> STATUSES = Set.of(301, 302, 303, 307, 308);
|
|
21
|
+
private static final Set<String> SAFE = Set.of("accept", "accept-language", "user-agent");
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* One request to send: its method, URL, headers, body (bytes, or a one-shot stream), and whether
|
|
25
|
+
* it has crossed an origin.
|
|
26
|
+
*/
|
|
27
|
+
record Leg(
|
|
28
|
+
String method,
|
|
29
|
+
URI url,
|
|
30
|
+
Map<String, String> headers,
|
|
31
|
+
byte[] body,
|
|
32
|
+
InputStream stream,
|
|
33
|
+
boolean cross) {}
|
|
34
|
+
|
|
35
|
+
private final URI start;
|
|
36
|
+
private final RedirectPolicy policy;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The rules for one attempt: the call's first URL, which a hop is cross-origin against, and the
|
|
40
|
+
* policy.
|
|
41
|
+
*/
|
|
42
|
+
Redirects(URI start, RedirectPolicy policy) {
|
|
43
|
+
this.start = start;
|
|
44
|
+
this.policy = policy;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The hop the 3xx {@code answer} to {@code leg} asks for, or null when the answer stands: a
|
|
49
|
+
* status that is not a redirect, a Location that does not parse to http(s), a policy that refuses
|
|
50
|
+
* the hop, or a body that cannot be resent.
|
|
51
|
+
*/
|
|
52
|
+
Leg next(Leg leg, int status, Map<String, String> answer) {
|
|
53
|
+
URI target = target(leg.url(), status, answer.get("location"));
|
|
54
|
+
if (target == null || policy == RedirectPolicy.NONE) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
boolean leaves = !sameOrigin(target, start);
|
|
58
|
+
if (leaves && policy != RedirectPolicy.ALL) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
boolean toGet =
|
|
62
|
+
status == 303 ? !"HEAD".equals(leg.method()) : status < 303 && "POST".equals(leg.method());
|
|
63
|
+
if (!toGet && (leg.stream() != null || (leg.body() != null && leaves))) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
boolean cross = leg.cross() || leaves;
|
|
67
|
+
return new Leg(
|
|
68
|
+
toGet ? "GET" : leg.method(),
|
|
69
|
+
target,
|
|
70
|
+
headersOf(leg.headers(), toGet, cross),
|
|
71
|
+
toGet ? null : leg.body(),
|
|
72
|
+
null,
|
|
73
|
+
cross);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The headers a hop keeps: no Content-Type on a GET, and only the safe set once it has crossed.
|
|
78
|
+
*/
|
|
79
|
+
private static Map<String, String> headersOf(
|
|
80
|
+
Map<String, String> headers, boolean toGet, boolean cross) {
|
|
81
|
+
Map<String, String> kept = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
|
82
|
+
for (Map.Entry<String, String> header : headers.entrySet()) {
|
|
83
|
+
String name = header.getKey().toLowerCase(Locale.ROOT);
|
|
84
|
+
boolean dropped = (toGet && name.equals("content-type")) || (cross && !SAFE.contains(name));
|
|
85
|
+
if (!dropped) {
|
|
86
|
+
kept.put(header.getKey(), header.getValue());
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return kept;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The URL a Location names against {@code from}, or null unless it parses to an http(s) URL with
|
|
94
|
+
* a port.
|
|
95
|
+
*/
|
|
96
|
+
private static URI target(URI from, int status, String location) {
|
|
97
|
+
if (location == null || location.isEmpty() || !STATUSES.contains(status)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
URI target = from.resolve(location);
|
|
102
|
+
String scheme = target.getScheme() == null ? "" : target.getScheme().toLowerCase(Locale.ROOT);
|
|
103
|
+
boolean web = scheme.equals("http") || scheme.equals("https");
|
|
104
|
+
return web && target.getHost() != null && target.getPort() <= 65535 ? target : null;
|
|
105
|
+
} catch (IllegalArgumentException e) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Whether {@code a} and {@code b} share a scheme, a host (case-insensitively) and a port
|
|
112
|
+
* (defaults filled).
|
|
113
|
+
*/
|
|
114
|
+
static boolean sameOrigin(URI a, URI b) {
|
|
115
|
+
return a.getScheme().equalsIgnoreCase(b.getScheme())
|
|
116
|
+
&& a.getHost().equalsIgnoreCase(b.getHost())
|
|
117
|
+
&& port(a) == port(b);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private static int port(URI uri) {
|
|
121
|
+
if (uri.getPort() != -1) {
|
|
122
|
+
return uri.getPort();
|
|
123
|
+
}
|
|
124
|
+
return uri.getScheme().equalsIgnoreCase("https") ? 443 : 80;
|
|
125
|
+
}
|
|
126
|
+
}
|