@diafunc/cli 0.25.0 → 0.27.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 +12 -5
- package/dist/bin/diafunc.js +3 -3
- package/dist/{chunk-DOVJKPLM.js → chunk-GNSV63PW.js} +2 -2
- package/dist/{chunk-DOVJKPLM.js.map → chunk-GNSV63PW.js.map} +1 -1
- package/dist/{chunk-RJM7OBRF.js → chunk-HYUMMSA2.js} +1586 -582
- package/dist/chunk-HYUMMSA2.js.map +1 -0
- package/dist/{chunk-2RII4SNX.js → chunk-ZM4QVYYB.js} +2 -2
- package/dist/src/index.js +2 -2
- package/dist/update-check-YRTWCRNY.js +8 -0
- package/package.json +1 -1
- package/dist/chunk-RJM7OBRF.js.map +0 -1
- package/dist/update-check-F2A6LMK6.js +0 -8
- /package/dist/{chunk-2RII4SNX.js.map → chunk-ZM4QVYYB.js.map} +0 -0
- /package/dist/{update-check-F2A6LMK6.js.map → update-check-YRTWCRNY.js.map} +0 -0
|
@@ -1,19 +1,182 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GNSV63PW.js";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
|
-
import
|
|
6
|
+
import chalk40 from "chalk";
|
|
7
7
|
|
|
8
8
|
// src/commands/auth/login.ts
|
|
9
9
|
import chalk4 from "chalk";
|
|
10
10
|
|
|
11
11
|
// src/config/store.ts
|
|
12
|
+
import * as fs2 from "fs";
|
|
13
|
+
import * as path2 from "path";
|
|
14
|
+
import * as os2 from "os";
|
|
15
|
+
import * as crypto2 from "crypto";
|
|
16
|
+
|
|
17
|
+
// src/config/lock.ts
|
|
18
|
+
import * as crypto from "crypto";
|
|
12
19
|
import * as fs from "fs";
|
|
13
|
-
import * as path from "path";
|
|
14
20
|
import * as os from "os";
|
|
15
|
-
|
|
16
|
-
var
|
|
21
|
+
import * as path from "path";
|
|
22
|
+
var LockTimeoutError = class extends Error {
|
|
23
|
+
lockPath;
|
|
24
|
+
constructor(lockPath, waitedMs) {
|
|
25
|
+
super(`Timed out after ${Math.round(waitedMs / 1e3)}s waiting for ${lockPath}.`);
|
|
26
|
+
this.name = "LockTimeoutError";
|
|
27
|
+
this.lockPath = lockPath;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var DEFAULT_STALE_MS = 3e4;
|
|
31
|
+
var DEFAULT_WAIT_MS = 25e3;
|
|
32
|
+
var DEFAULT_POLL_MS = 120;
|
|
33
|
+
var held = /* @__PURE__ */ new Map();
|
|
34
|
+
var exitHookInstalled = false;
|
|
35
|
+
function installExitHook() {
|
|
36
|
+
if (exitHookInstalled) return;
|
|
37
|
+
exitHookInstalled = true;
|
|
38
|
+
process.on("exit", () => {
|
|
39
|
+
for (const [lockPath, id] of held) removeIfOwned(lockPath, id);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function processIsAlive(pid) {
|
|
43
|
+
try {
|
|
44
|
+
process.kill(pid, 0);
|
|
45
|
+
return true;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return error.code === "EPERM";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function readHolder(lockPath) {
|
|
51
|
+
let raw;
|
|
52
|
+
try {
|
|
53
|
+
raw = fs.readFileSync(lockPath, "utf-8");
|
|
54
|
+
} catch (error) {
|
|
55
|
+
return error.code === "ENOENT" ? "absent" : "unreadable";
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const parsed = JSON.parse(raw);
|
|
59
|
+
if (typeof parsed.id === "string" && typeof parsed.pid === "number" && typeof parsed.createdAt === "number") {
|
|
60
|
+
return { id: parsed.id, pid: parsed.pid, host: String(parsed.host ?? ""), createdAt: parsed.createdAt };
|
|
61
|
+
}
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
return "unreadable";
|
|
65
|
+
}
|
|
66
|
+
function isStale(lockPath, holder, staleMs, isAlive) {
|
|
67
|
+
if (holder === "unreadable") {
|
|
68
|
+
try {
|
|
69
|
+
return Date.now() - fs.statSync(lockPath).mtimeMs > staleMs;
|
|
70
|
+
} catch {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (Date.now() - holder.createdAt > staleMs) return true;
|
|
75
|
+
return holder.host === os.hostname() && !isAlive(holder.pid);
|
|
76
|
+
}
|
|
77
|
+
function removeIfOwned(lockPath, id) {
|
|
78
|
+
const holder = readHolder(lockPath);
|
|
79
|
+
if (holder !== "absent" && holder !== "unreadable" && holder.id === id) {
|
|
80
|
+
try {
|
|
81
|
+
fs.unlinkSync(lockPath);
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function tryCreate(lockPath, content) {
|
|
87
|
+
let fd;
|
|
88
|
+
try {
|
|
89
|
+
fd = fs.openSync(lockPath, "wx", 384);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
const code = error.code;
|
|
92
|
+
if (code === "EEXIST") return false;
|
|
93
|
+
if (process.platform === "win32" && (code === "EPERM" || code === "EACCES" || code === "EBUSY")) return false;
|
|
94
|
+
if (code === "ENOENT") {
|
|
95
|
+
fs.mkdirSync(path.dirname(lockPath), { recursive: true, mode: 448 });
|
|
96
|
+
return tryCreate(lockPath, content);
|
|
97
|
+
}
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
fs.writeSync(fd, content);
|
|
102
|
+
} finally {
|
|
103
|
+
fs.closeSync(fd);
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
function removeStale(lockPath, staleMs, isAlive) {
|
|
108
|
+
const breaker = `${lockPath}.break`;
|
|
109
|
+
if (!tryCreate(breaker, "")) {
|
|
110
|
+
try {
|
|
111
|
+
if (Date.now() - fs.statSync(breaker).mtimeMs > staleMs) fs.unlinkSync(breaker);
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const holder = readHolder(lockPath);
|
|
118
|
+
if (holder !== "absent" && isStale(lockPath, holder, staleMs, isAlive)) {
|
|
119
|
+
try {
|
|
120
|
+
fs.unlinkSync(lockPath);
|
|
121
|
+
} catch {
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
} finally {
|
|
125
|
+
try {
|
|
126
|
+
fs.unlinkSync(breaker);
|
|
127
|
+
} catch {
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function pause(ms) {
|
|
132
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
133
|
+
}
|
|
134
|
+
async function acquireFileLock(lockPath, options = {}) {
|
|
135
|
+
const staleMs = options.staleMs ?? DEFAULT_STALE_MS;
|
|
136
|
+
const waitMs = options.waitMs ?? DEFAULT_WAIT_MS;
|
|
137
|
+
const pollMs = options.pollMs ?? DEFAULT_POLL_MS;
|
|
138
|
+
const isAlive = options.isAlive ?? processIsAlive;
|
|
139
|
+
const id = crypto.randomUUID();
|
|
140
|
+
const startedAt = Date.now();
|
|
141
|
+
for (; ; ) {
|
|
142
|
+
const content = JSON.stringify({ id, pid: process.pid, host: os.hostname(), createdAt: Date.now() });
|
|
143
|
+
if (tryCreate(lockPath, content)) {
|
|
144
|
+
installExitHook();
|
|
145
|
+
held.set(lockPath, id);
|
|
146
|
+
let released = false;
|
|
147
|
+
return {
|
|
148
|
+
release() {
|
|
149
|
+
if (released) return;
|
|
150
|
+
released = true;
|
|
151
|
+
if (held.get(lockPath) === id) held.delete(lockPath);
|
|
152
|
+
removeIfOwned(lockPath, id);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const waited = Date.now() - startedAt;
|
|
157
|
+
if (waited >= waitMs) throw new LockTimeoutError(lockPath, waited);
|
|
158
|
+
const holder = readHolder(lockPath);
|
|
159
|
+
let free = holder === "absent";
|
|
160
|
+
if (holder !== "absent" && isStale(lockPath, holder, staleMs, isAlive)) {
|
|
161
|
+
removeStale(lockPath, staleMs, isAlive);
|
|
162
|
+
free = true;
|
|
163
|
+
}
|
|
164
|
+
const nap = free ? 1 + 4 * Math.random() : pollMs * (0.25 + 0.75 * Math.random());
|
|
165
|
+
await pause(Math.min(nap, Math.max(1, waitMs - waited)));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async function withFileLock(lockPath, work, options = {}) {
|
|
169
|
+
const lock = await acquireFileLock(lockPath, options);
|
|
170
|
+
try {
|
|
171
|
+
return await work();
|
|
172
|
+
} finally {
|
|
173
|
+
lock.release();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/config/store.ts
|
|
178
|
+
var CONFIG_DIR = path2.join(os2.homedir(), ".diafunc");
|
|
179
|
+
var CONFIG_FILE = path2.join(CONFIG_DIR, "config.json");
|
|
17
180
|
var DEFAULT_CONFIG = {
|
|
18
181
|
currentProfile: "default",
|
|
19
182
|
profiles: {
|
|
@@ -24,25 +187,63 @@ var DEFAULT_CONFIG = {
|
|
|
24
187
|
defaults: {}
|
|
25
188
|
};
|
|
26
189
|
function ensureConfigDir() {
|
|
27
|
-
if (!
|
|
28
|
-
|
|
190
|
+
if (!fs2.existsSync(CONFIG_DIR)) {
|
|
191
|
+
fs2.mkdirSync(CONFIG_DIR, { recursive: true, mode: 448 });
|
|
29
192
|
}
|
|
30
193
|
}
|
|
31
194
|
function loadConfig() {
|
|
32
|
-
if (!
|
|
195
|
+
if (!fs2.existsSync(CONFIG_FILE)) {
|
|
33
196
|
return structuredClone(DEFAULT_CONFIG);
|
|
34
197
|
}
|
|
35
|
-
const raw =
|
|
198
|
+
const raw = fs2.readFileSync(CONFIG_FILE, "utf-8");
|
|
36
199
|
return JSON.parse(raw);
|
|
37
200
|
}
|
|
38
201
|
function saveConfig(config) {
|
|
39
202
|
ensureConfigDir();
|
|
40
|
-
const tmp = CONFIG_FILE
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
203
|
+
const tmp = `${CONFIG_FILE}.${process.pid}.${crypto2.randomBytes(4).toString("hex")}.tmp`;
|
|
204
|
+
try {
|
|
205
|
+
fs2.writeFileSync(tmp, JSON.stringify(config, null, 2) + "\n", {
|
|
206
|
+
encoding: "utf-8",
|
|
207
|
+
mode: 384
|
|
208
|
+
});
|
|
209
|
+
renameIntoPlace(tmp, CONFIG_FILE);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
fs2.rmSync(tmp, { force: true });
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function renameIntoPlace(from, to) {
|
|
216
|
+
for (let attempt = 1; ; attempt++) {
|
|
217
|
+
try {
|
|
218
|
+
fs2.renameSync(from, to);
|
|
219
|
+
return;
|
|
220
|
+
} catch (error) {
|
|
221
|
+
const code = error.code ?? "";
|
|
222
|
+
if (attempt >= 10 || !["EPERM", "EACCES", "EBUSY"].includes(code)) throw error;
|
|
223
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 20 * attempt);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
var STORE_LOCK_FILE = `${CONFIG_FILE}.lock`;
|
|
228
|
+
async function updateStoredProfile(profileName, change2) {
|
|
229
|
+
return withFileLock(STORE_LOCK_FILE, () => {
|
|
230
|
+
const config = loadConfig();
|
|
231
|
+
const profile = config.profiles[profileName];
|
|
232
|
+
if (!profile) {
|
|
233
|
+
throw new Error(`Profile "${profileName}" not found.`);
|
|
234
|
+
}
|
|
235
|
+
change2(profile);
|
|
236
|
+
saveConfig(config);
|
|
237
|
+
return config;
|
|
238
|
+
}, { waitMs: 5e3 });
|
|
239
|
+
}
|
|
240
|
+
function readStoredProfile(profileName) {
|
|
241
|
+
return loadConfig().profiles[profileName];
|
|
242
|
+
}
|
|
243
|
+
function profileSidecarFile(profileName, suffix) {
|
|
244
|
+
const safe = profileName.replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 40);
|
|
245
|
+
const digest = crypto2.createHash("sha256").update(profileName).digest("hex").slice(0, 8);
|
|
246
|
+
return `${CONFIG_FILE}.${safe}-${digest}.${suffix}`;
|
|
46
247
|
}
|
|
47
248
|
function resolveEndpoint(config, profileOverride) {
|
|
48
249
|
const name = profileOverride ?? config.currentProfile;
|
|
@@ -57,19 +258,31 @@ function resolveEndpoint(config, profileOverride) {
|
|
|
57
258
|
import chalk from "chalk";
|
|
58
259
|
|
|
59
260
|
// src/client/errors.ts
|
|
261
|
+
var LICENCE_REFUSALS = {
|
|
262
|
+
licence_required: "A public project needs a licence. Name one with --licence <id>.",
|
|
263
|
+
licence_not_selectable: "That licence cannot be chosen: it is not in the catalogue, or it is deprecated or withdrawn.",
|
|
264
|
+
licence_share_alike_mismatch: "This project is a fork of a share-alike project, so it has to carry the licence of the project it was forked from.",
|
|
265
|
+
licence_forbids_fork: "The licence of this project does not allow adaptations, so it cannot be forked."
|
|
266
|
+
};
|
|
267
|
+
var LICENCE_LIST_REFUSALS = /* @__PURE__ */ new Set(["licence_required", "licence_not_selectable"]);
|
|
60
268
|
var ApiError = class _ApiError extends Error {
|
|
61
269
|
status;
|
|
62
270
|
details;
|
|
63
|
-
|
|
271
|
+
/** The platform's stable error code, when the body carried one. */
|
|
272
|
+
code;
|
|
273
|
+
constructor(status, message, details, code) {
|
|
64
274
|
super(message);
|
|
65
275
|
this.name = "ApiError";
|
|
66
276
|
this.status = status;
|
|
67
277
|
this.details = details;
|
|
278
|
+
this.code = code;
|
|
68
279
|
}
|
|
69
280
|
static fromBody(status, body) {
|
|
70
|
-
return new _ApiError(status, body.message, body.details);
|
|
281
|
+
return new _ApiError(status, body.message, body.details, typeof body.error === "string" ? body.error : void 0);
|
|
71
282
|
}
|
|
72
283
|
toUserMessage() {
|
|
284
|
+
const refusal = this.code && Object.prototype.hasOwnProperty.call(LICENCE_REFUSALS, this.code) ? LICENCE_REFUSALS[this.code] : void 0;
|
|
285
|
+
if (refusal) return refusal;
|
|
73
286
|
const detail2 = this.readableMessage();
|
|
74
287
|
switch (this.status) {
|
|
75
288
|
case 401:
|
|
@@ -119,13 +332,207 @@ var NetworkError = class extends Error {
|
|
|
119
332
|
}
|
|
120
333
|
};
|
|
121
334
|
|
|
335
|
+
// src/client/sign-in.ts
|
|
336
|
+
import * as crypto3 from "crypto";
|
|
337
|
+
import * as fs3 from "fs";
|
|
338
|
+
var EXPIRY_MARGIN_MS = 3e4;
|
|
339
|
+
var TOKEN_REQUEST_TIMEOUT_MS = 1e4;
|
|
340
|
+
var MAX_RATE_LIMITED_ATTEMPTS = 3;
|
|
341
|
+
var DEFAULT_BACKOFF_MS = 5e3;
|
|
342
|
+
var MIN_BACKOFF_MS = 1e3;
|
|
343
|
+
var MAX_BACKOFF_MS = 12e4;
|
|
344
|
+
var NOTICE_THRESHOLD_MS = 2e3;
|
|
345
|
+
var SignInRefusedError = class extends ApiError {
|
|
346
|
+
constructor(profileName) {
|
|
347
|
+
super(401, `The stored sign-in of profile "${profileName}" is no longer accepted. Run 'diafunc auth login' to sign in again.`);
|
|
348
|
+
this.name = "SignInRefusedError";
|
|
349
|
+
}
|
|
350
|
+
toUserMessage() {
|
|
351
|
+
return this.message;
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
function isAuthenticationFailure(error) {
|
|
355
|
+
return error instanceof ApiError && error.status === 401;
|
|
356
|
+
}
|
|
357
|
+
function isTokenExpired(auth) {
|
|
358
|
+
if (!auth) return false;
|
|
359
|
+
if (auth.type === "device-code") {
|
|
360
|
+
return Date.now() >= auth.accessTokenExpiry - EXPIRY_MARGIN_MS;
|
|
361
|
+
}
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
function deriveAuthUrl(endpoint) {
|
|
365
|
+
const trimmed = endpoint.replace(/\/+$/, "");
|
|
366
|
+
if (trimmed.includes("://auth.")) {
|
|
367
|
+
return trimmed;
|
|
368
|
+
}
|
|
369
|
+
const url = new URL(trimmed);
|
|
370
|
+
url.hostname = `auth.${url.hostname}`;
|
|
371
|
+
url.pathname = "";
|
|
372
|
+
return url.toString().replace(/\/+$/, "");
|
|
373
|
+
}
|
|
374
|
+
function digestOf(token) {
|
|
375
|
+
return crypto3.createHash("sha256").update(token).digest("hex");
|
|
376
|
+
}
|
|
377
|
+
function retryAfterMs(header, now = Date.now()) {
|
|
378
|
+
let wait = DEFAULT_BACKOFF_MS;
|
|
379
|
+
if (header) {
|
|
380
|
+
const seconds = Number(header.trim());
|
|
381
|
+
if (Number.isFinite(seconds)) {
|
|
382
|
+
wait = seconds * 1e3;
|
|
383
|
+
} else {
|
|
384
|
+
const at = Date.parse(header);
|
|
385
|
+
if (Number.isFinite(at)) wait = at - now;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return Math.min(MAX_BACKOFF_MS, Math.max(MIN_BACKOFF_MS, wait));
|
|
389
|
+
}
|
|
390
|
+
function createSignInRefresher(options = {}) {
|
|
391
|
+
const sleep4 = options.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
|
|
392
|
+
const notify = options.notify ?? ((message) => console.error(message));
|
|
393
|
+
const lockOptions = { waitMs: options.lockWaitMs, staleMs: options.lockStaleMs };
|
|
394
|
+
const inFlight = /* @__PURE__ */ new Map();
|
|
395
|
+
const notBefore = /* @__PURE__ */ new Map();
|
|
396
|
+
const refused = /* @__PURE__ */ new Set();
|
|
397
|
+
function refusedMarkerFile(profileName) {
|
|
398
|
+
return profileSidecarFile(profileName, "refused");
|
|
399
|
+
}
|
|
400
|
+
function isKnownRefused(profileName, refreshToken) {
|
|
401
|
+
const digest = digestOf(refreshToken);
|
|
402
|
+
if (refused.has(digest)) return true;
|
|
403
|
+
try {
|
|
404
|
+
return fs3.readFileSync(refusedMarkerFile(profileName), "utf-8").trim() === digest;
|
|
405
|
+
} catch {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function rememberRefused(profileName, refreshToken, acrossProcesses) {
|
|
410
|
+
const digest = digestOf(refreshToken);
|
|
411
|
+
refused.add(digest);
|
|
412
|
+
if (!acrossProcesses) return;
|
|
413
|
+
try {
|
|
414
|
+
fs3.writeFileSync(refusedMarkerFile(profileName), digest + "\n", { encoding: "utf-8", mode: 384 });
|
|
415
|
+
} catch {
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function forgetRefused(profileName) {
|
|
419
|
+
fs3.rmSync(refusedMarkerFile(profileName), { force: true });
|
|
420
|
+
}
|
|
421
|
+
async function requestTokens(endpoint, auth) {
|
|
422
|
+
try {
|
|
423
|
+
return await fetch(`${deriveAuthUrl(endpoint)}/token`, {
|
|
424
|
+
method: "POST",
|
|
425
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
426
|
+
body: new URLSearchParams({
|
|
427
|
+
grant_type: "refresh_token",
|
|
428
|
+
refresh_token: auth.refreshToken,
|
|
429
|
+
client_id: auth.clientId
|
|
430
|
+
}).toString(),
|
|
431
|
+
signal: AbortSignal.timeout(TOKEN_REQUEST_TIMEOUT_MS)
|
|
432
|
+
});
|
|
433
|
+
} catch (error) {
|
|
434
|
+
throw new NetworkError(
|
|
435
|
+
`Could not reach the sign-in service of ${endpoint} to renew the sign-in.`,
|
|
436
|
+
error instanceof Error ? error : void 0
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
async function renewUnderLock(profileName) {
|
|
441
|
+
const profile = readStoredProfile(profileName);
|
|
442
|
+
const stored = profile?.auth;
|
|
443
|
+
if (!profile || !stored) {
|
|
444
|
+
throw new SignInRefusedError(profileName);
|
|
445
|
+
}
|
|
446
|
+
if (stored.type !== "device-code" || !isTokenExpired(stored)) {
|
|
447
|
+
return { kind: "credentials", auth: stored };
|
|
448
|
+
}
|
|
449
|
+
if (isKnownRefused(profileName, stored.refreshToken)) {
|
|
450
|
+
throw new SignInRefusedError(profileName);
|
|
451
|
+
}
|
|
452
|
+
let response;
|
|
453
|
+
try {
|
|
454
|
+
response = await requestTokens(profile.endpoint.replace(/\/+$/, ""), stored);
|
|
455
|
+
} catch (error) {
|
|
456
|
+
notBefore.set(profileName, Date.now() + DEFAULT_BACKOFF_MS);
|
|
457
|
+
throw error;
|
|
458
|
+
}
|
|
459
|
+
if (response.ok) {
|
|
460
|
+
const body = await response.json();
|
|
461
|
+
const renewed = {
|
|
462
|
+
type: "device-code",
|
|
463
|
+
clientId: stored.clientId,
|
|
464
|
+
accessToken: body.access_token,
|
|
465
|
+
refreshToken: body.refresh_token ?? stored.refreshToken,
|
|
466
|
+
accessTokenExpiry: Date.now() + body.expires_in * 1e3
|
|
467
|
+
};
|
|
468
|
+
await updateStoredProfile(profileName, (target) => {
|
|
469
|
+
target.auth = renewed;
|
|
470
|
+
});
|
|
471
|
+
forgetRefused(profileName);
|
|
472
|
+
return { kind: "credentials", auth: renewed };
|
|
473
|
+
}
|
|
474
|
+
if (response.status === 429) {
|
|
475
|
+
return { kind: "rate-limited", retryAfterMs: retryAfterMs(response.headers.get("retry-after")) };
|
|
476
|
+
}
|
|
477
|
+
if (response.status === 400 || response.status === 401) {
|
|
478
|
+
const reason2 = await response.json().then((body) => body.error, () => void 0);
|
|
479
|
+
const current = readStoredProfile(profileName)?.auth;
|
|
480
|
+
if (current && (current.type !== "device-code" || current.refreshToken !== stored.refreshToken)) {
|
|
481
|
+
return { kind: "credentials", auth: current };
|
|
482
|
+
}
|
|
483
|
+
rememberRefused(profileName, stored.refreshToken, reason2 === "invalid_grant");
|
|
484
|
+
throw new SignInRefusedError(profileName);
|
|
485
|
+
}
|
|
486
|
+
notBefore.set(profileName, Date.now() + DEFAULT_BACKOFF_MS);
|
|
487
|
+
throw new ApiError(response.status, `The sign-in service answered ${response.status} while renewing the sign-in.`);
|
|
488
|
+
}
|
|
489
|
+
async function waitOutBackoff(profileName) {
|
|
490
|
+
const wait = (notBefore.get(profileName) ?? 0) - Date.now();
|
|
491
|
+
if (wait <= 0) return;
|
|
492
|
+
if (wait >= NOTICE_THRESHOLD_MS) {
|
|
493
|
+
notify(`The sign-in service asked to wait; renewing the sign-in in ${Math.ceil(wait / 1e3)} s.`);
|
|
494
|
+
}
|
|
495
|
+
await sleep4(wait + Math.floor(Math.random() * 250));
|
|
496
|
+
}
|
|
497
|
+
async function renew(profileName) {
|
|
498
|
+
for (let attempt = 1; ; attempt++) {
|
|
499
|
+
await waitOutBackoff(profileName);
|
|
500
|
+
let outcome;
|
|
501
|
+
try {
|
|
502
|
+
outcome = await withFileLock(profileSidecarFile(profileName, "refresh.lock"), () => renewUnderLock(profileName), lockOptions);
|
|
503
|
+
} catch (error) {
|
|
504
|
+
if (!(error instanceof LockTimeoutError)) throw error;
|
|
505
|
+
const stored = readStoredProfile(profileName)?.auth;
|
|
506
|
+
if (stored && !isTokenExpired(stored)) return stored;
|
|
507
|
+
throw new NetworkError("Another diafunc process is still renewing the sign-in of this profile. Try again in a moment.");
|
|
508
|
+
}
|
|
509
|
+
if (outcome.kind === "credentials") return outcome.auth;
|
|
510
|
+
notBefore.set(profileName, Date.now() + outcome.retryAfterMs);
|
|
511
|
+
if (attempt >= MAX_RATE_LIMITED_ATTEMPTS) {
|
|
512
|
+
throw new ApiError(429, `The sign-in service is limiting requests from this address. Try again in ${Math.ceil(outcome.retryAfterMs / 1e3)} s.`);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return {
|
|
517
|
+
ensureFresh(profileName) {
|
|
518
|
+
let pending = inFlight.get(profileName);
|
|
519
|
+
if (!pending) {
|
|
520
|
+
pending = renew(profileName).finally(() => inFlight.delete(profileName));
|
|
521
|
+
inFlight.set(profileName, pending);
|
|
522
|
+
}
|
|
523
|
+
return pending;
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
var sharedSignIn = createSignInRefresher();
|
|
528
|
+
|
|
122
529
|
// src/client/http.ts
|
|
123
530
|
var REQUEST_TIMEOUT_MS = 6e4;
|
|
124
531
|
var RETRYABLE_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
125
532
|
var MAX_ATTEMPTS = 3;
|
|
126
533
|
var RETRYABLE_METHODS = /* @__PURE__ */ new Set(["GET"]);
|
|
127
|
-
function buildUrl(endpoint, service,
|
|
128
|
-
const base = `${endpoint}/api/v1/${service}${
|
|
534
|
+
function buildUrl(endpoint, service, path13, query) {
|
|
535
|
+
const base = `${endpoint}/api/v1/${service}${path13}`;
|
|
129
536
|
const params = new URLSearchParams();
|
|
130
537
|
if (query) {
|
|
131
538
|
for (const [key, value] of Object.entries(query)) {
|
|
@@ -147,62 +554,12 @@ function getAuthHeader(auth) {
|
|
|
147
554
|
}
|
|
148
555
|
return void 0;
|
|
149
556
|
}
|
|
150
|
-
function isTokenExpired(auth) {
|
|
151
|
-
if (!auth) return false;
|
|
152
|
-
if (auth.type === "device-code") {
|
|
153
|
-
return Date.now() >= auth.accessTokenExpiry - 3e4;
|
|
154
|
-
}
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
function deriveAuthUrl(endpoint) {
|
|
158
|
-
const trimmed = endpoint.replace(/\/+$/, "");
|
|
159
|
-
if (trimmed.includes("://auth.")) {
|
|
160
|
-
return trimmed;
|
|
161
|
-
}
|
|
162
|
-
const url = new URL(trimmed);
|
|
163
|
-
url.hostname = `auth.${url.hostname}`;
|
|
164
|
-
url.pathname = "";
|
|
165
|
-
return url.toString().replace(/\/+$/, "");
|
|
166
|
-
}
|
|
167
|
-
async function refreshOAuthTokens(endpoint, clientId, refreshToken) {
|
|
168
|
-
const authUrl = deriveAuthUrl(endpoint);
|
|
169
|
-
const response = await fetch(`${authUrl}/token`, {
|
|
170
|
-
method: "POST",
|
|
171
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
172
|
-
body: new URLSearchParams({
|
|
173
|
-
grant_type: "refresh_token",
|
|
174
|
-
refresh_token: refreshToken,
|
|
175
|
-
client_id: clientId
|
|
176
|
-
}).toString()
|
|
177
|
-
});
|
|
178
|
-
if (!response.ok) {
|
|
179
|
-
throw new ApiError(response.status, "OAuth token refresh failed. Please run `diafunc auth login` again.");
|
|
180
|
-
}
|
|
181
|
-
const body = await response.json();
|
|
182
|
-
return {
|
|
183
|
-
accessToken: body.access_token,
|
|
184
|
-
refreshToken: body.refresh_token,
|
|
185
|
-
accessTokenExpiry: Date.now() + body.expires_in * 1e3
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
557
|
async function ensureValidAuth(config, profileOverride) {
|
|
189
558
|
const profileName = profileOverride ?? config.currentProfile;
|
|
190
559
|
const profile = config.profiles[profileName];
|
|
191
560
|
if (!profile?.auth) return void 0;
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
const endpoint = resolveEndpoint(config, profileOverride);
|
|
196
|
-
if (profile.auth.type === "device-code") {
|
|
197
|
-
const refreshed = await refreshOAuthTokens(endpoint, profile.auth.clientId, profile.auth.refreshToken);
|
|
198
|
-
profile.auth = {
|
|
199
|
-
type: "device-code",
|
|
200
|
-
clientId: profile.auth.clientId,
|
|
201
|
-
accessToken: refreshed.accessToken,
|
|
202
|
-
refreshToken: refreshed.refreshToken,
|
|
203
|
-
accessTokenExpiry: refreshed.accessTokenExpiry
|
|
204
|
-
};
|
|
205
|
-
saveConfig(config);
|
|
561
|
+
if (profile.auth.type === "device-code" && isTokenExpired(profile.auth)) {
|
|
562
|
+
profile.auth = await sharedSignIn.ensureFresh(profileName);
|
|
206
563
|
}
|
|
207
564
|
return profile.auth;
|
|
208
565
|
}
|
|
@@ -315,7 +672,7 @@ ${bodyPreview}`));
|
|
|
315
672
|
);
|
|
316
673
|
}
|
|
317
674
|
function delay(ms) {
|
|
318
|
-
return new Promise((
|
|
675
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
319
676
|
}
|
|
320
677
|
return {
|
|
321
678
|
async request(opts) {
|
|
@@ -391,6 +748,21 @@ function createAdminService(client) {
|
|
|
391
748
|
path: `/projects/${encodeURIComponent(projectId)}`
|
|
392
749
|
});
|
|
393
750
|
},
|
|
751
|
+
// Licences: the catalogue answers anyone, signed in or not.
|
|
752
|
+
async listLicences() {
|
|
753
|
+
return client.request({
|
|
754
|
+
method: "GET",
|
|
755
|
+
service: SERVICE,
|
|
756
|
+
path: "/licences"
|
|
757
|
+
});
|
|
758
|
+
},
|
|
759
|
+
async getLicence(licenceId) {
|
|
760
|
+
return client.request({
|
|
761
|
+
method: "GET",
|
|
762
|
+
service: SERVICE,
|
|
763
|
+
path: `/licences/${encodeURIComponent(licenceId)}`
|
|
764
|
+
});
|
|
765
|
+
},
|
|
394
766
|
async createProject(request) {
|
|
395
767
|
return client.request({
|
|
396
768
|
method: "POST",
|
|
@@ -866,8 +1238,9 @@ function handleError(error) {
|
|
|
866
1238
|
}
|
|
867
1239
|
if (error instanceof ApiError) {
|
|
868
1240
|
failure(error.toUserMessage());
|
|
869
|
-
if (error.status === 401) hint(`Run 'diafunc auth login' to sign in.`);
|
|
1241
|
+
if (error.status === 401 && !(error instanceof SignInRefusedError)) hint(`Run 'diafunc auth login' to sign in.`);
|
|
870
1242
|
if (error.status === 404) hint(`Check the id, or list what exists with the matching 'list' command.`);
|
|
1243
|
+
if (error.code && LICENCE_LIST_REFUSALS.has(error.code)) hint(`List the licences that can be chosen with 'diafunc licence list'.`);
|
|
871
1244
|
process.exit(error.status === 401 || error.status === 403 ? EXIT_AUTH : EXIT_FAILURE);
|
|
872
1245
|
}
|
|
873
1246
|
if (error instanceof NetworkError) {
|
|
@@ -912,7 +1285,7 @@ function registerLoginCommand(parent) {
|
|
|
912
1285
|
}
|
|
913
1286
|
if (options.token) {
|
|
914
1287
|
profile.auth = { type: "api-token", token: options.token };
|
|
915
|
-
|
|
1288
|
+
await storeSignIn(config.currentProfile, profile);
|
|
916
1289
|
const client = createHttpClient();
|
|
917
1290
|
const admin = createAdminService(client);
|
|
918
1291
|
const user = await admin.getMyUser();
|
|
@@ -929,6 +1302,12 @@ function registerLoginCommand(parent) {
|
|
|
929
1302
|
}
|
|
930
1303
|
});
|
|
931
1304
|
}
|
|
1305
|
+
async function storeSignIn(profileName, signedIn) {
|
|
1306
|
+
await updateStoredProfile(profileName, (stored) => {
|
|
1307
|
+
stored.endpoint = signedIn.endpoint;
|
|
1308
|
+
stored.auth = signedIn.auth;
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
932
1311
|
async function deviceCodeLogin(config, profile) {
|
|
933
1312
|
const authUrl = deriveAuthUrl2(profile.endpoint);
|
|
934
1313
|
const deviceResponse = await fetch(`${authUrl}/device_authorization`, {
|
|
@@ -972,7 +1351,7 @@ async function deviceCodeLogin(config, profile) {
|
|
|
972
1351
|
refreshToken: tokens.refresh_token,
|
|
973
1352
|
accessTokenExpiry: Date.now() + (tokens.expires_in || ACCESS_TOKEN_LIFETIME_SECONDS) * 1e3
|
|
974
1353
|
};
|
|
975
|
-
|
|
1354
|
+
await storeSignIn(config.currentProfile, profile);
|
|
976
1355
|
const client = createHttpClient();
|
|
977
1356
|
const admin = createAdminService(client);
|
|
978
1357
|
const user = await admin.getMyUser();
|
|
@@ -1002,7 +1381,7 @@ async function deviceCodeLogin(config, profile) {
|
|
|
1002
1381
|
process.exit(1);
|
|
1003
1382
|
}
|
|
1004
1383
|
function sleep(ms) {
|
|
1005
|
-
return new Promise((
|
|
1384
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
1006
1385
|
}
|
|
1007
1386
|
|
|
1008
1387
|
// src/commands/auth/logout.ts
|
|
@@ -1043,8 +1422,9 @@ function registerLogoutCommand(parent) {
|
|
|
1043
1422
|
} catch {
|
|
1044
1423
|
}
|
|
1045
1424
|
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1425
|
+
await updateStoredProfile(config.currentProfile, (stored) => {
|
|
1426
|
+
delete stored.auth;
|
|
1427
|
+
});
|
|
1048
1428
|
success(`Logged out from profile "${config.currentProfile}".`);
|
|
1049
1429
|
});
|
|
1050
1430
|
}
|
|
@@ -2008,6 +2388,33 @@ function createStorageService(client) {
|
|
|
2008
2388
|
path: `/entities/revert${entityPath(ref)}/${version}`
|
|
2009
2389
|
});
|
|
2010
2390
|
},
|
|
2391
|
+
/**
|
|
2392
|
+
* Adds tags to an entity and takes others off, in one storage transaction. The platform applies
|
|
2393
|
+
* the removals, then the additions, and counts a tag that is already there (or already gone) as
|
|
2394
|
+
* nothing to do; nothing else of the entity is touched.
|
|
2395
|
+
*
|
|
2396
|
+
* A transaction writes an entity that does not exist yet, so a caller that means to change an
|
|
2397
|
+
* existing one reads it first.
|
|
2398
|
+
*/
|
|
2399
|
+
async changeEntityTags(ref, change2) {
|
|
2400
|
+
const transaction = {
|
|
2401
|
+
projectId: ref.projectId,
|
|
2402
|
+
projectBranch: ref.projectBranch,
|
|
2403
|
+
consistency: "WEAK",
|
|
2404
|
+
entityDeltas: {
|
|
2405
|
+
[`${ref.entityId}/${ref.entityBranch}`]: {
|
|
2406
|
+
...change2.addTags?.length ? { addTags: change2.addTags } : {},
|
|
2407
|
+
...change2.removeTags?.length ? { removeTags: change2.removeTags } : {}
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
};
|
|
2411
|
+
return client.request({
|
|
2412
|
+
method: "POST",
|
|
2413
|
+
service: SERVICE3,
|
|
2414
|
+
path: "/transactions/",
|
|
2415
|
+
body: transaction
|
|
2416
|
+
});
|
|
2417
|
+
},
|
|
2011
2418
|
// --- Entity Sets ---
|
|
2012
2419
|
async searchEntityIds(projectId, projectBranch, body) {
|
|
2013
2420
|
return client.request({
|
|
@@ -2058,14 +2465,14 @@ function createStorageService(client) {
|
|
|
2058
2465
|
});
|
|
2059
2466
|
},
|
|
2060
2467
|
async deleteLink(projectId, projectBranch, sourceEntityId, sourceEntityBranch, linkId, targetEntityId, targetEntityBranch) {
|
|
2061
|
-
let
|
|
2468
|
+
let path13 = `/links/actual/${enc(projectId)}/${enc(projectBranch)}/${enc(sourceEntityId)}/${enc(sourceEntityBranch)}/${enc(linkId)}`;
|
|
2062
2469
|
if (targetEntityId && targetEntityBranch) {
|
|
2063
|
-
|
|
2470
|
+
path13 += `/${enc(targetEntityId)}/${enc(targetEntityBranch)}`;
|
|
2064
2471
|
}
|
|
2065
2472
|
return client.request({
|
|
2066
2473
|
method: "DELETE",
|
|
2067
2474
|
service: SERVICE3,
|
|
2068
|
-
path:
|
|
2475
|
+
path: path13
|
|
2069
2476
|
});
|
|
2070
2477
|
},
|
|
2071
2478
|
// --- Events ---
|
|
@@ -2862,6 +3269,44 @@ function createIndexService(client) {
|
|
|
2862
3269
|
}
|
|
2863
3270
|
});
|
|
2864
3271
|
},
|
|
3272
|
+
/**
|
|
3273
|
+
* The curated tags in their order. Public: no account is needed. With `counts` each also says
|
|
3274
|
+
* how many public projects carry it.
|
|
3275
|
+
*/
|
|
3276
|
+
async getCuratedTags(counts = false) {
|
|
3277
|
+
return client.request({
|
|
3278
|
+
method: "GET",
|
|
3279
|
+
service: SERVICE7,
|
|
3280
|
+
path: "/tags/curated",
|
|
3281
|
+
query: counts ? { counts: true } : void 0
|
|
3282
|
+
});
|
|
3283
|
+
},
|
|
3284
|
+
/** Administrators only. The platform stores the tag in its canonical form. */
|
|
3285
|
+
async createCuratedTag(request) {
|
|
3286
|
+
return client.request({
|
|
3287
|
+
method: "POST",
|
|
3288
|
+
service: SERVICE7,
|
|
3289
|
+
path: "/admin/curated-tags",
|
|
3290
|
+
body: request
|
|
3291
|
+
});
|
|
3292
|
+
},
|
|
3293
|
+
/** Administrators only. A field left out of the request keeps what is stored. */
|
|
3294
|
+
async updateCuratedTag(tag, request) {
|
|
3295
|
+
return client.request({
|
|
3296
|
+
method: "PUT",
|
|
3297
|
+
service: SERVICE7,
|
|
3298
|
+
path: `/admin/curated-tags/${enc5(tag)}`,
|
|
3299
|
+
body: request
|
|
3300
|
+
});
|
|
3301
|
+
},
|
|
3302
|
+
/** Administrators only. Projects that carry the tag keep it; it only stops being curated. */
|
|
3303
|
+
async deleteCuratedTag(tag) {
|
|
3304
|
+
return client.request({
|
|
3305
|
+
method: "DELETE",
|
|
3306
|
+
service: SERVICE7,
|
|
3307
|
+
path: `/admin/curated-tags/${enc5(tag)}`
|
|
3308
|
+
});
|
|
3309
|
+
},
|
|
2865
3310
|
async rebuildAll() {
|
|
2866
3311
|
return client.request({
|
|
2867
3312
|
method: "POST",
|
|
@@ -3102,8 +3547,8 @@ Examples:
|
|
|
3102
3547
|
success(`Profile "${name}" removed.`);
|
|
3103
3548
|
});
|
|
3104
3549
|
}
|
|
3105
|
-
function setNestedValue(obj,
|
|
3106
|
-
const keys =
|
|
3550
|
+
function setNestedValue(obj, path13, value) {
|
|
3551
|
+
const keys = path13.split(".");
|
|
3107
3552
|
let current = obj;
|
|
3108
3553
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
3109
3554
|
const key = keys[i];
|
|
@@ -3114,8 +3559,8 @@ function setNestedValue(obj, path12, value) {
|
|
|
3114
3559
|
}
|
|
3115
3560
|
current[keys[keys.length - 1]] = value;
|
|
3116
3561
|
}
|
|
3117
|
-
function getNestedValue(obj,
|
|
3118
|
-
const keys =
|
|
3562
|
+
function getNestedValue(obj, path13) {
|
|
3563
|
+
const keys = path13.split(".");
|
|
3119
3564
|
let current = obj;
|
|
3120
3565
|
for (const key of keys) {
|
|
3121
3566
|
if (current === null || current === void 0 || typeof current !== "object") {
|
|
@@ -3127,7 +3572,7 @@ function getNestedValue(obj, path12) {
|
|
|
3127
3572
|
}
|
|
3128
3573
|
|
|
3129
3574
|
// src/commands/project/index.ts
|
|
3130
|
-
import
|
|
3575
|
+
import chalk13 from "chalk";
|
|
3131
3576
|
|
|
3132
3577
|
// src/util/references.ts
|
|
3133
3578
|
function parseEntityReference(ref, overrides) {
|
|
@@ -3213,8 +3658,8 @@ function parseProjectReference(ref, overrides) {
|
|
|
3213
3658
|
|
|
3214
3659
|
// src/commands/bundle-helpers.ts
|
|
3215
3660
|
import chalk11 from "chalk";
|
|
3216
|
-
import * as
|
|
3217
|
-
import * as
|
|
3661
|
+
import * as fs4 from "fs";
|
|
3662
|
+
import * as path3 from "path";
|
|
3218
3663
|
|
|
3219
3664
|
// src/output/progress.ts
|
|
3220
3665
|
import chalk10 from "chalk";
|
|
@@ -3344,7 +3789,7 @@ function shift(value, exponent) {
|
|
|
3344
3789
|
// src/commands/bundle-helpers.ts
|
|
3345
3790
|
async function streamResponseToFile(response, outFile) {
|
|
3346
3791
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
3347
|
-
|
|
3792
|
+
fs4.writeFileSync(outFile, buffer);
|
|
3348
3793
|
return buffer.length;
|
|
3349
3794
|
}
|
|
3350
3795
|
function printLossiness(notes) {
|
|
@@ -3395,10 +3840,10 @@ function printImportResult(result) {
|
|
|
3395
3840
|
printLossiness(result.lossinessNotes);
|
|
3396
3841
|
}
|
|
3397
3842
|
async function runBundleImport(storage, projectId, projectBranch, file, options, outputFormat) {
|
|
3398
|
-
const fileBuffer =
|
|
3843
|
+
const fileBuffer = fs4.readFileSync(file);
|
|
3399
3844
|
const blob = new Blob([fileBuffer]);
|
|
3400
3845
|
const formData = new FormData();
|
|
3401
|
-
formData.append("content", blob,
|
|
3846
|
+
formData.append("content", blob, path3.basename(file));
|
|
3402
3847
|
if (options.preview) {
|
|
3403
3848
|
const preview = await storage.previewBundleImport(projectId, projectBranch, formData);
|
|
3404
3849
|
if (outputFormat === "json") {
|
|
@@ -3415,7 +3860,7 @@ async function runBundleImport(storage, projectId, projectBranch, file, options,
|
|
|
3415
3860
|
}
|
|
3416
3861
|
printImportResult(result);
|
|
3417
3862
|
}
|
|
3418
|
-
var sleep2 = (ms) => new Promise((
|
|
3863
|
+
var sleep2 = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
3419
3864
|
async function pollUntilFinished(storage, projectId, projectBranch, bundleId, intervalMs = 2e3, maxAttempts = 150) {
|
|
3420
3865
|
const status = new Status();
|
|
3421
3866
|
status.start();
|
|
@@ -3488,12 +3933,219 @@ async function projectNames(api, projectIds) {
|
|
|
3488
3933
|
return names;
|
|
3489
3934
|
}
|
|
3490
3935
|
|
|
3491
|
-
// src/commands/
|
|
3936
|
+
// src/commands/entity/tags.ts
|
|
3937
|
+
import chalk12 from "chalk";
|
|
3938
|
+
|
|
3939
|
+
// src/util/tags.ts
|
|
3940
|
+
var NON_SPACING_MARK = new RegExp("^\\p{Mn}$", "u");
|
|
3941
|
+
var LETTER_OR_DIGIT = /^[\p{L}\p{Nd}]$/u;
|
|
3942
|
+
var SPACE_SEPARATOR = /^[\p{Zs}\p{Zl}\p{Zp}]$/u;
|
|
3943
|
+
var NON_BREAKING = /* @__PURE__ */ new Set(["\xA0", "\u2007", "\u202F"]);
|
|
3944
|
+
var CONTROL_WHITESPACE = /^[\t\n\u000B\f\r\u001C-\u001F]$/;
|
|
3945
|
+
function isWhitespace(ch) {
|
|
3946
|
+
return CONTROL_WHITESPACE.test(ch) || SPACE_SEPARATOR.test(ch) && !NON_BREAKING.has(ch);
|
|
3947
|
+
}
|
|
3948
|
+
function normalizeTag(raw) {
|
|
3949
|
+
const decomposed = raw.normalize("NFD");
|
|
3950
|
+
let out = "";
|
|
3951
|
+
let lastWasDash = false;
|
|
3952
|
+
for (let i = 0; i < decomposed.length; i++) {
|
|
3953
|
+
const ch = decomposed[i];
|
|
3954
|
+
if (NON_SPACING_MARK.test(ch)) continue;
|
|
3955
|
+
const lowered = ch.toLowerCase();
|
|
3956
|
+
const lower = lowered.length === 1 ? lowered : ch;
|
|
3957
|
+
if (LETTER_OR_DIGIT.test(lower)) {
|
|
3958
|
+
out += lower;
|
|
3959
|
+
lastWasDash = false;
|
|
3960
|
+
} else if (lower === "-" || lower === "_" || isWhitespace(lower)) {
|
|
3961
|
+
if (out.length > 0 && !lastWasDash) {
|
|
3962
|
+
out += "-";
|
|
3963
|
+
lastWasDash = true;
|
|
3964
|
+
}
|
|
3965
|
+
}
|
|
3966
|
+
}
|
|
3967
|
+
return lastWasDash ? out.slice(0, -1) : out;
|
|
3968
|
+
}
|
|
3969
|
+
var RESERVED_PREFIXES = ["auto-analysis-staging", "staging-run"];
|
|
3970
|
+
function isReservedTag(normalized) {
|
|
3971
|
+
return RESERVED_PREFIXES.some((prefix) => normalized.startsWith(prefix));
|
|
3972
|
+
}
|
|
3973
|
+
var TagError = class extends Error {
|
|
3974
|
+
constructor(message) {
|
|
3975
|
+
super(message);
|
|
3976
|
+
this.name = "TagError";
|
|
3977
|
+
}
|
|
3978
|
+
};
|
|
3979
|
+
function canonicalTags(given) {
|
|
3980
|
+
const tags = [];
|
|
3981
|
+
const renamed = [];
|
|
3982
|
+
for (const typed2 of given.flatMap((entry) => entry.split(",")).map((entry) => entry.trim())) {
|
|
3983
|
+
if (typed2 === "") continue;
|
|
3984
|
+
const tag = normalizeTag(typed2);
|
|
3985
|
+
if (tag === "") {
|
|
3986
|
+
throw new TagError(`"${typed2}" is not a usable tag: a tag needs at least one letter or digit.`);
|
|
3987
|
+
}
|
|
3988
|
+
if (isReservedTag(tag)) {
|
|
3989
|
+
throw new TagError(
|
|
3990
|
+
`"${typed2}" is reserved: tags beginning with ${RESERVED_PREFIXES.map((p) => `"${p}"`).join(" or ")} mark the staging content of an analysis run and are never searchable.`
|
|
3991
|
+
);
|
|
3992
|
+
}
|
|
3993
|
+
if (tag !== typed2) renamed.push([typed2, tag]);
|
|
3994
|
+
if (!tags.includes(tag)) tags.push(tag);
|
|
3995
|
+
}
|
|
3996
|
+
return { tags, renamed };
|
|
3997
|
+
}
|
|
3998
|
+
function planTagChange(operation, current, tags) {
|
|
3999
|
+
const wanted = new Set(tags);
|
|
4000
|
+
let addTags = [];
|
|
4001
|
+
let removeTags = [];
|
|
4002
|
+
if (operation === "add") {
|
|
4003
|
+
addTags = tags.filter((tag) => !current.includes(tag));
|
|
4004
|
+
} else if (operation === "remove") {
|
|
4005
|
+
removeTags = current.filter((stored) => wanted.has(stored) || wanted.has(normalizeTag(stored)));
|
|
4006
|
+
} else {
|
|
4007
|
+
addTags = tags.filter((tag) => !current.includes(tag));
|
|
4008
|
+
removeTags = current.filter((stored) => !wanted.has(stored));
|
|
4009
|
+
}
|
|
4010
|
+
const result = [...current.filter((stored) => !removeTags.includes(stored)), ...addTags];
|
|
4011
|
+
return { addTags, removeTags, result: sortTags(result) };
|
|
4012
|
+
}
|
|
4013
|
+
function sortTags(tags) {
|
|
4014
|
+
return [...tags].sort((a, b) => a.localeCompare(b));
|
|
4015
|
+
}
|
|
4016
|
+
|
|
4017
|
+
// src/commands/entity/tags.ts
|
|
3492
4018
|
function getOutputFormat(cmd) {
|
|
3493
4019
|
const config = loadConfig();
|
|
3494
4020
|
const globalOpts = cmd.optsWithGlobals();
|
|
3495
4021
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3496
4022
|
}
|
|
4023
|
+
function resolve(target, ref, cmd) {
|
|
4024
|
+
const opts = cmd.optsWithGlobals();
|
|
4025
|
+
const overrides = { project: opts.project, branch: opts.branch };
|
|
4026
|
+
if (target === "entity") return parseEntityReference(ref, overrides);
|
|
4027
|
+
const project = parseProjectReference(ref, overrides);
|
|
4028
|
+
return { ...project, entityId: project.projectId, entityBranch: "main" };
|
|
4029
|
+
}
|
|
4030
|
+
function printTags(result, outputFormat) {
|
|
4031
|
+
if (outputFormat === "json") {
|
|
4032
|
+
format(result, { format: outputFormat });
|
|
4033
|
+
} else if (outputFormat === "table") {
|
|
4034
|
+
format(result.tags.map((tag) => ({ tag })), { format: outputFormat, columns: ["tag"] });
|
|
4035
|
+
} else if (result.tags.length === 0) {
|
|
4036
|
+
empty("tags");
|
|
4037
|
+
} else {
|
|
4038
|
+
console.log(result.tags.join(", "));
|
|
4039
|
+
}
|
|
4040
|
+
}
|
|
4041
|
+
function describeChange(added, removed) {
|
|
4042
|
+
const parts = [
|
|
4043
|
+
...added.length ? [`added ${added.join(", ")}`] : [],
|
|
4044
|
+
...removed.length ? [`removed ${removed.join(", ")}`] : []
|
|
4045
|
+
];
|
|
4046
|
+
return parts.join("; ");
|
|
4047
|
+
}
|
|
4048
|
+
async function show(target, ref, cmd) {
|
|
4049
|
+
const resolved = resolve(target, ref, cmd);
|
|
4050
|
+
const entity = await createApiClient().storage.getEntity(resolved);
|
|
4051
|
+
printTags({ ...resolved, tags: sortTags(entity.tags ?? []) }, getOutputFormat(cmd));
|
|
4052
|
+
}
|
|
4053
|
+
async function change(target, operation, ref, given, cmd) {
|
|
4054
|
+
const outputFormat = getOutputFormat(cmd);
|
|
4055
|
+
const resolved = resolve(target, ref, cmd);
|
|
4056
|
+
const { tags, renamed } = canonicalTags(Array.isArray(given) ? given : [given]);
|
|
4057
|
+
if (tags.length === 0 && operation !== "set") {
|
|
4058
|
+
usageError("No tags given.", `Name at least one: diafunc ${target} tags ${operation} ${ref} <tag> [<tag>...]`);
|
|
4059
|
+
}
|
|
4060
|
+
for (const [typed2, tag] of renamed) {
|
|
4061
|
+
console.error(chalk12.dim(`"${typed2}" is written as "${tag}", the form tags are searched by.`));
|
|
4062
|
+
}
|
|
4063
|
+
const api = createApiClient();
|
|
4064
|
+
const current = (await api.storage.getEntity(resolved)).tags ?? [];
|
|
4065
|
+
const plan = planTagChange(operation, current, tags);
|
|
4066
|
+
const noun = target === "project" ? `project "${resolved.projectId}"` : `entity "${resolved.entityId}"`;
|
|
4067
|
+
if (plan.addTags.length === 0 && plan.removeTags.length === 0) {
|
|
4068
|
+
if (outputFormat === "human") success(`Tags of ${noun} are already as asked; nothing changed.`);
|
|
4069
|
+
printTags({ ...resolved, tags: sortTags(current), added: [], removed: [] }, outputFormat);
|
|
4070
|
+
return;
|
|
4071
|
+
}
|
|
4072
|
+
await api.storage.changeEntityTags(resolved, { addTags: plan.addTags, removeTags: plan.removeTags });
|
|
4073
|
+
const outcome = { added: plan.addTags, removed: plan.removeTags };
|
|
4074
|
+
if (isDryRun()) {
|
|
4075
|
+
if (outputFormat === "human") console.log(chalk12.dim(`Would leave ${noun} with:`));
|
|
4076
|
+
printTags({ ...resolved, tags: plan.result, ...outcome, dryRun: true }, outputFormat);
|
|
4077
|
+
return;
|
|
4078
|
+
}
|
|
4079
|
+
const stored = (await api.storage.getEntity(resolved)).tags ?? [];
|
|
4080
|
+
if (outputFormat === "human") success(`Tags of ${noun} updated: ${describeChange(plan.addTags, plan.removeTags)}.`);
|
|
4081
|
+
printTags({ ...resolved, tags: sortTags(stored), ...outcome }, outputFormat);
|
|
4082
|
+
}
|
|
4083
|
+
function guarded(run) {
|
|
4084
|
+
return run().catch((error) => {
|
|
4085
|
+
if (error instanceof TagError) usageError(error.message);
|
|
4086
|
+
handleError(error);
|
|
4087
|
+
});
|
|
4088
|
+
}
|
|
4089
|
+
var NORMALISATION = `
|
|
4090
|
+
Tags are written in the form they are searched by: lowercase, accents dropped,
|
|
4091
|
+
spaces and underscores as "-", punctuation removed ("Machine Learning" becomes
|
|
4092
|
+
"machine-learning"). Tags beginning with "auto-analysis-staging" or "staging-run"
|
|
4093
|
+
are reserved for analysis runs and are refused.`;
|
|
4094
|
+
function registerTagCommands(parent, target) {
|
|
4095
|
+
const argName = target === "project" ? "<projectId>" : "<ref>";
|
|
4096
|
+
const argHelp = target === "project" ? "Project ID (or projectId/branch)" : "Entity reference";
|
|
4097
|
+
const example = target === "project" ? "diafunc project tags" : "diafunc entity tags";
|
|
4098
|
+
const sample = target === "project" ? "<projectId>" : "<project>/main/<entity>/main";
|
|
4099
|
+
const tags = parent.command("tags").description(target === "project" ? "Show and change a project's tags, the ones Explore and the search filter by" : "Show and change an entity's tags").addHelpText("after", `${target === "project" ? `
|
|
4100
|
+
A project's tags are the tags of its project entity, so this is 'diafunc entity tags'
|
|
4101
|
+
on <projectId>/main/<projectId>/main. Changing them needs edit access to the project.
|
|
4102
|
+
` : ""}${NORMALISATION}
|
|
4103
|
+
|
|
4104
|
+
Examples:
|
|
4105
|
+
$ ${example} get ${sample}
|
|
4106
|
+
$ ${example} add ${sample} health "Machine Learning"
|
|
4107
|
+
$ ${example} remove ${sample} health
|
|
4108
|
+
$ ${example} set ${sample} energy climate exactly these two
|
|
4109
|
+
$ ${example} set ${sample} "" no tags at all
|
|
4110
|
+
$ diafunc admin curated-tags list the tags Explore offers as data domains
|
|
4111
|
+
`);
|
|
4112
|
+
tags.command("get").description(`Show the tags of ${target === "project" ? "a project" : "an entity"}`).argument(argName, argHelp).addHelpText("after", `
|
|
4113
|
+
Examples:
|
|
4114
|
+
$ ${example} get ${sample}
|
|
4115
|
+
$ ${example} get ${sample} -o json { ..., "tags": ["energy", "health"] }
|
|
4116
|
+
`).action((ref, _options, cmd) => guarded(() => show(target, ref, cmd)));
|
|
4117
|
+
tags.command("add").description("Add tags; one that is already there is left as it is").argument(argName, argHelp).argument("<tags...>", "Tags to add, as separate arguments or comma-separated").addHelpText("after", `${NORMALISATION}
|
|
4118
|
+
|
|
4119
|
+
Examples:
|
|
4120
|
+
$ ${example} add ${sample} health
|
|
4121
|
+
$ ${example} add ${sample} health energy "Machine Learning"
|
|
4122
|
+
$ ${example} add ${sample} health --dry-run print the request, send nothing
|
|
4123
|
+
`).action((ref, given, _options, cmd) => guarded(() => change(target, "add", ref, given, cmd)));
|
|
4124
|
+
tags.command("remove").description("Remove tags; one that is not there is ignored").argument(argName, argHelp).argument("<tags...>", "Tags to remove, as separate arguments or comma-separated").addHelpText("after", `
|
|
4125
|
+
A tag is matched in any spelling of the same tag: "Health" also removes a stored "health".
|
|
4126
|
+
|
|
4127
|
+
Examples:
|
|
4128
|
+
$ ${example} remove ${sample} health
|
|
4129
|
+
$ ${example} remove ${sample} health,energy --dry-run
|
|
4130
|
+
`).action((ref, given, _options, cmd) => guarded(() => change(target, "remove", ref, given, cmd)));
|
|
4131
|
+
tags.command("set").description("Replace the tags: afterwards exactly the given ones are there").argument(argName, argHelp).argument("<tags...>", "The complete tag set, as separate arguments or comma-separated (a single empty string removes every tag)").addHelpText("after", `${NORMALISATION}
|
|
4132
|
+
|
|
4133
|
+
Every tag that is not named is taken off, including ones the platform set itself
|
|
4134
|
+
(an analysis marks what it generates with "auto-analysis", for example).
|
|
4135
|
+
|
|
4136
|
+
Examples:
|
|
4137
|
+
$ ${example} set ${sample} energy climate
|
|
4138
|
+
$ ${example} set ${sample} "" no tags at all
|
|
4139
|
+
$ ${example} set ${sample} energy --dry-run print the request, send nothing
|
|
4140
|
+
`).action((ref, given, _options, cmd) => guarded(() => change(target, "set", ref, given, cmd)));
|
|
4141
|
+
}
|
|
4142
|
+
|
|
4143
|
+
// src/commands/project/index.ts
|
|
4144
|
+
function getOutputFormat2(cmd) {
|
|
4145
|
+
const config = loadConfig();
|
|
4146
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
4147
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
4148
|
+
}
|
|
3497
4149
|
function getOverrides(cmd) {
|
|
3498
4150
|
const opts = cmd.optsWithGlobals();
|
|
3499
4151
|
return { project: opts.project, branch: opts.branch };
|
|
@@ -3507,7 +4159,7 @@ Examples:
|
|
|
3507
4159
|
$ diafunc search "housing" --type project find a project by name
|
|
3508
4160
|
`).action(async (options, cmd) => {
|
|
3509
4161
|
try {
|
|
3510
|
-
const outputFormat =
|
|
4162
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
3511
4163
|
const api = createApiClient();
|
|
3512
4164
|
const projects = options.all ? await api.admin.getAllProjects() : await api.admin.getProjects();
|
|
3513
4165
|
const limit = Number.parseInt(options.limit, 10);
|
|
@@ -3516,7 +4168,7 @@ Examples:
|
|
|
3516
4168
|
try {
|
|
3517
4169
|
names = await projectNames(api, capped.map((p) => p.projectId));
|
|
3518
4170
|
} catch {
|
|
3519
|
-
console.error(
|
|
4171
|
+
console.error(chalk13.dim("Project names are unavailable right now; showing ids."));
|
|
3520
4172
|
}
|
|
3521
4173
|
const rows = capped.map((p) => ({ name: names.get(p.projectId) ?? null, ...p }));
|
|
3522
4174
|
format(rows, {
|
|
@@ -3533,7 +4185,7 @@ Examples:
|
|
|
3533
4185
|
]
|
|
3534
4186
|
});
|
|
3535
4187
|
if (capped.length < projects.length) {
|
|
3536
|
-
console.error(
|
|
4188
|
+
console.error(chalk13.dim(
|
|
3537
4189
|
`
|
|
3538
4190
|
Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
3539
4191
|
));
|
|
@@ -3544,7 +4196,7 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3544
4196
|
});
|
|
3545
4197
|
project.command("get").description("Get project details").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
3546
4198
|
try {
|
|
3547
|
-
const outputFormat =
|
|
4199
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
3548
4200
|
const api = createApiClient();
|
|
3549
4201
|
const p = await api.admin.getProject(projectId);
|
|
3550
4202
|
format(p, { format: outputFormat });
|
|
@@ -3552,14 +4204,20 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3552
4204
|
handleError(error);
|
|
3553
4205
|
}
|
|
3554
4206
|
});
|
|
3555
|
-
project.command("create").description("Create a new project").option("--visibility <visibility>", "Project visibility (PRIVATE or PUBLIC)", "PRIVATE").option("--language <language>", "The project's default language for functions (Java, Kotlin, Python, JavaScript, Scala)", DEFAULT_FUNCTION_LANGUAGE).
|
|
4207
|
+
project.command("create").description("Create a new project").option("--visibility <visibility>", "Project visibility (PRIVATE or PUBLIC)", "PRIVATE").option("--language <language>", "The project's default language for functions (Java, Kotlin, Python, JavaScript, Scala)", DEFAULT_FUNCTION_LANGUAGE).option("--licence <licenceId>", "Licence a public project is published under, an id of the licence catalogue (see 'diafunc licence list')").addHelpText("after", `
|
|
4208
|
+
Examples:
|
|
4209
|
+
$ diafunc project create a private project
|
|
4210
|
+
$ diafunc project create --visibility PUBLIC --licence CC-BY-4.0 a public one, open for reuse with attribution
|
|
4211
|
+
$ diafunc licence list the licences that can be chosen
|
|
4212
|
+
`).action(async (options, cmd) => {
|
|
3556
4213
|
try {
|
|
3557
|
-
const outputFormat =
|
|
4214
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
3558
4215
|
const api = createApiClient();
|
|
3559
4216
|
const p = await api.admin.createProject({
|
|
3560
4217
|
visibility: options.visibility.toUpperCase(),
|
|
3561
4218
|
language: options.language,
|
|
3562
|
-
active: true
|
|
4219
|
+
active: true,
|
|
4220
|
+
...options.licence ? { licenceId: options.licence } : {}
|
|
3563
4221
|
});
|
|
3564
4222
|
await api.storage.createProjectBranch({
|
|
3565
4223
|
projectId: p.projectId,
|
|
@@ -3568,9 +4226,10 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3568
4226
|
});
|
|
3569
4227
|
if (outputFormat === "human") {
|
|
3570
4228
|
success("Project created.");
|
|
3571
|
-
console.log(` Project ID: ${
|
|
4229
|
+
console.log(` Project ID: ${chalk13.bold(p.projectId)}`);
|
|
3572
4230
|
console.log(` Visibility: ${p.visibility}`);
|
|
3573
4231
|
console.log(` Language: ${p.language}`);
|
|
4232
|
+
if (p.licenceId) console.log(` Licence: ${p.licenceId}`);
|
|
3574
4233
|
} else {
|
|
3575
4234
|
format(p, { format: outputFormat });
|
|
3576
4235
|
}
|
|
@@ -3599,7 +4258,7 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3599
4258
|
});
|
|
3600
4259
|
project.command("recent").description("List recently accessed projects").action(async (_options, cmd) => {
|
|
3601
4260
|
try {
|
|
3602
|
-
const outputFormat =
|
|
4261
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
3603
4262
|
const api = createApiClient();
|
|
3604
4263
|
const recent = await api.admin.getRecentProjects();
|
|
3605
4264
|
format(recent, {
|
|
@@ -3641,10 +4300,11 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3641
4300
|
handleError(error);
|
|
3642
4301
|
}
|
|
3643
4302
|
});
|
|
4303
|
+
registerTagCommands(project, "project");
|
|
3644
4304
|
const members = project.command("members").description("Manage project members");
|
|
3645
4305
|
members.command("list").description("List project members").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
3646
4306
|
try {
|
|
3647
|
-
const outputFormat =
|
|
4307
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
3648
4308
|
const api = createApiClient();
|
|
3649
4309
|
const memberList = await api.admin.getProjectMembers(projectId);
|
|
3650
4310
|
format(memberList, {
|
|
@@ -3693,7 +4353,7 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3693
4353
|
console.log(`Poll progress: diafunc notebook bundles ${project2}`);
|
|
3694
4354
|
return;
|
|
3695
4355
|
}
|
|
3696
|
-
console.log(
|
|
4356
|
+
console.log(chalk13.dim(`Project export queued (bundle ID: ${bundleId}); waiting for it to finish\u2026`));
|
|
3697
4357
|
const job = await pollUntilFinished(api.storage, ref.projectId, ref.projectBranch, bundleId);
|
|
3698
4358
|
const response = await api.storage.getBundleContent(ref.projectId, ref.projectBranch, bundleId, job.filename);
|
|
3699
4359
|
const outFile = options.out ?? "project.dfproj";
|
|
@@ -3705,7 +4365,7 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3705
4365
|
});
|
|
3706
4366
|
project.command("import").description("Import a .dfproj (or any) bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the bundle").option("--on-conflict <policy>", "copy (default), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project2, file, options, cmd) => {
|
|
3707
4367
|
try {
|
|
3708
|
-
const outputFormat =
|
|
4368
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
3709
4369
|
const overrides = getOverrides(cmd);
|
|
3710
4370
|
const ref = parseProjectReference(project2, overrides);
|
|
3711
4371
|
const api = createApiClient();
|
|
@@ -3717,25 +4377,25 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3717
4377
|
}
|
|
3718
4378
|
|
|
3719
4379
|
// src/commands/team/index.ts
|
|
3720
|
-
import
|
|
4380
|
+
import chalk15 from "chalk";
|
|
3721
4381
|
|
|
3722
4382
|
// src/util/confirm.ts
|
|
3723
4383
|
import * as readline from "readline";
|
|
3724
|
-
import
|
|
4384
|
+
import chalk14 from "chalk";
|
|
3725
4385
|
async function confirmDestructive(message, opts = {}) {
|
|
3726
4386
|
if (!process.stdin.isTTY || opts.yes) return;
|
|
3727
4387
|
const expected = opts.resourceId ?? "yes";
|
|
3728
4388
|
const hint2 = opts.resourceId ? `"${opts.resourceId}"` : '"yes"';
|
|
3729
|
-
console.log(
|
|
3730
|
-
const answer = await new Promise((
|
|
4389
|
+
console.log(chalk14.yellow(`! ${message}`));
|
|
4390
|
+
const answer = await new Promise((resolve2) => {
|
|
3731
4391
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
3732
4392
|
rl.question(` Type ${hint2} to confirm: `, (ans) => {
|
|
3733
4393
|
rl.close();
|
|
3734
|
-
|
|
4394
|
+
resolve2(ans);
|
|
3735
4395
|
});
|
|
3736
4396
|
});
|
|
3737
4397
|
if (answer.trim() !== expected) {
|
|
3738
|
-
console.log(
|
|
4398
|
+
console.log(chalk14.dim("Aborted."));
|
|
3739
4399
|
process.exit(1);
|
|
3740
4400
|
}
|
|
3741
4401
|
}
|
|
@@ -3743,7 +4403,7 @@ async function confirmDestructive(message, opts = {}) {
|
|
|
3743
4403
|
// src/commands/team/index.ts
|
|
3744
4404
|
var ROLES = ["OWNER", "ADMIN", "MEMBER"];
|
|
3745
4405
|
var INTERVALS = ["MONTHLY", "YEARLY"];
|
|
3746
|
-
function
|
|
4406
|
+
function getOutputFormat3(cmd) {
|
|
3747
4407
|
const config = loadConfig();
|
|
3748
4408
|
const globalOpts = cmd.optsWithGlobals();
|
|
3749
4409
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -3808,7 +4468,7 @@ Examples:
|
|
|
3808
4468
|
const api = createApiClient();
|
|
3809
4469
|
const teams = await api.admin.listMyTeams();
|
|
3810
4470
|
format(teams, {
|
|
3811
|
-
format:
|
|
4471
|
+
format: getOutputFormat3(cmd),
|
|
3812
4472
|
columns: ["id", "name", "planId", "seatCount", "packCount", "renewal"]
|
|
3813
4473
|
});
|
|
3814
4474
|
} catch (error) {
|
|
@@ -3819,7 +4479,7 @@ Examples:
|
|
|
3819
4479
|
try {
|
|
3820
4480
|
const api = createApiClient();
|
|
3821
4481
|
format(await api.admin.getTeam(teamId), {
|
|
3822
|
-
format:
|
|
4482
|
+
format: getOutputFormat3(cmd)
|
|
3823
4483
|
});
|
|
3824
4484
|
} catch (error) {
|
|
3825
4485
|
handleError(error);
|
|
@@ -3829,14 +4489,14 @@ Examples:
|
|
|
3829
4489
|
try {
|
|
3830
4490
|
const api = createApiClient();
|
|
3831
4491
|
await api.admin.setActiveTeam(teamId);
|
|
3832
|
-
success(`Active team set to "${teamId}".`, { format:
|
|
4492
|
+
success(`Active team set to "${teamId}".`, { format: getOutputFormat3(cmd) });
|
|
3833
4493
|
} catch (error) {
|
|
3834
4494
|
handleError(error);
|
|
3835
4495
|
}
|
|
3836
4496
|
});
|
|
3837
4497
|
team.command("usage").description("Show credit usage for a team, broken down by member").argument("<teamId>", "Team ID").action(async (teamId, _options, cmd) => {
|
|
3838
4498
|
try {
|
|
3839
|
-
const outputFormat =
|
|
4499
|
+
const outputFormat = getOutputFormat3(cmd);
|
|
3840
4500
|
const api = createApiClient();
|
|
3841
4501
|
const usage = await api.admin.getTeamUsage(teamId);
|
|
3842
4502
|
if (outputFormat === "json") {
|
|
@@ -3865,13 +4525,13 @@ Examples:
|
|
|
3865
4525
|
...options.packs !== void 0 ? { packCount: parseCount(options.packs, "pack count") } : {},
|
|
3866
4526
|
...options.currency !== void 0 ? { currency: options.currency.toUpperCase() } : {}
|
|
3867
4527
|
});
|
|
3868
|
-
const outputFormat =
|
|
4528
|
+
const outputFormat = getOutputFormat3(cmd);
|
|
3869
4529
|
if (outputFormat === "json") {
|
|
3870
4530
|
format(session, { format: outputFormat });
|
|
3871
4531
|
return;
|
|
3872
4532
|
}
|
|
3873
4533
|
console.log("Open this URL to complete checkout:");
|
|
3874
|
-
console.log(
|
|
4534
|
+
console.log(chalk15.cyan(session.url));
|
|
3875
4535
|
} catch (error) {
|
|
3876
4536
|
handleError(error);
|
|
3877
4537
|
}
|
|
@@ -3880,13 +4540,13 @@ Examples:
|
|
|
3880
4540
|
try {
|
|
3881
4541
|
const api = createApiClient();
|
|
3882
4542
|
const session = await api.admin.createTeamPortalSession(teamId, options.returnUrl);
|
|
3883
|
-
const outputFormat =
|
|
4543
|
+
const outputFormat = getOutputFormat3(cmd);
|
|
3884
4544
|
if (outputFormat === "json") {
|
|
3885
4545
|
format(session, { format: outputFormat });
|
|
3886
4546
|
return;
|
|
3887
4547
|
}
|
|
3888
4548
|
console.log("Open this URL to manage billing:");
|
|
3889
|
-
console.log(
|
|
4549
|
+
console.log(chalk15.cyan(session.url));
|
|
3890
4550
|
} catch (error) {
|
|
3891
4551
|
handleError(error);
|
|
3892
4552
|
}
|
|
@@ -3901,7 +4561,7 @@ Examples:
|
|
|
3901
4561
|
const response = await api.admin.cancelTeam(teamId);
|
|
3902
4562
|
success(
|
|
3903
4563
|
`Team "${teamId}" cancelled. Access ends ${response.endsAt ?? "at the end of the period"}.`,
|
|
3904
|
-
{ format:
|
|
4564
|
+
{ format: getOutputFormat3(cmd) }
|
|
3905
4565
|
);
|
|
3906
4566
|
} catch (error) {
|
|
3907
4567
|
handleError(error);
|
|
@@ -3915,7 +4575,7 @@ Examples:
|
|
|
3915
4575
|
});
|
|
3916
4576
|
const api = createApiClient();
|
|
3917
4577
|
await api.admin.leaveTeam(teamId);
|
|
3918
|
-
success(`Left team "${teamId}".`, { format:
|
|
4578
|
+
success(`Left team "${teamId}".`, { format: getOutputFormat3(cmd) });
|
|
3919
4579
|
} catch (error) {
|
|
3920
4580
|
handleError(error);
|
|
3921
4581
|
}
|
|
@@ -3934,7 +4594,7 @@ function registerMemberCommands(team) {
|
|
|
3934
4594
|
const all = await api.admin.listTeamMembers(teamId);
|
|
3935
4595
|
const shown = options.all ? all : all.filter((m) => !m.removedAt);
|
|
3936
4596
|
format(shown, {
|
|
3937
|
-
format:
|
|
4597
|
+
format: getOutputFormat3(cmd),
|
|
3938
4598
|
columns: options.all ? ["userId", "name", "email", "role", "joinedAt", "removedAt"] : ["userId", "name", "email", "role", "joinedAt"]
|
|
3939
4599
|
});
|
|
3940
4600
|
} catch (error) {
|
|
@@ -3947,7 +4607,7 @@ function registerMemberCommands(team) {
|
|
|
3947
4607
|
const api = createApiClient();
|
|
3948
4608
|
await api.admin.inviteTeamMember(teamId, email, role);
|
|
3949
4609
|
success(`Invited ${email} to team "${teamId}" as ${role}.`, {
|
|
3950
|
-
format:
|
|
4610
|
+
format: getOutputFormat3(cmd)
|
|
3951
4611
|
});
|
|
3952
4612
|
} catch (error) {
|
|
3953
4613
|
handleError(error);
|
|
@@ -3962,7 +4622,7 @@ function registerMemberCommands(team) {
|
|
|
3962
4622
|
const api = createApiClient();
|
|
3963
4623
|
await api.admin.removeTeamMember(teamId, userId);
|
|
3964
4624
|
success(`Removed ${userId} from team "${teamId}".`, {
|
|
3965
|
-
format:
|
|
4625
|
+
format: getOutputFormat3(cmd)
|
|
3966
4626
|
});
|
|
3967
4627
|
} catch (error) {
|
|
3968
4628
|
handleError(error);
|
|
@@ -3975,7 +4635,7 @@ function registerInvitationCommands(team) {
|
|
|
3975
4635
|
try {
|
|
3976
4636
|
const api = createApiClient();
|
|
3977
4637
|
format(await api.admin.listTeamInvitations(teamId), {
|
|
3978
|
-
format:
|
|
4638
|
+
format: getOutputFormat3(cmd),
|
|
3979
4639
|
columns: ["invitationId", "email", "role", "invitedBy", "expiresAt"]
|
|
3980
4640
|
});
|
|
3981
4641
|
} catch (error) {
|
|
@@ -3991,7 +4651,7 @@ function registerInvitationCommands(team) {
|
|
|
3991
4651
|
const api = createApiClient();
|
|
3992
4652
|
await api.admin.revokeTeamInvitation(teamId, invitationId);
|
|
3993
4653
|
success(`Revoked invitation "${invitationId}".`, {
|
|
3994
|
-
format:
|
|
4654
|
+
format: getOutputFormat3(cmd)
|
|
3995
4655
|
});
|
|
3996
4656
|
} catch (error) {
|
|
3997
4657
|
handleError(error);
|
|
@@ -4002,7 +4662,7 @@ function registerInvitationCommands(team) {
|
|
|
4002
4662
|
const api = createApiClient();
|
|
4003
4663
|
await api.admin.resendTeamInvitation(teamId, invitationId);
|
|
4004
4664
|
success(`Resent invitation "${invitationId}".`, {
|
|
4005
|
-
format:
|
|
4665
|
+
format: getOutputFormat3(cmd)
|
|
4006
4666
|
});
|
|
4007
4667
|
} catch (error) {
|
|
4008
4668
|
handleError(error);
|
|
@@ -4013,7 +4673,7 @@ function registerInvitationCommands(team) {
|
|
|
4013
4673
|
const api = createApiClient();
|
|
4014
4674
|
const member = await api.admin.acceptTeamInvitation(token);
|
|
4015
4675
|
success(`Joined the team as ${member.role}.`, {
|
|
4016
|
-
format:
|
|
4676
|
+
format: getOutputFormat3(cmd)
|
|
4017
4677
|
});
|
|
4018
4678
|
} catch (error) {
|
|
4019
4679
|
handleError(error);
|
|
@@ -4027,7 +4687,7 @@ function registerSeatCommands(team) {
|
|
|
4027
4687
|
const api = createApiClient();
|
|
4028
4688
|
printInvoicePreview(
|
|
4029
4689
|
await api.admin.previewTeamSeatCount(teamId, parseCount(count, "seat count")),
|
|
4030
|
-
|
|
4690
|
+
getOutputFormat3(cmd)
|
|
4031
4691
|
);
|
|
4032
4692
|
} catch (error) {
|
|
4033
4693
|
handleError(error);
|
|
@@ -4041,9 +4701,9 @@ function registerSeatCommands(team) {
|
|
|
4041
4701
|
{ yes: options.yes, resourceId: teamId }
|
|
4042
4702
|
);
|
|
4043
4703
|
const api = createApiClient();
|
|
4044
|
-
const
|
|
4045
|
-
success(`Seats changed from ${
|
|
4046
|
-
format:
|
|
4704
|
+
const change2 = await api.admin.updateTeamSeatCount(teamId, seatCount);
|
|
4705
|
+
success(`Seats changed from ${change2.oldSeatCount} to ${change2.newSeatCount}.`, {
|
|
4706
|
+
format: getOutputFormat3(cmd)
|
|
4047
4707
|
});
|
|
4048
4708
|
} catch (error) {
|
|
4049
4709
|
handleError(error);
|
|
@@ -4057,7 +4717,7 @@ function registerPackCommands(team) {
|
|
|
4057
4717
|
const api = createApiClient();
|
|
4058
4718
|
printInvoicePreview(
|
|
4059
4719
|
await api.admin.previewTeamPackCount(teamId, parseCount(count, "pack count")),
|
|
4060
|
-
|
|
4720
|
+
getOutputFormat3(cmd)
|
|
4061
4721
|
);
|
|
4062
4722
|
} catch (error) {
|
|
4063
4723
|
handleError(error);
|
|
@@ -4071,9 +4731,9 @@ function registerPackCommands(team) {
|
|
|
4071
4731
|
{ yes: options.yes, resourceId: teamId }
|
|
4072
4732
|
);
|
|
4073
4733
|
const api = createApiClient();
|
|
4074
|
-
const
|
|
4075
|
-
success(`Packs changed from ${
|
|
4076
|
-
format:
|
|
4734
|
+
const change2 = await api.admin.updateTeamPackCount(teamId, packCount);
|
|
4735
|
+
success(`Packs changed from ${change2.oldPackCount} to ${change2.newPackCount}.`, {
|
|
4736
|
+
format: getOutputFormat3(cmd)
|
|
4077
4737
|
});
|
|
4078
4738
|
} catch (error) {
|
|
4079
4739
|
handleError(error);
|
|
@@ -4090,7 +4750,7 @@ function registerOwnershipCommands(team) {
|
|
|
4090
4750
|
);
|
|
4091
4751
|
const api = createApiClient();
|
|
4092
4752
|
format(await api.admin.initiateOwnershipTransfer(teamId, userId), {
|
|
4093
|
-
format:
|
|
4753
|
+
format: getOutputFormat3(cmd)
|
|
4094
4754
|
});
|
|
4095
4755
|
} catch (error) {
|
|
4096
4756
|
handleError(error);
|
|
@@ -4100,7 +4760,7 @@ function registerOwnershipCommands(team) {
|
|
|
4100
4760
|
try {
|
|
4101
4761
|
const api = createApiClient();
|
|
4102
4762
|
const pending = await api.admin.getOwnershipTransfer(teamId);
|
|
4103
|
-
const outputFormat =
|
|
4763
|
+
const outputFormat = getOutputFormat3(cmd);
|
|
4104
4764
|
if (!pending) {
|
|
4105
4765
|
if (outputFormat === "json") {
|
|
4106
4766
|
format(null, { format: outputFormat });
|
|
@@ -4118,7 +4778,7 @@ function registerOwnershipCommands(team) {
|
|
|
4118
4778
|
try {
|
|
4119
4779
|
const api = createApiClient();
|
|
4120
4780
|
const response = await api.admin.acceptOwnershipTransfer(teamId);
|
|
4121
|
-
const outputFormat =
|
|
4781
|
+
const outputFormat = getOutputFormat3(cmd);
|
|
4122
4782
|
if (outputFormat === "json") {
|
|
4123
4783
|
format(response, { format: outputFormat });
|
|
4124
4784
|
return;
|
|
@@ -4126,7 +4786,7 @@ function registerOwnershipCommands(team) {
|
|
|
4126
4786
|
success(`Ownership transfer ${response.status}.`);
|
|
4127
4787
|
if (response.checkoutUrl) {
|
|
4128
4788
|
console.log("Open this URL to complete the billing handover:");
|
|
4129
|
-
console.log(
|
|
4789
|
+
console.log(chalk15.cyan(response.checkoutUrl));
|
|
4130
4790
|
}
|
|
4131
4791
|
} catch (error) {
|
|
4132
4792
|
handleError(error);
|
|
@@ -4137,7 +4797,7 @@ function registerOwnershipCommands(team) {
|
|
|
4137
4797
|
const api = createApiClient();
|
|
4138
4798
|
await api.admin.cancelOwnershipTransfer(teamId);
|
|
4139
4799
|
success(`Cancelled the ownership transfer for team "${teamId}".`, {
|
|
4140
|
-
format:
|
|
4800
|
+
format: getOutputFormat3(cmd)
|
|
4141
4801
|
});
|
|
4142
4802
|
} catch (error) {
|
|
4143
4803
|
handleError(error);
|
|
@@ -4146,8 +4806,8 @@ function registerOwnershipCommands(team) {
|
|
|
4146
4806
|
}
|
|
4147
4807
|
|
|
4148
4808
|
// src/commands/entity/index.ts
|
|
4149
|
-
import * as
|
|
4150
|
-
function
|
|
4809
|
+
import * as fs5 from "fs";
|
|
4810
|
+
function getOutputFormat4(cmd) {
|
|
4151
4811
|
const config = loadConfig();
|
|
4152
4812
|
const globalOpts = cmd.optsWithGlobals();
|
|
4153
4813
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4165,11 +4825,12 @@ Examples:
|
|
|
4165
4825
|
$ diafunc entity list <projectId>
|
|
4166
4826
|
$ diafunc entity get <project>/main/<entity>/main
|
|
4167
4827
|
$ diafunc entity history <project>/main/<entity>/main
|
|
4828
|
+
$ diafunc entity tags add <project>/main/<entity>/main health
|
|
4168
4829
|
`);
|
|
4169
4830
|
;
|
|
4170
4831
|
entity.command("list").description("List entities in a project (via linked entities from project root)").argument("<projectRef>", "Project reference (projectId or projectId/branch)").action(async (projectRef, _options, cmd) => {
|
|
4171
4832
|
try {
|
|
4172
|
-
const outputFormat =
|
|
4833
|
+
const outputFormat = getOutputFormat4(cmd);
|
|
4173
4834
|
const overrides = getOverrides2(cmd);
|
|
4174
4835
|
const ref = parseEntityReference(projectRef + "/" + projectRef, overrides);
|
|
4175
4836
|
const api = createApiClient();
|
|
@@ -4196,7 +4857,7 @@ Examples:
|
|
|
4196
4857
|
});
|
|
4197
4858
|
entity.command("get").description("Get entity metadata").argument("<ref>", "Entity reference").option("--content", "Include content").action(async (ref, options, cmd) => {
|
|
4198
4859
|
try {
|
|
4199
|
-
const outputFormat =
|
|
4860
|
+
const outputFormat = getOutputFormat4(cmd);
|
|
4200
4861
|
const overrides = getOverrides2(cmd);
|
|
4201
4862
|
const resolved = parseEntityReference(ref, overrides);
|
|
4202
4863
|
const api = createApiClient();
|
|
@@ -4239,7 +4900,7 @@ Examples:
|
|
|
4239
4900
|
});
|
|
4240
4901
|
entity.command("history").description("Get entity version history").argument("<ref>", "Entity reference").option("--from <version>", "From version").option("--to <version>", "To version").action(async (ref, options, cmd) => {
|
|
4241
4902
|
try {
|
|
4242
|
-
const outputFormat =
|
|
4903
|
+
const outputFormat = getOutputFormat4(cmd);
|
|
4243
4904
|
const overrides = getOverrides2(cmd);
|
|
4244
4905
|
const resolved = parseEntityReference(ref, overrides);
|
|
4245
4906
|
const api = createApiClient();
|
|
@@ -4289,6 +4950,7 @@ Examples:
|
|
|
4289
4950
|
handleError(error);
|
|
4290
4951
|
}
|
|
4291
4952
|
});
|
|
4953
|
+
registerTagCommands(entity, "entity");
|
|
4292
4954
|
const content = entity.command("content").description("Manage entity content");
|
|
4293
4955
|
content.command("get").description("Download entity content").argument("<ref>", "Entity reference").option("--out <file>", "Output file (defaults to stdout)").action(async (ref, options, cmd) => {
|
|
4294
4956
|
try {
|
|
@@ -4298,7 +4960,7 @@ Examples:
|
|
|
4298
4960
|
const response = await api.storage.getEntityContent(resolved);
|
|
4299
4961
|
if (options.out) {
|
|
4300
4962
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
4301
|
-
|
|
4963
|
+
fs5.writeFileSync(options.out, buffer);
|
|
4302
4964
|
success(`Content saved to ${options.out}`);
|
|
4303
4965
|
} else {
|
|
4304
4966
|
const text2 = await response.text();
|
|
@@ -4313,7 +4975,7 @@ Examples:
|
|
|
4313
4975
|
const overrides = getOverrides2(cmd);
|
|
4314
4976
|
const resolved = parseEntityReference(ref, overrides);
|
|
4315
4977
|
const api = createApiClient();
|
|
4316
|
-
const fileBuffer =
|
|
4978
|
+
const fileBuffer = fs5.readFileSync(file);
|
|
4317
4979
|
const base64 = fileBuffer.toString("base64");
|
|
4318
4980
|
await api.storage.saveEntityContentBase64(resolved, base64);
|
|
4319
4981
|
success(`Content uploaded from "${file}" to entity "${resolved.entityId}".`);
|
|
@@ -4355,7 +5017,7 @@ Examples:
|
|
|
4355
5017
|
});
|
|
4356
5018
|
entity.command("import").description("Import a .dfset (or any) bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the bundle").option("--on-conflict <policy>", "copy (default), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project, file, options, cmd) => {
|
|
4357
5019
|
try {
|
|
4358
|
-
const outputFormat =
|
|
5020
|
+
const outputFormat = getOutputFormat4(cmd);
|
|
4359
5021
|
const overrides = getOverrides2(cmd);
|
|
4360
5022
|
const ref = parseProjectReference(project, overrides);
|
|
4361
5023
|
const api = createApiClient();
|
|
@@ -4367,7 +5029,7 @@ Examples:
|
|
|
4367
5029
|
}
|
|
4368
5030
|
|
|
4369
5031
|
// src/commands/link/index.ts
|
|
4370
|
-
function
|
|
5032
|
+
function getOutputFormat5(cmd) {
|
|
4371
5033
|
const config = loadConfig();
|
|
4372
5034
|
const globalOpts = cmd.optsWithGlobals();
|
|
4373
5035
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4380,7 +5042,7 @@ function registerLinkCommands(program) {
|
|
|
4380
5042
|
const link = program.command("link").description("Manage links between entities");
|
|
4381
5043
|
link.command("list").description("List links for an entity").argument("<ref>", "Source entity reference").option("--direction <dir>", "Link direction: FORWARD or BACKWARD", "FORWARD").action(async (ref, options, cmd) => {
|
|
4382
5044
|
try {
|
|
4383
|
-
const outputFormat =
|
|
5045
|
+
const outputFormat = getOutputFormat5(cmd);
|
|
4384
5046
|
const overrides = getOverrides3(cmd);
|
|
4385
5047
|
const resolved = parseEntityReference(ref, overrides);
|
|
4386
5048
|
const api = createApiClient();
|
|
@@ -4455,7 +5117,7 @@ function registerLinkCommands(program) {
|
|
|
4455
5117
|
}
|
|
4456
5118
|
|
|
4457
5119
|
// src/commands/event/index.ts
|
|
4458
|
-
function
|
|
5120
|
+
function getOutputFormat6(cmd) {
|
|
4459
5121
|
const config = loadConfig();
|
|
4460
5122
|
const globalOpts = cmd.optsWithGlobals();
|
|
4461
5123
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4468,7 +5130,7 @@ function registerEventCommands(program) {
|
|
|
4468
5130
|
const event = program.command("event").description("Manage events");
|
|
4469
5131
|
event.command("list").description("List events for an entity").argument("<ref>", "Entity reference").action(async (ref, _options, cmd) => {
|
|
4470
5132
|
try {
|
|
4471
|
-
const outputFormat =
|
|
5133
|
+
const outputFormat = getOutputFormat6(cmd);
|
|
4472
5134
|
const overrides = getOverrides4(cmd);
|
|
4473
5135
|
const resolved = parseEntityReference(ref, overrides);
|
|
4474
5136
|
const api = createApiClient();
|
|
@@ -4490,7 +5152,7 @@ function registerEventCommands(program) {
|
|
|
4490
5152
|
});
|
|
4491
5153
|
event.command("get").description("Get a specific event").argument("<ref>", "Entity reference").argument("<eventId>", "Event ID").argument("<occurrenceId>", "Occurrence ID").action(async (ref, eventId, occurrenceId, _options, cmd) => {
|
|
4492
5154
|
try {
|
|
4493
|
-
const outputFormat =
|
|
5155
|
+
const outputFormat = getOutputFormat6(cmd);
|
|
4494
5156
|
const overrides = getOverrides4(cmd);
|
|
4495
5157
|
const resolved = parseEntityReference(ref, overrides);
|
|
4496
5158
|
const api = createApiClient();
|
|
@@ -4502,14 +5164,14 @@ function registerEventCommands(program) {
|
|
|
4502
5164
|
});
|
|
4503
5165
|
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) => {
|
|
4504
5166
|
try {
|
|
4505
|
-
const
|
|
4506
|
-
const body = file ?
|
|
5167
|
+
const fs18 = await import("fs");
|
|
5168
|
+
const body = file ? fs18.readFileSync(file, "utf-8") : await new Promise((resolve2, reject) => {
|
|
4507
5169
|
let data = "";
|
|
4508
5170
|
process.stdin.setEncoding("utf-8");
|
|
4509
5171
|
process.stdin.on("data", (chunk) => {
|
|
4510
5172
|
data += chunk;
|
|
4511
5173
|
});
|
|
4512
|
-
process.stdin.on("end", () =>
|
|
5174
|
+
process.stdin.on("end", () => resolve2(data));
|
|
4513
5175
|
process.stdin.on("error", reject);
|
|
4514
5176
|
});
|
|
4515
5177
|
const events = JSON.parse(body);
|
|
@@ -4551,7 +5213,7 @@ function registerEventCommands(program) {
|
|
|
4551
5213
|
}
|
|
4552
5214
|
|
|
4553
5215
|
// src/commands/branch/index.ts
|
|
4554
|
-
function
|
|
5216
|
+
function getOutputFormat7(cmd) {
|
|
4555
5217
|
const config = loadConfig();
|
|
4556
5218
|
const globalOpts = cmd.optsWithGlobals();
|
|
4557
5219
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4570,7 +5232,7 @@ Examples:
|
|
|
4570
5232
|
;
|
|
4571
5233
|
branch.command("list").description("List branches for a project").argument("[projectId]", "Project ID (uses default if omitted)").action(async (projectId, _options, cmd) => {
|
|
4572
5234
|
try {
|
|
4573
|
-
const outputFormat =
|
|
5235
|
+
const outputFormat = getOutputFormat7(cmd);
|
|
4574
5236
|
const overrides = getOverrides5(cmd);
|
|
4575
5237
|
const config = loadConfig();
|
|
4576
5238
|
const pid = projectId ?? overrides.project ?? config.defaults.project;
|
|
@@ -4652,9 +5314,9 @@ Examples:
|
|
|
4652
5314
|
}
|
|
4653
5315
|
|
|
4654
5316
|
// src/commands/table/index.ts
|
|
4655
|
-
import
|
|
4656
|
-
import * as
|
|
4657
|
-
import * as
|
|
5317
|
+
import chalk16 from "chalk";
|
|
5318
|
+
import * as fs6 from "fs";
|
|
5319
|
+
import * as path4 from "path";
|
|
4658
5320
|
|
|
4659
5321
|
// src/util/table-window.ts
|
|
4660
5322
|
var WINDOW_MAX_ROWS = 100;
|
|
@@ -4806,8 +5468,8 @@ function buildTableEntity(args) {
|
|
|
4806
5468
|
}
|
|
4807
5469
|
|
|
4808
5470
|
// src/commands/table/index.ts
|
|
4809
|
-
import { randomUUID } from "crypto";
|
|
4810
|
-
function
|
|
5471
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
5472
|
+
function getOutputFormat8(cmd) {
|
|
4811
5473
|
const config = loadConfig();
|
|
4812
5474
|
const globalOpts = cmd.optsWithGlobals();
|
|
4813
5475
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4870,7 +5532,7 @@ Examples:
|
|
|
4870
5532
|
;
|
|
4871
5533
|
table.command("view").description("View table data").argument("<ref>", "Table entity reference").option("--rows <range>", "Rows to show, half-open: 0:10 is the first ten, 6490: runs to the end (default: up to 100)").option("--cols <range>", "Columns to show, half-open: 0:5 is the first five (default: up to 50)").action(async (ref, options, cmd) => {
|
|
4872
5534
|
try {
|
|
4873
|
-
const outputFormat =
|
|
5535
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
4874
5536
|
const overrides = getOverrides6(cmd);
|
|
4875
5537
|
const resolved = parseEntityReference(ref, overrides);
|
|
4876
5538
|
const api = createApiClient();
|
|
@@ -4879,7 +5541,7 @@ Examples:
|
|
|
4879
5541
|
if (outputFormat === "json") {
|
|
4880
5542
|
format({ rows: [], columns: [], cells: [], totalRows, totalColumns, window: null }, { format: outputFormat });
|
|
4881
5543
|
} else {
|
|
4882
|
-
console.log(
|
|
5544
|
+
console.log(chalk16.dim("Empty table."));
|
|
4883
5545
|
}
|
|
4884
5546
|
return;
|
|
4885
5547
|
}
|
|
@@ -4919,7 +5581,7 @@ Examples:
|
|
|
4919
5581
|
}
|
|
4920
5582
|
} else {
|
|
4921
5583
|
format(tableData, { format: outputFormat, columns: colNames.map((name) => ({ key: name, header: name })) });
|
|
4922
|
-
console.log(
|
|
5584
|
+
console.log(chalk16.dim(describeWindow(window, totalRows, totalColumns)));
|
|
4923
5585
|
}
|
|
4924
5586
|
} catch (error) {
|
|
4925
5587
|
handleError(error);
|
|
@@ -4935,9 +5597,9 @@ Examples:
|
|
|
4935
5597
|
$ diafunc table create --notebook <notebookId>
|
|
4936
5598
|
`).action(async (ref, options, cmd) => {
|
|
4937
5599
|
try {
|
|
4938
|
-
const outputFormat =
|
|
5600
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
4939
5601
|
const overrides = getOverrides6(cmd);
|
|
4940
|
-
const resolved = parseEntityReference(ref ??
|
|
5602
|
+
const resolved = parseEntityReference(ref ?? randomUUID2(), overrides);
|
|
4941
5603
|
if (resolved.entityId.includes(".partition.")) {
|
|
4942
5604
|
throw new CliError(`"${resolved.entityId}" contains ".partition.", which names a table's storage blocks.`, {
|
|
4943
5605
|
exitCode: EXIT_USAGE,
|
|
@@ -4972,17 +5634,17 @@ Examples:
|
|
|
4972
5634
|
try {
|
|
4973
5635
|
const overrides = getOverrides6(cmd);
|
|
4974
5636
|
const resolved = parseEntityReference(ref, overrides);
|
|
4975
|
-
if (!
|
|
5637
|
+
if (!fs6.existsSync(file)) {
|
|
4976
5638
|
failure(`File not found: ${file}`);
|
|
4977
5639
|
process.exit(EXIT_USAGE);
|
|
4978
5640
|
}
|
|
4979
5641
|
const api = createApiClient();
|
|
4980
|
-
const fileBuffer =
|
|
5642
|
+
const fileBuffer = fs6.readFileSync(file);
|
|
4981
5643
|
const blob = new Blob([fileBuffer]);
|
|
4982
5644
|
const formData = new FormData();
|
|
4983
|
-
formData.append("content", blob,
|
|
5645
|
+
formData.append("content", blob, path4.basename(file));
|
|
4984
5646
|
const importId = await withStatus(
|
|
4985
|
-
`Uploading ${
|
|
5647
|
+
`Uploading ${path4.basename(file)}`,
|
|
4986
5648
|
() => api.storage.importTable(resolved, formData, options.selection)
|
|
4987
5649
|
).catch((error) => {
|
|
4988
5650
|
if (error instanceof ApiError && error.status === 404) {
|
|
@@ -4999,7 +5661,7 @@ Examples:
|
|
|
4999
5661
|
const startedAt = Date.now();
|
|
5000
5662
|
try {
|
|
5001
5663
|
for (let i = 0; i < maxAttempts; i++) {
|
|
5002
|
-
await new Promise((
|
|
5664
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
5003
5665
|
const imp = await api.storage.getImport(resolved, importId);
|
|
5004
5666
|
if (imp.finished !== null) {
|
|
5005
5667
|
status.stop();
|
|
@@ -5024,7 +5686,7 @@ Examples:
|
|
|
5024
5686
|
});
|
|
5025
5687
|
table.command("import-formats").description("List supported import formats").action(async (_options, cmd) => {
|
|
5026
5688
|
try {
|
|
5027
|
-
const outputFormat =
|
|
5689
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
5028
5690
|
const api = createApiClient();
|
|
5029
5691
|
const response = await api.storage.getSupportedImportFormats();
|
|
5030
5692
|
if (outputFormat === "json") {
|
|
@@ -5102,7 +5764,7 @@ Examples:
|
|
|
5102
5764
|
const response = await api.storage.streamExport(resolved, format2.id, exportOptions);
|
|
5103
5765
|
const outFile = options.out ?? deriveOutFile(resolved.entityId, format2.extension, options.archive, options.compression);
|
|
5104
5766
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
5105
|
-
|
|
5767
|
+
fs6.writeFileSync(outFile, buffer);
|
|
5106
5768
|
success(`Table streamed to ${outFile}`);
|
|
5107
5769
|
} else {
|
|
5108
5770
|
const exportId = await api.storage.exportTable(resolved, format2.id, exportOptions);
|
|
@@ -5115,7 +5777,7 @@ Examples:
|
|
|
5115
5777
|
});
|
|
5116
5778
|
table.command("export-formats").description("List supported export formats").action(async (_options, cmd) => {
|
|
5117
5779
|
try {
|
|
5118
|
-
const outputFormat =
|
|
5780
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
5119
5781
|
const api = createApiClient();
|
|
5120
5782
|
const response = await api.storage.getSupportedExportFormats();
|
|
5121
5783
|
if (outputFormat === "json") {
|
|
@@ -5131,8 +5793,8 @@ Examples:
|
|
|
5131
5793
|
knownLimitations: f.knownLimitations.join(" / ")
|
|
5132
5794
|
}));
|
|
5133
5795
|
format(rows, { format: outputFormat, columns: ["id", "displayName", "category", "extension", "mimeType", "knownLimitations"] });
|
|
5134
|
-
console.log(
|
|
5135
|
-
console.log(
|
|
5796
|
+
console.log(chalk16.dim(`Compression: ${response.compressionAlgorithms.join(", ")}`));
|
|
5797
|
+
console.log(chalk16.dim(`Archive: ${response.archiveAlgorithms.join(", ")}`));
|
|
5136
5798
|
} catch (error) {
|
|
5137
5799
|
handleError(error);
|
|
5138
5800
|
}
|
|
@@ -5140,7 +5802,7 @@ Examples:
|
|
|
5140
5802
|
const exportsCmd = table.command("exports").description("Track and download async table exports");
|
|
5141
5803
|
exportsCmd.command("list").description("List async exports for a table entity").argument("<ref>", "Table entity reference").action(async (ref, _options, cmd) => {
|
|
5142
5804
|
try {
|
|
5143
|
-
const outputFormat =
|
|
5805
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
5144
5806
|
const overrides = getOverrides6(cmd);
|
|
5145
5807
|
const resolved = parseEntityReference(ref, overrides);
|
|
5146
5808
|
const api = createApiClient();
|
|
@@ -5168,7 +5830,7 @@ Examples:
|
|
|
5168
5830
|
});
|
|
5169
5831
|
exportsCmd.command("get").description("Get async export status; download the file once the export has succeeded").argument("<exportId>", "Export ID returned by `table export --async`").requiredOption("--ref <ref>", "Table entity reference").option("--out <file>", "Output file path (defaults to the original export filename)").action(async (exportId, options, cmd) => {
|
|
5170
5832
|
try {
|
|
5171
|
-
const outputFormat =
|
|
5833
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
5172
5834
|
const overrides = getOverrides6(cmd);
|
|
5173
5835
|
const resolved = parseEntityReference(options.ref, overrides);
|
|
5174
5836
|
const api = createApiClient();
|
|
@@ -5184,7 +5846,7 @@ Examples:
|
|
|
5184
5846
|
}
|
|
5185
5847
|
if (exp.finished === null) {
|
|
5186
5848
|
const pct = Math.round((exp.progress ?? 0) * 100);
|
|
5187
|
-
console.log(
|
|
5849
|
+
console.log(chalk16.dim(`Export in progress: ${pct}%. Check again later.`));
|
|
5188
5850
|
return;
|
|
5189
5851
|
}
|
|
5190
5852
|
if (!exp.succeeded) {
|
|
@@ -5195,7 +5857,7 @@ Examples:
|
|
|
5195
5857
|
console.log(`Downloading ${exp.filename} ...`);
|
|
5196
5858
|
const response = await api.storage.downloadExport(resolved, exportId, exp.filename);
|
|
5197
5859
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
5198
|
-
|
|
5860
|
+
fs6.writeFileSync(outFile, buffer);
|
|
5199
5861
|
success(`Export saved to ${outFile}`);
|
|
5200
5862
|
} catch (error) {
|
|
5201
5863
|
handleError(error);
|
|
@@ -5334,10 +5996,10 @@ Examples:
|
|
|
5334
5996
|
}
|
|
5335
5997
|
|
|
5336
5998
|
// src/commands/notebook/index.ts
|
|
5337
|
-
import
|
|
5338
|
-
import * as
|
|
5339
|
-
import * as
|
|
5340
|
-
function
|
|
5999
|
+
import chalk17 from "chalk";
|
|
6000
|
+
import * as fs7 from "fs";
|
|
6001
|
+
import * as path5 from "path";
|
|
6002
|
+
function getOutputFormat9(cmd) {
|
|
5341
6003
|
const config = loadConfig();
|
|
5342
6004
|
const globalOpts = cmd.optsWithGlobals();
|
|
5343
6005
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5369,7 +6031,7 @@ Examples:
|
|
|
5369
6031
|
const response = await api.storage.streamBundle(ref.projectId, ref.projectBranch, request);
|
|
5370
6032
|
const outFile = options.out ?? "notebooks.dfnb";
|
|
5371
6033
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
5372
|
-
|
|
6034
|
+
fs7.writeFileSync(outFile, buffer);
|
|
5373
6035
|
success(`Bundle written to ${outFile} (${buffer.length} bytes, ${notebookIds.length} notebook(s)).`);
|
|
5374
6036
|
} catch (error) {
|
|
5375
6037
|
handleError(error);
|
|
@@ -5377,23 +6039,23 @@ Examples:
|
|
|
5377
6039
|
});
|
|
5378
6040
|
notebook.command("import").description("Import a .dfnb bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the .dfnb bundle").option("--on-conflict <policy>", "copy (default), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project, file, options, cmd) => {
|
|
5379
6041
|
try {
|
|
5380
|
-
const outputFormat =
|
|
6042
|
+
const outputFormat = getOutputFormat9(cmd);
|
|
5381
6043
|
const overrides = getOverrides7(cmd);
|
|
5382
6044
|
const ref = parseProjectReference(project, overrides);
|
|
5383
6045
|
const api = createApiClient();
|
|
5384
|
-
const fileBuffer =
|
|
6046
|
+
const fileBuffer = fs7.readFileSync(file);
|
|
5385
6047
|
const blob = new Blob([fileBuffer]);
|
|
5386
6048
|
const formData = new FormData();
|
|
5387
|
-
formData.append("content", blob,
|
|
6049
|
+
formData.append("content", blob, path5.basename(file));
|
|
5388
6050
|
if (options.preview) {
|
|
5389
6051
|
const preview = await api.storage.previewBundleImport(ref.projectId, ref.projectBranch, formData);
|
|
5390
6052
|
if (outputFormat === "json") {
|
|
5391
6053
|
format(preview, { format: outputFormat });
|
|
5392
6054
|
return;
|
|
5393
6055
|
}
|
|
5394
|
-
console.log(
|
|
6056
|
+
console.log(chalk17.bold(`${preview.kind} bundle \xB7 ${preview.entityCount} entities`));
|
|
5395
6057
|
if (preview.sourceProjectId) {
|
|
5396
|
-
console.log(
|
|
6058
|
+
console.log(chalk17.dim(`from ${preview.sourceProjectId}/${preview.sourceProjectBranch}` + (preview.createdBy ? ` \xB7 by ${preview.createdBy}` : "")));
|
|
5397
6059
|
}
|
|
5398
6060
|
const counts = /* @__PURE__ */ new Map();
|
|
5399
6061
|
for (const e of preview.entities ?? []) {
|
|
@@ -5403,9 +6065,9 @@ Examples:
|
|
|
5403
6065
|
console.log(` ${type}: ${count}`);
|
|
5404
6066
|
}
|
|
5405
6067
|
if (preview.lossinessNotes && preview.lossinessNotes.length > 0) {
|
|
5406
|
-
console.log(
|
|
6068
|
+
console.log(chalk17.yellow("Lossiness:"));
|
|
5407
6069
|
for (const note of preview.lossinessNotes) {
|
|
5408
|
-
console.log(
|
|
6070
|
+
console.log(chalk17.yellow(` - ${note}`));
|
|
5409
6071
|
}
|
|
5410
6072
|
}
|
|
5411
6073
|
return;
|
|
@@ -5423,7 +6085,7 @@ Examples:
|
|
|
5423
6085
|
});
|
|
5424
6086
|
notebook.command("bundles").description("List notebook-bundle export jobs for a project").argument("<project>", "Project reference (projectId or projectId/branch)").action(async (project, _options, cmd) => {
|
|
5425
6087
|
try {
|
|
5426
|
-
const outputFormat =
|
|
6088
|
+
const outputFormat = getOutputFormat9(cmd);
|
|
5427
6089
|
const overrides = getOverrides7(cmd);
|
|
5428
6090
|
const ref = parseProjectReference(project, overrides);
|
|
5429
6091
|
const api = createApiClient();
|
|
@@ -5452,22 +6114,22 @@ Examples:
|
|
|
5452
6114
|
}
|
|
5453
6115
|
|
|
5454
6116
|
// src/commands/function/index.ts
|
|
5455
|
-
import
|
|
5456
|
-
import * as
|
|
5457
|
-
import * as
|
|
5458
|
-
import * as
|
|
6117
|
+
import chalk18 from "chalk";
|
|
6118
|
+
import * as fs8 from "fs";
|
|
6119
|
+
import * as os3 from "os";
|
|
6120
|
+
import * as path6 from "path";
|
|
5459
6121
|
import { spawn } from "child_process";
|
|
5460
|
-
import { randomUUID as
|
|
6122
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
5461
6123
|
|
|
5462
6124
|
// src/util/time-uuid.ts
|
|
5463
|
-
import { randomBytes } from "crypto";
|
|
6125
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
5464
6126
|
var GREGORIAN_OFFSET = 122192928000000000n;
|
|
5465
6127
|
var INTERVALS_PER_MILLI = 10000n;
|
|
5466
6128
|
function createTimeUuidGenerator() {
|
|
5467
|
-
const node =
|
|
6129
|
+
const node = randomBytes2(6);
|
|
5468
6130
|
node[0] |= 1;
|
|
5469
6131
|
const nodeHex = node.toString("hex");
|
|
5470
|
-
let clockSequence =
|
|
6132
|
+
let clockSequence = randomBytes2(2).readUInt16BE(0) & 16383;
|
|
5471
6133
|
let lastTimestamp = 0n;
|
|
5472
6134
|
let intervalsWithinMilli = 0n;
|
|
5473
6135
|
return function generate(now = Date.now()) {
|
|
@@ -5553,9 +6215,17 @@ function buildFunctionEntity(args) {
|
|
|
5553
6215
|
content: encodeFunctionSource(args.sourceCode)
|
|
5554
6216
|
};
|
|
5555
6217
|
}
|
|
6218
|
+
function resultText(result, resultEncoding) {
|
|
6219
|
+
if (result === null || result === void 0) return null;
|
|
6220
|
+
if (resultEncoding === "json") return typeof result === "string" ? result : JSON.stringify(result);
|
|
6221
|
+
if (resultEncoding === "text") return String(result);
|
|
6222
|
+
const bytes = Buffer.from(String(result), "base64");
|
|
6223
|
+
const text2 = bytes.toString("utf-8");
|
|
6224
|
+
return Buffer.from(text2, "utf-8").equals(bytes) ? text2 : String(result);
|
|
6225
|
+
}
|
|
5556
6226
|
|
|
5557
6227
|
// src/commands/function/index.ts
|
|
5558
|
-
function
|
|
6228
|
+
function getOutputFormat10(cmd) {
|
|
5559
6229
|
const config = loadConfig();
|
|
5560
6230
|
const globalOpts = cmd.optsWithGlobals();
|
|
5561
6231
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5585,7 +6255,7 @@ Examples:
|
|
|
5585
6255
|
;
|
|
5586
6256
|
fn.command("call").description("Execute a function").argument("<ref>", "Function entity reference").option("--async", "Execute asynchronously").option("--args <json>", "Arguments as JSON object").option("--target <ref>", "Target entity reference").action(async (ref, options, cmd) => {
|
|
5587
6257
|
try {
|
|
5588
|
-
const outputFormat =
|
|
6258
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
5589
6259
|
const overrides = getOverrides8(cmd);
|
|
5590
6260
|
const resolved = parseEntityReference(ref, overrides);
|
|
5591
6261
|
const api = createApiClient();
|
|
@@ -5638,12 +6308,12 @@ Examples:
|
|
|
5638
6308
|
if (result.successful) {
|
|
5639
6309
|
success("Function completed successfully.");
|
|
5640
6310
|
if (result.result) {
|
|
5641
|
-
console.log(` Result: ${result.result}`);
|
|
6311
|
+
console.log(` Result: ${resultText(result.result, result.resultEncoding)}`);
|
|
5642
6312
|
}
|
|
5643
6313
|
const duration = result.completed - result.started;
|
|
5644
6314
|
console.log(` Duration: ${duration}ms`);
|
|
5645
6315
|
} else {
|
|
5646
|
-
console.log(
|
|
6316
|
+
console.log(chalk18.red("Function failed."));
|
|
5647
6317
|
console.log(` Error: ${result.error}`);
|
|
5648
6318
|
if (result.lineNumber > 0) {
|
|
5649
6319
|
console.log(` Line: ${result.lineNumber}, Column: ${result.columnNumber}`);
|
|
@@ -5651,7 +6321,7 @@ Examples:
|
|
|
5651
6321
|
}
|
|
5652
6322
|
if (result.outputs?.length) {
|
|
5653
6323
|
console.log();
|
|
5654
|
-
console.log(
|
|
6324
|
+
console.log(chalk18.bold("Outputs:"));
|
|
5655
6325
|
for (const out of result.outputs) {
|
|
5656
6326
|
console.log(` [${out.type}] ${out.output}`);
|
|
5657
6327
|
}
|
|
@@ -5666,7 +6336,7 @@ Examples:
|
|
|
5666
6336
|
});
|
|
5667
6337
|
fn.command("evaluations").description("List evaluations for a function").argument("<ref>", "Function entity reference").requiredOption("--date <date>", "Date and hour (YYYY-MM-DD-HH in UTC)").action(async (ref, options, cmd) => {
|
|
5668
6338
|
try {
|
|
5669
|
-
const outputFormat =
|
|
6339
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
5670
6340
|
const overrides = getOverrides8(cmd);
|
|
5671
6341
|
const resolved = parseEntityReference(ref, overrides);
|
|
5672
6342
|
const api = createApiClient();
|
|
@@ -5707,7 +6377,7 @@ Examples:
|
|
|
5707
6377
|
});
|
|
5708
6378
|
fn.command("outputs").description("Get outputs for an evaluation").argument("<projectId>", "Project ID").argument("<evaluationId>", "Evaluation ID").action(async (projectId, evaluationId, _options, cmd) => {
|
|
5709
6379
|
try {
|
|
5710
|
-
const outputFormat =
|
|
6380
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
5711
6381
|
const api = createApiClient();
|
|
5712
6382
|
const outputs = await api.evaluation.getOutputs(projectId, evaluationId);
|
|
5713
6383
|
if (outputFormat === "human") {
|
|
@@ -5716,7 +6386,7 @@ Examples:
|
|
|
5716
6386
|
}
|
|
5717
6387
|
for (const out of outputs) {
|
|
5718
6388
|
const time = new Date(out.timestamp).toISOString();
|
|
5719
|
-
console.log(`${
|
|
6389
|
+
console.log(`${chalk18.dim(time)} [${out.type}] ${out.output}`);
|
|
5720
6390
|
}
|
|
5721
6391
|
} else {
|
|
5722
6392
|
format(outputs, { format: outputFormat });
|
|
@@ -5727,7 +6397,7 @@ Examples:
|
|
|
5727
6397
|
});
|
|
5728
6398
|
fn.command("logs").description("Get logs for a function evaluation").argument("<ref>", "Function entity reference").requiredOption("--date <date>", "Date and hour (YYYY-MM-DD-HH in UTC)").action(async (ref, options, cmd) => {
|
|
5729
6399
|
try {
|
|
5730
|
-
const outputFormat =
|
|
6400
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
5731
6401
|
const overrides = getOverrides8(cmd);
|
|
5732
6402
|
const resolved = parseEntityReference(ref, overrides);
|
|
5733
6403
|
const api = createApiClient();
|
|
@@ -5773,7 +6443,7 @@ Examples:
|
|
|
5773
6443
|
});
|
|
5774
6444
|
fn.command("languages").description("List the languages a function can be written in").action(async (_options, cmd) => {
|
|
5775
6445
|
try {
|
|
5776
|
-
const outputFormat =
|
|
6446
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
5777
6447
|
format(
|
|
5778
6448
|
FUNCTION_LANGUAGES.map((language) => ({
|
|
5779
6449
|
language,
|
|
@@ -5787,7 +6457,7 @@ Examples:
|
|
|
5787
6457
|
});
|
|
5788
6458
|
fn.command("last-evaluation").description("Show the most recent evaluation of a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
5789
6459
|
try {
|
|
5790
|
-
const outputFormat =
|
|
6460
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
5791
6461
|
const overrides = getOverrides8(cmd);
|
|
5792
6462
|
const resolved = parseEntityReference(ref, overrides);
|
|
5793
6463
|
const api = createApiClient();
|
|
@@ -5807,7 +6477,7 @@ Examples:
|
|
|
5807
6477
|
const overrides = getOverrides8(cmd);
|
|
5808
6478
|
const resolved = parseEntityReference(ref, overrides);
|
|
5809
6479
|
const api = createApiClient();
|
|
5810
|
-
const sourceCode = options.source ?
|
|
6480
|
+
const sourceCode = options.source ? fs8.readFileSync(options.source, "utf-8") : "";
|
|
5811
6481
|
const entity = buildFunctionEntity({
|
|
5812
6482
|
projectId: resolved.projectId,
|
|
5813
6483
|
projectBranch: resolved.projectBranch,
|
|
@@ -5833,7 +6503,7 @@ Examples:
|
|
|
5833
6503
|
const entity = await api.storage.getEntity(resolved, true);
|
|
5834
6504
|
const sourceCode = decodeFunctionSource(entity);
|
|
5835
6505
|
if (options.out) {
|
|
5836
|
-
|
|
6506
|
+
fs8.writeFileSync(options.out, sourceCode);
|
|
5837
6507
|
success(`Source written to ${options.out}`);
|
|
5838
6508
|
} else {
|
|
5839
6509
|
process.stdout.write(sourceCode);
|
|
@@ -5848,13 +6518,13 @@ Examples:
|
|
|
5848
6518
|
const overrides = getOverrides8(cmd);
|
|
5849
6519
|
const resolved = parseEntityReference(ref, overrides);
|
|
5850
6520
|
const api = createApiClient();
|
|
5851
|
-
const sourceCode = file ?
|
|
6521
|
+
const sourceCode = file ? fs8.readFileSync(file, "utf-8") : await new Promise((resolve2, reject) => {
|
|
5852
6522
|
let data = "";
|
|
5853
6523
|
process.stdin.setEncoding("utf-8");
|
|
5854
6524
|
process.stdin.on("data", (chunk) => {
|
|
5855
6525
|
data += chunk;
|
|
5856
6526
|
});
|
|
5857
|
-
process.stdin.on("end", () =>
|
|
6527
|
+
process.stdin.on("end", () => resolve2(data));
|
|
5858
6528
|
process.stdin.on("error", reject);
|
|
5859
6529
|
});
|
|
5860
6530
|
await api.storage.saveEntityContentBase64(resolved, encodeFunctionSource(sourceCode));
|
|
@@ -5872,16 +6542,16 @@ Examples:
|
|
|
5872
6542
|
const currentSource = decodeFunctionSource(entity);
|
|
5873
6543
|
const language = decodeTextAttribute(entity.attributes?.["language"]) ?? "txt";
|
|
5874
6544
|
const ext = extensionFor(language);
|
|
5875
|
-
const tmpFile =
|
|
5876
|
-
|
|
6545
|
+
const tmpFile = path6.join(os3.tmpdir(), `diafunc-${resolved.entityId}-${randomUUID3()}.${ext}`);
|
|
6546
|
+
fs8.writeFileSync(tmpFile, currentSource);
|
|
5877
6547
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
5878
|
-
await new Promise((
|
|
6548
|
+
await new Promise((resolve2, reject) => {
|
|
5879
6549
|
const child = spawn(editor, [tmpFile], { stdio: "inherit" });
|
|
5880
|
-
child.on("exit", (code) => code === 0 ?
|
|
6550
|
+
child.on("exit", (code) => code === 0 ? resolve2() : reject(new Error(`Editor exited with code ${code}`)));
|
|
5881
6551
|
child.on("error", reject);
|
|
5882
6552
|
});
|
|
5883
|
-
const newSource =
|
|
5884
|
-
|
|
6553
|
+
const newSource = fs8.readFileSync(tmpFile, "utf-8");
|
|
6554
|
+
fs8.unlinkSync(tmpFile);
|
|
5885
6555
|
if (newSource === currentSource) {
|
|
5886
6556
|
empty("changes");
|
|
5887
6557
|
return;
|
|
@@ -5904,7 +6574,7 @@ function extensionFor(language) {
|
|
|
5904
6574
|
}
|
|
5905
6575
|
|
|
5906
6576
|
// src/commands/trigger/index.ts
|
|
5907
|
-
function
|
|
6577
|
+
function getOutputFormat11(cmd) {
|
|
5908
6578
|
const config = loadConfig();
|
|
5909
6579
|
const globalOpts = cmd.optsWithGlobals();
|
|
5910
6580
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5923,7 +6593,7 @@ Examples:
|
|
|
5923
6593
|
;
|
|
5924
6594
|
trigger.command("list").description("List triggers for a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
5925
6595
|
try {
|
|
5926
|
-
const outputFormat =
|
|
6596
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
5927
6597
|
const overrides = getOverrides9(cmd);
|
|
5928
6598
|
const resolved = parseEntityReference(ref, overrides);
|
|
5929
6599
|
const api = createApiClient();
|
|
@@ -5951,7 +6621,7 @@ Examples:
|
|
|
5951
6621
|
});
|
|
5952
6622
|
trigger.command("get").description("Get a specific trigger").argument("<ref>", "Function entity reference").argument("<triggerId>", "Trigger ID").action(async (ref, triggerId, _options, cmd) => {
|
|
5953
6623
|
try {
|
|
5954
|
-
const outputFormat =
|
|
6624
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
5955
6625
|
const overrides = getOverrides9(cmd);
|
|
5956
6626
|
const resolved = parseEntityReference(ref, overrides);
|
|
5957
6627
|
const api = createApiClient();
|
|
@@ -6035,7 +6705,7 @@ Examples:
|
|
|
6035
6705
|
}
|
|
6036
6706
|
|
|
6037
6707
|
// src/commands/schedule/index.ts
|
|
6038
|
-
function
|
|
6708
|
+
function getOutputFormat12(cmd) {
|
|
6039
6709
|
const config = loadConfig();
|
|
6040
6710
|
const globalOpts = cmd.optsWithGlobals();
|
|
6041
6711
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -6048,7 +6718,7 @@ function registerScheduleCommands(program) {
|
|
|
6048
6718
|
const schedule = program.command("schedule").description("Schedule function execution");
|
|
6049
6719
|
schedule.command("call").description("Schedule a function call").argument("<ref>", "Function entity reference").option("--args <json>", "Arguments as JSON object").option("--target <ref>", "Target entity reference").action(async (ref, options, cmd) => {
|
|
6050
6720
|
try {
|
|
6051
|
-
const outputFormat =
|
|
6721
|
+
const outputFormat = getOutputFormat12(cmd);
|
|
6052
6722
|
const overrides = getOverrides10(cmd);
|
|
6053
6723
|
const resolved = parseEntityReference(ref, overrides);
|
|
6054
6724
|
const api = createApiClient();
|
|
@@ -6117,7 +6787,7 @@ function registerScheduleCommands(program) {
|
|
|
6117
6787
|
});
|
|
6118
6788
|
schedule.command("list").description("List persistent triggers (scheduled functions are modeled as triggers)").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
6119
6789
|
try {
|
|
6120
|
-
const outputFormat =
|
|
6790
|
+
const outputFormat = getOutputFormat12(cmd);
|
|
6121
6791
|
const overrides = getOverrides10(cmd);
|
|
6122
6792
|
const resolved = parseEntityReference(ref, overrides);
|
|
6123
6793
|
const api = createApiClient();
|
|
@@ -6147,12 +6817,12 @@ function registerScheduleCommands(program) {
|
|
|
6147
6817
|
}
|
|
6148
6818
|
|
|
6149
6819
|
// src/commands/chat/index.ts
|
|
6150
|
-
import
|
|
6151
|
-
import * as
|
|
6152
|
-
import * as
|
|
6820
|
+
import chalk20 from "chalk";
|
|
6821
|
+
import * as fs9 from "fs";
|
|
6822
|
+
import * as path7 from "path";
|
|
6153
6823
|
|
|
6154
6824
|
// src/output/markdown.ts
|
|
6155
|
-
import
|
|
6825
|
+
import chalk19 from "chalk";
|
|
6156
6826
|
var CODE_OPEN = "\0c";
|
|
6157
6827
|
var CODE_CLOSE = "\0";
|
|
6158
6828
|
var MarkdownRenderer = class {
|
|
@@ -6188,25 +6858,25 @@ var MarkdownRenderer = class {
|
|
|
6188
6858
|
if (fence) {
|
|
6189
6859
|
const opening = !this.inFence;
|
|
6190
6860
|
this.inFence = !this.inFence;
|
|
6191
|
-
return opening && fence[1] ? [
|
|
6861
|
+
return opening && fence[1] ? [chalk19.dim(` ${fence[1]}`)] : [];
|
|
6192
6862
|
}
|
|
6193
6863
|
if (this.inFence) {
|
|
6194
|
-
return [
|
|
6864
|
+
return [chalk19.cyan(` ${line}`)];
|
|
6195
6865
|
}
|
|
6196
6866
|
const heading2 = line.match(/^(#{1,6})\s+(.*)$/);
|
|
6197
6867
|
if (heading2) {
|
|
6198
6868
|
const text2 = inline(heading2[2]);
|
|
6199
|
-
return ["", heading2[1].length <= 2 ?
|
|
6869
|
+
return ["", heading2[1].length <= 2 ? chalk19.bold.underline(text2) : chalk19.bold(text2)];
|
|
6200
6870
|
}
|
|
6201
6871
|
if (/^\s*([-*_])\1{2,}\s*$/.test(line)) {
|
|
6202
|
-
return [
|
|
6872
|
+
return [chalk19.dim("\u2500".repeat(Math.min(this.width, 60)))];
|
|
6203
6873
|
}
|
|
6204
6874
|
const quote2 = line.match(/^\s*>\s?(.*)$/);
|
|
6205
|
-
if (quote2) return [
|
|
6875
|
+
if (quote2) return [chalk19.dim(` \u2502 ${inline(quote2[1])}`)];
|
|
6206
6876
|
const bullet = line.match(/^(\s*)[-*+]\s+(.*)$/);
|
|
6207
6877
|
if (bullet) {
|
|
6208
6878
|
return wrapWithIndent(
|
|
6209
|
-
`${bullet[1]}${
|
|
6879
|
+
`${bullet[1]}${chalk19.cyan("\u2022")} ${inline(bullet[2])}`,
|
|
6210
6880
|
bullet[1].length + 2,
|
|
6211
6881
|
this.width
|
|
6212
6882
|
);
|
|
@@ -6214,7 +6884,7 @@ var MarkdownRenderer = class {
|
|
|
6214
6884
|
const numbered = line.match(/^(\s*)(\d+)\.\s+(.*)$/);
|
|
6215
6885
|
if (numbered) {
|
|
6216
6886
|
return wrapWithIndent(
|
|
6217
|
-
`${numbered[1]}${
|
|
6887
|
+
`${numbered[1]}${chalk19.cyan(`${numbered[2]}.`)} ${inline(numbered[3])}`,
|
|
6218
6888
|
numbered[1].length + numbered[2].length + 2,
|
|
6219
6889
|
this.width
|
|
6220
6890
|
);
|
|
@@ -6237,15 +6907,15 @@ function inline(text2) {
|
|
|
6237
6907
|
codeSpans.push(code);
|
|
6238
6908
|
return `${CODE_OPEN}${codeSpans.length - 1}${CODE_CLOSE}`;
|
|
6239
6909
|
});
|
|
6240
|
-
working = working.replace(/\*\*([^*]+)\*\*/g, (_m, t) =>
|
|
6910
|
+
working = working.replace(/\*\*([^*]+)\*\*/g, (_m, t) => chalk19.bold(t)).replace(/__([^_]+)__/g, (_m, t) => chalk19.bold(t)).replace(/(^|[^*])\*([^*\n]+)\*/g, (_m, lead, t) => lead + chalk19.italic(t)).replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, label, url) => `${chalk19.underline(label)} ${chalk19.dim(`(${url})`)}`);
|
|
6241
6911
|
return working.replace(
|
|
6242
6912
|
new RegExp(`${CODE_OPEN}(\\d+)${CODE_CLOSE}`, "g"),
|
|
6243
|
-
(_m, i) =>
|
|
6913
|
+
(_m, i) => chalk19.yellow(codeSpans[Number(i)])
|
|
6244
6914
|
);
|
|
6245
6915
|
}
|
|
6246
6916
|
|
|
6247
6917
|
// src/commands/chat/index.ts
|
|
6248
|
-
function
|
|
6918
|
+
function getOutputFormat13(cmd) {
|
|
6249
6919
|
const config = loadConfig();
|
|
6250
6920
|
const globalOpts = cmd.optsWithGlobals();
|
|
6251
6921
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -6253,7 +6923,7 @@ function getOutputFormat12(cmd) {
|
|
|
6253
6923
|
async function streamOneTurn(message, sessionId, projectId, branch, signal) {
|
|
6254
6924
|
const api = createApiClient();
|
|
6255
6925
|
const status = new Status();
|
|
6256
|
-
status.set([` ${
|
|
6926
|
+
status.set([` ${chalk20.magenta(SPINNER)} ${chalk20.dim("thinking")}`]);
|
|
6257
6927
|
status.start();
|
|
6258
6928
|
let response;
|
|
6259
6929
|
try {
|
|
@@ -6330,19 +7000,19 @@ var HELP = [
|
|
|
6330
7000
|
];
|
|
6331
7001
|
async function runChatRepl(options) {
|
|
6332
7002
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
6333
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
7003
|
+
const { getUpdateNotice } = await import("./update-check-YRTWCRNY.js");
|
|
6334
7004
|
let sessionId = options.session;
|
|
6335
7005
|
let lastReportedSession;
|
|
6336
|
-
console.log(
|
|
6337
|
-
if (options.project) console.log(
|
|
6338
|
-
if (sessionId) console.log(
|
|
7006
|
+
console.log(chalk20.bold("Diafunc chat") + chalk20.dim(" \xB7 /help for commands, /quit to exit"));
|
|
7007
|
+
if (options.project) console.log(chalk20.dim(`Project context: ${options.project}`));
|
|
7008
|
+
if (sessionId) console.log(chalk20.dim(`Continuing session ${sessionId}`));
|
|
6339
7009
|
const notice = await getUpdateNotice();
|
|
6340
|
-
if (notice) console.log(
|
|
7010
|
+
if (notice) console.log(chalk20.dim(notice));
|
|
6341
7011
|
console.log();
|
|
6342
7012
|
for (; ; ) {
|
|
6343
7013
|
let line;
|
|
6344
7014
|
try {
|
|
6345
|
-
line = await promptInput({ message:
|
|
7015
|
+
line = await promptInput({ message: chalk20.cyan.bold("you >") });
|
|
6346
7016
|
} catch {
|
|
6347
7017
|
console.log();
|
|
6348
7018
|
return;
|
|
@@ -6360,27 +7030,27 @@ async function runChatRepl(options) {
|
|
|
6360
7030
|
case "new":
|
|
6361
7031
|
sessionId = void 0;
|
|
6362
7032
|
lastReportedSession = void 0;
|
|
6363
|
-
console.log(
|
|
7033
|
+
console.log(chalk20.dim("Started a new session."));
|
|
6364
7034
|
continue;
|
|
6365
7035
|
case "clear":
|
|
6366
7036
|
console.clear();
|
|
6367
7037
|
continue;
|
|
6368
7038
|
case "session":
|
|
6369
7039
|
if (!arg) {
|
|
6370
|
-
console.log(
|
|
7040
|
+
console.log(chalk20.dim(`Current session: ${sessionId ?? "(new)"}`));
|
|
6371
7041
|
} else {
|
|
6372
7042
|
sessionId = arg;
|
|
6373
7043
|
lastReportedSession = void 0;
|
|
6374
|
-
console.log(
|
|
7044
|
+
console.log(chalk20.dim(`Switched to session ${sessionId}`));
|
|
6375
7045
|
}
|
|
6376
7046
|
continue;
|
|
6377
7047
|
case "help":
|
|
6378
7048
|
case "h":
|
|
6379
7049
|
case "?":
|
|
6380
|
-
for (const l of HELP) console.log(
|
|
7050
|
+
for (const l of HELP) console.log(chalk20.dim(l));
|
|
6381
7051
|
continue;
|
|
6382
7052
|
default:
|
|
6383
|
-
console.log(
|
|
7053
|
+
console.log(chalk20.dim(`Unknown command: /${cmd}. Try /help.`));
|
|
6384
7054
|
continue;
|
|
6385
7055
|
}
|
|
6386
7056
|
}
|
|
@@ -6393,19 +7063,19 @@ async function runChatRepl(options) {
|
|
|
6393
7063
|
sessionId = result.sessionId || sessionId;
|
|
6394
7064
|
console.log();
|
|
6395
7065
|
if (controller.signal.aborted) {
|
|
6396
|
-
console.log(
|
|
7066
|
+
console.log(chalk20.dim(" (cancelled)"));
|
|
6397
7067
|
} else {
|
|
6398
7068
|
const parts = [`${result.input} in / ${result.output} out`];
|
|
6399
7069
|
if (sessionId && sessionId !== lastReportedSession) {
|
|
6400
7070
|
parts.push(`session ${sessionId}`);
|
|
6401
7071
|
lastReportedSession = sessionId;
|
|
6402
7072
|
}
|
|
6403
|
-
console.log(
|
|
7073
|
+
console.log(chalk20.dim(` ${parts.join(" \xB7 ")}`));
|
|
6404
7074
|
}
|
|
6405
7075
|
console.log();
|
|
6406
7076
|
} catch (error) {
|
|
6407
7077
|
if (controller.signal.aborted) {
|
|
6408
|
-
console.log(
|
|
7078
|
+
console.log(chalk20.dim(" (cancelled)"));
|
|
6409
7079
|
console.log();
|
|
6410
7080
|
} else {
|
|
6411
7081
|
failure(`Request failed: ${error.message}`);
|
|
@@ -6437,7 +7107,7 @@ Examples:
|
|
|
6437
7107
|
});
|
|
6438
7108
|
chat.command("send").description("Send a chat message (blocking). Project context: the global --project and --branch").argument("<message>", "Message to send").option("--session <id>", "Session ID to continue").action(async (message, options, cmd) => {
|
|
6439
7109
|
try {
|
|
6440
|
-
const outputFormat =
|
|
7110
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
6441
7111
|
const api = createApiClient();
|
|
6442
7112
|
const context = chatContext(cmd);
|
|
6443
7113
|
const response = await api.language.chat({
|
|
@@ -6449,7 +7119,7 @@ Examples:
|
|
|
6449
7119
|
if (outputFormat === "human") {
|
|
6450
7120
|
console.log(renderMarkdown(response.content));
|
|
6451
7121
|
console.log();
|
|
6452
|
-
console.log(
|
|
7122
|
+
console.log(chalk20.dim(
|
|
6453
7123
|
` session ${response.sessionId} \xB7 ${response.inputTokens} in / ${response.outputTokens} out`
|
|
6454
7124
|
));
|
|
6455
7125
|
} else {
|
|
@@ -6461,7 +7131,7 @@ Examples:
|
|
|
6461
7131
|
});
|
|
6462
7132
|
chat.command("stream").description("Send a chat message (streaming). Project context: the global --project and --branch").argument("<message>", "Message to send").option("--session <id>", "Session ID to continue").action(async (message, options, cmd) => {
|
|
6463
7133
|
try {
|
|
6464
|
-
const outputFormat =
|
|
7134
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
6465
7135
|
const api = createApiClient();
|
|
6466
7136
|
const context = chatContext(cmd);
|
|
6467
7137
|
const response = await api.language.chatStream({
|
|
@@ -6517,7 +7187,7 @@ Examples:
|
|
|
6517
7187
|
sessionId = event.sessionId ?? "";
|
|
6518
7188
|
console.log();
|
|
6519
7189
|
console.log();
|
|
6520
|
-
console.log(
|
|
7190
|
+
console.log(chalk20.dim(`Session: ${sessionId} | Tokens: ${event.inputTokens} in, ${event.outputTokens} out`));
|
|
6521
7191
|
} else if (event.type === "error") {
|
|
6522
7192
|
failure(`Error: ${event.content}`);
|
|
6523
7193
|
}
|
|
@@ -6533,15 +7203,15 @@ Examples:
|
|
|
6533
7203
|
});
|
|
6534
7204
|
chat.command("upload").description("Upload a file for chat context").argument("<file>", "File to upload").action(async (file) => {
|
|
6535
7205
|
try {
|
|
6536
|
-
if (!
|
|
7206
|
+
if (!fs9.existsSync(file)) {
|
|
6537
7207
|
failure(`File not found: ${file}`);
|
|
6538
7208
|
process.exit(1);
|
|
6539
7209
|
}
|
|
6540
7210
|
const api = createApiClient();
|
|
6541
|
-
const fileBuffer =
|
|
7211
|
+
const fileBuffer = fs9.readFileSync(file);
|
|
6542
7212
|
const blob = new Blob([fileBuffer]);
|
|
6543
7213
|
const formData = new FormData();
|
|
6544
|
-
formData.append("file", blob,
|
|
7214
|
+
formData.append("file", blob, path7.basename(file));
|
|
6545
7215
|
const result = await api.language.upload(formData);
|
|
6546
7216
|
success(`File uploaded: ${result}`);
|
|
6547
7217
|
} catch (error) {
|
|
@@ -6551,7 +7221,7 @@ Examples:
|
|
|
6551
7221
|
const session = chat.command("session").description("Manage chat sessions");
|
|
6552
7222
|
session.command("list").description("List chat sessions").action(async (_options, cmd) => {
|
|
6553
7223
|
try {
|
|
6554
|
-
const outputFormat =
|
|
7224
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
6555
7225
|
const api = createApiClient();
|
|
6556
7226
|
const sessions = await api.language.getSessions();
|
|
6557
7227
|
format(sessions, {
|
|
@@ -6573,15 +7243,15 @@ Examples:
|
|
|
6573
7243
|
});
|
|
6574
7244
|
session.command("show").description("Show the message history of a chat session").argument("<sessionId>", "Session ID").action(async (sessionId, _options, cmd) => {
|
|
6575
7245
|
try {
|
|
6576
|
-
const outputFormat =
|
|
7246
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
6577
7247
|
const api = createApiClient();
|
|
6578
7248
|
const detail2 = await api.language.getSession(sessionId);
|
|
6579
7249
|
if (outputFormat === "human") {
|
|
6580
|
-
console.log(
|
|
7250
|
+
console.log(chalk20.bold(detail2.title) + chalk20.dim(` (${detail2.sessionId})`));
|
|
6581
7251
|
console.log();
|
|
6582
7252
|
for (const msg of detail2.messages) {
|
|
6583
|
-
const role = msg.role === "user" ?
|
|
6584
|
-
console.log(`${role} ${
|
|
7253
|
+
const role = msg.role === "user" ? chalk20.cyan.bold("You") : chalk20.magenta.bold("Diafunc");
|
|
7254
|
+
console.log(`${role} ${chalk20.dim(msg.created)}`);
|
|
6585
7255
|
console.log(msg.content);
|
|
6586
7256
|
console.log();
|
|
6587
7257
|
}
|
|
@@ -6603,7 +7273,7 @@ Examples:
|
|
|
6603
7273
|
});
|
|
6604
7274
|
chat.command("usage").description("Show token usage").action(async (_options, cmd) => {
|
|
6605
7275
|
try {
|
|
6606
|
-
const outputFormat =
|
|
7276
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
6607
7277
|
const api = createApiClient();
|
|
6608
7278
|
const usage = await api.language.getUsage();
|
|
6609
7279
|
format(usage, { format: outputFormat });
|
|
@@ -6614,8 +7284,8 @@ Examples:
|
|
|
6614
7284
|
}
|
|
6615
7285
|
|
|
6616
7286
|
// src/commands/search/index.ts
|
|
6617
|
-
import
|
|
6618
|
-
function
|
|
7287
|
+
import chalk21 from "chalk";
|
|
7288
|
+
function getOutputFormat14(cmd) {
|
|
6619
7289
|
const config = loadConfig();
|
|
6620
7290
|
const globalOpts = cmd.optsWithGlobals();
|
|
6621
7291
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -6638,7 +7308,7 @@ whose discovered model has the better quality comes first; inside one project th
|
|
|
6638
7308
|
`).action(async (query, options, cmd) => {
|
|
6639
7309
|
const sort = parseSort(options.sort);
|
|
6640
7310
|
try {
|
|
6641
|
-
const outputFormat =
|
|
7311
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
6642
7312
|
const overrides = cmd.optsWithGlobals();
|
|
6643
7313
|
const config = loadConfig();
|
|
6644
7314
|
const api = createApiClient();
|
|
@@ -6676,7 +7346,7 @@ whose discovered model has the better quality comes first; inside one project th
|
|
|
6676
7346
|
});
|
|
6677
7347
|
}
|
|
6678
7348
|
if (page.nextCursor && isInteractive()) {
|
|
6679
|
-
console.log(
|
|
7349
|
+
console.log(chalk21.dim(`More results available. Raise --limit to see them.`));
|
|
6680
7350
|
}
|
|
6681
7351
|
} catch (error) {
|
|
6682
7352
|
handleError(error);
|
|
@@ -6698,12 +7368,12 @@ function renderResults(items) {
|
|
|
6698
7368
|
for (const item of items) {
|
|
6699
7369
|
const name = item.name || "(unnamed)";
|
|
6700
7370
|
console.log();
|
|
6701
|
-
console.log(`${
|
|
7371
|
+
console.log(`${chalk21.dim(`[${item.contentType}]`)} ${chalk21.bold(name)}${qualityNote(item)}`);
|
|
6702
7372
|
const raw = item.snippetField === "name" ? item.description : item.snippet ?? item.description;
|
|
6703
7373
|
const line = raw ? collapse(raw) : null;
|
|
6704
7374
|
if (line && stripHighlight(line) !== name) console.log(` ${highlight(line)}`);
|
|
6705
7375
|
const ref = item.entityId ? `${item.projectId}/${item.projectBranch}/${item.entityId}/${item.entityBranch ?? "main"}` : item.projectId;
|
|
6706
|
-
console.log(` ${
|
|
7376
|
+
console.log(` ${chalk21.dim(ref)}`);
|
|
6707
7377
|
}
|
|
6708
7378
|
console.log();
|
|
6709
7379
|
}
|
|
@@ -6711,16 +7381,16 @@ function qualityNote(item) {
|
|
|
6711
7381
|
if (item.contentType !== "project" || typeof item.quality !== "number" || !Number.isFinite(item.quality)) {
|
|
6712
7382
|
return "";
|
|
6713
7383
|
}
|
|
6714
|
-
return
|
|
7384
|
+
return chalk21.dim(` quality ${percent(item.quality).trim()}`);
|
|
6715
7385
|
}
|
|
6716
7386
|
var HIGHLIGHT_OPEN = /<mark>/g;
|
|
6717
7387
|
var HIGHLIGHT_CLOSE = /<\/mark>/g;
|
|
6718
7388
|
function highlight(text2) {
|
|
6719
7389
|
const parts = text2.split(HIGHLIGHT_OPEN);
|
|
6720
7390
|
return parts.map((part, i) => {
|
|
6721
|
-
if (i === 0) return
|
|
7391
|
+
if (i === 0) return chalk21.dim(part);
|
|
6722
7392
|
const [marked, ...rest] = part.split(HIGHLIGHT_CLOSE);
|
|
6723
|
-
return
|
|
7393
|
+
return chalk21.bold.cyan(marked) + chalk21.dim(rest.join(""));
|
|
6724
7394
|
}).join("");
|
|
6725
7395
|
}
|
|
6726
7396
|
function stripHighlight(text2) {
|
|
@@ -6733,7 +7403,147 @@ function collapse(text2) {
|
|
|
6733
7403
|
|
|
6734
7404
|
// src/commands/admin/index.ts
|
|
6735
7405
|
import { readFile } from "fs/promises";
|
|
6736
|
-
|
|
7406
|
+
|
|
7407
|
+
// src/commands/admin/curated-tags.ts
|
|
7408
|
+
import chalk22 from "chalk";
|
|
7409
|
+
function getOutputFormat15(cmd) {
|
|
7410
|
+
const config = loadConfig();
|
|
7411
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
7412
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
7413
|
+
}
|
|
7414
|
+
var COLUMNS = [
|
|
7415
|
+
{ key: "tag" },
|
|
7416
|
+
{ key: "displayName", header: "name" },
|
|
7417
|
+
{ key: "description" },
|
|
7418
|
+
{ key: "sortOrder", header: "order", kind: "number" },
|
|
7419
|
+
{ key: "projectCount", header: "public projects", kind: "number" }
|
|
7420
|
+
];
|
|
7421
|
+
function curatedTagOf(typed2) {
|
|
7422
|
+
const tag = normalizeTag(typed2);
|
|
7423
|
+
if (tag === "") usageError(`"${typed2}" is not a usable tag: a tag needs at least one letter or digit.`);
|
|
7424
|
+
if (tag !== typed2) console.error(chalk22.dim(`"${typed2}" is written as "${tag}", the form tags are searched by.`));
|
|
7425
|
+
return tag;
|
|
7426
|
+
}
|
|
7427
|
+
function parseSortOrder(raw) {
|
|
7428
|
+
if (!/^-?\d+$/.test(raw.trim())) usageError(`Invalid --sort-order "${raw}": a whole number is expected.`);
|
|
7429
|
+
return Number.parseInt(raw, 10);
|
|
7430
|
+
}
|
|
7431
|
+
function registerCuratedTagCommands(admin) {
|
|
7432
|
+
const curated = admin.command("curated-tags").description('The curated tags: the "data domain" filter of Explore').addHelpText("after", `
|
|
7433
|
+
A curated tag gives a tag a name and a place in Explore's data-domain filter; a project
|
|
7434
|
+
appears under it when it carries the tag (see 'diafunc project tags'). Anyone can list
|
|
7435
|
+
them; creating, updating and deleting need a platform administrator.
|
|
7436
|
+
|
|
7437
|
+
Examples:
|
|
7438
|
+
$ diafunc admin curated-tags list
|
|
7439
|
+
$ diafunc admin curated-tags create health --display-name "Health" --sort-order 1
|
|
7440
|
+
$ diafunc admin curated-tags update health --description "Medicine, public health, biology"
|
|
7441
|
+
$ diafunc admin curated-tags delete health
|
|
7442
|
+
`);
|
|
7443
|
+
curated.command("list").description("List the curated tags in their order, with the number of public projects under each").addHelpText("after", `
|
|
7444
|
+
Needs no account. The counts are of public projects only and can be a minute behind.
|
|
7445
|
+
|
|
7446
|
+
Examples:
|
|
7447
|
+
$ diafunc admin curated-tags list
|
|
7448
|
+
$ diafunc admin curated-tags list -o json
|
|
7449
|
+
`).action(async (_options, cmd) => {
|
|
7450
|
+
try {
|
|
7451
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
7452
|
+
const tags = await createApiClient().index.getCuratedTags(true);
|
|
7453
|
+
if (tags.length === 0) {
|
|
7454
|
+
empty("curated tags", { format: outputFormat });
|
|
7455
|
+
return;
|
|
7456
|
+
}
|
|
7457
|
+
format(tags, { format: outputFormat, columns: COLUMNS });
|
|
7458
|
+
} catch (error) {
|
|
7459
|
+
handleError(error);
|
|
7460
|
+
}
|
|
7461
|
+
});
|
|
7462
|
+
curated.command("create").description("Create a curated tag (admin)").argument("<tag>", 'The tag projects carry, stored in its canonical form ("Machine Learning" becomes "machine-learning")').requiredOption("--display-name <name>", "The name Explore shows for it").option("--description <text>", "What belongs under it").option("--sort-order <n>", "Position in the filter, lowest first; tags without one come last").addHelpText("after", `
|
|
7463
|
+
Examples:
|
|
7464
|
+
$ diafunc admin curated-tags create health --display-name "Health" --sort-order 1
|
|
7465
|
+
$ diafunc admin curated-tags create "Machine Learning" --display-name "Machine learning" --dry-run
|
|
7466
|
+
`).action(async (typed2, options, cmd) => {
|
|
7467
|
+
try {
|
|
7468
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
7469
|
+
const tag = curatedTagOf(typed2);
|
|
7470
|
+
if (isReservedTag(tag)) {
|
|
7471
|
+
usageError(`"${tag}" is reserved for the staging content of analysis runs and is never searchable.`);
|
|
7472
|
+
}
|
|
7473
|
+
const displayName = (options.displayName ?? "").trim();
|
|
7474
|
+
if (displayName === "") usageError("--display-name must not be empty.");
|
|
7475
|
+
const request = {
|
|
7476
|
+
tag,
|
|
7477
|
+
displayName,
|
|
7478
|
+
...options.description !== void 0 && options.description.trim() !== "" ? { description: options.description } : {},
|
|
7479
|
+
...options.sortOrder !== void 0 ? { sortOrder: parseSortOrder(options.sortOrder) } : {}
|
|
7480
|
+
};
|
|
7481
|
+
const created = await createApiClient().index.createCuratedTag(request);
|
|
7482
|
+
if (isDryRun()) return;
|
|
7483
|
+
if (outputFormat === "human") {
|
|
7484
|
+
success(`Curated tag "${created.tag}" created.`);
|
|
7485
|
+
} else {
|
|
7486
|
+
format(created, { format: outputFormat });
|
|
7487
|
+
}
|
|
7488
|
+
} catch (error) {
|
|
7489
|
+
handleError(error);
|
|
7490
|
+
}
|
|
7491
|
+
});
|
|
7492
|
+
curated.command("update").description("Change the name, description or position of a curated tag (admin)").argument("<tag>", "The curated tag").option("--display-name <name>", "The name Explore shows for it").option("--description <text>", "What belongs under it; an empty value clears it").option("--sort-order <n>", "Position in the filter, lowest first").addHelpText("after", `
|
|
7493
|
+
Only what is given changes. The tag itself cannot be renamed: delete it and create the new one.
|
|
7494
|
+
|
|
7495
|
+
Examples:
|
|
7496
|
+
$ diafunc admin curated-tags update health --display-name "Health and medicine"
|
|
7497
|
+
$ diafunc admin curated-tags update health --description "" clears the description
|
|
7498
|
+
$ diafunc admin curated-tags update health --sort-order 3 --dry-run
|
|
7499
|
+
`).action(async (typed2, options, cmd) => {
|
|
7500
|
+
try {
|
|
7501
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
7502
|
+
const tag = curatedTagOf(typed2);
|
|
7503
|
+
if (options.displayName === void 0 && options.description === void 0 && options.sortOrder === void 0) {
|
|
7504
|
+
usageError("Nothing to change.", "Pass at least one of --display-name, --description, --sort-order.");
|
|
7505
|
+
}
|
|
7506
|
+
if (options.displayName !== void 0 && options.displayName.trim() === "") {
|
|
7507
|
+
usageError("--display-name must not be empty.");
|
|
7508
|
+
}
|
|
7509
|
+
const request = {
|
|
7510
|
+
...options.displayName !== void 0 ? { displayName: options.displayName.trim() } : {},
|
|
7511
|
+
...options.description !== void 0 ? { description: options.description } : {},
|
|
7512
|
+
...options.sortOrder !== void 0 ? { sortOrder: parseSortOrder(options.sortOrder) } : {}
|
|
7513
|
+
};
|
|
7514
|
+
const updated = await createApiClient().index.updateCuratedTag(tag, request);
|
|
7515
|
+
if (isDryRun()) return;
|
|
7516
|
+
if (outputFormat === "human") {
|
|
7517
|
+
success(`Curated tag "${tag}" updated.`);
|
|
7518
|
+
} else {
|
|
7519
|
+
format(updated, { format: outputFormat });
|
|
7520
|
+
}
|
|
7521
|
+
} catch (error) {
|
|
7522
|
+
handleError(error);
|
|
7523
|
+
}
|
|
7524
|
+
});
|
|
7525
|
+
curated.command("delete").description("Delete a curated tag (admin); projects that carry the tag keep it").argument("<tag>", "The curated tag").option("-y, --yes", "Skip confirmation prompt (for CI / scripted use)").addHelpText("after", `
|
|
7526
|
+
Examples:
|
|
7527
|
+
$ diafunc admin curated-tags delete health
|
|
7528
|
+
$ diafunc admin curated-tags delete health --yes --dry-run
|
|
7529
|
+
`).action(async (typed2, options, cmd) => {
|
|
7530
|
+
try {
|
|
7531
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
7532
|
+
const tag = curatedTagOf(typed2);
|
|
7533
|
+
if (!isDryRun()) {
|
|
7534
|
+
await confirmDestructive(`This removes "${tag}" from Explore's data-domain filter.`, { yes: options.yes, resourceId: tag });
|
|
7535
|
+
}
|
|
7536
|
+
await createApiClient().index.deleteCuratedTag(tag);
|
|
7537
|
+
if (isDryRun()) return;
|
|
7538
|
+
success(`Curated tag "${tag}" deleted.`, { format: outputFormat });
|
|
7539
|
+
} catch (error) {
|
|
7540
|
+
handleError(error);
|
|
7541
|
+
}
|
|
7542
|
+
});
|
|
7543
|
+
}
|
|
7544
|
+
|
|
7545
|
+
// src/commands/admin/index.ts
|
|
7546
|
+
function getOutputFormat16(cmd) {
|
|
6737
7547
|
const config = loadConfig();
|
|
6738
7548
|
const globalOpts = cmd.optsWithGlobals();
|
|
6739
7549
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -6743,7 +7553,7 @@ function registerAdminCommands(program) {
|
|
|
6743
7553
|
const users = admin.command("users").description("Manage users");
|
|
6744
7554
|
users.command("list").description("List all users (admin)").action(async (_options, cmd) => {
|
|
6745
7555
|
try {
|
|
6746
|
-
const outputFormat =
|
|
7556
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6747
7557
|
const api = createApiClient();
|
|
6748
7558
|
const userList = await api.admin.getUsers();
|
|
6749
7559
|
const summary = userList.map((u) => ({
|
|
@@ -6769,7 +7579,7 @@ function registerAdminCommands(program) {
|
|
|
6769
7579
|
});
|
|
6770
7580
|
users.command("get").description("Get current user details").action(async (_options, cmd) => {
|
|
6771
7581
|
try {
|
|
6772
|
-
const outputFormat =
|
|
7582
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6773
7583
|
const api = createApiClient();
|
|
6774
7584
|
const user = await api.admin.getMyUser();
|
|
6775
7585
|
format(user, { format: outputFormat });
|
|
@@ -6779,7 +7589,7 @@ function registerAdminCommands(program) {
|
|
|
6779
7589
|
});
|
|
6780
7590
|
admin.command("subscription").description("Show current subscription").action(async (_options, cmd) => {
|
|
6781
7591
|
try {
|
|
6782
|
-
const outputFormat =
|
|
7592
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6783
7593
|
const api = createApiClient();
|
|
6784
7594
|
const sub = await api.admin.getCurrentSubscription();
|
|
6785
7595
|
format(sub, { format: outputFormat });
|
|
@@ -6790,7 +7600,7 @@ function registerAdminCommands(program) {
|
|
|
6790
7600
|
const settings = admin.command("settings").description("Manage settings");
|
|
6791
7601
|
settings.command("get").description("Get current settings").action(async (_options, cmd) => {
|
|
6792
7602
|
try {
|
|
6793
|
-
const outputFormat =
|
|
7603
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6794
7604
|
const api = createApiClient();
|
|
6795
7605
|
const s = await api.admin.getSettings();
|
|
6796
7606
|
format(s, { format: outputFormat });
|
|
@@ -6810,7 +7620,7 @@ function registerAdminCommands(program) {
|
|
|
6810
7620
|
const platformSettings = admin.command("platform-settings").description("Manage platform-wide settings (admin only)");
|
|
6811
7621
|
platformSettings.command("list").description("Show every platform setting with its default and current override").action(async (_options, cmd) => {
|
|
6812
7622
|
try {
|
|
6813
|
-
const outputFormat =
|
|
7623
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6814
7624
|
const api = createApiClient();
|
|
6815
7625
|
const settingsList = await api.admin.listPlatformSettings();
|
|
6816
7626
|
format(settingsList, { format: outputFormat });
|
|
@@ -6897,9 +7707,10 @@ function registerAdminCommands(program) {
|
|
|
6897
7707
|
handleError(error);
|
|
6898
7708
|
}
|
|
6899
7709
|
});
|
|
7710
|
+
registerCuratedTagCommands(admin);
|
|
6900
7711
|
admin.command("permissions").description("Show your permissions on a project").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
6901
7712
|
try {
|
|
6902
|
-
const outputFormat =
|
|
7713
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6903
7714
|
const api = createApiClient();
|
|
6904
7715
|
const perm = await api.admin.getPermissions(projectId);
|
|
6905
7716
|
format({ projectId, permission: perm }, { format: outputFormat });
|
|
@@ -6912,7 +7723,7 @@ function registerAdminCommands(program) {
|
|
|
6912
7723
|
contract.command("get", { isDefault: true }).description("Show a team's contract").argument("<teamId>", "Team ID").action(async (teamId, _options, cmd) => {
|
|
6913
7724
|
try {
|
|
6914
7725
|
const api = createApiClient();
|
|
6915
|
-
format(await api.admin.getTeamContract(teamId), { format:
|
|
7726
|
+
format(await api.admin.getTeamContract(teamId), { format: getOutputFormat16(cmd) });
|
|
6916
7727
|
} catch (error) {
|
|
6917
7728
|
handleError(error);
|
|
6918
7729
|
}
|
|
@@ -6925,7 +7736,7 @@ function registerAdminCommands(program) {
|
|
|
6925
7736
|
{ yes: options.yes, resourceId: teamId }
|
|
6926
7737
|
);
|
|
6927
7738
|
const api = createApiClient();
|
|
6928
|
-
format(await api.admin.issueTeamContract(teamId, request), { format:
|
|
7739
|
+
format(await api.admin.issueTeamContract(teamId, request), { format: getOutputFormat16(cmd) });
|
|
6929
7740
|
} catch (error) {
|
|
6930
7741
|
handleError(error);
|
|
6931
7742
|
}
|
|
@@ -6933,14 +7744,14 @@ function registerAdminCommands(program) {
|
|
|
6933
7744
|
}
|
|
6934
7745
|
|
|
6935
7746
|
// src/commands/status/summary.ts
|
|
6936
|
-
import
|
|
7747
|
+
import chalk23 from "chalk";
|
|
6937
7748
|
|
|
6938
7749
|
// src/client/services/status.ts
|
|
6939
7750
|
function createStatusService() {
|
|
6940
7751
|
const config = loadConfig();
|
|
6941
7752
|
const endpoint = resolveEndpoint(config);
|
|
6942
|
-
async function fetchJson(
|
|
6943
|
-
const url = `${endpoint}/status/v1${
|
|
7753
|
+
async function fetchJson(path13) {
|
|
7754
|
+
const url = `${endpoint}/status/v1${path13}`;
|
|
6944
7755
|
const response = await fetch(url, {
|
|
6945
7756
|
headers: { "Accept": "application/json" }
|
|
6946
7757
|
});
|
|
@@ -6959,24 +7770,24 @@ function createStatusService() {
|
|
|
6959
7770
|
|
|
6960
7771
|
// src/commands/status/summary.ts
|
|
6961
7772
|
var STATE_COLORS = {
|
|
6962
|
-
UP:
|
|
6963
|
-
DEGRADED:
|
|
6964
|
-
DOWN:
|
|
6965
|
-
UNKNOWN:
|
|
7773
|
+
UP: chalk23.green,
|
|
7774
|
+
DEGRADED: chalk23.yellow,
|
|
7775
|
+
DOWN: chalk23.red,
|
|
7776
|
+
UNKNOWN: chalk23.gray
|
|
6966
7777
|
};
|
|
6967
7778
|
function stateColor(state) {
|
|
6968
|
-
return STATE_COLORS[state] ??
|
|
7779
|
+
return STATE_COLORS[state] ?? chalk23.gray;
|
|
6969
7780
|
}
|
|
6970
7781
|
function stateSymbol(state) {
|
|
6971
7782
|
switch (state) {
|
|
6972
7783
|
case "UP":
|
|
6973
|
-
return
|
|
7784
|
+
return chalk23.green("\u25CF");
|
|
6974
7785
|
case "DEGRADED":
|
|
6975
|
-
return
|
|
7786
|
+
return chalk23.yellow("\u25CF");
|
|
6976
7787
|
case "DOWN":
|
|
6977
|
-
return
|
|
7788
|
+
return chalk23.red("\u25CF");
|
|
6978
7789
|
default:
|
|
6979
|
-
return
|
|
7790
|
+
return chalk23.gray("\u25CB");
|
|
6980
7791
|
}
|
|
6981
7792
|
}
|
|
6982
7793
|
function registerSummaryCommand(parent) {
|
|
@@ -7001,20 +7812,20 @@ function registerSummaryCommand(parent) {
|
|
|
7001
7812
|
const label = stateColor(domain.state)(domain.state.padEnd(10));
|
|
7002
7813
|
console.log(` ${stateSymbol(domain.state)} ${label} ${domain.name}`);
|
|
7003
7814
|
if (domain.componentIds.length > 0) {
|
|
7004
|
-
console.log(` ${
|
|
7815
|
+
console.log(` ${chalk23.dim(domain.componentIds.join(", "))}`);
|
|
7005
7816
|
}
|
|
7006
7817
|
}
|
|
7007
7818
|
console.log();
|
|
7008
7819
|
if (summary.openIncidents > 0) {
|
|
7009
|
-
console.log(
|
|
7820
|
+
console.log(chalk23.yellow(` ${summary.openIncidents} active incident(s)`));
|
|
7010
7821
|
} else {
|
|
7011
|
-
console.log(
|
|
7822
|
+
console.log(chalk23.dim(" No active incidents"));
|
|
7012
7823
|
}
|
|
7013
|
-
console.log(
|
|
7824
|
+
console.log(chalk23.dim(
|
|
7014
7825
|
`
|
|
7015
7826
|
Platform v${version.platformVersion} \xB7 checked ${formatInstant(summary.timestamp)}`
|
|
7016
7827
|
));
|
|
7017
|
-
console.log(
|
|
7828
|
+
console.log(chalk23.dim(` Drill into one with 'diafunc status component <id>'.`));
|
|
7018
7829
|
console.log();
|
|
7019
7830
|
} catch (error) {
|
|
7020
7831
|
handleError(error);
|
|
@@ -7023,17 +7834,17 @@ function registerSummaryCommand(parent) {
|
|
|
7023
7834
|
}
|
|
7024
7835
|
|
|
7025
7836
|
// src/commands/status/component.ts
|
|
7026
|
-
import
|
|
7837
|
+
import chalk24 from "chalk";
|
|
7027
7838
|
function stateSymbol2(state) {
|
|
7028
7839
|
switch (state) {
|
|
7029
7840
|
case "UP":
|
|
7030
|
-
return
|
|
7841
|
+
return chalk24.green("\u25CF");
|
|
7031
7842
|
case "DEGRADED":
|
|
7032
|
-
return
|
|
7843
|
+
return chalk24.yellow("\u25CF");
|
|
7033
7844
|
case "DOWN":
|
|
7034
|
-
return
|
|
7845
|
+
return chalk24.red("\u25CF");
|
|
7035
7846
|
default:
|
|
7036
|
-
return
|
|
7847
|
+
return chalk24.gray("\u25CB");
|
|
7037
7848
|
}
|
|
7038
7849
|
}
|
|
7039
7850
|
function registerComponentCommand(parent) {
|
|
@@ -7058,7 +7869,7 @@ function registerComponentCommand(parent) {
|
|
|
7058
7869
|
return;
|
|
7059
7870
|
}
|
|
7060
7871
|
console.log();
|
|
7061
|
-
console.log(` ${stateSymbol2(match.state)} ${
|
|
7872
|
+
console.log(` ${stateSymbol2(match.state)} ${chalk24.bold(match.id)} ${match.version ? chalk24.dim("v" + match.version) : ""}`);
|
|
7062
7873
|
console.log(` State: ${renderState(match.state)}`);
|
|
7063
7874
|
if (match.lastCheckAt) {
|
|
7064
7875
|
console.log(` Last check: ${formatInstant(match.lastCheckAt)}`);
|
|
@@ -7067,7 +7878,7 @@ function registerComponentCommand(parent) {
|
|
|
7067
7878
|
console.log();
|
|
7068
7879
|
console.log(" Checks:");
|
|
7069
7880
|
for (const check of match.checks) {
|
|
7070
|
-
const cat = check.category ?
|
|
7881
|
+
const cat = check.category ? chalk24.dim(` (${check.category})`) : "";
|
|
7071
7882
|
console.log(` ${stateSymbol2(check.state)} ${check.name}${cat}`);
|
|
7072
7883
|
}
|
|
7073
7884
|
}
|
|
@@ -7079,12 +7890,12 @@ function registerComponentCommand(parent) {
|
|
|
7079
7890
|
}
|
|
7080
7891
|
|
|
7081
7892
|
// src/commands/status/incidents.ts
|
|
7082
|
-
import
|
|
7893
|
+
import chalk25 from "chalk";
|
|
7083
7894
|
var SEVERITY_COLORS = {
|
|
7084
|
-
ERROR:
|
|
7085
|
-
WARNING:
|
|
7086
|
-
INFO:
|
|
7087
|
-
MAINTENANCE:
|
|
7895
|
+
ERROR: chalk25.red,
|
|
7896
|
+
WARNING: chalk25.yellow,
|
|
7897
|
+
INFO: chalk25.blue,
|
|
7898
|
+
MAINTENANCE: chalk25.cyan
|
|
7088
7899
|
};
|
|
7089
7900
|
function registerIncidentsCommand(parent) {
|
|
7090
7901
|
parent.command("incidents").description("List recent incidents").option("-w, --window <window>", "Time window (e.g. 24h, 48h)", "24h").action(async (options, cmd) => {
|
|
@@ -7098,22 +7909,22 @@ function registerIncidentsCommand(parent) {
|
|
|
7098
7909
|
return;
|
|
7099
7910
|
}
|
|
7100
7911
|
if (incidents.length === 0) {
|
|
7101
|
-
console.log(
|
|
7912
|
+
console.log(chalk25.dim(`
|
|
7102
7913
|
No incidents in the last ${options.window}.
|
|
7103
7914
|
`));
|
|
7104
7915
|
return;
|
|
7105
7916
|
}
|
|
7106
7917
|
console.log();
|
|
7107
7918
|
for (const incident of incidents) {
|
|
7108
|
-
const color = SEVERITY_COLORS[incident.severity] ??
|
|
7919
|
+
const color = SEVERITY_COLORS[incident.severity] ?? chalk25.gray;
|
|
7109
7920
|
const severity = color(incident.severity.padEnd(8));
|
|
7110
7921
|
const time = incident.startedAt ? new Date(incident.startedAt).toLocaleString() : "";
|
|
7111
|
-
const resolved = incident.resolvedAt ?
|
|
7922
|
+
const resolved = incident.resolvedAt ? chalk25.green(" [resolved]") : chalk25.yellow(" [open]");
|
|
7112
7923
|
console.log(` ${severity} ${incident.summary}${resolved}`);
|
|
7113
|
-
console.log(
|
|
7924
|
+
console.log(chalk25.dim(` ${time}`));
|
|
7114
7925
|
for (const update of incident.updates) {
|
|
7115
7926
|
const updateTime = new Date(update.at).toLocaleTimeString();
|
|
7116
|
-
console.log(
|
|
7927
|
+
console.log(chalk25.dim(` ${updateTime} ${update.status} ${update.message}`));
|
|
7117
7928
|
}
|
|
7118
7929
|
console.log();
|
|
7119
7930
|
}
|
|
@@ -7138,12 +7949,12 @@ Examples:
|
|
|
7138
7949
|
}
|
|
7139
7950
|
|
|
7140
7951
|
// src/commands/analyze/index.ts
|
|
7141
|
-
import * as
|
|
7142
|
-
import * as
|
|
7952
|
+
import * as fs11 from "fs";
|
|
7953
|
+
import * as path9 from "path";
|
|
7143
7954
|
import { spawn as spawn2 } from "child_process";
|
|
7144
7955
|
|
|
7145
7956
|
// src/commands/analyze/watch-view.ts
|
|
7146
|
-
import
|
|
7957
|
+
import chalk26 from "chalk";
|
|
7147
7958
|
|
|
7148
7959
|
// src/client/types/analysis.ts
|
|
7149
7960
|
var RUN_PHASE_LABELS = {
|
|
@@ -7280,25 +8091,25 @@ function renderWatchBlock(input) {
|
|
|
7280
8091
|
const lines = [];
|
|
7281
8092
|
const step = stepCounter(run);
|
|
7282
8093
|
const headline = [
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
step ?
|
|
8094
|
+
chalk26.cyan(SPINNER),
|
|
8095
|
+
chalk26.bold(phaseLabel(run)),
|
|
8096
|
+
step ? chalk26.dim(step) : null
|
|
7286
8097
|
].filter(Boolean).join(" ");
|
|
7287
8098
|
lines.push(` ${headline}`);
|
|
7288
8099
|
const fraction = overallProgress(run);
|
|
7289
|
-
const elapsed =
|
|
8100
|
+
const elapsed = chalk26.dim(formatDurationPrecise(elapsedMs));
|
|
7290
8101
|
if (fraction === null) {
|
|
7291
|
-
lines.push(` ${
|
|
8102
|
+
lines.push(` ${chalk26.dim("working")} ${elapsed}`);
|
|
7292
8103
|
} else {
|
|
7293
8104
|
const ceiling = remainingCeiling(run, budgetHours);
|
|
7294
8105
|
lines.push(
|
|
7295
|
-
` ${bar(fraction)} ${percent(fraction)} ${elapsed}` + (ceiling !== null ?
|
|
8106
|
+
` ${bar(fraction)} ${percent(fraction)} ${elapsed}` + (ceiling !== null ? chalk26.dim(` \xB7 at most ${formatDurationPrecise(ceiling)} remaining`) : "")
|
|
7296
8107
|
);
|
|
7297
8108
|
}
|
|
7298
8109
|
const detail2 = caption ?? phaseDetail(run);
|
|
7299
|
-
if (detail2) lines.push(` ${
|
|
8110
|
+
if (detail2) lines.push(` ${chalk26.dim(detail2)}`);
|
|
7300
8111
|
if (run.retryAttempts && run.retryAttempts > 0) {
|
|
7301
|
-
lines.push(` ${
|
|
8112
|
+
lines.push(` ${chalk26.yellow("!")} ${chalk26.dim(
|
|
7302
8113
|
`restarted ${run.retryAttempts === 1 ? "once" : `${run.retryAttempts} times`} after an interruption; progress restarts from the beginning`
|
|
7303
8114
|
)}`);
|
|
7304
8115
|
}
|
|
@@ -7306,7 +8117,7 @@ function renderWatchBlock(input) {
|
|
|
7306
8117
|
}
|
|
7307
8118
|
|
|
7308
8119
|
// src/commands/analyze/wizard.ts
|
|
7309
|
-
import
|
|
8120
|
+
import chalk27 from "chalk";
|
|
7310
8121
|
|
|
7311
8122
|
// src/commands/analyze/columns.ts
|
|
7312
8123
|
var MAX_COLUMNS_LISTED = 30;
|
|
@@ -7492,7 +8303,7 @@ function depthOf(hours, budget) {
|
|
|
7492
8303
|
const b = budget?.trim();
|
|
7493
8304
|
return h && b ? { hours: h, budget: b } : null;
|
|
7494
8305
|
}
|
|
7495
|
-
async function promptCreationFields(prompter, supplied, fallbackName) {
|
|
8306
|
+
async function promptCreationFields(prompter, supplied, fallbackName, licences) {
|
|
7496
8307
|
const name = supplied.name ?? await prompter.input({
|
|
7497
8308
|
message: "Analysis name",
|
|
7498
8309
|
default: fallbackName,
|
|
@@ -7509,7 +8320,31 @@ async function promptCreationFields(prompter, supplied, fallbackName) {
|
|
|
7509
8320
|
{ name: "Public", value: "PUBLIC", description: "Anyone with the link can read the notebook." }
|
|
7510
8321
|
]
|
|
7511
8322
|
});
|
|
7512
|
-
|
|
8323
|
+
const answers = { name: name.trim(), description: description.trim() || null, visibility };
|
|
8324
|
+
const licenceId = supplied.licenceId ?? (visibility === "PUBLIC" && licences ? await promptLicence(prompter, await licences()) : void 0);
|
|
8325
|
+
if (licenceId) answers.licenceId = licenceId;
|
|
8326
|
+
return answers;
|
|
8327
|
+
}
|
|
8328
|
+
var ALL_LICENCES = ":all";
|
|
8329
|
+
async function promptLicence(prompter, catalogue) {
|
|
8330
|
+
const selectable = catalogue.filter((l) => l.state === "ACTIVE");
|
|
8331
|
+
if (selectable.length === 0) return void 0;
|
|
8332
|
+
const choice = (l) => ({ name: `${l.name} (${l.licenceId})`, value: l.licenceId, description: l.summary ?? void 0 });
|
|
8333
|
+
const recommended = selectable.filter((l) => l.recommended);
|
|
8334
|
+
const others = selectable.filter((l) => !l.recommended);
|
|
8335
|
+
if (recommended.length === 0 || others.length === 0) {
|
|
8336
|
+
return prompter.select({ message: "Licence", default: selectable[0].licenceId, choices: selectable.map(choice) });
|
|
8337
|
+
}
|
|
8338
|
+
const picked = await prompter.select({
|
|
8339
|
+
message: "Licence",
|
|
8340
|
+
default: recommended[0].licenceId,
|
|
8341
|
+
choices: [
|
|
8342
|
+
...recommended.map(choice),
|
|
8343
|
+
{ name: "Another licence\u2026", value: ALL_LICENCES, description: `${others.length} more in the catalogue.` }
|
|
8344
|
+
]
|
|
8345
|
+
});
|
|
8346
|
+
if (picked !== ALL_LICENCES) return picked;
|
|
8347
|
+
return prompter.select({ message: "Licence (all)", default: others[0].licenceId, choices: selectable.map(choice) });
|
|
7513
8348
|
}
|
|
7514
8349
|
function matchDepthPreset(hours, budget) {
|
|
7515
8350
|
if (!hours || !budget) return null;
|
|
@@ -7546,7 +8381,7 @@ async function promptRunFields(prompter, options) {
|
|
|
7546
8381
|
});
|
|
7547
8382
|
if (preset) {
|
|
7548
8383
|
supplied = {
|
|
7549
|
-
targets: preset.
|
|
8384
|
+
targets: preset.targets.length > 0 ? preset.targets : void 0,
|
|
7550
8385
|
questions: preset.questions.length > 0 ? preset.questions : void 0,
|
|
7551
8386
|
segment: preset.segmentKey ?? void 0,
|
|
7552
8387
|
hours: preset.time || void 0,
|
|
@@ -7561,7 +8396,7 @@ async function promptRunFields(prompter, options) {
|
|
|
7561
8396
|
targets = await prompter.checkbox({
|
|
7562
8397
|
message: "Target columns: what should the analysis predict?",
|
|
7563
8398
|
choices: named.map((c) => ({
|
|
7564
|
-
name: c.valueType ? `${c.name} ${
|
|
8399
|
+
name: c.valueType ? `${c.name} ${chalk27.dim(`(${c.valueType})`)}` : c.name,
|
|
7565
8400
|
value: c.name,
|
|
7566
8401
|
checked: preselected.has(c.name)
|
|
7567
8402
|
})),
|
|
@@ -7590,7 +8425,7 @@ async function promptRunFields(prompter, options) {
|
|
|
7590
8425
|
choices: [
|
|
7591
8426
|
{ name: "No segmentation", value: null },
|
|
7592
8427
|
...remaining.map((c) => ({
|
|
7593
|
-
name: c.valueType ? `${c.name} ${
|
|
8428
|
+
name: c.valueType ? `${c.name} ${chalk27.dim(`(${c.valueType})`)}` : c.name,
|
|
7594
8429
|
value: c.name
|
|
7595
8430
|
}))
|
|
7596
8431
|
]
|
|
@@ -7661,16 +8496,17 @@ function describePreset(preset) {
|
|
|
7661
8496
|
const parts = [];
|
|
7662
8497
|
if (preset.time) parts.push(`${preset.time}h`);
|
|
7663
8498
|
if (preset.budget) parts.push(`${preset.budget} credits`);
|
|
7664
|
-
if (preset.
|
|
8499
|
+
if (preset.targets.length > 0) parts.push(`targets: ${preset.targets.join(", ")}`);
|
|
7665
8500
|
if (preset.segmentKey) parts.push(`segmented by ${preset.segmentKey}`);
|
|
7666
8501
|
return parts.join(" \xB7 ");
|
|
7667
8502
|
}
|
|
7668
8503
|
function summaryLines(creation, run) {
|
|
7669
8504
|
const lines = [
|
|
7670
8505
|
`Name: ${creation.name}`,
|
|
7671
|
-
`Visibility: ${creation.visibility === "PUBLIC" ? "Public" : "Private"}
|
|
7672
|
-
`Targets: ${run.targets.join(", ")}`
|
|
8506
|
+
`Visibility: ${creation.visibility === "PUBLIC" ? "Public" : "Private"}`
|
|
7673
8507
|
];
|
|
8508
|
+
if (creation.licenceId) lines.push(`Licence: ${creation.licenceId}`);
|
|
8509
|
+
lines.push(`Targets: ${run.targets.join(", ")}`);
|
|
7674
8510
|
if (run.segment) lines.push(`Segment: ${run.segment}`);
|
|
7675
8511
|
if (run.questions && run.questions.length > 0) {
|
|
7676
8512
|
lines.push(`Questions: ${run.questions.length}`);
|
|
@@ -7773,7 +8609,7 @@ function whyNoPrompt(outputFormat, noInteractive) {
|
|
|
7773
8609
|
}
|
|
7774
8610
|
|
|
7775
8611
|
// src/commands/analyze/data-import.ts
|
|
7776
|
-
import
|
|
8612
|
+
import chalk28 from "chalk";
|
|
7777
8613
|
|
|
7778
8614
|
// src/commands/analyze/details.ts
|
|
7779
8615
|
function analysisDetails(analysis, endpoint) {
|
|
@@ -7782,6 +8618,7 @@ function analysisDetails(analysis, endpoint) {
|
|
|
7782
8618
|
name: analysis.name,
|
|
7783
8619
|
description: analysis.description,
|
|
7784
8620
|
visibility: sentenceCase(analysis.visibility),
|
|
8621
|
+
licence: licenceText(analysis),
|
|
7785
8622
|
introduction: analysis.introduction,
|
|
7786
8623
|
data: dataShape(analysis.rowCount, analysis.columnCount),
|
|
7787
8624
|
dataImport: analysis.dataImport?.message ?? null,
|
|
@@ -7799,7 +8636,7 @@ function analysisDetails(analysis, endpoint) {
|
|
|
7799
8636
|
latestRunState: isImporting(analysis.dataImport) ? importingLabel(analysis.dataImport) : analysis.latestRunState ? sentenceCase(analysis.latestRunState) : null,
|
|
7800
8637
|
latestRunId: analysis.latestRunId,
|
|
7801
8638
|
quality: qualityText(analysis),
|
|
7802
|
-
|
|
8639
|
+
targetResults: targetResultsText(analysis),
|
|
7803
8640
|
resultRunId: analysis.resultRunId,
|
|
7804
8641
|
creditsUsed: creditsText(analysis.creditsUsed),
|
|
7805
8642
|
notebook: analysis.labUrl ? `${endpoint}${analysis.labUrl}` : null,
|
|
@@ -7813,13 +8650,14 @@ function analysisDetails(analysis, endpoint) {
|
|
|
7813
8650
|
{ key: "name", header: "Name" },
|
|
7814
8651
|
{ key: "description", header: "Description" },
|
|
7815
8652
|
{ key: "visibility", header: "Visibility" },
|
|
8653
|
+
{ key: "licence", header: "Licence" },
|
|
7816
8654
|
{ key: "introduction", header: "Introduction" },
|
|
7817
8655
|
{ key: "data", header: "Data" },
|
|
7818
8656
|
{ key: "dataImport", header: "Data import" },
|
|
7819
8657
|
{ key: "targets", header: "Targets" },
|
|
7820
8658
|
{ key: "targetKinds", header: "Target kinds" },
|
|
7821
|
-
{ key: "inputExclusions", header: "
|
|
7822
|
-
{ key: "confirmedInputs", header: "Known before the
|
|
8659
|
+
{ key: "inputExclusions", header: "Columns left out of the fit" },
|
|
8660
|
+
{ key: "confirmedInputs", header: "Known before the target" },
|
|
7823
8661
|
{ key: "questions", header: "Questions" },
|
|
7824
8662
|
{ key: "segment", header: "Segment" },
|
|
7825
8663
|
{ key: "hours", header: "Time limit" },
|
|
@@ -7829,7 +8667,7 @@ function analysisDetails(analysis, endpoint) {
|
|
|
7829
8667
|
{ key: "latestRunState", header: "Latest run", kind: "state" },
|
|
7830
8668
|
{ key: "latestRunId", header: "Latest run ID", kind: "id" },
|
|
7831
8669
|
{ key: "quality", header: "Quality" },
|
|
7832
|
-
{ key: "
|
|
8670
|
+
{ key: "targetResults", header: "Target results" },
|
|
7833
8671
|
{ key: "resultRunId", header: "Result from run", kind: "id" },
|
|
7834
8672
|
{ key: "creditsUsed", header: "Credits used" },
|
|
7835
8673
|
{ key: "notebook", header: "Notebook" },
|
|
@@ -7840,6 +8678,10 @@ function analysisDetails(analysis, endpoint) {
|
|
|
7840
8678
|
];
|
|
7841
8679
|
return { data, columns };
|
|
7842
8680
|
}
|
|
8681
|
+
function licenceText(analysis) {
|
|
8682
|
+
if (analysis.licenceId) return analysis.licenceId;
|
|
8683
|
+
return analysis.visibility === "PUBLIC" ? "none chosen" : null;
|
|
8684
|
+
}
|
|
7843
8685
|
function sentenceCase(token) {
|
|
7844
8686
|
const words = token.toLowerCase().replace(/_/g, " ");
|
|
7845
8687
|
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
@@ -7868,14 +8710,14 @@ function qualityText(analysis) {
|
|
|
7868
8710
|
if (analysis.resultRunQuality != null) return `${qualityPercent(analysis.resultRunQuality)} on the training rows`;
|
|
7869
8711
|
return null;
|
|
7870
8712
|
}
|
|
7871
|
-
function
|
|
7872
|
-
const
|
|
7873
|
-
if (
|
|
7874
|
-
const lines =
|
|
7875
|
-
const name =
|
|
7876
|
-
return
|
|
8713
|
+
function targetResultsText(analysis) {
|
|
8714
|
+
const results = analysis.targetResults ?? [];
|
|
8715
|
+
if (results.length === 0) return null;
|
|
8716
|
+
const lines = results.map((r) => {
|
|
8717
|
+
const name = r.title ?? r.target ?? "target";
|
|
8718
|
+
return r.quality != null ? `${name}: ${qualityPercent(r.quality)}` : name;
|
|
7877
8719
|
});
|
|
7878
|
-
const more = (analysis.
|
|
8720
|
+
const more = (analysis.targetResultCount ?? results.length) - results.length;
|
|
7879
8721
|
if (more > 0) lines.push(`and ${formatNumber(more)} more`);
|
|
7880
8722
|
return lines.join("\n");
|
|
7881
8723
|
}
|
|
@@ -7897,19 +8739,19 @@ function constraintsText(analysis) {
|
|
|
7897
8739
|
var IMPORT_POLL_INTERVAL_MS = 2e3;
|
|
7898
8740
|
function renderImportBlock(dataImport, elapsedMs) {
|
|
7899
8741
|
const title = dataImport.state === "STOPPING" ? "Stopping the data import" : "Importing data";
|
|
7900
|
-
const lines = [` ${
|
|
7901
|
-
const elapsed =
|
|
8742
|
+
const lines = [` ${chalk28.cyan(SPINNER)} ${chalk28.bold(title)}`];
|
|
8743
|
+
const elapsed = chalk28.dim(formatDurationPrecise(elapsedMs));
|
|
7902
8744
|
if (dataImport.state === "IMPORTING" && dataImport.progress !== null && dataImport.progress !== void 0) {
|
|
7903
8745
|
lines.push(` ${bar(dataImport.progress)} ${percent(dataImport.progress)} ${elapsed}`);
|
|
7904
8746
|
} else {
|
|
7905
|
-
lines.push(` ${
|
|
8747
|
+
lines.push(` ${chalk28.dim(dataImport.message)} ${elapsed}`);
|
|
7906
8748
|
}
|
|
7907
8749
|
return lines;
|
|
7908
8750
|
}
|
|
7909
8751
|
function sleep3(ms) {
|
|
7910
8752
|
let timer;
|
|
7911
|
-
const done = new Promise((
|
|
7912
|
-
timer = setTimeout(() =>
|
|
8753
|
+
const done = new Promise((resolve2) => {
|
|
8754
|
+
timer = setTimeout(() => resolve2("elapsed"), ms);
|
|
7913
8755
|
});
|
|
7914
8756
|
return { done, cancel: () => clearTimeout(timer) };
|
|
7915
8757
|
}
|
|
@@ -7921,8 +8763,8 @@ async function followImport(ctx, first) {
|
|
|
7921
8763
|
const status = new Status();
|
|
7922
8764
|
let interrupt = () => {
|
|
7923
8765
|
};
|
|
7924
|
-
const interrupted = new Promise((
|
|
7925
|
-
interrupt = () =>
|
|
8766
|
+
const interrupted = new Promise((resolve2) => {
|
|
8767
|
+
interrupt = () => resolve2("interrupted");
|
|
7926
8768
|
});
|
|
7927
8769
|
process.once("SIGINT", interrupt);
|
|
7928
8770
|
if (ctx.live) {
|
|
@@ -7934,10 +8776,10 @@ async function followImport(ctx, first) {
|
|
|
7934
8776
|
try {
|
|
7935
8777
|
for (; ; ) {
|
|
7936
8778
|
if (ctx.live) status.set(renderImportBlock(current, Date.now() - since));
|
|
7937
|
-
const
|
|
7938
|
-
const woke = await Promise.race([
|
|
8779
|
+
const pause2 = sleep3(IMPORT_POLL_INTERVAL_MS);
|
|
8780
|
+
const woke = await Promise.race([pause2.done, interrupted]);
|
|
7939
8781
|
if (woke === "interrupted") {
|
|
7940
|
-
|
|
8782
|
+
pause2.cancel();
|
|
7941
8783
|
status.stop();
|
|
7942
8784
|
warn("Stopped waiting. The import keeps running on the platform.");
|
|
7943
8785
|
hint(`See how far it is with 'diafunc analyze get ${analysisId}'.`);
|
|
@@ -8070,8 +8912,8 @@ async function queueRun(api, analysisId) {
|
|
|
8070
8912
|
}
|
|
8071
8913
|
|
|
8072
8914
|
// src/commands/analyze/sources.ts
|
|
8073
|
-
import * as
|
|
8074
|
-
import * as
|
|
8915
|
+
import * as fs10 from "fs";
|
|
8916
|
+
import * as path8 from "path";
|
|
8075
8917
|
var CAUTIONS = /* @__PURE__ */ new Set([
|
|
8076
8918
|
"UNEVEN_COLUMNS",
|
|
8077
8919
|
"TYPE_CONFLICT",
|
|
@@ -8092,7 +8934,7 @@ function recipeWithChoices(proposal, choices) {
|
|
|
8092
8934
|
return { parts: proposal.parts, originColumn, dropDuplicates, lookups: proposal.lookups ?? [] };
|
|
8093
8935
|
}
|
|
8094
8936
|
function labelOf(file) {
|
|
8095
|
-
return
|
|
8937
|
+
return path8.basename(file, path8.extname(file)).trim().toLowerCase();
|
|
8096
8938
|
}
|
|
8097
8939
|
function otherRowsLabel(proposal) {
|
|
8098
8940
|
const alternative = (proposal.lookups ?? []).find((lookup) => lookup.alternative)?.alternative;
|
|
@@ -8112,7 +8954,7 @@ function recipeWithRowsOf(proposal, rowsOf) {
|
|
|
8112
8954
|
function sourcesAsUploaded(uploaded, asUploaded) {
|
|
8113
8955
|
const chosen = [];
|
|
8114
8956
|
for (const name of asUploaded) {
|
|
8115
|
-
const wanted =
|
|
8957
|
+
const wanted = path8.basename(name).trim().toLowerCase();
|
|
8116
8958
|
const matches = uploaded.filter((source) => {
|
|
8117
8959
|
const fileName = source.fileName.trim().toLowerCase();
|
|
8118
8960
|
return fileName === wanted || labelOf(fileName) === labelOf(wanted);
|
|
@@ -8165,12 +9007,12 @@ function planLines(plan) {
|
|
|
8165
9007
|
}
|
|
8166
9008
|
function multipart(file) {
|
|
8167
9009
|
const formData = new FormData();
|
|
8168
|
-
formData.append("content", new Blob([
|
|
9010
|
+
formData.append("content", new Blob([fs10.readFileSync(file)]), path8.basename(file));
|
|
8169
9011
|
return formData;
|
|
8170
9012
|
}
|
|
8171
9013
|
async function uploadSeveral(api, analysisId, files, choices, human) {
|
|
8172
9014
|
for (const file of files) {
|
|
8173
|
-
if (!
|
|
9015
|
+
if (!fs10.existsSync(file)) {
|
|
8174
9016
|
throw new CliError(`File not found: ${file}`, { exitCode: EXIT_USAGE });
|
|
8175
9017
|
}
|
|
8176
9018
|
}
|
|
@@ -8179,7 +9021,7 @@ async function uploadSeveral(api, analysisId, files, choices, human) {
|
|
|
8179
9021
|
}
|
|
8180
9022
|
const uploaded = [];
|
|
8181
9023
|
for (const file of files) {
|
|
8182
|
-
uploaded.push(await withStatus(`Uploading ${
|
|
9024
|
+
uploaded.push(await withStatus(`Uploading ${path8.basename(file)}`, () => api.analysis.addSource(analysisId, multipart(file))));
|
|
8183
9025
|
}
|
|
8184
9026
|
for (const source of sourcesAsUploaded(uploaded, choices.asUploaded ?? [])) {
|
|
8185
9027
|
await api.analysis.updateSource(analysisId, source.sourceId, { asUploaded: true });
|
|
@@ -8229,7 +9071,7 @@ function openUrl(url) {
|
|
|
8229
9071
|
const args = process.platform === "win32" ? ["/c", "start", '""', url] : [url];
|
|
8230
9072
|
spawn2(cmd, args, { detached: true, stdio: "ignore" }).unref();
|
|
8231
9073
|
}
|
|
8232
|
-
function
|
|
9074
|
+
function getOutputFormat17(cmd) {
|
|
8233
9075
|
const config = loadConfig();
|
|
8234
9076
|
const globalOpts = cmd.optsWithGlobals();
|
|
8235
9077
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -8238,7 +9080,7 @@ function noInteractiveFlag(cmd) {
|
|
|
8238
9080
|
return cmd.optsWithGlobals().interactive === false;
|
|
8239
9081
|
}
|
|
8240
9082
|
function importContext(api, analysisId, cmd, machineReport) {
|
|
8241
|
-
const outputFormat =
|
|
9083
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8242
9084
|
const noInteractive = noInteractiveFlag(cmd);
|
|
8243
9085
|
return {
|
|
8244
9086
|
api,
|
|
@@ -8290,10 +9132,10 @@ function budgetHoursOf(hours) {
|
|
|
8290
9132
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
|
8291
9133
|
}
|
|
8292
9134
|
function multipartFromFile(file) {
|
|
8293
|
-
const buffer =
|
|
9135
|
+
const buffer = fs11.readFileSync(file);
|
|
8294
9136
|
const blob = new Blob([buffer]);
|
|
8295
9137
|
const formData = new FormData();
|
|
8296
|
-
formData.append("content", blob,
|
|
9138
|
+
formData.append("content", blob, path9.basename(file));
|
|
8297
9139
|
return formData;
|
|
8298
9140
|
}
|
|
8299
9141
|
function reportCommandError(error) {
|
|
@@ -8302,13 +9144,13 @@ function reportCommandError(error) {
|
|
|
8302
9144
|
}
|
|
8303
9145
|
async function runAnalysis(files, options, cmd) {
|
|
8304
9146
|
for (const candidate of files) {
|
|
8305
|
-
if (!
|
|
9147
|
+
if (!fs11.existsSync(candidate)) {
|
|
8306
9148
|
failure(`File not found: ${candidate}`);
|
|
8307
9149
|
process.exit(EXIT_FAILURE);
|
|
8308
9150
|
}
|
|
8309
9151
|
}
|
|
8310
9152
|
const file = files[0];
|
|
8311
|
-
const outputFormat =
|
|
9153
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8312
9154
|
const noInteractive = noInteractiveFlag(cmd);
|
|
8313
9155
|
const interactive = canPrompt(outputFormat, noInteractive);
|
|
8314
9156
|
const api = createApiClient();
|
|
@@ -8321,7 +9163,7 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8321
9163
|
process.exit(EXIT_FAILURE);
|
|
8322
9164
|
}
|
|
8323
9165
|
const p = opt.preset;
|
|
8324
|
-
if (options.targets === void 0 && p.
|
|
9166
|
+
if (options.targets === void 0 && p.targets.length > 0) presetTargets = p.targets;
|
|
8325
9167
|
if (options.question === void 0 && p.questions.length > 0) options.question = [...p.questions];
|
|
8326
9168
|
if (options.segment === void 0 && p.segmentKey) options.segment = p.segmentKey;
|
|
8327
9169
|
if (options.hours === void 0 && p.time?.trim()) options.hours = p.time;
|
|
@@ -8332,19 +9174,21 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8332
9174
|
if (!interactive && !targetsGiven) {
|
|
8333
9175
|
usageError(
|
|
8334
9176
|
`Target columns are required, and ${whyNoPrompt(outputFormat, noInteractive)}.`,
|
|
8335
|
-
`Pass --targets <columns> or --preset <id>. The names are the column headers of ${files.length > 1 ? "the files" :
|
|
9177
|
+
`Pass --targets <columns> or --preset <id>. The names are the column headers of ${files.length > 1 ? "the files" : path9.basename(file)}.`
|
|
8336
9178
|
);
|
|
8337
9179
|
}
|
|
8338
9180
|
const prompter = createInquirerPrompter();
|
|
8339
|
-
const fallbackName =
|
|
9181
|
+
const fallbackName = path9.basename(file, path9.extname(file));
|
|
8340
9182
|
const creation = interactive ? await promptCreationFields(prompter, {
|
|
8341
9183
|
name: options.name,
|
|
8342
9184
|
description: options.description,
|
|
8343
|
-
visibility: options.visibility === void 0 ? void 0 : parseVisibility(options.visibility)
|
|
8344
|
-
|
|
9185
|
+
visibility: options.visibility === void 0 ? void 0 : parseVisibility(options.visibility),
|
|
9186
|
+
licenceId: options.licence
|
|
9187
|
+
}, fallbackName, () => api.admin.listLicences()) : {
|
|
8345
9188
|
name: options.name ?? fallbackName,
|
|
8346
9189
|
description: options.description?.trim() || null,
|
|
8347
|
-
visibility: options.visibility === void 0 ? "PRIVATE" : parseVisibility(options.visibility)
|
|
9190
|
+
visibility: options.visibility === void 0 ? "PRIVATE" : parseVisibility(options.visibility),
|
|
9191
|
+
licenceId: options.licence
|
|
8348
9192
|
};
|
|
8349
9193
|
const request = {
|
|
8350
9194
|
name: creation.name,
|
|
@@ -8358,9 +9202,12 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8358
9202
|
questions: questionsOf(options.question),
|
|
8359
9203
|
segment: null
|
|
8360
9204
|
};
|
|
8361
|
-
const created = await withStatus(`Creating analysis "${creation.name}"`, () => api.analysis.create(
|
|
9205
|
+
const created = await withStatus(`Creating analysis "${creation.name}"`, () => api.analysis.create({
|
|
9206
|
+
...request,
|
|
9207
|
+
...creation.licenceId ? { licenceId: creation.licenceId } : {}
|
|
9208
|
+
}));
|
|
8362
9209
|
if (isDryRun()) {
|
|
8363
|
-
hint(`Dry run: nothing was created. A real run would upload ${
|
|
9210
|
+
hint(`Dry run: nothing was created. A real run would upload ${path9.basename(file)}, queue the analysis and follow it.`);
|
|
8364
9211
|
return;
|
|
8365
9212
|
}
|
|
8366
9213
|
detail(`analysisId: ${created.analysisId}`);
|
|
@@ -8394,7 +9241,7 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8394
9241
|
questions: options.question === void 0 ? void 0 : questionsOf(options.question),
|
|
8395
9242
|
hours: options.hours,
|
|
8396
9243
|
budget: options.budget
|
|
8397
|
-
}, columns);
|
|
9244
|
+
}, columns, creation.licenceId);
|
|
8398
9245
|
if (configuredHours === null) return;
|
|
8399
9246
|
runHours = configuredHours;
|
|
8400
9247
|
} else {
|
|
@@ -8411,9 +9258,9 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8411
9258
|
}
|
|
8412
9259
|
function namedColumns(analysisId, columns, interactive, given) {
|
|
8413
9260
|
const names = columns.map((c) => c.name).filter((name) => name && name.length > 0);
|
|
8414
|
-
const read = (
|
|
9261
|
+
const read = (resolve2) => {
|
|
8415
9262
|
try {
|
|
8416
|
-
return
|
|
9263
|
+
return resolve2();
|
|
8417
9264
|
} catch (error) {
|
|
8418
9265
|
if (!(error instanceof CliError)) throw error;
|
|
8419
9266
|
if (!interactive) {
|
|
@@ -8433,7 +9280,7 @@ function namedColumns(analysisId, columns, interactive, given) {
|
|
|
8433
9280
|
const segment = given.segment === void 0 || given.segment === "" ? void 0 : read(() => resolveColumnArgument(given.segment, names, analysisId));
|
|
8434
9281
|
return { targets, segment };
|
|
8435
9282
|
}
|
|
8436
|
-
async function configureInteractively(api, prompter, analysisId, recipe, supplied, knownColumns) {
|
|
9283
|
+
async function configureInteractively(api, prompter, analysisId, recipe, supplied, knownColumns, licenceId) {
|
|
8437
9284
|
const columns = knownColumns ?? await readColumns(api, analysisId);
|
|
8438
9285
|
const presets = await readPresets(api);
|
|
8439
9286
|
const depthAsked = supplied.hours === void 0 || supplied.budget === void 0;
|
|
@@ -8454,7 +9301,8 @@ async function configureInteractively(api, prompter, analysisId, recipe, supplie
|
|
|
8454
9301
|
const identity = {
|
|
8455
9302
|
name: recipe.name,
|
|
8456
9303
|
description: recipe.description ?? null,
|
|
8457
|
-
visibility: recipe.visibility ?? "PRIVATE"
|
|
9304
|
+
visibility: recipe.visibility ?? "PRIVATE",
|
|
9305
|
+
...licenceId ? { licenceId } : {}
|
|
8458
9306
|
};
|
|
8459
9307
|
const depth = depthOf(saved?.hours, saved?.budget) ?? { hours: answers.hours, budget: answers.budget };
|
|
8460
9308
|
for (const line of summaryLines(identity, { ...answers, ...depth })) detail(line);
|
|
@@ -8477,11 +9325,12 @@ async function readDepthDefault(api, stored) {
|
|
|
8477
9325
|
}
|
|
8478
9326
|
async function readColumns(api, analysisId) {
|
|
8479
9327
|
for (let attempt = 0; attempt < COLUMN_READ_ATTEMPTS; attempt++) {
|
|
8480
|
-
if (attempt > 0) await new Promise((
|
|
9328
|
+
if (attempt > 0) await new Promise((resolve2) => setTimeout(resolve2, COLUMN_READ_INTERVAL_MS));
|
|
8481
9329
|
try {
|
|
8482
9330
|
const columns = await api.analysis.getColumns(analysisId);
|
|
8483
9331
|
if (columns.length > 0) return columns;
|
|
8484
|
-
} catch {
|
|
9332
|
+
} catch (error) {
|
|
9333
|
+
if (isAuthenticationFailure(error)) throw error;
|
|
8485
9334
|
}
|
|
8486
9335
|
}
|
|
8487
9336
|
warn("Could not read the column names from the uploaded file.");
|
|
@@ -8496,7 +9345,7 @@ async function readPresets(api) {
|
|
|
8496
9345
|
}
|
|
8497
9346
|
async function monitorRun(api, analysisId, runId, budgetHours, cmd) {
|
|
8498
9347
|
const config = loadConfig();
|
|
8499
|
-
const outputFormat =
|
|
9348
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8500
9349
|
const human = outputFormat === "human";
|
|
8501
9350
|
const status = new Status();
|
|
8502
9351
|
const seenOutputs = /* @__PURE__ */ new Set();
|
|
@@ -8506,13 +9355,14 @@ async function monitorRun(api, analysisId, runId, budgetHours, cmd) {
|
|
|
8506
9355
|
if (human) status.start();
|
|
8507
9356
|
try {
|
|
8508
9357
|
for (; ; ) {
|
|
8509
|
-
await new Promise((
|
|
9358
|
+
await new Promise((resolve2) => setTimeout(resolve2, POLL_INTERVAL_MS));
|
|
8510
9359
|
let run = null;
|
|
8511
9360
|
let absent = false;
|
|
8512
9361
|
try {
|
|
8513
9362
|
run = (await api.analysis.getRun(runId)).run;
|
|
8514
9363
|
absent = run === null;
|
|
8515
9364
|
} catch (error) {
|
|
9365
|
+
if (isAuthenticationFailure(error)) throw error;
|
|
8516
9366
|
absent = error instanceof ApiError && error.status === 404;
|
|
8517
9367
|
}
|
|
8518
9368
|
if (!run) {
|
|
@@ -8540,7 +9390,8 @@ async function monitorRun(api, analysisId, runId, budgetHours, cmd) {
|
|
|
8540
9390
|
}
|
|
8541
9391
|
}
|
|
8542
9392
|
}
|
|
8543
|
-
} catch {
|
|
9393
|
+
} catch (error) {
|
|
9394
|
+
if (isAuthenticationFailure(error)) throw error;
|
|
8544
9395
|
}
|
|
8545
9396
|
if (isTerminalState(run.state)) {
|
|
8546
9397
|
status.stop();
|
|
@@ -8618,7 +9469,7 @@ async function printNotebookLink(api, config, analysisId) {
|
|
|
8618
9469
|
}
|
|
8619
9470
|
}
|
|
8620
9471
|
async function listAnalyses(limit, cmd) {
|
|
8621
|
-
const outputFormat =
|
|
9472
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8622
9473
|
const api = createApiClient();
|
|
8623
9474
|
const analyses = await api.analysis.getRecent(limit);
|
|
8624
9475
|
format(analyses.map((a) => ({
|
|
@@ -8648,7 +9499,7 @@ async function listAnalyses(limit, cmd) {
|
|
|
8648
9499
|
});
|
|
8649
9500
|
}
|
|
8650
9501
|
async function getAnalysisDetails(analysisId, options, cmd) {
|
|
8651
|
-
const outputFormat =
|
|
9502
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8652
9503
|
const api = createApiClient();
|
|
8653
9504
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
8654
9505
|
if (!result.analysis) {
|
|
@@ -8716,7 +9567,7 @@ async function rerunAnalysis(analysisId, cmd) {
|
|
|
8716
9567
|
const analysis = found.analysis;
|
|
8717
9568
|
const missing = missingRunFields(analysis);
|
|
8718
9569
|
if (missing.length > 0) {
|
|
8719
|
-
const outputFormat =
|
|
9570
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8720
9571
|
const noInteractive = noInteractiveFlag(cmd);
|
|
8721
9572
|
if (!canPrompt(outputFormat, noInteractive)) {
|
|
8722
9573
|
const { message, suggestion } = explainMissingRunFields(
|
|
@@ -8777,7 +9628,7 @@ function typedColumns(given) {
|
|
|
8777
9628
|
return entries === void 0 ? null : resolveColumnArguments(entries, []);
|
|
8778
9629
|
}
|
|
8779
9630
|
async function createAnalysis(options, cmd) {
|
|
8780
|
-
const outputFormat =
|
|
9631
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8781
9632
|
const api = createApiClient();
|
|
8782
9633
|
const visibility = parseVisibility(options.visibility);
|
|
8783
9634
|
const request = {
|
|
@@ -8790,7 +9641,10 @@ async function createAnalysis(options, cmd) {
|
|
|
8790
9641
|
questions: questionsOf(options.question),
|
|
8791
9642
|
segment: options.segment ?? null
|
|
8792
9643
|
};
|
|
8793
|
-
const created = await api.analysis.create(
|
|
9644
|
+
const created = await api.analysis.create({
|
|
9645
|
+
...request,
|
|
9646
|
+
...options.licence ? { licenceId: options.licence } : {}
|
|
9647
|
+
});
|
|
8794
9648
|
if (isDryRun()) {
|
|
8795
9649
|
hint("Dry run: nothing was created.");
|
|
8796
9650
|
return;
|
|
@@ -8807,7 +9661,7 @@ async function deleteAnalysis(analysisId) {
|
|
|
8807
9661
|
success(`Deleted analysis ${analysisId}.`);
|
|
8808
9662
|
}
|
|
8809
9663
|
async function patchAndPrint(analysisId, value, handler, successLabel, cmd) {
|
|
8810
|
-
const outputFormat =
|
|
9664
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8811
9665
|
const api = createApiClient();
|
|
8812
9666
|
const updated = await handler(api, analysisId, value);
|
|
8813
9667
|
if (isDryRun()) {
|
|
@@ -8847,19 +9701,19 @@ function stackChoices(options, files) {
|
|
|
8847
9701
|
}
|
|
8848
9702
|
async function uploadOne(api, analysisId, file, asUploaded, human) {
|
|
8849
9703
|
const uploaded = await withStatus(
|
|
8850
|
-
`Uploading ${
|
|
9704
|
+
`Uploading ${path9.basename(file)}`,
|
|
8851
9705
|
() => api.analysis.uploadDataMultipart(analysisId, multipartFromFile(file))
|
|
8852
9706
|
);
|
|
8853
9707
|
if (isDryRun() || uploaded.dataImport) return uploaded;
|
|
8854
9708
|
if (asUploaded.length > 0) {
|
|
8855
|
-
sourcesAsUploaded([{ fileName:
|
|
9709
|
+
sourcesAsUploaded([{ fileName: path9.basename(file) }], asUploaded);
|
|
8856
9710
|
return uploaded;
|
|
8857
9711
|
}
|
|
8858
9712
|
return await reshapeSingle(api, analysisId, human) ?? uploaded;
|
|
8859
9713
|
}
|
|
8860
9714
|
async function uploadData(analysisId, files, options, cmd) {
|
|
8861
9715
|
const api = createApiClient();
|
|
8862
|
-
const outputFormat =
|
|
9716
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8863
9717
|
const ctx = importContext(api, analysisId, cmd, "none");
|
|
8864
9718
|
const file = files[0];
|
|
8865
9719
|
if (files.length > 1) {
|
|
@@ -8891,7 +9745,7 @@ async function uploadData(analysisId, files, options, cmd) {
|
|
|
8891
9745
|
`For example: diafunc analyze upload ${analysisId} data.csv`
|
|
8892
9746
|
);
|
|
8893
9747
|
}
|
|
8894
|
-
if (!
|
|
9748
|
+
if (!fs11.existsSync(file)) {
|
|
8895
9749
|
throw new CliError(`File not found: ${file}`, { exitCode: EXIT_USAGE });
|
|
8896
9750
|
}
|
|
8897
9751
|
}
|
|
@@ -8909,7 +9763,7 @@ async function uploadData(analysisId, files, options, cmd) {
|
|
|
8909
9763
|
}
|
|
8910
9764
|
}
|
|
8911
9765
|
async function stopDataImport(analysisId, cmd) {
|
|
8912
|
-
const outputFormat =
|
|
9766
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8913
9767
|
const api = createApiClient();
|
|
8914
9768
|
const stopped = await withStatus("Stopping the data import", () => stopImport(api, analysisId));
|
|
8915
9769
|
if (isDryRun()) {
|
|
@@ -8932,7 +9786,7 @@ async function stopDataImport(analysisId, cmd) {
|
|
|
8932
9786
|
warn(stopped.dataImport.message);
|
|
8933
9787
|
}
|
|
8934
9788
|
async function listColumns(analysisId, cmd) {
|
|
8935
|
-
const outputFormat =
|
|
9789
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8936
9790
|
const api = createApiClient();
|
|
8937
9791
|
const columns = await api.analysis.getColumns(analysisId);
|
|
8938
9792
|
if (columns.length === 0) {
|
|
@@ -8943,7 +9797,7 @@ async function listColumns(analysisId, cmd) {
|
|
|
8943
9797
|
format(columns, { format: outputFormat, columns: ["name", "valueType"] });
|
|
8944
9798
|
}
|
|
8945
9799
|
async function listRuns(analysisId, count, cmd) {
|
|
8946
|
-
const outputFormat =
|
|
9800
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8947
9801
|
const api = createApiClient();
|
|
8948
9802
|
const runs = await api.analysis.getRunsForAnalysis(analysisId, count);
|
|
8949
9803
|
format(runs.map((r) => ({
|
|
@@ -8966,7 +9820,7 @@ async function listRuns(analysisId, count, cmd) {
|
|
|
8966
9820
|
});
|
|
8967
9821
|
}
|
|
8968
9822
|
async function cancelRun(runId, cmd) {
|
|
8969
|
-
const outputFormat =
|
|
9823
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8970
9824
|
const api = createApiClient();
|
|
8971
9825
|
const run = await api.analysis.cancelRun(runId);
|
|
8972
9826
|
if (outputFormat === "human") {
|
|
@@ -8980,13 +9834,13 @@ async function cancelRun(runId, cmd) {
|
|
|
8980
9834
|
}
|
|
8981
9835
|
}
|
|
8982
9836
|
async function listPresets(cmd) {
|
|
8983
|
-
const outputFormat =
|
|
9837
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8984
9838
|
const api = createApiClient();
|
|
8985
9839
|
const presets = await api.analysis.getPresets();
|
|
8986
9840
|
format(presets.map((p) => ({
|
|
8987
9841
|
presetId: p.presetId,
|
|
8988
9842
|
name: p.name,
|
|
8989
|
-
targets: p.
|
|
9843
|
+
targets: p.targets.join(", "),
|
|
8990
9844
|
questions: p.questions.length,
|
|
8991
9845
|
segment: p.segmentKey,
|
|
8992
9846
|
hours: p.time,
|
|
@@ -9005,7 +9859,7 @@ async function listPresets(cmd) {
|
|
|
9005
9859
|
});
|
|
9006
9860
|
}
|
|
9007
9861
|
async function getPreset(presetId, cmd) {
|
|
9008
|
-
const outputFormat =
|
|
9862
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
9009
9863
|
const api = createApiClient();
|
|
9010
9864
|
const opt = await api.analysis.getPreset(presetId);
|
|
9011
9865
|
if (!opt.preset) {
|
|
@@ -9015,12 +9869,12 @@ async function getPreset(presetId, cmd) {
|
|
|
9015
9869
|
format(opt.preset, { format: outputFormat });
|
|
9016
9870
|
}
|
|
9017
9871
|
async function savePreset(options, cmd) {
|
|
9018
|
-
const outputFormat =
|
|
9872
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
9019
9873
|
const api = createApiClient();
|
|
9020
9874
|
const preset = {
|
|
9021
9875
|
presetId: options.id ?? null,
|
|
9022
9876
|
name: options.name,
|
|
9023
|
-
|
|
9877
|
+
targets: typedColumns(options.targets) ?? [],
|
|
9024
9878
|
questions: questionsOf(options.question) ?? [],
|
|
9025
9879
|
segmentKey: options.segment ?? null,
|
|
9026
9880
|
time: options.hours,
|
|
@@ -9070,7 +9924,7 @@ function triggerChanges(options) {
|
|
|
9070
9924
|
};
|
|
9071
9925
|
}
|
|
9072
9926
|
async function listTriggers(analysisId, cmd) {
|
|
9073
|
-
const outputFormat =
|
|
9927
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
9074
9928
|
const api = createApiClient();
|
|
9075
9929
|
const triggers = await api.analysis.listTriggers(analysisId);
|
|
9076
9930
|
format(triggers.map(triggerRow), {
|
|
@@ -9087,7 +9941,7 @@ async function listTriggers(analysisId, cmd) {
|
|
|
9087
9941
|
});
|
|
9088
9942
|
}
|
|
9089
9943
|
async function createTrigger(analysisId, kind, schedule, cmd, refreshFirst = false) {
|
|
9090
|
-
const outputFormat =
|
|
9944
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
9091
9945
|
const upper = kind.toUpperCase();
|
|
9092
9946
|
if (upper !== "ONCE" && upper !== "CRON") {
|
|
9093
9947
|
failure(`Invalid kind "${kind}". Use ONCE or CRON.`);
|
|
@@ -9107,17 +9961,18 @@ async function deleteTrigger(triggerId) {
|
|
|
9107
9961
|
success(`Deleted trigger ${triggerId}.`);
|
|
9108
9962
|
}
|
|
9109
9963
|
async function updateTriggerCmd(triggerId, options, cmd) {
|
|
9110
|
-
const outputFormat =
|
|
9964
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
9111
9965
|
const changes = triggerChanges(options);
|
|
9112
9966
|
const api = createApiClient();
|
|
9113
9967
|
const trigger = await api.analysis.updateTrigger(triggerId, changes);
|
|
9114
9968
|
format(trigger, { format: outputFormat });
|
|
9115
9969
|
}
|
|
9116
9970
|
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";
|
|
9971
|
+
var LICENCE_HELP = "With PUBLIC: the licence the analysis's project is published under, an id of the licence catalogue (see 'diafunc licence list')";
|
|
9117
9972
|
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`;
|
|
9118
9973
|
function registerAnalyzeCommand(program) {
|
|
9119
9974
|
const analyze = program.command("analyze").description("Run and manage automatic analyses");
|
|
9120
|
-
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 limit (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").option("--as-uploaded [file]", AS_UPLOADED_HELP, collectAsUploaded).action(async (files, options, cmd) => {
|
|
9975
|
+
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("--licence <licenceId>", LICENCE_HELP).option("--hours <hours>", `Time limit (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").option("--as-uploaded [file]", AS_UPLOADED_HELP, collectAsUploaded).action(async (files, options, cmd) => {
|
|
9121
9976
|
try {
|
|
9122
9977
|
if (files.length === 0) {
|
|
9123
9978
|
analyze.help();
|
|
@@ -9163,7 +10018,7 @@ function registerAnalyzeCommand(program) {
|
|
|
9163
10018
|
reportCommandError(error);
|
|
9164
10019
|
}
|
|
9165
10020
|
});
|
|
9166
|
-
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 limit (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) => {
|
|
10021
|
+
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("--licence <licenceId>", LICENCE_HELP).option("--hours <hours>", `Time limit (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) => {
|
|
9167
10022
|
try {
|
|
9168
10023
|
await createAnalysis(options, cmd);
|
|
9169
10024
|
} catch (error) {
|
|
@@ -9204,13 +10059,20 @@ function registerAnalyzeCommand(program) {
|
|
|
9204
10059
|
handleError(error);
|
|
9205
10060
|
}
|
|
9206
10061
|
});
|
|
9207
|
-
analyze.command("visibility").description("Set analysis visibility (PRIVATE or PUBLIC)").argument("<id>", "Analysis ID").argument("<vis>", "PRIVATE or PUBLIC").
|
|
10062
|
+
analyze.command("visibility").description("Set analysis visibility (PRIVATE or PUBLIC)").argument("<id>", "Analysis ID").argument("<vis>", "PRIVATE or PUBLIC").option("--licence <licenceId>", LICENCE_HELP).addHelpText("after", `
|
|
10063
|
+
Examples:
|
|
10064
|
+
$ diafunc analyze visibility <id> PUBLIC --licence CC-BY-4.0 publish under a licence
|
|
10065
|
+
$ diafunc analyze visibility <id> PRIVATE withdraw it; the licence is kept for later
|
|
10066
|
+
`).action(async (id, vis, options, cmd) => {
|
|
9208
10067
|
try {
|
|
9209
10068
|
const visibility = parseVisibility(vis);
|
|
9210
10069
|
await patchAndPrint(
|
|
9211
10070
|
id,
|
|
9212
10071
|
visibility,
|
|
9213
|
-
(api, aid, v) => api.analysis.patchVisibility(aid, {
|
|
10072
|
+
(api, aid, v) => api.analysis.patchVisibility(aid, {
|
|
10073
|
+
visibility: v,
|
|
10074
|
+
...options.licence ? { licenceId: options.licence } : {}
|
|
10075
|
+
}),
|
|
9214
10076
|
"Visibility",
|
|
9215
10077
|
cmd
|
|
9216
10078
|
);
|
|
@@ -9283,13 +10145,13 @@ function registerAnalyzeCommand(program) {
|
|
|
9283
10145
|
handleError(error);
|
|
9284
10146
|
}
|
|
9285
10147
|
});
|
|
9286
|
-
analyze.command("confirmed-inputs").description("Set the columns the owner confirms as known before the
|
|
10148
|
+
analyze.command("confirmed-inputs").description("Set the columns the owner confirms as known before the target (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) => {
|
|
9287
10149
|
try {
|
|
9288
10150
|
await patchColumns(
|
|
9289
10151
|
id,
|
|
9290
10152
|
given,
|
|
9291
10153
|
(api, columns) => api.analysis.patchConfirmedInputs(id, { columns }),
|
|
9292
|
-
"Columns known before the
|
|
10154
|
+
"Columns known before the target",
|
|
9293
10155
|
cmd
|
|
9294
10156
|
);
|
|
9295
10157
|
} catch (error) {
|
|
@@ -9425,7 +10287,7 @@ function registerAnalyzeCommand(program) {
|
|
|
9425
10287
|
// src/commands/public/index.ts
|
|
9426
10288
|
var MIN_LIMIT = 1;
|
|
9427
10289
|
var MAX_LIMIT = 500;
|
|
9428
|
-
function
|
|
10290
|
+
function getOutputFormat18(cmd) {
|
|
9429
10291
|
const config = loadConfig();
|
|
9430
10292
|
const globalOpts = cmd.optsWithGlobals();
|
|
9431
10293
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9477,7 +10339,7 @@ async function readPublicAnalyses(analysis, options) {
|
|
|
9477
10339
|
}
|
|
9478
10340
|
}
|
|
9479
10341
|
async function listPublicAnalyses(options, cmd) {
|
|
9480
|
-
const outputFormat =
|
|
10342
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
9481
10343
|
const limit = parseLimit(options.limit);
|
|
9482
10344
|
const changedSince = options.changedSince === void 0 ? void 0 : parseChangedSince(options.changedSince);
|
|
9483
10345
|
const api = createApiClient();
|
|
@@ -9500,7 +10362,8 @@ async function listPublicAnalyses(options, cmd) {
|
|
|
9500
10362
|
{ key: "analysisId", kind: "id" },
|
|
9501
10363
|
{ key: "projectId", kind: "id" },
|
|
9502
10364
|
{ key: "publishedAt", header: "published", kind: "date" },
|
|
9503
|
-
{ key: "changedAt", header: "changed", kind: "date" }
|
|
10365
|
+
{ key: "changedAt", header: "changed", kind: "date" },
|
|
10366
|
+
{ key: "licenceId", header: "licence" }
|
|
9504
10367
|
]
|
|
9505
10368
|
});
|
|
9506
10369
|
}
|
|
@@ -9519,7 +10382,7 @@ function newestRunRecord(run) {
|
|
|
9519
10382
|
};
|
|
9520
10383
|
}
|
|
9521
10384
|
async function showPublicAnalysis(analysisId, cmd) {
|
|
9522
|
-
const outputFormat =
|
|
10385
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
9523
10386
|
const api = createApiClient();
|
|
9524
10387
|
const result = await api.analysis.get(analysisId);
|
|
9525
10388
|
if (!result?.analysis) {
|
|
@@ -9587,9 +10450,136 @@ Examples:
|
|
|
9587
10450
|
});
|
|
9588
10451
|
}
|
|
9589
10452
|
|
|
10453
|
+
// src/commands/licence/index.ts
|
|
10454
|
+
import chalk29 from "chalk";
|
|
10455
|
+
function getOutputFormat19(cmd) {
|
|
10456
|
+
const config = loadConfig();
|
|
10457
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
10458
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
10459
|
+
}
|
|
10460
|
+
var LICENCE_MARKS = [
|
|
10461
|
+
{ mark: "C", flag: "commercialUse", meaning: "commercial use" },
|
|
10462
|
+
{ mark: "D", flag: "derivatives", meaning: "adaptations and forks" },
|
|
10463
|
+
{ mark: "R", flag: "redistribution", meaning: "redistribution" },
|
|
10464
|
+
{ mark: "BY", flag: "attributionRequired", meaning: "attribution required" },
|
|
10465
|
+
{ mark: "SA", flag: "shareAlike", meaning: "share-alike" }
|
|
10466
|
+
];
|
|
10467
|
+
function licenceMarks(licence) {
|
|
10468
|
+
const marks = LICENCE_MARKS.filter(({ flag }) => licence[flag] === true).map(({ mark }) => mark);
|
|
10469
|
+
return marks.length > 0 ? marks.join(" ") : null;
|
|
10470
|
+
}
|
|
10471
|
+
function stateWord(state) {
|
|
10472
|
+
return state.toLowerCase();
|
|
10473
|
+
}
|
|
10474
|
+
async function listLicences(cmd) {
|
|
10475
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
10476
|
+
const api = createApiClient();
|
|
10477
|
+
const licences = await api.admin.listLicences();
|
|
10478
|
+
if (outputFormat === "json") {
|
|
10479
|
+
format(licences, { format: outputFormat });
|
|
10480
|
+
return;
|
|
10481
|
+
}
|
|
10482
|
+
if (licences.length === 0 && outputFormat === "human") {
|
|
10483
|
+
empty("licences");
|
|
10484
|
+
return;
|
|
10485
|
+
}
|
|
10486
|
+
format(licences.map((l) => ({
|
|
10487
|
+
licenceId: l.licenceId,
|
|
10488
|
+
name: l.name,
|
|
10489
|
+
state: stateWord(l.state),
|
|
10490
|
+
flags: licenceMarks(l),
|
|
10491
|
+
recommended: l.recommended
|
|
10492
|
+
})), {
|
|
10493
|
+
format: outputFormat,
|
|
10494
|
+
columns: [
|
|
10495
|
+
{ key: "licenceId", header: "id" },
|
|
10496
|
+
{ key: "name" },
|
|
10497
|
+
{ key: "state", kind: "state" },
|
|
10498
|
+
{ key: "flags" },
|
|
10499
|
+
{ key: "recommended", kind: "boolean" }
|
|
10500
|
+
]
|
|
10501
|
+
});
|
|
10502
|
+
if (outputFormat === "human") {
|
|
10503
|
+
console.error(chalk29.dim(
|
|
10504
|
+
`
|
|
10505
|
+
Flags: ${LICENCE_MARKS.map(({ mark, meaning }) => `${mark} ${meaning}`).join(", ")}. A deprecated licence stays on the projects that carry it and cannot be chosen.`
|
|
10506
|
+
));
|
|
10507
|
+
}
|
|
10508
|
+
}
|
|
10509
|
+
async function showLicence(licenceId, cmd) {
|
|
10510
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
10511
|
+
const api = createApiClient();
|
|
10512
|
+
let licence;
|
|
10513
|
+
try {
|
|
10514
|
+
licence = await api.admin.getLicence(licenceId);
|
|
10515
|
+
} catch (error) {
|
|
10516
|
+
if (error instanceof ApiError && error.status === 404) {
|
|
10517
|
+
throw new CliError(`No licence "${licenceId}" in the catalogue.`, {
|
|
10518
|
+
hint: `List the licences with 'diafunc licence list'.`
|
|
10519
|
+
});
|
|
10520
|
+
}
|
|
10521
|
+
throw error;
|
|
10522
|
+
}
|
|
10523
|
+
if (outputFormat !== "human") {
|
|
10524
|
+
format(licence, { format: outputFormat });
|
|
10525
|
+
return;
|
|
10526
|
+
}
|
|
10527
|
+
format({
|
|
10528
|
+
licenceId: licence.licenceId,
|
|
10529
|
+
name: licence.name,
|
|
10530
|
+
state: stateWord(licence.state),
|
|
10531
|
+
summary: licence.summary,
|
|
10532
|
+
url: licence.url,
|
|
10533
|
+
commercialUse: licence.commercialUse,
|
|
10534
|
+
derivatives: licence.derivatives,
|
|
10535
|
+
redistribution: licence.redistribution,
|
|
10536
|
+
attributionRequired: licence.attributionRequired,
|
|
10537
|
+
shareAlike: licence.shareAlike,
|
|
10538
|
+
recommended: licence.recommended
|
|
10539
|
+
}, {
|
|
10540
|
+
format: outputFormat,
|
|
10541
|
+
columns: [
|
|
10542
|
+
{ key: "licenceId", header: "ID", kind: "id" },
|
|
10543
|
+
{ key: "name", header: "Name" },
|
|
10544
|
+
{ key: "state", header: "State", kind: "state" },
|
|
10545
|
+
{ key: "summary", header: "Summary" },
|
|
10546
|
+
{ key: "url", header: "Licence text" },
|
|
10547
|
+
{ key: "commercialUse", header: "Commercial use", kind: "boolean" },
|
|
10548
|
+
{ key: "derivatives", header: "Adaptations and forks", kind: "boolean" },
|
|
10549
|
+
{ key: "redistribution", header: "Redistribution", kind: "boolean" },
|
|
10550
|
+
{ key: "attributionRequired", header: "Attribution required", kind: "boolean" },
|
|
10551
|
+
{ key: "shareAlike", header: "Share-alike", kind: "boolean" },
|
|
10552
|
+
{ key: "recommended", header: "Recommended", kind: "boolean" }
|
|
10553
|
+
]
|
|
10554
|
+
});
|
|
10555
|
+
}
|
|
10556
|
+
function registerLicenceCommands(program) {
|
|
10557
|
+
const licence = program.command("licence").description("The licences a public project can be published under (no sign-in needed)").addHelpText("after", `
|
|
10558
|
+
Examples:
|
|
10559
|
+
$ diafunc licence list the licences that can be chosen
|
|
10560
|
+
$ diafunc licence show CC-BY-4.0 one licence and what it allows
|
|
10561
|
+
$ diafunc project create --visibility PUBLIC --licence CC-BY-4.0
|
|
10562
|
+
$ diafunc analyze visibility <id> PUBLIC --licence CC0-1.0
|
|
10563
|
+
`);
|
|
10564
|
+
licence.command("list").description("List the licence catalogue: the active and the deprecated licences, in catalogue order").action(async (_options, cmd) => {
|
|
10565
|
+
try {
|
|
10566
|
+
await listLicences(cmd);
|
|
10567
|
+
} catch (error) {
|
|
10568
|
+
handleError(error);
|
|
10569
|
+
}
|
|
10570
|
+
});
|
|
10571
|
+
licence.command("show").description("Show one licence, in any state, and what it allows").argument("<licenceId>", "Licence ID (CC-BY-4.0, CC0-1.0, diafunc-view-only, ...)").action(async (licenceId, _options, cmd) => {
|
|
10572
|
+
try {
|
|
10573
|
+
await showLicence(licenceId, cmd);
|
|
10574
|
+
} catch (error) {
|
|
10575
|
+
handleError(error);
|
|
10576
|
+
}
|
|
10577
|
+
});
|
|
10578
|
+
}
|
|
10579
|
+
|
|
9590
10580
|
// src/commands/data-sources/index.ts
|
|
9591
|
-
import
|
|
9592
|
-
function
|
|
10581
|
+
import chalk30 from "chalk";
|
|
10582
|
+
function getOutputFormat20(cmd) {
|
|
9593
10583
|
const config = loadConfig();
|
|
9594
10584
|
const globalOpts = cmd.optsWithGlobals();
|
|
9595
10585
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9689,7 +10679,7 @@ function resolveProjectId(cmd) {
|
|
|
9689
10679
|
return resolved;
|
|
9690
10680
|
}
|
|
9691
10681
|
async function listDataSources(projectId, cmd) {
|
|
9692
|
-
const outputFormat =
|
|
10682
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9693
10683
|
const api = createApiClient();
|
|
9694
10684
|
const sources = await api.storage.listDataSources(projectId);
|
|
9695
10685
|
if (outputFormat === "human" && sources.length === 0) {
|
|
@@ -9710,13 +10700,13 @@ async function listDataSources(projectId, cmd) {
|
|
|
9710
10700
|
});
|
|
9711
10701
|
}
|
|
9712
10702
|
async function getDataSource(id, cmd) {
|
|
9713
|
-
const outputFormat =
|
|
10703
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9714
10704
|
const api = createApiClient();
|
|
9715
10705
|
const ds = await api.storage.getDataSource(id);
|
|
9716
10706
|
format(ds, { format: outputFormat });
|
|
9717
10707
|
}
|
|
9718
10708
|
async function showDashboard(projectId, cmd) {
|
|
9719
|
-
const outputFormat =
|
|
10709
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9720
10710
|
const api = createApiClient();
|
|
9721
10711
|
const dashboard = await api.storage.getDataSourceDashboard(projectId);
|
|
9722
10712
|
if (outputFormat !== "human") {
|
|
@@ -9724,7 +10714,7 @@ async function showDashboard(projectId, cmd) {
|
|
|
9724
10714
|
return;
|
|
9725
10715
|
}
|
|
9726
10716
|
const r = dashboard.rollup;
|
|
9727
|
-
let line =
|
|
10717
|
+
let line = chalk30.bold(`DataSources in ${projectId}: `) + `${r.totalSources} total, ${r.scheduledSources} scheduled, ${r.sourcesWithRecentFailure} failing recently`;
|
|
9728
10718
|
if (r.lastActivityAt) line += `, last activity ${r.lastActivityAt}`;
|
|
9729
10719
|
console.log(line);
|
|
9730
10720
|
if (dashboard.sources.length === 0) {
|
|
@@ -9785,14 +10775,14 @@ async function createForAnalysis(api, options, human) {
|
|
|
9785
10775
|
if (human) {
|
|
9786
10776
|
success(`Added ${source.fileName} to analysis ${analysisId} from data source ${source.dataSourceId ?? ""}`.trimEnd());
|
|
9787
10777
|
for (const line of planLines(build.plan)) {
|
|
9788
|
-
console.log(line.caution ?
|
|
10778
|
+
console.log(line.caution ? chalk30.yellow(` ${line.text}`) : chalk30.dim(` ${line.text}`));
|
|
9789
10779
|
}
|
|
9790
|
-
console.log(
|
|
10780
|
+
console.log(chalk30.dim(options.scheduleCron ? ` Refreshes ${humanizeCron(options.scheduleCron)}; each refresh replaces the file and builds the data again.` : " No schedule of its own: refresh it with `data-sources refresh`, or let a trigger fetch it before a run (`analyze triggers create --refresh-first`)."));
|
|
9791
10781
|
}
|
|
9792
10782
|
return { source, build };
|
|
9793
10783
|
}
|
|
9794
10784
|
async function createDataSource(options, cmd) {
|
|
9795
|
-
const outputFormat =
|
|
10785
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9796
10786
|
const target = createTarget(options);
|
|
9797
10787
|
const api = createApiClient();
|
|
9798
10788
|
if (target === "analysis") {
|
|
@@ -9815,14 +10805,14 @@ async function createDataSource(options, cmd) {
|
|
|
9815
10805
|
const ds = await api.storage.createDataSource(request);
|
|
9816
10806
|
if (outputFormat === "human") {
|
|
9817
10807
|
success(`Created data source ${ds.id}`);
|
|
9818
|
-
console.log(
|
|
9819
|
-
if (ds.lastRunError) console.log(
|
|
10808
|
+
console.log(chalk30.dim(` Last run: ${ds.lastRunStatus ?? "\u2014"}`));
|
|
10809
|
+
if (ds.lastRunError) console.log(chalk30.dim(` Error: ${ds.lastRunError}`));
|
|
9820
10810
|
} else {
|
|
9821
10811
|
format(ds, { format: outputFormat });
|
|
9822
10812
|
}
|
|
9823
10813
|
}
|
|
9824
10814
|
async function updateDataSource(id, options, cmd) {
|
|
9825
|
-
const outputFormat =
|
|
10815
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9826
10816
|
if (options.name === void 0 && options.type === void 0 && (!options.config || options.config.length === 0) && options.scheduleCron === void 0 && !options.clearSchedule) {
|
|
9827
10817
|
throw new Error("Provide at least one of --name, --type, --config, --schedule-cron, or --clear-schedule.");
|
|
9828
10818
|
}
|
|
@@ -9857,18 +10847,18 @@ async function deleteDataSource(id) {
|
|
|
9857
10847
|
success(`Deleted data source ${id}`);
|
|
9858
10848
|
}
|
|
9859
10849
|
async function refreshDataSource(id, cmd) {
|
|
9860
|
-
const outputFormat =
|
|
10850
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9861
10851
|
const api = createApiClient();
|
|
9862
10852
|
const run = await api.storage.refreshDataSource(id);
|
|
9863
10853
|
if (outputFormat === "human") {
|
|
9864
10854
|
success(`Refresh queued: run ${run.runId}, status ${run.status}.`);
|
|
9865
|
-
if (run.errorMessage) console.log(
|
|
10855
|
+
if (run.errorMessage) console.log(chalk30.red(` Error: ${run.errorMessage}`));
|
|
9866
10856
|
} else {
|
|
9867
10857
|
format(run, { format: outputFormat });
|
|
9868
10858
|
}
|
|
9869
10859
|
}
|
|
9870
10860
|
async function listRuns2(id, limit, cmd) {
|
|
9871
|
-
const outputFormat =
|
|
10861
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9872
10862
|
const api = createApiClient();
|
|
9873
10863
|
const runs = await api.storage.listDataSourceRuns(id, limit);
|
|
9874
10864
|
if (outputFormat === "human" && runs.length === 0) {
|
|
@@ -9890,13 +10880,13 @@ async function listRuns2(id, limit, cmd) {
|
|
|
9890
10880
|
});
|
|
9891
10881
|
}
|
|
9892
10882
|
async function getRun(id, runId, cmd) {
|
|
9893
|
-
const outputFormat =
|
|
10883
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9894
10884
|
const api = createApiClient();
|
|
9895
10885
|
const run = await api.storage.getDataSourceRun(id, runId);
|
|
9896
10886
|
format(run, { format: outputFormat });
|
|
9897
10887
|
}
|
|
9898
10888
|
async function listConnectorTypes(cmd) {
|
|
9899
|
-
const outputFormat =
|
|
10889
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
9900
10890
|
const api = createApiClient();
|
|
9901
10891
|
const types = await api.storage.listDataSourceConnectorTypes();
|
|
9902
10892
|
if (outputFormat === "human") {
|
|
@@ -9989,8 +10979,8 @@ Examples:
|
|
|
9989
10979
|
}
|
|
9990
10980
|
|
|
9991
10981
|
// src/commands/table-exporters/index.ts
|
|
9992
|
-
import
|
|
9993
|
-
function
|
|
10982
|
+
import chalk31 from "chalk";
|
|
10983
|
+
function getOutputFormat21(cmd) {
|
|
9994
10984
|
const config = loadConfig();
|
|
9995
10985
|
const globalOpts = cmd.optsWithGlobals();
|
|
9996
10986
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9999,7 +10989,7 @@ function registerTableExportersCommands(program) {
|
|
|
9999
10989
|
const exporters = program.command("table-exporters").description("Manage user-defined exporters (UDE); admin only");
|
|
10000
10990
|
exporters.command("list").description("List all registered user-defined exporters").action(async (_options, cmd) => {
|
|
10001
10991
|
try {
|
|
10002
|
-
const outputFormat =
|
|
10992
|
+
const outputFormat = getOutputFormat21(cmd);
|
|
10003
10993
|
const api = createApiClient();
|
|
10004
10994
|
const list = await api.storage.listUserDefinedExporters();
|
|
10005
10995
|
if (outputFormat === "json") {
|
|
@@ -10020,14 +11010,14 @@ function registerTableExportersCommands(program) {
|
|
|
10020
11010
|
format: outputFormat,
|
|
10021
11011
|
columns: ["id", "name", "format", "extension", "mimeType", "priority", "function", "createdBy"]
|
|
10022
11012
|
});
|
|
10023
|
-
console.log(
|
|
11013
|
+
console.log(chalk31.dim(`${list.length} exporter(s)`));
|
|
10024
11014
|
} catch (error) {
|
|
10025
11015
|
handleError(error);
|
|
10026
11016
|
}
|
|
10027
11017
|
});
|
|
10028
11018
|
exporters.command("get").description("Show a single user-defined exporter by id").argument("<id>", "Exporter id").action(async (id, _options, cmd) => {
|
|
10029
11019
|
try {
|
|
10030
|
-
const outputFormat =
|
|
11020
|
+
const outputFormat = getOutputFormat21(cmd);
|
|
10031
11021
|
const api = createApiClient();
|
|
10032
11022
|
const list = await api.storage.listUserDefinedExporters();
|
|
10033
11023
|
const exporter = list.find((e) => e.id === id);
|
|
@@ -10042,7 +11032,7 @@ function registerTableExportersCommands(program) {
|
|
|
10042
11032
|
});
|
|
10043
11033
|
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) => {
|
|
10044
11034
|
try {
|
|
10045
|
-
const outputFormat =
|
|
11035
|
+
const outputFormat = getOutputFormat21(cmd);
|
|
10046
11036
|
const api = createApiClient();
|
|
10047
11037
|
const payload = {
|
|
10048
11038
|
name: options.name,
|
|
@@ -10078,9 +11068,9 @@ function registerTableExportersCommands(program) {
|
|
|
10078
11068
|
}
|
|
10079
11069
|
|
|
10080
11070
|
// src/commands/skeleton/index.ts
|
|
10081
|
-
import
|
|
10082
|
-
import * as
|
|
10083
|
-
function
|
|
11071
|
+
import chalk32 from "chalk";
|
|
11072
|
+
import * as fs12 from "fs";
|
|
11073
|
+
function getOutputFormat22(cmd) {
|
|
10084
11074
|
const config = loadConfig();
|
|
10085
11075
|
const globalOpts = cmd.optsWithGlobals();
|
|
10086
11076
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -10103,10 +11093,10 @@ function resolveTemplate(raw) {
|
|
|
10103
11093
|
if (!file) {
|
|
10104
11094
|
throw new Error("--template @ requires a filename after the @, e.g. --template @template.txt");
|
|
10105
11095
|
}
|
|
10106
|
-
if (!
|
|
11096
|
+
if (!fs12.existsSync(file)) {
|
|
10107
11097
|
throw new Error(`Template file not found: ${file}`);
|
|
10108
11098
|
}
|
|
10109
|
-
return
|
|
11099
|
+
return fs12.readFileSync(file, "utf-8").trim();
|
|
10110
11100
|
}
|
|
10111
11101
|
return raw;
|
|
10112
11102
|
}
|
|
@@ -10129,7 +11119,7 @@ function skeletonTableRow(s) {
|
|
|
10129
11119
|
};
|
|
10130
11120
|
}
|
|
10131
11121
|
async function createSkeleton(options, cmd) {
|
|
10132
|
-
const outputFormat =
|
|
11122
|
+
const outputFormat = getOutputFormat22(cmd);
|
|
10133
11123
|
const projectId = resolveProjectId2(cmd);
|
|
10134
11124
|
const template = resolveTemplate(options.template);
|
|
10135
11125
|
const weight = parseWeight(options.weight);
|
|
@@ -10145,16 +11135,16 @@ async function createSkeleton(options, cmd) {
|
|
|
10145
11135
|
const skeleton = await api.storage.createSkeleton(request);
|
|
10146
11136
|
if (outputFormat === "human") {
|
|
10147
11137
|
success(`Created skeleton ${skeleton.id}`);
|
|
10148
|
-
console.log(
|
|
10149
|
-
console.log(
|
|
10150
|
-
console.log(
|
|
10151
|
-
console.log(
|
|
11138
|
+
console.log(chalk32.dim(` name: ${skeleton.name}`));
|
|
11139
|
+
console.log(chalk32.dim(` template: ${skeleton.template}`));
|
|
11140
|
+
console.log(chalk32.dim(` paramCount: ${skeleton.paramCount}`));
|
|
11141
|
+
console.log(chalk32.dim(` weight: ${skeleton.weight}`));
|
|
10152
11142
|
} else {
|
|
10153
11143
|
format(skeleton, { format: outputFormat });
|
|
10154
11144
|
}
|
|
10155
11145
|
}
|
|
10156
11146
|
async function listSkeletons(cmd) {
|
|
10157
|
-
const outputFormat =
|
|
11147
|
+
const outputFormat = getOutputFormat22(cmd);
|
|
10158
11148
|
const projectId = resolveProjectId2(cmd);
|
|
10159
11149
|
const api = createApiClient();
|
|
10160
11150
|
const skeletons = await api.storage.listSkeletons(projectId);
|
|
@@ -10168,13 +11158,13 @@ async function listSkeletons(cmd) {
|
|
|
10168
11158
|
});
|
|
10169
11159
|
}
|
|
10170
11160
|
async function getSkeleton(id, cmd) {
|
|
10171
|
-
const outputFormat =
|
|
11161
|
+
const outputFormat = getOutputFormat22(cmd);
|
|
10172
11162
|
const api = createApiClient();
|
|
10173
11163
|
const skeleton = await api.storage.getSkeleton(id);
|
|
10174
11164
|
format(skeleton, { format: outputFormat });
|
|
10175
11165
|
}
|
|
10176
11166
|
async function updateSkeleton(id, options, cmd) {
|
|
10177
|
-
const outputFormat =
|
|
11167
|
+
const outputFormat = getOutputFormat22(cmd);
|
|
10178
11168
|
if (options.name === void 0 && options.template === void 0 && options.weight === void 0) {
|
|
10179
11169
|
throw new Error("Provide at least one of --name, --template, --weight.");
|
|
10180
11170
|
}
|
|
@@ -10187,10 +11177,10 @@ async function updateSkeleton(id, options, cmd) {
|
|
|
10187
11177
|
const skeleton = await api.storage.updateSkeleton(id, request);
|
|
10188
11178
|
if (outputFormat === "human") {
|
|
10189
11179
|
success(`Updated skeleton ${skeleton.id}`);
|
|
10190
|
-
console.log(
|
|
10191
|
-
console.log(
|
|
10192
|
-
console.log(
|
|
10193
|
-
console.log(
|
|
11180
|
+
console.log(chalk32.dim(` name: ${skeleton.name}`));
|
|
11181
|
+
console.log(chalk32.dim(` template: ${skeleton.template}`));
|
|
11182
|
+
console.log(chalk32.dim(` paramCount: ${skeleton.paramCount}`));
|
|
11183
|
+
console.log(chalk32.dim(` weight: ${skeleton.weight}`));
|
|
10194
11184
|
} else {
|
|
10195
11185
|
format(skeleton, { format: outputFormat });
|
|
10196
11186
|
}
|
|
@@ -10275,17 +11265,21 @@ _diafunc_completions() {
|
|
|
10275
11265
|
fi
|
|
10276
11266
|
;;
|
|
10277
11267
|
project)
|
|
10278
|
-
subcommands="list get create delete lock unlock members"
|
|
11268
|
+
subcommands="list get create delete lock unlock members tags"
|
|
10279
11269
|
if [[ "\${COMP_WORDS[2]}" == "members" ]]; then
|
|
10280
11270
|
COMPREPLY=($(compgen -W "list invite join remove" -- "\${cur}"))
|
|
11271
|
+
elif [[ "\${COMP_WORDS[2]}" == "tags" ]]; then
|
|
11272
|
+
COMPREPLY=($(compgen -W "get add remove set" -- "\${cur}"))
|
|
10281
11273
|
else
|
|
10282
11274
|
COMPREPLY=($(compgen -W "\${subcommands}" -- "\${cur}"))
|
|
10283
11275
|
fi
|
|
10284
11276
|
;;
|
|
10285
11277
|
entity)
|
|
10286
|
-
subcommands="list get delete history revert rename content"
|
|
11278
|
+
subcommands="list get delete history revert rename content tags"
|
|
10287
11279
|
if [[ "\${COMP_WORDS[2]}" == "content" ]]; then
|
|
10288
11280
|
COMPREPLY=($(compgen -W "get set delete" -- "\${cur}"))
|
|
11281
|
+
elif [[ "\${COMP_WORDS[2]}" == "tags" ]]; then
|
|
11282
|
+
COMPREPLY=($(compgen -W "get add remove set" -- "\${cur}"))
|
|
10289
11283
|
else
|
|
10290
11284
|
COMPREPLY=($(compgen -W "\${subcommands}" -- "\${cur}"))
|
|
10291
11285
|
fi
|
|
@@ -10336,11 +11330,12 @@ _diafunc_completions() {
|
|
|
10336
11330
|
esac
|
|
10337
11331
|
;;
|
|
10338
11332
|
admin)
|
|
10339
|
-
subcommands="users subscription settings backup"
|
|
11333
|
+
subcommands="users subscription settings backup curated-tags"
|
|
10340
11334
|
case "\${COMP_WORDS[2]}" in
|
|
10341
11335
|
users) COMPREPLY=($(compgen -W "list get" -- "\${cur}")) ;;
|
|
10342
11336
|
settings) COMPREPLY=($(compgen -W "get set" -- "\${cur}")) ;;
|
|
10343
11337
|
backup) COMPREPLY=($(compgen -W "create-full project" -- "\${cur}")) ;;
|
|
11338
|
+
curated-tags) COMPREPLY=($(compgen -W "list create update delete" -- "\${cur}")) ;;
|
|
10344
11339
|
*) COMPREPLY=($(compgen -W "\${subcommands}" -- "\${cur}")) ;;
|
|
10345
11340
|
esac
|
|
10346
11341
|
;;
|
|
@@ -10414,12 +11409,12 @@ _diafunc() {
|
|
|
10414
11409
|
|
|
10415
11410
|
_diafunc_auth() { _values 'subcommand' login logout status token; }
|
|
10416
11411
|
_diafunc_config() { _values 'subcommand' set get list profile; }
|
|
10417
|
-
_diafunc_project() { _values 'subcommand' list get create delete lock unlock members; }
|
|
11412
|
+
_diafunc_project() { _values 'subcommand' list get create delete lock unlock members tags; }
|
|
10418
11413
|
_diafunc_team() { _values 'subcommand' list get use usage create portal cancel leave members invitations seats packs transfer; }
|
|
10419
|
-
_diafunc_entity() { _values 'subcommand' list get delete history revert rename content; }
|
|
11414
|
+
_diafunc_entity() { _values 'subcommand' list get delete history revert rename content tags; }
|
|
10420
11415
|
_diafunc_table() { _values 'subcommand' view import export row column cell clear; }
|
|
10421
11416
|
_diafunc_chat() { _values 'subcommand' repl send stream upload session usage; }
|
|
10422
|
-
_diafunc_admin() { _values 'subcommand' users subscription settings backup; }
|
|
11417
|
+
_diafunc_admin() { _values 'subcommand' users subscription settings backup curated-tags; }
|
|
10423
11418
|
|
|
10424
11419
|
_diafunc "$@"`;
|
|
10425
11420
|
var FISH_COMPLETION = `# Fish completions for diafunc
|
|
@@ -10462,10 +11457,10 @@ complete -c diafunc -n "__fish_seen_subcommand_from config; and not __fish_seen_
|
|
|
10462
11457
|
complete -c diafunc -n "__fish_seen_subcommand_from profile; and not __fish_seen_subcommand_from add use list remove" -a "add use list remove"
|
|
10463
11458
|
|
|
10464
11459
|
# project
|
|
10465
|
-
complete -c diafunc -n "__fish_seen_subcommand_from project; and not __fish_seen_subcommand_from list get create delete lock unlock members" -a "list get create delete lock unlock members"
|
|
11460
|
+
complete -c diafunc -n "__fish_seen_subcommand_from project; and not __fish_seen_subcommand_from list get create delete lock unlock members tags" -a "list get create delete lock unlock members tags"
|
|
10466
11461
|
|
|
10467
11462
|
# entity
|
|
10468
|
-
complete -c diafunc -n "__fish_seen_subcommand_from entity; and not __fish_seen_subcommand_from list get delete history revert rename content" -a "list get delete history revert rename content"
|
|
11463
|
+
complete -c diafunc -n "__fish_seen_subcommand_from entity; and not __fish_seen_subcommand_from list get delete history revert rename content tags" -a "list get delete history revert rename content tags"
|
|
10469
11464
|
|
|
10470
11465
|
# branch
|
|
10471
11466
|
complete -c diafunc -n "__fish_seen_subcommand_from branch; and not __fish_seen_subcommand_from list create delete merge fork" -a "list create delete merge fork"
|
|
@@ -10486,7 +11481,7 @@ complete -c diafunc -n "__fish_seen_subcommand_from seats packs; and not __fish_
|
|
|
10486
11481
|
complete -c diafunc -n "__fish_seen_subcommand_from transfer; and not __fish_seen_subcommand_from start status accept cancel" -a "start status accept cancel"
|
|
10487
11482
|
|
|
10488
11483
|
# admin
|
|
10489
|
-
complete -c diafunc -n "__fish_seen_subcommand_from admin; and not __fish_seen_subcommand_from users subscription settings backup" -a "users subscription settings backup"
|
|
11484
|
+
complete -c diafunc -n "__fish_seen_subcommand_from admin; and not __fish_seen_subcommand_from users subscription settings backup curated-tags" -a "users subscription settings backup curated-tags"
|
|
10490
11485
|
|
|
10491
11486
|
# analyze accepts files
|
|
10492
11487
|
complete -c diafunc -n "__fish_seen_subcommand_from analyze" -F`;
|
|
@@ -10510,7 +11505,7 @@ function registerCompletionCommand(program) {
|
|
|
10510
11505
|
}
|
|
10511
11506
|
|
|
10512
11507
|
// src/commands/whoami/index.ts
|
|
10513
|
-
import
|
|
11508
|
+
import chalk33 from "chalk";
|
|
10514
11509
|
function registerWhoamiCommand(program) {
|
|
10515
11510
|
program.command("whoami").description("Show the currently authenticated user").action(async (_options, cmd) => {
|
|
10516
11511
|
try {
|
|
@@ -10520,8 +11515,8 @@ function registerWhoamiCommand(program) {
|
|
|
10520
11515
|
const api = createApiClient();
|
|
10521
11516
|
const user = await api.admin.getMyUser();
|
|
10522
11517
|
if (outputFormat === "human") {
|
|
10523
|
-
console.log(
|
|
10524
|
-
console.log(
|
|
11518
|
+
console.log(chalk33.bold(user.name) + chalk33.dim(` <${user.email}>`));
|
|
11519
|
+
console.log(chalk33.dim(` Role: ${user.role} \xB7 Remaining credits: ${user.remainingCredits} \xB7 Profile: ${config.currentProfile}`));
|
|
10525
11520
|
} else {
|
|
10526
11521
|
format(user, { format: outputFormat });
|
|
10527
11522
|
}
|
|
@@ -10532,8 +11527,8 @@ function registerWhoamiCommand(program) {
|
|
|
10532
11527
|
}
|
|
10533
11528
|
|
|
10534
11529
|
// src/commands/utilization/index.ts
|
|
10535
|
-
import
|
|
10536
|
-
function
|
|
11530
|
+
import chalk34 from "chalk";
|
|
11531
|
+
function getOutputFormat23(cmd) {
|
|
10537
11532
|
const config = loadConfig();
|
|
10538
11533
|
const globalOpts = cmd.optsWithGlobals();
|
|
10539
11534
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -10549,19 +11544,19 @@ function windowLabel(u) {
|
|
|
10549
11544
|
}
|
|
10550
11545
|
function printUtilizationHuman(u, label) {
|
|
10551
11546
|
const when2 = windowLabel(u);
|
|
10552
|
-
console.log(label ?
|
|
11547
|
+
console.log(label ? chalk34.bold(label) + " " + chalk34.dim(when2) : chalk34.bold(when2));
|
|
10553
11548
|
if (u.types.length === 0) {
|
|
10554
|
-
console.log(
|
|
11549
|
+
console.log(chalk34.dim(" (no usage)"));
|
|
10555
11550
|
return;
|
|
10556
11551
|
}
|
|
10557
11552
|
const types = [...u.types].sort((a, b) => b.credits - a.credits);
|
|
10558
11553
|
const width = Math.max(...types.map((t) => t.type.length));
|
|
10559
11554
|
for (const t of types) {
|
|
10560
|
-
const line = ` ${t.type.padEnd(width)} ${formatNumber(t.quantity).padStart(12)} ${
|
|
10561
|
-
console.log(t.credits === 0 ?
|
|
11555
|
+
const line = ` ${t.type.padEnd(width)} ${formatNumber(t.quantity).padStart(12)} ${chalk34.dim("credits")} ${t.credits.toFixed(2).padStart(10)}`;
|
|
11556
|
+
console.log(t.credits === 0 ? chalk34.dim(line) : line);
|
|
10562
11557
|
}
|
|
10563
11558
|
const total = u.totalCredits ?? u.types.reduce((s, t) => s + t.credits, 0);
|
|
10564
|
-
console.log(
|
|
11559
|
+
console.log(chalk34.bold(` ${"Total".padEnd(width)} ${" ".repeat(12)} ${chalk34.dim("credits")} ${total.toFixed(2).padStart(10)}`));
|
|
10565
11560
|
}
|
|
10566
11561
|
function formatDailyHistory(history) {
|
|
10567
11562
|
const spentOn = (u) => u.dailyCredits ?? u.types.reduce((sum, t) => sum + (t.dailyCredits ?? 0), 0);
|
|
@@ -10578,14 +11573,14 @@ function formatDailyHistory(history) {
|
|
|
10578
11573
|
for (const u of history) {
|
|
10579
11574
|
const spent = spentOn(u);
|
|
10580
11575
|
total += spent;
|
|
10581
|
-
const line = `${windowLabel(u).padEnd(width)} ${amount(spent)} ${
|
|
10582
|
-
lines.push(spent > 0 ?
|
|
11576
|
+
const line = `${windowLabel(u).padEnd(width)} ${amount(spent)} ${chalk34.dim("credits")}`;
|
|
11577
|
+
lines.push(spent > 0 ? chalk34.bold(line) : chalk34.dim(line));
|
|
10583
11578
|
for (const t of costly(u)) {
|
|
10584
11579
|
lines.push(` ${t.type.padEnd(width - 2)} ${amount(t.dailyCredits ?? 0)}`);
|
|
10585
11580
|
}
|
|
10586
11581
|
}
|
|
10587
11582
|
lines.push("");
|
|
10588
|
-
lines.push(
|
|
11583
|
+
lines.push(chalk34.bold(`${totalLabel.padEnd(width)} ${amount(total)} ${chalk34.dim("credits")}`));
|
|
10589
11584
|
return lines;
|
|
10590
11585
|
}
|
|
10591
11586
|
function registerUtilizationCommand(program) {
|
|
@@ -10598,7 +11593,7 @@ Examples:
|
|
|
10598
11593
|
`);
|
|
10599
11594
|
util.command("actual", { isDefault: true }).description("Show current utilization (default subcommand)").action(async (_options, cmd) => {
|
|
10600
11595
|
try {
|
|
10601
|
-
const outputFormat =
|
|
11596
|
+
const outputFormat = getOutputFormat23(cmd);
|
|
10602
11597
|
const api = createApiClient();
|
|
10603
11598
|
const utilization = await api.admin.getActualUtilization();
|
|
10604
11599
|
if (outputFormat === "human") {
|
|
@@ -10612,7 +11607,7 @@ Examples:
|
|
|
10612
11607
|
});
|
|
10613
11608
|
util.command("history").description("Show what each day of the billing cycle cost").action(async (_options, cmd) => {
|
|
10614
11609
|
try {
|
|
10615
|
-
const outputFormat =
|
|
11610
|
+
const outputFormat = getOutputFormat23(cmd);
|
|
10616
11611
|
const api = createApiClient();
|
|
10617
11612
|
const history = await api.admin.getUtilizationHistory();
|
|
10618
11613
|
if (outputFormat === "human") {
|
|
@@ -10633,7 +11628,7 @@ Examples:
|
|
|
10633
11628
|
}
|
|
10634
11629
|
|
|
10635
11630
|
// src/commands/entity-branch/index.ts
|
|
10636
|
-
function
|
|
11631
|
+
function getOutputFormat24(cmd) {
|
|
10637
11632
|
const config = loadConfig();
|
|
10638
11633
|
const globalOpts = cmd.optsWithGlobals();
|
|
10639
11634
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -10646,7 +11641,7 @@ function registerEntityBranchCommands(program) {
|
|
|
10646
11641
|
const eb = program.command("entity-branch").description("Manage entity branches (parallel versions of a single entity)");
|
|
10647
11642
|
eb.command("list").description("List branches of an entity").argument("<ref>", "Entity reference (projectId/branch/entityId)").action(async (ref, _options, cmd) => {
|
|
10648
11643
|
try {
|
|
10649
|
-
const outputFormat =
|
|
11644
|
+
const outputFormat = getOutputFormat24(cmd);
|
|
10650
11645
|
const overrides = getOverrides11(cmd);
|
|
10651
11646
|
const resolved = parseEntityReference(ref, overrides);
|
|
10652
11647
|
const api = createApiClient();
|
|
@@ -10698,7 +11693,7 @@ function forReader(subscription) {
|
|
|
10698
11693
|
Object.entries(subscription).filter(([key]) => !BILLING_INTERNALS.has(key))
|
|
10699
11694
|
);
|
|
10700
11695
|
}
|
|
10701
|
-
function
|
|
11696
|
+
function getOutputFormat25(cmd) {
|
|
10702
11697
|
const config = loadConfig();
|
|
10703
11698
|
const globalOpts = cmd.optsWithGlobals();
|
|
10704
11699
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -10712,7 +11707,7 @@ Examples:
|
|
|
10712
11707
|
sub.command("current", { isDefault: true }).description("Show the current subscription").action(async (_options, cmd) => {
|
|
10713
11708
|
try {
|
|
10714
11709
|
const api = createApiClient();
|
|
10715
|
-
const outputFormat =
|
|
11710
|
+
const outputFormat = getOutputFormat25(cmd);
|
|
10716
11711
|
const s = await api.admin.getCurrentSubscription();
|
|
10717
11712
|
format(outputFormat === "human" ? forReader(s) : s, { format: outputFormat });
|
|
10718
11713
|
} catch (error) {
|
|
@@ -10722,7 +11717,7 @@ Examples:
|
|
|
10722
11717
|
sub.command("next").description("Show the next (upcoming) subscription").action(async (_options, cmd) => {
|
|
10723
11718
|
try {
|
|
10724
11719
|
const api = createApiClient();
|
|
10725
|
-
const outputFormat =
|
|
11720
|
+
const outputFormat = getOutputFormat25(cmd);
|
|
10726
11721
|
const s = await api.admin.getNextSubscription();
|
|
10727
11722
|
format(outputFormat === "human" ? forReader(s) : s, { format: outputFormat });
|
|
10728
11723
|
} catch (error) {
|
|
@@ -10733,7 +11728,7 @@ Examples:
|
|
|
10733
11728
|
try {
|
|
10734
11729
|
const api = createApiClient();
|
|
10735
11730
|
const plans = await api.admin.getSubscriptionPlans(subscriptionToken);
|
|
10736
|
-
format(plans, { format:
|
|
11731
|
+
format(plans, { format: getOutputFormat25(cmd) });
|
|
10737
11732
|
} catch (error) {
|
|
10738
11733
|
handleError(error);
|
|
10739
11734
|
}
|
|
@@ -10741,8 +11736,8 @@ Examples:
|
|
|
10741
11736
|
}
|
|
10742
11737
|
|
|
10743
11738
|
// src/commands/invoice/index.ts
|
|
10744
|
-
import * as
|
|
10745
|
-
function
|
|
11739
|
+
import * as fs13 from "fs";
|
|
11740
|
+
function getOutputFormat26(cmd) {
|
|
10746
11741
|
const config = loadConfig();
|
|
10747
11742
|
const globalOpts = cmd.optsWithGlobals();
|
|
10748
11743
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -10759,7 +11754,7 @@ Examples:
|
|
|
10759
11754
|
const api = createApiClient();
|
|
10760
11755
|
const invoices = await api.admin.getInvoices();
|
|
10761
11756
|
format(invoices, {
|
|
10762
|
-
format:
|
|
11757
|
+
format: getOutputFormat26(cmd),
|
|
10763
11758
|
columns: [
|
|
10764
11759
|
{ key: "invoiceNumber", header: "number" },
|
|
10765
11760
|
{ key: "issued", kind: "date" },
|
|
@@ -10779,7 +11774,7 @@ Examples:
|
|
|
10779
11774
|
const response = await api.admin.downloadInvoice(invoiceNumber, fileName);
|
|
10780
11775
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
10781
11776
|
const outPath = options.out ?? fileName;
|
|
10782
|
-
|
|
11777
|
+
fs13.writeFileSync(outPath, buffer);
|
|
10783
11778
|
success(`Invoice saved to ${outPath}`);
|
|
10784
11779
|
} catch (error) {
|
|
10785
11780
|
handleError(error);
|
|
@@ -10788,12 +11783,12 @@ Examples:
|
|
|
10788
11783
|
}
|
|
10789
11784
|
|
|
10790
11785
|
// src/commands/shell/index.ts
|
|
10791
|
-
import
|
|
10792
|
-
import * as
|
|
10793
|
-
import * as
|
|
10794
|
-
import * as
|
|
11786
|
+
import chalk35 from "chalk";
|
|
11787
|
+
import * as fs14 from "fs";
|
|
11788
|
+
import * as os4 from "os";
|
|
11789
|
+
import * as path10 from "path";
|
|
10795
11790
|
import { spawn as spawn3 } from "child_process";
|
|
10796
|
-
import { randomUUID as
|
|
11791
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
10797
11792
|
function extensionFor2(language) {
|
|
10798
11793
|
const l = language.toLowerCase();
|
|
10799
11794
|
if (l === "java") return "java";
|
|
@@ -10804,16 +11799,16 @@ function extensionFor2(language) {
|
|
|
10804
11799
|
return "txt";
|
|
10805
11800
|
}
|
|
10806
11801
|
async function openInEditor(initial, ext) {
|
|
10807
|
-
const tmpFile =
|
|
10808
|
-
|
|
11802
|
+
const tmpFile = path10.join(os4.tmpdir(), `diafunc-shell-${randomUUID4()}.${ext}`);
|
|
11803
|
+
fs14.writeFileSync(tmpFile, initial);
|
|
10809
11804
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
10810
|
-
await new Promise((
|
|
11805
|
+
await new Promise((resolve2, reject) => {
|
|
10811
11806
|
const child = spawn3(editor, [tmpFile], { stdio: "inherit" });
|
|
10812
|
-
child.on("exit", (code) => code === 0 ?
|
|
11807
|
+
child.on("exit", (code) => code === 0 ? resolve2() : reject(new Error(`Editor exited with ${code}`)));
|
|
10813
11808
|
child.on("error", reject);
|
|
10814
11809
|
});
|
|
10815
|
-
const content =
|
|
10816
|
-
|
|
11810
|
+
const content = fs14.readFileSync(tmpFile, "utf-8");
|
|
11811
|
+
fs14.unlinkSync(tmpFile);
|
|
10817
11812
|
return content;
|
|
10818
11813
|
}
|
|
10819
11814
|
function utcNowParts() {
|
|
@@ -10854,21 +11849,21 @@ async function evaluate(api, fnRef, language, sourceCode) {
|
|
|
10854
11849
|
}, false);
|
|
10855
11850
|
if (result.outputs?.length) {
|
|
10856
11851
|
for (const out of result.outputs) {
|
|
10857
|
-
console.log(
|
|
11852
|
+
console.log(chalk35.dim(` [${out.type}]`) + " " + out.output);
|
|
10858
11853
|
}
|
|
10859
11854
|
}
|
|
10860
11855
|
if (result.successful) {
|
|
10861
11856
|
if (result.result) {
|
|
10862
|
-
console.log(
|
|
11857
|
+
console.log(chalk35.green("=>") + " " + resultText(result.result, result.resultEncoding));
|
|
10863
11858
|
} else {
|
|
10864
|
-
console.log(
|
|
11859
|
+
console.log(chalk35.dim("=> (no value)"));
|
|
10865
11860
|
}
|
|
10866
11861
|
const duration = result.completed - result.started;
|
|
10867
|
-
console.log(
|
|
11862
|
+
console.log(chalk35.dim(` [${duration}ms \xB7 ${evaluationId}]`));
|
|
10868
11863
|
} else {
|
|
10869
|
-
console.log(
|
|
11864
|
+
console.log(chalk35.red("error: ") + result.error);
|
|
10870
11865
|
if (result.lineNumber > 0) {
|
|
10871
|
-
console.log(
|
|
11866
|
+
console.log(chalk35.dim(` at line ${result.lineNumber}, col ${result.columnNumber}`));
|
|
10872
11867
|
}
|
|
10873
11868
|
}
|
|
10874
11869
|
}
|
|
@@ -10889,19 +11884,19 @@ function registerShellCommand(program) {
|
|
|
10889
11884
|
});
|
|
10890
11885
|
const api = createApiClient();
|
|
10891
11886
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
10892
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
11887
|
+
const { getUpdateNotice } = await import("./update-check-YRTWCRNY.js");
|
|
10893
11888
|
const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
|
|
10894
|
-
console.log(
|
|
10895
|
-
console.log(
|
|
10896
|
-
console.log(
|
|
11889
|
+
console.log(chalk35.bold("Diafunc shell") + chalk35.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
|
|
11890
|
+
console.log(chalk35.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
11891
|
+
console.log(chalk35.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
|
|
10897
11892
|
const notice = await getUpdateNotice();
|
|
10898
|
-
if (notice) console.log(
|
|
11893
|
+
if (notice) console.log(chalk35.dim(notice));
|
|
10899
11894
|
console.log();
|
|
10900
11895
|
let language = resolvedLanguage;
|
|
10901
11896
|
for (; ; ) {
|
|
10902
11897
|
let line;
|
|
10903
11898
|
try {
|
|
10904
|
-
line = await promptInput({ message:
|
|
11899
|
+
line = await promptInput({ message: chalk35.cyan.bold(`${language} >`) });
|
|
10905
11900
|
} catch {
|
|
10906
11901
|
console.log();
|
|
10907
11902
|
return;
|
|
@@ -10919,54 +11914,54 @@ function registerShellCommand(program) {
|
|
|
10919
11914
|
case "help":
|
|
10920
11915
|
case "h":
|
|
10921
11916
|
case "?":
|
|
10922
|
-
console.log(
|
|
10923
|
-
console.log(
|
|
10924
|
-
console.log(
|
|
10925
|
-
console.log(
|
|
11917
|
+
console.log(chalk35.dim(" /edit open $EDITOR for multi-line code"));
|
|
11918
|
+
console.log(chalk35.dim(" /file <path> evaluate the contents of a file"));
|
|
11919
|
+
console.log(chalk35.dim(" /lang <name> switch language (Java, JavaScript, Kotlin, Python, Scala)"));
|
|
11920
|
+
console.log(chalk35.dim(" /quit exit the shell"));
|
|
10926
11921
|
continue;
|
|
10927
11922
|
case "lang":
|
|
10928
11923
|
if (arg) language = arg;
|
|
10929
|
-
console.log(
|
|
11924
|
+
console.log(chalk35.dim(`Language: ${language}`));
|
|
10930
11925
|
continue;
|
|
10931
11926
|
case "edit": {
|
|
10932
11927
|
const sourceCode = await openInEditor("", extensionFor2(language));
|
|
10933
11928
|
if (!sourceCode.trim()) {
|
|
10934
|
-
console.log(
|
|
11929
|
+
console.log(chalk35.dim("(empty; not evaluated)"));
|
|
10935
11930
|
continue;
|
|
10936
11931
|
}
|
|
10937
11932
|
try {
|
|
10938
11933
|
await evaluate(api, fnRef, language, sourceCode);
|
|
10939
11934
|
} catch (e) {
|
|
10940
|
-
console.error(
|
|
11935
|
+
console.error(chalk35.red(e.message));
|
|
10941
11936
|
}
|
|
10942
11937
|
continue;
|
|
10943
11938
|
}
|
|
10944
11939
|
case "file": {
|
|
10945
11940
|
if (!arg) {
|
|
10946
|
-
console.log(
|
|
11941
|
+
console.log(chalk35.dim("usage: /file <path>"));
|
|
10947
11942
|
continue;
|
|
10948
11943
|
}
|
|
10949
|
-
if (!
|
|
10950
|
-
console.log(
|
|
11944
|
+
if (!fs14.existsSync(arg)) {
|
|
11945
|
+
console.log(chalk35.red(`file not found: ${arg}`));
|
|
10951
11946
|
continue;
|
|
10952
11947
|
}
|
|
10953
|
-
const sourceCode =
|
|
11948
|
+
const sourceCode = fs14.readFileSync(arg, "utf-8");
|
|
10954
11949
|
try {
|
|
10955
11950
|
await evaluate(api, fnRef, language, sourceCode);
|
|
10956
11951
|
} catch (e) {
|
|
10957
|
-
console.error(
|
|
11952
|
+
console.error(chalk35.red(e.message));
|
|
10958
11953
|
}
|
|
10959
11954
|
continue;
|
|
10960
11955
|
}
|
|
10961
11956
|
default:
|
|
10962
|
-
console.log(
|
|
11957
|
+
console.log(chalk35.dim(`Unknown command: /${cmd2}. Try /help.`));
|
|
10963
11958
|
continue;
|
|
10964
11959
|
}
|
|
10965
11960
|
}
|
|
10966
11961
|
try {
|
|
10967
11962
|
await evaluate(api, fnRef, language, trimmed);
|
|
10968
11963
|
} catch (e) {
|
|
10969
|
-
console.error(
|
|
11964
|
+
console.error(chalk35.red(e.message));
|
|
10970
11965
|
}
|
|
10971
11966
|
}
|
|
10972
11967
|
} catch (error) {
|
|
@@ -10976,19 +11971,19 @@ function registerShellCommand(program) {
|
|
|
10976
11971
|
}
|
|
10977
11972
|
|
|
10978
11973
|
// src/commands/update/index.ts
|
|
10979
|
-
import
|
|
10980
|
-
import * as
|
|
11974
|
+
import chalk36 from "chalk";
|
|
11975
|
+
import * as path11 from "path";
|
|
10981
11976
|
import { spawn as spawn4 } from "child_process";
|
|
10982
11977
|
|
|
10983
11978
|
// src/util/install-method.ts
|
|
10984
|
-
import * as
|
|
11979
|
+
import * as fs15 from "fs";
|
|
10985
11980
|
function detectInstall() {
|
|
10986
11981
|
const exec = process.execPath;
|
|
10987
11982
|
const exe = exec.replace(/\\/g, "/").toLowerCase();
|
|
10988
11983
|
const isNode = exe.endsWith("/node") || exe.endsWith("/node.exe");
|
|
10989
11984
|
return {
|
|
10990
11985
|
method: isNode ? "npm" : "binary",
|
|
10991
|
-
binaryPath: isNode ? exec :
|
|
11986
|
+
binaryPath: isNode ? exec : fs15.realpathSync(exec)
|
|
10992
11987
|
};
|
|
10993
11988
|
}
|
|
10994
11989
|
|
|
@@ -11004,7 +11999,7 @@ async function fetchLatestVersion() {
|
|
|
11004
11999
|
return manifest.version;
|
|
11005
12000
|
}
|
|
11006
12001
|
function runInstaller(installDir) {
|
|
11007
|
-
return new Promise((
|
|
12002
|
+
return new Promise((resolve2, reject) => {
|
|
11008
12003
|
const isWindows = process.platform === "win32";
|
|
11009
12004
|
const cmd = isWindows ? "powershell.exe" : "sh";
|
|
11010
12005
|
const args = isWindows ? ["-NoProfile", "-Command", `& { iwr -useb ${WINDOWS_INSTALLER_URL} | iex }`] : ["-c", `curl -fsSL ${POSIX_INSTALLER_URL} | sh`];
|
|
@@ -11012,7 +12007,7 @@ function runInstaller(installDir) {
|
|
|
11012
12007
|
stdio: "inherit",
|
|
11013
12008
|
env: { ...process.env, DIAFUNC_CLI_INSTALL_DIR: installDir }
|
|
11014
12009
|
});
|
|
11015
|
-
child.on("exit", (code) => code === 0 ?
|
|
12010
|
+
child.on("exit", (code) => code === 0 ? resolve2() : reject(new Error(`Installer exited with code ${code}`)));
|
|
11016
12011
|
child.on("error", reject);
|
|
11017
12012
|
});
|
|
11018
12013
|
}
|
|
@@ -11022,17 +12017,17 @@ function registerUpdateCommand(program) {
|
|
|
11022
12017
|
const install = detectInstall();
|
|
11023
12018
|
const latest = await fetchLatestVersion();
|
|
11024
12019
|
if (latest === package_default.version) {
|
|
11025
|
-
console.log(
|
|
12020
|
+
console.log(chalk36.dim(`diafunc is already at the latest version (${package_default.version}).`));
|
|
11026
12021
|
return;
|
|
11027
12022
|
}
|
|
11028
|
-
console.log(
|
|
12023
|
+
console.log(chalk36.dim(`Current: ${package_default.version} \u2192 Available: ${latest}`));
|
|
11029
12024
|
if (install.method === "npm") {
|
|
11030
12025
|
console.log();
|
|
11031
12026
|
console.log("Installed via npm. Upgrade with:");
|
|
11032
|
-
console.log(
|
|
12027
|
+
console.log(chalk36.bold(` npm install -g @diafunc/cli@${latest}`));
|
|
11033
12028
|
return;
|
|
11034
12029
|
}
|
|
11035
|
-
const installDir =
|
|
12030
|
+
const installDir = path11.dirname(install.binaryPath);
|
|
11036
12031
|
console.log(`Installing diafunc ${latest} to ${installDir}...`);
|
|
11037
12032
|
console.log();
|
|
11038
12033
|
await runInstaller(installDir);
|
|
@@ -11043,23 +12038,23 @@ function registerUpdateCommand(program) {
|
|
|
11043
12038
|
}
|
|
11044
12039
|
|
|
11045
12040
|
// src/commands/uninstall/index.ts
|
|
11046
|
-
import
|
|
12041
|
+
import chalk37 from "chalk";
|
|
11047
12042
|
import { spawn as spawn5 } from "child_process";
|
|
11048
|
-
import * as
|
|
11049
|
-
import * as
|
|
11050
|
-
import * as
|
|
12043
|
+
import * as fs16 from "fs";
|
|
12044
|
+
import * as os5 from "os";
|
|
12045
|
+
import * as path12 from "path";
|
|
11051
12046
|
function registerUninstallCommand(program) {
|
|
11052
12047
|
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) => {
|
|
11053
12048
|
try {
|
|
11054
12049
|
const install = detectInstall();
|
|
11055
|
-
const configDir =
|
|
12050
|
+
const configDir = path12.join(os5.homedir(), ".diafunc");
|
|
11056
12051
|
if (install.method === "npm") {
|
|
11057
12052
|
console.log("Installed via npm. Remove with:");
|
|
11058
|
-
console.log(
|
|
11059
|
-
if (
|
|
12053
|
+
console.log(chalk37.bold(" npm uninstall -g @diafunc/cli"));
|
|
12054
|
+
if (fs16.existsSync(configDir)) {
|
|
11060
12055
|
console.log();
|
|
11061
12056
|
console.log(`Config and credentials live at ${configDir}. Remove them manually with:`);
|
|
11062
|
-
console.log(
|
|
12057
|
+
console.log(chalk37.bold(` rm -rf ${configDir}`));
|
|
11063
12058
|
}
|
|
11064
12059
|
return;
|
|
11065
12060
|
}
|
|
@@ -11069,19 +12064,19 @@ function registerUninstallCommand(program) {
|
|
|
11069
12064
|
default: false
|
|
11070
12065
|
});
|
|
11071
12066
|
if (!removeBinary) {
|
|
11072
|
-
console.log(
|
|
12067
|
+
console.log(chalk37.dim("Aborted."));
|
|
11073
12068
|
return;
|
|
11074
12069
|
}
|
|
11075
12070
|
let removeConfig = options.purge ?? false;
|
|
11076
|
-
if (!options.purge && !options.yes &&
|
|
12071
|
+
if (!options.purge && !options.yes && fs16.existsSync(configDir)) {
|
|
11077
12072
|
removeConfig = await confirm({
|
|
11078
12073
|
message: `Also remove ${configDir} (config + credentials)?`,
|
|
11079
12074
|
default: false
|
|
11080
12075
|
});
|
|
11081
12076
|
}
|
|
11082
|
-
if (removeConfig &&
|
|
11083
|
-
|
|
11084
|
-
console.log(
|
|
12077
|
+
if (removeConfig && fs16.existsSync(configDir)) {
|
|
12078
|
+
fs16.rmSync(configDir, { recursive: true, force: true });
|
|
12079
|
+
console.log(chalk37.dim(`Removed ${configDir}`));
|
|
11085
12080
|
}
|
|
11086
12081
|
if (process.platform === "win32") {
|
|
11087
12082
|
const cmd = `timeout /t 2 /nobreak >nul & del /f /q "${install.binaryPath}"`;
|
|
@@ -11091,13 +12086,13 @@ function registerUninstallCommand(program) {
|
|
|
11091
12086
|
windowsHide: true
|
|
11092
12087
|
});
|
|
11093
12088
|
child.unref();
|
|
11094
|
-
console.log(
|
|
12089
|
+
console.log(chalk37.dim(`Removing ${install.binaryPath} on exit...`));
|
|
11095
12090
|
console.log();
|
|
11096
12091
|
console.log("diafunc uninstalled.");
|
|
11097
12092
|
return;
|
|
11098
12093
|
}
|
|
11099
|
-
|
|
11100
|
-
console.log(
|
|
12094
|
+
fs16.rmSync(install.binaryPath, { force: true });
|
|
12095
|
+
console.log(chalk37.dim(`Removed ${install.binaryPath}`));
|
|
11101
12096
|
console.log();
|
|
11102
12097
|
console.log("diafunc uninstalled.");
|
|
11103
12098
|
} catch (error) {
|
|
@@ -11161,7 +12156,7 @@ var DiafuncCommand = class _DiafuncCommand extends Command {
|
|
|
11161
12156
|
};
|
|
11162
12157
|
|
|
11163
12158
|
// src/prompting/fill.ts
|
|
11164
|
-
import
|
|
12159
|
+
import chalk39 from "chalk";
|
|
11165
12160
|
|
|
11166
12161
|
// src/prompting/resolvers.ts
|
|
11167
12162
|
var PROJECT_ROLES = ["OWNER", "ADMIN", "DEVELOPER", "GUEST"];
|
|
@@ -11216,6 +12211,9 @@ var BY_COMMAND = {
|
|
|
11216
12211
|
"notebook export": {
|
|
11217
12212
|
"<notebookIds>": { kind: "entity", form: "id", contentType: "notebook", projectFrom: "project", multiple: true }
|
|
11218
12213
|
},
|
|
12214
|
+
"entity tags set": { "<tags>": TEXT_OR_EMPTY },
|
|
12215
|
+
"project tags set": { "<tags>": TEXT_OR_EMPTY },
|
|
12216
|
+
"admin curated-tags create": { "--display-name": TEXT },
|
|
11219
12217
|
"link delete": { "<linkId>": { kind: "link" } },
|
|
11220
12218
|
"link create": { "<linkId>": TEXT },
|
|
11221
12219
|
"config profile use": { "<name>": { kind: "profile" } },
|
|
@@ -11238,6 +12236,7 @@ var BY_NAME = {
|
|
|
11238
12236
|
teamId: { kind: "team" },
|
|
11239
12237
|
invitationId: { kind: "teamInvitation" },
|
|
11240
12238
|
analysisId: { kind: "analysis" },
|
|
12239
|
+
licenceId: { kind: "licence" },
|
|
11241
12240
|
sessionId: { kind: "chatSession" },
|
|
11242
12241
|
tokenId: { kind: "apiToken" },
|
|
11243
12242
|
resource: { kind: "tokenResource" },
|
|
@@ -11265,6 +12264,8 @@ var BY_NAME = {
|
|
|
11265
12264
|
value: TEXT_OR_EMPTY,
|
|
11266
12265
|
// Free text: names, messages and ids the reader is creating rather than choosing.
|
|
11267
12266
|
name: TEXT,
|
|
12267
|
+
tag: TEXT,
|
|
12268
|
+
tags: TEXT,
|
|
11268
12269
|
newId: TEXT,
|
|
11269
12270
|
message: TEXT,
|
|
11270
12271
|
query: TEXT,
|
|
@@ -11286,11 +12287,11 @@ var BY_NAME = {
|
|
|
11286
12287
|
function tokenOf(input) {
|
|
11287
12288
|
return input.kind === "option" ? input.flag ?? `--${input.name}` : `<${input.name}>`;
|
|
11288
12289
|
}
|
|
11289
|
-
function specFor(
|
|
11290
|
-
const exact = BY_COMMAND[
|
|
12290
|
+
function specFor(path13, input) {
|
|
12291
|
+
const exact = BY_COMMAND[path13]?.[tokenOf(input)];
|
|
11291
12292
|
if (exact) return exact;
|
|
11292
|
-
const group =
|
|
11293
|
-
const sub =
|
|
12293
|
+
const group = path13.split(" ")[0];
|
|
12294
|
+
const sub = path13.split(" ").slice(0, 2).join(" ");
|
|
11294
12295
|
switch (input.name) {
|
|
11295
12296
|
case "ref":
|
|
11296
12297
|
case "sourceRef":
|
|
@@ -11357,8 +12358,8 @@ function dependencies(spec) {
|
|
|
11357
12358
|
}
|
|
11358
12359
|
|
|
11359
12360
|
// src/prompting/pickers.ts
|
|
11360
|
-
import * as
|
|
11361
|
-
import
|
|
12361
|
+
import * as fs17 from "fs";
|
|
12362
|
+
import chalk38 from "chalk";
|
|
11362
12363
|
var SEARCH_THRESHOLD = 10;
|
|
11363
12364
|
var TYPE_IT = "\0type-it";
|
|
11364
12365
|
async function askFor(spec, input, ctx) {
|
|
@@ -11480,6 +12481,8 @@ async function askFor(spec, input, ctx) {
|
|
|
11480
12481
|
return listed(ctx, "profiles", messageFor(input, "Profile"), async () => Object.keys(loadConfig().profiles).map((p) => ({ label: p, value: p })));
|
|
11481
12482
|
case "statusComponent":
|
|
11482
12483
|
return listed(ctx, "components", messageFor(input, "Component"), async () => (await createStatusService().getComponents()).map((c) => ({ label: c.id, value: c.id, hint: `${c.state} \xB7 ${c.domainId}` })));
|
|
12484
|
+
case "licence":
|
|
12485
|
+
return listed(ctx, "licences", messageFor(input, "Licence"), async () => (await ctx.api().admin.listLicences()).map((l) => ({ label: l.name, value: l.licenceId, hint: `${l.state.toLowerCase()} \xB7 ${l.licenceId}` })));
|
|
11483
12486
|
case "choice":
|
|
11484
12487
|
return choose(ctx, question(input), spec.choices.map((c) => ({ label: c, value: c })));
|
|
11485
12488
|
case "choices": {
|
|
@@ -11492,7 +12495,7 @@ async function askFor(spec, input, ctx) {
|
|
|
11492
12495
|
}
|
|
11493
12496
|
case "file":
|
|
11494
12497
|
return typed(ctx, question(input), {
|
|
11495
|
-
validate: (value) =>
|
|
12498
|
+
validate: (value) => fs17.existsSync(value.trim()) || `No file at ${value.trim()}.`
|
|
11496
12499
|
});
|
|
11497
12500
|
case "number":
|
|
11498
12501
|
return typed(ctx, question(input), { validate: numberRule(spec) });
|
|
@@ -11706,7 +12709,7 @@ function typedValue(ctx, message) {
|
|
|
11706
12709
|
return typed(ctx, message);
|
|
11707
12710
|
}
|
|
11708
12711
|
function typeItChoice() {
|
|
11709
|
-
return { name:
|
|
12712
|
+
return { name: chalk38.dim("Type it instead"), value: TYPE_IT };
|
|
11710
12713
|
}
|
|
11711
12714
|
function text(ctx, name) {
|
|
11712
12715
|
const value = ctx.known.get(name);
|
|
@@ -11736,7 +12739,7 @@ function capitalize(value) {
|
|
|
11736
12739
|
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
11737
12740
|
}
|
|
11738
12741
|
function labelled(label, hint2) {
|
|
11739
|
-
return hint2 && hint2 !== label ? `${label} ${
|
|
12742
|
+
return hint2 && hint2 !== label ? `${label} ${chalk38.dim(hint2)}` : label;
|
|
11740
12743
|
}
|
|
11741
12744
|
function numberRule(spec) {
|
|
11742
12745
|
return (raw) => {
|
|
@@ -11782,7 +12785,7 @@ async function fillPendingInputs(actionCommand) {
|
|
|
11782
12785
|
known: knownValues(actionCommand),
|
|
11783
12786
|
globals: actionCommand.optsWithGlobals(),
|
|
11784
12787
|
prefill: /* @__PURE__ */ new Map(),
|
|
11785
|
-
note: (line) => process.stderr.write(
|
|
12788
|
+
note: (line) => process.stderr.write(chalk39.dim(` ${line}
|
|
11786
12789
|
`))
|
|
11787
12790
|
};
|
|
11788
12791
|
for (const item of orderByDependencies(pending)) {
|
|
@@ -11791,7 +12794,7 @@ async function fillPendingInputs(actionCommand) {
|
|
|
11791
12794
|
ctx.known.set(item.input.name, value);
|
|
11792
12795
|
}
|
|
11793
12796
|
const log = env.log ?? ((line) => console.log(line));
|
|
11794
|
-
log(
|
|
12797
|
+
log(chalk39.dim(` Equivalent: ${equivalentCommand(actionCommand)}`));
|
|
11795
12798
|
}
|
|
11796
12799
|
function commandChain(cmd) {
|
|
11797
12800
|
const chain = [];
|
|
@@ -11896,7 +12899,7 @@ function createProgram(environment = {}) {
|
|
|
11896
12899
|
const opts = thisCommand.optsWithGlobals();
|
|
11897
12900
|
if (opts.dryRun) setDryRun(true);
|
|
11898
12901
|
if (opts.verbose) setVerbose(true);
|
|
11899
|
-
if (opts.color === false)
|
|
12902
|
+
if (opts.color === false) chalk40.level = 0;
|
|
11900
12903
|
}).hook("preAction", (_thisCommand, actionCommand) => fillPendingInputs(actionCommand));
|
|
11901
12904
|
program.addHelpText("after", HELP_EPILOGUE);
|
|
11902
12905
|
registerAuthCommands(program);
|
|
@@ -11918,6 +12921,7 @@ function createProgram(environment = {}) {
|
|
|
11918
12921
|
registerStatusCommands(program);
|
|
11919
12922
|
registerAnalyzeCommand(program);
|
|
11920
12923
|
registerPublicCommands(program);
|
|
12924
|
+
registerLicenceCommands(program);
|
|
11921
12925
|
registerDataSourcesCommands(program);
|
|
11922
12926
|
registerTableExportersCommands(program);
|
|
11923
12927
|
registerSkeletonCommands(program);
|
|
@@ -11939,4 +12943,4 @@ export {
|
|
|
11939
12943
|
PromptCancelled,
|
|
11940
12944
|
createProgram
|
|
11941
12945
|
};
|
|
11942
|
-
//# sourceMappingURL=chunk-
|
|
12946
|
+
//# sourceMappingURL=chunk-HYUMMSA2.js.map
|