@workerstack/clients 1.0.0-rc.28 → 1.0.0-rc.30
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/README.md +403 -21
- package/assets/installers/examples/github.config.ts +17 -19
- package/assets/installers/examples/goreleaser.config.ts +16 -18
- package/assets/installers/examples/raw.config.ts +13 -15
- package/bin/clients.js +87 -66
- package/bin/installgen.js +19 -10
- package/dist/cli.d.ts +4 -4
- package/dist/cli.js +18 -12
- package/dist/emit/cli/channels.d.ts +2 -2
- package/dist/emit/cli/channels.js +18 -13
- package/dist/emit/cli/commands.d.ts +1 -1
- package/dist/emit/cli/commands.js +39 -13
- package/dist/emit/cli/discovery.d.ts +0 -6
- package/dist/emit/cli/discovery.js +9 -7
- package/dist/emit/cli/flags.d.ts +1 -3
- package/dist/emit/cli/flags.js +18 -8
- package/dist/emit/cli/install.d.ts +0 -8
- package/dist/emit/cli/install.js +3 -3
- package/dist/emit/cli/layout.d.ts +1 -1
- package/dist/emit/cli/layout.js +13 -10
- package/dist/emit/cli/module.d.ts +6 -6
- package/dist/emit/cli/module.js +10 -10
- package/dist/emit/cli/release.d.ts +0 -11
- package/dist/emit/cli/release.js +4 -4
- package/dist/emit/cli/skills.js +8 -4
- package/dist/emit/csharp/errors.js +4 -4
- package/dist/emit/csharp/json.js +8 -8
- package/dist/emit/csharp/realtime.d.ts +1 -8
- package/dist/emit/csharp/realtime.js +26 -26
- package/dist/emit/csharp/sdk-answer.d.ts +10 -2
- package/dist/emit/csharp/sdk-answer.js +4 -4
- package/dist/emit/csharp/sdk-body.js +8 -6
- package/dist/emit/csharp/sdk-client.d.ts +3 -3
- package/dist/emit/csharp/sdk-client.js +2 -2
- package/dist/emit/csharp/sdk-csproj.d.ts +7 -9
- package/dist/emit/csharp/sdk-csproj.js +10 -10
- package/dist/emit/csharp/sdk-doc.js +1 -1
- package/dist/emit/csharp/sdk-method.d.ts +0 -1
- package/dist/emit/csharp/sdk-method.js +19 -8
- package/dist/emit/csharp/sdk-plan.js +0 -1
- package/dist/emit/csharp/sdk.js +3 -3
- package/dist/emit/csharp/sse.d.ts +0 -13
- package/dist/emit/csharp/sse.js +92 -11
- package/dist/emit/csharp/transport.js +9 -9
- package/dist/emit/csharp/types-enum.js +3 -1
- package/dist/emit/csharp/types-messages.d.ts +47 -0
- package/dist/emit/csharp/types-messages.js +172 -0
- package/dist/emit/csharp/types-names.js +13 -14
- package/dist/emit/csharp/types-record.js +3 -3
- package/dist/emit/csharp/types-union.d.ts +1 -1
- package/dist/emit/csharp/types.d.ts +0 -1
- package/dist/emit/csharp/types.js +3 -3
- package/dist/emit/csharp/ws.d.ts +0 -15
- package/dist/emit/csharp/ws.js +26 -5
- package/dist/emit/go/errors.js +1 -1
- package/dist/emit/go/http.js +2 -2
- package/dist/emit/go/module-path.js +2 -2
- package/dist/emit/go/sdk-answer.d.ts +24 -1
- package/dist/emit/go/sdk-answer.js +1 -1
- package/dist/emit/go/sdk-body.js +11 -7
- package/dist/emit/go/sdk-client.js +1 -1
- package/dist/emit/go/sdk-method.d.ts +3 -0
- package/dist/emit/go/sdk-method.js +18 -12
- package/dist/emit/go/sdk-mirror.js +2 -2
- package/dist/emit/go/sdk-opts.d.ts +0 -2
- package/dist/emit/go/sdk-opts.js +3 -3
- package/dist/emit/go/sdk.d.ts +1 -1
- package/dist/emit/go/sdk.js +9 -9
- package/dist/emit/go/sse.d.ts +2 -10
- package/dist/emit/go/sse.js +88 -13
- package/dist/emit/go/types-names.js +5 -0
- package/dist/emit/go/types-struct.d.ts +2 -1
- package/dist/emit/go/types-struct.js +1 -1
- package/dist/emit/go/types-union.d.ts +3 -2
- package/dist/emit/go/types-union.js +2 -0
- package/dist/emit/go/types.d.ts +6 -0
- package/dist/emit/go/types.js +20 -9
- package/dist/emit/go/ws.d.ts +4 -11
- package/dist/emit/go/ws.js +215 -59
- package/dist/emit/java/gradle.d.ts +7 -9
- package/dist/emit/java/gradle.js +8 -8
- package/dist/emit/java/json.d.ts +3 -0
- package/dist/emit/java/json.js +1 -1
- package/dist/emit/java/layout-ast.d.ts +4 -1
- package/dist/emit/java/layout-ast.js +1 -1
- package/dist/emit/java/layout-decl.js +5 -4
- package/dist/emit/java/layout-doc.js +13 -7
- package/dist/emit/java/layout-dot.js +1 -1
- package/dist/emit/java/layout-strings.js +4 -5
- package/dist/emit/java/layout-types.js +7 -5
- package/dist/emit/java/layout-visitor.js +4 -3
- package/dist/emit/java/layout.js +5 -4
- package/dist/emit/java/models-names.d.ts +2 -0
- package/dist/emit/java/models-names.js +6 -4
- package/dist/emit/java/models-record.d.ts +0 -1
- package/dist/emit/java/models-record.js +3 -3
- package/dist/emit/java/models-union.d.ts +13 -2
- package/dist/emit/java/models-union.js +12 -6
- package/dist/emit/java/models.d.ts +5 -1
- package/dist/emit/java/models.js +44 -20
- package/dist/emit/java/realtime.d.ts +34 -26
- package/dist/emit/java/realtime.js +45 -10
- package/dist/emit/java/sdk-client.d.ts +6 -6
- package/dist/emit/java/sdk-client.js +1 -1
- package/dist/emit/java/sdk-decl.js +2 -2
- package/dist/emit/java/sdk-errors.js +1 -1
- package/dist/emit/java/sdk-headers.js +2 -2
- package/dist/emit/java/sdk-mirror.js +7 -6
- package/dist/emit/java/sdk-models.d.ts +1 -1
- package/dist/emit/java/sdk-models.js +7 -7
- package/dist/emit/java/sdk-op.d.ts +1 -10
- package/dist/emit/java/sdk-op.js +9 -9
- package/dist/emit/java/sdk-params.d.ts +5 -5
- package/dist/emit/java/sdk-params.js +3 -2
- package/dist/emit/java/sdk-plan.js +0 -1
- package/dist/emit/java/sdk.d.ts +1 -1
- package/dist/emit/java/sdk.js +14 -13
- package/dist/emit/java/sse.d.ts +12 -13
- package/dist/emit/java/sse.js +105 -6
- package/dist/emit/java/ws.d.ts +48 -9
- package/dist/emit/java/ws.js +88 -4
- package/dist/emit/mcp/annotations.js +8 -4
- package/dist/emit/mcp/files.js +9 -9
- package/dist/emit/mcp/mounted.js +2 -2
- package/dist/emit/mcp/output-schema.d.ts +4 -2
- package/dist/emit/mcp/output-schema.js +58 -14
- package/dist/emit/mcp/registry.d.ts +0 -2
- package/dist/emit/mcp/registry.js +5 -4
- package/dist/emit/mcp/runtime.js +2 -2
- package/dist/emit/mcp/schema.js +22 -11
- package/dist/emit/mcp/server.d.ts +7 -7
- package/dist/emit/mcp/server.js +7 -6
- package/dist/emit/mcp/tools.js +7 -6
- package/dist/emit/python/errors.js +3 -3
- package/dist/emit/python/realtime.d.ts +9 -6
- package/dist/emit/python/realtime.js +22 -20
- package/dist/emit/python/sdk-answer.d.ts +8 -8
- package/dist/emit/python/sdk-answer.js +2 -2
- package/dist/emit/python/sdk-body.js +4 -5
- package/dist/emit/python/sdk-client.js +5 -5
- package/dist/emit/python/sdk-doc.js +2 -2
- package/dist/emit/python/sdk-method.d.ts +1 -1
- package/dist/emit/python/sdk-method.js +38 -11
- package/dist/emit/python/sdk-plan.js +0 -1
- package/dist/emit/python/sdk-pyproject.d.ts +0 -2
- package/dist/emit/python/sdk-pyproject.js +8 -8
- package/dist/emit/python/sdk.d.ts +1 -1
- package/dist/emit/python/sdk.js +28 -8
- package/dist/emit/python/sse.d.ts +0 -7
- package/dist/emit/python/sse.js +36 -6
- package/dist/emit/python/transport.js +4 -4
- package/dist/emit/python/types-dict.d.ts +2 -2
- package/dist/emit/python/types-dict.js +1 -1
- package/dist/emit/python/types-names.js +2 -2
- package/dist/emit/python/types-union.js +1 -1
- package/dist/emit/python/types.d.ts +7 -0
- package/dist/emit/python/types.js +23 -6
- package/dist/emit/python/ws.d.ts +21 -10
- package/dist/emit/python/ws.js +69 -3
- package/dist/emit/rust/errors.js +3 -3
- package/dist/emit/rust/http.js +4 -4
- package/dist/emit/rust/realtime.d.ts +7 -5
- package/dist/emit/rust/realtime.js +15 -18
- package/dist/emit/rust/sdk-body.js +8 -5
- package/dist/emit/rust/sdk-cargo.d.ts +16 -18
- package/dist/emit/rust/sdk-cargo.js +12 -12
- package/dist/emit/rust/sdk-client.d.ts +1 -1
- package/dist/emit/rust/sdk-client.js +3 -3
- package/dist/emit/rust/sdk-method.js +3 -3
- package/dist/emit/rust/sdk-opts.d.ts +2 -1
- package/dist/emit/rust/sdk-opts.js +2 -2
- package/dist/emit/rust/sdk-plan.js +0 -1
- package/dist/emit/rust/sdk.d.ts +1 -1
- package/dist/emit/rust/sdk.js +5 -5
- package/dist/emit/rust/sse.d.ts +11 -12
- package/dist/emit/rust/sse.js +54 -8
- package/dist/emit/rust/types-names.js +3 -3
- package/dist/emit/rust/types-struct.js +1 -1
- package/dist/emit/rust/types-union.d.ts +10 -2
- package/dist/emit/rust/types-union.js +4 -0
- package/dist/emit/rust/types.d.ts +9 -0
- package/dist/emit/rust/types.js +20 -12
- package/dist/emit/rust/ws.d.ts +22 -15
- package/dist/emit/rust/ws.js +60 -10
- package/dist/emit/shared/escape.js +17 -17
- package/dist/emit/shared/format.js +1 -1
- package/dist/emit/shared/gofmt.js +1 -1
- package/dist/emit/shared/lang.js +10 -10
- package/dist/emit/shared/literals.d.ts +5 -0
- package/dist/emit/shared/literals.js +8 -0
- package/dist/emit/shared/metadata.d.ts +0 -6
- package/dist/emit/shared/metadata.js +8 -7
- package/dist/emit/shared/ruff.js +1 -1
- package/dist/emit/shared/rustfmt.js +1 -1
- package/dist/emit/shared/type-emitter.js +37 -20
- package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
- package/dist/emit/shared/unknown-type.constants.js +2 -0
- package/dist/emit/ts/http.d.ts +0 -2
- package/dist/emit/ts/http.js +4 -4
- package/dist/emit/ts/package.d.ts +14 -12
- package/dist/emit/ts/package.js +9 -8
- package/dist/emit/ts/route-tree.js +2 -2
- package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
- package/dist/emit/ts/sdk-types-preamble.js +6 -2
- package/dist/emit/ts/sdk-types.js +59 -20
- package/dist/emit/ts/sdk.js +6 -6
- package/dist/emit/ts/service-map.d.ts +10 -3
- package/dist/emit/ts/service-map.js +30 -2
- package/dist/emit/ts/tanstack-query.js +6 -6
- package/dist/emit/ts/type-gen.js +36 -21
- package/dist/emit/ts/webhooks.d.ts +0 -2
- package/dist/emit/ts/webhooks.js +3 -3
- package/dist/extract/chain.js +5 -4
- package/dist/extract/extract.js +5 -5
- package/dist/extract/serialize.d.ts +0 -2
- package/dist/extract/serialize.js +14 -15
- package/dist/extract/walk.js +15 -12
- package/dist/gen/args.js +9 -5
- package/dist/gen/formatters.js +5 -3
- package/dist/gen/shipped.js +2 -2
- package/dist/gen/targets.d.ts +2 -4
- package/dist/gen/targets.js +8 -4
- package/dist/gen/write.js +4 -2
- package/dist/index.js +2 -2
- package/dist/installers/cli.d.ts +4 -4
- package/dist/installers/cli.js +24 -24
- package/dist/installers/commands/build.d.ts +4 -4
- package/dist/installers/commands/build.js +2 -3
- package/dist/installers/commands/check.d.ts +2 -2
- package/dist/installers/commands/check.js +11 -10
- package/dist/installers/commands/init.d.ts +2 -2
- package/dist/installers/commands/init.js +1 -2
- package/dist/installers/config/define-config.d.ts +16 -16
- package/dist/installers/config/define-config.js +1 -1
- package/dist/installers/config/hooks/bun.d.ts +6 -6
- package/dist/installers/config/hooks/node.js +1 -1
- package/dist/installers/config/load.d.ts +6 -8
- package/dist/installers/config/load.js +7 -8
- package/dist/installers/config/resolve.d.ts +1 -2
- package/dist/installers/config/resolve.js +28 -33
- package/dist/installers/config/types.d.ts +6 -6
- package/dist/installers/config/types.js +0 -1
- package/dist/installers/render/quote.js +3 -5
- package/dist/installers/render/render.d.ts +6 -6
- package/dist/installers/render/render.js +26 -26
- package/dist/installers/ui.d.ts +4 -4
- package/dist/installers/ui.js +3 -3
- package/dist/ir/build.d.ts +3 -3
- package/dist/ir/build.js +12 -5
- package/dist/ir/load.js +9 -10
- package/dist/ir/model.d.ts +16 -1
- package/dist/ir/model.js +0 -1
- package/dist/ir/resolve-refs.js +2 -2
- package/dist/ir/resource-tree.js +2 -1
- package/dist/ir/route-tree-intern.js +1 -1
- package/dist/ir/schema.js +3 -3
- package/dist/ir/sdk-model.d.ts +25 -1
- package/dist/ir/sdk-model.js +38 -8
- package/dist/ir/slots.d.ts +1 -1
- package/dist/ir/slots.js +22 -11
- package/dist/ir/streams.d.ts +16 -0
- package/dist/ir/streams.js +40 -0
- package/dist/release/bootstrap.d.ts +3 -3
- package/dist/release/bootstrap.js +7 -7
- package/dist/release/bump-args.js +4 -4
- package/dist/release/bump-command.d.ts +1 -1
- package/dist/release/bump-command.js +9 -10
- package/dist/release/bump.d.ts +5 -4
- package/dist/release/bump.js +2 -2
- package/dist/release/cli.d.ts +4 -4
- package/dist/release/cli.js +4 -4
- package/dist/release/codegen.js +1 -1
- package/dist/release/digest.js +5 -7
- package/dist/release/git.js +5 -8
- package/dist/release/load.js +3 -3
- package/dist/release/manifest.js +9 -10
- package/dist/release/oasdiff.d.ts +10 -15
- package/dist/release/oasdiff.js +5 -6
- package/dist/release/registries.d.ts +0 -11
- package/dist/release/registries.js +17 -17
- package/dist/release/release-state.d.ts +16 -13
- package/dist/release/release-workflow.js +5 -7
- package/dist/release/repo-settings.d.ts +2 -1
- package/dist/release/spec-gate.d.ts +0 -2
- package/dist/release/spec-gate.js +6 -10
- package/dist/release/sync-command.d.ts +2 -2
- package/dist/release/sync-command.js +1 -1
- package/dist/release/sync-tree.js +9 -13
- package/dist/release/sync.d.ts +6 -6
- package/dist/release/sync.js +12 -13
- package/dist/release/types.d.ts +22 -22
- package/dist/release/types.js +0 -1
- package/dist/release/version-files.d.ts +3 -4
- package/dist/release/version-files.js +4 -5
- package/dist/runtime/.oxfmtrc.jsonc +8 -0
- package/dist/runtime/cli/socket.go +107 -13
- package/dist/runtime/cli/stream.go +18 -11
- package/dist/runtime/csharp/Adapters.cs +12 -11
- package/dist/runtime/csharp/Events.cs +22 -17
- package/dist/runtime/csharp/Realtime.cs +50 -23
- package/dist/runtime/csharp/RealtimeLoop.cs +1 -1
- package/dist/runtime/csharp/TransportSse.cs +3 -3
- package/dist/runtime/csharp/Ws.cs +1 -1
- package/dist/runtime/csharp/WsDial.cs +19 -1
- package/dist/runtime/csharp/WsTyped.cs +109 -0
- package/dist/runtime/go/realtime.go +125 -41
- package/dist/runtime/go/realtime_loop.go +21 -18
- package/dist/runtime/go/result.go +2 -1
- package/dist/runtime/go/sse.go +11 -0
- package/dist/runtime/go/stream.go +29 -13
- package/dist/runtime/go/transport.go +15 -21
- package/dist/runtime/go/transport_longpoll.go +3 -4
- package/dist/runtime/go/transport_sse.go +6 -6
- package/dist/runtime/go/ws.go +157 -61
- package/dist/runtime/java/EventStream.java +47 -29
- package/dist/runtime/java/Exchange.java +5 -5
- package/dist/runtime/java/Flight.java +3 -3
- package/dist/runtime/java/Realtime.java +45 -11
- package/dist/runtime/java/ResumableConnection.java +77 -32
- package/dist/runtime/java/Socket.java +8 -4
- package/dist/runtime/java/SseAdapter.java +1 -1
- package/dist/runtime/java/TypedWebSocket.java +81 -24
- package/dist/runtime/java/WsAdapter.java +4 -2
- package/dist/runtime/java/WsDial.java +12 -5
- package/dist/runtime/mcp/files.ts +1 -1
- package/dist/runtime/mcp/http.ts +6 -2
- package/dist/runtime/mcp/listen.ts +1 -1
- package/dist/runtime/mcp/mount.ts +2 -2
- package/dist/runtime/mcp/protocol.ts +1 -1
- package/dist/runtime/python/events.py +25 -11
- package/dist/runtime/python/operation.py +6 -1
- package/dist/runtime/python/realtime.py +47 -33
- package/dist/runtime/python/send_async.py +1 -0
- package/dist/runtime/python/transport_sse.py +2 -2
- package/dist/runtime/python/transport_ws.py +1 -1
- package/dist/runtime/python/ws.py +100 -39
- package/dist/runtime/rust/events.rs +64 -41
- package/dist/runtime/rust/realtime.rs +80 -34
- package/dist/runtime/rust/realtime_loop.rs +37 -12
- package/dist/runtime/rust/sse.rs +3 -2
- package/dist/runtime/rust/transport_sse.rs +1 -1
- package/dist/runtime/rust/transport_ws.rs +3 -2
- package/dist/runtime/rust/ws.rs +122 -50
- package/dist/runtime/ts/realtime-connection.ts +22 -0
- package/dist/runtime/ts/realtime-transports.ts +13 -4
- package/dist/runtime/ts/realtime.ts +27 -3
- package/dist/runtime/ts/sdk-realtime.ts +1 -1
- package/dist/runtime/ts/sdk-sse.ts +31 -14
- package/dist/runtime/ts/sdk-ws.ts +2 -1
- package/dist/runtime/ts/sdk.ts +9 -2
- package/dist/runtime/ts/sse.ts +8 -0
- package/dist/runtime/ts/ws.ts +88 -50
- package/dist/runtime/ts-tanstack-query/query.ts +0 -2
- package/package.json +12 -40
- package/dist/emit/cli/index.d.ts +0 -1
- package/dist/emit/cli/index.js +0 -1
- package/dist/emit/csharp/index.d.ts +0 -1
- package/dist/emit/csharp/index.js +0 -1
- package/dist/emit/go/index.d.ts +0 -1
- package/dist/emit/go/index.js +0 -1
- package/dist/emit/java/index.d.ts +0 -2
- package/dist/emit/java/index.js +0 -2
- package/dist/emit/mcp/index.d.ts +0 -3
- package/dist/emit/mcp/index.js +0 -3
- package/dist/emit/python/index.d.ts +0 -1
- package/dist/emit/python/index.js +0 -1
- package/dist/emit/rust/index.d.ts +0 -1
- package/dist/emit/rust/index.js +0 -1
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
import { type Shipped } from "../shared/metadata.ts";
|
|
2
2
|
/** The emitted `rust-version`: the toolchain floor every SDK builds with (Fb2). */
|
|
3
3
|
export declare const RUST_VERSION = "1.85";
|
|
4
|
-
/** The emitted edition, which the floor forces. */
|
|
5
|
-
export declare const EDITION = "2024";
|
|
6
4
|
/** The crate's name and version as Cargo.toml and the lock root carry them, and the metadata crates.io shows. */
|
|
7
5
|
export type CrateIdentity = {
|
|
8
6
|
readonly name: string;
|
|
9
7
|
readonly version: string;
|
|
10
8
|
/** what crates.io shows and `cargo publish` requires; left out when the caller names none */
|
|
11
|
-
readonly description?: string;
|
|
12
|
-
readonly documentation?: string;
|
|
13
|
-
readonly homepage?: string;
|
|
14
|
-
readonly keywords?: readonly string[];
|
|
15
|
-
readonly categories?: readonly string[];
|
|
16
|
-
readonly license?: string;
|
|
17
|
-
readonly repository?: string;
|
|
9
|
+
readonly description?: string | undefined;
|
|
10
|
+
readonly documentation?: string | undefined;
|
|
11
|
+
readonly homepage?: string | undefined;
|
|
12
|
+
readonly keywords?: readonly string[] | undefined;
|
|
13
|
+
readonly categories?: readonly string[] | undefined;
|
|
14
|
+
readonly license?: string | undefined;
|
|
15
|
+
readonly repository?: string | undefined;
|
|
18
16
|
};
|
|
19
17
|
/** The crate options as a run gives them: a list as a list, or the CLI's comma-separated value. */
|
|
20
18
|
export type CrateOptions = {
|
|
21
|
-
readonly crateName?: string;
|
|
22
|
-
readonly version?: string;
|
|
23
|
-
readonly description?: string;
|
|
24
|
-
readonly documentation?: string;
|
|
25
|
-
readonly homepage?: string;
|
|
26
|
-
readonly keywords?: readonly string[] | string;
|
|
27
|
-
readonly categories?: readonly string[] | string;
|
|
28
|
-
readonly license?: string;
|
|
29
|
-
readonly repository?: string;
|
|
19
|
+
readonly crateName?: string | undefined;
|
|
20
|
+
readonly version?: string | undefined;
|
|
21
|
+
readonly description?: string | undefined;
|
|
22
|
+
readonly documentation?: string | undefined;
|
|
23
|
+
readonly homepage?: string | undefined;
|
|
24
|
+
readonly keywords?: readonly string[] | string | undefined;
|
|
25
|
+
readonly categories?: readonly string[] | string | undefined;
|
|
26
|
+
readonly license?: string | undefined;
|
|
27
|
+
readonly repository?: string | undefined;
|
|
30
28
|
};
|
|
31
29
|
/**
|
|
32
30
|
* The crate `options` give, each value checked against the grammar every target shares and crates.io's own limits
|
|
@@ -10,12 +10,12 @@ import { checked, HTTPS_URL, LICENSE, README, SPDX_EXPRESSION, TEXT } from "../s
|
|
|
10
10
|
/** The emitted `rust-version`: the toolchain floor every SDK builds with (Fb2). */
|
|
11
11
|
export const RUST_VERSION = "1.85";
|
|
12
12
|
/** The emitted edition, which the floor forces. */
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const EDITION = "2024";
|
|
14
|
+
// a crate that ships nothing beside its code
|
|
15
15
|
const NONE_SHIPPED = { icon: undefined, licenseFile: false, readme: false };
|
|
16
|
-
|
|
16
|
+
// the dependency the WebSocket and realtime runtime files need, and only they
|
|
17
17
|
const WEBSOCKET = "tokio-tungstenite";
|
|
18
|
-
|
|
18
|
+
// each dependency's requirement line, in name order: the floors are the template lock's versions
|
|
19
19
|
const DEPENDENCIES = [
|
|
20
20
|
["bytes", '"1.12.1"'],
|
|
21
21
|
["futures-util", '{ version = "0.3.34", default-features = false, features = ["std", "sink"] }'],
|
|
@@ -30,17 +30,17 @@ const DEPENDENCIES = [
|
|
|
30
30
|
["url", '"2.5.8"'],
|
|
31
31
|
];
|
|
32
32
|
const MARKER = "# @generated by clients. DO NOT EDIT.";
|
|
33
|
-
|
|
33
|
+
// a semver version: it lands inside a TOML string, so nothing else may
|
|
34
34
|
const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
// crates.io's keyword: ASCII, a letter or digit first, then letters, digits, `_`, `-` or `+`, at most 20 characters;
|
|
36
|
+
// a category: a slug as https://crates.io/category_slugs lists them, which crates.io matches exactly; five of each
|
|
37
37
|
const CRATE_KEYWORD = /^[A-Za-z0-9][A-Za-z0-9_+-]{0,19}$/;
|
|
38
38
|
const CATEGORY = /^[a-z0-9-]+(?:::[a-z0-9-]+)*$/;
|
|
39
39
|
const MAX_LISTED = 5;
|
|
40
40
|
/** A list option as a list, each entry checked against `grammar`, at most five: crates.io's limit for both lists. */
|
|
41
41
|
function listed(option, value, grammar) {
|
|
42
42
|
if (value === undefined)
|
|
43
|
-
return
|
|
43
|
+
return;
|
|
44
44
|
const list = (typeof value === "string" ? value.split(",") : value).map((word) => word.trim()).filter(Boolean);
|
|
45
45
|
for (const word of list)
|
|
46
46
|
checked(option, word, grammar);
|
|
@@ -102,11 +102,11 @@ export function cargoToml(crate, ws, shipped = NONE_SHIPPED) {
|
|
|
102
102
|
`version = "${crate.version}"`,
|
|
103
103
|
`edition = "${EDITION}"`,
|
|
104
104
|
`rust-version = "${RUST_VERSION}"`,
|
|
105
|
-
|
|
105
|
+
// the metadata crates.io reads: each line only when the caller gave it
|
|
106
106
|
...metadata(crate),
|
|
107
107
|
...(shipped.readme ? [`readme = "${README}"`] : []),
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
// what the published crate holds beside Cargo.toml and its lock, which cargo always packs: its README and
|
|
109
|
+
// license file when it ships them; clients' manifest and anything else written beside the crate stay out
|
|
110
110
|
`include = ${toml(["/src", ...(shipped.readme ? [`/${README}`] : []), ...(shipped.licenseFile ? [`/${LICENSE}`] : [])])}`,
|
|
111
111
|
"",
|
|
112
112
|
"[lib]",
|
|
@@ -153,7 +153,7 @@ function referenced(kept, reference) {
|
|
|
153
153
|
return kept.filter((p) => p.name === name).length > 1 ? reference : name;
|
|
154
154
|
}
|
|
155
155
|
/** `p`'s text with every dependency reference rewritten for `kept`. */
|
|
156
|
-
const rewritten = (p, kept) => p.text.
|
|
156
|
+
const rewritten = (p, kept) => p.text.replaceAll(/^ "([^"]+)",$/gm, (_, reference) => ` "${referenced(kept, reference)}",`);
|
|
157
157
|
/** The root entry as `crate`, without `tokio-tungstenite` unless `ws`. */
|
|
158
158
|
function rootOf(root, crate, ws) {
|
|
159
159
|
const named = root.text
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { IR } from "../../ir/model.ts";
|
|
10
10
|
import type { SdkOp } from "../../ir/sdk-model.ts";
|
|
11
|
-
import type { RustCallPlan } from "./sdk-plan.ts";
|
|
12
11
|
import { type MethodEnv } from "./sdk-method.ts";
|
|
12
|
+
import type { RustCallPlan } from "./sdk-plan.ts";
|
|
13
13
|
/** The method env, the operations by id, and the notices the generation reports (a root member renamed for the mirror). */
|
|
14
14
|
export type ClientEnv = MethodEnv & {
|
|
15
15
|
readonly ops: ReadonlyMap<string, SdkOp>;
|
|
@@ -4,7 +4,7 @@ import { compareCodeUnits, NameScope, rustTypeIdent, rustValueIdent } from "../s
|
|
|
4
4
|
import { MIRROR, mirrorNotice } from "../shared/mirror.js";
|
|
5
5
|
import { rustMethod } from "./sdk-method.js";
|
|
6
6
|
import { STYLE } from "./types-names.js";
|
|
7
|
-
|
|
7
|
+
// the runtime's own associated functions on `Client`, the mirror among them: no operation takes their name
|
|
8
8
|
const CLIENT_FNS = ["build", "new", MIRROR];
|
|
9
9
|
/** A member's name in `scope`; at the root (`path` empty) one spelled like the mirror is `safe_` instead, and noticed. */
|
|
10
10
|
function memberName(segment, path, scope, env) {
|
|
@@ -22,7 +22,7 @@ function resourceOf(ns, path, type, env) {
|
|
|
22
22
|
const children = namespacesOf(ns).map(([segment, child]) => {
|
|
23
23
|
const accessor = memberName(segment, path, scope, env);
|
|
24
24
|
const childPath = [...path, segment];
|
|
25
|
-
|
|
25
|
+
// the type rule over the whole name: a leading digit gets its guard, and `self` stays `SelfResource`
|
|
26
26
|
const childType = env.at.names.claim(rustTypeIdent([...childPath, "Resource"].join(".")));
|
|
27
27
|
return { accessor, node: resourceOf(child, childPath, childType, env) };
|
|
28
28
|
});
|
|
@@ -42,7 +42,7 @@ function accessorBlocks(node, lifetime, client) {
|
|
|
42
42
|
const members = (blocks) => blocks.map((lines) => lines.join("\n")).join("\n\n");
|
|
43
43
|
/** Each namespace below the client: its type, its accessors and methods, then its children's. */
|
|
44
44
|
function resourceLines(node) {
|
|
45
|
-
|
|
45
|
+
// the lifetime is named only where an accessor hands it on
|
|
46
46
|
const head = node.children.length > 0
|
|
47
47
|
? `impl<'a, ${STYLE}: Style> ${node.type}<'a, ${STYLE}> {`
|
|
48
48
|
: `impl<${STYLE}: Style> ${node.type}<'_, ${STYLE}> {`;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { mediaEssence } from "../../ir/sdk-model.js";
|
|
2
2
|
import { lineComment, rustString } from "../shared/escape.js";
|
|
3
3
|
import { NameScope, rustTypeIdent, rustValueIdent } from "../shared/lang.js";
|
|
4
|
+
import { realtimeAnswer } from "./realtime.js";
|
|
4
5
|
import { rustBody, typeAt } from "./sdk-body.js";
|
|
5
6
|
import { optsDecl, optsFields, optsLines, responseHeaders, takesIdempotencyKey, } from "./sdk-opts.js";
|
|
6
|
-
import { realtimeAnswer } from "./realtime.js";
|
|
7
7
|
import { sseAnswer } from "./sse.js";
|
|
8
8
|
import { STYLE } from "./types-names.js";
|
|
9
9
|
import { wsAnswer } from "./ws.js";
|
|
10
|
-
|
|
10
|
+
// the method's own locals: a path param never shadows one (it is claimed as `…2`)
|
|
11
11
|
const METHOD_LOCALS = ["body", "client", "form", "opts", "spec"];
|
|
12
12
|
/** How a stream operation answers. */
|
|
13
13
|
function streamAnswer(op, at) {
|
|
14
14
|
if (op.stream === "sse")
|
|
15
15
|
return sseAnswer(op, at);
|
|
16
|
-
return op.stream === "ws" ? wsAnswer() : realtimeAnswer(op, at);
|
|
16
|
+
return op.stream === "ws" ? wsAnswer(op, at) : realtimeAnswer(op, at);
|
|
17
17
|
}
|
|
18
18
|
/** How a method answers: a stream's way, else its answer's kind read. */
|
|
19
19
|
function answerOf(op, env) {
|
|
@@ -13,7 +13,7 @@ export type OptsField = {
|
|
|
13
13
|
readonly bare: boolean;
|
|
14
14
|
};
|
|
15
15
|
/** A stream's own `<Op>Opts` field, after the declared ones. */
|
|
16
|
-
|
|
16
|
+
type StreamField = {
|
|
17
17
|
readonly ident: string;
|
|
18
18
|
readonly type: string;
|
|
19
19
|
readonly doc?: string;
|
|
@@ -56,3 +56,4 @@ export declare function responseHeaders(op: SdkOp, at: RustTypeContext): {
|
|
|
56
56
|
readonly plan: RustResponseHeaders;
|
|
57
57
|
readonly decl: string;
|
|
58
58
|
} | null;
|
|
59
|
+
export {};
|
|
@@ -2,7 +2,7 @@ import { lineComment, rustString } from "../shared/escape.js";
|
|
|
2
2
|
import { compareCodeUnits, NameScope, rustTypeIdent, rustValueIdent } from "../shared/lang.js";
|
|
3
3
|
import { unboxed } from "./types-struct.js";
|
|
4
4
|
import { rustTypeOf } from "./types.js";
|
|
5
|
-
|
|
5
|
+
// the Opts field an idempotent operation's caller sets its Idempotency-Key through
|
|
6
6
|
const IDEMPOTENCY_KEY = "idempotency_key";
|
|
7
7
|
const isStringConst = (s) => s.kind === "const" && typeof s.value === "string";
|
|
8
8
|
/** Whether the type `schema` declares as a component has a `Default`: a struct, a newtype and a payload enum do not. */
|
|
@@ -77,7 +77,7 @@ function declaredHeaders(op) {
|
|
|
77
77
|
.filter((status) => /^2(?:\d\d|XX)$/i.test(status))
|
|
78
78
|
.sort(compareCodeUnits)
|
|
79
79
|
.flatMap((status) => op.ir.responses[status].headers ?? []);
|
|
80
|
-
|
|
80
|
+
// reversed, so the first spelling of a name is the one its key ends on
|
|
81
81
|
const first = new Map(all.toReversed().map((header) => [header.name.toLowerCase(), header]));
|
|
82
82
|
return [...first.values()].sort((a, b) => compareCodeUnits(a.name, b.name));
|
|
83
83
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/emit/rust/sdk.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type CrateOptions } from "./sdk-cargo.ts";
|
|
2
1
|
import { type PackageIdentity, type Shipped } from "../shared/metadata.ts";
|
|
2
|
+
import { type CrateOptions } from "./sdk-cargo.ts";
|
|
3
3
|
import type { RustCallPlan } from "./sdk-plan.ts";
|
|
4
4
|
/**
|
|
5
5
|
* The crate's options: its name (`http-sdk` by default), version (`0.1.0` by default) and what crates.io shows,
|
package/dist/emit/rust/sdk.js
CHANGED
|
@@ -10,14 +10,14 @@ import { toIR } from "../../ir/build.js";
|
|
|
10
10
|
import { sdkModel } from "../../ir/sdk-model.js";
|
|
11
11
|
import { lineComment } from "../shared/escape.js";
|
|
12
12
|
import { compareCodeUnits, rustTypeIdent } from "../shared/lang.js";
|
|
13
|
+
import { packageOn } from "../shared/metadata.js";
|
|
13
14
|
import { renameNotice } from "../shared/mirror.js";
|
|
14
15
|
import { rustErrorKeys } from "./errors.js";
|
|
15
16
|
import { needsWebSocket, publicItems, runtimeFiles } from "./http.js";
|
|
16
17
|
import { cargoLock, cargoToml, crateIdentity } from "./sdk-cargo.js";
|
|
17
|
-
import { packageOn } from "../shared/metadata.js";
|
|
18
18
|
import { clientDecls } from "./sdk-client.js";
|
|
19
19
|
import { rustTopLevel, rustTypeContext } from "./types.js";
|
|
20
|
-
|
|
20
|
+
// the marker rustfmt and linguist read
|
|
21
21
|
const MARKER = "// @generated by clients. DO NOT EDIT.";
|
|
22
22
|
/** Each component's declaration in code-unit order, its description as its rustdoc. */
|
|
23
23
|
function componentDecls(ir, at) {
|
|
@@ -64,9 +64,9 @@ function emitRust(document, options, shipped) {
|
|
|
64
64
|
const ir = toIR(document, { deriveOperationIds: true });
|
|
65
65
|
const model = sdkModel(ir);
|
|
66
66
|
const at = rustTypeContext(ir);
|
|
67
|
-
|
|
67
|
+
// components first: the client's hoisted types then land beside them
|
|
68
68
|
const components = componentDecls(ir, at);
|
|
69
|
-
|
|
69
|
+
// every component emitted under another name is noticed, as the mirror's rename is
|
|
70
70
|
const notices = [...at.names.renamed].map(([name, emitted]) => renameNotice("rust", {
|
|
71
71
|
because: `"${rustTypeIdent(name)}" is a name the SDK's crate root or the Rust prelude holds`,
|
|
72
72
|
name,
|
|
@@ -74,7 +74,7 @@ function emitRust(document, options, shipped) {
|
|
|
74
74
|
what: "component",
|
|
75
75
|
}));
|
|
76
76
|
const client = clientDecls(ir, { at, notices, ops: model.opsById });
|
|
77
|
-
|
|
77
|
+
// before the hoisted are read: each key's <Key>Data lands among them; an API without operations answers no error
|
|
78
78
|
const errorKeys = model.ops.length > 0 ? [rustErrorKeys(model, at)] : [];
|
|
79
79
|
const hoisted = [...at.decls].sort(([a], [b]) => compareCodeUnits(a, b)).map(([, decl]) => decl);
|
|
80
80
|
const features = {
|
package/dist/emit/rust/sse.d.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* An SSE operation's answer (contract 20 §2.0–2.1)
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* An SSE operation's answer (contract 20 §2.0–2.1) and its Opts' `last_event_id`, sent as Last-Event-ID only
|
|
3
|
+
* when set and non-empty; a declared Last-Event-ID header param is folded into that field (Fd3). An operation that
|
|
4
|
+
* names its events (D7) answers `EventStream<<Op>Event>`: an enum with one variant per event name, holding
|
|
5
|
+
* `SseEvent<Data>` decoded by its name, and `Unknown(SseEvent<String>)` for a name it does not declare; it serializes
|
|
6
|
+
* as the `SseEvent` it holds (`{data, event, id, retry}`), so one reader takes any stream's events. Any other answers
|
|
7
|
+
* `EventStream<SseEvent<T>>`, `T` the declared event schema's type, or `EventStream` for untyped events.
|
|
5
8
|
*/
|
|
6
|
-
import type {
|
|
9
|
+
import type { IRSchema } from "../../ir/model.ts";
|
|
10
|
+
import { type SdkOp } from "../../ir/sdk-model.ts";
|
|
7
11
|
import type { OptsField, StreamAnswer } from "./sdk-opts.ts";
|
|
8
12
|
import type { RustTypeContext } from "./types.ts";
|
|
9
|
-
/** The resume cursor's id, which the SSE and realtime Opts carry. */
|
|
10
|
-
export declare const LAST_EVENT_ID: {
|
|
11
|
-
ident: string;
|
|
12
|
-
type: string;
|
|
13
|
-
};
|
|
14
13
|
/** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
|
|
15
14
|
export declare const isLastEventIdHeader: (param: string, where: OptsField["in"]) => boolean;
|
|
16
|
-
/**
|
|
17
|
-
export declare const eventType: (op: SdkOp,
|
|
18
|
-
/** The SSE operation `op`'s answer: its events as text
|
|
15
|
+
/** The type of the events `op` declares as `events`. */
|
|
16
|
+
export declare const eventType: (op: SdkOp, events: IRSchema, at: RustTypeContext) => string;
|
|
17
|
+
/** The SSE operation `op`'s answer: its events by name, else as text or JSON decoded into the event type. */
|
|
19
18
|
export declare function sseAnswer(op: SdkOp, at: RustTypeContext): StreamAnswer;
|
package/dist/emit/rust/sse.js
CHANGED
|
@@ -1,20 +1,66 @@
|
|
|
1
|
+
import { isJsonEventData, sseEvents } from "../../ir/sdk-model.js";
|
|
2
|
+
import { lineComment, rustString } from "../shared/escape.js";
|
|
3
|
+
import { NameScope, rustTypeIdent } from "../shared/lang.js";
|
|
1
4
|
import { typeAt } from "./sdk-body.js";
|
|
5
|
+
import { variantOf } from "./types-enum.js";
|
|
2
6
|
/** The resume cursor's id, which the SSE and realtime Opts carry. */
|
|
3
|
-
|
|
7
|
+
const LAST_EVENT_ID = { ident: "last_event_id", type: "Option<String>" };
|
|
4
8
|
/** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
|
|
5
9
|
export const isLastEventIdHeader = (param, where) => where === "header" && param.toLowerCase() === "last-event-id";
|
|
6
|
-
/**
|
|
7
|
-
export const eventType = (op,
|
|
8
|
-
|
|
10
|
+
/** The type of the events `op` declares as `events`. */
|
|
11
|
+
export const eventType = (op, events, at) => typeAt(events, op.id, "Event", at);
|
|
12
|
+
// Last-Event-ID, sent only when set: an empty cursor names no position
|
|
9
13
|
const SSE = {
|
|
10
14
|
carries: isLastEventIdHeader,
|
|
11
15
|
fields: [LAST_EVENT_ID],
|
|
12
16
|
sends: ['spec.header("Last-Event-ID", &crate::request::cursor(&opts.last_event_id));'],
|
|
13
17
|
};
|
|
14
18
|
const DOC = "Resolves once the stream is open: an error status is the answer's error (`Err(Error::Api)`, on `client.safe()` an `Answer::Err`). No timeout bounds the stream after that; `cancel_on` ends it quietly, and dropping it closes it.";
|
|
15
|
-
/** The
|
|
19
|
+
/** The match arm decoding `variant`: its data from JSON, or the event as sent. */
|
|
20
|
+
const armOf = ({ event, json, variant }) => ` ${rustString(event)} => ${json ? `crate::events::named_data(e).map(Self::${variant})` : `Ok(Self::${variant}(e))`},`;
|
|
21
|
+
/** `<Op>Event`, declared in `at` with its variants in the order declared and its decode; its name. */
|
|
22
|
+
function namedEvents(op, events, at) {
|
|
23
|
+
const name = at.names.claim(`${rustTypeIdent(op.id)}Event`);
|
|
24
|
+
const scope = new NameScope(["Unknown"]);
|
|
25
|
+
const variants = events.map(({ data, name: event }) => ({
|
|
26
|
+
data: typeAt(data, op.id, event, at),
|
|
27
|
+
event,
|
|
28
|
+
json: isJsonEventData(data, at.names.resolve),
|
|
29
|
+
variant: variantOf(event, scope),
|
|
30
|
+
}));
|
|
31
|
+
const list = variants.map((v) => `\`${v.variant}\``).join(", ");
|
|
32
|
+
at.decls.set(name, [
|
|
33
|
+
...lineComment(`One event of ${op.id}: ${list}, or \`Unknown\` for a name the operation does not declare, its data as sent. A match on it reads the event's data; it serializes as the \`SseEvent\` it holds.`, "///"),
|
|
34
|
+
"#[derive(Debug, Clone, PartialEq, serde::Serialize)]",
|
|
35
|
+
"#[serde(untagged)]",
|
|
36
|
+
`pub enum ${name} {`,
|
|
37
|
+
...variants.map((v) => ` ${v.variant}(crate::SseEvent<${v.data}>),`),
|
|
38
|
+
" Unknown(crate::SseEvent<String>),",
|
|
39
|
+
"}",
|
|
40
|
+
"",
|
|
41
|
+
`impl crate::events::Named for ${name} {`,
|
|
42
|
+
" fn named(mut e: crate::SseEvent) -> Result<Self, crate::Error> {",
|
|
43
|
+
" if e.event.is_empty() {",
|
|
44
|
+
' e.event = "message".to_owned();',
|
|
45
|
+
" }",
|
|
46
|
+
" match e.event.as_str() {",
|
|
47
|
+
...variants.map(armOf),
|
|
48
|
+
" _ => Ok(Self::Unknown(e)),",
|
|
49
|
+
" }",
|
|
50
|
+
" }",
|
|
51
|
+
"}",
|
|
52
|
+
].join("\n"));
|
|
53
|
+
return name;
|
|
54
|
+
}
|
|
55
|
+
/** The SSE operation `op`'s answer: its events by name, else as text or JSON decoded into the event type. */
|
|
16
56
|
export function sseAnswer(op, at) {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
57
|
+
const named = sseEvents(op.ir);
|
|
58
|
+
if (named !== undefined) {
|
|
59
|
+
const name = namedEvents(op, named, at);
|
|
60
|
+
return { doc: DOC, run: `crate::events::named::<${name}>`, stream: SSE, type: `EventStream<${name}>` };
|
|
61
|
+
}
|
|
62
|
+
if (op.events === undefined)
|
|
63
|
+
return { doc: DOC, run: "crate::events::text", stream: SSE, type: "EventStream" };
|
|
64
|
+
const events = eventType(op, op.events, at);
|
|
65
|
+
return { doc: DOC, run: `crate::events::json::<${events}>`, stream: SSE, type: `EventStream<SseEvent<${events}>>` };
|
|
20
66
|
}
|
|
@@ -14,7 +14,7 @@ function runtimeIdentifiers() {
|
|
|
14
14
|
}
|
|
15
15
|
/** The style parameter every resource and its methods' `Call` take (bit 21 i4): no type may be named it. */
|
|
16
16
|
export const STYLE = "S";
|
|
17
|
-
|
|
17
|
+
// the crate-root types the emitter itself declares beside the runtime's (errors.ts's enum), and the style parameter
|
|
18
18
|
const EMITTED = ["ErrorKey", STYLE];
|
|
19
19
|
/** Names for one schema on its own: each as asked for, no cycles, refs left unresolved. */
|
|
20
20
|
export function plainNames() {
|
|
@@ -22,8 +22,8 @@ export function plainNames() {
|
|
|
22
22
|
claim: (base) => base,
|
|
23
23
|
cyclic: new Set(),
|
|
24
24
|
hoist: (_key, base) => base,
|
|
25
|
-
renamed: new Map(),
|
|
26
25
|
ref: rustTypeIdent,
|
|
26
|
+
renamed: new Map(),
|
|
27
27
|
resolve: (schema) => schema,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
@@ -45,7 +45,7 @@ export function irNames(ir) {
|
|
|
45
45
|
if (taken)
|
|
46
46
|
renamed.set(name, claimed);
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
// a joined name can spell a prelude one (`Hash` + `map`): that one is taken too, so the claim moves on
|
|
49
49
|
const claim = (base) => {
|
|
50
50
|
const name = scope.claim(base);
|
|
51
51
|
return isRustPreludeType(name) ? scope.claim(base) : name;
|
|
@@ -2,7 +2,7 @@ import { rustString } from "../shared/escape.js";
|
|
|
2
2
|
import { compareCodeUnits, NameScope, rustValueIdent } from "../shared/lang.js";
|
|
3
3
|
export const DERIVE = "#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]";
|
|
4
4
|
const SKIP = 'skip_serializing_if = "Option::is_none"';
|
|
5
|
-
|
|
5
|
+
// absent, null and a value: `default` for absent, the runtime's deserializer keeping null as Some(None)
|
|
6
6
|
const TRI_STATE = ["default", 'deserialize_with = "crate::nullable::deserialize"', SKIP];
|
|
7
7
|
/** A field's lines: its serde keys in one attribute when it has any, then `pub <ident>: <type>,`. */
|
|
8
8
|
const fieldLines = ({ ident, type, serde }) => [
|
|
@@ -5,20 +5,28 @@
|
|
|
5
5
|
* object, plus `Unknown` keeping any other payload whole, serialized as the payload and deserialized
|
|
6
6
|
* on the discriminator's value with the payload kept, the discriminator included.
|
|
7
7
|
*/
|
|
8
|
-
import type { IRSchema } from "../../ir/model.ts";
|
|
8
|
+
import type { IRDiscriminator, IRSchema } from "../../ir/model.ts";
|
|
9
9
|
import { type Member } from "./types-struct.ts";
|
|
10
10
|
import type { RustTypeNames } from "./types.ts";
|
|
11
11
|
type Of<K extends IRSchema["kind"]> = Extract<IRSchema, {
|
|
12
12
|
kind: K;
|
|
13
13
|
}>;
|
|
14
14
|
/** Declares `schema` once under `names.hoist(key, base)`; its name. */
|
|
15
|
-
|
|
15
|
+
type Declare = (schema: IRSchema, key: string, base: string) => string;
|
|
16
16
|
/** What a union's declaration reaches: the names, its members' types, and the hoist. */
|
|
17
17
|
export type UnionScope = {
|
|
18
18
|
names: RustTypeNames;
|
|
19
19
|
member: Member;
|
|
20
20
|
declare: Declare;
|
|
21
21
|
};
|
|
22
|
+
/** Each value a keyed union selects a variant by, beside that variant's name and payload type, in declared order. */
|
|
23
|
+
export declare function unionVariants(name: string, union: Of<"union"> & {
|
|
24
|
+
discriminator: IRDiscriminator;
|
|
25
|
+
}, scope: UnionScope): {
|
|
26
|
+
value: string;
|
|
27
|
+
variant: string;
|
|
28
|
+
type: string;
|
|
29
|
+
}[];
|
|
22
30
|
/** The declaration of a union with at least one variant. */
|
|
23
31
|
export declare function unionDecl(name: string, union: Of<"union">, scope: UnionScope): string;
|
|
24
32
|
export {};
|
|
@@ -47,6 +47,10 @@ function variantsOf(name, union, scope) {
|
|
|
47
47
|
return [{ type, values: values.filter(fresh), variant: variantOf(values[0] ?? type, variantNames) }];
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
+
/** Each value a keyed union selects a variant by, beside that variant's name and payload type, in declared order. */
|
|
51
|
+
export function unionVariants(name, union, scope) {
|
|
52
|
+
return variantsOf(name, union, scope).flatMap(({ type, values, variant }) => values.map((value) => ({ type, value, variant })));
|
|
53
|
+
}
|
|
50
54
|
/** `Serialize` as the payload of whichever variant holds it. */
|
|
51
55
|
const serializeImpl = (name, variants) => [
|
|
52
56
|
`impl serde::Serialize for ${name} {`,
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* only through the shared escape layer.
|
|
6
6
|
*/
|
|
7
7
|
import type { IR, IRSchema } from "../../ir/model.ts";
|
|
8
|
+
import type { Dispatch } from "../../ir/sdk-model.ts";
|
|
8
9
|
/** How component and hoisted names are claimed, and which components sit on a value cycle. */
|
|
9
10
|
export type RustTypeNames = {
|
|
10
11
|
/** the Rust type name of the component `name` */
|
|
@@ -28,7 +29,15 @@ export type RustTypeContext = {
|
|
|
28
29
|
};
|
|
29
30
|
/** A context over `ir`'s components, or plain names without one. */
|
|
30
31
|
export declare function rustTypeContext(ir?: IR): RustTypeContext;
|
|
32
|
+
/** `ir` declared once as `names.hoist(key, base)` into `at.decls`; its name. */
|
|
33
|
+
export declare function rustHoisted(ir: IRSchema, at: RustTypeContext, key: string, base: string): string;
|
|
31
34
|
/** The Rust type of `ir` in use position; what it hoists lands in `at.decls`. */
|
|
32
35
|
export declare function rustTypeOf(ir: IRSchema, at: RustTypeContext): string;
|
|
36
|
+
/** Each value the keyed union `union`, declared as `name`, selects a variant by, with that variant and its payload type. */
|
|
37
|
+
export declare const rustUnionVariants: (name: string, union: Dispatch["union"], at: RustTypeContext) => {
|
|
38
|
+
value: string;
|
|
39
|
+
variant: string;
|
|
40
|
+
type: string;
|
|
41
|
+
}[];
|
|
33
42
|
/** The top-level declaration of the type `name` (a Rust identifier already) for `ir`. */
|
|
34
43
|
export declare function rustTopLevel(name: string, ir: IRSchema, at: RustTypeContext): string;
|
package/dist/emit/rust/types.js
CHANGED
|
@@ -2,10 +2,10 @@ import { pascalWords, rustTypeIdent } from "../shared/lang.js";
|
|
|
2
2
|
import { integerValues, intEnumDecl, stringEnumDecl, stringValues } from "./types-enum.js";
|
|
3
3
|
import { irNames, plainNames } from "./types-names.js";
|
|
4
4
|
import { allOfDecl, DERIVE, objectDecl, unboxed } from "./types-struct.js";
|
|
5
|
-
import { unionDecl } from "./types-union.js";
|
|
5
|
+
import { unionDecl, unionVariants } from "./types-union.js";
|
|
6
6
|
const VALUE = "serde_json::Value";
|
|
7
7
|
const MAP = "std::collections::HashMap";
|
|
8
|
-
|
|
8
|
+
// deeper than this, a schema is any JSON value
|
|
9
9
|
const MAX_DEPTH = 12;
|
|
10
10
|
const SCALARS = {
|
|
11
11
|
boolean: "bool",
|
|
@@ -19,21 +19,23 @@ export function rustTypeContext(ir) {
|
|
|
19
19
|
return { decls: new Map(), fieldName: "", names: ir ? irNames(ir) : plainNames(), parentName: "" };
|
|
20
20
|
}
|
|
21
21
|
/** `ir` declared once as `names.hoist(key, base)` into `at.decls`; its name. */
|
|
22
|
-
function
|
|
22
|
+
export function rustHoisted(ir, at, key, base) {
|
|
23
23
|
const name = at.names.hoist(key, base);
|
|
24
24
|
if (!at.decls.has(name)) {
|
|
25
|
-
|
|
25
|
+
// claimed before its body: what the body hoists in turn comes after it
|
|
26
26
|
at.decls.set(name, "");
|
|
27
27
|
at.decls.set(name, rustTopLevel(name, ir, at));
|
|
28
28
|
}
|
|
29
29
|
return name;
|
|
30
30
|
}
|
|
31
31
|
/** `ir` hoisted as `<Parent><Field>`. */
|
|
32
|
-
const hoist = (ir, at) =>
|
|
32
|
+
const hoist = (ir, at) => rustHoisted(ir, at, `${at.parentName}.${at.fieldName}`, `${rustTypeIdent(at.parentName)}${pascalWords(at.fieldName)}`);
|
|
33
33
|
const deeper = (at, fieldName = at.fieldName) => ({ ...at, depth: at.depth + 1, fieldName });
|
|
34
34
|
/** Whether a scalar is a string or integer enum with a value of its kind: a declared enum. */
|
|
35
35
|
const isEnum = (ir) => ir.enum !== undefined &&
|
|
36
|
-
(ir.type === "string"
|
|
36
|
+
(ir.type === "string"
|
|
37
|
+
? stringValues(ir.enum).length > 0
|
|
38
|
+
: ir.type === "integer" && integerValues(ir.enum).length > 0);
|
|
37
39
|
/** A const's Rust type: its value's, a declared `number` making an integral value f64. */
|
|
38
40
|
function constType({ type, value }) {
|
|
39
41
|
if (typeof value === "number")
|
|
@@ -70,7 +72,7 @@ const USES = {
|
|
|
70
72
|
ref: refUse,
|
|
71
73
|
scalar: (ir, at) => (isEnum(ir) ? hoist(ir, at) : SCALARS[ir.type]),
|
|
72
74
|
tuple: () => `Vec<${VALUE}>`,
|
|
73
|
-
|
|
75
|
+
// a union in use position is any JSON value; a component union is declared as an enum
|
|
74
76
|
union: () => VALUE,
|
|
75
77
|
unknown: () => VALUE,
|
|
76
78
|
};
|
|
@@ -83,6 +85,14 @@ export function rustTypeOf(ir, at) {
|
|
|
83
85
|
}
|
|
84
86
|
/** The use positions inside the declaration of `name`. */
|
|
85
87
|
const memberOf = (name, at) => (schema, fieldName) => use(schema, { ...at, depth: 0, fieldName, parentName: name, self: name });
|
|
88
|
+
/** What the union declared as `name` reaches: its members' use positions and the hoist of its inline variants. */
|
|
89
|
+
const unionScope = (name, at) => ({
|
|
90
|
+
declare: (schema, key, base) => rustHoisted(schema, at, key, base),
|
|
91
|
+
member: memberOf(name, at),
|
|
92
|
+
names: at.names,
|
|
93
|
+
});
|
|
94
|
+
/** Each value the keyed union `union`, declared as `name`, selects a variant by, with that variant and its payload type. */
|
|
95
|
+
export const rustUnionVariants = (name, union, at) => unionVariants(name, union, unionScope(name, at));
|
|
86
96
|
/** The top-level declaration of the type `name` (a Rust identifier already) for `ir`. */
|
|
87
97
|
export function rustTopLevel(name, ir, at) {
|
|
88
98
|
const member = memberOf(name, at);
|
|
@@ -94,12 +104,10 @@ export function rustTopLevel(name, ir, at) {
|
|
|
94
104
|
return [DERIVE, `pub struct ${name}(pub ${constType(ir)});`].join("\n");
|
|
95
105
|
if (ir.kind === "allOf")
|
|
96
106
|
return allOfDecl(name, ir, member, at.names.ref);
|
|
97
|
-
|
|
107
|
+
// a closed object without fields is a struct too: `{}` on the wire, where a map alias would admit any key
|
|
98
108
|
if (ir.kind === "object" && (ir.fields.length > 0 || ir.additional === false))
|
|
99
109
|
return objectDecl(name, ir, member);
|
|
100
|
-
if (ir.kind === "union" && ir.variants.length > 0)
|
|
101
|
-
|
|
102
|
-
return unionDecl(name, ir, { declare: variant, member, names: at.names });
|
|
103
|
-
}
|
|
110
|
+
if (ir.kind === "union" && ir.variants.length > 0)
|
|
111
|
+
return unionDecl(name, ir, unionScope(name, at));
|
|
104
112
|
return `pub type ${name} = ${member(ir, "Value")};`;
|
|
105
113
|
}
|
package/dist/emit/rust/ws.d.ts
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A WebSocket operation's answer (contract 20 §2.0, §2.2): `TypedWebSocket
|
|
2
|
+
* A WebSocket operation's answer (contract 20 §2.0, §2.2): `TypedWebSocket<In, Out>`, dialed offering the Opts'
|
|
3
3
|
* `protocols`, its Opts' `reconnect_token` sent as one query param only when set and non-empty; a declared
|
|
4
|
-
* `reconnect_token` query param is folded into that field (Fd3).
|
|
4
|
+
* `reconnect_token` query param is folded into that field (Fd3). `In` is what the server sends (`send`), `Out` what
|
|
5
|
+
* it receives (`receive`), an inline union hoisted as `<Op>Send` or `<Op>Receive`; an op without them keeps the
|
|
6
|
+
* defaults, its frames as bytes and any JSON value sent. A read side keyed on one field (D9) gets an `on_<value>` per
|
|
7
|
+
* member, an inherent impl in types.rs written once per read type, except a value whose method a handler holds.
|
|
5
8
|
*/
|
|
9
|
+
import type { IRSchema } from "../../ir/model.ts";
|
|
10
|
+
import { type SdkOp } from "../../ir/sdk-model.ts";
|
|
6
11
|
import type { OptsField, StreamAnswer } from "./sdk-opts.ts";
|
|
7
|
-
|
|
8
|
-
export declare const RECONNECT_TOKEN: {
|
|
9
|
-
ident: string;
|
|
10
|
-
type: string;
|
|
11
|
-
};
|
|
12
|
-
/** The subprotocols a WebSocket or realtime dial offers. */
|
|
13
|
-
export declare const PROTOCOLS: {
|
|
14
|
-
doc: string;
|
|
15
|
-
ident: string;
|
|
16
|
-
type: string;
|
|
17
|
-
};
|
|
12
|
+
import { type RustTypeContext } from "./types.ts";
|
|
18
13
|
/** Whether a declared param is the `reconnect_token` query param, the resume channel a socket dial sends. */
|
|
19
14
|
export declare const isReconnectToken: (param: string, where: OptsField["in"]) => boolean;
|
|
20
|
-
/**
|
|
21
|
-
export declare
|
|
15
|
+
/** One direction of `op`'s messages as its Rust type: an inline union is declared as `<Op><side>`. */
|
|
16
|
+
export declare function messageType(op: SdkOp, schema: IRSchema, side: "Receive" | "Send", at: RustTypeContext): string;
|
|
17
|
+
/**
|
|
18
|
+
* The `on_<value>` methods of `<base><read, Out>`, `read` the keyed `schema`, declared once in `at`: each takes the
|
|
19
|
+
* messages whose key is that value; a value whose method one of `handlers` names gets none.
|
|
20
|
+
*/
|
|
21
|
+
export declare function valueHandlers(base: string, handlers: readonly string[], read: {
|
|
22
|
+
readonly schema: IRSchema;
|
|
23
|
+
readonly type: string;
|
|
24
|
+
}, at: RustTypeContext): void;
|
|
25
|
+
/** The type params of a socket reading `read` and sending `write`, the defaults left out. */
|
|
26
|
+
export declare const typeParams: (read: string | undefined, write: string | undefined, untyped: string) => string;
|
|
27
|
+
/** The WebSocket operation `op`'s answer, its message types hoisted into `at`. */
|
|
28
|
+
export declare function wsAnswer(op: SdkOp, at: RustTypeContext): StreamAnswer;
|