@workerstack/clients 0.0.0-stage → 1.0.0-rc.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +619 -2
- package/bin/honey-clients.js +94 -0
- package/dist/cli.d.ts +102 -0
- package/dist/cli.js +190 -0
- package/dist/emit/cli/channels.d.ts +73 -0
- package/dist/emit/cli/channels.js +197 -0
- package/dist/emit/cli/commands.d.ts +27 -0
- package/dist/emit/cli/commands.js +187 -0
- package/dist/emit/cli/discovery.d.ts +35 -0
- package/dist/emit/cli/discovery.js +202 -0
- package/dist/emit/cli/flags.d.ts +59 -0
- package/dist/emit/cli/flags.js +186 -0
- package/dist/emit/cli/index.d.ts +1 -0
- package/dist/emit/cli/index.js +1 -0
- package/dist/emit/cli/install.d.ts +37 -0
- package/dist/emit/cli/install.js +88 -0
- package/dist/emit/cli/layout.d.ts +23 -0
- package/dist/emit/cli/layout.js +118 -0
- package/dist/emit/cli/module.d.ts +30 -0
- package/dist/emit/cli/module.js +186 -0
- package/dist/emit/cli/release.d.ts +40 -0
- package/dist/emit/cli/release.js +183 -0
- package/dist/emit/cli/skills.d.ts +11 -0
- package/dist/emit/cli/skills.js +56 -0
- package/dist/emit/csharp/errors.d.ts +7 -0
- package/dist/emit/csharp/errors.js +69 -0
- package/dist/emit/csharp/index.d.ts +1 -0
- package/dist/emit/csharp/index.js +1 -0
- package/dist/emit/csharp/json.d.ts +13 -0
- package/dist/emit/csharp/json.js +113 -0
- package/dist/emit/csharp/realtime.d.ts +10 -0
- package/dist/emit/csharp/realtime.js +33 -0
- package/dist/emit/csharp/sdk-answer.d.ts +48 -0
- package/dist/emit/csharp/sdk-answer.js +85 -0
- package/dist/emit/csharp/sdk-body.d.ts +10 -0
- package/dist/emit/csharp/sdk-body.js +87 -0
- package/dist/emit/csharp/sdk-client.d.ts +32 -0
- package/dist/emit/csharp/sdk-client.js +177 -0
- package/dist/emit/csharp/sdk-csproj.d.ts +36 -0
- package/dist/emit/csharp/sdk-csproj.js +136 -0
- package/dist/emit/csharp/sdk-doc.d.ts +12 -0
- package/dist/emit/csharp/sdk-doc.js +35 -0
- package/dist/emit/csharp/sdk-method.d.ts +26 -0
- package/dist/emit/csharp/sdk-method.js +187 -0
- package/dist/emit/csharp/sdk-plan.d.ts +38 -0
- package/dist/emit/csharp/sdk-plan.js +1 -0
- package/dist/emit/csharp/sdk.d.ts +40 -0
- package/dist/emit/csharp/sdk.js +105 -0
- package/dist/emit/csharp/sse.d.ts +18 -0
- package/dist/emit/csharp/sse.js +29 -0
- package/dist/emit/csharp/transport.d.ts +11 -0
- package/dist/emit/csharp/transport.js +67 -0
- package/dist/emit/csharp/types-enum.d.ts +19 -0
- package/dist/emit/csharp/types-enum.js +63 -0
- package/dist/emit/csharp/types-names.d.ts +33 -0
- package/dist/emit/csharp/types-names.js +182 -0
- package/dist/emit/csharp/types-record.d.ts +25 -0
- package/dist/emit/csharp/types-record.js +65 -0
- package/dist/emit/csharp/types-union.d.ts +27 -0
- package/dist/emit/csharp/types-union.js +113 -0
- package/dist/emit/csharp/types.d.ts +36 -0
- package/dist/emit/csharp/types.js +126 -0
- package/dist/emit/csharp/ws.d.ts +20 -0
- package/dist/emit/csharp/ws.js +14 -0
- package/dist/emit/go/errors.d.ts +7 -0
- package/dist/emit/go/errors.js +44 -0
- package/dist/emit/go/http.d.ts +11 -0
- package/dist/emit/go/http.js +50 -0
- package/dist/emit/go/index.d.ts +1 -0
- package/dist/emit/go/index.js +1 -0
- package/dist/emit/go/module-path.d.ts +2 -0
- package/dist/emit/go/module-path.js +27 -0
- package/dist/emit/go/sdk-answer.d.ts +28 -0
- package/dist/emit/go/sdk-answer.js +41 -0
- package/dist/emit/go/sdk-body.d.ts +24 -0
- package/dist/emit/go/sdk-body.js +76 -0
- package/dist/emit/go/sdk-client.d.ts +29 -0
- package/dist/emit/go/sdk-client.js +141 -0
- package/dist/emit/go/sdk-method.d.ts +68 -0
- package/dist/emit/go/sdk-method.js +172 -0
- package/dist/emit/go/sdk-mirror.d.ts +23 -0
- package/dist/emit/go/sdk-mirror.js +97 -0
- package/dist/emit/go/sdk-opts.d.ts +55 -0
- package/dist/emit/go/sdk-opts.js +100 -0
- package/dist/emit/go/sdk.d.ts +26 -0
- package/dist/emit/go/sdk.js +111 -0
- package/dist/emit/go/sse.d.ts +16 -0
- package/dist/emit/go/sse.js +26 -0
- package/dist/emit/go/types-codec.d.ts +15 -0
- package/dist/emit/go/types-codec.js +171 -0
- package/dist/emit/go/types-names.d.ts +14 -0
- package/dist/emit/go/types-names.js +64 -0
- package/dist/emit/go/types-struct.d.ts +29 -0
- package/dist/emit/go/types-struct.js +65 -0
- package/dist/emit/go/types-union.d.ts +17 -0
- package/dist/emit/go/types-union.js +84 -0
- package/dist/emit/go/types.d.ts +32 -0
- package/dist/emit/go/types.js +177 -0
- package/dist/emit/go/ws.d.ts +12 -0
- package/dist/emit/go/ws.js +70 -0
- package/dist/emit/java/gradle.d.ts +57 -0
- package/dist/emit/java/gradle.js +221 -0
- package/dist/emit/java/index.d.ts +2 -0
- package/dist/emit/java/index.js +2 -0
- package/dist/emit/java/json.d.ts +13 -0
- package/dist/emit/java/json.js +84 -0
- package/dist/emit/java/layout-ast.d.ts +146 -0
- package/dist/emit/java/layout-ast.js +102 -0
- package/dist/emit/java/layout-decl.d.ts +20 -0
- package/dist/emit/java/layout-decl.js +155 -0
- package/dist/emit/java/layout-doc.d.ts +55 -0
- package/dist/emit/java/layout-doc.js +166 -0
- package/dist/emit/java/layout-dot.d.ts +18 -0
- package/dist/emit/java/layout-dot.js +127 -0
- package/dist/emit/java/layout-strings.d.ts +8 -0
- package/dist/emit/java/layout-strings.js +76 -0
- package/dist/emit/java/layout-types.d.ts +11 -0
- package/dist/emit/java/layout-types.js +95 -0
- package/dist/emit/java/layout-visitor.d.ts +38 -0
- package/dist/emit/java/layout-visitor.js +232 -0
- package/dist/emit/java/layout.d.ts +61 -0
- package/dist/emit/java/layout.js +121 -0
- package/dist/emit/java/models-enum.d.ts +17 -0
- package/dist/emit/java/models-enum.js +51 -0
- package/dist/emit/java/models-names.d.ts +29 -0
- package/dist/emit/java/models-names.js +97 -0
- package/dist/emit/java/models-record.d.ts +24 -0
- package/dist/emit/java/models-record.js +79 -0
- package/dist/emit/java/models-union.d.ts +27 -0
- package/dist/emit/java/models-union.js +86 -0
- package/dist/emit/java/models.d.ts +28 -0
- package/dist/emit/java/models.js +118 -0
- package/dist/emit/java/realtime.d.ts +50 -0
- package/dist/emit/java/realtime.js +69 -0
- package/dist/emit/java/sdk-client.d.ts +66 -0
- package/dist/emit/java/sdk-client.js +207 -0
- package/dist/emit/java/sdk-decl.d.ts +11 -0
- package/dist/emit/java/sdk-decl.js +63 -0
- package/dist/emit/java/sdk-errors.d.ts +13 -0
- package/dist/emit/java/sdk-errors.js +141 -0
- package/dist/emit/java/sdk-headers.d.ts +12 -0
- package/dist/emit/java/sdk-headers.js +74 -0
- package/dist/emit/java/sdk-mirror.d.ts +14 -0
- package/dist/emit/java/sdk-mirror.js +107 -0
- package/dist/emit/java/sdk-models.d.ts +16 -0
- package/dist/emit/java/sdk-models.js +68 -0
- package/dist/emit/java/sdk-op.d.ts +57 -0
- package/dist/emit/java/sdk-op.js +216 -0
- package/dist/emit/java/sdk-params.d.ts +38 -0
- package/dist/emit/java/sdk-params.js +133 -0
- package/dist/emit/java/sdk-plan.d.ts +52 -0
- package/dist/emit/java/sdk-plan.js +1 -0
- package/dist/emit/java/sdk-record.d.ts +16 -0
- package/dist/emit/java/sdk-record.js +99 -0
- package/dist/emit/java/sdk.d.ts +49 -0
- package/dist/emit/java/sdk.js +216 -0
- package/dist/emit/java/sse.d.ts +35 -0
- package/dist/emit/java/sse.js +57 -0
- package/dist/emit/java/ws.d.ts +27 -0
- package/dist/emit/java/ws.js +31 -0
- package/dist/emit/mcp/annotations.d.ts +15 -0
- package/dist/emit/mcp/annotations.js +15 -0
- package/dist/emit/mcp/files.d.ts +18 -0
- package/dist/emit/mcp/files.js +42 -0
- package/dist/emit/mcp/index.d.ts +3 -0
- package/dist/emit/mcp/index.js +3 -0
- package/dist/emit/mcp/literal.d.ts +2 -0
- package/dist/emit/mcp/literal.js +33 -0
- package/dist/emit/mcp/mounted.d.ts +21 -0
- package/dist/emit/mcp/mounted.js +89 -0
- package/dist/emit/mcp/output-schema.d.ts +18 -0
- package/dist/emit/mcp/output-schema.js +38 -0
- package/dist/emit/mcp/registry.d.ts +23 -0
- package/dist/emit/mcp/registry.js +83 -0
- package/dist/emit/mcp/runtime.d.ts +10 -0
- package/dist/emit/mcp/runtime.js +47 -0
- package/dist/emit/mcp/schema.d.ts +19 -0
- package/dist/emit/mcp/schema.js +88 -0
- package/dist/emit/mcp/server.d.ts +30 -0
- package/dist/emit/mcp/server.js +246 -0
- package/dist/emit/mcp/tools.d.ts +51 -0
- package/dist/emit/mcp/tools.js +153 -0
- package/dist/emit/python/errors.d.ts +8 -0
- package/dist/emit/python/errors.js +68 -0
- package/dist/emit/python/index.d.ts +1 -0
- package/dist/emit/python/index.js +1 -0
- package/dist/emit/python/realtime.d.ts +10 -0
- package/dist/emit/python/realtime.js +33 -0
- package/dist/emit/python/sdk-answer.d.ts +49 -0
- package/dist/emit/python/sdk-answer.js +89 -0
- package/dist/emit/python/sdk-body.d.ts +11 -0
- package/dist/emit/python/sdk-body.js +40 -0
- package/dist/emit/python/sdk-client.d.ts +36 -0
- package/dist/emit/python/sdk-client.js +163 -0
- package/dist/emit/python/sdk-doc.d.ts +9 -0
- package/dist/emit/python/sdk-doc.js +32 -0
- package/dist/emit/python/sdk-imports.d.ts +14 -0
- package/dist/emit/python/sdk-imports.js +38 -0
- package/dist/emit/python/sdk-method.d.ts +29 -0
- package/dist/emit/python/sdk-method.js +183 -0
- package/dist/emit/python/sdk-plan.d.ts +33 -0
- package/dist/emit/python/sdk-plan.js +1 -0
- package/dist/emit/python/sdk-pyproject.d.ts +27 -0
- package/dist/emit/python/sdk-pyproject.js +103 -0
- package/dist/emit/python/sdk.d.ts +22 -0
- package/dist/emit/python/sdk.js +154 -0
- package/dist/emit/python/sse.d.ts +12 -0
- package/dist/emit/python/sse.js +23 -0
- package/dist/emit/python/transport.d.ts +15 -0
- package/dist/emit/python/transport.js +60 -0
- package/dist/emit/python/types-dict.d.ts +31 -0
- package/dist/emit/python/types-dict.js +45 -0
- package/dist/emit/python/types-names.d.ts +16 -0
- package/dist/emit/python/types-names.js +52 -0
- package/dist/emit/python/types-union.d.ts +32 -0
- package/dist/emit/python/types-union.js +46 -0
- package/dist/emit/python/types.d.ts +36 -0
- package/dist/emit/python/types.js +128 -0
- package/dist/emit/python/ws.d.ts +14 -0
- package/dist/emit/python/ws.js +16 -0
- package/dist/emit/rust/errors.d.ts +7 -0
- package/dist/emit/rust/errors.js +107 -0
- package/dist/emit/rust/http.d.ts +13 -0
- package/dist/emit/rust/http.js +67 -0
- package/dist/emit/rust/index.d.ts +1 -0
- package/dist/emit/rust/index.js +1 -0
- package/dist/emit/rust/realtime.d.ts +11 -0
- package/dist/emit/rust/realtime.js +29 -0
- package/dist/emit/rust/sdk-body.d.ts +19 -0
- package/dist/emit/rust/sdk-body.js +53 -0
- package/dist/emit/rust/sdk-cargo.d.ts +43 -0
- package/dist/emit/rust/sdk-cargo.js +178 -0
- package/dist/emit/rust/sdk-client.d.ts +25 -0
- package/dist/emit/rust/sdk-client.js +108 -0
- package/dist/emit/rust/sdk-method.d.ts +15 -0
- package/dist/emit/rust/sdk-method.js +119 -0
- package/dist/emit/rust/sdk-opts.d.ts +58 -0
- package/dist/emit/rust/sdk-opts.js +117 -0
- package/dist/emit/rust/sdk-plan.d.ts +33 -0
- package/dist/emit/rust/sdk-plan.js +1 -0
- package/dist/emit/rust/sdk.d.ts +23 -0
- package/dist/emit/rust/sdk.js +111 -0
- package/dist/emit/rust/sse.d.ts +19 -0
- package/dist/emit/rust/sse.js +20 -0
- package/dist/emit/rust/types-enum.d.ts +13 -0
- package/dist/emit/rust/types-enum.js +62 -0
- package/dist/emit/rust/types-names.d.ts +19 -0
- package/dist/emit/rust/types-names.js +66 -0
- package/dist/emit/rust/types-struct.d.ts +21 -0
- package/dist/emit/rust/types-struct.js +59 -0
- package/dist/emit/rust/types-union.d.ts +24 -0
- package/dist/emit/rust/types-union.js +97 -0
- package/dist/emit/rust/types.d.ts +34 -0
- package/dist/emit/rust/types.js +105 -0
- package/dist/emit/rust/ws.d.ts +21 -0
- package/dist/emit/rust/ws.js +20 -0
- package/dist/emit/shared/escape.d.ts +55 -0
- package/dist/emit/shared/escape.js +144 -0
- package/dist/emit/shared/format.d.ts +24 -0
- package/dist/emit/shared/format.js +23 -0
- package/dist/emit/shared/gofmt.d.ts +3 -0
- package/dist/emit/shared/gofmt.js +26 -0
- package/dist/emit/shared/lang.d.ts +60 -0
- package/dist/emit/shared/lang.js +233 -0
- package/dist/emit/shared/literals.d.ts +4 -0
- package/dist/emit/shared/literals.js +31 -0
- package/dist/emit/shared/metadata.d.ts +106 -0
- package/dist/emit/shared/metadata.js +130 -0
- package/dist/emit/shared/mirror.d.ts +22 -0
- package/dist/emit/shared/mirror.js +26 -0
- package/dist/emit/shared/ruff.d.ts +3 -0
- package/dist/emit/shared/ruff.js +31 -0
- package/dist/emit/shared/rustfmt.d.ts +3 -0
- package/dist/emit/shared/rustfmt.js +32 -0
- package/dist/emit/shared/status-keys.d.ts +7 -0
- package/dist/emit/shared/status-keys.js +67 -0
- package/dist/emit/shared/type-emitter.d.ts +19 -0
- package/dist/emit/shared/type-emitter.js +100 -0
- package/dist/emit/ts/app-client.d.ts +4 -0
- package/dist/emit/ts/app-client.js +68 -0
- package/dist/emit/ts/http.d.ts +20 -0
- package/dist/emit/ts/http.js +74 -0
- package/dist/emit/ts/package.d.ts +36 -0
- package/dist/emit/ts/package.js +126 -0
- package/dist/emit/ts/route-tree.d.ts +68 -0
- package/dist/emit/ts/route-tree.js +240 -0
- package/dist/emit/ts/sdk-types-preamble.d.ts +14 -0
- package/dist/emit/ts/sdk-types-preamble.js +123 -0
- package/dist/emit/ts/sdk-types.d.ts +13 -0
- package/dist/emit/ts/sdk-types.js +213 -0
- package/dist/emit/ts/sdk.d.ts +21 -0
- package/dist/emit/ts/sdk.js +173 -0
- package/dist/emit/ts/service-map.d.ts +40 -0
- package/dist/emit/ts/service-map.js +171 -0
- package/dist/emit/ts/tanstack-query.d.ts +12 -0
- package/dist/emit/ts/tanstack-query.js +156 -0
- package/dist/emit/ts/type-gen.d.ts +26 -0
- package/dist/emit/ts/type-gen.js +255 -0
- package/dist/emit/ts/webhooks.d.ts +19 -0
- package/dist/emit/ts/webhooks.js +81 -0
- package/dist/extract/chain.d.ts +34 -0
- package/dist/extract/chain.js +84 -0
- package/dist/extract/extract.d.ts +41 -0
- package/dist/extract/extract.js +191 -0
- package/dist/extract/serialize.d.ts +34 -0
- package/dist/extract/serialize.js +295 -0
- package/dist/extract/walk.d.ts +47 -0
- package/dist/extract/walk.js +109 -0
- package/dist/gen/args.d.ts +28 -0
- package/dist/gen/args.js +133 -0
- package/dist/gen/formatters.d.ts +62 -0
- package/dist/gen/formatters.js +146 -0
- package/dist/gen/process.d.ts +13 -0
- package/dist/gen/process.js +35 -0
- package/dist/gen/shipped.d.ts +17 -0
- package/dist/gen/shipped.js +55 -0
- package/dist/gen/targets.d.ts +93 -0
- package/dist/gen/targets.js +171 -0
- package/dist/gen/write.d.ts +33 -0
- package/dist/gen/write.js +118 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +15 -0
- package/dist/ir/build.d.ts +37 -0
- package/dist/ir/build.js +152 -0
- package/dist/ir/load.d.ts +11 -0
- package/dist/ir/load.js +112 -0
- package/dist/ir/model.d.ts +206 -0
- package/dist/ir/model.js +5 -0
- package/dist/ir/resolve-refs.d.ts +11 -0
- package/dist/ir/resolve-refs.js +66 -0
- package/dist/ir/resource-tree.d.ts +9 -0
- package/dist/ir/resource-tree.js +53 -0
- package/dist/ir/route-tree-intern.d.ts +18 -0
- package/dist/ir/route-tree-intern.js +174 -0
- package/dist/ir/schema.d.ts +11 -0
- package/dist/ir/schema.js +192 -0
- package/dist/ir/sdk-model.d.ts +86 -0
- package/dist/ir/sdk-model.js +204 -0
- package/dist/ir/slots.d.ts +42 -0
- package/dist/ir/slots.js +245 -0
- package/dist/runtime/cli/body.go +176 -0
- package/dist/runtime/cli/config.go +243 -0
- package/dist/runtime/cli/discovery.go +147 -0
- package/dist/runtime/cli/format.go +174 -0
- package/dist/runtime/cli/log.go +117 -0
- package/dist/runtime/cli/output.go +247 -0
- package/dist/runtime/cli/params.go +197 -0
- package/dist/runtime/cli/run.go +226 -0
- package/dist/runtime/cli/socket.go +60 -0
- package/dist/runtime/cli/stream.go +217 -0
- package/dist/runtime/cli/target.go +117 -0
- package/dist/runtime/csharp/Adapters.cs +183 -0
- package/dist/runtime/csharp/Auth.cs +56 -0
- package/dist/runtime/csharp/Body.cs +135 -0
- package/dist/runtime/csharp/Config.cs +161 -0
- package/dist/runtime/csharp/Envelope.cs +149 -0
- package/dist/runtime/csharp/Errors.cs +194 -0
- package/dist/runtime/csharp/Events.cs +155 -0
- package/dist/runtime/csharp/Exchange.cs +247 -0
- package/dist/runtime/csharp/Handler.cs +103 -0
- package/dist/runtime/csharp/Hooks.cs +128 -0
- package/dist/runtime/csharp/Invalidation.cs +102 -0
- package/dist/runtime/csharp/Json.cs +144 -0
- package/dist/runtime/csharp/Log.cs +48 -0
- package/dist/runtime/csharp/Operation.cs +33 -0
- package/dist/runtime/csharp/Path.cs +65 -0
- package/dist/runtime/csharp/Query.cs +72 -0
- package/dist/runtime/csharp/Realtime.cs +118 -0
- package/dist/runtime/csharp/RealtimeLoop.cs +236 -0
- package/dist/runtime/csharp/Redirect.cs +53 -0
- package/dist/runtime/csharp/Result.cs +57 -0
- package/dist/runtime/csharp/Sse.cs +122 -0
- package/dist/runtime/csharp/Stale.cs +151 -0
- package/dist/runtime/csharp/Transport.cs +143 -0
- package/dist/runtime/csharp/TransportLongPoll.cs +63 -0
- package/dist/runtime/csharp/TransportSse.cs +54 -0
- package/dist/runtime/csharp/TransportWs.cs +40 -0
- package/dist/runtime/csharp/Wire.cs +109 -0
- package/dist/runtime/csharp/Ws.cs +300 -0
- package/dist/runtime/csharp/WsDial.cs +127 -0
- package/dist/runtime/go/auth.go +127 -0
- package/dist/runtime/go/body.go +129 -0
- package/dist/runtime/go/config.go +75 -0
- package/dist/runtime/go/errors.go +185 -0
- package/dist/runtime/go/export.go +37 -0
- package/dist/runtime/go/hooks.go +53 -0
- package/dist/runtime/go/invalidation.go +112 -0
- package/dist/runtime/go/log.go +92 -0
- package/dist/runtime/go/nullable.go +64 -0
- package/dist/runtime/go/options.go +118 -0
- package/dist/runtime/go/path.go +156 -0
- package/dist/runtime/go/query.go +147 -0
- package/dist/runtime/go/realtime.go +239 -0
- package/dist/runtime/go/realtime_loop.go +208 -0
- package/dist/runtime/go/redirect.go +124 -0
- package/dist/runtime/go/request.go +222 -0
- package/dist/runtime/go/result.go +86 -0
- package/dist/runtime/go/sse.go +186 -0
- package/dist/runtime/go/stale.go +229 -0
- package/dist/runtime/go/stream.go +105 -0
- package/dist/runtime/go/transport.go +242 -0
- package/dist/runtime/go/transport_longpoll.go +121 -0
- package/dist/runtime/go/transport_sse.go +175 -0
- package/dist/runtime/go/ws.go +205 -0
- package/dist/runtime/java/Answer.java +107 -0
- package/dist/runtime/java/ApiException.java +110 -0
- package/dist/runtime/java/BinaryBody.java +36 -0
- package/dist/runtime/java/Body.java +105 -0
- package/dist/runtime/java/Call.java +23 -0
- package/dist/runtime/java/CallLog.java +51 -0
- package/dist/runtime/java/ClientConfig.java +233 -0
- package/dist/runtime/java/ConnectionState.java +12 -0
- package/dist/runtime/java/Credential.java +58 -0
- package/dist/runtime/java/Deadline.java +38 -0
- package/dist/runtime/java/Decode.java +181 -0
- package/dist/runtime/java/Envelope.java +141 -0
- package/dist/runtime/java/ErrorEnvelope.java +23 -0
- package/dist/runtime/java/EventStream.java +129 -0
- package/dist/runtime/java/Exchange.java +62 -0
- package/dist/runtime/java/FilePart.java +5 -0
- package/dist/runtime/java/Flight.java +306 -0
- package/dist/runtime/java/HoneyException.java +14 -0
- package/dist/runtime/java/Hooks.java +47 -0
- package/dist/runtime/java/Hops.java +133 -0
- package/dist/runtime/java/InvalidationConfig.java +73 -0
- package/dist/runtime/java/Json.java +23 -0
- package/dist/runtime/java/Keepalive.java +60 -0
- package/dist/runtime/java/LogEntry.java +14 -0
- package/dist/runtime/java/LongPollAdapter.java +68 -0
- package/dist/runtime/java/Operation.java +21 -0
- package/dist/runtime/java/Opt.java +121 -0
- package/dist/runtime/java/Pump.java +160 -0
- package/dist/runtime/java/RawResponse.java +48 -0
- package/dist/runtime/java/Realtime.java +152 -0
- package/dist/runtime/java/RealtimeLoop.java +371 -0
- package/dist/runtime/java/RedirectPolicy.java +13 -0
- package/dist/runtime/java/Redirects.java +126 -0
- package/dist/runtime/java/RequestContext.java +78 -0
- package/dist/runtime/java/RequestHook.java +9 -0
- package/dist/runtime/java/RequestOptions.java +91 -0
- package/dist/runtime/java/ResponseContext.java +70 -0
- package/dist/runtime/java/ResponseHook.java +12 -0
- package/dist/runtime/java/Result.java +32 -0
- package/dist/runtime/java/ResumableConnection.java +165 -0
- package/dist/runtime/java/SdkException.java +11 -0
- package/dist/runtime/java/Socket.java +301 -0
- package/dist/runtime/java/Sse.java +171 -0
- package/dist/runtime/java/SseAdapter.java +61 -0
- package/dist/runtime/java/SseEvent.java +10 -0
- package/dist/runtime/java/StaleMeta.java +16 -0
- package/dist/runtime/java/StaleTracker.java +287 -0
- package/dist/runtime/java/Transport.java +16 -0
- package/dist/runtime/java/TransportAdapter.java +14 -0
- package/dist/runtime/java/TransportConnection.java +15 -0
- package/dist/runtime/java/TransportKind.java +12 -0
- package/dist/runtime/java/TransportMessage.java +9 -0
- package/dist/runtime/java/TransportOptions.java +138 -0
- package/dist/runtime/java/TypedWebSocket.java +83 -0
- package/dist/runtime/java/UrlPath.java +49 -0
- package/dist/runtime/java/UrlQuery.java +99 -0
- package/dist/runtime/java/WsAdapter.java +52 -0
- package/dist/runtime/java/WsClose.java +47 -0
- package/dist/runtime/java/WsDial.java +148 -0
- package/dist/runtime/java/WsMessage.java +18 -0
- package/dist/runtime/mcp/call.ts +167 -0
- package/dist/runtime/mcp/files.ts +183 -0
- package/dist/runtime/mcp/guard.ts +176 -0
- package/dist/runtime/mcp/http.ts +159 -0
- package/dist/runtime/mcp/jsonrpc.ts +50 -0
- package/dist/runtime/mcp/listen.ts +76 -0
- package/dist/runtime/mcp/mount.ts +123 -0
- package/dist/runtime/mcp/protocol.ts +219 -0
- package/dist/runtime/mcp/reader.ts +57 -0
- package/dist/runtime/mcp/result.ts +85 -0
- package/dist/runtime/mcp/stdio.ts +79 -0
- package/dist/runtime/mcp/stream.ts +62 -0
- package/dist/runtime/python/__init__.py +2 -0
- package/dist/runtime/python/auth.py +67 -0
- package/dist/runtime/python/body.py +83 -0
- package/dist/runtime/python/config.py +139 -0
- package/dist/runtime/python/errors.py +213 -0
- package/dist/runtime/python/events.py +152 -0
- package/dist/runtime/python/exchange.py +298 -0
- package/dist/runtime/python/hooks.py +86 -0
- package/dist/runtime/python/invalidation.py +57 -0
- package/dist/runtime/python/log.py +60 -0
- package/dist/runtime/python/operation.py +25 -0
- package/dist/runtime/python/path.py +41 -0
- package/dist/runtime/python/query.py +48 -0
- package/dist/runtime/python/realtime.py +244 -0
- package/dist/runtime/python/redirect.py +93 -0
- package/dist/runtime/python/result.py +58 -0
- package/dist/runtime/python/send_async.py +189 -0
- package/dist/runtime/python/send_sync.py +105 -0
- package/dist/runtime/python/sse.py +81 -0
- package/dist/runtime/python/stale.py +94 -0
- package/dist/runtime/python/transport.py +157 -0
- package/dist/runtime/python/transport_longpoll.py +60 -0
- package/dist/runtime/python/transport_sse.py +60 -0
- package/dist/runtime/python/transport_ws.py +57 -0
- package/dist/runtime/python/ws.py +276 -0
- package/dist/runtime/rust/Cargo.lock +1763 -0
- package/dist/runtime/rust/answer.rs +120 -0
- package/dist/runtime/rust/auth.rs +80 -0
- package/dist/runtime/rust/body.rs +150 -0
- package/dist/runtime/rust/call.rs +200 -0
- package/dist/runtime/rust/config.rs +254 -0
- package/dist/runtime/rust/envelope.rs +84 -0
- package/dist/runtime/rust/errors.rs +235 -0
- package/dist/runtime/rust/events.rs +177 -0
- package/dist/runtime/rust/exchange.rs +287 -0
- package/dist/runtime/rust/hooks.rs +63 -0
- package/dist/runtime/rust/invalidation.rs +84 -0
- package/dist/runtime/rust/log.rs +88 -0
- package/dist/runtime/rust/nullable.rs +13 -0
- package/dist/runtime/rust/path.rs +83 -0
- package/dist/runtime/rust/query.rs +84 -0
- package/dist/runtime/rust/realtime.rs +182 -0
- package/dist/runtime/rust/realtime_loop.rs +177 -0
- package/dist/runtime/rust/redirect.rs +121 -0
- package/dist/runtime/rust/request.rs +178 -0
- package/dist/runtime/rust/result.rs +101 -0
- package/dist/runtime/rust/sse.rs +104 -0
- package/dist/runtime/rust/stale.rs +209 -0
- package/dist/runtime/rust/transport.rs +221 -0
- package/dist/runtime/rust/transport_longpoll.rs +108 -0
- package/dist/runtime/rust/transport_sse.rs +91 -0
- package/dist/runtime/rust/transport_ws.rs +75 -0
- package/dist/runtime/rust/ws.rs +322 -0
- package/dist/runtime/ts/app-types.ts +200 -0
- package/dist/runtime/ts/app.ts +104 -0
- package/dist/runtime/ts/config.ts +124 -0
- package/dist/runtime/ts/defaults.ts +48 -0
- package/dist/runtime/ts/error.ts +113 -0
- package/dist/runtime/ts/hooks.ts +92 -0
- package/dist/runtime/ts/http.ts +228 -0
- package/dist/runtime/ts/media-type.ts +36 -0
- package/dist/runtime/ts/path.ts +152 -0
- package/dist/runtime/ts/realtime-connection.ts +296 -0
- package/dist/runtime/ts/realtime-transports.ts +149 -0
- package/dist/runtime/ts/realtime.ts +293 -0
- package/dist/runtime/ts/redirect-policy.ts +17 -0
- package/dist/runtime/ts/redirects.ts +74 -0
- package/dist/runtime/ts/request.ts +239 -0
- package/dist/runtime/ts/response.ts +219 -0
- package/dist/runtime/ts/sdk-realtime.ts +10 -0
- package/dist/runtime/ts/sdk-sse.ts +55 -0
- package/dist/runtime/ts/sdk-ws.ts +21 -0
- package/dist/runtime/ts/sdk.ts +242 -0
- package/dist/runtime/ts/sse.ts +175 -0
- package/dist/runtime/ts/stale.ts +137 -0
- package/dist/runtime/ts/stream.ts +87 -0
- package/dist/runtime/ts/webhook.ts +116 -0
- package/dist/runtime/ts/ws.ts +155 -0
- package/dist/runtime/ts-tanstack-query/invalidate.ts +152 -0
- package/dist/runtime/ts-tanstack-query/query.ts +261 -0
- package/package.json +135 -5
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { methodsOf, namespacesOf } from "../../ir/resource-tree.js";
|
|
2
|
+
import { javaString } from "../shared/escape.js";
|
|
3
|
+
import { javaIdentifier, javaTypeName, NameScope } from "../shared/lang.js";
|
|
4
|
+
import { MIRROR, mirrorNotice } from "../shared/mirror.js";
|
|
5
|
+
import { accessor, assign, call, classHeader, exprStmt, finalField, methodHeader, newOf, returnStmt, statement, } from "./layout.js";
|
|
6
|
+
import { docOf } from "./sdk-decl.js";
|
|
7
|
+
import { putFile, sourceOf } from "./sdk-models.js";
|
|
8
|
+
import { javaOp } from "./sdk-op.js";
|
|
9
|
+
/** The names a class inherits from Object or the builder, which an accessor or an operation may not take. */
|
|
10
|
+
const RESERVED = [
|
|
11
|
+
"builder",
|
|
12
|
+
"clone",
|
|
13
|
+
"equals",
|
|
14
|
+
"finalize",
|
|
15
|
+
"getClass",
|
|
16
|
+
"hashCode",
|
|
17
|
+
"notify",
|
|
18
|
+
"notifyAll",
|
|
19
|
+
"toString",
|
|
20
|
+
"wait",
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* The resource class of `path`: its words in PascalCase, then `Resource`, claimed from the model scope after the
|
|
24
|
+
* components (C#'s order), so a component spelled the same keeps its name and this one is `…2`; one path, one name.
|
|
25
|
+
*/
|
|
26
|
+
export const resourceName = (path, ctx) => ctx.names.hoist(`resource:${JSON.stringify(path)}`, `${javaTypeName(path.join("."))}Resource`);
|
|
27
|
+
export function nodeOf(ns, path) {
|
|
28
|
+
return {
|
|
29
|
+
children: namespacesOf(ns).map(([segment, child]) => ({ node: nodeOf(child, [...path, segment]), segment })),
|
|
30
|
+
methods: methodsOf(ns).map(([segment, op]) => ({ op, segment })),
|
|
31
|
+
path,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A node's members, claimed in one scope: each child's accessor name, each operation's method name. At the root the
|
|
36
|
+
* mirror's `safe` is held, so a member spelled `safe` is `safe_` instead, and noticed (shared/mirror.ts's one rule).
|
|
37
|
+
*/
|
|
38
|
+
export function membersOf(node, env) {
|
|
39
|
+
const root = node.path.length === 0;
|
|
40
|
+
const scope = new NameScope(root ? [...RESERVED, MIRROR] : RESERVED);
|
|
41
|
+
const claim = (segment) => {
|
|
42
|
+
const name = javaIdentifier(segment);
|
|
43
|
+
if (!root || name !== MIRROR)
|
|
44
|
+
return scope.claim(name);
|
|
45
|
+
const renamed = scope.claim(`${MIRROR}_`);
|
|
46
|
+
env.notices.push(mirrorNotice("java", MIRROR, name, renamed));
|
|
47
|
+
return renamed;
|
|
48
|
+
};
|
|
49
|
+
const children = node.children.map(({ node: child, segment }) => ({ child, name: claim(segment) }));
|
|
50
|
+
const ops = node.methods.map(({ op, segment }) => {
|
|
51
|
+
const name = claim(segment);
|
|
52
|
+
return { name, op: javaOp(env.ops.get(op.id), name, env) };
|
|
53
|
+
});
|
|
54
|
+
return { children, ops };
|
|
55
|
+
}
|
|
56
|
+
/** A list of blocks, each set apart by one blank line; a block's own trailing blank lines are dropped. */
|
|
57
|
+
export const blocks = (parts) => parts
|
|
58
|
+
.map(trimmed)
|
|
59
|
+
.filter((part) => part.length > 0)
|
|
60
|
+
.flatMap((part, i) => (i === 0 ? part : ["", ...part]));
|
|
61
|
+
/** The lines without their leading and trailing blank lines. */
|
|
62
|
+
function trimmed(lines) {
|
|
63
|
+
const text = lines.join("\n").replace(/^(?:\n)+|(?:\n)+$/g, "");
|
|
64
|
+
return text === "" ? [] : text.split("\n");
|
|
65
|
+
}
|
|
66
|
+
/** The operations' constants and methods of a class, each block set apart. */
|
|
67
|
+
const opBlocks = (ops) => ops.map(({ op }) => [...op.lines, ...op.helper]);
|
|
68
|
+
/** A child node's resource class name, by its path: the name its own file declares. */
|
|
69
|
+
const own = (child, env) => resourceName(child.path, env.ctx);
|
|
70
|
+
/** `this.name = new Type(args);` in a constructor. */
|
|
71
|
+
const constructed = (name, type, args) => statement(4, exprStmt(assign(`this.${name}`, newOf(type, args))));
|
|
72
|
+
/** A resource class's text: its constants, its exchange and child fields, its constructor, accessors and methods. */
|
|
73
|
+
function resourceLines(node, env) {
|
|
74
|
+
const { children, ops } = membersOf(node, env);
|
|
75
|
+
const constants = ops.map(({ op }) => op.constantLines);
|
|
76
|
+
return blocks([
|
|
77
|
+
[docOf(`The ${node.path.join(".")} operations.`, ""), ...classHeader(resourceName(node.path, env.ctx))],
|
|
78
|
+
constants.flat(),
|
|
79
|
+
[" private final Exchange exchange;", ...children.flatMap(({ child, name }) => finalField(own(child, env), name))],
|
|
80
|
+
[
|
|
81
|
+
...methodHeader(2, {
|
|
82
|
+
name: resourceName(node.path, env.ctx),
|
|
83
|
+
params: [{ name: "exchange", type: "Exchange" }],
|
|
84
|
+
}),
|
|
85
|
+
" this.exchange = exchange;",
|
|
86
|
+
...children.flatMap(({ child, name }) => constructed(name, own(child, env), ["exchange"])),
|
|
87
|
+
" }",
|
|
88
|
+
],
|
|
89
|
+
...children.map(({ child, name }) => accessor(own(child, env), name)),
|
|
90
|
+
...opBlocks(ops),
|
|
91
|
+
]).concat("}");
|
|
92
|
+
}
|
|
93
|
+
/** One builder setter: its doc, its signature, and the config call it makes. */
|
|
94
|
+
const setter = (name, type, method) => [
|
|
95
|
+
` /** Sets the ${name}. */`,
|
|
96
|
+
` public Builder ${name}(${type} ${name}) {`,
|
|
97
|
+
` config.${method}(${name});`,
|
|
98
|
+
" return this;",
|
|
99
|
+
" }",
|
|
100
|
+
];
|
|
101
|
+
/** The builder's setters, by name, type and the config call each makes. */
|
|
102
|
+
const SETTERS = [
|
|
103
|
+
["baseUrl", "String"],
|
|
104
|
+
["bearerToken", "String"],
|
|
105
|
+
["apiKey", "String"],
|
|
106
|
+
["authHeaderName", "String"],
|
|
107
|
+
["authHeaderPrefix", "String"],
|
|
108
|
+
["headers", "Map<String, String>"],
|
|
109
|
+
["timeout", "Duration"],
|
|
110
|
+
["onRequest", "RequestHook"],
|
|
111
|
+
["onResponse", "ResponseHook"],
|
|
112
|
+
["onAuthExpired", "Supplier<String>"],
|
|
113
|
+
["onLog", "Consumer<LogEntry>"],
|
|
114
|
+
["redirect", "RedirectPolicy"],
|
|
115
|
+
["maxResponseBytes", "long"],
|
|
116
|
+
["invalidation", "InvalidationConfig"],
|
|
117
|
+
];
|
|
118
|
+
/** The client: its constructor, its root resources, its safe mirror, its ungrouped operations, and its builder. */
|
|
119
|
+
export function clientLines(ir, root, env, mirror) {
|
|
120
|
+
const { children, ops } = membersOf(root, env);
|
|
121
|
+
const server = ir.servers[0];
|
|
122
|
+
const defaults = [
|
|
123
|
+
server === undefined ? "null" : javaString(server),
|
|
124
|
+
javaString(ir.auth.headerName),
|
|
125
|
+
javaString(ir.auth.prefix),
|
|
126
|
+
];
|
|
127
|
+
return blocks([
|
|
128
|
+
[docOf("The client for the API. Build one with {@link #builder()}.", ""), ...classHeader(env.client)],
|
|
129
|
+
[
|
|
130
|
+
" private final Exchange exchange;",
|
|
131
|
+
...children.flatMap(({ child, name }) => finalField(own(child, env), name)),
|
|
132
|
+
...finalField(mirror, "safe"),
|
|
133
|
+
],
|
|
134
|
+
ops.flatMap(({ op }) => op.constantLines),
|
|
135
|
+
[
|
|
136
|
+
...methodHeader(2, {
|
|
137
|
+
modifiers: ["private"],
|
|
138
|
+
name: env.client,
|
|
139
|
+
params: [{ name: "config", type: "ClientConfig" }],
|
|
140
|
+
}),
|
|
141
|
+
" this.exchange = new Exchange(config);",
|
|
142
|
+
...children.flatMap(({ child, name }) => constructed(name, own(child, env), ["exchange"])),
|
|
143
|
+
...constructed("safe", mirror, ["this"]),
|
|
144
|
+
" }",
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
" /** A builder for a client; the base URL is required unless the API declares a server. */",
|
|
148
|
+
" public static Builder builder() {",
|
|
149
|
+
" return new Builder();",
|
|
150
|
+
" }",
|
|
151
|
+
],
|
|
152
|
+
...children.map(({ child, name }) => accessor(own(child, env), name)),
|
|
153
|
+
[
|
|
154
|
+
" /** The safe mirror: the same calls, each answering a {@link Result}; no answer still throws. */",
|
|
155
|
+
...accessor(mirror, "safe"),
|
|
156
|
+
],
|
|
157
|
+
...opBlocks(ops),
|
|
158
|
+
[
|
|
159
|
+
` /** Builds an {@link ${env.client}}. */`,
|
|
160
|
+
" public static final class Builder {",
|
|
161
|
+
" private final ClientConfig.Builder config;",
|
|
162
|
+
"",
|
|
163
|
+
" private Builder() {",
|
|
164
|
+
...statement(6, exprStmt(assign("this.config", call("ClientConfig", "builder", defaults)))),
|
|
165
|
+
" }",
|
|
166
|
+
"",
|
|
167
|
+
...SETTERS.flatMap(([name, type]) => [...setter(name, type, name), ""]),
|
|
168
|
+
` /** Builds the client. */`,
|
|
169
|
+
...methodHeader(4, { modifiers: ["public"], name: "build", params: [], returns: env.client }),
|
|
170
|
+
...statement(6, returnStmt(newOf(env.client, [call("config", "build")]))),
|
|
171
|
+
" }",
|
|
172
|
+
" }",
|
|
173
|
+
],
|
|
174
|
+
]).concat("}");
|
|
175
|
+
}
|
|
176
|
+
/** The root's operations' plans, and their record files, reached through `accessors`, depth first. */
|
|
177
|
+
function visit(node, accessors, env, out) {
|
|
178
|
+
const { children, ops } = membersOf(node, env);
|
|
179
|
+
for (const { name, op } of ops) {
|
|
180
|
+
out.plans.push({ ...op.plan, accessors, method: name });
|
|
181
|
+
putFile(out.files, `${op.plan.params}.java`, recordSource(op.params, env));
|
|
182
|
+
if (op.headers !== null)
|
|
183
|
+
putFile(out.files, `${op.headers.type}.java`, recordSource(op.headers.lines, env));
|
|
184
|
+
if (op.body !== null)
|
|
185
|
+
putFile(out.files, `${op.body.name}.java`, recordSource(op.body.lines, env));
|
|
186
|
+
}
|
|
187
|
+
for (const { child, name } of children)
|
|
188
|
+
visit(child, [...accessors, name], env, out);
|
|
189
|
+
}
|
|
190
|
+
/** A file's text: the marker, the package, the imports its code spells, then its lines. */
|
|
191
|
+
export function recordSource(lines, env) {
|
|
192
|
+
return sourceOf(env.marker, env.packageName, trimmed(lines).join("\n"));
|
|
193
|
+
}
|
|
194
|
+
/** Every resource and record file of the call surface, and every operation's call plan, for `ir`. */
|
|
195
|
+
export function surfaceOf(ir, env) {
|
|
196
|
+
const root = nodeOf(ir.tree, []);
|
|
197
|
+
const out = { files: {}, plans: [] };
|
|
198
|
+
visit(root, [], env, out);
|
|
199
|
+
const walk = (node) => {
|
|
200
|
+
if (node.path.length > 0)
|
|
201
|
+
putFile(out.files, `${resourceName(node.path, env.ctx)}.java`, recordSource(resourceLines(node, env), env));
|
|
202
|
+
for (const child of node.children)
|
|
203
|
+
walk(child.node);
|
|
204
|
+
};
|
|
205
|
+
walk(root);
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `/** … *\/` doc comment at `indent`, its text made safe (docText): one line when it fits in 100 columns, else
|
|
3
|
+
* google-java-format's filled lines, each word on the first line it fits, after ` * `.
|
|
4
|
+
*/
|
|
5
|
+
export declare function docOf(raw: string, indent?: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* A doc comment of several paragraphs, as google-java-format writes one: the first as it is, each later one after a
|
|
8
|
+
* blank ` *` line and opened by `<p>`, every paragraph's text made safe (docText) and filled to 100 columns. One
|
|
9
|
+
* paragraph is docOf.
|
|
10
|
+
*/
|
|
11
|
+
export declare function docParagraphs(raws: readonly string[], indent?: string): string;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Java doc comments (bit 16 phase c1): spec text made safe and filled as google-java-format fills a javadoc. Code is
|
|
3
|
+
* laid out by layout.ts (bit 21 i7a), which took over this file's list and assignment rules.
|
|
4
|
+
*/
|
|
5
|
+
import { invisible } from "../shared/escape.js";
|
|
6
|
+
/** The longest line google-java-format keeps. */
|
|
7
|
+
const WIDTH = 100;
|
|
8
|
+
/** Whether `cp` is a control, DEL, C1, the BOM, a line or paragraph separator or a bidi control: never raw in a doc. */
|
|
9
|
+
const control = (cp) => cp < 0x20 || cp === 0x7f || cp === 0xfeff || cp === 0x2028 || cp === 0x2029 || invisible(cp);
|
|
10
|
+
/**
|
|
11
|
+
* Spec text as a doc comment holds it: each control a space; every backslash `\`, so none begins a `\u` escape,
|
|
12
|
+
* which javac reads before it lexes, comments included (JLS 3.3); and `*\/` as `*/`, so the comment never ends
|
|
13
|
+
* early. Javadoc renders both entities as the characters they stand for.
|
|
14
|
+
*/
|
|
15
|
+
const docText = (text) => [...text.toWellFormed()]
|
|
16
|
+
.map((ch) => (control(ch.codePointAt(0)) ? " " : ch))
|
|
17
|
+
.join("")
|
|
18
|
+
.replace(/\\/g, "\")
|
|
19
|
+
.replace(/\*\//g, "*/");
|
|
20
|
+
/**
|
|
21
|
+
* A `/** … *\/` doc comment at `indent`, its text made safe (docText): one line when it fits in 100 columns, else
|
|
22
|
+
* google-java-format's filled lines, each word on the first line it fits, after ` * `.
|
|
23
|
+
*/
|
|
24
|
+
export function docOf(raw, indent = " ") {
|
|
25
|
+
const text = docText(raw);
|
|
26
|
+
const one = `${indent}/** ${text} */`;
|
|
27
|
+
if (one.length <= WIDTH)
|
|
28
|
+
return one;
|
|
29
|
+
return docBlock([filled(text, WIDTH - indent.length - " * ".length)], indent);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A doc comment of several paragraphs, as google-java-format writes one: the first as it is, each later one after a
|
|
33
|
+
* blank ` *` line and opened by `<p>`, every paragraph's text made safe (docText) and filled to 100 columns. One
|
|
34
|
+
* paragraph is docOf.
|
|
35
|
+
*/
|
|
36
|
+
export function docParagraphs(raws, indent = " ") {
|
|
37
|
+
if (raws.length === 1)
|
|
38
|
+
return docOf(raws[0], indent);
|
|
39
|
+
const available = WIDTH - indent.length - " * ".length;
|
|
40
|
+
return docBlock(raws.map((raw, i) => filled(i === 0 ? docText(raw) : `<p>${docText(raw)}`, available)), indent);
|
|
41
|
+
}
|
|
42
|
+
/** The words of `text` filled into lines of at most `available` columns, each word on the first line it fits. */
|
|
43
|
+
function filled(text, available) {
|
|
44
|
+
const lines = [];
|
|
45
|
+
let line = "";
|
|
46
|
+
for (const word of text.split(/\s+/).filter((w) => w !== "")) {
|
|
47
|
+
if (line !== "" && line.length + 1 + word.length > available) {
|
|
48
|
+
lines.push(line);
|
|
49
|
+
line = word;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
line = line === "" ? word : `${line} ${word}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
lines.push(line);
|
|
56
|
+
return lines;
|
|
57
|
+
}
|
|
58
|
+
/** A `/** … *\/` block at `indent` of `paragraphs` (each its lines), a blank ` *` line between two. */
|
|
59
|
+
function docBlock(paragraphs, indent) {
|
|
60
|
+
const lines = paragraphs.flatMap((paragraph, i) => [...(i === 0 ? [] : [""]), ...paragraph]);
|
|
61
|
+
const body = lines.map((line) => (line === "" ? `${indent} *` : `${indent} * ${line}`));
|
|
62
|
+
return [`${indent}/**`, ...body, `${indent} */`].join("\n");
|
|
63
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type SdkModel } from "../../ir/sdk-model.ts";
|
|
2
|
+
import type { JavaTypeContext } from "./models.ts";
|
|
3
|
+
/** Every error class's file, by path, under `dir` in `packageName`, each behind `marker`. */
|
|
4
|
+
export declare function errorClassFiles(dir: string, packageName: string, marker: string): Record<string, string>;
|
|
5
|
+
/**
|
|
6
|
+
* The `ErrorKey` file for `model`, every `<Key>Data` hoisted into `ctx.decls`; an empty map when no key is declared.
|
|
7
|
+
* Each constant is the key's PascalCase name, numbered on a collision, its value the key as the server spells it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function errorKeyFiles(model: SdkModel, ctx: JavaTypeContext, target: {
|
|
10
|
+
readonly dir: string;
|
|
11
|
+
readonly packageName: string;
|
|
12
|
+
readonly marker: string;
|
|
13
|
+
}): Record<string, string>;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { irErrorEnvelope, isJsonMedia } from "../../ir/sdk-model.js";
|
|
2
|
+
import { javaString } from "../shared/escape.js";
|
|
3
|
+
import { compareCodeUnits, javaTypeName, NameScope } from "../shared/lang.js";
|
|
4
|
+
import { declares, javaTopLevel } from "./models.js";
|
|
5
|
+
import { docOf } from "./sdk-decl.js";
|
|
6
|
+
import { sourceOf } from "./sdk-models.js";
|
|
7
|
+
/** The classes one per common status, their statuses in ascending order. */
|
|
8
|
+
const STATUSES = [
|
|
9
|
+
[400, "BadRequestException"],
|
|
10
|
+
[401, "UnauthorizedException"],
|
|
11
|
+
[403, "ForbiddenException"],
|
|
12
|
+
[404, "NotFoundException"],
|
|
13
|
+
[409, "ConflictException"],
|
|
14
|
+
[422, "UnprocessableEntityException"],
|
|
15
|
+
[429, "RateLimitException"],
|
|
16
|
+
[500, "InternalServerException"],
|
|
17
|
+
[502, "BadGatewayException"],
|
|
18
|
+
[503, "ServiceUnavailableException"],
|
|
19
|
+
[504, "GatewayTimeoutException"],
|
|
20
|
+
];
|
|
21
|
+
/** The non-status errors: their base class, and their constructor's parameters after the message. */
|
|
22
|
+
const OTHER = [
|
|
23
|
+
{ base: "HoneyException", cause: true, doc: "The call ran past its timeout.", name: "ApiTimeoutException" },
|
|
24
|
+
{
|
|
25
|
+
base: "HoneyException",
|
|
26
|
+
cause: true,
|
|
27
|
+
doc: "No answer: the connection failed or broke.",
|
|
28
|
+
name: "ApiConnectionException",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
base: "HoneyException",
|
|
32
|
+
cause: false,
|
|
33
|
+
doc: "A path param that is empty, `.` or `..`: nothing is sent.",
|
|
34
|
+
name: "PathParamException",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
base: "HoneyException",
|
|
38
|
+
cause: false,
|
|
39
|
+
doc: "A client or call configured in a way it cannot send.",
|
|
40
|
+
name: "ConfigException",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
base: "SdkException",
|
|
44
|
+
cause: true,
|
|
45
|
+
doc: "An answer that does not decode as the declared type, or a 2xx past maxResponseBytes.",
|
|
46
|
+
name: "DecodeException",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
base: "HoneyException",
|
|
50
|
+
cause: true,
|
|
51
|
+
doc: "A hook or the auth refresh threw; its error is the cause.",
|
|
52
|
+
name: "HookException",
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
function classLines({ name, doc, base, cause, param }) {
|
|
56
|
+
const message = cause ? "message, cause" : "message, null";
|
|
57
|
+
const args = param === "failure" ? "failure" : message;
|
|
58
|
+
return [
|
|
59
|
+
docOf(doc, ""),
|
|
60
|
+
`public final class ${name} extends ${base} {`,
|
|
61
|
+
" private static final long serialVersionUID = 1L;",
|
|
62
|
+
"",
|
|
63
|
+
` ${name}(${param === "failure" ? "Failure failure" : "String message" + (cause ? ", Throwable cause" : "")}) {`,
|
|
64
|
+
` super(${args});`,
|
|
65
|
+
" }",
|
|
66
|
+
"}",
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
/** Every error class's file, by path, under `dir` in `packageName`, each behind `marker`. */
|
|
70
|
+
export function errorClassFiles(dir, packageName, marker) {
|
|
71
|
+
const statuses = STATUSES.map(([status, name]) => [
|
|
72
|
+
name,
|
|
73
|
+
classLines({ base: "ApiException", cause: false, doc: `HTTP ${status}.`, name, param: "failure" }),
|
|
74
|
+
]);
|
|
75
|
+
const unexpected = classLines({
|
|
76
|
+
base: "ApiException",
|
|
77
|
+
cause: false,
|
|
78
|
+
doc: "Any other status outside 2xx, a redirect the call did not follow included.",
|
|
79
|
+
name: "UnexpectedStatusException",
|
|
80
|
+
param: "failure",
|
|
81
|
+
});
|
|
82
|
+
const others = OTHER.map(({ name, base, cause, doc }) => [name, classLines({ base, cause, doc, name, param: "message" })]);
|
|
83
|
+
return Object.fromEntries([...statuses, ["UnexpectedStatusException", unexpected], ...others].map(([name, lines]) => [
|
|
84
|
+
`${dir}/${name}.java`,
|
|
85
|
+
sourceOf(marker, packageName, lines.join("\n")),
|
|
86
|
+
]));
|
|
87
|
+
}
|
|
88
|
+
/** Every key an error response's envelope names, over each operation's JSON error statuses. */
|
|
89
|
+
function envelopeKeys(model) {
|
|
90
|
+
return model.ops.flatMap((op) => op.errorStatuses.flatMap((status) => {
|
|
91
|
+
const { contentType, schema } = op.ir.responses[String(status)];
|
|
92
|
+
if (schema === undefined || !isJsonMedia(contentType))
|
|
93
|
+
return [];
|
|
94
|
+
return irErrorEnvelope(schema, model.resolve)?.keys ?? [];
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
/** Every declared key in code-unit order, its schema if an operation gives one (the first spelling wins). */
|
|
98
|
+
function declaredKeys(model) {
|
|
99
|
+
const byId = [...model.ops].sort((a, b) => compareCodeUnits(a.id, b.id));
|
|
100
|
+
const declared = byId.flatMap((op) => Object.entries(op.ir.extensions.errors ?? {}));
|
|
101
|
+
const keys = new Map([
|
|
102
|
+
...envelopeKeys(model).map((key) => [key, undefined]),
|
|
103
|
+
...declared.toReversed().map(([key, { schema }]) => [key, schema]),
|
|
104
|
+
]);
|
|
105
|
+
return [...keys].sort(([a], [b]) => compareCodeUnits(a, b));
|
|
106
|
+
}
|
|
107
|
+
/** The `<Key>Data` record for a key's inline schema, declared into `ctx.decls`; undefined when the key has none to name. */
|
|
108
|
+
function dataType(key, schema, model, ctx) {
|
|
109
|
+
if (schema === undefined || schema.kind === "ref")
|
|
110
|
+
return undefined;
|
|
111
|
+
if (!declares(schema) || irErrorEnvelope(schema, model.resolve) !== null)
|
|
112
|
+
return undefined;
|
|
113
|
+
const name = ctx.names.hoist(`error:${key}`, `${javaTypeName(key)}Data`);
|
|
114
|
+
ctx.decls.set(name, "");
|
|
115
|
+
ctx.decls.set(name, javaTopLevel(name, schema, ctx));
|
|
116
|
+
return name;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The `ErrorKey` file for `model`, every `<Key>Data` hoisted into `ctx.decls`; an empty map when no key is declared.
|
|
120
|
+
* Each constant is the key's PascalCase name, numbered on a collision, its value the key as the server spells it.
|
|
121
|
+
*/
|
|
122
|
+
export function errorKeyFiles(model, ctx, target) {
|
|
123
|
+
const { dir, packageName, marker } = target;
|
|
124
|
+
const declared = declaredKeys(model);
|
|
125
|
+
if (declared.length === 0)
|
|
126
|
+
return {};
|
|
127
|
+
const members = new NameScope([]);
|
|
128
|
+
const constants = declared.map(([wire, schema]) => {
|
|
129
|
+
dataType(wire, schema, model, ctx);
|
|
130
|
+
return { member: members.claim(javaTypeName(wire)), wire };
|
|
131
|
+
});
|
|
132
|
+
const lines = [
|
|
133
|
+
docOf("The error keys the API declares: ApiException.key() is one of these, else the server's own string.", ""),
|
|
134
|
+
"public final class ErrorKey {",
|
|
135
|
+
...constants.map(({ member, wire }) => ` public static final String ${member} = ${javaString(wire)};`),
|
|
136
|
+
"",
|
|
137
|
+
" private ErrorKey() {}",
|
|
138
|
+
"}",
|
|
139
|
+
];
|
|
140
|
+
return { [`${dir}/ErrorKey.java`]: sourceOf(marker, packageName, lines.join("\n")) };
|
|
141
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SdkOp } from "../../ir/sdk-model.ts";
|
|
2
|
+
import type { JavaTypeContext } from "./models.ts";
|
|
3
|
+
/** The holder's type, its file's declaration lines, and each declared header (as written) to its accessor. */
|
|
4
|
+
export type JavaHeaders = {
|
|
5
|
+
readonly type: string;
|
|
6
|
+
readonly lines: string[];
|
|
7
|
+
readonly fields: Readonly<Record<string, string>>;
|
|
8
|
+
};
|
|
9
|
+
/** `<Op>Headers` for `op`, or null when its 2xx responses declare no header. */
|
|
10
|
+
export declare function javaResponseHeaders(op: SdkOp, env: {
|
|
11
|
+
readonly ctx: JavaTypeContext;
|
|
12
|
+
}): JavaHeaders | null;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { javaString } from "../shared/escape.js";
|
|
2
|
+
import { camelWords, compareCodeUnits, javaIdentifier, NameScope } from "../shared/lang.js";
|
|
3
|
+
import { accessor as accessorLines, assign, call, classHeader, exprStmt, field, id, lambda, ref, statement, } from "./layout.js";
|
|
4
|
+
import { docOf } from "./sdk-decl.js";
|
|
5
|
+
import { opTypeName } from "./sdk-params.js";
|
|
6
|
+
/** The names an accessor may not take: the holder's own members, Object's, and the `read` parameters' (which shadow a field). */
|
|
7
|
+
const HOLDER_MEMBERS = [
|
|
8
|
+
"clone",
|
|
9
|
+
"equals",
|
|
10
|
+
"finalize",
|
|
11
|
+
"getClass",
|
|
12
|
+
"hashCode",
|
|
13
|
+
"headers",
|
|
14
|
+
"notify",
|
|
15
|
+
"notifyAll",
|
|
16
|
+
"read",
|
|
17
|
+
"toString",
|
|
18
|
+
"wait",
|
|
19
|
+
];
|
|
20
|
+
/** The headers `op`'s 2xx responses declare, statuses ascending, a name's first spelling (any casing) kept; by name. */
|
|
21
|
+
function declaredHeaders(op) {
|
|
22
|
+
const all = Object.keys(op.ir.responses)
|
|
23
|
+
.filter((status) => /^2(?:\d\d|XX)$/i.test(status))
|
|
24
|
+
.sort(compareCodeUnits)
|
|
25
|
+
.flatMap((status) => op.ir.responses[status].headers ?? []);
|
|
26
|
+
/* reversed, so the first spelling of a name is the one its key ends on */
|
|
27
|
+
const first = new Map(all.toReversed().map((header) => [header.name.toLowerCase(), header]));
|
|
28
|
+
return [...first.values()].sort((a, b) => compareCodeUnits(a.name, b.name));
|
|
29
|
+
}
|
|
30
|
+
/** A header's Java type, its parser, and the word its unparsable message names: a `Long`, `Double` or `Boolean` scalar parses strictly; anything else is its text. */
|
|
31
|
+
function scalarOf(schema, ctx) {
|
|
32
|
+
const resolved = ctx.names.resolve(schema);
|
|
33
|
+
if (resolved.kind === "scalar" && resolved.type === "integer")
|
|
34
|
+
return { java: "Long", parse: ref("Long", "parseLong"), word: "integer" };
|
|
35
|
+
if (resolved.kind === "scalar" && resolved.type === "number")
|
|
36
|
+
return { java: "Double", parse: ref("Double", "parseDouble"), word: "number" };
|
|
37
|
+
if (resolved.kind === "scalar" && resolved.type === "boolean")
|
|
38
|
+
return { java: "Boolean", parse: ref("Answer", "flag"), word: "boolean" };
|
|
39
|
+
return { java: "String", parse: lambda("value", id("value")), word: "text" };
|
|
40
|
+
}
|
|
41
|
+
/** `<Op>Headers` for `op`, or null when its 2xx responses declare no header. */
|
|
42
|
+
export function javaResponseHeaders(op, env) {
|
|
43
|
+
const headers = declaredHeaders(op);
|
|
44
|
+
if (headers.length === 0)
|
|
45
|
+
return null;
|
|
46
|
+
const type = opTypeName(op, "Headers", env.ctx);
|
|
47
|
+
const scope = new NameScope(HOLDER_MEMBERS);
|
|
48
|
+
const fields = headers.map((header) => {
|
|
49
|
+
const scalar = scalarOf(header.schema, env.ctx);
|
|
50
|
+
return { accessor: scope.claim(javaIdentifier(camelWords(header.name))), header, ...scalar };
|
|
51
|
+
});
|
|
52
|
+
const lines = [
|
|
53
|
+
docOf(`The response headers of ${op.id}, set when the call answers 2xx.`, ""),
|
|
54
|
+
...classHeader(type),
|
|
55
|
+
...fields.flatMap(({ accessor, java }) => field(2, { modifiers: ["private"], name: accessor, type: java })),
|
|
56
|
+
"",
|
|
57
|
+
...fields.flatMap(({ accessor, java }) => [...accessorLines(java, accessor), ""]),
|
|
58
|
+
" void read(Map<String, String> headers) {",
|
|
59
|
+
...fields.flatMap(({ accessor, header, parse, word }) => statement(4, exprStmt(assign(accessor, call("Answer", "header", [
|
|
60
|
+
"headers",
|
|
61
|
+
javaString(header.name),
|
|
62
|
+
String(header.required === true),
|
|
63
|
+
javaString(word),
|
|
64
|
+
parse,
|
|
65
|
+
]))))),
|
|
66
|
+
" }",
|
|
67
|
+
"}",
|
|
68
|
+
];
|
|
69
|
+
return {
|
|
70
|
+
fields: Object.fromEntries(fields.map(({ accessor, header }) => [header.name, accessor])),
|
|
71
|
+
lines,
|
|
72
|
+
type,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Java SDK's safe mirror (bit 21 i6): `client.safe()` is a `Safe<Client>`, with a `Safe<Resource>` per resource
|
|
3
|
+
* class, the same members as the class it mirrors; each method a twin restating every overload of the normal one. A
|
|
4
|
+
* connection's twin is the very method, as every SDK's is; every other answers `Result<T>` (`Result<Void>` for none)
|
|
5
|
+
* through `Answer.safe`, which runs the very method, so a twin never builds a call. Its class names are claimed once
|
|
6
|
+
* every normal name is, so none moves.
|
|
7
|
+
*/
|
|
8
|
+
import type { IR } from "../../ir/model.ts";
|
|
9
|
+
import { type SurfaceEnv } from "./sdk-client.ts";
|
|
10
|
+
/**
|
|
11
|
+
* The client and its safe mirror's files for `ir`, run once every normal name is claimed (the error keys' records
|
|
12
|
+
* included), so a mirror class never takes a name a normal one would have had.
|
|
13
|
+
*/
|
|
14
|
+
export declare function mirrorOf(ir: IR, env: SurfaceEnv): Record<string, string>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { messageTypeOf } from "./realtime.js";
|
|
2
|
+
import { accessor, assign, call, classHeader, exprStmt, finalField, lambda, methodHeader, newOf, param, returnStmt, statement, } from "./layout.js";
|
|
3
|
+
import { docOf, docParagraphs } from "./sdk-decl.js";
|
|
4
|
+
import { putFile } from "./sdk-models.js";
|
|
5
|
+
import { answerOf, paragraphsOf } from "./sdk-op.js";
|
|
6
|
+
import { paramsName } from "./sdk-params.js";
|
|
7
|
+
import { blocks, clientLines, membersOf, nodeOf, recordSource, resourceName, } from "./sdk-client.js";
|
|
8
|
+
import { eventTypeOf } from "./sse.js";
|
|
9
|
+
/** The type the normal method answers: a stream's, a connection's, or the answer's (`void` for none). */
|
|
10
|
+
function returnsOf(op, env) {
|
|
11
|
+
if (op.stream === "sse")
|
|
12
|
+
return `EventStream<${eventTypeOf(op, env.ctx)}>`;
|
|
13
|
+
if (op.stream === "ws")
|
|
14
|
+
return "TypedWebSocket";
|
|
15
|
+
if (op.stream === "realtime")
|
|
16
|
+
return `ResumableConnection<${messageTypeOf(op, env.ctx)}>`;
|
|
17
|
+
return answerOf(op, env).type;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The widest twin's body: `Answer.<helper>(options, o -> _n.<name>(<args>, o))` returned, the normal method run on
|
|
21
|
+
* the options with a raw box.
|
|
22
|
+
*/
|
|
23
|
+
const safeCall = (helper, name, args) => statement(4, returnStmt(call("Answer", helper, ["options", lambda("o", call("_n", name, [...args, "o"]))])));
|
|
24
|
+
/**
|
|
25
|
+
* The twin's lines on the safe mirror (bit 21 i6): each overload of the normal method restated. A connection's twin
|
|
26
|
+
* is the very method (`return _n.<name>(…)`), as every SDK's is; every other answers `Result<T>` (`Result<Void>` for
|
|
27
|
+
* none): its shorter overloads delegate as the normal ones do, its widest runs the normal method through
|
|
28
|
+
* `Answer.safe` (`Answer.safeNone` for none), so the twin never builds a call of its own.
|
|
29
|
+
*/
|
|
30
|
+
function twinLines(op, name, headers, env) {
|
|
31
|
+
const params = paramsName(op, env.ctx);
|
|
32
|
+
const returns = returnsOf(op, env);
|
|
33
|
+
const doc = docParagraphs(paragraphsOf(op));
|
|
34
|
+
const connection = op.stream === "ws" || op.stream === "realtime";
|
|
35
|
+
const type = connection ? returns : `Result<${returns === "void" ? "Void" : returns}>`;
|
|
36
|
+
const signature = (args) => methodHeader(2, { modifiers: ["public"], name, params: args, returns: type });
|
|
37
|
+
const method = (args, body) => [
|
|
38
|
+
doc,
|
|
39
|
+
...signature(args),
|
|
40
|
+
...body,
|
|
41
|
+
" }",
|
|
42
|
+
"",
|
|
43
|
+
];
|
|
44
|
+
const delegate = (of, args) => statement(4, returnStmt(call(of, name, args)));
|
|
45
|
+
const one = [param(params, "params")];
|
|
46
|
+
const two = [...one, param("RequestOptions", "options")];
|
|
47
|
+
if (connection)
|
|
48
|
+
return [...method(one, delegate("_n", ["params"])), ...method(two, delegate("_n", ["params", "options"]))];
|
|
49
|
+
const run = safeCall(returns === "void" ? "safeNone" : "safe", name, headers === null ? ["params"] : ["params", "headersInto"]);
|
|
50
|
+
return [
|
|
51
|
+
...method(one, delegate(null, headers === null ? ["params", "null"] : ["params", "null", "null"])),
|
|
52
|
+
...method(two, headers === null ? run : delegate(null, ["params", "null", "options"])),
|
|
53
|
+
...(headers === null
|
|
54
|
+
? []
|
|
55
|
+
: method([...one, param(headers.type, "headersInto"), param("RequestOptions", "options")], run)),
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
/** The mirror class of a resource's `path`: `Safe<Resource>`, claimed once every normal name is (C#'s order). */
|
|
59
|
+
const mirrorName = (path, env) => env.ctx.names.hoist(`safe:${JSON.stringify(path)}`, `Safe${resourceName(path, env.ctx)}`);
|
|
60
|
+
/**
|
|
61
|
+
* A mirror class's text: its doc naming the class it mirrors, the normal instance `_n` (`javaIdentifier` puts a `_`
|
|
62
|
+
* first only before a digit, so no member is `_n`) when it has operations, its children's mirrors built from the
|
|
63
|
+
* normal children, their accessors, and each operation's twin.
|
|
64
|
+
*/
|
|
65
|
+
function mirrorLines(node, own, normal, env) {
|
|
66
|
+
const { children, ops } = membersOf(node, env);
|
|
67
|
+
const held = ops.length > 0;
|
|
68
|
+
return blocks([
|
|
69
|
+
[
|
|
70
|
+
docOf(`{@link ${normal}}'s safe mirror: each method answers a {@link Result}, an error status or an answer that does not decode its Err; no answer still throws.`, ""),
|
|
71
|
+
...classHeader(own),
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
...(held ? finalField(normal, "_n") : []),
|
|
75
|
+
...children.flatMap(({ child, name }) => finalField(mirrorName(child.path, env), name)),
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
...methodHeader(2, { name: own, params: [param(normal, "_n")] }),
|
|
79
|
+
...(held ? [" this._n = _n;"] : []),
|
|
80
|
+
...children.flatMap(({ child, name }) => statement(4, exprStmt(assign(`this.${name}`, newOf(mirrorName(child.path, env), [call("_n", name)]))))),
|
|
81
|
+
" }",
|
|
82
|
+
],
|
|
83
|
+
...children.map(({ child, name }) => accessor(mirrorName(child.path, env), name)),
|
|
84
|
+
...ops.map(({ name, op }) => twinLines(env.ops.get(op.plan.operation), name, op.headers, env)),
|
|
85
|
+
]).concat("}");
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The client and its safe mirror's files for `ir`, run once every normal name is claimed (the error keys' records
|
|
89
|
+
* included), so a mirror class never takes a name a normal one would have had.
|
|
90
|
+
*/
|
|
91
|
+
export function mirrorOf(ir, env) {
|
|
92
|
+
const root = nodeOf(ir.tree, []);
|
|
93
|
+
const files = {};
|
|
94
|
+
const client = env.ctx.names.hoist("safe:client", `Safe${env.client}`);
|
|
95
|
+
const walk = (node) => {
|
|
96
|
+
if (node.path.length > 0) {
|
|
97
|
+
const own = mirrorName(node.path, env);
|
|
98
|
+
putFile(files, `${own}.java`, recordSource(mirrorLines(node, own, resourceName(node.path, env.ctx), env), env));
|
|
99
|
+
}
|
|
100
|
+
for (const child of node.children)
|
|
101
|
+
walk(child.node);
|
|
102
|
+
};
|
|
103
|
+
putFile(files, `${client}.java`, recordSource(mirrorLines(root, client, env.client, env), env));
|
|
104
|
+
walk(root);
|
|
105
|
+
putFile(files, `${env.client}.java`, recordSource(clientLines(ir, root, env, client), env));
|
|
106
|
+
return files;
|
|
107
|
+
}
|