@diafunc/cli 0.19.0 → 0.20.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 +6 -3
- package/dist/bin/diafunc.js +3 -3
- package/dist/{chunk-SYNS3L7N.js → chunk-4STLEQUJ.js} +2 -2
- package/dist/{chunk-OCZSFCU6.js → chunk-D7AJH4Y3.js} +935 -200
- package/dist/chunk-D7AJH4Y3.js.map +1 -0
- package/dist/{chunk-A5D45VXJ.js → chunk-V2VLVFWP.js} +2 -2
- package/dist/{chunk-A5D45VXJ.js.map → chunk-V2VLVFWP.js.map} +1 -1
- package/dist/src/index.js +2 -2
- package/dist/update-check-7F4ABBDC.js +8 -0
- package/package.json +1 -1
- package/dist/chunk-OCZSFCU6.js.map +0 -1
- package/dist/update-check-TTXILAMD.js +0 -8
- /package/dist/{chunk-SYNS3L7N.js.map → chunk-4STLEQUJ.js.map} +0 -0
- /package/dist/{update-check-TTXILAMD.js.map → update-check-7F4ABBDC.js.map} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-V2VLVFWP.js";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
|
-
import
|
|
6
|
+
import chalk37 from "chalk";
|
|
7
7
|
|
|
8
8
|
// src/commands/auth/login.ts
|
|
9
9
|
import chalk4 from "chalk";
|
|
@@ -1510,6 +1510,7 @@ var SERVICE2 = "analyses";
|
|
|
1510
1510
|
var RUNS_SERVICE = "runs";
|
|
1511
1511
|
var PRESETS_SERVICE = "analysis-presets";
|
|
1512
1512
|
var TRIGGERS_SERVICE = "triggers";
|
|
1513
|
+
var PUBLIC_SERVICE = "public-analyses";
|
|
1513
1514
|
function createAnalysisService(client) {
|
|
1514
1515
|
return {
|
|
1515
1516
|
// ----- Lifecycle: create / read / replace / delete --------------------------------
|
|
@@ -1558,6 +1559,16 @@ function createAnalysisService(client) {
|
|
|
1558
1559
|
path: `/${encodeURIComponent(analysisId)}`
|
|
1559
1560
|
});
|
|
1560
1561
|
},
|
|
1562
|
+
// ----- Public analyses: readable without signing in --------------------------------
|
|
1563
|
+
/** One page of the public analyses. `cursor` is the `nextCursor` of the page before. */
|
|
1564
|
+
async listPublic(page = {}) {
|
|
1565
|
+
return client.request({
|
|
1566
|
+
method: "GET",
|
|
1567
|
+
service: PUBLIC_SERVICE,
|
|
1568
|
+
path: "",
|
|
1569
|
+
query: { cursor: page.cursor, limit: page.limit }
|
|
1570
|
+
});
|
|
1571
|
+
},
|
|
1561
1572
|
// ----- Typed PATCH per editable field --------------------------------------------
|
|
1562
1573
|
async patchName(analysisId, request) {
|
|
1563
1574
|
return client.request({
|
|
@@ -1712,6 +1723,22 @@ function createAnalysisService(client) {
|
|
|
1712
1723
|
body: request
|
|
1713
1724
|
});
|
|
1714
1725
|
},
|
|
1726
|
+
/** How the import of the analysis's data stands. `dataImport` null means it finished and the counts are final. */
|
|
1727
|
+
async getDataImport(analysisId) {
|
|
1728
|
+
return client.request({
|
|
1729
|
+
method: "GET",
|
|
1730
|
+
service: SERVICE2,
|
|
1731
|
+
path: `/${encodeURIComponent(analysisId)}/data/import`
|
|
1732
|
+
});
|
|
1733
|
+
},
|
|
1734
|
+
/** Stops the running import. The platform waits a while for it to end and answers `STOPPING` when it has not yet. */
|
|
1735
|
+
async stopDataImport(analysisId) {
|
|
1736
|
+
return client.request({
|
|
1737
|
+
method: "DELETE",
|
|
1738
|
+
service: SERVICE2,
|
|
1739
|
+
path: `/${encodeURIComponent(analysisId)}/data/import`
|
|
1740
|
+
});
|
|
1741
|
+
},
|
|
1715
1742
|
async getColumns(analysisId) {
|
|
1716
1743
|
return client.request({
|
|
1717
1744
|
method: "GET",
|
|
@@ -2790,7 +2817,8 @@ function createIndexService(client) {
|
|
|
2790
2817
|
cursor: query.cursor ?? void 0,
|
|
2791
2818
|
contentType: query.contentType ?? void 0,
|
|
2792
2819
|
projectId: query.projectId ?? void 0,
|
|
2793
|
-
projectBranch: query.projectBranch ?? void 0
|
|
2820
|
+
projectBranch: query.projectBranch ?? void 0,
|
|
2821
|
+
sort: query.sort && query.sort !== "best" ? query.sort : void 0
|
|
2794
2822
|
}
|
|
2795
2823
|
});
|
|
2796
2824
|
},
|
|
@@ -3405,17 +3433,17 @@ async function projectNames(api, projectIds) {
|
|
|
3405
3433
|
const wanted = new Set(projectIds);
|
|
3406
3434
|
const names = /* @__PURE__ */ new Map();
|
|
3407
3435
|
if (wanted.size === 0) return names;
|
|
3408
|
-
const
|
|
3436
|
+
const take2 = (items) => {
|
|
3409
3437
|
for (const item of items) {
|
|
3410
3438
|
if (item.contentType !== "project" || !item.name || !wanted.has(item.projectId)) continue;
|
|
3411
3439
|
if (!names.has(item.projectId)) names.set(item.projectId, item.name);
|
|
3412
3440
|
}
|
|
3413
3441
|
};
|
|
3414
|
-
|
|
3442
|
+
take2((await api.index.searchPage({ query: "*", contentType: "project", limit: FIRST_PAGE })).items);
|
|
3415
3443
|
const missing = [...wanted].filter((id) => !names.has(id));
|
|
3416
3444
|
for (let i = 0; i < missing.length; i += CONCURRENCY) {
|
|
3417
3445
|
const pages = await Promise.all(missing.slice(i, i + CONCURRENCY).map((projectId) => api.index.searchPage({ query: "*", contentType: "project", projectId, projectBranch: "main", limit: 5 }).catch(() => null)));
|
|
3418
|
-
for (const page of pages) if (page)
|
|
3446
|
+
for (const page of pages) if (page) take2(page.items);
|
|
3419
3447
|
}
|
|
3420
3448
|
return names;
|
|
3421
3449
|
}
|
|
@@ -6259,7 +6287,7 @@ var HELP = [
|
|
|
6259
6287
|
];
|
|
6260
6288
|
async function runChatRepl(options) {
|
|
6261
6289
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
6262
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
6290
|
+
const { getUpdateNotice } = await import("./update-check-7F4ABBDC.js");
|
|
6263
6291
|
let sessionId = options.session;
|
|
6264
6292
|
let lastReportedSession;
|
|
6265
6293
|
console.log(chalk19.bold("Diafunc chat") + chalk19.dim(" \xB7 /help for commands, /quit to exit"));
|
|
@@ -6549,14 +6577,23 @@ function getOutputFormat13(cmd) {
|
|
|
6549
6577
|
const globalOpts = cmd.optsWithGlobals();
|
|
6550
6578
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
6551
6579
|
}
|
|
6580
|
+
function parseSort(raw) {
|
|
6581
|
+
if (raw === "best" || raw === "newest") return raw;
|
|
6582
|
+
return usageError(`Unknown sort "${raw}".`, "Use --sort best or --sort newest.");
|
|
6583
|
+
}
|
|
6552
6584
|
function registerSearchCommands(program) {
|
|
6553
|
-
program.command("search").description("Search across every project you can see").argument("<query>", "Search query").option("--type <contentType>", "Limit to one content type, e.g. project, notebook, table, function").option("--limit <n>", "Maximum results", "20").addHelpText("after", `
|
|
6585
|
+
program.command("search").description("Search across every project you can see").argument("<query>", "Search query").option("--type <contentType>", "Limit to one content type, e.g. project, notebook, table, function").option("--limit <n>", "Maximum results", "20").option("--sort <order>", "Order of equally relevant results: best (model quality) or newest", "best").addHelpText("after", `
|
|
6554
6586
|
Examples:
|
|
6555
6587
|
$ diafunc search "housing" everything matching, across projects
|
|
6556
6588
|
$ diafunc search "housing" --type project only projects
|
|
6557
6589
|
$ diafunc search "medv" --project <id> only inside one project
|
|
6590
|
+
$ diafunc search "housing" --sort newest most recently changed first among equal matches
|
|
6558
6591
|
$ diafunc search "housing" --output json for scripting
|
|
6592
|
+
|
|
6593
|
+
Results are ordered by how well they match. Among results that match equally well, the project
|
|
6594
|
+
whose discovered model has the better quality comes first; inside one project the newer one does.
|
|
6559
6595
|
`).action(async (query, options, cmd) => {
|
|
6596
|
+
const sort = parseSort(options.sort);
|
|
6560
6597
|
try {
|
|
6561
6598
|
const outputFormat = getOutputFormat13(cmd);
|
|
6562
6599
|
const overrides = cmd.optsWithGlobals();
|
|
@@ -6569,7 +6606,8 @@ Examples:
|
|
|
6569
6606
|
limit: Number.isFinite(limit) && limit > 0 ? limit : 20,
|
|
6570
6607
|
contentType: options.type ?? null,
|
|
6571
6608
|
projectId,
|
|
6572
|
-
projectBranch: projectId ? overrides.branch ?? config.defaults.branch ?? "main" : null
|
|
6609
|
+
projectBranch: projectId ? overrides.branch ?? config.defaults.branch ?? "main" : null,
|
|
6610
|
+
sort
|
|
6573
6611
|
});
|
|
6574
6612
|
const items = dedupe(page.items);
|
|
6575
6613
|
if (outputFormat === "json") {
|
|
@@ -6588,6 +6626,7 @@ Examples:
|
|
|
6588
6626
|
columns: [
|
|
6589
6627
|
{ key: "contentType", header: "type" },
|
|
6590
6628
|
{ key: "name" },
|
|
6629
|
+
{ key: "quality" },
|
|
6591
6630
|
{ key: "projectId", kind: "id" },
|
|
6592
6631
|
{ key: "entityId", kind: "id" }
|
|
6593
6632
|
]
|
|
@@ -6616,7 +6655,7 @@ function renderResults(items) {
|
|
|
6616
6655
|
for (const item of items) {
|
|
6617
6656
|
const name = item.name || "(unnamed)";
|
|
6618
6657
|
console.log();
|
|
6619
|
-
console.log(`${chalk20.dim(`[${item.contentType}]`)} ${chalk20.bold(name)}`);
|
|
6658
|
+
console.log(`${chalk20.dim(`[${item.contentType}]`)} ${chalk20.bold(name)}${qualityNote(item)}`);
|
|
6620
6659
|
const raw = item.snippetField === "name" ? item.description : item.snippet ?? item.description;
|
|
6621
6660
|
const line = raw ? collapse(raw) : null;
|
|
6622
6661
|
if (line && stripHighlight(line) !== name) console.log(` ${highlight(line)}`);
|
|
@@ -6625,6 +6664,12 @@ function renderResults(items) {
|
|
|
6625
6664
|
}
|
|
6626
6665
|
console.log();
|
|
6627
6666
|
}
|
|
6667
|
+
function qualityNote(item) {
|
|
6668
|
+
if (item.contentType !== "project" || typeof item.quality !== "number" || !Number.isFinite(item.quality)) {
|
|
6669
|
+
return "";
|
|
6670
|
+
}
|
|
6671
|
+
return chalk20.dim(` quality ${percent(item.quality).trim()}`);
|
|
6672
|
+
}
|
|
6628
6673
|
var HIGHLIGHT_OPEN = /<mark>/g;
|
|
6629
6674
|
var HIGHLIGHT_CLOSE = /<\/mark>/g;
|
|
6630
6675
|
function highlight(text2) {
|
|
@@ -7145,6 +7190,14 @@ function terminalSentence(state, duration, credits = null) {
|
|
|
7145
7190
|
return `Analysis failed after ${duration}${cost}.`;
|
|
7146
7191
|
}
|
|
7147
7192
|
}
|
|
7193
|
+
function isImporting(dataImport) {
|
|
7194
|
+
return dataImport?.state === "IMPORTING" || dataImport?.state === "STOPPING";
|
|
7195
|
+
}
|
|
7196
|
+
function importingLabel(dataImport) {
|
|
7197
|
+
const progress = dataImport.progress;
|
|
7198
|
+
if (progress === null || progress === void 0 || !Number.isFinite(progress)) return "Importing data";
|
|
7199
|
+
return `Importing data, ${Math.floor(Math.max(0, Math.min(progress, 1)) * 100)} %`;
|
|
7200
|
+
}
|
|
7148
7201
|
|
|
7149
7202
|
// src/commands/analyze/watch-view.ts
|
|
7150
7203
|
function overallProgress(run) {
|
|
@@ -7211,6 +7264,178 @@ function renderWatchBlock(input) {
|
|
|
7211
7264
|
|
|
7212
7265
|
// src/commands/analyze/wizard.ts
|
|
7213
7266
|
import chalk25 from "chalk";
|
|
7267
|
+
|
|
7268
|
+
// src/commands/analyze/columns.ts
|
|
7269
|
+
var MAX_COLUMNS_LISTED = 30;
|
|
7270
|
+
var MAX_NEAR_MATCHES = 3;
|
|
7271
|
+
function parseColumnList(text2) {
|
|
7272
|
+
const names = [];
|
|
7273
|
+
let i = 0;
|
|
7274
|
+
while (i < text2.length) {
|
|
7275
|
+
while (i < text2.length && isSpace(text2[i])) i++;
|
|
7276
|
+
if (i >= text2.length) break;
|
|
7277
|
+
if (text2[i] === '"') {
|
|
7278
|
+
let name = "";
|
|
7279
|
+
let closed = false;
|
|
7280
|
+
i++;
|
|
7281
|
+
while (i < text2.length) {
|
|
7282
|
+
if (text2[i] === '"' && text2[i + 1] === '"') {
|
|
7283
|
+
name += '"';
|
|
7284
|
+
i += 2;
|
|
7285
|
+
} else if (text2[i] === '"') {
|
|
7286
|
+
closed = true;
|
|
7287
|
+
i++;
|
|
7288
|
+
break;
|
|
7289
|
+
} else {
|
|
7290
|
+
name += text2[i++];
|
|
7291
|
+
}
|
|
7292
|
+
}
|
|
7293
|
+
if (!closed) {
|
|
7294
|
+
throw new CliError(`A double quote is opened and never closed in: ${text2}`, {
|
|
7295
|
+
exitCode: EXIT_USAGE,
|
|
7296
|
+
hint: QUOTING_HINT
|
|
7297
|
+
});
|
|
7298
|
+
}
|
|
7299
|
+
while (i < text2.length && isSpace(text2[i])) i++;
|
|
7300
|
+
if (i < text2.length && text2[i] !== ",") {
|
|
7301
|
+
throw new CliError(`Text follows a closing double quote without a comma in: ${text2}`, {
|
|
7302
|
+
exitCode: EXIT_USAGE,
|
|
7303
|
+
hint: QUOTING_HINT
|
|
7304
|
+
});
|
|
7305
|
+
}
|
|
7306
|
+
i++;
|
|
7307
|
+
if (name.length > 0) names.push(name);
|
|
7308
|
+
} else {
|
|
7309
|
+
const end = text2.indexOf(",", i);
|
|
7310
|
+
const name = text2.slice(i, end === -1 ? text2.length : end).trim();
|
|
7311
|
+
i = end === -1 ? text2.length : end + 1;
|
|
7312
|
+
if (name.length > 0) names.push(name);
|
|
7313
|
+
}
|
|
7314
|
+
}
|
|
7315
|
+
return names;
|
|
7316
|
+
}
|
|
7317
|
+
var QUOTING_HINT = `Inside a list, put a name that contains a comma in double quotes and write a quote in it twice: '"a, b",c'.`;
|
|
7318
|
+
function isSpace(char) {
|
|
7319
|
+
return char === " " || char === " ";
|
|
7320
|
+
}
|
|
7321
|
+
function quoteColumn(name) {
|
|
7322
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
7323
|
+
}
|
|
7324
|
+
function loose(name) {
|
|
7325
|
+
return name.trim().toLowerCase();
|
|
7326
|
+
}
|
|
7327
|
+
function matchColumn(name, columns) {
|
|
7328
|
+
if (columns.includes(name)) return { kind: "column", column: name };
|
|
7329
|
+
const wanted = loose(name);
|
|
7330
|
+
const candidates = columns.filter((column) => loose(column) === wanted);
|
|
7331
|
+
if (candidates.length === 1) return { kind: "column", column: candidates[0] };
|
|
7332
|
+
return candidates.length > 1 ? { kind: "ambiguous", candidates } : { kind: "unknown" };
|
|
7333
|
+
}
|
|
7334
|
+
function nearMatches(name, columns) {
|
|
7335
|
+
const wanted = loose(name);
|
|
7336
|
+
if (wanted.length === 0) return [];
|
|
7337
|
+
return columns.map((column) => ({ column, distance: distanceTo(wanted, loose(column)) })).filter((scored) => scored.distance !== null).sort((a, b) => a.distance - b.distance).slice(0, MAX_NEAR_MATCHES).map((scored) => scored.column);
|
|
7338
|
+
}
|
|
7339
|
+
function distanceTo(wanted, column) {
|
|
7340
|
+
const edits = editDistance(wanted, column);
|
|
7341
|
+
if (edits <= Math.max(1, Math.floor(Math.min(wanted.length, column.length) / 4))) return edits;
|
|
7342
|
+
if (wanted.length >= 3 && (column.includes(wanted) || wanted.includes(column)) && column.length > 0) {
|
|
7343
|
+
return 100 + Math.abs(column.length - wanted.length);
|
|
7344
|
+
}
|
|
7345
|
+
return null;
|
|
7346
|
+
}
|
|
7347
|
+
function editDistance(a, b) {
|
|
7348
|
+
let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
7349
|
+
for (let i = 1; i <= a.length; i++) {
|
|
7350
|
+
const current = [i];
|
|
7351
|
+
for (let j = 1; j <= b.length; j++) {
|
|
7352
|
+
current[j] = Math.min(
|
|
7353
|
+
previous[j] + 1,
|
|
7354
|
+
current[j - 1] + 1,
|
|
7355
|
+
previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)
|
|
7356
|
+
);
|
|
7357
|
+
}
|
|
7358
|
+
previous = current;
|
|
7359
|
+
}
|
|
7360
|
+
return previous[b.length];
|
|
7361
|
+
}
|
|
7362
|
+
function take(name, columns, into, problems) {
|
|
7363
|
+
const match = matchColumn(name, columns);
|
|
7364
|
+
if (match.kind === "column") {
|
|
7365
|
+
if (!into.includes(match.column)) into.push(match.column);
|
|
7366
|
+
return true;
|
|
7367
|
+
}
|
|
7368
|
+
if (match.kind === "ambiguous") problems.ambiguous.push({ name, candidates: match.candidates });
|
|
7369
|
+
else problems.unknown.push(name);
|
|
7370
|
+
return false;
|
|
7371
|
+
}
|
|
7372
|
+
function refuse(problems, columns, analysisId) {
|
|
7373
|
+
const sentences = [];
|
|
7374
|
+
if (problems.unknown.length === 1) {
|
|
7375
|
+
sentences.push(`${quoteColumn(problems.unknown[0])} is not a column of the analysis data.`);
|
|
7376
|
+
} else if (problems.unknown.length > 1) {
|
|
7377
|
+
sentences.push(`These are not columns of the analysis data: ${problems.unknown.map(quoteColumn).join(", ")}.`);
|
|
7378
|
+
}
|
|
7379
|
+
for (const { name, candidates } of problems.ambiguous) {
|
|
7380
|
+
sentences.push(`${quoteColumn(name)} matches more than one column: ${candidates.map(quoteColumn).join(", ")}. Type the one you mean exactly.`);
|
|
7381
|
+
}
|
|
7382
|
+
const hints = [];
|
|
7383
|
+
const near = [...new Set(problems.unknown.flatMap((name) => nearMatches(name, columns)))];
|
|
7384
|
+
if (near.length > 0) hints.push(`Did you mean ${near.map(quoteColumn).join(" or ")}?`);
|
|
7385
|
+
const listed2 = columns.slice(0, MAX_COLUMNS_LISTED).map(quoteColumn).join(", ");
|
|
7386
|
+
const more = columns.length > MAX_COLUMNS_LISTED ? ` and ${columns.length - MAX_COLUMNS_LISTED} more${analysisId ? ` ('diafunc analyze columns ${analysisId}' lists them all)` : ""}` : "";
|
|
7387
|
+
hints.push(`The columns are: ${listed2}${more}.`);
|
|
7388
|
+
if (problems.fromList) {
|
|
7389
|
+
hints.push(`A name that contains a comma is an argument of its own, or goes in double quotes inside a list: '"a, b",c'.`);
|
|
7390
|
+
}
|
|
7391
|
+
throw new CliError(sentences.join(" "), { exitCode: EXIT_USAGE, hint: hints.join("\n ") });
|
|
7392
|
+
}
|
|
7393
|
+
function resolveColumnArguments(given, columns, analysisId) {
|
|
7394
|
+
const resolved = [];
|
|
7395
|
+
if (columns.length === 0) {
|
|
7396
|
+
for (const name of given.flatMap(parseColumnList)) {
|
|
7397
|
+
if (!resolved.includes(name)) resolved.push(name);
|
|
7398
|
+
}
|
|
7399
|
+
return resolved;
|
|
7400
|
+
}
|
|
7401
|
+
const problems = { unknown: [], ambiguous: [], fromList: false };
|
|
7402
|
+
for (const argument of given) {
|
|
7403
|
+
if (argument.trim().length === 0) continue;
|
|
7404
|
+
const whole = matchColumn(argument, columns);
|
|
7405
|
+
if (whole.kind === "column") {
|
|
7406
|
+
if (!resolved.includes(whole.column)) resolved.push(whole.column);
|
|
7407
|
+
continue;
|
|
7408
|
+
}
|
|
7409
|
+
const names = parseColumnList(argument);
|
|
7410
|
+
const single = names.length === 1 && names[0] === argument.trim();
|
|
7411
|
+
for (const name of names) {
|
|
7412
|
+
if (!take(name, columns, resolved, problems) && !single) problems.fromList = true;
|
|
7413
|
+
}
|
|
7414
|
+
}
|
|
7415
|
+
if (problems.unknown.length > 0 || problems.ambiguous.length > 0) refuse(problems, columns, analysisId);
|
|
7416
|
+
return resolved;
|
|
7417
|
+
}
|
|
7418
|
+
function resolveColumnNames(names, columns, analysisId) {
|
|
7419
|
+
if (columns.length === 0) return [...names];
|
|
7420
|
+
const resolved = [];
|
|
7421
|
+
const problems = { unknown: [], ambiguous: [], fromList: false };
|
|
7422
|
+
for (const name of names) take(name, columns, resolved, problems);
|
|
7423
|
+
if (problems.unknown.length > 0 || problems.ambiguous.length > 0) refuse(problems, columns, analysisId);
|
|
7424
|
+
return resolved;
|
|
7425
|
+
}
|
|
7426
|
+
function resolveColumnArgument(given, columns, analysisId) {
|
|
7427
|
+
if (columns.length === 0) return given;
|
|
7428
|
+
return resolveColumnNames([given], columns, analysisId)[0];
|
|
7429
|
+
}
|
|
7430
|
+
function occurrences(value) {
|
|
7431
|
+
if (value === void 0) return void 0;
|
|
7432
|
+
return Array.isArray(value) ? value : [value];
|
|
7433
|
+
}
|
|
7434
|
+
function collectColumns(value, previous = []) {
|
|
7435
|
+
return previous.concat([value]);
|
|
7436
|
+
}
|
|
7437
|
+
|
|
7438
|
+
// src/commands/analyze/wizard.ts
|
|
7214
7439
|
var DEPTH_PRESETS = [
|
|
7215
7440
|
{ name: "Express", hours: "1", budget: "500" },
|
|
7216
7441
|
{ name: "Quick", hours: "2", budget: "2000" },
|
|
@@ -7297,10 +7522,16 @@ async function promptRunFields(prompter, options) {
|
|
|
7297
7522
|
});
|
|
7298
7523
|
} else {
|
|
7299
7524
|
const typed2 = await prompter.input({
|
|
7300
|
-
message: "Target column names (comma-separated)",
|
|
7301
|
-
validate: (value) =>
|
|
7525
|
+
message: "Target column names (comma-separated; a name that contains a comma goes in double quotes)",
|
|
7526
|
+
validate: (value) => {
|
|
7527
|
+
try {
|
|
7528
|
+
return parseColumnList(value).length > 0 || "Name at least one target column.";
|
|
7529
|
+
} catch (error) {
|
|
7530
|
+
return error instanceof Error ? error.message : String(error);
|
|
7531
|
+
}
|
|
7532
|
+
}
|
|
7302
7533
|
});
|
|
7303
|
-
targets =
|
|
7534
|
+
targets = parseColumnList(typed2);
|
|
7304
7535
|
}
|
|
7305
7536
|
}
|
|
7306
7537
|
const remaining = named.filter((c) => !targets.includes(c.name));
|
|
@@ -7359,9 +7590,9 @@ async function promptRunFields(prompter, options) {
|
|
|
7359
7590
|
}
|
|
7360
7591
|
if (hours === void 0) {
|
|
7361
7592
|
hours = await prompter.input({
|
|
7362
|
-
message: "
|
|
7593
|
+
message: "Time budget (hours)",
|
|
7363
7594
|
default: DEFAULT_HOURS,
|
|
7364
|
-
validate: positiveNumber("
|
|
7595
|
+
validate: positiveNumber("Time budget")
|
|
7365
7596
|
});
|
|
7366
7597
|
}
|
|
7367
7598
|
if (budget === void 0) {
|
|
@@ -7400,9 +7631,6 @@ function summaryLines(creation, run) {
|
|
|
7400
7631
|
lines.push(`Depth: ${named}${run.hours}h \xB7 ${run.budget} credits`);
|
|
7401
7632
|
return lines;
|
|
7402
7633
|
}
|
|
7403
|
-
function splitCsv(value) {
|
|
7404
|
-
return value.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
7405
|
-
}
|
|
7406
7634
|
function missingRunFields(recipe) {
|
|
7407
7635
|
const missing = [];
|
|
7408
7636
|
if (!recipe.hours || recipe.hours.trim().length === 0) missing.push("hours");
|
|
@@ -7422,7 +7650,7 @@ function suppliedFromAnalysis(analysis) {
|
|
|
7422
7650
|
var FIELD_COMMANDS = {
|
|
7423
7651
|
hours: "hours <id> <hours>",
|
|
7424
7652
|
budget: "budget <id> <credits>",
|
|
7425
|
-
targets: "targets <id> <
|
|
7653
|
+
targets: "targets <id> <column...>"
|
|
7426
7654
|
};
|
|
7427
7655
|
function explainMissingRunFields(analysisId, missing, reason2) {
|
|
7428
7656
|
const commands = missing.map((f) => `'diafunc analyze ${FIELD_COMMANDS[f].replace("<id>", analysisId)}'`);
|
|
@@ -7492,6 +7720,9 @@ function whyNoPrompt(outputFormat, noInteractive) {
|
|
|
7492
7720
|
return "there is no terminal to ask";
|
|
7493
7721
|
}
|
|
7494
7722
|
|
|
7723
|
+
// src/commands/analyze/data-import.ts
|
|
7724
|
+
import chalk26 from "chalk";
|
|
7725
|
+
|
|
7495
7726
|
// src/commands/analyze/details.ts
|
|
7496
7727
|
function analysisDetails(analysis, endpoint) {
|
|
7497
7728
|
const data = {
|
|
@@ -7501,6 +7732,7 @@ function analysisDetails(analysis, endpoint) {
|
|
|
7501
7732
|
visibility: sentenceCase(analysis.visibility),
|
|
7502
7733
|
introduction: analysis.introduction,
|
|
7503
7734
|
data: dataShape(analysis.rowCount, analysis.columnCount),
|
|
7735
|
+
dataImport: analysis.dataImport?.message ?? null,
|
|
7504
7736
|
targets: analysis.targets,
|
|
7505
7737
|
targetKinds: analysis.targetKinds && Object.keys(analysis.targetKinds).length > 0 ? analysis.targetKinds : "detected from the data",
|
|
7506
7738
|
featureExclusions: analysis.featureExclusions,
|
|
@@ -7511,7 +7743,8 @@ function analysisDetails(analysis, endpoint) {
|
|
|
7511
7743
|
budget: creditsText(analysis.budget),
|
|
7512
7744
|
constraints: constraintsText(analysis),
|
|
7513
7745
|
notifyByEmail: analysis.notifyByEmail == null ? "account default" : analysis.notifyByEmail ? "yes" : "no",
|
|
7514
|
-
|
|
7746
|
+
// While the data is still arriving no run can start, so the import is what the analysis is doing.
|
|
7747
|
+
latestRunState: isImporting(analysis.dataImport) ? importingLabel(analysis.dataImport) : analysis.latestRunState ? sentenceCase(analysis.latestRunState) : null,
|
|
7515
7748
|
latestRunId: analysis.latestRunId,
|
|
7516
7749
|
quality: qualityText(analysis),
|
|
7517
7750
|
outputs: outputsText(analysis),
|
|
@@ -7530,13 +7763,14 @@ function analysisDetails(analysis, endpoint) {
|
|
|
7530
7763
|
{ key: "visibility", header: "Visibility" },
|
|
7531
7764
|
{ key: "introduction", header: "Introduction" },
|
|
7532
7765
|
{ key: "data", header: "Data" },
|
|
7766
|
+
{ key: "dataImport", header: "Data import" },
|
|
7533
7767
|
{ key: "targets", header: "Targets" },
|
|
7534
7768
|
{ key: "targetKinds", header: "Target kinds" },
|
|
7535
7769
|
{ key: "featureExclusions", header: "Excluded columns" },
|
|
7536
7770
|
{ key: "confirmedInputs", header: "Known before the outcome" },
|
|
7537
7771
|
{ key: "questions", header: "Questions" },
|
|
7538
7772
|
{ key: "segment", header: "Segment" },
|
|
7539
|
-
{ key: "hours", header: "
|
|
7773
|
+
{ key: "hours", header: "Time budget" },
|
|
7540
7774
|
{ key: "budget", header: "Credit budget" },
|
|
7541
7775
|
{ key: "constraints", header: "Constraints" },
|
|
7542
7776
|
{ key: "notifyByEmail", header: "Email when done" },
|
|
@@ -7604,16 +7838,220 @@ function constraintsText(analysis) {
|
|
|
7604
7838
|
return parts.length > 0 ? parts.join(", ") : "none";
|
|
7605
7839
|
}
|
|
7606
7840
|
|
|
7841
|
+
// src/commands/analyze/data-import.ts
|
|
7842
|
+
var IMPORT_POLL_INTERVAL_MS = 2e3;
|
|
7843
|
+
function renderImportBlock(dataImport, elapsedMs) {
|
|
7844
|
+
const title = dataImport.state === "STOPPING" ? "Stopping the data import" : "Importing data";
|
|
7845
|
+
const lines = [` ${chalk26.cyan(SPINNER)} ${chalk26.bold(title)}`];
|
|
7846
|
+
const elapsed = chalk26.dim(formatDurationPrecise(elapsedMs));
|
|
7847
|
+
if (dataImport.state === "IMPORTING" && dataImport.progress !== null && dataImport.progress !== void 0) {
|
|
7848
|
+
lines.push(` ${bar(dataImport.progress)} ${percent(dataImport.progress)} ${elapsed}`);
|
|
7849
|
+
} else {
|
|
7850
|
+
lines.push(` ${chalk26.dim(dataImport.message)} ${elapsed}`);
|
|
7851
|
+
}
|
|
7852
|
+
return lines;
|
|
7853
|
+
}
|
|
7854
|
+
function sleep3(ms) {
|
|
7855
|
+
let timer;
|
|
7856
|
+
const done = new Promise((resolve) => {
|
|
7857
|
+
timer = setTimeout(() => resolve("elapsed"), ms);
|
|
7858
|
+
});
|
|
7859
|
+
return { done, cancel: () => clearTimeout(timer) };
|
|
7860
|
+
}
|
|
7861
|
+
async function followImport(ctx, first) {
|
|
7862
|
+
const { api, analysisId } = ctx;
|
|
7863
|
+
const human = ctx.outputFormat === "human";
|
|
7864
|
+
const startedAt = Date.parse(first.startedAt);
|
|
7865
|
+
const since = Number.isFinite(startedAt) ? startedAt : Date.now();
|
|
7866
|
+
const status = new Status();
|
|
7867
|
+
let interrupt = () => {
|
|
7868
|
+
};
|
|
7869
|
+
const interrupted = new Promise((resolve) => {
|
|
7870
|
+
interrupt = () => resolve("interrupted");
|
|
7871
|
+
});
|
|
7872
|
+
process.once("SIGINT", interrupt);
|
|
7873
|
+
if (ctx.live) {
|
|
7874
|
+
status.start();
|
|
7875
|
+
} else {
|
|
7876
|
+
console.error("The import is still running on the platform. Waiting for it to finish.");
|
|
7877
|
+
}
|
|
7878
|
+
let current = first;
|
|
7879
|
+
try {
|
|
7880
|
+
for (; ; ) {
|
|
7881
|
+
if (ctx.live) status.set(renderImportBlock(current, Date.now() - since));
|
|
7882
|
+
const pause = sleep3(IMPORT_POLL_INTERVAL_MS);
|
|
7883
|
+
const woke = await Promise.race([pause.done, interrupted]);
|
|
7884
|
+
if (woke === "interrupted") {
|
|
7885
|
+
pause.cancel();
|
|
7886
|
+
status.stop();
|
|
7887
|
+
warn("Stopped waiting. The import keeps running on the platform.");
|
|
7888
|
+
hint(`See how far it is with 'diafunc analyze get ${analysisId}'.`);
|
|
7889
|
+
hint(`Start the run once it has finished with 'diafunc analyze rerun ${analysisId}'.`);
|
|
7890
|
+
process.exit(EXIT_CANCELLED);
|
|
7891
|
+
}
|
|
7892
|
+
let answer;
|
|
7893
|
+
try {
|
|
7894
|
+
answer = await api.analysis.getDataImport(analysisId);
|
|
7895
|
+
} catch (error) {
|
|
7896
|
+
if (error instanceof ApiError && error.status < 500) throw error;
|
|
7897
|
+
continue;
|
|
7898
|
+
}
|
|
7899
|
+
if (isImporting(answer.dataImport)) {
|
|
7900
|
+
current = answer.dataImport;
|
|
7901
|
+
continue;
|
|
7902
|
+
}
|
|
7903
|
+
status.stop();
|
|
7904
|
+
if (!answer.dataImport) {
|
|
7905
|
+
const shape = dataShape(answer.rowCount, answer.columnCount);
|
|
7906
|
+
if (human) {
|
|
7907
|
+
success(shape ? `Data imported: ${shape}.` : "Data imported.");
|
|
7908
|
+
} else if (ctx.machineReport === "stream") {
|
|
7909
|
+
process.stdout.write(JSON.stringify({
|
|
7910
|
+
type: "import",
|
|
7911
|
+
state: "IMPORTED",
|
|
7912
|
+
rowCount: answer.rowCount ?? null,
|
|
7913
|
+
columnCount: answer.columnCount ?? null
|
|
7914
|
+
}) + "\n");
|
|
7915
|
+
} else {
|
|
7916
|
+
console.error("The import has finished.");
|
|
7917
|
+
}
|
|
7918
|
+
}
|
|
7919
|
+
return { dataImport: answer.dataImport ?? null, rowCount: answer.rowCount ?? null, columnCount: answer.columnCount ?? null };
|
|
7920
|
+
}
|
|
7921
|
+
} finally {
|
|
7922
|
+
status.stop();
|
|
7923
|
+
process.off("SIGINT", interrupt);
|
|
7924
|
+
}
|
|
7925
|
+
}
|
|
7926
|
+
async function stopImport(api, analysisId) {
|
|
7927
|
+
let answer = await api.analysis.stopDataImport(analysisId);
|
|
7928
|
+
while (answer.dataImport?.state === "STOPPING") {
|
|
7929
|
+
await sleep3(IMPORT_POLL_INTERVAL_MS).done;
|
|
7930
|
+
answer = await api.analysis.getDataImport(analysisId);
|
|
7931
|
+
}
|
|
7932
|
+
return { dataImport: answer.dataImport ?? null, rowCount: answer.rowCount ?? null, columnCount: answer.columnCount ?? null };
|
|
7933
|
+
}
|
|
7934
|
+
async function importInFlight(api, analysisId) {
|
|
7935
|
+
try {
|
|
7936
|
+
const { dataImport } = await api.analysis.getDataImport(analysisId);
|
|
7937
|
+
return isImporting(dataImport) ? dataImport : null;
|
|
7938
|
+
} catch {
|
|
7939
|
+
return null;
|
|
7940
|
+
}
|
|
7941
|
+
}
|
|
7942
|
+
async function importBlockingRun(api, analysisId) {
|
|
7943
|
+
try {
|
|
7944
|
+
const { dataImport } = await api.analysis.getDataImport(analysisId);
|
|
7945
|
+
return dataImport?.blocksRun ? dataImport : null;
|
|
7946
|
+
} catch {
|
|
7947
|
+
return null;
|
|
7948
|
+
}
|
|
7949
|
+
}
|
|
7950
|
+
function uploadAgainHint(analysisId) {
|
|
7951
|
+
return `Upload the data with 'diafunc analyze upload ${analysisId} <file>'.`;
|
|
7952
|
+
}
|
|
7953
|
+
async function settle(ctx, answer, data) {
|
|
7954
|
+
let status = {
|
|
7955
|
+
dataImport: data.dataImport ?? null,
|
|
7956
|
+
rowCount: data.rowCount ?? null,
|
|
7957
|
+
columnCount: data.columnCount ?? null
|
|
7958
|
+
};
|
|
7959
|
+
if (isImporting(status.dataImport)) {
|
|
7960
|
+
status = await followImport(ctx, status.dataImport);
|
|
7961
|
+
}
|
|
7962
|
+
const ended = status.dataImport;
|
|
7963
|
+
if (ended) {
|
|
7964
|
+
if (ended.blocksRun) {
|
|
7965
|
+
throw new CliError(ended.message, { hint: uploadAgainHint(ctx.analysisId) });
|
|
7966
|
+
}
|
|
7967
|
+
warn(ended.message);
|
|
7968
|
+
}
|
|
7969
|
+
return { ...status, answer };
|
|
7970
|
+
}
|
|
7971
|
+
async function sendData(ctx, send) {
|
|
7972
|
+
let answer;
|
|
7973
|
+
try {
|
|
7974
|
+
answer = await send();
|
|
7975
|
+
} catch (error) {
|
|
7976
|
+
if (!(error instanceof ApiError) || error.status !== 409) throw error;
|
|
7977
|
+
const running = await importInFlight(ctx.api, ctx.analysisId);
|
|
7978
|
+
if (!running) throw error;
|
|
7979
|
+
if (!ctx.prompter) {
|
|
7980
|
+
throw new CliError(error.message, {
|
|
7981
|
+
hint: `Stop the running import with 'diafunc analyze stop-import ${ctx.analysisId}' and upload again, or wait for it: 'diafunc analyze get ${ctx.analysisId}' shows how far it is.`
|
|
7982
|
+
});
|
|
7983
|
+
}
|
|
7984
|
+
warn(error.message);
|
|
7985
|
+
const stopping = running.state === "STOPPING";
|
|
7986
|
+
const choice = await ctx.prompter.select({
|
|
7987
|
+
message: "What should happen?",
|
|
7988
|
+
choices: stopping ? [
|
|
7989
|
+
{ name: "Upload as soon as the stopped import has ended", value: "replace" },
|
|
7990
|
+
{ name: "Wait for the stopped import to end and upload nothing", value: "wait" }
|
|
7991
|
+
] : [
|
|
7992
|
+
{ name: "Wait for the running import to finish and keep its data", value: "wait" },
|
|
7993
|
+
{ name: "Stop the running import and upload again", value: "replace" }
|
|
7994
|
+
]
|
|
7995
|
+
});
|
|
7996
|
+
if (choice === "wait") {
|
|
7997
|
+
return settle(ctx, null, { dataImport: running });
|
|
7998
|
+
}
|
|
7999
|
+
await withStatus("Stopping the running import", () => stopImport(ctx.api, ctx.analysisId));
|
|
8000
|
+
answer = await send();
|
|
8001
|
+
}
|
|
8002
|
+
return settle(ctx, answer, answer);
|
|
8003
|
+
}
|
|
8004
|
+
async function queueRun(api, analysisId) {
|
|
8005
|
+
try {
|
|
8006
|
+
return await api.analysis.runAnalysis(analysisId);
|
|
8007
|
+
} catch (error) {
|
|
8008
|
+
if (!(error instanceof ApiError) || error.status !== 409) throw error;
|
|
8009
|
+
const blocking = await importBlockingRun(api, analysisId);
|
|
8010
|
+
if (!blocking) throw error;
|
|
8011
|
+
throw new CliError(error.message, {
|
|
8012
|
+
hint: isImporting(blocking) ? `Wait for the import to finish: 'diafunc analyze get ${analysisId}' shows how far it is. Then start the run with 'diafunc analyze rerun ${analysisId}'.` : uploadAgainHint(analysisId)
|
|
8013
|
+
});
|
|
8014
|
+
}
|
|
8015
|
+
}
|
|
8016
|
+
|
|
7607
8017
|
// src/commands/analyze/sources.ts
|
|
7608
8018
|
import * as fs8 from "fs";
|
|
7609
8019
|
import * as path7 from "path";
|
|
7610
|
-
var CAUTIONS = /* @__PURE__ */ new Set([
|
|
8020
|
+
var CAUTIONS = /* @__PURE__ */ new Set([
|
|
8021
|
+
"UNEVEN_COLUMNS",
|
|
8022
|
+
"TYPE_CONFLICT",
|
|
8023
|
+
"SOURCE_WARNING",
|
|
8024
|
+
"LEFT_OUT",
|
|
8025
|
+
"POSSIBLE_KEY",
|
|
8026
|
+
"MANY_TO_MANY",
|
|
8027
|
+
"NO_KEY",
|
|
8028
|
+
"TOO_LARGE",
|
|
8029
|
+
"HINT_REJECTED"
|
|
8030
|
+
]);
|
|
7611
8031
|
function recipeWithChoices(proposal, choices) {
|
|
7612
8032
|
if (proposal.parts.length < 2) return null;
|
|
7613
8033
|
const originColumn = choices.fileColumn ? proposal.originColumn : null;
|
|
7614
8034
|
const dropDuplicates = !choices.keepDuplicates;
|
|
7615
8035
|
if (originColumn === proposal.originColumn && dropDuplicates === proposal.dropDuplicates) return null;
|
|
7616
|
-
return { parts: proposal.parts, originColumn, dropDuplicates };
|
|
8036
|
+
return { parts: proposal.parts, originColumn, dropDuplicates, lookups: proposal.lookups ?? [] };
|
|
8037
|
+
}
|
|
8038
|
+
function labelOf(file) {
|
|
8039
|
+
return path7.basename(file, path7.extname(file)).trim().toLowerCase();
|
|
8040
|
+
}
|
|
8041
|
+
function otherRowsLabel(proposal) {
|
|
8042
|
+
const alternative = (proposal.lookups ?? []).find((lookup) => lookup.alternative)?.alternative;
|
|
8043
|
+
return alternative && alternative.parts.length > 0 ? alternative.parts[0].label : null;
|
|
8044
|
+
}
|
|
8045
|
+
function recipeWithRowsOf(proposal, rowsOf) {
|
|
8046
|
+
const wanted = labelOf(rowsOf);
|
|
8047
|
+
if (proposal.recipe.parts.some((part) => part.label.trim().toLowerCase() === wanted)) return null;
|
|
8048
|
+
const alternative = (proposal.lookups ?? []).find((lookup) => lookup.alternative)?.alternative;
|
|
8049
|
+
if (alternative && alternative.parts.some((part) => part.label.trim().toLowerCase() === wanted)) return alternative;
|
|
8050
|
+
const rows = proposal.recipe.parts.map((part) => part.label).join(", ");
|
|
8051
|
+
throw new CliError(`${rowsOf} cannot carry the rows of this table.`, {
|
|
8052
|
+
exitCode: EXIT_USAGE,
|
|
8053
|
+
hint: alternative ? `The rows can come from ${rows} or from ${alternative.parts.map((part) => part.label).join(", ")}.` : `These files have one reading: the rows come from ${rows}.`
|
|
8054
|
+
});
|
|
7617
8055
|
}
|
|
7618
8056
|
function planLines(plan) {
|
|
7619
8057
|
const lines = [{
|
|
@@ -7642,8 +8080,15 @@ async function uploadSeveral(api, analysisId, files, choices, human) {
|
|
|
7642
8080
|
for (const file of files) {
|
|
7643
8081
|
await withStatus(`Uploading ${path7.basename(file)}`, () => api.analysis.addSource(analysisId, multipart(file)));
|
|
7644
8082
|
}
|
|
8083
|
+
let other = null;
|
|
7645
8084
|
const plan = await withStatus("Reading the files together", async () => {
|
|
7646
8085
|
const proposal = await api.analysis.planSources(analysisId, null);
|
|
8086
|
+
const exchanged = choices.rowsOf ? recipeWithRowsOf(proposal, choices.rowsOf) : null;
|
|
8087
|
+
if (exchanged) {
|
|
8088
|
+
other = proposal.recipe.parts[0]?.label ?? null;
|
|
8089
|
+
return api.analysis.planSources(analysisId, exchanged);
|
|
8090
|
+
}
|
|
8091
|
+
other = otherRowsLabel(proposal);
|
|
7647
8092
|
const chosen = recipeWithChoices(proposal.recipe, choices);
|
|
7648
8093
|
return chosen ? api.analysis.planSources(analysisId, chosen) : proposal;
|
|
7649
8094
|
});
|
|
@@ -7652,9 +8097,17 @@ async function uploadSeveral(api, analysisId, files, choices, human) {
|
|
|
7652
8097
|
if (line.caution) warn(line.text);
|
|
7653
8098
|
else detail(line.text);
|
|
7654
8099
|
}
|
|
8100
|
+
if (other) {
|
|
8101
|
+
hint(`These files can be read two ways. For one row per row of ${other}, add --rows-of ${other}.`);
|
|
8102
|
+
}
|
|
8103
|
+
}
|
|
8104
|
+
if (choices.planOnly) {
|
|
8105
|
+
if (human) hint("Plan only: the files are stored with the analysis and nothing was built.");
|
|
8106
|
+
return { plan, rowCount: null, columnCount: null };
|
|
7655
8107
|
}
|
|
8108
|
+
const tables = plan.recipe.parts.length + (plan.recipe.lookups ?? []).reduce((sum, lookup) => sum + lookup.parts.length, 0);
|
|
7656
8109
|
return withStatus(
|
|
7657
|
-
`Building one table from ${
|
|
8110
|
+
`Building one table from ${tables} file${tables === 1 ? "" : "s"}`,
|
|
7658
8111
|
() => api.analysis.buildSources(analysisId, plan.recipe)
|
|
7659
8112
|
);
|
|
7660
8113
|
}
|
|
@@ -7677,9 +8130,17 @@ function getOutputFormat15(cmd) {
|
|
|
7677
8130
|
function noInteractiveFlag(cmd) {
|
|
7678
8131
|
return cmd.optsWithGlobals().interactive === false;
|
|
7679
8132
|
}
|
|
7680
|
-
function
|
|
7681
|
-
|
|
7682
|
-
|
|
8133
|
+
function importContext(api, analysisId, cmd, machineReport) {
|
|
8134
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
8135
|
+
const noInteractive = noInteractiveFlag(cmd);
|
|
8136
|
+
return {
|
|
8137
|
+
api,
|
|
8138
|
+
analysisId,
|
|
8139
|
+
outputFormat,
|
|
8140
|
+
live: outputFormat === "human" && !noInteractive && isInteractive(),
|
|
8141
|
+
prompter: canPrompt(outputFormat, noInteractive) ? createInquirerPrompter() : null,
|
|
8142
|
+
machineReport
|
|
8143
|
+
};
|
|
7683
8144
|
}
|
|
7684
8145
|
function collectQuestion(value, previous = []) {
|
|
7685
8146
|
return previous.concat([value]);
|
|
@@ -7726,6 +8187,7 @@ async function runAnalysis(files, options, cmd) {
|
|
|
7726
8187
|
const noInteractive = noInteractiveFlag(cmd);
|
|
7727
8188
|
const interactive = canPrompt(outputFormat, noInteractive);
|
|
7728
8189
|
const api = createApiClient();
|
|
8190
|
+
let presetTargets;
|
|
7729
8191
|
if (options.preset) {
|
|
7730
8192
|
const opt = await api.analysis.getPreset(options.preset);
|
|
7731
8193
|
if (!opt.preset) {
|
|
@@ -7734,17 +8196,18 @@ async function runAnalysis(files, options, cmd) {
|
|
|
7734
8196
|
process.exit(EXIT_FAILURE);
|
|
7735
8197
|
}
|
|
7736
8198
|
const p = opt.preset;
|
|
7737
|
-
if (options.targets === void 0 && p.targetKeys.length > 0)
|
|
8199
|
+
if (options.targets === void 0 && p.targetKeys.length > 0) presetTargets = p.targetKeys;
|
|
7738
8200
|
if (options.question === void 0 && p.questions.length > 0) options.question = [...p.questions];
|
|
7739
8201
|
if (options.segment === void 0 && p.segmentKey) options.segment = p.segmentKey;
|
|
7740
8202
|
if (options.hours === void 0) options.hours = p.time;
|
|
7741
8203
|
if (options.budget === void 0) options.budget = p.budget;
|
|
7742
8204
|
}
|
|
7743
|
-
const
|
|
7744
|
-
|
|
8205
|
+
const typedTargets = occurrences(options.targets)?.filter((entry) => entry.trim().length > 0);
|
|
8206
|
+
const targetsGiven = (typedTargets?.length ?? 0) > 0 || (presetTargets?.length ?? 0) > 0;
|
|
8207
|
+
if (!interactive && !targetsGiven) {
|
|
7745
8208
|
usageError(
|
|
7746
8209
|
`Target columns are required, and ${whyNoPrompt(outputFormat, noInteractive)}.`,
|
|
7747
|
-
`Pass --targets <
|
|
8210
|
+
`Pass --targets <columns> or --preset <id>. The names are the column headers of ${files.length > 1 ? "the files" : path8.basename(file)}.`
|
|
7748
8211
|
);
|
|
7749
8212
|
}
|
|
7750
8213
|
const prompter = createInquirerPrompter();
|
|
@@ -7765,9 +8228,11 @@ async function runAnalysis(files, options, cmd) {
|
|
|
7765
8228
|
introduction: options.introduction ?? null,
|
|
7766
8229
|
hours: options.hours ?? DEFAULT_HOURS,
|
|
7767
8230
|
budget: options.budget ?? DEFAULT_BUDGET,
|
|
7768
|
-
targets
|
|
8231
|
+
// The targets and the segment are column names, and the columns exist only once the file is
|
|
8232
|
+
// uploaded. They are set below, read against the real header.
|
|
8233
|
+
targets: null,
|
|
7769
8234
|
questions: questionsOf(options.question),
|
|
7770
|
-
segment:
|
|
8235
|
+
segment: null
|
|
7771
8236
|
};
|
|
7772
8237
|
const created = await withStatus(`Creating analysis "${creation.name}"`, () => api.analysis.create(request));
|
|
7773
8238
|
if (isDryRun()) {
|
|
@@ -7775,33 +8240,66 @@ async function runAnalysis(files, options, cmd) {
|
|
|
7775
8240
|
return;
|
|
7776
8241
|
}
|
|
7777
8242
|
detail(`analysisId: ${created.analysisId}`);
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
8243
|
+
await sendData(importContext(api, created.analysisId, cmd, "stream"), () => files.length > 1 ? uploadSeveral(api, created.analysisId, files, stackChoices(options), outputFormat === "human") : withStatus(
|
|
8244
|
+
`Uploading ${path8.basename(file)}`,
|
|
8245
|
+
() => api.analysis.uploadDataMultipart(created.analysisId, multipartFromFile(file))
|
|
8246
|
+
));
|
|
8247
|
+
const columns = await readColumns(api, created.analysisId);
|
|
8248
|
+
const named = namedColumns(
|
|
8249
|
+
created.analysisId,
|
|
8250
|
+
columns,
|
|
8251
|
+
interactive,
|
|
8252
|
+
{ typedTargets, presetTargets, segment: options.segment }
|
|
8253
|
+
);
|
|
7786
8254
|
let runHours = request.hours;
|
|
7787
8255
|
if (interactive) {
|
|
7788
8256
|
const configuredHours = await configureInteractively(api, prompter, created.analysisId, request, {
|
|
7789
|
-
targets:
|
|
7790
|
-
segment:
|
|
8257
|
+
targets: named.targets,
|
|
8258
|
+
segment: named.segment,
|
|
7791
8259
|
questions: options.question === void 0 ? void 0 : questionsOf(options.question),
|
|
7792
8260
|
hours: options.hours,
|
|
7793
8261
|
budget: options.budget
|
|
7794
|
-
});
|
|
8262
|
+
}, columns);
|
|
7795
8263
|
if (configuredHours === null) return;
|
|
7796
8264
|
runHours = configuredHours;
|
|
8265
|
+
} else {
|
|
8266
|
+
await withStatus("Saving the analysis settings", () => api.analysis.update(created.analysisId, {
|
|
8267
|
+
...request,
|
|
8268
|
+
targets: named.targets ?? null,
|
|
8269
|
+
segment: named.segment ?? null
|
|
8270
|
+
}));
|
|
7797
8271
|
}
|
|
7798
|
-
const run = await withStatus("Queuing analysis run", () => api
|
|
8272
|
+
const run = await withStatus("Queuing analysis run", () => queueRun(api, created.analysisId));
|
|
7799
8273
|
detail(`runId: ${run.runId}`);
|
|
7800
8274
|
console.log();
|
|
7801
8275
|
await monitorRun(api, created.analysisId, run.runId, budgetHoursOf(runHours), cmd);
|
|
7802
8276
|
}
|
|
7803
|
-
|
|
7804
|
-
const
|
|
8277
|
+
function namedColumns(analysisId, columns, interactive, given) {
|
|
8278
|
+
const names = columns.map((c) => c.name).filter((name) => name && name.length > 0);
|
|
8279
|
+
const read = (resolve) => {
|
|
8280
|
+
try {
|
|
8281
|
+
return resolve();
|
|
8282
|
+
} catch (error) {
|
|
8283
|
+
if (!(error instanceof CliError)) throw error;
|
|
8284
|
+
if (!interactive) {
|
|
8285
|
+
throw new CliError(error.message, {
|
|
8286
|
+
exitCode: error.exitCode,
|
|
8287
|
+
hint: [
|
|
8288
|
+
error.hint,
|
|
8289
|
+
`Analysis ${analysisId} is created and holds the data. Name the columns with 'diafunc analyze targets ${analysisId} <column...>' and start it with 'diafunc analyze rerun ${analysisId}'.`
|
|
8290
|
+
].filter(Boolean).join("\n ")
|
|
8291
|
+
});
|
|
8292
|
+
}
|
|
8293
|
+
warn(error.message);
|
|
8294
|
+
return void 0;
|
|
8295
|
+
}
|
|
8296
|
+
};
|
|
8297
|
+
const targets = given.typedTargets && given.typedTargets.length > 0 ? read(() => resolveColumnArguments(given.typedTargets, names, analysisId)) : given.presetTargets && given.presetTargets.length > 0 ? read(() => resolveColumnNames(given.presetTargets, names, analysisId)) : void 0;
|
|
8298
|
+
const segment = given.segment === void 0 || given.segment === "" ? void 0 : read(() => resolveColumnArgument(given.segment, names, analysisId));
|
|
8299
|
+
return { targets, segment };
|
|
8300
|
+
}
|
|
8301
|
+
async function configureInteractively(api, prompter, analysisId, recipe, supplied, knownColumns) {
|
|
8302
|
+
const columns = knownColumns ?? await readColumns(api, analysisId);
|
|
7805
8303
|
const presets = await readPresets(api);
|
|
7806
8304
|
console.log();
|
|
7807
8305
|
const answers = await promptRunFields(prompter, { columns, presets, supplied });
|
|
@@ -7983,8 +8481,11 @@ async function listAnalyses(limit, cmd) {
|
|
|
7983
8481
|
hours: a.hours,
|
|
7984
8482
|
budget: a.budget,
|
|
7985
8483
|
targets: a.targets,
|
|
7986
|
-
|
|
7987
|
-
|
|
8484
|
+
// A reader sees the import where the run state would be: no run can start before the data is
|
|
8485
|
+
// in place. JSON keeps the state as it is and carries the import beside it.
|
|
8486
|
+
latestRunState: outputFormat !== "json" && isImporting(a.dataImport) ? importingLabel(a.dataImport) : a.latestRunState,
|
|
8487
|
+
createdAt: a.createdAt,
|
|
8488
|
+
...outputFormat === "json" && a.dataImport !== void 0 ? { dataImport: a.dataImport } : {}
|
|
7988
8489
|
})), {
|
|
7989
8490
|
format: outputFormat,
|
|
7990
8491
|
columns: [
|
|
@@ -8098,7 +8599,7 @@ async function rerunAnalysis(analysisId, cmd) {
|
|
|
8098
8599
|
);
|
|
8099
8600
|
if (configuredHours === null) return;
|
|
8100
8601
|
}
|
|
8101
|
-
const run = await api
|
|
8602
|
+
const run = await queueRun(api, analysisId);
|
|
8102
8603
|
if (isDryRun()) {
|
|
8103
8604
|
hint("Dry run: no run was queued.");
|
|
8104
8605
|
return;
|
|
@@ -8124,6 +8625,10 @@ async function openAnalysis(analysisId) {
|
|
|
8124
8625
|
hint("The notebook is not available yet. Run the analysis first.");
|
|
8125
8626
|
}
|
|
8126
8627
|
}
|
|
8628
|
+
function typedColumns(given) {
|
|
8629
|
+
const entries = occurrences(given);
|
|
8630
|
+
return entries === void 0 ? null : resolveColumnArguments(entries, []);
|
|
8631
|
+
}
|
|
8127
8632
|
async function createAnalysis(options, cmd) {
|
|
8128
8633
|
const outputFormat = getOutputFormat15(cmd);
|
|
8129
8634
|
const api = createApiClient();
|
|
@@ -8135,7 +8640,7 @@ async function createAnalysis(options, cmd) {
|
|
|
8135
8640
|
introduction: options.introduction ?? null,
|
|
8136
8641
|
hours: options.hours ?? null,
|
|
8137
8642
|
budget: options.budget ?? null,
|
|
8138
|
-
targets:
|
|
8643
|
+
targets: typedColumns(options.targets),
|
|
8139
8644
|
questions: questionsOf(options.question),
|
|
8140
8645
|
segment: options.segment ?? null
|
|
8141
8646
|
};
|
|
@@ -8169,44 +8674,98 @@ async function patchAndPrint(analysisId, value, handler, successLabel, cmd) {
|
|
|
8169
8674
|
format(updated, { format: outputFormat });
|
|
8170
8675
|
}
|
|
8171
8676
|
}
|
|
8677
|
+
async function columnNames(api, analysisId) {
|
|
8678
|
+
return (await api.analysis.getColumns(analysisId)).map((c) => c.name).filter((name) => name && name.length > 0);
|
|
8679
|
+
}
|
|
8680
|
+
async function patchColumns(analysisId, given, send, successLabel, cmd) {
|
|
8681
|
+
const api = createApiClient();
|
|
8682
|
+
const columns = resolveColumnArguments(occurrences(given) ?? [], await columnNames(api, analysisId), analysisId);
|
|
8683
|
+
await patchAndPrint(analysisId, "", () => send(api, columns), successLabel, cmd);
|
|
8684
|
+
}
|
|
8172
8685
|
function stackChoices(options) {
|
|
8173
|
-
return {
|
|
8686
|
+
return {
|
|
8687
|
+
fileColumn: options.fileColumn !== false,
|
|
8688
|
+
keepDuplicates: options.keepDuplicates === true,
|
|
8689
|
+
rowsOf: options.rowsOf,
|
|
8690
|
+
planOnly: options.planOnly === true
|
|
8691
|
+
};
|
|
8174
8692
|
}
|
|
8175
8693
|
async function uploadData(analysisId, files, options, cmd) {
|
|
8176
8694
|
const api = createApiClient();
|
|
8695
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
8696
|
+
const ctx = importContext(api, analysisId, cmd, "none");
|
|
8177
8697
|
const file = files[0];
|
|
8178
8698
|
if (files.length > 1) {
|
|
8179
8699
|
if (options.url) {
|
|
8180
8700
|
usageError("Provide either files or --url, not both.", "Drop one of the two and run it again.");
|
|
8181
8701
|
}
|
|
8182
|
-
const
|
|
8183
|
-
|
|
8702
|
+
const built = await sendData(
|
|
8703
|
+
ctx,
|
|
8704
|
+
() => uploadSeveral(api, analysisId, files, stackChoices(options), outputFormat === "human")
|
|
8705
|
+
);
|
|
8184
8706
|
if (outputFormat !== "human") {
|
|
8185
|
-
format(
|
|
8707
|
+
format({
|
|
8708
|
+
...built.answer,
|
|
8709
|
+
rowCount: built.rowCount,
|
|
8710
|
+
columnCount: built.columnCount,
|
|
8711
|
+
dataImport: built.dataImport
|
|
8712
|
+
}, { format: outputFormat });
|
|
8186
8713
|
}
|
|
8187
8714
|
return;
|
|
8188
8715
|
}
|
|
8189
8716
|
const dataUrl = options.url;
|
|
8190
|
-
if (dataUrl) {
|
|
8191
|
-
|
|
8192
|
-
|
|
8717
|
+
if (dataUrl && file) {
|
|
8718
|
+
usageError("Provide either a file or --url, not both.", "Drop one of the two and run it again.");
|
|
8719
|
+
}
|
|
8720
|
+
if (!dataUrl) {
|
|
8721
|
+
if (!file) {
|
|
8722
|
+
usageError(
|
|
8723
|
+
"Provide a file path or --url <URL>.",
|
|
8724
|
+
`For example: diafunc analyze upload ${analysisId} data.csv`
|
|
8725
|
+
);
|
|
8726
|
+
}
|
|
8727
|
+
if (!fs9.existsSync(file)) {
|
|
8728
|
+
throw new CliError(`File not found: ${file}`, { exitCode: EXIT_USAGE });
|
|
8193
8729
|
}
|
|
8194
|
-
|
|
8730
|
+
}
|
|
8731
|
+
const uploaded = await sendData(ctx, () => dataUrl ? withStatus(`Uploading from ${dataUrl}`, () => api.analysis.uploadDataUrl(analysisId, { dataUrl })) : withStatus(
|
|
8732
|
+
`Uploading ${path8.basename(file)}`,
|
|
8733
|
+
() => api.analysis.uploadDataMultipart(analysisId, multipartFromFile(file))
|
|
8734
|
+
));
|
|
8735
|
+
if (isDryRun()) {
|
|
8736
|
+
hint("Dry run: nothing was uploaded.");
|
|
8195
8737
|
return;
|
|
8196
8738
|
}
|
|
8197
|
-
if (
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8739
|
+
if (outputFormat !== "human") {
|
|
8740
|
+
format({
|
|
8741
|
+
dataImport: uploaded.dataImport,
|
|
8742
|
+
rowCount: uploaded.rowCount,
|
|
8743
|
+
columnCount: uploaded.columnCount
|
|
8744
|
+
}, { format: outputFormat });
|
|
8202
8745
|
}
|
|
8203
|
-
|
|
8204
|
-
|
|
8746
|
+
}
|
|
8747
|
+
async function stopDataImport(analysisId, cmd) {
|
|
8748
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
8749
|
+
const api = createApiClient();
|
|
8750
|
+
const stopped = await withStatus("Stopping the data import", () => stopImport(api, analysisId));
|
|
8751
|
+
if (isDryRun()) {
|
|
8752
|
+
hint("Dry run: nothing was stopped.");
|
|
8753
|
+
return;
|
|
8205
8754
|
}
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8755
|
+
if (outputFormat !== "human") {
|
|
8756
|
+
format(stopped, { format: outputFormat });
|
|
8757
|
+
return;
|
|
8758
|
+
}
|
|
8759
|
+
if (!stopped.dataImport) {
|
|
8760
|
+
success(`No data import is running for analysis ${analysisId}.`);
|
|
8761
|
+
return;
|
|
8762
|
+
}
|
|
8763
|
+
if (stopped.dataImport.state === "STOPPED") {
|
|
8764
|
+
success(`Stopped the data import of analysis ${analysisId}.`);
|
|
8765
|
+
hint(stopped.dataImport.message);
|
|
8766
|
+
return;
|
|
8767
|
+
}
|
|
8768
|
+
warn(stopped.dataImport.message);
|
|
8210
8769
|
}
|
|
8211
8770
|
async function listColumns(analysisId, cmd) {
|
|
8212
8771
|
const outputFormat = getOutputFormat15(cmd);
|
|
@@ -8297,7 +8856,7 @@ async function savePreset(options, cmd) {
|
|
|
8297
8856
|
const preset = {
|
|
8298
8857
|
presetId: options.id ?? null,
|
|
8299
8858
|
name: options.name,
|
|
8300
|
-
targetKeys:
|
|
8859
|
+
targetKeys: typedColumns(options.targets) ?? [],
|
|
8301
8860
|
questions: questionsOf(options.question) ?? [],
|
|
8302
8861
|
segmentKey: options.segment ?? null,
|
|
8303
8862
|
time: options.hours,
|
|
@@ -8377,9 +8936,11 @@ async function updateTriggerCmd(triggerId, options, cmd) {
|
|
|
8377
8936
|
});
|
|
8378
8937
|
format(trigger, { format: outputFormat });
|
|
8379
8938
|
}
|
|
8939
|
+
var COLUMN_LIST_HELP = "one argument each or comma-separated; a name that contains a comma is an argument of its own, or goes in double quotes inside a list";
|
|
8940
|
+
var TARGETS_HELP = `Target column names: repeat the flag or separate them with commas; a name that contains a comma is one flag of its own, or goes in double quotes inside a list`;
|
|
8380
8941
|
function registerAnalyzeCommand(program) {
|
|
8381
8942
|
const analyze = program.command("analyze").description("Run and manage automatic analyses");
|
|
8382
|
-
analyze.command("run", { isDefault: true }).description("Create an analysis from a data file, configure it and run it (the default: `analyze <file>`)").argument("[files...]", "Data file to analyze (CSV, Excel and more than 45 file formats; see `table import-formats`). Several files with the same columns are stacked
|
|
8943
|
+
analyze.command("run", { isDefault: true }).description("Create an analysis from a data file, configure it and run it (the default: `analyze <file>`)").argument("[files...]", "Data file to analyze (CSV, Excel and more than 45 file formats; see `table import-formats`). Several files are combined into one table: files with the same columns are stacked, a file that shares a key adds its columns").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>", `Time budget (hours). Default ${DEFAULT_HOURS}, the Standard preset; a saved preset applies when omitted`).option("--budget <credits>", `Credit budget. Default ${Number(DEFAULT_BUDGET).toLocaleString("en-US")}, the Standard preset; a saved preset applies when omitted`).option("--targets <columns>", `${TARGETS_HELP} (required when not interactive)`, collectColumns).option("--question <text>", "A question for the analysis to answer; repeat the flag for several", collectQuestion).option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction shown at the top of the notebook").option("--preset <id>", "Apply a saved preset as defaults (explicit flags override it)").option("--no-file-column", "With several files: do not add the column that records the file each row came from").option("--keep-duplicates", "With several files: keep rows that occur in more than one file").option("--rows-of <file>", "With several files that can be read two ways: the file in which one row is one observation").action(async (files, options, cmd) => {
|
|
8383
8944
|
try {
|
|
8384
8945
|
if (files.length === 0) {
|
|
8385
8946
|
analyze.help();
|
|
@@ -8418,14 +8979,14 @@ function registerAnalyzeCommand(program) {
|
|
|
8418
8979
|
handleError(error);
|
|
8419
8980
|
}
|
|
8420
8981
|
});
|
|
8421
|
-
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) => {
|
|
8982
|
+
analyze.command("rerun").description("Queue a fresh run on an existing analysis (asks for anything a run still needs). A run cannot start while the data is still being imported").argument("<id>", "Analysis ID to rerun").action(async (id, _options, cmd) => {
|
|
8422
8983
|
try {
|
|
8423
8984
|
await rerunAnalysis(id, cmd);
|
|
8424
8985
|
} catch (error) {
|
|
8425
8986
|
reportCommandError(error);
|
|
8426
8987
|
}
|
|
8427
8988
|
});
|
|
8428
|
-
analyze.command("create").description("Create an analysis without uploading data or running it").option("--name <name>", "Analysis name").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").option("--hours <hours>", "
|
|
8989
|
+
analyze.command("create").description("Create an analysis without uploading data or running it").option("--name <name>", "Analysis name").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").option("--hours <hours>", "Time budget (hours)").option("--budget <credits>", "Credit budget").option("--targets <columns>", TARGETS_HELP, collectColumns).option("--question <text>", "A question for the analysis to answer; repeat the flag for several", collectQuestion).option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction shown at the top of the notebook").action(async (options, cmd) => {
|
|
8429
8990
|
try {
|
|
8430
8991
|
await createAnalysis(options, cmd);
|
|
8431
8992
|
} catch (error) {
|
|
@@ -8493,7 +9054,7 @@ function registerAnalyzeCommand(program) {
|
|
|
8493
9054
|
handleError(error);
|
|
8494
9055
|
}
|
|
8495
9056
|
});
|
|
8496
|
-
analyze.command("hours").description("Set the
|
|
9057
|
+
analyze.command("hours").description("Set the time budget (hours) for the next run").argument("<id>", "Analysis ID").argument("<hours>", "Time budget (hours), e.g. 4").action(async (id, hours, _options, cmd) => {
|
|
8497
9058
|
try {
|
|
8498
9059
|
await patchAndPrint(
|
|
8499
9060
|
id,
|
|
@@ -8519,13 +9080,12 @@ function registerAnalyzeCommand(program) {
|
|
|
8519
9080
|
handleError(error);
|
|
8520
9081
|
}
|
|
8521
9082
|
});
|
|
8522
|
-
analyze.command("targets").description("Set the target
|
|
9083
|
+
analyze.command("targets").description("Set the target columns, matched against the columns of the analysis data").argument("<id>", "Analysis ID").argument("<column...>", `Target column names, ${COLUMN_LIST_HELP}`).action(async (id, given, _options, cmd) => {
|
|
8523
9084
|
try {
|
|
8524
|
-
|
|
8525
|
-
await patchAndPrint(
|
|
9085
|
+
await patchColumns(
|
|
8526
9086
|
id,
|
|
8527
|
-
|
|
8528
|
-
(api,
|
|
9087
|
+
given,
|
|
9088
|
+
(api, targets) => api.analysis.patchTargets(id, { targets }),
|
|
8529
9089
|
"Targets",
|
|
8530
9090
|
cmd
|
|
8531
9091
|
);
|
|
@@ -8533,13 +9093,12 @@ function registerAnalyzeCommand(program) {
|
|
|
8533
9093
|
handleError(error);
|
|
8534
9094
|
}
|
|
8535
9095
|
});
|
|
8536
|
-
analyze.command("feature-exclusions").description("Set the columns every fit leaves out as an input (
|
|
9096
|
+
analyze.command("feature-exclusions").description("Set the columns every fit leaves out as an input (a single empty string leaves nothing out)").argument("<id>", "Analysis ID").argument("<column...>", `Column names, ${COLUMN_LIST_HELP}`).action(async (id, given, _options, cmd) => {
|
|
8537
9097
|
try {
|
|
8538
|
-
|
|
8539
|
-
await patchAndPrint(
|
|
9098
|
+
await patchColumns(
|
|
8540
9099
|
id,
|
|
8541
|
-
|
|
8542
|
-
(api,
|
|
9100
|
+
given,
|
|
9101
|
+
(api, columns) => api.analysis.patchFeatureExclusions(id, { columns }),
|
|
8543
9102
|
"Columns left out of the fit",
|
|
8544
9103
|
cmd
|
|
8545
9104
|
);
|
|
@@ -8547,13 +9106,12 @@ function registerAnalyzeCommand(program) {
|
|
|
8547
9106
|
handleError(error);
|
|
8548
9107
|
}
|
|
8549
9108
|
});
|
|
8550
|
-
analyze.command("confirmed-inputs").description("Set the columns the owner confirms as known before the outcome (
|
|
9109
|
+
analyze.command("confirmed-inputs").description("Set the columns the owner confirms as known before the outcome (a single empty string confirms nothing). A confirmed column raises no leakage concern.").argument("<id>", "Analysis ID").argument("<column...>", `Column names, ${COLUMN_LIST_HELP}`).action(async (id, given, _options, cmd) => {
|
|
8551
9110
|
try {
|
|
8552
|
-
|
|
8553
|
-
await patchAndPrint(
|
|
9111
|
+
await patchColumns(
|
|
8554
9112
|
id,
|
|
8555
|
-
|
|
8556
|
-
(api,
|
|
9113
|
+
given,
|
|
9114
|
+
(api, columns) => api.analysis.patchConfirmedInputs(id, { columns }),
|
|
8557
9115
|
"Columns known before the outcome",
|
|
8558
9116
|
cmd
|
|
8559
9117
|
);
|
|
@@ -8575,12 +9133,14 @@ function registerAnalyzeCommand(program) {
|
|
|
8575
9133
|
handleError(error);
|
|
8576
9134
|
}
|
|
8577
9135
|
});
|
|
8578
|
-
analyze.command("segment").description("Set or clear the segmentation column (empty string clears)").argument("<id>", "Analysis ID").argument("<name>", "Column name (empty string to clear)").action(async (id, name, _options, cmd) => {
|
|
9136
|
+
analyze.command("segment").description("Set or clear the segmentation column (empty string clears)").argument("<id>", "Analysis ID").argument("<name>", "Column name, matched against the columns of the analysis data (empty string to clear)").action(async (id, name, _options, cmd) => {
|
|
8579
9137
|
try {
|
|
9138
|
+
const api = createApiClient();
|
|
9139
|
+
const segment = name === "" ? null : resolveColumnArgument(name, await columnNames(api, id), id);
|
|
8580
9140
|
await patchAndPrint(
|
|
8581
9141
|
id,
|
|
8582
9142
|
name,
|
|
8583
|
-
(
|
|
9143
|
+
() => api.analysis.patchSegment(id, { segment }),
|
|
8584
9144
|
"Segment",
|
|
8585
9145
|
cmd
|
|
8586
9146
|
);
|
|
@@ -8588,9 +9148,16 @@ function registerAnalyzeCommand(program) {
|
|
|
8588
9148
|
handleError(error);
|
|
8589
9149
|
}
|
|
8590
9150
|
});
|
|
8591
|
-
analyze.command("upload").description("Replace the analysis data with a new file (any supported format; see `table import-formats`)").argument("<id>", "Analysis ID").argument("[files...]", "Data file to upload (CSV, Excel and more than 45 file formats; see `table import-formats`). Several files with the same columns are stacked
|
|
9151
|
+
analyze.command("upload").description("Replace the analysis data with a new file (any supported format; see `table import-formats`). An import that takes long is followed until it has finished").argument("<id>", "Analysis ID").argument("[files...]", "Data file to upload (CSV, Excel and more than 45 file formats; see `table import-formats`). Several files are combined into one table: files with the same columns are stacked, a file that shares a key adds its columns").option("--url <url>", "HTTPS URL to fetch the data file from, instead of a file path").option("--no-file-column", "With several files: do not add the column that records the file each row came from").option("--keep-duplicates", "With several files: keep rows that occur in more than one file").option("--rows-of <file>", "With several files that can be read two ways: the file in which one row is one observation").option("--plan-only", "With several files: store them and print how they fit together, without building the table").action(async (id, files, options, cmd) => {
|
|
8592
9152
|
try {
|
|
8593
9153
|
await uploadData(id, files, options, cmd);
|
|
9154
|
+
} catch (error) {
|
|
9155
|
+
reportCommandError(error);
|
|
9156
|
+
}
|
|
9157
|
+
});
|
|
9158
|
+
analyze.command("stop-import").description("Stop the data import that is running for an analysis, so the data can be uploaded again").argument("<id>", "Analysis ID").action(async (id, _options, cmd) => {
|
|
9159
|
+
try {
|
|
9160
|
+
await stopDataImport(id, cmd);
|
|
8594
9161
|
} catch (error) {
|
|
8595
9162
|
handleError(error);
|
|
8596
9163
|
}
|
|
@@ -8631,7 +9198,7 @@ function registerAnalyzeCommand(program) {
|
|
|
8631
9198
|
handleError(error);
|
|
8632
9199
|
}
|
|
8633
9200
|
});
|
|
8634
|
-
presets.command("save").description("Create a new preset (omit --id) or update an existing one (with --id)").requiredOption("--name <name>", "Preset name").requiredOption("--targets <
|
|
9201
|
+
presets.command("save").description("Create a new preset (omit --id) or update an existing one (with --id)").requiredOption("--name <name>", "Preset name").requiredOption("--targets <columns>", TARGETS_HELP, collectColumns).requiredOption("--hours <hours>", "Time budget (hours)").requiredOption("--budget <credits>", "Credit budget").option("--question <text>", "A question for the analysis to answer; repeat the flag for several", collectQuestion).option("--segment <name>", "Column to segment the analysis by").option("--id <id>", "Existing preset ID (update mode)").action(async (options, cmd) => {
|
|
8635
9202
|
try {
|
|
8636
9203
|
await savePreset(options, cmd);
|
|
8637
9204
|
} catch (error) {
|
|
@@ -8678,13 +9245,178 @@ function registerAnalyzeCommand(program) {
|
|
|
8678
9245
|
});
|
|
8679
9246
|
}
|
|
8680
9247
|
|
|
8681
|
-
// src/commands/
|
|
8682
|
-
|
|
9248
|
+
// src/commands/public/index.ts
|
|
9249
|
+
var MIN_LIMIT = 1;
|
|
9250
|
+
var MAX_LIMIT = 500;
|
|
8683
9251
|
function getOutputFormat16(cmd) {
|
|
8684
9252
|
const config = loadConfig();
|
|
8685
9253
|
const globalOpts = cmd.optsWithGlobals();
|
|
8686
9254
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
8687
9255
|
}
|
|
9256
|
+
function parseLimit(value) {
|
|
9257
|
+
const limit = Number(value);
|
|
9258
|
+
if (!Number.isInteger(limit) || limit < MIN_LIMIT || limit > MAX_LIMIT) {
|
|
9259
|
+
throw new CliError(
|
|
9260
|
+
`Invalid limit "${value}". Expected a whole number from ${MIN_LIMIT} to ${MAX_LIMIT}.`,
|
|
9261
|
+
{ exitCode: EXIT_USAGE }
|
|
9262
|
+
);
|
|
9263
|
+
}
|
|
9264
|
+
return limit;
|
|
9265
|
+
}
|
|
9266
|
+
var ISO_INSTANT = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2}))?$/;
|
|
9267
|
+
function parseChangedSince(value) {
|
|
9268
|
+
const text2 = value.trim();
|
|
9269
|
+
const instant = ISO_INSTANT.test(text2) ? Date.parse(text2) : Number.NaN;
|
|
9270
|
+
if (!Number.isFinite(instant)) {
|
|
9271
|
+
throw new CliError(
|
|
9272
|
+
`Invalid timestamp "${value}". Expected ISO-8601, such as 2026-10-01 or 2026-10-01T08:30:00Z.`,
|
|
9273
|
+
{ exitCode: EXIT_USAGE }
|
|
9274
|
+
);
|
|
9275
|
+
}
|
|
9276
|
+
return instant;
|
|
9277
|
+
}
|
|
9278
|
+
function instantMillis(value) {
|
|
9279
|
+
if (typeof value === "number") return value;
|
|
9280
|
+
return typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
9281
|
+
}
|
|
9282
|
+
async function readPublicAnalyses(analysis, options) {
|
|
9283
|
+
const analyses = [];
|
|
9284
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9285
|
+
let cursor = options.cursor;
|
|
9286
|
+
for (; ; ) {
|
|
9287
|
+
const page = await analysis.listPublic({ cursor, limit: options.limit });
|
|
9288
|
+
for (const entry of page.analyses ?? []) {
|
|
9289
|
+
if (options.changedSince === void 0 || instantMillis(entry.changedAt) >= options.changedSince) {
|
|
9290
|
+
analyses.push(entry);
|
|
9291
|
+
}
|
|
9292
|
+
}
|
|
9293
|
+
const next = page.nextCursor ?? null;
|
|
9294
|
+
if (!options.all || next === null) return { analyses, nextCursor: next };
|
|
9295
|
+
if (seen.has(next)) {
|
|
9296
|
+
throw new CliError(`The platform returned the cursor "${next}" twice; stopped after ${analyses.length} analyses.`);
|
|
9297
|
+
}
|
|
9298
|
+
seen.add(next);
|
|
9299
|
+
cursor = next;
|
|
9300
|
+
}
|
|
9301
|
+
}
|
|
9302
|
+
async function listPublicAnalyses(options, cmd) {
|
|
9303
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
9304
|
+
const limit = parseLimit(options.limit);
|
|
9305
|
+
const changedSince = options.changedSince === void 0 ? void 0 : parseChangedSince(options.changedSince);
|
|
9306
|
+
const api = createApiClient();
|
|
9307
|
+
const listing = await readPublicAnalyses(api.analysis, {
|
|
9308
|
+
limit,
|
|
9309
|
+
cursor: options.cursor,
|
|
9310
|
+
all: options.all,
|
|
9311
|
+
changedSince
|
|
9312
|
+
});
|
|
9313
|
+
if (outputFormat === "json") {
|
|
9314
|
+
format(listing, { format: outputFormat });
|
|
9315
|
+
return;
|
|
9316
|
+
}
|
|
9317
|
+
if (listing.analyses.length === 0 && outputFormat === "human") {
|
|
9318
|
+
empty("public analyses");
|
|
9319
|
+
} else {
|
|
9320
|
+
format(listing.analyses, {
|
|
9321
|
+
format: outputFormat,
|
|
9322
|
+
columns: [
|
|
9323
|
+
{ key: "analysisId", kind: "id" },
|
|
9324
|
+
{ key: "projectId", kind: "id" },
|
|
9325
|
+
{ key: "publishedAt", header: "published", kind: "date" },
|
|
9326
|
+
{ key: "changedAt", header: "changed", kind: "date" }
|
|
9327
|
+
]
|
|
9328
|
+
});
|
|
9329
|
+
}
|
|
9330
|
+
if (listing.nextCursor !== null) {
|
|
9331
|
+
hint(`More public analyses follow. Continue with --cursor ${listing.nextCursor}, or pass --all.`);
|
|
9332
|
+
}
|
|
9333
|
+
}
|
|
9334
|
+
function newestRunRecord(run) {
|
|
9335
|
+
return {
|
|
9336
|
+
runId: run.runId,
|
|
9337
|
+
state: run.state,
|
|
9338
|
+
phase: runPhaseCell(run),
|
|
9339
|
+
submittedAt: run.submittedAt,
|
|
9340
|
+
startedAt: run.startedAt,
|
|
9341
|
+
endedAt: run.endedAt
|
|
9342
|
+
};
|
|
9343
|
+
}
|
|
9344
|
+
async function showPublicAnalysis(analysisId, cmd) {
|
|
9345
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
9346
|
+
const api = createApiClient();
|
|
9347
|
+
const result = await api.analysis.get(analysisId);
|
|
9348
|
+
if (!result?.analysis) {
|
|
9349
|
+
throw new CliError(`No public analysis "${analysisId}".`, {
|
|
9350
|
+
hint: `List the public analyses with 'diafunc public list'.`
|
|
9351
|
+
});
|
|
9352
|
+
}
|
|
9353
|
+
const runs = await api.analysis.getRunsForAnalysis(analysisId, 1);
|
|
9354
|
+
const newestRun = runs?.[0] ?? null;
|
|
9355
|
+
if (outputFormat === "json") {
|
|
9356
|
+
format({ analysis: result.analysis, newestRun }, { format: outputFormat });
|
|
9357
|
+
return;
|
|
9358
|
+
}
|
|
9359
|
+
if (outputFormat === "table") {
|
|
9360
|
+
format({
|
|
9361
|
+
...result.analysis,
|
|
9362
|
+
newestRunId: newestRun?.runId ?? null,
|
|
9363
|
+
newestRunState: newestRun?.state ?? null,
|
|
9364
|
+
newestRunSubmittedAt: newestRun?.submittedAt ?? null,
|
|
9365
|
+
newestRunStartedAt: newestRun?.startedAt ?? null,
|
|
9366
|
+
newestRunEndedAt: newestRun?.endedAt ?? null
|
|
9367
|
+
}, { format: outputFormat });
|
|
9368
|
+
return;
|
|
9369
|
+
}
|
|
9370
|
+
const details = analysisDetails(result.analysis, resolveEndpoint(loadConfig()));
|
|
9371
|
+
format(details.data, { format: outputFormat, columns: details.columns });
|
|
9372
|
+
heading("Newest run");
|
|
9373
|
+
if (!newestRun) {
|
|
9374
|
+
empty("runs");
|
|
9375
|
+
return;
|
|
9376
|
+
}
|
|
9377
|
+
format(newestRunRecord(newestRun), {
|
|
9378
|
+
format: outputFormat,
|
|
9379
|
+
columns: [
|
|
9380
|
+
{ key: "runId", header: "Run ID", kind: "id" },
|
|
9381
|
+
{ key: "state", header: "State", kind: "state" },
|
|
9382
|
+
{ key: "phase", header: "Phase" },
|
|
9383
|
+
{ key: "submittedAt", header: "Submitted", kind: "date" },
|
|
9384
|
+
{ key: "startedAt", header: "Started", kind: "date" },
|
|
9385
|
+
{ key: "endedAt", header: "Ended", kind: "date" }
|
|
9386
|
+
]
|
|
9387
|
+
});
|
|
9388
|
+
}
|
|
9389
|
+
function registerPublicCommands(program) {
|
|
9390
|
+
const pub = program.command("public").description("Read the analyses their owners made public (no sign-in needed)").addHelpText("after", `
|
|
9391
|
+
Examples:
|
|
9392
|
+
$ diafunc public list the first 100 public analyses
|
|
9393
|
+
$ diafunc public list --all --output json every one of them, for a script
|
|
9394
|
+
$ diafunc public list --all --changed-since 2026-10-01 only those changed since that day
|
|
9395
|
+
$ diafunc public show <analysisId> one analysis and its newest run
|
|
9396
|
+
`);
|
|
9397
|
+
pub.command("list").description("List public analyses").option("--limit <n>", `Analyses per page (${MIN_LIMIT} to ${MAX_LIMIT})`, "100").option("--cursor <c>", "Continue from the cursor an earlier call ended with").option("--all", "Follow the pages to the end of the listing").option("--changed-since <ISO-8601>", "Only analyses changed at or after this date or instant").action(async (options, cmd) => {
|
|
9398
|
+
try {
|
|
9399
|
+
await listPublicAnalyses(options, cmd);
|
|
9400
|
+
} catch (error) {
|
|
9401
|
+
handleError(error);
|
|
9402
|
+
}
|
|
9403
|
+
});
|
|
9404
|
+
pub.command("show").description("Show a public analysis and its newest run").argument("<analysisId>", "Analysis ID").action(async (analysisId, _options, cmd) => {
|
|
9405
|
+
try {
|
|
9406
|
+
await showPublicAnalysis(analysisId, cmd);
|
|
9407
|
+
} catch (error) {
|
|
9408
|
+
handleError(error);
|
|
9409
|
+
}
|
|
9410
|
+
});
|
|
9411
|
+
}
|
|
9412
|
+
|
|
9413
|
+
// src/commands/data-sources/index.ts
|
|
9414
|
+
import chalk27 from "chalk";
|
|
9415
|
+
function getOutputFormat17(cmd) {
|
|
9416
|
+
const config = loadConfig();
|
|
9417
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
9418
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
9419
|
+
}
|
|
8688
9420
|
function parseConfigPairs(pairs) {
|
|
8689
9421
|
const out = {};
|
|
8690
9422
|
if (!pairs) return out;
|
|
@@ -8780,7 +9512,7 @@ function resolveProjectId(cmd) {
|
|
|
8780
9512
|
return resolved;
|
|
8781
9513
|
}
|
|
8782
9514
|
async function listDataSources(projectId, cmd) {
|
|
8783
|
-
const outputFormat =
|
|
9515
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8784
9516
|
const api = createApiClient();
|
|
8785
9517
|
const sources = await api.storage.listDataSources(projectId);
|
|
8786
9518
|
if (outputFormat === "human" && sources.length === 0) {
|
|
@@ -8801,13 +9533,13 @@ async function listDataSources(projectId, cmd) {
|
|
|
8801
9533
|
});
|
|
8802
9534
|
}
|
|
8803
9535
|
async function getDataSource(id, cmd) {
|
|
8804
|
-
const outputFormat =
|
|
9536
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8805
9537
|
const api = createApiClient();
|
|
8806
9538
|
const ds = await api.storage.getDataSource(id);
|
|
8807
9539
|
format(ds, { format: outputFormat });
|
|
8808
9540
|
}
|
|
8809
9541
|
async function showDashboard(projectId, cmd) {
|
|
8810
|
-
const outputFormat =
|
|
9542
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8811
9543
|
const api = createApiClient();
|
|
8812
9544
|
const dashboard = await api.storage.getDataSourceDashboard(projectId);
|
|
8813
9545
|
if (outputFormat !== "human") {
|
|
@@ -8815,7 +9547,7 @@ async function showDashboard(projectId, cmd) {
|
|
|
8815
9547
|
return;
|
|
8816
9548
|
}
|
|
8817
9549
|
const r = dashboard.rollup;
|
|
8818
|
-
let line =
|
|
9550
|
+
let line = chalk27.bold(`DataSources in ${projectId}: `) + `${r.totalSources} total, ${r.scheduledSources} scheduled, ${r.sourcesWithRecentFailure} failing recently`;
|
|
8819
9551
|
if (r.lastActivityAt) line += `, last activity ${r.lastActivityAt}`;
|
|
8820
9552
|
console.log(line);
|
|
8821
9553
|
if (dashboard.sources.length === 0) {
|
|
@@ -8838,7 +9570,7 @@ async function showDashboard(projectId, cmd) {
|
|
|
8838
9570
|
});
|
|
8839
9571
|
}
|
|
8840
9572
|
async function createDataSource(options, cmd) {
|
|
8841
|
-
const outputFormat =
|
|
9573
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8842
9574
|
const api = createApiClient();
|
|
8843
9575
|
const request = {
|
|
8844
9576
|
projectId: options.projectId,
|
|
@@ -8853,14 +9585,14 @@ async function createDataSource(options, cmd) {
|
|
|
8853
9585
|
const ds = await api.storage.createDataSource(request);
|
|
8854
9586
|
if (outputFormat === "human") {
|
|
8855
9587
|
success(`Created data source ${ds.id}`);
|
|
8856
|
-
console.log(
|
|
8857
|
-
if (ds.lastRunError) console.log(
|
|
9588
|
+
console.log(chalk27.dim(` Last run: ${ds.lastRunStatus ?? "\u2014"}`));
|
|
9589
|
+
if (ds.lastRunError) console.log(chalk27.dim(` Error: ${ds.lastRunError}`));
|
|
8858
9590
|
} else {
|
|
8859
9591
|
format(ds, { format: outputFormat });
|
|
8860
9592
|
}
|
|
8861
9593
|
}
|
|
8862
9594
|
async function updateDataSource(id, options, cmd) {
|
|
8863
|
-
const outputFormat =
|
|
9595
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8864
9596
|
if (options.name === void 0 && options.type === void 0 && (!options.config || options.config.length === 0) && options.scheduleCron === void 0 && !options.clearSchedule) {
|
|
8865
9597
|
throw new Error("Provide at least one of --name, --type, --config, --schedule-cron, or --clear-schedule.");
|
|
8866
9598
|
}
|
|
@@ -8895,18 +9627,18 @@ async function deleteDataSource(id) {
|
|
|
8895
9627
|
success(`Deleted data source ${id}`);
|
|
8896
9628
|
}
|
|
8897
9629
|
async function refreshDataSource(id, cmd) {
|
|
8898
|
-
const outputFormat =
|
|
9630
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8899
9631
|
const api = createApiClient();
|
|
8900
9632
|
const run = await api.storage.refreshDataSource(id);
|
|
8901
9633
|
if (outputFormat === "human") {
|
|
8902
9634
|
success(`Refresh queued: run ${run.runId}, status ${run.status}.`);
|
|
8903
|
-
if (run.errorMessage) console.log(
|
|
9635
|
+
if (run.errorMessage) console.log(chalk27.red(` Error: ${run.errorMessage}`));
|
|
8904
9636
|
} else {
|
|
8905
9637
|
format(run, { format: outputFormat });
|
|
8906
9638
|
}
|
|
8907
9639
|
}
|
|
8908
9640
|
async function listRuns2(id, limit, cmd) {
|
|
8909
|
-
const outputFormat =
|
|
9641
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8910
9642
|
const api = createApiClient();
|
|
8911
9643
|
const runs = await api.storage.listDataSourceRuns(id, limit);
|
|
8912
9644
|
if (outputFormat === "human" && runs.length === 0) {
|
|
@@ -8928,13 +9660,13 @@ async function listRuns2(id, limit, cmd) {
|
|
|
8928
9660
|
});
|
|
8929
9661
|
}
|
|
8930
9662
|
async function getRun(id, runId, cmd) {
|
|
8931
|
-
const outputFormat =
|
|
9663
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8932
9664
|
const api = createApiClient();
|
|
8933
9665
|
const run = await api.storage.getDataSourceRun(id, runId);
|
|
8934
9666
|
format(run, { format: outputFormat });
|
|
8935
9667
|
}
|
|
8936
9668
|
async function listConnectorTypes(cmd) {
|
|
8937
|
-
const outputFormat =
|
|
9669
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8938
9670
|
const api = createApiClient();
|
|
8939
9671
|
const types = await api.storage.listDataSourceConnectorTypes();
|
|
8940
9672
|
if (outputFormat === "human") {
|
|
@@ -9027,8 +9759,8 @@ Examples:
|
|
|
9027
9759
|
}
|
|
9028
9760
|
|
|
9029
9761
|
// src/commands/table-exporters/index.ts
|
|
9030
|
-
import
|
|
9031
|
-
function
|
|
9762
|
+
import chalk28 from "chalk";
|
|
9763
|
+
function getOutputFormat18(cmd) {
|
|
9032
9764
|
const config = loadConfig();
|
|
9033
9765
|
const globalOpts = cmd.optsWithGlobals();
|
|
9034
9766
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9037,7 +9769,7 @@ function registerTableExportersCommands(program) {
|
|
|
9037
9769
|
const exporters = program.command("table-exporters").description("Manage user-defined exporters (UDE); admin only");
|
|
9038
9770
|
exporters.command("list").description("List all registered user-defined exporters").action(async (_options, cmd) => {
|
|
9039
9771
|
try {
|
|
9040
|
-
const outputFormat =
|
|
9772
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
9041
9773
|
const api = createApiClient();
|
|
9042
9774
|
const list = await api.storage.listUserDefinedExporters();
|
|
9043
9775
|
if (outputFormat === "json") {
|
|
@@ -9058,14 +9790,14 @@ function registerTableExportersCommands(program) {
|
|
|
9058
9790
|
format: outputFormat,
|
|
9059
9791
|
columns: ["id", "name", "format", "extension", "mimeType", "priority", "function", "createdBy"]
|
|
9060
9792
|
});
|
|
9061
|
-
console.log(
|
|
9793
|
+
console.log(chalk28.dim(`${list.length} exporter(s)`));
|
|
9062
9794
|
} catch (error) {
|
|
9063
9795
|
handleError(error);
|
|
9064
9796
|
}
|
|
9065
9797
|
});
|
|
9066
9798
|
exporters.command("get").description("Show a single user-defined exporter by id").argument("<id>", "Exporter id").action(async (id, _options, cmd) => {
|
|
9067
9799
|
try {
|
|
9068
|
-
const outputFormat =
|
|
9800
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
9069
9801
|
const api = createApiClient();
|
|
9070
9802
|
const list = await api.storage.listUserDefinedExporters();
|
|
9071
9803
|
const exporter = list.find((e) => e.id === id);
|
|
@@ -9080,7 +9812,7 @@ function registerTableExportersCommands(program) {
|
|
|
9080
9812
|
});
|
|
9081
9813
|
exporters.command("create").description("Register a new user-defined exporter").requiredOption("--name <name>", 'Display name (e.g. "Acme machine instrument export")').requiredOption("--format <token>", 'Format token used in the dispatch URL (e.g. "acme")').requiredOption("--function-project <id>", "Function entity's project id").requiredOption("--function-entity <id>", "Function entity id").option("--description <text>", "Free-form description").option("--extension <ext>", 'Filename extension (must start with ".")').option("--mime-type <mime>", "MIME type the function produces").option("--function-project-branch <branch>", "Function project branch", "main").option("--function-entity-branch <branch>", "Function entity branch", "main").option("--priority <n>", "Dispatch priority (default 50; > 200 overrides built-ins)", "50").action(async (options, cmd) => {
|
|
9082
9814
|
try {
|
|
9083
|
-
const outputFormat =
|
|
9815
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
9084
9816
|
const api = createApiClient();
|
|
9085
9817
|
const payload = {
|
|
9086
9818
|
name: options.name,
|
|
@@ -9116,9 +9848,9 @@ function registerTableExportersCommands(program) {
|
|
|
9116
9848
|
}
|
|
9117
9849
|
|
|
9118
9850
|
// src/commands/skeleton/index.ts
|
|
9119
|
-
import
|
|
9851
|
+
import chalk29 from "chalk";
|
|
9120
9852
|
import * as fs10 from "fs";
|
|
9121
|
-
function
|
|
9853
|
+
function getOutputFormat19(cmd) {
|
|
9122
9854
|
const config = loadConfig();
|
|
9123
9855
|
const globalOpts = cmd.optsWithGlobals();
|
|
9124
9856
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9167,7 +9899,7 @@ function skeletonTableRow(s) {
|
|
|
9167
9899
|
};
|
|
9168
9900
|
}
|
|
9169
9901
|
async function createSkeleton(options, cmd) {
|
|
9170
|
-
const outputFormat =
|
|
9902
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9171
9903
|
const projectId = resolveProjectId2(cmd);
|
|
9172
9904
|
const template = resolveTemplate(options.template);
|
|
9173
9905
|
const weight = parseWeight(options.weight);
|
|
@@ -9183,16 +9915,16 @@ async function createSkeleton(options, cmd) {
|
|
|
9183
9915
|
const skeleton = await api.storage.createSkeleton(request);
|
|
9184
9916
|
if (outputFormat === "human") {
|
|
9185
9917
|
success(`Created skeleton ${skeleton.id}`);
|
|
9186
|
-
console.log(
|
|
9187
|
-
console.log(
|
|
9188
|
-
console.log(
|
|
9189
|
-
console.log(
|
|
9918
|
+
console.log(chalk29.dim(` name: ${skeleton.name}`));
|
|
9919
|
+
console.log(chalk29.dim(` template: ${skeleton.template}`));
|
|
9920
|
+
console.log(chalk29.dim(` paramCount: ${skeleton.paramCount}`));
|
|
9921
|
+
console.log(chalk29.dim(` weight: ${skeleton.weight}`));
|
|
9190
9922
|
} else {
|
|
9191
9923
|
format(skeleton, { format: outputFormat });
|
|
9192
9924
|
}
|
|
9193
9925
|
}
|
|
9194
9926
|
async function listSkeletons(cmd) {
|
|
9195
|
-
const outputFormat =
|
|
9927
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9196
9928
|
const projectId = resolveProjectId2(cmd);
|
|
9197
9929
|
const api = createApiClient();
|
|
9198
9930
|
const skeletons = await api.storage.listSkeletons(projectId);
|
|
@@ -9206,13 +9938,13 @@ async function listSkeletons(cmd) {
|
|
|
9206
9938
|
});
|
|
9207
9939
|
}
|
|
9208
9940
|
async function getSkeleton(id, cmd) {
|
|
9209
|
-
const outputFormat =
|
|
9941
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9210
9942
|
const api = createApiClient();
|
|
9211
9943
|
const skeleton = await api.storage.getSkeleton(id);
|
|
9212
9944
|
format(skeleton, { format: outputFormat });
|
|
9213
9945
|
}
|
|
9214
9946
|
async function updateSkeleton(id, options, cmd) {
|
|
9215
|
-
const outputFormat =
|
|
9947
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9216
9948
|
if (options.name === void 0 && options.template === void 0 && options.weight === void 0) {
|
|
9217
9949
|
throw new Error("Provide at least one of --name, --template, --weight.");
|
|
9218
9950
|
}
|
|
@@ -9225,10 +9957,10 @@ async function updateSkeleton(id, options, cmd) {
|
|
|
9225
9957
|
const skeleton = await api.storage.updateSkeleton(id, request);
|
|
9226
9958
|
if (outputFormat === "human") {
|
|
9227
9959
|
success(`Updated skeleton ${skeleton.id}`);
|
|
9228
|
-
console.log(
|
|
9229
|
-
console.log(
|
|
9230
|
-
console.log(
|
|
9231
|
-
console.log(
|
|
9960
|
+
console.log(chalk29.dim(` name: ${skeleton.name}`));
|
|
9961
|
+
console.log(chalk29.dim(` template: ${skeleton.template}`));
|
|
9962
|
+
console.log(chalk29.dim(` paramCount: ${skeleton.paramCount}`));
|
|
9963
|
+
console.log(chalk29.dim(` weight: ${skeleton.weight}`));
|
|
9232
9964
|
} else {
|
|
9233
9965
|
format(skeleton, { format: outputFormat });
|
|
9234
9966
|
}
|
|
@@ -9548,7 +10280,7 @@ function registerCompletionCommand(program) {
|
|
|
9548
10280
|
}
|
|
9549
10281
|
|
|
9550
10282
|
// src/commands/whoami/index.ts
|
|
9551
|
-
import
|
|
10283
|
+
import chalk30 from "chalk";
|
|
9552
10284
|
function registerWhoamiCommand(program) {
|
|
9553
10285
|
program.command("whoami").description("Show the currently authenticated user").action(async (_options, cmd) => {
|
|
9554
10286
|
try {
|
|
@@ -9558,8 +10290,8 @@ function registerWhoamiCommand(program) {
|
|
|
9558
10290
|
const api = createApiClient();
|
|
9559
10291
|
const user = await api.admin.getMyUser();
|
|
9560
10292
|
if (outputFormat === "human") {
|
|
9561
|
-
console.log(
|
|
9562
|
-
console.log(
|
|
10293
|
+
console.log(chalk30.bold(user.name) + chalk30.dim(` <${user.email}>`));
|
|
10294
|
+
console.log(chalk30.dim(` Role: ${user.role} \xB7 Remaining credits: ${user.remainingCredits} \xB7 Profile: ${config.currentProfile}`));
|
|
9563
10295
|
} else {
|
|
9564
10296
|
format(user, { format: outputFormat });
|
|
9565
10297
|
}
|
|
@@ -9570,8 +10302,8 @@ function registerWhoamiCommand(program) {
|
|
|
9570
10302
|
}
|
|
9571
10303
|
|
|
9572
10304
|
// src/commands/utilization/index.ts
|
|
9573
|
-
import
|
|
9574
|
-
function
|
|
10305
|
+
import chalk31 from "chalk";
|
|
10306
|
+
function getOutputFormat20(cmd) {
|
|
9575
10307
|
const config = loadConfig();
|
|
9576
10308
|
const globalOpts = cmd.optsWithGlobals();
|
|
9577
10309
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9587,19 +10319,19 @@ function windowLabel(u) {
|
|
|
9587
10319
|
}
|
|
9588
10320
|
function printUtilizationHuman(u, label) {
|
|
9589
10321
|
const when2 = windowLabel(u);
|
|
9590
|
-
console.log(label ?
|
|
10322
|
+
console.log(label ? chalk31.bold(label) + " " + chalk31.dim(when2) : chalk31.bold(when2));
|
|
9591
10323
|
if (u.types.length === 0) {
|
|
9592
|
-
console.log(
|
|
10324
|
+
console.log(chalk31.dim(" (no usage)"));
|
|
9593
10325
|
return;
|
|
9594
10326
|
}
|
|
9595
10327
|
const types = [...u.types].sort((a, b) => b.credits - a.credits);
|
|
9596
10328
|
const width = Math.max(...types.map((t) => t.type.length));
|
|
9597
10329
|
for (const t of types) {
|
|
9598
|
-
const line = ` ${t.type.padEnd(width)} ${formatNumber(t.quantity).padStart(12)} ${
|
|
9599
|
-
console.log(t.credits === 0 ?
|
|
10330
|
+
const line = ` ${t.type.padEnd(width)} ${formatNumber(t.quantity).padStart(12)} ${chalk31.dim("credits")} ${t.credits.toFixed(2).padStart(10)}`;
|
|
10331
|
+
console.log(t.credits === 0 ? chalk31.dim(line) : line);
|
|
9600
10332
|
}
|
|
9601
10333
|
const total = u.totalCredits ?? u.types.reduce((s, t) => s + t.credits, 0);
|
|
9602
|
-
console.log(
|
|
10334
|
+
console.log(chalk31.bold(` ${"Total".padEnd(width)} ${" ".repeat(12)} ${chalk31.dim("credits")} ${total.toFixed(2).padStart(10)}`));
|
|
9603
10335
|
}
|
|
9604
10336
|
function formatDailyHistory(history) {
|
|
9605
10337
|
const spentOn = (u) => u.dailyCredits ?? u.types.reduce((sum, t) => sum + (t.dailyCredits ?? 0), 0);
|
|
@@ -9616,14 +10348,14 @@ function formatDailyHistory(history) {
|
|
|
9616
10348
|
for (const u of history) {
|
|
9617
10349
|
const spent = spentOn(u);
|
|
9618
10350
|
total += spent;
|
|
9619
|
-
const line = `${windowLabel(u).padEnd(width)} ${amount(spent)} ${
|
|
9620
|
-
lines.push(spent > 0 ?
|
|
10351
|
+
const line = `${windowLabel(u).padEnd(width)} ${amount(spent)} ${chalk31.dim("credits")}`;
|
|
10352
|
+
lines.push(spent > 0 ? chalk31.bold(line) : chalk31.dim(line));
|
|
9621
10353
|
for (const t of costly(u)) {
|
|
9622
10354
|
lines.push(` ${t.type.padEnd(width - 2)} ${amount(t.dailyCredits ?? 0)}`);
|
|
9623
10355
|
}
|
|
9624
10356
|
}
|
|
9625
10357
|
lines.push("");
|
|
9626
|
-
lines.push(
|
|
10358
|
+
lines.push(chalk31.bold(`${totalLabel.padEnd(width)} ${amount(total)} ${chalk31.dim("credits")}`));
|
|
9627
10359
|
return lines;
|
|
9628
10360
|
}
|
|
9629
10361
|
function registerUtilizationCommand(program) {
|
|
@@ -9636,7 +10368,7 @@ Examples:
|
|
|
9636
10368
|
`);
|
|
9637
10369
|
util.command("actual", { isDefault: true }).description("Show current utilization (default subcommand)").action(async (_options, cmd) => {
|
|
9638
10370
|
try {
|
|
9639
|
-
const outputFormat =
|
|
10371
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9640
10372
|
const api = createApiClient();
|
|
9641
10373
|
const utilization = await api.admin.getActualUtilization();
|
|
9642
10374
|
if (outputFormat === "human") {
|
|
@@ -9650,7 +10382,7 @@ Examples:
|
|
|
9650
10382
|
});
|
|
9651
10383
|
util.command("history").description("Show what each day of the billing cycle cost").action(async (_options, cmd) => {
|
|
9652
10384
|
try {
|
|
9653
|
-
const outputFormat =
|
|
10385
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9654
10386
|
const api = createApiClient();
|
|
9655
10387
|
const history = await api.admin.getUtilizationHistory();
|
|
9656
10388
|
if (outputFormat === "human") {
|
|
@@ -9671,7 +10403,7 @@ Examples:
|
|
|
9671
10403
|
}
|
|
9672
10404
|
|
|
9673
10405
|
// src/commands/entity-branch/index.ts
|
|
9674
|
-
function
|
|
10406
|
+
function getOutputFormat21(cmd) {
|
|
9675
10407
|
const config = loadConfig();
|
|
9676
10408
|
const globalOpts = cmd.optsWithGlobals();
|
|
9677
10409
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9684,7 +10416,7 @@ function registerEntityBranchCommands(program) {
|
|
|
9684
10416
|
const eb = program.command("entity-branch").description("Manage entity branches (parallel versions of a single entity)");
|
|
9685
10417
|
eb.command("list").description("List branches of an entity").argument("<ref>", "Entity reference (projectId/branch/entityId)").action(async (ref, _options, cmd) => {
|
|
9686
10418
|
try {
|
|
9687
|
-
const outputFormat =
|
|
10419
|
+
const outputFormat = getOutputFormat21(cmd);
|
|
9688
10420
|
const overrides = getOverrides11(cmd);
|
|
9689
10421
|
const resolved = parseEntityReference(ref, overrides);
|
|
9690
10422
|
const api = createApiClient();
|
|
@@ -9736,7 +10468,7 @@ function forReader(subscription) {
|
|
|
9736
10468
|
Object.entries(subscription).filter(([key]) => !BILLING_INTERNALS.has(key))
|
|
9737
10469
|
);
|
|
9738
10470
|
}
|
|
9739
|
-
function
|
|
10471
|
+
function getOutputFormat22(cmd) {
|
|
9740
10472
|
const config = loadConfig();
|
|
9741
10473
|
const globalOpts = cmd.optsWithGlobals();
|
|
9742
10474
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9750,7 +10482,7 @@ Examples:
|
|
|
9750
10482
|
sub.command("current", { isDefault: true }).description("Show the current subscription").action(async (_options, cmd) => {
|
|
9751
10483
|
try {
|
|
9752
10484
|
const api = createApiClient();
|
|
9753
|
-
const outputFormat =
|
|
10485
|
+
const outputFormat = getOutputFormat22(cmd);
|
|
9754
10486
|
const s = await api.admin.getCurrentSubscription();
|
|
9755
10487
|
format(outputFormat === "human" ? forReader(s) : s, { format: outputFormat });
|
|
9756
10488
|
} catch (error) {
|
|
@@ -9760,7 +10492,7 @@ Examples:
|
|
|
9760
10492
|
sub.command("next").description("Show the next (upcoming) subscription").action(async (_options, cmd) => {
|
|
9761
10493
|
try {
|
|
9762
10494
|
const api = createApiClient();
|
|
9763
|
-
const outputFormat =
|
|
10495
|
+
const outputFormat = getOutputFormat22(cmd);
|
|
9764
10496
|
const s = await api.admin.getNextSubscription();
|
|
9765
10497
|
format(outputFormat === "human" ? forReader(s) : s, { format: outputFormat });
|
|
9766
10498
|
} catch (error) {
|
|
@@ -9771,7 +10503,7 @@ Examples:
|
|
|
9771
10503
|
try {
|
|
9772
10504
|
const api = createApiClient();
|
|
9773
10505
|
const plans = await api.admin.getSubscriptionPlans(subscriptionToken);
|
|
9774
|
-
format(plans, { format:
|
|
10506
|
+
format(plans, { format: getOutputFormat22(cmd) });
|
|
9775
10507
|
} catch (error) {
|
|
9776
10508
|
handleError(error);
|
|
9777
10509
|
}
|
|
@@ -9780,7 +10512,7 @@ Examples:
|
|
|
9780
10512
|
|
|
9781
10513
|
// src/commands/invoice/index.ts
|
|
9782
10514
|
import * as fs11 from "fs";
|
|
9783
|
-
function
|
|
10515
|
+
function getOutputFormat23(cmd) {
|
|
9784
10516
|
const config = loadConfig();
|
|
9785
10517
|
const globalOpts = cmd.optsWithGlobals();
|
|
9786
10518
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9797,7 +10529,7 @@ Examples:
|
|
|
9797
10529
|
const api = createApiClient();
|
|
9798
10530
|
const invoices = await api.admin.getInvoices();
|
|
9799
10531
|
format(invoices, {
|
|
9800
|
-
format:
|
|
10532
|
+
format: getOutputFormat23(cmd),
|
|
9801
10533
|
columns: [
|
|
9802
10534
|
{ key: "invoiceNumber", header: "number" },
|
|
9803
10535
|
{ key: "issued", kind: "date" },
|
|
@@ -9826,7 +10558,7 @@ Examples:
|
|
|
9826
10558
|
}
|
|
9827
10559
|
|
|
9828
10560
|
// src/commands/shell/index.ts
|
|
9829
|
-
import
|
|
10561
|
+
import chalk32 from "chalk";
|
|
9830
10562
|
import * as fs12 from "fs";
|
|
9831
10563
|
import * as os3 from "os";
|
|
9832
10564
|
import * as path9 from "path";
|
|
@@ -9892,21 +10624,21 @@ async function evaluate(api, fnRef, language, sourceCode) {
|
|
|
9892
10624
|
}, false);
|
|
9893
10625
|
if (result.outputs?.length) {
|
|
9894
10626
|
for (const out of result.outputs) {
|
|
9895
|
-
console.log(
|
|
10627
|
+
console.log(chalk32.dim(` [${out.type}]`) + " " + out.output);
|
|
9896
10628
|
}
|
|
9897
10629
|
}
|
|
9898
10630
|
if (result.successful) {
|
|
9899
10631
|
if (result.result) {
|
|
9900
|
-
console.log(
|
|
10632
|
+
console.log(chalk32.green("=>") + " " + result.result);
|
|
9901
10633
|
} else {
|
|
9902
|
-
console.log(
|
|
10634
|
+
console.log(chalk32.dim("=> (no value)"));
|
|
9903
10635
|
}
|
|
9904
10636
|
const duration = result.completed - result.started;
|
|
9905
|
-
console.log(
|
|
10637
|
+
console.log(chalk32.dim(` [${duration}ms \xB7 ${evaluationId}]`));
|
|
9906
10638
|
} else {
|
|
9907
|
-
console.log(
|
|
10639
|
+
console.log(chalk32.red("error: ") + result.error);
|
|
9908
10640
|
if (result.lineNumber > 0) {
|
|
9909
|
-
console.log(
|
|
10641
|
+
console.log(chalk32.dim(` at line ${result.lineNumber}, col ${result.columnNumber}`));
|
|
9910
10642
|
}
|
|
9911
10643
|
}
|
|
9912
10644
|
}
|
|
@@ -9927,19 +10659,19 @@ function registerShellCommand(program) {
|
|
|
9927
10659
|
});
|
|
9928
10660
|
const api = createApiClient();
|
|
9929
10661
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
9930
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
10662
|
+
const { getUpdateNotice } = await import("./update-check-7F4ABBDC.js");
|
|
9931
10663
|
const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
|
|
9932
|
-
console.log(
|
|
9933
|
-
console.log(
|
|
9934
|
-
console.log(
|
|
10664
|
+
console.log(chalk32.bold("Diafunc shell") + chalk32.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
|
|
10665
|
+
console.log(chalk32.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
10666
|
+
console.log(chalk32.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
|
|
9935
10667
|
const notice = await getUpdateNotice();
|
|
9936
|
-
if (notice) console.log(
|
|
10668
|
+
if (notice) console.log(chalk32.dim(notice));
|
|
9937
10669
|
console.log();
|
|
9938
10670
|
let language = resolvedLanguage;
|
|
9939
10671
|
for (; ; ) {
|
|
9940
10672
|
let line;
|
|
9941
10673
|
try {
|
|
9942
|
-
line = await promptInput({ message:
|
|
10674
|
+
line = await promptInput({ message: chalk32.cyan.bold(`${language} >`) });
|
|
9943
10675
|
} catch {
|
|
9944
10676
|
console.log();
|
|
9945
10677
|
return;
|
|
@@ -9957,54 +10689,54 @@ function registerShellCommand(program) {
|
|
|
9957
10689
|
case "help":
|
|
9958
10690
|
case "h":
|
|
9959
10691
|
case "?":
|
|
9960
|
-
console.log(
|
|
9961
|
-
console.log(
|
|
9962
|
-
console.log(
|
|
9963
|
-
console.log(
|
|
10692
|
+
console.log(chalk32.dim(" /edit open $EDITOR for multi-line code"));
|
|
10693
|
+
console.log(chalk32.dim(" /file <path> evaluate the contents of a file"));
|
|
10694
|
+
console.log(chalk32.dim(" /lang <name> switch language (Java, JavaScript, Kotlin, Python, Scala)"));
|
|
10695
|
+
console.log(chalk32.dim(" /quit exit the shell"));
|
|
9964
10696
|
continue;
|
|
9965
10697
|
case "lang":
|
|
9966
10698
|
if (arg) language = arg;
|
|
9967
|
-
console.log(
|
|
10699
|
+
console.log(chalk32.dim(`Language: ${language}`));
|
|
9968
10700
|
continue;
|
|
9969
10701
|
case "edit": {
|
|
9970
10702
|
const sourceCode = await openInEditor("", extensionFor2(language));
|
|
9971
10703
|
if (!sourceCode.trim()) {
|
|
9972
|
-
console.log(
|
|
10704
|
+
console.log(chalk32.dim("(empty; not evaluated)"));
|
|
9973
10705
|
continue;
|
|
9974
10706
|
}
|
|
9975
10707
|
try {
|
|
9976
10708
|
await evaluate(api, fnRef, language, sourceCode);
|
|
9977
10709
|
} catch (e) {
|
|
9978
|
-
console.error(
|
|
10710
|
+
console.error(chalk32.red(e.message));
|
|
9979
10711
|
}
|
|
9980
10712
|
continue;
|
|
9981
10713
|
}
|
|
9982
10714
|
case "file": {
|
|
9983
10715
|
if (!arg) {
|
|
9984
|
-
console.log(
|
|
10716
|
+
console.log(chalk32.dim("usage: /file <path>"));
|
|
9985
10717
|
continue;
|
|
9986
10718
|
}
|
|
9987
10719
|
if (!fs12.existsSync(arg)) {
|
|
9988
|
-
console.log(
|
|
10720
|
+
console.log(chalk32.red(`file not found: ${arg}`));
|
|
9989
10721
|
continue;
|
|
9990
10722
|
}
|
|
9991
10723
|
const sourceCode = fs12.readFileSync(arg, "utf-8");
|
|
9992
10724
|
try {
|
|
9993
10725
|
await evaluate(api, fnRef, language, sourceCode);
|
|
9994
10726
|
} catch (e) {
|
|
9995
|
-
console.error(
|
|
10727
|
+
console.error(chalk32.red(e.message));
|
|
9996
10728
|
}
|
|
9997
10729
|
continue;
|
|
9998
10730
|
}
|
|
9999
10731
|
default:
|
|
10000
|
-
console.log(
|
|
10732
|
+
console.log(chalk32.dim(`Unknown command: /${cmd2}. Try /help.`));
|
|
10001
10733
|
continue;
|
|
10002
10734
|
}
|
|
10003
10735
|
}
|
|
10004
10736
|
try {
|
|
10005
10737
|
await evaluate(api, fnRef, language, trimmed);
|
|
10006
10738
|
} catch (e) {
|
|
10007
|
-
console.error(
|
|
10739
|
+
console.error(chalk32.red(e.message));
|
|
10008
10740
|
}
|
|
10009
10741
|
}
|
|
10010
10742
|
} catch (error) {
|
|
@@ -10014,7 +10746,7 @@ function registerShellCommand(program) {
|
|
|
10014
10746
|
}
|
|
10015
10747
|
|
|
10016
10748
|
// src/commands/update/index.ts
|
|
10017
|
-
import
|
|
10749
|
+
import chalk33 from "chalk";
|
|
10018
10750
|
import * as path10 from "path";
|
|
10019
10751
|
import { spawn as spawn4 } from "child_process";
|
|
10020
10752
|
|
|
@@ -10060,14 +10792,14 @@ function registerUpdateCommand(program) {
|
|
|
10060
10792
|
const install = detectInstall();
|
|
10061
10793
|
const latest = await fetchLatestVersion();
|
|
10062
10794
|
if (latest === package_default.version) {
|
|
10063
|
-
console.log(
|
|
10795
|
+
console.log(chalk33.dim(`diafunc is already at the latest version (${package_default.version}).`));
|
|
10064
10796
|
return;
|
|
10065
10797
|
}
|
|
10066
|
-
console.log(
|
|
10798
|
+
console.log(chalk33.dim(`Current: ${package_default.version} \u2192 Available: ${latest}`));
|
|
10067
10799
|
if (install.method === "npm") {
|
|
10068
10800
|
console.log();
|
|
10069
10801
|
console.log("Installed via npm. Upgrade with:");
|
|
10070
|
-
console.log(
|
|
10802
|
+
console.log(chalk33.bold(` npm install -g @diafunc/cli@${latest}`));
|
|
10071
10803
|
return;
|
|
10072
10804
|
}
|
|
10073
10805
|
const installDir = path10.dirname(install.binaryPath);
|
|
@@ -10081,7 +10813,7 @@ function registerUpdateCommand(program) {
|
|
|
10081
10813
|
}
|
|
10082
10814
|
|
|
10083
10815
|
// src/commands/uninstall/index.ts
|
|
10084
|
-
import
|
|
10816
|
+
import chalk34 from "chalk";
|
|
10085
10817
|
import { spawn as spawn5 } from "child_process";
|
|
10086
10818
|
import * as fs14 from "fs";
|
|
10087
10819
|
import * as os4 from "os";
|
|
@@ -10093,11 +10825,11 @@ function registerUninstallCommand(program) {
|
|
|
10093
10825
|
const configDir = path11.join(os4.homedir(), ".diafunc");
|
|
10094
10826
|
if (install.method === "npm") {
|
|
10095
10827
|
console.log("Installed via npm. Remove with:");
|
|
10096
|
-
console.log(
|
|
10828
|
+
console.log(chalk34.bold(" npm uninstall -g @diafunc/cli"));
|
|
10097
10829
|
if (fs14.existsSync(configDir)) {
|
|
10098
10830
|
console.log();
|
|
10099
10831
|
console.log(`Config and credentials live at ${configDir}. Remove them manually with:`);
|
|
10100
|
-
console.log(
|
|
10832
|
+
console.log(chalk34.bold(` rm -rf ${configDir}`));
|
|
10101
10833
|
}
|
|
10102
10834
|
return;
|
|
10103
10835
|
}
|
|
@@ -10107,7 +10839,7 @@ function registerUninstallCommand(program) {
|
|
|
10107
10839
|
default: false
|
|
10108
10840
|
});
|
|
10109
10841
|
if (!removeBinary) {
|
|
10110
|
-
console.log(
|
|
10842
|
+
console.log(chalk34.dim("Aborted."));
|
|
10111
10843
|
return;
|
|
10112
10844
|
}
|
|
10113
10845
|
let removeConfig = options.purge ?? false;
|
|
@@ -10119,7 +10851,7 @@ function registerUninstallCommand(program) {
|
|
|
10119
10851
|
}
|
|
10120
10852
|
if (removeConfig && fs14.existsSync(configDir)) {
|
|
10121
10853
|
fs14.rmSync(configDir, { recursive: true, force: true });
|
|
10122
|
-
console.log(
|
|
10854
|
+
console.log(chalk34.dim(`Removed ${configDir}`));
|
|
10123
10855
|
}
|
|
10124
10856
|
if (process.platform === "win32") {
|
|
10125
10857
|
const cmd = `timeout /t 2 /nobreak >nul & del /f /q "${install.binaryPath}"`;
|
|
@@ -10129,13 +10861,13 @@ function registerUninstallCommand(program) {
|
|
|
10129
10861
|
windowsHide: true
|
|
10130
10862
|
});
|
|
10131
10863
|
child.unref();
|
|
10132
|
-
console.log(
|
|
10864
|
+
console.log(chalk34.dim(`Removing ${install.binaryPath} on exit...`));
|
|
10133
10865
|
console.log();
|
|
10134
10866
|
console.log("diafunc uninstalled.");
|
|
10135
10867
|
return;
|
|
10136
10868
|
}
|
|
10137
10869
|
fs14.rmSync(install.binaryPath, { force: true });
|
|
10138
|
-
console.log(
|
|
10870
|
+
console.log(chalk34.dim(`Removed ${install.binaryPath}`));
|
|
10139
10871
|
console.log();
|
|
10140
10872
|
console.log("diafunc uninstalled.");
|
|
10141
10873
|
} catch (error) {
|
|
@@ -10199,7 +10931,7 @@ var DiafuncCommand = class _DiafuncCommand extends Command {
|
|
|
10199
10931
|
};
|
|
10200
10932
|
|
|
10201
10933
|
// src/prompting/fill.ts
|
|
10202
|
-
import
|
|
10934
|
+
import chalk36 from "chalk";
|
|
10203
10935
|
|
|
10204
10936
|
// src/prompting/resolvers.ts
|
|
10205
10937
|
var PROJECT_ROLES = ["OWNER", "ADMIN", "DEVELOPER", "GUEST"];
|
|
@@ -10220,12 +10952,14 @@ var POSITIVE = { kind: "number", min: 0, integer: false, exclusive: true };
|
|
|
10220
10952
|
var INDEX = { kind: "number", min: 0, integer: true };
|
|
10221
10953
|
var BY_COMMAND = {
|
|
10222
10954
|
"analyze segment": { "<name>": { kind: "analysisColumns", multiple: false, allowEmpty: true } },
|
|
10223
|
-
"analyze targets": { "<
|
|
10224
|
-
"analyze feature-exclusions": { "<
|
|
10225
|
-
"analyze confirmed-inputs": { "<
|
|
10955
|
+
"analyze targets": { "<column>": { kind: "analysisColumns", multiple: true, allowEmpty: false } },
|
|
10956
|
+
"analyze feature-exclusions": { "<column>": { kind: "analysisColumns", multiple: true, allowEmpty: true } },
|
|
10957
|
+
"analyze confirmed-inputs": { "<column>": { kind: "analysisColumns", multiple: true, allowEmpty: true } },
|
|
10226
10958
|
"analyze questions": { "<question>": TEXT_OR_EMPTY },
|
|
10227
10959
|
"analyze description": { "<text>": TEXT_OR_EMPTY },
|
|
10228
10960
|
"analyze introduction": { "<markdown>": TEXT_OR_EMPTY },
|
|
10961
|
+
// Not the analysis picker: that one offers the reader's own analyses, and this command needs no account.
|
|
10962
|
+
"public show": { "<analysisId>": TEXT },
|
|
10229
10963
|
"analyze presets save": { "--targets": TEXT, "--hours": POSITIVE, "--budget": POSITIVE },
|
|
10230
10964
|
"branch merge": {
|
|
10231
10965
|
"--source": { kind: "entity", form: "ref" },
|
|
@@ -10394,7 +11128,7 @@ function dependencies(spec) {
|
|
|
10394
11128
|
|
|
10395
11129
|
// src/prompting/pickers.ts
|
|
10396
11130
|
import * as fs15 from "fs";
|
|
10397
|
-
import
|
|
11131
|
+
import chalk35 from "chalk";
|
|
10398
11132
|
var SEARCH_THRESHOLD = 10;
|
|
10399
11133
|
var TYPE_IT = "\0type-it";
|
|
10400
11134
|
async function askFor(spec, input, ctx) {
|
|
@@ -10652,7 +11386,7 @@ async function askColumns(ctx, spec, input) {
|
|
|
10652
11386
|
choices: columns.map((c) => ({ name: c, value: c })),
|
|
10653
11387
|
validate: (picked) => picked.length > 0 || "Pick at least one column."
|
|
10654
11388
|
});
|
|
10655
|
-
return chosen
|
|
11389
|
+
return chosen;
|
|
10656
11390
|
}
|
|
10657
11391
|
const items = columns.map((c) => ({ label: c, value: c }));
|
|
10658
11392
|
if (spec.allowEmpty) items.unshift({ label: "None (clear it)", value: "" });
|
|
@@ -10742,7 +11476,7 @@ function typedValue(ctx, message) {
|
|
|
10742
11476
|
return typed(ctx, message);
|
|
10743
11477
|
}
|
|
10744
11478
|
function typeItChoice() {
|
|
10745
|
-
return { name:
|
|
11479
|
+
return { name: chalk35.dim("Type it instead"), value: TYPE_IT };
|
|
10746
11480
|
}
|
|
10747
11481
|
function text(ctx, name) {
|
|
10748
11482
|
const value = ctx.known.get(name);
|
|
@@ -10772,7 +11506,7 @@ function capitalize(value) {
|
|
|
10772
11506
|
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
10773
11507
|
}
|
|
10774
11508
|
function labelled(label, hint2) {
|
|
10775
|
-
return hint2 && hint2 !== label ? `${label} ${
|
|
11509
|
+
return hint2 && hint2 !== label ? `${label} ${chalk35.dim(hint2)}` : label;
|
|
10776
11510
|
}
|
|
10777
11511
|
function numberRule(spec) {
|
|
10778
11512
|
return (raw) => {
|
|
@@ -10818,7 +11552,7 @@ async function fillPendingInputs(actionCommand) {
|
|
|
10818
11552
|
known: knownValues(actionCommand),
|
|
10819
11553
|
globals: actionCommand.optsWithGlobals(),
|
|
10820
11554
|
prefill: /* @__PURE__ */ new Map(),
|
|
10821
|
-
note: (line) => process.stderr.write(
|
|
11555
|
+
note: (line) => process.stderr.write(chalk36.dim(` ${line}
|
|
10822
11556
|
`))
|
|
10823
11557
|
};
|
|
10824
11558
|
for (const item of orderByDependencies(pending)) {
|
|
@@ -10827,7 +11561,7 @@ async function fillPendingInputs(actionCommand) {
|
|
|
10827
11561
|
ctx.known.set(item.input.name, value);
|
|
10828
11562
|
}
|
|
10829
11563
|
const log = env.log ?? ((line) => console.log(line));
|
|
10830
|
-
log(
|
|
11564
|
+
log(chalk36.dim(` Equivalent: ${equivalentCommand(actionCommand)}`));
|
|
10831
11565
|
}
|
|
10832
11566
|
function commandChain(cmd) {
|
|
10833
11567
|
const chain = [];
|
|
@@ -10932,7 +11666,7 @@ function createProgram(environment = {}) {
|
|
|
10932
11666
|
const opts = thisCommand.optsWithGlobals();
|
|
10933
11667
|
if (opts.dryRun) setDryRun(true);
|
|
10934
11668
|
if (opts.verbose) setVerbose(true);
|
|
10935
|
-
if (opts.color === false)
|
|
11669
|
+
if (opts.color === false) chalk37.level = 0;
|
|
10936
11670
|
}).hook("preAction", (_thisCommand, actionCommand) => fillPendingInputs(actionCommand));
|
|
10937
11671
|
program.addHelpText("after", HELP_EPILOGUE);
|
|
10938
11672
|
registerAuthCommands(program);
|
|
@@ -10953,6 +11687,7 @@ function createProgram(environment = {}) {
|
|
|
10953
11687
|
registerAdminCommands(program);
|
|
10954
11688
|
registerStatusCommands(program);
|
|
10955
11689
|
registerAnalyzeCommand(program);
|
|
11690
|
+
registerPublicCommands(program);
|
|
10956
11691
|
registerDataSourcesCommands(program);
|
|
10957
11692
|
registerTableExportersCommands(program);
|
|
10958
11693
|
registerSkeletonCommands(program);
|
|
@@ -10974,4 +11709,4 @@ export {
|
|
|
10974
11709
|
PromptCancelled,
|
|
10975
11710
|
createProgram
|
|
10976
11711
|
};
|
|
10977
|
-
//# sourceMappingURL=chunk-
|
|
11712
|
+
//# sourceMappingURL=chunk-D7AJH4Y3.js.map
|