@workerstack/clients 1.0.0-rc.29 → 1.0.0-rc.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +548 -35
- package/assets/installers/examples/github.config.ts +17 -19
- package/assets/installers/examples/goreleaser.config.ts +16 -18
- package/assets/installers/examples/raw.config.ts +13 -15
- package/bin/clients.js +88 -68
- package/bin/installgen.js +18 -13
- package/dist/cli.d.ts +4 -4
- package/dist/cli.js +20 -12
- package/dist/emit/cli/channels.d.ts +2 -2
- package/dist/emit/cli/channels.js +18 -13
- package/dist/emit/cli/commands.d.ts +1 -1
- package/dist/emit/cli/commands.js +14 -8
- package/dist/emit/cli/discovery.d.ts +0 -6
- package/dist/emit/cli/discovery.js +9 -7
- package/dist/emit/cli/flags.d.ts +1 -3
- package/dist/emit/cli/flags.js +11 -5
- package/dist/emit/cli/install.d.ts +0 -8
- package/dist/emit/cli/install.js +3 -3
- package/dist/emit/cli/layout.d.ts +1 -1
- package/dist/emit/cli/layout.js +13 -10
- package/dist/emit/cli/module.d.ts +6 -6
- package/dist/emit/cli/module.js +10 -10
- package/dist/emit/cli/release.d.ts +0 -11
- package/dist/emit/cli/release.js +4 -4
- package/dist/emit/cli/skills.js +3 -3
- package/dist/emit/csharp/errors.js +4 -4
- package/dist/emit/csharp/json.js +8 -8
- package/dist/emit/csharp/realtime.js +3 -3
- package/dist/emit/csharp/sdk-answer.js +4 -4
- package/dist/emit/csharp/sdk-body.js +8 -6
- package/dist/emit/csharp/sdk-client.d.ts +3 -3
- package/dist/emit/csharp/sdk-client.js +2 -2
- package/dist/emit/csharp/sdk-csproj.d.ts +7 -9
- package/dist/emit/csharp/sdk-csproj.js +10 -10
- package/dist/emit/csharp/sdk-doc.js +1 -1
- package/dist/emit/csharp/sdk-method.d.ts +18 -2
- package/dist/emit/csharp/sdk-method.js +24 -9
- package/dist/emit/csharp/sdk-plan.js +0 -1
- package/dist/emit/csharp/sdk.js +7 -4
- package/dist/emit/csharp/sse.d.ts +0 -2
- package/dist/emit/csharp/sse.js +7 -7
- package/dist/emit/csharp/transport.js +7 -7
- package/dist/emit/csharp/types-enum.js +3 -1
- package/dist/emit/csharp/types-messages.js +3 -3
- package/dist/emit/csharp/types-names.js +10 -12
- package/dist/emit/csharp/types-record.js +3 -3
- package/dist/emit/csharp/types-union.d.ts +1 -1
- package/dist/emit/csharp/types.d.ts +0 -1
- package/dist/emit/csharp/types.js +3 -3
- package/dist/emit/csharp/ws.js +2 -2
- package/dist/emit/go/errors.js +1 -1
- package/dist/emit/go/http.js +2 -2
- package/dist/emit/go/module-path.js +2 -2
- package/dist/emit/go/sdk-answer.js +1 -1
- package/dist/emit/go/sdk-body.js +11 -7
- package/dist/emit/go/sdk-client.js +1 -1
- package/dist/emit/go/sdk-method.d.ts +9 -0
- package/dist/emit/go/sdk-method.js +12 -3
- package/dist/emit/go/sdk-mirror.js +2 -2
- package/dist/emit/go/sdk-opts.d.ts +0 -2
- package/dist/emit/go/sdk-opts.js +3 -3
- package/dist/emit/go/sdk.d.ts +1 -1
- package/dist/emit/go/sdk.js +12 -11
- package/dist/emit/go/sse.js +1 -1
- package/dist/emit/go/types-names.js +5 -0
- package/dist/emit/go/types-struct.d.ts +2 -1
- package/dist/emit/go/types-struct.js +1 -1
- package/dist/emit/go/types.js +9 -9
- package/dist/emit/go/ws.js +6 -6
- package/dist/emit/java/gradle.d.ts +7 -9
- package/dist/emit/java/gradle.js +8 -8
- package/dist/emit/java/json.js +1 -1
- package/dist/emit/java/layout-ast.js +1 -1
- package/dist/emit/java/layout-decl.js +5 -4
- package/dist/emit/java/layout-doc.js +13 -7
- package/dist/emit/java/layout-dot.js +1 -1
- package/dist/emit/java/layout-strings.js +4 -5
- package/dist/emit/java/layout-types.js +7 -5
- package/dist/emit/java/layout-visitor.js +4 -3
- package/dist/emit/java/layout.js +5 -4
- package/dist/emit/java/models-names.js +5 -4
- package/dist/emit/java/models-record.d.ts +0 -1
- package/dist/emit/java/models-record.js +3 -3
- package/dist/emit/java/models-union.d.ts +1 -1
- package/dist/emit/java/models-union.js +1 -1
- package/dist/emit/java/models.d.ts +1 -2
- package/dist/emit/java/models.js +25 -16
- package/dist/emit/java/realtime.d.ts +5 -17
- package/dist/emit/java/realtime.js +1 -1
- package/dist/emit/java/sdk-client.d.ts +6 -6
- package/dist/emit/java/sdk-client.js +2 -1
- package/dist/emit/java/sdk-decl.js +2 -2
- package/dist/emit/java/sdk-errors.js +1 -1
- package/dist/emit/java/sdk-headers.js +2 -2
- package/dist/emit/java/sdk-mirror.js +2 -2
- package/dist/emit/java/sdk-models.d.ts +1 -1
- package/dist/emit/java/sdk-models.js +7 -7
- package/dist/emit/java/sdk-op.d.ts +7 -11
- package/dist/emit/java/sdk-op.js +22 -10
- package/dist/emit/java/sdk-params.d.ts +5 -5
- package/dist/emit/java/sdk-params.js +3 -2
- package/dist/emit/java/sdk-plan.js +0 -1
- package/dist/emit/java/sdk.d.ts +1 -1
- package/dist/emit/java/sdk.js +21 -14
- package/dist/emit/java/sse.d.ts +2 -4
- package/dist/emit/java/sse.js +6 -6
- package/dist/emit/java/ws.d.ts +2 -2
- package/dist/emit/java/ws.js +3 -4
- package/dist/emit/mcp/annotations.js +8 -4
- package/dist/emit/mcp/files.js +9 -9
- package/dist/emit/mcp/mounted.js +2 -2
- package/dist/emit/mcp/output-schema.js +3 -3
- package/dist/emit/mcp/registry.d.ts +0 -2
- package/dist/emit/mcp/registry.js +5 -4
- package/dist/emit/mcp/runtime.js +2 -2
- package/dist/emit/mcp/schema.js +22 -11
- package/dist/emit/mcp/server.d.ts +7 -7
- package/dist/emit/mcp/server.js +7 -6
- package/dist/emit/mcp/tools.js +7 -6
- package/dist/emit/python/errors.js +3 -3
- package/dist/emit/python/realtime.js +2 -2
- package/dist/emit/python/sdk-answer.d.ts +3 -7
- package/dist/emit/python/sdk-answer.js +2 -2
- package/dist/emit/python/sdk-body.js +4 -5
- package/dist/emit/python/sdk-client.js +5 -5
- package/dist/emit/python/sdk-doc.js +2 -2
- package/dist/emit/python/sdk-method.d.ts +11 -0
- package/dist/emit/python/sdk-method.js +20 -5
- package/dist/emit/python/sdk-plan.js +0 -1
- package/dist/emit/python/sdk-pyproject.d.ts +0 -2
- package/dist/emit/python/sdk-pyproject.js +8 -8
- package/dist/emit/python/sdk.d.ts +1 -1
- package/dist/emit/python/sdk.js +12 -8
- package/dist/emit/python/sse.d.ts +0 -2
- package/dist/emit/python/sse.js +2 -2
- package/dist/emit/python/transport.js +4 -4
- package/dist/emit/python/types-dict.d.ts +2 -2
- package/dist/emit/python/types-dict.js +1 -1
- package/dist/emit/python/types-names.js +2 -2
- package/dist/emit/python/types-union.js +1 -1
- package/dist/emit/python/types.js +3 -3
- package/dist/emit/python/ws.d.ts +2 -5
- package/dist/emit/python/ws.js +4 -4
- package/dist/emit/rust/errors.js +3 -3
- package/dist/emit/rust/http.js +4 -4
- package/dist/emit/rust/realtime.js +2 -2
- package/dist/emit/rust/sdk-body.js +8 -5
- package/dist/emit/rust/sdk-cargo.d.ts +16 -18
- package/dist/emit/rust/sdk-cargo.js +12 -12
- package/dist/emit/rust/sdk-client.d.ts +1 -1
- package/dist/emit/rust/sdk-client.js +3 -3
- package/dist/emit/rust/sdk-method.d.ts +12 -1
- package/dist/emit/rust/sdk-method.js +12 -4
- package/dist/emit/rust/sdk-opts.d.ts +2 -1
- package/dist/emit/rust/sdk-opts.js +2 -2
- package/dist/emit/rust/sdk-plan.js +0 -1
- package/dist/emit/rust/sdk.d.ts +1 -1
- package/dist/emit/rust/sdk.js +9 -6
- package/dist/emit/rust/sse.d.ts +0 -5
- package/dist/emit/rust/sse.js +2 -2
- package/dist/emit/rust/types-names.js +3 -3
- package/dist/emit/rust/types-struct.js +1 -1
- package/dist/emit/rust/types-union.d.ts +1 -1
- package/dist/emit/rust/types.js +7 -5
- package/dist/emit/rust/ws.d.ts +0 -11
- package/dist/emit/rust/ws.js +5 -5
- package/dist/emit/shared/escape.js +17 -17
- package/dist/emit/shared/format.js +1 -1
- package/dist/emit/shared/gofmt.js +1 -1
- package/dist/emit/shared/lang.js +10 -10
- package/dist/emit/shared/literals.d.ts +5 -0
- package/dist/emit/shared/literals.js +8 -0
- package/dist/emit/shared/metadata.d.ts +0 -6
- package/dist/emit/shared/metadata.js +8 -7
- package/dist/emit/shared/ruff.js +1 -1
- package/dist/emit/shared/rustfmt.js +1 -1
- package/dist/emit/shared/type-emitter.js +37 -20
- package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
- package/dist/emit/shared/unknown-type.constants.js +2 -0
- package/dist/emit/ts/http.d.ts +8 -2
- package/dist/emit/ts/http.js +51 -6
- package/dist/emit/ts/package.d.ts +14 -12
- package/dist/emit/ts/package.js +10 -8
- package/dist/emit/ts/route-tree.js +2 -2
- package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
- package/dist/emit/ts/sdk-types-preamble.js +12 -4
- package/dist/emit/ts/sdk-types.d.ts +0 -5
- package/dist/emit/ts/sdk-types.js +63 -19
- package/dist/emit/ts/sdk.d.ts +3 -1
- package/dist/emit/ts/sdk.js +44 -12
- package/dist/emit/ts/service-map.d.ts +7 -1
- package/dist/emit/ts/service-map.js +10 -1
- package/dist/emit/ts/single-flight-text.d.ts +3 -0
- package/dist/emit/ts/single-flight-text.js +38 -0
- package/dist/emit/ts/tanstack-query.d.ts +3 -2
- package/dist/emit/ts/tanstack-query.js +60 -35
- package/dist/emit/ts/type-gen.js +31 -18
- package/dist/emit/ts/webhooks.d.ts +0 -2
- package/dist/emit/ts/webhooks.js +3 -3
- package/dist/extract/chain.js +5 -4
- package/dist/extract/extract.js +5 -5
- package/dist/extract/serialize.d.ts +0 -2
- package/dist/extract/serialize.js +14 -15
- package/dist/extract/walk.js +15 -12
- package/dist/gen/args.js +9 -5
- package/dist/gen/formatters.js +5 -3
- package/dist/gen/process.js +2 -1
- package/dist/gen/shipped.js +2 -2
- package/dist/gen/switch-on.constants.d.ts +2 -0
- package/dist/gen/switch-on.constants.js +2 -0
- package/dist/gen/targets.d.ts +6 -7
- package/dist/gen/targets.js +11 -6
- package/dist/gen/write.js +4 -2
- package/dist/index.js +2 -2
- package/dist/installers/cli.d.ts +4 -4
- package/dist/installers/cli.js +24 -24
- package/dist/installers/commands/build.d.ts +4 -4
- package/dist/installers/commands/build.js +2 -3
- package/dist/installers/commands/check.d.ts +2 -2
- package/dist/installers/commands/check.js +11 -10
- package/dist/installers/commands/init.d.ts +2 -2
- package/dist/installers/commands/init.js +1 -2
- package/dist/installers/config/define-config.d.ts +16 -16
- package/dist/installers/config/define-config.js +1 -1
- package/dist/installers/config/hooks/bun.d.ts +6 -6
- package/dist/installers/config/hooks/node.js +1 -1
- package/dist/installers/config/load.d.ts +6 -8
- package/dist/installers/config/load.js +7 -8
- package/dist/installers/config/resolve.d.ts +1 -2
- package/dist/installers/config/resolve.js +28 -33
- package/dist/installers/config/types.d.ts +6 -6
- package/dist/installers/config/types.js +0 -1
- package/dist/installers/render/quote.js +3 -5
- package/dist/installers/render/render.d.ts +6 -6
- package/dist/installers/render/render.js +26 -26
- package/dist/installers/ui.d.ts +4 -4
- package/dist/installers/ui.js +3 -3
- package/dist/ir/build.d.ts +3 -3
- package/dist/ir/build.js +8 -5
- package/dist/ir/invalidate-reads.d.ts +17 -0
- package/dist/ir/invalidate-reads.js +104 -0
- package/dist/ir/load.d.ts +10 -0
- package/dist/ir/load.js +65 -18
- package/dist/ir/model.d.ts +2 -1
- package/dist/ir/model.js +0 -1
- package/dist/ir/read-method.constants.d.ts +2 -0
- package/dist/ir/read-method.constants.js +2 -0
- package/dist/ir/resolve-refs.js +2 -2
- package/dist/ir/resource-tree.js +2 -1
- package/dist/ir/route-tree-intern.js +1 -1
- package/dist/ir/schema.js +3 -3
- package/dist/ir/sdk-model.js +3 -3
- package/dist/ir/slots.js +13 -8
- package/dist/ir/streams.js +1 -1
- package/dist/release/bootstrap.d.ts +3 -3
- package/dist/release/bootstrap.js +7 -7
- package/dist/release/bump-args.js +4 -4
- package/dist/release/bump-command.d.ts +1 -1
- package/dist/release/bump-command.js +9 -10
- package/dist/release/bump.d.ts +5 -4
- package/dist/release/bump.js +2 -2
- package/dist/release/cli.d.ts +4 -4
- package/dist/release/cli.js +4 -4
- package/dist/release/codegen.js +1 -1
- package/dist/release/digest.js +5 -7
- package/dist/release/git.js +5 -8
- package/dist/release/load.js +4 -4
- package/dist/release/manifest.js +9 -10
- package/dist/release/oasdiff.d.ts +10 -15
- package/dist/release/oasdiff.js +5 -6
- package/dist/release/registries.d.ts +0 -11
- package/dist/release/registries.js +17 -17
- package/dist/release/release-state.d.ts +16 -13
- package/dist/release/release-workflow.js +5 -7
- package/dist/release/repo-settings.d.ts +2 -1
- package/dist/release/spec-gate.d.ts +0 -2
- package/dist/release/spec-gate.js +6 -10
- package/dist/release/sync-command.d.ts +2 -2
- package/dist/release/sync-command.js +1 -1
- package/dist/release/sync-tree.js +9 -13
- package/dist/release/sync.d.ts +6 -6
- package/dist/release/sync.js +12 -13
- package/dist/release/types.d.ts +22 -22
- package/dist/release/types.js +0 -1
- package/dist/release/version-files.d.ts +3 -4
- package/dist/release/version-files.js +4 -5
- package/dist/runtime/.oxfmtrc.jsonc +8 -0
- package/dist/runtime/csharp/Config.cs +9 -1
- package/dist/runtime/csharp/Exchange.cs +56 -4
- package/dist/runtime/csharp/Hooks.cs +9 -0
- package/dist/runtime/csharp/Operation.cs +6 -1
- package/dist/runtime/csharp/WsDial.cs +3 -1
- package/dist/runtime/go/config.go +5 -0
- package/dist/runtime/go/hooks.go +70 -0
- package/dist/runtime/go/request.go +6 -2
- package/dist/runtime/go/stream.go +4 -1
- package/dist/runtime/go/ws.go +3 -1
- package/dist/runtime/java/ClientConfig.java +11 -0
- package/dist/runtime/java/Flight.java +2 -12
- package/dist/runtime/java/Hooks.java +45 -0
- package/dist/runtime/java/InvalidateEvent.java +10 -0
- package/dist/runtime/java/InvalidateHook.java +12 -0
- package/dist/runtime/java/InvalidateTarget.java +7 -0
- package/dist/runtime/java/Operation.java +23 -3
- package/dist/runtime/java/Realtime.java +3 -1
- package/dist/runtime/java/WsDial.java +3 -0
- package/dist/runtime/mcp/files.ts +1 -1
- package/dist/runtime/mcp/http.ts +6 -2
- package/dist/runtime/mcp/listen.ts +1 -1
- package/dist/runtime/mcp/mount.ts +2 -2
- package/dist/runtime/mcp/protocol.ts +1 -1
- package/dist/runtime/python/config.py +8 -2
- package/dist/runtime/python/exchange.py +3 -1
- package/dist/runtime/python/hooks.py +110 -5
- package/dist/runtime/python/operation.py +2 -0
- package/dist/runtime/python/send_async.py +14 -2
- package/dist/runtime/python/send_sync.py +4 -2
- package/dist/runtime/python/ws.py +5 -1
- package/dist/runtime/rust/config.rs +6 -1
- package/dist/runtime/rust/exchange.rs +15 -3
- package/dist/runtime/rust/hooks.rs +127 -2
- package/dist/runtime/rust/log.rs +11 -3
- package/dist/runtime/rust/request.rs +17 -0
- package/dist/runtime/rust/ws.rs +9 -1
- package/dist/runtime/ts/config.ts +69 -0
- package/dist/runtime/ts/http.ts +12 -10
- package/dist/runtime/ts/request.ts +2 -0
- package/dist/runtime/ts/response.ts +7 -0
- package/dist/runtime/ts/sdk-invalidate.ts +82 -0
- package/dist/runtime/ts/sdk-single-flight.constants.ts +25 -0
- package/dist/runtime/ts/sdk-single-flight.ts +203 -0
- package/dist/runtime/ts/sdk-sse.ts +5 -1
- package/dist/runtime/ts/sdk-ws.ts +9 -3
- package/dist/runtime/ts/sdk.ts +55 -31
- package/dist/runtime/ts/single-flight-batch.ts +184 -0
- package/dist/runtime/ts/single-flight-body.ts +59 -0
- package/dist/runtime/ts/single-flight-run.ts +160 -0
- package/dist/runtime/ts/single-flight.constants.ts +31 -0
- package/dist/runtime/ts/single-flight.ts +158 -0
- package/dist/runtime/ts-tanstack-query/invalidate.ts +96 -92
- package/dist/runtime/ts-tanstack-query/query.ts +140 -170
- package/package.json +12 -17
- package/references/INDEX.md +31 -0
- package/references/cli.md +33 -0
- package/references/configuring.md +29 -0
- package/references/documentation.md +15 -0
- package/references/errors.md +23 -0
- package/references/flags.md +104 -0
- package/references/gates.md +46 -0
- package/references/generate.md +29 -0
- package/references/install-scripts.md +28 -0
- package/references/install.md +38 -0
- package/references/license.md +8 -0
- package/references/mcp.md +76 -0
- package/references/output.md +45 -0
- package/references/overview.md +14 -0
- package/references/release-tooling.md +34 -0
- package/references/release.md +305 -0
- package/references/sdks.md +393 -0
- package/references/start.md +22 -0
- package/references/tdd.md +16 -0
- package/dist/emit/cli/index.d.ts +0 -1
- package/dist/emit/cli/index.js +0 -1
- package/dist/emit/csharp/index.d.ts +0 -1
- package/dist/emit/csharp/index.js +0 -1
- package/dist/emit/go/index.d.ts +0 -1
- package/dist/emit/go/index.js +0 -1
- package/dist/emit/java/index.d.ts +0 -2
- package/dist/emit/java/index.js +0 -2
- package/dist/emit/mcp/index.d.ts +0 -3
- package/dist/emit/mcp/index.js +0 -3
- package/dist/emit/python/index.d.ts +0 -1
- package/dist/emit/python/index.js +0 -1
- package/dist/emit/rust/index.d.ts +0 -1
- package/dist/emit/rust/index.js +0 -1
|
@@ -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,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One operation as a Go method (G1): `(ctx, <path params in path order>, <body>?, opts *<Op>Opts,
|
|
3
|
+
* reqOpts ...RequestOption)`, filling the runtime's `call` and handing it to `doRequest`, or to its
|
|
4
|
+
* stream's runtime call (`sse.ts`, `ws.ts`). The query and header params ride on `<Op>Opts`, sent
|
|
5
|
+
* only when set. Spec text reaches the source only through the shared escape layer.
|
|
6
|
+
*/
|
|
7
|
+
import type { InvalidatedRead } from "../../ir/invalidate-reads.ts";
|
|
1
8
|
import { type SdkBody, type SdkOp, type SdkResponseKind, type SdkStream } from "../../ir/sdk-model.ts";
|
|
2
9
|
import { type GoSends } from "./sdk-answer.ts";
|
|
3
10
|
import { type GoPart } from "./sdk-body.ts";
|
|
@@ -47,8 +54,10 @@ export type GoMethod = {
|
|
|
47
54
|
readonly twin: Twin;
|
|
48
55
|
};
|
|
49
56
|
/** What every method of one SDK shares: the type context it hoists into. */
|
|
57
|
+
/** The type context, and each write's reads by operationId (`invalidateReads`): what its `OnInvalidate` event names. */
|
|
50
58
|
export type MethodEnv = {
|
|
51
59
|
readonly at: GoTypeContext;
|
|
60
|
+
readonly reads: ReadonlyMap<string, readonly InvalidatedRead[]>;
|
|
52
61
|
};
|
|
53
62
|
/** Where a method lives: its receiver's type, and the expression reaching the `*Client` from it. */
|
|
54
63
|
export type Receiver = {
|
|
@@ -3,11 +3,11 @@ 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",
|
|
@@ -40,6 +40,7 @@ const METHOD_LOCALS = [
|
|
|
40
40
|
"setIdempotencyKey",
|
|
41
41
|
"sseData",
|
|
42
42
|
"sseFail",
|
|
43
|
+
"staleRead",
|
|
43
44
|
"streamEvents",
|
|
44
45
|
"streamText",
|
|
45
46
|
"textField",
|
|
@@ -120,6 +121,13 @@ function callMembers(op, path, body, client) {
|
|
|
120
121
|
...(path.lines.length > 0 ? ["params: params"] : []),
|
|
121
122
|
];
|
|
122
123
|
}
|
|
124
|
+
/** The `call` literal's `OnInvalidate` members: its operationId and the reads a success makes stale, for a write. */
|
|
125
|
+
function invalidatingMembers(op, reads) {
|
|
126
|
+
if (reads === undefined || reads.length === 0)
|
|
127
|
+
return [];
|
|
128
|
+
const each = reads.map((read) => `{${goString(read.operationId)}, []string{${read.params.map(goString).join(", ")}}}`);
|
|
129
|
+
return [`by: ${goString(op.id)}`, `reads: []staleRead{${each.join(", ")}}`];
|
|
130
|
+
}
|
|
123
131
|
/** The twin of a method of `op` returning `returns`, taking `params` before its RequestOptions. */
|
|
124
132
|
function twinOf(op, returns, params) {
|
|
125
133
|
const answered = returns.slice("(".length, -", error)".length);
|
|
@@ -150,12 +158,13 @@ export function goMethod(op, name, receiver, env) {
|
|
|
150
158
|
`opts *${opts}`,
|
|
151
159
|
"reqOpts ...RequestOption",
|
|
152
160
|
];
|
|
161
|
+
const members = [...callMembers(op, path, body, receiver.client), ...invalidatingMembers(op, env.reads.get(op.id))];
|
|
153
162
|
const lines = [
|
|
154
163
|
...methodDoc(op, name, stream),
|
|
155
164
|
`func (r *${receiver.type}) ${name}(${params.join(", ")}) ${shape.returns} {`,
|
|
156
165
|
...path.lines,
|
|
157
166
|
...(body ? body.lines(shape.fail) : []),
|
|
158
|
-
`\tc := &call{${
|
|
167
|
+
`\tc := &call{${members.join(", ")}}`,
|
|
159
168
|
...optsLines(op, fields, streamOpts),
|
|
160
169
|
...shape.tail(receiver.client),
|
|
161
170
|
"}",
|
|
@@ -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
|
@@ -7,24 +7,25 @@
|
|
|
7
7
|
* generated-code marker.
|
|
8
8
|
*/
|
|
9
9
|
import { toIR } from "../../ir/build.js";
|
|
10
|
+
import { invalidateReads } from "../../ir/invalidate-reads.js";
|
|
10
11
|
import { sdkModel } from "../../ir/sdk-model.js";
|
|
11
12
|
import { lineComment } from "../shared/escape.js";
|
|
12
|
-
import { packageOn } from "../shared/metadata.js";
|
|
13
13
|
import { compareCodeUnits } from "../shared/lang.js";
|
|
14
|
+
import { packageOn } from "../shared/metadata.js";
|
|
14
15
|
import { goErrorKeys } from "./errors.js";
|
|
15
16
|
import { needsWebSocket, runtimeFiles } from "./http.js";
|
|
16
17
|
import { goModulePath } from "./module-path.js";
|
|
17
18
|
import { clientDecls } from "./sdk-client.js";
|
|
18
19
|
import { goTopLevel, goTypeContext } from "./types.js";
|
|
19
|
-
|
|
20
|
+
// the marker gopls and linters read, apart from the package doc by a blank line
|
|
20
21
|
const MARKER = "// Code generated by clients. DO NOT EDIT.";
|
|
21
|
-
|
|
22
|
+
// the WebSocket library and its go.sum lines, as the Go checksum database has them; the CLI's module requires them too
|
|
22
23
|
export const WEBSOCKET = "github.com/coder/websocket v1.8.15";
|
|
23
24
|
export const WEBSOCKET_SUM = [
|
|
24
25
|
`${WEBSOCKET} h1:6B2JPeOGlpff2Uz6vOEH1Vzpi0iUz20A+lPVhPHtNUA=`,
|
|
25
26
|
`${WEBSOCKET}/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=`,
|
|
26
27
|
];
|
|
27
|
-
|
|
28
|
+
// what client.go may import, each only when its code uses it
|
|
28
29
|
const CLIENT_IMPORTS = [
|
|
29
30
|
["context", "context"],
|
|
30
31
|
["json", "encoding/json"],
|
|
@@ -37,7 +38,7 @@ const CLIENT_IMPORTS = [
|
|
|
37
38
|
export const NOT_CODE = /"(?:[^"\\\n]|\\.)*"|`[^`]*`|'(?:[^'\\\n]|\\.)*'|\/\/[^\n]*/g;
|
|
38
39
|
/** A `.go` file of package `sdk` holding `decls`, importing each of `imports` (`[name, path]`) its code uses. */
|
|
39
40
|
function goFile(decls, imports) {
|
|
40
|
-
const code = decls.
|
|
41
|
+
const code = decls.replaceAll(NOT_CODE, "");
|
|
41
42
|
const used = imports.filter(([name]) => new RegExp(`\\b${name}\\.`).test(code)).map(([, path]) => `\t"${path}"`);
|
|
42
43
|
const block = used.length === 0 ? "" : `import (\n${used.join("\n")}\n)\n\n`;
|
|
43
44
|
return `${MARKER}\n\npackage sdk\n\n${block}${decls}\n`;
|
|
@@ -70,11 +71,11 @@ function emitGo(document, options) {
|
|
|
70
71
|
const ir = toIR(document, { deriveOperationIds: true });
|
|
71
72
|
const model = sdkModel(ir);
|
|
72
73
|
const at = goTypeContext(ir);
|
|
73
|
-
|
|
74
|
+
// components first: the client's hoisted types then land beside them
|
|
74
75
|
const components = componentDecls(ir, at);
|
|
75
|
-
const
|
|
76
|
+
const { reads, warnings } = invalidateReads(ir);
|
|
76
77
|
const notices = [];
|
|
77
|
-
const client = clientDecls(ir, { at, notices, ops });
|
|
78
|
+
const client = clientDecls(ir, { at, notices, ops: model.opsById, reads });
|
|
78
79
|
const errorKeys = goErrorKeys(model, at);
|
|
79
80
|
const hoisted = [...at.decls].sort(([a], [b]) => compareCodeUnits(a, b)).map(([, decl]) => decl);
|
|
80
81
|
const features = {
|
|
@@ -83,9 +84,6 @@ function emitGo(document, options) {
|
|
|
83
84
|
};
|
|
84
85
|
const modulePath = goModulePath(options.modulePath ?? "example.com/sdk", options.version);
|
|
85
86
|
return {
|
|
86
|
-
notices,
|
|
87
|
-
packages: [packageOn("go", modulePath, options.version)],
|
|
88
|
-
plans: client.plans,
|
|
89
87
|
files: {
|
|
90
88
|
...runtimeFiles(features),
|
|
91
89
|
...moduleFiles(modulePath, needsWebSocket(features)),
|
|
@@ -95,6 +93,9 @@ function emitGo(document, options) {
|
|
|
95
93
|
["json", "encoding/json"],
|
|
96
94
|
]),
|
|
97
95
|
},
|
|
96
|
+
notices: [...notices, ...warnings.map((warning) => `go: ${warning}`)],
|
|
97
|
+
packages: [packageOn("go", modulePath, options.version)],
|
|
98
|
+
plans: client.plans,
|
|
98
99
|
};
|
|
99
100
|
}
|
|
100
101
|
/** The Go SDK module for `document`, by file name, and its notices. */
|
package/dist/emit/go/sse.js
CHANGED
|
@@ -5,7 +5,7 @@ import { sendArgs } from "./sdk-answer.js";
|
|
|
5
5
|
import { goTypeOf } from "./types.js";
|
|
6
6
|
/** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
|
|
7
7
|
export const isLastEventIdHeader = (param, where) => where === "header" && param.toLowerCase() === "last-event-id";
|
|
8
|
-
|
|
8
|
+
// LastEventID, sent only when set: an empty header would still name a position
|
|
9
9
|
const SSE_OPTS = {
|
|
10
10
|
before: [],
|
|
11
11
|
carries: isLastEventIdHeader,
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The package-level names Go types are declared under (v0 buildGoNames): one scope that components,
|
|
3
|
+
* hoisted types and constants all claim from, clear of every identifier the Go runtime declares.
|
|
4
|
+
*/
|
|
5
|
+
import {} from "../../ir/model.js";
|
|
1
6
|
import { irResolver } from "../../ir/schema.js";
|
|
2
7
|
import { valueCycleSchemas } from "../../ir/sdk-model.js";
|
|
3
8
|
import { compareCodeUnits, goExported, NameScope } from "../shared/lang.js";
|
|
@@ -10,7 +10,7 @@ export type StructField = {
|
|
|
10
10
|
triState: boolean;
|
|
11
11
|
};
|
|
12
12
|
/** The field holding the keys `additionalProperties` admits beyond the declared ones. */
|
|
13
|
-
|
|
13
|
+
type ExtraField = {
|
|
14
14
|
goName: string;
|
|
15
15
|
valueType: string;
|
|
16
16
|
};
|
|
@@ -27,3 +27,4 @@ export type StructShape = {
|
|
|
27
27
|
export declare function isTagName(key: string): boolean;
|
|
28
28
|
/** `type <name> struct { … }` with its embeds, fields and extra map, then whatever methods its keys need. */
|
|
29
29
|
export declare function structDecl(name: string, shape: StructShape): string;
|
|
30
|
+
export {};
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { goString } from "../shared/escape.js";
|
|
8
8
|
import { fillingMarshal, marshal, unmarshal } from "./types-codec.js";
|
|
9
|
-
|
|
9
|
+
// the punctuation encoding/json's isValidTag accepts in a tag name
|
|
10
10
|
const TAG_PUNCTUATION = "!#$%&()*+-./:;<=>?@[]^_{|}~ ";
|
|
11
11
|
/** Whether encoding/json reads `key` as a tag name (its isValidTag: a letter, a decimal digit or that punctuation). */
|
|
12
12
|
export function isTagName(key) {
|
package/dist/emit/go/types.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { goString } from "../shared/escape.js";
|
|
2
2
|
import { compareCodeUnits, goExported, NameScope } from "../shared/lang.js";
|
|
3
|
-
import { irNames, plainNames } from "./types-names.js";
|
|
4
3
|
import { isNilable } from "./types-codec.js";
|
|
4
|
+
import { irNames, plainNames } from "./types-names.js";
|
|
5
5
|
import { isTagName, structDecl } from "./types-struct.js";
|
|
6
6
|
import { unionDecl, variantTypes } from "./types-union.js";
|
|
7
7
|
const RAW = "json.RawMessage";
|
|
8
|
-
|
|
8
|
+
// deeper than this, a schema is raw JSON
|
|
9
9
|
const MAX_DEPTH = 12;
|
|
10
10
|
const SCALARS = {
|
|
11
11
|
boolean: "bool",
|
|
@@ -22,7 +22,7 @@ export function goTypeContext(ir) {
|
|
|
22
22
|
function declare(ir, at, key, base) {
|
|
23
23
|
const name = at.names.hoist(key, base);
|
|
24
24
|
if (!at.decls.has(name)) {
|
|
25
|
-
|
|
25
|
+
// claimed before its body: what the body hoists in turn comes after it
|
|
26
26
|
at.decls.set(name, "");
|
|
27
27
|
at.decls.set(name, goTopLevel(name, ir, at));
|
|
28
28
|
}
|
|
@@ -71,7 +71,7 @@ const USES = {
|
|
|
71
71
|
ref: refUse,
|
|
72
72
|
scalar: (ir, at) => (isEnum(ir) ? hoist(ir, at) : SCALARS[ir.type]),
|
|
73
73
|
tuple: (ir) => `[${ir.items.length}]interface{}`,
|
|
74
|
-
|
|
74
|
+
// Go has no union type
|
|
75
75
|
union: () => RAW,
|
|
76
76
|
unknown: () => RAW,
|
|
77
77
|
};
|
|
@@ -85,13 +85,13 @@ export function goTypeOf(ir, at) {
|
|
|
85
85
|
/** A label for an enum value inside a constant name: `""` is `Empty`, a negative number `Neg<n>`. */
|
|
86
86
|
function enumLabel(value) {
|
|
87
87
|
if (typeof value === "number")
|
|
88
|
-
return `${value < 0 ? "Neg" : ""}${String(Math.abs(value)).
|
|
88
|
+
return `${value < 0 ? "Neg" : ""}${String(Math.abs(value)).replaceAll(/\W/g, "_")}`;
|
|
89
89
|
return value === "" ? "Empty" : goExported(String(value));
|
|
90
90
|
}
|
|
91
91
|
/** `type <name> string|int` and one `<name><Label>` constant per value of its kind. */
|
|
92
92
|
function enumDecl(name, ir, names) {
|
|
93
93
|
const integer = ir.type === "integer";
|
|
94
|
-
|
|
94
|
+
// a value of the other kind (or a null) has no constant
|
|
95
95
|
const values = ir.enum.filter((value) => integer ? Number.isInteger(value) : value !== null);
|
|
96
96
|
const labels = new NameScope();
|
|
97
97
|
const consts = values.map((value) => {
|
|
@@ -132,7 +132,7 @@ function objectDecl(name, ir, at) {
|
|
|
132
132
|
: undefined;
|
|
133
133
|
return structDecl(name, { embeds: [], extra, fields });
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
// the kinds a required field may render as a slice or a map, whose nil a MarshalJSON fills
|
|
136
136
|
const SLICE_OR_MAP = ["allOf", "array", "nullable", "object"];
|
|
137
137
|
/** A field encoding/json handles alone: a key a tag can name, never a required slice or map. */
|
|
138
138
|
const plainField = (field) => isTagName(field.name) && !(field.required && SLICE_OR_MAP.includes(field.schema.kind));
|
|
@@ -172,7 +172,7 @@ export function goTopLevel(name, ir, at) {
|
|
|
172
172
|
const variant = (schema, key, base) => declare(schema, at, key, base);
|
|
173
173
|
return unionDecl(name, { ...ir, discriminator: ir.discriminator }, at.names, variant);
|
|
174
174
|
}
|
|
175
|
-
|
|
175
|
+
// a map or an empty struct is a named type; anything else an alias
|
|
176
176
|
return `type ${name} ${ir.kind === "object" ? "" : "= "}${use(ir, member(name, at, "Value"))}`;
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
@@ -181,7 +181,7 @@ export function goTopLevel(name, ir, at) {
|
|
|
181
181
|
*/
|
|
182
182
|
export function goKeyedMembers(schema, dispatch, at) {
|
|
183
183
|
const name = schema.kind === "ref" ? at.names.ref(schema.name) : `${goExported(at.parentName)}${goExported(at.fieldName)}`;
|
|
184
|
-
|
|
184
|
+
// a mapping names refs only, whose type is their component's: the key alone names each inline member
|
|
185
185
|
const union = { ...dispatch.union, discriminator: { propertyName: dispatch.key } };
|
|
186
186
|
const types = variantTypes(name, union, at.names, (variant, key, base) => declare(variant, at, key, base));
|
|
187
187
|
return dispatch.members.map(({ value }, i) => [value, types[i]]);
|
package/dist/emit/go/ws.js
CHANGED
|
@@ -6,7 +6,7 @@ import { isLastEventIdHeader } from "./sse.js";
|
|
|
6
6
|
import { goKeyedMembers, goTypeOf } from "./types.js";
|
|
7
7
|
/** Whether a declared param is the `reconnect_token` query param a WebSocket dial sends. */
|
|
8
8
|
const isReconnectToken = (param, where) => where === "query" && param === "reconnect_token";
|
|
9
|
-
|
|
9
|
+
// both open a socket: a dial fails before any stream exists
|
|
10
10
|
const FAIL = "nil, err";
|
|
11
11
|
const WS_OPTS = {
|
|
12
12
|
before: [],
|
|
@@ -25,16 +25,16 @@ const WS_OPTS = {
|
|
|
25
25
|
const WS = {
|
|
26
26
|
base: "TypedWebSocket",
|
|
27
27
|
handlers: ["OnMessage", "OnClose", "OnError"],
|
|
28
|
+
open: (client, read, write) => `dialWebSocket(${sendArgs(client, read, write)})`,
|
|
28
29
|
suffix: "Socket",
|
|
29
30
|
what: "socket",
|
|
30
|
-
open: (client, read, write) => `dialWebSocket(${sendArgs(client, read, write)})`,
|
|
31
31
|
};
|
|
32
32
|
const REALTIME = {
|
|
33
33
|
base: "ResumableConnection",
|
|
34
34
|
handlers: ["OnMessage"],
|
|
35
|
+
open: (client, read, write) => `newRealtime(${sendArgs(client, "topts", read, write)})`,
|
|
35
36
|
suffix: "Connection",
|
|
36
37
|
what: "connection",
|
|
37
|
-
open: (client, read, write) => `newRealtime(${sendArgs(client, "topts", read, write)})`,
|
|
38
38
|
};
|
|
39
39
|
/** `<Op><direction>`, the sealed interface of the keyed union `schema`'s members, each marked as one; its lines. */
|
|
40
40
|
function sealed(op, members, iface, says) {
|
|
@@ -99,7 +99,7 @@ function keyedInbound(op, send, dispatch, at) {
|
|
|
99
99
|
].join("\n"));
|
|
100
100
|
return { codec: decode, decode, key: dispatch.key, members, type: iface };
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
// a send of an op that declares none: as given
|
|
103
103
|
const UNTYPED_OUT = { codec: "messageAsIs", type: "any" };
|
|
104
104
|
/** The fields `schema` requires at its top level: an object's, none for any other schema. */
|
|
105
105
|
function requiredOf(schema, at) {
|
|
@@ -188,7 +188,7 @@ function wsStream(op, at) {
|
|
|
188
188
|
const read = inbound(op, send, () => ({ codec: "frameBytes", type: "[]byte" }), at);
|
|
189
189
|
return { ...answerOf(op, WS, { read, write: outbound(op, receive, at) }, at), doc: "", opts: WS_OPTS };
|
|
190
190
|
}
|
|
191
|
-
|
|
191
|
+
// the realtime Opts' one own field, which `sets` copies: the method sets its Headers and HTTPClient
|
|
192
192
|
const REALTIME_FIELDS = [
|
|
193
193
|
{
|
|
194
194
|
doc: "Transport is the resume cursor, the offered subprotocols and the reconnect policy; the connection advances its own copy, and the client sets Headers and HTTPClient.",
|
|
@@ -198,7 +198,7 @@ const REALTIME_FIELDS = [
|
|
|
198
198
|
];
|
|
199
199
|
const REALTIME_OPTS = {
|
|
200
200
|
before: ["var topts TransportOpts"],
|
|
201
|
-
|
|
201
|
+
// the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID
|
|
202
202
|
carries: (param, where) => isReconnectToken(param, where) ||
|
|
203
203
|
(where === "query" && param === "last_event_id") ||
|
|
204
204
|
isLastEventIdHeader(param, where),
|
|
@@ -6,8 +6,6 @@ export type JavaPackage = {
|
|
|
6
6
|
readonly packageName: string;
|
|
7
7
|
readonly version: string;
|
|
8
8
|
};
|
|
9
|
-
/** The one runtime dependency, its coordinates pinned with the test classpath's (java-pins.json). */
|
|
10
|
-
export declare const JACKSON = "tools.jackson.core:jackson-databind:3.2.4";
|
|
11
9
|
/** A Maven group id: lowercase dotted words. */
|
|
12
10
|
export declare const validateGroupId: (value: string) => string;
|
|
13
11
|
/** A Maven artifact id: lowercase words joined by `-`. */
|
|
@@ -21,23 +19,23 @@ export declare const validateVersion: (value: string) => string;
|
|
|
21
19
|
/** What Maven Central requires of a POM beyond its name and description, each part the caller gave, validated. */
|
|
22
20
|
export type JavaPomMetadata = {
|
|
23
21
|
/** the POM's description, over the document's */
|
|
24
|
-
readonly description?: string;
|
|
22
|
+
readonly description?: string | undefined;
|
|
25
23
|
/** the project's https home page, the POM's `url` */
|
|
26
|
-
readonly homepage?: string;
|
|
24
|
+
readonly homepage?: string | undefined;
|
|
27
25
|
/** one SPDX license id */
|
|
28
|
-
readonly license?: string;
|
|
26
|
+
readonly license?: string | undefined;
|
|
29
27
|
/** the https URL of its git repository, without a trailing `/` or `.git` */
|
|
30
|
-
readonly repository?: string;
|
|
28
|
+
readonly repository?: string | undefined;
|
|
31
29
|
/** the POM's developers, comma separated: each a name, or `Name <email>` */
|
|
32
|
-
readonly developers?: string;
|
|
30
|
+
readonly developers?: string | undefined;
|
|
33
31
|
};
|
|
34
32
|
/** The POM metadata validated: the developers one entry each. */
|
|
35
33
|
type PomFields = Omit<JavaPomMetadata, "developers"> & {
|
|
36
|
-
readonly developers?: readonly string[];
|
|
34
|
+
readonly developers?: readonly string[] | undefined;
|
|
37
35
|
};
|
|
38
36
|
/** The POM's words: the document's name and description (spec text, written only through `groovyString`), the rest. */
|
|
39
37
|
export type JavaPom = PomFields & {
|
|
40
|
-
readonly name?: string;
|
|
38
|
+
readonly name?: string | undefined;
|
|
41
39
|
};
|
|
42
40
|
/** The POM for `options` over the document's `info`: the metadata validated, its description over the document's. */
|
|
43
41
|
export declare function pomOf(options: JavaPomMetadata, info: {
|
package/dist/emit/java/gradle.js
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
import { escapeText } from "../shared/escape.js";
|
|
11
11
|
import { AUTHOR, authorOf, checked, HTTPS_URL, SPDX_ID, TEXT } from "../shared/metadata.js";
|
|
12
12
|
/** The one runtime dependency, its coordinates pinned with the test classpath's (java-pins.json). */
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const JACKSON = "tools.jackson.core:jackson-databind:3.2.4";
|
|
14
|
+
// Java's keywords and literals (JLS 3.9, 3.10.3, 3.10.7): no package segment may be one, and `_` is one since 9
|
|
15
15
|
const RESERVED = [
|
|
16
16
|
"abstract",
|
|
17
17
|
"assert",
|
|
@@ -68,15 +68,15 @@ const RESERVED = [
|
|
|
68
68
|
"null",
|
|
69
69
|
"_",
|
|
70
70
|
];
|
|
71
|
-
|
|
71
|
+
// the type names the client file spells or imports, and its nested Builder: a client of one of these clashes
|
|
72
72
|
const SPELLED = ["Builder", "IllegalStateException", "String", "Transport", "URI"];
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
// a Maven group: lowercase dotted words; an artifact: lowercase words joined by `-`; a package segment: a lowercase
|
|
74
|
+
// identifier; a client: a PascalCase type
|
|
75
75
|
const GROUP_ID = /^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)*$/;
|
|
76
76
|
const ARTIFACT_ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
77
77
|
const SEGMENT = /^[a-z_][a-z0-9_]*$/;
|
|
78
78
|
const CLIENT_NAME = /^[A-Z][A-Za-z0-9_]*$/;
|
|
79
|
-
|
|
79
|
+
// SemVer 2 (semver.org's recommended pattern), as the C# and Rust packages take it
|
|
80
80
|
const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
81
81
|
const refuse = (option, value) => {
|
|
82
82
|
throw new Error(`Invalid ${option}: ${JSON.stringify(value)}`);
|
|
@@ -95,7 +95,7 @@ export function validatePackageName(value) {
|
|
|
95
95
|
export const validateClientName = (value) => CLIENT_NAME.test(value) && !SPELLED.includes(value) ? value : refuse("clientName", value);
|
|
96
96
|
/** A SemVer 2 version. */
|
|
97
97
|
export const validateVersion = (value) => (SEMVER.test(value) ? value : refuse("version", value));
|
|
98
|
-
|
|
98
|
+
// a repository is a path on its host: `https://host/owner/name`
|
|
99
99
|
const REPOSITORY_PATH = /^https:\/\/[^/]+\/[^/]/;
|
|
100
100
|
/** The developers option as one author each, or a refusal of the whole value when any is not a name or `Name <email>`. */
|
|
101
101
|
function developersOf(value) {
|
|
@@ -128,7 +128,7 @@ export function pomOf(options, info) {
|
|
|
128
128
|
* text neither interpolates (no `$` in `'…'`) nor ends the string.
|
|
129
129
|
*/
|
|
130
130
|
const groovyString = (text) => `'${escapeText(text, "java").replaceAll("'", "\\'")}'`;
|
|
131
|
-
|
|
131
|
+
// the indent of the `pom { … }` block's members, and of one level in
|
|
132
132
|
const POM = " ";
|
|
133
133
|
const IN = " ";
|
|
134
134
|
/** `key = '…'` lines at `indent`, each value a Groovy string. */
|
package/dist/emit/java/json.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { javaString } from "../shared/escape.js";
|
|
7
7
|
import { bin, call, classOf, forOpen, ifOpen, lit, local, methodHeader, newOf, param, returnStmt, rule, statement, throwStmt, typeHeader, } from "./layout.js";
|
|
8
|
-
|
|
8
|
+
// a payload's erasure: `Class` takes no type arguments
|
|
9
9
|
const erased = (type) => type.replace(/<.*$/, "");
|
|
10
10
|
/** One switch arm, `case label -> value;` (`default` for no label), in the switch's body. */
|
|
11
11
|
const arm = (label, value) => statement(8, rule(label === null ? null : lit(label), value));
|
|
@@ -52,7 +52,7 @@ export const id = (path) => path
|
|
|
52
52
|
/** A literal or any token kept whole: `"GET"`, `null`, `true`, `16L`. */
|
|
53
53
|
export const lit = (text) => ({ k: "lit", text });
|
|
54
54
|
/** A string as an expression: an identifier path, else a token kept whole. */
|
|
55
|
-
export const expr = (e) => typeof e
|
|
55
|
+
export const expr = (e) => typeof e === "string" ? (/^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*)*$/.test(e) ? id(e) : lit(e)) : e;
|
|
56
56
|
/** `of.name(args)`, or `name(args)` with no receiver; a string receiver is an identifier path. */
|
|
57
57
|
export const call = (of, name, args = []) => ({
|
|
58
58
|
args: args.map(expr),
|
|
@@ -125,15 +125,16 @@ export function method(v, m) {
|
|
|
125
125
|
/** The return type and the name with its `(`, the break before the name tagged. */
|
|
126
126
|
function nameScope(v, m, beforeName) {
|
|
127
127
|
v.b.open(0);
|
|
128
|
-
if (m.returns
|
|
128
|
+
if (m.returns === undefined) {
|
|
129
|
+
v.b.open(0);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
129
132
|
v.b.open(0);
|
|
130
133
|
v.b.open(0);
|
|
131
134
|
v.type(type(m.returns));
|
|
132
135
|
v.b.close();
|
|
133
136
|
v.b.brk("independent", " ", 0, beforeName);
|
|
134
|
-
}
|
|
135
|
-
else
|
|
136
|
-
v.b.open(0); /* a constructor's name scope opens with its name */
|
|
137
|
+
} /* a constructor's name scope opens with its name */
|
|
137
138
|
v.b.token(m.name);
|
|
138
139
|
v.b.token("(");
|
|
139
140
|
v.b.close();
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/** google-java-format's line width. */
|
|
10
10
|
export const WIDTH = 100;
|
|
11
|
-
|
|
11
|
+
// a forced break is "wider" than any line (Doc.MAX_LINE_WIDTH)
|
|
12
12
|
const MAX = 1000;
|
|
13
13
|
const evalIndent = (indent) => typeof indent === "number" ? indent : indent.tag.taken ? indent.onBreak : indent.onFlat;
|
|
14
14
|
/** Indent.If: `onBreak` when `tag`'s break was taken, else `onFlat`. */
|
|
@@ -50,8 +50,9 @@ function computeBroken(doc, start) {
|
|
|
50
50
|
doc.breaks.push(child);
|
|
51
51
|
doc.splits.push([]);
|
|
52
52
|
}
|
|
53
|
-
else
|
|
53
|
+
else {
|
|
54
54
|
doc.splits.at(-1).push(child);
|
|
55
|
+
}
|
|
55
56
|
}
|
|
56
57
|
return doc.splits.reduce((state, split, i) => breakAndSplit(state, i === 0 ? undefined : doc.breaks[i - 1], split), start);
|
|
57
58
|
}
|
|
@@ -68,8 +69,9 @@ function breakAndSplit(state, brk, split) {
|
|
|
68
69
|
brk.newIndent = Math.max(state.lastIndent + evalIndent(brk.indent), 0);
|
|
69
70
|
next = { ...state, column: brk.newIndent };
|
|
70
71
|
}
|
|
71
|
-
else
|
|
72
|
+
else {
|
|
72
73
|
next = { ...state, column: state.column + brk.flat.length };
|
|
74
|
+
}
|
|
73
75
|
}
|
|
74
76
|
const room = next.column + splitWidth <= WIDTH;
|
|
75
77
|
next = { ...next, mustBreak: false };
|
|
@@ -78,20 +80,24 @@ function breakAndSplit(state, brk, split) {
|
|
|
78
80
|
return room ? next : { ...next, mustBreak: true };
|
|
79
81
|
}
|
|
80
82
|
function write(doc, out) {
|
|
81
|
-
if (doc.k === "text")
|
|
83
|
+
if (doc.k === "text") {
|
|
82
84
|
put(doc, out);
|
|
83
|
-
|
|
85
|
+
}
|
|
86
|
+
else if (doc.k === "break") {
|
|
84
87
|
out.text += doc.broken ? `\n${" ".repeat(doc.newIndent)}` : doc.flat;
|
|
85
|
-
|
|
88
|
+
}
|
|
89
|
+
else if (doc.oneLine) {
|
|
86
90
|
for (const child of doc.docs)
|
|
87
91
|
writeFlat(child, out);
|
|
88
|
-
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
89
94
|
doc.splits.forEach((split, i) => {
|
|
90
95
|
if (i > 0)
|
|
91
96
|
write(doc.breaks[i - 1], out);
|
|
92
97
|
for (const child of split)
|
|
93
98
|
write(child, out);
|
|
94
99
|
});
|
|
100
|
+
}
|
|
95
101
|
}
|
|
96
102
|
function writeFlat(doc, out) {
|
|
97
103
|
if (doc.k === "level")
|
|
@@ -59,7 +59,7 @@ function regularDot(v, items) {
|
|
|
59
59
|
}
|
|
60
60
|
v.b.token(e.name);
|
|
61
61
|
argsAndParen(v, e, 0);
|
|
62
|
-
|
|
62
|
+
// the last item is the chain itself, and no dot follows it
|
|
63
63
|
if (i < items.length - 1)
|
|
64
64
|
length += v.flat(e).length;
|
|
65
65
|
});
|
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
* `+` chain (or stands alone), else under its own quote.
|
|
5
5
|
*/
|
|
6
6
|
import { WIDTH } from "./layout-doc.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* `\n`/`\r` escapes ending the piece it closes
|
|
10
|
-
*/
|
|
7
|
+
// StringWrapper.stringComponents: a literal's body cut before each whitespace character (and a `\t`), a run of
|
|
8
|
+
// `\n`/`\r` escapes ending the piece it closes
|
|
11
9
|
function piecesOf(body) {
|
|
12
10
|
const out = [];
|
|
13
11
|
let start = 0;
|
|
@@ -19,8 +17,9 @@ function piecesOf(body) {
|
|
|
19
17
|
while (body.startsWith("\\r", i) || body.startsWith("\\n", i))
|
|
20
18
|
i += 2;
|
|
21
19
|
}
|
|
22
|
-
else
|
|
20
|
+
else {
|
|
23
21
|
continue;
|
|
22
|
+
}
|
|
24
23
|
out.push(body.slice(start, i));
|
|
25
24
|
start = i;
|
|
26
25
|
}
|