@diafunc/cli 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/diafunc.js +3 -3
- package/dist/{chunk-3AY25U63.js → chunk-B7GDGRAR.js} +2 -2
- package/dist/{chunk-L63Y72FJ.js → chunk-E4O67FMQ.js} +1573 -600
- package/dist/chunk-E4O67FMQ.js.map +1 -0
- package/dist/{chunk-QAMANXTQ.js → chunk-NSFXPO66.js} +2 -2
- package/dist/{chunk-QAMANXTQ.js.map → chunk-NSFXPO66.js.map} +1 -1
- package/dist/src/index.js +2 -2
- package/dist/update-check-KL3CHODI.js +8 -0
- package/package.json +1 -1
- package/dist/chunk-L63Y72FJ.js.map +0 -1
- package/dist/update-check-E3YHFRKF.js +0 -8
- /package/dist/{chunk-3AY25U63.js.map → chunk-B7GDGRAR.js.map} +0 -0
- /package/dist/{update-check-E3YHFRKF.js.map → update-check-KL3CHODI.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-NSFXPO66.js";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
import { Command } from "commander";
|
|
@@ -92,8 +92,8 @@ var NetworkError = class extends Error {
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
// src/client/http.ts
|
|
95
|
-
function buildUrl(endpoint, service,
|
|
96
|
-
const base = `${endpoint}/api/v1/${service}${
|
|
95
|
+
function buildUrl(endpoint, service, path11, query) {
|
|
96
|
+
const base = `${endpoint}/api/v1/${service}${path11}`;
|
|
97
97
|
const params = new URLSearchParams();
|
|
98
98
|
if (query) {
|
|
99
99
|
for (const [key, value] of Object.entries(query)) {
|
|
@@ -263,24 +263,6 @@ ${bodyPreview}`);
|
|
|
263
263
|
var SERVICE = "admin";
|
|
264
264
|
function createAdminService(client) {
|
|
265
265
|
return {
|
|
266
|
-
// Sessions
|
|
267
|
-
async createSession(credentials) {
|
|
268
|
-
return client.request({
|
|
269
|
-
method: "POST",
|
|
270
|
-
service: SERVICE,
|
|
271
|
-
path: "/sessions/",
|
|
272
|
-
body: credentials
|
|
273
|
-
});
|
|
274
|
-
},
|
|
275
|
-
async refreshSession(refreshToken) {
|
|
276
|
-
return client.request({
|
|
277
|
-
method: "PUT",
|
|
278
|
-
service: SERVICE,
|
|
279
|
-
path: "/sessions/",
|
|
280
|
-
rawBody: refreshToken,
|
|
281
|
-
contentType: "text/plain"
|
|
282
|
-
});
|
|
283
|
-
},
|
|
284
266
|
// Users
|
|
285
267
|
async getMyUser() {
|
|
286
268
|
return client.request({
|
|
@@ -1190,6 +1172,20 @@ function enc(s) {
|
|
|
1190
1172
|
function entityPath(ref) {
|
|
1191
1173
|
return `/${enc(ref.projectId)}/${enc(ref.projectBranch)}/${enc(ref.entityId)}/${enc(ref.entityBranch)}`;
|
|
1192
1174
|
}
|
|
1175
|
+
function exportTableQuery(options) {
|
|
1176
|
+
const query = {};
|
|
1177
|
+
if (options.compression) query.compression = options.compression;
|
|
1178
|
+
if (options.archive) query.archive = options.archive;
|
|
1179
|
+
if (options.fromRow !== void 0 && options.fromRow !== null) query.fromRow = String(options.fromRow);
|
|
1180
|
+
if (options.toRow !== void 0 && options.toRow !== null) query.toRow = String(options.toRow);
|
|
1181
|
+
if (options.fromColumn !== void 0 && options.fromColumn !== null) query.fromColumn = String(options.fromColumn);
|
|
1182
|
+
if (options.toColumn !== void 0 && options.toColumn !== null) query.toColumn = String(options.toColumn);
|
|
1183
|
+
if (options.delimiter !== void 0) query.delimiter = options.delimiter;
|
|
1184
|
+
if (options.quote !== void 0) query.quote = options.quote;
|
|
1185
|
+
if (options.nullValue !== void 0) query.nullValue = options.nullValue;
|
|
1186
|
+
if (options.quoteAll !== void 0) query.quoteAll = String(options.quoteAll);
|
|
1187
|
+
return query;
|
|
1188
|
+
}
|
|
1193
1189
|
function createStorageService(client) {
|
|
1194
1190
|
return {
|
|
1195
1191
|
// --- Entities ---
|
|
@@ -1331,14 +1327,14 @@ function createStorageService(client) {
|
|
|
1331
1327
|
});
|
|
1332
1328
|
},
|
|
1333
1329
|
async deleteLink(projectId, projectBranch, sourceEntityId, sourceEntityBranch, linkId, targetEntityId, targetEntityBranch) {
|
|
1334
|
-
let
|
|
1330
|
+
let path11 = `/links/actual/${enc(projectId)}/${enc(projectBranch)}/${enc(sourceEntityId)}/${enc(sourceEntityBranch)}/${enc(linkId)}`;
|
|
1335
1331
|
if (targetEntityId && targetEntityBranch) {
|
|
1336
|
-
|
|
1332
|
+
path11 += `/${enc(targetEntityId)}/${enc(targetEntityBranch)}`;
|
|
1337
1333
|
}
|
|
1338
1334
|
return client.request({
|
|
1339
1335
|
method: "DELETE",
|
|
1340
1336
|
service: SERVICE3,
|
|
1341
|
-
path:
|
|
1337
|
+
path: path11
|
|
1342
1338
|
});
|
|
1343
1339
|
},
|
|
1344
1340
|
// --- Events ---
|
|
@@ -1395,13 +1391,27 @@ function createStorageService(client) {
|
|
|
1395
1391
|
path: `/tables${entityPath(ref)}/rows`
|
|
1396
1392
|
});
|
|
1397
1393
|
},
|
|
1398
|
-
async
|
|
1394
|
+
async insertRow(ref, rowIndex) {
|
|
1395
|
+
return client.request({
|
|
1396
|
+
method: "POST",
|
|
1397
|
+
service: SERVICE3,
|
|
1398
|
+
path: `/tables${entityPath(ref)}/rows/${rowIndex}/insert`
|
|
1399
|
+
});
|
|
1400
|
+
},
|
|
1401
|
+
async removeRow(ref, rowIndex) {
|
|
1399
1402
|
return client.request({
|
|
1400
1403
|
method: "DELETE",
|
|
1401
1404
|
service: SERVICE3,
|
|
1402
1405
|
path: `/tables${entityPath(ref)}/rows/${rowIndex}`
|
|
1403
1406
|
});
|
|
1404
1407
|
},
|
|
1408
|
+
async deleteRow(ref, rowIndex) {
|
|
1409
|
+
return client.request({
|
|
1410
|
+
method: "POST",
|
|
1411
|
+
service: SERVICE3,
|
|
1412
|
+
path: `/tables${entityPath(ref)}/rows/${rowIndex}/delete`
|
|
1413
|
+
});
|
|
1414
|
+
},
|
|
1405
1415
|
async appendColumn(ref) {
|
|
1406
1416
|
return client.request({
|
|
1407
1417
|
method: "POST",
|
|
@@ -1409,13 +1419,27 @@ function createStorageService(client) {
|
|
|
1409
1419
|
path: `/tables${entityPath(ref)}/columns`
|
|
1410
1420
|
});
|
|
1411
1421
|
},
|
|
1412
|
-
async
|
|
1422
|
+
async insertColumn(ref, columnIndex) {
|
|
1423
|
+
return client.request({
|
|
1424
|
+
method: "POST",
|
|
1425
|
+
service: SERVICE3,
|
|
1426
|
+
path: `/tables${entityPath(ref)}/columns/${columnIndex}/insert`
|
|
1427
|
+
});
|
|
1428
|
+
},
|
|
1429
|
+
async removeColumn(ref, columnIndex) {
|
|
1413
1430
|
return client.request({
|
|
1414
1431
|
method: "DELETE",
|
|
1415
1432
|
service: SERVICE3,
|
|
1416
1433
|
path: `/tables${entityPath(ref)}/columns/${columnIndex}`
|
|
1417
1434
|
});
|
|
1418
1435
|
},
|
|
1436
|
+
async deleteColumn(ref, columnIndex) {
|
|
1437
|
+
return client.request({
|
|
1438
|
+
method: "POST",
|
|
1439
|
+
service: SERVICE3,
|
|
1440
|
+
path: `/tables${entityPath(ref)}/columns/${columnIndex}/delete`
|
|
1441
|
+
});
|
|
1442
|
+
},
|
|
1419
1443
|
async mergeCells(ref, cells) {
|
|
1420
1444
|
return client.request({
|
|
1421
1445
|
method: "PUT",
|
|
@@ -1424,7 +1448,7 @@ function createStorageService(client) {
|
|
|
1424
1448
|
body: cells
|
|
1425
1449
|
});
|
|
1426
1450
|
},
|
|
1427
|
-
async
|
|
1451
|
+
async removeCell(ref, rowIndex, columnIndex) {
|
|
1428
1452
|
return client.request({
|
|
1429
1453
|
method: "DELETE",
|
|
1430
1454
|
service: SERVICE3,
|
|
@@ -1439,15 +1463,24 @@ function createStorageService(client) {
|
|
|
1439
1463
|
});
|
|
1440
1464
|
},
|
|
1441
1465
|
// --- Table Import/Export ---
|
|
1442
|
-
async importTable(ref, formData,
|
|
1466
|
+
async importTable(ref, formData, selection) {
|
|
1467
|
+
const query = {};
|
|
1468
|
+
if (selection) query.selection = selection;
|
|
1443
1469
|
return client.request({
|
|
1444
1470
|
method: "PUT",
|
|
1445
1471
|
service: SERVICE3,
|
|
1446
1472
|
path: `/table-imports${entityPath(ref)}`,
|
|
1447
|
-
query:
|
|
1473
|
+
query: Object.keys(query).length > 0 ? query : void 0,
|
|
1448
1474
|
rawBody: formData
|
|
1449
1475
|
});
|
|
1450
1476
|
},
|
|
1477
|
+
async getSupportedImportFormats() {
|
|
1478
|
+
return client.request({
|
|
1479
|
+
method: "GET",
|
|
1480
|
+
service: SERVICE3,
|
|
1481
|
+
path: `/table-imports/supported-formats`
|
|
1482
|
+
});
|
|
1483
|
+
},
|
|
1451
1484
|
async getImport(ref, importId) {
|
|
1452
1485
|
return client.request({
|
|
1453
1486
|
method: "GET",
|
|
@@ -1455,18 +1488,47 @@ function createStorageService(client) {
|
|
|
1455
1488
|
path: `/imports${entityPath(ref)}/${enc(importId)}`
|
|
1456
1489
|
});
|
|
1457
1490
|
},
|
|
1458
|
-
|
|
1491
|
+
/**
|
|
1492
|
+
* Async (queue) export. Server returns the exportId as plain text; the
|
|
1493
|
+
* caller polls progress via {@code getExport} / {@code listExports}.
|
|
1494
|
+
* For streaming bytes back synchronously, use {@link streamExport}.
|
|
1495
|
+
*/
|
|
1496
|
+
async exportTable(ref, format2, options = {}) {
|
|
1497
|
+
const query = exportTableQuery(options);
|
|
1498
|
+
return client.request({
|
|
1499
|
+
method: "POST",
|
|
1500
|
+
service: SERVICE3,
|
|
1501
|
+
path: `/table-exports${entityPath(ref)}/${enc(format2)}`,
|
|
1502
|
+
query: Object.keys(query).length > 0 ? query : void 0
|
|
1503
|
+
});
|
|
1504
|
+
},
|
|
1505
|
+
/**
|
|
1506
|
+
* Streaming download via the synchronous {@code /stream} endpoint.
|
|
1507
|
+
* Server runs the exporter and writes chunk-encoded bytes back; the CLI
|
|
1508
|
+
* pipes them straight to a file (no async {@code ExportRow}, no progress
|
|
1509
|
+
* polling). Default for {@code diafunc table export} unless {@code
|
|
1510
|
+
* --async} is passed.
|
|
1511
|
+
*/
|
|
1512
|
+
async streamExport(ref, format2, options = {}) {
|
|
1513
|
+
const query = exportTableQuery(options);
|
|
1459
1514
|
return client.requestRaw({
|
|
1460
1515
|
method: "POST",
|
|
1461
1516
|
service: SERVICE3,
|
|
1462
|
-
path: `/table-exports${entityPath(ref)}/
|
|
1517
|
+
path: `/table-exports${entityPath(ref)}/${enc(format2)}/stream`,
|
|
1518
|
+
query: Object.keys(query).length > 0 ? query : void 0
|
|
1463
1519
|
});
|
|
1464
1520
|
},
|
|
1521
|
+
async exportTableCsv(ref) {
|
|
1522
|
+
return this.exportTable(ref, "csv");
|
|
1523
|
+
},
|
|
1465
1524
|
async exportTableExcel(ref) {
|
|
1466
|
-
return
|
|
1467
|
-
|
|
1525
|
+
return this.exportTable(ref, "excel");
|
|
1526
|
+
},
|
|
1527
|
+
async getSupportedExportFormats() {
|
|
1528
|
+
return client.request({
|
|
1529
|
+
method: "GET",
|
|
1468
1530
|
service: SERVICE3,
|
|
1469
|
-
path: `/table-exports
|
|
1531
|
+
path: `/table-exports/supported-formats`
|
|
1470
1532
|
});
|
|
1471
1533
|
},
|
|
1472
1534
|
// --- Branches ---
|
|
@@ -1580,6 +1642,29 @@ function createStorageService(client) {
|
|
|
1580
1642
|
},
|
|
1581
1643
|
// --- Event write ops (moved from read-only block) ---
|
|
1582
1644
|
// NOTE: createEvents / consumeEvents already exist above in the Events section.
|
|
1645
|
+
// --- User-defined exporters (UDE) ---
|
|
1646
|
+
async listUserDefinedExporters() {
|
|
1647
|
+
return client.request({
|
|
1648
|
+
method: "GET",
|
|
1649
|
+
service: SERVICE3,
|
|
1650
|
+
path: `/table-exporters`
|
|
1651
|
+
});
|
|
1652
|
+
},
|
|
1653
|
+
async registerUserDefinedExporter(request) {
|
|
1654
|
+
return client.request({
|
|
1655
|
+
method: "POST",
|
|
1656
|
+
service: SERVICE3,
|
|
1657
|
+
path: `/table-exporters`,
|
|
1658
|
+
body: request
|
|
1659
|
+
});
|
|
1660
|
+
},
|
|
1661
|
+
async deleteUserDefinedExporter(id) {
|
|
1662
|
+
await client.request({
|
|
1663
|
+
method: "DELETE",
|
|
1664
|
+
service: SERVICE3,
|
|
1665
|
+
path: `/table-exporters/${enc(id)}`
|
|
1666
|
+
});
|
|
1667
|
+
},
|
|
1583
1668
|
// --- Data sources ---
|
|
1584
1669
|
async createDataSource(request) {
|
|
1585
1670
|
return client.request({
|
|
@@ -1597,6 +1682,14 @@ function createStorageService(client) {
|
|
|
1597
1682
|
query: projectId ? { projectId } : void 0
|
|
1598
1683
|
});
|
|
1599
1684
|
},
|
|
1685
|
+
async getDataSourceDashboard(projectId) {
|
|
1686
|
+
return client.request({
|
|
1687
|
+
method: "GET",
|
|
1688
|
+
service: SERVICE3,
|
|
1689
|
+
path: `/data-sources/dashboard`,
|
|
1690
|
+
query: { projectId }
|
|
1691
|
+
});
|
|
1692
|
+
},
|
|
1600
1693
|
async getDataSource(id) {
|
|
1601
1694
|
return client.request({
|
|
1602
1695
|
method: "GET",
|
|
@@ -1647,6 +1740,131 @@ function createStorageService(client) {
|
|
|
1647
1740
|
service: SERVICE3,
|
|
1648
1741
|
path: `/data-sources/types`
|
|
1649
1742
|
});
|
|
1743
|
+
},
|
|
1744
|
+
// --- Skeletons ---
|
|
1745
|
+
async createSkeleton(request) {
|
|
1746
|
+
return client.request({
|
|
1747
|
+
method: "POST",
|
|
1748
|
+
service: SERVICE3,
|
|
1749
|
+
path: `/skeletons`,
|
|
1750
|
+
body: request
|
|
1751
|
+
});
|
|
1752
|
+
},
|
|
1753
|
+
async listSkeletons(projectId) {
|
|
1754
|
+
return client.request({
|
|
1755
|
+
method: "GET",
|
|
1756
|
+
service: SERVICE3,
|
|
1757
|
+
path: `/skeletons`,
|
|
1758
|
+
query: { projectId }
|
|
1759
|
+
});
|
|
1760
|
+
},
|
|
1761
|
+
async getSkeleton(id) {
|
|
1762
|
+
return client.request({
|
|
1763
|
+
method: "GET",
|
|
1764
|
+
service: SERVICE3,
|
|
1765
|
+
path: `/skeletons/${enc(id)}`
|
|
1766
|
+
});
|
|
1767
|
+
},
|
|
1768
|
+
async updateSkeleton(id, request) {
|
|
1769
|
+
return client.request({
|
|
1770
|
+
method: "PUT",
|
|
1771
|
+
service: SERVICE3,
|
|
1772
|
+
path: `/skeletons/${enc(id)}`,
|
|
1773
|
+
body: request
|
|
1774
|
+
});
|
|
1775
|
+
},
|
|
1776
|
+
async deleteSkeleton(id) {
|
|
1777
|
+
await client.request({
|
|
1778
|
+
method: "DELETE",
|
|
1779
|
+
service: SERVICE3,
|
|
1780
|
+
path: `/skeletons/${enc(id)}`
|
|
1781
|
+
});
|
|
1782
|
+
},
|
|
1783
|
+
// --- Notebook bundles ---
|
|
1784
|
+
/** Queue an async bundle export; returns the bundleId for polling. */
|
|
1785
|
+
async exportBundle(projectId, projectBranch, request) {
|
|
1786
|
+
return client.request({
|
|
1787
|
+
method: "POST",
|
|
1788
|
+
service: SERVICE3,
|
|
1789
|
+
path: `/notebook-bundles/${enc(projectId)}/${enc(projectBranch)}/export`,
|
|
1790
|
+
body: request
|
|
1791
|
+
});
|
|
1792
|
+
},
|
|
1793
|
+
/** Streaming download via the synchronous /stream endpoint; pipe bytes to disk. */
|
|
1794
|
+
async streamBundle(projectId, projectBranch, request) {
|
|
1795
|
+
return client.requestRaw({
|
|
1796
|
+
method: "POST",
|
|
1797
|
+
service: SERVICE3,
|
|
1798
|
+
path: `/notebook-bundles/${enc(projectId)}/${enc(projectBranch)}/export/stream`,
|
|
1799
|
+
body: request
|
|
1800
|
+
});
|
|
1801
|
+
},
|
|
1802
|
+
/** Queue an async whole-project (.dfproj) export (async-only; poll + download the result). */
|
|
1803
|
+
async exportProjectBundle(projectId, projectBranch) {
|
|
1804
|
+
return client.request({
|
|
1805
|
+
method: "POST",
|
|
1806
|
+
service: SERVICE3,
|
|
1807
|
+
path: `/project-bundles/${enc(projectId)}/${enc(projectBranch)}/export`
|
|
1808
|
+
});
|
|
1809
|
+
},
|
|
1810
|
+
/** Queue an async entity-subset (.dfset) export; returns the bundleId for polling. */
|
|
1811
|
+
async exportEntitySubset(projectId, projectBranch, request) {
|
|
1812
|
+
return client.request({
|
|
1813
|
+
method: "POST",
|
|
1814
|
+
service: SERVICE3,
|
|
1815
|
+
path: `/entity-subset-bundles/${enc(projectId)}/${enc(projectBranch)}/export`,
|
|
1816
|
+
body: request
|
|
1817
|
+
});
|
|
1818
|
+
},
|
|
1819
|
+
/** Streaming download of an entity-subset bundle via the synchronous /stream endpoint. */
|
|
1820
|
+
async streamEntitySubset(projectId, projectBranch, request) {
|
|
1821
|
+
return client.requestRaw({
|
|
1822
|
+
method: "POST",
|
|
1823
|
+
service: SERVICE3,
|
|
1824
|
+
path: `/entity-subset-bundles/${enc(projectId)}/${enc(projectBranch)}/export/stream`,
|
|
1825
|
+
body: request
|
|
1826
|
+
});
|
|
1827
|
+
},
|
|
1828
|
+
async getBundles(projectId, projectBranch) {
|
|
1829
|
+
return client.request({
|
|
1830
|
+
method: "GET",
|
|
1831
|
+
service: SERVICE3,
|
|
1832
|
+
path: `/bundles/${enc(projectId)}/${enc(projectBranch)}`
|
|
1833
|
+
});
|
|
1834
|
+
},
|
|
1835
|
+
/** Download a finished bundle's bytes. */
|
|
1836
|
+
async getBundleContent(projectId, projectBranch, bundleId, filename) {
|
|
1837
|
+
return client.requestRaw({
|
|
1838
|
+
method: "GET",
|
|
1839
|
+
service: SERVICE3,
|
|
1840
|
+
path: `/bundles/${enc(projectId)}/${enc(projectBranch)}/${enc(bundleId)}/${enc(filename)}`
|
|
1841
|
+
});
|
|
1842
|
+
},
|
|
1843
|
+
async stopBundle(projectId, projectBranch, bundleId, filename) {
|
|
1844
|
+
await client.request({
|
|
1845
|
+
method: "DELETE",
|
|
1846
|
+
service: SERVICE3,
|
|
1847
|
+
path: `/bundles/${enc(projectId)}/${enc(projectBranch)}/${enc(bundleId)}/${enc(filename)}`
|
|
1848
|
+
});
|
|
1849
|
+
},
|
|
1850
|
+
/** Non-committing inventory of an uploaded bundle. */
|
|
1851
|
+
async previewBundleImport(projectId, projectBranch, formData) {
|
|
1852
|
+
return client.request({
|
|
1853
|
+
method: "POST",
|
|
1854
|
+
service: SERVICE3,
|
|
1855
|
+
path: `/notebook-bundle-imports/${enc(projectId)}/${enc(projectBranch)}/preview`,
|
|
1856
|
+
rawBody: formData
|
|
1857
|
+
});
|
|
1858
|
+
},
|
|
1859
|
+
/** Commit an uploaded bundle into the target project. */
|
|
1860
|
+
async importBundle(projectId, projectBranch, formData, onConflict = "copy") {
|
|
1861
|
+
return client.request({
|
|
1862
|
+
method: "POST",
|
|
1863
|
+
service: SERVICE3,
|
|
1864
|
+
path: `/notebook-bundle-imports/${enc(projectId)}/${enc(projectBranch)}/import`,
|
|
1865
|
+
query: { onConflict },
|
|
1866
|
+
rawBody: formData
|
|
1867
|
+
});
|
|
1650
1868
|
}
|
|
1651
1869
|
};
|
|
1652
1870
|
}
|
|
@@ -2095,8 +2313,8 @@ function registerConfigCommands(program) {
|
|
|
2095
2313
|
console.log(chalk7.green(`Profile "${name}" removed.`));
|
|
2096
2314
|
});
|
|
2097
2315
|
}
|
|
2098
|
-
function setNestedValue(obj,
|
|
2099
|
-
const keys =
|
|
2316
|
+
function setNestedValue(obj, path11, value) {
|
|
2317
|
+
const keys = path11.split(".");
|
|
2100
2318
|
let current = obj;
|
|
2101
2319
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
2102
2320
|
const key = keys[i];
|
|
@@ -2107,8 +2325,8 @@ function setNestedValue(obj, path9, value) {
|
|
|
2107
2325
|
}
|
|
2108
2326
|
current[keys[keys.length - 1]] = value;
|
|
2109
2327
|
}
|
|
2110
|
-
function getNestedValue(obj,
|
|
2111
|
-
const keys =
|
|
2328
|
+
function getNestedValue(obj, path11) {
|
|
2329
|
+
const keys = path11.split(".");
|
|
2112
2330
|
let current = obj;
|
|
2113
2331
|
for (const key of keys) {
|
|
2114
2332
|
if (current === null || current === void 0 || typeof current !== "object") {
|
|
@@ -2120,71 +2338,255 @@ function getNestedValue(obj, path9) {
|
|
|
2120
2338
|
}
|
|
2121
2339
|
|
|
2122
2340
|
// src/commands/project/index.ts
|
|
2123
|
-
import
|
|
2124
|
-
|
|
2341
|
+
import chalk9 from "chalk";
|
|
2342
|
+
|
|
2343
|
+
// src/util/references.ts
|
|
2344
|
+
function parseEntityReference(ref, overrides) {
|
|
2125
2345
|
const config = loadConfig();
|
|
2126
|
-
const
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
try {
|
|
2133
|
-
const outputFormat = getOutputFormat(cmd);
|
|
2134
|
-
const api = createApiClient();
|
|
2135
|
-
const projects = options.all ? await api.admin.getAllProjects() : await api.admin.getProjects();
|
|
2136
|
-
format(projects, {
|
|
2137
|
-
format: outputFormat,
|
|
2138
|
-
columns: ["projectId", "groupId", "visibility", "language", "active", "locked"]
|
|
2139
|
-
});
|
|
2140
|
-
} catch (error) {
|
|
2141
|
-
handleError(error);
|
|
2346
|
+
const defaultProject = overrides?.project ?? config.defaults.project;
|
|
2347
|
+
const defaultBranch = overrides?.branch ?? config.defaults.branch ?? "main";
|
|
2348
|
+
if (!ref.includes("/") && ref.includes(":")) {
|
|
2349
|
+
const [entityId, entityBranch] = ref.split(":");
|
|
2350
|
+
if (!defaultProject) {
|
|
2351
|
+
throw new Error("No default project configured. Set one with: diafunc config set defaults.project <id>");
|
|
2142
2352
|
}
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2353
|
+
return {
|
|
2354
|
+
projectId: defaultProject,
|
|
2355
|
+
projectBranch: defaultBranch,
|
|
2356
|
+
entityId,
|
|
2357
|
+
entityBranch: entityBranch || defaultBranch
|
|
2358
|
+
};
|
|
2359
|
+
}
|
|
2360
|
+
const parts = ref.split("/");
|
|
2361
|
+
if (parts.length === 1) {
|
|
2362
|
+
if (!defaultProject) {
|
|
2363
|
+
throw new Error("No default project configured. Set one with: diafunc config set defaults.project <id>");
|
|
2152
2364
|
}
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2365
|
+
return {
|
|
2366
|
+
projectId: defaultProject,
|
|
2367
|
+
projectBranch: defaultBranch,
|
|
2368
|
+
entityId: parts[0],
|
|
2369
|
+
entityBranch: defaultBranch
|
|
2370
|
+
};
|
|
2371
|
+
}
|
|
2372
|
+
if (parts.length === 2) {
|
|
2373
|
+
return {
|
|
2374
|
+
projectId: parts[0],
|
|
2375
|
+
projectBranch: defaultBranch,
|
|
2376
|
+
entityId: parts[1],
|
|
2377
|
+
entityBranch: defaultBranch
|
|
2378
|
+
};
|
|
2379
|
+
}
|
|
2380
|
+
if (parts.length === 3) {
|
|
2381
|
+
if (parts[1] === "") {
|
|
2382
|
+
return {
|
|
2383
|
+
projectId: parts[0],
|
|
2384
|
+
projectBranch: defaultBranch,
|
|
2385
|
+
entityId: parts[2],
|
|
2386
|
+
entityBranch: defaultBranch
|
|
2387
|
+
};
|
|
2173
2388
|
}
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2389
|
+
return {
|
|
2390
|
+
projectId: parts[0],
|
|
2391
|
+
projectBranch: parts[1],
|
|
2392
|
+
entityId: parts[2],
|
|
2393
|
+
entityBranch: defaultBranch
|
|
2394
|
+
};
|
|
2395
|
+
}
|
|
2396
|
+
if (parts.length === 4) {
|
|
2397
|
+
return {
|
|
2398
|
+
projectId: parts[0],
|
|
2399
|
+
projectBranch: parts[1] || defaultBranch,
|
|
2400
|
+
entityId: parts[2],
|
|
2401
|
+
entityBranch: parts[3] || defaultBranch
|
|
2402
|
+
};
|
|
2403
|
+
}
|
|
2404
|
+
throw new Error(
|
|
2405
|
+
`Invalid entity reference: "${ref}". Expected format: entityId, entityId:branch, or projectId/projectBranch/entityId/entityBranch`
|
|
2406
|
+
);
|
|
2407
|
+
}
|
|
2408
|
+
function parseProjectReference(ref, overrides) {
|
|
2409
|
+
const config = loadConfig();
|
|
2410
|
+
const defaultProject = overrides?.project ?? config.defaults.project;
|
|
2411
|
+
const defaultBranch = overrides?.branch ?? config.defaults.branch ?? "main";
|
|
2412
|
+
if (!ref.includes("/")) {
|
|
2413
|
+
return {
|
|
2414
|
+
projectId: ref || defaultProject,
|
|
2415
|
+
projectBranch: defaultBranch
|
|
2416
|
+
};
|
|
2417
|
+
}
|
|
2418
|
+
const parts = ref.split("/");
|
|
2419
|
+
return {
|
|
2420
|
+
projectId: parts[0],
|
|
2421
|
+
projectBranch: parts[1] || defaultBranch
|
|
2422
|
+
};
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
// src/commands/bundle-helpers.ts
|
|
2426
|
+
import chalk8 from "chalk";
|
|
2427
|
+
import * as fs2 from "fs";
|
|
2428
|
+
import * as path2 from "path";
|
|
2429
|
+
async function streamResponseToFile(response, outFile) {
|
|
2430
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
2431
|
+
fs2.writeFileSync(outFile, buffer);
|
|
2432
|
+
return buffer.length;
|
|
2433
|
+
}
|
|
2434
|
+
function printLossiness(notes) {
|
|
2435
|
+
if (notes && notes.length > 0) {
|
|
2436
|
+
console.log(chalk8.yellow("Lossiness:"));
|
|
2437
|
+
for (const note of notes) {
|
|
2438
|
+
console.log(chalk8.yellow(` - ${note}`));
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
function printImportPreview(preview) {
|
|
2443
|
+
console.log(chalk8.bold(`${preview.kind} bundle \xB7 ${preview.entityCount} entities`));
|
|
2444
|
+
if (preview.projectName) {
|
|
2445
|
+
console.log(chalk8.dim(preview.projectName));
|
|
2446
|
+
}
|
|
2447
|
+
if (preview.sourceProjectId) {
|
|
2448
|
+
console.log(chalk8.dim(`from ${preview.sourceProjectId}/${preview.sourceProjectBranch}` + (preview.createdBy ? ` \xB7 by ${preview.createdBy}` : "")));
|
|
2449
|
+
}
|
|
2450
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2451
|
+
for (const e of preview.entities ?? []) {
|
|
2452
|
+
counts.set(e.type, (counts.get(e.type) ?? 0) + 1);
|
|
2453
|
+
}
|
|
2454
|
+
for (const [type, count] of [...counts.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
2455
|
+
console.log(` ${type}: ${count}`);
|
|
2456
|
+
}
|
|
2457
|
+
if (preview.hasAnalysis) {
|
|
2458
|
+
console.log(" analysis recipe: included");
|
|
2459
|
+
}
|
|
2460
|
+
if (preview.skeletonCount) {
|
|
2461
|
+
console.log(` skeletons: ${preview.skeletonCount}`);
|
|
2462
|
+
}
|
|
2463
|
+
if (preview.redactedDataSourceCount) {
|
|
2464
|
+
console.log(` data sources: ${preview.redactedDataSourceCount} (credentials redacted)`);
|
|
2465
|
+
}
|
|
2466
|
+
printLossiness(preview.lossinessNotes);
|
|
2467
|
+
}
|
|
2468
|
+
function printImportResult(result) {
|
|
2469
|
+
console.log(chalk8.green(`Imported ${result.entityCount} entities, ${result.linkCount} links.`));
|
|
2470
|
+
if (result.skeletonCount) {
|
|
2471
|
+
console.log(`Skeletons: ${result.skeletonCount}`);
|
|
2472
|
+
}
|
|
2473
|
+
if (result.dataSourceCount) {
|
|
2474
|
+
console.log(`Data sources: ${result.dataSourceCount} (re-authenticate before refreshing)`);
|
|
2475
|
+
}
|
|
2476
|
+
if (result.analysisOutcome && result.analysisOutcome !== "none") {
|
|
2477
|
+
console.log(`Analysis recipe: ${result.analysisOutcome}`);
|
|
2478
|
+
}
|
|
2479
|
+
if (result.rootEntityIds.length > 0) {
|
|
2480
|
+
console.log(`Root id(s): ${result.rootEntityIds.join(", ")}`);
|
|
2481
|
+
}
|
|
2482
|
+
printLossiness(result.lossinessNotes);
|
|
2483
|
+
}
|
|
2484
|
+
async function runBundleImport(storage, projectId, projectBranch, file, options, outputFormat) {
|
|
2485
|
+
const fileBuffer = fs2.readFileSync(file);
|
|
2486
|
+
const blob = new Blob([fileBuffer]);
|
|
2487
|
+
const formData = new FormData();
|
|
2488
|
+
formData.append("content", blob, path2.basename(file));
|
|
2489
|
+
if (options.preview) {
|
|
2490
|
+
const preview = await storage.previewBundleImport(projectId, projectBranch, formData);
|
|
2491
|
+
if (outputFormat === "json") {
|
|
2492
|
+
format(preview, { format: outputFormat });
|
|
2493
|
+
return;
|
|
2494
|
+
}
|
|
2495
|
+
printImportPreview(preview);
|
|
2496
|
+
return;
|
|
2497
|
+
}
|
|
2498
|
+
const result = await storage.importBundle(projectId, projectBranch, formData, options.onConflict);
|
|
2499
|
+
if (outputFormat === "json") {
|
|
2500
|
+
format(result, { format: outputFormat });
|
|
2501
|
+
return;
|
|
2502
|
+
}
|
|
2503
|
+
printImportResult(result);
|
|
2504
|
+
}
|
|
2505
|
+
var sleep2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
2506
|
+
async function pollUntilFinished(storage, projectId, projectBranch, bundleId, intervalMs = 2e3, maxAttempts = 150) {
|
|
2507
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
2508
|
+
const bundles = await storage.getBundles(projectId, projectBranch);
|
|
2509
|
+
const job = bundles.find((b) => b.bundleId === bundleId);
|
|
2510
|
+
if (job && job.finished) {
|
|
2511
|
+
if (job.succeeded === false) {
|
|
2512
|
+
throw new Error(`Export failed: ${job.error || "unknown error"}`);
|
|
2513
|
+
}
|
|
2514
|
+
return job;
|
|
2515
|
+
}
|
|
2516
|
+
await sleep2(intervalMs);
|
|
2517
|
+
}
|
|
2518
|
+
throw new Error(`Export ${bundleId} did not finish within the timeout \u2014 poll it with 'diafunc notebook bundles'`);
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
// src/commands/project/index.ts
|
|
2522
|
+
function getOutputFormat(cmd) {
|
|
2523
|
+
const config = loadConfig();
|
|
2524
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
2525
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2526
|
+
}
|
|
2527
|
+
function getOverrides(cmd) {
|
|
2528
|
+
const opts = cmd.optsWithGlobals();
|
|
2529
|
+
return { project: opts.project, branch: opts.branch };
|
|
2530
|
+
}
|
|
2531
|
+
function registerProjectCommands(program) {
|
|
2532
|
+
const project = program.command("project").description("Manage projects");
|
|
2533
|
+
project.command("list").description("List projects").option("--all", "List all projects (admin)").action(async (options, cmd) => {
|
|
2534
|
+
try {
|
|
2535
|
+
const outputFormat = getOutputFormat(cmd);
|
|
2536
|
+
const api = createApiClient();
|
|
2537
|
+
const projects = options.all ? await api.admin.getAllProjects() : await api.admin.getProjects();
|
|
2538
|
+
format(projects, {
|
|
2539
|
+
format: outputFormat,
|
|
2540
|
+
columns: ["projectId", "groupId", "visibility", "language", "active", "locked"]
|
|
2541
|
+
});
|
|
2542
|
+
} catch (error) {
|
|
2543
|
+
handleError(error);
|
|
2544
|
+
}
|
|
2545
|
+
});
|
|
2546
|
+
project.command("get").description("Get project details").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
2547
|
+
try {
|
|
2548
|
+
const outputFormat = getOutputFormat(cmd);
|
|
2549
|
+
const api = createApiClient();
|
|
2550
|
+
const p = await api.admin.getProject(projectId);
|
|
2551
|
+
format(p, { format: outputFormat });
|
|
2552
|
+
} catch (error) {
|
|
2553
|
+
handleError(error);
|
|
2554
|
+
}
|
|
2555
|
+
});
|
|
2556
|
+
project.command("create").description("Create a new project").option("--visibility <visibility>", "Project visibility (PRIVATE or PUBLIC)", "PRIVATE").option("--language <language>", "Project language", "Java").action(async (options, cmd) => {
|
|
2557
|
+
try {
|
|
2558
|
+
const outputFormat = getOutputFormat(cmd);
|
|
2559
|
+
const api = createApiClient();
|
|
2560
|
+
const p = await api.admin.createProject({
|
|
2561
|
+
visibility: options.visibility.toUpperCase(),
|
|
2562
|
+
language: options.language,
|
|
2563
|
+
active: true
|
|
2564
|
+
});
|
|
2565
|
+
if (outputFormat === "human") {
|
|
2566
|
+
console.log(chalk9.green("Project created."));
|
|
2567
|
+
console.log(` Project ID: ${chalk9.bold(p.projectId)}`);
|
|
2568
|
+
console.log(` Visibility: ${p.visibility}`);
|
|
2569
|
+
console.log(` Language: ${p.language}`);
|
|
2570
|
+
} else {
|
|
2571
|
+
format(p, { format: outputFormat });
|
|
2572
|
+
}
|
|
2573
|
+
} catch (error) {
|
|
2574
|
+
handleError(error);
|
|
2575
|
+
}
|
|
2576
|
+
});
|
|
2577
|
+
project.command("update").description("Update a project").argument("<projectId>", "Project ID").option("--visibility <visibility>", "PRIVATE or PUBLIC").option("--language <language>", "Project language").option("--group <groupId>", "Group ID (empty string to unset)").option("--active <bool>", "Whether the project is active (true/false)").action(async (projectId, options) => {
|
|
2578
|
+
try {
|
|
2579
|
+
const api = createApiClient();
|
|
2580
|
+
const current = await api.admin.getProject(projectId);
|
|
2581
|
+
const updated = {
|
|
2582
|
+
...current,
|
|
2583
|
+
...options.visibility ? { visibility: options.visibility.toUpperCase() } : {},
|
|
2584
|
+
...options.language ? { language: options.language } : {},
|
|
2585
|
+
...options.group !== void 0 ? { groupId: options.group || null } : {},
|
|
2184
2586
|
...options.active !== void 0 ? { active: options.active === "true" } : {}
|
|
2185
2587
|
};
|
|
2186
2588
|
await api.admin.updateProject(updated);
|
|
2187
|
-
console.log(
|
|
2589
|
+
console.log(chalk9.green(`Project "${projectId}" updated.`));
|
|
2188
2590
|
} catch (error) {
|
|
2189
2591
|
handleError(error);
|
|
2190
2592
|
}
|
|
@@ -2206,7 +2608,7 @@ function registerProjectCommands(program) {
|
|
|
2206
2608
|
try {
|
|
2207
2609
|
const api = createApiClient();
|
|
2208
2610
|
await api.admin.deleteProject(projectId);
|
|
2209
|
-
console.log(
|
|
2611
|
+
console.log(chalk9.green(`Project "${projectId}" deleted.`));
|
|
2210
2612
|
} catch (error) {
|
|
2211
2613
|
handleError(error);
|
|
2212
2614
|
}
|
|
@@ -2215,7 +2617,7 @@ function registerProjectCommands(program) {
|
|
|
2215
2617
|
try {
|
|
2216
2618
|
const api = createApiClient();
|
|
2217
2619
|
await api.admin.lockProject(projectId);
|
|
2218
|
-
console.log(
|
|
2620
|
+
console.log(chalk9.green(`Project "${projectId}" locked.`));
|
|
2219
2621
|
} catch (error) {
|
|
2220
2622
|
handleError(error);
|
|
2221
2623
|
}
|
|
@@ -2224,7 +2626,7 @@ function registerProjectCommands(program) {
|
|
|
2224
2626
|
try {
|
|
2225
2627
|
const api = createApiClient();
|
|
2226
2628
|
await api.admin.unlockProject(projectId);
|
|
2227
|
-
console.log(
|
|
2629
|
+
console.log(chalk9.green(`Project "${projectId}" unlocked.`));
|
|
2228
2630
|
} catch (error) {
|
|
2229
2631
|
handleError(error);
|
|
2230
2632
|
}
|
|
@@ -2247,7 +2649,7 @@ function registerProjectCommands(program) {
|
|
|
2247
2649
|
try {
|
|
2248
2650
|
const api = createApiClient();
|
|
2249
2651
|
await api.admin.inviteProjectMember(projectId, userId, role.toUpperCase());
|
|
2250
|
-
console.log(
|
|
2652
|
+
console.log(chalk9.green(`Invited ${userId} to "${projectId}" as ${role.toUpperCase()}.`));
|
|
2251
2653
|
} catch (error) {
|
|
2252
2654
|
handleError(error);
|
|
2253
2655
|
}
|
|
@@ -2256,7 +2658,7 @@ function registerProjectCommands(program) {
|
|
|
2256
2658
|
try {
|
|
2257
2659
|
const api = createApiClient();
|
|
2258
2660
|
await api.admin.joinProject(projectId, userId);
|
|
2259
|
-
console.log(
|
|
2661
|
+
console.log(chalk9.green(`Joined project "${projectId}".`));
|
|
2260
2662
|
} catch (error) {
|
|
2261
2663
|
handleError(error);
|
|
2262
2664
|
}
|
|
@@ -2265,90 +2667,54 @@ function registerProjectCommands(program) {
|
|
|
2265
2667
|
try {
|
|
2266
2668
|
const api = createApiClient();
|
|
2267
2669
|
await api.admin.removeProjectMember(projectId, userId);
|
|
2268
|
-
console.log(
|
|
2670
|
+
console.log(chalk9.green(`Removed ${userId} from "${projectId}".`));
|
|
2269
2671
|
} catch (error) {
|
|
2270
2672
|
handleError(error);
|
|
2271
2673
|
}
|
|
2272
2674
|
});
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
entityId,
|
|
2293
|
-
entityBranch: entityBranch || defaultBranch
|
|
2294
|
-
};
|
|
2295
|
-
}
|
|
2296
|
-
const parts = ref.split("/");
|
|
2297
|
-
if (parts.length === 1) {
|
|
2298
|
-
if (!defaultProject) {
|
|
2299
|
-
throw new Error("No default project configured. Set one with: diafunc config set defaults.project <id>");
|
|
2675
|
+
project.command("export").description("Export a whole project (entities, links, skeletons, analysis recipe) to a .dfproj bundle").argument("<project>", "Project reference (projectId or projectId/branch)").option("--out <file>", "Output file (defaults to project.dfproj)").option("--async", "Queue the background job and return immediately instead of waiting for the file").action(async (project2, options, cmd) => {
|
|
2676
|
+
try {
|
|
2677
|
+
const overrides = getOverrides(cmd);
|
|
2678
|
+
const ref = parseProjectReference(project2, overrides);
|
|
2679
|
+
const api = createApiClient();
|
|
2680
|
+
const bundleId = await api.storage.exportProjectBundle(ref.projectId, ref.projectBranch);
|
|
2681
|
+
if (options.async) {
|
|
2682
|
+
console.log(chalk9.green(`Project export queued (bundle ID: ${bundleId}).`));
|
|
2683
|
+
console.log(`Poll progress: diafunc notebook bundles ${project2}`);
|
|
2684
|
+
return;
|
|
2685
|
+
}
|
|
2686
|
+
console.log(chalk9.dim(`Project export queued (bundle ID: ${bundleId}); waiting for it to finish\u2026`));
|
|
2687
|
+
const job = await pollUntilFinished(api.storage, ref.projectId, ref.projectBranch, bundleId);
|
|
2688
|
+
const response = await api.storage.getBundleContent(ref.projectId, ref.projectBranch, bundleId, job.filename);
|
|
2689
|
+
const outFile = options.out ?? "project.dfproj";
|
|
2690
|
+
const bytes = await streamResponseToFile(response, outFile);
|
|
2691
|
+
console.log(chalk9.green(`Bundle written to ${outFile} (${bytes} bytes, ${job.entityCount ?? "?"} entities).`));
|
|
2692
|
+
} catch (error) {
|
|
2693
|
+
handleError(error);
|
|
2300
2694
|
}
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
projectBranch: defaultBranch,
|
|
2312
|
-
entityId: parts[1],
|
|
2313
|
-
entityBranch: defaultBranch
|
|
2314
|
-
};
|
|
2315
|
-
}
|
|
2316
|
-
if (parts.length === 3) {
|
|
2317
|
-
if (parts[1] === "") {
|
|
2318
|
-
return {
|
|
2319
|
-
projectId: parts[0],
|
|
2320
|
-
projectBranch: defaultBranch,
|
|
2321
|
-
entityId: parts[2],
|
|
2322
|
-
entityBranch: defaultBranch
|
|
2323
|
-
};
|
|
2695
|
+
});
|
|
2696
|
+
project.command("import").description("Import a .dfproj (or any) bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the bundle").option("--on-conflict <policy>", "copy (default), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project2, file, options, cmd) => {
|
|
2697
|
+
try {
|
|
2698
|
+
const outputFormat = getOutputFormat(cmd);
|
|
2699
|
+
const overrides = getOverrides(cmd);
|
|
2700
|
+
const ref = parseProjectReference(project2, overrides);
|
|
2701
|
+
const api = createApiClient();
|
|
2702
|
+
await runBundleImport(api.storage, ref.projectId, ref.projectBranch, file, options, outputFormat);
|
|
2703
|
+
} catch (error) {
|
|
2704
|
+
handleError(error);
|
|
2324
2705
|
}
|
|
2325
|
-
|
|
2326
|
-
projectId: parts[0],
|
|
2327
|
-
projectBranch: parts[1],
|
|
2328
|
-
entityId: parts[2],
|
|
2329
|
-
entityBranch: defaultBranch
|
|
2330
|
-
};
|
|
2331
|
-
}
|
|
2332
|
-
if (parts.length === 4) {
|
|
2333
|
-
return {
|
|
2334
|
-
projectId: parts[0],
|
|
2335
|
-
projectBranch: parts[1] || defaultBranch,
|
|
2336
|
-
entityId: parts[2],
|
|
2337
|
-
entityBranch: parts[3] || defaultBranch
|
|
2338
|
-
};
|
|
2339
|
-
}
|
|
2340
|
-
throw new Error(
|
|
2341
|
-
`Invalid entity reference: "${ref}". Expected format: entityId, entityId:branch, or projectId/projectBranch/entityId/entityBranch`
|
|
2342
|
-
);
|
|
2706
|
+
});
|
|
2343
2707
|
}
|
|
2344
2708
|
|
|
2345
2709
|
// src/commands/entity/index.ts
|
|
2710
|
+
import chalk10 from "chalk";
|
|
2711
|
+
import * as fs3 from "fs";
|
|
2346
2712
|
function getOutputFormat2(cmd) {
|
|
2347
2713
|
const config = loadConfig();
|
|
2348
2714
|
const globalOpts = cmd.optsWithGlobals();
|
|
2349
2715
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2350
2716
|
}
|
|
2351
|
-
function
|
|
2717
|
+
function getOverrides2(cmd) {
|
|
2352
2718
|
const opts = cmd.optsWithGlobals();
|
|
2353
2719
|
return { project: opts.project, branch: opts.branch };
|
|
2354
2720
|
}
|
|
@@ -2357,7 +2723,7 @@ function registerEntityCommands(program) {
|
|
|
2357
2723
|
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) => {
|
|
2358
2724
|
try {
|
|
2359
2725
|
const outputFormat = getOutputFormat2(cmd);
|
|
2360
|
-
const overrides =
|
|
2726
|
+
const overrides = getOverrides2(cmd);
|
|
2361
2727
|
const ref = parseEntityReference(projectRef + "/" + projectRef, overrides);
|
|
2362
2728
|
const api = createApiClient();
|
|
2363
2729
|
const entities = await api.storage.getLinkedEntities("FORWARD", {
|
|
@@ -2384,7 +2750,7 @@ function registerEntityCommands(program) {
|
|
|
2384
2750
|
entity.command("get").description("Get entity metadata").argument("<ref>", "Entity reference").option("--content", "Include content").action(async (ref, options, cmd) => {
|
|
2385
2751
|
try {
|
|
2386
2752
|
const outputFormat = getOutputFormat2(cmd);
|
|
2387
|
-
const overrides =
|
|
2753
|
+
const overrides = getOverrides2(cmd);
|
|
2388
2754
|
const resolved = parseEntityReference(ref, overrides);
|
|
2389
2755
|
const api = createApiClient();
|
|
2390
2756
|
const e = await api.storage.getEntity(resolved, options.content);
|
|
@@ -2414,11 +2780,11 @@ function registerEntityCommands(program) {
|
|
|
2414
2780
|
});
|
|
2415
2781
|
entity.command("delete").description("Delete an entity").argument("<ref>", "Entity reference").action(async (ref, _options, cmd) => {
|
|
2416
2782
|
try {
|
|
2417
|
-
const overrides =
|
|
2783
|
+
const overrides = getOverrides2(cmd);
|
|
2418
2784
|
const resolved = parseEntityReference(ref, overrides);
|
|
2419
2785
|
const api = createApiClient();
|
|
2420
2786
|
await api.storage.deleteEntity(resolved);
|
|
2421
|
-
console.log(
|
|
2787
|
+
console.log(chalk10.green(`Entity "${resolved.entityId}" deleted.`));
|
|
2422
2788
|
} catch (error) {
|
|
2423
2789
|
handleError(error);
|
|
2424
2790
|
}
|
|
@@ -2426,7 +2792,7 @@ function registerEntityCommands(program) {
|
|
|
2426
2792
|
entity.command("history").description("Get entity version history").argument("<ref>", "Entity reference").option("--from <version>", "From version").option("--to <version>", "To version").action(async (ref, options, cmd) => {
|
|
2427
2793
|
try {
|
|
2428
2794
|
const outputFormat = getOutputFormat2(cmd);
|
|
2429
|
-
const overrides =
|
|
2795
|
+
const overrides = getOverrides2(cmd);
|
|
2430
2796
|
const resolved = parseEntityReference(ref, overrides);
|
|
2431
2797
|
const api = createApiClient();
|
|
2432
2798
|
if (options.from && options.to) {
|
|
@@ -2455,22 +2821,22 @@ function registerEntityCommands(program) {
|
|
|
2455
2821
|
});
|
|
2456
2822
|
entity.command("revert").description("Revert an entity to a previous version").argument("<ref>", "Entity reference").argument("<version>", "Version to revert to").action(async (ref, version, _options, cmd) => {
|
|
2457
2823
|
try {
|
|
2458
|
-
const overrides =
|
|
2824
|
+
const overrides = getOverrides2(cmd);
|
|
2459
2825
|
const resolved = parseEntityReference(ref, overrides);
|
|
2460
2826
|
const api = createApiClient();
|
|
2461
2827
|
await api.storage.revertEntity(resolved, parseInt(version, 10));
|
|
2462
|
-
console.log(
|
|
2828
|
+
console.log(chalk10.green(`Entity "${resolved.entityId}" reverted to version ${version}.`));
|
|
2463
2829
|
} catch (error) {
|
|
2464
2830
|
handleError(error);
|
|
2465
2831
|
}
|
|
2466
2832
|
});
|
|
2467
2833
|
entity.command("rename").description("Rename an entity").argument("<ref>", "Entity reference").argument("<newId>", "New entity ID").action(async (ref, newId, _options, cmd) => {
|
|
2468
2834
|
try {
|
|
2469
|
-
const overrides =
|
|
2835
|
+
const overrides = getOverrides2(cmd);
|
|
2470
2836
|
const resolved = parseEntityReference(ref, overrides);
|
|
2471
2837
|
const api = createApiClient();
|
|
2472
2838
|
await api.storage.renameEntity(resolved, newId);
|
|
2473
|
-
console.log(
|
|
2839
|
+
console.log(chalk10.green(`Entity renamed from "${resolved.entityId}" to "${newId}".`));
|
|
2474
2840
|
} catch (error) {
|
|
2475
2841
|
handleError(error);
|
|
2476
2842
|
}
|
|
@@ -2478,14 +2844,14 @@ function registerEntityCommands(program) {
|
|
|
2478
2844
|
const content = entity.command("content").description("Manage entity content");
|
|
2479
2845
|
content.command("get").description("Download entity content").argument("<ref>", "Entity reference").option("--out <file>", "Output file (defaults to stdout)").action(async (ref, options, cmd) => {
|
|
2480
2846
|
try {
|
|
2481
|
-
const overrides =
|
|
2847
|
+
const overrides = getOverrides2(cmd);
|
|
2482
2848
|
const resolved = parseEntityReference(ref, overrides);
|
|
2483
2849
|
const api = createApiClient();
|
|
2484
2850
|
const response = await api.storage.getEntityContent(resolved);
|
|
2485
2851
|
if (options.out) {
|
|
2486
2852
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
2487
|
-
|
|
2488
|
-
console.log(
|
|
2853
|
+
fs3.writeFileSync(options.out, buffer);
|
|
2854
|
+
console.log(chalk10.green(`Content saved to ${options.out}`));
|
|
2489
2855
|
} else {
|
|
2490
2856
|
const text = await response.text();
|
|
2491
2857
|
process.stdout.write(text);
|
|
@@ -2496,24 +2862,55 @@ function registerEntityCommands(program) {
|
|
|
2496
2862
|
});
|
|
2497
2863
|
content.command("set").description("Upload entity content from a file").argument("<ref>", "Entity reference").argument("<file>", "File to upload").action(async (ref, file, _options, cmd) => {
|
|
2498
2864
|
try {
|
|
2499
|
-
const overrides =
|
|
2865
|
+
const overrides = getOverrides2(cmd);
|
|
2500
2866
|
const resolved = parseEntityReference(ref, overrides);
|
|
2501
2867
|
const api = createApiClient();
|
|
2502
|
-
const fileBuffer =
|
|
2868
|
+
const fileBuffer = fs3.readFileSync(file);
|
|
2503
2869
|
const base64 = fileBuffer.toString("base64");
|
|
2504
2870
|
await api.storage.saveEntityContentBase64(resolved, base64);
|
|
2505
|
-
console.log(
|
|
2871
|
+
console.log(chalk10.green(`Content uploaded from "${file}" to entity "${resolved.entityId}".`));
|
|
2506
2872
|
} catch (error) {
|
|
2507
2873
|
handleError(error);
|
|
2508
2874
|
}
|
|
2509
2875
|
});
|
|
2510
2876
|
content.command("delete").description("Delete entity content").argument("<ref>", "Entity reference").action(async (ref, _options, cmd) => {
|
|
2511
2877
|
try {
|
|
2512
|
-
const overrides =
|
|
2878
|
+
const overrides = getOverrides2(cmd);
|
|
2513
2879
|
const resolved = parseEntityReference(ref, overrides);
|
|
2514
2880
|
const api = createApiClient();
|
|
2515
2881
|
await api.storage.deleteEntityContent(resolved);
|
|
2516
|
-
console.log(
|
|
2882
|
+
console.log(chalk10.green(`Content deleted from entity "${resolved.entityId}".`));
|
|
2883
|
+
} catch (error) {
|
|
2884
|
+
handleError(error);
|
|
2885
|
+
}
|
|
2886
|
+
});
|
|
2887
|
+
entity.command("export").description("Export a subset of entities (plus their closure) to a .dfset bundle").argument("<project>", "Project reference (projectId or projectId/branch)").argument("<entityIds...>", "Entity id(s) to export").option("--out <file>", "Output file (defaults to entities.dfset)").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, entityIds, options, cmd) => {
|
|
2888
|
+
try {
|
|
2889
|
+
const overrides = getOverrides2(cmd);
|
|
2890
|
+
const ref = parseProjectReference(project, overrides);
|
|
2891
|
+
const api = createApiClient();
|
|
2892
|
+
const request = { rootEntityIds: entityIds, dataFormat: options.data };
|
|
2893
|
+
if (options.async) {
|
|
2894
|
+
const bundleId = await api.storage.exportEntitySubset(ref.projectId, ref.projectBranch, request);
|
|
2895
|
+
console.log(chalk10.green(`Export queued (bundle ID: ${bundleId}).`));
|
|
2896
|
+
console.log(`Poll progress: diafunc notebook bundles ${project}`);
|
|
2897
|
+
return;
|
|
2898
|
+
}
|
|
2899
|
+
const response = await api.storage.streamEntitySubset(ref.projectId, ref.projectBranch, request);
|
|
2900
|
+
const outFile = options.out ?? "entities.dfset";
|
|
2901
|
+
const bytes = await streamResponseToFile(response, outFile);
|
|
2902
|
+
console.log(chalk10.green(`Bundle written to ${outFile} (${bytes} bytes, ${entityIds.length} entity(ies)).`));
|
|
2903
|
+
} catch (error) {
|
|
2904
|
+
handleError(error);
|
|
2905
|
+
}
|
|
2906
|
+
});
|
|
2907
|
+
entity.command("import").description("Import a .dfset (or any) bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the bundle").option("--on-conflict <policy>", "copy (default), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project, file, options, cmd) => {
|
|
2908
|
+
try {
|
|
2909
|
+
const outputFormat = getOutputFormat2(cmd);
|
|
2910
|
+
const overrides = getOverrides2(cmd);
|
|
2911
|
+
const ref = parseProjectReference(project, overrides);
|
|
2912
|
+
const api = createApiClient();
|
|
2913
|
+
await runBundleImport(api.storage, ref.projectId, ref.projectBranch, file, options, outputFormat);
|
|
2517
2914
|
} catch (error) {
|
|
2518
2915
|
handleError(error);
|
|
2519
2916
|
}
|
|
@@ -2521,13 +2918,13 @@ function registerEntityCommands(program) {
|
|
|
2521
2918
|
}
|
|
2522
2919
|
|
|
2523
2920
|
// src/commands/link/index.ts
|
|
2524
|
-
import
|
|
2921
|
+
import chalk11 from "chalk";
|
|
2525
2922
|
function getOutputFormat3(cmd) {
|
|
2526
2923
|
const config = loadConfig();
|
|
2527
2924
|
const globalOpts = cmd.optsWithGlobals();
|
|
2528
2925
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2529
2926
|
}
|
|
2530
|
-
function
|
|
2927
|
+
function getOverrides3(cmd) {
|
|
2531
2928
|
const opts = cmd.optsWithGlobals();
|
|
2532
2929
|
return { project: opts.project, branch: opts.branch };
|
|
2533
2930
|
}
|
|
@@ -2536,7 +2933,7 @@ function registerLinkCommands(program) {
|
|
|
2536
2933
|
link.command("list").description("List links for an entity").argument("<ref>", "Source entity reference").option("--direction <dir>", "Link direction: FORWARD or BACKWARD", "FORWARD").action(async (ref, options, cmd) => {
|
|
2537
2934
|
try {
|
|
2538
2935
|
const outputFormat = getOutputFormat3(cmd);
|
|
2539
|
-
const overrides =
|
|
2936
|
+
const overrides = getOverrides3(cmd);
|
|
2540
2937
|
const resolved = parseEntityReference(ref, overrides);
|
|
2541
2938
|
const api = createApiClient();
|
|
2542
2939
|
const direction = options.direction.toUpperCase();
|
|
@@ -2558,7 +2955,7 @@ function registerLinkCommands(program) {
|
|
|
2558
2955
|
});
|
|
2559
2956
|
link.command("create").description("Create a link between two entities").argument("<sourceRef>", "Source entity reference").argument("<linkId>", "Link ID").argument("<targetRef>", "Target entity reference").action(async (sourceRef, linkId, targetRef, _options, cmd) => {
|
|
2560
2957
|
try {
|
|
2561
|
-
const overrides =
|
|
2958
|
+
const overrides = getOverrides3(cmd);
|
|
2562
2959
|
const source = parseEntityReference(sourceRef, overrides);
|
|
2563
2960
|
const target = parseEntityReference(targetRef, overrides);
|
|
2564
2961
|
const api = createApiClient();
|
|
@@ -2571,14 +2968,14 @@ function registerLinkCommands(program) {
|
|
|
2571
2968
|
target.entityId,
|
|
2572
2969
|
target.entityBranch
|
|
2573
2970
|
);
|
|
2574
|
-
console.log(
|
|
2971
|
+
console.log(chalk11.green(`Link "${linkId}" created: ${source.entityId} \u2192 ${target.entityId}`));
|
|
2575
2972
|
} catch (error) {
|
|
2576
2973
|
handleError(error);
|
|
2577
2974
|
}
|
|
2578
2975
|
});
|
|
2579
2976
|
link.command("delete").description("Delete a link").argument("<sourceRef>", "Source entity reference").argument("<linkId>", "Link ID").argument("[targetRef]", "Target entity reference (optional, deletes all targets if omitted)").action(async (sourceRef, linkId, targetRef, _options, cmd) => {
|
|
2580
2977
|
try {
|
|
2581
|
-
const overrides =
|
|
2978
|
+
const overrides = getOverrides3(cmd);
|
|
2582
2979
|
const source = parseEntityReference(sourceRef, overrides);
|
|
2583
2980
|
const api = createApiClient();
|
|
2584
2981
|
if (targetRef) {
|
|
@@ -2592,7 +2989,7 @@ function registerLinkCommands(program) {
|
|
|
2592
2989
|
target.entityId,
|
|
2593
2990
|
target.entityBranch
|
|
2594
2991
|
);
|
|
2595
|
-
console.log(
|
|
2992
|
+
console.log(chalk11.green(`Link "${linkId}" deleted: ${source.entityId} \u2192 ${target.entityId}`));
|
|
2596
2993
|
} else {
|
|
2597
2994
|
await api.storage.deleteLink(
|
|
2598
2995
|
source.projectId,
|
|
@@ -2601,7 +2998,7 @@ function registerLinkCommands(program) {
|
|
|
2601
2998
|
source.entityBranch,
|
|
2602
2999
|
linkId
|
|
2603
3000
|
);
|
|
2604
|
-
console.log(
|
|
3001
|
+
console.log(chalk11.green(`All links with ID "${linkId}" from "${source.entityId}" deleted.`));
|
|
2605
3002
|
}
|
|
2606
3003
|
} catch (error) {
|
|
2607
3004
|
handleError(error);
|
|
@@ -2610,13 +3007,13 @@ function registerLinkCommands(program) {
|
|
|
2610
3007
|
}
|
|
2611
3008
|
|
|
2612
3009
|
// src/commands/event/index.ts
|
|
2613
|
-
import
|
|
3010
|
+
import chalk12 from "chalk";
|
|
2614
3011
|
function getOutputFormat4(cmd) {
|
|
2615
3012
|
const config = loadConfig();
|
|
2616
3013
|
const globalOpts = cmd.optsWithGlobals();
|
|
2617
3014
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2618
3015
|
}
|
|
2619
|
-
function
|
|
3016
|
+
function getOverrides4(cmd) {
|
|
2620
3017
|
const opts = cmd.optsWithGlobals();
|
|
2621
3018
|
return { project: opts.project, branch: opts.branch };
|
|
2622
3019
|
}
|
|
@@ -2625,7 +3022,7 @@ function registerEventCommands(program) {
|
|
|
2625
3022
|
event.command("list").description("List events for an entity").argument("<ref>", "Entity reference").action(async (ref, _options, cmd) => {
|
|
2626
3023
|
try {
|
|
2627
3024
|
const outputFormat = getOutputFormat4(cmd);
|
|
2628
|
-
const overrides =
|
|
3025
|
+
const overrides = getOverrides4(cmd);
|
|
2629
3026
|
const resolved = parseEntityReference(ref, overrides);
|
|
2630
3027
|
const api = createApiClient();
|
|
2631
3028
|
const events = await api.storage.getEvents(resolved);
|
|
@@ -2647,7 +3044,7 @@ function registerEventCommands(program) {
|
|
|
2647
3044
|
event.command("get").description("Get a specific event").argument("<ref>", "Entity reference").argument("<eventId>", "Event ID").argument("<occurrenceId>", "Occurrence ID").action(async (ref, eventId, occurrenceId, _options, cmd) => {
|
|
2648
3045
|
try {
|
|
2649
3046
|
const outputFormat = getOutputFormat4(cmd);
|
|
2650
|
-
const overrides =
|
|
3047
|
+
const overrides = getOverrides4(cmd);
|
|
2651
3048
|
const resolved = parseEntityReference(ref, overrides);
|
|
2652
3049
|
const api = createApiClient();
|
|
2653
3050
|
const event2 = await api.storage.getEvent(resolved, eventId, occurrenceId);
|
|
@@ -2658,8 +3055,8 @@ function registerEventCommands(program) {
|
|
|
2658
3055
|
});
|
|
2659
3056
|
event.command("create").description("Create one or more events (body from JSON file or stdin)").argument("[file]", "JSON file containing a BareEvent array; defaults to stdin").action(async (file) => {
|
|
2660
3057
|
try {
|
|
2661
|
-
const
|
|
2662
|
-
const body = file ?
|
|
3058
|
+
const fs14 = await import("fs");
|
|
3059
|
+
const body = file ? fs14.readFileSync(file, "utf-8") : await new Promise((resolve, reject) => {
|
|
2663
3060
|
let data = "";
|
|
2664
3061
|
process.stdin.setEncoding("utf-8");
|
|
2665
3062
|
process.stdin.on("data", (chunk) => {
|
|
@@ -2672,7 +3069,7 @@ function registerEventCommands(program) {
|
|
|
2672
3069
|
const api = createApiClient();
|
|
2673
3070
|
const arr = Array.isArray(events) ? events : [events];
|
|
2674
3071
|
await api.storage.createEvents(arr);
|
|
2675
|
-
console.log(
|
|
3072
|
+
console.log(chalk12.green(`${arr.length} event(s) created.`));
|
|
2676
3073
|
} catch (error) {
|
|
2677
3074
|
handleError(error);
|
|
2678
3075
|
}
|
|
@@ -2695,11 +3092,11 @@ function registerEventCommands(program) {
|
|
|
2695
3092
|
});
|
|
2696
3093
|
event.command("delete").description("Delete an event").argument("<ref>", "Entity reference").argument("<eventId>", "Event ID").argument("<occurrenceId>", "Occurrence ID").action(async (ref, eventId, occurrenceId, _options, cmd) => {
|
|
2697
3094
|
try {
|
|
2698
|
-
const overrides =
|
|
3095
|
+
const overrides = getOverrides4(cmd);
|
|
2699
3096
|
const resolved = parseEntityReference(ref, overrides);
|
|
2700
3097
|
const api = createApiClient();
|
|
2701
3098
|
await api.storage.deleteEvent(resolved, eventId, occurrenceId);
|
|
2702
|
-
console.log(
|
|
3099
|
+
console.log(chalk12.green(`Event "${eventId}/${occurrenceId}" deleted.`));
|
|
2703
3100
|
} catch (error) {
|
|
2704
3101
|
handleError(error);
|
|
2705
3102
|
}
|
|
@@ -2707,13 +3104,13 @@ function registerEventCommands(program) {
|
|
|
2707
3104
|
}
|
|
2708
3105
|
|
|
2709
3106
|
// src/commands/branch/index.ts
|
|
2710
|
-
import
|
|
3107
|
+
import chalk13 from "chalk";
|
|
2711
3108
|
function getOutputFormat5(cmd) {
|
|
2712
3109
|
const config = loadConfig();
|
|
2713
3110
|
const globalOpts = cmd.optsWithGlobals();
|
|
2714
3111
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2715
3112
|
}
|
|
2716
|
-
function
|
|
3113
|
+
function getOverrides5(cmd) {
|
|
2717
3114
|
const opts = cmd.optsWithGlobals();
|
|
2718
3115
|
return { project: opts.project, branch: opts.branch };
|
|
2719
3116
|
}
|
|
@@ -2722,11 +3119,11 @@ function registerBranchCommands(program) {
|
|
|
2722
3119
|
branch.command("list").description("List branches for a project").argument("[projectId]", "Project ID (uses default if omitted)").action(async (projectId, _options, cmd) => {
|
|
2723
3120
|
try {
|
|
2724
3121
|
const outputFormat = getOutputFormat5(cmd);
|
|
2725
|
-
const overrides =
|
|
3122
|
+
const overrides = getOverrides5(cmd);
|
|
2726
3123
|
const config = loadConfig();
|
|
2727
3124
|
const pid = projectId ?? overrides.project ?? config.defaults.project;
|
|
2728
3125
|
if (!pid) {
|
|
2729
|
-
console.error(
|
|
3126
|
+
console.error(chalk13.red("No project specified. Pass a project ID or set defaults.project."));
|
|
2730
3127
|
process.exit(1);
|
|
2731
3128
|
}
|
|
2732
3129
|
const api = createApiClient();
|
|
@@ -2750,7 +3147,7 @@ function registerBranchCommands(program) {
|
|
|
2750
3147
|
sourceProjectBranch: options.source,
|
|
2751
3148
|
targetProjectBranch: branchName
|
|
2752
3149
|
});
|
|
2753
|
-
console.log(
|
|
3150
|
+
console.log(chalk13.green(`Branch "${branchName}" created in project "${projectId}" from "${options.source}".`));
|
|
2754
3151
|
} catch (error) {
|
|
2755
3152
|
handleError(error);
|
|
2756
3153
|
}
|
|
@@ -2759,14 +3156,14 @@ function registerBranchCommands(program) {
|
|
|
2759
3156
|
try {
|
|
2760
3157
|
const api = createApiClient();
|
|
2761
3158
|
await api.storage.deleteProjectBranch(projectId, branchName);
|
|
2762
|
-
console.log(
|
|
3159
|
+
console.log(chalk13.green(`Branch "${branchName}" deleted from project "${projectId}".`));
|
|
2763
3160
|
} catch (error) {
|
|
2764
3161
|
handleError(error);
|
|
2765
3162
|
}
|
|
2766
3163
|
});
|
|
2767
3164
|
branch.command("merge").description("Merge an entity from one branch to another").requiredOption("--source <ref>", "Source entity reference (projectId/branch/entityId/entityBranch)").requiredOption("--target <ref>", "Target project reference (projectId/branch)").option("--link-id <linkId>", "Link ID for the merge", "main").option("--deep", "Deep merge (include linked entities)", false).action(async (options, cmd) => {
|
|
2768
3165
|
try {
|
|
2769
|
-
const overrides =
|
|
3166
|
+
const overrides = getOverrides5(cmd);
|
|
2770
3167
|
const source = parseEntityReference(options.source, overrides);
|
|
2771
3168
|
const targetParts = options.target.split("/");
|
|
2772
3169
|
const api = createApiClient();
|
|
@@ -2780,7 +3177,7 @@ function registerBranchCommands(program) {
|
|
|
2780
3177
|
linkId: options.linkId,
|
|
2781
3178
|
deepMerge: options.deep
|
|
2782
3179
|
});
|
|
2783
|
-
console.log(
|
|
3180
|
+
console.log(chalk13.green("Merge completed."));
|
|
2784
3181
|
} catch (error) {
|
|
2785
3182
|
handleError(error);
|
|
2786
3183
|
}
|
|
@@ -2795,7 +3192,7 @@ function registerBranchCommands(program) {
|
|
|
2795
3192
|
forkProjectName: options.name ?? forkProjectId,
|
|
2796
3193
|
forkProjectDescription: options.description
|
|
2797
3194
|
});
|
|
2798
|
-
console.log(
|
|
3195
|
+
console.log(chalk13.green(`Project "${projectId}" forked to "${forkProjectId}".`));
|
|
2799
3196
|
} catch (error) {
|
|
2800
3197
|
handleError(error);
|
|
2801
3198
|
}
|
|
@@ -2803,24 +3200,37 @@ function registerBranchCommands(program) {
|
|
|
2803
3200
|
}
|
|
2804
3201
|
|
|
2805
3202
|
// src/commands/table/index.ts
|
|
2806
|
-
import
|
|
2807
|
-
import * as
|
|
2808
|
-
import * as
|
|
3203
|
+
import chalk14 from "chalk";
|
|
3204
|
+
import * as fs4 from "fs";
|
|
3205
|
+
import * as path3 from "path";
|
|
2809
3206
|
function getOutputFormat6(cmd) {
|
|
2810
3207
|
const config = loadConfig();
|
|
2811
3208
|
const globalOpts = cmd.optsWithGlobals();
|
|
2812
3209
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2813
3210
|
}
|
|
2814
|
-
function
|
|
3211
|
+
function getOverrides6(cmd) {
|
|
2815
3212
|
const opts = cmd.optsWithGlobals();
|
|
2816
3213
|
return { project: opts.project, branch: opts.branch };
|
|
2817
3214
|
}
|
|
3215
|
+
function deriveOutFile(entityId, extension, archive, compression) {
|
|
3216
|
+
let name = `${entityId}${extension}`;
|
|
3217
|
+
if (archive === "zip") {
|
|
3218
|
+
name += ".zip";
|
|
3219
|
+
} else if (archive === "tar") {
|
|
3220
|
+
name += ".tar";
|
|
3221
|
+
}
|
|
3222
|
+
if (archive !== "zip" && compression) {
|
|
3223
|
+
const suffix = { gzip: ".gz", bzip2: ".bz2", xz: ".xz", zstd: ".zst" };
|
|
3224
|
+
name += suffix[compression] ?? "";
|
|
3225
|
+
}
|
|
3226
|
+
return name;
|
|
3227
|
+
}
|
|
2818
3228
|
function registerTableCommands(program) {
|
|
2819
3229
|
const table = program.command("table").description("Manage tables");
|
|
2820
3230
|
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) => {
|
|
2821
3231
|
try {
|
|
2822
3232
|
const outputFormat = getOutputFormat6(cmd);
|
|
2823
|
-
const overrides =
|
|
3233
|
+
const overrides = getOverrides6(cmd);
|
|
2824
3234
|
const resolved = parseEntityReference(ref, overrides);
|
|
2825
3235
|
const api = createApiClient();
|
|
2826
3236
|
const request = {};
|
|
@@ -2860,29 +3270,28 @@ function registerTableCommands(program) {
|
|
|
2860
3270
|
console.log(colNames.map((c) => row2[c] ?? "").join(" "));
|
|
2861
3271
|
}
|
|
2862
3272
|
} else {
|
|
2863
|
-
console.log(
|
|
3273
|
+
console.log(chalk14.dim(`${snapshot.rows.length} rows \xD7 ${snapshot.columns.length} columns`));
|
|
2864
3274
|
format(tableData, { format: outputFormat, columns: colNames });
|
|
2865
3275
|
}
|
|
2866
3276
|
} catch (error) {
|
|
2867
3277
|
handleError(error);
|
|
2868
3278
|
}
|
|
2869
3279
|
});
|
|
2870
|
-
table.command("import").description("Import data from a
|
|
3280
|
+
table.command("import").description("Import data from a file (any supported format \u2014 see `table import-formats`)").argument("<ref>", "Table entity reference").argument("<file>", "File to import").option("--selection <id>", "Pin a sheet / inner-table id for multi-table sources (Excel sheets, SQLite tables, archive entries)").action(async (ref, file, options, cmd) => {
|
|
2871
3281
|
try {
|
|
2872
|
-
const overrides =
|
|
3282
|
+
const overrides = getOverrides6(cmd);
|
|
2873
3283
|
const resolved = parseEntityReference(ref, overrides);
|
|
2874
|
-
if (!
|
|
2875
|
-
console.error(
|
|
3284
|
+
if (!fs4.existsSync(file)) {
|
|
3285
|
+
console.error(chalk14.red(`File not found: ${file}`));
|
|
2876
3286
|
process.exit(1);
|
|
2877
3287
|
}
|
|
2878
3288
|
const api = createApiClient();
|
|
2879
|
-
const fileBuffer =
|
|
3289
|
+
const fileBuffer = fs4.readFileSync(file);
|
|
2880
3290
|
const blob = new Blob([fileBuffer]);
|
|
2881
3291
|
const formData = new FormData();
|
|
2882
|
-
formData.append("content", blob,
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
const importId = await api.storage.importTable(resolved, formData, columnHeaders);
|
|
3292
|
+
formData.append("content", blob, path3.basename(file));
|
|
3293
|
+
console.log(`Importing ${path3.basename(file)} ...`);
|
|
3294
|
+
const importId = await api.storage.importTable(resolved, formData, options.selection);
|
|
2886
3295
|
console.log(`Import started (ID: ${importId}). Waiting for completion ...`);
|
|
2887
3296
|
const pollInterval = 1e3;
|
|
2888
3297
|
const maxAttempts = 300;
|
|
@@ -2891,40 +3300,118 @@ function registerTableCommands(program) {
|
|
|
2891
3300
|
const imp = await api.storage.getImport(resolved, importId);
|
|
2892
3301
|
if (imp.finished !== null) {
|
|
2893
3302
|
if (imp.succeeded) {
|
|
2894
|
-
console.log(
|
|
3303
|
+
console.log(chalk14.green(`Import completed successfully (${imp.duration}ms).`));
|
|
2895
3304
|
} else {
|
|
2896
|
-
console.error(
|
|
3305
|
+
console.error(chalk14.red(`Import failed: ${imp.error}`));
|
|
2897
3306
|
process.exit(1);
|
|
2898
3307
|
}
|
|
2899
3308
|
return;
|
|
2900
3309
|
}
|
|
2901
3310
|
}
|
|
2902
|
-
console.error(
|
|
3311
|
+
console.error(chalk14.yellow("Import still in progress. Check status later."));
|
|
2903
3312
|
} catch (error) {
|
|
2904
3313
|
handleError(error);
|
|
2905
3314
|
}
|
|
2906
3315
|
});
|
|
2907
|
-
table.command("
|
|
3316
|
+
table.command("import-formats").description("List supported import formats").action(async (_options, cmd) => {
|
|
2908
3317
|
try {
|
|
2909
|
-
const
|
|
3318
|
+
const outputFormat = getOutputFormat6(cmd);
|
|
3319
|
+
const api = createApiClient();
|
|
3320
|
+
const response = await api.storage.getSupportedImportFormats();
|
|
3321
|
+
if (outputFormat === "json") {
|
|
3322
|
+
format(response, { format: outputFormat });
|
|
3323
|
+
return;
|
|
3324
|
+
}
|
|
3325
|
+
const rows = response.formats.map((f) => ({
|
|
3326
|
+
id: f.id,
|
|
3327
|
+
displayName: f.displayName,
|
|
3328
|
+
category: f.category,
|
|
3329
|
+
extensions: f.extensions.join(", "),
|
|
3330
|
+
mimeTypes: f.mimeTypes.join(", "),
|
|
3331
|
+
multiTable: f.multiTable ? "yes" : "no",
|
|
3332
|
+
userDefined: f.userDefined ? "yes" : "no"
|
|
3333
|
+
}));
|
|
3334
|
+
format(rows, { format: outputFormat, columns: ["id", "displayName", "category", "extensions", "mimeTypes", "multiTable", "userDefined"] });
|
|
3335
|
+
} catch (error) {
|
|
3336
|
+
handleError(error);
|
|
3337
|
+
}
|
|
3338
|
+
});
|
|
3339
|
+
table.command("export").description("Export table data in any supported format (see `table export-formats`)").argument("<ref>", "Table entity reference").argument("<format>", "Export format (csv, tsv, excel, parquet, arrow, orc, avro, json, jsonl, yaml, xml, html, pdf, sqlite, duckdb, hdf5, netcdf, ...)").option("--out <file>", "Output file").option("--compression <algorithm>", "Compression wrapper: gzip, bzip2, xz, or zstd").option("--archive <algorithm>", "Archive wrapper: zip or tar").option("--rows <range>", "Row range (e.g., 0:1000) \u2014 half-open").option("--cols <range>", "Column range (e.g., 0:5) \u2014 half-open").option("--delimiter <char>", "CSV/TSV only: single-character delimiter override").option("--quote <char>", 'CSV/TSV only: quote character (use "" for empty)').option("--null <token>", 'CSV/TSV only: null token (default "?")').option("--no-quote-all", "CSV/TSV only: only quote fields when necessary (default quotes every field)").option("--async", "Queue an async export (with progress + later re-download) instead of streaming directly to disk", false).action(async (ref, fmt, options, cmd) => {
|
|
3340
|
+
try {
|
|
3341
|
+
const overrides = getOverrides6(cmd);
|
|
2910
3342
|
const resolved = parseEntityReference(ref, overrides);
|
|
2911
3343
|
const api = createApiClient();
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
if (
|
|
2915
|
-
|
|
2916
|
-
defaultExt = ".csv";
|
|
2917
|
-
} else if (fmt.toLowerCase() === "excel" || fmt.toLowerCase() === "xlsx") {
|
|
2918
|
-
response = await api.storage.exportTableExcel(resolved);
|
|
2919
|
-
defaultExt = ".xlsx";
|
|
2920
|
-
} else {
|
|
2921
|
-
console.error(chalk13.red(`Unknown format: "${fmt}". Use "csv" or "excel".`));
|
|
3344
|
+
const formats = await api.storage.getSupportedExportFormats();
|
|
3345
|
+
const format2 = formats.formats.find((f) => f.id.toLowerCase() === fmt.toLowerCase());
|
|
3346
|
+
if (!format2) {
|
|
3347
|
+
console.error(chalk14.red(`Unknown format: "${fmt}". Run \`diafunc table export-formats\` to see the catalogue.`));
|
|
2922
3348
|
process.exit(1);
|
|
2923
3349
|
}
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
3350
|
+
if (options.compression && !formats.compressionAlgorithms.includes(options.compression)) {
|
|
3351
|
+
console.error(chalk14.red(`Unknown compression: "${options.compression}". Use one of ${formats.compressionAlgorithms.join(", ")}.`));
|
|
3352
|
+
process.exit(1);
|
|
3353
|
+
}
|
|
3354
|
+
if (options.archive && !formats.archiveAlgorithms.includes(options.archive)) {
|
|
3355
|
+
console.error(chalk14.red(`Unknown archive: "${options.archive}". Use one of ${formats.archiveAlgorithms.join(", ")}.`));
|
|
3356
|
+
process.exit(1);
|
|
3357
|
+
}
|
|
3358
|
+
const exportOptions = {
|
|
3359
|
+
compression: options.compression,
|
|
3360
|
+
archive: options.archive
|
|
3361
|
+
};
|
|
3362
|
+
if (options.rows) {
|
|
3363
|
+
const [from, to] = String(options.rows).split(":").map(Number);
|
|
3364
|
+
if (!isNaN(from)) exportOptions.fromRow = from;
|
|
3365
|
+
if (!isNaN(to)) exportOptions.toRow = to;
|
|
3366
|
+
}
|
|
3367
|
+
if (options.cols) {
|
|
3368
|
+
const [from, to] = String(options.cols).split(":").map(Number);
|
|
3369
|
+
if (!isNaN(from)) exportOptions.fromColumn = from;
|
|
3370
|
+
if (!isNaN(to)) exportOptions.toColumn = to;
|
|
3371
|
+
}
|
|
3372
|
+
const csvLike = format2.id === "csv" || format2.id === "tsv";
|
|
3373
|
+
if (csvLike) {
|
|
3374
|
+
if (options.delimiter !== void 0) exportOptions.delimiter = options.delimiter;
|
|
3375
|
+
if (options.quote !== void 0) exportOptions.quote = options.quote;
|
|
3376
|
+
if (options.null !== void 0) exportOptions.nullValue = options.null;
|
|
3377
|
+
if (options.quoteAll === false) exportOptions.quoteAll = false;
|
|
3378
|
+
}
|
|
3379
|
+
const useStream = !options.async;
|
|
3380
|
+
if (useStream) {
|
|
3381
|
+
const response = await api.storage.streamExport(resolved, format2.id, exportOptions);
|
|
3382
|
+
const outFile = options.out ?? deriveOutFile(resolved.entityId, format2.extension, options.archive, options.compression);
|
|
3383
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
3384
|
+
fs4.writeFileSync(outFile, buffer);
|
|
3385
|
+
console.log(chalk14.green(`Table streamed to ${outFile}`));
|
|
3386
|
+
} else {
|
|
3387
|
+
const exportId = await api.storage.exportTable(resolved, format2.id, exportOptions);
|
|
3388
|
+
console.log(chalk14.green(`Export queued (ID: ${exportId}).`));
|
|
3389
|
+
console.log(`Poll progress: diafunc table exports get ${exportId} --ref ${ref}`);
|
|
3390
|
+
}
|
|
3391
|
+
} catch (error) {
|
|
3392
|
+
handleError(error);
|
|
3393
|
+
}
|
|
3394
|
+
});
|
|
3395
|
+
table.command("export-formats").description("List supported export formats").action(async (_options, cmd) => {
|
|
3396
|
+
try {
|
|
3397
|
+
const outputFormat = getOutputFormat6(cmd);
|
|
3398
|
+
const api = createApiClient();
|
|
3399
|
+
const response = await api.storage.getSupportedExportFormats();
|
|
3400
|
+
if (outputFormat === "json") {
|
|
3401
|
+
format(response, { format: outputFormat });
|
|
3402
|
+
return;
|
|
3403
|
+
}
|
|
3404
|
+
const rows = response.formats.map((f) => ({
|
|
3405
|
+
id: f.id,
|
|
3406
|
+
displayName: f.displayName,
|
|
3407
|
+
category: f.category,
|
|
3408
|
+
extension: f.extension,
|
|
3409
|
+
mimeType: f.mimeType,
|
|
3410
|
+
knownLimitations: f.knownLimitations.join(" / ")
|
|
3411
|
+
}));
|
|
3412
|
+
format(rows, { format: outputFormat, columns: ["id", "displayName", "category", "extension", "mimeType", "knownLimitations"] });
|
|
3413
|
+
console.log(chalk14.dim(`Compression: ${response.compressionAlgorithms.join(", ")}`));
|
|
3414
|
+
console.log(chalk14.dim(`Archive: ${response.archiveAlgorithms.join(", ")}`));
|
|
2928
3415
|
} catch (error) {
|
|
2929
3416
|
handleError(error);
|
|
2930
3417
|
}
|
|
@@ -2932,22 +3419,44 @@ function registerTableCommands(program) {
|
|
|
2932
3419
|
const row = table.command("row").description("Manage table rows");
|
|
2933
3420
|
row.command("add").description("Append a row to a table").argument("<ref>", "Table entity reference").action(async (ref, _options, cmd) => {
|
|
2934
3421
|
try {
|
|
2935
|
-
const overrides =
|
|
3422
|
+
const overrides = getOverrides6(cmd);
|
|
2936
3423
|
const resolved = parseEntityReference(ref, overrides);
|
|
2937
3424
|
const api = createApiClient();
|
|
2938
3425
|
await api.storage.appendRow(resolved);
|
|
2939
|
-
console.log(
|
|
3426
|
+
console.log(chalk14.green("Row appended."));
|
|
2940
3427
|
} catch (error) {
|
|
2941
3428
|
handleError(error);
|
|
2942
3429
|
}
|
|
2943
3430
|
});
|
|
2944
|
-
row.command("
|
|
3431
|
+
row.command("insert").description("Insert an empty row at the given index, shifting existing rows down").argument("<ref>", "Table entity reference").argument("<index>", "Row index").action(async (ref, index, _options, cmd) => {
|
|
2945
3432
|
try {
|
|
2946
|
-
const overrides =
|
|
3433
|
+
const overrides = getOverrides6(cmd);
|
|
3434
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3435
|
+
const api = createApiClient();
|
|
3436
|
+
await api.storage.insertRow(resolved, parseInt(index, 10));
|
|
3437
|
+
console.log(chalk14.green(`Row inserted at index ${index}.`));
|
|
3438
|
+
} catch (error) {
|
|
3439
|
+
handleError(error);
|
|
3440
|
+
}
|
|
3441
|
+
});
|
|
3442
|
+
row.command("remove").description("Remove a row in place (blanks the row; no shift)").argument("<ref>", "Table entity reference").argument("<index>", "Row index").action(async (ref, index, _options, cmd) => {
|
|
3443
|
+
try {
|
|
3444
|
+
const overrides = getOverrides6(cmd);
|
|
3445
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3446
|
+
const api = createApiClient();
|
|
3447
|
+
await api.storage.removeRow(resolved, parseInt(index, 10));
|
|
3448
|
+
console.log(chalk14.green(`Row ${index} removed.`));
|
|
3449
|
+
} catch (error) {
|
|
3450
|
+
handleError(error);
|
|
3451
|
+
}
|
|
3452
|
+
});
|
|
3453
|
+
row.command("delete").description("Delete a row and shift the rows below up by one").argument("<ref>", "Table entity reference").argument("<index>", "Row index").action(async (ref, index, _options, cmd) => {
|
|
3454
|
+
try {
|
|
3455
|
+
const overrides = getOverrides6(cmd);
|
|
2947
3456
|
const resolved = parseEntityReference(ref, overrides);
|
|
2948
3457
|
const api = createApiClient();
|
|
2949
3458
|
await api.storage.deleteRow(resolved, parseInt(index, 10));
|
|
2950
|
-
console.log(
|
|
3459
|
+
console.log(chalk14.green(`Row ${index} deleted.`));
|
|
2951
3460
|
} catch (error) {
|
|
2952
3461
|
handleError(error);
|
|
2953
3462
|
}
|
|
@@ -2955,22 +3464,44 @@ function registerTableCommands(program) {
|
|
|
2955
3464
|
const column = table.command("column").description("Manage table columns");
|
|
2956
3465
|
column.command("add").description("Append a column to a table").argument("<ref>", "Table entity reference").action(async (ref, _options, cmd) => {
|
|
2957
3466
|
try {
|
|
2958
|
-
const overrides =
|
|
3467
|
+
const overrides = getOverrides6(cmd);
|
|
2959
3468
|
const resolved = parseEntityReference(ref, overrides);
|
|
2960
3469
|
const api = createApiClient();
|
|
2961
3470
|
await api.storage.appendColumn(resolved);
|
|
2962
|
-
console.log(
|
|
3471
|
+
console.log(chalk14.green("Column appended."));
|
|
2963
3472
|
} catch (error) {
|
|
2964
3473
|
handleError(error);
|
|
2965
3474
|
}
|
|
2966
3475
|
});
|
|
2967
|
-
column.command("
|
|
3476
|
+
column.command("insert").description("Insert an empty column at the given index, shifting existing columns right").argument("<ref>", "Table entity reference").argument("<index>", "Column index").action(async (ref, index, _options, cmd) => {
|
|
2968
3477
|
try {
|
|
2969
|
-
const overrides =
|
|
3478
|
+
const overrides = getOverrides6(cmd);
|
|
3479
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3480
|
+
const api = createApiClient();
|
|
3481
|
+
await api.storage.insertColumn(resolved, parseInt(index, 10));
|
|
3482
|
+
console.log(chalk14.green(`Column inserted at index ${index}.`));
|
|
3483
|
+
} catch (error) {
|
|
3484
|
+
handleError(error);
|
|
3485
|
+
}
|
|
3486
|
+
});
|
|
3487
|
+
column.command("remove").description("Remove a column in place (blanks the column; no shift)").argument("<ref>", "Table entity reference").argument("<index>", "Column index").action(async (ref, index, _options, cmd) => {
|
|
3488
|
+
try {
|
|
3489
|
+
const overrides = getOverrides6(cmd);
|
|
3490
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3491
|
+
const api = createApiClient();
|
|
3492
|
+
await api.storage.removeColumn(resolved, parseInt(index, 10));
|
|
3493
|
+
console.log(chalk14.green(`Column ${index} removed.`));
|
|
3494
|
+
} catch (error) {
|
|
3495
|
+
handleError(error);
|
|
3496
|
+
}
|
|
3497
|
+
});
|
|
3498
|
+
column.command("delete").description("Delete a column and shift the columns to its right left by one").argument("<ref>", "Table entity reference").argument("<index>", "Column index").action(async (ref, index, _options, cmd) => {
|
|
3499
|
+
try {
|
|
3500
|
+
const overrides = getOverrides6(cmd);
|
|
2970
3501
|
const resolved = parseEntityReference(ref, overrides);
|
|
2971
3502
|
const api = createApiClient();
|
|
2972
3503
|
await api.storage.deleteColumn(resolved, parseInt(index, 10));
|
|
2973
|
-
console.log(
|
|
3504
|
+
console.log(chalk14.green(`Column ${index} deleted.`));
|
|
2974
3505
|
} catch (error) {
|
|
2975
3506
|
handleError(error);
|
|
2976
3507
|
}
|
|
@@ -2978,7 +3509,7 @@ function registerTableCommands(program) {
|
|
|
2978
3509
|
const cell = table.command("cell").description("Manage table cells");
|
|
2979
3510
|
cell.command("set").description("Set a cell value").argument("<ref>", "Table entity reference").argument("<row>", "Row index").argument("<col>", "Column index").argument("<value>", "Cell value").action(async (ref, row2, col, value, _options, cmd) => {
|
|
2980
3511
|
try {
|
|
2981
|
-
const overrides =
|
|
3512
|
+
const overrides = getOverrides6(cmd);
|
|
2982
3513
|
const resolved = parseEntityReference(ref, overrides);
|
|
2983
3514
|
const api = createApiClient();
|
|
2984
3515
|
await api.storage.mergeCells(resolved, [{
|
|
@@ -2987,29 +3518,141 @@ function registerTableCommands(program) {
|
|
|
2987
3518
|
value,
|
|
2988
3519
|
type: "text"
|
|
2989
3520
|
}]);
|
|
2990
|
-
console.log(
|
|
3521
|
+
console.log(chalk14.green(`Cell [${row2}, ${col}] set to "${value}".`));
|
|
2991
3522
|
} catch (error) {
|
|
2992
3523
|
handleError(error);
|
|
2993
3524
|
}
|
|
2994
3525
|
});
|
|
2995
3526
|
cell.command("delete").description("Delete a cell value").argument("<ref>", "Table entity reference").argument("<row>", "Row index").argument("<col>", "Column index").action(async (ref, row2, col, _options, cmd) => {
|
|
2996
3527
|
try {
|
|
2997
|
-
const overrides =
|
|
3528
|
+
const overrides = getOverrides6(cmd);
|
|
2998
3529
|
const resolved = parseEntityReference(ref, overrides);
|
|
2999
3530
|
const api = createApiClient();
|
|
3000
|
-
await api.storage.
|
|
3001
|
-
console.log(
|
|
3531
|
+
await api.storage.removeCell(resolved, parseInt(row2, 10), parseInt(col, 10));
|
|
3532
|
+
console.log(chalk14.green(`Cell [${row2}, ${col}] deleted.`));
|
|
3002
3533
|
} catch (error) {
|
|
3003
3534
|
handleError(error);
|
|
3004
3535
|
}
|
|
3005
3536
|
});
|
|
3006
3537
|
table.command("clear").description("Clear all data from a table").argument("<ref>", "Table entity reference").action(async (ref, _options, cmd) => {
|
|
3007
3538
|
try {
|
|
3008
|
-
const overrides =
|
|
3539
|
+
const overrides = getOverrides6(cmd);
|
|
3009
3540
|
const resolved = parseEntityReference(ref, overrides);
|
|
3010
3541
|
const api = createApiClient();
|
|
3011
3542
|
await api.storage.clearTable(resolved);
|
|
3012
|
-
console.log(
|
|
3543
|
+
console.log(chalk14.green("Table cleared."));
|
|
3544
|
+
} catch (error) {
|
|
3545
|
+
handleError(error);
|
|
3546
|
+
}
|
|
3547
|
+
});
|
|
3548
|
+
}
|
|
3549
|
+
|
|
3550
|
+
// src/commands/notebook/index.ts
|
|
3551
|
+
import chalk15 from "chalk";
|
|
3552
|
+
import * as fs5 from "fs";
|
|
3553
|
+
import * as path4 from "path";
|
|
3554
|
+
function getOutputFormat7(cmd) {
|
|
3555
|
+
const config = loadConfig();
|
|
3556
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
3557
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3558
|
+
}
|
|
3559
|
+
function getOverrides7(cmd) {
|
|
3560
|
+
const opts = cmd.optsWithGlobals();
|
|
3561
|
+
return { project: opts.project, branch: opts.branch };
|
|
3562
|
+
}
|
|
3563
|
+
function registerNotebookCommands(program) {
|
|
3564
|
+
const notebook = program.command("notebook").description("Export and import notebook bundles");
|
|
3565
|
+
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) => {
|
|
3566
|
+
try {
|
|
3567
|
+
const overrides = getOverrides7(cmd);
|
|
3568
|
+
const ref = parseProjectReference(project, overrides);
|
|
3569
|
+
const api = createApiClient();
|
|
3570
|
+
const request = { rootEntityIds: notebookIds, dataFormat: options.data };
|
|
3571
|
+
if (options.async) {
|
|
3572
|
+
const bundleId = await api.storage.exportBundle(ref.projectId, ref.projectBranch, request);
|
|
3573
|
+
console.log(chalk15.green(`Export queued (bundle ID: ${bundleId}).`));
|
|
3574
|
+
console.log(`Poll progress: diafunc notebook bundles ${project}`);
|
|
3575
|
+
return;
|
|
3576
|
+
}
|
|
3577
|
+
const response = await api.storage.streamBundle(ref.projectId, ref.projectBranch, request);
|
|
3578
|
+
const outFile = options.out ?? "notebooks.dfnb";
|
|
3579
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
3580
|
+
fs5.writeFileSync(outFile, buffer);
|
|
3581
|
+
console.log(chalk15.green(`Bundle written to ${outFile} (${buffer.length} bytes, ${notebookIds.length} notebook(s)).`));
|
|
3582
|
+
} catch (error) {
|
|
3583
|
+
handleError(error);
|
|
3584
|
+
}
|
|
3585
|
+
});
|
|
3586
|
+
notebook.command("import").description("Import a .dfnb bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the .dfnb bundle").option("--on-conflict <policy>", "copy (default), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project, file, options, cmd) => {
|
|
3587
|
+
try {
|
|
3588
|
+
const outputFormat = getOutputFormat7(cmd);
|
|
3589
|
+
const overrides = getOverrides7(cmd);
|
|
3590
|
+
const ref = parseProjectReference(project, overrides);
|
|
3591
|
+
const api = createApiClient();
|
|
3592
|
+
const fileBuffer = fs5.readFileSync(file);
|
|
3593
|
+
const blob = new Blob([fileBuffer]);
|
|
3594
|
+
const formData = new FormData();
|
|
3595
|
+
formData.append("content", blob, path4.basename(file));
|
|
3596
|
+
if (options.preview) {
|
|
3597
|
+
const preview = await api.storage.previewBundleImport(ref.projectId, ref.projectBranch, formData);
|
|
3598
|
+
if (outputFormat === "json") {
|
|
3599
|
+
format(preview, { format: outputFormat });
|
|
3600
|
+
return;
|
|
3601
|
+
}
|
|
3602
|
+
console.log(chalk15.bold(`${preview.kind} bundle \xB7 ${preview.entityCount} entities`));
|
|
3603
|
+
if (preview.sourceProjectId) {
|
|
3604
|
+
console.log(chalk15.dim(`from ${preview.sourceProjectId}/${preview.sourceProjectBranch}` + (preview.createdBy ? ` \xB7 by ${preview.createdBy}` : "")));
|
|
3605
|
+
}
|
|
3606
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3607
|
+
for (const e of preview.entities ?? []) {
|
|
3608
|
+
counts.set(e.type, (counts.get(e.type) ?? 0) + 1);
|
|
3609
|
+
}
|
|
3610
|
+
for (const [type, count] of [...counts.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
3611
|
+
console.log(` ${type}: ${count}`);
|
|
3612
|
+
}
|
|
3613
|
+
if (preview.lossinessNotes && preview.lossinessNotes.length > 0) {
|
|
3614
|
+
console.log(chalk15.yellow("Lossiness:"));
|
|
3615
|
+
for (const note of preview.lossinessNotes) {
|
|
3616
|
+
console.log(chalk15.yellow(` - ${note}`));
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3619
|
+
return;
|
|
3620
|
+
}
|
|
3621
|
+
const result = await api.storage.importBundle(ref.projectId, ref.projectBranch, formData, options.onConflict);
|
|
3622
|
+
if (outputFormat === "json") {
|
|
3623
|
+
format(result, { format: outputFormat });
|
|
3624
|
+
return;
|
|
3625
|
+
}
|
|
3626
|
+
console.log(chalk15.green(`Imported ${result.entityCount} entities, ${result.linkCount} links.`));
|
|
3627
|
+
console.log(`Notebook id(s): ${result.rootEntityIds.join(", ")}`);
|
|
3628
|
+
} catch (error) {
|
|
3629
|
+
handleError(error);
|
|
3630
|
+
}
|
|
3631
|
+
});
|
|
3632
|
+
notebook.command("bundles").description("List notebook-bundle export jobs for a project").argument("<project>", "Project reference (projectId or projectId/branch)").action(async (project, _options, cmd) => {
|
|
3633
|
+
try {
|
|
3634
|
+
const outputFormat = getOutputFormat7(cmd);
|
|
3635
|
+
const overrides = getOverrides7(cmd);
|
|
3636
|
+
const ref = parseProjectReference(project, overrides);
|
|
3637
|
+
const api = createApiClient();
|
|
3638
|
+
const bundles = await api.storage.getBundles(ref.projectId, ref.projectBranch);
|
|
3639
|
+
if (outputFormat === "json") {
|
|
3640
|
+
format(bundles, { format: outputFormat });
|
|
3641
|
+
return;
|
|
3642
|
+
}
|
|
3643
|
+
const rows = bundles.map((b) => ({
|
|
3644
|
+
bundleId: b.bundleId,
|
|
3645
|
+
kind: b.kind,
|
|
3646
|
+
filename: b.filename,
|
|
3647
|
+
entities: b.entityCount ?? "",
|
|
3648
|
+
progress: b.progress,
|
|
3649
|
+
succeeded: b.succeeded ?? "",
|
|
3650
|
+
error: b.error ?? ""
|
|
3651
|
+
}));
|
|
3652
|
+
format(rows, {
|
|
3653
|
+
format: outputFormat,
|
|
3654
|
+
columns: ["bundleId", "kind", "filename", "entities", "progress", "succeeded", "error"]
|
|
3655
|
+
});
|
|
3013
3656
|
} catch (error) {
|
|
3014
3657
|
handleError(error);
|
|
3015
3658
|
}
|
|
@@ -3017,10 +3660,10 @@ function registerTableCommands(program) {
|
|
|
3017
3660
|
}
|
|
3018
3661
|
|
|
3019
3662
|
// src/commands/function/index.ts
|
|
3020
|
-
import
|
|
3021
|
-
import * as
|
|
3663
|
+
import chalk16 from "chalk";
|
|
3664
|
+
import * as fs6 from "fs";
|
|
3022
3665
|
import * as os2 from "os";
|
|
3023
|
-
import * as
|
|
3666
|
+
import * as path5 from "path";
|
|
3024
3667
|
import { spawn } from "child_process";
|
|
3025
3668
|
import { randomUUID } from "crypto";
|
|
3026
3669
|
|
|
@@ -3073,12 +3716,12 @@ function buildFunctionEntity(args) {
|
|
|
3073
3716
|
}
|
|
3074
3717
|
|
|
3075
3718
|
// src/commands/function/index.ts
|
|
3076
|
-
function
|
|
3719
|
+
function getOutputFormat8(cmd) {
|
|
3077
3720
|
const config = loadConfig();
|
|
3078
3721
|
const globalOpts = cmd.optsWithGlobals();
|
|
3079
3722
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3080
3723
|
}
|
|
3081
|
-
function
|
|
3724
|
+
function getOverrides8(cmd) {
|
|
3082
3725
|
const opts = cmd.optsWithGlobals();
|
|
3083
3726
|
return { project: opts.project, branch: opts.branch };
|
|
3084
3727
|
}
|
|
@@ -3096,8 +3739,8 @@ function registerFunctionCommands(program) {
|
|
|
3096
3739
|
const fn = program.command("function").description("Execute and manage functions");
|
|
3097
3740
|
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) => {
|
|
3098
3741
|
try {
|
|
3099
|
-
const outputFormat =
|
|
3100
|
-
const overrides =
|
|
3742
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3743
|
+
const overrides = getOverrides8(cmd);
|
|
3101
3744
|
const resolved = parseEntityReference(ref, overrides);
|
|
3102
3745
|
const api = createApiClient();
|
|
3103
3746
|
const time = createTimeUuid();
|
|
@@ -3139,7 +3782,7 @@ function registerFunctionCommands(program) {
|
|
|
3139
3782
|
}, isAsync);
|
|
3140
3783
|
if (isAsync) {
|
|
3141
3784
|
if (outputFormat === "human") {
|
|
3142
|
-
console.log(
|
|
3785
|
+
console.log(chalk16.green("Function launched."));
|
|
3143
3786
|
console.log(` Evaluation ID: ${result.evaluationId}`);
|
|
3144
3787
|
} else {
|
|
3145
3788
|
format({ evaluationId: result.evaluationId }, { format: outputFormat });
|
|
@@ -3147,14 +3790,14 @@ function registerFunctionCommands(program) {
|
|
|
3147
3790
|
} else {
|
|
3148
3791
|
if (outputFormat === "human") {
|
|
3149
3792
|
if (result.successful) {
|
|
3150
|
-
console.log(
|
|
3793
|
+
console.log(chalk16.green("Function completed successfully."));
|
|
3151
3794
|
if (result.result) {
|
|
3152
3795
|
console.log(` Result: ${result.result}`);
|
|
3153
3796
|
}
|
|
3154
3797
|
const duration = result.completed - result.started;
|
|
3155
3798
|
console.log(` Duration: ${duration}ms`);
|
|
3156
3799
|
} else {
|
|
3157
|
-
console.log(
|
|
3800
|
+
console.log(chalk16.red("Function failed."));
|
|
3158
3801
|
console.log(` Error: ${result.error}`);
|
|
3159
3802
|
if (result.lineNumber > 0) {
|
|
3160
3803
|
console.log(` Line: ${result.lineNumber}, Column: ${result.columnNumber}`);
|
|
@@ -3162,7 +3805,7 @@ function registerFunctionCommands(program) {
|
|
|
3162
3805
|
}
|
|
3163
3806
|
if (result.outputs?.length) {
|
|
3164
3807
|
console.log();
|
|
3165
|
-
console.log(
|
|
3808
|
+
console.log(chalk16.bold("Outputs:"));
|
|
3166
3809
|
for (const out of result.outputs) {
|
|
3167
3810
|
console.log(` [${out.type}] ${out.output}`);
|
|
3168
3811
|
}
|
|
@@ -3177,8 +3820,8 @@ function registerFunctionCommands(program) {
|
|
|
3177
3820
|
});
|
|
3178
3821
|
fn.command("evaluations").description("List evaluations for a function").argument("<ref>", "Function entity reference").requiredOption("--date <date>", "Date and hour (YYYY-MM-DD-HH in UTC)").action(async (ref, options, cmd) => {
|
|
3179
3822
|
try {
|
|
3180
|
-
const outputFormat =
|
|
3181
|
-
const overrides =
|
|
3823
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3824
|
+
const overrides = getOverrides8(cmd);
|
|
3182
3825
|
const resolved = parseEntityReference(ref, overrides);
|
|
3183
3826
|
const api = createApiClient();
|
|
3184
3827
|
const parts = options.date.split("-").map(Number);
|
|
@@ -3211,16 +3854,16 @@ function registerFunctionCommands(program) {
|
|
|
3211
3854
|
});
|
|
3212
3855
|
fn.command("outputs").description("Get outputs for an evaluation").argument("<projectId>", "Project ID").argument("<evaluationId>", "Evaluation ID").action(async (projectId, evaluationId, _options, cmd) => {
|
|
3213
3856
|
try {
|
|
3214
|
-
const outputFormat =
|
|
3857
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3215
3858
|
const api = createApiClient();
|
|
3216
3859
|
const outputs = await api.evaluation.getOutputs(projectId, evaluationId);
|
|
3217
3860
|
if (outputFormat === "human") {
|
|
3218
3861
|
if (outputs.length === 0) {
|
|
3219
|
-
console.log(
|
|
3862
|
+
console.log(chalk16.dim("No outputs."));
|
|
3220
3863
|
}
|
|
3221
3864
|
for (const out of outputs) {
|
|
3222
3865
|
const time = new Date(out.timestamp).toISOString();
|
|
3223
|
-
console.log(`${
|
|
3866
|
+
console.log(`${chalk16.dim(time)} [${out.type}] ${out.output}`);
|
|
3224
3867
|
}
|
|
3225
3868
|
} else {
|
|
3226
3869
|
format(outputs, { format: outputFormat });
|
|
@@ -3231,8 +3874,8 @@ function registerFunctionCommands(program) {
|
|
|
3231
3874
|
});
|
|
3232
3875
|
fn.command("logs").description("Get logs for a function evaluation").argument("<ref>", "Function entity reference").requiredOption("--date <date>", "Date and hour (YYYY-MM-DD-HH in UTC)").action(async (ref, options, cmd) => {
|
|
3233
3876
|
try {
|
|
3234
|
-
const outputFormat =
|
|
3235
|
-
const overrides =
|
|
3877
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3878
|
+
const overrides = getOverrides8(cmd);
|
|
3236
3879
|
const resolved = parseEntityReference(ref, overrides);
|
|
3237
3880
|
const api = createApiClient();
|
|
3238
3881
|
const parts = options.date.split("-").map(Number);
|
|
@@ -3254,7 +3897,7 @@ function registerFunctionCommands(program) {
|
|
|
3254
3897
|
});
|
|
3255
3898
|
fn.command("stop").description("Stop a running evaluation").argument("<ref>", "Function entity reference").requiredOption("--date <date>", "Date and hour (YYYY-MM-DD-HH in UTC)").argument("<evaluationId>", "Evaluation ID").action(async (ref, evaluationId, options, cmd) => {
|
|
3256
3899
|
try {
|
|
3257
|
-
const overrides =
|
|
3900
|
+
const overrides = getOverrides8(cmd);
|
|
3258
3901
|
const resolved = parseEntityReference(ref, overrides);
|
|
3259
3902
|
const api = createApiClient();
|
|
3260
3903
|
const parts = options.date.split("-").map(Number);
|
|
@@ -3270,14 +3913,14 @@ function registerFunctionCommands(program) {
|
|
|
3270
3913
|
hour,
|
|
3271
3914
|
evaluationId
|
|
3272
3915
|
);
|
|
3273
|
-
console.log(
|
|
3916
|
+
console.log(chalk16.green(`Evaluation ${evaluationId} stopped.`));
|
|
3274
3917
|
} catch (error) {
|
|
3275
3918
|
handleError(error);
|
|
3276
3919
|
}
|
|
3277
3920
|
});
|
|
3278
3921
|
fn.command("engines").description("List available engines").action(async (_options, cmd) => {
|
|
3279
3922
|
try {
|
|
3280
|
-
const outputFormat =
|
|
3923
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3281
3924
|
const api = createApiClient();
|
|
3282
3925
|
const engines = await api.evaluation.getEngines();
|
|
3283
3926
|
format(engines, { format: outputFormat });
|
|
@@ -3287,8 +3930,8 @@ function registerFunctionCommands(program) {
|
|
|
3287
3930
|
});
|
|
3288
3931
|
fn.command("last-evaluation").description("Show the most recent evaluation of a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3289
3932
|
try {
|
|
3290
|
-
const outputFormat =
|
|
3291
|
-
const overrides =
|
|
3933
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3934
|
+
const overrides = getOverrides8(cmd);
|
|
3292
3935
|
const resolved = parseEntityReference(ref, overrides);
|
|
3293
3936
|
const api = createApiClient();
|
|
3294
3937
|
const evaluation = await api.evaluation.getLastEvaluation(
|
|
@@ -3304,10 +3947,10 @@ function registerFunctionCommands(program) {
|
|
|
3304
3947
|
});
|
|
3305
3948
|
fn.command("create").description("Create a new function entity").argument("<ref>", "Function entity reference").option("--language <lang>", "Function language (Java, JavaScript, Kotlin, Python, Scala)", "Java").option("--source <file>", "Initial source code file").option("--name <name>", "Display name (defaults to entityId)").action(async (ref, options, cmd) => {
|
|
3306
3949
|
try {
|
|
3307
|
-
const overrides =
|
|
3950
|
+
const overrides = getOverrides8(cmd);
|
|
3308
3951
|
const resolved = parseEntityReference(ref, overrides);
|
|
3309
3952
|
const api = createApiClient();
|
|
3310
|
-
const sourceCode = options.source ?
|
|
3953
|
+
const sourceCode = options.source ? fs6.readFileSync(options.source, "utf-8") : "";
|
|
3311
3954
|
const entity = buildFunctionEntity({
|
|
3312
3955
|
projectId: resolved.projectId,
|
|
3313
3956
|
projectBranch: resolved.projectBranch,
|
|
@@ -3318,7 +3961,7 @@ function registerFunctionCommands(program) {
|
|
|
3318
3961
|
sourceCode
|
|
3319
3962
|
});
|
|
3320
3963
|
await api.storage.saveEntities([entity]);
|
|
3321
|
-
console.log(
|
|
3964
|
+
console.log(chalk16.green(`Function "${resolved.entityId}" created (${options.language}).`));
|
|
3322
3965
|
} catch (error) {
|
|
3323
3966
|
handleError(error);
|
|
3324
3967
|
}
|
|
@@ -3326,14 +3969,14 @@ function registerFunctionCommands(program) {
|
|
|
3326
3969
|
const source = fn.command("source").description("Get or set function source code");
|
|
3327
3970
|
source.command("get").description("Print the function source code").argument("<ref>", "Function entity reference").option("--out <file>", "Write source to this file instead of stdout").action(async (ref, options, cmd) => {
|
|
3328
3971
|
try {
|
|
3329
|
-
const overrides =
|
|
3972
|
+
const overrides = getOverrides8(cmd);
|
|
3330
3973
|
const resolved = parseEntityReference(ref, overrides);
|
|
3331
3974
|
const api = createApiClient();
|
|
3332
3975
|
const entity = await api.storage.getEntity(resolved, true);
|
|
3333
3976
|
const sourceCode = decodeFunctionSource(entity);
|
|
3334
3977
|
if (options.out) {
|
|
3335
|
-
|
|
3336
|
-
console.log(
|
|
3978
|
+
fs6.writeFileSync(options.out, sourceCode);
|
|
3979
|
+
console.log(chalk16.green(`Source written to ${options.out}`));
|
|
3337
3980
|
} else {
|
|
3338
3981
|
process.stdout.write(sourceCode);
|
|
3339
3982
|
if (!sourceCode.endsWith("\n")) process.stdout.write("\n");
|
|
@@ -3344,10 +3987,10 @@ function registerFunctionCommands(program) {
|
|
|
3344
3987
|
});
|
|
3345
3988
|
source.command("set").description("Replace the function source code from a file or stdin").argument("<ref>", "Function entity reference").argument("[file]", "Source file; defaults to stdin").action(async (ref, file, _options, cmd) => {
|
|
3346
3989
|
try {
|
|
3347
|
-
const overrides =
|
|
3990
|
+
const overrides = getOverrides8(cmd);
|
|
3348
3991
|
const resolved = parseEntityReference(ref, overrides);
|
|
3349
3992
|
const api = createApiClient();
|
|
3350
|
-
const sourceCode = file ?
|
|
3993
|
+
const sourceCode = file ? fs6.readFileSync(file, "utf-8") : await new Promise((resolve, reject) => {
|
|
3351
3994
|
let data = "";
|
|
3352
3995
|
process.stdin.setEncoding("utf-8");
|
|
3353
3996
|
process.stdin.on("data", (chunk) => {
|
|
@@ -3357,36 +4000,36 @@ function registerFunctionCommands(program) {
|
|
|
3357
4000
|
process.stdin.on("error", reject);
|
|
3358
4001
|
});
|
|
3359
4002
|
await api.storage.saveEntityContentBase64(resolved, encodeFunctionSource(sourceCode));
|
|
3360
|
-
console.log(
|
|
4003
|
+
console.log(chalk16.green(`Source updated for "${resolved.entityId}".`));
|
|
3361
4004
|
} catch (error) {
|
|
3362
4005
|
handleError(error);
|
|
3363
4006
|
}
|
|
3364
4007
|
});
|
|
3365
4008
|
fn.command("edit").description("Open the function source in $EDITOR and save on exit").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3366
4009
|
try {
|
|
3367
|
-
const overrides =
|
|
4010
|
+
const overrides = getOverrides8(cmd);
|
|
3368
4011
|
const resolved = parseEntityReference(ref, overrides);
|
|
3369
4012
|
const api = createApiClient();
|
|
3370
4013
|
const entity = await api.storage.getEntity(resolved, true);
|
|
3371
4014
|
const currentSource = decodeFunctionSource(entity);
|
|
3372
4015
|
const language = entity.attributes?.["language"] ?? "txt";
|
|
3373
4016
|
const ext = extensionFor(language);
|
|
3374
|
-
const tmpFile =
|
|
3375
|
-
|
|
4017
|
+
const tmpFile = path5.join(os2.tmpdir(), `diafunc-${resolved.entityId}-${randomUUID()}.${ext}`);
|
|
4018
|
+
fs6.writeFileSync(tmpFile, currentSource);
|
|
3376
4019
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
3377
4020
|
await new Promise((resolve, reject) => {
|
|
3378
4021
|
const child = spawn(editor, [tmpFile], { stdio: "inherit" });
|
|
3379
4022
|
child.on("exit", (code) => code === 0 ? resolve() : reject(new Error(`Editor exited with code ${code}`)));
|
|
3380
4023
|
child.on("error", reject);
|
|
3381
4024
|
});
|
|
3382
|
-
const newSource =
|
|
3383
|
-
|
|
4025
|
+
const newSource = fs6.readFileSync(tmpFile, "utf-8");
|
|
4026
|
+
fs6.unlinkSync(tmpFile);
|
|
3384
4027
|
if (newSource === currentSource) {
|
|
3385
|
-
console.log(
|
|
4028
|
+
console.log(chalk16.dim("No changes."));
|
|
3386
4029
|
return;
|
|
3387
4030
|
}
|
|
3388
4031
|
await api.storage.saveEntityContentBase64(resolved, encodeFunctionSource(newSource));
|
|
3389
|
-
console.log(
|
|
4032
|
+
console.log(chalk16.green(`Source updated for "${resolved.entityId}".`));
|
|
3390
4033
|
} catch (error) {
|
|
3391
4034
|
handleError(error);
|
|
3392
4035
|
}
|
|
@@ -3403,13 +4046,13 @@ function extensionFor(language) {
|
|
|
3403
4046
|
}
|
|
3404
4047
|
|
|
3405
4048
|
// src/commands/trigger/index.ts
|
|
3406
|
-
import
|
|
3407
|
-
function
|
|
4049
|
+
import chalk17 from "chalk";
|
|
4050
|
+
function getOutputFormat9(cmd) {
|
|
3408
4051
|
const config = loadConfig();
|
|
3409
4052
|
const globalOpts = cmd.optsWithGlobals();
|
|
3410
4053
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3411
4054
|
}
|
|
3412
|
-
function
|
|
4055
|
+
function getOverrides9(cmd) {
|
|
3413
4056
|
const opts = cmd.optsWithGlobals();
|
|
3414
4057
|
return { project: opts.project, branch: opts.branch };
|
|
3415
4058
|
}
|
|
@@ -3417,8 +4060,8 @@ function registerTriggerCommands(program) {
|
|
|
3417
4060
|
const trigger = program.command("trigger").description("Manage function triggers");
|
|
3418
4061
|
trigger.command("list").description("List triggers for a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3419
4062
|
try {
|
|
3420
|
-
const outputFormat =
|
|
3421
|
-
const overrides =
|
|
4063
|
+
const outputFormat = getOutputFormat9(cmd);
|
|
4064
|
+
const overrides = getOverrides9(cmd);
|
|
3422
4065
|
const resolved = parseEntityReference(ref, overrides);
|
|
3423
4066
|
const api = createApiClient();
|
|
3424
4067
|
const triggers = await api.evaluation.getTriggers(
|
|
@@ -3445,8 +4088,8 @@ function registerTriggerCommands(program) {
|
|
|
3445
4088
|
});
|
|
3446
4089
|
trigger.command("get").description("Get a specific trigger").argument("<ref>", "Function entity reference").argument("<triggerId>", "Trigger ID").action(async (ref, triggerId, _options, cmd) => {
|
|
3447
4090
|
try {
|
|
3448
|
-
const outputFormat =
|
|
3449
|
-
const overrides =
|
|
4091
|
+
const outputFormat = getOutputFormat9(cmd);
|
|
4092
|
+
const overrides = getOverrides9(cmd);
|
|
3450
4093
|
const resolved = parseEntityReference(ref, overrides);
|
|
3451
4094
|
const api = createApiClient();
|
|
3452
4095
|
const t = await api.evaluation.getTrigger(
|
|
@@ -3463,7 +4106,7 @@ function registerTriggerCommands(program) {
|
|
|
3463
4106
|
});
|
|
3464
4107
|
trigger.command("delete").description("Delete a trigger").argument("<ref>", "Function entity reference").argument("<triggerId>", "Trigger ID").action(async (ref, triggerId, _options, cmd) => {
|
|
3465
4108
|
try {
|
|
3466
|
-
const overrides =
|
|
4109
|
+
const overrides = getOverrides9(cmd);
|
|
3467
4110
|
const resolved = parseEntityReference(ref, overrides);
|
|
3468
4111
|
const api = createApiClient();
|
|
3469
4112
|
await api.evaluation.deleteTrigger(
|
|
@@ -3473,14 +4116,14 @@ function registerTriggerCommands(program) {
|
|
|
3473
4116
|
resolved.entityBranch,
|
|
3474
4117
|
triggerId
|
|
3475
4118
|
);
|
|
3476
|
-
console.log(
|
|
4119
|
+
console.log(chalk17.green(`Trigger "${triggerId}" deleted.`));
|
|
3477
4120
|
} catch (error) {
|
|
3478
4121
|
handleError(error);
|
|
3479
4122
|
}
|
|
3480
4123
|
});
|
|
3481
4124
|
trigger.command("create").description("Create or update a trigger on a function").argument("<ref>", "Function entity reference").requiredOption("--type <type>", "Trigger type (SCHEDULE, EVENT, LINK, MANUAL)").option("--trigger-id <id>", "Trigger ID (auto-generated if omitted)").option("--expression <expr>", "Cron expression (for SCHEDULE) or event pattern").option("--origin <ref>", "Origin entity reference (for LINK/EVENT)").option("--persistent", "Persistent trigger (survives after first fire)").option("--inactive", "Create the trigger inactive").option("--max <n>", "Maximum fire count (0 = unlimited)", "0").option("--args <json>", "Arguments passed on fire (JSON object)").action(async (ref, options, cmd) => {
|
|
3482
4125
|
try {
|
|
3483
|
-
const overrides =
|
|
4126
|
+
const overrides = getOverrides9(cmd);
|
|
3484
4127
|
const fn = parseEntityReference(ref, overrides);
|
|
3485
4128
|
const api = createApiClient();
|
|
3486
4129
|
const args = options.args ? JSON.parse(options.args) : null;
|
|
@@ -3521,7 +4164,7 @@ function registerTriggerCommands(program) {
|
|
|
3521
4164
|
scheduler: null,
|
|
3522
4165
|
heartbeat: null
|
|
3523
4166
|
});
|
|
3524
|
-
console.log(
|
|
4167
|
+
console.log(chalk17.green("Trigger saved."));
|
|
3525
4168
|
} catch (error) {
|
|
3526
4169
|
handleError(error);
|
|
3527
4170
|
}
|
|
@@ -3529,14 +4172,14 @@ function registerTriggerCommands(program) {
|
|
|
3529
4172
|
}
|
|
3530
4173
|
|
|
3531
4174
|
// src/commands/schedule/index.ts
|
|
3532
|
-
import
|
|
4175
|
+
import chalk18 from "chalk";
|
|
3533
4176
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
3534
|
-
function
|
|
4177
|
+
function getOutputFormat10(cmd) {
|
|
3535
4178
|
const config = loadConfig();
|
|
3536
4179
|
const globalOpts = cmd.optsWithGlobals();
|
|
3537
4180
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3538
4181
|
}
|
|
3539
|
-
function
|
|
4182
|
+
function getOverrides10(cmd) {
|
|
3540
4183
|
const opts = cmd.optsWithGlobals();
|
|
3541
4184
|
return { project: opts.project, branch: opts.branch };
|
|
3542
4185
|
}
|
|
@@ -3544,8 +4187,8 @@ function registerScheduleCommands(program) {
|
|
|
3544
4187
|
const schedule = program.command("schedule").description("Schedule function execution");
|
|
3545
4188
|
schedule.command("call").description("Schedule a function call").argument("<ref>", "Function entity reference").option("--args <json>", "Arguments as JSON object").option("--target <ref>", "Target entity reference").action(async (ref, options, cmd) => {
|
|
3546
4189
|
try {
|
|
3547
|
-
const outputFormat =
|
|
3548
|
-
const overrides =
|
|
4190
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
4191
|
+
const overrides = getOverrides10(cmd);
|
|
3549
4192
|
const resolved = parseEntityReference(ref, overrides);
|
|
3550
4193
|
const api = createApiClient();
|
|
3551
4194
|
let args = null;
|
|
@@ -3581,7 +4224,7 @@ function registerScheduleCommands(program) {
|
|
|
3581
4224
|
removeFunction: false
|
|
3582
4225
|
});
|
|
3583
4226
|
if (outputFormat === "human") {
|
|
3584
|
-
console.log(
|
|
4227
|
+
console.log(chalk18.green("Function scheduled."));
|
|
3585
4228
|
} else {
|
|
3586
4229
|
format(result, { format: outputFormat });
|
|
3587
4230
|
}
|
|
@@ -3591,7 +4234,7 @@ function registerScheduleCommands(program) {
|
|
|
3591
4234
|
});
|
|
3592
4235
|
schedule.command("stop").description("Stop a scheduled function evaluation").argument("<ref>", "Function entity reference").argument("<evaluationId>", "Evaluation ID to stop").requiredOption("--date <date>", "Evaluation date/hour (YYYY-MM-DD-HH in UTC)").action(async (ref, evaluationId, options, cmd) => {
|
|
3593
4236
|
try {
|
|
3594
|
-
const overrides =
|
|
4237
|
+
const overrides = getOverrides10(cmd);
|
|
3595
4238
|
const resolved = parseEntityReference(ref, overrides);
|
|
3596
4239
|
const api = createApiClient();
|
|
3597
4240
|
const [year, month, day, hour] = options.date.split("-").map(Number);
|
|
@@ -3606,15 +4249,15 @@ function registerScheduleCommands(program) {
|
|
|
3606
4249
|
hour,
|
|
3607
4250
|
evaluationId
|
|
3608
4251
|
);
|
|
3609
|
-
console.log(
|
|
4252
|
+
console.log(chalk18.green(`Scheduled evaluation ${evaluationId} stopped.`));
|
|
3610
4253
|
} catch (error) {
|
|
3611
4254
|
handleError(error);
|
|
3612
4255
|
}
|
|
3613
4256
|
});
|
|
3614
4257
|
schedule.command("list").description("List persistent triggers (scheduled functions are modeled as triggers)").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3615
4258
|
try {
|
|
3616
|
-
const outputFormat =
|
|
3617
|
-
const overrides =
|
|
4259
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
4260
|
+
const overrides = getOverrides10(cmd);
|
|
3618
4261
|
const resolved = parseEntityReference(ref, overrides);
|
|
3619
4262
|
const api = createApiClient();
|
|
3620
4263
|
const triggers = await api.evaluation.getTriggers(
|
|
@@ -3640,13 +4283,13 @@ function registerScheduleCommands(program) {
|
|
|
3640
4283
|
handleError(error);
|
|
3641
4284
|
}
|
|
3642
4285
|
});
|
|
3643
|
-
}
|
|
3644
|
-
|
|
3645
|
-
// src/commands/chat/index.ts
|
|
3646
|
-
import
|
|
3647
|
-
import * as
|
|
3648
|
-
import * as
|
|
3649
|
-
function
|
|
4286
|
+
}
|
|
4287
|
+
|
|
4288
|
+
// src/commands/chat/index.ts
|
|
4289
|
+
import chalk19 from "chalk";
|
|
4290
|
+
import * as fs7 from "fs";
|
|
4291
|
+
import * as path6 from "path";
|
|
4292
|
+
function getOutputFormat11(cmd) {
|
|
3650
4293
|
const config = loadConfig();
|
|
3651
4294
|
const globalOpts = cmd.optsWithGlobals();
|
|
3652
4295
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -3684,7 +4327,7 @@ async function streamOneTurn(message, sessionId, projectId, branch) {
|
|
|
3684
4327
|
input = event.inputTokens;
|
|
3685
4328
|
output = event.outputTokens;
|
|
3686
4329
|
} else if (event.type === "error") {
|
|
3687
|
-
console.error(
|
|
4330
|
+
console.error(chalk19.red(`
|
|
3688
4331
|
Error: ${event.content}`));
|
|
3689
4332
|
}
|
|
3690
4333
|
} catch {
|
|
@@ -3695,19 +4338,19 @@ Error: ${event.content}`));
|
|
|
3695
4338
|
}
|
|
3696
4339
|
async function runChatRepl(options) {
|
|
3697
4340
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
3698
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
4341
|
+
const { getUpdateNotice } = await import("./update-check-KL3CHODI.js");
|
|
3699
4342
|
let sessionId = options.session;
|
|
3700
|
-
console.log(
|
|
4343
|
+
console.log(chalk19.bold("Diafunc chat") + chalk19.dim(" \xB7 /help for commands, /quit to exit"));
|
|
3701
4344
|
if (sessionId) {
|
|
3702
|
-
console.log(
|
|
4345
|
+
console.log(chalk19.dim(`Continuing session ${sessionId}`));
|
|
3703
4346
|
}
|
|
3704
4347
|
const notice = await getUpdateNotice();
|
|
3705
|
-
if (notice) console.log(
|
|
4348
|
+
if (notice) console.log(chalk19.dim(notice));
|
|
3706
4349
|
console.log();
|
|
3707
4350
|
for (; ; ) {
|
|
3708
4351
|
let line;
|
|
3709
4352
|
try {
|
|
3710
|
-
line = await promptInput({ message:
|
|
4353
|
+
line = await promptInput({ message: chalk19.cyan.bold("you >") });
|
|
3711
4354
|
} catch {
|
|
3712
4355
|
console.log();
|
|
3713
4356
|
return;
|
|
@@ -3724,37 +4367,37 @@ async function runChatRepl(options) {
|
|
|
3724
4367
|
return;
|
|
3725
4368
|
case "new":
|
|
3726
4369
|
sessionId = void 0;
|
|
3727
|
-
console.log(
|
|
4370
|
+
console.log(chalk19.dim("Started a new session."));
|
|
3728
4371
|
continue;
|
|
3729
4372
|
case "session":
|
|
3730
4373
|
if (!arg) {
|
|
3731
|
-
console.log(
|
|
4374
|
+
console.log(chalk19.dim(`Current session: ${sessionId ?? "(new)"}`));
|
|
3732
4375
|
} else {
|
|
3733
4376
|
sessionId = arg;
|
|
3734
|
-
console.log(
|
|
4377
|
+
console.log(chalk19.dim(`Switched to session ${sessionId}`));
|
|
3735
4378
|
}
|
|
3736
4379
|
continue;
|
|
3737
4380
|
case "help":
|
|
3738
4381
|
case "h":
|
|
3739
4382
|
case "?":
|
|
3740
|
-
console.log(
|
|
3741
|
-
console.log(
|
|
3742
|
-
console.log(
|
|
4383
|
+
console.log(chalk19.dim(" /new start a new session"));
|
|
4384
|
+
console.log(chalk19.dim(" /session [id] switch to a session (no id = show current)"));
|
|
4385
|
+
console.log(chalk19.dim(" /quit exit the REPL"));
|
|
3743
4386
|
continue;
|
|
3744
4387
|
default:
|
|
3745
|
-
console.log(
|
|
4388
|
+
console.log(chalk19.dim(`Unknown command: /${cmd}. Try /help.`));
|
|
3746
4389
|
continue;
|
|
3747
4390
|
}
|
|
3748
4391
|
}
|
|
3749
|
-
process.stdout.write(
|
|
4392
|
+
process.stdout.write(chalk19.magenta.bold("diafunc > "));
|
|
3750
4393
|
try {
|
|
3751
4394
|
const result = await streamOneTurn(trimmed, sessionId, options.project, options.branch);
|
|
3752
4395
|
sessionId = result.sessionId || sessionId;
|
|
3753
4396
|
console.log();
|
|
3754
|
-
console.log(
|
|
4397
|
+
console.log(chalk19.dim(`[session ${sessionId} \xB7 ${result.input} in / ${result.output} out]`));
|
|
3755
4398
|
console.log();
|
|
3756
4399
|
} catch (error) {
|
|
3757
|
-
console.error(
|
|
4400
|
+
console.error(chalk19.red(`
|
|
3758
4401
|
Request failed: ${error.message}`));
|
|
3759
4402
|
}
|
|
3760
4403
|
}
|
|
@@ -3770,7 +4413,7 @@ function registerChatCommands(program) {
|
|
|
3770
4413
|
});
|
|
3771
4414
|
chat.command("send").description("Send a chat message (blocking)").argument("<message>", "Message to send").option("--project <id>", "Project context").option("--branch <branch>", "Project branch", "main").option("--session <id>", "Session ID to continue").action(async (message, options, cmd) => {
|
|
3772
4415
|
try {
|
|
3773
|
-
const outputFormat =
|
|
4416
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3774
4417
|
const api = createApiClient();
|
|
3775
4418
|
const response = await api.language.chat({
|
|
3776
4419
|
message,
|
|
@@ -3781,7 +4424,7 @@ function registerChatCommands(program) {
|
|
|
3781
4424
|
if (outputFormat === "human") {
|
|
3782
4425
|
console.log(response.content);
|
|
3783
4426
|
console.log();
|
|
3784
|
-
console.log(
|
|
4427
|
+
console.log(chalk19.dim(`Session: ${response.sessionId} | Tokens: ${response.inputTokens} in, ${response.outputTokens} out`));
|
|
3785
4428
|
} else {
|
|
3786
4429
|
format(response, { format: outputFormat });
|
|
3787
4430
|
}
|
|
@@ -3791,7 +4434,7 @@ function registerChatCommands(program) {
|
|
|
3791
4434
|
});
|
|
3792
4435
|
chat.command("stream").description("Send a chat message (streaming)").argument("<message>", "Message to send").option("--project <id>", "Project context").option("--branch <branch>", "Project branch", "main").option("--session <id>", "Session ID to continue").action(async (message, options, cmd) => {
|
|
3793
4436
|
try {
|
|
3794
|
-
const outputFormat =
|
|
4437
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3795
4438
|
const api = createApiClient();
|
|
3796
4439
|
const response = await api.language.chatStream({
|
|
3797
4440
|
message,
|
|
@@ -3846,9 +4489,9 @@ function registerChatCommands(program) {
|
|
|
3846
4489
|
sessionId = event.sessionId ?? "";
|
|
3847
4490
|
console.log();
|
|
3848
4491
|
console.log();
|
|
3849
|
-
console.log(
|
|
4492
|
+
console.log(chalk19.dim(`Session: ${sessionId} | Tokens: ${event.inputTokens} in, ${event.outputTokens} out`));
|
|
3850
4493
|
} else if (event.type === "error") {
|
|
3851
|
-
console.error(
|
|
4494
|
+
console.error(chalk19.red(`
|
|
3852
4495
|
Error: ${event.content}`));
|
|
3853
4496
|
}
|
|
3854
4497
|
} catch {
|
|
@@ -3863,17 +4506,17 @@ Error: ${event.content}`));
|
|
|
3863
4506
|
});
|
|
3864
4507
|
chat.command("upload").description("Upload a file for chat context").argument("<file>", "File to upload").action(async (file) => {
|
|
3865
4508
|
try {
|
|
3866
|
-
if (!
|
|
3867
|
-
console.error(
|
|
4509
|
+
if (!fs7.existsSync(file)) {
|
|
4510
|
+
console.error(chalk19.red(`File not found: ${file}`));
|
|
3868
4511
|
process.exit(1);
|
|
3869
4512
|
}
|
|
3870
4513
|
const api = createApiClient();
|
|
3871
|
-
const fileBuffer =
|
|
4514
|
+
const fileBuffer = fs7.readFileSync(file);
|
|
3872
4515
|
const blob = new Blob([fileBuffer]);
|
|
3873
4516
|
const formData = new FormData();
|
|
3874
|
-
formData.append("file", blob,
|
|
4517
|
+
formData.append("file", blob, path6.basename(file));
|
|
3875
4518
|
const result = await api.language.upload(formData);
|
|
3876
|
-
console.log(
|
|
4519
|
+
console.log(chalk19.green(`File uploaded: ${result}`));
|
|
3877
4520
|
} catch (error) {
|
|
3878
4521
|
handleError(error);
|
|
3879
4522
|
}
|
|
@@ -3881,7 +4524,7 @@ Error: ${event.content}`));
|
|
|
3881
4524
|
const session = chat.command("session").description("Manage chat sessions");
|
|
3882
4525
|
session.command("list").description("List chat sessions").action(async (_options, cmd) => {
|
|
3883
4526
|
try {
|
|
3884
|
-
const outputFormat =
|
|
4527
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3885
4528
|
const api = createApiClient();
|
|
3886
4529
|
const sessions = await api.language.getSessions();
|
|
3887
4530
|
format(sessions, {
|
|
@@ -3896,22 +4539,22 @@ Error: ${event.content}`));
|
|
|
3896
4539
|
try {
|
|
3897
4540
|
const api = createApiClient();
|
|
3898
4541
|
await api.language.deleteSession(sessionId);
|
|
3899
|
-
console.log(
|
|
4542
|
+
console.log(chalk19.green(`Session "${sessionId}" deleted.`));
|
|
3900
4543
|
} catch (error) {
|
|
3901
4544
|
handleError(error);
|
|
3902
4545
|
}
|
|
3903
4546
|
});
|
|
3904
4547
|
session.command("show").description("Show the message history of a chat session").argument("<sessionId>", "Session ID").action(async (sessionId, _options, cmd) => {
|
|
3905
4548
|
try {
|
|
3906
|
-
const outputFormat =
|
|
4549
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3907
4550
|
const api = createApiClient();
|
|
3908
4551
|
const detail = await api.language.getSession(sessionId);
|
|
3909
4552
|
if (outputFormat === "human") {
|
|
3910
|
-
console.log(
|
|
4553
|
+
console.log(chalk19.bold(detail.title) + chalk19.dim(` (${detail.sessionId})`));
|
|
3911
4554
|
console.log();
|
|
3912
4555
|
for (const msg of detail.messages) {
|
|
3913
|
-
const role = msg.role === "user" ?
|
|
3914
|
-
console.log(`${role} ${
|
|
4556
|
+
const role = msg.role === "user" ? chalk19.cyan.bold("You") : chalk19.magenta.bold("Diafunc");
|
|
4557
|
+
console.log(`${role} ${chalk19.dim(msg.created)}`);
|
|
3915
4558
|
console.log(msg.content);
|
|
3916
4559
|
console.log();
|
|
3917
4560
|
}
|
|
@@ -3926,14 +4569,14 @@ Error: ${event.content}`));
|
|
|
3926
4569
|
try {
|
|
3927
4570
|
const api = createApiClient();
|
|
3928
4571
|
await api.language.renameSession(sessionId, title);
|
|
3929
|
-
console.log(
|
|
4572
|
+
console.log(chalk19.green(`Session "${sessionId}" renamed to "${title}".`));
|
|
3930
4573
|
} catch (error) {
|
|
3931
4574
|
handleError(error);
|
|
3932
4575
|
}
|
|
3933
4576
|
});
|
|
3934
4577
|
chat.command("usage").description("Show token usage").action(async (_options, cmd) => {
|
|
3935
4578
|
try {
|
|
3936
|
-
const outputFormat =
|
|
4579
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
3937
4580
|
const api = createApiClient();
|
|
3938
4581
|
const usage = await api.language.getUsage();
|
|
3939
4582
|
format(usage, { format: outputFormat });
|
|
@@ -3944,7 +4587,7 @@ Error: ${event.content}`));
|
|
|
3944
4587
|
}
|
|
3945
4588
|
|
|
3946
4589
|
// src/commands/search/index.ts
|
|
3947
|
-
function
|
|
4590
|
+
function getOutputFormat12(cmd) {
|
|
3948
4591
|
const config = loadConfig();
|
|
3949
4592
|
const globalOpts = cmd.optsWithGlobals();
|
|
3950
4593
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -3952,7 +4595,7 @@ function getOutputFormat11(cmd) {
|
|
|
3952
4595
|
function registerSearchCommands(program) {
|
|
3953
4596
|
program.command("search").description("Search entities across projects").argument("<query>", "Search query").option("--project <id>", "Limit search to a project").option("--branch <branch>", "Project branch", "main").action(async (query, options, cmd) => {
|
|
3954
4597
|
try {
|
|
3955
|
-
const outputFormat =
|
|
4598
|
+
const outputFormat = getOutputFormat12(cmd);
|
|
3956
4599
|
const api = createApiClient();
|
|
3957
4600
|
if (options.project) {
|
|
3958
4601
|
const results = await api.storage.searchProject(
|
|
@@ -3983,8 +4626,8 @@ function registerSearchCommands(program) {
|
|
|
3983
4626
|
}
|
|
3984
4627
|
|
|
3985
4628
|
// src/commands/group/index.ts
|
|
3986
|
-
import
|
|
3987
|
-
function
|
|
4629
|
+
import chalk20 from "chalk";
|
|
4630
|
+
function getOutputFormat13(cmd) {
|
|
3988
4631
|
const config = loadConfig();
|
|
3989
4632
|
const globalOpts = cmd.optsWithGlobals();
|
|
3990
4633
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -3993,7 +4636,7 @@ function registerGroupCommands(program) {
|
|
|
3993
4636
|
const group = program.command("group").description("Manage groups");
|
|
3994
4637
|
group.command("list").description("List groups").option("--all", "List all groups (admin)").action(async (options, cmd) => {
|
|
3995
4638
|
try {
|
|
3996
|
-
const outputFormat =
|
|
4639
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
3997
4640
|
const api = createApiClient();
|
|
3998
4641
|
const groups = options.all ? await api.admin.getAllGroups() : await api.admin.getGroups();
|
|
3999
4642
|
format(groups, { format: outputFormat, columns: ["groupId", "name"] });
|
|
@@ -4003,7 +4646,7 @@ function registerGroupCommands(program) {
|
|
|
4003
4646
|
});
|
|
4004
4647
|
group.command("get").description("Get group details").argument("<groupId>", "Group ID").action(async (groupId, _options, cmd) => {
|
|
4005
4648
|
try {
|
|
4006
|
-
const outputFormat =
|
|
4649
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
4007
4650
|
const api = createApiClient();
|
|
4008
4651
|
const g = await api.admin.getGroup(groupId);
|
|
4009
4652
|
format(g, { format: outputFormat });
|
|
@@ -4015,7 +4658,7 @@ function registerGroupCommands(program) {
|
|
|
4015
4658
|
try {
|
|
4016
4659
|
const api = createApiClient();
|
|
4017
4660
|
await api.admin.createGroup({ groupId, name: options.name ?? groupId });
|
|
4018
|
-
console.log(
|
|
4661
|
+
console.log(chalk20.green(`Group "${groupId}" created.`));
|
|
4019
4662
|
} catch (error) {
|
|
4020
4663
|
handleError(error);
|
|
4021
4664
|
}
|
|
@@ -4024,7 +4667,7 @@ function registerGroupCommands(program) {
|
|
|
4024
4667
|
try {
|
|
4025
4668
|
const api = createApiClient();
|
|
4026
4669
|
await api.admin.updateGroup({ groupId, name: options.name });
|
|
4027
|
-
console.log(
|
|
4670
|
+
console.log(chalk20.green(`Group "${groupId}" updated.`));
|
|
4028
4671
|
} catch (error) {
|
|
4029
4672
|
handleError(error);
|
|
4030
4673
|
}
|
|
@@ -4033,7 +4676,7 @@ function registerGroupCommands(program) {
|
|
|
4033
4676
|
try {
|
|
4034
4677
|
const api = createApiClient();
|
|
4035
4678
|
await api.admin.deleteGroup(groupId);
|
|
4036
|
-
console.log(
|
|
4679
|
+
console.log(chalk20.green(`Group "${groupId}" deleted.`));
|
|
4037
4680
|
} catch (error) {
|
|
4038
4681
|
handleError(error);
|
|
4039
4682
|
}
|
|
@@ -4041,7 +4684,7 @@ function registerGroupCommands(program) {
|
|
|
4041
4684
|
const members = group.command("members").description("Manage group members");
|
|
4042
4685
|
members.command("list").description("List group members").argument("<groupId>", "Group ID").action(async (groupId, _options, cmd) => {
|
|
4043
4686
|
try {
|
|
4044
|
-
const outputFormat =
|
|
4687
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
4045
4688
|
const api = createApiClient();
|
|
4046
4689
|
const memberList = await api.admin.getGroupMembers(groupId);
|
|
4047
4690
|
format(memberList, { format: outputFormat, columns: ["userId", "role", "joined"] });
|
|
@@ -4053,7 +4696,7 @@ function registerGroupCommands(program) {
|
|
|
4053
4696
|
try {
|
|
4054
4697
|
const api = createApiClient();
|
|
4055
4698
|
await api.admin.inviteGroupMember(groupId, userId, role.toUpperCase());
|
|
4056
|
-
console.log(
|
|
4699
|
+
console.log(chalk20.green(`Invited ${userId} to group "${groupId}" as ${role.toUpperCase()}.`));
|
|
4057
4700
|
} catch (error) {
|
|
4058
4701
|
handleError(error);
|
|
4059
4702
|
}
|
|
@@ -4062,7 +4705,7 @@ function registerGroupCommands(program) {
|
|
|
4062
4705
|
try {
|
|
4063
4706
|
const api = createApiClient();
|
|
4064
4707
|
await api.admin.removeGroupMember(groupId, userId);
|
|
4065
|
-
console.log(
|
|
4708
|
+
console.log(chalk20.green(`Removed ${userId} from group "${groupId}".`));
|
|
4066
4709
|
} catch (error) {
|
|
4067
4710
|
handleError(error);
|
|
4068
4711
|
}
|
|
@@ -4070,7 +4713,7 @@ function registerGroupCommands(program) {
|
|
|
4070
4713
|
const projects = group.command("projects").description("Manage group projects");
|
|
4071
4714
|
projects.command("list").description("List group projects").argument("<groupId>", "Group ID").action(async (groupId, _options, cmd) => {
|
|
4072
4715
|
try {
|
|
4073
|
-
const outputFormat =
|
|
4716
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
4074
4717
|
const api = createApiClient();
|
|
4075
4718
|
const projectList = await api.admin.getGroupProjects(groupId);
|
|
4076
4719
|
format(projectList, { format: outputFormat, columns: ["projectId", "visibility", "language"] });
|
|
@@ -4082,7 +4725,7 @@ function registerGroupCommands(program) {
|
|
|
4082
4725
|
try {
|
|
4083
4726
|
const api = createApiClient();
|
|
4084
4727
|
await api.admin.addGroupProject(groupId, projectId);
|
|
4085
|
-
console.log(
|
|
4728
|
+
console.log(chalk20.green(`Project "${projectId}" added to group "${groupId}".`));
|
|
4086
4729
|
} catch (error) {
|
|
4087
4730
|
handleError(error);
|
|
4088
4731
|
}
|
|
@@ -4091,7 +4734,7 @@ function registerGroupCommands(program) {
|
|
|
4091
4734
|
try {
|
|
4092
4735
|
const api = createApiClient();
|
|
4093
4736
|
await api.admin.removeGroupProject(groupId, projectId);
|
|
4094
|
-
console.log(
|
|
4737
|
+
console.log(chalk20.green(`Project "${projectId}" removed from group "${groupId}".`));
|
|
4095
4738
|
} catch (error) {
|
|
4096
4739
|
handleError(error);
|
|
4097
4740
|
}
|
|
@@ -4099,8 +4742,8 @@ function registerGroupCommands(program) {
|
|
|
4099
4742
|
}
|
|
4100
4743
|
|
|
4101
4744
|
// src/commands/admin/index.ts
|
|
4102
|
-
import
|
|
4103
|
-
function
|
|
4745
|
+
import chalk21 from "chalk";
|
|
4746
|
+
function getOutputFormat14(cmd) {
|
|
4104
4747
|
const config = loadConfig();
|
|
4105
4748
|
const globalOpts = cmd.optsWithGlobals();
|
|
4106
4749
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4110,7 +4753,7 @@ function registerAdminCommands(program) {
|
|
|
4110
4753
|
const users = admin.command("users").description("Manage users");
|
|
4111
4754
|
users.command("list").description("List all users (admin)").action(async (_options, cmd) => {
|
|
4112
4755
|
try {
|
|
4113
|
-
const outputFormat =
|
|
4756
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4114
4757
|
const api = createApiClient();
|
|
4115
4758
|
const userList = await api.admin.getUsers();
|
|
4116
4759
|
const summary = userList.map((u) => ({
|
|
@@ -4130,7 +4773,7 @@ function registerAdminCommands(program) {
|
|
|
4130
4773
|
});
|
|
4131
4774
|
users.command("get").description("Get current user details").action(async (_options, cmd) => {
|
|
4132
4775
|
try {
|
|
4133
|
-
const outputFormat =
|
|
4776
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4134
4777
|
const api = createApiClient();
|
|
4135
4778
|
const user = await api.admin.getMyUser();
|
|
4136
4779
|
format(user, { format: outputFormat });
|
|
@@ -4140,7 +4783,7 @@ function registerAdminCommands(program) {
|
|
|
4140
4783
|
});
|
|
4141
4784
|
admin.command("subscription").description("Show current subscription").action(async (_options, cmd) => {
|
|
4142
4785
|
try {
|
|
4143
|
-
const outputFormat =
|
|
4786
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4144
4787
|
const api = createApiClient();
|
|
4145
4788
|
const sub = await api.admin.getCurrentSubscription();
|
|
4146
4789
|
format(sub, { format: outputFormat });
|
|
@@ -4151,7 +4794,7 @@ function registerAdminCommands(program) {
|
|
|
4151
4794
|
const settings = admin.command("settings").description("Manage settings");
|
|
4152
4795
|
settings.command("get").description("Get current settings").action(async (_options, cmd) => {
|
|
4153
4796
|
try {
|
|
4154
|
-
const outputFormat =
|
|
4797
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4155
4798
|
const api = createApiClient();
|
|
4156
4799
|
const s = await api.admin.getSettings();
|
|
4157
4800
|
format(s, { format: outputFormat });
|
|
@@ -4163,7 +4806,7 @@ function registerAdminCommands(program) {
|
|
|
4163
4806
|
try {
|
|
4164
4807
|
const api = createApiClient();
|
|
4165
4808
|
await api.admin.mergeSetting({ [key]: value });
|
|
4166
|
-
console.log(
|
|
4809
|
+
console.log(chalk21.green(`Setting "${key}" updated.`));
|
|
4167
4810
|
} catch (error) {
|
|
4168
4811
|
handleError(error);
|
|
4169
4812
|
}
|
|
@@ -4174,10 +4817,10 @@ function registerAdminCommands(program) {
|
|
|
4174
4817
|
const api = createApiClient();
|
|
4175
4818
|
if (options.longTerm) {
|
|
4176
4819
|
await api.storage.createLongTermFullBackup();
|
|
4177
|
-
console.log(
|
|
4820
|
+
console.log(chalk21.green("Full long-term backup initiated."));
|
|
4178
4821
|
} else {
|
|
4179
4822
|
await api.storage.createShortTermFullBackup();
|
|
4180
|
-
console.log(
|
|
4823
|
+
console.log(chalk21.green("Full short-term backup initiated."));
|
|
4181
4824
|
}
|
|
4182
4825
|
} catch (error) {
|
|
4183
4826
|
handleError(error);
|
|
@@ -4188,10 +4831,10 @@ function registerAdminCommands(program) {
|
|
|
4188
4831
|
const api = createApiClient();
|
|
4189
4832
|
if (options.longTerm) {
|
|
4190
4833
|
await api.storage.createLongTermProjectBackup();
|
|
4191
|
-
console.log(
|
|
4834
|
+
console.log(chalk21.green("Project long-term backup initiated."));
|
|
4192
4835
|
} else {
|
|
4193
4836
|
await api.storage.createShortTermProjectBackup();
|
|
4194
|
-
console.log(
|
|
4837
|
+
console.log(chalk21.green("Project short-term backup initiated."));
|
|
4195
4838
|
}
|
|
4196
4839
|
} catch (error) {
|
|
4197
4840
|
handleError(error);
|
|
@@ -4201,7 +4844,7 @@ function registerAdminCommands(program) {
|
|
|
4201
4844
|
try {
|
|
4202
4845
|
const api = createApiClient();
|
|
4203
4846
|
await api.storage.restoreProjectBackup({ projectId, projectBranch, bucketName, objectName });
|
|
4204
|
-
console.log(
|
|
4847
|
+
console.log(chalk21.green(`Restore initiated for ${projectId}/${projectBranch} from ${bucketName}/${objectName}.`));
|
|
4205
4848
|
} catch (error) {
|
|
4206
4849
|
handleError(error);
|
|
4207
4850
|
}
|
|
@@ -4210,7 +4853,7 @@ function registerAdminCommands(program) {
|
|
|
4210
4853
|
try {
|
|
4211
4854
|
const api = createApiClient();
|
|
4212
4855
|
await api.storage.restoreFullBackup({ bucketName, objectName });
|
|
4213
|
-
console.log(
|
|
4856
|
+
console.log(chalk21.green(`Full restore initiated from ${bucketName}/${objectName}.`));
|
|
4214
4857
|
} catch (error) {
|
|
4215
4858
|
handleError(error);
|
|
4216
4859
|
}
|
|
@@ -4220,10 +4863,10 @@ function registerAdminCommands(program) {
|
|
|
4220
4863
|
const api = createApiClient();
|
|
4221
4864
|
if (options.project) {
|
|
4222
4865
|
await api.index.rebuildProject(options.project);
|
|
4223
|
-
console.log(
|
|
4866
|
+
console.log(chalk21.green(`Index rebuild initiated for project "${options.project}".`));
|
|
4224
4867
|
} else {
|
|
4225
4868
|
await api.index.rebuildAll();
|
|
4226
|
-
console.log(
|
|
4869
|
+
console.log(chalk21.green("Index rebuild initiated for all projects."));
|
|
4227
4870
|
}
|
|
4228
4871
|
} catch (error) {
|
|
4229
4872
|
handleError(error);
|
|
@@ -4231,7 +4874,7 @@ function registerAdminCommands(program) {
|
|
|
4231
4874
|
});
|
|
4232
4875
|
admin.command("permissions").description("Show your permissions on a project").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
4233
4876
|
try {
|
|
4234
|
-
const outputFormat =
|
|
4877
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4235
4878
|
const api = createApiClient();
|
|
4236
4879
|
const perm = await api.admin.getPermissions(projectId);
|
|
4237
4880
|
format(perm, { format: outputFormat });
|
|
@@ -4242,14 +4885,14 @@ function registerAdminCommands(program) {
|
|
|
4242
4885
|
}
|
|
4243
4886
|
|
|
4244
4887
|
// src/commands/status/summary.ts
|
|
4245
|
-
import
|
|
4888
|
+
import chalk22 from "chalk";
|
|
4246
4889
|
|
|
4247
4890
|
// src/client/services/status.ts
|
|
4248
4891
|
function createStatusService() {
|
|
4249
4892
|
const config = loadConfig();
|
|
4250
4893
|
const endpoint = resolveEndpoint(config);
|
|
4251
|
-
async function fetchJson(
|
|
4252
|
-
const url = `${endpoint}/status/v1${
|
|
4894
|
+
async function fetchJson(path11) {
|
|
4895
|
+
const url = `${endpoint}/status/v1${path11}`;
|
|
4253
4896
|
const response = await fetch(url, {
|
|
4254
4897
|
headers: { "Accept": "application/json" }
|
|
4255
4898
|
});
|
|
@@ -4268,24 +4911,24 @@ function createStatusService() {
|
|
|
4268
4911
|
|
|
4269
4912
|
// src/commands/status/summary.ts
|
|
4270
4913
|
var STATE_COLORS = {
|
|
4271
|
-
UP:
|
|
4272
|
-
DEGRADED:
|
|
4273
|
-
DOWN:
|
|
4274
|
-
UNKNOWN:
|
|
4914
|
+
UP: chalk22.green,
|
|
4915
|
+
DEGRADED: chalk22.yellow,
|
|
4916
|
+
DOWN: chalk22.red,
|
|
4917
|
+
UNKNOWN: chalk22.gray
|
|
4275
4918
|
};
|
|
4276
4919
|
function stateColor(state) {
|
|
4277
|
-
return STATE_COLORS[state] ??
|
|
4920
|
+
return STATE_COLORS[state] ?? chalk22.gray;
|
|
4278
4921
|
}
|
|
4279
4922
|
function stateSymbol(state) {
|
|
4280
4923
|
switch (state) {
|
|
4281
4924
|
case "UP":
|
|
4282
|
-
return
|
|
4925
|
+
return chalk22.green("\u25CF");
|
|
4283
4926
|
case "DEGRADED":
|
|
4284
|
-
return
|
|
4927
|
+
return chalk22.yellow("\u25CF");
|
|
4285
4928
|
case "DOWN":
|
|
4286
|
-
return
|
|
4929
|
+
return chalk22.red("\u25CF");
|
|
4287
4930
|
default:
|
|
4288
|
-
return
|
|
4931
|
+
return chalk22.gray("\u25CB");
|
|
4289
4932
|
}
|
|
4290
4933
|
}
|
|
4291
4934
|
function registerSummaryCommand(parent) {
|
|
@@ -4312,11 +4955,11 @@ function registerSummaryCommand(parent) {
|
|
|
4312
4955
|
}
|
|
4313
4956
|
console.log();
|
|
4314
4957
|
if (summary.openIncidents > 0) {
|
|
4315
|
-
console.log(
|
|
4958
|
+
console.log(chalk22.yellow(` ${summary.openIncidents} active incident(s)`));
|
|
4316
4959
|
} else {
|
|
4317
|
-
console.log(
|
|
4960
|
+
console.log(chalk22.dim(" No active incidents"));
|
|
4318
4961
|
}
|
|
4319
|
-
console.log(
|
|
4962
|
+
console.log(chalk22.dim(`
|
|
4320
4963
|
Platform v${version.platformVersion} \u2022 ${new Date(summary.timestamp).toLocaleString()}`));
|
|
4321
4964
|
console.log();
|
|
4322
4965
|
} catch (error) {
|
|
@@ -4326,17 +4969,17 @@ function registerSummaryCommand(parent) {
|
|
|
4326
4969
|
}
|
|
4327
4970
|
|
|
4328
4971
|
// src/commands/status/component.ts
|
|
4329
|
-
import
|
|
4972
|
+
import chalk23 from "chalk";
|
|
4330
4973
|
function stateSymbol2(state) {
|
|
4331
4974
|
switch (state) {
|
|
4332
4975
|
case "UP":
|
|
4333
|
-
return
|
|
4976
|
+
return chalk23.green("\u25CF");
|
|
4334
4977
|
case "DEGRADED":
|
|
4335
|
-
return
|
|
4978
|
+
return chalk23.yellow("\u25CF");
|
|
4336
4979
|
case "DOWN":
|
|
4337
|
-
return
|
|
4980
|
+
return chalk23.red("\u25CF");
|
|
4338
4981
|
default:
|
|
4339
|
-
return
|
|
4982
|
+
return chalk23.gray("\u25CB");
|
|
4340
4983
|
}
|
|
4341
4984
|
}
|
|
4342
4985
|
function registerComponentCommand(parent) {
|
|
@@ -4349,7 +4992,7 @@ function registerComponentCommand(parent) {
|
|
|
4349
4992
|
const match = components.find((c) => c.id === id || c.id === id + "-service");
|
|
4350
4993
|
if (!match) {
|
|
4351
4994
|
const available = components.map((c) => c.id).join(", ");
|
|
4352
|
-
console.error(
|
|
4995
|
+
console.error(chalk23.red(`Component "${id}" not found. Available: ${available}`));
|
|
4353
4996
|
process.exit(1);
|
|
4354
4997
|
}
|
|
4355
4998
|
if (outputFormat !== "human") {
|
|
@@ -4357,7 +5000,7 @@ function registerComponentCommand(parent) {
|
|
|
4357
5000
|
return;
|
|
4358
5001
|
}
|
|
4359
5002
|
console.log();
|
|
4360
|
-
console.log(` ${stateSymbol2(match.state)} ${
|
|
5003
|
+
console.log(` ${stateSymbol2(match.state)} ${chalk23.bold(match.id)} ${match.version ? chalk23.dim("v" + match.version) : ""}`);
|
|
4361
5004
|
console.log(` State: ${match.state}`);
|
|
4362
5005
|
if (match.lastCheckAt) {
|
|
4363
5006
|
console.log(` Last check: ${new Date(match.lastCheckAt).toLocaleString()}`);
|
|
@@ -4366,7 +5009,7 @@ function registerComponentCommand(parent) {
|
|
|
4366
5009
|
console.log();
|
|
4367
5010
|
console.log(" Checks:");
|
|
4368
5011
|
for (const check of match.checks) {
|
|
4369
|
-
const cat = check.category ?
|
|
5012
|
+
const cat = check.category ? chalk23.dim(` (${check.category})`) : "";
|
|
4370
5013
|
console.log(` ${stateSymbol2(check.state)} ${check.name}${cat}`);
|
|
4371
5014
|
}
|
|
4372
5015
|
}
|
|
@@ -4378,12 +5021,12 @@ function registerComponentCommand(parent) {
|
|
|
4378
5021
|
}
|
|
4379
5022
|
|
|
4380
5023
|
// src/commands/status/incidents.ts
|
|
4381
|
-
import
|
|
5024
|
+
import chalk24 from "chalk";
|
|
4382
5025
|
var SEVERITY_COLORS = {
|
|
4383
|
-
ERROR:
|
|
4384
|
-
WARNING:
|
|
4385
|
-
INFO:
|
|
4386
|
-
MAINTENANCE:
|
|
5026
|
+
ERROR: chalk24.red,
|
|
5027
|
+
WARNING: chalk24.yellow,
|
|
5028
|
+
INFO: chalk24.blue,
|
|
5029
|
+
MAINTENANCE: chalk24.cyan
|
|
4387
5030
|
};
|
|
4388
5031
|
function registerIncidentsCommand(parent) {
|
|
4389
5032
|
parent.command("incidents").description("List recent incidents").option("-w, --window <window>", "Time window (e.g. 24h, 48h)", "24h").action(async (options, cmd) => {
|
|
@@ -4397,22 +5040,22 @@ function registerIncidentsCommand(parent) {
|
|
|
4397
5040
|
return;
|
|
4398
5041
|
}
|
|
4399
5042
|
if (incidents.length === 0) {
|
|
4400
|
-
console.log(
|
|
5043
|
+
console.log(chalk24.dim(`
|
|
4401
5044
|
No incidents in the last ${options.window}.
|
|
4402
5045
|
`));
|
|
4403
5046
|
return;
|
|
4404
5047
|
}
|
|
4405
5048
|
console.log();
|
|
4406
5049
|
for (const incident of incidents) {
|
|
4407
|
-
const color = SEVERITY_COLORS[incident.severity] ??
|
|
5050
|
+
const color = SEVERITY_COLORS[incident.severity] ?? chalk24.gray;
|
|
4408
5051
|
const severity = color(incident.severity.padEnd(8));
|
|
4409
5052
|
const time = incident.startedAt ? new Date(incident.startedAt).toLocaleString() : "";
|
|
4410
|
-
const resolved = incident.resolvedAt ?
|
|
5053
|
+
const resolved = incident.resolvedAt ? chalk24.green(" [resolved]") : chalk24.yellow(" [open]");
|
|
4411
5054
|
console.log(` ${severity} ${incident.summary}${resolved}`);
|
|
4412
|
-
console.log(
|
|
5055
|
+
console.log(chalk24.dim(` ${time}`));
|
|
4413
5056
|
for (const update of incident.updates) {
|
|
4414
5057
|
const updateTime = new Date(update.at).toLocaleTimeString();
|
|
4415
|
-
console.log(
|
|
5058
|
+
console.log(chalk24.dim(` ${updateTime} ${update.status} ${update.message}`));
|
|
4416
5059
|
}
|
|
4417
5060
|
console.log();
|
|
4418
5061
|
}
|
|
@@ -4431,9 +5074,9 @@ function registerStatusCommands(program) {
|
|
|
4431
5074
|
}
|
|
4432
5075
|
|
|
4433
5076
|
// src/commands/analyze/index.ts
|
|
4434
|
-
import
|
|
4435
|
-
import * as
|
|
4436
|
-
import * as
|
|
5077
|
+
import chalk25 from "chalk";
|
|
5078
|
+
import * as fs8 from "fs";
|
|
5079
|
+
import * as path7 from "path";
|
|
4437
5080
|
import { spawn as spawn2 } from "child_process";
|
|
4438
5081
|
function formatDuration(ms) {
|
|
4439
5082
|
const seconds = Math.floor(ms / 1e3);
|
|
@@ -4448,7 +5091,7 @@ function openUrl(url) {
|
|
|
4448
5091
|
const args = process.platform === "win32" ? ["/c", "start", '""', url] : [url];
|
|
4449
5092
|
spawn2(cmd, args, { detached: true, stdio: "ignore" }).unref();
|
|
4450
5093
|
}
|
|
4451
|
-
function
|
|
5094
|
+
function getOutputFormat15(cmd) {
|
|
4452
5095
|
const config = loadConfig();
|
|
4453
5096
|
const globalOpts = cmd.optsWithGlobals();
|
|
4454
5097
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -4468,20 +5111,20 @@ function isTerminalState(state) {
|
|
|
4468
5111
|
return state === "COMPLETED" || state === "FAILED" || state === "CANCELLED";
|
|
4469
5112
|
}
|
|
4470
5113
|
function multipartFromFile(file) {
|
|
4471
|
-
const buffer =
|
|
5114
|
+
const buffer = fs8.readFileSync(file);
|
|
4472
5115
|
const blob = new Blob([buffer]);
|
|
4473
5116
|
const formData = new FormData();
|
|
4474
|
-
formData.append("content", blob,
|
|
5117
|
+
formData.append("content", blob, path7.basename(file));
|
|
4475
5118
|
return formData;
|
|
4476
5119
|
}
|
|
4477
5120
|
async function runAnalysis(file, options, cmd) {
|
|
4478
|
-
if (!
|
|
4479
|
-
console.error(
|
|
5121
|
+
if (!fs8.existsSync(file)) {
|
|
5122
|
+
console.error(chalk25.red(`File not found: ${file}`));
|
|
4480
5123
|
process.exit(1);
|
|
4481
5124
|
}
|
|
4482
5125
|
const api = createApiClient();
|
|
4483
5126
|
const visibility = parseVisibility(options.visibility);
|
|
4484
|
-
const name = options.name ??
|
|
5127
|
+
const name = options.name ?? path7.basename(file, path7.extname(file));
|
|
4485
5128
|
const request = {
|
|
4486
5129
|
name,
|
|
4487
5130
|
description: options.description || null,
|
|
@@ -4495,21 +5138,21 @@ async function runAnalysis(file, options, cmd) {
|
|
|
4495
5138
|
};
|
|
4496
5139
|
process.stdout.write(`Creating analysis "${name}" ...`);
|
|
4497
5140
|
const created = await api.analysis.create(request);
|
|
4498
|
-
console.log(
|
|
4499
|
-
console.log(
|
|
4500
|
-
process.stdout.write(`Uploading ${
|
|
5141
|
+
console.log(chalk25.green(" done"));
|
|
5142
|
+
console.log(chalk25.dim(` analysisId: ${created.analysisId}`));
|
|
5143
|
+
process.stdout.write(`Uploading ${path7.basename(file)} ...`);
|
|
4501
5144
|
await api.analysis.uploadDataMultipart(created.analysisId, multipartFromFile(file));
|
|
4502
|
-
console.log(
|
|
5145
|
+
console.log(chalk25.green(" done"));
|
|
4503
5146
|
process.stdout.write("Queuing analysis run ...");
|
|
4504
5147
|
const run = await api.analysis.runAnalysis(created.analysisId);
|
|
4505
|
-
console.log(
|
|
4506
|
-
console.log(
|
|
5148
|
+
console.log(chalk25.green(" done"));
|
|
5149
|
+
console.log(chalk25.dim(` runId: ${run.runId}`));
|
|
4507
5150
|
console.log();
|
|
4508
5151
|
await monitorRun(api, created.analysisId, run.runId, parseFloat(options.hours), cmd);
|
|
4509
5152
|
}
|
|
4510
5153
|
async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
4511
5154
|
const config = loadConfig();
|
|
4512
|
-
const outputFormat =
|
|
5155
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4513
5156
|
const computationMs = hoursForProgress * 60 * 60 * 1e3;
|
|
4514
5157
|
const startMs = Date.now();
|
|
4515
5158
|
const seenOutputIds = /* @__PURE__ */ new Set();
|
|
@@ -4528,7 +5171,7 @@ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
|
4528
5171
|
if (!seenOutputIds.has(out.outputId)) {
|
|
4529
5172
|
seenOutputIds.add(out.outputId);
|
|
4530
5173
|
if (outputFormat === "human") {
|
|
4531
|
-
console.log(` ${
|
|
5174
|
+
console.log(` ${chalk25.dim("Output:")} ${out.output}`);
|
|
4532
5175
|
}
|
|
4533
5176
|
}
|
|
4534
5177
|
}
|
|
@@ -4541,7 +5184,7 @@ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
|
4541
5184
|
const durationStr = formatDuration(duration);
|
|
4542
5185
|
if (run.state === "COMPLETED") {
|
|
4543
5186
|
if (outputFormat === "human") {
|
|
4544
|
-
console.log(
|
|
5187
|
+
console.log(chalk25.green(`Analysis complete! (${durationStr})`));
|
|
4545
5188
|
try {
|
|
4546
5189
|
const nav = await api.analysis.getNavigation(analysisId);
|
|
4547
5190
|
const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
|
|
@@ -4553,13 +5196,13 @@ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
|
4553
5196
|
}
|
|
4554
5197
|
} else if (run.state === "CANCELLED") {
|
|
4555
5198
|
if (outputFormat === "human") {
|
|
4556
|
-
console.log(
|
|
5199
|
+
console.log(chalk25.yellow("Analysis cancelled."));
|
|
4557
5200
|
} else {
|
|
4558
5201
|
format({ status: "cancelled", runId, analysisId }, { format: outputFormat });
|
|
4559
5202
|
}
|
|
4560
5203
|
} else {
|
|
4561
5204
|
if (outputFormat === "human") {
|
|
4562
|
-
console.log(
|
|
5205
|
+
console.log(chalk25.red("Analysis failed."));
|
|
4563
5206
|
if (run.errorMessage) console.log(` Error: ${run.errorMessage}`);
|
|
4564
5207
|
} else {
|
|
4565
5208
|
format({ status: "failed", runId, analysisId, error: run.errorMessage }, { format: outputFormat });
|
|
@@ -4579,7 +5222,7 @@ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
|
|
|
4579
5222
|
}
|
|
4580
5223
|
}
|
|
4581
5224
|
async function listAnalyses(limit, cmd) {
|
|
4582
|
-
const outputFormat =
|
|
5225
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4583
5226
|
const api = createApiClient();
|
|
4584
5227
|
const analyses = await api.analysis.getRecent(limit);
|
|
4585
5228
|
format(analyses.map((a) => ({
|
|
@@ -4597,11 +5240,11 @@ async function listAnalyses(limit, cmd) {
|
|
|
4597
5240
|
});
|
|
4598
5241
|
}
|
|
4599
5242
|
async function getAnalysisDetails(analysisId, cmd) {
|
|
4600
|
-
const outputFormat =
|
|
5243
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4601
5244
|
const api = createApiClient();
|
|
4602
5245
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
4603
5246
|
if (!result.analysis) {
|
|
4604
|
-
console.log(
|
|
5247
|
+
console.log(chalk25.dim("No analysis found."));
|
|
4605
5248
|
return;
|
|
4606
5249
|
}
|
|
4607
5250
|
format(result.analysis, { format: outputFormat });
|
|
@@ -4610,18 +5253,18 @@ async function watchAnalysis(analysisId, cmd) {
|
|
|
4610
5253
|
const api = createApiClient();
|
|
4611
5254
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
4612
5255
|
if (!result.analysis) {
|
|
4613
|
-
console.log(
|
|
5256
|
+
console.log(chalk25.dim("No analysis found."));
|
|
4614
5257
|
return;
|
|
4615
5258
|
}
|
|
4616
5259
|
const recipe = result.analysis;
|
|
4617
5260
|
const runs = await api.analysis.getRunsForAnalysis(recipe.analysisId, 1);
|
|
4618
5261
|
if (runs.length === 0) {
|
|
4619
|
-
console.log(
|
|
5262
|
+
console.log(chalk25.dim("No runs for this analysis."));
|
|
4620
5263
|
return;
|
|
4621
5264
|
}
|
|
4622
5265
|
const latest = runs[0];
|
|
4623
5266
|
if (isTerminalState(latest.state)) {
|
|
4624
|
-
console.log(
|
|
5267
|
+
console.log(chalk25.green(`Latest run already in terminal state: ${latest.state}`));
|
|
4625
5268
|
try {
|
|
4626
5269
|
const nav = await api.analysis.getNavigation(recipe.analysisId);
|
|
4627
5270
|
const config = loadConfig();
|
|
@@ -4637,16 +5280,16 @@ async function watchAnalysis(analysisId, cmd) {
|
|
|
4637
5280
|
async function rerunAnalysis(analysisId) {
|
|
4638
5281
|
const api = createApiClient();
|
|
4639
5282
|
const run = await api.analysis.runAnalysis(analysisId);
|
|
4640
|
-
console.log(
|
|
4641
|
-
console.log(
|
|
5283
|
+
console.log(chalk25.green(`\u2713 Queued new run ${run.runId} for analysis ${analysisId}`));
|
|
5284
|
+
console.log(chalk25.dim(` State: ${run.state}`));
|
|
4642
5285
|
console.log();
|
|
4643
|
-
console.log(
|
|
5286
|
+
console.log(chalk25.dim("Track progress: diafunc analyze watch " + analysisId));
|
|
4644
5287
|
}
|
|
4645
5288
|
async function openAnalysis(analysisId) {
|
|
4646
5289
|
const api = createApiClient();
|
|
4647
5290
|
const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
|
|
4648
5291
|
if (!result.analysis) {
|
|
4649
|
-
console.log(
|
|
5292
|
+
console.log(chalk25.dim("No analysis found."));
|
|
4650
5293
|
return;
|
|
4651
5294
|
}
|
|
4652
5295
|
const config = loadConfig();
|
|
@@ -4657,11 +5300,11 @@ async function openAnalysis(analysisId) {
|
|
|
4657
5300
|
console.log(`Opening ${url} ...`);
|
|
4658
5301
|
openUrl(url);
|
|
4659
5302
|
} catch {
|
|
4660
|
-
console.log(
|
|
5303
|
+
console.log(chalk25.dim("Notebook not yet provisioned \u2014 run the analysis first."));
|
|
4661
5304
|
}
|
|
4662
5305
|
}
|
|
4663
5306
|
async function createRecipe(options, cmd) {
|
|
4664
|
-
const outputFormat =
|
|
5307
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4665
5308
|
const api = createApiClient();
|
|
4666
5309
|
const visibility = parseVisibility(options.visibility);
|
|
4667
5310
|
const request = {
|
|
@@ -4681,14 +5324,14 @@ async function createRecipe(options, cmd) {
|
|
|
4681
5324
|
async function deleteAnalysis(analysisId) {
|
|
4682
5325
|
const api = createApiClient();
|
|
4683
5326
|
await api.analysis.delete(analysisId);
|
|
4684
|
-
console.log(
|
|
5327
|
+
console.log(chalk25.green(`\u2713 Deleted analysis ${analysisId}`));
|
|
4685
5328
|
}
|
|
4686
5329
|
async function patchAndPrint(analysisId, value, handler, successLabel, cmd) {
|
|
4687
|
-
const outputFormat =
|
|
5330
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4688
5331
|
const api = createApiClient();
|
|
4689
5332
|
const updated = await handler(api, analysisId, value);
|
|
4690
5333
|
if (outputFormat === "human") {
|
|
4691
|
-
console.log(
|
|
5334
|
+
console.log(chalk25.green(`\u2713 ${successLabel} updated for analysis ${analysisId}`));
|
|
4692
5335
|
} else {
|
|
4693
5336
|
format(updated, { format: outputFormat });
|
|
4694
5337
|
}
|
|
@@ -4697,38 +5340,38 @@ async function uploadData(analysisId, file, options) {
|
|
|
4697
5340
|
const api = createApiClient();
|
|
4698
5341
|
if (options.url) {
|
|
4699
5342
|
if (file) {
|
|
4700
|
-
console.error(
|
|
5343
|
+
console.error(chalk25.red("Provide either a file or --url, not both."));
|
|
4701
5344
|
process.exit(1);
|
|
4702
5345
|
}
|
|
4703
5346
|
process.stdout.write(`Uploading from ${options.url} ...`);
|
|
4704
5347
|
await api.analysis.uploadDataUrl(analysisId, { dataUrl: options.url });
|
|
4705
|
-
console.log(
|
|
5348
|
+
console.log(chalk25.green(" done"));
|
|
4706
5349
|
return;
|
|
4707
5350
|
}
|
|
4708
5351
|
if (!file) {
|
|
4709
|
-
console.error(
|
|
5352
|
+
console.error(chalk25.red("Provide a file path or --url <URL>."));
|
|
4710
5353
|
process.exit(1);
|
|
4711
5354
|
}
|
|
4712
|
-
if (!
|
|
4713
|
-
console.error(
|
|
5355
|
+
if (!fs8.existsSync(file)) {
|
|
5356
|
+
console.error(chalk25.red(`File not found: ${file}`));
|
|
4714
5357
|
process.exit(1);
|
|
4715
5358
|
}
|
|
4716
|
-
process.stdout.write(`Uploading ${
|
|
5359
|
+
process.stdout.write(`Uploading ${path7.basename(file)} ...`);
|
|
4717
5360
|
await api.analysis.uploadDataMultipart(analysisId, multipartFromFile(file));
|
|
4718
|
-
console.log(
|
|
5361
|
+
console.log(chalk25.green(" done"));
|
|
4719
5362
|
}
|
|
4720
5363
|
async function listColumns(analysisId, cmd) {
|
|
4721
|
-
const outputFormat =
|
|
5364
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4722
5365
|
const api = createApiClient();
|
|
4723
5366
|
const columns = await api.analysis.getColumns(analysisId);
|
|
4724
5367
|
if (columns.length === 0) {
|
|
4725
|
-
console.log(
|
|
5368
|
+
console.log(chalk25.dim("No columns yet \u2014 upload data first."));
|
|
4726
5369
|
return;
|
|
4727
5370
|
}
|
|
4728
5371
|
format(columns, { format: outputFormat, columns: ["name", "valueType"] });
|
|
4729
5372
|
}
|
|
4730
5373
|
async function listRuns(analysisId, count, cmd) {
|
|
4731
|
-
const outputFormat =
|
|
5374
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4732
5375
|
const api = createApiClient();
|
|
4733
5376
|
const runs = await api.analysis.getRunsForAnalysis(analysisId, count);
|
|
4734
5377
|
format(runs.map((r) => ({
|
|
@@ -4744,17 +5387,17 @@ async function listRuns(analysisId, count, cmd) {
|
|
|
4744
5387
|
});
|
|
4745
5388
|
}
|
|
4746
5389
|
async function cancelRun(runId, cmd) {
|
|
4747
|
-
const outputFormat =
|
|
5390
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4748
5391
|
const api = createApiClient();
|
|
4749
5392
|
const run = await api.analysis.cancelRun(runId);
|
|
4750
5393
|
if (outputFormat === "human") {
|
|
4751
|
-
console.log(
|
|
5394
|
+
console.log(chalk25.green(`\u2713 Run ${run.runId} state: ${run.state}`));
|
|
4752
5395
|
} else {
|
|
4753
5396
|
format(run, { format: outputFormat });
|
|
4754
5397
|
}
|
|
4755
5398
|
}
|
|
4756
5399
|
async function listPresets(cmd) {
|
|
4757
|
-
const outputFormat =
|
|
5400
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4758
5401
|
const api = createApiClient();
|
|
4759
5402
|
const presets = await api.analysis.getPresets();
|
|
4760
5403
|
format(presets.map((p) => ({
|
|
@@ -4771,17 +5414,17 @@ async function listPresets(cmd) {
|
|
|
4771
5414
|
});
|
|
4772
5415
|
}
|
|
4773
5416
|
async function getPreset(presetId, cmd) {
|
|
4774
|
-
const outputFormat =
|
|
5417
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4775
5418
|
const api = createApiClient();
|
|
4776
5419
|
const opt = await api.analysis.getPreset(presetId);
|
|
4777
5420
|
if (!opt.preset) {
|
|
4778
|
-
console.log(
|
|
5421
|
+
console.log(chalk25.dim("Preset not found."));
|
|
4779
5422
|
return;
|
|
4780
5423
|
}
|
|
4781
5424
|
format(opt.preset, { format: outputFormat });
|
|
4782
5425
|
}
|
|
4783
5426
|
async function savePreset(options, cmd) {
|
|
4784
|
-
const outputFormat =
|
|
5427
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4785
5428
|
const api = createApiClient();
|
|
4786
5429
|
const preset = {
|
|
4787
5430
|
presetId: options.id ?? null,
|
|
@@ -4798,10 +5441,10 @@ async function savePreset(options, cmd) {
|
|
|
4798
5441
|
async function deletePreset(presetId) {
|
|
4799
5442
|
const api = createApiClient();
|
|
4800
5443
|
await api.analysis.deletePreset(presetId);
|
|
4801
|
-
console.log(
|
|
5444
|
+
console.log(chalk25.green(`\u2713 Deleted preset ${presetId}`));
|
|
4802
5445
|
}
|
|
4803
5446
|
async function listTriggers(analysisId, cmd) {
|
|
4804
|
-
const outputFormat =
|
|
5447
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4805
5448
|
const api = createApiClient();
|
|
4806
5449
|
const triggers = await api.analysis.listTriggers(analysisId);
|
|
4807
5450
|
format(triggers.map((t) => ({
|
|
@@ -4816,10 +5459,10 @@ async function listTriggers(analysisId, cmd) {
|
|
|
4816
5459
|
});
|
|
4817
5460
|
}
|
|
4818
5461
|
async function createTrigger(analysisId, kind, schedule, cmd) {
|
|
4819
|
-
const outputFormat =
|
|
5462
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4820
5463
|
const upper = kind.toUpperCase();
|
|
4821
5464
|
if (upper !== "ONCE" && upper !== "CRON") {
|
|
4822
|
-
console.error(
|
|
5465
|
+
console.error(chalk25.red(`Invalid kind "${kind}" \u2014 must be ONCE or CRON.`));
|
|
4823
5466
|
process.exit(1);
|
|
4824
5467
|
}
|
|
4825
5468
|
const api = createApiClient();
|
|
@@ -4832,21 +5475,21 @@ async function createTrigger(analysisId, kind, schedule, cmd) {
|
|
|
4832
5475
|
async function deleteTrigger(triggerId) {
|
|
4833
5476
|
const api = createApiClient();
|
|
4834
5477
|
await api.analysis.deleteTrigger(triggerId);
|
|
4835
|
-
console.log(
|
|
5478
|
+
console.log(chalk25.green(`\u2713 Deleted trigger ${triggerId}`));
|
|
4836
5479
|
}
|
|
4837
5480
|
async function updateTriggerCmd(triggerId, options, cmd) {
|
|
4838
|
-
const outputFormat =
|
|
5481
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
4839
5482
|
let activeFlag;
|
|
4840
5483
|
if (options.active !== void 0) {
|
|
4841
5484
|
const lc = options.active.toLowerCase();
|
|
4842
5485
|
if (lc !== "true" && lc !== "false") {
|
|
4843
|
-
console.error(
|
|
5486
|
+
console.error(chalk25.red(`Invalid --active value "${options.active}" \u2014 must be true or false.`));
|
|
4844
5487
|
process.exit(1);
|
|
4845
5488
|
}
|
|
4846
5489
|
activeFlag = lc === "true";
|
|
4847
5490
|
}
|
|
4848
5491
|
if (activeFlag === void 0 && !options.schedule) {
|
|
4849
|
-
console.error(
|
|
5492
|
+
console.error(chalk25.red("Pass at least one of --active or --schedule."));
|
|
4850
5493
|
process.exit(1);
|
|
4851
5494
|
}
|
|
4852
5495
|
const api = createApiClient();
|
|
@@ -5127,8 +5770,8 @@ function registerAnalyzeCommand(program) {
|
|
|
5127
5770
|
}
|
|
5128
5771
|
|
|
5129
5772
|
// src/commands/data-sources/index.ts
|
|
5130
|
-
import
|
|
5131
|
-
function
|
|
5773
|
+
import chalk26 from "chalk";
|
|
5774
|
+
function getOutputFormat16(cmd) {
|
|
5132
5775
|
const config = loadConfig();
|
|
5133
5776
|
const globalOpts = cmd.optsWithGlobals();
|
|
5134
5777
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5161,6 +5804,49 @@ function dataSourceTableRow(ds) {
|
|
|
5161
5804
|
lastRefreshAt: ds.lastRefreshAt ?? "\u2014"
|
|
5162
5805
|
};
|
|
5163
5806
|
}
|
|
5807
|
+
function formatBytes(bytes) {
|
|
5808
|
+
if (bytes === null || bytes === void 0) return "\u2014";
|
|
5809
|
+
if (bytes < 1e3) return `${bytes} B`;
|
|
5810
|
+
if (bytes < 1e6) return `${(bytes / 1e3).toFixed(1)} kB`;
|
|
5811
|
+
if (bytes < 1e9) return `${(bytes / 1e6).toFixed(2)} MB`;
|
|
5812
|
+
return `${(bytes / 1e9).toFixed(2)} GB`;
|
|
5813
|
+
}
|
|
5814
|
+
function formatCredits(credits) {
|
|
5815
|
+
if (credits === null || credits === void 0) return "\u2014";
|
|
5816
|
+
if (credits === 0) return "0";
|
|
5817
|
+
if (credits < 0.01) return credits.toFixed(4);
|
|
5818
|
+
return credits.toFixed(2);
|
|
5819
|
+
}
|
|
5820
|
+
function humanizeCron(cron) {
|
|
5821
|
+
if (!cron || !cron.trim()) return "manual";
|
|
5822
|
+
const parts = cron.trim().split(/\s+/);
|
|
5823
|
+
if (parts.length < 6) return cron.trim();
|
|
5824
|
+
const [sec, min, hour, dom, mon, dow] = parts;
|
|
5825
|
+
const pad2 = (n) => n.length < 2 ? `0${n}` : n;
|
|
5826
|
+
const everyDay = (dom === "*" || dom === "?") && mon === "*" && (dow === "*" || dow === "?");
|
|
5827
|
+
if (sec === "0" && min === "*" && hour === "*" && everyDay) return "every minute";
|
|
5828
|
+
if (sec === "0" && /^\d+$/.test(min) && hour === "*" && everyDay) {
|
|
5829
|
+
return min === "0" ? "hourly" : `hourly at :${pad2(min)}`;
|
|
5830
|
+
}
|
|
5831
|
+
if (sec === "0" && /^\d+$/.test(min) && /^\d+$/.test(hour) && everyDay) {
|
|
5832
|
+
if (hour === "0" && min === "0") return "daily at midnight UTC";
|
|
5833
|
+
return `daily at ${pad2(hour)}:${pad2(min)} UTC`;
|
|
5834
|
+
}
|
|
5835
|
+
return cron.trim();
|
|
5836
|
+
}
|
|
5837
|
+
function dashboardTableRow(s) {
|
|
5838
|
+
return {
|
|
5839
|
+
id: s.id,
|
|
5840
|
+
name: s.name,
|
|
5841
|
+
type: s.type,
|
|
5842
|
+
schedule: humanizeCron(s.scheduleCron),
|
|
5843
|
+
lastStatus: s.lastRunStatus ?? "\u2014",
|
|
5844
|
+
lastRunAt: s.lastRunAt ?? "\u2014",
|
|
5845
|
+
nextScheduledAt: s.nextScheduledAt ?? "\u2014",
|
|
5846
|
+
recentFailures: `${s.recentFailureCount}/${s.recentRunCount}`,
|
|
5847
|
+
lastTransferred: formatBytes(s.lastBytesFetched)
|
|
5848
|
+
};
|
|
5849
|
+
}
|
|
5164
5850
|
function runTableRow(run) {
|
|
5165
5851
|
return {
|
|
5166
5852
|
runId: run.runId,
|
|
@@ -5168,15 +5854,17 @@ function runTableRow(run) {
|
|
|
5168
5854
|
startedAt: run.startedAt ?? "\u2014",
|
|
5169
5855
|
finishedAt: run.finishedAt ?? "\u2014",
|
|
5170
5856
|
rows: run.rowsImported !== null && run.rowsImported !== void 0 ? String(run.rowsImported) : "\u2014",
|
|
5857
|
+
transferred: formatBytes(run.bytesFetched),
|
|
5858
|
+
credits: formatCredits(run.creditsCharged),
|
|
5171
5859
|
triggeredBy: run.triggeredBy ?? "\u2014"
|
|
5172
5860
|
};
|
|
5173
5861
|
}
|
|
5174
5862
|
async function listDataSources(projectId, cmd) {
|
|
5175
|
-
const outputFormat =
|
|
5863
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5176
5864
|
const api = createApiClient();
|
|
5177
5865
|
const sources = await api.storage.listDataSources(projectId);
|
|
5178
5866
|
if (outputFormat === "human" && sources.length === 0) {
|
|
5179
|
-
console.log(
|
|
5867
|
+
console.log(chalk26.dim("No data sources found."));
|
|
5180
5868
|
return;
|
|
5181
5869
|
}
|
|
5182
5870
|
format(sources.map(dataSourceTableRow), {
|
|
@@ -5185,13 +5873,34 @@ async function listDataSources(projectId, cmd) {
|
|
|
5185
5873
|
});
|
|
5186
5874
|
}
|
|
5187
5875
|
async function getDataSource(id, cmd) {
|
|
5188
|
-
const outputFormat =
|
|
5876
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5189
5877
|
const api = createApiClient();
|
|
5190
5878
|
const ds = await api.storage.getDataSource(id);
|
|
5191
5879
|
format(ds, { format: outputFormat });
|
|
5192
5880
|
}
|
|
5881
|
+
async function showDashboard(projectId, cmd) {
|
|
5882
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5883
|
+
const api = createApiClient();
|
|
5884
|
+
const dashboard = await api.storage.getDataSourceDashboard(projectId);
|
|
5885
|
+
if (outputFormat !== "human") {
|
|
5886
|
+
format(dashboard, { format: outputFormat });
|
|
5887
|
+
return;
|
|
5888
|
+
}
|
|
5889
|
+
const r = dashboard.rollup;
|
|
5890
|
+
let line = chalk26.bold(`DataSources in ${projectId}: `) + `${r.totalSources} total, ${r.scheduledSources} scheduled, ${r.sourcesWithRecentFailure} failing recently`;
|
|
5891
|
+
if (r.lastActivityAt) line += `, last activity ${r.lastActivityAt}`;
|
|
5892
|
+
console.log(line);
|
|
5893
|
+
if (dashboard.sources.length === 0) {
|
|
5894
|
+
console.log(chalk26.dim("No data sources."));
|
|
5895
|
+
return;
|
|
5896
|
+
}
|
|
5897
|
+
format(dashboard.sources.map(dashboardTableRow), {
|
|
5898
|
+
format: outputFormat,
|
|
5899
|
+
columns: ["id", "name", "type", "schedule", "lastStatus", "lastRunAt", "nextScheduledAt", "recentFailures", "lastTransferred"]
|
|
5900
|
+
});
|
|
5901
|
+
}
|
|
5193
5902
|
async function createDataSource(options, cmd) {
|
|
5194
|
-
const outputFormat =
|
|
5903
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5195
5904
|
const api = createApiClient();
|
|
5196
5905
|
const request = {
|
|
5197
5906
|
projectId: options.projectId,
|
|
@@ -5205,15 +5914,15 @@ async function createDataSource(options, cmd) {
|
|
|
5205
5914
|
};
|
|
5206
5915
|
const ds = await api.storage.createDataSource(request);
|
|
5207
5916
|
if (outputFormat === "human") {
|
|
5208
|
-
console.log(
|
|
5209
|
-
console.log(
|
|
5210
|
-
if (ds.lastRunError) console.log(
|
|
5917
|
+
console.log(chalk26.green(`\u2713 Created data source ${ds.id}`));
|
|
5918
|
+
console.log(chalk26.dim(` Last run: ${ds.lastRunStatus ?? "\u2014"}`));
|
|
5919
|
+
if (ds.lastRunError) console.log(chalk26.dim(` Error: ${ds.lastRunError}`));
|
|
5211
5920
|
} else {
|
|
5212
5921
|
format(ds, { format: outputFormat });
|
|
5213
5922
|
}
|
|
5214
5923
|
}
|
|
5215
5924
|
async function updateDataSource(id, options, cmd) {
|
|
5216
|
-
const outputFormat =
|
|
5925
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5217
5926
|
if (options.name === void 0 && options.type === void 0 && (!options.config || options.config.length === 0) && options.scheduleCron === void 0 && !options.clearSchedule) {
|
|
5218
5927
|
throw new Error("Provide at least one of --name, --type, --config, --schedule-cron, or --clear-schedule.");
|
|
5219
5928
|
}
|
|
@@ -5237,7 +5946,7 @@ async function updateDataSource(id, options, cmd) {
|
|
|
5237
5946
|
const api = createApiClient();
|
|
5238
5947
|
const ds = await api.storage.updateDataSource(id, request);
|
|
5239
5948
|
if (outputFormat === "human") {
|
|
5240
|
-
console.log(
|
|
5949
|
+
console.log(chalk26.green(`\u2713 Updated data source ${ds.id}`));
|
|
5241
5950
|
} else {
|
|
5242
5951
|
format(ds, { format: outputFormat });
|
|
5243
5952
|
}
|
|
@@ -5245,45 +5954,45 @@ async function updateDataSource(id, options, cmd) {
|
|
|
5245
5954
|
async function deleteDataSource(id) {
|
|
5246
5955
|
const api = createApiClient();
|
|
5247
5956
|
await api.storage.deleteDataSource(id);
|
|
5248
|
-
console.log(
|
|
5957
|
+
console.log(chalk26.green(`\u2713 Deleted data source ${id}`));
|
|
5249
5958
|
}
|
|
5250
5959
|
async function refreshDataSource(id, cmd) {
|
|
5251
|
-
const outputFormat =
|
|
5960
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5252
5961
|
const api = createApiClient();
|
|
5253
5962
|
const run = await api.storage.refreshDataSource(id);
|
|
5254
5963
|
if (outputFormat === "human") {
|
|
5255
|
-
console.log(
|
|
5256
|
-
if (run.errorMessage) console.log(
|
|
5964
|
+
console.log(chalk26.green(`\u2713 Refresh queued \u2014 run ${run.runId}, status ${run.status}`));
|
|
5965
|
+
if (run.errorMessage) console.log(chalk26.red(` Error: ${run.errorMessage}`));
|
|
5257
5966
|
} else {
|
|
5258
5967
|
format(run, { format: outputFormat });
|
|
5259
5968
|
}
|
|
5260
5969
|
}
|
|
5261
5970
|
async function listRuns2(id, limit, cmd) {
|
|
5262
|
-
const outputFormat =
|
|
5971
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5263
5972
|
const api = createApiClient();
|
|
5264
5973
|
const runs = await api.storage.listDataSourceRuns(id, limit);
|
|
5265
5974
|
if (outputFormat === "human" && runs.length === 0) {
|
|
5266
|
-
console.log(
|
|
5975
|
+
console.log(chalk26.dim("No runs yet."));
|
|
5267
5976
|
return;
|
|
5268
5977
|
}
|
|
5269
5978
|
format(runs.map(runTableRow), {
|
|
5270
5979
|
format: outputFormat,
|
|
5271
|
-
columns: ["runId", "status", "startedAt", "finishedAt", "rows", "triggeredBy"]
|
|
5980
|
+
columns: ["runId", "status", "startedAt", "finishedAt", "rows", "transferred", "credits", "triggeredBy"]
|
|
5272
5981
|
});
|
|
5273
5982
|
}
|
|
5274
5983
|
async function getRun(id, runId, cmd) {
|
|
5275
|
-
const outputFormat =
|
|
5984
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5276
5985
|
const api = createApiClient();
|
|
5277
5986
|
const run = await api.storage.getDataSourceRun(id, runId);
|
|
5278
5987
|
format(run, { format: outputFormat });
|
|
5279
5988
|
}
|
|
5280
5989
|
async function listConnectorTypes(cmd) {
|
|
5281
|
-
const outputFormat =
|
|
5990
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5282
5991
|
const api = createApiClient();
|
|
5283
5992
|
const types = await api.storage.listDataSourceConnectorTypes();
|
|
5284
5993
|
if (outputFormat === "human") {
|
|
5285
5994
|
if (types.length === 0) {
|
|
5286
|
-
console.log(
|
|
5995
|
+
console.log(chalk26.dim("No connector types registered."));
|
|
5287
5996
|
return;
|
|
5288
5997
|
}
|
|
5289
5998
|
for (const t of types) console.log(t);
|
|
@@ -5300,6 +6009,13 @@ function registerDataSourcesCommands(program) {
|
|
|
5300
6009
|
handleError(error);
|
|
5301
6010
|
}
|
|
5302
6011
|
});
|
|
6012
|
+
dataSources.command("dashboard").description("Project-level rollup: per-source last-run status, next-scheduled, recent failures").requiredOption("--project-id <id>", "Project ID").action(async (options, cmd) => {
|
|
6013
|
+
try {
|
|
6014
|
+
await showDashboard(options.projectId, cmd);
|
|
6015
|
+
} catch (error) {
|
|
6016
|
+
handleError(error);
|
|
6017
|
+
}
|
|
6018
|
+
});
|
|
5303
6019
|
dataSources.command("get").description("Show one data source").argument("<id>", "Data source ID (UUID)").action(async (id, _options, cmd) => {
|
|
5304
6020
|
try {
|
|
5305
6021
|
await getDataSource(id, cmd);
|
|
@@ -5358,6 +6074,260 @@ function registerDataSourcesCommands(program) {
|
|
|
5358
6074
|
});
|
|
5359
6075
|
}
|
|
5360
6076
|
|
|
6077
|
+
// src/commands/table-exporters/index.ts
|
|
6078
|
+
import chalk27 from "chalk";
|
|
6079
|
+
function getOutputFormat17(cmd) {
|
|
6080
|
+
const config = loadConfig();
|
|
6081
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
6082
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
6083
|
+
}
|
|
6084
|
+
function registerTableExportersCommands(program) {
|
|
6085
|
+
const exporters = program.command("table-exporters").description("Manage user-defined exporters (UDE) \u2014 admin-only");
|
|
6086
|
+
exporters.command("list").description("List all registered user-defined exporters").action(async (_options, cmd) => {
|
|
6087
|
+
try {
|
|
6088
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
6089
|
+
const api = createApiClient();
|
|
6090
|
+
const list = await api.storage.listUserDefinedExporters();
|
|
6091
|
+
if (outputFormat === "json") {
|
|
6092
|
+
format(list, { format: outputFormat });
|
|
6093
|
+
return;
|
|
6094
|
+
}
|
|
6095
|
+
const rows = list.map((e) => ({
|
|
6096
|
+
id: e.id ?? "",
|
|
6097
|
+
name: e.name,
|
|
6098
|
+
format: e.format,
|
|
6099
|
+
extension: e.extension ?? "",
|
|
6100
|
+
mimeType: e.mimeType ?? "",
|
|
6101
|
+
priority: e.priority ?? 50,
|
|
6102
|
+
function: `${e.functionProjectId}/${e.functionEntityId}`,
|
|
6103
|
+
createdBy: e.createdBy ?? ""
|
|
6104
|
+
}));
|
|
6105
|
+
format(rows, {
|
|
6106
|
+
format: outputFormat,
|
|
6107
|
+
columns: ["id", "name", "format", "extension", "mimeType", "priority", "function", "createdBy"]
|
|
6108
|
+
});
|
|
6109
|
+
console.log(chalk27.dim(`${list.length} exporter(s)`));
|
|
6110
|
+
} catch (error) {
|
|
6111
|
+
handleError(error);
|
|
6112
|
+
}
|
|
6113
|
+
});
|
|
6114
|
+
exporters.command("get").description("Show a single user-defined exporter by id").argument("<id>", "Exporter id").action(async (id, _options, cmd) => {
|
|
6115
|
+
try {
|
|
6116
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
6117
|
+
const api = createApiClient();
|
|
6118
|
+
const list = await api.storage.listUserDefinedExporters();
|
|
6119
|
+
const exporter = list.find((e) => e.id === id);
|
|
6120
|
+
if (!exporter) {
|
|
6121
|
+
console.error(chalk27.red(`No exporter with id="${id}".`));
|
|
6122
|
+
process.exit(1);
|
|
6123
|
+
}
|
|
6124
|
+
format(exporter, { format: outputFormat });
|
|
6125
|
+
} catch (error) {
|
|
6126
|
+
handleError(error);
|
|
6127
|
+
}
|
|
6128
|
+
});
|
|
6129
|
+
exporters.command("create").description("Register a new user-defined exporter").requiredOption("--name <name>", 'Display name (e.g. "Acme machine instrument export")').requiredOption("--format <token>", 'Format token used in the dispatch URL (e.g. "acme")').requiredOption("--function-project <id>", "Function entity's project id").requiredOption("--function-entity <id>", "Function entity id").option("--description <text>", "Free-form description").option("--extension <ext>", 'Filename extension (must start with ".")').option("--mime-type <mime>", "MIME type the function produces").option("--function-project-branch <branch>", "Function project branch", "main").option("--function-entity-branch <branch>", "Function entity branch", "main").option("--priority <n>", "Dispatch priority (default 50; > 200 overrides built-ins)", "50").action(async (options, cmd) => {
|
|
6130
|
+
try {
|
|
6131
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
6132
|
+
const api = createApiClient();
|
|
6133
|
+
const payload = {
|
|
6134
|
+
name: options.name,
|
|
6135
|
+
description: options.description,
|
|
6136
|
+
format: options.format,
|
|
6137
|
+
extension: options.extension,
|
|
6138
|
+
mimeType: options.mimeType,
|
|
6139
|
+
functionProjectId: options.functionProject,
|
|
6140
|
+
functionProjectBranch: options.functionProjectBranch,
|
|
6141
|
+
functionEntityId: options.functionEntity,
|
|
6142
|
+
functionEntityBranch: options.functionEntityBranch,
|
|
6143
|
+
priority: Number(options.priority)
|
|
6144
|
+
};
|
|
6145
|
+
const created = await api.storage.registerUserDefinedExporter(payload);
|
|
6146
|
+
if (outputFormat === "json") {
|
|
6147
|
+
format(created, { format: outputFormat });
|
|
6148
|
+
return;
|
|
6149
|
+
}
|
|
6150
|
+
console.log(chalk27.green(`Registered exporter "${created.name}" (id=${created.id}, format=${created.format})`));
|
|
6151
|
+
} catch (error) {
|
|
6152
|
+
handleError(error);
|
|
6153
|
+
}
|
|
6154
|
+
});
|
|
6155
|
+
exporters.command("delete").description("Delete a user-defined exporter").argument("<id>", "Exporter id").action(async (id) => {
|
|
6156
|
+
try {
|
|
6157
|
+
const api = createApiClient();
|
|
6158
|
+
await api.storage.deleteUserDefinedExporter(id);
|
|
6159
|
+
console.log(chalk27.green(`Deleted exporter id=${id}`));
|
|
6160
|
+
} catch (error) {
|
|
6161
|
+
handleError(error);
|
|
6162
|
+
}
|
|
6163
|
+
});
|
|
6164
|
+
}
|
|
6165
|
+
|
|
6166
|
+
// src/commands/skeleton/index.ts
|
|
6167
|
+
import chalk28 from "chalk";
|
|
6168
|
+
import * as fs9 from "fs";
|
|
6169
|
+
function getOutputFormat18(cmd) {
|
|
6170
|
+
const config = loadConfig();
|
|
6171
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
6172
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
6173
|
+
}
|
|
6174
|
+
function resolveProjectId(localOption, cmd) {
|
|
6175
|
+
if (localOption) return localOption;
|
|
6176
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
6177
|
+
if (globalOpts.project) return globalOpts.project;
|
|
6178
|
+
const config = loadConfig();
|
|
6179
|
+
if (config.defaults.project) return config.defaults.project;
|
|
6180
|
+
throw new Error(
|
|
6181
|
+
"No project specified. Pass --project <id>, set the global --project flag, or run `diafunc config defaults project <id>`."
|
|
6182
|
+
);
|
|
6183
|
+
}
|
|
6184
|
+
function resolveTemplate(raw) {
|
|
6185
|
+
if (raw.startsWith("@@")) {
|
|
6186
|
+
return raw.substring(1);
|
|
6187
|
+
}
|
|
6188
|
+
if (raw.startsWith("@")) {
|
|
6189
|
+
const file = raw.substring(1);
|
|
6190
|
+
if (!file) {
|
|
6191
|
+
throw new Error("--template @ requires a filename after the @, e.g. --template @template.txt");
|
|
6192
|
+
}
|
|
6193
|
+
if (!fs9.existsSync(file)) {
|
|
6194
|
+
throw new Error(`Template file not found: ${file}`);
|
|
6195
|
+
}
|
|
6196
|
+
return fs9.readFileSync(file, "utf-8").trim();
|
|
6197
|
+
}
|
|
6198
|
+
return raw;
|
|
6199
|
+
}
|
|
6200
|
+
function parseWeight(raw) {
|
|
6201
|
+
if (raw === void 0) return null;
|
|
6202
|
+
const value = Number(raw);
|
|
6203
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
6204
|
+
throw new Error(`Invalid --weight "${raw}" \u2014 must be a positive number.`);
|
|
6205
|
+
}
|
|
6206
|
+
return value;
|
|
6207
|
+
}
|
|
6208
|
+
function skeletonTableRow(s) {
|
|
6209
|
+
return {
|
|
6210
|
+
id: s.id,
|
|
6211
|
+
name: s.name,
|
|
6212
|
+
template: s.template,
|
|
6213
|
+
paramCount: String(s.paramCount),
|
|
6214
|
+
weight: s.weight.toFixed(2),
|
|
6215
|
+
createdAt: s.createdAt ?? "\u2014"
|
|
6216
|
+
};
|
|
6217
|
+
}
|
|
6218
|
+
async function createSkeleton(options, cmd) {
|
|
6219
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
6220
|
+
const projectId = resolveProjectId(options.project, cmd);
|
|
6221
|
+
const template = resolveTemplate(options.template);
|
|
6222
|
+
const weight = parseWeight(options.weight);
|
|
6223
|
+
const request = {
|
|
6224
|
+
projectId,
|
|
6225
|
+
projectBranch: options.branch,
|
|
6226
|
+
name: options.name,
|
|
6227
|
+
template,
|
|
6228
|
+
weight
|
|
6229
|
+
};
|
|
6230
|
+
const api = createApiClient();
|
|
6231
|
+
const skeleton = await api.storage.createSkeleton(request);
|
|
6232
|
+
if (outputFormat === "human") {
|
|
6233
|
+
console.log(chalk28.green(`\u2713 Created skeleton ${skeleton.id}`));
|
|
6234
|
+
console.log(chalk28.dim(` name: ${skeleton.name}`));
|
|
6235
|
+
console.log(chalk28.dim(` template: ${skeleton.template}`));
|
|
6236
|
+
console.log(chalk28.dim(` paramCount: ${skeleton.paramCount}`));
|
|
6237
|
+
console.log(chalk28.dim(` weight: ${skeleton.weight}`));
|
|
6238
|
+
} else {
|
|
6239
|
+
format(skeleton, { format: outputFormat });
|
|
6240
|
+
}
|
|
6241
|
+
}
|
|
6242
|
+
async function listSkeletons(localProject, cmd) {
|
|
6243
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
6244
|
+
const projectId = resolveProjectId(localProject, cmd);
|
|
6245
|
+
const api = createApiClient();
|
|
6246
|
+
const skeletons = await api.storage.listSkeletons(projectId);
|
|
6247
|
+
if (outputFormat === "human" && skeletons.length === 0) {
|
|
6248
|
+
console.log(chalk28.dim(`No skeletons in project ${projectId}.`));
|
|
6249
|
+
return;
|
|
6250
|
+
}
|
|
6251
|
+
format(skeletons.map(skeletonTableRow), {
|
|
6252
|
+
format: outputFormat,
|
|
6253
|
+
columns: ["id", "name", "template", "paramCount", "weight", "createdAt"]
|
|
6254
|
+
});
|
|
6255
|
+
}
|
|
6256
|
+
async function getSkeleton(id, cmd) {
|
|
6257
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
6258
|
+
const api = createApiClient();
|
|
6259
|
+
const skeleton = await api.storage.getSkeleton(id);
|
|
6260
|
+
format(skeleton, { format: outputFormat });
|
|
6261
|
+
}
|
|
6262
|
+
async function updateSkeleton(id, options, cmd) {
|
|
6263
|
+
const outputFormat = getOutputFormat18(cmd);
|
|
6264
|
+
if (options.name === void 0 && options.template === void 0 && options.weight === void 0) {
|
|
6265
|
+
throw new Error("Provide at least one of --name, --template, --weight.");
|
|
6266
|
+
}
|
|
6267
|
+
const request = {
|
|
6268
|
+
name: options.name ?? null,
|
|
6269
|
+
template: options.template !== void 0 ? resolveTemplate(options.template) : null,
|
|
6270
|
+
weight: parseWeight(options.weight)
|
|
6271
|
+
};
|
|
6272
|
+
const api = createApiClient();
|
|
6273
|
+
const skeleton = await api.storage.updateSkeleton(id, request);
|
|
6274
|
+
if (outputFormat === "human") {
|
|
6275
|
+
console.log(chalk28.green(`\u2713 Updated skeleton ${skeleton.id}`));
|
|
6276
|
+
console.log(chalk28.dim(` name: ${skeleton.name}`));
|
|
6277
|
+
console.log(chalk28.dim(` template: ${skeleton.template}`));
|
|
6278
|
+
console.log(chalk28.dim(` paramCount: ${skeleton.paramCount}`));
|
|
6279
|
+
console.log(chalk28.dim(` weight: ${skeleton.weight}`));
|
|
6280
|
+
} else {
|
|
6281
|
+
format(skeleton, { format: outputFormat });
|
|
6282
|
+
}
|
|
6283
|
+
}
|
|
6284
|
+
async function deleteSkeleton(id) {
|
|
6285
|
+
const api = createApiClient();
|
|
6286
|
+
await api.storage.deleteSkeleton(id);
|
|
6287
|
+
console.log(chalk28.green(`\u2713 Deleted skeleton ${id}`));
|
|
6288
|
+
}
|
|
6289
|
+
function registerSkeletonCommands(program) {
|
|
6290
|
+
const skeleton = program.command("skeleton").description("Manage user-provided skeleton templates (project-scoped, capped at 100/project)");
|
|
6291
|
+
skeleton.command("create").description("Create a skeleton. Parse errors from the engine are surfaced as stderr.").requiredOption("--name <name>", "Display name").requiredOption(
|
|
6292
|
+
"--template <expr>",
|
|
6293
|
+
'Skeleton template expression (e.g. "?*x+?"). Use "@file.txt" to read from a file; "@@\u2026" escapes a literal leading @.'
|
|
6294
|
+
).option("--project <id>", "Project ID (defaults to global --project / config defaults.project)").option("--branch <branch>", "Project branch", "main").option("--weight <number>", "Sampling weight (positive; server default applies if omitted)").action(async (options, cmd) => {
|
|
6295
|
+
try {
|
|
6296
|
+
await createSkeleton(options, cmd);
|
|
6297
|
+
} catch (error) {
|
|
6298
|
+
handleError(error);
|
|
6299
|
+
}
|
|
6300
|
+
});
|
|
6301
|
+
skeleton.command("list").description("List skeletons in a project").option("--project <id>", "Project ID (defaults to global --project / config defaults.project)").action(async (options, cmd) => {
|
|
6302
|
+
try {
|
|
6303
|
+
await listSkeletons(options.project, cmd);
|
|
6304
|
+
} catch (error) {
|
|
6305
|
+
handleError(error);
|
|
6306
|
+
}
|
|
6307
|
+
});
|
|
6308
|
+
skeleton.command("get").description("Show one skeleton").argument("<id>", "Skeleton ID (UUID)").action(async (id, _options, cmd) => {
|
|
6309
|
+
try {
|
|
6310
|
+
await getSkeleton(id, cmd);
|
|
6311
|
+
} catch (error) {
|
|
6312
|
+
handleError(error);
|
|
6313
|
+
}
|
|
6314
|
+
});
|
|
6315
|
+
skeleton.command("update").description("Update a skeleton (omit a flag to leave that field unchanged)").argument("<id>", "Skeleton ID").option("--name <name>", "New display name").option("--template <expr>", 'New template expression (supports the same "@file.txt" sugar as create)').option("--weight <number>", "New sampling weight (positive)").action(async (id, options, cmd) => {
|
|
6316
|
+
try {
|
|
6317
|
+
await updateSkeleton(id, options, cmd);
|
|
6318
|
+
} catch (error) {
|
|
6319
|
+
handleError(error);
|
|
6320
|
+
}
|
|
6321
|
+
});
|
|
6322
|
+
skeleton.command("delete").description("Delete a skeleton").argument("<id>", "Skeleton ID").action(async (id) => {
|
|
6323
|
+
try {
|
|
6324
|
+
await deleteSkeleton(id);
|
|
6325
|
+
} catch (error) {
|
|
6326
|
+
handleError(error);
|
|
6327
|
+
}
|
|
6328
|
+
});
|
|
6329
|
+
}
|
|
6330
|
+
|
|
5361
6331
|
// src/commands/completion/index.ts
|
|
5362
6332
|
var BASH_COMPLETION = `#!/bin/bash
|
|
5363
6333
|
_diafunc_completions() {
|
|
@@ -5612,7 +6582,7 @@ function registerCompletionCommand(program) {
|
|
|
5612
6582
|
}
|
|
5613
6583
|
|
|
5614
6584
|
// src/commands/whoami/index.ts
|
|
5615
|
-
import
|
|
6585
|
+
import chalk29 from "chalk";
|
|
5616
6586
|
function registerWhoamiCommand(program) {
|
|
5617
6587
|
program.command("whoami").description("Show the currently authenticated user").action(async (_options, cmd) => {
|
|
5618
6588
|
try {
|
|
@@ -5622,8 +6592,8 @@ function registerWhoamiCommand(program) {
|
|
|
5622
6592
|
const api = createApiClient();
|
|
5623
6593
|
const user = await api.admin.getMyUser();
|
|
5624
6594
|
if (outputFormat === "human") {
|
|
5625
|
-
console.log(
|
|
5626
|
-
console.log(
|
|
6595
|
+
console.log(chalk29.bold(user.name) + chalk29.dim(` <${user.email}>`));
|
|
6596
|
+
console.log(chalk29.dim(` Role: ${user.role} \xB7 Remaining credits: ${user.remainingCredits} \xB7 Profile: ${config.currentProfile}`));
|
|
5627
6597
|
} else {
|
|
5628
6598
|
format(user, { format: outputFormat });
|
|
5629
6599
|
}
|
|
@@ -5634,8 +6604,8 @@ function registerWhoamiCommand(program) {
|
|
|
5634
6604
|
}
|
|
5635
6605
|
|
|
5636
6606
|
// src/commands/utilization/index.ts
|
|
5637
|
-
import
|
|
5638
|
-
function
|
|
6607
|
+
import chalk30 from "chalk";
|
|
6608
|
+
function getOutputFormat19(cmd) {
|
|
5639
6609
|
const config = loadConfig();
|
|
5640
6610
|
const globalOpts = cmd.optsWithGlobals();
|
|
5641
6611
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5643,27 +6613,27 @@ function getOutputFormat16(cmd) {
|
|
|
5643
6613
|
function printUtilizationHuman(u, label) {
|
|
5644
6614
|
const when = u.day !== null && u.day !== void 0 ? `${u.year}-${String(u.month).padStart(2, "0")}-${String(u.day).padStart(2, "0")}` : `${u.year}-${String(u.month).padStart(2, "0")}`;
|
|
5645
6615
|
if (label) {
|
|
5646
|
-
console.log(
|
|
6616
|
+
console.log(chalk30.bold(label) + " " + chalk30.dim(when));
|
|
5647
6617
|
} else {
|
|
5648
|
-
console.log(
|
|
6618
|
+
console.log(chalk30.bold(when));
|
|
5649
6619
|
}
|
|
5650
6620
|
if (u.types.length === 0) {
|
|
5651
|
-
console.log(
|
|
6621
|
+
console.log(chalk30.dim(" (no usage)"));
|
|
5652
6622
|
return;
|
|
5653
6623
|
}
|
|
5654
6624
|
for (const t of u.types) {
|
|
5655
6625
|
console.log(
|
|
5656
|
-
` ${t.type.padEnd(24)} ${
|
|
6626
|
+
` ${t.type.padEnd(24)} ${chalk30.cyan(String(t.quantity).padStart(10))} ${chalk30.dim("credits:")} ${t.credits.toFixed(2)}`
|
|
5657
6627
|
);
|
|
5658
6628
|
}
|
|
5659
6629
|
const total = u.totalCredits ?? u.types.reduce((s, t) => s + t.credits, 0);
|
|
5660
|
-
console.log(
|
|
6630
|
+
console.log(chalk30.bold(` Total credits: ${total.toFixed(2)}`));
|
|
5661
6631
|
}
|
|
5662
6632
|
function registerUtilizationCommand(program) {
|
|
5663
6633
|
const util = program.command("utilization").description("Show credit utilization");
|
|
5664
6634
|
util.command("actual", { isDefault: true }).description("Show current utilization (default subcommand)").action(async (_options, cmd) => {
|
|
5665
6635
|
try {
|
|
5666
|
-
const outputFormat =
|
|
6636
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
5667
6637
|
const api = createApiClient();
|
|
5668
6638
|
const utilization = await api.admin.getActualUtilization();
|
|
5669
6639
|
if (outputFormat === "human") {
|
|
@@ -5677,12 +6647,12 @@ function registerUtilizationCommand(program) {
|
|
|
5677
6647
|
});
|
|
5678
6648
|
util.command("history").description("Show utilization history").action(async (_options, cmd) => {
|
|
5679
6649
|
try {
|
|
5680
|
-
const outputFormat =
|
|
6650
|
+
const outputFormat = getOutputFormat19(cmd);
|
|
5681
6651
|
const api = createApiClient();
|
|
5682
6652
|
const history = await api.admin.getUtilizationHistory();
|
|
5683
6653
|
if (outputFormat === "human") {
|
|
5684
6654
|
if (history.length === 0) {
|
|
5685
|
-
console.log(
|
|
6655
|
+
console.log(chalk30.dim("No usage recorded."));
|
|
5686
6656
|
return;
|
|
5687
6657
|
}
|
|
5688
6658
|
for (const u of history) {
|
|
@@ -5699,13 +6669,13 @@ function registerUtilizationCommand(program) {
|
|
|
5699
6669
|
}
|
|
5700
6670
|
|
|
5701
6671
|
// src/commands/entity-branch/index.ts
|
|
5702
|
-
import
|
|
5703
|
-
function
|
|
6672
|
+
import chalk31 from "chalk";
|
|
6673
|
+
function getOutputFormat20(cmd) {
|
|
5704
6674
|
const config = loadConfig();
|
|
5705
6675
|
const globalOpts = cmd.optsWithGlobals();
|
|
5706
6676
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
5707
6677
|
}
|
|
5708
|
-
function
|
|
6678
|
+
function getOverrides11(cmd) {
|
|
5709
6679
|
const opts = cmd.optsWithGlobals();
|
|
5710
6680
|
return { project: opts.project, branch: opts.branch };
|
|
5711
6681
|
}
|
|
@@ -5713,8 +6683,8 @@ function registerEntityBranchCommands(program) {
|
|
|
5713
6683
|
const eb = program.command("entity-branch").description("Manage entity branches (parallel versions of a single entity)");
|
|
5714
6684
|
eb.command("list").description("List branches of an entity").argument("<ref>", "Entity reference (projectId/branch/entityId)").action(async (ref, _options, cmd) => {
|
|
5715
6685
|
try {
|
|
5716
|
-
const outputFormat =
|
|
5717
|
-
const overrides =
|
|
6686
|
+
const outputFormat = getOutputFormat20(cmd);
|
|
6687
|
+
const overrides = getOverrides11(cmd);
|
|
5718
6688
|
const resolved = parseEntityReference(ref, overrides);
|
|
5719
6689
|
const api = createApiClient();
|
|
5720
6690
|
const branches = await api.storage.getEntityBranches(
|
|
@@ -5733,7 +6703,7 @@ function registerEntityBranchCommands(program) {
|
|
|
5733
6703
|
});
|
|
5734
6704
|
eb.command("create").description("Create a new branch of an entity from an existing branch").argument("<ref>", "Source entity reference (projectId/branch/entityId/sourceBranch)").argument("<targetBranch>", "New branch name").action(async (ref, targetBranch, _options, cmd) => {
|
|
5735
6705
|
try {
|
|
5736
|
-
const overrides =
|
|
6706
|
+
const overrides = getOverrides11(cmd);
|
|
5737
6707
|
const resolved = parseEntityReference(ref, overrides);
|
|
5738
6708
|
const api = createApiClient();
|
|
5739
6709
|
await api.storage.createEntityBranch({
|
|
@@ -5743,7 +6713,7 @@ function registerEntityBranchCommands(program) {
|
|
|
5743
6713
|
sourceEntityBranch: resolved.entityBranch,
|
|
5744
6714
|
targetEntityBranch: targetBranch
|
|
5745
6715
|
});
|
|
5746
|
-
console.log(
|
|
6716
|
+
console.log(chalk31.green(`Entity branch "${targetBranch}" created from "${resolved.entityBranch}".`));
|
|
5747
6717
|
} catch (error) {
|
|
5748
6718
|
handleError(error);
|
|
5749
6719
|
}
|
|
@@ -5751,7 +6721,7 @@ function registerEntityBranchCommands(program) {
|
|
|
5751
6721
|
}
|
|
5752
6722
|
|
|
5753
6723
|
// src/commands/subscription/index.ts
|
|
5754
|
-
function
|
|
6724
|
+
function getOutputFormat21(cmd) {
|
|
5755
6725
|
const config = loadConfig();
|
|
5756
6726
|
const globalOpts = cmd.optsWithGlobals();
|
|
5757
6727
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5762,7 +6732,7 @@ function registerSubscriptionCommand(program) {
|
|
|
5762
6732
|
try {
|
|
5763
6733
|
const api = createApiClient();
|
|
5764
6734
|
const s = await api.admin.getCurrentSubscription();
|
|
5765
|
-
format(s, { format:
|
|
6735
|
+
format(s, { format: getOutputFormat21(cmd) });
|
|
5766
6736
|
} catch (error) {
|
|
5767
6737
|
handleError(error);
|
|
5768
6738
|
}
|
|
@@ -5771,7 +6741,7 @@ function registerSubscriptionCommand(program) {
|
|
|
5771
6741
|
try {
|
|
5772
6742
|
const api = createApiClient();
|
|
5773
6743
|
const s = await api.admin.getNextSubscription();
|
|
5774
|
-
format(s, { format:
|
|
6744
|
+
format(s, { format: getOutputFormat21(cmd) });
|
|
5775
6745
|
} catch (error) {
|
|
5776
6746
|
handleError(error);
|
|
5777
6747
|
}
|
|
@@ -5780,7 +6750,7 @@ function registerSubscriptionCommand(program) {
|
|
|
5780
6750
|
try {
|
|
5781
6751
|
const api = createApiClient();
|
|
5782
6752
|
const plans = await api.admin.getSubscriptionPlans(subscriptionToken);
|
|
5783
|
-
format(plans, { format:
|
|
6753
|
+
format(plans, { format: getOutputFormat21(cmd) });
|
|
5784
6754
|
} catch (error) {
|
|
5785
6755
|
handleError(error);
|
|
5786
6756
|
}
|
|
@@ -5788,9 +6758,9 @@ function registerSubscriptionCommand(program) {
|
|
|
5788
6758
|
}
|
|
5789
6759
|
|
|
5790
6760
|
// src/commands/invoice/index.ts
|
|
5791
|
-
import
|
|
5792
|
-
import * as
|
|
5793
|
-
function
|
|
6761
|
+
import chalk32 from "chalk";
|
|
6762
|
+
import * as fs10 from "fs";
|
|
6763
|
+
function getOutputFormat22(cmd) {
|
|
5794
6764
|
const config = loadConfig();
|
|
5795
6765
|
const globalOpts = cmd.optsWithGlobals();
|
|
5796
6766
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
@@ -5802,7 +6772,7 @@ function registerInvoiceCommand(program) {
|
|
|
5802
6772
|
const api = createApiClient();
|
|
5803
6773
|
const invoices = await api.admin.getInvoices();
|
|
5804
6774
|
format(invoices, {
|
|
5805
|
-
format:
|
|
6775
|
+
format: getOutputFormat22(cmd),
|
|
5806
6776
|
columns: ["invoiceNumber", "issued", "periodFrom", "periodTo", "total", "status"]
|
|
5807
6777
|
});
|
|
5808
6778
|
} catch (error) {
|
|
@@ -5815,8 +6785,8 @@ function registerInvoiceCommand(program) {
|
|
|
5815
6785
|
const response = await api.admin.downloadInvoice(invoiceNumber, fileName);
|
|
5816
6786
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
5817
6787
|
const outPath = options.out ?? fileName;
|
|
5818
|
-
|
|
5819
|
-
console.log(
|
|
6788
|
+
fs10.writeFileSync(outPath, buffer);
|
|
6789
|
+
console.log(chalk32.green(`Invoice saved to ${outPath}`));
|
|
5820
6790
|
} catch (error) {
|
|
5821
6791
|
handleError(error);
|
|
5822
6792
|
}
|
|
@@ -5824,10 +6794,10 @@ function registerInvoiceCommand(program) {
|
|
|
5824
6794
|
}
|
|
5825
6795
|
|
|
5826
6796
|
// src/commands/shell/index.ts
|
|
5827
|
-
import
|
|
5828
|
-
import * as
|
|
6797
|
+
import chalk33 from "chalk";
|
|
6798
|
+
import * as fs11 from "fs";
|
|
5829
6799
|
import * as os3 from "os";
|
|
5830
|
-
import * as
|
|
6800
|
+
import * as path8 from "path";
|
|
5831
6801
|
import { spawn as spawn3 } from "child_process";
|
|
5832
6802
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
5833
6803
|
function extensionFor2(language) {
|
|
@@ -5840,16 +6810,16 @@ function extensionFor2(language) {
|
|
|
5840
6810
|
return "txt";
|
|
5841
6811
|
}
|
|
5842
6812
|
async function openInEditor(initial, ext) {
|
|
5843
|
-
const tmpFile =
|
|
5844
|
-
|
|
6813
|
+
const tmpFile = path8.join(os3.tmpdir(), `diafunc-shell-${randomUUID3()}.${ext}`);
|
|
6814
|
+
fs11.writeFileSync(tmpFile, initial);
|
|
5845
6815
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
5846
6816
|
await new Promise((resolve, reject) => {
|
|
5847
6817
|
const child = spawn3(editor, [tmpFile], { stdio: "inherit" });
|
|
5848
6818
|
child.on("exit", (code) => code === 0 ? resolve() : reject(new Error(`Editor exited with ${code}`)));
|
|
5849
6819
|
child.on("error", reject);
|
|
5850
6820
|
});
|
|
5851
|
-
const content =
|
|
5852
|
-
|
|
6821
|
+
const content = fs11.readFileSync(tmpFile, "utf-8");
|
|
6822
|
+
fs11.unlinkSync(tmpFile);
|
|
5853
6823
|
return content;
|
|
5854
6824
|
}
|
|
5855
6825
|
function utcNowParts() {
|
|
@@ -5890,21 +6860,21 @@ async function evaluate(api, fnRef, language, sourceCode) {
|
|
|
5890
6860
|
}, false);
|
|
5891
6861
|
if (result.outputs?.length) {
|
|
5892
6862
|
for (const out of result.outputs) {
|
|
5893
|
-
console.log(
|
|
6863
|
+
console.log(chalk33.dim(` [${out.type}]`) + " " + out.output);
|
|
5894
6864
|
}
|
|
5895
6865
|
}
|
|
5896
6866
|
if (result.successful) {
|
|
5897
6867
|
if (result.result) {
|
|
5898
|
-
console.log(
|
|
6868
|
+
console.log(chalk33.green("=> ") + result.result);
|
|
5899
6869
|
} else {
|
|
5900
|
-
console.log(
|
|
6870
|
+
console.log(chalk33.dim("=> (no value)"));
|
|
5901
6871
|
}
|
|
5902
6872
|
const duration = result.completed - result.started;
|
|
5903
|
-
console.log(
|
|
6873
|
+
console.log(chalk33.dim(` [${duration}ms \xB7 ${evaluationId}]`));
|
|
5904
6874
|
} else {
|
|
5905
|
-
console.log(
|
|
6875
|
+
console.log(chalk33.red("error: ") + result.error);
|
|
5906
6876
|
if (result.lineNumber > 0) {
|
|
5907
|
-
console.log(
|
|
6877
|
+
console.log(chalk33.dim(` at line ${result.lineNumber}, col ${result.columnNumber}`));
|
|
5908
6878
|
}
|
|
5909
6879
|
}
|
|
5910
6880
|
}
|
|
@@ -5912,9 +6882,9 @@ function registerShellCommand(program) {
|
|
|
5912
6882
|
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", "JavaScript").action(async (options, cmd) => {
|
|
5913
6883
|
try {
|
|
5914
6884
|
if (!options.function) {
|
|
5915
|
-
console.error(
|
|
5916
|
-
console.error(
|
|
5917
|
-
console.error(
|
|
6885
|
+
console.error(chalk33.red("Missing --function <ref>."));
|
|
6886
|
+
console.error(chalk33.dim("Pass an existing or new function entity reference to use as the shell target."));
|
|
6887
|
+
console.error(chalk33.dim("Example: diafunc shell --function my-project/main/scratch/main --language JavaScript"));
|
|
5918
6888
|
process.exit(1);
|
|
5919
6889
|
}
|
|
5920
6890
|
const config = loadConfig();
|
|
@@ -5925,18 +6895,18 @@ function registerShellCommand(program) {
|
|
|
5925
6895
|
});
|
|
5926
6896
|
const api = createApiClient();
|
|
5927
6897
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
5928
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
5929
|
-
console.log(
|
|
5930
|
-
console.log(
|
|
5931
|
-
console.log(
|
|
6898
|
+
const { getUpdateNotice } = await import("./update-check-KL3CHODI.js");
|
|
6899
|
+
console.log(chalk33.bold("Diafunc shell") + chalk33.dim(` \xB7 function ${fnRef.entityId} \xB7 ${options.language}`));
|
|
6900
|
+
console.log(chalk33.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
6901
|
+
console.log(chalk33.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
|
|
5932
6902
|
const notice = await getUpdateNotice();
|
|
5933
|
-
if (notice) console.log(
|
|
6903
|
+
if (notice) console.log(chalk33.dim(notice));
|
|
5934
6904
|
console.log();
|
|
5935
6905
|
let language = options.language;
|
|
5936
6906
|
for (; ; ) {
|
|
5937
6907
|
let line;
|
|
5938
6908
|
try {
|
|
5939
|
-
line = await promptInput({ message:
|
|
6909
|
+
line = await promptInput({ message: chalk33.cyan.bold(`${language} >`) });
|
|
5940
6910
|
} catch {
|
|
5941
6911
|
console.log();
|
|
5942
6912
|
return;
|
|
@@ -5954,54 +6924,54 @@ function registerShellCommand(program) {
|
|
|
5954
6924
|
case "help":
|
|
5955
6925
|
case "h":
|
|
5956
6926
|
case "?":
|
|
5957
|
-
console.log(
|
|
5958
|
-
console.log(
|
|
5959
|
-
console.log(
|
|
5960
|
-
console.log(
|
|
6927
|
+
console.log(chalk33.dim(" /edit open $EDITOR for multi-line code"));
|
|
6928
|
+
console.log(chalk33.dim(" /file <path> evaluate the contents of a file"));
|
|
6929
|
+
console.log(chalk33.dim(" /lang <name> switch language (Java, JavaScript, Kotlin, Python, Scala)"));
|
|
6930
|
+
console.log(chalk33.dim(" /quit exit the shell"));
|
|
5961
6931
|
continue;
|
|
5962
6932
|
case "lang":
|
|
5963
6933
|
if (arg) language = arg;
|
|
5964
|
-
console.log(
|
|
6934
|
+
console.log(chalk33.dim(`Language: ${language}`));
|
|
5965
6935
|
continue;
|
|
5966
6936
|
case "edit": {
|
|
5967
6937
|
const sourceCode = await openInEditor("", extensionFor2(language));
|
|
5968
6938
|
if (!sourceCode.trim()) {
|
|
5969
|
-
console.log(
|
|
6939
|
+
console.log(chalk33.dim("(empty \u2014 not evaluated)"));
|
|
5970
6940
|
continue;
|
|
5971
6941
|
}
|
|
5972
6942
|
try {
|
|
5973
6943
|
await evaluate(api, fnRef, language, sourceCode);
|
|
5974
6944
|
} catch (e) {
|
|
5975
|
-
console.error(
|
|
6945
|
+
console.error(chalk33.red(e.message));
|
|
5976
6946
|
}
|
|
5977
6947
|
continue;
|
|
5978
6948
|
}
|
|
5979
6949
|
case "file": {
|
|
5980
6950
|
if (!arg) {
|
|
5981
|
-
console.log(
|
|
6951
|
+
console.log(chalk33.dim("usage: /file <path>"));
|
|
5982
6952
|
continue;
|
|
5983
6953
|
}
|
|
5984
|
-
if (!
|
|
5985
|
-
console.log(
|
|
6954
|
+
if (!fs11.existsSync(arg)) {
|
|
6955
|
+
console.log(chalk33.red(`file not found: ${arg}`));
|
|
5986
6956
|
continue;
|
|
5987
6957
|
}
|
|
5988
|
-
const sourceCode =
|
|
6958
|
+
const sourceCode = fs11.readFileSync(arg, "utf-8");
|
|
5989
6959
|
try {
|
|
5990
6960
|
await evaluate(api, fnRef, language, sourceCode);
|
|
5991
6961
|
} catch (e) {
|
|
5992
|
-
console.error(
|
|
6962
|
+
console.error(chalk33.red(e.message));
|
|
5993
6963
|
}
|
|
5994
6964
|
continue;
|
|
5995
6965
|
}
|
|
5996
6966
|
default:
|
|
5997
|
-
console.log(
|
|
6967
|
+
console.log(chalk33.dim(`Unknown command: /${cmd2}. Try /help.`));
|
|
5998
6968
|
continue;
|
|
5999
6969
|
}
|
|
6000
6970
|
}
|
|
6001
6971
|
try {
|
|
6002
6972
|
await evaluate(api, fnRef, language, trimmed);
|
|
6003
6973
|
} catch (e) {
|
|
6004
|
-
console.error(
|
|
6974
|
+
console.error(chalk33.red(e.message));
|
|
6005
6975
|
}
|
|
6006
6976
|
}
|
|
6007
6977
|
} catch (error) {
|
|
@@ -6011,19 +6981,19 @@ function registerShellCommand(program) {
|
|
|
6011
6981
|
}
|
|
6012
6982
|
|
|
6013
6983
|
// src/commands/update/index.ts
|
|
6014
|
-
import
|
|
6015
|
-
import * as
|
|
6984
|
+
import chalk34 from "chalk";
|
|
6985
|
+
import * as path9 from "path";
|
|
6016
6986
|
import { spawn as spawn4 } from "child_process";
|
|
6017
6987
|
|
|
6018
6988
|
// src/util/install-method.ts
|
|
6019
|
-
import * as
|
|
6989
|
+
import * as fs12 from "fs";
|
|
6020
6990
|
function detectInstall() {
|
|
6021
6991
|
const exec = process.execPath;
|
|
6022
6992
|
const exe = exec.replace(/\\/g, "/").toLowerCase();
|
|
6023
6993
|
const isNode = exe.endsWith("/node") || exe.endsWith("/node.exe");
|
|
6024
6994
|
return {
|
|
6025
6995
|
method: isNode ? "npm" : "binary",
|
|
6026
|
-
binaryPath: isNode ? exec :
|
|
6996
|
+
binaryPath: isNode ? exec : fs12.realpathSync(exec)
|
|
6027
6997
|
};
|
|
6028
6998
|
}
|
|
6029
6999
|
|
|
@@ -6057,17 +7027,17 @@ function registerUpdateCommand(program) {
|
|
|
6057
7027
|
const install = detectInstall();
|
|
6058
7028
|
const latest = await fetchLatestVersion();
|
|
6059
7029
|
if (latest === package_default.version) {
|
|
6060
|
-
console.log(
|
|
7030
|
+
console.log(chalk34.dim(`diafunc is already at the latest version (${package_default.version}).`));
|
|
6061
7031
|
return;
|
|
6062
7032
|
}
|
|
6063
|
-
console.log(
|
|
7033
|
+
console.log(chalk34.dim(`Current: ${package_default.version} \u2192 Available: ${latest}`));
|
|
6064
7034
|
if (install.method === "npm") {
|
|
6065
7035
|
console.log();
|
|
6066
7036
|
console.log("Installed via npm. Upgrade with:");
|
|
6067
|
-
console.log(
|
|
7037
|
+
console.log(chalk34.bold(` npm install -g @diafunc/cli@${latest}`));
|
|
6068
7038
|
return;
|
|
6069
7039
|
}
|
|
6070
|
-
const installDir =
|
|
7040
|
+
const installDir = path9.dirname(install.binaryPath);
|
|
6071
7041
|
console.log(`Installing diafunc ${latest} to ${installDir}...`);
|
|
6072
7042
|
console.log();
|
|
6073
7043
|
await runInstaller(installDir);
|
|
@@ -6078,23 +7048,23 @@ function registerUpdateCommand(program) {
|
|
|
6078
7048
|
}
|
|
6079
7049
|
|
|
6080
7050
|
// src/commands/uninstall/index.ts
|
|
6081
|
-
import
|
|
7051
|
+
import chalk35 from "chalk";
|
|
6082
7052
|
import { spawn as spawn5 } from "child_process";
|
|
6083
|
-
import * as
|
|
7053
|
+
import * as fs13 from "fs";
|
|
6084
7054
|
import * as os4 from "os";
|
|
6085
|
-
import * as
|
|
7055
|
+
import * as path10 from "path";
|
|
6086
7056
|
function registerUninstallCommand(program) {
|
|
6087
7057
|
program.command("uninstall").description("Remove the CLI binary and (optionally) its config from this machine").option("-y, --yes", "Skip confirmation prompts").option("--purge", "Also remove ~/.diafunc/ (config + credentials) without prompting").action(async (options) => {
|
|
6088
7058
|
try {
|
|
6089
7059
|
const install = detectInstall();
|
|
6090
|
-
const configDir =
|
|
7060
|
+
const configDir = path10.join(os4.homedir(), ".diafunc");
|
|
6091
7061
|
if (install.method === "npm") {
|
|
6092
7062
|
console.log("Installed via npm. Remove with:");
|
|
6093
|
-
console.log(
|
|
6094
|
-
if (
|
|
7063
|
+
console.log(chalk35.bold(" npm uninstall -g @diafunc/cli"));
|
|
7064
|
+
if (fs13.existsSync(configDir)) {
|
|
6095
7065
|
console.log();
|
|
6096
7066
|
console.log(`Config + credentials live at ${configDir} \u2014 remove manually with:`);
|
|
6097
|
-
console.log(
|
|
7067
|
+
console.log(chalk35.bold(` rm -rf ${configDir}`));
|
|
6098
7068
|
}
|
|
6099
7069
|
return;
|
|
6100
7070
|
}
|
|
@@ -6104,19 +7074,19 @@ function registerUninstallCommand(program) {
|
|
|
6104
7074
|
default: false
|
|
6105
7075
|
});
|
|
6106
7076
|
if (!removeBinary) {
|
|
6107
|
-
console.log(
|
|
7077
|
+
console.log(chalk35.dim("Aborted."));
|
|
6108
7078
|
return;
|
|
6109
7079
|
}
|
|
6110
7080
|
let removeConfig = options.purge ?? false;
|
|
6111
|
-
if (!options.purge && !options.yes &&
|
|
7081
|
+
if (!options.purge && !options.yes && fs13.existsSync(configDir)) {
|
|
6112
7082
|
removeConfig = await confirm({
|
|
6113
7083
|
message: `Also remove ${configDir} (config + credentials)?`,
|
|
6114
7084
|
default: false
|
|
6115
7085
|
});
|
|
6116
7086
|
}
|
|
6117
|
-
if (removeConfig &&
|
|
6118
|
-
|
|
6119
|
-
console.log(
|
|
7087
|
+
if (removeConfig && fs13.existsSync(configDir)) {
|
|
7088
|
+
fs13.rmSync(configDir, { recursive: true, force: true });
|
|
7089
|
+
console.log(chalk35.dim(`Removed ${configDir}`));
|
|
6120
7090
|
}
|
|
6121
7091
|
if (process.platform === "win32") {
|
|
6122
7092
|
const cmd = `timeout /t 2 /nobreak >nul & del /f /q "${install.binaryPath}"`;
|
|
@@ -6126,13 +7096,13 @@ function registerUninstallCommand(program) {
|
|
|
6126
7096
|
windowsHide: true
|
|
6127
7097
|
});
|
|
6128
7098
|
child.unref();
|
|
6129
|
-
console.log(
|
|
7099
|
+
console.log(chalk35.dim(`Removing ${install.binaryPath} on exit...`));
|
|
6130
7100
|
console.log();
|
|
6131
7101
|
console.log("diafunc uninstalled.");
|
|
6132
7102
|
return;
|
|
6133
7103
|
}
|
|
6134
|
-
|
|
6135
|
-
console.log(
|
|
7104
|
+
fs13.rmSync(install.binaryPath, { force: true });
|
|
7105
|
+
console.log(chalk35.dim(`Removed ${install.binaryPath}`));
|
|
6136
7106
|
console.log();
|
|
6137
7107
|
console.log("diafunc uninstalled.");
|
|
6138
7108
|
} catch (error) {
|
|
@@ -6158,6 +7128,7 @@ function createProgram() {
|
|
|
6158
7128
|
registerEventCommands(program);
|
|
6159
7129
|
registerBranchCommands(program);
|
|
6160
7130
|
registerTableCommands(program);
|
|
7131
|
+
registerNotebookCommands(program);
|
|
6161
7132
|
registerFunctionCommands(program);
|
|
6162
7133
|
registerTriggerCommands(program);
|
|
6163
7134
|
registerScheduleCommands(program);
|
|
@@ -6168,6 +7139,8 @@ function createProgram() {
|
|
|
6168
7139
|
registerStatusCommands(program);
|
|
6169
7140
|
registerAnalyzeCommand(program);
|
|
6170
7141
|
registerDataSourcesCommands(program);
|
|
7142
|
+
registerTableExportersCommands(program);
|
|
7143
|
+
registerSkeletonCommands(program);
|
|
6171
7144
|
registerCompletionCommand(program);
|
|
6172
7145
|
registerWhoamiCommand(program);
|
|
6173
7146
|
registerUtilizationCommand(program);
|
|
@@ -6183,4 +7156,4 @@ function createProgram() {
|
|
|
6183
7156
|
export {
|
|
6184
7157
|
createProgram
|
|
6185
7158
|
};
|
|
6186
|
-
//# sourceMappingURL=chunk-
|
|
7159
|
+
//# sourceMappingURL=chunk-E4O67FMQ.js.map
|