@workerstack/clients 1.0.0-rc.29 → 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 +373 -14
- 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 +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 +0 -1
- package/dist/emit/csharp/sdk-method.js +10 -6
- 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 -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.js +2 -2
- 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.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 +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 +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 +1 -10
- package/dist/emit/java/sdk-op.js +8 -8
- 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 +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.js +5 -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 +7 -7
- 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.js +2 -2
- 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 +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 +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 +2 -2
- package/dist/emit/ts/sdk-types.js +11 -11
- package/dist/emit/ts/sdk.js +4 -4
- package/dist/emit/ts/service-map.d.ts +2 -1
- package/dist/emit/ts/tanstack-query.js +6 -6
- 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/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 +8 -5
- package/dist/ir/load.js +9 -10
- package/dist/ir/model.d.ts +2 -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.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 +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/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/ts-tanstack-query/query.ts +0 -2
- package/package.json +10 -7
- 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
|
@@ -19,8 +19,6 @@ export type InstallApp = {
|
|
|
19
19
|
readonly prefix: string;
|
|
20
20
|
readonly installUrl: string;
|
|
21
21
|
};
|
|
22
|
-
/** The issuer of the OIDC token a GitHub Actions run signs with. */
|
|
23
|
-
export declare const ISSUER = "https://token.actions.githubusercontent.com";
|
|
24
22
|
/**
|
|
25
23
|
* The `npx` that runs installgen from the clients release that wrote the scripts: the release workflow's `check` runs
|
|
26
24
|
* it on installgen.config.mts in the module's root, so the scripts and their check always come from one release.
|
|
@@ -30,11 +28,5 @@ export declare function installgenCommand(): string;
|
|
|
30
28
|
export declare const INSTALLGEN_CONFIG = "installgen.config.mts";
|
|
31
29
|
/** installgen's config for `app`, its files under `base` (the repository's GitHub Releases outside a test). */
|
|
32
30
|
export declare function installerConfig(app: InstallApp, base?: string): InstallgenConfig;
|
|
33
|
-
/**
|
|
34
|
-
* `installgen.config.mts` for `app`: `installerConfig`'s config as a module installgen loads with no local install
|
|
35
|
-
* (its one import is type-only, which Node 22.18+ strips), so `installgenCommand()`'s `check` runs in the module's root
|
|
36
|
-
* with nothing installed.
|
|
37
|
-
*/
|
|
38
|
-
export declare function installgenConfigFile(app: InstallApp): string;
|
|
39
31
|
/** `install.sh`, `install.ps1` and `installgen.config.mts` for `app`, by file name. */
|
|
40
32
|
export declare function installFiles(app: InstallApp): Record<string, string>;
|
package/dist/emit/cli/install.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import { generateInstallers } from "../../installers/index.js";
|
|
15
15
|
import { clientsVersion } from "../../version.js";
|
|
16
16
|
/** The issuer of the OIDC token a GitHub Actions run signs with. */
|
|
17
|
-
|
|
17
|
+
const ISSUER = "https://token.actions.githubusercontent.com";
|
|
18
18
|
/**
|
|
19
19
|
* The `npx` that runs installgen from the clients release that wrote the scripts: the release workflow's `check` runs
|
|
20
20
|
* it on installgen.config.mts in the module's root, so the scripts and their check always come from one release.
|
|
@@ -60,7 +60,7 @@ export function installerConfig(app, base = `https://github.com/${app.repo}/rele
|
|
|
60
60
|
* (its one import is type-only, which Node 22.18+ strips), so `installgenCommand()`'s `check` runs in the module's root
|
|
61
61
|
* with nothing installed.
|
|
62
62
|
*/
|
|
63
|
-
|
|
63
|
+
function installgenConfigFile(app) {
|
|
64
64
|
const installgen = installgenCommand();
|
|
65
65
|
const { asset, checksums, identity, plain } = layout(app, `https://github.com/${app.repo}/releases`);
|
|
66
66
|
const value = (key) => `\t${key}: ${JSON.stringify(plain[key])},\n`;
|
|
@@ -83,7 +83,7 @@ ${value("envPrefix")}${value("installDir")}${value("latestPath")}${value("messag
|
|
|
83
83
|
/** `install.sh`, `install.ps1` and `installgen.config.mts` for `app`, by file name. */
|
|
84
84
|
export function installFiles(app) {
|
|
85
85
|
const { ps1, sh } = generateInstallers(installerConfig(app));
|
|
86
|
-
|
|
86
|
+
// every platform is configured, so installgen writes both
|
|
87
87
|
const scripts = [
|
|
88
88
|
["install.ps1", ps1],
|
|
89
89
|
["install.sh", sh],
|
|
@@ -10,7 +10,7 @@ import { type Entry } from "./discovery.ts";
|
|
|
10
10
|
/** The CLI's name, description and environment prefix, and its module. */
|
|
11
11
|
export type CliApp = {
|
|
12
12
|
/** the base URL the root command is built with; none when the document declares no server */
|
|
13
|
-
readonly baseUrl?: string;
|
|
13
|
+
readonly baseUrl?: string | undefined;
|
|
14
14
|
readonly binaryName: string;
|
|
15
15
|
readonly short: string;
|
|
16
16
|
readonly envPrefix: string;
|
package/dist/emit/cli/layout.js
CHANGED
|
@@ -4,12 +4,15 @@ import { compareCodeUnits, NameScope, snakeWords } from "../shared/lang.js";
|
|
|
4
4
|
import { groupFuncs } from "./commands.js";
|
|
5
5
|
import { discoveryBody } from "./discovery.js";
|
|
6
6
|
import { helpText } from "./flags.js";
|
|
7
|
-
|
|
7
|
+
// the marker gopls and linters read, apart from the package doc by a blank line
|
|
8
8
|
const MARKER = "// Code generated by clients. DO NOT EDIT.";
|
|
9
9
|
/** What a cmd file imports, by the packages its code names: the runtime always. */
|
|
10
10
|
const importsOf = (text) => {
|
|
11
11
|
const code = text.replace(NOT_CODE, "");
|
|
12
|
-
return [
|
|
12
|
+
return [
|
|
13
|
+
"cli",
|
|
14
|
+
...["cobra", "errors", "http", "json", "sdk"].filter((name) => new RegExp(`\\b${name}\\.`).test(code)),
|
|
15
|
+
];
|
|
13
16
|
};
|
|
14
17
|
/** Each package a cmd file may import, by name, in its import group: the standard library, cobra, the module's own. */
|
|
15
18
|
const PACKAGES = {
|
|
@@ -34,7 +37,7 @@ function cmdFile(module, body, doc = "") {
|
|
|
34
37
|
return `${MARKER}\n\n${doc}package cmd\n\nimport (\n${block}\n)\n\n${body}\n`;
|
|
35
38
|
}
|
|
36
39
|
/** cmd/root.go: the root command, named by the binary, its skill given, its top-level commands its API ones. */
|
|
37
|
-
function rootBody(app,
|
|
40
|
+
function rootBody(app, nodes) {
|
|
38
41
|
const fields = [
|
|
39
42
|
`Name: ${goString(app.binaryName)}`,
|
|
40
43
|
`Short: ${goString(helpText(app.short))}`,
|
|
@@ -55,15 +58,15 @@ function rootBody(app, ir, nodes) {
|
|
|
55
58
|
* cmd/client.go: the SDK client the run's settings configure, its requests and responses logged under --verbose, and
|
|
56
59
|
* an answer outside 2xx as the runtime's APIError. An API that declares no server needs a base URL set.
|
|
57
60
|
*/
|
|
58
|
-
function clientBody(app
|
|
61
|
+
function clientBody(app) {
|
|
59
62
|
const env = `$${app.envPrefix}_BASE_URL`;
|
|
60
|
-
const noServer = app.baseUrl
|
|
61
|
-
? [
|
|
62
|
-
: [
|
|
63
|
+
const noServer = app.baseUrl === undefined
|
|
64
|
+
? [
|
|
63
65
|
'\tif s.BaseURL == "" {',
|
|
64
66
|
`\t\treturn nil, cli.Usage(${goString(`no base URL: set --base-url, ${env} or base_url in the config file`)})`,
|
|
65
67
|
"\t}",
|
|
66
|
-
]
|
|
68
|
+
]
|
|
69
|
+
: [];
|
|
67
70
|
return [
|
|
68
71
|
"// newClient is the API client the run's settings configure.",
|
|
69
72
|
"func newClient(c *cobra.Command) (*sdk.Client, error) {",
|
|
@@ -104,9 +107,9 @@ function clientBody(app, ir) {
|
|
|
104
107
|
export function cmdFiles(app, ir, nodes, entries) {
|
|
105
108
|
const stems = new NameScope(["client", "root"]);
|
|
106
109
|
const files = {
|
|
107
|
-
"cmd/client.go": cmdFile(app.modulePath, clientBody(app
|
|
110
|
+
"cmd/client.go": cmdFile(app.modulePath, clientBody(app)),
|
|
108
111
|
"cmd/discovery.go": cmdFile(app.modulePath, discoveryBody(entries)),
|
|
109
|
-
"cmd/root.go": cmdFile(app.modulePath, rootBody(app,
|
|
112
|
+
"cmd/root.go": cmdFile(app.modulePath, rootBody(app, nodes), `// Package cmd holds the ${app.binaryName} commands.\n`),
|
|
110
113
|
};
|
|
111
114
|
for (const node of nodes) {
|
|
112
115
|
const body = groupFuncs(node, [], ir)
|
|
@@ -2,20 +2,20 @@ import { type PackageIdentity } from "../shared/metadata.ts";
|
|
|
2
2
|
import { type ReleaseOptions } from "./release.ts";
|
|
3
3
|
export type GoCliOptions = ReleaseOptions & {
|
|
4
4
|
/** the binary and root command name: lowercase words joined by `-`, at most 64 characters; the title's, else `api` */
|
|
5
|
-
readonly binaryName?: string;
|
|
5
|
+
readonly binaryName?: string | undefined;
|
|
6
6
|
/** the module path go.mod declares, a domain first; `example.com/<binaryName>` by default */
|
|
7
|
-
readonly modulePath?: string;
|
|
7
|
+
readonly modulePath?: string | undefined;
|
|
8
8
|
/** the module's version, semver: from v2 on, its major suffix (`/v2`) ends the module path */
|
|
9
|
-
readonly version?: string;
|
|
9
|
+
readonly version?: string | undefined;
|
|
10
10
|
/** the environment variables' prefix: uppercase words joined by `_`; the binary name's by default */
|
|
11
|
-
readonly envPrefix?: string;
|
|
11
|
+
readonly envPrefix?: string | undefined;
|
|
12
12
|
/** the GitHub repository the release is published to, `owner/name`; none by default (then no install scripts) */
|
|
13
|
-
readonly repo?: string;
|
|
13
|
+
readonly repo?: string | undefined;
|
|
14
14
|
/**
|
|
15
15
|
* the base URL the binary calls by default, absolute; the document's first server by default. A document
|
|
16
16
|
* served under a path (a gateway's `servers: [{ url: "/api" }]`) names no host a CLI can call, so it needs this.
|
|
17
17
|
*/
|
|
18
|
-
readonly baseUrl?: string;
|
|
18
|
+
readonly baseUrl?: string | undefined;
|
|
19
19
|
};
|
|
20
20
|
export type GeneratedGoCli = {
|
|
21
21
|
readonly files: Readonly<Record<string, string>>;
|
package/dist/emit/cli/module.js
CHANGED
|
@@ -11,17 +11,17 @@
|
|
|
11
11
|
import { readFileSync } from "node:fs";
|
|
12
12
|
import { toIR } from "../../ir/build.js";
|
|
13
13
|
import { sdkModel } from "../../ir/sdk-model.js";
|
|
14
|
-
import { compareCodeUnits } from "../shared/lang.js";
|
|
15
|
-
import { packageOn } from "../shared/metadata.js";
|
|
16
14
|
import { goModulePath } from "../go/module-path.js";
|
|
17
15
|
import { generateGoSdk, goCallPlans, WEBSOCKET, WEBSOCKET_SUM } from "../go/sdk.js";
|
|
16
|
+
import { compareCodeUnits } from "../shared/lang.js";
|
|
17
|
+
import { packageOn } from "../shared/metadata.js";
|
|
18
18
|
import { commandTree } from "./commands.js";
|
|
19
19
|
import { discoveryEntries } from "./discovery.js";
|
|
20
20
|
import { installFiles } from "./install.js";
|
|
21
21
|
import { cmdFiles } from "./layout.js";
|
|
22
22
|
import { goreleaserFile, releaseWorkflow, REPO, resolvedRelease } from "./release.js";
|
|
23
23
|
import { skillFile, skillPath } from "./skills.js";
|
|
24
|
-
|
|
24
|
+
// the marker gopls and linters read, apart from the package doc by a blank line
|
|
25
25
|
const MARKER = "// Code generated by clients. DO NOT EDIT.";
|
|
26
26
|
/** The runtime files a CLI ships, read from `runtime/cli/` and nowhere else; SOCKET only beside the WebSocket library. */
|
|
27
27
|
export const CLI_RUNTIME = [
|
|
@@ -39,7 +39,7 @@ export const CLI_RUNTIME = [
|
|
|
39
39
|
];
|
|
40
40
|
/** The runtime file that names the WebSocket library: shipped only when the SDK requires it. */
|
|
41
41
|
const SOCKET = "socket.go";
|
|
42
|
-
|
|
42
|
+
// the CLI's own requirements and their go.sum lines, exactly as `go mod tidy` writes them
|
|
43
43
|
const DIRECT = [
|
|
44
44
|
"github.com/pelletier/go-toml/v2 v2.4.3",
|
|
45
45
|
"github.com/spf13/cobra v1.10.2",
|
|
@@ -61,11 +61,11 @@ const SUM = [
|
|
|
61
61
|
"go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=",
|
|
62
62
|
"gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=",
|
|
63
63
|
];
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
// a binary: lowercase words joined by `-`, at most 64 characters (its agent skill's name is the binary's); an
|
|
65
|
+
// environment prefix: uppercase words joined by `_`
|
|
66
66
|
const BINARY_NAME = /^(?=.{1,64}$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
67
67
|
const ENV_PREFIX = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
68
|
-
|
|
68
|
+
// a base URL a CLI can call: a scheme and a host, never a path alone
|
|
69
69
|
const ABSOLUTE_URL = /^https?:\/\/[^\s/]+/;
|
|
70
70
|
const refuse = (option, value) => {
|
|
71
71
|
throw new Error(`Invalid ${option}: ${JSON.stringify(value)}`);
|
|
@@ -73,8 +73,8 @@ const refuse = (option, value) => {
|
|
|
73
73
|
/** The binary name a title gives: its letters and digits, lowercased, joined by `-`; `api` when it has none. */
|
|
74
74
|
export const binaryNameOf = (title) => (title ?? "")
|
|
75
75
|
.toLowerCase()
|
|
76
|
-
.
|
|
77
|
-
.
|
|
76
|
+
.replaceAll(/[^a-z0-9]+/g, "-")
|
|
77
|
+
.replaceAll(/^[^a-z]+|-+$/g, "") || "api";
|
|
78
78
|
/**
|
|
79
79
|
* The base URL the binary calls: the option, else the document's first server when that is absolute. A relative
|
|
80
80
|
* server is no base URL a CLI can call — a gateway's document says `servers: [{ url: "/api" }]` — so it is left
|
|
@@ -103,7 +103,7 @@ function resolved(options, title) {
|
|
|
103
103
|
return { baseUrl: options.baseUrl, binaryName, envPrefix, modulePath, repo: options.repo };
|
|
104
104
|
}
|
|
105
105
|
/** A go.sum line's order key: its module path, then its version with each number zero-padded, as Go sorts them. */
|
|
106
|
-
const sumKey = (line) => line.
|
|
106
|
+
const sumKey = (line) => line.replaceAll(/\d+/g, (digits) => digits.padStart(20, "0"));
|
|
107
107
|
/** A require directive as `go mod tidy` writes it: one requirement on its line, more in a block. */
|
|
108
108
|
const requireOf = (lines) => lines.length === 1 ? `require ${lines[0]}\n` : `require (\n${lines.map((line) => `\t${line}`).join("\n")}\n)\n`;
|
|
109
109
|
/** go.mod and go.sum: the CLI's requirements, and the WebSocket library's when the embedded SDK needs it. */
|
|
@@ -18,19 +18,8 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { type Release } from "./channels.ts";
|
|
20
20
|
export { REPO, type Release, type ReleaseOptions, resolvedRelease } from "./channels.ts";
|
|
21
|
-
/** The tools release.yml runs, each pinned by commit (its release in the comment beside it). */
|
|
22
|
-
export declare const RELEASE_ACTIONS: {
|
|
23
|
-
attest: string;
|
|
24
|
-
checkout: string;
|
|
25
|
-
cosign: string;
|
|
26
|
-
goreleaser: string;
|
|
27
|
-
setupGo: string;
|
|
28
|
-
setupNode: string;
|
|
29
|
-
};
|
|
30
21
|
/** A value as a YAML double-quoted scalar (a JSON string is one): a name like `true` or `1e3` stays a string. */
|
|
31
22
|
export declare const q: (value: string) => string;
|
|
32
|
-
/** The goreleaser release the action installs: the one the tests check the config with. */
|
|
33
|
-
export declare const GORELEASER_VERSION = "v2.18.3";
|
|
34
23
|
/** .goreleaser.yaml for the CLI `bin` in module `modulePath`, released per `release` when it names a repository. */
|
|
35
24
|
export declare function goreleaserFile(bin: string, modulePath: string, release: Release | undefined): string;
|
|
36
25
|
/**
|
package/dist/emit/cli/release.js
CHANGED
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
import { channelBlock, SECRETS } from "./channels.js";
|
|
20
20
|
import { installgenCommand } from "./install.js";
|
|
21
21
|
export { REPO, resolvedRelease } from "./channels.js";
|
|
22
|
-
|
|
22
|
+
// the marker generated YAML carries on its first line
|
|
23
23
|
const MARKER = "# Code generated by clients. DO NOT EDIT.";
|
|
24
24
|
/** The tools release.yml runs, each pinned by commit (its release in the comment beside it). */
|
|
25
|
-
|
|
25
|
+
const RELEASE_ACTIONS = {
|
|
26
26
|
attest: "actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2",
|
|
27
27
|
checkout: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1",
|
|
28
28
|
cosign: "sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2",
|
|
@@ -33,10 +33,10 @@ export const RELEASE_ACTIONS = {
|
|
|
33
33
|
/** A value as a YAML double-quoted scalar (a JSON string is one): a name like `true` or `1e3` stays a string. */
|
|
34
34
|
export const q = (value) => JSON.stringify(value);
|
|
35
35
|
/** The goreleaser release the action installs: the one the tests check the config with. */
|
|
36
|
-
|
|
36
|
+
const GORELEASER_VERSION = "v2.18.3";
|
|
37
37
|
/** .goreleaser.yaml for the CLI `bin` in module `modulePath`, released per `release` when it names a repository. */
|
|
38
38
|
export function goreleaserFile(bin, modulePath, release) {
|
|
39
|
-
|
|
39
|
+
// without a repository, goreleaser releases to the git remote's, and there is no version file to serve
|
|
40
40
|
const before = release === undefined
|
|
41
41
|
? ""
|
|
42
42
|
: `# the release's tag, which the install scripts read through releases/latest/download
|
package/dist/emit/cli/skills.js
CHANGED
|
@@ -7,8 +7,8 @@ export const skillPath = (binaryName) => `skills/${binaryName}/SKILL.md`;
|
|
|
7
7
|
const streamsOf = (ops) => ["sse", "ws", "realtime"].filter((kind) => ops.some((op) => op.stream === kind));
|
|
8
8
|
/** SKILL.md for the CLI `bin` over the API `title` and its operations, its env variables prefixed `prefix`. */
|
|
9
9
|
export function skillFile(bin, title, prefix, ops) {
|
|
10
|
-
const named = [...(helpText(title).
|
|
11
|
-
|
|
10
|
+
const named = [...(helpText(title).replaceAll(/\s+/g, " ").trim() || bin)];
|
|
11
|
+
// the description stays within the format's 1024 characters whatever the title
|
|
12
12
|
const api = named.length <= TITLE_MAX ? named.join("") : `${named.slice(0, TITLE_MAX - 1).join("")}…`;
|
|
13
13
|
const description = `Call the ${api} API from the shell with ${bin}: find a command, read its request and answer, call it, and branch on its JSON output and exit code.`;
|
|
14
14
|
const streams = streamsOf(ops);
|
|
@@ -32,7 +32,7 @@ export function skillFile(bin, title, prefix, ops) {
|
|
|
32
32
|
return [
|
|
33
33
|
"---",
|
|
34
34
|
`name: ${bin}`,
|
|
35
|
-
|
|
35
|
+
// a JSON string is a YAML double-quoted scalar: a colon or quote in the title cannot end it
|
|
36
36
|
`description: ${JSON.stringify(description)}`,
|
|
37
37
|
"---",
|
|
38
38
|
"",
|
|
@@ -3,12 +3,12 @@ import { csString } from "../shared/escape.js";
|
|
|
3
3
|
import { compareCodeUnits, csTypeName, NameScope } from "../shared/lang.js";
|
|
4
4
|
import { docLines } from "./sdk-doc.js";
|
|
5
5
|
import { csTopLevel, declares } from "./types.js";
|
|
6
|
-
|
|
6
|
+
// the class's own name (CS0542) and the members a static class would hide (CS0108 under warnings as errors)
|
|
7
7
|
const RESERVED = ["ErrorKey", "Equals", "GetHashCode", "GetType", "MemberwiseClone", "ReferenceEquals", "ToString"];
|
|
8
8
|
/** The keys an error response's envelope names, over every operation's JSON error statuses. */
|
|
9
9
|
function envelopeKeys(model) {
|
|
10
10
|
return model.ops.flatMap((op) => op.errorStatuses.flatMap((status) => {
|
|
11
|
-
|
|
11
|
+
// an error status is a declared response, and a schema comes with the content type it is under
|
|
12
12
|
const { contentType, schema } = op.ir.responses[String(status)];
|
|
13
13
|
if (schema === undefined || !isJsonMedia(contentType))
|
|
14
14
|
return [];
|
|
@@ -37,7 +37,7 @@ function bodyType(key, schema, model, at) {
|
|
|
37
37
|
if (!declares(schema) || irErrorEnvelope(schema, model.resolve) !== null)
|
|
38
38
|
return undefined;
|
|
39
39
|
const name = at.names.claim(`${csTypeName(key)}Data`);
|
|
40
|
-
|
|
40
|
+
// claimed before its body: what the body hoists in turn comes after it
|
|
41
41
|
at.decls.set(name, "");
|
|
42
42
|
at.decls.set(name, csTopLevel(name, schema, at));
|
|
43
43
|
return name;
|
|
@@ -56,7 +56,7 @@ export function csharpErrorKeys(model, at) {
|
|
|
56
56
|
member: members.claim(csTypeName(wire)),
|
|
57
57
|
wire,
|
|
58
58
|
}));
|
|
59
|
-
const decoded = keys.flatMap(({ data, wire }) =>
|
|
59
|
+
const decoded = keys.flatMap(({ data, wire }) => data === undefined ? [] : [`${wire}: its body decodes as ${data}`]);
|
|
60
60
|
const remark = decoded.map((line, i) => `${line}${i === 0 ? " (ApiStatusException.DecodeBody)" : ""}.`).join(" ");
|
|
61
61
|
return [
|
|
62
62
|
"/// <summary>The error keys the API declares: ApiStatusException.Key is one of these, else the server's own string.</summary>",
|
package/dist/emit/csharp/json.js
CHANGED
|
@@ -7,19 +7,19 @@
|
|
|
7
7
|
* annotations are erased at run time, so such a type stays lenient everywhere).
|
|
8
8
|
*/
|
|
9
9
|
import { compareCodeUnits, NameScope } from "../shared/lang.js";
|
|
10
|
-
|
|
10
|
+
// the value types emitted text spells, besides the declared enums: `T?` of one is `Nullable<T>` at run time
|
|
11
11
|
const VALUE_TYPES = ["bool", "double", "JsonElement", "long"];
|
|
12
|
-
|
|
12
|
+
// the names the generator gives the BCL types it lists, which the context's own names follow
|
|
13
13
|
const BCL_NAMES = {
|
|
14
|
+
JsonElement: "JsonElement",
|
|
14
15
|
bool: "Boolean",
|
|
15
16
|
double: "Double",
|
|
16
|
-
JsonElement: "JsonElement",
|
|
17
17
|
long: "Int64",
|
|
18
18
|
string: "String",
|
|
19
19
|
};
|
|
20
20
|
const LIST = /^IReadOnlyList<(.*)>$/;
|
|
21
21
|
const MAP = /^IReadOnlyDictionary<string, (.*)>$/;
|
|
22
|
-
|
|
22
|
+
// the context's own members and the members every class has: no TypeInfoPropertyName may take one
|
|
23
23
|
const CONTEXT_MEMBERS = [
|
|
24
24
|
"Default",
|
|
25
25
|
"Equals",
|
|
@@ -78,13 +78,13 @@ export function strictConverters(collections, runtime) {
|
|
|
78
78
|
const lenient = new Set();
|
|
79
79
|
const strict = new Set();
|
|
80
80
|
for (const type of collections) {
|
|
81
|
-
const list = LIST.
|
|
82
|
-
const item = list
|
|
81
|
+
const list = LIST.test(type);
|
|
82
|
+
const item = type.replace(list ? LIST : MAP, "$1");
|
|
83
83
|
const base = runtime(item).replace(/\?$/, "");
|
|
84
|
-
|
|
84
|
+
// a value type keeps its `?` at run time: its null item fails the read already (Q2)
|
|
85
85
|
if (runtime(`${base}?`).endsWith("?"))
|
|
86
86
|
continue;
|
|
87
|
-
const converter = `typeof(${list
|
|
87
|
+
const converter = `typeof(${list ? "NonNullList" : "NonNullMap"}<${base}>)`;
|
|
88
88
|
(item.endsWith("?") ? lenient : strict).add(converter);
|
|
89
89
|
}
|
|
90
90
|
return [...strict].filter((converter) => !lenient.has(converter)).sort(compareCodeUnits);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { eventType } from "./sdk-answer.js";
|
|
2
2
|
import { isLastEventIdHeader } from "./sse.js";
|
|
3
|
-
import { JSON_ELEMENT } from "./types.js";
|
|
4
3
|
import { messageType, valueHandlers } from "./types-messages.js";
|
|
4
|
+
import { JSON_ELEMENT } from "./types.js";
|
|
5
5
|
import { isReconnectToken } from "./ws.js";
|
|
6
|
-
|
|
6
|
+
// the connection, and its own event: a member whose On<Value> it names gets none
|
|
7
7
|
const READER = { base: "ResumableConnection", handlers: ["OnMessage"], receiver: "connection" };
|
|
8
8
|
/** The realtime operation `op`'s answer, its message types hoisted into `env.at`. */
|
|
9
9
|
function realtimeAnswer(op, env) {
|
|
@@ -24,7 +24,7 @@ function realtimeAnswer(op, env) {
|
|
|
24
24
|
export const realtimeStream = {
|
|
25
25
|
answer: realtimeAnswer,
|
|
26
26
|
args: ["(transport ?? new()).Copy()"],
|
|
27
|
-
|
|
27
|
+
// the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID
|
|
28
28
|
carries: (name, where) => isReconnectToken(name, where) ||
|
|
29
29
|
(where === "query" && name === "last_event_id") ||
|
|
30
30
|
isLastEventIdHeader(name, where),
|
|
@@ -35,17 +35,17 @@ function declaredHeaders(op) {
|
|
|
35
35
|
.filter((status) => /^2(?:\d\d|XX)$/i.test(status))
|
|
36
36
|
.sort(compareCodeUnits)
|
|
37
37
|
.flatMap((status) => op.ir.responses[status].headers ?? []);
|
|
38
|
-
|
|
38
|
+
// reversed, so the first spelling of a name is the one its key ends on
|
|
39
39
|
const first = new Map(all.toReversed().map((header) => [header.name.toLowerCase(), header]));
|
|
40
40
|
return [...first.values()].sort((a, b) => compareCodeUnits(a.name, b.name));
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
// a scalar header's C# type and its reader; anything else is its text
|
|
43
43
|
const READERS = {
|
|
44
44
|
boolean: ["bool?", "Bool"],
|
|
45
45
|
integer: ["long?", "Int64"],
|
|
46
46
|
number: ["double?", "Double"],
|
|
47
47
|
};
|
|
48
|
-
|
|
48
|
+
// the holder's own members and the members every class has
|
|
49
49
|
const HOLDER_MEMBERS = ["Equals", "Finalize", "GetHashCode", "GetType", "MemberwiseClone", "Read", "ToString"];
|
|
50
50
|
/** `<Op>Headers` hoisted into `env.at.decls` (never listed), and its plan; null when `op` declares none. */
|
|
51
51
|
export function csResponseHeaders(op, env) {
|
|
@@ -77,7 +77,7 @@ export function csResponseHeaders(op, env) {
|
|
|
77
77
|
"",
|
|
78
78
|
" internal void Read(IReadOnlyDictionary<string, string> headers)",
|
|
79
79
|
" {",
|
|
80
|
-
...fields.map((f) => ` ${f.property} = ResponseHeaders.${f.reader}(headers, ${csString(f.header)}, required: ${f.required
|
|
80
|
+
...fields.map((f) => ` ${f.property} = ResponseHeaders.${f.reader}(headers, ${csString(f.header)}, required: ${f.required});`),
|
|
81
81
|
" }",
|
|
82
82
|
"}",
|
|
83
83
|
].join("\n"));
|
|
@@ -6,13 +6,13 @@ import { csTypeOf } from "./types.js";
|
|
|
6
6
|
const NONE = { expr: () => "null", type: null, types: [] };
|
|
7
7
|
/** The parts the body schema of `op` requires: none unless it is an object. */
|
|
8
8
|
function requiredParts(op, env) {
|
|
9
|
-
|
|
9
|
+
// a multipart body, with file parts or text parts alone, is declared with its form's schema
|
|
10
10
|
const form = env.at.names.resolve(op.ir.body.schema);
|
|
11
11
|
return new Set(form.kind === "object" ? form.fields.flatMap((f) => (f.required ? [f.name] : [])) : []);
|
|
12
12
|
}
|
|
13
13
|
/** The C# type of `part` as a property of `parent`: `FilePart` or its list for a file, its schema's type for text. */
|
|
14
14
|
function partType(part, parent, env) {
|
|
15
|
-
|
|
15
|
+
// the IR gives every part its schema (ir/slots.ts partsOf, ir/sdk-model.ts bodyOf)
|
|
16
16
|
const schema = part.schema;
|
|
17
17
|
if (part.type === "text")
|
|
18
18
|
return csTypeOf(schema, { ...env.at, fieldName: part.name, parentName: parent });
|
|
@@ -21,7 +21,7 @@ function partType(part, parent, env) {
|
|
|
21
21
|
/** `<Op>Body` for `parts`, declared once into `env.at.decls` and never listed; its name and its parts. */
|
|
22
22
|
function multipartBody(op, parts, env) {
|
|
23
23
|
const name = env.at.names.hoist(`${op.id}.Body`, `${csTypeName(op.id)}Body`);
|
|
24
|
-
|
|
24
|
+
// claimed before its parts: what a text part hoists in turn comes after it
|
|
25
25
|
env.at.decls.set(name, "");
|
|
26
26
|
env.at.unlisted.add(name);
|
|
27
27
|
const required = requiredParts(op, env);
|
|
@@ -30,7 +30,7 @@ function multipartBody(op, parts, env) {
|
|
|
30
30
|
.sort((a, b) => compareCodeUnits(a.name, b.name))
|
|
31
31
|
.map((part) => {
|
|
32
32
|
const type = partType(part, name, env);
|
|
33
|
-
|
|
33
|
+
// a part left unset is null: a value type's `?` makes it Nullable<T>, which the context lists
|
|
34
34
|
return {
|
|
35
35
|
file: part.type === "file",
|
|
36
36
|
name: part.name,
|
|
@@ -74,10 +74,12 @@ export function csBody(op, env) {
|
|
|
74
74
|
const type = schemaType(body.schema);
|
|
75
75
|
return { expr: (spell) => `Body.Form(body, ${spell.info(type)})`, type, types: [type] };
|
|
76
76
|
}
|
|
77
|
-
case "text":
|
|
77
|
+
case "text": {
|
|
78
78
|
return { expr: () => `Body.Text(body, ${media})`, type: "string", types: [] };
|
|
79
|
-
|
|
79
|
+
}
|
|
80
|
+
case "binary": {
|
|
80
81
|
return { expr: () => `Body.Binary(body, ${media})`, type: "BinaryBody", types: [] };
|
|
82
|
+
}
|
|
81
83
|
case "multipart": {
|
|
82
84
|
const { name, parts } = multipartBody(op, body.parts, env);
|
|
83
85
|
const expr = (spell) => guarded(op, `Body.Multipart([${parts.map((part) => partExpr(part, spell)).join(", ")}])`);
|
|
@@ -26,7 +26,7 @@ export type ClientEnv = MethodEnv & {
|
|
|
26
26
|
* them.
|
|
27
27
|
*/
|
|
28
28
|
export declare function clientDecls(ir: IR, env: ClientEnv): {
|
|
29
|
-
plans: CSharpCallPlan[];
|
|
30
|
-
text: (spell: Spelling) => string;
|
|
31
|
-
types: string[];
|
|
29
|
+
readonly plans: CSharpCallPlan[];
|
|
30
|
+
readonly text: (spell: Spelling) => string;
|
|
31
|
+
readonly types: string[];
|
|
32
32
|
};
|
|
@@ -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;
|