@rockcarver/frodo-cli 5.0.0-6 → 5.0.0-7
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 +24 -0
- package/dist/AuthoringPrintState-vyWOD1Wt.cjs +124 -0
- package/dist/AuthoringPrintState-vyWOD1Wt.cjs.map +1 -0
- package/dist/ColorTheme-DEHDqYXV.cjs +172418 -0
- package/dist/ColorTheme-DEHDqYXV.cjs.map +1 -0
- package/dist/Console--leD9RdR.cjs +4655 -0
- package/dist/Console--leD9RdR.cjs.map +1 -0
- package/dist/DefaultsStore-RlEkAWqT.cjs +155 -0
- package/dist/DefaultsStore-RlEkAWqT.cjs.map +1 -0
- package/dist/EntityPickers-szvN8rXt.cjs +143 -0
- package/dist/EntityPickers-szvN8rXt.cjs.map +1 -0
- package/dist/EscapableSelectPrompt-Us2SkS12.cjs +2356 -0
- package/dist/EscapableSelectPrompt-Us2SkS12.cjs.map +1 -0
- package/dist/FrodoCommand-gFM6WHXw.cjs +15475 -0
- package/dist/FrodoCommand-gFM6WHXw.cjs.map +1 -0
- package/dist/RealmOps-CQwmHsxG.cjs +341 -0
- package/dist/RealmOps-CQwmHsxG.cjs.map +1 -0
- package/dist/RealmPickers-7b9g8ZTE.cjs +138 -0
- package/dist/RealmPickers-7b9g8ZTE.cjs.map +1 -0
- package/dist/ResolveInteractiveInputs-CQBVc_CT.cjs +1843 -0
- package/dist/ResolveInteractiveInputs-CQBVc_CT.cjs.map +1 -0
- package/dist/app.cjs +2 -2
- package/package.json +3 -8
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-Ctb5zv51.cjs");
|
|
2
|
+
let path = require("path");
|
|
3
|
+
path = require_rolldown_runtime.__toESM(path, 1);
|
|
4
|
+
let fs = require("fs");
|
|
5
|
+
fs = require_rolldown_runtime.__toESM(fs, 1);
|
|
6
|
+
let os = require("os");
|
|
7
|
+
os = require_rolldown_runtime.__toESM(os, 1);
|
|
8
|
+
//#region src/utils/interactive/DefaultsStore.ts
|
|
9
|
+
var DefaultsStore_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
10
|
+
applicableCommandDefaults: () => applicableCommandDefaults,
|
|
11
|
+
clearDefaultsByPath: () => clearDefaultsByPath,
|
|
12
|
+
commandStoreKey: () => commandStoreKey,
|
|
13
|
+
getDefaultsPath: () => getDefaultsPath,
|
|
14
|
+
optionMissingUserValue: () => optionMissingUserValue,
|
|
15
|
+
readCommandDefaults: () => readCommandDefaults,
|
|
16
|
+
readDefaultsStore: () => readDefaultsStore,
|
|
17
|
+
saveCommandDefaults: () => saveCommandDefaults,
|
|
18
|
+
writeDefaultsStore: () => writeDefaultsStore
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Persistent per-command defaults (docs/INTERACTIVE-COMMANDS.md):
|
|
22
|
+
* values committed through the invocation editor with --save-defaults
|
|
23
|
+
* land here and become the starting values for FUTURE runs of the same
|
|
24
|
+
* command. Deliberately a sibling of SettingsStore (plain user
|
|
25
|
+
* preferences, not secrets; corrupt file = empty, never a failure):
|
|
26
|
+
* ~/.frodo/Defaults.json, keyed by the command's full path
|
|
27
|
+
* ("journey list"), then by the option's attributeName:
|
|
28
|
+
*
|
|
29
|
+
* { "journey list": { "long": true }, "esv secret list": { "flat": "all" } }
|
|
30
|
+
*
|
|
31
|
+
* PRECEDENCE (the plan's chain: explicit CLI flag > env var > persisted
|
|
32
|
+
* default > built-in default) is enforced by the RESOLUTION PASS, not
|
|
33
|
+
* here -- this module only reads/writes the store. The pass applies a
|
|
34
|
+
* persisted value only when the option has no value from flag or env
|
|
35
|
+
* (source undefined or 'default'), writing it with source 'cli': a
|
|
36
|
+
* persisted default is user-authored configuration -- the serializer's
|
|
37
|
+
* "only user-provided tokens" rule and the editor's (current: x)
|
|
38
|
+
* display must both see it as real input.
|
|
39
|
+
*/
|
|
40
|
+
const DEFAULTS_FILENAME = "Defaults.json";
|
|
41
|
+
function getDefaultsPath() {
|
|
42
|
+
return path.default.join(path.default.join(os.default.homedir(), ".frodo"), DEFAULTS_FILENAME);
|
|
43
|
+
}
|
|
44
|
+
/** Reads the store; missing/corrupt file = empty store. */
|
|
45
|
+
function readDefaultsStore() {
|
|
46
|
+
try {
|
|
47
|
+
const parsed = JSON.parse(fs.default.readFileSync(getDefaultsPath(), "utf8"));
|
|
48
|
+
return typeof parsed === "object" && parsed !== null ? parsed : {};
|
|
49
|
+
} catch {
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** Writes the store (creating ~/.frodo as needed). */
|
|
54
|
+
function writeDefaultsStore(store) {
|
|
55
|
+
const file = getDefaultsPath();
|
|
56
|
+
fs.default.mkdirSync(path.default.dirname(file), { recursive: true });
|
|
57
|
+
fs.default.writeFileSync(file, JSON.stringify(store, null, 2));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The `frodo x y z` path of the command (root name + ancestors + this) --
|
|
61
|
+
* the store's key. Matches CommandPreview's commandPath; duplicated here
|
|
62
|
+
* to keep this module free of the preview graph (the store must load in
|
|
63
|
+
* tests that mock frodo-lib wholesale, same constraint as the other
|
|
64
|
+
* zero-import modules in this directory).
|
|
65
|
+
*/
|
|
66
|
+
function commandStoreKey(command) {
|
|
67
|
+
const names = [];
|
|
68
|
+
for (let cursor = command; cursor; cursor = cursor.parent) names.unshift(cursor.name());
|
|
69
|
+
return names.join(" ");
|
|
70
|
+
}
|
|
71
|
+
/** The persisted defaults for one command (empty when none). */
|
|
72
|
+
function readCommandDefaults(command) {
|
|
73
|
+
return readDefaultsStore()[commandStoreKey(command)] ?? {};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Merges `values` into the command's persisted defaults (a partial
|
|
77
|
+
* save: only the options committed this session change).
|
|
78
|
+
*/
|
|
79
|
+
function saveCommandDefaults(command, values) {
|
|
80
|
+
const store = readDefaultsStore();
|
|
81
|
+
const key = commandStoreKey(command);
|
|
82
|
+
store[key] = {
|
|
83
|
+
...store[key] ?? {},
|
|
84
|
+
...values
|
|
85
|
+
};
|
|
86
|
+
writeDefaultsStore(store);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Drops one command's defaults by its verbatim store path -- the
|
|
90
|
+
* `frodo settings defaults --clear <path>` form. Path-keyed (not
|
|
91
|
+
* Command-keyed) on purpose: clearing must work even when the command's
|
|
92
|
+
* option set changed since the save.
|
|
93
|
+
*/
|
|
94
|
+
function clearDefaultsByPath(commandPath) {
|
|
95
|
+
const store = readDefaultsStore();
|
|
96
|
+
delete store[commandPath];
|
|
97
|
+
writeDefaultsStore(store);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The persisted values that still make sense for this command: keys the
|
|
101
|
+
* command actually declares as options (the store outlives code -- a
|
|
102
|
+
* removed or renamed option's stale entry is skipped, not applied).
|
|
103
|
+
* Returns attributeName -> value.
|
|
104
|
+
*/
|
|
105
|
+
function applicableCommandDefaults(command) {
|
|
106
|
+
const persisted = readCommandDefaults(command);
|
|
107
|
+
const known = new Set(command.options.map((option) => option.attributeName()));
|
|
108
|
+
return Object.fromEntries(Object.entries(persisted).filter(([name]) => known.has(name)));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Whether `option` may take a persisted default this invocation: it has
|
|
112
|
+
* NO value from flag or env. Commander source semantics: an untouched
|
|
113
|
+
* option with a built-in default reads (value, 'default'); one without
|
|
114
|
+
* any default reads (undefined, undefined). Both mean "the user did not
|
|
115
|
+
* provide anything" -- the persisted default may fill the gap. Anything
|
|
116
|
+
* else ('cli', 'env', 'config'...) means the user (or this pass) already
|
|
117
|
+
* authored a value -- the persisted default must NOT override it.
|
|
118
|
+
*/
|
|
119
|
+
function optionMissingUserValue(command, option) {
|
|
120
|
+
const source = command.getOptionValueSource(option.attributeName());
|
|
121
|
+
return source === void 0 || source === "default";
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
Object.defineProperty(exports, "DefaultsStore_exports", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
get: function() {
|
|
127
|
+
return DefaultsStore_exports;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(exports, "applicableCommandDefaults", {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
get: function() {
|
|
133
|
+
return applicableCommandDefaults;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
Object.defineProperty(exports, "clearDefaultsByPath", {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
get: function() {
|
|
139
|
+
return clearDefaultsByPath;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
Object.defineProperty(exports, "optionMissingUserValue", {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function() {
|
|
145
|
+
return optionMissingUserValue;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
Object.defineProperty(exports, "readDefaultsStore", {
|
|
149
|
+
enumerable: true,
|
|
150
|
+
get: function() {
|
|
151
|
+
return readDefaultsStore;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
//# sourceMappingURL=DefaultsStore-RlEkAWqT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultsStore-RlEkAWqT.cjs","names":[],"sources":["../src/utils/interactive/DefaultsStore.ts"],"sourcesContent":["import fs from 'fs';\nimport os from 'os';\nimport path from 'path';\nimport type { Command, Option } from 'commander';\n\n/**\n * Persistent per-command defaults (docs/INTERACTIVE-COMMANDS.md):\n * values committed through the invocation editor with --save-defaults\n * land here and become the starting values for FUTURE runs of the same\n * command. Deliberately a sibling of SettingsStore (plain user\n * preferences, not secrets; corrupt file = empty, never a failure):\n * ~/.frodo/Defaults.json, keyed by the command's full path\n * (\"journey list\"), then by the option's attributeName:\n *\n * { \"journey list\": { \"long\": true }, \"esv secret list\": { \"flat\": \"all\" } }\n *\n * PRECEDENCE (the plan's chain: explicit CLI flag > env var > persisted\n * default > built-in default) is enforced by the RESOLUTION PASS, not\n * here -- this module only reads/writes the store. The pass applies a\n * persisted value only when the option has no value from flag or env\n * (source undefined or 'default'), writing it with source 'cli': a\n * persisted default is user-authored configuration -- the serializer's\n * \"only user-provided tokens\" rule and the editor's (current: x)\n * display must both see it as real input.\n */\n\nconst DEFAULTS_FILENAME = 'Defaults.json';\n\n/** A single command's persisted defaults: attributeName -> value. */\nexport type CommandDefaults = Record<string, unknown>;\n\n/** The whole store: full command path -> that command's defaults. */\nexport type DefaultsStore = Record<string, CommandDefaults>;\n\n/**\n * Test seam: overrides the ~/.frodo base directory for the duration of\n * a test (jest workers share process.env.HOME, and os.homedir() can\n * cache -- an env fiddle in one test leaks into its siblings).\n * Production callers never touch this.\n */\nlet baseDirOverride: string | undefined;\n\n/** FOR TESTS ONLY: redirects the store's base directory (undefined = ~/.frodo). */\nexport function setDefaultsBaseDirForTests(dir: string | undefined): void {\n baseDirOverride = dir;\n}\n\nexport function getDefaultsPath(): string {\n return path.join(\n baseDirOverride ?? path.join(os.homedir(), '.frodo'),\n DEFAULTS_FILENAME\n );\n}\n\n/** Reads the store; missing/corrupt file = empty store. */\nexport function readDefaultsStore(): DefaultsStore {\n try {\n const parsed = JSON.parse(fs.readFileSync(getDefaultsPath(), 'utf8'));\n return typeof parsed === 'object' && parsed !== null ? parsed : {};\n } catch {\n return {};\n }\n}\n\n/** Writes the store (creating ~/.frodo as needed). */\nexport function writeDefaultsStore(store: DefaultsStore): void {\n const file = getDefaultsPath();\n fs.mkdirSync(path.dirname(file), { recursive: true });\n fs.writeFileSync(file, JSON.stringify(store, null, 2));\n}\n\n/**\n * The `frodo x y z` path of the command (root name + ancestors + this) --\n * the store's key. Matches CommandPreview's commandPath; duplicated here\n * to keep this module free of the preview graph (the store must load in\n * tests that mock frodo-lib wholesale, same constraint as the other\n * zero-import modules in this directory).\n */\nexport function commandStoreKey(command: Command): string {\n const names: string[] = [];\n for (\n let cursor: Command | undefined = command;\n cursor;\n cursor = cursor.parent\n ) {\n names.unshift(cursor.name());\n }\n return names.join(' ');\n}\n\n/** The persisted defaults for one command (empty when none). */\nexport function readCommandDefaults(command: Command): CommandDefaults {\n return readDefaultsStore()[commandStoreKey(command)] ?? {};\n}\n\n/**\n * Merges `values` into the command's persisted defaults (a partial\n * save: only the options committed this session change).\n */\nexport function saveCommandDefaults(\n command: Command,\n values: CommandDefaults\n): void {\n const store = readDefaultsStore();\n const key = commandStoreKey(command);\n store[key] = { ...(store[key] ?? {}), ...values };\n writeDefaultsStore(store);\n}\n\n/** Drops one command's defaults entirely (frodo settings defaults --clear). */\nexport function clearCommandDefaults(command: Command): void {\n const store = readDefaultsStore();\n delete store[commandStoreKey(command)];\n writeDefaultsStore(store);\n}\n\n/**\n * Drops one command's defaults by its verbatim store path -- the\n * `frodo settings defaults --clear <path>` form. Path-keyed (not\n * Command-keyed) on purpose: clearing must work even when the command's\n * option set changed since the save.\n */\nexport function clearDefaultsByPath(commandPath: string): void {\n const store = readDefaultsStore();\n delete store[commandPath];\n writeDefaultsStore(store);\n}\n\n/**\n * The persisted values that still make sense for this command: keys the\n * command actually declares as options (the store outlives code -- a\n * removed or renamed option's stale entry is skipped, not applied).\n * Returns attributeName -> value.\n */\nexport function applicableCommandDefaults(command: Command): CommandDefaults {\n const persisted = readCommandDefaults(command);\n const known = new Set(\n command.options.map((option) => option.attributeName())\n );\n return Object.fromEntries(\n Object.entries(persisted).filter(([name]) => known.has(name))\n );\n}\n\n/**\n * Whether `option` may take a persisted default this invocation: it has\n * NO value from flag or env. Commander source semantics: an untouched\n * option with a built-in default reads (value, 'default'); one without\n * any default reads (undefined, undefined). Both mean \"the user did not\n * provide anything\" -- the persisted default may fill the gap. Anything\n * else ('cli', 'env', 'config'...) means the user (or this pass) already\n * authored a value -- the persisted default must NOT override it.\n */\nexport function optionMissingUserValue(\n command: Command,\n option: Option\n): boolean {\n const source = command.getOptionValueSource(option.attributeName());\n return source === undefined || source === 'default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AC3E,MAAM,YAAY,oBAAoB,OAAO;CAC7C,MAAM,QAAQ,IAAI,IAChB,QAAQ,QAAQ,KAAK,WAAW,OAAO,cAAc,CAAC,CACxD;CACA,OAAO,OAAO,YACZ,OAAO,QAAQ,SAAS,CAAC,CAAC,QAAQ,CAAC,UAAU,MAAM,IAAI,IAAI,CAAC,CAC9D;AACF;;;;;;;;;;AAWA,SAAgB,uBACd,SACA,QACS;CACT,MAAM,SAAS,QAAQ,qBAAqB,OAAO,cAAc,CAAC;CAClE,OAAO,WAAW,KAAA,KAAa,WAAW;AAC5C"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-Ctb5zv51.cjs");
|
|
2
|
+
const require_EscapableSelectPrompt = require("./EscapableSelectPrompt-Us2SkS12.cjs");
|
|
3
|
+
//#region src/utils/interactive/EntityPickers.ts
|
|
4
|
+
var EntityPickers_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
5
|
+
deferEntityPicks: () => deferEntityPicks,
|
|
6
|
+
entityPick: () => entityPick,
|
|
7
|
+
getEntityPicks: () => getEntityPicks,
|
|
8
|
+
hasEntityPick: () => hasEntityPick,
|
|
9
|
+
resolveEntityPicks: () => resolveEntityPicks
|
|
10
|
+
});
|
|
11
|
+
const pendingEntityPicks = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
/**
|
|
13
|
+
* Registers entity pickers on a command. Called from the command's setup
|
|
14
|
+
* (module scope of the command file) so the resolver can consult the
|
|
15
|
+
* registry and the action body can run the picks with one bare call.
|
|
16
|
+
* `T` defaults to unknown, so heterogenous spec lists type-check.
|
|
17
|
+
*/
|
|
18
|
+
function deferEntityPicks(command, picks) {
|
|
19
|
+
pendingEntityPicks.set(command, [...pendingEntityPicks.get(command) ?? [], ...picks]);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The entity pickers registered on a command (empty when none). Read by
|
|
23
|
+
* ResolveInteractiveInputs to know which options it should NOT free-text
|
|
24
|
+
* prompt for -- those belong to the post-auth dropdown.
|
|
25
|
+
*/
|
|
26
|
+
function getEntityPicks(command) {
|
|
27
|
+
return pendingEntityPicks.get(command) ?? [];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether the named option has an entity picker registered on this
|
|
31
|
+
* command. Convenience for the resolver's value steps.
|
|
32
|
+
*/
|
|
33
|
+
function hasEntityPick(command, name) {
|
|
34
|
+
return getEntityPicks(command).some((pick) => pick.name === name);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Defines an entity picker for one option. The returned spec is registered
|
|
38
|
+
* via `deferEntityPicks`.
|
|
39
|
+
*/
|
|
40
|
+
function entityPick(spec) {
|
|
41
|
+
return spec;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Runs every entity pick registered for this command whose option is still
|
|
45
|
+
* unspecified. No-op when prompting is disallowed. Returns false when the
|
|
46
|
+
* user escaped the picker -- the caller should return without running the
|
|
47
|
+
* action's body (same shape as a failed getTokens()).
|
|
48
|
+
*/
|
|
49
|
+
async function resolveEntityPicks(command) {
|
|
50
|
+
if (!require_EscapableSelectPrompt.canPrompt()) return true;
|
|
51
|
+
for (const pick of getEntityPicks(command)) {
|
|
52
|
+
if (command.getOptionValue(pick.name)) continue;
|
|
53
|
+
let entities;
|
|
54
|
+
try {
|
|
55
|
+
entities = await pick.load();
|
|
56
|
+
} catch {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (entities.length === 0) return true;
|
|
60
|
+
if (entities.length === 1) {
|
|
61
|
+
apply(command, pick, entities[0]);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
let chosen;
|
|
65
|
+
for (;;) {
|
|
66
|
+
const { liveOptionPreviewFor } = await Promise.resolve().then(() => require("./ResolveInteractiveInputs-CQBVc_CT.cjs")).then((n) => n.ResolveInteractiveInputs_exports);
|
|
67
|
+
chosen = await require_EscapableSelectPrompt.escapableSelect({
|
|
68
|
+
message: pick.message ?? `Select ${pick.kind} to act on:`,
|
|
69
|
+
hint: require_EscapableSelectPrompt.editableOptionsHint(command),
|
|
70
|
+
preview: liveOptionPreviewFor(command, pick.name, (entity) => pick.label(entity)),
|
|
71
|
+
choices: entities.map((entity) => {
|
|
72
|
+
const description = pick.description?.(entity);
|
|
73
|
+
return {
|
|
74
|
+
value: entity,
|
|
75
|
+
name: pick.label(entity),
|
|
76
|
+
...description !== void 0 ? { description } : {}
|
|
77
|
+
};
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
if (chosen !== require_EscapableSelectPrompt.RIGHT) break;
|
|
81
|
+
const { runInvocationEditorForCommand } = await Promise.resolve().then(() => require("./ResolveInteractiveInputs-CQBVc_CT.cjs")).then((n) => n.ResolveInteractiveInputs_exports);
|
|
82
|
+
await runInvocationEditorForCommand(command);
|
|
83
|
+
}
|
|
84
|
+
if (chosen === require_EscapableSelectPrompt.EXIT_ALL) {
|
|
85
|
+
const { revokeAuthoringPrint } = await Promise.resolve().then(() => require("./AuthoringPrintState-vyWOD1Wt.cjs")).then((n) => n.AuthoringPrintState_exports);
|
|
86
|
+
revokeAuthoringPrint();
|
|
87
|
+
throw require_EscapableSelectPrompt.EXIT_ALL_SIGNAL;
|
|
88
|
+
}
|
|
89
|
+
if (chosen === require_EscapableSelectPrompt.ESCAPE) {
|
|
90
|
+
const { revokeAuthoringPrint } = await Promise.resolve().then(() => require("./AuthoringPrintState-vyWOD1Wt.cjs")).then((n) => n.AuthoringPrintState_exports);
|
|
91
|
+
revokeAuthoringPrint();
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
apply(command, pick, chosen);
|
|
95
|
+
}
|
|
96
|
+
{
|
|
97
|
+
const { authSucceededForFlush, flushAuthoringPrint } = await Promise.resolve().then(() => require("./AuthoringPrintState-vyWOD1Wt.cjs")).then((n) => n.AuthoringPrintState_exports);
|
|
98
|
+
if (authSucceededForFlush()) flushAuthoringPrint();
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
function apply(command, pick, entity) {
|
|
103
|
+
command.setOptionValueWithSource(pick.name, pick.label(entity), "cli");
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
Object.defineProperty(exports, "EntityPickers_exports", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
get: function() {
|
|
109
|
+
return EntityPickers_exports;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
Object.defineProperty(exports, "deferEntityPicks", {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
get: function() {
|
|
115
|
+
return deferEntityPicks;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
Object.defineProperty(exports, "entityPick", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
get: function() {
|
|
121
|
+
return entityPick;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
Object.defineProperty(exports, "getEntityPicks", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
get: function() {
|
|
127
|
+
return getEntityPicks;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(exports, "hasEntityPick", {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
get: function() {
|
|
133
|
+
return hasEntityPick;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
Object.defineProperty(exports, "resolveEntityPicks", {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
get: function() {
|
|
139
|
+
return resolveEntityPicks;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
//# sourceMappingURL=EntityPickers-szvN8rXt.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityPickers-szvN8rXt.cjs","names":["canPrompt","escapableSelect","editableOptionsHint","RIGHT","EXIT_ALL","EXIT_ALL_SIGNAL","ESCAPE"],"sources":["../src/utils/interactive/EntityPickers.ts"],"sourcesContent":["/**\n * Entity pickers (docs/INTERACTIVE-COMMANDS.md, post-auth pickers).\n *\n * A command whose target-entity option (`-i/--secret-id`, `-i/--tree-id`\n * etc.) was left unspecified can offer a dropdown populated from the live\n * system -- a PingAM server, a PingIDM instance, or an Identity Cloud\n * tenant, whichever the command targets -- instead of failing or forcing\n * `-a`. The data source is per-command: the spec's `load` is whatever read\n * function the command family's ops layer provides (`frodo.authn.journey\n * .readJourneys` for PingAM, `frodo.cloud.secret.readSecrets` for cloud,\n * and so on), so each picker is deployment-type-correct by construction;\n * nothing here assumes a particular deployment type.\n *\n * The flow spans two stages:\n *\n * 1. SETUP: the command declares its specs with `deferEntityPicks(command,\n * [...])`. The resolver (ResolveInteractiveInputs) reads the registry to\n * learn which options are entity-pickable, and when such an option is\n * the missing half of a mandatory/one-of rule, it SKIPS the free-text\n * value step for it (asking the user to type an id by hand would defeat\n * the picker's purpose) and leaves the option unset.\n *\n * 2. ACTION BODY: after `getTokens()` succeeds (the loaders need tokens),\n * the command calls `resolveEntityPicks(command)`, which runs the\n * dropdown for every still-unspecified pickable option. A prompt only\n * happens when the gate allows prompting (canPrompt()), the option is\n * still unspecified, and the loader returned at least one entity. Every\n * other path is a no-op, so non-interactive behavior stays\n * byte-identical: no TTY, `--no-prompt`, FRODO_NO_PROMPT, FRODO_TEST,\n * or an empty system all leave `options.<name>` untouched and the\n * action proceeds exactly as before (usually to its existing \"required\"\n * error).\n *\n * Escape backs out of a picker without setting anything -- callers treat\n * that as \"declined to run\" and return (same shape as a failed\n * getTokens()). A returned `false` from `resolveEntityPicks` is the\n * caller's signal to stop.\n */\n\nimport { Command } from 'commander';\nimport { editableOptionsHint } from './EditableOptions';\nimport { escapableSelect, ESCAPE, RIGHT } from './EscapableSelectPrompt';\nimport { EXIT_ALL, EXIT_ALL_SIGNAL } from './ExitAll';\nimport { canPrompt } from './PromptGateState';\n\n/**\n * Loads the candidate entities for a picker. Returns the raw skeletons;\n * `label`/`description` turn an entity into the picker row. Errors\n * (host unreachable, permission denied) resolve to an empty list rather\n * than throwing -- the action's own error path handles a failing\n * connection better than a picker-side stack trace.\n */\nexport type EntityPickLoader<T> = () => Promise<T[]>;\n\n/**\n * The registry-facing shape of an entity pick spec: the entity type is\n * erased (functions accept `any`) so heterogenous spec lists type-check.\n * `entityPick<T>` keeps the typed surface for call sites; the erasure only\n * widens what the registry stores.\n */\nexport type EntityPickSpec<T = any> = {\n /**\n * Attribute name of the option being filled (e.g. `secretId`). The value\n * written back is the entity's rendered label -- for every current\n * command family, the option wants the entity id/name, so the label IS\n * the value (loaders are expected to feed the label with the id).\n */\n name: string;\n /** Loads the candidates from the live system. */\n load: EntityPickLoader<T>;\n /** Renders an entity as both the picker row label and the option value. */\n label: (entity: T) => string;\n /** Optional second line shown as the row's dimmed description. */\n description?: (entity: T) => string | undefined;\n /** Prompt message; defaults to \"Select <entity kind>:\". */\n message?: string;\n /** Noun for the default message, e.g. \"secret\". */\n kind: string;\n};\n\nconst pendingEntityPicks = new WeakMap<Command, EntityPickSpec<unknown>[]>();\n\n/**\n * Registers entity pickers on a command. Called from the command's setup\n * (module scope of the command file) so the resolver can consult the\n * registry and the action body can run the picks with one bare call.\n * `T` defaults to unknown, so heterogenous spec lists type-check.\n */\nexport function deferEntityPicks(\n command: Command,\n picks: EntityPickSpec[]\n): void {\n pendingEntityPicks.set(command, [\n ...(pendingEntityPicks.get(command) ?? []),\n ...picks,\n ]);\n}\n\n/**\n * The entity pickers registered on a command (empty when none). Read by\n * ResolveInteractiveInputs to know which options it should NOT free-text\n * prompt for -- those belong to the post-auth dropdown.\n */\nexport function getEntityPicks(command: Command): EntityPickSpec<unknown>[] {\n return pendingEntityPicks.get(command) ?? [];\n}\n\n/**\n * Whether the named option has an entity picker registered on this\n * command. Convenience for the resolver's value steps.\n */\nexport function hasEntityPick(command: Command, name: string): boolean {\n return getEntityPicks(command).some((pick) => pick.name === name);\n}\n\n/**\n * Defines an entity picker for one option. The returned spec is registered\n * via `deferEntityPicks`.\n */\nexport function entityPick<T>(spec: EntityPickSpec<T>): EntityPickSpec<T> {\n return spec;\n}\n\n/**\n * Runs every entity pick registered for this command whose option is still\n * unspecified. No-op when prompting is disallowed. Returns false when the\n * user escaped the picker -- the caller should return without running the\n * action's body (same shape as a failed getTokens()).\n */\nexport async function resolveEntityPicks(command: Command): Promise<boolean> {\n if (!canPrompt()) return true;\n for (const pick of getEntityPicks(command)) {\n // Commands branch on the RAW option value (options.secretId); writing\n // through setOptionValueWithSource keeps both that object and the\n // resolver's own getOptionValue reads consistent.\n if (command.getOptionValue(pick.name)) continue;\n let entities: unknown[];\n try {\n entities = await pick.load();\n } catch {\n return true; // loader failure: leave the action's own error path\n }\n if (entities.length === 0) return true;\n if (entities.length === 1) {\n // Single-option paradigm (gap-fill prompts): one candidate is no\n // choice -- auto-select it, mirroring the single-profile host\n // picker and the single-child stub auto-descend.\n apply(command, pick, entities[0]);\n continue;\n }\n // The → key (armed by the hint) opens the invocation\n // editor, then re-prompts this picker -- discover-and-edit without\n // leaving the flow. Editorial loop, ESCAPE still declines the pick.\n let chosen: unknown | typeof ESCAPE | typeof RIGHT;\n for (;;) {\n const { liveOptionPreviewFor } =\n await import('../../cli/ResolveInteractiveInputs');\n chosen = await escapableSelect<unknown>({\n message: pick.message ?? `Select ${pick.kind} to act on:`,\n hint: editableOptionsHint(command),\n // LIVE footer: the highlighted entity's label (the exact value\n // the real apply writes) shadows the target option per render,\n // so the footer shows the command gaining that pick BEFORE\n // <enter> commits. `pick.label` maps entity -> option value --\n // the same mapping the committed apply uses.\n preview: liveOptionPreviewFor(command, pick.name, (entity) =>\n pick.label(entity)\n ),\n choices: entities.map((entity) => {\n const description = pick.description?.(entity);\n return {\n value: entity,\n name: pick.label(entity),\n ...(description !== undefined ? { description } : {}),\n };\n }),\n });\n if (chosen !== RIGHT) break;\n const { runInvocationEditorForCommand } =\n await import('../../cli/ResolveInteractiveInputs');\n await runInvocationEditorForCommand(command);\n }\n if (chosen === EXIT_ALL) {\n // Exit-all: revoke the deferred authoring print (nothing may be\n // left behind for an abandoned flow) and THROW the unwind signal\n // -- it propagates through the action body to app.ts's top-level\n // handler, ending the session from any nesting depth.\n const { revokeAuthoringPrint } = await import('./AuthoringPrintState');\n revokeAuthoringPrint();\n throw EXIT_ALL_SIGNAL;\n }\n if (chosen === ESCAPE) {\n // User declined to run (single ESC): revoke the deferred authoring\n // print so the postAction fallback (non-auth commands' flush site)\n // leaves nothing behind for an abandoned flow -- same contract as\n // the one-of error path skipping postAction entirely.\n const { revokeAuthoringPrint } = await import('./AuthoringPrintState');\n revokeAuthoringPrint();\n return false;\n }\n apply(command, pick, chosen);\n }\n // The deferred authoring print: this\n // function is the flush site for commands whose entity picks are the\n // last command-mutating interactive step. Two shapes exist: pick-first\n // (`(pick) && (await getTokens())` -- picks run BEFORE auth) and\n // pick-after-auth (esv variable set, secret store mapping delete --\n // picks run AFTER auth). In both, flushing HERE puts the eventual\n // command directly above the action's results. Gated on auth already\n // having succeeded: a pick-first flow whose auth then fails must not\n // print (the command never ran). When auth has NOT succeeded yet, the\n // getTokens wrapper flushes instead (no picks pending -> it doesn't\n // skip). Non-interactive sessions (canPrompt false, early return)\n // never reach this.\n {\n const { authSucceededForFlush, flushAuthoringPrint } =\n await import('./AuthoringPrintState');\n if (authSucceededForFlush()) {\n flushAuthoringPrint();\n }\n }\n return true;\n}\n\nfunction apply(\n command: Command,\n pick: EntityPickSpec<unknown>,\n entity: unknown\n): void {\n command.setOptionValueWithSource(pick.name, pick.label(entity), 'cli');\n}\n"],"mappings":";;;;;;;;;;AAgFA,MAAM,qCAAqB,IAAI,QAA4C;;;;;;;AAQ3E,SAAgB,iBACd,SACA,OACM;CACN,mBAAmB,IAAI,SAAS,CAC9B,GAAI,mBAAmB,IAAI,OAAO,KAAK,CAAC,GACxC,GAAG,KACL,CAAC;AACH;;;;;;AAOA,SAAgB,eAAe,SAA6C;CAC1E,OAAO,mBAAmB,IAAI,OAAO,KAAK,CAAC;AAC7C;;;;;AAMA,SAAgB,cAAc,SAAkB,MAAuB;CACrE,OA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