@diafunc/cli 0.9.2 → 0.10.1
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/dist/bin/diafunc.js +3 -3
- package/dist/{chunk-WPZBLPVY.js → chunk-4EDLP7DD.js} +2 -2
- package/dist/chunk-4EDLP7DD.js.map +1 -0
- package/dist/{chunk-CBSJB5GC.js → chunk-RMW4OLRA.js} +2 -2
- package/dist/{chunk-SOXLUOWV.js → chunk-XRUDG6ZY.js} +1905 -701
- package/dist/chunk-XRUDG6ZY.js.map +1 -0
- package/dist/src/index.js +2 -2
- package/dist/update-check-XRMWJ753.js +8 -0
- package/package.json +1 -1
- package/dist/chunk-SOXLUOWV.js.map +0 -1
- package/dist/chunk-WPZBLPVY.js.map +0 -1
- package/dist/update-check-JKIWTPFB.js +0 -8
- /package/dist/{chunk-CBSJB5GC.js.map → chunk-RMW4OLRA.js.map} +0 -0
- /package/dist/{update-check-JKIWTPFB.js.map → update-check-XRMWJ753.js.map} +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4EDLP7DD.js";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
import { Command } from "commander";
|
|
7
|
+
import chalk34 from "chalk";
|
|
7
8
|
|
|
8
9
|
// src/commands/auth/login.ts
|
|
9
|
-
import
|
|
10
|
+
import chalk4 from "chalk";
|
|
10
11
|
|
|
11
12
|
// src/config/store.ts
|
|
12
13
|
import * as fs from "fs";
|
|
@@ -53,6 +54,9 @@ function resolveEndpoint(config, profileOverride) {
|
|
|
53
54
|
return profile.endpoint.replace(/\/+$/, "");
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
// src/client/http.ts
|
|
58
|
+
import chalk from "chalk";
|
|
59
|
+
|
|
56
60
|
// src/client/errors.ts
|
|
57
61
|
var ApiError = class _ApiError extends Error {
|
|
58
62
|
status;
|
|
@@ -67,22 +71,47 @@ var ApiError = class _ApiError extends Error {
|
|
|
67
71
|
return new _ApiError(status, body.message, body.details);
|
|
68
72
|
}
|
|
69
73
|
toUserMessage() {
|
|
74
|
+
const detail2 = this.readableMessage();
|
|
70
75
|
switch (this.status) {
|
|
71
76
|
case 401:
|
|
72
|
-
return `Authentication failed. Run 'diafunc auth login' to
|
|
77
|
+
return `Authentication failed. Run 'diafunc auth login' to sign in again.`;
|
|
73
78
|
case 403:
|
|
74
|
-
return
|
|
79
|
+
return detail2 ? `Permission denied: ${detail2}` : `Permission denied. Your account or token lacks the required access.`;
|
|
75
80
|
case 404:
|
|
76
|
-
return `Not found: ${
|
|
81
|
+
return detail2 ? `Not found: ${detail2}` : `Not found: the server has no such resource.`;
|
|
77
82
|
case 409:
|
|
78
|
-
return `Conflict: ${this
|
|
83
|
+
return detail2 ? `Conflict: ${detail2}` : `Conflict: the resource changed under this request.`;
|
|
79
84
|
case 429:
|
|
80
|
-
return `Rate limited.
|
|
85
|
+
return `Rate limited. Wait a moment and try again.`;
|
|
86
|
+
case 500:
|
|
87
|
+
case 502:
|
|
88
|
+
case 503:
|
|
89
|
+
case 504:
|
|
90
|
+
return detail2 ? `The Diafunc platform returned ${this.status}: ${detail2}` : `The Diafunc platform returned ${this.status}. Check 'diafunc status summary'.`;
|
|
81
91
|
default:
|
|
82
|
-
return
|
|
92
|
+
return detail2 || `The request failed with status ${this.status}.`;
|
|
83
93
|
}
|
|
84
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* The server's message, or nothing when what came back was not meant for a person.
|
|
97
|
+
*
|
|
98
|
+
* A gateway answering with its own HTML error page used to be surfaced verbatim, so a missing
|
|
99
|
+
* endpoint read as
|
|
100
|
+
* `Error: Not found: <html><head><title>Error</title></head><body>Not Found</body></html>`.
|
|
101
|
+
* Markup is never the explanation the reader needs, so it is dropped in favour of the
|
|
102
|
+
* status-derived sentence above.
|
|
103
|
+
*/
|
|
104
|
+
readableMessage() {
|
|
105
|
+
const message = (this.message ?? "").trim();
|
|
106
|
+
if (!message || looksLikeMarkup(message)) return "";
|
|
107
|
+
const withDetails = this.details && !looksLikeMarkup(this.details) ? `${message} (${this.details})` : message;
|
|
108
|
+
return withDetails;
|
|
109
|
+
}
|
|
85
110
|
};
|
|
111
|
+
function looksLikeMarkup(text) {
|
|
112
|
+
const head = text.trimStart().slice(0, 200).toLowerCase();
|
|
113
|
+
return head.startsWith("<") || head.includes("<html") || head.includes("<!doctype");
|
|
114
|
+
}
|
|
86
115
|
var NetworkError = class extends Error {
|
|
87
116
|
constructor(message, cause) {
|
|
88
117
|
super(message);
|
|
@@ -92,6 +121,10 @@ var NetworkError = class extends Error {
|
|
|
92
121
|
};
|
|
93
122
|
|
|
94
123
|
// src/client/http.ts
|
|
124
|
+
var REQUEST_TIMEOUT_MS = 6e4;
|
|
125
|
+
var RETRYABLE_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
126
|
+
var MAX_ATTEMPTS = 3;
|
|
127
|
+
var RETRYABLE_METHODS = /* @__PURE__ */ new Set(["GET"]);
|
|
95
128
|
function buildUrl(endpoint, service, path11, query) {
|
|
96
129
|
const base = `${endpoint}/api/v1/${service}${path11}`;
|
|
97
130
|
const params = new URLSearchParams();
|
|
@@ -181,16 +214,29 @@ async function parseErrorBody(response) {
|
|
|
181
214
|
const body = await response.json();
|
|
182
215
|
return ApiError.fromBody(response.status, body);
|
|
183
216
|
}
|
|
184
|
-
const text = await response.text();
|
|
217
|
+
const text = (await response.text()).trim();
|
|
185
218
|
return new ApiError(response.status, text || response.statusText);
|
|
186
219
|
} catch {
|
|
187
220
|
return new ApiError(response.status, response.statusText);
|
|
188
221
|
}
|
|
189
222
|
}
|
|
190
223
|
var _dryRun = false;
|
|
224
|
+
var _verbose = false;
|
|
191
225
|
function setDryRun(enabled) {
|
|
192
226
|
_dryRun = enabled;
|
|
193
227
|
}
|
|
228
|
+
function setVerbose(enabled) {
|
|
229
|
+
_verbose = enabled;
|
|
230
|
+
}
|
|
231
|
+
function trace(line) {
|
|
232
|
+
if (_verbose) console.error(chalk.dim(` [http] ${line}`));
|
|
233
|
+
}
|
|
234
|
+
function isTransient(error) {
|
|
235
|
+
if (error.name === "TimeoutError" || error.name === "AbortError") return false;
|
|
236
|
+
const cause = error.cause;
|
|
237
|
+
const code = cause?.code ?? "";
|
|
238
|
+
return ["ECONNRESET", "ECONNREFUSED", "EPIPE", "ETIMEDOUT", "ENOTFOUND", "EAI_AGAIN"].includes(code);
|
|
239
|
+
}
|
|
194
240
|
function createHttpClient(options = {}) {
|
|
195
241
|
const config = loadConfig();
|
|
196
242
|
const endpoint = resolveEndpoint(config, options.profileOverride);
|
|
@@ -198,10 +244,10 @@ function createHttpClient(options = {}) {
|
|
|
198
244
|
if (_dryRun && opts.method !== "GET") {
|
|
199
245
|
const url2 = buildUrl(endpoint, opts.service, opts.path, opts.query);
|
|
200
246
|
const bodyPreview = opts.body ? JSON.stringify(opts.body, null, 2) : opts.rawBody ? "(binary)" : "(none)";
|
|
201
|
-
console.
|
|
247
|
+
console.error(chalk.yellow(`[dry-run] ${opts.method} ${url2}`));
|
|
202
248
|
if (opts.body) {
|
|
203
|
-
console.
|
|
204
|
-
${bodyPreview}`);
|
|
249
|
+
console.error(chalk.dim(`[dry-run] Body:
|
|
250
|
+
${bodyPreview}`));
|
|
205
251
|
}
|
|
206
252
|
return new Response("{}", { status: 200, headers: { "content-type": "application/json" } });
|
|
207
253
|
}
|
|
@@ -224,18 +270,49 @@ ${bodyPreview}`);
|
|
|
224
270
|
headers["Content-Type"] = "application/json";
|
|
225
271
|
body = JSON.stringify(opts.body);
|
|
226
272
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
273
|
+
headers["User-Agent"] = `diafunc-cli/${package_default.version} (${process.platform}; node ${process.versions.node})`;
|
|
274
|
+
const retryable = RETRYABLE_METHODS.has(opts.method);
|
|
275
|
+
const maxAttempts = retryable ? MAX_ATTEMPTS : 1;
|
|
276
|
+
let lastError;
|
|
277
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
278
|
+
const startedAt = Date.now();
|
|
279
|
+
try {
|
|
280
|
+
const response = await fetch(url, {
|
|
281
|
+
method: opts.method,
|
|
282
|
+
headers,
|
|
283
|
+
body,
|
|
284
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
285
|
+
});
|
|
286
|
+
trace(`${opts.method} ${url} -> ${response.status} (${Date.now() - startedAt}ms)`);
|
|
287
|
+
if (RETRYABLE_STATUSES.has(response.status) && attempt < maxAttempts) {
|
|
288
|
+
trace(`retrying after ${response.status} (attempt ${attempt} of ${maxAttempts})`);
|
|
289
|
+
await delay(attempt * 500);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
return response;
|
|
293
|
+
} catch (err) {
|
|
294
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
295
|
+
trace(`${opts.method} ${url} -> ${lastError.name}: ${lastError.message}`);
|
|
296
|
+
if (attempt < maxAttempts && isTransient(lastError)) {
|
|
297
|
+
await delay(attempt * 500);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (lastError?.name === "TimeoutError") {
|
|
234
304
|
throw new NetworkError(
|
|
235
|
-
`
|
|
236
|
-
|
|
305
|
+
`No response from ${endpoint} within ${REQUEST_TIMEOUT_MS / 1e3}s.`,
|
|
306
|
+
lastError
|
|
237
307
|
);
|
|
238
308
|
}
|
|
309
|
+
throw new NetworkError(
|
|
310
|
+
`Failed to connect to ${endpoint}${lastError ? ` (${lastError.message})` : ""}. Check your network, or the endpoint set by 'diafunc config list'.`,
|
|
311
|
+
lastError
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
function delay(ms) {
|
|
315
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
239
316
|
}
|
|
240
317
|
return {
|
|
241
318
|
async request(opts) {
|
|
@@ -695,22 +772,90 @@ function createAdminService(client) {
|
|
|
695
772
|
}
|
|
696
773
|
|
|
697
774
|
// src/util/errors.ts
|
|
698
|
-
import
|
|
775
|
+
import chalk3 from "chalk";
|
|
776
|
+
|
|
777
|
+
// src/output/messages.ts
|
|
778
|
+
import chalk2 from "chalk";
|
|
779
|
+
|
|
780
|
+
// src/output/json.ts
|
|
781
|
+
function formatJson(data) {
|
|
782
|
+
console.log(JSON.stringify(data, null, 2));
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// src/output/messages.ts
|
|
786
|
+
var MARK_OK = "\u2713";
|
|
787
|
+
var MARK_WARN = "!";
|
|
788
|
+
var MARK_FAIL = "\u2717";
|
|
789
|
+
function success(message, options) {
|
|
790
|
+
if (options?.format === "json") {
|
|
791
|
+
formatJson({ ok: true, message });
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
console.log(`${chalk2.green(MARK_OK)} ${message}`);
|
|
795
|
+
}
|
|
796
|
+
function warn(message) {
|
|
797
|
+
console.error(`${chalk2.yellow(MARK_WARN)} ${message}`);
|
|
798
|
+
}
|
|
799
|
+
function failure(message) {
|
|
800
|
+
console.error(`${chalk2.red(MARK_FAIL)} ${message}`);
|
|
801
|
+
}
|
|
802
|
+
function detail(message) {
|
|
803
|
+
console.log(chalk2.dim(` ${message}`));
|
|
804
|
+
}
|
|
805
|
+
function hint(message) {
|
|
806
|
+
console.error(chalk2.dim(` ${message}`));
|
|
807
|
+
}
|
|
808
|
+
function empty(noun, options) {
|
|
809
|
+
if (options?.format === "json") {
|
|
810
|
+
formatJson([]);
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
console.log(chalk2.dim(`No ${noun}.`));
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// src/util/errors.ts
|
|
817
|
+
var EXIT_FAILURE = 1;
|
|
818
|
+
var EXIT_USAGE = 2;
|
|
819
|
+
var EXIT_AUTH = 3;
|
|
820
|
+
var CliError = class extends Error {
|
|
821
|
+
exitCode;
|
|
822
|
+
hint;
|
|
823
|
+
constructor(message, options = {}) {
|
|
824
|
+
super(message);
|
|
825
|
+
this.name = "CliError";
|
|
826
|
+
this.exitCode = options.exitCode ?? EXIT_FAILURE;
|
|
827
|
+
this.hint = options.hint;
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
function usageError(message, suggestion) {
|
|
831
|
+
failure(message);
|
|
832
|
+
if (suggestion) hint(suggestion);
|
|
833
|
+
process.exit(EXIT_USAGE);
|
|
834
|
+
}
|
|
699
835
|
function handleError(error) {
|
|
836
|
+
if (error instanceof CliError) {
|
|
837
|
+
failure(error.message);
|
|
838
|
+
if (error.hint) hint(error.hint);
|
|
839
|
+
process.exit(error.exitCode);
|
|
840
|
+
}
|
|
700
841
|
if (error instanceof ApiError) {
|
|
701
|
-
|
|
702
|
-
|
|
842
|
+
failure(error.toUserMessage());
|
|
843
|
+
if (error.status === 401) hint(`Run 'diafunc auth login' to sign in.`);
|
|
844
|
+
if (error.status === 404) hint(`Check the id, or list what exists with the matching 'list' command.`);
|
|
845
|
+
process.exit(error.status === 401 || error.status === 403 ? EXIT_AUTH : EXIT_FAILURE);
|
|
703
846
|
}
|
|
704
847
|
if (error instanceof NetworkError) {
|
|
705
|
-
|
|
706
|
-
|
|
848
|
+
failure(error.message);
|
|
849
|
+
hint(`Run 'diafunc status summary' to check the platform, or 'diafunc config list' for the endpoint in use.`);
|
|
850
|
+
process.exit(EXIT_FAILURE);
|
|
707
851
|
}
|
|
708
852
|
if (error instanceof Error) {
|
|
709
|
-
|
|
710
|
-
process.
|
|
853
|
+
failure(error.message);
|
|
854
|
+
if (process.env.DIAFUNC_DEBUG && error.stack) console.error(chalk3.dim(error.stack));
|
|
855
|
+
process.exit(EXIT_FAILURE);
|
|
711
856
|
}
|
|
712
|
-
|
|
713
|
-
process.exit(
|
|
857
|
+
failure(String(error));
|
|
858
|
+
process.exit(EXIT_FAILURE);
|
|
714
859
|
}
|
|
715
860
|
|
|
716
861
|
// src/commands/auth/login.ts
|
|
@@ -733,7 +878,7 @@ function registerLoginCommand(parent) {
|
|
|
733
878
|
const config = loadConfig();
|
|
734
879
|
const profile = config.profiles[config.currentProfile];
|
|
735
880
|
if (!profile) {
|
|
736
|
-
|
|
881
|
+
failure(`Profile "${config.currentProfile}" not found. Run 'diafunc config profile add' first.`);
|
|
737
882
|
process.exit(1);
|
|
738
883
|
}
|
|
739
884
|
if (options.endpoint) {
|
|
@@ -745,8 +890,8 @@ function registerLoginCommand(parent) {
|
|
|
745
890
|
const client = createHttpClient();
|
|
746
891
|
const admin = createAdminService(client);
|
|
747
892
|
const user = await admin.getMyUser();
|
|
748
|
-
|
|
749
|
-
console.log(` User: ${
|
|
893
|
+
success("Authenticated successfully.");
|
|
894
|
+
console.log(` User: ${chalk4.bold(user.name)}`);
|
|
750
895
|
console.log(` Email: ${user.email}`);
|
|
751
896
|
console.log(` Profile: ${config.currentProfile}`);
|
|
752
897
|
console.log(` Endpoint: ${profile.endpoint}`);
|
|
@@ -767,18 +912,18 @@ async function deviceCodeLogin(config, profile) {
|
|
|
767
912
|
});
|
|
768
913
|
if (!deviceResponse.ok) {
|
|
769
914
|
const text = await deviceResponse.text();
|
|
770
|
-
|
|
915
|
+
failure(`Failed to start device-code flow: ${text || deviceResponse.statusText}`);
|
|
771
916
|
process.exit(1);
|
|
772
917
|
}
|
|
773
918
|
const device = await deviceResponse.json();
|
|
774
919
|
console.log("");
|
|
775
|
-
console.log(`Open this URL in a browser: ${
|
|
776
|
-
console.log(`Enter the code: ${
|
|
920
|
+
console.log(`Open this URL in a browser: ${chalk4.cyan(device.verification_uri)}`);
|
|
921
|
+
console.log(`Enter the code: ${chalk4.bold.yellow(device.user_code)}`);
|
|
777
922
|
console.log("");
|
|
778
|
-
console.log(
|
|
779
|
-
console.log(
|
|
923
|
+
console.log(chalk4.dim("Or open the full URL to pre-fill:"));
|
|
924
|
+
console.log(chalk4.dim(` ${device.verification_uri_complete}`));
|
|
780
925
|
console.log("");
|
|
781
|
-
console.log(
|
|
926
|
+
console.log(chalk4.dim(`Waiting for approval (expires in ${Math.floor(device.expires_in / 60)} min)...`));
|
|
782
927
|
const deadline = Date.now() + device.expires_in * 1e3;
|
|
783
928
|
let interval = Math.max(1, device.interval || 5);
|
|
784
929
|
while (Date.now() < deadline) {
|
|
@@ -805,8 +950,8 @@ async function deviceCodeLogin(config, profile) {
|
|
|
805
950
|
const client = createHttpClient();
|
|
806
951
|
const admin = createAdminService(client);
|
|
807
952
|
const user = await admin.getMyUser();
|
|
808
|
-
|
|
809
|
-
console.log(` User: ${
|
|
953
|
+
success("Logged in successfully.");
|
|
954
|
+
console.log(` User: ${chalk4.bold(user.name)}`);
|
|
810
955
|
console.log(` Email: ${user.email}`);
|
|
811
956
|
console.log(` Profile: ${config.currentProfile}`);
|
|
812
957
|
console.log(` Endpoint: ${profile.endpoint}`);
|
|
@@ -821,14 +966,13 @@ async function deviceCodeLogin(config, profile) {
|
|
|
821
966
|
continue;
|
|
822
967
|
}
|
|
823
968
|
if (errorBody.error === "expired_token") {
|
|
824
|
-
|
|
969
|
+
failure("Code expired before approval. Run `diafunc auth login` again.");
|
|
825
970
|
process.exit(1);
|
|
826
971
|
}
|
|
827
|
-
|
|
828
|
-
Device-code flow failed: ${errorBody.error}${errorBody.error_description ? " \u2014 " + errorBody.error_description : ""}`));
|
|
972
|
+
failure(`Device-code flow failed: ${errorBody.error}${errorBody.error_description ? " \u2014 " + errorBody.error_description : ""}`);
|
|
829
973
|
process.exit(1);
|
|
830
974
|
}
|
|
831
|
-
|
|
975
|
+
failure("Timed out waiting for approval.");
|
|
832
976
|
process.exit(1);
|
|
833
977
|
}
|
|
834
978
|
function sleep(ms) {
|
|
@@ -836,7 +980,6 @@ function sleep(ms) {
|
|
|
836
980
|
}
|
|
837
981
|
|
|
838
982
|
// src/commands/auth/logout.ts
|
|
839
|
-
import chalk3 from "chalk";
|
|
840
983
|
function deriveAuthUrl3(endpoint) {
|
|
841
984
|
const trimmed = endpoint.replace(/\/+$/, "");
|
|
842
985
|
if (trimmed.includes("://auth.")) {
|
|
@@ -852,11 +995,11 @@ function registerLogoutCommand(parent) {
|
|
|
852
995
|
const config = loadConfig();
|
|
853
996
|
const profile = config.profiles[config.currentProfile];
|
|
854
997
|
if (!profile) {
|
|
855
|
-
|
|
998
|
+
failure(`Profile "${config.currentProfile}" not found.`);
|
|
856
999
|
process.exit(1);
|
|
857
1000
|
}
|
|
858
1001
|
if (!profile.auth) {
|
|
859
|
-
|
|
1002
|
+
empty("credentials stored for this profile");
|
|
860
1003
|
return;
|
|
861
1004
|
}
|
|
862
1005
|
if (profile.auth.type === "device-code") {
|
|
@@ -876,94 +1019,371 @@ function registerLogoutCommand(parent) {
|
|
|
876
1019
|
}
|
|
877
1020
|
delete profile.auth;
|
|
878
1021
|
saveConfig(config);
|
|
879
|
-
|
|
1022
|
+
success(`Logged out from profile "${config.currentProfile}".`);
|
|
880
1023
|
});
|
|
881
1024
|
}
|
|
882
1025
|
|
|
883
1026
|
// src/commands/auth/status.ts
|
|
1027
|
+
import chalk7 from "chalk";
|
|
1028
|
+
|
|
1029
|
+
// src/output/human.ts
|
|
884
1030
|
import chalk6 from "chalk";
|
|
885
1031
|
|
|
886
|
-
// src/output/
|
|
887
|
-
|
|
1032
|
+
// src/output/columns.ts
|
|
1033
|
+
function normalizeColumns(columns) {
|
|
1034
|
+
return columns.map((c) => typeof c === "string" ? { key: c } : c);
|
|
1035
|
+
}
|
|
1036
|
+
function humanizeKey(key) {
|
|
1037
|
+
return key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase();
|
|
1038
|
+
}
|
|
1039
|
+
function headerOf(spec) {
|
|
1040
|
+
return spec.header ?? humanizeKey(spec.key);
|
|
1041
|
+
}
|
|
1042
|
+
function inferKind(key) {
|
|
1043
|
+
const k = key.toLowerCase();
|
|
1044
|
+
if (/[a-z](At|Date|Time|Timestamp)$/.test(key) || DATE_KEYS.has(k)) return "date";
|
|
1045
|
+
if (/[a-z](State|Status)$/.test(key) || k === "state" || k === "status") return "state";
|
|
1046
|
+
if (/[a-z]Ids?$/.test(key) || k === "id") return "id";
|
|
1047
|
+
return "text";
|
|
1048
|
+
}
|
|
1049
|
+
var DATE_KEYS = /* @__PURE__ */ new Set([
|
|
1050
|
+
"created",
|
|
1051
|
+
"modified",
|
|
1052
|
+
"started",
|
|
1053
|
+
"ended",
|
|
1054
|
+
"issued",
|
|
1055
|
+
"requested",
|
|
1056
|
+
"finished",
|
|
1057
|
+
"submitted",
|
|
1058
|
+
"renewal",
|
|
1059
|
+
"expires",
|
|
1060
|
+
"joined",
|
|
1061
|
+
"invited",
|
|
1062
|
+
"removed",
|
|
1063
|
+
"lastaccessed",
|
|
1064
|
+
"lastcheck"
|
|
1065
|
+
]);
|
|
888
1066
|
|
|
889
|
-
// src/output/
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
1067
|
+
// src/output/terminal.ts
|
|
1068
|
+
function isInteractive() {
|
|
1069
|
+
return Boolean(process.stdout.isTTY) && process.env.TERM !== "dumb";
|
|
1070
|
+
}
|
|
1071
|
+
function terminalWidth() {
|
|
1072
|
+
const columns = process.stdout.columns;
|
|
1073
|
+
if (!columns || !Number.isFinite(columns)) return 80;
|
|
1074
|
+
return Math.max(40, columns - 1);
|
|
1075
|
+
}
|
|
1076
|
+
function displayWidth(text) {
|
|
1077
|
+
return stripAnsi(text).length;
|
|
1078
|
+
}
|
|
1079
|
+
var ANSI_PATTERN = new RegExp("\\u001B\\[[0-9;]*m", "g");
|
|
1080
|
+
function stripAnsi(text) {
|
|
1081
|
+
return text.replace(ANSI_PATTERN, "");
|
|
1082
|
+
}
|
|
1083
|
+
function truncate(text, width) {
|
|
1084
|
+
const plain = stripAnsi(text);
|
|
1085
|
+
if (plain.length <= width) return text;
|
|
1086
|
+
if (width <= 1) return plain.slice(0, Math.max(0, width));
|
|
1087
|
+
return plain.slice(0, width - 1) + "\u2026";
|
|
1088
|
+
}
|
|
1089
|
+
function wrap(text, width) {
|
|
1090
|
+
const out = [];
|
|
1091
|
+
for (const paragraph of text.split("\n")) {
|
|
1092
|
+
if (paragraph.length <= width) {
|
|
1093
|
+
out.push(paragraph);
|
|
1094
|
+
continue;
|
|
907
1095
|
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
1096
|
+
let line = "";
|
|
1097
|
+
for (const word of paragraph.split(/(\s+)/)) {
|
|
1098
|
+
if (line.length + word.length <= width) {
|
|
1099
|
+
line += word;
|
|
1100
|
+
continue;
|
|
1101
|
+
}
|
|
1102
|
+
if (line.trim()) out.push(line.trimEnd());
|
|
1103
|
+
let rest = word.trimStart();
|
|
1104
|
+
while (rest.length > width) {
|
|
1105
|
+
out.push(rest.slice(0, width));
|
|
1106
|
+
rest = rest.slice(width);
|
|
1107
|
+
}
|
|
1108
|
+
line = rest;
|
|
916
1109
|
}
|
|
917
|
-
|
|
918
|
-
} else {
|
|
919
|
-
console.log(String(data));
|
|
1110
|
+
if (line.trim() || out.length === 0) out.push(line.trimEnd());
|
|
920
1111
|
}
|
|
1112
|
+
return out;
|
|
921
1113
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
1114
|
+
|
|
1115
|
+
// src/output/values.ts
|
|
1116
|
+
import chalk5 from "chalk";
|
|
1117
|
+
var ABSENT = "\u2014";
|
|
1118
|
+
function renderValue(value, kind = "text", plain = false) {
|
|
1119
|
+
const dim = (text) => plain ? text : chalk5.dim(text);
|
|
1120
|
+
if (value === null || value === void 0 || value === "") return dim(ABSENT);
|
|
1121
|
+
switch (kind) {
|
|
1122
|
+
case "id":
|
|
1123
|
+
return dim(String(value));
|
|
1124
|
+
case "date":
|
|
1125
|
+
return plain ? formatInstantAbsolute(value) : formatInstant(value);
|
|
1126
|
+
case "number":
|
|
1127
|
+
return renderNumber(value, plain);
|
|
1128
|
+
case "state":
|
|
1129
|
+
return plain ? String(value) : renderState(String(value));
|
|
1130
|
+
case "boolean":
|
|
1131
|
+
return renderBoolean(value, plain);
|
|
1132
|
+
case "text":
|
|
1133
|
+
default:
|
|
1134
|
+
if (typeof value === "boolean") return renderBoolean(value, plain);
|
|
1135
|
+
if (typeof value === "number") return renderNumber(value, plain);
|
|
1136
|
+
if (Array.isArray(value)) return renderArray(value, plain, dim);
|
|
1137
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
1138
|
+
return String(value);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
function renderNumber(value, plain) {
|
|
1142
|
+
const text = typeof value === "number" && !plain ? formatNumber(value) : String(value);
|
|
1143
|
+
return plain ? text : chalk5.cyan(text);
|
|
1144
|
+
}
|
|
1145
|
+
function renderArray(value, plain, dim) {
|
|
1146
|
+
if (value.length === 0) return dim(ABSENT);
|
|
1147
|
+
const allScalar = value.every((v) => v === null || typeof v !== "object");
|
|
1148
|
+
return allScalar ? value.map(String).join(", ") : JSON.stringify(value);
|
|
1149
|
+
}
|
|
1150
|
+
function renderBoolean(value, plain) {
|
|
1151
|
+
const truthy = value === true || value === "true";
|
|
1152
|
+
if (plain) return truthy ? "yes" : "no";
|
|
1153
|
+
return truthy ? chalk5.green("yes") : chalk5.dim("no");
|
|
1154
|
+
}
|
|
1155
|
+
function formatNumber(value) {
|
|
1156
|
+
if (!Number.isFinite(value)) return String(value);
|
|
1157
|
+
if (!Number.isInteger(value)) return String(value);
|
|
1158
|
+
return value.toLocaleString("en-US");
|
|
929
1159
|
}
|
|
930
1160
|
function formatInstant(value) {
|
|
931
|
-
|
|
1161
|
+
const date = toDate(value);
|
|
1162
|
+
if (!date) return String(value);
|
|
1163
|
+
const absolute = formatLocal(date);
|
|
1164
|
+
const relative = formatRelative(date.getTime());
|
|
1165
|
+
return relative ? `${absolute} ${chalk5.dim(`(${relative})`)}` : absolute;
|
|
1166
|
+
}
|
|
1167
|
+
function formatInstantAbsolute(value) {
|
|
1168
|
+
const date = toDate(value);
|
|
1169
|
+
return date ? formatLocal(date) : String(value);
|
|
1170
|
+
}
|
|
1171
|
+
function toDate(value) {
|
|
1172
|
+
if (value === null || value === void 0 || value === "") return null;
|
|
1173
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value;
|
|
932
1174
|
if (typeof value === "number") {
|
|
1175
|
+
const millis = value < 1e11 && value > 0 ? value * 1e3 : value;
|
|
1176
|
+
const d = new Date(millis);
|
|
1177
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
1178
|
+
}
|
|
1179
|
+
if (typeof value === "string") {
|
|
1180
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) return null;
|
|
1181
|
+
if (/^\d+$/.test(value)) return toDate(Number(value));
|
|
933
1182
|
const d = new Date(value);
|
|
934
|
-
return Number.isNaN(d.getTime()) ?
|
|
1183
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
935
1184
|
}
|
|
936
|
-
return
|
|
1185
|
+
return null;
|
|
1186
|
+
}
|
|
1187
|
+
function formatLocal(date) {
|
|
1188
|
+
const pad2 = (n) => String(n).padStart(2, "0");
|
|
1189
|
+
return `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())} ${pad2(date.getHours())}:${pad2(date.getMinutes())}`;
|
|
1190
|
+
}
|
|
1191
|
+
function formatRelative(millis, now = Date.now()) {
|
|
1192
|
+
const delta = now - millis;
|
|
1193
|
+
const abs = Math.abs(delta);
|
|
1194
|
+
if (abs < 3e4) return "just now";
|
|
1195
|
+
if (abs > 180 * 24 * 60 * 60 * 1e3) return null;
|
|
1196
|
+
const span = formatDuration(abs);
|
|
1197
|
+
return delta >= 0 ? `${span} ago` : `in ${span}`;
|
|
1198
|
+
}
|
|
1199
|
+
function formatDuration(millis) {
|
|
1200
|
+
const seconds = Math.floor(millis / 1e3);
|
|
1201
|
+
if (seconds < 60) return `${seconds}s`;
|
|
1202
|
+
const minutes = Math.floor(seconds / 60);
|
|
1203
|
+
if (minutes < 60) return `${minutes}m ${String(seconds % 60).padStart(2, "0")}s`;
|
|
1204
|
+
const hours = Math.floor(minutes / 60);
|
|
1205
|
+
if (hours < 24) return `${hours}h ${String(minutes % 60).padStart(2, "0")}m`;
|
|
1206
|
+
const days = Math.floor(hours / 24);
|
|
1207
|
+
return `${days}d ${hours % 24}h`;
|
|
1208
|
+
}
|
|
1209
|
+
var GOOD_STATES = /* @__PURE__ */ new Set([
|
|
1210
|
+
"COMPLETED",
|
|
1211
|
+
"SUCCEEDED",
|
|
1212
|
+
"SUCCESS",
|
|
1213
|
+
"ACTIVE",
|
|
1214
|
+
"UP",
|
|
1215
|
+
"OPERATIONAL",
|
|
1216
|
+
"PAID",
|
|
1217
|
+
"RESOLVED",
|
|
1218
|
+
"OK"
|
|
1219
|
+
]);
|
|
1220
|
+
var BAD_STATES = /* @__PURE__ */ new Set([
|
|
1221
|
+
"FAILED",
|
|
1222
|
+
"FAILURE",
|
|
1223
|
+
"ERROR",
|
|
1224
|
+
"DOWN",
|
|
1225
|
+
"CANCELLED",
|
|
1226
|
+
"CANCELED",
|
|
1227
|
+
"EXPIRED",
|
|
1228
|
+
"REVOKED",
|
|
1229
|
+
"UNPAID"
|
|
1230
|
+
]);
|
|
1231
|
+
var BUSY_STATES = /* @__PURE__ */ new Set([
|
|
1232
|
+
"RUNNING",
|
|
1233
|
+
"QUEUED",
|
|
1234
|
+
"DISPATCHING",
|
|
1235
|
+
"PENDING",
|
|
1236
|
+
"IN_PROGRESS",
|
|
1237
|
+
"DEGRADED",
|
|
1238
|
+
"OPEN",
|
|
1239
|
+
"PROCESSING"
|
|
1240
|
+
]);
|
|
1241
|
+
function renderState(state) {
|
|
1242
|
+
const key = state.toUpperCase();
|
|
1243
|
+
if (GOOD_STATES.has(key)) return chalk5.green(state);
|
|
1244
|
+
if (BAD_STATES.has(key)) return chalk5.red(state);
|
|
1245
|
+
if (BUSY_STATES.has(key)) return chalk5.yellow(state);
|
|
1246
|
+
return state;
|
|
937
1247
|
}
|
|
938
1248
|
|
|
939
|
-
// src/output/
|
|
940
|
-
|
|
941
|
-
|
|
1249
|
+
// src/output/human.ts
|
|
1250
|
+
var GAP = " ";
|
|
1251
|
+
var MIN_COLUMN_WIDTH = 6;
|
|
1252
|
+
function formatHuman(data, columns) {
|
|
1253
|
+
if (Array.isArray(data)) {
|
|
1254
|
+
renderRows(data, columns);
|
|
1255
|
+
} else if (data && typeof data === "object") {
|
|
1256
|
+
renderRecord(data);
|
|
1257
|
+
} else {
|
|
1258
|
+
console.log(String(data));
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
function renderRows(rows, columns) {
|
|
1262
|
+
if (rows.length === 0) {
|
|
1263
|
+
console.log(chalk6.dim("No results."));
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
const specs = resolveSpecs(rows[0], columns);
|
|
1267
|
+
if (!isInteractive()) {
|
|
1268
|
+
console.log(specs.map((s) => headerOf(s)).join(" "));
|
|
1269
|
+
for (const row of rows) {
|
|
1270
|
+
console.log(specs.map((spec) => forPipe(row[spec.key], spec)).join(" "));
|
|
1271
|
+
}
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
let cells = rows.map((row) => specs.map((spec) => renderCell(row, spec)));
|
|
1275
|
+
if (naturalWidth(specs, cells) > terminalWidth()) {
|
|
1276
|
+
cells = rows.map((row) => specs.map((spec) => renderCell(row, spec, true)));
|
|
1277
|
+
}
|
|
1278
|
+
const widths = budgetWidths(specs, cells);
|
|
1279
|
+
console.log(
|
|
1280
|
+
specs.map((s, i) => chalk6.bold(pad(headerOf(s).toUpperCase(), widths[i]))).join(GAP).trimEnd()
|
|
1281
|
+
);
|
|
1282
|
+
for (const row of cells) {
|
|
1283
|
+
console.log(row.map((c, i) => pad(truncate(c, widths[i]), widths[i])).join(GAP).trimEnd());
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
function renderRecord(obj) {
|
|
1287
|
+
const entries = Object.entries(obj);
|
|
1288
|
+
if (entries.length === 0) {
|
|
1289
|
+
console.log(chalk6.dim("No fields."));
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
if (!isInteractive()) {
|
|
1293
|
+
for (const [key, value] of entries) {
|
|
1294
|
+
console.log(`${key} ${forPipe(value, { key })}`);
|
|
1295
|
+
}
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
const labelWidth = Math.min(
|
|
1299
|
+
24,
|
|
1300
|
+
entries.reduce((max, [key]) => Math.max(max, key.length), 0)
|
|
1301
|
+
);
|
|
1302
|
+
const valueWidth = Math.max(MIN_COLUMN_WIDTH, terminalWidth() - labelWidth - GAP.length);
|
|
1303
|
+
for (const [key, value] of entries) {
|
|
1304
|
+
const rendered = renderValue(value, inferKind(key));
|
|
1305
|
+
const label = chalk6.bold(pad(truncate(key, labelWidth), labelWidth));
|
|
1306
|
+
if (displayWidth(rendered) <= valueWidth) {
|
|
1307
|
+
console.log(label + GAP + rendered);
|
|
1308
|
+
continue;
|
|
1309
|
+
}
|
|
1310
|
+
const lines = wrap(stripAnsi(rendered), valueWidth);
|
|
1311
|
+
console.log(label + GAP + (lines[0] ?? ""));
|
|
1312
|
+
for (const line of lines.slice(1)) {
|
|
1313
|
+
console.log(" ".repeat(labelWidth + GAP.length) + line);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
function resolveSpecs(sample, columns) {
|
|
1318
|
+
const specs = columns ? normalizeColumns(columns) : Object.keys(sample).map((key) => ({ key }));
|
|
1319
|
+
return specs.map((spec) => ({ ...spec, kind: spec.kind ?? inferKind(spec.key) }));
|
|
1320
|
+
}
|
|
1321
|
+
function renderCell(row, spec, compactDates = false) {
|
|
1322
|
+
const value = row[spec.key];
|
|
1323
|
+
const rendered = compactDates && spec.kind === "date" ? renderCompactDate(value) : renderValue(value, spec.kind);
|
|
1324
|
+
return spec.maxWidth ? truncate(rendered, spec.maxWidth) : rendered;
|
|
1325
|
+
}
|
|
1326
|
+
function renderCompactDate(value) {
|
|
1327
|
+
if (value === null || value === void 0 || value === "") return chalk6.dim(ABSENT);
|
|
1328
|
+
return formatInstantAbsolute(value);
|
|
1329
|
+
}
|
|
1330
|
+
function naturalWidth(specs, cells) {
|
|
1331
|
+
const widths = specs.map(
|
|
1332
|
+
(spec, i) => Math.max(displayWidth(headerOf(spec)), ...cells.map((row) => displayWidth(row[i])))
|
|
1333
|
+
);
|
|
1334
|
+
return widths.reduce((a, b) => a + b, 0) + GAP.length * (specs.length - 1);
|
|
1335
|
+
}
|
|
1336
|
+
var SHRINK_ORDER = ["text", "date", "state", "number", "boolean", "id"];
|
|
1337
|
+
function budgetWidths(specs, cells) {
|
|
1338
|
+
const widths = specs.map(
|
|
1339
|
+
(spec, i) => Math.max(displayWidth(headerOf(spec)), ...cells.map((row) => displayWidth(row[i])))
|
|
1340
|
+
);
|
|
1341
|
+
const budget = terminalWidth() - GAP.length * (specs.length - 1);
|
|
1342
|
+
let total = widths.reduce((a, b) => a + b, 0);
|
|
1343
|
+
if (total <= budget) return widths;
|
|
1344
|
+
for (const kind of SHRINK_ORDER) {
|
|
1345
|
+
const candidates = specs.map((spec, i) => ({ i, kind: spec.kind ?? "text" })).filter((c) => c.kind === kind).map((c) => c.i);
|
|
1346
|
+
while (total > budget) {
|
|
1347
|
+
let widest = -1;
|
|
1348
|
+
for (const i of candidates) {
|
|
1349
|
+
if (widths[i] > MIN_COLUMN_WIDTH && (widest < 0 || widths[i] > widths[widest])) widest = i;
|
|
1350
|
+
}
|
|
1351
|
+
if (widest < 0) break;
|
|
1352
|
+
widths[widest] -= 1;
|
|
1353
|
+
total -= 1;
|
|
1354
|
+
}
|
|
1355
|
+
if (total <= budget) break;
|
|
1356
|
+
}
|
|
1357
|
+
return widths;
|
|
1358
|
+
}
|
|
1359
|
+
function pad(text, width) {
|
|
1360
|
+
const deficit = width - displayWidth(text);
|
|
1361
|
+
return deficit > 0 ? text + " ".repeat(deficit) : text;
|
|
1362
|
+
}
|
|
1363
|
+
function forPipe(value, spec) {
|
|
1364
|
+
const rendered = stripAnsi(renderValue(value, spec.kind ?? inferKind(spec.key), true));
|
|
1365
|
+
return rendered === ABSENT ? "" : rendered;
|
|
942
1366
|
}
|
|
943
1367
|
|
|
944
1368
|
// src/output/table.ts
|
|
945
1369
|
function formatTable(data, columns) {
|
|
946
1370
|
if (Array.isArray(data)) {
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
console.log(cols.join(" "));
|
|
1371
|
+
const specs = columns ? normalizeColumns(columns) : Object.keys(data[0] ?? {}).map((key) => ({ key }));
|
|
1372
|
+
if (specs.length > 0) console.log(specs.map((s) => headerOf(s)).join(" "));
|
|
950
1373
|
for (const row of data) {
|
|
951
|
-
|
|
952
|
-
console.log(cols.map((c) => cell(r[c])).join(" "));
|
|
1374
|
+
console.log(specs.map((s) => cell(row[s.key], s.kind ?? inferKind(s.key))).join(" "));
|
|
953
1375
|
}
|
|
954
1376
|
} else if (data && typeof data === "object") {
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
console.log(`${key} ${cell(value)}`);
|
|
1377
|
+
for (const [key, value] of Object.entries(data)) {
|
|
1378
|
+
console.log(`${key} ${cell(value, inferKind(key))}`);
|
|
958
1379
|
}
|
|
959
1380
|
} else {
|
|
960
1381
|
console.log(String(data));
|
|
961
1382
|
}
|
|
962
1383
|
}
|
|
963
|
-
function cell(value) {
|
|
1384
|
+
function cell(value, kind) {
|
|
964
1385
|
if (value === null || value === void 0) return "";
|
|
965
|
-
|
|
966
|
-
return String(value);
|
|
1386
|
+
return renderValue(value, kind, true);
|
|
967
1387
|
}
|
|
968
1388
|
|
|
969
1389
|
// src/output/formatter.ts
|
|
@@ -977,17 +1397,10 @@ function format(data, options) {
|
|
|
977
1397
|
break;
|
|
978
1398
|
case "human":
|
|
979
1399
|
default:
|
|
980
|
-
formatHuman(data, options.columns
|
|
1400
|
+
formatHuman(data, options.columns);
|
|
981
1401
|
break;
|
|
982
1402
|
}
|
|
983
1403
|
}
|
|
984
|
-
function formatMessage(message, options) {
|
|
985
|
-
if (options.format === "json") {
|
|
986
|
-
formatJson({ message });
|
|
987
|
-
} else {
|
|
988
|
-
console.log(chalk5.green(message));
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
1404
|
|
|
992
1405
|
// src/commands/auth/status.ts
|
|
993
1406
|
function registerStatusCommand(parent) {
|
|
@@ -1001,7 +1414,7 @@ function registerStatusCommand(parent) {
|
|
|
1001
1414
|
if (outputFormat === "json") {
|
|
1002
1415
|
console.log(JSON.stringify({ authenticated: false, profile: config.currentProfile }));
|
|
1003
1416
|
} else {
|
|
1004
|
-
console.log(
|
|
1417
|
+
console.log(chalk7.yellow("Not authenticated."), `Run 'diafunc auth login' to configure credentials.`);
|
|
1005
1418
|
console.log(` Profile: ${config.currentProfile}`);
|
|
1006
1419
|
console.log(` Endpoint: ${profile?.endpoint ?? "not configured"}`);
|
|
1007
1420
|
}
|
|
@@ -1029,7 +1442,7 @@ function registerStatusCommand(parent) {
|
|
|
1029
1442
|
}
|
|
1030
1443
|
|
|
1031
1444
|
// src/commands/auth/token.ts
|
|
1032
|
-
import
|
|
1445
|
+
import chalk8 from "chalk";
|
|
1033
1446
|
|
|
1034
1447
|
// src/client/services/analysis.ts
|
|
1035
1448
|
var SERVICE2 = "analyses";
|
|
@@ -2125,14 +2538,6 @@ function createEvaluationService(client) {
|
|
|
2125
2538
|
service: SERVICE4,
|
|
2126
2539
|
path: `/triggers/${enc2(projectId)}/${enc2(projectBranch)}/${enc2(functionId)}/${enc2(functionBranch)}/${enc2(triggerId)}`
|
|
2127
2540
|
});
|
|
2128
|
-
},
|
|
2129
|
-
// Engines
|
|
2130
|
-
async getEngines() {
|
|
2131
|
-
return client.request({
|
|
2132
|
-
method: "GET",
|
|
2133
|
-
service: SERVICE4,
|
|
2134
|
-
path: "/engines/"
|
|
2135
|
-
});
|
|
2136
2541
|
}
|
|
2137
2542
|
};
|
|
2138
2543
|
}
|
|
@@ -2252,6 +2657,25 @@ function enc5(s) {
|
|
|
2252
2657
|
}
|
|
2253
2658
|
function createIndexService(client) {
|
|
2254
2659
|
return {
|
|
2660
|
+
/**
|
|
2661
|
+
* Cross-project search. Scoped to one project by passing `projectId`; unscoped it searches
|
|
2662
|
+
* everything the caller can see, which is what the command's description has always promised.
|
|
2663
|
+
*/
|
|
2664
|
+
async searchPage(query) {
|
|
2665
|
+
return client.request({
|
|
2666
|
+
method: "GET",
|
|
2667
|
+
service: SERVICE7,
|
|
2668
|
+
path: "/search/page",
|
|
2669
|
+
query: {
|
|
2670
|
+
query: query.query,
|
|
2671
|
+
limit: query.limit ?? 20,
|
|
2672
|
+
cursor: query.cursor ?? void 0,
|
|
2673
|
+
contentType: query.contentType ?? void 0,
|
|
2674
|
+
projectId: query.projectId ?? void 0,
|
|
2675
|
+
projectBranch: query.projectBranch ?? void 0
|
|
2676
|
+
}
|
|
2677
|
+
});
|
|
2678
|
+
},
|
|
2255
2679
|
async rebuildAll() {
|
|
2256
2680
|
return client.request({
|
|
2257
2681
|
method: "POST",
|
|
@@ -2304,7 +2728,7 @@ function registerTokenCommands(parent) {
|
|
|
2304
2728
|
const resourceType = options.resourceType.trim().toLowerCase();
|
|
2305
2729
|
if (!VALID_RESOURCE_TYPES.includes(resourceType)) {
|
|
2306
2730
|
console.error(
|
|
2307
|
-
|
|
2731
|
+
chalk8.red(`Invalid resource type: "${options.resourceType}".`),
|
|
2308
2732
|
`Valid resource types: ${VALID_RESOURCE_TYPES.join(", ")}`
|
|
2309
2733
|
);
|
|
2310
2734
|
process.exit(1);
|
|
@@ -2312,7 +2736,7 @@ function registerTokenCommands(parent) {
|
|
|
2312
2736
|
const scopes = options.scopes.split(",").map((s) => s.trim());
|
|
2313
2737
|
for (const scope of scopes) {
|
|
2314
2738
|
if (!VALID_SCOPES.includes(scope)) {
|
|
2315
|
-
console.error(
|
|
2739
|
+
console.error(chalk8.red(`Invalid scope: "${scope}".`), `Valid scopes: ${VALID_SCOPES.join(", ")}`);
|
|
2316
2740
|
process.exit(1);
|
|
2317
2741
|
}
|
|
2318
2742
|
}
|
|
@@ -2325,14 +2749,14 @@ function registerTokenCommands(parent) {
|
|
|
2325
2749
|
validityDays: parseInt(options.days, 10)
|
|
2326
2750
|
});
|
|
2327
2751
|
if (outputFormat === "human") {
|
|
2328
|
-
|
|
2752
|
+
success("API token created successfully.");
|
|
2329
2753
|
console.log();
|
|
2330
|
-
console.log(` Token: ${
|
|
2754
|
+
console.log(` Token: ${chalk8.bold(result.token)}`);
|
|
2331
2755
|
console.log(` Token ID: ${result.tokenId}`);
|
|
2332
2756
|
console.log(` Name: ${result.name}`);
|
|
2333
2757
|
console.log(` Expires: ${result.expiresAt}`);
|
|
2334
2758
|
console.log();
|
|
2335
|
-
console.log(
|
|
2759
|
+
console.log(chalk8.yellow("Save this token \u2014 it will not be shown again."));
|
|
2336
2760
|
} else {
|
|
2337
2761
|
format(result, { format: outputFormat });
|
|
2338
2762
|
}
|
|
@@ -2359,7 +2783,7 @@ function registerTokenCommands(parent) {
|
|
|
2359
2783
|
try {
|
|
2360
2784
|
const api = createApiClient();
|
|
2361
2785
|
await api.admin.revokeApiToken(tokenId);
|
|
2362
|
-
|
|
2786
|
+
success(`Token ${tokenId} revoked.`);
|
|
2363
2787
|
} catch (error) {
|
|
2364
2788
|
handleError(error);
|
|
2365
2789
|
}
|
|
@@ -2368,7 +2792,14 @@ function registerTokenCommands(parent) {
|
|
|
2368
2792
|
|
|
2369
2793
|
// src/commands/auth/index.ts
|
|
2370
2794
|
function registerAuthCommands(program) {
|
|
2371
|
-
const auth = program.command("auth").description("Authentication and credential management")
|
|
2795
|
+
const auth = program.command("auth").description("Authentication and credential management").addHelpText("after", `
|
|
2796
|
+
Examples:
|
|
2797
|
+
$ diafunc auth login sign in with a browser
|
|
2798
|
+
$ diafunc auth status who you are signed in as
|
|
2799
|
+
$ diafunc auth token create a token for scripts and CI
|
|
2800
|
+
$ diafunc auth logout
|
|
2801
|
+
`);
|
|
2802
|
+
;
|
|
2372
2803
|
registerLoginCommand(auth);
|
|
2373
2804
|
registerLogoutCommand(auth);
|
|
2374
2805
|
registerStatusCommand(auth);
|
|
@@ -2376,20 +2807,29 @@ function registerAuthCommands(program) {
|
|
|
2376
2807
|
}
|
|
2377
2808
|
|
|
2378
2809
|
// src/commands/config/index.ts
|
|
2379
|
-
import
|
|
2810
|
+
import chalk9 from "chalk";
|
|
2380
2811
|
function registerConfigCommands(program) {
|
|
2381
|
-
const config = program.command("config").description("Manage CLI configuration")
|
|
2812
|
+
const config = program.command("config").description("Manage CLI configuration").addHelpText("after", `
|
|
2813
|
+
Setting a default project lets every command that takes one omit it.
|
|
2814
|
+
|
|
2815
|
+
Examples:
|
|
2816
|
+
$ diafunc config list
|
|
2817
|
+
$ diafunc config set defaults.project <id>
|
|
2818
|
+
$ diafunc config set defaults.output json
|
|
2819
|
+
$ diafunc config profile add staging --endpoint https://staging.diafunc.com
|
|
2820
|
+
`);
|
|
2821
|
+
;
|
|
2382
2822
|
config.command("set").description("Set a configuration value").argument("<key>", "Config key (e.g., defaults.project, defaults.branch, defaults.output)").argument("<value>", "Config value").action((key, value) => {
|
|
2383
2823
|
const cfg = loadConfig();
|
|
2384
2824
|
setNestedValue(cfg, key, value);
|
|
2385
2825
|
saveConfig(cfg);
|
|
2386
|
-
|
|
2826
|
+
success(`Set ${key} = ${value}`);
|
|
2387
2827
|
});
|
|
2388
2828
|
config.command("get").description("Get a configuration value").argument("<key>", "Config key").action((key) => {
|
|
2389
2829
|
const cfg = loadConfig();
|
|
2390
2830
|
const value = getNestedValue(cfg, key);
|
|
2391
2831
|
if (value === void 0) {
|
|
2392
|
-
console.log(
|
|
2832
|
+
console.log(chalk9.dim("(not set)"));
|
|
2393
2833
|
} else {
|
|
2394
2834
|
console.log(String(value));
|
|
2395
2835
|
}
|
|
@@ -2399,20 +2839,20 @@ function registerConfigCommands(program) {
|
|
|
2399
2839
|
const globalOpts = cmd.optsWithGlobals();
|
|
2400
2840
|
const outputFormat = globalOpts.output ?? "human";
|
|
2401
2841
|
if (outputFormat === "human") {
|
|
2402
|
-
console.log(
|
|
2403
|
-
console.log(
|
|
2842
|
+
console.log(chalk9.bold("Config file:"), CONFIG_FILE);
|
|
2843
|
+
console.log(chalk9.bold("Active profile:"), cfg.currentProfile);
|
|
2404
2844
|
console.log();
|
|
2405
|
-
console.log(
|
|
2845
|
+
console.log(chalk9.bold("Profiles:"));
|
|
2406
2846
|
for (const [name, profile2] of Object.entries(cfg.profiles)) {
|
|
2407
|
-
const active = name === cfg.currentProfile ?
|
|
2847
|
+
const active = name === cfg.currentProfile ? chalk9.green(" (active)") : "";
|
|
2408
2848
|
const authType = profile2.auth?.type ?? "none";
|
|
2409
|
-
console.log(` ${
|
|
2849
|
+
console.log(` ${chalk9.bold(name)}${active}`);
|
|
2410
2850
|
console.log(` Endpoint: ${profile2.endpoint}`);
|
|
2411
2851
|
console.log(` Auth: ${authType}`);
|
|
2412
2852
|
}
|
|
2413
2853
|
if (Object.keys(cfg.defaults).length > 0) {
|
|
2414
2854
|
console.log();
|
|
2415
|
-
console.log(
|
|
2855
|
+
console.log(chalk9.bold("Defaults:"));
|
|
2416
2856
|
for (const [key, value] of Object.entries(cfg.defaults)) {
|
|
2417
2857
|
console.log(` ${key}: ${value}`);
|
|
2418
2858
|
}
|
|
@@ -2425,7 +2865,7 @@ function registerConfigCommands(program) {
|
|
|
2425
2865
|
profile.command("add").description("Add a new profile").argument("<name>", "Profile name").option("--endpoint <url>", "API endpoint URL", "https://diafunc.com").option("--token <token>", "API token to store").action((name, options) => {
|
|
2426
2866
|
const cfg = loadConfig();
|
|
2427
2867
|
if (cfg.profiles[name]) {
|
|
2428
|
-
|
|
2868
|
+
failure(`Profile "${name}" already exists. Use 'diafunc config profile use' to switch to it.`);
|
|
2429
2869
|
process.exit(1);
|
|
2430
2870
|
}
|
|
2431
2871
|
cfg.profiles[name] = {
|
|
@@ -2433,18 +2873,18 @@ function registerConfigCommands(program) {
|
|
|
2433
2873
|
...options.token ? { auth: { type: "api-token", token: options.token } } : {}
|
|
2434
2874
|
};
|
|
2435
2875
|
saveConfig(cfg);
|
|
2436
|
-
|
|
2876
|
+
success(`Profile "${name}" added.`);
|
|
2437
2877
|
});
|
|
2438
2878
|
profile.command("use").description("Switch to a profile").argument("<name>", "Profile name").action((name) => {
|
|
2439
2879
|
const cfg = loadConfig();
|
|
2440
2880
|
if (!cfg.profiles[name]) {
|
|
2441
|
-
|
|
2881
|
+
failure(`Profile "${name}" not found.`);
|
|
2442
2882
|
console.log(`Available profiles: ${Object.keys(cfg.profiles).join(", ")}`);
|
|
2443
2883
|
process.exit(1);
|
|
2444
2884
|
}
|
|
2445
2885
|
cfg.currentProfile = name;
|
|
2446
2886
|
saveConfig(cfg);
|
|
2447
|
-
|
|
2887
|
+
success(`Switched to profile "${name}".`);
|
|
2448
2888
|
});
|
|
2449
2889
|
profile.command("list").description("List all profiles").action((_options, cmd) => {
|
|
2450
2890
|
const cfg = loadConfig();
|
|
@@ -2464,16 +2904,16 @@ function registerConfigCommands(program) {
|
|
|
2464
2904
|
profile.command("remove").description("Remove a profile").argument("<name>", "Profile name").action((name) => {
|
|
2465
2905
|
const cfg = loadConfig();
|
|
2466
2906
|
if (!cfg.profiles[name]) {
|
|
2467
|
-
|
|
2907
|
+
failure(`Profile "${name}" not found.`);
|
|
2468
2908
|
process.exit(1);
|
|
2469
2909
|
}
|
|
2470
2910
|
if (name === cfg.currentProfile) {
|
|
2471
|
-
|
|
2911
|
+
failure(`Cannot remove the active profile. Switch to another profile first.`);
|
|
2472
2912
|
process.exit(1);
|
|
2473
2913
|
}
|
|
2474
2914
|
delete cfg.profiles[name];
|
|
2475
2915
|
saveConfig(cfg);
|
|
2476
|
-
|
|
2916
|
+
success(`Profile "${name}" removed.`);
|
|
2477
2917
|
});
|
|
2478
2918
|
}
|
|
2479
2919
|
function setNestedValue(obj, path11, value) {
|
|
@@ -2501,7 +2941,7 @@ function getNestedValue(obj, path11) {
|
|
|
2501
2941
|
}
|
|
2502
2942
|
|
|
2503
2943
|
// src/commands/project/index.ts
|
|
2504
|
-
import
|
|
2944
|
+
import chalk12 from "chalk";
|
|
2505
2945
|
|
|
2506
2946
|
// src/util/references.ts
|
|
2507
2947
|
function parseEntityReference(ref, overrides) {
|
|
@@ -2586,29 +3026,134 @@ function parseProjectReference(ref, overrides) {
|
|
|
2586
3026
|
}
|
|
2587
3027
|
|
|
2588
3028
|
// src/commands/bundle-helpers.ts
|
|
2589
|
-
import
|
|
3029
|
+
import chalk11 from "chalk";
|
|
2590
3030
|
import * as fs2 from "fs";
|
|
2591
3031
|
import * as path2 from "path";
|
|
3032
|
+
|
|
3033
|
+
// src/output/progress.ts
|
|
3034
|
+
import chalk10 from "chalk";
|
|
3035
|
+
var ESC = "\x1B[";
|
|
3036
|
+
var CURSOR_UP = (n) => `${ESC}${n}A`;
|
|
3037
|
+
var CLEAR_BELOW = `${ESC}0J`;
|
|
3038
|
+
var SPINNER = "\0spinner\0";
|
|
3039
|
+
var Status = class _Status {
|
|
3040
|
+
lines = [];
|
|
3041
|
+
painted = 0;
|
|
3042
|
+
lastLogged = "";
|
|
3043
|
+
spinnerIndex = 0;
|
|
3044
|
+
timer = null;
|
|
3045
|
+
static FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
3046
|
+
/** Replaces the transient block. Repaints only when the content actually changed. */
|
|
3047
|
+
set(lines) {
|
|
3048
|
+
const next = lines.filter((l) => l !== void 0);
|
|
3049
|
+
if (!isInteractive()) {
|
|
3050
|
+
const joined = next.map((l) => l.split(SPINNER).join("").trim()).filter(Boolean).join(" \xB7 ");
|
|
3051
|
+
if (joined && joined !== this.lastLogged) {
|
|
3052
|
+
this.lastLogged = joined;
|
|
3053
|
+
console.log(joined);
|
|
3054
|
+
}
|
|
3055
|
+
this.lines = next;
|
|
3056
|
+
return;
|
|
3057
|
+
}
|
|
3058
|
+
this.lines = next;
|
|
3059
|
+
this.repaint();
|
|
3060
|
+
}
|
|
3061
|
+
/** Prints a durable line above the transient block. */
|
|
3062
|
+
log(line) {
|
|
3063
|
+
if (!isInteractive()) {
|
|
3064
|
+
console.log(line);
|
|
3065
|
+
return;
|
|
3066
|
+
}
|
|
3067
|
+
this.erase();
|
|
3068
|
+
console.log(line);
|
|
3069
|
+
this.repaint();
|
|
3070
|
+
}
|
|
3071
|
+
/**
|
|
3072
|
+
* Starts the spinner animation. The caller still drives content through {@link set}; this only
|
|
3073
|
+
* advances the frame so a long wait does not look like a hung process.
|
|
3074
|
+
*/
|
|
3075
|
+
start() {
|
|
3076
|
+
if (this.timer || !isInteractive()) return;
|
|
3077
|
+
this.timer = setInterval(() => {
|
|
3078
|
+
this.spinnerIndex = (this.spinnerIndex + 1) % _Status.FRAMES.length;
|
|
3079
|
+
this.repaint();
|
|
3080
|
+
}, 80);
|
|
3081
|
+
this.timer.unref?.();
|
|
3082
|
+
}
|
|
3083
|
+
/** Stops the animation and clears the transient block for good. */
|
|
3084
|
+
stop() {
|
|
3085
|
+
if (this.timer) {
|
|
3086
|
+
clearInterval(this.timer);
|
|
3087
|
+
this.timer = null;
|
|
3088
|
+
}
|
|
3089
|
+
this.erase();
|
|
3090
|
+
this.lines = [];
|
|
3091
|
+
}
|
|
3092
|
+
/** The current spinner glyph, for a caller that wants one frame rather than an animation. */
|
|
3093
|
+
spinner() {
|
|
3094
|
+
return isInteractive() ? _Status.FRAMES[this.spinnerIndex] : "\xB7";
|
|
3095
|
+
}
|
|
3096
|
+
frame(line) {
|
|
3097
|
+
return line.includes(SPINNER) ? line.split(SPINNER).join(this.spinner()) : line;
|
|
3098
|
+
}
|
|
3099
|
+
repaint() {
|
|
3100
|
+
this.erase();
|
|
3101
|
+
const width = terminalWidth();
|
|
3102
|
+
for (const line of this.lines) {
|
|
3103
|
+
process.stdout.write(truncate(this.frame(line), width) + "\n");
|
|
3104
|
+
}
|
|
3105
|
+
this.painted = this.lines.length;
|
|
3106
|
+
}
|
|
3107
|
+
erase() {
|
|
3108
|
+
if (this.painted === 0) return;
|
|
3109
|
+
process.stdout.write(CURSOR_UP(this.painted) + CLEAR_BELOW);
|
|
3110
|
+
this.painted = 0;
|
|
3111
|
+
}
|
|
3112
|
+
};
|
|
3113
|
+
async function withStatus(label, work) {
|
|
3114
|
+
const status = new Status();
|
|
3115
|
+
status.set([`${chalk10.cyan(SPINNER)} ${label}`]);
|
|
3116
|
+
status.start();
|
|
3117
|
+
const startedAt = Date.now();
|
|
3118
|
+
try {
|
|
3119
|
+
const result = await work();
|
|
3120
|
+
status.stop();
|
|
3121
|
+
console.log(`${chalk10.green("\u2713")} ${label} ${chalk10.dim(`(${Date.now() - startedAt}ms)`)}`);
|
|
3122
|
+
return result;
|
|
3123
|
+
} catch (error) {
|
|
3124
|
+
status.stop();
|
|
3125
|
+
console.error(`${chalk10.red("\u2717")} ${label}`);
|
|
3126
|
+
throw error;
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
function bar(fraction, width = 28) {
|
|
3130
|
+
const clamped = Math.max(0, Math.min(1, Number.isFinite(fraction) ? fraction : 0));
|
|
3131
|
+
const filled = Math.round(clamped * width);
|
|
3132
|
+
return chalk10.cyan("\u2588".repeat(filled)) + chalk10.dim("\u2591".repeat(width - filled));
|
|
3133
|
+
}
|
|
3134
|
+
function percent(fraction) {
|
|
3135
|
+
const clamped = Math.max(0, Math.min(1, Number.isFinite(fraction) ? fraction : 0));
|
|
3136
|
+
return `${Math.round(clamped * 100)}%`.padStart(4);
|
|
3137
|
+
}
|
|
3138
|
+
|
|
3139
|
+
// src/commands/bundle-helpers.ts
|
|
2592
3140
|
async function streamResponseToFile(response, outFile) {
|
|
2593
3141
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
2594
3142
|
fs2.writeFileSync(outFile, buffer);
|
|
2595
3143
|
return buffer.length;
|
|
2596
3144
|
}
|
|
2597
3145
|
function printLossiness(notes) {
|
|
2598
|
-
if (notes
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
console.log(chalk9.yellow(` - ${note}`));
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
3146
|
+
if (!notes || notes.length === 0) return;
|
|
3147
|
+
warn(notes.length === 1 ? "One detail could not be carried in the bundle:" : "Some details could not be carried in the bundle:");
|
|
3148
|
+
for (const note of notes) hint(`- ${note}`);
|
|
2604
3149
|
}
|
|
2605
3150
|
function printImportPreview(preview) {
|
|
2606
|
-
console.log(
|
|
3151
|
+
console.log(chalk11.bold(`${preview.kind} bundle \xB7 ${preview.entityCount} entities`));
|
|
2607
3152
|
if (preview.projectName) {
|
|
2608
|
-
console.log(
|
|
3153
|
+
console.log(chalk11.dim(preview.projectName));
|
|
2609
3154
|
}
|
|
2610
3155
|
if (preview.sourceProjectId) {
|
|
2611
|
-
console.log(
|
|
3156
|
+
console.log(chalk11.dim(`from ${preview.sourceProjectId}/${preview.sourceProjectBranch}` + (preview.createdBy ? ` \xB7 by ${preview.createdBy}` : "")));
|
|
2612
3157
|
}
|
|
2613
3158
|
const counts = /* @__PURE__ */ new Map();
|
|
2614
3159
|
for (const e of preview.entities ?? []) {
|
|
@@ -2629,7 +3174,7 @@ function printImportPreview(preview) {
|
|
|
2629
3174
|
printLossiness(preview.lossinessNotes);
|
|
2630
3175
|
}
|
|
2631
3176
|
function printImportResult(result) {
|
|
2632
|
-
|
|
3177
|
+
success(`Imported ${result.entityCount} entities, ${result.linkCount} links.`);
|
|
2633
3178
|
if (result.skeletonCount) {
|
|
2634
3179
|
console.log(`Skeletons: ${result.skeletonCount}`);
|
|
2635
3180
|
}
|
|
@@ -2667,21 +3212,40 @@ async function runBundleImport(storage, projectId, projectBranch, file, options,
|
|
|
2667
3212
|
}
|
|
2668
3213
|
var sleep2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
2669
3214
|
async function pollUntilFinished(storage, projectId, projectBranch, bundleId, intervalMs = 2e3, maxAttempts = 150) {
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
3215
|
+
const status = new Status();
|
|
3216
|
+
status.start();
|
|
3217
|
+
const startedAt = Date.now();
|
|
3218
|
+
try {
|
|
3219
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
3220
|
+
const bundles = await storage.getBundles(projectId, projectBranch);
|
|
3221
|
+
const job = bundles.find((b) => b.bundleId === bundleId);
|
|
3222
|
+
if (job && job.finished) {
|
|
3223
|
+
if (job.succeeded === false) {
|
|
3224
|
+
throw new Error(`Export failed: ${job.error || "unknown error"}`);
|
|
3225
|
+
}
|
|
3226
|
+
return job;
|
|
2676
3227
|
}
|
|
2677
|
-
|
|
3228
|
+
status.set([progressLine("Exporting", job?.progress, Date.now() - startedAt)]);
|
|
3229
|
+
await sleep2(intervalMs);
|
|
2678
3230
|
}
|
|
2679
|
-
|
|
3231
|
+
} finally {
|
|
3232
|
+
status.stop();
|
|
2680
3233
|
}
|
|
2681
|
-
throw new Error(
|
|
3234
|
+
throw new Error(
|
|
3235
|
+
`Export ${bundleId} is still running after ${formatDuration(intervalMs * maxAttempts)} \u2014 check it with 'diafunc notebook bundles ${projectId}'`
|
|
3236
|
+
);
|
|
3237
|
+
}
|
|
3238
|
+
function progressLine(label, progress, elapsedMs) {
|
|
3239
|
+
const elapsed = chalk11.dim(formatDuration(elapsedMs));
|
|
3240
|
+
if (progress === null || progress === void 0) {
|
|
3241
|
+
return ` ${chalk11.cyan(SPINNER)} ${label} ${elapsed}`;
|
|
3242
|
+
}
|
|
3243
|
+
const fraction = progress > 1 ? progress / 100 : progress;
|
|
3244
|
+
return ` ${chalk11.cyan(SPINNER)} ${label} ${bar(fraction, 20)} ${percent(fraction)} ${elapsed}`;
|
|
2682
3245
|
}
|
|
2683
3246
|
|
|
2684
3247
|
// src/util/function-language.ts
|
|
3248
|
+
var FUNCTION_LANGUAGES = ["Java", "Kotlin", "Python", "JavaScript", "Scala"];
|
|
2685
3249
|
var DEFAULT_FUNCTION_LANGUAGE = "Java";
|
|
2686
3250
|
async function resolveLanguage(api, projectId, explicit) {
|
|
2687
3251
|
if (explicit) {
|
|
@@ -2709,15 +3273,39 @@ function getOverrides(cmd) {
|
|
|
2709
3273
|
}
|
|
2710
3274
|
function registerProjectCommands(program) {
|
|
2711
3275
|
const project = program.command("project").description("Manage projects");
|
|
2712
|
-
project.command("list").description("List projects").option("--all", "List
|
|
3276
|
+
project.command("list").description("List projects").option("--all", "List every project on the platform (admin)").option("--limit <n>", "Maximum projects to show; 0 for all", "20").addHelpText("after", `
|
|
3277
|
+
Examples:
|
|
3278
|
+
$ diafunc project list the twenty most recent
|
|
3279
|
+
$ diafunc project list --limit 0 every one of them
|
|
3280
|
+
$ diafunc search "housing" --type project find a project by name
|
|
3281
|
+
|
|
3282
|
+
A project's name lives on its main entity rather than on the project row, so this listing shows
|
|
3283
|
+
ids. Use 'diafunc search --type project' when you know the name but not the id.
|
|
3284
|
+
`).action(async (options, cmd) => {
|
|
2713
3285
|
try {
|
|
2714
3286
|
const outputFormat = getOutputFormat(cmd);
|
|
2715
3287
|
const api = createApiClient();
|
|
2716
3288
|
const projects = options.all ? await api.admin.getAllProjects() : await api.admin.getProjects();
|
|
2717
|
-
|
|
3289
|
+
const limit = Number.parseInt(options.limit, 10);
|
|
3290
|
+
const capped = Number.isFinite(limit) && limit > 0 ? projects.slice(0, limit) : projects;
|
|
3291
|
+
format(capped, {
|
|
2718
3292
|
format: outputFormat,
|
|
2719
|
-
columns: [
|
|
2720
|
-
|
|
3293
|
+
columns: [
|
|
3294
|
+
{ key: "projectId", kind: "id" },
|
|
3295
|
+
{ key: "teamName", header: "team" },
|
|
3296
|
+
{ key: "visibility" },
|
|
3297
|
+
{ key: "language" },
|
|
3298
|
+
{ key: "active", kind: "boolean" },
|
|
3299
|
+
{ key: "locked", kind: "boolean" },
|
|
3300
|
+
{ key: "created", kind: "date" }
|
|
3301
|
+
]
|
|
3302
|
+
});
|
|
3303
|
+
if (capped.length < projects.length) {
|
|
3304
|
+
console.log(chalk12.dim(
|
|
3305
|
+
`
|
|
3306
|
+
Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
3307
|
+
));
|
|
3308
|
+
}
|
|
2721
3309
|
} catch (error) {
|
|
2722
3310
|
handleError(error);
|
|
2723
3311
|
}
|
|
@@ -2742,8 +3330,8 @@ function registerProjectCommands(program) {
|
|
|
2742
3330
|
active: true
|
|
2743
3331
|
});
|
|
2744
3332
|
if (outputFormat === "human") {
|
|
2745
|
-
|
|
2746
|
-
console.log(` Project ID: ${
|
|
3333
|
+
success("Project created.");
|
|
3334
|
+
console.log(` Project ID: ${chalk12.bold(p.projectId)}`);
|
|
2747
3335
|
console.log(` Visibility: ${p.visibility}`);
|
|
2748
3336
|
console.log(` Language: ${p.language}`);
|
|
2749
3337
|
} else {
|
|
@@ -2764,7 +3352,7 @@ function registerProjectCommands(program) {
|
|
|
2764
3352
|
...options.active !== void 0 ? { active: options.active === "true" } : {}
|
|
2765
3353
|
};
|
|
2766
3354
|
await api.admin.updateProject(updated);
|
|
2767
|
-
|
|
3355
|
+
success(`Project "${projectId}" updated.`);
|
|
2768
3356
|
} catch (error) {
|
|
2769
3357
|
handleError(error);
|
|
2770
3358
|
}
|
|
@@ -2776,7 +3364,11 @@ function registerProjectCommands(program) {
|
|
|
2776
3364
|
const recent = await api.admin.getRecentProjects();
|
|
2777
3365
|
format(recent, {
|
|
2778
3366
|
format: outputFormat,
|
|
2779
|
-
columns: [
|
|
3367
|
+
columns: [
|
|
3368
|
+
{ key: "projectId", kind: "id" },
|
|
3369
|
+
{ key: "projectBranch", header: "branch" },
|
|
3370
|
+
{ key: "lastAccessed", kind: "date" }
|
|
3371
|
+
]
|
|
2780
3372
|
});
|
|
2781
3373
|
} catch (error) {
|
|
2782
3374
|
handleError(error);
|
|
@@ -2786,7 +3378,7 @@ function registerProjectCommands(program) {
|
|
|
2786
3378
|
try {
|
|
2787
3379
|
const api = createApiClient();
|
|
2788
3380
|
await api.admin.deleteProject(projectId);
|
|
2789
|
-
|
|
3381
|
+
success(`Project "${projectId}" deleted.`);
|
|
2790
3382
|
} catch (error) {
|
|
2791
3383
|
handleError(error);
|
|
2792
3384
|
}
|
|
@@ -2795,7 +3387,7 @@ function registerProjectCommands(program) {
|
|
|
2795
3387
|
try {
|
|
2796
3388
|
const api = createApiClient();
|
|
2797
3389
|
await api.admin.lockProject(projectId);
|
|
2798
|
-
|
|
3390
|
+
success(`Project "${projectId}" locked.`);
|
|
2799
3391
|
} catch (error) {
|
|
2800
3392
|
handleError(error);
|
|
2801
3393
|
}
|
|
@@ -2804,7 +3396,7 @@ function registerProjectCommands(program) {
|
|
|
2804
3396
|
try {
|
|
2805
3397
|
const api = createApiClient();
|
|
2806
3398
|
await api.admin.unlockProject(projectId);
|
|
2807
|
-
|
|
3399
|
+
success(`Project "${projectId}" unlocked.`);
|
|
2808
3400
|
} catch (error) {
|
|
2809
3401
|
handleError(error);
|
|
2810
3402
|
}
|
|
@@ -2827,7 +3419,7 @@ function registerProjectCommands(program) {
|
|
|
2827
3419
|
try {
|
|
2828
3420
|
const api = createApiClient();
|
|
2829
3421
|
await api.admin.inviteProjectMember(projectId, userId, role.toUpperCase());
|
|
2830
|
-
|
|
3422
|
+
success(`Invited ${userId} to "${projectId}" as ${role.toUpperCase()}.`);
|
|
2831
3423
|
} catch (error) {
|
|
2832
3424
|
handleError(error);
|
|
2833
3425
|
}
|
|
@@ -2836,7 +3428,7 @@ function registerProjectCommands(program) {
|
|
|
2836
3428
|
try {
|
|
2837
3429
|
const api = createApiClient();
|
|
2838
3430
|
await api.admin.joinProject(projectId, userId);
|
|
2839
|
-
|
|
3431
|
+
success(`Joined project "${projectId}".`);
|
|
2840
3432
|
} catch (error) {
|
|
2841
3433
|
handleError(error);
|
|
2842
3434
|
}
|
|
@@ -2845,7 +3437,7 @@ function registerProjectCommands(program) {
|
|
|
2845
3437
|
try {
|
|
2846
3438
|
const api = createApiClient();
|
|
2847
3439
|
await api.admin.removeProjectMember(projectId, userId);
|
|
2848
|
-
|
|
3440
|
+
success(`Removed ${userId} from "${projectId}".`);
|
|
2849
3441
|
} catch (error) {
|
|
2850
3442
|
handleError(error);
|
|
2851
3443
|
}
|
|
@@ -2857,16 +3449,16 @@ function registerProjectCommands(program) {
|
|
|
2857
3449
|
const api = createApiClient();
|
|
2858
3450
|
const bundleId = await api.storage.exportProjectBundle(ref.projectId, ref.projectBranch);
|
|
2859
3451
|
if (options.async) {
|
|
2860
|
-
|
|
3452
|
+
success(`Project export queued (bundle ID: ${bundleId}).`);
|
|
2861
3453
|
console.log(`Poll progress: diafunc notebook bundles ${project2}`);
|
|
2862
3454
|
return;
|
|
2863
3455
|
}
|
|
2864
|
-
console.log(
|
|
3456
|
+
console.log(chalk12.dim(`Project export queued (bundle ID: ${bundleId}); waiting for it to finish\u2026`));
|
|
2865
3457
|
const job = await pollUntilFinished(api.storage, ref.projectId, ref.projectBranch, bundleId);
|
|
2866
3458
|
const response = await api.storage.getBundleContent(ref.projectId, ref.projectBranch, bundleId, job.filename);
|
|
2867
3459
|
const outFile = options.out ?? "project.dfproj";
|
|
2868
3460
|
const bytes = await streamResponseToFile(response, outFile);
|
|
2869
|
-
|
|
3461
|
+
success(`Bundle written to ${outFile} (${bytes} bytes, ${job.entityCount ?? "?"} entities).`);
|
|
2870
3462
|
} catch (error) {
|
|
2871
3463
|
handleError(error);
|
|
2872
3464
|
}
|
|
@@ -2885,25 +3477,25 @@ function registerProjectCommands(program) {
|
|
|
2885
3477
|
}
|
|
2886
3478
|
|
|
2887
3479
|
// src/commands/team/index.ts
|
|
2888
|
-
import
|
|
3480
|
+
import chalk14 from "chalk";
|
|
2889
3481
|
|
|
2890
3482
|
// src/util/confirm.ts
|
|
2891
3483
|
import * as readline from "readline";
|
|
2892
|
-
import
|
|
3484
|
+
import chalk13 from "chalk";
|
|
2893
3485
|
async function confirmDestructive(message, opts = {}) {
|
|
2894
3486
|
if (!process.stdin.isTTY || opts.yes) return;
|
|
2895
3487
|
const expected = opts.resourceId ?? "yes";
|
|
2896
|
-
const
|
|
2897
|
-
console.log(
|
|
3488
|
+
const hint2 = opts.resourceId ? `"${opts.resourceId}"` : '"yes"';
|
|
3489
|
+
console.log(chalk13.yellow(`! ${message}`));
|
|
2898
3490
|
const answer = await new Promise((resolve) => {
|
|
2899
3491
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
2900
|
-
rl.question(` Type ${
|
|
3492
|
+
rl.question(` Type ${hint2} to confirm: `, (ans) => {
|
|
2901
3493
|
rl.close();
|
|
2902
3494
|
resolve(ans);
|
|
2903
3495
|
});
|
|
2904
3496
|
});
|
|
2905
3497
|
if (answer.trim() !== expected) {
|
|
2906
|
-
console.log(
|
|
3498
|
+
console.log(chalk13.dim("Aborted."));
|
|
2907
3499
|
process.exit(1);
|
|
2908
3500
|
}
|
|
2909
3501
|
}
|
|
@@ -2963,15 +3555,21 @@ function printInvoicePreview(preview, outputFormat) {
|
|
|
2963
3555
|
}
|
|
2964
3556
|
}
|
|
2965
3557
|
function registerTeamCommands(program) {
|
|
2966
|
-
const team = program.command("team").description("Manage teams: membership, invitations, seats, billing, and ownership")
|
|
3558
|
+
const team = program.command("team").description("Manage teams: membership, invitations, seats, billing, and ownership").addHelpText("after", `
|
|
3559
|
+
Examples:
|
|
3560
|
+
$ diafunc team list the teams you belong to
|
|
3561
|
+
$ diafunc team use <teamId> work under one
|
|
3562
|
+
$ diafunc team usage <teamId> credits, by member
|
|
3563
|
+
$ diafunc team members invite <teamId> <email> MEMBER
|
|
3564
|
+
`);
|
|
3565
|
+
;
|
|
2967
3566
|
team.command("list", { isDefault: true }).description("List the teams you belong to").action(async (_options, cmd) => {
|
|
2968
3567
|
try {
|
|
2969
3568
|
const api = createApiClient();
|
|
2970
3569
|
const teams = await api.admin.listMyTeams();
|
|
2971
3570
|
format(teams, {
|
|
2972
3571
|
format: getOutputFormat2(cmd),
|
|
2973
|
-
columns: ["id", "name", "planId", "seatCount", "packCount", "renewal"]
|
|
2974
|
-
dateColumns: ["createdAt", "dunningStartedAt"]
|
|
3572
|
+
columns: ["id", "name", "planId", "seatCount", "packCount", "renewal"]
|
|
2975
3573
|
});
|
|
2976
3574
|
} catch (error) {
|
|
2977
3575
|
handleError(error);
|
|
@@ -2981,8 +3579,7 @@ function registerTeamCommands(program) {
|
|
|
2981
3579
|
try {
|
|
2982
3580
|
const api = createApiClient();
|
|
2983
3581
|
format(await api.admin.getTeam(teamId), {
|
|
2984
|
-
format: getOutputFormat2(cmd)
|
|
2985
|
-
dateColumns: ["createdAt", "dunningStartedAt"]
|
|
3582
|
+
format: getOutputFormat2(cmd)
|
|
2986
3583
|
});
|
|
2987
3584
|
} catch (error) {
|
|
2988
3585
|
handleError(error);
|
|
@@ -2992,7 +3589,7 @@ function registerTeamCommands(program) {
|
|
|
2992
3589
|
try {
|
|
2993
3590
|
const api = createApiClient();
|
|
2994
3591
|
await api.admin.setActiveTeam(teamId);
|
|
2995
|
-
|
|
3592
|
+
success(`Active team set to "${teamId}".`, { format: getOutputFormat2(cmd) });
|
|
2996
3593
|
} catch (error) {
|
|
2997
3594
|
handleError(error);
|
|
2998
3595
|
}
|
|
@@ -3034,7 +3631,7 @@ function registerTeamCommands(program) {
|
|
|
3034
3631
|
return;
|
|
3035
3632
|
}
|
|
3036
3633
|
console.log("Open this URL to complete checkout:");
|
|
3037
|
-
console.log(
|
|
3634
|
+
console.log(chalk14.cyan(session.url));
|
|
3038
3635
|
} catch (error) {
|
|
3039
3636
|
handleError(error);
|
|
3040
3637
|
}
|
|
@@ -3049,7 +3646,7 @@ function registerTeamCommands(program) {
|
|
|
3049
3646
|
return;
|
|
3050
3647
|
}
|
|
3051
3648
|
console.log("Open this URL to manage billing:");
|
|
3052
|
-
console.log(
|
|
3649
|
+
console.log(chalk14.cyan(session.url));
|
|
3053
3650
|
} catch (error) {
|
|
3054
3651
|
handleError(error);
|
|
3055
3652
|
}
|
|
@@ -3062,7 +3659,7 @@ function registerTeamCommands(program) {
|
|
|
3062
3659
|
);
|
|
3063
3660
|
const api = createApiClient();
|
|
3064
3661
|
const response = await api.admin.cancelTeam(teamId);
|
|
3065
|
-
|
|
3662
|
+
success(
|
|
3066
3663
|
`Team "${teamId}" cancelled. Access ends ${response.endsAt ?? "at the end of the period"}.`,
|
|
3067
3664
|
{ format: getOutputFormat2(cmd) }
|
|
3068
3665
|
);
|
|
@@ -3078,7 +3675,7 @@ function registerTeamCommands(program) {
|
|
|
3078
3675
|
});
|
|
3079
3676
|
const api = createApiClient();
|
|
3080
3677
|
await api.admin.leaveTeam(teamId);
|
|
3081
|
-
|
|
3678
|
+
success(`Left team "${teamId}".`, { format: getOutputFormat2(cmd) });
|
|
3082
3679
|
} catch (error) {
|
|
3083
3680
|
handleError(error);
|
|
3084
3681
|
}
|
|
@@ -3098,8 +3695,7 @@ function registerMemberCommands(team) {
|
|
|
3098
3695
|
const shown = options.all ? all : all.filter((m) => !m.removedAt);
|
|
3099
3696
|
format(shown, {
|
|
3100
3697
|
format: getOutputFormat2(cmd),
|
|
3101
|
-
columns: options.all ? ["userId", "name", "email", "role", "joinedAt", "removedAt"] : ["userId", "name", "email", "role", "joinedAt"]
|
|
3102
|
-
dateColumns: ["joinedAt", "invitedAt", "removedAt"]
|
|
3698
|
+
columns: options.all ? ["userId", "name", "email", "role", "joinedAt", "removedAt"] : ["userId", "name", "email", "role", "joinedAt"]
|
|
3103
3699
|
});
|
|
3104
3700
|
} catch (error) {
|
|
3105
3701
|
handleError(error);
|
|
@@ -3110,7 +3706,7 @@ function registerMemberCommands(team) {
|
|
|
3110
3706
|
const role = parseRole(options.role);
|
|
3111
3707
|
const api = createApiClient();
|
|
3112
3708
|
await api.admin.inviteTeamMember(teamId, email, role);
|
|
3113
|
-
|
|
3709
|
+
success(`Invited ${email} to team "${teamId}" as ${role}.`, {
|
|
3114
3710
|
format: getOutputFormat2(cmd)
|
|
3115
3711
|
});
|
|
3116
3712
|
} catch (error) {
|
|
@@ -3125,7 +3721,7 @@ function registerMemberCommands(team) {
|
|
|
3125
3721
|
});
|
|
3126
3722
|
const api = createApiClient();
|
|
3127
3723
|
await api.admin.removeTeamMember(teamId, userId);
|
|
3128
|
-
|
|
3724
|
+
success(`Removed ${userId} from team "${teamId}".`, {
|
|
3129
3725
|
format: getOutputFormat2(cmd)
|
|
3130
3726
|
});
|
|
3131
3727
|
} catch (error) {
|
|
@@ -3140,8 +3736,7 @@ function registerInvitationCommands(team) {
|
|
|
3140
3736
|
const api = createApiClient();
|
|
3141
3737
|
format(await api.admin.listTeamInvitations(teamId), {
|
|
3142
3738
|
format: getOutputFormat2(cmd),
|
|
3143
|
-
columns: ["invitationId", "email", "role", "invitedBy", "expiresAt"]
|
|
3144
|
-
dateColumns: ["createdAt", "expiresAt"]
|
|
3739
|
+
columns: ["invitationId", "email", "role", "invitedBy", "expiresAt"]
|
|
3145
3740
|
});
|
|
3146
3741
|
} catch (error) {
|
|
3147
3742
|
handleError(error);
|
|
@@ -3155,7 +3750,7 @@ function registerInvitationCommands(team) {
|
|
|
3155
3750
|
});
|
|
3156
3751
|
const api = createApiClient();
|
|
3157
3752
|
await api.admin.revokeTeamInvitation(teamId, invitationId);
|
|
3158
|
-
|
|
3753
|
+
success(`Revoked invitation "${invitationId}".`, {
|
|
3159
3754
|
format: getOutputFormat2(cmd)
|
|
3160
3755
|
});
|
|
3161
3756
|
} catch (error) {
|
|
@@ -3166,7 +3761,7 @@ function registerInvitationCommands(team) {
|
|
|
3166
3761
|
try {
|
|
3167
3762
|
const api = createApiClient();
|
|
3168
3763
|
await api.admin.resendTeamInvitation(teamId, invitationId);
|
|
3169
|
-
|
|
3764
|
+
success(`Resent invitation "${invitationId}".`, {
|
|
3170
3765
|
format: getOutputFormat2(cmd)
|
|
3171
3766
|
});
|
|
3172
3767
|
} catch (error) {
|
|
@@ -3177,7 +3772,7 @@ function registerInvitationCommands(team) {
|
|
|
3177
3772
|
try {
|
|
3178
3773
|
const api = createApiClient();
|
|
3179
3774
|
const member = await api.admin.acceptTeamInvitation(token);
|
|
3180
|
-
|
|
3775
|
+
success(`Joined the team as ${member.role}.`, {
|
|
3181
3776
|
format: getOutputFormat2(cmd)
|
|
3182
3777
|
});
|
|
3183
3778
|
} catch (error) {
|
|
@@ -3207,7 +3802,7 @@ function registerSeatCommands(team) {
|
|
|
3207
3802
|
);
|
|
3208
3803
|
const api = createApiClient();
|
|
3209
3804
|
const change = await api.admin.updateTeamSeatCount(teamId, seatCount);
|
|
3210
|
-
|
|
3805
|
+
success(`Seats changed from ${change.oldSeatCount} to ${change.newSeatCount}.`, {
|
|
3211
3806
|
format: getOutputFormat2(cmd)
|
|
3212
3807
|
});
|
|
3213
3808
|
} catch (error) {
|
|
@@ -3237,7 +3832,7 @@ function registerPackCommands(team) {
|
|
|
3237
3832
|
);
|
|
3238
3833
|
const api = createApiClient();
|
|
3239
3834
|
const change = await api.admin.updateTeamPackCount(teamId, packCount);
|
|
3240
|
-
|
|
3835
|
+
success(`Packs changed from ${change.oldPackCount} to ${change.newPackCount}.`, {
|
|
3241
3836
|
format: getOutputFormat2(cmd)
|
|
3242
3837
|
});
|
|
3243
3838
|
} catch (error) {
|
|
@@ -3274,7 +3869,7 @@ function registerOwnershipCommands(team) {
|
|
|
3274
3869
|
}
|
|
3275
3870
|
return;
|
|
3276
3871
|
}
|
|
3277
|
-
format(pending, { format: outputFormat
|
|
3872
|
+
format(pending, { format: outputFormat });
|
|
3278
3873
|
} catch (error) {
|
|
3279
3874
|
handleError(error);
|
|
3280
3875
|
}
|
|
@@ -3288,10 +3883,10 @@ function registerOwnershipCommands(team) {
|
|
|
3288
3883
|
format(response, { format: outputFormat });
|
|
3289
3884
|
return;
|
|
3290
3885
|
}
|
|
3291
|
-
|
|
3886
|
+
success(`Ownership transfer ${response.status}.`);
|
|
3292
3887
|
if (response.checkoutUrl) {
|
|
3293
3888
|
console.log("Open this URL to complete the billing handover:");
|
|
3294
|
-
console.log(
|
|
3889
|
+
console.log(chalk14.cyan(response.checkoutUrl));
|
|
3295
3890
|
}
|
|
3296
3891
|
} catch (error) {
|
|
3297
3892
|
handleError(error);
|
|
@@ -3301,7 +3896,7 @@ function registerOwnershipCommands(team) {
|
|
|
3301
3896
|
try {
|
|
3302
3897
|
const api = createApiClient();
|
|
3303
3898
|
await api.admin.cancelOwnershipTransfer(teamId);
|
|
3304
|
-
|
|
3899
|
+
success(`Cancelled the ownership transfer for team "${teamId}".`, {
|
|
3305
3900
|
format: getOutputFormat2(cmd)
|
|
3306
3901
|
});
|
|
3307
3902
|
} catch (error) {
|
|
@@ -3311,7 +3906,6 @@ function registerOwnershipCommands(team) {
|
|
|
3311
3906
|
}
|
|
3312
3907
|
|
|
3313
3908
|
// src/commands/entity/index.ts
|
|
3314
|
-
import chalk13 from "chalk";
|
|
3315
3909
|
import * as fs3 from "fs";
|
|
3316
3910
|
function getOutputFormat3(cmd) {
|
|
3317
3911
|
const config = loadConfig();
|
|
@@ -3323,7 +3917,16 @@ function getOverrides2(cmd) {
|
|
|
3323
3917
|
return { project: opts.project, branch: opts.branch };
|
|
3324
3918
|
}
|
|
3325
3919
|
function registerEntityCommands(program) {
|
|
3326
|
-
const entity = program.command("entity").description("Manage entities")
|
|
3920
|
+
const entity = program.command("entity").description("Manage entities").addHelpText("after", `
|
|
3921
|
+
An entity reference is <project>/<branch>/<entity>/<entityBranch>. With
|
|
3922
|
+
'diafunc config set defaults.project <id>' the leading parts can be omitted.
|
|
3923
|
+
|
|
3924
|
+
Examples:
|
|
3925
|
+
$ diafunc entity list <projectId>
|
|
3926
|
+
$ diafunc entity get <project>/main/<entity>/main
|
|
3927
|
+
$ diafunc entity history <project>/main/<entity>/main
|
|
3928
|
+
`);
|
|
3929
|
+
;
|
|
3327
3930
|
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) => {
|
|
3328
3931
|
try {
|
|
3329
3932
|
const outputFormat = getOutputFormat3(cmd);
|
|
@@ -3389,7 +3992,7 @@ function registerEntityCommands(program) {
|
|
|
3389
3992
|
const resolved = parseEntityReference(ref, overrides);
|
|
3390
3993
|
const api = createApiClient();
|
|
3391
3994
|
await api.storage.deleteEntity(resolved);
|
|
3392
|
-
|
|
3995
|
+
success(`Entity "${resolved.entityId}" deleted.`);
|
|
3393
3996
|
} catch (error) {
|
|
3394
3997
|
handleError(error);
|
|
3395
3998
|
}
|
|
@@ -3430,7 +4033,7 @@ function registerEntityCommands(program) {
|
|
|
3430
4033
|
const resolved = parseEntityReference(ref, overrides);
|
|
3431
4034
|
const api = createApiClient();
|
|
3432
4035
|
await api.storage.revertEntity(resolved, parseInt(version, 10));
|
|
3433
|
-
|
|
4036
|
+
success(`Entity "${resolved.entityId}" reverted to version ${version}.`);
|
|
3434
4037
|
} catch (error) {
|
|
3435
4038
|
handleError(error);
|
|
3436
4039
|
}
|
|
@@ -3441,7 +4044,7 @@ function registerEntityCommands(program) {
|
|
|
3441
4044
|
const resolved = parseEntityReference(ref, overrides);
|
|
3442
4045
|
const api = createApiClient();
|
|
3443
4046
|
await api.storage.renameEntity(resolved, newId);
|
|
3444
|
-
|
|
4047
|
+
success(`Entity renamed from "${resolved.entityId}" to "${newId}".`);
|
|
3445
4048
|
} catch (error) {
|
|
3446
4049
|
handleError(error);
|
|
3447
4050
|
}
|
|
@@ -3456,7 +4059,7 @@ function registerEntityCommands(program) {
|
|
|
3456
4059
|
if (options.out) {
|
|
3457
4060
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
3458
4061
|
fs3.writeFileSync(options.out, buffer);
|
|
3459
|
-
|
|
4062
|
+
success(`Content saved to ${options.out}`);
|
|
3460
4063
|
} else {
|
|
3461
4064
|
const text = await response.text();
|
|
3462
4065
|
process.stdout.write(text);
|
|
@@ -3473,7 +4076,7 @@ function registerEntityCommands(program) {
|
|
|
3473
4076
|
const fileBuffer = fs3.readFileSync(file);
|
|
3474
4077
|
const base64 = fileBuffer.toString("base64");
|
|
3475
4078
|
await api.storage.saveEntityContentBase64(resolved, base64);
|
|
3476
|
-
|
|
4079
|
+
success(`Content uploaded from "${file}" to entity "${resolved.entityId}".`);
|
|
3477
4080
|
} catch (error) {
|
|
3478
4081
|
handleError(error);
|
|
3479
4082
|
}
|
|
@@ -3485,7 +4088,7 @@ function registerEntityCommands(program) {
|
|
|
3485
4088
|
const resolved = parseEntityReference(ref, overrides);
|
|
3486
4089
|
const api = createApiClient();
|
|
3487
4090
|
await api.storage.deleteEntityContent(resolved);
|
|
3488
|
-
|
|
4091
|
+
success(`Content deleted from entity "${resolved.entityId}".`);
|
|
3489
4092
|
} catch (error) {
|
|
3490
4093
|
handleError(error);
|
|
3491
4094
|
}
|
|
@@ -3498,14 +4101,14 @@ function registerEntityCommands(program) {
|
|
|
3498
4101
|
const request = { rootEntityIds: entityIds, dataFormat: options.data };
|
|
3499
4102
|
if (options.async) {
|
|
3500
4103
|
const bundleId = await api.storage.exportEntitySubset(ref.projectId, ref.projectBranch, request);
|
|
3501
|
-
|
|
4104
|
+
success(`Export queued (bundle ID: ${bundleId}).`);
|
|
3502
4105
|
console.log(`Poll progress: diafunc notebook bundles ${project}`);
|
|
3503
4106
|
return;
|
|
3504
4107
|
}
|
|
3505
4108
|
const response = await api.storage.streamEntitySubset(ref.projectId, ref.projectBranch, request);
|
|
3506
4109
|
const outFile = options.out ?? "entities.dfset";
|
|
3507
4110
|
const bytes = await streamResponseToFile(response, outFile);
|
|
3508
|
-
|
|
4111
|
+
success(`Bundle written to ${outFile} (${bytes} bytes, ${entityIds.length} entity(ies)).`);
|
|
3509
4112
|
} catch (error) {
|
|
3510
4113
|
handleError(error);
|
|
3511
4114
|
}
|
|
@@ -3524,7 +4127,6 @@ function registerEntityCommands(program) {
|
|
|
3524
4127
|
}
|
|
3525
4128
|
|
|
3526
4129
|
// src/commands/link/index.ts
|
|
3527
|
-
import chalk14 from "chalk";
|
|
3528
4130
|
function getOutputFormat4(cmd) {
|
|
3529
4131
|
const config = loadConfig();
|
|
3530
4132
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -3574,7 +4176,7 @@ function registerLinkCommands(program) {
|
|
|
3574
4176
|
target.entityId,
|
|
3575
4177
|
target.entityBranch
|
|
3576
4178
|
);
|
|
3577
|
-
|
|
4179
|
+
success(`Link "${linkId}" created: ${source.entityId} \u2192 ${target.entityId}`);
|
|
3578
4180
|
} catch (error) {
|
|
3579
4181
|
handleError(error);
|
|
3580
4182
|
}
|
|
@@ -3595,7 +4197,7 @@ function registerLinkCommands(program) {
|
|
|
3595
4197
|
target.entityId,
|
|
3596
4198
|
target.entityBranch
|
|
3597
4199
|
);
|
|
3598
|
-
|
|
4200
|
+
success(`Link "${linkId}" deleted: ${source.entityId} \u2192 ${target.entityId}`);
|
|
3599
4201
|
} else {
|
|
3600
4202
|
await api.storage.deleteLink(
|
|
3601
4203
|
source.projectId,
|
|
@@ -3604,7 +4206,7 @@ function registerLinkCommands(program) {
|
|
|
3604
4206
|
source.entityBranch,
|
|
3605
4207
|
linkId
|
|
3606
4208
|
);
|
|
3607
|
-
|
|
4209
|
+
success(`All links with ID "${linkId}" from "${source.entityId}" deleted.`);
|
|
3608
4210
|
}
|
|
3609
4211
|
} catch (error) {
|
|
3610
4212
|
handleError(error);
|
|
@@ -3613,7 +4215,6 @@ function registerLinkCommands(program) {
|
|
|
3613
4215
|
}
|
|
3614
4216
|
|
|
3615
4217
|
// src/commands/event/index.ts
|
|
3616
|
-
import chalk15 from "chalk";
|
|
3617
4218
|
function getOutputFormat5(cmd) {
|
|
3618
4219
|
const config = loadConfig();
|
|
3619
4220
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -3675,7 +4276,7 @@ function registerEventCommands(program) {
|
|
|
3675
4276
|
const api = createApiClient();
|
|
3676
4277
|
const arr = Array.isArray(events) ? events : [events];
|
|
3677
4278
|
await api.storage.createEvents(arr);
|
|
3678
|
-
|
|
4279
|
+
success(`${arr.length} event(s) created.`);
|
|
3679
4280
|
} catch (error) {
|
|
3680
4281
|
handleError(error);
|
|
3681
4282
|
}
|
|
@@ -3702,7 +4303,7 @@ function registerEventCommands(program) {
|
|
|
3702
4303
|
const resolved = parseEntityReference(ref, overrides);
|
|
3703
4304
|
const api = createApiClient();
|
|
3704
4305
|
await api.storage.deleteEvent(resolved, eventId, occurrenceId);
|
|
3705
|
-
|
|
4306
|
+
success(`Event "${eventId}/${occurrenceId}" deleted.`);
|
|
3706
4307
|
} catch (error) {
|
|
3707
4308
|
handleError(error);
|
|
3708
4309
|
}
|
|
@@ -3710,7 +4311,6 @@ function registerEventCommands(program) {
|
|
|
3710
4311
|
}
|
|
3711
4312
|
|
|
3712
4313
|
// src/commands/branch/index.ts
|
|
3713
|
-
import chalk16 from "chalk";
|
|
3714
4314
|
function getOutputFormat6(cmd) {
|
|
3715
4315
|
const config = loadConfig();
|
|
3716
4316
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -3721,7 +4321,13 @@ function getOverrides5(cmd) {
|
|
|
3721
4321
|
return { project: opts.project, branch: opts.branch };
|
|
3722
4322
|
}
|
|
3723
4323
|
function registerBranchCommands(program) {
|
|
3724
|
-
const branch = program.command("branch").description("Manage branches")
|
|
4324
|
+
const branch = program.command("branch").description("Manage branches").addHelpText("after", `
|
|
4325
|
+
Examples:
|
|
4326
|
+
$ diafunc branch list <projectId>
|
|
4327
|
+
$ diafunc branch create <projectId> experiment
|
|
4328
|
+
$ diafunc branch merge --from experiment --to main --entity <id>
|
|
4329
|
+
`);
|
|
4330
|
+
;
|
|
3725
4331
|
branch.command("list").description("List branches for a project").argument("[projectId]", "Project ID (uses default if omitted)").action(async (projectId, _options, cmd) => {
|
|
3726
4332
|
try {
|
|
3727
4333
|
const outputFormat = getOutputFormat6(cmd);
|
|
@@ -3729,7 +4335,7 @@ function registerBranchCommands(program) {
|
|
|
3729
4335
|
const config = loadConfig();
|
|
3730
4336
|
const pid = projectId ?? overrides.project ?? config.defaults.project;
|
|
3731
4337
|
if (!pid) {
|
|
3732
|
-
|
|
4338
|
+
failure("No project specified. Pass a project ID or set defaults.project.");
|
|
3733
4339
|
process.exit(1);
|
|
3734
4340
|
}
|
|
3735
4341
|
const api = createApiClient();
|
|
@@ -3753,7 +4359,7 @@ function registerBranchCommands(program) {
|
|
|
3753
4359
|
sourceProjectBranch: options.source,
|
|
3754
4360
|
targetProjectBranch: branchName
|
|
3755
4361
|
});
|
|
3756
|
-
|
|
4362
|
+
success(`Branch "${branchName}" created in project "${projectId}" from "${options.source}".`);
|
|
3757
4363
|
} catch (error) {
|
|
3758
4364
|
handleError(error);
|
|
3759
4365
|
}
|
|
@@ -3762,7 +4368,7 @@ function registerBranchCommands(program) {
|
|
|
3762
4368
|
try {
|
|
3763
4369
|
const api = createApiClient();
|
|
3764
4370
|
await api.storage.deleteProjectBranch(projectId, branchName);
|
|
3765
|
-
|
|
4371
|
+
success(`Branch "${branchName}" deleted from project "${projectId}".`);
|
|
3766
4372
|
} catch (error) {
|
|
3767
4373
|
handleError(error);
|
|
3768
4374
|
}
|
|
@@ -3783,7 +4389,7 @@ function registerBranchCommands(program) {
|
|
|
3783
4389
|
linkId: options.linkId,
|
|
3784
4390
|
deepMerge: options.deep
|
|
3785
4391
|
});
|
|
3786
|
-
|
|
4392
|
+
success("Merge completed.");
|
|
3787
4393
|
} catch (error) {
|
|
3788
4394
|
handleError(error);
|
|
3789
4395
|
}
|
|
@@ -3798,7 +4404,7 @@ function registerBranchCommands(program) {
|
|
|
3798
4404
|
forkProjectName: options.name ?? forkProjectId,
|
|
3799
4405
|
forkProjectDescription: options.description
|
|
3800
4406
|
});
|
|
3801
|
-
|
|
4407
|
+
success(`Project "${projectId}" forked to "${forkProjectId}".`);
|
|
3802
4408
|
} catch (error) {
|
|
3803
4409
|
handleError(error);
|
|
3804
4410
|
}
|
|
@@ -3806,7 +4412,7 @@ function registerBranchCommands(program) {
|
|
|
3806
4412
|
}
|
|
3807
4413
|
|
|
3808
4414
|
// src/commands/table/index.ts
|
|
3809
|
-
import
|
|
4415
|
+
import chalk15 from "chalk";
|
|
3810
4416
|
import * as fs4 from "fs";
|
|
3811
4417
|
import * as path3 from "path";
|
|
3812
4418
|
function getOutputFormat7(cmd) {
|
|
@@ -3832,7 +4438,14 @@ function deriveOutFile(entityId, extension, archive, compression) {
|
|
|
3832
4438
|
return name;
|
|
3833
4439
|
}
|
|
3834
4440
|
function registerTableCommands(program) {
|
|
3835
|
-
const table = program.command("table").description("Manage tables")
|
|
4441
|
+
const table = program.command("table").description("Manage tables").addHelpText("after", `
|
|
4442
|
+
Examples:
|
|
4443
|
+
$ diafunc table view <ref> --rows 0:20 the first twenty rows
|
|
4444
|
+
$ diafunc table import <ref> data.csv load a file
|
|
4445
|
+
$ diafunc table export <ref> parquet write one out
|
|
4446
|
+
$ diafunc table import-formats what can be loaded
|
|
4447
|
+
`);
|
|
4448
|
+
;
|
|
3836
4449
|
table.command("view").description("View table data").argument("<ref>", "Table entity reference").option("--rows <range>", "Row range (e.g., 0:10)").option("--cols <range>", "Column range (e.g., 0:5)").action(async (ref, options, cmd) => {
|
|
3837
4450
|
try {
|
|
3838
4451
|
const outputFormat = getOutputFormat7(cmd);
|
|
@@ -3876,7 +4489,7 @@ function registerTableCommands(program) {
|
|
|
3876
4489
|
console.log(colNames.map((c) => row2[c] ?? "").join(" "));
|
|
3877
4490
|
}
|
|
3878
4491
|
} else {
|
|
3879
|
-
console.log(
|
|
4492
|
+
console.log(chalk15.dim(`${snapshot.rows.length} rows \xD7 ${snapshot.columns.length} columns`));
|
|
3880
4493
|
format(tableData, { format: outputFormat, columns: colNames });
|
|
3881
4494
|
}
|
|
3882
4495
|
} catch (error) {
|
|
@@ -3888,33 +4501,44 @@ function registerTableCommands(program) {
|
|
|
3888
4501
|
const overrides = getOverrides6(cmd);
|
|
3889
4502
|
const resolved = parseEntityReference(ref, overrides);
|
|
3890
4503
|
if (!fs4.existsSync(file)) {
|
|
3891
|
-
|
|
3892
|
-
process.exit(
|
|
4504
|
+
failure(`File not found: ${file}`);
|
|
4505
|
+
process.exit(EXIT_USAGE);
|
|
3893
4506
|
}
|
|
3894
4507
|
const api = createApiClient();
|
|
3895
4508
|
const fileBuffer = fs4.readFileSync(file);
|
|
3896
4509
|
const blob = new Blob([fileBuffer]);
|
|
3897
4510
|
const formData = new FormData();
|
|
3898
4511
|
formData.append("content", blob, path3.basename(file));
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
4512
|
+
const importId = await withStatus(
|
|
4513
|
+
`Uploading ${path3.basename(file)}`,
|
|
4514
|
+
() => api.storage.importTable(resolved, formData, options.selection)
|
|
4515
|
+
);
|
|
3902
4516
|
const pollInterval = 1e3;
|
|
3903
4517
|
const maxAttempts = 300;
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
4518
|
+
const status = new Status();
|
|
4519
|
+
status.start();
|
|
4520
|
+
const startedAt = Date.now();
|
|
4521
|
+
try {
|
|
4522
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
4523
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
4524
|
+
const imp = await api.storage.getImport(resolved, importId);
|
|
4525
|
+
if (imp.finished !== null) {
|
|
4526
|
+
status.stop();
|
|
4527
|
+
if (imp.succeeded) {
|
|
4528
|
+
success(`Imported in ${formatDuration(imp.duration)}.`);
|
|
4529
|
+
return;
|
|
4530
|
+
}
|
|
4531
|
+
failure(`Import failed: ${imp.error}`);
|
|
4532
|
+
process.exit(EXIT_FAILURE);
|
|
3913
4533
|
}
|
|
3914
|
-
|
|
4534
|
+
status.set([progressLine("Importing", imp.progress, Date.now() - startedAt)]);
|
|
3915
4535
|
}
|
|
4536
|
+
} finally {
|
|
4537
|
+
status.stop();
|
|
3916
4538
|
}
|
|
3917
|
-
|
|
4539
|
+
failure(`Import ${importId} is still running after ${formatDuration(pollInterval * maxAttempts)}.`);
|
|
4540
|
+
hint(`It continues on the server \u2014 re-check with 'diafunc table view ${ref}'.`);
|
|
4541
|
+
process.exit(EXIT_FAILURE);
|
|
3918
4542
|
} catch (error) {
|
|
3919
4543
|
handleError(error);
|
|
3920
4544
|
}
|
|
@@ -3934,10 +4558,22 @@ function registerTableCommands(program) {
|
|
|
3934
4558
|
category: f.category,
|
|
3935
4559
|
extensions: f.extensions.join(", "),
|
|
3936
4560
|
mimeTypes: f.mimeTypes.join(", "),
|
|
3937
|
-
multiTable: f.multiTable
|
|
3938
|
-
userDefined: f.userDefined
|
|
4561
|
+
multiTable: f.multiTable,
|
|
4562
|
+
userDefined: f.userDefined
|
|
3939
4563
|
}));
|
|
3940
|
-
format(rows, {
|
|
4564
|
+
format(rows, {
|
|
4565
|
+
format: outputFormat,
|
|
4566
|
+
columns: [
|
|
4567
|
+
{ key: "id" },
|
|
4568
|
+
{ key: "displayName", header: "name" },
|
|
4569
|
+
{ key: "category" },
|
|
4570
|
+
{ key: "extensions" },
|
|
4571
|
+
// The longest of these runs to 93 characters and would otherwise set the table width.
|
|
4572
|
+
{ key: "mimeTypes", header: "mime types", maxWidth: 40 },
|
|
4573
|
+
{ key: "multiTable", header: "multi-table", kind: "boolean" },
|
|
4574
|
+
{ key: "userDefined", header: "user-defined", kind: "boolean" }
|
|
4575
|
+
]
|
|
4576
|
+
});
|
|
3941
4577
|
} catch (error) {
|
|
3942
4578
|
handleError(error);
|
|
3943
4579
|
}
|
|
@@ -3950,15 +4586,15 @@ function registerTableCommands(program) {
|
|
|
3950
4586
|
const formats = await api.storage.getSupportedExportFormats();
|
|
3951
4587
|
const format2 = formats.formats.find((f) => f.id.toLowerCase() === fmt.toLowerCase());
|
|
3952
4588
|
if (!format2) {
|
|
3953
|
-
|
|
4589
|
+
failure(`Unknown format: "${fmt}". Run \`diafunc table export-formats\` to see the catalogue.`);
|
|
3954
4590
|
process.exit(1);
|
|
3955
4591
|
}
|
|
3956
4592
|
if (options.compression && !formats.compressionAlgorithms.includes(options.compression)) {
|
|
3957
|
-
|
|
4593
|
+
failure(`Unknown compression: "${options.compression}". Use one of ${formats.compressionAlgorithms.join(", ")}.`);
|
|
3958
4594
|
process.exit(1);
|
|
3959
4595
|
}
|
|
3960
4596
|
if (options.archive && !formats.archiveAlgorithms.includes(options.archive)) {
|
|
3961
|
-
|
|
4597
|
+
failure(`Unknown archive: "${options.archive}". Use one of ${formats.archiveAlgorithms.join(", ")}.`);
|
|
3962
4598
|
process.exit(1);
|
|
3963
4599
|
}
|
|
3964
4600
|
const exportOptions = {
|
|
@@ -3988,10 +4624,10 @@ function registerTableCommands(program) {
|
|
|
3988
4624
|
const outFile = options.out ?? deriveOutFile(resolved.entityId, format2.extension, options.archive, options.compression);
|
|
3989
4625
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
3990
4626
|
fs4.writeFileSync(outFile, buffer);
|
|
3991
|
-
|
|
4627
|
+
success(`Table streamed to ${outFile}`);
|
|
3992
4628
|
} else {
|
|
3993
4629
|
const exportId = await api.storage.exportTable(resolved, format2.id, exportOptions);
|
|
3994
|
-
|
|
4630
|
+
success(`Export queued (ID: ${exportId}).`);
|
|
3995
4631
|
console.log(`Poll progress: diafunc table exports get ${exportId} --ref ${ref}`);
|
|
3996
4632
|
}
|
|
3997
4633
|
} catch (error) {
|
|
@@ -4016,8 +4652,8 @@ function registerTableCommands(program) {
|
|
|
4016
4652
|
knownLimitations: f.knownLimitations.join(" / ")
|
|
4017
4653
|
}));
|
|
4018
4654
|
format(rows, { format: outputFormat, columns: ["id", "displayName", "category", "extension", "mimeType", "knownLimitations"] });
|
|
4019
|
-
console.log(
|
|
4020
|
-
console.log(
|
|
4655
|
+
console.log(chalk15.dim(`Compression: ${response.compressionAlgorithms.join(", ")}`));
|
|
4656
|
+
console.log(chalk15.dim(`Archive: ${response.archiveAlgorithms.join(", ")}`));
|
|
4021
4657
|
} catch (error) {
|
|
4022
4658
|
handleError(error);
|
|
4023
4659
|
}
|
|
@@ -4035,7 +4671,7 @@ function registerTableCommands(program) {
|
|
|
4035
4671
|
return;
|
|
4036
4672
|
}
|
|
4037
4673
|
if (exports.length === 0) {
|
|
4038
|
-
|
|
4674
|
+
empty("exports found");
|
|
4039
4675
|
return;
|
|
4040
4676
|
}
|
|
4041
4677
|
const rows = exports.map((e) => ({
|
|
@@ -4060,7 +4696,7 @@ function registerTableCommands(program) {
|
|
|
4060
4696
|
const exports = await api.storage.listExports(resolved);
|
|
4061
4697
|
const exp = exports.find((e) => e.exportId === exportId);
|
|
4062
4698
|
if (!exp) {
|
|
4063
|
-
|
|
4699
|
+
failure(`Export ${exportId} not found for ref ${options.ref}.`);
|
|
4064
4700
|
process.exit(1);
|
|
4065
4701
|
}
|
|
4066
4702
|
if (outputFormat === "json") {
|
|
@@ -4069,11 +4705,11 @@ function registerTableCommands(program) {
|
|
|
4069
4705
|
}
|
|
4070
4706
|
if (exp.finished === null) {
|
|
4071
4707
|
const pct = Math.round((exp.progress ?? 0) * 100);
|
|
4072
|
-
console.log(
|
|
4708
|
+
console.log(chalk15.dim(`Export in progress: ${pct}% \u2014 check again later.`));
|
|
4073
4709
|
return;
|
|
4074
4710
|
}
|
|
4075
4711
|
if (!exp.succeeded) {
|
|
4076
|
-
|
|
4712
|
+
failure(`Export failed: ${exp.error}`);
|
|
4077
4713
|
process.exit(1);
|
|
4078
4714
|
}
|
|
4079
4715
|
const outFile = options.out ?? exp.filename;
|
|
@@ -4081,7 +4717,7 @@ function registerTableCommands(program) {
|
|
|
4081
4717
|
const response = await api.storage.downloadExport(resolved, exportId, exp.filename);
|
|
4082
4718
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
4083
4719
|
fs4.writeFileSync(outFile, buffer);
|
|
4084
|
-
|
|
4720
|
+
success(`Export saved to ${outFile}`);
|
|
4085
4721
|
} catch (error) {
|
|
4086
4722
|
handleError(error);
|
|
4087
4723
|
}
|
|
@@ -4093,7 +4729,7 @@ function registerTableCommands(program) {
|
|
|
4093
4729
|
const resolved = parseEntityReference(ref, overrides);
|
|
4094
4730
|
const api = createApiClient();
|
|
4095
4731
|
await api.storage.appendRow(resolved);
|
|
4096
|
-
|
|
4732
|
+
success("Row appended.");
|
|
4097
4733
|
} catch (error) {
|
|
4098
4734
|
handleError(error);
|
|
4099
4735
|
}
|
|
@@ -4104,7 +4740,7 @@ function registerTableCommands(program) {
|
|
|
4104
4740
|
const resolved = parseEntityReference(ref, overrides);
|
|
4105
4741
|
const api = createApiClient();
|
|
4106
4742
|
await api.storage.insertRow(resolved, parseInt(index, 10));
|
|
4107
|
-
|
|
4743
|
+
success(`Row inserted at index ${index}.`);
|
|
4108
4744
|
} catch (error) {
|
|
4109
4745
|
handleError(error);
|
|
4110
4746
|
}
|
|
@@ -4115,7 +4751,7 @@ function registerTableCommands(program) {
|
|
|
4115
4751
|
const resolved = parseEntityReference(ref, overrides);
|
|
4116
4752
|
const api = createApiClient();
|
|
4117
4753
|
await api.storage.removeRow(resolved, parseInt(index, 10));
|
|
4118
|
-
|
|
4754
|
+
success(`Row ${index} removed.`);
|
|
4119
4755
|
} catch (error) {
|
|
4120
4756
|
handleError(error);
|
|
4121
4757
|
}
|
|
@@ -4126,7 +4762,7 @@ function registerTableCommands(program) {
|
|
|
4126
4762
|
const resolved = parseEntityReference(ref, overrides);
|
|
4127
4763
|
const api = createApiClient();
|
|
4128
4764
|
await api.storage.deleteRow(resolved, parseInt(index, 10));
|
|
4129
|
-
|
|
4765
|
+
success(`Row ${index} deleted.`);
|
|
4130
4766
|
} catch (error) {
|
|
4131
4767
|
handleError(error);
|
|
4132
4768
|
}
|
|
@@ -4138,7 +4774,7 @@ function registerTableCommands(program) {
|
|
|
4138
4774
|
const resolved = parseEntityReference(ref, overrides);
|
|
4139
4775
|
const api = createApiClient();
|
|
4140
4776
|
await api.storage.appendColumn(resolved);
|
|
4141
|
-
|
|
4777
|
+
success("Column appended.");
|
|
4142
4778
|
} catch (error) {
|
|
4143
4779
|
handleError(error);
|
|
4144
4780
|
}
|
|
@@ -4149,7 +4785,7 @@ function registerTableCommands(program) {
|
|
|
4149
4785
|
const resolved = parseEntityReference(ref, overrides);
|
|
4150
4786
|
const api = createApiClient();
|
|
4151
4787
|
await api.storage.insertColumn(resolved, parseInt(index, 10));
|
|
4152
|
-
|
|
4788
|
+
success(`Column inserted at index ${index}.`);
|
|
4153
4789
|
} catch (error) {
|
|
4154
4790
|
handleError(error);
|
|
4155
4791
|
}
|
|
@@ -4160,7 +4796,7 @@ function registerTableCommands(program) {
|
|
|
4160
4796
|
const resolved = parseEntityReference(ref, overrides);
|
|
4161
4797
|
const api = createApiClient();
|
|
4162
4798
|
await api.storage.removeColumn(resolved, parseInt(index, 10));
|
|
4163
|
-
|
|
4799
|
+
success(`Column ${index} removed.`);
|
|
4164
4800
|
} catch (error) {
|
|
4165
4801
|
handleError(error);
|
|
4166
4802
|
}
|
|
@@ -4171,7 +4807,7 @@ function registerTableCommands(program) {
|
|
|
4171
4807
|
const resolved = parseEntityReference(ref, overrides);
|
|
4172
4808
|
const api = createApiClient();
|
|
4173
4809
|
await api.storage.deleteColumn(resolved, parseInt(index, 10));
|
|
4174
|
-
|
|
4810
|
+
success(`Column ${index} deleted.`);
|
|
4175
4811
|
} catch (error) {
|
|
4176
4812
|
handleError(error);
|
|
4177
4813
|
}
|
|
@@ -4188,7 +4824,7 @@ function registerTableCommands(program) {
|
|
|
4188
4824
|
value,
|
|
4189
4825
|
type: "text"
|
|
4190
4826
|
}]);
|
|
4191
|
-
|
|
4827
|
+
success(`Cell [${row2}, ${col}] set to "${value}".`);
|
|
4192
4828
|
} catch (error) {
|
|
4193
4829
|
handleError(error);
|
|
4194
4830
|
}
|
|
@@ -4199,7 +4835,7 @@ function registerTableCommands(program) {
|
|
|
4199
4835
|
const resolved = parseEntityReference(ref, overrides);
|
|
4200
4836
|
const api = createApiClient();
|
|
4201
4837
|
await api.storage.removeCell(resolved, parseInt(row2, 10), parseInt(col, 10));
|
|
4202
|
-
|
|
4838
|
+
success(`Cell [${row2}, ${col}] deleted.`);
|
|
4203
4839
|
} catch (error) {
|
|
4204
4840
|
handleError(error);
|
|
4205
4841
|
}
|
|
@@ -4211,7 +4847,7 @@ function registerTableCommands(program) {
|
|
|
4211
4847
|
const resolved = parseEntityReference(ref, overrides);
|
|
4212
4848
|
const api = createApiClient();
|
|
4213
4849
|
await api.storage.clearTable(resolved);
|
|
4214
|
-
|
|
4850
|
+
success("Table cleared.");
|
|
4215
4851
|
} catch (error) {
|
|
4216
4852
|
handleError(error);
|
|
4217
4853
|
}
|
|
@@ -4219,7 +4855,7 @@ function registerTableCommands(program) {
|
|
|
4219
4855
|
}
|
|
4220
4856
|
|
|
4221
4857
|
// src/commands/notebook/index.ts
|
|
4222
|
-
import
|
|
4858
|
+
import chalk16 from "chalk";
|
|
4223
4859
|
import * as fs5 from "fs";
|
|
4224
4860
|
import * as path4 from "path";
|
|
4225
4861
|
function getOutputFormat8(cmd) {
|
|
@@ -4232,7 +4868,13 @@ function getOverrides7(cmd) {
|
|
|
4232
4868
|
return { project: opts.project, branch: opts.branch };
|
|
4233
4869
|
}
|
|
4234
4870
|
function registerNotebookCommands(program) {
|
|
4235
|
-
const notebook = program.command("notebook").description("Export and import notebook bundles")
|
|
4871
|
+
const notebook = program.command("notebook").description("Export and import notebook bundles").addHelpText("after", `
|
|
4872
|
+
Examples:
|
|
4873
|
+
$ diafunc notebook export <project> <notebookId> -o notebook.dfnb
|
|
4874
|
+
$ diafunc notebook import <project> notebook.dfnb --preview
|
|
4875
|
+
$ diafunc notebook import <project> notebook.dfnb
|
|
4876
|
+
`);
|
|
4877
|
+
;
|
|
4236
4878
|
notebook.command("export").description("Export one or more notebooks (plus their closure) to a .dfnb bundle").argument("<project>", "Project reference (projectId or projectId/branch)").argument("<notebookIds...>", "Entity id(s) of the notebook(s) to export").option("--out <file>", "Output file (defaults to notebooks.dfnb)").option("--data <encoding>", "Embedded table-data encoding: csv (default) or parquet", "csv").option("--async", "Queue a background job instead of streaming the download now").action(async (project, notebookIds, options, cmd) => {
|
|
4237
4879
|
try {
|
|
4238
4880
|
const overrides = getOverrides7(cmd);
|
|
@@ -4241,7 +4883,7 @@ function registerNotebookCommands(program) {
|
|
|
4241
4883
|
const request = { rootEntityIds: notebookIds, dataFormat: options.data };
|
|
4242
4884
|
if (options.async) {
|
|
4243
4885
|
const bundleId = await api.storage.exportBundle(ref.projectId, ref.projectBranch, request);
|
|
4244
|
-
|
|
4886
|
+
success(`Export queued (bundle ID: ${bundleId}).`);
|
|
4245
4887
|
console.log(`Poll progress: diafunc notebook bundles ${project}`);
|
|
4246
4888
|
return;
|
|
4247
4889
|
}
|
|
@@ -4249,7 +4891,7 @@ function registerNotebookCommands(program) {
|
|
|
4249
4891
|
const outFile = options.out ?? "notebooks.dfnb";
|
|
4250
4892
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
4251
4893
|
fs5.writeFileSync(outFile, buffer);
|
|
4252
|
-
|
|
4894
|
+
success(`Bundle written to ${outFile} (${buffer.length} bytes, ${notebookIds.length} notebook(s)).`);
|
|
4253
4895
|
} catch (error) {
|
|
4254
4896
|
handleError(error);
|
|
4255
4897
|
}
|
|
@@ -4270,9 +4912,9 @@ function registerNotebookCommands(program) {
|
|
|
4270
4912
|
format(preview, { format: outputFormat });
|
|
4271
4913
|
return;
|
|
4272
4914
|
}
|
|
4273
|
-
console.log(
|
|
4915
|
+
console.log(chalk16.bold(`${preview.kind} bundle \xB7 ${preview.entityCount} entities`));
|
|
4274
4916
|
if (preview.sourceProjectId) {
|
|
4275
|
-
console.log(
|
|
4917
|
+
console.log(chalk16.dim(`from ${preview.sourceProjectId}/${preview.sourceProjectBranch}` + (preview.createdBy ? ` \xB7 by ${preview.createdBy}` : "")));
|
|
4276
4918
|
}
|
|
4277
4919
|
const counts = /* @__PURE__ */ new Map();
|
|
4278
4920
|
for (const e of preview.entities ?? []) {
|
|
@@ -4282,9 +4924,9 @@ function registerNotebookCommands(program) {
|
|
|
4282
4924
|
console.log(` ${type}: ${count}`);
|
|
4283
4925
|
}
|
|
4284
4926
|
if (preview.lossinessNotes && preview.lossinessNotes.length > 0) {
|
|
4285
|
-
console.log(
|
|
4927
|
+
console.log(chalk16.yellow("Lossiness:"));
|
|
4286
4928
|
for (const note of preview.lossinessNotes) {
|
|
4287
|
-
console.log(
|
|
4929
|
+
console.log(chalk16.yellow(` - ${note}`));
|
|
4288
4930
|
}
|
|
4289
4931
|
}
|
|
4290
4932
|
return;
|
|
@@ -4294,7 +4936,7 @@ function registerNotebookCommands(program) {
|
|
|
4294
4936
|
format(result, { format: outputFormat });
|
|
4295
4937
|
return;
|
|
4296
4938
|
}
|
|
4297
|
-
|
|
4939
|
+
success(`Imported ${result.entityCount} entities, ${result.linkCount} links.`);
|
|
4298
4940
|
console.log(`Notebook id(s): ${result.rootEntityIds.join(", ")}`);
|
|
4299
4941
|
} catch (error) {
|
|
4300
4942
|
handleError(error);
|
|
@@ -4331,13 +4973,56 @@ function registerNotebookCommands(program) {
|
|
|
4331
4973
|
}
|
|
4332
4974
|
|
|
4333
4975
|
// src/commands/function/index.ts
|
|
4334
|
-
import
|
|
4976
|
+
import chalk17 from "chalk";
|
|
4335
4977
|
import * as fs6 from "fs";
|
|
4336
4978
|
import * as os2 from "os";
|
|
4337
4979
|
import * as path5 from "path";
|
|
4338
4980
|
import { spawn } from "child_process";
|
|
4339
4981
|
import { randomUUID } from "crypto";
|
|
4340
4982
|
|
|
4983
|
+
// src/util/time-uuid.ts
|
|
4984
|
+
import { randomBytes } from "crypto";
|
|
4985
|
+
var GREGORIAN_OFFSET = 122192928000000000n;
|
|
4986
|
+
var INTERVALS_PER_MILLI = 10000n;
|
|
4987
|
+
function createTimeUuidGenerator() {
|
|
4988
|
+
const node = randomBytes(6);
|
|
4989
|
+
node[0] |= 1;
|
|
4990
|
+
const nodeHex = node.toString("hex");
|
|
4991
|
+
let clockSequence = randomBytes(2).readUInt16BE(0) & 16383;
|
|
4992
|
+
let lastTimestamp = 0n;
|
|
4993
|
+
let intervalsWithinMilli = 0n;
|
|
4994
|
+
return function generate(now = Date.now()) {
|
|
4995
|
+
let timestamp = BigInt(now) * 10000n + GREGORIAN_OFFSET;
|
|
4996
|
+
if (timestamp !== lastTimestamp) {
|
|
4997
|
+
lastTimestamp = timestamp;
|
|
4998
|
+
intervalsWithinMilli = 0n;
|
|
4999
|
+
} else {
|
|
5000
|
+
intervalsWithinMilli += 1n;
|
|
5001
|
+
if (intervalsWithinMilli >= INTERVALS_PER_MILLI) {
|
|
5002
|
+
clockSequence = clockSequence + 1 & 16383;
|
|
5003
|
+
intervalsWithinMilli = 0n;
|
|
5004
|
+
}
|
|
5005
|
+
timestamp = lastTimestamp + intervalsWithinMilli;
|
|
5006
|
+
}
|
|
5007
|
+
const timeLow = Number(timestamp & 0xffffffffn);
|
|
5008
|
+
const timeMid = Number(timestamp >> 32n & 0xffffn);
|
|
5009
|
+
const timeHiAndVersion = Number(timestamp >> 48n & 0x0fffn) | 4096;
|
|
5010
|
+
const clockSeqHi = clockSequence >> 8 & 63 | 128;
|
|
5011
|
+
const clockSeqLow = clockSequence & 255;
|
|
5012
|
+
return [
|
|
5013
|
+
hex(timeLow, 8),
|
|
5014
|
+
hex(timeMid, 4),
|
|
5015
|
+
hex(timeHiAndVersion, 4),
|
|
5016
|
+
hex(clockSeqHi, 2) + hex(clockSeqLow, 2),
|
|
5017
|
+
nodeHex
|
|
5018
|
+
].join("-");
|
|
5019
|
+
};
|
|
5020
|
+
}
|
|
5021
|
+
var timeUuid = createTimeUuidGenerator();
|
|
5022
|
+
function hex(value, width) {
|
|
5023
|
+
return value.toString(16).padStart(width, "0");
|
|
5024
|
+
}
|
|
5025
|
+
|
|
4341
5026
|
// src/util/function-content.ts
|
|
4342
5027
|
function decodeFunctionSource(entity) {
|
|
4343
5028
|
if (!entity.content) return "";
|
|
@@ -4403,7 +5088,7 @@ function getOverrides8(cmd) {
|
|
|
4403
5088
|
function createTimeUuid() {
|
|
4404
5089
|
const now = /* @__PURE__ */ new Date();
|
|
4405
5090
|
return {
|
|
4406
|
-
evaluationId:
|
|
5091
|
+
evaluationId: timeUuid(now.getTime()),
|
|
4407
5092
|
year: now.getUTCFullYear(),
|
|
4408
5093
|
month: now.getUTCMonth() + 1,
|
|
4409
5094
|
day: now.getUTCDate(),
|
|
@@ -4411,7 +5096,14 @@ function createTimeUuid() {
|
|
|
4411
5096
|
};
|
|
4412
5097
|
}
|
|
4413
5098
|
function registerFunctionCommands(program) {
|
|
4414
|
-
const fn = program.command("function").description("Execute and manage functions")
|
|
5099
|
+
const fn = program.command("function").description("Execute and manage functions").addHelpText("after", `
|
|
5100
|
+
Examples:
|
|
5101
|
+
$ diafunc function call <ref> --args '{"x": 1}' run one
|
|
5102
|
+
$ diafunc function edit <ref> edit the source in $EDITOR
|
|
5103
|
+
$ diafunc function logs <ref> what the last run printed
|
|
5104
|
+
$ diafunc function languages what it can be written in
|
|
5105
|
+
`);
|
|
5106
|
+
;
|
|
4415
5107
|
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) => {
|
|
4416
5108
|
try {
|
|
4417
5109
|
const outputFormat = getOutputFormat9(cmd);
|
|
@@ -4457,7 +5149,7 @@ function registerFunctionCommands(program) {
|
|
|
4457
5149
|
}, isAsync);
|
|
4458
5150
|
if (isAsync) {
|
|
4459
5151
|
if (outputFormat === "human") {
|
|
4460
|
-
|
|
5152
|
+
success("Function launched.");
|
|
4461
5153
|
console.log(` Evaluation ID: ${result.evaluationId}`);
|
|
4462
5154
|
} else {
|
|
4463
5155
|
format({ evaluationId: result.evaluationId }, { format: outputFormat });
|
|
@@ -4465,14 +5157,14 @@ function registerFunctionCommands(program) {
|
|
|
4465
5157
|
} else {
|
|
4466
5158
|
if (outputFormat === "human") {
|
|
4467
5159
|
if (result.successful) {
|
|
4468
|
-
|
|
5160
|
+
success("Function completed successfully.");
|
|
4469
5161
|
if (result.result) {
|
|
4470
5162
|
console.log(` Result: ${result.result}`);
|
|
4471
5163
|
}
|
|
4472
5164
|
const duration = result.completed - result.started;
|
|
4473
5165
|
console.log(` Duration: ${duration}ms`);
|
|
4474
5166
|
} else {
|
|
4475
|
-
console.log(
|
|
5167
|
+
console.log(chalk17.red("Function failed."));
|
|
4476
5168
|
console.log(` Error: ${result.error}`);
|
|
4477
5169
|
if (result.lineNumber > 0) {
|
|
4478
5170
|
console.log(` Line: ${result.lineNumber}, Column: ${result.columnNumber}`);
|
|
@@ -4480,7 +5172,7 @@ function registerFunctionCommands(program) {
|
|
|
4480
5172
|
}
|
|
4481
5173
|
if (result.outputs?.length) {
|
|
4482
5174
|
console.log();
|
|
4483
|
-
console.log(
|
|
5175
|
+
console.log(chalk17.bold("Outputs:"));
|
|
4484
5176
|
for (const out of result.outputs) {
|
|
4485
5177
|
console.log(` [${out.type}] ${out.output}`);
|
|
4486
5178
|
}
|
|
@@ -4521,7 +5213,14 @@ function registerFunctionCommands(program) {
|
|
|
4521
5213
|
}));
|
|
4522
5214
|
format(summary, {
|
|
4523
5215
|
format: outputFormat,
|
|
4524
|
-
columns: [
|
|
5216
|
+
columns: [
|
|
5217
|
+
{ key: "evaluationId", kind: "id" },
|
|
5218
|
+
{ key: "active", kind: "boolean" },
|
|
5219
|
+
{ key: "successful", kind: "boolean" },
|
|
5220
|
+
{ key: "language" },
|
|
5221
|
+
{ key: "started", kind: "date" },
|
|
5222
|
+
{ key: "duration", kind: "number" }
|
|
5223
|
+
]
|
|
4525
5224
|
});
|
|
4526
5225
|
} catch (error) {
|
|
4527
5226
|
handleError(error);
|
|
@@ -4534,11 +5233,11 @@ function registerFunctionCommands(program) {
|
|
|
4534
5233
|
const outputs = await api.evaluation.getOutputs(projectId, evaluationId);
|
|
4535
5234
|
if (outputFormat === "human") {
|
|
4536
5235
|
if (outputs.length === 0) {
|
|
4537
|
-
|
|
5236
|
+
empty("outputs");
|
|
4538
5237
|
}
|
|
4539
5238
|
for (const out of outputs) {
|
|
4540
5239
|
const time = new Date(out.timestamp).toISOString();
|
|
4541
|
-
console.log(`${
|
|
5240
|
+
console.log(`${chalk17.dim(time)} [${out.type}] ${out.output}`);
|
|
4542
5241
|
}
|
|
4543
5242
|
} else {
|
|
4544
5243
|
format(outputs, { format: outputFormat });
|
|
@@ -4588,17 +5287,21 @@ function registerFunctionCommands(program) {
|
|
|
4588
5287
|
hour,
|
|
4589
5288
|
evaluationId
|
|
4590
5289
|
);
|
|
4591
|
-
|
|
5290
|
+
success(`Evaluation ${evaluationId} stopped.`);
|
|
4592
5291
|
} catch (error) {
|
|
4593
5292
|
handleError(error);
|
|
4594
5293
|
}
|
|
4595
5294
|
});
|
|
4596
|
-
fn.command("
|
|
5295
|
+
fn.command("languages").description("List the languages a function can be written in").action(async (_options, cmd) => {
|
|
4597
5296
|
try {
|
|
4598
5297
|
const outputFormat = getOutputFormat9(cmd);
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
5298
|
+
format(
|
|
5299
|
+
FUNCTION_LANGUAGES.map((language) => ({
|
|
5300
|
+
language,
|
|
5301
|
+
default: language === DEFAULT_FUNCTION_LANGUAGE
|
|
5302
|
+
})),
|
|
5303
|
+
{ format: outputFormat, columns: [{ key: "language" }, { key: "default", kind: "boolean" }] }
|
|
5304
|
+
);
|
|
4602
5305
|
} catch (error) {
|
|
4603
5306
|
handleError(error);
|
|
4604
5307
|
}
|
|
@@ -4637,7 +5340,7 @@ function registerFunctionCommands(program) {
|
|
|
4637
5340
|
});
|
|
4638
5341
|
await api.storage.saveEntities([entity]);
|
|
4639
5342
|
const effective = options.language ? options.language : `${await resolveLanguage(api, resolved.projectId)}, the project's language`;
|
|
4640
|
-
|
|
5343
|
+
success(`Function "${resolved.entityId}" created (${effective}).`);
|
|
4641
5344
|
} catch (error) {
|
|
4642
5345
|
handleError(error);
|
|
4643
5346
|
}
|
|
@@ -4652,7 +5355,7 @@ function registerFunctionCommands(program) {
|
|
|
4652
5355
|
const sourceCode = decodeFunctionSource(entity);
|
|
4653
5356
|
if (options.out) {
|
|
4654
5357
|
fs6.writeFileSync(options.out, sourceCode);
|
|
4655
|
-
|
|
5358
|
+
success(`Source written to ${options.out}`);
|
|
4656
5359
|
} else {
|
|
4657
5360
|
process.stdout.write(sourceCode);
|
|
4658
5361
|
if (!sourceCode.endsWith("\n")) process.stdout.write("\n");
|
|
@@ -4676,7 +5379,7 @@ function registerFunctionCommands(program) {
|
|
|
4676
5379
|
process.stdin.on("error", reject);
|
|
4677
5380
|
});
|
|
4678
5381
|
await api.storage.saveEntityContentBase64(resolved, encodeFunctionSource(sourceCode));
|
|
4679
|
-
|
|
5382
|
+
success(`Source updated for "${resolved.entityId}".`);
|
|
4680
5383
|
} catch (error) {
|
|
4681
5384
|
handleError(error);
|
|
4682
5385
|
}
|
|
@@ -4701,11 +5404,11 @@ function registerFunctionCommands(program) {
|
|
|
4701
5404
|
const newSource = fs6.readFileSync(tmpFile, "utf-8");
|
|
4702
5405
|
fs6.unlinkSync(tmpFile);
|
|
4703
5406
|
if (newSource === currentSource) {
|
|
4704
|
-
|
|
5407
|
+
empty("changes");
|
|
4705
5408
|
return;
|
|
4706
5409
|
}
|
|
4707
5410
|
await api.storage.saveEntityContentBase64(resolved, encodeFunctionSource(newSource));
|
|
4708
|
-
|
|
5411
|
+
success(`Source updated for "${resolved.entityId}".`);
|
|
4709
5412
|
} catch (error) {
|
|
4710
5413
|
handleError(error);
|
|
4711
5414
|
}
|
|
@@ -4722,7 +5425,6 @@ function extensionFor(language) {
|
|
|
4722
5425
|
}
|
|
4723
5426
|
|
|
4724
5427
|
// src/commands/trigger/index.ts
|
|
4725
|
-
import chalk20 from "chalk";
|
|
4726
5428
|
function getOutputFormat10(cmd) {
|
|
4727
5429
|
const config = loadConfig();
|
|
4728
5430
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -4733,7 +5435,13 @@ function getOverrides9(cmd) {
|
|
|
4733
5435
|
return { project: opts.project, branch: opts.branch };
|
|
4734
5436
|
}
|
|
4735
5437
|
function registerTriggerCommands(program) {
|
|
4736
|
-
const trigger = program.command("trigger").description("Manage function triggers")
|
|
5438
|
+
const trigger = program.command("trigger").description("Manage function triggers").addHelpText("after", `
|
|
5439
|
+
Examples:
|
|
5440
|
+
$ diafunc trigger list <ref>
|
|
5441
|
+
$ diafunc trigger create <ref> --expression '0 0 * * *'
|
|
5442
|
+
$ diafunc trigger delete <ref> <triggerId>
|
|
5443
|
+
`);
|
|
5444
|
+
;
|
|
4737
5445
|
trigger.command("list").description("List triggers for a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
4738
5446
|
try {
|
|
4739
5447
|
const outputFormat = getOutputFormat10(cmd);
|
|
@@ -4792,7 +5500,7 @@ function registerTriggerCommands(program) {
|
|
|
4792
5500
|
resolved.entityBranch,
|
|
4793
5501
|
triggerId
|
|
4794
5502
|
);
|
|
4795
|
-
|
|
5503
|
+
success(`Trigger "${triggerId}" deleted.`);
|
|
4796
5504
|
} catch (error) {
|
|
4797
5505
|
handleError(error);
|
|
4798
5506
|
}
|
|
@@ -4840,7 +5548,7 @@ function registerTriggerCommands(program) {
|
|
|
4840
5548
|
scheduler: null,
|
|
4841
5549
|
heartbeat: null
|
|
4842
5550
|
});
|
|
4843
|
-
|
|
5551
|
+
success("Trigger saved.");
|
|
4844
5552
|
} catch (error) {
|
|
4845
5553
|
handleError(error);
|
|
4846
5554
|
}
|
|
@@ -4848,8 +5556,6 @@ function registerTriggerCommands(program) {
|
|
|
4848
5556
|
}
|
|
4849
5557
|
|
|
4850
5558
|
// src/commands/schedule/index.ts
|
|
4851
|
-
import chalk21 from "chalk";
|
|
4852
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
4853
5559
|
function getOutputFormat11(cmd) {
|
|
4854
5560
|
const config = loadConfig();
|
|
4855
5561
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -4886,7 +5592,7 @@ function registerScheduleCommands(program) {
|
|
|
4886
5592
|
targetEntityBranch = targetRef.entityBranch;
|
|
4887
5593
|
}
|
|
4888
5594
|
const result = await api.scheduler.scheduleCall({
|
|
4889
|
-
evaluationId:
|
|
5595
|
+
evaluationId: timeUuid(),
|
|
4890
5596
|
projectId: resolved.projectId,
|
|
4891
5597
|
projectBranch: resolved.projectBranch,
|
|
4892
5598
|
functionId: resolved.entityId,
|
|
@@ -4900,7 +5606,7 @@ function registerScheduleCommands(program) {
|
|
|
4900
5606
|
removeFunction: false
|
|
4901
5607
|
});
|
|
4902
5608
|
if (outputFormat === "human") {
|
|
4903
|
-
|
|
5609
|
+
success("Function scheduled.");
|
|
4904
5610
|
} else {
|
|
4905
5611
|
format(result, { format: outputFormat });
|
|
4906
5612
|
}
|
|
@@ -4925,7 +5631,7 @@ function registerScheduleCommands(program) {
|
|
|
4925
5631
|
hour,
|
|
4926
5632
|
evaluationId
|
|
4927
5633
|
);
|
|
4928
|
-
|
|
5634
|
+
success(`Scheduled evaluation ${evaluationId} stopped.`);
|
|
4929
5635
|
} catch (error) {
|
|
4930
5636
|
handleError(error);
|
|
4931
5637
|
}
|
|
@@ -4962,71 +5668,202 @@ function registerScheduleCommands(program) {
|
|
|
4962
5668
|
}
|
|
4963
5669
|
|
|
4964
5670
|
// src/commands/chat/index.ts
|
|
4965
|
-
import
|
|
5671
|
+
import chalk19 from "chalk";
|
|
4966
5672
|
import * as fs7 from "fs";
|
|
4967
5673
|
import * as path6 from "path";
|
|
5674
|
+
|
|
5675
|
+
// src/output/markdown.ts
|
|
5676
|
+
import chalk18 from "chalk";
|
|
5677
|
+
var CODE_OPEN = "\0c";
|
|
5678
|
+
var CODE_CLOSE = "\0";
|
|
5679
|
+
var MarkdownRenderer = class {
|
|
5680
|
+
constructor(width = terminalWidth()) {
|
|
5681
|
+
this.width = width;
|
|
5682
|
+
}
|
|
5683
|
+
width;
|
|
5684
|
+
inFence = false;
|
|
5685
|
+
pending = "";
|
|
5686
|
+
/** Renders whatever complete lines `chunk` completes. The remainder is held for the next call. */
|
|
5687
|
+
push(chunk) {
|
|
5688
|
+
if (!isInteractive()) return this.pushPlain(chunk);
|
|
5689
|
+
this.pending += chunk;
|
|
5690
|
+
const parts = this.pending.split("\n");
|
|
5691
|
+
this.pending = parts.pop() ?? "";
|
|
5692
|
+
return parts.flatMap((line) => this.line(line));
|
|
5693
|
+
}
|
|
5694
|
+
/** Renders the held remainder, if any. Call once the stream has ended. */
|
|
5695
|
+
flush() {
|
|
5696
|
+
if (this.pending === "") return [];
|
|
5697
|
+
const rest = this.pending;
|
|
5698
|
+
this.pending = "";
|
|
5699
|
+
return isInteractive() ? this.line(rest) : [rest];
|
|
5700
|
+
}
|
|
5701
|
+
pushPlain(chunk) {
|
|
5702
|
+
this.pending += chunk;
|
|
5703
|
+
const parts = this.pending.split("\n");
|
|
5704
|
+
this.pending = parts.pop() ?? "";
|
|
5705
|
+
return parts;
|
|
5706
|
+
}
|
|
5707
|
+
line(line) {
|
|
5708
|
+
const fence = line.match(/^\s*```(\w*)\s*$/);
|
|
5709
|
+
if (fence) {
|
|
5710
|
+
const opening = !this.inFence;
|
|
5711
|
+
this.inFence = !this.inFence;
|
|
5712
|
+
return opening && fence[1] ? [chalk18.dim(` ${fence[1]}`)] : [];
|
|
5713
|
+
}
|
|
5714
|
+
if (this.inFence) {
|
|
5715
|
+
return [chalk18.cyan(` ${line}`)];
|
|
5716
|
+
}
|
|
5717
|
+
const heading = line.match(/^(#{1,6})\s+(.*)$/);
|
|
5718
|
+
if (heading) {
|
|
5719
|
+
const text = inline(heading[2]);
|
|
5720
|
+
return ["", heading[1].length <= 2 ? chalk18.bold.underline(text) : chalk18.bold(text)];
|
|
5721
|
+
}
|
|
5722
|
+
if (/^\s*([-*_])\1{2,}\s*$/.test(line)) {
|
|
5723
|
+
return [chalk18.dim("\u2500".repeat(Math.min(this.width, 60)))];
|
|
5724
|
+
}
|
|
5725
|
+
const quote = line.match(/^\s*>\s?(.*)$/);
|
|
5726
|
+
if (quote) return [chalk18.dim(` \u2502 ${inline(quote[1])}`)];
|
|
5727
|
+
const bullet = line.match(/^(\s*)[-*+]\s+(.*)$/);
|
|
5728
|
+
if (bullet) {
|
|
5729
|
+
return wrapWithIndent(
|
|
5730
|
+
`${bullet[1]}${chalk18.cyan("\u2022")} ${inline(bullet[2])}`,
|
|
5731
|
+
bullet[1].length + 2,
|
|
5732
|
+
this.width
|
|
5733
|
+
);
|
|
5734
|
+
}
|
|
5735
|
+
const numbered = line.match(/^(\s*)(\d+)\.\s+(.*)$/);
|
|
5736
|
+
if (numbered) {
|
|
5737
|
+
return wrapWithIndent(
|
|
5738
|
+
`${numbered[1]}${chalk18.cyan(`${numbered[2]}.`)} ${inline(numbered[3])}`,
|
|
5739
|
+
numbered[1].length + numbered[2].length + 2,
|
|
5740
|
+
this.width
|
|
5741
|
+
);
|
|
5742
|
+
}
|
|
5743
|
+
if (line.trim() === "") return [""];
|
|
5744
|
+
return wrapWithIndent(inline(line), 0, this.width);
|
|
5745
|
+
}
|
|
5746
|
+
};
|
|
5747
|
+
function renderMarkdown(source, width = terminalWidth()) {
|
|
5748
|
+
if (!isInteractive()) return source;
|
|
5749
|
+
const renderer = new MarkdownRenderer(width);
|
|
5750
|
+
return [...renderer.push(source), ...renderer.flush()].join("\n");
|
|
5751
|
+
}
|
|
5752
|
+
function wrapWithIndent(text, indent, width) {
|
|
5753
|
+
return wrap(text, width).map((l, i) => i === 0 ? l : " ".repeat(indent) + l);
|
|
5754
|
+
}
|
|
5755
|
+
function inline(text) {
|
|
5756
|
+
const codeSpans = [];
|
|
5757
|
+
let working = text.replace(/`([^`]+)`/g, (_m, code) => {
|
|
5758
|
+
codeSpans.push(code);
|
|
5759
|
+
return `${CODE_OPEN}${codeSpans.length - 1}${CODE_CLOSE}`;
|
|
5760
|
+
});
|
|
5761
|
+
working = working.replace(/\*\*([^*]+)\*\*/g, (_m, t) => chalk18.bold(t)).replace(/__([^_]+)__/g, (_m, t) => chalk18.bold(t)).replace(/(^|[^*])\*([^*\n]+)\*/g, (_m, lead, t) => lead + chalk18.italic(t)).replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, label, url) => `${chalk18.underline(label)} ${chalk18.dim(`(${url})`)}`);
|
|
5762
|
+
return working.replace(
|
|
5763
|
+
new RegExp(`${CODE_OPEN}(\\d+)${CODE_CLOSE}`, "g"),
|
|
5764
|
+
(_m, i) => chalk18.yellow(codeSpans[Number(i)])
|
|
5765
|
+
);
|
|
5766
|
+
}
|
|
5767
|
+
|
|
5768
|
+
// src/commands/chat/index.ts
|
|
4968
5769
|
function getOutputFormat12(cmd) {
|
|
4969
5770
|
const config = loadConfig();
|
|
4970
5771
|
const globalOpts = cmd.optsWithGlobals();
|
|
4971
5772
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
4972
5773
|
}
|
|
4973
|
-
async function streamOneTurn(message, sessionId, projectId, branch) {
|
|
5774
|
+
async function streamOneTurn(message, sessionId, projectId, branch, signal) {
|
|
4974
5775
|
const api = createApiClient();
|
|
4975
|
-
const
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
5776
|
+
const status = new Status();
|
|
5777
|
+
status.set([` ${chalk19.magenta(SPINNER)} ${chalk19.dim("thinking")}`]);
|
|
5778
|
+
status.start();
|
|
5779
|
+
let response;
|
|
5780
|
+
try {
|
|
5781
|
+
response = await api.language.chatStream({
|
|
5782
|
+
message,
|
|
5783
|
+
sessionId,
|
|
5784
|
+
projectId,
|
|
5785
|
+
projectBranch: projectId ? branch : void 0
|
|
5786
|
+
});
|
|
5787
|
+
} catch (error) {
|
|
5788
|
+
status.stop();
|
|
5789
|
+
throw error;
|
|
5790
|
+
}
|
|
4981
5791
|
const reader = response.body.getReader();
|
|
4982
5792
|
const decoder = new TextDecoder();
|
|
5793
|
+
const markdown = new MarkdownRenderer();
|
|
4983
5794
|
let buffer = "";
|
|
4984
5795
|
let finalSession = sessionId ?? "";
|
|
4985
5796
|
let input = 0;
|
|
4986
5797
|
let output = 0;
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
if (
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5798
|
+
let started = false;
|
|
5799
|
+
const emit = (lines) => {
|
|
5800
|
+
if (lines.length === 0) return;
|
|
5801
|
+
if (!started) {
|
|
5802
|
+
started = true;
|
|
5803
|
+
status.stop();
|
|
5804
|
+
}
|
|
5805
|
+
for (const line of lines) console.log(line);
|
|
5806
|
+
};
|
|
5807
|
+
const onAbort = () => {
|
|
5808
|
+
void reader.cancel();
|
|
5809
|
+
};
|
|
5810
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
5811
|
+
try {
|
|
5812
|
+
for (; ; ) {
|
|
5813
|
+
const { done, value } = await reader.read();
|
|
5814
|
+
if (done) break;
|
|
5815
|
+
buffer += decoder.decode(value, { stream: true });
|
|
5816
|
+
const lines = buffer.split("\n");
|
|
5817
|
+
buffer = lines.pop() ?? "";
|
|
5818
|
+
for (const line of lines) {
|
|
5819
|
+
if (!line.startsWith("data:")) continue;
|
|
5820
|
+
const data = line.slice(5).trim();
|
|
5821
|
+
if (!data) continue;
|
|
5822
|
+
try {
|
|
5823
|
+
const event = JSON.parse(data);
|
|
5824
|
+
if (event.type === "token" && event.content) {
|
|
5825
|
+
emit(markdown.push(event.content));
|
|
5826
|
+
} else if (event.type === "done") {
|
|
5827
|
+
finalSession = event.sessionId ?? finalSession;
|
|
5828
|
+
input = event.inputTokens;
|
|
5829
|
+
output = event.outputTokens;
|
|
5830
|
+
} else if (event.type === "error") {
|
|
5831
|
+
emit(markdown.flush());
|
|
5832
|
+
failure(event.content ?? "The assistant reported an error.");
|
|
5833
|
+
}
|
|
5834
|
+
} catch {
|
|
5008
5835
|
}
|
|
5009
|
-
} catch {
|
|
5010
5836
|
}
|
|
5011
5837
|
}
|
|
5838
|
+
emit(markdown.flush());
|
|
5839
|
+
} finally {
|
|
5840
|
+
signal?.removeEventListener("abort", onAbort);
|
|
5841
|
+
status.stop();
|
|
5012
5842
|
}
|
|
5013
5843
|
return { sessionId: finalSession, input, output };
|
|
5014
5844
|
}
|
|
5845
|
+
var HELP = [
|
|
5846
|
+
" /new start a fresh session",
|
|
5847
|
+
" /session [id] show the current session, or switch to another",
|
|
5848
|
+
" /clear clear the screen",
|
|
5849
|
+
" /help this list",
|
|
5850
|
+
" /quit leave (Ctrl-D also works)"
|
|
5851
|
+
];
|
|
5015
5852
|
async function runChatRepl(options) {
|
|
5016
5853
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
5017
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
5854
|
+
const { getUpdateNotice } = await import("./update-check-XRMWJ753.js");
|
|
5018
5855
|
let sessionId = options.session;
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
}
|
|
5856
|
+
let lastReportedSession;
|
|
5857
|
+
console.log(chalk19.bold("Diafunc chat") + chalk19.dim(" \xB7 /help for commands, /quit to exit"));
|
|
5858
|
+
if (options.project) console.log(chalk19.dim(`Project context: ${options.project}`));
|
|
5859
|
+
if (sessionId) console.log(chalk19.dim(`Continuing session ${sessionId}`));
|
|
5023
5860
|
const notice = await getUpdateNotice();
|
|
5024
|
-
if (notice) console.log(
|
|
5861
|
+
if (notice) console.log(chalk19.dim(notice));
|
|
5025
5862
|
console.log();
|
|
5026
5863
|
for (; ; ) {
|
|
5027
5864
|
let line;
|
|
5028
5865
|
try {
|
|
5029
|
-
line = await promptInput({ message:
|
|
5866
|
+
line = await promptInput({ message: chalk19.cyan.bold("you >") });
|
|
5030
5867
|
} catch {
|
|
5031
5868
|
console.log();
|
|
5032
5869
|
return;
|
|
@@ -5043,43 +5880,70 @@ async function runChatRepl(options) {
|
|
|
5043
5880
|
return;
|
|
5044
5881
|
case "new":
|
|
5045
5882
|
sessionId = void 0;
|
|
5046
|
-
|
|
5883
|
+
lastReportedSession = void 0;
|
|
5884
|
+
console.log(chalk19.dim("Started a new session."));
|
|
5885
|
+
continue;
|
|
5886
|
+
case "clear":
|
|
5887
|
+
console.clear();
|
|
5047
5888
|
continue;
|
|
5048
5889
|
case "session":
|
|
5049
5890
|
if (!arg) {
|
|
5050
|
-
console.log(
|
|
5891
|
+
console.log(chalk19.dim(`Current session: ${sessionId ?? "(new)"}`));
|
|
5051
5892
|
} else {
|
|
5052
5893
|
sessionId = arg;
|
|
5053
|
-
|
|
5894
|
+
lastReportedSession = void 0;
|
|
5895
|
+
console.log(chalk19.dim(`Switched to session ${sessionId}`));
|
|
5054
5896
|
}
|
|
5055
5897
|
continue;
|
|
5056
5898
|
case "help":
|
|
5057
5899
|
case "h":
|
|
5058
5900
|
case "?":
|
|
5059
|
-
console.log(
|
|
5060
|
-
console.log(chalk22.dim(" /session [id] switch to a session (no id = show current)"));
|
|
5061
|
-
console.log(chalk22.dim(" /quit exit the REPL"));
|
|
5901
|
+
for (const l of HELP) console.log(chalk19.dim(l));
|
|
5062
5902
|
continue;
|
|
5063
5903
|
default:
|
|
5064
|
-
console.log(
|
|
5904
|
+
console.log(chalk19.dim(`Unknown command: /${cmd}. Try /help.`));
|
|
5065
5905
|
continue;
|
|
5066
5906
|
}
|
|
5067
5907
|
}
|
|
5068
|
-
|
|
5908
|
+
const controller = new AbortController();
|
|
5909
|
+
const onSigint = () => controller.abort();
|
|
5910
|
+
process.on("SIGINT", onSigint);
|
|
5911
|
+
console.log();
|
|
5069
5912
|
try {
|
|
5070
|
-
const result = await streamOneTurn(trimmed, sessionId, options.project, options.branch);
|
|
5913
|
+
const result = await streamOneTurn(trimmed, sessionId, options.project, options.branch, controller.signal);
|
|
5071
5914
|
sessionId = result.sessionId || sessionId;
|
|
5072
5915
|
console.log();
|
|
5073
|
-
|
|
5916
|
+
if (controller.signal.aborted) {
|
|
5917
|
+
console.log(chalk19.dim(" (cancelled)"));
|
|
5918
|
+
} else {
|
|
5919
|
+
const parts = [`${result.input} in / ${result.output} out`];
|
|
5920
|
+
if (sessionId && sessionId !== lastReportedSession) {
|
|
5921
|
+
parts.push(`session ${sessionId}`);
|
|
5922
|
+
lastReportedSession = sessionId;
|
|
5923
|
+
}
|
|
5924
|
+
console.log(chalk19.dim(` ${parts.join(" \xB7 ")}`));
|
|
5925
|
+
}
|
|
5074
5926
|
console.log();
|
|
5075
5927
|
} catch (error) {
|
|
5076
|
-
|
|
5077
|
-
|
|
5928
|
+
if (controller.signal.aborted) {
|
|
5929
|
+
console.log(chalk19.dim(" (cancelled)"));
|
|
5930
|
+
console.log();
|
|
5931
|
+
} else {
|
|
5932
|
+
failure(`Request failed: ${error.message}`);
|
|
5933
|
+
hint(`Check 'diafunc status summary' if this keeps happening.`);
|
|
5934
|
+
}
|
|
5935
|
+
} finally {
|
|
5936
|
+
process.off("SIGINT", onSigint);
|
|
5078
5937
|
}
|
|
5079
5938
|
}
|
|
5080
5939
|
}
|
|
5081
5940
|
function registerChatCommands(program) {
|
|
5082
|
-
const chat = program.command("chat").description("
|
|
5941
|
+
const chat = program.command("chat").description("Ask the Diafunc assistant").addHelpText("after", `
|
|
5942
|
+
Examples:
|
|
5943
|
+
$ diafunc chat interactive session
|
|
5944
|
+
$ diafunc chat --project <id> with a project in context
|
|
5945
|
+
$ diafunc chat send "how do I add a table?" one question, one answer
|
|
5946
|
+
`);
|
|
5083
5947
|
chat.option("--session <id>", "Continue an existing session").option("--project <id>", "Project context").option("--branch <branch>", "Project branch", "main").action(async (options) => {
|
|
5084
5948
|
try {
|
|
5085
5949
|
await runChatRepl(options);
|
|
@@ -5098,9 +5962,11 @@ function registerChatCommands(program) {
|
|
|
5098
5962
|
projectBranch: options.branch
|
|
5099
5963
|
});
|
|
5100
5964
|
if (outputFormat === "human") {
|
|
5101
|
-
console.log(response.content);
|
|
5965
|
+
console.log(renderMarkdown(response.content));
|
|
5102
5966
|
console.log();
|
|
5103
|
-
console.log(
|
|
5967
|
+
console.log(chalk19.dim(
|
|
5968
|
+
` session ${response.sessionId} \xB7 ${response.inputTokens} in / ${response.outputTokens} out`
|
|
5969
|
+
));
|
|
5104
5970
|
} else {
|
|
5105
5971
|
format(response, { format: outputFormat });
|
|
5106
5972
|
}
|
|
@@ -5165,10 +6031,9 @@ function registerChatCommands(program) {
|
|
|
5165
6031
|
sessionId = event.sessionId ?? "";
|
|
5166
6032
|
console.log();
|
|
5167
6033
|
console.log();
|
|
5168
|
-
console.log(
|
|
6034
|
+
console.log(chalk19.dim(`Session: ${sessionId} | Tokens: ${event.inputTokens} in, ${event.outputTokens} out`));
|
|
5169
6035
|
} else if (event.type === "error") {
|
|
5170
|
-
|
|
5171
|
-
Error: ${event.content}`));
|
|
6036
|
+
failure(`Error: ${event.content}`);
|
|
5172
6037
|
}
|
|
5173
6038
|
} catch {
|
|
5174
6039
|
}
|
|
@@ -5183,7 +6048,7 @@ Error: ${event.content}`));
|
|
|
5183
6048
|
chat.command("upload").description("Upload a file for chat context").argument("<file>", "File to upload").action(async (file) => {
|
|
5184
6049
|
try {
|
|
5185
6050
|
if (!fs7.existsSync(file)) {
|
|
5186
|
-
|
|
6051
|
+
failure(`File not found: ${file}`);
|
|
5187
6052
|
process.exit(1);
|
|
5188
6053
|
}
|
|
5189
6054
|
const api = createApiClient();
|
|
@@ -5192,7 +6057,7 @@ Error: ${event.content}`));
|
|
|
5192
6057
|
const formData = new FormData();
|
|
5193
6058
|
formData.append("file", blob, path6.basename(file));
|
|
5194
6059
|
const result = await api.language.upload(formData);
|
|
5195
|
-
|
|
6060
|
+
success(`File uploaded: ${result}`);
|
|
5196
6061
|
} catch (error) {
|
|
5197
6062
|
handleError(error);
|
|
5198
6063
|
}
|
|
@@ -5215,7 +6080,7 @@ Error: ${event.content}`));
|
|
|
5215
6080
|
try {
|
|
5216
6081
|
const api = createApiClient();
|
|
5217
6082
|
await api.language.deleteSession(sessionId);
|
|
5218
|
-
|
|
6083
|
+
success(`Session "${sessionId}" deleted.`);
|
|
5219
6084
|
} catch (error) {
|
|
5220
6085
|
handleError(error);
|
|
5221
6086
|
}
|
|
@@ -5224,18 +6089,18 @@ Error: ${event.content}`));
|
|
|
5224
6089
|
try {
|
|
5225
6090
|
const outputFormat = getOutputFormat12(cmd);
|
|
5226
6091
|
const api = createApiClient();
|
|
5227
|
-
const
|
|
6092
|
+
const detail2 = await api.language.getSession(sessionId);
|
|
5228
6093
|
if (outputFormat === "human") {
|
|
5229
|
-
console.log(
|
|
6094
|
+
console.log(chalk19.bold(detail2.title) + chalk19.dim(` (${detail2.sessionId})`));
|
|
5230
6095
|
console.log();
|
|
5231
|
-
for (const msg of
|
|
5232
|
-
const role = msg.role === "user" ?
|
|
5233
|
-
console.log(`${role} ${
|
|
6096
|
+
for (const msg of detail2.messages) {
|
|
6097
|
+
const role = msg.role === "user" ? chalk19.cyan.bold("You") : chalk19.magenta.bold("Diafunc");
|
|
6098
|
+
console.log(`${role} ${chalk19.dim(msg.created)}`);
|
|
5234
6099
|
console.log(msg.content);
|
|
5235
6100
|
console.log();
|
|
5236
6101
|
}
|
|
5237
6102
|
} else {
|
|
5238
|
-
format(
|
|
6103
|
+
format(detail2, { format: outputFormat });
|
|
5239
6104
|
}
|
|
5240
6105
|
} catch (error) {
|
|
5241
6106
|
handleError(error);
|
|
@@ -5245,7 +6110,7 @@ Error: ${event.content}`));
|
|
|
5245
6110
|
try {
|
|
5246
6111
|
const api = createApiClient();
|
|
5247
6112
|
await api.language.renameSession(sessionId, title);
|
|
5248
|
-
|
|
6113
|
+
success(`Session "${sessionId}" renamed to "${title}".`);
|
|
5249
6114
|
} catch (error) {
|
|
5250
6115
|
handleError(error);
|
|
5251
6116
|
}
|
|
@@ -5263,47 +6128,108 @@ Error: ${event.content}`));
|
|
|
5263
6128
|
}
|
|
5264
6129
|
|
|
5265
6130
|
// src/commands/search/index.ts
|
|
6131
|
+
import chalk20 from "chalk";
|
|
5266
6132
|
function getOutputFormat13(cmd) {
|
|
5267
6133
|
const config = loadConfig();
|
|
5268
6134
|
const globalOpts = cmd.optsWithGlobals();
|
|
5269
6135
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
5270
6136
|
}
|
|
5271
6137
|
function registerSearchCommands(program) {
|
|
5272
|
-
program.command("search").description("Search
|
|
6138
|
+
program.command("search").description("Search across every project you can see").argument("<query>", "Search query").option("--project <id>", "Limit the search to one project").option("--branch <branch>", "Project branch, when --project is given").option("--type <contentType>", "Limit to one content type, e.g. project, notebook, table, function").option("--limit <n>", "Maximum results", "20").addHelpText("after", `
|
|
6139
|
+
Examples:
|
|
6140
|
+
$ diafunc search "housing" everything matching, across projects
|
|
6141
|
+
$ diafunc search "housing" --type project only projects
|
|
6142
|
+
$ diafunc search "medv" --project <id> only inside one project
|
|
6143
|
+
$ diafunc search "housing" --output json for scripting
|
|
6144
|
+
`).action(async (query, options, cmd) => {
|
|
5273
6145
|
try {
|
|
5274
6146
|
const outputFormat = getOutputFormat13(cmd);
|
|
6147
|
+
const overrides = cmd.optsWithGlobals();
|
|
6148
|
+
const config = loadConfig();
|
|
5275
6149
|
const api = createApiClient();
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
6150
|
+
const projectId = options.project ?? overrides.project ?? config.defaults.project ?? null;
|
|
6151
|
+
const limit = Number.parseInt(options.limit, 10);
|
|
6152
|
+
const page = await api.index.searchPage({
|
|
6153
|
+
query,
|
|
6154
|
+
limit: Number.isFinite(limit) && limit > 0 ? limit : 20,
|
|
6155
|
+
contentType: options.type ?? null,
|
|
6156
|
+
projectId,
|
|
6157
|
+
projectBranch: projectId ? options.branch ?? overrides.branch ?? config.defaults.branch ?? "main" : null
|
|
6158
|
+
});
|
|
6159
|
+
const items = dedupe(page.items);
|
|
6160
|
+
if (items.length === 0) {
|
|
6161
|
+
empty("matches", { format: outputFormat });
|
|
6162
|
+
return;
|
|
6163
|
+
}
|
|
6164
|
+
if (outputFormat === "json") {
|
|
6165
|
+
format({ ...page, items }, { format: outputFormat });
|
|
6166
|
+
return;
|
|
6167
|
+
}
|
|
6168
|
+
if (isInteractive()) {
|
|
6169
|
+
renderResults(items);
|
|
5283
6170
|
} else {
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
projectId,
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
}
|
|
6171
|
+
format(items, {
|
|
6172
|
+
format: outputFormat,
|
|
6173
|
+
columns: [
|
|
6174
|
+
{ key: "contentType", header: "type" },
|
|
6175
|
+
{ key: "name" },
|
|
6176
|
+
{ key: "projectId", kind: "id" },
|
|
6177
|
+
{ key: "entityId", kind: "id" }
|
|
6178
|
+
]
|
|
6179
|
+
});
|
|
6180
|
+
}
|
|
6181
|
+
if (page.nextCursor && isInteractive()) {
|
|
6182
|
+
console.log(chalk20.dim(`More results available \u2014 raise --limit to see them.`));
|
|
5297
6183
|
}
|
|
5298
6184
|
} catch (error) {
|
|
5299
6185
|
handleError(error);
|
|
5300
6186
|
}
|
|
5301
6187
|
});
|
|
5302
6188
|
}
|
|
6189
|
+
function dedupe(items) {
|
|
6190
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6191
|
+
const out = [];
|
|
6192
|
+
for (const item of items) {
|
|
6193
|
+
const key = [item.contentType, item.projectId, item.projectBranch, item.entityId, item.entityBranch].join("|");
|
|
6194
|
+
if (seen.has(key)) continue;
|
|
6195
|
+
seen.add(key);
|
|
6196
|
+
out.push(item);
|
|
6197
|
+
}
|
|
6198
|
+
return out;
|
|
6199
|
+
}
|
|
6200
|
+
function renderResults(items) {
|
|
6201
|
+
for (const item of items) {
|
|
6202
|
+
const name = item.name || "(unnamed)";
|
|
6203
|
+
console.log();
|
|
6204
|
+
console.log(`${chalk20.dim(`[${item.contentType}]`)} ${chalk20.bold(name)}`);
|
|
6205
|
+
const raw = item.snippetField === "name" ? item.description : item.snippet ?? item.description;
|
|
6206
|
+
const line = raw ? collapse(raw) : null;
|
|
6207
|
+
if (line && stripHighlight(line) !== name) console.log(` ${highlight(line)}`);
|
|
6208
|
+
const ref = item.entityId ? `${item.projectId}/${item.projectBranch}/${item.entityId}/${item.entityBranch ?? "main"}` : item.projectId;
|
|
6209
|
+
console.log(` ${chalk20.dim(ref)}`);
|
|
6210
|
+
}
|
|
6211
|
+
console.log();
|
|
6212
|
+
}
|
|
6213
|
+
var HIGHLIGHT_OPEN = /<mark>/g;
|
|
6214
|
+
var HIGHLIGHT_CLOSE = /<\/mark>/g;
|
|
6215
|
+
function highlight(text) {
|
|
6216
|
+
const parts = text.split(HIGHLIGHT_OPEN);
|
|
6217
|
+
return parts.map((part, i) => {
|
|
6218
|
+
if (i === 0) return chalk20.dim(part);
|
|
6219
|
+
const [marked, ...rest] = part.split(HIGHLIGHT_CLOSE);
|
|
6220
|
+
return chalk20.bold.cyan(marked) + chalk20.dim(rest.join(""));
|
|
6221
|
+
}).join("");
|
|
6222
|
+
}
|
|
6223
|
+
function stripHighlight(text) {
|
|
6224
|
+
return text.replace(HIGHLIGHT_OPEN, "").replace(HIGHLIGHT_CLOSE, "");
|
|
6225
|
+
}
|
|
6226
|
+
function collapse(text) {
|
|
6227
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
6228
|
+
return flat.length > 160 ? `${flat.slice(0, 159)}\u2026` : flat;
|
|
6229
|
+
}
|
|
5303
6230
|
|
|
5304
6231
|
// src/commands/admin/index.ts
|
|
5305
6232
|
import { readFile } from "fs/promises";
|
|
5306
|
-
import chalk23 from "chalk";
|
|
5307
6233
|
function getOutputFormat14(cmd) {
|
|
5308
6234
|
const config = loadConfig();
|
|
5309
6235
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -5326,7 +6252,13 @@ function registerAdminCommands(program) {
|
|
|
5326
6252
|
}));
|
|
5327
6253
|
format(summary, {
|
|
5328
6254
|
format: outputFormat,
|
|
5329
|
-
columns: [
|
|
6255
|
+
columns: [
|
|
6256
|
+
{ key: "id", kind: "id" },
|
|
6257
|
+
{ key: "name" },
|
|
6258
|
+
{ key: "email" },
|
|
6259
|
+
{ key: "role" },
|
|
6260
|
+
{ key: "remainingCredits", header: "credits", kind: "number" }
|
|
6261
|
+
]
|
|
5330
6262
|
});
|
|
5331
6263
|
} catch (error) {
|
|
5332
6264
|
handleError(error);
|
|
@@ -5367,7 +6299,7 @@ function registerAdminCommands(program) {
|
|
|
5367
6299
|
try {
|
|
5368
6300
|
const api = createApiClient();
|
|
5369
6301
|
await api.admin.mergeSetting({ [key]: value });
|
|
5370
|
-
|
|
6302
|
+
success(`Setting "${key}" updated.`);
|
|
5371
6303
|
} catch (error) {
|
|
5372
6304
|
handleError(error);
|
|
5373
6305
|
}
|
|
@@ -5378,10 +6310,10 @@ function registerAdminCommands(program) {
|
|
|
5378
6310
|
const api = createApiClient();
|
|
5379
6311
|
if (options.longTerm) {
|
|
5380
6312
|
await api.storage.createLongTermFullBackup();
|
|
5381
|
-
|
|
6313
|
+
success("Full long-term backup initiated.");
|
|
5382
6314
|
} else {
|
|
5383
6315
|
await api.storage.createShortTermFullBackup();
|
|
5384
|
-
|
|
6316
|
+
success("Full short-term backup initiated.");
|
|
5385
6317
|
}
|
|
5386
6318
|
} catch (error) {
|
|
5387
6319
|
handleError(error);
|
|
@@ -5392,10 +6324,10 @@ function registerAdminCommands(program) {
|
|
|
5392
6324
|
const api = createApiClient();
|
|
5393
6325
|
if (options.longTerm) {
|
|
5394
6326
|
await api.storage.createLongTermProjectBackup();
|
|
5395
|
-
|
|
6327
|
+
success("Project long-term backup initiated.");
|
|
5396
6328
|
} else {
|
|
5397
6329
|
await api.storage.createShortTermProjectBackup();
|
|
5398
|
-
|
|
6330
|
+
success("Project short-term backup initiated.");
|
|
5399
6331
|
}
|
|
5400
6332
|
} catch (error) {
|
|
5401
6333
|
handleError(error);
|
|
@@ -5409,7 +6341,7 @@ function registerAdminCommands(program) {
|
|
|
5409
6341
|
);
|
|
5410
6342
|
const api = createApiClient();
|
|
5411
6343
|
await api.storage.restoreProjectBackup({ projectId, projectBranch, bucketName, objectName });
|
|
5412
|
-
|
|
6344
|
+
success(`Restore initiated for ${projectId}/${projectBranch} from ${bucketName}/${objectName}.`);
|
|
5413
6345
|
} catch (error) {
|
|
5414
6346
|
handleError(error);
|
|
5415
6347
|
}
|
|
@@ -5422,7 +6354,7 @@ function registerAdminCommands(program) {
|
|
|
5422
6354
|
);
|
|
5423
6355
|
const api = createApiClient();
|
|
5424
6356
|
await api.storage.restoreFullBackup({ bucketName, objectName });
|
|
5425
|
-
|
|
6357
|
+
success(`Full restore initiated from ${bucketName}/${objectName}.`);
|
|
5426
6358
|
} catch (error) {
|
|
5427
6359
|
handleError(error);
|
|
5428
6360
|
}
|
|
@@ -5432,10 +6364,10 @@ function registerAdminCommands(program) {
|
|
|
5432
6364
|
const api = createApiClient();
|
|
5433
6365
|
if (options.project) {
|
|
5434
6366
|
await api.index.rebuildProject(options.project);
|
|
5435
|
-
|
|
6367
|
+
success(`Index rebuild initiated for project "${options.project}".`);
|
|
5436
6368
|
} else {
|
|
5437
6369
|
await api.index.rebuildAll();
|
|
5438
|
-
|
|
6370
|
+
success("Index rebuild initiated for all projects.");
|
|
5439
6371
|
}
|
|
5440
6372
|
} catch (error) {
|
|
5441
6373
|
handleError(error);
|
|
@@ -5446,7 +6378,7 @@ function registerAdminCommands(program) {
|
|
|
5446
6378
|
const outputFormat = getOutputFormat14(cmd);
|
|
5447
6379
|
const api = createApiClient();
|
|
5448
6380
|
const perm = await api.admin.getPermissions(projectId);
|
|
5449
|
-
format(perm, { format: outputFormat });
|
|
6381
|
+
format({ projectId, permission: perm }, { format: outputFormat });
|
|
5450
6382
|
} catch (error) {
|
|
5451
6383
|
handleError(error);
|
|
5452
6384
|
}
|
|
@@ -5477,7 +6409,7 @@ function registerAdminCommands(program) {
|
|
|
5477
6409
|
}
|
|
5478
6410
|
|
|
5479
6411
|
// src/commands/status/summary.ts
|
|
5480
|
-
import
|
|
6412
|
+
import chalk21 from "chalk";
|
|
5481
6413
|
|
|
5482
6414
|
// src/client/services/status.ts
|
|
5483
6415
|
function createStatusService() {
|
|
@@ -5503,24 +6435,24 @@ function createStatusService() {
|
|
|
5503
6435
|
|
|
5504
6436
|
// src/commands/status/summary.ts
|
|
5505
6437
|
var STATE_COLORS = {
|
|
5506
|
-
UP:
|
|
5507
|
-
DEGRADED:
|
|
5508
|
-
DOWN:
|
|
5509
|
-
UNKNOWN:
|
|
6438
|
+
UP: chalk21.green,
|
|
6439
|
+
DEGRADED: chalk21.yellow,
|
|
6440
|
+
DOWN: chalk21.red,
|
|
6441
|
+
UNKNOWN: chalk21.gray
|
|
5510
6442
|
};
|
|
5511
6443
|
function stateColor(state) {
|
|
5512
|
-
return STATE_COLORS[state] ??
|
|
6444
|
+
return STATE_COLORS[state] ?? chalk21.gray;
|
|
5513
6445
|
}
|
|
5514
6446
|
function stateSymbol(state) {
|
|
5515
6447
|
switch (state) {
|
|
5516
6448
|
case "UP":
|
|
5517
|
-
return
|
|
6449
|
+
return chalk21.green("\u25CF");
|
|
5518
6450
|
case "DEGRADED":
|
|
5519
|
-
return
|
|
6451
|
+
return chalk21.yellow("\u25CF");
|
|
5520
6452
|
case "DOWN":
|
|
5521
|
-
return
|
|
6453
|
+
return chalk21.red("\u25CF");
|
|
5522
6454
|
default:
|
|
5523
|
-
return
|
|
6455
|
+
return chalk21.gray("\u25CB");
|
|
5524
6456
|
}
|
|
5525
6457
|
}
|
|
5526
6458
|
function registerSummaryCommand(parent) {
|
|
@@ -5544,15 +6476,21 @@ function registerSummaryCommand(parent) {
|
|
|
5544
6476
|
for (const domain of summary.domains) {
|
|
5545
6477
|
const label = stateColor(domain.state)(domain.state.padEnd(10));
|
|
5546
6478
|
console.log(` ${stateSymbol(domain.state)} ${label} ${domain.name}`);
|
|
6479
|
+
if (domain.componentIds.length > 0) {
|
|
6480
|
+
console.log(` ${chalk21.dim(domain.componentIds.join(", "))}`);
|
|
6481
|
+
}
|
|
5547
6482
|
}
|
|
5548
6483
|
console.log();
|
|
5549
6484
|
if (summary.openIncidents > 0) {
|
|
5550
|
-
console.log(
|
|
6485
|
+
console.log(chalk21.yellow(` ${summary.openIncidents} active incident(s)`));
|
|
5551
6486
|
} else {
|
|
5552
|
-
console.log(
|
|
6487
|
+
console.log(chalk21.dim(" No active incidents"));
|
|
5553
6488
|
}
|
|
5554
|
-
console.log(
|
|
5555
|
-
|
|
6489
|
+
console.log(chalk21.dim(
|
|
6490
|
+
`
|
|
6491
|
+
Platform v${version.platformVersion} \xB7 checked ${formatInstant(summary.timestamp)}`
|
|
6492
|
+
));
|
|
6493
|
+
console.log(chalk21.dim(` Drill into one with 'diafunc status component <id>'.`));
|
|
5556
6494
|
console.log();
|
|
5557
6495
|
} catch (error) {
|
|
5558
6496
|
handleError(error);
|
|
@@ -5561,17 +6499,17 @@ function registerSummaryCommand(parent) {
|
|
|
5561
6499
|
}
|
|
5562
6500
|
|
|
5563
6501
|
// src/commands/status/component.ts
|
|
5564
|
-
import
|
|
6502
|
+
import chalk22 from "chalk";
|
|
5565
6503
|
function stateSymbol2(state) {
|
|
5566
6504
|
switch (state) {
|
|
5567
6505
|
case "UP":
|
|
5568
|
-
return
|
|
6506
|
+
return chalk22.green("\u25CF");
|
|
5569
6507
|
case "DEGRADED":
|
|
5570
|
-
return
|
|
6508
|
+
return chalk22.yellow("\u25CF");
|
|
5571
6509
|
case "DOWN":
|
|
5572
|
-
return
|
|
6510
|
+
return chalk22.red("\u25CF");
|
|
5573
6511
|
default:
|
|
5574
|
-
return
|
|
6512
|
+
return chalk22.gray("\u25CB");
|
|
5575
6513
|
}
|
|
5576
6514
|
}
|
|
5577
6515
|
function registerComponentCommand(parent) {
|
|
@@ -5581,27 +6519,31 @@ function registerComponentCommand(parent) {
|
|
|
5581
6519
|
const outputFormat = globalOpts.output ?? "human";
|
|
5582
6520
|
const status = createStatusService();
|
|
5583
6521
|
const components = await status.getComponents();
|
|
5584
|
-
const
|
|
6522
|
+
const wanted = id.toLowerCase();
|
|
6523
|
+
const match = components.find((c) => {
|
|
6524
|
+
const cid = c.id.toLowerCase();
|
|
6525
|
+
return cid === wanted || cid === `${wanted}-service` || cid.replace(/-service$/, "") === wanted.replace(/[\s-]*service$/, "").replace(/\s+/g, "-");
|
|
6526
|
+
});
|
|
5585
6527
|
if (!match) {
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
process.exit(
|
|
6528
|
+
failure(`No component called "${id}".`);
|
|
6529
|
+
hint(`Available: ${components.map((c) => c.id).join(", ")}`);
|
|
6530
|
+
process.exit(EXIT_USAGE);
|
|
5589
6531
|
}
|
|
5590
6532
|
if (outputFormat !== "human") {
|
|
5591
6533
|
format(match, { format: outputFormat });
|
|
5592
6534
|
return;
|
|
5593
6535
|
}
|
|
5594
6536
|
console.log();
|
|
5595
|
-
console.log(` ${stateSymbol2(match.state)} ${
|
|
5596
|
-
console.log(` State: ${match.state}`);
|
|
6537
|
+
console.log(` ${stateSymbol2(match.state)} ${chalk22.bold(match.id)} ${match.version ? chalk22.dim("v" + match.version) : ""}`);
|
|
6538
|
+
console.log(` State: ${renderState(match.state)}`);
|
|
5597
6539
|
if (match.lastCheckAt) {
|
|
5598
|
-
console.log(` Last check: ${
|
|
6540
|
+
console.log(` Last check: ${formatInstant(match.lastCheckAt)}`);
|
|
5599
6541
|
}
|
|
5600
6542
|
if (match.checks.length > 0) {
|
|
5601
6543
|
console.log();
|
|
5602
6544
|
console.log(" Checks:");
|
|
5603
6545
|
for (const check of match.checks) {
|
|
5604
|
-
const cat = check.category ?
|
|
6546
|
+
const cat = check.category ? chalk22.dim(` (${check.category})`) : "";
|
|
5605
6547
|
console.log(` ${stateSymbol2(check.state)} ${check.name}${cat}`);
|
|
5606
6548
|
}
|
|
5607
6549
|
}
|
|
@@ -5613,12 +6555,12 @@ function registerComponentCommand(parent) {
|
|
|
5613
6555
|
}
|
|
5614
6556
|
|
|
5615
6557
|
// src/commands/status/incidents.ts
|
|
5616
|
-
import
|
|
6558
|
+
import chalk23 from "chalk";
|
|
5617
6559
|
var SEVERITY_COLORS = {
|
|
5618
|
-
ERROR:
|
|
5619
|
-
WARNING:
|
|
5620
|
-
INFO:
|
|
5621
|
-
MAINTENANCE:
|
|
6560
|
+
ERROR: chalk23.red,
|
|
6561
|
+
WARNING: chalk23.yellow,
|
|
6562
|
+
INFO: chalk23.blue,
|
|
6563
|
+
MAINTENANCE: chalk23.cyan
|
|
5622
6564
|
};
|
|
5623
6565
|
function registerIncidentsCommand(parent) {
|
|
5624
6566
|
parent.command("incidents").description("List recent incidents").option("-w, --window <window>", "Time window (e.g. 24h, 48h)", "24h").action(async (options, cmd) => {
|
|
@@ -5632,22 +6574,22 @@ function registerIncidentsCommand(parent) {
|
|
|
5632
6574
|
return;
|
|
5633
6575
|
}
|
|
5634
6576
|
if (incidents.length === 0) {
|
|
5635
|
-
console.log(
|
|
6577
|
+
console.log(chalk23.dim(`
|
|
5636
6578
|
No incidents in the last ${options.window}.
|
|
5637
6579
|
`));
|
|
5638
6580
|
return;
|
|
5639
6581
|
}
|
|
5640
6582
|
console.log();
|
|
5641
6583
|
for (const incident of incidents) {
|
|
5642
|
-
const color = SEVERITY_COLORS[incident.severity] ??
|
|
6584
|
+
const color = SEVERITY_COLORS[incident.severity] ?? chalk23.gray;
|
|
5643
6585
|
const severity = color(incident.severity.padEnd(8));
|
|
5644
6586
|
const time = incident.startedAt ? new Date(incident.startedAt).toLocaleString() : "";
|
|
5645
|
-
const resolved = incident.resolvedAt ?
|
|
6587
|
+
const resolved = incident.resolvedAt ? chalk23.green(" [resolved]") : chalk23.yellow(" [open]");
|
|
5646
6588
|
console.log(` ${severity} ${incident.summary}${resolved}`);
|
|
5647
|
-
console.log(
|
|
6589
|
+
console.log(chalk23.dim(` ${time}`));
|
|
5648
6590
|
for (const update of incident.updates) {
|
|
5649
6591
|
const updateTime = new Date(update.at).toLocaleTimeString();
|
|
5650
|
-
console.log(
|
|
6592
|
+
console.log(chalk23.dim(` ${updateTime} ${update.status} ${update.message}`));
|
|
5651
6593
|
}
|
|
5652
6594
|
console.log();
|
|
5653
6595
|
}
|
|
@@ -5659,25 +6601,112 @@ function registerIncidentsCommand(parent) {
|
|
|
5659
6601
|
|
|
5660
6602
|
// src/commands/status/index.ts
|
|
5661
6603
|
function registerStatusCommands(program) {
|
|
5662
|
-
const status = program.command("status").description("Platform health and status")
|
|
6604
|
+
const status = program.command("status").description("Platform health and status").addHelpText("after", `
|
|
6605
|
+
Examples:
|
|
6606
|
+
$ diafunc status summary everything, at a glance
|
|
6607
|
+
$ diafunc status component storage one service in detail
|
|
6608
|
+
$ diafunc status incidents --days 7
|
|
6609
|
+
`);
|
|
6610
|
+
;
|
|
5663
6611
|
registerSummaryCommand(status);
|
|
5664
6612
|
registerComponentCommand(status);
|
|
5665
6613
|
registerIncidentsCommand(status);
|
|
5666
6614
|
}
|
|
5667
6615
|
|
|
5668
6616
|
// src/commands/analyze/index.ts
|
|
5669
|
-
import
|
|
6617
|
+
import chalk25 from "chalk";
|
|
5670
6618
|
import * as fs8 from "fs";
|
|
5671
6619
|
import * as path7 from "path";
|
|
5672
6620
|
import { spawn as spawn2 } from "child_process";
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
6621
|
+
|
|
6622
|
+
// src/commands/analyze/watch-view.ts
|
|
6623
|
+
import chalk24 from "chalk";
|
|
6624
|
+
|
|
6625
|
+
// src/client/types/analysis.ts
|
|
6626
|
+
var RUN_PHASE_LABELS = {
|
|
6627
|
+
QUEUED: "Waiting for a slot",
|
|
6628
|
+
PREPARING: "Preparing",
|
|
6629
|
+
PROFILING: "Profiling your data",
|
|
6630
|
+
DISCOVERING: "Discovering formulas",
|
|
6631
|
+
EXPLAINING: "Building charts and diagnostics",
|
|
6632
|
+
WRITING: "Writing the report"
|
|
6633
|
+
};
|
|
6634
|
+
|
|
6635
|
+
// src/commands/analyze/watch-view.ts
|
|
6636
|
+
var PHASE_ORDER = ["QUEUED", "PREPARING", "PROFILING", "DISCOVERING", "EXPLAINING", "WRITING"];
|
|
6637
|
+
function overallProgress(run) {
|
|
6638
|
+
if (run.overallFraction !== null && run.overallFraction !== void 0) return run.overallFraction;
|
|
6639
|
+
if (run.progressTotal && run.progressTotal > 0) return (run.progressDone ?? 0) / run.progressTotal;
|
|
6640
|
+
return null;
|
|
6641
|
+
}
|
|
6642
|
+
function phaseLabel(run) {
|
|
6643
|
+
if (run.phase && RUN_PHASE_LABELS[run.phase]) return RUN_PHASE_LABELS[run.phase];
|
|
6644
|
+
return run.state.charAt(0) + run.state.slice(1).toLowerCase();
|
|
6645
|
+
}
|
|
6646
|
+
function stepCounter(run) {
|
|
6647
|
+
if (!run.phase) return null;
|
|
6648
|
+
const index = PHASE_ORDER.indexOf(run.phase);
|
|
6649
|
+
if (index < 0) return null;
|
|
6650
|
+
return `step ${index + 1} of ${PHASE_ORDER.length}`;
|
|
6651
|
+
}
|
|
6652
|
+
function phaseDetail(run) {
|
|
6653
|
+
const parts = [];
|
|
6654
|
+
if (run.phase === "DISCOVERING") {
|
|
6655
|
+
if (run.fitGeneration !== null && run.fitGeneration !== void 0) {
|
|
6656
|
+
parts.push(`generation ${formatNumber(run.fitGeneration)}`);
|
|
6657
|
+
}
|
|
6658
|
+
if (run.fitQuality !== null && run.fitQuality !== void 0) {
|
|
6659
|
+
parts.push(`quality ${run.fitQuality.toPrecision(4)}`);
|
|
6660
|
+
}
|
|
6661
|
+
if (run.fitBudgetFraction !== null && run.fitBudgetFraction !== void 0) {
|
|
6662
|
+
parts.push(`${Math.round(run.fitBudgetFraction * 100)}% of budget used`);
|
|
6663
|
+
}
|
|
6664
|
+
}
|
|
6665
|
+
if (parts.length === 0 && run.progressTotal && run.progressTotal > 0) {
|
|
6666
|
+
parts.push(`${formatNumber(run.progressDone ?? 0)} of ${formatNumber(run.progressTotal)} tasks`);
|
|
6667
|
+
} else if (parts.length === 0 && run.phaseFraction !== null && run.phaseFraction !== void 0) {
|
|
6668
|
+
parts.push(`${Math.round(run.phaseFraction * 100)}% of this step`);
|
|
6669
|
+
}
|
|
6670
|
+
return parts.length > 0 ? parts.join(" \xB7 ") : null;
|
|
6671
|
+
}
|
|
6672
|
+
function renderWatchBlock(input) {
|
|
6673
|
+
const { run, elapsedMs, caption } = input;
|
|
6674
|
+
const lines = [];
|
|
6675
|
+
const step = stepCounter(run);
|
|
6676
|
+
const headline = [
|
|
6677
|
+
chalk24.cyan(SPINNER),
|
|
6678
|
+
chalk24.bold(phaseLabel(run)),
|
|
6679
|
+
step ? chalk24.dim(step) : null
|
|
6680
|
+
].filter(Boolean).join(" ");
|
|
6681
|
+
lines.push(` ${headline}`);
|
|
6682
|
+
const fraction = overallProgress(run);
|
|
6683
|
+
const elapsed = chalk24.dim(formatDuration(elapsedMs));
|
|
6684
|
+
if (fraction === null) {
|
|
6685
|
+
lines.push(` ${chalk24.dim("working")} ${elapsed}`);
|
|
6686
|
+
} else {
|
|
6687
|
+
const eta = estimateRemaining(fraction, elapsedMs);
|
|
6688
|
+
lines.push(
|
|
6689
|
+
` ${bar(fraction)} ${percent(fraction)} ${elapsed}` + (eta ? chalk24.dim(` \xB7 ~${formatDuration(eta)} left`) : "")
|
|
6690
|
+
);
|
|
6691
|
+
}
|
|
6692
|
+
const detail2 = caption ?? phaseDetail(run);
|
|
6693
|
+
if (detail2) lines.push(` ${chalk24.dim(detail2)}`);
|
|
6694
|
+
if (run.retryAttempts && run.retryAttempts > 0) {
|
|
6695
|
+
lines.push(` ${chalk24.yellow("!")} ${chalk24.dim(
|
|
6696
|
+
`restarted ${run.retryAttempts === 1 ? "once" : `${run.retryAttempts} times`} after an interruption \u2014 progress restarts from the beginning`
|
|
6697
|
+
)}`);
|
|
6698
|
+
}
|
|
6699
|
+
return lines;
|
|
6700
|
+
}
|
|
6701
|
+
function estimateRemaining(fraction, elapsedMs) {
|
|
6702
|
+
if (fraction <= 0.02 || fraction >= 1 || elapsedMs < 3e4) return null;
|
|
6703
|
+
const total = elapsedMs / fraction;
|
|
6704
|
+
const remaining = total - elapsedMs;
|
|
6705
|
+
return remaining > 0 ? remaining : null;
|
|
5680
6706
|
}
|
|
6707
|
+
|
|
6708
|
+
// src/commands/analyze/index.ts
|
|
6709
|
+
var POLL_INTERVAL_MS = 2e3;
|
|
5681
6710
|
function openUrl(url) {
|
|
5682
6711
|
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
5683
6712
|
const args = process.platform === "win32" ? ["/c", "start", '""', url] : [url];
|
|
@@ -5711,14 +6740,14 @@ function multipartFromFile(file) {
|
|
|
5711
6740
|
}
|
|
5712
6741
|
async function runAnalysis(file, options, cmd) {
|
|
5713
6742
|
if (!fs8.existsSync(file)) {
|
|
5714
|
-
|
|
6743
|
+
failure(`File not found: ${file}`);
|
|
5715
6744
|
process.exit(1);
|
|
5716
6745
|
}
|
|
5717
6746
|
if (options.preset) {
|
|
5718
6747
|
const api2 = createApiClient();
|
|
5719
6748
|
const opt = await api2.analysis.getPreset(options.preset);
|
|
5720
6749
|
if (!opt.preset) {
|
|
5721
|
-
|
|
6750
|
+
failure(`Preset not found: ${options.preset}`);
|
|
5722
6751
|
process.exit(1);
|
|
5723
6752
|
}
|
|
5724
6753
|
const p = opt.preset;
|
|
@@ -5744,93 +6773,121 @@ async function runAnalysis(file, options, cmd) {
|
|
|
5744
6773
|
questions: parseCsv(options.questions),
|
|
5745
6774
|
segment: options.segment ?? null
|
|
5746
6775
|
};
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
const run = await api.analysis.runAnalysis(created.analysisId);
|
|
5756
|
-
console.log(chalk27.green(" done"));
|
|
5757
|
-
console.log(chalk27.dim(` runId: ${run.runId}`));
|
|
6776
|
+
const created = await withStatus(`Creating analysis "${name}"`, () => api.analysis.create(request));
|
|
6777
|
+
console.log(chalk25.dim(` analysisId: ${created.analysisId}`));
|
|
6778
|
+
await withStatus(
|
|
6779
|
+
`Uploading ${path7.basename(file)}`,
|
|
6780
|
+
() => api.analysis.uploadDataMultipart(created.analysisId, multipartFromFile(file))
|
|
6781
|
+
);
|
|
6782
|
+
const run = await withStatus("Queuing analysis run", () => api.analysis.runAnalysis(created.analysisId));
|
|
6783
|
+
console.log(chalk25.dim(` runId: ${run.runId}`));
|
|
5758
6784
|
console.log();
|
|
5759
|
-
await monitorRun(api, created.analysisId, run.runId,
|
|
6785
|
+
await monitorRun(api, created.analysisId, run.runId, cmd);
|
|
5760
6786
|
}
|
|
5761
|
-
async function monitorRun(api, analysisId, runId,
|
|
6787
|
+
async function monitorRun(api, analysisId, runId, cmd) {
|
|
5762
6788
|
const config = loadConfig();
|
|
5763
6789
|
const outputFormat = getOutputFormat15(cmd);
|
|
5764
|
-
const
|
|
5765
|
-
const
|
|
5766
|
-
const
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
6790
|
+
const human = outputFormat === "human";
|
|
6791
|
+
const status = new Status();
|
|
6792
|
+
const seenOutputs = /* @__PURE__ */ new Set();
|
|
6793
|
+
let caption = null;
|
|
6794
|
+
let lastReported = "";
|
|
6795
|
+
if (human) status.start();
|
|
6796
|
+
try {
|
|
6797
|
+
for (; ; ) {
|
|
6798
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
6799
|
+
let run = null;
|
|
6800
|
+
try {
|
|
6801
|
+
run = (await api.analysis.getRun(runId)).run;
|
|
6802
|
+
} catch {
|
|
6803
|
+
}
|
|
6804
|
+
if (!run) continue;
|
|
6805
|
+
try {
|
|
6806
|
+
for (const out of await api.analysis.getRunOutputs(analysisId, runId)) {
|
|
6807
|
+
const key = `${out.outputId}:${out.output}`;
|
|
6808
|
+
if (seenOutputs.has(key)) continue;
|
|
6809
|
+
seenOutputs.add(key);
|
|
6810
|
+
if (out.type === "event") {
|
|
6811
|
+
if (!human) process.stdout.write(JSON.stringify({ type: "event", ...safeParse(out.output) }) + "\n");
|
|
5783
6812
|
} else {
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
6813
|
+
caption = out.output;
|
|
6814
|
+
if (!human) {
|
|
6815
|
+
process.stdout.write(JSON.stringify({ type: "info", message: out.output }) + "\n");
|
|
6816
|
+
}
|
|
5787
6817
|
}
|
|
5788
6818
|
}
|
|
6819
|
+
} catch {
|
|
5789
6820
|
}
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
const
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
if (outputFormat === "human") {
|
|
5799
|
-
console.log(chalk27.green(`Analysis complete! (${durationStr})`));
|
|
5800
|
-
try {
|
|
5801
|
-
const nav = await api.analysis.getNavigation(analysisId);
|
|
5802
|
-
const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
|
|
5803
|
-
console.log(` Project: ${endpoint}${nav.labUrl}`);
|
|
5804
|
-
} catch {
|
|
5805
|
-
}
|
|
5806
|
-
} else {
|
|
5807
|
-
format({ status: "completed", runId, analysisId, duration }, { format: outputFormat });
|
|
5808
|
-
}
|
|
5809
|
-
} else if (run.state === "CANCELLED") {
|
|
5810
|
-
if (outputFormat === "human") {
|
|
5811
|
-
console.log(chalk27.yellow("Analysis cancelled."));
|
|
5812
|
-
} else {
|
|
5813
|
-
format({ status: "cancelled", runId, analysisId }, { format: outputFormat });
|
|
5814
|
-
}
|
|
6821
|
+
if (isTerminalState(run.state)) {
|
|
6822
|
+
status.stop();
|
|
6823
|
+
await reportTerminalRun(api, config, run, analysisId, runId, outputFormat);
|
|
6824
|
+
return;
|
|
6825
|
+
}
|
|
6826
|
+
const startedAt = run.startedAt ?? run.submittedAt ?? Date.now();
|
|
6827
|
+
if (human) {
|
|
6828
|
+
status.set(renderWatchBlock({ run, elapsedMs: Date.now() - startedAt, caption }));
|
|
5815
6829
|
} else {
|
|
5816
|
-
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
6830
|
+
const snapshot = JSON.stringify({
|
|
6831
|
+
type: "progress",
|
|
6832
|
+
state: run.state,
|
|
6833
|
+
phase: run.phase,
|
|
6834
|
+
overallFraction: run.overallFraction,
|
|
6835
|
+
progressDone: run.progressDone,
|
|
6836
|
+
progressTotal: run.progressTotal
|
|
6837
|
+
});
|
|
6838
|
+
if (snapshot !== lastReported) {
|
|
6839
|
+
lastReported = snapshot;
|
|
6840
|
+
process.stdout.write(snapshot + "\n");
|
|
5821
6841
|
}
|
|
5822
6842
|
}
|
|
5823
|
-
return;
|
|
5824
|
-
}
|
|
5825
|
-
if (outputFormat === "human" && i % 5 === 0) {
|
|
5826
|
-
const elapsed = Date.now() - startMs;
|
|
5827
|
-
const progress = run.progressTotal && run.progressTotal > 0 ? (run.progressDone ?? 0) / run.progressTotal : Math.min(elapsed / computationMs, 1);
|
|
5828
|
-
const pct = Math.round(progress * 100);
|
|
5829
|
-
const filled = Math.round(progress * 30);
|
|
5830
|
-
const bar = "\u2588".repeat(filled) + "\u2591".repeat(30 - filled);
|
|
5831
|
-
const stateLabel = run.state.toLowerCase().padEnd(11);
|
|
5832
|
-
process.stdout.write(`\r ${stateLabel} [${bar}] ${pct}% `);
|
|
5833
6843
|
}
|
|
6844
|
+
} finally {
|
|
6845
|
+
status.stop();
|
|
6846
|
+
}
|
|
6847
|
+
}
|
|
6848
|
+
function safeParse(text) {
|
|
6849
|
+
try {
|
|
6850
|
+
const parsed = JSON.parse(text);
|
|
6851
|
+
return parsed && typeof parsed === "object" ? parsed : { output: text };
|
|
6852
|
+
} catch {
|
|
6853
|
+
return { output: text };
|
|
6854
|
+
}
|
|
6855
|
+
}
|
|
6856
|
+
async function reportTerminalRun(api, config, run, analysisId, runId, outputFormat) {
|
|
6857
|
+
const baseStart = run.startedAt ?? run.submittedAt ?? Date.now();
|
|
6858
|
+
const durationMs = (run.endedAt ?? Date.now()) - baseStart;
|
|
6859
|
+
if (outputFormat !== "human") {
|
|
6860
|
+
format({
|
|
6861
|
+
status: run.state.toLowerCase(),
|
|
6862
|
+
runId,
|
|
6863
|
+
analysisId,
|
|
6864
|
+
durationMs,
|
|
6865
|
+
error: run.errorMessage
|
|
6866
|
+
}, { format: outputFormat });
|
|
6867
|
+
if (run.state !== "COMPLETED") process.exit(EXIT_FAILURE);
|
|
6868
|
+
return;
|
|
6869
|
+
}
|
|
6870
|
+
console.log();
|
|
6871
|
+
if (run.state === "COMPLETED") {
|
|
6872
|
+
success(`Analysis complete in ${formatDuration(durationMs)}.`);
|
|
6873
|
+
await printNotebookLink(api, config, analysisId);
|
|
6874
|
+
return;
|
|
6875
|
+
}
|
|
6876
|
+
if (run.state === "CANCELLED") {
|
|
6877
|
+
warn(`Analysis cancelled after ${formatDuration(durationMs)}.`);
|
|
6878
|
+
process.exit(EXIT_FAILURE);
|
|
6879
|
+
}
|
|
6880
|
+
failure(`Analysis failed after ${formatDuration(durationMs)}.`);
|
|
6881
|
+
if (run.errorMessage) hint(run.errorMessage);
|
|
6882
|
+
hint(`Queue a fresh run with 'diafunc analyze rerun ${analysisId}'.`);
|
|
6883
|
+
process.exit(EXIT_FAILURE);
|
|
6884
|
+
}
|
|
6885
|
+
async function printNotebookLink(api, config, analysisId) {
|
|
6886
|
+
try {
|
|
6887
|
+
const nav = await api.analysis.getNavigation(analysisId);
|
|
6888
|
+
const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
|
|
6889
|
+
detail(`${endpoint}${nav.labUrl}`);
|
|
6890
|
+
} catch {
|
|
5834
6891
|
}
|
|
5835
6892
|
}
|
|
5836
6893
|
async function listAnalyses(limit, cmd) {
|
|
@@ -5843,40 +6900,68 @@ async function listAnalyses(limit, cmd) {
|
|
|
5843
6900
|
visibility: a.visibility,
|
|
5844
6901
|
hours: a.hours,
|
|
5845
6902
|
budget: a.budget,
|
|
5846
|
-
targets:
|
|
5847
|
-
latestRunState: a.latestRunState
|
|
5848
|
-
createdAt: a.createdAt
|
|
6903
|
+
targets: a.targets,
|
|
6904
|
+
latestRunState: a.latestRunState,
|
|
6905
|
+
createdAt: a.createdAt
|
|
5849
6906
|
})), {
|
|
5850
6907
|
format: outputFormat,
|
|
5851
|
-
columns: [
|
|
5852
|
-
|
|
5853
|
-
}
|
|
5854
|
-
|
|
6908
|
+
columns: [
|
|
6909
|
+
{ key: "analysisId", kind: "id" },
|
|
6910
|
+
{ key: "name", maxWidth: 40 },
|
|
6911
|
+
{ key: "visibility" },
|
|
6912
|
+
{ key: "hours" },
|
|
6913
|
+
{ key: "budget" },
|
|
6914
|
+
{ key: "targets" },
|
|
6915
|
+
{ key: "latestRunState", header: "last run", kind: "state" },
|
|
6916
|
+
{ key: "createdAt", header: "created", kind: "date" }
|
|
6917
|
+
]
|
|
6918
|
+
});
|
|
6919
|
+
}
|
|
6920
|
+
async function getAnalysisDetails(analysisId, options, cmd) {
|
|
5855
6921
|
const outputFormat = getOutputFormat15(cmd);
|
|
5856
6922
|
const api = createApiClient();
|
|
5857
6923
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
5858
6924
|
if (!result.analysis) {
|
|
5859
|
-
|
|
6925
|
+
empty("analysis found");
|
|
5860
6926
|
return;
|
|
5861
6927
|
}
|
|
5862
|
-
|
|
6928
|
+
const analysis = outputFormat === "human" && !options.full ? { ...result.analysis, introduction: abbreviate(result.analysis.introduction) } : result.analysis;
|
|
6929
|
+
format(analysis, { format: outputFormat });
|
|
6930
|
+
if (outputFormat === "human" && !options.full && isLong(result.analysis.introduction)) {
|
|
6931
|
+
hint(`Introduction abbreviated \u2014 pass --full to print it whole.`);
|
|
6932
|
+
}
|
|
6933
|
+
}
|
|
6934
|
+
var INTRODUCTION_PREVIEW_LINES = 3;
|
|
6935
|
+
function isLong(text) {
|
|
6936
|
+
return Boolean(text && text.split("\n").length > INTRODUCTION_PREVIEW_LINES);
|
|
6937
|
+
}
|
|
6938
|
+
function abbreviate(text) {
|
|
6939
|
+
if (!isLong(text)) return text;
|
|
6940
|
+
const lines = text.split("\n").filter((l) => l.trim().length > 0);
|
|
6941
|
+
return `${lines.slice(0, INTRODUCTION_PREVIEW_LINES).join("\n")}
|
|
6942
|
+
\u2026`;
|
|
5863
6943
|
}
|
|
5864
6944
|
async function watchAnalysis(analysisId, cmd) {
|
|
5865
6945
|
const api = createApiClient();
|
|
5866
6946
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
5867
6947
|
if (!result.analysis) {
|
|
5868
|
-
|
|
6948
|
+
empty("analysis found");
|
|
5869
6949
|
return;
|
|
5870
6950
|
}
|
|
5871
6951
|
const recipe = result.analysis;
|
|
5872
6952
|
const runs = await api.analysis.getRunsForAnalysis(recipe.analysisId, 1);
|
|
5873
6953
|
if (runs.length === 0) {
|
|
5874
|
-
|
|
6954
|
+
empty("runs for this analysis");
|
|
5875
6955
|
return;
|
|
5876
6956
|
}
|
|
5877
6957
|
const latest = runs[0];
|
|
5878
6958
|
if (isTerminalState(latest.state)) {
|
|
5879
|
-
|
|
6959
|
+
if (latest.state === "COMPLETED") {
|
|
6960
|
+
success("The latest run has already completed.");
|
|
6961
|
+
} else {
|
|
6962
|
+
warn(`The latest run ended as ${latest.state}.`);
|
|
6963
|
+
if (latest.errorMessage) hint(latest.errorMessage);
|
|
6964
|
+
}
|
|
5880
6965
|
try {
|
|
5881
6966
|
const nav = await api.analysis.getNavigation(recipe.analysisId);
|
|
5882
6967
|
const config = loadConfig();
|
|
@@ -5887,21 +6972,21 @@ async function watchAnalysis(analysisId, cmd) {
|
|
|
5887
6972
|
return;
|
|
5888
6973
|
}
|
|
5889
6974
|
console.log(`Watching run ${latest.runId} for analysis ${recipe.analysisId} ...`);
|
|
5890
|
-
await monitorRun(api, recipe.analysisId, latest.runId,
|
|
6975
|
+
await monitorRun(api, recipe.analysisId, latest.runId, cmd);
|
|
5891
6976
|
}
|
|
5892
6977
|
async function rerunAnalysis(analysisId) {
|
|
5893
6978
|
const api = createApiClient();
|
|
5894
6979
|
const run = await api.analysis.runAnalysis(analysisId);
|
|
5895
|
-
|
|
5896
|
-
console.log(
|
|
6980
|
+
success(`Queued new run ${run.runId} for analysis ${analysisId}`);
|
|
6981
|
+
console.log(chalk25.dim(` State: ${run.state}`));
|
|
5897
6982
|
console.log();
|
|
5898
|
-
console.log(
|
|
6983
|
+
console.log(chalk25.dim("Track progress: diafunc analyze watch " + analysisId));
|
|
5899
6984
|
}
|
|
5900
6985
|
async function openAnalysis(analysisId) {
|
|
5901
6986
|
const api = createApiClient();
|
|
5902
6987
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
5903
6988
|
if (!result.analysis) {
|
|
5904
|
-
|
|
6989
|
+
empty("analysis found");
|
|
5905
6990
|
return;
|
|
5906
6991
|
}
|
|
5907
6992
|
const config = loadConfig();
|
|
@@ -5912,7 +6997,7 @@ async function openAnalysis(analysisId) {
|
|
|
5912
6997
|
console.log(`Opening ${url} ...`);
|
|
5913
6998
|
openUrl(url);
|
|
5914
6999
|
} catch {
|
|
5915
|
-
console.log(
|
|
7000
|
+
console.log(chalk25.dim("Notebook not yet provisioned \u2014 run the analysis first."));
|
|
5916
7001
|
}
|
|
5917
7002
|
}
|
|
5918
7003
|
async function createRecipe(options, cmd) {
|
|
@@ -5936,48 +7021,48 @@ async function createRecipe(options, cmd) {
|
|
|
5936
7021
|
async function deleteAnalysis(analysisId) {
|
|
5937
7022
|
const api = createApiClient();
|
|
5938
7023
|
await api.analysis.delete(analysisId);
|
|
5939
|
-
|
|
7024
|
+
success(`Deleted analysis ${analysisId}`);
|
|
5940
7025
|
}
|
|
5941
7026
|
async function patchAndPrint(analysisId, value, handler, successLabel, cmd) {
|
|
5942
7027
|
const outputFormat = getOutputFormat15(cmd);
|
|
5943
7028
|
const api = createApiClient();
|
|
5944
7029
|
const updated = await handler(api, analysisId, value);
|
|
5945
7030
|
if (outputFormat === "human") {
|
|
5946
|
-
|
|
7031
|
+
success(`${successLabel} updated for analysis ${analysisId}`);
|
|
5947
7032
|
} else {
|
|
5948
7033
|
format(updated, { format: outputFormat });
|
|
5949
7034
|
}
|
|
5950
7035
|
}
|
|
5951
7036
|
async function uploadData(analysisId, file, options) {
|
|
5952
7037
|
const api = createApiClient();
|
|
5953
|
-
|
|
7038
|
+
const dataUrl = options.url;
|
|
7039
|
+
if (dataUrl) {
|
|
5954
7040
|
if (file) {
|
|
5955
|
-
|
|
5956
|
-
process.exit(1);
|
|
7041
|
+
usageError("Provide either a file or --url, not both.", "Drop one of the two and run it again.");
|
|
5957
7042
|
}
|
|
5958
|
-
|
|
5959
|
-
await api.analysis.uploadDataUrl(analysisId, { dataUrl: options.url });
|
|
5960
|
-
console.log(chalk27.green(" done"));
|
|
7043
|
+
await withStatus(`Uploading from ${dataUrl}`, () => api.analysis.uploadDataUrl(analysisId, { dataUrl }));
|
|
5961
7044
|
return;
|
|
5962
7045
|
}
|
|
5963
7046
|
if (!file) {
|
|
5964
|
-
|
|
5965
|
-
|
|
7047
|
+
usageError(
|
|
7048
|
+
"Provide a file path or --url <URL>.",
|
|
7049
|
+
`For example: diafunc analyze upload ${analysisId} data.csv`
|
|
7050
|
+
);
|
|
5966
7051
|
}
|
|
5967
7052
|
if (!fs8.existsSync(file)) {
|
|
5968
|
-
|
|
5969
|
-
process.exit(1);
|
|
7053
|
+
throw new CliError(`File not found: ${file}`, { exitCode: EXIT_USAGE });
|
|
5970
7054
|
}
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
7055
|
+
await withStatus(
|
|
7056
|
+
`Uploading ${path7.basename(file)}`,
|
|
7057
|
+
() => api.analysis.uploadDataMultipart(analysisId, multipartFromFile(file))
|
|
7058
|
+
);
|
|
5974
7059
|
}
|
|
5975
7060
|
async function listColumns(analysisId, cmd) {
|
|
5976
7061
|
const outputFormat = getOutputFormat15(cmd);
|
|
5977
7062
|
const api = createApiClient();
|
|
5978
7063
|
const columns = await api.analysis.getColumns(analysisId);
|
|
5979
7064
|
if (columns.length === 0) {
|
|
5980
|
-
|
|
7065
|
+
empty("columns yet \u2014 upload data first");
|
|
5981
7066
|
return;
|
|
5982
7067
|
}
|
|
5983
7068
|
format(columns, { format: outputFormat, columns: ["name", "valueType"] });
|
|
@@ -5995,7 +7080,13 @@ async function listRuns(analysisId, count, cmd) {
|
|
|
5995
7080
|
evaluationId: r.evaluationId ?? "\u2014"
|
|
5996
7081
|
})), {
|
|
5997
7082
|
format: outputFormat,
|
|
5998
|
-
columns: [
|
|
7083
|
+
columns: [
|
|
7084
|
+
{ key: "runId", kind: "id" },
|
|
7085
|
+
{ key: "state", kind: "state" },
|
|
7086
|
+
{ key: "phase" },
|
|
7087
|
+
{ key: "submittedAt", header: "submitted", kind: "date" },
|
|
7088
|
+
{ key: "endedAt", header: "ended", kind: "date" }
|
|
7089
|
+
]
|
|
5999
7090
|
});
|
|
6000
7091
|
}
|
|
6001
7092
|
async function cancelRun(runId, cmd) {
|
|
@@ -6003,7 +7094,7 @@ async function cancelRun(runId, cmd) {
|
|
|
6003
7094
|
const api = createApiClient();
|
|
6004
7095
|
const run = await api.analysis.cancelRun(runId);
|
|
6005
7096
|
if (outputFormat === "human") {
|
|
6006
|
-
|
|
7097
|
+
success(`Run ${run.runId} state: ${run.state}`);
|
|
6007
7098
|
} else {
|
|
6008
7099
|
format(run, { format: outputFormat });
|
|
6009
7100
|
}
|
|
@@ -6030,7 +7121,7 @@ async function getPreset(presetId, cmd) {
|
|
|
6030
7121
|
const api = createApiClient();
|
|
6031
7122
|
const opt = await api.analysis.getPreset(presetId);
|
|
6032
7123
|
if (!opt.preset) {
|
|
6033
|
-
console.log(
|
|
7124
|
+
console.log(chalk25.dim("Preset not found."));
|
|
6034
7125
|
return;
|
|
6035
7126
|
}
|
|
6036
7127
|
format(opt.preset, { format: outputFormat });
|
|
@@ -6053,7 +7144,7 @@ async function savePreset(options, cmd) {
|
|
|
6053
7144
|
async function deletePreset(presetId) {
|
|
6054
7145
|
const api = createApiClient();
|
|
6055
7146
|
await api.analysis.deletePreset(presetId);
|
|
6056
|
-
|
|
7147
|
+
success(`Deleted preset ${presetId}`);
|
|
6057
7148
|
}
|
|
6058
7149
|
async function listTriggers(analysisId, cmd) {
|
|
6059
7150
|
const outputFormat = getOutputFormat15(cmd);
|
|
@@ -6074,7 +7165,7 @@ async function createTrigger(analysisId, kind, schedule, cmd) {
|
|
|
6074
7165
|
const outputFormat = getOutputFormat15(cmd);
|
|
6075
7166
|
const upper = kind.toUpperCase();
|
|
6076
7167
|
if (upper !== "ONCE" && upper !== "CRON") {
|
|
6077
|
-
|
|
7168
|
+
failure(`Invalid kind "${kind}" \u2014 must be ONCE or CRON.`);
|
|
6078
7169
|
process.exit(1);
|
|
6079
7170
|
}
|
|
6080
7171
|
const api = createApiClient();
|
|
@@ -6087,7 +7178,7 @@ async function createTrigger(analysisId, kind, schedule, cmd) {
|
|
|
6087
7178
|
async function deleteTrigger(triggerId) {
|
|
6088
7179
|
const api = createApiClient();
|
|
6089
7180
|
await api.analysis.deleteTrigger(triggerId);
|
|
6090
|
-
|
|
7181
|
+
success(`Deleted trigger ${triggerId}`);
|
|
6091
7182
|
}
|
|
6092
7183
|
async function updateTriggerCmd(triggerId, options, cmd) {
|
|
6093
7184
|
const outputFormat = getOutputFormat15(cmd);
|
|
@@ -6095,13 +7186,13 @@ async function updateTriggerCmd(triggerId, options, cmd) {
|
|
|
6095
7186
|
if (options.active !== void 0) {
|
|
6096
7187
|
const lc = options.active.toLowerCase();
|
|
6097
7188
|
if (lc !== "true" && lc !== "false") {
|
|
6098
|
-
|
|
7189
|
+
failure(`Invalid --active value "${options.active}" \u2014 must be true or false.`);
|
|
6099
7190
|
process.exit(1);
|
|
6100
7191
|
}
|
|
6101
7192
|
activeFlag = lc === "true";
|
|
6102
7193
|
}
|
|
6103
7194
|
if (activeFlag === void 0 && !options.schedule) {
|
|
6104
|
-
|
|
7195
|
+
failure("Pass at least one of --active or --schedule.");
|
|
6105
7196
|
process.exit(1);
|
|
6106
7197
|
}
|
|
6107
7198
|
const api = createApiClient();
|
|
@@ -6131,9 +7222,9 @@ function registerAnalyzeCommand(program) {
|
|
|
6131
7222
|
handleError(error);
|
|
6132
7223
|
}
|
|
6133
7224
|
});
|
|
6134
|
-
analyze.command("get").description("Show details of an analysis").argument("[id]", "Analysis ID (defaults to the most recent)").action(async (id,
|
|
7225
|
+
analyze.command("get").description("Show details of an analysis").argument("[id]", "Analysis ID (defaults to the most recent)").option("--full", "Print the introduction in full instead of abbreviating it").action(async (id, options, cmd) => {
|
|
6135
7226
|
try {
|
|
6136
|
-
await getAnalysisDetails(id, cmd);
|
|
7227
|
+
await getAnalysisDetails(id, options, cmd);
|
|
6137
7228
|
} catch (error) {
|
|
6138
7229
|
handleError(error);
|
|
6139
7230
|
}
|
|
@@ -6385,7 +7476,7 @@ function registerAnalyzeCommand(program) {
|
|
|
6385
7476
|
}
|
|
6386
7477
|
|
|
6387
7478
|
// src/commands/data-sources/index.ts
|
|
6388
|
-
import
|
|
7479
|
+
import chalk26 from "chalk";
|
|
6389
7480
|
function getOutputFormat16(cmd) {
|
|
6390
7481
|
const config = loadConfig();
|
|
6391
7482
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -6474,17 +7565,36 @@ function runTableRow(run) {
|
|
|
6474
7565
|
triggeredBy: run.triggeredBy ?? "\u2014"
|
|
6475
7566
|
};
|
|
6476
7567
|
}
|
|
7568
|
+
function resolveProjectId(explicit, cmd) {
|
|
7569
|
+
const globals = cmd.optsWithGlobals();
|
|
7570
|
+
const resolved = explicit ?? globals.project ?? loadConfig().defaults.project;
|
|
7571
|
+
if (!resolved) {
|
|
7572
|
+
usageError(
|
|
7573
|
+
"This command needs a project.",
|
|
7574
|
+
`Pass --project <id>, or set a default with 'diafunc config set defaults.project <id>'.`
|
|
7575
|
+
);
|
|
7576
|
+
}
|
|
7577
|
+
return resolved;
|
|
7578
|
+
}
|
|
6477
7579
|
async function listDataSources(projectId, cmd) {
|
|
6478
7580
|
const outputFormat = getOutputFormat16(cmd);
|
|
6479
7581
|
const api = createApiClient();
|
|
6480
7582
|
const sources = await api.storage.listDataSources(projectId);
|
|
6481
7583
|
if (outputFormat === "human" && sources.length === 0) {
|
|
6482
|
-
|
|
7584
|
+
empty("data sources");
|
|
6483
7585
|
return;
|
|
6484
7586
|
}
|
|
6485
7587
|
format(sources.map(dataSourceTableRow), {
|
|
6486
7588
|
format: outputFormat,
|
|
6487
|
-
columns: [
|
|
7589
|
+
columns: [
|
|
7590
|
+
{ key: "id", kind: "id" },
|
|
7591
|
+
{ key: "name" },
|
|
7592
|
+
{ key: "type" },
|
|
7593
|
+
{ key: "target" },
|
|
7594
|
+
{ key: "schedule" },
|
|
7595
|
+
{ key: "lastStatus", header: "last status", kind: "state" },
|
|
7596
|
+
{ key: "lastRefreshAt", header: "last refresh", kind: "date" }
|
|
7597
|
+
]
|
|
6488
7598
|
});
|
|
6489
7599
|
}
|
|
6490
7600
|
async function getDataSource(id, cmd) {
|
|
@@ -6502,16 +7612,26 @@ async function showDashboard(projectId, cmd) {
|
|
|
6502
7612
|
return;
|
|
6503
7613
|
}
|
|
6504
7614
|
const r = dashboard.rollup;
|
|
6505
|
-
let line =
|
|
7615
|
+
let line = chalk26.bold(`DataSources in ${projectId}: `) + `${r.totalSources} total, ${r.scheduledSources} scheduled, ${r.sourcesWithRecentFailure} failing recently`;
|
|
6506
7616
|
if (r.lastActivityAt) line += `, last activity ${r.lastActivityAt}`;
|
|
6507
7617
|
console.log(line);
|
|
6508
7618
|
if (dashboard.sources.length === 0) {
|
|
6509
|
-
|
|
7619
|
+
empty("data sources");
|
|
6510
7620
|
return;
|
|
6511
7621
|
}
|
|
6512
7622
|
format(dashboard.sources.map(dashboardTableRow), {
|
|
6513
7623
|
format: outputFormat,
|
|
6514
|
-
columns: [
|
|
7624
|
+
columns: [
|
|
7625
|
+
{ key: "id", kind: "id" },
|
|
7626
|
+
{ key: "name" },
|
|
7627
|
+
{ key: "type" },
|
|
7628
|
+
{ key: "schedule" },
|
|
7629
|
+
{ key: "lastStatus", header: "last status", kind: "state" },
|
|
7630
|
+
{ key: "lastRunAt", header: "last run", kind: "date" },
|
|
7631
|
+
{ key: "nextScheduledAt", header: "next run", kind: "date" },
|
|
7632
|
+
{ key: "recentFailures", header: "failures", kind: "number" },
|
|
7633
|
+
{ key: "lastTransferred", header: "transferred" }
|
|
7634
|
+
]
|
|
6515
7635
|
});
|
|
6516
7636
|
}
|
|
6517
7637
|
async function createDataSource(options, cmd) {
|
|
@@ -6529,9 +7649,9 @@ async function createDataSource(options, cmd) {
|
|
|
6529
7649
|
};
|
|
6530
7650
|
const ds = await api.storage.createDataSource(request);
|
|
6531
7651
|
if (outputFormat === "human") {
|
|
6532
|
-
|
|
6533
|
-
console.log(
|
|
6534
|
-
if (ds.lastRunError) console.log(
|
|
7652
|
+
success(`Created data source ${ds.id}`);
|
|
7653
|
+
console.log(chalk26.dim(` Last run: ${ds.lastRunStatus ?? "\u2014"}`));
|
|
7654
|
+
if (ds.lastRunError) console.log(chalk26.dim(` Error: ${ds.lastRunError}`));
|
|
6535
7655
|
} else {
|
|
6536
7656
|
format(ds, { format: outputFormat });
|
|
6537
7657
|
}
|
|
@@ -6561,7 +7681,7 @@ async function updateDataSource(id, options, cmd) {
|
|
|
6561
7681
|
const api = createApiClient();
|
|
6562
7682
|
const ds = await api.storage.updateDataSource(id, request);
|
|
6563
7683
|
if (outputFormat === "human") {
|
|
6564
|
-
|
|
7684
|
+
success(`Updated data source ${ds.id}`);
|
|
6565
7685
|
} else {
|
|
6566
7686
|
format(ds, { format: outputFormat });
|
|
6567
7687
|
}
|
|
@@ -6569,15 +7689,15 @@ async function updateDataSource(id, options, cmd) {
|
|
|
6569
7689
|
async function deleteDataSource(id) {
|
|
6570
7690
|
const api = createApiClient();
|
|
6571
7691
|
await api.storage.deleteDataSource(id);
|
|
6572
|
-
|
|
7692
|
+
success(`Deleted data source ${id}`);
|
|
6573
7693
|
}
|
|
6574
7694
|
async function refreshDataSource(id, cmd) {
|
|
6575
7695
|
const outputFormat = getOutputFormat16(cmd);
|
|
6576
7696
|
const api = createApiClient();
|
|
6577
7697
|
const run = await api.storage.refreshDataSource(id);
|
|
6578
7698
|
if (outputFormat === "human") {
|
|
6579
|
-
|
|
6580
|
-
if (run.errorMessage) console.log(
|
|
7699
|
+
success(`Refresh queued \u2014 run ${run.runId}, status ${run.status}`);
|
|
7700
|
+
if (run.errorMessage) console.log(chalk26.red(` Error: ${run.errorMessage}`));
|
|
6581
7701
|
} else {
|
|
6582
7702
|
format(run, { format: outputFormat });
|
|
6583
7703
|
}
|
|
@@ -6587,12 +7707,21 @@ async function listRuns2(id, limit, cmd) {
|
|
|
6587
7707
|
const api = createApiClient();
|
|
6588
7708
|
const runs = await api.storage.listDataSourceRuns(id, limit);
|
|
6589
7709
|
if (outputFormat === "human" && runs.length === 0) {
|
|
6590
|
-
|
|
7710
|
+
empty("runs yet");
|
|
6591
7711
|
return;
|
|
6592
7712
|
}
|
|
6593
7713
|
format(runs.map(runTableRow), {
|
|
6594
7714
|
format: outputFormat,
|
|
6595
|
-
columns: [
|
|
7715
|
+
columns: [
|
|
7716
|
+
{ key: "runId", kind: "id" },
|
|
7717
|
+
{ key: "status", kind: "state" },
|
|
7718
|
+
{ key: "startedAt", header: "started", kind: "date" },
|
|
7719
|
+
{ key: "finishedAt", header: "finished", kind: "date" },
|
|
7720
|
+
{ key: "rows", kind: "number" },
|
|
7721
|
+
{ key: "transferred" },
|
|
7722
|
+
{ key: "credits" },
|
|
7723
|
+
{ key: "triggeredBy", header: "triggered by" }
|
|
7724
|
+
]
|
|
6596
7725
|
});
|
|
6597
7726
|
}
|
|
6598
7727
|
async function getRun(id, runId, cmd) {
|
|
@@ -6607,7 +7736,7 @@ async function listConnectorTypes(cmd) {
|
|
|
6607
7736
|
const types = await api.storage.listDataSourceConnectorTypes();
|
|
6608
7737
|
if (outputFormat === "human") {
|
|
6609
7738
|
if (types.length === 0) {
|
|
6610
|
-
|
|
7739
|
+
empty("connector types registered");
|
|
6611
7740
|
return;
|
|
6612
7741
|
}
|
|
6613
7742
|
for (const t of types) console.log(t);
|
|
@@ -6617,9 +7746,13 @@ async function listConnectorTypes(cmd) {
|
|
|
6617
7746
|
}
|
|
6618
7747
|
function registerDataSourcesCommands(program) {
|
|
6619
7748
|
const dataSources = program.command("data-sources").description("Manage scheduled DataSource imports (Google Sheets, S3 URL, JDBC)");
|
|
6620
|
-
dataSources.command("list").description("List data sources
|
|
7749
|
+
dataSources.command("list").description("List the data sources of one project").option("--project <id>", "Project ID; defaults to defaults.project from the config").addHelpText("after", `
|
|
7750
|
+
Examples:
|
|
7751
|
+
$ diafunc data-sources list --project <id>
|
|
7752
|
+
$ diafunc config set defaults.project <id> then --project can be omitted
|
|
7753
|
+
`).action(async (options, cmd) => {
|
|
6621
7754
|
try {
|
|
6622
|
-
await listDataSources(options.
|
|
7755
|
+
await listDataSources(resolveProjectId(options.project, cmd), cmd);
|
|
6623
7756
|
} catch (error) {
|
|
6624
7757
|
handleError(error);
|
|
6625
7758
|
}
|
|
@@ -6691,7 +7824,7 @@ function registerDataSourcesCommands(program) {
|
|
|
6691
7824
|
}
|
|
6692
7825
|
|
|
6693
7826
|
// src/commands/table-exporters/index.ts
|
|
6694
|
-
import
|
|
7827
|
+
import chalk27 from "chalk";
|
|
6695
7828
|
function getOutputFormat17(cmd) {
|
|
6696
7829
|
const config = loadConfig();
|
|
6697
7830
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -6722,7 +7855,7 @@ function registerTableExportersCommands(program) {
|
|
|
6722
7855
|
format: outputFormat,
|
|
6723
7856
|
columns: ["id", "name", "format", "extension", "mimeType", "priority", "function", "createdBy"]
|
|
6724
7857
|
});
|
|
6725
|
-
console.log(
|
|
7858
|
+
console.log(chalk27.dim(`${list.length} exporter(s)`));
|
|
6726
7859
|
} catch (error) {
|
|
6727
7860
|
handleError(error);
|
|
6728
7861
|
}
|
|
@@ -6734,7 +7867,7 @@ function registerTableExportersCommands(program) {
|
|
|
6734
7867
|
const list = await api.storage.listUserDefinedExporters();
|
|
6735
7868
|
const exporter = list.find((e) => e.id === id);
|
|
6736
7869
|
if (!exporter) {
|
|
6737
|
-
|
|
7870
|
+
failure(`No exporter with id="${id}".`);
|
|
6738
7871
|
process.exit(1);
|
|
6739
7872
|
}
|
|
6740
7873
|
format(exporter, { format: outputFormat });
|
|
@@ -6763,7 +7896,7 @@ function registerTableExportersCommands(program) {
|
|
|
6763
7896
|
format(created, { format: outputFormat });
|
|
6764
7897
|
return;
|
|
6765
7898
|
}
|
|
6766
|
-
|
|
7899
|
+
success(`Registered exporter "${created.name}" (id=${created.id}, format=${created.format})`);
|
|
6767
7900
|
} catch (error) {
|
|
6768
7901
|
handleError(error);
|
|
6769
7902
|
}
|
|
@@ -6772,7 +7905,7 @@ function registerTableExportersCommands(program) {
|
|
|
6772
7905
|
try {
|
|
6773
7906
|
const api = createApiClient();
|
|
6774
7907
|
await api.storage.deleteUserDefinedExporter(id);
|
|
6775
|
-
|
|
7908
|
+
success(`Deleted exporter id=${id}`);
|
|
6776
7909
|
} catch (error) {
|
|
6777
7910
|
handleError(error);
|
|
6778
7911
|
}
|
|
@@ -6780,14 +7913,14 @@ function registerTableExportersCommands(program) {
|
|
|
6780
7913
|
}
|
|
6781
7914
|
|
|
6782
7915
|
// src/commands/skeleton/index.ts
|
|
6783
|
-
import
|
|
7916
|
+
import chalk28 from "chalk";
|
|
6784
7917
|
import * as fs9 from "fs";
|
|
6785
7918
|
function getOutputFormat18(cmd) {
|
|
6786
7919
|
const config = loadConfig();
|
|
6787
7920
|
const globalOpts = cmd.optsWithGlobals();
|
|
6788
7921
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
6789
7922
|
}
|
|
6790
|
-
function
|
|
7923
|
+
function resolveProjectId2(localOption, cmd) {
|
|
6791
7924
|
if (localOption) return localOption;
|
|
6792
7925
|
const globalOpts = cmd.optsWithGlobals();
|
|
6793
7926
|
if (globalOpts.project) return globalOpts.project;
|
|
@@ -6833,7 +7966,7 @@ function skeletonTableRow(s) {
|
|
|
6833
7966
|
}
|
|
6834
7967
|
async function createSkeleton(options, cmd) {
|
|
6835
7968
|
const outputFormat = getOutputFormat18(cmd);
|
|
6836
|
-
const projectId =
|
|
7969
|
+
const projectId = resolveProjectId2(options.project, cmd);
|
|
6837
7970
|
const template = resolveTemplate(options.template);
|
|
6838
7971
|
const weight = parseWeight(options.weight);
|
|
6839
7972
|
const request = {
|
|
@@ -6846,22 +7979,22 @@ async function createSkeleton(options, cmd) {
|
|
|
6846
7979
|
const api = createApiClient();
|
|
6847
7980
|
const skeleton = await api.storage.createSkeleton(request);
|
|
6848
7981
|
if (outputFormat === "human") {
|
|
6849
|
-
|
|
6850
|
-
console.log(
|
|
6851
|
-
console.log(
|
|
6852
|
-
console.log(
|
|
6853
|
-
console.log(
|
|
7982
|
+
success(`Created skeleton ${skeleton.id}`);
|
|
7983
|
+
console.log(chalk28.dim(` name: ${skeleton.name}`));
|
|
7984
|
+
console.log(chalk28.dim(` template: ${skeleton.template}`));
|
|
7985
|
+
console.log(chalk28.dim(` paramCount: ${skeleton.paramCount}`));
|
|
7986
|
+
console.log(chalk28.dim(` weight: ${skeleton.weight}`));
|
|
6854
7987
|
} else {
|
|
6855
7988
|
format(skeleton, { format: outputFormat });
|
|
6856
7989
|
}
|
|
6857
7990
|
}
|
|
6858
7991
|
async function listSkeletons(localProject, cmd) {
|
|
6859
7992
|
const outputFormat = getOutputFormat18(cmd);
|
|
6860
|
-
const projectId =
|
|
7993
|
+
const projectId = resolveProjectId2(localProject, cmd);
|
|
6861
7994
|
const api = createApiClient();
|
|
6862
7995
|
const skeletons = await api.storage.listSkeletons(projectId);
|
|
6863
7996
|
if (outputFormat === "human" && skeletons.length === 0) {
|
|
6864
|
-
|
|
7997
|
+
empty(`skeletons in project ${projectId}`);
|
|
6865
7998
|
return;
|
|
6866
7999
|
}
|
|
6867
8000
|
format(skeletons.map(skeletonTableRow), {
|
|
@@ -6888,11 +8021,11 @@ async function updateSkeleton(id, options, cmd) {
|
|
|
6888
8021
|
const api = createApiClient();
|
|
6889
8022
|
const skeleton = await api.storage.updateSkeleton(id, request);
|
|
6890
8023
|
if (outputFormat === "human") {
|
|
6891
|
-
|
|
6892
|
-
console.log(
|
|
6893
|
-
console.log(
|
|
6894
|
-
console.log(
|
|
6895
|
-
console.log(
|
|
8024
|
+
success(`Updated skeleton ${skeleton.id}`);
|
|
8025
|
+
console.log(chalk28.dim(` name: ${skeleton.name}`));
|
|
8026
|
+
console.log(chalk28.dim(` template: ${skeleton.template}`));
|
|
8027
|
+
console.log(chalk28.dim(` paramCount: ${skeleton.paramCount}`));
|
|
8028
|
+
console.log(chalk28.dim(` weight: ${skeleton.weight}`));
|
|
6896
8029
|
} else {
|
|
6897
8030
|
format(skeleton, { format: outputFormat });
|
|
6898
8031
|
}
|
|
@@ -6900,10 +8033,15 @@ async function updateSkeleton(id, options, cmd) {
|
|
|
6900
8033
|
async function deleteSkeleton(id) {
|
|
6901
8034
|
const api = createApiClient();
|
|
6902
8035
|
await api.storage.deleteSkeleton(id);
|
|
6903
|
-
|
|
8036
|
+
success(`Deleted skeleton ${id}`);
|
|
6904
8037
|
}
|
|
6905
8038
|
function registerSkeletonCommands(program) {
|
|
6906
|
-
const skeleton = program.command("skeleton").description("Manage user-provided skeleton templates (project-scoped, capped at 100/project)")
|
|
8039
|
+
const skeleton = program.command("skeleton").description("Manage user-provided skeleton templates (project-scoped, capped at 100/project)").addHelpText("after", `
|
|
8040
|
+
Examples:
|
|
8041
|
+
$ diafunc skeleton list --project <id>
|
|
8042
|
+
$ diafunc skeleton create --project <id> --name linear --template 'a*x+b'
|
|
8043
|
+
`);
|
|
8044
|
+
;
|
|
6907
8045
|
skeleton.command("create").description("Create a skeleton. Parse errors from the engine are surfaced as stderr.").requiredOption("--name <name>", "Display name").requiredOption(
|
|
6908
8046
|
"--template <expr>",
|
|
6909
8047
|
'Skeleton template expression (e.g. "?*x+?"). Use "@file.txt" to read from a file; "@@\u2026" escapes a literal leading @.'
|
|
@@ -7204,7 +8342,7 @@ function registerCompletionCommand(program) {
|
|
|
7204
8342
|
}
|
|
7205
8343
|
|
|
7206
8344
|
// src/commands/whoami/index.ts
|
|
7207
|
-
import
|
|
8345
|
+
import chalk29 from "chalk";
|
|
7208
8346
|
function registerWhoamiCommand(program) {
|
|
7209
8347
|
program.command("whoami").description("Show the currently authenticated user").action(async (_options, cmd) => {
|
|
7210
8348
|
try {
|
|
@@ -7214,8 +8352,8 @@ function registerWhoamiCommand(program) {
|
|
|
7214
8352
|
const api = createApiClient();
|
|
7215
8353
|
const user = await api.admin.getMyUser();
|
|
7216
8354
|
if (outputFormat === "human") {
|
|
7217
|
-
console.log(
|
|
7218
|
-
console.log(
|
|
8355
|
+
console.log(chalk29.bold(user.name) + chalk29.dim(` <${user.email}>`));
|
|
8356
|
+
console.log(chalk29.dim(` Role: ${user.role} \xB7 Remaining credits: ${user.remainingCredits} \xB7 Profile: ${config.currentProfile}`));
|
|
7219
8357
|
} else {
|
|
7220
8358
|
format(user, { format: outputFormat });
|
|
7221
8359
|
}
|
|
@@ -7226,33 +8364,45 @@ function registerWhoamiCommand(program) {
|
|
|
7226
8364
|
}
|
|
7227
8365
|
|
|
7228
8366
|
// src/commands/utilization/index.ts
|
|
7229
|
-
import
|
|
8367
|
+
import chalk30 from "chalk";
|
|
7230
8368
|
function getOutputFormat19(cmd) {
|
|
7231
8369
|
const config = loadConfig();
|
|
7232
8370
|
const globalOpts = cmd.optsWithGlobals();
|
|
7233
8371
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
7234
8372
|
}
|
|
7235
|
-
function
|
|
7236
|
-
|
|
7237
|
-
|
|
7238
|
-
console.log(chalk32.bold(label) + " " + chalk32.dim(when));
|
|
7239
|
-
} else {
|
|
7240
|
-
console.log(chalk32.bold(when));
|
|
8373
|
+
function windowLabel(u) {
|
|
8374
|
+
if (u.cycleStart) {
|
|
8375
|
+
return u.cycleEnd ? `billing cycle ${u.cycleStart} to ${u.cycleEnd}` : `billing cycle from ${u.cycleStart}`;
|
|
7241
8376
|
}
|
|
8377
|
+
if (u.day !== null && u.day !== void 0) {
|
|
8378
|
+
return `${u.year}-${String(u.month).padStart(2, "0")}-${String(u.day).padStart(2, "0")}`;
|
|
8379
|
+
}
|
|
8380
|
+
return `billing cycle ${u.year}-${String(u.month).padStart(2, "0")}`;
|
|
8381
|
+
}
|
|
8382
|
+
function printUtilizationHuman(u, label) {
|
|
8383
|
+
const when = windowLabel(u);
|
|
8384
|
+
console.log(label ? chalk30.bold(label) + " " + chalk30.dim(when) : chalk30.bold(when));
|
|
7242
8385
|
if (u.types.length === 0) {
|
|
7243
|
-
console.log(
|
|
8386
|
+
console.log(chalk30.dim(" (no usage)"));
|
|
7244
8387
|
return;
|
|
7245
8388
|
}
|
|
7246
|
-
|
|
7247
|
-
|
|
7248
|
-
|
|
7249
|
-
)
|
|
8389
|
+
const types = [...u.types].sort((a, b) => b.credits - a.credits);
|
|
8390
|
+
const width = Math.max(...types.map((t) => t.type.length));
|
|
8391
|
+
for (const t of types) {
|
|
8392
|
+
const line = ` ${t.type.padEnd(width)} ${formatNumber(t.quantity).padStart(12)} ${chalk30.dim("credits")} ${t.credits.toFixed(2).padStart(10)}`;
|
|
8393
|
+
console.log(t.credits === 0 ? chalk30.dim(line) : line);
|
|
7250
8394
|
}
|
|
7251
8395
|
const total = u.totalCredits ?? u.types.reduce((s, t) => s + t.credits, 0);
|
|
7252
|
-
console.log(
|
|
8396
|
+
console.log(chalk30.bold(` ${"Total".padEnd(width)} ${" ".repeat(12)} ${chalk30.dim("credits")} ${total.toFixed(2).padStart(10)}`));
|
|
7253
8397
|
}
|
|
7254
8398
|
function registerUtilizationCommand(program) {
|
|
7255
|
-
const util = program.command("utilization").description("Show credit utilization")
|
|
8399
|
+
const util = program.command("utilization").description("Show credit utilization for the current billing cycle").addHelpText("after", `
|
|
8400
|
+
The billing cycle starts on your subscription anniversary, not on the first of the month.
|
|
8401
|
+
|
|
8402
|
+
Examples:
|
|
8403
|
+
$ diafunc utilization this cycle, by consumption type
|
|
8404
|
+
$ diafunc utilization history day by day across the cycle
|
|
8405
|
+
`);
|
|
7256
8406
|
util.command("actual", { isDefault: true }).description("Show current utilization (default subcommand)").action(async (_options, cmd) => {
|
|
7257
8407
|
try {
|
|
7258
8408
|
const outputFormat = getOutputFormat19(cmd);
|
|
@@ -7274,7 +8424,7 @@ function registerUtilizationCommand(program) {
|
|
|
7274
8424
|
const history = await api.admin.getUtilizationHistory();
|
|
7275
8425
|
if (outputFormat === "human") {
|
|
7276
8426
|
if (history.length === 0) {
|
|
7277
|
-
|
|
8427
|
+
empty("usage recorded");
|
|
7278
8428
|
return;
|
|
7279
8429
|
}
|
|
7280
8430
|
for (const u of history) {
|
|
@@ -7291,7 +8441,6 @@ function registerUtilizationCommand(program) {
|
|
|
7291
8441
|
}
|
|
7292
8442
|
|
|
7293
8443
|
// src/commands/entity-branch/index.ts
|
|
7294
|
-
import chalk33 from "chalk";
|
|
7295
8444
|
function getOutputFormat20(cmd) {
|
|
7296
8445
|
const config = loadConfig();
|
|
7297
8446
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -7335,7 +8484,7 @@ function registerEntityBranchCommands(program) {
|
|
|
7335
8484
|
sourceEntityBranch: resolved.entityBranch,
|
|
7336
8485
|
targetEntityBranch: targetBranch
|
|
7337
8486
|
});
|
|
7338
|
-
|
|
8487
|
+
success(`Entity branch "${targetBranch}" created from "${resolved.entityBranch}".`);
|
|
7339
8488
|
} catch (error) {
|
|
7340
8489
|
handleError(error);
|
|
7341
8490
|
}
|
|
@@ -7343,18 +8492,37 @@ function registerEntityBranchCommands(program) {
|
|
|
7343
8492
|
}
|
|
7344
8493
|
|
|
7345
8494
|
// src/commands/subscription/index.ts
|
|
8495
|
+
var BILLING_INTERNALS = /* @__PURE__ */ new Set([
|
|
8496
|
+
"stripeSubscriptionId",
|
|
8497
|
+
"stripePriceId",
|
|
8498
|
+
"stripeCustomerId",
|
|
8499
|
+
"dunningStage",
|
|
8500
|
+
"dunningStartedAt",
|
|
8501
|
+
"nextRetryAt"
|
|
8502
|
+
]);
|
|
8503
|
+
function forReader(subscription) {
|
|
8504
|
+
if (!subscription || typeof subscription !== "object") return subscription;
|
|
8505
|
+
return Object.fromEntries(
|
|
8506
|
+
Object.entries(subscription).filter(([key]) => !BILLING_INTERNALS.has(key))
|
|
8507
|
+
);
|
|
8508
|
+
}
|
|
7346
8509
|
function getOutputFormat21(cmd) {
|
|
7347
8510
|
const config = loadConfig();
|
|
7348
8511
|
const globalOpts = cmd.optsWithGlobals();
|
|
7349
8512
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
7350
8513
|
}
|
|
7351
8514
|
function registerSubscriptionCommand(program) {
|
|
7352
|
-
const sub = program.command("subscription").description("View subscription info")
|
|
8515
|
+
const sub = program.command("subscription").description("View subscription info").addHelpText("after", `
|
|
8516
|
+
Examples:
|
|
8517
|
+
$ diafunc subscription current plan, term and billing interval
|
|
8518
|
+
$ diafunc subscription current -o json including the billing-integration fields
|
|
8519
|
+
`);
|
|
7353
8520
|
sub.command("current", { isDefault: true }).description("Show the current subscription").action(async (_options, cmd) => {
|
|
7354
8521
|
try {
|
|
7355
8522
|
const api = createApiClient();
|
|
8523
|
+
const outputFormat = getOutputFormat21(cmd);
|
|
7356
8524
|
const s = await api.admin.getCurrentSubscription();
|
|
7357
|
-
format(s, { format:
|
|
8525
|
+
format(outputFormat === "human" ? forReader(s) : s, { format: outputFormat });
|
|
7358
8526
|
} catch (error) {
|
|
7359
8527
|
handleError(error);
|
|
7360
8528
|
}
|
|
@@ -7362,8 +8530,9 @@ function registerSubscriptionCommand(program) {
|
|
|
7362
8530
|
sub.command("next").description("Show the next (upcoming) subscription").action(async (_options, cmd) => {
|
|
7363
8531
|
try {
|
|
7364
8532
|
const api = createApiClient();
|
|
8533
|
+
const outputFormat = getOutputFormat21(cmd);
|
|
7365
8534
|
const s = await api.admin.getNextSubscription();
|
|
7366
|
-
format(s, { format:
|
|
8535
|
+
format(outputFormat === "human" ? forReader(s) : s, { format: outputFormat });
|
|
7367
8536
|
} catch (error) {
|
|
7368
8537
|
handleError(error);
|
|
7369
8538
|
}
|
|
@@ -7380,7 +8549,6 @@ function registerSubscriptionCommand(program) {
|
|
|
7380
8549
|
}
|
|
7381
8550
|
|
|
7382
8551
|
// src/commands/invoice/index.ts
|
|
7383
|
-
import chalk34 from "chalk";
|
|
7384
8552
|
import * as fs10 from "fs";
|
|
7385
8553
|
function getOutputFormat22(cmd) {
|
|
7386
8554
|
const config = loadConfig();
|
|
@@ -7388,14 +8556,26 @@ function getOutputFormat22(cmd) {
|
|
|
7388
8556
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
7389
8557
|
}
|
|
7390
8558
|
function registerInvoiceCommand(program) {
|
|
7391
|
-
const invoice = program.command("invoice").description("View and download invoices")
|
|
8559
|
+
const invoice = program.command("invoice").description("View and download invoices").addHelpText("after", `
|
|
8560
|
+
Examples:
|
|
8561
|
+
$ diafunc invoice list
|
|
8562
|
+
$ diafunc invoice download 120 invoice-120.pdf
|
|
8563
|
+
`);
|
|
8564
|
+
;
|
|
7392
8565
|
invoice.command("list").description("List your invoices").action(async (_options, cmd) => {
|
|
7393
8566
|
try {
|
|
7394
8567
|
const api = createApiClient();
|
|
7395
8568
|
const invoices = await api.admin.getInvoices();
|
|
7396
8569
|
format(invoices, {
|
|
7397
8570
|
format: getOutputFormat22(cmd),
|
|
7398
|
-
columns: [
|
|
8571
|
+
columns: [
|
|
8572
|
+
{ key: "invoiceNumber", header: "number" },
|
|
8573
|
+
{ key: "issued", kind: "date" },
|
|
8574
|
+
{ key: "periodFrom", header: "from" },
|
|
8575
|
+
{ key: "periodTo", header: "to" },
|
|
8576
|
+
{ key: "total", kind: "number" },
|
|
8577
|
+
{ key: "status", kind: "state" }
|
|
8578
|
+
]
|
|
7399
8579
|
});
|
|
7400
8580
|
} catch (error) {
|
|
7401
8581
|
handleError(error);
|
|
@@ -7408,7 +8588,7 @@ function registerInvoiceCommand(program) {
|
|
|
7408
8588
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
7409
8589
|
const outPath = options.out ?? fileName;
|
|
7410
8590
|
fs10.writeFileSync(outPath, buffer);
|
|
7411
|
-
|
|
8591
|
+
success(`Invoice saved to ${outPath}`);
|
|
7412
8592
|
} catch (error) {
|
|
7413
8593
|
handleError(error);
|
|
7414
8594
|
}
|
|
@@ -7416,12 +8596,12 @@ function registerInvoiceCommand(program) {
|
|
|
7416
8596
|
}
|
|
7417
8597
|
|
|
7418
8598
|
// src/commands/shell/index.ts
|
|
7419
|
-
import
|
|
8599
|
+
import chalk31 from "chalk";
|
|
7420
8600
|
import * as fs11 from "fs";
|
|
7421
8601
|
import * as os3 from "os";
|
|
7422
8602
|
import * as path8 from "path";
|
|
7423
8603
|
import { spawn as spawn3 } from "child_process";
|
|
7424
|
-
import { randomUUID as
|
|
8604
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
7425
8605
|
function extensionFor2(language) {
|
|
7426
8606
|
const l = language.toLowerCase();
|
|
7427
8607
|
if (l === "java") return "java";
|
|
@@ -7432,7 +8612,7 @@ function extensionFor2(language) {
|
|
|
7432
8612
|
return "txt";
|
|
7433
8613
|
}
|
|
7434
8614
|
async function openInEditor(initial, ext) {
|
|
7435
|
-
const tmpFile = path8.join(os3.tmpdir(), `diafunc-shell-${
|
|
8615
|
+
const tmpFile = path8.join(os3.tmpdir(), `diafunc-shell-${randomUUID2()}.${ext}`);
|
|
7436
8616
|
fs11.writeFileSync(tmpFile, initial);
|
|
7437
8617
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
7438
8618
|
await new Promise((resolve, reject) => {
|
|
@@ -7464,7 +8644,7 @@ async function evaluate(api, fnRef, language, sourceCode) {
|
|
|
7464
8644
|
sourceCode
|
|
7465
8645
|
});
|
|
7466
8646
|
await api.storage.saveEntities([entity]);
|
|
7467
|
-
const evaluationId =
|
|
8647
|
+
const evaluationId = timeUuid();
|
|
7468
8648
|
const nowParts = utcNowParts();
|
|
7469
8649
|
const result = await api.evaluation.call({
|
|
7470
8650
|
evaluationId,
|
|
@@ -7482,21 +8662,21 @@ async function evaluate(api, fnRef, language, sourceCode) {
|
|
|
7482
8662
|
}, false);
|
|
7483
8663
|
if (result.outputs?.length) {
|
|
7484
8664
|
for (const out of result.outputs) {
|
|
7485
|
-
console.log(
|
|
8665
|
+
console.log(chalk31.dim(` [${out.type}]`) + " " + out.output);
|
|
7486
8666
|
}
|
|
7487
8667
|
}
|
|
7488
8668
|
if (result.successful) {
|
|
7489
8669
|
if (result.result) {
|
|
7490
|
-
console.log(
|
|
8670
|
+
console.log(chalk31.green("=>") + " " + result.result);
|
|
7491
8671
|
} else {
|
|
7492
|
-
console.log(
|
|
8672
|
+
console.log(chalk31.dim("=> (no value)"));
|
|
7493
8673
|
}
|
|
7494
8674
|
const duration = result.completed - result.started;
|
|
7495
|
-
console.log(
|
|
8675
|
+
console.log(chalk31.dim(` [${duration}ms \xB7 ${evaluationId}]`));
|
|
7496
8676
|
} else {
|
|
7497
|
-
console.log(
|
|
8677
|
+
console.log(chalk31.red("error: ") + result.error);
|
|
7498
8678
|
if (result.lineNumber > 0) {
|
|
7499
|
-
console.log(
|
|
8679
|
+
console.log(chalk31.dim(` at line ${result.lineNumber}, col ${result.columnNumber}`));
|
|
7500
8680
|
}
|
|
7501
8681
|
}
|
|
7502
8682
|
}
|
|
@@ -7504,9 +8684,9 @@ function registerShellCommand(program) {
|
|
|
7504
8684
|
program.command("shell").description("Interactive REPL for function code evaluation").option("--function <ref>", "Function entity reference to use as scratch (required)").option("--language <lang>", "Source language; defaults to the project's language").action(async (options, cmd) => {
|
|
7505
8685
|
try {
|
|
7506
8686
|
if (!options.function) {
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
8687
|
+
failure("Missing --function <ref>.");
|
|
8688
|
+
hint("Pass an existing or new function entity reference to use as the shell target.");
|
|
8689
|
+
hint("Example: diafunc shell --function my-project/main/scratch/main --language Kotlin");
|
|
7510
8690
|
process.exit(1);
|
|
7511
8691
|
}
|
|
7512
8692
|
const config = loadConfig();
|
|
@@ -7517,19 +8697,19 @@ function registerShellCommand(program) {
|
|
|
7517
8697
|
});
|
|
7518
8698
|
const api = createApiClient();
|
|
7519
8699
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
7520
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
8700
|
+
const { getUpdateNotice } = await import("./update-check-XRMWJ753.js");
|
|
7521
8701
|
const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
|
|
7522
|
-
console.log(
|
|
7523
|
-
console.log(
|
|
7524
|
-
console.log(
|
|
8702
|
+
console.log(chalk31.bold("Diafunc shell") + chalk31.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
|
|
8703
|
+
console.log(chalk31.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
8704
|
+
console.log(chalk31.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
|
|
7525
8705
|
const notice = await getUpdateNotice();
|
|
7526
|
-
if (notice) console.log(
|
|
8706
|
+
if (notice) console.log(chalk31.dim(notice));
|
|
7527
8707
|
console.log();
|
|
7528
8708
|
let language = resolvedLanguage;
|
|
7529
8709
|
for (; ; ) {
|
|
7530
8710
|
let line;
|
|
7531
8711
|
try {
|
|
7532
|
-
line = await promptInput({ message:
|
|
8712
|
+
line = await promptInput({ message: chalk31.cyan.bold(`${language} >`) });
|
|
7533
8713
|
} catch {
|
|
7534
8714
|
console.log();
|
|
7535
8715
|
return;
|
|
@@ -7547,54 +8727,54 @@ function registerShellCommand(program) {
|
|
|
7547
8727
|
case "help":
|
|
7548
8728
|
case "h":
|
|
7549
8729
|
case "?":
|
|
7550
|
-
console.log(
|
|
7551
|
-
console.log(
|
|
7552
|
-
console.log(
|
|
7553
|
-
console.log(
|
|
8730
|
+
console.log(chalk31.dim(" /edit open $EDITOR for multi-line code"));
|
|
8731
|
+
console.log(chalk31.dim(" /file <path> evaluate the contents of a file"));
|
|
8732
|
+
console.log(chalk31.dim(" /lang <name> switch language (Java, JavaScript, Kotlin, Python, Scala)"));
|
|
8733
|
+
console.log(chalk31.dim(" /quit exit the shell"));
|
|
7554
8734
|
continue;
|
|
7555
8735
|
case "lang":
|
|
7556
8736
|
if (arg) language = arg;
|
|
7557
|
-
console.log(
|
|
8737
|
+
console.log(chalk31.dim(`Language: ${language}`));
|
|
7558
8738
|
continue;
|
|
7559
8739
|
case "edit": {
|
|
7560
8740
|
const sourceCode = await openInEditor("", extensionFor2(language));
|
|
7561
8741
|
if (!sourceCode.trim()) {
|
|
7562
|
-
console.log(
|
|
8742
|
+
console.log(chalk31.dim("(empty \u2014 not evaluated)"));
|
|
7563
8743
|
continue;
|
|
7564
8744
|
}
|
|
7565
8745
|
try {
|
|
7566
8746
|
await evaluate(api, fnRef, language, sourceCode);
|
|
7567
8747
|
} catch (e) {
|
|
7568
|
-
console.error(
|
|
8748
|
+
console.error(chalk31.red(e.message));
|
|
7569
8749
|
}
|
|
7570
8750
|
continue;
|
|
7571
8751
|
}
|
|
7572
8752
|
case "file": {
|
|
7573
8753
|
if (!arg) {
|
|
7574
|
-
console.log(
|
|
8754
|
+
console.log(chalk31.dim("usage: /file <path>"));
|
|
7575
8755
|
continue;
|
|
7576
8756
|
}
|
|
7577
8757
|
if (!fs11.existsSync(arg)) {
|
|
7578
|
-
console.log(
|
|
8758
|
+
console.log(chalk31.red(`file not found: ${arg}`));
|
|
7579
8759
|
continue;
|
|
7580
8760
|
}
|
|
7581
8761
|
const sourceCode = fs11.readFileSync(arg, "utf-8");
|
|
7582
8762
|
try {
|
|
7583
8763
|
await evaluate(api, fnRef, language, sourceCode);
|
|
7584
8764
|
} catch (e) {
|
|
7585
|
-
console.error(
|
|
8765
|
+
console.error(chalk31.red(e.message));
|
|
7586
8766
|
}
|
|
7587
8767
|
continue;
|
|
7588
8768
|
}
|
|
7589
8769
|
default:
|
|
7590
|
-
console.log(
|
|
8770
|
+
console.log(chalk31.dim(`Unknown command: /${cmd2}. Try /help.`));
|
|
7591
8771
|
continue;
|
|
7592
8772
|
}
|
|
7593
8773
|
}
|
|
7594
8774
|
try {
|
|
7595
8775
|
await evaluate(api, fnRef, language, trimmed);
|
|
7596
8776
|
} catch (e) {
|
|
7597
|
-
console.error(
|
|
8777
|
+
console.error(chalk31.red(e.message));
|
|
7598
8778
|
}
|
|
7599
8779
|
}
|
|
7600
8780
|
} catch (error) {
|
|
@@ -7604,7 +8784,7 @@ function registerShellCommand(program) {
|
|
|
7604
8784
|
}
|
|
7605
8785
|
|
|
7606
8786
|
// src/commands/update/index.ts
|
|
7607
|
-
import
|
|
8787
|
+
import chalk32 from "chalk";
|
|
7608
8788
|
import * as path9 from "path";
|
|
7609
8789
|
import { spawn as spawn4 } from "child_process";
|
|
7610
8790
|
|
|
@@ -7650,14 +8830,14 @@ function registerUpdateCommand(program) {
|
|
|
7650
8830
|
const install = detectInstall();
|
|
7651
8831
|
const latest = await fetchLatestVersion();
|
|
7652
8832
|
if (latest === package_default.version) {
|
|
7653
|
-
console.log(
|
|
8833
|
+
console.log(chalk32.dim(`diafunc is already at the latest version (${package_default.version}).`));
|
|
7654
8834
|
return;
|
|
7655
8835
|
}
|
|
7656
|
-
console.log(
|
|
8836
|
+
console.log(chalk32.dim(`Current: ${package_default.version} \u2192 Available: ${latest}`));
|
|
7657
8837
|
if (install.method === "npm") {
|
|
7658
8838
|
console.log();
|
|
7659
8839
|
console.log("Installed via npm. Upgrade with:");
|
|
7660
|
-
console.log(
|
|
8840
|
+
console.log(chalk32.bold(` npm install -g @diafunc/cli@${latest}`));
|
|
7661
8841
|
return;
|
|
7662
8842
|
}
|
|
7663
8843
|
const installDir = path9.dirname(install.binaryPath);
|
|
@@ -7671,7 +8851,7 @@ function registerUpdateCommand(program) {
|
|
|
7671
8851
|
}
|
|
7672
8852
|
|
|
7673
8853
|
// src/commands/uninstall/index.ts
|
|
7674
|
-
import
|
|
8854
|
+
import chalk33 from "chalk";
|
|
7675
8855
|
import { spawn as spawn5 } from "child_process";
|
|
7676
8856
|
import * as fs13 from "fs";
|
|
7677
8857
|
import * as os4 from "os";
|
|
@@ -7683,11 +8863,11 @@ function registerUninstallCommand(program) {
|
|
|
7683
8863
|
const configDir = path10.join(os4.homedir(), ".diafunc");
|
|
7684
8864
|
if (install.method === "npm") {
|
|
7685
8865
|
console.log("Installed via npm. Remove with:");
|
|
7686
|
-
console.log(
|
|
8866
|
+
console.log(chalk33.bold(" npm uninstall -g @diafunc/cli"));
|
|
7687
8867
|
if (fs13.existsSync(configDir)) {
|
|
7688
8868
|
console.log();
|
|
7689
8869
|
console.log(`Config + credentials live at ${configDir} \u2014 remove manually with:`);
|
|
7690
|
-
console.log(
|
|
8870
|
+
console.log(chalk33.bold(` rm -rf ${configDir}`));
|
|
7691
8871
|
}
|
|
7692
8872
|
return;
|
|
7693
8873
|
}
|
|
@@ -7697,7 +8877,7 @@ function registerUninstallCommand(program) {
|
|
|
7697
8877
|
default: false
|
|
7698
8878
|
});
|
|
7699
8879
|
if (!removeBinary) {
|
|
7700
|
-
console.log(
|
|
8880
|
+
console.log(chalk33.dim("Aborted."));
|
|
7701
8881
|
return;
|
|
7702
8882
|
}
|
|
7703
8883
|
let removeConfig = options.purge ?? false;
|
|
@@ -7709,7 +8889,7 @@ function registerUninstallCommand(program) {
|
|
|
7709
8889
|
}
|
|
7710
8890
|
if (removeConfig && fs13.existsSync(configDir)) {
|
|
7711
8891
|
fs13.rmSync(configDir, { recursive: true, force: true });
|
|
7712
|
-
console.log(
|
|
8892
|
+
console.log(chalk33.dim(`Removed ${configDir}`));
|
|
7713
8893
|
}
|
|
7714
8894
|
if (process.platform === "win32") {
|
|
7715
8895
|
const cmd = `timeout /t 2 /nobreak >nul & del /f /q "${install.binaryPath}"`;
|
|
@@ -7719,13 +8899,13 @@ function registerUninstallCommand(program) {
|
|
|
7719
8899
|
windowsHide: true
|
|
7720
8900
|
});
|
|
7721
8901
|
child.unref();
|
|
7722
|
-
console.log(
|
|
8902
|
+
console.log(chalk33.dim(`Removing ${install.binaryPath} on exit...`));
|
|
7723
8903
|
console.log();
|
|
7724
8904
|
console.log("diafunc uninstalled.");
|
|
7725
8905
|
return;
|
|
7726
8906
|
}
|
|
7727
8907
|
fs13.rmSync(install.binaryPath, { force: true });
|
|
7728
|
-
console.log(
|
|
8908
|
+
console.log(chalk33.dim(`Removed ${install.binaryPath}`));
|
|
7729
8909
|
console.log();
|
|
7730
8910
|
console.log("diafunc uninstalled.");
|
|
7731
8911
|
} catch (error) {
|
|
@@ -7735,14 +8915,38 @@ function registerUninstallCommand(program) {
|
|
|
7735
8915
|
}
|
|
7736
8916
|
|
|
7737
8917
|
// src/index.ts
|
|
8918
|
+
var HELP_EPILOGUE = `
|
|
8919
|
+
Getting started:
|
|
8920
|
+
$ diafunc auth login sign in
|
|
8921
|
+
$ diafunc analyze data.csv --targets price run an analysis and follow it
|
|
8922
|
+
$ diafunc analyze watch follow the latest run again
|
|
8923
|
+
$ diafunc analyze open open the finished notebook
|
|
8924
|
+
|
|
8925
|
+
Everyday:
|
|
8926
|
+
$ diafunc project list what you have
|
|
8927
|
+
$ diafunc search "housing" find it across every project
|
|
8928
|
+
$ diafunc chat ask the assistant
|
|
8929
|
+
$ diafunc status summary is the platform healthy
|
|
8930
|
+
|
|
8931
|
+
Output:
|
|
8932
|
+
Add --output json for scripting, or pipe any command to get tab-separated fields.
|
|
8933
|
+
Add --verbose to see the requests, --dry-run to preview a mutation.
|
|
8934
|
+
|
|
8935
|
+
Docs: https://diafunc.com/documentation
|
|
8936
|
+
`;
|
|
7738
8937
|
function createProgram() {
|
|
7739
8938
|
const program = new Command();
|
|
7740
|
-
program.name("diafunc").description("Diafunc CLI \u2014 command-line interface for the Diafunc platform").version(package_default.version).option("-p, --profile <name>", "Profile to use").option("-o, --output <format>", "Output format: human, json, table").option("--project <id>", "Default project ID override").option("--branch <name>", "Default branch override").option("--dry-run", "Preview mutating operations without executing them").
|
|
8939
|
+
program.name("diafunc").description("Diafunc CLI \u2014 command-line interface for the Diafunc platform").version(package_default.version).option("-p, --profile <name>", "Profile to use").option("-o, --output <format>", "Output format: human, json, table (default: human)").option("--project <id>", "Default project ID override").option("--branch <name>", "Default branch override").option("--dry-run", "Preview mutating operations without executing them").option("--verbose", "Echo every HTTP request to stderr").option("--no-color", "Disable coloured output").showSuggestionAfterError().showHelpAfterError(`(run 'diafunc --help' to see the available commands)`).configureOutput({
|
|
8940
|
+
// Commander writes usage errors to stdout by default, which puts a complaint in the middle
|
|
8941
|
+
// of whatever a caller was capturing.
|
|
8942
|
+
writeErr: (str) => process.stderr.write(str)
|
|
8943
|
+
}).hook("preAction", (thisCommand) => {
|
|
7741
8944
|
const opts = thisCommand.optsWithGlobals();
|
|
7742
|
-
if (opts.dryRun)
|
|
7743
|
-
|
|
7744
|
-
|
|
8945
|
+
if (opts.dryRun) setDryRun(true);
|
|
8946
|
+
if (opts.verbose) setVerbose(true);
|
|
8947
|
+
if (opts.color === false) chalk34.level = 0;
|
|
7745
8948
|
});
|
|
8949
|
+
program.addHelpText("after", HELP_EPILOGUE);
|
|
7746
8950
|
registerAuthCommands(program);
|
|
7747
8951
|
registerConfigCommands(program);
|
|
7748
8952
|
registerProjectCommands(program);
|
|
@@ -7779,4 +8983,4 @@ function createProgram() {
|
|
|
7779
8983
|
export {
|
|
7780
8984
|
createProgram
|
|
7781
8985
|
};
|
|
7782
|
-
//# sourceMappingURL=chunk-
|
|
8986
|
+
//# sourceMappingURL=chunk-XRUDG6ZY.js.map
|