@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
|
@@ -4,7 +4,7 @@ import { csIdentifier, csTypeName, NameScope } from "../shared/lang.js";
|
|
|
4
4
|
import { mirrorNotice } from "../shared/mirror.js";
|
|
5
5
|
import { docLines } from "./sdk-doc.js";
|
|
6
6
|
import { csMethod } from "./sdk-method.js";
|
|
7
|
-
|
|
7
|
+
// every class's own members, and the names a method body spells in an expression (a property would shadow them)
|
|
8
8
|
const CLASS_MEMBERS = [
|
|
9
9
|
"Arg",
|
|
10
10
|
"Body",
|
|
@@ -20,7 +20,7 @@ const CLASS_MEMBERS = [
|
|
|
20
20
|
"Transport",
|
|
21
21
|
"TransportOptions",
|
|
22
22
|
];
|
|
23
|
-
|
|
23
|
+
// the client's mirror property, `client.Safe` (shared/mirror.ts's name as C# spells it)
|
|
24
24
|
const SAFE = "Safe";
|
|
25
25
|
/** A namespace's class name before it is claimed: its path PascalCase, then `Resource`. */
|
|
26
26
|
const baseName = (path) => `${path.map(csTypeName).join("")}Resource`;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { type Shipped } from "../shared/metadata.ts";
|
|
2
|
-
/** The one target framework: the pinned SDK's major (R1). */
|
|
3
|
-
export declare const TARGET_FRAMEWORK = "net10.0";
|
|
4
2
|
/** What nuget.org shows about the package, each part the caller gave, validated. */
|
|
5
3
|
export type CSharpMetadata = {
|
|
6
|
-
readonly description?: string;
|
|
7
|
-
readonly authors?: string;
|
|
8
|
-
readonly license?: string;
|
|
9
|
-
readonly homepage?: string;
|
|
10
|
-
readonly repository?: string;
|
|
11
|
-
readonly copyright?: string;
|
|
4
|
+
readonly description?: string | undefined;
|
|
5
|
+
readonly authors?: string | undefined;
|
|
6
|
+
readonly license?: string | undefined;
|
|
7
|
+
readonly homepage?: string | undefined;
|
|
8
|
+
readonly repository?: string | undefined;
|
|
9
|
+
readonly copyright?: string | undefined;
|
|
12
10
|
/** comma separated, as the CLI gives it */
|
|
13
|
-
readonly tags?: string;
|
|
11
|
+
readonly tags?: string | undefined;
|
|
14
12
|
};
|
|
15
13
|
/** The package's identity, each part validated, its metadata, and the files it ships beside the code. */
|
|
16
14
|
export type CSharpPackage = {
|
|
@@ -12,10 +12,10 @@ import { isCsReserved } from "../shared/lang.js";
|
|
|
12
12
|
import { checked, HTTPS_URL, LICENSE, README, SPDX_EXPRESSION, TEXT } from "../shared/metadata.js";
|
|
13
13
|
import { BCL, RUNTIME_BCL } from "./types-names.js";
|
|
14
14
|
/** The one target framework: the pinned SDK's major (R1). */
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const TARGET_FRAMEWORK = "net10.0";
|
|
16
|
+
// authors: names joined by commas, each with a character other than a space, none with a control character
|
|
17
17
|
const AUTHORS = /^(?=[^\p{Cc}]{1,4000}$)[^,]*[^,\s][^,]*(?:,[^,]*[^,\s][^,]*)*$/u;
|
|
18
|
-
|
|
18
|
+
// tags: words joined by commas, none holding a space or a `;`, which NuGet splits PackageTags on
|
|
19
19
|
const TAGS = /^(?=.{1,4000}$)[^\s,;\p{Cc}\p{Cs}]{1,50}(?:,[^\s,;\p{Cc}\p{Cs}]{1,50})*$/u;
|
|
20
20
|
/** The metadata options, each validated: the description and authors as text, the license as SPDX, the URLs https. */
|
|
21
21
|
export function packageMetadata(options) {
|
|
@@ -29,11 +29,11 @@ export function packageMetadata(options) {
|
|
|
29
29
|
tags: checked("tags", options.tags, TAGS),
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
// the characters MSBuild expands or splits on in a property, written as its own %XX escapes, which it reads back
|
|
33
33
|
const MSBUILD_SPECIAL = /[%*?@$();']/g;
|
|
34
34
|
/** `text` as a `.csproj` property value: MSBuild's escapes first, then XML's. */
|
|
35
35
|
const propertyText = (text) => text
|
|
36
|
-
.
|
|
36
|
+
.replaceAll(MSBUILD_SPECIAL, (ch) => `%${ch.charCodeAt(0).toString(16).toUpperCase()}`)
|
|
37
37
|
.replaceAll("&", "&")
|
|
38
38
|
.replaceAll("<", "<")
|
|
39
39
|
.replaceAll(">", ">");
|
|
@@ -50,17 +50,17 @@ function metadataLines(metadata) {
|
|
|
50
50
|
const lines = entries.flatMap(([element, value]) => value === undefined ? [] : [` <${element}>${propertyText(value)}</${element}>\n`]);
|
|
51
51
|
if (metadata?.repository !== undefined)
|
|
52
52
|
lines.push(" <RepositoryType>git</RepositoryType>\n");
|
|
53
|
-
|
|
53
|
+
// each tag escaped on its own: the `;` between them is the list's, which MSBuild hands to NuGet as written
|
|
54
54
|
const tags = metadata?.tags?.split(",").map(propertyText).join(";");
|
|
55
55
|
if (tags !== undefined)
|
|
56
56
|
lines.push(` <PackageTags>${tags}</PackageTags>\n`);
|
|
57
57
|
return lines.join("");
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
// NuGet's id rule; a namespace segment is an identifier; a client is a PascalCase type
|
|
60
60
|
const PACKAGE_ID = /^[A-Za-z0-9_]+(?:[.-][A-Za-z0-9_]+)*$/;
|
|
61
61
|
const SEGMENT = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
62
62
|
const CLIENT_NAME = /^[A-Z][A-Za-z0-9_]*$/;
|
|
63
|
-
|
|
63
|
+
// SemVer 2 (semver.org's recommended pattern), as Rust's sdk-cargo.ts takes it
|
|
64
64
|
const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
65
65
|
const refuse = (option, value) => {
|
|
66
66
|
throw new Error(`Invalid ${option}: ${JSON.stringify(value)}`);
|
|
@@ -70,14 +70,14 @@ export const validatePackageId = (value) => PACKAGE_ID.test(value) && value.leng
|
|
|
70
70
|
/** A namespace: dot-separated identifiers, none a keyword or a BCL type the sources spell, not under `System`. */
|
|
71
71
|
export function validateRootNamespace(value) {
|
|
72
72
|
const segments = value.split(".");
|
|
73
|
-
|
|
73
|
+
// a segment naming a BCL type the sources spell unqualified turns that spelling into the namespace (CS0118)
|
|
74
74
|
const bcl = new Set([...Object.values(BCL).flat(), ...RUNTIME_BCL]);
|
|
75
75
|
const valid = segments.every((s) => SEGMENT.test(s) && !isCsReserved(s) && !bcl.has(s));
|
|
76
76
|
return valid && segments[0] !== "System" ? value : refuse("rootNamespace", value);
|
|
77
77
|
}
|
|
78
78
|
/** A client class name: PascalCase. */
|
|
79
79
|
export const validateClientName = (value) => CLIENT_NAME.test(value) ? value : refuse("clientName", value);
|
|
80
|
-
|
|
80
|
+
// MSBuild derives the assembly version from major.minor.patch, each part at most 65534 (CS7034 past it)
|
|
81
81
|
const ASSEMBLY_PART_MAX = 65534;
|
|
82
82
|
/** A SemVer 2 version whose major, minor and patch each fit an assembly version part. */
|
|
83
83
|
export function validateVersion(value) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { csDocLines } from "../shared/escape.js";
|
|
2
|
-
|
|
2
|
+
// the runtime's status classes (runtime/csharp/Errors.cs, Python's statuses); any other status throws UnexpectedStatusException
|
|
3
3
|
const STATUS_EXCEPTIONS = {
|
|
4
4
|
400: "BadRequestException",
|
|
5
5
|
401: "UnauthorizedException",
|
|
@@ -21,6 +21,5 @@ export type CsMethod = {
|
|
|
21
21
|
readonly types: readonly string[];
|
|
22
22
|
readonly plan: Omit<CSharpCallPlan, "accessors">;
|
|
23
23
|
};
|
|
24
|
-
export declare const METHOD_LOCALS: string[];
|
|
25
24
|
/** The method of `op` named `name`, its `Operation` in the private field `field`. */
|
|
26
25
|
export declare function csMethod(op: SdkOp, name: string, field: string, env: MethodEnv): CsMethod;
|
|
@@ -7,9 +7,9 @@ import { methodDoc } from "./sdk-doc.js";
|
|
|
7
7
|
import { sseStream } from "./sse.js";
|
|
8
8
|
import { csTypeOf } from "./types.js";
|
|
9
9
|
import { wsStream } from "./ws.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
// the method's own parameters: a spec param that takes one of these names is claimed as `…2`
|
|
11
|
+
const METHOD_LOCALS = ["body", "cancellationToken", "headersInto", "idempotencyKey", "options"];
|
|
12
|
+
// each stream's answer, its own fields, and the declared params its resume channels carry (the fold)
|
|
13
13
|
const STREAMS = {
|
|
14
14
|
realtime: realtimeStream,
|
|
15
15
|
sse: sseStream,
|
|
@@ -44,7 +44,10 @@ function paramsOf(op, scope, at, stream) {
|
|
|
44
44
|
/** A parameter: its declaration, then its name. */
|
|
45
45
|
const one = (decl, ident) => ({ decl: `${decl} ${ident}`, ident });
|
|
46
46
|
/** An optional parameter, defaulting to `fallback`. */
|
|
47
|
-
const optional = (decl, ident, fallback = "null") => ({
|
|
47
|
+
const optional = (decl, ident, fallback = "null") => ({
|
|
48
|
+
decl: `${decl} ${ident} = ${fallback}`,
|
|
49
|
+
ident,
|
|
50
|
+
});
|
|
48
51
|
/**
|
|
49
52
|
* The parameters, each its declaration and its name, in C#4's order, the response-header holder after the
|
|
50
53
|
* idempotency key, then a stream's fields.
|
|
@@ -86,12 +89,14 @@ function call({ body, headers, keyed, params, path }, spell) {
|
|
|
86
89
|
...(headers === null ? [] : ["headersInto is null ? null : headersInto.Read"]),
|
|
87
90
|
].join(", ");
|
|
88
91
|
}
|
|
89
|
-
/** The method's lines: its docs (its error statuses' exceptions), its signature, the one call into the transport (a stream's arguments after the `Call`). */
|
|
92
|
+
/** The method's lines: its docs (its error statuses' exceptions), its signature, the one call into the transport (a stream's arguments, then its answer's, after the `Call`). */
|
|
90
93
|
function methodLines(parts, spell) {
|
|
91
94
|
const { answer, stream } = parts;
|
|
92
95
|
const [returns, run] = answer.render(spell);
|
|
93
96
|
const args = [
|
|
94
97
|
...(stream?.args ?? []),
|
|
98
|
+
...(answer.args ?? []),
|
|
99
|
+
...(answer.infos ?? []).map(spell.info),
|
|
95
100
|
...(answer.type === null ? [] : [spell.info(answer.type)]),
|
|
96
101
|
"cancellationToken",
|
|
97
102
|
];
|
|
@@ -101,7 +106,7 @@ function methodLines(parts, spell) {
|
|
|
101
106
|
` _t.${run}(${parts.field}, new(${call(parts, spell)}), ${args.join(", ")});`,
|
|
102
107
|
];
|
|
103
108
|
}
|
|
104
|
-
|
|
109
|
+
// an SSE twin's <returns>: the open stream is its Ok, an error status opening it its Err
|
|
105
110
|
const SAFE_STREAM = "Ok with the open stream, or Err with the opening answer's error status. No timeout bounds it after that, and a drop or an event that does not decode is the stream's own exception; the token, leaving await foreach or DisposeAsync ends it.";
|
|
106
111
|
/**
|
|
107
112
|
* The `client.Safe` twin's lines: the signature restated, answering `Task<Result<T>>` (`Task<Result>` for no body)
|
|
@@ -112,12 +117,13 @@ function twinLines(parts, spell) {
|
|
|
112
117
|
const [returns] = parts.answer.render(spell);
|
|
113
118
|
const sig = `${signature(parts, spell).join(", ")})`;
|
|
114
119
|
const idents = parameters(parts, spell).map(({ ident }) => ident);
|
|
115
|
-
if (parts.op.stream === "ws" || parts.op.stream === "realtime")
|
|
120
|
+
if (parts.op.stream === "ws" || parts.op.stream === "realtime") {
|
|
116
121
|
return [
|
|
117
122
|
...methodDoc(parts.op, true, parts.stream?.returns),
|
|
118
123
|
` public ${returns} ${parts.name}(${sig} =>`,
|
|
119
124
|
` _n.${parts.name}(${idents.join(", ")});`,
|
|
120
125
|
];
|
|
126
|
+
}
|
|
121
127
|
const safe = returns === "Task" ? "Task<Result>" : `Task<Result<${returns.slice("Task<".length, -1)}>>`;
|
|
122
128
|
const sent = idents.map((ident) => (ident === "options" ? "_o" : ident));
|
|
123
129
|
return [
|
|
@@ -182,6 +188,11 @@ export function csMethod(op, name, field, env) {
|
|
|
182
188
|
lines: (spell) => methodLines(parts, spell),
|
|
183
189
|
plan: planOf(parts),
|
|
184
190
|
twin: (spell) => twinLines(parts, spell),
|
|
185
|
-
types: [
|
|
191
|
+
types: [
|
|
192
|
+
...params.map(({ type }) => type),
|
|
193
|
+
...body.types,
|
|
194
|
+
...(answer.infos ?? []),
|
|
195
|
+
...(answer.type === null ? [] : [answer.type]),
|
|
196
|
+
],
|
|
186
197
|
};
|
|
187
198
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/emit/csharp/sdk.js
CHANGED
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
import { toIR } from "../../ir/build.js";
|
|
13
13
|
import { sdkModel } from "../../ir/sdk-model.js";
|
|
14
14
|
import { compareCodeUnits, csTypeName } from "../shared/lang.js";
|
|
15
|
+
import { packageOn } from "../shared/metadata.js";
|
|
15
16
|
import { renameNotice } from "../shared/mirror.js";
|
|
16
17
|
import { csharpErrorKeys } from "./errors.js";
|
|
17
18
|
import { jsonContext, runtimeOf, strictConverters, typeInfoNames } from "./json.js";
|
|
18
19
|
import { clientDecls } from "./sdk-client.js";
|
|
19
20
|
import { csproj, EDITORCONFIG, packageMetadata, validateClientName, validatePackageId, validateRootNamespace, validateVersion, } from "./sdk-csproj.js";
|
|
20
|
-
import { packageOn } from "../shared/metadata.js";
|
|
21
21
|
import { docLines } from "./sdk-doc.js";
|
|
22
22
|
import { runtimeFiles } from "./transport.js";
|
|
23
23
|
import { usings } from "./types-names.js";
|
|
24
24
|
import { csTopLevel, csTypeContext, declares } from "./types.js";
|
|
25
|
-
|
|
25
|
+
// the marker every .cs file opens with; never `<auto-generated`, which the format gate and the analyzers skip (Q4)
|
|
26
26
|
const MARKER = "// @generated by clients. DO NOT EDIT.";
|
|
27
27
|
/** The options validated, each default filled in, and the client's and its context's class names. */
|
|
28
28
|
function identity(options) {
|
|
@@ -60,7 +60,7 @@ function emitCSharp(document, options, shipped) {
|
|
|
60
60
|
const at = csTypeContext(ir, [id.client, id.context]);
|
|
61
61
|
const components = componentDecls(ir, at);
|
|
62
62
|
const errorKey = csharpErrorKeys(model, at);
|
|
63
|
-
|
|
63
|
+
// every component emitted under another name is noticed, as the mirror's rename is
|
|
64
64
|
const notices = [...at.names.renamed].map(([name, renamed]) => renameNotice("csharp", {
|
|
65
65
|
because: `"${csTypeName(name)}" is a name the SDK's runtime, the BCL or another declaration holds`,
|
|
66
66
|
name,
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An SSE operation's answer (contract 50 §2, Fd1, Fd4): `Task<EventStream<T>>` through `EventsAsync`, `T` the
|
|
3
|
-
* declared event schema's type, or `Task<EventStream<string>>` through `TextEventsAsync` for untyped events, opened
|
|
4
|
-
* by awaiting the method (G15). Its one field, `lastEventId`, is sent as Last-Event-ID only when set and non-empty;
|
|
5
|
-
* a declared Last-Event-ID header param is folded into that field.
|
|
6
|
-
*/
|
|
7
1
|
import { type CsStream } from "./sdk-answer.ts";
|
|
8
|
-
/** The header the SSE and realtime dials resume an event stream with. */
|
|
9
|
-
export declare const LAST_EVENT_ID = "Last-Event-ID";
|
|
10
|
-
/** The resume cursor's event id, which the SSE and realtime methods take. */
|
|
11
|
-
export declare const LAST_EVENT_ID_FIELD: {
|
|
12
|
-
ident: string;
|
|
13
|
-
type: string;
|
|
14
|
-
};
|
|
15
2
|
/** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
|
|
16
3
|
export declare const isLastEventIdHeader: (name: string, where: string) => boolean;
|
|
17
4
|
/** The SSE operation's answer, its one field and its `<returns>` text. */
|
package/dist/emit/csharp/sse.js
CHANGED
|
@@ -1,24 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* by awaiting the method (G15). Its one field, `lastEventId`, is sent as Last-Event-ID only when set and non-empty;
|
|
5
|
-
* a declared Last-Event-ID header param is folded into that field.
|
|
6
|
-
*/
|
|
1
|
+
import { isJsonEventData, sseEvents } from "../../ir/sdk-model.js";
|
|
2
|
+
import { csString } from "../shared/escape.js";
|
|
3
|
+
import { csTypeName, NameScope } from "../shared/lang.js";
|
|
7
4
|
import { eventType } from "./sdk-answer.js";
|
|
5
|
+
import { docLines } from "./sdk-doc.js";
|
|
6
|
+
import { csTypeOf } from "./types.js";
|
|
8
7
|
/** The header the SSE and realtime dials resume an event stream with. */
|
|
9
|
-
|
|
10
|
-
/** The resume cursor's event id, which the SSE
|
|
11
|
-
|
|
8
|
+
const LAST_EVENT_ID = "Last-Event-ID";
|
|
9
|
+
/** The resume cursor's event id, which the SSE method takes. */
|
|
10
|
+
const LAST_EVENT_ID_FIELD = { ident: "lastEventId", type: "string?" };
|
|
12
11
|
/** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
|
|
13
12
|
export const isLastEventIdHeader = (name, where) => where === "header" && name.toLowerCase() === LAST_EVENT_ID.toLowerCase();
|
|
13
|
+
// the names a nested record never takes: the members, and the types the decode spells
|
|
14
|
+
const TAKEN = [
|
|
15
|
+
// a nested record's members
|
|
16
|
+
"Data",
|
|
17
|
+
"Event",
|
|
18
|
+
"Id",
|
|
19
|
+
"Retry",
|
|
20
|
+
"Of",
|
|
21
|
+
// every record's
|
|
22
|
+
"Deconstruct",
|
|
23
|
+
"EqualityContract",
|
|
24
|
+
"Equals",
|
|
25
|
+
"Finalize",
|
|
26
|
+
"GetHashCode",
|
|
27
|
+
"GetType",
|
|
28
|
+
"MemberwiseClone",
|
|
29
|
+
"PrintMembers",
|
|
30
|
+
"ToString",
|
|
31
|
+
// the decode's
|
|
32
|
+
"JsonSerializerOptions",
|
|
33
|
+
"JsonTypeInfo",
|
|
34
|
+
"SseEvent",
|
|
35
|
+
"TimeSpan",
|
|
36
|
+
"Transport",
|
|
37
|
+
];
|
|
38
|
+
/** The decode arm of `nested`: its data from JSON through the context, or as sent. */
|
|
39
|
+
const armOf = ({ data, event, json, record }) => {
|
|
40
|
+
const value = json
|
|
41
|
+
? `Transport.EventData(e.Data, (JsonTypeInfo<${data}>)options.GetTypeInfo(typeof(${data})))`
|
|
42
|
+
: "e.Data";
|
|
43
|
+
return ` ${csString(event)} => new ${record}(${value}, ${csString(event)}, e.Id, e.Retry),`;
|
|
44
|
+
};
|
|
45
|
+
/** A nested record's declaration: its data, then the event's name, id and retry. */
|
|
46
|
+
const recordOf = (record, data, name) => ` public sealed record ${record}(${data} Data, string Event, string? Id, TimeSpan? Retry) : ${name};`;
|
|
47
|
+
/** `<Op>Event`, hoisted into `env.at.decls` (never listed) with its nested records and its decode; its name. */
|
|
48
|
+
function namedEvents(op, events, env) {
|
|
49
|
+
const { at } = env;
|
|
50
|
+
const name = at.names.claim(`${csTypeName(op.id)}Event`);
|
|
51
|
+
at.unlisted.add(name);
|
|
52
|
+
const typed = events.map(({ data, name: event }) => {
|
|
53
|
+
const json = isJsonEventData(data, at.names.resolve);
|
|
54
|
+
// the decode throws on null, so the data is never null
|
|
55
|
+
const type = json ? csTypeOf(data, { ...at, fieldName: event, parentName: op.id }).replace(/\?$/, "") : "string";
|
|
56
|
+
if (json)
|
|
57
|
+
at.serialized.add(type);
|
|
58
|
+
return { data: type, event, json };
|
|
59
|
+
});
|
|
60
|
+
// a type a record's data spells would be shadowed by a nested record of its name
|
|
61
|
+
const spelled = typed.flatMap(({ data }) => data.split(/\W+/).filter((word) => word !== ""));
|
|
62
|
+
const reserved = new Set([...TAKEN, ...spelled, name, "Unknown"]);
|
|
63
|
+
const scope = new NameScope(reserved);
|
|
64
|
+
const nested = typed.map((t) => {
|
|
65
|
+
const base = csTypeName(t.event);
|
|
66
|
+
return { ...t, record: scope.claim(reserved.has(base) ? `${base}Event` : base) };
|
|
67
|
+
});
|
|
68
|
+
const list = nested.map(({ record }) => record).join(", ");
|
|
69
|
+
at.decls.set(name, [
|
|
70
|
+
...docLines("summary", `One event of ${op.id}: ${list}, or Unknown for a name the operation does not declare, its data as sent. An is match reads the event's data.`),
|
|
71
|
+
`public abstract record ${name}`,
|
|
72
|
+
"{",
|
|
73
|
+
` private ${name}()`,
|
|
74
|
+
" {",
|
|
75
|
+
" }",
|
|
76
|
+
"",
|
|
77
|
+
...nested.map(({ data, record }) => recordOf(record, data, name)),
|
|
78
|
+
recordOf("Unknown", "string", name),
|
|
79
|
+
"",
|
|
80
|
+
` internal static ${name} Of(SseEvent<string> e, JsonSerializerOptions options) =>`,
|
|
81
|
+
' (e.Event is null or "" ? "message" : e.Event) switch',
|
|
82
|
+
" {",
|
|
83
|
+
...nested.map(armOf),
|
|
84
|
+
" var named => new Unknown(e.Data, named, e.Id, e.Retry),",
|
|
85
|
+
" };",
|
|
86
|
+
"}",
|
|
87
|
+
].join("\n"));
|
|
88
|
+
return name;
|
|
89
|
+
}
|
|
14
90
|
/** The SSE operation's answer, its one field and its `<returns>` text. */
|
|
15
91
|
export const sseStream = {
|
|
16
92
|
answer: (op, env) => {
|
|
93
|
+
const named = sseEvents(op.ir);
|
|
94
|
+
if (named !== undefined) {
|
|
95
|
+
const name = namedEvents(op, named, env);
|
|
96
|
+
return { args: [`${name}.Of`], render: () => [`Task<EventStream<${name}>>`, "NamedEventsAsync"], type: null };
|
|
97
|
+
}
|
|
17
98
|
const type = op.events === undefined ? null : eventType(op.events, op, env);
|
|
18
99
|
return {
|
|
19
100
|
render: (spell) => type === null
|
|
20
|
-
? ["Task<EventStream<string
|
|
21
|
-
: [`Task<EventStream<${spell.runtime(type)}
|
|
101
|
+
? ["Task<EventStream<SseEvent<string>>>", "TextEventsAsync"]
|
|
102
|
+
: [`Task<EventStream<SseEvent<${spell.runtime(type)}>>>`, "EventsAsync"],
|
|
22
103
|
type,
|
|
23
104
|
};
|
|
24
105
|
},
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* and nowhere else (the F8 mutation target), each emitted as committed but for its one `namespace Http.Runtime;`
|
|
4
4
|
* line, which becomes the SDK's own namespace (Fb2), so `using <RootNamespace>;` reaches the client, the config,
|
|
5
5
|
* the exceptions and the models alike. Every API ships the core, SSE among it; a WebSocket or realtime API adds the
|
|
6
|
-
* socket and its
|
|
6
|
+
* socket, its dial and its typed face, and a realtime API the adapters and the connection (contract 50 §2).
|
|
7
7
|
*/
|
|
8
8
|
import { readFileSync } from "node:fs";
|
|
9
9
|
import { compareCodeUnits } from "../shared/lang.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
// every SDK: the HTTP runtime (config, errors and envelopes, bodies, auth, hooks, log, redirects and the strip
|
|
11
|
+
// handler, stale tracking, the exchange, its wire readers and the transport), the safe result, the strict JSON
|
|
12
|
+
// converters, the encoders, and the SSE parser and its EventStream
|
|
13
13
|
const CORE = [
|
|
14
14
|
"Auth",
|
|
15
15
|
"Body",
|
|
@@ -33,9 +33,9 @@ const CORE = [
|
|
|
33
33
|
"Transport",
|
|
34
34
|
"Wire",
|
|
35
35
|
];
|
|
36
|
-
|
|
37
|
-
const WS = ["Ws", "WsDial"];
|
|
38
|
-
|
|
36
|
+
// a WebSocket or realtime operation: the socket, its own HTTP/1.1 upgrade, and the socket of declared messages
|
|
37
|
+
const WS = ["Ws", "WsDial", "WsTyped"];
|
|
38
|
+
// a realtime operation: the adapters, the resumable connection and its loop, and the three transports
|
|
39
39
|
const REALTIME = [
|
|
40
40
|
"Adapters",
|
|
41
41
|
"Realtime",
|
|
@@ -44,9 +44,9 @@ const REALTIME = [
|
|
|
44
44
|
"TransportSse",
|
|
45
45
|
"TransportWs",
|
|
46
46
|
];
|
|
47
|
-
|
|
47
|
+
// the one line each committed file holds, swapped for the SDK's namespace
|
|
48
48
|
const NAMESPACE = /^namespace Http\.Runtime;$/m;
|
|
49
|
-
|
|
49
|
+
// a top-level type at column 0: its modifiers, its kind, its name (type parameters after it are not part of it)
|
|
50
50
|
const TOP_LEVEL = /^(?:(?:public|internal|file|sealed|abstract|static|readonly|partial|unsafe)\s+)*(?:record\s+struct|record\s+class|class|record|struct|enum|interface)\s+([A-Za-z_]\w*)/gm;
|
|
51
51
|
/** The runtime file names an SDK with `features` ships, `.cs` included, in code-unit order. */
|
|
52
52
|
export function runtimeFileNames(features) {
|
|
@@ -59,5 +59,7 @@ function intEnumDecl(name, values, at) {
|
|
|
59
59
|
/** The enum `name` of the string or integer enum `ir`. */
|
|
60
60
|
export function enumDecl(name, ir, at) {
|
|
61
61
|
const values = enumValues(ir);
|
|
62
|
-
return ir.type === "string"
|
|
62
|
+
return ir.type === "string"
|
|
63
|
+
? stringEnumDecl(name, values, at)
|
|
64
|
+
: intEnumDecl(name, values, at);
|
|
63
65
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C# message types (D9, D17): one direction of a socket's declared messages as the type its socket reads or sends.
|
|
3
|
+
* A union keyed on one field (`dispatchOf`) is `<Op>Inbound` (what the server sends, the read side) or
|
|
4
|
+
* `<Op>Outbound` (what it receives, the send side), declared beside the body union, which does not change: an
|
|
5
|
+
* abstract record with a private constructor and one nested sealed record per member in the order declared, each
|
|
6
|
+
* wrapping its variant record as `Value`; the read side adds `Unknown(JsonElement Raw)` for a value the op does not
|
|
7
|
+
* declare, the send side an implicit conversion from each variant record. Its converter reads the discriminator and
|
|
8
|
+
* decodes the variant through the context (AOT-safe). A nested name that is one of the record's members, a type it
|
|
9
|
+
* spells or the enclosing type takes the suffix `Message`. Any other direction is its declared type itself, an
|
|
10
|
+
* inline schema hoisted as `<Op><Side>`. Each keyed read side gets an `On<Value>` extension per member, in a static
|
|
11
|
+
* class beside it, for the socket or the connection that reads it, except a member whose value names one of that
|
|
12
|
+
* reader's own events.
|
|
13
|
+
*/
|
|
14
|
+
import type { IRSchema } from "../../ir/model.ts";
|
|
15
|
+
import { type SdkOp } from "../../ir/sdk-model.ts";
|
|
16
|
+
import { type CsTypeContext } from "./types.ts";
|
|
17
|
+
/** Which way a direction goes: the server's `send` is the client's read, its `receive` the client's send. */
|
|
18
|
+
export type Side = "Receive" | "Send";
|
|
19
|
+
/** One keyed member as a nested record: the value that selects it, its record, and its variant's type. */
|
|
20
|
+
type Nested = {
|
|
21
|
+
readonly value: string;
|
|
22
|
+
readonly record: string;
|
|
23
|
+
readonly type: string;
|
|
24
|
+
};
|
|
25
|
+
/** One direction's C# type, and a keyed one's key and nested records in the order declared. */
|
|
26
|
+
export type MessageType = {
|
|
27
|
+
readonly type: string;
|
|
28
|
+
readonly keyed?: {
|
|
29
|
+
readonly key: string;
|
|
30
|
+
readonly nested: readonly Nested[];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/** One direction of `op`'s messages as its C# type: a keyed union's hierarchy, else the declared type itself. */
|
|
34
|
+
export declare function messageType(op: SdkOp, schema: IRSchema, side: Side, at: CsTypeContext): MessageType;
|
|
35
|
+
/** What reads a keyed side: its generic type, the name its extensions give their `this` param, and its own events. */
|
|
36
|
+
export type Reader = {
|
|
37
|
+
readonly base: string;
|
|
38
|
+
readonly receiver: string;
|
|
39
|
+
readonly handlers: readonly string[];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The `On<Value>` extensions of `<base><read, TOut>` (a socket or a connection, `reader`), `read` a keyed read side,
|
|
43
|
+
* declared beside it in `at`: each takes the variant of the member its value selects, matched inside the reader's
|
|
44
|
+
* `Message`; a value whose method one of the reader's `handlers` names gets none.
|
|
45
|
+
*/
|
|
46
|
+
export declare function valueHandlers({ base, handlers, receiver }: Reader, read: MessageType, at: CsTypeContext): void;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { dispatchOf } from "../../ir/sdk-model.js";
|
|
2
|
+
import { csString } from "../shared/escape.js";
|
|
3
|
+
import { csTypeName, NameScope } from "../shared/lang.js";
|
|
4
|
+
import { docLines } from "./sdk-doc.js";
|
|
5
|
+
import { csTypeOf } from "./types.js";
|
|
6
|
+
// the names a nested record never takes: its members, every record's, and the types its converter spells
|
|
7
|
+
const TAKEN = [
|
|
8
|
+
"Value",
|
|
9
|
+
"Raw",
|
|
10
|
+
"Unknown",
|
|
11
|
+
"Clone",
|
|
12
|
+
"Deconstruct",
|
|
13
|
+
"EqualityContract",
|
|
14
|
+
"Equals",
|
|
15
|
+
"Finalize",
|
|
16
|
+
"GetHashCode",
|
|
17
|
+
"GetType",
|
|
18
|
+
"MemberwiseClone",
|
|
19
|
+
"PrintMembers",
|
|
20
|
+
"ToString",
|
|
21
|
+
"JsonElement",
|
|
22
|
+
];
|
|
23
|
+
/** `JsonTypeInfo<T>` of `type` from the converter's options. */
|
|
24
|
+
const info = (type) => `(JsonTypeInfo<${type}>)options.GetTypeInfo(typeof(${type}))`;
|
|
25
|
+
/** Each member of `dispatch` once per value, its variant typed at `<parent><Value>`, its nested name claimed. */
|
|
26
|
+
function nestedOf(name, dispatch, parent, at) {
|
|
27
|
+
const seen = new Set();
|
|
28
|
+
const members = dispatch.members.flatMap(({ value, variant }) => {
|
|
29
|
+
if (seen.has(value))
|
|
30
|
+
return [];
|
|
31
|
+
seen.add(value);
|
|
32
|
+
const type = csTypeOf(variant, { ...at, fieldName: value, parentName: parent }).replace(/\?$/, "");
|
|
33
|
+
at.serialized.add(type);
|
|
34
|
+
return [{ type, value }];
|
|
35
|
+
});
|
|
36
|
+
// a type a member spells would be shadowed by a nested record of its name
|
|
37
|
+
const spelled = members.flatMap(({ type }) => type.split(/\W+/).filter((word) => word !== ""));
|
|
38
|
+
const reserved = new Set([...TAKEN, ...spelled, name]);
|
|
39
|
+
const scope = new NameScope(reserved);
|
|
40
|
+
return members.map((member) => {
|
|
41
|
+
const base = csTypeName(member.value);
|
|
42
|
+
return { ...member, record: scope.claim(reserved.has(base) ? `${base}Message` : base) };
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** The converter's `Read`: the key's string value selects a member; any other value is `Unknown`, or refused. */
|
|
46
|
+
function readLines(name, key, nested, read) {
|
|
47
|
+
const other = read ? `new ${name}.Unknown(raw)` : `throw new JsonException($"no ${name} member is keyed {kind}")`;
|
|
48
|
+
return [
|
|
49
|
+
` public override ${name} Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)`,
|
|
50
|
+
" {",
|
|
51
|
+
" var raw = JsonElement.ParseValue(ref reader);",
|
|
52
|
+
` var kind = raw.ValueKind == JsonValueKind.Object && raw.TryGetProperty(${csString(key)}, out var at) && at.ValueKind == JsonValueKind.String ? at.GetString() : null;`,
|
|
53
|
+
" return kind switch",
|
|
54
|
+
" {",
|
|
55
|
+
...nested.map(({ record, type, value }) => ` ${csString(value)} => new ${name}.${record}(raw.Deserialize(${info(type)}) ?? throw new JsonException("a ${record} message is null")),`),
|
|
56
|
+
` _ => ${other},`,
|
|
57
|
+
" };",
|
|
58
|
+
" }",
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
/** The converter's `Write`: the member's variant through its own type, `Unknown` as received. */
|
|
62
|
+
function writeLines(name, nested, read) {
|
|
63
|
+
const arms = [
|
|
64
|
+
...nested.map(({ record, type }, i) => [
|
|
65
|
+
`value is ${name}.${record} member${i}`,
|
|
66
|
+
`JsonSerializer.Serialize(writer, member${i}.Value, ${info(type)});`,
|
|
67
|
+
]),
|
|
68
|
+
...(read ? [[`value is ${name}.Unknown unknown`, "unknown.Raw.WriteTo(writer);"]] : []),
|
|
69
|
+
];
|
|
70
|
+
return [
|
|
71
|
+
` public override void Write(Utf8JsonWriter writer, ${name} value, JsonSerializerOptions options)`,
|
|
72
|
+
" {",
|
|
73
|
+
...arms.flatMap(([test, write], i) => [
|
|
74
|
+
` ${i > 0 ? "else " : ""}if (${test})`,
|
|
75
|
+
" {",
|
|
76
|
+
` ${write}`,
|
|
77
|
+
" }",
|
|
78
|
+
]),
|
|
79
|
+
" else",
|
|
80
|
+
" {",
|
|
81
|
+
" writer.WriteNullValue();",
|
|
82
|
+
" }",
|
|
83
|
+
" }",
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
/** `<Op>Inbound` or `<Op>Outbound` for the keyed `dispatch`, hoisted with its converter into `at.decls`. */
|
|
87
|
+
function keyedType(op, dispatch, side, at) {
|
|
88
|
+
const read = side === "Send";
|
|
89
|
+
const name = at.names.claim(`${csTypeName(op.id)}${read ? "Inbound" : "Outbound"}`);
|
|
90
|
+
// claimed before its body: what the members hoist comes after it
|
|
91
|
+
at.decls.set(name, "");
|
|
92
|
+
const nested = nestedOf(name, dispatch, `${op.id}.${side}`, at);
|
|
93
|
+
const converter = at.names.claim(`${name}Converter`);
|
|
94
|
+
const list = nested.map(({ record }) => record).join(", ");
|
|
95
|
+
const summary = read
|
|
96
|
+
? `One message ${op.id} reads: ${list}, or Unknown for a value the operation does not declare, as received. An is match reads its Value.`
|
|
97
|
+
: `One message ${op.id} sends: ${list}. Each member's record converts to it implicitly.`;
|
|
98
|
+
const converts = [...new Map(nested.map((n) => [n.type, n])).values()].map(({ record, type }) => ` public static implicit operator ${name}(${type} value) => new ${record}(value);`);
|
|
99
|
+
at.decls.set(name, [
|
|
100
|
+
...docLines("summary", summary),
|
|
101
|
+
`[JsonConverter(typeof(${converter}))]`,
|
|
102
|
+
`public abstract record ${name}`,
|
|
103
|
+
"{",
|
|
104
|
+
` private ${name}()`,
|
|
105
|
+
" {",
|
|
106
|
+
" }",
|
|
107
|
+
"",
|
|
108
|
+
...nested.map(({ record, type }) => ` public sealed record ${record}(${type} Value) : ${name};`),
|
|
109
|
+
...(read ? [` public sealed record Unknown(JsonElement Raw) : ${name};`] : ["", ...converts]),
|
|
110
|
+
"}",
|
|
111
|
+
"",
|
|
112
|
+
`public sealed class ${converter} : JsonConverter<${name}>`,
|
|
113
|
+
"{",
|
|
114
|
+
...readLines(name, dispatch.key, nested, read),
|
|
115
|
+
"",
|
|
116
|
+
...writeLines(name, nested, read),
|
|
117
|
+
"}",
|
|
118
|
+
].join("\n"));
|
|
119
|
+
return { keyed: { key: dispatch.key, nested }, type: name };
|
|
120
|
+
}
|
|
121
|
+
/** One direction of `op`'s messages as its C# type: a keyed union's hierarchy, else the declared type itself. */
|
|
122
|
+
export function messageType(op, schema, side, at) {
|
|
123
|
+
const dispatch = dispatchOf(schema, at.names.resolve);
|
|
124
|
+
const message = dispatch === undefined
|
|
125
|
+
? { type: csTypeOf(schema, { ...at, fieldName: side, parentName: op.id }).replace(/\?$/, "") }
|
|
126
|
+
: keyedType(op, dispatch, side, at);
|
|
127
|
+
at.serialized.add(message.type);
|
|
128
|
+
return message;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The `On<Value>` extensions of `<base><read, TOut>` (a socket or a connection, `reader`), `read` a keyed read side,
|
|
132
|
+
* declared beside it in `at`: each takes the variant of the member its value selects, matched inside the reader's
|
|
133
|
+
* `Message`; a value whose method one of the reader's `handlers` names gets none.
|
|
134
|
+
*/
|
|
135
|
+
export function valueHandlers({ base, handlers, receiver }, read, at) {
|
|
136
|
+
const declared = at.decls.get(read.type);
|
|
137
|
+
if (read.keyed === undefined || declared === undefined)
|
|
138
|
+
return;
|
|
139
|
+
const { key, nested } = read.keyed;
|
|
140
|
+
const scope = new NameScope(handlers);
|
|
141
|
+
const methods = nested.flatMap(({ record, type, value }) => {
|
|
142
|
+
const method = `On${csTypeName(value)}`;
|
|
143
|
+
if (scope.has(method))
|
|
144
|
+
return [];
|
|
145
|
+
return [
|
|
146
|
+
"",
|
|
147
|
+
...docLines("summary", `Calls handler with each message whose ${csString(key)} is ${csString(value)}, inside Message.`, " "),
|
|
148
|
+
` public static void ${scope.claim(method)}<TOut>(this ${base}<${read.type}, TOut> ${receiver}, Action<${type}> handler)`,
|
|
149
|
+
" {",
|
|
150
|
+
` ${receiver}.Message += message =>`,
|
|
151
|
+
" {",
|
|
152
|
+
` if (message is ${read.type}.${record} matched)`,
|
|
153
|
+
" {",
|
|
154
|
+
" handler(matched.Value);",
|
|
155
|
+
" }",
|
|
156
|
+
" };",
|
|
157
|
+
" }",
|
|
158
|
+
];
|
|
159
|
+
});
|
|
160
|
+
if (methods.length === 0)
|
|
161
|
+
return;
|
|
162
|
+
const holder = at.names.claim(`${read.type}Extensions`);
|
|
163
|
+
at.decls.set(read.type, [
|
|
164
|
+
declared,
|
|
165
|
+
"",
|
|
166
|
+
...docLines("summary", `A handler per member of ${read.type}, each matching inside the Message of a ${base} that reads it.`),
|
|
167
|
+
`public static class ${holder}`,
|
|
168
|
+
"{",
|
|
169
|
+
...methods.slice(1),
|
|
170
|
+
"}",
|
|
171
|
+
].join("\n"));
|
|
172
|
+
}
|