@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,300 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
using System;
|
|
3
|
+
using System.IO;
|
|
4
|
+
using System.Net.WebSockets;
|
|
5
|
+
using System.Text;
|
|
6
|
+
using System.Text.Json;
|
|
7
|
+
using System.Text.Json.Serialization.Metadata;
|
|
8
|
+
using System.Threading;
|
|
9
|
+
using System.Threading.Tasks;
|
|
10
|
+
|
|
11
|
+
namespace Honey.Runtime;
|
|
12
|
+
|
|
13
|
+
/// <summary>One whole WebSocket message: its type and its data.</summary>
|
|
14
|
+
public sealed record WsMessage(WebSocketMessageType Type, byte[] Data)
|
|
15
|
+
{
|
|
16
|
+
/// <summary>The data as UTF-8 text, an invalid sequence as U+FFFD.</summary>
|
|
17
|
+
public string Text => Encoding.UTF8.GetString(Data);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/// <summary>A close frame's status and reason.</summary>
|
|
21
|
+
public sealed record WsClose(WebSocketCloseStatus Status, string Reason);
|
|
22
|
+
|
|
23
|
+
/// <summary>
|
|
24
|
+
/// An open WebSocket, read one whole message at a time (16 MiB at most) and written from any task. It ends once, firing
|
|
25
|
+
/// <see cref="Closed"/> or <see cref="Error"/>: on the server's close (echoed, its code in <see cref="ClosedBy"/>),
|
|
26
|
+
/// <see cref="CloseAsync"/>, a drop, a message over the cap, or a cancel. The method's or a read's token closes it with
|
|
27
|
+
/// 1000 and the pending read throws OperationCanceledException; a read after the end answers null. Its dial runs no
|
|
28
|
+
/// OnRequest or OnResponse hook, and a refused handshake's 401 is its error, with no OnAuthExpired refresh.
|
|
29
|
+
/// </summary>
|
|
30
|
+
public sealed class TypedWebSocket : IAsyncDisposable
|
|
31
|
+
{
|
|
32
|
+
private const int MaxMessage = 16 << 20;
|
|
33
|
+
private const int MaxReason = 123;
|
|
34
|
+
|
|
35
|
+
private readonly WebSocket _socket;
|
|
36
|
+
private readonly IDisposable _owner;
|
|
37
|
+
private CancellationTokenRegistration _registration;
|
|
38
|
+
private readonly byte[] _chunk = new byte[65_536];
|
|
39
|
+
private readonly object _gate = new();
|
|
40
|
+
private bool _ended;
|
|
41
|
+
private Exception? _pending;
|
|
42
|
+
|
|
43
|
+
internal TypedWebSocket(WebSocket socket, string? subprotocol, IDisposable owner)
|
|
44
|
+
{
|
|
45
|
+
_socket = socket;
|
|
46
|
+
_owner = owner;
|
|
47
|
+
Subprotocol = subprotocol;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* the method's token, which closes the socket for its whole life */
|
|
51
|
+
internal TypedWebSocket Bound(CancellationToken call)
|
|
52
|
+
{
|
|
53
|
+
_registration = call.Register(static (socket, token) => ((TypedWebSocket)socket!).Cancel(token), this);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// <summary>The subprotocol the server chose; null when it chose none.</summary>
|
|
58
|
+
public string? Subprotocol { get; }
|
|
59
|
+
|
|
60
|
+
/// <summary>The server's close frame, once it closed the socket.</summary>
|
|
61
|
+
public WsClose? ClosedBy { get; private set; }
|
|
62
|
+
|
|
63
|
+
/// <summary>Each message as it is read; a handler that throws is ignored.</summary>
|
|
64
|
+
public event Action<WsMessage>? Message;
|
|
65
|
+
|
|
66
|
+
/// <summary>The socket's close, the server's or the client's own; a handler that throws is ignored.</summary>
|
|
67
|
+
public event Action<WsClose>? Closed;
|
|
68
|
+
|
|
69
|
+
/// <summary>The failure that ended the socket; a handler that throws is ignored.</summary>
|
|
70
|
+
public event Action<Exception>? Error;
|
|
71
|
+
|
|
72
|
+
/// <summary>The next whole message; null once the socket ended. Its token, once fired, closes the socket.</summary>
|
|
73
|
+
public async Task<WsMessage?> ReceiveAsync(CancellationToken cancellationToken = default)
|
|
74
|
+
{
|
|
75
|
+
if (Ended())
|
|
76
|
+
{
|
|
77
|
+
return Interlocked.Exchange(ref _pending, null) is { } pending ? throw pending : null;
|
|
78
|
+
}
|
|
79
|
+
using var registration = cancellationToken.Register(static (socket, token) => ((TypedWebSocket)socket!).Cancel(token), this);
|
|
80
|
+
using var message = new MemoryStream();
|
|
81
|
+
while (true)
|
|
82
|
+
{
|
|
83
|
+
ValueWebSocketReceiveResult result;
|
|
84
|
+
try
|
|
85
|
+
{
|
|
86
|
+
/* never the caller's token: a canceled BCL receive aborts the socket with no close frame */
|
|
87
|
+
result = await _socket.ReceiveAsync(_chunk.AsMemory(), CancellationToken.None).ConfigureAwait(false);
|
|
88
|
+
}
|
|
89
|
+
catch (Exception e)
|
|
90
|
+
{
|
|
91
|
+
return Failed(e);
|
|
92
|
+
}
|
|
93
|
+
if (Interlocked.Exchange(ref _pending, null) is { } canceled)
|
|
94
|
+
{
|
|
95
|
+
if (result.MessageType == WebSocketMessageType.Close)
|
|
96
|
+
{
|
|
97
|
+
Release();
|
|
98
|
+
}
|
|
99
|
+
throw canceled;
|
|
100
|
+
}
|
|
101
|
+
if (result.MessageType == WebSocketMessageType.Close)
|
|
102
|
+
{
|
|
103
|
+
return await ClosedByServerAsync().ConfigureAwait(false);
|
|
104
|
+
}
|
|
105
|
+
message.Write(_chunk, 0, result.Count);
|
|
106
|
+
if (message.Length > MaxMessage)
|
|
107
|
+
{
|
|
108
|
+
throw await OverCapAsync().ConfigureAwait(false);
|
|
109
|
+
}
|
|
110
|
+
if (result.EndOfMessage)
|
|
111
|
+
{
|
|
112
|
+
var whole = new WsMessage(result.MessageType, message.ToArray());
|
|
113
|
+
Fire(Message, whole);
|
|
114
|
+
return whole;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// <summary>Sends <paramref name="text"/> as one text message.</summary>
|
|
120
|
+
public Task SendAsync(string text, CancellationToken cancellationToken = default) =>
|
|
121
|
+
SentAsync(Encoding.UTF8.GetBytes(text), WebSocketMessageType.Text, cancellationToken);
|
|
122
|
+
|
|
123
|
+
/// <summary>Sends <paramref name="data"/> as one binary message.</summary>
|
|
124
|
+
public Task SendAsync(byte[] data, CancellationToken cancellationToken = default) =>
|
|
125
|
+
SentAsync(data, WebSocketMessageType.Binary, cancellationToken);
|
|
126
|
+
|
|
127
|
+
/// <summary>Sends <paramref name="value"/> as one text message of its JSON.</summary>
|
|
128
|
+
public Task SendAsync<T>(T value, JsonTypeInfo<T> info, CancellationToken cancellationToken = default) =>
|
|
129
|
+
SentAsync(JsonSerializer.SerializeToUtf8Bytes(value, info), WebSocketMessageType.Text, cancellationToken);
|
|
130
|
+
|
|
131
|
+
/// <summary>
|
|
132
|
+
/// Closes the socket with <paramref name="status"/> and <paramref name="reason"/> (cut to 123 UTF-8 bytes) and waits
|
|
133
|
+
/// for the server's echo, then fires <see cref="Closed"/>; on a socket that already ended it does nothing.
|
|
134
|
+
/// </summary>
|
|
135
|
+
public async Task CloseAsync(WebSocketCloseStatus status = WebSocketCloseStatus.NormalClosure, string reason = "", CancellationToken cancellationToken = default)
|
|
136
|
+
{
|
|
137
|
+
try
|
|
138
|
+
{
|
|
139
|
+
if (End())
|
|
140
|
+
{
|
|
141
|
+
var cut = Cut(reason);
|
|
142
|
+
await Quietly(_socket.CloseAsync(status, cut, cancellationToken), cancellationToken).ConfigureAwait(false);
|
|
143
|
+
Fire(Closed, new WsClose(status, cut));
|
|
144
|
+
}
|
|
145
|
+
else if (_socket.State == WebSocketState.CloseSent)
|
|
146
|
+
{
|
|
147
|
+
/* the close a cancel or the cap sent: its echo drained */
|
|
148
|
+
await Quietly(_socket.CloseAsync(status, null, cancellationToken), cancellationToken).ConfigureAwait(false);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
finally
|
|
152
|
+
{
|
|
153
|
+
Release();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/// <summary>Closes the socket with 1000, as <see cref="CloseAsync"/> does.</summary>
|
|
158
|
+
public ValueTask DisposeAsync() => new(CloseAsync());
|
|
159
|
+
|
|
160
|
+
private async Task SentAsync(byte[] data, WebSocketMessageType type, CancellationToken token)
|
|
161
|
+
{
|
|
162
|
+
if (Ended() || _socket.State != WebSocketState.Open)
|
|
163
|
+
{
|
|
164
|
+
throw new ApiConnectionException("the WebSocket is closed");
|
|
165
|
+
}
|
|
166
|
+
try
|
|
167
|
+
{
|
|
168
|
+
await _socket.SendAsync(data, type, true, token).ConfigureAwait(false);
|
|
169
|
+
}
|
|
170
|
+
catch (OperationCanceledException) when (token.IsCancellationRequested)
|
|
171
|
+
{
|
|
172
|
+
throw;
|
|
173
|
+
}
|
|
174
|
+
catch (Exception e)
|
|
175
|
+
{
|
|
176
|
+
throw new ApiConnectionException($"the WebSocket send failed: {e.GetType().Name}", e);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private void Cancel(CancellationToken token)
|
|
181
|
+
{
|
|
182
|
+
lock (_gate)
|
|
183
|
+
{
|
|
184
|
+
if (_ended)
|
|
185
|
+
{
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
_pending = new OperationCanceledException("the WebSocket was canceled", token);
|
|
189
|
+
_ended = true;
|
|
190
|
+
}
|
|
191
|
+
Fire(Closed, new WsClose(WebSocketCloseStatus.NormalClosure, ""));
|
|
192
|
+
_ = Quietly(_socket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None), CancellationToken.None);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* the server's close, echoed at once; the echo of the client's own close is CloseAsync's to finish */
|
|
196
|
+
private async Task<WsMessage?> ClosedByServerAsync()
|
|
197
|
+
{
|
|
198
|
+
if (End())
|
|
199
|
+
{
|
|
200
|
+
ClosedBy = new WsClose(_socket.CloseStatus ?? WebSocketCloseStatus.Empty, _socket.CloseStatusDescription ?? "");
|
|
201
|
+
await Quietly(_socket.CloseOutputAsync(ClosedBy.Status, ClosedBy.Reason, CancellationToken.None), CancellationToken.None).ConfigureAwait(false);
|
|
202
|
+
Fire(Closed, ClosedBy);
|
|
203
|
+
Release();
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private WsMessage? Failed(Exception e)
|
|
209
|
+
{
|
|
210
|
+
Release();
|
|
211
|
+
if (Interlocked.Exchange(ref _pending, null) is { } canceled)
|
|
212
|
+
{
|
|
213
|
+
throw canceled;
|
|
214
|
+
}
|
|
215
|
+
if (!End())
|
|
216
|
+
{
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
var error = new ApiConnectionException("the WebSocket failed", e);
|
|
220
|
+
Fire(Error, error);
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private async Task<Exception> OverCapAsync()
|
|
225
|
+
{
|
|
226
|
+
End();
|
|
227
|
+
await Quietly(_socket.CloseOutputAsync(WebSocketCloseStatus.MessageTooBig, "Message too big", CancellationToken.None), CancellationToken.None).ConfigureAwait(false);
|
|
228
|
+
var error = new ApiConnectionException("the WebSocket ended: 1009 Message too big");
|
|
229
|
+
Fire(Error, error);
|
|
230
|
+
return error;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private bool Ended()
|
|
234
|
+
{
|
|
235
|
+
lock (_gate)
|
|
236
|
+
{
|
|
237
|
+
return _ended;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/* whether this call ended the socket */
|
|
242
|
+
private bool End()
|
|
243
|
+
{
|
|
244
|
+
lock (_gate)
|
|
245
|
+
{
|
|
246
|
+
var first = !_ended;
|
|
247
|
+
_ended = true;
|
|
248
|
+
return first;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private void Release()
|
|
253
|
+
{
|
|
254
|
+
_registration.Unregister();
|
|
255
|
+
_socket.Dispose();
|
|
256
|
+
_owner.Dispose();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/* a close frame's work: the peer may be gone already, which ends the socket all the same */
|
|
260
|
+
private static async Task Quietly(Task work, CancellationToken token)
|
|
261
|
+
{
|
|
262
|
+
try
|
|
263
|
+
{
|
|
264
|
+
await work.ConfigureAwait(false);
|
|
265
|
+
}
|
|
266
|
+
catch (Exception) when (!token.IsCancellationRequested)
|
|
267
|
+
{
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
private static string Cut(string reason)
|
|
272
|
+
{
|
|
273
|
+
var (bytes, end) = (0, 0);
|
|
274
|
+
foreach (var rune in reason.EnumerateRunes())
|
|
275
|
+
{
|
|
276
|
+
bytes += rune.Utf8SequenceLength;
|
|
277
|
+
if (bytes > MaxReason)
|
|
278
|
+
{
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
end += rune.Utf16SequenceLength;
|
|
282
|
+
}
|
|
283
|
+
return reason[..end];
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
private static void Fire<T>(Action<T>? handlers, T value)
|
|
287
|
+
{
|
|
288
|
+
foreach (var handler in handlers?.GetInvocationList() ?? [])
|
|
289
|
+
{
|
|
290
|
+
try
|
|
291
|
+
{
|
|
292
|
+
((Action<T>)handler)(value);
|
|
293
|
+
}
|
|
294
|
+
catch (Exception)
|
|
295
|
+
{
|
|
296
|
+
/* a handler's failure is not the socket's */
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
using System;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using System.IO;
|
|
5
|
+
using System.Linq;
|
|
6
|
+
using System.Net;
|
|
7
|
+
using System.Net.Http;
|
|
8
|
+
using System.Net.WebSockets;
|
|
9
|
+
using System.Security.Cryptography;
|
|
10
|
+
using System.Text;
|
|
11
|
+
using System.Threading;
|
|
12
|
+
using System.Threading.Tasks;
|
|
13
|
+
|
|
14
|
+
namespace Honey.Runtime;
|
|
15
|
+
|
|
16
|
+
internal sealed partial class Transport
|
|
17
|
+
{
|
|
18
|
+
public async Task<TypedWebSocket> SocketAsync(Operation op, Call call, IReadOnlyList<string>? protocols, string? reconnectToken, CancellationToken cancellationToken) =>
|
|
19
|
+
(await WsDial.DialAsync(this, new Exchange(this, op, call with { Query = [.. call.Query, Arg.Text("reconnect_token", reconnectToken)] }, stream: true), protocols ?? [], cancellationToken).ConfigureAwait(false))
|
|
20
|
+
.Bound(cancellationToken);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
internal static class WsDial
|
|
24
|
+
{
|
|
25
|
+
private const string Rfc6455 = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
26
|
+
private static readonly TimeSpan KeepAlive = TimeSpan.FromSeconds(20);
|
|
27
|
+
|
|
28
|
+
public static async Task<TypedWebSocket> DialAsync(Transport client, Exchange x, IReadOnlyList<string> protocols, CancellationToken cancellationToken)
|
|
29
|
+
{
|
|
30
|
+
var url = x.Url();
|
|
31
|
+
cancellationToken.ThrowIfCancellationRequested();
|
|
32
|
+
var key = Convert.ToBase64String(RandomNumberGenerator.GetBytes(16));
|
|
33
|
+
var request = Request(url, x.DialHeaders(client.Auth.Token), key, protocols);
|
|
34
|
+
var response = await AnsweredAsync(client, x, request, cancellationToken).ConfigureAwait(false);
|
|
35
|
+
var headers = Wire.HeadersOf(response);
|
|
36
|
+
try
|
|
37
|
+
{
|
|
38
|
+
var chosen = headers.GetValueOrDefault("sec-websocket-protocol") is { Length: > 0 } picked ? picked : null;
|
|
39
|
+
var refusal = Refusal(headers, key, chosen, protocols);
|
|
40
|
+
if (refusal is not null)
|
|
41
|
+
{
|
|
42
|
+
throw new ApiConnectionException($"the WebSocket handshake failed: {refusal}");
|
|
43
|
+
}
|
|
44
|
+
x.Raw?.Fill(101, headers, [], SocketUrl(url));
|
|
45
|
+
var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
|
46
|
+
var options = new WebSocketCreationOptions { SubProtocol = chosen, KeepAliveInterval = KeepAlive, KeepAliveTimeout = KeepAlive };
|
|
47
|
+
return new TypedWebSocket(WebSocket.CreateFromStream(stream, options), chosen, response);
|
|
48
|
+
}
|
|
49
|
+
catch
|
|
50
|
+
{
|
|
51
|
+
response.Dispose();
|
|
52
|
+
throw;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private static Uri SocketUrl(Uri url) => new UriBuilder(url) { Scheme = url.Scheme == Uri.UriSchemeHttps ? "wss" : "ws" }.Uri;
|
|
57
|
+
|
|
58
|
+
private static HttpRequestMessage Request(Uri url, Dictionary<string, string> headers, string key, IReadOnlyList<string> protocols)
|
|
59
|
+
{
|
|
60
|
+
Wire.Check(headers);
|
|
61
|
+
headers["Connection"] = "Upgrade";
|
|
62
|
+
headers["Upgrade"] = "websocket";
|
|
63
|
+
headers["Sec-WebSocket-Version"] = "13";
|
|
64
|
+
headers["Sec-WebSocket-Key"] = key;
|
|
65
|
+
if (protocols.Count > 0)
|
|
66
|
+
{
|
|
67
|
+
headers["Sec-WebSocket-Protocol"] = string.Join(", ", protocols);
|
|
68
|
+
}
|
|
69
|
+
var request = Wire.Message(new Hop("GET", url, headers, null, null, false));
|
|
70
|
+
request.Version = HttpVersion.Version11;
|
|
71
|
+
request.VersionPolicy = HttpVersionPolicy.RequestVersionExact;
|
|
72
|
+
return request;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* the 101, or the refusal's status exception with its body read; the deadline bounds both */
|
|
76
|
+
private static async Task<HttpResponseMessage> AnsweredAsync(Transport client, Exchange x, HttpRequestMessage request, CancellationToken cancellationToken)
|
|
77
|
+
{
|
|
78
|
+
var limit = x.Limit;
|
|
79
|
+
using var deadline = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
|
80
|
+
if (limit > TimeSpan.Zero)
|
|
81
|
+
{
|
|
82
|
+
deadline.CancelAfter(limit);
|
|
83
|
+
}
|
|
84
|
+
try
|
|
85
|
+
{
|
|
86
|
+
var response = await client.Http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, deadline.Token).ConfigureAwait(false);
|
|
87
|
+
if (response.StatusCode == HttpStatusCode.SwitchingProtocols)
|
|
88
|
+
{
|
|
89
|
+
return response;
|
|
90
|
+
}
|
|
91
|
+
using (response)
|
|
92
|
+
{
|
|
93
|
+
var (status, headers) = ((int)response.StatusCode, Wire.HeadersOf(response));
|
|
94
|
+
var body = await x.ReadAsync(response, deadline.Token).ConfigureAwait(false);
|
|
95
|
+
x.Raw?.Fill(status, headers, body, SocketUrl(request.RequestUri!));
|
|
96
|
+
throw ApiStatusException.Of(Envelopes.Of(status, headers, body, client.Json));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
|
|
100
|
+
{
|
|
101
|
+
throw;
|
|
102
|
+
}
|
|
103
|
+
catch (OperationCanceledException e)
|
|
104
|
+
{
|
|
105
|
+
throw new ApiTimeoutException($"{x.Route} timed out after {limit.TotalMilliseconds} ms", e);
|
|
106
|
+
}
|
|
107
|
+
catch (Exception e) when (e is HttpRequestException or IOException)
|
|
108
|
+
{
|
|
109
|
+
throw new ApiConnectionException($"{x.Route}: {e.Message}", e);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* RFC 6455 §4.1: what makes a 101 no WebSocket handshake; null when it is one */
|
|
114
|
+
private static string? Refusal(Dictionary<string, string> headers, string key, string? chosen, IReadOnlyList<string> protocols)
|
|
115
|
+
{
|
|
116
|
+
var accept = Convert.ToBase64String(SHA1.HashData(Encoding.ASCII.GetBytes(key + Rfc6455)));
|
|
117
|
+
if (!string.Equals(headers.GetValueOrDefault("upgrade")?.Trim(), "websocket", StringComparison.OrdinalIgnoreCase))
|
|
118
|
+
{
|
|
119
|
+
return "the answer has no Upgrade: websocket";
|
|
120
|
+
}
|
|
121
|
+
if (headers.GetValueOrDefault("sec-websocket-accept")?.Trim() != accept)
|
|
122
|
+
{
|
|
123
|
+
return "the Sec-WebSocket-Accept does not match";
|
|
124
|
+
}
|
|
125
|
+
return chosen is not null && !protocols.Contains(chosen) ? $"the server chose subprotocol {chosen}, which was not offered" : null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Code generated by honey. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package sdk
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"context"
|
|
7
|
+
"crypto/rand"
|
|
8
|
+
"net/http"
|
|
9
|
+
"sort"
|
|
10
|
+
"strings"
|
|
11
|
+
"sync"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
// authState holds the current bearer token so a refreshed token is reused by later calls, and
|
|
15
|
+
// serializes refreshes so N concurrent 401s refresh once.
|
|
16
|
+
type authState struct {
|
|
17
|
+
mu sync.Mutex
|
|
18
|
+
token string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func (a *authState) current(cfg Config) string {
|
|
22
|
+
if a == nil {
|
|
23
|
+
return cfg.BearerToken
|
|
24
|
+
}
|
|
25
|
+
a.mu.Lock()
|
|
26
|
+
defer a.mu.Unlock()
|
|
27
|
+
return a.token
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// refresh calls OnAuthExpired unless another call already replaced rejected.
|
|
31
|
+
func (a *authState) refresh(ctx context.Context, cfg Config, rejected string) (string, error) {
|
|
32
|
+
if a == nil {
|
|
33
|
+
return cfg.OnAuthExpired(ctx)
|
|
34
|
+
}
|
|
35
|
+
a.mu.Lock()
|
|
36
|
+
defer a.mu.Unlock()
|
|
37
|
+
if a.token != rejected {
|
|
38
|
+
return a.token, nil
|
|
39
|
+
}
|
|
40
|
+
token, err := cfg.OnAuthExpired(ctx)
|
|
41
|
+
if err != nil {
|
|
42
|
+
return "", err
|
|
43
|
+
}
|
|
44
|
+
a.token = token
|
|
45
|
+
return token, nil
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// mergeHeaders builds a request's headers, later layers winning per name in any casing:
|
|
49
|
+
// Content-Type when contentType is set, then Config.Headers, then each of layers (the operation's
|
|
50
|
+
// headers, then the per-call ones), then the auth header when token is set. OnRequest hooks may
|
|
51
|
+
// change the result.
|
|
52
|
+
func mergeHeaders(cfg Config, token, contentType string, layers ...map[string]string) http.Header {
|
|
53
|
+
h := http.Header{}
|
|
54
|
+
if contentType != "" {
|
|
55
|
+
h.Set("Content-Type", contentType)
|
|
56
|
+
}
|
|
57
|
+
for _, layer := range append([]map[string]string{cfg.Headers}, layers...) {
|
|
58
|
+
for _, k := range sortedKeys(layer) {
|
|
59
|
+
h.Set(k, layer[k])
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if token != "" {
|
|
63
|
+
h.Set(cfg.AuthHeaderName, cfg.AuthHeaderPrefix+token)
|
|
64
|
+
}
|
|
65
|
+
return h
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// withRequestID gives h a fresh X-Request-Id unless it has one (a nil h becomes a new header) and
|
|
69
|
+
// returns it: each request names itself, and a caller's id is kept.
|
|
70
|
+
func withRequestID(h http.Header) http.Header {
|
|
71
|
+
if h == nil {
|
|
72
|
+
h = http.Header{}
|
|
73
|
+
}
|
|
74
|
+
if h.Get("X-Request-Id") == "" {
|
|
75
|
+
h.Set("X-Request-Id", newUUIDv4())
|
|
76
|
+
}
|
|
77
|
+
return h
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
func sortedKeys(m map[string]string) []string {
|
|
81
|
+
keys := make([]string, 0, len(m))
|
|
82
|
+
for k := range m {
|
|
83
|
+
keys = append(keys, k)
|
|
84
|
+
}
|
|
85
|
+
sort.Strings(keys)
|
|
86
|
+
return keys
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// hasHeader reports whether h has name in any casing.
|
|
90
|
+
func hasHeader(h map[string]string, name string) bool {
|
|
91
|
+
for k := range h {
|
|
92
|
+
if strings.EqualFold(k, name) {
|
|
93
|
+
return true
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// setIdempotencyKey gives a call its Idempotency-Key: a header already set (any casing) wins, then
|
|
100
|
+
// key, then a fresh UUID, so every dispatch carries one.
|
|
101
|
+
func setIdempotencyKey(h map[string]string, key string) {
|
|
102
|
+
if hasHeader(h, "Idempotency-Key") {
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
if key == "" {
|
|
106
|
+
key = newUUIDv4()
|
|
107
|
+
}
|
|
108
|
+
h["Idempotency-Key"] = key
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// newUUIDv4 returns a random RFC 4122 version 4 UUID in canonical lower-case form.
|
|
112
|
+
func newUUIDv4() string {
|
|
113
|
+
var b [16]byte
|
|
114
|
+
/* crypto/rand.Read never fails on supported platforms; it panics itself otherwise */
|
|
115
|
+
_, _ = rand.Read(b[:])
|
|
116
|
+
b[6] = (b[6] & 0x0f) | 0x40
|
|
117
|
+
b[8] = (b[8] & 0x3f) | 0x80
|
|
118
|
+
const hex = "0123456789abcdef"
|
|
119
|
+
out := make([]byte, 0, 36)
|
|
120
|
+
for i, by := range b {
|
|
121
|
+
if i == 4 || i == 6 || i == 8 || i == 10 {
|
|
122
|
+
out = append(out, '-')
|
|
123
|
+
}
|
|
124
|
+
out = append(out, hex[by>>4], hex[by&0x0f])
|
|
125
|
+
}
|
|
126
|
+
return string(out)
|
|
127
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Code generated by honey. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package sdk
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"bytes"
|
|
7
|
+
"encoding/json"
|
|
8
|
+
"fmt"
|
|
9
|
+
"io"
|
|
10
|
+
"mime/multipart"
|
|
11
|
+
"net/textproto"
|
|
12
|
+
"net/url"
|
|
13
|
+
"strconv"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
// requestBody is one request payload. JSON values and byte payloads can be sent again on an auth
|
|
17
|
+
// retry or a 307/308 redirect; a Reader cannot.
|
|
18
|
+
type requestBody struct {
|
|
19
|
+
json any
|
|
20
|
+
hasJSON bool
|
|
21
|
+
raw []byte
|
|
22
|
+
hasRaw bool
|
|
23
|
+
reader io.Reader
|
|
24
|
+
contentType string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func jsonBody(v any) requestBody { return requestBody{json: v, hasJSON: true} }
|
|
28
|
+
|
|
29
|
+
// readerBody streams r as is, under the operation's declared media type.
|
|
30
|
+
func readerBody(r io.Reader, contentType string) requestBody {
|
|
31
|
+
return requestBody{reader: r, contentType: contentType}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
func formBody(values url.Values) requestBody {
|
|
35
|
+
return rawBody([]byte(values.Encode()), "application/x-www-form-urlencoded")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func rawBody(raw []byte, contentType string) requestBody {
|
|
39
|
+
return requestBody{raw: raw, hasRaw: true, contentType: contentType}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func (b requestBody) present() bool { return b.hasJSON || b.hasRaw || b.reader != nil }
|
|
43
|
+
|
|
44
|
+
func (b requestBody) replayable() bool { return b.reader == nil }
|
|
45
|
+
|
|
46
|
+
// mediaType is the Content-Type to send: none without a body, JSON unless declared otherwise.
|
|
47
|
+
func (b requestBody) mediaType() string {
|
|
48
|
+
switch {
|
|
49
|
+
case !b.present():
|
|
50
|
+
return ""
|
|
51
|
+
case b.contentType != "":
|
|
52
|
+
return b.contentType
|
|
53
|
+
}
|
|
54
|
+
return "application/json"
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// bytes returns the encoded payload for JSON and raw bodies.
|
|
58
|
+
func (b requestBody) bytes() ([]byte, error) {
|
|
59
|
+
if b.hasRaw {
|
|
60
|
+
return b.raw, nil
|
|
61
|
+
}
|
|
62
|
+
if b.hasJSON {
|
|
63
|
+
encoded, err := json.Marshal(b.json)
|
|
64
|
+
if err != nil {
|
|
65
|
+
return nil, fmt.Errorf("honey: marshal body: %w", err)
|
|
66
|
+
}
|
|
67
|
+
return encoded, nil
|
|
68
|
+
}
|
|
69
|
+
return nil, nil
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// FilePart is one file in a multipart/form-data upload. The SDK reads Data fully before sending,
|
|
73
|
+
// so the request can be retried after an auth refresh.
|
|
74
|
+
type FilePart struct {
|
|
75
|
+
Filename string
|
|
76
|
+
ContentType string
|
|
77
|
+
Data io.Reader
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type multipartField struct {
|
|
81
|
+
name string
|
|
82
|
+
value string
|
|
83
|
+
file *FilePart
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func textField(name string, value any) multipartField {
|
|
87
|
+
return multipartField{name: name, value: formatQueryValue(value)}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
func fileField(name string, file FilePart) multipartField {
|
|
91
|
+
return multipartField{name: name, file: &file}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
func multipartBody(fields []multipartField) (requestBody, error) {
|
|
95
|
+
var buf bytes.Buffer
|
|
96
|
+
w := multipart.NewWriter(&buf)
|
|
97
|
+
for _, f := range fields {
|
|
98
|
+
if err := writeField(w, f); err != nil {
|
|
99
|
+
return requestBody{}, err
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if err := w.Close(); err != nil {
|
|
103
|
+
return requestBody{}, err
|
|
104
|
+
}
|
|
105
|
+
return rawBody(buf.Bytes(), w.FormDataContentType()), nil
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
func writeField(w *multipart.Writer, f multipartField) error {
|
|
109
|
+
if f.file == nil {
|
|
110
|
+
return w.WriteField(f.name, f.value)
|
|
111
|
+
}
|
|
112
|
+
filename := f.file.Filename
|
|
113
|
+
if filename == "" {
|
|
114
|
+
filename = f.name
|
|
115
|
+
}
|
|
116
|
+
ct := f.file.ContentType
|
|
117
|
+
if ct == "" {
|
|
118
|
+
ct = "application/octet-stream"
|
|
119
|
+
}
|
|
120
|
+
h := make(textproto.MIMEHeader)
|
|
121
|
+
h.Set("Content-Disposition", "form-data; name="+strconv.Quote(f.name)+"; filename="+strconv.Quote(filename))
|
|
122
|
+
h.Set("Content-Type", ct)
|
|
123
|
+
part, err := w.CreatePart(h)
|
|
124
|
+
if err != nil || f.file.Data == nil {
|
|
125
|
+
return err
|
|
126
|
+
}
|
|
127
|
+
_, err = io.Copy(part, f.file.Data)
|
|
128
|
+
return err
|
|
129
|
+
}
|