@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/go/sse.js
CHANGED
|
@@ -5,7 +5,7 @@ import { sendArgs } from "./sdk-answer.js";
|
|
|
5
5
|
import { goTypeOf } from "./types.js";
|
|
6
6
|
/** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
|
|
7
7
|
export const isLastEventIdHeader = (param, where) => where === "header" && param.toLowerCase() === "last-event-id";
|
|
8
|
-
|
|
8
|
+
// LastEventID, sent only when set: an empty header would still name a position
|
|
9
9
|
const SSE_OPTS = {
|
|
10
10
|
before: [],
|
|
11
11
|
carries: isLastEventIdHeader,
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The package-level names Go types are declared under (v0 buildGoNames): one scope that components,
|
|
3
|
+
* hoisted types and constants all claim from, clear of every identifier the Go runtime declares.
|
|
4
|
+
*/
|
|
5
|
+
import {} from "../../ir/model.js";
|
|
1
6
|
import { irResolver } from "../../ir/schema.js";
|
|
2
7
|
import { valueCycleSchemas } from "../../ir/sdk-model.js";
|
|
3
8
|
import { compareCodeUnits, goExported, NameScope } from "../shared/lang.js";
|
|
@@ -10,7 +10,7 @@ export type StructField = {
|
|
|
10
10
|
triState: boolean;
|
|
11
11
|
};
|
|
12
12
|
/** The field holding the keys `additionalProperties` admits beyond the declared ones. */
|
|
13
|
-
|
|
13
|
+
type ExtraField = {
|
|
14
14
|
goName: string;
|
|
15
15
|
valueType: string;
|
|
16
16
|
};
|
|
@@ -27,3 +27,4 @@ export type StructShape = {
|
|
|
27
27
|
export declare function isTagName(key: string): boolean;
|
|
28
28
|
/** `type <name> struct { … }` with its embeds, fields and extra map, then whatever methods its keys need. */
|
|
29
29
|
export declare function structDecl(name: string, shape: StructShape): string;
|
|
30
|
+
export {};
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { goString } from "../shared/escape.js";
|
|
8
8
|
import { fillingMarshal, marshal, unmarshal } from "./types-codec.js";
|
|
9
|
-
|
|
9
|
+
// the punctuation encoding/json's isValidTag accepts in a tag name
|
|
10
10
|
const TAG_PUNCTUATION = "!#$%&()*+-./:;<=>?@[]^_{|}~ ";
|
|
11
11
|
/** Whether encoding/json reads `key` as a tag name (its isValidTag: a letter, a decimal digit or that punctuation). */
|
|
12
12
|
export function isTagName(key) {
|
package/dist/emit/go/types.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { goString } from "../shared/escape.js";
|
|
2
2
|
import { compareCodeUnits, goExported, NameScope } from "../shared/lang.js";
|
|
3
|
-
import { irNames, plainNames } from "./types-names.js";
|
|
4
3
|
import { isNilable } from "./types-codec.js";
|
|
4
|
+
import { irNames, plainNames } from "./types-names.js";
|
|
5
5
|
import { isTagName, structDecl } from "./types-struct.js";
|
|
6
6
|
import { unionDecl, variantTypes } from "./types-union.js";
|
|
7
7
|
const RAW = "json.RawMessage";
|
|
8
|
-
|
|
8
|
+
// deeper than this, a schema is raw JSON
|
|
9
9
|
const MAX_DEPTH = 12;
|
|
10
10
|
const SCALARS = {
|
|
11
11
|
boolean: "bool",
|
|
@@ -22,7 +22,7 @@ export function goTypeContext(ir) {
|
|
|
22
22
|
function declare(ir, at, key, base) {
|
|
23
23
|
const name = at.names.hoist(key, base);
|
|
24
24
|
if (!at.decls.has(name)) {
|
|
25
|
-
|
|
25
|
+
// claimed before its body: what the body hoists in turn comes after it
|
|
26
26
|
at.decls.set(name, "");
|
|
27
27
|
at.decls.set(name, goTopLevel(name, ir, at));
|
|
28
28
|
}
|
|
@@ -71,7 +71,7 @@ const USES = {
|
|
|
71
71
|
ref: refUse,
|
|
72
72
|
scalar: (ir, at) => (isEnum(ir) ? hoist(ir, at) : SCALARS[ir.type]),
|
|
73
73
|
tuple: (ir) => `[${ir.items.length}]interface{}`,
|
|
74
|
-
|
|
74
|
+
// Go has no union type
|
|
75
75
|
union: () => RAW,
|
|
76
76
|
unknown: () => RAW,
|
|
77
77
|
};
|
|
@@ -85,13 +85,13 @@ export function goTypeOf(ir, at) {
|
|
|
85
85
|
/** A label for an enum value inside a constant name: `""` is `Empty`, a negative number `Neg<n>`. */
|
|
86
86
|
function enumLabel(value) {
|
|
87
87
|
if (typeof value === "number")
|
|
88
|
-
return `${value < 0 ? "Neg" : ""}${String(Math.abs(value)).
|
|
88
|
+
return `${value < 0 ? "Neg" : ""}${String(Math.abs(value)).replaceAll(/\W/g, "_")}`;
|
|
89
89
|
return value === "" ? "Empty" : goExported(String(value));
|
|
90
90
|
}
|
|
91
91
|
/** `type <name> string|int` and one `<name><Label>` constant per value of its kind. */
|
|
92
92
|
function enumDecl(name, ir, names) {
|
|
93
93
|
const integer = ir.type === "integer";
|
|
94
|
-
|
|
94
|
+
// a value of the other kind (or a null) has no constant
|
|
95
95
|
const values = ir.enum.filter((value) => integer ? Number.isInteger(value) : value !== null);
|
|
96
96
|
const labels = new NameScope();
|
|
97
97
|
const consts = values.map((value) => {
|
|
@@ -132,7 +132,7 @@ function objectDecl(name, ir, at) {
|
|
|
132
132
|
: undefined;
|
|
133
133
|
return structDecl(name, { embeds: [], extra, fields });
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
// the kinds a required field may render as a slice or a map, whose nil a MarshalJSON fills
|
|
136
136
|
const SLICE_OR_MAP = ["allOf", "array", "nullable", "object"];
|
|
137
137
|
/** A field encoding/json handles alone: a key a tag can name, never a required slice or map. */
|
|
138
138
|
const plainField = (field) => isTagName(field.name) && !(field.required && SLICE_OR_MAP.includes(field.schema.kind));
|
|
@@ -172,7 +172,7 @@ export function goTopLevel(name, ir, at) {
|
|
|
172
172
|
const variant = (schema, key, base) => declare(schema, at, key, base);
|
|
173
173
|
return unionDecl(name, { ...ir, discriminator: ir.discriminator }, at.names, variant);
|
|
174
174
|
}
|
|
175
|
-
|
|
175
|
+
// a map or an empty struct is a named type; anything else an alias
|
|
176
176
|
return `type ${name} ${ir.kind === "object" ? "" : "= "}${use(ir, member(name, at, "Value"))}`;
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
@@ -181,7 +181,7 @@ export function goTopLevel(name, ir, at) {
|
|
|
181
181
|
*/
|
|
182
182
|
export function goKeyedMembers(schema, dispatch, at) {
|
|
183
183
|
const name = schema.kind === "ref" ? at.names.ref(schema.name) : `${goExported(at.parentName)}${goExported(at.fieldName)}`;
|
|
184
|
-
|
|
184
|
+
// a mapping names refs only, whose type is their component's: the key alone names each inline member
|
|
185
185
|
const union = { ...dispatch.union, discriminator: { propertyName: dispatch.key } };
|
|
186
186
|
const types = variantTypes(name, union, at.names, (variant, key, base) => declare(variant, at, key, base));
|
|
187
187
|
return dispatch.members.map(({ value }, i) => [value, types[i]]);
|
package/dist/emit/go/ws.js
CHANGED
|
@@ -6,7 +6,7 @@ import { isLastEventIdHeader } from "./sse.js";
|
|
|
6
6
|
import { goKeyedMembers, goTypeOf } from "./types.js";
|
|
7
7
|
/** Whether a declared param is the `reconnect_token` query param a WebSocket dial sends. */
|
|
8
8
|
const isReconnectToken = (param, where) => where === "query" && param === "reconnect_token";
|
|
9
|
-
|
|
9
|
+
// both open a socket: a dial fails before any stream exists
|
|
10
10
|
const FAIL = "nil, err";
|
|
11
11
|
const WS_OPTS = {
|
|
12
12
|
before: [],
|
|
@@ -25,16 +25,16 @@ const WS_OPTS = {
|
|
|
25
25
|
const WS = {
|
|
26
26
|
base: "TypedWebSocket",
|
|
27
27
|
handlers: ["OnMessage", "OnClose", "OnError"],
|
|
28
|
+
open: (client, read, write) => `dialWebSocket(${sendArgs(client, read, write)})`,
|
|
28
29
|
suffix: "Socket",
|
|
29
30
|
what: "socket",
|
|
30
|
-
open: (client, read, write) => `dialWebSocket(${sendArgs(client, read, write)})`,
|
|
31
31
|
};
|
|
32
32
|
const REALTIME = {
|
|
33
33
|
base: "ResumableConnection",
|
|
34
34
|
handlers: ["OnMessage"],
|
|
35
|
+
open: (client, read, write) => `newRealtime(${sendArgs(client, "topts", read, write)})`,
|
|
35
36
|
suffix: "Connection",
|
|
36
37
|
what: "connection",
|
|
37
|
-
open: (client, read, write) => `newRealtime(${sendArgs(client, "topts", read, write)})`,
|
|
38
38
|
};
|
|
39
39
|
/** `<Op><direction>`, the sealed interface of the keyed union `schema`'s members, each marked as one; its lines. */
|
|
40
40
|
function sealed(op, members, iface, says) {
|
|
@@ -99,7 +99,7 @@ function keyedInbound(op, send, dispatch, at) {
|
|
|
99
99
|
].join("\n"));
|
|
100
100
|
return { codec: decode, decode, key: dispatch.key, members, type: iface };
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
// a send of an op that declares none: as given
|
|
103
103
|
const UNTYPED_OUT = { codec: "messageAsIs", type: "any" };
|
|
104
104
|
/** The fields `schema` requires at its top level: an object's, none for any other schema. */
|
|
105
105
|
function requiredOf(schema, at) {
|
|
@@ -188,7 +188,7 @@ function wsStream(op, at) {
|
|
|
188
188
|
const read = inbound(op, send, () => ({ codec: "frameBytes", type: "[]byte" }), at);
|
|
189
189
|
return { ...answerOf(op, WS, { read, write: outbound(op, receive, at) }, at), doc: "", opts: WS_OPTS };
|
|
190
190
|
}
|
|
191
|
-
|
|
191
|
+
// the realtime Opts' one own field, which `sets` copies: the method sets its Headers and HTTPClient
|
|
192
192
|
const REALTIME_FIELDS = [
|
|
193
193
|
{
|
|
194
194
|
doc: "Transport is the resume cursor, the offered subprotocols and the reconnect policy; the connection advances its own copy, and the client sets Headers and HTTPClient.",
|
|
@@ -198,7 +198,7 @@ const REALTIME_FIELDS = [
|
|
|
198
198
|
];
|
|
199
199
|
const REALTIME_OPTS = {
|
|
200
200
|
before: ["var topts TransportOpts"],
|
|
201
|
-
|
|
201
|
+
// the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID
|
|
202
202
|
carries: (param, where) => isReconnectToken(param, where) ||
|
|
203
203
|
(where === "query" && param === "last_event_id") ||
|
|
204
204
|
isLastEventIdHeader(param, where),
|
|
@@ -6,8 +6,6 @@ export type JavaPackage = {
|
|
|
6
6
|
readonly packageName: string;
|
|
7
7
|
readonly version: string;
|
|
8
8
|
};
|
|
9
|
-
/** The one runtime dependency, its coordinates pinned with the test classpath's (java-pins.json). */
|
|
10
|
-
export declare const JACKSON = "tools.jackson.core:jackson-databind:3.2.4";
|
|
11
9
|
/** A Maven group id: lowercase dotted words. */
|
|
12
10
|
export declare const validateGroupId: (value: string) => string;
|
|
13
11
|
/** A Maven artifact id: lowercase words joined by `-`. */
|
|
@@ -21,23 +19,23 @@ export declare const validateVersion: (value: string) => string;
|
|
|
21
19
|
/** What Maven Central requires of a POM beyond its name and description, each part the caller gave, validated. */
|
|
22
20
|
export type JavaPomMetadata = {
|
|
23
21
|
/** the POM's description, over the document's */
|
|
24
|
-
readonly description?: string;
|
|
22
|
+
readonly description?: string | undefined;
|
|
25
23
|
/** the project's https home page, the POM's `url` */
|
|
26
|
-
readonly homepage?: string;
|
|
24
|
+
readonly homepage?: string | undefined;
|
|
27
25
|
/** one SPDX license id */
|
|
28
|
-
readonly license?: string;
|
|
26
|
+
readonly license?: string | undefined;
|
|
29
27
|
/** the https URL of its git repository, without a trailing `/` or `.git` */
|
|
30
|
-
readonly repository?: string;
|
|
28
|
+
readonly repository?: string | undefined;
|
|
31
29
|
/** the POM's developers, comma separated: each a name, or `Name <email>` */
|
|
32
|
-
readonly developers?: string;
|
|
30
|
+
readonly developers?: string | undefined;
|
|
33
31
|
};
|
|
34
32
|
/** The POM metadata validated: the developers one entry each. */
|
|
35
33
|
type PomFields = Omit<JavaPomMetadata, "developers"> & {
|
|
36
|
-
readonly developers?: readonly string[];
|
|
34
|
+
readonly developers?: readonly string[] | undefined;
|
|
37
35
|
};
|
|
38
36
|
/** The POM's words: the document's name and description (spec text, written only through `groovyString`), the rest. */
|
|
39
37
|
export type JavaPom = PomFields & {
|
|
40
|
-
readonly name?: string;
|
|
38
|
+
readonly name?: string | undefined;
|
|
41
39
|
};
|
|
42
40
|
/** The POM for `options` over the document's `info`: the metadata validated, its description over the document's. */
|
|
43
41
|
export declare function pomOf(options: JavaPomMetadata, info: {
|
package/dist/emit/java/gradle.js
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
import { escapeText } from "../shared/escape.js";
|
|
11
11
|
import { AUTHOR, authorOf, checked, HTTPS_URL, SPDX_ID, TEXT } from "../shared/metadata.js";
|
|
12
12
|
/** The one runtime dependency, its coordinates pinned with the test classpath's (java-pins.json). */
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const JACKSON = "tools.jackson.core:jackson-databind:3.2.4";
|
|
14
|
+
// Java's keywords and literals (JLS 3.9, 3.10.3, 3.10.7): no package segment may be one, and `_` is one since 9
|
|
15
15
|
const RESERVED = [
|
|
16
16
|
"abstract",
|
|
17
17
|
"assert",
|
|
@@ -68,15 +68,15 @@ const RESERVED = [
|
|
|
68
68
|
"null",
|
|
69
69
|
"_",
|
|
70
70
|
];
|
|
71
|
-
|
|
71
|
+
// the type names the client file spells or imports, and its nested Builder: a client of one of these clashes
|
|
72
72
|
const SPELLED = ["Builder", "IllegalStateException", "String", "Transport", "URI"];
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
// a Maven group: lowercase dotted words; an artifact: lowercase words joined by `-`; a package segment: a lowercase
|
|
74
|
+
// identifier; a client: a PascalCase type
|
|
75
75
|
const GROUP_ID = /^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)*$/;
|
|
76
76
|
const ARTIFACT_ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
77
77
|
const SEGMENT = /^[a-z_][a-z0-9_]*$/;
|
|
78
78
|
const CLIENT_NAME = /^[A-Z][A-Za-z0-9_]*$/;
|
|
79
|
-
|
|
79
|
+
// SemVer 2 (semver.org's recommended pattern), as the C# and Rust packages take it
|
|
80
80
|
const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
81
81
|
const refuse = (option, value) => {
|
|
82
82
|
throw new Error(`Invalid ${option}: ${JSON.stringify(value)}`);
|
|
@@ -95,7 +95,7 @@ export function validatePackageName(value) {
|
|
|
95
95
|
export const validateClientName = (value) => CLIENT_NAME.test(value) && !SPELLED.includes(value) ? value : refuse("clientName", value);
|
|
96
96
|
/** A SemVer 2 version. */
|
|
97
97
|
export const validateVersion = (value) => (SEMVER.test(value) ? value : refuse("version", value));
|
|
98
|
-
|
|
98
|
+
// a repository is a path on its host: `https://host/owner/name`
|
|
99
99
|
const REPOSITORY_PATH = /^https:\/\/[^/]+\/[^/]/;
|
|
100
100
|
/** The developers option as one author each, or a refusal of the whole value when any is not a name or `Name <email>`. */
|
|
101
101
|
function developersOf(value) {
|
|
@@ -128,7 +128,7 @@ export function pomOf(options, info) {
|
|
|
128
128
|
* text neither interpolates (no `$` in `'…'`) nor ends the string.
|
|
129
129
|
*/
|
|
130
130
|
const groovyString = (text) => `'${escapeText(text, "java").replaceAll("'", "\\'")}'`;
|
|
131
|
-
|
|
131
|
+
// the indent of the `pom { … }` block's members, and of one level in
|
|
132
132
|
const POM = " ";
|
|
133
133
|
const IN = " ";
|
|
134
134
|
/** `key = '…'` lines at `indent`, each value a Groovy string. */
|
package/dist/emit/java/json.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { javaString } from "../shared/escape.js";
|
|
7
7
|
import { bin, call, classOf, forOpen, ifOpen, lit, local, methodHeader, newOf, param, returnStmt, rule, statement, throwStmt, typeHeader, } from "./layout.js";
|
|
8
|
-
|
|
8
|
+
// a payload's erasure: `Class` takes no type arguments
|
|
9
9
|
const erased = (type) => type.replace(/<.*$/, "");
|
|
10
10
|
/** One switch arm, `case label -> value;` (`default` for no label), in the switch's body. */
|
|
11
11
|
const arm = (label, value) => statement(8, rule(label === null ? null : lit(label), value));
|
|
@@ -52,7 +52,7 @@ export const id = (path) => path
|
|
|
52
52
|
/** A literal or any token kept whole: `"GET"`, `null`, `true`, `16L`. */
|
|
53
53
|
export const lit = (text) => ({ k: "lit", text });
|
|
54
54
|
/** A string as an expression: an identifier path, else a token kept whole. */
|
|
55
|
-
export const expr = (e) => typeof e
|
|
55
|
+
export const expr = (e) => typeof e === "string" ? (/^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*)*$/.test(e) ? id(e) : lit(e)) : e;
|
|
56
56
|
/** `of.name(args)`, or `name(args)` with no receiver; a string receiver is an identifier path. */
|
|
57
57
|
export const call = (of, name, args = []) => ({
|
|
58
58
|
args: args.map(expr),
|
|
@@ -125,15 +125,16 @@ export function method(v, m) {
|
|
|
125
125
|
/** The return type and the name with its `(`, the break before the name tagged. */
|
|
126
126
|
function nameScope(v, m, beforeName) {
|
|
127
127
|
v.b.open(0);
|
|
128
|
-
if (m.returns
|
|
128
|
+
if (m.returns === undefined) {
|
|
129
|
+
v.b.open(0);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
129
132
|
v.b.open(0);
|
|
130
133
|
v.b.open(0);
|
|
131
134
|
v.type(type(m.returns));
|
|
132
135
|
v.b.close();
|
|
133
136
|
v.b.brk("independent", " ", 0, beforeName);
|
|
134
|
-
}
|
|
135
|
-
else
|
|
136
|
-
v.b.open(0); /* a constructor's name scope opens with its name */
|
|
137
|
+
} /* a constructor's name scope opens with its name */
|
|
137
138
|
v.b.token(m.name);
|
|
138
139
|
v.b.token("(");
|
|
139
140
|
v.b.close();
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/** google-java-format's line width. */
|
|
10
10
|
export const WIDTH = 100;
|
|
11
|
-
|
|
11
|
+
// a forced break is "wider" than any line (Doc.MAX_LINE_WIDTH)
|
|
12
12
|
const MAX = 1000;
|
|
13
13
|
const evalIndent = (indent) => typeof indent === "number" ? indent : indent.tag.taken ? indent.onBreak : indent.onFlat;
|
|
14
14
|
/** Indent.If: `onBreak` when `tag`'s break was taken, else `onFlat`. */
|
|
@@ -50,8 +50,9 @@ function computeBroken(doc, start) {
|
|
|
50
50
|
doc.breaks.push(child);
|
|
51
51
|
doc.splits.push([]);
|
|
52
52
|
}
|
|
53
|
-
else
|
|
53
|
+
else {
|
|
54
54
|
doc.splits.at(-1).push(child);
|
|
55
|
+
}
|
|
55
56
|
}
|
|
56
57
|
return doc.splits.reduce((state, split, i) => breakAndSplit(state, i === 0 ? undefined : doc.breaks[i - 1], split), start);
|
|
57
58
|
}
|
|
@@ -68,8 +69,9 @@ function breakAndSplit(state, brk, split) {
|
|
|
68
69
|
brk.newIndent = Math.max(state.lastIndent + evalIndent(brk.indent), 0);
|
|
69
70
|
next = { ...state, column: brk.newIndent };
|
|
70
71
|
}
|
|
71
|
-
else
|
|
72
|
+
else {
|
|
72
73
|
next = { ...state, column: state.column + brk.flat.length };
|
|
74
|
+
}
|
|
73
75
|
}
|
|
74
76
|
const room = next.column + splitWidth <= WIDTH;
|
|
75
77
|
next = { ...next, mustBreak: false };
|
|
@@ -78,20 +80,24 @@ function breakAndSplit(state, brk, split) {
|
|
|
78
80
|
return room ? next : { ...next, mustBreak: true };
|
|
79
81
|
}
|
|
80
82
|
function write(doc, out) {
|
|
81
|
-
if (doc.k === "text")
|
|
83
|
+
if (doc.k === "text") {
|
|
82
84
|
put(doc, out);
|
|
83
|
-
|
|
85
|
+
}
|
|
86
|
+
else if (doc.k === "break") {
|
|
84
87
|
out.text += doc.broken ? `\n${" ".repeat(doc.newIndent)}` : doc.flat;
|
|
85
|
-
|
|
88
|
+
}
|
|
89
|
+
else if (doc.oneLine) {
|
|
86
90
|
for (const child of doc.docs)
|
|
87
91
|
writeFlat(child, out);
|
|
88
|
-
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
89
94
|
doc.splits.forEach((split, i) => {
|
|
90
95
|
if (i > 0)
|
|
91
96
|
write(doc.breaks[i - 1], out);
|
|
92
97
|
for (const child of split)
|
|
93
98
|
write(child, out);
|
|
94
99
|
});
|
|
100
|
+
}
|
|
95
101
|
}
|
|
96
102
|
function writeFlat(doc, out) {
|
|
97
103
|
if (doc.k === "level")
|
|
@@ -59,7 +59,7 @@ function regularDot(v, items) {
|
|
|
59
59
|
}
|
|
60
60
|
v.b.token(e.name);
|
|
61
61
|
argsAndParen(v, e, 0);
|
|
62
|
-
|
|
62
|
+
// the last item is the chain itself, and no dot follows it
|
|
63
63
|
if (i < items.length - 1)
|
|
64
64
|
length += v.flat(e).length;
|
|
65
65
|
});
|
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
* `+` chain (or stands alone), else under its own quote.
|
|
5
5
|
*/
|
|
6
6
|
import { WIDTH } from "./layout-doc.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* `\n`/`\r` escapes ending the piece it closes
|
|
10
|
-
*/
|
|
7
|
+
// StringWrapper.stringComponents: a literal's body cut before each whitespace character (and a `\t`), a run of
|
|
8
|
+
// `\n`/`\r` escapes ending the piece it closes
|
|
11
9
|
function piecesOf(body) {
|
|
12
10
|
const out = [];
|
|
13
11
|
let start = 0;
|
|
@@ -19,8 +17,9 @@ function piecesOf(body) {
|
|
|
19
17
|
while (body.startsWith("\\r", i) || body.startsWith("\\n", i))
|
|
20
18
|
i += 2;
|
|
21
19
|
}
|
|
22
|
-
else
|
|
20
|
+
else {
|
|
23
21
|
continue;
|
|
22
|
+
}
|
|
24
23
|
out.push(body.slice(start, i));
|
|
25
24
|
start = i;
|
|
26
25
|
}
|
|
@@ -31,8 +31,9 @@ function typeList(v, word, types) {
|
|
|
31
31
|
v.b.open(4);
|
|
32
32
|
v.b.token(word);
|
|
33
33
|
types.forEach((t, i) => {
|
|
34
|
-
if (i === 0)
|
|
34
|
+
if (i === 0) {
|
|
35
35
|
v.b.space();
|
|
36
|
+
}
|
|
36
37
|
else {
|
|
37
38
|
v.b.token(",");
|
|
38
39
|
v.b.breakOp(" ");
|
|
@@ -44,7 +45,7 @@ function typeList(v, word, types) {
|
|
|
44
45
|
/** A type declaration's header, through its `{` (or `{}`). */
|
|
45
46
|
export function typeDeclaration(v, h) {
|
|
46
47
|
if (h.kind === "enum") {
|
|
47
|
-
|
|
48
|
+
// visitEnumDeclaration's header: a level of its own, `enum` and a unified break before the name at +4
|
|
48
49
|
v.b.open(0);
|
|
49
50
|
typeModifiers(v, h);
|
|
50
51
|
v.b.open(4);
|
|
@@ -61,7 +62,7 @@ export function typeDeclaration(v, h) {
|
|
|
61
62
|
v.b.token(h.name);
|
|
62
63
|
v.b.open(4);
|
|
63
64
|
if (h.kind === "record") {
|
|
64
|
-
|
|
65
|
+
// visitRecordDeclaration's components as formals, then its interface
|
|
65
66
|
v.b.token("(");
|
|
66
67
|
if (h.components.length > 0) {
|
|
67
68
|
v.b.breakToFill("");
|
|
@@ -79,15 +80,16 @@ export function typeDeclaration(v, h) {
|
|
|
79
80
|
}
|
|
80
81
|
else if (h.kind === "class") {
|
|
81
82
|
if (h.extends !== undefined) {
|
|
82
|
-
|
|
83
|
+
// classDeclarationTypeList of one superclass, in no level of its own
|
|
83
84
|
v.b.breakToFill(" ");
|
|
84
85
|
v.b.token("extends");
|
|
85
86
|
v.b.space();
|
|
86
87
|
v.type(type(h.extends));
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
|
-
else if (h.permits.length > 0)
|
|
90
|
+
else if (h.permits.length > 0) {
|
|
90
91
|
typeList(v, "permits", h.permits);
|
|
92
|
+
}
|
|
91
93
|
v.b.close();
|
|
92
94
|
}
|
|
93
95
|
v.b.space();
|
|
@@ -59,7 +59,7 @@ export class Visitor {
|
|
|
59
59
|
new Visitor(b).expr(e);
|
|
60
60
|
return b.flat();
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
// hasOnlyShortItems: every item under MAX_ITEM_LENGTH_FOR_FILLING (10) characters
|
|
63
63
|
shortItems(items) {
|
|
64
64
|
return items.every((item) => this.flat(item).length < 10);
|
|
65
65
|
}
|
|
@@ -78,8 +78,9 @@ export class Visitor {
|
|
|
78
78
|
const dims = t.dims > 0;
|
|
79
79
|
if (dims)
|
|
80
80
|
this.b.open(4);
|
|
81
|
-
if (t.args.length === 0)
|
|
81
|
+
if (t.args.length === 0) {
|
|
82
82
|
this.typeName(t.name);
|
|
83
|
+
}
|
|
83
84
|
else {
|
|
84
85
|
this.b.open(4);
|
|
85
86
|
this.typeName(t.name);
|
|
@@ -220,7 +221,7 @@ export class Visitor {
|
|
|
220
221
|
this.b.brk(fill, " ");
|
|
221
222
|
this.b.token(e.op);
|
|
222
223
|
this.b.space();
|
|
223
|
-
|
|
224
|
+
// a literal in a `+` after a non-literal operand reflows under its own quote
|
|
224
225
|
const later = e.op === "+" && isString(operand) && !e.operands.slice(0, i + 1).every(isString);
|
|
225
226
|
if (later)
|
|
226
227
|
this.b.literal(this.flat(operand), true);
|
package/dist/emit/java/layout.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* (GJF's Doc and DocBuilder), the visitor layout-visitor.ts, layout-dot.ts and layout-decl.ts (JavaInputAstVisitor),
|
|
6
6
|
* and a long string literal is reflowed as StringWrapper reflows it (layout-strings.ts).
|
|
7
7
|
*/
|
|
8
|
-
import { expr } from "./layout-ast.js";
|
|
8
|
+
import { expr, } from "./layout-ast.js";
|
|
9
9
|
import { annotation, declareOne, method } from "./layout-decl.js";
|
|
10
10
|
import { Builder } from "./layout-doc.js";
|
|
11
11
|
import { wrapStrings } from "./layout-strings.js";
|
|
@@ -26,7 +26,7 @@ const STATEMENTS = {
|
|
|
26
26
|
v.b.token(";");
|
|
27
27
|
},
|
|
28
28
|
for: (v, s) => {
|
|
29
|
-
|
|
29
|
+
// visitEnhancedForLoop: the variable declared with `:` before its iterable
|
|
30
30
|
v.b.open(0);
|
|
31
31
|
v.b.token("for");
|
|
32
32
|
v.b.space();
|
|
@@ -53,10 +53,11 @@ const STATEMENTS = {
|
|
|
53
53
|
local: (v, s) => declareOne(v, s.decl, { kind: "variable", trailing: ";" }),
|
|
54
54
|
return: (v, s) => keyword(v, "return", s.expr),
|
|
55
55
|
rule: (v, s) => {
|
|
56
|
-
|
|
56
|
+
// visitCase, a rule: `case label ->` or `default ->`, a unified break, the value at +4
|
|
57
57
|
v.b.open(4);
|
|
58
|
-
if (s.label === null)
|
|
58
|
+
if (s.label === null) {
|
|
59
59
|
v.b.token("default");
|
|
60
|
+
}
|
|
60
61
|
else {
|
|
61
62
|
v.b.token("case");
|
|
62
63
|
v.b.open(0);
|
|
@@ -9,7 +9,7 @@ import { irResolver } from "../../ir/schema.js";
|
|
|
9
9
|
import { compareCodeUnits, javaTypeName, NameScope } from "../shared/lang.js";
|
|
10
10
|
/** The type a value without a schema is, and the one a nullable open value is. */
|
|
11
11
|
export const JSON_NODE = "JsonNode";
|
|
12
|
-
|
|
12
|
+
// the type names the emitted models and the client spell, which no runtime file holds: each is reserved
|
|
13
13
|
const SPELLED = [
|
|
14
14
|
"Boolean",
|
|
15
15
|
"Builder",
|
|
@@ -39,7 +39,7 @@ const SPELLED = [
|
|
|
39
39
|
* The code text a scan reads: comments dropped and string and char literals emptied, in one left-to-right pass, so a
|
|
40
40
|
* `//` inside a string opens no comment and a quote inside a comment opens no string.
|
|
41
41
|
*/
|
|
42
|
-
export const codeOf = (code) => code.
|
|
42
|
+
export const codeOf = (code) => code.replaceAll(/\/\*[\s\S]*?\*\/|\/\/.*$|"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)'/gm, (token) => token.startsWith("/") ? "" : token[0] === '"' ? '""' : "''");
|
|
43
43
|
/** The type names `code` spells: each imported type by its simple name, and each capitalized identifier that is not a member access. */
|
|
44
44
|
export function spelledIn(code) {
|
|
45
45
|
const text = codeOf(code);
|
|
@@ -70,13 +70,14 @@ export function javaNames(schemas, taken, declares) {
|
|
|
70
70
|
const base = javaTypeName(name);
|
|
71
71
|
const taken = scope.has(base);
|
|
72
72
|
components.set(name, scope.claim(taken ? `${base}Model` : base));
|
|
73
|
-
if (taken)
|
|
73
|
+
if (taken) {
|
|
74
74
|
renamed.push({
|
|
75
75
|
because: `"${base}" is a name the SDK's runtime, the JDK or another declaration holds`,
|
|
76
76
|
name,
|
|
77
77
|
renamed: components.get(name),
|
|
78
78
|
what: "component",
|
|
79
79
|
});
|
|
80
|
+
}
|
|
80
81
|
}
|
|
81
82
|
const hoisted = new Map();
|
|
82
83
|
return {
|
|
@@ -90,7 +91,7 @@ export function javaNames(schemas, taken, declares) {
|
|
|
90
91
|
hoisted.set(key, name);
|
|
91
92
|
return name;
|
|
92
93
|
},
|
|
93
|
-
|
|
94
|
+
// a ref reaches here only for a declared component: `alias` answers for every other one
|
|
94
95
|
ref: (name) => components.get(name),
|
|
95
96
|
renamed,
|
|
96
97
|
resolve: irResolver(schemas),
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import type { IRField, IRSchema } from "../../ir/model.ts";
|
|
12
12
|
import type { JavaTypeContext, Member } from "./models.ts";
|
|
13
|
-
export declare const RECORD_MEMBERS: readonly string[];
|
|
14
13
|
/** A record's members: its fields, and whether it keeps every other member (it declares `additionalProperties`). */
|
|
15
14
|
export type RecordShape = {
|
|
16
15
|
readonly fields: readonly IRField[];
|
|
@@ -2,8 +2,8 @@ import { javaString } from "../shared/escape.js";
|
|
|
2
2
|
import { camelWords, compareCodeUnits, isJavaReserved, NameScope } from "../shared/lang.js";
|
|
3
3
|
import { typeHeader } from "./layout.js";
|
|
4
4
|
import { JSON_NODE } from "./models-names.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// every member name a record component collides with: java.lang.Record's and Object's synthesized and final methods
|
|
6
|
+
const RECORD_MEMBERS = [
|
|
7
7
|
"clone",
|
|
8
8
|
"equals",
|
|
9
9
|
"finalize",
|
|
@@ -16,7 +16,7 @@ export const RECORD_MEMBERS = [
|
|
|
16
16
|
];
|
|
17
17
|
const NON_NULL = { args: ["JsonInclude.Include.NON_NULL"], name: "JsonInclude" };
|
|
18
18
|
const NON_EMPTY = { args: ["JsonInclude.Include.NON_EMPTY"], name: "JsonInclude" };
|
|
19
|
-
|
|
19
|
+
// a required, non-nullable use of these is written primitive
|
|
20
20
|
const PRIMITIVE = { Boolean: "boolean", Double: "double", Long: "long" };
|
|
21
21
|
/** Whether an object, or any object part of an allOf (refs followed), declares `additionalProperties`. */
|
|
22
22
|
export function isOpen(schema, resolve) {
|
|
@@ -15,7 +15,7 @@ type Discriminated = Of<"union"> & {
|
|
|
15
15
|
discriminator: IRDiscriminator;
|
|
16
16
|
};
|
|
17
17
|
/** Declares `schema` once under `key` and `base`; its name. */
|
|
18
|
-
|
|
18
|
+
type Declare = (schema: IRSchema, key: string, base: string) => string;
|
|
19
19
|
/** What a union's declaration reaches: the context, its members' types, and the hoist. */
|
|
20
20
|
export type UnionScope = {
|
|
21
21
|
at: JavaTypeContext;
|
|
@@ -2,8 +2,8 @@ import { compareCodeUnits, javaTypeName } from "../shared/lang.js";
|
|
|
2
2
|
import { deserializerLines } from "./json.js";
|
|
3
3
|
import { classOf, typeHeader } from "./layout.js";
|
|
4
4
|
import { enumValues, stringEnumDecl } from "./models-enum.js";
|
|
5
|
-
import { fieldsOf } from "./models-record.js";
|
|
6
5
|
import { JSON_NODE } from "./models-names.js";
|
|
6
|
+
import { fieldsOf } from "./models-record.js";
|
|
7
7
|
/** Whether a variant is a const string: a union of these alone is a string enum. */
|
|
8
8
|
export const isLiteral = (variant) => variant.kind === "const" && typeof variant.value === "string";
|
|
9
9
|
/** The values that select `variant`: its mapping keys, else its property's const or enum, else its ref's name. */
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* type name is reserved where it collides (models-names.ts).
|
|
6
6
|
*/
|
|
7
7
|
import type { IR, IRSchema } from "../../ir/model.ts";
|
|
8
|
-
import { type JavaTypeNames } from "./models-names.ts";
|
|
9
8
|
import type { Dispatch } from "./json.ts";
|
|
10
|
-
|
|
9
|
+
import { type JavaTypeNames } from "./models-names.ts";
|
|
11
10
|
/** Where a type is being written, the declarations it hoists, and the names. */
|
|
12
11
|
export type JavaTypeContext = {
|
|
13
12
|
parentName: string;
|