@workerstack/clients 1.0.0-rc.28 → 1.0.0-rc.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +403 -21
- package/assets/installers/examples/github.config.ts +17 -19
- package/assets/installers/examples/goreleaser.config.ts +16 -18
- package/assets/installers/examples/raw.config.ts +13 -15
- package/bin/clients.js +87 -66
- package/bin/installgen.js +19 -10
- package/dist/cli.d.ts +4 -4
- package/dist/cli.js +18 -12
- package/dist/emit/cli/channels.d.ts +2 -2
- package/dist/emit/cli/channels.js +18 -13
- package/dist/emit/cli/commands.d.ts +1 -1
- package/dist/emit/cli/commands.js +39 -13
- package/dist/emit/cli/discovery.d.ts +0 -6
- package/dist/emit/cli/discovery.js +9 -7
- package/dist/emit/cli/flags.d.ts +1 -3
- package/dist/emit/cli/flags.js +18 -8
- package/dist/emit/cli/install.d.ts +0 -8
- package/dist/emit/cli/install.js +3 -3
- package/dist/emit/cli/layout.d.ts +1 -1
- package/dist/emit/cli/layout.js +13 -10
- package/dist/emit/cli/module.d.ts +6 -6
- package/dist/emit/cli/module.js +10 -10
- package/dist/emit/cli/release.d.ts +0 -11
- package/dist/emit/cli/release.js +4 -4
- package/dist/emit/cli/skills.js +8 -4
- package/dist/emit/csharp/errors.js +4 -4
- package/dist/emit/csharp/json.js +8 -8
- package/dist/emit/csharp/realtime.d.ts +1 -8
- package/dist/emit/csharp/realtime.js +26 -26
- package/dist/emit/csharp/sdk-answer.d.ts +10 -2
- package/dist/emit/csharp/sdk-answer.js +4 -4
- package/dist/emit/csharp/sdk-body.js +8 -6
- package/dist/emit/csharp/sdk-client.d.ts +3 -3
- package/dist/emit/csharp/sdk-client.js +2 -2
- package/dist/emit/csharp/sdk-csproj.d.ts +7 -9
- package/dist/emit/csharp/sdk-csproj.js +10 -10
- package/dist/emit/csharp/sdk-doc.js +1 -1
- package/dist/emit/csharp/sdk-method.d.ts +0 -1
- package/dist/emit/csharp/sdk-method.js +19 -8
- package/dist/emit/csharp/sdk-plan.js +0 -1
- package/dist/emit/csharp/sdk.js +3 -3
- package/dist/emit/csharp/sse.d.ts +0 -13
- package/dist/emit/csharp/sse.js +92 -11
- package/dist/emit/csharp/transport.js +9 -9
- package/dist/emit/csharp/types-enum.js +3 -1
- package/dist/emit/csharp/types-messages.d.ts +47 -0
- package/dist/emit/csharp/types-messages.js +172 -0
- package/dist/emit/csharp/types-names.js +13 -14
- package/dist/emit/csharp/types-record.js +3 -3
- package/dist/emit/csharp/types-union.d.ts +1 -1
- package/dist/emit/csharp/types.d.ts +0 -1
- package/dist/emit/csharp/types.js +3 -3
- package/dist/emit/csharp/ws.d.ts +0 -15
- package/dist/emit/csharp/ws.js +26 -5
- package/dist/emit/go/errors.js +1 -1
- package/dist/emit/go/http.js +2 -2
- package/dist/emit/go/module-path.js +2 -2
- package/dist/emit/go/sdk-answer.d.ts +24 -1
- package/dist/emit/go/sdk-answer.js +1 -1
- package/dist/emit/go/sdk-body.js +11 -7
- package/dist/emit/go/sdk-client.js +1 -1
- package/dist/emit/go/sdk-method.d.ts +3 -0
- package/dist/emit/go/sdk-method.js +18 -12
- package/dist/emit/go/sdk-mirror.js +2 -2
- package/dist/emit/go/sdk-opts.d.ts +0 -2
- package/dist/emit/go/sdk-opts.js +3 -3
- package/dist/emit/go/sdk.d.ts +1 -1
- package/dist/emit/go/sdk.js +9 -9
- package/dist/emit/go/sse.d.ts +2 -10
- package/dist/emit/go/sse.js +88 -13
- package/dist/emit/go/types-names.js +5 -0
- package/dist/emit/go/types-struct.d.ts +2 -1
- package/dist/emit/go/types-struct.js +1 -1
- package/dist/emit/go/types-union.d.ts +3 -2
- package/dist/emit/go/types-union.js +2 -0
- package/dist/emit/go/types.d.ts +6 -0
- package/dist/emit/go/types.js +20 -9
- package/dist/emit/go/ws.d.ts +4 -11
- package/dist/emit/go/ws.js +215 -59
- package/dist/emit/java/gradle.d.ts +7 -9
- package/dist/emit/java/gradle.js +8 -8
- package/dist/emit/java/json.d.ts +3 -0
- package/dist/emit/java/json.js +1 -1
- package/dist/emit/java/layout-ast.d.ts +4 -1
- package/dist/emit/java/layout-ast.js +1 -1
- package/dist/emit/java/layout-decl.js +5 -4
- package/dist/emit/java/layout-doc.js +13 -7
- package/dist/emit/java/layout-dot.js +1 -1
- package/dist/emit/java/layout-strings.js +4 -5
- package/dist/emit/java/layout-types.js +7 -5
- package/dist/emit/java/layout-visitor.js +4 -3
- package/dist/emit/java/layout.js +5 -4
- package/dist/emit/java/models-names.d.ts +2 -0
- package/dist/emit/java/models-names.js +6 -4
- package/dist/emit/java/models-record.d.ts +0 -1
- package/dist/emit/java/models-record.js +3 -3
- package/dist/emit/java/models-union.d.ts +13 -2
- package/dist/emit/java/models-union.js +12 -6
- package/dist/emit/java/models.d.ts +5 -1
- package/dist/emit/java/models.js +44 -20
- package/dist/emit/java/realtime.d.ts +34 -26
- package/dist/emit/java/realtime.js +45 -10
- package/dist/emit/java/sdk-client.d.ts +6 -6
- package/dist/emit/java/sdk-client.js +1 -1
- package/dist/emit/java/sdk-decl.js +2 -2
- package/dist/emit/java/sdk-errors.js +1 -1
- package/dist/emit/java/sdk-headers.js +2 -2
- package/dist/emit/java/sdk-mirror.js +7 -6
- package/dist/emit/java/sdk-models.d.ts +1 -1
- package/dist/emit/java/sdk-models.js +7 -7
- package/dist/emit/java/sdk-op.d.ts +1 -10
- package/dist/emit/java/sdk-op.js +9 -9
- package/dist/emit/java/sdk-params.d.ts +5 -5
- package/dist/emit/java/sdk-params.js +3 -2
- package/dist/emit/java/sdk-plan.js +0 -1
- package/dist/emit/java/sdk.d.ts +1 -1
- package/dist/emit/java/sdk.js +14 -13
- package/dist/emit/java/sse.d.ts +12 -13
- package/dist/emit/java/sse.js +105 -6
- package/dist/emit/java/ws.d.ts +48 -9
- package/dist/emit/java/ws.js +88 -4
- package/dist/emit/mcp/annotations.js +8 -4
- package/dist/emit/mcp/files.js +9 -9
- package/dist/emit/mcp/mounted.js +2 -2
- package/dist/emit/mcp/output-schema.d.ts +4 -2
- package/dist/emit/mcp/output-schema.js +58 -14
- package/dist/emit/mcp/registry.d.ts +0 -2
- package/dist/emit/mcp/registry.js +5 -4
- package/dist/emit/mcp/runtime.js +2 -2
- package/dist/emit/mcp/schema.js +22 -11
- package/dist/emit/mcp/server.d.ts +7 -7
- package/dist/emit/mcp/server.js +7 -6
- package/dist/emit/mcp/tools.js +7 -6
- package/dist/emit/python/errors.js +3 -3
- package/dist/emit/python/realtime.d.ts +9 -6
- package/dist/emit/python/realtime.js +22 -20
- package/dist/emit/python/sdk-answer.d.ts +8 -8
- package/dist/emit/python/sdk-answer.js +2 -2
- package/dist/emit/python/sdk-body.js +4 -5
- package/dist/emit/python/sdk-client.js +5 -5
- package/dist/emit/python/sdk-doc.js +2 -2
- package/dist/emit/python/sdk-method.d.ts +1 -1
- package/dist/emit/python/sdk-method.js +38 -11
- package/dist/emit/python/sdk-plan.js +0 -1
- package/dist/emit/python/sdk-pyproject.d.ts +0 -2
- package/dist/emit/python/sdk-pyproject.js +8 -8
- package/dist/emit/python/sdk.d.ts +1 -1
- package/dist/emit/python/sdk.js +28 -8
- package/dist/emit/python/sse.d.ts +0 -7
- package/dist/emit/python/sse.js +36 -6
- package/dist/emit/python/transport.js +4 -4
- package/dist/emit/python/types-dict.d.ts +2 -2
- package/dist/emit/python/types-dict.js +1 -1
- package/dist/emit/python/types-names.js +2 -2
- package/dist/emit/python/types-union.js +1 -1
- package/dist/emit/python/types.d.ts +7 -0
- package/dist/emit/python/types.js +23 -6
- package/dist/emit/python/ws.d.ts +21 -10
- package/dist/emit/python/ws.js +69 -3
- package/dist/emit/rust/errors.js +3 -3
- package/dist/emit/rust/http.js +4 -4
- package/dist/emit/rust/realtime.d.ts +7 -5
- package/dist/emit/rust/realtime.js +15 -18
- package/dist/emit/rust/sdk-body.js +8 -5
- package/dist/emit/rust/sdk-cargo.d.ts +16 -18
- package/dist/emit/rust/sdk-cargo.js +12 -12
- package/dist/emit/rust/sdk-client.d.ts +1 -1
- package/dist/emit/rust/sdk-client.js +3 -3
- package/dist/emit/rust/sdk-method.js +3 -3
- package/dist/emit/rust/sdk-opts.d.ts +2 -1
- package/dist/emit/rust/sdk-opts.js +2 -2
- package/dist/emit/rust/sdk-plan.js +0 -1
- package/dist/emit/rust/sdk.d.ts +1 -1
- package/dist/emit/rust/sdk.js +5 -5
- package/dist/emit/rust/sse.d.ts +11 -12
- package/dist/emit/rust/sse.js +54 -8
- package/dist/emit/rust/types-names.js +3 -3
- package/dist/emit/rust/types-struct.js +1 -1
- package/dist/emit/rust/types-union.d.ts +10 -2
- package/dist/emit/rust/types-union.js +4 -0
- package/dist/emit/rust/types.d.ts +9 -0
- package/dist/emit/rust/types.js +20 -12
- package/dist/emit/rust/ws.d.ts +22 -15
- package/dist/emit/rust/ws.js +60 -10
- package/dist/emit/shared/escape.js +17 -17
- package/dist/emit/shared/format.js +1 -1
- package/dist/emit/shared/gofmt.js +1 -1
- package/dist/emit/shared/lang.js +10 -10
- package/dist/emit/shared/literals.d.ts +5 -0
- package/dist/emit/shared/literals.js +8 -0
- package/dist/emit/shared/metadata.d.ts +0 -6
- package/dist/emit/shared/metadata.js +8 -7
- package/dist/emit/shared/ruff.js +1 -1
- package/dist/emit/shared/rustfmt.js +1 -1
- package/dist/emit/shared/type-emitter.js +37 -20
- package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
- package/dist/emit/shared/unknown-type.constants.js +2 -0
- package/dist/emit/ts/http.d.ts +0 -2
- package/dist/emit/ts/http.js +4 -4
- package/dist/emit/ts/package.d.ts +14 -12
- package/dist/emit/ts/package.js +9 -8
- package/dist/emit/ts/route-tree.js +2 -2
- package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
- package/dist/emit/ts/sdk-types-preamble.js +6 -2
- package/dist/emit/ts/sdk-types.js +59 -20
- package/dist/emit/ts/sdk.js +6 -6
- package/dist/emit/ts/service-map.d.ts +10 -3
- package/dist/emit/ts/service-map.js +30 -2
- package/dist/emit/ts/tanstack-query.js +6 -6
- package/dist/emit/ts/type-gen.js +36 -21
- package/dist/emit/ts/webhooks.d.ts +0 -2
- package/dist/emit/ts/webhooks.js +3 -3
- package/dist/extract/chain.js +5 -4
- package/dist/extract/extract.js +5 -5
- package/dist/extract/serialize.d.ts +0 -2
- package/dist/extract/serialize.js +14 -15
- package/dist/extract/walk.js +15 -12
- package/dist/gen/args.js +9 -5
- package/dist/gen/formatters.js +5 -3
- package/dist/gen/shipped.js +2 -2
- package/dist/gen/targets.d.ts +2 -4
- package/dist/gen/targets.js +8 -4
- package/dist/gen/write.js +4 -2
- package/dist/index.js +2 -2
- package/dist/installers/cli.d.ts +4 -4
- package/dist/installers/cli.js +24 -24
- package/dist/installers/commands/build.d.ts +4 -4
- package/dist/installers/commands/build.js +2 -3
- package/dist/installers/commands/check.d.ts +2 -2
- package/dist/installers/commands/check.js +11 -10
- package/dist/installers/commands/init.d.ts +2 -2
- package/dist/installers/commands/init.js +1 -2
- package/dist/installers/config/define-config.d.ts +16 -16
- package/dist/installers/config/define-config.js +1 -1
- package/dist/installers/config/hooks/bun.d.ts +6 -6
- package/dist/installers/config/hooks/node.js +1 -1
- package/dist/installers/config/load.d.ts +6 -8
- package/dist/installers/config/load.js +7 -8
- package/dist/installers/config/resolve.d.ts +1 -2
- package/dist/installers/config/resolve.js +28 -33
- package/dist/installers/config/types.d.ts +6 -6
- package/dist/installers/config/types.js +0 -1
- package/dist/installers/render/quote.js +3 -5
- package/dist/installers/render/render.d.ts +6 -6
- package/dist/installers/render/render.js +26 -26
- package/dist/installers/ui.d.ts +4 -4
- package/dist/installers/ui.js +3 -3
- package/dist/ir/build.d.ts +3 -3
- package/dist/ir/build.js +12 -5
- package/dist/ir/load.js +9 -10
- package/dist/ir/model.d.ts +16 -1
- package/dist/ir/model.js +0 -1
- package/dist/ir/resolve-refs.js +2 -2
- package/dist/ir/resource-tree.js +2 -1
- package/dist/ir/route-tree-intern.js +1 -1
- package/dist/ir/schema.js +3 -3
- package/dist/ir/sdk-model.d.ts +25 -1
- package/dist/ir/sdk-model.js +38 -8
- package/dist/ir/slots.d.ts +1 -1
- package/dist/ir/slots.js +22 -11
- package/dist/ir/streams.d.ts +16 -0
- package/dist/ir/streams.js +40 -0
- package/dist/release/bootstrap.d.ts +3 -3
- package/dist/release/bootstrap.js +7 -7
- package/dist/release/bump-args.js +4 -4
- package/dist/release/bump-command.d.ts +1 -1
- package/dist/release/bump-command.js +9 -10
- package/dist/release/bump.d.ts +5 -4
- package/dist/release/bump.js +2 -2
- package/dist/release/cli.d.ts +4 -4
- package/dist/release/cli.js +4 -4
- package/dist/release/codegen.js +1 -1
- package/dist/release/digest.js +5 -7
- package/dist/release/git.js +5 -8
- package/dist/release/load.js +3 -3
- package/dist/release/manifest.js +9 -10
- package/dist/release/oasdiff.d.ts +10 -15
- package/dist/release/oasdiff.js +5 -6
- package/dist/release/registries.d.ts +0 -11
- package/dist/release/registries.js +17 -17
- package/dist/release/release-state.d.ts +16 -13
- package/dist/release/release-workflow.js +5 -7
- package/dist/release/repo-settings.d.ts +2 -1
- package/dist/release/spec-gate.d.ts +0 -2
- package/dist/release/spec-gate.js +6 -10
- package/dist/release/sync-command.d.ts +2 -2
- package/dist/release/sync-command.js +1 -1
- package/dist/release/sync-tree.js +9 -13
- package/dist/release/sync.d.ts +6 -6
- package/dist/release/sync.js +12 -13
- package/dist/release/types.d.ts +22 -22
- package/dist/release/types.js +0 -1
- package/dist/release/version-files.d.ts +3 -4
- package/dist/release/version-files.js +4 -5
- package/dist/runtime/.oxfmtrc.jsonc +8 -0
- package/dist/runtime/cli/socket.go +107 -13
- package/dist/runtime/cli/stream.go +18 -11
- package/dist/runtime/csharp/Adapters.cs +12 -11
- package/dist/runtime/csharp/Events.cs +22 -17
- package/dist/runtime/csharp/Realtime.cs +50 -23
- package/dist/runtime/csharp/RealtimeLoop.cs +1 -1
- package/dist/runtime/csharp/TransportSse.cs +3 -3
- package/dist/runtime/csharp/Ws.cs +1 -1
- package/dist/runtime/csharp/WsDial.cs +19 -1
- package/dist/runtime/csharp/WsTyped.cs +109 -0
- package/dist/runtime/go/realtime.go +125 -41
- package/dist/runtime/go/realtime_loop.go +21 -18
- package/dist/runtime/go/result.go +2 -1
- package/dist/runtime/go/sse.go +11 -0
- package/dist/runtime/go/stream.go +29 -13
- package/dist/runtime/go/transport.go +15 -21
- package/dist/runtime/go/transport_longpoll.go +3 -4
- package/dist/runtime/go/transport_sse.go +6 -6
- package/dist/runtime/go/ws.go +157 -61
- package/dist/runtime/java/EventStream.java +47 -29
- package/dist/runtime/java/Exchange.java +5 -5
- package/dist/runtime/java/Flight.java +3 -3
- package/dist/runtime/java/Realtime.java +45 -11
- package/dist/runtime/java/ResumableConnection.java +77 -32
- package/dist/runtime/java/Socket.java +8 -4
- package/dist/runtime/java/SseAdapter.java +1 -1
- package/dist/runtime/java/TypedWebSocket.java +81 -24
- package/dist/runtime/java/WsAdapter.java +4 -2
- package/dist/runtime/java/WsDial.java +12 -5
- package/dist/runtime/mcp/files.ts +1 -1
- package/dist/runtime/mcp/http.ts +6 -2
- package/dist/runtime/mcp/listen.ts +1 -1
- package/dist/runtime/mcp/mount.ts +2 -2
- package/dist/runtime/mcp/protocol.ts +1 -1
- package/dist/runtime/python/events.py +25 -11
- package/dist/runtime/python/operation.py +6 -1
- package/dist/runtime/python/realtime.py +47 -33
- package/dist/runtime/python/send_async.py +1 -0
- package/dist/runtime/python/transport_sse.py +2 -2
- package/dist/runtime/python/transport_ws.py +1 -1
- package/dist/runtime/python/ws.py +100 -39
- package/dist/runtime/rust/events.rs +64 -41
- package/dist/runtime/rust/realtime.rs +80 -34
- package/dist/runtime/rust/realtime_loop.rs +37 -12
- package/dist/runtime/rust/sse.rs +3 -2
- package/dist/runtime/rust/transport_sse.rs +1 -1
- package/dist/runtime/rust/transport_ws.rs +3 -2
- package/dist/runtime/rust/ws.rs +122 -50
- package/dist/runtime/ts/realtime-connection.ts +22 -0
- package/dist/runtime/ts/realtime-transports.ts +13 -4
- package/dist/runtime/ts/realtime.ts +27 -3
- package/dist/runtime/ts/sdk-realtime.ts +1 -1
- package/dist/runtime/ts/sdk-sse.ts +31 -14
- package/dist/runtime/ts/sdk-ws.ts +2 -1
- package/dist/runtime/ts/sdk.ts +9 -2
- package/dist/runtime/ts/sse.ts +8 -0
- package/dist/runtime/ts/ws.ts +88 -50
- package/dist/runtime/ts-tanstack-query/query.ts +0 -2
- package/package.json +12 -40
- package/dist/emit/cli/index.d.ts +0 -1
- package/dist/emit/cli/index.js +0 -1
- package/dist/emit/csharp/index.d.ts +0 -1
- package/dist/emit/csharp/index.js +0 -1
- package/dist/emit/go/index.d.ts +0 -1
- package/dist/emit/go/index.js +0 -1
- package/dist/emit/java/index.d.ts +0 -2
- package/dist/emit/java/index.js +0 -2
- package/dist/emit/mcp/index.d.ts +0 -3
- package/dist/emit/mcp/index.js +0 -3
- package/dist/emit/python/index.d.ts +0 -1
- package/dist/emit/python/index.js +0 -1
- package/dist/emit/rust/index.d.ts +0 -1
- package/dist/emit/rust/index.js +0 -1
package/dist/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,9 +4,11 @@
|
|
|
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";
|
|
11
|
+
import { websocketMessagesOf } from "./streams.js";
|
|
10
12
|
const METHODS = ["get", "post", "put", "patch", "delete", "head", "options"];
|
|
11
13
|
/** A stable id for an operation without one: `GET /users/{id}` → `getUsersById`, `GET /` → `getRoot`. */
|
|
12
14
|
export function deriveOperationId(method, path) {
|
|
@@ -42,6 +44,9 @@ function operationOf(id, op, { components, item, method, path }) {
|
|
|
42
44
|
operation.description = op.description;
|
|
43
45
|
if (typeof op.summary === "string")
|
|
44
46
|
operation.summary = op.summary;
|
|
47
|
+
const messages = websocketMessagesOf(op["x-websocket"]);
|
|
48
|
+
if (messages !== undefined)
|
|
49
|
+
operation.messages = messages;
|
|
45
50
|
return operation;
|
|
46
51
|
}
|
|
47
52
|
/**
|
|
@@ -104,10 +109,12 @@ function explicitOperations(doc, options, seen) {
|
|
|
104
109
|
const op = item[method];
|
|
105
110
|
const id = op.operationId;
|
|
106
111
|
const site = { components, item, method, path };
|
|
107
|
-
if (id === undefined)
|
|
112
|
+
if (id === undefined) {
|
|
108
113
|
unnamed.push([op, site]);
|
|
109
|
-
|
|
114
|
+
}
|
|
115
|
+
else if (seen.has(id) && onDuplicate === "throw") {
|
|
110
116
|
throw new Error(`Duplicate operationId: "${id}"`);
|
|
117
|
+
}
|
|
111
118
|
else {
|
|
112
119
|
const final = seen.has(id) ? free(`${id}${pascalWords(method)}`, (c) => seen.has(c)) : id;
|
|
113
120
|
seen.add(final);
|
|
@@ -119,7 +126,7 @@ function explicitOperations(doc, options, seen) {
|
|
|
119
126
|
}
|
|
120
127
|
/** A server URL with each declared `{variable}` replaced by its default; an undeclared one is left as written. */
|
|
121
128
|
function serverUrl({ url, variables = {} }) {
|
|
122
|
-
return url.
|
|
129
|
+
return url.replaceAll(/\{([^{}]*)\}/g, (whole, name) => variables[name]?.default ?? whole);
|
|
123
130
|
}
|
|
124
131
|
/** The IR of `doc`; an explicit id always keeps its name, a derived one takes what is left. */
|
|
125
132
|
export function toIR(doc, options = {}) {
|
|
@@ -132,7 +139,7 @@ export function toIR(doc, options = {}) {
|
|
|
132
139
|
}
|
|
133
140
|
const seen = new Set();
|
|
134
141
|
const { operations, unnamed } = explicitOperations(doc, options, seen);
|
|
135
|
-
|
|
142
|
+
// derived ids after explicit ones, clear of explicit ids and of their namespaces
|
|
136
143
|
const roots = new Set(operations.map(({ id }) => id.split(".")[0]));
|
|
137
144
|
for (const [op, site] of options.deriveOperationIds === true ? unnamed : []) {
|
|
138
145
|
const id = free(deriveOperationId(site.method, site.path), (c) => seen.has(c) || roots.has(c));
|
package/dist/ir/load.js
CHANGED
|
@@ -63,18 +63,16 @@ function appOf(mod, ref, name) {
|
|
|
63
63
|
const which = name === undefined ? "no `app` or `default` export" : `no export ${JSON.stringify(name)}`;
|
|
64
64
|
throw new Error(`--app ${ref}: ${which} that is a backend app (name one as <module>#<export>)`);
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
// Node: jiti, its one module cache shared by the app and its document, so both see one core module (its GRAPH symbol)
|
|
67
67
|
async function jitiImporter(path, alias) {
|
|
68
68
|
const { createJiti } = await import("jiti");
|
|
69
69
|
const jiti = createJiti(path, { alias, fsCache: false, interopDefault: true });
|
|
70
70
|
return (specifier) => jiti.import(specifier);
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* each must resolve to its source, never to an unbuilt or stale dist/.
|
|
77
|
-
*/
|
|
72
|
+
// Bun: its own import, never jiti, which there retries a module that threw through its Babel (evaluating it twice),
|
|
73
|
+
// whose Error.prepareStackTrace hook then breaks Bun's captureStackTrace on a non-Error (Vite's follow-redirects), and
|
|
74
|
+
// whose native mode ignores the aliases (bit 20). A checkout's aliases hold by the backend-source condition instead:
|
|
75
|
+
// each must resolve to its source, never to an unbuilt or stale dist/.
|
|
78
76
|
function bunImporter(bun, path, aliases, ref) {
|
|
79
77
|
const from = dirname(path);
|
|
80
78
|
for (const [specifier, source] of Object.entries(aliases)) {
|
|
@@ -83,10 +81,11 @@ function bunImporter(bun, path, aliases, ref) {
|
|
|
83
81
|
resolved = bun.resolveSync(specifier, from);
|
|
84
82
|
}
|
|
85
83
|
catch {
|
|
86
|
-
|
|
84
|
+
// unresolvable without the condition (a checkout has no dist/): refused below, as one resolved elsewhere
|
|
87
85
|
}
|
|
88
|
-
if (resolved !== realpathSync(source))
|
|
86
|
+
if (resolved !== realpathSync(source)) {
|
|
89
87
|
throw new Error(`--app ${ref}: ${specifier} is a checkout, read from its source only under the backend-source condition: start Bun with --conditions=backend-source`);
|
|
88
|
+
}
|
|
90
89
|
}
|
|
91
90
|
return (specifier) => import(__rewriteRelativeImportExtension(pathToFileURL(bun.resolveSync(specifier, from)).href));
|
|
92
91
|
}
|
|
@@ -101,7 +100,7 @@ export async function loadAppDocument(ref, cwd) {
|
|
|
101
100
|
throw new Error(`--app ${ref}: no ${CORE} is installed where ${relative(cwd, path)} resolves it`);
|
|
102
101
|
const bun = globalThis.Bun;
|
|
103
102
|
const aliases = sourceAliases(root);
|
|
104
|
-
|
|
103
|
+
// Bun resolves core's own imports under the backend-source condition, through core's package.json
|
|
105
104
|
const load = bun === undefined
|
|
106
105
|
? await jitiImporter(path, { ...aliases.exports, ...aliases.imports })
|
|
107
106
|
: bunImporter(bun, path, aliases.exports, ref);
|
package/dist/ir/model.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export type IRScalarType = "boolean" | "integer" | "null" | "number" | "string";
|
|
6
6
|
/** A value's constraint keywords as the spec states them (bit 19 c): a string's, a number's, an array's. */
|
|
7
|
-
|
|
7
|
+
type IRBounds = {
|
|
8
8
|
minLength?: number;
|
|
9
9
|
maxLength?: number;
|
|
10
10
|
pattern?: string;
|
|
@@ -102,6 +102,16 @@ export type IRBody = {
|
|
|
102
102
|
/** the whole form, for emitters that type it as one value */
|
|
103
103
|
schema: IRSchema;
|
|
104
104
|
};
|
|
105
|
+
/** One named event an SSE response streams (an OpenAPI 3.2 `itemSchema` member): `message` when it names none. */
|
|
106
|
+
export type IRSseEvent = {
|
|
107
|
+
name: string;
|
|
108
|
+
data: IRSchema;
|
|
109
|
+
};
|
|
110
|
+
/** A WebSocket's message schemas from the rich `x-websocket`, named from the server's side: what it receives and sends. */
|
|
111
|
+
export type IRWebSocketMessages = {
|
|
112
|
+
receive?: IRSchema;
|
|
113
|
+
send?: IRSchema;
|
|
114
|
+
};
|
|
105
115
|
export type IRResponse = {
|
|
106
116
|
/** the status key as written: `200`, `4XX`, `default` */
|
|
107
117
|
status: string;
|
|
@@ -121,6 +131,8 @@ export type IRResponse = {
|
|
|
121
131
|
}[];
|
|
122
132
|
/** a response a declared error produces (`x-backend-error`), never a declared output */
|
|
123
133
|
error?: true;
|
|
134
|
+
/** the named events an SSE response's `itemSchema` declares, in order */
|
|
135
|
+
events?: IRSseEvent[];
|
|
124
136
|
};
|
|
125
137
|
export type IROperationExtensions = {
|
|
126
138
|
/** the id the route declared, when the document renamed its operationId (`x-backend-declared-id`) */
|
|
@@ -161,6 +173,8 @@ export type IROperation = {
|
|
|
161
173
|
bodies?: IRBody[];
|
|
162
174
|
responses: Record<string, IRResponse>;
|
|
163
175
|
extensions: IROperationExtensions;
|
|
176
|
+
/** the rich `x-websocket` object's messages, on a websocket or realtime operation */
|
|
177
|
+
messages?: IRWebSocketMessages;
|
|
164
178
|
};
|
|
165
179
|
export type IRTreeEntry = {
|
|
166
180
|
kind: "method";
|
|
@@ -206,3 +220,4 @@ export type IR = {
|
|
|
206
220
|
/** every webhook, by name in code-unit order */
|
|
207
221
|
webhooks: IRWebhook[];
|
|
208
222
|
};
|
|
223
|
+
export {};
|
package/dist/ir/model.js
CHANGED
package/dist/ir/resolve-refs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const PREFIX = "#/components/schemas/";
|
|
2
|
-
|
|
2
|
+
// past this many schema nodes, inlining fails loudly instead of eating the machine
|
|
3
3
|
const MAX_NODES = 200_000;
|
|
4
4
|
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5
5
|
/** `schema` with its component ref, if it is one, replaced by a copy of the component, inlined. */
|
|
@@ -60,7 +60,7 @@ export function resolveRefs(doc) {
|
|
|
60
60
|
inlineContent(response, run);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
// schemas were there, so components are
|
|
64
64
|
const { schemas: _inlined, ...rest } = components;
|
|
65
65
|
return { ...doc, components: Object.keys(rest).length > 0 ? rest : undefined, paths };
|
|
66
66
|
}
|
package/dist/ir/resource-tree.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* values JSON cannot carry first, so equal JSON always means equal values.
|
|
5
5
|
*/
|
|
6
6
|
import { tsString } from "../emit/shared/escape.js";
|
|
7
|
-
|
|
7
|
+
// shorter strings and numbers cost less inline than a name
|
|
8
8
|
const STRING_MIN = 8;
|
|
9
9
|
const NUMBER_MIN = 8;
|
|
10
10
|
/** How deeply `value` nests: 0 for a primitive. */
|
package/dist/ir/schema.js
CHANGED
|
@@ -12,7 +12,7 @@ function isNullable(schema) {
|
|
|
12
12
|
/** The schema `schema` makes nullable; never wrapped twice. */
|
|
13
13
|
function nullableOf(schema) {
|
|
14
14
|
let inner;
|
|
15
|
-
|
|
15
|
+
// only a type list that holds null is stripped; a flag beside any other list drops the flag below
|
|
16
16
|
if (Array.isArray(schema.type) && schema.type.includes("null")) {
|
|
17
17
|
const rest = schema.type.filter((type) => type !== "null");
|
|
18
18
|
inner = schemaToIR({ ...schema, type: rest.length === 1 ? rest[0] : rest });
|
|
@@ -119,7 +119,7 @@ function constOf(schema) {
|
|
|
119
119
|
const typed = SCALARS.includes(schema.type) && schema.type !== "null";
|
|
120
120
|
return typed ? { kind: "const", type: schema.type, value } : { kind: "const", value };
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
// the constraint keywords a value carries (bit 19 c), each read when the spec states it with its JSON type
|
|
123
123
|
const BOUNDS = ["minLength", "maxLength", "minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum"];
|
|
124
124
|
function scalarOf(schema) {
|
|
125
125
|
if (!SCALARS.includes(schema.type))
|
|
@@ -147,7 +147,7 @@ function arrayOf(schema) {
|
|
|
147
147
|
array.maxItems = schema.maxItems;
|
|
148
148
|
return array;
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
// the order matters: a ref before anything it might also say, const before type, nullability before unions
|
|
151
151
|
const READERS = [
|
|
152
152
|
(schema) => (typeof schema.$ref === "string" ? { kind: "ref", name: lastSegment(schema.$ref) } : null),
|
|
153
153
|
(schema) => (Array.isArray(schema.allOf) ? { kind: "allOf", parts: schema.allOf.map(schemaToIR) } : null),
|
package/dist/ir/sdk-model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type IR, type IRMultipartPart, type IROperation, type IRParam, type IRSchema } from "./model.ts";
|
|
1
|
+
import { type IR, type IRDiscriminator, type IRMultipartPart, type IROperation, type IRParam, type IRSchema, type IRSseEvent } from "./model.ts";
|
|
2
2
|
import { type IRPathSegment } from "./slots.ts";
|
|
3
3
|
export type SdkBody = {
|
|
4
4
|
kind: "json";
|
|
@@ -70,6 +70,30 @@ export type SdkModel = {
|
|
|
70
70
|
export declare function mediaEssence(contentType: string): string;
|
|
71
71
|
export declare function isJsonMedia(contentType: string): boolean;
|
|
72
72
|
export declare function isTextMedia(contentType: string): boolean;
|
|
73
|
+
/** The named events an SSE op's `itemSchema` declares (D7), in order; none for a stream of one `schema`. */
|
|
74
|
+
export declare function sseEvents(op: IROperation): readonly IRSseEvent[] | undefined;
|
|
75
|
+
/** Whether an event's `data` of `schema` is JSON on the wire: anything but text, which core sends as is. */
|
|
76
|
+
export declare const isJsonEventData: (schema: IRSchema, resolve: (schema: IRSchema) => IRSchema) => boolean;
|
|
77
|
+
/** A message union keyed on one field (D9): the union, the field, and each variant beside its string const there. */
|
|
78
|
+
export type Dispatch = {
|
|
79
|
+
readonly union: Extract<IRSchema, {
|
|
80
|
+
kind: "union";
|
|
81
|
+
}> & {
|
|
82
|
+
readonly discriminator: IRDiscriminator;
|
|
83
|
+
};
|
|
84
|
+
readonly key: string;
|
|
85
|
+
readonly members: readonly {
|
|
86
|
+
readonly variant: IRSchema;
|
|
87
|
+
readonly value: string;
|
|
88
|
+
}[];
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* How a message union dispatches (D9): on its discriminator's `propertyName` when every variant is an object whose
|
|
92
|
+
* field there is a string const; none for any other schema.
|
|
93
|
+
*/
|
|
94
|
+
export declare function dispatchOf(schema: IRSchema, resolve: (schema: IRSchema) => IRSchema): Dispatch | undefined;
|
|
95
|
+
/** The field a message union dispatches on (D9); none for a schema that does not dispatch. */
|
|
96
|
+
export declare const dispatchKey: (schema: IRSchema, resolve: (schema: IRSchema) => IRSchema) => string | undefined;
|
|
73
97
|
/**
|
|
74
98
|
* The schema an SSE op declares for its events' `data`, when it is not a string: such events are
|
|
75
99
|
* JSON (core JSON-encodes an object `data`) and the client parses them.
|
package/dist/ir/sdk-model.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* realtime calls alike, instead of in each emitter.
|
|
5
5
|
*/
|
|
6
6
|
import { compareCodeUnits } from "../emit/shared/lang.js";
|
|
7
|
+
import {} from "./model.js";
|
|
7
8
|
import { irResolver } from "./schema.js";
|
|
8
9
|
import { parseOpenApiPath } from "./slots.js";
|
|
9
10
|
/** A media type's essence: `Application/JSON; charset=utf-8` → `application/json`. */
|
|
@@ -34,9 +35,8 @@ function successOf(op) {
|
|
|
34
35
|
const status = codes.find((code) => op.responses[code]?.contentType !== undefined) ?? codes[0];
|
|
35
36
|
if (status === undefined) {
|
|
36
37
|
const fallback = op.responses["2XX"] ?? op.responses.default;
|
|
37
|
-
if (fallback?.contentType === undefined || !isJsonMedia(fallback.contentType))
|
|
38
|
+
if (fallback?.contentType === undefined || !isJsonMedia(fallback.contentType))
|
|
38
39
|
return { kind: Object.keys(op.responses).length === 0 ? "json" : "none", status: "200" };
|
|
39
|
-
}
|
|
40
40
|
const out = { contentType: fallback.contentType, kind: "json", status: fallback.status };
|
|
41
41
|
if (fallback.schema !== undefined)
|
|
42
42
|
out.schema = fallback.schema;
|
|
@@ -81,19 +81,49 @@ function streamOf(op) {
|
|
|
81
81
|
return "ws";
|
|
82
82
|
return sse === true ? "sse" : null;
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
// a string-typed schema: a scalar string, or a string const or enum
|
|
85
85
|
const isStringSchema = (schema) => (schema.kind === "scalar" && schema.type === "string") ||
|
|
86
86
|
(schema.kind === "const" && typeof schema.value === "string");
|
|
87
|
+
/** The SSE response of `op`: its `text/event-stream` answer, if any. */
|
|
88
|
+
const sseResponse = (op) => Object.values(op.responses).find(({ contentType }) => contentType !== undefined && mediaEssence(contentType) === "text/event-stream");
|
|
89
|
+
/** The named events an SSE op's `itemSchema` declares (D7), in order; none for a stream of one `schema`. */
|
|
90
|
+
export function sseEvents(op) {
|
|
91
|
+
const events = sseResponse(op)?.events;
|
|
92
|
+
return events === undefined || events.length === 0 ? undefined : events;
|
|
93
|
+
}
|
|
94
|
+
/** Whether an event's `data` of `schema` is JSON on the wire: anything but text, which core sends as is. */
|
|
95
|
+
export const isJsonEventData = (schema, resolve) => {
|
|
96
|
+
const resolved = resolve(schema);
|
|
97
|
+
return resolved.kind !== "unknown" && !isStringSchema(resolved);
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* How a message union dispatches (D9): on its discriminator's `propertyName` when every variant is an object whose
|
|
101
|
+
* field there is a string const; none for any other schema.
|
|
102
|
+
*/
|
|
103
|
+
export function dispatchOf(schema, resolve) {
|
|
104
|
+
const union = resolve(schema);
|
|
105
|
+
if (union.kind !== "union" || union.discriminator === undefined)
|
|
106
|
+
return undefined;
|
|
107
|
+
const { discriminator } = union;
|
|
108
|
+
const key = discriminator.propertyName;
|
|
109
|
+
const members = union.variants.map((variant) => {
|
|
110
|
+
const object = resolve(variant);
|
|
111
|
+
const field = object.kind === "object" ? object.fields.find(({ name }) => name === key) : undefined;
|
|
112
|
+
const value = field === undefined ? undefined : resolve(field.schema);
|
|
113
|
+
return { value: value?.kind === "const" && typeof value.value === "string" ? value.value : undefined, variant };
|
|
114
|
+
});
|
|
115
|
+
const keyed = members.every((member) => member.value !== undefined);
|
|
116
|
+
return keyed ? { key, members, union: { ...union, discriminator } } : undefined;
|
|
117
|
+
}
|
|
118
|
+
/** The field a message union dispatches on (D9); none for a schema that does not dispatch. */
|
|
119
|
+
export const dispatchKey = (schema, resolve) => dispatchOf(schema, resolve)?.key;
|
|
87
120
|
/**
|
|
88
121
|
* The schema an SSE op declares for its events' `data`, when it is not a string: such events are
|
|
89
122
|
* JSON (core JSON-encodes an object `data`) and the client parses them.
|
|
90
123
|
*/
|
|
91
124
|
export function sseEventSchema(op, resolve) {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
return undefined;
|
|
95
|
-
const resolved = resolve(response.schema);
|
|
96
|
-
return resolved.kind === "unknown" || isStringSchema(resolved) ? undefined : response.schema;
|
|
125
|
+
const schema = sseResponse(op)?.schema;
|
|
126
|
+
return schema !== undefined && isJsonEventData(schema, resolve) ? schema : undefined;
|
|
97
127
|
}
|
|
98
128
|
function opOf(op, resolve) {
|
|
99
129
|
const errorStatuses = Object.keys(op.responses)
|
package/dist/ir/slots.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare function responsesOf(op: Json, components: Components): {
|
|
|
31
31
|
responses: Record<string, IRResponse>;
|
|
32
32
|
sse: boolean;
|
|
33
33
|
};
|
|
34
|
-
/** The backend extensions: each only when it is literally `true
|
|
34
|
+
/** The backend extensions: each only when it is literally `true` (`x-websocket` also as its rich object); invalidation targets as strings. */
|
|
35
35
|
export declare function extensionsOf(op: Json, sse: boolean): IROperationExtensions;
|
|
36
36
|
/**
|
|
37
37
|
* The Standard Webhooks event the webhook `name` declares through `x-backend-webhook`, from its JSON
|
package/dist/ir/slots.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { schemaToIR } from "./schema.js";
|
|
2
1
|
import { compareCodeUnits } from "../emit/shared/lang.js";
|
|
2
|
+
/**
|
|
3
|
+
* One operation's slots in the IR: its parameters by where they travel, its request bodies in
|
|
4
|
+
* preference order, its responses by status, and the backend extensions it carries (realtime, SSE,
|
|
5
|
+
* websocket, invalidation…), and for a Standard Webhooks event, its type and data. Component `$ref`s on
|
|
6
|
+
* parameters, bodies, responses and an event's envelope are followed.
|
|
7
|
+
*/
|
|
8
|
+
import {} from "./model.js";
|
|
9
|
+
import { schemaToIR } from "./schema.js";
|
|
10
|
+
import { sseEventsOf, websocketMessagesOf } from "./streams.js";
|
|
3
11
|
/** Splits an OpenAPI path template into literal text and `{param}` pieces. */
|
|
4
12
|
export function parseOpenApiPath(path) {
|
|
5
13
|
const out = [];
|
|
@@ -66,13 +74,12 @@ export function paramsOf(path, op, item, components) {
|
|
|
66
74
|
const declared = (op.parameters ?? [])
|
|
67
75
|
.map((p) => deref(p, components))
|
|
68
76
|
.filter((p) => p !== undefined);
|
|
69
|
-
for (const p of (item.parameters ?? []).map((q) => deref(q, components)))
|
|
77
|
+
for (const p of (item.parameters ?? []).map((q) => deref(q, components)))
|
|
70
78
|
if (p !== undefined && !declared.some((d) => d.name === p.name && d.in === p.in))
|
|
71
79
|
declared.push(p);
|
|
72
|
-
}
|
|
73
80
|
const by = (place) => declared.filter((p) => p.in === place).map(paramOf);
|
|
74
81
|
const pathParams = by("path");
|
|
75
|
-
|
|
82
|
+
// path params in template order; one the template lacks cannot be sent, one it has but nobody declared is a string
|
|
76
83
|
const params = {
|
|
77
84
|
header: by("header"),
|
|
78
85
|
path: openApiPathParams(path).map((name) => pathParams.find((p) => p.name === name) ?? { name, required: true, schema: STRING }),
|
|
@@ -83,7 +90,7 @@ export function paramsOf(path, op, item, components) {
|
|
|
83
90
|
params.cookie = cookie;
|
|
84
91
|
return params;
|
|
85
92
|
}
|
|
86
|
-
|
|
93
|
+
// JSON first, then the structured kinds; other JSON-like types next, then the rest as listed
|
|
87
94
|
const PREFERENCE = [
|
|
88
95
|
"application/json",
|
|
89
96
|
"application/x-www-form-urlencoded",
|
|
@@ -124,12 +131,11 @@ function bodyOf(type, media, required, components) {
|
|
|
124
131
|
return { contentType: "application/octet-stream", kind: "stream", required };
|
|
125
132
|
const ir = schemaToIR(schema);
|
|
126
133
|
const parts = essence === "multipart/form-data" ? partsOf(ir, components) : [];
|
|
127
|
-
if (parts.some((part) => part.type === "file"))
|
|
134
|
+
if (parts.some((part) => part.type === "file"))
|
|
128
135
|
return { contentType: "multipart/form-data", kind: "multipart", parts, required, schema: ir };
|
|
129
|
-
}
|
|
130
136
|
return { contentType: type, kind: "raw", required, schema: ir };
|
|
131
137
|
}
|
|
132
|
-
|
|
138
|
+
// a urlencoded form cannot carry a file, so a multipart one with a file part ranks just above it
|
|
133
139
|
const weight = (body) => body.kind === "multipart" ? rank("application/x-www-form-urlencoded") - 0.5 : rank(body.contentType);
|
|
134
140
|
/** Every request body the operation declares, preferred first. */
|
|
135
141
|
export function requestBodies(op, components) {
|
|
@@ -159,8 +165,13 @@ export function responsesOf(op, components) {
|
|
|
159
165
|
const type = ordered(content)[0];
|
|
160
166
|
const out = { status };
|
|
161
167
|
if (type !== undefined) {
|
|
162
|
-
|
|
168
|
+
const stream = Object.keys(content).find((key) => essenceOf(key) === "text/event-stream");
|
|
169
|
+
if (stream !== undefined) {
|
|
163
170
|
sse = true;
|
|
171
|
+
const events = sseEventsOf(content[stream]?.itemSchema, (value) => deref(value, components));
|
|
172
|
+
if (events !== undefined)
|
|
173
|
+
out.events = events;
|
|
174
|
+
}
|
|
164
175
|
out.contentType = type;
|
|
165
176
|
const schema = content[type]?.schema;
|
|
166
177
|
if (schema !== undefined)
|
|
@@ -179,10 +190,10 @@ export function responsesOf(op, components) {
|
|
|
179
190
|
}
|
|
180
191
|
return { responses, sse };
|
|
181
192
|
}
|
|
182
|
-
/** The backend extensions: each only when it is literally `true
|
|
193
|
+
/** The backend extensions: each only when it is literally `true` (`x-websocket` also as its rich object); invalidation targets as strings. */
|
|
183
194
|
export function extensionsOf(op, sse) {
|
|
184
195
|
const out = {};
|
|
185
|
-
if (op["x-websocket"] === true)
|
|
196
|
+
if (op["x-websocket"] === true || websocketMessagesOf(op["x-websocket"]) !== undefined)
|
|
186
197
|
out.websocket = true;
|
|
187
198
|
if (op["x-realtime"] === true)
|
|
188
199
|
out.realtime = true;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The typed stream shapes an operation declares: an OpenAPI 3.2 SSE `itemSchema`'s named events, and the
|
|
3
|
+
* rich `x-websocket` object's `receive` and `send` messages (realtime operations carry the same object).
|
|
4
|
+
* Both read any document, so a malformed shape is left out, never refused.
|
|
5
|
+
*/
|
|
6
|
+
import type { IRSseEvent, IRWebSocketMessages } from "./model.ts";
|
|
7
|
+
type Json = Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* The events an SSE `itemSchema` declares, in order: one event object, or a `oneOf`/`anyOf` of them, each
|
|
10
|
+
* followed through `follow`. A member is named by its `event` const, `message` when it has none; its data
|
|
11
|
+
* is its `data`'s `contentSchema` when it has one, else the `data` schema. None for a non-object itemSchema.
|
|
12
|
+
*/
|
|
13
|
+
export declare function sseEventsOf(itemSchema: unknown, follow: (value: unknown) => Json | undefined): IRSseEvent[] | undefined;
|
|
14
|
+
/** The rich `x-websocket` object's message schemas, each direction only when it is an object; none for any other value. */
|
|
15
|
+
export declare function websocketMessagesOf(raw: unknown): IRWebSocketMessages | undefined;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { schemaToIR } from "./schema.js";
|
|
2
|
+
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3
|
+
/**
|
|
4
|
+
* The events an SSE `itemSchema` declares, in order: one event object, or a `oneOf`/`anyOf` of them, each
|
|
5
|
+
* followed through `follow`. A member is named by its `event` const, `message` when it has none; its data
|
|
6
|
+
* is its `data`'s `contentSchema` when it has one, else the `data` schema. None for a non-object itemSchema.
|
|
7
|
+
*/
|
|
8
|
+
export function sseEventsOf(itemSchema, follow) {
|
|
9
|
+
const root = follow(itemSchema);
|
|
10
|
+
if (!isObject(root))
|
|
11
|
+
return undefined;
|
|
12
|
+
const union = root.oneOf ?? root.anyOf;
|
|
13
|
+
const members = Array.isArray(union) ? union.map(follow) : [root];
|
|
14
|
+
return members.flatMap((member) => {
|
|
15
|
+
if (!isObject(member))
|
|
16
|
+
return [];
|
|
17
|
+
const properties = isObject(member.properties) ? member.properties : {};
|
|
18
|
+
const event = isObject(properties.event) ? properties.event.const : undefined;
|
|
19
|
+
if (event !== undefined && typeof event !== "string")
|
|
20
|
+
return [];
|
|
21
|
+
return [{ data: dataOf(properties.data), name: event ?? "message" }];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
// an event's data: what `contentSchema` encodes when it is there, else the schema itself
|
|
25
|
+
function dataOf(data) {
|
|
26
|
+
if (!isObject(data))
|
|
27
|
+
return { kind: "unknown" };
|
|
28
|
+
return schemaToIR(isObject(data.contentSchema) ? data.contentSchema : data);
|
|
29
|
+
}
|
|
30
|
+
/** The rich `x-websocket` object's message schemas, each direction only when it is an object; none for any other value. */
|
|
31
|
+
export function websocketMessagesOf(raw) {
|
|
32
|
+
if (!isObject(raw))
|
|
33
|
+
return undefined;
|
|
34
|
+
const out = {};
|
|
35
|
+
if (isObject(raw.receive))
|
|
36
|
+
out.receive = schemaToIR(raw.receive);
|
|
37
|
+
if (isObject(raw.send))
|
|
38
|
+
out.send = schemaToIR(raw.send);
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
@@ -2,7 +2,7 @@ import { type ReleaseContext } from "./context.ts";
|
|
|
2
2
|
/** The most commits a public repo's branch may hold for `--force-bootstrap` to overwrite it: a stub, not history. */
|
|
3
3
|
export declare const FORCE_COMMIT_LIMIT = 2;
|
|
4
4
|
/** What `release bootstrap` prints when it is not told what to target. */
|
|
5
|
-
export declare const USAGE: string[];
|
|
5
|
+
export declare const USAGE: readonly string[];
|
|
6
6
|
/**
|
|
7
7
|
* Returns commit count on the remote branch, capped at FORCE_COMMIT_LIMIT + 1.
|
|
8
8
|
* Used to gate --force-bootstrap: only mirrors with ≤FORCE_COMMIT_LIMIT commits
|
|
@@ -10,7 +10,7 @@ export declare const USAGE: string[];
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function countRemoteCommits(httpsUrl: string, branch: string): Promise<number>;
|
|
12
12
|
/** What `release bootstrap` was asked for. */
|
|
13
|
-
export
|
|
13
|
+
export type BootstrapOptions = {
|
|
14
14
|
/** Every package of the release. */
|
|
15
15
|
all: boolean;
|
|
16
16
|
/** The release config's path; required. */
|
|
@@ -19,7 +19,7 @@ export interface BootstrapOptions {
|
|
|
19
19
|
forceBootstrap: boolean;
|
|
20
20
|
/** The packages to bootstrap, by `name` or `project/name`. */
|
|
21
21
|
only: string[] | undefined;
|
|
22
|
-
}
|
|
22
|
+
};
|
|
23
23
|
/** A parse that succeeded with `options`, or failed with an `error` to show the caller. */
|
|
24
24
|
export type ParsedArgs = {
|
|
25
25
|
error: string;
|
|
@@ -44,7 +44,7 @@ export async function countRemoteCommits(httpsUrl, branch) {
|
|
|
44
44
|
rmSync(tmpDir, { force: true, recursive: true });
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
// Unknown arguments are ignored.
|
|
48
48
|
const SWITCHES = { "--all": "all", "--force-bootstrap": "forceBootstrap" };
|
|
49
49
|
const VALUE_FLAGS = { "--config": "config", "--name": "only", "--only": "only" };
|
|
50
50
|
const isSwitch = (arg) => Object.hasOwn(SWITCHES, arg);
|
|
@@ -106,7 +106,7 @@ export function judgeMirror(input) {
|
|
|
106
106
|
}
|
|
107
107
|
return { proceed: true };
|
|
108
108
|
}
|
|
109
|
-
|
|
109
|
+
// one package bootstrapped: its outcome, reported as it goes
|
|
110
110
|
async function bootstrapOne(entry, run, ctx) {
|
|
111
111
|
ctx.out(`\n→ ${packageKey(entry)} → ${entry.mirror}\n`);
|
|
112
112
|
const httpsUrl = sshToHttps(entry.mirror, run.token);
|
|
@@ -121,9 +121,9 @@ async function bootstrapOne(entry, run, ctx) {
|
|
|
121
121
|
ctx.err(` fail: ${verdict.reason}\n`);
|
|
122
122
|
return "failed";
|
|
123
123
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
// Bootstrap commits force-overwrite the mirror with a fresh "initial release" snapshot. bootstrapExclude globs
|
|
125
|
+
// skip generated source on the initial push, so the next sync adds it cleanly. A repo bootstrap creates is exactly
|
|
126
|
+
// one whose description, website and topics are empty, so the settings step fills them.
|
|
127
127
|
const result = await syncPackage(entry, {
|
|
128
128
|
applyBootstrapExclude: true,
|
|
129
129
|
dryRun: false,
|
|
@@ -142,12 +142,12 @@ async function bootstrapOne(entry, run, ctx) {
|
|
|
142
142
|
ctx.out(` skip: ${result.reason}\n`);
|
|
143
143
|
return "skipped";
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
// a push that is no dry run always reports both shas
|
|
146
146
|
const [source, mirror] = [result.sourceSha, result.mirrorSha];
|
|
147
147
|
ctx.out(` ok: source=${source.slice(0, SHORT_SHA_LENGTH)} mirror=${mirror.slice(0, SHORT_SHA_LENGTH)}\n`);
|
|
148
148
|
return "synced";
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
// the packages a bootstrap targets, bootstrapped one after another; the exit code it ends with
|
|
151
151
|
async function bootstrapAll(release, options, token, ctx) {
|
|
152
152
|
const targets = filterPackages(release.packages, { only: options.only });
|
|
153
153
|
if (targets.length === 0) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
// Each flag takes the next argument as its value, unless that argument is a switch.
|
|
2
2
|
const BUMP_FLAGS = { "--config": "config" };
|
|
3
|
-
|
|
3
|
+
// Bare flags: present or not.
|
|
4
4
|
const BUMP_SWITCHES = { "--major": "major" };
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// The value of every `flags` entry and the presence of every `switches` entry in `argv`, or the first argument that
|
|
6
|
+
// is neither.
|
|
7
7
|
function readFlags(flags, switches, argv) {
|
|
8
8
|
const values = {};
|
|
9
9
|
const set = {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReleaseContext } from "./context.ts";
|
|
2
|
-
import type { Release } from "./types.ts";
|
|
3
2
|
import { type ReleaseState } from "./release-state.ts";
|
|
3
|
+
import type { Release } from "./types.ts";
|
|
4
4
|
/** The header every CHANGELOG bump writes starts with; entries go directly under it, newest first. */
|
|
5
5
|
export declare const CHANGELOG_HEADER = "# Changelog\n\n";
|
|
6
6
|
/**
|