@diafunc/cli 0.25.0 → 0.26.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 +9 -3
- package/dist/bin/diafunc.js +3 -3
- package/dist/{chunk-DOVJKPLM.js → chunk-EJ2LNAYV.js} +2 -2
- package/dist/{chunk-DOVJKPLM.js.map → chunk-EJ2LNAYV.js.map} +1 -1
- package/dist/{chunk-RJM7OBRF.js → chunk-Q5GOPNYM.js} +1323 -542
- package/dist/chunk-Q5GOPNYM.js.map +1 -0
- package/dist/{chunk-2RII4SNX.js → chunk-RSOGVUUU.js} +2 -2
- package/dist/src/index.js +2 -2
- package/dist/update-check-4345HWGE.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-RSOGVUUU.js.map} +0 -0
- /package/dist/{update-check-F2A6LMK6.js.map → update-check-4345HWGE.js.map} +0 -0
|
@@ -1,19 +1,182 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EJ2LNAYV.js";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
|
-
import
|
|
6
|
+
import chalk39 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;
|
|
@@ -119,13 +320,207 @@ var NetworkError = class extends Error {
|
|
|
119
320
|
}
|
|
120
321
|
};
|
|
121
322
|
|
|
323
|
+
// src/client/sign-in.ts
|
|
324
|
+
import * as crypto3 from "crypto";
|
|
325
|
+
import * as fs3 from "fs";
|
|
326
|
+
var EXPIRY_MARGIN_MS = 3e4;
|
|
327
|
+
var TOKEN_REQUEST_TIMEOUT_MS = 1e4;
|
|
328
|
+
var MAX_RATE_LIMITED_ATTEMPTS = 3;
|
|
329
|
+
var DEFAULT_BACKOFF_MS = 5e3;
|
|
330
|
+
var MIN_BACKOFF_MS = 1e3;
|
|
331
|
+
var MAX_BACKOFF_MS = 12e4;
|
|
332
|
+
var NOTICE_THRESHOLD_MS = 2e3;
|
|
333
|
+
var SignInRefusedError = class extends ApiError {
|
|
334
|
+
constructor(profileName) {
|
|
335
|
+
super(401, `The stored sign-in of profile "${profileName}" is no longer accepted. Run 'diafunc auth login' to sign in again.`);
|
|
336
|
+
this.name = "SignInRefusedError";
|
|
337
|
+
}
|
|
338
|
+
toUserMessage() {
|
|
339
|
+
return this.message;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
function isAuthenticationFailure(error) {
|
|
343
|
+
return error instanceof ApiError && error.status === 401;
|
|
344
|
+
}
|
|
345
|
+
function isTokenExpired(auth) {
|
|
346
|
+
if (!auth) return false;
|
|
347
|
+
if (auth.type === "device-code") {
|
|
348
|
+
return Date.now() >= auth.accessTokenExpiry - EXPIRY_MARGIN_MS;
|
|
349
|
+
}
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
function deriveAuthUrl(endpoint) {
|
|
353
|
+
const trimmed = endpoint.replace(/\/+$/, "");
|
|
354
|
+
if (trimmed.includes("://auth.")) {
|
|
355
|
+
return trimmed;
|
|
356
|
+
}
|
|
357
|
+
const url = new URL(trimmed);
|
|
358
|
+
url.hostname = `auth.${url.hostname}`;
|
|
359
|
+
url.pathname = "";
|
|
360
|
+
return url.toString().replace(/\/+$/, "");
|
|
361
|
+
}
|
|
362
|
+
function digestOf(token) {
|
|
363
|
+
return crypto3.createHash("sha256").update(token).digest("hex");
|
|
364
|
+
}
|
|
365
|
+
function retryAfterMs(header, now = Date.now()) {
|
|
366
|
+
let wait = DEFAULT_BACKOFF_MS;
|
|
367
|
+
if (header) {
|
|
368
|
+
const seconds = Number(header.trim());
|
|
369
|
+
if (Number.isFinite(seconds)) {
|
|
370
|
+
wait = seconds * 1e3;
|
|
371
|
+
} else {
|
|
372
|
+
const at = Date.parse(header);
|
|
373
|
+
if (Number.isFinite(at)) wait = at - now;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return Math.min(MAX_BACKOFF_MS, Math.max(MIN_BACKOFF_MS, wait));
|
|
377
|
+
}
|
|
378
|
+
function createSignInRefresher(options = {}) {
|
|
379
|
+
const sleep4 = options.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
|
|
380
|
+
const notify = options.notify ?? ((message) => console.error(message));
|
|
381
|
+
const lockOptions = { waitMs: options.lockWaitMs, staleMs: options.lockStaleMs };
|
|
382
|
+
const inFlight = /* @__PURE__ */ new Map();
|
|
383
|
+
const notBefore = /* @__PURE__ */ new Map();
|
|
384
|
+
const refused = /* @__PURE__ */ new Set();
|
|
385
|
+
function refusedMarkerFile(profileName) {
|
|
386
|
+
return profileSidecarFile(profileName, "refused");
|
|
387
|
+
}
|
|
388
|
+
function isKnownRefused(profileName, refreshToken) {
|
|
389
|
+
const digest = digestOf(refreshToken);
|
|
390
|
+
if (refused.has(digest)) return true;
|
|
391
|
+
try {
|
|
392
|
+
return fs3.readFileSync(refusedMarkerFile(profileName), "utf-8").trim() === digest;
|
|
393
|
+
} catch {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function rememberRefused(profileName, refreshToken, acrossProcesses) {
|
|
398
|
+
const digest = digestOf(refreshToken);
|
|
399
|
+
refused.add(digest);
|
|
400
|
+
if (!acrossProcesses) return;
|
|
401
|
+
try {
|
|
402
|
+
fs3.writeFileSync(refusedMarkerFile(profileName), digest + "\n", { encoding: "utf-8", mode: 384 });
|
|
403
|
+
} catch {
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function forgetRefused(profileName) {
|
|
407
|
+
fs3.rmSync(refusedMarkerFile(profileName), { force: true });
|
|
408
|
+
}
|
|
409
|
+
async function requestTokens(endpoint, auth) {
|
|
410
|
+
try {
|
|
411
|
+
return await fetch(`${deriveAuthUrl(endpoint)}/token`, {
|
|
412
|
+
method: "POST",
|
|
413
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
414
|
+
body: new URLSearchParams({
|
|
415
|
+
grant_type: "refresh_token",
|
|
416
|
+
refresh_token: auth.refreshToken,
|
|
417
|
+
client_id: auth.clientId
|
|
418
|
+
}).toString(),
|
|
419
|
+
signal: AbortSignal.timeout(TOKEN_REQUEST_TIMEOUT_MS)
|
|
420
|
+
});
|
|
421
|
+
} catch (error) {
|
|
422
|
+
throw new NetworkError(
|
|
423
|
+
`Could not reach the sign-in service of ${endpoint} to renew the sign-in.`,
|
|
424
|
+
error instanceof Error ? error : void 0
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
async function renewUnderLock(profileName) {
|
|
429
|
+
const profile = readStoredProfile(profileName);
|
|
430
|
+
const stored = profile?.auth;
|
|
431
|
+
if (!profile || !stored) {
|
|
432
|
+
throw new SignInRefusedError(profileName);
|
|
433
|
+
}
|
|
434
|
+
if (stored.type !== "device-code" || !isTokenExpired(stored)) {
|
|
435
|
+
return { kind: "credentials", auth: stored };
|
|
436
|
+
}
|
|
437
|
+
if (isKnownRefused(profileName, stored.refreshToken)) {
|
|
438
|
+
throw new SignInRefusedError(profileName);
|
|
439
|
+
}
|
|
440
|
+
let response;
|
|
441
|
+
try {
|
|
442
|
+
response = await requestTokens(profile.endpoint.replace(/\/+$/, ""), stored);
|
|
443
|
+
} catch (error) {
|
|
444
|
+
notBefore.set(profileName, Date.now() + DEFAULT_BACKOFF_MS);
|
|
445
|
+
throw error;
|
|
446
|
+
}
|
|
447
|
+
if (response.ok) {
|
|
448
|
+
const body = await response.json();
|
|
449
|
+
const renewed = {
|
|
450
|
+
type: "device-code",
|
|
451
|
+
clientId: stored.clientId,
|
|
452
|
+
accessToken: body.access_token,
|
|
453
|
+
refreshToken: body.refresh_token ?? stored.refreshToken,
|
|
454
|
+
accessTokenExpiry: Date.now() + body.expires_in * 1e3
|
|
455
|
+
};
|
|
456
|
+
await updateStoredProfile(profileName, (target) => {
|
|
457
|
+
target.auth = renewed;
|
|
458
|
+
});
|
|
459
|
+
forgetRefused(profileName);
|
|
460
|
+
return { kind: "credentials", auth: renewed };
|
|
461
|
+
}
|
|
462
|
+
if (response.status === 429) {
|
|
463
|
+
return { kind: "rate-limited", retryAfterMs: retryAfterMs(response.headers.get("retry-after")) };
|
|
464
|
+
}
|
|
465
|
+
if (response.status === 400 || response.status === 401) {
|
|
466
|
+
const reason2 = await response.json().then((body) => body.error, () => void 0);
|
|
467
|
+
const current = readStoredProfile(profileName)?.auth;
|
|
468
|
+
if (current && (current.type !== "device-code" || current.refreshToken !== stored.refreshToken)) {
|
|
469
|
+
return { kind: "credentials", auth: current };
|
|
470
|
+
}
|
|
471
|
+
rememberRefused(profileName, stored.refreshToken, reason2 === "invalid_grant");
|
|
472
|
+
throw new SignInRefusedError(profileName);
|
|
473
|
+
}
|
|
474
|
+
notBefore.set(profileName, Date.now() + DEFAULT_BACKOFF_MS);
|
|
475
|
+
throw new ApiError(response.status, `The sign-in service answered ${response.status} while renewing the sign-in.`);
|
|
476
|
+
}
|
|
477
|
+
async function waitOutBackoff(profileName) {
|
|
478
|
+
const wait = (notBefore.get(profileName) ?? 0) - Date.now();
|
|
479
|
+
if (wait <= 0) return;
|
|
480
|
+
if (wait >= NOTICE_THRESHOLD_MS) {
|
|
481
|
+
notify(`The sign-in service asked to wait; renewing the sign-in in ${Math.ceil(wait / 1e3)} s.`);
|
|
482
|
+
}
|
|
483
|
+
await sleep4(wait + Math.floor(Math.random() * 250));
|
|
484
|
+
}
|
|
485
|
+
async function renew(profileName) {
|
|
486
|
+
for (let attempt = 1; ; attempt++) {
|
|
487
|
+
await waitOutBackoff(profileName);
|
|
488
|
+
let outcome;
|
|
489
|
+
try {
|
|
490
|
+
outcome = await withFileLock(profileSidecarFile(profileName, "refresh.lock"), () => renewUnderLock(profileName), lockOptions);
|
|
491
|
+
} catch (error) {
|
|
492
|
+
if (!(error instanceof LockTimeoutError)) throw error;
|
|
493
|
+
const stored = readStoredProfile(profileName)?.auth;
|
|
494
|
+
if (stored && !isTokenExpired(stored)) return stored;
|
|
495
|
+
throw new NetworkError("Another diafunc process is still renewing the sign-in of this profile. Try again in a moment.");
|
|
496
|
+
}
|
|
497
|
+
if (outcome.kind === "credentials") return outcome.auth;
|
|
498
|
+
notBefore.set(profileName, Date.now() + outcome.retryAfterMs);
|
|
499
|
+
if (attempt >= MAX_RATE_LIMITED_ATTEMPTS) {
|
|
500
|
+
throw new ApiError(429, `The sign-in service is limiting requests from this address. Try again in ${Math.ceil(outcome.retryAfterMs / 1e3)} s.`);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return {
|
|
505
|
+
ensureFresh(profileName) {
|
|
506
|
+
let pending = inFlight.get(profileName);
|
|
507
|
+
if (!pending) {
|
|
508
|
+
pending = renew(profileName).finally(() => inFlight.delete(profileName));
|
|
509
|
+
inFlight.set(profileName, pending);
|
|
510
|
+
}
|
|
511
|
+
return pending;
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
var sharedSignIn = createSignInRefresher();
|
|
516
|
+
|
|
122
517
|
// src/client/http.ts
|
|
123
518
|
var REQUEST_TIMEOUT_MS = 6e4;
|
|
124
519
|
var RETRYABLE_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
125
520
|
var MAX_ATTEMPTS = 3;
|
|
126
521
|
var RETRYABLE_METHODS = /* @__PURE__ */ new Set(["GET"]);
|
|
127
|
-
function buildUrl(endpoint, service,
|
|
128
|
-
const base = `${endpoint}/api/v1/${service}${
|
|
522
|
+
function buildUrl(endpoint, service, path13, query) {
|
|
523
|
+
const base = `${endpoint}/api/v1/${service}${path13}`;
|
|
129
524
|
const params = new URLSearchParams();
|
|
130
525
|
if (query) {
|
|
131
526
|
for (const [key, value] of Object.entries(query)) {
|
|
@@ -147,62 +542,12 @@ function getAuthHeader(auth) {
|
|
|
147
542
|
}
|
|
148
543
|
return void 0;
|
|
149
544
|
}
|
|
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
545
|
async function ensureValidAuth(config, profileOverride) {
|
|
189
546
|
const profileName = profileOverride ?? config.currentProfile;
|
|
190
547
|
const profile = config.profiles[profileName];
|
|
191
548
|
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);
|
|
549
|
+
if (profile.auth.type === "device-code" && isTokenExpired(profile.auth)) {
|
|
550
|
+
profile.auth = await sharedSignIn.ensureFresh(profileName);
|
|
206
551
|
}
|
|
207
552
|
return profile.auth;
|
|
208
553
|
}
|
|
@@ -315,7 +660,7 @@ ${bodyPreview}`));
|
|
|
315
660
|
);
|
|
316
661
|
}
|
|
317
662
|
function delay(ms) {
|
|
318
|
-
return new Promise((
|
|
663
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
319
664
|
}
|
|
320
665
|
return {
|
|
321
666
|
async request(opts) {
|
|
@@ -866,7 +1211,7 @@ function handleError(error) {
|
|
|
866
1211
|
}
|
|
867
1212
|
if (error instanceof ApiError) {
|
|
868
1213
|
failure(error.toUserMessage());
|
|
869
|
-
if (error.status === 401) hint(`Run 'diafunc auth login' to sign in.`);
|
|
1214
|
+
if (error.status === 401 && !(error instanceof SignInRefusedError)) hint(`Run 'diafunc auth login' to sign in.`);
|
|
870
1215
|
if (error.status === 404) hint(`Check the id, or list what exists with the matching 'list' command.`);
|
|
871
1216
|
process.exit(error.status === 401 || error.status === 403 ? EXIT_AUTH : EXIT_FAILURE);
|
|
872
1217
|
}
|
|
@@ -912,7 +1257,7 @@ function registerLoginCommand(parent) {
|
|
|
912
1257
|
}
|
|
913
1258
|
if (options.token) {
|
|
914
1259
|
profile.auth = { type: "api-token", token: options.token };
|
|
915
|
-
|
|
1260
|
+
await storeSignIn(config.currentProfile, profile);
|
|
916
1261
|
const client = createHttpClient();
|
|
917
1262
|
const admin = createAdminService(client);
|
|
918
1263
|
const user = await admin.getMyUser();
|
|
@@ -929,6 +1274,12 @@ function registerLoginCommand(parent) {
|
|
|
929
1274
|
}
|
|
930
1275
|
});
|
|
931
1276
|
}
|
|
1277
|
+
async function storeSignIn(profileName, signedIn) {
|
|
1278
|
+
await updateStoredProfile(profileName, (stored) => {
|
|
1279
|
+
stored.endpoint = signedIn.endpoint;
|
|
1280
|
+
stored.auth = signedIn.auth;
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
932
1283
|
async function deviceCodeLogin(config, profile) {
|
|
933
1284
|
const authUrl = deriveAuthUrl2(profile.endpoint);
|
|
934
1285
|
const deviceResponse = await fetch(`${authUrl}/device_authorization`, {
|
|
@@ -972,7 +1323,7 @@ async function deviceCodeLogin(config, profile) {
|
|
|
972
1323
|
refreshToken: tokens.refresh_token,
|
|
973
1324
|
accessTokenExpiry: Date.now() + (tokens.expires_in || ACCESS_TOKEN_LIFETIME_SECONDS) * 1e3
|
|
974
1325
|
};
|
|
975
|
-
|
|
1326
|
+
await storeSignIn(config.currentProfile, profile);
|
|
976
1327
|
const client = createHttpClient();
|
|
977
1328
|
const admin = createAdminService(client);
|
|
978
1329
|
const user = await admin.getMyUser();
|
|
@@ -1002,7 +1353,7 @@ async function deviceCodeLogin(config, profile) {
|
|
|
1002
1353
|
process.exit(1);
|
|
1003
1354
|
}
|
|
1004
1355
|
function sleep(ms) {
|
|
1005
|
-
return new Promise((
|
|
1356
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
1006
1357
|
}
|
|
1007
1358
|
|
|
1008
1359
|
// src/commands/auth/logout.ts
|
|
@@ -1043,8 +1394,9 @@ function registerLogoutCommand(parent) {
|
|
|
1043
1394
|
} catch {
|
|
1044
1395
|
}
|
|
1045
1396
|
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1397
|
+
await updateStoredProfile(config.currentProfile, (stored) => {
|
|
1398
|
+
delete stored.auth;
|
|
1399
|
+
});
|
|
1048
1400
|
success(`Logged out from profile "${config.currentProfile}".`);
|
|
1049
1401
|
});
|
|
1050
1402
|
}
|
|
@@ -2008,6 +2360,33 @@ function createStorageService(client) {
|
|
|
2008
2360
|
path: `/entities/revert${entityPath(ref)}/${version}`
|
|
2009
2361
|
});
|
|
2010
2362
|
},
|
|
2363
|
+
/**
|
|
2364
|
+
* Adds tags to an entity and takes others off, in one storage transaction. The platform applies
|
|
2365
|
+
* the removals, then the additions, and counts a tag that is already there (or already gone) as
|
|
2366
|
+
* nothing to do; nothing else of the entity is touched.
|
|
2367
|
+
*
|
|
2368
|
+
* A transaction writes an entity that does not exist yet, so a caller that means to change an
|
|
2369
|
+
* existing one reads it first.
|
|
2370
|
+
*/
|
|
2371
|
+
async changeEntityTags(ref, change2) {
|
|
2372
|
+
const transaction = {
|
|
2373
|
+
projectId: ref.projectId,
|
|
2374
|
+
projectBranch: ref.projectBranch,
|
|
2375
|
+
consistency: "WEAK",
|
|
2376
|
+
entityDeltas: {
|
|
2377
|
+
[`${ref.entityId}/${ref.entityBranch}`]: {
|
|
2378
|
+
...change2.addTags?.length ? { addTags: change2.addTags } : {},
|
|
2379
|
+
...change2.removeTags?.length ? { removeTags: change2.removeTags } : {}
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
};
|
|
2383
|
+
return client.request({
|
|
2384
|
+
method: "POST",
|
|
2385
|
+
service: SERVICE3,
|
|
2386
|
+
path: "/transactions/",
|
|
2387
|
+
body: transaction
|
|
2388
|
+
});
|
|
2389
|
+
},
|
|
2011
2390
|
// --- Entity Sets ---
|
|
2012
2391
|
async searchEntityIds(projectId, projectBranch, body) {
|
|
2013
2392
|
return client.request({
|
|
@@ -2058,14 +2437,14 @@ function createStorageService(client) {
|
|
|
2058
2437
|
});
|
|
2059
2438
|
},
|
|
2060
2439
|
async deleteLink(projectId, projectBranch, sourceEntityId, sourceEntityBranch, linkId, targetEntityId, targetEntityBranch) {
|
|
2061
|
-
let
|
|
2440
|
+
let path13 = `/links/actual/${enc(projectId)}/${enc(projectBranch)}/${enc(sourceEntityId)}/${enc(sourceEntityBranch)}/${enc(linkId)}`;
|
|
2062
2441
|
if (targetEntityId && targetEntityBranch) {
|
|
2063
|
-
|
|
2442
|
+
path13 += `/${enc(targetEntityId)}/${enc(targetEntityBranch)}`;
|
|
2064
2443
|
}
|
|
2065
2444
|
return client.request({
|
|
2066
2445
|
method: "DELETE",
|
|
2067
2446
|
service: SERVICE3,
|
|
2068
|
-
path:
|
|
2447
|
+
path: path13
|
|
2069
2448
|
});
|
|
2070
2449
|
},
|
|
2071
2450
|
// --- Events ---
|
|
@@ -2862,6 +3241,44 @@ function createIndexService(client) {
|
|
|
2862
3241
|
}
|
|
2863
3242
|
});
|
|
2864
3243
|
},
|
|
3244
|
+
/**
|
|
3245
|
+
* The curated tags in their order. Public: no account is needed. With `counts` each also says
|
|
3246
|
+
* how many public projects carry it.
|
|
3247
|
+
*/
|
|
3248
|
+
async getCuratedTags(counts = false) {
|
|
3249
|
+
return client.request({
|
|
3250
|
+
method: "GET",
|
|
3251
|
+
service: SERVICE7,
|
|
3252
|
+
path: "/tags/curated",
|
|
3253
|
+
query: counts ? { counts: true } : void 0
|
|
3254
|
+
});
|
|
3255
|
+
},
|
|
3256
|
+
/** Administrators only. The platform stores the tag in its canonical form. */
|
|
3257
|
+
async createCuratedTag(request) {
|
|
3258
|
+
return client.request({
|
|
3259
|
+
method: "POST",
|
|
3260
|
+
service: SERVICE7,
|
|
3261
|
+
path: "/admin/curated-tags",
|
|
3262
|
+
body: request
|
|
3263
|
+
});
|
|
3264
|
+
},
|
|
3265
|
+
/** Administrators only. A field left out of the request keeps what is stored. */
|
|
3266
|
+
async updateCuratedTag(tag, request) {
|
|
3267
|
+
return client.request({
|
|
3268
|
+
method: "PUT",
|
|
3269
|
+
service: SERVICE7,
|
|
3270
|
+
path: `/admin/curated-tags/${enc5(tag)}`,
|
|
3271
|
+
body: request
|
|
3272
|
+
});
|
|
3273
|
+
},
|
|
3274
|
+
/** Administrators only. Projects that carry the tag keep it; it only stops being curated. */
|
|
3275
|
+
async deleteCuratedTag(tag) {
|
|
3276
|
+
return client.request({
|
|
3277
|
+
method: "DELETE",
|
|
3278
|
+
service: SERVICE7,
|
|
3279
|
+
path: `/admin/curated-tags/${enc5(tag)}`
|
|
3280
|
+
});
|
|
3281
|
+
},
|
|
2865
3282
|
async rebuildAll() {
|
|
2866
3283
|
return client.request({
|
|
2867
3284
|
method: "POST",
|
|
@@ -3102,8 +3519,8 @@ Examples:
|
|
|
3102
3519
|
success(`Profile "${name}" removed.`);
|
|
3103
3520
|
});
|
|
3104
3521
|
}
|
|
3105
|
-
function setNestedValue(obj,
|
|
3106
|
-
const keys =
|
|
3522
|
+
function setNestedValue(obj, path13, value) {
|
|
3523
|
+
const keys = path13.split(".");
|
|
3107
3524
|
let current = obj;
|
|
3108
3525
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
3109
3526
|
const key = keys[i];
|
|
@@ -3114,8 +3531,8 @@ function setNestedValue(obj, path12, value) {
|
|
|
3114
3531
|
}
|
|
3115
3532
|
current[keys[keys.length - 1]] = value;
|
|
3116
3533
|
}
|
|
3117
|
-
function getNestedValue(obj,
|
|
3118
|
-
const keys =
|
|
3534
|
+
function getNestedValue(obj, path13) {
|
|
3535
|
+
const keys = path13.split(".");
|
|
3119
3536
|
let current = obj;
|
|
3120
3537
|
for (const key of keys) {
|
|
3121
3538
|
if (current === null || current === void 0 || typeof current !== "object") {
|
|
@@ -3127,7 +3544,7 @@ function getNestedValue(obj, path12) {
|
|
|
3127
3544
|
}
|
|
3128
3545
|
|
|
3129
3546
|
// src/commands/project/index.ts
|
|
3130
|
-
import
|
|
3547
|
+
import chalk13 from "chalk";
|
|
3131
3548
|
|
|
3132
3549
|
// src/util/references.ts
|
|
3133
3550
|
function parseEntityReference(ref, overrides) {
|
|
@@ -3213,8 +3630,8 @@ function parseProjectReference(ref, overrides) {
|
|
|
3213
3630
|
|
|
3214
3631
|
// src/commands/bundle-helpers.ts
|
|
3215
3632
|
import chalk11 from "chalk";
|
|
3216
|
-
import * as
|
|
3217
|
-
import * as
|
|
3633
|
+
import * as fs4 from "fs";
|
|
3634
|
+
import * as path3 from "path";
|
|
3218
3635
|
|
|
3219
3636
|
// src/output/progress.ts
|
|
3220
3637
|
import chalk10 from "chalk";
|
|
@@ -3344,7 +3761,7 @@ function shift(value, exponent) {
|
|
|
3344
3761
|
// src/commands/bundle-helpers.ts
|
|
3345
3762
|
async function streamResponseToFile(response, outFile) {
|
|
3346
3763
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
3347
|
-
|
|
3764
|
+
fs4.writeFileSync(outFile, buffer);
|
|
3348
3765
|
return buffer.length;
|
|
3349
3766
|
}
|
|
3350
3767
|
function printLossiness(notes) {
|
|
@@ -3395,10 +3812,10 @@ function printImportResult(result) {
|
|
|
3395
3812
|
printLossiness(result.lossinessNotes);
|
|
3396
3813
|
}
|
|
3397
3814
|
async function runBundleImport(storage, projectId, projectBranch, file, options, outputFormat) {
|
|
3398
|
-
const fileBuffer =
|
|
3815
|
+
const fileBuffer = fs4.readFileSync(file);
|
|
3399
3816
|
const blob = new Blob([fileBuffer]);
|
|
3400
3817
|
const formData = new FormData();
|
|
3401
|
-
formData.append("content", blob,
|
|
3818
|
+
formData.append("content", blob, path3.basename(file));
|
|
3402
3819
|
if (options.preview) {
|
|
3403
3820
|
const preview = await storage.previewBundleImport(projectId, projectBranch, formData);
|
|
3404
3821
|
if (outputFormat === "json") {
|
|
@@ -3415,7 +3832,7 @@ async function runBundleImport(storage, projectId, projectBranch, file, options,
|
|
|
3415
3832
|
}
|
|
3416
3833
|
printImportResult(result);
|
|
3417
3834
|
}
|
|
3418
|
-
var sleep2 = (ms) => new Promise((
|
|
3835
|
+
var sleep2 = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
3419
3836
|
async function pollUntilFinished(storage, projectId, projectBranch, bundleId, intervalMs = 2e3, maxAttempts = 150) {
|
|
3420
3837
|
const status = new Status();
|
|
3421
3838
|
status.start();
|
|
@@ -3488,12 +3905,219 @@ async function projectNames(api, projectIds) {
|
|
|
3488
3905
|
return names;
|
|
3489
3906
|
}
|
|
3490
3907
|
|
|
3491
|
-
// src/commands/
|
|
3908
|
+
// src/commands/entity/tags.ts
|
|
3909
|
+
import chalk12 from "chalk";
|
|
3910
|
+
|
|
3911
|
+
// src/util/tags.ts
|
|
3912
|
+
var NON_SPACING_MARK = new RegExp("^\\p{Mn}$", "u");
|
|
3913
|
+
var LETTER_OR_DIGIT = /^[\p{L}\p{Nd}]$/u;
|
|
3914
|
+
var SPACE_SEPARATOR = /^[\p{Zs}\p{Zl}\p{Zp}]$/u;
|
|
3915
|
+
var NON_BREAKING = /* @__PURE__ */ new Set(["\xA0", "\u2007", "\u202F"]);
|
|
3916
|
+
var CONTROL_WHITESPACE = /^[\t\n\u000B\f\r\u001C-\u001F]$/;
|
|
3917
|
+
function isWhitespace(ch) {
|
|
3918
|
+
return CONTROL_WHITESPACE.test(ch) || SPACE_SEPARATOR.test(ch) && !NON_BREAKING.has(ch);
|
|
3919
|
+
}
|
|
3920
|
+
function normalizeTag(raw) {
|
|
3921
|
+
const decomposed = raw.normalize("NFD");
|
|
3922
|
+
let out = "";
|
|
3923
|
+
let lastWasDash = false;
|
|
3924
|
+
for (let i = 0; i < decomposed.length; i++) {
|
|
3925
|
+
const ch = decomposed[i];
|
|
3926
|
+
if (NON_SPACING_MARK.test(ch)) continue;
|
|
3927
|
+
const lowered = ch.toLowerCase();
|
|
3928
|
+
const lower = lowered.length === 1 ? lowered : ch;
|
|
3929
|
+
if (LETTER_OR_DIGIT.test(lower)) {
|
|
3930
|
+
out += lower;
|
|
3931
|
+
lastWasDash = false;
|
|
3932
|
+
} else if (lower === "-" || lower === "_" || isWhitespace(lower)) {
|
|
3933
|
+
if (out.length > 0 && !lastWasDash) {
|
|
3934
|
+
out += "-";
|
|
3935
|
+
lastWasDash = true;
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
}
|
|
3939
|
+
return lastWasDash ? out.slice(0, -1) : out;
|
|
3940
|
+
}
|
|
3941
|
+
var RESERVED_PREFIXES = ["auto-analysis-staging", "staging-run"];
|
|
3942
|
+
function isReservedTag(normalized) {
|
|
3943
|
+
return RESERVED_PREFIXES.some((prefix) => normalized.startsWith(prefix));
|
|
3944
|
+
}
|
|
3945
|
+
var TagError = class extends Error {
|
|
3946
|
+
constructor(message) {
|
|
3947
|
+
super(message);
|
|
3948
|
+
this.name = "TagError";
|
|
3949
|
+
}
|
|
3950
|
+
};
|
|
3951
|
+
function canonicalTags(given) {
|
|
3952
|
+
const tags = [];
|
|
3953
|
+
const renamed = [];
|
|
3954
|
+
for (const typed2 of given.flatMap((entry) => entry.split(",")).map((entry) => entry.trim())) {
|
|
3955
|
+
if (typed2 === "") continue;
|
|
3956
|
+
const tag = normalizeTag(typed2);
|
|
3957
|
+
if (tag === "") {
|
|
3958
|
+
throw new TagError(`"${typed2}" is not a usable tag: a tag needs at least one letter or digit.`);
|
|
3959
|
+
}
|
|
3960
|
+
if (isReservedTag(tag)) {
|
|
3961
|
+
throw new TagError(
|
|
3962
|
+
`"${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.`
|
|
3963
|
+
);
|
|
3964
|
+
}
|
|
3965
|
+
if (tag !== typed2) renamed.push([typed2, tag]);
|
|
3966
|
+
if (!tags.includes(tag)) tags.push(tag);
|
|
3967
|
+
}
|
|
3968
|
+
return { tags, renamed };
|
|
3969
|
+
}
|
|
3970
|
+
function planTagChange(operation, current, tags) {
|
|
3971
|
+
const wanted = new Set(tags);
|
|
3972
|
+
let addTags = [];
|
|
3973
|
+
let removeTags = [];
|
|
3974
|
+
if (operation === "add") {
|
|
3975
|
+
addTags = tags.filter((tag) => !current.includes(tag));
|
|
3976
|
+
} else if (operation === "remove") {
|
|
3977
|
+
removeTags = current.filter((stored) => wanted.has(stored) || wanted.has(normalizeTag(stored)));
|
|
3978
|
+
} else {
|
|
3979
|
+
addTags = tags.filter((tag) => !current.includes(tag));
|
|
3980
|
+
removeTags = current.filter((stored) => !wanted.has(stored));
|
|
3981
|
+
}
|
|
3982
|
+
const result = [...current.filter((stored) => !removeTags.includes(stored)), ...addTags];
|
|
3983
|
+
return { addTags, removeTags, result: sortTags(result) };
|
|
3984
|
+
}
|
|
3985
|
+
function sortTags(tags) {
|
|
3986
|
+
return [...tags].sort((a, b) => a.localeCompare(b));
|
|
3987
|
+
}
|
|
3988
|
+
|
|
3989
|
+
// src/commands/entity/tags.ts
|
|
3492
3990
|
function getOutputFormat(cmd) {
|
|
3493
3991
|
const config = loadConfig();
|
|
3494
3992
|
const globalOpts = cmd.optsWithGlobals();
|
|
3495
3993
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3496
3994
|
}
|
|
3995
|
+
function resolve(target, ref, cmd) {
|
|
3996
|
+
const opts = cmd.optsWithGlobals();
|
|
3997
|
+
const overrides = { project: opts.project, branch: opts.branch };
|
|
3998
|
+
if (target === "entity") return parseEntityReference(ref, overrides);
|
|
3999
|
+
const project = parseProjectReference(ref, overrides);
|
|
4000
|
+
return { ...project, entityId: project.projectId, entityBranch: "main" };
|
|
4001
|
+
}
|
|
4002
|
+
function printTags(result, outputFormat) {
|
|
4003
|
+
if (outputFormat === "json") {
|
|
4004
|
+
format(result, { format: outputFormat });
|
|
4005
|
+
} else if (outputFormat === "table") {
|
|
4006
|
+
format(result.tags.map((tag) => ({ tag })), { format: outputFormat, columns: ["tag"] });
|
|
4007
|
+
} else if (result.tags.length === 0) {
|
|
4008
|
+
empty("tags");
|
|
4009
|
+
} else {
|
|
4010
|
+
console.log(result.tags.join(", "));
|
|
4011
|
+
}
|
|
4012
|
+
}
|
|
4013
|
+
function describeChange(added, removed) {
|
|
4014
|
+
const parts = [
|
|
4015
|
+
...added.length ? [`added ${added.join(", ")}`] : [],
|
|
4016
|
+
...removed.length ? [`removed ${removed.join(", ")}`] : []
|
|
4017
|
+
];
|
|
4018
|
+
return parts.join("; ");
|
|
4019
|
+
}
|
|
4020
|
+
async function show(target, ref, cmd) {
|
|
4021
|
+
const resolved = resolve(target, ref, cmd);
|
|
4022
|
+
const entity = await createApiClient().storage.getEntity(resolved);
|
|
4023
|
+
printTags({ ...resolved, tags: sortTags(entity.tags ?? []) }, getOutputFormat(cmd));
|
|
4024
|
+
}
|
|
4025
|
+
async function change(target, operation, ref, given, cmd) {
|
|
4026
|
+
const outputFormat = getOutputFormat(cmd);
|
|
4027
|
+
const resolved = resolve(target, ref, cmd);
|
|
4028
|
+
const { tags, renamed } = canonicalTags(Array.isArray(given) ? given : [given]);
|
|
4029
|
+
if (tags.length === 0 && operation !== "set") {
|
|
4030
|
+
usageError("No tags given.", `Name at least one: diafunc ${target} tags ${operation} ${ref} <tag> [<tag>...]`);
|
|
4031
|
+
}
|
|
4032
|
+
for (const [typed2, tag] of renamed) {
|
|
4033
|
+
console.error(chalk12.dim(`"${typed2}" is written as "${tag}", the form tags are searched by.`));
|
|
4034
|
+
}
|
|
4035
|
+
const api = createApiClient();
|
|
4036
|
+
const current = (await api.storage.getEntity(resolved)).tags ?? [];
|
|
4037
|
+
const plan = planTagChange(operation, current, tags);
|
|
4038
|
+
const noun = target === "project" ? `project "${resolved.projectId}"` : `entity "${resolved.entityId}"`;
|
|
4039
|
+
if (plan.addTags.length === 0 && plan.removeTags.length === 0) {
|
|
4040
|
+
if (outputFormat === "human") success(`Tags of ${noun} are already as asked; nothing changed.`);
|
|
4041
|
+
printTags({ ...resolved, tags: sortTags(current), added: [], removed: [] }, outputFormat);
|
|
4042
|
+
return;
|
|
4043
|
+
}
|
|
4044
|
+
await api.storage.changeEntityTags(resolved, { addTags: plan.addTags, removeTags: plan.removeTags });
|
|
4045
|
+
const outcome = { added: plan.addTags, removed: plan.removeTags };
|
|
4046
|
+
if (isDryRun()) {
|
|
4047
|
+
if (outputFormat === "human") console.log(chalk12.dim(`Would leave ${noun} with:`));
|
|
4048
|
+
printTags({ ...resolved, tags: plan.result, ...outcome, dryRun: true }, outputFormat);
|
|
4049
|
+
return;
|
|
4050
|
+
}
|
|
4051
|
+
const stored = (await api.storage.getEntity(resolved)).tags ?? [];
|
|
4052
|
+
if (outputFormat === "human") success(`Tags of ${noun} updated: ${describeChange(plan.addTags, plan.removeTags)}.`);
|
|
4053
|
+
printTags({ ...resolved, tags: sortTags(stored), ...outcome }, outputFormat);
|
|
4054
|
+
}
|
|
4055
|
+
function guarded(run) {
|
|
4056
|
+
return run().catch((error) => {
|
|
4057
|
+
if (error instanceof TagError) usageError(error.message);
|
|
4058
|
+
handleError(error);
|
|
4059
|
+
});
|
|
4060
|
+
}
|
|
4061
|
+
var NORMALISATION = `
|
|
4062
|
+
Tags are written in the form they are searched by: lowercase, accents dropped,
|
|
4063
|
+
spaces and underscores as "-", punctuation removed ("Machine Learning" becomes
|
|
4064
|
+
"machine-learning"). Tags beginning with "auto-analysis-staging" or "staging-run"
|
|
4065
|
+
are reserved for analysis runs and are refused.`;
|
|
4066
|
+
function registerTagCommands(parent, target) {
|
|
4067
|
+
const argName = target === "project" ? "<projectId>" : "<ref>";
|
|
4068
|
+
const argHelp = target === "project" ? "Project ID (or projectId/branch)" : "Entity reference";
|
|
4069
|
+
const example = target === "project" ? "diafunc project tags" : "diafunc entity tags";
|
|
4070
|
+
const sample = target === "project" ? "<projectId>" : "<project>/main/<entity>/main";
|
|
4071
|
+
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" ? `
|
|
4072
|
+
A project's tags are the tags of its project entity, so this is 'diafunc entity tags'
|
|
4073
|
+
on <projectId>/main/<projectId>/main. Changing them needs edit access to the project.
|
|
4074
|
+
` : ""}${NORMALISATION}
|
|
4075
|
+
|
|
4076
|
+
Examples:
|
|
4077
|
+
$ ${example} get ${sample}
|
|
4078
|
+
$ ${example} add ${sample} health "Machine Learning"
|
|
4079
|
+
$ ${example} remove ${sample} health
|
|
4080
|
+
$ ${example} set ${sample} energy climate exactly these two
|
|
4081
|
+
$ ${example} set ${sample} "" no tags at all
|
|
4082
|
+
$ diafunc admin curated-tags list the tags Explore offers as data domains
|
|
4083
|
+
`);
|
|
4084
|
+
tags.command("get").description(`Show the tags of ${target === "project" ? "a project" : "an entity"}`).argument(argName, argHelp).addHelpText("after", `
|
|
4085
|
+
Examples:
|
|
4086
|
+
$ ${example} get ${sample}
|
|
4087
|
+
$ ${example} get ${sample} -o json { ..., "tags": ["energy", "health"] }
|
|
4088
|
+
`).action((ref, _options, cmd) => guarded(() => show(target, ref, cmd)));
|
|
4089
|
+
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}
|
|
4090
|
+
|
|
4091
|
+
Examples:
|
|
4092
|
+
$ ${example} add ${sample} health
|
|
4093
|
+
$ ${example} add ${sample} health energy "Machine Learning"
|
|
4094
|
+
$ ${example} add ${sample} health --dry-run print the request, send nothing
|
|
4095
|
+
`).action((ref, given, _options, cmd) => guarded(() => change(target, "add", ref, given, cmd)));
|
|
4096
|
+
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", `
|
|
4097
|
+
A tag is matched in any spelling of the same tag: "Health" also removes a stored "health".
|
|
4098
|
+
|
|
4099
|
+
Examples:
|
|
4100
|
+
$ ${example} remove ${sample} health
|
|
4101
|
+
$ ${example} remove ${sample} health,energy --dry-run
|
|
4102
|
+
`).action((ref, given, _options, cmd) => guarded(() => change(target, "remove", ref, given, cmd)));
|
|
4103
|
+
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}
|
|
4104
|
+
|
|
4105
|
+
Every tag that is not named is taken off, including ones the platform set itself
|
|
4106
|
+
(an analysis marks what it generates with "auto-analysis", for example).
|
|
4107
|
+
|
|
4108
|
+
Examples:
|
|
4109
|
+
$ ${example} set ${sample} energy climate
|
|
4110
|
+
$ ${example} set ${sample} "" no tags at all
|
|
4111
|
+
$ ${example} set ${sample} energy --dry-run print the request, send nothing
|
|
4112
|
+
`).action((ref, given, _options, cmd) => guarded(() => change(target, "set", ref, given, cmd)));
|
|
4113
|
+
}
|
|
4114
|
+
|
|
4115
|
+
// src/commands/project/index.ts
|
|
4116
|
+
function getOutputFormat2(cmd) {
|
|
4117
|
+
const config = loadConfig();
|
|
4118
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
4119
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
4120
|
+
}
|
|
3497
4121
|
function getOverrides(cmd) {
|
|
3498
4122
|
const opts = cmd.optsWithGlobals();
|
|
3499
4123
|
return { project: opts.project, branch: opts.branch };
|
|
@@ -3507,7 +4131,7 @@ Examples:
|
|
|
3507
4131
|
$ diafunc search "housing" --type project find a project by name
|
|
3508
4132
|
`).action(async (options, cmd) => {
|
|
3509
4133
|
try {
|
|
3510
|
-
const outputFormat =
|
|
4134
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
3511
4135
|
const api = createApiClient();
|
|
3512
4136
|
const projects = options.all ? await api.admin.getAllProjects() : await api.admin.getProjects();
|
|
3513
4137
|
const limit = Number.parseInt(options.limit, 10);
|
|
@@ -3516,7 +4140,7 @@ Examples:
|
|
|
3516
4140
|
try {
|
|
3517
4141
|
names = await projectNames(api, capped.map((p) => p.projectId));
|
|
3518
4142
|
} catch {
|
|
3519
|
-
console.error(
|
|
4143
|
+
console.error(chalk13.dim("Project names are unavailable right now; showing ids."));
|
|
3520
4144
|
}
|
|
3521
4145
|
const rows = capped.map((p) => ({ name: names.get(p.projectId) ?? null, ...p }));
|
|
3522
4146
|
format(rows, {
|
|
@@ -3533,7 +4157,7 @@ Examples:
|
|
|
3533
4157
|
]
|
|
3534
4158
|
});
|
|
3535
4159
|
if (capped.length < projects.length) {
|
|
3536
|
-
console.error(
|
|
4160
|
+
console.error(chalk13.dim(
|
|
3537
4161
|
`
|
|
3538
4162
|
Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
3539
4163
|
));
|
|
@@ -3544,7 +4168,7 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3544
4168
|
});
|
|
3545
4169
|
project.command("get").description("Get project details").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
3546
4170
|
try {
|
|
3547
|
-
const outputFormat =
|
|
4171
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
3548
4172
|
const api = createApiClient();
|
|
3549
4173
|
const p = await api.admin.getProject(projectId);
|
|
3550
4174
|
format(p, { format: outputFormat });
|
|
@@ -3554,7 +4178,7 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3554
4178
|
});
|
|
3555
4179
|
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).action(async (options, cmd) => {
|
|
3556
4180
|
try {
|
|
3557
|
-
const outputFormat =
|
|
4181
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
3558
4182
|
const api = createApiClient();
|
|
3559
4183
|
const p = await api.admin.createProject({
|
|
3560
4184
|
visibility: options.visibility.toUpperCase(),
|
|
@@ -3568,7 +4192,7 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3568
4192
|
});
|
|
3569
4193
|
if (outputFormat === "human") {
|
|
3570
4194
|
success("Project created.");
|
|
3571
|
-
console.log(` Project ID: ${
|
|
4195
|
+
console.log(` Project ID: ${chalk13.bold(p.projectId)}`);
|
|
3572
4196
|
console.log(` Visibility: ${p.visibility}`);
|
|
3573
4197
|
console.log(` Language: ${p.language}`);
|
|
3574
4198
|
} else {
|
|
@@ -3599,7 +4223,7 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3599
4223
|
});
|
|
3600
4224
|
project.command("recent").description("List recently accessed projects").action(async (_options, cmd) => {
|
|
3601
4225
|
try {
|
|
3602
|
-
const outputFormat =
|
|
4226
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
3603
4227
|
const api = createApiClient();
|
|
3604
4228
|
const recent = await api.admin.getRecentProjects();
|
|
3605
4229
|
format(recent, {
|
|
@@ -3641,10 +4265,11 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3641
4265
|
handleError(error);
|
|
3642
4266
|
}
|
|
3643
4267
|
});
|
|
4268
|
+
registerTagCommands(project, "project");
|
|
3644
4269
|
const members = project.command("members").description("Manage project members");
|
|
3645
4270
|
members.command("list").description("List project members").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
3646
4271
|
try {
|
|
3647
|
-
const outputFormat =
|
|
4272
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
3648
4273
|
const api = createApiClient();
|
|
3649
4274
|
const memberList = await api.admin.getProjectMembers(projectId);
|
|
3650
4275
|
format(memberList, {
|
|
@@ -3693,7 +4318,7 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3693
4318
|
console.log(`Poll progress: diafunc notebook bundles ${project2}`);
|
|
3694
4319
|
return;
|
|
3695
4320
|
}
|
|
3696
|
-
console.log(
|
|
4321
|
+
console.log(chalk13.dim(`Project export queued (bundle ID: ${bundleId}); waiting for it to finish\u2026`));
|
|
3697
4322
|
const job = await pollUntilFinished(api.storage, ref.projectId, ref.projectBranch, bundleId);
|
|
3698
4323
|
const response = await api.storage.getBundleContent(ref.projectId, ref.projectBranch, bundleId, job.filename);
|
|
3699
4324
|
const outFile = options.out ?? "project.dfproj";
|
|
@@ -3705,7 +4330,7 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3705
4330
|
});
|
|
3706
4331
|
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
4332
|
try {
|
|
3708
|
-
const outputFormat =
|
|
4333
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
3709
4334
|
const overrides = getOverrides(cmd);
|
|
3710
4335
|
const ref = parseProjectReference(project2, overrides);
|
|
3711
4336
|
const api = createApiClient();
|
|
@@ -3717,25 +4342,25 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
3717
4342
|
}
|
|
3718
4343
|
|
|
3719
4344
|
// src/commands/team/index.ts
|
|
3720
|
-
import
|
|
4345
|
+
import chalk15 from "chalk";
|
|
3721
4346
|
|
|
3722
4347
|
// src/util/confirm.ts
|
|
3723
4348
|
import * as readline from "readline";
|
|
3724
|
-
import
|
|
4349
|
+
import chalk14 from "chalk";
|
|
3725
4350
|
async function confirmDestructive(message, opts = {}) {
|
|
3726
4351
|
if (!process.stdin.isTTY || opts.yes) return;
|
|
3727
4352
|
const expected = opts.resourceId ?? "yes";
|
|
3728
4353
|
const hint2 = opts.resourceId ? `"${opts.resourceId}"` : '"yes"';
|
|
3729
|
-
console.log(
|
|
3730
|
-
const answer = await new Promise((
|
|
4354
|
+
console.log(chalk14.yellow(`! ${message}`));
|
|
4355
|
+
const answer = await new Promise((resolve2) => {
|
|
3731
4356
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
3732
4357
|
rl.question(` Type ${hint2} to confirm: `, (ans) => {
|
|
3733
4358
|
rl.close();
|
|
3734
|
-
|
|
4359
|
+
resolve2(ans);
|
|
3735
4360
|
});
|
|
3736
4361
|
});
|
|
3737
4362
|
if (answer.trim() !== expected) {
|
|
3738
|
-
console.log(
|
|
4363
|
+
console.log(chalk14.dim("Aborted."));
|
|
3739
4364
|
process.exit(1);
|
|
3740
4365
|
}
|
|
3741
4366
|
}
|
|
@@ -3743,7 +4368,7 @@ async function confirmDestructive(message, opts = {}) {
|
|
|
3743
4368
|
// src/commands/team/index.ts
|
|
3744
4369
|
var ROLES = ["OWNER", "ADMIN", "MEMBER"];
|
|
3745
4370
|
var INTERVALS = ["MONTHLY", "YEARLY"];
|
|
3746
|
-
function
|
|
4371
|
+
function getOutputFormat3(cmd) {
|
|
3747
4372
|
const config = loadConfig();
|
|
3748
4373
|
const globalOpts = cmd.optsWithGlobals();
|
|
3749
4374
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -3808,7 +4433,7 @@ Examples:
|
|
|
3808
4433
|
const api = createApiClient();
|
|
3809
4434
|
const teams = await api.admin.listMyTeams();
|
|
3810
4435
|
format(teams, {
|
|
3811
|
-
format:
|
|
4436
|
+
format: getOutputFormat3(cmd),
|
|
3812
4437
|
columns: ["id", "name", "planId", "seatCount", "packCount", "renewal"]
|
|
3813
4438
|
});
|
|
3814
4439
|
} catch (error) {
|
|
@@ -3819,7 +4444,7 @@ Examples:
|
|
|
3819
4444
|
try {
|
|
3820
4445
|
const api = createApiClient();
|
|
3821
4446
|
format(await api.admin.getTeam(teamId), {
|
|
3822
|
-
format:
|
|
4447
|
+
format: getOutputFormat3(cmd)
|
|
3823
4448
|
});
|
|
3824
4449
|
} catch (error) {
|
|
3825
4450
|
handleError(error);
|
|
@@ -3829,14 +4454,14 @@ Examples:
|
|
|
3829
4454
|
try {
|
|
3830
4455
|
const api = createApiClient();
|
|
3831
4456
|
await api.admin.setActiveTeam(teamId);
|
|
3832
|
-
success(`Active team set to "${teamId}".`, { format:
|
|
4457
|
+
success(`Active team set to "${teamId}".`, { format: getOutputFormat3(cmd) });
|
|
3833
4458
|
} catch (error) {
|
|
3834
4459
|
handleError(error);
|
|
3835
4460
|
}
|
|
3836
4461
|
});
|
|
3837
4462
|
team.command("usage").description("Show credit usage for a team, broken down by member").argument("<teamId>", "Team ID").action(async (teamId, _options, cmd) => {
|
|
3838
4463
|
try {
|
|
3839
|
-
const outputFormat =
|
|
4464
|
+
const outputFormat = getOutputFormat3(cmd);
|
|
3840
4465
|
const api = createApiClient();
|
|
3841
4466
|
const usage = await api.admin.getTeamUsage(teamId);
|
|
3842
4467
|
if (outputFormat === "json") {
|
|
@@ -3865,13 +4490,13 @@ Examples:
|
|
|
3865
4490
|
...options.packs !== void 0 ? { packCount: parseCount(options.packs, "pack count") } : {},
|
|
3866
4491
|
...options.currency !== void 0 ? { currency: options.currency.toUpperCase() } : {}
|
|
3867
4492
|
});
|
|
3868
|
-
const outputFormat =
|
|
4493
|
+
const outputFormat = getOutputFormat3(cmd);
|
|
3869
4494
|
if (outputFormat === "json") {
|
|
3870
4495
|
format(session, { format: outputFormat });
|
|
3871
4496
|
return;
|
|
3872
4497
|
}
|
|
3873
4498
|
console.log("Open this URL to complete checkout:");
|
|
3874
|
-
console.log(
|
|
4499
|
+
console.log(chalk15.cyan(session.url));
|
|
3875
4500
|
} catch (error) {
|
|
3876
4501
|
handleError(error);
|
|
3877
4502
|
}
|
|
@@ -3880,13 +4505,13 @@ Examples:
|
|
|
3880
4505
|
try {
|
|
3881
4506
|
const api = createApiClient();
|
|
3882
4507
|
const session = await api.admin.createTeamPortalSession(teamId, options.returnUrl);
|
|
3883
|
-
const outputFormat =
|
|
4508
|
+
const outputFormat = getOutputFormat3(cmd);
|
|
3884
4509
|
if (outputFormat === "json") {
|
|
3885
4510
|
format(session, { format: outputFormat });
|
|
3886
4511
|
return;
|
|
3887
4512
|
}
|
|
3888
4513
|
console.log("Open this URL to manage billing:");
|
|
3889
|
-
console.log(
|
|
4514
|
+
console.log(chalk15.cyan(session.url));
|
|
3890
4515
|
} catch (error) {
|
|
3891
4516
|
handleError(error);
|
|
3892
4517
|
}
|
|
@@ -3901,7 +4526,7 @@ Examples:
|
|
|
3901
4526
|
const response = await api.admin.cancelTeam(teamId);
|
|
3902
4527
|
success(
|
|
3903
4528
|
`Team "${teamId}" cancelled. Access ends ${response.endsAt ?? "at the end of the period"}.`,
|
|
3904
|
-
{ format:
|
|
4529
|
+
{ format: getOutputFormat3(cmd) }
|
|
3905
4530
|
);
|
|
3906
4531
|
} catch (error) {
|
|
3907
4532
|
handleError(error);
|
|
@@ -3915,7 +4540,7 @@ Examples:
|
|
|
3915
4540
|
});
|
|
3916
4541
|
const api = createApiClient();
|
|
3917
4542
|
await api.admin.leaveTeam(teamId);
|
|
3918
|
-
success(`Left team "${teamId}".`, { format:
|
|
4543
|
+
success(`Left team "${teamId}".`, { format: getOutputFormat3(cmd) });
|
|
3919
4544
|
} catch (error) {
|
|
3920
4545
|
handleError(error);
|
|
3921
4546
|
}
|
|
@@ -3934,7 +4559,7 @@ function registerMemberCommands(team) {
|
|
|
3934
4559
|
const all = await api.admin.listTeamMembers(teamId);
|
|
3935
4560
|
const shown = options.all ? all : all.filter((m) => !m.removedAt);
|
|
3936
4561
|
format(shown, {
|
|
3937
|
-
format:
|
|
4562
|
+
format: getOutputFormat3(cmd),
|
|
3938
4563
|
columns: options.all ? ["userId", "name", "email", "role", "joinedAt", "removedAt"] : ["userId", "name", "email", "role", "joinedAt"]
|
|
3939
4564
|
});
|
|
3940
4565
|
} catch (error) {
|
|
@@ -3947,7 +4572,7 @@ function registerMemberCommands(team) {
|
|
|
3947
4572
|
const api = createApiClient();
|
|
3948
4573
|
await api.admin.inviteTeamMember(teamId, email, role);
|
|
3949
4574
|
success(`Invited ${email} to team "${teamId}" as ${role}.`, {
|
|
3950
|
-
format:
|
|
4575
|
+
format: getOutputFormat3(cmd)
|
|
3951
4576
|
});
|
|
3952
4577
|
} catch (error) {
|
|
3953
4578
|
handleError(error);
|
|
@@ -3962,7 +4587,7 @@ function registerMemberCommands(team) {
|
|
|
3962
4587
|
const api = createApiClient();
|
|
3963
4588
|
await api.admin.removeTeamMember(teamId, userId);
|
|
3964
4589
|
success(`Removed ${userId} from team "${teamId}".`, {
|
|
3965
|
-
format:
|
|
4590
|
+
format: getOutputFormat3(cmd)
|
|
3966
4591
|
});
|
|
3967
4592
|
} catch (error) {
|
|
3968
4593
|
handleError(error);
|
|
@@ -3975,7 +4600,7 @@ function registerInvitationCommands(team) {
|
|
|
3975
4600
|
try {
|
|
3976
4601
|
const api = createApiClient();
|
|
3977
4602
|
format(await api.admin.listTeamInvitations(teamId), {
|
|
3978
|
-
format:
|
|
4603
|
+
format: getOutputFormat3(cmd),
|
|
3979
4604
|
columns: ["invitationId", "email", "role", "invitedBy", "expiresAt"]
|
|
3980
4605
|
});
|
|
3981
4606
|
} catch (error) {
|
|
@@ -3991,7 +4616,7 @@ function registerInvitationCommands(team) {
|
|
|
3991
4616
|
const api = createApiClient();
|
|
3992
4617
|
await api.admin.revokeTeamInvitation(teamId, invitationId);
|
|
3993
4618
|
success(`Revoked invitation "${invitationId}".`, {
|
|
3994
|
-
format:
|
|
4619
|
+
format: getOutputFormat3(cmd)
|
|
3995
4620
|
});
|
|
3996
4621
|
} catch (error) {
|
|
3997
4622
|
handleError(error);
|
|
@@ -4002,7 +4627,7 @@ function registerInvitationCommands(team) {
|
|
|
4002
4627
|
const api = createApiClient();
|
|
4003
4628
|
await api.admin.resendTeamInvitation(teamId, invitationId);
|
|
4004
4629
|
success(`Resent invitation "${invitationId}".`, {
|
|
4005
|
-
format:
|
|
4630
|
+
format: getOutputFormat3(cmd)
|
|
4006
4631
|
});
|
|
4007
4632
|
} catch (error) {
|
|
4008
4633
|
handleError(error);
|
|
@@ -4013,7 +4638,7 @@ function registerInvitationCommands(team) {
|
|
|
4013
4638
|
const api = createApiClient();
|
|
4014
4639
|
const member = await api.admin.acceptTeamInvitation(token);
|
|
4015
4640
|
success(`Joined the team as ${member.role}.`, {
|
|
4016
|
-
format:
|
|
4641
|
+
format: getOutputFormat3(cmd)
|
|
4017
4642
|
});
|
|
4018
4643
|
} catch (error) {
|
|
4019
4644
|
handleError(error);
|
|
@@ -4027,7 +4652,7 @@ function registerSeatCommands(team) {
|
|
|
4027
4652
|
const api = createApiClient();
|
|
4028
4653
|
printInvoicePreview(
|
|
4029
4654
|
await api.admin.previewTeamSeatCount(teamId, parseCount(count, "seat count")),
|
|
4030
|
-
|
|
4655
|
+
getOutputFormat3(cmd)
|
|
4031
4656
|
);
|
|
4032
4657
|
} catch (error) {
|
|
4033
4658
|
handleError(error);
|
|
@@ -4041,9 +4666,9 @@ function registerSeatCommands(team) {
|
|
|
4041
4666
|
{ yes: options.yes, resourceId: teamId }
|
|
4042
4667
|
);
|
|
4043
4668
|
const api = createApiClient();
|
|
4044
|
-
const
|
|
4045
|
-
success(`Seats changed from ${
|
|
4046
|
-
format:
|
|
4669
|
+
const change2 = await api.admin.updateTeamSeatCount(teamId, seatCount);
|
|
4670
|
+
success(`Seats changed from ${change2.oldSeatCount} to ${change2.newSeatCount}.`, {
|
|
4671
|
+
format: getOutputFormat3(cmd)
|
|
4047
4672
|
});
|
|
4048
4673
|
} catch (error) {
|
|
4049
4674
|
handleError(error);
|
|
@@ -4057,7 +4682,7 @@ function registerPackCommands(team) {
|
|
|
4057
4682
|
const api = createApiClient();
|
|
4058
4683
|
printInvoicePreview(
|
|
4059
4684
|
await api.admin.previewTeamPackCount(teamId, parseCount(count, "pack count")),
|
|
4060
|
-
|
|
4685
|
+
getOutputFormat3(cmd)
|
|
4061
4686
|
);
|
|
4062
4687
|
} catch (error) {
|
|
4063
4688
|
handleError(error);
|
|
@@ -4071,9 +4696,9 @@ function registerPackCommands(team) {
|
|
|
4071
4696
|
{ yes: options.yes, resourceId: teamId }
|
|
4072
4697
|
);
|
|
4073
4698
|
const api = createApiClient();
|
|
4074
|
-
const
|
|
4075
|
-
success(`Packs changed from ${
|
|
4076
|
-
format:
|
|
4699
|
+
const change2 = await api.admin.updateTeamPackCount(teamId, packCount);
|
|
4700
|
+
success(`Packs changed from ${change2.oldPackCount} to ${change2.newPackCount}.`, {
|
|
4701
|
+
format: getOutputFormat3(cmd)
|
|
4077
4702
|
});
|
|
4078
4703
|
} catch (error) {
|
|
4079
4704
|
handleError(error);
|
|
@@ -4090,7 +4715,7 @@ function registerOwnershipCommands(team) {
|
|
|
4090
4715
|
);
|
|
4091
4716
|
const api = createApiClient();
|
|
4092
4717
|
format(await api.admin.initiateOwnershipTransfer(teamId, userId), {
|
|
4093
|
-
format:
|
|
4718
|
+
format: getOutputFormat3(cmd)
|
|
4094
4719
|
});
|
|
4095
4720
|
} catch (error) {
|
|
4096
4721
|
handleError(error);
|
|
@@ -4100,7 +4725,7 @@ function registerOwnershipCommands(team) {
|
|
|
4100
4725
|
try {
|
|
4101
4726
|
const api = createApiClient();
|
|
4102
4727
|
const pending = await api.admin.getOwnershipTransfer(teamId);
|
|
4103
|
-
const outputFormat =
|
|
4728
|
+
const outputFormat = getOutputFormat3(cmd);
|
|
4104
4729
|
if (!pending) {
|
|
4105
4730
|
if (outputFormat === "json") {
|
|
4106
4731
|
format(null, { format: outputFormat });
|
|
@@ -4118,7 +4743,7 @@ function registerOwnershipCommands(team) {
|
|
|
4118
4743
|
try {
|
|
4119
4744
|
const api = createApiClient();
|
|
4120
4745
|
const response = await api.admin.acceptOwnershipTransfer(teamId);
|
|
4121
|
-
const outputFormat =
|
|
4746
|
+
const outputFormat = getOutputFormat3(cmd);
|
|
4122
4747
|
if (outputFormat === "json") {
|
|
4123
4748
|
format(response, { format: outputFormat });
|
|
4124
4749
|
return;
|
|
@@ -4126,7 +4751,7 @@ function registerOwnershipCommands(team) {
|
|
|
4126
4751
|
success(`Ownership transfer ${response.status}.`);
|
|
4127
4752
|
if (response.checkoutUrl) {
|
|
4128
4753
|
console.log("Open this URL to complete the billing handover:");
|
|
4129
|
-
console.log(
|
|
4754
|
+
console.log(chalk15.cyan(response.checkoutUrl));
|
|
4130
4755
|
}
|
|
4131
4756
|
} catch (error) {
|
|
4132
4757
|
handleError(error);
|
|
@@ -4137,7 +4762,7 @@ function registerOwnershipCommands(team) {
|
|
|
4137
4762
|
const api = createApiClient();
|
|
4138
4763
|
await api.admin.cancelOwnershipTransfer(teamId);
|
|
4139
4764
|
success(`Cancelled the ownership transfer for team "${teamId}".`, {
|
|
4140
|
-
format:
|
|
4765
|
+
format: getOutputFormat3(cmd)
|
|
4141
4766
|
});
|
|
4142
4767
|
} catch (error) {
|
|
4143
4768
|
handleError(error);
|
|
@@ -4146,8 +4771,8 @@ function registerOwnershipCommands(team) {
|
|
|
4146
4771
|
}
|
|
4147
4772
|
|
|
4148
4773
|
// src/commands/entity/index.ts
|
|
4149
|
-
import * as
|
|
4150
|
-
function
|
|
4774
|
+
import * as fs5 from "fs";
|
|
4775
|
+
function getOutputFormat4(cmd) {
|
|
4151
4776
|
const config = loadConfig();
|
|
4152
4777
|
const globalOpts = cmd.optsWithGlobals();
|
|
4153
4778
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4165,11 +4790,12 @@ Examples:
|
|
|
4165
4790
|
$ diafunc entity list <projectId>
|
|
4166
4791
|
$ diafunc entity get <project>/main/<entity>/main
|
|
4167
4792
|
$ diafunc entity history <project>/main/<entity>/main
|
|
4793
|
+
$ diafunc entity tags add <project>/main/<entity>/main health
|
|
4168
4794
|
`);
|
|
4169
4795
|
;
|
|
4170
4796
|
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
4797
|
try {
|
|
4172
|
-
const outputFormat =
|
|
4798
|
+
const outputFormat = getOutputFormat4(cmd);
|
|
4173
4799
|
const overrides = getOverrides2(cmd);
|
|
4174
4800
|
const ref = parseEntityReference(projectRef + "/" + projectRef, overrides);
|
|
4175
4801
|
const api = createApiClient();
|
|
@@ -4196,7 +4822,7 @@ Examples:
|
|
|
4196
4822
|
});
|
|
4197
4823
|
entity.command("get").description("Get entity metadata").argument("<ref>", "Entity reference").option("--content", "Include content").action(async (ref, options, cmd) => {
|
|
4198
4824
|
try {
|
|
4199
|
-
const outputFormat =
|
|
4825
|
+
const outputFormat = getOutputFormat4(cmd);
|
|
4200
4826
|
const overrides = getOverrides2(cmd);
|
|
4201
4827
|
const resolved = parseEntityReference(ref, overrides);
|
|
4202
4828
|
const api = createApiClient();
|
|
@@ -4239,7 +4865,7 @@ Examples:
|
|
|
4239
4865
|
});
|
|
4240
4866
|
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
4867
|
try {
|
|
4242
|
-
const outputFormat =
|
|
4868
|
+
const outputFormat = getOutputFormat4(cmd);
|
|
4243
4869
|
const overrides = getOverrides2(cmd);
|
|
4244
4870
|
const resolved = parseEntityReference(ref, overrides);
|
|
4245
4871
|
const api = createApiClient();
|
|
@@ -4289,6 +4915,7 @@ Examples:
|
|
|
4289
4915
|
handleError(error);
|
|
4290
4916
|
}
|
|
4291
4917
|
});
|
|
4918
|
+
registerTagCommands(entity, "entity");
|
|
4292
4919
|
const content = entity.command("content").description("Manage entity content");
|
|
4293
4920
|
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
4921
|
try {
|
|
@@ -4298,7 +4925,7 @@ Examples:
|
|
|
4298
4925
|
const response = await api.storage.getEntityContent(resolved);
|
|
4299
4926
|
if (options.out) {
|
|
4300
4927
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
4301
|
-
|
|
4928
|
+
fs5.writeFileSync(options.out, buffer);
|
|
4302
4929
|
success(`Content saved to ${options.out}`);
|
|
4303
4930
|
} else {
|
|
4304
4931
|
const text2 = await response.text();
|
|
@@ -4313,7 +4940,7 @@ Examples:
|
|
|
4313
4940
|
const overrides = getOverrides2(cmd);
|
|
4314
4941
|
const resolved = parseEntityReference(ref, overrides);
|
|
4315
4942
|
const api = createApiClient();
|
|
4316
|
-
const fileBuffer =
|
|
4943
|
+
const fileBuffer = fs5.readFileSync(file);
|
|
4317
4944
|
const base64 = fileBuffer.toString("base64");
|
|
4318
4945
|
await api.storage.saveEntityContentBase64(resolved, base64);
|
|
4319
4946
|
success(`Content uploaded from "${file}" to entity "${resolved.entityId}".`);
|
|
@@ -4355,7 +4982,7 @@ Examples:
|
|
|
4355
4982
|
});
|
|
4356
4983
|
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
4984
|
try {
|
|
4358
|
-
const outputFormat =
|
|
4985
|
+
const outputFormat = getOutputFormat4(cmd);
|
|
4359
4986
|
const overrides = getOverrides2(cmd);
|
|
4360
4987
|
const ref = parseProjectReference(project, overrides);
|
|
4361
4988
|
const api = createApiClient();
|
|
@@ -4367,7 +4994,7 @@ Examples:
|
|
|
4367
4994
|
}
|
|
4368
4995
|
|
|
4369
4996
|
// src/commands/link/index.ts
|
|
4370
|
-
function
|
|
4997
|
+
function getOutputFormat5(cmd) {
|
|
4371
4998
|
const config = loadConfig();
|
|
4372
4999
|
const globalOpts = cmd.optsWithGlobals();
|
|
4373
5000
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4380,7 +5007,7 @@ function registerLinkCommands(program) {
|
|
|
4380
5007
|
const link = program.command("link").description("Manage links between entities");
|
|
4381
5008
|
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
5009
|
try {
|
|
4383
|
-
const outputFormat =
|
|
5010
|
+
const outputFormat = getOutputFormat5(cmd);
|
|
4384
5011
|
const overrides = getOverrides3(cmd);
|
|
4385
5012
|
const resolved = parseEntityReference(ref, overrides);
|
|
4386
5013
|
const api = createApiClient();
|
|
@@ -4455,7 +5082,7 @@ function registerLinkCommands(program) {
|
|
|
4455
5082
|
}
|
|
4456
5083
|
|
|
4457
5084
|
// src/commands/event/index.ts
|
|
4458
|
-
function
|
|
5085
|
+
function getOutputFormat6(cmd) {
|
|
4459
5086
|
const config = loadConfig();
|
|
4460
5087
|
const globalOpts = cmd.optsWithGlobals();
|
|
4461
5088
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4468,7 +5095,7 @@ function registerEventCommands(program) {
|
|
|
4468
5095
|
const event = program.command("event").description("Manage events");
|
|
4469
5096
|
event.command("list").description("List events for an entity").argument("<ref>", "Entity reference").action(async (ref, _options, cmd) => {
|
|
4470
5097
|
try {
|
|
4471
|
-
const outputFormat =
|
|
5098
|
+
const outputFormat = getOutputFormat6(cmd);
|
|
4472
5099
|
const overrides = getOverrides4(cmd);
|
|
4473
5100
|
const resolved = parseEntityReference(ref, overrides);
|
|
4474
5101
|
const api = createApiClient();
|
|
@@ -4490,7 +5117,7 @@ function registerEventCommands(program) {
|
|
|
4490
5117
|
});
|
|
4491
5118
|
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
5119
|
try {
|
|
4493
|
-
const outputFormat =
|
|
5120
|
+
const outputFormat = getOutputFormat6(cmd);
|
|
4494
5121
|
const overrides = getOverrides4(cmd);
|
|
4495
5122
|
const resolved = parseEntityReference(ref, overrides);
|
|
4496
5123
|
const api = createApiClient();
|
|
@@ -4502,14 +5129,14 @@ function registerEventCommands(program) {
|
|
|
4502
5129
|
});
|
|
4503
5130
|
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
5131
|
try {
|
|
4505
|
-
const
|
|
4506
|
-
const body = file ?
|
|
5132
|
+
const fs18 = await import("fs");
|
|
5133
|
+
const body = file ? fs18.readFileSync(file, "utf-8") : await new Promise((resolve2, reject) => {
|
|
4507
5134
|
let data = "";
|
|
4508
5135
|
process.stdin.setEncoding("utf-8");
|
|
4509
5136
|
process.stdin.on("data", (chunk) => {
|
|
4510
5137
|
data += chunk;
|
|
4511
5138
|
});
|
|
4512
|
-
process.stdin.on("end", () =>
|
|
5139
|
+
process.stdin.on("end", () => resolve2(data));
|
|
4513
5140
|
process.stdin.on("error", reject);
|
|
4514
5141
|
});
|
|
4515
5142
|
const events = JSON.parse(body);
|
|
@@ -4551,7 +5178,7 @@ function registerEventCommands(program) {
|
|
|
4551
5178
|
}
|
|
4552
5179
|
|
|
4553
5180
|
// src/commands/branch/index.ts
|
|
4554
|
-
function
|
|
5181
|
+
function getOutputFormat7(cmd) {
|
|
4555
5182
|
const config = loadConfig();
|
|
4556
5183
|
const globalOpts = cmd.optsWithGlobals();
|
|
4557
5184
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4570,7 +5197,7 @@ Examples:
|
|
|
4570
5197
|
;
|
|
4571
5198
|
branch.command("list").description("List branches for a project").argument("[projectId]", "Project ID (uses default if omitted)").action(async (projectId, _options, cmd) => {
|
|
4572
5199
|
try {
|
|
4573
|
-
const outputFormat =
|
|
5200
|
+
const outputFormat = getOutputFormat7(cmd);
|
|
4574
5201
|
const overrides = getOverrides5(cmd);
|
|
4575
5202
|
const config = loadConfig();
|
|
4576
5203
|
const pid = projectId ?? overrides.project ?? config.defaults.project;
|
|
@@ -4652,9 +5279,9 @@ Examples:
|
|
|
4652
5279
|
}
|
|
4653
5280
|
|
|
4654
5281
|
// src/commands/table/index.ts
|
|
4655
|
-
import
|
|
4656
|
-
import * as
|
|
4657
|
-
import * as
|
|
5282
|
+
import chalk16 from "chalk";
|
|
5283
|
+
import * as fs6 from "fs";
|
|
5284
|
+
import * as path4 from "path";
|
|
4658
5285
|
|
|
4659
5286
|
// src/util/table-window.ts
|
|
4660
5287
|
var WINDOW_MAX_ROWS = 100;
|
|
@@ -4806,8 +5433,8 @@ function buildTableEntity(args) {
|
|
|
4806
5433
|
}
|
|
4807
5434
|
|
|
4808
5435
|
// src/commands/table/index.ts
|
|
4809
|
-
import { randomUUID } from "crypto";
|
|
4810
|
-
function
|
|
5436
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
5437
|
+
function getOutputFormat8(cmd) {
|
|
4811
5438
|
const config = loadConfig();
|
|
4812
5439
|
const globalOpts = cmd.optsWithGlobals();
|
|
4813
5440
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4870,7 +5497,7 @@ Examples:
|
|
|
4870
5497
|
;
|
|
4871
5498
|
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
5499
|
try {
|
|
4873
|
-
const outputFormat =
|
|
5500
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
4874
5501
|
const overrides = getOverrides6(cmd);
|
|
4875
5502
|
const resolved = parseEntityReference(ref, overrides);
|
|
4876
5503
|
const api = createApiClient();
|
|
@@ -4879,7 +5506,7 @@ Examples:
|
|
|
4879
5506
|
if (outputFormat === "json") {
|
|
4880
5507
|
format({ rows: [], columns: [], cells: [], totalRows, totalColumns, window: null }, { format: outputFormat });
|
|
4881
5508
|
} else {
|
|
4882
|
-
console.log(
|
|
5509
|
+
console.log(chalk16.dim("Empty table."));
|
|
4883
5510
|
}
|
|
4884
5511
|
return;
|
|
4885
5512
|
}
|
|
@@ -4919,7 +5546,7 @@ Examples:
|
|
|
4919
5546
|
}
|
|
4920
5547
|
} else {
|
|
4921
5548
|
format(tableData, { format: outputFormat, columns: colNames.map((name) => ({ key: name, header: name })) });
|
|
4922
|
-
console.log(
|
|
5549
|
+
console.log(chalk16.dim(describeWindow(window, totalRows, totalColumns)));
|
|
4923
5550
|
}
|
|
4924
5551
|
} catch (error) {
|
|
4925
5552
|
handleError(error);
|
|
@@ -4935,9 +5562,9 @@ Examples:
|
|
|
4935
5562
|
$ diafunc table create --notebook <notebookId>
|
|
4936
5563
|
`).action(async (ref, options, cmd) => {
|
|
4937
5564
|
try {
|
|
4938
|
-
const outputFormat =
|
|
5565
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
4939
5566
|
const overrides = getOverrides6(cmd);
|
|
4940
|
-
const resolved = parseEntityReference(ref ??
|
|
5567
|
+
const resolved = parseEntityReference(ref ?? randomUUID2(), overrides);
|
|
4941
5568
|
if (resolved.entityId.includes(".partition.")) {
|
|
4942
5569
|
throw new CliError(`"${resolved.entityId}" contains ".partition.", which names a table's storage blocks.`, {
|
|
4943
5570
|
exitCode: EXIT_USAGE,
|
|
@@ -4972,17 +5599,17 @@ Examples:
|
|
|
4972
5599
|
try {
|
|
4973
5600
|
const overrides = getOverrides6(cmd);
|
|
4974
5601
|
const resolved = parseEntityReference(ref, overrides);
|
|
4975
|
-
if (!
|
|
5602
|
+
if (!fs6.existsSync(file)) {
|
|
4976
5603
|
failure(`File not found: ${file}`);
|
|
4977
5604
|
process.exit(EXIT_USAGE);
|
|
4978
5605
|
}
|
|
4979
5606
|
const api = createApiClient();
|
|
4980
|
-
const fileBuffer =
|
|
5607
|
+
const fileBuffer = fs6.readFileSync(file);
|
|
4981
5608
|
const blob = new Blob([fileBuffer]);
|
|
4982
5609
|
const formData = new FormData();
|
|
4983
|
-
formData.append("content", blob,
|
|
5610
|
+
formData.append("content", blob, path4.basename(file));
|
|
4984
5611
|
const importId = await withStatus(
|
|
4985
|
-
`Uploading ${
|
|
5612
|
+
`Uploading ${path4.basename(file)}`,
|
|
4986
5613
|
() => api.storage.importTable(resolved, formData, options.selection)
|
|
4987
5614
|
).catch((error) => {
|
|
4988
5615
|
if (error instanceof ApiError && error.status === 404) {
|
|
@@ -4999,7 +5626,7 @@ Examples:
|
|
|
4999
5626
|
const startedAt = Date.now();
|
|
5000
5627
|
try {
|
|
5001
5628
|
for (let i = 0; i < maxAttempts; i++) {
|
|
5002
|
-
await new Promise((
|
|
5629
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
5003
5630
|
const imp = await api.storage.getImport(resolved, importId);
|
|
5004
5631
|
if (imp.finished !== null) {
|
|
5005
5632
|
status.stop();
|
|
@@ -5024,7 +5651,7 @@ Examples:
|
|
|
5024
5651
|
});
|
|
5025
5652
|
table.command("import-formats").description("List supported import formats").action(async (_options, cmd) => {
|
|
5026
5653
|
try {
|
|
5027
|
-
const outputFormat =
|
|
5654
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
5028
5655
|
const api = createApiClient();
|
|
5029
5656
|
const response = await api.storage.getSupportedImportFormats();
|
|
5030
5657
|
if (outputFormat === "json") {
|
|
@@ -5102,7 +5729,7 @@ Examples:
|
|
|
5102
5729
|
const response = await api.storage.streamExport(resolved, format2.id, exportOptions);
|
|
5103
5730
|
const outFile = options.out ?? deriveOutFile(resolved.entityId, format2.extension, options.archive, options.compression);
|
|
5104
5731
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
5105
|
-
|
|
5732
|
+
fs6.writeFileSync(outFile, buffer);
|
|
5106
5733
|
success(`Table streamed to ${outFile}`);
|
|
5107
5734
|
} else {
|
|
5108
5735
|
const exportId = await api.storage.exportTable(resolved, format2.id, exportOptions);
|
|
@@ -5115,7 +5742,7 @@ Examples:
|
|
|
5115
5742
|
});
|
|
5116
5743
|
table.command("export-formats").description("List supported export formats").action(async (_options, cmd) => {
|
|
5117
5744
|
try {
|
|
5118
|
-
const outputFormat =
|
|
5745
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
5119
5746
|
const api = createApiClient();
|
|
5120
5747
|
const response = await api.storage.getSupportedExportFormats();
|
|
5121
5748
|
if (outputFormat === "json") {
|
|
@@ -5131,8 +5758,8 @@ Examples:
|
|
|
5131
5758
|
knownLimitations: f.knownLimitations.join(" / ")
|
|
5132
5759
|
}));
|
|
5133
5760
|
format(rows, { format: outputFormat, columns: ["id", "displayName", "category", "extension", "mimeType", "knownLimitations"] });
|
|
5134
|
-
console.log(
|
|
5135
|
-
console.log(
|
|
5761
|
+
console.log(chalk16.dim(`Compression: ${response.compressionAlgorithms.join(", ")}`));
|
|
5762
|
+
console.log(chalk16.dim(`Archive: ${response.archiveAlgorithms.join(", ")}`));
|
|
5136
5763
|
} catch (error) {
|
|
5137
5764
|
handleError(error);
|
|
5138
5765
|
}
|
|
@@ -5140,7 +5767,7 @@ Examples:
|
|
|
5140
5767
|
const exportsCmd = table.command("exports").description("Track and download async table exports");
|
|
5141
5768
|
exportsCmd.command("list").description("List async exports for a table entity").argument("<ref>", "Table entity reference").action(async (ref, _options, cmd) => {
|
|
5142
5769
|
try {
|
|
5143
|
-
const outputFormat =
|
|
5770
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
5144
5771
|
const overrides = getOverrides6(cmd);
|
|
5145
5772
|
const resolved = parseEntityReference(ref, overrides);
|
|
5146
5773
|
const api = createApiClient();
|
|
@@ -5168,7 +5795,7 @@ Examples:
|
|
|
5168
5795
|
});
|
|
5169
5796
|
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
5797
|
try {
|
|
5171
|
-
const outputFormat =
|
|
5798
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
5172
5799
|
const overrides = getOverrides6(cmd);
|
|
5173
5800
|
const resolved = parseEntityReference(options.ref, overrides);
|
|
5174
5801
|
const api = createApiClient();
|
|
@@ -5184,7 +5811,7 @@ Examples:
|
|
|
5184
5811
|
}
|
|
5185
5812
|
if (exp.finished === null) {
|
|
5186
5813
|
const pct = Math.round((exp.progress ?? 0) * 100);
|
|
5187
|
-
console.log(
|
|
5814
|
+
console.log(chalk16.dim(`Export in progress: ${pct}%. Check again later.`));
|
|
5188
5815
|
return;
|
|
5189
5816
|
}
|
|
5190
5817
|
if (!exp.succeeded) {
|
|
@@ -5195,7 +5822,7 @@ Examples:
|
|
|
5195
5822
|
console.log(`Downloading ${exp.filename} ...`);
|
|
5196
5823
|
const response = await api.storage.downloadExport(resolved, exportId, exp.filename);
|
|
5197
5824
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
5198
|
-
|
|
5825
|
+
fs6.writeFileSync(outFile, buffer);
|
|
5199
5826
|
success(`Export saved to ${outFile}`);
|
|
5200
5827
|
} catch (error) {
|
|
5201
5828
|
handleError(error);
|
|
@@ -5334,10 +5961,10 @@ Examples:
|
|
|
5334
5961
|
}
|
|
5335
5962
|
|
|
5336
5963
|
// src/commands/notebook/index.ts
|
|
5337
|
-
import
|
|
5338
|
-
import * as
|
|
5339
|
-
import * as
|
|
5340
|
-
function
|
|
5964
|
+
import chalk17 from "chalk";
|
|
5965
|
+
import * as fs7 from "fs";
|
|
5966
|
+
import * as path5 from "path";
|
|
5967
|
+
function getOutputFormat9(cmd) {
|
|
5341
5968
|
const config = loadConfig();
|
|
5342
5969
|
const globalOpts = cmd.optsWithGlobals();
|
|
5343
5970
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5369,7 +5996,7 @@ Examples:
|
|
|
5369
5996
|
const response = await api.storage.streamBundle(ref.projectId, ref.projectBranch, request);
|
|
5370
5997
|
const outFile = options.out ?? "notebooks.dfnb";
|
|
5371
5998
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
5372
|
-
|
|
5999
|
+
fs7.writeFileSync(outFile, buffer);
|
|
5373
6000
|
success(`Bundle written to ${outFile} (${buffer.length} bytes, ${notebookIds.length} notebook(s)).`);
|
|
5374
6001
|
} catch (error) {
|
|
5375
6002
|
handleError(error);
|
|
@@ -5377,23 +6004,23 @@ Examples:
|
|
|
5377
6004
|
});
|
|
5378
6005
|
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
6006
|
try {
|
|
5380
|
-
const outputFormat =
|
|
6007
|
+
const outputFormat = getOutputFormat9(cmd);
|
|
5381
6008
|
const overrides = getOverrides7(cmd);
|
|
5382
6009
|
const ref = parseProjectReference(project, overrides);
|
|
5383
6010
|
const api = createApiClient();
|
|
5384
|
-
const fileBuffer =
|
|
6011
|
+
const fileBuffer = fs7.readFileSync(file);
|
|
5385
6012
|
const blob = new Blob([fileBuffer]);
|
|
5386
6013
|
const formData = new FormData();
|
|
5387
|
-
formData.append("content", blob,
|
|
6014
|
+
formData.append("content", blob, path5.basename(file));
|
|
5388
6015
|
if (options.preview) {
|
|
5389
6016
|
const preview = await api.storage.previewBundleImport(ref.projectId, ref.projectBranch, formData);
|
|
5390
6017
|
if (outputFormat === "json") {
|
|
5391
6018
|
format(preview, { format: outputFormat });
|
|
5392
6019
|
return;
|
|
5393
6020
|
}
|
|
5394
|
-
console.log(
|
|
6021
|
+
console.log(chalk17.bold(`${preview.kind} bundle \xB7 ${preview.entityCount} entities`));
|
|
5395
6022
|
if (preview.sourceProjectId) {
|
|
5396
|
-
console.log(
|
|
6023
|
+
console.log(chalk17.dim(`from ${preview.sourceProjectId}/${preview.sourceProjectBranch}` + (preview.createdBy ? ` \xB7 by ${preview.createdBy}` : "")));
|
|
5397
6024
|
}
|
|
5398
6025
|
const counts = /* @__PURE__ */ new Map();
|
|
5399
6026
|
for (const e of preview.entities ?? []) {
|
|
@@ -5403,9 +6030,9 @@ Examples:
|
|
|
5403
6030
|
console.log(` ${type}: ${count}`);
|
|
5404
6031
|
}
|
|
5405
6032
|
if (preview.lossinessNotes && preview.lossinessNotes.length > 0) {
|
|
5406
|
-
console.log(
|
|
6033
|
+
console.log(chalk17.yellow("Lossiness:"));
|
|
5407
6034
|
for (const note of preview.lossinessNotes) {
|
|
5408
|
-
console.log(
|
|
6035
|
+
console.log(chalk17.yellow(` - ${note}`));
|
|
5409
6036
|
}
|
|
5410
6037
|
}
|
|
5411
6038
|
return;
|
|
@@ -5423,7 +6050,7 @@ Examples:
|
|
|
5423
6050
|
});
|
|
5424
6051
|
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
6052
|
try {
|
|
5426
|
-
const outputFormat =
|
|
6053
|
+
const outputFormat = getOutputFormat9(cmd);
|
|
5427
6054
|
const overrides = getOverrides7(cmd);
|
|
5428
6055
|
const ref = parseProjectReference(project, overrides);
|
|
5429
6056
|
const api = createApiClient();
|
|
@@ -5452,22 +6079,22 @@ Examples:
|
|
|
5452
6079
|
}
|
|
5453
6080
|
|
|
5454
6081
|
// src/commands/function/index.ts
|
|
5455
|
-
import
|
|
5456
|
-
import * as
|
|
5457
|
-
import * as
|
|
5458
|
-
import * as
|
|
6082
|
+
import chalk18 from "chalk";
|
|
6083
|
+
import * as fs8 from "fs";
|
|
6084
|
+
import * as os3 from "os";
|
|
6085
|
+
import * as path6 from "path";
|
|
5459
6086
|
import { spawn } from "child_process";
|
|
5460
|
-
import { randomUUID as
|
|
6087
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
5461
6088
|
|
|
5462
6089
|
// src/util/time-uuid.ts
|
|
5463
|
-
import { randomBytes } from "crypto";
|
|
6090
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
5464
6091
|
var GREGORIAN_OFFSET = 122192928000000000n;
|
|
5465
6092
|
var INTERVALS_PER_MILLI = 10000n;
|
|
5466
6093
|
function createTimeUuidGenerator() {
|
|
5467
|
-
const node =
|
|
6094
|
+
const node = randomBytes2(6);
|
|
5468
6095
|
node[0] |= 1;
|
|
5469
6096
|
const nodeHex = node.toString("hex");
|
|
5470
|
-
let clockSequence =
|
|
6097
|
+
let clockSequence = randomBytes2(2).readUInt16BE(0) & 16383;
|
|
5471
6098
|
let lastTimestamp = 0n;
|
|
5472
6099
|
let intervalsWithinMilli = 0n;
|
|
5473
6100
|
return function generate(now = Date.now()) {
|
|
@@ -5555,7 +6182,7 @@ function buildFunctionEntity(args) {
|
|
|
5555
6182
|
}
|
|
5556
6183
|
|
|
5557
6184
|
// src/commands/function/index.ts
|
|
5558
|
-
function
|
|
6185
|
+
function getOutputFormat10(cmd) {
|
|
5559
6186
|
const config = loadConfig();
|
|
5560
6187
|
const globalOpts = cmd.optsWithGlobals();
|
|
5561
6188
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5585,7 +6212,7 @@ Examples:
|
|
|
5585
6212
|
;
|
|
5586
6213
|
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
6214
|
try {
|
|
5588
|
-
const outputFormat =
|
|
6215
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
5589
6216
|
const overrides = getOverrides8(cmd);
|
|
5590
6217
|
const resolved = parseEntityReference(ref, overrides);
|
|
5591
6218
|
const api = createApiClient();
|
|
@@ -5643,7 +6270,7 @@ Examples:
|
|
|
5643
6270
|
const duration = result.completed - result.started;
|
|
5644
6271
|
console.log(` Duration: ${duration}ms`);
|
|
5645
6272
|
} else {
|
|
5646
|
-
console.log(
|
|
6273
|
+
console.log(chalk18.red("Function failed."));
|
|
5647
6274
|
console.log(` Error: ${result.error}`);
|
|
5648
6275
|
if (result.lineNumber > 0) {
|
|
5649
6276
|
console.log(` Line: ${result.lineNumber}, Column: ${result.columnNumber}`);
|
|
@@ -5651,7 +6278,7 @@ Examples:
|
|
|
5651
6278
|
}
|
|
5652
6279
|
if (result.outputs?.length) {
|
|
5653
6280
|
console.log();
|
|
5654
|
-
console.log(
|
|
6281
|
+
console.log(chalk18.bold("Outputs:"));
|
|
5655
6282
|
for (const out of result.outputs) {
|
|
5656
6283
|
console.log(` [${out.type}] ${out.output}`);
|
|
5657
6284
|
}
|
|
@@ -5666,7 +6293,7 @@ Examples:
|
|
|
5666
6293
|
});
|
|
5667
6294
|
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
6295
|
try {
|
|
5669
|
-
const outputFormat =
|
|
6296
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
5670
6297
|
const overrides = getOverrides8(cmd);
|
|
5671
6298
|
const resolved = parseEntityReference(ref, overrides);
|
|
5672
6299
|
const api = createApiClient();
|
|
@@ -5707,7 +6334,7 @@ Examples:
|
|
|
5707
6334
|
});
|
|
5708
6335
|
fn.command("outputs").description("Get outputs for an evaluation").argument("<projectId>", "Project ID").argument("<evaluationId>", "Evaluation ID").action(async (projectId, evaluationId, _options, cmd) => {
|
|
5709
6336
|
try {
|
|
5710
|
-
const outputFormat =
|
|
6337
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
5711
6338
|
const api = createApiClient();
|
|
5712
6339
|
const outputs = await api.evaluation.getOutputs(projectId, evaluationId);
|
|
5713
6340
|
if (outputFormat === "human") {
|
|
@@ -5716,7 +6343,7 @@ Examples:
|
|
|
5716
6343
|
}
|
|
5717
6344
|
for (const out of outputs) {
|
|
5718
6345
|
const time = new Date(out.timestamp).toISOString();
|
|
5719
|
-
console.log(`${
|
|
6346
|
+
console.log(`${chalk18.dim(time)} [${out.type}] ${out.output}`);
|
|
5720
6347
|
}
|
|
5721
6348
|
} else {
|
|
5722
6349
|
format(outputs, { format: outputFormat });
|
|
@@ -5727,7 +6354,7 @@ Examples:
|
|
|
5727
6354
|
});
|
|
5728
6355
|
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
6356
|
try {
|
|
5730
|
-
const outputFormat =
|
|
6357
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
5731
6358
|
const overrides = getOverrides8(cmd);
|
|
5732
6359
|
const resolved = parseEntityReference(ref, overrides);
|
|
5733
6360
|
const api = createApiClient();
|
|
@@ -5773,7 +6400,7 @@ Examples:
|
|
|
5773
6400
|
});
|
|
5774
6401
|
fn.command("languages").description("List the languages a function can be written in").action(async (_options, cmd) => {
|
|
5775
6402
|
try {
|
|
5776
|
-
const outputFormat =
|
|
6403
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
5777
6404
|
format(
|
|
5778
6405
|
FUNCTION_LANGUAGES.map((language) => ({
|
|
5779
6406
|
language,
|
|
@@ -5787,7 +6414,7 @@ Examples:
|
|
|
5787
6414
|
});
|
|
5788
6415
|
fn.command("last-evaluation").description("Show the most recent evaluation of a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
5789
6416
|
try {
|
|
5790
|
-
const outputFormat =
|
|
6417
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
5791
6418
|
const overrides = getOverrides8(cmd);
|
|
5792
6419
|
const resolved = parseEntityReference(ref, overrides);
|
|
5793
6420
|
const api = createApiClient();
|
|
@@ -5807,7 +6434,7 @@ Examples:
|
|
|
5807
6434
|
const overrides = getOverrides8(cmd);
|
|
5808
6435
|
const resolved = parseEntityReference(ref, overrides);
|
|
5809
6436
|
const api = createApiClient();
|
|
5810
|
-
const sourceCode = options.source ?
|
|
6437
|
+
const sourceCode = options.source ? fs8.readFileSync(options.source, "utf-8") : "";
|
|
5811
6438
|
const entity = buildFunctionEntity({
|
|
5812
6439
|
projectId: resolved.projectId,
|
|
5813
6440
|
projectBranch: resolved.projectBranch,
|
|
@@ -5833,7 +6460,7 @@ Examples:
|
|
|
5833
6460
|
const entity = await api.storage.getEntity(resolved, true);
|
|
5834
6461
|
const sourceCode = decodeFunctionSource(entity);
|
|
5835
6462
|
if (options.out) {
|
|
5836
|
-
|
|
6463
|
+
fs8.writeFileSync(options.out, sourceCode);
|
|
5837
6464
|
success(`Source written to ${options.out}`);
|
|
5838
6465
|
} else {
|
|
5839
6466
|
process.stdout.write(sourceCode);
|
|
@@ -5848,13 +6475,13 @@ Examples:
|
|
|
5848
6475
|
const overrides = getOverrides8(cmd);
|
|
5849
6476
|
const resolved = parseEntityReference(ref, overrides);
|
|
5850
6477
|
const api = createApiClient();
|
|
5851
|
-
const sourceCode = file ?
|
|
6478
|
+
const sourceCode = file ? fs8.readFileSync(file, "utf-8") : await new Promise((resolve2, reject) => {
|
|
5852
6479
|
let data = "";
|
|
5853
6480
|
process.stdin.setEncoding("utf-8");
|
|
5854
6481
|
process.stdin.on("data", (chunk) => {
|
|
5855
6482
|
data += chunk;
|
|
5856
6483
|
});
|
|
5857
|
-
process.stdin.on("end", () =>
|
|
6484
|
+
process.stdin.on("end", () => resolve2(data));
|
|
5858
6485
|
process.stdin.on("error", reject);
|
|
5859
6486
|
});
|
|
5860
6487
|
await api.storage.saveEntityContentBase64(resolved, encodeFunctionSource(sourceCode));
|
|
@@ -5872,16 +6499,16 @@ Examples:
|
|
|
5872
6499
|
const currentSource = decodeFunctionSource(entity);
|
|
5873
6500
|
const language = decodeTextAttribute(entity.attributes?.["language"]) ?? "txt";
|
|
5874
6501
|
const ext = extensionFor(language);
|
|
5875
|
-
const tmpFile =
|
|
5876
|
-
|
|
6502
|
+
const tmpFile = path6.join(os3.tmpdir(), `diafunc-${resolved.entityId}-${randomUUID3()}.${ext}`);
|
|
6503
|
+
fs8.writeFileSync(tmpFile, currentSource);
|
|
5877
6504
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
5878
|
-
await new Promise((
|
|
6505
|
+
await new Promise((resolve2, reject) => {
|
|
5879
6506
|
const child = spawn(editor, [tmpFile], { stdio: "inherit" });
|
|
5880
|
-
child.on("exit", (code) => code === 0 ?
|
|
6507
|
+
child.on("exit", (code) => code === 0 ? resolve2() : reject(new Error(`Editor exited with code ${code}`)));
|
|
5881
6508
|
child.on("error", reject);
|
|
5882
6509
|
});
|
|
5883
|
-
const newSource =
|
|
5884
|
-
|
|
6510
|
+
const newSource = fs8.readFileSync(tmpFile, "utf-8");
|
|
6511
|
+
fs8.unlinkSync(tmpFile);
|
|
5885
6512
|
if (newSource === currentSource) {
|
|
5886
6513
|
empty("changes");
|
|
5887
6514
|
return;
|
|
@@ -5904,7 +6531,7 @@ function extensionFor(language) {
|
|
|
5904
6531
|
}
|
|
5905
6532
|
|
|
5906
6533
|
// src/commands/trigger/index.ts
|
|
5907
|
-
function
|
|
6534
|
+
function getOutputFormat11(cmd) {
|
|
5908
6535
|
const config = loadConfig();
|
|
5909
6536
|
const globalOpts = cmd.optsWithGlobals();
|
|
5910
6537
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5923,7 +6550,7 @@ Examples:
|
|
|
5923
6550
|
;
|
|
5924
6551
|
trigger.command("list").description("List triggers for a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
5925
6552
|
try {
|
|
5926
|
-
const outputFormat =
|
|
6553
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
5927
6554
|
const overrides = getOverrides9(cmd);
|
|
5928
6555
|
const resolved = parseEntityReference(ref, overrides);
|
|
5929
6556
|
const api = createApiClient();
|
|
@@ -5951,7 +6578,7 @@ Examples:
|
|
|
5951
6578
|
});
|
|
5952
6579
|
trigger.command("get").description("Get a specific trigger").argument("<ref>", "Function entity reference").argument("<triggerId>", "Trigger ID").action(async (ref, triggerId, _options, cmd) => {
|
|
5953
6580
|
try {
|
|
5954
|
-
const outputFormat =
|
|
6581
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
5955
6582
|
const overrides = getOverrides9(cmd);
|
|
5956
6583
|
const resolved = parseEntityReference(ref, overrides);
|
|
5957
6584
|
const api = createApiClient();
|
|
@@ -6035,7 +6662,7 @@ Examples:
|
|
|
6035
6662
|
}
|
|
6036
6663
|
|
|
6037
6664
|
// src/commands/schedule/index.ts
|
|
6038
|
-
function
|
|
6665
|
+
function getOutputFormat12(cmd) {
|
|
6039
6666
|
const config = loadConfig();
|
|
6040
6667
|
const globalOpts = cmd.optsWithGlobals();
|
|
6041
6668
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -6048,7 +6675,7 @@ function registerScheduleCommands(program) {
|
|
|
6048
6675
|
const schedule = program.command("schedule").description("Schedule function execution");
|
|
6049
6676
|
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
6677
|
try {
|
|
6051
|
-
const outputFormat =
|
|
6678
|
+
const outputFormat = getOutputFormat12(cmd);
|
|
6052
6679
|
const overrides = getOverrides10(cmd);
|
|
6053
6680
|
const resolved = parseEntityReference(ref, overrides);
|
|
6054
6681
|
const api = createApiClient();
|
|
@@ -6117,7 +6744,7 @@ function registerScheduleCommands(program) {
|
|
|
6117
6744
|
});
|
|
6118
6745
|
schedule.command("list").description("List persistent triggers (scheduled functions are modeled as triggers)").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
6119
6746
|
try {
|
|
6120
|
-
const outputFormat =
|
|
6747
|
+
const outputFormat = getOutputFormat12(cmd);
|
|
6121
6748
|
const overrides = getOverrides10(cmd);
|
|
6122
6749
|
const resolved = parseEntityReference(ref, overrides);
|
|
6123
6750
|
const api = createApiClient();
|
|
@@ -6147,12 +6774,12 @@ function registerScheduleCommands(program) {
|
|
|
6147
6774
|
}
|
|
6148
6775
|
|
|
6149
6776
|
// src/commands/chat/index.ts
|
|
6150
|
-
import
|
|
6151
|
-
import * as
|
|
6152
|
-
import * as
|
|
6777
|
+
import chalk20 from "chalk";
|
|
6778
|
+
import * as fs9 from "fs";
|
|
6779
|
+
import * as path7 from "path";
|
|
6153
6780
|
|
|
6154
6781
|
// src/output/markdown.ts
|
|
6155
|
-
import
|
|
6782
|
+
import chalk19 from "chalk";
|
|
6156
6783
|
var CODE_OPEN = "\0c";
|
|
6157
6784
|
var CODE_CLOSE = "\0";
|
|
6158
6785
|
var MarkdownRenderer = class {
|
|
@@ -6188,25 +6815,25 @@ var MarkdownRenderer = class {
|
|
|
6188
6815
|
if (fence) {
|
|
6189
6816
|
const opening = !this.inFence;
|
|
6190
6817
|
this.inFence = !this.inFence;
|
|
6191
|
-
return opening && fence[1] ? [
|
|
6818
|
+
return opening && fence[1] ? [chalk19.dim(` ${fence[1]}`)] : [];
|
|
6192
6819
|
}
|
|
6193
6820
|
if (this.inFence) {
|
|
6194
|
-
return [
|
|
6821
|
+
return [chalk19.cyan(` ${line}`)];
|
|
6195
6822
|
}
|
|
6196
6823
|
const heading2 = line.match(/^(#{1,6})\s+(.*)$/);
|
|
6197
6824
|
if (heading2) {
|
|
6198
6825
|
const text2 = inline(heading2[2]);
|
|
6199
|
-
return ["", heading2[1].length <= 2 ?
|
|
6826
|
+
return ["", heading2[1].length <= 2 ? chalk19.bold.underline(text2) : chalk19.bold(text2)];
|
|
6200
6827
|
}
|
|
6201
6828
|
if (/^\s*([-*_])\1{2,}\s*$/.test(line)) {
|
|
6202
|
-
return [
|
|
6829
|
+
return [chalk19.dim("\u2500".repeat(Math.min(this.width, 60)))];
|
|
6203
6830
|
}
|
|
6204
6831
|
const quote2 = line.match(/^\s*>\s?(.*)$/);
|
|
6205
|
-
if (quote2) return [
|
|
6832
|
+
if (quote2) return [chalk19.dim(` \u2502 ${inline(quote2[1])}`)];
|
|
6206
6833
|
const bullet = line.match(/^(\s*)[-*+]\s+(.*)$/);
|
|
6207
6834
|
if (bullet) {
|
|
6208
6835
|
return wrapWithIndent(
|
|
6209
|
-
`${bullet[1]}${
|
|
6836
|
+
`${bullet[1]}${chalk19.cyan("\u2022")} ${inline(bullet[2])}`,
|
|
6210
6837
|
bullet[1].length + 2,
|
|
6211
6838
|
this.width
|
|
6212
6839
|
);
|
|
@@ -6214,7 +6841,7 @@ var MarkdownRenderer = class {
|
|
|
6214
6841
|
const numbered = line.match(/^(\s*)(\d+)\.\s+(.*)$/);
|
|
6215
6842
|
if (numbered) {
|
|
6216
6843
|
return wrapWithIndent(
|
|
6217
|
-
`${numbered[1]}${
|
|
6844
|
+
`${numbered[1]}${chalk19.cyan(`${numbered[2]}.`)} ${inline(numbered[3])}`,
|
|
6218
6845
|
numbered[1].length + numbered[2].length + 2,
|
|
6219
6846
|
this.width
|
|
6220
6847
|
);
|
|
@@ -6237,15 +6864,15 @@ function inline(text2) {
|
|
|
6237
6864
|
codeSpans.push(code);
|
|
6238
6865
|
return `${CODE_OPEN}${codeSpans.length - 1}${CODE_CLOSE}`;
|
|
6239
6866
|
});
|
|
6240
|
-
working = working.replace(/\*\*([^*]+)\*\*/g, (_m, t) =>
|
|
6867
|
+
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
6868
|
return working.replace(
|
|
6242
6869
|
new RegExp(`${CODE_OPEN}(\\d+)${CODE_CLOSE}`, "g"),
|
|
6243
|
-
(_m, i) =>
|
|
6870
|
+
(_m, i) => chalk19.yellow(codeSpans[Number(i)])
|
|
6244
6871
|
);
|
|
6245
6872
|
}
|
|
6246
6873
|
|
|
6247
6874
|
// src/commands/chat/index.ts
|
|
6248
|
-
function
|
|
6875
|
+
function getOutputFormat13(cmd) {
|
|
6249
6876
|
const config = loadConfig();
|
|
6250
6877
|
const globalOpts = cmd.optsWithGlobals();
|
|
6251
6878
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -6253,7 +6880,7 @@ function getOutputFormat12(cmd) {
|
|
|
6253
6880
|
async function streamOneTurn(message, sessionId, projectId, branch, signal) {
|
|
6254
6881
|
const api = createApiClient();
|
|
6255
6882
|
const status = new Status();
|
|
6256
|
-
status.set([` ${
|
|
6883
|
+
status.set([` ${chalk20.magenta(SPINNER)} ${chalk20.dim("thinking")}`]);
|
|
6257
6884
|
status.start();
|
|
6258
6885
|
let response;
|
|
6259
6886
|
try {
|
|
@@ -6330,19 +6957,19 @@ var HELP = [
|
|
|
6330
6957
|
];
|
|
6331
6958
|
async function runChatRepl(options) {
|
|
6332
6959
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
6333
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
6960
|
+
const { getUpdateNotice } = await import("./update-check-4345HWGE.js");
|
|
6334
6961
|
let sessionId = options.session;
|
|
6335
6962
|
let lastReportedSession;
|
|
6336
|
-
console.log(
|
|
6337
|
-
if (options.project) console.log(
|
|
6338
|
-
if (sessionId) console.log(
|
|
6963
|
+
console.log(chalk20.bold("Diafunc chat") + chalk20.dim(" \xB7 /help for commands, /quit to exit"));
|
|
6964
|
+
if (options.project) console.log(chalk20.dim(`Project context: ${options.project}`));
|
|
6965
|
+
if (sessionId) console.log(chalk20.dim(`Continuing session ${sessionId}`));
|
|
6339
6966
|
const notice = await getUpdateNotice();
|
|
6340
|
-
if (notice) console.log(
|
|
6967
|
+
if (notice) console.log(chalk20.dim(notice));
|
|
6341
6968
|
console.log();
|
|
6342
6969
|
for (; ; ) {
|
|
6343
6970
|
let line;
|
|
6344
6971
|
try {
|
|
6345
|
-
line = await promptInput({ message:
|
|
6972
|
+
line = await promptInput({ message: chalk20.cyan.bold("you >") });
|
|
6346
6973
|
} catch {
|
|
6347
6974
|
console.log();
|
|
6348
6975
|
return;
|
|
@@ -6360,27 +6987,27 @@ async function runChatRepl(options) {
|
|
|
6360
6987
|
case "new":
|
|
6361
6988
|
sessionId = void 0;
|
|
6362
6989
|
lastReportedSession = void 0;
|
|
6363
|
-
console.log(
|
|
6990
|
+
console.log(chalk20.dim("Started a new session."));
|
|
6364
6991
|
continue;
|
|
6365
6992
|
case "clear":
|
|
6366
6993
|
console.clear();
|
|
6367
6994
|
continue;
|
|
6368
6995
|
case "session":
|
|
6369
6996
|
if (!arg) {
|
|
6370
|
-
console.log(
|
|
6997
|
+
console.log(chalk20.dim(`Current session: ${sessionId ?? "(new)"}`));
|
|
6371
6998
|
} else {
|
|
6372
6999
|
sessionId = arg;
|
|
6373
7000
|
lastReportedSession = void 0;
|
|
6374
|
-
console.log(
|
|
7001
|
+
console.log(chalk20.dim(`Switched to session ${sessionId}`));
|
|
6375
7002
|
}
|
|
6376
7003
|
continue;
|
|
6377
7004
|
case "help":
|
|
6378
7005
|
case "h":
|
|
6379
7006
|
case "?":
|
|
6380
|
-
for (const l of HELP) console.log(
|
|
7007
|
+
for (const l of HELP) console.log(chalk20.dim(l));
|
|
6381
7008
|
continue;
|
|
6382
7009
|
default:
|
|
6383
|
-
console.log(
|
|
7010
|
+
console.log(chalk20.dim(`Unknown command: /${cmd}. Try /help.`));
|
|
6384
7011
|
continue;
|
|
6385
7012
|
}
|
|
6386
7013
|
}
|
|
@@ -6393,19 +7020,19 @@ async function runChatRepl(options) {
|
|
|
6393
7020
|
sessionId = result.sessionId || sessionId;
|
|
6394
7021
|
console.log();
|
|
6395
7022
|
if (controller.signal.aborted) {
|
|
6396
|
-
console.log(
|
|
7023
|
+
console.log(chalk20.dim(" (cancelled)"));
|
|
6397
7024
|
} else {
|
|
6398
7025
|
const parts = [`${result.input} in / ${result.output} out`];
|
|
6399
7026
|
if (sessionId && sessionId !== lastReportedSession) {
|
|
6400
7027
|
parts.push(`session ${sessionId}`);
|
|
6401
7028
|
lastReportedSession = sessionId;
|
|
6402
7029
|
}
|
|
6403
|
-
console.log(
|
|
7030
|
+
console.log(chalk20.dim(` ${parts.join(" \xB7 ")}`));
|
|
6404
7031
|
}
|
|
6405
7032
|
console.log();
|
|
6406
7033
|
} catch (error) {
|
|
6407
7034
|
if (controller.signal.aborted) {
|
|
6408
|
-
console.log(
|
|
7035
|
+
console.log(chalk20.dim(" (cancelled)"));
|
|
6409
7036
|
console.log();
|
|
6410
7037
|
} else {
|
|
6411
7038
|
failure(`Request failed: ${error.message}`);
|
|
@@ -6437,7 +7064,7 @@ Examples:
|
|
|
6437
7064
|
});
|
|
6438
7065
|
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
7066
|
try {
|
|
6440
|
-
const outputFormat =
|
|
7067
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
6441
7068
|
const api = createApiClient();
|
|
6442
7069
|
const context = chatContext(cmd);
|
|
6443
7070
|
const response = await api.language.chat({
|
|
@@ -6449,7 +7076,7 @@ Examples:
|
|
|
6449
7076
|
if (outputFormat === "human") {
|
|
6450
7077
|
console.log(renderMarkdown(response.content));
|
|
6451
7078
|
console.log();
|
|
6452
|
-
console.log(
|
|
7079
|
+
console.log(chalk20.dim(
|
|
6453
7080
|
` session ${response.sessionId} \xB7 ${response.inputTokens} in / ${response.outputTokens} out`
|
|
6454
7081
|
));
|
|
6455
7082
|
} else {
|
|
@@ -6461,7 +7088,7 @@ Examples:
|
|
|
6461
7088
|
});
|
|
6462
7089
|
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
7090
|
try {
|
|
6464
|
-
const outputFormat =
|
|
7091
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
6465
7092
|
const api = createApiClient();
|
|
6466
7093
|
const context = chatContext(cmd);
|
|
6467
7094
|
const response = await api.language.chatStream({
|
|
@@ -6517,7 +7144,7 @@ Examples:
|
|
|
6517
7144
|
sessionId = event.sessionId ?? "";
|
|
6518
7145
|
console.log();
|
|
6519
7146
|
console.log();
|
|
6520
|
-
console.log(
|
|
7147
|
+
console.log(chalk20.dim(`Session: ${sessionId} | Tokens: ${event.inputTokens} in, ${event.outputTokens} out`));
|
|
6521
7148
|
} else if (event.type === "error") {
|
|
6522
7149
|
failure(`Error: ${event.content}`);
|
|
6523
7150
|
}
|
|
@@ -6533,15 +7160,15 @@ Examples:
|
|
|
6533
7160
|
});
|
|
6534
7161
|
chat.command("upload").description("Upload a file for chat context").argument("<file>", "File to upload").action(async (file) => {
|
|
6535
7162
|
try {
|
|
6536
|
-
if (!
|
|
7163
|
+
if (!fs9.existsSync(file)) {
|
|
6537
7164
|
failure(`File not found: ${file}`);
|
|
6538
7165
|
process.exit(1);
|
|
6539
7166
|
}
|
|
6540
7167
|
const api = createApiClient();
|
|
6541
|
-
const fileBuffer =
|
|
7168
|
+
const fileBuffer = fs9.readFileSync(file);
|
|
6542
7169
|
const blob = new Blob([fileBuffer]);
|
|
6543
7170
|
const formData = new FormData();
|
|
6544
|
-
formData.append("file", blob,
|
|
7171
|
+
formData.append("file", blob, path7.basename(file));
|
|
6545
7172
|
const result = await api.language.upload(formData);
|
|
6546
7173
|
success(`File uploaded: ${result}`);
|
|
6547
7174
|
} catch (error) {
|
|
@@ -6551,7 +7178,7 @@ Examples:
|
|
|
6551
7178
|
const session = chat.command("session").description("Manage chat sessions");
|
|
6552
7179
|
session.command("list").description("List chat sessions").action(async (_options, cmd) => {
|
|
6553
7180
|
try {
|
|
6554
|
-
const outputFormat =
|
|
7181
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
6555
7182
|
const api = createApiClient();
|
|
6556
7183
|
const sessions = await api.language.getSessions();
|
|
6557
7184
|
format(sessions, {
|
|
@@ -6573,15 +7200,15 @@ Examples:
|
|
|
6573
7200
|
});
|
|
6574
7201
|
session.command("show").description("Show the message history of a chat session").argument("<sessionId>", "Session ID").action(async (sessionId, _options, cmd) => {
|
|
6575
7202
|
try {
|
|
6576
|
-
const outputFormat =
|
|
7203
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
6577
7204
|
const api = createApiClient();
|
|
6578
7205
|
const detail2 = await api.language.getSession(sessionId);
|
|
6579
7206
|
if (outputFormat === "human") {
|
|
6580
|
-
console.log(
|
|
7207
|
+
console.log(chalk20.bold(detail2.title) + chalk20.dim(` (${detail2.sessionId})`));
|
|
6581
7208
|
console.log();
|
|
6582
7209
|
for (const msg of detail2.messages) {
|
|
6583
|
-
const role = msg.role === "user" ?
|
|
6584
|
-
console.log(`${role} ${
|
|
7210
|
+
const role = msg.role === "user" ? chalk20.cyan.bold("You") : chalk20.magenta.bold("Diafunc");
|
|
7211
|
+
console.log(`${role} ${chalk20.dim(msg.created)}`);
|
|
6585
7212
|
console.log(msg.content);
|
|
6586
7213
|
console.log();
|
|
6587
7214
|
}
|
|
@@ -6603,7 +7230,7 @@ Examples:
|
|
|
6603
7230
|
});
|
|
6604
7231
|
chat.command("usage").description("Show token usage").action(async (_options, cmd) => {
|
|
6605
7232
|
try {
|
|
6606
|
-
const outputFormat =
|
|
7233
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
6607
7234
|
const api = createApiClient();
|
|
6608
7235
|
const usage = await api.language.getUsage();
|
|
6609
7236
|
format(usage, { format: outputFormat });
|
|
@@ -6614,8 +7241,8 @@ Examples:
|
|
|
6614
7241
|
}
|
|
6615
7242
|
|
|
6616
7243
|
// src/commands/search/index.ts
|
|
6617
|
-
import
|
|
6618
|
-
function
|
|
7244
|
+
import chalk21 from "chalk";
|
|
7245
|
+
function getOutputFormat14(cmd) {
|
|
6619
7246
|
const config = loadConfig();
|
|
6620
7247
|
const globalOpts = cmd.optsWithGlobals();
|
|
6621
7248
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -6638,7 +7265,7 @@ whose discovered model has the better quality comes first; inside one project th
|
|
|
6638
7265
|
`).action(async (query, options, cmd) => {
|
|
6639
7266
|
const sort = parseSort(options.sort);
|
|
6640
7267
|
try {
|
|
6641
|
-
const outputFormat =
|
|
7268
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
6642
7269
|
const overrides = cmd.optsWithGlobals();
|
|
6643
7270
|
const config = loadConfig();
|
|
6644
7271
|
const api = createApiClient();
|
|
@@ -6676,7 +7303,7 @@ whose discovered model has the better quality comes first; inside one project th
|
|
|
6676
7303
|
});
|
|
6677
7304
|
}
|
|
6678
7305
|
if (page.nextCursor && isInteractive()) {
|
|
6679
|
-
console.log(
|
|
7306
|
+
console.log(chalk21.dim(`More results available. Raise --limit to see them.`));
|
|
6680
7307
|
}
|
|
6681
7308
|
} catch (error) {
|
|
6682
7309
|
handleError(error);
|
|
@@ -6698,12 +7325,12 @@ function renderResults(items) {
|
|
|
6698
7325
|
for (const item of items) {
|
|
6699
7326
|
const name = item.name || "(unnamed)";
|
|
6700
7327
|
console.log();
|
|
6701
|
-
console.log(`${
|
|
7328
|
+
console.log(`${chalk21.dim(`[${item.contentType}]`)} ${chalk21.bold(name)}${qualityNote(item)}`);
|
|
6702
7329
|
const raw = item.snippetField === "name" ? item.description : item.snippet ?? item.description;
|
|
6703
7330
|
const line = raw ? collapse(raw) : null;
|
|
6704
7331
|
if (line && stripHighlight(line) !== name) console.log(` ${highlight(line)}`);
|
|
6705
7332
|
const ref = item.entityId ? `${item.projectId}/${item.projectBranch}/${item.entityId}/${item.entityBranch ?? "main"}` : item.projectId;
|
|
6706
|
-
console.log(` ${
|
|
7333
|
+
console.log(` ${chalk21.dim(ref)}`);
|
|
6707
7334
|
}
|
|
6708
7335
|
console.log();
|
|
6709
7336
|
}
|
|
@@ -6711,16 +7338,16 @@ function qualityNote(item) {
|
|
|
6711
7338
|
if (item.contentType !== "project" || typeof item.quality !== "number" || !Number.isFinite(item.quality)) {
|
|
6712
7339
|
return "";
|
|
6713
7340
|
}
|
|
6714
|
-
return
|
|
7341
|
+
return chalk21.dim(` quality ${percent(item.quality).trim()}`);
|
|
6715
7342
|
}
|
|
6716
7343
|
var HIGHLIGHT_OPEN = /<mark>/g;
|
|
6717
7344
|
var HIGHLIGHT_CLOSE = /<\/mark>/g;
|
|
6718
7345
|
function highlight(text2) {
|
|
6719
7346
|
const parts = text2.split(HIGHLIGHT_OPEN);
|
|
6720
7347
|
return parts.map((part, i) => {
|
|
6721
|
-
if (i === 0) return
|
|
7348
|
+
if (i === 0) return chalk21.dim(part);
|
|
6722
7349
|
const [marked, ...rest] = part.split(HIGHLIGHT_CLOSE);
|
|
6723
|
-
return
|
|
7350
|
+
return chalk21.bold.cyan(marked) + chalk21.dim(rest.join(""));
|
|
6724
7351
|
}).join("");
|
|
6725
7352
|
}
|
|
6726
7353
|
function stripHighlight(text2) {
|
|
@@ -6733,7 +7360,147 @@ function collapse(text2) {
|
|
|
6733
7360
|
|
|
6734
7361
|
// src/commands/admin/index.ts
|
|
6735
7362
|
import { readFile } from "fs/promises";
|
|
6736
|
-
|
|
7363
|
+
|
|
7364
|
+
// src/commands/admin/curated-tags.ts
|
|
7365
|
+
import chalk22 from "chalk";
|
|
7366
|
+
function getOutputFormat15(cmd) {
|
|
7367
|
+
const config = loadConfig();
|
|
7368
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
7369
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
7370
|
+
}
|
|
7371
|
+
var COLUMNS = [
|
|
7372
|
+
{ key: "tag" },
|
|
7373
|
+
{ key: "displayName", header: "name" },
|
|
7374
|
+
{ key: "description" },
|
|
7375
|
+
{ key: "sortOrder", header: "order", kind: "number" },
|
|
7376
|
+
{ key: "projectCount", header: "public projects", kind: "number" }
|
|
7377
|
+
];
|
|
7378
|
+
function curatedTagOf(typed2) {
|
|
7379
|
+
const tag = normalizeTag(typed2);
|
|
7380
|
+
if (tag === "") usageError(`"${typed2}" is not a usable tag: a tag needs at least one letter or digit.`);
|
|
7381
|
+
if (tag !== typed2) console.error(chalk22.dim(`"${typed2}" is written as "${tag}", the form tags are searched by.`));
|
|
7382
|
+
return tag;
|
|
7383
|
+
}
|
|
7384
|
+
function parseSortOrder(raw) {
|
|
7385
|
+
if (!/^-?\d+$/.test(raw.trim())) usageError(`Invalid --sort-order "${raw}": a whole number is expected.`);
|
|
7386
|
+
return Number.parseInt(raw, 10);
|
|
7387
|
+
}
|
|
7388
|
+
function registerCuratedTagCommands(admin) {
|
|
7389
|
+
const curated = admin.command("curated-tags").description('The curated tags: the "data domain" filter of Explore').addHelpText("after", `
|
|
7390
|
+
A curated tag gives a tag a name and a place in Explore's data-domain filter; a project
|
|
7391
|
+
appears under it when it carries the tag (see 'diafunc project tags'). Anyone can list
|
|
7392
|
+
them; creating, updating and deleting need a platform administrator.
|
|
7393
|
+
|
|
7394
|
+
Examples:
|
|
7395
|
+
$ diafunc admin curated-tags list
|
|
7396
|
+
$ diafunc admin curated-tags create health --display-name "Health" --sort-order 1
|
|
7397
|
+
$ diafunc admin curated-tags update health --description "Medicine, public health, biology"
|
|
7398
|
+
$ diafunc admin curated-tags delete health
|
|
7399
|
+
`);
|
|
7400
|
+
curated.command("list").description("List the curated tags in their order, with the number of public projects under each").addHelpText("after", `
|
|
7401
|
+
Needs no account. The counts are of public projects only and can be a minute behind.
|
|
7402
|
+
|
|
7403
|
+
Examples:
|
|
7404
|
+
$ diafunc admin curated-tags list
|
|
7405
|
+
$ diafunc admin curated-tags list -o json
|
|
7406
|
+
`).action(async (_options, cmd) => {
|
|
7407
|
+
try {
|
|
7408
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
7409
|
+
const tags = await createApiClient().index.getCuratedTags(true);
|
|
7410
|
+
if (tags.length === 0) {
|
|
7411
|
+
empty("curated tags", { format: outputFormat });
|
|
7412
|
+
return;
|
|
7413
|
+
}
|
|
7414
|
+
format(tags, { format: outputFormat, columns: COLUMNS });
|
|
7415
|
+
} catch (error) {
|
|
7416
|
+
handleError(error);
|
|
7417
|
+
}
|
|
7418
|
+
});
|
|
7419
|
+
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", `
|
|
7420
|
+
Examples:
|
|
7421
|
+
$ diafunc admin curated-tags create health --display-name "Health" --sort-order 1
|
|
7422
|
+
$ diafunc admin curated-tags create "Machine Learning" --display-name "Machine learning" --dry-run
|
|
7423
|
+
`).action(async (typed2, options, cmd) => {
|
|
7424
|
+
try {
|
|
7425
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
7426
|
+
const tag = curatedTagOf(typed2);
|
|
7427
|
+
if (isReservedTag(tag)) {
|
|
7428
|
+
usageError(`"${tag}" is reserved for the staging content of analysis runs and is never searchable.`);
|
|
7429
|
+
}
|
|
7430
|
+
const displayName = (options.displayName ?? "").trim();
|
|
7431
|
+
if (displayName === "") usageError("--display-name must not be empty.");
|
|
7432
|
+
const request = {
|
|
7433
|
+
tag,
|
|
7434
|
+
displayName,
|
|
7435
|
+
...options.description !== void 0 && options.description.trim() !== "" ? { description: options.description } : {},
|
|
7436
|
+
...options.sortOrder !== void 0 ? { sortOrder: parseSortOrder(options.sortOrder) } : {}
|
|
7437
|
+
};
|
|
7438
|
+
const created = await createApiClient().index.createCuratedTag(request);
|
|
7439
|
+
if (isDryRun()) return;
|
|
7440
|
+
if (outputFormat === "human") {
|
|
7441
|
+
success(`Curated tag "${created.tag}" created.`);
|
|
7442
|
+
} else {
|
|
7443
|
+
format(created, { format: outputFormat });
|
|
7444
|
+
}
|
|
7445
|
+
} catch (error) {
|
|
7446
|
+
handleError(error);
|
|
7447
|
+
}
|
|
7448
|
+
});
|
|
7449
|
+
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", `
|
|
7450
|
+
Only what is given changes. The tag itself cannot be renamed: delete it and create the new one.
|
|
7451
|
+
|
|
7452
|
+
Examples:
|
|
7453
|
+
$ diafunc admin curated-tags update health --display-name "Health and medicine"
|
|
7454
|
+
$ diafunc admin curated-tags update health --description "" clears the description
|
|
7455
|
+
$ diafunc admin curated-tags update health --sort-order 3 --dry-run
|
|
7456
|
+
`).action(async (typed2, options, cmd) => {
|
|
7457
|
+
try {
|
|
7458
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
7459
|
+
const tag = curatedTagOf(typed2);
|
|
7460
|
+
if (options.displayName === void 0 && options.description === void 0 && options.sortOrder === void 0) {
|
|
7461
|
+
usageError("Nothing to change.", "Pass at least one of --display-name, --description, --sort-order.");
|
|
7462
|
+
}
|
|
7463
|
+
if (options.displayName !== void 0 && options.displayName.trim() === "") {
|
|
7464
|
+
usageError("--display-name must not be empty.");
|
|
7465
|
+
}
|
|
7466
|
+
const request = {
|
|
7467
|
+
...options.displayName !== void 0 ? { displayName: options.displayName.trim() } : {},
|
|
7468
|
+
...options.description !== void 0 ? { description: options.description } : {},
|
|
7469
|
+
...options.sortOrder !== void 0 ? { sortOrder: parseSortOrder(options.sortOrder) } : {}
|
|
7470
|
+
};
|
|
7471
|
+
const updated = await createApiClient().index.updateCuratedTag(tag, request);
|
|
7472
|
+
if (isDryRun()) return;
|
|
7473
|
+
if (outputFormat === "human") {
|
|
7474
|
+
success(`Curated tag "${tag}" updated.`);
|
|
7475
|
+
} else {
|
|
7476
|
+
format(updated, { format: outputFormat });
|
|
7477
|
+
}
|
|
7478
|
+
} catch (error) {
|
|
7479
|
+
handleError(error);
|
|
7480
|
+
}
|
|
7481
|
+
});
|
|
7482
|
+
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", `
|
|
7483
|
+
Examples:
|
|
7484
|
+
$ diafunc admin curated-tags delete health
|
|
7485
|
+
$ diafunc admin curated-tags delete health --yes --dry-run
|
|
7486
|
+
`).action(async (typed2, options, cmd) => {
|
|
7487
|
+
try {
|
|
7488
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
7489
|
+
const tag = curatedTagOf(typed2);
|
|
7490
|
+
if (!isDryRun()) {
|
|
7491
|
+
await confirmDestructive(`This removes "${tag}" from Explore's data-domain filter.`, { yes: options.yes, resourceId: tag });
|
|
7492
|
+
}
|
|
7493
|
+
await createApiClient().index.deleteCuratedTag(tag);
|
|
7494
|
+
if (isDryRun()) return;
|
|
7495
|
+
success(`Curated tag "${tag}" deleted.`, { format: outputFormat });
|
|
7496
|
+
} catch (error) {
|
|
7497
|
+
handleError(error);
|
|
7498
|
+
}
|
|
7499
|
+
});
|
|
7500
|
+
}
|
|
7501
|
+
|
|
7502
|
+
// src/commands/admin/index.ts
|
|
7503
|
+
function getOutputFormat16(cmd) {
|
|
6737
7504
|
const config = loadConfig();
|
|
6738
7505
|
const globalOpts = cmd.optsWithGlobals();
|
|
6739
7506
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -6743,7 +7510,7 @@ function registerAdminCommands(program) {
|
|
|
6743
7510
|
const users = admin.command("users").description("Manage users");
|
|
6744
7511
|
users.command("list").description("List all users (admin)").action(async (_options, cmd) => {
|
|
6745
7512
|
try {
|
|
6746
|
-
const outputFormat =
|
|
7513
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6747
7514
|
const api = createApiClient();
|
|
6748
7515
|
const userList = await api.admin.getUsers();
|
|
6749
7516
|
const summary = userList.map((u) => ({
|
|
@@ -6769,7 +7536,7 @@ function registerAdminCommands(program) {
|
|
|
6769
7536
|
});
|
|
6770
7537
|
users.command("get").description("Get current user details").action(async (_options, cmd) => {
|
|
6771
7538
|
try {
|
|
6772
|
-
const outputFormat =
|
|
7539
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6773
7540
|
const api = createApiClient();
|
|
6774
7541
|
const user = await api.admin.getMyUser();
|
|
6775
7542
|
format(user, { format: outputFormat });
|
|
@@ -6779,7 +7546,7 @@ function registerAdminCommands(program) {
|
|
|
6779
7546
|
});
|
|
6780
7547
|
admin.command("subscription").description("Show current subscription").action(async (_options, cmd) => {
|
|
6781
7548
|
try {
|
|
6782
|
-
const outputFormat =
|
|
7549
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6783
7550
|
const api = createApiClient();
|
|
6784
7551
|
const sub = await api.admin.getCurrentSubscription();
|
|
6785
7552
|
format(sub, { format: outputFormat });
|
|
@@ -6790,7 +7557,7 @@ function registerAdminCommands(program) {
|
|
|
6790
7557
|
const settings = admin.command("settings").description("Manage settings");
|
|
6791
7558
|
settings.command("get").description("Get current settings").action(async (_options, cmd) => {
|
|
6792
7559
|
try {
|
|
6793
|
-
const outputFormat =
|
|
7560
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6794
7561
|
const api = createApiClient();
|
|
6795
7562
|
const s = await api.admin.getSettings();
|
|
6796
7563
|
format(s, { format: outputFormat });
|
|
@@ -6810,7 +7577,7 @@ function registerAdminCommands(program) {
|
|
|
6810
7577
|
const platformSettings = admin.command("platform-settings").description("Manage platform-wide settings (admin only)");
|
|
6811
7578
|
platformSettings.command("list").description("Show every platform setting with its default and current override").action(async (_options, cmd) => {
|
|
6812
7579
|
try {
|
|
6813
|
-
const outputFormat =
|
|
7580
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6814
7581
|
const api = createApiClient();
|
|
6815
7582
|
const settingsList = await api.admin.listPlatformSettings();
|
|
6816
7583
|
format(settingsList, { format: outputFormat });
|
|
@@ -6897,9 +7664,10 @@ function registerAdminCommands(program) {
|
|
|
6897
7664
|
handleError(error);
|
|
6898
7665
|
}
|
|
6899
7666
|
});
|
|
7667
|
+
registerCuratedTagCommands(admin);
|
|
6900
7668
|
admin.command("permissions").description("Show your permissions on a project").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
6901
7669
|
try {
|
|
6902
|
-
const outputFormat =
|
|
7670
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
6903
7671
|
const api = createApiClient();
|
|
6904
7672
|
const perm = await api.admin.getPermissions(projectId);
|
|
6905
7673
|
format({ projectId, permission: perm }, { format: outputFormat });
|
|
@@ -6912,7 +7680,7 @@ function registerAdminCommands(program) {
|
|
|
6912
7680
|
contract.command("get", { isDefault: true }).description("Show a team's contract").argument("<teamId>", "Team ID").action(async (teamId, _options, cmd) => {
|
|
6913
7681
|
try {
|
|
6914
7682
|
const api = createApiClient();
|
|
6915
|
-
format(await api.admin.getTeamContract(teamId), { format:
|
|
7683
|
+
format(await api.admin.getTeamContract(teamId), { format: getOutputFormat16(cmd) });
|
|
6916
7684
|
} catch (error) {
|
|
6917
7685
|
handleError(error);
|
|
6918
7686
|
}
|
|
@@ -6925,7 +7693,7 @@ function registerAdminCommands(program) {
|
|
|
6925
7693
|
{ yes: options.yes, resourceId: teamId }
|
|
6926
7694
|
);
|
|
6927
7695
|
const api = createApiClient();
|
|
6928
|
-
format(await api.admin.issueTeamContract(teamId, request), { format:
|
|
7696
|
+
format(await api.admin.issueTeamContract(teamId, request), { format: getOutputFormat16(cmd) });
|
|
6929
7697
|
} catch (error) {
|
|
6930
7698
|
handleError(error);
|
|
6931
7699
|
}
|
|
@@ -6933,14 +7701,14 @@ function registerAdminCommands(program) {
|
|
|
6933
7701
|
}
|
|
6934
7702
|
|
|
6935
7703
|
// src/commands/status/summary.ts
|
|
6936
|
-
import
|
|
7704
|
+
import chalk23 from "chalk";
|
|
6937
7705
|
|
|
6938
7706
|
// src/client/services/status.ts
|
|
6939
7707
|
function createStatusService() {
|
|
6940
7708
|
const config = loadConfig();
|
|
6941
7709
|
const endpoint = resolveEndpoint(config);
|
|
6942
|
-
async function fetchJson(
|
|
6943
|
-
const url = `${endpoint}/status/v1${
|
|
7710
|
+
async function fetchJson(path13) {
|
|
7711
|
+
const url = `${endpoint}/status/v1${path13}`;
|
|
6944
7712
|
const response = await fetch(url, {
|
|
6945
7713
|
headers: { "Accept": "application/json" }
|
|
6946
7714
|
});
|
|
@@ -6959,24 +7727,24 @@ function createStatusService() {
|
|
|
6959
7727
|
|
|
6960
7728
|
// src/commands/status/summary.ts
|
|
6961
7729
|
var STATE_COLORS = {
|
|
6962
|
-
UP:
|
|
6963
|
-
DEGRADED:
|
|
6964
|
-
DOWN:
|
|
6965
|
-
UNKNOWN:
|
|
7730
|
+
UP: chalk23.green,
|
|
7731
|
+
DEGRADED: chalk23.yellow,
|
|
7732
|
+
DOWN: chalk23.red,
|
|
7733
|
+
UNKNOWN: chalk23.gray
|
|
6966
7734
|
};
|
|
6967
7735
|
function stateColor(state) {
|
|
6968
|
-
return STATE_COLORS[state] ??
|
|
7736
|
+
return STATE_COLORS[state] ?? chalk23.gray;
|
|
6969
7737
|
}
|
|
6970
7738
|
function stateSymbol(state) {
|
|
6971
7739
|
switch (state) {
|
|
6972
7740
|
case "UP":
|
|
6973
|
-
return
|
|
7741
|
+
return chalk23.green("\u25CF");
|
|
6974
7742
|
case "DEGRADED":
|
|
6975
|
-
return
|
|
7743
|
+
return chalk23.yellow("\u25CF");
|
|
6976
7744
|
case "DOWN":
|
|
6977
|
-
return
|
|
7745
|
+
return chalk23.red("\u25CF");
|
|
6978
7746
|
default:
|
|
6979
|
-
return
|
|
7747
|
+
return chalk23.gray("\u25CB");
|
|
6980
7748
|
}
|
|
6981
7749
|
}
|
|
6982
7750
|
function registerSummaryCommand(parent) {
|
|
@@ -7001,20 +7769,20 @@ function registerSummaryCommand(parent) {
|
|
|
7001
7769
|
const label = stateColor(domain.state)(domain.state.padEnd(10));
|
|
7002
7770
|
console.log(` ${stateSymbol(domain.state)} ${label} ${domain.name}`);
|
|
7003
7771
|
if (domain.componentIds.length > 0) {
|
|
7004
|
-
console.log(` ${
|
|
7772
|
+
console.log(` ${chalk23.dim(domain.componentIds.join(", "))}`);
|
|
7005
7773
|
}
|
|
7006
7774
|
}
|
|
7007
7775
|
console.log();
|
|
7008
7776
|
if (summary.openIncidents > 0) {
|
|
7009
|
-
console.log(
|
|
7777
|
+
console.log(chalk23.yellow(` ${summary.openIncidents} active incident(s)`));
|
|
7010
7778
|
} else {
|
|
7011
|
-
console.log(
|
|
7779
|
+
console.log(chalk23.dim(" No active incidents"));
|
|
7012
7780
|
}
|
|
7013
|
-
console.log(
|
|
7781
|
+
console.log(chalk23.dim(
|
|
7014
7782
|
`
|
|
7015
7783
|
Platform v${version.platformVersion} \xB7 checked ${formatInstant(summary.timestamp)}`
|
|
7016
7784
|
));
|
|
7017
|
-
console.log(
|
|
7785
|
+
console.log(chalk23.dim(` Drill into one with 'diafunc status component <id>'.`));
|
|
7018
7786
|
console.log();
|
|
7019
7787
|
} catch (error) {
|
|
7020
7788
|
handleError(error);
|
|
@@ -7023,17 +7791,17 @@ function registerSummaryCommand(parent) {
|
|
|
7023
7791
|
}
|
|
7024
7792
|
|
|
7025
7793
|
// src/commands/status/component.ts
|
|
7026
|
-
import
|
|
7794
|
+
import chalk24 from "chalk";
|
|
7027
7795
|
function stateSymbol2(state) {
|
|
7028
7796
|
switch (state) {
|
|
7029
7797
|
case "UP":
|
|
7030
|
-
return
|
|
7798
|
+
return chalk24.green("\u25CF");
|
|
7031
7799
|
case "DEGRADED":
|
|
7032
|
-
return
|
|
7800
|
+
return chalk24.yellow("\u25CF");
|
|
7033
7801
|
case "DOWN":
|
|
7034
|
-
return
|
|
7802
|
+
return chalk24.red("\u25CF");
|
|
7035
7803
|
default:
|
|
7036
|
-
return
|
|
7804
|
+
return chalk24.gray("\u25CB");
|
|
7037
7805
|
}
|
|
7038
7806
|
}
|
|
7039
7807
|
function registerComponentCommand(parent) {
|
|
@@ -7058,7 +7826,7 @@ function registerComponentCommand(parent) {
|
|
|
7058
7826
|
return;
|
|
7059
7827
|
}
|
|
7060
7828
|
console.log();
|
|
7061
|
-
console.log(` ${stateSymbol2(match.state)} ${
|
|
7829
|
+
console.log(` ${stateSymbol2(match.state)} ${chalk24.bold(match.id)} ${match.version ? chalk24.dim("v" + match.version) : ""}`);
|
|
7062
7830
|
console.log(` State: ${renderState(match.state)}`);
|
|
7063
7831
|
if (match.lastCheckAt) {
|
|
7064
7832
|
console.log(` Last check: ${formatInstant(match.lastCheckAt)}`);
|
|
@@ -7067,7 +7835,7 @@ function registerComponentCommand(parent) {
|
|
|
7067
7835
|
console.log();
|
|
7068
7836
|
console.log(" Checks:");
|
|
7069
7837
|
for (const check of match.checks) {
|
|
7070
|
-
const cat = check.category ?
|
|
7838
|
+
const cat = check.category ? chalk24.dim(` (${check.category})`) : "";
|
|
7071
7839
|
console.log(` ${stateSymbol2(check.state)} ${check.name}${cat}`);
|
|
7072
7840
|
}
|
|
7073
7841
|
}
|
|
@@ -7079,12 +7847,12 @@ function registerComponentCommand(parent) {
|
|
|
7079
7847
|
}
|
|
7080
7848
|
|
|
7081
7849
|
// src/commands/status/incidents.ts
|
|
7082
|
-
import
|
|
7850
|
+
import chalk25 from "chalk";
|
|
7083
7851
|
var SEVERITY_COLORS = {
|
|
7084
|
-
ERROR:
|
|
7085
|
-
WARNING:
|
|
7086
|
-
INFO:
|
|
7087
|
-
MAINTENANCE:
|
|
7852
|
+
ERROR: chalk25.red,
|
|
7853
|
+
WARNING: chalk25.yellow,
|
|
7854
|
+
INFO: chalk25.blue,
|
|
7855
|
+
MAINTENANCE: chalk25.cyan
|
|
7088
7856
|
};
|
|
7089
7857
|
function registerIncidentsCommand(parent) {
|
|
7090
7858
|
parent.command("incidents").description("List recent incidents").option("-w, --window <window>", "Time window (e.g. 24h, 48h)", "24h").action(async (options, cmd) => {
|
|
@@ -7098,22 +7866,22 @@ function registerIncidentsCommand(parent) {
|
|
|
7098
7866
|
return;
|
|
7099
7867
|
}
|
|
7100
7868
|
if (incidents.length === 0) {
|
|
7101
|
-
console.log(
|
|
7869
|
+
console.log(chalk25.dim(`
|
|
7102
7870
|
No incidents in the last ${options.window}.
|
|
7103
7871
|
`));
|
|
7104
7872
|
return;
|
|
7105
7873
|
}
|
|
7106
7874
|
console.log();
|
|
7107
7875
|
for (const incident of incidents) {
|
|
7108
|
-
const color = SEVERITY_COLORS[incident.severity] ??
|
|
7876
|
+
const color = SEVERITY_COLORS[incident.severity] ?? chalk25.gray;
|
|
7109
7877
|
const severity = color(incident.severity.padEnd(8));
|
|
7110
7878
|
const time = incident.startedAt ? new Date(incident.startedAt).toLocaleString() : "";
|
|
7111
|
-
const resolved = incident.resolvedAt ?
|
|
7879
|
+
const resolved = incident.resolvedAt ? chalk25.green(" [resolved]") : chalk25.yellow(" [open]");
|
|
7112
7880
|
console.log(` ${severity} ${incident.summary}${resolved}`);
|
|
7113
|
-
console.log(
|
|
7881
|
+
console.log(chalk25.dim(` ${time}`));
|
|
7114
7882
|
for (const update of incident.updates) {
|
|
7115
7883
|
const updateTime = new Date(update.at).toLocaleTimeString();
|
|
7116
|
-
console.log(
|
|
7884
|
+
console.log(chalk25.dim(` ${updateTime} ${update.status} ${update.message}`));
|
|
7117
7885
|
}
|
|
7118
7886
|
console.log();
|
|
7119
7887
|
}
|
|
@@ -7138,12 +7906,12 @@ Examples:
|
|
|
7138
7906
|
}
|
|
7139
7907
|
|
|
7140
7908
|
// src/commands/analyze/index.ts
|
|
7141
|
-
import * as
|
|
7142
|
-
import * as
|
|
7909
|
+
import * as fs11 from "fs";
|
|
7910
|
+
import * as path9 from "path";
|
|
7143
7911
|
import { spawn as spawn2 } from "child_process";
|
|
7144
7912
|
|
|
7145
7913
|
// src/commands/analyze/watch-view.ts
|
|
7146
|
-
import
|
|
7914
|
+
import chalk26 from "chalk";
|
|
7147
7915
|
|
|
7148
7916
|
// src/client/types/analysis.ts
|
|
7149
7917
|
var RUN_PHASE_LABELS = {
|
|
@@ -7280,25 +8048,25 @@ function renderWatchBlock(input) {
|
|
|
7280
8048
|
const lines = [];
|
|
7281
8049
|
const step = stepCounter(run);
|
|
7282
8050
|
const headline = [
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
step ?
|
|
8051
|
+
chalk26.cyan(SPINNER),
|
|
8052
|
+
chalk26.bold(phaseLabel(run)),
|
|
8053
|
+
step ? chalk26.dim(step) : null
|
|
7286
8054
|
].filter(Boolean).join(" ");
|
|
7287
8055
|
lines.push(` ${headline}`);
|
|
7288
8056
|
const fraction = overallProgress(run);
|
|
7289
|
-
const elapsed =
|
|
8057
|
+
const elapsed = chalk26.dim(formatDurationPrecise(elapsedMs));
|
|
7290
8058
|
if (fraction === null) {
|
|
7291
|
-
lines.push(` ${
|
|
8059
|
+
lines.push(` ${chalk26.dim("working")} ${elapsed}`);
|
|
7292
8060
|
} else {
|
|
7293
8061
|
const ceiling = remainingCeiling(run, budgetHours);
|
|
7294
8062
|
lines.push(
|
|
7295
|
-
` ${bar(fraction)} ${percent(fraction)} ${elapsed}` + (ceiling !== null ?
|
|
8063
|
+
` ${bar(fraction)} ${percent(fraction)} ${elapsed}` + (ceiling !== null ? chalk26.dim(` \xB7 at most ${formatDurationPrecise(ceiling)} remaining`) : "")
|
|
7296
8064
|
);
|
|
7297
8065
|
}
|
|
7298
8066
|
const detail2 = caption ?? phaseDetail(run);
|
|
7299
|
-
if (detail2) lines.push(` ${
|
|
8067
|
+
if (detail2) lines.push(` ${chalk26.dim(detail2)}`);
|
|
7300
8068
|
if (run.retryAttempts && run.retryAttempts > 0) {
|
|
7301
|
-
lines.push(` ${
|
|
8069
|
+
lines.push(` ${chalk26.yellow("!")} ${chalk26.dim(
|
|
7302
8070
|
`restarted ${run.retryAttempts === 1 ? "once" : `${run.retryAttempts} times`} after an interruption; progress restarts from the beginning`
|
|
7303
8071
|
)}`);
|
|
7304
8072
|
}
|
|
@@ -7306,7 +8074,7 @@ function renderWatchBlock(input) {
|
|
|
7306
8074
|
}
|
|
7307
8075
|
|
|
7308
8076
|
// src/commands/analyze/wizard.ts
|
|
7309
|
-
import
|
|
8077
|
+
import chalk27 from "chalk";
|
|
7310
8078
|
|
|
7311
8079
|
// src/commands/analyze/columns.ts
|
|
7312
8080
|
var MAX_COLUMNS_LISTED = 30;
|
|
@@ -7561,7 +8329,7 @@ async function promptRunFields(prompter, options) {
|
|
|
7561
8329
|
targets = await prompter.checkbox({
|
|
7562
8330
|
message: "Target columns: what should the analysis predict?",
|
|
7563
8331
|
choices: named.map((c) => ({
|
|
7564
|
-
name: c.valueType ? `${c.name} ${
|
|
8332
|
+
name: c.valueType ? `${c.name} ${chalk27.dim(`(${c.valueType})`)}` : c.name,
|
|
7565
8333
|
value: c.name,
|
|
7566
8334
|
checked: preselected.has(c.name)
|
|
7567
8335
|
})),
|
|
@@ -7590,7 +8358,7 @@ async function promptRunFields(prompter, options) {
|
|
|
7590
8358
|
choices: [
|
|
7591
8359
|
{ name: "No segmentation", value: null },
|
|
7592
8360
|
...remaining.map((c) => ({
|
|
7593
|
-
name: c.valueType ? `${c.name} ${
|
|
8361
|
+
name: c.valueType ? `${c.name} ${chalk27.dim(`(${c.valueType})`)}` : c.name,
|
|
7594
8362
|
value: c.name
|
|
7595
8363
|
}))
|
|
7596
8364
|
]
|
|
@@ -7773,7 +8541,7 @@ function whyNoPrompt(outputFormat, noInteractive) {
|
|
|
7773
8541
|
}
|
|
7774
8542
|
|
|
7775
8543
|
// src/commands/analyze/data-import.ts
|
|
7776
|
-
import
|
|
8544
|
+
import chalk28 from "chalk";
|
|
7777
8545
|
|
|
7778
8546
|
// src/commands/analyze/details.ts
|
|
7779
8547
|
function analysisDetails(analysis, endpoint) {
|
|
@@ -7897,19 +8665,19 @@ function constraintsText(analysis) {
|
|
|
7897
8665
|
var IMPORT_POLL_INTERVAL_MS = 2e3;
|
|
7898
8666
|
function renderImportBlock(dataImport, elapsedMs) {
|
|
7899
8667
|
const title = dataImport.state === "STOPPING" ? "Stopping the data import" : "Importing data";
|
|
7900
|
-
const lines = [` ${
|
|
7901
|
-
const elapsed =
|
|
8668
|
+
const lines = [` ${chalk28.cyan(SPINNER)} ${chalk28.bold(title)}`];
|
|
8669
|
+
const elapsed = chalk28.dim(formatDurationPrecise(elapsedMs));
|
|
7902
8670
|
if (dataImport.state === "IMPORTING" && dataImport.progress !== null && dataImport.progress !== void 0) {
|
|
7903
8671
|
lines.push(` ${bar(dataImport.progress)} ${percent(dataImport.progress)} ${elapsed}`);
|
|
7904
8672
|
} else {
|
|
7905
|
-
lines.push(` ${
|
|
8673
|
+
lines.push(` ${chalk28.dim(dataImport.message)} ${elapsed}`);
|
|
7906
8674
|
}
|
|
7907
8675
|
return lines;
|
|
7908
8676
|
}
|
|
7909
8677
|
function sleep3(ms) {
|
|
7910
8678
|
let timer;
|
|
7911
|
-
const done = new Promise((
|
|
7912
|
-
timer = setTimeout(() =>
|
|
8679
|
+
const done = new Promise((resolve2) => {
|
|
8680
|
+
timer = setTimeout(() => resolve2("elapsed"), ms);
|
|
7913
8681
|
});
|
|
7914
8682
|
return { done, cancel: () => clearTimeout(timer) };
|
|
7915
8683
|
}
|
|
@@ -7921,8 +8689,8 @@ async function followImport(ctx, first) {
|
|
|
7921
8689
|
const status = new Status();
|
|
7922
8690
|
let interrupt = () => {
|
|
7923
8691
|
};
|
|
7924
|
-
const interrupted = new Promise((
|
|
7925
|
-
interrupt = () =>
|
|
8692
|
+
const interrupted = new Promise((resolve2) => {
|
|
8693
|
+
interrupt = () => resolve2("interrupted");
|
|
7926
8694
|
});
|
|
7927
8695
|
process.once("SIGINT", interrupt);
|
|
7928
8696
|
if (ctx.live) {
|
|
@@ -7934,10 +8702,10 @@ async function followImport(ctx, first) {
|
|
|
7934
8702
|
try {
|
|
7935
8703
|
for (; ; ) {
|
|
7936
8704
|
if (ctx.live) status.set(renderImportBlock(current, Date.now() - since));
|
|
7937
|
-
const
|
|
7938
|
-
const woke = await Promise.race([
|
|
8705
|
+
const pause2 = sleep3(IMPORT_POLL_INTERVAL_MS);
|
|
8706
|
+
const woke = await Promise.race([pause2.done, interrupted]);
|
|
7939
8707
|
if (woke === "interrupted") {
|
|
7940
|
-
|
|
8708
|
+
pause2.cancel();
|
|
7941
8709
|
status.stop();
|
|
7942
8710
|
warn("Stopped waiting. The import keeps running on the platform.");
|
|
7943
8711
|
hint(`See how far it is with 'diafunc analyze get ${analysisId}'.`);
|
|
@@ -8070,8 +8838,8 @@ async function queueRun(api, analysisId) {
|
|
|
8070
8838
|
}
|
|
8071
8839
|
|
|
8072
8840
|
// src/commands/analyze/sources.ts
|
|
8073
|
-
import * as
|
|
8074
|
-
import * as
|
|
8841
|
+
import * as fs10 from "fs";
|
|
8842
|
+
import * as path8 from "path";
|
|
8075
8843
|
var CAUTIONS = /* @__PURE__ */ new Set([
|
|
8076
8844
|
"UNEVEN_COLUMNS",
|
|
8077
8845
|
"TYPE_CONFLICT",
|
|
@@ -8092,7 +8860,7 @@ function recipeWithChoices(proposal, choices) {
|
|
|
8092
8860
|
return { parts: proposal.parts, originColumn, dropDuplicates, lookups: proposal.lookups ?? [] };
|
|
8093
8861
|
}
|
|
8094
8862
|
function labelOf(file) {
|
|
8095
|
-
return
|
|
8863
|
+
return path8.basename(file, path8.extname(file)).trim().toLowerCase();
|
|
8096
8864
|
}
|
|
8097
8865
|
function otherRowsLabel(proposal) {
|
|
8098
8866
|
const alternative = (proposal.lookups ?? []).find((lookup) => lookup.alternative)?.alternative;
|
|
@@ -8112,7 +8880,7 @@ function recipeWithRowsOf(proposal, rowsOf) {
|
|
|
8112
8880
|
function sourcesAsUploaded(uploaded, asUploaded) {
|
|
8113
8881
|
const chosen = [];
|
|
8114
8882
|
for (const name of asUploaded) {
|
|
8115
|
-
const wanted =
|
|
8883
|
+
const wanted = path8.basename(name).trim().toLowerCase();
|
|
8116
8884
|
const matches = uploaded.filter((source) => {
|
|
8117
8885
|
const fileName = source.fileName.trim().toLowerCase();
|
|
8118
8886
|
return fileName === wanted || labelOf(fileName) === labelOf(wanted);
|
|
@@ -8165,12 +8933,12 @@ function planLines(plan) {
|
|
|
8165
8933
|
}
|
|
8166
8934
|
function multipart(file) {
|
|
8167
8935
|
const formData = new FormData();
|
|
8168
|
-
formData.append("content", new Blob([
|
|
8936
|
+
formData.append("content", new Blob([fs10.readFileSync(file)]), path8.basename(file));
|
|
8169
8937
|
return formData;
|
|
8170
8938
|
}
|
|
8171
8939
|
async function uploadSeveral(api, analysisId, files, choices, human) {
|
|
8172
8940
|
for (const file of files) {
|
|
8173
|
-
if (!
|
|
8941
|
+
if (!fs10.existsSync(file)) {
|
|
8174
8942
|
throw new CliError(`File not found: ${file}`, { exitCode: EXIT_USAGE });
|
|
8175
8943
|
}
|
|
8176
8944
|
}
|
|
@@ -8179,7 +8947,7 @@ async function uploadSeveral(api, analysisId, files, choices, human) {
|
|
|
8179
8947
|
}
|
|
8180
8948
|
const uploaded = [];
|
|
8181
8949
|
for (const file of files) {
|
|
8182
|
-
uploaded.push(await withStatus(`Uploading ${
|
|
8950
|
+
uploaded.push(await withStatus(`Uploading ${path8.basename(file)}`, () => api.analysis.addSource(analysisId, multipart(file))));
|
|
8183
8951
|
}
|
|
8184
8952
|
for (const source of sourcesAsUploaded(uploaded, choices.asUploaded ?? [])) {
|
|
8185
8953
|
await api.analysis.updateSource(analysisId, source.sourceId, { asUploaded: true });
|
|
@@ -8229,7 +8997,7 @@ function openUrl(url) {
|
|
|
8229
8997
|
const args = process.platform === "win32" ? ["/c", "start", '""', url] : [url];
|
|
8230
8998
|
spawn2(cmd, args, { detached: true, stdio: "ignore" }).unref();
|
|
8231
8999
|
}
|
|
8232
|
-
function
|
|
9000
|
+
function getOutputFormat17(cmd) {
|
|
8233
9001
|
const config = loadConfig();
|
|
8234
9002
|
const globalOpts = cmd.optsWithGlobals();
|
|
8235
9003
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -8238,7 +9006,7 @@ function noInteractiveFlag(cmd) {
|
|
|
8238
9006
|
return cmd.optsWithGlobals().interactive === false;
|
|
8239
9007
|
}
|
|
8240
9008
|
function importContext(api, analysisId, cmd, machineReport) {
|
|
8241
|
-
const outputFormat =
|
|
9009
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8242
9010
|
const noInteractive = noInteractiveFlag(cmd);
|
|
8243
9011
|
return {
|
|
8244
9012
|
api,
|
|
@@ -8290,10 +9058,10 @@ function budgetHoursOf(hours) {
|
|
|
8290
9058
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
|
8291
9059
|
}
|
|
8292
9060
|
function multipartFromFile(file) {
|
|
8293
|
-
const buffer =
|
|
9061
|
+
const buffer = fs11.readFileSync(file);
|
|
8294
9062
|
const blob = new Blob([buffer]);
|
|
8295
9063
|
const formData = new FormData();
|
|
8296
|
-
formData.append("content", blob,
|
|
9064
|
+
formData.append("content", blob, path9.basename(file));
|
|
8297
9065
|
return formData;
|
|
8298
9066
|
}
|
|
8299
9067
|
function reportCommandError(error) {
|
|
@@ -8302,13 +9070,13 @@ function reportCommandError(error) {
|
|
|
8302
9070
|
}
|
|
8303
9071
|
async function runAnalysis(files, options, cmd) {
|
|
8304
9072
|
for (const candidate of files) {
|
|
8305
|
-
if (!
|
|
9073
|
+
if (!fs11.existsSync(candidate)) {
|
|
8306
9074
|
failure(`File not found: ${candidate}`);
|
|
8307
9075
|
process.exit(EXIT_FAILURE);
|
|
8308
9076
|
}
|
|
8309
9077
|
}
|
|
8310
9078
|
const file = files[0];
|
|
8311
|
-
const outputFormat =
|
|
9079
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8312
9080
|
const noInteractive = noInteractiveFlag(cmd);
|
|
8313
9081
|
const interactive = canPrompt(outputFormat, noInteractive);
|
|
8314
9082
|
const api = createApiClient();
|
|
@@ -8332,11 +9100,11 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8332
9100
|
if (!interactive && !targetsGiven) {
|
|
8333
9101
|
usageError(
|
|
8334
9102
|
`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" :
|
|
9103
|
+
`Pass --targets <columns> or --preset <id>. The names are the column headers of ${files.length > 1 ? "the files" : path9.basename(file)}.`
|
|
8336
9104
|
);
|
|
8337
9105
|
}
|
|
8338
9106
|
const prompter = createInquirerPrompter();
|
|
8339
|
-
const fallbackName =
|
|
9107
|
+
const fallbackName = path9.basename(file, path9.extname(file));
|
|
8340
9108
|
const creation = interactive ? await promptCreationFields(prompter, {
|
|
8341
9109
|
name: options.name,
|
|
8342
9110
|
description: options.description,
|
|
@@ -8360,7 +9128,7 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8360
9128
|
};
|
|
8361
9129
|
const created = await withStatus(`Creating analysis "${creation.name}"`, () => api.analysis.create(request));
|
|
8362
9130
|
if (isDryRun()) {
|
|
8363
|
-
hint(`Dry run: nothing was created. A real run would upload ${
|
|
9131
|
+
hint(`Dry run: nothing was created. A real run would upload ${path9.basename(file)}, queue the analysis and follow it.`);
|
|
8364
9132
|
return;
|
|
8365
9133
|
}
|
|
8366
9134
|
detail(`analysisId: ${created.analysisId}`);
|
|
@@ -8411,9 +9179,9 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8411
9179
|
}
|
|
8412
9180
|
function namedColumns(analysisId, columns, interactive, given) {
|
|
8413
9181
|
const names = columns.map((c) => c.name).filter((name) => name && name.length > 0);
|
|
8414
|
-
const read = (
|
|
9182
|
+
const read = (resolve2) => {
|
|
8415
9183
|
try {
|
|
8416
|
-
return
|
|
9184
|
+
return resolve2();
|
|
8417
9185
|
} catch (error) {
|
|
8418
9186
|
if (!(error instanceof CliError)) throw error;
|
|
8419
9187
|
if (!interactive) {
|
|
@@ -8477,11 +9245,12 @@ async function readDepthDefault(api, stored) {
|
|
|
8477
9245
|
}
|
|
8478
9246
|
async function readColumns(api, analysisId) {
|
|
8479
9247
|
for (let attempt = 0; attempt < COLUMN_READ_ATTEMPTS; attempt++) {
|
|
8480
|
-
if (attempt > 0) await new Promise((
|
|
9248
|
+
if (attempt > 0) await new Promise((resolve2) => setTimeout(resolve2, COLUMN_READ_INTERVAL_MS));
|
|
8481
9249
|
try {
|
|
8482
9250
|
const columns = await api.analysis.getColumns(analysisId);
|
|
8483
9251
|
if (columns.length > 0) return columns;
|
|
8484
|
-
} catch {
|
|
9252
|
+
} catch (error) {
|
|
9253
|
+
if (isAuthenticationFailure(error)) throw error;
|
|
8485
9254
|
}
|
|
8486
9255
|
}
|
|
8487
9256
|
warn("Could not read the column names from the uploaded file.");
|
|
@@ -8496,7 +9265,7 @@ async function readPresets(api) {
|
|
|
8496
9265
|
}
|
|
8497
9266
|
async function monitorRun(api, analysisId, runId, budgetHours, cmd) {
|
|
8498
9267
|
const config = loadConfig();
|
|
8499
|
-
const outputFormat =
|
|
9268
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8500
9269
|
const human = outputFormat === "human";
|
|
8501
9270
|
const status = new Status();
|
|
8502
9271
|
const seenOutputs = /* @__PURE__ */ new Set();
|
|
@@ -8506,13 +9275,14 @@ async function monitorRun(api, analysisId, runId, budgetHours, cmd) {
|
|
|
8506
9275
|
if (human) status.start();
|
|
8507
9276
|
try {
|
|
8508
9277
|
for (; ; ) {
|
|
8509
|
-
await new Promise((
|
|
9278
|
+
await new Promise((resolve2) => setTimeout(resolve2, POLL_INTERVAL_MS));
|
|
8510
9279
|
let run = null;
|
|
8511
9280
|
let absent = false;
|
|
8512
9281
|
try {
|
|
8513
9282
|
run = (await api.analysis.getRun(runId)).run;
|
|
8514
9283
|
absent = run === null;
|
|
8515
9284
|
} catch (error) {
|
|
9285
|
+
if (isAuthenticationFailure(error)) throw error;
|
|
8516
9286
|
absent = error instanceof ApiError && error.status === 404;
|
|
8517
9287
|
}
|
|
8518
9288
|
if (!run) {
|
|
@@ -8540,7 +9310,8 @@ async function monitorRun(api, analysisId, runId, budgetHours, cmd) {
|
|
|
8540
9310
|
}
|
|
8541
9311
|
}
|
|
8542
9312
|
}
|
|
8543
|
-
} catch {
|
|
9313
|
+
} catch (error) {
|
|
9314
|
+
if (isAuthenticationFailure(error)) throw error;
|
|
8544
9315
|
}
|
|
8545
9316
|
if (isTerminalState(run.state)) {
|
|
8546
9317
|
status.stop();
|
|
@@ -8618,7 +9389,7 @@ async function printNotebookLink(api, config, analysisId) {
|
|
|
8618
9389
|
}
|
|
8619
9390
|
}
|
|
8620
9391
|
async function listAnalyses(limit, cmd) {
|
|
8621
|
-
const outputFormat =
|
|
9392
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8622
9393
|
const api = createApiClient();
|
|
8623
9394
|
const analyses = await api.analysis.getRecent(limit);
|
|
8624
9395
|
format(analyses.map((a) => ({
|
|
@@ -8648,7 +9419,7 @@ async function listAnalyses(limit, cmd) {
|
|
|
8648
9419
|
});
|
|
8649
9420
|
}
|
|
8650
9421
|
async function getAnalysisDetails(analysisId, options, cmd) {
|
|
8651
|
-
const outputFormat =
|
|
9422
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8652
9423
|
const api = createApiClient();
|
|
8653
9424
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
8654
9425
|
if (!result.analysis) {
|
|
@@ -8716,7 +9487,7 @@ async function rerunAnalysis(analysisId, cmd) {
|
|
|
8716
9487
|
const analysis = found.analysis;
|
|
8717
9488
|
const missing = missingRunFields(analysis);
|
|
8718
9489
|
if (missing.length > 0) {
|
|
8719
|
-
const outputFormat =
|
|
9490
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8720
9491
|
const noInteractive = noInteractiveFlag(cmd);
|
|
8721
9492
|
if (!canPrompt(outputFormat, noInteractive)) {
|
|
8722
9493
|
const { message, suggestion } = explainMissingRunFields(
|
|
@@ -8777,7 +9548,7 @@ function typedColumns(given) {
|
|
|
8777
9548
|
return entries === void 0 ? null : resolveColumnArguments(entries, []);
|
|
8778
9549
|
}
|
|
8779
9550
|
async function createAnalysis(options, cmd) {
|
|
8780
|
-
const outputFormat =
|
|
9551
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8781
9552
|
const api = createApiClient();
|
|
8782
9553
|
const visibility = parseVisibility(options.visibility);
|
|
8783
9554
|
const request = {
|
|
@@ -8807,7 +9578,7 @@ async function deleteAnalysis(analysisId) {
|
|
|
8807
9578
|
success(`Deleted analysis ${analysisId}.`);
|
|
8808
9579
|
}
|
|
8809
9580
|
async function patchAndPrint(analysisId, value, handler, successLabel, cmd) {
|
|
8810
|
-
const outputFormat =
|
|
9581
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8811
9582
|
const api = createApiClient();
|
|
8812
9583
|
const updated = await handler(api, analysisId, value);
|
|
8813
9584
|
if (isDryRun()) {
|
|
@@ -8847,19 +9618,19 @@ function stackChoices(options, files) {
|
|
|
8847
9618
|
}
|
|
8848
9619
|
async function uploadOne(api, analysisId, file, asUploaded, human) {
|
|
8849
9620
|
const uploaded = await withStatus(
|
|
8850
|
-
`Uploading ${
|
|
9621
|
+
`Uploading ${path9.basename(file)}`,
|
|
8851
9622
|
() => api.analysis.uploadDataMultipart(analysisId, multipartFromFile(file))
|
|
8852
9623
|
);
|
|
8853
9624
|
if (isDryRun() || uploaded.dataImport) return uploaded;
|
|
8854
9625
|
if (asUploaded.length > 0) {
|
|
8855
|
-
sourcesAsUploaded([{ fileName:
|
|
9626
|
+
sourcesAsUploaded([{ fileName: path9.basename(file) }], asUploaded);
|
|
8856
9627
|
return uploaded;
|
|
8857
9628
|
}
|
|
8858
9629
|
return await reshapeSingle(api, analysisId, human) ?? uploaded;
|
|
8859
9630
|
}
|
|
8860
9631
|
async function uploadData(analysisId, files, options, cmd) {
|
|
8861
9632
|
const api = createApiClient();
|
|
8862
|
-
const outputFormat =
|
|
9633
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8863
9634
|
const ctx = importContext(api, analysisId, cmd, "none");
|
|
8864
9635
|
const file = files[0];
|
|
8865
9636
|
if (files.length > 1) {
|
|
@@ -8891,7 +9662,7 @@ async function uploadData(analysisId, files, options, cmd) {
|
|
|
8891
9662
|
`For example: diafunc analyze upload ${analysisId} data.csv`
|
|
8892
9663
|
);
|
|
8893
9664
|
}
|
|
8894
|
-
if (!
|
|
9665
|
+
if (!fs11.existsSync(file)) {
|
|
8895
9666
|
throw new CliError(`File not found: ${file}`, { exitCode: EXIT_USAGE });
|
|
8896
9667
|
}
|
|
8897
9668
|
}
|
|
@@ -8909,7 +9680,7 @@ async function uploadData(analysisId, files, options, cmd) {
|
|
|
8909
9680
|
}
|
|
8910
9681
|
}
|
|
8911
9682
|
async function stopDataImport(analysisId, cmd) {
|
|
8912
|
-
const outputFormat =
|
|
9683
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8913
9684
|
const api = createApiClient();
|
|
8914
9685
|
const stopped = await withStatus("Stopping the data import", () => stopImport(api, analysisId));
|
|
8915
9686
|
if (isDryRun()) {
|
|
@@ -8932,7 +9703,7 @@ async function stopDataImport(analysisId, cmd) {
|
|
|
8932
9703
|
warn(stopped.dataImport.message);
|
|
8933
9704
|
}
|
|
8934
9705
|
async function listColumns(analysisId, cmd) {
|
|
8935
|
-
const outputFormat =
|
|
9706
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8936
9707
|
const api = createApiClient();
|
|
8937
9708
|
const columns = await api.analysis.getColumns(analysisId);
|
|
8938
9709
|
if (columns.length === 0) {
|
|
@@ -8943,7 +9714,7 @@ async function listColumns(analysisId, cmd) {
|
|
|
8943
9714
|
format(columns, { format: outputFormat, columns: ["name", "valueType"] });
|
|
8944
9715
|
}
|
|
8945
9716
|
async function listRuns(analysisId, count, cmd) {
|
|
8946
|
-
const outputFormat =
|
|
9717
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8947
9718
|
const api = createApiClient();
|
|
8948
9719
|
const runs = await api.analysis.getRunsForAnalysis(analysisId, count);
|
|
8949
9720
|
format(runs.map((r) => ({
|
|
@@ -8966,7 +9737,7 @@ async function listRuns(analysisId, count, cmd) {
|
|
|
8966
9737
|
});
|
|
8967
9738
|
}
|
|
8968
9739
|
async function cancelRun(runId, cmd) {
|
|
8969
|
-
const outputFormat =
|
|
9740
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8970
9741
|
const api = createApiClient();
|
|
8971
9742
|
const run = await api.analysis.cancelRun(runId);
|
|
8972
9743
|
if (outputFormat === "human") {
|
|
@@ -8980,7 +9751,7 @@ async function cancelRun(runId, cmd) {
|
|
|
8980
9751
|
}
|
|
8981
9752
|
}
|
|
8982
9753
|
async function listPresets(cmd) {
|
|
8983
|
-
const outputFormat =
|
|
9754
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
8984
9755
|
const api = createApiClient();
|
|
8985
9756
|
const presets = await api.analysis.getPresets();
|
|
8986
9757
|
format(presets.map((p) => ({
|
|
@@ -9005,7 +9776,7 @@ async function listPresets(cmd) {
|
|
|
9005
9776
|
});
|
|
9006
9777
|
}
|
|
9007
9778
|
async function getPreset(presetId, cmd) {
|
|
9008
|
-
const outputFormat =
|
|
9779
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
9009
9780
|
const api = createApiClient();
|
|
9010
9781
|
const opt = await api.analysis.getPreset(presetId);
|
|
9011
9782
|
if (!opt.preset) {
|
|
@@ -9015,7 +9786,7 @@ async function getPreset(presetId, cmd) {
|
|
|
9015
9786
|
format(opt.preset, { format: outputFormat });
|
|
9016
9787
|
}
|
|
9017
9788
|
async function savePreset(options, cmd) {
|
|
9018
|
-
const outputFormat =
|
|
9789
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
9019
9790
|
const api = createApiClient();
|
|
9020
9791
|
const preset = {
|
|
9021
9792
|
presetId: options.id ?? null,
|
|
@@ -9070,7 +9841,7 @@ function triggerChanges(options) {
|
|
|
9070
9841
|
};
|
|
9071
9842
|
}
|
|
9072
9843
|
async function listTriggers(analysisId, cmd) {
|
|
9073
|
-
const outputFormat =
|
|
9844
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
9074
9845
|
const api = createApiClient();
|
|
9075
9846
|
const triggers = await api.analysis.listTriggers(analysisId);
|
|
9076
9847
|
format(triggers.map(triggerRow), {
|
|
@@ -9087,7 +9858,7 @@ async function listTriggers(analysisId, cmd) {
|
|
|
9087
9858
|
});
|
|
9088
9859
|
}
|
|
9089
9860
|
async function createTrigger(analysisId, kind, schedule, cmd, refreshFirst = false) {
|
|
9090
|
-
const outputFormat =
|
|
9861
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
9091
9862
|
const upper = kind.toUpperCase();
|
|
9092
9863
|
if (upper !== "ONCE" && upper !== "CRON") {
|
|
9093
9864
|
failure(`Invalid kind "${kind}". Use ONCE or CRON.`);
|
|
@@ -9107,7 +9878,7 @@ async function deleteTrigger(triggerId) {
|
|
|
9107
9878
|
success(`Deleted trigger ${triggerId}.`);
|
|
9108
9879
|
}
|
|
9109
9880
|
async function updateTriggerCmd(triggerId, options, cmd) {
|
|
9110
|
-
const outputFormat =
|
|
9881
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
9111
9882
|
const changes = triggerChanges(options);
|
|
9112
9883
|
const api = createApiClient();
|
|
9113
9884
|
const trigger = await api.analysis.updateTrigger(triggerId, changes);
|
|
@@ -9425,7 +10196,7 @@ function registerAnalyzeCommand(program) {
|
|
|
9425
10196
|
// src/commands/public/index.ts
|
|
9426
10197
|
var MIN_LIMIT = 1;
|
|
9427
10198
|
var MAX_LIMIT = 500;
|
|
9428
|
-
function
|
|
10199
|
+
function getOutputFormat18(cmd) {
|
|
9429
10200
|
const config = loadConfig();
|
|
9430
10201
|
const globalOpts = cmd.optsWithGlobals();
|
|
9431
10202
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9477,7 +10248,7 @@ async function readPublicAnalyses(analysis, options) {
|
|
|
9477
10248
|
}
|
|
9478
10249
|
}
|
|
9479
10250
|
async function listPublicAnalyses(options, cmd) {
|
|
9480
|
-
const outputFormat =
|
|
10251
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
9481
10252
|
const limit = parseLimit(options.limit);
|
|
9482
10253
|
const changedSince = options.changedSince === void 0 ? void 0 : parseChangedSince(options.changedSince);
|
|
9483
10254
|
const api = createApiClient();
|
|
@@ -9519,7 +10290,7 @@ function newestRunRecord(run) {
|
|
|
9519
10290
|
};
|
|
9520
10291
|
}
|
|
9521
10292
|
async function showPublicAnalysis(analysisId, cmd) {
|
|
9522
|
-
const outputFormat =
|
|
10293
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
9523
10294
|
const api = createApiClient();
|
|
9524
10295
|
const result = await api.analysis.get(analysisId);
|
|
9525
10296
|
if (!result?.analysis) {
|
|
@@ -9588,8 +10359,8 @@ Examples:
|
|
|
9588
10359
|
}
|
|
9589
10360
|
|
|
9590
10361
|
// src/commands/data-sources/index.ts
|
|
9591
|
-
import
|
|
9592
|
-
function
|
|
10362
|
+
import chalk29 from "chalk";
|
|
10363
|
+
function getOutputFormat19(cmd) {
|
|
9593
10364
|
const config = loadConfig();
|
|
9594
10365
|
const globalOpts = cmd.optsWithGlobals();
|
|
9595
10366
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9689,7 +10460,7 @@ function resolveProjectId(cmd) {
|
|
|
9689
10460
|
return resolved;
|
|
9690
10461
|
}
|
|
9691
10462
|
async function listDataSources(projectId, cmd) {
|
|
9692
|
-
const outputFormat =
|
|
10463
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9693
10464
|
const api = createApiClient();
|
|
9694
10465
|
const sources = await api.storage.listDataSources(projectId);
|
|
9695
10466
|
if (outputFormat === "human" && sources.length === 0) {
|
|
@@ -9710,13 +10481,13 @@ async function listDataSources(projectId, cmd) {
|
|
|
9710
10481
|
});
|
|
9711
10482
|
}
|
|
9712
10483
|
async function getDataSource(id, cmd) {
|
|
9713
|
-
const outputFormat =
|
|
10484
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9714
10485
|
const api = createApiClient();
|
|
9715
10486
|
const ds = await api.storage.getDataSource(id);
|
|
9716
10487
|
format(ds, { format: outputFormat });
|
|
9717
10488
|
}
|
|
9718
10489
|
async function showDashboard(projectId, cmd) {
|
|
9719
|
-
const outputFormat =
|
|
10490
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9720
10491
|
const api = createApiClient();
|
|
9721
10492
|
const dashboard = await api.storage.getDataSourceDashboard(projectId);
|
|
9722
10493
|
if (outputFormat !== "human") {
|
|
@@ -9724,7 +10495,7 @@ async function showDashboard(projectId, cmd) {
|
|
|
9724
10495
|
return;
|
|
9725
10496
|
}
|
|
9726
10497
|
const r = dashboard.rollup;
|
|
9727
|
-
let line =
|
|
10498
|
+
let line = chalk29.bold(`DataSources in ${projectId}: `) + `${r.totalSources} total, ${r.scheduledSources} scheduled, ${r.sourcesWithRecentFailure} failing recently`;
|
|
9728
10499
|
if (r.lastActivityAt) line += `, last activity ${r.lastActivityAt}`;
|
|
9729
10500
|
console.log(line);
|
|
9730
10501
|
if (dashboard.sources.length === 0) {
|
|
@@ -9785,14 +10556,14 @@ async function createForAnalysis(api, options, human) {
|
|
|
9785
10556
|
if (human) {
|
|
9786
10557
|
success(`Added ${source.fileName} to analysis ${analysisId} from data source ${source.dataSourceId ?? ""}`.trimEnd());
|
|
9787
10558
|
for (const line of planLines(build.plan)) {
|
|
9788
|
-
console.log(line.caution ?
|
|
10559
|
+
console.log(line.caution ? chalk29.yellow(` ${line.text}`) : chalk29.dim(` ${line.text}`));
|
|
9789
10560
|
}
|
|
9790
|
-
console.log(
|
|
10561
|
+
console.log(chalk29.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
10562
|
}
|
|
9792
10563
|
return { source, build };
|
|
9793
10564
|
}
|
|
9794
10565
|
async function createDataSource(options, cmd) {
|
|
9795
|
-
const outputFormat =
|
|
10566
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9796
10567
|
const target = createTarget(options);
|
|
9797
10568
|
const api = createApiClient();
|
|
9798
10569
|
if (target === "analysis") {
|
|
@@ -9815,14 +10586,14 @@ async function createDataSource(options, cmd) {
|
|
|
9815
10586
|
const ds = await api.storage.createDataSource(request);
|
|
9816
10587
|
if (outputFormat === "human") {
|
|
9817
10588
|
success(`Created data source ${ds.id}`);
|
|
9818
|
-
console.log(
|
|
9819
|
-
if (ds.lastRunError) console.log(
|
|
10589
|
+
console.log(chalk29.dim(` Last run: ${ds.lastRunStatus ?? "\u2014"}`));
|
|
10590
|
+
if (ds.lastRunError) console.log(chalk29.dim(` Error: ${ds.lastRunError}`));
|
|
9820
10591
|
} else {
|
|
9821
10592
|
format(ds, { format: outputFormat });
|
|
9822
10593
|
}
|
|
9823
10594
|
}
|
|
9824
10595
|
async function updateDataSource(id, options, cmd) {
|
|
9825
|
-
const outputFormat =
|
|
10596
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9826
10597
|
if (options.name === void 0 && options.type === void 0 && (!options.config || options.config.length === 0) && options.scheduleCron === void 0 && !options.clearSchedule) {
|
|
9827
10598
|
throw new Error("Provide at least one of --name, --type, --config, --schedule-cron, or --clear-schedule.");
|
|
9828
10599
|
}
|
|
@@ -9857,18 +10628,18 @@ async function deleteDataSource(id) {
|
|
|
9857
10628
|
success(`Deleted data source ${id}`);
|
|
9858
10629
|
}
|
|
9859
10630
|
async function refreshDataSource(id, cmd) {
|
|
9860
|
-
const outputFormat =
|
|
10631
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9861
10632
|
const api = createApiClient();
|
|
9862
10633
|
const run = await api.storage.refreshDataSource(id);
|
|
9863
10634
|
if (outputFormat === "human") {
|
|
9864
10635
|
success(`Refresh queued: run ${run.runId}, status ${run.status}.`);
|
|
9865
|
-
if (run.errorMessage) console.log(
|
|
10636
|
+
if (run.errorMessage) console.log(chalk29.red(` Error: ${run.errorMessage}`));
|
|
9866
10637
|
} else {
|
|
9867
10638
|
format(run, { format: outputFormat });
|
|
9868
10639
|
}
|
|
9869
10640
|
}
|
|
9870
10641
|
async function listRuns2(id, limit, cmd) {
|
|
9871
|
-
const outputFormat =
|
|
10642
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9872
10643
|
const api = createApiClient();
|
|
9873
10644
|
const runs = await api.storage.listDataSourceRuns(id, limit);
|
|
9874
10645
|
if (outputFormat === "human" && runs.length === 0) {
|
|
@@ -9890,13 +10661,13 @@ async function listRuns2(id, limit, cmd) {
|
|
|
9890
10661
|
});
|
|
9891
10662
|
}
|
|
9892
10663
|
async function getRun(id, runId, cmd) {
|
|
9893
|
-
const outputFormat =
|
|
10664
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9894
10665
|
const api = createApiClient();
|
|
9895
10666
|
const run = await api.storage.getDataSourceRun(id, runId);
|
|
9896
10667
|
format(run, { format: outputFormat });
|
|
9897
10668
|
}
|
|
9898
10669
|
async function listConnectorTypes(cmd) {
|
|
9899
|
-
const outputFormat =
|
|
10670
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
9900
10671
|
const api = createApiClient();
|
|
9901
10672
|
const types = await api.storage.listDataSourceConnectorTypes();
|
|
9902
10673
|
if (outputFormat === "human") {
|
|
@@ -9989,8 +10760,8 @@ Examples:
|
|
|
9989
10760
|
}
|
|
9990
10761
|
|
|
9991
10762
|
// src/commands/table-exporters/index.ts
|
|
9992
|
-
import
|
|
9993
|
-
function
|
|
10763
|
+
import chalk30 from "chalk";
|
|
10764
|
+
function getOutputFormat20(cmd) {
|
|
9994
10765
|
const config = loadConfig();
|
|
9995
10766
|
const globalOpts = cmd.optsWithGlobals();
|
|
9996
10767
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -9999,7 +10770,7 @@ function registerTableExportersCommands(program) {
|
|
|
9999
10770
|
const exporters = program.command("table-exporters").description("Manage user-defined exporters (UDE); admin only");
|
|
10000
10771
|
exporters.command("list").description("List all registered user-defined exporters").action(async (_options, cmd) => {
|
|
10001
10772
|
try {
|
|
10002
|
-
const outputFormat =
|
|
10773
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
10003
10774
|
const api = createApiClient();
|
|
10004
10775
|
const list = await api.storage.listUserDefinedExporters();
|
|
10005
10776
|
if (outputFormat === "json") {
|
|
@@ -10020,14 +10791,14 @@ function registerTableExportersCommands(program) {
|
|
|
10020
10791
|
format: outputFormat,
|
|
10021
10792
|
columns: ["id", "name", "format", "extension", "mimeType", "priority", "function", "createdBy"]
|
|
10022
10793
|
});
|
|
10023
|
-
console.log(
|
|
10794
|
+
console.log(chalk30.dim(`${list.length} exporter(s)`));
|
|
10024
10795
|
} catch (error) {
|
|
10025
10796
|
handleError(error);
|
|
10026
10797
|
}
|
|
10027
10798
|
});
|
|
10028
10799
|
exporters.command("get").description("Show a single user-defined exporter by id").argument("<id>", "Exporter id").action(async (id, _options, cmd) => {
|
|
10029
10800
|
try {
|
|
10030
|
-
const outputFormat =
|
|
10801
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
10031
10802
|
const api = createApiClient();
|
|
10032
10803
|
const list = await api.storage.listUserDefinedExporters();
|
|
10033
10804
|
const exporter = list.find((e) => e.id === id);
|
|
@@ -10042,7 +10813,7 @@ function registerTableExportersCommands(program) {
|
|
|
10042
10813
|
});
|
|
10043
10814
|
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
10815
|
try {
|
|
10045
|
-
const outputFormat =
|
|
10816
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
10046
10817
|
const api = createApiClient();
|
|
10047
10818
|
const payload = {
|
|
10048
10819
|
name: options.name,
|
|
@@ -10078,9 +10849,9 @@ function registerTableExportersCommands(program) {
|
|
|
10078
10849
|
}
|
|
10079
10850
|
|
|
10080
10851
|
// src/commands/skeleton/index.ts
|
|
10081
|
-
import
|
|
10082
|
-
import * as
|
|
10083
|
-
function
|
|
10852
|
+
import chalk31 from "chalk";
|
|
10853
|
+
import * as fs12 from "fs";
|
|
10854
|
+
function getOutputFormat21(cmd) {
|
|
10084
10855
|
const config = loadConfig();
|
|
10085
10856
|
const globalOpts = cmd.optsWithGlobals();
|
|
10086
10857
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -10103,10 +10874,10 @@ function resolveTemplate(raw) {
|
|
|
10103
10874
|
if (!file) {
|
|
10104
10875
|
throw new Error("--template @ requires a filename after the @, e.g. --template @template.txt");
|
|
10105
10876
|
}
|
|
10106
|
-
if (!
|
|
10877
|
+
if (!fs12.existsSync(file)) {
|
|
10107
10878
|
throw new Error(`Template file not found: ${file}`);
|
|
10108
10879
|
}
|
|
10109
|
-
return
|
|
10880
|
+
return fs12.readFileSync(file, "utf-8").trim();
|
|
10110
10881
|
}
|
|
10111
10882
|
return raw;
|
|
10112
10883
|
}
|
|
@@ -10129,7 +10900,7 @@ function skeletonTableRow(s) {
|
|
|
10129
10900
|
};
|
|
10130
10901
|
}
|
|
10131
10902
|
async function createSkeleton(options, cmd) {
|
|
10132
|
-
const outputFormat =
|
|
10903
|
+
const outputFormat = getOutputFormat21(cmd);
|
|
10133
10904
|
const projectId = resolveProjectId2(cmd);
|
|
10134
10905
|
const template = resolveTemplate(options.template);
|
|
10135
10906
|
const weight = parseWeight(options.weight);
|
|
@@ -10145,16 +10916,16 @@ async function createSkeleton(options, cmd) {
|
|
|
10145
10916
|
const skeleton = await api.storage.createSkeleton(request);
|
|
10146
10917
|
if (outputFormat === "human") {
|
|
10147
10918
|
success(`Created skeleton ${skeleton.id}`);
|
|
10148
|
-
console.log(
|
|
10149
|
-
console.log(
|
|
10150
|
-
console.log(
|
|
10151
|
-
console.log(
|
|
10919
|
+
console.log(chalk31.dim(` name: ${skeleton.name}`));
|
|
10920
|
+
console.log(chalk31.dim(` template: ${skeleton.template}`));
|
|
10921
|
+
console.log(chalk31.dim(` paramCount: ${skeleton.paramCount}`));
|
|
10922
|
+
console.log(chalk31.dim(` weight: ${skeleton.weight}`));
|
|
10152
10923
|
} else {
|
|
10153
10924
|
format(skeleton, { format: outputFormat });
|
|
10154
10925
|
}
|
|
10155
10926
|
}
|
|
10156
10927
|
async function listSkeletons(cmd) {
|
|
10157
|
-
const outputFormat =
|
|
10928
|
+
const outputFormat = getOutputFormat21(cmd);
|
|
10158
10929
|
const projectId = resolveProjectId2(cmd);
|
|
10159
10930
|
const api = createApiClient();
|
|
10160
10931
|
const skeletons = await api.storage.listSkeletons(projectId);
|
|
@@ -10168,13 +10939,13 @@ async function listSkeletons(cmd) {
|
|
|
10168
10939
|
});
|
|
10169
10940
|
}
|
|
10170
10941
|
async function getSkeleton(id, cmd) {
|
|
10171
|
-
const outputFormat =
|
|
10942
|
+
const outputFormat = getOutputFormat21(cmd);
|
|
10172
10943
|
const api = createApiClient();
|
|
10173
10944
|
const skeleton = await api.storage.getSkeleton(id);
|
|
10174
10945
|
format(skeleton, { format: outputFormat });
|
|
10175
10946
|
}
|
|
10176
10947
|
async function updateSkeleton(id, options, cmd) {
|
|
10177
|
-
const outputFormat =
|
|
10948
|
+
const outputFormat = getOutputFormat21(cmd);
|
|
10178
10949
|
if (options.name === void 0 && options.template === void 0 && options.weight === void 0) {
|
|
10179
10950
|
throw new Error("Provide at least one of --name, --template, --weight.");
|
|
10180
10951
|
}
|
|
@@ -10187,10 +10958,10 @@ async function updateSkeleton(id, options, cmd) {
|
|
|
10187
10958
|
const skeleton = await api.storage.updateSkeleton(id, request);
|
|
10188
10959
|
if (outputFormat === "human") {
|
|
10189
10960
|
success(`Updated skeleton ${skeleton.id}`);
|
|
10190
|
-
console.log(
|
|
10191
|
-
console.log(
|
|
10192
|
-
console.log(
|
|
10193
|
-
console.log(
|
|
10961
|
+
console.log(chalk31.dim(` name: ${skeleton.name}`));
|
|
10962
|
+
console.log(chalk31.dim(` template: ${skeleton.template}`));
|
|
10963
|
+
console.log(chalk31.dim(` paramCount: ${skeleton.paramCount}`));
|
|
10964
|
+
console.log(chalk31.dim(` weight: ${skeleton.weight}`));
|
|
10194
10965
|
} else {
|
|
10195
10966
|
format(skeleton, { format: outputFormat });
|
|
10196
10967
|
}
|
|
@@ -10275,17 +11046,21 @@ _diafunc_completions() {
|
|
|
10275
11046
|
fi
|
|
10276
11047
|
;;
|
|
10277
11048
|
project)
|
|
10278
|
-
subcommands="list get create delete lock unlock members"
|
|
11049
|
+
subcommands="list get create delete lock unlock members tags"
|
|
10279
11050
|
if [[ "\${COMP_WORDS[2]}" == "members" ]]; then
|
|
10280
11051
|
COMPREPLY=($(compgen -W "list invite join remove" -- "\${cur}"))
|
|
11052
|
+
elif [[ "\${COMP_WORDS[2]}" == "tags" ]]; then
|
|
11053
|
+
COMPREPLY=($(compgen -W "get add remove set" -- "\${cur}"))
|
|
10281
11054
|
else
|
|
10282
11055
|
COMPREPLY=($(compgen -W "\${subcommands}" -- "\${cur}"))
|
|
10283
11056
|
fi
|
|
10284
11057
|
;;
|
|
10285
11058
|
entity)
|
|
10286
|
-
subcommands="list get delete history revert rename content"
|
|
11059
|
+
subcommands="list get delete history revert rename content tags"
|
|
10287
11060
|
if [[ "\${COMP_WORDS[2]}" == "content" ]]; then
|
|
10288
11061
|
COMPREPLY=($(compgen -W "get set delete" -- "\${cur}"))
|
|
11062
|
+
elif [[ "\${COMP_WORDS[2]}" == "tags" ]]; then
|
|
11063
|
+
COMPREPLY=($(compgen -W "get add remove set" -- "\${cur}"))
|
|
10289
11064
|
else
|
|
10290
11065
|
COMPREPLY=($(compgen -W "\${subcommands}" -- "\${cur}"))
|
|
10291
11066
|
fi
|
|
@@ -10336,11 +11111,12 @@ _diafunc_completions() {
|
|
|
10336
11111
|
esac
|
|
10337
11112
|
;;
|
|
10338
11113
|
admin)
|
|
10339
|
-
subcommands="users subscription settings backup"
|
|
11114
|
+
subcommands="users subscription settings backup curated-tags"
|
|
10340
11115
|
case "\${COMP_WORDS[2]}" in
|
|
10341
11116
|
users) COMPREPLY=($(compgen -W "list get" -- "\${cur}")) ;;
|
|
10342
11117
|
settings) COMPREPLY=($(compgen -W "get set" -- "\${cur}")) ;;
|
|
10343
11118
|
backup) COMPREPLY=($(compgen -W "create-full project" -- "\${cur}")) ;;
|
|
11119
|
+
curated-tags) COMPREPLY=($(compgen -W "list create update delete" -- "\${cur}")) ;;
|
|
10344
11120
|
*) COMPREPLY=($(compgen -W "\${subcommands}" -- "\${cur}")) ;;
|
|
10345
11121
|
esac
|
|
10346
11122
|
;;
|
|
@@ -10414,12 +11190,12 @@ _diafunc() {
|
|
|
10414
11190
|
|
|
10415
11191
|
_diafunc_auth() { _values 'subcommand' login logout status token; }
|
|
10416
11192
|
_diafunc_config() { _values 'subcommand' set get list profile; }
|
|
10417
|
-
_diafunc_project() { _values 'subcommand' list get create delete lock unlock members; }
|
|
11193
|
+
_diafunc_project() { _values 'subcommand' list get create delete lock unlock members tags; }
|
|
10418
11194
|
_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; }
|
|
11195
|
+
_diafunc_entity() { _values 'subcommand' list get delete history revert rename content tags; }
|
|
10420
11196
|
_diafunc_table() { _values 'subcommand' view import export row column cell clear; }
|
|
10421
11197
|
_diafunc_chat() { _values 'subcommand' repl send stream upload session usage; }
|
|
10422
|
-
_diafunc_admin() { _values 'subcommand' users subscription settings backup; }
|
|
11198
|
+
_diafunc_admin() { _values 'subcommand' users subscription settings backup curated-tags; }
|
|
10423
11199
|
|
|
10424
11200
|
_diafunc "$@"`;
|
|
10425
11201
|
var FISH_COMPLETION = `# Fish completions for diafunc
|
|
@@ -10462,10 +11238,10 @@ complete -c diafunc -n "__fish_seen_subcommand_from config; and not __fish_seen_
|
|
|
10462
11238
|
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
11239
|
|
|
10464
11240
|
# 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"
|
|
11241
|
+
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
11242
|
|
|
10467
11243
|
# 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"
|
|
11244
|
+
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
11245
|
|
|
10470
11246
|
# branch
|
|
10471
11247
|
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 +11262,7 @@ complete -c diafunc -n "__fish_seen_subcommand_from seats packs; and not __fish_
|
|
|
10486
11262
|
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
11263
|
|
|
10488
11264
|
# 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"
|
|
11265
|
+
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
11266
|
|
|
10491
11267
|
# analyze accepts files
|
|
10492
11268
|
complete -c diafunc -n "__fish_seen_subcommand_from analyze" -F`;
|
|
@@ -10510,7 +11286,7 @@ function registerCompletionCommand(program) {
|
|
|
10510
11286
|
}
|
|
10511
11287
|
|
|
10512
11288
|
// src/commands/whoami/index.ts
|
|
10513
|
-
import
|
|
11289
|
+
import chalk32 from "chalk";
|
|
10514
11290
|
function registerWhoamiCommand(program) {
|
|
10515
11291
|
program.command("whoami").description("Show the currently authenticated user").action(async (_options, cmd) => {
|
|
10516
11292
|
try {
|
|
@@ -10520,8 +11296,8 @@ function registerWhoamiCommand(program) {
|
|
|
10520
11296
|
const api = createApiClient();
|
|
10521
11297
|
const user = await api.admin.getMyUser();
|
|
10522
11298
|
if (outputFormat === "human") {
|
|
10523
|
-
console.log(
|
|
10524
|
-
console.log(
|
|
11299
|
+
console.log(chalk32.bold(user.name) + chalk32.dim(` <${user.email}>`));
|
|
11300
|
+
console.log(chalk32.dim(` Role: ${user.role} \xB7 Remaining credits: ${user.remainingCredits} \xB7 Profile: ${config.currentProfile}`));
|
|
10525
11301
|
} else {
|
|
10526
11302
|
format(user, { format: outputFormat });
|
|
10527
11303
|
}
|
|
@@ -10532,8 +11308,8 @@ function registerWhoamiCommand(program) {
|
|
|
10532
11308
|
}
|
|
10533
11309
|
|
|
10534
11310
|
// src/commands/utilization/index.ts
|
|
10535
|
-
import
|
|
10536
|
-
function
|
|
11311
|
+
import chalk33 from "chalk";
|
|
11312
|
+
function getOutputFormat22(cmd) {
|
|
10537
11313
|
const config = loadConfig();
|
|
10538
11314
|
const globalOpts = cmd.optsWithGlobals();
|
|
10539
11315
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -10549,19 +11325,19 @@ function windowLabel(u) {
|
|
|
10549
11325
|
}
|
|
10550
11326
|
function printUtilizationHuman(u, label) {
|
|
10551
11327
|
const when2 = windowLabel(u);
|
|
10552
|
-
console.log(label ?
|
|
11328
|
+
console.log(label ? chalk33.bold(label) + " " + chalk33.dim(when2) : chalk33.bold(when2));
|
|
10553
11329
|
if (u.types.length === 0) {
|
|
10554
|
-
console.log(
|
|
11330
|
+
console.log(chalk33.dim(" (no usage)"));
|
|
10555
11331
|
return;
|
|
10556
11332
|
}
|
|
10557
11333
|
const types = [...u.types].sort((a, b) => b.credits - a.credits);
|
|
10558
11334
|
const width = Math.max(...types.map((t) => t.type.length));
|
|
10559
11335
|
for (const t of types) {
|
|
10560
|
-
const line = ` ${t.type.padEnd(width)} ${formatNumber(t.quantity).padStart(12)} ${
|
|
10561
|
-
console.log(t.credits === 0 ?
|
|
11336
|
+
const line = ` ${t.type.padEnd(width)} ${formatNumber(t.quantity).padStart(12)} ${chalk33.dim("credits")} ${t.credits.toFixed(2).padStart(10)}`;
|
|
11337
|
+
console.log(t.credits === 0 ? chalk33.dim(line) : line);
|
|
10562
11338
|
}
|
|
10563
11339
|
const total = u.totalCredits ?? u.types.reduce((s, t) => s + t.credits, 0);
|
|
10564
|
-
console.log(
|
|
11340
|
+
console.log(chalk33.bold(` ${"Total".padEnd(width)} ${" ".repeat(12)} ${chalk33.dim("credits")} ${total.toFixed(2).padStart(10)}`));
|
|
10565
11341
|
}
|
|
10566
11342
|
function formatDailyHistory(history) {
|
|
10567
11343
|
const spentOn = (u) => u.dailyCredits ?? u.types.reduce((sum, t) => sum + (t.dailyCredits ?? 0), 0);
|
|
@@ -10578,14 +11354,14 @@ function formatDailyHistory(history) {
|
|
|
10578
11354
|
for (const u of history) {
|
|
10579
11355
|
const spent = spentOn(u);
|
|
10580
11356
|
total += spent;
|
|
10581
|
-
const line = `${windowLabel(u).padEnd(width)} ${amount(spent)} ${
|
|
10582
|
-
lines.push(spent > 0 ?
|
|
11357
|
+
const line = `${windowLabel(u).padEnd(width)} ${amount(spent)} ${chalk33.dim("credits")}`;
|
|
11358
|
+
lines.push(spent > 0 ? chalk33.bold(line) : chalk33.dim(line));
|
|
10583
11359
|
for (const t of costly(u)) {
|
|
10584
11360
|
lines.push(` ${t.type.padEnd(width - 2)} ${amount(t.dailyCredits ?? 0)}`);
|
|
10585
11361
|
}
|
|
10586
11362
|
}
|
|
10587
11363
|
lines.push("");
|
|
10588
|
-
lines.push(
|
|
11364
|
+
lines.push(chalk33.bold(`${totalLabel.padEnd(width)} ${amount(total)} ${chalk33.dim("credits")}`));
|
|
10589
11365
|
return lines;
|
|
10590
11366
|
}
|
|
10591
11367
|
function registerUtilizationCommand(program) {
|
|
@@ -10598,7 +11374,7 @@ Examples:
|
|
|
10598
11374
|
`);
|
|
10599
11375
|
util.command("actual", { isDefault: true }).description("Show current utilization (default subcommand)").action(async (_options, cmd) => {
|
|
10600
11376
|
try {
|
|
10601
|
-
const outputFormat =
|
|
11377
|
+
const outputFormat = getOutputFormat22(cmd);
|
|
10602
11378
|
const api = createApiClient();
|
|
10603
11379
|
const utilization = await api.admin.getActualUtilization();
|
|
10604
11380
|
if (outputFormat === "human") {
|
|
@@ -10612,7 +11388,7 @@ Examples:
|
|
|
10612
11388
|
});
|
|
10613
11389
|
util.command("history").description("Show what each day of the billing cycle cost").action(async (_options, cmd) => {
|
|
10614
11390
|
try {
|
|
10615
|
-
const outputFormat =
|
|
11391
|
+
const outputFormat = getOutputFormat22(cmd);
|
|
10616
11392
|
const api = createApiClient();
|
|
10617
11393
|
const history = await api.admin.getUtilizationHistory();
|
|
10618
11394
|
if (outputFormat === "human") {
|
|
@@ -10633,7 +11409,7 @@ Examples:
|
|
|
10633
11409
|
}
|
|
10634
11410
|
|
|
10635
11411
|
// src/commands/entity-branch/index.ts
|
|
10636
|
-
function
|
|
11412
|
+
function getOutputFormat23(cmd) {
|
|
10637
11413
|
const config = loadConfig();
|
|
10638
11414
|
const globalOpts = cmd.optsWithGlobals();
|
|
10639
11415
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -10646,7 +11422,7 @@ function registerEntityBranchCommands(program) {
|
|
|
10646
11422
|
const eb = program.command("entity-branch").description("Manage entity branches (parallel versions of a single entity)");
|
|
10647
11423
|
eb.command("list").description("List branches of an entity").argument("<ref>", "Entity reference (projectId/branch/entityId)").action(async (ref, _options, cmd) => {
|
|
10648
11424
|
try {
|
|
10649
|
-
const outputFormat =
|
|
11425
|
+
const outputFormat = getOutputFormat23(cmd);
|
|
10650
11426
|
const overrides = getOverrides11(cmd);
|
|
10651
11427
|
const resolved = parseEntityReference(ref, overrides);
|
|
10652
11428
|
const api = createApiClient();
|
|
@@ -10698,7 +11474,7 @@ function forReader(subscription) {
|
|
|
10698
11474
|
Object.entries(subscription).filter(([key]) => !BILLING_INTERNALS.has(key))
|
|
10699
11475
|
);
|
|
10700
11476
|
}
|
|
10701
|
-
function
|
|
11477
|
+
function getOutputFormat24(cmd) {
|
|
10702
11478
|
const config = loadConfig();
|
|
10703
11479
|
const globalOpts = cmd.optsWithGlobals();
|
|
10704
11480
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -10712,7 +11488,7 @@ Examples:
|
|
|
10712
11488
|
sub.command("current", { isDefault: true }).description("Show the current subscription").action(async (_options, cmd) => {
|
|
10713
11489
|
try {
|
|
10714
11490
|
const api = createApiClient();
|
|
10715
|
-
const outputFormat =
|
|
11491
|
+
const outputFormat = getOutputFormat24(cmd);
|
|
10716
11492
|
const s = await api.admin.getCurrentSubscription();
|
|
10717
11493
|
format(outputFormat === "human" ? forReader(s) : s, { format: outputFormat });
|
|
10718
11494
|
} catch (error) {
|
|
@@ -10722,7 +11498,7 @@ Examples:
|
|
|
10722
11498
|
sub.command("next").description("Show the next (upcoming) subscription").action(async (_options, cmd) => {
|
|
10723
11499
|
try {
|
|
10724
11500
|
const api = createApiClient();
|
|
10725
|
-
const outputFormat =
|
|
11501
|
+
const outputFormat = getOutputFormat24(cmd);
|
|
10726
11502
|
const s = await api.admin.getNextSubscription();
|
|
10727
11503
|
format(outputFormat === "human" ? forReader(s) : s, { format: outputFormat });
|
|
10728
11504
|
} catch (error) {
|
|
@@ -10733,7 +11509,7 @@ Examples:
|
|
|
10733
11509
|
try {
|
|
10734
11510
|
const api = createApiClient();
|
|
10735
11511
|
const plans = await api.admin.getSubscriptionPlans(subscriptionToken);
|
|
10736
|
-
format(plans, { format:
|
|
11512
|
+
format(plans, { format: getOutputFormat24(cmd) });
|
|
10737
11513
|
} catch (error) {
|
|
10738
11514
|
handleError(error);
|
|
10739
11515
|
}
|
|
@@ -10741,8 +11517,8 @@ Examples:
|
|
|
10741
11517
|
}
|
|
10742
11518
|
|
|
10743
11519
|
// src/commands/invoice/index.ts
|
|
10744
|
-
import * as
|
|
10745
|
-
function
|
|
11520
|
+
import * as fs13 from "fs";
|
|
11521
|
+
function getOutputFormat25(cmd) {
|
|
10746
11522
|
const config = loadConfig();
|
|
10747
11523
|
const globalOpts = cmd.optsWithGlobals();
|
|
10748
11524
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -10759,7 +11535,7 @@ Examples:
|
|
|
10759
11535
|
const api = createApiClient();
|
|
10760
11536
|
const invoices = await api.admin.getInvoices();
|
|
10761
11537
|
format(invoices, {
|
|
10762
|
-
format:
|
|
11538
|
+
format: getOutputFormat25(cmd),
|
|
10763
11539
|
columns: [
|
|
10764
11540
|
{ key: "invoiceNumber", header: "number" },
|
|
10765
11541
|
{ key: "issued", kind: "date" },
|
|
@@ -10779,7 +11555,7 @@ Examples:
|
|
|
10779
11555
|
const response = await api.admin.downloadInvoice(invoiceNumber, fileName);
|
|
10780
11556
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
10781
11557
|
const outPath = options.out ?? fileName;
|
|
10782
|
-
|
|
11558
|
+
fs13.writeFileSync(outPath, buffer);
|
|
10783
11559
|
success(`Invoice saved to ${outPath}`);
|
|
10784
11560
|
} catch (error) {
|
|
10785
11561
|
handleError(error);
|
|
@@ -10788,12 +11564,12 @@ Examples:
|
|
|
10788
11564
|
}
|
|
10789
11565
|
|
|
10790
11566
|
// src/commands/shell/index.ts
|
|
10791
|
-
import
|
|
10792
|
-
import * as
|
|
10793
|
-
import * as
|
|
10794
|
-
import * as
|
|
11567
|
+
import chalk34 from "chalk";
|
|
11568
|
+
import * as fs14 from "fs";
|
|
11569
|
+
import * as os4 from "os";
|
|
11570
|
+
import * as path10 from "path";
|
|
10795
11571
|
import { spawn as spawn3 } from "child_process";
|
|
10796
|
-
import { randomUUID as
|
|
11572
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
10797
11573
|
function extensionFor2(language) {
|
|
10798
11574
|
const l = language.toLowerCase();
|
|
10799
11575
|
if (l === "java") return "java";
|
|
@@ -10804,16 +11580,16 @@ function extensionFor2(language) {
|
|
|
10804
11580
|
return "txt";
|
|
10805
11581
|
}
|
|
10806
11582
|
async function openInEditor(initial, ext) {
|
|
10807
|
-
const tmpFile =
|
|
10808
|
-
|
|
11583
|
+
const tmpFile = path10.join(os4.tmpdir(), `diafunc-shell-${randomUUID4()}.${ext}`);
|
|
11584
|
+
fs14.writeFileSync(tmpFile, initial);
|
|
10809
11585
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
10810
|
-
await new Promise((
|
|
11586
|
+
await new Promise((resolve2, reject) => {
|
|
10811
11587
|
const child = spawn3(editor, [tmpFile], { stdio: "inherit" });
|
|
10812
|
-
child.on("exit", (code) => code === 0 ?
|
|
11588
|
+
child.on("exit", (code) => code === 0 ? resolve2() : reject(new Error(`Editor exited with ${code}`)));
|
|
10813
11589
|
child.on("error", reject);
|
|
10814
11590
|
});
|
|
10815
|
-
const content =
|
|
10816
|
-
|
|
11591
|
+
const content = fs14.readFileSync(tmpFile, "utf-8");
|
|
11592
|
+
fs14.unlinkSync(tmpFile);
|
|
10817
11593
|
return content;
|
|
10818
11594
|
}
|
|
10819
11595
|
function utcNowParts() {
|
|
@@ -10854,21 +11630,21 @@ async function evaluate(api, fnRef, language, sourceCode) {
|
|
|
10854
11630
|
}, false);
|
|
10855
11631
|
if (result.outputs?.length) {
|
|
10856
11632
|
for (const out of result.outputs) {
|
|
10857
|
-
console.log(
|
|
11633
|
+
console.log(chalk34.dim(` [${out.type}]`) + " " + out.output);
|
|
10858
11634
|
}
|
|
10859
11635
|
}
|
|
10860
11636
|
if (result.successful) {
|
|
10861
11637
|
if (result.result) {
|
|
10862
|
-
console.log(
|
|
11638
|
+
console.log(chalk34.green("=>") + " " + result.result);
|
|
10863
11639
|
} else {
|
|
10864
|
-
console.log(
|
|
11640
|
+
console.log(chalk34.dim("=> (no value)"));
|
|
10865
11641
|
}
|
|
10866
11642
|
const duration = result.completed - result.started;
|
|
10867
|
-
console.log(
|
|
11643
|
+
console.log(chalk34.dim(` [${duration}ms \xB7 ${evaluationId}]`));
|
|
10868
11644
|
} else {
|
|
10869
|
-
console.log(
|
|
11645
|
+
console.log(chalk34.red("error: ") + result.error);
|
|
10870
11646
|
if (result.lineNumber > 0) {
|
|
10871
|
-
console.log(
|
|
11647
|
+
console.log(chalk34.dim(` at line ${result.lineNumber}, col ${result.columnNumber}`));
|
|
10872
11648
|
}
|
|
10873
11649
|
}
|
|
10874
11650
|
}
|
|
@@ -10889,19 +11665,19 @@ function registerShellCommand(program) {
|
|
|
10889
11665
|
});
|
|
10890
11666
|
const api = createApiClient();
|
|
10891
11667
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
10892
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
11668
|
+
const { getUpdateNotice } = await import("./update-check-4345HWGE.js");
|
|
10893
11669
|
const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
|
|
10894
|
-
console.log(
|
|
10895
|
-
console.log(
|
|
10896
|
-
console.log(
|
|
11670
|
+
console.log(chalk34.bold("Diafunc shell") + chalk34.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
|
|
11671
|
+
console.log(chalk34.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
11672
|
+
console.log(chalk34.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
|
|
10897
11673
|
const notice = await getUpdateNotice();
|
|
10898
|
-
if (notice) console.log(
|
|
11674
|
+
if (notice) console.log(chalk34.dim(notice));
|
|
10899
11675
|
console.log();
|
|
10900
11676
|
let language = resolvedLanguage;
|
|
10901
11677
|
for (; ; ) {
|
|
10902
11678
|
let line;
|
|
10903
11679
|
try {
|
|
10904
|
-
line = await promptInput({ message:
|
|
11680
|
+
line = await promptInput({ message: chalk34.cyan.bold(`${language} >`) });
|
|
10905
11681
|
} catch {
|
|
10906
11682
|
console.log();
|
|
10907
11683
|
return;
|
|
@@ -10919,54 +11695,54 @@ function registerShellCommand(program) {
|
|
|
10919
11695
|
case "help":
|
|
10920
11696
|
case "h":
|
|
10921
11697
|
case "?":
|
|
10922
|
-
console.log(
|
|
10923
|
-
console.log(
|
|
10924
|
-
console.log(
|
|
10925
|
-
console.log(
|
|
11698
|
+
console.log(chalk34.dim(" /edit open $EDITOR for multi-line code"));
|
|
11699
|
+
console.log(chalk34.dim(" /file <path> evaluate the contents of a file"));
|
|
11700
|
+
console.log(chalk34.dim(" /lang <name> switch language (Java, JavaScript, Kotlin, Python, Scala)"));
|
|
11701
|
+
console.log(chalk34.dim(" /quit exit the shell"));
|
|
10926
11702
|
continue;
|
|
10927
11703
|
case "lang":
|
|
10928
11704
|
if (arg) language = arg;
|
|
10929
|
-
console.log(
|
|
11705
|
+
console.log(chalk34.dim(`Language: ${language}`));
|
|
10930
11706
|
continue;
|
|
10931
11707
|
case "edit": {
|
|
10932
11708
|
const sourceCode = await openInEditor("", extensionFor2(language));
|
|
10933
11709
|
if (!sourceCode.trim()) {
|
|
10934
|
-
console.log(
|
|
11710
|
+
console.log(chalk34.dim("(empty; not evaluated)"));
|
|
10935
11711
|
continue;
|
|
10936
11712
|
}
|
|
10937
11713
|
try {
|
|
10938
11714
|
await evaluate(api, fnRef, language, sourceCode);
|
|
10939
11715
|
} catch (e) {
|
|
10940
|
-
console.error(
|
|
11716
|
+
console.error(chalk34.red(e.message));
|
|
10941
11717
|
}
|
|
10942
11718
|
continue;
|
|
10943
11719
|
}
|
|
10944
11720
|
case "file": {
|
|
10945
11721
|
if (!arg) {
|
|
10946
|
-
console.log(
|
|
11722
|
+
console.log(chalk34.dim("usage: /file <path>"));
|
|
10947
11723
|
continue;
|
|
10948
11724
|
}
|
|
10949
|
-
if (!
|
|
10950
|
-
console.log(
|
|
11725
|
+
if (!fs14.existsSync(arg)) {
|
|
11726
|
+
console.log(chalk34.red(`file not found: ${arg}`));
|
|
10951
11727
|
continue;
|
|
10952
11728
|
}
|
|
10953
|
-
const sourceCode =
|
|
11729
|
+
const sourceCode = fs14.readFileSync(arg, "utf-8");
|
|
10954
11730
|
try {
|
|
10955
11731
|
await evaluate(api, fnRef, language, sourceCode);
|
|
10956
11732
|
} catch (e) {
|
|
10957
|
-
console.error(
|
|
11733
|
+
console.error(chalk34.red(e.message));
|
|
10958
11734
|
}
|
|
10959
11735
|
continue;
|
|
10960
11736
|
}
|
|
10961
11737
|
default:
|
|
10962
|
-
console.log(
|
|
11738
|
+
console.log(chalk34.dim(`Unknown command: /${cmd2}. Try /help.`));
|
|
10963
11739
|
continue;
|
|
10964
11740
|
}
|
|
10965
11741
|
}
|
|
10966
11742
|
try {
|
|
10967
11743
|
await evaluate(api, fnRef, language, trimmed);
|
|
10968
11744
|
} catch (e) {
|
|
10969
|
-
console.error(
|
|
11745
|
+
console.error(chalk34.red(e.message));
|
|
10970
11746
|
}
|
|
10971
11747
|
}
|
|
10972
11748
|
} catch (error) {
|
|
@@ -10976,19 +11752,19 @@ function registerShellCommand(program) {
|
|
|
10976
11752
|
}
|
|
10977
11753
|
|
|
10978
11754
|
// src/commands/update/index.ts
|
|
10979
|
-
import
|
|
10980
|
-
import * as
|
|
11755
|
+
import chalk35 from "chalk";
|
|
11756
|
+
import * as path11 from "path";
|
|
10981
11757
|
import { spawn as spawn4 } from "child_process";
|
|
10982
11758
|
|
|
10983
11759
|
// src/util/install-method.ts
|
|
10984
|
-
import * as
|
|
11760
|
+
import * as fs15 from "fs";
|
|
10985
11761
|
function detectInstall() {
|
|
10986
11762
|
const exec = process.execPath;
|
|
10987
11763
|
const exe = exec.replace(/\\/g, "/").toLowerCase();
|
|
10988
11764
|
const isNode = exe.endsWith("/node") || exe.endsWith("/node.exe");
|
|
10989
11765
|
return {
|
|
10990
11766
|
method: isNode ? "npm" : "binary",
|
|
10991
|
-
binaryPath: isNode ? exec :
|
|
11767
|
+
binaryPath: isNode ? exec : fs15.realpathSync(exec)
|
|
10992
11768
|
};
|
|
10993
11769
|
}
|
|
10994
11770
|
|
|
@@ -11004,7 +11780,7 @@ async function fetchLatestVersion() {
|
|
|
11004
11780
|
return manifest.version;
|
|
11005
11781
|
}
|
|
11006
11782
|
function runInstaller(installDir) {
|
|
11007
|
-
return new Promise((
|
|
11783
|
+
return new Promise((resolve2, reject) => {
|
|
11008
11784
|
const isWindows = process.platform === "win32";
|
|
11009
11785
|
const cmd = isWindows ? "powershell.exe" : "sh";
|
|
11010
11786
|
const args = isWindows ? ["-NoProfile", "-Command", `& { iwr -useb ${WINDOWS_INSTALLER_URL} | iex }`] : ["-c", `curl -fsSL ${POSIX_INSTALLER_URL} | sh`];
|
|
@@ -11012,7 +11788,7 @@ function runInstaller(installDir) {
|
|
|
11012
11788
|
stdio: "inherit",
|
|
11013
11789
|
env: { ...process.env, DIAFUNC_CLI_INSTALL_DIR: installDir }
|
|
11014
11790
|
});
|
|
11015
|
-
child.on("exit", (code) => code === 0 ?
|
|
11791
|
+
child.on("exit", (code) => code === 0 ? resolve2() : reject(new Error(`Installer exited with code ${code}`)));
|
|
11016
11792
|
child.on("error", reject);
|
|
11017
11793
|
});
|
|
11018
11794
|
}
|
|
@@ -11022,17 +11798,17 @@ function registerUpdateCommand(program) {
|
|
|
11022
11798
|
const install = detectInstall();
|
|
11023
11799
|
const latest = await fetchLatestVersion();
|
|
11024
11800
|
if (latest === package_default.version) {
|
|
11025
|
-
console.log(
|
|
11801
|
+
console.log(chalk35.dim(`diafunc is already at the latest version (${package_default.version}).`));
|
|
11026
11802
|
return;
|
|
11027
11803
|
}
|
|
11028
|
-
console.log(
|
|
11804
|
+
console.log(chalk35.dim(`Current: ${package_default.version} \u2192 Available: ${latest}`));
|
|
11029
11805
|
if (install.method === "npm") {
|
|
11030
11806
|
console.log();
|
|
11031
11807
|
console.log("Installed via npm. Upgrade with:");
|
|
11032
|
-
console.log(
|
|
11808
|
+
console.log(chalk35.bold(` npm install -g @diafunc/cli@${latest}`));
|
|
11033
11809
|
return;
|
|
11034
11810
|
}
|
|
11035
|
-
const installDir =
|
|
11811
|
+
const installDir = path11.dirname(install.binaryPath);
|
|
11036
11812
|
console.log(`Installing diafunc ${latest} to ${installDir}...`);
|
|
11037
11813
|
console.log();
|
|
11038
11814
|
await runInstaller(installDir);
|
|
@@ -11043,23 +11819,23 @@ function registerUpdateCommand(program) {
|
|
|
11043
11819
|
}
|
|
11044
11820
|
|
|
11045
11821
|
// src/commands/uninstall/index.ts
|
|
11046
|
-
import
|
|
11822
|
+
import chalk36 from "chalk";
|
|
11047
11823
|
import { spawn as spawn5 } from "child_process";
|
|
11048
|
-
import * as
|
|
11049
|
-
import * as
|
|
11050
|
-
import * as
|
|
11824
|
+
import * as fs16 from "fs";
|
|
11825
|
+
import * as os5 from "os";
|
|
11826
|
+
import * as path12 from "path";
|
|
11051
11827
|
function registerUninstallCommand(program) {
|
|
11052
11828
|
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
11829
|
try {
|
|
11054
11830
|
const install = detectInstall();
|
|
11055
|
-
const configDir =
|
|
11831
|
+
const configDir = path12.join(os5.homedir(), ".diafunc");
|
|
11056
11832
|
if (install.method === "npm") {
|
|
11057
11833
|
console.log("Installed via npm. Remove with:");
|
|
11058
|
-
console.log(
|
|
11059
|
-
if (
|
|
11834
|
+
console.log(chalk36.bold(" npm uninstall -g @diafunc/cli"));
|
|
11835
|
+
if (fs16.existsSync(configDir)) {
|
|
11060
11836
|
console.log();
|
|
11061
11837
|
console.log(`Config and credentials live at ${configDir}. Remove them manually with:`);
|
|
11062
|
-
console.log(
|
|
11838
|
+
console.log(chalk36.bold(` rm -rf ${configDir}`));
|
|
11063
11839
|
}
|
|
11064
11840
|
return;
|
|
11065
11841
|
}
|
|
@@ -11069,19 +11845,19 @@ function registerUninstallCommand(program) {
|
|
|
11069
11845
|
default: false
|
|
11070
11846
|
});
|
|
11071
11847
|
if (!removeBinary) {
|
|
11072
|
-
console.log(
|
|
11848
|
+
console.log(chalk36.dim("Aborted."));
|
|
11073
11849
|
return;
|
|
11074
11850
|
}
|
|
11075
11851
|
let removeConfig = options.purge ?? false;
|
|
11076
|
-
if (!options.purge && !options.yes &&
|
|
11852
|
+
if (!options.purge && !options.yes && fs16.existsSync(configDir)) {
|
|
11077
11853
|
removeConfig = await confirm({
|
|
11078
11854
|
message: `Also remove ${configDir} (config + credentials)?`,
|
|
11079
11855
|
default: false
|
|
11080
11856
|
});
|
|
11081
11857
|
}
|
|
11082
|
-
if (removeConfig &&
|
|
11083
|
-
|
|
11084
|
-
console.log(
|
|
11858
|
+
if (removeConfig && fs16.existsSync(configDir)) {
|
|
11859
|
+
fs16.rmSync(configDir, { recursive: true, force: true });
|
|
11860
|
+
console.log(chalk36.dim(`Removed ${configDir}`));
|
|
11085
11861
|
}
|
|
11086
11862
|
if (process.platform === "win32") {
|
|
11087
11863
|
const cmd = `timeout /t 2 /nobreak >nul & del /f /q "${install.binaryPath}"`;
|
|
@@ -11091,13 +11867,13 @@ function registerUninstallCommand(program) {
|
|
|
11091
11867
|
windowsHide: true
|
|
11092
11868
|
});
|
|
11093
11869
|
child.unref();
|
|
11094
|
-
console.log(
|
|
11870
|
+
console.log(chalk36.dim(`Removing ${install.binaryPath} on exit...`));
|
|
11095
11871
|
console.log();
|
|
11096
11872
|
console.log("diafunc uninstalled.");
|
|
11097
11873
|
return;
|
|
11098
11874
|
}
|
|
11099
|
-
|
|
11100
|
-
console.log(
|
|
11875
|
+
fs16.rmSync(install.binaryPath, { force: true });
|
|
11876
|
+
console.log(chalk36.dim(`Removed ${install.binaryPath}`));
|
|
11101
11877
|
console.log();
|
|
11102
11878
|
console.log("diafunc uninstalled.");
|
|
11103
11879
|
} catch (error) {
|
|
@@ -11161,7 +11937,7 @@ var DiafuncCommand = class _DiafuncCommand extends Command {
|
|
|
11161
11937
|
};
|
|
11162
11938
|
|
|
11163
11939
|
// src/prompting/fill.ts
|
|
11164
|
-
import
|
|
11940
|
+
import chalk38 from "chalk";
|
|
11165
11941
|
|
|
11166
11942
|
// src/prompting/resolvers.ts
|
|
11167
11943
|
var PROJECT_ROLES = ["OWNER", "ADMIN", "DEVELOPER", "GUEST"];
|
|
@@ -11216,6 +11992,9 @@ var BY_COMMAND = {
|
|
|
11216
11992
|
"notebook export": {
|
|
11217
11993
|
"<notebookIds>": { kind: "entity", form: "id", contentType: "notebook", projectFrom: "project", multiple: true }
|
|
11218
11994
|
},
|
|
11995
|
+
"entity tags set": { "<tags>": TEXT_OR_EMPTY },
|
|
11996
|
+
"project tags set": { "<tags>": TEXT_OR_EMPTY },
|
|
11997
|
+
"admin curated-tags create": { "--display-name": TEXT },
|
|
11219
11998
|
"link delete": { "<linkId>": { kind: "link" } },
|
|
11220
11999
|
"link create": { "<linkId>": TEXT },
|
|
11221
12000
|
"config profile use": { "<name>": { kind: "profile" } },
|
|
@@ -11265,6 +12044,8 @@ var BY_NAME = {
|
|
|
11265
12044
|
value: TEXT_OR_EMPTY,
|
|
11266
12045
|
// Free text: names, messages and ids the reader is creating rather than choosing.
|
|
11267
12046
|
name: TEXT,
|
|
12047
|
+
tag: TEXT,
|
|
12048
|
+
tags: TEXT,
|
|
11268
12049
|
newId: TEXT,
|
|
11269
12050
|
message: TEXT,
|
|
11270
12051
|
query: TEXT,
|
|
@@ -11286,11 +12067,11 @@ var BY_NAME = {
|
|
|
11286
12067
|
function tokenOf(input) {
|
|
11287
12068
|
return input.kind === "option" ? input.flag ?? `--${input.name}` : `<${input.name}>`;
|
|
11288
12069
|
}
|
|
11289
|
-
function specFor(
|
|
11290
|
-
const exact = BY_COMMAND[
|
|
12070
|
+
function specFor(path13, input) {
|
|
12071
|
+
const exact = BY_COMMAND[path13]?.[tokenOf(input)];
|
|
11291
12072
|
if (exact) return exact;
|
|
11292
|
-
const group =
|
|
11293
|
-
const sub =
|
|
12073
|
+
const group = path13.split(" ")[0];
|
|
12074
|
+
const sub = path13.split(" ").slice(0, 2).join(" ");
|
|
11294
12075
|
switch (input.name) {
|
|
11295
12076
|
case "ref":
|
|
11296
12077
|
case "sourceRef":
|
|
@@ -11357,8 +12138,8 @@ function dependencies(spec) {
|
|
|
11357
12138
|
}
|
|
11358
12139
|
|
|
11359
12140
|
// src/prompting/pickers.ts
|
|
11360
|
-
import * as
|
|
11361
|
-
import
|
|
12141
|
+
import * as fs17 from "fs";
|
|
12142
|
+
import chalk37 from "chalk";
|
|
11362
12143
|
var SEARCH_THRESHOLD = 10;
|
|
11363
12144
|
var TYPE_IT = "\0type-it";
|
|
11364
12145
|
async function askFor(spec, input, ctx) {
|
|
@@ -11492,7 +12273,7 @@ async function askFor(spec, input, ctx) {
|
|
|
11492
12273
|
}
|
|
11493
12274
|
case "file":
|
|
11494
12275
|
return typed(ctx, question(input), {
|
|
11495
|
-
validate: (value) =>
|
|
12276
|
+
validate: (value) => fs17.existsSync(value.trim()) || `No file at ${value.trim()}.`
|
|
11496
12277
|
});
|
|
11497
12278
|
case "number":
|
|
11498
12279
|
return typed(ctx, question(input), { validate: numberRule(spec) });
|
|
@@ -11706,7 +12487,7 @@ function typedValue(ctx, message) {
|
|
|
11706
12487
|
return typed(ctx, message);
|
|
11707
12488
|
}
|
|
11708
12489
|
function typeItChoice() {
|
|
11709
|
-
return { name:
|
|
12490
|
+
return { name: chalk37.dim("Type it instead"), value: TYPE_IT };
|
|
11710
12491
|
}
|
|
11711
12492
|
function text(ctx, name) {
|
|
11712
12493
|
const value = ctx.known.get(name);
|
|
@@ -11736,7 +12517,7 @@ function capitalize(value) {
|
|
|
11736
12517
|
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
11737
12518
|
}
|
|
11738
12519
|
function labelled(label, hint2) {
|
|
11739
|
-
return hint2 && hint2 !== label ? `${label} ${
|
|
12520
|
+
return hint2 && hint2 !== label ? `${label} ${chalk37.dim(hint2)}` : label;
|
|
11740
12521
|
}
|
|
11741
12522
|
function numberRule(spec) {
|
|
11742
12523
|
return (raw) => {
|
|
@@ -11782,7 +12563,7 @@ async function fillPendingInputs(actionCommand) {
|
|
|
11782
12563
|
known: knownValues(actionCommand),
|
|
11783
12564
|
globals: actionCommand.optsWithGlobals(),
|
|
11784
12565
|
prefill: /* @__PURE__ */ new Map(),
|
|
11785
|
-
note: (line) => process.stderr.write(
|
|
12566
|
+
note: (line) => process.stderr.write(chalk38.dim(` ${line}
|
|
11786
12567
|
`))
|
|
11787
12568
|
};
|
|
11788
12569
|
for (const item of orderByDependencies(pending)) {
|
|
@@ -11791,7 +12572,7 @@ async function fillPendingInputs(actionCommand) {
|
|
|
11791
12572
|
ctx.known.set(item.input.name, value);
|
|
11792
12573
|
}
|
|
11793
12574
|
const log = env.log ?? ((line) => console.log(line));
|
|
11794
|
-
log(
|
|
12575
|
+
log(chalk38.dim(` Equivalent: ${equivalentCommand(actionCommand)}`));
|
|
11795
12576
|
}
|
|
11796
12577
|
function commandChain(cmd) {
|
|
11797
12578
|
const chain = [];
|
|
@@ -11896,7 +12677,7 @@ function createProgram(environment = {}) {
|
|
|
11896
12677
|
const opts = thisCommand.optsWithGlobals();
|
|
11897
12678
|
if (opts.dryRun) setDryRun(true);
|
|
11898
12679
|
if (opts.verbose) setVerbose(true);
|
|
11899
|
-
if (opts.color === false)
|
|
12680
|
+
if (opts.color === false) chalk39.level = 0;
|
|
11900
12681
|
}).hook("preAction", (_thisCommand, actionCommand) => fillPendingInputs(actionCommand));
|
|
11901
12682
|
program.addHelpText("after", HELP_EPILOGUE);
|
|
11902
12683
|
registerAuthCommands(program);
|
|
@@ -11939,4 +12720,4 @@ export {
|
|
|
11939
12720
|
PromptCancelled,
|
|
11940
12721
|
createProgram
|
|
11941
12722
|
};
|
|
11942
|
-
//# sourceMappingURL=chunk-
|
|
12723
|
+
//# sourceMappingURL=chunk-Q5GOPNYM.js.map
|