@workerstack/clients 0.0.0-stage → 1.0.0-rc.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +619 -2
- package/bin/honey-clients.js +94 -0
- package/dist/cli.d.ts +102 -0
- package/dist/cli.js +190 -0
- package/dist/emit/cli/channels.d.ts +73 -0
- package/dist/emit/cli/channels.js +197 -0
- package/dist/emit/cli/commands.d.ts +27 -0
- package/dist/emit/cli/commands.js +187 -0
- package/dist/emit/cli/discovery.d.ts +35 -0
- package/dist/emit/cli/discovery.js +202 -0
- package/dist/emit/cli/flags.d.ts +59 -0
- package/dist/emit/cli/flags.js +186 -0
- package/dist/emit/cli/index.d.ts +1 -0
- package/dist/emit/cli/index.js +1 -0
- package/dist/emit/cli/install.d.ts +37 -0
- package/dist/emit/cli/install.js +88 -0
- package/dist/emit/cli/layout.d.ts +23 -0
- package/dist/emit/cli/layout.js +118 -0
- package/dist/emit/cli/module.d.ts +30 -0
- package/dist/emit/cli/module.js +186 -0
- package/dist/emit/cli/release.d.ts +40 -0
- package/dist/emit/cli/release.js +183 -0
- package/dist/emit/cli/skills.d.ts +11 -0
- package/dist/emit/cli/skills.js +56 -0
- package/dist/emit/csharp/errors.d.ts +7 -0
- package/dist/emit/csharp/errors.js +69 -0
- package/dist/emit/csharp/index.d.ts +1 -0
- package/dist/emit/csharp/index.js +1 -0
- package/dist/emit/csharp/json.d.ts +13 -0
- package/dist/emit/csharp/json.js +113 -0
- package/dist/emit/csharp/realtime.d.ts +10 -0
- package/dist/emit/csharp/realtime.js +33 -0
- package/dist/emit/csharp/sdk-answer.d.ts +48 -0
- package/dist/emit/csharp/sdk-answer.js +85 -0
- package/dist/emit/csharp/sdk-body.d.ts +10 -0
- package/dist/emit/csharp/sdk-body.js +87 -0
- package/dist/emit/csharp/sdk-client.d.ts +32 -0
- package/dist/emit/csharp/sdk-client.js +177 -0
- package/dist/emit/csharp/sdk-csproj.d.ts +36 -0
- package/dist/emit/csharp/sdk-csproj.js +136 -0
- package/dist/emit/csharp/sdk-doc.d.ts +12 -0
- package/dist/emit/csharp/sdk-doc.js +35 -0
- package/dist/emit/csharp/sdk-method.d.ts +26 -0
- package/dist/emit/csharp/sdk-method.js +187 -0
- package/dist/emit/csharp/sdk-plan.d.ts +38 -0
- package/dist/emit/csharp/sdk-plan.js +1 -0
- package/dist/emit/csharp/sdk.d.ts +40 -0
- package/dist/emit/csharp/sdk.js +105 -0
- package/dist/emit/csharp/sse.d.ts +18 -0
- package/dist/emit/csharp/sse.js +29 -0
- package/dist/emit/csharp/transport.d.ts +11 -0
- package/dist/emit/csharp/transport.js +67 -0
- package/dist/emit/csharp/types-enum.d.ts +19 -0
- package/dist/emit/csharp/types-enum.js +63 -0
- package/dist/emit/csharp/types-names.d.ts +33 -0
- package/dist/emit/csharp/types-names.js +182 -0
- package/dist/emit/csharp/types-record.d.ts +25 -0
- package/dist/emit/csharp/types-record.js +65 -0
- package/dist/emit/csharp/types-union.d.ts +27 -0
- package/dist/emit/csharp/types-union.js +113 -0
- package/dist/emit/csharp/types.d.ts +36 -0
- package/dist/emit/csharp/types.js +126 -0
- package/dist/emit/csharp/ws.d.ts +20 -0
- package/dist/emit/csharp/ws.js +14 -0
- package/dist/emit/go/errors.d.ts +7 -0
- package/dist/emit/go/errors.js +44 -0
- package/dist/emit/go/http.d.ts +11 -0
- package/dist/emit/go/http.js +50 -0
- package/dist/emit/go/index.d.ts +1 -0
- package/dist/emit/go/index.js +1 -0
- package/dist/emit/go/module-path.d.ts +2 -0
- package/dist/emit/go/module-path.js +27 -0
- package/dist/emit/go/sdk-answer.d.ts +28 -0
- package/dist/emit/go/sdk-answer.js +41 -0
- package/dist/emit/go/sdk-body.d.ts +24 -0
- package/dist/emit/go/sdk-body.js +76 -0
- package/dist/emit/go/sdk-client.d.ts +29 -0
- package/dist/emit/go/sdk-client.js +141 -0
- package/dist/emit/go/sdk-method.d.ts +68 -0
- package/dist/emit/go/sdk-method.js +172 -0
- package/dist/emit/go/sdk-mirror.d.ts +23 -0
- package/dist/emit/go/sdk-mirror.js +97 -0
- package/dist/emit/go/sdk-opts.d.ts +55 -0
- package/dist/emit/go/sdk-opts.js +100 -0
- package/dist/emit/go/sdk.d.ts +26 -0
- package/dist/emit/go/sdk.js +111 -0
- package/dist/emit/go/sse.d.ts +16 -0
- package/dist/emit/go/sse.js +26 -0
- package/dist/emit/go/types-codec.d.ts +15 -0
- package/dist/emit/go/types-codec.js +171 -0
- package/dist/emit/go/types-names.d.ts +14 -0
- package/dist/emit/go/types-names.js +64 -0
- package/dist/emit/go/types-struct.d.ts +29 -0
- package/dist/emit/go/types-struct.js +65 -0
- package/dist/emit/go/types-union.d.ts +17 -0
- package/dist/emit/go/types-union.js +84 -0
- package/dist/emit/go/types.d.ts +32 -0
- package/dist/emit/go/types.js +177 -0
- package/dist/emit/go/ws.d.ts +12 -0
- package/dist/emit/go/ws.js +70 -0
- package/dist/emit/java/gradle.d.ts +57 -0
- package/dist/emit/java/gradle.js +221 -0
- package/dist/emit/java/index.d.ts +2 -0
- package/dist/emit/java/index.js +2 -0
- package/dist/emit/java/json.d.ts +13 -0
- package/dist/emit/java/json.js +84 -0
- package/dist/emit/java/layout-ast.d.ts +146 -0
- package/dist/emit/java/layout-ast.js +102 -0
- package/dist/emit/java/layout-decl.d.ts +20 -0
- package/dist/emit/java/layout-decl.js +155 -0
- package/dist/emit/java/layout-doc.d.ts +55 -0
- package/dist/emit/java/layout-doc.js +166 -0
- package/dist/emit/java/layout-dot.d.ts +18 -0
- package/dist/emit/java/layout-dot.js +127 -0
- package/dist/emit/java/layout-strings.d.ts +8 -0
- package/dist/emit/java/layout-strings.js +76 -0
- package/dist/emit/java/layout-types.d.ts +11 -0
- package/dist/emit/java/layout-types.js +95 -0
- package/dist/emit/java/layout-visitor.d.ts +38 -0
- package/dist/emit/java/layout-visitor.js +232 -0
- package/dist/emit/java/layout.d.ts +61 -0
- package/dist/emit/java/layout.js +121 -0
- package/dist/emit/java/models-enum.d.ts +17 -0
- package/dist/emit/java/models-enum.js +51 -0
- package/dist/emit/java/models-names.d.ts +29 -0
- package/dist/emit/java/models-names.js +97 -0
- package/dist/emit/java/models-record.d.ts +24 -0
- package/dist/emit/java/models-record.js +79 -0
- package/dist/emit/java/models-union.d.ts +27 -0
- package/dist/emit/java/models-union.js +86 -0
- package/dist/emit/java/models.d.ts +28 -0
- package/dist/emit/java/models.js +118 -0
- package/dist/emit/java/realtime.d.ts +50 -0
- package/dist/emit/java/realtime.js +69 -0
- package/dist/emit/java/sdk-client.d.ts +66 -0
- package/dist/emit/java/sdk-client.js +207 -0
- package/dist/emit/java/sdk-decl.d.ts +11 -0
- package/dist/emit/java/sdk-decl.js +63 -0
- package/dist/emit/java/sdk-errors.d.ts +13 -0
- package/dist/emit/java/sdk-errors.js +141 -0
- package/dist/emit/java/sdk-headers.d.ts +12 -0
- package/dist/emit/java/sdk-headers.js +74 -0
- package/dist/emit/java/sdk-mirror.d.ts +14 -0
- package/dist/emit/java/sdk-mirror.js +107 -0
- package/dist/emit/java/sdk-models.d.ts +16 -0
- package/dist/emit/java/sdk-models.js +68 -0
- package/dist/emit/java/sdk-op.d.ts +57 -0
- package/dist/emit/java/sdk-op.js +216 -0
- package/dist/emit/java/sdk-params.d.ts +38 -0
- package/dist/emit/java/sdk-params.js +133 -0
- package/dist/emit/java/sdk-plan.d.ts +52 -0
- package/dist/emit/java/sdk-plan.js +1 -0
- package/dist/emit/java/sdk-record.d.ts +16 -0
- package/dist/emit/java/sdk-record.js +99 -0
- package/dist/emit/java/sdk.d.ts +49 -0
- package/dist/emit/java/sdk.js +216 -0
- package/dist/emit/java/sse.d.ts +35 -0
- package/dist/emit/java/sse.js +57 -0
- package/dist/emit/java/ws.d.ts +27 -0
- package/dist/emit/java/ws.js +31 -0
- package/dist/emit/mcp/annotations.d.ts +15 -0
- package/dist/emit/mcp/annotations.js +15 -0
- package/dist/emit/mcp/files.d.ts +18 -0
- package/dist/emit/mcp/files.js +42 -0
- package/dist/emit/mcp/index.d.ts +3 -0
- package/dist/emit/mcp/index.js +3 -0
- package/dist/emit/mcp/literal.d.ts +2 -0
- package/dist/emit/mcp/literal.js +33 -0
- package/dist/emit/mcp/mounted.d.ts +21 -0
- package/dist/emit/mcp/mounted.js +89 -0
- package/dist/emit/mcp/output-schema.d.ts +18 -0
- package/dist/emit/mcp/output-schema.js +38 -0
- package/dist/emit/mcp/registry.d.ts +23 -0
- package/dist/emit/mcp/registry.js +83 -0
- package/dist/emit/mcp/runtime.d.ts +10 -0
- package/dist/emit/mcp/runtime.js +47 -0
- package/dist/emit/mcp/schema.d.ts +19 -0
- package/dist/emit/mcp/schema.js +88 -0
- package/dist/emit/mcp/server.d.ts +30 -0
- package/dist/emit/mcp/server.js +246 -0
- package/dist/emit/mcp/tools.d.ts +51 -0
- package/dist/emit/mcp/tools.js +153 -0
- package/dist/emit/python/errors.d.ts +8 -0
- package/dist/emit/python/errors.js +68 -0
- package/dist/emit/python/index.d.ts +1 -0
- package/dist/emit/python/index.js +1 -0
- package/dist/emit/python/realtime.d.ts +10 -0
- package/dist/emit/python/realtime.js +33 -0
- package/dist/emit/python/sdk-answer.d.ts +49 -0
- package/dist/emit/python/sdk-answer.js +89 -0
- package/dist/emit/python/sdk-body.d.ts +11 -0
- package/dist/emit/python/sdk-body.js +40 -0
- package/dist/emit/python/sdk-client.d.ts +36 -0
- package/dist/emit/python/sdk-client.js +163 -0
- package/dist/emit/python/sdk-doc.d.ts +9 -0
- package/dist/emit/python/sdk-doc.js +32 -0
- package/dist/emit/python/sdk-imports.d.ts +14 -0
- package/dist/emit/python/sdk-imports.js +38 -0
- package/dist/emit/python/sdk-method.d.ts +29 -0
- package/dist/emit/python/sdk-method.js +183 -0
- package/dist/emit/python/sdk-plan.d.ts +33 -0
- package/dist/emit/python/sdk-plan.js +1 -0
- package/dist/emit/python/sdk-pyproject.d.ts +27 -0
- package/dist/emit/python/sdk-pyproject.js +103 -0
- package/dist/emit/python/sdk.d.ts +22 -0
- package/dist/emit/python/sdk.js +154 -0
- package/dist/emit/python/sse.d.ts +12 -0
- package/dist/emit/python/sse.js +23 -0
- package/dist/emit/python/transport.d.ts +15 -0
- package/dist/emit/python/transport.js +60 -0
- package/dist/emit/python/types-dict.d.ts +31 -0
- package/dist/emit/python/types-dict.js +45 -0
- package/dist/emit/python/types-names.d.ts +16 -0
- package/dist/emit/python/types-names.js +52 -0
- package/dist/emit/python/types-union.d.ts +32 -0
- package/dist/emit/python/types-union.js +46 -0
- package/dist/emit/python/types.d.ts +36 -0
- package/dist/emit/python/types.js +128 -0
- package/dist/emit/python/ws.d.ts +14 -0
- package/dist/emit/python/ws.js +16 -0
- package/dist/emit/rust/errors.d.ts +7 -0
- package/dist/emit/rust/errors.js +107 -0
- package/dist/emit/rust/http.d.ts +13 -0
- package/dist/emit/rust/http.js +67 -0
- package/dist/emit/rust/index.d.ts +1 -0
- package/dist/emit/rust/index.js +1 -0
- package/dist/emit/rust/realtime.d.ts +11 -0
- package/dist/emit/rust/realtime.js +29 -0
- package/dist/emit/rust/sdk-body.d.ts +19 -0
- package/dist/emit/rust/sdk-body.js +53 -0
- package/dist/emit/rust/sdk-cargo.d.ts +43 -0
- package/dist/emit/rust/sdk-cargo.js +178 -0
- package/dist/emit/rust/sdk-client.d.ts +25 -0
- package/dist/emit/rust/sdk-client.js +108 -0
- package/dist/emit/rust/sdk-method.d.ts +15 -0
- package/dist/emit/rust/sdk-method.js +119 -0
- package/dist/emit/rust/sdk-opts.d.ts +58 -0
- package/dist/emit/rust/sdk-opts.js +117 -0
- package/dist/emit/rust/sdk-plan.d.ts +33 -0
- package/dist/emit/rust/sdk-plan.js +1 -0
- package/dist/emit/rust/sdk.d.ts +23 -0
- package/dist/emit/rust/sdk.js +111 -0
- package/dist/emit/rust/sse.d.ts +19 -0
- package/dist/emit/rust/sse.js +20 -0
- package/dist/emit/rust/types-enum.d.ts +13 -0
- package/dist/emit/rust/types-enum.js +62 -0
- package/dist/emit/rust/types-names.d.ts +19 -0
- package/dist/emit/rust/types-names.js +66 -0
- package/dist/emit/rust/types-struct.d.ts +21 -0
- package/dist/emit/rust/types-struct.js +59 -0
- package/dist/emit/rust/types-union.d.ts +24 -0
- package/dist/emit/rust/types-union.js +97 -0
- package/dist/emit/rust/types.d.ts +34 -0
- package/dist/emit/rust/types.js +105 -0
- package/dist/emit/rust/ws.d.ts +21 -0
- package/dist/emit/rust/ws.js +20 -0
- package/dist/emit/shared/escape.d.ts +55 -0
- package/dist/emit/shared/escape.js +144 -0
- package/dist/emit/shared/format.d.ts +24 -0
- package/dist/emit/shared/format.js +23 -0
- package/dist/emit/shared/gofmt.d.ts +3 -0
- package/dist/emit/shared/gofmt.js +26 -0
- package/dist/emit/shared/lang.d.ts +60 -0
- package/dist/emit/shared/lang.js +233 -0
- package/dist/emit/shared/literals.d.ts +4 -0
- package/dist/emit/shared/literals.js +31 -0
- package/dist/emit/shared/metadata.d.ts +106 -0
- package/dist/emit/shared/metadata.js +130 -0
- package/dist/emit/shared/mirror.d.ts +22 -0
- package/dist/emit/shared/mirror.js +26 -0
- package/dist/emit/shared/ruff.d.ts +3 -0
- package/dist/emit/shared/ruff.js +31 -0
- package/dist/emit/shared/rustfmt.d.ts +3 -0
- package/dist/emit/shared/rustfmt.js +32 -0
- package/dist/emit/shared/status-keys.d.ts +7 -0
- package/dist/emit/shared/status-keys.js +67 -0
- package/dist/emit/shared/type-emitter.d.ts +19 -0
- package/dist/emit/shared/type-emitter.js +100 -0
- package/dist/emit/ts/app-client.d.ts +4 -0
- package/dist/emit/ts/app-client.js +68 -0
- package/dist/emit/ts/http.d.ts +20 -0
- package/dist/emit/ts/http.js +74 -0
- package/dist/emit/ts/package.d.ts +36 -0
- package/dist/emit/ts/package.js +126 -0
- package/dist/emit/ts/route-tree.d.ts +68 -0
- package/dist/emit/ts/route-tree.js +240 -0
- package/dist/emit/ts/sdk-types-preamble.d.ts +14 -0
- package/dist/emit/ts/sdk-types-preamble.js +123 -0
- package/dist/emit/ts/sdk-types.d.ts +13 -0
- package/dist/emit/ts/sdk-types.js +213 -0
- package/dist/emit/ts/sdk.d.ts +21 -0
- package/dist/emit/ts/sdk.js +173 -0
- package/dist/emit/ts/service-map.d.ts +40 -0
- package/dist/emit/ts/service-map.js +171 -0
- package/dist/emit/ts/tanstack-query.d.ts +12 -0
- package/dist/emit/ts/tanstack-query.js +156 -0
- package/dist/emit/ts/type-gen.d.ts +26 -0
- package/dist/emit/ts/type-gen.js +255 -0
- package/dist/emit/ts/webhooks.d.ts +19 -0
- package/dist/emit/ts/webhooks.js +81 -0
- package/dist/extract/chain.d.ts +34 -0
- package/dist/extract/chain.js +84 -0
- package/dist/extract/extract.d.ts +41 -0
- package/dist/extract/extract.js +191 -0
- package/dist/extract/serialize.d.ts +34 -0
- package/dist/extract/serialize.js +295 -0
- package/dist/extract/walk.d.ts +47 -0
- package/dist/extract/walk.js +109 -0
- package/dist/gen/args.d.ts +28 -0
- package/dist/gen/args.js +133 -0
- package/dist/gen/formatters.d.ts +62 -0
- package/dist/gen/formatters.js +146 -0
- package/dist/gen/process.d.ts +13 -0
- package/dist/gen/process.js +35 -0
- package/dist/gen/shipped.d.ts +17 -0
- package/dist/gen/shipped.js +55 -0
- package/dist/gen/targets.d.ts +93 -0
- package/dist/gen/targets.js +171 -0
- package/dist/gen/write.d.ts +33 -0
- package/dist/gen/write.js +118 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +15 -0
- package/dist/ir/build.d.ts +37 -0
- package/dist/ir/build.js +152 -0
- package/dist/ir/load.d.ts +11 -0
- package/dist/ir/load.js +112 -0
- package/dist/ir/model.d.ts +206 -0
- package/dist/ir/model.js +5 -0
- package/dist/ir/resolve-refs.d.ts +11 -0
- package/dist/ir/resolve-refs.js +66 -0
- package/dist/ir/resource-tree.d.ts +9 -0
- package/dist/ir/resource-tree.js +53 -0
- package/dist/ir/route-tree-intern.d.ts +18 -0
- package/dist/ir/route-tree-intern.js +174 -0
- package/dist/ir/schema.d.ts +11 -0
- package/dist/ir/schema.js +192 -0
- package/dist/ir/sdk-model.d.ts +86 -0
- package/dist/ir/sdk-model.js +204 -0
- package/dist/ir/slots.d.ts +42 -0
- package/dist/ir/slots.js +245 -0
- package/dist/runtime/cli/body.go +176 -0
- package/dist/runtime/cli/config.go +243 -0
- package/dist/runtime/cli/discovery.go +147 -0
- package/dist/runtime/cli/format.go +174 -0
- package/dist/runtime/cli/log.go +117 -0
- package/dist/runtime/cli/output.go +247 -0
- package/dist/runtime/cli/params.go +197 -0
- package/dist/runtime/cli/run.go +226 -0
- package/dist/runtime/cli/socket.go +60 -0
- package/dist/runtime/cli/stream.go +217 -0
- package/dist/runtime/cli/target.go +117 -0
- package/dist/runtime/csharp/Adapters.cs +183 -0
- package/dist/runtime/csharp/Auth.cs +56 -0
- package/dist/runtime/csharp/Body.cs +135 -0
- package/dist/runtime/csharp/Config.cs +161 -0
- package/dist/runtime/csharp/Envelope.cs +149 -0
- package/dist/runtime/csharp/Errors.cs +194 -0
- package/dist/runtime/csharp/Events.cs +155 -0
- package/dist/runtime/csharp/Exchange.cs +247 -0
- package/dist/runtime/csharp/Handler.cs +103 -0
- package/dist/runtime/csharp/Hooks.cs +128 -0
- package/dist/runtime/csharp/Invalidation.cs +102 -0
- package/dist/runtime/csharp/Json.cs +144 -0
- package/dist/runtime/csharp/Log.cs +48 -0
- package/dist/runtime/csharp/Operation.cs +33 -0
- package/dist/runtime/csharp/Path.cs +65 -0
- package/dist/runtime/csharp/Query.cs +72 -0
- package/dist/runtime/csharp/Realtime.cs +118 -0
- package/dist/runtime/csharp/RealtimeLoop.cs +236 -0
- package/dist/runtime/csharp/Redirect.cs +53 -0
- package/dist/runtime/csharp/Result.cs +57 -0
- package/dist/runtime/csharp/Sse.cs +122 -0
- package/dist/runtime/csharp/Stale.cs +151 -0
- package/dist/runtime/csharp/Transport.cs +143 -0
- package/dist/runtime/csharp/TransportLongPoll.cs +63 -0
- package/dist/runtime/csharp/TransportSse.cs +54 -0
- package/dist/runtime/csharp/TransportWs.cs +40 -0
- package/dist/runtime/csharp/Wire.cs +109 -0
- package/dist/runtime/csharp/Ws.cs +300 -0
- package/dist/runtime/csharp/WsDial.cs +127 -0
- package/dist/runtime/go/auth.go +127 -0
- package/dist/runtime/go/body.go +129 -0
- package/dist/runtime/go/config.go +75 -0
- package/dist/runtime/go/errors.go +185 -0
- package/dist/runtime/go/export.go +37 -0
- package/dist/runtime/go/hooks.go +53 -0
- package/dist/runtime/go/invalidation.go +112 -0
- package/dist/runtime/go/log.go +92 -0
- package/dist/runtime/go/nullable.go +64 -0
- package/dist/runtime/go/options.go +118 -0
- package/dist/runtime/go/path.go +156 -0
- package/dist/runtime/go/query.go +147 -0
- package/dist/runtime/go/realtime.go +239 -0
- package/dist/runtime/go/realtime_loop.go +208 -0
- package/dist/runtime/go/redirect.go +124 -0
- package/dist/runtime/go/request.go +222 -0
- package/dist/runtime/go/result.go +86 -0
- package/dist/runtime/go/sse.go +186 -0
- package/dist/runtime/go/stale.go +229 -0
- package/dist/runtime/go/stream.go +105 -0
- package/dist/runtime/go/transport.go +242 -0
- package/dist/runtime/go/transport_longpoll.go +121 -0
- package/dist/runtime/go/transport_sse.go +175 -0
- package/dist/runtime/go/ws.go +205 -0
- package/dist/runtime/java/Answer.java +107 -0
- package/dist/runtime/java/ApiException.java +110 -0
- package/dist/runtime/java/BinaryBody.java +36 -0
- package/dist/runtime/java/Body.java +105 -0
- package/dist/runtime/java/Call.java +23 -0
- package/dist/runtime/java/CallLog.java +51 -0
- package/dist/runtime/java/ClientConfig.java +233 -0
- package/dist/runtime/java/ConnectionState.java +12 -0
- package/dist/runtime/java/Credential.java +58 -0
- package/dist/runtime/java/Deadline.java +38 -0
- package/dist/runtime/java/Decode.java +181 -0
- package/dist/runtime/java/Envelope.java +141 -0
- package/dist/runtime/java/ErrorEnvelope.java +23 -0
- package/dist/runtime/java/EventStream.java +129 -0
- package/dist/runtime/java/Exchange.java +62 -0
- package/dist/runtime/java/FilePart.java +5 -0
- package/dist/runtime/java/Flight.java +306 -0
- package/dist/runtime/java/HoneyException.java +14 -0
- package/dist/runtime/java/Hooks.java +47 -0
- package/dist/runtime/java/Hops.java +133 -0
- package/dist/runtime/java/InvalidationConfig.java +73 -0
- package/dist/runtime/java/Json.java +23 -0
- package/dist/runtime/java/Keepalive.java +60 -0
- package/dist/runtime/java/LogEntry.java +14 -0
- package/dist/runtime/java/LongPollAdapter.java +68 -0
- package/dist/runtime/java/Operation.java +21 -0
- package/dist/runtime/java/Opt.java +121 -0
- package/dist/runtime/java/Pump.java +160 -0
- package/dist/runtime/java/RawResponse.java +48 -0
- package/dist/runtime/java/Realtime.java +152 -0
- package/dist/runtime/java/RealtimeLoop.java +371 -0
- package/dist/runtime/java/RedirectPolicy.java +13 -0
- package/dist/runtime/java/Redirects.java +126 -0
- package/dist/runtime/java/RequestContext.java +78 -0
- package/dist/runtime/java/RequestHook.java +9 -0
- package/dist/runtime/java/RequestOptions.java +91 -0
- package/dist/runtime/java/ResponseContext.java +70 -0
- package/dist/runtime/java/ResponseHook.java +12 -0
- package/dist/runtime/java/Result.java +32 -0
- package/dist/runtime/java/ResumableConnection.java +165 -0
- package/dist/runtime/java/SdkException.java +11 -0
- package/dist/runtime/java/Socket.java +301 -0
- package/dist/runtime/java/Sse.java +171 -0
- package/dist/runtime/java/SseAdapter.java +61 -0
- package/dist/runtime/java/SseEvent.java +10 -0
- package/dist/runtime/java/StaleMeta.java +16 -0
- package/dist/runtime/java/StaleTracker.java +287 -0
- package/dist/runtime/java/Transport.java +16 -0
- package/dist/runtime/java/TransportAdapter.java +14 -0
- package/dist/runtime/java/TransportConnection.java +15 -0
- package/dist/runtime/java/TransportKind.java +12 -0
- package/dist/runtime/java/TransportMessage.java +9 -0
- package/dist/runtime/java/TransportOptions.java +138 -0
- package/dist/runtime/java/TypedWebSocket.java +83 -0
- package/dist/runtime/java/UrlPath.java +49 -0
- package/dist/runtime/java/UrlQuery.java +99 -0
- package/dist/runtime/java/WsAdapter.java +52 -0
- package/dist/runtime/java/WsClose.java +47 -0
- package/dist/runtime/java/WsDial.java +148 -0
- package/dist/runtime/java/WsMessage.java +18 -0
- package/dist/runtime/mcp/call.ts +167 -0
- package/dist/runtime/mcp/files.ts +183 -0
- package/dist/runtime/mcp/guard.ts +176 -0
- package/dist/runtime/mcp/http.ts +159 -0
- package/dist/runtime/mcp/jsonrpc.ts +50 -0
- package/dist/runtime/mcp/listen.ts +76 -0
- package/dist/runtime/mcp/mount.ts +123 -0
- package/dist/runtime/mcp/protocol.ts +219 -0
- package/dist/runtime/mcp/reader.ts +57 -0
- package/dist/runtime/mcp/result.ts +85 -0
- package/dist/runtime/mcp/stdio.ts +79 -0
- package/dist/runtime/mcp/stream.ts +62 -0
- package/dist/runtime/python/__init__.py +2 -0
- package/dist/runtime/python/auth.py +67 -0
- package/dist/runtime/python/body.py +83 -0
- package/dist/runtime/python/config.py +139 -0
- package/dist/runtime/python/errors.py +213 -0
- package/dist/runtime/python/events.py +152 -0
- package/dist/runtime/python/exchange.py +298 -0
- package/dist/runtime/python/hooks.py +86 -0
- package/dist/runtime/python/invalidation.py +57 -0
- package/dist/runtime/python/log.py +60 -0
- package/dist/runtime/python/operation.py +25 -0
- package/dist/runtime/python/path.py +41 -0
- package/dist/runtime/python/query.py +48 -0
- package/dist/runtime/python/realtime.py +244 -0
- package/dist/runtime/python/redirect.py +93 -0
- package/dist/runtime/python/result.py +58 -0
- package/dist/runtime/python/send_async.py +189 -0
- package/dist/runtime/python/send_sync.py +105 -0
- package/dist/runtime/python/sse.py +81 -0
- package/dist/runtime/python/stale.py +94 -0
- package/dist/runtime/python/transport.py +157 -0
- package/dist/runtime/python/transport_longpoll.py +60 -0
- package/dist/runtime/python/transport_sse.py +60 -0
- package/dist/runtime/python/transport_ws.py +57 -0
- package/dist/runtime/python/ws.py +276 -0
- package/dist/runtime/rust/Cargo.lock +1763 -0
- package/dist/runtime/rust/answer.rs +120 -0
- package/dist/runtime/rust/auth.rs +80 -0
- package/dist/runtime/rust/body.rs +150 -0
- package/dist/runtime/rust/call.rs +200 -0
- package/dist/runtime/rust/config.rs +254 -0
- package/dist/runtime/rust/envelope.rs +84 -0
- package/dist/runtime/rust/errors.rs +235 -0
- package/dist/runtime/rust/events.rs +177 -0
- package/dist/runtime/rust/exchange.rs +287 -0
- package/dist/runtime/rust/hooks.rs +63 -0
- package/dist/runtime/rust/invalidation.rs +84 -0
- package/dist/runtime/rust/log.rs +88 -0
- package/dist/runtime/rust/nullable.rs +13 -0
- package/dist/runtime/rust/path.rs +83 -0
- package/dist/runtime/rust/query.rs +84 -0
- package/dist/runtime/rust/realtime.rs +182 -0
- package/dist/runtime/rust/realtime_loop.rs +177 -0
- package/dist/runtime/rust/redirect.rs +121 -0
- package/dist/runtime/rust/request.rs +178 -0
- package/dist/runtime/rust/result.rs +101 -0
- package/dist/runtime/rust/sse.rs +104 -0
- package/dist/runtime/rust/stale.rs +209 -0
- package/dist/runtime/rust/transport.rs +221 -0
- package/dist/runtime/rust/transport_longpoll.rs +108 -0
- package/dist/runtime/rust/transport_sse.rs +91 -0
- package/dist/runtime/rust/transport_ws.rs +75 -0
- package/dist/runtime/rust/ws.rs +322 -0
- package/dist/runtime/ts/app-types.ts +200 -0
- package/dist/runtime/ts/app.ts +104 -0
- package/dist/runtime/ts/config.ts +124 -0
- package/dist/runtime/ts/defaults.ts +48 -0
- package/dist/runtime/ts/error.ts +113 -0
- package/dist/runtime/ts/hooks.ts +92 -0
- package/dist/runtime/ts/http.ts +228 -0
- package/dist/runtime/ts/media-type.ts +36 -0
- package/dist/runtime/ts/path.ts +152 -0
- package/dist/runtime/ts/realtime-connection.ts +296 -0
- package/dist/runtime/ts/realtime-transports.ts +149 -0
- package/dist/runtime/ts/realtime.ts +293 -0
- package/dist/runtime/ts/redirect-policy.ts +17 -0
- package/dist/runtime/ts/redirects.ts +74 -0
- package/dist/runtime/ts/request.ts +239 -0
- package/dist/runtime/ts/response.ts +219 -0
- package/dist/runtime/ts/sdk-realtime.ts +10 -0
- package/dist/runtime/ts/sdk-sse.ts +55 -0
- package/dist/runtime/ts/sdk-ws.ts +21 -0
- package/dist/runtime/ts/sdk.ts +242 -0
- package/dist/runtime/ts/sse.ts +175 -0
- package/dist/runtime/ts/stale.ts +137 -0
- package/dist/runtime/ts/stream.ts +87 -0
- package/dist/runtime/ts/webhook.ts +116 -0
- package/dist/runtime/ts/ws.ts +155 -0
- package/dist/runtime/ts-tanstack-query/invalidate.ts +152 -0
- package/dist/runtime/ts-tanstack-query/query.ts +261 -0
- package/package.json +135 -5
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""The credential: the header that carries it, and the token, refreshed once for concurrent 401s.
|
|
3
|
+
``SDK`` takes a plain ``on_auth_expired`` (never a coroutine run on a thread of its own)."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import inspect
|
|
7
|
+
import threading
|
|
8
|
+
from collections.abc import Awaitable, Callable
|
|
9
|
+
|
|
10
|
+
from .config import ClientConfig, Defaults
|
|
11
|
+
from .errors import ConfigError
|
|
12
|
+
from .hooks import wrapped
|
|
13
|
+
|
|
14
|
+
RefreshHook = Callable[[], Awaitable[str | None] | str | None]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def scheme(config: ClientConfig, defaults: Defaults) -> tuple[str, str]:
|
|
18
|
+
if config.auth_header_name is not None:
|
|
19
|
+
return config.auth_header_name, config.auth_header_prefix or ""
|
|
20
|
+
prefix = config.auth_header_prefix
|
|
21
|
+
return defaults.auth_header, defaults.auth_prefix if prefix is None else prefix
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class AuthState:
|
|
25
|
+
def __init__(self, token: str | None) -> None:
|
|
26
|
+
self.token = token or None
|
|
27
|
+
self.lock = threading.Lock()
|
|
28
|
+
self.alock = asyncio.Lock()
|
|
29
|
+
|
|
30
|
+
def keep(self, fresh: object) -> str | None:
|
|
31
|
+
if isinstance(fresh, str) and fresh:
|
|
32
|
+
self.token = fresh
|
|
33
|
+
return fresh
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def refresh_sync(
|
|
38
|
+
state: AuthState, hook: RefreshHook, rejected: str | None
|
|
39
|
+
) -> str | None:
|
|
40
|
+
with state.lock:
|
|
41
|
+
if state.token != rejected:
|
|
42
|
+
return state.token
|
|
43
|
+
try:
|
|
44
|
+
fresh = hook()
|
|
45
|
+
except Exception as error:
|
|
46
|
+
raise wrapped(error, "on_auth_expired") from error
|
|
47
|
+
if inspect.iscoroutine(fresh):
|
|
48
|
+
fresh.close()
|
|
49
|
+
raise ConfigError(
|
|
50
|
+
"SDK takes a plain on_auth_expired; AsyncSDK takes a coroutine one"
|
|
51
|
+
)
|
|
52
|
+
return state.keep(fresh)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
async def refresh_async(
|
|
56
|
+
state: AuthState, hook: RefreshHook, rejected: str | None
|
|
57
|
+
) -> str | None:
|
|
58
|
+
async with state.alock:
|
|
59
|
+
if state.token != rejected:
|
|
60
|
+
return state.token
|
|
61
|
+
try:
|
|
62
|
+
fresh = hook()
|
|
63
|
+
if inspect.isawaitable(fresh):
|
|
64
|
+
fresh = await fresh
|
|
65
|
+
except Exception as error:
|
|
66
|
+
raise wrapped(error, "on_auth_expired") from error
|
|
67
|
+
return state.keep(fresh)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""A request body by its declared kind. Only bytes are sent twice: an iterable body is never retried."""
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import uuid
|
|
6
|
+
from collections.abc import AsyncIterable, Iterable, Mapping
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
|
|
9
|
+
from .operation import Operation
|
|
10
|
+
from .query import encode, pairs, text
|
|
11
|
+
|
|
12
|
+
__all__ = ["FilePart"]
|
|
13
|
+
|
|
14
|
+
BodyPayload = bytes | Iterable[bytes] | AsyncIterable[bytes]
|
|
15
|
+
|
|
16
|
+
MEDIA = {
|
|
17
|
+
"binary": "application/octet-stream",
|
|
18
|
+
"form": "application/x-www-form-urlencoded",
|
|
19
|
+
"json": "application/json",
|
|
20
|
+
"text": "text/plain; charset=utf-8",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True)
|
|
25
|
+
class FilePart:
|
|
26
|
+
"""One multipart file, in memory, so a retry or a redirect can send it again."""
|
|
27
|
+
|
|
28
|
+
filename: str
|
|
29
|
+
data: bytes
|
|
30
|
+
content_type: str = "application/octet-stream"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True)
|
|
34
|
+
class BodyContent:
|
|
35
|
+
payload: BodyPayload
|
|
36
|
+
media: str
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def part(name: str, value: object) -> bytes:
|
|
40
|
+
|
|
41
|
+
def quoted(raw: str) -> str:
|
|
42
|
+
return raw.replace("\r", "%0D").replace("\n", "%0A").replace('"', "%22")
|
|
43
|
+
|
|
44
|
+
head = f'Content-Disposition: form-data; name="{quoted(name)}"'
|
|
45
|
+
if not isinstance(value, FilePart):
|
|
46
|
+
return f"{head}\r\n\r\n{text(value)}".encode()
|
|
47
|
+
media = quoted(value.content_type)
|
|
48
|
+
return (
|
|
49
|
+
f'{head}; filename="{quoted(value.filename)}"\r\nContent-Type: {media}\r\n\r\n'.encode()
|
|
50
|
+
+ value.data
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def dumps(value: object) -> str:
|
|
55
|
+
return json.dumps(value, separators=(",", ":"), ensure_ascii=False)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def encode_body(op: Operation[object], body: object) -> BodyContent | None:
|
|
59
|
+
if body is None or op.body is None:
|
|
60
|
+
return None
|
|
61
|
+
fields = body if isinstance(body, Mapping) else {}
|
|
62
|
+
if op.body == "multipart":
|
|
63
|
+
mark = uuid.uuid4().hex
|
|
64
|
+
parts = [
|
|
65
|
+
b"--%s\r\n%s\r\n" % (mark.encode(), part(name, item))
|
|
66
|
+
for name, value in fields.items()
|
|
67
|
+
for item in (value if isinstance(value, list) else [value])
|
|
68
|
+
if item is not None and item != {}
|
|
69
|
+
]
|
|
70
|
+
return BodyContent(
|
|
71
|
+
b"".join(parts) + f"--{mark}--\r\n".encode(),
|
|
72
|
+
f"multipart/form-data; boundary={mark}",
|
|
73
|
+
)
|
|
74
|
+
media = op.content_type or MEDIA[op.body]
|
|
75
|
+
if op.body == "json":
|
|
76
|
+
return BodyContent(dumps(body).encode(), media)
|
|
77
|
+
if op.body == "form":
|
|
78
|
+
return BodyContent(encode(pairs(fields)).encode(), media)
|
|
79
|
+
if op.body == "text":
|
|
80
|
+
return BodyContent(str(body).encode(), media)
|
|
81
|
+
if isinstance(body, (bytes, Iterable, AsyncIterable)):
|
|
82
|
+
return BodyContent(body, media)
|
|
83
|
+
raise TypeError("a binary body is bytes, or an iterable of bytes")
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""A client's settings, and one call's overrides."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import asyncio
|
|
7
|
+
import threading
|
|
8
|
+
from collections.abc import Awaitable, Callable, Mapping, Sequence
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
from typing import TYPE_CHECKING, Any, Literal, TypedDict
|
|
11
|
+
from urllib.parse import urlsplit, urlunsplit
|
|
12
|
+
|
|
13
|
+
import httpx2
|
|
14
|
+
|
|
15
|
+
from .errors import ConfigError
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from .hooks import RequestContext, ResponseContext
|
|
19
|
+
from .log import LogEntry
|
|
20
|
+
|
|
21
|
+
__all__ = ["ClientConfig", "InvalidationConfig", "RawResponse", "RequestOptions"]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True)
|
|
25
|
+
class InvalidationConfig:
|
|
26
|
+
"""Stale tracking: a call's targets stay stale ``stale_time`` seconds after it succeeds (0: off)."""
|
|
27
|
+
|
|
28
|
+
stale_time: float = 0.0
|
|
29
|
+
stale_max_entries: int = 1000
|
|
30
|
+
max_sources_per_target: int = 16
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True, repr=False)
|
|
34
|
+
class ClientConfig:
|
|
35
|
+
"""A client's settings.
|
|
36
|
+
|
|
37
|
+
``base_url`` defaults to the API's first server. ``bearer_token`` (else ``api_key``) is sent as
|
|
38
|
+
``auth_header_name: auth_header_prefix + token``; unset, both follow the API's scheme, and a set
|
|
39
|
+
name takes no prefix unless one is given. ``timeout`` (seconds; ``None`` or 0: none) bounds a
|
|
40
|
+
whole call, and a stream only up to its headers. ``ws_keepalive`` (seconds; ``None`` or 0: none) is a
|
|
41
|
+
WebSocket's ping interval and pong wait. A redirect to another origin is followed only under ``"follow"``, and
|
|
42
|
+
never carries credentials, a body, or what an ``http_client`` adds. ``SDK`` runs the ``*_sync``
|
|
43
|
+
hooks and a plain ``on_auth_expired``; ``AsyncSDK`` runs the others, and coroutine functions too.
|
|
44
|
+
Either refuses, at construction, a hook it would not run.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
base_url: str = ""
|
|
48
|
+
bearer_token: str | None = field(default=None, repr=False)
|
|
49
|
+
api_key: str | None = field(default=None, repr=False)
|
|
50
|
+
auth_header_name: str | None = None
|
|
51
|
+
auth_header_prefix: str | None = None
|
|
52
|
+
headers: Mapping[str, str] = field(default_factory=dict)
|
|
53
|
+
timeout: float | None = 30.0
|
|
54
|
+
max_response_bytes: int = 100 << 20
|
|
55
|
+
ws_keepalive: float | None = 20.0
|
|
56
|
+
redirect: Literal["same-origin", "follow", "manual"] = "same-origin"
|
|
57
|
+
http_client: httpx2.Client | None = None
|
|
58
|
+
async_http_client: httpx2.AsyncClient | None = None
|
|
59
|
+
on_request: Sequence[Callable[[RequestContext], Awaitable[None] | None]] = ()
|
|
60
|
+
on_response: Sequence[Callable[[ResponseContext], Awaitable[None] | None]] = ()
|
|
61
|
+
on_request_sync: Sequence[Callable[[RequestContext], None]] = ()
|
|
62
|
+
on_response_sync: Sequence[Callable[[ResponseContext], None]] = ()
|
|
63
|
+
on_log: Callable[[LogEntry], None] | None = None
|
|
64
|
+
on_auth_expired: Callable[[], Awaitable[str | None] | str | None] | None = None
|
|
65
|
+
invalidation: InvalidationConfig | None = None
|
|
66
|
+
state: dict[str, Any] | None = None
|
|
67
|
+
|
|
68
|
+
def __repr__(self) -> str:
|
|
69
|
+
secrets = {"bearer_token": self.bearer_token, "api_key": self.api_key}
|
|
70
|
+
shown = {
|
|
71
|
+
"base_url": redacted(self.base_url),
|
|
72
|
+
**{name: "set" for name, value in secrets.items() if value is not None},
|
|
73
|
+
"header_names": sorted(self.headers),
|
|
74
|
+
"timeout": self.timeout,
|
|
75
|
+
"redirect": self.redirect,
|
|
76
|
+
}
|
|
77
|
+
return f"ClientConfig({', '.join(f'{k}={v!r}' for k, v in shown.items())})"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class RequestOptions(TypedDict, total=False):
|
|
81
|
+
"""One call's overrides; ``raw`` is filled with the answer as it arrived."""
|
|
82
|
+
|
|
83
|
+
timeout: float | None
|
|
84
|
+
headers: Mapping[str, str]
|
|
85
|
+
base_url: str
|
|
86
|
+
cancel: threading.Event | asyncio.Event
|
|
87
|
+
raw: RawResponse
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class RawResponse:
|
|
91
|
+
"""The answer as it arrived, on success and on error."""
|
|
92
|
+
|
|
93
|
+
def __init__(self) -> None:
|
|
94
|
+
self.status = 0
|
|
95
|
+
self.headers: Mapping[str, str] = {}
|
|
96
|
+
self.body = b""
|
|
97
|
+
self.url = ""
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@dataclass(frozen=True)
|
|
101
|
+
class Defaults:
|
|
102
|
+
base_url: str | None
|
|
103
|
+
auth_header: str = "Authorization"
|
|
104
|
+
auth_prefix: str = "Bearer "
|
|
105
|
+
keys: Callable[[str], str] | None = None
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def redacted(url: str) -> str:
|
|
109
|
+
try:
|
|
110
|
+
parts = urlsplit(url)
|
|
111
|
+
port = f":{parts.port}" if parts.port else ""
|
|
112
|
+
except ValueError:
|
|
113
|
+
return "(not a URL)"
|
|
114
|
+
return urlunsplit((parts.scheme, (parts.hostname or "") + port, parts.path, "", ""))
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def parse_base(url: str, what: str) -> str:
|
|
118
|
+
try:
|
|
119
|
+
parts = urlsplit(url)
|
|
120
|
+
absolute = parts.scheme in ("http", "https") and bool(parts.hostname)
|
|
121
|
+
except ValueError:
|
|
122
|
+
absolute = False
|
|
123
|
+
if not absolute:
|
|
124
|
+
raise ConfigError(f"{what} is not an absolute http(s) URL")
|
|
125
|
+
return url
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def base_of(config: ClientConfig, defaults: Defaults) -> str:
|
|
129
|
+
if config.base_url:
|
|
130
|
+
return parse_base(config.base_url, "base_url")
|
|
131
|
+
unset = "base_url is empty, and the API"
|
|
132
|
+
if defaults.base_url is None:
|
|
133
|
+
raise ConfigError(f"{unset} declares no server: set ClientConfig.base_url")
|
|
134
|
+
try:
|
|
135
|
+
return parse_base(defaults.base_url, "")
|
|
136
|
+
except ConfigError:
|
|
137
|
+
raise ConfigError(
|
|
138
|
+
f"{unset}'s first server is relative: set ClientConfig.base_url"
|
|
139
|
+
) from None
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""Every error the SDK raises."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import contextlib
|
|
7
|
+
import json
|
|
8
|
+
import unicodedata
|
|
9
|
+
from collections.abc import Callable, Mapping
|
|
10
|
+
from typing import TypedDict, TypeVar, cast
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"APIConnectionError",
|
|
14
|
+
"APIStatusError",
|
|
15
|
+
"APITimeoutError",
|
|
16
|
+
"BadGatewayError",
|
|
17
|
+
"BadRequestError",
|
|
18
|
+
"CanceledError",
|
|
19
|
+
"ConfigError",
|
|
20
|
+
"ConflictError",
|
|
21
|
+
"DecodeError",
|
|
22
|
+
"ErrorEnvelope",
|
|
23
|
+
"FieldError",
|
|
24
|
+
"ForbiddenError",
|
|
25
|
+
"GatewayTimeoutError",
|
|
26
|
+
"HoneyError",
|
|
27
|
+
"HookError",
|
|
28
|
+
"InternalServerError",
|
|
29
|
+
"NotFoundError",
|
|
30
|
+
"PathParamError",
|
|
31
|
+
"RateLimitError",
|
|
32
|
+
"ServiceUnavailableError",
|
|
33
|
+
"UnauthorizedError",
|
|
34
|
+
"UnprocessableEntityError",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class HoneyError(Exception):
|
|
39
|
+
"""The base of every error the SDK raises."""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ConfigError(HoneyError):
|
|
43
|
+
"""A client or call that cannot be built: no usable base URL, or a header value no request carries."""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class PathParamError(HoneyError):
|
|
47
|
+
"""A path parameter that is missing, or empty, ``.`` or ``..``: nothing is sent."""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class APIConnectionError(HoneyError):
|
|
51
|
+
"""No answer: the connection failed, or the answer was cut off or too large."""
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class APITimeoutError(APIConnectionError):
|
|
55
|
+
"""The call ran past its timeout."""
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class CanceledError(HoneyError):
|
|
59
|
+
"""The call's ``cancel`` event fired."""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class DecodeError(HoneyError):
|
|
63
|
+
"""A success answer whose body is not what the operation declares."""
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class HookError(HoneyError):
|
|
67
|
+
"""A hook raised; its error is the cause."""
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
T = TypeVar("T")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class FieldError(TypedDict, total=False):
|
|
74
|
+
"""One field's error in an envelope's ``fields``."""
|
|
75
|
+
|
|
76
|
+
error_key: str
|
|
77
|
+
message: str
|
|
78
|
+
path: str
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class ErrorEnvelope(TypedDict, total=False):
|
|
82
|
+
"""honey's error envelope: a view of the body's JSON object (empty for any other body), each member
|
|
83
|
+
as the server sent it; ``json.loads(e.body)`` holds the members it does not name."""
|
|
84
|
+
|
|
85
|
+
status: int
|
|
86
|
+
error_key: str
|
|
87
|
+
status_key: str
|
|
88
|
+
message: str
|
|
89
|
+
fields: dict[str, list[FieldError]]
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def loads(body: bytes) -> object:
|
|
93
|
+
try:
|
|
94
|
+
return json.loads(body)
|
|
95
|
+
except RecursionError:
|
|
96
|
+
raise ValueError("the JSON is nested too deep") from None
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def sanitized(text: str) -> str:
|
|
100
|
+
kept = "".join(
|
|
101
|
+
ch for ch in text if ch != "\ufffd" and unicodedata.category(ch)[0] != "C"
|
|
102
|
+
)
|
|
103
|
+
return kept if len(kept) <= 512 else kept[:512] + "\u2026"
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class APIStatusError(HoneyError):
|
|
107
|
+
"""An error status: its status, headers, body, envelope and message, and the error key the body
|
|
108
|
+
names (an ``ErrorKey`` member when the API declares it). ``str()`` is ``HTTP <status>: <message>``."""
|
|
109
|
+
|
|
110
|
+
def __init__(
|
|
111
|
+
self,
|
|
112
|
+
status: int,
|
|
113
|
+
headers: Mapping[str, str],
|
|
114
|
+
body: bytes,
|
|
115
|
+
key: str | None = None,
|
|
116
|
+
envelope: ErrorEnvelope | None = None,
|
|
117
|
+
message: str = "",
|
|
118
|
+
) -> None:
|
|
119
|
+
super().__init__(f"HTTP {status}: {message}" if message else f"HTTP {status}")
|
|
120
|
+
self.status, self.headers, self.body, self.key = status, headers, body, key
|
|
121
|
+
self.envelope = envelope or ErrorEnvelope()
|
|
122
|
+
self.message = message
|
|
123
|
+
|
|
124
|
+
def decode_body(self, kind: type[T]) -> T:
|
|
125
|
+
"""The body's JSON as ``kind`` (a cast: nothing is checked); ``DecodeError`` when it is none."""
|
|
126
|
+
try:
|
|
127
|
+
return cast("T", loads(self.body))
|
|
128
|
+
except ValueError:
|
|
129
|
+
raise DecodeError(f"HTTP {self.status}: the body is not JSON") from None
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class BadRequestError(APIStatusError):
|
|
133
|
+
"""HTTP 400."""
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class UnauthorizedError(APIStatusError):
|
|
137
|
+
"""HTTP 401."""
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class ForbiddenError(APIStatusError):
|
|
141
|
+
"""HTTP 403."""
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class NotFoundError(APIStatusError):
|
|
145
|
+
"""HTTP 404."""
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class ConflictError(APIStatusError):
|
|
149
|
+
"""HTTP 409."""
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class UnprocessableEntityError(APIStatusError):
|
|
153
|
+
"""HTTP 422."""
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class RateLimitError(APIStatusError):
|
|
157
|
+
"""HTTP 429."""
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class InternalServerError(APIStatusError):
|
|
161
|
+
"""HTTP 500."""
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
class BadGatewayError(APIStatusError):
|
|
165
|
+
"""HTTP 502."""
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class ServiceUnavailableError(APIStatusError):
|
|
169
|
+
"""HTTP 503."""
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class GatewayTimeoutError(APIStatusError):
|
|
173
|
+
"""HTTP 504."""
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
STATUS_ERRORS: Mapping[int, type[APIStatusError]] = {
|
|
177
|
+
400: BadRequestError,
|
|
178
|
+
401: UnauthorizedError,
|
|
179
|
+
403: ForbiddenError,
|
|
180
|
+
404: NotFoundError,
|
|
181
|
+
409: ConflictError,
|
|
182
|
+
422: UnprocessableEntityError,
|
|
183
|
+
429: RateLimitError,
|
|
184
|
+
500: InternalServerError,
|
|
185
|
+
502: BadGatewayError,
|
|
186
|
+
503: ServiceUnavailableError,
|
|
187
|
+
504: GatewayTimeoutError,
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def status_error(
|
|
192
|
+
status: int,
|
|
193
|
+
headers: Mapping[str, str],
|
|
194
|
+
body: bytes,
|
|
195
|
+
keys: Callable[[str], str] | None = None,
|
|
196
|
+
) -> APIStatusError:
|
|
197
|
+
try:
|
|
198
|
+
parsed = loads(body)
|
|
199
|
+
except ValueError:
|
|
200
|
+
parsed = None
|
|
201
|
+
envelope = cast("ErrorEnvelope", parsed if isinstance(parsed, dict) else {})
|
|
202
|
+
text = envelope.get("message")
|
|
203
|
+
message = sanitized(
|
|
204
|
+
text if isinstance(text, str) else body.decode("utf-8", "replace")
|
|
205
|
+
)
|
|
206
|
+
key = envelope.get("error_key")
|
|
207
|
+
if not isinstance(key, str):
|
|
208
|
+
key = None
|
|
209
|
+
elif keys is not None:
|
|
210
|
+
with contextlib.suppress(ValueError):
|
|
211
|
+
key = keys(key)
|
|
212
|
+
error = STATUS_ERRORS.get(status, APIStatusError)
|
|
213
|
+
return error(status, headers, body, key, envelope, message)
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""An SSE operation's answer: the open stream's events, each one's data decoded. No timeout bounds it.
|
|
3
|
+
An event that does not decode, a cap or a failed read is raised once and ends it; the call's ``cancel``,
|
|
4
|
+
``aclose`` and a cancelled read end it, the cancelled read raising ``CancelledError``. Open it with
|
|
5
|
+
``async with`` or call ``aclose()`` to free its connection; a dropped stream frees it only when collected."""
|
|
6
|
+
|
|
7
|
+
import asyncio
|
|
8
|
+
import contextlib
|
|
9
|
+
import threading
|
|
10
|
+
import weakref
|
|
11
|
+
from collections import deque
|
|
12
|
+
from collections.abc import AsyncGenerator, Awaitable
|
|
13
|
+
from dataclasses import dataclass
|
|
14
|
+
from typing import Generic, Self, TypeVar, cast
|
|
15
|
+
|
|
16
|
+
import httpx2
|
|
17
|
+
|
|
18
|
+
from .errors import APIConnectionError, CanceledError, DecodeError, HoneyError, loads
|
|
19
|
+
from .exchange import shaped
|
|
20
|
+
from .sse import RawEvent, SseParser
|
|
21
|
+
|
|
22
|
+
__all__ = ["EventStream", "SseEvent"]
|
|
23
|
+
|
|
24
|
+
T = TypeVar("T")
|
|
25
|
+
R = TypeVar("R")
|
|
26
|
+
|
|
27
|
+
Cancel = threading.Event | asyncio.Event | None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
async def raced(work: Awaitable[R], cancel: Cancel) -> R:
|
|
31
|
+
if not isinstance(cancel, asyncio.Event):
|
|
32
|
+
return await work
|
|
33
|
+
task = asyncio.ensure_future(work)
|
|
34
|
+
waiter = asyncio.ensure_future(cancel.wait())
|
|
35
|
+
try:
|
|
36
|
+
await asyncio.wait((task, waiter), return_when=asyncio.FIRST_COMPLETED)
|
|
37
|
+
if task.done():
|
|
38
|
+
return task.result()
|
|
39
|
+
raise CanceledError("the call was canceled")
|
|
40
|
+
finally:
|
|
41
|
+
waiter.cancel()
|
|
42
|
+
if not task.done():
|
|
43
|
+
task.cancel()
|
|
44
|
+
await asyncio.wait((task,))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
async def released(chunks: AsyncGenerator[bytes], response: httpx2.Response) -> None:
|
|
48
|
+
await chunks.aclose()
|
|
49
|
+
await response.aclose()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def dropped(chunks: AsyncGenerator[bytes], response: httpx2.Response) -> None:
|
|
53
|
+
with contextlib.suppress(RuntimeError):
|
|
54
|
+
_ = asyncio.get_running_loop().create_task(released(chunks, response))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True)
|
|
58
|
+
class SseEvent(Generic[T]):
|
|
59
|
+
"""One event: its decoded data, its type, the stream's last event id, and its ``retry``."""
|
|
60
|
+
|
|
61
|
+
data: T
|
|
62
|
+
event: str | None = None
|
|
63
|
+
id: str | None = None
|
|
64
|
+
retry: int | None = None
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class EventStream(Generic[T]):
|
|
68
|
+
"""An open stream's events, in order (``async for``); ``aclose`` lets the connection go."""
|
|
69
|
+
|
|
70
|
+
def __init__(
|
|
71
|
+
self,
|
|
72
|
+
response: httpx2.Response,
|
|
73
|
+
*,
|
|
74
|
+
decode: bool,
|
|
75
|
+
shape: str | None = None,
|
|
76
|
+
cancel: Cancel = None,
|
|
77
|
+
) -> None:
|
|
78
|
+
self.response = response
|
|
79
|
+
self.decode, self.shape = decode, shape
|
|
80
|
+
self.cancel = cancel
|
|
81
|
+
self.chunks = response.aiter_bytes()
|
|
82
|
+
weakref.finalize(self, dropped, self.chunks, response)
|
|
83
|
+
self.parser = SseParser()
|
|
84
|
+
self.pending: deque[RawEvent] = deque()
|
|
85
|
+
self.failure: HoneyError | None = None
|
|
86
|
+
self.ended = False
|
|
87
|
+
self.delivered = ""
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def last_event_id(self) -> str:
|
|
91
|
+
"""The id of the last event delivered, to resume from: a resume from it skips nothing."""
|
|
92
|
+
return self.delivered
|
|
93
|
+
|
|
94
|
+
def __aiter__(self) -> Self:
|
|
95
|
+
return self
|
|
96
|
+
|
|
97
|
+
async def __anext__(self) -> SseEvent[T]:
|
|
98
|
+
while not self.pending and not self.ended:
|
|
99
|
+
await self.pull()
|
|
100
|
+
if not self.pending:
|
|
101
|
+
failure, self.failure = self.failure, None
|
|
102
|
+
if failure is None:
|
|
103
|
+
raise StopAsyncIteration
|
|
104
|
+
raise failure
|
|
105
|
+
raw = self.pending.popleft()
|
|
106
|
+
data: object = raw.data
|
|
107
|
+
if self.decode:
|
|
108
|
+
try:
|
|
109
|
+
data = loads(raw.data.encode())
|
|
110
|
+
fits = shaped(data, self.shape)
|
|
111
|
+
except ValueError:
|
|
112
|
+
fits = False
|
|
113
|
+
if not fits:
|
|
114
|
+
await self.aclose()
|
|
115
|
+
raise DecodeError(
|
|
116
|
+
f"an event's data is not a JSON {self.shape or 'value'}"
|
|
117
|
+
)
|
|
118
|
+
self.delivered = raw.id or ""
|
|
119
|
+
return SseEvent(cast("T", data), raw.event, raw.id, raw.retry)
|
|
120
|
+
|
|
121
|
+
async def pull(self) -> None:
|
|
122
|
+
try:
|
|
123
|
+
chunk = await raced(anext(self.chunks), self.cancel)
|
|
124
|
+
self.pending.extend(self.parser.feed(chunk))
|
|
125
|
+
except (StopAsyncIteration, CanceledError):
|
|
126
|
+
await self.end(None)
|
|
127
|
+
except DecodeError as error:
|
|
128
|
+
await self.end(error)
|
|
129
|
+
except httpx2.HTTPError as error:
|
|
130
|
+
await self.end(APIConnectionError("the event stream failed"), error)
|
|
131
|
+
except asyncio.CancelledError:
|
|
132
|
+
await self.end(None)
|
|
133
|
+
raise
|
|
134
|
+
|
|
135
|
+
async def end(
|
|
136
|
+
self, failure: HoneyError | None, cause: Exception | None = None
|
|
137
|
+
) -> None:
|
|
138
|
+
if not self.ended:
|
|
139
|
+
if failure is not None:
|
|
140
|
+
failure.__cause__ = cause
|
|
141
|
+
self.failure, self.ended = failure, True
|
|
142
|
+
await self.response.aclose()
|
|
143
|
+
|
|
144
|
+
async def aclose(self) -> None:
|
|
145
|
+
self.pending.clear()
|
|
146
|
+
await self.end(None)
|
|
147
|
+
|
|
148
|
+
async def __aenter__(self) -> Self:
|
|
149
|
+
return self
|
|
150
|
+
|
|
151
|
+
async def __aexit__(self, *exc: object) -> None:
|
|
152
|
+
await self.aclose()
|