@diafunc/cli 0.19.0 → 0.21.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-OCZSFCU6.js → chunk-IV75CA5V.js} +1002 -220
- package/dist/chunk-IV75CA5V.js.map +1 -0
- package/dist/{chunk-A5D45VXJ.js → chunk-M34533JL.js} +2 -2
- package/dist/{chunk-A5D45VXJ.js.map → chunk-M34533JL.js.map} +1 -1
- package/dist/{chunk-SYNS3L7N.js → chunk-ZCJKBLEW.js} +2 -2
- package/dist/src/index.js +2 -2
- package/dist/update-check-EW6JPLJT.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-ZCJKBLEW.js.map} +0 -0
- /package/dist/{update-check-TTXILAMD.js.map → update-check-EW6JPLJT.js.map} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-M34533JL.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,24 @@ function createAnalysisService(client) {
|
|
|
1558
1559
|
path: `/${encodeURIComponent(analysisId)}`
|
|
1559
1560
|
});
|
|
1560
1561
|
},
|
|
1562
|
+
/** The depth the platform would give the caller's next analysis if its creation named none. */
|
|
1563
|
+
async getDepthDefault() {
|
|
1564
|
+
return client.request({
|
|
1565
|
+
method: "GET",
|
|
1566
|
+
service: SERVICE2,
|
|
1567
|
+
path: "/depth-default"
|
|
1568
|
+
});
|
|
1569
|
+
},
|
|
1570
|
+
// ----- Public analyses: readable without signing in --------------------------------
|
|
1571
|
+
/** One page of the public analyses. `cursor` is the `nextCursor` of the page before. */
|
|
1572
|
+
async listPublic(page = {}) {
|
|
1573
|
+
return client.request({
|
|
1574
|
+
method: "GET",
|
|
1575
|
+
service: PUBLIC_SERVICE,
|
|
1576
|
+
path: "",
|
|
1577
|
+
query: { cursor: page.cursor, limit: page.limit }
|
|
1578
|
+
});
|
|
1579
|
+
},
|
|
1561
1580
|
// ----- Typed PATCH per editable field --------------------------------------------
|
|
1562
1581
|
async patchName(analysisId, request) {
|
|
1563
1582
|
return client.request({
|
|
@@ -1712,6 +1731,22 @@ function createAnalysisService(client) {
|
|
|
1712
1731
|
body: request
|
|
1713
1732
|
});
|
|
1714
1733
|
},
|
|
1734
|
+
/** How the import of the analysis's data stands. `dataImport` null means it finished and the counts are final. */
|
|
1735
|
+
async getDataImport(analysisId) {
|
|
1736
|
+
return client.request({
|
|
1737
|
+
method: "GET",
|
|
1738
|
+
service: SERVICE2,
|
|
1739
|
+
path: `/${encodeURIComponent(analysisId)}/data/import`
|
|
1740
|
+
});
|
|
1741
|
+
},
|
|
1742
|
+
/** Stops the running import. The platform waits a while for it to end and answers `STOPPING` when it has not yet. */
|
|
1743
|
+
async stopDataImport(analysisId) {
|
|
1744
|
+
return client.request({
|
|
1745
|
+
method: "DELETE",
|
|
1746
|
+
service: SERVICE2,
|
|
1747
|
+
path: `/${encodeURIComponent(analysisId)}/data/import`
|
|
1748
|
+
});
|
|
1749
|
+
},
|
|
1715
1750
|
async getColumns(analysisId) {
|
|
1716
1751
|
return client.request({
|
|
1717
1752
|
method: "GET",
|
|
@@ -2790,7 +2825,8 @@ function createIndexService(client) {
|
|
|
2790
2825
|
cursor: query.cursor ?? void 0,
|
|
2791
2826
|
contentType: query.contentType ?? void 0,
|
|
2792
2827
|
projectId: query.projectId ?? void 0,
|
|
2793
|
-
projectBranch: query.projectBranch ?? void 0
|
|
2828
|
+
projectBranch: query.projectBranch ?? void 0,
|
|
2829
|
+
sort: query.sort && query.sort !== "best" ? query.sort : void 0
|
|
2794
2830
|
}
|
|
2795
2831
|
});
|
|
2796
2832
|
},
|
|
@@ -3405,17 +3441,17 @@ async function projectNames(api, projectIds) {
|
|
|
3405
3441
|
const wanted = new Set(projectIds);
|
|
3406
3442
|
const names = /* @__PURE__ */ new Map();
|
|
3407
3443
|
if (wanted.size === 0) return names;
|
|
3408
|
-
const
|
|
3444
|
+
const take2 = (items) => {
|
|
3409
3445
|
for (const item of items) {
|
|
3410
3446
|
if (item.contentType !== "project" || !item.name || !wanted.has(item.projectId)) continue;
|
|
3411
3447
|
if (!names.has(item.projectId)) names.set(item.projectId, item.name);
|
|
3412
3448
|
}
|
|
3413
3449
|
};
|
|
3414
|
-
|
|
3450
|
+
take2((await api.index.searchPage({ query: "*", contentType: "project", limit: FIRST_PAGE })).items);
|
|
3415
3451
|
const missing = [...wanted].filter((id) => !names.has(id));
|
|
3416
3452
|
for (let i = 0; i < missing.length; i += CONCURRENCY) {
|
|
3417
3453
|
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)
|
|
3454
|
+
for (const page of pages) if (page) take2(page.items);
|
|
3419
3455
|
}
|
|
3420
3456
|
return names;
|
|
3421
3457
|
}
|
|
@@ -6259,7 +6295,7 @@ var HELP = [
|
|
|
6259
6295
|
];
|
|
6260
6296
|
async function runChatRepl(options) {
|
|
6261
6297
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
6262
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
6298
|
+
const { getUpdateNotice } = await import("./update-check-EW6JPLJT.js");
|
|
6263
6299
|
let sessionId = options.session;
|
|
6264
6300
|
let lastReportedSession;
|
|
6265
6301
|
console.log(chalk19.bold("Diafunc chat") + chalk19.dim(" \xB7 /help for commands, /quit to exit"));
|
|
@@ -6549,14 +6585,23 @@ function getOutputFormat13(cmd) {
|
|
|
6549
6585
|
const globalOpts = cmd.optsWithGlobals();
|
|
6550
6586
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
6551
6587
|
}
|
|
6588
|
+
function parseSort(raw) {
|
|
6589
|
+
if (raw === "best" || raw === "newest") return raw;
|
|
6590
|
+
return usageError(`Unknown sort "${raw}".`, "Use --sort best or --sort newest.");
|
|
6591
|
+
}
|
|
6552
6592
|
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", `
|
|
6593
|
+
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
6594
|
Examples:
|
|
6555
6595
|
$ diafunc search "housing" everything matching, across projects
|
|
6556
6596
|
$ diafunc search "housing" --type project only projects
|
|
6557
6597
|
$ diafunc search "medv" --project <id> only inside one project
|
|
6598
|
+
$ diafunc search "housing" --sort newest most recently changed first among equal matches
|
|
6558
6599
|
$ diafunc search "housing" --output json for scripting
|
|
6600
|
+
|
|
6601
|
+
Results are ordered by how well they match. Among results that match equally well, the project
|
|
6602
|
+
whose discovered model has the better quality comes first; inside one project the newer one does.
|
|
6559
6603
|
`).action(async (query, options, cmd) => {
|
|
6604
|
+
const sort = parseSort(options.sort);
|
|
6560
6605
|
try {
|
|
6561
6606
|
const outputFormat = getOutputFormat13(cmd);
|
|
6562
6607
|
const overrides = cmd.optsWithGlobals();
|
|
@@ -6569,7 +6614,8 @@ Examples:
|
|
|
6569
6614
|
limit: Number.isFinite(limit) && limit > 0 ? limit : 20,
|
|
6570
6615
|
contentType: options.type ?? null,
|
|
6571
6616
|
projectId,
|
|
6572
|
-
projectBranch: projectId ? overrides.branch ?? config.defaults.branch ?? "main" : null
|
|
6617
|
+
projectBranch: projectId ? overrides.branch ?? config.defaults.branch ?? "main" : null,
|
|
6618
|
+
sort
|
|
6573
6619
|
});
|
|
6574
6620
|
const items = dedupe(page.items);
|
|
6575
6621
|
if (outputFormat === "json") {
|
|
@@ -6588,6 +6634,7 @@ Examples:
|
|
|
6588
6634
|
columns: [
|
|
6589
6635
|
{ key: "contentType", header: "type" },
|
|
6590
6636
|
{ key: "name" },
|
|
6637
|
+
{ key: "quality" },
|
|
6591
6638
|
{ key: "projectId", kind: "id" },
|
|
6592
6639
|
{ key: "entityId", kind: "id" }
|
|
6593
6640
|
]
|
|
@@ -6616,7 +6663,7 @@ function renderResults(items) {
|
|
|
6616
6663
|
for (const item of items) {
|
|
6617
6664
|
const name = item.name || "(unnamed)";
|
|
6618
6665
|
console.log();
|
|
6619
|
-
console.log(`${chalk20.dim(`[${item.contentType}]`)} ${chalk20.bold(name)}`);
|
|
6666
|
+
console.log(`${chalk20.dim(`[${item.contentType}]`)} ${chalk20.bold(name)}${qualityNote(item)}`);
|
|
6620
6667
|
const raw = item.snippetField === "name" ? item.description : item.snippet ?? item.description;
|
|
6621
6668
|
const line = raw ? collapse(raw) : null;
|
|
6622
6669
|
if (line && stripHighlight(line) !== name) console.log(` ${highlight(line)}`);
|
|
@@ -6625,6 +6672,12 @@ function renderResults(items) {
|
|
|
6625
6672
|
}
|
|
6626
6673
|
console.log();
|
|
6627
6674
|
}
|
|
6675
|
+
function qualityNote(item) {
|
|
6676
|
+
if (item.contentType !== "project" || typeof item.quality !== "number" || !Number.isFinite(item.quality)) {
|
|
6677
|
+
return "";
|
|
6678
|
+
}
|
|
6679
|
+
return chalk20.dim(` quality ${percent(item.quality).trim()}`);
|
|
6680
|
+
}
|
|
6628
6681
|
var HIGHLIGHT_OPEN = /<mark>/g;
|
|
6629
6682
|
var HIGHLIGHT_CLOSE = /<\/mark>/g;
|
|
6630
6683
|
function highlight(text2) {
|
|
@@ -7145,6 +7198,14 @@ function terminalSentence(state, duration, credits = null) {
|
|
|
7145
7198
|
return `Analysis failed after ${duration}${cost}.`;
|
|
7146
7199
|
}
|
|
7147
7200
|
}
|
|
7201
|
+
function isImporting(dataImport) {
|
|
7202
|
+
return dataImport?.state === "IMPORTING" || dataImport?.state === "STOPPING";
|
|
7203
|
+
}
|
|
7204
|
+
function importingLabel(dataImport) {
|
|
7205
|
+
const progress = dataImport.progress;
|
|
7206
|
+
if (progress === null || progress === void 0 || !Number.isFinite(progress)) return "Importing data";
|
|
7207
|
+
return `Importing data, ${Math.floor(Math.max(0, Math.min(progress, 1)) * 100)} %`;
|
|
7208
|
+
}
|
|
7148
7209
|
|
|
7149
7210
|
// src/commands/analyze/watch-view.ts
|
|
7150
7211
|
function overallProgress(run) {
|
|
@@ -7211,6 +7272,178 @@ function renderWatchBlock(input) {
|
|
|
7211
7272
|
|
|
7212
7273
|
// src/commands/analyze/wizard.ts
|
|
7213
7274
|
import chalk25 from "chalk";
|
|
7275
|
+
|
|
7276
|
+
// src/commands/analyze/columns.ts
|
|
7277
|
+
var MAX_COLUMNS_LISTED = 30;
|
|
7278
|
+
var MAX_NEAR_MATCHES = 3;
|
|
7279
|
+
function parseColumnList(text2) {
|
|
7280
|
+
const names = [];
|
|
7281
|
+
let i = 0;
|
|
7282
|
+
while (i < text2.length) {
|
|
7283
|
+
while (i < text2.length && isSpace(text2[i])) i++;
|
|
7284
|
+
if (i >= text2.length) break;
|
|
7285
|
+
if (text2[i] === '"') {
|
|
7286
|
+
let name = "";
|
|
7287
|
+
let closed = false;
|
|
7288
|
+
i++;
|
|
7289
|
+
while (i < text2.length) {
|
|
7290
|
+
if (text2[i] === '"' && text2[i + 1] === '"') {
|
|
7291
|
+
name += '"';
|
|
7292
|
+
i += 2;
|
|
7293
|
+
} else if (text2[i] === '"') {
|
|
7294
|
+
closed = true;
|
|
7295
|
+
i++;
|
|
7296
|
+
break;
|
|
7297
|
+
} else {
|
|
7298
|
+
name += text2[i++];
|
|
7299
|
+
}
|
|
7300
|
+
}
|
|
7301
|
+
if (!closed) {
|
|
7302
|
+
throw new CliError(`A double quote is opened and never closed in: ${text2}`, {
|
|
7303
|
+
exitCode: EXIT_USAGE,
|
|
7304
|
+
hint: QUOTING_HINT
|
|
7305
|
+
});
|
|
7306
|
+
}
|
|
7307
|
+
while (i < text2.length && isSpace(text2[i])) i++;
|
|
7308
|
+
if (i < text2.length && text2[i] !== ",") {
|
|
7309
|
+
throw new CliError(`Text follows a closing double quote without a comma in: ${text2}`, {
|
|
7310
|
+
exitCode: EXIT_USAGE,
|
|
7311
|
+
hint: QUOTING_HINT
|
|
7312
|
+
});
|
|
7313
|
+
}
|
|
7314
|
+
i++;
|
|
7315
|
+
if (name.length > 0) names.push(name);
|
|
7316
|
+
} else {
|
|
7317
|
+
const end = text2.indexOf(",", i);
|
|
7318
|
+
const name = text2.slice(i, end === -1 ? text2.length : end).trim();
|
|
7319
|
+
i = end === -1 ? text2.length : end + 1;
|
|
7320
|
+
if (name.length > 0) names.push(name);
|
|
7321
|
+
}
|
|
7322
|
+
}
|
|
7323
|
+
return names;
|
|
7324
|
+
}
|
|
7325
|
+
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'.`;
|
|
7326
|
+
function isSpace(char) {
|
|
7327
|
+
return char === " " || char === " ";
|
|
7328
|
+
}
|
|
7329
|
+
function quoteColumn(name) {
|
|
7330
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
7331
|
+
}
|
|
7332
|
+
function loose(name) {
|
|
7333
|
+
return name.trim().toLowerCase();
|
|
7334
|
+
}
|
|
7335
|
+
function matchColumn(name, columns) {
|
|
7336
|
+
if (columns.includes(name)) return { kind: "column", column: name };
|
|
7337
|
+
const wanted = loose(name);
|
|
7338
|
+
const candidates = columns.filter((column) => loose(column) === wanted);
|
|
7339
|
+
if (candidates.length === 1) return { kind: "column", column: candidates[0] };
|
|
7340
|
+
return candidates.length > 1 ? { kind: "ambiguous", candidates } : { kind: "unknown" };
|
|
7341
|
+
}
|
|
7342
|
+
function nearMatches(name, columns) {
|
|
7343
|
+
const wanted = loose(name);
|
|
7344
|
+
if (wanted.length === 0) return [];
|
|
7345
|
+
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);
|
|
7346
|
+
}
|
|
7347
|
+
function distanceTo(wanted, column) {
|
|
7348
|
+
const edits = editDistance(wanted, column);
|
|
7349
|
+
if (edits <= Math.max(1, Math.floor(Math.min(wanted.length, column.length) / 4))) return edits;
|
|
7350
|
+
if (wanted.length >= 3 && (column.includes(wanted) || wanted.includes(column)) && column.length > 0) {
|
|
7351
|
+
return 100 + Math.abs(column.length - wanted.length);
|
|
7352
|
+
}
|
|
7353
|
+
return null;
|
|
7354
|
+
}
|
|
7355
|
+
function editDistance(a, b) {
|
|
7356
|
+
let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
7357
|
+
for (let i = 1; i <= a.length; i++) {
|
|
7358
|
+
const current = [i];
|
|
7359
|
+
for (let j = 1; j <= b.length; j++) {
|
|
7360
|
+
current[j] = Math.min(
|
|
7361
|
+
previous[j] + 1,
|
|
7362
|
+
current[j - 1] + 1,
|
|
7363
|
+
previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)
|
|
7364
|
+
);
|
|
7365
|
+
}
|
|
7366
|
+
previous = current;
|
|
7367
|
+
}
|
|
7368
|
+
return previous[b.length];
|
|
7369
|
+
}
|
|
7370
|
+
function take(name, columns, into, problems) {
|
|
7371
|
+
const match = matchColumn(name, columns);
|
|
7372
|
+
if (match.kind === "column") {
|
|
7373
|
+
if (!into.includes(match.column)) into.push(match.column);
|
|
7374
|
+
return true;
|
|
7375
|
+
}
|
|
7376
|
+
if (match.kind === "ambiguous") problems.ambiguous.push({ name, candidates: match.candidates });
|
|
7377
|
+
else problems.unknown.push(name);
|
|
7378
|
+
return false;
|
|
7379
|
+
}
|
|
7380
|
+
function refuse(problems, columns, analysisId) {
|
|
7381
|
+
const sentences = [];
|
|
7382
|
+
if (problems.unknown.length === 1) {
|
|
7383
|
+
sentences.push(`${quoteColumn(problems.unknown[0])} is not a column of the analysis data.`);
|
|
7384
|
+
} else if (problems.unknown.length > 1) {
|
|
7385
|
+
sentences.push(`These are not columns of the analysis data: ${problems.unknown.map(quoteColumn).join(", ")}.`);
|
|
7386
|
+
}
|
|
7387
|
+
for (const { name, candidates } of problems.ambiguous) {
|
|
7388
|
+
sentences.push(`${quoteColumn(name)} matches more than one column: ${candidates.map(quoteColumn).join(", ")}. Type the one you mean exactly.`);
|
|
7389
|
+
}
|
|
7390
|
+
const hints = [];
|
|
7391
|
+
const near = [...new Set(problems.unknown.flatMap((name) => nearMatches(name, columns)))];
|
|
7392
|
+
if (near.length > 0) hints.push(`Did you mean ${near.map(quoteColumn).join(" or ")}?`);
|
|
7393
|
+
const listed2 = columns.slice(0, MAX_COLUMNS_LISTED).map(quoteColumn).join(", ");
|
|
7394
|
+
const more = columns.length > MAX_COLUMNS_LISTED ? ` and ${columns.length - MAX_COLUMNS_LISTED} more${analysisId ? ` ('diafunc analyze columns ${analysisId}' lists them all)` : ""}` : "";
|
|
7395
|
+
hints.push(`The columns are: ${listed2}${more}.`);
|
|
7396
|
+
if (problems.fromList) {
|
|
7397
|
+
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'.`);
|
|
7398
|
+
}
|
|
7399
|
+
throw new CliError(sentences.join(" "), { exitCode: EXIT_USAGE, hint: hints.join("\n ") });
|
|
7400
|
+
}
|
|
7401
|
+
function resolveColumnArguments(given, columns, analysisId) {
|
|
7402
|
+
const resolved = [];
|
|
7403
|
+
if (columns.length === 0) {
|
|
7404
|
+
for (const name of given.flatMap(parseColumnList)) {
|
|
7405
|
+
if (!resolved.includes(name)) resolved.push(name);
|
|
7406
|
+
}
|
|
7407
|
+
return resolved;
|
|
7408
|
+
}
|
|
7409
|
+
const problems = { unknown: [], ambiguous: [], fromList: false };
|
|
7410
|
+
for (const argument of given) {
|
|
7411
|
+
if (argument.trim().length === 0) continue;
|
|
7412
|
+
const whole = matchColumn(argument, columns);
|
|
7413
|
+
if (whole.kind === "column") {
|
|
7414
|
+
if (!resolved.includes(whole.column)) resolved.push(whole.column);
|
|
7415
|
+
continue;
|
|
7416
|
+
}
|
|
7417
|
+
const names = parseColumnList(argument);
|
|
7418
|
+
const single = names.length === 1 && names[0] === argument.trim();
|
|
7419
|
+
for (const name of names) {
|
|
7420
|
+
if (!take(name, columns, resolved, problems) && !single) problems.fromList = true;
|
|
7421
|
+
}
|
|
7422
|
+
}
|
|
7423
|
+
if (problems.unknown.length > 0 || problems.ambiguous.length > 0) refuse(problems, columns, analysisId);
|
|
7424
|
+
return resolved;
|
|
7425
|
+
}
|
|
7426
|
+
function resolveColumnNames(names, columns, analysisId) {
|
|
7427
|
+
if (columns.length === 0) return [...names];
|
|
7428
|
+
const resolved = [];
|
|
7429
|
+
const problems = { unknown: [], ambiguous: [], fromList: false };
|
|
7430
|
+
for (const name of names) take(name, columns, resolved, problems);
|
|
7431
|
+
if (problems.unknown.length > 0 || problems.ambiguous.length > 0) refuse(problems, columns, analysisId);
|
|
7432
|
+
return resolved;
|
|
7433
|
+
}
|
|
7434
|
+
function resolveColumnArgument(given, columns, analysisId) {
|
|
7435
|
+
if (columns.length === 0) return given;
|
|
7436
|
+
return resolveColumnNames([given], columns, analysisId)[0];
|
|
7437
|
+
}
|
|
7438
|
+
function occurrences(value) {
|
|
7439
|
+
if (value === void 0) return void 0;
|
|
7440
|
+
return Array.isArray(value) ? value : [value];
|
|
7441
|
+
}
|
|
7442
|
+
function collectColumns(value, previous = []) {
|
|
7443
|
+
return previous.concat([value]);
|
|
7444
|
+
}
|
|
7445
|
+
|
|
7446
|
+
// src/commands/analyze/wizard.ts
|
|
7214
7447
|
var DEPTH_PRESETS = [
|
|
7215
7448
|
{ name: "Express", hours: "1", budget: "500" },
|
|
7216
7449
|
{ name: "Quick", hours: "2", budget: "2000" },
|
|
@@ -7218,8 +7451,12 @@ var DEPTH_PRESETS = [
|
|
|
7218
7451
|
{ name: "Thorough", hours: "8", budget: "40000" },
|
|
7219
7452
|
{ name: "Deep", hours: "24", budget: "150000" }
|
|
7220
7453
|
];
|
|
7221
|
-
var
|
|
7222
|
-
|
|
7454
|
+
var STARTING_DEPTH_RULE = "Defaults to the account's starting depth: Express (1 hour, 500 credits) until the account has a finished analysis, Standard (4 hours, 10,000 credits) afterwards.";
|
|
7455
|
+
function depthOf(hours, budget) {
|
|
7456
|
+
const h = hours?.trim();
|
|
7457
|
+
const b = budget?.trim();
|
|
7458
|
+
return h && b ? { hours: h, budget: b } : null;
|
|
7459
|
+
}
|
|
7223
7460
|
async function promptCreationFields(prompter, supplied, fallbackName) {
|
|
7224
7461
|
const name = supplied.name ?? await prompter.input({
|
|
7225
7462
|
message: "Analysis name",
|
|
@@ -7255,7 +7492,7 @@ function positiveNumber(label) {
|
|
|
7255
7492
|
};
|
|
7256
7493
|
}
|
|
7257
7494
|
async function promptRunFields(prompter, options) {
|
|
7258
|
-
const { columns } = options;
|
|
7495
|
+
const { columns, depthDefault } = options;
|
|
7259
7496
|
const named = columns.filter((c) => c.name && c.name.length > 0);
|
|
7260
7497
|
let supplied = { ...options.supplied };
|
|
7261
7498
|
const nothingSupplied = supplied.targets === void 0 && supplied.segment === void 0 && supplied.questions === void 0 && supplied.hours === void 0 && supplied.budget === void 0;
|
|
@@ -7297,10 +7534,16 @@ async function promptRunFields(prompter, options) {
|
|
|
7297
7534
|
});
|
|
7298
7535
|
} else {
|
|
7299
7536
|
const typed2 = await prompter.input({
|
|
7300
|
-
message: "Target column names (comma-separated)",
|
|
7301
|
-
validate: (value) =>
|
|
7537
|
+
message: "Target column names (comma-separated; a name that contains a comma goes in double quotes)",
|
|
7538
|
+
validate: (value) => {
|
|
7539
|
+
try {
|
|
7540
|
+
return parseColumnList(value).length > 0 || "Name at least one target column.";
|
|
7541
|
+
} catch (error) {
|
|
7542
|
+
return error instanceof Error ? error.message : String(error);
|
|
7543
|
+
}
|
|
7544
|
+
}
|
|
7302
7545
|
});
|
|
7303
|
-
targets =
|
|
7546
|
+
targets = parseColumnList(typed2);
|
|
7304
7547
|
}
|
|
7305
7548
|
}
|
|
7306
7549
|
const remaining = named.filter((c) => !targets.includes(c.name));
|
|
@@ -7342,7 +7585,7 @@ async function promptRunFields(prompter, options) {
|
|
|
7342
7585
|
if (hours === void 0 && budget === void 0) {
|
|
7343
7586
|
const chosen = await prompter.select({
|
|
7344
7587
|
message: "Depth: how long may the search run, and what may it spend?",
|
|
7345
|
-
default:
|
|
7588
|
+
default: matchDepthPreset(depthDefault?.hours, depthDefault?.budget) ?? void 0,
|
|
7346
7589
|
choices: [
|
|
7347
7590
|
...DEPTH_PRESETS.map((p) => ({
|
|
7348
7591
|
name: p.name,
|
|
@@ -7359,15 +7602,15 @@ async function promptRunFields(prompter, options) {
|
|
|
7359
7602
|
}
|
|
7360
7603
|
if (hours === void 0) {
|
|
7361
7604
|
hours = await prompter.input({
|
|
7362
|
-
message: "
|
|
7363
|
-
default:
|
|
7364
|
-
validate: positiveNumber("
|
|
7605
|
+
message: "Time budget (hours)",
|
|
7606
|
+
default: depthDefault?.hours,
|
|
7607
|
+
validate: positiveNumber("Time budget")
|
|
7365
7608
|
});
|
|
7366
7609
|
}
|
|
7367
7610
|
if (budget === void 0) {
|
|
7368
7611
|
budget = await prompter.input({
|
|
7369
7612
|
message: "Credit budget",
|
|
7370
|
-
default:
|
|
7613
|
+
default: depthDefault?.budget,
|
|
7371
7614
|
validate: positiveNumber("Credit budget")
|
|
7372
7615
|
});
|
|
7373
7616
|
}
|
|
@@ -7380,7 +7623,9 @@ async function promptRunFields(prompter, options) {
|
|
|
7380
7623
|
};
|
|
7381
7624
|
}
|
|
7382
7625
|
function describePreset(preset) {
|
|
7383
|
-
const parts = [
|
|
7626
|
+
const parts = [];
|
|
7627
|
+
if (preset.time) parts.push(`${preset.time}h`);
|
|
7628
|
+
if (preset.budget) parts.push(`${preset.budget} credits`);
|
|
7384
7629
|
if (preset.targetKeys.length > 0) parts.push(`targets: ${preset.targetKeys.join(", ")}`);
|
|
7385
7630
|
if (preset.segmentKey) parts.push(`segmented by ${preset.segmentKey}`);
|
|
7386
7631
|
return parts.join(" \xB7 ");
|
|
@@ -7395,13 +7640,13 @@ function summaryLines(creation, run) {
|
|
|
7395
7640
|
if (run.questions && run.questions.length > 0) {
|
|
7396
7641
|
lines.push(`Questions: ${run.questions.length}`);
|
|
7397
7642
|
}
|
|
7398
|
-
|
|
7399
|
-
const named = depth ? `${depth.name}, ` : "";
|
|
7400
|
-
lines.push(`Depth: ${named}${run.hours}h \xB7 ${run.budget} credits`);
|
|
7643
|
+
lines.push(`Depth: ${depthLabel(run)}`);
|
|
7401
7644
|
return lines;
|
|
7402
7645
|
}
|
|
7403
|
-
function
|
|
7404
|
-
|
|
7646
|
+
function depthLabel(depth) {
|
|
7647
|
+
const preset = matchDepthPreset(depth.hours, depth.budget);
|
|
7648
|
+
const named = preset ? `${preset.name}, ` : "";
|
|
7649
|
+
return `${named}${depth.hours}h \xB7 ${depth.budget} credits`;
|
|
7405
7650
|
}
|
|
7406
7651
|
function missingRunFields(recipe) {
|
|
7407
7652
|
const missing = [];
|
|
@@ -7422,7 +7667,7 @@ function suppliedFromAnalysis(analysis) {
|
|
|
7422
7667
|
var FIELD_COMMANDS = {
|
|
7423
7668
|
hours: "hours <id> <hours>",
|
|
7424
7669
|
budget: "budget <id> <credits>",
|
|
7425
|
-
targets: "targets <id> <
|
|
7670
|
+
targets: "targets <id> <column...>"
|
|
7426
7671
|
};
|
|
7427
7672
|
function explainMissingRunFields(analysisId, missing, reason2) {
|
|
7428
7673
|
const commands = missing.map((f) => `'diafunc analyze ${FIELD_COMMANDS[f].replace("<id>", analysisId)}'`);
|
|
@@ -7492,6 +7737,9 @@ function whyNoPrompt(outputFormat, noInteractive) {
|
|
|
7492
7737
|
return "there is no terminal to ask";
|
|
7493
7738
|
}
|
|
7494
7739
|
|
|
7740
|
+
// src/commands/analyze/data-import.ts
|
|
7741
|
+
import chalk26 from "chalk";
|
|
7742
|
+
|
|
7495
7743
|
// src/commands/analyze/details.ts
|
|
7496
7744
|
function analysisDetails(analysis, endpoint) {
|
|
7497
7745
|
const data = {
|
|
@@ -7501,6 +7749,7 @@ function analysisDetails(analysis, endpoint) {
|
|
|
7501
7749
|
visibility: sentenceCase(analysis.visibility),
|
|
7502
7750
|
introduction: analysis.introduction,
|
|
7503
7751
|
data: dataShape(analysis.rowCount, analysis.columnCount),
|
|
7752
|
+
dataImport: analysis.dataImport?.message ?? null,
|
|
7504
7753
|
targets: analysis.targets,
|
|
7505
7754
|
targetKinds: analysis.targetKinds && Object.keys(analysis.targetKinds).length > 0 ? analysis.targetKinds : "detected from the data",
|
|
7506
7755
|
featureExclusions: analysis.featureExclusions,
|
|
@@ -7511,7 +7760,8 @@ function analysisDetails(analysis, endpoint) {
|
|
|
7511
7760
|
budget: creditsText(analysis.budget),
|
|
7512
7761
|
constraints: constraintsText(analysis),
|
|
7513
7762
|
notifyByEmail: analysis.notifyByEmail == null ? "account default" : analysis.notifyByEmail ? "yes" : "no",
|
|
7514
|
-
|
|
7763
|
+
// While the data is still arriving no run can start, so the import is what the analysis is doing.
|
|
7764
|
+
latestRunState: isImporting(analysis.dataImport) ? importingLabel(analysis.dataImport) : analysis.latestRunState ? sentenceCase(analysis.latestRunState) : null,
|
|
7515
7765
|
latestRunId: analysis.latestRunId,
|
|
7516
7766
|
quality: qualityText(analysis),
|
|
7517
7767
|
outputs: outputsText(analysis),
|
|
@@ -7530,13 +7780,14 @@ function analysisDetails(analysis, endpoint) {
|
|
|
7530
7780
|
{ key: "visibility", header: "Visibility" },
|
|
7531
7781
|
{ key: "introduction", header: "Introduction" },
|
|
7532
7782
|
{ key: "data", header: "Data" },
|
|
7783
|
+
{ key: "dataImport", header: "Data import" },
|
|
7533
7784
|
{ key: "targets", header: "Targets" },
|
|
7534
7785
|
{ key: "targetKinds", header: "Target kinds" },
|
|
7535
7786
|
{ key: "featureExclusions", header: "Excluded columns" },
|
|
7536
7787
|
{ key: "confirmedInputs", header: "Known before the outcome" },
|
|
7537
7788
|
{ key: "questions", header: "Questions" },
|
|
7538
7789
|
{ key: "segment", header: "Segment" },
|
|
7539
|
-
{ key: "hours", header: "
|
|
7790
|
+
{ key: "hours", header: "Time budget" },
|
|
7540
7791
|
{ key: "budget", header: "Credit budget" },
|
|
7541
7792
|
{ key: "constraints", header: "Constraints" },
|
|
7542
7793
|
{ key: "notifyByEmail", header: "Email when done" },
|
|
@@ -7604,16 +7855,220 @@ function constraintsText(analysis) {
|
|
|
7604
7855
|
return parts.length > 0 ? parts.join(", ") : "none";
|
|
7605
7856
|
}
|
|
7606
7857
|
|
|
7858
|
+
// src/commands/analyze/data-import.ts
|
|
7859
|
+
var IMPORT_POLL_INTERVAL_MS = 2e3;
|
|
7860
|
+
function renderImportBlock(dataImport, elapsedMs) {
|
|
7861
|
+
const title = dataImport.state === "STOPPING" ? "Stopping the data import" : "Importing data";
|
|
7862
|
+
const lines = [` ${chalk26.cyan(SPINNER)} ${chalk26.bold(title)}`];
|
|
7863
|
+
const elapsed = chalk26.dim(formatDurationPrecise(elapsedMs));
|
|
7864
|
+
if (dataImport.state === "IMPORTING" && dataImport.progress !== null && dataImport.progress !== void 0) {
|
|
7865
|
+
lines.push(` ${bar(dataImport.progress)} ${percent(dataImport.progress)} ${elapsed}`);
|
|
7866
|
+
} else {
|
|
7867
|
+
lines.push(` ${chalk26.dim(dataImport.message)} ${elapsed}`);
|
|
7868
|
+
}
|
|
7869
|
+
return lines;
|
|
7870
|
+
}
|
|
7871
|
+
function sleep3(ms) {
|
|
7872
|
+
let timer;
|
|
7873
|
+
const done = new Promise((resolve) => {
|
|
7874
|
+
timer = setTimeout(() => resolve("elapsed"), ms);
|
|
7875
|
+
});
|
|
7876
|
+
return { done, cancel: () => clearTimeout(timer) };
|
|
7877
|
+
}
|
|
7878
|
+
async function followImport(ctx, first) {
|
|
7879
|
+
const { api, analysisId } = ctx;
|
|
7880
|
+
const human = ctx.outputFormat === "human";
|
|
7881
|
+
const startedAt = Date.parse(first.startedAt);
|
|
7882
|
+
const since = Number.isFinite(startedAt) ? startedAt : Date.now();
|
|
7883
|
+
const status = new Status();
|
|
7884
|
+
let interrupt = () => {
|
|
7885
|
+
};
|
|
7886
|
+
const interrupted = new Promise((resolve) => {
|
|
7887
|
+
interrupt = () => resolve("interrupted");
|
|
7888
|
+
});
|
|
7889
|
+
process.once("SIGINT", interrupt);
|
|
7890
|
+
if (ctx.live) {
|
|
7891
|
+
status.start();
|
|
7892
|
+
} else {
|
|
7893
|
+
console.error("The import is still running on the platform. Waiting for it to finish.");
|
|
7894
|
+
}
|
|
7895
|
+
let current = first;
|
|
7896
|
+
try {
|
|
7897
|
+
for (; ; ) {
|
|
7898
|
+
if (ctx.live) status.set(renderImportBlock(current, Date.now() - since));
|
|
7899
|
+
const pause = sleep3(IMPORT_POLL_INTERVAL_MS);
|
|
7900
|
+
const woke = await Promise.race([pause.done, interrupted]);
|
|
7901
|
+
if (woke === "interrupted") {
|
|
7902
|
+
pause.cancel();
|
|
7903
|
+
status.stop();
|
|
7904
|
+
warn("Stopped waiting. The import keeps running on the platform.");
|
|
7905
|
+
hint(`See how far it is with 'diafunc analyze get ${analysisId}'.`);
|
|
7906
|
+
hint(`Start the run once it has finished with 'diafunc analyze rerun ${analysisId}'.`);
|
|
7907
|
+
process.exit(EXIT_CANCELLED);
|
|
7908
|
+
}
|
|
7909
|
+
let answer;
|
|
7910
|
+
try {
|
|
7911
|
+
answer = await api.analysis.getDataImport(analysisId);
|
|
7912
|
+
} catch (error) {
|
|
7913
|
+
if (error instanceof ApiError && error.status < 500) throw error;
|
|
7914
|
+
continue;
|
|
7915
|
+
}
|
|
7916
|
+
if (isImporting(answer.dataImport)) {
|
|
7917
|
+
current = answer.dataImport;
|
|
7918
|
+
continue;
|
|
7919
|
+
}
|
|
7920
|
+
status.stop();
|
|
7921
|
+
if (!answer.dataImport) {
|
|
7922
|
+
const shape = dataShape(answer.rowCount, answer.columnCount);
|
|
7923
|
+
if (human) {
|
|
7924
|
+
success(shape ? `Data imported: ${shape}.` : "Data imported.");
|
|
7925
|
+
} else if (ctx.machineReport === "stream") {
|
|
7926
|
+
process.stdout.write(JSON.stringify({
|
|
7927
|
+
type: "import",
|
|
7928
|
+
state: "IMPORTED",
|
|
7929
|
+
rowCount: answer.rowCount ?? null,
|
|
7930
|
+
columnCount: answer.columnCount ?? null
|
|
7931
|
+
}) + "\n");
|
|
7932
|
+
} else {
|
|
7933
|
+
console.error("The import has finished.");
|
|
7934
|
+
}
|
|
7935
|
+
}
|
|
7936
|
+
return { dataImport: answer.dataImport ?? null, rowCount: answer.rowCount ?? null, columnCount: answer.columnCount ?? null };
|
|
7937
|
+
}
|
|
7938
|
+
} finally {
|
|
7939
|
+
status.stop();
|
|
7940
|
+
process.off("SIGINT", interrupt);
|
|
7941
|
+
}
|
|
7942
|
+
}
|
|
7943
|
+
async function stopImport(api, analysisId) {
|
|
7944
|
+
let answer = await api.analysis.stopDataImport(analysisId);
|
|
7945
|
+
while (answer.dataImport?.state === "STOPPING") {
|
|
7946
|
+
await sleep3(IMPORT_POLL_INTERVAL_MS).done;
|
|
7947
|
+
answer = await api.analysis.getDataImport(analysisId);
|
|
7948
|
+
}
|
|
7949
|
+
return { dataImport: answer.dataImport ?? null, rowCount: answer.rowCount ?? null, columnCount: answer.columnCount ?? null };
|
|
7950
|
+
}
|
|
7951
|
+
async function importInFlight(api, analysisId) {
|
|
7952
|
+
try {
|
|
7953
|
+
const { dataImport } = await api.analysis.getDataImport(analysisId);
|
|
7954
|
+
return isImporting(dataImport) ? dataImport : null;
|
|
7955
|
+
} catch {
|
|
7956
|
+
return null;
|
|
7957
|
+
}
|
|
7958
|
+
}
|
|
7959
|
+
async function importBlockingRun(api, analysisId) {
|
|
7960
|
+
try {
|
|
7961
|
+
const { dataImport } = await api.analysis.getDataImport(analysisId);
|
|
7962
|
+
return dataImport?.blocksRun ? dataImport : null;
|
|
7963
|
+
} catch {
|
|
7964
|
+
return null;
|
|
7965
|
+
}
|
|
7966
|
+
}
|
|
7967
|
+
function uploadAgainHint(analysisId) {
|
|
7968
|
+
return `Upload the data with 'diafunc analyze upload ${analysisId} <file>'.`;
|
|
7969
|
+
}
|
|
7970
|
+
async function settle(ctx, answer, data) {
|
|
7971
|
+
let status = {
|
|
7972
|
+
dataImport: data.dataImport ?? null,
|
|
7973
|
+
rowCount: data.rowCount ?? null,
|
|
7974
|
+
columnCount: data.columnCount ?? null
|
|
7975
|
+
};
|
|
7976
|
+
if (isImporting(status.dataImport)) {
|
|
7977
|
+
status = await followImport(ctx, status.dataImport);
|
|
7978
|
+
}
|
|
7979
|
+
const ended = status.dataImport;
|
|
7980
|
+
if (ended) {
|
|
7981
|
+
if (ended.blocksRun) {
|
|
7982
|
+
throw new CliError(ended.message, { hint: uploadAgainHint(ctx.analysisId) });
|
|
7983
|
+
}
|
|
7984
|
+
warn(ended.message);
|
|
7985
|
+
}
|
|
7986
|
+
return { ...status, answer };
|
|
7987
|
+
}
|
|
7988
|
+
async function sendData(ctx, send) {
|
|
7989
|
+
let answer;
|
|
7990
|
+
try {
|
|
7991
|
+
answer = await send();
|
|
7992
|
+
} catch (error) {
|
|
7993
|
+
if (!(error instanceof ApiError) || error.status !== 409) throw error;
|
|
7994
|
+
const running = await importInFlight(ctx.api, ctx.analysisId);
|
|
7995
|
+
if (!running) throw error;
|
|
7996
|
+
if (!ctx.prompter) {
|
|
7997
|
+
throw new CliError(error.message, {
|
|
7998
|
+
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.`
|
|
7999
|
+
});
|
|
8000
|
+
}
|
|
8001
|
+
warn(error.message);
|
|
8002
|
+
const stopping = running.state === "STOPPING";
|
|
8003
|
+
const choice = await ctx.prompter.select({
|
|
8004
|
+
message: "What should happen?",
|
|
8005
|
+
choices: stopping ? [
|
|
8006
|
+
{ name: "Upload as soon as the stopped import has ended", value: "replace" },
|
|
8007
|
+
{ name: "Wait for the stopped import to end and upload nothing", value: "wait" }
|
|
8008
|
+
] : [
|
|
8009
|
+
{ name: "Wait for the running import to finish and keep its data", value: "wait" },
|
|
8010
|
+
{ name: "Stop the running import and upload again", value: "replace" }
|
|
8011
|
+
]
|
|
8012
|
+
});
|
|
8013
|
+
if (choice === "wait") {
|
|
8014
|
+
return settle(ctx, null, { dataImport: running });
|
|
8015
|
+
}
|
|
8016
|
+
await withStatus("Stopping the running import", () => stopImport(ctx.api, ctx.analysisId));
|
|
8017
|
+
answer = await send();
|
|
8018
|
+
}
|
|
8019
|
+
return settle(ctx, answer, answer);
|
|
8020
|
+
}
|
|
8021
|
+
async function queueRun(api, analysisId) {
|
|
8022
|
+
try {
|
|
8023
|
+
return await api.analysis.runAnalysis(analysisId);
|
|
8024
|
+
} catch (error) {
|
|
8025
|
+
if (!(error instanceof ApiError) || error.status !== 409) throw error;
|
|
8026
|
+
const blocking = await importBlockingRun(api, analysisId);
|
|
8027
|
+
if (!blocking) throw error;
|
|
8028
|
+
throw new CliError(error.message, {
|
|
8029
|
+
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)
|
|
8030
|
+
});
|
|
8031
|
+
}
|
|
8032
|
+
}
|
|
8033
|
+
|
|
7607
8034
|
// src/commands/analyze/sources.ts
|
|
7608
8035
|
import * as fs8 from "fs";
|
|
7609
8036
|
import * as path7 from "path";
|
|
7610
|
-
var CAUTIONS = /* @__PURE__ */ new Set([
|
|
8037
|
+
var CAUTIONS = /* @__PURE__ */ new Set([
|
|
8038
|
+
"UNEVEN_COLUMNS",
|
|
8039
|
+
"TYPE_CONFLICT",
|
|
8040
|
+
"SOURCE_WARNING",
|
|
8041
|
+
"LEFT_OUT",
|
|
8042
|
+
"POSSIBLE_KEY",
|
|
8043
|
+
"MANY_TO_MANY",
|
|
8044
|
+
"NO_KEY",
|
|
8045
|
+
"TOO_LARGE",
|
|
8046
|
+
"HINT_REJECTED"
|
|
8047
|
+
]);
|
|
7611
8048
|
function recipeWithChoices(proposal, choices) {
|
|
7612
8049
|
if (proposal.parts.length < 2) return null;
|
|
7613
8050
|
const originColumn = choices.fileColumn ? proposal.originColumn : null;
|
|
7614
8051
|
const dropDuplicates = !choices.keepDuplicates;
|
|
7615
8052
|
if (originColumn === proposal.originColumn && dropDuplicates === proposal.dropDuplicates) return null;
|
|
7616
|
-
return { parts: proposal.parts, originColumn, dropDuplicates };
|
|
8053
|
+
return { parts: proposal.parts, originColumn, dropDuplicates, lookups: proposal.lookups ?? [] };
|
|
8054
|
+
}
|
|
8055
|
+
function labelOf(file) {
|
|
8056
|
+
return path7.basename(file, path7.extname(file)).trim().toLowerCase();
|
|
8057
|
+
}
|
|
8058
|
+
function otherRowsLabel(proposal) {
|
|
8059
|
+
const alternative = (proposal.lookups ?? []).find((lookup) => lookup.alternative)?.alternative;
|
|
8060
|
+
return alternative && alternative.parts.length > 0 ? alternative.parts[0].label : null;
|
|
8061
|
+
}
|
|
8062
|
+
function recipeWithRowsOf(proposal, rowsOf) {
|
|
8063
|
+
const wanted = labelOf(rowsOf);
|
|
8064
|
+
if (proposal.recipe.parts.some((part) => part.label.trim().toLowerCase() === wanted)) return null;
|
|
8065
|
+
const alternative = (proposal.lookups ?? []).find((lookup) => lookup.alternative)?.alternative;
|
|
8066
|
+
if (alternative && alternative.parts.some((part) => part.label.trim().toLowerCase() === wanted)) return alternative;
|
|
8067
|
+
const rows = proposal.recipe.parts.map((part) => part.label).join(", ");
|
|
8068
|
+
throw new CliError(`${rowsOf} cannot carry the rows of this table.`, {
|
|
8069
|
+
exitCode: EXIT_USAGE,
|
|
8070
|
+
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}.`
|
|
8071
|
+
});
|
|
7617
8072
|
}
|
|
7618
8073
|
function planLines(plan) {
|
|
7619
8074
|
const lines = [{
|
|
@@ -7642,8 +8097,15 @@ async function uploadSeveral(api, analysisId, files, choices, human) {
|
|
|
7642
8097
|
for (const file of files) {
|
|
7643
8098
|
await withStatus(`Uploading ${path7.basename(file)}`, () => api.analysis.addSource(analysisId, multipart(file)));
|
|
7644
8099
|
}
|
|
8100
|
+
let other = null;
|
|
7645
8101
|
const plan = await withStatus("Reading the files together", async () => {
|
|
7646
8102
|
const proposal = await api.analysis.planSources(analysisId, null);
|
|
8103
|
+
const exchanged = choices.rowsOf ? recipeWithRowsOf(proposal, choices.rowsOf) : null;
|
|
8104
|
+
if (exchanged) {
|
|
8105
|
+
other = proposal.recipe.parts[0]?.label ?? null;
|
|
8106
|
+
return api.analysis.planSources(analysisId, exchanged);
|
|
8107
|
+
}
|
|
8108
|
+
other = otherRowsLabel(proposal);
|
|
7647
8109
|
const chosen = recipeWithChoices(proposal.recipe, choices);
|
|
7648
8110
|
return chosen ? api.analysis.planSources(analysisId, chosen) : proposal;
|
|
7649
8111
|
});
|
|
@@ -7652,9 +8114,17 @@ async function uploadSeveral(api, analysisId, files, choices, human) {
|
|
|
7652
8114
|
if (line.caution) warn(line.text);
|
|
7653
8115
|
else detail(line.text);
|
|
7654
8116
|
}
|
|
8117
|
+
if (other) {
|
|
8118
|
+
hint(`These files can be read two ways. For one row per row of ${other}, add --rows-of ${other}.`);
|
|
8119
|
+
}
|
|
8120
|
+
}
|
|
8121
|
+
if (choices.planOnly) {
|
|
8122
|
+
if (human) hint("Plan only: the files are stored with the analysis and nothing was built.");
|
|
8123
|
+
return { plan, rowCount: null, columnCount: null };
|
|
7655
8124
|
}
|
|
8125
|
+
const tables = plan.recipe.parts.length + (plan.recipe.lookups ?? []).reduce((sum, lookup) => sum + lookup.parts.length, 0);
|
|
7656
8126
|
return withStatus(
|
|
7657
|
-
`Building one table from ${
|
|
8127
|
+
`Building one table from ${tables} file${tables === 1 ? "" : "s"}`,
|
|
7658
8128
|
() => api.analysis.buildSources(analysisId, plan.recipe)
|
|
7659
8129
|
);
|
|
7660
8130
|
}
|
|
@@ -7677,9 +8147,17 @@ function getOutputFormat15(cmd) {
|
|
|
7677
8147
|
function noInteractiveFlag(cmd) {
|
|
7678
8148
|
return cmd.optsWithGlobals().interactive === false;
|
|
7679
8149
|
}
|
|
7680
|
-
function
|
|
7681
|
-
|
|
7682
|
-
|
|
8150
|
+
function importContext(api, analysisId, cmd, machineReport) {
|
|
8151
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
8152
|
+
const noInteractive = noInteractiveFlag(cmd);
|
|
8153
|
+
return {
|
|
8154
|
+
api,
|
|
8155
|
+
analysisId,
|
|
8156
|
+
outputFormat,
|
|
8157
|
+
live: outputFormat === "human" && !noInteractive && isInteractive(),
|
|
8158
|
+
prompter: canPrompt(outputFormat, noInteractive) ? createInquirerPrompter() : null,
|
|
8159
|
+
machineReport
|
|
8160
|
+
};
|
|
7683
8161
|
}
|
|
7684
8162
|
function collectQuestion(value, previous = []) {
|
|
7685
8163
|
return previous.concat([value]);
|
|
@@ -7698,6 +8176,12 @@ function parseVisibility(value) {
|
|
|
7698
8176
|
function isTerminalState(state) {
|
|
7699
8177
|
return state === "COMPLETED" || state === "FAILED" || state === "CANCELLED";
|
|
7700
8178
|
}
|
|
8179
|
+
function namedDepth(options) {
|
|
8180
|
+
const depth = {};
|
|
8181
|
+
if (options.hours?.trim()) depth.hours = options.hours.trim();
|
|
8182
|
+
if (options.budget?.trim()) depth.budget = options.budget.trim();
|
|
8183
|
+
return depth;
|
|
8184
|
+
}
|
|
7701
8185
|
function budgetHoursOf(hours) {
|
|
7702
8186
|
if (hours === null || hours === void 0) return null;
|
|
7703
8187
|
const parsed = Number(hours);
|
|
@@ -7726,6 +8210,7 @@ async function runAnalysis(files, options, cmd) {
|
|
|
7726
8210
|
const noInteractive = noInteractiveFlag(cmd);
|
|
7727
8211
|
const interactive = canPrompt(outputFormat, noInteractive);
|
|
7728
8212
|
const api = createApiClient();
|
|
8213
|
+
let presetTargets;
|
|
7729
8214
|
if (options.preset) {
|
|
7730
8215
|
const opt = await api.analysis.getPreset(options.preset);
|
|
7731
8216
|
if (!opt.preset) {
|
|
@@ -7734,17 +8219,18 @@ async function runAnalysis(files, options, cmd) {
|
|
|
7734
8219
|
process.exit(EXIT_FAILURE);
|
|
7735
8220
|
}
|
|
7736
8221
|
const p = opt.preset;
|
|
7737
|
-
if (options.targets === void 0 && p.targetKeys.length > 0)
|
|
8222
|
+
if (options.targets === void 0 && p.targetKeys.length > 0) presetTargets = p.targetKeys;
|
|
7738
8223
|
if (options.question === void 0 && p.questions.length > 0) options.question = [...p.questions];
|
|
7739
8224
|
if (options.segment === void 0 && p.segmentKey) options.segment = p.segmentKey;
|
|
7740
|
-
if (options.hours === void 0) options.hours = p.time;
|
|
7741
|
-
if (options.budget === void 0) options.budget = p.budget;
|
|
8225
|
+
if (options.hours === void 0 && p.time?.trim()) options.hours = p.time;
|
|
8226
|
+
if (options.budget === void 0 && p.budget?.trim()) options.budget = p.budget;
|
|
7742
8227
|
}
|
|
7743
|
-
const
|
|
7744
|
-
|
|
8228
|
+
const typedTargets = occurrences(options.targets)?.filter((entry) => entry.trim().length > 0);
|
|
8229
|
+
const targetsGiven = (typedTargets?.length ?? 0) > 0 || (presetTargets?.length ?? 0) > 0;
|
|
8230
|
+
if (!interactive && !targetsGiven) {
|
|
7745
8231
|
usageError(
|
|
7746
8232
|
`Target columns are required, and ${whyNoPrompt(outputFormat, noInteractive)}.`,
|
|
7747
|
-
`Pass --targets <
|
|
8233
|
+
`Pass --targets <columns> or --preset <id>. The names are the column headers of ${files.length > 1 ? "the files" : path8.basename(file)}.`
|
|
7748
8234
|
);
|
|
7749
8235
|
}
|
|
7750
8236
|
const prompter = createInquirerPrompter();
|
|
@@ -7763,11 +8249,12 @@ async function runAnalysis(files, options, cmd) {
|
|
|
7763
8249
|
description: creation.description,
|
|
7764
8250
|
visibility: creation.visibility,
|
|
7765
8251
|
introduction: options.introduction ?? null,
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
8252
|
+
...namedDepth(options),
|
|
8253
|
+
// The targets and the segment are column names, and the columns exist only once the file is
|
|
8254
|
+
// uploaded. They are set below, read against the real header.
|
|
8255
|
+
targets: null,
|
|
7769
8256
|
questions: questionsOf(options.question),
|
|
7770
|
-
segment:
|
|
8257
|
+
segment: null
|
|
7771
8258
|
};
|
|
7772
8259
|
const created = await withStatus(`Creating analysis "${creation.name}"`, () => api.analysis.create(request));
|
|
7773
8260
|
if (isDryRun()) {
|
|
@@ -7775,38 +8262,87 @@ async function runAnalysis(files, options, cmd) {
|
|
|
7775
8262
|
return;
|
|
7776
8263
|
}
|
|
7777
8264
|
detail(`analysisId: ${created.analysisId}`);
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
8265
|
+
const stored = depthOf(created.hours, created.budget);
|
|
8266
|
+
const recipe = { ...request, hours: created.hours, budget: created.budget };
|
|
8267
|
+
if (!interactive) {
|
|
8268
|
+
if (!stored) {
|
|
8269
|
+
throw new CliError(
|
|
8270
|
+
`The platform gave analysis ${created.analysisId} no depth, and ${whyNoPrompt(outputFormat, noInteractive)}.`,
|
|
8271
|
+
{
|
|
8272
|
+
exitCode: EXIT_USAGE,
|
|
8273
|
+
hint: `Pass --hours and --budget. Analysis ${created.analysisId} is created and holds no data yet; remove it with 'diafunc analyze delete ${created.analysisId}'.`
|
|
8274
|
+
}
|
|
8275
|
+
);
|
|
8276
|
+
}
|
|
8277
|
+
detail(`depth: ${depthLabel(stored)}${created.depthPreselection ? " (the account's starting depth)" : ""}`);
|
|
7785
8278
|
}
|
|
7786
|
-
|
|
8279
|
+
await sendData(importContext(api, created.analysisId, cmd, "stream"), () => files.length > 1 ? uploadSeveral(api, created.analysisId, files, stackChoices(options), outputFormat === "human") : withStatus(
|
|
8280
|
+
`Uploading ${path8.basename(file)}`,
|
|
8281
|
+
() => api.analysis.uploadDataMultipart(created.analysisId, multipartFromFile(file))
|
|
8282
|
+
));
|
|
8283
|
+
const columns = await readColumns(api, created.analysisId);
|
|
8284
|
+
const named = namedColumns(
|
|
8285
|
+
created.analysisId,
|
|
8286
|
+
columns,
|
|
8287
|
+
interactive,
|
|
8288
|
+
{ typedTargets, presetTargets, segment: options.segment }
|
|
8289
|
+
);
|
|
8290
|
+
let runHours = created.hours;
|
|
7787
8291
|
if (interactive) {
|
|
7788
|
-
const configuredHours = await configureInteractively(api, prompter, created.analysisId,
|
|
7789
|
-
targets:
|
|
7790
|
-
segment:
|
|
8292
|
+
const configuredHours = await configureInteractively(api, prompter, created.analysisId, recipe, {
|
|
8293
|
+
targets: named.targets,
|
|
8294
|
+
segment: named.segment,
|
|
7791
8295
|
questions: options.question === void 0 ? void 0 : questionsOf(options.question),
|
|
7792
8296
|
hours: options.hours,
|
|
7793
8297
|
budget: options.budget
|
|
7794
|
-
});
|
|
8298
|
+
}, columns);
|
|
7795
8299
|
if (configuredHours === null) return;
|
|
7796
8300
|
runHours = configuredHours;
|
|
8301
|
+
} else {
|
|
8302
|
+
await withStatus("Saving the analysis settings", () => api.analysis.update(created.analysisId, {
|
|
8303
|
+
...recipe,
|
|
8304
|
+
targets: named.targets ?? null,
|
|
8305
|
+
segment: named.segment ?? null
|
|
8306
|
+
}));
|
|
7797
8307
|
}
|
|
7798
|
-
const run = await withStatus("Queuing analysis run", () => api
|
|
8308
|
+
const run = await withStatus("Queuing analysis run", () => queueRun(api, created.analysisId));
|
|
7799
8309
|
detail(`runId: ${run.runId}`);
|
|
7800
8310
|
console.log();
|
|
7801
8311
|
await monitorRun(api, created.analysisId, run.runId, budgetHoursOf(runHours), cmd);
|
|
7802
8312
|
}
|
|
7803
|
-
|
|
7804
|
-
const
|
|
8313
|
+
function namedColumns(analysisId, columns, interactive, given) {
|
|
8314
|
+
const names = columns.map((c) => c.name).filter((name) => name && name.length > 0);
|
|
8315
|
+
const read = (resolve) => {
|
|
8316
|
+
try {
|
|
8317
|
+
return resolve();
|
|
8318
|
+
} catch (error) {
|
|
8319
|
+
if (!(error instanceof CliError)) throw error;
|
|
8320
|
+
if (!interactive) {
|
|
8321
|
+
throw new CliError(error.message, {
|
|
8322
|
+
exitCode: error.exitCode,
|
|
8323
|
+
hint: [
|
|
8324
|
+
error.hint,
|
|
8325
|
+
`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}'.`
|
|
8326
|
+
].filter(Boolean).join("\n ")
|
|
8327
|
+
});
|
|
8328
|
+
}
|
|
8329
|
+
warn(error.message);
|
|
8330
|
+
return void 0;
|
|
8331
|
+
}
|
|
8332
|
+
};
|
|
8333
|
+
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;
|
|
8334
|
+
const segment = given.segment === void 0 || given.segment === "" ? void 0 : read(() => resolveColumnArgument(given.segment, names, analysisId));
|
|
8335
|
+
return { targets, segment };
|
|
8336
|
+
}
|
|
8337
|
+
async function configureInteractively(api, prompter, analysisId, recipe, supplied, knownColumns) {
|
|
8338
|
+
const columns = knownColumns ?? await readColumns(api, analysisId);
|
|
7805
8339
|
const presets = await readPresets(api);
|
|
8340
|
+
const depthAsked = supplied.hours === void 0 || supplied.budget === void 0;
|
|
8341
|
+
const depthDefault = depthAsked ? await readDepthDefault(api, recipe) : null;
|
|
7806
8342
|
console.log();
|
|
7807
|
-
const answers = await promptRunFields(prompter, { columns, presets, supplied });
|
|
8343
|
+
const answers = await promptRunFields(prompter, { columns, presets, supplied, depthDefault });
|
|
7808
8344
|
console.log();
|
|
7809
|
-
await withStatus("Saving the analysis settings", () => api.analysis.update(analysisId, {
|
|
8345
|
+
const saved = await withStatus("Saving the analysis settings", () => api.analysis.update(analysisId, {
|
|
7810
8346
|
...recipe,
|
|
7811
8347
|
targets: answers.targets,
|
|
7812
8348
|
questions: answers.questions,
|
|
@@ -7821,14 +8357,24 @@ async function configureInteractively(api, prompter, analysisId, recipe, supplie
|
|
|
7821
8357
|
description: recipe.description ?? null,
|
|
7822
8358
|
visibility: recipe.visibility ?? "PRIVATE"
|
|
7823
8359
|
};
|
|
7824
|
-
|
|
8360
|
+
const depth = depthOf(saved?.hours, saved?.budget) ?? { hours: answers.hours, budget: answers.budget };
|
|
8361
|
+
for (const line of summaryLines(identity, { ...answers, ...depth })) detail(line);
|
|
7825
8362
|
console.log();
|
|
7826
8363
|
if (!await prompter.confirm({ message: "Start the analysis?", default: true })) {
|
|
7827
8364
|
warn("Not started. The analysis and these settings are saved.");
|
|
7828
8365
|
hint(`Start it later with 'diafunc analyze rerun ${analysisId}'.`);
|
|
7829
8366
|
return null;
|
|
7830
8367
|
}
|
|
7831
|
-
return
|
|
8368
|
+
return depth.hours;
|
|
8369
|
+
}
|
|
8370
|
+
async function readDepthDefault(api, stored) {
|
|
8371
|
+
try {
|
|
8372
|
+
const answer = await api.analysis.getDepthDefault();
|
|
8373
|
+
const depth = depthOf(answer?.hours, answer?.budget);
|
|
8374
|
+
if (depth) return depth;
|
|
8375
|
+
} catch {
|
|
8376
|
+
}
|
|
8377
|
+
return depthOf(stored.hours, stored.budget);
|
|
7832
8378
|
}
|
|
7833
8379
|
async function readColumns(api, analysisId) {
|
|
7834
8380
|
for (let attempt = 0; attempt < COLUMN_READ_ATTEMPTS; attempt++) {
|
|
@@ -7983,8 +8529,11 @@ async function listAnalyses(limit, cmd) {
|
|
|
7983
8529
|
hours: a.hours,
|
|
7984
8530
|
budget: a.budget,
|
|
7985
8531
|
targets: a.targets,
|
|
7986
|
-
|
|
7987
|
-
|
|
8532
|
+
// A reader sees the import where the run state would be: no run can start before the data is
|
|
8533
|
+
// in place. JSON keeps the state as it is and carries the import beside it.
|
|
8534
|
+
latestRunState: outputFormat !== "json" && isImporting(a.dataImport) ? importingLabel(a.dataImport) : a.latestRunState,
|
|
8535
|
+
createdAt: a.createdAt,
|
|
8536
|
+
...outputFormat === "json" && a.dataImport !== void 0 ? { dataImport: a.dataImport } : {}
|
|
7988
8537
|
})), {
|
|
7989
8538
|
format: outputFormat,
|
|
7990
8539
|
columns: [
|
|
@@ -8098,7 +8647,7 @@ async function rerunAnalysis(analysisId, cmd) {
|
|
|
8098
8647
|
);
|
|
8099
8648
|
if (configuredHours === null) return;
|
|
8100
8649
|
}
|
|
8101
|
-
const run = await api
|
|
8650
|
+
const run = await queueRun(api, analysisId);
|
|
8102
8651
|
if (isDryRun()) {
|
|
8103
8652
|
hint("Dry run: no run was queued.");
|
|
8104
8653
|
return;
|
|
@@ -8124,6 +8673,10 @@ async function openAnalysis(analysisId) {
|
|
|
8124
8673
|
hint("The notebook is not available yet. Run the analysis first.");
|
|
8125
8674
|
}
|
|
8126
8675
|
}
|
|
8676
|
+
function typedColumns(given) {
|
|
8677
|
+
const entries = occurrences(given);
|
|
8678
|
+
return entries === void 0 ? null : resolveColumnArguments(entries, []);
|
|
8679
|
+
}
|
|
8127
8680
|
async function createAnalysis(options, cmd) {
|
|
8128
8681
|
const outputFormat = getOutputFormat15(cmd);
|
|
8129
8682
|
const api = createApiClient();
|
|
@@ -8133,9 +8686,8 @@ async function createAnalysis(options, cmd) {
|
|
|
8133
8686
|
description: options.description ?? null,
|
|
8134
8687
|
visibility,
|
|
8135
8688
|
introduction: options.introduction ?? null,
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
targets: parseCsv(options.targets),
|
|
8689
|
+
...namedDepth(options),
|
|
8690
|
+
targets: typedColumns(options.targets),
|
|
8139
8691
|
questions: questionsOf(options.question),
|
|
8140
8692
|
segment: options.segment ?? null
|
|
8141
8693
|
};
|
|
@@ -8169,44 +8721,98 @@ async function patchAndPrint(analysisId, value, handler, successLabel, cmd) {
|
|
|
8169
8721
|
format(updated, { format: outputFormat });
|
|
8170
8722
|
}
|
|
8171
8723
|
}
|
|
8724
|
+
async function columnNames(api, analysisId) {
|
|
8725
|
+
return (await api.analysis.getColumns(analysisId)).map((c) => c.name).filter((name) => name && name.length > 0);
|
|
8726
|
+
}
|
|
8727
|
+
async function patchColumns(analysisId, given, send, successLabel, cmd) {
|
|
8728
|
+
const api = createApiClient();
|
|
8729
|
+
const columns = resolveColumnArguments(occurrences(given) ?? [], await columnNames(api, analysisId), analysisId);
|
|
8730
|
+
await patchAndPrint(analysisId, "", () => send(api, columns), successLabel, cmd);
|
|
8731
|
+
}
|
|
8172
8732
|
function stackChoices(options) {
|
|
8173
|
-
return {
|
|
8733
|
+
return {
|
|
8734
|
+
fileColumn: options.fileColumn !== false,
|
|
8735
|
+
keepDuplicates: options.keepDuplicates === true,
|
|
8736
|
+
rowsOf: options.rowsOf,
|
|
8737
|
+
planOnly: options.planOnly === true
|
|
8738
|
+
};
|
|
8174
8739
|
}
|
|
8175
8740
|
async function uploadData(analysisId, files, options, cmd) {
|
|
8176
8741
|
const api = createApiClient();
|
|
8742
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
8743
|
+
const ctx = importContext(api, analysisId, cmd, "none");
|
|
8177
8744
|
const file = files[0];
|
|
8178
8745
|
if (files.length > 1) {
|
|
8179
8746
|
if (options.url) {
|
|
8180
8747
|
usageError("Provide either files or --url, not both.", "Drop one of the two and run it again.");
|
|
8181
8748
|
}
|
|
8182
|
-
const
|
|
8183
|
-
|
|
8749
|
+
const built = await sendData(
|
|
8750
|
+
ctx,
|
|
8751
|
+
() => uploadSeveral(api, analysisId, files, stackChoices(options), outputFormat === "human")
|
|
8752
|
+
);
|
|
8184
8753
|
if (outputFormat !== "human") {
|
|
8185
|
-
format(
|
|
8754
|
+
format({
|
|
8755
|
+
...built.answer,
|
|
8756
|
+
rowCount: built.rowCount,
|
|
8757
|
+
columnCount: built.columnCount,
|
|
8758
|
+
dataImport: built.dataImport
|
|
8759
|
+
}, { format: outputFormat });
|
|
8186
8760
|
}
|
|
8187
8761
|
return;
|
|
8188
8762
|
}
|
|
8189
8763
|
const dataUrl = options.url;
|
|
8190
|
-
if (dataUrl) {
|
|
8191
|
-
|
|
8192
|
-
|
|
8764
|
+
if (dataUrl && file) {
|
|
8765
|
+
usageError("Provide either a file or --url, not both.", "Drop one of the two and run it again.");
|
|
8766
|
+
}
|
|
8767
|
+
if (!dataUrl) {
|
|
8768
|
+
if (!file) {
|
|
8769
|
+
usageError(
|
|
8770
|
+
"Provide a file path or --url <URL>.",
|
|
8771
|
+
`For example: diafunc analyze upload ${analysisId} data.csv`
|
|
8772
|
+
);
|
|
8193
8773
|
}
|
|
8194
|
-
|
|
8774
|
+
if (!fs9.existsSync(file)) {
|
|
8775
|
+
throw new CliError(`File not found: ${file}`, { exitCode: EXIT_USAGE });
|
|
8776
|
+
}
|
|
8777
|
+
}
|
|
8778
|
+
const uploaded = await sendData(ctx, () => dataUrl ? withStatus(`Uploading from ${dataUrl}`, () => api.analysis.uploadDataUrl(analysisId, { dataUrl })) : withStatus(
|
|
8779
|
+
`Uploading ${path8.basename(file)}`,
|
|
8780
|
+
() => api.analysis.uploadDataMultipart(analysisId, multipartFromFile(file))
|
|
8781
|
+
));
|
|
8782
|
+
if (isDryRun()) {
|
|
8783
|
+
hint("Dry run: nothing was uploaded.");
|
|
8195
8784
|
return;
|
|
8196
8785
|
}
|
|
8197
|
-
if (
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8786
|
+
if (outputFormat !== "human") {
|
|
8787
|
+
format({
|
|
8788
|
+
dataImport: uploaded.dataImport,
|
|
8789
|
+
rowCount: uploaded.rowCount,
|
|
8790
|
+
columnCount: uploaded.columnCount
|
|
8791
|
+
}, { format: outputFormat });
|
|
8202
8792
|
}
|
|
8203
|
-
|
|
8204
|
-
|
|
8793
|
+
}
|
|
8794
|
+
async function stopDataImport(analysisId, cmd) {
|
|
8795
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
8796
|
+
const api = createApiClient();
|
|
8797
|
+
const stopped = await withStatus("Stopping the data import", () => stopImport(api, analysisId));
|
|
8798
|
+
if (isDryRun()) {
|
|
8799
|
+
hint("Dry run: nothing was stopped.");
|
|
8800
|
+
return;
|
|
8205
8801
|
}
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8802
|
+
if (outputFormat !== "human") {
|
|
8803
|
+
format(stopped, { format: outputFormat });
|
|
8804
|
+
return;
|
|
8805
|
+
}
|
|
8806
|
+
if (!stopped.dataImport) {
|
|
8807
|
+
success(`No data import is running for analysis ${analysisId}.`);
|
|
8808
|
+
return;
|
|
8809
|
+
}
|
|
8810
|
+
if (stopped.dataImport.state === "STOPPED") {
|
|
8811
|
+
success(`Stopped the data import of analysis ${analysisId}.`);
|
|
8812
|
+
hint(stopped.dataImport.message);
|
|
8813
|
+
return;
|
|
8814
|
+
}
|
|
8815
|
+
warn(stopped.dataImport.message);
|
|
8210
8816
|
}
|
|
8211
8817
|
async function listColumns(analysisId, cmd) {
|
|
8212
8818
|
const outputFormat = getOutputFormat15(cmd);
|
|
@@ -8297,7 +8903,7 @@ async function savePreset(options, cmd) {
|
|
|
8297
8903
|
const preset = {
|
|
8298
8904
|
presetId: options.id ?? null,
|
|
8299
8905
|
name: options.name,
|
|
8300
|
-
targetKeys:
|
|
8906
|
+
targetKeys: typedColumns(options.targets) ?? [],
|
|
8301
8907
|
questions: questionsOf(options.question) ?? [],
|
|
8302
8908
|
segmentKey: options.segment ?? null,
|
|
8303
8909
|
time: options.hours,
|
|
@@ -8377,9 +8983,11 @@ async function updateTriggerCmd(triggerId, options, cmd) {
|
|
|
8377
8983
|
});
|
|
8378
8984
|
format(trigger, { format: outputFormat });
|
|
8379
8985
|
}
|
|
8986
|
+
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";
|
|
8987
|
+
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
8988
|
function registerAnalyzeCommand(program) {
|
|
8381
8989
|
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
|
|
8990
|
+
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). ${STARTING_DEPTH_RULE}`).option("--budget <credits>", `Credit budget. ${STARTING_DEPTH_RULE}`).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
8991
|
try {
|
|
8384
8992
|
if (files.length === 0) {
|
|
8385
8993
|
analyze.help();
|
|
@@ -8418,14 +9026,14 @@ function registerAnalyzeCommand(program) {
|
|
|
8418
9026
|
handleError(error);
|
|
8419
9027
|
}
|
|
8420
9028
|
});
|
|
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) => {
|
|
9029
|
+
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
9030
|
try {
|
|
8423
9031
|
await rerunAnalysis(id, cmd);
|
|
8424
9032
|
} catch (error) {
|
|
8425
9033
|
reportCommandError(error);
|
|
8426
9034
|
}
|
|
8427
9035
|
});
|
|
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>",
|
|
9036
|
+
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). ${STARTING_DEPTH_RULE}`).option("--budget <credits>", `Credit budget. ${STARTING_DEPTH_RULE}`).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
9037
|
try {
|
|
8430
9038
|
await createAnalysis(options, cmd);
|
|
8431
9039
|
} catch (error) {
|
|
@@ -8493,7 +9101,7 @@ function registerAnalyzeCommand(program) {
|
|
|
8493
9101
|
handleError(error);
|
|
8494
9102
|
}
|
|
8495
9103
|
});
|
|
8496
|
-
analyze.command("hours").description("Set the
|
|
9104
|
+
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
9105
|
try {
|
|
8498
9106
|
await patchAndPrint(
|
|
8499
9107
|
id,
|
|
@@ -8519,13 +9127,12 @@ function registerAnalyzeCommand(program) {
|
|
|
8519
9127
|
handleError(error);
|
|
8520
9128
|
}
|
|
8521
9129
|
});
|
|
8522
|
-
analyze.command("targets").description("Set the target
|
|
9130
|
+
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
9131
|
try {
|
|
8524
|
-
|
|
8525
|
-
await patchAndPrint(
|
|
9132
|
+
await patchColumns(
|
|
8526
9133
|
id,
|
|
8527
|
-
|
|
8528
|
-
(api,
|
|
9134
|
+
given,
|
|
9135
|
+
(api, targets) => api.analysis.patchTargets(id, { targets }),
|
|
8529
9136
|
"Targets",
|
|
8530
9137
|
cmd
|
|
8531
9138
|
);
|
|
@@ -8533,13 +9140,12 @@ function registerAnalyzeCommand(program) {
|
|
|
8533
9140
|
handleError(error);
|
|
8534
9141
|
}
|
|
8535
9142
|
});
|
|
8536
|
-
analyze.command("feature-exclusions").description("Set the columns every fit leaves out as an input (
|
|
9143
|
+
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
9144
|
try {
|
|
8538
|
-
|
|
8539
|
-
await patchAndPrint(
|
|
9145
|
+
await patchColumns(
|
|
8540
9146
|
id,
|
|
8541
|
-
|
|
8542
|
-
(api,
|
|
9147
|
+
given,
|
|
9148
|
+
(api, columns) => api.analysis.patchFeatureExclusions(id, { columns }),
|
|
8543
9149
|
"Columns left out of the fit",
|
|
8544
9150
|
cmd
|
|
8545
9151
|
);
|
|
@@ -8547,13 +9153,12 @@ function registerAnalyzeCommand(program) {
|
|
|
8547
9153
|
handleError(error);
|
|
8548
9154
|
}
|
|
8549
9155
|
});
|
|
8550
|
-
analyze.command("confirmed-inputs").description("Set the columns the owner confirms as known before the outcome (
|
|
9156
|
+
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
9157
|
try {
|
|
8552
|
-
|
|
8553
|
-
await patchAndPrint(
|
|
9158
|
+
await patchColumns(
|
|
8554
9159
|
id,
|
|
8555
|
-
|
|
8556
|
-
(api,
|
|
9160
|
+
given,
|
|
9161
|
+
(api, columns) => api.analysis.patchConfirmedInputs(id, { columns }),
|
|
8557
9162
|
"Columns known before the outcome",
|
|
8558
9163
|
cmd
|
|
8559
9164
|
);
|
|
@@ -8575,12 +9180,14 @@ function registerAnalyzeCommand(program) {
|
|
|
8575
9180
|
handleError(error);
|
|
8576
9181
|
}
|
|
8577
9182
|
});
|
|
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) => {
|
|
9183
|
+
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
9184
|
try {
|
|
9185
|
+
const api = createApiClient();
|
|
9186
|
+
const segment = name === "" ? null : resolveColumnArgument(name, await columnNames(api, id), id);
|
|
8580
9187
|
await patchAndPrint(
|
|
8581
9188
|
id,
|
|
8582
9189
|
name,
|
|
8583
|
-
(
|
|
9190
|
+
() => api.analysis.patchSegment(id, { segment }),
|
|
8584
9191
|
"Segment",
|
|
8585
9192
|
cmd
|
|
8586
9193
|
);
|
|
@@ -8588,9 +9195,16 @@ function registerAnalyzeCommand(program) {
|
|
|
8588
9195
|
handleError(error);
|
|
8589
9196
|
}
|
|
8590
9197
|
});
|
|
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
|
|
9198
|
+
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
9199
|
try {
|
|
8593
9200
|
await uploadData(id, files, options, cmd);
|
|
9201
|
+
} catch (error) {
|
|
9202
|
+
reportCommandError(error);
|
|
9203
|
+
}
|
|
9204
|
+
});
|
|
9205
|
+
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) => {
|
|
9206
|
+
try {
|
|
9207
|
+
await stopDataImport(id, cmd);
|
|
8594
9208
|
} catch (error) {
|
|
8595
9209
|
handleError(error);
|
|
8596
9210
|
}
|
|
@@ -8631,7 +9245,7 @@ function registerAnalyzeCommand(program) {
|
|
|
8631
9245
|
handleError(error);
|
|
8632
9246
|
}
|
|
8633
9247
|
});
|
|
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 <
|
|
9248
|
+
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
9249
|
try {
|
|
8636
9250
|
await savePreset(options, cmd);
|
|
8637
9251
|
} catch (error) {
|
|
@@ -8678,13 +9292,178 @@ function registerAnalyzeCommand(program) {
|
|
|
8678
9292
|
});
|
|
8679
9293
|
}
|
|
8680
9294
|
|
|
8681
|
-
// src/commands/
|
|
8682
|
-
|
|
9295
|
+
// src/commands/public/index.ts
|
|
9296
|
+
var MIN_LIMIT = 1;
|
|
9297
|
+
var MAX_LIMIT = 500;
|
|
8683
9298
|
function getOutputFormat16(cmd) {
|
|
8684
9299
|
const config = loadConfig();
|
|
8685
9300
|
const globalOpts = cmd.optsWithGlobals();
|
|
8686
9301
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
8687
9302
|
}
|
|
9303
|
+
function parseLimit(value) {
|
|
9304
|
+
const limit = Number(value);
|
|
9305
|
+
if (!Number.isInteger(limit) || limit < MIN_LIMIT || limit > MAX_LIMIT) {
|
|
9306
|
+
throw new CliError(
|
|
9307
|
+
`Invalid limit "${value}". Expected a whole number from ${MIN_LIMIT} to ${MAX_LIMIT}.`,
|
|
9308
|
+
{ exitCode: EXIT_USAGE }
|
|
9309
|
+
);
|
|
9310
|
+
}
|
|
9311
|
+
return limit;
|
|
9312
|
+
}
|
|
9313
|
+
var ISO_INSTANT = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2}))?$/;
|
|
9314
|
+
function parseChangedSince(value) {
|
|
9315
|
+
const text2 = value.trim();
|
|
9316
|
+
const instant = ISO_INSTANT.test(text2) ? Date.parse(text2) : Number.NaN;
|
|
9317
|
+
if (!Number.isFinite(instant)) {
|
|
9318
|
+
throw new CliError(
|
|
9319
|
+
`Invalid timestamp "${value}". Expected ISO-8601, such as 2026-10-01 or 2026-10-01T08:30:00Z.`,
|
|
9320
|
+
{ exitCode: EXIT_USAGE }
|
|
9321
|
+
);
|
|
9322
|
+
}
|
|
9323
|
+
return instant;
|
|
9324
|
+
}
|
|
9325
|
+
function instantMillis(value) {
|
|
9326
|
+
if (typeof value === "number") return value;
|
|
9327
|
+
return typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
9328
|
+
}
|
|
9329
|
+
async function readPublicAnalyses(analysis, options) {
|
|
9330
|
+
const analyses = [];
|
|
9331
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9332
|
+
let cursor = options.cursor;
|
|
9333
|
+
for (; ; ) {
|
|
9334
|
+
const page = await analysis.listPublic({ cursor, limit: options.limit });
|
|
9335
|
+
for (const entry of page.analyses ?? []) {
|
|
9336
|
+
if (options.changedSince === void 0 || instantMillis(entry.changedAt) >= options.changedSince) {
|
|
9337
|
+
analyses.push(entry);
|
|
9338
|
+
}
|
|
9339
|
+
}
|
|
9340
|
+
const next = page.nextCursor ?? null;
|
|
9341
|
+
if (!options.all || next === null) return { analyses, nextCursor: next };
|
|
9342
|
+
if (seen.has(next)) {
|
|
9343
|
+
throw new CliError(`The platform returned the cursor "${next}" twice; stopped after ${analyses.length} analyses.`);
|
|
9344
|
+
}
|
|
9345
|
+
seen.add(next);
|
|
9346
|
+
cursor = next;
|
|
9347
|
+
}
|
|
9348
|
+
}
|
|
9349
|
+
async function listPublicAnalyses(options, cmd) {
|
|
9350
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
9351
|
+
const limit = parseLimit(options.limit);
|
|
9352
|
+
const changedSince = options.changedSince === void 0 ? void 0 : parseChangedSince(options.changedSince);
|
|
9353
|
+
const api = createApiClient();
|
|
9354
|
+
const listing = await readPublicAnalyses(api.analysis, {
|
|
9355
|
+
limit,
|
|
9356
|
+
cursor: options.cursor,
|
|
9357
|
+
all: options.all,
|
|
9358
|
+
changedSince
|
|
9359
|
+
});
|
|
9360
|
+
if (outputFormat === "json") {
|
|
9361
|
+
format(listing, { format: outputFormat });
|
|
9362
|
+
return;
|
|
9363
|
+
}
|
|
9364
|
+
if (listing.analyses.length === 0 && outputFormat === "human") {
|
|
9365
|
+
empty("public analyses");
|
|
9366
|
+
} else {
|
|
9367
|
+
format(listing.analyses, {
|
|
9368
|
+
format: outputFormat,
|
|
9369
|
+
columns: [
|
|
9370
|
+
{ key: "analysisId", kind: "id" },
|
|
9371
|
+
{ key: "projectId", kind: "id" },
|
|
9372
|
+
{ key: "publishedAt", header: "published", kind: "date" },
|
|
9373
|
+
{ key: "changedAt", header: "changed", kind: "date" }
|
|
9374
|
+
]
|
|
9375
|
+
});
|
|
9376
|
+
}
|
|
9377
|
+
if (listing.nextCursor !== null) {
|
|
9378
|
+
hint(`More public analyses follow. Continue with --cursor ${listing.nextCursor}, or pass --all.`);
|
|
9379
|
+
}
|
|
9380
|
+
}
|
|
9381
|
+
function newestRunRecord(run) {
|
|
9382
|
+
return {
|
|
9383
|
+
runId: run.runId,
|
|
9384
|
+
state: run.state,
|
|
9385
|
+
phase: runPhaseCell(run),
|
|
9386
|
+
submittedAt: run.submittedAt,
|
|
9387
|
+
startedAt: run.startedAt,
|
|
9388
|
+
endedAt: run.endedAt
|
|
9389
|
+
};
|
|
9390
|
+
}
|
|
9391
|
+
async function showPublicAnalysis(analysisId, cmd) {
|
|
9392
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
9393
|
+
const api = createApiClient();
|
|
9394
|
+
const result = await api.analysis.get(analysisId);
|
|
9395
|
+
if (!result?.analysis) {
|
|
9396
|
+
throw new CliError(`No public analysis "${analysisId}".`, {
|
|
9397
|
+
hint: `List the public analyses with 'diafunc public list'.`
|
|
9398
|
+
});
|
|
9399
|
+
}
|
|
9400
|
+
const runs = await api.analysis.getRunsForAnalysis(analysisId, 1);
|
|
9401
|
+
const newestRun = runs?.[0] ?? null;
|
|
9402
|
+
if (outputFormat === "json") {
|
|
9403
|
+
format({ analysis: result.analysis, newestRun }, { format: outputFormat });
|
|
9404
|
+
return;
|
|
9405
|
+
}
|
|
9406
|
+
if (outputFormat === "table") {
|
|
9407
|
+
format({
|
|
9408
|
+
...result.analysis,
|
|
9409
|
+
newestRunId: newestRun?.runId ?? null,
|
|
9410
|
+
newestRunState: newestRun?.state ?? null,
|
|
9411
|
+
newestRunSubmittedAt: newestRun?.submittedAt ?? null,
|
|
9412
|
+
newestRunStartedAt: newestRun?.startedAt ?? null,
|
|
9413
|
+
newestRunEndedAt: newestRun?.endedAt ?? null
|
|
9414
|
+
}, { format: outputFormat });
|
|
9415
|
+
return;
|
|
9416
|
+
}
|
|
9417
|
+
const details = analysisDetails(result.analysis, resolveEndpoint(loadConfig()));
|
|
9418
|
+
format(details.data, { format: outputFormat, columns: details.columns });
|
|
9419
|
+
heading("Newest run");
|
|
9420
|
+
if (!newestRun) {
|
|
9421
|
+
empty("runs");
|
|
9422
|
+
return;
|
|
9423
|
+
}
|
|
9424
|
+
format(newestRunRecord(newestRun), {
|
|
9425
|
+
format: outputFormat,
|
|
9426
|
+
columns: [
|
|
9427
|
+
{ key: "runId", header: "Run ID", kind: "id" },
|
|
9428
|
+
{ key: "state", header: "State", kind: "state" },
|
|
9429
|
+
{ key: "phase", header: "Phase" },
|
|
9430
|
+
{ key: "submittedAt", header: "Submitted", kind: "date" },
|
|
9431
|
+
{ key: "startedAt", header: "Started", kind: "date" },
|
|
9432
|
+
{ key: "endedAt", header: "Ended", kind: "date" }
|
|
9433
|
+
]
|
|
9434
|
+
});
|
|
9435
|
+
}
|
|
9436
|
+
function registerPublicCommands(program) {
|
|
9437
|
+
const pub = program.command("public").description("Read the analyses their owners made public (no sign-in needed)").addHelpText("after", `
|
|
9438
|
+
Examples:
|
|
9439
|
+
$ diafunc public list the first 100 public analyses
|
|
9440
|
+
$ diafunc public list --all --output json every one of them, for a script
|
|
9441
|
+
$ diafunc public list --all --changed-since 2026-10-01 only those changed since that day
|
|
9442
|
+
$ diafunc public show <analysisId> one analysis and its newest run
|
|
9443
|
+
`);
|
|
9444
|
+
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) => {
|
|
9445
|
+
try {
|
|
9446
|
+
await listPublicAnalyses(options, cmd);
|
|
9447
|
+
} catch (error) {
|
|
9448
|
+
handleError(error);
|
|
9449
|
+
}
|
|
9450
|
+
});
|
|
9451
|
+
pub.command("show").description("Show a public analysis and its newest run").argument("<analysisId>", "Analysis ID").action(async (analysisId, _options, cmd) => {
|
|
9452
|
+
try {
|
|
9453
|
+
await showPublicAnalysis(analysisId, cmd);
|
|
9454
|
+
} catch (error) {
|
|
9455
|
+
handleError(error);
|
|
9456
|
+
}
|
|
9457
|
+
});
|
|
9458
|
+
}
|
|
9459
|
+
|
|
9460
|
+
// src/commands/data-sources/index.ts
|
|
9461
|
+
import chalk27 from "chalk";
|
|
9462
|
+
function getOutputFormat17(cmd) {
|
|
9463
|
+
const config = loadConfig();
|
|
9464
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
9465
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
9466
|
+
}
|
|
8688
9467
|
function parseConfigPairs(pairs) {
|
|
8689
9468
|
const out = {};
|
|
8690
9469
|
if (!pairs) return out;
|
|
@@ -8780,7 +9559,7 @@ function resolveProjectId(cmd) {
|
|
|
8780
9559
|
return resolved;
|
|
8781
9560
|
}
|
|
8782
9561
|
async function listDataSources(projectId, cmd) {
|
|
8783
|
-
const outputFormat =
|
|
9562
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8784
9563
|
const api = createApiClient();
|
|
8785
9564
|
const sources = await api.storage.listDataSources(projectId);
|
|
8786
9565
|
if (outputFormat === "human" && sources.length === 0) {
|
|
@@ -8801,13 +9580,13 @@ async function listDataSources(projectId, cmd) {
|
|
|
8801
9580
|
});
|
|
8802
9581
|
}
|
|
8803
9582
|
async function getDataSource(id, cmd) {
|
|
8804
|
-
const outputFormat =
|
|
9583
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8805
9584
|
const api = createApiClient();
|
|
8806
9585
|
const ds = await api.storage.getDataSource(id);
|
|
8807
9586
|
format(ds, { format: outputFormat });
|
|
8808
9587
|
}
|
|
8809
9588
|
async function showDashboard(projectId, cmd) {
|
|
8810
|
-
const outputFormat =
|
|
9589
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8811
9590
|
const api = createApiClient();
|
|
8812
9591
|
const dashboard = await api.storage.getDataSourceDashboard(projectId);
|
|
8813
9592
|
if (outputFormat !== "human") {
|
|
@@ -8815,7 +9594,7 @@ async function showDashboard(projectId, cmd) {
|
|
|
8815
9594
|
return;
|
|
8816
9595
|
}
|
|
8817
9596
|
const r = dashboard.rollup;
|
|
8818
|
-
let line =
|
|
9597
|
+
let line = chalk27.bold(`DataSources in ${projectId}: `) + `${r.totalSources} total, ${r.scheduledSources} scheduled, ${r.sourcesWithRecentFailure} failing recently`;
|
|
8819
9598
|
if (r.lastActivityAt) line += `, last activity ${r.lastActivityAt}`;
|
|
8820
9599
|
console.log(line);
|
|
8821
9600
|
if (dashboard.sources.length === 0) {
|
|
@@ -8838,7 +9617,7 @@ async function showDashboard(projectId, cmd) {
|
|
|
8838
9617
|
});
|
|
8839
9618
|
}
|
|
8840
9619
|
async function createDataSource(options, cmd) {
|
|
8841
|
-
const outputFormat =
|
|
9620
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8842
9621
|
const api = createApiClient();
|
|
8843
9622
|
const request = {
|
|
8844
9623
|
projectId: options.projectId,
|
|
@@ -8853,14 +9632,14 @@ async function createDataSource(options, cmd) {
|
|
|
8853
9632
|
const ds = await api.storage.createDataSource(request);
|
|
8854
9633
|
if (outputFormat === "human") {
|
|
8855
9634
|
success(`Created data source ${ds.id}`);
|
|
8856
|
-
console.log(
|
|
8857
|
-
if (ds.lastRunError) console.log(
|
|
9635
|
+
console.log(chalk27.dim(` Last run: ${ds.lastRunStatus ?? "\u2014"}`));
|
|
9636
|
+
if (ds.lastRunError) console.log(chalk27.dim(` Error: ${ds.lastRunError}`));
|
|
8858
9637
|
} else {
|
|
8859
9638
|
format(ds, { format: outputFormat });
|
|
8860
9639
|
}
|
|
8861
9640
|
}
|
|
8862
9641
|
async function updateDataSource(id, options, cmd) {
|
|
8863
|
-
const outputFormat =
|
|
9642
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8864
9643
|
if (options.name === void 0 && options.type === void 0 && (!options.config || options.config.length === 0) && options.scheduleCron === void 0 && !options.clearSchedule) {
|
|
8865
9644
|
throw new Error("Provide at least one of --name, --type, --config, --schedule-cron, or --clear-schedule.");
|
|
8866
9645
|
}
|
|
@@ -8895,18 +9674,18 @@ async function deleteDataSource(id) {
|
|
|
8895
9674
|
success(`Deleted data source ${id}`);
|
|
8896
9675
|
}
|
|
8897
9676
|
async function refreshDataSource(id, cmd) {
|
|
8898
|
-
const outputFormat =
|
|
9677
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8899
9678
|
const api = createApiClient();
|
|
8900
9679
|
const run = await api.storage.refreshDataSource(id);
|
|
8901
9680
|
if (outputFormat === "human") {
|
|
8902
9681
|
success(`Refresh queued: run ${run.runId}, status ${run.status}.`);
|
|
8903
|
-
if (run.errorMessage) console.log(
|
|
9682
|
+
if (run.errorMessage) console.log(chalk27.red(` Error: ${run.errorMessage}`));
|
|
8904
9683
|
} else {
|
|
8905
9684
|
format(run, { format: outputFormat });
|
|
8906
9685
|
}
|
|
8907
9686
|
}
|
|
8908
9687
|
async function listRuns2(id, limit, cmd) {
|
|
8909
|
-
const outputFormat =
|
|
9688
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8910
9689
|
const api = createApiClient();
|
|
8911
9690
|
const runs = await api.storage.listDataSourceRuns(id, limit);
|
|
8912
9691
|
if (outputFormat === "human" && runs.length === 0) {
|
|
@@ -8928,13 +9707,13 @@ async function listRuns2(id, limit, cmd) {
|
|
|
8928
9707
|
});
|
|
8929
9708
|
}
|
|
8930
9709
|
async function getRun(id, runId, cmd) {
|
|
8931
|
-
const outputFormat =
|
|
9710
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8932
9711
|
const api = createApiClient();
|
|
8933
9712
|
const run = await api.storage.getDataSourceRun(id, runId);
|
|
8934
9713
|
format(run, { format: outputFormat });
|
|
8935
9714
|
}
|
|
8936
9715
|
async function listConnectorTypes(cmd) {
|
|
8937
|
-
const outputFormat =
|
|
9716
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8938
9717
|
const api = createApiClient();
|
|
8939
9718
|
const types = await api.storage.listDataSourceConnectorTypes();
|
|
8940
9719
|
if (outputFormat === "human") {
|
|
@@ -9027,8 +9806,8 @@ Examples:
|
|
|
9027
9806
|
}
|
|
9028
9807
|
|
|
9029
9808
|
// src/commands/table-exporters/index.ts
|
|
9030
|
-
import
|
|
9031
|
-
function
|
|
9809
|
+
import chalk28 from "chalk";
|
|
9810
|
+
function getOutputFormat18(cmd) {
|
|
9032
9811
|
const config = loadConfig();
|
|
9033
9812
|
const globalOpts = cmd.optsWithGlobals();
|
|
9034
9813
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9037,7 +9816,7 @@ function registerTableExportersCommands(program) {
|
|
|
9037
9816
|
const exporters = program.command("table-exporters").description("Manage user-defined exporters (UDE); admin only");
|
|
9038
9817
|
exporters.command("list").description("List all registered user-defined exporters").action(async (_options, cmd) => {
|
|
9039
9818
|
try {
|
|
9040
|
-
const outputFormat =
|
|
9819
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
9041
9820
|
const api = createApiClient();
|
|
9042
9821
|
const list = await api.storage.listUserDefinedExporters();
|
|
9043
9822
|
if (outputFormat === "json") {
|
|
@@ -9058,14 +9837,14 @@ function registerTableExportersCommands(program) {
|
|
|
9058
9837
|
format: outputFormat,
|
|
9059
9838
|
columns: ["id", "name", "format", "extension", "mimeType", "priority", "function", "createdBy"]
|
|
9060
9839
|
});
|
|
9061
|
-
console.log(
|
|
9840
|
+
console.log(chalk28.dim(`${list.length} exporter(s)`));
|
|
9062
9841
|
} catch (error) {
|
|
9063
9842
|
handleError(error);
|
|
9064
9843
|
}
|
|
9065
9844
|
});
|
|
9066
9845
|
exporters.command("get").description("Show a single user-defined exporter by id").argument("<id>", "Exporter id").action(async (id, _options, cmd) => {
|
|
9067
9846
|
try {
|
|
9068
|
-
const outputFormat =
|
|
9847
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
9069
9848
|
const api = createApiClient();
|
|
9070
9849
|
const list = await api.storage.listUserDefinedExporters();
|
|
9071
9850
|
const exporter = list.find((e) => e.id === id);
|
|
@@ -9080,7 +9859,7 @@ function registerTableExportersCommands(program) {
|
|
|
9080
9859
|
});
|
|
9081
9860
|
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
9861
|
try {
|
|
9083
|
-
const outputFormat =
|
|
9862
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
9084
9863
|
const api = createApiClient();
|
|
9085
9864
|
const payload = {
|
|
9086
9865
|
name: options.name,
|
|
@@ -9116,9 +9895,9 @@ function registerTableExportersCommands(program) {
|
|
|
9116
9895
|
}
|
|
9117
9896
|
|
|
9118
9897
|
// src/commands/skeleton/index.ts
|
|
9119
|
-
import
|
|
9898
|
+
import chalk29 from "chalk";
|
|
9120
9899
|
import * as fs10 from "fs";
|
|
9121
|
-
function
|
|
9900
|
+
function getOutputFormat19(cmd) {
|
|
9122
9901
|
const config = loadConfig();
|
|
9123
9902
|
const globalOpts = cmd.optsWithGlobals();
|
|
9124
9903
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9167,7 +9946,7 @@ function skeletonTableRow(s) {
|
|
|
9167
9946
|
};
|
|
9168
9947
|
}
|
|
9169
9948
|
async function createSkeleton(options, cmd) {
|
|
9170
|
-
const outputFormat =
|
|
9949
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9171
9950
|
const projectId = resolveProjectId2(cmd);
|
|
9172
9951
|
const template = resolveTemplate(options.template);
|
|
9173
9952
|
const weight = parseWeight(options.weight);
|
|
@@ -9183,16 +9962,16 @@ async function createSkeleton(options, cmd) {
|
|
|
9183
9962
|
const skeleton = await api.storage.createSkeleton(request);
|
|
9184
9963
|
if (outputFormat === "human") {
|
|
9185
9964
|
success(`Created skeleton ${skeleton.id}`);
|
|
9186
|
-
console.log(
|
|
9187
|
-
console.log(
|
|
9188
|
-
console.log(
|
|
9189
|
-
console.log(
|
|
9965
|
+
console.log(chalk29.dim(` name: ${skeleton.name}`));
|
|
9966
|
+
console.log(chalk29.dim(` template: ${skeleton.template}`));
|
|
9967
|
+
console.log(chalk29.dim(` paramCount: ${skeleton.paramCount}`));
|
|
9968
|
+
console.log(chalk29.dim(` weight: ${skeleton.weight}`));
|
|
9190
9969
|
} else {
|
|
9191
9970
|
format(skeleton, { format: outputFormat });
|
|
9192
9971
|
}
|
|
9193
9972
|
}
|
|
9194
9973
|
async function listSkeletons(cmd) {
|
|
9195
|
-
const outputFormat =
|
|
9974
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9196
9975
|
const projectId = resolveProjectId2(cmd);
|
|
9197
9976
|
const api = createApiClient();
|
|
9198
9977
|
const skeletons = await api.storage.listSkeletons(projectId);
|
|
@@ -9206,13 +9985,13 @@ async function listSkeletons(cmd) {
|
|
|
9206
9985
|
});
|
|
9207
9986
|
}
|
|
9208
9987
|
async function getSkeleton(id, cmd) {
|
|
9209
|
-
const outputFormat =
|
|
9988
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9210
9989
|
const api = createApiClient();
|
|
9211
9990
|
const skeleton = await api.storage.getSkeleton(id);
|
|
9212
9991
|
format(skeleton, { format: outputFormat });
|
|
9213
9992
|
}
|
|
9214
9993
|
async function updateSkeleton(id, options, cmd) {
|
|
9215
|
-
const outputFormat =
|
|
9994
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9216
9995
|
if (options.name === void 0 && options.template === void 0 && options.weight === void 0) {
|
|
9217
9996
|
throw new Error("Provide at least one of --name, --template, --weight.");
|
|
9218
9997
|
}
|
|
@@ -9225,10 +10004,10 @@ async function updateSkeleton(id, options, cmd) {
|
|
|
9225
10004
|
const skeleton = await api.storage.updateSkeleton(id, request);
|
|
9226
10005
|
if (outputFormat === "human") {
|
|
9227
10006
|
success(`Updated skeleton ${skeleton.id}`);
|
|
9228
|
-
console.log(
|
|
9229
|
-
console.log(
|
|
9230
|
-
console.log(
|
|
9231
|
-
console.log(
|
|
10007
|
+
console.log(chalk29.dim(` name: ${skeleton.name}`));
|
|
10008
|
+
console.log(chalk29.dim(` template: ${skeleton.template}`));
|
|
10009
|
+
console.log(chalk29.dim(` paramCount: ${skeleton.paramCount}`));
|
|
10010
|
+
console.log(chalk29.dim(` weight: ${skeleton.weight}`));
|
|
9232
10011
|
} else {
|
|
9233
10012
|
format(skeleton, { format: outputFormat });
|
|
9234
10013
|
}
|
|
@@ -9548,7 +10327,7 @@ function registerCompletionCommand(program) {
|
|
|
9548
10327
|
}
|
|
9549
10328
|
|
|
9550
10329
|
// src/commands/whoami/index.ts
|
|
9551
|
-
import
|
|
10330
|
+
import chalk30 from "chalk";
|
|
9552
10331
|
function registerWhoamiCommand(program) {
|
|
9553
10332
|
program.command("whoami").description("Show the currently authenticated user").action(async (_options, cmd) => {
|
|
9554
10333
|
try {
|
|
@@ -9558,8 +10337,8 @@ function registerWhoamiCommand(program) {
|
|
|
9558
10337
|
const api = createApiClient();
|
|
9559
10338
|
const user = await api.admin.getMyUser();
|
|
9560
10339
|
if (outputFormat === "human") {
|
|
9561
|
-
console.log(
|
|
9562
|
-
console.log(
|
|
10340
|
+
console.log(chalk30.bold(user.name) + chalk30.dim(` <${user.email}>`));
|
|
10341
|
+
console.log(chalk30.dim(` Role: ${user.role} \xB7 Remaining credits: ${user.remainingCredits} \xB7 Profile: ${config.currentProfile}`));
|
|
9563
10342
|
} else {
|
|
9564
10343
|
format(user, { format: outputFormat });
|
|
9565
10344
|
}
|
|
@@ -9570,8 +10349,8 @@ function registerWhoamiCommand(program) {
|
|
|
9570
10349
|
}
|
|
9571
10350
|
|
|
9572
10351
|
// src/commands/utilization/index.ts
|
|
9573
|
-
import
|
|
9574
|
-
function
|
|
10352
|
+
import chalk31 from "chalk";
|
|
10353
|
+
function getOutputFormat20(cmd) {
|
|
9575
10354
|
const config = loadConfig();
|
|
9576
10355
|
const globalOpts = cmd.optsWithGlobals();
|
|
9577
10356
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9587,19 +10366,19 @@ function windowLabel(u) {
|
|
|
9587
10366
|
}
|
|
9588
10367
|
function printUtilizationHuman(u, label) {
|
|
9589
10368
|
const when2 = windowLabel(u);
|
|
9590
|
-
console.log(label ?
|
|
10369
|
+
console.log(label ? chalk31.bold(label) + " " + chalk31.dim(when2) : chalk31.bold(when2));
|
|
9591
10370
|
if (u.types.length === 0) {
|
|
9592
|
-
console.log(
|
|
10371
|
+
console.log(chalk31.dim(" (no usage)"));
|
|
9593
10372
|
return;
|
|
9594
10373
|
}
|
|
9595
10374
|
const types = [...u.types].sort((a, b) => b.credits - a.credits);
|
|
9596
10375
|
const width = Math.max(...types.map((t) => t.type.length));
|
|
9597
10376
|
for (const t of types) {
|
|
9598
|
-
const line = ` ${t.type.padEnd(width)} ${formatNumber(t.quantity).padStart(12)} ${
|
|
9599
|
-
console.log(t.credits === 0 ?
|
|
10377
|
+
const line = ` ${t.type.padEnd(width)} ${formatNumber(t.quantity).padStart(12)} ${chalk31.dim("credits")} ${t.credits.toFixed(2).padStart(10)}`;
|
|
10378
|
+
console.log(t.credits === 0 ? chalk31.dim(line) : line);
|
|
9600
10379
|
}
|
|
9601
10380
|
const total = u.totalCredits ?? u.types.reduce((s, t) => s + t.credits, 0);
|
|
9602
|
-
console.log(
|
|
10381
|
+
console.log(chalk31.bold(` ${"Total".padEnd(width)} ${" ".repeat(12)} ${chalk31.dim("credits")} ${total.toFixed(2).padStart(10)}`));
|
|
9603
10382
|
}
|
|
9604
10383
|
function formatDailyHistory(history) {
|
|
9605
10384
|
const spentOn = (u) => u.dailyCredits ?? u.types.reduce((sum, t) => sum + (t.dailyCredits ?? 0), 0);
|
|
@@ -9616,14 +10395,14 @@ function formatDailyHistory(history) {
|
|
|
9616
10395
|
for (const u of history) {
|
|
9617
10396
|
const spent = spentOn(u);
|
|
9618
10397
|
total += spent;
|
|
9619
|
-
const line = `${windowLabel(u).padEnd(width)} ${amount(spent)} ${
|
|
9620
|
-
lines.push(spent > 0 ?
|
|
10398
|
+
const line = `${windowLabel(u).padEnd(width)} ${amount(spent)} ${chalk31.dim("credits")}`;
|
|
10399
|
+
lines.push(spent > 0 ? chalk31.bold(line) : chalk31.dim(line));
|
|
9621
10400
|
for (const t of costly(u)) {
|
|
9622
10401
|
lines.push(` ${t.type.padEnd(width - 2)} ${amount(t.dailyCredits ?? 0)}`);
|
|
9623
10402
|
}
|
|
9624
10403
|
}
|
|
9625
10404
|
lines.push("");
|
|
9626
|
-
lines.push(
|
|
10405
|
+
lines.push(chalk31.bold(`${totalLabel.padEnd(width)} ${amount(total)} ${chalk31.dim("credits")}`));
|
|
9627
10406
|
return lines;
|
|
9628
10407
|
}
|
|
9629
10408
|
function registerUtilizationCommand(program) {
|
|
@@ -9636,7 +10415,7 @@ Examples:
|
|
|
9636
10415
|
`);
|
|
9637
10416
|
util.command("actual", { isDefault: true }).description("Show current utilization (default subcommand)").action(async (_options, cmd) => {
|
|
9638
10417
|
try {
|
|
9639
|
-
const outputFormat =
|
|
10418
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9640
10419
|
const api = createApiClient();
|
|
9641
10420
|
const utilization = await api.admin.getActualUtilization();
|
|
9642
10421
|
if (outputFormat === "human") {
|
|
@@ -9650,7 +10429,7 @@ Examples:
|
|
|
9650
10429
|
});
|
|
9651
10430
|
util.command("history").description("Show what each day of the billing cycle cost").action(async (_options, cmd) => {
|
|
9652
10431
|
try {
|
|
9653
|
-
const outputFormat =
|
|
10432
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9654
10433
|
const api = createApiClient();
|
|
9655
10434
|
const history = await api.admin.getUtilizationHistory();
|
|
9656
10435
|
if (outputFormat === "human") {
|
|
@@ -9671,7 +10450,7 @@ Examples:
|
|
|
9671
10450
|
}
|
|
9672
10451
|
|
|
9673
10452
|
// src/commands/entity-branch/index.ts
|
|
9674
|
-
function
|
|
10453
|
+
function getOutputFormat21(cmd) {
|
|
9675
10454
|
const config = loadConfig();
|
|
9676
10455
|
const globalOpts = cmd.optsWithGlobals();
|
|
9677
10456
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9684,7 +10463,7 @@ function registerEntityBranchCommands(program) {
|
|
|
9684
10463
|
const eb = program.command("entity-branch").description("Manage entity branches (parallel versions of a single entity)");
|
|
9685
10464
|
eb.command("list").description("List branches of an entity").argument("<ref>", "Entity reference (projectId/branch/entityId)").action(async (ref, _options, cmd) => {
|
|
9686
10465
|
try {
|
|
9687
|
-
const outputFormat =
|
|
10466
|
+
const outputFormat = getOutputFormat21(cmd);
|
|
9688
10467
|
const overrides = getOverrides11(cmd);
|
|
9689
10468
|
const resolved = parseEntityReference(ref, overrides);
|
|
9690
10469
|
const api = createApiClient();
|
|
@@ -9736,7 +10515,7 @@ function forReader(subscription) {
|
|
|
9736
10515
|
Object.entries(subscription).filter(([key]) => !BILLING_INTERNALS.has(key))
|
|
9737
10516
|
);
|
|
9738
10517
|
}
|
|
9739
|
-
function
|
|
10518
|
+
function getOutputFormat22(cmd) {
|
|
9740
10519
|
const config = loadConfig();
|
|
9741
10520
|
const globalOpts = cmd.optsWithGlobals();
|
|
9742
10521
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9750,7 +10529,7 @@ Examples:
|
|
|
9750
10529
|
sub.command("current", { isDefault: true }).description("Show the current subscription").action(async (_options, cmd) => {
|
|
9751
10530
|
try {
|
|
9752
10531
|
const api = createApiClient();
|
|
9753
|
-
const outputFormat =
|
|
10532
|
+
const outputFormat = getOutputFormat22(cmd);
|
|
9754
10533
|
const s = await api.admin.getCurrentSubscription();
|
|
9755
10534
|
format(outputFormat === "human" ? forReader(s) : s, { format: outputFormat });
|
|
9756
10535
|
} catch (error) {
|
|
@@ -9760,7 +10539,7 @@ Examples:
|
|
|
9760
10539
|
sub.command("next").description("Show the next (upcoming) subscription").action(async (_options, cmd) => {
|
|
9761
10540
|
try {
|
|
9762
10541
|
const api = createApiClient();
|
|
9763
|
-
const outputFormat =
|
|
10542
|
+
const outputFormat = getOutputFormat22(cmd);
|
|
9764
10543
|
const s = await api.admin.getNextSubscription();
|
|
9765
10544
|
format(outputFormat === "human" ? forReader(s) : s, { format: outputFormat });
|
|
9766
10545
|
} catch (error) {
|
|
@@ -9771,7 +10550,7 @@ Examples:
|
|
|
9771
10550
|
try {
|
|
9772
10551
|
const api = createApiClient();
|
|
9773
10552
|
const plans = await api.admin.getSubscriptionPlans(subscriptionToken);
|
|
9774
|
-
format(plans, { format:
|
|
10553
|
+
format(plans, { format: getOutputFormat22(cmd) });
|
|
9775
10554
|
} catch (error) {
|
|
9776
10555
|
handleError(error);
|
|
9777
10556
|
}
|
|
@@ -9780,7 +10559,7 @@ Examples:
|
|
|
9780
10559
|
|
|
9781
10560
|
// src/commands/invoice/index.ts
|
|
9782
10561
|
import * as fs11 from "fs";
|
|
9783
|
-
function
|
|
10562
|
+
function getOutputFormat23(cmd) {
|
|
9784
10563
|
const config = loadConfig();
|
|
9785
10564
|
const globalOpts = cmd.optsWithGlobals();
|
|
9786
10565
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9797,7 +10576,7 @@ Examples:
|
|
|
9797
10576
|
const api = createApiClient();
|
|
9798
10577
|
const invoices = await api.admin.getInvoices();
|
|
9799
10578
|
format(invoices, {
|
|
9800
|
-
format:
|
|
10579
|
+
format: getOutputFormat23(cmd),
|
|
9801
10580
|
columns: [
|
|
9802
10581
|
{ key: "invoiceNumber", header: "number" },
|
|
9803
10582
|
{ key: "issued", kind: "date" },
|
|
@@ -9826,7 +10605,7 @@ Examples:
|
|
|
9826
10605
|
}
|
|
9827
10606
|
|
|
9828
10607
|
// src/commands/shell/index.ts
|
|
9829
|
-
import
|
|
10608
|
+
import chalk32 from "chalk";
|
|
9830
10609
|
import * as fs12 from "fs";
|
|
9831
10610
|
import * as os3 from "os";
|
|
9832
10611
|
import * as path9 from "path";
|
|
@@ -9892,21 +10671,21 @@ async function evaluate(api, fnRef, language, sourceCode) {
|
|
|
9892
10671
|
}, false);
|
|
9893
10672
|
if (result.outputs?.length) {
|
|
9894
10673
|
for (const out of result.outputs) {
|
|
9895
|
-
console.log(
|
|
10674
|
+
console.log(chalk32.dim(` [${out.type}]`) + " " + out.output);
|
|
9896
10675
|
}
|
|
9897
10676
|
}
|
|
9898
10677
|
if (result.successful) {
|
|
9899
10678
|
if (result.result) {
|
|
9900
|
-
console.log(
|
|
10679
|
+
console.log(chalk32.green("=>") + " " + result.result);
|
|
9901
10680
|
} else {
|
|
9902
|
-
console.log(
|
|
10681
|
+
console.log(chalk32.dim("=> (no value)"));
|
|
9903
10682
|
}
|
|
9904
10683
|
const duration = result.completed - result.started;
|
|
9905
|
-
console.log(
|
|
10684
|
+
console.log(chalk32.dim(` [${duration}ms \xB7 ${evaluationId}]`));
|
|
9906
10685
|
} else {
|
|
9907
|
-
console.log(
|
|
10686
|
+
console.log(chalk32.red("error: ") + result.error);
|
|
9908
10687
|
if (result.lineNumber > 0) {
|
|
9909
|
-
console.log(
|
|
10688
|
+
console.log(chalk32.dim(` at line ${result.lineNumber}, col ${result.columnNumber}`));
|
|
9910
10689
|
}
|
|
9911
10690
|
}
|
|
9912
10691
|
}
|
|
@@ -9927,19 +10706,19 @@ function registerShellCommand(program) {
|
|
|
9927
10706
|
});
|
|
9928
10707
|
const api = createApiClient();
|
|
9929
10708
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
9930
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
10709
|
+
const { getUpdateNotice } = await import("./update-check-EW6JPLJT.js");
|
|
9931
10710
|
const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
|
|
9932
|
-
console.log(
|
|
9933
|
-
console.log(
|
|
9934
|
-
console.log(
|
|
10711
|
+
console.log(chalk32.bold("Diafunc shell") + chalk32.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
|
|
10712
|
+
console.log(chalk32.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
10713
|
+
console.log(chalk32.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
|
|
9935
10714
|
const notice = await getUpdateNotice();
|
|
9936
|
-
if (notice) console.log(
|
|
10715
|
+
if (notice) console.log(chalk32.dim(notice));
|
|
9937
10716
|
console.log();
|
|
9938
10717
|
let language = resolvedLanguage;
|
|
9939
10718
|
for (; ; ) {
|
|
9940
10719
|
let line;
|
|
9941
10720
|
try {
|
|
9942
|
-
line = await promptInput({ message:
|
|
10721
|
+
line = await promptInput({ message: chalk32.cyan.bold(`${language} >`) });
|
|
9943
10722
|
} catch {
|
|
9944
10723
|
console.log();
|
|
9945
10724
|
return;
|
|
@@ -9957,54 +10736,54 @@ function registerShellCommand(program) {
|
|
|
9957
10736
|
case "help":
|
|
9958
10737
|
case "h":
|
|
9959
10738
|
case "?":
|
|
9960
|
-
console.log(
|
|
9961
|
-
console.log(
|
|
9962
|
-
console.log(
|
|
9963
|
-
console.log(
|
|
10739
|
+
console.log(chalk32.dim(" /edit open $EDITOR for multi-line code"));
|
|
10740
|
+
console.log(chalk32.dim(" /file <path> evaluate the contents of a file"));
|
|
10741
|
+
console.log(chalk32.dim(" /lang <name> switch language (Java, JavaScript, Kotlin, Python, Scala)"));
|
|
10742
|
+
console.log(chalk32.dim(" /quit exit the shell"));
|
|
9964
10743
|
continue;
|
|
9965
10744
|
case "lang":
|
|
9966
10745
|
if (arg) language = arg;
|
|
9967
|
-
console.log(
|
|
10746
|
+
console.log(chalk32.dim(`Language: ${language}`));
|
|
9968
10747
|
continue;
|
|
9969
10748
|
case "edit": {
|
|
9970
10749
|
const sourceCode = await openInEditor("", extensionFor2(language));
|
|
9971
10750
|
if (!sourceCode.trim()) {
|
|
9972
|
-
console.log(
|
|
10751
|
+
console.log(chalk32.dim("(empty; not evaluated)"));
|
|
9973
10752
|
continue;
|
|
9974
10753
|
}
|
|
9975
10754
|
try {
|
|
9976
10755
|
await evaluate(api, fnRef, language, sourceCode);
|
|
9977
10756
|
} catch (e) {
|
|
9978
|
-
console.error(
|
|
10757
|
+
console.error(chalk32.red(e.message));
|
|
9979
10758
|
}
|
|
9980
10759
|
continue;
|
|
9981
10760
|
}
|
|
9982
10761
|
case "file": {
|
|
9983
10762
|
if (!arg) {
|
|
9984
|
-
console.log(
|
|
10763
|
+
console.log(chalk32.dim("usage: /file <path>"));
|
|
9985
10764
|
continue;
|
|
9986
10765
|
}
|
|
9987
10766
|
if (!fs12.existsSync(arg)) {
|
|
9988
|
-
console.log(
|
|
10767
|
+
console.log(chalk32.red(`file not found: ${arg}`));
|
|
9989
10768
|
continue;
|
|
9990
10769
|
}
|
|
9991
10770
|
const sourceCode = fs12.readFileSync(arg, "utf-8");
|
|
9992
10771
|
try {
|
|
9993
10772
|
await evaluate(api, fnRef, language, sourceCode);
|
|
9994
10773
|
} catch (e) {
|
|
9995
|
-
console.error(
|
|
10774
|
+
console.error(chalk32.red(e.message));
|
|
9996
10775
|
}
|
|
9997
10776
|
continue;
|
|
9998
10777
|
}
|
|
9999
10778
|
default:
|
|
10000
|
-
console.log(
|
|
10779
|
+
console.log(chalk32.dim(`Unknown command: /${cmd2}. Try /help.`));
|
|
10001
10780
|
continue;
|
|
10002
10781
|
}
|
|
10003
10782
|
}
|
|
10004
10783
|
try {
|
|
10005
10784
|
await evaluate(api, fnRef, language, trimmed);
|
|
10006
10785
|
} catch (e) {
|
|
10007
|
-
console.error(
|
|
10786
|
+
console.error(chalk32.red(e.message));
|
|
10008
10787
|
}
|
|
10009
10788
|
}
|
|
10010
10789
|
} catch (error) {
|
|
@@ -10014,7 +10793,7 @@ function registerShellCommand(program) {
|
|
|
10014
10793
|
}
|
|
10015
10794
|
|
|
10016
10795
|
// src/commands/update/index.ts
|
|
10017
|
-
import
|
|
10796
|
+
import chalk33 from "chalk";
|
|
10018
10797
|
import * as path10 from "path";
|
|
10019
10798
|
import { spawn as spawn4 } from "child_process";
|
|
10020
10799
|
|
|
@@ -10060,14 +10839,14 @@ function registerUpdateCommand(program) {
|
|
|
10060
10839
|
const install = detectInstall();
|
|
10061
10840
|
const latest = await fetchLatestVersion();
|
|
10062
10841
|
if (latest === package_default.version) {
|
|
10063
|
-
console.log(
|
|
10842
|
+
console.log(chalk33.dim(`diafunc is already at the latest version (${package_default.version}).`));
|
|
10064
10843
|
return;
|
|
10065
10844
|
}
|
|
10066
|
-
console.log(
|
|
10845
|
+
console.log(chalk33.dim(`Current: ${package_default.version} \u2192 Available: ${latest}`));
|
|
10067
10846
|
if (install.method === "npm") {
|
|
10068
10847
|
console.log();
|
|
10069
10848
|
console.log("Installed via npm. Upgrade with:");
|
|
10070
|
-
console.log(
|
|
10849
|
+
console.log(chalk33.bold(` npm install -g @diafunc/cli@${latest}`));
|
|
10071
10850
|
return;
|
|
10072
10851
|
}
|
|
10073
10852
|
const installDir = path10.dirname(install.binaryPath);
|
|
@@ -10081,7 +10860,7 @@ function registerUpdateCommand(program) {
|
|
|
10081
10860
|
}
|
|
10082
10861
|
|
|
10083
10862
|
// src/commands/uninstall/index.ts
|
|
10084
|
-
import
|
|
10863
|
+
import chalk34 from "chalk";
|
|
10085
10864
|
import { spawn as spawn5 } from "child_process";
|
|
10086
10865
|
import * as fs14 from "fs";
|
|
10087
10866
|
import * as os4 from "os";
|
|
@@ -10093,11 +10872,11 @@ function registerUninstallCommand(program) {
|
|
|
10093
10872
|
const configDir = path11.join(os4.homedir(), ".diafunc");
|
|
10094
10873
|
if (install.method === "npm") {
|
|
10095
10874
|
console.log("Installed via npm. Remove with:");
|
|
10096
|
-
console.log(
|
|
10875
|
+
console.log(chalk34.bold(" npm uninstall -g @diafunc/cli"));
|
|
10097
10876
|
if (fs14.existsSync(configDir)) {
|
|
10098
10877
|
console.log();
|
|
10099
10878
|
console.log(`Config and credentials live at ${configDir}. Remove them manually with:`);
|
|
10100
|
-
console.log(
|
|
10879
|
+
console.log(chalk34.bold(` rm -rf ${configDir}`));
|
|
10101
10880
|
}
|
|
10102
10881
|
return;
|
|
10103
10882
|
}
|
|
@@ -10107,7 +10886,7 @@ function registerUninstallCommand(program) {
|
|
|
10107
10886
|
default: false
|
|
10108
10887
|
});
|
|
10109
10888
|
if (!removeBinary) {
|
|
10110
|
-
console.log(
|
|
10889
|
+
console.log(chalk34.dim("Aborted."));
|
|
10111
10890
|
return;
|
|
10112
10891
|
}
|
|
10113
10892
|
let removeConfig = options.purge ?? false;
|
|
@@ -10119,7 +10898,7 @@ function registerUninstallCommand(program) {
|
|
|
10119
10898
|
}
|
|
10120
10899
|
if (removeConfig && fs14.existsSync(configDir)) {
|
|
10121
10900
|
fs14.rmSync(configDir, { recursive: true, force: true });
|
|
10122
|
-
console.log(
|
|
10901
|
+
console.log(chalk34.dim(`Removed ${configDir}`));
|
|
10123
10902
|
}
|
|
10124
10903
|
if (process.platform === "win32") {
|
|
10125
10904
|
const cmd = `timeout /t 2 /nobreak >nul & del /f /q "${install.binaryPath}"`;
|
|
@@ -10129,13 +10908,13 @@ function registerUninstallCommand(program) {
|
|
|
10129
10908
|
windowsHide: true
|
|
10130
10909
|
});
|
|
10131
10910
|
child.unref();
|
|
10132
|
-
console.log(
|
|
10911
|
+
console.log(chalk34.dim(`Removing ${install.binaryPath} on exit...`));
|
|
10133
10912
|
console.log();
|
|
10134
10913
|
console.log("diafunc uninstalled.");
|
|
10135
10914
|
return;
|
|
10136
10915
|
}
|
|
10137
10916
|
fs14.rmSync(install.binaryPath, { force: true });
|
|
10138
|
-
console.log(
|
|
10917
|
+
console.log(chalk34.dim(`Removed ${install.binaryPath}`));
|
|
10139
10918
|
console.log();
|
|
10140
10919
|
console.log("diafunc uninstalled.");
|
|
10141
10920
|
} catch (error) {
|
|
@@ -10199,7 +10978,7 @@ var DiafuncCommand = class _DiafuncCommand extends Command {
|
|
|
10199
10978
|
};
|
|
10200
10979
|
|
|
10201
10980
|
// src/prompting/fill.ts
|
|
10202
|
-
import
|
|
10981
|
+
import chalk36 from "chalk";
|
|
10203
10982
|
|
|
10204
10983
|
// src/prompting/resolvers.ts
|
|
10205
10984
|
var PROJECT_ROLES = ["OWNER", "ADMIN", "DEVELOPER", "GUEST"];
|
|
@@ -10220,12 +10999,14 @@ var POSITIVE = { kind: "number", min: 0, integer: false, exclusive: true };
|
|
|
10220
10999
|
var INDEX = { kind: "number", min: 0, integer: true };
|
|
10221
11000
|
var BY_COMMAND = {
|
|
10222
11001
|
"analyze segment": { "<name>": { kind: "analysisColumns", multiple: false, allowEmpty: true } },
|
|
10223
|
-
"analyze targets": { "<
|
|
10224
|
-
"analyze feature-exclusions": { "<
|
|
10225
|
-
"analyze confirmed-inputs": { "<
|
|
11002
|
+
"analyze targets": { "<column>": { kind: "analysisColumns", multiple: true, allowEmpty: false } },
|
|
11003
|
+
"analyze feature-exclusions": { "<column>": { kind: "analysisColumns", multiple: true, allowEmpty: true } },
|
|
11004
|
+
"analyze confirmed-inputs": { "<column>": { kind: "analysisColumns", multiple: true, allowEmpty: true } },
|
|
10226
11005
|
"analyze questions": { "<question>": TEXT_OR_EMPTY },
|
|
10227
11006
|
"analyze description": { "<text>": TEXT_OR_EMPTY },
|
|
10228
11007
|
"analyze introduction": { "<markdown>": TEXT_OR_EMPTY },
|
|
11008
|
+
// Not the analysis picker: that one offers the reader's own analyses, and this command needs no account.
|
|
11009
|
+
"public show": { "<analysisId>": TEXT },
|
|
10229
11010
|
"analyze presets save": { "--targets": TEXT, "--hours": POSITIVE, "--budget": POSITIVE },
|
|
10230
11011
|
"branch merge": {
|
|
10231
11012
|
"--source": { kind: "entity", form: "ref" },
|
|
@@ -10394,7 +11175,7 @@ function dependencies(spec) {
|
|
|
10394
11175
|
|
|
10395
11176
|
// src/prompting/pickers.ts
|
|
10396
11177
|
import * as fs15 from "fs";
|
|
10397
|
-
import
|
|
11178
|
+
import chalk35 from "chalk";
|
|
10398
11179
|
var SEARCH_THRESHOLD = 10;
|
|
10399
11180
|
var TYPE_IT = "\0type-it";
|
|
10400
11181
|
async function askFor(spec, input, ctx) {
|
|
@@ -10652,7 +11433,7 @@ async function askColumns(ctx, spec, input) {
|
|
|
10652
11433
|
choices: columns.map((c) => ({ name: c, value: c })),
|
|
10653
11434
|
validate: (picked) => picked.length > 0 || "Pick at least one column."
|
|
10654
11435
|
});
|
|
10655
|
-
return chosen
|
|
11436
|
+
return chosen;
|
|
10656
11437
|
}
|
|
10657
11438
|
const items = columns.map((c) => ({ label: c, value: c }));
|
|
10658
11439
|
if (spec.allowEmpty) items.unshift({ label: "None (clear it)", value: "" });
|
|
@@ -10742,7 +11523,7 @@ function typedValue(ctx, message) {
|
|
|
10742
11523
|
return typed(ctx, message);
|
|
10743
11524
|
}
|
|
10744
11525
|
function typeItChoice() {
|
|
10745
|
-
return { name:
|
|
11526
|
+
return { name: chalk35.dim("Type it instead"), value: TYPE_IT };
|
|
10746
11527
|
}
|
|
10747
11528
|
function text(ctx, name) {
|
|
10748
11529
|
const value = ctx.known.get(name);
|
|
@@ -10772,7 +11553,7 @@ function capitalize(value) {
|
|
|
10772
11553
|
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
10773
11554
|
}
|
|
10774
11555
|
function labelled(label, hint2) {
|
|
10775
|
-
return hint2 && hint2 !== label ? `${label} ${
|
|
11556
|
+
return hint2 && hint2 !== label ? `${label} ${chalk35.dim(hint2)}` : label;
|
|
10776
11557
|
}
|
|
10777
11558
|
function numberRule(spec) {
|
|
10778
11559
|
return (raw) => {
|
|
@@ -10818,7 +11599,7 @@ async function fillPendingInputs(actionCommand) {
|
|
|
10818
11599
|
known: knownValues(actionCommand),
|
|
10819
11600
|
globals: actionCommand.optsWithGlobals(),
|
|
10820
11601
|
prefill: /* @__PURE__ */ new Map(),
|
|
10821
|
-
note: (line) => process.stderr.write(
|
|
11602
|
+
note: (line) => process.stderr.write(chalk36.dim(` ${line}
|
|
10822
11603
|
`))
|
|
10823
11604
|
};
|
|
10824
11605
|
for (const item of orderByDependencies(pending)) {
|
|
@@ -10827,7 +11608,7 @@ async function fillPendingInputs(actionCommand) {
|
|
|
10827
11608
|
ctx.known.set(item.input.name, value);
|
|
10828
11609
|
}
|
|
10829
11610
|
const log = env.log ?? ((line) => console.log(line));
|
|
10830
|
-
log(
|
|
11611
|
+
log(chalk36.dim(` Equivalent: ${equivalentCommand(actionCommand)}`));
|
|
10831
11612
|
}
|
|
10832
11613
|
function commandChain(cmd) {
|
|
10833
11614
|
const chain = [];
|
|
@@ -10932,7 +11713,7 @@ function createProgram(environment = {}) {
|
|
|
10932
11713
|
const opts = thisCommand.optsWithGlobals();
|
|
10933
11714
|
if (opts.dryRun) setDryRun(true);
|
|
10934
11715
|
if (opts.verbose) setVerbose(true);
|
|
10935
|
-
if (opts.color === false)
|
|
11716
|
+
if (opts.color === false) chalk37.level = 0;
|
|
10936
11717
|
}).hook("preAction", (_thisCommand, actionCommand) => fillPendingInputs(actionCommand));
|
|
10937
11718
|
program.addHelpText("after", HELP_EPILOGUE);
|
|
10938
11719
|
registerAuthCommands(program);
|
|
@@ -10953,6 +11734,7 @@ function createProgram(environment = {}) {
|
|
|
10953
11734
|
registerAdminCommands(program);
|
|
10954
11735
|
registerStatusCommands(program);
|
|
10955
11736
|
registerAnalyzeCommand(program);
|
|
11737
|
+
registerPublicCommands(program);
|
|
10956
11738
|
registerDataSourcesCommands(program);
|
|
10957
11739
|
registerTableExportersCommands(program);
|
|
10958
11740
|
registerSkeletonCommands(program);
|
|
@@ -10974,4 +11756,4 @@ export {
|
|
|
10974
11756
|
PromptCancelled,
|
|
10975
11757
|
createProgram
|
|
10976
11758
|
};
|
|
10977
|
-
//# sourceMappingURL=chunk-
|
|
11759
|
+
//# sourceMappingURL=chunk-IV75CA5V.js.map
|