@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,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side path templates. Two spellings are accepted, segment by segment:
|
|
3
|
+
*
|
|
4
|
+
* - Honey route patterns: `:name` (or `:name?`) takes a whole segment, `*name` (or `*`) takes the
|
|
5
|
+
* rest of the path. Names follow the router grammar, so `:user-id` is one parameter.
|
|
6
|
+
* - OpenAPI templates: `{name}` anywhere inside a segment (`/ops/{id}:cancel`).
|
|
7
|
+
*
|
|
8
|
+
* Values are percent-encoded. A value that would change the path's shape once a URL parser
|
|
9
|
+
* normalizes it (`""`, `.`, `..`) is rejected, so `{ id: ".." }` can never retarget a request to
|
|
10
|
+
* the parent resource and `{ org: "" }` can never turn `/:org/:repo` into `//repo`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** A fresh `{name}` placeholder matcher: a global regex carries `lastIndex`, so none is shared. */
|
|
14
|
+
const braces = () => /\{([^{}/]+)\}/g
|
|
15
|
+
|
|
16
|
+
export class PathParamError extends Error {
|
|
17
|
+
constructor(message: string) {
|
|
18
|
+
super(message)
|
|
19
|
+
this.name = "PathParamError"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function paramValue(params: Record<string, unknown>, key: string): string | undefined {
|
|
24
|
+
const raw = Object.hasOwn(params, key) ? params[key] : undefined
|
|
25
|
+
if (raw === undefined || raw === null) return undefined
|
|
26
|
+
return typeof raw === "string" ? raw : String(raw)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function encodeSegmentValue(key: string, value: string): string {
|
|
30
|
+
if (value === "" || value === "." || value === "..") {
|
|
31
|
+
throw new PathParamError(
|
|
32
|
+
`Invalid path param ${JSON.stringify(key)}: ${JSON.stringify(value)} is not a path segment`,
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
return encodeURIComponent(value)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A wildcard value may span segments; each one is encoded and validated on its own. */
|
|
39
|
+
function encodeWildcardValue(key: string, value: string): string {
|
|
40
|
+
if (value === "") return ""
|
|
41
|
+
return value
|
|
42
|
+
.split("/")
|
|
43
|
+
.map((part) => encodeSegmentValue(key, part))
|
|
44
|
+
.join("/")
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** One `:name`/`:name?` segment, `null` when an optional one is left out. */
|
|
48
|
+
function paramSegment(seg: string, params: Record<string, unknown>): string | null {
|
|
49
|
+
const optional = seg.endsWith("?")
|
|
50
|
+
const name = optional ? seg.slice(1, -1) : seg.slice(1)
|
|
51
|
+
const value = paramValue(params, name)
|
|
52
|
+
if (value !== undefined) return encodeSegmentValue(name, value)
|
|
53
|
+
if (optional) return null
|
|
54
|
+
throw new PathParamError(`Missing path param: ${name}`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The trailing `*`/`*name` segment: an unnamed one may be left empty. */
|
|
58
|
+
function wildcardSegment(seg: string, params: Record<string, unknown>): string {
|
|
59
|
+
const name = seg.length > 1 ? seg.slice(1) : "*"
|
|
60
|
+
const value = paramValue(params, name)
|
|
61
|
+
if (value !== undefined) return encodeWildcardValue(name, value)
|
|
62
|
+
if (seg.length === 1) return ""
|
|
63
|
+
throw new PathParamError(`Missing path param: ${name}`)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function interpolatePath(path: string, params: Record<string, unknown> = {}): string {
|
|
67
|
+
const segments = path.split("/")
|
|
68
|
+
const out: string[] = []
|
|
69
|
+
for (let i = 0; i < segments.length; i++) {
|
|
70
|
+
const seg = segments[i] as string
|
|
71
|
+
if (seg.length > 1 && seg.charCodeAt(0) === 58 /* : */) {
|
|
72
|
+
const value = paramSegment(seg, params)
|
|
73
|
+
if (value !== null) out.push(value)
|
|
74
|
+
} else if (seg.charCodeAt(0) === 42 /* * */ && i === segments.length - 1) out.push(wildcardSegment(seg, params))
|
|
75
|
+
else {
|
|
76
|
+
out.push(
|
|
77
|
+
seg.replace(braces(), (_, name: string) => {
|
|
78
|
+
const value = paramValue(params, name)
|
|
79
|
+
if (value === undefined) throw new PathParamError(`Missing path param: ${name}`)
|
|
80
|
+
return encodeSegmentValue(name, value)
|
|
81
|
+
}),
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return out.join("/")
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** True when the template still has a placeholder in either spelling. */
|
|
89
|
+
export function hasPlaceholder(path: string): boolean {
|
|
90
|
+
for (const seg of path.split("/")) {
|
|
91
|
+
if (seg.length > 1 && seg.charCodeAt(0) === 58) return true
|
|
92
|
+
if (seg.charCodeAt(0) === 42) return true
|
|
93
|
+
if (braces().test(seg)) return true
|
|
94
|
+
}
|
|
95
|
+
return false
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Substitute the params that are present and leave the others as placeholders. Used for
|
|
100
|
+
* invalidation targets, where a partially resolved target is still a narrower pattern.
|
|
101
|
+
*/
|
|
102
|
+
export function interpolatePartial(path: string, params: Record<string, unknown>): string {
|
|
103
|
+
return path
|
|
104
|
+
.split("/")
|
|
105
|
+
.map((seg, i, all) => {
|
|
106
|
+
if (seg.length > 1 && seg.charCodeAt(0) === 58) {
|
|
107
|
+
const optional = seg.endsWith("?")
|
|
108
|
+
const name = optional ? seg.slice(1, -1) : seg.slice(1)
|
|
109
|
+
const value = paramValue(params, name)
|
|
110
|
+
return value === undefined ? seg : encodeSegmentValue(name, value)
|
|
111
|
+
}
|
|
112
|
+
if (seg.charCodeAt(0) === 42 && i === all.length - 1) {
|
|
113
|
+
const value = paramValue(params, seg.length > 1 ? seg.slice(1) : "*")
|
|
114
|
+
return value === undefined ? seg : encodeWildcardValue(seg.slice(1), value)
|
|
115
|
+
}
|
|
116
|
+
return seg.replace(braces(), (match, name: string) => {
|
|
117
|
+
const value = paramValue(params, name)
|
|
118
|
+
return value === undefined ? match : encodeSegmentValue(name, value)
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
.join("/")
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function escapeRegExp(text: string): string {
|
|
125
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The regex source of one literal segment, its `{name}` placeholders matching one segment's text. */
|
|
129
|
+
function literalSource(seg: string): string {
|
|
130
|
+
let source = ""
|
|
131
|
+
let last = 0
|
|
132
|
+
const brace = braces()
|
|
133
|
+
for (let m = brace.exec(seg); m !== null; m = brace.exec(seg)) {
|
|
134
|
+
source += `${escapeRegExp(seg.slice(last, m.index))}[^/]+`
|
|
135
|
+
last = m.index + m[0].length
|
|
136
|
+
}
|
|
137
|
+
return source + escapeRegExp(seg.slice(last))
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Compile a template to a regex over concrete paths, using the same segment grammar; the caller caches it. */
|
|
141
|
+
export function compilePattern(pattern: string): RegExp {
|
|
142
|
+
const segments = pattern.split("/")
|
|
143
|
+
let source = ""
|
|
144
|
+
for (let i = 0; i < segments.length; i++) {
|
|
145
|
+
const seg = segments[i] as string
|
|
146
|
+
const sep = i === 0 ? "" : "/"
|
|
147
|
+
if (seg.length > 1 && seg.charCodeAt(0) === 58) source += seg.endsWith("?") ? `(?:${sep}[^/]+)?` : `${sep}[^/]+`
|
|
148
|
+
else if (seg.charCodeAt(0) === 42 && i === segments.length - 1) source += `(?:${sep}.*)?`
|
|
149
|
+
else source += sep + literalSource(seg)
|
|
150
|
+
}
|
|
151
|
+
return new RegExp(`^${source}$`)
|
|
152
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ConnectionState,
|
|
3
|
+
type ResumableConnection,
|
|
4
|
+
type ResumableConnectionOpts,
|
|
5
|
+
type KeepaliveLoop,
|
|
6
|
+
RealtimeAbortError,
|
|
7
|
+
RealtimeConnectError,
|
|
8
|
+
safely,
|
|
9
|
+
type ServerFrame,
|
|
10
|
+
type Transport,
|
|
11
|
+
type TransportAdapter,
|
|
12
|
+
type TransportConnection,
|
|
13
|
+
transportAt,
|
|
14
|
+
keepaliveOf,
|
|
15
|
+
refused,
|
|
16
|
+
walkChain,
|
|
17
|
+
} from "./realtime.ts"
|
|
18
|
+
|
|
19
|
+
type QueueEntry = { type: "done" } | { error: unknown; type: "error" } | { type: "value"; value: unknown }
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* One logical stream over reconnecting transports: messages arrive in order through the async
|
|
23
|
+
* iterator, a drop reconnects (proven transport first, then the chain) and resumes from the last
|
|
24
|
+
* message id with the server's reconnect token.
|
|
25
|
+
*/
|
|
26
|
+
export class Resumable implements ResumableConnection {
|
|
27
|
+
readonly #opts: ResumableConnectionOpts
|
|
28
|
+
readonly #refresh: (() => Promise<boolean>) | undefined
|
|
29
|
+
readonly #queue: QueueEntry[] = []
|
|
30
|
+
#pending: { reject: (err: unknown) => void; resolve: (result: IteratorResult<unknown>) => void } | null = null
|
|
31
|
+
#state: ConnectionState = "idle"
|
|
32
|
+
#conn: TransportConnection | null = null
|
|
33
|
+
#keepalive: KeepaliveLoop | null = null
|
|
34
|
+
#attempts = 0
|
|
35
|
+
#proven: number | null = null
|
|
36
|
+
#lastEventId: string | undefined
|
|
37
|
+
#reconnectToken: string | undefined
|
|
38
|
+
#started = false
|
|
39
|
+
#closed = false
|
|
40
|
+
/** the dial and reconnect timers still pending: `close()` clears them, so nothing outlives the connection */
|
|
41
|
+
readonly #timers = new Set<ReturnType<typeof setTimeout>>()
|
|
42
|
+
/** the transport being dialed, closed with the connection */
|
|
43
|
+
#dialing: TransportConnection | null = null
|
|
44
|
+
|
|
45
|
+
constructor(opts: ResumableConnectionOpts, refresh?: () => Promise<boolean>) {
|
|
46
|
+
this.#opts = opts
|
|
47
|
+
this.#refresh = refresh
|
|
48
|
+
this.#lastEventId = opts.lastEventId
|
|
49
|
+
this.#reconnectToken = opts.reconnectToken
|
|
50
|
+
if (opts.signal?.aborted) this.#end()
|
|
51
|
+
else opts.signal?.addEventListener("abort", () => this.#abort(), { once: true })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get state(): ConnectionState {
|
|
55
|
+
return this.#state
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get provenTransport(): Transport | null {
|
|
59
|
+
return this.#proven === null ? null : transportAt(this.#proven)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#end(): void {
|
|
63
|
+
this.#state = "closed"
|
|
64
|
+
this.#closed = true
|
|
65
|
+
for (const timer of this.#timers) clearTimeout(timer)
|
|
66
|
+
this.#timers.clear()
|
|
67
|
+
const dialing = this.#dialing
|
|
68
|
+
this.#dialing = null
|
|
69
|
+
dialing?.close()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Run `fn` after `ms`, unless the connection closes first; the timer never holds the process open. */
|
|
73
|
+
#later(fn: () => void, ms: number): () => void {
|
|
74
|
+
const timer = setTimeout(() => {
|
|
75
|
+
this.#timers.delete(timer)
|
|
76
|
+
fn()
|
|
77
|
+
}, ms)
|
|
78
|
+
;(timer as unknown as { unref?: () => void }).unref?.()
|
|
79
|
+
this.#timers.add(timer)
|
|
80
|
+
return () => {
|
|
81
|
+
clearTimeout(timer)
|
|
82
|
+
this.#timers.delete(timer)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#enqueue(entry: QueueEntry): void {
|
|
87
|
+
const pending = this.#pending
|
|
88
|
+
if (!pending) {
|
|
89
|
+
this.#queue.push(entry)
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
this.#pending = null
|
|
93
|
+
if (entry.type === "value") pending.resolve({ done: false, value: entry.value })
|
|
94
|
+
else if (entry.type === "done") pending.resolve({ done: true, value: undefined })
|
|
95
|
+
else pending.reject(entry.error)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#detach(): void {
|
|
99
|
+
this.#keepalive?.stop()
|
|
100
|
+
this.#keepalive = null
|
|
101
|
+
const conn = this.#conn
|
|
102
|
+
if (!conn) return
|
|
103
|
+
this.#conn = null
|
|
104
|
+
conn.onFrame = () => {}
|
|
105
|
+
conn.onError = () => {}
|
|
106
|
+
conn.onClose = () => {}
|
|
107
|
+
try {
|
|
108
|
+
conn.close()
|
|
109
|
+
} catch {
|
|
110
|
+
/* an adapter's close is best-effort */
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#abort(): void {
|
|
115
|
+
if (this.#state === "closed") return
|
|
116
|
+
this.#end()
|
|
117
|
+
this.#detach()
|
|
118
|
+
this.#enqueue({ error: new RealtimeAbortError("Connection aborted", "aborted"), type: "error" })
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** A frame on a ready connection: a message, a new reconnect token, a pong or the server's goodbye. */
|
|
122
|
+
#onFrame(frame: ServerFrame): void {
|
|
123
|
+
this.#keepalive?.onFrame()
|
|
124
|
+
if (frame.t === "msg") {
|
|
125
|
+
this.#lastEventId = frame.id ?? this.#lastEventId
|
|
126
|
+
this.#reconnectToken = frame.reconnectToken || this.#reconnectToken
|
|
127
|
+
this.#enqueue({ type: "value", value: frame.data })
|
|
128
|
+
} else if (frame.t === "ready") this.#reconnectToken = frame.reconnectToken || this.#reconnectToken
|
|
129
|
+
else if (frame.t === "pong") this.#keepalive?.onPong()
|
|
130
|
+
else {
|
|
131
|
+
this.#detach()
|
|
132
|
+
this.#reconnect()
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Dial adapter `index` with this dial's headers (a function's read now); resolve when ready, frames wired first. */
|
|
137
|
+
#dial(index: number): Promise<TransportConnection> {
|
|
138
|
+
const given = this.#opts.headers
|
|
139
|
+
if (typeof given === "function") return Promise.resolve(given()).then((headers) => this.#dialWith(index, headers))
|
|
140
|
+
return this.#dialWith(index, given)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
#dialWith(index: number, headers: Record<string, string> | undefined): Promise<TransportConnection> {
|
|
144
|
+
return new Promise((resolve, reject) => {
|
|
145
|
+
if (this.#closed) return reject(new RealtimeConnectError("the connection is closed", "closed"))
|
|
146
|
+
const adapter = this.#opts.transports[index] as TransportAdapter
|
|
147
|
+
const opts = { headers, lastEventId: this.#lastEventId, reconnectToken: this.#reconnectToken }
|
|
148
|
+
const conn = adapter.connect(this.#opts.url, { ...opts, signal: this.#opts.signal })
|
|
149
|
+
this.#dialing = conn
|
|
150
|
+
let ready = false
|
|
151
|
+
const cancel = this.#later(() => {
|
|
152
|
+
this.#dialing = null
|
|
153
|
+
conn.close()
|
|
154
|
+
reject(new RealtimeConnectError("transport open timeout", "timeout"))
|
|
155
|
+
}, this.#opts.fallbackTimeout ?? 3000)
|
|
156
|
+
const fail = (error: unknown) => {
|
|
157
|
+
cancel()
|
|
158
|
+
if (this.#dialing === conn) this.#dialing = null
|
|
159
|
+
if (!ready) return reject(error)
|
|
160
|
+
this.#detach()
|
|
161
|
+
if (refused(error)) this.#refuse(error)
|
|
162
|
+
else this.#reconnect()
|
|
163
|
+
}
|
|
164
|
+
conn.onFrame = (frame) => {
|
|
165
|
+
/* a message before ready is kept; a goodbye before ready is the server refusing the open */
|
|
166
|
+
if (ready || frame.t === "msg" || frame.t === "pong") return this.#onFrame(frame)
|
|
167
|
+
if (frame.t === "bye") {
|
|
168
|
+
conn.close()
|
|
169
|
+
return fail(new RealtimeConnectError(`transport refused: ${frame.reason}`, "bye"))
|
|
170
|
+
}
|
|
171
|
+
ready = true
|
|
172
|
+
cancel()
|
|
173
|
+
this.#dialing = null
|
|
174
|
+
/* the connection from its ready frame on, so a drop before the caller resumes is seen */
|
|
175
|
+
this.#conn = conn
|
|
176
|
+
this.#reconnectToken = frame.reconnectToken || this.#reconnectToken
|
|
177
|
+
resolve(conn)
|
|
178
|
+
}
|
|
179
|
+
conn.onError = (err) => {
|
|
180
|
+
if (!ready) conn.close()
|
|
181
|
+
fail(err)
|
|
182
|
+
}
|
|
183
|
+
conn.onClose = (reason) =>
|
|
184
|
+
fail(new RealtimeConnectError(`transport closed before ready: ${reason}`, "closed_early"))
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** The proven transport first, then walkChain. */
|
|
189
|
+
#open(): Promise<TransportConnection> {
|
|
190
|
+
const { transports } = this.#opts
|
|
191
|
+
if (transports.length === 0)
|
|
192
|
+
return Promise.reject(new RealtimeConnectError("No transports configured", "no_transports"))
|
|
193
|
+
const walk = () =>
|
|
194
|
+
walkChain(
|
|
195
|
+
transports.length,
|
|
196
|
+
(i) => this.#dial(i),
|
|
197
|
+
(i) => (this.#proven = i),
|
|
198
|
+
this.#refresh,
|
|
199
|
+
)
|
|
200
|
+
return this.#proven === null ? walk() : this.#dial(this.#proven).catch(walk)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
#watch(conn: TransportConnection): void {
|
|
204
|
+
if (this.#proven === null) return
|
|
205
|
+
this.#keepalive = keepaliveOf(this.#opts.keepaliveInterval, transportAt(this.#proven), conn, () => {
|
|
206
|
+
this.#detach()
|
|
207
|
+
this.#reconnect()
|
|
208
|
+
})
|
|
209
|
+
this.#keepalive?.start()
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async #connect(): Promise<void> {
|
|
213
|
+
if (this.#closed) return
|
|
214
|
+
if (this.#state === "idle") this.#state = "connecting"
|
|
215
|
+
try {
|
|
216
|
+
const conn = await this.#open()
|
|
217
|
+
/* closed, or dropped between its ready frame and here (a reconnect is already scheduled) */
|
|
218
|
+
if (this.#closed || this.#conn !== conn) return
|
|
219
|
+
this.#state = "connected"
|
|
220
|
+
this.#attempts = 0
|
|
221
|
+
this.#watch(conn)
|
|
222
|
+
safely(this.#opts.onReconnected)
|
|
223
|
+
} catch (err) {
|
|
224
|
+
if (refused(err)) this.#refuse(err)
|
|
225
|
+
else this.#reconnect()
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** End the connection with a refusal no retry changes. */
|
|
230
|
+
#refuse(err: unknown): void {
|
|
231
|
+
this.#end()
|
|
232
|
+
this.#enqueue({ error: err, type: "error" })
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** After a drop or a failed open: wait, then dial again; past the attempt cap the stream ends. */
|
|
236
|
+
#reconnect(): void {
|
|
237
|
+
if (this.#closed) return
|
|
238
|
+
this.#attempts += 1
|
|
239
|
+
const max = this.#opts.maxReconnectAttempts ?? 5
|
|
240
|
+
if (max > 0 && this.#attempts > max) {
|
|
241
|
+
this.#end()
|
|
242
|
+
this.#enqueue({ type: "done" })
|
|
243
|
+
return
|
|
244
|
+
}
|
|
245
|
+
this.#state = "reconnecting"
|
|
246
|
+
/* a drop means that transport is not healthy: the next attempt walks the whole chain */
|
|
247
|
+
this.#proven = null
|
|
248
|
+
const attempt = this.#attempts
|
|
249
|
+
safely(() => this.#opts.onReconnecting?.(attempt, transportAt(0)))
|
|
250
|
+
this.#later(() => void this.#connect(), this.#opts.reconnectDelayMs ?? 1000)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
send(data: unknown): Promise<void> {
|
|
254
|
+
return this.sendText(JSON.stringify(data))
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async sendText(text: string): Promise<void> {
|
|
258
|
+
if (!this.#closed) await this.#conn?.send(text)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
close(_reason?: string): void {
|
|
262
|
+
if (this.#state === "closed") return
|
|
263
|
+
this.#end()
|
|
264
|
+
this.#detach()
|
|
265
|
+
this.#enqueue({ type: "done" })
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
#next(): Promise<IteratorResult<unknown>> {
|
|
269
|
+
if (!this.#started && !this.#closed) {
|
|
270
|
+
this.#started = true
|
|
271
|
+
this.#state = "connecting"
|
|
272
|
+
void this.#connect()
|
|
273
|
+
}
|
|
274
|
+
const entry = this.#queue.shift()
|
|
275
|
+
if (entry?.type === "value") return Promise.resolve({ done: false, value: entry.value })
|
|
276
|
+
if (entry?.type === "error") return Promise.reject(entry.error)
|
|
277
|
+
if (entry || this.#closed) return Promise.resolve({ done: true, value: undefined })
|
|
278
|
+
const next = new Promise<IteratorResult<unknown>>((resolve, reject) => {
|
|
279
|
+
this.#pending = { reject, resolve }
|
|
280
|
+
})
|
|
281
|
+
next.catch(() => {})
|
|
282
|
+
return next
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<unknown> {
|
|
286
|
+
const iterator: AsyncIterableIterator<unknown> = {
|
|
287
|
+
next: () => this.#next(),
|
|
288
|
+
[Symbol.asyncIterator]: () => iterator,
|
|
289
|
+
}
|
|
290
|
+
return iterator
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function createResumableConnection(opts: ResumableConnectionOpts): ResumableConnection {
|
|
295
|
+
return new Resumable(opts)
|
|
296
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type HTTPClient, REFRESH_AUTH } from "./http.ts"
|
|
2
|
+
import {
|
|
3
|
+
RealtimeConnectError,
|
|
4
|
+
type ResumableConnectionOpts,
|
|
5
|
+
type ServerFrame,
|
|
6
|
+
type TransportAdapter,
|
|
7
|
+
type TransportConnection,
|
|
8
|
+
type TransportOpts,
|
|
9
|
+
} from "./realtime.ts"
|
|
10
|
+
import { Resumable } from "./realtime-connection.ts"
|
|
11
|
+
import type { RequestOptions } from "./request.ts"
|
|
12
|
+
import { isEventStream, streamOperation } from "./stream.ts"
|
|
13
|
+
import { createTypedWebSocket, wsUrl } from "./ws.ts"
|
|
14
|
+
|
|
15
|
+
type Target = { http: HTTPClient; opts: RequestOptions; path: string }
|
|
16
|
+
|
|
17
|
+
export type RealtimeOptions = Omit<ResumableConnectionOpts, "headers" | "signal" | "transports" | "url">
|
|
18
|
+
|
|
19
|
+
/** A payload's JSON when it parses, else its text. */
|
|
20
|
+
function payloadOf(text: string): unknown {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(text)
|
|
23
|
+
} catch {
|
|
24
|
+
return text
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A payload's frame: `last_event_id` or `id` the cursor (a transport's id first), `reconnect_token` the token. */
|
|
29
|
+
function frameOf(data: unknown, id?: string): Extract<ServerFrame, { t: "msg" }> {
|
|
30
|
+
const fields = (typeof data === "object" && data !== null ? data : {}) as Record<string, unknown>
|
|
31
|
+
const cursor = [fields["last_event_id"], fields["id"]].find((v) => typeof v === "string" || typeof v === "number")
|
|
32
|
+
const reconnectToken = typeof fields["reconnect_token"] === "string" ? fields["reconnect_token"] : undefined
|
|
33
|
+
return { data, id: id ?? (cursor === undefined ? undefined : String(cursor)), reconnectToken, t: "msg" }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ready = (opts: TransportOpts): ServerFrame => ({ reconnectToken: opts.reconnectToken ?? "", t: "ready" })
|
|
37
|
+
|
|
38
|
+
/** The cursor in the query: the reconnect token, and the last event id when `withId`. */
|
|
39
|
+
function cursorOpts(at: Target, opts: TransportOpts, withId: boolean): RequestOptions {
|
|
40
|
+
const search = { ...at.opts.search }
|
|
41
|
+
if (opts.reconnectToken) search["reconnect_token"] = opts.reconnectToken
|
|
42
|
+
if (withId && opts.lastEventId) search["last_event_id"] = opts.lastEventId
|
|
43
|
+
return { ...at.opts, search }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function connection(close: () => void, send: (data: string) => Promise<void> | void): TransportConnection {
|
|
47
|
+
return { close, onClose: () => {}, onError: () => {}, onFrame: () => {}, send }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** An HTTP transport: `run` until closed; a send POSTs through the client. */
|
|
51
|
+
function httpConnection(at: Target, run: (conn: TransportConnection, signal: AbortSignal) => Promise<void>) {
|
|
52
|
+
const abort = new AbortController()
|
|
53
|
+
const post = (data: string) => {
|
|
54
|
+
const value = payloadOf(data)
|
|
55
|
+
const text = { body: new TextEncoder().encode(data), headers: { ...at.opts.headers, "content-type": "text/plain" } }
|
|
56
|
+
return at.http.request("POST", at.path, { ...at.opts, ...(value === data ? text : { json: value }) }).then(() => {})
|
|
57
|
+
}
|
|
58
|
+
const conn = connection(() => abort.abort(), post)
|
|
59
|
+
run(conn, abort.signal).catch((err: unknown) => abort.signal.aborted || conn.onError(err))
|
|
60
|
+
return conn
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The platform WebSocket: no credential; a failure before open is a refused upgrade. */
|
|
64
|
+
function wsAdapter(at: Target): TransportAdapter {
|
|
65
|
+
return {
|
|
66
|
+
connect(_url, opts) {
|
|
67
|
+
const refused = () => new RealtimeConnectError("the WebSocket upgrade failed", "upgrade_refused")
|
|
68
|
+
if (typeof WebSocket === "undefined") {
|
|
69
|
+
const absent = connection(
|
|
70
|
+
() => {},
|
|
71
|
+
() => {},
|
|
72
|
+
)
|
|
73
|
+
queueMicrotask(() => absent.onError(refused()))
|
|
74
|
+
return absent
|
|
75
|
+
}
|
|
76
|
+
const socket = createTypedWebSocket(wsUrl(at.http, at.path, cursorOpts(at, opts, true)))
|
|
77
|
+
const conn = connection(
|
|
78
|
+
() => socket.close(),
|
|
79
|
+
(data) => socket.send(data),
|
|
80
|
+
)
|
|
81
|
+
let open = false
|
|
82
|
+
socket.on("open", () => {
|
|
83
|
+
open = true
|
|
84
|
+
conn.onFrame(ready(opts))
|
|
85
|
+
})
|
|
86
|
+
socket.on("message", (text) => conn.onFrame(frameOf(payloadOf(text))))
|
|
87
|
+
socket.on("error", (err) => conn.onError(open ? err : refused()))
|
|
88
|
+
socket.on("close", (code, reason) => (open ? conn.onClose(reason || `${code}`) : conn.onError(refused())))
|
|
89
|
+
return conn
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** An event stream through the client, Last-Event-ID the cursor; any other answer fails it. */
|
|
95
|
+
function sseAdapter(at: Target): TransportAdapter {
|
|
96
|
+
return {
|
|
97
|
+
connect: (_url, opts) =>
|
|
98
|
+
httpConnection(at, async (conn, signal) => {
|
|
99
|
+
let stream = false
|
|
100
|
+
const events = streamOperation(at.http, {
|
|
101
|
+
method: "GET",
|
|
102
|
+
onOpen: (response) => {
|
|
103
|
+
stream = isEventStream(response)
|
|
104
|
+
if (stream) conn.onFrame(ready(opts))
|
|
105
|
+
},
|
|
106
|
+
opts: { ...cursorOpts(at, opts, false), lastEventId: opts.lastEventId, signal },
|
|
107
|
+
path: at.path,
|
|
108
|
+
refreshes: false,
|
|
109
|
+
})
|
|
110
|
+
for await (const event of events)
|
|
111
|
+
if (stream) conn.onFrame(frameOf(payloadOf(event.data), event.id || undefined))
|
|
112
|
+
if (stream) conn.onClose("end")
|
|
113
|
+
else conn.onError(new RealtimeConnectError("the answer is no event stream", "not_event_stream"))
|
|
114
|
+
}),
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** GETs through the client, the cursor in the query; a 204 polls again. */
|
|
119
|
+
function pollAdapter(at: Target): TransportAdapter {
|
|
120
|
+
return {
|
|
121
|
+
connect: (_url, opts) =>
|
|
122
|
+
httpConnection(at, async (conn, signal) => {
|
|
123
|
+
const cursor = { ...opts }
|
|
124
|
+
for (let polls = 0; !signal.aborted; polls++) {
|
|
125
|
+
const poll = { ...cursorOpts(at, cursor, true), signal }
|
|
126
|
+
const { data } = await at.http.requestOperation({
|
|
127
|
+
method: "GET",
|
|
128
|
+
opts: poll,
|
|
129
|
+
path: at.path,
|
|
130
|
+
refreshes: false,
|
|
131
|
+
})
|
|
132
|
+
if (polls === 0) conn.onFrame(ready(opts))
|
|
133
|
+
if (data === null || data === undefined || data === "") continue
|
|
134
|
+
const frame = frameOf(data)
|
|
135
|
+
cursor.lastEventId = frame.id ?? cursor.lastEventId
|
|
136
|
+
cursor.reconnectToken = frame.reconnectToken || cursor.reconnectToken
|
|
137
|
+
conn.onFrame(frame)
|
|
138
|
+
}
|
|
139
|
+
}),
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** An x-realtime op's chain, as Go's: WebSocket, SSE, long-poll; no JSON keepalive unless set. */
|
|
144
|
+
export function realtimeConnection(http: HTTPClient, path: string, input: RequestOptions & RealtimeOptions): Resumable {
|
|
145
|
+
const { baseURL, cookies, headers, params, search, signal, ...opts } = input
|
|
146
|
+
const at = { http, opts: { baseURL, cookies, headers, params, search }, path }
|
|
147
|
+
const transports = [wsAdapter(at), sseAdapter(at), pollAdapter(at)]
|
|
148
|
+
return new Resumable({ keepaliveInterval: 0, ...opts, signal, transports, url: path }, () => http[REFRESH_AUTH]())
|
|
149
|
+
}
|