@diafunc/cli 0.11.0 → 0.12.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/README.md +19 -0
- package/dist/bin/diafunc.js +17 -5
- package/dist/bin/diafunc.js.map +1 -1
- package/dist/{chunk-GDW62ZQX.js → chunk-4NQYIRPF.js} +906 -138
- package/dist/chunk-4NQYIRPF.js.map +1 -0
- package/dist/{chunk-Q7HG2CUO.js → chunk-A4VM56MK.js} +2 -2
- package/dist/{chunk-Q7HG2CUO.js.map → chunk-A4VM56MK.js.map} +1 -1
- package/dist/{chunk-77KBGDMM.js → chunk-BUHZT6MT.js} +2 -2
- package/dist/src/index.js +2 -2
- package/dist/update-check-SNH7P32S.js +8 -0
- package/package.json +1 -1
- package/dist/chunk-GDW62ZQX.js.map +0 -1
- package/dist/update-check-ZCS3IYOZ.js +0 -8
- /package/dist/{chunk-77KBGDMM.js.map → chunk-BUHZT6MT.js.map} +0 -0
- /package/dist/{update-check-ZCS3IYOZ.js.map → update-check-SNH7P32S.js.map} +0 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-A4VM56MK.js";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
|
-
import
|
|
7
|
-
import chalk35 from "chalk";
|
|
6
|
+
import chalk37 from "chalk";
|
|
8
7
|
|
|
9
8
|
// src/commands/auth/login.ts
|
|
10
9
|
import chalk4 from "chalk";
|
|
@@ -108,8 +107,8 @@ var ApiError = class _ApiError extends Error {
|
|
|
108
107
|
return withDetails;
|
|
109
108
|
}
|
|
110
109
|
};
|
|
111
|
-
function looksLikeMarkup(
|
|
112
|
-
const head =
|
|
110
|
+
function looksLikeMarkup(text2) {
|
|
111
|
+
const head = text2.trimStart().slice(0, 200).toLowerCase();
|
|
113
112
|
return head.startsWith("<") || head.includes("<html") || head.includes("<!doctype");
|
|
114
113
|
}
|
|
115
114
|
var NetworkError = class extends Error {
|
|
@@ -214,8 +213,8 @@ async function parseErrorBody(response) {
|
|
|
214
213
|
const body = await response.json();
|
|
215
214
|
return ApiError.fromBody(response.status, body);
|
|
216
215
|
}
|
|
217
|
-
const
|
|
218
|
-
return new ApiError(response.status,
|
|
216
|
+
const text2 = (await response.text()).trim();
|
|
217
|
+
return new ApiError(response.status, text2 || response.statusText);
|
|
219
218
|
} catch {
|
|
220
219
|
return new ApiError(response.status, response.statusText);
|
|
221
220
|
}
|
|
@@ -324,11 +323,11 @@ ${bodyPreview}`));
|
|
|
324
323
|
return void 0;
|
|
325
324
|
}
|
|
326
325
|
const contentType = response.headers.get("content-type") ?? "";
|
|
327
|
-
const
|
|
326
|
+
const text2 = await response.text();
|
|
328
327
|
if (contentType.includes("application/json")) {
|
|
329
|
-
return
|
|
328
|
+
return text2 ? JSON.parse(text2) : void 0;
|
|
330
329
|
}
|
|
331
|
-
return
|
|
330
|
+
return text2;
|
|
332
331
|
},
|
|
333
332
|
async requestRaw(opts) {
|
|
334
333
|
const response = await doRequest(opts);
|
|
@@ -812,9 +811,9 @@ function empty(noun, options) {
|
|
|
812
811
|
}
|
|
813
812
|
console.log(chalk2.dim(`No ${noun}.`));
|
|
814
813
|
}
|
|
815
|
-
function heading(
|
|
814
|
+
function heading(text2) {
|
|
816
815
|
console.log();
|
|
817
|
-
console.log(chalk2.bold(
|
|
816
|
+
console.log(chalk2.bold(text2));
|
|
818
817
|
}
|
|
819
818
|
|
|
820
819
|
// src/util/errors.ts
|
|
@@ -916,8 +915,8 @@ async function deviceCodeLogin(config, profile) {
|
|
|
916
915
|
body: new URLSearchParams({ client_id: DEVICE_CLIENT_ID, scope: DEVICE_SCOPE }).toString()
|
|
917
916
|
});
|
|
918
917
|
if (!deviceResponse.ok) {
|
|
919
|
-
const
|
|
920
|
-
failure(`Failed to start device-code flow: ${
|
|
918
|
+
const text2 = await deviceResponse.text();
|
|
919
|
+
failure(`Failed to start device-code flow: ${text2 || deviceResponse.statusText}`);
|
|
921
920
|
process.exit(1);
|
|
922
921
|
}
|
|
923
922
|
const device = await deviceResponse.json();
|
|
@@ -1078,22 +1077,22 @@ function terminalWidth() {
|
|
|
1078
1077
|
if (!columns || !Number.isFinite(columns)) return 80;
|
|
1079
1078
|
return Math.max(40, columns - 1);
|
|
1080
1079
|
}
|
|
1081
|
-
function displayWidth(
|
|
1082
|
-
return stripAnsi(
|
|
1080
|
+
function displayWidth(text2) {
|
|
1081
|
+
return stripAnsi(text2).length;
|
|
1083
1082
|
}
|
|
1084
1083
|
var ANSI_PATTERN = new RegExp("\\u001B\\[[0-9;]*m", "g");
|
|
1085
|
-
function stripAnsi(
|
|
1086
|
-
return
|
|
1084
|
+
function stripAnsi(text2) {
|
|
1085
|
+
return text2.replace(ANSI_PATTERN, "");
|
|
1087
1086
|
}
|
|
1088
|
-
function truncate(
|
|
1089
|
-
const plain = stripAnsi(
|
|
1090
|
-
if (plain.length <= width) return
|
|
1087
|
+
function truncate(text2, width) {
|
|
1088
|
+
const plain = stripAnsi(text2);
|
|
1089
|
+
if (plain.length <= width) return text2;
|
|
1091
1090
|
if (width <= 1) return plain.slice(0, Math.max(0, width));
|
|
1092
1091
|
return plain.slice(0, width - 1) + "\u2026";
|
|
1093
1092
|
}
|
|
1094
|
-
function wrap(
|
|
1093
|
+
function wrap(text2, width) {
|
|
1095
1094
|
const out = [];
|
|
1096
|
-
for (const paragraph of
|
|
1095
|
+
for (const paragraph of text2.split("\n")) {
|
|
1097
1096
|
if (paragraph.length <= width) {
|
|
1098
1097
|
out.push(paragraph);
|
|
1099
1098
|
continue;
|
|
@@ -1121,7 +1120,7 @@ function wrap(text, width) {
|
|
|
1121
1120
|
import chalk5 from "chalk";
|
|
1122
1121
|
var ABSENT = "\u2014";
|
|
1123
1122
|
function renderValue(value, kind = "text", plain = false) {
|
|
1124
|
-
const dim = (
|
|
1123
|
+
const dim = (text2) => plain ? text2 : chalk5.dim(text2);
|
|
1125
1124
|
if (value === null || value === void 0 || value === "") return dim(ABSENT);
|
|
1126
1125
|
switch (kind) {
|
|
1127
1126
|
case "id":
|
|
@@ -1144,8 +1143,8 @@ function renderValue(value, kind = "text", plain = false) {
|
|
|
1144
1143
|
}
|
|
1145
1144
|
}
|
|
1146
1145
|
function renderNumber(value, plain) {
|
|
1147
|
-
const
|
|
1148
|
-
return plain ?
|
|
1146
|
+
const text2 = typeof value === "number" && !plain ? formatNumber(value) : String(value);
|
|
1147
|
+
return plain ? text2 : chalk5.cyan(text2);
|
|
1149
1148
|
}
|
|
1150
1149
|
function renderArray(value, plain, dim) {
|
|
1151
1150
|
if (value.length === 0) return dim(ABSENT);
|
|
@@ -1361,9 +1360,9 @@ function budgetWidths(specs, cells) {
|
|
|
1361
1360
|
}
|
|
1362
1361
|
return widths;
|
|
1363
1362
|
}
|
|
1364
|
-
function pad(
|
|
1365
|
-
const deficit = width - displayWidth(
|
|
1366
|
-
return deficit > 0 ?
|
|
1363
|
+
function pad(text2, width) {
|
|
1364
|
+
const deficit = width - displayWidth(text2);
|
|
1365
|
+
return deficit > 0 ? text2 + " ".repeat(deficit) : text2;
|
|
1367
1366
|
}
|
|
1368
1367
|
function forPipe(value, spec) {
|
|
1369
1368
|
const rendered = stripAnsi(renderValue(value, spec.kind ?? inferKind(spec.key), true));
|
|
@@ -2951,15 +2950,15 @@ import chalk12 from "chalk";
|
|
|
2951
2950
|
// src/util/references.ts
|
|
2952
2951
|
function parseEntityReference(ref, overrides) {
|
|
2953
2952
|
const config = loadConfig();
|
|
2954
|
-
const
|
|
2953
|
+
const defaultProject2 = overrides?.project ?? config.defaults.project;
|
|
2955
2954
|
const defaultBranch = overrides?.branch ?? config.defaults.branch ?? "main";
|
|
2956
2955
|
if (!ref.includes("/") && ref.includes(":")) {
|
|
2957
2956
|
const [entityId, entityBranch] = ref.split(":");
|
|
2958
|
-
if (!
|
|
2957
|
+
if (!defaultProject2) {
|
|
2959
2958
|
throw new Error("No default project configured. Set one with: diafunc config set defaults.project <id>");
|
|
2960
2959
|
}
|
|
2961
2960
|
return {
|
|
2962
|
-
projectId:
|
|
2961
|
+
projectId: defaultProject2,
|
|
2963
2962
|
projectBranch: defaultBranch,
|
|
2964
2963
|
entityId,
|
|
2965
2964
|
entityBranch: entityBranch || defaultBranch
|
|
@@ -2967,11 +2966,11 @@ function parseEntityReference(ref, overrides) {
|
|
|
2967
2966
|
}
|
|
2968
2967
|
const parts = ref.split("/");
|
|
2969
2968
|
if (parts.length === 1) {
|
|
2970
|
-
if (!
|
|
2969
|
+
if (!defaultProject2) {
|
|
2971
2970
|
throw new Error("No default project configured. Set one with: diafunc config set defaults.project <id>");
|
|
2972
2971
|
}
|
|
2973
2972
|
return {
|
|
2974
|
-
projectId:
|
|
2973
|
+
projectId: defaultProject2,
|
|
2975
2974
|
projectBranch: defaultBranch,
|
|
2976
2975
|
entityId: parts[0],
|
|
2977
2976
|
entityBranch: defaultBranch
|
|
@@ -3015,11 +3014,11 @@ function parseEntityReference(ref, overrides) {
|
|
|
3015
3014
|
}
|
|
3016
3015
|
function parseProjectReference(ref, overrides) {
|
|
3017
3016
|
const config = loadConfig();
|
|
3018
|
-
const
|
|
3017
|
+
const defaultProject2 = overrides?.project ?? config.defaults.project;
|
|
3019
3018
|
const defaultBranch = overrides?.branch ?? config.defaults.branch ?? "main";
|
|
3020
3019
|
if (!ref.includes("/")) {
|
|
3021
3020
|
return {
|
|
3022
|
-
projectId: ref ||
|
|
3021
|
+
projectId: ref || defaultProject2,
|
|
3023
3022
|
projectBranch: defaultBranch
|
|
3024
3023
|
};
|
|
3025
3024
|
}
|
|
@@ -4066,8 +4065,8 @@ Examples:
|
|
|
4066
4065
|
fs3.writeFileSync(options.out, buffer);
|
|
4067
4066
|
success(`Content saved to ${options.out}`);
|
|
4068
4067
|
} else {
|
|
4069
|
-
const
|
|
4070
|
-
process.stdout.write(
|
|
4068
|
+
const text2 = await response.text();
|
|
4069
|
+
process.stdout.write(text2);
|
|
4071
4070
|
}
|
|
4072
4071
|
} catch (error) {
|
|
4073
4072
|
handleError(error);
|
|
@@ -4267,8 +4266,8 @@ function registerEventCommands(program) {
|
|
|
4267
4266
|
});
|
|
4268
4267
|
event.command("create").description("Create one or more events (body from JSON file or stdin)").argument("[file]", "JSON file containing a BareEvent array; defaults to stdin").action(async (file) => {
|
|
4269
4268
|
try {
|
|
4270
|
-
const
|
|
4271
|
-
const body = file ?
|
|
4269
|
+
const fs15 = await import("fs");
|
|
4270
|
+
const body = file ? fs15.readFileSync(file, "utf-8") : await new Promise((resolve, reject) => {
|
|
4272
4271
|
let data = "";
|
|
4273
4272
|
process.stdin.setEncoding("utf-8");
|
|
4274
4273
|
process.stdin.on("data", (chunk) => {
|
|
@@ -5721,14 +5720,14 @@ var MarkdownRenderer = class {
|
|
|
5721
5720
|
}
|
|
5722
5721
|
const heading2 = line.match(/^(#{1,6})\s+(.*)$/);
|
|
5723
5722
|
if (heading2) {
|
|
5724
|
-
const
|
|
5725
|
-
return ["", heading2[1].length <= 2 ? chalk18.bold.underline(
|
|
5723
|
+
const text2 = inline(heading2[2]);
|
|
5724
|
+
return ["", heading2[1].length <= 2 ? chalk18.bold.underline(text2) : chalk18.bold(text2)];
|
|
5726
5725
|
}
|
|
5727
5726
|
if (/^\s*([-*_])\1{2,}\s*$/.test(line)) {
|
|
5728
5727
|
return [chalk18.dim("\u2500".repeat(Math.min(this.width, 60)))];
|
|
5729
5728
|
}
|
|
5730
|
-
const
|
|
5731
|
-
if (
|
|
5729
|
+
const quote2 = line.match(/^\s*>\s?(.*)$/);
|
|
5730
|
+
if (quote2) return [chalk18.dim(` \u2502 ${inline(quote2[1])}`)];
|
|
5732
5731
|
const bullet = line.match(/^(\s*)[-*+]\s+(.*)$/);
|
|
5733
5732
|
if (bullet) {
|
|
5734
5733
|
return wrapWithIndent(
|
|
@@ -5754,12 +5753,12 @@ function renderMarkdown(source, width = terminalWidth()) {
|
|
|
5754
5753
|
const renderer = new MarkdownRenderer(width);
|
|
5755
5754
|
return [...renderer.push(source), ...renderer.flush()].join("\n");
|
|
5756
5755
|
}
|
|
5757
|
-
function wrapWithIndent(
|
|
5758
|
-
return wrap(
|
|
5756
|
+
function wrapWithIndent(text2, indent, width) {
|
|
5757
|
+
return wrap(text2, width).map((l, i) => i === 0 ? l : " ".repeat(indent) + l);
|
|
5759
5758
|
}
|
|
5760
|
-
function inline(
|
|
5759
|
+
function inline(text2) {
|
|
5761
5760
|
const codeSpans = [];
|
|
5762
|
-
let working =
|
|
5761
|
+
let working = text2.replace(/`([^`]+)`/g, (_m, code) => {
|
|
5763
5762
|
codeSpans.push(code);
|
|
5764
5763
|
return `${CODE_OPEN}${codeSpans.length - 1}${CODE_CLOSE}`;
|
|
5765
5764
|
});
|
|
@@ -5856,7 +5855,7 @@ var HELP = [
|
|
|
5856
5855
|
];
|
|
5857
5856
|
async function runChatRepl(options) {
|
|
5858
5857
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
5859
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
5858
|
+
const { getUpdateNotice } = await import("./update-check-SNH7P32S.js");
|
|
5860
5859
|
let sessionId = options.session;
|
|
5861
5860
|
let lastReportedSession;
|
|
5862
5861
|
console.log(chalk19.bold("Diafunc chat") + chalk19.dim(" \xB7 /help for commands, /quit to exit"));
|
|
@@ -6224,19 +6223,19 @@ function renderResults(items) {
|
|
|
6224
6223
|
}
|
|
6225
6224
|
var HIGHLIGHT_OPEN = /<mark>/g;
|
|
6226
6225
|
var HIGHLIGHT_CLOSE = /<\/mark>/g;
|
|
6227
|
-
function highlight(
|
|
6228
|
-
const parts =
|
|
6226
|
+
function highlight(text2) {
|
|
6227
|
+
const parts = text2.split(HIGHLIGHT_OPEN);
|
|
6229
6228
|
return parts.map((part, i) => {
|
|
6230
6229
|
if (i === 0) return chalk20.dim(part);
|
|
6231
6230
|
const [marked, ...rest] = part.split(HIGHLIGHT_CLOSE);
|
|
6232
6231
|
return chalk20.bold.cyan(marked) + chalk20.dim(rest.join(""));
|
|
6233
6232
|
}).join("");
|
|
6234
6233
|
}
|
|
6235
|
-
function stripHighlight(
|
|
6236
|
-
return
|
|
6234
|
+
function stripHighlight(text2) {
|
|
6235
|
+
return text2.replace(HIGHLIGHT_OPEN, "").replace(HIGHLIGHT_CLOSE, "");
|
|
6237
6236
|
}
|
|
6238
|
-
function collapse(
|
|
6239
|
-
const flat =
|
|
6237
|
+
function collapse(text2) {
|
|
6238
|
+
const flat = text2.replace(/\s+/g, " ").trim();
|
|
6240
6239
|
return flat.length > 160 ? `${flat.slice(0, 159)}\u2026` : flat;
|
|
6241
6240
|
}
|
|
6242
6241
|
|
|
@@ -6729,51 +6728,6 @@ var DEPTH_PRESETS = [
|
|
|
6729
6728
|
];
|
|
6730
6729
|
var DEFAULT_HOURS = "4";
|
|
6731
6730
|
var DEFAULT_BUDGET = "10000";
|
|
6732
|
-
var PromptCancelled = class extends Error {
|
|
6733
|
-
constructor() {
|
|
6734
|
-
super("Cancelled.");
|
|
6735
|
-
this.name = "PromptCancelled";
|
|
6736
|
-
}
|
|
6737
|
-
};
|
|
6738
|
-
function createInquirerPrompter() {
|
|
6739
|
-
const load = () => import("@inquirer/prompts");
|
|
6740
|
-
const guard = async (work) => {
|
|
6741
|
-
try {
|
|
6742
|
-
return await work();
|
|
6743
|
-
} catch (error) {
|
|
6744
|
-
if (error instanceof Error && error.name === "ExitPromptError") throw new PromptCancelled();
|
|
6745
|
-
throw error;
|
|
6746
|
-
}
|
|
6747
|
-
};
|
|
6748
|
-
return {
|
|
6749
|
-
async input(options) {
|
|
6750
|
-
const { input } = await load();
|
|
6751
|
-
return guard(() => input(options));
|
|
6752
|
-
},
|
|
6753
|
-
async select(options) {
|
|
6754
|
-
const { select } = await load();
|
|
6755
|
-
return guard(() => select(options));
|
|
6756
|
-
},
|
|
6757
|
-
async checkbox(options) {
|
|
6758
|
-
const { checkbox } = await load();
|
|
6759
|
-
return guard(() => checkbox(options));
|
|
6760
|
-
},
|
|
6761
|
-
async confirm(options) {
|
|
6762
|
-
const { confirm } = await load();
|
|
6763
|
-
return guard(() => confirm(options));
|
|
6764
|
-
}
|
|
6765
|
-
};
|
|
6766
|
-
}
|
|
6767
|
-
function canPrompt(outputFormat, noInteractive) {
|
|
6768
|
-
if (noInteractive) return false;
|
|
6769
|
-
if (outputFormat !== "human") return false;
|
|
6770
|
-
return Boolean(process.stdin.isTTY) && isInteractive();
|
|
6771
|
-
}
|
|
6772
|
-
function whyNoPrompt(outputFormat, noInteractive) {
|
|
6773
|
-
if (noInteractive) return "--no-interactive is set";
|
|
6774
|
-
if (outputFormat !== "human") return `--output ${outputFormat} does not prompt`;
|
|
6775
|
-
return "there is no terminal to ask";
|
|
6776
|
-
}
|
|
6777
6731
|
async function promptCreationFields(prompter, supplied, fallbackName) {
|
|
6778
6732
|
const name = supplied.name ?? await prompter.input({
|
|
6779
6733
|
message: "Analysis name",
|
|
@@ -6850,11 +6804,11 @@ async function promptRunFields(prompter, options) {
|
|
|
6850
6804
|
validate: (chosen) => chosen.length > 0 || "Pick at least one target column."
|
|
6851
6805
|
});
|
|
6852
6806
|
} else {
|
|
6853
|
-
const
|
|
6807
|
+
const typed2 = await prompter.input({
|
|
6854
6808
|
message: "Target column names (comma-separated)",
|
|
6855
6809
|
validate: (value) => splitCsv(value).length > 0 || "Name at least one target column."
|
|
6856
6810
|
});
|
|
6857
|
-
targets = splitCsv(
|
|
6811
|
+
targets = splitCsv(typed2);
|
|
6858
6812
|
}
|
|
6859
6813
|
}
|
|
6860
6814
|
const remaining = named.filter((c) => !targets.includes(c.name));
|
|
@@ -6881,10 +6835,10 @@ async function promptRunFields(prompter, options) {
|
|
|
6881
6835
|
if (wanted) {
|
|
6882
6836
|
const collected = [];
|
|
6883
6837
|
for (; ; ) {
|
|
6884
|
-
const
|
|
6838
|
+
const question2 = await prompter.input({
|
|
6885
6839
|
message: collected.length === 0 ? "Question" : "Another question (blank to finish)"
|
|
6886
6840
|
});
|
|
6887
|
-
const trimmed =
|
|
6841
|
+
const trimmed = question2.trim();
|
|
6888
6842
|
if (trimmed.length === 0) break;
|
|
6889
6843
|
collected.push(trimmed);
|
|
6890
6844
|
}
|
|
@@ -6978,11 +6932,11 @@ var FIELD_COMMANDS = {
|
|
|
6978
6932
|
budget: "budget <id> <credits>",
|
|
6979
6933
|
targets: "targets <id> <csv>"
|
|
6980
6934
|
};
|
|
6981
|
-
function explainMissingRunFields(analysisId, missing,
|
|
6935
|
+
function explainMissingRunFields(analysisId, missing, reason2) {
|
|
6982
6936
|
const commands = missing.map((f) => `'diafunc analyze ${FIELD_COMMANDS[f].replace("<id>", analysisId)}'`);
|
|
6983
6937
|
const columns = missing.includes("targets") ? ` Column names: 'diafunc analyze columns ${analysisId}'.` : "";
|
|
6984
6938
|
return {
|
|
6985
|
-
message: `Analysis ${analysisId} cannot run yet: it has no ${joinList(missing)}, and ${
|
|
6939
|
+
message: `Analysis ${analysisId} cannot run yet: it has no ${joinList(missing)}, and ${reason2}.`,
|
|
6986
6940
|
suggestion: `Set ${missing.length === 1 ? "it" : "them"} with ${commands.join(", ")}, then rerun.${columns}`
|
|
6987
6941
|
};
|
|
6988
6942
|
}
|
|
@@ -6991,6 +6945,61 @@ function joinList(items) {
|
|
|
6991
6945
|
return `${items.slice(0, -1).join(", ")} or ${items[items.length - 1]}`;
|
|
6992
6946
|
}
|
|
6993
6947
|
|
|
6948
|
+
// src/prompting/prompter.ts
|
|
6949
|
+
var PromptCancelled = class extends Error {
|
|
6950
|
+
constructor() {
|
|
6951
|
+
super("Cancelled.");
|
|
6952
|
+
this.name = "PromptCancelled";
|
|
6953
|
+
}
|
|
6954
|
+
};
|
|
6955
|
+
function createInquirerPrompter() {
|
|
6956
|
+
const load = () => import("@inquirer/prompts");
|
|
6957
|
+
const guard = async (work) => {
|
|
6958
|
+
try {
|
|
6959
|
+
return await work();
|
|
6960
|
+
} catch (error) {
|
|
6961
|
+
if (error instanceof Error && error.name === "ExitPromptError") throw new PromptCancelled();
|
|
6962
|
+
throw error;
|
|
6963
|
+
}
|
|
6964
|
+
};
|
|
6965
|
+
return {
|
|
6966
|
+
async input(options) {
|
|
6967
|
+
const { input } = await load();
|
|
6968
|
+
return guard(() => input(options));
|
|
6969
|
+
},
|
|
6970
|
+
async select(options) {
|
|
6971
|
+
const { select } = await load();
|
|
6972
|
+
return guard(() => select(options));
|
|
6973
|
+
},
|
|
6974
|
+
async checkbox(options) {
|
|
6975
|
+
const { checkbox } = await load();
|
|
6976
|
+
return guard(() => checkbox(options));
|
|
6977
|
+
},
|
|
6978
|
+
async confirm(options) {
|
|
6979
|
+
const { confirm } = await load();
|
|
6980
|
+
return guard(() => confirm(options));
|
|
6981
|
+
},
|
|
6982
|
+
async search(options) {
|
|
6983
|
+
const { search } = await load();
|
|
6984
|
+
return guard(() => search({
|
|
6985
|
+
message: options.message,
|
|
6986
|
+
pageSize: 12,
|
|
6987
|
+
source: async (term) => options.source(term ?? "")
|
|
6988
|
+
}));
|
|
6989
|
+
}
|
|
6990
|
+
};
|
|
6991
|
+
}
|
|
6992
|
+
function canPrompt(outputFormat, noInteractive) {
|
|
6993
|
+
if (noInteractive) return false;
|
|
6994
|
+
if (outputFormat !== "human") return false;
|
|
6995
|
+
return Boolean(process.stdin.isTTY) && isInteractive();
|
|
6996
|
+
}
|
|
6997
|
+
function whyNoPrompt(outputFormat, noInteractive) {
|
|
6998
|
+
if (noInteractive) return "--no-interactive is set";
|
|
6999
|
+
if (outputFormat !== "human") return `--output ${outputFormat} does not prompt`;
|
|
7000
|
+
return "there is no terminal to ask";
|
|
7001
|
+
}
|
|
7002
|
+
|
|
6994
7003
|
// src/commands/analyze/index.ts
|
|
6995
7004
|
var POLL_INTERVAL_MS = 2e3;
|
|
6996
7005
|
var COLUMN_READ_ATTEMPTS = 3;
|
|
@@ -7005,6 +7014,9 @@ function getOutputFormat15(cmd) {
|
|
|
7005
7014
|
const globalOpts = cmd.optsWithGlobals();
|
|
7006
7015
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
7007
7016
|
}
|
|
7017
|
+
function noInteractiveFlag(cmd) {
|
|
7018
|
+
return cmd.optsWithGlobals().interactive === false;
|
|
7019
|
+
}
|
|
7008
7020
|
function parseCsv(value) {
|
|
7009
7021
|
if (value === void 0) return null;
|
|
7010
7022
|
return value.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
@@ -7027,11 +7039,7 @@ function multipartFromFile(file) {
|
|
|
7027
7039
|
return formData;
|
|
7028
7040
|
}
|
|
7029
7041
|
function reportCommandError(error) {
|
|
7030
|
-
if (error instanceof PromptCancelled)
|
|
7031
|
-
console.log();
|
|
7032
|
-
console.log(chalk26.dim("Cancelled."));
|
|
7033
|
-
process.exit(EXIT_CANCELLED);
|
|
7034
|
-
}
|
|
7042
|
+
if (error instanceof PromptCancelled) throw error;
|
|
7035
7043
|
handleError(error);
|
|
7036
7044
|
}
|
|
7037
7045
|
async function runAnalysis(file, options, cmd) {
|
|
@@ -7040,7 +7048,8 @@ async function runAnalysis(file, options, cmd) {
|
|
|
7040
7048
|
process.exit(EXIT_FAILURE);
|
|
7041
7049
|
}
|
|
7042
7050
|
const outputFormat = getOutputFormat15(cmd);
|
|
7043
|
-
const
|
|
7051
|
+
const noInteractive = noInteractiveFlag(cmd);
|
|
7052
|
+
const interactive = canPrompt(outputFormat, noInteractive);
|
|
7044
7053
|
const api = createApiClient();
|
|
7045
7054
|
if (options.preset) {
|
|
7046
7055
|
const opt = await api.analysis.getPreset(options.preset);
|
|
@@ -7058,7 +7067,7 @@ async function runAnalysis(file, options, cmd) {
|
|
|
7058
7067
|
const flagTargets = parseCsv(options.targets);
|
|
7059
7068
|
if (!interactive && (flagTargets === null || flagTargets.length === 0)) {
|
|
7060
7069
|
usageError(
|
|
7061
|
-
`Target columns are required, and ${whyNoPrompt(outputFormat,
|
|
7070
|
+
`Target columns are required, and ${whyNoPrompt(outputFormat, noInteractive)}.`,
|
|
7062
7071
|
`Pass --targets <csv> or --preset <id>. The names are the column headers of ${path7.basename(file)}.`
|
|
7063
7072
|
);
|
|
7064
7073
|
}
|
|
@@ -7215,12 +7224,12 @@ async function monitorRun(api, analysisId, runId, cmd) {
|
|
|
7215
7224
|
status.stop();
|
|
7216
7225
|
}
|
|
7217
7226
|
}
|
|
7218
|
-
function safeParse(
|
|
7227
|
+
function safeParse(text2) {
|
|
7219
7228
|
try {
|
|
7220
|
-
const parsed = JSON.parse(
|
|
7221
|
-
return parsed && typeof parsed === "object" ? parsed : { output:
|
|
7229
|
+
const parsed = JSON.parse(text2);
|
|
7230
|
+
return parsed && typeof parsed === "object" ? parsed : { output: text2 };
|
|
7222
7231
|
} catch {
|
|
7223
|
-
return { output:
|
|
7232
|
+
return { output: text2 };
|
|
7224
7233
|
}
|
|
7225
7234
|
}
|
|
7226
7235
|
async function reportTerminalRun(api, config, run, analysisId, runId, outputFormat) {
|
|
@@ -7302,12 +7311,12 @@ async function getAnalysisDetails(analysisId, options, cmd) {
|
|
|
7302
7311
|
}
|
|
7303
7312
|
}
|
|
7304
7313
|
var INTRODUCTION_PREVIEW_LINES = 3;
|
|
7305
|
-
function isLong(
|
|
7306
|
-
return Boolean(
|
|
7314
|
+
function isLong(text2) {
|
|
7315
|
+
return Boolean(text2 && text2.split("\n").length > INTRODUCTION_PREVIEW_LINES);
|
|
7307
7316
|
}
|
|
7308
|
-
function abbreviate(
|
|
7309
|
-
if (!isLong(
|
|
7310
|
-
const lines =
|
|
7317
|
+
function abbreviate(text2) {
|
|
7318
|
+
if (!isLong(text2)) return text2;
|
|
7319
|
+
const lines = text2.split("\n").filter((l) => l.trim().length > 0);
|
|
7311
7320
|
return `${lines.slice(0, INTRODUCTION_PREVIEW_LINES).join("\n")}
|
|
7312
7321
|
\u2026`;
|
|
7313
7322
|
}
|
|
@@ -7344,7 +7353,7 @@ async function watchAnalysis(analysisId, cmd) {
|
|
|
7344
7353
|
console.log(`Watching run ${latest.runId} for analysis ${recipe.analysisId} ...`);
|
|
7345
7354
|
await monitorRun(api, recipe.analysisId, latest.runId, cmd);
|
|
7346
7355
|
}
|
|
7347
|
-
async function rerunAnalysis(analysisId,
|
|
7356
|
+
async function rerunAnalysis(analysisId, cmd) {
|
|
7348
7357
|
const api = createApiClient();
|
|
7349
7358
|
const found = await api.analysis.get(analysisId);
|
|
7350
7359
|
if (!found.analysis) {
|
|
@@ -7355,7 +7364,7 @@ async function rerunAnalysis(analysisId, options, cmd) {
|
|
|
7355
7364
|
const missing = missingRunFields(analysis);
|
|
7356
7365
|
if (missing.length > 0) {
|
|
7357
7366
|
const outputFormat = getOutputFormat15(cmd);
|
|
7358
|
-
const noInteractive =
|
|
7367
|
+
const noInteractive = noInteractiveFlag(cmd);
|
|
7359
7368
|
if (!canPrompt(outputFormat, noInteractive)) {
|
|
7360
7369
|
const { message, suggestion } = explainMissingRunFields(
|
|
7361
7370
|
analysisId,
|
|
@@ -7612,7 +7621,7 @@ async function updateTriggerCmd(triggerId, options, cmd) {
|
|
|
7612
7621
|
}
|
|
7613
7622
|
function registerAnalyzeCommand(program) {
|
|
7614
7623
|
const analyze = program.command("analyze").description("Run and manage automatic analyses");
|
|
7615
|
-
analyze.command("run", { isDefault: true }).description("Create an analysis from a data file, configure it and run it (the default: `analyze <file>`)").argument("[file]", "CSV or Excel file to analyze").option("--name <name>", "Analysis name (asked for, or derived from the filename)").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC (default: PRIVATE)").option("--hours <hours>", `Computation time in hours (default: ${DEFAULT_HOURS}; preset value used when --preset set)`).option("--budget <credits>", `Credit budget (default: ${DEFAULT_BUDGET}; preset value used when --preset set)`).option("--targets <csv>", "Comma-separated target column names (required when not interactive)").option("--questions <csv>", "Comma-separated questions to answer").option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction at notebook position 0").option("--preset <id>", "Apply a saved preset as defaults (explicit flags override preset values)").
|
|
7624
|
+
analyze.command("run", { isDefault: true }).description("Create an analysis from a data file, configure it and run it (the default: `analyze <file>`)").argument("[file]", "CSV or Excel file to analyze").option("--name <name>", "Analysis name (asked for, or derived from the filename)").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC (default: PRIVATE)").option("--hours <hours>", `Computation time in hours (default: ${DEFAULT_HOURS}; preset value used when --preset set)`).option("--budget <credits>", `Credit budget (default: ${DEFAULT_BUDGET}; preset value used when --preset set)`).option("--targets <csv>", "Comma-separated target column names (required when not interactive)").option("--questions <csv>", "Comma-separated questions to answer").option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction at notebook position 0").option("--preset <id>", "Apply a saved preset as defaults (explicit flags override preset values)").action(async (file, options, cmd) => {
|
|
7616
7625
|
try {
|
|
7617
7626
|
if (!file) {
|
|
7618
7627
|
analyze.help();
|
|
@@ -7651,9 +7660,9 @@ function registerAnalyzeCommand(program) {
|
|
|
7651
7660
|
handleError(error);
|
|
7652
7661
|
}
|
|
7653
7662
|
});
|
|
7654
|
-
analyze.command("rerun").description("Queue a fresh run on an existing analysis (asks for anything a run still needs)").argument("<id>", "Analysis ID to rerun").
|
|
7663
|
+
analyze.command("rerun").description("Queue a fresh run on an existing analysis (asks for anything a run still needs)").argument("<id>", "Analysis ID to rerun").action(async (id, _options, cmd) => {
|
|
7655
7664
|
try {
|
|
7656
|
-
await rerunAnalysis(id,
|
|
7665
|
+
await rerunAnalysis(id, cmd);
|
|
7657
7666
|
} catch (error) {
|
|
7658
7667
|
reportCommandError(error);
|
|
7659
7668
|
}
|
|
@@ -7686,11 +7695,11 @@ function registerAnalyzeCommand(program) {
|
|
|
7686
7695
|
handleError(error);
|
|
7687
7696
|
}
|
|
7688
7697
|
});
|
|
7689
|
-
analyze.command("description").description("Set or clear the analysis description (empty string clears)").argument("<id>", "Analysis ID").argument("<text>", "New description (empty string to clear)").action(async (id,
|
|
7698
|
+
analyze.command("description").description("Set or clear the analysis description (empty string clears)").argument("<id>", "Analysis ID").argument("<text>", "New description (empty string to clear)").action(async (id, text2, _options, cmd) => {
|
|
7690
7699
|
try {
|
|
7691
7700
|
await patchAndPrint(
|
|
7692
7701
|
id,
|
|
7693
|
-
|
|
7702
|
+
text2,
|
|
7694
7703
|
(api, aid, v) => api.analysis.patchDescription(aid, { description: v === "" ? null : v }),
|
|
7695
7704
|
"Description",
|
|
7696
7705
|
cmd
|
|
@@ -8788,8 +8797,8 @@ function windowLabel(u) {
|
|
|
8788
8797
|
return `billing cycle ${u.year}-${String(u.month).padStart(2, "0")}`;
|
|
8789
8798
|
}
|
|
8790
8799
|
function printUtilizationHuman(u, label) {
|
|
8791
|
-
const
|
|
8792
|
-
console.log(label ? chalk31.bold(label) + " " + chalk31.dim(
|
|
8800
|
+
const when2 = windowLabel(u);
|
|
8801
|
+
console.log(label ? chalk31.bold(label) + " " + chalk31.dim(when2) : chalk31.bold(when2));
|
|
8793
8802
|
if (u.types.length === 0) {
|
|
8794
8803
|
console.log(chalk31.dim(" (no usage)"));
|
|
8795
8804
|
return;
|
|
@@ -9105,7 +9114,7 @@ function registerShellCommand(program) {
|
|
|
9105
9114
|
});
|
|
9106
9115
|
const api = createApiClient();
|
|
9107
9116
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
9108
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
9117
|
+
const { getUpdateNotice } = await import("./update-check-SNH7P32S.js");
|
|
9109
9118
|
const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
|
|
9110
9119
|
console.log(chalk32.bold("Diafunc shell") + chalk32.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
|
|
9111
9120
|
console.log(chalk32.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
@@ -9322,6 +9331,757 @@ function registerUninstallCommand(program) {
|
|
|
9322
9331
|
});
|
|
9323
9332
|
}
|
|
9324
9333
|
|
|
9334
|
+
// src/prompting/command.ts
|
|
9335
|
+
import { Command } from "commander";
|
|
9336
|
+
var commanderOriginal = Command.prototype;
|
|
9337
|
+
var DiafuncCommand = class _DiafuncCommand extends Command {
|
|
9338
|
+
/** Gaps recorded during the current parse, in the order commander found them. */
|
|
9339
|
+
pendingInputs = [];
|
|
9340
|
+
/** Set on the program only; every command reads it from there. */
|
|
9341
|
+
promptEnvironment = {};
|
|
9342
|
+
createCommand(name) {
|
|
9343
|
+
return new _DiafuncCommand(name);
|
|
9344
|
+
}
|
|
9345
|
+
missingArgument(name) {
|
|
9346
|
+
if (!this.mayPrompt()) {
|
|
9347
|
+
commanderOriginal.missingArgument.call(this, name);
|
|
9348
|
+
return;
|
|
9349
|
+
}
|
|
9350
|
+
const index = this.registeredArguments.findIndex((a) => a.name() === name);
|
|
9351
|
+
const argument = this.registeredArguments[index];
|
|
9352
|
+
this.pendingInputs.push({
|
|
9353
|
+
kind: "argument",
|
|
9354
|
+
name,
|
|
9355
|
+
index,
|
|
9356
|
+
description: argument?.description ?? "",
|
|
9357
|
+
variadic: Boolean(argument?.variadic)
|
|
9358
|
+
});
|
|
9359
|
+
}
|
|
9360
|
+
missingMandatoryOptionValue(option) {
|
|
9361
|
+
if (!this.mayPrompt()) {
|
|
9362
|
+
commanderOriginal.missingMandatoryOptionValue.call(this, option);
|
|
9363
|
+
return;
|
|
9364
|
+
}
|
|
9365
|
+
this.pendingInputs.push({
|
|
9366
|
+
kind: "option",
|
|
9367
|
+
name: option.attributeName(),
|
|
9368
|
+
flag: option.long ?? option.flags,
|
|
9369
|
+
description: option.description ?? "",
|
|
9370
|
+
variadic: Boolean(option.variadic)
|
|
9371
|
+
});
|
|
9372
|
+
}
|
|
9373
|
+
/** The environment set on the program. */
|
|
9374
|
+
environment() {
|
|
9375
|
+
let root = this;
|
|
9376
|
+
while (root.parent) root = root.parent;
|
|
9377
|
+
return root instanceof _DiafuncCommand ? root.promptEnvironment : {};
|
|
9378
|
+
}
|
|
9379
|
+
mayPrompt() {
|
|
9380
|
+
const forced = this.environment().interactive;
|
|
9381
|
+
if (forced !== void 0) return forced;
|
|
9382
|
+
const globals = this.optsWithGlobals();
|
|
9383
|
+
const output = globals.output ?? loadConfig().defaults.output ?? "human";
|
|
9384
|
+
return canPrompt(output, globals.interactive === false);
|
|
9385
|
+
}
|
|
9386
|
+
};
|
|
9387
|
+
|
|
9388
|
+
// src/prompting/fill.ts
|
|
9389
|
+
import chalk36 from "chalk";
|
|
9390
|
+
|
|
9391
|
+
// src/prompting/resolvers.ts
|
|
9392
|
+
var PROJECT_ROLES = ["OWNER", "ADMIN", "DEVELOPER", "GUEST"];
|
|
9393
|
+
var TRIGGER_TYPES = ["SCHEDULE", "EVENT", "LINK", "MANUAL"];
|
|
9394
|
+
var ANALYSIS_TRIGGER_KINDS = ["ONCE", "CRON"];
|
|
9395
|
+
var VISIBILITIES = ["PRIVATE", "PUBLIC"];
|
|
9396
|
+
var SHELLS = ["bash", "zsh", "fish"];
|
|
9397
|
+
var CONFIG_KEYS = ["defaults.project", "defaults.branch", "defaults.output"];
|
|
9398
|
+
var ENTITY_TYPE_BY_GROUP = {
|
|
9399
|
+
table: "table",
|
|
9400
|
+
function: "function",
|
|
9401
|
+
trigger: "function",
|
|
9402
|
+
schedule: "function"
|
|
9403
|
+
};
|
|
9404
|
+
var TEXT = { kind: "text" };
|
|
9405
|
+
var TEXT_OR_EMPTY = { kind: "text", allowEmpty: true };
|
|
9406
|
+
var POSITIVE = { kind: "number", min: 0, integer: false, exclusive: true };
|
|
9407
|
+
var INDEX = { kind: "number", min: 0, integer: true };
|
|
9408
|
+
var BY_COMMAND = {
|
|
9409
|
+
"analyze segment": { "<name>": { kind: "analysisColumns", multiple: false, allowEmpty: true } },
|
|
9410
|
+
"analyze targets": { "<csv>": { kind: "analysisColumns", multiple: true, allowEmpty: false } },
|
|
9411
|
+
"analyze questions": { "<csv>": TEXT_OR_EMPTY },
|
|
9412
|
+
"analyze description": { "<text>": TEXT_OR_EMPTY },
|
|
9413
|
+
"analyze introduction": { "<markdown>": TEXT_OR_EMPTY },
|
|
9414
|
+
"analyze presets save": { "--targets": TEXT, "--hours": POSITIVE, "--budget": POSITIVE },
|
|
9415
|
+
"branch merge": {
|
|
9416
|
+
"--source": { kind: "entity", form: "ref" },
|
|
9417
|
+
"--target": { kind: "project", withBranch: true }
|
|
9418
|
+
},
|
|
9419
|
+
"branch create": { "<branchName>": TEXT },
|
|
9420
|
+
"branch delete": { "<branchName>": { kind: "projectBranch", projectFrom: "projectId" } },
|
|
9421
|
+
"admin backup restore-project": { "<projectBranch>": { kind: "projectBranch", projectFrom: "projectId" } },
|
|
9422
|
+
"data-sources create": {
|
|
9423
|
+
"--project-id": { kind: "project", withBranch: false },
|
|
9424
|
+
"--project-branch": { kind: "projectBranch", projectFrom: "projectId" },
|
|
9425
|
+
"--target-entity-id": { kind: "entity", form: "id", contentType: "table", projectFrom: "projectId" },
|
|
9426
|
+
"--target-entity-branch": { kind: "text", defaultValue: "main" },
|
|
9427
|
+
"--type": { kind: "connectorType" }
|
|
9428
|
+
},
|
|
9429
|
+
"table-exporters create": {
|
|
9430
|
+
"--function-project": { kind: "project", withBranch: false },
|
|
9431
|
+
"--function-entity": { kind: "entity", form: "id", contentType: "function", projectFrom: "functionProject" },
|
|
9432
|
+
"--format": TEXT
|
|
9433
|
+
},
|
|
9434
|
+
"table exports get": { "--ref": { kind: "entity", form: "ref", contentType: "table" } },
|
|
9435
|
+
"table export": { "<format>": { kind: "exportFormat" } },
|
|
9436
|
+
"entity export": { "<entityIds>": { kind: "entity", form: "id", projectFrom: "project", multiple: true } },
|
|
9437
|
+
"notebook export": {
|
|
9438
|
+
"<notebookIds>": { kind: "entity", form: "id", contentType: "notebook", projectFrom: "project", multiple: true }
|
|
9439
|
+
},
|
|
9440
|
+
"link delete": { "<linkId>": { kind: "link" } },
|
|
9441
|
+
"link create": { "<linkId>": TEXT },
|
|
9442
|
+
"config profile use": { "<name>": { kind: "profile" } },
|
|
9443
|
+
"config profile remove": { "<name>": { kind: "profile" } },
|
|
9444
|
+
"config get": { "<key>": { kind: "choice", choices: CONFIG_KEYS } },
|
|
9445
|
+
"config set": { "<key>": { kind: "choice", choices: CONFIG_KEYS } },
|
|
9446
|
+
"project members invite": { "<userId>": TEXT, "<role>": { kind: "choice", choices: PROJECT_ROLES } },
|
|
9447
|
+
"project members join": { "<userId>": TEXT },
|
|
9448
|
+
"trigger create": { "--type": { kind: "choice", choices: TRIGGER_TYPES } },
|
|
9449
|
+
"analyze triggers create": { "--kind": { kind: "choice", choices: ANALYSIS_TRIGGER_KINDS } },
|
|
9450
|
+
"function outputs": { "<evaluationId>": TEXT },
|
|
9451
|
+
"team create": { "--seats": { kind: "number", min: 1, integer: true } },
|
|
9452
|
+
"team seats preview": { "<count>": { kind: "number", min: 1, integer: true } },
|
|
9453
|
+
"team seats set": { "<count>": { kind: "number", min: 1, integer: true } }
|
|
9454
|
+
};
|
|
9455
|
+
var BY_NAME = {
|
|
9456
|
+
projectId: { kind: "project", withBranch: false },
|
|
9457
|
+
projectRef: { kind: "project", withBranch: true },
|
|
9458
|
+
project: { kind: "project", withBranch: true },
|
|
9459
|
+
teamId: { kind: "team" },
|
|
9460
|
+
invitationId: { kind: "teamInvitation" },
|
|
9461
|
+
analysisId: { kind: "analysis" },
|
|
9462
|
+
sessionId: { kind: "chatSession" },
|
|
9463
|
+
tokenId: { kind: "apiToken" },
|
|
9464
|
+
resource: { kind: "tokenResource" },
|
|
9465
|
+
scopes: { kind: "choices", choices: VALID_SCOPES },
|
|
9466
|
+
evaluationId: { kind: "evaluation" },
|
|
9467
|
+
eventId: { kind: "event" },
|
|
9468
|
+
occurrenceId: { kind: "occurrence" },
|
|
9469
|
+
exportId: { kind: "tableExport" },
|
|
9470
|
+
invoiceNumber: { kind: "invoice" },
|
|
9471
|
+
fileName: { kind: "invoiceDocument" },
|
|
9472
|
+
shell: { kind: "choice", choices: SHELLS },
|
|
9473
|
+
vis: { kind: "choice", choices: VISIBILITIES },
|
|
9474
|
+
kind: { kind: "choice", choices: ANALYSIS_TRIGGER_KINDS },
|
|
9475
|
+
date: { kind: "date" },
|
|
9476
|
+
file: { kind: "file" },
|
|
9477
|
+
email: { kind: "text", email: true },
|
|
9478
|
+
index: INDEX,
|
|
9479
|
+
row: INDEX,
|
|
9480
|
+
col: INDEX,
|
|
9481
|
+
count: INDEX,
|
|
9482
|
+
version: { kind: "number", min: 1, integer: true },
|
|
9483
|
+
hours: POSITIVE,
|
|
9484
|
+
credits: POSITIVE,
|
|
9485
|
+
seats: { kind: "number", min: 1, integer: true },
|
|
9486
|
+
value: TEXT_OR_EMPTY,
|
|
9487
|
+
// Free text: names, messages and ids the reader is creating rather than choosing.
|
|
9488
|
+
name: TEXT,
|
|
9489
|
+
newId: TEXT,
|
|
9490
|
+
message: TEXT,
|
|
9491
|
+
query: TEXT,
|
|
9492
|
+
title: TEXT,
|
|
9493
|
+
token: TEXT,
|
|
9494
|
+
subscriptionToken: TEXT,
|
|
9495
|
+
forkProjectId: TEXT,
|
|
9496
|
+
targetBranch: TEXT,
|
|
9497
|
+
bucketName: TEXT,
|
|
9498
|
+
objectName: TEXT,
|
|
9499
|
+
template: TEXT,
|
|
9500
|
+
plan: TEXT,
|
|
9501
|
+
schedule: TEXT,
|
|
9502
|
+
consumerType: TEXT,
|
|
9503
|
+
consumerId: TEXT,
|
|
9504
|
+
format: TEXT,
|
|
9505
|
+
key: TEXT
|
|
9506
|
+
};
|
|
9507
|
+
function tokenOf(input) {
|
|
9508
|
+
return input.kind === "option" ? input.flag ?? `--${input.name}` : `<${input.name}>`;
|
|
9509
|
+
}
|
|
9510
|
+
function specFor(path11, input) {
|
|
9511
|
+
const exact = BY_COMMAND[path11]?.[tokenOf(input)];
|
|
9512
|
+
if (exact) return exact;
|
|
9513
|
+
const group = path11.split(" ")[0];
|
|
9514
|
+
const sub = path11.split(" ").slice(0, 2).join(" ");
|
|
9515
|
+
switch (input.name) {
|
|
9516
|
+
case "ref":
|
|
9517
|
+
case "sourceRef":
|
|
9518
|
+
case "targetRef":
|
|
9519
|
+
return { kind: "entity", form: "ref", contentType: ENTITY_TYPE_BY_GROUP[group] };
|
|
9520
|
+
case "userId":
|
|
9521
|
+
return group === "team" ? { kind: "teamMember" } : { kind: "projectMember" };
|
|
9522
|
+
case "id":
|
|
9523
|
+
if (sub === "analyze presets") return { kind: "preset" };
|
|
9524
|
+
if (group === "analyze") return { kind: "analysis" };
|
|
9525
|
+
if (group === "data-sources") return { kind: "dataSource" };
|
|
9526
|
+
if (group === "skeleton") return { kind: "skeleton" };
|
|
9527
|
+
if (group === "table-exporters") return { kind: "tableExporter" };
|
|
9528
|
+
if (group === "status") return { kind: "statusComponent" };
|
|
9529
|
+
return null;
|
|
9530
|
+
case "runId":
|
|
9531
|
+
if (group === "analyze") return { kind: "analysisRun" };
|
|
9532
|
+
if (group === "data-sources") return { kind: "dataSourceRun" };
|
|
9533
|
+
return null;
|
|
9534
|
+
case "triggerId":
|
|
9535
|
+
if (group === "analyze") return { kind: "analysisTrigger" };
|
|
9536
|
+
if (group === "trigger") return { kind: "functionTrigger" };
|
|
9537
|
+
return null;
|
|
9538
|
+
case "role":
|
|
9539
|
+
return { kind: "choice", choices: PROJECT_ROLES };
|
|
9540
|
+
case "type":
|
|
9541
|
+
return null;
|
|
9542
|
+
default:
|
|
9543
|
+
return BY_NAME[input.name] ?? null;
|
|
9544
|
+
}
|
|
9545
|
+
}
|
|
9546
|
+
function dependencies(spec) {
|
|
9547
|
+
switch (spec.kind) {
|
|
9548
|
+
case "teamMember":
|
|
9549
|
+
case "teamInvitation":
|
|
9550
|
+
return ["teamId"];
|
|
9551
|
+
case "projectMember":
|
|
9552
|
+
return ["projectId"];
|
|
9553
|
+
case "analysisColumns":
|
|
9554
|
+
return ["id"];
|
|
9555
|
+
case "evaluation":
|
|
9556
|
+
return ["ref", "date"];
|
|
9557
|
+
case "functionTrigger":
|
|
9558
|
+
case "event":
|
|
9559
|
+
case "tableExport":
|
|
9560
|
+
return ["ref"];
|
|
9561
|
+
case "occurrence":
|
|
9562
|
+
return ["ref", "eventId"];
|
|
9563
|
+
case "link":
|
|
9564
|
+
return ["sourceRef"];
|
|
9565
|
+
case "tokenResource":
|
|
9566
|
+
return ["resourceType"];
|
|
9567
|
+
case "dataSourceRun":
|
|
9568
|
+
return ["id"];
|
|
9569
|
+
case "invoiceDocument":
|
|
9570
|
+
return ["invoiceNumber"];
|
|
9571
|
+
case "projectBranch":
|
|
9572
|
+
return [spec.projectFrom];
|
|
9573
|
+
case "entity":
|
|
9574
|
+
return spec.projectFrom ? [spec.projectFrom] : [];
|
|
9575
|
+
default:
|
|
9576
|
+
return [];
|
|
9577
|
+
}
|
|
9578
|
+
}
|
|
9579
|
+
|
|
9580
|
+
// src/prompting/pickers.ts
|
|
9581
|
+
import * as fs14 from "fs";
|
|
9582
|
+
import chalk35 from "chalk";
|
|
9583
|
+
var SEARCH_THRESHOLD = 10;
|
|
9584
|
+
var TYPE_IT = "\0type-it";
|
|
9585
|
+
async function askFor(spec, input, ctx) {
|
|
9586
|
+
const prefilled = ctx.prefill.get(input.name);
|
|
9587
|
+
if (prefilled !== void 0) return prefilled;
|
|
9588
|
+
switch (spec.kind) {
|
|
9589
|
+
case "project":
|
|
9590
|
+
return askProject(ctx, spec.withBranch, messageFor(input, "Project"));
|
|
9591
|
+
case "entity":
|
|
9592
|
+
return askEntity(ctx, spec, input);
|
|
9593
|
+
case "team":
|
|
9594
|
+
return listed(ctx, "teams", messageFor(input, "Team"), async () => (await ctx.api().admin.listMyTeams()).map((t) => ({ label: t.name, value: t.id, hint: t.id })));
|
|
9595
|
+
case "teamMember": {
|
|
9596
|
+
const teamId = text(ctx, "teamId");
|
|
9597
|
+
return listed(ctx, "team members", messageFor(input, "Team member"), async () => teamId ? (await ctx.api().admin.listTeamMembers(teamId)).filter((m) => !m.removedAt).map((m) => ({ label: m.name ?? m.email ?? m.userId, value: m.userId, hint: `${m.role} \xB7 ${m.userId}` })) : []);
|
|
9598
|
+
}
|
|
9599
|
+
case "projectMember": {
|
|
9600
|
+
const projectId = text(ctx, "projectId")?.split("/")[0];
|
|
9601
|
+
return listed(ctx, "project members", messageFor(input, "Project member"), async () => projectId ? (await ctx.api().admin.getProjectMembers(projectId)).map((m) => ({ label: m.userId, value: m.userId, hint: m.role })) : []);
|
|
9602
|
+
}
|
|
9603
|
+
case "teamInvitation": {
|
|
9604
|
+
const teamId = text(ctx, "teamId");
|
|
9605
|
+
return listed(ctx, "invitations", messageFor(input, "Invitation"), async () => teamId ? (await ctx.api().admin.listTeamInvitations(teamId)).map((i) => ({ label: i.email, value: i.invitationId, hint: `${i.role} \xB7 ${i.invitationId}` })) : []);
|
|
9606
|
+
}
|
|
9607
|
+
case "analysis":
|
|
9608
|
+
return askAnalysis(ctx, messageFor(input, "Analysis"));
|
|
9609
|
+
case "analysisRun": {
|
|
9610
|
+
const analysisId = text(ctx, "id") ?? await askAnalysis(ctx, "Analysis");
|
|
9611
|
+
return listed(ctx, "runs", messageFor(input, "Run"), async () => {
|
|
9612
|
+
const runs = await ctx.api().analysis.getRunsForAnalysis(analysisId, 20);
|
|
9613
|
+
const unfinished = (s) => !["COMPLETED", "FAILED", "CANCELLED"].includes(s);
|
|
9614
|
+
return [...runs].sort((a, b) => Number(unfinished(b.state)) - Number(unfinished(a.state))).map((r) => ({ label: r.state, value: r.runId, hint: `${when(r.submittedAt)} \xB7 ${r.runId}` }));
|
|
9615
|
+
});
|
|
9616
|
+
}
|
|
9617
|
+
case "preset":
|
|
9618
|
+
return listed(ctx, "presets", messageFor(input, "Preset"), async () => (await ctx.api().analysis.getPresets()).filter((p) => p.presetId).map((p) => ({ label: p.name, value: p.presetId, hint: p.presetId })));
|
|
9619
|
+
case "analysisTrigger": {
|
|
9620
|
+
const analysisId = text(ctx, "analysisId") ?? await askAnalysis(ctx, "Analysis");
|
|
9621
|
+
return listed(ctx, "triggers", messageFor(input, "Trigger"), async () => (await ctx.api().analysis.listTriggers(analysisId)).map((t) => ({
|
|
9622
|
+
label: `${t.kind} ${t.scheduleSpec}`,
|
|
9623
|
+
value: t.triggerId,
|
|
9624
|
+
hint: `${t.active ? "active" : "paused"} \xB7 ${t.triggerId}`
|
|
9625
|
+
})));
|
|
9626
|
+
}
|
|
9627
|
+
case "analysisColumns":
|
|
9628
|
+
return askColumns(ctx, spec, input);
|
|
9629
|
+
case "evaluation":
|
|
9630
|
+
return askEvaluation(ctx, input);
|
|
9631
|
+
case "functionTrigger": {
|
|
9632
|
+
const ref = entityRef(ctx, "ref");
|
|
9633
|
+
return listed(ctx, "triggers", messageFor(input, "Trigger"), async () => ref ? (await ctx.api().evaluation.getTriggers(ref.projectId, ref.projectBranch, ref.entityId, ref.entityBranch)).filter((t) => t.triggerId).map((t) => ({ label: `${t.type}${t.expression ? ` ${t.expression}` : ""}`, value: t.triggerId, hint: t.triggerId })) : []);
|
|
9634
|
+
}
|
|
9635
|
+
case "chatSession":
|
|
9636
|
+
return listed(ctx, "chat sessions", messageFor(input, "Chat session"), async () => (await ctx.api().language.getSessions()).map((s) => ({ label: s.title || "(untitled)", value: s.sessionId, hint: `${s.modified} \xB7 ${s.sessionId}` })));
|
|
9637
|
+
case "apiToken":
|
|
9638
|
+
return listed(ctx, "API tokens", messageFor(input, "API token"), async () => (await ctx.api().admin.getApiTokens()).map((t) => ({
|
|
9639
|
+
label: t.name,
|
|
9640
|
+
value: t.tokenId,
|
|
9641
|
+
hint: `${t.resourceType} ${t.resourceId} \xB7 ${t.scopes.join(",")}`
|
|
9642
|
+
})));
|
|
9643
|
+
case "tokenResource":
|
|
9644
|
+
return text(ctx, "resourceType")?.toLowerCase() === "team" ? listed(ctx, "teams", "Team", async () => (await ctx.api().admin.listMyTeams()).map((t) => ({ label: t.name, value: t.id, hint: t.id }))) : askProject(ctx, false, "Project");
|
|
9645
|
+
case "dataSource":
|
|
9646
|
+
return listed(ctx, "data sources", messageFor(input, "Data source"), async () => (await ctx.api().storage.listDataSources(defaultProject(ctx))).map((d) => ({ label: d.name, value: d.id, hint: `${d.type} \xB7 ${d.id}` })));
|
|
9647
|
+
case "dataSourceRun": {
|
|
9648
|
+
const id = text(ctx, "id");
|
|
9649
|
+
return listed(ctx, "runs", messageFor(input, "Run"), async () => id ? (await ctx.api().storage.listDataSourceRuns(id, 20)).map((r) => ({ label: r.status, value: r.runId, hint: `${r.startedAt ?? ""} \xB7 ${r.runId}` })) : []);
|
|
9650
|
+
}
|
|
9651
|
+
case "skeleton": {
|
|
9652
|
+
const projectId = defaultProject(ctx) ?? await askProject(ctx, false, "Project");
|
|
9653
|
+
return listed(ctx, "skeletons", messageFor(input, "Skeleton"), async () => (await ctx.api().storage.listSkeletons(projectId)).map((s) => ({ label: s.name, value: s.id, hint: `${s.template} \xB7 ${s.id}` })));
|
|
9654
|
+
}
|
|
9655
|
+
case "tableExporter":
|
|
9656
|
+
return listed(ctx, "exporters", messageFor(input, "Exporter"), async () => (await ctx.api().storage.listUserDefinedExporters()).filter((e) => e.id).map((e) => ({ label: e.name, value: e.id, hint: `${e.format} \xB7 ${e.id}` })));
|
|
9657
|
+
case "tableExport": {
|
|
9658
|
+
const ref = entityRef(ctx, "ref");
|
|
9659
|
+
return listed(ctx, "exports", messageFor(input, "Export"), async () => ref ? (await ctx.api().storage.listExports(ref)).map((e) => ({
|
|
9660
|
+
label: e.filename,
|
|
9661
|
+
value: e.exportId,
|
|
9662
|
+
hint: `${e.finished ? e.succeeded ? "done" : "failed" : `${Math.round(e.progress * 100)}%`} \xB7 ${e.exportId}`
|
|
9663
|
+
})) : []);
|
|
9664
|
+
}
|
|
9665
|
+
case "invoice":
|
|
9666
|
+
return listed(ctx, "invoices", messageFor(input, "Invoice"), async () => {
|
|
9667
|
+
const invoices = await ctx.api().admin.getInvoices();
|
|
9668
|
+
for (const i of invoices) ctx.prefill.set(`invoiceKind:${i.invoiceNumber}`, i.kind ?? "INVOICE");
|
|
9669
|
+
return invoices.map((i) => ({
|
|
9670
|
+
label: `#${i.invoiceNumber} ${i.periodFrom ?? ""}\u2013${i.periodTo ?? ""}`,
|
|
9671
|
+
value: String(i.invoiceNumber),
|
|
9672
|
+
hint: `${i.status ?? ""} \xB7 ${i.total ?? ""} ${i.currency ?? ""}`.trim()
|
|
9673
|
+
}));
|
|
9674
|
+
});
|
|
9675
|
+
case "invoiceDocument": {
|
|
9676
|
+
const number = text(ctx, "invoiceNumber");
|
|
9677
|
+
const kind = number ? ctx.prefill.get(`invoiceKind:${number}`) : void 0;
|
|
9678
|
+
const slug = kind && /credit/i.test(kind) ? "credit-note" : "invoice";
|
|
9679
|
+
return typed(ctx, messageFor(input, "Document file name"), { defaultValue: number ? `diafunc-${slug}-${number}.pdf` : void 0 });
|
|
9680
|
+
}
|
|
9681
|
+
case "projectBranch": {
|
|
9682
|
+
const projectId = text(ctx, spec.projectFrom)?.split("/")[0];
|
|
9683
|
+
return listed(ctx, "branches", messageFor(input, "Branch"), async () => projectId ? (await ctx.api().storage.getProjectBranches(projectId)).map((b) => ({ label: b, value: b })) : []);
|
|
9684
|
+
}
|
|
9685
|
+
case "event":
|
|
9686
|
+
return askEvent(ctx, input);
|
|
9687
|
+
case "occurrence": {
|
|
9688
|
+
const ref = entityRef(ctx, "ref");
|
|
9689
|
+
const eventId = text(ctx, "eventId");
|
|
9690
|
+
return listed(ctx, "occurrences", messageFor(input, "Occurrence"), async () => ref ? (await ctx.api().storage.getEvents(ref)).filter((e) => !eventId || e.eventId === eventId).map((e) => ({ label: e.occurrenceId, value: e.occurrenceId, hint: e.type })) : []);
|
|
9691
|
+
}
|
|
9692
|
+
case "link": {
|
|
9693
|
+
const ref = entityRef(ctx, "sourceRef");
|
|
9694
|
+
return listed(ctx, "links", messageFor(input, "Link"), async () => ref ? (await ctx.api().storage.getLinkIds("FORWARD", ref)).map((id) => ({ label: id, value: id })) : []);
|
|
9695
|
+
}
|
|
9696
|
+
case "exportFormat":
|
|
9697
|
+
return listed(ctx, "export formats", messageFor(input, "Export format"), async () => (await ctx.api().storage.getSupportedExportFormats()).formats.map((f) => ({ label: f.displayName, value: f.id, hint: `${f.id} \xB7 ${f.category}` })));
|
|
9698
|
+
case "connectorType":
|
|
9699
|
+
return listed(ctx, "connector types", messageFor(input, "Connector type"), async () => (await ctx.api().storage.listDataSourceConnectorTypes()).map((t) => ({ label: t, value: t })));
|
|
9700
|
+
case "profile":
|
|
9701
|
+
return listed(ctx, "profiles", messageFor(input, "Profile"), async () => Object.keys(loadConfig().profiles).map((p) => ({ label: p, value: p })));
|
|
9702
|
+
case "statusComponent":
|
|
9703
|
+
return listed(ctx, "components", messageFor(input, "Component"), async () => (await createStatusService().getComponents()).map((c) => ({ label: c.id, value: c.id, hint: `${c.state} \xB7 ${c.domainId}` })));
|
|
9704
|
+
case "choice":
|
|
9705
|
+
return choose(ctx, question(input), spec.choices.map((c) => ({ label: c, value: c })));
|
|
9706
|
+
case "choices": {
|
|
9707
|
+
const chosen = await ctx.prompter.checkbox({
|
|
9708
|
+
message: question(input),
|
|
9709
|
+
choices: spec.choices.map((c) => ({ name: c, value: c })),
|
|
9710
|
+
validate: (picked) => picked.length > 0 || "Pick at least one."
|
|
9711
|
+
});
|
|
9712
|
+
return chosen.join(",");
|
|
9713
|
+
}
|
|
9714
|
+
case "file":
|
|
9715
|
+
return typed(ctx, question(input), {
|
|
9716
|
+
validate: (value) => fs14.existsSync(value.trim()) || `No file at ${value.trim()}.`
|
|
9717
|
+
});
|
|
9718
|
+
case "number":
|
|
9719
|
+
return typed(ctx, question(input), { validate: numberRule(spec) });
|
|
9720
|
+
case "date":
|
|
9721
|
+
return typed(ctx, question(input), {
|
|
9722
|
+
defaultValue: currentUtcHour(),
|
|
9723
|
+
validate: (value) => /^\d{4}-\d{2}-\d{2}-\d{2}$/.test(value.trim()) || "Use YYYY-MM-DD-HH, in UTC."
|
|
9724
|
+
});
|
|
9725
|
+
case "text":
|
|
9726
|
+
return typed(ctx, question(input), {
|
|
9727
|
+
allowEmpty: spec.allowEmpty,
|
|
9728
|
+
defaultValue: spec.defaultValue,
|
|
9729
|
+
validate: spec.email ? (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value.trim()) || "That is not an email address." : void 0
|
|
9730
|
+
});
|
|
9731
|
+
}
|
|
9732
|
+
}
|
|
9733
|
+
async function askProject(ctx, withBranch, message) {
|
|
9734
|
+
const projectId = await fromIndex(ctx, message, { contentType: "project" }, (item) => item.projectId);
|
|
9735
|
+
if (!withBranch) return projectId;
|
|
9736
|
+
let branches = [];
|
|
9737
|
+
try {
|
|
9738
|
+
branches = await ctx.api().storage.getProjectBranches(projectId);
|
|
9739
|
+
} catch {
|
|
9740
|
+
}
|
|
9741
|
+
if (branches.length <= 1) return projectId;
|
|
9742
|
+
const branch = await choose(ctx, "Branch", branches.map((b) => ({ label: b, value: b })), "main");
|
|
9743
|
+
return branch === "main" ? projectId : `${projectId}/${branch}`;
|
|
9744
|
+
}
|
|
9745
|
+
async function askEntity(ctx, spec, input) {
|
|
9746
|
+
const { projectId, projectBranch } = await projectContext(ctx, spec.projectFrom);
|
|
9747
|
+
const noun = spec.contentType ? capitalize(spec.contentType) : "Entity";
|
|
9748
|
+
const query = { contentType: spec.contentType, projectId, projectBranch };
|
|
9749
|
+
const answer = (item) => spec.form === "id" ? item.entityId : [item.projectId, item.projectBranch, item.entityId, ...item.entityBranch && item.entityBranch !== "main" ? [item.entityBranch] : []].join("/");
|
|
9750
|
+
if (spec.multiple) {
|
|
9751
|
+
let items = [];
|
|
9752
|
+
try {
|
|
9753
|
+
items = await indexItems(ctx, "*", query, 200);
|
|
9754
|
+
} catch (error) {
|
|
9755
|
+
ctx.note(`Could not list them (${reason(error)}).`);
|
|
9756
|
+
}
|
|
9757
|
+
if (items.length === 0) {
|
|
9758
|
+
const typed2 = await typedValue(ctx, `${question(input)} (space-separated)`);
|
|
9759
|
+
return typed2.split(/[\s,]+/).filter(Boolean);
|
|
9760
|
+
}
|
|
9761
|
+
return ctx.prompter.checkbox({
|
|
9762
|
+
message: messageFor(input, `${noun}s`),
|
|
9763
|
+
choices: items.map((item) => ({ name: labelled(item.name || item.entityId, item.entityId), value: answer(item) })),
|
|
9764
|
+
validate: (picked) => picked.length > 0 || "Pick at least one."
|
|
9765
|
+
});
|
|
9766
|
+
}
|
|
9767
|
+
return fromIndex(ctx, messageFor(input, noun), query, answer);
|
|
9768
|
+
}
|
|
9769
|
+
async function projectContext(ctx, projectFrom) {
|
|
9770
|
+
const config = loadConfig();
|
|
9771
|
+
const raw = (projectFrom ? text(ctx, projectFrom) : void 0) ?? ctx.globals.project ?? config.defaults.project ?? await askProject(ctx, true, "Project");
|
|
9772
|
+
const [projectId, branch] = raw.split("/");
|
|
9773
|
+
return { projectId, projectBranch: branch || ctx.globals.branch || config.defaults.branch || "main" };
|
|
9774
|
+
}
|
|
9775
|
+
var FIRST_PAGE = 100;
|
|
9776
|
+
async function fromIndex(ctx, message, query, answer) {
|
|
9777
|
+
let firstPage = null;
|
|
9778
|
+
let warned = false;
|
|
9779
|
+
const toChoice = (item) => ({
|
|
9780
|
+
name: labelled(item.name || item.entityId || item.projectId, item.entityId ?? item.projectId),
|
|
9781
|
+
value: answer(item)
|
|
9782
|
+
});
|
|
9783
|
+
const picked = await ctx.prompter.search({
|
|
9784
|
+
message,
|
|
9785
|
+
source: async (term) => {
|
|
9786
|
+
try {
|
|
9787
|
+
firstPage ??= await indexItems(ctx, "*", query, FIRST_PAGE);
|
|
9788
|
+
const needle = term.trim().toLowerCase();
|
|
9789
|
+
let items = needle ? firstPage.filter((item) => `${item.name ?? ""} ${item.entityId ?? item.projectId}`.toLowerCase().includes(needle)) : firstPage;
|
|
9790
|
+
if (needle && items.length === 0) items = await indexItems(ctx, term.trim(), query, 30);
|
|
9791
|
+
return [...items.map(toChoice), typeItChoice()];
|
|
9792
|
+
} catch (error) {
|
|
9793
|
+
if (!warned) ctx.note(`Could not search (${reason(error)}).`);
|
|
9794
|
+
warned = true;
|
|
9795
|
+
return [typeItChoice()];
|
|
9796
|
+
}
|
|
9797
|
+
}
|
|
9798
|
+
});
|
|
9799
|
+
return picked === TYPE_IT ? typedValue(ctx, message) : picked;
|
|
9800
|
+
}
|
|
9801
|
+
async function indexItems(ctx, term, query, limit) {
|
|
9802
|
+
const page = await ctx.api().index.searchPage({
|
|
9803
|
+
query: term,
|
|
9804
|
+
limit,
|
|
9805
|
+
contentType: query.contentType ?? null,
|
|
9806
|
+
projectId: query.projectId ?? null,
|
|
9807
|
+
projectBranch: query.projectId ? query.projectBranch ?? "main" : null
|
|
9808
|
+
});
|
|
9809
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9810
|
+
return page.items.filter((item) => {
|
|
9811
|
+
if (query.contentType !== "project" && !item.entityId) return false;
|
|
9812
|
+
const key = [item.contentType, item.projectId, item.projectBranch, item.entityId, item.entityBranch].join("|");
|
|
9813
|
+
if (seen.has(key)) return false;
|
|
9814
|
+
seen.add(key);
|
|
9815
|
+
return true;
|
|
9816
|
+
});
|
|
9817
|
+
}
|
|
9818
|
+
async function askAnalysis(ctx, message) {
|
|
9819
|
+
return listed(ctx, "analyses", message, async () => (await ctx.api().analysis.getRecent(50)).map((a) => ({
|
|
9820
|
+
label: a.name,
|
|
9821
|
+
value: a.analysisId,
|
|
9822
|
+
hint: `${a.latestRunState ?? "never run"} \xB7 ${a.analysisId}`
|
|
9823
|
+
})));
|
|
9824
|
+
}
|
|
9825
|
+
async function askColumns(ctx, spec, input) {
|
|
9826
|
+
const analysisId = text(ctx, "id");
|
|
9827
|
+
let columns = [];
|
|
9828
|
+
try {
|
|
9829
|
+
if (analysisId) columns = (await ctx.api().analysis.getColumns(analysisId)).map((c) => c.name).filter(Boolean);
|
|
9830
|
+
} catch (error) {
|
|
9831
|
+
ctx.note(`Could not read the columns (${reason(error)}).`);
|
|
9832
|
+
}
|
|
9833
|
+
if (columns.length === 0) return typed(ctx, question(input), { allowEmpty: spec.allowEmpty });
|
|
9834
|
+
if (spec.multiple) {
|
|
9835
|
+
const chosen = await ctx.prompter.checkbox({
|
|
9836
|
+
message: messageFor(input, "Columns"),
|
|
9837
|
+
choices: columns.map((c) => ({ name: c, value: c })),
|
|
9838
|
+
validate: (picked) => picked.length > 0 || "Pick at least one column."
|
|
9839
|
+
});
|
|
9840
|
+
return chosen.join(",");
|
|
9841
|
+
}
|
|
9842
|
+
const items = columns.map((c) => ({ label: c, value: c }));
|
|
9843
|
+
if (spec.allowEmpty) items.unshift({ label: "None (clear it)", value: "" });
|
|
9844
|
+
return choose(ctx, messageFor(input, "Column"), items);
|
|
9845
|
+
}
|
|
9846
|
+
async function askEvaluation(ctx, input) {
|
|
9847
|
+
const ref = entityRef(ctx, "ref");
|
|
9848
|
+
const hour = parseHour(text(ctx, "date") ?? currentUtcHour());
|
|
9849
|
+
return listed(ctx, "evaluations in that hour", messageFor(input, "Evaluation"), async () => ref && hour ? (await ctx.api().evaluation.getEvaluations(
|
|
9850
|
+
ref.projectId,
|
|
9851
|
+
ref.projectBranch,
|
|
9852
|
+
ref.entityId,
|
|
9853
|
+
ref.entityBranch,
|
|
9854
|
+
hour.year,
|
|
9855
|
+
hour.month,
|
|
9856
|
+
hour.day,
|
|
9857
|
+
hour.hour
|
|
9858
|
+
)).map((e) => ({ label: e.evaluationId, value: e.evaluationId, hint: e.active ? "running" : "finished" })) : []);
|
|
9859
|
+
}
|
|
9860
|
+
async function askEvent(ctx, input) {
|
|
9861
|
+
const ref = entityRef(ctx, "ref");
|
|
9862
|
+
let events = [];
|
|
9863
|
+
try {
|
|
9864
|
+
if (ref) events = await ctx.api().storage.getEvents(ref);
|
|
9865
|
+
} catch (error) {
|
|
9866
|
+
ctx.note(`Could not list the events (${reason(error)}).`);
|
|
9867
|
+
}
|
|
9868
|
+
if (events.length === 0) return typedValue(ctx, question(input));
|
|
9869
|
+
const key = await choose(ctx, messageFor(input, "Event"), events.map((e) => ({
|
|
9870
|
+
label: `${e.type} ${e.eventId}`,
|
|
9871
|
+
value: `${e.eventId}\0${e.occurrenceId}`,
|
|
9872
|
+
hint: e.occurrenceId
|
|
9873
|
+
})));
|
|
9874
|
+
if (key === TYPE_IT || !key.includes("\0")) return key === TYPE_IT ? typedValue(ctx, question(input)) : key;
|
|
9875
|
+
const [eventId, occurrenceId] = key.split("\0");
|
|
9876
|
+
ctx.prefill.set("occurrenceId", occurrenceId);
|
|
9877
|
+
return eventId;
|
|
9878
|
+
}
|
|
9879
|
+
async function listed(ctx, noun, message, load) {
|
|
9880
|
+
let items;
|
|
9881
|
+
try {
|
|
9882
|
+
items = await load();
|
|
9883
|
+
} catch (error) {
|
|
9884
|
+
ctx.note(`Could not list ${noun} (${reason(error)}); type it instead.`);
|
|
9885
|
+
return typedValue(ctx, message);
|
|
9886
|
+
}
|
|
9887
|
+
if (items.length === 0) {
|
|
9888
|
+
ctx.note(`No ${noun} to choose from; type it instead.`);
|
|
9889
|
+
return typedValue(ctx, message);
|
|
9890
|
+
}
|
|
9891
|
+
const picked = await choose(ctx, message, items);
|
|
9892
|
+
return picked === TYPE_IT ? typedValue(ctx, message) : picked;
|
|
9893
|
+
}
|
|
9894
|
+
async function choose(ctx, message, items, defaultValue) {
|
|
9895
|
+
const choices = [
|
|
9896
|
+
...items.map((i) => ({ name: labelled(i.label, i.hint), value: i.value })),
|
|
9897
|
+
typeItChoice()
|
|
9898
|
+
];
|
|
9899
|
+
if (items.length > SEARCH_THRESHOLD) {
|
|
9900
|
+
return ctx.prompter.search({
|
|
9901
|
+
message,
|
|
9902
|
+
source: (term) => {
|
|
9903
|
+
const needle = term.trim().toLowerCase();
|
|
9904
|
+
if (!needle) return choices;
|
|
9905
|
+
return [
|
|
9906
|
+
...choices.filter((c) => c.value !== TYPE_IT && `${c.name} ${c.value}`.toLowerCase().includes(needle)),
|
|
9907
|
+
typeItChoice()
|
|
9908
|
+
];
|
|
9909
|
+
}
|
|
9910
|
+
});
|
|
9911
|
+
}
|
|
9912
|
+
return ctx.prompter.select({ message, choices, default: defaultValue });
|
|
9913
|
+
}
|
|
9914
|
+
async function typed(ctx, message, options = {}) {
|
|
9915
|
+
const value = await ctx.prompter.input({
|
|
9916
|
+
message,
|
|
9917
|
+
default: options.defaultValue,
|
|
9918
|
+
validate: (raw) => {
|
|
9919
|
+
if (!options.allowEmpty && raw.trim().length === 0) return "A value is required.";
|
|
9920
|
+
if (options.allowEmpty && raw.trim().length === 0) return true;
|
|
9921
|
+
return options.validate ? options.validate(raw) : true;
|
|
9922
|
+
}
|
|
9923
|
+
});
|
|
9924
|
+
return value.trim();
|
|
9925
|
+
}
|
|
9926
|
+
function typedValue(ctx, message) {
|
|
9927
|
+
return typed(ctx, message);
|
|
9928
|
+
}
|
|
9929
|
+
function typeItChoice() {
|
|
9930
|
+
return { name: chalk35.dim("Type it instead"), value: TYPE_IT };
|
|
9931
|
+
}
|
|
9932
|
+
function text(ctx, name) {
|
|
9933
|
+
const value = ctx.known.get(name);
|
|
9934
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
9935
|
+
}
|
|
9936
|
+
function entityRef(ctx, name) {
|
|
9937
|
+
const ref = text(ctx, name);
|
|
9938
|
+
if (!ref) return void 0;
|
|
9939
|
+
try {
|
|
9940
|
+
return parseEntityReference(ref, ctx.globals);
|
|
9941
|
+
} catch {
|
|
9942
|
+
return void 0;
|
|
9943
|
+
}
|
|
9944
|
+
}
|
|
9945
|
+
function defaultProject(ctx) {
|
|
9946
|
+
return (ctx.globals.project ?? loadConfig().defaults.project)?.split("/")[0];
|
|
9947
|
+
}
|
|
9948
|
+
function messageFor(input, noun) {
|
|
9949
|
+
const lead = /^(Source|Target)\b/.exec(input.description)?.[1];
|
|
9950
|
+
return lead ? `${lead} ${noun.toLowerCase()}` : noun;
|
|
9951
|
+
}
|
|
9952
|
+
function question(input) {
|
|
9953
|
+
const text2 = input.description.trim() || input.name;
|
|
9954
|
+
return capitalize(text2);
|
|
9955
|
+
}
|
|
9956
|
+
function capitalize(value) {
|
|
9957
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
9958
|
+
}
|
|
9959
|
+
function labelled(label, hint2) {
|
|
9960
|
+
return hint2 && hint2 !== label ? `${label} ${chalk35.dim(hint2)}` : label;
|
|
9961
|
+
}
|
|
9962
|
+
function numberRule(spec) {
|
|
9963
|
+
return (raw) => {
|
|
9964
|
+
const value = Number(raw.trim());
|
|
9965
|
+
if (raw.trim() === "" || !Number.isFinite(value)) return "Enter a number.";
|
|
9966
|
+
if (spec.integer && !Number.isInteger(value)) return "Enter a whole number.";
|
|
9967
|
+
if (spec.exclusive ? value <= spec.min : value < spec.min) {
|
|
9968
|
+
return spec.exclusive ? `Enter a number above ${spec.min}.` : `Enter ${spec.min} or more.`;
|
|
9969
|
+
}
|
|
9970
|
+
return true;
|
|
9971
|
+
};
|
|
9972
|
+
}
|
|
9973
|
+
function currentUtcHour(now = /* @__PURE__ */ new Date()) {
|
|
9974
|
+
const iso = now.toISOString();
|
|
9975
|
+
return `${iso.slice(0, 10)}-${iso.slice(11, 13)}`;
|
|
9976
|
+
}
|
|
9977
|
+
function parseHour(value) {
|
|
9978
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})-(\d{2})$/.exec(value.trim());
|
|
9979
|
+
if (!match) return null;
|
|
9980
|
+
return { year: Number(match[1]), month: Number(match[2]), day: Number(match[3]), hour: Number(match[4]) };
|
|
9981
|
+
}
|
|
9982
|
+
function when(epochMs) {
|
|
9983
|
+
return epochMs ? new Date(epochMs).toISOString().slice(0, 16).replace("T", " ") : "";
|
|
9984
|
+
}
|
|
9985
|
+
function reason(error) {
|
|
9986
|
+
return error instanceof Error ? error.message : String(error);
|
|
9987
|
+
}
|
|
9988
|
+
|
|
9989
|
+
// src/prompting/fill.ts
|
|
9990
|
+
async function fillPendingInputs(actionCommand) {
|
|
9991
|
+
const chain = commandChain(actionCommand);
|
|
9992
|
+
const owners = chain.filter((c) => c instanceof DiafuncCommand && c.pendingInputs.length > 0);
|
|
9993
|
+
if (owners.length === 0) return;
|
|
9994
|
+
const env = actionCommand.environment();
|
|
9995
|
+
const pending = owners.flatMap((owner) => owner.pendingInputs.splice(0).map((input) => ({
|
|
9996
|
+
owner,
|
|
9997
|
+
input,
|
|
9998
|
+
spec: specFor(pathOf(owner), input) ?? { kind: "text" }
|
|
9999
|
+
})));
|
|
10000
|
+
const ctx = {
|
|
10001
|
+
prompter: env.prompter ?? createInquirerPrompter(),
|
|
10002
|
+
api: memoize(env.api ?? (() => createApiClient())),
|
|
10003
|
+
known: knownValues(actionCommand),
|
|
10004
|
+
globals: actionCommand.optsWithGlobals(),
|
|
10005
|
+
prefill: /* @__PURE__ */ new Map(),
|
|
10006
|
+
note: (line) => process.stderr.write(chalk36.dim(` ${line}
|
|
10007
|
+
`))
|
|
10008
|
+
};
|
|
10009
|
+
for (const item of orderByDependencies(pending)) {
|
|
10010
|
+
const value = await askFor(item.spec, item.input, ctx);
|
|
10011
|
+
write(item.owner, item.input, value);
|
|
10012
|
+
ctx.known.set(item.input.name, value);
|
|
10013
|
+
}
|
|
10014
|
+
const log = env.log ?? ((line) => console.log(line));
|
|
10015
|
+
log(chalk36.dim(` Equivalent: ${equivalentCommand(actionCommand)}`));
|
|
10016
|
+
}
|
|
10017
|
+
function commandChain(cmd) {
|
|
10018
|
+
const chain = [];
|
|
10019
|
+
for (let c = cmd; c; c = c.parent) chain.unshift(c);
|
|
10020
|
+
return chain;
|
|
10021
|
+
}
|
|
10022
|
+
function pathOf(cmd) {
|
|
10023
|
+
return commandChain(cmd).slice(1).map((c) => c.name()).join(" ");
|
|
10024
|
+
}
|
|
10025
|
+
function knownValues(cmd) {
|
|
10026
|
+
const known = /* @__PURE__ */ new Map();
|
|
10027
|
+
for (const [key, value] of Object.entries(cmd.optsWithGlobals())) {
|
|
10028
|
+
if (value !== void 0) known.set(key, value);
|
|
10029
|
+
}
|
|
10030
|
+
cmd.registeredArguments.forEach((argument, i) => {
|
|
10031
|
+
const value = cmd.processedArgs[i];
|
|
10032
|
+
if (value !== void 0) known.set(argument.name(), value);
|
|
10033
|
+
});
|
|
10034
|
+
return known;
|
|
10035
|
+
}
|
|
10036
|
+
function orderByDependencies(pending) {
|
|
10037
|
+
const remaining = [...pending];
|
|
10038
|
+
const ordered = [];
|
|
10039
|
+
while (remaining.length > 0) {
|
|
10040
|
+
const waiting = new Set(remaining.map((p) => p.input.name));
|
|
10041
|
+
const index = remaining.findIndex((p) => dependencies(p.spec).every((name) => !waiting.has(name) || name === p.input.name));
|
|
10042
|
+
ordered.push(...remaining.splice(index === -1 ? 0 : index, 1));
|
|
10043
|
+
}
|
|
10044
|
+
return ordered;
|
|
10045
|
+
}
|
|
10046
|
+
function write(owner, input, value) {
|
|
10047
|
+
if (input.kind === "argument" && input.index !== void 0 && input.index >= 0) {
|
|
10048
|
+
owner.processedArgs[input.index] = value;
|
|
10049
|
+
} else {
|
|
10050
|
+
owner.setOptionValueWithSource(input.name, value, "cli");
|
|
10051
|
+
}
|
|
10052
|
+
}
|
|
10053
|
+
function memoize(make) {
|
|
10054
|
+
let made;
|
|
10055
|
+
return () => made ??= make();
|
|
10056
|
+
}
|
|
10057
|
+
function equivalentCommand(cmd) {
|
|
10058
|
+
const chain = commandChain(cmd);
|
|
10059
|
+
const tokens = [chain[0].name(), ...chain.slice(1).map((c) => c.name())];
|
|
10060
|
+
for (const value of cmd.processedArgs) {
|
|
10061
|
+
if (value === void 0) continue;
|
|
10062
|
+
for (const v of Array.isArray(value) ? value : [value]) tokens.push(quote(String(v)));
|
|
10063
|
+
}
|
|
10064
|
+
for (const c of chain) {
|
|
10065
|
+
for (const option of c.options) {
|
|
10066
|
+
const key = option.attributeName();
|
|
10067
|
+
if (c.getOptionValueSource(key) !== "cli" || !option.long) continue;
|
|
10068
|
+
const value = c.getOptionValue(key);
|
|
10069
|
+
if (typeof value === "boolean") {
|
|
10070
|
+
if (value === !option.negate) tokens.push(option.long);
|
|
10071
|
+
} else if (Array.isArray(value)) {
|
|
10072
|
+
for (const v of value) tokens.push(option.long, quote(String(v)));
|
|
10073
|
+
} else if (value !== void 0) {
|
|
10074
|
+
tokens.push(option.long, quote(String(value)));
|
|
10075
|
+
}
|
|
10076
|
+
}
|
|
10077
|
+
}
|
|
10078
|
+
return tokens.join(" ");
|
|
10079
|
+
}
|
|
10080
|
+
function quote(value) {
|
|
10081
|
+
if (/^[\w@%+=:,./-]+$/.test(value)) return value;
|
|
10082
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
10083
|
+
}
|
|
10084
|
+
|
|
9325
10085
|
// src/index.ts
|
|
9326
10086
|
var HELP_EPILOGUE = `
|
|
9327
10087
|
Getting started:
|
|
@@ -9340,11 +10100,16 @@ Output:
|
|
|
9340
10100
|
Add --output json for scripting, or pipe any command to get tab-separated fields.
|
|
9341
10101
|
Add --verbose to see the requests, --dry-run to preview a mutation.
|
|
9342
10102
|
|
|
10103
|
+
Missing input:
|
|
10104
|
+
In a terminal, leave out a required argument and the command asks for it, offering
|
|
10105
|
+
your projects, tables, teams and the like to choose from. --no-interactive never asks.
|
|
10106
|
+
|
|
9343
10107
|
Docs: https://diafunc.com/documentation
|
|
9344
10108
|
`;
|
|
9345
|
-
function createProgram() {
|
|
9346
|
-
const program = new
|
|
9347
|
-
program.
|
|
10109
|
+
function createProgram(environment = {}) {
|
|
10110
|
+
const program = new DiafuncCommand();
|
|
10111
|
+
program.promptEnvironment = environment;
|
|
10112
|
+
program.name("diafunc").description("Diafunc CLI \u2014 command-line interface for the Diafunc platform").version(package_default.version).option("-p, --profile <name>", "Profile to use").option("-o, --output <format>", "Output format: human, json, table (default: human)").option("--project <id>", "Project to work in (overrides defaults.project)").option("--branch <name>", "Project branch (overrides defaults.branch)").option("--dry-run", "Preview mutating operations without executing them").option("--verbose", "Echo every HTTP request to stderr").option("--no-color", "Disable coloured output").option("--no-interactive", "Never prompt: a missing required input fails as it would in a script").showSuggestionAfterError().showHelpAfterError(`(run 'diafunc --help' to see the available commands)`).configureHelp({ showGlobalOptions: true }).configureOutput({
|
|
9348
10113
|
// Commander writes usage errors to stdout by default, which puts a complaint in the middle
|
|
9349
10114
|
// of whatever a caller was capturing.
|
|
9350
10115
|
writeErr: (str) => process.stderr.write(str)
|
|
@@ -9352,8 +10117,8 @@ function createProgram() {
|
|
|
9352
10117
|
const opts = thisCommand.optsWithGlobals();
|
|
9353
10118
|
if (opts.dryRun) setDryRun(true);
|
|
9354
10119
|
if (opts.verbose) setVerbose(true);
|
|
9355
|
-
if (opts.color === false)
|
|
9356
|
-
});
|
|
10120
|
+
if (opts.color === false) chalk37.level = 0;
|
|
10121
|
+
}).hook("preAction", (_thisCommand, actionCommand) => fillPendingInputs(actionCommand));
|
|
9357
10122
|
program.addHelpText("after", HELP_EPILOGUE);
|
|
9358
10123
|
registerAuthCommands(program);
|
|
9359
10124
|
registerConfigCommands(program);
|
|
@@ -9389,6 +10154,9 @@ function createProgram() {
|
|
|
9389
10154
|
}
|
|
9390
10155
|
|
|
9391
10156
|
export {
|
|
10157
|
+
EXIT_CANCELLED,
|
|
10158
|
+
handleError,
|
|
10159
|
+
PromptCancelled,
|
|
9392
10160
|
createProgram
|
|
9393
10161
|
};
|
|
9394
|
-
//# sourceMappingURL=chunk-
|
|
10162
|
+
//# sourceMappingURL=chunk-4NQYIRPF.js.map
|