@prudai/cli 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/bin.js +23 -10
- package/dist/index.js +23 -10
- package/dist/openapi.d.ts +5 -0
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -184,6 +184,8 @@ bun install --frozen-lockfile
|
|
|
184
184
|
bun run check:source && bun run typecheck && bun test && bun run test:break && bun run check:pack
|
|
185
185
|
```
|
|
186
186
|
|
|
187
|
+
Commandonamen liggen vast in `tests/fixtures/command-names.txt` (meegeleverde IRMA-spec en de ORDO- en platformfixtures). `tests/command-names.test.ts` faalt bij elke hernoeming: een gewijzigde regel is een gewijzigd commando voor elke gebruiker. Alleen bij een bedoelde hernoeming opnieuw maken met `bun scripts/gen-command-names.ts` en de diff in de PR toelichten. Een naambotsing in een live spec laat alleen de botsende commando's weg, met een waarschuwing; `--spec` en plugins blijven strikt.
|
|
188
|
+
|
|
187
189
|
De gebouwde CLI (`dist/bin.js`, shebang `#!/usr/bin/env node`) gebruikt in `src/` alleen Node-API's (`node:fs`, `node:child_process`, …): `check:source` en `typecheck` (tegen `@types/node` 20, zonder Bun-types) weigeren `Bun.*`, `bun:`-imports en `import.meta.dir`. `tests/node-runtime.test.ts` en `check:pack` draaien de gebouwde bundel onder echte Node (`node` van PATH, of `PRUDAI_TEST_NODE=/pad/naar/node`; minimaal Node 20, Bun's `node`-shim wordt geweigerd), en `check:pack` pakt bovendien de tarball uit zoals npx hem installeert.
|
|
188
190
|
|
|
189
191
|
MIT-licentie. Vragen en meldingen: https://support.prudai.com.
|
package/dist/bin.js
CHANGED
|
@@ -470,6 +470,7 @@ function generateCommands(product, spec, options = {}) {
|
|
|
470
470
|
items.set(path, object(resolve(doc, item), `path ${specPath}`));
|
|
471
471
|
}
|
|
472
472
|
const hasItemChild = (path) => [...items.keys()].some((other) => other.startsWith(`${path}/{`));
|
|
473
|
+
const itemHasPatch = (path) => [...items].some(([other, item]) => other.startsWith(`${path}/{`) && !other.slice(path.length + 1).includes("/") && ("patch" in item));
|
|
473
474
|
const drafts = [];
|
|
474
475
|
for (const [path, pathItem] of items) {
|
|
475
476
|
const segments = path.slice(4).split("/");
|
|
@@ -539,7 +540,7 @@ function generateCommands(product, spec, options = {}) {
|
|
|
539
540
|
} else if (method === "delete") {
|
|
540
541
|
kind = "delete";
|
|
541
542
|
preferred = fallback = [all, "delete"];
|
|
542
|
-
} else if (method === "put" && "patch" in pathItem) {
|
|
543
|
+
} else if (method === "put" && (("patch" in pathItem) || !endsWithParam && itemHasPatch(path))) {
|
|
543
544
|
kind = "replace";
|
|
544
545
|
preferred = fallback = [all, "replace"];
|
|
545
546
|
} else {
|
|
@@ -591,14 +592,22 @@ function generateCommands(product, spec, options = {}) {
|
|
|
591
592
|
const count = new Map;
|
|
592
593
|
for (const draft of drafts)
|
|
593
594
|
count.set(draft.preferred.join(" "), (count.get(draft.preferred.join(" ")) ?? 0) + 1);
|
|
594
|
-
const
|
|
595
|
-
const names = new Set;
|
|
596
|
-
for (const draft of drafts) {
|
|
595
|
+
const named = drafts.map((draft) => {
|
|
597
596
|
const words = !draft.pinned && count.get(draft.preferred.join(" ")) > 1 ? draft.fallback : draft.preferred;
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
597
|
+
return { draft, words, name: words.join(" ") };
|
|
598
|
+
});
|
|
599
|
+
const byName = new Map;
|
|
600
|
+
for (const entry of named)
|
|
601
|
+
byName.set(entry.name, [...byName.get(entry.name) ?? [], entry]);
|
|
602
|
+
const commands = [];
|
|
603
|
+
for (const [name, entries] of byName) {
|
|
604
|
+
if (entries.length > 1) {
|
|
605
|
+
if (!options.onAmbiguous)
|
|
606
|
+
throw new CliError(`Ambiguous generated command: ${product} ${name}. Pin names with x-prudai-cli.`, 2, "invalid_spec");
|
|
607
|
+
options.onAmbiguous(name, entries.map(({ draft: draft2 }) => `${draft2.command.method} ${draft2.command.path}`));
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
610
|
+
const { draft, words } = entries[0];
|
|
602
611
|
commands.push({ ...draft.command, name, words, resource: words.length === 1 ? words[0] : words.slice(0, -1).join(" "), action: words.length === 1 ? "" : words.at(-1) });
|
|
603
612
|
}
|
|
604
613
|
return commands;
|
|
@@ -1037,7 +1046,11 @@ async function loadProductCatalog(word, ctx) {
|
|
|
1037
1046
|
return { ...base, notAvailable: true, error: `${product} is not available yet: its /v1 spec is not served publicly (${base.liveNote ?? (ctx.offline ? "offline: the live spec was not fetched" : "the live spec was not fetched")}), and this CLI bundles only APIs that are live. Commands appear here once ${(base.origin || info.origin).replace(/\/+$/, "")}${info.liveSpecPath ?? "/v1/openapi.json"} is served; or pass --spec <path-or-url> for a contract you have.` };
|
|
1038
1047
|
}
|
|
1039
1048
|
try {
|
|
1040
|
-
const
|
|
1049
|
+
const lenient = source?.kind !== "explicit" && source?.kind !== "plugin";
|
|
1050
|
+
const commands = generateCommands(product, spec, {
|
|
1051
|
+
lenientApproval: lenient,
|
|
1052
|
+
...lenient ? { onAmbiguous: (name, operations) => base.warnings.push(`${operations.length} operations share the generated name "${product} ${name}" (${operations.join(", ")}) and are left out; reach them with prudai api <METHOD> <path>, or the product pins names with x-prudai-cli.`) } : {}
|
|
1053
|
+
});
|
|
1041
1054
|
const defaulted = commands.filter((command) => command.approvalSource === "default").length;
|
|
1042
1055
|
if (defaulted)
|
|
1043
1056
|
base.warnings.push(`${defaulted} write operation(s) declare no x-prudai-approval; the CLI assumes the default level (confirm, delete: review).`);
|
|
@@ -3346,7 +3359,7 @@ function platformHelp() {
|
|
|
3346
3359
|
}
|
|
3347
3360
|
|
|
3348
3361
|
// src/version.ts
|
|
3349
|
-
var VERSION = "0.1.
|
|
3362
|
+
var VERSION = "0.1.1";
|
|
3350
3363
|
|
|
3351
3364
|
// src/discovery.ts
|
|
3352
3365
|
var CATALOG_FLAGS = ["json", "help", "profile", "refresh", "offline", "spec", "registry", "api-url"];
|
package/dist/index.js
CHANGED
|
@@ -989,6 +989,7 @@ function generateCommands(product, spec, options = {}) {
|
|
|
989
989
|
items.set(path, object2(resolve(doc, item), `path ${specPath}`));
|
|
990
990
|
}
|
|
991
991
|
const hasItemChild = (path) => [...items.keys()].some((other) => other.startsWith(`${path}/{`));
|
|
992
|
+
const itemHasPatch = (path) => [...items].some(([other, item]) => other.startsWith(`${path}/{`) && !other.slice(path.length + 1).includes("/") && ("patch" in item));
|
|
992
993
|
const drafts = [];
|
|
993
994
|
for (const [path, pathItem] of items) {
|
|
994
995
|
const segments = path.slice(4).split("/");
|
|
@@ -1058,7 +1059,7 @@ function generateCommands(product, spec, options = {}) {
|
|
|
1058
1059
|
} else if (method === "delete") {
|
|
1059
1060
|
kind = "delete";
|
|
1060
1061
|
preferred = fallback = [all, "delete"];
|
|
1061
|
-
} else if (method === "put" && "patch" in pathItem) {
|
|
1062
|
+
} else if (method === "put" && (("patch" in pathItem) || !endsWithParam && itemHasPatch(path))) {
|
|
1062
1063
|
kind = "replace";
|
|
1063
1064
|
preferred = fallback = [all, "replace"];
|
|
1064
1065
|
} else {
|
|
@@ -1110,14 +1111,22 @@ function generateCommands(product, spec, options = {}) {
|
|
|
1110
1111
|
const count = new Map;
|
|
1111
1112
|
for (const draft of drafts)
|
|
1112
1113
|
count.set(draft.preferred.join(" "), (count.get(draft.preferred.join(" ")) ?? 0) + 1);
|
|
1113
|
-
const
|
|
1114
|
-
const names2 = new Set;
|
|
1115
|
-
for (const draft of drafts) {
|
|
1114
|
+
const named = drafts.map((draft) => {
|
|
1116
1115
|
const words = !draft.pinned && count.get(draft.preferred.join(" ")) > 1 ? draft.fallback : draft.preferred;
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1116
|
+
return { draft, words, name: words.join(" ") };
|
|
1117
|
+
});
|
|
1118
|
+
const byName = new Map;
|
|
1119
|
+
for (const entry of named)
|
|
1120
|
+
byName.set(entry.name, [...byName.get(entry.name) ?? [], entry]);
|
|
1121
|
+
const commands = [];
|
|
1122
|
+
for (const [name, entries] of byName) {
|
|
1123
|
+
if (entries.length > 1) {
|
|
1124
|
+
if (!options.onAmbiguous)
|
|
1125
|
+
throw new CliError(`Ambiguous generated command: ${product} ${name}. Pin names with x-prudai-cli.`, 2, "invalid_spec");
|
|
1126
|
+
options.onAmbiguous(name, entries.map(({ draft: draft2 }) => `${draft2.command.method} ${draft2.command.path}`));
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
const { draft, words } = entries[0];
|
|
1121
1130
|
commands.push({ ...draft.command, name, words, resource: words.length === 1 ? words[0] : words.slice(0, -1).join(" "), action: words.length === 1 ? "" : words.at(-1) });
|
|
1122
1131
|
}
|
|
1123
1132
|
return commands;
|
|
@@ -1669,7 +1678,11 @@ async function loadProductCatalog(word, ctx) {
|
|
|
1669
1678
|
return { ...base, notAvailable: true, error: `${product} is not available yet: its /v1 spec is not served publicly (${base.liveNote ?? (ctx.offline ? "offline: the live spec was not fetched" : "the live spec was not fetched")}), and this CLI bundles only APIs that are live. Commands appear here once ${(base.origin || info.origin).replace(/\/+$/, "")}${info.liveSpecPath ?? "/v1/openapi.json"} is served; or pass --spec <path-or-url> for a contract you have.` };
|
|
1670
1679
|
}
|
|
1671
1680
|
try {
|
|
1672
|
-
const
|
|
1681
|
+
const lenient = source?.kind !== "explicit" && source?.kind !== "plugin";
|
|
1682
|
+
const commands = generateCommands(product, spec, {
|
|
1683
|
+
lenientApproval: lenient,
|
|
1684
|
+
...lenient ? { onAmbiguous: (name, operations) => base.warnings.push(`${operations.length} operations share the generated name "${product} ${name}" (${operations.join(", ")}) and are left out; reach them with prudai api <METHOD> <path>, or the product pins names with x-prudai-cli.`) } : {}
|
|
1685
|
+
});
|
|
1673
1686
|
const defaulted = commands.filter((command) => command.approvalSource === "default").length;
|
|
1674
1687
|
if (defaulted)
|
|
1675
1688
|
base.warnings.push(`${defaulted} write operation(s) declare no x-prudai-approval; the CLI assumes the default level (confirm, delete: review).`);
|
|
@@ -3340,7 +3353,7 @@ function platformHelp() {
|
|
|
3340
3353
|
}
|
|
3341
3354
|
|
|
3342
3355
|
// src/version.ts
|
|
3343
|
-
var VERSION = "0.1.
|
|
3356
|
+
var VERSION = "0.1.1";
|
|
3344
3357
|
|
|
3345
3358
|
// src/discovery.ts
|
|
3346
3359
|
var CATALOG_FLAGS = ["json", "help", "profile", "refresh", "offline", "spec", "registry", "api-url"];
|
package/dist/openapi.d.ts
CHANGED
|
@@ -75,6 +75,11 @@ export interface GenerateOptions {
|
|
|
75
75
|
* the whole product. Writes stay dry-run-gated either way.
|
|
76
76
|
*/
|
|
77
77
|
lenientApproval?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Catalogue mode: commands whose generated name stays ambiguous are left out (all of them, so
|
|
80
|
+
* none silently runs the wrong operation) and reported here, instead of failing the whole product.
|
|
81
|
+
*/
|
|
82
|
+
onAmbiguous?: (name: string, operations: string[]) => void;
|
|
78
83
|
}
|
|
79
84
|
/** Base path of the first server, e.g. "/v1" for https://api.prudai.com/v1; "" when absent. */
|
|
80
85
|
export declare function serverBasePath(spec: unknown): string;
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The one version constant; tests compare it with package.json. */
|
|
2
|
-
export declare const VERSION = "0.1.
|
|
2
|
+
export declare const VERSION = "0.1.1";
|