@workerstack/clients 0.0.0-stage → 1.0.0-rc.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +619 -2
- package/bin/honey-clients.js +94 -0
- package/dist/cli.d.ts +102 -0
- package/dist/cli.js +190 -0
- package/dist/emit/cli/channels.d.ts +73 -0
- package/dist/emit/cli/channels.js +197 -0
- package/dist/emit/cli/commands.d.ts +27 -0
- package/dist/emit/cli/commands.js +187 -0
- package/dist/emit/cli/discovery.d.ts +35 -0
- package/dist/emit/cli/discovery.js +202 -0
- package/dist/emit/cli/flags.d.ts +59 -0
- package/dist/emit/cli/flags.js +186 -0
- package/dist/emit/cli/index.d.ts +1 -0
- package/dist/emit/cli/index.js +1 -0
- package/dist/emit/cli/install.d.ts +37 -0
- package/dist/emit/cli/install.js +88 -0
- package/dist/emit/cli/layout.d.ts +23 -0
- package/dist/emit/cli/layout.js +118 -0
- package/dist/emit/cli/module.d.ts +30 -0
- package/dist/emit/cli/module.js +186 -0
- package/dist/emit/cli/release.d.ts +40 -0
- package/dist/emit/cli/release.js +183 -0
- package/dist/emit/cli/skills.d.ts +11 -0
- package/dist/emit/cli/skills.js +56 -0
- package/dist/emit/csharp/errors.d.ts +7 -0
- package/dist/emit/csharp/errors.js +69 -0
- package/dist/emit/csharp/index.d.ts +1 -0
- package/dist/emit/csharp/index.js +1 -0
- package/dist/emit/csharp/json.d.ts +13 -0
- package/dist/emit/csharp/json.js +113 -0
- package/dist/emit/csharp/realtime.d.ts +10 -0
- package/dist/emit/csharp/realtime.js +33 -0
- package/dist/emit/csharp/sdk-answer.d.ts +48 -0
- package/dist/emit/csharp/sdk-answer.js +85 -0
- package/dist/emit/csharp/sdk-body.d.ts +10 -0
- package/dist/emit/csharp/sdk-body.js +87 -0
- package/dist/emit/csharp/sdk-client.d.ts +32 -0
- package/dist/emit/csharp/sdk-client.js +177 -0
- package/dist/emit/csharp/sdk-csproj.d.ts +36 -0
- package/dist/emit/csharp/sdk-csproj.js +136 -0
- package/dist/emit/csharp/sdk-doc.d.ts +12 -0
- package/dist/emit/csharp/sdk-doc.js +35 -0
- package/dist/emit/csharp/sdk-method.d.ts +26 -0
- package/dist/emit/csharp/sdk-method.js +187 -0
- package/dist/emit/csharp/sdk-plan.d.ts +38 -0
- package/dist/emit/csharp/sdk-plan.js +1 -0
- package/dist/emit/csharp/sdk.d.ts +40 -0
- package/dist/emit/csharp/sdk.js +105 -0
- package/dist/emit/csharp/sse.d.ts +18 -0
- package/dist/emit/csharp/sse.js +29 -0
- package/dist/emit/csharp/transport.d.ts +11 -0
- package/dist/emit/csharp/transport.js +67 -0
- package/dist/emit/csharp/types-enum.d.ts +19 -0
- package/dist/emit/csharp/types-enum.js +63 -0
- package/dist/emit/csharp/types-names.d.ts +33 -0
- package/dist/emit/csharp/types-names.js +182 -0
- package/dist/emit/csharp/types-record.d.ts +25 -0
- package/dist/emit/csharp/types-record.js +65 -0
- package/dist/emit/csharp/types-union.d.ts +27 -0
- package/dist/emit/csharp/types-union.js +113 -0
- package/dist/emit/csharp/types.d.ts +36 -0
- package/dist/emit/csharp/types.js +126 -0
- package/dist/emit/csharp/ws.d.ts +20 -0
- package/dist/emit/csharp/ws.js +14 -0
- package/dist/emit/go/errors.d.ts +7 -0
- package/dist/emit/go/errors.js +44 -0
- package/dist/emit/go/http.d.ts +11 -0
- package/dist/emit/go/http.js +50 -0
- package/dist/emit/go/index.d.ts +1 -0
- package/dist/emit/go/index.js +1 -0
- package/dist/emit/go/module-path.d.ts +2 -0
- package/dist/emit/go/module-path.js +27 -0
- package/dist/emit/go/sdk-answer.d.ts +28 -0
- package/dist/emit/go/sdk-answer.js +41 -0
- package/dist/emit/go/sdk-body.d.ts +24 -0
- package/dist/emit/go/sdk-body.js +76 -0
- package/dist/emit/go/sdk-client.d.ts +29 -0
- package/dist/emit/go/sdk-client.js +141 -0
- package/dist/emit/go/sdk-method.d.ts +68 -0
- package/dist/emit/go/sdk-method.js +172 -0
- package/dist/emit/go/sdk-mirror.d.ts +23 -0
- package/dist/emit/go/sdk-mirror.js +97 -0
- package/dist/emit/go/sdk-opts.d.ts +55 -0
- package/dist/emit/go/sdk-opts.js +100 -0
- package/dist/emit/go/sdk.d.ts +26 -0
- package/dist/emit/go/sdk.js +111 -0
- package/dist/emit/go/sse.d.ts +16 -0
- package/dist/emit/go/sse.js +26 -0
- package/dist/emit/go/types-codec.d.ts +15 -0
- package/dist/emit/go/types-codec.js +171 -0
- package/dist/emit/go/types-names.d.ts +14 -0
- package/dist/emit/go/types-names.js +64 -0
- package/dist/emit/go/types-struct.d.ts +29 -0
- package/dist/emit/go/types-struct.js +65 -0
- package/dist/emit/go/types-union.d.ts +17 -0
- package/dist/emit/go/types-union.js +84 -0
- package/dist/emit/go/types.d.ts +32 -0
- package/dist/emit/go/types.js +177 -0
- package/dist/emit/go/ws.d.ts +12 -0
- package/dist/emit/go/ws.js +70 -0
- package/dist/emit/java/gradle.d.ts +57 -0
- package/dist/emit/java/gradle.js +221 -0
- package/dist/emit/java/index.d.ts +2 -0
- package/dist/emit/java/index.js +2 -0
- package/dist/emit/java/json.d.ts +13 -0
- package/dist/emit/java/json.js +84 -0
- package/dist/emit/java/layout-ast.d.ts +146 -0
- package/dist/emit/java/layout-ast.js +102 -0
- package/dist/emit/java/layout-decl.d.ts +20 -0
- package/dist/emit/java/layout-decl.js +155 -0
- package/dist/emit/java/layout-doc.d.ts +55 -0
- package/dist/emit/java/layout-doc.js +166 -0
- package/dist/emit/java/layout-dot.d.ts +18 -0
- package/dist/emit/java/layout-dot.js +127 -0
- package/dist/emit/java/layout-strings.d.ts +8 -0
- package/dist/emit/java/layout-strings.js +76 -0
- package/dist/emit/java/layout-types.d.ts +11 -0
- package/dist/emit/java/layout-types.js +95 -0
- package/dist/emit/java/layout-visitor.d.ts +38 -0
- package/dist/emit/java/layout-visitor.js +232 -0
- package/dist/emit/java/layout.d.ts +61 -0
- package/dist/emit/java/layout.js +121 -0
- package/dist/emit/java/models-enum.d.ts +17 -0
- package/dist/emit/java/models-enum.js +51 -0
- package/dist/emit/java/models-names.d.ts +29 -0
- package/dist/emit/java/models-names.js +97 -0
- package/dist/emit/java/models-record.d.ts +24 -0
- package/dist/emit/java/models-record.js +79 -0
- package/dist/emit/java/models-union.d.ts +27 -0
- package/dist/emit/java/models-union.js +86 -0
- package/dist/emit/java/models.d.ts +28 -0
- package/dist/emit/java/models.js +118 -0
- package/dist/emit/java/realtime.d.ts +50 -0
- package/dist/emit/java/realtime.js +69 -0
- package/dist/emit/java/sdk-client.d.ts +66 -0
- package/dist/emit/java/sdk-client.js +207 -0
- package/dist/emit/java/sdk-decl.d.ts +11 -0
- package/dist/emit/java/sdk-decl.js +63 -0
- package/dist/emit/java/sdk-errors.d.ts +13 -0
- package/dist/emit/java/sdk-errors.js +141 -0
- package/dist/emit/java/sdk-headers.d.ts +12 -0
- package/dist/emit/java/sdk-headers.js +74 -0
- package/dist/emit/java/sdk-mirror.d.ts +14 -0
- package/dist/emit/java/sdk-mirror.js +107 -0
- package/dist/emit/java/sdk-models.d.ts +16 -0
- package/dist/emit/java/sdk-models.js +68 -0
- package/dist/emit/java/sdk-op.d.ts +57 -0
- package/dist/emit/java/sdk-op.js +216 -0
- package/dist/emit/java/sdk-params.d.ts +38 -0
- package/dist/emit/java/sdk-params.js +133 -0
- package/dist/emit/java/sdk-plan.d.ts +52 -0
- package/dist/emit/java/sdk-plan.js +1 -0
- package/dist/emit/java/sdk-record.d.ts +16 -0
- package/dist/emit/java/sdk-record.js +99 -0
- package/dist/emit/java/sdk.d.ts +49 -0
- package/dist/emit/java/sdk.js +216 -0
- package/dist/emit/java/sse.d.ts +35 -0
- package/dist/emit/java/sse.js +57 -0
- package/dist/emit/java/ws.d.ts +27 -0
- package/dist/emit/java/ws.js +31 -0
- package/dist/emit/mcp/annotations.d.ts +15 -0
- package/dist/emit/mcp/annotations.js +15 -0
- package/dist/emit/mcp/files.d.ts +18 -0
- package/dist/emit/mcp/files.js +42 -0
- package/dist/emit/mcp/index.d.ts +3 -0
- package/dist/emit/mcp/index.js +3 -0
- package/dist/emit/mcp/literal.d.ts +2 -0
- package/dist/emit/mcp/literal.js +33 -0
- package/dist/emit/mcp/mounted.d.ts +21 -0
- package/dist/emit/mcp/mounted.js +89 -0
- package/dist/emit/mcp/output-schema.d.ts +18 -0
- package/dist/emit/mcp/output-schema.js +38 -0
- package/dist/emit/mcp/registry.d.ts +23 -0
- package/dist/emit/mcp/registry.js +83 -0
- package/dist/emit/mcp/runtime.d.ts +10 -0
- package/dist/emit/mcp/runtime.js +47 -0
- package/dist/emit/mcp/schema.d.ts +19 -0
- package/dist/emit/mcp/schema.js +88 -0
- package/dist/emit/mcp/server.d.ts +30 -0
- package/dist/emit/mcp/server.js +246 -0
- package/dist/emit/mcp/tools.d.ts +51 -0
- package/dist/emit/mcp/tools.js +153 -0
- package/dist/emit/python/errors.d.ts +8 -0
- package/dist/emit/python/errors.js +68 -0
- package/dist/emit/python/index.d.ts +1 -0
- package/dist/emit/python/index.js +1 -0
- package/dist/emit/python/realtime.d.ts +10 -0
- package/dist/emit/python/realtime.js +33 -0
- package/dist/emit/python/sdk-answer.d.ts +49 -0
- package/dist/emit/python/sdk-answer.js +89 -0
- package/dist/emit/python/sdk-body.d.ts +11 -0
- package/dist/emit/python/sdk-body.js +40 -0
- package/dist/emit/python/sdk-client.d.ts +36 -0
- package/dist/emit/python/sdk-client.js +163 -0
- package/dist/emit/python/sdk-doc.d.ts +9 -0
- package/dist/emit/python/sdk-doc.js +32 -0
- package/dist/emit/python/sdk-imports.d.ts +14 -0
- package/dist/emit/python/sdk-imports.js +38 -0
- package/dist/emit/python/sdk-method.d.ts +29 -0
- package/dist/emit/python/sdk-method.js +183 -0
- package/dist/emit/python/sdk-plan.d.ts +33 -0
- package/dist/emit/python/sdk-plan.js +1 -0
- package/dist/emit/python/sdk-pyproject.d.ts +27 -0
- package/dist/emit/python/sdk-pyproject.js +103 -0
- package/dist/emit/python/sdk.d.ts +22 -0
- package/dist/emit/python/sdk.js +154 -0
- package/dist/emit/python/sse.d.ts +12 -0
- package/dist/emit/python/sse.js +23 -0
- package/dist/emit/python/transport.d.ts +15 -0
- package/dist/emit/python/transport.js +60 -0
- package/dist/emit/python/types-dict.d.ts +31 -0
- package/dist/emit/python/types-dict.js +45 -0
- package/dist/emit/python/types-names.d.ts +16 -0
- package/dist/emit/python/types-names.js +52 -0
- package/dist/emit/python/types-union.d.ts +32 -0
- package/dist/emit/python/types-union.js +46 -0
- package/dist/emit/python/types.d.ts +36 -0
- package/dist/emit/python/types.js +128 -0
- package/dist/emit/python/ws.d.ts +14 -0
- package/dist/emit/python/ws.js +16 -0
- package/dist/emit/rust/errors.d.ts +7 -0
- package/dist/emit/rust/errors.js +107 -0
- package/dist/emit/rust/http.d.ts +13 -0
- package/dist/emit/rust/http.js +67 -0
- package/dist/emit/rust/index.d.ts +1 -0
- package/dist/emit/rust/index.js +1 -0
- package/dist/emit/rust/realtime.d.ts +11 -0
- package/dist/emit/rust/realtime.js +29 -0
- package/dist/emit/rust/sdk-body.d.ts +19 -0
- package/dist/emit/rust/sdk-body.js +53 -0
- package/dist/emit/rust/sdk-cargo.d.ts +43 -0
- package/dist/emit/rust/sdk-cargo.js +178 -0
- package/dist/emit/rust/sdk-client.d.ts +25 -0
- package/dist/emit/rust/sdk-client.js +108 -0
- package/dist/emit/rust/sdk-method.d.ts +15 -0
- package/dist/emit/rust/sdk-method.js +119 -0
- package/dist/emit/rust/sdk-opts.d.ts +58 -0
- package/dist/emit/rust/sdk-opts.js +117 -0
- package/dist/emit/rust/sdk-plan.d.ts +33 -0
- package/dist/emit/rust/sdk-plan.js +1 -0
- package/dist/emit/rust/sdk.d.ts +23 -0
- package/dist/emit/rust/sdk.js +111 -0
- package/dist/emit/rust/sse.d.ts +19 -0
- package/dist/emit/rust/sse.js +20 -0
- package/dist/emit/rust/types-enum.d.ts +13 -0
- package/dist/emit/rust/types-enum.js +62 -0
- package/dist/emit/rust/types-names.d.ts +19 -0
- package/dist/emit/rust/types-names.js +66 -0
- package/dist/emit/rust/types-struct.d.ts +21 -0
- package/dist/emit/rust/types-struct.js +59 -0
- package/dist/emit/rust/types-union.d.ts +24 -0
- package/dist/emit/rust/types-union.js +97 -0
- package/dist/emit/rust/types.d.ts +34 -0
- package/dist/emit/rust/types.js +105 -0
- package/dist/emit/rust/ws.d.ts +21 -0
- package/dist/emit/rust/ws.js +20 -0
- package/dist/emit/shared/escape.d.ts +55 -0
- package/dist/emit/shared/escape.js +144 -0
- package/dist/emit/shared/format.d.ts +24 -0
- package/dist/emit/shared/format.js +23 -0
- package/dist/emit/shared/gofmt.d.ts +3 -0
- package/dist/emit/shared/gofmt.js +26 -0
- package/dist/emit/shared/lang.d.ts +60 -0
- package/dist/emit/shared/lang.js +233 -0
- package/dist/emit/shared/literals.d.ts +4 -0
- package/dist/emit/shared/literals.js +31 -0
- package/dist/emit/shared/metadata.d.ts +106 -0
- package/dist/emit/shared/metadata.js +130 -0
- package/dist/emit/shared/mirror.d.ts +22 -0
- package/dist/emit/shared/mirror.js +26 -0
- package/dist/emit/shared/ruff.d.ts +3 -0
- package/dist/emit/shared/ruff.js +31 -0
- package/dist/emit/shared/rustfmt.d.ts +3 -0
- package/dist/emit/shared/rustfmt.js +32 -0
- package/dist/emit/shared/status-keys.d.ts +7 -0
- package/dist/emit/shared/status-keys.js +67 -0
- package/dist/emit/shared/type-emitter.d.ts +19 -0
- package/dist/emit/shared/type-emitter.js +100 -0
- package/dist/emit/ts/app-client.d.ts +4 -0
- package/dist/emit/ts/app-client.js +68 -0
- package/dist/emit/ts/http.d.ts +20 -0
- package/dist/emit/ts/http.js +74 -0
- package/dist/emit/ts/package.d.ts +36 -0
- package/dist/emit/ts/package.js +126 -0
- package/dist/emit/ts/route-tree.d.ts +68 -0
- package/dist/emit/ts/route-tree.js +240 -0
- package/dist/emit/ts/sdk-types-preamble.d.ts +14 -0
- package/dist/emit/ts/sdk-types-preamble.js +123 -0
- package/dist/emit/ts/sdk-types.d.ts +13 -0
- package/dist/emit/ts/sdk-types.js +213 -0
- package/dist/emit/ts/sdk.d.ts +21 -0
- package/dist/emit/ts/sdk.js +173 -0
- package/dist/emit/ts/service-map.d.ts +40 -0
- package/dist/emit/ts/service-map.js +171 -0
- package/dist/emit/ts/tanstack-query.d.ts +12 -0
- package/dist/emit/ts/tanstack-query.js +156 -0
- package/dist/emit/ts/type-gen.d.ts +26 -0
- package/dist/emit/ts/type-gen.js +255 -0
- package/dist/emit/ts/webhooks.d.ts +19 -0
- package/dist/emit/ts/webhooks.js +81 -0
- package/dist/extract/chain.d.ts +34 -0
- package/dist/extract/chain.js +84 -0
- package/dist/extract/extract.d.ts +41 -0
- package/dist/extract/extract.js +191 -0
- package/dist/extract/serialize.d.ts +34 -0
- package/dist/extract/serialize.js +295 -0
- package/dist/extract/walk.d.ts +47 -0
- package/dist/extract/walk.js +109 -0
- package/dist/gen/args.d.ts +28 -0
- package/dist/gen/args.js +133 -0
- package/dist/gen/formatters.d.ts +62 -0
- package/dist/gen/formatters.js +146 -0
- package/dist/gen/process.d.ts +13 -0
- package/dist/gen/process.js +35 -0
- package/dist/gen/shipped.d.ts +17 -0
- package/dist/gen/shipped.js +55 -0
- package/dist/gen/targets.d.ts +93 -0
- package/dist/gen/targets.js +171 -0
- package/dist/gen/write.d.ts +33 -0
- package/dist/gen/write.js +118 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +15 -0
- package/dist/ir/build.d.ts +37 -0
- package/dist/ir/build.js +152 -0
- package/dist/ir/load.d.ts +11 -0
- package/dist/ir/load.js +112 -0
- package/dist/ir/model.d.ts +206 -0
- package/dist/ir/model.js +5 -0
- package/dist/ir/resolve-refs.d.ts +11 -0
- package/dist/ir/resolve-refs.js +66 -0
- package/dist/ir/resource-tree.d.ts +9 -0
- package/dist/ir/resource-tree.js +53 -0
- package/dist/ir/route-tree-intern.d.ts +18 -0
- package/dist/ir/route-tree-intern.js +174 -0
- package/dist/ir/schema.d.ts +11 -0
- package/dist/ir/schema.js +192 -0
- package/dist/ir/sdk-model.d.ts +86 -0
- package/dist/ir/sdk-model.js +204 -0
- package/dist/ir/slots.d.ts +42 -0
- package/dist/ir/slots.js +245 -0
- package/dist/runtime/cli/body.go +176 -0
- package/dist/runtime/cli/config.go +243 -0
- package/dist/runtime/cli/discovery.go +147 -0
- package/dist/runtime/cli/format.go +174 -0
- package/dist/runtime/cli/log.go +117 -0
- package/dist/runtime/cli/output.go +247 -0
- package/dist/runtime/cli/params.go +197 -0
- package/dist/runtime/cli/run.go +226 -0
- package/dist/runtime/cli/socket.go +60 -0
- package/dist/runtime/cli/stream.go +217 -0
- package/dist/runtime/cli/target.go +117 -0
- package/dist/runtime/csharp/Adapters.cs +183 -0
- package/dist/runtime/csharp/Auth.cs +56 -0
- package/dist/runtime/csharp/Body.cs +135 -0
- package/dist/runtime/csharp/Config.cs +161 -0
- package/dist/runtime/csharp/Envelope.cs +149 -0
- package/dist/runtime/csharp/Errors.cs +194 -0
- package/dist/runtime/csharp/Events.cs +155 -0
- package/dist/runtime/csharp/Exchange.cs +247 -0
- package/dist/runtime/csharp/Handler.cs +103 -0
- package/dist/runtime/csharp/Hooks.cs +128 -0
- package/dist/runtime/csharp/Invalidation.cs +102 -0
- package/dist/runtime/csharp/Json.cs +144 -0
- package/dist/runtime/csharp/Log.cs +48 -0
- package/dist/runtime/csharp/Operation.cs +33 -0
- package/dist/runtime/csharp/Path.cs +65 -0
- package/dist/runtime/csharp/Query.cs +72 -0
- package/dist/runtime/csharp/Realtime.cs +118 -0
- package/dist/runtime/csharp/RealtimeLoop.cs +236 -0
- package/dist/runtime/csharp/Redirect.cs +53 -0
- package/dist/runtime/csharp/Result.cs +57 -0
- package/dist/runtime/csharp/Sse.cs +122 -0
- package/dist/runtime/csharp/Stale.cs +151 -0
- package/dist/runtime/csharp/Transport.cs +143 -0
- package/dist/runtime/csharp/TransportLongPoll.cs +63 -0
- package/dist/runtime/csharp/TransportSse.cs +54 -0
- package/dist/runtime/csharp/TransportWs.cs +40 -0
- package/dist/runtime/csharp/Wire.cs +109 -0
- package/dist/runtime/csharp/Ws.cs +300 -0
- package/dist/runtime/csharp/WsDial.cs +127 -0
- package/dist/runtime/go/auth.go +127 -0
- package/dist/runtime/go/body.go +129 -0
- package/dist/runtime/go/config.go +75 -0
- package/dist/runtime/go/errors.go +185 -0
- package/dist/runtime/go/export.go +37 -0
- package/dist/runtime/go/hooks.go +53 -0
- package/dist/runtime/go/invalidation.go +112 -0
- package/dist/runtime/go/log.go +92 -0
- package/dist/runtime/go/nullable.go +64 -0
- package/dist/runtime/go/options.go +118 -0
- package/dist/runtime/go/path.go +156 -0
- package/dist/runtime/go/query.go +147 -0
- package/dist/runtime/go/realtime.go +239 -0
- package/dist/runtime/go/realtime_loop.go +208 -0
- package/dist/runtime/go/redirect.go +124 -0
- package/dist/runtime/go/request.go +222 -0
- package/dist/runtime/go/result.go +86 -0
- package/dist/runtime/go/sse.go +186 -0
- package/dist/runtime/go/stale.go +229 -0
- package/dist/runtime/go/stream.go +105 -0
- package/dist/runtime/go/transport.go +242 -0
- package/dist/runtime/go/transport_longpoll.go +121 -0
- package/dist/runtime/go/transport_sse.go +175 -0
- package/dist/runtime/go/ws.go +205 -0
- package/dist/runtime/java/Answer.java +107 -0
- package/dist/runtime/java/ApiException.java +110 -0
- package/dist/runtime/java/BinaryBody.java +36 -0
- package/dist/runtime/java/Body.java +105 -0
- package/dist/runtime/java/Call.java +23 -0
- package/dist/runtime/java/CallLog.java +51 -0
- package/dist/runtime/java/ClientConfig.java +233 -0
- package/dist/runtime/java/ConnectionState.java +12 -0
- package/dist/runtime/java/Credential.java +58 -0
- package/dist/runtime/java/Deadline.java +38 -0
- package/dist/runtime/java/Decode.java +181 -0
- package/dist/runtime/java/Envelope.java +141 -0
- package/dist/runtime/java/ErrorEnvelope.java +23 -0
- package/dist/runtime/java/EventStream.java +129 -0
- package/dist/runtime/java/Exchange.java +62 -0
- package/dist/runtime/java/FilePart.java +5 -0
- package/dist/runtime/java/Flight.java +306 -0
- package/dist/runtime/java/HoneyException.java +14 -0
- package/dist/runtime/java/Hooks.java +47 -0
- package/dist/runtime/java/Hops.java +133 -0
- package/dist/runtime/java/InvalidationConfig.java +73 -0
- package/dist/runtime/java/Json.java +23 -0
- package/dist/runtime/java/Keepalive.java +60 -0
- package/dist/runtime/java/LogEntry.java +14 -0
- package/dist/runtime/java/LongPollAdapter.java +68 -0
- package/dist/runtime/java/Operation.java +21 -0
- package/dist/runtime/java/Opt.java +121 -0
- package/dist/runtime/java/Pump.java +160 -0
- package/dist/runtime/java/RawResponse.java +48 -0
- package/dist/runtime/java/Realtime.java +152 -0
- package/dist/runtime/java/RealtimeLoop.java +371 -0
- package/dist/runtime/java/RedirectPolicy.java +13 -0
- package/dist/runtime/java/Redirects.java +126 -0
- package/dist/runtime/java/RequestContext.java +78 -0
- package/dist/runtime/java/RequestHook.java +9 -0
- package/dist/runtime/java/RequestOptions.java +91 -0
- package/dist/runtime/java/ResponseContext.java +70 -0
- package/dist/runtime/java/ResponseHook.java +12 -0
- package/dist/runtime/java/Result.java +32 -0
- package/dist/runtime/java/ResumableConnection.java +165 -0
- package/dist/runtime/java/SdkException.java +11 -0
- package/dist/runtime/java/Socket.java +301 -0
- package/dist/runtime/java/Sse.java +171 -0
- package/dist/runtime/java/SseAdapter.java +61 -0
- package/dist/runtime/java/SseEvent.java +10 -0
- package/dist/runtime/java/StaleMeta.java +16 -0
- package/dist/runtime/java/StaleTracker.java +287 -0
- package/dist/runtime/java/Transport.java +16 -0
- package/dist/runtime/java/TransportAdapter.java +14 -0
- package/dist/runtime/java/TransportConnection.java +15 -0
- package/dist/runtime/java/TransportKind.java +12 -0
- package/dist/runtime/java/TransportMessage.java +9 -0
- package/dist/runtime/java/TransportOptions.java +138 -0
- package/dist/runtime/java/TypedWebSocket.java +83 -0
- package/dist/runtime/java/UrlPath.java +49 -0
- package/dist/runtime/java/UrlQuery.java +99 -0
- package/dist/runtime/java/WsAdapter.java +52 -0
- package/dist/runtime/java/WsClose.java +47 -0
- package/dist/runtime/java/WsDial.java +148 -0
- package/dist/runtime/java/WsMessage.java +18 -0
- package/dist/runtime/mcp/call.ts +167 -0
- package/dist/runtime/mcp/files.ts +183 -0
- package/dist/runtime/mcp/guard.ts +176 -0
- package/dist/runtime/mcp/http.ts +159 -0
- package/dist/runtime/mcp/jsonrpc.ts +50 -0
- package/dist/runtime/mcp/listen.ts +76 -0
- package/dist/runtime/mcp/mount.ts +123 -0
- package/dist/runtime/mcp/protocol.ts +219 -0
- package/dist/runtime/mcp/reader.ts +57 -0
- package/dist/runtime/mcp/result.ts +85 -0
- package/dist/runtime/mcp/stdio.ts +79 -0
- package/dist/runtime/mcp/stream.ts +62 -0
- package/dist/runtime/python/__init__.py +2 -0
- package/dist/runtime/python/auth.py +67 -0
- package/dist/runtime/python/body.py +83 -0
- package/dist/runtime/python/config.py +139 -0
- package/dist/runtime/python/errors.py +213 -0
- package/dist/runtime/python/events.py +152 -0
- package/dist/runtime/python/exchange.py +298 -0
- package/dist/runtime/python/hooks.py +86 -0
- package/dist/runtime/python/invalidation.py +57 -0
- package/dist/runtime/python/log.py +60 -0
- package/dist/runtime/python/operation.py +25 -0
- package/dist/runtime/python/path.py +41 -0
- package/dist/runtime/python/query.py +48 -0
- package/dist/runtime/python/realtime.py +244 -0
- package/dist/runtime/python/redirect.py +93 -0
- package/dist/runtime/python/result.py +58 -0
- package/dist/runtime/python/send_async.py +189 -0
- package/dist/runtime/python/send_sync.py +105 -0
- package/dist/runtime/python/sse.py +81 -0
- package/dist/runtime/python/stale.py +94 -0
- package/dist/runtime/python/transport.py +157 -0
- package/dist/runtime/python/transport_longpoll.py +60 -0
- package/dist/runtime/python/transport_sse.py +60 -0
- package/dist/runtime/python/transport_ws.py +57 -0
- package/dist/runtime/python/ws.py +276 -0
- package/dist/runtime/rust/Cargo.lock +1763 -0
- package/dist/runtime/rust/answer.rs +120 -0
- package/dist/runtime/rust/auth.rs +80 -0
- package/dist/runtime/rust/body.rs +150 -0
- package/dist/runtime/rust/call.rs +200 -0
- package/dist/runtime/rust/config.rs +254 -0
- package/dist/runtime/rust/envelope.rs +84 -0
- package/dist/runtime/rust/errors.rs +235 -0
- package/dist/runtime/rust/events.rs +177 -0
- package/dist/runtime/rust/exchange.rs +287 -0
- package/dist/runtime/rust/hooks.rs +63 -0
- package/dist/runtime/rust/invalidation.rs +84 -0
- package/dist/runtime/rust/log.rs +88 -0
- package/dist/runtime/rust/nullable.rs +13 -0
- package/dist/runtime/rust/path.rs +83 -0
- package/dist/runtime/rust/query.rs +84 -0
- package/dist/runtime/rust/realtime.rs +182 -0
- package/dist/runtime/rust/realtime_loop.rs +177 -0
- package/dist/runtime/rust/redirect.rs +121 -0
- package/dist/runtime/rust/request.rs +178 -0
- package/dist/runtime/rust/result.rs +101 -0
- package/dist/runtime/rust/sse.rs +104 -0
- package/dist/runtime/rust/stale.rs +209 -0
- package/dist/runtime/rust/transport.rs +221 -0
- package/dist/runtime/rust/transport_longpoll.rs +108 -0
- package/dist/runtime/rust/transport_sse.rs +91 -0
- package/dist/runtime/rust/transport_ws.rs +75 -0
- package/dist/runtime/rust/ws.rs +322 -0
- package/dist/runtime/ts/app-types.ts +200 -0
- package/dist/runtime/ts/app.ts +104 -0
- package/dist/runtime/ts/config.ts +124 -0
- package/dist/runtime/ts/defaults.ts +48 -0
- package/dist/runtime/ts/error.ts +113 -0
- package/dist/runtime/ts/hooks.ts +92 -0
- package/dist/runtime/ts/http.ts +228 -0
- package/dist/runtime/ts/media-type.ts +36 -0
- package/dist/runtime/ts/path.ts +152 -0
- package/dist/runtime/ts/realtime-connection.ts +296 -0
- package/dist/runtime/ts/realtime-transports.ts +149 -0
- package/dist/runtime/ts/realtime.ts +293 -0
- package/dist/runtime/ts/redirect-policy.ts +17 -0
- package/dist/runtime/ts/redirects.ts +74 -0
- package/dist/runtime/ts/request.ts +239 -0
- package/dist/runtime/ts/response.ts +219 -0
- package/dist/runtime/ts/sdk-realtime.ts +10 -0
- package/dist/runtime/ts/sdk-sse.ts +55 -0
- package/dist/runtime/ts/sdk-ws.ts +21 -0
- package/dist/runtime/ts/sdk.ts +242 -0
- package/dist/runtime/ts/sse.ts +175 -0
- package/dist/runtime/ts/stale.ts +137 -0
- package/dist/runtime/ts/stream.ts +87 -0
- package/dist/runtime/ts/webhook.ts +116 -0
- package/dist/runtime/ts/ws.ts +155 -0
- package/dist/runtime/ts-tanstack-query/invalidate.ts +152 -0
- package/dist/runtime/ts-tanstack-query/query.ts +261 -0
- package/package.json +84 -5
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
using System;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using System.Globalization;
|
|
5
|
+
using System.Text;
|
|
6
|
+
using System.Text.Json;
|
|
7
|
+
|
|
8
|
+
namespace Honey.Runtime;
|
|
9
|
+
|
|
10
|
+
/// <summary>
|
|
11
|
+
/// honey's error envelope, read from an error body's JSON object (empty for any other body): each member it names
|
|
12
|
+
/// when the server sent it with its type, and every other member, a mistyped one included, in <see cref="Extra"/>.
|
|
13
|
+
/// </summary>
|
|
14
|
+
public sealed record ErrorEnvelope(
|
|
15
|
+
int? Status,
|
|
16
|
+
string? ErrorKey,
|
|
17
|
+
string? StatusKey,
|
|
18
|
+
string? Message,
|
|
19
|
+
IReadOnlyDictionary<string, IReadOnlyList<FieldError>> Fields,
|
|
20
|
+
IReadOnlyDictionary<string, JsonElement> Extra);
|
|
21
|
+
|
|
22
|
+
/// <summary>One field's error in an envelope's <c>fields</c>.</summary>
|
|
23
|
+
public sealed record FieldError(string ErrorKey, string Message, string Path);
|
|
24
|
+
|
|
25
|
+
internal sealed record Failure(
|
|
26
|
+
int Status,
|
|
27
|
+
IReadOnlyDictionary<string, string> Headers,
|
|
28
|
+
byte[] Body,
|
|
29
|
+
string? Key,
|
|
30
|
+
ErrorEnvelope Envelope,
|
|
31
|
+
string Detail,
|
|
32
|
+
JsonSerializerOptions Json);
|
|
33
|
+
|
|
34
|
+
internal static class Envelopes
|
|
35
|
+
{
|
|
36
|
+
private const int MaxDetail = 512;
|
|
37
|
+
|
|
38
|
+
private static readonly ErrorEnvelope Empty = new(null, null, null, null,
|
|
39
|
+
new Dictionary<string, IReadOnlyList<FieldError>>(), new Dictionary<string, JsonElement>());
|
|
40
|
+
|
|
41
|
+
public static Failure Of(int status, IReadOnlyDictionary<string, string> headers, byte[] body, JsonSerializerOptions json)
|
|
42
|
+
{
|
|
43
|
+
var (envelope, _) = Parse(body);
|
|
44
|
+
var text = envelope.Message ?? Encoding.UTF8.GetString(body);
|
|
45
|
+
return new Failure(status, headers, body, envelope.ErrorKey, envelope, Sanitized(text), json);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public static (ErrorEnvelope Envelope, bool Json) Parse(byte[] body)
|
|
49
|
+
{
|
|
50
|
+
try
|
|
51
|
+
{
|
|
52
|
+
using var document = JsonDocument.Parse(body);
|
|
53
|
+
return (document.RootElement.ValueKind == JsonValueKind.Object ? Read(document.RootElement) : Empty, true);
|
|
54
|
+
}
|
|
55
|
+
catch (JsonException)
|
|
56
|
+
{
|
|
57
|
+
return (Empty, false);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private static ErrorEnvelope Read(JsonElement root)
|
|
62
|
+
{
|
|
63
|
+
int? status = null;
|
|
64
|
+
string? errorKey = null, statusKey = null, message = null;
|
|
65
|
+
var fields = Empty.Fields;
|
|
66
|
+
var extra = new Dictionary<string, JsonElement>();
|
|
67
|
+
foreach (var member in root.EnumerateObject())
|
|
68
|
+
{
|
|
69
|
+
var value = member.Value;
|
|
70
|
+
var text = value.ValueKind == JsonValueKind.String ? value.GetString() : null;
|
|
71
|
+
switch (member.Name)
|
|
72
|
+
{
|
|
73
|
+
case "status" when value.ValueKind == JsonValueKind.Number && value.TryGetInt32(out var code):
|
|
74
|
+
status = code;
|
|
75
|
+
break;
|
|
76
|
+
case "error_key" when text is not null:
|
|
77
|
+
errorKey = text;
|
|
78
|
+
break;
|
|
79
|
+
case "status_key" when text is not null:
|
|
80
|
+
statusKey = text;
|
|
81
|
+
break;
|
|
82
|
+
case "message" when text is not null:
|
|
83
|
+
message = text;
|
|
84
|
+
break;
|
|
85
|
+
case "fields" when FieldsOf(value) is { } read:
|
|
86
|
+
fields = read;
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
extra[member.Name] = value.Clone();
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return new ErrorEnvelope(status, errorKey, statusKey, message, fields, extra);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private static Dictionary<string, IReadOnlyList<FieldError>>? FieldsOf(JsonElement value)
|
|
97
|
+
{
|
|
98
|
+
if (value.ValueKind != JsonValueKind.Object)
|
|
99
|
+
{
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
var fields = new Dictionary<string, IReadOnlyList<FieldError>>();
|
|
103
|
+
foreach (var field in value.EnumerateObject())
|
|
104
|
+
{
|
|
105
|
+
if (field.Value.ValueKind != JsonValueKind.Array)
|
|
106
|
+
{
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
var errors = new List<FieldError>();
|
|
110
|
+
foreach (var item in field.Value.EnumerateArray())
|
|
111
|
+
{
|
|
112
|
+
if (item.ValueKind != JsonValueKind.Object || TextOf(item, "error_key") is not { } key
|
|
113
|
+
|| TextOf(item, "message") is not { } text || TextOf(item, "path") is not { } path)
|
|
114
|
+
{
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
errors.Add(new FieldError(key, text, path));
|
|
118
|
+
}
|
|
119
|
+
fields[field.Name] = errors;
|
|
120
|
+
}
|
|
121
|
+
return fields;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private static string? TextOf(JsonElement item, string name) =>
|
|
125
|
+
item.TryGetProperty(name, out var value) && value.ValueKind == JsonValueKind.String ? value.GetString() : null;
|
|
126
|
+
|
|
127
|
+
public static string Sanitized(string text)
|
|
128
|
+
{
|
|
129
|
+
var kept = new StringBuilder();
|
|
130
|
+
var count = 0;
|
|
131
|
+
foreach (var rune in text.EnumerateRunes())
|
|
132
|
+
{
|
|
133
|
+
if (rune.Value == 0xFFFD || IsOther(Rune.GetUnicodeCategory(rune)))
|
|
134
|
+
{
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (count == MaxDetail)
|
|
138
|
+
{
|
|
139
|
+
return kept.Append('…').ToString();
|
|
140
|
+
}
|
|
141
|
+
kept.Append(rune.ToString());
|
|
142
|
+
count++;
|
|
143
|
+
}
|
|
144
|
+
return kept.ToString();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private static bool IsOther(UnicodeCategory category) => category is UnicodeCategory.Control or UnicodeCategory.Format
|
|
148
|
+
or UnicodeCategory.Surrogate or UnicodeCategory.PrivateUse or UnicodeCategory.OtherNotAssigned;
|
|
149
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
using System;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using System.Text.Json;
|
|
5
|
+
using System.Text.Json.Serialization.Metadata;
|
|
6
|
+
|
|
7
|
+
namespace Honey.Runtime;
|
|
8
|
+
|
|
9
|
+
/// <summary>Every error the SDK throws; the caller's own cancellation is an OperationCanceledException instead.</summary>
|
|
10
|
+
public abstract class HoneyException : Exception
|
|
11
|
+
{
|
|
12
|
+
private protected HoneyException(string message, Exception? inner = null)
|
|
13
|
+
: base(message, inner)
|
|
14
|
+
{
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// <summary>A client or call configured in a way it cannot send: no absolute base URL, a header value with a line break, a handler it cannot install.</summary>
|
|
19
|
+
public sealed class ConfigException(string message) : HoneyException(message);
|
|
20
|
+
|
|
21
|
+
/// <summary>A path param that is empty, <c>.</c> or <c>..</c>: nothing is sent.</summary>
|
|
22
|
+
public sealed class PathParamException(string message) : HoneyException(message);
|
|
23
|
+
|
|
24
|
+
/// <summary>No answer: the connection failed or broke, or a realtime dial's answer ran past the largest the client reads.</summary>
|
|
25
|
+
public sealed class ApiConnectionException(string message, Exception? inner = null) : HoneyException(message, inner);
|
|
26
|
+
|
|
27
|
+
/// <summary>The call ran past its timeout.</summary>
|
|
28
|
+
public sealed class ApiTimeoutException(string message, Exception inner) : HoneyException(message, inner);
|
|
29
|
+
|
|
30
|
+
/// <summary>An answer the call does not return: an error status or a 2xx that does not decode; a <c>client.Safe</c> Result's Err.</summary>
|
|
31
|
+
public abstract class SdkException : HoneyException
|
|
32
|
+
{
|
|
33
|
+
private protected SdkException(string message, Exception? inner = null)
|
|
34
|
+
: base(message, inner)
|
|
35
|
+
{
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// <summary>An answer that does not decode as the declared type, or a 2xx past the cap; the JSON error, if any, is the inner exception.</summary>
|
|
40
|
+
public sealed class DecodeException(string message, Exception? inner = null) : SdkException(message, inner);
|
|
41
|
+
|
|
42
|
+
/// <summary>A hook or <c>OnAuthExpired</c> threw; what it threw is the inner exception.</summary>
|
|
43
|
+
public sealed class HookException(string message, Exception? inner = null) : HoneyException(message, inner);
|
|
44
|
+
|
|
45
|
+
/// <summary>
|
|
46
|
+
/// A status outside 2xx: one class per common status, <see cref="UnexpectedStatusException"/> for the rest. Its
|
|
47
|
+
/// message is <c>HTTP <status>: <Detail></c>, or <c>HTTP <status></c> without a detail.
|
|
48
|
+
/// </summary>
|
|
49
|
+
public abstract class ApiStatusException : SdkException
|
|
50
|
+
{
|
|
51
|
+
private readonly JsonSerializerOptions _json;
|
|
52
|
+
|
|
53
|
+
private protected ApiStatusException(Failure failure)
|
|
54
|
+
: base(failure.Detail.Length > 0 ? $"HTTP {failure.Status}: {failure.Detail}" : $"HTTP {failure.Status}")
|
|
55
|
+
{
|
|
56
|
+
Status = failure.Status;
|
|
57
|
+
Headers = failure.Headers;
|
|
58
|
+
Body = failure.Body;
|
|
59
|
+
Key = failure.Key;
|
|
60
|
+
Envelope = failure.Envelope;
|
|
61
|
+
Detail = failure.Detail;
|
|
62
|
+
_json = failure.Json;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// <summary>The HTTP status.</summary>
|
|
66
|
+
public int Status { get; }
|
|
67
|
+
|
|
68
|
+
/// <summary>Each header by lower-case name.</summary>
|
|
69
|
+
public IReadOnlyDictionary<string, string> Headers { get; }
|
|
70
|
+
|
|
71
|
+
/// <summary>The body as received.</summary>
|
|
72
|
+
public byte[] Body { get; }
|
|
73
|
+
|
|
74
|
+
/// <summary>The body's <c>error_key</c> as the server sent it: one of the API's <c>ErrorKey</c> constants, else its own string; null without one.</summary>
|
|
75
|
+
public string? Key { get; }
|
|
76
|
+
|
|
77
|
+
/// <summary>The body's envelope: empty for a body that is no JSON object.</summary>
|
|
78
|
+
public ErrorEnvelope Envelope { get; }
|
|
79
|
+
|
|
80
|
+
/// <summary>The envelope's message, else the body's text: control and format characters dropped, cut at 512 characters.</summary>
|
|
81
|
+
public string Detail { get; }
|
|
82
|
+
|
|
83
|
+
/// <summary>The body as <typeparamref name="T"/>, a type the SDK declares; a DecodeException when it is not one.</summary>
|
|
84
|
+
public T DecodeBody<T>()
|
|
85
|
+
{
|
|
86
|
+
JsonTypeInfo<T> info;
|
|
87
|
+
try
|
|
88
|
+
{
|
|
89
|
+
info = (JsonTypeInfo<T>)_json.GetTypeInfo(typeof(T));
|
|
90
|
+
}
|
|
91
|
+
catch (NotSupportedException e)
|
|
92
|
+
{
|
|
93
|
+
throw new DecodeException($"HTTP {Status}: the SDK does not decode {typeof(T).Name}", e);
|
|
94
|
+
}
|
|
95
|
+
try
|
|
96
|
+
{
|
|
97
|
+
return JsonSerializer.Deserialize(Body, info) is T value ? value : throw new DecodeException($"HTTP {Status}: the body is null");
|
|
98
|
+
}
|
|
99
|
+
catch (JsonException e)
|
|
100
|
+
{
|
|
101
|
+
var what = Envelopes.Parse(Body).Json ? $"does not decode as {typeof(T).Name}" : "is not JSON";
|
|
102
|
+
throw new DecodeException($"HTTP {Status}: the body {what}", e);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
internal static ApiStatusException Of(Failure failure) =>
|
|
107
|
+
failure.Status switch
|
|
108
|
+
{
|
|
109
|
+
400 => new BadRequestException(failure),
|
|
110
|
+
401 => new UnauthorizedException(failure),
|
|
111
|
+
403 => new ForbiddenException(failure),
|
|
112
|
+
404 => new NotFoundException(failure),
|
|
113
|
+
409 => new ConflictException(failure),
|
|
114
|
+
422 => new UnprocessableEntityException(failure),
|
|
115
|
+
429 => new RateLimitException(failure),
|
|
116
|
+
500 => new InternalServerException(failure),
|
|
117
|
+
502 => new BadGatewayException(failure),
|
|
118
|
+
503 => new ServiceUnavailableException(failure),
|
|
119
|
+
504 => new GatewayTimeoutException(failure),
|
|
120
|
+
_ => new UnexpectedStatusException(failure),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/// <summary>HTTP 400.</summary>
|
|
125
|
+
public sealed class BadRequestException : ApiStatusException
|
|
126
|
+
{
|
|
127
|
+
internal BadRequestException(Failure failure) : base(failure) { }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/// <summary>HTTP 401.</summary>
|
|
131
|
+
public sealed class UnauthorizedException : ApiStatusException
|
|
132
|
+
{
|
|
133
|
+
internal UnauthorizedException(Failure failure) : base(failure) { }
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/// <summary>HTTP 403.</summary>
|
|
137
|
+
public sealed class ForbiddenException : ApiStatusException
|
|
138
|
+
{
|
|
139
|
+
internal ForbiddenException(Failure failure) : base(failure) { }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/// <summary>HTTP 404.</summary>
|
|
143
|
+
public sealed class NotFoundException : ApiStatusException
|
|
144
|
+
{
|
|
145
|
+
internal NotFoundException(Failure failure) : base(failure) { }
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/// <summary>HTTP 409.</summary>
|
|
149
|
+
public sealed class ConflictException : ApiStatusException
|
|
150
|
+
{
|
|
151
|
+
internal ConflictException(Failure failure) : base(failure) { }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/// <summary>HTTP 422.</summary>
|
|
155
|
+
public sealed class UnprocessableEntityException : ApiStatusException
|
|
156
|
+
{
|
|
157
|
+
internal UnprocessableEntityException(Failure failure) : base(failure) { }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/// <summary>HTTP 429.</summary>
|
|
161
|
+
public sealed class RateLimitException : ApiStatusException
|
|
162
|
+
{
|
|
163
|
+
internal RateLimitException(Failure failure) : base(failure) { }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/// <summary>HTTP 500.</summary>
|
|
167
|
+
public sealed class InternalServerException : ApiStatusException
|
|
168
|
+
{
|
|
169
|
+
internal InternalServerException(Failure failure) : base(failure) { }
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/// <summary>HTTP 502.</summary>
|
|
173
|
+
public sealed class BadGatewayException : ApiStatusException
|
|
174
|
+
{
|
|
175
|
+
internal BadGatewayException(Failure failure) : base(failure) { }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/// <summary>HTTP 503.</summary>
|
|
179
|
+
public sealed class ServiceUnavailableException : ApiStatusException
|
|
180
|
+
{
|
|
181
|
+
internal ServiceUnavailableException(Failure failure) : base(failure) { }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/// <summary>HTTP 504.</summary>
|
|
185
|
+
public sealed class GatewayTimeoutException : ApiStatusException
|
|
186
|
+
{
|
|
187
|
+
internal GatewayTimeoutException(Failure failure) : base(failure) { }
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/// <summary>Any other status outside 2xx, a redirect the call did not follow included.</summary>
|
|
191
|
+
public sealed class UnexpectedStatusException : ApiStatusException
|
|
192
|
+
{
|
|
193
|
+
internal UnexpectedStatusException(Failure failure) : base(failure) { }
|
|
194
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
using System;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using System.IO;
|
|
5
|
+
using System.Net.Http;
|
|
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 server-sent event: its decoded data, its type, the stream's last event id when it came, and its <c>retry</c>.</summary>
|
|
14
|
+
public sealed record SseEvent<T>(T Data, string? Event, string? Id, TimeSpan? Retry);
|
|
15
|
+
|
|
16
|
+
/// <summary>
|
|
17
|
+
/// An open event stream, read once by <c>await foreach</c>. No timeout bounds it. An event that does not decode, a
|
|
18
|
+
/// cap or a failed read is thrown once and ends it. The method's token or the read's own token ends it with an
|
|
19
|
+
/// OperationCanceledException; leaving the loop or <see cref="DisposeAsync"/> ends it quietly. Each end lets the
|
|
20
|
+
/// connection go: dispose it, or read it to its end.
|
|
21
|
+
/// </summary>
|
|
22
|
+
public sealed class EventStream<T> : IAsyncEnumerable<SseEvent<T>>, IAsyncDisposable
|
|
23
|
+
{
|
|
24
|
+
private const int ReadBuffer = 65_536;
|
|
25
|
+
|
|
26
|
+
private readonly HttpResponseMessage _response;
|
|
27
|
+
private readonly Func<string, T> _decode;
|
|
28
|
+
private readonly CancellationToken _call;
|
|
29
|
+
private readonly CancellationTokenSource _end = new();
|
|
30
|
+
private readonly CancellationTokenRegistration _registration;
|
|
31
|
+
private readonly SseParser _parser = new();
|
|
32
|
+
private readonly List<RawEvent> _pending = [];
|
|
33
|
+
private readonly byte[] _buffer = new byte[ReadBuffer];
|
|
34
|
+
private Stream? _body;
|
|
35
|
+
private bool _over;
|
|
36
|
+
private int _taken;
|
|
37
|
+
private int _released;
|
|
38
|
+
|
|
39
|
+
internal EventStream(HttpResponseMessage response, Func<string, T> decode, CancellationToken call)
|
|
40
|
+
{
|
|
41
|
+
_response = response;
|
|
42
|
+
_decode = decode;
|
|
43
|
+
_call = call;
|
|
44
|
+
_registration = call.Register(static stream => ((EventStream<T>)stream!).Release(), this);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// <summary>The id of the last event read, to resume from; empty before any.</summary>
|
|
48
|
+
public string LastEventId { get; private set; } = "";
|
|
49
|
+
|
|
50
|
+
/// <summary>The stream's events in order; a second enumeration throws InvalidOperationException.</summary>
|
|
51
|
+
public IAsyncEnumerator<SseEvent<T>> GetAsyncEnumerator(CancellationToken cancellationToken = default) =>
|
|
52
|
+
Interlocked.Exchange(ref _taken, 1) == 0
|
|
53
|
+
? EventsAsync(cancellationToken)
|
|
54
|
+
: throw new InvalidOperationException("an EventStream is read once");
|
|
55
|
+
|
|
56
|
+
/// <summary>Ends the stream: a pending read ends quietly, and the connection goes.</summary>
|
|
57
|
+
public ValueTask DisposeAsync()
|
|
58
|
+
{
|
|
59
|
+
Release();
|
|
60
|
+
return ValueTask.CompletedTask;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private void Release()
|
|
64
|
+
{
|
|
65
|
+
if (Interlocked.Exchange(ref _released, 1) == 0)
|
|
66
|
+
{
|
|
67
|
+
/* the pending read ends at once; a dispose alone would wait for it */
|
|
68
|
+
_end.Cancel();
|
|
69
|
+
_registration.Unregister();
|
|
70
|
+
_response.Dispose();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private async IAsyncEnumerator<SseEvent<T>> EventsAsync(CancellationToken token)
|
|
75
|
+
{
|
|
76
|
+
using var read = CancellationTokenSource.CreateLinkedTokenSource(token, _end.Token);
|
|
77
|
+
try
|
|
78
|
+
{
|
|
79
|
+
while (!_over)
|
|
80
|
+
{
|
|
81
|
+
var cap = await PullAsync(token, read.Token).ConfigureAwait(false);
|
|
82
|
+
foreach (var raw in _pending)
|
|
83
|
+
{
|
|
84
|
+
var data = _decode(raw.Data);
|
|
85
|
+
LastEventId = raw.Id ?? "";
|
|
86
|
+
yield return new SseEvent<T>(data, raw.Event, raw.Id, raw.Retry);
|
|
87
|
+
}
|
|
88
|
+
_pending.Clear();
|
|
89
|
+
if (cap is not null)
|
|
90
|
+
{
|
|
91
|
+
throw cap;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
finally
|
|
96
|
+
{
|
|
97
|
+
Release();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* one read into the parser: the cap it hit after the events it completed, an OCE for a caller's token */
|
|
102
|
+
private async Task<DecodeException?> PullAsync(CancellationToken own, CancellationToken read)
|
|
103
|
+
{
|
|
104
|
+
int count;
|
|
105
|
+
try
|
|
106
|
+
{
|
|
107
|
+
_body ??= await _response.Content.ReadAsStreamAsync(read).ConfigureAwait(false);
|
|
108
|
+
count = await _body.ReadAsync(_buffer, read).ConfigureAwait(false);
|
|
109
|
+
}
|
|
110
|
+
catch (Exception e)
|
|
111
|
+
{
|
|
112
|
+
_over = true;
|
|
113
|
+
if (_call.IsCancellationRequested || own.IsCancellationRequested)
|
|
114
|
+
{
|
|
115
|
+
throw new OperationCanceledException("the stream was canceled", e, _call.IsCancellationRequested ? _call : own);
|
|
116
|
+
}
|
|
117
|
+
return _end.IsCancellationRequested ? null : throw new ApiConnectionException("the event stream failed", e);
|
|
118
|
+
}
|
|
119
|
+
_over = count == 0;
|
|
120
|
+
try
|
|
121
|
+
{
|
|
122
|
+
_parser.Feed(_buffer.AsSpan(0, count), _pending);
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
catch (DecodeException cap)
|
|
126
|
+
{
|
|
127
|
+
_over = true;
|
|
128
|
+
return cap;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
internal sealed partial class Transport
|
|
134
|
+
{
|
|
135
|
+
public async Task<EventStream<T>> EventsAsync<T>(Operation op, Call call, string? lastEventId, JsonTypeInfo<T> info, CancellationToken cancellationToken) =>
|
|
136
|
+
new(await OpenedAsync(op, call, lastEventId, cancellationToken).ConfigureAwait(false), data => Event(data, info), cancellationToken);
|
|
137
|
+
|
|
138
|
+
public async Task<EventStream<string>> TextEventsAsync(Operation op, Call call, string? lastEventId, CancellationToken cancellationToken) =>
|
|
139
|
+
new(await OpenedAsync(op, call, lastEventId, cancellationToken).ConfigureAwait(false), data => data, cancellationToken);
|
|
140
|
+
|
|
141
|
+
private Task<HttpResponseMessage> OpenedAsync(Operation op, Call call, string? lastEventId, CancellationToken cancellationToken) =>
|
|
142
|
+
new Exchange(this, op, call with { Headers = [.. call.Headers, Arg.Text("Last-Event-ID", lastEventId)] }, stream: true).OpenAsync(cancellationToken);
|
|
143
|
+
|
|
144
|
+
private static T Event<T>(string data, JsonTypeInfo<T> info)
|
|
145
|
+
{
|
|
146
|
+
try
|
|
147
|
+
{
|
|
148
|
+
return JsonSerializer.Deserialize(data, info) ?? throw new DecodeException("an event's data does not decode: it is null");
|
|
149
|
+
}
|
|
150
|
+
catch (JsonException e)
|
|
151
|
+
{
|
|
152
|
+
throw new DecodeException($"an event's data does not decode: {e.Message}", e);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|