@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InstallgenError } from "../errors.js";
|
|
2
2
|
import { TAG_SENTINEL, VERSION_SENTINEL, tagToken, versionToken, } from "./define-config.js";
|
|
3
|
-
|
|
3
|
+
const ALL_PLATFORMS = [
|
|
4
4
|
"linux/amd64",
|
|
5
5
|
"linux/arm64",
|
|
6
6
|
"darwin/amd64",
|
|
@@ -11,12 +11,12 @@ export const ALL_PLATFORMS = [
|
|
|
11
11
|
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
12
12
|
const ENV_PREFIX = /^[A-Z_][A-Z0-9_]*$/;
|
|
13
13
|
const TAG_PREFIX = /^[A-Za-z0-9._-]*$/;
|
|
14
|
-
|
|
14
|
+
// Each segment of installDir after ~/: rendered into sh and ps1 paths and shell profile lines
|
|
15
15
|
const DIR_SEGMENT = /^[A-Za-z0-9._ -]+$/;
|
|
16
16
|
const SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*:/;
|
|
17
17
|
const LOOPBACK = ["127.0.0.1", "localhost", "[::1]"];
|
|
18
18
|
const MANGLED = /installgen(version|tag)/;
|
|
19
|
-
|
|
19
|
+
// the issuer of the OIDC token a GitHub Actions run signs with
|
|
20
20
|
const GITHUB_ACTIONS_ISSUER = "https://token.actions.githubusercontent.com";
|
|
21
21
|
const fail = (message) => {
|
|
22
22
|
throw new InstallgenError(message);
|
|
@@ -52,25 +52,25 @@ function checkUrl(field, url) {
|
|
|
52
52
|
return fail(`config.${field} must be an https URL (http is allowed only on loopback), got ${JSON.stringify(url)}`);
|
|
53
53
|
}
|
|
54
54
|
function checkRelative(field, path) {
|
|
55
|
-
if (path === "" || path.startsWith("/") || SCHEME.test(path))
|
|
55
|
+
if (path === "" || path.startsWith("/") || SCHEME.test(path))
|
|
56
56
|
fail(`config.${field} must be a path relative to baseUrl, got ${JSON.stringify(path)}`);
|
|
57
|
-
}
|
|
58
57
|
}
|
|
59
58
|
function noSentinel(field, value) {
|
|
60
|
-
if (value?.includes(VERSION_SENTINEL) || value?.includes(TAG_SENTINEL))
|
|
59
|
+
if (value?.includes(VERSION_SENTINEL) || value?.includes(TAG_SENTINEL))
|
|
61
60
|
fail(`config.${field} cannot hold a version or tag token; only path functions can`);
|
|
62
|
-
}
|
|
63
61
|
}
|
|
64
62
|
/** Splits on the exact sentinels; a sentinel a string method rewrote is still recognizable in a literal piece. */
|
|
65
63
|
function split(field, platform, path) {
|
|
66
64
|
const segments = [];
|
|
67
65
|
for (const piece of path.split(new RegExp(`(${VERSION_SENTINEL}|${TAG_SENTINEL})`))) {
|
|
68
|
-
if (piece === VERSION_SENTINEL)
|
|
66
|
+
if (piece === VERSION_SENTINEL) {
|
|
69
67
|
segments.push({ kind: "version" });
|
|
70
|
-
|
|
68
|
+
}
|
|
69
|
+
else if (piece === TAG_SENTINEL) {
|
|
71
70
|
segments.push({ kind: "tag" });
|
|
71
|
+
}
|
|
72
72
|
else if (piece !== "") {
|
|
73
|
-
if (MANGLED.test(piece.toLowerCase().
|
|
73
|
+
if (MANGLED.test(piece.toLowerCase().replaceAll(/[^a-z0-9]/g, ""))) {
|
|
74
74
|
fail(`config.${field} for ${platform} returned a mangled version or tag token (${JSON.stringify(path)}); ` +
|
|
75
75
|
"interpolate it as-is, without string methods");
|
|
76
76
|
}
|
|
@@ -79,7 +79,7 @@ function split(field, platform, path) {
|
|
|
79
79
|
}
|
|
80
80
|
return segments;
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
// A certificate identity is matched, never fetched: https only, loopback included
|
|
83
83
|
function checkIdentity(field, identity) {
|
|
84
84
|
let parsed;
|
|
85
85
|
try {
|
|
@@ -88,9 +88,8 @@ function checkIdentity(field, identity) {
|
|
|
88
88
|
catch {
|
|
89
89
|
// reported below
|
|
90
90
|
}
|
|
91
|
-
if (parsed?.protocol !== "https:" || parsed.host === "")
|
|
91
|
+
if (parsed?.protocol !== "https:" || parsed.host === "")
|
|
92
92
|
fail(`config.${field} must return an https URL, got ${JSON.stringify(identity)}`);
|
|
93
|
-
}
|
|
94
93
|
}
|
|
95
94
|
function evaluate(field, fn, ctx, check = checkRelative) {
|
|
96
95
|
const out = fn(ctx);
|
|
@@ -115,7 +114,7 @@ function signatureOf(config, signed) {
|
|
|
115
114
|
noSentinel("signature.issuer", issuer);
|
|
116
115
|
if (!checkUrl("signature.issuer", issuer))
|
|
117
116
|
fail(`config.signature.issuer must be an https URL, got ${JSON.stringify(issuer)}`);
|
|
118
|
-
return {
|
|
117
|
+
return { bundlePath, identity, issuer };
|
|
119
118
|
}
|
|
120
119
|
function formatOf(asset) {
|
|
121
120
|
const tail = asset.toLowerCase();
|
|
@@ -135,9 +134,8 @@ function platformsOf(config) {
|
|
|
135
134
|
fail("config.platforms must list at least one platform");
|
|
136
135
|
const seen = new Set();
|
|
137
136
|
for (const p of value) {
|
|
138
|
-
if (!ALL_PLATFORMS.includes(p))
|
|
137
|
+
if (!ALL_PLATFORMS.includes(p))
|
|
139
138
|
fail(`config.platforms has unknown platform ${JSON.stringify(p)}; use one of ${ALL_PLATFORMS.join(", ")}`);
|
|
140
|
-
}
|
|
141
139
|
if (seen.has(p))
|
|
142
140
|
fail(`config.platforms lists ${p} twice`);
|
|
143
141
|
seen.add(p);
|
|
@@ -146,14 +144,14 @@ function platformsOf(config) {
|
|
|
146
144
|
}
|
|
147
145
|
const key = (segments) => segments.map((s) => (s.kind === "literal" ? `L${s.value}` : s.kind)).join("\0");
|
|
148
146
|
const osOf = (platform) => platform.split("/")[0];
|
|
149
|
-
|
|
147
|
+
// GoReleaser universal_binaries: one asset serves both macOS architectures
|
|
150
148
|
const universal = (a, b) => osOf(a) === "darwin" && osOf(b) === "darwin";
|
|
151
149
|
function pathFunctionsOf(config) {
|
|
152
150
|
const assetPath = required(func(config, "assetPath"), "assetPath", "a function");
|
|
153
151
|
const checksumsPath = func(config, "checksumsPath");
|
|
154
152
|
const signature = signatureOf(config, checksumsPath !== undefined);
|
|
155
153
|
const binaryInArchive = func(config, "binaryInArchive");
|
|
156
|
-
return { assetPath, checksumsPath, signature
|
|
154
|
+
return { assetPath, binaryInArchive, checksumsPath, signature };
|
|
157
155
|
}
|
|
158
156
|
function tagPrefixOf(config) {
|
|
159
157
|
const tagPrefix = string(config, "tagPrefix") ?? "v";
|
|
@@ -172,7 +170,7 @@ function installDirOf(config, name) {
|
|
|
172
170
|
return installDir;
|
|
173
171
|
}
|
|
174
172
|
function envPrefixOf(config, name) {
|
|
175
|
-
const derived = name.toUpperCase().
|
|
173
|
+
const derived = name.toUpperCase().replaceAll(/[^A-Z0-9]/g, "_");
|
|
176
174
|
const envPrefix = string(config, "envPrefix") ?? (/^[0-9]/.test(derived) ? `_${derived}` : derived);
|
|
177
175
|
if (!ENV_PREFIX.test(envPrefix))
|
|
178
176
|
fail(`config.envPrefix must match ${ENV_PREFIX.source}, got ${JSON.stringify(envPrefix)}`);
|
|
@@ -186,7 +184,7 @@ function outDirOf(config) {
|
|
|
186
184
|
}
|
|
187
185
|
function scriptUrlsOf(config, baseUrl) {
|
|
188
186
|
if (config.scriptUrls === undefined)
|
|
189
|
-
return {
|
|
187
|
+
return { ps1: `${baseUrl}/install.ps1`, sh: `${baseUrl}/install.sh` };
|
|
190
188
|
if (typeof config.scriptUrls !== "object" || config.scriptUrls === null)
|
|
191
189
|
fail("config.scriptUrls must be an object");
|
|
192
190
|
const urls = config.scriptUrls;
|
|
@@ -194,7 +192,7 @@ function scriptUrlsOf(config, baseUrl) {
|
|
|
194
192
|
const ps1 = required(string(urls, "ps1"), "scriptUrls.ps1", "a string");
|
|
195
193
|
checkUrl("scriptUrls.sh", sh);
|
|
196
194
|
checkUrl("scriptUrls.ps1", ps1);
|
|
197
|
-
return {
|
|
195
|
+
return { ps1, sh };
|
|
198
196
|
}
|
|
199
197
|
/** The settings after the path functions, validated in the order a config's errors are reported. */
|
|
200
198
|
function settingsOf(config, name, baseUrl) {
|
|
@@ -219,10 +217,9 @@ function settingsOf(config, name, baseUrl) {
|
|
|
219
217
|
["outDir", outDir],
|
|
220
218
|
["scriptUrls.sh", scriptUrls.sh],
|
|
221
219
|
["scriptUrls.ps1", scriptUrls.ps1],
|
|
222
|
-
])
|
|
220
|
+
])
|
|
223
221
|
noSentinel(field, value);
|
|
224
|
-
}
|
|
225
|
-
return { latestPath, tagPrefix, installDir, envPrefix, modifyPath, message, outDir, scriptUrls };
|
|
222
|
+
return { envPrefix, installDir, latestPath, message, modifyPath, outDir, scriptUrls, tagPrefix };
|
|
226
223
|
}
|
|
227
224
|
function resolveSignature(signature, ctx, checksumsRaw) {
|
|
228
225
|
const platform = `${ctx.os}/${ctx.arch}`;
|
|
@@ -238,30 +235,28 @@ function resolveSignature(signature, ctx, checksumsRaw) {
|
|
|
238
235
|
}
|
|
239
236
|
function resolvePlatform(platform, fns, assets) {
|
|
240
237
|
const [os, arch] = platform.split("/");
|
|
241
|
-
const ctx = {
|
|
238
|
+
const ctx = { arch, os, tag: tagToken, version: versionToken };
|
|
242
239
|
const assetRaw = evaluate("assetPath", fns.assetPath, ctx);
|
|
243
240
|
const asset = split("assetPath", platform, assetRaw);
|
|
244
|
-
if (asset.every((s) => s.kind === "literal"))
|
|
241
|
+
if (asset.every((s) => s.kind === "literal"))
|
|
245
242
|
fail(`config.assetPath for ${platform} must contain the version or tag token, got ${JSON.stringify(assetRaw)}`);
|
|
246
|
-
}
|
|
247
243
|
const prior = assets.get(key(asset));
|
|
248
|
-
if (prior !== undefined && !universal(prior, platform))
|
|
244
|
+
if (prior !== undefined && !universal(prior, platform))
|
|
249
245
|
fail(`config.assetPath gives ${prior} and ${platform} the same asset ${JSON.stringify(assetRaw)}`);
|
|
250
|
-
}
|
|
251
246
|
assets.set(key(asset), platform);
|
|
252
247
|
const checksumsRaw = fns.checksumsPath && evaluate("checksumsPath", fns.checksumsPath, { ...ctx, asset: assetRaw });
|
|
253
248
|
const signature = fns.signature && checksumsRaw !== undefined
|
|
254
249
|
? resolveSignature(fns.signature, { ...ctx, asset: assetRaw }, checksumsRaw)
|
|
255
250
|
: undefined;
|
|
256
251
|
return {
|
|
257
|
-
platform,
|
|
258
|
-
os,
|
|
259
252
|
arch,
|
|
260
253
|
asset,
|
|
261
|
-
|
|
254
|
+
binaryInArchive: fns.binaryInArchive && split("binaryInArchive", platform, evaluate("binaryInArchive", fns.binaryInArchive, ctx)),
|
|
262
255
|
checksums: checksumsRaw === undefined ? undefined : split("checksumsPath", platform, checksumsRaw),
|
|
256
|
+
format: formatOf(assetRaw),
|
|
257
|
+
os,
|
|
258
|
+
platform,
|
|
263
259
|
signature,
|
|
264
|
-
binaryInArchive: fns.binaryInArchive && split("binaryInArchive", platform, evaluate("binaryInArchive", fns.binaryInArchive, ctx)),
|
|
265
260
|
};
|
|
266
261
|
}
|
|
267
262
|
export function resolveConfig(input) {
|
|
@@ -9,12 +9,12 @@ export type Segment = {
|
|
|
9
9
|
readonly kind: "tag";
|
|
10
10
|
};
|
|
11
11
|
export type Format = "tar.gz" | "zip" | "raw";
|
|
12
|
-
export
|
|
12
|
+
export type ResolvedSignature = {
|
|
13
13
|
readonly bundle: readonly Segment[];
|
|
14
14
|
readonly identity: readonly Segment[];
|
|
15
15
|
readonly issuer: string;
|
|
16
|
-
}
|
|
17
|
-
export
|
|
16
|
+
};
|
|
17
|
+
export type ResolvedPlatform = {
|
|
18
18
|
readonly platform: Platform;
|
|
19
19
|
readonly os: Os;
|
|
20
20
|
readonly arch: Arch;
|
|
@@ -23,8 +23,8 @@ export interface ResolvedPlatform {
|
|
|
23
23
|
readonly checksums: readonly Segment[] | undefined;
|
|
24
24
|
readonly signature: ResolvedSignature | undefined;
|
|
25
25
|
readonly binaryInArchive: readonly Segment[] | undefined;
|
|
26
|
-
}
|
|
27
|
-
export
|
|
26
|
+
};
|
|
27
|
+
export type ResolvedConfig = {
|
|
28
28
|
readonly name: string;
|
|
29
29
|
/** No trailing slash. */
|
|
30
30
|
readonly baseUrl: string;
|
|
@@ -42,4 +42,4 @@ export interface ResolvedConfig {
|
|
|
42
42
|
};
|
|
43
43
|
readonly outDir: string;
|
|
44
44
|
readonly platforms: readonly ResolvedPlatform[];
|
|
45
|
-
}
|
|
45
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* `-Version` parameter).
|
|
5
|
-
*/
|
|
1
|
+
// Literals are single-quoted, where neither shell expands anything; the tokens become the scripts' own variables.
|
|
2
|
+
// sh: `$version` / `$tag`. ps1: `$ver` / `$tag` (PowerShell names are case-insensitive, so `$version` would be the
|
|
3
|
+
// `-Version` parameter).
|
|
6
4
|
/** One sh word: adjacent quoted pieces, so no separator is needed. */
|
|
7
5
|
export function shWord(segments) {
|
|
8
6
|
if (segments.length === 0)
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type { ResolvedConfig } from "../config/types.ts";
|
|
2
2
|
/** How `generateInstallers` renders beyond the config itself. */
|
|
3
|
-
export
|
|
3
|
+
export type RenderOptions = {
|
|
4
4
|
/** Baked in as the version to install when neither the argument nor `<PREFIX>_VERSION` names one. */
|
|
5
5
|
defaultVersion?: string | undefined;
|
|
6
|
-
}
|
|
7
|
-
export
|
|
6
|
+
};
|
|
7
|
+
export type Templates = {
|
|
8
8
|
sh: string;
|
|
9
9
|
ps1: string;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
11
|
/** The scripts a config needs: each is absent when none of its platforms needs that script. */
|
|
12
|
-
export
|
|
12
|
+
export type Rendered = {
|
|
13
13
|
/** `install.sh`, for the linux and darwin platforms; served for `curl -fsSL <url> | sh`. */
|
|
14
14
|
sh?: string;
|
|
15
15
|
/** `install.ps1`, for the windows platforms; served for `irm <url> | iex`. */
|
|
16
16
|
ps1?: string;
|
|
17
|
-
}
|
|
17
|
+
};
|
|
18
18
|
export declare function readTemplates(): Templates;
|
|
19
19
|
/** The value of each `@@KEY@@` in install.sh and install.ps1, already quoted for its shell. */
|
|
20
20
|
export declare function placeholders(resolved: ResolvedConfig, options: RenderOptions): {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { InstallgenError } from "../errors.js";
|
|
3
3
|
import { psLiteral, psString, shLiteral, shWord } from "./quote.js";
|
|
4
|
-
|
|
4
|
+
// The scripts validate the same pattern at install time, after stripping the tag prefix
|
|
5
5
|
const VERSION = /^[A-Za-z0-9._+-]+$/;
|
|
6
|
-
|
|
6
|
+
// in non-unicode mode an astral character is two surrogates, both in this range
|
|
7
7
|
const NON_ASCII = /[\u0080-\uffff]/;
|
|
8
8
|
const PLACEHOLDER = /@@([A-Z0-9_]+)@@/g;
|
|
9
9
|
const readTemplate = (file) => readFileSync(new URL(`../../../assets/installers/templates/${file}`, import.meta.url), "utf8");
|
|
10
10
|
export function readTemplates() {
|
|
11
|
-
return {
|
|
11
|
+
return { ps1: readTemplate("install.ps1"), sh: readTemplate("install.sh") };
|
|
12
12
|
}
|
|
13
13
|
function ascii(field, value) {
|
|
14
14
|
if (value !== undefined && NON_ASCII.test(value)) {
|
|
@@ -65,26 +65,6 @@ export function placeholders(resolved, options) {
|
|
|
65
65
|
const defaultVersion = options.defaultVersion ?? "";
|
|
66
66
|
const message = resolved.message ?? "";
|
|
67
67
|
return {
|
|
68
|
-
sh: {
|
|
69
|
-
NAME: shLiteral(resolved.name),
|
|
70
|
-
ENV_PREFIX: resolved.envPrefix,
|
|
71
|
-
BASE_URL: shLiteral(resolved.baseUrl),
|
|
72
|
-
LATEST_URL: shLiteral(latestUrl),
|
|
73
|
-
DEFAULT_VERSION: shLiteral(defaultVersion),
|
|
74
|
-
TAG_PREFIX: shLiteral(resolved.tagPrefix),
|
|
75
|
-
INSTALL_DIR: `"$HOME"${shLiteral(`/${resolved.installDir}`)}`,
|
|
76
|
-
INSTALL_DIR_DISPLAY: shLiteral(`~/${resolved.installDir}`),
|
|
77
|
-
MODIFY_PATH: resolved.modifyPath ? "1" : "0",
|
|
78
|
-
MESSAGE: shLiteral(message),
|
|
79
|
-
SH_URL: shLiteral(resolved.scriptUrls.sh),
|
|
80
|
-
/* with no Windows build there is no install.ps1 to point Git Bash users at */
|
|
81
|
-
PS1_URL: shLiteral(windows.length > 0 ? resolved.scriptUrls.ps1 : ""),
|
|
82
|
-
CURL_FLAGS: resolved.https ? "--proto '=https' --tlsv1.2" : "",
|
|
83
|
-
WGET_FLAGS: shLiteral(resolved.https ? "--https-only" : ""),
|
|
84
|
-
/* a case pattern list */
|
|
85
|
-
PLATFORMS: unix.map((p) => shLiteral(p.platform)).join(" | "),
|
|
86
|
-
PLATFORM_CASES: unix.map(shCase).join("\n"),
|
|
87
|
-
},
|
|
88
68
|
ps1: {
|
|
89
69
|
NAME: psLiteral(resolved.name),
|
|
90
70
|
ENV_PREFIX: resolved.envPrefix,
|
|
@@ -92,8 +72,8 @@ export function placeholders(resolved, options) {
|
|
|
92
72
|
LATEST_URL: psLiteral(latestUrl),
|
|
93
73
|
DEFAULT_VERSION: psLiteral(defaultVersion),
|
|
94
74
|
TAG_PREFIX: psLiteral(resolved.tagPrefix),
|
|
95
|
-
|
|
96
|
-
|
|
75
|
+
// $env:USERPROFILE is unset on non-Windows pwsh and in some service contexts, and a literal \ is a filename
|
|
76
|
+
// character off Windows: Combine(params string[]) (.NET 4, so 5.1 too) joins with the native separator
|
|
97
77
|
INSTALL_DIR: `[IO.Path]::Combine([string[]](@([Environment]::GetFolderPath('UserProfile')) + @(${resolved.installDir
|
|
98
78
|
.split("/")
|
|
99
79
|
.map(psLiteral)
|
|
@@ -106,10 +86,30 @@ export function placeholders(resolved, options) {
|
|
|
106
86
|
PLATFORMS: `@(${windows.map((p) => psLiteral(p.platform)).join(", ")})`,
|
|
107
87
|
PLATFORM_CASES: windows.map(psCase).join("\n"),
|
|
108
88
|
},
|
|
89
|
+
sh: {
|
|
90
|
+
NAME: shLiteral(resolved.name),
|
|
91
|
+
ENV_PREFIX: resolved.envPrefix,
|
|
92
|
+
BASE_URL: shLiteral(resolved.baseUrl),
|
|
93
|
+
LATEST_URL: shLiteral(latestUrl),
|
|
94
|
+
DEFAULT_VERSION: shLiteral(defaultVersion),
|
|
95
|
+
TAG_PREFIX: shLiteral(resolved.tagPrefix),
|
|
96
|
+
INSTALL_DIR: `"$HOME"${shLiteral(`/${resolved.installDir}`)}`,
|
|
97
|
+
INSTALL_DIR_DISPLAY: shLiteral(`~/${resolved.installDir}`),
|
|
98
|
+
MODIFY_PATH: resolved.modifyPath ? "1" : "0",
|
|
99
|
+
MESSAGE: shLiteral(message),
|
|
100
|
+
SH_URL: shLiteral(resolved.scriptUrls.sh),
|
|
101
|
+
// with no Windows build there is no install.ps1 to point Git Bash users at
|
|
102
|
+
PS1_URL: shLiteral(windows.length > 0 ? resolved.scriptUrls.ps1 : ""),
|
|
103
|
+
CURL_FLAGS: resolved.https ? "--proto '=https' --tlsv1.2" : "",
|
|
104
|
+
WGET_FLAGS: shLiteral(resolved.https ? "--https-only" : ""),
|
|
105
|
+
// a case pattern list
|
|
106
|
+
PLATFORMS: unix.map((p) => shLiteral(p.platform)).join(" | "),
|
|
107
|
+
PLATFORM_CASES: unix.map(shCase).join("\n"),
|
|
108
|
+
},
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
function fill(file, template, values) {
|
|
112
|
-
const out = template.
|
|
112
|
+
const out = template.replaceAll(PLACEHOLDER, (_match, key) => {
|
|
113
113
|
const value = values[key];
|
|
114
114
|
if (value === undefined)
|
|
115
115
|
throw new InstallgenError(`unknown placeholder @@${key}@@ in ${file}`);
|
package/dist/installers/ui.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/** Rows like the installers': a mark, a label, a value. Marks and color on a TTY; plain `+`, `x`, `!` otherwise. */
|
|
2
|
-
export
|
|
2
|
+
export type Ui = {
|
|
3
3
|
ok(label: string, value: string): void;
|
|
4
4
|
bad(label: string, value: string): void;
|
|
5
5
|
info(text: string): void;
|
|
6
6
|
warn(text: string): void;
|
|
7
7
|
error(text: string): void;
|
|
8
|
-
}
|
|
9
|
-
export
|
|
8
|
+
};
|
|
9
|
+
export type UiIo = {
|
|
10
10
|
stdout(text: string): void;
|
|
11
11
|
stderr(text: string): void;
|
|
12
12
|
isTTY: boolean;
|
|
13
13
|
env: Record<string, string | undefined>;
|
|
14
|
-
}
|
|
14
|
+
};
|
|
15
15
|
export declare function createUi(io: UiIo): Ui;
|
package/dist/installers/ui.js
CHANGED
|
@@ -3,12 +3,12 @@ const row = (glyph, label, value) => `${glyph} ${label.padEnd(13)} ${value}\n`;
|
|
|
3
3
|
export function createUi(io) {
|
|
4
4
|
const color = io.isTTY && !io.env.NO_COLOR;
|
|
5
5
|
const paint = (code, text) => (color ? `${ESC}[${code}m${text}${ESC}[0m` : text);
|
|
6
|
-
const mark = {
|
|
6
|
+
const mark = { bad: io.isTTY ? "✗" : "x", ok: io.isTTY ? "✓" : "+" };
|
|
7
7
|
return {
|
|
8
|
-
ok: (label, value) => io.stdout(row(paint(32, mark.ok), label, value)),
|
|
9
8
|
bad: (label, value) => io.stdout(row(paint(31, mark.bad), label, value)),
|
|
9
|
+
error: (text) => io.stderr(`${paint(31, io.isTTY ? `${mark.bad} error:` : "error:")} ${text}\n`),
|
|
10
10
|
info: (text) => io.stdout(`${text}\n`),
|
|
11
|
+
ok: (label, value) => io.stdout(row(paint(32, mark.ok), label, value)),
|
|
11
12
|
warn: (text) => io.stderr(`${paint(33, "warning:")} ${text}\n`),
|
|
12
|
-
error: (text) => io.stderr(`${paint(31, io.isTTY ? `${mark.bad} error:` : "error:")} ${text}\n`),
|
|
13
13
|
};
|
|
14
14
|
}
|
package/dist/ir/build.d.ts
CHANGED
|
@@ -2,16 +2,16 @@ import { type IR, type IRAuth } from "./model.ts";
|
|
|
2
2
|
type Json = Record<string, unknown>;
|
|
3
3
|
/** An OpenAPI document as gen reads it: plain JSON. */
|
|
4
4
|
/** A server: its URL template and the defaults of its variables. */
|
|
5
|
-
|
|
5
|
+
type OpenApiServer = {
|
|
6
6
|
readonly url: string;
|
|
7
7
|
readonly variables?: Readonly<Record<string, {
|
|
8
8
|
readonly default?: string;
|
|
9
9
|
}>>;
|
|
10
10
|
};
|
|
11
11
|
export type OpenApiDocument = {
|
|
12
|
-
readonly components?: Readonly<Record<string, Readonly<Record<string, unknown>>>> & {
|
|
12
|
+
readonly components?: (Readonly<Record<string, Readonly<Record<string, unknown>>>> & {
|
|
13
13
|
readonly schemas?: Readonly<Record<string, Json>>;
|
|
14
|
-
};
|
|
14
|
+
}) | undefined;
|
|
15
15
|
readonly info?: Readonly<Record<string, unknown>>;
|
|
16
16
|
readonly openapi: string;
|
|
17
17
|
readonly paths?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
package/dist/ir/build.js
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* document's info, and the webhooks it sends. Reads the document alone; gen never reaches into core (H2).
|
|
5
5
|
*/
|
|
6
6
|
import { compareCodeUnits, pascalWords } from "../emit/shared/lang.js";
|
|
7
|
-
import {
|
|
7
|
+
import {} from "./model.js";
|
|
8
8
|
import { buildResourceTree } from "./resource-tree.js";
|
|
9
|
+
import { schemaToIR } from "./schema.js";
|
|
9
10
|
import { eventOf, extensionsOf, paramsOf, parseOpenApiPath, requestBodies, responsesOf, } from "./slots.js";
|
|
10
11
|
import { websocketMessagesOf } from "./streams.js";
|
|
11
12
|
const METHODS = ["get", "post", "put", "patch", "delete", "head", "options"];
|
|
@@ -108,10 +109,12 @@ function explicitOperations(doc, options, seen) {
|
|
|
108
109
|
const op = item[method];
|
|
109
110
|
const id = op.operationId;
|
|
110
111
|
const site = { components, item, method, path };
|
|
111
|
-
if (id === undefined)
|
|
112
|
+
if (id === undefined) {
|
|
112
113
|
unnamed.push([op, site]);
|
|
113
|
-
|
|
114
|
+
}
|
|
115
|
+
else if (seen.has(id) && onDuplicate === "throw") {
|
|
114
116
|
throw new Error(`Duplicate operationId: "${id}"`);
|
|
117
|
+
}
|
|
115
118
|
else {
|
|
116
119
|
const final = seen.has(id) ? free(`${id}${pascalWords(method)}`, (c) => seen.has(c)) : id;
|
|
117
120
|
seen.add(final);
|
|
@@ -123,7 +126,7 @@ function explicitOperations(doc, options, seen) {
|
|
|
123
126
|
}
|
|
124
127
|
/** A server URL with each declared `{variable}` replaced by its default; an undeclared one is left as written. */
|
|
125
128
|
function serverUrl({ url, variables = {} }) {
|
|
126
|
-
return url.
|
|
129
|
+
return url.replaceAll(/\{([^{}]*)\}/g, (whole, name) => variables[name]?.default ?? whole);
|
|
127
130
|
}
|
|
128
131
|
/** The IR of `doc`; an explicit id always keeps its name, a derived one takes what is left. */
|
|
129
132
|
export function toIR(doc, options = {}) {
|
|
@@ -136,7 +139,7 @@ export function toIR(doc, options = {}) {
|
|
|
136
139
|
}
|
|
137
140
|
const seen = new Set();
|
|
138
141
|
const { operations, unnamed } = explicitOperations(doc, options, seen);
|
|
139
|
-
|
|
142
|
+
// derived ids after explicit ones, clear of explicit ids and of their namespaces
|
|
140
143
|
const roots = new Set(operations.map(({ id }) => id.split(".")[0]));
|
|
141
144
|
for (const [op, site] of options.deriveOperationIds === true ? unnamed : []) {
|
|
142
145
|
const id = free(deriveOperationId(site.method, site.path), (c) => seen.has(c) || roots.has(c));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IR } from "./model.ts";
|
|
2
|
+
/** One read a write makes stale: its operationId and its own path params, in path order. */
|
|
3
|
+
export type InvalidatedRead = {
|
|
4
|
+
operationId: string;
|
|
5
|
+
params: string[];
|
|
6
|
+
};
|
|
7
|
+
/** Each write's reads, by its operationId, and why any selector resolved to nothing. */
|
|
8
|
+
export type InvalidateReads = {
|
|
9
|
+
reads: Map<string, InvalidatedRead[]>;
|
|
10
|
+
warnings: string[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Each write's reads: every selector of its `x-invalidate` resolved to the reads it names, deduped, in selector
|
|
14
|
+
* order. A write is any operation with `x-invalidate` but a read (a stream or a socket counts: it marks on open). A
|
|
15
|
+
* non-GET selector and one no read matches are skipped with a warning; a write left with no reads is not held.
|
|
16
|
+
*/
|
|
17
|
+
export declare function invalidateReads(ir: IR): InvalidateReads;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which reads each write makes stale, resolved once at generation for every emitter: a write's `x-invalidate`
|
|
3
|
+
* selectors are backend route patterns (`GET /users/:id`, `GET /files/*rest`, `GET /docs/:id?`), and a read is an
|
|
4
|
+
* OpenAPI path (`/users/{id}`), so this is the one place the two spellings meet. A runtime then fills each read's
|
|
5
|
+
* params from the write's own and never parses a selector.
|
|
6
|
+
*/
|
|
7
|
+
import { compareCodeUnits } from "../emit/shared/lang.js";
|
|
8
|
+
import { READ_METHOD } from "./read-method.constants.js";
|
|
9
|
+
import { openApiPathParams } from "./slots.js";
|
|
10
|
+
const PARAM = ":";
|
|
11
|
+
const WILDCARD = "*";
|
|
12
|
+
/** A whole-segment OpenAPI param, `{name}`. */
|
|
13
|
+
const BRACED = /^\{([^{}/]+)\}$/;
|
|
14
|
+
/** A segment of fixed text, as a route key spells it. */
|
|
15
|
+
function literal(text) {
|
|
16
|
+
return `=${text}`;
|
|
17
|
+
}
|
|
18
|
+
/** A read: a GET that answers once, never a stream or a connection. */
|
|
19
|
+
function isRead(op) {
|
|
20
|
+
const { realtime, sse, websocket } = op.extensions;
|
|
21
|
+
return op.method === READ_METHOD && !sse && !websocket && !realtime;
|
|
22
|
+
}
|
|
23
|
+
/** The key of a read's OpenAPI path: a whole `{name}` is a param, a wildcard one the rest of the path. */
|
|
24
|
+
function readKey(op) {
|
|
25
|
+
const wildcards = new Set(op.params.path.filter((p) => p.wildcard === true).map((p) => p.name));
|
|
26
|
+
return op.path
|
|
27
|
+
.split("/")
|
|
28
|
+
.map((text) => {
|
|
29
|
+
const name = BRACED.exec(text)?.[1];
|
|
30
|
+
if (name === undefined)
|
|
31
|
+
return literal(text);
|
|
32
|
+
return wildcards.has(name) ? WILDCARD : PARAM;
|
|
33
|
+
})
|
|
34
|
+
.join("/");
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Every key a selector's route pattern spells (`:name`, `{name}`, a trailing `*name` or `*`, or text): an optional
|
|
38
|
+
* `:name?` segment both left out and kept.
|
|
39
|
+
*/
|
|
40
|
+
function selectorKeys(path) {
|
|
41
|
+
const texts = path.split("/");
|
|
42
|
+
let keys = [[]];
|
|
43
|
+
for (const [i, text] of texts.entries()) {
|
|
44
|
+
const isParam = text.length > 1 && text.startsWith(":");
|
|
45
|
+
let segment = literal(text);
|
|
46
|
+
if (text.startsWith("*") && i === texts.length - 1)
|
|
47
|
+
segment = WILDCARD;
|
|
48
|
+
else if (isParam || BRACED.test(text))
|
|
49
|
+
segment = PARAM;
|
|
50
|
+
const kept = keys.map((key) => [...key, segment]);
|
|
51
|
+
keys = isParam && text.endsWith("?") ? [...keys, ...kept] : kept;
|
|
52
|
+
}
|
|
53
|
+
return keys.map((key) => key.join("/"));
|
|
54
|
+
}
|
|
55
|
+
/** The reads whose key is `at`, by operationId. */
|
|
56
|
+
function readsAt(reads, at) {
|
|
57
|
+
return reads
|
|
58
|
+
.filter(({ key }) => key === at)
|
|
59
|
+
.map(({ op }) => op)
|
|
60
|
+
.toSorted((a, b) => compareCodeUnits(a.id, b.id));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The reads `selector` names, in the order its keys spell them (an optional segment left out first) and by
|
|
64
|
+
* operationId within one key, so a document's path order never reorders them; or why it names none.
|
|
65
|
+
*/
|
|
66
|
+
function resolve(selector, reads) {
|
|
67
|
+
const space = selector.indexOf(" ");
|
|
68
|
+
if (space <= 0)
|
|
69
|
+
return { why: "is not a route selector" };
|
|
70
|
+
const method = selector.slice(0, space).toUpperCase();
|
|
71
|
+
if (method !== READ_METHOD)
|
|
72
|
+
return { why: `names a ${method} route; only ${READ_METHOD} reads are cached` };
|
|
73
|
+
const matched = selectorKeys(selector.slice(space + 1)).flatMap((at) => readsAt(reads, at));
|
|
74
|
+
return matched.length > 0 ? { ops: matched } : { why: `matches no ${READ_METHOD} read` };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Each write's reads: every selector of its `x-invalidate` resolved to the reads it names, deduped, in selector
|
|
78
|
+
* order. A write is any operation with `x-invalidate` but a read (a stream or a socket counts: it marks on open). A
|
|
79
|
+
* non-GET selector and one no read matches are skipped with a warning; a write left with no reads is not held.
|
|
80
|
+
*/
|
|
81
|
+
export function invalidateReads(ir) {
|
|
82
|
+
const readOps = ir.operations.filter(isRead).map((op) => ({ key: readKey(op), op }));
|
|
83
|
+
const reads = new Map();
|
|
84
|
+
const warnings = [];
|
|
85
|
+
for (const op of ir.operations) {
|
|
86
|
+
const selectors = op.extensions.invalidates ?? [];
|
|
87
|
+
if (selectors.length === 0 || isRead(op))
|
|
88
|
+
continue;
|
|
89
|
+
const seen = new Map();
|
|
90
|
+
for (const selector of selectors) {
|
|
91
|
+
const resolved = resolve(selector, readOps);
|
|
92
|
+
if ("why" in resolved) {
|
|
93
|
+
warnings.push(`${op.id}: x-invalidate ${JSON.stringify(selector)} ${resolved.why}; skipped`);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
for (const read of resolved.ops)
|
|
97
|
+
if (!seen.has(read.id))
|
|
98
|
+
seen.set(read.id, { operationId: read.id, params: openApiPathParams(read.path) });
|
|
99
|
+
}
|
|
100
|
+
if (seen.size > 0)
|
|
101
|
+
reads.set(op.id, [...seen.values()]);
|
|
102
|
+
}
|
|
103
|
+
return { reads, warnings };
|
|
104
|
+
}
|
package/dist/ir/load.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
import type * as Vite from "vite";
|
|
1
2
|
/** Bun's resolver, as the loader uses it: `specifier` resolved from `from` under this process's conditions. */
|
|
2
3
|
export type BunResolver = {
|
|
3
4
|
resolveSync(specifier: string, from: string): string;
|
|
4
5
|
};
|
|
6
|
+
type Importer = (specifier: string) => Promise<Record<string, unknown>>;
|
|
5
7
|
/** `<module>[#export]` as its module path and the export it names, if any. */
|
|
6
8
|
export declare function appRef(ref: string): {
|
|
7
9
|
module: string;
|
|
8
10
|
name: string | undefined;
|
|
9
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Node: Vite's SSR runner rooted at the module's directory, one graph shared by the app and its document, so both see
|
|
14
|
+
* one core module (its GRAPH symbol). Each alias matches its specifier exactly, never as a prefix of a longer subpath.
|
|
15
|
+
* The app's Vite config is never applied, and the server holds no handle (no socket, no watcher, no dependency scan),
|
|
16
|
+
* so it is left for the process to end. `vite` is the import, a parameter so its absence can be tested.
|
|
17
|
+
*/
|
|
18
|
+
export declare function viteImporter(path: string, aliases: Record<string, string>, vite?: () => Promise<typeof Vite>): Promise<Importer>;
|
|
10
19
|
/** The OpenAPI document of the app `ref` names, by the app's own core; `cwd` resolves it. One load at a time per process. */
|
|
11
20
|
export declare function loadAppDocument(ref: string, cwd: string): Promise<Record<string, unknown>>;
|
|
21
|
+
export {};
|