@wirecat/cli-base 0.113.0 → 0.115.0
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/CHANGELOG.md +46 -0
- package/dist/codegen/graphql-fake.d.ts +55 -0
- package/dist/codegen/graphql-fake.js +187 -0
- package/dist/codegen/graphql.d.ts +53 -0
- package/dist/codegen/graphql.js +379 -0
- package/dist/codegen/index.d.ts +5 -3
- package/dist/codegen/index.js +4 -2
- package/dist/codegen/manifest.js +2 -2
- package/dist/codegen/model.d.ts +14 -1
- package/dist/codegen/names.d.ts +3 -0
- package/dist/codegen/names.js +6 -0
- package/dist/codegen/pipeline.js +7 -6
- package/dist/codegen/skill.js +2 -2
- package/dist/dev/audit.d.ts +19 -0
- package/dist/dev/audit.js +23 -4
- package/dist/dev/main.js +15 -10
- package/dist/standards/audit.d.ts +14 -0
- package/dist/standards/audit.js +29 -11
- package/docs/standards/ci.md +1 -0
- package/docs/standards/kit-surface.md +7 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,52 @@ Versions before 0.8.0 are in the [git tags](https://github.com/WireCatLabs/cli-b
|
|
|
8
8
|
Every entry says what changed as a caller sees it, why, and what to watch for — the rules are
|
|
9
9
|
[`docs/dev/CONVENTIONS.md`](docs/dev/CONVENTIONS.md#the-changelog).
|
|
10
10
|
|
|
11
|
+
## 0.115.0 — 17.11.2026
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **A GraphQL API generates its `api` group too.** `adaptGraphql` reads an introspection result into the model: one
|
|
16
|
+
operation per `Query` and `Mutation` field, with a new `graphql` binding (the field, its variables' GraphQL types and
|
|
17
|
+
a default selection), its arguments as body flags, a Relay connection paged as `cursor`, and `*Delete`/`*Archive`
|
|
18
|
+
mutations as deletes. `syncGraphql` and `readGraphql` keep the snapshot with its hash, `graphqlDocument` builds the
|
|
19
|
+
request, and `graphqlFake` is a strict fake for tests. Watch for: `Binding` has a third member, so code that reads
|
|
20
|
+
`binding.name` once a binding is not `http` must narrow to `rpc`; `bindingLabel` names any binding. See the
|
|
21
|
+
[reference](docs/REFERENCE.md). For the Linear pilot.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- **`generate` with `auth` signs in an operation whose spec says `security: []`**, the same as one with no
|
|
26
|
+
`security`. Before, the empty list stayed, cli-core read it as "no sign-in", and the call went out without the key:
|
|
27
|
+
HubSpot's object specs mark 115 calls so, and each answered 401. An operation keeps its own `security` only when
|
|
28
|
+
it signs in by `auth`'s schemes. A CLI that drops an empty `security` from the generated manifest at runtime can
|
|
29
|
+
stop once it regenerates on this version.
|
|
30
|
+
|
|
31
|
+
## 0.114.0 — 17.11.2026
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
|
|
35
|
+
- **hubspot-cli takes the monthly minute 03:11 UTC** in the [CI](docs/standards/ci.md) list, and joins the
|
|
36
|
+
`shared-roots` and `crm` parity groups next to b24 and amo. Like notion and pbx, it is not one of the CLIs
|
|
37
|
+
`audit --family` installs. Its `schedule` summary is a declared difference until cli-core stops cutting summaries
|
|
38
|
+
after the CLI's name, which ends hubspot's a word earlier than b24's.
|
|
39
|
+
|
|
40
|
+
### Fixed
|
|
41
|
+
|
|
42
|
+
- **An audit by a CLI's own parity groups keeps cli-base's declared entity schema and error reason differences.**
|
|
43
|
+
`cli-dev audit --groups`, and `--family` reading `config/parity-groups.json`, replaced cli-base's groups along with
|
|
44
|
+
differences such as `entity hit`, so every CLI made from cli-template blocked on a divergence cli-base had already
|
|
45
|
+
accepted. These differences name no CLI list, so they now hold in any audit, outside every group's budget. Past
|
|
46
|
+
their `review_after` they only warn there: only cli-base can renew them, and its own weekly audit fails on them. A
|
|
47
|
+
group that declares the same rule and target keeps its own entry.
|
|
48
|
+
- **`cli-dev audit --family` no longer blocks a CLI on an entity schema a published CLI shares with it.** The published
|
|
49
|
+
CLIs then already disagree among themselves, as when some are on an older cli-core, and the release cannot fix it.
|
|
50
|
+
A schema no other CLI prints still blocks, and so does any shared one outside `--family`, where two local builds
|
|
51
|
+
could vouch for each other. The rule cannot tell ahead from behind, and the first CLI to take a new schema still
|
|
52
|
+
needs a declared difference. A CRM CLI made from cli-template on cli-core 0.695.0 was blocked on `entity hit`:
|
|
53
|
+
cli-core 0.688.0 added the `crm_file` kind, and zm 0.80.0 prints it while tg 0.133.0, max 0.118.0, wa 0.45.0,
|
|
54
|
+
cli-memo 0.143.0 and drive 0.71.0 do not yet. cli-base already declared that difference, and the entry above now
|
|
55
|
+
keeps it in a CLI's own audit.
|
|
56
|
+
|
|
11
57
|
## 0.113.0 — 17.11.2026
|
|
12
58
|
|
|
13
59
|
### Added
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A strict fake of a GraphQL service, built from the files `generate` wrote, in the spirit of `fakeApi`: a `fetch` that
|
|
3
|
+
* takes only a POST of a document `graphqlDocument` builds for an operation the manifest has, refuses a selection
|
|
4
|
+
* field the type lacks, variables that break their schema and a missing sign-in, and answers `data.<field>` within
|
|
5
|
+
* the selection. A test writes only its scenarios; one that answers outside the schema or the selection throws.
|
|
6
|
+
*/
|
|
7
|
+
import { type Selection } from "./graphql.js";
|
|
8
|
+
import type { ManifestOperation } from "./manifest.js";
|
|
9
|
+
import type { SchemaNode } from "./model.js";
|
|
10
|
+
type Definitions = Readonly<Record<string, SchemaNode>>;
|
|
11
|
+
export interface GraphqlFakeCall {
|
|
12
|
+
/** The matched operation's id; absent when the request matched none. */
|
|
13
|
+
operation?: string;
|
|
14
|
+
query: string;
|
|
15
|
+
selection?: Selection;
|
|
16
|
+
variables: Readonly<Record<string, unknown>>;
|
|
17
|
+
headers: Headers;
|
|
18
|
+
}
|
|
19
|
+
/** `data` is the field's answer; `errors` are sent as GraphQL's, with HTTP 200 unless `status` says otherwise. */
|
|
20
|
+
export interface GraphqlFakeAnswer {
|
|
21
|
+
status?: number;
|
|
22
|
+
data?: unknown;
|
|
23
|
+
errors?: readonly {
|
|
24
|
+
message: string;
|
|
25
|
+
extensions?: Readonly<Record<string, unknown>>;
|
|
26
|
+
}[];
|
|
27
|
+
headers?: Readonly<Record<string, string>>;
|
|
28
|
+
}
|
|
29
|
+
type Answering = (call: GraphqlFakeCall) => GraphqlFakeAnswer | Promise<GraphqlFakeAnswer>;
|
|
30
|
+
export interface GraphqlFakeOptions {
|
|
31
|
+
operations: readonly ManifestOperation[];
|
|
32
|
+
definitions: Definitions;
|
|
33
|
+
/** The endpoint: `https://api.linear.app/graphql`. */
|
|
34
|
+
url: string;
|
|
35
|
+
/** The header and value every call must carry: `{ header: "Authorization", value: "<key>" }`. */
|
|
36
|
+
auth?: {
|
|
37
|
+
header: string;
|
|
38
|
+
value: string;
|
|
39
|
+
};
|
|
40
|
+
/** Answers by operation id; one without an answer gets a sample of its selection. */
|
|
41
|
+
answers?: Readonly<Record<string, Answering>>;
|
|
42
|
+
}
|
|
43
|
+
export interface GraphqlFake {
|
|
44
|
+
fetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
45
|
+
calls: GraphqlFakeCall[];
|
|
46
|
+
/** Why each refused call was refused; a test that expects none asserts this is empty. */
|
|
47
|
+
refusals: string[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Every field the selection names that the type lacks, a leaf asked without a selection, or an object asked with one.
|
|
51
|
+
* On a union only `__typename` is selectable: its members' fields need fragments, which a selection here never has.
|
|
52
|
+
*/
|
|
53
|
+
export declare const selectionProblems: (selection: Selection, node: SchemaNode, definitions: Definitions, where?: string) => string[];
|
|
54
|
+
export declare const graphqlFake: (options: GraphqlFakeOptions) => GraphqlFake;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A strict fake of a GraphQL service, built from the files `generate` wrote, in the spirit of `fakeApi`: a `fetch` that
|
|
3
|
+
* takes only a POST of a document `graphqlDocument` builds for an operation the manifest has, refuses a selection
|
|
4
|
+
* field the type lacks, variables that break their schema and a missing sign-in, and answers `data.<field>` within
|
|
5
|
+
* the selection. A test writes only its scenarios; one that answers outside the schema or the selection throws.
|
|
6
|
+
*/
|
|
7
|
+
import { sampleOf, schemaProblems } from "./fake.js";
|
|
8
|
+
import { graphqlDocument, parseSelection } from "./graphql.js";
|
|
9
|
+
import { identifier } from "./names.js";
|
|
10
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11
|
+
/** What a selection walks into, through references, lists and a nullable wrapper: an object, a union or a leaf. */
|
|
12
|
+
const shapeOf = (node, definitions, depth = 0) => {
|
|
13
|
+
if (depth > 20)
|
|
14
|
+
return { kind: "leaf" };
|
|
15
|
+
switch (node.type) {
|
|
16
|
+
case "ref": {
|
|
17
|
+
const target = definitions[identifier(node.ref)];
|
|
18
|
+
return target ? shapeOf(target, definitions, depth + 1) : { kind: "leaf" };
|
|
19
|
+
}
|
|
20
|
+
case "array":
|
|
21
|
+
return shapeOf(node.items, definitions, depth + 1);
|
|
22
|
+
case "allOf": {
|
|
23
|
+
const objects = node.of.flatMap((one) => {
|
|
24
|
+
const inner = shapeOf(one, definitions, depth + 1);
|
|
25
|
+
return inner.kind === "object" ? inner.objects : [];
|
|
26
|
+
});
|
|
27
|
+
return objects.length > 0 ? { kind: "object", objects } : { kind: "leaf" };
|
|
28
|
+
}
|
|
29
|
+
case "union":
|
|
30
|
+
return { kind: "union" };
|
|
31
|
+
case "object":
|
|
32
|
+
return { kind: "object", objects: [node] };
|
|
33
|
+
default:
|
|
34
|
+
return { kind: "leaf" };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Every field the selection names that the type lacks, a leaf asked without a selection, or an object asked with one.
|
|
39
|
+
* On a union only `__typename` is selectable: its members' fields need fragments, which a selection here never has.
|
|
40
|
+
*/
|
|
41
|
+
export const selectionProblems = (selection, node, definitions, where = "selection") => {
|
|
42
|
+
const shape = shapeOf(node, definitions);
|
|
43
|
+
if (shape.kind === "leaf")
|
|
44
|
+
return [`${where}: a scalar has no fields to select`];
|
|
45
|
+
return Object.entries(selection).flatMap(([name, inner]) => {
|
|
46
|
+
if (name === "__typename")
|
|
47
|
+
return inner === true ? [] : [`${where}.__typename: a scalar has no fields to select`];
|
|
48
|
+
if (shape.kind === "union")
|
|
49
|
+
return [`${where}.${name}: a union takes only __typename`];
|
|
50
|
+
const property = shape.objects.map((one) => one.properties[name]).find(Boolean);
|
|
51
|
+
if (!property)
|
|
52
|
+
return [`${where}.${name}: no such field`];
|
|
53
|
+
const leaf = shapeOf(property, definitions).kind === "leaf";
|
|
54
|
+
if (inner === true)
|
|
55
|
+
return leaf ? [] : [`${where}.${name}: an object needs a selection`];
|
|
56
|
+
return selectionProblems(inner, property, definitions, `${where}.${name}`);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
/** Every field of the answer outside the selection. */
|
|
60
|
+
const outside = (value, selection, where) => {
|
|
61
|
+
if (Array.isArray(value))
|
|
62
|
+
return value.flatMap((one, index) => outside(one, selection, `${where}[${index}]`));
|
|
63
|
+
if (!isObject(value))
|
|
64
|
+
return [];
|
|
65
|
+
return Object.entries(value).flatMap(([name, inner]) => {
|
|
66
|
+
const asked = selection[name];
|
|
67
|
+
if (asked === undefined)
|
|
68
|
+
return [`${where}.${name}: not selected`];
|
|
69
|
+
return asked === true ? [] : outside(inner, asked, `${where}.${name}`);
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
/** A value of the type with only the selected fields. */
|
|
73
|
+
const sampleWithin = (node, selection, definitions) => {
|
|
74
|
+
if (selection === true)
|
|
75
|
+
return sampleOf(node, definitions);
|
|
76
|
+
if (node.type === "ref") {
|
|
77
|
+
const target = definitions[identifier(node.ref)];
|
|
78
|
+
return target ? sampleWithin(target, selection, definitions) : null;
|
|
79
|
+
}
|
|
80
|
+
if (node.type === "array")
|
|
81
|
+
return [sampleWithin(node.items, selection, definitions)];
|
|
82
|
+
const shape = shapeOf(node, definitions);
|
|
83
|
+
const objects = shape.kind === "object" ? shape.objects : [];
|
|
84
|
+
return Object.fromEntries(Object.entries(selection).map(([name, inner]) => [
|
|
85
|
+
name,
|
|
86
|
+
name === "__typename"
|
|
87
|
+
? "Object"
|
|
88
|
+
: sampleWithin(objects.map((one) => one.properties[name]).find(Boolean) ?? { type: "unknown" }, inner, definitions),
|
|
89
|
+
]));
|
|
90
|
+
};
|
|
91
|
+
const json = (status, body, headers = {}) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json", ...headers } });
|
|
92
|
+
/** The selection inside a document built for `binding`, or `undefined` when it was not built so. */
|
|
93
|
+
const selectionIn = (binding, query) => {
|
|
94
|
+
const marker = "\u0000";
|
|
95
|
+
const [head = "", tail = ""] = graphqlDocument(binding, marker).split(marker);
|
|
96
|
+
if (query === graphqlDocument(binding, ""))
|
|
97
|
+
return "";
|
|
98
|
+
if (!query.startsWith(head) || !query.endsWith(tail) || query.length < head.length + tail.length)
|
|
99
|
+
return undefined;
|
|
100
|
+
return query.slice(head.length, query.length - tail.length);
|
|
101
|
+
};
|
|
102
|
+
export const graphqlFake = (options) => {
|
|
103
|
+
const calls = [];
|
|
104
|
+
const refusals = [];
|
|
105
|
+
const { definitions } = options;
|
|
106
|
+
const endpoint = new URL(options.url).href;
|
|
107
|
+
const refuse = (status, problems) => {
|
|
108
|
+
for (const problem of problems)
|
|
109
|
+
refusals.push(problem);
|
|
110
|
+
return json(status, { errors: problems.map((message) => ({ message, extensions: { code: "FAKE_REFUSED" } })) });
|
|
111
|
+
};
|
|
112
|
+
const graphql = options.operations.filter((one) => one.binding.kind === "graphql");
|
|
113
|
+
const fetch = async (input, init) => {
|
|
114
|
+
const request = new Request(input, init);
|
|
115
|
+
let body;
|
|
116
|
+
try {
|
|
117
|
+
body = JSON.parse(await request.text());
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
body = undefined;
|
|
121
|
+
}
|
|
122
|
+
const query = isObject(body) && typeof body.query === "string" ? body.query : "";
|
|
123
|
+
const variables = isObject(body) && isObject(body.variables) ? body.variables : {};
|
|
124
|
+
const call = { query, variables, headers: request.headers };
|
|
125
|
+
calls.push(call);
|
|
126
|
+
if (request.url !== endpoint)
|
|
127
|
+
return refuse(404, [`${request.url} is not ${endpoint}`]);
|
|
128
|
+
if (request.method !== "POST")
|
|
129
|
+
return refuse(405, [`a GraphQL call is a POST, not ${request.method}`]);
|
|
130
|
+
if (!query)
|
|
131
|
+
return refuse(400, ["the body is not JSON with a query"]);
|
|
132
|
+
if (options.auth && request.headers.get(options.auth.header) !== options.auth.value)
|
|
133
|
+
return refuse(401, [`no ${options.auth.header} header with the expected sign-in`]);
|
|
134
|
+
const found = graphql
|
|
135
|
+
.map((operation) => ({ operation, text: selectionIn(operation.binding, query) }))
|
|
136
|
+
.find((one) => one.text !== undefined);
|
|
137
|
+
if (!found)
|
|
138
|
+
return refuse(400, [`no operation of the manifest builds the document: ${query.slice(0, 120)}`]);
|
|
139
|
+
const { operation } = found;
|
|
140
|
+
call.operation = operation.id;
|
|
141
|
+
const response = operation.response?.schema ? definitions[operation.response.schema] : undefined;
|
|
142
|
+
let selection = {};
|
|
143
|
+
const parseProblems = [];
|
|
144
|
+
try {
|
|
145
|
+
selection = parseSelection(found.text ?? "");
|
|
146
|
+
call.selection = selection;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
parseProblems.push(`${operation.id}: ${error.message}`);
|
|
150
|
+
}
|
|
151
|
+
const variablesSchema = operation.request?.schema ? definitions[operation.request.schema] : undefined;
|
|
152
|
+
const problems = [
|
|
153
|
+
...parseProblems,
|
|
154
|
+
...(response && found.text ? selectionProblems(selection, response, definitions, operation.id) : []),
|
|
155
|
+
...(response && !found.text && shapeOf(response, definitions).kind !== "leaf"
|
|
156
|
+
? [`${operation.id}: an object needs a selection`]
|
|
157
|
+
: []),
|
|
158
|
+
...(variablesSchema
|
|
159
|
+
? schemaProblems(variables, variablesSchema, definitions, "variables")
|
|
160
|
+
: Object.keys(variables).map((name) => `${operation.id}: takes no argument "${name}"`)),
|
|
161
|
+
];
|
|
162
|
+
if (problems.length > 0)
|
|
163
|
+
return refuse(400, problems);
|
|
164
|
+
const answering = options.answers?.[operation.id];
|
|
165
|
+
if (!answering) {
|
|
166
|
+
const data = response
|
|
167
|
+
? found.text
|
|
168
|
+
? sampleWithin(response, selection, definitions)
|
|
169
|
+
: sampleOf(response, definitions)
|
|
170
|
+
: null;
|
|
171
|
+
return json(200, { data: { [operation.binding.field]: data } });
|
|
172
|
+
}
|
|
173
|
+
const { status = 200, data, errors, headers } = await answering(call);
|
|
174
|
+
if (errors?.length)
|
|
175
|
+
return json(status, { data: null, errors }, headers);
|
|
176
|
+
if (status >= 200 && status < 300 && response && data !== undefined) {
|
|
177
|
+
const wrong = [
|
|
178
|
+
...schemaProblems(data, response, definitions, "answer"),
|
|
179
|
+
...(found.text ? outside(data, selection, "answer") : []),
|
|
180
|
+
];
|
|
181
|
+
if (wrong.length > 0)
|
|
182
|
+
throw new Error(`the answer for ${operation.id} breaks its schema or selection: ${wrong.join("; ")}`);
|
|
183
|
+
}
|
|
184
|
+
return json(status, { data: { [operation.binding.field]: data ?? null } }, headers);
|
|
185
|
+
};
|
|
186
|
+
return { fetch, calls, refusals };
|
|
187
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ApiModel, GraphqlBinding, SchemaNode } from "./model.js";
|
|
2
|
+
export interface GraphqlOptions {
|
|
3
|
+
/** The endpoint every operation is sent to: `https://api.linear.app/graphql`. */
|
|
4
|
+
url: string;
|
|
5
|
+
/**
|
|
6
|
+
* The schema's own scalars, each as the JSON value it travels as: `{ DateTime: { type: "string" }, JSON: { type:
|
|
7
|
+
* "unknown" } }`. A scalar the schema uses that is not here stops generation: its shape is never guessed.
|
|
8
|
+
*/
|
|
9
|
+
scalars?: Readonly<Record<string, SchemaNode>>;
|
|
10
|
+
/**
|
|
11
|
+
* Fields of `Query` or `Mutation` left out, each with the reason: by name, or as `query.<name>` or `mutation.<name>`
|
|
12
|
+
* when both roots have one of that name. One that matches no field stops generation.
|
|
13
|
+
*/
|
|
14
|
+
exclude?: Readonly<Record<string, string>>;
|
|
15
|
+
sourceUrl?: string;
|
|
16
|
+
sourceRevision?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const GRAPHQL_DELETE_REASON = "a mutation whose name ends in Delete or Archive deletes";
|
|
19
|
+
/** Builds the one document an operation sends: every variable declared and passed, the selection inside. */
|
|
20
|
+
export declare const graphqlDocument: (binding: GraphqlBinding, selection?: string) => string;
|
|
21
|
+
/** A selection as a tree: a field's name → its own selection, or `true` for a leaf. */
|
|
22
|
+
export interface Selection {
|
|
23
|
+
readonly [field: string]: Selection | true;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* `id title state { id type }` → its tree. Only names and braces: an argument, an alias, a fragment or a directive
|
|
27
|
+
* throws, since nothing here can check one.
|
|
28
|
+
*/
|
|
29
|
+
export declare const parseSelection: (text: string) => Selection;
|
|
30
|
+
export declare const adaptGraphql: (introspection: unknown, options: GraphqlOptions) => ApiModel;
|
|
31
|
+
/** The standard introspection query, deep enough for `[[Type!]!]!`. */
|
|
32
|
+
export declare const INTROSPECTION_QUERY = "query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n types {\n kind name description\n fields(includeDeprecated: true) { name description isDeprecated args { ...InputValue } type { ...TypeRef } }\n inputFields { ...InputValue }\n enumValues(includeDeprecated: true) { name }\n possibleTypes { name }\n }\n }\n}\nfragment InputValue on __InputValue { name description defaultValue type { ...TypeRef } }\nfragment TypeRef on __Type {\n kind name\n ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } }\n}";
|
|
33
|
+
export interface GraphqlProvenance {
|
|
34
|
+
source: string;
|
|
35
|
+
/** Of the committed file; `readGraphql` refuses a snapshot that no longer matches it. */
|
|
36
|
+
sha256: string;
|
|
37
|
+
retrieved_at: string;
|
|
38
|
+
normalization: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Asks `url` for its schema and writes `schema.json` and `provenance.json` to `dir`. Run by hand, then review the diff:
|
|
42
|
+
* the build never fetches. Types are sorted by name so a reordered answer is no diff. `headers` is for a service that
|
|
43
|
+
* answers introspection only when signed in; nothing of them is written.
|
|
44
|
+
*/
|
|
45
|
+
export declare const syncGraphql: (options: {
|
|
46
|
+
url: string;
|
|
47
|
+
dir: string;
|
|
48
|
+
fetch?: typeof globalThis.fetch;
|
|
49
|
+
headers?: Readonly<Record<string, string>>;
|
|
50
|
+
now?: Date;
|
|
51
|
+
}) => Promise<GraphqlProvenance>;
|
|
52
|
+
/** The snapshot `syncGraphql` wrote, parsed. Throws if its hash changed. */
|
|
53
|
+
export declare const readGraphql: (dir: string) => unknown;
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A GraphQL schema's introspection result, already parsed → the format-neutral `ApiModel`, plus the offline snapshot
|
|
3
|
+
* it comes from: `syncGraphql` asks the endpoint for its schema with the standard introspection query and records
|
|
4
|
+
* where it came from, and `readGraphql` loads it back only while its hash still matches.
|
|
5
|
+
*
|
|
6
|
+
* One field of `Query` or `Mutation` is one operation. Its arguments are the request body (the variables), each also a
|
|
7
|
+
* flag; its answer is `data.<field>`, typed by the field's type. A query reads; a mutation writes, and one whose name
|
|
8
|
+
* ends in `Delete` or `Archive` deletes. A Relay connection pages as a `cursor`: `after`, `pageInfo.endCursor`.
|
|
9
|
+
* SDL is not read: that needs graphql-js, and codegen adds no runtime dependency.
|
|
10
|
+
*/
|
|
11
|
+
import { createHash } from "node:crypto";
|
|
12
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { CodegenError } from "./pipeline.js";
|
|
15
|
+
const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
16
|
+
const BUILT_IN = {
|
|
17
|
+
String: { type: "string" },
|
|
18
|
+
ID: { type: "string" },
|
|
19
|
+
Int: { type: "integer", format: "int32" },
|
|
20
|
+
Float: { type: "number" },
|
|
21
|
+
Boolean: { type: "boolean" },
|
|
22
|
+
};
|
|
23
|
+
const DELETES = /(Delete|Archive)$/;
|
|
24
|
+
const UNDOES = /Unarchive$/;
|
|
25
|
+
export const GRAPHQL_DELETE_REASON = "a mutation whose name ends in Delete or Archive deletes";
|
|
26
|
+
/** `[ID!]!` from its introspection reference. */
|
|
27
|
+
const typeText = (ref) => ref.kind === "NON_NULL" && ref.ofType
|
|
28
|
+
? `${typeText(ref.ofType)}!`
|
|
29
|
+
: ref.kind === "LIST" && ref.ofType
|
|
30
|
+
? `[${typeText(ref.ofType)}]`
|
|
31
|
+
: String(ref.name);
|
|
32
|
+
const named = (ref) => (ref.ofType ? named(ref.ofType) : String(ref.name));
|
|
33
|
+
/** Builds the one document an operation sends: every variable declared and passed, the selection inside. */
|
|
34
|
+
export const graphqlDocument = (binding, selection = binding.selection) => {
|
|
35
|
+
const variables = Object.entries(binding.variables);
|
|
36
|
+
const declared = variables.length ? `(${variables.map(([name, type]) => `$${name}: ${type}`).join(", ")})` : "";
|
|
37
|
+
const passed = variables.length ? `(${variables.map(([name]) => `${name}: $${name}`).join(", ")})` : "";
|
|
38
|
+
const inner = selection.trim() ? ` { ${selection.trim()} }` : "";
|
|
39
|
+
return `${binding.operation} ${binding.field[0]?.toUpperCase()}${binding.field.slice(1)}${declared} { ${binding.field}${passed}${inner} }`;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* `id title state { id type }` → its tree. Only names and braces: an argument, an alias, a fragment or a directive
|
|
43
|
+
* throws, since nothing here can check one.
|
|
44
|
+
*/
|
|
45
|
+
export const parseSelection = (text) => {
|
|
46
|
+
const tokens = text.match(/[_A-Za-z][_0-9A-Za-z]*|[{}]|\S/g) ?? [];
|
|
47
|
+
let at = 0;
|
|
48
|
+
const level = (nested) => {
|
|
49
|
+
const fields = {};
|
|
50
|
+
while (at < tokens.length) {
|
|
51
|
+
const token = tokens[at];
|
|
52
|
+
if (token === "}") {
|
|
53
|
+
if (!nested)
|
|
54
|
+
throw new Error(`selection "${text}": an unmatched }`);
|
|
55
|
+
at += 1;
|
|
56
|
+
return fields;
|
|
57
|
+
}
|
|
58
|
+
if (!/^[_A-Za-z]/.test(token))
|
|
59
|
+
throw new Error(`selection "${text}": "${token}" — only field names and braces are supported`);
|
|
60
|
+
at += 1;
|
|
61
|
+
if (tokens[at] === "{") {
|
|
62
|
+
at += 1;
|
|
63
|
+
const inner = level(true);
|
|
64
|
+
if (Object.keys(inner).length === 0)
|
|
65
|
+
throw new Error(`selection "${text}": ${token} selects nothing`);
|
|
66
|
+
fields[token] = inner;
|
|
67
|
+
}
|
|
68
|
+
else
|
|
69
|
+
fields[token] = true;
|
|
70
|
+
}
|
|
71
|
+
if (nested)
|
|
72
|
+
throw new Error(`selection "${text}": a { is not closed`);
|
|
73
|
+
return fields;
|
|
74
|
+
};
|
|
75
|
+
return level(false);
|
|
76
|
+
};
|
|
77
|
+
const schemaOf = (raw) => {
|
|
78
|
+
const root = object(raw) && object(raw.data) ? raw.data : raw;
|
|
79
|
+
if (!object(root) || !object(root.__schema))
|
|
80
|
+
throw new CodegenError(["not a GraphQL introspection result: no __schema"]);
|
|
81
|
+
return root.__schema;
|
|
82
|
+
};
|
|
83
|
+
export const adaptGraphql = (introspection, options) => {
|
|
84
|
+
const schema = schemaOf(introspection);
|
|
85
|
+
const types = new Map();
|
|
86
|
+
for (const type of Array.isArray(schema.types) ? schema.types : [])
|
|
87
|
+
if (object(type) && typeof type.name === "string" && !type.name.startsWith("__"))
|
|
88
|
+
types.set(type.name, type);
|
|
89
|
+
const rootName = (key) => {
|
|
90
|
+
const root = schema[key];
|
|
91
|
+
return object(root) && typeof root.name === "string" ? root.name : undefined;
|
|
92
|
+
};
|
|
93
|
+
const scalars = { ...BUILT_IN, ...options.scalars };
|
|
94
|
+
const unknownScalars = [...types.values()]
|
|
95
|
+
.filter((type) => type.kind === "SCALAR" && !scalars[type.name])
|
|
96
|
+
.map((type) => `scalar ${type.name}: map it in scalars, as the JSON value it travels as`);
|
|
97
|
+
if (unknownScalars.length > 0)
|
|
98
|
+
throw new CodegenError(unknownScalars);
|
|
99
|
+
const described = (text) => (text ? { description: text } : {});
|
|
100
|
+
const reference = (ref, where) => {
|
|
101
|
+
if (ref.kind === "NON_NULL" && ref.ofType) {
|
|
102
|
+
const { nullable: _, ...inner } = reference(ref.ofType, where);
|
|
103
|
+
return inner;
|
|
104
|
+
}
|
|
105
|
+
if (ref.kind === "LIST" && ref.ofType)
|
|
106
|
+
return { type: "array", items: reference(ref.ofType, where), nullable: true };
|
|
107
|
+
const name = String(ref.name);
|
|
108
|
+
const type = types.get(name);
|
|
109
|
+
if (!type)
|
|
110
|
+
throw new CodegenError([`${where}: the schema has no type ${name}`]);
|
|
111
|
+
if (type.kind === "SCALAR")
|
|
112
|
+
return { ...scalars[name], nullable: true };
|
|
113
|
+
return { type: "ref", ref: name, nullable: true };
|
|
114
|
+
};
|
|
115
|
+
const schemas = [];
|
|
116
|
+
for (const type of types.values()) {
|
|
117
|
+
const where = `type ${type.name}`;
|
|
118
|
+
const common = described(type.description);
|
|
119
|
+
switch (type.kind) {
|
|
120
|
+
case "SCALAR":
|
|
121
|
+
break;
|
|
122
|
+
case "ENUM":
|
|
123
|
+
schemas.push({
|
|
124
|
+
id: type.name,
|
|
125
|
+
schema: { ...common, type: "string", enum: (type.enumValues ?? []).map((one) => one.name) },
|
|
126
|
+
});
|
|
127
|
+
break;
|
|
128
|
+
case "OBJECT":
|
|
129
|
+
case "INTERFACE":
|
|
130
|
+
// A selection asks for some of the fields, so none is required in an answer.
|
|
131
|
+
schemas.push({
|
|
132
|
+
id: type.name,
|
|
133
|
+
schema: {
|
|
134
|
+
...common,
|
|
135
|
+
type: "object",
|
|
136
|
+
properties: Object.fromEntries((type.fields ?? []).map((field) => [
|
|
137
|
+
field.name,
|
|
138
|
+
{ ...reference(field.type, `${where}.${field.name}`), ...described(field.description) },
|
|
139
|
+
])),
|
|
140
|
+
required: [],
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
break;
|
|
144
|
+
case "UNION":
|
|
145
|
+
schemas.push({
|
|
146
|
+
id: type.name,
|
|
147
|
+
schema: {
|
|
148
|
+
...common,
|
|
149
|
+
type: "union",
|
|
150
|
+
of: (type.possibleTypes ?? []).map((one) => ({ type: "ref", ref: one.name })),
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
break;
|
|
154
|
+
case "INPUT_OBJECT":
|
|
155
|
+
schemas.push({ id: type.name, schema: { ...common, ...inputObject(type.inputFields ?? [], where) } });
|
|
156
|
+
break;
|
|
157
|
+
default:
|
|
158
|
+
throw new CodegenError([`${where}: unsupported kind ${type.kind}`]);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function inputObject(values, where) {
|
|
162
|
+
return {
|
|
163
|
+
type: "object",
|
|
164
|
+
properties: Object.fromEntries(values.map((one) => [
|
|
165
|
+
one.name,
|
|
166
|
+
{ ...reference(one.type, `${where}.${one.name}`), ...described(one.description) },
|
|
167
|
+
])),
|
|
168
|
+
required: values.filter((one) => one.type.kind === "NON_NULL" && one.defaultValue == null).map((one) => one.name),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const fieldsOf = (name) => {
|
|
172
|
+
const type = types.get(name);
|
|
173
|
+
return type && (type.kind === "OBJECT" || type.kind === "INTERFACE") ? (type.fields ?? []) : undefined;
|
|
174
|
+
};
|
|
175
|
+
const selectable = (field) => !field.isDeprecated && !field.args.some((one) => one.type.kind === "NON_NULL" && one.defaultValue == null);
|
|
176
|
+
const isLeaf = (name) => {
|
|
177
|
+
const kind = types.get(name)?.kind;
|
|
178
|
+
return kind === "SCALAR" || kind === "ENUM";
|
|
179
|
+
};
|
|
180
|
+
/** Scalars, and `{ id }` of each object that has one; a type with neither gives `__typename`. */
|
|
181
|
+
const oneLevel = (name) => {
|
|
182
|
+
const parts = (fieldsOf(name) ?? []).filter(selectable).flatMap((field) => {
|
|
183
|
+
const inner = named(field.type);
|
|
184
|
+
if (isLeaf(inner))
|
|
185
|
+
return [field.name];
|
|
186
|
+
return fieldsOf(inner)?.some((one) => one.name === "id") ? [`${field.name} { id }`] : [];
|
|
187
|
+
});
|
|
188
|
+
return parts.length > 0 ? parts.join(" ") : "__typename";
|
|
189
|
+
};
|
|
190
|
+
/** A Relay connection: `nodes` of one type, and a `pageInfo` with `hasNextPage` and `endCursor`. */
|
|
191
|
+
const connectionOf = (name) => {
|
|
192
|
+
const fields = fieldsOf(name);
|
|
193
|
+
const nodes = fields?.find((one) => one.name === "nodes");
|
|
194
|
+
const pageInfo = fields?.find((one) => one.name === "pageInfo");
|
|
195
|
+
const info = pageInfo && fieldsOf(named(pageInfo.type));
|
|
196
|
+
if (!nodes || !info || !["hasNextPage", "endCursor"].every((key) => info.some((one) => one.name === key)))
|
|
197
|
+
return undefined;
|
|
198
|
+
return named(nodes.type);
|
|
199
|
+
};
|
|
200
|
+
const selectionOf = (name) => {
|
|
201
|
+
if (isLeaf(name))
|
|
202
|
+
return "";
|
|
203
|
+
if (types.get(name)?.kind === "UNION")
|
|
204
|
+
return "__typename";
|
|
205
|
+
const node = connectionOf(name);
|
|
206
|
+
return node ? `nodes { ${oneLevel(node)} } pageInfo { hasNextPage endCursor }` : oneLevel(name);
|
|
207
|
+
};
|
|
208
|
+
// An answer that is only a reference is named after its type, which would drop a nullable field's null: such an
|
|
209
|
+
// answer is wrapped, so it gets a name of its own that keeps it.
|
|
210
|
+
const answerOf = (node) => node.type === "ref" && node.nullable
|
|
211
|
+
? { type: "allOf", of: [{ type: "ref", ref: node.ref }], nullable: true }
|
|
212
|
+
: node;
|
|
213
|
+
const exclude = options.exclude ?? {};
|
|
214
|
+
const excluded = new Set();
|
|
215
|
+
const operations = [];
|
|
216
|
+
for (const [key, operation] of [
|
|
217
|
+
["queryType", "query"],
|
|
218
|
+
["mutationType", "mutation"],
|
|
219
|
+
]) {
|
|
220
|
+
const root = rootName(key);
|
|
221
|
+
if (!root)
|
|
222
|
+
continue;
|
|
223
|
+
for (const field of fieldsOf(root) ?? []) {
|
|
224
|
+
const scoped = `${operation}.${field.name}`;
|
|
225
|
+
const left = [scoped, field.name].find((name) => exclude[name] !== undefined);
|
|
226
|
+
if (left !== undefined) {
|
|
227
|
+
excluded.add(left);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const where = `${root}.${field.name}`;
|
|
231
|
+
const argument = (one) => ({
|
|
232
|
+
...reference(one.type, `${where}(${one.name})`),
|
|
233
|
+
...described(one.description),
|
|
234
|
+
});
|
|
235
|
+
const required = field.args.filter((one) => one.type.kind === "NON_NULL" && one.defaultValue == null);
|
|
236
|
+
const answer = named(field.type);
|
|
237
|
+
const binding = {
|
|
238
|
+
kind: "graphql",
|
|
239
|
+
operation,
|
|
240
|
+
field: field.name,
|
|
241
|
+
// A non-null argument with a default may be left out; declared non-null, its variable could not be.
|
|
242
|
+
variables: Object.fromEntries(field.args.map((one) => [
|
|
243
|
+
one.name,
|
|
244
|
+
one.defaultValue != null && one.type.kind === "NON_NULL" && one.type.ofType
|
|
245
|
+
? typeText(one.type.ofType)
|
|
246
|
+
: typeText(one.type),
|
|
247
|
+
])),
|
|
248
|
+
selection: selectionOf(answer),
|
|
249
|
+
};
|
|
250
|
+
const deletes = operation === "mutation" && DELETES.test(field.name) && !UNDOES.test(field.name);
|
|
251
|
+
const has = (name, type) => field.args.some((one) => one.name === name && one.type.kind !== "NON_NULL" && named(one.type) === type);
|
|
252
|
+
const pages = operation === "query" && field.type.kind !== "LIST" && connectionOf(answer) && has("after", "String");
|
|
253
|
+
const pagination = pages
|
|
254
|
+
? {
|
|
255
|
+
style: "cursor",
|
|
256
|
+
cursor: { in: "body", name: "after" },
|
|
257
|
+
next: "pageInfo.endCursor",
|
|
258
|
+
items: "nodes",
|
|
259
|
+
hasMore: "pageInfo.hasNextPage",
|
|
260
|
+
...(has("first", "Int") ? { limit: { in: "body", name: "first" } } : {}),
|
|
261
|
+
}
|
|
262
|
+
: undefined;
|
|
263
|
+
const summary = field.description?.split("\n")[0];
|
|
264
|
+
operations.push({
|
|
265
|
+
id: field.name,
|
|
266
|
+
binding,
|
|
267
|
+
...(summary ? { summary } : {}),
|
|
268
|
+
...described(field.description),
|
|
269
|
+
tags: [operation],
|
|
270
|
+
parameters: field.args.map((one) => ({
|
|
271
|
+
name: one.name,
|
|
272
|
+
in: "body",
|
|
273
|
+
required: required.includes(one),
|
|
274
|
+
...described(one.description),
|
|
275
|
+
schema: argument(one),
|
|
276
|
+
})),
|
|
277
|
+
...(field.args.length > 0
|
|
278
|
+
? {
|
|
279
|
+
requestBody: {
|
|
280
|
+
confidence: "contract",
|
|
281
|
+
required: required.length > 0,
|
|
282
|
+
schema: inputObject(field.args, where),
|
|
283
|
+
},
|
|
284
|
+
}
|
|
285
|
+
: {}),
|
|
286
|
+
response: { confidence: "contract", required: false, schema: answerOf(reference(field.type, where)) },
|
|
287
|
+
effect: operation === "query" ? "read" : deletes ? "destructive" : "write",
|
|
288
|
+
...(deletes ? { effectReason: GRAPHQL_DELETE_REASON } : {}),
|
|
289
|
+
...(pagination ? { pagination, paginationSource: "detected" } : {}),
|
|
290
|
+
...(field.isDeprecated ? { deprecated: true } : {}),
|
|
291
|
+
source: { location: where },
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const stale = Object.keys(exclude).filter((name) => !excluded.has(name));
|
|
296
|
+
if (stale.length > 0)
|
|
297
|
+
throw new CodegenError(stale.map((name) => `exclusion "${name}" matches no field of Query or Mutation`));
|
|
298
|
+
return {
|
|
299
|
+
source: {
|
|
300
|
+
kind: "other",
|
|
301
|
+
sourceUrl: options.sourceUrl ?? options.url,
|
|
302
|
+
...(options.sourceRevision !== undefined ? { sourceRevision: options.sourceRevision } : {}),
|
|
303
|
+
},
|
|
304
|
+
operations: operations.sort((a, b) => a.id.localeCompare(b.id)),
|
|
305
|
+
schemas,
|
|
306
|
+
servers: [{ url: options.url }],
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
/** The standard introspection query, deep enough for `[[Type!]!]!`. */
|
|
310
|
+
export const INTROSPECTION_QUERY = `query IntrospectionQuery {
|
|
311
|
+
__schema {
|
|
312
|
+
queryType { name }
|
|
313
|
+
mutationType { name }
|
|
314
|
+
types {
|
|
315
|
+
kind name description
|
|
316
|
+
fields(includeDeprecated: true) { name description isDeprecated args { ...InputValue } type { ...TypeRef } }
|
|
317
|
+
inputFields { ...InputValue }
|
|
318
|
+
enumValues(includeDeprecated: true) { name }
|
|
319
|
+
possibleTypes { name }
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
fragment InputValue on __InputValue { name description defaultValue type { ...TypeRef } }
|
|
324
|
+
fragment TypeRef on __Type {
|
|
325
|
+
kind name
|
|
326
|
+
ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } }
|
|
327
|
+
}`;
|
|
328
|
+
const FILE = "schema.json";
|
|
329
|
+
const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
330
|
+
const sortKeys = (value) => Array.isArray(value)
|
|
331
|
+
? value.map(sortKeys)
|
|
332
|
+
: object(value)
|
|
333
|
+
? Object.fromEntries(Object.keys(value)
|
|
334
|
+
.sort()
|
|
335
|
+
.map((key) => [key, sortKeys(value[key])]))
|
|
336
|
+
: value;
|
|
337
|
+
const byName = (list) => Array.isArray(list)
|
|
338
|
+
? [...list].sort((a, b) => String(a?.name).localeCompare(String(b?.name)))
|
|
339
|
+
: list;
|
|
340
|
+
/**
|
|
341
|
+
* Asks `url` for its schema and writes `schema.json` and `provenance.json` to `dir`. Run by hand, then review the diff:
|
|
342
|
+
* the build never fetches. Types are sorted by name so a reordered answer is no diff. `headers` is for a service that
|
|
343
|
+
* answers introspection only when signed in; nothing of them is written.
|
|
344
|
+
*/
|
|
345
|
+
export const syncGraphql = async (options) => {
|
|
346
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
347
|
+
const response = await fetch(options.url, {
|
|
348
|
+
method: "POST",
|
|
349
|
+
headers: { "content-type": "application/json", ...options.headers },
|
|
350
|
+
body: JSON.stringify({ query: INTROSPECTION_QUERY }),
|
|
351
|
+
signal: AbortSignal.timeout(30_000),
|
|
352
|
+
redirect: "error",
|
|
353
|
+
});
|
|
354
|
+
if (!response.ok)
|
|
355
|
+
throw new Error(`GraphQL introspection failed: HTTP ${response.status}`);
|
|
356
|
+
const answer = await response.json();
|
|
357
|
+
if (object(answer) && Array.isArray(answer.errors) && answer.errors.length > 0)
|
|
358
|
+
throw new Error("GraphQL introspection failed: the service answered errors[]; it may need a sign-in");
|
|
359
|
+
const schema = schemaOf(answer);
|
|
360
|
+
const written = `${JSON.stringify(sortKeys({ __schema: { ...schema, types: byName(schema.types) } }), null, 2)}\n`;
|
|
361
|
+
const provenance = {
|
|
362
|
+
source: options.url,
|
|
363
|
+
sha256: sha256(written),
|
|
364
|
+
retrieved_at: (options.now ?? new Date()).toISOString(),
|
|
365
|
+
normalization: "types sorted by name, object keys sorted, 2-space JSON",
|
|
366
|
+
};
|
|
367
|
+
mkdirSync(options.dir, { recursive: true });
|
|
368
|
+
writeFileSync(join(options.dir, FILE), written);
|
|
369
|
+
writeFileSync(join(options.dir, "provenance.json"), `${JSON.stringify(provenance, null, 2)}\n`);
|
|
370
|
+
return provenance;
|
|
371
|
+
};
|
|
372
|
+
/** The snapshot `syncGraphql` wrote, parsed. Throws if its hash changed. */
|
|
373
|
+
export const readGraphql = (dir) => {
|
|
374
|
+
const provenance = JSON.parse(readFileSync(join(dir, "provenance.json"), "utf8"));
|
|
375
|
+
const raw = readFileSync(join(dir, FILE));
|
|
376
|
+
if (sha256(raw) !== provenance.sha256)
|
|
377
|
+
throw new CodegenError([`GraphQL schema hash mismatch: ${join(dir, FILE)}`]);
|
|
378
|
+
return JSON.parse(raw.toString("utf8"));
|
|
379
|
+
};
|
package/dist/codegen/index.d.ts
CHANGED
|
@@ -3,18 +3,20 @@
|
|
|
3
3
|
* manifest and a coverage page. Build-time, apart from the small helpers a CLI reads the generated
|
|
4
4
|
* files with (`identifier`, `requestSchema`), and format-neutral: it parses no file format and
|
|
5
5
|
* adds no runtime dependency. `adaptOpenApi` reads an OpenAPI document and `adaptDiscovery` Google Discovery
|
|
6
|
-
* documents the consumer has parsed; `upgradeToOpenApi3` brings Swagger 1.2 and 2.0 to OpenAPI 3 through two optional
|
|
6
|
+
* documents the consumer has parsed, and `adaptGraphql` a GraphQL introspection result; `upgradeToOpenApi3` brings Swagger 1.2 and 2.0 to OpenAPI 3 through two optional
|
|
7
7
|
* peer dependencies. `fakeApi` serves the generated manifest as a strict fake for a CLI's tests, and `signInRequirements` with
|
|
8
8
|
* `signInPlace` say which sign-in a call needs and where its token goes. An adapter from
|
|
9
9
|
* Postman or anything else lives in the consumer.
|
|
10
10
|
*/
|
|
11
11
|
export { adaptDiscovery, type DiscoveryMetadata, type DiscoveryOptions, type DiscoveryProvenance, type DiscoveryResult, type DiscoveryService, readDiscovery, type SyncDiscoveryOptions, syncDiscovery, } from "./discovery.js";
|
|
12
12
|
export { type FakeAnswer, type FakeApi, type FakeApiOptions, type FakeCall, fakeApi, sampleOf, schemaProblems, } from "./fake.js";
|
|
13
|
+
export { adaptGraphql, GRAPHQL_DELETE_REASON, type GraphqlOptions, type GraphqlProvenance, graphqlDocument, INTROSPECTION_QUERY, parseSelection, readGraphql, type Selection, syncGraphql, } from "./graphql.js";
|
|
14
|
+
export { type GraphqlFake, type GraphqlFakeAnswer, type GraphqlFakeCall, type GraphqlFakeOptions, graphqlFake, selectionProblems, } from "./graphql-fake.js";
|
|
13
15
|
export { requestSchema } from "./json-schema.js";
|
|
14
16
|
export { type CoverageOptions, coverageGenerator, definitionsGenerator, examplesGenerator, type ManifestOperation, manifestGenerator, } from "./manifest.js";
|
|
15
17
|
export { type MergedSource, type MergeOptions, type MergeReport, mergeOpenApi, type SpecSource } from "./merge.js";
|
|
16
|
-
export type { ApiBody, ApiModel, ApiOperation, ApiParameter, ApiSchema, ApiServer, Binding, CodeGenerator, Confidence, Discriminator, Effect, GeneratedArtifact, HttpBinding, HttpMethod, OAuthFlow, OperationPermission, Override, PageParameter, Pagination, RpcBinding, SchemaNode, SecurityRequirement, SecurityScheme, SourceInfo, SourceReference, } from "./model.js";
|
|
17
|
-
export { identifier, kebab } from "./names.js";
|
|
18
|
+
export type { ApiBody, ApiModel, ApiOperation, ApiParameter, ApiSchema, ApiServer, Binding, CodeGenerator, Confidence, Discriminator, Effect, GeneratedArtifact, GraphqlBinding, HttpBinding, HttpMethod, OAuthFlow, OperationPermission, Override, PageParameter, Pagination, RpcBinding, SchemaNode, SecurityRequirement, SecurityScheme, SourceInfo, SourceReference, } from "./model.js";
|
|
19
|
+
export { bindingLabel, identifier, kebab } from "./names.js";
|
|
18
20
|
export { adaptOpenApi, OpenApiError } from "./openapi.js";
|
|
19
21
|
export { detectPagination } from "./pagination.js";
|
|
20
22
|
export { type PatchedSpec, type PatchSpecOptions, patchSpec, type SpecPatch } from "./patch.js";
|
package/dist/codegen/index.js
CHANGED
|
@@ -3,17 +3,19 @@
|
|
|
3
3
|
* manifest and a coverage page. Build-time, apart from the small helpers a CLI reads the generated
|
|
4
4
|
* files with (`identifier`, `requestSchema`), and format-neutral: it parses no file format and
|
|
5
5
|
* adds no runtime dependency. `adaptOpenApi` reads an OpenAPI document and `adaptDiscovery` Google Discovery
|
|
6
|
-
* documents the consumer has parsed; `upgradeToOpenApi3` brings Swagger 1.2 and 2.0 to OpenAPI 3 through two optional
|
|
6
|
+
* documents the consumer has parsed, and `adaptGraphql` a GraphQL introspection result; `upgradeToOpenApi3` brings Swagger 1.2 and 2.0 to OpenAPI 3 through two optional
|
|
7
7
|
* peer dependencies. `fakeApi` serves the generated manifest as a strict fake for a CLI's tests, and `signInRequirements` with
|
|
8
8
|
* `signInPlace` say which sign-in a call needs and where its token goes. An adapter from
|
|
9
9
|
* Postman or anything else lives in the consumer.
|
|
10
10
|
*/
|
|
11
11
|
export { adaptDiscovery, readDiscovery, syncDiscovery, } from "./discovery.js";
|
|
12
12
|
export { fakeApi, sampleOf, schemaProblems, } from "./fake.js";
|
|
13
|
+
export { adaptGraphql, GRAPHQL_DELETE_REASON, graphqlDocument, INTROSPECTION_QUERY, parseSelection, readGraphql, syncGraphql, } from "./graphql.js";
|
|
14
|
+
export { graphqlFake, selectionProblems, } from "./graphql-fake.js";
|
|
13
15
|
export { requestSchema } from "./json-schema.js";
|
|
14
16
|
export { coverageGenerator, definitionsGenerator, examplesGenerator, manifestGenerator, } from "./manifest.js";
|
|
15
17
|
export { mergeOpenApi } from "./merge.js";
|
|
16
|
-
export { identifier, kebab } from "./names.js";
|
|
18
|
+
export { bindingLabel, identifier, kebab } from "./names.js";
|
|
17
19
|
export { adaptOpenApi, OpenApiError } from "./openapi.js";
|
|
18
20
|
export { detectPagination } from "./pagination.js";
|
|
19
21
|
export { patchSpec } from "./patch.js";
|
package/dist/codegen/manifest.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { kebab } from "./names.js";
|
|
1
|
+
import { bindingLabel, kebab } from "./names.js";
|
|
2
2
|
import { isLossless } from "./runtime.js";
|
|
3
3
|
import { SchemaTree } from "./tree.js";
|
|
4
4
|
const withoutUndefined = (value) => Object.fromEntries(Object.entries(value).filter(([, field]) => field !== undefined));
|
|
@@ -119,7 +119,7 @@ export const coverageGenerator = (options) => (model) => {
|
|
|
119
119
|
const tree = new SchemaTree(model);
|
|
120
120
|
const rows = model.operations.map((operation) => {
|
|
121
121
|
const entry = toManifest(operation, tree);
|
|
122
|
-
const binding = entry.binding
|
|
122
|
+
const binding = bindingLabel(entry.binding);
|
|
123
123
|
const status = entry.deprecated ? "deprecated" : "generated";
|
|
124
124
|
return `| \`${entry.id}\` | \`${binding}\` | \`${options.command(entry)}\` | ${entry.effect} | ${entry.request?.confidence ?? "—"} | ${status} | ${cell(entry.summary)} |`;
|
|
125
125
|
});
|
package/dist/codegen/model.d.ts
CHANGED
|
@@ -22,7 +22,20 @@ export interface RpcBinding {
|
|
|
22
22
|
kind: "rpc";
|
|
23
23
|
name: string;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* One field of a GraphQL schema's `Query` or `Mutation`. The request is one document, built by `graphqlDocument` from
|
|
27
|
+
* the field, its variables' GraphQL types and a selection; the answer is `data.<field>`.
|
|
28
|
+
*/
|
|
29
|
+
export interface GraphqlBinding {
|
|
30
|
+
kind: "graphql";
|
|
31
|
+
operation: "query" | "mutation";
|
|
32
|
+
field: string;
|
|
33
|
+
/** Each argument's GraphQL type as written in the schema: `{ id: "String!", filter: "IssueFilter" }`. */
|
|
34
|
+
variables: Readonly<Record<string, string>>;
|
|
35
|
+
/** The default selection: scalars, and `{ id }` of each object, one level deep; a connection's `nodes` and `pageInfo`. */
|
|
36
|
+
selection: string;
|
|
37
|
+
}
|
|
38
|
+
export type Binding = HttpBinding | RpcBinding | GraphqlBinding;
|
|
26
39
|
interface SchemaCommon {
|
|
27
40
|
sensitive?: boolean;
|
|
28
41
|
description?: string;
|
package/dist/codegen/names.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { Binding } from "./model.js";
|
|
1
2
|
export declare const identifier: (id: string) => string;
|
|
2
3
|
/** `getMyInfo` → `get-my-info`. */
|
|
3
4
|
export declare const kebab: (id: string) => string;
|
|
5
|
+
/** How a reader names the call: `GET /pages/{id}`, `sendMessage`, `query issues`. */
|
|
6
|
+
export declare const bindingLabel: (binding: Binding) => string;
|
package/dist/codegen/names.js
CHANGED
|
@@ -43,3 +43,9 @@ export const kebab = (id) => id
|
|
|
43
43
|
.replace(/[^A-Za-z0-9]+/g, "-")
|
|
44
44
|
.replace(/^-|-$/g, "")
|
|
45
45
|
.toLowerCase();
|
|
46
|
+
/** How a reader names the call: `GET /pages/{id}`, `sendMessage`, `query issues`. */
|
|
47
|
+
export const bindingLabel = (binding) => binding.kind === "http"
|
|
48
|
+
? `${binding.method} ${binding.path}`
|
|
49
|
+
: binding.kind === "rpc"
|
|
50
|
+
? binding.name
|
|
51
|
+
: `${binding.operation} ${binding.field}`;
|
package/dist/codegen/pipeline.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, extname, join, posix } from "node:path";
|
|
3
|
-
import { identifier, kebab } from "./names.js";
|
|
3
|
+
import { bindingLabel, identifier, kebab } from "./names.js";
|
|
4
4
|
import { answerPaths, detectPagination, requestParameters } from "./pagination.js";
|
|
5
|
+
import { signInRequirements } from "./sign-in.js";
|
|
5
6
|
export class CodegenError extends Error {
|
|
6
7
|
problems;
|
|
7
8
|
constructor(problems) {
|
|
@@ -198,15 +199,15 @@ const applyAuth = (model, auth) => {
|
|
|
198
199
|
securitySchemes: auth.securitySchemes,
|
|
199
200
|
security: auth.security,
|
|
200
201
|
securityReason: auth.reason,
|
|
201
|
-
//
|
|
202
|
-
|
|
202
|
+
// `[]` is replaced too: `auth` says the source's sign-in is wrong, and a key sent to a public call is ignored while
|
|
203
|
+
// a key left off a private one always fails.
|
|
204
|
+
operations: model.operations.map(({ security, ...operation }) => signInRequirements({ security }, undefined) &&
|
|
205
|
+
security?.every((requirement) => Object.keys(requirement).every((name) => names.has(name)))
|
|
203
206
|
? { ...operation, security }
|
|
204
207
|
: operation),
|
|
205
208
|
};
|
|
206
209
|
};
|
|
207
|
-
const bindingKey = (operation) => operation.binding.kind === "
|
|
208
|
-
? `${operation.binding.method} ${operation.binding.path}`
|
|
209
|
-
: `rpc ${operation.binding.name}`;
|
|
210
|
+
const bindingKey = (operation) => operation.binding.kind === "rpc" ? `rpc ${operation.binding.name}` : bindingLabel(operation.binding);
|
|
210
211
|
const duplicates = (values) => [...new Set(values.filter((value, index) => values.indexOf(value) !== index))].sort();
|
|
211
212
|
const refsIn = (node, found = []) => {
|
|
212
213
|
switch (node.type) {
|
package/dist/codegen/skill.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { flatten } from "../commands/registry.js";
|
|
2
|
-
import { kebab } from "./names.js";
|
|
2
|
+
import { bindingLabel, kebab } from "./names.js";
|
|
3
3
|
import { CodegenError } from "./pipeline.js";
|
|
4
4
|
export const API_SKILL_INDEX = "references/api.md";
|
|
5
5
|
export const API_SKILL_GROUPS = "references/api";
|
|
@@ -38,7 +38,7 @@ const pages = (pagination) => {
|
|
|
38
38
|
};
|
|
39
39
|
const flagRow = (option) => `| ${code(option.flags, true)} | ${option.mandatory ? "yes" : "no"} | ${text(option.description)} |`;
|
|
40
40
|
const section = (operation, command) => {
|
|
41
|
-
const call = operation.binding
|
|
41
|
+
const call = bindingLabel(operation.binding);
|
|
42
42
|
const scopes = (operation.security ?? []).map((requirement) => Object.entries(requirement)
|
|
43
43
|
.map(([scheme, list]) => (list.length > 0 ? `${scheme} (${list.join(", ")})` : scheme))
|
|
44
44
|
.join(" and "));
|
package/dist/dev/audit.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface Finding {
|
|
|
28
28
|
message: string;
|
|
29
29
|
/** What each CLI showed, for a finding about one flag or output; `absent` when it lacks the flag. */
|
|
30
30
|
values?: Record<string, string>;
|
|
31
|
+
/** The CLIs that show the same thing, one list per variant, for a rule that compares whole values. */
|
|
32
|
+
variants?: string[][];
|
|
31
33
|
}
|
|
32
34
|
export interface ScoreRow {
|
|
33
35
|
cli: string;
|
|
@@ -51,6 +53,16 @@ export interface AuditOptions {
|
|
|
51
53
|
blocks: "new" | "never";
|
|
52
54
|
/** Only new findings that name this CLI block: the one being released. */
|
|
53
55
|
only?: string;
|
|
56
|
+
/**
|
|
57
|
+
* `--family`: `only` is the one local build, every other CLI its latest published version. A schema `only` shares with
|
|
58
|
+
* one of them is then not `only`'s to fix.
|
|
59
|
+
*/
|
|
60
|
+
family?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* cli-base's entity and reason differences, for groups that are not cli-base's own: they name no CLI list, so they
|
|
63
|
+
* hold in any group, and count against none.
|
|
64
|
+
*/
|
|
65
|
+
shared?: ParityGroup["differences"];
|
|
54
66
|
}
|
|
55
67
|
export interface AuditResult {
|
|
56
68
|
findings: Finding[];
|
|
@@ -68,3 +80,10 @@ export declare const clisOf: (target: string) => string[];
|
|
|
68
80
|
export declare const auditClis: (inputs: readonly AuditInput[], options: AuditOptions, rules?: readonly AuditRule[]) => AuditResult;
|
|
69
81
|
/** One line per CLI and rule that found something, then one total per CLI. */
|
|
70
82
|
export declare const scorecardTable: (rows: readonly ScoreRow[]) => string;
|
|
83
|
+
/**
|
|
84
|
+
* The shared differences a groups file does not declare itself. Past their review_after they only warn there
|
|
85
|
+
* (`sharedReviews`): only cli-base can renew them, and its own weekly audit fails on them.
|
|
86
|
+
*/
|
|
87
|
+
export declare const sharedDifferences: (declared: ParityGroup["differences"]) => ParityGroup["differences"];
|
|
88
|
+
/** The review warnings of the shared differences, due or overdue: never a failure outside cli-base's own audit. */
|
|
89
|
+
export declare const sharedReviews: (shared: ParityGroup["differences"], today: string) => string[];
|
package/dist/dev/audit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AUDIT_RULES } from "../standards/audit.js";
|
|
1
|
+
import { AUDIT_RULES, SHARED_DIFFERENCES, } from "../standards/audit.js";
|
|
2
2
|
import { BASE_REASONS } from "../standards/errors.js";
|
|
3
|
-
import { LINT_RULES, OVERRIDE_BUDGET } from "../standards/lint.js";
|
|
3
|
+
import { LINT_RULES, OVERRIDE_BUDGET, overdue, overridesDueSoon } from "../standards/lint.js";
|
|
4
4
|
import { capabilityDifference } from "./capabilities.js";
|
|
5
5
|
import { judge, kindOf, lintCommands, longName, registeredKinds, summaryOf, walk } from "./lint.js";
|
|
6
6
|
import { sharedContractProblems } from "./shared-contracts.js";
|
|
@@ -174,6 +174,7 @@ const sameEntitySchema = (inputs) => {
|
|
|
174
174
|
clis,
|
|
175
175
|
target: `${named(clis)} entity ${entity}`,
|
|
176
176
|
message: `${groups.length} different schemas: ${groups.map((one) => one.join(", ")).join(" / ")}`,
|
|
177
|
+
variants: groups,
|
|
177
178
|
},
|
|
178
179
|
];
|
|
179
180
|
});
|
|
@@ -278,7 +279,8 @@ export const auditClis = (inputs, options, rules = AUDIT_RULES) => {
|
|
|
278
279
|
.map((finding) => `${finding.rule} ${finding.target}`));
|
|
279
280
|
// An `absent` or `only` difference names no CLI list: it stands for every finding where only that CLI lacks the
|
|
280
281
|
// flag, or only that CLI has it.
|
|
281
|
-
const
|
|
282
|
+
const sharedGroup = { name: "cli-base", differences: options.shared ?? [] };
|
|
283
|
+
const differences = [...options.groups, sharedGroup].flatMap((group) => group.differences.flatMap((entry) => {
|
|
282
284
|
// Which CLIs share an entity or a reason changes with each release, so the entry names only what differs, and
|
|
283
285
|
// its review_after, not a stale check, retires it.
|
|
284
286
|
if (UNLISTED_RULES.has(entry.rule))
|
|
@@ -399,11 +401,18 @@ export const auditClis = (inputs, options, rules = AUDIT_RULES) => {
|
|
|
399
401
|
return {
|
|
400
402
|
findings,
|
|
401
403
|
rows,
|
|
402
|
-
blocking: [...unique.values()].filter((finding) => options.only === undefined ||
|
|
404
|
+
blocking: [...unique.values()].filter((finding) => options.only === undefined ||
|
|
405
|
+
(finding.clis.includes(options.only) && !(options.family && sharedWithAnother(finding, options.only)))),
|
|
403
406
|
nextBaseline,
|
|
404
407
|
problems,
|
|
405
408
|
};
|
|
406
409
|
};
|
|
410
|
+
/**
|
|
411
|
+
* The CLI being released shows what a published CLI shows: the published ones already disagree among themselves, as
|
|
412
|
+
* when some are on an older cli-core, so the divergence is not this CLI's to fix and does not block its release. It
|
|
413
|
+
* cannot tell ahead from behind: a CLI that keeps an older schema a lagging CLI still prints passes too.
|
|
414
|
+
*/
|
|
415
|
+
const sharedWithAnother = (finding, cli) => (finding.variants?.find((variant) => variant.includes(cli))?.length ?? 0) > 1;
|
|
407
416
|
const pad = (cells, widths) => cells
|
|
408
417
|
.map((cell, index) => (index < 2 ? cell.padEnd(widths[index] ?? 0) : cell.padStart(widths[index] ?? 0)))
|
|
409
418
|
.join(" ");
|
|
@@ -423,3 +432,13 @@ export const scorecardTable = (rows) => {
|
|
|
423
432
|
const widths = header.map((_, index) => Math.max(...lines.map((line) => line[index]?.length ?? 0)));
|
|
424
433
|
return lines.map((line) => pad(line, widths).trimEnd()).join("\n");
|
|
425
434
|
};
|
|
435
|
+
/**
|
|
436
|
+
* The shared differences a groups file does not declare itself. Past their review_after they only warn there
|
|
437
|
+
* (`sharedReviews`): only cli-base can renew them, and its own weekly audit fails on them.
|
|
438
|
+
*/
|
|
439
|
+
export const sharedDifferences = (declared) => SHARED_DIFFERENCES.filter((entry) => !declared.some((own) => own.rule === entry.rule && own.target === entry.target));
|
|
440
|
+
/** The review warnings of the shared differences, due or overdue: never a failure outside cli-base's own audit. */
|
|
441
|
+
export const sharedReviews = (shared, today) => [
|
|
442
|
+
...overridesDueSoon(shared, today, "cli-base's audit"),
|
|
443
|
+
...overdue(shared, today),
|
|
444
|
+
];
|
package/dist/dev/main.js
CHANGED
|
@@ -21,7 +21,7 @@ import { issuesOf, RegistryError } from "../standards/registry.js";
|
|
|
21
21
|
import { VOCABULARY } from "../standards/vocabulary.js";
|
|
22
22
|
import { buildManifest, MANIFEST_FILE, ManifestError, manifestText } from "../wcat/manifest.js";
|
|
23
23
|
import { adopt } from "./adopt.js";
|
|
24
|
-
import { auditClis, scorecardTable, snakeKeys } from "./audit.js";
|
|
24
|
+
import { auditClis, scorecardTable, sharedDifferences, sharedReviews, snakeKeys } from "./audit.js";
|
|
25
25
|
import { readCapabilities } from "./capabilities.js";
|
|
26
26
|
import { CONFORMANCE_USAGE, conformanceCommand } from "./conformance.js";
|
|
27
27
|
import { familyPackages, installFamily } from "./family.js";
|
|
@@ -91,14 +91,15 @@ const USAGE = `usage: cli-dev <command> [options]
|
|
|
91
91
|
Prints the scorecard; fails on a new finding (one naming
|
|
92
92
|
--for's CLI, when given). --lint judges that CLI's lint
|
|
93
93
|
rules by its own lint/ folder; the rest by --baseline
|
|
94
|
-
(audit/baseline). --groups replaces PARITY_GROUPS
|
|
95
|
-
|
|
96
|
-
to the groups in use. --family takes this
|
|
97
|
-
installs the latest published CLIs of the
|
|
98
|
-
it (npm, without install scripts), runs
|
|
99
|
-
reads every CLI's commands info (so
|
|
100
|
-
same-entity-schema are measured), and
|
|
101
|
-
CLI, --lint to its lint/ and --groups to
|
|
94
|
+
(audit/baseline). --groups replaces PARITY_GROUPS (not its
|
|
95
|
+
entity and reason differences) with the groups in that file;
|
|
96
|
+
--differences adds to the groups in use. --family takes this
|
|
97
|
+
CLI's one --cli and installs the latest published CLIs of the
|
|
98
|
+
parity groups beside it (npm, without install scripts), runs
|
|
99
|
+
each in an empty home, reads every CLI's commands info (so
|
|
100
|
+
same-error-reason and same-entity-schema are measured), and
|
|
101
|
+
defaults --for to this CLI, --lint to its lint/ and --groups to
|
|
102
|
+
config/parity-groups.json
|
|
102
103
|
bundle --bin <dist/bin/name.js> [--external <package>]... [--anchor <package>]... [--harmless <path>]...
|
|
103
104
|
bundles the compiled bin with esbuild (a devDependency) into
|
|
104
105
|
dist/bundle/ and turns the bin into its loader. --external keeps
|
|
@@ -826,18 +827,22 @@ const auditRun = (args, io, family = false) => {
|
|
|
826
827
|
})));
|
|
827
828
|
}
|
|
828
829
|
const differences = groups.flatMap((group) => group.differences);
|
|
830
|
+
const shared = values.groups ? sharedDifferences(differences) : [];
|
|
829
831
|
for (const line of overdue(differences, today(io)))
|
|
830
832
|
problems.push(`parity difference: ${line}`);
|
|
831
|
-
|
|
833
|
+
const due = [...overridesDueSoon(differences, today(io), "the audit"), ...sharedReviews(shared, today(io))];
|
|
834
|
+
for (const line of due)
|
|
832
835
|
io.err(`warning parity difference: ${line}`);
|
|
833
836
|
const result = auditClis(inputs, {
|
|
834
837
|
...(values.capabilities ? { capabilities: readCapabilities(readJson(at(values.capabilities))) } : {}),
|
|
835
838
|
groups,
|
|
839
|
+
shared,
|
|
836
840
|
roots: REQUIRED_ROOTS,
|
|
837
841
|
vocabulary: VOCABULARY,
|
|
838
842
|
baseline,
|
|
839
843
|
blocks: AUDIT_BLOCKS,
|
|
840
844
|
only: values.for,
|
|
845
|
+
family,
|
|
841
846
|
});
|
|
842
847
|
problems.push(...result.problems);
|
|
843
848
|
if (values["write-baseline"]) {
|
|
@@ -42,6 +42,20 @@ declare const parityGroupSchema: v.StrictObjectSchema<{
|
|
|
42
42
|
export type ParityGroup = v.InferOutput<typeof parityGroupSchema>;
|
|
43
43
|
export declare const defineParityGroups: (input: unknown) => ParityGroup[];
|
|
44
44
|
export declare const PARITY_GROUPS: ParityGroup[];
|
|
45
|
+
/**
|
|
46
|
+
* The declared entity and reason differences: they name no CLI list, so they hold in any group, and an audit by a CLI's
|
|
47
|
+
* own groups file keeps them.
|
|
48
|
+
*/
|
|
49
|
+
export declare const SHARED_DIFFERENCES: {
|
|
50
|
+
rule: string;
|
|
51
|
+
target: string;
|
|
52
|
+
expected?: string | undefined;
|
|
53
|
+
absent?: string | undefined;
|
|
54
|
+
only?: string | undefined;
|
|
55
|
+
differs?: string | undefined;
|
|
56
|
+
reason: string;
|
|
57
|
+
review_after?: string | undefined;
|
|
58
|
+
}[];
|
|
45
59
|
declare const requiredRootSchema: v.StrictObjectSchema<{
|
|
46
60
|
readonly path: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a command word">]>, undefined>, v.MinLengthAction<string[], 1, undefined>]>;
|
|
47
61
|
readonly meaning: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "must not be empty">]>;
|
package/dist/standards/audit.js
CHANGED
|
@@ -158,28 +158,46 @@ export const PARITY_GROUPS = defineParityGroups([
|
|
|
158
158
|
},
|
|
159
159
|
// bitrix24-cli's search is cli-core's CRM `search all`, and beeline-cli's and asterisk-cli's meetings take call
|
|
160
160
|
// recordings, not zoom-cli's: they are compared on the root commands every CLI shares, the way gcal and mail are.
|
|
161
|
-
// amo-cli
|
|
161
|
+
// amo-cli and hubspot-cli share them too, and their CRM commands are compared with b24 in `crm` below.
|
|
162
162
|
// notion-cli joins here until its documents commands ship; then it moves next to drive.
|
|
163
163
|
{
|
|
164
164
|
name: "shared-roots",
|
|
165
|
-
members: ["tg", "max", "memo", "drive", "zm", "wa", "b24", "beeline", "pbx", "notion", "amo"],
|
|
165
|
+
members: ["tg", "max", "memo", "drive", "zm", "wa", "b24", "beeline", "pbx", "notion", "amo", "hubspot"],
|
|
166
166
|
covers: ["commands", "doctor", "skill", "mcp", "upgrade"],
|
|
167
167
|
differences: [...MEMO_HAS_NO_PROFILES, ...MEMO_MCP_SUMMARIES, MEMO_DOCTOR_DEEP],
|
|
168
168
|
},
|
|
169
|
-
// The CRM CLIs on cli-core's shared CRM commands. amo-cli (amoCRM and Kommo) is not on npm yet
|
|
170
|
-
//
|
|
171
|
-
// later) and `deals delete` (amoCRM's
|
|
172
|
-
// https://www.amocrm.ru/developers/content/crm_platform/leads-api)
|
|
173
|
-
// these need no difference. `people`, `organizations`,
|
|
174
|
-
// is on cli-core's shared people and organizations
|
|
175
|
-
// in options, outputs and summaries.
|
|
169
|
+
// The CRM CLIs on cli-core's shared CRM commands. amo-cli (amoCRM and Kommo) is not on npm yet and hubspot-cli is
|
|
170
|
+
// not in the family packages, so `audit --family` skips them, as beeline. Only b24 and hubspot have `leads` (amoCRM
|
|
171
|
+
// has no lead apart from a deal), only b24 has `products` (amo leaves them for later) and `deals delete` (amoCRM's
|
|
172
|
+
// API v4 cannot delete a lead, https://www.amocrm.ru/developers/content/crm_platform/leads-api), and hubspot writes
|
|
173
|
+
// no deals yet; a list of roots does not compare presence, so these need no difference. `people`, `organizations`,
|
|
174
|
+
// `users`, `api` and `session` join once b24's released tree is on cli-core's shared people and organizations
|
|
175
|
+
// commands: measured against b24 0.23.0 on 2026-11-16 they differ in options, outputs and summaries.
|
|
176
176
|
{
|
|
177
177
|
name: "crm",
|
|
178
|
-
members: ["b24", "amo"],
|
|
178
|
+
members: ["b24", "amo", "hubspot"],
|
|
179
179
|
covers: ["deals", "sync", "search", "store", "schedule", "account"],
|
|
180
|
-
differences: [
|
|
180
|
+
differences: [
|
|
181
|
+
{
|
|
182
|
+
rule: "same-path-contract",
|
|
183
|
+
target: "schedule: summary",
|
|
184
|
+
differs: "hubspot",
|
|
185
|
+
reason: "cli-core cuts the summary to a fixed width after it puts in the CLI's name " +
|
|
186
|
+
"(src/cli/help/commands-text.ts), so hubspot's longer name ends it a word earlier than b24's and amo's",
|
|
187
|
+
review_after: "2026-12-01",
|
|
188
|
+
},
|
|
189
|
+
],
|
|
181
190
|
},
|
|
182
191
|
]);
|
|
192
|
+
/**
|
|
193
|
+
* The declared entity and reason differences: they name no CLI list, so they hold in any group, and an audit by a CLI's
|
|
194
|
+
* own groups file keeps them.
|
|
195
|
+
*/
|
|
196
|
+
export const SHARED_DIFFERENCES = [
|
|
197
|
+
...new Map(PARITY_GROUPS.flatMap((group) => group.differences)
|
|
198
|
+
.filter((entry) => entry.rule === "same-entity-schema" || entry.rule === "same-error-reason")
|
|
199
|
+
.map((entry) => [`${entry.rule} ${entry.target}`, entry])).values(),
|
|
200
|
+
];
|
|
183
201
|
const requiredRootSchema = v.strictObject({ path: v.pipe(v.array(segment), v.minLength(1)), meaning: text });
|
|
184
202
|
export const defineRequiredRoots = (input) => parseRegistry("required roots", v.array(requiredRootSchema), input, (roots) => duplicates(roots.map((root) => root.path.join(" "))).map((path) => `"${path}" is listed twice`));
|
|
185
203
|
export const REQUIRED_ROOTS = defineRequiredRoots([
|
package/docs/standards/ci.md
CHANGED
|
@@ -47,6 +47,7 @@ what it cannot do yet.
|
|
|
47
47
|
| Swagger 2.0 | `adaptOpenApi(await upgradeToOpenApi3(document))` |
|
|
48
48
|
| Swagger 1.2 (Yandex Disk) | `upgradeToOpenApi3(listing, declarations)`: the resource listing, and each API declaration keyed by its `apis[].path`, fetched from the listing's `basePath` followed by that path |
|
|
49
49
|
| Google Discovery | `adaptDiscovery(readDiscovery(dir))`, snapshots written by `syncDiscovery` |
|
|
50
|
+
| GraphQL (Linear) | `adaptGraphql(readGraphql(dir), { url, scalars })`, the introspection result written by `syncGraphql` |
|
|
50
51
|
|
|
51
52
|
`upgradeToOpenApi3` converts with [swagger-converter](https://github.com/apigee-127/swagger-converter) (1.2 → 2.0) and
|
|
52
53
|
[@scalar/openapi-upgrader](https://github.com/scalar/scalar/tree/main/packages/openapi-upgrader) (2.0 → 3.0). They are
|
|
@@ -87,8 +88,9 @@ From the source the generator reads:
|
|
|
87
88
|
- **Effect**: GET and HEAD read, POST, PUT and PATCH write, DELETE is destructive.
|
|
88
89
|
- **Servers and sign-in**: `servers` (each URL once, as written), `components/securitySchemes` and `security` go into
|
|
89
90
|
the manifest as `servers`, `securitySchemes` and `security`, and an operation's own `security` (`[]` for one that
|
|
90
|
-
needs no sign-in) onto that operation. A CLI then does not copy its base URL or
|
|
91
|
-
only when the source has them. A requirement naming a scheme the document lacks
|
|
91
|
+
needs no sign-in, unless `auth` below replaces it) onto that operation. A CLI then does not copy its base URL or
|
|
92
|
+
OAuth endpoints by hand. They appear only when the source has them. A requirement naming a scheme the document lacks
|
|
93
|
+
stops generation.
|
|
92
94
|
|
|
93
95
|
### Corrections a CLI passes to `generate`
|
|
94
96
|
|
|
@@ -126,7 +128,9 @@ From the source the generator reads:
|
|
|
126
128
|
parameter the operation does not take stops generation.
|
|
127
129
|
- **`auth`**: `{ securitySchemes, security, reason }` replaces the source's sign-in, the operations' own requirements
|
|
128
130
|
included. Yandex Disk's Swagger 1.2 has no scheme, and its header is `Authorization: OAuth <token>`:
|
|
129
|
-
`{ oauth: { type: "http", scheme: "OAuth" } }`. HubSpot's spec has no private app token.
|
|
131
|
+
`{ oauth: { type: "http", scheme: "OAuth" } }`. HubSpot's spec has no private app token. An operation keeps its own
|
|
132
|
+
`security` only when it signs in by `auth`'s schemes. One the source marks as needing no sign-in (`[]`) gets `auth`
|
|
133
|
+
as well: HubSpot's object specs mark 115 calls that way, and each answered 401 without the key.
|
|
130
134
|
|
|
131
135
|
### A strict fake for tests
|
|
132
136
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.115.0",
|
|
4
4
|
"description": "The parts every command line tool needs: output modes, terminal rendering, error model, exit codes, credentials, clocks",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|