@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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { irResolver } from "../../ir/schema.js";
|
|
2
2
|
import { compareCodeUnits, csTypeName, NameScope } from "../shared/lang.js";
|
|
3
3
|
import { runtimeFiles, runtimeTypeNames } from "./transport.js";
|
|
4
|
-
|
|
4
|
+
// the BCL names emitted text spells unqualified, by the namespace a `using` brings them from (§4.7)
|
|
5
5
|
export const BCL = {
|
|
6
|
-
System: ["Exception", "Func", "IDisposable", "Object", "String", "TimeSpan", "Type"],
|
|
6
|
+
System: ["Action", "Exception", "Func", "IDisposable", "Object", "String", "TimeSpan", "Type"],
|
|
7
7
|
"System.Collections.Generic": ["IDictionary", "IReadOnlyDictionary", "IReadOnlyList"],
|
|
8
8
|
"System.Text.Json": [
|
|
9
9
|
"JsonElement",
|
|
@@ -30,13 +30,11 @@ export const BCL = {
|
|
|
30
30
|
"System.Threading": ["CancellationToken"],
|
|
31
31
|
"System.Threading.Tasks": ["Task"],
|
|
32
32
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* the emitted types share the runtime's namespace (Fb2), so each is reserved, never a `using`
|
|
36
|
-
*/
|
|
33
|
+
// the BCL names the vendored runtime spells unqualified (as a type or by static access) and emitted text never does:
|
|
34
|
+
// the emitted types share the runtime's namespace (Fb2), so each is reserved, never a `using`
|
|
37
35
|
export const RUNTIME_BCL = [
|
|
38
|
-
"Action",
|
|
39
36
|
"Array",
|
|
37
|
+
"BrotliStream",
|
|
40
38
|
"ByteArrayContent",
|
|
41
39
|
"CancellationTokenRegistration",
|
|
42
40
|
"CancellationTokenSource",
|
|
@@ -48,6 +46,7 @@ export const RUNTIME_BCL = [
|
|
|
48
46
|
"Encoding",
|
|
49
47
|
"Enum",
|
|
50
48
|
"EqualityComparer",
|
|
49
|
+
"GZipStream",
|
|
51
50
|
"Guid",
|
|
52
51
|
"HashCode",
|
|
53
52
|
"HashSet",
|
|
@@ -95,7 +94,7 @@ export const RUNTIME_BCL = [
|
|
|
95
94
|
"StringBuilder",
|
|
96
95
|
"StringComparer",
|
|
97
96
|
"StringComparison",
|
|
98
|
-
|
|
97
|
+
// System.Threading's, also a runtime property: the scan cannot tell `Timeout.InfiniteTimeSpan` (CS0117) from it
|
|
99
98
|
"Timeout",
|
|
100
99
|
"UnicodeCategory",
|
|
101
100
|
"Uri",
|
|
@@ -109,7 +108,7 @@ export const RUNTIME_BCL = [
|
|
|
109
108
|
"WebSocketMessageType",
|
|
110
109
|
"WebSocketState",
|
|
111
110
|
];
|
|
112
|
-
|
|
111
|
+
// the attributes emitted text spells without their `Attribute` suffix: the suffixed name is taken too
|
|
113
112
|
const ATTRIBUTES = [
|
|
114
113
|
"JsonConverter",
|
|
115
114
|
"JsonExtensionData",
|
|
@@ -125,7 +124,7 @@ const reserved = (taken) => [
|
|
|
125
124
|
...Object.values(BCL).flat(),
|
|
126
125
|
...RUNTIME_BCL,
|
|
127
126
|
...ATTRIBUTES.map((name) => `${name}Attribute`),
|
|
128
|
-
|
|
127
|
+
// the static class of the API's error keys (errors.ts), declared beside the types when any key is
|
|
129
128
|
"ErrorKey",
|
|
130
129
|
"System",
|
|
131
130
|
...taken,
|
|
@@ -161,7 +160,7 @@ export function irNames(schemas, taken, declares) {
|
|
|
161
160
|
hoisted.set(key, name);
|
|
162
161
|
return name;
|
|
163
162
|
},
|
|
164
|
-
|
|
163
|
+
// a ref reaches here only for a declared component: `alias` answers for every other one
|
|
165
164
|
ref: (name) => components.get(name),
|
|
166
165
|
renamed,
|
|
167
166
|
resolve: irResolver(schemas),
|
|
@@ -169,9 +168,9 @@ export function irNames(schemas, taken, declares) {
|
|
|
169
168
|
}
|
|
170
169
|
/** `code` without its string and char literals and comments: the text that spells names. */
|
|
171
170
|
const codeOf = (code) => code
|
|
172
|
-
.
|
|
173
|
-
.
|
|
174
|
-
.
|
|
171
|
+
.replaceAll(/"(?:[^"\\\n]|\\.)*"/g, '""')
|
|
172
|
+
.replaceAll(/'(?:[^'\\\n]|\\.)'/g, "''")
|
|
173
|
+
.replaceAll(/\/\/.*$/gm, "");
|
|
175
174
|
/** The `using` lines `code` needs: each namespace one of whose BCL names it spells as a type, in code-unit order. */
|
|
176
175
|
export function usings(code) {
|
|
177
176
|
const text = codeOf(code);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { csString } from "../shared/escape.js";
|
|
2
2
|
import { compareCodeUnits, csTypeName, NameScope } from "../shared/lang.js";
|
|
3
|
-
|
|
3
|
+
// every member name a record property collides with (CS0102, CS0108, CS8859, CS8874), and the name its attributes spell in an expression
|
|
4
4
|
export const RECORD_MEMBERS = [
|
|
5
5
|
"Clone",
|
|
6
6
|
"EqualityContract",
|
|
@@ -12,7 +12,7 @@ export const RECORD_MEMBERS = [
|
|
|
12
12
|
"PrintMembers",
|
|
13
13
|
"ToString",
|
|
14
14
|
];
|
|
15
|
-
|
|
15
|
+
// a required nullable member is written even when null; an unset tri-state or open value is not written
|
|
16
16
|
const NEVER = "[JsonIgnore(Condition = JsonIgnoreCondition.Never)]";
|
|
17
17
|
const UNSET = "[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]";
|
|
18
18
|
/** One property's lines, unindented: its attributes, then `public <type> <name> { get; init; }`. */
|
|
@@ -25,7 +25,7 @@ function propertyLines(field, name, member, at) {
|
|
|
25
25
|
return [key, UNSET, `public ${type} ${name} { get; init; }`];
|
|
26
26
|
if (!type.endsWith("?"))
|
|
27
27
|
return [key, `public ${type}? ${name} { get; init; }`];
|
|
28
|
-
|
|
28
|
+
// OptConverter reads T through the context: it must list T
|
|
29
29
|
at.serialized.add(type);
|
|
30
30
|
return [key, `[JsonConverter(typeof(OptConverter<${type}>))]`, UNSET, `public Opt<${type}> ${name} { get; init; }`];
|
|
31
31
|
}
|
|
@@ -11,7 +11,7 @@ type Of<K extends IRSchema["kind"]> = Extract<IRSchema, {
|
|
|
11
11
|
kind: K;
|
|
12
12
|
}>;
|
|
13
13
|
/** Declares `schema` once under `names.hoist(key, base)`; its name. */
|
|
14
|
-
|
|
14
|
+
type Declare = (schema: IRSchema, key: string, base: string) => string;
|
|
15
15
|
/** What a union's declaration reaches: the context, its members' types, and the hoist. */
|
|
16
16
|
export type UnionScope = {
|
|
17
17
|
at: CsTypeContext;
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { IR, IRSchema } from "../../ir/model.ts";
|
|
9
9
|
import { type CsTypeNames } from "./types-names.ts";
|
|
10
|
-
export type { CsTypeNames } from "./types-names.ts";
|
|
11
10
|
/** Where a type is being written, the declarations it hoists, the names, and what the JSON context gathers. */
|
|
12
11
|
export type CsTypeContext = {
|
|
13
12
|
parentName: string;
|
|
@@ -5,7 +5,7 @@ import { fieldsOf, isOpen, recordDecl } from "./types-record.js";
|
|
|
5
5
|
import { isLiteral, unionDecl } from "./types-union.js";
|
|
6
6
|
export const JSON_ELEMENT = "JsonElement";
|
|
7
7
|
const MAP = "IReadOnlyDictionary<string, ";
|
|
8
|
-
|
|
8
|
+
// deeper than this, a schema is any JSON value
|
|
9
9
|
const MAX_DEPTH = 12;
|
|
10
10
|
const SCALARS = {
|
|
11
11
|
boolean: "bool",
|
|
@@ -45,7 +45,7 @@ export function declares(ir) {
|
|
|
45
45
|
function declare(ir, at, key, base) {
|
|
46
46
|
const name = at.names.hoist(key, base);
|
|
47
47
|
if (!at.decls.has(name)) {
|
|
48
|
-
|
|
48
|
+
// claimed before its body: what the body hoists in turn comes after it
|
|
49
49
|
at.decls.set(name, "");
|
|
50
50
|
at.decls.set(name, csTopLevel(name, ir, at));
|
|
51
51
|
}
|
|
@@ -98,7 +98,7 @@ const USES = {
|
|
|
98
98
|
ref: refUse,
|
|
99
99
|
scalar: (ir, at) => (isEnum(ir) ? hoist(ir, at) : SCALARS[ir.type]),
|
|
100
100
|
tuple: () => `IReadOnlyList<${JSON_ELEMENT}>`,
|
|
101
|
-
|
|
101
|
+
// a union in use position is any JSON value; a component union is declared (Fb7)
|
|
102
102
|
union: () => JSON_ELEMENT,
|
|
103
103
|
unknown: () => JSON_ELEMENT,
|
|
104
104
|
};
|
package/dist/emit/csharp/ws.d.ts
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A WebSocket operation's answer (contract 50 §2, Fd5): `Task<TypedWebSocket>` through `SocketAsync`, opened by
|
|
3
|
-
* awaiting the method and dialed offering `protocols`, its `reconnectToken` sent as one query param only when set and
|
|
4
|
-
* non-empty; a declared `reconnect_token` query param is folded into that field.
|
|
5
|
-
*/
|
|
6
1
|
import type { CsStream } from "./sdk-answer.ts";
|
|
7
|
-
/** The subprotocols a WebSocket or realtime dial offers. */
|
|
8
|
-
export declare const PROTOCOLS: {
|
|
9
|
-
ident: string;
|
|
10
|
-
type: string;
|
|
11
|
-
};
|
|
12
|
-
/** The resume cursor's token, which the WebSocket and realtime methods take. */
|
|
13
|
-
export declare const RECONNECT_TOKEN: {
|
|
14
|
-
ident: string;
|
|
15
|
-
type: string;
|
|
16
|
-
};
|
|
17
2
|
/** Whether a declared param is the `reconnect_token` query param, the resume channel a socket dial sends. */
|
|
18
3
|
export declare const isReconnectToken: (name: string, where: string) => boolean;
|
|
19
4
|
/** The WebSocket operation's answer, its two fields and its `<returns>` text. */
|
package/dist/emit/csharp/ws.js
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** The
|
|
4
|
-
|
|
1
|
+
import { messageType, valueHandlers } from "./types-messages.js";
|
|
2
|
+
import { JSON_ELEMENT } from "./types.js";
|
|
3
|
+
/** The subprotocols a WebSocket dial offers. */
|
|
4
|
+
const PROTOCOLS = { ident: "protocols", type: "IReadOnlyList<string>?" };
|
|
5
|
+
/** The resume cursor's token, which the WebSocket method takes. */
|
|
6
|
+
const RECONNECT_TOKEN = { ident: "reconnectToken", type: "string?" };
|
|
7
|
+
// the typed socket, and its own events: a member whose On<Value> one of them names gets none
|
|
8
|
+
const READER = { base: "TypedWebSocket", handlers: ["OnMessage", "OnClose", "OnError"], receiver: "socket" };
|
|
5
9
|
/** Whether a declared param is the `reconnect_token` query param, the resume channel a socket dial sends. */
|
|
6
10
|
export const isReconnectToken = (name, where) => where === "query" && name === "reconnect_token";
|
|
11
|
+
/** The WebSocket operation `op`'s answer, its message types hoisted into `env.at`. */
|
|
12
|
+
function wsAnswer(op, { at }) {
|
|
13
|
+
if (op.ir.messages === undefined)
|
|
14
|
+
return { render: () => ["Task<TypedWebSocket>", "SocketAsync"], type: null };
|
|
15
|
+
const { receive, send } = op.ir.messages;
|
|
16
|
+
const read = send === undefined ? { type: JSON_ELEMENT } : messageType(op, send, "Send", at);
|
|
17
|
+
const write = receive === undefined ? { type: JSON_ELEMENT } : messageType(op, receive, "Receive", at);
|
|
18
|
+
valueHandlers(READER, read, at);
|
|
19
|
+
return {
|
|
20
|
+
infos: [read.type, write.type],
|
|
21
|
+
render: (spell) => [
|
|
22
|
+
`Task<TypedWebSocket<${spell.runtime(read.type)}, ${spell.runtime(write.type)}>>`,
|
|
23
|
+
"TypedSocketAsync",
|
|
24
|
+
],
|
|
25
|
+
type: null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
7
28
|
/** The WebSocket operation's answer, its two fields and its `<returns>` text. */
|
|
8
29
|
export const wsStream = {
|
|
9
|
-
answer:
|
|
30
|
+
answer: wsAnswer,
|
|
10
31
|
args: ["protocols", "reconnectToken"],
|
|
11
32
|
carries: isReconnectToken,
|
|
12
33
|
fields: [PROTOCOLS, RECONNECT_TOKEN],
|
package/dist/emit/go/errors.js
CHANGED
|
@@ -5,7 +5,7 @@ import { goTopLevel } from "./types.js";
|
|
|
5
5
|
/** Every declared key's schema (the first operation's to declare one), keys in code-unit order. */
|
|
6
6
|
function declaredKeys(model) {
|
|
7
7
|
const declared = model.ops.flatMap((op) => Object.entries(op.ir.extensions.errors ?? {}));
|
|
8
|
-
|
|
8
|
+
// reversed, so a key ends on its first declaration
|
|
9
9
|
const first = new Map(declared.toReversed().map(([key, { schema }]) => [key, schema]));
|
|
10
10
|
return [...first].sort(([a], [b]) => compareCodeUnits(a, b));
|
|
11
11
|
}
|
package/dist/emit/go/http.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { readFileSync } from "node:fs";
|
|
8
8
|
import { compareCodeUnits } from "../shared/lang.js";
|
|
9
|
-
|
|
9
|
+
// every SDK: config, request, auth, redirects, errors, SSE, invalidation
|
|
10
10
|
const CORE = [
|
|
11
11
|
"auth",
|
|
12
12
|
"body",
|
|
@@ -27,7 +27,7 @@ const CORE = [
|
|
|
27
27
|
"stale",
|
|
28
28
|
"stream",
|
|
29
29
|
];
|
|
30
|
-
|
|
30
|
+
// a WebSocket operation; realtime adds the resumable transports on top of it
|
|
31
31
|
const WS = ["ws"];
|
|
32
32
|
const REALTIME = ["realtime", "realtime_loop", "transport", "transport_longpoll", "transport_sse"];
|
|
33
33
|
/** The runtime file names an SDK with `features` ships, in code-unit order. */
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* so the two can never disagree.
|
|
7
7
|
*/
|
|
8
8
|
import { checked, SEMVER } from "../shared/metadata.js";
|
|
9
|
-
|
|
9
|
+
// a dotted domain, then path elements (Go's module.CheckPath, less its rarely used characters)
|
|
10
10
|
const MODULE_PATH = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+(?:\/[A-Za-z0-9_~-](?:[A-Za-z0-9._~-]*[A-Za-z0-9_~-])?)*$/;
|
|
11
|
-
|
|
11
|
+
// a last element Go reads as a major version suffix, and the ones it takes
|
|
12
12
|
const SUFFIX = /\/v[\d.]+$/;
|
|
13
13
|
const MAJOR = /\/v(?:[2-9]|[1-9]\d+)$/;
|
|
14
14
|
/** `modulePath` with the major suffix `version` gives from v2 on, each refused unless Go would take it. */
|
|
@@ -11,11 +11,34 @@ export type Shape = {
|
|
|
11
11
|
readonly fail: string;
|
|
12
12
|
readonly tail: (client: string) => string[];
|
|
13
13
|
};
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* What a streaming operation's method is: how it answers, what its Opts add, the note its godoc ends on, and the
|
|
16
|
+
* package-level functions declared for it that its body calls, which a path param never shadows.
|
|
17
|
+
*/
|
|
15
18
|
export type GoStream = {
|
|
16
19
|
readonly shape: Shape;
|
|
17
20
|
readonly opts: StreamOpts;
|
|
18
21
|
readonly doc: string;
|
|
22
|
+
readonly calls: readonly string[];
|
|
23
|
+
/** what a socket's server receives, typed; absent for an SSE op and a socket that declares no `receive` */
|
|
24
|
+
readonly sends?: GoSends;
|
|
25
|
+
};
|
|
26
|
+
/** A message type the server receives: its Go type, and the fields it requires at its top level. */
|
|
27
|
+
export type GoMessageType = {
|
|
28
|
+
readonly type: string;
|
|
29
|
+
readonly required: readonly string[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* What a socket's server receives, as the CLI checks an input line against it: one message type,
|
|
33
|
+
* or a union keyed on `key` (D9), each member by its value.
|
|
34
|
+
*/
|
|
35
|
+
export type GoSends = (GoMessageType & {
|
|
36
|
+
readonly key: null;
|
|
37
|
+
}) | {
|
|
38
|
+
readonly key: string;
|
|
39
|
+
readonly members: readonly (GoMessageType & {
|
|
40
|
+
readonly value: string;
|
|
41
|
+
})[];
|
|
19
42
|
};
|
|
20
43
|
/** The runtime call's arguments: the ctx, the client's config, the call, each of `extra`, then the per-call options. */
|
|
21
44
|
export declare const sendArgs: (client: string, ...extra: string[]) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** The runtime call's arguments: the ctx, the client's config, the call, each of `extra`, then the per-call options. */
|
|
2
2
|
export const sendArgs = (client, ...extra) => ["ctx", `${client}.cfg`, "c", ...extra, "reqOpts"].join(", ");
|
|
3
|
-
|
|
3
|
+
// an operation answering without a body
|
|
4
4
|
const NO_BODY_SHAPE = {
|
|
5
5
|
fail: "err",
|
|
6
6
|
returns: "error",
|
package/dist/emit/go/sdk-body.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { goString, lineComment } from "../shared/escape.js";
|
|
2
2
|
import { goExported, NameScope } from "../shared/lang.js";
|
|
3
3
|
import { goTypeOf } from "./types.js";
|
|
4
|
-
|
|
4
|
+
// a body sent as it is: nothing to encode first
|
|
5
5
|
const NO_LINES = () => [];
|
|
6
|
-
|
|
6
|
+
// a text part's Go type by its scalar type (v0 codegen-go.ts:382-391); any other schema is sent as a string
|
|
7
7
|
const PART_SCALARS = {
|
|
8
8
|
boolean: "bool",
|
|
9
9
|
integer: "int64",
|
|
@@ -15,7 +15,7 @@ const PART_SCALARS = {
|
|
|
15
15
|
const appended = (indent, part) => `${indent}fields = append(fields, ${part})`;
|
|
16
16
|
/** The field of `part` named `name` on the body `local`: a list repeats the part, an unset value sends none. */
|
|
17
17
|
function partField(part, name, local, at) {
|
|
18
|
-
|
|
18
|
+
// the IR gives every part its schema (ir/slots.ts partsOf, sdk-model bodyOf)
|
|
19
19
|
const schema = at.names.resolve(part.schema);
|
|
20
20
|
const list = schema.kind === "array";
|
|
21
21
|
const item = schema.kind === "array" ? at.names.resolve(schema.items) : schema;
|
|
@@ -64,13 +64,17 @@ export function goBody(op, body, env) {
|
|
|
64
64
|
const type = goTypeOf(body.schema, { ...env.at, fieldName: "Body", parentName: op.id });
|
|
65
65
|
return { lines: NO_LINES, send: `jsonBody(${local})`, type };
|
|
66
66
|
}
|
|
67
|
-
case "form":
|
|
67
|
+
case "form": {
|
|
68
68
|
return { lines: NO_LINES, send: `formBody(${local})`, type: "url.Values" };
|
|
69
|
-
|
|
69
|
+
}
|
|
70
|
+
case "binary": {
|
|
70
71
|
return { lines: NO_LINES, send: `readerBody(${local}, ${contentType})`, type: "io.Reader" };
|
|
71
|
-
|
|
72
|
+
}
|
|
73
|
+
case "text": {
|
|
72
74
|
return { lines: NO_LINES, send: `rawBody([]byte(${local}), ${contentType})`, type: "string" };
|
|
73
|
-
|
|
75
|
+
}
|
|
76
|
+
case "multipart": {
|
|
74
77
|
return multipartBody(op, body.parts, env);
|
|
78
|
+
}
|
|
75
79
|
}
|
|
76
80
|
}
|
|
@@ -4,7 +4,7 @@ import { compareCodeUnits, goExported, NameScope } from "../shared/lang.js";
|
|
|
4
4
|
import { MIRROR, mirrorNotice } from "../shared/mirror.js";
|
|
5
5
|
import { goMethod } from "./sdk-method.js";
|
|
6
6
|
import { twinLines, twinLiteral, twinTypeLines, twinTypes } from "./sdk-mirror.js";
|
|
7
|
-
|
|
7
|
+
// the mirror as Go spells it, Client's method: goExported(MIRROR)
|
|
8
8
|
const SAFE = "Safe";
|
|
9
9
|
/**
|
|
10
10
|
* A member's name in `members`, `segment` exported; at the root (`path` empty) one spelled like the mirror is
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type SdkBody, type SdkOp, type SdkResponseKind, type SdkStream } from "../../ir/sdk-model.ts";
|
|
2
|
+
import { type GoSends } from "./sdk-answer.ts";
|
|
2
3
|
import { type GoPart } from "./sdk-body.ts";
|
|
3
4
|
import { type GoResponseHeaders } from "./sdk-opts.ts";
|
|
4
5
|
import { type GoTypeContext } from "./types.ts";
|
|
@@ -32,6 +33,8 @@ export type GoMethodCall = {
|
|
|
32
33
|
readonly opts: string;
|
|
33
34
|
/** a multipart body's parts by their `<Op>Body` fields; null for any other body */
|
|
34
35
|
readonly parts: readonly GoPart[] | null;
|
|
36
|
+
/** what a socket's server receives, typed: the CLI checks each input line against it; null when untyped or no socket */
|
|
37
|
+
readonly sends: GoSends | null;
|
|
35
38
|
};
|
|
36
39
|
/**
|
|
37
40
|
* One operation's method, its client.go declarations by name (`<Op>Opts`, `<Op>Headers`), how a caller reaches it,
|
|
@@ -3,14 +3,15 @@ import { goString, lineComment } from "../shared/escape.js";
|
|
|
3
3
|
import { goExported, goLocal, NameScope } from "../shared/lang.js";
|
|
4
4
|
import { shapeOf } from "./sdk-answer.js";
|
|
5
5
|
import { goBody } from "./sdk-body.js";
|
|
6
|
-
import { optsDecl, optsFields, optsLines, responseHeaders } from "./sdk-opts.js";
|
|
6
|
+
import { optsDecl, optsFields, optsLines, responseHeaders, } from "./sdk-opts.js";
|
|
7
7
|
import { sseStream } from "./sse.js";
|
|
8
8
|
import { goTypeOf } from "./types.js";
|
|
9
9
|
import { socketStream } from "./ws.js";
|
|
10
|
-
|
|
10
|
+
// the receiver, the method's own locals and the unexported runtime names its body calls: a path param never shadows one
|
|
11
11
|
const METHOD_LOCALS = [
|
|
12
12
|
"c",
|
|
13
13
|
"call",
|
|
14
|
+
"conn",
|
|
14
15
|
"ctx",
|
|
15
16
|
"data",
|
|
16
17
|
"decodeJSON",
|
|
@@ -37,8 +38,9 @@ const METHOD_LOCALS = [
|
|
|
37
38
|
"result",
|
|
38
39
|
"setHeaderValue",
|
|
39
40
|
"setIdempotencyKey",
|
|
41
|
+
"sseData",
|
|
40
42
|
"sseFail",
|
|
41
|
-
"
|
|
43
|
+
"streamEvents",
|
|
42
44
|
"streamText",
|
|
43
45
|
"textField",
|
|
44
46
|
"topts",
|
|
@@ -69,15 +71,18 @@ function methodDoc(op, name, stream) {
|
|
|
69
71
|
const text = [route, op.summary, op.description].filter((part) => part !== "");
|
|
70
72
|
return lineComment(text.join("\n\n"), "//");
|
|
71
73
|
}
|
|
72
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* How the method of `op` answers, its stream (null for an operation that answers once), and the method's locals: the
|
|
76
|
+
* runtime's names, and the stream's own.
|
|
77
|
+
*/
|
|
73
78
|
function answering(op, env) {
|
|
74
79
|
if (op.stream !== null) {
|
|
75
|
-
const stream = op.stream === "sse" ? sseStream(op, env.at) : socketStream(op.stream);
|
|
76
|
-
return { shape: stream.shape, stream };
|
|
80
|
+
const stream = op.stream === "sse" ? sseStream(op, env.at) : socketStream(op, op.stream, env.at);
|
|
81
|
+
return { locals: new NameScope([...METHOD_LOCALS, ...stream.calls]), shape: stream.shape, stream };
|
|
77
82
|
}
|
|
78
83
|
const schema = op.success.schema;
|
|
79
84
|
const result = schema && goTypeOf(schema, { ...env.at, fieldName: "Response", parentName: op.id }).replace(/^\*/, "");
|
|
80
|
-
return { shape: shapeOf({ kind: op.success.kind, result }), stream: null };
|
|
85
|
+
return { locals: new NameScope(METHOD_LOCALS), shape: shapeOf({ kind: op.success.kind, result }), stream: null };
|
|
81
86
|
}
|
|
82
87
|
/** The statements before `c`: the path expanded from its params, or the template as it is. */
|
|
83
88
|
function pathLines(op, locals, fail) {
|
|
@@ -129,19 +134,19 @@ function twinOf(op, returns, params) {
|
|
|
129
134
|
/** The method of `op` named `name` on `receiver`, and its `<Op>Opts` and `<Op>Headers`. */
|
|
130
135
|
export function goMethod(op, name, receiver, env) {
|
|
131
136
|
const opts = env.at.names.claimConst(`${goExported(op.id)}Opts`);
|
|
132
|
-
const locals =
|
|
137
|
+
const { locals, shape, stream } = answering(op, env);
|
|
133
138
|
const bodyLocal = op.body && locals.claim("body");
|
|
134
139
|
const body = op.body && goBody(op, op.body, { at: env.at, local: bodyLocal });
|
|
135
140
|
const pathLocals = pathParamsOf(op).map((param) => [param, locals.claim(goLocal(param.name))]);
|
|
136
|
-
const { shape, stream } = answering(op, env);
|
|
137
141
|
const streamOpts = stream?.opts ?? null;
|
|
138
142
|
const fields = optsFields(op, opts, env.at, streamOpts);
|
|
139
143
|
const path = pathLines(op, pathLocals, shape.fail);
|
|
140
144
|
const headers = responseHeaders(op, env.at);
|
|
145
|
+
const bodyTypes = body ? [body.type] : [];
|
|
141
146
|
const params = [
|
|
142
147
|
"ctx context.Context",
|
|
143
148
|
...pathLocals.map(([, local]) => `${local} string`),
|
|
144
|
-
...(
|
|
149
|
+
...bodyTypes.map((type) => `${bodyLocal} ${type}`),
|
|
145
150
|
`opts *${opts}`,
|
|
146
151
|
"reqOpts ...RequestOption",
|
|
147
152
|
];
|
|
@@ -160,13 +165,14 @@ export function goMethod(op, name, receiver, env) {
|
|
|
160
165
|
decls.push([headers.plan.type, headers.decl]);
|
|
161
166
|
const call = {
|
|
162
167
|
...callOf(op, name, pathLocals, fields),
|
|
163
|
-
bodyType:
|
|
168
|
+
bodyType: bodyTypes[0] ?? null,
|
|
164
169
|
opts,
|
|
165
170
|
parts: body?.parts ?? null,
|
|
166
171
|
responseHeaders: headers?.plan ?? null,
|
|
167
172
|
returns: shape.returns,
|
|
173
|
+
sends: stream?.sends ?? null,
|
|
168
174
|
};
|
|
169
|
-
const types = ["context.Context", ...pathLocals.map(() => "string"), ...
|
|
175
|
+
const types = ["context.Context", ...pathLocals.map(() => "string"), ...bodyTypes, `*${opts}`];
|
|
170
176
|
const twin = twinOf(op, shape.returns, types);
|
|
171
177
|
return { call, decls, lines, twin };
|
|
172
178
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { lineComment } from "../shared/escape.js";
|
|
1
2
|
/**
|
|
2
3
|
* The Go SDK's safe mirror, `Client.Safe()` (bit 21 i3): a twin struct per resource struct, each method a field of its
|
|
3
4
|
* name holding the normal method value under a generic wrapper that answers a `Result`. The field's type is a generic
|
|
@@ -6,8 +7,7 @@
|
|
|
6
7
|
* wrapper (`call<n>`, `none<n>`, `stream<n>`), so a twin spells its types once and the one request path runs.
|
|
7
8
|
*/
|
|
8
9
|
import { compareCodeUnits } from "../shared/lang.js";
|
|
9
|
-
|
|
10
|
-
/* each kind's type and wrapper base names: none shares call's type, a connection needs no wrapper */
|
|
10
|
+
// each kind's type and wrapper base names: none shares call's type, a connection needs no wrapper
|
|
11
11
|
const TWIN_NAMES = {
|
|
12
12
|
call: ["Call", "call"],
|
|
13
13
|
conn: ["Conn", null],
|
|
@@ -30,8 +30,6 @@ export type GoResponseHeaders = {
|
|
|
30
30
|
readonly type: string;
|
|
31
31
|
readonly fields: Readonly<Record<string, string>>;
|
|
32
32
|
};
|
|
33
|
-
/** Whether `op`'s Opts carry `IdempotencyKey`: an idempotent operation that answers once. */
|
|
34
|
-
export declare const takesIdempotencyKey: (op: SdkOp) => boolean;
|
|
35
33
|
/**
|
|
36
34
|
* `<Op>Opts`'s param fields: each query param, then each header param, sent unless unset; a param
|
|
37
35
|
* `stream` carries has none.
|
package/dist/emit/go/sdk-opts.js
CHANGED
|
@@ -2,12 +2,12 @@ import { goString, lineComment } from "../shared/escape.js";
|
|
|
2
2
|
import { compareCodeUnits, goExported, NameScope } from "../shared/lang.js";
|
|
3
3
|
import { isNilable } from "./types-codec.js";
|
|
4
4
|
import { goTypeOf } from "./types.js";
|
|
5
|
-
|
|
5
|
+
// the Opts field an idempotent operation's caller sets its Idempotency-Key through
|
|
6
6
|
const IDEMPOTENCY_KEY = "IdempotencyKey";
|
|
7
7
|
/** A value's Go type when it may be absent: as is where nil already means unset (H4), else a pointer. */
|
|
8
8
|
const optional = (type, required) => (required || isNilable(type) ? type : `*${type}`);
|
|
9
9
|
/** Whether `op`'s Opts carry `IdempotencyKey`: an idempotent operation that answers once. */
|
|
10
|
-
|
|
10
|
+
const takesIdempotencyKey = (op) => op.idempotent && op.stream === null;
|
|
11
11
|
/**
|
|
12
12
|
* `<Op>Opts`'s param fields: each query param, then each header param, sent unless unset; a param
|
|
13
13
|
* `stream` carries has none.
|
|
@@ -65,7 +65,7 @@ function declaredHeaders(op) {
|
|
|
65
65
|
.filter((status) => /^2(?:\d\d|XX)$/i.test(status))
|
|
66
66
|
.sort(compareCodeUnits)
|
|
67
67
|
.flatMap((status) => op.ir.responses[status].headers ?? []);
|
|
68
|
-
|
|
68
|
+
// reversed, so the first spelling of a name is the one its key ends on
|
|
69
69
|
const first = new Map(all.toReversed().map((header) => [header.name.toLowerCase(), header]));
|
|
70
70
|
return [...first.values()].sort((a, b) => compareCodeUnits(a.name, b.name));
|
|
71
71
|
}
|
package/dist/emit/go/sdk.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type GeneratedGoSdk = {
|
|
|
14
14
|
readonly packages: readonly PackageIdentity[];
|
|
15
15
|
};
|
|
16
16
|
export declare const WEBSOCKET = "github.com/coder/websocket v1.8.15";
|
|
17
|
-
export declare const WEBSOCKET_SUM: string[];
|
|
17
|
+
export declare const WEBSOCKET_SUM: readonly string[];
|
|
18
18
|
/** String and rune literals and line comments: text an import check must not read as code (the CLI's cmd files too). */
|
|
19
19
|
export declare const NOT_CODE: RegExp;
|
|
20
20
|
/** The Go SDK module for `document`, by file name, and its notices. */
|
package/dist/emit/go/sdk.js
CHANGED
|
@@ -9,22 +9,22 @@
|
|
|
9
9
|
import { toIR } from "../../ir/build.js";
|
|
10
10
|
import { sdkModel } from "../../ir/sdk-model.js";
|
|
11
11
|
import { lineComment } from "../shared/escape.js";
|
|
12
|
-
import { packageOn } from "../shared/metadata.js";
|
|
13
12
|
import { compareCodeUnits } from "../shared/lang.js";
|
|
13
|
+
import { packageOn } from "../shared/metadata.js";
|
|
14
14
|
import { goErrorKeys } from "./errors.js";
|
|
15
15
|
import { needsWebSocket, runtimeFiles } from "./http.js";
|
|
16
16
|
import { goModulePath } from "./module-path.js";
|
|
17
17
|
import { clientDecls } from "./sdk-client.js";
|
|
18
18
|
import { goTopLevel, goTypeContext } from "./types.js";
|
|
19
|
-
|
|
19
|
+
// the marker gopls and linters read, apart from the package doc by a blank line
|
|
20
20
|
const MARKER = "// Code generated by clients. DO NOT EDIT.";
|
|
21
|
-
|
|
21
|
+
// the WebSocket library and its go.sum lines, as the Go checksum database has them; the CLI's module requires them too
|
|
22
22
|
export const WEBSOCKET = "github.com/coder/websocket v1.8.15";
|
|
23
23
|
export const WEBSOCKET_SUM = [
|
|
24
24
|
`${WEBSOCKET} h1:6B2JPeOGlpff2Uz6vOEH1Vzpi0iUz20A+lPVhPHtNUA=`,
|
|
25
25
|
`${WEBSOCKET}/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=`,
|
|
26
26
|
];
|
|
27
|
-
|
|
27
|
+
// what client.go may import, each only when its code uses it
|
|
28
28
|
const CLIENT_IMPORTS = [
|
|
29
29
|
["context", "context"],
|
|
30
30
|
["json", "encoding/json"],
|
|
@@ -37,7 +37,7 @@ const CLIENT_IMPORTS = [
|
|
|
37
37
|
export const NOT_CODE = /"(?:[^"\\\n]|\\.)*"|`[^`]*`|'(?:[^'\\\n]|\\.)*'|\/\/[^\n]*/g;
|
|
38
38
|
/** A `.go` file of package `sdk` holding `decls`, importing each of `imports` (`[name, path]`) its code uses. */
|
|
39
39
|
function goFile(decls, imports) {
|
|
40
|
-
const code = decls.
|
|
40
|
+
const code = decls.replaceAll(NOT_CODE, "");
|
|
41
41
|
const used = imports.filter(([name]) => new RegExp(`\\b${name}\\.`).test(code)).map(([, path]) => `\t"${path}"`);
|
|
42
42
|
const block = used.length === 0 ? "" : `import (\n${used.join("\n")}\n)\n\n`;
|
|
43
43
|
return `${MARKER}\n\npackage sdk\n\n${block}${decls}\n`;
|
|
@@ -70,7 +70,7 @@ function emitGo(document, options) {
|
|
|
70
70
|
const ir = toIR(document, { deriveOperationIds: true });
|
|
71
71
|
const model = sdkModel(ir);
|
|
72
72
|
const at = goTypeContext(ir);
|
|
73
|
-
|
|
73
|
+
// components first: the client's hoisted types then land beside them
|
|
74
74
|
const components = componentDecls(ir, at);
|
|
75
75
|
const ops = model.opsById;
|
|
76
76
|
const notices = [];
|
|
@@ -83,9 +83,6 @@ function emitGo(document, options) {
|
|
|
83
83
|
};
|
|
84
84
|
const modulePath = goModulePath(options.modulePath ?? "example.com/sdk", options.version);
|
|
85
85
|
return {
|
|
86
|
-
notices,
|
|
87
|
-
packages: [packageOn("go", modulePath, options.version)],
|
|
88
|
-
plans: client.plans,
|
|
89
86
|
files: {
|
|
90
87
|
...runtimeFiles(features),
|
|
91
88
|
...moduleFiles(modulePath, needsWebSocket(features)),
|
|
@@ -95,6 +92,9 @@ function emitGo(document, options) {
|
|
|
95
92
|
["json", "encoding/json"],
|
|
96
93
|
]),
|
|
97
94
|
},
|
|
95
|
+
notices,
|
|
96
|
+
packages: [packageOn("go", modulePath, options.version)],
|
|
97
|
+
plans: client.plans,
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
/** The Go SDK module for `document`, by file name, and its notices. */
|
package/dist/emit/go/sse.d.ts
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
* A server-sent-events operation as a Go method (G12): it returns `iter.Seq2[SSEEvent[T], error]`,
|
|
3
|
-
* `T` the type of the declared event schema (`string` when the events are untyped), and opens the
|
|
4
|
-
* stream when ranged. `<Op>Opts.LastEventID` resumes it as the Last-Event-ID header, which also
|
|
5
|
-
* carries a declared Last-Event-ID header param (Fd3). An error status at the opening is the
|
|
6
|
-
* stream's error value; its `Client.Safe()` twin opens the stream on the call and answers that
|
|
7
|
-
* status as its Result's Err (bit 21 i3).
|
|
8
|
-
*/
|
|
9
|
-
import type { SdkOp } from "../../ir/sdk-model.ts";
|
|
1
|
+
import { type SdkOp } from "../../ir/sdk-model.ts";
|
|
10
2
|
import { type GoStream } from "./sdk-answer.ts";
|
|
11
3
|
import type { OptsField } from "./sdk-opts.ts";
|
|
12
4
|
import { type GoTypeContext } from "./types.ts";
|
|
13
5
|
/** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
|
|
14
6
|
export declare const isLastEventIdHeader: (param: string, where: OptsField["in"]) => boolean;
|
|
15
|
-
/** The method of the SSE operation `op`, its event
|
|
7
|
+
/** The method of the SSE operation `op`, its event types hoisted into `at`. */
|
|
16
8
|
export declare function sseStream(op: SdkOp, at: GoTypeContext): GoStream;
|