@workerstack/clients 1.0.0-rc.28 → 1.0.0-rc.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +403 -21
- package/assets/installers/examples/github.config.ts +17 -19
- package/assets/installers/examples/goreleaser.config.ts +16 -18
- package/assets/installers/examples/raw.config.ts +13 -15
- package/bin/clients.js +87 -66
- package/bin/installgen.js +19 -10
- package/dist/cli.d.ts +4 -4
- package/dist/cli.js +18 -12
- package/dist/emit/cli/channels.d.ts +2 -2
- package/dist/emit/cli/channels.js +18 -13
- package/dist/emit/cli/commands.d.ts +1 -1
- package/dist/emit/cli/commands.js +39 -13
- package/dist/emit/cli/discovery.d.ts +0 -6
- package/dist/emit/cli/discovery.js +9 -7
- package/dist/emit/cli/flags.d.ts +1 -3
- package/dist/emit/cli/flags.js +18 -8
- package/dist/emit/cli/install.d.ts +0 -8
- package/dist/emit/cli/install.js +3 -3
- package/dist/emit/cli/layout.d.ts +1 -1
- package/dist/emit/cli/layout.js +13 -10
- package/dist/emit/cli/module.d.ts +6 -6
- package/dist/emit/cli/module.js +10 -10
- package/dist/emit/cli/release.d.ts +0 -11
- package/dist/emit/cli/release.js +4 -4
- package/dist/emit/cli/skills.js +8 -4
- package/dist/emit/csharp/errors.js +4 -4
- package/dist/emit/csharp/json.js +8 -8
- package/dist/emit/csharp/realtime.d.ts +1 -8
- package/dist/emit/csharp/realtime.js +26 -26
- package/dist/emit/csharp/sdk-answer.d.ts +10 -2
- package/dist/emit/csharp/sdk-answer.js +4 -4
- package/dist/emit/csharp/sdk-body.js +8 -6
- package/dist/emit/csharp/sdk-client.d.ts +3 -3
- package/dist/emit/csharp/sdk-client.js +2 -2
- package/dist/emit/csharp/sdk-csproj.d.ts +7 -9
- package/dist/emit/csharp/sdk-csproj.js +10 -10
- package/dist/emit/csharp/sdk-doc.js +1 -1
- package/dist/emit/csharp/sdk-method.d.ts +0 -1
- package/dist/emit/csharp/sdk-method.js +19 -8
- package/dist/emit/csharp/sdk-plan.js +0 -1
- package/dist/emit/csharp/sdk.js +3 -3
- package/dist/emit/csharp/sse.d.ts +0 -13
- package/dist/emit/csharp/sse.js +92 -11
- package/dist/emit/csharp/transport.js +9 -9
- package/dist/emit/csharp/types-enum.js +3 -1
- package/dist/emit/csharp/types-messages.d.ts +47 -0
- package/dist/emit/csharp/types-messages.js +172 -0
- package/dist/emit/csharp/types-names.js +13 -14
- package/dist/emit/csharp/types-record.js +3 -3
- package/dist/emit/csharp/types-union.d.ts +1 -1
- package/dist/emit/csharp/types.d.ts +0 -1
- package/dist/emit/csharp/types.js +3 -3
- package/dist/emit/csharp/ws.d.ts +0 -15
- package/dist/emit/csharp/ws.js +26 -5
- package/dist/emit/go/errors.js +1 -1
- package/dist/emit/go/http.js +2 -2
- package/dist/emit/go/module-path.js +2 -2
- package/dist/emit/go/sdk-answer.d.ts +24 -1
- package/dist/emit/go/sdk-answer.js +1 -1
- package/dist/emit/go/sdk-body.js +11 -7
- package/dist/emit/go/sdk-client.js +1 -1
- package/dist/emit/go/sdk-method.d.ts +3 -0
- package/dist/emit/go/sdk-method.js +18 -12
- package/dist/emit/go/sdk-mirror.js +2 -2
- package/dist/emit/go/sdk-opts.d.ts +0 -2
- package/dist/emit/go/sdk-opts.js +3 -3
- package/dist/emit/go/sdk.d.ts +1 -1
- package/dist/emit/go/sdk.js +9 -9
- package/dist/emit/go/sse.d.ts +2 -10
- package/dist/emit/go/sse.js +88 -13
- package/dist/emit/go/types-names.js +5 -0
- package/dist/emit/go/types-struct.d.ts +2 -1
- package/dist/emit/go/types-struct.js +1 -1
- package/dist/emit/go/types-union.d.ts +3 -2
- package/dist/emit/go/types-union.js +2 -0
- package/dist/emit/go/types.d.ts +6 -0
- package/dist/emit/go/types.js +20 -9
- package/dist/emit/go/ws.d.ts +4 -11
- package/dist/emit/go/ws.js +215 -59
- package/dist/emit/java/gradle.d.ts +7 -9
- package/dist/emit/java/gradle.js +8 -8
- package/dist/emit/java/json.d.ts +3 -0
- package/dist/emit/java/json.js +1 -1
- package/dist/emit/java/layout-ast.d.ts +4 -1
- package/dist/emit/java/layout-ast.js +1 -1
- package/dist/emit/java/layout-decl.js +5 -4
- package/dist/emit/java/layout-doc.js +13 -7
- package/dist/emit/java/layout-dot.js +1 -1
- package/dist/emit/java/layout-strings.js +4 -5
- package/dist/emit/java/layout-types.js +7 -5
- package/dist/emit/java/layout-visitor.js +4 -3
- package/dist/emit/java/layout.js +5 -4
- package/dist/emit/java/models-names.d.ts +2 -0
- package/dist/emit/java/models-names.js +6 -4
- package/dist/emit/java/models-record.d.ts +0 -1
- package/dist/emit/java/models-record.js +3 -3
- package/dist/emit/java/models-union.d.ts +13 -2
- package/dist/emit/java/models-union.js +12 -6
- package/dist/emit/java/models.d.ts +5 -1
- package/dist/emit/java/models.js +44 -20
- package/dist/emit/java/realtime.d.ts +34 -26
- package/dist/emit/java/realtime.js +45 -10
- package/dist/emit/java/sdk-client.d.ts +6 -6
- package/dist/emit/java/sdk-client.js +1 -1
- package/dist/emit/java/sdk-decl.js +2 -2
- package/dist/emit/java/sdk-errors.js +1 -1
- package/dist/emit/java/sdk-headers.js +2 -2
- package/dist/emit/java/sdk-mirror.js +7 -6
- package/dist/emit/java/sdk-models.d.ts +1 -1
- package/dist/emit/java/sdk-models.js +7 -7
- package/dist/emit/java/sdk-op.d.ts +1 -10
- package/dist/emit/java/sdk-op.js +9 -9
- package/dist/emit/java/sdk-params.d.ts +5 -5
- package/dist/emit/java/sdk-params.js +3 -2
- package/dist/emit/java/sdk-plan.js +0 -1
- package/dist/emit/java/sdk.d.ts +1 -1
- package/dist/emit/java/sdk.js +14 -13
- package/dist/emit/java/sse.d.ts +12 -13
- package/dist/emit/java/sse.js +105 -6
- package/dist/emit/java/ws.d.ts +48 -9
- package/dist/emit/java/ws.js +88 -4
- package/dist/emit/mcp/annotations.js +8 -4
- package/dist/emit/mcp/files.js +9 -9
- package/dist/emit/mcp/mounted.js +2 -2
- package/dist/emit/mcp/output-schema.d.ts +4 -2
- package/dist/emit/mcp/output-schema.js +58 -14
- package/dist/emit/mcp/registry.d.ts +0 -2
- package/dist/emit/mcp/registry.js +5 -4
- package/dist/emit/mcp/runtime.js +2 -2
- package/dist/emit/mcp/schema.js +22 -11
- package/dist/emit/mcp/server.d.ts +7 -7
- package/dist/emit/mcp/server.js +7 -6
- package/dist/emit/mcp/tools.js +7 -6
- package/dist/emit/python/errors.js +3 -3
- package/dist/emit/python/realtime.d.ts +9 -6
- package/dist/emit/python/realtime.js +22 -20
- package/dist/emit/python/sdk-answer.d.ts +8 -8
- package/dist/emit/python/sdk-answer.js +2 -2
- package/dist/emit/python/sdk-body.js +4 -5
- package/dist/emit/python/sdk-client.js +5 -5
- package/dist/emit/python/sdk-doc.js +2 -2
- package/dist/emit/python/sdk-method.d.ts +1 -1
- package/dist/emit/python/sdk-method.js +38 -11
- package/dist/emit/python/sdk-plan.js +0 -1
- package/dist/emit/python/sdk-pyproject.d.ts +0 -2
- package/dist/emit/python/sdk-pyproject.js +8 -8
- package/dist/emit/python/sdk.d.ts +1 -1
- package/dist/emit/python/sdk.js +28 -8
- package/dist/emit/python/sse.d.ts +0 -7
- package/dist/emit/python/sse.js +36 -6
- package/dist/emit/python/transport.js +4 -4
- package/dist/emit/python/types-dict.d.ts +2 -2
- package/dist/emit/python/types-dict.js +1 -1
- package/dist/emit/python/types-names.js +2 -2
- package/dist/emit/python/types-union.js +1 -1
- package/dist/emit/python/types.d.ts +7 -0
- package/dist/emit/python/types.js +23 -6
- package/dist/emit/python/ws.d.ts +21 -10
- package/dist/emit/python/ws.js +69 -3
- package/dist/emit/rust/errors.js +3 -3
- package/dist/emit/rust/http.js +4 -4
- package/dist/emit/rust/realtime.d.ts +7 -5
- package/dist/emit/rust/realtime.js +15 -18
- package/dist/emit/rust/sdk-body.js +8 -5
- package/dist/emit/rust/sdk-cargo.d.ts +16 -18
- package/dist/emit/rust/sdk-cargo.js +12 -12
- package/dist/emit/rust/sdk-client.d.ts +1 -1
- package/dist/emit/rust/sdk-client.js +3 -3
- package/dist/emit/rust/sdk-method.js +3 -3
- package/dist/emit/rust/sdk-opts.d.ts +2 -1
- package/dist/emit/rust/sdk-opts.js +2 -2
- package/dist/emit/rust/sdk-plan.js +0 -1
- package/dist/emit/rust/sdk.d.ts +1 -1
- package/dist/emit/rust/sdk.js +5 -5
- package/dist/emit/rust/sse.d.ts +11 -12
- package/dist/emit/rust/sse.js +54 -8
- package/dist/emit/rust/types-names.js +3 -3
- package/dist/emit/rust/types-struct.js +1 -1
- package/dist/emit/rust/types-union.d.ts +10 -2
- package/dist/emit/rust/types-union.js +4 -0
- package/dist/emit/rust/types.d.ts +9 -0
- package/dist/emit/rust/types.js +20 -12
- package/dist/emit/rust/ws.d.ts +22 -15
- package/dist/emit/rust/ws.js +60 -10
- package/dist/emit/shared/escape.js +17 -17
- package/dist/emit/shared/format.js +1 -1
- package/dist/emit/shared/gofmt.js +1 -1
- package/dist/emit/shared/lang.js +10 -10
- package/dist/emit/shared/literals.d.ts +5 -0
- package/dist/emit/shared/literals.js +8 -0
- package/dist/emit/shared/metadata.d.ts +0 -6
- package/dist/emit/shared/metadata.js +8 -7
- package/dist/emit/shared/ruff.js +1 -1
- package/dist/emit/shared/rustfmt.js +1 -1
- package/dist/emit/shared/type-emitter.js +37 -20
- package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
- package/dist/emit/shared/unknown-type.constants.js +2 -0
- package/dist/emit/ts/http.d.ts +0 -2
- package/dist/emit/ts/http.js +4 -4
- package/dist/emit/ts/package.d.ts +14 -12
- package/dist/emit/ts/package.js +9 -8
- package/dist/emit/ts/route-tree.js +2 -2
- package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
- package/dist/emit/ts/sdk-types-preamble.js +6 -2
- package/dist/emit/ts/sdk-types.js +59 -20
- package/dist/emit/ts/sdk.js +6 -6
- package/dist/emit/ts/service-map.d.ts +10 -3
- package/dist/emit/ts/service-map.js +30 -2
- package/dist/emit/ts/tanstack-query.js +6 -6
- package/dist/emit/ts/type-gen.js +36 -21
- package/dist/emit/ts/webhooks.d.ts +0 -2
- package/dist/emit/ts/webhooks.js +3 -3
- package/dist/extract/chain.js +5 -4
- package/dist/extract/extract.js +5 -5
- package/dist/extract/serialize.d.ts +0 -2
- package/dist/extract/serialize.js +14 -15
- package/dist/extract/walk.js +15 -12
- package/dist/gen/args.js +9 -5
- package/dist/gen/formatters.js +5 -3
- package/dist/gen/shipped.js +2 -2
- package/dist/gen/targets.d.ts +2 -4
- package/dist/gen/targets.js +8 -4
- package/dist/gen/write.js +4 -2
- package/dist/index.js +2 -2
- package/dist/installers/cli.d.ts +4 -4
- package/dist/installers/cli.js +24 -24
- package/dist/installers/commands/build.d.ts +4 -4
- package/dist/installers/commands/build.js +2 -3
- package/dist/installers/commands/check.d.ts +2 -2
- package/dist/installers/commands/check.js +11 -10
- package/dist/installers/commands/init.d.ts +2 -2
- package/dist/installers/commands/init.js +1 -2
- package/dist/installers/config/define-config.d.ts +16 -16
- package/dist/installers/config/define-config.js +1 -1
- package/dist/installers/config/hooks/bun.d.ts +6 -6
- package/dist/installers/config/hooks/node.js +1 -1
- package/dist/installers/config/load.d.ts +6 -8
- package/dist/installers/config/load.js +7 -8
- package/dist/installers/config/resolve.d.ts +1 -2
- package/dist/installers/config/resolve.js +28 -33
- package/dist/installers/config/types.d.ts +6 -6
- package/dist/installers/config/types.js +0 -1
- package/dist/installers/render/quote.js +3 -5
- package/dist/installers/render/render.d.ts +6 -6
- package/dist/installers/render/render.js +26 -26
- package/dist/installers/ui.d.ts +4 -4
- package/dist/installers/ui.js +3 -3
- package/dist/ir/build.d.ts +3 -3
- package/dist/ir/build.js +12 -5
- package/dist/ir/load.js +9 -10
- package/dist/ir/model.d.ts +16 -1
- package/dist/ir/model.js +0 -1
- package/dist/ir/resolve-refs.js +2 -2
- package/dist/ir/resource-tree.js +2 -1
- package/dist/ir/route-tree-intern.js +1 -1
- package/dist/ir/schema.js +3 -3
- package/dist/ir/sdk-model.d.ts +25 -1
- package/dist/ir/sdk-model.js +38 -8
- package/dist/ir/slots.d.ts +1 -1
- package/dist/ir/slots.js +22 -11
- package/dist/ir/streams.d.ts +16 -0
- package/dist/ir/streams.js +40 -0
- package/dist/release/bootstrap.d.ts +3 -3
- package/dist/release/bootstrap.js +7 -7
- package/dist/release/bump-args.js +4 -4
- package/dist/release/bump-command.d.ts +1 -1
- package/dist/release/bump-command.js +9 -10
- package/dist/release/bump.d.ts +5 -4
- package/dist/release/bump.js +2 -2
- package/dist/release/cli.d.ts +4 -4
- package/dist/release/cli.js +4 -4
- package/dist/release/codegen.js +1 -1
- package/dist/release/digest.js +5 -7
- package/dist/release/git.js +5 -8
- package/dist/release/load.js +3 -3
- package/dist/release/manifest.js +9 -10
- package/dist/release/oasdiff.d.ts +10 -15
- package/dist/release/oasdiff.js +5 -6
- package/dist/release/registries.d.ts +0 -11
- package/dist/release/registries.js +17 -17
- package/dist/release/release-state.d.ts +16 -13
- package/dist/release/release-workflow.js +5 -7
- package/dist/release/repo-settings.d.ts +2 -1
- package/dist/release/spec-gate.d.ts +0 -2
- package/dist/release/spec-gate.js +6 -10
- package/dist/release/sync-command.d.ts +2 -2
- package/dist/release/sync-command.js +1 -1
- package/dist/release/sync-tree.js +9 -13
- package/dist/release/sync.d.ts +6 -6
- package/dist/release/sync.js +12 -13
- package/dist/release/types.d.ts +22 -22
- package/dist/release/types.js +0 -1
- package/dist/release/version-files.d.ts +3 -4
- package/dist/release/version-files.js +4 -5
- package/dist/runtime/.oxfmtrc.jsonc +8 -0
- package/dist/runtime/cli/socket.go +107 -13
- package/dist/runtime/cli/stream.go +18 -11
- package/dist/runtime/csharp/Adapters.cs +12 -11
- package/dist/runtime/csharp/Events.cs +22 -17
- package/dist/runtime/csharp/Realtime.cs +50 -23
- package/dist/runtime/csharp/RealtimeLoop.cs +1 -1
- package/dist/runtime/csharp/TransportSse.cs +3 -3
- package/dist/runtime/csharp/Ws.cs +1 -1
- package/dist/runtime/csharp/WsDial.cs +19 -1
- package/dist/runtime/csharp/WsTyped.cs +109 -0
- package/dist/runtime/go/realtime.go +125 -41
- package/dist/runtime/go/realtime_loop.go +21 -18
- package/dist/runtime/go/result.go +2 -1
- package/dist/runtime/go/sse.go +11 -0
- package/dist/runtime/go/stream.go +29 -13
- package/dist/runtime/go/transport.go +15 -21
- package/dist/runtime/go/transport_longpoll.go +3 -4
- package/dist/runtime/go/transport_sse.go +6 -6
- package/dist/runtime/go/ws.go +157 -61
- package/dist/runtime/java/EventStream.java +47 -29
- package/dist/runtime/java/Exchange.java +5 -5
- package/dist/runtime/java/Flight.java +3 -3
- package/dist/runtime/java/Realtime.java +45 -11
- package/dist/runtime/java/ResumableConnection.java +77 -32
- package/dist/runtime/java/Socket.java +8 -4
- package/dist/runtime/java/SseAdapter.java +1 -1
- package/dist/runtime/java/TypedWebSocket.java +81 -24
- package/dist/runtime/java/WsAdapter.java +4 -2
- package/dist/runtime/java/WsDial.java +12 -5
- package/dist/runtime/mcp/files.ts +1 -1
- package/dist/runtime/mcp/http.ts +6 -2
- package/dist/runtime/mcp/listen.ts +1 -1
- package/dist/runtime/mcp/mount.ts +2 -2
- package/dist/runtime/mcp/protocol.ts +1 -1
- package/dist/runtime/python/events.py +25 -11
- package/dist/runtime/python/operation.py +6 -1
- package/dist/runtime/python/realtime.py +47 -33
- package/dist/runtime/python/send_async.py +1 -0
- package/dist/runtime/python/transport_sse.py +2 -2
- package/dist/runtime/python/transport_ws.py +1 -1
- package/dist/runtime/python/ws.py +100 -39
- package/dist/runtime/rust/events.rs +64 -41
- package/dist/runtime/rust/realtime.rs +80 -34
- package/dist/runtime/rust/realtime_loop.rs +37 -12
- package/dist/runtime/rust/sse.rs +3 -2
- package/dist/runtime/rust/transport_sse.rs +1 -1
- package/dist/runtime/rust/transport_ws.rs +3 -2
- package/dist/runtime/rust/ws.rs +122 -50
- package/dist/runtime/ts/realtime-connection.ts +22 -0
- package/dist/runtime/ts/realtime-transports.ts +13 -4
- package/dist/runtime/ts/realtime.ts +27 -3
- package/dist/runtime/ts/sdk-realtime.ts +1 -1
- package/dist/runtime/ts/sdk-sse.ts +31 -14
- package/dist/runtime/ts/sdk-ws.ts +2 -1
- package/dist/runtime/ts/sdk.ts +9 -2
- package/dist/runtime/ts/sse.ts +8 -0
- package/dist/runtime/ts/ws.ts +88 -50
- package/dist/runtime/ts-tanstack-query/query.ts +0 -2
- package/package.json +12 -40
- package/dist/emit/cli/index.d.ts +0 -1
- package/dist/emit/cli/index.js +0 -1
- package/dist/emit/csharp/index.d.ts +0 -1
- package/dist/emit/csharp/index.js +0 -1
- package/dist/emit/go/index.d.ts +0 -1
- package/dist/emit/go/index.js +0 -1
- package/dist/emit/java/index.d.ts +0 -2
- package/dist/emit/java/index.js +0 -2
- package/dist/emit/mcp/index.d.ts +0 -3
- package/dist/emit/mcp/index.js +0 -3
- package/dist/emit/python/index.d.ts +0 -1
- package/dist/emit/python/index.js +0 -1
- package/dist/emit/rust/index.d.ts +0 -1
- package/dist/emit/rust/index.js +0 -1
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,24 +122,34 @@ 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. */
|
|
130
136
|
const LAST_EVENT_ID = ["last-event-id", "LastEventID", "resume after this event id"];
|
|
131
137
|
const RECONNECT_TOKEN = ["reconnect-token", "ReconnectToken", "resume with this reconnect token"];
|
|
132
138
|
const CURSOR = { realtime: [LAST_EVENT_ID, RECONNECT_TOKEN], sse: [LAST_EVENT_ID], ws: [RECONNECT_TOKEN] };
|
|
133
|
-
/**
|
|
139
|
+
/**
|
|
140
|
+
* A stream command's own flags: --take, a realtime one's --max-reconnects, and its cursor flags, each set into its
|
|
141
|
+
* Opts field (a realtime one's into its one `Transport`).
|
|
142
|
+
*/
|
|
134
143
|
function streamFlags(stream, lines, opts) {
|
|
144
|
+
const into = stream === "realtime" ? "opts.Transport" : "opts";
|
|
135
145
|
lines.push("\tp.Take()");
|
|
136
146
|
if (stream === "realtime") {
|
|
137
147
|
lines.push("\tp.MaxReconnects()");
|
|
138
|
-
opts.push("\treconnects, err := p.Reconnects()", "\tif err != nil {", "\t\treturn err", "\t}",
|
|
148
|
+
opts.push("\treconnects, err := p.Reconnects()", "\tif err != nil {", "\t\treturn err", "\t}", `\t${into}.MaxReconnectAttempts = reconnects`);
|
|
139
149
|
}
|
|
140
150
|
for (const [flag, field, usage] of CURSOR[stream]) {
|
|
141
151
|
lines.push(flagLine(flag, { enum: [], kind: "string", list: false }, false, usage));
|
|
142
|
-
opts.push(`\tif err := cli.Set(
|
|
152
|
+
opts.push(`\tif err := cli.Set(&${into}.${field}, p.Values(${goString(flag)})); err != nil {`, "\t\treturn err", "\t}");
|
|
143
153
|
}
|
|
144
154
|
}
|
|
145
155
|
/** A multipart body's flags, each declared into `lines` by its part's name: a text part typed by its schema, a file part a path. */
|
|
@@ -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);
|
|
@@ -18,7 +18,11 @@ export function skillFile(bin, title, prefix, ops) {
|
|
|
18
18
|
"",
|
|
19
19
|
"## Streams",
|
|
20
20
|
`A stream command (${streams.join(", ")}) prints one JSON line per event; \`--take N\` ends it after N.`,
|
|
21
|
-
...(streams.includes("ws")
|
|
21
|
+
...(streams.includes("ws")
|
|
22
|
+
? [
|
|
23
|
+
"A ws command sends each stdin line as a text frame; where its messages are typed, a line that is not one is refused on stderr, not sent, and the run exits 4.",
|
|
24
|
+
]
|
|
25
|
+
: []),
|
|
22
26
|
...(streams.includes("realtime")
|
|
23
27
|
? [
|
|
24
28
|
"A realtime feed writes its resume cursor to stderr when it ends; pass it back with `--reconnect-token` and `--last-event-id`.",
|
|
@@ -28,7 +32,7 @@ export function skillFile(bin, title, prefix, ops) {
|
|
|
28
32
|
return [
|
|
29
33
|
"---",
|
|
30
34
|
`name: ${bin}`,
|
|
31
|
-
|
|
35
|
+
// a JSON string is a YAML double-quoted scalar: a colon or quote in the title cannot end it
|
|
32
36
|
`description: ${JSON.stringify(description)}`,
|
|
33
37
|
"---",
|
|
34
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,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A realtime operation's answer (contract 50 §2, Fd6, Fd7): `Task<ResumableConnection<T>>` through `RealtimeAsync`,
|
|
3
|
-
* `T` the declared event schema's type (`JsonElement` for a string or absent one), opened by awaiting the method over
|
|
4
|
-
* WebSocket, else SSE, else long-poll. Its five fields are `TransportOptions.Of`'s: the resume cursor, the offered
|
|
5
|
-
* subprotocols and the reconnect policy (`TimeSpan? reconnectDelay`). A declared param on a resume channel is folded
|
|
6
|
-
* in, and one named like a field is claimed as `…2` (`sdk-method.ts`).
|
|
7
|
-
*/
|
|
8
1
|
import { type CsStream } from "./sdk-answer.ts";
|
|
9
|
-
/** The realtime operation's answer, its
|
|
2
|
+
/** The realtime operation's answer, its one field and its `<returns>` text. */
|
|
10
3
|
export declare const realtimeStream: CsStream;
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A realtime operation's answer (contract 50 §2, Fd6, Fd7): `Task<ResumableConnection<T>>` through `RealtimeAsync`,
|
|
3
|
-
* `T` the declared event schema's type (`JsonElement` for a string or absent one), opened by awaiting the method over
|
|
4
|
-
* WebSocket, else SSE, else long-poll. Its five fields are `TransportOptions.Of`'s: the resume cursor, the offered
|
|
5
|
-
* subprotocols and the reconnect policy (`TimeSpan? reconnectDelay`). A declared param on a resume channel is folded
|
|
6
|
-
* in, and one named like a field is claimed as `…2` (`sdk-method.ts`).
|
|
7
|
-
*/
|
|
8
1
|
import { eventType } from "./sdk-answer.js";
|
|
9
|
-
import { isLastEventIdHeader
|
|
10
|
-
import {
|
|
11
|
-
|
|
2
|
+
import { isLastEventIdHeader } from "./sse.js";
|
|
3
|
+
import { messageType, valueHandlers } from "./types-messages.js";
|
|
4
|
+
import { JSON_ELEMENT } from "./types.js";
|
|
5
|
+
import { isReconnectToken } from "./ws.js";
|
|
6
|
+
// the connection, and its own event: a member whose On<Value> it names gets none
|
|
7
|
+
const READER = { base: "ResumableConnection", handlers: ["OnMessage"], receiver: "connection" };
|
|
8
|
+
/** The realtime operation `op`'s answer, its message types hoisted into `env.at`. */
|
|
9
|
+
function realtimeAnswer(op, env) {
|
|
10
|
+
const { receive, send } = op.ir.messages ?? {};
|
|
11
|
+
const read = send === undefined ? undefined : messageType(op, send, "Send", env.at);
|
|
12
|
+
const write = receive === undefined ? JSON_ELEMENT : messageType(op, receive, "Receive", env.at).type;
|
|
13
|
+
if (read !== undefined)
|
|
14
|
+
valueHandlers(READER, read, env.at);
|
|
15
|
+
const type = read?.type ?? (op.events === undefined ? JSON_ELEMENT : eventType(op.events, op, env));
|
|
16
|
+
const run = send === undefined && receive === undefined ? "RealtimeAsync" : "TypedRealtimeAsync";
|
|
17
|
+
return {
|
|
18
|
+
infos: [type, write],
|
|
19
|
+
render: (spell) => [`Task<ResumableConnection<${spell.runtime(type)}, ${spell.runtime(write)}>>`, run],
|
|
20
|
+
type: null,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** The realtime operation's answer, its one field and its `<returns>` text. */
|
|
12
24
|
export const realtimeStream = {
|
|
13
|
-
answer:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
render: (spell) => [`Task<ResumableConnection<${spell.runtime(type)}>>`, "RealtimeAsync"],
|
|
17
|
-
type,
|
|
18
|
-
};
|
|
19
|
-
},
|
|
20
|
-
args: ["TransportOptions.Of(lastEventId, reconnectToken, protocols, maxReconnectAttempts, reconnectDelay)"],
|
|
21
|
-
/* the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID */
|
|
25
|
+
answer: realtimeAnswer,
|
|
26
|
+
args: ["(transport ?? new()).Copy()"],
|
|
27
|
+
// the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID
|
|
22
28
|
carries: (name, where) => isReconnectToken(name, where) ||
|
|
23
29
|
(where === "query" && name === "last_event_id") ||
|
|
24
30
|
isLastEventIdHeader(name, where),
|
|
25
|
-
fields: [
|
|
26
|
-
LAST_EVENT_ID_FIELD,
|
|
27
|
-
RECONNECT_TOKEN,
|
|
28
|
-
PROTOCOLS,
|
|
29
|
-
{ ident: "maxReconnectAttempts", type: "int?" },
|
|
30
|
-
{ ident: "reconnectDelay", type: "TimeSpan?" },
|
|
31
|
-
],
|
|
31
|
+
fields: [{ ident: "transport", type: "TransportOptions?" }],
|
|
32
32
|
returns: "The connection over WebSocket, else SSE, else long-poll: it reconnects after a drop and resumes after the last message it delivered; the token, CloseAsync or DisposeAsync ends it.",
|
|
33
33
|
};
|
|
@@ -6,14 +6,22 @@
|
|
|
6
6
|
* in the JSON context) with one nullable `{ get; private set; }` property per header in code-unit order of its
|
|
7
7
|
* name, typed by the header's scalar (`long?`, `double?`, `bool?`, else `string?`), and an `internal` `Read` the
|
|
8
8
|
* transport calls on a 2xx; a WebSocket or realtime operation, whose 2xx no caller receives, gets none. A
|
|
9
|
-
* stream operation answers as its `CsStream` says (`sse.ts`, `ws.ts`, `realtime.ts`)
|
|
9
|
+
* stream operation answers as its `CsStream` says (`sse.ts`, `ws.ts`, `realtime.ts`), its call passing the arguments
|
|
10
|
+
* and type infos its answer adds (a named-event stream's decode, a socket's or a connection's two types) before
|
|
11
|
+
* the type info.
|
|
10
12
|
*/
|
|
11
13
|
import type { IRSchema } from "../../ir/model.ts";
|
|
12
14
|
import type { SdkOp } from "../../ir/sdk-model.ts";
|
|
13
15
|
import type { MethodEnv, Spelling } from "./sdk-method.ts";
|
|
14
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* A method's answer: its JSON type (null for any other kind), the arguments its call passes before that type's info
|
|
18
|
+
* (a named-event stream's decode), the types whose infos it passes after them (a typed socket's or a realtime
|
|
19
|
+
* connection's read and send types), and its return type and transport method.
|
|
20
|
+
*/
|
|
15
21
|
export type CsAnswer = {
|
|
16
22
|
readonly type: string | null;
|
|
23
|
+
readonly args?: readonly string[];
|
|
24
|
+
readonly infos?: readonly string[];
|
|
17
25
|
readonly render: (spell: Spelling) => readonly [returns: string, run: string];
|
|
18
26
|
};
|
|
19
27
|
/**
|
|
@@ -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
|
};
|