@workerstack/clients 1.0.0-rc.29 → 1.0.0-rc.31
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 +548 -35
- 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 +88 -68
- package/bin/installgen.js +18 -13
- package/dist/cli.d.ts +4 -4
- package/dist/cli.js +20 -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 +14 -8
- 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 +11 -5
- 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 +3 -3
- package/dist/emit/csharp/errors.js +4 -4
- package/dist/emit/csharp/json.js +8 -8
- package/dist/emit/csharp/realtime.js +3 -3
- 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 +18 -2
- package/dist/emit/csharp/sdk-method.js +24 -9
- package/dist/emit/csharp/sdk-plan.js +0 -1
- package/dist/emit/csharp/sdk.js +7 -4
- package/dist/emit/csharp/sse.d.ts +0 -2
- package/dist/emit/csharp/sse.js +7 -7
- package/dist/emit/csharp/transport.js +7 -7
- package/dist/emit/csharp/types-enum.js +3 -1
- package/dist/emit/csharp/types-messages.js +3 -3
- package/dist/emit/csharp/types-names.js +10 -12
- 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.js +2 -2
- 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.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 +9 -0
- package/dist/emit/go/sdk-method.js +12 -3
- 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 +12 -11
- package/dist/emit/go/sse.js +1 -1
- 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.js +9 -9
- package/dist/emit/go/ws.js +6 -6
- package/dist/emit/java/gradle.d.ts +7 -9
- package/dist/emit/java/gradle.js +8 -8
- package/dist/emit/java/json.js +1 -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.js +5 -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 +1 -1
- package/dist/emit/java/models-union.js +1 -1
- package/dist/emit/java/models.d.ts +1 -2
- package/dist/emit/java/models.js +25 -16
- package/dist/emit/java/realtime.d.ts +5 -17
- package/dist/emit/java/realtime.js +1 -1
- package/dist/emit/java/sdk-client.d.ts +6 -6
- package/dist/emit/java/sdk-client.js +2 -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 +2 -2
- 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 +7 -11
- package/dist/emit/java/sdk-op.js +22 -10
- 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 +21 -14
- package/dist/emit/java/sse.d.ts +2 -4
- package/dist/emit/java/sse.js +6 -6
- package/dist/emit/java/ws.d.ts +2 -2
- package/dist/emit/java/ws.js +3 -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.js +3 -3
- 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.js +2 -2
- package/dist/emit/python/sdk-answer.d.ts +3 -7
- 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 +11 -0
- package/dist/emit/python/sdk-method.js +20 -5
- 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 +12 -8
- package/dist/emit/python/sse.d.ts +0 -2
- package/dist/emit/python/sse.js +2 -2
- 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.js +3 -3
- package/dist/emit/python/ws.d.ts +2 -5
- package/dist/emit/python/ws.js +4 -4
- package/dist/emit/rust/errors.js +3 -3
- package/dist/emit/rust/http.js +4 -4
- package/dist/emit/rust/realtime.js +2 -2
- 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.d.ts +12 -1
- package/dist/emit/rust/sdk-method.js +12 -4
- 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 +9 -6
- package/dist/emit/rust/sse.d.ts +0 -5
- package/dist/emit/rust/sse.js +2 -2
- 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 +1 -1
- package/dist/emit/rust/types.js +7 -5
- package/dist/emit/rust/ws.d.ts +0 -11
- package/dist/emit/rust/ws.js +5 -5
- 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 +8 -2
- package/dist/emit/ts/http.js +51 -6
- package/dist/emit/ts/package.d.ts +14 -12
- package/dist/emit/ts/package.js +10 -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 +12 -4
- package/dist/emit/ts/sdk-types.d.ts +0 -5
- package/dist/emit/ts/sdk-types.js +63 -19
- package/dist/emit/ts/sdk.d.ts +3 -1
- package/dist/emit/ts/sdk.js +44 -12
- package/dist/emit/ts/service-map.d.ts +7 -1
- package/dist/emit/ts/service-map.js +10 -1
- package/dist/emit/ts/single-flight-text.d.ts +3 -0
- package/dist/emit/ts/single-flight-text.js +38 -0
- package/dist/emit/ts/tanstack-query.d.ts +3 -2
- package/dist/emit/ts/tanstack-query.js +60 -35
- package/dist/emit/ts/type-gen.js +31 -18
- 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/process.js +2 -1
- package/dist/gen/shipped.js +2 -2
- package/dist/gen/switch-on.constants.d.ts +2 -0
- package/dist/gen/switch-on.constants.js +2 -0
- package/dist/gen/targets.d.ts +6 -7
- package/dist/gen/targets.js +11 -6
- 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 +8 -5
- package/dist/ir/invalidate-reads.d.ts +17 -0
- package/dist/ir/invalidate-reads.js +104 -0
- package/dist/ir/load.d.ts +10 -0
- package/dist/ir/load.js +65 -18
- package/dist/ir/model.d.ts +2 -1
- package/dist/ir/model.js +0 -1
- package/dist/ir/read-method.constants.d.ts +2 -0
- package/dist/ir/read-method.constants.js +2 -0
- 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.js +3 -3
- package/dist/ir/slots.js +13 -8
- package/dist/ir/streams.js +1 -1
- 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 +4 -4
- 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/csharp/Config.cs +9 -1
- package/dist/runtime/csharp/Exchange.cs +56 -4
- package/dist/runtime/csharp/Hooks.cs +9 -0
- package/dist/runtime/csharp/Operation.cs +6 -1
- package/dist/runtime/csharp/WsDial.cs +3 -1
- package/dist/runtime/go/config.go +5 -0
- package/dist/runtime/go/hooks.go +70 -0
- package/dist/runtime/go/request.go +6 -2
- package/dist/runtime/go/stream.go +4 -1
- package/dist/runtime/go/ws.go +3 -1
- package/dist/runtime/java/ClientConfig.java +11 -0
- package/dist/runtime/java/Flight.java +2 -12
- package/dist/runtime/java/Hooks.java +45 -0
- package/dist/runtime/java/InvalidateEvent.java +10 -0
- package/dist/runtime/java/InvalidateHook.java +12 -0
- package/dist/runtime/java/InvalidateTarget.java +7 -0
- package/dist/runtime/java/Operation.java +23 -3
- package/dist/runtime/java/Realtime.java +3 -1
- package/dist/runtime/java/WsDial.java +3 -0
- 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/config.py +8 -2
- package/dist/runtime/python/exchange.py +3 -1
- package/dist/runtime/python/hooks.py +110 -5
- package/dist/runtime/python/operation.py +2 -0
- package/dist/runtime/python/send_async.py +14 -2
- package/dist/runtime/python/send_sync.py +4 -2
- package/dist/runtime/python/ws.py +5 -1
- package/dist/runtime/rust/config.rs +6 -1
- package/dist/runtime/rust/exchange.rs +15 -3
- package/dist/runtime/rust/hooks.rs +127 -2
- package/dist/runtime/rust/log.rs +11 -3
- package/dist/runtime/rust/request.rs +17 -0
- package/dist/runtime/rust/ws.rs +9 -1
- package/dist/runtime/ts/config.ts +69 -0
- package/dist/runtime/ts/http.ts +12 -10
- package/dist/runtime/ts/request.ts +2 -0
- package/dist/runtime/ts/response.ts +7 -0
- package/dist/runtime/ts/sdk-invalidate.ts +82 -0
- package/dist/runtime/ts/sdk-single-flight.constants.ts +25 -0
- package/dist/runtime/ts/sdk-single-flight.ts +203 -0
- package/dist/runtime/ts/sdk-sse.ts +5 -1
- package/dist/runtime/ts/sdk-ws.ts +9 -3
- package/dist/runtime/ts/sdk.ts +55 -31
- package/dist/runtime/ts/single-flight-batch.ts +184 -0
- package/dist/runtime/ts/single-flight-body.ts +59 -0
- package/dist/runtime/ts/single-flight-run.ts +160 -0
- package/dist/runtime/ts/single-flight.constants.ts +31 -0
- package/dist/runtime/ts/single-flight.ts +158 -0
- package/dist/runtime/ts-tanstack-query/invalidate.ts +96 -92
- package/dist/runtime/ts-tanstack-query/query.ts +140 -170
- package/package.json +12 -17
- package/references/INDEX.md +31 -0
- package/references/cli.md +33 -0
- package/references/configuring.md +29 -0
- package/references/documentation.md +15 -0
- package/references/errors.md +23 -0
- package/references/flags.md +104 -0
- package/references/gates.md +46 -0
- package/references/generate.md +29 -0
- package/references/install-scripts.md +28 -0
- package/references/install.md +38 -0
- package/references/license.md +8 -0
- package/references/mcp.md +76 -0
- package/references/output.md +45 -0
- package/references/overview.md +14 -0
- package/references/release-tooling.md +34 -0
- package/references/release.md +305 -0
- package/references/sdks.md +393 -0
- package/references/start.md +22 -0
- package/references/tdd.md +16 -0
- 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
|
@@ -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",
|
|
@@ -1,9 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One operation (§4.4, §4.8; contract 47 §2): its private `Operation` field (`Accept` for a text or binary answer,
|
|
3
|
+
* `Invalidates` for its `x-invalidate` targets), its method, the types the JSON context must list for it, and its
|
|
4
|
+
* call plan. A method takes its path params as `string` in path order, then a required body, the required query
|
|
5
|
+
* and header params, an optional body, the optional ones, `idempotencyKey` on an idempotent op, `headersInto` where
|
|
6
|
+
* the op declares response headers (Fc7), a stream's own fields, `options` and `cancellationToken` (C#4). Its body
|
|
7
|
+
* by kind is sdk-body.ts's, its answer sdk-answer.ts's, a stream's its `CsStream`'s (contract 50 §2): a stream takes
|
|
8
|
+
* no idempotency key, an SSE one asks for `text/event-stream`, and a declared param a stream field carries gets no
|
|
9
|
+
* parameter. Its body is one call into the transport, a stream's arguments then its answer's (and their type infos) after the `Call`, the
|
|
10
|
+
* signature on one line and the call on the next (Fb8). Its `client.Safe` twin (C#2, bit 21 i5) restates the
|
|
11
|
+
* signature and answers `Task<Result<T>>` (`Task<Result>` for no body) through `Transport.Safe` and the very method,
|
|
12
|
+
* its options given a response box; a connection's twin is the very method. A param named like one of the method's
|
|
13
|
+
* own locals or its stream's fields is `…2`, a keyword `@`-escaped (H52); the twin's lambda takes `_o`, which no
|
|
14
|
+
* param is (a `_` leads a name only before a digit).
|
|
15
|
+
*/
|
|
16
|
+
import type { InvalidatedRead } from "../../ir/invalidate-reads.ts";
|
|
1
17
|
import type { SdkOp } from "../../ir/sdk-model.ts";
|
|
2
18
|
import type { CSharpCallPlan } from "./sdk-plan.ts";
|
|
3
19
|
import { type CsTypeContext } from "./types.ts";
|
|
4
|
-
/**
|
|
20
|
+
/** The type context, and each write's reads by operationId (`invalidateReads`): what its `OnInvalidate` event names. */
|
|
5
21
|
export type MethodEnv = {
|
|
6
22
|
readonly at: CsTypeContext;
|
|
23
|
+
readonly reads: ReadonlyMap<string, readonly InvalidatedRead[]>;
|
|
7
24
|
};
|
|
8
25
|
/** How a rendered method spells a type the context lists: its runtime type, and its `<Context>.Default.<Name>`. */
|
|
9
26
|
export type Spelling = {
|
|
@@ -21,6 +38,5 @@ export type CsMethod = {
|
|
|
21
38
|
readonly types: readonly string[];
|
|
22
39
|
readonly plan: Omit<CSharpCallPlan, "accessors">;
|
|
23
40
|
};
|
|
24
|
-
export declare const METHOD_LOCALS: string[];
|
|
25
41
|
/** The method of `op` named `name`, its `Operation` in the private field `field`. */
|
|
26
42
|
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.
|
|
@@ -103,7 +106,7 @@ function methodLines(parts, spell) {
|
|
|
103
106
|
` _t.${run}(${parts.field}, new(${call(parts, spell)}), ${args.join(", ")});`,
|
|
104
107
|
];
|
|
105
108
|
}
|
|
106
|
-
|
|
109
|
+
// an SSE twin's <returns>: the open stream is its Ok, an error status opening it its Err
|
|
107
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.";
|
|
108
111
|
/**
|
|
109
112
|
* The `client.Safe` twin's lines: the signature restated, answering `Task<Result<T>>` (`Task<Result>` for no body)
|
|
@@ -114,12 +117,13 @@ function twinLines(parts, spell) {
|
|
|
114
117
|
const [returns] = parts.answer.render(spell);
|
|
115
118
|
const sig = `${signature(parts, spell).join(", ")})`;
|
|
116
119
|
const idents = parameters(parts, spell).map(({ ident }) => ident);
|
|
117
|
-
if (parts.op.stream === "ws" || parts.op.stream === "realtime")
|
|
120
|
+
if (parts.op.stream === "ws" || parts.op.stream === "realtime") {
|
|
118
121
|
return [
|
|
119
122
|
...methodDoc(parts.op, true, parts.stream?.returns),
|
|
120
123
|
` public ${returns} ${parts.name}(${sig} =>`,
|
|
121
124
|
` _n.${parts.name}(${idents.join(", ")});`,
|
|
122
125
|
];
|
|
126
|
+
}
|
|
123
127
|
const safe = returns === "Task" ? "Task<Result>" : `Task<Result<${returns.slice("Task<".length, -1)}>>`;
|
|
124
128
|
const sent = idents.map((ident) => (ident === "options" ? "_o" : ident));
|
|
125
129
|
return [
|
|
@@ -157,13 +161,24 @@ function acceptOf(op) {
|
|
|
157
161
|
return "text/event-stream";
|
|
158
162
|
return op.success.kind === "binary" || op.success.kind === "text" ? op.success.contentType : undefined;
|
|
159
163
|
}
|
|
160
|
-
/** The `Operation`
|
|
161
|
-
function
|
|
164
|
+
/** The `Operation` members a write's `OnInvalidate` event needs: its operationId and the reads it makes stale. */
|
|
165
|
+
function readsOf(op, reads) {
|
|
166
|
+
if (reads === undefined || reads.length === 0)
|
|
167
|
+
return [];
|
|
168
|
+
const each = reads.map((read) => `new(${csString(read.operationId)}, [${read.params.map(csString).join(", ")}])`);
|
|
169
|
+
return [`By: ${csString(op.id)}`, `Reads: [${each.join(", ")}]`];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The `Operation` field: method, path, path params, `Idempotent`, then `Accept`, `Invalidates` and the
|
|
173
|
+
* `OnInvalidate` reads when they apply.
|
|
174
|
+
*/
|
|
175
|
+
function operationField({ field, keyed, op, path }, reads) {
|
|
162
176
|
const accept = acceptOf(op);
|
|
163
177
|
const named = [
|
|
164
178
|
`Idempotent: ${keyed}`,
|
|
165
179
|
...(accept === undefined ? [] : [`Accept: ${csString(accept)}`]),
|
|
166
180
|
...(op.invalidates.length === 0 ? [] : [`Invalidates: [${op.invalidates.map(csString).join(", ")}]`]),
|
|
181
|
+
...readsOf(op, reads),
|
|
167
182
|
];
|
|
168
183
|
const params = path.map(({ param }) => csString(param.name)).join(", ");
|
|
169
184
|
return ` private static readonly Operation ${field} = new(${csString(op.method)}, ${csString(op.path)}, [${params}], ${named.join(", ")});`;
|
|
@@ -180,7 +195,7 @@ export function csMethod(op, name, field, env) {
|
|
|
180
195
|
const keyed = op.idempotent && stream === null;
|
|
181
196
|
const parts = { answer, body, field, headers, keyed, name, op, params, path, stream };
|
|
182
197
|
return {
|
|
183
|
-
field: operationField(parts),
|
|
198
|
+
field: operationField(parts, env.reads.get(op.id)),
|
|
184
199
|
lines: (spell) => methodLines(parts, spell),
|
|
185
200
|
plan: planOf(parts),
|
|
186
201
|
twin: (spell) => twinLines(parts, spell),
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/emit/csharp/sdk.js
CHANGED
|
@@ -10,19 +10,20 @@
|
|
|
10
10
|
* reports every name it emits other than the spec's (`notices`, shared/mirror.ts), never silently.
|
|
11
11
|
*/
|
|
12
12
|
import { toIR } from "../../ir/build.js";
|
|
13
|
+
import { invalidateReads } from "../../ir/invalidate-reads.js";
|
|
13
14
|
import { sdkModel } from "../../ir/sdk-model.js";
|
|
14
15
|
import { compareCodeUnits, csTypeName } from "../shared/lang.js";
|
|
16
|
+
import { packageOn } from "../shared/metadata.js";
|
|
15
17
|
import { renameNotice } from "../shared/mirror.js";
|
|
16
18
|
import { csharpErrorKeys } from "./errors.js";
|
|
17
19
|
import { jsonContext, runtimeOf, strictConverters, typeInfoNames } from "./json.js";
|
|
18
20
|
import { clientDecls } from "./sdk-client.js";
|
|
19
21
|
import { csproj, EDITORCONFIG, packageMetadata, validateClientName, validatePackageId, validateRootNamespace, validateVersion, } from "./sdk-csproj.js";
|
|
20
|
-
import { packageOn } from "../shared/metadata.js";
|
|
21
22
|
import { docLines } from "./sdk-doc.js";
|
|
22
23
|
import { runtimeFiles } from "./transport.js";
|
|
23
24
|
import { usings } from "./types-names.js";
|
|
24
25
|
import { csTopLevel, csTypeContext, declares } from "./types.js";
|
|
25
|
-
|
|
26
|
+
// the marker every .cs file opens with; never `<auto-generated`, which the format gate and the analyzers skip (Q4)
|
|
26
27
|
const MARKER = "// @generated by clients. DO NOT EDIT.";
|
|
27
28
|
/** The options validated, each default filled in, and the client's and its context's class names. */
|
|
28
29
|
function identity(options) {
|
|
@@ -60,14 +61,16 @@ function emitCSharp(document, options, shipped) {
|
|
|
60
61
|
const at = csTypeContext(ir, [id.client, id.context]);
|
|
61
62
|
const components = componentDecls(ir, at);
|
|
62
63
|
const errorKey = csharpErrorKeys(model, at);
|
|
63
|
-
|
|
64
|
+
// every component emitted under another name is noticed, as the mirror's rename is
|
|
64
65
|
const notices = [...at.names.renamed].map(([name, renamed]) => renameNotice("csharp", {
|
|
65
66
|
because: `"${csTypeName(name)}" is a name the SDK's runtime, the BCL or another declaration holds`,
|
|
66
67
|
name,
|
|
67
68
|
renamed,
|
|
68
69
|
what: "component",
|
|
69
70
|
}));
|
|
70
|
-
const
|
|
71
|
+
const { reads, warnings } = invalidateReads(ir);
|
|
72
|
+
notices.push(...warnings.map((warning) => `csharp: ${warning}`));
|
|
73
|
+
const env = { at, client: id.client, context: id.context, notices, ops: model.opsById, reads };
|
|
71
74
|
const client = clientDecls(ir, env);
|
|
72
75
|
const decls = [...components, ...[...at.decls].sort(([a], [b]) => compareCodeUnits(a, b))];
|
|
73
76
|
const types = [...decls.map(([, text]) => text), ...(errorKey === null ? [] : [errorKey])].join("\n\n");
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { type CsStream } from "./sdk-answer.ts";
|
|
2
|
-
/** The header the SSE and realtime dials resume an event stream with. */
|
|
3
|
-
export declare const LAST_EVENT_ID = "Last-Event-ID";
|
|
4
2
|
/** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
|
|
5
3
|
export declare const isLastEventIdHeader: (name: string, where: string) => boolean;
|
|
6
4
|
/** The SSE operation's answer, its one field and its `<returns>` text. */
|
package/dist/emit/csharp/sse.js
CHANGED
|
@@ -5,20 +5,20 @@ import { eventType } from "./sdk-answer.js";
|
|
|
5
5
|
import { docLines } from "./sdk-doc.js";
|
|
6
6
|
import { csTypeOf } from "./types.js";
|
|
7
7
|
/** The header the SSE and realtime dials resume an event stream with. */
|
|
8
|
-
|
|
8
|
+
const LAST_EVENT_ID = "Last-Event-ID";
|
|
9
9
|
/** The resume cursor's event id, which the SSE method takes. */
|
|
10
10
|
const LAST_EVENT_ID_FIELD = { ident: "lastEventId", type: "string?" };
|
|
11
11
|
/** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
|
|
12
12
|
export const isLastEventIdHeader = (name, where) => where === "header" && name.toLowerCase() === LAST_EVENT_ID.toLowerCase();
|
|
13
|
-
|
|
13
|
+
// the names a nested record never takes: the members, and the types the decode spells
|
|
14
14
|
const TAKEN = [
|
|
15
|
-
|
|
15
|
+
// a nested record's members
|
|
16
16
|
"Data",
|
|
17
17
|
"Event",
|
|
18
18
|
"Id",
|
|
19
19
|
"Retry",
|
|
20
20
|
"Of",
|
|
21
|
-
|
|
21
|
+
// every record's
|
|
22
22
|
"Deconstruct",
|
|
23
23
|
"EqualityContract",
|
|
24
24
|
"Equals",
|
|
@@ -28,7 +28,7 @@ const TAKEN = [
|
|
|
28
28
|
"MemberwiseClone",
|
|
29
29
|
"PrintMembers",
|
|
30
30
|
"ToString",
|
|
31
|
-
|
|
31
|
+
// the decode's
|
|
32
32
|
"JsonSerializerOptions",
|
|
33
33
|
"JsonTypeInfo",
|
|
34
34
|
"SseEvent",
|
|
@@ -51,13 +51,13 @@ function namedEvents(op, events, env) {
|
|
|
51
51
|
at.unlisted.add(name);
|
|
52
52
|
const typed = events.map(({ data, name: event }) => {
|
|
53
53
|
const json = isJsonEventData(data, at.names.resolve);
|
|
54
|
-
|
|
54
|
+
// the decode throws on null, so the data is never null
|
|
55
55
|
const type = json ? csTypeOf(data, { ...at, fieldName: event, parentName: op.id }).replace(/\?$/, "") : "string";
|
|
56
56
|
if (json)
|
|
57
57
|
at.serialized.add(type);
|
|
58
58
|
return { data: type, event, json };
|
|
59
59
|
});
|
|
60
|
-
|
|
60
|
+
// a type a record's data spells would be shadowed by a nested record of its name
|
|
61
61
|
const spelled = typed.flatMap(({ data }) => data.split(/\W+/).filter((word) => word !== ""));
|
|
62
62
|
const reserved = new Set([...TAKEN, ...spelled, name, "Unknown"]);
|
|
63
63
|
const scope = new NameScope(reserved);
|
|
@@ -7,9 +7,9 @@
|
|
|
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
|
-
|
|
36
|
+
// a WebSocket or realtime operation: the socket, its own HTTP/1.1 upgrade, and the socket of declared messages
|
|
37
37
|
const WS = ["Ws", "WsDial", "WsTyped"];
|
|
38
|
-
|
|
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
|
}
|
|
@@ -3,7 +3,7 @@ import { csString } from "../shared/escape.js";
|
|
|
3
3
|
import { csTypeName, NameScope } from "../shared/lang.js";
|
|
4
4
|
import { docLines } from "./sdk-doc.js";
|
|
5
5
|
import { csTypeOf } from "./types.js";
|
|
6
|
-
|
|
6
|
+
// the names a nested record never takes: its members, every record's, and the types its converter spells
|
|
7
7
|
const TAKEN = [
|
|
8
8
|
"Value",
|
|
9
9
|
"Raw",
|
|
@@ -33,7 +33,7 @@ function nestedOf(name, dispatch, parent, at) {
|
|
|
33
33
|
at.serialized.add(type);
|
|
34
34
|
return [{ type, value }];
|
|
35
35
|
});
|
|
36
|
-
|
|
36
|
+
// a type a member spells would be shadowed by a nested record of its name
|
|
37
37
|
const spelled = members.flatMap(({ type }) => type.split(/\W+/).filter((word) => word !== ""));
|
|
38
38
|
const reserved = new Set([...TAKEN, ...spelled, name]);
|
|
39
39
|
const scope = new NameScope(reserved);
|
|
@@ -87,7 +87,7 @@ function writeLines(name, nested, read) {
|
|
|
87
87
|
function keyedType(op, dispatch, side, at) {
|
|
88
88
|
const read = side === "Send";
|
|
89
89
|
const name = at.names.claim(`${csTypeName(op.id)}${read ? "Inbound" : "Outbound"}`);
|
|
90
|
-
|
|
90
|
+
// claimed before its body: what the members hoist comes after it
|
|
91
91
|
at.decls.set(name, "");
|
|
92
92
|
const nested = nestedOf(name, dispatch, `${op.id}.${side}`, at);
|
|
93
93
|
const converter = at.names.claim(`${name}Converter`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { irResolver } from "../../ir/schema.js";
|
|
2
2
|
import { compareCodeUnits, csTypeName, NameScope } from "../shared/lang.js";
|
|
3
3
|
import { runtimeFiles, runtimeTypeNames } from "./transport.js";
|
|
4
|
-
|
|
4
|
+
// the BCL names emitted text spells unqualified, by the namespace a `using` brings them from (§4.7)
|
|
5
5
|
export const BCL = {
|
|
6
6
|
System: ["Action", "Exception", "Func", "IDisposable", "Object", "String", "TimeSpan", "Type"],
|
|
7
7
|
"System.Collections.Generic": ["IDictionary", "IReadOnlyDictionary", "IReadOnlyList"],
|
|
@@ -30,10 +30,8 @@ export const BCL = {
|
|
|
30
30
|
"System.Threading": ["CancellationToken"],
|
|
31
31
|
"System.Threading.Tasks": ["Task"],
|
|
32
32
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* the emitted types share the runtime's namespace (Fb2), so each is reserved, never a `using`
|
|
36
|
-
*/
|
|
33
|
+
// the BCL names the vendored runtime spells unqualified (as a type or by static access) and emitted text never does:
|
|
34
|
+
// the emitted types share the runtime's namespace (Fb2), so each is reserved, never a `using`
|
|
37
35
|
export const RUNTIME_BCL = [
|
|
38
36
|
"Array",
|
|
39
37
|
"BrotliStream",
|
|
@@ -96,7 +94,7 @@ export const RUNTIME_BCL = [
|
|
|
96
94
|
"StringBuilder",
|
|
97
95
|
"StringComparer",
|
|
98
96
|
"StringComparison",
|
|
99
|
-
|
|
97
|
+
// System.Threading's, also a runtime property: the scan cannot tell `Timeout.InfiniteTimeSpan` (CS0117) from it
|
|
100
98
|
"Timeout",
|
|
101
99
|
"UnicodeCategory",
|
|
102
100
|
"Uri",
|
|
@@ -110,7 +108,7 @@ export const RUNTIME_BCL = [
|
|
|
110
108
|
"WebSocketMessageType",
|
|
111
109
|
"WebSocketState",
|
|
112
110
|
];
|
|
113
|
-
|
|
111
|
+
// the attributes emitted text spells without their `Attribute` suffix: the suffixed name is taken too
|
|
114
112
|
const ATTRIBUTES = [
|
|
115
113
|
"JsonConverter",
|
|
116
114
|
"JsonExtensionData",
|
|
@@ -126,7 +124,7 @@ const reserved = (taken) => [
|
|
|
126
124
|
...Object.values(BCL).flat(),
|
|
127
125
|
...RUNTIME_BCL,
|
|
128
126
|
...ATTRIBUTES.map((name) => `${name}Attribute`),
|
|
129
|
-
|
|
127
|
+
// the static class of the API's error keys (errors.ts), declared beside the types when any key is
|
|
130
128
|
"ErrorKey",
|
|
131
129
|
"System",
|
|
132
130
|
...taken,
|
|
@@ -162,7 +160,7 @@ export function irNames(schemas, taken, declares) {
|
|
|
162
160
|
hoisted.set(key, name);
|
|
163
161
|
return name;
|
|
164
162
|
},
|
|
165
|
-
|
|
163
|
+
// a ref reaches here only for a declared component: `alias` answers for every other one
|
|
166
164
|
ref: (name) => components.get(name),
|
|
167
165
|
renamed,
|
|
168
166
|
resolve: irResolver(schemas),
|
|
@@ -170,9 +168,9 @@ export function irNames(schemas, taken, declares) {
|
|
|
170
168
|
}
|
|
171
169
|
/** `code` without its string and char literals and comments: the text that spells names. */
|
|
172
170
|
const codeOf = (code) => code
|
|
173
|
-
.
|
|
174
|
-
.
|
|
175
|
-
.
|
|
171
|
+
.replaceAll(/"(?:[^"\\\n]|\\.)*"/g, '""')
|
|
172
|
+
.replaceAll(/'(?:[^'\\\n]|\\.)'/g, "''")
|
|
173
|
+
.replaceAll(/\/\/.*$/gm, "");
|
|
176
174
|
/** The `using` lines `code` needs: each namespace one of whose BCL names it spells as a type, in code-unit order. */
|
|
177
175
|
export function usings(code) {
|
|
178
176
|
const text = codeOf(code);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { csString } from "../shared/escape.js";
|
|
2
2
|
import { compareCodeUnits, csTypeName, NameScope } from "../shared/lang.js";
|
|
3
|
-
|
|
3
|
+
// every member name a record property collides with (CS0102, CS0108, CS8859, CS8874), and the name its attributes spell in an expression
|
|
4
4
|
export const RECORD_MEMBERS = [
|
|
5
5
|
"Clone",
|
|
6
6
|
"EqualityContract",
|
|
@@ -12,7 +12,7 @@ export const RECORD_MEMBERS = [
|
|
|
12
12
|
"PrintMembers",
|
|
13
13
|
"ToString",
|
|
14
14
|
];
|
|
15
|
-
|
|
15
|
+
// a required nullable member is written even when null; an unset tri-state or open value is not written
|
|
16
16
|
const NEVER = "[JsonIgnore(Condition = JsonIgnoreCondition.Never)]";
|
|
17
17
|
const UNSET = "[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]";
|
|
18
18
|
/** One property's lines, unindented: its attributes, then `public <type> <name> { get; init; }`. */
|
|
@@ -25,7 +25,7 @@ function propertyLines(field, name, member, at) {
|
|
|
25
25
|
return [key, UNSET, `public ${type} ${name} { get; init; }`];
|
|
26
26
|
if (!type.endsWith("?"))
|
|
27
27
|
return [key, `public ${type}? ${name} { get; init; }`];
|
|
28
|
-
|
|
28
|
+
// OptConverter reads T through the context: it must list T
|
|
29
29
|
at.serialized.add(type);
|
|
30
30
|
return [key, `[JsonConverter(typeof(OptConverter<${type}>))]`, UNSET, `public Opt<${type}> ${name} { get; init; }`];
|
|
31
31
|
}
|
|
@@ -11,7 +11,7 @@ type Of<K extends IRSchema["kind"]> = Extract<IRSchema, {
|
|
|
11
11
|
kind: K;
|
|
12
12
|
}>;
|
|
13
13
|
/** Declares `schema` once under `names.hoist(key, base)`; its name. */
|
|
14
|
-
|
|
14
|
+
type Declare = (schema: IRSchema, key: string, base: string) => string;
|
|
15
15
|
/** What a union's declaration reaches: the context, its members' types, and the hoist. */
|
|
16
16
|
export type UnionScope = {
|
|
17
17
|
at: CsTypeContext;
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { IR, IRSchema } from "../../ir/model.ts";
|
|
9
9
|
import { type CsTypeNames } from "./types-names.ts";
|
|
10
|
-
export type { CsTypeNames } from "./types-names.ts";
|
|
11
10
|
/** Where a type is being written, the declarations it hoists, the names, and what the JSON context gathers. */
|
|
12
11
|
export type CsTypeContext = {
|
|
13
12
|
parentName: string;
|
|
@@ -5,7 +5,7 @@ import { fieldsOf, isOpen, recordDecl } from "./types-record.js";
|
|
|
5
5
|
import { isLiteral, unionDecl } from "./types-union.js";
|
|
6
6
|
export const JSON_ELEMENT = "JsonElement";
|
|
7
7
|
const MAP = "IReadOnlyDictionary<string, ";
|
|
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",
|
|
@@ -45,7 +45,7 @@ export function declares(ir) {
|
|
|
45
45
|
function declare(ir, at, key, base) {
|
|
46
46
|
const name = at.names.hoist(key, base);
|
|
47
47
|
if (!at.decls.has(name)) {
|
|
48
|
-
|
|
48
|
+
// claimed before its body: what the body hoists in turn comes after it
|
|
49
49
|
at.decls.set(name, "");
|
|
50
50
|
at.decls.set(name, csTopLevel(name, ir, at));
|
|
51
51
|
}
|
|
@@ -98,7 +98,7 @@ const USES = {
|
|
|
98
98
|
ref: refUse,
|
|
99
99
|
scalar: (ir, at) => (isEnum(ir) ? hoist(ir, at) : SCALARS[ir.type]),
|
|
100
100
|
tuple: () => `IReadOnlyList<${JSON_ELEMENT}>`,
|
|
101
|
-
|
|
101
|
+
// a union in use position is any JSON value; a component union is declared (Fb7)
|
|
102
102
|
union: () => JSON_ELEMENT,
|
|
103
103
|
unknown: () => JSON_ELEMENT,
|
|
104
104
|
};
|
package/dist/emit/csharp/ws.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { JSON_ELEMENT } from "./types.js";
|
|
2
1
|
import { messageType, valueHandlers } from "./types-messages.js";
|
|
2
|
+
import { JSON_ELEMENT } from "./types.js";
|
|
3
3
|
/** The subprotocols a WebSocket dial offers. */
|
|
4
4
|
const PROTOCOLS = { ident: "protocols", type: "IReadOnlyList<string>?" };
|
|
5
5
|
/** The resume cursor's token, which the WebSocket method takes. */
|
|
6
6
|
const RECONNECT_TOKEN = { ident: "reconnectToken", type: "string?" };
|
|
7
|
-
|
|
7
|
+
// the typed socket, and its own events: a member whose On<Value> one of them names gets none
|
|
8
8
|
const READER = { base: "TypedWebSocket", handlers: ["OnMessage", "OnClose", "OnError"], receiver: "socket" };
|
|
9
9
|
/** Whether a declared param is the `reconnect_token` query param, the resume channel a socket dial sends. */
|
|
10
10
|
export const isReconnectToken = (name, where) => where === "query" && name === "reconnect_token";
|
package/dist/emit/go/errors.js
CHANGED
|
@@ -5,7 +5,7 @@ import { goTopLevel } from "./types.js";
|
|
|
5
5
|
/** Every declared key's schema (the first operation's to declare one), keys in code-unit order. */
|
|
6
6
|
function declaredKeys(model) {
|
|
7
7
|
const declared = model.ops.flatMap((op) => Object.entries(op.ir.extensions.errors ?? {}));
|
|
8
|
-
|
|
8
|
+
// reversed, so a key ends on its first declaration
|
|
9
9
|
const first = new Map(declared.toReversed().map(([key, { schema }]) => [key, schema]));
|
|
10
10
|
return [...first].sort(([a], [b]) => compareCodeUnits(a, b));
|
|
11
11
|
}
|
package/dist/emit/go/http.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { readFileSync } from "node:fs";
|
|
8
8
|
import { compareCodeUnits } from "../shared/lang.js";
|
|
9
|
-
|
|
9
|
+
// every SDK: config, request, auth, redirects, errors, SSE, invalidation
|
|
10
10
|
const CORE = [
|
|
11
11
|
"auth",
|
|
12
12
|
"body",
|
|
@@ -27,7 +27,7 @@ const CORE = [
|
|
|
27
27
|
"stale",
|
|
28
28
|
"stream",
|
|
29
29
|
];
|
|
30
|
-
|
|
30
|
+
// a WebSocket operation; realtime adds the resumable transports on top of it
|
|
31
31
|
const WS = ["ws"];
|
|
32
32
|
const REALTIME = ["realtime", "realtime_loop", "transport", "transport_longpoll", "transport_sse"];
|
|
33
33
|
/** The runtime file names an SDK with `features` ships, in code-unit order. */
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* so the two can never disagree.
|
|
7
7
|
*/
|
|
8
8
|
import { checked, SEMVER } from "../shared/metadata.js";
|
|
9
|
-
|
|
9
|
+
// a dotted domain, then path elements (Go's module.CheckPath, less its rarely used characters)
|
|
10
10
|
const MODULE_PATH = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+(?:\/[A-Za-z0-9_~-](?:[A-Za-z0-9._~-]*[A-Za-z0-9_~-])?)*$/;
|
|
11
|
-
|
|
11
|
+
// a last element Go reads as a major version suffix, and the ones it takes
|
|
12
12
|
const SUFFIX = /\/v[\d.]+$/;
|
|
13
13
|
const MAJOR = /\/v(?:[2-9]|[1-9]\d+)$/;
|
|
14
14
|
/** `modulePath` with the major suffix `version` gives from v2 on, each refused unless Go would take it. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** The runtime call's arguments: the ctx, the client's config, the call, each of `extra`, then the per-call options. */
|
|
2
2
|
export const sendArgs = (client, ...extra) => ["ctx", `${client}.cfg`, "c", ...extra, "reqOpts"].join(", ");
|
|
3
|
-
|
|
3
|
+
// an operation answering without a body
|
|
4
4
|
const NO_BODY_SHAPE = {
|
|
5
5
|
fail: "err",
|
|
6
6
|
returns: "error",
|
package/dist/emit/go/sdk-body.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { goString, lineComment } from "../shared/escape.js";
|
|
2
2
|
import { goExported, NameScope } from "../shared/lang.js";
|
|
3
3
|
import { goTypeOf } from "./types.js";
|
|
4
|
-
|
|
4
|
+
// a body sent as it is: nothing to encode first
|
|
5
5
|
const NO_LINES = () => [];
|
|
6
|
-
|
|
6
|
+
// a text part's Go type by its scalar type (v0 codegen-go.ts:382-391); any other schema is sent as a string
|
|
7
7
|
const PART_SCALARS = {
|
|
8
8
|
boolean: "bool",
|
|
9
9
|
integer: "int64",
|
|
@@ -15,7 +15,7 @@ const PART_SCALARS = {
|
|
|
15
15
|
const appended = (indent, part) => `${indent}fields = append(fields, ${part})`;
|
|
16
16
|
/** The field of `part` named `name` on the body `local`: a list repeats the part, an unset value sends none. */
|
|
17
17
|
function partField(part, name, local, at) {
|
|
18
|
-
|
|
18
|
+
// the IR gives every part its schema (ir/slots.ts partsOf, sdk-model bodyOf)
|
|
19
19
|
const schema = at.names.resolve(part.schema);
|
|
20
20
|
const list = schema.kind === "array";
|
|
21
21
|
const item = schema.kind === "array" ? at.names.resolve(schema.items) : schema;
|
|
@@ -64,13 +64,17 @@ export function goBody(op, body, env) {
|
|
|
64
64
|
const type = goTypeOf(body.schema, { ...env.at, fieldName: "Body", parentName: op.id });
|
|
65
65
|
return { lines: NO_LINES, send: `jsonBody(${local})`, type };
|
|
66
66
|
}
|
|
67
|
-
case "form":
|
|
67
|
+
case "form": {
|
|
68
68
|
return { lines: NO_LINES, send: `formBody(${local})`, type: "url.Values" };
|
|
69
|
-
|
|
69
|
+
}
|
|
70
|
+
case "binary": {
|
|
70
71
|
return { lines: NO_LINES, send: `readerBody(${local}, ${contentType})`, type: "io.Reader" };
|
|
71
|
-
|
|
72
|
+
}
|
|
73
|
+
case "text": {
|
|
72
74
|
return { lines: NO_LINES, send: `rawBody([]byte(${local}), ${contentType})`, type: "string" };
|
|
73
|
-
|
|
75
|
+
}
|
|
76
|
+
case "multipart": {
|
|
74
77
|
return multipartBody(op, body.parts, env);
|
|
78
|
+
}
|
|
75
79
|
}
|
|
76
80
|
}
|