@workerstack/clients 1.0.0-rc.29 → 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 +373 -14
- 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 +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 +0 -1
- package/dist/emit/csharp/sdk-method.js +10 -6
- 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 -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.js +2 -2
- 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.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 +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 +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 +1 -10
- package/dist/emit/java/sdk-op.js +8 -8
- 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 +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.js +5 -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 +7 -7
- 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.js +2 -2
- 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 +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 +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 +2 -2
- package/dist/emit/ts/sdk-types.js +11 -11
- package/dist/emit/ts/sdk.js +4 -4
- package/dist/emit/ts/service-map.d.ts +2 -1
- package/dist/emit/ts/tanstack-query.js +6 -6
- 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/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 +8 -5
- package/dist/ir/load.js +9 -10
- package/dist/ir/model.d.ts +2 -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.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 +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/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/ts-tanstack-query/query.ts +0 -2
- package/package.json +10 -7
- package/dist/emit/cli/index.d.ts +0 -1
- package/dist/emit/cli/index.js +0 -1
- package/dist/emit/csharp/index.d.ts +0 -1
- package/dist/emit/csharp/index.js +0 -1
- package/dist/emit/go/index.d.ts +0 -1
- package/dist/emit/go/index.js +0 -1
- package/dist/emit/java/index.d.ts +0 -2
- package/dist/emit/java/index.js +0 -2
- package/dist/emit/mcp/index.d.ts +0 -3
- package/dist/emit/mcp/index.js +0 -3
- package/dist/emit/python/index.d.ts +0 -1
- package/dist/emit/python/index.js +0 -1
- package/dist/emit/rust/index.d.ts +0 -1
- package/dist/emit/rust/index.js +0 -1
package/dist/emit/java/models.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { pascalWords, javaTypeName } from "../shared/lang.js";
|
|
2
2
|
import { enumDecl, enumValues } from "./models-enum.js";
|
|
3
|
-
import { fieldsOf, isOpen, recordDecl } from "./models-record.js";
|
|
4
3
|
import { javaNames, JSON_NODE } from "./models-names.js";
|
|
4
|
+
import { fieldsOf, isOpen, recordDecl } from "./models-record.js";
|
|
5
5
|
import { dispatchOf, isKeyed, isLiteral, unionDecl } from "./models-union.js";
|
|
6
|
-
|
|
6
|
+
// deeper than this, a schema is any JSON value
|
|
7
7
|
const MAX_DEPTH = 12;
|
|
8
8
|
const SCALARS = {
|
|
9
9
|
boolean: "Boolean",
|
|
@@ -32,7 +32,7 @@ export function declares(ir) {
|
|
|
32
32
|
function declare(ir, at, key, base) {
|
|
33
33
|
const name = at.names.hoist(key, base);
|
|
34
34
|
if (!at.decls.has(name)) {
|
|
35
|
-
|
|
35
|
+
// claimed before its body: what the body hoists in turn comes after it
|
|
36
36
|
at.decls.set(name, "");
|
|
37
37
|
at.decls.set(name, javaTopLevel(name, ir, at));
|
|
38
38
|
}
|
|
@@ -75,28 +75,38 @@ function use(ir, at) {
|
|
|
75
75
|
if (at.depth > MAX_DEPTH)
|
|
76
76
|
return JSON_NODE;
|
|
77
77
|
switch (ir.kind) {
|
|
78
|
-
case "allOf":
|
|
78
|
+
case "allOf": {
|
|
79
79
|
return allOfUse(ir, at);
|
|
80
|
-
|
|
80
|
+
}
|
|
81
|
+
case "array": {
|
|
81
82
|
return `List<${use(ir.items, deeper(at, `${at.fieldName}Item`, "[]"))}>`;
|
|
82
|
-
|
|
83
|
+
}
|
|
84
|
+
case "binary": {
|
|
83
85
|
return "String";
|
|
84
|
-
|
|
86
|
+
}
|
|
87
|
+
case "const": {
|
|
85
88
|
return constType(ir);
|
|
86
|
-
|
|
89
|
+
}
|
|
90
|
+
case "nullable": {
|
|
87
91
|
return use(ir.inner, deeper(at));
|
|
88
|
-
|
|
92
|
+
}
|
|
93
|
+
case "object": {
|
|
89
94
|
return objectUse(ir, at);
|
|
90
|
-
|
|
95
|
+
}
|
|
96
|
+
case "ref": {
|
|
91
97
|
return refUse(ir, at);
|
|
92
|
-
|
|
98
|
+
}
|
|
99
|
+
case "scalar": {
|
|
93
100
|
return enumValues(ir).length > 0 ? hoist(ir, at) : SCALARS[ir.type];
|
|
94
|
-
|
|
101
|
+
}
|
|
102
|
+
case "tuple": {
|
|
95
103
|
return `List<${JSON_NODE}>`;
|
|
96
|
-
|
|
104
|
+
}
|
|
105
|
+
// a union in use position is any JSON value; a component union is declared
|
|
97
106
|
case "union":
|
|
98
|
-
case "unknown":
|
|
107
|
+
case "unknown": {
|
|
99
108
|
return JSON_NODE;
|
|
109
|
+
}
|
|
100
110
|
}
|
|
101
111
|
}
|
|
102
112
|
/** The Java type of `ir` at a use position of `at`. */
|
|
@@ -126,8 +136,7 @@ export function javaTopLevel(name, ir, ctx) {
|
|
|
126
136
|
const open = isOpen(ir, ctx.names.resolve);
|
|
127
137
|
if (ir.kind === "object")
|
|
128
138
|
return recordDecl(name, { fields: ir.fields, open }, scope.member, ctx);
|
|
129
|
-
if (ir.kind === "allOf")
|
|
139
|
+
if (ir.kind === "allOf")
|
|
130
140
|
return recordDecl(name, { fields: fieldsOf(ir, ctx.names.resolve), open }, scope.member, ctx);
|
|
131
|
-
}
|
|
132
141
|
return unionDecl(name, ir, scope);
|
|
133
142
|
}
|
|
@@ -19,22 +19,10 @@ import { type JavaTypeContext } from "./models.ts";
|
|
|
19
19
|
export declare const MAX_RECONNECT_ATTEMPTS = "maxReconnectAttempts";
|
|
20
20
|
export declare const RECONNECT_DELAY = "reconnectDelay";
|
|
21
21
|
/** A realtime op's own fields in `TransportOptions.of`'s order, each with its Java type. */
|
|
22
|
-
export declare const REALTIME_FIELDS: readonly
|
|
23
|
-
readonly field:
|
|
24
|
-
readonly type:
|
|
25
|
-
}
|
|
26
|
-
readonly field: "reconnectToken";
|
|
27
|
-
readonly type: "String";
|
|
28
|
-
}, {
|
|
29
|
-
readonly field: "protocols";
|
|
30
|
-
readonly type: "List<String>";
|
|
31
|
-
}, {
|
|
32
|
-
readonly field: "maxReconnectAttempts";
|
|
33
|
-
readonly type: "java.lang.Integer";
|
|
34
|
-
}, {
|
|
35
|
-
readonly field: "reconnectDelay";
|
|
36
|
-
readonly type: "Duration";
|
|
37
|
-
}];
|
|
22
|
+
export declare const REALTIME_FIELDS: readonly {
|
|
23
|
+
readonly field: string;
|
|
24
|
+
readonly type: string;
|
|
25
|
+
}[];
|
|
38
26
|
/** Whether a declared param is on a realtime resume channel the cursor fields carry (C#'s `carries`). */
|
|
39
27
|
export declare const carriesRealtime: (name: string, where: "query" | "header") => boolean;
|
|
40
28
|
/**
|
|
@@ -42,7 +30,7 @@ export declare const carriesRealtime: (name: string, where: "query" | "header")
|
|
|
42
30
|
* adapters; only an SDK with a realtime operation ships them (with the WebSocket files, which its WebSocket adapter dials
|
|
43
31
|
* through).
|
|
44
32
|
*/
|
|
45
|
-
export declare const REALTIME_FILES: string[];
|
|
33
|
+
export declare const REALTIME_FILES: readonly string[];
|
|
46
34
|
/**
|
|
47
35
|
* What a realtime method answers: its type, the type its messages decode to, whether they must be JSON (the op
|
|
48
36
|
* declares its messages), and the wrap of the opened connection.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { call as callOf, local, methodHeader, newOf, param, returnStmt, statement, } from "./layout.js";
|
|
2
|
-
import { declaredTypeOf, javaTypeOf, keyedArms } from "./models.js";
|
|
3
2
|
import { JSON_NODE } from "./models-names.js";
|
|
3
|
+
import { declaredTypeOf, javaTypeOf, keyedArms } from "./models.js";
|
|
4
4
|
import { docOf } from "./sdk-decl.js";
|
|
5
5
|
import { CURSOR, isLastEventIdHeader } from "./sse.js";
|
|
6
6
|
import { handledArms, isReconnectTokenQuery, keyedReader, PROTOCOLS, TOKEN } from "./ws.js";
|
|
@@ -44,13 +44,13 @@ export declare function nodeOf(ns: IRNamespace, path: readonly string[]): Node;
|
|
|
44
44
|
* mirror's `safe` is held, so a member spelled `safe` is `safe_` instead, and noticed (shared/mirror.ts's one rule).
|
|
45
45
|
*/
|
|
46
46
|
export declare function membersOf(node: Node, env: SurfaceEnv): {
|
|
47
|
-
children: {
|
|
48
|
-
child: Node;
|
|
49
|
-
name: string;
|
|
47
|
+
readonly children: {
|
|
48
|
+
readonly child: Node;
|
|
49
|
+
readonly name: string;
|
|
50
50
|
}[];
|
|
51
|
-
ops: {
|
|
52
|
-
name: string;
|
|
53
|
-
op: JavaOp;
|
|
51
|
+
readonly ops: {
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly op: JavaOp;
|
|
54
54
|
}[];
|
|
55
55
|
};
|
|
56
56
|
/** A list of blocks, each set apart by one blank line; a block's own trailing blank lines are dropped. */
|
|
@@ -60,7 +60,7 @@ export const blocks = (parts) => parts
|
|
|
60
60
|
.flatMap((part, i) => (i === 0 ? part : ["", ...part]));
|
|
61
61
|
/** The lines without their leading and trailing blank lines. */
|
|
62
62
|
function trimmed(lines) {
|
|
63
|
-
const text = lines.join("\n").
|
|
63
|
+
const text = lines.join("\n").replaceAll(/^(?:\n)+|(?:\n)+$/g, "");
|
|
64
64
|
return text === "" ? [] : text.split("\n");
|
|
65
65
|
}
|
|
66
66
|
/** The operations' constants and methods of a class, each block set apart. */
|
|
@@ -15,8 +15,8 @@ const control = (cp) => cp < 0x20 || cp === 0x7f || cp === 0xfeff || cp === 0x20
|
|
|
15
15
|
const docText = (text) => [...text.toWellFormed()]
|
|
16
16
|
.map((ch) => (control(ch.codePointAt(0)) ? " " : ch))
|
|
17
17
|
.join("")
|
|
18
|
-
.
|
|
19
|
-
.
|
|
18
|
+
.replaceAll("\\", "\")
|
|
19
|
+
.replaceAll("*/", "*/");
|
|
20
20
|
/**
|
|
21
21
|
* A `/** … *\/` doc comment at `indent`, its text made safe (docText): one line when it fits in 100 columns, else
|
|
22
22
|
* google-java-format's filled lines, each word on the first line it fits, after ` * `.
|
|
@@ -60,7 +60,7 @@ function classLines({ name, doc, base, cause, param }) {
|
|
|
60
60
|
`public final class ${name} extends ${base} {`,
|
|
61
61
|
" private static final long serialVersionUID = 1L;",
|
|
62
62
|
"",
|
|
63
|
-
` ${name}(${param === "failure" ? "Failure failure" :
|
|
63
|
+
` ${name}(${param === "failure" ? "Failure failure" : `String message${cause ? ", Throwable cause" : ""}`}) {`,
|
|
64
64
|
` super(${args});`,
|
|
65
65
|
" }",
|
|
66
66
|
"}",
|
|
@@ -23,7 +23,7 @@ function declaredHeaders(op) {
|
|
|
23
23
|
.filter((status) => /^2(?:\d\d|XX)$/i.test(status))
|
|
24
24
|
.sort(compareCodeUnits)
|
|
25
25
|
.flatMap((status) => op.ir.responses[status].headers ?? []);
|
|
26
|
-
|
|
26
|
+
// reversed, so the first spelling of a name is the one its key ends on
|
|
27
27
|
const first = new Map(all.toReversed().map((header) => [header.name.toLowerCase(), header]));
|
|
28
28
|
return [...first.values()].sort((a, b) => compareCodeUnits(a.name, b.name));
|
|
29
29
|
}
|
|
@@ -59,7 +59,7 @@ export function javaResponseHeaders(op, env) {
|
|
|
59
59
|
...fields.flatMap(({ accessor, header, parse, word }) => statement(4, exprStmt(assign(accessor, call("Answer", "header", [
|
|
60
60
|
"headers",
|
|
61
61
|
javaString(header.name),
|
|
62
|
-
String(header.required
|
|
62
|
+
String(header.required),
|
|
63
63
|
javaString(word),
|
|
64
64
|
parse,
|
|
65
65
|
]))))),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { accessor, assign, call, classHeader, exprStmt, finalField, lambda, methodHeader, newOf, param, returnStmt, statement, } from "./layout.js";
|
|
2
|
+
import { connectionOf } from "./realtime.js";
|
|
3
|
+
import { blocks, clientLines, membersOf, nodeOf, recordSource, resourceName, } from "./sdk-client.js";
|
|
2
4
|
import { docOf, docParagraphs } from "./sdk-decl.js";
|
|
3
5
|
import { putFile } from "./sdk-models.js";
|
|
4
6
|
import { answerOf, paragraphsOf } from "./sdk-op.js";
|
|
5
|
-
import { connectionOf } from "./realtime.js";
|
|
6
7
|
import { paramsName } from "./sdk-params.js";
|
|
7
|
-
import { blocks, clientLines, membersOf, nodeOf, recordSource, resourceName, } from "./sdk-client.js";
|
|
8
8
|
import { sseEventOf } from "./sse.js";
|
|
9
9
|
import { wsSocketOf } from "./ws.js";
|
|
10
10
|
/** The type the normal method answers: a stream's, a connection's, or the answer's (`void` for none). */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type JavaTypeContext } from "./models.ts";
|
|
2
1
|
import type { IR } from "../../ir/model.ts";
|
|
2
|
+
import { type JavaTypeContext } from "./models.ts";
|
|
3
3
|
/** The import lines `decl` needs, sorted as google-java-format sorts them. */
|
|
4
4
|
export declare function importsOf(decl: string): string[];
|
|
5
5
|
/** One model file's text: the marker, the package, its imports, its declaration. */
|
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
* needs its own. A file imports exactly the types its text spells, in google-java-format's order: one block, sorted.
|
|
5
5
|
*/
|
|
6
6
|
import { compareCodeUnits } from "../shared/lang.js";
|
|
7
|
-
import { declares, javaTopLevel } from "./models.js";
|
|
8
7
|
import { codeOf } from "./models-names.js";
|
|
9
|
-
|
|
8
|
+
import { declares, javaTopLevel } from "./models.js";
|
|
9
|
+
// every type a model declaration may spell that java.lang does not hold, by its simple name
|
|
10
10
|
const IMPORTS = {
|
|
11
|
+
Consumer: "java.util.function.Consumer",
|
|
11
12
|
DeserializationContext: "tools.jackson.databind.DeserializationContext",
|
|
13
|
+
Duration: "java.time.Duration",
|
|
14
|
+
InputStream: "java.io.InputStream",
|
|
12
15
|
JsonAnyGetter: "com.fasterxml.jackson.annotation.JsonAnyGetter",
|
|
13
16
|
JsonAnySetter: "com.fasterxml.jackson.annotation.JsonAnySetter",
|
|
14
17
|
JsonCreator: "com.fasterxml.jackson.annotation.JsonCreator",
|
|
@@ -19,12 +22,9 @@ const IMPORTS = {
|
|
|
19
22
|
JsonProperty: "com.fasterxml.jackson.annotation.JsonProperty",
|
|
20
23
|
JsonValue: "com.fasterxml.jackson.annotation.JsonValue",
|
|
21
24
|
LinkedHashMap: "java.util.LinkedHashMap",
|
|
25
|
+
List: "java.util.List",
|
|
22
26
|
Map: "java.util.Map",
|
|
23
27
|
StdDeserializer: "tools.jackson.databind.deser.std.StdDeserializer",
|
|
24
|
-
Consumer: "java.util.function.Consumer",
|
|
25
|
-
Duration: "java.time.Duration",
|
|
26
|
-
InputStream: "java.io.InputStream",
|
|
27
|
-
List: "java.util.List",
|
|
28
28
|
Supplier: "java.util.function.Supplier",
|
|
29
29
|
TypeReference: "tools.jackson.core.type.TypeReference",
|
|
30
30
|
};
|
|
@@ -51,7 +51,7 @@ export function componentDecls(ir, ctx) {
|
|
|
51
51
|
const name = ctx.names.ref(key);
|
|
52
52
|
decls.set(name, javaTopLevel(name, schema, ctx));
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
// a hoist claims its name from the same scope as the components, so it never repeats one
|
|
55
55
|
for (const [name, decl] of ctx.decls)
|
|
56
56
|
decls.set(name, decl);
|
|
57
57
|
return decls;
|
|
@@ -8,11 +8,10 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { IRSchema } from "../../ir/model.ts";
|
|
10
10
|
import type { SdkOp } from "../../ir/sdk-model.ts";
|
|
11
|
-
import { type JavaTypeContext } from "./models.ts";
|
|
12
11
|
import { type Expr } from "./layout.ts";
|
|
12
|
+
import { type JavaTypeContext } from "./models.ts";
|
|
13
13
|
import { type JavaHeaders } from "./sdk-headers.ts";
|
|
14
14
|
import type { JavaCallPlan } from "./sdk-plan.ts";
|
|
15
|
-
import { type Field } from "./sdk-params.ts";
|
|
16
15
|
/** What an operation's text needs: the type context its types hoist into, and the array test. */
|
|
17
16
|
export type OpEnv = {
|
|
18
17
|
readonly ctx: JavaTypeContext;
|
|
@@ -40,18 +39,10 @@ export type JavaOp = {
|
|
|
40
39
|
};
|
|
41
40
|
/** A method's javadoc paragraphs: the operation's id, then its summary and description, as the other SDKs carry them. */
|
|
42
41
|
export declare const paragraphsOf: (op: SdkOp) => string[];
|
|
43
|
-
/** The constant's name for a method: its words upper-cased, `_OPERATION` after them. */
|
|
44
|
-
export declare const constantOf: (method: string) => string;
|
|
45
42
|
/** The answer's Java type and its reader on `answer`, for each response kind. */
|
|
46
43
|
export declare function answerOf(op: SdkOp, env: OpEnv): {
|
|
47
44
|
readonly reader: Expr;
|
|
48
45
|
readonly type: string;
|
|
49
46
|
};
|
|
50
|
-
/** One method's name, its fields, and the holder of its response headers when it declares any. */
|
|
51
|
-
export type MethodSite = {
|
|
52
|
-
readonly name: string;
|
|
53
|
-
readonly fields: readonly Field[];
|
|
54
|
-
readonly headers: JavaHeaders | null;
|
|
55
|
-
};
|
|
56
47
|
/** One operation's text and plan, with its accessors left to the resource tree. */
|
|
57
48
|
export declare function javaOp(op: SdkOp, name: string, env: OpEnv): JavaOp;
|
package/dist/emit/java/sdk-op.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { javaString } from "../shared/escape.js";
|
|
2
2
|
import { snakeWords } from "../shared/lang.js";
|
|
3
|
-
import { javaTypeOf } from "./models.js";
|
|
4
3
|
import { array, call, exprStmt, field, lit, local, methodHeader, param, newOf, returnStmt, statement, } from "./layout.js";
|
|
4
|
+
import { javaTypeOf } from "./models.js";
|
|
5
|
+
import { MAX_RECONNECT_ATTEMPTS, RECONNECT_DELAY, realtimeMethodLines } from "./realtime.js";
|
|
5
6
|
import { docParagraphs } from "./sdk-decl.js";
|
|
6
7
|
import { javaResponseHeaders } from "./sdk-headers.js";
|
|
7
|
-
import {
|
|
8
|
+
import { fieldsOf, multipartRecord, paramsName } from "./sdk-params.js";
|
|
9
|
+
import { multipartHelper, multipartRecordLines, paramsRecord } from "./sdk-record.js";
|
|
8
10
|
import { CURSOR, sseMethodLines } from "./sse.js";
|
|
9
11
|
import { PROTOCOLS, TOKEN, wsMethodLines } from "./ws.js";
|
|
10
|
-
import { multipartHelper, multipartRecordLines, paramsRecord } from "./sdk-record.js";
|
|
11
|
-
import { fieldsOf, multipartRecord, paramsName } from "./sdk-params.js";
|
|
12
12
|
const UNKNOWN = { kind: "unknown" };
|
|
13
13
|
/** A method's javadoc paragraphs: the operation's id, then its summary and description, as the other SDKs carry them. */
|
|
14
14
|
export const paragraphsOf = (op) => [op.id, op.summary, op.description].filter((text) => text !== "");
|
|
15
15
|
/** The constant's name for a method: its words upper-cased, `_OPERATION` after them. */
|
|
16
|
-
|
|
16
|
+
const constantOf = (method) => `${snakeWords(method).toUpperCase()}_OPERATION`;
|
|
17
17
|
/** The answer's Java type and its reader on `answer`, for each response kind. */
|
|
18
18
|
export function answerOf(op, env) {
|
|
19
19
|
const kind = op.success.kind;
|
|
@@ -97,7 +97,7 @@ function methodLines(op, site, env) {
|
|
|
97
97
|
const answer = answerOf(op, env);
|
|
98
98
|
const returns = answer.type;
|
|
99
99
|
const params = paramsName(op, env.ctx);
|
|
100
|
-
|
|
100
|
+
// `return value;`, or the statement alone for no answer
|
|
101
101
|
const ret = (value) => statement(4, returns === "void" ? exprStmt(value) : returnStmt(value));
|
|
102
102
|
const delegate = (args) => ret(call(null, name, args));
|
|
103
103
|
const fill = headers === null
|
|
@@ -205,10 +205,10 @@ export function javaOp(op, name, env) {
|
|
|
205
205
|
body: multipart === null
|
|
206
206
|
? null
|
|
207
207
|
: { lines: multipartRecordLines(multipart.name, op.id, multipart.components), name: multipart.name },
|
|
208
|
-
headers,
|
|
209
|
-
helper: multipartHelper(op, env),
|
|
210
208
|
constant,
|
|
211
209
|
constantLines: constantLines(op, constant),
|
|
210
|
+
headers,
|
|
211
|
+
helper: multipartHelper(op, env),
|
|
212
212
|
lines: methodLines(op, { fields, headers, name }, env),
|
|
213
213
|
params: paramsRecord(paramsName(op, env.ctx), op.id, fields),
|
|
214
214
|
plan,
|
|
@@ -29,10 +29,10 @@ export declare const opTypeName: (op: SdkOp, kind: "Body" | "Headers" | "Params"
|
|
|
29
29
|
export declare const paramsName: (op: SdkOp, ctx: JavaTypeContext) => string;
|
|
30
30
|
/** Each multipart part as a record component: a file's `FilePart` or a list of them, a text part's type. */
|
|
31
31
|
export declare function multipartRecord(op: SdkOp, parts: readonly IRMultipartPart[], ctx: JavaTypeContext, isArray: (s: IRSchema) => boolean): {
|
|
32
|
-
components: {
|
|
33
|
-
field: string;
|
|
34
|
-
name: string;
|
|
35
|
-
type: string;
|
|
32
|
+
readonly components: {
|
|
33
|
+
readonly field: string;
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly type: string;
|
|
36
36
|
}[];
|
|
37
|
-
name: string;
|
|
37
|
+
readonly name: string;
|
|
38
38
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { compareCodeUnits, javaIdentifier, javaTypeName, NameScope } from "../shared/lang.js";
|
|
2
2
|
import { javaTypeOf } from "./models.js";
|
|
3
|
-
import { CURSOR, isLastEventIdHeader, LAST_EVENT_ID } from "./sse.js";
|
|
4
3
|
import { carriesRealtime, REALTIME_FIELDS } from "./realtime.js";
|
|
4
|
+
import { CURSOR, isLastEventIdHeader, LAST_EVENT_ID } from "./sse.js";
|
|
5
5
|
import { isReconnectTokenQuery, PROTOCOLS, RECONNECT_TOKEN, TOKEN } from "./ws.js";
|
|
6
6
|
/** The record's own members, which a component may not take (`builder()` is static). */
|
|
7
7
|
const RECORD_RESERVED = ["builder", "equals", "hashCode", "toString"];
|
|
@@ -88,7 +88,7 @@ export function fieldsOf(op, ctx) {
|
|
|
88
88
|
function streamFields(op) {
|
|
89
89
|
if (op.stream === "sse")
|
|
90
90
|
return [{ field: CURSOR, name: LAST_EVENT_ID, required: false, type: "String", where: "cursor" }];
|
|
91
|
-
if (op.stream === "realtime")
|
|
91
|
+
if (op.stream === "realtime") {
|
|
92
92
|
return REALTIME_FIELDS.map((f) => ({
|
|
93
93
|
field: f.field,
|
|
94
94
|
name: f.field,
|
|
@@ -96,6 +96,7 @@ function streamFields(op) {
|
|
|
96
96
|
type: f.type,
|
|
97
97
|
where: "realtime",
|
|
98
98
|
}));
|
|
99
|
+
}
|
|
99
100
|
if (op.stream !== "ws")
|
|
100
101
|
return [];
|
|
101
102
|
return [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/emit/java/sdk.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type PackageIdentity } from "../shared/metadata.ts";
|
|
1
2
|
import { type JavaPomMetadata } from "./gradle.ts";
|
|
2
3
|
import { type JavaCallPlan } from "./sdk-plan.ts";
|
|
3
|
-
import { type PackageIdentity } from "../shared/metadata.ts";
|
|
4
4
|
/** The package's options, each defaulted and validated. */
|
|
5
5
|
export type JavaSdkOptions = {
|
|
6
6
|
/** the Maven group id; `com.example` by default, the reserved example domain as the Go SDK's `example.com/sdk`: Maven
|
package/dist/emit/java/sdk.js
CHANGED
|
@@ -5,23 +5,24 @@
|
|
|
5
5
|
* no `HttpClient.close`). The emitted Java is google-java-format's canonical form by construction (format.test.ts).
|
|
6
6
|
*/
|
|
7
7
|
import { readFileSync } from "node:fs";
|
|
8
|
+
import { toIR } from "../../ir/build.js";
|
|
9
|
+
import { sdkModel } from "../../ir/sdk-model.js";
|
|
8
10
|
import { compareCodeUnits } from "../shared/lang.js";
|
|
11
|
+
import { packageOn } from "../shared/metadata.js";
|
|
12
|
+
import { renameNotice } from "../shared/mirror.js";
|
|
9
13
|
import { buildGradle, pomOf, settingsGradle, validateArtifactId, validateClientName, validateGroupId, validatePackageName, validateVersion, } from "./gradle.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
14
|
+
import { javaTypeContext } from "./models.js";
|
|
15
|
+
import { REALTIME_FILES } from "./realtime.js";
|
|
12
16
|
import { surfaceOf } from "./sdk-client.js";
|
|
17
|
+
import { errorClassFiles, errorKeyFiles } from "./sdk-errors.js";
|
|
13
18
|
import { mirrorOf } from "./sdk-mirror.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { javaTypeContext } from "./models.js";
|
|
19
|
+
import { componentDecls, modelFiles, putFile } from "./sdk-models.js";
|
|
20
|
+
import {} from "./sdk-plan.js";
|
|
17
21
|
import { SSE_FILES } from "./sse.js";
|
|
18
|
-
import { REALTIME_FILES } from "./realtime.js";
|
|
19
22
|
import { WS_FILES } from "./ws.js";
|
|
20
|
-
import { sdkModel } from "../../ir/sdk-model.js";
|
|
21
|
-
import { toIR } from "../../ir/build.js";
|
|
22
23
|
/** The marker on line 1 of every emitted file. */
|
|
23
24
|
const MARKER = "// @generated by clients. DO NOT EDIT.";
|
|
24
|
-
|
|
25
|
+
// the package line of every vendored runtime file
|
|
25
26
|
const RUNTIME_PACKAGE = /^package http\.runtime;$/m;
|
|
26
27
|
/** The validated package for `options`. */
|
|
27
28
|
function packageOf(options) {
|
|
@@ -114,8 +115,8 @@ const OPERATION_FILES = [
|
|
|
114
115
|
/** The vendored runtime's files by class name, read from disk on every call, in `packageName`; every file by default. */
|
|
115
116
|
export function runtimeFiles(packageName, features = {
|
|
116
117
|
json: true,
|
|
117
|
-
opt: true,
|
|
118
118
|
operations: true,
|
|
119
|
+
opt: true,
|
|
119
120
|
realtime: true,
|
|
120
121
|
transport: true,
|
|
121
122
|
ws: true,
|
|
@@ -164,7 +165,7 @@ function featuresOf(ops, decls) {
|
|
|
164
165
|
function emitJava(document, options) {
|
|
165
166
|
const pkg = packageOf(options);
|
|
166
167
|
const dir = `src/main/java/${pkg.packageName.replaceAll(".", "/")}`;
|
|
167
|
-
|
|
168
|
+
// an operation without an operationId is named by the IR's derivation, as every sibling emitter asks
|
|
168
169
|
const ir = toIR(document, { deriveOperationIds: true });
|
|
169
170
|
const pom = pomOf(options, ir.info);
|
|
170
171
|
const model = sdkModel(ir);
|
|
@@ -188,7 +189,7 @@ function emitJava(document, options) {
|
|
|
188
189
|
}
|
|
189
190
|
: {};
|
|
190
191
|
const decls = componentDecls(ir, ctx);
|
|
191
|
-
|
|
192
|
+
// the mirror's names are claimed last, after every normal one (the components' own hoists included)
|
|
192
193
|
const mirror = operations ? mirrorOf(ir, env) : {};
|
|
193
194
|
const runtime = Object.entries(runtimeFiles(pkg.packageName, featuresOf(model.ops, decls))).map(([name, text]) => [`${dir}/${name}.java`, text]);
|
|
194
195
|
const client = operations ? mirror[`${pkg.clientName}.java`] : `${MARKER}\n${clientJava(pkg)}`;
|
|
@@ -203,7 +204,7 @@ function emitJava(document, options) {
|
|
|
203
204
|
.filter(([name]) => name !== `${pkg.clientName}.java`)
|
|
204
205
|
.map(([name, text]) => [`${dir}/${name}`, text]),
|
|
205
206
|
];
|
|
206
|
-
|
|
207
|
+
// one declaration per file: a second claim of a path throws, never overwrites
|
|
207
208
|
const files = {};
|
|
208
209
|
for (const [path, text] of entries)
|
|
209
210
|
putFile(files, path, text);
|
package/dist/emit/java/sse.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SdkOp } from "../../ir/sdk-model.ts";
|
|
2
|
-
import { type JavaTypeContext } from "./models.ts";
|
|
3
2
|
import { type Expr } from "./layout.ts";
|
|
3
|
+
import { type JavaTypeContext } from "./models.ts";
|
|
4
4
|
import type { JavaHeaders } from "./sdk-headers.ts";
|
|
5
5
|
/** The header an SSE open resumes an event stream with. */
|
|
6
6
|
export declare const LAST_EVENT_ID = "Last-Event-ID";
|
|
@@ -8,10 +8,8 @@ export declare const LAST_EVENT_ID = "Last-Event-ID";
|
|
|
8
8
|
export declare const CURSOR = "lastEventId";
|
|
9
9
|
/** Whether a declared header param is Last-Event-ID (any casing), the resume channel the cursor field carries. */
|
|
10
10
|
export declare const isLastEventIdHeader: (name: string) => boolean;
|
|
11
|
-
/** F1's doc obligation: how a stream lets its connection go. */
|
|
12
|
-
export declare const RELEASE = "Open it in try-with-resources: a for-each break without one keeps the connection.";
|
|
13
11
|
/** The SSE runtime's files: the stream, its event, the parser and the body's pump; core, with every exchange. */
|
|
14
|
-
export declare const SSE_FILES: string[];
|
|
12
|
+
export declare const SSE_FILES: readonly string[];
|
|
15
13
|
/**
|
|
16
14
|
* What an SSE op's stream yields and the decode the method hands the runtime: a named-event op's `<Op>Event` through
|
|
17
15
|
* its `of`; else `SseEvent<T>` through `EventStream.typed`, `T` the declared event schema's type, or `SseEvent<String>`
|
package/dist/emit/java/sse.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isJsonEventData, sseEvents } from "../../ir/sdk-model.js";
|
|
2
2
|
import { javaString } from "../shared/escape.js";
|
|
3
3
|
import { javaTypeName, NameScope } from "../shared/lang.js";
|
|
4
|
-
import { javaTypeOf } from "./models.js";
|
|
5
4
|
import { bin, call as callOf, cond, id, lambda, lit, local, methodHeader, param, newOf, ref, returnStmt, rule, statement, typeHeader, } from "./layout.js";
|
|
5
|
+
import { javaTypeOf } from "./models.js";
|
|
6
6
|
import { docOf } from "./sdk-decl.js";
|
|
7
7
|
/** The header an SSE open resumes an event stream with. */
|
|
8
8
|
export const LAST_EVENT_ID = "Last-Event-ID";
|
|
@@ -11,10 +11,10 @@ export const CURSOR = "lastEventId";
|
|
|
11
11
|
/** Whether a declared header param is Last-Event-ID (any casing), the resume channel the cursor field carries. */
|
|
12
12
|
export const isLastEventIdHeader = (name) => name.toLowerCase() === LAST_EVENT_ID.toLowerCase();
|
|
13
13
|
/** F1's doc obligation: how a stream lets its connection go. */
|
|
14
|
-
|
|
14
|
+
const RELEASE = "Open it in try-with-resources: a for-each break without one keeps the connection.";
|
|
15
15
|
/** The SSE runtime's files: the stream, its event, the parser and the body's pump; core, with every exchange. */
|
|
16
16
|
export const SSE_FILES = ["EventStream", "Pump", "Sse", "SseEvent"];
|
|
17
|
-
|
|
17
|
+
// the names a nested record never takes besides the models scope's: the types its declaration spells
|
|
18
18
|
const SPELLED = ["Duration", "EventStream", "Object", "SseEvent", "String", "TypeReference"];
|
|
19
19
|
/** A nested record's header: its data, then the event's name, id and retry. */
|
|
20
20
|
const recordLines = (record, data, name) => typeHeader(2, {
|
|
@@ -51,7 +51,7 @@ function nestedOf(op, events, name, ctx) {
|
|
|
51
51
|
const type = json ? javaTypeOf(data, { ...ctx, fieldName: event, parentName: op.id, path: "" }) : "String";
|
|
52
52
|
return { data: type, event, json };
|
|
53
53
|
});
|
|
54
|
-
|
|
54
|
+
// a type a record's data spells would be shadowed by a nested record of its name
|
|
55
55
|
const spelled = typed.flatMap(({ data }) => data.split(/\W+/).filter((word) => word !== ""));
|
|
56
56
|
const reserved = new Set([...SPELLED, ...spelled, name, "Unknown"]);
|
|
57
57
|
const scope = new NameScope(reserved);
|
|
@@ -76,11 +76,11 @@ function namedEvents(op, events, ctx) {
|
|
|
76
76
|
const name = ctx.names.hoist(`${op.id}.events`, `${javaTypeName(op.id)}Event`);
|
|
77
77
|
if (ctx.decls.has(name))
|
|
78
78
|
return name;
|
|
79
|
-
|
|
79
|
+
// claimed before its body: what the data types hoist comes after it
|
|
80
80
|
ctx.decls.set(name, "");
|
|
81
81
|
const nested = nestedOf(op, events, name, ctx);
|
|
82
82
|
const records = nested.map(({ record }) => record).join(", ");
|
|
83
|
-
|
|
83
|
+
// the nested records are its permits
|
|
84
84
|
const header = typeHeader(0, { end: "{", kind: "interface", modifiers: ["public", "sealed"], name, permits: [] });
|
|
85
85
|
ctx.decls.set(name, [
|
|
86
86
|
docOf(`One event of ${op.id}: ${records}, or Unknown for a name the operation does not declare, its data as sent. An instanceof match reads the event's data.`, ""),
|
package/dist/emit/java/ws.d.ts
CHANGED
|
@@ -23,9 +23,9 @@ export declare const RECONNECT_TOKEN = "reconnect_token";
|
|
|
23
23
|
export declare const PROTOCOLS = "protocols";
|
|
24
24
|
export declare const TOKEN = "reconnectToken";
|
|
25
25
|
/** Whether a declared query param is reconnect_token, the resume channel the token field carries. */
|
|
26
|
-
export declare const isReconnectTokenQuery: (name: string) =>
|
|
26
|
+
export declare const isReconnectTokenQuery: (name: string) => boolean;
|
|
27
27
|
/** The WebSocket runtime's files: the socket and its parts; only an SDK with a WebSocket operation ships them. */
|
|
28
|
-
export declare const WS_FILES: string[];
|
|
28
|
+
export declare const WS_FILES: readonly string[];
|
|
29
29
|
/**
|
|
30
30
|
* What a generated reader extends: its base class, the handlers the base has (a member whose `on<Value>` one of them
|
|
31
31
|
* names gets none), what its docs call it, and the suffix its name takes after the read type's.
|
package/dist/emit/java/ws.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NameScope } from "../shared/lang.js";
|
|
2
2
|
import { bin, call as callOf, exprStmt, id, ifOpen, lambda, lit, methodHeader, newOf, param, returnStmt, statement, typeHeader, } from "./layout.js";
|
|
3
|
-
import { declaredTypeOf, keyedArms } from "./models.js";
|
|
4
3
|
import { JSON_NODE } from "./models-names.js";
|
|
4
|
+
import { declaredTypeOf, keyedArms } from "./models.js";
|
|
5
5
|
import { docOf } from "./sdk-decl.js";
|
|
6
6
|
/** The query param the token travels in. */
|
|
7
7
|
export const RECONNECT_TOKEN = "reconnect_token";
|
|
@@ -42,7 +42,7 @@ const handlerLines = (reader, sub, name, { payload, wrapper }) => [
|
|
|
42
42
|
];
|
|
43
43
|
/** The arms of `arms` that get an `on<Value>`: each but one whose handler `reader` has already. */
|
|
44
44
|
export const handledArms = (reader, arms) => arms.filter((arm) => !reader.handlers.includes(handlerName(arm)));
|
|
45
|
-
|
|
45
|
+
// the handler an arm's first value spells
|
|
46
46
|
const handlerName = (arm) => `on${arm.spelled}`;
|
|
47
47
|
/**
|
|
48
48
|
* `<read><Suffix>`, hoisted into `ctx.decls` once per read type and reader with an `on<Value>` per arm of `arms` but
|
|
@@ -82,9 +82,8 @@ export function wsSocketOf(op, ctx) {
|
|
|
82
82
|
const messages = op.ir.messages;
|
|
83
83
|
const at = (fieldName) => ({ ...ctx, fieldName, parentName: op.id, path: "" });
|
|
84
84
|
const write = messages?.receive === undefined ? JSON_NODE : declaredTypeOf(messages.receive, at("Receive"));
|
|
85
|
-
if (messages?.send === undefined)
|
|
85
|
+
if (messages?.send === undefined)
|
|
86
86
|
return { read: asSent(), type: `TypedWebSocket<WsMessage, ${write}>`, wrap: AS_DIALED };
|
|
87
|
-
}
|
|
88
87
|
const read = declaredTypeOf(messages.send, at("Send"));
|
|
89
88
|
const decode = callOf("TypedWebSocket", "json", [newOf(`TypeReference<${read}>`, [], true)]);
|
|
90
89
|
const arms = keyedArms(read, messages.send, ctx);
|
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
export function annotationsOf(op) {
|
|
3
3
|
switch (op.method.toUpperCase()) {
|
|
4
4
|
case "GET":
|
|
5
|
-
case "HEAD":
|
|
5
|
+
case "HEAD": {
|
|
6
6
|
return { readOnlyHint: true };
|
|
7
|
-
|
|
7
|
+
}
|
|
8
|
+
case "POST": {
|
|
8
9
|
return op.idempotent ? { destructiveHint: false, idempotentHint: true } : { destructiveHint: false };
|
|
10
|
+
}
|
|
9
11
|
case "PUT":
|
|
10
|
-
case "DELETE":
|
|
12
|
+
case "DELETE": {
|
|
11
13
|
return { idempotentHint: true };
|
|
12
|
-
|
|
14
|
+
}
|
|
15
|
+
default: {
|
|
13
16
|
return undefined;
|
|
17
|
+
}
|
|
14
18
|
}
|
|
15
19
|
}
|