@diafunc/cli 0.18.0 → 0.19.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 +3 -0
- package/dist/bin/diafunc.js +3 -3
- package/dist/{chunk-JG3FMXGU.js → chunk-A5D45VXJ.js} +2 -2
- package/dist/{chunk-JG3FMXGU.js.map → chunk-A5D45VXJ.js.map} +1 -1
- package/dist/{chunk-ZVC7B6VZ.js → chunk-OCZSFCU6.js} +204 -73
- package/dist/chunk-OCZSFCU6.js.map +1 -0
- package/dist/{chunk-GQT5HO6G.js → chunk-SYNS3L7N.js} +2 -2
- package/dist/src/index.js +2 -2
- package/dist/update-check-TTXILAMD.js +8 -0
- package/package.json +1 -1
- package/dist/chunk-ZVC7B6VZ.js.map +0 -1
- package/dist/update-check-HMBNFIA5.js +0 -8
- /package/dist/{chunk-GQT5HO6G.js.map → chunk-SYNS3L7N.js.map} +0 -0
- /package/dist/{update-check-HMBNFIA5.js.map → update-check-TTXILAMD.js.map} +0 -0
package/README.md
CHANGED
|
@@ -69,6 +69,9 @@ diafunc analyze data.csv
|
|
|
69
69
|
|
|
70
70
|
# Answer everything up front instead, which is what a script has to do.
|
|
71
71
|
diafunc analyze data.csv --name "My Analysis" --targets quality --hours 2 --budget 2000
|
|
72
|
+
|
|
73
|
+
# Several files with the same columns are stacked into one table
|
|
74
|
+
diafunc analyze jan.csv feb.csv mar.csv --targets quality
|
|
72
75
|
diafunc analyze watch
|
|
73
76
|
```
|
|
74
77
|
|
package/dist/bin/diafunc.js
CHANGED
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
PromptCancelled,
|
|
5
5
|
createProgram,
|
|
6
6
|
handleError
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-OCZSFCU6.js";
|
|
8
8
|
import {
|
|
9
9
|
getUpdateNotice
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-SYNS3L7N.js";
|
|
11
11
|
import {
|
|
12
12
|
package_default
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-A5D45VXJ.js";
|
|
14
14
|
|
|
15
15
|
// bin/diafunc.ts
|
|
16
16
|
import chalk2 from "chalk";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@diafunc/cli",
|
|
4
|
-
version: "0.
|
|
4
|
+
version: "0.19.0",
|
|
5
5
|
description: "Diafunc CLI: the command-line interface for the Diafunc platform",
|
|
6
6
|
type: "module",
|
|
7
7
|
bin: {
|
|
@@ -62,4 +62,4 @@ var package_default = {
|
|
|
62
62
|
export {
|
|
63
63
|
package_default
|
|
64
64
|
};
|
|
65
|
-
//# sourceMappingURL=chunk-
|
|
65
|
+
//# sourceMappingURL=chunk-A5D45VXJ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"@diafunc/cli\",\n \"version\": \"0.
|
|
1
|
+
{"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"@diafunc/cli\",\n \"version\": \"0.19.0\",\n \"description\": \"Diafunc CLI: the command-line interface for the Diafunc platform\",\n \"type\": \"module\",\n \"bin\": {\n \"diafunc\": \"./dist/bin/diafunc.js\"\n },\n \"homepage\": \"https://diafunc.com\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://gitlab.com/diafunc/cli.git\"\n },\n \"bugs\": {\n \"url\": \"https://gitlab.com/diafunc/cli/-/issues\"\n },\n \"author\": \"Markus Pollak <markus.pollak@diafunc.com>\",\n \"scripts\": {\n \"build\": \"tsup && node -e \\\"const fs=require('fs');const f='dist/bin/diafunc.js';fs.writeFileSync(f,'#!/usr/bin/env node\\\\n'+fs.readFileSync(f,'utf8'))\\\"\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"lint\": \"tsc --noEmit\",\n \"start\": \"node dist/bin/diafunc.js\",\n \"prepublishOnly\": \"npm run lint && npm test && npm run build\"\n },\n \"files\": [\n \"dist\",\n \"LICENSE\",\n \"README.md\"\n ],\n \"keywords\": [\n \"diafunc\",\n \"cli\",\n \"data-science\",\n \"symbolic-regression\"\n ],\n \"license\": \"Apache-2.0\",\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org/\"\n },\n \"engines\": {\n \"node\": \">=20.0.0\"\n },\n \"dependencies\": {\n \"@inquirer/prompts\": \"^7.0.0\",\n \"chalk\": \"^5.4.0\",\n \"cli-table3\": \"^0.6.5\",\n \"commander\": \"^12.1.0\",\n \"ora\": \"^8.1.0\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^22.0.0\",\n \"tsup\": \"^8.3.0\",\n \"typescript\": \"^5.6.0\",\n \"vitest\": \"^2.1.0\"\n }\n}\n"],"mappings":";AAAA;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,KAAO;AAAA,IACL,SAAW;AAAA,EACb;AAAA,EACA,UAAY;AAAA,EACZ,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,EACT;AAAA,EACA,MAAQ;AAAA,IACN,KAAO;AAAA,EACT;AAAA,EACA,QAAU;AAAA,EACV,SAAW;AAAA,IACT,OAAS;AAAA,IACT,KAAO;AAAA,IACP,MAAQ;AAAA,IACR,cAAc;AAAA,IACd,MAAQ;AAAA,IACR,OAAS;AAAA,IACT,gBAAkB;AAAA,EACpB;AAAA,EACA,OAAS;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,UAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,SAAW;AAAA,EACX,eAAiB;AAAA,IACf,QAAU;AAAA,IACV,UAAY;AAAA,EACd;AAAA,EACA,SAAW;AAAA,IACT,MAAQ;AAAA,EACV;AAAA,EACA,cAAgB;AAAA,IACd,qBAAqB;AAAA,IACrB,OAAS;AAAA,IACT,cAAc;AAAA,IACd,WAAa;AAAA,IACb,KAAO;AAAA,EACT;AAAA,EACA,iBAAmB;AAAA,IACjB,eAAe;AAAA,IACf,MAAQ;AAAA,IACR,YAAc;AAAA,IACd,QAAU;AAAA,EACZ;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-A5D45VXJ.js";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
import chalk36 from "chalk";
|
|
@@ -124,8 +124,8 @@ var REQUEST_TIMEOUT_MS = 6e4;
|
|
|
124
124
|
var RETRYABLE_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
125
125
|
var MAX_ATTEMPTS = 3;
|
|
126
126
|
var RETRYABLE_METHODS = /* @__PURE__ */ new Set(["GET"]);
|
|
127
|
-
function buildUrl(endpoint, service,
|
|
128
|
-
const base = `${endpoint}/api/v1/${service}${
|
|
127
|
+
function buildUrl(endpoint, service, path12, query) {
|
|
128
|
+
const base = `${endpoint}/api/v1/${service}${path12}`;
|
|
129
129
|
const params = new URLSearchParams();
|
|
130
130
|
if (query) {
|
|
131
131
|
for (const [key, value] of Object.entries(query)) {
|
|
@@ -1656,6 +1656,46 @@ function createAnalysisService(client) {
|
|
|
1656
1656
|
rawBody: formData
|
|
1657
1657
|
});
|
|
1658
1658
|
},
|
|
1659
|
+
// ----- Several files: sources ------------------------------------------------------
|
|
1660
|
+
async addSource(analysisId, formData) {
|
|
1661
|
+
return client.request({
|
|
1662
|
+
method: "POST",
|
|
1663
|
+
service: SERVICE2,
|
|
1664
|
+
path: `/${encodeURIComponent(analysisId)}/sources`,
|
|
1665
|
+
rawBody: formData
|
|
1666
|
+
});
|
|
1667
|
+
},
|
|
1668
|
+
async listSources(analysisId) {
|
|
1669
|
+
return client.request({
|
|
1670
|
+
method: "GET",
|
|
1671
|
+
service: SERVICE2,
|
|
1672
|
+
path: `/${encodeURIComponent(analysisId)}/sources`
|
|
1673
|
+
});
|
|
1674
|
+
},
|
|
1675
|
+
async removeSource(analysisId, sourceId) {
|
|
1676
|
+
return client.request({
|
|
1677
|
+
method: "DELETE",
|
|
1678
|
+
service: SERVICE2,
|
|
1679
|
+
path: `/${encodeURIComponent(analysisId)}/sources/${encodeURIComponent(sourceId)}`
|
|
1680
|
+
});
|
|
1681
|
+
},
|
|
1682
|
+
/** What building from the sources would yield: for `recipe`, or for the platform's proposal when it is null. */
|
|
1683
|
+
async planSources(analysisId, recipe) {
|
|
1684
|
+
return client.request({
|
|
1685
|
+
method: "POST",
|
|
1686
|
+
service: SERVICE2,
|
|
1687
|
+
path: `/${encodeURIComponent(analysisId)}/sources/plan`,
|
|
1688
|
+
body: recipe
|
|
1689
|
+
});
|
|
1690
|
+
},
|
|
1691
|
+
async buildSources(analysisId, recipe) {
|
|
1692
|
+
return client.request({
|
|
1693
|
+
method: "POST",
|
|
1694
|
+
service: SERVICE2,
|
|
1695
|
+
path: `/${encodeURIComponent(analysisId)}/sources/build`,
|
|
1696
|
+
body: recipe
|
|
1697
|
+
});
|
|
1698
|
+
},
|
|
1659
1699
|
async uploadDataUrl(analysisId, request) {
|
|
1660
1700
|
return client.request({
|
|
1661
1701
|
method: "POST",
|
|
@@ -1951,14 +1991,14 @@ function createStorageService(client) {
|
|
|
1951
1991
|
});
|
|
1952
1992
|
},
|
|
1953
1993
|
async deleteLink(projectId, projectBranch, sourceEntityId, sourceEntityBranch, linkId, targetEntityId, targetEntityBranch) {
|
|
1954
|
-
let
|
|
1994
|
+
let path12 = `/links/actual/${enc(projectId)}/${enc(projectBranch)}/${enc(sourceEntityId)}/${enc(sourceEntityBranch)}/${enc(linkId)}`;
|
|
1955
1995
|
if (targetEntityId && targetEntityBranch) {
|
|
1956
|
-
|
|
1996
|
+
path12 += `/${enc(targetEntityId)}/${enc(targetEntityBranch)}`;
|
|
1957
1997
|
}
|
|
1958
1998
|
return client.request({
|
|
1959
1999
|
method: "DELETE",
|
|
1960
2000
|
service: SERVICE3,
|
|
1961
|
-
path:
|
|
2001
|
+
path: path12
|
|
1962
2002
|
});
|
|
1963
2003
|
},
|
|
1964
2004
|
// --- Events ---
|
|
@@ -2994,8 +3034,8 @@ Examples:
|
|
|
2994
3034
|
success(`Profile "${name}" removed.`);
|
|
2995
3035
|
});
|
|
2996
3036
|
}
|
|
2997
|
-
function setNestedValue(obj,
|
|
2998
|
-
const keys =
|
|
3037
|
+
function setNestedValue(obj, path12, value) {
|
|
3038
|
+
const keys = path12.split(".");
|
|
2999
3039
|
let current = obj;
|
|
3000
3040
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
3001
3041
|
const key = keys[i];
|
|
@@ -3006,8 +3046,8 @@ function setNestedValue(obj, path11, value) {
|
|
|
3006
3046
|
}
|
|
3007
3047
|
current[keys[keys.length - 1]] = value;
|
|
3008
3048
|
}
|
|
3009
|
-
function getNestedValue(obj,
|
|
3010
|
-
const keys =
|
|
3049
|
+
function getNestedValue(obj, path12) {
|
|
3050
|
+
const keys = path12.split(".");
|
|
3011
3051
|
let current = obj;
|
|
3012
3052
|
for (const key of keys) {
|
|
3013
3053
|
if (current === null || current === void 0 || typeof current !== "object") {
|
|
@@ -4391,8 +4431,8 @@ function registerEventCommands(program) {
|
|
|
4391
4431
|
});
|
|
4392
4432
|
event.command("create").description("Create one or more events (body from JSON file or stdin)").argument("[file]", "JSON file containing a BareEvent array; defaults to stdin").action(async (file) => {
|
|
4393
4433
|
try {
|
|
4394
|
-
const
|
|
4395
|
-
const body = file ?
|
|
4434
|
+
const fs16 = await import("fs");
|
|
4435
|
+
const body = file ? fs16.readFileSync(file, "utf-8") : await new Promise((resolve, reject) => {
|
|
4396
4436
|
let data = "";
|
|
4397
4437
|
process.stdin.setEncoding("utf-8");
|
|
4398
4438
|
process.stdin.on("data", (chunk) => {
|
|
@@ -6219,7 +6259,7 @@ var HELP = [
|
|
|
6219
6259
|
];
|
|
6220
6260
|
async function runChatRepl(options) {
|
|
6221
6261
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
6222
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
6262
|
+
const { getUpdateNotice } = await import("./update-check-TTXILAMD.js");
|
|
6223
6263
|
let sessionId = options.session;
|
|
6224
6264
|
let lastReportedSession;
|
|
6225
6265
|
console.log(chalk19.bold("Diafunc chat") + chalk19.dim(" \xB7 /help for commands, /quit to exit"));
|
|
@@ -6811,8 +6851,8 @@ import chalk21 from "chalk";
|
|
|
6811
6851
|
function createStatusService() {
|
|
6812
6852
|
const config = loadConfig();
|
|
6813
6853
|
const endpoint = resolveEndpoint(config);
|
|
6814
|
-
async function fetchJson(
|
|
6815
|
-
const url = `${endpoint}/status/v1${
|
|
6854
|
+
async function fetchJson(path12) {
|
|
6855
|
+
const url = `${endpoint}/status/v1${path12}`;
|
|
6816
6856
|
const response = await fetch(url, {
|
|
6817
6857
|
headers: { "Accept": "application/json" }
|
|
6818
6858
|
});
|
|
@@ -7010,8 +7050,8 @@ Examples:
|
|
|
7010
7050
|
}
|
|
7011
7051
|
|
|
7012
7052
|
// src/commands/analyze/index.ts
|
|
7013
|
-
import * as
|
|
7014
|
-
import * as
|
|
7053
|
+
import * as fs9 from "fs";
|
|
7054
|
+
import * as path8 from "path";
|
|
7015
7055
|
import { spawn as spawn2 } from "child_process";
|
|
7016
7056
|
|
|
7017
7057
|
// src/commands/analyze/watch-view.ts
|
|
@@ -7031,12 +7071,25 @@ var RUN_PHASE_LABELS = {
|
|
|
7031
7071
|
var RUN_STEPS = ["PREPARING", "PROFILING", "DISCOVERING", "EXPLAINING", "WRITING"];
|
|
7032
7072
|
var STARTING = "Starting";
|
|
7033
7073
|
function phaseLabel(run) {
|
|
7034
|
-
if (run.state === "QUEUED") return
|
|
7074
|
+
if (run.state === "QUEUED") return waitLabel(run);
|
|
7035
7075
|
if (run.state === "DISPATCHING") return STARTING;
|
|
7036
7076
|
if (run.phase && RUN_PHASE_LABELS[run.phase]) return RUN_PHASE_LABELS[run.phase];
|
|
7037
7077
|
if (run.state === "RUNNING" && !((run.progressTotal ?? 0) > 0)) return RUN_PHASE_LABELS.PREPARING;
|
|
7038
7078
|
return run.state.charAt(0) + run.state.slice(1).toLowerCase();
|
|
7039
7079
|
}
|
|
7080
|
+
function waitLabel(run) {
|
|
7081
|
+
switch (run.waitReason) {
|
|
7082
|
+
case "OWN_RUNS":
|
|
7083
|
+
return "Waiting for one of your analyses to finish";
|
|
7084
|
+
case "PLATFORM_BUSY":
|
|
7085
|
+
return "Waiting for a free slot";
|
|
7086
|
+
default:
|
|
7087
|
+
return RUN_PHASE_LABELS.QUEUED;
|
|
7088
|
+
}
|
|
7089
|
+
}
|
|
7090
|
+
function waitCell(run) {
|
|
7091
|
+
return run.waitReason === "OWN_RUNS" ? "Waiting for your runs" : RUN_PHASE_LABELS.QUEUED;
|
|
7092
|
+
}
|
|
7040
7093
|
function stepCounter(run) {
|
|
7041
7094
|
if (!run.phase) return null;
|
|
7042
7095
|
const index = RUN_STEPS.indexOf(run.phase);
|
|
@@ -7045,7 +7098,8 @@ function stepCounter(run) {
|
|
|
7045
7098
|
}
|
|
7046
7099
|
function runPhaseCell(run) {
|
|
7047
7100
|
if (run.state === "COMPLETED") return null;
|
|
7048
|
-
if (run.state === "QUEUED"
|
|
7101
|
+
if (run.state === "QUEUED") return waitCell(run);
|
|
7102
|
+
if (run.state === "DISPATCHING") return phaseLabel(run);
|
|
7049
7103
|
if (run.phase && RUN_PHASE_LABELS[run.phase]) return RUN_PHASE_LABELS[run.phase];
|
|
7050
7104
|
return null;
|
|
7051
7105
|
}
|
|
@@ -7550,6 +7604,61 @@ function constraintsText(analysis) {
|
|
|
7550
7604
|
return parts.length > 0 ? parts.join(", ") : "none";
|
|
7551
7605
|
}
|
|
7552
7606
|
|
|
7607
|
+
// src/commands/analyze/sources.ts
|
|
7608
|
+
import * as fs8 from "fs";
|
|
7609
|
+
import * as path7 from "path";
|
|
7610
|
+
var CAUTIONS = /* @__PURE__ */ new Set(["UNEVEN_COLUMNS", "TYPE_CONFLICT", "SOURCE_WARNING", "LEFT_OUT"]);
|
|
7611
|
+
function recipeWithChoices(proposal, choices) {
|
|
7612
|
+
if (proposal.parts.length < 2) return null;
|
|
7613
|
+
const originColumn = choices.fileColumn ? proposal.originColumn : null;
|
|
7614
|
+
const dropDuplicates = !choices.keepDuplicates;
|
|
7615
|
+
if (originColumn === proposal.originColumn && dropDuplicates === proposal.dropDuplicates) return null;
|
|
7616
|
+
return { parts: proposal.parts, originColumn, dropDuplicates };
|
|
7617
|
+
}
|
|
7618
|
+
function planLines(plan) {
|
|
7619
|
+
const lines = [{
|
|
7620
|
+
text: `One table of ${plan.rows.toLocaleString("en-US")} rows and ${plan.columns.toLocaleString("en-US")} columns.`,
|
|
7621
|
+
caution: false
|
|
7622
|
+
}];
|
|
7623
|
+
for (const finding of plan.findings) {
|
|
7624
|
+
lines.push({ text: finding.message, caution: CAUTIONS.has(finding.kind) });
|
|
7625
|
+
}
|
|
7626
|
+
return lines;
|
|
7627
|
+
}
|
|
7628
|
+
function multipart(file) {
|
|
7629
|
+
const formData = new FormData();
|
|
7630
|
+
formData.append("content", new Blob([fs8.readFileSync(file)]), path7.basename(file));
|
|
7631
|
+
return formData;
|
|
7632
|
+
}
|
|
7633
|
+
async function uploadSeveral(api, analysisId, files, choices, human) {
|
|
7634
|
+
for (const file of files) {
|
|
7635
|
+
if (!fs8.existsSync(file)) {
|
|
7636
|
+
throw new CliError(`File not found: ${file}`, { exitCode: EXIT_USAGE });
|
|
7637
|
+
}
|
|
7638
|
+
}
|
|
7639
|
+
for (const earlier of await api.analysis.listSources(analysisId)) {
|
|
7640
|
+
await api.analysis.removeSource(analysisId, earlier.sourceId);
|
|
7641
|
+
}
|
|
7642
|
+
for (const file of files) {
|
|
7643
|
+
await withStatus(`Uploading ${path7.basename(file)}`, () => api.analysis.addSource(analysisId, multipart(file)));
|
|
7644
|
+
}
|
|
7645
|
+
const plan = await withStatus("Reading the files together", async () => {
|
|
7646
|
+
const proposal = await api.analysis.planSources(analysisId, null);
|
|
7647
|
+
const chosen = recipeWithChoices(proposal.recipe, choices);
|
|
7648
|
+
return chosen ? api.analysis.planSources(analysisId, chosen) : proposal;
|
|
7649
|
+
});
|
|
7650
|
+
if (human) {
|
|
7651
|
+
for (const line of planLines(plan)) {
|
|
7652
|
+
if (line.caution) warn(line.text);
|
|
7653
|
+
else detail(line.text);
|
|
7654
|
+
}
|
|
7655
|
+
}
|
|
7656
|
+
return withStatus(
|
|
7657
|
+
`Building one table from ${plan.recipe.parts.length} file${plan.recipe.parts.length === 1 ? "" : "s"}`,
|
|
7658
|
+
() => api.analysis.buildSources(analysisId, plan.recipe)
|
|
7659
|
+
);
|
|
7660
|
+
}
|
|
7661
|
+
|
|
7553
7662
|
// src/commands/analyze/index.ts
|
|
7554
7663
|
var POLL_INTERVAL_MS = 2e3;
|
|
7555
7664
|
var MISSING_RUN_POLLS = 5;
|
|
@@ -7595,21 +7704,24 @@ function budgetHoursOf(hours) {
|
|
|
7595
7704
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
|
7596
7705
|
}
|
|
7597
7706
|
function multipartFromFile(file) {
|
|
7598
|
-
const buffer =
|
|
7707
|
+
const buffer = fs9.readFileSync(file);
|
|
7599
7708
|
const blob = new Blob([buffer]);
|
|
7600
7709
|
const formData = new FormData();
|
|
7601
|
-
formData.append("content", blob,
|
|
7710
|
+
formData.append("content", blob, path8.basename(file));
|
|
7602
7711
|
return formData;
|
|
7603
7712
|
}
|
|
7604
7713
|
function reportCommandError(error) {
|
|
7605
7714
|
if (error instanceof PromptCancelled) throw error;
|
|
7606
7715
|
handleError(error);
|
|
7607
7716
|
}
|
|
7608
|
-
async function runAnalysis(
|
|
7609
|
-
|
|
7610
|
-
|
|
7611
|
-
|
|
7717
|
+
async function runAnalysis(files, options, cmd) {
|
|
7718
|
+
for (const candidate of files) {
|
|
7719
|
+
if (!fs9.existsSync(candidate)) {
|
|
7720
|
+
failure(`File not found: ${candidate}`);
|
|
7721
|
+
process.exit(EXIT_FAILURE);
|
|
7722
|
+
}
|
|
7612
7723
|
}
|
|
7724
|
+
const file = files[0];
|
|
7613
7725
|
const outputFormat = getOutputFormat15(cmd);
|
|
7614
7726
|
const noInteractive = noInteractiveFlag(cmd);
|
|
7615
7727
|
const interactive = canPrompt(outputFormat, noInteractive);
|
|
@@ -7632,11 +7744,11 @@ async function runAnalysis(file, options, cmd) {
|
|
|
7632
7744
|
if (!interactive && (flagTargets === null || flagTargets.length === 0)) {
|
|
7633
7745
|
usageError(
|
|
7634
7746
|
`Target columns are required, and ${whyNoPrompt(outputFormat, noInteractive)}.`,
|
|
7635
|
-
`Pass --targets <csv> or --preset <id>. The names are the column headers of ${
|
|
7747
|
+
`Pass --targets <csv> or --preset <id>. The names are the column headers of ${files.length > 1 ? "the files" : path8.basename(file)}.`
|
|
7636
7748
|
);
|
|
7637
7749
|
}
|
|
7638
7750
|
const prompter = createInquirerPrompter();
|
|
7639
|
-
const fallbackName =
|
|
7751
|
+
const fallbackName = path8.basename(file, path8.extname(file));
|
|
7640
7752
|
const creation = interactive ? await promptCreationFields(prompter, {
|
|
7641
7753
|
name: options.name,
|
|
7642
7754
|
description: options.description,
|
|
@@ -7659,14 +7771,18 @@ async function runAnalysis(file, options, cmd) {
|
|
|
7659
7771
|
};
|
|
7660
7772
|
const created = await withStatus(`Creating analysis "${creation.name}"`, () => api.analysis.create(request));
|
|
7661
7773
|
if (isDryRun()) {
|
|
7662
|
-
hint(`Dry run: nothing was created. A real run would upload ${
|
|
7774
|
+
hint(`Dry run: nothing was created. A real run would upload ${path8.basename(file)}, queue the analysis and follow it.`);
|
|
7663
7775
|
return;
|
|
7664
7776
|
}
|
|
7665
7777
|
detail(`analysisId: ${created.analysisId}`);
|
|
7666
|
-
|
|
7667
|
-
|
|
7668
|
-
|
|
7669
|
-
|
|
7778
|
+
if (files.length > 1) {
|
|
7779
|
+
await uploadSeveral(api, created.analysisId, files, stackChoices(options), outputFormat === "human");
|
|
7780
|
+
} else {
|
|
7781
|
+
await withStatus(
|
|
7782
|
+
`Uploading ${path8.basename(file)}`,
|
|
7783
|
+
() => api.analysis.uploadDataMultipart(created.analysisId, multipartFromFile(file))
|
|
7784
|
+
);
|
|
7785
|
+
}
|
|
7670
7786
|
let runHours = request.hours;
|
|
7671
7787
|
if (interactive) {
|
|
7672
7788
|
const configuredHours = await configureInteractively(api, prompter, created.analysisId, request, {
|
|
@@ -8053,8 +8169,23 @@ async function patchAndPrint(analysisId, value, handler, successLabel, cmd) {
|
|
|
8053
8169
|
format(updated, { format: outputFormat });
|
|
8054
8170
|
}
|
|
8055
8171
|
}
|
|
8056
|
-
|
|
8172
|
+
function stackChoices(options) {
|
|
8173
|
+
return { fileColumn: options.fileColumn !== false, keepDuplicates: options.keepDuplicates === true };
|
|
8174
|
+
}
|
|
8175
|
+
async function uploadData(analysisId, files, options, cmd) {
|
|
8057
8176
|
const api = createApiClient();
|
|
8177
|
+
const file = files[0];
|
|
8178
|
+
if (files.length > 1) {
|
|
8179
|
+
if (options.url) {
|
|
8180
|
+
usageError("Provide either files or --url, not both.", "Drop one of the two and run it again.");
|
|
8181
|
+
}
|
|
8182
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
8183
|
+
const build = await uploadSeveral(api, analysisId, files, stackChoices(options), outputFormat === "human");
|
|
8184
|
+
if (outputFormat !== "human") {
|
|
8185
|
+
format(build, { format: outputFormat });
|
|
8186
|
+
}
|
|
8187
|
+
return;
|
|
8188
|
+
}
|
|
8058
8189
|
const dataUrl = options.url;
|
|
8059
8190
|
if (dataUrl) {
|
|
8060
8191
|
if (file) {
|
|
@@ -8069,11 +8200,11 @@ async function uploadData(analysisId, file, options) {
|
|
|
8069
8200
|
`For example: diafunc analyze upload ${analysisId} data.csv`
|
|
8070
8201
|
);
|
|
8071
8202
|
}
|
|
8072
|
-
if (!
|
|
8203
|
+
if (!fs9.existsSync(file)) {
|
|
8073
8204
|
throw new CliError(`File not found: ${file}`, { exitCode: EXIT_USAGE });
|
|
8074
8205
|
}
|
|
8075
8206
|
await withStatus(
|
|
8076
|
-
`Uploading ${
|
|
8207
|
+
`Uploading ${path8.basename(file)}`,
|
|
8077
8208
|
() => api.analysis.uploadDataMultipart(analysisId, multipartFromFile(file))
|
|
8078
8209
|
);
|
|
8079
8210
|
}
|
|
@@ -8248,13 +8379,13 @@ async function updateTriggerCmd(triggerId, options, cmd) {
|
|
|
8248
8379
|
}
|
|
8249
8380
|
function registerAnalyzeCommand(program) {
|
|
8250
8381
|
const analyze = program.command("analyze").description("Run and manage automatic analyses");
|
|
8251
|
-
analyze.command("run", { isDefault: true }).description("Create an analysis from a data file, configure it and run it (the default: `analyze <file>`)").argument("[
|
|
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 into one table").option("--name <name>", "Analysis name (asked for, or derived from the filename)").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC (default: PRIVATE)").option("--hours <hours>", `Computation time (hours). Default ${DEFAULT_HOURS}, the Standard preset; a saved preset applies when omitted`).option("--budget <credits>", `Credit budget. Default ${Number(DEFAULT_BUDGET).toLocaleString("en-US")}, the Standard preset; a saved preset applies when omitted`).option("--targets <csv>", "Comma-separated target column names (required when not interactive)").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").action(async (files, options, cmd) => {
|
|
8252
8383
|
try {
|
|
8253
|
-
if (
|
|
8384
|
+
if (files.length === 0) {
|
|
8254
8385
|
analyze.help();
|
|
8255
8386
|
return;
|
|
8256
8387
|
}
|
|
8257
|
-
await runAnalysis(
|
|
8388
|
+
await runAnalysis(files, options, cmd);
|
|
8258
8389
|
} catch (error) {
|
|
8259
8390
|
reportCommandError(error);
|
|
8260
8391
|
}
|
|
@@ -8457,9 +8588,9 @@ function registerAnalyzeCommand(program) {
|
|
|
8457
8588
|
handleError(error);
|
|
8458
8589
|
}
|
|
8459
8590
|
});
|
|
8460
|
-
analyze.command("upload").description("Replace the analysis data with a new file (any supported format; see `table import-formats`)").argument("<id>", "Analysis ID").argument("[
|
|
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 into one table").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").action(async (id, files, options, cmd) => {
|
|
8461
8592
|
try {
|
|
8462
|
-
await uploadData(id,
|
|
8593
|
+
await uploadData(id, files, options, cmd);
|
|
8463
8594
|
} catch (error) {
|
|
8464
8595
|
handleError(error);
|
|
8465
8596
|
}
|
|
@@ -8986,7 +9117,7 @@ function registerTableExportersCommands(program) {
|
|
|
8986
9117
|
|
|
8987
9118
|
// src/commands/skeleton/index.ts
|
|
8988
9119
|
import chalk28 from "chalk";
|
|
8989
|
-
import * as
|
|
9120
|
+
import * as fs10 from "fs";
|
|
8990
9121
|
function getOutputFormat18(cmd) {
|
|
8991
9122
|
const config = loadConfig();
|
|
8992
9123
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -9010,10 +9141,10 @@ function resolveTemplate(raw) {
|
|
|
9010
9141
|
if (!file) {
|
|
9011
9142
|
throw new Error("--template @ requires a filename after the @, e.g. --template @template.txt");
|
|
9012
9143
|
}
|
|
9013
|
-
if (!
|
|
9144
|
+
if (!fs10.existsSync(file)) {
|
|
9014
9145
|
throw new Error(`Template file not found: ${file}`);
|
|
9015
9146
|
}
|
|
9016
|
-
return
|
|
9147
|
+
return fs10.readFileSync(file, "utf-8").trim();
|
|
9017
9148
|
}
|
|
9018
9149
|
return raw;
|
|
9019
9150
|
}
|
|
@@ -9648,7 +9779,7 @@ Examples:
|
|
|
9648
9779
|
}
|
|
9649
9780
|
|
|
9650
9781
|
// src/commands/invoice/index.ts
|
|
9651
|
-
import * as
|
|
9782
|
+
import * as fs11 from "fs";
|
|
9652
9783
|
function getOutputFormat22(cmd) {
|
|
9653
9784
|
const config = loadConfig();
|
|
9654
9785
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -9686,7 +9817,7 @@ Examples:
|
|
|
9686
9817
|
const response = await api.admin.downloadInvoice(invoiceNumber, fileName);
|
|
9687
9818
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
9688
9819
|
const outPath = options.out ?? fileName;
|
|
9689
|
-
|
|
9820
|
+
fs11.writeFileSync(outPath, buffer);
|
|
9690
9821
|
success(`Invoice saved to ${outPath}`);
|
|
9691
9822
|
} catch (error) {
|
|
9692
9823
|
handleError(error);
|
|
@@ -9696,9 +9827,9 @@ Examples:
|
|
|
9696
9827
|
|
|
9697
9828
|
// src/commands/shell/index.ts
|
|
9698
9829
|
import chalk31 from "chalk";
|
|
9699
|
-
import * as
|
|
9830
|
+
import * as fs12 from "fs";
|
|
9700
9831
|
import * as os3 from "os";
|
|
9701
|
-
import * as
|
|
9832
|
+
import * as path9 from "path";
|
|
9702
9833
|
import { spawn as spawn3 } from "child_process";
|
|
9703
9834
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
9704
9835
|
function extensionFor2(language) {
|
|
@@ -9711,16 +9842,16 @@ function extensionFor2(language) {
|
|
|
9711
9842
|
return "txt";
|
|
9712
9843
|
}
|
|
9713
9844
|
async function openInEditor(initial, ext) {
|
|
9714
|
-
const tmpFile =
|
|
9715
|
-
|
|
9845
|
+
const tmpFile = path9.join(os3.tmpdir(), `diafunc-shell-${randomUUID3()}.${ext}`);
|
|
9846
|
+
fs12.writeFileSync(tmpFile, initial);
|
|
9716
9847
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
9717
9848
|
await new Promise((resolve, reject) => {
|
|
9718
9849
|
const child = spawn3(editor, [tmpFile], { stdio: "inherit" });
|
|
9719
9850
|
child.on("exit", (code) => code === 0 ? resolve() : reject(new Error(`Editor exited with ${code}`)));
|
|
9720
9851
|
child.on("error", reject);
|
|
9721
9852
|
});
|
|
9722
|
-
const content =
|
|
9723
|
-
|
|
9853
|
+
const content = fs12.readFileSync(tmpFile, "utf-8");
|
|
9854
|
+
fs12.unlinkSync(tmpFile);
|
|
9724
9855
|
return content;
|
|
9725
9856
|
}
|
|
9726
9857
|
function utcNowParts() {
|
|
@@ -9796,7 +9927,7 @@ function registerShellCommand(program) {
|
|
|
9796
9927
|
});
|
|
9797
9928
|
const api = createApiClient();
|
|
9798
9929
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
9799
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
9930
|
+
const { getUpdateNotice } = await import("./update-check-TTXILAMD.js");
|
|
9800
9931
|
const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
|
|
9801
9932
|
console.log(chalk31.bold("Diafunc shell") + chalk31.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
|
|
9802
9933
|
console.log(chalk31.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
@@ -9853,11 +9984,11 @@ function registerShellCommand(program) {
|
|
|
9853
9984
|
console.log(chalk31.dim("usage: /file <path>"));
|
|
9854
9985
|
continue;
|
|
9855
9986
|
}
|
|
9856
|
-
if (!
|
|
9987
|
+
if (!fs12.existsSync(arg)) {
|
|
9857
9988
|
console.log(chalk31.red(`file not found: ${arg}`));
|
|
9858
9989
|
continue;
|
|
9859
9990
|
}
|
|
9860
|
-
const sourceCode =
|
|
9991
|
+
const sourceCode = fs12.readFileSync(arg, "utf-8");
|
|
9861
9992
|
try {
|
|
9862
9993
|
await evaluate(api, fnRef, language, sourceCode);
|
|
9863
9994
|
} catch (e) {
|
|
@@ -9884,18 +10015,18 @@ function registerShellCommand(program) {
|
|
|
9884
10015
|
|
|
9885
10016
|
// src/commands/update/index.ts
|
|
9886
10017
|
import chalk32 from "chalk";
|
|
9887
|
-
import * as
|
|
10018
|
+
import * as path10 from "path";
|
|
9888
10019
|
import { spawn as spawn4 } from "child_process";
|
|
9889
10020
|
|
|
9890
10021
|
// src/util/install-method.ts
|
|
9891
|
-
import * as
|
|
10022
|
+
import * as fs13 from "fs";
|
|
9892
10023
|
function detectInstall() {
|
|
9893
10024
|
const exec = process.execPath;
|
|
9894
10025
|
const exe = exec.replace(/\\/g, "/").toLowerCase();
|
|
9895
10026
|
const isNode = exe.endsWith("/node") || exe.endsWith("/node.exe");
|
|
9896
10027
|
return {
|
|
9897
10028
|
method: isNode ? "npm" : "binary",
|
|
9898
|
-
binaryPath: isNode ? exec :
|
|
10029
|
+
binaryPath: isNode ? exec : fs13.realpathSync(exec)
|
|
9899
10030
|
};
|
|
9900
10031
|
}
|
|
9901
10032
|
|
|
@@ -9939,7 +10070,7 @@ function registerUpdateCommand(program) {
|
|
|
9939
10070
|
console.log(chalk32.bold(` npm install -g @diafunc/cli@${latest}`));
|
|
9940
10071
|
return;
|
|
9941
10072
|
}
|
|
9942
|
-
const installDir =
|
|
10073
|
+
const installDir = path10.dirname(install.binaryPath);
|
|
9943
10074
|
console.log(`Installing diafunc ${latest} to ${installDir}...`);
|
|
9944
10075
|
console.log();
|
|
9945
10076
|
await runInstaller(installDir);
|
|
@@ -9952,18 +10083,18 @@ function registerUpdateCommand(program) {
|
|
|
9952
10083
|
// src/commands/uninstall/index.ts
|
|
9953
10084
|
import chalk33 from "chalk";
|
|
9954
10085
|
import { spawn as spawn5 } from "child_process";
|
|
9955
|
-
import * as
|
|
10086
|
+
import * as fs14 from "fs";
|
|
9956
10087
|
import * as os4 from "os";
|
|
9957
|
-
import * as
|
|
10088
|
+
import * as path11 from "path";
|
|
9958
10089
|
function registerUninstallCommand(program) {
|
|
9959
10090
|
program.command("uninstall").description("Remove the CLI binary and (optionally) its config from this machine").option("-y, --yes", "Skip confirmation prompts").option("--purge", "Also remove ~/.diafunc/ (config + credentials) without prompting").action(async (options) => {
|
|
9960
10091
|
try {
|
|
9961
10092
|
const install = detectInstall();
|
|
9962
|
-
const configDir =
|
|
10093
|
+
const configDir = path11.join(os4.homedir(), ".diafunc");
|
|
9963
10094
|
if (install.method === "npm") {
|
|
9964
10095
|
console.log("Installed via npm. Remove with:");
|
|
9965
10096
|
console.log(chalk33.bold(" npm uninstall -g @diafunc/cli"));
|
|
9966
|
-
if (
|
|
10097
|
+
if (fs14.existsSync(configDir)) {
|
|
9967
10098
|
console.log();
|
|
9968
10099
|
console.log(`Config and credentials live at ${configDir}. Remove them manually with:`);
|
|
9969
10100
|
console.log(chalk33.bold(` rm -rf ${configDir}`));
|
|
@@ -9980,14 +10111,14 @@ function registerUninstallCommand(program) {
|
|
|
9980
10111
|
return;
|
|
9981
10112
|
}
|
|
9982
10113
|
let removeConfig = options.purge ?? false;
|
|
9983
|
-
if (!options.purge && !options.yes &&
|
|
10114
|
+
if (!options.purge && !options.yes && fs14.existsSync(configDir)) {
|
|
9984
10115
|
removeConfig = await confirm({
|
|
9985
10116
|
message: `Also remove ${configDir} (config + credentials)?`,
|
|
9986
10117
|
default: false
|
|
9987
10118
|
});
|
|
9988
10119
|
}
|
|
9989
|
-
if (removeConfig &&
|
|
9990
|
-
|
|
10120
|
+
if (removeConfig && fs14.existsSync(configDir)) {
|
|
10121
|
+
fs14.rmSync(configDir, { recursive: true, force: true });
|
|
9991
10122
|
console.log(chalk33.dim(`Removed ${configDir}`));
|
|
9992
10123
|
}
|
|
9993
10124
|
if (process.platform === "win32") {
|
|
@@ -10003,7 +10134,7 @@ function registerUninstallCommand(program) {
|
|
|
10003
10134
|
console.log("diafunc uninstalled.");
|
|
10004
10135
|
return;
|
|
10005
10136
|
}
|
|
10006
|
-
|
|
10137
|
+
fs14.rmSync(install.binaryPath, { force: true });
|
|
10007
10138
|
console.log(chalk33.dim(`Removed ${install.binaryPath}`));
|
|
10008
10139
|
console.log();
|
|
10009
10140
|
console.log("diafunc uninstalled.");
|
|
@@ -10191,11 +10322,11 @@ var BY_NAME = {
|
|
|
10191
10322
|
function tokenOf(input) {
|
|
10192
10323
|
return input.kind === "option" ? input.flag ?? `--${input.name}` : `<${input.name}>`;
|
|
10193
10324
|
}
|
|
10194
|
-
function specFor(
|
|
10195
|
-
const exact = BY_COMMAND[
|
|
10325
|
+
function specFor(path12, input) {
|
|
10326
|
+
const exact = BY_COMMAND[path12]?.[tokenOf(input)];
|
|
10196
10327
|
if (exact) return exact;
|
|
10197
|
-
const group =
|
|
10198
|
-
const sub =
|
|
10328
|
+
const group = path12.split(" ")[0];
|
|
10329
|
+
const sub = path12.split(" ").slice(0, 2).join(" ");
|
|
10199
10330
|
switch (input.name) {
|
|
10200
10331
|
case "ref":
|
|
10201
10332
|
case "sourceRef":
|
|
@@ -10262,7 +10393,7 @@ function dependencies(spec) {
|
|
|
10262
10393
|
}
|
|
10263
10394
|
|
|
10264
10395
|
// src/prompting/pickers.ts
|
|
10265
|
-
import * as
|
|
10396
|
+
import * as fs15 from "fs";
|
|
10266
10397
|
import chalk34 from "chalk";
|
|
10267
10398
|
var SEARCH_THRESHOLD = 10;
|
|
10268
10399
|
var TYPE_IT = "\0type-it";
|
|
@@ -10397,7 +10528,7 @@ async function askFor(spec, input, ctx) {
|
|
|
10397
10528
|
}
|
|
10398
10529
|
case "file":
|
|
10399
10530
|
return typed(ctx, question(input), {
|
|
10400
|
-
validate: (value) =>
|
|
10531
|
+
validate: (value) => fs15.existsSync(value.trim()) || `No file at ${value.trim()}.`
|
|
10401
10532
|
});
|
|
10402
10533
|
case "number":
|
|
10403
10534
|
return typed(ctx, question(input), { validate: numberRule(spec) });
|
|
@@ -10843,4 +10974,4 @@ export {
|
|
|
10843
10974
|
PromptCancelled,
|
|
10844
10975
|
createProgram
|
|
10845
10976
|
};
|
|
10846
|
-
//# sourceMappingURL=chunk-
|
|
10977
|
+
//# sourceMappingURL=chunk-OCZSFCU6.js.map
|