@wirecat/cli-base 0.117.0 → 0.118.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 +21 -0
- package/dist/codegen/discovery.js +1 -10
- package/dist/codegen/graphql.js +1 -9
- package/dist/codegen/index.d.ts +2 -1
- package/dist/codegen/index.js +2 -1
- package/dist/codegen/manifest.js +6 -2
- package/dist/codegen/model.d.ts +9 -1
- package/dist/codegen/pipeline.d.ts +12 -0
- package/dist/codegen/pipeline.js +47 -4
- package/dist/codegen/snapshot.d.ts +4 -0
- package/dist/codegen/snapshot.js +11 -0
- package/dist/codegen/wp-json.d.ts +49 -0
- package/dist/codegen/wp-json.js +333 -0
- package/docs/standards/kit-surface.md +9 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,27 @@ 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.118.0 — 18.11.2026
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **A WordPress API from the site's own index: `syncWpJson`, `readWpJson` and `wpJsonToOpenApi`.** WordPress has no
|
|
16
|
+
OpenAPI, but `/wp-json/?context=help` lists every route with its arguments and the schema of its answer.
|
|
17
|
+
`syncWpJson` keeps that one answer, without the site's name, address and links, with its provenance;
|
|
18
|
+
`wpJsonToOpenApi` turns the routes of the namespaces a CLI offers into OpenAPI 3.1 for `adaptOpenApi`. WordPress
|
|
19
|
+
6.9.4's `wp/v2` gives 152 operations (`getWpV2Posts`, `postWpV2PostsById`…). A route whose value may hold a slash
|
|
20
|
+
(templates, plugins, fonts) is left out and listed in `omissions`. Watch for: an array argument in the query is
|
|
21
|
+
one comma-separated string, as WordPress splits it and PHP keeps only the last of a repeated name, so it loses
|
|
22
|
+
its `enum`; WordPress's lists
|
|
23
|
+
page by headers, so `pagination: true` finds no paging for them yet.
|
|
24
|
+
- **A permission key from a field's value: `permissions.valueKeys`.** `{ key: "publish", field: "status", values:
|
|
25
|
+
["publish", "future"] }` gives `posts.publish` to a write that sends `status: "publish"`, in the body or the query,
|
|
26
|
+
so a profile that denies publishing also stops the raw `api` group. Where the field defaults to such a value
|
|
27
|
+
(WordPress's templates, template parts and menu items), the key applies on every call, as leaving the field out
|
|
28
|
+
publishes. `OperationPermission.values` carries it in the manifest, and the coverage page's "When" says `` `status` is publish or future ``. Watch for: cli-core checks
|
|
29
|
+
`values` only from the release that reads them; an older cli-core asks for the key on every call of that operation,
|
|
30
|
+
as it does for a key with no flags.
|
|
31
|
+
|
|
11
32
|
## 0.117.0 — 18.11.2026
|
|
12
33
|
|
|
13
34
|
### Added
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* Strict like `adaptOpenApi`: an unknown schema keyword, format or parameter location stops generation.
|
|
7
7
|
* Effects come from the HTTP verb; a method the verb misjudges is corrected with `generate`'s `overrides`.
|
|
8
8
|
*/
|
|
9
|
-
import { createHash } from "node:crypto";
|
|
10
9
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
11
10
|
import { join } from "node:path";
|
|
12
11
|
import { CodegenError } from "./pipeline.js";
|
|
12
|
+
import { sha256, sortKeys } from "./snapshot.js";
|
|
13
13
|
const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
14
14
|
/** Discovery links point at developers.google.com without the host, which breaks them in generated Markdown. */
|
|
15
15
|
const description = (value) => String(value ?? "").replace(/\]\((\/workspace\/[^)]+)\)/g, "](https://developers.google.com$1)");
|
|
@@ -249,15 +249,6 @@ export const adaptDiscovery = (documents, options = {}) => {
|
|
|
249
249
|
services,
|
|
250
250
|
};
|
|
251
251
|
};
|
|
252
|
-
const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
253
|
-
/** Google serves the same revision with its keys in a different order each time; arrays keep theirs. */
|
|
254
|
-
const sortKeys = (value) => Array.isArray(value)
|
|
255
|
-
? value.map(sortKeys)
|
|
256
|
-
: object(value)
|
|
257
|
-
? Object.fromEntries(Object.keys(value)
|
|
258
|
-
.sort()
|
|
259
|
-
.map((key) => [key, sortKeys(value[key])]))
|
|
260
|
-
: value;
|
|
261
252
|
const NORMALIZATION = "object keys sorted, 2-space JSON; values and array order unchanged";
|
|
262
253
|
/**
|
|
263
254
|
* Downloads each Discovery document, sorts its object keys so the same revision always gives the same file, and
|
package/dist/codegen/graphql.js
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* ends in `Delete` or `Archive` deletes. A Relay connection pages as a `cursor`: `after`, `pageInfo.endCursor`.
|
|
9
9
|
* SDL is not read: that needs graphql-js, and codegen adds no runtime dependency.
|
|
10
10
|
*/
|
|
11
|
-
import { createHash } from "node:crypto";
|
|
12
11
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
12
|
import { join } from "node:path";
|
|
14
13
|
import { CodegenError } from "./pipeline.js";
|
|
14
|
+
import { sha256, sortKeys } from "./snapshot.js";
|
|
15
15
|
const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
16
16
|
const BUILT_IN = {
|
|
17
17
|
String: { type: "string" },
|
|
@@ -326,14 +326,6 @@ fragment TypeRef on __Type {
|
|
|
326
326
|
ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } }
|
|
327
327
|
}`;
|
|
328
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
329
|
const byName = (list) => Array.isArray(list)
|
|
338
330
|
? [...list].sort((a, b) => String(a?.name).localeCompare(String(b?.name)))
|
|
339
331
|
: list;
|
package/dist/codegen/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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, and `adaptGraphql` a GraphQL introspection result; `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; `wpJsonToOpenApi` turns WordPress's REST index into OpenAPI; `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 (Basic included). An adapter from
|
|
9
9
|
* Postman or anything else lives in the consumer.
|
|
@@ -26,3 +26,4 @@ export { API_SKILL_GROUPS, API_SKILL_INDEX, type ApiSkillOptions, apiSkillFiles
|
|
|
26
26
|
export { upgradeToOpenApi3 } from "./swagger.js";
|
|
27
27
|
export { typesGenerator } from "./typescript.js";
|
|
28
28
|
export { type ValibotOptions, valibotGenerator } from "./valibot.js";
|
|
29
|
+
export { readWpJson, syncWpJson, type WpJsonOptions, type WpJsonProvenance, type WpJsonResult, wpJsonToOpenApi, } from "./wp-json.js";
|
package/dist/codegen/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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, and `adaptGraphql` a GraphQL introspection result; `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; `wpJsonToOpenApi` turns WordPress's REST index into OpenAPI; `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 (Basic included). An adapter from
|
|
9
9
|
* Postman or anything else lives in the consumer.
|
|
@@ -25,3 +25,4 @@ export { API_SKILL_GROUPS, API_SKILL_INDEX, apiSkillFiles } from "./skill.js";
|
|
|
25
25
|
export { upgradeToOpenApi3 } from "./swagger.js";
|
|
26
26
|
export { typesGenerator } from "./typescript.js";
|
|
27
27
|
export { valibotGenerator } from "./valibot.js";
|
|
28
|
+
export { readWpJson, syncWpJson, wpJsonToOpenApi, } from "./wp-json.js";
|
package/dist/codegen/manifest.js
CHANGED
|
@@ -127,7 +127,11 @@ export const coverageGenerator = (options) => (model) => {
|
|
|
127
127
|
const reasoned = model.operations.filter((operation) => operation.effectReason);
|
|
128
128
|
const paged = model.operations.filter((operation) => operation.pagination);
|
|
129
129
|
const guarded = model.operations.flatMap((operation) => (operation.permissions ?? []).map((permission) => ({ id: operation.id, permission })));
|
|
130
|
-
const when = ({ body, query }) => [
|
|
130
|
+
const when = ({ body, query, values }) => [
|
|
131
|
+
...(body ?? []).map((flag) => `body \`${flag}\` is true`),
|
|
132
|
+
...(query ?? []).map((flag) => `query \`${flag}\` is true`),
|
|
133
|
+
...Object.entries(values ?? {}).map(([field, listed]) => `\`${field}\` is ${listed.join(" or ")}`),
|
|
134
|
+
].join(" or ");
|
|
131
135
|
const content = [
|
|
132
136
|
`# ${options.title}`,
|
|
133
137
|
"",
|
|
@@ -181,7 +185,7 @@ export const coverageGenerator = (options) => (model) => {
|
|
|
181
185
|
"|---|---|---|",
|
|
182
186
|
...guarded.map(({ id, permission }) => {
|
|
183
187
|
const flags = when(permission);
|
|
184
|
-
return `| \`${id}\` | \`${permission.key}\` | ${flags
|
|
188
|
+
return `| \`${id}\` | \`${permission.key}\` | ${flags || "always"} |`;
|
|
185
189
|
}),
|
|
186
190
|
]
|
|
187
191
|
: []),
|
package/dist/codegen/model.d.ts
CHANGED
|
@@ -190,13 +190,21 @@ export type Pagination = {
|
|
|
190
190
|
next: string;
|
|
191
191
|
items?: string;
|
|
192
192
|
};
|
|
193
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* A key a call must pass: always, or, when `body`, `query` or `values` is given, only when one of those flags is `true`
|
|
195
|
+
* or one of those fields holds one of its values.
|
|
196
|
+
*/
|
|
194
197
|
export interface OperationPermission {
|
|
195
198
|
key: string;
|
|
196
199
|
/** Top-level request body fields. */
|
|
197
200
|
body?: readonly string[];
|
|
198
201
|
/** Query parameters. */
|
|
199
202
|
query?: readonly string[];
|
|
203
|
+
/**
|
|
204
|
+
* A top-level body field or query parameter of this name holding one of these values: `{ status: ["publish"] }`.
|
|
205
|
+
* Both places count, as a service that merges them (WordPress) publishes from either.
|
|
206
|
+
*/
|
|
207
|
+
values?: Readonly<Record<string, readonly string[]>>;
|
|
200
208
|
}
|
|
201
209
|
/** The scheme names an operation needs, each with its OAuth scopes; one requirement of the list is enough. */
|
|
202
210
|
export type SecurityRequirement = Readonly<Record<string, readonly string[]>>;
|
|
@@ -37,6 +37,18 @@ export interface PermissionRule {
|
|
|
37
37
|
deletingFlags?: readonly string[];
|
|
38
38
|
/** Operation ids that make something public, as a share link does: neither a plain write nor a delete. */
|
|
39
39
|
shares?: readonly string[];
|
|
40
|
+
/**
|
|
41
|
+
* A field whose value is the change, not a flag: WordPress publishes by `status: "publish"`. Each gives
|
|
42
|
+
* `<group>.<key>` to every write or delete whose body field or query parameter `field` lists one of `values` in its
|
|
43
|
+
* `enum`, so a field of the same name that means something else (a comment's `status`) gets no key, nor does a read
|
|
44
|
+
* that filters by the value. Where the field's default is one of `values` (a WordPress template), leaving it out
|
|
45
|
+
* publishes too, and the key always applies.
|
|
46
|
+
*/
|
|
47
|
+
valueKeys?: readonly {
|
|
48
|
+
key: string;
|
|
49
|
+
field: string;
|
|
50
|
+
values: readonly string[];
|
|
51
|
+
}[];
|
|
40
52
|
}
|
|
41
53
|
export declare const applyPermissionRule: (model: ApiModel, rule: PermissionRule) => ApiModel;
|
|
42
54
|
/**
|
package/dist/codegen/pipeline.js
CHANGED
|
@@ -135,7 +135,7 @@ export const applyOverrides = (model, overrides) => {
|
|
|
135
135
|
}),
|
|
136
136
|
};
|
|
137
137
|
};
|
|
138
|
-
/** The top-level
|
|
138
|
+
/** The top-level properties a body may carry, through references, inheritance, unions and subtypes. */
|
|
139
139
|
const bodyFields = (node, schemas, seen = new Set()) => {
|
|
140
140
|
switch (node.type) {
|
|
141
141
|
case "ref": {
|
|
@@ -147,7 +147,7 @@ const bodyFields = (node, schemas, seen = new Set()) => {
|
|
|
147
147
|
return [...bodyFields(target.schema, schemas, inner), ...subtypes];
|
|
148
148
|
}
|
|
149
149
|
case "object":
|
|
150
|
-
return Object.
|
|
150
|
+
return Object.entries(node.properties);
|
|
151
151
|
case "union":
|
|
152
152
|
case "allOf":
|
|
153
153
|
return node.of.flatMap((member) => bodyFields(member, schemas, seen));
|
|
@@ -164,9 +164,50 @@ export const applyPermissionRule = (model, rule) => {
|
|
|
164
164
|
const schemas = new Map(model.schemas.map((schema) => [schema.id, schema]));
|
|
165
165
|
const fields = new Map(model.operations.map((operation) => [
|
|
166
166
|
operation.id,
|
|
167
|
-
new
|
|
167
|
+
new Map(operation.requestBody?.schema ? bodyFields(operation.requestBody.schema, schemas) : []),
|
|
168
168
|
]));
|
|
169
|
-
const fieldsOf = (operation) => fields.get(operation.id) ?? new
|
|
169
|
+
const fieldsOf = (operation) => fields.get(operation.id) ?? new Map();
|
|
170
|
+
/** The enums and defaults of a field, through references and every alternative of a union. */
|
|
171
|
+
const valuesIn = (node, seen = new Set()) => {
|
|
172
|
+
if (!node)
|
|
173
|
+
return { enums: [], defaults: [] };
|
|
174
|
+
const own = {
|
|
175
|
+
enums: "enum" in node && node.enum ? [...node.enum] : [],
|
|
176
|
+
defaults: node.default === undefined ? [] : [node.default],
|
|
177
|
+
};
|
|
178
|
+
const inner = node.type === "ref" && !seen.has(node.ref)
|
|
179
|
+
? [valuesIn(schemas.get(node.ref)?.schema, new Set([...seen, node.ref]))]
|
|
180
|
+
: node.type === "union" || node.type === "allOf"
|
|
181
|
+
? node.of.map((member) => valuesIn(member, seen))
|
|
182
|
+
: [];
|
|
183
|
+
return {
|
|
184
|
+
enums: [...own.enums, ...inner.flatMap((one) => one.enums)],
|
|
185
|
+
defaults: [...own.defaults, ...inner.flatMap((one) => one.defaults)],
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
const valuesOf = (operation, name) => {
|
|
189
|
+
const nodes = [
|
|
190
|
+
fieldsOf(operation).get(name),
|
|
191
|
+
operation.parameters.find((parameter) => parameter.in === "query" && parameter.name === name)?.schema,
|
|
192
|
+
].map((node) => valuesIn(node));
|
|
193
|
+
return { enums: nodes.flatMap((one) => one.enums), defaults: nodes.flatMap((one) => one.defaults) };
|
|
194
|
+
};
|
|
195
|
+
const valueKeys = rule.valueKeys ?? [];
|
|
196
|
+
// A field whose default is one of the values publishes when the call leaves it out: the key then always applies.
|
|
197
|
+
const valued = (operation) => operation.effect === "read"
|
|
198
|
+
? []
|
|
199
|
+
: valueKeys.flatMap(({ key, field, values }) => {
|
|
200
|
+
const { enums, defaults } = valuesOf(operation, field);
|
|
201
|
+
const named = values.filter((value) => enums.includes(value));
|
|
202
|
+
if (named.length === 0)
|
|
203
|
+
return [];
|
|
204
|
+
return defaults.some((value) => values.includes(value))
|
|
205
|
+
? [{ key }]
|
|
206
|
+
: [{ key, values: { [field]: named } }];
|
|
207
|
+
});
|
|
208
|
+
const idle = valueKeys.filter(({ key }) => !model.operations.some((operation) => valued(operation).some((one) => one.key === key)));
|
|
209
|
+
if (idle.length > 0)
|
|
210
|
+
throw new CodegenError(idle.map(({ field, values }) => `valueKeys: no write lists ${values.join(" or ")} in the enum of "${field}"`));
|
|
170
211
|
const unused = flags.filter((flag) => !model.operations.some((operation) => fieldsOf(operation).has(flag) ||
|
|
171
212
|
operation.parameters.some((parameter) => parameter.in === "query" && parameter.name === flag)));
|
|
172
213
|
if (unused.length > 0)
|
|
@@ -190,6 +231,8 @@ export const applyPermissionRule = (model, rule) => {
|
|
|
190
231
|
...(query.length > 0 ? { query } : {}),
|
|
191
232
|
});
|
|
192
233
|
}
|
|
234
|
+
for (const permission of valued(operation))
|
|
235
|
+
permissions.push({ ...permission, key: `${group}.${permission.key}` });
|
|
193
236
|
return permissions.length > 0 ? { ...operation, permissions } : operation;
|
|
194
237
|
}),
|
|
195
238
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The hash a snapshot's `provenance.json` keeps, so a hand edit or a changed file stops generation. */
|
|
2
|
+
export declare const sha256: (bytes: string | Buffer) => string;
|
|
3
|
+
/** A service may send the same description with its keys in another order each time; arrays keep theirs. */
|
|
4
|
+
export declare const sortKeys: (value: unknown) => unknown;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
/** The hash a snapshot's `provenance.json` keeps, so a hand edit or a changed file stops generation. */
|
|
3
|
+
export const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
4
|
+
/** A service may send the same description with its keys in another order each time; arrays keep theirs. */
|
|
5
|
+
export const sortKeys = (value) => Array.isArray(value)
|
|
6
|
+
? value.map(sortKeys)
|
|
7
|
+
: value && typeof value === "object"
|
|
8
|
+
? Object.fromEntries(Object.keys(value)
|
|
9
|
+
.sort()
|
|
10
|
+
.map((key) => [key, sortKeys(value[key])]))
|
|
11
|
+
: value;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
type Json = Record<string, unknown>;
|
|
2
|
+
export interface WpJsonOptions {
|
|
3
|
+
/** The namespaces the CLI offers, as `wp/v2`; every other route is left out and listed in `omissions`. */
|
|
4
|
+
namespaces: readonly string[];
|
|
5
|
+
/** Routes, as the index spells them, left out with the reason. One that matches no route stops generation. */
|
|
6
|
+
exclude?: Readonly<Record<string, string>>;
|
|
7
|
+
/** The `site` server variable's default: the host in `https://{site}/wp-json`. */
|
|
8
|
+
site?: string;
|
|
9
|
+
/** The WordPress version the snapshot came from, as `info.version`. */
|
|
10
|
+
version?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface WpJsonResult {
|
|
13
|
+
/** An OpenAPI 3.1 document for `adaptOpenApi`. */
|
|
14
|
+
document: Json;
|
|
15
|
+
/** What the document leaves out, one line each, for a reviewer. */
|
|
16
|
+
omissions: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The OpenAPI document of the routes under `namespaces`. A route offers GET as a read, DELETE as a delete with its
|
|
20
|
+
* arguments in the query (`force=true`), and one write: POST where the route takes it, as WordPress takes the same
|
|
21
|
+
* call by POST, PUT and PATCH. A write's arguments are its JSON body. An array argument in the query travels as one
|
|
22
|
+
* comma-separated value, which WordPress splits, as PHP keeps only the last of a repeated name.
|
|
23
|
+
*/
|
|
24
|
+
export declare const wpJsonToOpenApi: (index: unknown, options: WpJsonOptions) => WpJsonResult;
|
|
25
|
+
/** The snapshot's entry in `provenance.json`. */
|
|
26
|
+
export interface WpJsonProvenance {
|
|
27
|
+
source: string;
|
|
28
|
+
/** The WordPress version it came from; the index does not say it. */
|
|
29
|
+
version: string;
|
|
30
|
+
/** Of the committed file; `readWpJson` refuses a snapshot that no longer matches it. */
|
|
31
|
+
sha256: string;
|
|
32
|
+
retrieved_at: string;
|
|
33
|
+
normalization: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Asks `root` (`https://<site>/wp-json/`) for its index with every schema and writes `wp-json.json` and
|
|
37
|
+
* `provenance.json` to `dir`. Take it from a plain WordPress, as the CLI serves every site: a plugin's routes and
|
|
38
|
+
* fields belong to that site. Run by hand, then review the diff: the build never fetches.
|
|
39
|
+
*/
|
|
40
|
+
export declare const syncWpJson: (options: {
|
|
41
|
+
root: string;
|
|
42
|
+
dir: string;
|
|
43
|
+
version: string;
|
|
44
|
+
fetch?: typeof globalThis.fetch;
|
|
45
|
+
now?: Date;
|
|
46
|
+
}) => Promise<WpJsonProvenance>;
|
|
47
|
+
/** The snapshot `syncWpJson` wrote, parsed. Throws if its hash changed. */
|
|
48
|
+
export declare const readWpJson: (dir: string) => unknown;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress's REST index (`/wp-json/?context=help`), already parsed → an OpenAPI 3.1 document, so `adaptOpenApi` reads
|
|
3
|
+
* it like any other. WordPress publishes no OpenAPI: the index lists each route's endpoints with their arguments, and
|
|
4
|
+
* with `context=help` also the schema of what the route answers, the same one an `OPTIONS` call returns. One request
|
|
5
|
+
* holds the whole API, so `syncWpJson` keeps that one answer with its provenance and `readWpJson` loads it back only
|
|
6
|
+
* while its hash still matches.
|
|
7
|
+
*
|
|
8
|
+
* Strict like `adaptOpenApi`: a route that cannot become a path template, two routes on one path, or an argument with
|
|
9
|
+
* no type stops generation unless `exclude` names the route with a reason.
|
|
10
|
+
*/
|
|
11
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { CodegenError } from "./pipeline.js";
|
|
14
|
+
import { sha256, sortKeys } from "./snapshot.js";
|
|
15
|
+
const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
16
|
+
/** WordPress's own, beside JSON Schema: which `context` shows a field, and its spelling of `readOnly`. */
|
|
17
|
+
const DROPPED = new Set(["context", "readonly", "arg_options", "links", "$schema", "patternProperties", "required"]);
|
|
18
|
+
/** WordPress names the boolean type `bool` in a few block attributes. */
|
|
19
|
+
const typeName = (type) => type === "bool" ? "boolean" : Array.isArray(type) ? type.map(typeName) : type;
|
|
20
|
+
/**
|
|
21
|
+
* One JSON Schema draft 4 node, as WordPress writes it, → its OpenAPI 3.1 form: a field's `required: true` joins its
|
|
22
|
+
* object's `required` list, a node with `properties` and no type is an object, and a draft 4 `exclusiveMinimum: true`
|
|
23
|
+
* goes, keeping `minimum`, which accepts one value more and refuses nothing valid. `patternProperties` (block names to their hooks) becomes the object's
|
|
24
|
+
* `additionalProperties`: the keys are free, the values keep their schema.
|
|
25
|
+
*/
|
|
26
|
+
const schemaOf = (value, where) => {
|
|
27
|
+
if (!object(value))
|
|
28
|
+
throw new CodegenError([`${where}: expected a schema object`]);
|
|
29
|
+
const out = {};
|
|
30
|
+
for (const [key, field] of Object.entries(value)) {
|
|
31
|
+
if (DROPPED.has(key))
|
|
32
|
+
continue;
|
|
33
|
+
if ((key === "exclusiveMinimum" || key === "exclusiveMaximum") && typeof field === "boolean")
|
|
34
|
+
continue;
|
|
35
|
+
if (key === "type")
|
|
36
|
+
out.type = typeName(field);
|
|
37
|
+
else if (key === "properties" && object(field))
|
|
38
|
+
out.properties = Object.fromEntries(Object.entries(field).map(([name, inner]) => [name, schemaOf(inner, `${where}/properties/${name}`)]));
|
|
39
|
+
else if (key === "items")
|
|
40
|
+
out.items = schemaOf(field, `${where}/items`);
|
|
41
|
+
else if ((key === "oneOf" || key === "anyOf") && Array.isArray(field))
|
|
42
|
+
// A `required` beside the alternatives names fields each of them holds.
|
|
43
|
+
out[key] = field.map((member, index) => schemaOf(object(member) && Array.isArray(value.required) && object(member.properties)
|
|
44
|
+
? {
|
|
45
|
+
...member,
|
|
46
|
+
required: [...new Set([...(Array.isArray(member.required) ? member.required : []), ...value.required])],
|
|
47
|
+
}
|
|
48
|
+
: member, `${where}/${key}/${index}`));
|
|
49
|
+
else if (key === "additionalProperties" && object(field))
|
|
50
|
+
out.additionalProperties = schemaOf(field, `${where}/additionalProperties`);
|
|
51
|
+
else
|
|
52
|
+
out[key] = field;
|
|
53
|
+
}
|
|
54
|
+
if (object(value.properties)) {
|
|
55
|
+
const required = [
|
|
56
|
+
...(Array.isArray(value.required) ? value.required.map(String) : []),
|
|
57
|
+
...Object.entries(value.properties)
|
|
58
|
+
.filter(([, inner]) => object(inner) && inner.required === true)
|
|
59
|
+
.map(([name]) => name),
|
|
60
|
+
];
|
|
61
|
+
if (required.length > 0)
|
|
62
|
+
out.required = [...new Set(required)];
|
|
63
|
+
out.type ??= "object";
|
|
64
|
+
}
|
|
65
|
+
if (object(value.patternProperties) && out.additionalProperties === undefined) {
|
|
66
|
+
const members = Object.entries(value.patternProperties).map(([pattern, inner]) => schemaOf(inner, `${where}/patternProperties/${pattern}`));
|
|
67
|
+
out.additionalProperties = members.length === 1 ? members[0] : { anyOf: members };
|
|
68
|
+
}
|
|
69
|
+
if (out.type === undefined && out.oneOf === undefined && out.anyOf === undefined)
|
|
70
|
+
throw new CodegenError([`${where}: no type`]);
|
|
71
|
+
return out;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* `(?P<id>[\d]+)` → `{id}`, with the group's pattern; `"slash"` when a value may hold one; `undefined` when the rest
|
|
75
|
+
* is still a pattern, not a path.
|
|
76
|
+
*/
|
|
77
|
+
const template = (route) => {
|
|
78
|
+
const patterns = {};
|
|
79
|
+
let path = "";
|
|
80
|
+
let at = 0;
|
|
81
|
+
while (at < route.length) {
|
|
82
|
+
const start = route.indexOf("(?P<", at);
|
|
83
|
+
if (start < 0) {
|
|
84
|
+
path += route.slice(at);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
path += route.slice(at, start);
|
|
88
|
+
const close = route.indexOf(">", start);
|
|
89
|
+
const name = route.slice(start + 4, close);
|
|
90
|
+
let depth = 1;
|
|
91
|
+
let index = close + 1;
|
|
92
|
+
let inClass = false;
|
|
93
|
+
for (; index < route.length && depth > 0; index++) {
|
|
94
|
+
const char = route[index];
|
|
95
|
+
if (char === "\\")
|
|
96
|
+
index++;
|
|
97
|
+
else if (inClass)
|
|
98
|
+
inClass = char !== "]";
|
|
99
|
+
else if (char === "[")
|
|
100
|
+
inClass = true;
|
|
101
|
+
else if (char === "(")
|
|
102
|
+
depth++;
|
|
103
|
+
else if (char === ")")
|
|
104
|
+
depth--;
|
|
105
|
+
}
|
|
106
|
+
if (depth > 0)
|
|
107
|
+
return undefined;
|
|
108
|
+
patterns[name] = route.slice(close + 1, index - 1);
|
|
109
|
+
path += `{${name}}`;
|
|
110
|
+
at = index;
|
|
111
|
+
}
|
|
112
|
+
if (/[()[\]?*+\\^$|]/.test(path))
|
|
113
|
+
return undefined;
|
|
114
|
+
// A value that may hold a slash, as a template's `theme//slug`, does not fit in one path segment.
|
|
115
|
+
const slashed = (pattern) => {
|
|
116
|
+
try {
|
|
117
|
+
const regex = new RegExp(`^(?:${pattern})$`);
|
|
118
|
+
return ["a/b", "1/2", "/", "a/", "/a", "a-b/c_d", "1/a"].some((sample) => regex.test(sample));
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
if (Object.values(patterns).some(slashed))
|
|
125
|
+
return "slash";
|
|
126
|
+
return { path, patterns };
|
|
127
|
+
};
|
|
128
|
+
/** Collection reads page with `page` and `per_page` and answer a list; every other answer is one item. */
|
|
129
|
+
const isList = (args) => "per_page" in args && "page" in args;
|
|
130
|
+
/**
|
|
131
|
+
* The OpenAPI document of the routes under `namespaces`. A route offers GET as a read, DELETE as a delete with its
|
|
132
|
+
* arguments in the query (`force=true`), and one write: POST where the route takes it, as WordPress takes the same
|
|
133
|
+
* call by POST, PUT and PATCH. A write's arguments are its JSON body. An array argument in the query travels as one
|
|
134
|
+
* comma-separated value, which WordPress splits, as PHP keeps only the last of a repeated name.
|
|
135
|
+
*/
|
|
136
|
+
export const wpJsonToOpenApi = (index, options) => {
|
|
137
|
+
if (!object(index) || !object(index.routes))
|
|
138
|
+
throw new CodegenError(["not a WordPress REST index: no routes"]);
|
|
139
|
+
const exclude = options.exclude ?? {};
|
|
140
|
+
const used = new Set();
|
|
141
|
+
const problems = [];
|
|
142
|
+
const omissions = [];
|
|
143
|
+
const paths = {};
|
|
144
|
+
const schemas = {};
|
|
145
|
+
const left = new Map();
|
|
146
|
+
const schemaRef = (route, schema) => {
|
|
147
|
+
const title = object(schema) && typeof schema.title === "string" ? schema.title : route;
|
|
148
|
+
const base = title.replace(/[^A-Za-z0-9]+/g, "_");
|
|
149
|
+
const converted = schemaOf(schema, `${route} schema`);
|
|
150
|
+
let name = base;
|
|
151
|
+
for (let n = 2; schemas[name] && JSON.stringify(schemas[name]) !== JSON.stringify(converted); n++)
|
|
152
|
+
name = `${base}${n}`;
|
|
153
|
+
schemas[name] = converted;
|
|
154
|
+
return { $ref: `#/components/schemas/${name}` };
|
|
155
|
+
};
|
|
156
|
+
for (const [route, raw] of Object.entries(index.routes)) {
|
|
157
|
+
if (!object(raw))
|
|
158
|
+
throw new CodegenError([`${route}: not a route`]);
|
|
159
|
+
const namespace = String(raw.namespace ?? "");
|
|
160
|
+
if (!options.namespaces.includes(namespace)) {
|
|
161
|
+
left.set(namespace, (left.get(namespace) ?? 0) + 1);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
// The namespace's own index: the description, not an operation.
|
|
165
|
+
if (route === `/${namespace}`)
|
|
166
|
+
continue;
|
|
167
|
+
if (exclude[route] !== undefined) {
|
|
168
|
+
used.add(route);
|
|
169
|
+
omissions.push(`${route}: excluded — ${exclude[route]}`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const templated = template(route);
|
|
173
|
+
if (templated === "slash") {
|
|
174
|
+
omissions.push(`${route}: left out, as its value may hold a slash, which no path segment carries`);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (!templated) {
|
|
178
|
+
problems.push(`${route}: the route is a pattern no path template expresses; exclude it with a reason`);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const { path, patterns } = templated;
|
|
182
|
+
if (paths[path]) {
|
|
183
|
+
problems.push(`${route}: a second route on ${path}; exclude one with a reason`);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const item = {};
|
|
187
|
+
const endpoints = Array.isArray(raw.endpoints) ? raw.endpoints.filter(object) : [];
|
|
188
|
+
try {
|
|
189
|
+
for (const endpoint of endpoints) {
|
|
190
|
+
const methods = (Array.isArray(endpoint.methods) ? endpoint.methods : []).map(String);
|
|
191
|
+
const args = object(endpoint.args) ? endpoint.args : {};
|
|
192
|
+
const write = ["POST", "PUT", "PATCH"].find((method) => methods.includes(method));
|
|
193
|
+
const dropped = methods.filter((method) => method !== write && ["PUT", "PATCH"].includes(method));
|
|
194
|
+
if (dropped.length > 0)
|
|
195
|
+
omissions.push(`${route}: ${dropped.join(", ")} left out, as ${write} does the same`);
|
|
196
|
+
for (const method of methods.filter((one) => one === "GET" || one === "DELETE" || one === write)) {
|
|
197
|
+
const verb = method.toLowerCase();
|
|
198
|
+
if (item[verb])
|
|
199
|
+
throw new CodegenError([`${route}: two endpoints answer ${method}`]);
|
|
200
|
+
const where = `${route} ${method}`;
|
|
201
|
+
const pathParameters = Object.entries(patterns).map(([name, pattern]) => ({
|
|
202
|
+
name,
|
|
203
|
+
in: "path",
|
|
204
|
+
required: true,
|
|
205
|
+
schema: object(args[name])
|
|
206
|
+
? schemaOf(args[name], `${where} ${name}`)
|
|
207
|
+
: { type: "string", pattern: `^(?:${pattern})$` },
|
|
208
|
+
}));
|
|
209
|
+
const rest = Object.entries(args).filter(([name]) => patterns[name] === undefined);
|
|
210
|
+
const operation = { parameters: pathParameters };
|
|
211
|
+
if (method === write) {
|
|
212
|
+
if (rest.length > 0)
|
|
213
|
+
operation.requestBody = {
|
|
214
|
+
required: rest.some(([, arg]) => object(arg) && arg.required === true),
|
|
215
|
+
content: {
|
|
216
|
+
"application/json": {
|
|
217
|
+
schema: schemaOf({ type: "object", properties: Object.fromEntries(rest) }, `${where} body`),
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
else
|
|
223
|
+
operation.parameters = [
|
|
224
|
+
...pathParameters,
|
|
225
|
+
...rest.map(([name, arg]) => {
|
|
226
|
+
const schema = schemaOf(arg, `${where} ${name}`);
|
|
227
|
+
const list = schema.type === "array" || (Array.isArray(schema.type) && schema.type.includes("array"));
|
|
228
|
+
return {
|
|
229
|
+
name,
|
|
230
|
+
in: "query",
|
|
231
|
+
required: object(arg) && arg.required === true,
|
|
232
|
+
...(typeof schema.description === "string" ? { description: schema.description } : {}),
|
|
233
|
+
schema: list
|
|
234
|
+
? { type: "string", description: `${schema.description ?? name}; several, comma-separated` }
|
|
235
|
+
: schema,
|
|
236
|
+
};
|
|
237
|
+
}),
|
|
238
|
+
];
|
|
239
|
+
if (raw.schema !== undefined && method !== "DELETE") {
|
|
240
|
+
const ref = schemaRef(route, raw.schema);
|
|
241
|
+
const answer = method === "GET" && isList(args) ? { type: "array", items: ref } : ref;
|
|
242
|
+
operation.responses = { "200": { description: "OK", content: { "application/json": { schema: answer } } } };
|
|
243
|
+
}
|
|
244
|
+
else
|
|
245
|
+
operation.responses = { "200": { description: "OK" } };
|
|
246
|
+
item[verb] = operation;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
if (!(error instanceof CodegenError))
|
|
252
|
+
throw error;
|
|
253
|
+
for (const problem of error.problems)
|
|
254
|
+
problems.push(problem);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (Object.keys(item).length > 0)
|
|
258
|
+
paths[path] = item;
|
|
259
|
+
}
|
|
260
|
+
for (const [namespace, count] of left)
|
|
261
|
+
omissions.push(`${namespace || "routes outside a namespace"}: not offered, ${count} routes`);
|
|
262
|
+
const stale = Object.keys(exclude).filter((route) => !used.has(route));
|
|
263
|
+
for (const route of stale)
|
|
264
|
+
problems.push(`exclusion "${route}" matches no route — stale, or the route changed`);
|
|
265
|
+
if (problems.length > 0)
|
|
266
|
+
throw new CodegenError(problems);
|
|
267
|
+
return {
|
|
268
|
+
document: {
|
|
269
|
+
openapi: "3.1.0",
|
|
270
|
+
info: { title: "WordPress REST API", version: options.version ?? "unknown" },
|
|
271
|
+
servers: [{ url: "https://{site}/wp-json", variables: { site: { default: options.site ?? "example.com" } } }],
|
|
272
|
+
// An application password, sent as Basic `<user>:<password>`.
|
|
273
|
+
components: { schemas, securitySchemes: { applicationPassword: { type: "http", scheme: "basic" } } },
|
|
274
|
+
security: [{ applicationPassword: [] }],
|
|
275
|
+
paths,
|
|
276
|
+
},
|
|
277
|
+
omissions,
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
const FILE = "wp-json.json";
|
|
281
|
+
/** The site's name, address, time zone and links go, the schemas' `links` too: the API is the same from any site. */
|
|
282
|
+
const ROUTE_FIELDS = ["namespace", "methods", "endpoints", "schema"];
|
|
283
|
+
/**
|
|
284
|
+
* Asks `root` (`https://<site>/wp-json/`) for its index with every schema and writes `wp-json.json` and
|
|
285
|
+
* `provenance.json` to `dir`. Take it from a plain WordPress, as the CLI serves every site: a plugin's routes and
|
|
286
|
+
* fields belong to that site. Run by hand, then review the diff: the build never fetches.
|
|
287
|
+
*/
|
|
288
|
+
export const syncWpJson = async (options) => {
|
|
289
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
290
|
+
const url = new URL(options.root);
|
|
291
|
+
// The URL goes into provenance.json; a user or password in it must not.
|
|
292
|
+
url.username = "";
|
|
293
|
+
url.password = "";
|
|
294
|
+
url.searchParams.set("context", "help");
|
|
295
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(30_000), redirect: "error" });
|
|
296
|
+
if (!response.ok)
|
|
297
|
+
throw new Error(`WordPress index fetch failed: HTTP ${response.status}`);
|
|
298
|
+
const index = await response.json();
|
|
299
|
+
if (!object(index) || !object(index.routes) || !Array.isArray(index.namespaces))
|
|
300
|
+
throw new Error(`${options.root} is not a WordPress REST index`);
|
|
301
|
+
const routes = Object.fromEntries(Object.entries(index.routes).map(([route, value]) => [
|
|
302
|
+
route,
|
|
303
|
+
object(value)
|
|
304
|
+
? Object.fromEntries(ROUTE_FIELDS.filter((key) => key in value).map((key) => {
|
|
305
|
+
const field = value[key];
|
|
306
|
+
if (key !== "schema" || !object(field))
|
|
307
|
+
return [key, field];
|
|
308
|
+
const { links: _, ...schema } = field;
|
|
309
|
+
return [key, schema];
|
|
310
|
+
}))
|
|
311
|
+
: value,
|
|
312
|
+
]));
|
|
313
|
+
const written = `${JSON.stringify(sortKeys({ namespaces: index.namespaces, routes }), null, 2)}\n`;
|
|
314
|
+
const provenance = {
|
|
315
|
+
source: url.href,
|
|
316
|
+
version: options.version,
|
|
317
|
+
sha256: sha256(written),
|
|
318
|
+
retrieved_at: (options.now ?? new Date()).toISOString(),
|
|
319
|
+
normalization: "the namespaces and each route's namespace, methods, endpoints and schema (without its links); keys sorted, 2-space JSON",
|
|
320
|
+
};
|
|
321
|
+
mkdirSync(options.dir, { recursive: true });
|
|
322
|
+
writeFileSync(join(options.dir, FILE), written);
|
|
323
|
+
writeFileSync(join(options.dir, "provenance.json"), `${JSON.stringify(provenance, null, 2)}\n`);
|
|
324
|
+
return provenance;
|
|
325
|
+
};
|
|
326
|
+
/** The snapshot `syncWpJson` wrote, parsed. Throws if its hash changed. */
|
|
327
|
+
export const readWpJson = (dir) => {
|
|
328
|
+
const provenance = JSON.parse(readFileSync(join(dir, "provenance.json"), "utf8"));
|
|
329
|
+
const raw = readFileSync(join(dir, FILE));
|
|
330
|
+
if (sha256(raw) !== provenance.sha256)
|
|
331
|
+
throw new CodegenError([`WordPress index hash mismatch: ${join(dir, FILE)}`]);
|
|
332
|
+
return JSON.parse(raw.toString("utf8"));
|
|
333
|
+
};
|
|
@@ -48,6 +48,7 @@ what it cannot do yet.
|
|
|
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
50
|
| GraphQL (Linear) | `adaptGraphql(readGraphql(dir), { url, scalars })`, the introspection result written by `syncGraphql` |
|
|
51
|
+
| WordPress's REST index | `adaptOpenApi(wpJsonToOpenApi(readWpJson(dir), { namespaces: ["wp/v2"] }).document)`, the index written by `syncWpJson` |
|
|
51
52
|
|
|
52
53
|
`upgradeToOpenApi3` converts with [swagger-converter](https://github.com/apigee-127/swagger-converter) (1.2 → 2.0) and
|
|
53
54
|
[@scalar/openapi-upgrader](https://github.com/scalar/scalar/tree/main/packages/openapi-upgrader) (2.0 → 3.0). They are
|
|
@@ -106,7 +107,7 @@ From the source the generator reads:
|
|
|
106
107
|
empty or not in kebab case stops generation; map that operation in `commands`. `segments` renames a path segment
|
|
107
108
|
or, with `""`, leaves it out: `{ "0-3": "deals", crm: "", objects: "" }`. Without `names` the command is the operation
|
|
108
109
|
id in kebab case, as before.
|
|
109
|
-
- **`permissions`**: `{ group, deletingFlags, shares }`. `group` is a name (`files`) or a function of the operation, for
|
|
110
|
+
- **`permissions`**: `{ group, deletingFlags, shares, valueKeys }`. `group` is a name (`files`) or a function of the operation, for
|
|
110
111
|
example the first word of its `command` (set only with `names`). Each key lands in the manifest as the operation's `permissions`.
|
|
111
112
|
- `<group>.delete` for every destructive operation (Yandex Disk's `DELETE /trash/resources` empties the whole
|
|
112
113
|
trash), and for every operation that takes a flag in `deletingFlags`, as a top-level body field (Notion's
|
|
@@ -114,6 +115,13 @@ From the source the generator reads:
|
|
|
114
115
|
key applies when the flag is `true`. A flag no operation takes stops generation.
|
|
115
116
|
- `<group>.share` for the operation ids in `shares`: a public link opens a file to anyone, which is neither a
|
|
116
117
|
plain write nor a delete.
|
|
118
|
+
- `<group>.<key>` for each of `valueKeys`, `{ key, field, values }`, on every write or delete whose body field or
|
|
119
|
+
query parameter `field` lists one of `values` in its `enum`, through a reference or a union too: WordPress
|
|
120
|
+
publishes by `status: "publish"`, so `{ key: "publish", field: "status", values: ["publish", "future"] }` gives
|
|
121
|
+
`posts.publish` and `pages.publish`. The key applies when the call sends one of those values, in the body or the
|
|
122
|
+
query; where the field's default is one of them (a WordPress template), leaving it out publishes too, and the key
|
|
123
|
+
always applies. A read that filters by the value gets no key, nor a field of that name without such an enum (a
|
|
124
|
+
comment's `status`); a rule no write matches stops generation.
|
|
117
125
|
|
|
118
126
|
Which flags delete is the CLI's call: read the service's documentation, and count an undocumented flag as a delete.
|
|
119
127
|
A flag counts on every method, a GET included: Yandex Disk's upload link is a GET whose `overwrite` replaces a file.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.118.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",
|