@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
package/bin/clients.js
CHANGED
|
@@ -2,93 +2,114 @@
|
|
|
2
2
|
// The clients bin (bit 17 phase h). A repository checkout (marked by tsconfig.json, which is not published)
|
|
3
3
|
// runs the TypeScript source, natively on Bun (under the backend-source condition) and through jiti on Node, so a stale
|
|
4
4
|
// dist/ never runs; an installed package runs the compiled JavaScript on any runtime (the tarball ships dist/, not src/).
|
|
5
|
-
import { spawn } from "node:child_process"
|
|
6
|
-
import { existsSync } from "node:fs"
|
|
7
|
-
import { basename } from "node:path"
|
|
8
|
-
import { fileURLToPath } from "node:url"
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { basename } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
9
|
|
|
10
|
-
const isBun = typeof globalThis.Bun !== "undefined"
|
|
11
|
-
const checkout = existsSync(new URL("../tsconfig.json", import.meta.url))
|
|
10
|
+
const isBun = typeof globalThis.Bun !== "undefined";
|
|
11
|
+
const checkout = existsSync(new URL("../tsconfig.json", import.meta.url));
|
|
12
12
|
|
|
13
13
|
// `bun run` and `bunx` start this file through its node shebang, while what they run is meant for Bun: hand over to
|
|
14
14
|
// the Bun that started us, which they name in npm_execpath. Once, never again in the child.
|
|
15
15
|
function invokingBun() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
if (isBun || process.env.CLIENTS_NO_BUN_HANDOFF === "1") return null;
|
|
17
|
+
|
|
18
|
+
if (!process.env.npm_config_user_agent?.startsWith("bun/")) return null;
|
|
19
|
+
const bun = process.env.npm_execpath;
|
|
20
|
+
|
|
21
|
+
if (!bun || !/^bunx?(\.exe)?$/.test(basename(bun)) || !existsSync(bun)) return null;
|
|
22
|
+
|
|
23
|
+
return bun;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
// The handoff: Bun runs this file with our arguments and `env` over ours; a signal we get is passed on to it, and we
|
|
24
27
|
// end as it ended, its exit code or the same signal.
|
|
25
28
|
function handOff(bun, env) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
// Forwarders first: a signal landing as spawn returns would otherwise end this process by its default action,
|
|
30
|
+
// orphaning the child. A handler runs from the event loop, after this block, so `child` is set by then.
|
|
31
|
+
let child;
|
|
32
|
+
const forward = (signal) => child.kill(signal);
|
|
33
|
+
|
|
34
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) process.on(signal, forward);
|
|
35
|
+
child = spawn(bun, [fileURLToPath(import.meta.url), ...process.argv.slice(2)], {
|
|
36
|
+
env: { ...process.env, ...env, CLIENTS_NO_BUN_HANDOFF: "1" },
|
|
37
|
+
stdio: "inherit",
|
|
38
|
+
});
|
|
39
|
+
child.on("error", (error) => {
|
|
40
|
+
console.error(`clients: could not start ${bun}: ${error.message}`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|
|
43
|
+
child.on("exit", (code, signal) => {
|
|
44
|
+
if (signal) {
|
|
45
|
+
for (const each of ["SIGINT", "SIGTERM", "SIGHUP"]) process.off(each, forward);
|
|
46
|
+
process.kill(process.pid, signal);
|
|
47
|
+
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
process.exit(code ?? 1);
|
|
52
|
+
});
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
// A checkout on Bun runs under the backend-source condition: an --app module's checkout core then resolves to its
|
|
50
56
|
// source, never to an unbuilt or stale dist/ (bit 20). Set through BUN_OPTIONS when the caller did not, in the one
|
|
51
57
|
// handoff, so a watch's generation children inherit it; Bun reports BUN_OPTIONS' flags in execArgv, so a Bun started
|
|
52
58
|
// with it never hands off again.
|
|
53
|
-
const SOURCE_CONDITION = "--conditions=backend-source"
|
|
54
|
-
const unconditioned = isBun && checkout && !process.execArgv.includes(SOURCE_CONDITION)
|
|
59
|
+
const SOURCE_CONDITION = "--conditions=backend-source";
|
|
60
|
+
const unconditioned = isBun && checkout && !process.execArgv.includes(SOURCE_CONDITION);
|
|
61
|
+
|
|
55
62
|
// The hand-off's backstop: its child carries CLIENTS_BUN_HANDOFF, the depth of hand-offs before it. A child that would
|
|
56
63
|
// hand off again (the condition set but not in its execArgv) refuses instead of re-running itself without end.
|
|
57
|
-
const handOffDepth = Number(process.env.CLIENTS_BUN_HANDOFF ?? 0)
|
|
64
|
+
const handOffDepth = Number(process.env.CLIENTS_BUN_HANDOFF ?? 0);
|
|
65
|
+
|
|
58
66
|
const sourceEnv = checkout
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
? {
|
|
68
|
+
BUN_OPTIONS: `${process.env.BUN_OPTIONS ?? ""} ${SOURCE_CONDITION}`.trim(),
|
|
69
|
+
CLIENTS_BUN_HANDOFF: String(handOffDepth + 1),
|
|
70
|
+
}
|
|
71
|
+
: {};
|
|
64
72
|
|
|
73
|
+
/**
|
|
74
|
+
* The module to run: the source, or the build compiled from it, typed as the source.
|
|
75
|
+
*
|
|
76
|
+
* @returns {Promise<typeof import("../src/cli.ts")>}
|
|
77
|
+
*/
|
|
65
78
|
async function entry() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
if (checkout) {
|
|
80
|
+
if (isBun) return import("../src/cli.ts");
|
|
81
|
+
const { createJiti } = await import("jiti");
|
|
82
|
+
|
|
83
|
+
return createJiti(import.meta.url).import("../src/cli.ts");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
// typed as the source it compiles from, so lint reads the same types with or without a build
|
|
88
|
+
return /** @type {typeof import("../src/cli.ts")} */ (await import("../dist/cli.js"));
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (error?.code === "ERR_MODULE_NOT_FOUND" && String(error.url).endsWith("/dist/cli.js")) {
|
|
91
|
+
console.error("clients: dist/ is missing from this install. Reinstall it, or run it with Bun.");
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
80
97
|
}
|
|
81
98
|
|
|
82
|
-
const bun = invokingBun()
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
const bun = invokingBun();
|
|
100
|
+
|
|
101
|
+
if (bun) {
|
|
102
|
+
handOff(bun, sourceEnv);
|
|
103
|
+
} else if (unconditioned && handOffDepth >= 1) {
|
|
104
|
+
console.error("clients: Bun hand-off loop: --conditions=backend-source not visible after re-exec");
|
|
105
|
+
process.exit(1);
|
|
106
|
+
} else if (unconditioned) {
|
|
107
|
+
handOff(process.execPath, sourceEnv);
|
|
108
|
+
} else {
|
|
109
|
+
const { main } = await entry();
|
|
110
|
+
const code = await main(process.argv.slice(2));
|
|
111
|
+
|
|
112
|
+
// an --app module may leave a timer or a socket open: the run is over once main returns, its output flushed
|
|
113
|
+
for (const stream of [process.stdout, process.stderr]) await new Promise((done) => stream.write("", done));
|
|
114
|
+
process.exit(code);
|
|
94
115
|
}
|
package/bin/installgen.js
CHANGED
|
@@ -2,18 +2,27 @@
|
|
|
2
2
|
// The installgen bin. A repository checkout (marked by tsconfig.json, which is not published) runs the TypeScript
|
|
3
3
|
// source, natively on Bun and through jiti on Node, so a stale build never runs; an installed package runs the
|
|
4
4
|
// compiled JavaScript (the tarball ships it, not src/).
|
|
5
|
-
import { existsSync } from "node:fs"
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
6
|
|
|
7
|
-
const checkout = existsSync(new URL("../tsconfig.json", import.meta.url))
|
|
7
|
+
const checkout = existsSync(new URL("../tsconfig.json", import.meta.url));
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* The module to run: the source, or the build compiled from it, typed as the source.
|
|
11
|
+
*
|
|
12
|
+
* @returns {Promise<typeof import("../src/installers/cli.ts")>}
|
|
13
|
+
*/
|
|
9
14
|
async function entry() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
if (checkout) {
|
|
16
|
+
if (typeof globalThis.Bun !== "undefined") return import("../src/installers/cli.ts");
|
|
17
|
+
const { createJiti } = await import("jiti");
|
|
18
|
+
|
|
19
|
+
return createJiti(import.meta.url).import("../src/installers/cli.ts");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// typed as the source it compiles from, so lint reads the same types with or without a build
|
|
23
|
+
return /** @type {Promise<typeof import("../src/installers/cli.ts")>} */ (import("../dist/installers/cli.js"));
|
|
16
24
|
}
|
|
17
25
|
|
|
18
|
-
const { start } = await entry()
|
|
19
|
-
|
|
26
|
+
const { start } = await entry();
|
|
27
|
+
|
|
28
|
+
await start();
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Metadata, type PackageIdentity } from "./emit/shared/metadata.ts";
|
|
2
|
-
import { type Target, type TargetOptions } from "./gen/targets.ts";
|
|
3
2
|
import { type ReadFile } from "./gen/shipped.ts";
|
|
3
|
+
import { type Target, type TargetOptions } from "./gen/targets.ts";
|
|
4
4
|
/**
|
|
5
5
|
* What one run generates: its targets, and each target's options by name (a target whose options are left out
|
|
6
6
|
* takes its generator's defaults). The CLI parses `generate` into one of these; a consumer writes one by hand.
|
|
@@ -86,17 +86,17 @@ export declare function writeGenerated(run: GenerateRun & {
|
|
|
86
86
|
/** What a run takes beside its arguments: the environment, the directory paths resolve from, a watch's stop signal. */
|
|
87
87
|
export type RunOptions = {
|
|
88
88
|
/** The directory the spec, the app module and `--out` resolve from. Defaults to the process's. */
|
|
89
|
-
readonly cwd?: string;
|
|
89
|
+
readonly cwd?: string | undefined;
|
|
90
90
|
/**
|
|
91
91
|
* The environment formatters are looked up in, laid over the process's for each `--watch` child. Defaults to the
|
|
92
92
|
* process's.
|
|
93
93
|
*/
|
|
94
|
-
readonly env?: NodeJS.ProcessEnv;
|
|
94
|
+
readonly env?: NodeJS.ProcessEnv | undefined;
|
|
95
95
|
/**
|
|
96
96
|
* Stops a `--watch` run, which ends with 0 once the generation in progress finishes. Without it a watch never
|
|
97
97
|
* returns.
|
|
98
98
|
*/
|
|
99
|
-
readonly signal?: AbortSignal;
|
|
99
|
+
readonly signal?: AbortSignal | undefined;
|
|
100
100
|
};
|
|
101
101
|
/** Runs `clients <argv>`: the exit code it ends with (a watch ends only by `options.signal`). */
|
|
102
102
|
export declare function main(argv: readonly string[], io?: Io, options?: RunOptions): Promise<number>;
|
package/dist/cli.js
CHANGED
|
@@ -19,22 +19,22 @@ import { generateMcpServer } from "./emit/mcp/server.js";
|
|
|
19
19
|
import { generatePythonSdk } from "./emit/python/sdk.js";
|
|
20
20
|
import { generateRustSdk } from "./emit/rust/sdk.js";
|
|
21
21
|
import { formatFiles } from "./emit/shared/format.js";
|
|
22
|
+
import { checkedMetadata, shippedOf } from "./emit/shared/metadata.js";
|
|
22
23
|
import { generateSdkPackage } from "./emit/ts/package.js";
|
|
23
24
|
import { parseGenerate, usage, UsageError } from "./gen/args.js";
|
|
24
25
|
import { FORMATTERS, formatterFor, missingFormatter } from "./gen/formatters.js";
|
|
25
26
|
import { runCli } from "./gen/process.js";
|
|
26
|
-
import { appRef, loadAppDocument } from "./ir/load.js";
|
|
27
|
-
import { checkedMetadata, shippedOf } from "./emit/shared/metadata.js";
|
|
28
|
-
import { optionsFor } from "./gen/targets.js";
|
|
29
27
|
import { shippedFiles } from "./gen/shipped.js";
|
|
28
|
+
import { optionsFor } from "./gen/targets.js";
|
|
30
29
|
import { writeTarget } from "./gen/write.js";
|
|
30
|
+
import { appRef, loadAppDocument } from "./ir/load.js";
|
|
31
31
|
import { release } from "./release/cli.js";
|
|
32
32
|
/** One SDK target's generation: its files, its package's identity on each registry, and what it reports (a name it renamed). */
|
|
33
33
|
function sdkOf(target, document, options, metadata) {
|
|
34
34
|
switch (target) {
|
|
35
|
-
case "ts":
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
case "ts": {
|
|
36
|
+
// mapped key by key, never spread: `options` holds strings, and `tanstackQuery` is a boolean —
|
|
37
|
+
// a spread under a cast would make "false" as truthy as "true"
|
|
38
38
|
return generateSdkPackage(document, {
|
|
39
39
|
name: options.name ?? "SDK",
|
|
40
40
|
...(options.packageName === undefined ? {} : { packageName: options.packageName }),
|
|
@@ -42,16 +42,22 @@ function sdkOf(target, document, options, metadata) {
|
|
|
42
42
|
tanstackQuery: options.tanstackQuery === "true",
|
|
43
43
|
...(options.version === undefined ? {} : { version: options.version }),
|
|
44
44
|
}, metadata);
|
|
45
|
-
|
|
45
|
+
}
|
|
46
|
+
case "go": {
|
|
46
47
|
return generateGoSdk(document, options);
|
|
47
|
-
|
|
48
|
+
}
|
|
49
|
+
case "rust": {
|
|
48
50
|
return generateRustSdk(document, options, shippedOf(metadata));
|
|
49
|
-
|
|
51
|
+
}
|
|
52
|
+
case "python": {
|
|
50
53
|
return generatePythonSdk(document, options, metadata);
|
|
51
|
-
|
|
54
|
+
}
|
|
55
|
+
case "csharp": {
|
|
52
56
|
return generateCSharpSdk(document, options, shippedOf(metadata));
|
|
53
|
-
|
|
57
|
+
}
|
|
58
|
+
case "java": {
|
|
54
59
|
return generateJavaSdk(document, options);
|
|
60
|
+
}
|
|
55
61
|
}
|
|
56
62
|
}
|
|
57
63
|
/**
|
|
@@ -168,7 +174,7 @@ function watchSpec(run, argv, io, options) {
|
|
|
168
174
|
/** Runs `clients <argv>`: the exit code it ends with (a watch ends only by `options.signal`). */
|
|
169
175
|
export async function main(argv, io = PROCESS_IO, options = {}) {
|
|
170
176
|
try {
|
|
171
|
-
|
|
177
|
+
// release has subcommands of its own, each with its own --help
|
|
172
178
|
if (argv[0] === "release")
|
|
173
179
|
return await release(argv.slice(1), io, { env: options.env });
|
|
174
180
|
if (argv.length === 0 || argv[0] === "-h" || argv[0] === "--help" || argv.includes("--help")) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** The Linux package formats nfpm builds. */
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
declare const PACKAGE_FORMATS: readonly ["deb", "rpm", "apk"];
|
|
3
|
+
type PackageFormat = (typeof PACKAGE_FORMATS)[number];
|
|
4
4
|
/** What a package manager shows about the CLI. */
|
|
5
5
|
type About = {
|
|
6
6
|
readonly description: string;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { checked, HTTPS_URL, PERSON, refuse, SPDX_EXPRESSION } from "../shared/metadata.js";
|
|
9
9
|
import { q } from "./release.js";
|
|
10
10
|
/** The Linux package formats nfpm builds. */
|
|
11
|
-
|
|
11
|
+
const PACKAGE_FORMATS = ["deb", "rpm", "apk"];
|
|
12
12
|
/** The secret each channel's push reads, by the environment variable goreleaser's config names. */
|
|
13
13
|
export const SECRETS = {
|
|
14
14
|
aur: "AUR_SSH_KEY",
|
|
@@ -17,13 +17,13 @@ export const SECRETS = {
|
|
|
17
17
|
scoop: "SCOOP_BUCKET_TOKEN",
|
|
18
18
|
winget: "WINGET_TOKEN",
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
// a description: one line of printable text, at most 256 characters (winget's ShortDescription); a winget
|
|
21
|
+
// publisher: a name of letters, digits, spaces and `.,&'-`, at most 64 characters; a homepage, an install URL, a
|
|
22
|
+
// license and a maintainer take the grammars every target's package metadata shares (../shared/metadata.ts)
|
|
23
23
|
const DESCRIPTION = /^\P{Cc}{1,256}$/u;
|
|
24
24
|
const PUBLISHER = /^[A-Za-z0-9][A-Za-z0-9 .,&'-]{0,63}$/;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
// a GitHub repository: its owner 1 to 39 letters, digits and single inner hyphens; its name 1 to 100 of letters,
|
|
26
|
+
// digits, `.`, `_` and `-`, not `.` or `..` and not ending in `.git`
|
|
27
27
|
export const REPO = /^[A-Za-z0-9](?:-?[A-Za-z0-9]){0,38}\/(?!\.\.?$)(?![\s\S]*\.git$)[A-Za-z0-9._-]{1,100}$/;
|
|
28
28
|
/** `owner/name` split, once REPO has checked it. */
|
|
29
29
|
const split = (repo) => {
|
|
@@ -93,7 +93,7 @@ export function resolvedRelease(options, repo) {
|
|
|
93
93
|
channels.push({ about: about("homebrew-tap"), kind: "homebrew", ...tap });
|
|
94
94
|
if (bucket !== undefined)
|
|
95
95
|
channels.push({ about: about("scoop-bucket"), kind: "scoop", ...bucket });
|
|
96
|
-
|
|
96
|
+
// winget needs both: the fork it pushes the manifests to, and the publisher they are filed under
|
|
97
97
|
if (fork === undefined && publisher !== undefined)
|
|
98
98
|
needed("winget-fork", undefined, "winget-publisher");
|
|
99
99
|
if (fork !== undefined) {
|
|
@@ -138,7 +138,7 @@ const aboutLines = ({ description, homepage, license }, descriptionKey = "descri
|
|
|
138
138
|
/** The goreleaser block for one channel of `bin`. */
|
|
139
139
|
export function channelBlock(bin, channel) {
|
|
140
140
|
switch (channel.kind) {
|
|
141
|
-
case "homebrew":
|
|
141
|
+
case "homebrew": {
|
|
142
142
|
return `# the Homebrew cask, pushed to the tap; the binaries are not notarized, so it clears macOS's quarantine flag
|
|
143
143
|
homebrew_casks:
|
|
144
144
|
- name: ${q(bin)}
|
|
@@ -150,19 +150,21 @@ ${pushTo(channel.owner, channel.name, SECRETS.homebrew, " ")}${aboutLines(cha
|
|
|
150
150
|
system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/${bin}"]
|
|
151
151
|
end
|
|
152
152
|
`;
|
|
153
|
-
|
|
153
|
+
}
|
|
154
|
+
case "scoop": {
|
|
154
155
|
return `# the Scoop manifest, pushed to the bucket
|
|
155
156
|
scoops:
|
|
156
157
|
- name: ${q(bin)}
|
|
157
158
|
skip_upload: auto
|
|
158
159
|
${pushTo(channel.owner, channel.name, SECRETS.scoop, " ")}${aboutLines(channel.about)}`;
|
|
159
|
-
|
|
160
|
+
}
|
|
161
|
+
case "winget": {
|
|
160
162
|
return `# the winget manifests, pushed to the fork and proposed to microsoft/winget-pkgs
|
|
161
163
|
winget:
|
|
162
164
|
- name: ${q(bin)}
|
|
163
165
|
skip_upload: auto
|
|
164
166
|
publisher: ${q(channel.publisher)}
|
|
165
|
-
package_identifier: ${q(`${channel.publisher.
|
|
167
|
+
package_identifier: ${q(`${channel.publisher.replaceAll(/[^A-Za-z0-9]/g, "")}.${bin}`)}
|
|
166
168
|
${aboutLines(channel.about, "short_description")} repository:
|
|
167
169
|
owner: ${q(channel.owner)}
|
|
168
170
|
name: ${q(channel.name)}
|
|
@@ -175,7 +177,8 @@ ${aboutLines(channel.about, "short_description")} repository:
|
|
|
175
177
|
name: winget-pkgs
|
|
176
178
|
branch: master
|
|
177
179
|
`;
|
|
178
|
-
|
|
180
|
+
}
|
|
181
|
+
case "aur": {
|
|
179
182
|
return `# the AUR ${bin}-bin package, pushed over SSH
|
|
180
183
|
aurs:
|
|
181
184
|
- name: ${q(`${bin}-bin`)}
|
|
@@ -184,7 +187,8 @@ ${aboutLines(channel.about)} maintainers: [${q(channel.about.maintainer)}]
|
|
|
184
187
|
private_key: "{{ .Env.${SECRETS.aur} }}"
|
|
185
188
|
git_url: ${q(`ssh://aur@aur.archlinux.org/${bin}-bin.git`)}
|
|
186
189
|
`;
|
|
187
|
-
|
|
190
|
+
}
|
|
191
|
+
case "packages": {
|
|
188
192
|
return `# Linux packages beside the archives, each named ${bin}_<os>_<arch>
|
|
189
193
|
nfpms:
|
|
190
194
|
- id: ${q(bin)}
|
|
@@ -193,5 +197,6 @@ nfpms:
|
|
|
193
197
|
formats: [${channel.formats.join(", ")}]
|
|
194
198
|
${aboutLines(channel.about)} maintainer: ${q(channel.about.maintainer)}
|
|
195
199
|
`;
|
|
200
|
+
}
|
|
196
201
|
}
|
|
197
202
|
}
|
|
@@ -10,7 +10,7 @@ import type { IR } from "../../ir/model.ts";
|
|
|
10
10
|
import type { SdkOp } from "../../ir/sdk-model.ts";
|
|
11
11
|
import type { GoCallPlan } from "../go/sdk-client.ts";
|
|
12
12
|
/** The root's own commands, each taken before an operation's. */
|
|
13
|
-
export declare const BUILT_INS: string[];
|
|
13
|
+
export declare const BUILT_INS: readonly string[];
|
|
14
14
|
/** A command node: a group of others, or one operation's command. */
|
|
15
15
|
export type CommandNode = {
|
|
16
16
|
readonly name: string;
|
|
@@ -41,7 +41,7 @@ export function commandTree(ops, plans) {
|
|
|
41
41
|
return named(rawTree(ops, plans), [], new NameScope(BUILT_INS), new NameScope(["Root", "newClient", "failed"]));
|
|
42
42
|
}
|
|
43
43
|
/** A named type of the SDK's, as package cmd spells it: `sdk.` before each exported name. */
|
|
44
|
-
const qualified = (type) => type.
|
|
44
|
+
const qualified = (type) => type.replaceAll(/(?<![\w.])([A-Z]\w*)/g, "sdk.$1");
|
|
45
45
|
/** A multipart body's statements: each file part from its opened files, each text part from its flag. */
|
|
46
46
|
function multipartLines(type, parts) {
|
|
47
47
|
const lines = [`\tvar body ${type}`];
|
|
@@ -67,18 +67,22 @@ function bodyLines(op, plan, flags) {
|
|
|
67
67
|
const fail = ["\tif err != nil {", "\t\treturn err", "\t}"];
|
|
68
68
|
switch (body.kind) {
|
|
69
69
|
case "json": {
|
|
70
|
-
|
|
70
|
+
// a pointer type decodes as well: json.Unmarshal allocates it, and an absent optional body stays nil
|
|
71
71
|
const read = `\tif err := p.JSON(&body, ${required}, ${map}); err != nil {`;
|
|
72
72
|
return [[`\tvar body ${qualified(plan.bodyType)}`, read, "\t\treturn err", "\t}"], ", body"];
|
|
73
73
|
}
|
|
74
|
-
case "form":
|
|
74
|
+
case "form": {
|
|
75
75
|
return [[`\tbody, err := p.Form(${required}, ${map})`, ...fail], ", body"];
|
|
76
|
-
|
|
76
|
+
}
|
|
77
|
+
case "text": {
|
|
77
78
|
return [[`\tbody, err := p.Text(${required})`, ...fail], ", body"];
|
|
78
|
-
|
|
79
|
+
}
|
|
80
|
+
case "multipart": {
|
|
79
81
|
return [multipartLines(qualified(plan.bodyType), flags.parts), ", body"];
|
|
80
|
-
|
|
82
|
+
}
|
|
83
|
+
default: {
|
|
81
84
|
return [[`\tbody, err := p.Reader(${required})`, ...fail], ", body"];
|
|
85
|
+
}
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
88
|
/** The check of one message type: an input line decoded as it, holding each field it requires. */
|
|
@@ -101,7 +105,7 @@ function linesChecked(sends) {
|
|
|
101
105
|
*/
|
|
102
106
|
function streamLines(call, stream, sends) {
|
|
103
107
|
const open = ["\tout, err := cli.OpenStream(c)", "\tif err != nil {", "\t\treturn err", "\t}", "\tdefer out.Close()"];
|
|
104
|
-
if (stream === "sse")
|
|
108
|
+
if (stream === "sse") {
|
|
105
109
|
return [
|
|
106
110
|
...open,
|
|
107
111
|
`\tfor event, err := range ${call} {`,
|
|
@@ -115,6 +119,7 @@ function streamLines(call, stream, sends) {
|
|
|
115
119
|
"\t}",
|
|
116
120
|
"\treturn out.Err()",
|
|
117
121
|
];
|
|
122
|
+
}
|
|
118
123
|
return [
|
|
119
124
|
...open,
|
|
120
125
|
`\tconn, err := ${call}`,
|
|
@@ -132,7 +137,7 @@ function callLines(call, plan) {
|
|
|
132
137
|
.map(goString)
|
|
133
138
|
.join(", ");
|
|
134
139
|
const answer = (data) => `\treturn cli.Print(c, cli.Answer{${data}Response: resp, Declared: []string{${declared}}})`;
|
|
135
|
-
if (plan.returns === "error")
|
|
140
|
+
if (plan.returns === "error") {
|
|
136
141
|
return [
|
|
137
142
|
"\tvar resp *http.Response",
|
|
138
143
|
`\tif err := ${call}; err != nil {`,
|
|
@@ -140,6 +145,7 @@ function callLines(call, plan) {
|
|
|
140
145
|
"\t}",
|
|
141
146
|
answer(""),
|
|
142
147
|
];
|
|
148
|
+
}
|
|
143
149
|
return [
|
|
144
150
|
"\tvar resp *http.Response",
|
|
145
151
|
`\tanswer, err := ${call}`,
|
|
@@ -10,12 +10,6 @@
|
|
|
10
10
|
import type { IRSchema } from "../../ir/model.ts";
|
|
11
11
|
import { type SdkModel } from "../../ir/sdk-model.ts";
|
|
12
12
|
import type { CommandNode } from "./commands.ts";
|
|
13
|
-
/** How deep a schema sketch shows objects: deeper ones are `{…}`. */
|
|
14
|
-
export declare const SKETCH_DEPTH = 3;
|
|
15
|
-
/** The longest summary an index line carries, in characters, `…` included. */
|
|
16
|
-
export declare const SUMMARY_MAX = 80;
|
|
17
|
-
/** The most values an index line spells out for an enum: more show as `<enum:N>` (the schema lists them all). */
|
|
18
|
-
export declare const ENUM_MAX = 6;
|
|
19
13
|
/** One API command as discovery shows it. */
|
|
20
14
|
export type Entry = {
|
|
21
15
|
readonly path: string;
|
|
@@ -3,13 +3,13 @@ import { goString } from "../shared/escape.js";
|
|
|
3
3
|
import { compareCodeUnits } from "../shared/lang.js";
|
|
4
4
|
import { commandFlags, helpText } from "./flags.js";
|
|
5
5
|
/** How deep a schema sketch shows objects: deeper ones are `{…}`. */
|
|
6
|
-
|
|
6
|
+
const SKETCH_DEPTH = 3;
|
|
7
7
|
/** The longest summary an index line carries, in characters, `…` included. */
|
|
8
|
-
|
|
8
|
+
const SUMMARY_MAX = 80;
|
|
9
9
|
/** The most values an index line spells out for an enum: more show as `<enum:N>` (the schema lists them all). */
|
|
10
|
-
|
|
10
|
+
const ENUM_MAX = 6;
|
|
11
11
|
/** Spec text on one line: helpText's, its whitespace runs one space. */
|
|
12
|
-
const oneLine = (text) => helpText(text).
|
|
12
|
+
const oneLine = (text) => helpText(text).replaceAll(/\s+/g, " ").trim();
|
|
13
13
|
/** A summary as the index carries it: its first sentence, at most SUMMARY_MAX characters with `…`. */
|
|
14
14
|
export function summaryOf(text) {
|
|
15
15
|
const line = oneLine(text);
|
|
@@ -18,7 +18,7 @@ export function summaryOf(text) {
|
|
|
18
18
|
return chars.length <= SUMMARY_MAX ? sentence : `${chars.slice(0, SUMMARY_MAX - 1).join("")}…`;
|
|
19
19
|
}
|
|
20
20
|
/** JSON text with DEL, C1, the BOM and the line separators escaped too (JSON.stringify leaves them raw): exact, and safe. */
|
|
21
|
-
const json = (value) => JSON.stringify(value).
|
|
21
|
+
const json = (value) => JSON.stringify(value).replaceAll(/[\u007f-\u009f\u2028\u2029\ufeff]/g, (ch) => `\\u${ch.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
22
22
|
/** A value as a usage line shows it: bare when it is a plain word, else quoted. */
|
|
23
23
|
const word = (value) => (/^[\w.:/@+-]+$/.test(value) ? value : json(value));
|
|
24
24
|
/** A flag's value as the usage line shows it: its enum, `<enum:N>` past `enumMax`, else its kind; repeatable `...`. */
|
|
@@ -64,7 +64,9 @@ function objectSketch(schema, at) {
|
|
|
64
64
|
/** A ref's sketch: its schema inlined, or its name when it is already open (recursive) or unknown. */
|
|
65
65
|
function refSketch(name, at) {
|
|
66
66
|
const target = at.model.ir.schemas[name];
|
|
67
|
-
return target === undefined || at.open.includes(name)
|
|
67
|
+
return target === undefined || at.open.includes(name)
|
|
68
|
+
? key(name)
|
|
69
|
+
: shown(target, { ...at, open: [...at.open, name] });
|
|
68
70
|
}
|
|
69
71
|
/** The sketch of a schema of each kind. */
|
|
70
72
|
const SKETCHES = {
|
|
@@ -92,7 +94,7 @@ export const sketch = (schema, model) => shown(schema, { depth: 0, model, open:
|
|
|
92
94
|
/** Each declared error status, with the keys its backend error envelope names: `[status, keys]`. */
|
|
93
95
|
function errorsOf(op, model) {
|
|
94
96
|
return op.errorStatuses.map((status) => {
|
|
95
|
-
|
|
97
|
+
// an error status is one of the operation's declared responses
|
|
96
98
|
const { schema } = op.ir.responses[String(status)];
|
|
97
99
|
return [status, schema === undefined ? [] : (irErrorEnvelope(schema, model.resolve)?.keys ?? [])];
|
|
98
100
|
});
|
package/dist/emit/cli/flags.d.ts
CHANGED
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
import type { IRSchema } from "../../ir/model.ts";
|
|
10
10
|
import type { SdkOp } from "../../ir/sdk-model.ts";
|
|
11
11
|
import type { GoCallPlan } from "../go/sdk-client.ts";
|
|
12
|
-
/** The flags every command has, and those later phases give it: a parameter never takes one of these names. */
|
|
13
|
-
export declare const GLOBAL_FLAGS: string[];
|
|
14
12
|
/** A flag's kind as the runtime checks it, whether it repeats, and its allowed values. */
|
|
15
13
|
export type Kind = {
|
|
16
14
|
readonly kind: string;
|
|
@@ -45,7 +43,7 @@ export type Usage = {
|
|
|
45
43
|
readonly kind: Kind;
|
|
46
44
|
readonly required: boolean;
|
|
47
45
|
/** the parameter's own name, for a path, query or header parameter */
|
|
48
|
-
readonly param?: string;
|
|
46
|
+
readonly param?: string | undefined;
|
|
49
47
|
};
|
|
50
48
|
/** One multipart part's flag, `--<part>`: a value of `kind` for a text part, a path for a file part. */
|
|
51
49
|
export type PartFlag = {
|
package/dist/emit/cli/flags.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { goString, invisible } from "../shared/escape.js";
|
|
2
2
|
import { NameScope, words } from "../shared/lang.js";
|
|
3
3
|
/** The flags every command has, and those later phases give it: a parameter never takes one of these names. */
|
|
4
|
-
|
|
4
|
+
const GLOBAL_FLAGS = [
|
|
5
5
|
"api-key",
|
|
6
6
|
"base-url",
|
|
7
7
|
"config",
|
|
@@ -29,7 +29,7 @@ const JSON_KIND = { enum: [], kind: "json", list: false };
|
|
|
29
29
|
* the BOM, the line and paragraph separators, the bidi controls) dropped, so no spec can move the cursor, recolor a
|
|
30
30
|
* user's terminal or reorder what it shows.
|
|
31
31
|
*/
|
|
32
|
-
export const helpText = (text) => [...text.
|
|
32
|
+
export const helpText = (text) => [...text.replaceAll(/\r\n?/g, "\n")].filter((ch) => !hidden(ch.codePointAt(0))).join("");
|
|
33
33
|
/** Whether a code point is one help drops: a C0 control but tab and line feed, DEL, C1, the BOM, U+2028, U+2029, bidi. */
|
|
34
34
|
const hidden = (cp) => (cp < 0x20 && cp !== 0x09 && cp !== 0x0a) ||
|
|
35
35
|
cp === 0x7f ||
|
|
@@ -98,7 +98,7 @@ export function commandFlags(op, plan, schemas) {
|
|
|
98
98
|
lines.push(`\tp.Path(${names.map(goString).join(", ")})`);
|
|
99
99
|
usage.push(...names.map((name, i) => ({ kind: STRING, name, param: plan.pathParams[i], positional: true, required: true })));
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
// each param the SDK gives an Opts field, by the plan: a stream's channel param (Last-Event-ID) has none
|
|
102
102
|
const params = (specs, fields) => {
|
|
103
103
|
for (const [param, field] of Object.entries(fields)) {
|
|
104
104
|
const spec = specs.find((each) => each.name === param);
|
|
@@ -122,8 +122,14 @@ export function commandFlags(op, plan, schemas) {
|
|
|
122
122
|
return { declare: lines, fields: [], opts, parts, usage };
|
|
123
123
|
}
|
|
124
124
|
const fields = bodyFields(op, schemas, scope, lines);
|
|
125
|
-
if (op.body !== undefined)
|
|
126
|
-
usage.push({
|
|
125
|
+
if (op.body !== undefined) {
|
|
126
|
+
usage.push({
|
|
127
|
+
kind: { ...STRING, kind: op.body.kind },
|
|
128
|
+
name: "data",
|
|
129
|
+
positional: false,
|
|
130
|
+
required: op.body.required,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
127
133
|
return { declare: lines, fields, opts, parts: [], usage };
|
|
128
134
|
}
|
|
129
135
|
/** A stream's cursor flags, each `[flag, its Opts field, usage]`: the names GLOBAL_FLAGS keeps from a parameter. */
|