@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,29 @@
|
|
|
1
|
+
import { eventType, isLastEventIdHeader, LAST_EVENT_ID } from "./sse.js";
|
|
2
|
+
import { isReconnectToken, PROTOCOLS, RECONNECT_TOKEN } from "./ws.js";
|
|
3
|
+
/* the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID */
|
|
4
|
+
const REALTIME = {
|
|
5
|
+
carries: (param, where) => isReconnectToken(param, where) ||
|
|
6
|
+
(where === "query" && param === "last_event_id") ||
|
|
7
|
+
isLastEventIdHeader(param, where),
|
|
8
|
+
fields: [
|
|
9
|
+
LAST_EVENT_ID,
|
|
10
|
+
RECONNECT_TOKEN,
|
|
11
|
+
PROTOCOLS,
|
|
12
|
+
{ doc: "Reconnects after a drop; 5 when None.", ident: "max_reconnect_attempts", type: "Option<u32>" },
|
|
13
|
+
{
|
|
14
|
+
doc: "The first backoff delay in milliseconds; 1000 when None.",
|
|
15
|
+
ident: "reconnect_delay_ms",
|
|
16
|
+
type: "Option<u64>",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
sends: [],
|
|
20
|
+
};
|
|
21
|
+
/* the realtime Opts' own fields, each the TransportOpts field of its name */
|
|
22
|
+
const TRANSPORT_OPTS = "TransportOpts { last_event_id: opts.last_event_id.clone(), reconnect_token: opts.reconnect_token.clone(), protocols: opts.protocols.clone(), max_reconnect_attempts: opts.max_reconnect_attempts, reconnect_delay_ms: opts.reconnect_delay_ms }";
|
|
23
|
+
const DOC = "Resolves once the connection is open over WebSocket, else SSE, else long-poll; `recv` reconnects after a drop and resumes after the last message it delivered. `cancel_on` ends it quietly; dropping it closes it.";
|
|
24
|
+
/** The realtime operation `op`'s answer. */
|
|
25
|
+
export function realtimeAnswer(op, at) {
|
|
26
|
+
const events = eventType(op, at, "serde_json::Value");
|
|
27
|
+
const run = `crate::realtime_loop::connect::<${events}>(${TRANSPORT_OPTS})`;
|
|
28
|
+
return { doc: DOC, run, stream: REALTIME, type: `ResumableConnection<${events}>` };
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Rust method's request body (G4), by its declared kind: JSON and a form as a borrowed `&<T>` encoded at
|
|
3
|
+
* once, text as `&str`, binary as the runtime's `Body`, and multipart as a borrowed `<Op>Body` hoisted beside
|
|
4
|
+
* the API's types: a text part as `Option<T>` (a list as `Vec<T>`), a file part as `Option<FilePart>` (a list
|
|
5
|
+
* as `Vec<FilePart>`), each added to the runtime's encoder by name. Spec text reaches the source only through
|
|
6
|
+
* the shared escape layer.
|
|
7
|
+
*/
|
|
8
|
+
import type { IRSchema } from "../../ir/model.ts";
|
|
9
|
+
import type { SdkBody, SdkOp } from "../../ir/sdk-model.ts";
|
|
10
|
+
import { type RustTypeContext } from "./types.ts";
|
|
11
|
+
/** A method's body: its parameter's type, and the statements encoding it into `spec`. */
|
|
12
|
+
export type RustBody = {
|
|
13
|
+
readonly type: string;
|
|
14
|
+
readonly lines: readonly string[];
|
|
15
|
+
};
|
|
16
|
+
/** `schema`'s Rust type at `<parent><field>`, a component reference unboxed. */
|
|
17
|
+
export declare const typeAt: (schema: IRSchema, parent: string, field: string, at: RustTypeContext) => string;
|
|
18
|
+
/** The body of `op` as its method takes it, and the statements encoding it into the spec at once. */
|
|
19
|
+
export declare function rustBody(op: SdkOp, body: SdkBody, at: RustTypeContext): RustBody;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { lineComment, rustString } from "../shared/escape.js";
|
|
2
|
+
import { compareCodeUnits, NameScope, rustTypeIdent, rustValueIdent } from "../shared/lang.js";
|
|
3
|
+
import { unboxed } from "./types-struct.js";
|
|
4
|
+
import { rustTypeOf } from "./types.js";
|
|
5
|
+
/** `schema`'s Rust type at `<parent><field>`, a component reference unboxed. */
|
|
6
|
+
export const typeAt = (schema, parent, field, at) => unboxed(schema, rustTypeOf(schema, { ...at, fieldName: field, parentName: parent }));
|
|
7
|
+
/** The field of `part` named `ident` on the struct `parent`: its type by the part's kind, and its statement. */
|
|
8
|
+
function partField(part, ident, parent, at) {
|
|
9
|
+
/* the IR gives every part its schema (ir/slots.ts partsOf) */
|
|
10
|
+
const declared = part.schema;
|
|
11
|
+
const schema = at.names.resolve(declared);
|
|
12
|
+
const call = part.type === "file" ? "files" : "text";
|
|
13
|
+
const line = `form.${call}(${rustString(part.name)}, &body.${ident});`;
|
|
14
|
+
if (part.type === "file") {
|
|
15
|
+
return { decl: schema.kind === "array" ? "Vec<crate::FilePart>" : "Option<crate::FilePart>", line };
|
|
16
|
+
}
|
|
17
|
+
if (schema.kind === "array")
|
|
18
|
+
return { decl: `Vec<${typeAt(schema.items, parent, part.name, at)}>`, line };
|
|
19
|
+
return { decl: `Option<${typeAt(declared, parent, part.name, at)}>`, line };
|
|
20
|
+
}
|
|
21
|
+
/** A multipart body: `<Op>Body` hoisted into `at.decls`, a field per part in name order, and the encoder filled from it. */
|
|
22
|
+
function multipartBody(op, parts, at) {
|
|
23
|
+
const type = at.names.claim(`${rustTypeIdent(op.id)}Body`);
|
|
24
|
+
const scope = new NameScope();
|
|
25
|
+
const sorted = [...parts].sort((a, b) => compareCodeUnits(a.name, b.name));
|
|
26
|
+
const fields = sorted.map((part) => {
|
|
27
|
+
const ident = scope.claim(rustValueIdent(part.name));
|
|
28
|
+
return { ident, ...partField(part, ident, type, at) };
|
|
29
|
+
});
|
|
30
|
+
const doc = `The multipart/form-data parts of ${op.id}'s body: None and an empty list send no part.`;
|
|
31
|
+
/* never empty: a body is multipart only with a file part (ir/slots.ts bodyOf) */
|
|
32
|
+
const decl = [
|
|
33
|
+
...lineComment(doc, "///"),
|
|
34
|
+
"#[derive(Debug, Clone, Default)]",
|
|
35
|
+
`pub struct ${type} {`,
|
|
36
|
+
...fields.map((f) => ` pub ${f.ident}: ${f.decl},`),
|
|
37
|
+
"}",
|
|
38
|
+
];
|
|
39
|
+
at.decls.set(type, decl.join("\n"));
|
|
40
|
+
const lines = ["let mut form = crate::body::Multipart::new();", ...fields.map((f) => f.line), "spec.multipart(form);"];
|
|
41
|
+
return { lines, type: `&${type}` };
|
|
42
|
+
}
|
|
43
|
+
/** The body of `op` as its method takes it, and the statements encoding it into the spec at once. */
|
|
44
|
+
export function rustBody(op, body, at) {
|
|
45
|
+
if (body.kind === "multipart")
|
|
46
|
+
return multipartBody(op, body.parts, at);
|
|
47
|
+
const media = rustString(body.contentType);
|
|
48
|
+
if (body.kind === "text")
|
|
49
|
+
return { lines: [`spec.text(body, ${media});`], type: "&str" };
|
|
50
|
+
if (body.kind === "binary")
|
|
51
|
+
return { lines: [`spec.binary(body, ${media});`], type: "Body" };
|
|
52
|
+
return { lines: [`spec.${body.kind}(body, ${media});`], type: `&${typeAt(body.schema, op.id, "Body", at)}` };
|
|
53
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type Shipped } from "../shared/metadata.ts";
|
|
2
|
+
/** The emitted `rust-version`: the toolchain floor every SDK builds with (Fb2). */
|
|
3
|
+
export declare const RUST_VERSION = "1.85";
|
|
4
|
+
/** The emitted edition, which the floor forces. */
|
|
5
|
+
export declare const EDITION = "2024";
|
|
6
|
+
/** The crate's name and version as Cargo.toml and the lock root carry them, and the metadata crates.io shows. */
|
|
7
|
+
export type CrateIdentity = {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly version: string;
|
|
10
|
+
/** what crates.io shows and `cargo publish` requires; left out when the caller names none */
|
|
11
|
+
readonly description?: string;
|
|
12
|
+
readonly documentation?: string;
|
|
13
|
+
readonly homepage?: string;
|
|
14
|
+
readonly keywords?: readonly string[];
|
|
15
|
+
readonly categories?: readonly string[];
|
|
16
|
+
readonly license?: string;
|
|
17
|
+
readonly repository?: string;
|
|
18
|
+
};
|
|
19
|
+
/** The crate options as a run gives them: a list as a list, or the CLI's comma-separated value. */
|
|
20
|
+
export type CrateOptions = {
|
|
21
|
+
readonly crateName?: string;
|
|
22
|
+
readonly version?: string;
|
|
23
|
+
readonly description?: string;
|
|
24
|
+
readonly documentation?: string;
|
|
25
|
+
readonly homepage?: string;
|
|
26
|
+
readonly keywords?: readonly string[] | string;
|
|
27
|
+
readonly categories?: readonly string[] | string;
|
|
28
|
+
readonly license?: string;
|
|
29
|
+
readonly repository?: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The crate `options` give, each value checked against the grammar every target shares and crates.io's own limits
|
|
33
|
+
* before it reaches a TOML string: what `cargo publish` would refuse is refused at generate, naming the option.
|
|
34
|
+
*/
|
|
35
|
+
export declare function crateIdentity(options: CrateOptions): CrateIdentity;
|
|
36
|
+
/** Cargo.toml: the package at the floor, the library `sdk`, the dependencies (`tokio-tungstenite` only when `ws`). */
|
|
37
|
+
export declare function cargoToml(crate: CrateIdentity, ws: boolean, shipped?: Shipped): string;
|
|
38
|
+
/**
|
|
39
|
+
* The crate's Cargo.lock from `template`: the root entry as `crate`, at its name's place among the packages;
|
|
40
|
+
* without `ws`, `tokio-tungstenite` and every package only it reached gone. A crate named like a locked
|
|
41
|
+
* package is refused: the lock could not tell the two apart.
|
|
42
|
+
*/
|
|
43
|
+
export declare function cargoLock(template: string, crate: CrateIdentity, ws: boolean): string;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The crate's manifest and lock (contract 18 §5.2). `Cargo.toml` declares the trimmed dependency set (G9)
|
|
3
|
+
* at caret floors equal to the locked versions (Fb7), `tokio-tungstenite` only for a WebSocket or realtime
|
|
4
|
+
* API (Fb3). `Cargo.lock` is cut from the one committed template: its root entry renamed to the crate, and
|
|
5
|
+
* for an HTTP-only crate every package only `tokio-tungstenite` reached dropped, each reference then written
|
|
6
|
+
* as cargo writes it, so `--locked` accepts the lock as it is.
|
|
7
|
+
*/
|
|
8
|
+
import { compareCodeUnits } from "../shared/lang.js";
|
|
9
|
+
import { checked, HTTPS_URL, LICENSE, README, SPDX_EXPRESSION, TEXT } from "../shared/metadata.js";
|
|
10
|
+
/** The emitted `rust-version`: the toolchain floor every SDK builds with (Fb2). */
|
|
11
|
+
export const RUST_VERSION = "1.85";
|
|
12
|
+
/** The emitted edition, which the floor forces. */
|
|
13
|
+
export const EDITION = "2024";
|
|
14
|
+
/* a crate that ships nothing beside its code */
|
|
15
|
+
const NONE_SHIPPED = { icon: undefined, licenseFile: false, readme: false };
|
|
16
|
+
/* the dependency the WebSocket and realtime runtime files need, and only they */
|
|
17
|
+
const WEBSOCKET = "tokio-tungstenite";
|
|
18
|
+
/* each dependency's requirement line, in name order: the floors are the template lock's versions */
|
|
19
|
+
const DEPENDENCIES = [
|
|
20
|
+
["bytes", '"1.12.1"'],
|
|
21
|
+
["futures-util", '{ version = "0.3.34", default-features = false, features = ["std", "sink"] }'],
|
|
22
|
+
[
|
|
23
|
+
"reqwest",
|
|
24
|
+
'{ version = "0.13.5", default-features = false, features = ["rustls", "json", "stream", "gzip", "deflate"] }',
|
|
25
|
+
],
|
|
26
|
+
["serde", '{ version = "1.0.229", features = ["derive"] }'],
|
|
27
|
+
["serde_json", '"1.0.154"'],
|
|
28
|
+
["tokio", '{ version = "1.53.3", features = ["rt", "macros", "time", "sync"] }'],
|
|
29
|
+
[WEBSOCKET, '{ version = "0.30.0", default-features = false, features = ["connect", "rustls-tls-native-roots"] }'],
|
|
30
|
+
["url", '"2.5.8"'],
|
|
31
|
+
];
|
|
32
|
+
const MARKER = "# @generated by honey. DO NOT EDIT.";
|
|
33
|
+
/* a semver version: it lands inside a TOML string, so nothing else may */
|
|
34
|
+
const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
35
|
+
/* crates.io's keyword: ASCII, a letter or digit first, then letters, digits, `_`, `-` or `+`, at most 20 characters;
|
|
36
|
+
* a category: a slug as https://crates.io/category_slugs lists them, which crates.io matches exactly; five of each */
|
|
37
|
+
const CRATE_KEYWORD = /^[A-Za-z0-9][A-Za-z0-9_+-]{0,19}$/;
|
|
38
|
+
const CATEGORY = /^[a-z0-9-]+(?:::[a-z0-9-]+)*$/;
|
|
39
|
+
const MAX_LISTED = 5;
|
|
40
|
+
/** A list option as a list, each entry checked against `grammar`, at most five: crates.io's limit for both lists. */
|
|
41
|
+
function listed(option, value, grammar) {
|
|
42
|
+
if (value === undefined)
|
|
43
|
+
return undefined;
|
|
44
|
+
const list = (typeof value === "string" ? value.split(",") : value).map((word) => word.trim()).filter(Boolean);
|
|
45
|
+
for (const word of list)
|
|
46
|
+
checked(option, word, grammar);
|
|
47
|
+
if (list.length > MAX_LISTED)
|
|
48
|
+
throw new Error(`Invalid ${option}: crates.io takes at most ${MAX_LISTED}, given ${JSON.stringify(list)}`);
|
|
49
|
+
return list.length === 0 ? undefined : list;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The crate `options` give, each value checked against the grammar every target shares and crates.io's own limits
|
|
53
|
+
* before it reaches a TOML string: what `cargo publish` would refuse is refused at generate, naming the option.
|
|
54
|
+
*/
|
|
55
|
+
export function crateIdentity(options) {
|
|
56
|
+
return {
|
|
57
|
+
categories: listed("categories", options.categories, CATEGORY),
|
|
58
|
+
description: checked("description", options.description, TEXT),
|
|
59
|
+
documentation: checked("documentation", options.documentation, HTTPS_URL),
|
|
60
|
+
homepage: checked("homepage", options.homepage, HTTPS_URL),
|
|
61
|
+
keywords: listed("keywords", options.keywords, CRATE_KEYWORD),
|
|
62
|
+
license: checked("license", options.license, SPDX_EXPRESSION),
|
|
63
|
+
name: validateCrateName(options.crateName ?? "honey-sdk"),
|
|
64
|
+
repository: checked("repository", options.repository, HTTPS_URL),
|
|
65
|
+
version: validateCrateVersion(options.version ?? "0.1.0"),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** `name` as a crate name, else throws: lower case, a letter first, then letters, digits, `_` and `-`. */
|
|
69
|
+
function validateCrateName(name) {
|
|
70
|
+
if (!/^[a-z][a-z0-9_-]*$/.test(name))
|
|
71
|
+
throw new Error(`Invalid crate name: ${JSON.stringify(name)}`);
|
|
72
|
+
return name;
|
|
73
|
+
}
|
|
74
|
+
/** `version` as a crate version, else throws: a semver version. */
|
|
75
|
+
function validateCrateVersion(version) {
|
|
76
|
+
if (!SEMVER.test(version))
|
|
77
|
+
throw new Error(`Invalid crate version: ${JSON.stringify(version)}`);
|
|
78
|
+
return version;
|
|
79
|
+
}
|
|
80
|
+
/** The `[package]` metadata lines the caller gave, in Cargo's order; a crate without them publishes nowhere. */
|
|
81
|
+
function metadata(crate) {
|
|
82
|
+
const fields = [
|
|
83
|
+
["description", crate.description],
|
|
84
|
+
["documentation", crate.documentation],
|
|
85
|
+
["license", crate.license],
|
|
86
|
+
["repository", crate.repository],
|
|
87
|
+
["homepage", crate.homepage],
|
|
88
|
+
["keywords", crate.keywords],
|
|
89
|
+
["categories", crate.categories],
|
|
90
|
+
];
|
|
91
|
+
return fields.flatMap(([key, value]) => (value === undefined ? [] : [`${key} = ${toml(value)}`]));
|
|
92
|
+
}
|
|
93
|
+
/** A string or a list of them as TOML: JSON's string escapes are TOML's, for the text the grammars let through. */
|
|
94
|
+
const toml = (value) => typeof value === "string" ? JSON.stringify(value) : `[${value.map((word) => JSON.stringify(word)).join(", ")}]`;
|
|
95
|
+
/** Cargo.toml: the package at the floor, the library `sdk`, the dependencies (`tokio-tungstenite` only when `ws`). */
|
|
96
|
+
export function cargoToml(crate, ws, shipped = NONE_SHIPPED) {
|
|
97
|
+
const dependencies = DEPENDENCIES.filter(([name]) => ws || name !== WEBSOCKET);
|
|
98
|
+
return [
|
|
99
|
+
MARKER,
|
|
100
|
+
"[package]",
|
|
101
|
+
`name = "${crate.name}"`,
|
|
102
|
+
`version = "${crate.version}"`,
|
|
103
|
+
`edition = "${EDITION}"`,
|
|
104
|
+
`rust-version = "${RUST_VERSION}"`,
|
|
105
|
+
/* the metadata crates.io reads: each line only when the caller gave it */
|
|
106
|
+
...metadata(crate),
|
|
107
|
+
...(shipped.readme ? [`readme = "${README}"`] : []),
|
|
108
|
+
/* what the published crate holds beside Cargo.toml and its lock, which cargo always packs: its README and
|
|
109
|
+
* license file when it ships them; honey's manifest and anything else written beside the crate stay out */
|
|
110
|
+
`include = ${toml(["/src", ...(shipped.readme ? [`/${README}`] : []), ...(shipped.licenseFile ? [`/${LICENSE}`] : [])])}`,
|
|
111
|
+
"",
|
|
112
|
+
"[lib]",
|
|
113
|
+
'name = "sdk"',
|
|
114
|
+
'path = "src/lib.rs"',
|
|
115
|
+
"",
|
|
116
|
+
"[dependencies]",
|
|
117
|
+
...dependencies.map(([name, requirement]) => `${name} = ${requirement}`),
|
|
118
|
+
"",
|
|
119
|
+
].join("\n");
|
|
120
|
+
}
|
|
121
|
+
const SEPARATOR = "\n[[package]]\n";
|
|
122
|
+
/** The value of `key = "…"` in a package's text. */
|
|
123
|
+
const field = (text, key) => new RegExp(`^${key} = "([^"]*)"$`, "m").exec(text)?.[1];
|
|
124
|
+
function parsed(text) {
|
|
125
|
+
return {
|
|
126
|
+
dependencies: [...text.matchAll(/^ "([^"]+)",$/gm)].map((match) => match[1]),
|
|
127
|
+
name: field(text, "name"),
|
|
128
|
+
root: !/^source = /m.test(text),
|
|
129
|
+
text,
|
|
130
|
+
version: field(text, "version"),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** The package a dependency reference (`name`, `name version` or `name version (source)`) names. */
|
|
134
|
+
function resolve(packages, reference) {
|
|
135
|
+
const [name, version] = reference.split(" ");
|
|
136
|
+
return packages.find((p) => p.name === name && (version === undefined || p.version === version));
|
|
137
|
+
}
|
|
138
|
+
/** `root` and every package it reaches. */
|
|
139
|
+
function reachable(packages, root) {
|
|
140
|
+
const seen = new Set();
|
|
141
|
+
const stack = [root];
|
|
142
|
+
for (let at = stack.pop(); at !== undefined; at = stack.pop()) {
|
|
143
|
+
if (seen.has(at))
|
|
144
|
+
continue;
|
|
145
|
+
seen.add(at);
|
|
146
|
+
stack.push(...at.dependencies.map((reference) => resolve(packages, reference)));
|
|
147
|
+
}
|
|
148
|
+
return packages.filter((p) => seen.has(p));
|
|
149
|
+
}
|
|
150
|
+
/** A dependency list line as cargo writes it: the version only while another version of the name is locked. */
|
|
151
|
+
function referenced(kept, reference) {
|
|
152
|
+
const name = reference.split(" ")[0];
|
|
153
|
+
return kept.filter((p) => p.name === name).length > 1 ? reference : name;
|
|
154
|
+
}
|
|
155
|
+
/** `p`'s text with every dependency reference rewritten for `kept`. */
|
|
156
|
+
const rewritten = (p, kept) => p.text.replace(/^ "([^"]+)",$/gm, (_, reference) => ` "${referenced(kept, reference)}",`);
|
|
157
|
+
/** The root entry as `crate`, without `tokio-tungstenite` unless `ws`. */
|
|
158
|
+
function rootOf(root, crate, ws) {
|
|
159
|
+
const named = root.text
|
|
160
|
+
.replace(/^name = ".*"$/m, `name = "${crate.name}"`)
|
|
161
|
+
.replace(/^version = ".*"$/m, `version = "${crate.version}"`);
|
|
162
|
+
return parsed(ws ? named : named.replace(new RegExp(`^ "${WEBSOCKET}( [^"]*)?",\\n`, "m"), ""));
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The crate's Cargo.lock from `template`: the root entry as `crate`, at its name's place among the packages;
|
|
166
|
+
* without `ws`, `tokio-tungstenite` and every package only it reached gone. A crate named like a locked
|
|
167
|
+
* package is refused: the lock could not tell the two apart.
|
|
168
|
+
*/
|
|
169
|
+
export function cargoLock(template, crate, ws) {
|
|
170
|
+
const [head, ...blocks] = template.split(SEPARATOR);
|
|
171
|
+
const packages = blocks.map(parsed);
|
|
172
|
+
if (packages.some((p) => !p.root && p.name === crate.name))
|
|
173
|
+
throw new Error(`Invalid crate name: ${JSON.stringify(crate.name)} is a dependency's name`);
|
|
174
|
+
const all = packages.map((p) => (p.root ? rootOf(p, crate, ws) : p));
|
|
175
|
+
const kept = reachable(all, all.find((p) => p.root));
|
|
176
|
+
const ordered = kept.toSorted((a, b) => compareCodeUnits(a.name, b.name));
|
|
177
|
+
return [head, ...ordered.map((p) => rewritten(p, kept))].join(SEPARATOR);
|
|
178
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* client.rs's body (G1): `Client::new` (the API's first server as the default `base_url`, its auth scheme as
|
|
3
|
+
* the default header), an accessor per top-level namespace of `IR.tree`, a `<Path>Resource<'a, S>` per nested
|
|
4
|
+
* namespace borrowing the client, every operation a method on the type of its namespace, and each method's
|
|
5
|
+
* `<Op>Opts` and `<Op>Headers` after them in name order. Every accessor and method is the client's style's
|
|
6
|
+
* (bit 21 i4): `Client<S>` and each resource take `S`, so `client.safe()` (the runtime's `Client<Safe>`) holds
|
|
7
|
+
* the very same tree, nothing emitted twice. A root member spelled `safe` is `safe_` (shared/mirror.ts), noticed.
|
|
8
|
+
*/
|
|
9
|
+
import type { IR } from "../../ir/model.ts";
|
|
10
|
+
import type { SdkOp } from "../../ir/sdk-model.ts";
|
|
11
|
+
import type { RustCallPlan } from "./sdk-plan.ts";
|
|
12
|
+
import { type MethodEnv } from "./sdk-method.ts";
|
|
13
|
+
/** The method env, the operations by id, and the notices the generation reports (a root member renamed for the mirror). */
|
|
14
|
+
export type ClientEnv = MethodEnv & {
|
|
15
|
+
readonly ops: ReadonlyMap<string, SdkOp>;
|
|
16
|
+
readonly notices: string[];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* client.rs's declarations for `ir` (the client's constructor, accessors and methods, every resource, then
|
|
20
|
+
* every `<Op>Opts` and `<Op>Headers` in name order), and every method's call plan.
|
|
21
|
+
*/
|
|
22
|
+
export declare function clientDecls(ir: IR, env: ClientEnv): {
|
|
23
|
+
readonly decls: string;
|
|
24
|
+
readonly plans: RustCallPlan[];
|
|
25
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { methodsOf, namespacesOf } from "../../ir/resource-tree.js";
|
|
2
|
+
import { lineComment, rustString } from "../shared/escape.js";
|
|
3
|
+
import { compareCodeUnits, NameScope, rustTypeIdent, rustValueIdent } from "../shared/lang.js";
|
|
4
|
+
import { MIRROR, mirrorNotice } from "../shared/mirror.js";
|
|
5
|
+
import { rustMethod } from "./sdk-method.js";
|
|
6
|
+
import { STYLE } from "./types-names.js";
|
|
7
|
+
/* the runtime's own associated functions on `Client`, the mirror among them: no operation takes their name */
|
|
8
|
+
const CLIENT_FNS = ["build", "new", MIRROR];
|
|
9
|
+
/** A member's name in `scope`; at the root (`path` empty) one spelled like the mirror is `safe_` instead, and noticed. */
|
|
10
|
+
function memberName(segment, path, scope, env) {
|
|
11
|
+
const name = rustValueIdent(segment);
|
|
12
|
+
if (path.length > 0 || name !== MIRROR)
|
|
13
|
+
return scope.claim(name);
|
|
14
|
+
const renamed = scope.claim(`${MIRROR}_`);
|
|
15
|
+
env.notices.push(mirrorNotice("rust", MIRROR, name, renamed));
|
|
16
|
+
return renamed;
|
|
17
|
+
}
|
|
18
|
+
/** `ns` at `path` as the type `type`: its child namespaces first, so a method never takes an accessor's name. */
|
|
19
|
+
function resourceOf(ns, path, type, env) {
|
|
20
|
+
const scope = new NameScope(path.length === 0 ? CLIENT_FNS : []);
|
|
21
|
+
const client = path.length === 0 ? "self" : "self.client";
|
|
22
|
+
const children = namespacesOf(ns).map(([segment, child]) => {
|
|
23
|
+
const accessor = memberName(segment, path, scope, env);
|
|
24
|
+
const childPath = [...path, segment];
|
|
25
|
+
/* the type rule over the whole name: a leading digit gets its guard, and `self` stays `SelfResource` */
|
|
26
|
+
const childType = env.at.names.claim(rustTypeIdent([...childPath, "Resource"].join(".")));
|
|
27
|
+
return { accessor, node: resourceOf(child, childPath, childType, env) };
|
|
28
|
+
});
|
|
29
|
+
const methods = methodsOf(ns).map(([segment, op]) => rustMethod(env.ops.get(op.id), memberName(segment, path, scope, env), client, env));
|
|
30
|
+
return { children, methods, path, type };
|
|
31
|
+
}
|
|
32
|
+
/** Each accessor of `node`, reaching its child from `client` (`self` at the root, the borrowed client below it). */
|
|
33
|
+
function accessorBlocks(node, lifetime, client) {
|
|
34
|
+
return node.children.map(({ accessor, node: child }) => [
|
|
35
|
+
...lineComment(`The ${child.path.join(".")} operations.`, "///", " "),
|
|
36
|
+
` pub fn ${accessor}(&self) -> ${child.type}<${lifetime}, ${STYLE}> {`,
|
|
37
|
+
` ${child.type} { client: ${client} }`,
|
|
38
|
+
" }",
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
/** An impl block's members, a blank line apart. */
|
|
42
|
+
const members = (blocks) => blocks.map((lines) => lines.join("\n")).join("\n\n");
|
|
43
|
+
/** Each namespace below the client: its type, its accessors and methods, then its children's. */
|
|
44
|
+
function resourceLines(node) {
|
|
45
|
+
/* the lifetime is named only where an accessor hands it on */
|
|
46
|
+
const head = node.children.length > 0
|
|
47
|
+
? `impl<'a, ${STYLE}: Style> ${node.type}<'a, ${STYLE}> {`
|
|
48
|
+
: `impl<${STYLE}: Style> ${node.type}<'_, ${STYLE}> {`;
|
|
49
|
+
const own = [...accessorBlocks(node, "'a", "self.client"), ...node.methods.map((method) => method.lines)];
|
|
50
|
+
return [
|
|
51
|
+
...lineComment(`The ${node.path.join(".")} operations.`, "///"),
|
|
52
|
+
`pub struct ${node.type}<'a, ${STYLE} = Throw> {`,
|
|
53
|
+
` client: &'a Client<${STYLE}>,`,
|
|
54
|
+
"}",
|
|
55
|
+
"",
|
|
56
|
+
head,
|
|
57
|
+
members(own),
|
|
58
|
+
"}",
|
|
59
|
+
...node.children.flatMap(({ node: child }) => ["", ...resourceLines(child)]),
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
/** `Client::new`: the `base_url` default (the document's first server; without one an empty `base_url` is an error) and the auth scheme. */
|
|
63
|
+
function newClient(ir) {
|
|
64
|
+
const server = ir.servers[0];
|
|
65
|
+
const doc = server === undefined
|
|
66
|
+
? "The client for `config`. Its `base_url` is required: the API declares no server."
|
|
67
|
+
: `The client for \`config\`. An empty \`base_url\` is the API's first server, ${server}.`;
|
|
68
|
+
const base = server === undefined ? "None" : `Some(${rustString(server)})`;
|
|
69
|
+
const defaults = `base_url: ${base}, auth_header: ${rustString(ir.auth.headerName)}, auth_prefix: ${rustString(ir.auth.prefix)}`;
|
|
70
|
+
return [
|
|
71
|
+
...lineComment(doc, "///", " "),
|
|
72
|
+
" pub fn new(config: ClientConfig) -> Result<Client, Error> {",
|
|
73
|
+
` Client::build(config, crate::config::Defaults { ${defaults} })`,
|
|
74
|
+
" }",
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
/** Every method in the tree, depth first. */
|
|
78
|
+
const methodsIn = (node) => [
|
|
79
|
+
...node.methods,
|
|
80
|
+
...node.children.flatMap(({ node: child }) => methodsIn(child)),
|
|
81
|
+
];
|
|
82
|
+
/** Every method's call plan below `node`, reached through `accessors`, depth first. */
|
|
83
|
+
const plansIn = (node, accessors) => [
|
|
84
|
+
...node.methods.map((method) => ({ ...method.plan, accessors })),
|
|
85
|
+
...node.children.flatMap(({ accessor, node: child }) => plansIn(child, [...accessors, accessor])),
|
|
86
|
+
];
|
|
87
|
+
/**
|
|
88
|
+
* client.rs's declarations for `ir` (the client's constructor, accessors and methods, every resource, then
|
|
89
|
+
* every `<Op>Opts` and `<Op>Headers` in name order), and every method's call plan.
|
|
90
|
+
*/
|
|
91
|
+
export function clientDecls(ir, env) {
|
|
92
|
+
const root = resourceOf(ir.tree, [], "Client", env);
|
|
93
|
+
const opts = methodsIn(root)
|
|
94
|
+
.flatMap((method) => method.decls)
|
|
95
|
+
.sort(([a], [b]) => compareCodeUnits(a, b))
|
|
96
|
+
.map(([, decl]) => decl);
|
|
97
|
+
const own = [...accessorBlocks(root, "'_", "self"), ...root.methods.map((method) => method.lines)];
|
|
98
|
+
const styled = own.length === 0 ? [] : ["", `impl<${STYLE}: Style> Client<${STYLE}> {`, members(own), "}"];
|
|
99
|
+
const decls = [
|
|
100
|
+
"impl Client {",
|
|
101
|
+
members([newClient(ir)]),
|
|
102
|
+
"}",
|
|
103
|
+
...styled,
|
|
104
|
+
...root.children.flatMap(({ node }) => ["", ...resourceLines(node)]),
|
|
105
|
+
...opts.flatMap((decl) => ["", decl]),
|
|
106
|
+
].join("\n");
|
|
107
|
+
return { decls, plans: plansIn(root, []) };
|
|
108
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type SdkOp } from "../../ir/sdk-model.ts";
|
|
2
|
+
import type { RustCallPlan } from "./sdk-plan.ts";
|
|
3
|
+
import type { RustTypeContext } from "./types.ts";
|
|
4
|
+
/** One operation's method, its client.rs declarations by name (`<Op>Opts`, `<Op>Headers`), and its call plan less the accessors. */
|
|
5
|
+
export type RustMethod = {
|
|
6
|
+
readonly plan: Omit<RustCallPlan, "accessors">;
|
|
7
|
+
readonly decls: readonly (readonly [string, string])[];
|
|
8
|
+
readonly lines: readonly string[];
|
|
9
|
+
};
|
|
10
|
+
/** What every method of one SDK shares: the type context it hoists into. */
|
|
11
|
+
export type MethodEnv = {
|
|
12
|
+
readonly at: RustTypeContext;
|
|
13
|
+
};
|
|
14
|
+
/** The method of `op` named `name`, its client reached as `client` (`self`, `self.client`), and its `<Op>Opts` and `<Op>Headers`. */
|
|
15
|
+
export declare function rustMethod(op: SdkOp, name: string, client: string, env: MethodEnv): RustMethod;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { mediaEssence } from "../../ir/sdk-model.js";
|
|
2
|
+
import { lineComment, rustString } from "../shared/escape.js";
|
|
3
|
+
import { NameScope, rustTypeIdent, rustValueIdent } from "../shared/lang.js";
|
|
4
|
+
import { rustBody, typeAt } from "./sdk-body.js";
|
|
5
|
+
import { optsDecl, optsFields, optsLines, responseHeaders, takesIdempotencyKey, } from "./sdk-opts.js";
|
|
6
|
+
import { realtimeAnswer } from "./realtime.js";
|
|
7
|
+
import { sseAnswer } from "./sse.js";
|
|
8
|
+
import { STYLE } from "./types-names.js";
|
|
9
|
+
import { wsAnswer } from "./ws.js";
|
|
10
|
+
/* the method's own locals: a path param never shadows one (it is claimed as `…2`) */
|
|
11
|
+
const METHOD_LOCALS = ["body", "client", "form", "opts", "spec"];
|
|
12
|
+
/** How a stream operation answers. */
|
|
13
|
+
function streamAnswer(op, at) {
|
|
14
|
+
if (op.stream === "sse")
|
|
15
|
+
return sseAnswer(op, at);
|
|
16
|
+
return op.stream === "ws" ? wsAnswer() : realtimeAnswer(op, at);
|
|
17
|
+
}
|
|
18
|
+
/** How a method answers: a stream's way, else its answer's kind read. */
|
|
19
|
+
function answerOf(op, env) {
|
|
20
|
+
if (op.stream !== null)
|
|
21
|
+
return streamAnswer(op, env.at);
|
|
22
|
+
const { kind, schema } = op.success;
|
|
23
|
+
const [type, decoder] = kind === "text"
|
|
24
|
+
? ["String", "text"]
|
|
25
|
+
: kind === "binary"
|
|
26
|
+
? ["Vec<u8>", "binary"]
|
|
27
|
+
: schema === undefined
|
|
28
|
+
? ["()", "none"]
|
|
29
|
+
: [typeAt(schema, op.id, "Response", env.at), "json"];
|
|
30
|
+
const generic = decoder === "json" ? `::<${type}>` : "";
|
|
31
|
+
return { run: `crate::answer::${decoder}${generic}`, stream: null, type };
|
|
32
|
+
}
|
|
33
|
+
/** The method's `Call`: in the client's style but for a connection (the same on both clients), its headers last. */
|
|
34
|
+
function callType(op, answer, headers) {
|
|
35
|
+
if (op.stream === "ws" || op.stream === "realtime")
|
|
36
|
+
return `Call<${answer.type}>`;
|
|
37
|
+
return `Call<${[answer.type, STYLE, ...(headers ? [headers.plan.type] : [])].join(", ")}>`;
|
|
38
|
+
}
|
|
39
|
+
/** The operation's path params in the order the path holds them, whatever order they were declared in. */
|
|
40
|
+
function pathParamsOf(op) {
|
|
41
|
+
const order = op.pathSegments.flatMap((segment) => (segment.kind === "param" ? [segment.name] : []));
|
|
42
|
+
return [...op.pathParams].sort((a, b) => order.indexOf(a.name) - order.indexOf(b.name));
|
|
43
|
+
}
|
|
44
|
+
/** The method's rustdoc: its route, then the operation's summary and description, then how a stream resolves. */
|
|
45
|
+
function methodDoc(op, answer) {
|
|
46
|
+
const text = [
|
|
47
|
+
`Sends \`${op.method} ${op.path}\`.`,
|
|
48
|
+
op.summary,
|
|
49
|
+
op.description,
|
|
50
|
+
answer.stream === null ? "" : answer.doc,
|
|
51
|
+
];
|
|
52
|
+
return lineComment(text.filter((part) => part !== "").join("\n\n"), "///", " ");
|
|
53
|
+
}
|
|
54
|
+
/** The spec statements after the path: the asked media type, the Opts, the body, the targets a 2xx stales. */
|
|
55
|
+
function specLines(op, fields, answer, body) {
|
|
56
|
+
const { contentType, kind } = op.success;
|
|
57
|
+
const accept = op.stream === null && (kind === "binary" || kind === "text");
|
|
58
|
+
return [
|
|
59
|
+
...(accept ? [`spec.accept(${rustString(mediaEssence(contentType))});`] : []),
|
|
60
|
+
...optsLines(op, fields, answer.stream),
|
|
61
|
+
...body,
|
|
62
|
+
...(op.invalidates.length > 0 ? [`spec.invalidates(&[${op.invalidates.map(rustString).join(", ")}]);`] : []),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
/** The method's lines: its signature over `client`, the spec it fills, the `Call` it returns. */
|
|
66
|
+
function methodLines(parts, client, answer, body) {
|
|
67
|
+
const { fields, headers, op, opts, path } = parts;
|
|
68
|
+
const empty = fields.length === 0 && answer.stream === null && !takesIdempotencyKey(op);
|
|
69
|
+
const params = [
|
|
70
|
+
"&self",
|
|
71
|
+
...path.map(([, local]) => `${local}: &str`),
|
|
72
|
+
...(body ? [`body: ${body.type}`] : []),
|
|
73
|
+
`${empty ? "_opts" : "opts"}: &${opts}`,
|
|
74
|
+
];
|
|
75
|
+
const bound = path.map(([param, local]) => `(${rustString(param.name)}, ${local})`).join(", ");
|
|
76
|
+
const statements = specLines(op, fields, answer, body?.lines ?? []);
|
|
77
|
+
const returns = callType(op, answer, headers);
|
|
78
|
+
return [
|
|
79
|
+
...(params.length > 7 ? [" #[allow(clippy::too_many_arguments)]"] : []),
|
|
80
|
+
...methodDoc(op, answer),
|
|
81
|
+
` pub fn ${parts.name}(${params.join(", ")}) -> ${returns} {`,
|
|
82
|
+
` let ${statements.length > 0 ? "mut " : ""}spec = crate::request::RequestSpec::new(${rustString(op.method)}, ${rustString(op.path)}, &[${bound}]);`,
|
|
83
|
+
...statements.map((statement) => ` ${statement}`),
|
|
84
|
+
` Call::new(${client}, spec, ${answer.run})`,
|
|
85
|
+
" }",
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
/** How the driver reaches the method, by the names this emitter gave it. */
|
|
89
|
+
function planOf({ fields, headers, name, op, opts, path }) {
|
|
90
|
+
const by = (where) => Object.fromEntries(fields.filter((field) => field.in === where).map((field) => [field.param, field.ident]));
|
|
91
|
+
return {
|
|
92
|
+
body: op.body?.kind ?? null,
|
|
93
|
+
headers: by("header"),
|
|
94
|
+
idempotencyKey: takesIdempotencyKey(op) ? "idempotency_key" : null,
|
|
95
|
+
method: name,
|
|
96
|
+
operation: op.id,
|
|
97
|
+
opts,
|
|
98
|
+
pathParams: path.map(([param]) => param.name),
|
|
99
|
+
query: by("query"),
|
|
100
|
+
required: fields.filter((field) => field.bare).map((field) => field.ident),
|
|
101
|
+
response: op.success.kind,
|
|
102
|
+
responseHeaders: headers?.plan ?? null,
|
|
103
|
+
stream: op.stream,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** The method of `op` named `name`, its client reached as `client` (`self`, `self.client`), and its `<Op>Opts` and `<Op>Headers`. */
|
|
107
|
+
export function rustMethod(op, name, client, env) {
|
|
108
|
+
const opts = env.at.names.claim(`${rustTypeIdent(op.id)}Opts`);
|
|
109
|
+
const locals = new NameScope(METHOD_LOCALS);
|
|
110
|
+
const path = pathParamsOf(op).map((param) => [param, locals.claim(rustValueIdent(param.name))]);
|
|
111
|
+
const body = op.body && rustBody(op, op.body, env.at);
|
|
112
|
+
const answer = answerOf(op, env);
|
|
113
|
+
const fields = optsFields(op, opts, env.at, answer.stream);
|
|
114
|
+
const parts = { fields, headers: responseHeaders(op, env.at), name, op, opts, path };
|
|
115
|
+
const decls = [[opts, optsDecl(op, opts, fields, answer.stream)]];
|
|
116
|
+
if (parts.headers)
|
|
117
|
+
decls.push([parts.headers.plan.type, parts.headers.decl]);
|
|
118
|
+
return { decls, lines: methodLines(parts, client, answer, body), plan: planOf(parts) };
|
|
119
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { SdkOp } from "../../ir/sdk-model.ts";
|
|
2
|
+
import { type RustTypeContext } from "./types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* One declared param's `<Op>Opts` field: its ident and type, the param it carries, whether the API requires
|
|
5
|
+
* it, and whether it is a bare `T` (set without `Some`).
|
|
6
|
+
*/
|
|
7
|
+
export type OptsField = {
|
|
8
|
+
readonly ident: string;
|
|
9
|
+
readonly type: string;
|
|
10
|
+
readonly param: string;
|
|
11
|
+
readonly in: "header" | "query";
|
|
12
|
+
readonly required: boolean;
|
|
13
|
+
readonly bare: boolean;
|
|
14
|
+
};
|
|
15
|
+
/** A stream's own `<Op>Opts` field, after the declared ones. */
|
|
16
|
+
export type StreamField = {
|
|
17
|
+
readonly ident: string;
|
|
18
|
+
readonly type: string;
|
|
19
|
+
readonly doc?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* What a stream adds to its `<Op>Opts`: its fields (claimed first, so a declared param that collides gets
|
|
23
|
+
* `…2`), whether a declared param is a channel a field carries (then it has no field of its own), and the
|
|
24
|
+
* statements sending its fields after the declared params.
|
|
25
|
+
*/
|
|
26
|
+
export type StreamOpts = {
|
|
27
|
+
readonly fields: readonly StreamField[];
|
|
28
|
+
readonly carries: (param: string, where: OptsField["in"]) => boolean;
|
|
29
|
+
readonly sends: readonly string[];
|
|
30
|
+
};
|
|
31
|
+
/** How a stream operation's method answers: the `Call`'s answer type, the run it is sent with, its Opts fields and its rustdoc line. */
|
|
32
|
+
export type StreamAnswer = {
|
|
33
|
+
readonly type: string;
|
|
34
|
+
readonly run: string;
|
|
35
|
+
readonly stream: StreamOpts;
|
|
36
|
+
readonly doc: string;
|
|
37
|
+
};
|
|
38
|
+
/** A method's typed response headers, as a caller names them. */
|
|
39
|
+
export type RustResponseHeaders = {
|
|
40
|
+
readonly type: string;
|
|
41
|
+
readonly fields: Readonly<Record<string, string>>;
|
|
42
|
+
};
|
|
43
|
+
/** Whether `op`'s Opts carry `idempotency_key`: an idempotent operation that answers once. */
|
|
44
|
+
export declare const takesIdempotencyKey: (op: SdkOp) => boolean;
|
|
45
|
+
/** `<Op>Opts`'s param fields: each query param, then each header param; a param `stream` carries has none. */
|
|
46
|
+
export declare function optsFields(op: SdkOp, opts: string, at: RustTypeContext, stream: StreamOpts | null): OptsField[];
|
|
47
|
+
/** `<Op>Opts`: the operation's inputs beyond its path and body, documented, then `stream`'s own fields. */
|
|
48
|
+
export declare function optsDecl(op: SdkOp, opts: string, fields: readonly OptsField[], stream: StreamOpts | null): string;
|
|
49
|
+
/** The statements sending `opts`: each declared field, then `stream`'s, then the Idempotency-Key. */
|
|
50
|
+
export declare function optsLines(op: SdkOp, fields: readonly OptsField[], stream: StreamOpts | null): string[];
|
|
51
|
+
/**
|
|
52
|
+
* `<Op>Headers` and its `FromHeaders` impl, and its plan; null when `op` declares no response header, or is a
|
|
53
|
+
* WebSocket or realtime operation, whose 2xx response no caller receives.
|
|
54
|
+
*/
|
|
55
|
+
export declare function responseHeaders(op: SdkOp, at: RustTypeContext): {
|
|
56
|
+
readonly plan: RustResponseHeaders;
|
|
57
|
+
readonly decl: string;
|
|
58
|
+
} | null;
|