@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,298 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""The sans-IO core every call shares, whichever client sends it: the URL, the header layers (the
|
|
3
|
+
credential last), the idempotency key and request id, each redirect, the retry after a 401, and the
|
|
4
|
+
answer's error class and decoding. The shells only move bytes."""
|
|
5
|
+
|
|
6
|
+
import re
|
|
7
|
+
import time
|
|
8
|
+
import uuid
|
|
9
|
+
from collections.abc import Iterable, Mapping
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from typing import Any, TypedDict
|
|
12
|
+
|
|
13
|
+
from .auth import AuthState, scheme
|
|
14
|
+
from .body import encode_body
|
|
15
|
+
from .config import (
|
|
16
|
+
ClientConfig,
|
|
17
|
+
Defaults,
|
|
18
|
+
RawResponse,
|
|
19
|
+
RequestOptions,
|
|
20
|
+
base_of,
|
|
21
|
+
parse_base,
|
|
22
|
+
)
|
|
23
|
+
from .errors import (
|
|
24
|
+
APIStatusError,
|
|
25
|
+
APITimeoutError,
|
|
26
|
+
CanceledError,
|
|
27
|
+
ConfigError,
|
|
28
|
+
DecodeError,
|
|
29
|
+
loads,
|
|
30
|
+
status_error,
|
|
31
|
+
)
|
|
32
|
+
from .hooks import RequestContext, ResponseContext
|
|
33
|
+
from .log import CallLog
|
|
34
|
+
from .operation import Operation
|
|
35
|
+
from .path import expand
|
|
36
|
+
from .query import encode, pairs, text
|
|
37
|
+
from .redirect import MAX_REDIRECTS, Hop, follow
|
|
38
|
+
from .stale import StaleTracker
|
|
39
|
+
|
|
40
|
+
SHAPES: Mapping[str, tuple[type, ...]] = {
|
|
41
|
+
"array": (list,),
|
|
42
|
+
"boolean": (bool,),
|
|
43
|
+
"number": (int, float),
|
|
44
|
+
"object": (dict,),
|
|
45
|
+
"string": (str,),
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# RFC 9110's token, all a header name may hold; and every control character but tab, which no value may hold
|
|
49
|
+
TOKEN = re.compile(r"[!#$%&'*+.^_`|~0-9A-Za-z-]+")
|
|
50
|
+
CONTROL = re.compile(r"[\x00-\x08\x0a-\x1f\x7f]")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class CallArgs(TypedDict, total=False):
|
|
54
|
+
path: tuple[str, ...]
|
|
55
|
+
query: Mapping[str, object] | None
|
|
56
|
+
headers: Mapping[str, object] | None
|
|
57
|
+
body: object
|
|
58
|
+
idempotency_key: str | None
|
|
59
|
+
headers_into: Mapping[str, object] | None
|
|
60
|
+
options: RequestOptions | None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@dataclass(frozen=True)
|
|
64
|
+
class HttpAnswer:
|
|
65
|
+
status: int
|
|
66
|
+
headers: Mapping[str, str]
|
|
67
|
+
body: bytes
|
|
68
|
+
url: str
|
|
69
|
+
over: bool = False
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class ClientCore:
|
|
73
|
+
def __init__(self, config: ClientConfig, defaults: Defaults) -> None:
|
|
74
|
+
self.config = config
|
|
75
|
+
self.base = base_of(config, defaults)
|
|
76
|
+
self.auth_header, self.auth_prefix = scheme(config, defaults)
|
|
77
|
+
self.auth = AuthState(config.bearer_token or config.api_key)
|
|
78
|
+
self.stale = StaleTracker(config.invalidation)
|
|
79
|
+
self.state: dict[str, Any] = {} if config.state is None else config.state
|
|
80
|
+
self.keys = defaults.keys
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class Exchange:
|
|
84
|
+
def __init__(
|
|
85
|
+
self,
|
|
86
|
+
core: ClientCore,
|
|
87
|
+
op: Operation[object],
|
|
88
|
+
args: CallArgs,
|
|
89
|
+
stream: bool = False,
|
|
90
|
+
refreshes: bool = True,
|
|
91
|
+
) -> None:
|
|
92
|
+
self.core, self.op, self.args, self.stream = core, op, args, stream
|
|
93
|
+
self.refreshes = refreshes
|
|
94
|
+
options: RequestOptions = args.get("options") or {}
|
|
95
|
+
self.options = options
|
|
96
|
+
self.params = dict(zip(op.path_params, args.get("path", ()), strict=True))
|
|
97
|
+
self.path = expand(op.path, self.params)
|
|
98
|
+
self.content = encode_body(op, args.get("body"))
|
|
99
|
+
self.base = (
|
|
100
|
+
parse_base(options["base_url"], "the call's base_url")
|
|
101
|
+
if "base_url" in options
|
|
102
|
+
else core.base
|
|
103
|
+
)
|
|
104
|
+
self.log = CallLog(core.config.on_log, f"{op.method} {op.path}")
|
|
105
|
+
self.meta = core.stale.begin(op.method, self.path)
|
|
106
|
+
self.timeout = options.get("timeout", core.config.timeout) or None
|
|
107
|
+
self.deadline = (
|
|
108
|
+
None if stream or not self.timeout else time.monotonic() + self.timeout
|
|
109
|
+
)
|
|
110
|
+
key = args.get("idempotency_key") or str(uuid.uuid4())
|
|
111
|
+
self.idempotency = key if op.idempotent and not op.stream else None
|
|
112
|
+
self.hops = 0
|
|
113
|
+
self.raw = options.get("raw") or RawResponse()
|
|
114
|
+
self.failure: APIStatusError | None = None
|
|
115
|
+
|
|
116
|
+
def check(self) -> float | None:
|
|
117
|
+
cancel = self.options.get("cancel")
|
|
118
|
+
if cancel is not None and cancel.is_set():
|
|
119
|
+
raise CanceledError("the call was canceled")
|
|
120
|
+
left = None if self.deadline is None else self.deadline - time.monotonic()
|
|
121
|
+
if left is not None and left <= 0:
|
|
122
|
+
raise APITimeoutError("the call ran past its timeout")
|
|
123
|
+
return left
|
|
124
|
+
|
|
125
|
+
def url(self) -> str:
|
|
126
|
+
base, _, query = self.base.partition("#")[0].partition("?")
|
|
127
|
+
own = "&".join(q for q in (query, encode(pairs(self.args.get("query")))) if q)
|
|
128
|
+
return base.rstrip("/") + self.path + (f"?{own}" if own else "")
|
|
129
|
+
|
|
130
|
+
def request(self, token: str | None, is_retry: bool) -> RequestContext:
|
|
131
|
+
content, idempotency, call = (
|
|
132
|
+
self.content,
|
|
133
|
+
self.idempotency,
|
|
134
|
+
self.args.get("headers") or {},
|
|
135
|
+
)
|
|
136
|
+
layers: list[Mapping[str, object]] = [
|
|
137
|
+
{"X-Request-Id": str(uuid.uuid4())},
|
|
138
|
+
{"Content-Type": content.media} if content else {},
|
|
139
|
+
self.core.config.headers,
|
|
140
|
+
{"Accept": self.op.accept} if self.op.accept else {},
|
|
141
|
+
{"Idempotency-Key": idempotency} if idempotency else {},
|
|
142
|
+
{k: v for k, v in call.items() if v is not None and v != {}},
|
|
143
|
+
self.options.get("headers", {}),
|
|
144
|
+
{self.core.auth_header: self.core.auth_prefix + token} if token else {},
|
|
145
|
+
]
|
|
146
|
+
shown = [(k, text(v)) for layer in layers for k, v in layer.items()]
|
|
147
|
+
for name, value in shown:
|
|
148
|
+
if not TOKEN.fullmatch(name):
|
|
149
|
+
raise ConfigError(f"the {name} header cannot be sent")
|
|
150
|
+
if CONTROL.search(value):
|
|
151
|
+
raise ConfigError(f"the {name} header's value cannot be sent")
|
|
152
|
+
headers = folded(shown)
|
|
153
|
+
body = (
|
|
154
|
+
content.payload if content and isinstance(content.payload, bytes) else None
|
|
155
|
+
)
|
|
156
|
+
m = self.meta
|
|
157
|
+
return RequestContext(
|
|
158
|
+
self.op.method,
|
|
159
|
+
self.url(),
|
|
160
|
+
self.path,
|
|
161
|
+
headers,
|
|
162
|
+
body,
|
|
163
|
+
is_retry,
|
|
164
|
+
m.selector,
|
|
165
|
+
m.is_stale,
|
|
166
|
+
list(m.invalidated_by),
|
|
167
|
+
self.core.state,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
def hop(self, ctx: RequestContext) -> Hop:
|
|
171
|
+
streamed = (
|
|
172
|
+
None
|
|
173
|
+
if self.content is None or ctx.body is not None
|
|
174
|
+
else self.content.payload
|
|
175
|
+
)
|
|
176
|
+
return Hop(
|
|
177
|
+
ctx.method,
|
|
178
|
+
ctx.url,
|
|
179
|
+
folded(ctx.headers.items()),
|
|
180
|
+
ctx.body if streamed is None or isinstance(streamed, bytes) else streamed,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
def follow(self, hop: Hop, answer: HttpAnswer, start: str) -> Hop | None:
|
|
184
|
+
if self.hops == MAX_REDIRECTS:
|
|
185
|
+
return None
|
|
186
|
+
nxt = follow(
|
|
187
|
+
hop,
|
|
188
|
+
answer.status,
|
|
189
|
+
answer.headers.get("location"),
|
|
190
|
+
self.core.config.redirect,
|
|
191
|
+
start,
|
|
192
|
+
)
|
|
193
|
+
self.hops += nxt is not None
|
|
194
|
+
return nxt
|
|
195
|
+
|
|
196
|
+
def limit(self) -> int:
|
|
197
|
+
return 64 << 10 if self.stream else self.core.config.max_response_bytes
|
|
198
|
+
|
|
199
|
+
def read(self, chunks: list[bytes], chunk: bytes) -> bool:
|
|
200
|
+
chunks.append(chunk)
|
|
201
|
+
return 0 < self.limit() < sum(map(len, chunks))
|
|
202
|
+
|
|
203
|
+
def response(self, answer: HttpAnswer, is_retry: bool) -> ResponseContext:
|
|
204
|
+
m = self.meta
|
|
205
|
+
return ResponseContext(
|
|
206
|
+
answer.status,
|
|
207
|
+
answer.headers,
|
|
208
|
+
answer.body,
|
|
209
|
+
is_retry,
|
|
210
|
+
m.selector,
|
|
211
|
+
m.is_stale,
|
|
212
|
+
list(m.invalidated_by),
|
|
213
|
+
self.core.state,
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
def retries(self, answer: HttpAnswer) -> bool:
|
|
217
|
+
replayable = self.content is None or isinstance(self.content.payload, bytes)
|
|
218
|
+
return (
|
|
219
|
+
answer.status == 401
|
|
220
|
+
and self.refreshes
|
|
221
|
+
and self.core.config.on_auth_expired is not None
|
|
222
|
+
and replayable
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
def done(self, answer: HttpAnswer) -> HttpAnswer:
|
|
226
|
+
self.log.answered(answer.status)
|
|
227
|
+
if 200 <= answer.status < 300:
|
|
228
|
+
self.core.stale.settle(self.meta, self.op.invalidates, self.params)
|
|
229
|
+
else:
|
|
230
|
+
self.failure = failure(answer, self.core)
|
|
231
|
+
self.log.failed(self.failure)
|
|
232
|
+
raw = self.raw
|
|
233
|
+
raw.status, raw.headers, raw.body, raw.url = (
|
|
234
|
+
answer.status,
|
|
235
|
+
answer.headers,
|
|
236
|
+
answer.body,
|
|
237
|
+
answer.url,
|
|
238
|
+
)
|
|
239
|
+
return answer
|
|
240
|
+
|
|
241
|
+
def decoded(self, answer: HttpAnswer) -> object:
|
|
242
|
+
if self.failure is not None:
|
|
243
|
+
raise self.failure
|
|
244
|
+
if answer.over:
|
|
245
|
+
raise DecodeError(
|
|
246
|
+
f"HTTP {answer.status}: the body exceeds {self.limit()} bytes"
|
|
247
|
+
)
|
|
248
|
+
self.fill(answer)
|
|
249
|
+
if self.op.answer in ("none", "binary", "text"):
|
|
250
|
+
return {"none": None, "binary": answer.body}.get(
|
|
251
|
+
self.op.answer, answer.body.decode("utf-8", "replace")
|
|
252
|
+
)
|
|
253
|
+
try:
|
|
254
|
+
value: object = loads(answer.body)
|
|
255
|
+
except ValueError:
|
|
256
|
+
raise DecodeError(f"HTTP {answer.status}: the body is not JSON") from None
|
|
257
|
+
if not shaped(value, self.op.shape):
|
|
258
|
+
raise DecodeError(
|
|
259
|
+
f"HTTP {answer.status}: the body is not a JSON {self.op.shape}"
|
|
260
|
+
)
|
|
261
|
+
return value
|
|
262
|
+
|
|
263
|
+
def fill(self, answer: HttpAnswer) -> None:
|
|
264
|
+
target = self.args.get("headers_into")
|
|
265
|
+
if isinstance(target, dict):
|
|
266
|
+
for name, key, kind, required in self.op.headers:
|
|
267
|
+
if name in answer.headers:
|
|
268
|
+
target[key] = scalar(name, answer.headers[name], kind)
|
|
269
|
+
elif required:
|
|
270
|
+
raise DecodeError(f"the {name} header is missing")
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def folded(items: Iterable[tuple[str, str]]) -> dict[str, str]:
|
|
274
|
+
out: dict[str, tuple[str, str]] = {}
|
|
275
|
+
for name, value in items:
|
|
276
|
+
out.pop(name.lower(), None)
|
|
277
|
+
out[name.lower()] = (name, value)
|
|
278
|
+
return dict(out.values())
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def shaped(value: object, shape: str | None) -> bool:
|
|
282
|
+
kinds = SHAPES.get(shape or "", (object,))
|
|
283
|
+
return isinstance(value, kinds) and not (
|
|
284
|
+
shape == "number" and isinstance(value, bool)
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def scalar(name: str, value: str, kind: str) -> object:
|
|
289
|
+
if kind == "boolean" and value in ("true", "false"):
|
|
290
|
+
return value == "true"
|
|
291
|
+
try:
|
|
292
|
+
return {"integer": int, "number": float, "string": str}[kind](value)
|
|
293
|
+
except (KeyError, ValueError):
|
|
294
|
+
raise DecodeError(f"the {name} header is not a valid {kind}") from None
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def failure(answer: HttpAnswer, core: ClientCore) -> APIStatusError:
|
|
298
|
+
return status_error(answer.status, answer.headers, answer.body, core.keys)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""The caller's hooks, TypeScript parity: ``on_request`` before each send, ``on_response`` on each
|
|
3
|
+
answer, in order, sharing one ``state``; a hook that raises ends the call."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import inspect
|
|
8
|
+
from collections.abc import Awaitable, Callable, Mapping, Sequence
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
from typing import TYPE_CHECKING, Any, TypeVar
|
|
11
|
+
|
|
12
|
+
from .errors import ConfigError, HoneyError, HookError
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from .config import ClientConfig
|
|
16
|
+
|
|
17
|
+
__all__ = ["RequestContext", "ResponseContext"]
|
|
18
|
+
|
|
19
|
+
C = TypeVar("C")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class RequestContext:
|
|
24
|
+
"""A request about to be sent; a hook may change it. ``body`` is ``None`` for an iterable body."""
|
|
25
|
+
|
|
26
|
+
method: str
|
|
27
|
+
url: str = field(repr=False)
|
|
28
|
+
path: str = field(repr=False)
|
|
29
|
+
headers: dict[str, str] = field(repr=False)
|
|
30
|
+
body: bytes | None = field(repr=False)
|
|
31
|
+
is_retry: bool = False
|
|
32
|
+
selector: str = ""
|
|
33
|
+
is_stale: bool = False
|
|
34
|
+
invalidated_by: list[str] = field(default_factory=list)
|
|
35
|
+
state: dict[str, Any] = field(default_factory=dict, repr=False)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass
|
|
39
|
+
class ResponseContext:
|
|
40
|
+
"""An answer before it is decoded; a hook may replace it. A stream's 2xx body is not read."""
|
|
41
|
+
|
|
42
|
+
status: int
|
|
43
|
+
headers: Mapping[str, str] = field(repr=False)
|
|
44
|
+
body: bytes = field(repr=False)
|
|
45
|
+
is_retry: bool = False
|
|
46
|
+
selector: str = ""
|
|
47
|
+
is_stale: bool = False
|
|
48
|
+
invalidated_by: list[str] = field(default_factory=list)
|
|
49
|
+
state: dict[str, Any] = field(default_factory=dict, repr=False)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def wrapped(error: Exception, what: str = "hook") -> HoneyError:
|
|
53
|
+
return error if isinstance(error, HoneyError) else HookError(f"{what}: {error}")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def refuse_hooks(config: ClientConfig, sync: bool) -> None:
|
|
57
|
+
if sync and (
|
|
58
|
+
config.on_request
|
|
59
|
+
or config.on_response
|
|
60
|
+
or inspect.iscoroutinefunction(config.on_auth_expired)
|
|
61
|
+
):
|
|
62
|
+
raise ConfigError(
|
|
63
|
+
"SDK runs on_request_sync, on_response_sync and a plain on_auth_expired"
|
|
64
|
+
)
|
|
65
|
+
if not sync and (config.on_request_sync or config.on_response_sync):
|
|
66
|
+
raise ConfigError("AsyncSDK runs on_request and on_response")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def run_sync(hooks: Sequence[Callable[[C], None]], context: C) -> None:
|
|
70
|
+
for hook in hooks:
|
|
71
|
+
try:
|
|
72
|
+
hook(context)
|
|
73
|
+
except Exception as error:
|
|
74
|
+
raise wrapped(error) from error
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
async def run_async(
|
|
78
|
+
hooks: Sequence[Callable[[C], Awaitable[None] | None]], context: C
|
|
79
|
+
) -> None:
|
|
80
|
+
for hook in hooks:
|
|
81
|
+
try:
|
|
82
|
+
result = hook(context)
|
|
83
|
+
if inspect.isawaitable(result):
|
|
84
|
+
await result
|
|
85
|
+
except Exception as error:
|
|
86
|
+
raise wrapped(error) from error
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""Invalidation targets (``METHOD /path``): filled from a call's path params, and matched against a
|
|
3
|
+
concrete path segment by segment, with no regular expression."""
|
|
4
|
+
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
|
|
8
|
+
from .errors import PathParamError
|
|
9
|
+
from .path import colon_name, expand
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True)
|
|
13
|
+
class RequestMeta:
|
|
14
|
+
selector: str = ""
|
|
15
|
+
is_stale: bool = False
|
|
16
|
+
invalidated_by: list[str] = field(default_factory=list)
|
|
17
|
+
seq: int = 0
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def has_placeholders(path: str) -> bool:
|
|
21
|
+
return any(
|
|
22
|
+
colon_name(p) is not None or ("{" in p and "}" in p) for p in path.split("/")
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def segment_matches(text: str, pattern: str) -> bool:
|
|
27
|
+
at = pattern.find("{")
|
|
28
|
+
close = pattern.find("}", at)
|
|
29
|
+
if at < 0 or close < 0:
|
|
30
|
+
return text == pattern
|
|
31
|
+
head, rest = pattern[:at], pattern[close + 1 :]
|
|
32
|
+
tail = text[len(head) :]
|
|
33
|
+
return text.startswith(head) and any(
|
|
34
|
+
segment_matches(tail[i:], rest) for i in range(1, len(tail) + 1)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def matches_pattern(path: str, pattern: str) -> bool:
|
|
39
|
+
got, want = path.split("/"), pattern.split("/")
|
|
40
|
+
return path == pattern or (
|
|
41
|
+
len(got) == len(want)
|
|
42
|
+
and all(
|
|
43
|
+
bool(g) if colon_name(w) else segment_matches(g, w)
|
|
44
|
+
for g, w in zip(got, want, strict=True)
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def resolve_targets(targets: tuple[str, ...], params: Mapping[str, str]) -> list[str]:
|
|
50
|
+
out = []
|
|
51
|
+
for target in targets:
|
|
52
|
+
method, _, path = target.partition(" ")
|
|
53
|
+
try:
|
|
54
|
+
out.append(f"{method} {expand(path, params)}")
|
|
55
|
+
except PathParamError:
|
|
56
|
+
out.append(target)
|
|
57
|
+
return out
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""Lifecycle log entries for ``on_log``. No entry carries a path value, a header value or a query:
|
|
3
|
+
``operation`` is ``METHOD /template``. A logger that raises is ignored."""
|
|
4
|
+
|
|
5
|
+
import contextlib
|
|
6
|
+
import time
|
|
7
|
+
from collections.abc import Callable
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
|
|
10
|
+
__all__ = ["LogEntry"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class LogEntry:
|
|
15
|
+
"""One event of a call: ``request_start``, ``response_received`` or ``error``."""
|
|
16
|
+
|
|
17
|
+
level: str
|
|
18
|
+
event: str
|
|
19
|
+
operation: str
|
|
20
|
+
duration_ms: int
|
|
21
|
+
status: int | None = None
|
|
22
|
+
error: str | None = None
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CallLog:
|
|
26
|
+
def __init__(self, hook: Callable[[LogEntry], None] | None, operation: str) -> None:
|
|
27
|
+
self.hook = hook
|
|
28
|
+
self.operation = operation
|
|
29
|
+
self.start = time.monotonic()
|
|
30
|
+
|
|
31
|
+
def emit(
|
|
32
|
+
self,
|
|
33
|
+
level: str,
|
|
34
|
+
event: str,
|
|
35
|
+
status: int | None = None,
|
|
36
|
+
error: str | None = None,
|
|
37
|
+
took: int | None = None,
|
|
38
|
+
) -> None:
|
|
39
|
+
if took is None:
|
|
40
|
+
took = round((time.monotonic() - self.start) * 1000)
|
|
41
|
+
if self.hook is not None:
|
|
42
|
+
with contextlib.suppress(Exception):
|
|
43
|
+
self.hook(LogEntry(level, event, self.operation, took, status, error))
|
|
44
|
+
|
|
45
|
+
def started(self) -> None:
|
|
46
|
+
# the call's clock starts at request_start, so it logs 0, as every SDK's does
|
|
47
|
+
self.start = time.monotonic()
|
|
48
|
+
self.emit("debug", "request_start", took=0)
|
|
49
|
+
|
|
50
|
+
def answered(self, status: int) -> None:
|
|
51
|
+
self.emit("warn" if status >= 400 else "info", "response_received", status)
|
|
52
|
+
|
|
53
|
+
def failed(self, error: Exception) -> None:
|
|
54
|
+
status = getattr(error, "status", None)
|
|
55
|
+
self.emit(
|
|
56
|
+
"error",
|
|
57
|
+
"error",
|
|
58
|
+
status if isinstance(status, int) else None,
|
|
59
|
+
f"{type(error).__name__}: {error}",
|
|
60
|
+
)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""One operation, as its methods call it."""
|
|
3
|
+
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Generic, Literal, TypeVar
|
|
6
|
+
|
|
7
|
+
T = TypeVar("T", covariant=True)
|
|
8
|
+
|
|
9
|
+
HeaderKind = Literal["boolean", "integer", "number", "string"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True)
|
|
13
|
+
class Operation(Generic[T]):
|
|
14
|
+
method: str
|
|
15
|
+
path: str
|
|
16
|
+
path_params: tuple[str, ...] = ()
|
|
17
|
+
body: Literal["binary", "form", "json", "multipart", "text"] | None = None
|
|
18
|
+
content_type: str | None = None
|
|
19
|
+
answer: Literal["binary", "json", "none", "text"] = "json"
|
|
20
|
+
accept: str | None = None
|
|
21
|
+
shape: Literal["array", "boolean", "number", "object", "string"] | None = None
|
|
22
|
+
idempotent: bool = False
|
|
23
|
+
invalidates: tuple[str, ...] = ()
|
|
24
|
+
stream: Literal["realtime", "sse", "ws"] | None = None
|
|
25
|
+
headers: tuple[tuple[str, str, HeaderKind, bool], ...] = ()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""Path templates: ``{name}`` in a segment and whole ``:name`` segments, each value encoded like
|
|
3
|
+
``encodeURIComponent``, so every SDK language sends the same bytes."""
|
|
4
|
+
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from urllib.parse import quote
|
|
7
|
+
|
|
8
|
+
from .errors import PathParamError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def colon_name(part: str) -> str | None:
|
|
12
|
+
name = part[1:]
|
|
13
|
+
return name if part[:1] == ":" and name.isidentifier() and name.isascii() else None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def expand(template: str, params: Mapping[str, str]) -> str:
|
|
17
|
+
|
|
18
|
+
def value(name: str) -> str:
|
|
19
|
+
found = params.get(name)
|
|
20
|
+
if found is None or found in ("", ".", ".."):
|
|
21
|
+
raise PathParamError(
|
|
22
|
+
f"path parameter {name!r} is missing, empty, '.' or '..'"
|
|
23
|
+
)
|
|
24
|
+
return quote(found, safe="!~*'()")
|
|
25
|
+
|
|
26
|
+
out = []
|
|
27
|
+
for part in template.split("/"):
|
|
28
|
+
name = colon_name(part)
|
|
29
|
+
if name is not None:
|
|
30
|
+
out.append(value(name))
|
|
31
|
+
continue
|
|
32
|
+
text = ""
|
|
33
|
+
while (at := part.find("{")) >= 0:
|
|
34
|
+
close = part.find("}", at)
|
|
35
|
+
inner = part[at + 1 : close]
|
|
36
|
+
if close < 0 or not inner or "{" in inner:
|
|
37
|
+
text, part = text + part[: at + 1], part[at + 1 :]
|
|
38
|
+
else:
|
|
39
|
+
text, part = text + part[:at] + value(inner), part[close + 1 :]
|
|
40
|
+
out.append(text + part)
|
|
41
|
+
return "/".join(out)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @generated by honey. DO NOT EDIT.
|
|
2
|
+
"""Query and form values as URLSearchParams writes them: ``+`` for a space, a list repeating its key,
|
|
3
|
+
a number as JavaScript prints it."""
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from collections.abc import Mapping
|
|
7
|
+
from decimal import Decimal
|
|
8
|
+
from enum import Enum
|
|
9
|
+
from urllib.parse import quote
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def number(value: float) -> str:
|
|
13
|
+
if value != value or value in (float("inf"), float("-inf")):
|
|
14
|
+
return {"nan": "NaN", "inf": "Infinity", "-inf": "-Infinity"}[str(value)]
|
|
15
|
+
if value == 0:
|
|
16
|
+
return "0"
|
|
17
|
+
if 1e-6 <= abs(value) < 1e21:
|
|
18
|
+
text = format(Decimal(repr(value)), "f")
|
|
19
|
+
return text.rstrip("0").rstrip(".") if "." in text else text
|
|
20
|
+
mantissa, _, exponent = f"{value:e}".partition("e")
|
|
21
|
+
return f"{mantissa.rstrip('0').rstrip('.')}e{int(exponent):+d}"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def text(value: object) -> str:
|
|
25
|
+
if isinstance(value, Enum):
|
|
26
|
+
value = value.value
|
|
27
|
+
if isinstance(value, bool):
|
|
28
|
+
return "true" if value else "false"
|
|
29
|
+
if isinstance(value, float):
|
|
30
|
+
return number(value)
|
|
31
|
+
if isinstance(value, (str, int)):
|
|
32
|
+
return str(value)
|
|
33
|
+
return json.dumps(value, separators=(",", ":"), ensure_ascii=False)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def pairs(params: Mapping[str, object] | None) -> list[tuple[str, str]]:
|
|
37
|
+
out = []
|
|
38
|
+
for key, value in (params or {}).items():
|
|
39
|
+
items = value if isinstance(value, (list, tuple)) else [value]
|
|
40
|
+
out += [(key, text(item)) for item in items if item is not None and item != {}]
|
|
41
|
+
return out
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def encode(items: list[tuple[str, str]]) -> str:
|
|
45
|
+
def escape(value: str) -> str:
|
|
46
|
+
return quote(value, safe="*").replace("%20", "+").replace("~", "%7E")
|
|
47
|
+
|
|
48
|
+
return "&".join(f"{escape(key)}={escape(value)}" for key, value in items)
|