@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,301 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.io.ByteArrayOutputStream;
|
|
5
|
+
import java.net.http.WebSocket;
|
|
6
|
+
import java.nio.ByteBuffer;
|
|
7
|
+
import java.nio.charset.StandardCharsets;
|
|
8
|
+
import java.time.Duration;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
import java.util.concurrent.BlockingQueue;
|
|
11
|
+
import java.util.concurrent.CancellationException;
|
|
12
|
+
import java.util.concurrent.CompletableFuture;
|
|
13
|
+
import java.util.concurrent.CompletionStage;
|
|
14
|
+
import java.util.concurrent.CopyOnWriteArrayList;
|
|
15
|
+
import java.util.concurrent.CountDownLatch;
|
|
16
|
+
import java.util.concurrent.ExecutionException;
|
|
17
|
+
import java.util.concurrent.LinkedBlockingQueue;
|
|
18
|
+
import java.util.concurrent.Semaphore;
|
|
19
|
+
import java.util.concurrent.TimeUnit;
|
|
20
|
+
import java.util.concurrent.atomic.AtomicBoolean;
|
|
21
|
+
import java.util.function.Consumer;
|
|
22
|
+
import java.util.function.Function;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A WebSocket as the SDK holds it: the JDK's listener, assembling each message's partials up to 16
|
|
26
|
+
* MiB and asking for more only as the reader takes what waits (no background reader); the one send
|
|
27
|
+
* gate every frame goes through, since the JDK fails a frame sent beside another; and the socket's
|
|
28
|
+
* one end, which fires exactly one of Closed or Error, once.
|
|
29
|
+
*/
|
|
30
|
+
final class Socket implements WebSocket.Listener {
|
|
31
|
+
private static final int CAP = 16 << 20;
|
|
32
|
+
private static final Object END = new Object();
|
|
33
|
+
|
|
34
|
+
/** A remote end, queued after the messages before it, fired as receive reaches it. */
|
|
35
|
+
private record Ending(WsClose closed, RuntimeException error) {}
|
|
36
|
+
|
|
37
|
+
private final Duration every;
|
|
38
|
+
private final BlockingQueue<Object> inbox = new LinkedBlockingQueue<>();
|
|
39
|
+
private final ByteArrayOutputStream partial = new ByteArrayOutputStream();
|
|
40
|
+
private final Semaphore gate = new Semaphore(1);
|
|
41
|
+
private final AtomicBoolean ended = new AtomicBoolean();
|
|
42
|
+
private final CountDownLatch echo = new CountDownLatch(1);
|
|
43
|
+
final List<Consumer<WsMessage>> onMessage = new CopyOnWriteArrayList<>();
|
|
44
|
+
final List<Consumer<WsClose>> onClosed = new CopyOnWriteArrayList<>();
|
|
45
|
+
final List<Consumer<java.lang.Exception>> onError = new CopyOnWriteArrayList<>();
|
|
46
|
+
volatile WebSocket ws;
|
|
47
|
+
private volatile Keepalive keepalive;
|
|
48
|
+
volatile WsClose closedBy;
|
|
49
|
+
private volatile boolean deferredPing;
|
|
50
|
+
|
|
51
|
+
Socket(Duration every) {
|
|
52
|
+
this.every = every;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Override
|
|
56
|
+
public void onOpen(WebSocket socket) {
|
|
57
|
+
ws = socket;
|
|
58
|
+
keepalive = new Keepalive(this, every);
|
|
59
|
+
keepalive.start();
|
|
60
|
+
socket.request(1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Override
|
|
64
|
+
public CompletionStage<?> onText(WebSocket socket, CharSequence data, boolean last) {
|
|
65
|
+
take(data.toString().getBytes(StandardCharsets.UTF_8), WsMessage.Type.TEXT, last);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@Override
|
|
70
|
+
public CompletionStage<?> onBinary(WebSocket socket, ByteBuffer data, boolean last) {
|
|
71
|
+
byte[] bytes = new byte[data.remaining()];
|
|
72
|
+
data.get(bytes);
|
|
73
|
+
take(bytes, WsMessage.Type.BINARY, last);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* One partial: refused at once when it would cross the cap; a whole message waits for receive.
|
|
79
|
+
*/
|
|
80
|
+
private synchronized void take(byte[] bytes, WsMessage.Type type, boolean last) {
|
|
81
|
+
keepalive.heard();
|
|
82
|
+
if (ended.get()) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (partial.size() + bytes.length > CAP) {
|
|
86
|
+
if (ended.compareAndSet(false, true)) {
|
|
87
|
+
shut(1008, "Message too big", true);
|
|
88
|
+
finish(
|
|
89
|
+
null,
|
|
90
|
+
new ApiConnectionException("the WebSocket ended: 1008 Message too big", null),
|
|
91
|
+
false);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
partial.write(bytes, 0, bytes.length);
|
|
96
|
+
if (last) {
|
|
97
|
+
inbox.add(new WsMessage(type, partial.toByteArray()));
|
|
98
|
+
partial.reset();
|
|
99
|
+
} else {
|
|
100
|
+
ws.request(1);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@Override
|
|
105
|
+
public CompletionStage<?> onPing(WebSocket socket, ByteBuffer message) {
|
|
106
|
+
keepalive.heard();
|
|
107
|
+
socket.request(1);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@Override
|
|
112
|
+
public CompletionStage<?> onPong(WebSocket socket, ByteBuffer message) {
|
|
113
|
+
return onPing(socket, message);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@Override
|
|
117
|
+
public CompletionStage<?> onClose(WebSocket socket, int code, String reason) {
|
|
118
|
+
if (!ended.compareAndSet(false, true)) {
|
|
119
|
+
echo.countDown();
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
if (code == 1006) {
|
|
123
|
+
finish(null, new ApiConnectionException("the WebSocket failed", null), false);
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
closedBy = new WsClose(code, reason);
|
|
127
|
+
shut(WsClose.sendable(code) ? code : 1000, WsClose.cut(reason), true);
|
|
128
|
+
finish(closedBy, null, false);
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@Override
|
|
133
|
+
public void onError(WebSocket socket, Throwable error) {
|
|
134
|
+
if (ended.compareAndSet(false, true)) {
|
|
135
|
+
finish(null, new ApiConnectionException("the WebSocket failed", error), false);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The keepalive's ping went unanswered for an interval: the peer is gone. */
|
|
140
|
+
void unanswered() {
|
|
141
|
+
if (ended.compareAndSet(false, true)) {
|
|
142
|
+
ws.abort();
|
|
143
|
+
finish(
|
|
144
|
+
null, new ApiConnectionException("the WebSocket stopped answering pings", null), false);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The keepalive's ping, through the gate: deferred while a send holds it, sent when it frees.
|
|
150
|
+
* False once the socket ended, which stops the keepalive.
|
|
151
|
+
*/
|
|
152
|
+
boolean ping() {
|
|
153
|
+
if (ended.get()) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
if (keepalive.waiting()) {
|
|
157
|
+
deferredPing = false;
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
if (!gate.tryAcquire()) {
|
|
161
|
+
deferredPing = true;
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
deferredPing = false;
|
|
165
|
+
keepalive.sent();
|
|
166
|
+
ws.sendPing(ByteBuffer.allocate(0)).whenComplete((sent, error) -> release());
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private void release() {
|
|
171
|
+
gate.release();
|
|
172
|
+
if (deferredPing) {
|
|
173
|
+
ping();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* A close frame through the gate, or an abort when a send holds it: no frame follows half a
|
|
179
|
+
* message. Whether the frame went out.
|
|
180
|
+
*/
|
|
181
|
+
private boolean shut(int status, String reason, boolean await) {
|
|
182
|
+
if (!gate.tryAcquire()) {
|
|
183
|
+
ws.abort();
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
CompletableFuture<WebSocket> sent = ws.sendClose(status, reason);
|
|
187
|
+
sent.whenComplete((done, error) -> release());
|
|
188
|
+
if (await) {
|
|
189
|
+
try {
|
|
190
|
+
sent.get(every.toMillis(), TimeUnit.MILLISECONDS);
|
|
191
|
+
} catch (InterruptedException e) {
|
|
192
|
+
java.lang.Thread.currentThread().interrupt();
|
|
193
|
+
} catch (ExecutionException | java.util.concurrent.TimeoutException e) {
|
|
194
|
+
/* the end goes on: the frame is the server's to miss */
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The end: the reader's end queued, and Closed or Error fired once. */
|
|
201
|
+
private void finish(WsClose closed, RuntimeException error, boolean local) {
|
|
202
|
+
if (local) {
|
|
203
|
+
fire(closed, error);
|
|
204
|
+
inbox.add(END);
|
|
205
|
+
} else {
|
|
206
|
+
inbox.add(new Ending(closed, error));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Closed or Error: once, since only the end that won {@code ended} queues or fires one, and its
|
|
212
|
+
* Ending is taken once.
|
|
213
|
+
*/
|
|
214
|
+
private void fire(WsClose closed, RuntimeException error) {
|
|
215
|
+
if (error != null) {
|
|
216
|
+
onError.forEach(handler -> run(handler, error));
|
|
217
|
+
} else {
|
|
218
|
+
onClosed.forEach(handler -> run(handler, closed));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private static <T> void run(Consumer<T> handler, T value) {
|
|
223
|
+
try {
|
|
224
|
+
handler.accept(value);
|
|
225
|
+
} catch (RuntimeException e) {
|
|
226
|
+
/* a throwing handler is ignored */
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
WsMessage receive() {
|
|
231
|
+
Object item;
|
|
232
|
+
try {
|
|
233
|
+
item = inbox.take();
|
|
234
|
+
} catch (InterruptedException e) {
|
|
235
|
+
close(1000, "");
|
|
236
|
+
java.lang.Thread.currentThread().interrupt();
|
|
237
|
+
throw new CancellationException("the read was canceled");
|
|
238
|
+
}
|
|
239
|
+
if (item instanceof WsMessage message) {
|
|
240
|
+
onMessage.forEach(handler -> run(handler, message));
|
|
241
|
+
if (!ended.get()) {
|
|
242
|
+
ws.request(1);
|
|
243
|
+
}
|
|
244
|
+
return message;
|
|
245
|
+
}
|
|
246
|
+
inbox.add(END);
|
|
247
|
+
if (item instanceof Ending ending) {
|
|
248
|
+
fire(ending.closed(), ending.error());
|
|
249
|
+
if (ending.error() != null) {
|
|
250
|
+
throw ending.error();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** One frame through the gate, waiting until it went out; never the payload in an error. */
|
|
257
|
+
void send(Function<WebSocket, CompletableFuture<WebSocket>> frame) {
|
|
258
|
+
if (ended.get()) {
|
|
259
|
+
throw new ApiConnectionException("the WebSocket is closed", null);
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
gate.acquire();
|
|
263
|
+
} catch (InterruptedException e) {
|
|
264
|
+
java.lang.Thread.currentThread().interrupt();
|
|
265
|
+
throw new CancellationException("the send was canceled");
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
if (ended.get()) {
|
|
269
|
+
throw new ApiConnectionException("the WebSocket is closed", null);
|
|
270
|
+
}
|
|
271
|
+
frame.apply(ws).get();
|
|
272
|
+
} catch (ExecutionException e) {
|
|
273
|
+
throw new ApiConnectionException(
|
|
274
|
+
"the WebSocket send failed: " + e.getCause().getClass().getSimpleName(), null);
|
|
275
|
+
} catch (InterruptedException e) {
|
|
276
|
+
ws.abort();
|
|
277
|
+
java.lang.Thread.currentThread().interrupt();
|
|
278
|
+
throw new CancellationException("the send was canceled");
|
|
279
|
+
} finally {
|
|
280
|
+
release();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** The client's close: its frame, Closed with its own code and reason, then the echo awaited. */
|
|
285
|
+
void close(int status, String reason) {
|
|
286
|
+
WsClose.check(status);
|
|
287
|
+
if (!ended.compareAndSet(false, true)) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
String cut = WsClose.cut(reason);
|
|
291
|
+
boolean framed = shut(status, cut, false);
|
|
292
|
+
finish(new WsClose(status, cut), null, true);
|
|
293
|
+
try {
|
|
294
|
+
if (framed) {
|
|
295
|
+
echo.await(every.toMillis(), TimeUnit.MILLISECONDS);
|
|
296
|
+
}
|
|
297
|
+
} catch (InterruptedException e) {
|
|
298
|
+
java.lang.Thread.currentThread().interrupt();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.io.ByteArrayOutputStream;
|
|
5
|
+
import java.io.IOException;
|
|
6
|
+
import java.io.InputStream;
|
|
7
|
+
import java.nio.charset.StandardCharsets;
|
|
8
|
+
import java.util.ArrayDeque;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An event stream's parser (WHATWG), over bytes read at most 64 KiB at a time: lines end on CR, LF
|
|
12
|
+
* or CRLF (a CR at a read's end waits for the next byte); a BOM is stripped at the stream's start
|
|
13
|
+
* only; data lines join with LF; the id is sticky, ignored when it holds NUL, cleared when empty;
|
|
14
|
+
* retry is ASCII digits only; a final event without its blank line is dropped. A line over 1 MiB,
|
|
15
|
+
* or an event's data over 8 MiB, counted in bytes, is a DecodeException raised once, after the
|
|
16
|
+
* events the same read completed.
|
|
17
|
+
*/
|
|
18
|
+
final class Sse {
|
|
19
|
+
private static final int CHUNK = 64 * 1024;
|
|
20
|
+
private static final int LINE_CAP = 1 << 20;
|
|
21
|
+
private static final int DATA_CAP = 8 << 20;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* One event: its data, its event name and id (null when unset), its retry in ms (null when
|
|
25
|
+
* unset).
|
|
26
|
+
*/
|
|
27
|
+
record Event(String data, String event, String id, Long retry) {}
|
|
28
|
+
|
|
29
|
+
private final InputStream in;
|
|
30
|
+
private final byte[] buffer = new byte[CHUNK];
|
|
31
|
+
private final ArrayDeque<Event> ready = new ArrayDeque<>();
|
|
32
|
+
private final ByteArrayOutputStream line = new ByteArrayOutputStream();
|
|
33
|
+
private final ByteArrayOutputStream data = new ByteArrayOutputStream();
|
|
34
|
+
private DecodeException failure;
|
|
35
|
+
private boolean ended;
|
|
36
|
+
private boolean start = true;
|
|
37
|
+
private boolean cr;
|
|
38
|
+
private boolean hasData;
|
|
39
|
+
private String event;
|
|
40
|
+
private String id = "";
|
|
41
|
+
private Long retry;
|
|
42
|
+
|
|
43
|
+
Sse(InputStream in) {
|
|
44
|
+
this.in = in;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The next event, null at the stream's end; the cap's error once the events before it are read.
|
|
49
|
+
*/
|
|
50
|
+
Event next() throws IOException {
|
|
51
|
+
while (ready.isEmpty()) {
|
|
52
|
+
if (failure != null) {
|
|
53
|
+
DecodeException raised = failure;
|
|
54
|
+
failure = null;
|
|
55
|
+
ended = true;
|
|
56
|
+
throw raised;
|
|
57
|
+
}
|
|
58
|
+
if (ended) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
int n = in.read(buffer, 0, CHUNK);
|
|
62
|
+
if (n < 0) {
|
|
63
|
+
ended = true;
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
feed(n);
|
|
67
|
+
}
|
|
68
|
+
return ready.poll();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private void feed(int n) {
|
|
72
|
+
for (int i = 0; i < n && failure == null; i++) {
|
|
73
|
+
byte b = buffer[i];
|
|
74
|
+
if (cr) {
|
|
75
|
+
cr = false;
|
|
76
|
+
if (b == '\n') {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (b == '\r' || b == '\n') {
|
|
81
|
+
cr = b == '\r';
|
|
82
|
+
lineEnded();
|
|
83
|
+
} else if (line.size() == LINE_CAP) {
|
|
84
|
+
failure = new DecodeException("an event-stream line exceeds 1 MiB", null);
|
|
85
|
+
} else {
|
|
86
|
+
line.write(b);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private void lineEnded() {
|
|
92
|
+
byte[] bytes = line.toByteArray();
|
|
93
|
+
line.reset();
|
|
94
|
+
int from = 0;
|
|
95
|
+
if (start) {
|
|
96
|
+
start = false;
|
|
97
|
+
boolean bom = bytes.length >= 3 && (bytes[0] & 0xff) == 0xef;
|
|
98
|
+
from = bom && (bytes[1] & 0xff) == 0xbb && (bytes[2] & 0xff) == 0xbf ? 3 : 0;
|
|
99
|
+
}
|
|
100
|
+
if (from == bytes.length) {
|
|
101
|
+
dispatch();
|
|
102
|
+
} else if (bytes[from] != ':') {
|
|
103
|
+
field(bytes, from);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private void field(byte[] bytes, int from) {
|
|
108
|
+
int colon = from;
|
|
109
|
+
while (colon < bytes.length && bytes[colon] != ':') {
|
|
110
|
+
colon++;
|
|
111
|
+
}
|
|
112
|
+
String name = new String(bytes, from, colon - from, StandardCharsets.UTF_8);
|
|
113
|
+
int value =
|
|
114
|
+
colon < bytes.length && colon + 1 < bytes.length && bytes[colon + 1] == ' '
|
|
115
|
+
? colon + 2
|
|
116
|
+
: colon + 1;
|
|
117
|
+
int length = Math.max(0, bytes.length - value);
|
|
118
|
+
switch (name) {
|
|
119
|
+
case "data" -> {
|
|
120
|
+
if (data.size() + (hasData ? 1 : 0) + length > DATA_CAP) {
|
|
121
|
+
failure = new DecodeException("an event's data exceeds 8 MiB", null);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (hasData) {
|
|
125
|
+
data.write('\n');
|
|
126
|
+
}
|
|
127
|
+
data.write(bytes, Math.min(value, bytes.length), length);
|
|
128
|
+
hasData = true;
|
|
129
|
+
}
|
|
130
|
+
case "event" -> event = text(bytes, value, length);
|
|
131
|
+
case "id" -> {
|
|
132
|
+
String given = text(bytes, value, length);
|
|
133
|
+
if (given.indexOf('\0') < 0) {
|
|
134
|
+
id = given;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
case "retry" -> retry = digits(text(bytes, value, length));
|
|
138
|
+
default -> {}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private static String text(byte[] bytes, int from, int length) {
|
|
143
|
+
return length == 0 ? "" : new String(bytes, from, length, StandardCharsets.UTF_8);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The value as a count of ms when it is ASCII digits alone, else null (a value no long holds
|
|
148
|
+
* too).
|
|
149
|
+
*/
|
|
150
|
+
private static Long digits(String value) {
|
|
151
|
+
if (value.isEmpty() || !value.chars().allMatch(c -> c >= '0' && c <= '9')) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
return Long.parseLong(value);
|
|
156
|
+
} catch (NumberFormatException e) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private void dispatch() {
|
|
162
|
+
if (hasData) {
|
|
163
|
+
String text = data.toString(StandardCharsets.UTF_8);
|
|
164
|
+
ready.add(new Event(text, event, id.isEmpty() ? null : id, retry));
|
|
165
|
+
}
|
|
166
|
+
data.reset();
|
|
167
|
+
hasData = false;
|
|
168
|
+
event = null;
|
|
169
|
+
retry = null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.util.Iterator;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A realtime call's event stream through its exchange: the cursor's id as Last-Event-ID, its token
|
|
8
|
+
* as a query param; a send is a POST.
|
|
9
|
+
*/
|
|
10
|
+
final class SseAdapter implements TransportAdapter, RealtimeLoop.Dialed {
|
|
11
|
+
private final Realtime dial;
|
|
12
|
+
|
|
13
|
+
SseAdapter(Realtime dial) {
|
|
14
|
+
this.dial = dial;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Override
|
|
18
|
+
public Realtime dial() {
|
|
19
|
+
return dial;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Override
|
|
23
|
+
public String name() {
|
|
24
|
+
return "sse";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Override
|
|
28
|
+
public TransportKind kind() {
|
|
29
|
+
return TransportKind.SSE;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Opens the call's event stream, which no read timeout bounds; {@code url} is a caller's
|
|
34
|
+
* adapter's.
|
|
35
|
+
*/
|
|
36
|
+
@Override
|
|
37
|
+
public TransportConnection connect(String url, TransportOptions options) {
|
|
38
|
+
EventStream<String> stream = dial.stream(options);
|
|
39
|
+
Iterator<SseEvent<String>> events = stream.iterator();
|
|
40
|
+
return new TransportConnection() {
|
|
41
|
+
@Override
|
|
42
|
+
public TransportMessage receive() {
|
|
43
|
+
if (!events.hasNext()) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
SseEvent<String> event = events.next();
|
|
47
|
+
return new TransportMessage(event.data(), event.id(), event.retry());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Override
|
|
51
|
+
public void send(String text) {
|
|
52
|
+
dial.post(text);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Override
|
|
56
|
+
public void close() {
|
|
57
|
+
stream.close();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.time.Duration;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One event of an {@link EventStream}: its data decoded as {@code T}, its event name and its id
|
|
8
|
+
* (null when unset), and its retry (null when unset).
|
|
9
|
+
*/
|
|
10
|
+
public record SseEvent<T>(T data, String event, String id, Duration retry) {}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// @generated by honey. DO NOT EDIT.
|
|
2
|
+
package honey.runtime;
|
|
3
|
+
|
|
4
|
+
import java.util.List;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A read's stale view: its selector, whether a mark names it, the mutations that did, and the mark
|
|
8
|
+
* sequence it was taken at. {@link #NONE} is the view with stale tracking off.
|
|
9
|
+
*/
|
|
10
|
+
record StaleMeta(String selector, boolean isStale, List<String> invalidatedBy, long seq) {
|
|
11
|
+
static final StaleMeta NONE = new StaleMeta("", false, List.of(), 0);
|
|
12
|
+
|
|
13
|
+
StaleMeta {
|
|
14
|
+
invalidatedBy = List.copyOf(invalidatedBy);
|
|
15
|
+
}
|
|
16
|
+
}
|