@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,183 @@
|
|
|
1
|
+
import { mediaEssence } from "../../ir/sdk-model.js";
|
|
2
|
+
import { pyString } from "../shared/escape.js";
|
|
3
|
+
import { compareCodeUnits, NameScope, pyIdentifier } from "../shared/lang.js";
|
|
4
|
+
import { realtimeStream } from "./realtime.js";
|
|
5
|
+
import { answerOf, bodyType, responseHeaders, shapeOf, typeAt } from "./sdk-answer.js";
|
|
6
|
+
import { methodDoc } from "./sdk-doc.js";
|
|
7
|
+
import { sseStream } from "./sse.js";
|
|
8
|
+
import { wsStream } from "./ws.js";
|
|
9
|
+
/* the builtins an annotation may spell that a method may be named: a method so named shadows it below */
|
|
10
|
+
export const BUILTINS = ["bool", "bytes", "dict", "float", "int", "list", "str", "tuple"];
|
|
11
|
+
/**
|
|
12
|
+
* `type` with each builtin `shadowed` names spelled `_builtins.<name>`; strings inside it kept. The module is
|
|
13
|
+
* aliased because a method may be named `builtins`, and `pyIdentifier` never yields a leading `_`.
|
|
14
|
+
*/
|
|
15
|
+
function qualified(type, shadowed, env) {
|
|
16
|
+
return type.replace(/("(?:[^"\\]|\\.)*")|\b([a-z]+)\b/g, (whole, text, name) => {
|
|
17
|
+
if (text !== undefined || !shadowed.has(name))
|
|
18
|
+
return whole;
|
|
19
|
+
env.imports.add("builtins");
|
|
20
|
+
return `_builtins.${name}`;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/* the method's own names, a stream's fields among them: a parameter that takes one is claimed as `…2` */
|
|
24
|
+
const METHOD_LOCALS = ["self", "body", "options", "idempotency_key", "headers_into"];
|
|
25
|
+
/* each stream's answer, its own fields, and the declared params its resume channels carry (Fd3) */
|
|
26
|
+
const STREAMS = {
|
|
27
|
+
realtime: realtimeStream,
|
|
28
|
+
sse: sseStream,
|
|
29
|
+
ws: wsStream,
|
|
30
|
+
};
|
|
31
|
+
/** A field's name: `name` of `name: type = default`. */
|
|
32
|
+
const nameOf = (field) => field.slice(0, field.indexOf(":"));
|
|
33
|
+
/** `type` as it may be left unset: as it is when it admits `None` already. */
|
|
34
|
+
const optional = (type) => type === "Any" || type === "None" || type.endsWith(" | None") ? type : `${type} | None`;
|
|
35
|
+
/** The path params in path order, whatever order they were declared in. */
|
|
36
|
+
function pathParamsOf(op) {
|
|
37
|
+
const order = op.pathSegments.flatMap((segment) => (segment.kind === "param" ? [segment.name] : []));
|
|
38
|
+
return [...op.pathParams].sort((a, b) => order.indexOf(a.name) - order.indexOf(b.name));
|
|
39
|
+
}
|
|
40
|
+
/** The query then header params as keywords, each claimed in `scope`; one a stream field carries has none. */
|
|
41
|
+
function keywordsOf(op, scope, env) {
|
|
42
|
+
const headers = [...op.headers].sort((a, b) => compareCodeUnits(a.name, b.name));
|
|
43
|
+
const carries = op.stream === null ? () => false : STREAMS[op.stream].carries;
|
|
44
|
+
return [
|
|
45
|
+
...op.query.map((param) => ({ param, where: "query" })),
|
|
46
|
+
...headers.map((param) => ({ param, where: "header" })),
|
|
47
|
+
]
|
|
48
|
+
.filter(({ param, where }) => !carries(param.name, where))
|
|
49
|
+
.map(({ param, where }) => ({
|
|
50
|
+
ident: scope.claim(pyIdentifier(param.name)),
|
|
51
|
+
param,
|
|
52
|
+
type: typeAt(op, param.name, param.schema, env),
|
|
53
|
+
where,
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
/** `items` as a Python tuple. */
|
|
57
|
+
const tuple = (items) => (items.length === 1 ? `(${items[0]},)` : `(${items.join(", ")})`);
|
|
58
|
+
/** How the runtime reads `op`'s answer: its stream's, else its success kind (`none` when it is typed `None`). */
|
|
59
|
+
function decodedAs(op, answer) {
|
|
60
|
+
if (op.stream === "sse")
|
|
61
|
+
return op.events === undefined ? "text" : "json";
|
|
62
|
+
return op.stream !== null || answer.type === "None" ? "none" : op.success.kind;
|
|
63
|
+
}
|
|
64
|
+
/** The media type a call asks for: an event stream's, or a text or binary answer's. */
|
|
65
|
+
function acceptOf(op, kind) {
|
|
66
|
+
if (op.stream === "sse")
|
|
67
|
+
return "text/event-stream";
|
|
68
|
+
return kind === "text" || kind === "binary" ? mediaEssence(op.success.contentType) : null;
|
|
69
|
+
}
|
|
70
|
+
/** The `Operation(…)` keywords that differ from its defaults, in its field order. */
|
|
71
|
+
function namedArgs(parts, env) {
|
|
72
|
+
const { answer, headers, op } = parts;
|
|
73
|
+
const kind = decodedAs(op, answer);
|
|
74
|
+
const accept = acceptOf(op, kind);
|
|
75
|
+
const shape = shapeOf(op, env);
|
|
76
|
+
const named = [
|
|
77
|
+
["body", op.body === undefined ? null : pyString(op.body.kind)],
|
|
78
|
+
["content_type", op.body === undefined ? null : pyString(op.body.contentType)],
|
|
79
|
+
["answer", kind === "json" ? null : pyString(kind)],
|
|
80
|
+
["accept", accept === null ? null : pyString(accept)],
|
|
81
|
+
["shape", shape === null ? null : pyString(shape)],
|
|
82
|
+
["idempotent", op.idempotent && op.stream === null ? "True" : null],
|
|
83
|
+
["invalidates", op.invalidates.length > 0 ? tuple(op.invalidates.map(pyString)) : null],
|
|
84
|
+
["stream", op.stream === null ? null : pyString(op.stream)],
|
|
85
|
+
["headers", headers === null ? null : tuple(headers.read)],
|
|
86
|
+
];
|
|
87
|
+
return named.flatMap(([key, value]) => (value === null ? [] : [`${key}=${value}`]));
|
|
88
|
+
}
|
|
89
|
+
/** `_<NAME>: Operation[T] = Operation(…)`, every argument but its defaults. */
|
|
90
|
+
function constantLine(parts, env) {
|
|
91
|
+
const { op, path } = parts;
|
|
92
|
+
const params = path.length > 0 ? [tuple(path.map(({ param }) => pyString(param.name)))] : [];
|
|
93
|
+
const args = [pyString(op.method), pyString(op.path), ...params, ...namedArgs(parts, env)];
|
|
94
|
+
return `${parts.constant}: Operation[${parts.answer.type}] = Operation(${args.join(", ")})`;
|
|
95
|
+
}
|
|
96
|
+
/** The keywords sent `where`, as one dict argument; none without any. */
|
|
97
|
+
const dictArg = (keywords, where) => {
|
|
98
|
+
const sent = keywords.filter((keyword) => keyword.where === where);
|
|
99
|
+
const entries = sent.map(({ ident, param }) => `${pyString(param.name)}: ${ident}`);
|
|
100
|
+
return sent.length > 0 ? [`${where === "query" ? "query" : "headers"}={${entries.join(", ")}}`] : [];
|
|
101
|
+
};
|
|
102
|
+
/** The method's lines on one client: its signature, its docstring, the one call into the transport. */
|
|
103
|
+
function methodLines(parts, async, env, shadowed) {
|
|
104
|
+
const { answer, headers, keywords, op, path } = parts;
|
|
105
|
+
const body = bodyType(op, async, env);
|
|
106
|
+
const required = op.body?.required === true;
|
|
107
|
+
const keyed = op.idempotent && op.stream === null;
|
|
108
|
+
const own = op.stream === null ? [] : STREAMS[op.stream].fields;
|
|
109
|
+
/* `name: type`, or `name: type = default`, its type qualified where an earlier method shadows a builtin */
|
|
110
|
+
const param = (text) => {
|
|
111
|
+
const [name, rest] = [text.slice(0, text.indexOf(": ")), text.slice(text.indexOf(": ") + 2)];
|
|
112
|
+
const unset = rest.endsWith(" = None");
|
|
113
|
+
return `${name}: ${qualified(unset ? rest.slice(0, -7) : rest, shadowed, env)}${unset ? " = None" : ""}`;
|
|
114
|
+
};
|
|
115
|
+
const params = [
|
|
116
|
+
"self",
|
|
117
|
+
...[
|
|
118
|
+
...path.map(({ ident }) => `${ident}: str`),
|
|
119
|
+
...(body === null ? [] : [required ? `body: ${body}` : `body: ${optional(body)} = None`]),
|
|
120
|
+
].map(param),
|
|
121
|
+
"*",
|
|
122
|
+
...[
|
|
123
|
+
...keywords.map(({ ident, param: p, type }) => p.required === true ? `${ident}: ${type}` : `${ident}: ${optional(type)} = None`),
|
|
124
|
+
...(keyed ? ["idempotency_key: str | None = None"] : []),
|
|
125
|
+
...(headers === null ? [] : [`headers_into: ${headers.plan.type} | None = None`]),
|
|
126
|
+
...own,
|
|
127
|
+
"options: RequestOptions | None = None",
|
|
128
|
+
].map(param),
|
|
129
|
+
];
|
|
130
|
+
const args = [
|
|
131
|
+
parts.constant,
|
|
132
|
+
...(path.length > 0 ? [`path=${tuple(path.map(({ ident }) => ident))}`] : []),
|
|
133
|
+
...dictArg(keywords, "query"),
|
|
134
|
+
...dictArg(keywords, "header"),
|
|
135
|
+
...(body === null ? [] : ["body=body"]),
|
|
136
|
+
...(keyed ? ["idempotency_key=idempotency_key"] : []),
|
|
137
|
+
...(headers === null ? [] : ["headers_into=headers_into"]),
|
|
138
|
+
...own.map(nameOf).map((field) => `${field}=${field}`),
|
|
139
|
+
"options=options",
|
|
140
|
+
];
|
|
141
|
+
return [
|
|
142
|
+
` ${async ? "async " : ""}def ${parts.name}(${params.join(", ")}) -> ${qualified(answer.returns, shadowed, env)}:`,
|
|
143
|
+
...methodDoc(op, op.stream === null ? [] : STREAMS[op.stream].doc),
|
|
144
|
+
` return ${async ? "await " : ""}self._t.${answer.run}(${args.join(", ")})`,
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
/** The runtime and `collections.abc` names `op`'s methods spell. */
|
|
148
|
+
function noteImports(op, env) {
|
|
149
|
+
const names = { realtime: "ResumableConnection", sse: "EventStream", ws: "TypedWebSocket" };
|
|
150
|
+
if (op.stream !== null)
|
|
151
|
+
env.imports.add(names[op.stream]);
|
|
152
|
+
if (op.stream === "ws" || op.stream === "realtime")
|
|
153
|
+
env.imports.add("Sequence");
|
|
154
|
+
}
|
|
155
|
+
/** The method of `op` named `name`: its constant, its sync method (none for a stream), its async one, its plan. */
|
|
156
|
+
export function pyMethod(op, name, env) {
|
|
157
|
+
const scope = new NameScope([...METHOD_LOCALS, ...(op.stream === null ? [] : STREAMS[op.stream].fields.map(nameOf))]);
|
|
158
|
+
const path = pathParamsOf(op).map((param) => ({ ident: scope.claim(pyIdentifier(param.name)), param }));
|
|
159
|
+
const keywords = keywordsOf(op, scope, env);
|
|
160
|
+
const answer = op.stream === null ? answerOf(op, env) : STREAMS[op.stream].answer(op, env);
|
|
161
|
+
const constant = env.constants.claim(`_${pyIdentifier(op.id).toUpperCase()}`);
|
|
162
|
+
const parts = { answer, constant, headers: responseHeaders(op, env), keywords, name, op, path };
|
|
163
|
+
noteImports(op, env);
|
|
164
|
+
env.imports.add("Operation").add("RequestOptions");
|
|
165
|
+
const by = (where) => Object.fromEntries(keywords.filter((k) => k.where === where).map(({ ident, param }) => [param.name, ident]));
|
|
166
|
+
const plan = {
|
|
167
|
+
body: op.body?.kind ?? null,
|
|
168
|
+
headers: by("header"),
|
|
169
|
+
idempotencyKey: op.idempotent && op.stream === null ? "idempotency_key" : null,
|
|
170
|
+
method: name,
|
|
171
|
+
operation: op.id,
|
|
172
|
+
pathParams: path.map(({ param }) => param.name),
|
|
173
|
+
query: by("query"),
|
|
174
|
+
required: keywords.filter(({ param }) => param.required === true).map(({ ident }) => ident),
|
|
175
|
+
response: op.success.kind,
|
|
176
|
+
responseHeaders: parts.headers?.plan ?? null,
|
|
177
|
+
stream: op.stream,
|
|
178
|
+
sync: op.stream === null,
|
|
179
|
+
};
|
|
180
|
+
const sync = op.stream === null ? (shadowed) => methodLines(parts, false, env, shadowed) : null;
|
|
181
|
+
const async = (shadowed) => methodLines(parts, true, env, shadowed);
|
|
182
|
+
return { async, constant: constantLine(parts, env), name, plan, sync };
|
|
183
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Python SDK's call plan for one operation (contract 28 §4.7), in the emitter's own names: what the fixed
|
|
3
|
+
* reflection driver (`__fixtures__/driver/invoke.py`) walks with `getattr`, so nothing is generated for it
|
|
4
|
+
* (G17). A plan carries no Python type: the driver passes each value as the call gives it.
|
|
5
|
+
*/
|
|
6
|
+
import type { SdkBody, SdkResponseKind, SdkStream } from "../../ir/sdk-model.ts";
|
|
7
|
+
export type PythonCallPlan = {
|
|
8
|
+
readonly operation: string;
|
|
9
|
+
/** the attribute names from the client to the method's resource, root first: `["orgs", "members", "notes"]` */
|
|
10
|
+
readonly accessors: readonly string[];
|
|
11
|
+
/** the method name as emitted (may be `from_`) */
|
|
12
|
+
readonly method: string;
|
|
13
|
+
/** the path params by spec name, in signature order */
|
|
14
|
+
readonly pathParams: readonly string[];
|
|
15
|
+
readonly body: SdkBody["kind"] | null;
|
|
16
|
+
/** each query param's spec name to its keyword */
|
|
17
|
+
readonly query: Readonly<Record<string, string>>;
|
|
18
|
+
/** each header param's spec name to its keyword (a folded stream header is absent) */
|
|
19
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
20
|
+
/** the keywords that have no default */
|
|
21
|
+
readonly required: readonly string[];
|
|
22
|
+
/** the keyword of the idempotency key */
|
|
23
|
+
readonly idempotencyKey: string | null;
|
|
24
|
+
readonly response: SdkResponseKind;
|
|
25
|
+
/** the `<Op>Headers` TypedDict, and each declared header (as the spec spells it) to its key */
|
|
26
|
+
readonly responseHeaders: {
|
|
27
|
+
readonly type: string;
|
|
28
|
+
readonly fields: Readonly<Record<string, string>>;
|
|
29
|
+
} | null;
|
|
30
|
+
readonly stream: SdkStream;
|
|
31
|
+
/** whether `SDK` (sync) has the method: every non-stream op */
|
|
32
|
+
readonly sync: boolean;
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The package manifest (Fb2, Fb3): `pyproject.toml` with the generated marker, hatchling over the src
|
|
3
|
+
* layout, `requires-python` and the one httpx2 dependency. No spec text reaches it; the run's metadata block does
|
|
4
|
+
* (plan 39 8.4), each value already held to its grammar (no control character), and lands as a TOML basic string,
|
|
5
|
+
* whose escapes JSON's are. The package name and version are validated before anything is emitted.
|
|
6
|
+
*/
|
|
7
|
+
import { type Metadata } from "../shared/metadata.ts";
|
|
8
|
+
/** The `requires-python` every emitted package declares: the floor CI installs (PY_FLOOR). */
|
|
9
|
+
export declare const PYTHON_REQUIRES = ">=3.11";
|
|
10
|
+
/**
|
|
11
|
+
* The trove classifiers every package carries: the Python versions from that floor to the one `.python-version` pins,
|
|
12
|
+
* which sdk-pyproject.test holds them to, and typed (PEP 561); no `License ::` (PEP 639).
|
|
13
|
+
*/
|
|
14
|
+
export declare const PYTHON_CLASSIFIERS: readonly string[];
|
|
15
|
+
/** The lowest httpx2 every emitted package accepts. */
|
|
16
|
+
export declare const HTTPX2_FLOOR = "2.12.0";
|
|
17
|
+
/** The dependency string every emitted package declares (`httpx2[ws]` when it needs WebSockets). */
|
|
18
|
+
export declare const HTTPX2 = "httpx2>=2.12.0,<3";
|
|
19
|
+
/** `name` when it is an import name a package may take: lower snake case, no keyword, not the runtime's. */
|
|
20
|
+
export declare function validatePackageName(name: string): string;
|
|
21
|
+
/** `version` when it is in PEP 440's release, pre, post and dev subset. */
|
|
22
|
+
export declare function validateVersion(version: string): string;
|
|
23
|
+
/** The manifest of package `pkg` (its import name; the distribution name has `-` for `_`). */
|
|
24
|
+
export declare function pyproject(pkg: {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly version: string;
|
|
27
|
+
}, ws: boolean, metadata?: Metadata): string;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The package manifest (Fb2, Fb3): `pyproject.toml` with the generated marker, hatchling over the src
|
|
3
|
+
* layout, `requires-python` and the one httpx2 dependency. No spec text reaches it; the run's metadata block does
|
|
4
|
+
* (plan 39 8.4), each value already held to its grammar (no control character), and lands as a TOML basic string,
|
|
5
|
+
* whose escapes JSON's are. The package name and version are validated before anything is emitted.
|
|
6
|
+
*/
|
|
7
|
+
import { authorOf, issuesUrl, LICENSE, README, shippedOf } from "../shared/metadata.js";
|
|
8
|
+
/** The `requires-python` every emitted package declares: the floor CI installs (PY_FLOOR). */
|
|
9
|
+
export const PYTHON_REQUIRES = ">=3.11";
|
|
10
|
+
/**
|
|
11
|
+
* The trove classifiers every package carries: the Python versions from that floor to the one `.python-version` pins,
|
|
12
|
+
* which sdk-pyproject.test holds them to, and typed (PEP 561); no `License ::` (PEP 639).
|
|
13
|
+
*/
|
|
14
|
+
export const PYTHON_CLASSIFIERS = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
21
|
+
"Typing :: Typed",
|
|
22
|
+
];
|
|
23
|
+
/* honey's own record of what it wrote (gen/write.ts MANIFEST), which no sdist ships */
|
|
24
|
+
const MANIFEST = ".honey-generated.json";
|
|
25
|
+
/** The lowest httpx2 every emitted package accepts. */
|
|
26
|
+
export const HTTPX2_FLOOR = "2.12.0";
|
|
27
|
+
/** The dependency string every emitted package declares (`httpx2[ws]` when it needs WebSockets). */
|
|
28
|
+
export const HTTPX2 = `httpx2>=${HTTPX2_FLOOR},<3`;
|
|
29
|
+
/* the hard keywords and the soft ones, none an import name */
|
|
30
|
+
const KEYWORDS = " False None True and as assert async await break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield match case type _ ";
|
|
31
|
+
/** `name` when it is an import name a package may take: lower snake case, no keyword, not the runtime's. */
|
|
32
|
+
export function validatePackageName(name) {
|
|
33
|
+
if (!/^[a-z][a-z0-9_]*$/.test(name) || KEYWORDS.includes(` ${name} `) || name === "_honey") {
|
|
34
|
+
throw new Error(`Invalid package name: "${name}"`);
|
|
35
|
+
}
|
|
36
|
+
return name;
|
|
37
|
+
}
|
|
38
|
+
/** `version` when it is in PEP 440's release, pre, post and dev subset. */
|
|
39
|
+
export function validateVersion(version) {
|
|
40
|
+
if (!/^\d+(\.\d+)*((a|b|rc)\d+)?(\.post\d+)?(\.dev\d+)?$/.test(version)) {
|
|
41
|
+
throw new Error(`Invalid version: "${version}"`);
|
|
42
|
+
}
|
|
43
|
+
return version;
|
|
44
|
+
}
|
|
45
|
+
/** A TOML basic string of `text`. */
|
|
46
|
+
const toml = (text) => JSON.stringify(text);
|
|
47
|
+
/** One author as PEP 621's inline table: its name, and its email when given. */
|
|
48
|
+
function authorTable(author) {
|
|
49
|
+
const { email, name } = authorOf(author);
|
|
50
|
+
return email === undefined ? `{ name = ${toml(name)} }` : `{ name = ${toml(name)}, email = ${toml(email)} }`;
|
|
51
|
+
}
|
|
52
|
+
/** The `[project]` lines the metadata block fills, each only when given, in PEP 621's order: the README and the
|
|
53
|
+
* license file (PEP 639) by the names they ship under. */
|
|
54
|
+
function described(metadata) {
|
|
55
|
+
const { authors, description, keywords, license } = metadata;
|
|
56
|
+
const shipped = shippedOf(metadata);
|
|
57
|
+
return [
|
|
58
|
+
...(description === undefined ? [] : [`description = ${toml(description)}`]),
|
|
59
|
+
...(shipped.readme ? [`readme = ${toml(README)}`] : []),
|
|
60
|
+
`requires-python = "${PYTHON_REQUIRES}"`,
|
|
61
|
+
...(license === undefined ? [] : [`license = ${toml(license)}`]),
|
|
62
|
+
...(shipped.licenseFile ? [`license-files = [${toml(LICENSE)}]`] : []),
|
|
63
|
+
...(authors === undefined ? [] : [`authors = [${authors.map(authorTable).join(", ")}]`]),
|
|
64
|
+
...(keywords === undefined ? [] : [`keywords = [${keywords.map(toml).join(", ")}]`]),
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
/** `[project.urls]` under the well-known labels PyPI shows, or nothing when the block gives no URL. */
|
|
68
|
+
function urls(metadata) {
|
|
69
|
+
const { changelog, documentation, homepage, repository } = metadata;
|
|
70
|
+
const labeled = [
|
|
71
|
+
["Homepage", homepage],
|
|
72
|
+
["Source", repository],
|
|
73
|
+
["Issues", repository === undefined ? undefined : issuesUrl(repository)],
|
|
74
|
+
["Documentation", documentation],
|
|
75
|
+
["Changelog", changelog],
|
|
76
|
+
].filter((entry) => entry[1] !== undefined);
|
|
77
|
+
return labeled.length === 0 ? [] : ["[project.urls]", ...labeled.map(([label, url]) => `${label} = ${toml(url)}`), ""];
|
|
78
|
+
}
|
|
79
|
+
/** The manifest of package `pkg` (its import name; the distribution name has `-` for `_`). */
|
|
80
|
+
export function pyproject(pkg, ws, metadata = {}) {
|
|
81
|
+
const dependency = ws ? HTTPX2.replace("httpx2", "httpx2[ws]") : HTTPX2;
|
|
82
|
+
return [
|
|
83
|
+
"# @generated by honey. DO NOT EDIT.",
|
|
84
|
+
"[build-system]",
|
|
85
|
+
'requires = ["hatchling>=1.27"]',
|
|
86
|
+
'build-backend = "hatchling.build"',
|
|
87
|
+
"",
|
|
88
|
+
"[project]",
|
|
89
|
+
`name = "${pkg.name.replaceAll("_", "-")}"`,
|
|
90
|
+
`version = "${pkg.version}"`,
|
|
91
|
+
...described(metadata),
|
|
92
|
+
`classifiers = [${PYTHON_CLASSIFIERS.map(toml).join(", ")}]`,
|
|
93
|
+
`dependencies = ["${dependency}"]`,
|
|
94
|
+
"",
|
|
95
|
+
...urls(metadata),
|
|
96
|
+
"[tool.hatch.build.targets.sdist]",
|
|
97
|
+
`exclude = ["${MANIFEST}"]`,
|
|
98
|
+
"",
|
|
99
|
+
"[tool.hatch.build.targets.wheel]",
|
|
100
|
+
`packages = ["src/${pkg.name}"]`,
|
|
101
|
+
"",
|
|
102
|
+
].join("\n");
|
|
103
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PythonCallPlan } from "./sdk-plan.ts";
|
|
2
|
+
import { type Metadata, type PackageIdentity } from "../shared/metadata.ts";
|
|
3
|
+
export type PythonSdkOptions = {
|
|
4
|
+
/** the import name; `honey_sdk` by default, its distribution name with `-` for `_` */
|
|
5
|
+
readonly packageName?: string;
|
|
6
|
+
/** the package version; `0.1.0` by default */
|
|
7
|
+
readonly version?: string;
|
|
8
|
+
};
|
|
9
|
+
/** The package's files by path, and what the generation reports: a root member renamed for the safe mirror. */
|
|
10
|
+
export type GeneratedPythonSdk = {
|
|
11
|
+
readonly files: Readonly<Record<string, string>>;
|
|
12
|
+
readonly notices: readonly string[];
|
|
13
|
+
/** the distribution as PyPI lists it */
|
|
14
|
+
readonly packages: readonly PackageIdentity[];
|
|
15
|
+
};
|
|
16
|
+
/** The package's files for `document`, by path, and its notices; `metadata` fills pyproject.toml's description fields. */
|
|
17
|
+
export declare function generatePythonSdk(document: Record<string, unknown>, options?: PythonSdkOptions, metadata?: Metadata): GeneratedPythonSdk;
|
|
18
|
+
/**
|
|
19
|
+
* Each operation's call plan by id, from the very emit `generatePythonSdk` runs with these options: the names
|
|
20
|
+
* the fixed reflection driver walks (G17), never re-derived outside the emitter.
|
|
21
|
+
*/
|
|
22
|
+
export declare function pythonCallPlans(document: Record<string, unknown>, options?: PythonSdkOptions): Readonly<Record<string, PythonCallPlan>>;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Python SDK (bit 14): a package emitted from the IR alone (H2), in the src layout: `pyproject.toml`,
|
|
3
|
+
* `src/<pkg>/types.py` (every component, then every hoisted declaration, in name order, then the `ErrorKey`
|
|
4
|
+
* StrEnum when the API declares error keys), `client.py` (the
|
|
5
|
+
* resource classes and the `SDK` and `AsyncSDK` clients, each with its `safe` mirror), `__init__.py` (the package
|
|
6
|
+
* root's exports), an empty `py.typed`, and the vendored runtime under `_honey/`. Every `.py` file and the manifest
|
|
7
|
+
* carry the marker. A client always raises; `client.safe` answers the same calls as a `Result` (bit 21 i2), so there
|
|
8
|
+
* is no error-mode option.
|
|
9
|
+
*/
|
|
10
|
+
import { toIR } from "../../ir/build.js";
|
|
11
|
+
import { sdkModel } from "../../ir/sdk-model.js";
|
|
12
|
+
import { pyDocLines } from "../shared/escape.js";
|
|
13
|
+
import { compareCodeUnits, NameScope } from "../shared/lang.js";
|
|
14
|
+
import { pythonErrorKeys } from "./errors.js";
|
|
15
|
+
import { clientDecls, clientTitle } from "./sdk-client.js";
|
|
16
|
+
import { allOrder, importBlock, importLine } from "./sdk-imports.js";
|
|
17
|
+
import { packageOn } from "../shared/metadata.js";
|
|
18
|
+
import { pyproject, validatePackageName, validateVersion } from "./sdk-pyproject.js";
|
|
19
|
+
import { needsWebSocket, runtimeExports, runtimeFiles } from "./transport.js";
|
|
20
|
+
import { pyTopLevel, pyTypeContext } from "./types.js";
|
|
21
|
+
/* the marker ruff, mypy and linguist read */
|
|
22
|
+
const MARKER = "# @generated by honey. DO NOT EDIT.";
|
|
23
|
+
/* where client.py imports each runtime name from, under `._honey.` */
|
|
24
|
+
const RUNTIME = {
|
|
25
|
+
AsyncRealtimeTransport: "realtime",
|
|
26
|
+
AsyncTransport: "send_async",
|
|
27
|
+
AsyncWsTransport: "ws",
|
|
28
|
+
ClientConfig: "config",
|
|
29
|
+
Defaults: "config",
|
|
30
|
+
EventStream: "events",
|
|
31
|
+
Operation: "operation",
|
|
32
|
+
RequestOptions: "config",
|
|
33
|
+
ResumableConnection: "realtime",
|
|
34
|
+
Safe: "result",
|
|
35
|
+
SyncTransport: "send_sync",
|
|
36
|
+
TypedWebSocket: "ws",
|
|
37
|
+
};
|
|
38
|
+
/** A docstring of `lines` at column 0: one line, or the first on the quotes and the closing quotes alone. */
|
|
39
|
+
const docstring = (lines) => lines.length === 1 ? [`"""${lines[0]}"""`] : [`"""${lines[0]}`, ...lines.slice(1), '"""'];
|
|
40
|
+
/** The blank lines before a module's `i`th declaration: one after the imports unless it is a class, else two. */
|
|
41
|
+
const gap = (decl, i) => (i === 0 && !decl.startsWith("class ") ? [""] : ["", ""]);
|
|
42
|
+
/** A module: the marker, its docstring, its imports (every module has one), then its declarations two blank lines
|
|
43
|
+
* apart, one after the imports when the first is no class (isort's spacing). */
|
|
44
|
+
function pyFile(doc, imports, decls) {
|
|
45
|
+
const head = [MARKER, ...docstring(doc), "", ...importBlock(imports)];
|
|
46
|
+
return [...head, ...decls.flatMap((decl, i) => [...gap(decl, i), decl]), ""].join("\n");
|
|
47
|
+
}
|
|
48
|
+
/** Each component's declaration in code-unit order, its description as its docstring: [name, text]. */
|
|
49
|
+
function componentDecls(ir, at) {
|
|
50
|
+
return Object.keys(ir.schemas)
|
|
51
|
+
.sort(compareCodeUnits)
|
|
52
|
+
.map((name) => {
|
|
53
|
+
const claimed = at.names.ref(name);
|
|
54
|
+
return [claimed, pyTopLevel(claimed, ir.schemas[name], at, ir.schemaDescriptions[name])];
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** The identifiers `text` spells outside its strings. */
|
|
58
|
+
const spelled = (text) => new Set(Array.from(text.replace(/"""[\s\S]*?"""|"(?:[^"\\\n]|\\.)*"/g, '""').matchAll(/[A-Za-z_]\w*/g), (match) => match[0]));
|
|
59
|
+
/** client.py: the marker, the API's doc, its imports, then its declarations. */
|
|
60
|
+
function clientFile(ir, env, body) {
|
|
61
|
+
const doc = pyDocLines([clientTitle(ir), ir.info.description].filter((part) => part !== undefined).join("\n\n"));
|
|
62
|
+
const used = spelled(body.lines.join("\n"));
|
|
63
|
+
const honey = new Map();
|
|
64
|
+
for (const name of ["ClientConfig", "Defaults", "Safe", "SyncTransport", env.transport, ...env.imports].filter((n) => n in RUNTIME))
|
|
65
|
+
honey.set(RUNTIME[name], [...(honey.get(RUNTIME[name]) ?? []), name]);
|
|
66
|
+
const sections = [
|
|
67
|
+
["from __future__ import annotations"],
|
|
68
|
+
[
|
|
69
|
+
...(env.imports.has("builtins") ? ["import builtins as _builtins"] : []),
|
|
70
|
+
...importLine("collections.abc", [...env.imports].filter((name) => !(name in RUNTIME) && name !== "builtins")),
|
|
71
|
+
...importLine("typing", [...env.at.typing, "Self"]),
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
...[...honey.keys()]
|
|
75
|
+
.sort(compareCodeUnits)
|
|
76
|
+
.flatMap((module) => importLine(`._honey.${module}`, honey.get(module))),
|
|
77
|
+
...importLine(".types", body.types.filter((name) => used.has(name))),
|
|
78
|
+
],
|
|
79
|
+
];
|
|
80
|
+
return pyFile(doc, sections, [body.lines.join("\n")]);
|
|
81
|
+
}
|
|
82
|
+
/** __init__.py: each runtime module's exports, the clients, every type; all of them in `__all__`. */
|
|
83
|
+
function initFile(ir, runtime, types) {
|
|
84
|
+
const modules = Object.entries(runtime).map(([file, source]) => [file.replace(/\.py$/, ""), runtimeExports(source)]);
|
|
85
|
+
const lines = [
|
|
86
|
+
...modules.flatMap(([module, names]) => importLine(`._honey.${module}`, names)),
|
|
87
|
+
...importLine(".client", ["SDK", "AsyncSDK"]),
|
|
88
|
+
...importLine(".types", types),
|
|
89
|
+
];
|
|
90
|
+
const all = allOrder([...modules.flatMap(([, names]) => names), "SDK", "AsyncSDK", ...types]);
|
|
91
|
+
return pyFile([clientTitle(ir)], [lines], [`__all__ = [${all.map((name) => `"${name}"`).join(", ")}]`]);
|
|
92
|
+
}
|
|
93
|
+
/** The package's files for `document`, and the call plan of every method in them. */
|
|
94
|
+
function emitPython(document, options, metadata = {}) {
|
|
95
|
+
const pkg = {
|
|
96
|
+
name: validatePackageName(options.packageName ?? "honey_sdk"),
|
|
97
|
+
version: validateVersion(options.version ?? "0.1.0"),
|
|
98
|
+
};
|
|
99
|
+
const ir = toIR(document, { deriveOperationIds: true });
|
|
100
|
+
const model = sdkModel(ir);
|
|
101
|
+
const at = pyTypeContext(ir);
|
|
102
|
+
/* components first: the client's hoisted types then land beside them */
|
|
103
|
+
const components = componentDecls(ir, at);
|
|
104
|
+
/* before the client: its `_DEFAULTS` names ErrorKey, and each `<Key>Data` lands among the hoisted declarations */
|
|
105
|
+
const errorKey = pythonErrorKeys(model, at);
|
|
106
|
+
const features = {
|
|
107
|
+
realtime: model.ops.some((op) => op.stream === "realtime"),
|
|
108
|
+
ws: model.ops.some((op) => op.stream === "ws"),
|
|
109
|
+
};
|
|
110
|
+
const transport = features.realtime ? "AsyncRealtimeTransport" : features.ws ? "AsyncWsTransport" : "AsyncTransport";
|
|
111
|
+
const env = {
|
|
112
|
+
at: { ...at, declTyping: at.typing, typing: new Set() },
|
|
113
|
+
constants: new NameScope(),
|
|
114
|
+
imports: new Set(),
|
|
115
|
+
keyed: errorKey !== null,
|
|
116
|
+
notices: [],
|
|
117
|
+
ops: model.opsById,
|
|
118
|
+
transport,
|
|
119
|
+
typesImports: new Set(),
|
|
120
|
+
};
|
|
121
|
+
const client = clientDecls(ir, env);
|
|
122
|
+
const hoisted = [...at.decls].sort(([a], [b]) => compareCodeUnits(a, b));
|
|
123
|
+
const decls = [...components, ...hoisted, ...(errorKey === null ? [] : [["ErrorKey", errorKey]])];
|
|
124
|
+
const types = decls.map(([name]) => name);
|
|
125
|
+
const runtime = runtimeFiles(features);
|
|
126
|
+
const typesDoc = pyDocLines(ir.info.title === undefined ? "The API's types." : `The ${ir.info.title} API's types.`);
|
|
127
|
+
const root = `src/${pkg.name}`;
|
|
128
|
+
const files = {
|
|
129
|
+
"pyproject.toml": pyproject(pkg, needsWebSocket(features), metadata),
|
|
130
|
+
[`${root}/__init__.py`]: initFile(ir, runtime, types),
|
|
131
|
+
[`${root}/client.py`]: clientFile(ir, env, { lines: client.lines, types }),
|
|
132
|
+
[`${root}/py.typed`]: "",
|
|
133
|
+
[`${root}/types.py`]: pyFile([typesDoc[0]], [
|
|
134
|
+
["from __future__ import annotations"],
|
|
135
|
+
[...(errorKey === null ? [] : ["from enum import StrEnum"]), ...importLine("typing", at.typing)],
|
|
136
|
+
importLine("._honey.body", env.typesImports),
|
|
137
|
+
], decls.map(([, text]) => text)),
|
|
138
|
+
...Object.fromEntries(Object.entries(runtime).map(([name, source]) => [`${root}/_honey/${name}`, source])),
|
|
139
|
+
};
|
|
140
|
+
const sorted = Object.fromEntries(Object.entries(files).sort(([a], [b]) => compareCodeUnits(a, b)));
|
|
141
|
+
return { files: sorted, notices: env.notices, pkg, plans: client.plans };
|
|
142
|
+
}
|
|
143
|
+
/** The package's files for `document`, by path, and its notices; `metadata` fills pyproject.toml's description fields. */
|
|
144
|
+
export function generatePythonSdk(document, options = {}, metadata = {}) {
|
|
145
|
+
const { files, notices, pkg } = emitPython(document, options, metadata);
|
|
146
|
+
return { files, notices, packages: [packageOn("pypi", pkg.name.replaceAll("_", "-"), pkg.version)] };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Each operation's call plan by id, from the very emit `generatePythonSdk` runs with these options: the names
|
|
150
|
+
* the fixed reflection driver walks (G17), never re-derived outside the emitter.
|
|
151
|
+
*/
|
|
152
|
+
export function pythonCallPlans(document, options = {}) {
|
|
153
|
+
return Object.fromEntries(emitPython(document, options).plans.map((plan) => [plan.operation, plan]));
|
|
154
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An SSE operation's answer (contract 34 §2.0–2.1): `EventStream[E]`, `E` the declared event schema's type (`str`
|
|
3
|
+
* for untyped events), opened by awaiting the method (G15), and its `last_event_id` field, sent as Last-Event-ID
|
|
4
|
+
* only when set and non-empty; a declared Last-Event-ID header param is folded into that field (Fd3).
|
|
5
|
+
*/
|
|
6
|
+
import { type PyStream } from "./sdk-answer.ts";
|
|
7
|
+
/** The header the SSE and realtime dials resume an event stream with. */
|
|
8
|
+
export declare const LAST_EVENT_ID = "Last-Event-ID";
|
|
9
|
+
/** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
|
|
10
|
+
export declare const isLastEventIdHeader: (name: string, where: string) => boolean;
|
|
11
|
+
/** The SSE operation's answer, its one field and its docstring's lines. */
|
|
12
|
+
export declare const sseStream: PyStream;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An SSE operation's answer (contract 34 §2.0–2.1): `EventStream[E]`, `E` the declared event schema's type (`str`
|
|
3
|
+
* for untyped events), opened by awaiting the method (G15), and its `last_event_id` field, sent as Last-Event-ID
|
|
4
|
+
* only when set and non-empty; a declared Last-Event-ID header param is folded into that field (Fd3).
|
|
5
|
+
*/
|
|
6
|
+
import { eventType } from "./sdk-answer.js";
|
|
7
|
+
/** The header the SSE and realtime dials resume an event stream with. */
|
|
8
|
+
export const LAST_EVENT_ID = "Last-Event-ID";
|
|
9
|
+
/** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
|
|
10
|
+
export const isLastEventIdHeader = (name, where) => where === "header" && name.toLowerCase() === LAST_EVENT_ID.toLowerCase();
|
|
11
|
+
/** The SSE operation's answer, its one field and its docstring's lines. */
|
|
12
|
+
export const sseStream = {
|
|
13
|
+
answer: (op, env) => {
|
|
14
|
+
const events = eventType(op, env, () => "str");
|
|
15
|
+
return { returns: `EventStream[${events}]`, run: "sse", type: events };
|
|
16
|
+
},
|
|
17
|
+
carries: isLastEventIdHeader,
|
|
18
|
+
doc: [
|
|
19
|
+
"Opens the stream: an error status raises before any event. No timeout bounds it after that;",
|
|
20
|
+
'options["cancel"], aclose() or dropping it ends it.',
|
|
21
|
+
],
|
|
22
|
+
fields: ["last_event_id: str | None = None"],
|
|
23
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** What the API needs from the runtime beyond plain HTTP. */
|
|
2
|
+
export type PythonRuntimeFeatures = {
|
|
3
|
+
readonly realtime: boolean;
|
|
4
|
+
readonly ws: boolean;
|
|
5
|
+
};
|
|
6
|
+
/** Whether these features make the package depend on `httpx2[ws]` (Fb3). */
|
|
7
|
+
export declare const needsWebSocket: (features: PythonRuntimeFeatures) => boolean;
|
|
8
|
+
/** The runtime file names an SDK with `features` ships, `.py` included, in code-unit order. */
|
|
9
|
+
export declare function runtimeFileNames(features: PythonRuntimeFeatures): string[];
|
|
10
|
+
/** The runtime files an SDK with `features` ships, by file name, read verbatim. */
|
|
11
|
+
export declare function runtimeFiles(features: PythonRuntimeFeatures): Record<string, string>;
|
|
12
|
+
/** A runtime module's root exports: the names its `__all__` lists, in order; none without one. */
|
|
13
|
+
export declare function runtimeExports(source: string): string[];
|
|
14
|
+
/** A module's top-level public names (column 0, no leading `_`), in source order: what a component may not take. */
|
|
15
|
+
export declare function publicNames(source: string): string[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vendored Python runtime, as the files a Python SDK ships under `src/<pkg>/_honey/` (H9/F5):
|
|
3
|
+
* `runtime/python/*.py`, read here and nowhere else (the F8 mutation target), emitted verbatim. The WebSocket
|
|
4
|
+
* module ships for a WebSocket or realtime API and the realtime modules for a realtime API, so a plain HTTP SDK
|
|
5
|
+
* carries neither them nor the `httpx2[ws]` extra.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
import { compareCodeUnits } from "../shared/lang.js";
|
|
9
|
+
/* every SDK: the sans-IO core and its two shells, config, errors, hooks, log, redirects, SSE, invalidation */
|
|
10
|
+
const CORE = [
|
|
11
|
+
"__init__",
|
|
12
|
+
"auth",
|
|
13
|
+
"body",
|
|
14
|
+
"config",
|
|
15
|
+
"errors",
|
|
16
|
+
"events",
|
|
17
|
+
"exchange",
|
|
18
|
+
"hooks",
|
|
19
|
+
"invalidation",
|
|
20
|
+
"log",
|
|
21
|
+
"operation",
|
|
22
|
+
"path",
|
|
23
|
+
"query",
|
|
24
|
+
"redirect",
|
|
25
|
+
"result",
|
|
26
|
+
"send_async",
|
|
27
|
+
"send_sync",
|
|
28
|
+
"sse",
|
|
29
|
+
"stale",
|
|
30
|
+
];
|
|
31
|
+
/* a WebSocket operation; realtime adds the transports on top of it */
|
|
32
|
+
const WS = ["ws"];
|
|
33
|
+
const REALTIME = ["realtime", "transport", "transport_longpoll", "transport_sse", "transport_ws"];
|
|
34
|
+
/* a module's `__all__ = [...]`, one name per line or on one line */
|
|
35
|
+
const ALL = /^__all__ = \[([^\]]*)\]/m;
|
|
36
|
+
/* a top-level public name: `class X`, `def x`, `async def x`, `X =` or `X: T =` at column 0 */
|
|
37
|
+
const PUBLIC_NAME = /^(?:class (?<cls>[A-Za-z]\w*)|(?:async )?def (?<fn>[A-Za-z]\w*)\(|(?<bound>[A-Za-z]\w*)(?:: [^=\n]+)? = )/gm;
|
|
38
|
+
/** Whether these features make the package depend on `httpx2[ws]` (Fb3). */
|
|
39
|
+
export const needsWebSocket = (features) => features.ws || features.realtime;
|
|
40
|
+
/** The runtime file names an SDK with `features` ships, `.py` included, in code-unit order. */
|
|
41
|
+
export function runtimeFileNames(features) {
|
|
42
|
+
const names = [...CORE, ...(needsWebSocket(features) ? WS : []), ...(features.realtime ? REALTIME : [])];
|
|
43
|
+
return names.map((name) => `${name}.py`).sort(compareCodeUnits);
|
|
44
|
+
}
|
|
45
|
+
/** The runtime files an SDK with `features` ships, by file name, read verbatim. */
|
|
46
|
+
export function runtimeFiles(features) {
|
|
47
|
+
return Object.fromEntries(runtimeFileNames(features).map((name) => [
|
|
48
|
+
name,
|
|
49
|
+
readFileSync(new URL(`../../runtime/python/${name}`, import.meta.url), "utf8"),
|
|
50
|
+
]));
|
|
51
|
+
}
|
|
52
|
+
/** A runtime module's root exports: the names its `__all__` lists, in order; none without one. */
|
|
53
|
+
export function runtimeExports(source) {
|
|
54
|
+
const list = ALL.exec(source)?.[1] ?? "";
|
|
55
|
+
return [...list.matchAll(/"([^"]+)"/g)].map((match) => match[1]);
|
|
56
|
+
}
|
|
57
|
+
/** A module's top-level public names (column 0, no leading `_`), in source order: what a component may not take. */
|
|
58
|
+
export function publicNames(source) {
|
|
59
|
+
return [...source.matchAll(PUBLIC_NAME)].map(({ groups }) => (groups?.cls ?? groups?.fn ?? groups?.bound));
|
|
60
|
+
}
|