@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,244 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""A realtime operation's answer: a connection over a chain of transports (WebSocket, then SSE, then
|
|
3
|
+
long-poll) that reconnects after a drop and resumes past the last message it delivered."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import contextlib
|
|
7
|
+
import random
|
|
8
|
+
from collections.abc import Sequence
|
|
9
|
+
from enum import StrEnum
|
|
10
|
+
from typing import Generic, Self, TypeVar, Unpack, cast
|
|
11
|
+
|
|
12
|
+
from .body import dumps
|
|
13
|
+
from .errors import (
|
|
14
|
+
APIConnectionError,
|
|
15
|
+
APIStatusError,
|
|
16
|
+
APITimeoutError,
|
|
17
|
+
CanceledError,
|
|
18
|
+
DecodeError,
|
|
19
|
+
HoneyError,
|
|
20
|
+
loads,
|
|
21
|
+
)
|
|
22
|
+
from .events import Cancel, raced
|
|
23
|
+
from .exchange import CallArgs, Exchange, shaped
|
|
24
|
+
from .operation import Operation
|
|
25
|
+
from .transport import (
|
|
26
|
+
Dial,
|
|
27
|
+
TransportAdapter,
|
|
28
|
+
TransportConn,
|
|
29
|
+
TransportKind,
|
|
30
|
+
TransportMessage,
|
|
31
|
+
TransportOpts,
|
|
32
|
+
advance,
|
|
33
|
+
)
|
|
34
|
+
from .transport_longpoll import LongpollAdapter
|
|
35
|
+
from .transport_sse import SseAdapter
|
|
36
|
+
from .transport_ws import WsAdapter
|
|
37
|
+
from .ws import AsyncWsTransport
|
|
38
|
+
|
|
39
|
+
__all__ = ["ConnectionState", "ResumableConnection"]
|
|
40
|
+
|
|
41
|
+
T = TypeVar("T")
|
|
42
|
+
|
|
43
|
+
JITTER = random.SystemRandom()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
WEIGHTS = {401: 6, 403: 5, 422: 4, 400: 3, 410: 2, 404: 1, 405: 1}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def weight(error: Exception) -> int:
|
|
50
|
+
"""A failure's weight: a transient one 7 (retried), else its refusal's rank."""
|
|
51
|
+
status = error.status if isinstance(error, APIStatusError) else 0
|
|
52
|
+
return WEIGHTS.get(status, 7)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ConnectionState(StrEnum):
|
|
56
|
+
CONNECTED = "connected"
|
|
57
|
+
RECONNECTING = "reconnecting"
|
|
58
|
+
DISCONNECTED = "disconnected"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class ResumableConnection(Generic[T]):
|
|
62
|
+
"""``recv`` (or ``async for``) reads the next message, JSON decoded when it is JSON. After a drop it
|
|
63
|
+
reopens the chain in order, backing off from the delay (an SSE ``retry``, else ``reconnect_delay_ms``;
|
|
64
|
+
doubling to at most 30 s, with jitter) for up to ``max_reconnect_attempts`` in a row; giving up raises
|
|
65
|
+
the last failure once, and ``recv`` then answers ``None``, as it does once closed or after the call's
|
|
66
|
+
``cancel``. A ``recv`` the caller's task cancels raises ``CancelledError`` and leaves it reconnecting:
|
|
67
|
+
the next ``recv`` resumes from the cursor."""
|
|
68
|
+
|
|
69
|
+
def __init__(
|
|
70
|
+
self,
|
|
71
|
+
url: str,
|
|
72
|
+
adapters: Sequence[TransportAdapter],
|
|
73
|
+
opts: TransportOpts | None = None,
|
|
74
|
+
) -> None:
|
|
75
|
+
self.url = url
|
|
76
|
+
self.adapters = tuple(adapters)
|
|
77
|
+
self.opts = opts or TransportOpts()
|
|
78
|
+
self.conn: TransportConn | None = None
|
|
79
|
+
self.proven: TransportAdapter | None = None
|
|
80
|
+
self.state = ConnectionState.DISCONNECTED
|
|
81
|
+
self.attempts = 0
|
|
82
|
+
self.retry: int | None = None
|
|
83
|
+
self.failure: Exception = APIConnectionError("the connection ended")
|
|
84
|
+
self.cancel: Cancel = None
|
|
85
|
+
self.shape: str | None = None
|
|
86
|
+
self.closing = asyncio.Event()
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def proven_transport(self) -> TransportKind | None:
|
|
90
|
+
"""The transport that last opened; ``None`` after a drop."""
|
|
91
|
+
return None if self.proven is None else self.proven.kind()
|
|
92
|
+
|
|
93
|
+
async def connect(self) -> None:
|
|
94
|
+
"""Opens the chain in order, once more after a refreshed 401; else the heaviest failure."""
|
|
95
|
+
refreshed = False
|
|
96
|
+
while True:
|
|
97
|
+
best: Exception | None = None
|
|
98
|
+
for adapter in self.adapters:
|
|
99
|
+
try:
|
|
100
|
+
self.conn = await adapter.connect(self.url, self.opts)
|
|
101
|
+
except (HoneyError, OSError) as error:
|
|
102
|
+
if weight(error) == 6 and not refreshed:
|
|
103
|
+
refreshed = True
|
|
104
|
+
refresh = getattr(adapter, "refresh", None)
|
|
105
|
+
if refresh is not None and await refresh():
|
|
106
|
+
break
|
|
107
|
+
if best is None or weight(error) > weight(best):
|
|
108
|
+
best = error
|
|
109
|
+
continue
|
|
110
|
+
self.proven, self.state = adapter, ConnectionState.CONNECTED
|
|
111
|
+
return
|
|
112
|
+
else:
|
|
113
|
+
self.failure = best or self.failure
|
|
114
|
+
raise self.failure
|
|
115
|
+
|
|
116
|
+
async def reconnect(self) -> None:
|
|
117
|
+
while (
|
|
118
|
+
self.attempts < self.opts.max_reconnect_attempts
|
|
119
|
+
and weight(self.failure) == 7
|
|
120
|
+
):
|
|
121
|
+
base = self.opts.reconnect_delay_ms if self.retry is None else self.retry
|
|
122
|
+
full = min(base / 1000 * 2**self.attempts, 30.0)
|
|
123
|
+
await asyncio.sleep(full / 2 + JITTER.uniform(0, full / 2))
|
|
124
|
+
self.attempts += 1
|
|
125
|
+
with contextlib.suppress(HoneyError, OSError):
|
|
126
|
+
return await asyncio.wait_for(self.connect(), 30)
|
|
127
|
+
self.state = ConnectionState.DISCONNECTED
|
|
128
|
+
raise self.failure
|
|
129
|
+
|
|
130
|
+
async def recv(self) -> T | None:
|
|
131
|
+
"""The next message; ``None`` once closed, given up or cancelled."""
|
|
132
|
+
try:
|
|
133
|
+
return await raced(raced(self.read(), self.closing), self.cancel)
|
|
134
|
+
except CanceledError:
|
|
135
|
+
await self.close()
|
|
136
|
+
return None
|
|
137
|
+
except asyncio.CancelledError:
|
|
138
|
+
if self.conn is not None:
|
|
139
|
+
await self.drop(self.conn, self.failure)
|
|
140
|
+
raise
|
|
141
|
+
|
|
142
|
+
async def read(self) -> T | None:
|
|
143
|
+
while self.state is not ConnectionState.DISCONNECTED:
|
|
144
|
+
conn = self.conn
|
|
145
|
+
if conn is None:
|
|
146
|
+
await self.reconnect()
|
|
147
|
+
continue
|
|
148
|
+
try:
|
|
149
|
+
message = await conn.recv()
|
|
150
|
+
failure: Exception = APIConnectionError("the connection ended")
|
|
151
|
+
except (HoneyError, OSError) as error:
|
|
152
|
+
message, failure = None, error
|
|
153
|
+
if message is not None:
|
|
154
|
+
return self.deliver(message)
|
|
155
|
+
await self.drop(conn, failure)
|
|
156
|
+
return None
|
|
157
|
+
|
|
158
|
+
async def drop(self, conn: TransportConn, failure: Exception) -> None:
|
|
159
|
+
if self.closing.is_set():
|
|
160
|
+
return
|
|
161
|
+
self.conn, self.proven, self.failure = None, None, failure
|
|
162
|
+
self.state = ConnectionState.RECONNECTING
|
|
163
|
+
with contextlib.suppress(Exception):
|
|
164
|
+
await conn.close()
|
|
165
|
+
|
|
166
|
+
def deliver(self, message: TransportMessage) -> T:
|
|
167
|
+
"""``message`` as ``T``, the cursor advanced past it and an SSE ``retry`` kept."""
|
|
168
|
+
self.attempts = 0
|
|
169
|
+
if message.retry is not None:
|
|
170
|
+
self.retry = message.retry
|
|
171
|
+
try:
|
|
172
|
+
value = loads(message.text.encode())
|
|
173
|
+
except ValueError:
|
|
174
|
+
value = message.text
|
|
175
|
+
advance(self.opts, message.id, value)
|
|
176
|
+
if not shaped(value, self.shape):
|
|
177
|
+
raise DecodeError(f"a message is not a JSON {self.shape}")
|
|
178
|
+
return cast("T", value)
|
|
179
|
+
|
|
180
|
+
def __aiter__(self) -> Self:
|
|
181
|
+
return self
|
|
182
|
+
|
|
183
|
+
async def __anext__(self) -> T:
|
|
184
|
+
message = await self.recv()
|
|
185
|
+
if message is None and self.state is ConnectionState.DISCONNECTED:
|
|
186
|
+
raise StopAsyncIteration
|
|
187
|
+
return cast("T", message)
|
|
188
|
+
|
|
189
|
+
async def send(self, data: object) -> None:
|
|
190
|
+
"""Sends text as it is, anything else as JSON (an SSE or long-poll connection POSTs it)."""
|
|
191
|
+
if self.conn is None:
|
|
192
|
+
raise APIConnectionError("the connection is not open")
|
|
193
|
+
await self.conn.send(data if isinstance(data, str) else dumps(data))
|
|
194
|
+
|
|
195
|
+
async def close(self) -> None:
|
|
196
|
+
"""Closes the open transport and ends a ``recv`` waiting in any task with ``None``."""
|
|
197
|
+
self.closing.set()
|
|
198
|
+
self.state = ConnectionState.DISCONNECTED
|
|
199
|
+
conn, self.conn = self.conn, None
|
|
200
|
+
if conn is not None:
|
|
201
|
+
with contextlib.suppress(Exception):
|
|
202
|
+
await conn.close()
|
|
203
|
+
|
|
204
|
+
async def __aenter__(self) -> Self:
|
|
205
|
+
return self
|
|
206
|
+
|
|
207
|
+
async def __aexit__(self, *exc: object) -> None:
|
|
208
|
+
await self.close()
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
class AsyncRealtimeTransport(AsyncWsTransport):
|
|
212
|
+
async def realtime(
|
|
213
|
+
self,
|
|
214
|
+
op: Operation[T],
|
|
215
|
+
*,
|
|
216
|
+
last_event_id: str | None = None,
|
|
217
|
+
reconnect_token: str | None = None,
|
|
218
|
+
protocols: Sequence[str] | None = None,
|
|
219
|
+
max_reconnect_attempts: int | None = None,
|
|
220
|
+
reconnect_delay_ms: int | None = None,
|
|
221
|
+
**args: Unpack[CallArgs],
|
|
222
|
+
) -> ResumableConnection[T]:
|
|
223
|
+
x = Exchange(self, op, args, stream=True)
|
|
224
|
+
x.check()
|
|
225
|
+
opts = TransportOpts(
|
|
226
|
+
last_event_id,
|
|
227
|
+
reconnect_token,
|
|
228
|
+
list(protocols or []),
|
|
229
|
+
5 if max_reconnect_attempts is None else max_reconnect_attempts,
|
|
230
|
+
1000 if reconnect_delay_ms is None else reconnect_delay_ms,
|
|
231
|
+
)
|
|
232
|
+
dial = Dial(self, op, args, x.options.get("raw"))
|
|
233
|
+
chain: list[TransportAdapter] = [
|
|
234
|
+
WsAdapter(dial),
|
|
235
|
+
SseAdapter(dial),
|
|
236
|
+
LongpollAdapter(dial),
|
|
237
|
+
]
|
|
238
|
+
connection = ResumableConnection[T](x.url(), chain, opts)
|
|
239
|
+
connection.shape, connection.cancel = op.shape, x.options.get("cancel")
|
|
240
|
+
try:
|
|
241
|
+
await raced(asyncio.wait_for(connection.connect(), 30), connection.cancel)
|
|
242
|
+
except TimeoutError:
|
|
243
|
+
raise APITimeoutError("no transport opened within 30 s") from None
|
|
244
|
+
return connection
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""Which redirects a call follows (R2): the HTTP client never follows one itself. A hop to another
|
|
3
|
+
origin is followed only under ``"follow"``, stripped to the safe headers, and never carries a body."""
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
from dataclasses import dataclass, replace
|
|
7
|
+
from typing import Any, Literal
|
|
8
|
+
from urllib.parse import urljoin, urlsplit
|
|
9
|
+
|
|
10
|
+
import httpx2
|
|
11
|
+
|
|
12
|
+
from .body import BodyPayload
|
|
13
|
+
|
|
14
|
+
MAX_REDIRECTS = 10
|
|
15
|
+
SAFE = ("accept", "accept-language", "user-agent")
|
|
16
|
+
FRAMING = (
|
|
17
|
+
"accept-encoding",
|
|
18
|
+
"connection",
|
|
19
|
+
"content-length",
|
|
20
|
+
"host",
|
|
21
|
+
"transfer-encoding",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True)
|
|
26
|
+
class Hop:
|
|
27
|
+
method: str
|
|
28
|
+
url: str
|
|
29
|
+
headers: dict[str, str]
|
|
30
|
+
content: BodyPayload | None
|
|
31
|
+
cross: bool = False
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def origin(url: str) -> tuple[str, str | None, int | None]:
|
|
35
|
+
parts = urlsplit(url)
|
|
36
|
+
return parts.scheme, parts.hostname, parts.port
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def follow(
|
|
40
|
+
hop: Hop,
|
|
41
|
+
status: int,
|
|
42
|
+
location: str | None,
|
|
43
|
+
policy: Literal["same-origin", "follow", "manual"],
|
|
44
|
+
start: str,
|
|
45
|
+
) -> Hop | None:
|
|
46
|
+
if policy == "manual" or status not in (301, 302, 303, 307, 308) or not location:
|
|
47
|
+
return None
|
|
48
|
+
try:
|
|
49
|
+
target = urljoin(hop.url, location)
|
|
50
|
+
cross = origin(target) != origin(start)
|
|
51
|
+
except ValueError:
|
|
52
|
+
return None
|
|
53
|
+
if urlsplit(target).scheme not in ("http", "https") or (
|
|
54
|
+
cross and policy != "follow"
|
|
55
|
+
):
|
|
56
|
+
return None
|
|
57
|
+
to_get = (
|
|
58
|
+
hop.method != "HEAD" if status == 303 else status < 303 and hop.method == "POST"
|
|
59
|
+
)
|
|
60
|
+
headers = {
|
|
61
|
+
k: v
|
|
62
|
+
for k, v in hop.headers.items()
|
|
63
|
+
if not (to_get and k.lower() == "content-type")
|
|
64
|
+
}
|
|
65
|
+
if (
|
|
66
|
+
not to_get
|
|
67
|
+
and hop.content is not None
|
|
68
|
+
and (cross or not isinstance(hop.content, bytes))
|
|
69
|
+
):
|
|
70
|
+
return None
|
|
71
|
+
if cross:
|
|
72
|
+
headers = {k: v for k, v in headers.items() if k.lower() in SAFE}
|
|
73
|
+
method = "GET" if to_get else hop.method
|
|
74
|
+
return replace(
|
|
75
|
+
hop,
|
|
76
|
+
method=method,
|
|
77
|
+
url=target,
|
|
78
|
+
headers=headers,
|
|
79
|
+
content=None if to_get else hop.content,
|
|
80
|
+
cross=cross,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def cross(request: httpx2.Request, hop: Hop) -> dict[str, Any]:
|
|
85
|
+
if not hop.cross:
|
|
86
|
+
return {}
|
|
87
|
+
for name in foreign(request.headers):
|
|
88
|
+
del request.headers[name]
|
|
89
|
+
return {"auth": None}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def foreign(names: Iterable[str]) -> list[str]:
|
|
93
|
+
return [name for name in names if name.lower() not in SAFE + FRAMING]
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""What ``client.safe`` answers: ``Ok``, or ``Err`` with the error the call raises for an answer."""
|
|
3
|
+
|
|
4
|
+
from collections.abc import Callable, Coroutine
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any, Concatenate, Generic, ParamSpec, TypeAlias, TypeVar, cast
|
|
7
|
+
|
|
8
|
+
from .config import RawResponse
|
|
9
|
+
from .errors import APIStatusError, DecodeError
|
|
10
|
+
|
|
11
|
+
__all__ = ["Err", "Ok", "Result"]
|
|
12
|
+
|
|
13
|
+
T = TypeVar("T")
|
|
14
|
+
E = TypeVar("E")
|
|
15
|
+
P = ParamSpec("P")
|
|
16
|
+
|
|
17
|
+
ANSWERS = (APIStatusError, DecodeError)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class Ok(Generic[T]):
|
|
22
|
+
data: T
|
|
23
|
+
response: RawResponse
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True)
|
|
27
|
+
class Err(Generic[E]):
|
|
28
|
+
error: E
|
|
29
|
+
response: RawResponse
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
Result: TypeAlias = Ok[T] | Err[APIStatusError | DecodeError]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Safe:
|
|
36
|
+
"""The transport under ``client.safe``; ``of`` types a method as its safe twin, ``keep`` a connection's."""
|
|
37
|
+
|
|
38
|
+
def __init__(self, t: Any) -> None:
|
|
39
|
+
self.t = t
|
|
40
|
+
|
|
41
|
+
def __getattr__(self, name: str) -> Any:
|
|
42
|
+
return getattr(self.t, {"call": "result", "sse": "safe_sse"}.get(name, name))
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def of(
|
|
46
|
+
f: Callable[Concatenate[Any, P], Coroutine[Any, Any, T]],
|
|
47
|
+
) -> Callable[Concatenate[Any, P], Coroutine[Any, Any, Result[T]]]:
|
|
48
|
+
return cast("Callable[Concatenate[Any, P], Coroutine[Any, Any, Result[T]]]", f)
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def of_sync(
|
|
52
|
+
f: Callable[Concatenate[Any, P], T],
|
|
53
|
+
) -> Callable[Concatenate[Any, P], Result[T]]:
|
|
54
|
+
return cast("Callable[Concatenate[Any, P], Result[T]]", f)
|
|
55
|
+
|
|
56
|
+
@staticmethod
|
|
57
|
+
def keep(f: Callable[Concatenate[Any, P], T]) -> Callable[Concatenate[Any, P], T]:
|
|
58
|
+
return f
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""The async shell: the core's hops sent with ``httpx2.AsyncClient``. An ``asyncio.Event`` ``cancel`` is
|
|
3
|
+
raced against each send; a ``threading.Event`` is checked between steps."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from typing import TypeVar, Unpack, cast
|
|
7
|
+
|
|
8
|
+
import httpx2
|
|
9
|
+
|
|
10
|
+
from .auth import refresh_async
|
|
11
|
+
from .config import ClientConfig, Defaults
|
|
12
|
+
from .errors import APIConnectionError, APITimeoutError, HoneyError
|
|
13
|
+
from .events import EventStream, raced
|
|
14
|
+
from .exchange import CallArgs, ClientCore, Exchange, HttpAnswer, failure
|
|
15
|
+
from .hooks import RequestContext, refuse_hooks, run_async
|
|
16
|
+
from .operation import Operation
|
|
17
|
+
from .redirect import Hop, cross
|
|
18
|
+
from .result import ANSWERS, Err, Ok, Result
|
|
19
|
+
|
|
20
|
+
T = TypeVar("T")
|
|
21
|
+
|
|
22
|
+
LiveResponse = httpx2.Response | None
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class AsyncTransport(ClientCore):
|
|
26
|
+
def __init__(self, config: ClientConfig, defaults: Defaults) -> None:
|
|
27
|
+
refuse_hooks(config, sync=False)
|
|
28
|
+
super().__init__(config, defaults)
|
|
29
|
+
self.http = config.async_http_client or httpx2.AsyncClient()
|
|
30
|
+
|
|
31
|
+
async def call(self, op: Operation[T], **args: Unpack[CallArgs]) -> T:
|
|
32
|
+
x = Exchange(self, op, args)
|
|
33
|
+
return cast("T", x.decoded((await self.run(x))[0]))
|
|
34
|
+
|
|
35
|
+
async def result(self, op: Operation[T], **args: Unpack[CallArgs]) -> Result[T]:
|
|
36
|
+
x = Exchange(self, op, args)
|
|
37
|
+
answer, _ = await self.run(x)
|
|
38
|
+
try:
|
|
39
|
+
return Ok(cast("T", x.decoded(answer)), x.raw)
|
|
40
|
+
except ANSWERS as error:
|
|
41
|
+
return Err(error, x.raw)
|
|
42
|
+
|
|
43
|
+
async def sse(
|
|
44
|
+
self,
|
|
45
|
+
op: Operation[T],
|
|
46
|
+
*,
|
|
47
|
+
last_event_id: str | None = None,
|
|
48
|
+
**args: Unpack[CallArgs],
|
|
49
|
+
) -> EventStream[T]:
|
|
50
|
+
r = await self.safe_sse(op, last_event_id=last_event_id, **args)
|
|
51
|
+
if isinstance(r, Err):
|
|
52
|
+
raise r.error
|
|
53
|
+
return r.data
|
|
54
|
+
|
|
55
|
+
async def safe_sse(
|
|
56
|
+
self,
|
|
57
|
+
op: Operation[T],
|
|
58
|
+
*,
|
|
59
|
+
last_event_id: str | None = None,
|
|
60
|
+
**args: Unpack[CallArgs],
|
|
61
|
+
) -> Result[EventStream[T]]:
|
|
62
|
+
resume = {"Last-Event-ID": last_event_id or None}
|
|
63
|
+
x = Exchange(
|
|
64
|
+
self,
|
|
65
|
+
op,
|
|
66
|
+
{**args, "headers": {**(args.get("headers") or {}), **resume}},
|
|
67
|
+
stream=True,
|
|
68
|
+
)
|
|
69
|
+
try:
|
|
70
|
+
live = await self.opened(x)
|
|
71
|
+
except ANSWERS as error:
|
|
72
|
+
return Err(error, x.raw)
|
|
73
|
+
return Ok(
|
|
74
|
+
EventStream(
|
|
75
|
+
live,
|
|
76
|
+
decode=op.answer == "json",
|
|
77
|
+
shape=op.shape,
|
|
78
|
+
cancel=x.options.get("cancel"),
|
|
79
|
+
),
|
|
80
|
+
x.raw,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
async def opened(self, x: Exchange) -> httpx2.Response:
|
|
84
|
+
answer, live = await self.run(x)
|
|
85
|
+
if live is None:
|
|
86
|
+
raise x.failure or failure(answer, self)
|
|
87
|
+
try:
|
|
88
|
+
x.fill(answer)
|
|
89
|
+
except HoneyError:
|
|
90
|
+
await live.aclose()
|
|
91
|
+
raise
|
|
92
|
+
return live
|
|
93
|
+
|
|
94
|
+
async def run(self, x: Exchange) -> tuple[HttpAnswer, LiveResponse]:
|
|
95
|
+
x.log.started()
|
|
96
|
+
try:
|
|
97
|
+
token = self.auth.token
|
|
98
|
+
answer, live = await self.attempt(x, token, False)
|
|
99
|
+
hook = self.config.on_auth_expired
|
|
100
|
+
if hook is not None and x.retries(answer):
|
|
101
|
+
fresh = await refresh_async(self.auth, hook, token)
|
|
102
|
+
if fresh is not None:
|
|
103
|
+
answer, live = await self.attempt(x, fresh, True)
|
|
104
|
+
except HoneyError as error:
|
|
105
|
+
x.log.failed(error)
|
|
106
|
+
raise
|
|
107
|
+
except asyncio.CancelledError:
|
|
108
|
+
x.log.emit("error", "error", error="the call was canceled")
|
|
109
|
+
raise
|
|
110
|
+
return x.done(answer), live
|
|
111
|
+
|
|
112
|
+
async def prepared(
|
|
113
|
+
self, x: Exchange, token: str | None, is_retry: bool = False
|
|
114
|
+
) -> RequestContext:
|
|
115
|
+
ctx = x.request(token, is_retry)
|
|
116
|
+
await run_async(self.config.on_request, ctx)
|
|
117
|
+
return ctx
|
|
118
|
+
|
|
119
|
+
async def attempt(
|
|
120
|
+
self, x: Exchange, token: str | None, is_retry: bool
|
|
121
|
+
) -> tuple[HttpAnswer, LiveResponse]:
|
|
122
|
+
hop = start = x.hop(await self.prepared(x, token, is_retry))
|
|
123
|
+
while True:
|
|
124
|
+
answer, live = await raced(self.send(x, hop), x.options.get("cancel"))
|
|
125
|
+
nxt = None if live else x.follow(hop, answer, start.url)
|
|
126
|
+
if nxt is None:
|
|
127
|
+
break
|
|
128
|
+
hop = nxt
|
|
129
|
+
response = x.response(answer, is_retry)
|
|
130
|
+
try:
|
|
131
|
+
await run_async(self.config.on_response, response)
|
|
132
|
+
except BaseException:
|
|
133
|
+
if live is not None:
|
|
134
|
+
await live.aclose()
|
|
135
|
+
raise
|
|
136
|
+
return HttpAnswer(
|
|
137
|
+
response.status, response.headers, response.body, answer.url, answer.over
|
|
138
|
+
), live
|
|
139
|
+
|
|
140
|
+
async def send(self, x: Exchange, hop: Hop) -> tuple[HttpAnswer, LiveResponse]:
|
|
141
|
+
left = x.check()
|
|
142
|
+
timeout = httpx2.Timeout(x.timeout, read=None) if x.stream else left
|
|
143
|
+
request = self.http.build_request(
|
|
144
|
+
hop.method,
|
|
145
|
+
hop.url,
|
|
146
|
+
headers=hop.headers,
|
|
147
|
+
content=hop.content,
|
|
148
|
+
timeout=timeout,
|
|
149
|
+
)
|
|
150
|
+
chunks: list[bytes] = []
|
|
151
|
+
over = False
|
|
152
|
+
try:
|
|
153
|
+
sending = self.http.send(
|
|
154
|
+
request, stream=True, follow_redirects=False, **cross(request, hop)
|
|
155
|
+
)
|
|
156
|
+
# a stream reads with no timeout, so the call's bounds its wait for the headers
|
|
157
|
+
response = await (
|
|
158
|
+
asyncio.wait_for(sending, x.timeout)
|
|
159
|
+
if x.stream and x.timeout
|
|
160
|
+
else sending
|
|
161
|
+
)
|
|
162
|
+
if x.stream and 200 <= response.status_code < 300:
|
|
163
|
+
return HttpAnswer(
|
|
164
|
+
response.status_code, response.headers, b"", str(response.url)
|
|
165
|
+
), response
|
|
166
|
+
try:
|
|
167
|
+
async for chunk in response.aiter_bytes():
|
|
168
|
+
if over := x.read(chunks, chunk):
|
|
169
|
+
break
|
|
170
|
+
x.check()
|
|
171
|
+
finally:
|
|
172
|
+
await response.aclose()
|
|
173
|
+
except (httpx2.TimeoutException, TimeoutError) as error:
|
|
174
|
+
raise APITimeoutError("the call ran past its timeout") from error
|
|
175
|
+
except httpx2.HTTPError as error:
|
|
176
|
+
raise APIConnectionError(
|
|
177
|
+
f"the request failed: {type(error).__name__}"
|
|
178
|
+
) from error
|
|
179
|
+
return HttpAnswer(
|
|
180
|
+
response.status_code,
|
|
181
|
+
response.headers,
|
|
182
|
+
b"" if over else b"".join(chunks),
|
|
183
|
+
str(response.url),
|
|
184
|
+
over,
|
|
185
|
+
), None
|
|
186
|
+
|
|
187
|
+
async def aclose(self) -> None:
|
|
188
|
+
if self.config.async_http_client is None:
|
|
189
|
+
await self.http.aclose()
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""The blocking shell: the core's hops sent with ``httpx2.Client``; ``cancel`` is checked between steps."""
|
|
3
|
+
|
|
4
|
+
from typing import TypeVar, Unpack, cast
|
|
5
|
+
|
|
6
|
+
import httpx2
|
|
7
|
+
|
|
8
|
+
from .auth import refresh_sync
|
|
9
|
+
from .config import ClientConfig, Defaults
|
|
10
|
+
from .errors import APIConnectionError, APITimeoutError, HoneyError
|
|
11
|
+
from .exchange import CallArgs, ClientCore, Exchange, HttpAnswer
|
|
12
|
+
from .hooks import refuse_hooks, run_sync
|
|
13
|
+
from .operation import Operation
|
|
14
|
+
from .redirect import Hop, cross
|
|
15
|
+
from .result import ANSWERS, Err, Ok, Result
|
|
16
|
+
|
|
17
|
+
T = TypeVar("T")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SyncTransport(ClientCore):
|
|
21
|
+
def __init__(self, config: ClientConfig, defaults: Defaults) -> None:
|
|
22
|
+
refuse_hooks(config, sync=True)
|
|
23
|
+
super().__init__(config, defaults)
|
|
24
|
+
self.http = config.http_client or httpx2.Client()
|
|
25
|
+
|
|
26
|
+
def call(self, op: Operation[T], **args: Unpack[CallArgs]) -> T:
|
|
27
|
+
x = Exchange(self, op, args)
|
|
28
|
+
return cast("T", x.decoded(self.run(x)))
|
|
29
|
+
|
|
30
|
+
def result(self, op: Operation[T], **args: Unpack[CallArgs]) -> Result[T]:
|
|
31
|
+
x = Exchange(self, op, args)
|
|
32
|
+
answer = self.run(x)
|
|
33
|
+
try:
|
|
34
|
+
return Ok(cast("T", x.decoded(answer)), x.raw)
|
|
35
|
+
except ANSWERS as error:
|
|
36
|
+
return Err(error, x.raw)
|
|
37
|
+
|
|
38
|
+
def run(self, x: Exchange) -> HttpAnswer:
|
|
39
|
+
x.log.started()
|
|
40
|
+
try:
|
|
41
|
+
token = self.auth.token
|
|
42
|
+
answer = self.attempt(x, token, False)
|
|
43
|
+
hook = self.config.on_auth_expired
|
|
44
|
+
if hook is not None and x.retries(answer):
|
|
45
|
+
fresh = refresh_sync(self.auth, hook, token)
|
|
46
|
+
answer = answer if fresh is None else self.attempt(x, fresh, True)
|
|
47
|
+
except HoneyError as error:
|
|
48
|
+
x.log.failed(error)
|
|
49
|
+
raise
|
|
50
|
+
return x.done(answer)
|
|
51
|
+
|
|
52
|
+
def attempt(self, x: Exchange, token: str | None, is_retry: bool) -> HttpAnswer:
|
|
53
|
+
ctx = x.request(token, is_retry)
|
|
54
|
+
run_sync(self.config.on_request_sync, ctx)
|
|
55
|
+
hop = start = x.hop(ctx)
|
|
56
|
+
while True:
|
|
57
|
+
answer = self.send(x, hop)
|
|
58
|
+
nxt = x.follow(hop, answer, start.url)
|
|
59
|
+
if nxt is None:
|
|
60
|
+
break
|
|
61
|
+
hop = nxt
|
|
62
|
+
response = x.response(answer, is_retry)
|
|
63
|
+
run_sync(self.config.on_response_sync, response)
|
|
64
|
+
return HttpAnswer(
|
|
65
|
+
response.status, response.headers, response.body, answer.url, answer.over
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def send(self, x: Exchange, hop: Hop) -> HttpAnswer:
|
|
69
|
+
request = self.http.build_request(
|
|
70
|
+
hop.method,
|
|
71
|
+
hop.url,
|
|
72
|
+
headers=hop.headers,
|
|
73
|
+
content=hop.content,
|
|
74
|
+
timeout=x.check(),
|
|
75
|
+
)
|
|
76
|
+
chunks: list[bytes] = []
|
|
77
|
+
over = False
|
|
78
|
+
try:
|
|
79
|
+
response = self.http.send(
|
|
80
|
+
request, stream=True, follow_redirects=False, **cross(request, hop)
|
|
81
|
+
)
|
|
82
|
+
try:
|
|
83
|
+
for chunk in response.iter_bytes():
|
|
84
|
+
if over := x.read(chunks, chunk):
|
|
85
|
+
break
|
|
86
|
+
x.check()
|
|
87
|
+
finally:
|
|
88
|
+
response.close()
|
|
89
|
+
except httpx2.TimeoutException as error:
|
|
90
|
+
raise APITimeoutError("the call ran past its timeout") from error
|
|
91
|
+
except httpx2.HTTPError as error:
|
|
92
|
+
raise APIConnectionError(
|
|
93
|
+
f"the request failed: {type(error).__name__}"
|
|
94
|
+
) from error
|
|
95
|
+
return HttpAnswer(
|
|
96
|
+
response.status_code,
|
|
97
|
+
response.headers,
|
|
98
|
+
b"" if over else b"".join(chunks),
|
|
99
|
+
str(response.url),
|
|
100
|
+
over,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
def close(self) -> None:
|
|
104
|
+
if self.config.http_client is None:
|
|
105
|
+
self.http.close()
|