@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,255 @@
|
|
|
1
|
+
import { toIR } from "../../ir/build.js";
|
|
2
|
+
import { isJsonMedia, mediaEssence } from "../../ir/sdk-model.js";
|
|
3
|
+
import { bodiesOf } from "../../ir/slots.js";
|
|
4
|
+
import { tsString } from "../shared/escape.js";
|
|
5
|
+
import { compareCodeUnits } from "../shared/lang.js";
|
|
6
|
+
import { literalType, quoteKey } from "../shared/literals.js";
|
|
7
|
+
import { statusKeyOf } from "../shared/status-keys.js";
|
|
8
|
+
import { irToTs } from "../shared/type-emitter.js";
|
|
9
|
+
import { componentNames } from "./sdk-types.js";
|
|
10
|
+
/* the names the file declares, which a component schema never takes */
|
|
11
|
+
const RESERVED = [
|
|
12
|
+
"HoneyContext",
|
|
13
|
+
"HoneyError",
|
|
14
|
+
"HoneyMeta",
|
|
15
|
+
"Omit",
|
|
16
|
+
"Partial",
|
|
17
|
+
"Readonly",
|
|
18
|
+
"Record",
|
|
19
|
+
"Routes",
|
|
20
|
+
"RouteSelector",
|
|
21
|
+
"TapMap",
|
|
22
|
+
];
|
|
23
|
+
/* the v1 error-factory signature of a key without a schema (core errors.ts ErrorFactoryOpts) */
|
|
24
|
+
const STANDARD_FACTORY = "(opts?: { cause?: unknown; fields?: Record<string, { error_key: string; message: string; path: string }[]>; headers?: Record<string, string>; vars?: Record<string, number | string> }) => HoneyError";
|
|
25
|
+
const EXTRACTORS = [
|
|
26
|
+
["RouteCtx", "ctx"],
|
|
27
|
+
["RouteInput", "input"],
|
|
28
|
+
["RouteOutput", "output"],
|
|
29
|
+
["RouteErrors", "errors"],
|
|
30
|
+
["RouteErrorShapes", "errorShapes"],
|
|
31
|
+
["RouteErrorsByStatus", "errorsByStatus"],
|
|
32
|
+
["RouteMeta", "meta"],
|
|
33
|
+
];
|
|
34
|
+
/** `{ k: T; … }`, or `{}` when there is nothing in it. */
|
|
35
|
+
const objectText = (fields) => fields.length === 0 ? "{}" : `{ ${fields.map(([key, type]) => `${key}: ${type}`).join("; ")} }`;
|
|
36
|
+
const propsText = (props) => objectText(props.map((p) => [`${quoteKey(p.name)}${p.optional ? "?" : ""}`, p.type]));
|
|
37
|
+
/** The documented routes by route id; an operation without `x-honey-route` is reported and left out. */
|
|
38
|
+
function routesOf(ir, report) {
|
|
39
|
+
const routes = new Map();
|
|
40
|
+
const missing = [];
|
|
41
|
+
for (const op of ir.operations) {
|
|
42
|
+
const id = op.extensions.route;
|
|
43
|
+
if (op.extensions.websocket === true)
|
|
44
|
+
continue;
|
|
45
|
+
if (id === undefined)
|
|
46
|
+
missing.push(`${op.method} ${op.path}: no x-honey-route; left out of Routes`);
|
|
47
|
+
/* `all()` and an optional param document one route as several operations: the first speaks for it */
|
|
48
|
+
if (id !== undefined && !routes.has(id))
|
|
49
|
+
routes.set(id, op);
|
|
50
|
+
}
|
|
51
|
+
for (const message of missing.sort(compareCodeUnits))
|
|
52
|
+
report(message);
|
|
53
|
+
return routes;
|
|
54
|
+
}
|
|
55
|
+
/** A route pattern's params, as core's `ParamKeys` names them: `:name`, `:name?`, `*name`, an unnamed `*`. */
|
|
56
|
+
function paramsOf(pattern) {
|
|
57
|
+
const names = [...pattern.matchAll(/:([^/?]+)\??|\*([^/]*)/g)].map((m) => m[1] ?? (m[2] === "" ? "*" : m[2]));
|
|
58
|
+
return [...new Set(names)].map((name) => [quoteKey(name), "string"]);
|
|
59
|
+
}
|
|
60
|
+
/** The request as the document describes it (the wire type): its query, headers, cookies and body. */
|
|
61
|
+
function wireInput(op, ctx) {
|
|
62
|
+
const group = (params) => objectText([...params]
|
|
63
|
+
.sort((a, b) => compareCodeUnits(a.name, b.name))
|
|
64
|
+
.map((p) => [`${quoteKey(p.name)}${p.required === true ? "" : "?"}`, ctx.resolve(p.schema)]));
|
|
65
|
+
const fields = [];
|
|
66
|
+
if (op.params.query.length > 0)
|
|
67
|
+
fields.push(["search", group(op.params.query)]);
|
|
68
|
+
if (op.params.header.length > 0)
|
|
69
|
+
fields.push(["headers", group(op.params.header)]);
|
|
70
|
+
/* the IR sets `cookie` only when the operation declares one */
|
|
71
|
+
if (op.params.cookie !== undefined)
|
|
72
|
+
fields.push(["cookies", group(op.params.cookie)]);
|
|
73
|
+
const body = bodiesOf(op)[0];
|
|
74
|
+
if (body?.kind === "stream")
|
|
75
|
+
fields.push(["binary", `{ readonly bytes: Uint8Array<ArrayBuffer>; readonly type: ${tsString(body.contentType)} }`]);
|
|
76
|
+
else if (body !== undefined) {
|
|
77
|
+
const essence = mediaEssence(body.contentType);
|
|
78
|
+
const field = isJsonMedia(body.contentType) ? "json" : "form";
|
|
79
|
+
if (field === "json" || essence === "application/x-www-form-urlencoded" || essence === "multipart/form-data")
|
|
80
|
+
fields.push([field, ctx.resolve(body.schema)]);
|
|
81
|
+
}
|
|
82
|
+
return fields;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Where a response with no body reads back as `.output()` declares it, with its type: a redirect carries its target and
|
|
86
|
+
* a 304 (the other bodiless 3xx `.output()` declares under `redirect`) has none; a 204 or 205 is written with no body,
|
|
87
|
+
* and reads back as the shorthand declares it, under JSON. `undefined` for a body, or any other bodiless status.
|
|
88
|
+
*/
|
|
89
|
+
function bodilessAt(response) {
|
|
90
|
+
if (response.contents !== undefined)
|
|
91
|
+
return undefined;
|
|
92
|
+
if (response.status === "204" || response.status === "205")
|
|
93
|
+
return ["application/json", "unknown"];
|
|
94
|
+
const located = response.headers?.some((h) => h.name.toLowerCase() === "location") === true;
|
|
95
|
+
return response.status.startsWith("3") && (located || response.status === "304") ? ["redirect", "true"] : undefined;
|
|
96
|
+
}
|
|
97
|
+
/** What the route answers, error responses aside: `{ [media]: { [statusKey]: T } }`, a redirect as `redirect`. */
|
|
98
|
+
function outputOf(op, ctx) {
|
|
99
|
+
const media = new Map();
|
|
100
|
+
const add = (type, field) => media.set(type, [...(media.get(type) ?? []), field]);
|
|
101
|
+
for (const response of Object.values(op.responses).sort((a, b) => compareCodeUnits(a.status, b.status))) {
|
|
102
|
+
const key = /^[0-9]{3}$/.test(response.status) ? statusKeyOf(Number(response.status)) : undefined;
|
|
103
|
+
if (response.error === true || key === undefined)
|
|
104
|
+
continue;
|
|
105
|
+
const bodiless = bodilessAt(response);
|
|
106
|
+
if (bodiless !== undefined)
|
|
107
|
+
add(bodiless[0], [key, bodiless[1]]);
|
|
108
|
+
for (const { contentType, schema } of response.contents ?? [])
|
|
109
|
+
add(contentType, [key, schema === undefined ? "unknown" : ctx.resolve(schema)]);
|
|
110
|
+
}
|
|
111
|
+
return objectText([...media].map(([type, fields]) => [tsString(type), objectText(fields)]));
|
|
112
|
+
}
|
|
113
|
+
/** The route's declared errors: their union, each key's shape, and the shapes by status. */
|
|
114
|
+
function errorsOf(op, ctx) {
|
|
115
|
+
const declared = op.extensions.errors ?? {};
|
|
116
|
+
const keys = Object.keys(declared).sort(compareCodeUnits);
|
|
117
|
+
if (keys.length === 0)
|
|
118
|
+
return { factories: [], fields: [["errors", "never"]] };
|
|
119
|
+
const shape = (key) => {
|
|
120
|
+
const schema = declared[key]?.schema;
|
|
121
|
+
return schema === undefined ? "null" : ctx.resolve(schema);
|
|
122
|
+
};
|
|
123
|
+
const byStatus = new Map();
|
|
124
|
+
for (const key of keys) {
|
|
125
|
+
const status = declared[key]?.status;
|
|
126
|
+
if (typeof status === "number")
|
|
127
|
+
byStatus.set(status, (byStatus.get(status) ?? new Set()).add(shape(key)));
|
|
128
|
+
}
|
|
129
|
+
const statuses = [...byStatus]
|
|
130
|
+
.sort(([a], [b]) => a - b)
|
|
131
|
+
.map(([code, shapes]) => [String(code), [...shapes].join(" | ")]);
|
|
132
|
+
const factory = (key) => shape(key) === "null"
|
|
133
|
+
? STANDARD_FACTORY
|
|
134
|
+
: `(data: ${shape(key)}, opts?: { cause?: unknown; headers?: Record<string, string> }) => HoneyError`;
|
|
135
|
+
return {
|
|
136
|
+
factories: keys.map((key) => [quoteKey(key), factory(key)]),
|
|
137
|
+
fields: [
|
|
138
|
+
["errors", keys.map(tsString).join(" | ")],
|
|
139
|
+
["errorShapes", objectText(keys.map((key) => [quoteKey(key), shape(key)]))],
|
|
140
|
+
["errorsByStatus", objectText(statuses)],
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The ctx's `meta`: what the app declares, with the OpenAPI keys a route may add (bit 22 a), so a handler may pass
|
|
146
|
+
* its own ctx to a function typed with the generated ctx. The tree's literals are narrower than the handler's type
|
|
147
|
+
* — a route's `operationId` is `string` there, not its value — and would reject it; they stay the sibling field.
|
|
148
|
+
* Without an extracted declaration (no ts-morph, or an app that declares no meta) the literals are all there is.
|
|
149
|
+
*/
|
|
150
|
+
function ctxMeta(extracted, literal) {
|
|
151
|
+
const declared = extracted?.meta ?? null;
|
|
152
|
+
/* the OpenAPI keys the declared meta does not redefine: a consumer that types `security` its own way holds
|
|
153
|
+
that type in the handler, and intersecting honey's would conflict with it */
|
|
154
|
+
return declared === null ? literal : `Partial<Omit<HoneyMeta, keyof ${declared}>> & ${declared}`;
|
|
155
|
+
}
|
|
156
|
+
/** `ctx.params`: the type a param schema gives it as extracted, else each of the pattern's params a string. */
|
|
157
|
+
function ctxParams(extracted, id, pattern) {
|
|
158
|
+
return extracted?.params[id] ?? objectText(paramsOf(pattern));
|
|
159
|
+
}
|
|
160
|
+
/** One `Routes[pattern][method]` entry. */
|
|
161
|
+
function routeEntry(id, op, options, ctx) {
|
|
162
|
+
const pattern = id.slice(id.indexOf(" ") + 1);
|
|
163
|
+
const { extracted } = options;
|
|
164
|
+
const wire = objectText(wireInput(op, ctx));
|
|
165
|
+
const input = extracted?.inputs[id] ?? wire;
|
|
166
|
+
const params = ctxParams(extracted, id, pattern);
|
|
167
|
+
const { factories, fields } = errorsOf(op, ctx);
|
|
168
|
+
const mt = options.tree.routes[id]?.mt;
|
|
169
|
+
/* the values the tree carries, as literals: what a consumer reads a route's configuration from */
|
|
170
|
+
const literal = mt && Object.keys(mt).length > 0 ? literalType(mt) : "{}";
|
|
171
|
+
const meta = ctxMeta(extracted, literal);
|
|
172
|
+
const output = outputOf(op, ctx);
|
|
173
|
+
const own = [];
|
|
174
|
+
if (input !== "{}")
|
|
175
|
+
own.push(["readonly input", input]);
|
|
176
|
+
if (params !== "{}")
|
|
177
|
+
own.push(["readonly params", params]);
|
|
178
|
+
if (factories.length > 0)
|
|
179
|
+
own.push(["readonly errors", objectText(factories)]);
|
|
180
|
+
own.push(["readonly meta", `Readonly<${meta}>`], ["readonly routePattern", tsString(pattern)]);
|
|
181
|
+
const base = options.baseCtxName ?? "BaseCtx";
|
|
182
|
+
const parts = [factories.length > 0 ? `Omit<${base}, "errors">` : base];
|
|
183
|
+
const adds = extracted?.routes[id];
|
|
184
|
+
if (adds !== undefined && adds.length > 0)
|
|
185
|
+
parts.push(propsText(adds));
|
|
186
|
+
parts.push(objectText(own));
|
|
187
|
+
const entry = [
|
|
188
|
+
["ctx", `WithOutput<${parts.join(" & ")}, ${output === "{}" ? "never" : output}>`],
|
|
189
|
+
...fields,
|
|
190
|
+
["input", input],
|
|
191
|
+
["meta", literal],
|
|
192
|
+
["output", output],
|
|
193
|
+
];
|
|
194
|
+
return entry.map(([key, type]) => `\t\t\t${key}: ${type}`).join("\n");
|
|
195
|
+
}
|
|
196
|
+
/** `BaseCtx`: the app's context over its env, the middleware's additions and its typed taps. */
|
|
197
|
+
function baseCtx(extracted, name) {
|
|
198
|
+
const env = extracted?.env ?? "Record<string, unknown>";
|
|
199
|
+
const taps = extracted?.taps ?? null;
|
|
200
|
+
const parts = [taps === null ? `HoneyContext<${env}>` : `Omit<HoneyContext<${env}>, "tap">`];
|
|
201
|
+
const middleware = extracted?.middleware ?? [];
|
|
202
|
+
if (middleware.length > 0)
|
|
203
|
+
parts.push(propsText(middleware));
|
|
204
|
+
if (taps !== null)
|
|
205
|
+
parts.push("{ tap<K extends keyof TapMap>(key: K, payload: TapMap[K]): void }");
|
|
206
|
+
const lines = taps === null ? [] : [`type TapMap = ${taps}`];
|
|
207
|
+
return [...lines, `export type ${name} = ${parts.join(" & ")}`];
|
|
208
|
+
}
|
|
209
|
+
/** A route id's path: `GET /a` → `/a`. */
|
|
210
|
+
const pathOf = (id) => id.slice(id.indexOf(" ") + 1);
|
|
211
|
+
/** The `Routes` map: paths and methods in code-unit order. */
|
|
212
|
+
function routesType(routes, options, ctx) {
|
|
213
|
+
const byPath = new Map();
|
|
214
|
+
const ids = [...routes.keys()].sort(compareCodeUnits);
|
|
215
|
+
for (const id of ids.sort((a, b) => compareCodeUnits(pathOf(a), pathOf(b)) || compareCodeUnits(a, b))) {
|
|
216
|
+
const method = id.slice(0, id.indexOf(" ")).toLowerCase();
|
|
217
|
+
const entry = `\t\t${quoteKey(method)}: {\n${routeEntry(id, routes.get(id), options, ctx)}\n\t\t}`;
|
|
218
|
+
byPath.set(pathOf(id), [...(byPath.get(pathOf(id)) ?? []), entry]);
|
|
219
|
+
}
|
|
220
|
+
const paths = [...byPath].map(([path, methods]) => `\t${tsString(path)}: {\n${methods.join("\n")}\n\t}`);
|
|
221
|
+
return paths.length === 0 ? "export type Routes = {}" : `export type Routes = {\n${paths.join("\n")}\n}`;
|
|
222
|
+
}
|
|
223
|
+
/** The `types.gen.d.ts` text for the app the options describe. */
|
|
224
|
+
export function generateTypes(options) {
|
|
225
|
+
const ir = toIR(options.document, { deriveOperationIds: true });
|
|
226
|
+
const routes = routesOf(ir, options.report);
|
|
227
|
+
const extra = Object.keys(options.extracted?.routes ?? {}).filter((id) => !routes.has(id));
|
|
228
|
+
for (const id of extra.sort(compareCodeUnits))
|
|
229
|
+
options.report(`${id}: extracted ctx additions match no documented operation (internal and filtered routes are not documented); not typed`);
|
|
230
|
+
const name = options.baseCtxName ?? "BaseCtx";
|
|
231
|
+
const names = { refName: componentNames(ir, [...RESERVED, name]) };
|
|
232
|
+
const ctx = { names, resolve: (schema) => irToTs(schema, names) };
|
|
233
|
+
const hasErrors = [...routes.values()].some((op) => Object.keys(op.extensions.errors ?? {}).length > 0);
|
|
234
|
+
const selectors = [...routes.keys()].sort(compareCodeUnits);
|
|
235
|
+
/* HoneyMeta only when a declared meta is emitted: the ctx's meta is that type and the keys a route may add */
|
|
236
|
+
const declaredMeta = options.extracted?.meta ?? null;
|
|
237
|
+
const imports = [
|
|
238
|
+
"HoneyContext",
|
|
239
|
+
"WithOutput",
|
|
240
|
+
...(hasErrors ? ["HoneyError"] : []),
|
|
241
|
+
...(declaredMeta === null ? [] : ["HoneyMeta"]),
|
|
242
|
+
];
|
|
243
|
+
const out = [`import type { ${imports.join(", ")} } from "@workerstack/backend"`];
|
|
244
|
+
out.push(...baseCtx(options.extracted, name));
|
|
245
|
+
if (selectors.length > 0) {
|
|
246
|
+
out.push(`export type RouteSelector = ${selectors.map(tsString).join(" | ")}`);
|
|
247
|
+
out.push('declare module "@workerstack/backend" {\n\tinterface HoneyCodegen {\n\t\trouteSelector: RouteSelector\n\t}\n}');
|
|
248
|
+
}
|
|
249
|
+
for (const schema of Object.keys(ir.schemas).sort(compareCodeUnits))
|
|
250
|
+
out.push(`type ${names.refName?.(schema)} = ${ctx.resolve(ir.schemas[schema])}`);
|
|
251
|
+
out.push(routesType(routes, options, ctx));
|
|
252
|
+
for (const [type, field] of EXTRACTORS)
|
|
253
|
+
out.push(`export type ${type}<TPath extends keyof Routes, TMethod extends keyof Routes[TPath] & string> = Routes[TPath][TMethod] extends { ${field}: infer T } ? T : never`);
|
|
254
|
+
return `${out.join("\n\n")}\n`;
|
|
255
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A TS SDK's Standard Webhooks events: one type per event the document declares, the `WebhookEvent` union a receiver
|
|
3
|
+
* narrows (`known` first, then `type`), and `${stem}.webhook.gen.ts`, a receiver's whole import: `verifyWebhook`, which
|
|
4
|
+
* marks whether a delivery's type is one of them, its error, and the event types. Written only for a document that declares one.
|
|
5
|
+
*/
|
|
6
|
+
import type { IR } from "../../ir/model.ts";
|
|
7
|
+
import { type TypeOptions } from "../shared/type-emitter.ts";
|
|
8
|
+
/** The catch-all event and the union, declared beside the events. */
|
|
9
|
+
export declare const WEBHOOK_TYPES: readonly ["UnknownWebhookEvent", "WebhookEvent"];
|
|
10
|
+
/** The type names `ir`'s events declare, for the component names to stay clear of; none without events. */
|
|
11
|
+
export declare function webhookTypeNames(ir: IR): string[];
|
|
12
|
+
/** The event types and their union, for `types.gen.ts`; empty for a document without events. */
|
|
13
|
+
export declare function webhookTypesText(ir: IR, types: TypeOptions): string;
|
|
14
|
+
/**
|
|
15
|
+
* The `${stem}.webhook.gen.ts` text of `ir`: the runtime's verifier, its untyped core unexported, then `verifyWebhook`
|
|
16
|
+
* over it, and the event types re-exported. Its only import is type-only, which compiles away, so a receiver that
|
|
17
|
+
* imports it bundles no client.
|
|
18
|
+
*/
|
|
19
|
+
export declare function webhooksText(ir: IR, stem: string): string;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { blockCommentText, tsString } from "../shared/escape.js";
|
|
2
|
+
import { compareCodeUnits, pascalWords } from "../shared/lang.js";
|
|
3
|
+
import { irToTs } from "../shared/type-emitter.js";
|
|
4
|
+
import { webhookSource } from "./http.js";
|
|
5
|
+
/** The catch-all event and the union, declared beside the events. */
|
|
6
|
+
export const WEBHOOK_TYPES = ["UnknownWebhookEvent", "WebhookEvent"];
|
|
7
|
+
/** `ir`'s events in code-unit order of their type, each named; two that name one type throw, naming both. */
|
|
8
|
+
function namedEvents(ir) {
|
|
9
|
+
const named = ir.webhooks
|
|
10
|
+
.flatMap(({ description, event, summary }) => (event ? [{ doc: summary ?? description, event }] : []))
|
|
11
|
+
.sort((a, b) => compareCodeUnits(a.event.type, b.event.type))
|
|
12
|
+
.map((entry) => {
|
|
13
|
+
const base = pascalWords(entry.event.type);
|
|
14
|
+
return { ...entry, name: `${/^[A-Za-z]/.test(base) ? "" : "Event"}${base}WebhookEvent` };
|
|
15
|
+
});
|
|
16
|
+
const byName = new Map();
|
|
17
|
+
for (const { event, name } of named) {
|
|
18
|
+
const type = JSON.stringify(event.type);
|
|
19
|
+
if (WEBHOOK_TYPES.includes(name))
|
|
20
|
+
throw new Error(`webhook event ${type} names the type ${name}, which the SDK declares itself`);
|
|
21
|
+
const taken = byName.get(name);
|
|
22
|
+
if (taken !== undefined)
|
|
23
|
+
throw new Error(`webhook events ${JSON.stringify(taken)} and ${type} both name the type ${name}`);
|
|
24
|
+
byName.set(name, event.type);
|
|
25
|
+
}
|
|
26
|
+
return named;
|
|
27
|
+
}
|
|
28
|
+
/** The type names `ir`'s events declare, for the component names to stay clear of; none without events. */
|
|
29
|
+
export function webhookTypeNames(ir) {
|
|
30
|
+
const names = namedEvents(ir).map(({ name }) => name);
|
|
31
|
+
return names.length === 0 ? [] : [...names, ...WEBHOOK_TYPES];
|
|
32
|
+
}
|
|
33
|
+
/** The event types and their union, for `types.gen.ts`; empty for a document without events. */
|
|
34
|
+
export function webhookTypesText(ir, types) {
|
|
35
|
+
const named = namedEvents(ir);
|
|
36
|
+
if (named.length === 0)
|
|
37
|
+
return "";
|
|
38
|
+
const events = named.map(({ doc, event, name, }) => `/** The ${blockCommentText(event.type)} webhook event${doc ? `: ${blockCommentText(doc)}` : ""} */
|
|
39
|
+
export type ${name} = { id: string; known: true; type: ${tsString(event.type)}; timestamp: string; data: ${irToTs(event.data, types)} }`);
|
|
40
|
+
return `${events.join("\n")}
|
|
41
|
+
/** An event of a type this SDK's document does not declare: a newer API's, its data as sent. */
|
|
42
|
+
export type UnknownWebhookEvent = { id: string; known: false; type: string; timestamp: string; data: unknown }
|
|
43
|
+
/** A verified delivery: check \`known\`, then switch on \`type\` for its typed \`data\`. */
|
|
44
|
+
export type WebhookEvent = ${[...named.map(({ name }) => name), "UnknownWebhookEvent"].join(" | ")}
|
|
45
|
+
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
/* the runtime verifier's untyped core, which `verifyWebhook` wraps: kept inside the file, out of a receiver's imports */
|
|
49
|
+
const INTERNAL = /^export ((?:async function verifyStandardWebhook|type VerifiedWebhook)\b)/gm;
|
|
50
|
+
/**
|
|
51
|
+
* The `${stem}.webhook.gen.ts` text of `ir`: the runtime's verifier, its untyped core unexported, then `verifyWebhook`
|
|
52
|
+
* over it, and the event types re-exported. Its only import is type-only, which compiles away, so a receiver that
|
|
53
|
+
* imports it bundles no client.
|
|
54
|
+
*/
|
|
55
|
+
export function webhooksText(ir, stem) {
|
|
56
|
+
const named = namedEvents(ir);
|
|
57
|
+
const known = named.map(({ event }) => tsString(event.type));
|
|
58
|
+
const types = [...named.map(({ name }) => name), ...WEBHOOK_TYPES].sort(compareCodeUnits);
|
|
59
|
+
return `import type { WebhookEvent } from "./${stem}.types.gen.js"
|
|
60
|
+
|
|
61
|
+
export type { ${types.join(", ")} } from "./${stem}.types.gen.js"
|
|
62
|
+
|
|
63
|
+
${webhookSource().replace(INTERNAL, "$1")}
|
|
64
|
+
|
|
65
|
+
const KNOWN: ReadonlySet<string> = new Set([${known.join(", ")}])
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Verifies a Standard Webhooks delivery against the receiver's secret (or, while rotating, both) and returns its
|
|
69
|
+
* event: pass the body as received, before any parse, and the request's headers. A forged, tampered, stale or
|
|
70
|
+
* malformed delivery is a \`WebhookVerificationError\`; a secret that is not a \`whsec_\` key is a \`TypeError\`.
|
|
71
|
+
*/
|
|
72
|
+
export async function verifyWebhook(
|
|
73
|
+
body: string | Uint8Array,
|
|
74
|
+
headers: WebhookHeaders,
|
|
75
|
+
secret: string | readonly string[],
|
|
76
|
+
): Promise<WebhookEvent> {
|
|
77
|
+
const event = await verifyStandardWebhook(body, headers, secret)
|
|
78
|
+
return { ...event, known: KNOWN.has(event.type) } as WebhookEvent
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What middleware added to a ctx. A prop is the framework's when every declaration of it is a
|
|
3
|
+
* member of the framework's context class (the one declaring `res`), so the list never drifts from
|
|
4
|
+
* the class; everything else, a user prop of a framework name included, was added. Each added prop
|
|
5
|
+
* is written by the type its declaration names when there is one, else by its type.
|
|
6
|
+
*/
|
|
7
|
+
import type { ts } from "ts-morph";
|
|
8
|
+
import { type Serializer } from "./serialize.ts";
|
|
9
|
+
import type { Registration } from "./walk.ts";
|
|
10
|
+
/** One property on `ctx` that the framework's context class does not declare: what the middleware added. */
|
|
11
|
+
export type ExtractedProp = {
|
|
12
|
+
/** Its name on `ctx`. */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Whether it is declared optional (`?`). */
|
|
15
|
+
optional: boolean;
|
|
16
|
+
/** Its type as TypeScript source text: the type its declaration names when there is one, else the checker's. */
|
|
17
|
+
type: string;
|
|
18
|
+
};
|
|
19
|
+
/** The class that declares `res` on `ctx`: the framework's context. None for a ctx typed without it. */
|
|
20
|
+
export declare function frameworkClass(ctx: ts.Type, compiler: typeof ts): ts.Node | undefined;
|
|
21
|
+
/** The props of `ctx` the framework class does not own, in the ctx's order. */
|
|
22
|
+
export declare function addedProps(ctx: ts.Type, owner: ts.Node | undefined, ser: Serializer): ExtractedProp[];
|
|
23
|
+
export type RouteOptions = {
|
|
24
|
+
/** the names the app itself added: a route lists only what it adds beyond them */
|
|
25
|
+
base: ReadonlySet<string>;
|
|
26
|
+
owner: ts.Node | undefined;
|
|
27
|
+
report: (message: string) => void;
|
|
28
|
+
routeId: (method: string, path: string) => string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Each route's own additions by route id. A route whose path is no literal, or one the router
|
|
32
|
+
* refuses, is skipped; an id two registrations give different additions is dropped, never guessed.
|
|
33
|
+
*/
|
|
34
|
+
export declare function routeAdditions(found: readonly Registration[], ser: Serializer, options: RouteOptions): Record<string, ExtractedProp[]>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { isPublicName } from "./serialize.js";
|
|
2
|
+
/** The class that declares `res` on `ctx`: the framework's context. None for a ctx typed without it. */
|
|
3
|
+
export function frameworkClass(ctx, compiler) {
|
|
4
|
+
const parent = ctx.getProperty("res")?.declarations?.[0]?.parent;
|
|
5
|
+
return parent !== undefined && compiler.isClassDeclaration(parent) ? parent : undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The type an added prop's single declaration names: an annotation, the annotation of the variable
|
|
9
|
+
* a shorthand (`next({ db })`) stands for, or, for a destructured variable (`const { db } = open()`),
|
|
10
|
+
* the annotation of the variable the source's shorthand returns.
|
|
11
|
+
*/
|
|
12
|
+
function declaredRef(decl, ser) {
|
|
13
|
+
const { checker, compiler } = ser;
|
|
14
|
+
if (!compiler.isShorthandPropertyAssignment(decl))
|
|
15
|
+
return ser.refFromDeclaration(decl);
|
|
16
|
+
const variable = checker.getShorthandAssignmentValueSymbol(decl)?.valueDeclaration;
|
|
17
|
+
if (variable === undefined || !compiler.isBindingElement(variable))
|
|
18
|
+
return ser.refFromDeclaration(variable);
|
|
19
|
+
/* `const { db } = open()`: the pattern's own declaration; a parameter or a nested pattern names nothing */
|
|
20
|
+
const holder = variable.parent.parent;
|
|
21
|
+
const init = compiler.isVariableDeclaration(holder) ? holder.initializer : undefined;
|
|
22
|
+
const source = init === undefined ? undefined : checker.getTypeAtLocation(init).getProperty(decl.name.text);
|
|
23
|
+
const returned = source?.valueDeclaration;
|
|
24
|
+
if (returned === undefined || !compiler.isShorthandPropertyAssignment(returned))
|
|
25
|
+
return undefined;
|
|
26
|
+
return ser.refFromDeclaration(checker.getShorthandAssignmentValueSymbol(returned)?.valueDeclaration);
|
|
27
|
+
}
|
|
28
|
+
/** The props of `ctx` the framework class does not own, in the ctx's order. */
|
|
29
|
+
export function addedProps(ctx, owner, ser) {
|
|
30
|
+
const { checker, compiler } = ser;
|
|
31
|
+
/* a prop with no declaration (a mapped type's) is no member of anything */
|
|
32
|
+
const owned = (decls) => owner !== undefined && decls.length > 0 && decls.every((d) => d.parent === owner);
|
|
33
|
+
return ctx
|
|
34
|
+
.getProperties()
|
|
35
|
+
.filter((p) => isPublicName(p.getName()) && !owned(p.declarations ?? []))
|
|
36
|
+
.map((p) => {
|
|
37
|
+
const decls = p.declarations ?? [];
|
|
38
|
+
const optional = (p.flags & compiler.SymbolFlags.Optional) !== 0;
|
|
39
|
+
/* a prop several middleware add is their intersection: only the checker's type says it */
|
|
40
|
+
const ref = decls.length === 1 ? declaredRef(decls[0], ser) : undefined;
|
|
41
|
+
const type = checker.getTypeOfSymbol(p);
|
|
42
|
+
return { name: p.getName(), optional, type: ref ?? (optional ? ser.optional(type) : ser.text(type)) };
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const SKIPPED = "its ctx is not extracted";
|
|
46
|
+
/**
|
|
47
|
+
* Each route's own additions by route id. A route whose path is no literal, or one the router
|
|
48
|
+
* refuses, is skipped; an id two registrations give different additions is dropped, never guessed.
|
|
49
|
+
*/
|
|
50
|
+
export function routeAdditions(found, ser, options) {
|
|
51
|
+
const { base, owner, report, routeId } = options;
|
|
52
|
+
const byId = new Map();
|
|
53
|
+
const conflicted = new Set();
|
|
54
|
+
for (const { at, ctx, methods, path } of found) {
|
|
55
|
+
if (path === null) {
|
|
56
|
+
report(`${at}: the route's path is not a literal type; ${SKIPPED}`);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
let ids;
|
|
60
|
+
try {
|
|
61
|
+
ids = methods.map((method) => routeId(method, path));
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
report(`${at}: the router refuses ${JSON.stringify(path)} (${error.message}); ${SKIPPED}`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const props = addedProps(ctx, owner, ser).filter((p) => !base.has(p.name));
|
|
68
|
+
const key = JSON.stringify(props);
|
|
69
|
+
for (const id of ids) {
|
|
70
|
+
const seen = byId.get(id);
|
|
71
|
+
if (seen === undefined)
|
|
72
|
+
byId.set(id, { key, props });
|
|
73
|
+
else if (seen.key !== key && !conflicted.has(id)) {
|
|
74
|
+
conflicted.add(id);
|
|
75
|
+
report(`${JSON.stringify(id)} is registered with different middleware; ${SKIPPED}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const out = {};
|
|
80
|
+
for (const [id, { props }] of byId)
|
|
81
|
+
if (props.length > 0 && !conflicted.has(id))
|
|
82
|
+
out[id] = props;
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type ExtractedProp } from "./chain.ts";
|
|
2
|
+
import { type EntryOptions, type TsMorph } from "./walk.ts";
|
|
3
|
+
export type { ExtractedProp } from "./chain.ts";
|
|
4
|
+
/** What `extractTypes` reads: the app's entry, where the output goes, and how to report and name routes. */
|
|
5
|
+
export type ExtractOptions = EntryOptions & {
|
|
6
|
+
/** where the generated file goes: `import()` specifiers are written relative to it */
|
|
7
|
+
outputDir?: string;
|
|
8
|
+
/** what extraction skipped or could not do, said once each */
|
|
9
|
+
report: (message: string) => void;
|
|
10
|
+
/** the router's id for a method and a full path (core's `routeId`); throws on a pattern it refuses */
|
|
11
|
+
routeId: (method: string, path: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* The caller's `ts-morph` module, as `loadTsMorph` returns it; when undefined, `extractTypes` reports that and
|
|
14
|
+
* returns null.
|
|
15
|
+
*/
|
|
16
|
+
tsMorph: TsMorph | undefined;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The types extracted from an app's source, as TypeScript source text whose `import()` specifiers resolve from
|
|
20
|
+
* `outputDir`.
|
|
21
|
+
*/
|
|
22
|
+
export type ExtractedTypes = {
|
|
23
|
+
/** The app's environment bindings: the type of `ctx.env`. */
|
|
24
|
+
env: string;
|
|
25
|
+
/** what the app's middleware and context values added */
|
|
26
|
+
middleware: ExtractedProp[];
|
|
27
|
+
/** per route id, `ctx.input` as the handler gets it (the parsed type); a route without input has none */
|
|
28
|
+
inputs: Record<string, string>;
|
|
29
|
+
/** per route id, `ctx.params` where a param schema types a key; a route of the path's strings has none */
|
|
30
|
+
params: Record<string, string>;
|
|
31
|
+
/** the meta type the app declares (`metaType<AppMeta>()`), or null when it declares none */
|
|
32
|
+
meta: string | null;
|
|
33
|
+
/** per route id, what the route's middleware added beyond `middleware`; a route that added nothing has none */
|
|
34
|
+
routes: Record<string, ExtractedProp[]>;
|
|
35
|
+
/** the declared tap payloads, or null when none are */
|
|
36
|
+
taps: string | null;
|
|
37
|
+
};
|
|
38
|
+
/** ts-morph, the optional peer, when installed; else undefined, which `extractTypes` reports once. */
|
|
39
|
+
export declare function loadTsMorph(specifier?: string): Promise<TsMorph | undefined>;
|
|
40
|
+
/** The app's extracted types, or null (said once through `report`) without ts-morph. */
|
|
41
|
+
export declare function extractTypes(options: ExtractOptions): ExtractedTypes | null;
|