@workerstack/clients 0.0.0-stage → 1.0.0-rc.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +619 -2
- package/bin/honey-clients.js +94 -0
- package/dist/cli.d.ts +102 -0
- package/dist/cli.js +190 -0
- package/dist/emit/cli/channels.d.ts +73 -0
- package/dist/emit/cli/channels.js +197 -0
- package/dist/emit/cli/commands.d.ts +27 -0
- package/dist/emit/cli/commands.js +187 -0
- package/dist/emit/cli/discovery.d.ts +35 -0
- package/dist/emit/cli/discovery.js +202 -0
- package/dist/emit/cli/flags.d.ts +59 -0
- package/dist/emit/cli/flags.js +186 -0
- package/dist/emit/cli/index.d.ts +1 -0
- package/dist/emit/cli/index.js +1 -0
- package/dist/emit/cli/install.d.ts +37 -0
- package/dist/emit/cli/install.js +88 -0
- package/dist/emit/cli/layout.d.ts +23 -0
- package/dist/emit/cli/layout.js +118 -0
- package/dist/emit/cli/module.d.ts +30 -0
- package/dist/emit/cli/module.js +186 -0
- package/dist/emit/cli/release.d.ts +40 -0
- package/dist/emit/cli/release.js +183 -0
- package/dist/emit/cli/skills.d.ts +11 -0
- package/dist/emit/cli/skills.js +56 -0
- package/dist/emit/csharp/errors.d.ts +7 -0
- package/dist/emit/csharp/errors.js +69 -0
- package/dist/emit/csharp/index.d.ts +1 -0
- package/dist/emit/csharp/index.js +1 -0
- package/dist/emit/csharp/json.d.ts +13 -0
- package/dist/emit/csharp/json.js +113 -0
- package/dist/emit/csharp/realtime.d.ts +10 -0
- package/dist/emit/csharp/realtime.js +33 -0
- package/dist/emit/csharp/sdk-answer.d.ts +48 -0
- package/dist/emit/csharp/sdk-answer.js +85 -0
- package/dist/emit/csharp/sdk-body.d.ts +10 -0
- package/dist/emit/csharp/sdk-body.js +87 -0
- package/dist/emit/csharp/sdk-client.d.ts +32 -0
- package/dist/emit/csharp/sdk-client.js +177 -0
- package/dist/emit/csharp/sdk-csproj.d.ts +36 -0
- package/dist/emit/csharp/sdk-csproj.js +136 -0
- package/dist/emit/csharp/sdk-doc.d.ts +12 -0
- package/dist/emit/csharp/sdk-doc.js +35 -0
- package/dist/emit/csharp/sdk-method.d.ts +26 -0
- package/dist/emit/csharp/sdk-method.js +187 -0
- package/dist/emit/csharp/sdk-plan.d.ts +38 -0
- package/dist/emit/csharp/sdk-plan.js +1 -0
- package/dist/emit/csharp/sdk.d.ts +40 -0
- package/dist/emit/csharp/sdk.js +105 -0
- package/dist/emit/csharp/sse.d.ts +18 -0
- package/dist/emit/csharp/sse.js +29 -0
- package/dist/emit/csharp/transport.d.ts +11 -0
- package/dist/emit/csharp/transport.js +67 -0
- package/dist/emit/csharp/types-enum.d.ts +19 -0
- package/dist/emit/csharp/types-enum.js +63 -0
- package/dist/emit/csharp/types-names.d.ts +33 -0
- package/dist/emit/csharp/types-names.js +182 -0
- package/dist/emit/csharp/types-record.d.ts +25 -0
- package/dist/emit/csharp/types-record.js +65 -0
- package/dist/emit/csharp/types-union.d.ts +27 -0
- package/dist/emit/csharp/types-union.js +113 -0
- package/dist/emit/csharp/types.d.ts +36 -0
- package/dist/emit/csharp/types.js +126 -0
- package/dist/emit/csharp/ws.d.ts +20 -0
- package/dist/emit/csharp/ws.js +14 -0
- package/dist/emit/go/errors.d.ts +7 -0
- package/dist/emit/go/errors.js +44 -0
- package/dist/emit/go/http.d.ts +11 -0
- package/dist/emit/go/http.js +50 -0
- package/dist/emit/go/index.d.ts +1 -0
- package/dist/emit/go/index.js +1 -0
- package/dist/emit/go/module-path.d.ts +2 -0
- package/dist/emit/go/module-path.js +27 -0
- package/dist/emit/go/sdk-answer.d.ts +28 -0
- package/dist/emit/go/sdk-answer.js +41 -0
- package/dist/emit/go/sdk-body.d.ts +24 -0
- package/dist/emit/go/sdk-body.js +76 -0
- package/dist/emit/go/sdk-client.d.ts +29 -0
- package/dist/emit/go/sdk-client.js +141 -0
- package/dist/emit/go/sdk-method.d.ts +68 -0
- package/dist/emit/go/sdk-method.js +172 -0
- package/dist/emit/go/sdk-mirror.d.ts +23 -0
- package/dist/emit/go/sdk-mirror.js +97 -0
- package/dist/emit/go/sdk-opts.d.ts +55 -0
- package/dist/emit/go/sdk-opts.js +100 -0
- package/dist/emit/go/sdk.d.ts +26 -0
- package/dist/emit/go/sdk.js +111 -0
- package/dist/emit/go/sse.d.ts +16 -0
- package/dist/emit/go/sse.js +26 -0
- package/dist/emit/go/types-codec.d.ts +15 -0
- package/dist/emit/go/types-codec.js +171 -0
- package/dist/emit/go/types-names.d.ts +14 -0
- package/dist/emit/go/types-names.js +64 -0
- package/dist/emit/go/types-struct.d.ts +29 -0
- package/dist/emit/go/types-struct.js +65 -0
- package/dist/emit/go/types-union.d.ts +17 -0
- package/dist/emit/go/types-union.js +84 -0
- package/dist/emit/go/types.d.ts +32 -0
- package/dist/emit/go/types.js +177 -0
- package/dist/emit/go/ws.d.ts +12 -0
- package/dist/emit/go/ws.js +70 -0
- package/dist/emit/java/gradle.d.ts +57 -0
- package/dist/emit/java/gradle.js +221 -0
- package/dist/emit/java/index.d.ts +2 -0
- package/dist/emit/java/index.js +2 -0
- package/dist/emit/java/json.d.ts +13 -0
- package/dist/emit/java/json.js +84 -0
- package/dist/emit/java/layout-ast.d.ts +146 -0
- package/dist/emit/java/layout-ast.js +102 -0
- package/dist/emit/java/layout-decl.d.ts +20 -0
- package/dist/emit/java/layout-decl.js +155 -0
- package/dist/emit/java/layout-doc.d.ts +55 -0
- package/dist/emit/java/layout-doc.js +166 -0
- package/dist/emit/java/layout-dot.d.ts +18 -0
- package/dist/emit/java/layout-dot.js +127 -0
- package/dist/emit/java/layout-strings.d.ts +8 -0
- package/dist/emit/java/layout-strings.js +76 -0
- package/dist/emit/java/layout-types.d.ts +11 -0
- package/dist/emit/java/layout-types.js +95 -0
- package/dist/emit/java/layout-visitor.d.ts +38 -0
- package/dist/emit/java/layout-visitor.js +232 -0
- package/dist/emit/java/layout.d.ts +61 -0
- package/dist/emit/java/layout.js +121 -0
- package/dist/emit/java/models-enum.d.ts +17 -0
- package/dist/emit/java/models-enum.js +51 -0
- package/dist/emit/java/models-names.d.ts +29 -0
- package/dist/emit/java/models-names.js +97 -0
- package/dist/emit/java/models-record.d.ts +24 -0
- package/dist/emit/java/models-record.js +79 -0
- package/dist/emit/java/models-union.d.ts +27 -0
- package/dist/emit/java/models-union.js +86 -0
- package/dist/emit/java/models.d.ts +28 -0
- package/dist/emit/java/models.js +118 -0
- package/dist/emit/java/realtime.d.ts +50 -0
- package/dist/emit/java/realtime.js +69 -0
- package/dist/emit/java/sdk-client.d.ts +66 -0
- package/dist/emit/java/sdk-client.js +207 -0
- package/dist/emit/java/sdk-decl.d.ts +11 -0
- package/dist/emit/java/sdk-decl.js +63 -0
- package/dist/emit/java/sdk-errors.d.ts +13 -0
- package/dist/emit/java/sdk-errors.js +141 -0
- package/dist/emit/java/sdk-headers.d.ts +12 -0
- package/dist/emit/java/sdk-headers.js +74 -0
- package/dist/emit/java/sdk-mirror.d.ts +14 -0
- package/dist/emit/java/sdk-mirror.js +107 -0
- package/dist/emit/java/sdk-models.d.ts +16 -0
- package/dist/emit/java/sdk-models.js +68 -0
- package/dist/emit/java/sdk-op.d.ts +57 -0
- package/dist/emit/java/sdk-op.js +216 -0
- package/dist/emit/java/sdk-params.d.ts +38 -0
- package/dist/emit/java/sdk-params.js +133 -0
- package/dist/emit/java/sdk-plan.d.ts +52 -0
- package/dist/emit/java/sdk-plan.js +1 -0
- package/dist/emit/java/sdk-record.d.ts +16 -0
- package/dist/emit/java/sdk-record.js +99 -0
- package/dist/emit/java/sdk.d.ts +49 -0
- package/dist/emit/java/sdk.js +216 -0
- package/dist/emit/java/sse.d.ts +35 -0
- package/dist/emit/java/sse.js +57 -0
- package/dist/emit/java/ws.d.ts +27 -0
- package/dist/emit/java/ws.js +31 -0
- package/dist/emit/mcp/annotations.d.ts +15 -0
- package/dist/emit/mcp/annotations.js +15 -0
- package/dist/emit/mcp/files.d.ts +18 -0
- package/dist/emit/mcp/files.js +42 -0
- package/dist/emit/mcp/index.d.ts +3 -0
- package/dist/emit/mcp/index.js +3 -0
- package/dist/emit/mcp/literal.d.ts +2 -0
- package/dist/emit/mcp/literal.js +33 -0
- package/dist/emit/mcp/mounted.d.ts +21 -0
- package/dist/emit/mcp/mounted.js +89 -0
- package/dist/emit/mcp/output-schema.d.ts +18 -0
- package/dist/emit/mcp/output-schema.js +38 -0
- package/dist/emit/mcp/registry.d.ts +23 -0
- package/dist/emit/mcp/registry.js +83 -0
- package/dist/emit/mcp/runtime.d.ts +10 -0
- package/dist/emit/mcp/runtime.js +47 -0
- package/dist/emit/mcp/schema.d.ts +19 -0
- package/dist/emit/mcp/schema.js +88 -0
- package/dist/emit/mcp/server.d.ts +30 -0
- package/dist/emit/mcp/server.js +246 -0
- package/dist/emit/mcp/tools.d.ts +51 -0
- package/dist/emit/mcp/tools.js +153 -0
- package/dist/emit/python/errors.d.ts +8 -0
- package/dist/emit/python/errors.js +68 -0
- package/dist/emit/python/index.d.ts +1 -0
- package/dist/emit/python/index.js +1 -0
- package/dist/emit/python/realtime.d.ts +10 -0
- package/dist/emit/python/realtime.js +33 -0
- package/dist/emit/python/sdk-answer.d.ts +49 -0
- package/dist/emit/python/sdk-answer.js +89 -0
- package/dist/emit/python/sdk-body.d.ts +11 -0
- package/dist/emit/python/sdk-body.js +40 -0
- package/dist/emit/python/sdk-client.d.ts +36 -0
- package/dist/emit/python/sdk-client.js +163 -0
- package/dist/emit/python/sdk-doc.d.ts +9 -0
- package/dist/emit/python/sdk-doc.js +32 -0
- package/dist/emit/python/sdk-imports.d.ts +14 -0
- package/dist/emit/python/sdk-imports.js +38 -0
- package/dist/emit/python/sdk-method.d.ts +29 -0
- package/dist/emit/python/sdk-method.js +183 -0
- package/dist/emit/python/sdk-plan.d.ts +33 -0
- package/dist/emit/python/sdk-plan.js +1 -0
- package/dist/emit/python/sdk-pyproject.d.ts +27 -0
- package/dist/emit/python/sdk-pyproject.js +103 -0
- package/dist/emit/python/sdk.d.ts +22 -0
- package/dist/emit/python/sdk.js +154 -0
- package/dist/emit/python/sse.d.ts +12 -0
- package/dist/emit/python/sse.js +23 -0
- package/dist/emit/python/transport.d.ts +15 -0
- package/dist/emit/python/transport.js +60 -0
- package/dist/emit/python/types-dict.d.ts +31 -0
- package/dist/emit/python/types-dict.js +45 -0
- package/dist/emit/python/types-names.d.ts +16 -0
- package/dist/emit/python/types-names.js +52 -0
- package/dist/emit/python/types-union.d.ts +32 -0
- package/dist/emit/python/types-union.js +46 -0
- package/dist/emit/python/types.d.ts +36 -0
- package/dist/emit/python/types.js +128 -0
- package/dist/emit/python/ws.d.ts +14 -0
- package/dist/emit/python/ws.js +16 -0
- package/dist/emit/rust/errors.d.ts +7 -0
- package/dist/emit/rust/errors.js +107 -0
- package/dist/emit/rust/http.d.ts +13 -0
- package/dist/emit/rust/http.js +67 -0
- package/dist/emit/rust/index.d.ts +1 -0
- package/dist/emit/rust/index.js +1 -0
- package/dist/emit/rust/realtime.d.ts +11 -0
- package/dist/emit/rust/realtime.js +29 -0
- package/dist/emit/rust/sdk-body.d.ts +19 -0
- package/dist/emit/rust/sdk-body.js +53 -0
- package/dist/emit/rust/sdk-cargo.d.ts +43 -0
- package/dist/emit/rust/sdk-cargo.js +178 -0
- package/dist/emit/rust/sdk-client.d.ts +25 -0
- package/dist/emit/rust/sdk-client.js +108 -0
- package/dist/emit/rust/sdk-method.d.ts +15 -0
- package/dist/emit/rust/sdk-method.js +119 -0
- package/dist/emit/rust/sdk-opts.d.ts +58 -0
- package/dist/emit/rust/sdk-opts.js +117 -0
- package/dist/emit/rust/sdk-plan.d.ts +33 -0
- package/dist/emit/rust/sdk-plan.js +1 -0
- package/dist/emit/rust/sdk.d.ts +23 -0
- package/dist/emit/rust/sdk.js +111 -0
- package/dist/emit/rust/sse.d.ts +19 -0
- package/dist/emit/rust/sse.js +20 -0
- package/dist/emit/rust/types-enum.d.ts +13 -0
- package/dist/emit/rust/types-enum.js +62 -0
- package/dist/emit/rust/types-names.d.ts +19 -0
- package/dist/emit/rust/types-names.js +66 -0
- package/dist/emit/rust/types-struct.d.ts +21 -0
- package/dist/emit/rust/types-struct.js +59 -0
- package/dist/emit/rust/types-union.d.ts +24 -0
- package/dist/emit/rust/types-union.js +97 -0
- package/dist/emit/rust/types.d.ts +34 -0
- package/dist/emit/rust/types.js +105 -0
- package/dist/emit/rust/ws.d.ts +21 -0
- package/dist/emit/rust/ws.js +20 -0
- package/dist/emit/shared/escape.d.ts +55 -0
- package/dist/emit/shared/escape.js +144 -0
- package/dist/emit/shared/format.d.ts +24 -0
- package/dist/emit/shared/format.js +23 -0
- package/dist/emit/shared/gofmt.d.ts +3 -0
- package/dist/emit/shared/gofmt.js +26 -0
- package/dist/emit/shared/lang.d.ts +60 -0
- package/dist/emit/shared/lang.js +233 -0
- package/dist/emit/shared/literals.d.ts +4 -0
- package/dist/emit/shared/literals.js +31 -0
- package/dist/emit/shared/metadata.d.ts +106 -0
- package/dist/emit/shared/metadata.js +130 -0
- package/dist/emit/shared/mirror.d.ts +22 -0
- package/dist/emit/shared/mirror.js +26 -0
- package/dist/emit/shared/ruff.d.ts +3 -0
- package/dist/emit/shared/ruff.js +31 -0
- package/dist/emit/shared/rustfmt.d.ts +3 -0
- package/dist/emit/shared/rustfmt.js +32 -0
- package/dist/emit/shared/status-keys.d.ts +7 -0
- package/dist/emit/shared/status-keys.js +67 -0
- package/dist/emit/shared/type-emitter.d.ts +19 -0
- package/dist/emit/shared/type-emitter.js +100 -0
- package/dist/emit/ts/app-client.d.ts +4 -0
- package/dist/emit/ts/app-client.js +68 -0
- package/dist/emit/ts/http.d.ts +20 -0
- package/dist/emit/ts/http.js +74 -0
- package/dist/emit/ts/package.d.ts +36 -0
- package/dist/emit/ts/package.js +126 -0
- package/dist/emit/ts/route-tree.d.ts +68 -0
- package/dist/emit/ts/route-tree.js +240 -0
- package/dist/emit/ts/sdk-types-preamble.d.ts +14 -0
- package/dist/emit/ts/sdk-types-preamble.js +123 -0
- package/dist/emit/ts/sdk-types.d.ts +13 -0
- package/dist/emit/ts/sdk-types.js +213 -0
- package/dist/emit/ts/sdk.d.ts +21 -0
- package/dist/emit/ts/sdk.js +173 -0
- package/dist/emit/ts/service-map.d.ts +40 -0
- package/dist/emit/ts/service-map.js +171 -0
- package/dist/emit/ts/tanstack-query.d.ts +12 -0
- package/dist/emit/ts/tanstack-query.js +156 -0
- package/dist/emit/ts/type-gen.d.ts +26 -0
- package/dist/emit/ts/type-gen.js +255 -0
- package/dist/emit/ts/webhooks.d.ts +19 -0
- package/dist/emit/ts/webhooks.js +81 -0
- package/dist/extract/chain.d.ts +34 -0
- package/dist/extract/chain.js +84 -0
- package/dist/extract/extract.d.ts +41 -0
- package/dist/extract/extract.js +191 -0
- package/dist/extract/serialize.d.ts +34 -0
- package/dist/extract/serialize.js +295 -0
- package/dist/extract/walk.d.ts +47 -0
- package/dist/extract/walk.js +109 -0
- package/dist/gen/args.d.ts +28 -0
- package/dist/gen/args.js +133 -0
- package/dist/gen/formatters.d.ts +62 -0
- package/dist/gen/formatters.js +146 -0
- package/dist/gen/process.d.ts +13 -0
- package/dist/gen/process.js +35 -0
- package/dist/gen/shipped.d.ts +17 -0
- package/dist/gen/shipped.js +55 -0
- package/dist/gen/targets.d.ts +93 -0
- package/dist/gen/targets.js +171 -0
- package/dist/gen/write.d.ts +33 -0
- package/dist/gen/write.js +118 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +15 -0
- package/dist/ir/build.d.ts +37 -0
- package/dist/ir/build.js +152 -0
- package/dist/ir/load.d.ts +11 -0
- package/dist/ir/load.js +112 -0
- package/dist/ir/model.d.ts +206 -0
- package/dist/ir/model.js +5 -0
- package/dist/ir/resolve-refs.d.ts +11 -0
- package/dist/ir/resolve-refs.js +66 -0
- package/dist/ir/resource-tree.d.ts +9 -0
- package/dist/ir/resource-tree.js +53 -0
- package/dist/ir/route-tree-intern.d.ts +18 -0
- package/dist/ir/route-tree-intern.js +174 -0
- package/dist/ir/schema.d.ts +11 -0
- package/dist/ir/schema.js +192 -0
- package/dist/ir/sdk-model.d.ts +86 -0
- package/dist/ir/sdk-model.js +204 -0
- package/dist/ir/slots.d.ts +42 -0
- package/dist/ir/slots.js +245 -0
- package/dist/runtime/cli/body.go +176 -0
- package/dist/runtime/cli/config.go +243 -0
- package/dist/runtime/cli/discovery.go +147 -0
- package/dist/runtime/cli/format.go +174 -0
- package/dist/runtime/cli/log.go +117 -0
- package/dist/runtime/cli/output.go +247 -0
- package/dist/runtime/cli/params.go +197 -0
- package/dist/runtime/cli/run.go +226 -0
- package/dist/runtime/cli/socket.go +60 -0
- package/dist/runtime/cli/stream.go +217 -0
- package/dist/runtime/cli/target.go +117 -0
- package/dist/runtime/csharp/Adapters.cs +183 -0
- package/dist/runtime/csharp/Auth.cs +56 -0
- package/dist/runtime/csharp/Body.cs +135 -0
- package/dist/runtime/csharp/Config.cs +161 -0
- package/dist/runtime/csharp/Envelope.cs +149 -0
- package/dist/runtime/csharp/Errors.cs +194 -0
- package/dist/runtime/csharp/Events.cs +155 -0
- package/dist/runtime/csharp/Exchange.cs +247 -0
- package/dist/runtime/csharp/Handler.cs +103 -0
- package/dist/runtime/csharp/Hooks.cs +128 -0
- package/dist/runtime/csharp/Invalidation.cs +102 -0
- package/dist/runtime/csharp/Json.cs +144 -0
- package/dist/runtime/csharp/Log.cs +48 -0
- package/dist/runtime/csharp/Operation.cs +33 -0
- package/dist/runtime/csharp/Path.cs +65 -0
- package/dist/runtime/csharp/Query.cs +72 -0
- package/dist/runtime/csharp/Realtime.cs +118 -0
- package/dist/runtime/csharp/RealtimeLoop.cs +236 -0
- package/dist/runtime/csharp/Redirect.cs +53 -0
- package/dist/runtime/csharp/Result.cs +57 -0
- package/dist/runtime/csharp/Sse.cs +122 -0
- package/dist/runtime/csharp/Stale.cs +151 -0
- package/dist/runtime/csharp/Transport.cs +143 -0
- package/dist/runtime/csharp/TransportLongPoll.cs +63 -0
- package/dist/runtime/csharp/TransportSse.cs +54 -0
- package/dist/runtime/csharp/TransportWs.cs +40 -0
- package/dist/runtime/csharp/Wire.cs +109 -0
- package/dist/runtime/csharp/Ws.cs +300 -0
- package/dist/runtime/csharp/WsDial.cs +127 -0
- package/dist/runtime/go/auth.go +127 -0
- package/dist/runtime/go/body.go +129 -0
- package/dist/runtime/go/config.go +75 -0
- package/dist/runtime/go/errors.go +185 -0
- package/dist/runtime/go/export.go +37 -0
- package/dist/runtime/go/hooks.go +53 -0
- package/dist/runtime/go/invalidation.go +112 -0
- package/dist/runtime/go/log.go +92 -0
- package/dist/runtime/go/nullable.go +64 -0
- package/dist/runtime/go/options.go +118 -0
- package/dist/runtime/go/path.go +156 -0
- package/dist/runtime/go/query.go +147 -0
- package/dist/runtime/go/realtime.go +239 -0
- package/dist/runtime/go/realtime_loop.go +208 -0
- package/dist/runtime/go/redirect.go +124 -0
- package/dist/runtime/go/request.go +222 -0
- package/dist/runtime/go/result.go +86 -0
- package/dist/runtime/go/sse.go +186 -0
- package/dist/runtime/go/stale.go +229 -0
- package/dist/runtime/go/stream.go +105 -0
- package/dist/runtime/go/transport.go +242 -0
- package/dist/runtime/go/transport_longpoll.go +121 -0
- package/dist/runtime/go/transport_sse.go +175 -0
- package/dist/runtime/go/ws.go +205 -0
- package/dist/runtime/java/Answer.java +107 -0
- package/dist/runtime/java/ApiException.java +110 -0
- package/dist/runtime/java/BinaryBody.java +36 -0
- package/dist/runtime/java/Body.java +105 -0
- package/dist/runtime/java/Call.java +23 -0
- package/dist/runtime/java/CallLog.java +51 -0
- package/dist/runtime/java/ClientConfig.java +233 -0
- package/dist/runtime/java/ConnectionState.java +12 -0
- package/dist/runtime/java/Credential.java +58 -0
- package/dist/runtime/java/Deadline.java +38 -0
- package/dist/runtime/java/Decode.java +181 -0
- package/dist/runtime/java/Envelope.java +141 -0
- package/dist/runtime/java/ErrorEnvelope.java +23 -0
- package/dist/runtime/java/EventStream.java +129 -0
- package/dist/runtime/java/Exchange.java +62 -0
- package/dist/runtime/java/FilePart.java +5 -0
- package/dist/runtime/java/Flight.java +306 -0
- package/dist/runtime/java/HoneyException.java +14 -0
- package/dist/runtime/java/Hooks.java +47 -0
- package/dist/runtime/java/Hops.java +133 -0
- package/dist/runtime/java/InvalidationConfig.java +73 -0
- package/dist/runtime/java/Json.java +23 -0
- package/dist/runtime/java/Keepalive.java +60 -0
- package/dist/runtime/java/LogEntry.java +14 -0
- package/dist/runtime/java/LongPollAdapter.java +68 -0
- package/dist/runtime/java/Operation.java +21 -0
- package/dist/runtime/java/Opt.java +121 -0
- package/dist/runtime/java/Pump.java +160 -0
- package/dist/runtime/java/RawResponse.java +48 -0
- package/dist/runtime/java/Realtime.java +152 -0
- package/dist/runtime/java/RealtimeLoop.java +371 -0
- package/dist/runtime/java/RedirectPolicy.java +13 -0
- package/dist/runtime/java/Redirects.java +126 -0
- package/dist/runtime/java/RequestContext.java +78 -0
- package/dist/runtime/java/RequestHook.java +9 -0
- package/dist/runtime/java/RequestOptions.java +91 -0
- package/dist/runtime/java/ResponseContext.java +70 -0
- package/dist/runtime/java/ResponseHook.java +12 -0
- package/dist/runtime/java/Result.java +32 -0
- package/dist/runtime/java/ResumableConnection.java +165 -0
- package/dist/runtime/java/SdkException.java +11 -0
- package/dist/runtime/java/Socket.java +301 -0
- package/dist/runtime/java/Sse.java +171 -0
- package/dist/runtime/java/SseAdapter.java +61 -0
- package/dist/runtime/java/SseEvent.java +10 -0
- package/dist/runtime/java/StaleMeta.java +16 -0
- package/dist/runtime/java/StaleTracker.java +287 -0
- package/dist/runtime/java/Transport.java +16 -0
- package/dist/runtime/java/TransportAdapter.java +14 -0
- package/dist/runtime/java/TransportConnection.java +15 -0
- package/dist/runtime/java/TransportKind.java +12 -0
- package/dist/runtime/java/TransportMessage.java +9 -0
- package/dist/runtime/java/TransportOptions.java +138 -0
- package/dist/runtime/java/TypedWebSocket.java +83 -0
- package/dist/runtime/java/UrlPath.java +49 -0
- package/dist/runtime/java/UrlQuery.java +99 -0
- package/dist/runtime/java/WsAdapter.java +52 -0
- package/dist/runtime/java/WsClose.java +47 -0
- package/dist/runtime/java/WsDial.java +148 -0
- package/dist/runtime/java/WsMessage.java +18 -0
- package/dist/runtime/mcp/call.ts +167 -0
- package/dist/runtime/mcp/files.ts +183 -0
- package/dist/runtime/mcp/guard.ts +176 -0
- package/dist/runtime/mcp/http.ts +159 -0
- package/dist/runtime/mcp/jsonrpc.ts +50 -0
- package/dist/runtime/mcp/listen.ts +76 -0
- package/dist/runtime/mcp/mount.ts +123 -0
- package/dist/runtime/mcp/protocol.ts +219 -0
- package/dist/runtime/mcp/reader.ts +57 -0
- package/dist/runtime/mcp/result.ts +85 -0
- package/dist/runtime/mcp/stdio.ts +79 -0
- package/dist/runtime/mcp/stream.ts +62 -0
- package/dist/runtime/python/__init__.py +2 -0
- package/dist/runtime/python/auth.py +67 -0
- package/dist/runtime/python/body.py +83 -0
- package/dist/runtime/python/config.py +139 -0
- package/dist/runtime/python/errors.py +213 -0
- package/dist/runtime/python/events.py +152 -0
- package/dist/runtime/python/exchange.py +298 -0
- package/dist/runtime/python/hooks.py +86 -0
- package/dist/runtime/python/invalidation.py +57 -0
- package/dist/runtime/python/log.py +60 -0
- package/dist/runtime/python/operation.py +25 -0
- package/dist/runtime/python/path.py +41 -0
- package/dist/runtime/python/query.py +48 -0
- package/dist/runtime/python/realtime.py +244 -0
- package/dist/runtime/python/redirect.py +93 -0
- package/dist/runtime/python/result.py +58 -0
- package/dist/runtime/python/send_async.py +189 -0
- package/dist/runtime/python/send_sync.py +105 -0
- package/dist/runtime/python/sse.py +81 -0
- package/dist/runtime/python/stale.py +94 -0
- package/dist/runtime/python/transport.py +157 -0
- package/dist/runtime/python/transport_longpoll.py +60 -0
- package/dist/runtime/python/transport_sse.py +60 -0
- package/dist/runtime/python/transport_ws.py +57 -0
- package/dist/runtime/python/ws.py +276 -0
- package/dist/runtime/rust/Cargo.lock +1763 -0
- package/dist/runtime/rust/answer.rs +120 -0
- package/dist/runtime/rust/auth.rs +80 -0
- package/dist/runtime/rust/body.rs +150 -0
- package/dist/runtime/rust/call.rs +200 -0
- package/dist/runtime/rust/config.rs +254 -0
- package/dist/runtime/rust/envelope.rs +84 -0
- package/dist/runtime/rust/errors.rs +235 -0
- package/dist/runtime/rust/events.rs +177 -0
- package/dist/runtime/rust/exchange.rs +287 -0
- package/dist/runtime/rust/hooks.rs +63 -0
- package/dist/runtime/rust/invalidation.rs +84 -0
- package/dist/runtime/rust/log.rs +88 -0
- package/dist/runtime/rust/nullable.rs +13 -0
- package/dist/runtime/rust/path.rs +83 -0
- package/dist/runtime/rust/query.rs +84 -0
- package/dist/runtime/rust/realtime.rs +182 -0
- package/dist/runtime/rust/realtime_loop.rs +177 -0
- package/dist/runtime/rust/redirect.rs +121 -0
- package/dist/runtime/rust/request.rs +178 -0
- package/dist/runtime/rust/result.rs +101 -0
- package/dist/runtime/rust/sse.rs +104 -0
- package/dist/runtime/rust/stale.rs +209 -0
- package/dist/runtime/rust/transport.rs +221 -0
- package/dist/runtime/rust/transport_longpoll.rs +108 -0
- package/dist/runtime/rust/transport_sse.rs +91 -0
- package/dist/runtime/rust/transport_ws.rs +75 -0
- package/dist/runtime/rust/ws.rs +322 -0
- package/dist/runtime/ts/app-types.ts +200 -0
- package/dist/runtime/ts/app.ts +104 -0
- package/dist/runtime/ts/config.ts +124 -0
- package/dist/runtime/ts/defaults.ts +48 -0
- package/dist/runtime/ts/error.ts +113 -0
- package/dist/runtime/ts/hooks.ts +92 -0
- package/dist/runtime/ts/http.ts +228 -0
- package/dist/runtime/ts/media-type.ts +36 -0
- package/dist/runtime/ts/path.ts +152 -0
- package/dist/runtime/ts/realtime-connection.ts +296 -0
- package/dist/runtime/ts/realtime-transports.ts +149 -0
- package/dist/runtime/ts/realtime.ts +293 -0
- package/dist/runtime/ts/redirect-policy.ts +17 -0
- package/dist/runtime/ts/redirects.ts +74 -0
- package/dist/runtime/ts/request.ts +239 -0
- package/dist/runtime/ts/response.ts +219 -0
- package/dist/runtime/ts/sdk-realtime.ts +10 -0
- package/dist/runtime/ts/sdk-sse.ts +55 -0
- package/dist/runtime/ts/sdk-ws.ts +21 -0
- package/dist/runtime/ts/sdk.ts +242 -0
- package/dist/runtime/ts/sse.ts +175 -0
- package/dist/runtime/ts/stale.ts +137 -0
- package/dist/runtime/ts/stream.ts +87 -0
- package/dist/runtime/ts/webhook.ts +116 -0
- package/dist/runtime/ts/ws.ts +155 -0
- package/dist/runtime/ts-tanstack-query/invalidate.ts +152 -0
- package/dist/runtime/ts-tanstack-query/query.ts +261 -0
- package/package.json +84 -5
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { ClientError, clientErrorFor, DecodeError } from "./error.ts"
|
|
2
|
+
import { isJsonMediaType, isTextMediaType, parseMediaType } from "./media-type.ts"
|
|
3
|
+
|
|
4
|
+
/** A sent request: its answer, and how to release what it holds once the body is read. */
|
|
5
|
+
export type Sent = {
|
|
6
|
+
done: () => void
|
|
7
|
+
exemptFromTimeout: () => void
|
|
8
|
+
/** a failed body read's error (noAnswer) */
|
|
9
|
+
failed: (cause: unknown) => unknown
|
|
10
|
+
response: Response
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A REST call's answer: its value (the response itself when raw) and the response. */
|
|
14
|
+
export type Answer = { data: unknown; response: Response }
|
|
15
|
+
|
|
16
|
+
/** Object keys of `{ 400: ... }` are `400` or `"400"` depending on the TS version. */
|
|
17
|
+
export type StatusOf<K> = K extends number ? K : K extends `${infer N extends number}` ? N : never
|
|
18
|
+
|
|
19
|
+
/** 0 to N-1 as literals. */
|
|
20
|
+
type Upto<N extends number, A extends number[] = []> = A["length"] extends N ? A[number] : Upto<N, [...A, A["length"]]>
|
|
21
|
+
|
|
22
|
+
/** Each declared status's error, its body typed; the base ClientError at every other error status, 300 to 599. */
|
|
23
|
+
type StatusErrors<E> = [E] extends [never]
|
|
24
|
+
? ClientError
|
|
25
|
+
: [keyof E] extends [never]
|
|
26
|
+
? ClientError
|
|
27
|
+
:
|
|
28
|
+
| { [K in keyof E]: ClientError<E[K]> & { readonly status: StatusOf<K> } }[keyof E]
|
|
29
|
+
| (ClientError & { readonly status: Exclude<Exclude<Upto<600>, Upto<300>>, StatusOf<keyof E>> })
|
|
30
|
+
|
|
31
|
+
/** A safe call's outcome: its data (and declared headers), or the answer's error; the response on both. */
|
|
32
|
+
export type Result<T, TErrors = never, THeaders = never> =
|
|
33
|
+
| ([THeaders] extends [never]
|
|
34
|
+
? { ok: true; data: T; response: Response }
|
|
35
|
+
: { ok: true; data: T; headers: THeaders; response: Response })
|
|
36
|
+
| { ok: false; error: StatusErrors<TErrors> | DecodeError; response: Response }
|
|
37
|
+
|
|
38
|
+
/** How a REST answer is read: parsed or raw, by its declared media type, within the client's limits. */
|
|
39
|
+
export type Reading = {
|
|
40
|
+
/**
|
|
41
|
+
* the non-JSON media type the operation declares: its body is read as that type, empty or not.
|
|
42
|
+
* `null` when it declares no success body: whatever arrives is discarded and reads as null.
|
|
43
|
+
*/
|
|
44
|
+
declared?: string | null | undefined
|
|
45
|
+
/** the client's limits: an error message's characters, and the bytes a body may hold decoded */
|
|
46
|
+
limits?: Limits | undefined
|
|
47
|
+
method: string
|
|
48
|
+
raw?: boolean | undefined
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A server's message as an Error may carry it: ASCII control characters stripped, `max` characters at most. */
|
|
52
|
+
function sanitizeMessage(message: string, max: number): string {
|
|
53
|
+
let out = ""
|
|
54
|
+
for (const ch of message) {
|
|
55
|
+
const code = ch.charCodeAt(0)
|
|
56
|
+
if (code > 31 && code !== 127) out += ch
|
|
57
|
+
}
|
|
58
|
+
return out.slice(0, max)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** What a client bounds an answer to: its error message's characters, and its body's decoded bytes. */
|
|
62
|
+
export type Limits = { readonly maxErrorMessageChars?: number; readonly maxResponseBytes?: number }
|
|
63
|
+
|
|
64
|
+
/** The most bytes a body may hold, decoded, before its read is refused: 100 MiB, as every other SDK's. */
|
|
65
|
+
export const MAX_RESPONSE_BYTES: number = 100 * 1024 * 1024
|
|
66
|
+
|
|
67
|
+
/** `response`'s body, read in the chunks it arrives in, refused past `max` decoded bytes with the body cancelled. */
|
|
68
|
+
async function bodyBytes(response: Response, max = MAX_RESPONSE_BYTES): Promise<Uint8Array> {
|
|
69
|
+
const reader = response.body?.getReader()
|
|
70
|
+
if (reader === undefined) return new Uint8Array(0)
|
|
71
|
+
const chunks: Uint8Array[] = []
|
|
72
|
+
let size = 0
|
|
73
|
+
for (let next = await reader.read(); !next.done; next = await reader.read()) {
|
|
74
|
+
size += next.value.byteLength
|
|
75
|
+
if (size > max) {
|
|
76
|
+
/* not awaited: a cloned body's branch settles its cancel only once its twin cancels too */
|
|
77
|
+
reader.cancel().catch(() => {
|
|
78
|
+
/* the refusal stands whether or not the body cancels cleanly */
|
|
79
|
+
})
|
|
80
|
+
const sent = response.headers.get("content-length")
|
|
81
|
+
const what = [response.headers.get("content-type") ?? "no content type", sent && `${sent} bytes`]
|
|
82
|
+
const message = `Response body is over the ${max}-byte cap (${what.filter(Boolean).join(", ")})`
|
|
83
|
+
throw new DecodeError({ body: null, message, response, status: response.status })
|
|
84
|
+
}
|
|
85
|
+
chunks.push(next.value)
|
|
86
|
+
}
|
|
87
|
+
const bytes = new Uint8Array(size)
|
|
88
|
+
let at = 0
|
|
89
|
+
for (const chunk of chunks) {
|
|
90
|
+
bytes.set(chunk, at)
|
|
91
|
+
at += chunk.byteLength
|
|
92
|
+
}
|
|
93
|
+
return bytes
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** `response`'s body as UTF-8 text, bounded as bodyBytes reads it. */
|
|
97
|
+
const bodyText = async (response: Response, max?: number) => new TextDecoder().decode(await bodyBytes(response, max))
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Read an error body: JSON when it parses, else the text, else null; one past `max` bytes reads as null, and its
|
|
101
|
+
* `preserved` twin is cancelled with it, so the body's source stops.
|
|
102
|
+
*/
|
|
103
|
+
async function readErrorBody(response: Response, preserved: Response, max?: number): Promise<unknown> {
|
|
104
|
+
let text: string
|
|
105
|
+
try {
|
|
106
|
+
text = await bodyText(response, max)
|
|
107
|
+
} catch {
|
|
108
|
+
/* an unreadable body still answers with its status */
|
|
109
|
+
preserved.body?.cancel().catch(() => {
|
|
110
|
+
/* the twin may already be gone */
|
|
111
|
+
})
|
|
112
|
+
return null
|
|
113
|
+
}
|
|
114
|
+
if (text.length === 0) return null
|
|
115
|
+
try {
|
|
116
|
+
return JSON.parse(text)
|
|
117
|
+
} catch {
|
|
118
|
+
/* not JSON: the text itself is the body */
|
|
119
|
+
return text
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The typed error a non-2xx answer becomes, its response kept readable, its body and message bounded by `limits`. */
|
|
124
|
+
export async function errorFromResponse(response: Response, limits: Limits = {}): Promise<ClientError> {
|
|
125
|
+
const preserved = response.clone()
|
|
126
|
+
const body = await readErrorBody(response, preserved, limits.maxResponseBytes)
|
|
127
|
+
const message =
|
|
128
|
+
typeof body === "object" && body !== null && "message" in body
|
|
129
|
+
? (body as Record<string, unknown>)["message"]
|
|
130
|
+
: undefined
|
|
131
|
+
const text =
|
|
132
|
+
typeof message === "string" && message.length > 0
|
|
133
|
+
? `HTTP ${response.status}: ${sanitizeMessage(message, limits.maxErrorMessageChars ?? 512)}`
|
|
134
|
+
: `HTTP ${response.status}`
|
|
135
|
+
return clientErrorFor({ body, message: text, response: preserved, status: response.status })
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** A body with no content to read: 204/205/304 and every answer to HEAD. */
|
|
139
|
+
function hasNoBody(response: Response, method: string): boolean {
|
|
140
|
+
return response.status === 204 || response.status === 205 || response.status === 304 || method === "HEAD"
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A 2xx body as a value. An operation declaring no body (`declared` null) reads as null, as a 204
|
|
145
|
+
* does. A declared text or binary answer reads as that type, so an empty one is `""` or zero bytes;
|
|
146
|
+
* otherwise by its content type: JSON parsed, text as text, anything else as bytes (A1), and null
|
|
147
|
+
* when empty.
|
|
148
|
+
*/
|
|
149
|
+
export async function parseBody(
|
|
150
|
+
response: Response,
|
|
151
|
+
method: string,
|
|
152
|
+
declared?: string | null,
|
|
153
|
+
max?: number,
|
|
154
|
+
): Promise<unknown> {
|
|
155
|
+
if (declared === null || hasNoBody(response, method.toUpperCase())) {
|
|
156
|
+
await response.body?.cancel().catch(() => {
|
|
157
|
+
/* nothing to read: a cancel that fails changes nothing */
|
|
158
|
+
})
|
|
159
|
+
return null
|
|
160
|
+
}
|
|
161
|
+
if (declared !== undefined) {
|
|
162
|
+
if (isTextMediaType(parseMediaType(declared))) return bodyText(response, max)
|
|
163
|
+
return bodyBytes(response, max)
|
|
164
|
+
}
|
|
165
|
+
const type = parseMediaType(response.headers.get("content-type"))
|
|
166
|
+
if (isJsonMediaType(type)) {
|
|
167
|
+
const text = await bodyText(response, max)
|
|
168
|
+
if (text.length === 0) return null
|
|
169
|
+
try {
|
|
170
|
+
return JSON.parse(text)
|
|
171
|
+
} catch (cause) {
|
|
172
|
+
const message = "Response body is not valid JSON"
|
|
173
|
+
throw new DecodeError({ body: text, cause, message, response, status: response.status })
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (isTextMediaType(type)) return bodyText(response, max)
|
|
177
|
+
const bytes = await bodyBytes(response, max)
|
|
178
|
+
return bytes.byteLength === 0 ? null : bytes
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The declared response headers (A2), by lower-case name, each one only when the answer carries it. */
|
|
182
|
+
function declaredHeaders(response: Response, names: readonly string[]): Record<string, string> {
|
|
183
|
+
const out: Record<string, string> = {}
|
|
184
|
+
for (const name of names) {
|
|
185
|
+
const value = response.headers.get(name)
|
|
186
|
+
if (value !== null) out[name] = value
|
|
187
|
+
}
|
|
188
|
+
return out
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* A REST answer read into its value, or the response itself when raw. A non-2xx throws its ClientError, an
|
|
193
|
+
* undecodable 2xx DecodeError, and a body read that fails no answer (f2).
|
|
194
|
+
*/
|
|
195
|
+
export async function finishRequest(sent: Sent, reading: Reading): Promise<Answer> {
|
|
196
|
+
const { response } = sent
|
|
197
|
+
try {
|
|
198
|
+
if (!response.ok) throw await errorFromResponse(response, reading.limits)
|
|
199
|
+
if (reading.raw) return { data: response, response }
|
|
200
|
+
const max = reading.limits?.maxResponseBytes
|
|
201
|
+
return { data: await parseBody(response, reading.method, reading.declared, max), response }
|
|
202
|
+
} catch (e) {
|
|
203
|
+
throw e instanceof ClientError ? e : sent.failed(e)
|
|
204
|
+
} finally {
|
|
205
|
+
sent.done()
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** `answer` as a safe call's Result (bit 21 i): an answer's error its Err; no answer, or none sent, thrown (f2). */
|
|
210
|
+
export async function resultOf(answer: Promise<Answer>, names?: readonly string[]): Promise<Result<unknown>> {
|
|
211
|
+
try {
|
|
212
|
+
const { data, response } = await answer
|
|
213
|
+
const ok: Result<unknown> = { data, ok: true, response }
|
|
214
|
+
return names ? Object.assign(ok, { headers: declaredHeaders(response, names) }) : ok
|
|
215
|
+
} catch (e) {
|
|
216
|
+
if (e instanceof ClientError && e.status !== 0) return { error: e, ok: false, response: e.response }
|
|
217
|
+
throw e
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ResumableConnection } from "./realtime.ts"
|
|
2
|
+
import { type RealtimeOptions, realtimeConnection } from "./realtime-transports.ts"
|
|
3
|
+
import type { RequestOptions } from "./request.ts"
|
|
4
|
+
import { type OperationCall, templateOf } from "./sdk.ts"
|
|
5
|
+
|
|
6
|
+
/** An x-realtime op: one resumable connection per call, dialed through the client. */
|
|
7
|
+
export const realtimeOp: OperationCall =
|
|
8
|
+
(core, entry) =>
|
|
9
|
+
(input: RequestOptions & RealtimeOptions = {}): ResumableConnection =>
|
|
10
|
+
realtimeConnection(core.http, templateOf(entry), input)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { RequestMeta } from "./config.ts"
|
|
2
|
+
import { ClientError } from "./error.ts"
|
|
3
|
+
import { interpolatePath } from "./path.ts"
|
|
4
|
+
import type { RequestOptions } from "./request.ts"
|
|
5
|
+
import { type Answer, resultOf } from "./response.ts"
|
|
6
|
+
import { type OperationCall, optionsFor, type SdkCore, type ServiceEntry, templateOf } from "./sdk.ts"
|
|
7
|
+
import type { SSEEvent } from "./sse.ts"
|
|
8
|
+
import { later, openStream } from "./stream.ts"
|
|
9
|
+
|
|
10
|
+
/** Each event with its `data` parsed as JSON; an event that does not parse fails the stream, naming it. */
|
|
11
|
+
function jsonEvents(events: AsyncIterable<SSEEvent>): AsyncIterable<SSEEvent<unknown>> {
|
|
12
|
+
return {
|
|
13
|
+
async *[Symbol.asyncIterator]() {
|
|
14
|
+
for await (const event of events) {
|
|
15
|
+
let data: unknown
|
|
16
|
+
try {
|
|
17
|
+
data = JSON.parse(event.data)
|
|
18
|
+
} catch (e) {
|
|
19
|
+
const name = event.id === undefined ? "an event" : `event ${JSON.stringify(event.id)}`
|
|
20
|
+
const message = `SSE ${name} is not valid JSON: ${e instanceof Error ? e.message : String(e)}`
|
|
21
|
+
throw new ClientError({ body: event.data, message, response: Response.error(), status: 0 })
|
|
22
|
+
}
|
|
23
|
+
yield { ...event, data }
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** An SSE op opened: its stale view for the hooks, and its `x-invalidate` targets marked once the answer is ok. */
|
|
30
|
+
async function open(core: SdkCore, entry: ServiceEntry, input: RequestOptions): Promise<Answer> {
|
|
31
|
+
const opts = optionsFor(entry, input)
|
|
32
|
+
const template = templateOf(entry)
|
|
33
|
+
let selector: string | undefined
|
|
34
|
+
let meta: RequestMeta | undefined
|
|
35
|
+
try {
|
|
36
|
+
const path = interpolatePath(template, input.params)
|
|
37
|
+
selector = `${entry.method} ${path}`
|
|
38
|
+
meta = core.meta(selector, path, entry.method)
|
|
39
|
+
} catch {
|
|
40
|
+
/* a bad param fails the stream when it is sent, as for any call */
|
|
41
|
+
}
|
|
42
|
+
const onOpen = () => {
|
|
43
|
+
if (selector !== undefined) core.mark(entry, input.params, selector)
|
|
44
|
+
}
|
|
45
|
+
const { data, response } = await openStream(core.http, { meta, method: entry.method, onOpen, opts, path: template })
|
|
46
|
+
return { data: entry.sse === "json" ? jsonEvents(data) : data, response }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** An event stream: sent when iterated, or opened into a Result by the safe twin. */
|
|
50
|
+
export const sseOp: OperationCall = (core, entry, safe) => {
|
|
51
|
+
const opened = (input?: RequestOptions) => open(core, entry, input ?? {})
|
|
52
|
+
return safe
|
|
53
|
+
? (input?: RequestOptions) => resultOf(opened(input))
|
|
54
|
+
: (input?: RequestOptions) => later(() => opened(input))
|
|
55
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { interpolatePath } from "./path.ts"
|
|
2
|
+
import type { RequestOptions } from "./request.ts"
|
|
3
|
+
import { type OperationCall, templateOf } from "./sdk.ts"
|
|
4
|
+
import { createTypedWebSocket, type TypedWebSocket, wsUrl } from "./ws.ts"
|
|
5
|
+
|
|
6
|
+
/** A WebSocket call's input: the request's options, the subprotocols, and a resume token. */
|
|
7
|
+
type WsInput = RequestOptions & { protocols?: string | string[]; reconnectToken?: string }
|
|
8
|
+
|
|
9
|
+
/** A WebSocket op: one socket per call, its `x-invalidate` targets marked once it opens. */
|
|
10
|
+
export const wsOp: OperationCall =
|
|
11
|
+
(core, entry) =>
|
|
12
|
+
(input: WsInput = {}): TypedWebSocket => {
|
|
13
|
+
const url = new URL(wsUrl(core.http, templateOf(entry), { params: input.params, search: input.search }))
|
|
14
|
+
if (input.reconnectToken) url.searchParams.append("reconnect_token", input.reconnectToken)
|
|
15
|
+
const socket = createTypedWebSocket(url.toString(), { protocols: input.protocols })
|
|
16
|
+
if (entry.invalidate?.length) {
|
|
17
|
+
const selector = `WS ${interpolatePath(templateOf(entry), input.params)}`
|
|
18
|
+
socket.on("open", () => core.mark(entry, input.params, selector))
|
|
19
|
+
}
|
|
20
|
+
return socket
|
|
21
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import type { ClientConfig, RequestMeta } from "./config.ts"
|
|
2
|
+
import { ClientError, DecodeError } from "./error.ts"
|
|
3
|
+
import { HTTPClient } from "./http.ts"
|
|
4
|
+
import { interpolatePath, PathParamError } from "./path.ts"
|
|
5
|
+
import { newClientRequestId, type RequestOptions } from "./request.ts"
|
|
6
|
+
import { type Answer, resultOf } from "./response.ts"
|
|
7
|
+
import { resolveInvalidationTargets, StaleIndex } from "./stale.ts"
|
|
8
|
+
|
|
9
|
+
/** One operation as the service map holds it: where it goes and how its answer is read. */
|
|
10
|
+
export type ServiceEntry = {
|
|
11
|
+
/** the declared non-JSON media type, sent as `Accept` */
|
|
12
|
+
accept?: string
|
|
13
|
+
/** the operation declares no success body: a 2xx answer is null, its body reached only through `raw` */
|
|
14
|
+
empty?: boolean
|
|
15
|
+
/** the declared response headers, lower case (A2) */
|
|
16
|
+
headers?: readonly string[]
|
|
17
|
+
idempotent?: boolean
|
|
18
|
+
invalidate?: readonly string[]
|
|
19
|
+
method: string
|
|
20
|
+
params?: readonly string[]
|
|
21
|
+
/** the OpenAPI path template, `{param}` kept */
|
|
22
|
+
path: string
|
|
23
|
+
realtime?: boolean
|
|
24
|
+
/** an event stream; `"json"` when its events carry JSON `data` the client parses */
|
|
25
|
+
sse?: boolean | "json"
|
|
26
|
+
/** the param that spans segments (`x-honey-wildcard`) */
|
|
27
|
+
wildcard?: string
|
|
28
|
+
ws?: boolean
|
|
29
|
+
/** how a stream, WebSocket or realtime operation is called; a REST one has none */
|
|
30
|
+
call?: OperationCall
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ServiceMapNode = ServiceEntry | { readonly [key: string]: ServiceMapNode }
|
|
34
|
+
|
|
35
|
+
export type ServiceMap = { readonly [key: string]: ServiceMapNode }
|
|
36
|
+
|
|
37
|
+
/** Read-after-write tracking: a mutation's `x-invalidate` targets read as stale for `staleTime` ms. */
|
|
38
|
+
export type InvalidationConfig = {
|
|
39
|
+
/** how many mutations a stale mark remembers in `invalidatedBy`. Default 16. */
|
|
40
|
+
maxSourcesPerTarget?: number
|
|
41
|
+
/** how many exact stale marks are kept; past it expired, then the oldest, marks go. Default 1000. */
|
|
42
|
+
staleMaxEntries?: number
|
|
43
|
+
staleTime: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type SDKConfig = ClientConfig & { invalidation?: InvalidationConfig }
|
|
47
|
+
|
|
48
|
+
/** What a REST call takes; a stream, WebSocket or realtime operation's own call types its input further. */
|
|
49
|
+
export type CallInput = RequestOptions
|
|
50
|
+
|
|
51
|
+
export type OperationFn<I = CallInput> = (input?: I) => unknown
|
|
52
|
+
|
|
53
|
+
/** The function a non-REST entry is called through: its own adapter, which the service map names. */
|
|
54
|
+
export type OperationCall = (core: SdkCore, entry: ServiceEntry, safe: boolean) => OperationFn<never>
|
|
55
|
+
|
|
56
|
+
const isEntry = (node: unknown): node is ServiceEntry =>
|
|
57
|
+
typeof node === "object" &&
|
|
58
|
+
node !== null &&
|
|
59
|
+
Object.hasOwn(node, "method") &&
|
|
60
|
+
typeof (node as ServiceEntry).method === "string"
|
|
61
|
+
|
|
62
|
+
/** Only the map's own keys are operations: never `toString`, `constructor` or `then`. */
|
|
63
|
+
const childOf = (node: ServiceMapNode, key: string): ServiceMapNode | undefined =>
|
|
64
|
+
Object.hasOwn(node, key) ? (node as Record<string, ServiceMapNode>)[key] : undefined
|
|
65
|
+
|
|
66
|
+
/** The template the runtime interpolates: a wildcard param's `{name}` becomes the rest-of-path `*name`. */
|
|
67
|
+
export function templateOf(entry: ServiceEntry): string {
|
|
68
|
+
return entry.wildcard === undefined ? entry.path : entry.path.replace(`{${entry.wildcard}}`, `*${entry.wildcard}`)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A call whose path params cannot form a path, as a status-0 ClientError: no request was sent. */
|
|
72
|
+
function pathError(e: PathParamError, entry: ServiceEntry): ClientError {
|
|
73
|
+
return new ClientError({
|
|
74
|
+
body: null,
|
|
75
|
+
message: `${e.message} for ${entry.method} ${entry.path}`,
|
|
76
|
+
response: Response.error(),
|
|
77
|
+
status: 0,
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The per-call options an entry adds: its `Accept` and an `Idempotency-Key`. */
|
|
82
|
+
export function optionsFor(entry: ServiceEntry, input: CallInput): RequestOptions {
|
|
83
|
+
const headers: Record<string, string | undefined> = {}
|
|
84
|
+
if (entry.accept) headers["accept"] = entry.accept
|
|
85
|
+
Object.assign(headers, input.headers)
|
|
86
|
+
if (entry.idempotent && !Object.keys(headers).some((k) => k.toLowerCase() === "idempotency-key"))
|
|
87
|
+
headers["Idempotency-Key"] = input.idempotencyKey ?? newClientRequestId()
|
|
88
|
+
return { ...input, headers }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The client behind a generated SDK class: operations from the service map, read-after-write tracking, dispose. */
|
|
92
|
+
export class SdkCore {
|
|
93
|
+
readonly http: HTTPClient
|
|
94
|
+
readonly #config: SDKConfig
|
|
95
|
+
readonly #disposal = new AbortController()
|
|
96
|
+
#stale: StaleIndex | null
|
|
97
|
+
#seq = 0
|
|
98
|
+
|
|
99
|
+
constructor(config: SDKConfig) {
|
|
100
|
+
this.#config = config
|
|
101
|
+
this.http = new HTTPClient(config, this.#disposal.signal)
|
|
102
|
+
this.#stale = this.#newIndex()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
#newIndex(): StaleIndex | null {
|
|
106
|
+
const invalidation = this.#config.invalidation
|
|
107
|
+
if (!invalidation || invalidation.staleTime <= 0) return null
|
|
108
|
+
const maxSources = Math.max(invalidation.maxSourcesPerTarget ?? 16, 1)
|
|
109
|
+
return new StaleIndex({ maxEntries: invalidation.staleMaxEntries ?? 1000, maxSources })
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
dispose(): void {
|
|
113
|
+
this.#disposal.abort(new Error("The client was disposed"))
|
|
114
|
+
this.#stale = this.#newIndex()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The stale view of the read `selector` before it is sent. */
|
|
118
|
+
meta(selector: string, path: string, method: string): RequestMeta | undefined {
|
|
119
|
+
if (!this.#stale) return undefined
|
|
120
|
+
const { by, isStale } = this.#stale.lookup(selector, path, method, Date.now())
|
|
121
|
+
return { invalidatedBy: by, isStale, selector, seqSnapshot: this.#seq }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Mark what a successful mutation `selector` invalidates. */
|
|
125
|
+
mark(entry: ServiceEntry, params: Record<string, string> | undefined, selector: string): void {
|
|
126
|
+
if (!this.#stale || !entry.invalidate?.length) return
|
|
127
|
+
const now = Date.now()
|
|
128
|
+
const at = { now, seq: ++this.#seq, until: now + (this.#config.invalidation?.staleTime ?? 0) }
|
|
129
|
+
for (const target of resolveInvalidationTargets(entry.invalidate, params)) this.#stale.mark(target, selector, at)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** A REST op's answer, its `x-invalidate` targets marked and its stale mark cleared once it is a 2xx. */
|
|
133
|
+
async request(entry: ServiceEntry, input: CallInput): Promise<Answer> {
|
|
134
|
+
const template = templateOf(entry)
|
|
135
|
+
let path: string
|
|
136
|
+
try {
|
|
137
|
+
path = interpolatePath(template, input.params)
|
|
138
|
+
} catch (e) {
|
|
139
|
+
throw e instanceof PathParamError ? pathError(e, entry) : e
|
|
140
|
+
}
|
|
141
|
+
const selector = `${entry.method} ${path}`
|
|
142
|
+
const meta = this.meta(selector, path, entry.method)
|
|
143
|
+
const opts = optionsFor(entry, input)
|
|
144
|
+
const declared = entry.empty ? null : entry.accept
|
|
145
|
+
const settle = () => {
|
|
146
|
+
this.mark(entry, input.params, selector)
|
|
147
|
+
if (meta?.isStale) this.#stale?.clear(selector, path, entry.method, meta.seqSnapshot)
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
const answer = await this.http.requestOperation({ declared, meta, method: entry.method, opts, path: template })
|
|
151
|
+
settle()
|
|
152
|
+
return answer
|
|
153
|
+
} catch (e) {
|
|
154
|
+
/* a 2xx whose body does not decode still changed what it invalidates */
|
|
155
|
+
if (e instanceof DecodeError) settle()
|
|
156
|
+
throw e
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The function an entry is called through, named by its member path; a safe one's REST answer a Result. */
|
|
162
|
+
function callable(core: SdkCore, entry: ServiceEntry, name: string, safe: boolean): OperationFn<never> {
|
|
163
|
+
let fn: OperationFn<never>
|
|
164
|
+
/* a stream, WebSocket or realtime op is called through the adapter its entry names */
|
|
165
|
+
if (entry.call) fn = entry.call(core, entry, safe)
|
|
166
|
+
else if (safe) fn = (input?: CallInput) => resultOf(core.request(entry, input ?? {}), entry.headers)
|
|
167
|
+
else fn = async (input?: CallInput) => (await core.request(entry, input ?? {})).data
|
|
168
|
+
Object.defineProperty(fn, "name", { value: name })
|
|
169
|
+
return fn
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** A namespace of the map: each read of a key returns the same function or namespace object. */
|
|
173
|
+
function namespace(core: SdkCore, node: ServiceMapNode, path: readonly string[], safe: boolean): object {
|
|
174
|
+
const members = new Map<string, unknown>()
|
|
175
|
+
return new Proxy({} as Record<string, unknown>, {
|
|
176
|
+
get(target, key: string | symbol) {
|
|
177
|
+
if (typeof key === "symbol") return Reflect.get(target, key)
|
|
178
|
+
const child = childOf(node, key)
|
|
179
|
+
if (child === undefined) return Reflect.get(target, key)
|
|
180
|
+
return memberOf(core, members, { child, path: [...path, key], safe })
|
|
181
|
+
},
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
type At = { child: ServiceMapNode; path: string[]; safe: boolean }
|
|
186
|
+
|
|
187
|
+
/** A member at its node and path, the twin's or not, once: a callable for an entry, a namespace object otherwise. */
|
|
188
|
+
function memberOf(core: SdkCore, members: Map<string, unknown>, at: At) {
|
|
189
|
+
const key = at.path.join(".")
|
|
190
|
+
let member = members.get(key)
|
|
191
|
+
if (member === undefined) {
|
|
192
|
+
member = isEntry(at.child) ? callable(core, at.child, key, at.safe) : namespace(core, at.child, at.path, at.safe)
|
|
193
|
+
members.set(key, member)
|
|
194
|
+
}
|
|
195
|
+
return member
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** `config` with the API's auth scheme as its header pair's default. */
|
|
199
|
+
export function schemeAuth<T extends ClientConfig>(config: T, headerName: string, prefix: string): T {
|
|
200
|
+
if (config.authHeaderName !== undefined) return config
|
|
201
|
+
return { ...config, authHeaderName: headerName, authHeaderPrefix: config.authHeaderPrefix ?? prefix }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* A generated SDK's base class. The instance is a Proxy over the service map: `sdk.users.create(input)`
|
|
206
|
+
* dispatches the entry at `users.create`; the client's own members (`safe`, `state`, `dispose`, `toString`)
|
|
207
|
+
* always win, and a key the map does not hold reads as `undefined`.
|
|
208
|
+
*/
|
|
209
|
+
export class SDKClient {
|
|
210
|
+
/** the same operations, each answering a Result, never throwing an API answer (bit 21 i) */
|
|
211
|
+
readonly safe: object
|
|
212
|
+
state: Record<string, unknown>
|
|
213
|
+
readonly #core: SdkCore
|
|
214
|
+
|
|
215
|
+
constructor(serviceMap: ServiceMap, config: SDKConfig) {
|
|
216
|
+
this.state = config.state ?? {}
|
|
217
|
+
this.#core = new SdkCore({ ...config, state: this.state })
|
|
218
|
+
const core = this.#core
|
|
219
|
+
this.safe = namespace(core, serviceMap, [], true)
|
|
220
|
+
const members = new Map<string, unknown>()
|
|
221
|
+
return new Proxy(this, {
|
|
222
|
+
get(target, key: string | symbol) {
|
|
223
|
+
if (typeof key === "symbol" || key in target) {
|
|
224
|
+
const value: unknown = Reflect.get(target, key)
|
|
225
|
+
return typeof value === "function" ? value.bind(target) : value
|
|
226
|
+
}
|
|
227
|
+
const child = childOf(serviceMap, key)
|
|
228
|
+
return child === undefined ? undefined : memberOf(core, members, { child, path: [key], safe: false })
|
|
229
|
+
},
|
|
230
|
+
})
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Printable: `String(sdk)` is `[object <SdkName>]`. */
|
|
234
|
+
get [Symbol.toStringTag](): string {
|
|
235
|
+
return this.constructor.name
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** Abort every call in flight, refuse later ones, and drop the stale marks. */
|
|
239
|
+
dispose(): void {
|
|
240
|
+
this.#core.dispose()
|
|
241
|
+
}
|
|
242
|
+
}
|