@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,191 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Extract the types a generated file needs from the app's source: its env, what its middleware
|
|
11
|
+
* added (the app's own, and each route's beyond them), and its taps. Written inline, so the
|
|
12
|
+
* generated file imports nothing from the app but the named types it references by `import()`,
|
|
13
|
+
* each through a specifier the output can resolve. ts-morph is the caller's, passed in.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
16
|
+
import { dirname, join, relative, sep } from "node:path";
|
|
17
|
+
import { addedProps, frameworkClass, routeAdditions } from "./chain.js";
|
|
18
|
+
import { Serializer } from "./serialize.js";
|
|
19
|
+
import { loadEntry, registrations } from "./walk.js";
|
|
20
|
+
/* the type-only members every honey app carries */
|
|
21
|
+
const APP_MEMBERS = ["$ctx", "$env", "$taps"];
|
|
22
|
+
/* the declared meta, read when the app carries it: an app from an older honey has no $meta and still extracts */
|
|
23
|
+
const META_MEMBER = "$meta";
|
|
24
|
+
/** The nearest named package.json above `file` (one without a name only marks a module type). */
|
|
25
|
+
function nearestPackage(file, cache) {
|
|
26
|
+
const visited = [];
|
|
27
|
+
let found = null;
|
|
28
|
+
for (let dir = dirname(file), prev = ""; dir !== prev; prev = dir, dir = dirname(dir)) {
|
|
29
|
+
const cached = cache.get(dir);
|
|
30
|
+
if (cached !== undefined) {
|
|
31
|
+
found = cached;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
visited.push(dir);
|
|
35
|
+
const json = readPackage(join(dir, "package.json"));
|
|
36
|
+
if (typeof json?.name === "string") {
|
|
37
|
+
found = { dir, json };
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const dir of visited)
|
|
42
|
+
cache.set(dir, found);
|
|
43
|
+
return found;
|
|
44
|
+
}
|
|
45
|
+
function readPackage(path) {
|
|
46
|
+
if (!existsSync(path))
|
|
47
|
+
return null;
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Every file an `exports` value can point at, under any condition, with the subpath that names it. */
|
|
56
|
+
function exportTargets(exports) {
|
|
57
|
+
const out = [];
|
|
58
|
+
const collect = (subpath, value) => {
|
|
59
|
+
if (typeof value === "string")
|
|
60
|
+
out.push({ subpath, target: value });
|
|
61
|
+
else if (value !== null && typeof value === "object")
|
|
62
|
+
for (const v of Object.values(value))
|
|
63
|
+
collect(subpath, v);
|
|
64
|
+
};
|
|
65
|
+
const entries = exports !== null && typeof exports === "object" && !Array.isArray(exports) ? Object.entries(exports) : [];
|
|
66
|
+
if (entries.some(([key]) => key.startsWith(".")))
|
|
67
|
+
for (const [key, value] of entries)
|
|
68
|
+
collect(key, value);
|
|
69
|
+
else
|
|
70
|
+
collect(".", exports);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
const stripExtension = (path) => path.replace(/\.d\.[mc]?ts$|\.[mc]?tsx?$|\.[mc]?js$/, "");
|
|
74
|
+
/** `@types/foo` types `foo`; `@types/scope__name` types `@scope/name`. */
|
|
75
|
+
function typedPackage(name) {
|
|
76
|
+
if (!name.startsWith("@types/"))
|
|
77
|
+
return name;
|
|
78
|
+
const bare = name.slice("@types/".length);
|
|
79
|
+
return bare.includes("__") ? `@${bare.replace("__", "/")}` : bare;
|
|
80
|
+
}
|
|
81
|
+
/** How the package `pkg` names its file `rel` (`./dist/x.d.ts`): an exports subpath, its types entry, or its path; null if it does not. */
|
|
82
|
+
function packageSpecifier(pkg, rel) {
|
|
83
|
+
const name = typedPackage(String(pkg.json.name));
|
|
84
|
+
const same = (target) => stripExtension(`./${target.replace(/^\.\//, "")}`) === stripExtension(rel);
|
|
85
|
+
if (pkg.json.exports !== undefined) {
|
|
86
|
+
const match = exportTargets(pkg.json.exports).find(({ target }) => same(target));
|
|
87
|
+
if (match === undefined)
|
|
88
|
+
return null;
|
|
89
|
+
return match.subpath === "." ? name : `${name}/${match.subpath.replace(/^\.\//, "")}`;
|
|
90
|
+
}
|
|
91
|
+
const types = pkg.json.types ?? pkg.json.typings;
|
|
92
|
+
if (typeof types === "string" && same(types))
|
|
93
|
+
return name;
|
|
94
|
+
const sub = stripExtension(rel.slice(2)).replace(/\/index$/, "");
|
|
95
|
+
return sub === "index" ? name : `${name}/${sub}`;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The specifier the output uses to import `file`: through its package when it is another
|
|
99
|
+
* package's (a file the package does not export is reached relatively), else a relative path.
|
|
100
|
+
*/
|
|
101
|
+
function moduleSpecifier(file, outputDir, cache) {
|
|
102
|
+
const pkg = nearestPackage(file, cache);
|
|
103
|
+
const own = outputDir === undefined ? null : nearestPackage(join(outputDir, "_"), cache);
|
|
104
|
+
const external = pkg !== null && pkg.dir !== own?.dir;
|
|
105
|
+
const viaPackage = external ? packageSpecifier(pkg, `./${relative(pkg.dir, file).split(sep).join("/")}`) : null;
|
|
106
|
+
if (viaPackage !== null || outputDir === undefined)
|
|
107
|
+
return viaPackage ?? file;
|
|
108
|
+
const rel = relative(outputDir, file).split(sep).join("/");
|
|
109
|
+
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
110
|
+
}
|
|
111
|
+
/** `import("/abs/file.ts").X` → a specifier the output resolves (lib types are never referenced: they are global). */
|
|
112
|
+
function resolvable(text, outputDir, cache) {
|
|
113
|
+
return text.replace(/import\("([^"]+)"\)\./g, (_, file) => `import("${moduleSpecifier(file, outputDir, cache)}").`);
|
|
114
|
+
}
|
|
115
|
+
/** Each route's `pick` type (its parsed `ctx.input`, its `ctx.params`) as text by route id; an id two registrations type differently is left out. */
|
|
116
|
+
function routeTypes(found, pick, serialize, routeId) {
|
|
117
|
+
const byId = new Map();
|
|
118
|
+
for (const registration of found) {
|
|
119
|
+
const { methods, path } = registration;
|
|
120
|
+
const type = pick(registration);
|
|
121
|
+
if (type === null || path === null)
|
|
122
|
+
continue;
|
|
123
|
+
const text = serialize(type);
|
|
124
|
+
for (const method of methods) {
|
|
125
|
+
let id;
|
|
126
|
+
try {
|
|
127
|
+
id = routeId(method, path);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
/* the router refuses the path: routeAdditions said so once */
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
byId.set(id, byId.has(id) && byId.get(id) !== text ? null : text);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return Object.fromEntries([...byId].filter((entry) => entry[1] !== null));
|
|
137
|
+
}
|
|
138
|
+
/** ts-morph, the optional peer, when installed; else undefined, which `extractTypes` reports once. */
|
|
139
|
+
export async function loadTsMorph(specifier = "ts-morph") {
|
|
140
|
+
try {
|
|
141
|
+
return (await import(__rewriteRelativeImportExtension(specifier)));
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (error.code === "ERR_MODULE_NOT_FOUND")
|
|
145
|
+
return undefined;
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** The app's extracted types, or null (said once through `report`) without ts-morph. */
|
|
150
|
+
export function extractTypes(options) {
|
|
151
|
+
const { exportName, report, routeId, tsMorph } = options;
|
|
152
|
+
if (tsMorph === undefined) {
|
|
153
|
+
report("ts-morph is not installed: middleware and env types are not extracted (install ts-morph to type ctx)");
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
const entry = loadEntry(tsMorph, options);
|
|
157
|
+
const { appType, checker, compiler } = entry;
|
|
158
|
+
const ser = new Serializer(checker, compiler);
|
|
159
|
+
const members = APP_MEMBERS.map((name) => {
|
|
160
|
+
const sym = appType.getProperty(name);
|
|
161
|
+
return sym === undefined ? undefined : checker.getTypeOfSymbol(sym);
|
|
162
|
+
});
|
|
163
|
+
if (members.includes(undefined)) {
|
|
164
|
+
const missing = APP_MEMBERS.filter((_, index) => members[index] === undefined);
|
|
165
|
+
throw new Error(`Export "${exportName}" is not a honey app: it carries no ${missing.join(", ")}`);
|
|
166
|
+
}
|
|
167
|
+
const [ctx, env, tapsType] = members;
|
|
168
|
+
const metaSym = appType.getProperty(META_MEMBER);
|
|
169
|
+
const metaType = metaSym === undefined ? undefined : checker.getTypeOfSymbol(metaSym);
|
|
170
|
+
const owner = frameworkClass(ctx, compiler);
|
|
171
|
+
const middleware = addedProps(ctx, owner, ser);
|
|
172
|
+
const base = new Set(middleware.map((p) => p.name));
|
|
173
|
+
const found = registrations(entry);
|
|
174
|
+
const routes = routeAdditions(found, ser, { base, owner, report, routeId });
|
|
175
|
+
const taps = ser.serialize(tapsType);
|
|
176
|
+
/* what `metaType<AppMeta>()` declared, written out: the ctx's meta is this and the OpenAPI keys, never the tree's
|
|
177
|
+
literal values, so a handler may pass its own ctx to a function typed with the generated ctx (bit 22 a) */
|
|
178
|
+
const meta = metaType === undefined ? "{}" : ser.shape(metaType);
|
|
179
|
+
const cache = new Map();
|
|
180
|
+
const text = (t) => resolvable(t, options.outputDir, cache);
|
|
181
|
+
const props = (list) => list.map((p) => ({ ...p, type: text(p.type) }));
|
|
182
|
+
return {
|
|
183
|
+
env: text(ser.serialize(env)),
|
|
184
|
+
inputs: routeTypes(found, (r) => r.input, (type) => text(ser.shape(type)), routeId),
|
|
185
|
+
meta: meta === "{}" ? null : text(meta),
|
|
186
|
+
middleware: props(middleware),
|
|
187
|
+
params: routeTypes(found, (r) => r.params, (type) => text(ser.shape(type)), routeId),
|
|
188
|
+
routes: Object.fromEntries(Object.entries(routes).map(([id, list]) => [id, props(list)])),
|
|
189
|
+
taps: taps === "{}" ? null : text(taps),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types → type source text.
|
|
3
|
+
*
|
|
4
|
+
* A named type whose module exports it becomes an `import("…").Name<Args>` reference, a global one
|
|
5
|
+
* its global name; everything else is written structurally. The structural writer keeps what a
|
|
6
|
+
* reader relies on: optional and rest parameters, generic signatures, tuple rest and optional
|
|
7
|
+
* elements, literal types, quoted keys and precedence (`(() => void)[]`, `(A | B) & C`). A type it
|
|
8
|
+
* is still writing when it meets it again is written as `unknown` there, never expanded without end.
|
|
9
|
+
* A name the program cannot resolve throws: TypeScript reads it as `any`, and writing that as `unknown`
|
|
10
|
+
* would hand the output a type the source never had.
|
|
11
|
+
*/
|
|
12
|
+
import type { ts } from "ts-morph";
|
|
13
|
+
export type Compiler = typeof ts;
|
|
14
|
+
/** Lib types every program has in scope: written by name, never imported. */
|
|
15
|
+
export declare function isLibFile(fileName: string): boolean;
|
|
16
|
+
export declare class Serializer {
|
|
17
|
+
#private;
|
|
18
|
+
readonly checker: ts.TypeChecker;
|
|
19
|
+
readonly compiler: Compiler;
|
|
20
|
+
constructor(checker: ts.TypeChecker, compiler: Compiler);
|
|
21
|
+
/** An annotation's named type (`x: Foo<Bar>`) as an `import()` reference, when its module exports it. */
|
|
22
|
+
refFromDeclaration(decl: ts.Declaration | undefined): string | undefined;
|
|
23
|
+
/** A reference if the type has a name to be written by, else its structure. */
|
|
24
|
+
text(type: ts.Type): string;
|
|
25
|
+
/** `import("path").Name<Args>` (or a global's name) for a declared type name, else null; lib types are left to `serialize`. */
|
|
26
|
+
asRef(type: ts.Type): string | null;
|
|
27
|
+
serialize(type: ts.Type): string;
|
|
28
|
+
/** An object type written out member by member, never by its alias name: a core-internal alias stays out of the output. */
|
|
29
|
+
shape(type: ts.Type): string;
|
|
30
|
+
/** An optional member's type, without the `| undefined` its `?` already says (a `null` stays). */
|
|
31
|
+
optional(type: ts.Type): string;
|
|
32
|
+
}
|
|
33
|
+
/** A property name a type literal can spell: `#secret` fields surface as `__#123@#secret`, symbol keys as `__@name@1`. */
|
|
34
|
+
export declare function isPublicName(name: string): boolean;
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { quoteKey } from "../emit/shared/literals.js";
|
|
2
|
+
import { arrayOf, intersectionOf, unionOf } from "../emit/shared/type-emitter.js";
|
|
3
|
+
/** Lib types every program has in scope: written by name, never imported. */
|
|
4
|
+
export function isLibFile(fileName) {
|
|
5
|
+
return /(?:^|[\\/])lib\.[\w.-]*\.d\.ts$/.test(fileName) || /[\\/]typescript[\\/]lib[\\/]/.test(fileName);
|
|
6
|
+
}
|
|
7
|
+
/** Whether a declaring module exports `sym` (a declaration file's types are always reachable). */
|
|
8
|
+
function isExported(sym, file, checker) {
|
|
9
|
+
if (file.isDeclarationFile)
|
|
10
|
+
return true;
|
|
11
|
+
const module = checker.getSymbolAtLocation(file);
|
|
12
|
+
return module !== undefined && checker.getExportsOfModule(module).some((e) => e.getName() === sym.getName());
|
|
13
|
+
}
|
|
14
|
+
/** A script file (no import or export): its top-level declarations are global. */
|
|
15
|
+
function isScript(file) {
|
|
16
|
+
return file.externalModuleIndicator === undefined;
|
|
17
|
+
}
|
|
18
|
+
/* checked in order: `boolean` is a union of its literals, so it is named before unions are split */
|
|
19
|
+
const KEYWORDS = [
|
|
20
|
+
["String", "string"],
|
|
21
|
+
["Number", "number"],
|
|
22
|
+
["Boolean", "boolean"],
|
|
23
|
+
["BigInt", "bigint"],
|
|
24
|
+
["ESSymbol", "symbol"],
|
|
25
|
+
["UniqueESSymbol", "symbol"],
|
|
26
|
+
["Void", "void"],
|
|
27
|
+
["Undefined", "undefined"],
|
|
28
|
+
["Null", "null"],
|
|
29
|
+
["Never", "never"],
|
|
30
|
+
["Unknown", "unknown"],
|
|
31
|
+
["Any", "unknown"],
|
|
32
|
+
["NonPrimitive", "object"],
|
|
33
|
+
/* deferred generic forms (`T extends U ? X : Y`, `T[K]`, `keyof T`) are written as their bound */
|
|
34
|
+
["StringMapping", "string"],
|
|
35
|
+
["Conditional", "unknown"],
|
|
36
|
+
["Substitution", "unknown"],
|
|
37
|
+
["IndexedAccess", "unknown"],
|
|
38
|
+
["Index", "unknown"],
|
|
39
|
+
];
|
|
40
|
+
export class Serializer {
|
|
41
|
+
checker;
|
|
42
|
+
compiler;
|
|
43
|
+
#active = new Set();
|
|
44
|
+
/* type parameters of the signatures being written: inside them a parameter keeps its name */
|
|
45
|
+
#bound = new Set();
|
|
46
|
+
constructor(checker, compiler) {
|
|
47
|
+
this.checker = checker;
|
|
48
|
+
this.compiler = compiler;
|
|
49
|
+
}
|
|
50
|
+
/** An annotation's named type (`x: Foo<Bar>`) as an `import()` reference, when its module exports it. */
|
|
51
|
+
refFromDeclaration(decl) {
|
|
52
|
+
const { checker, compiler } = this;
|
|
53
|
+
const typeRef = decl?.type;
|
|
54
|
+
if (typeRef === undefined || !compiler.isTypeReferenceNode(typeRef))
|
|
55
|
+
return undefined;
|
|
56
|
+
let sym = checker.getSymbolAtLocation(typeRef.typeName);
|
|
57
|
+
while (sym !== undefined && sym.flags & compiler.SymbolFlags.Alias)
|
|
58
|
+
sym = checker.getAliasedSymbol(sym);
|
|
59
|
+
const file = sym?.declarations?.[0]?.getSourceFile();
|
|
60
|
+
if (sym === undefined || file === undefined || isLibFile(file.fileName) || !isExported(sym, file, checker)) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const args = (typeRef.typeArguments ?? []).map((a) => this.text(checker.getTypeFromTypeNode(a)));
|
|
64
|
+
return `import("${file.fileName}").${sym.getName()}${args.length > 0 ? `<${args.join(", ")}>` : ""}`;
|
|
65
|
+
}
|
|
66
|
+
/** A reference if the type has a name to be written by, else its structure. */
|
|
67
|
+
text(type) {
|
|
68
|
+
return this.asRef(type) ?? this.serialize(type);
|
|
69
|
+
}
|
|
70
|
+
/** `import("path").Name<Args>` (or a global's name) for a declared type name, else null; lib types are left to `serialize`. */
|
|
71
|
+
asRef(type) {
|
|
72
|
+
const sym = type.aliasSymbol ?? type.getSymbol();
|
|
73
|
+
const decl = sym?.declarations?.[0];
|
|
74
|
+
if (sym === undefined || decl === undefined || !this.#isTypeName(sym))
|
|
75
|
+
return null;
|
|
76
|
+
const file = decl.getSourceFile();
|
|
77
|
+
if (isLibFile(file.fileName))
|
|
78
|
+
return null;
|
|
79
|
+
const globalName = this.#globalName(sym, decl);
|
|
80
|
+
if (globalName !== null)
|
|
81
|
+
return this.#withArgs(globalName, type, decl);
|
|
82
|
+
/* an ambient module's member has no import() path here, and import() of an unexported type is `any` */
|
|
83
|
+
if (isScript(file) || !isExported(sym, file, this.checker))
|
|
84
|
+
return null;
|
|
85
|
+
return this.#withArgs(`import("${file.fileName}").${sym.getName()}`, type, decl);
|
|
86
|
+
}
|
|
87
|
+
/** A name a type position can use: an alias, interface, class or enum (never a function's or a variable's). */
|
|
88
|
+
#isTypeName(sym) {
|
|
89
|
+
const S = this.compiler.SymbolFlags;
|
|
90
|
+
return (sym.flags & (S.TypeAlias | S.Interface | S.Class | S.Enum)) !== 0;
|
|
91
|
+
}
|
|
92
|
+
/** `ref` with the type's arguments; a class or interface reference carries its `this` type last, dropped here. */
|
|
93
|
+
#withArgs(ref, type, decl) {
|
|
94
|
+
const all = (type.aliasSymbol ? type.aliasTypeArguments : type.typeArguments) ?? [];
|
|
95
|
+
const declared = decl.typeParameters?.length ?? all.length;
|
|
96
|
+
const args = all.slice(0, declared).map((arg) => this.text(arg));
|
|
97
|
+
return args.length > 0 ? `${ref}<${args.join(", ")}>` : ref;
|
|
98
|
+
}
|
|
99
|
+
/** The name a global declaration is reachable by (`Cloudflare.Env`), or null if it is module-scoped. */
|
|
100
|
+
#globalName(sym, decl) {
|
|
101
|
+
const { compiler } = this;
|
|
102
|
+
let global = false;
|
|
103
|
+
for (let n = decl.parent; n !== undefined; n = n.parent) {
|
|
104
|
+
if (compiler.isModuleDeclaration(n) && n.flags & compiler.NodeFlags.GlobalAugmentation) {
|
|
105
|
+
global = true;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (compiler.isSourceFile(n))
|
|
109
|
+
global = isScript(n);
|
|
110
|
+
}
|
|
111
|
+
/* a `declare global` member is qualified as `global.Name`; in scope it is `Name` */
|
|
112
|
+
const name = this.checker.getFullyQualifiedName(sym).replace(/^global\./, "");
|
|
113
|
+
return global && /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(name) ? name : null;
|
|
114
|
+
}
|
|
115
|
+
serialize(type) {
|
|
116
|
+
this.#resolved(type);
|
|
117
|
+
if (this.#active.has(type))
|
|
118
|
+
return "unknown";
|
|
119
|
+
this.#active.add(type);
|
|
120
|
+
try {
|
|
121
|
+
return this.#serialize(type);
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
this.#active.delete(type);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
#serialize(type) {
|
|
128
|
+
const { compiler } = this;
|
|
129
|
+
/* an enum is nominal: its name when it can be referenced */
|
|
130
|
+
const enumRef = (type.getSymbol()?.flags ?? 0) & compiler.SymbolFlags.Enum ? this.asRef(type) : null;
|
|
131
|
+
return (enumRef ??
|
|
132
|
+
this.#keyword(type) ??
|
|
133
|
+
this.#literal(type) ??
|
|
134
|
+
this.#typeParameter(type) ??
|
|
135
|
+
this.#composite(type) ??
|
|
136
|
+
this.#named(type) ??
|
|
137
|
+
this.#object(type));
|
|
138
|
+
}
|
|
139
|
+
#keyword(type) {
|
|
140
|
+
const flags = this.compiler.TypeFlags;
|
|
141
|
+
return KEYWORDS.find(([flag]) => type.flags & flags[flag])?.[1] ?? null;
|
|
142
|
+
}
|
|
143
|
+
#literal(type) {
|
|
144
|
+
const F = this.compiler.TypeFlags;
|
|
145
|
+
if (type.isStringLiteral())
|
|
146
|
+
return JSON.stringify(type.value);
|
|
147
|
+
if (type.isNumberLiteral())
|
|
148
|
+
return `${type.value}`;
|
|
149
|
+
if (type.flags & F.TemplateLiteral)
|
|
150
|
+
return this.#template(type);
|
|
151
|
+
if (type.flags & F.BigIntLiteral) {
|
|
152
|
+
const { base10Value, negative } = type.value;
|
|
153
|
+
return `${negative ? "-" : ""}${base10Value}n`;
|
|
154
|
+
}
|
|
155
|
+
return type.flags & F.BooleanLiteral ? this.checker.typeToString(type) : null;
|
|
156
|
+
}
|
|
157
|
+
/** A template literal type as written: its text escaped where a template would read it, each hole serialized. */
|
|
158
|
+
#template(type) {
|
|
159
|
+
const holes = type.types.map((hole) => `\${${this.serialize(hole)}}`);
|
|
160
|
+
const texts = type.texts.map((text) => text.replace(/[`\\]|\$(?=\{)/g, (c) => `\\${c}`));
|
|
161
|
+
return `\`${texts.map((text, i) => text + (holes[i] ?? "")).join("")}\``;
|
|
162
|
+
}
|
|
163
|
+
/** By name inside the signature that declares it, else its constraint, else unknown. */
|
|
164
|
+
#typeParameter(type) {
|
|
165
|
+
if (!(type.flags & this.compiler.TypeFlags.TypeParameter))
|
|
166
|
+
return null;
|
|
167
|
+
if (this.#bound.has(type.symbol))
|
|
168
|
+
return type.symbol.getName();
|
|
169
|
+
const constraint = this.checker.getBaseConstraintOfType(type);
|
|
170
|
+
return constraint !== undefined && constraint !== type ? this.serialize(constraint) : "unknown";
|
|
171
|
+
}
|
|
172
|
+
#composite(type) {
|
|
173
|
+
const { checker } = this;
|
|
174
|
+
if (type.isUnion())
|
|
175
|
+
return unionOf(type.types.map((t) => this.serialize(t)));
|
|
176
|
+
if (type.isIntersection())
|
|
177
|
+
return intersectionOf(type.types.map((t) => this.serialize(t)));
|
|
178
|
+
if (checker.isArrayType(type)) {
|
|
179
|
+
const [element] = checker.getTypeArguments(type);
|
|
180
|
+
const text = arrayOf(this.serialize(element));
|
|
181
|
+
return type.getSymbol()?.getName() === "ReadonlyArray" ? `readonly ${text}` : text;
|
|
182
|
+
}
|
|
183
|
+
if (checker.isTupleType(type))
|
|
184
|
+
return this.#tuple(type);
|
|
185
|
+
const sigs = type.getCallSignatures();
|
|
186
|
+
if (sigs.length === 0 || type.getProperties().length > 0)
|
|
187
|
+
return null;
|
|
188
|
+
const parts = sigs.map((sig) => this.#signature(sig));
|
|
189
|
+
return parts.length === 1 ? parts[0] : parts.map((p) => `(${p})`).join(" & ");
|
|
190
|
+
}
|
|
191
|
+
#tuple(ref) {
|
|
192
|
+
const E = this.compiler.ElementFlags;
|
|
193
|
+
const target = ref.target;
|
|
194
|
+
const parts = this.checker.getTypeArguments(ref).map((arg, i) => {
|
|
195
|
+
const flags = target.elementFlags[i];
|
|
196
|
+
if (flags & E.Rest)
|
|
197
|
+
return `...${arrayOf(this.serialize(arg))}`;
|
|
198
|
+
if (flags & E.Variadic)
|
|
199
|
+
return `...${this.serialize(arg)}`;
|
|
200
|
+
return flags & E.Optional ? `${this.optional(arg)}?` : this.serialize(arg);
|
|
201
|
+
});
|
|
202
|
+
return `${target.readonly ? "readonly " : ""}[${parts.join(", ")}]`;
|
|
203
|
+
}
|
|
204
|
+
/** A lib type by its name with its arguments; another named type by reference. */
|
|
205
|
+
#named(type) {
|
|
206
|
+
const sym = type.getSymbol();
|
|
207
|
+
const decl = sym?.declarations?.[0];
|
|
208
|
+
if (sym === undefined || decl === undefined || !isLibFile(decl.getSourceFile().fileName))
|
|
209
|
+
return this.asRef(type);
|
|
210
|
+
if (!this.#isTypeName(sym))
|
|
211
|
+
return null;
|
|
212
|
+
const args = type.typeArguments ?? [];
|
|
213
|
+
const declared = decl.typeParameters?.length ?? args.length;
|
|
214
|
+
const kept = args.slice(0, declared).map((arg) => this.serialize(arg));
|
|
215
|
+
return kept.length > 0 ? `${sym.getName()}<${kept.join(", ")}>` : sym.getName();
|
|
216
|
+
}
|
|
217
|
+
#object(type) {
|
|
218
|
+
const { checker, compiler } = this;
|
|
219
|
+
const index = type.getStringIndexType();
|
|
220
|
+
const props = type.getProperties().filter((p) => isPublicName(p.getName()));
|
|
221
|
+
if (index !== undefined && props.length === 0 && type.getCallSignatures().length === 0) {
|
|
222
|
+
return `Record<string, ${this.serialize(index)}>`;
|
|
223
|
+
}
|
|
224
|
+
const M = compiler.ModifierFlags;
|
|
225
|
+
const entries = [];
|
|
226
|
+
for (const p of props) {
|
|
227
|
+
/* a mapped type's prop has no declaration */
|
|
228
|
+
const decls = p.getDeclarations() ?? [];
|
|
229
|
+
if (decls.some((d) => compiler.getCombinedModifierFlags(d) & (M.Private | M.Protected)))
|
|
230
|
+
continue;
|
|
231
|
+
const readonly = decls.some((d) => compiler.getCombinedModifierFlags(d) & M.Readonly);
|
|
232
|
+
const optional = (p.flags & compiler.SymbolFlags.Optional) !== 0;
|
|
233
|
+
const member = checker.getTypeOfSymbol(p);
|
|
234
|
+
const value = optional ? this.optional(member) : this.serialize(member);
|
|
235
|
+
entries.push(`${readonly ? "readonly " : ""}${quoteKey(p.getName())}${optional ? "?" : ""}: ${value}`);
|
|
236
|
+
}
|
|
237
|
+
if (index !== undefined)
|
|
238
|
+
entries.push(`[key: string]: ${this.serialize(index)}`);
|
|
239
|
+
for (const sig of type.getCallSignatures())
|
|
240
|
+
entries.push(this.#signature(sig, true));
|
|
241
|
+
return entries.length > 0 ? `{ ${entries.join("; ")} }` : "{}";
|
|
242
|
+
}
|
|
243
|
+
/** An object type written out member by member, never by its alias name: a core-internal alias stays out of the output. */
|
|
244
|
+
shape(type) {
|
|
245
|
+
this.#resolved(type);
|
|
246
|
+
return this.#object(type);
|
|
247
|
+
}
|
|
248
|
+
/** Throws on TypeScript's error type, an unresolved name; a written `any` passes. */
|
|
249
|
+
#resolved(type) {
|
|
250
|
+
if (type.intrinsicName !== "error")
|
|
251
|
+
return;
|
|
252
|
+
throw new Error(`type ${this.checker.typeToString(type)} does not resolve in the program honey reads: the entry, its imports and its tsconfig's .d.ts files`);
|
|
253
|
+
}
|
|
254
|
+
/** An optional member's type, without the `| undefined` its `?` already says (a `null` stays). */
|
|
255
|
+
optional(type) {
|
|
256
|
+
const kept = type.isUnion() ? type.types.filter((t) => !(t.flags & this.compiler.TypeFlags.Undefined)) : [type];
|
|
257
|
+
return kept.length === 1 ? this.text(kept[0]) : unionOf(kept.map((t) => this.text(t)));
|
|
258
|
+
}
|
|
259
|
+
/** `<T extends X>(a: A, b?: B, ...rest: C[]) => R`, or the call-signature member form. */
|
|
260
|
+
#signature(sig, member = false) {
|
|
261
|
+
const params = sig.getTypeParameters() ?? [];
|
|
262
|
+
const added = params.map((t) => t.symbol).filter((s) => !this.#bound.has(s));
|
|
263
|
+
for (const s of added)
|
|
264
|
+
this.#bound.add(s);
|
|
265
|
+
try {
|
|
266
|
+
return this.#signatureText(sig, params, member);
|
|
267
|
+
}
|
|
268
|
+
finally {
|
|
269
|
+
for (const s of added)
|
|
270
|
+
this.#bound.delete(s);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
#signatureText(sig, typeParams, member) {
|
|
274
|
+
const { checker } = this;
|
|
275
|
+
const generics = typeParams.map((t) => {
|
|
276
|
+
const constraint = t.getConstraint();
|
|
277
|
+
return `${t.symbol.getName()}${constraint === undefined ? "" : ` extends ${this.text(constraint)}`}`;
|
|
278
|
+
});
|
|
279
|
+
const params = sig.getParameters().map((p) => {
|
|
280
|
+
const type = checker.getTypeOfSymbol(p);
|
|
281
|
+
const param = p.valueDeclaration;
|
|
282
|
+
const rest = param?.dotDotDotToken !== undefined;
|
|
283
|
+
const optional = !rest && param !== undefined && checker.isOptionalParameter(param);
|
|
284
|
+
const text = optional ? this.optional(type) : this.text(type);
|
|
285
|
+
return `${rest ? "..." : ""}${p.getName()}${optional ? "?" : ""}: ${text}`;
|
|
286
|
+
});
|
|
287
|
+
const head = `${generics.length > 0 ? `<${generics.join(", ")}>` : ""}(${params.join(", ")})`;
|
|
288
|
+
const ret = this.text(checker.getReturnTypeOfSignature(sig));
|
|
289
|
+
return member ? `${head}: ${ret}` : `${head} => ${ret}`;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/** A property name a type literal can spell: `#secret` fields surface as `__#123@#secret`, symbol keys as `__@name@1`. */
|
|
293
|
+
export function isPublicName(name) {
|
|
294
|
+
return !name.startsWith("#") && !name.startsWith("__#") && !name.startsWith("__@");
|
|
295
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Project, ts } from "ts-morph";
|
|
2
|
+
import type { Compiler } from "./serialize.ts";
|
|
3
|
+
/** ts-morph, passed in by the caller: an optional peer this package never imports. */
|
|
4
|
+
export type TsMorph = typeof import("ts-morph");
|
|
5
|
+
/** Which exported app to read. */
|
|
6
|
+
export type EntryOptions = {
|
|
7
|
+
/** The path of the source file that holds the app. */
|
|
8
|
+
entryPath: string;
|
|
9
|
+
/**
|
|
10
|
+
* The app's export name in that file (`default` for a default export); an unexported variable of that name also
|
|
11
|
+
* counts. Throws when neither exists.
|
|
12
|
+
*/
|
|
13
|
+
exportName: string;
|
|
14
|
+
/** the tsconfig to read the project with; else the nearest one (`findTsConfig`) */
|
|
15
|
+
tsconfigPath?: string;
|
|
16
|
+
};
|
|
17
|
+
export type LoadedEntry = {
|
|
18
|
+
/** the app's type */
|
|
19
|
+
appType: ts.Type;
|
|
20
|
+
checker: ts.TypeChecker;
|
|
21
|
+
compiler: Compiler;
|
|
22
|
+
project: Project;
|
|
23
|
+
};
|
|
24
|
+
/** One route a `.handler()` call registers: where, its methods, its full path (null if not a literal) and its ctx. */
|
|
25
|
+
export type Registration = {
|
|
26
|
+
at: string;
|
|
27
|
+
ctx: ts.Type;
|
|
28
|
+
/** `ctx.input` as the handler receives it (parsed), or null when the route declares no input */
|
|
29
|
+
input: ts.Type | null;
|
|
30
|
+
/** `ctx.params` as the handler receives it, or null when every param is the path's string */
|
|
31
|
+
params: ts.Type | null;
|
|
32
|
+
methods: string[];
|
|
33
|
+
path: string | null;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The tsconfig that governs `fromPath`: the nearest one walking up, but never past the project root
|
|
37
|
+
* (the nearest directory with a package.json); a stray tsconfig above it is not this project's.
|
|
38
|
+
*/
|
|
39
|
+
export declare function findTsConfig(fromPath: string): string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Load the entry and its app: `export const app`, an export list, an unexported declaration of the name, or `export default`.
|
|
42
|
+
* The program is the entry, what it imports, and the tsconfig's own declaration files: an ambient one that only
|
|
43
|
+
* `include` names (wrangler's `worker-configuration.d.ts`) declares globals the app's types use, as under `tsc -p`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function loadEntry(tsMorph: TsMorph, options: EntryOptions): LoadedEntry;
|
|
46
|
+
/** Every route the program's own files register (not declaration files, not packages), in file order then source order. */
|
|
47
|
+
export declare function registrations(entry: LoadedEntry): Registration[];
|