bkper 4.0.1 → 4.1.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/CHANGELOG.md +51 -28
- package/README.md +52 -4
- package/lib/auth/local-auth-service.d.ts +12 -0
- package/lib/auth/local-auth-service.d.ts.map +1 -1
- package/lib/auth/local-auth-service.js +12 -0
- package/lib/auth/local-auth-service.js.map +1 -1
- package/lib/bkper-factory.d.ts.map +1 -1
- package/lib/bkper-factory.js +5 -0
- package/lib/bkper-factory.js.map +1 -1
- package/lib/cli.js +19 -881
- package/lib/cli.js.map +1 -1
- package/lib/commands/accounts/batch-create.d.ts +10 -0
- package/lib/commands/accounts/batch-create.d.ts.map +1 -0
- package/lib/commands/accounts/batch-create.js +74 -0
- package/lib/commands/accounts/batch-create.js.map +1 -0
- package/lib/commands/accounts/create.d.ts +17 -0
- package/lib/commands/accounts/create.d.ts.map +1 -1
- package/lib/commands/accounts/create.js +24 -5
- package/lib/commands/accounts/create.js.map +1 -1
- package/lib/commands/accounts/delete.d.ts +8 -0
- package/lib/commands/accounts/delete.d.ts.map +1 -1
- package/lib/commands/accounts/delete.js +8 -0
- package/lib/commands/accounts/delete.js.map +1 -1
- package/lib/commands/accounts/get.d.ts +8 -0
- package/lib/commands/accounts/get.d.ts.map +1 -1
- package/lib/commands/accounts/get.js +8 -0
- package/lib/commands/accounts/get.js.map +1 -1
- package/lib/commands/accounts/index.d.ts +2 -1
- package/lib/commands/accounts/index.d.ts.map +1 -1
- package/lib/commands/accounts/index.js +2 -1
- package/lib/commands/accounts/index.js.map +1 -1
- package/lib/commands/accounts/list.d.ts +12 -0
- package/lib/commands/accounts/list.d.ts.map +1 -1
- package/lib/commands/accounts/list.js +25 -0
- package/lib/commands/accounts/list.js.map +1 -1
- package/lib/commands/accounts/register.d.ts +3 -0
- package/lib/commands/accounts/register.d.ts.map +1 -0
- package/lib/commands/accounts/register.js +96 -0
- package/lib/commands/accounts/register.js.map +1 -0
- package/lib/commands/accounts/update.d.ts +18 -0
- package/lib/commands/accounts/update.d.ts.map +1 -1
- package/lib/commands/accounts/update.js +23 -5
- package/lib/commands/accounts/update.js.map +1 -1
- package/lib/commands/action.d.ts +21 -0
- package/lib/commands/action.d.ts.map +1 -0
- package/lib/commands/action.js +36 -0
- package/lib/commands/action.js.map +1 -0
- package/lib/commands/apps/index.d.ts +1 -1
- package/lib/commands/apps/index.d.ts.map +1 -1
- package/lib/commands/apps/index.js +1 -1
- package/lib/commands/apps/index.js.map +1 -1
- package/lib/commands/apps/install.d.ts +7 -0
- package/lib/commands/apps/install.d.ts.map +1 -1
- package/lib/commands/apps/install.js +7 -0
- package/lib/commands/apps/install.js.map +1 -1
- package/lib/commands/apps/list.d.ts +6 -0
- package/lib/commands/apps/list.d.ts.map +1 -1
- package/lib/commands/apps/list.js +20 -0
- package/lib/commands/apps/list.js.map +1 -1
- package/lib/commands/apps/register.d.ts +3 -0
- package/lib/commands/apps/register.d.ts.map +1 -0
- package/lib/commands/apps/register.js +130 -0
- package/lib/commands/apps/register.js.map +1 -0
- package/lib/commands/apps/uninstall.d.ts +8 -0
- package/lib/commands/apps/uninstall.d.ts.map +1 -1
- package/lib/commands/apps/uninstall.js +8 -0
- package/lib/commands/apps/uninstall.js.map +1 -1
- package/lib/commands/balances/list.d.ts +12 -0
- package/lib/commands/balances/list.d.ts.map +1 -1
- package/lib/commands/balances/list.js +16 -1
- package/lib/commands/balances/list.js.map +1 -1
- package/lib/commands/balances/register.d.ts +3 -0
- package/lib/commands/balances/register.d.ts.map +1 -0
- package/lib/commands/balances/register.js +35 -0
- package/lib/commands/balances/register.js.map +1 -0
- package/lib/commands/books/create.d.ts +9 -0
- package/lib/commands/books/create.d.ts.map +1 -1
- package/lib/commands/books/create.js +16 -2
- package/lib/commands/books/create.js.map +1 -1
- package/lib/commands/books/get.d.ts +6 -0
- package/lib/commands/books/get.d.ts.map +1 -1
- package/lib/commands/books/get.js +6 -0
- package/lib/commands/books/get.js.map +1 -1
- package/lib/commands/books/index.d.ts +1 -1
- package/lib/commands/books/index.d.ts.map +1 -1
- package/lib/commands/books/index.js +1 -1
- package/lib/commands/books/index.js.map +1 -1
- package/lib/commands/books/list.d.ts +13 -0
- package/lib/commands/books/list.d.ts.map +1 -1
- package/lib/commands/books/list.js +43 -0
- package/lib/commands/books/list.js.map +1 -1
- package/lib/commands/books/register.d.ts +3 -0
- package/lib/commands/books/register.d.ts.map +1 -0
- package/lib/commands/books/register.js +82 -0
- package/lib/commands/books/register.js.map +1 -0
- package/lib/commands/books/update.d.ts +11 -0
- package/lib/commands/books/update.d.ts.map +1 -1
- package/lib/commands/books/update.js +21 -5
- package/lib/commands/books/update.js.map +1 -1
- package/lib/commands/cli-helpers.d.ts +15 -0
- package/lib/commands/cli-helpers.d.ts.map +1 -0
- package/lib/commands/cli-helpers.js +29 -0
- package/lib/commands/cli-helpers.js.map +1 -0
- package/lib/commands/collections/add-book.d.ts +8 -0
- package/lib/commands/collections/add-book.d.ts.map +1 -1
- package/lib/commands/collections/add-book.js +8 -0
- package/lib/commands/collections/add-book.js.map +1 -1
- package/lib/commands/collections/create.d.ts +9 -0
- package/lib/commands/collections/create.d.ts.map +1 -1
- package/lib/commands/collections/create.js +6 -0
- package/lib/commands/collections/create.js.map +1 -1
- package/lib/commands/collections/delete.d.ts +7 -0
- package/lib/commands/collections/delete.d.ts.map +1 -1
- package/lib/commands/collections/delete.js +7 -0
- package/lib/commands/collections/delete.js.map +1 -1
- package/lib/commands/collections/get.d.ts +7 -0
- package/lib/commands/collections/get.d.ts.map +1 -1
- package/lib/commands/collections/get.js +7 -0
- package/lib/commands/collections/get.js.map +1 -1
- package/lib/commands/collections/index.d.ts +1 -1
- package/lib/commands/collections/index.d.ts.map +1 -1
- package/lib/commands/collections/index.js +1 -1
- package/lib/commands/collections/index.js.map +1 -1
- package/lib/commands/collections/list.d.ts +11 -0
- package/lib/commands/collections/list.d.ts.map +1 -1
- package/lib/commands/collections/list.js +26 -0
- package/lib/commands/collections/list.js.map +1 -1
- package/lib/commands/collections/register.d.ts +3 -0
- package/lib/commands/collections/register.d.ts.map +1 -0
- package/lib/commands/collections/register.js +86 -0
- package/lib/commands/collections/register.js.map +1 -0
- package/lib/commands/collections/remove-book.d.ts +8 -0
- package/lib/commands/collections/remove-book.d.ts.map +1 -1
- package/lib/commands/collections/remove-book.js +8 -0
- package/lib/commands/collections/remove-book.js.map +1 -1
- package/lib/commands/collections/update.d.ts +11 -0
- package/lib/commands/collections/update.d.ts.map +1 -1
- package/lib/commands/collections/update.js +8 -0
- package/lib/commands/collections/update.js.map +1 -1
- package/lib/commands/groups/batch-create.d.ts +10 -0
- package/lib/commands/groups/batch-create.d.ts.map +1 -0
- package/lib/commands/groups/batch-create.js +69 -0
- package/lib/commands/groups/batch-create.js.map +1 -0
- package/lib/commands/groups/create.d.ts +8 -0
- package/lib/commands/groups/create.d.ts.map +1 -1
- package/lib/commands/groups/create.js +23 -5
- package/lib/commands/groups/create.js.map +1 -1
- package/lib/commands/groups/delete.d.ts +7 -0
- package/lib/commands/groups/delete.d.ts.map +1 -1
- package/lib/commands/groups/delete.js +7 -0
- package/lib/commands/groups/delete.js.map +1 -1
- package/lib/commands/groups/get.d.ts +7 -0
- package/lib/commands/groups/get.d.ts.map +1 -1
- package/lib/commands/groups/get.js +7 -0
- package/lib/commands/groups/get.js.map +1 -1
- package/lib/commands/groups/index.d.ts +2 -1
- package/lib/commands/groups/index.d.ts.map +1 -1
- package/lib/commands/groups/index.js +2 -1
- package/lib/commands/groups/index.js.map +1 -1
- package/lib/commands/groups/list.d.ts +12 -0
- package/lib/commands/groups/list.d.ts.map +1 -1
- package/lib/commands/groups/list.js +25 -0
- package/lib/commands/groups/list.js.map +1 -1
- package/lib/commands/groups/register.d.ts +3 -0
- package/lib/commands/groups/register.d.ts.map +1 -0
- package/lib/commands/groups/register.js +90 -0
- package/lib/commands/groups/register.js.map +1 -0
- package/lib/commands/groups/update.d.ts +9 -0
- package/lib/commands/groups/update.d.ts.map +1 -1
- package/lib/commands/groups/update.js +21 -5
- package/lib/commands/groups/update.js.map +1 -1
- package/lib/commands/transactions/batch-create.d.ts +10 -0
- package/lib/commands/transactions/batch-create.d.ts.map +1 -0
- package/lib/commands/transactions/batch-create.js +98 -0
- package/lib/commands/transactions/batch-create.js.map +1 -0
- package/lib/commands/transactions/check.d.ts +7 -0
- package/lib/commands/transactions/check.d.ts.map +1 -1
- package/lib/commands/transactions/check.js +7 -0
- package/lib/commands/transactions/check.js.map +1 -1
- package/lib/commands/transactions/create.d.ts +10 -0
- package/lib/commands/transactions/create.d.ts.map +1 -1
- package/lib/commands/transactions/create.js +31 -9
- package/lib/commands/transactions/create.js.map +1 -1
- package/lib/commands/transactions/index.d.ts +2 -1
- package/lib/commands/transactions/index.d.ts.map +1 -1
- package/lib/commands/transactions/index.js +2 -1
- package/lib/commands/transactions/index.js.map +1 -1
- package/lib/commands/transactions/list.d.ts +20 -0
- package/lib/commands/transactions/list.d.ts.map +1 -1
- package/lib/commands/transactions/list.js +38 -0
- package/lib/commands/transactions/list.js.map +1 -1
- package/lib/commands/transactions/merge.d.ts +12 -0
- package/lib/commands/transactions/merge.d.ts.map +1 -1
- package/lib/commands/transactions/merge.js +15 -2
- package/lib/commands/transactions/merge.js.map +1 -1
- package/lib/commands/transactions/post.d.ts +7 -0
- package/lib/commands/transactions/post.d.ts.map +1 -1
- package/lib/commands/transactions/post.js +7 -0
- package/lib/commands/transactions/post.js.map +1 -1
- package/lib/commands/transactions/register.d.ts +3 -0
- package/lib/commands/transactions/register.d.ts.map +1 -0
- package/lib/commands/transactions/register.js +146 -0
- package/lib/commands/transactions/register.js.map +1 -0
- package/lib/commands/transactions/trash.d.ts +7 -0
- package/lib/commands/transactions/trash.d.ts.map +1 -1
- package/lib/commands/transactions/trash.js +7 -0
- package/lib/commands/transactions/trash.js.map +1 -1
- package/lib/commands/transactions/update.d.ts +11 -0
- package/lib/commands/transactions/update.d.ts.map +1 -1
- package/lib/commands/transactions/update.js +31 -7
- package/lib/commands/transactions/update.js.map +1 -1
- package/lib/input/csv-parser.d.ts +9 -0
- package/lib/input/csv-parser.d.ts.map +1 -0
- package/lib/input/csv-parser.js +110 -0
- package/lib/input/csv-parser.js.map +1 -0
- package/lib/input/format-detector.d.ts +12 -0
- package/lib/input/format-detector.d.ts.map +1 -0
- package/lib/input/format-detector.js +14 -0
- package/lib/input/format-detector.js.map +1 -0
- package/lib/input/index.d.ts +9 -0
- package/lib/input/index.d.ts.map +1 -0
- package/lib/input/index.js +40 -0
- package/lib/input/index.js.map +1 -0
- package/lib/input/stdin-reader.d.ts +8 -0
- package/lib/input/stdin-reader.d.ts.map +1 -0
- package/lib/input/stdin-reader.js +37 -0
- package/lib/input/stdin-reader.js.map +1 -0
- package/lib/render/csv-formatter.d.ts +15 -0
- package/lib/render/csv-formatter.d.ts.map +1 -0
- package/lib/render/csv-formatter.js +37 -0
- package/lib/render/csv-formatter.js.map +1 -0
- package/lib/render/index.d.ts +3 -1
- package/lib/render/index.d.ts.map +1 -1
- package/lib/render/index.js +2 -1
- package/lib/render/index.js.map +1 -1
- package/lib/render/output.d.ts +27 -6
- package/lib/render/output.d.ts.map +1 -1
- package/lib/render/output.js +35 -12
- package/lib/render/output.js.map +1 -1
- package/lib/render/table-formatter.d.ts.map +1 -1
- package/lib/render/table-formatter.js +22 -4
- package/lib/render/table-formatter.js.map +1 -1
- package/lib/utils/validation.d.ts +38 -0
- package/lib/utils/validation.d.ts.map +1 -0
- package/lib/utils/validation.js +46 -0
- package/lib/utils/validation.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export { readStdin } from './stdin-reader.js';
|
|
11
|
+
import { readStdin } from './stdin-reader.js';
|
|
12
|
+
import { detectInputFormat } from './format-detector.js';
|
|
13
|
+
import { parseCsv } from './csv-parser.js';
|
|
14
|
+
export function parseStdinItems() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const content = yield readStdin();
|
|
17
|
+
if (content === null) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const format = detectInputFormat(content);
|
|
21
|
+
let items;
|
|
22
|
+
if (format === 'json') {
|
|
23
|
+
const parsed = JSON.parse(content);
|
|
24
|
+
if (Array.isArray(parsed)) {
|
|
25
|
+
items = parsed;
|
|
26
|
+
}
|
|
27
|
+
else if (typeof parsed === 'object' && parsed !== null) {
|
|
28
|
+
items = [parsed];
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw new Error('JSON input must be an object or an array of objects');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
items = parseCsv(content);
|
|
36
|
+
}
|
|
37
|
+
return { items, format };
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/input/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAe,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAO3C,MAAM,UAAgB,eAAe;;QACjC,MAAM,OAAO,GAAG,MAAM,SAAS,EAAE,CAAC;QAClC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,KAA+B,CAAC;QAEpC,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YACpB,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBACxB,KAAK,GAAG,MAAkC,CAAC;YAC/C,CAAC;iBAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;gBACvD,KAAK,GAAG,CAAC,MAAgC,CAAC,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACJ,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;YAC3E,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAC7B,CAAC;CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads all content from stdin if piped input is available.
|
|
3
|
+
* Returns null if stdin is a TTY (no piped input) or if the input is empty.
|
|
4
|
+
*
|
|
5
|
+
* @returns The trimmed stdin content, or null if no input is available
|
|
6
|
+
*/
|
|
7
|
+
export declare function readStdin(): Promise<string | null>;
|
|
8
|
+
//# sourceMappingURL=stdin-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdin-reader.d.ts","sourceRoot":"","sources":["../../src/input/stdin-reader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAsB,SAAS,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAsBxD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Reads all content from stdin if piped input is available.
|
|
12
|
+
* Returns null if stdin is a TTY (no piped input) or if the input is empty.
|
|
13
|
+
*
|
|
14
|
+
* @returns The trimmed stdin content, or null if no input is available
|
|
15
|
+
*/
|
|
16
|
+
export function readStdin() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
if (process.stdin.isTTY) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const chunks = [];
|
|
23
|
+
process.stdin.setEncoding('utf8');
|
|
24
|
+
process.stdin.on('data', (chunk) => {
|
|
25
|
+
chunks.push(chunk);
|
|
26
|
+
});
|
|
27
|
+
process.stdin.on('end', () => {
|
|
28
|
+
const content = chunks.join('').trim();
|
|
29
|
+
resolve(content.length > 0 ? content : null);
|
|
30
|
+
});
|
|
31
|
+
process.stdin.on('error', (err) => {
|
|
32
|
+
reject(err);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=stdin-reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdin-reader.js","sourceRoot":"","sources":["../../src/input/stdin-reader.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;GAKG;AACH,MAAM,UAAgB,SAAS;;QAC3B,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,MAAM,MAAM,GAAa,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YAElC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;gBACvC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC,CAAC,CAAC;YAEH,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBACzB,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;gBACvC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;YAEH,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;gBACrC,MAAM,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a 2D matrix into an RFC 4180 compliant CSV string.
|
|
3
|
+
*
|
|
4
|
+
* - Row 0 is treated as headers, rows 1+ as data (all rendered identically)
|
|
5
|
+
* - Uses CRLF line endings per RFC 4180
|
|
6
|
+
* - Fields containing commas, double quotes, or newlines are quoted
|
|
7
|
+
* - Double quotes are escaped by doubling them ("")
|
|
8
|
+
* - null/undefined cells are rendered as empty strings
|
|
9
|
+
* - No truncation is applied to any field
|
|
10
|
+
*
|
|
11
|
+
* @param matrix - 2D array where row 0 is headers and rows 1+ are data
|
|
12
|
+
* @returns RFC 4180 CSV string
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatCsv(matrix: unknown[][]): string;
|
|
15
|
+
//# sourceMappingURL=csv-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv-formatter.d.ts","sourceRoot":"","sources":["../../src/render/csv-formatter.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,GAAG,MAAM,CAMrD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a field value according to RFC 4180 rules.
|
|
3
|
+
*
|
|
4
|
+
* - null/undefined become empty string
|
|
5
|
+
* - Fields containing commas, double quotes, or newlines are wrapped in double quotes
|
|
6
|
+
* - Double quotes within a field are escaped by doubling them ("")
|
|
7
|
+
*/
|
|
8
|
+
function formatField(value) {
|
|
9
|
+
if (value == null) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
const str = String(value);
|
|
13
|
+
if (str.includes('"') || str.includes(',') || str.includes('\n') || str.includes('\r')) {
|
|
14
|
+
return '"' + str.replace(/"/g, '""') + '"';
|
|
15
|
+
}
|
|
16
|
+
return str;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Formats a 2D matrix into an RFC 4180 compliant CSV string.
|
|
20
|
+
*
|
|
21
|
+
* - Row 0 is treated as headers, rows 1+ as data (all rendered identically)
|
|
22
|
+
* - Uses CRLF line endings per RFC 4180
|
|
23
|
+
* - Fields containing commas, double quotes, or newlines are quoted
|
|
24
|
+
* - Double quotes are escaped by doubling them ("")
|
|
25
|
+
* - null/undefined cells are rendered as empty strings
|
|
26
|
+
* - No truncation is applied to any field
|
|
27
|
+
*
|
|
28
|
+
* @param matrix - 2D array where row 0 is headers and rows 1+ are data
|
|
29
|
+
* @returns RFC 4180 CSV string
|
|
30
|
+
*/
|
|
31
|
+
export function formatCsv(matrix) {
|
|
32
|
+
if (!matrix || matrix.length === 0) {
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
return matrix.map(row => row.map(formatField).join(',')).join('\r\n');
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=csv-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv-formatter.js","sourceRoot":"","sources":["../../src/render/csv-formatter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,KAAc;IAC/B,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO,EAAE,CAAC;IACd,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAE1B,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACrF,OAAO,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,GAAG,CAAC;IAC/C,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS,CAAC,MAAmB;IACzC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,EAAE,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC1E,CAAC"}
|
package/lib/render/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { formatTable, formatItem } from './table-formatter.js';
|
|
2
|
-
export {
|
|
2
|
+
export { formatCsv } from './csv-formatter.js';
|
|
3
|
+
export { renderTable, renderItem, renderListResult } from './output.js';
|
|
4
|
+
export type { OutputFormat, ListResult } from './output.js';
|
|
3
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACxE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
package/lib/render/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { formatTable, formatItem } from './table-formatter.js';
|
|
2
|
-
export {
|
|
2
|
+
export { formatCsv } from './csv-formatter.js';
|
|
3
|
+
export { renderTable, renderItem, renderListResult } from './output.js';
|
|
3
4
|
//# sourceMappingURL=index.js.map
|
package/lib/render/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
package/lib/render/output.d.ts
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Output format type for CLI rendering.
|
|
3
|
+
*/
|
|
4
|
+
export type OutputFormat = 'table' | 'json' | 'csv';
|
|
5
|
+
/**
|
|
6
|
+
* Structured result from list commands, allowing cli.ts to render
|
|
7
|
+
* without knowing how the data was built.
|
|
8
|
+
*/
|
|
9
|
+
export type ListResult = {
|
|
10
|
+
kind: 'json';
|
|
11
|
+
data: unknown;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'matrix';
|
|
14
|
+
matrix: unknown[][];
|
|
15
|
+
footer?: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Renders a ListResult to stdout based on the active output format.
|
|
19
|
+
*/
|
|
20
|
+
export declare function renderListResult(result: ListResult, format: OutputFormat): void;
|
|
21
|
+
/**
|
|
22
|
+
* Renders a 2D matrix as a formatted table, JSON, or CSV.
|
|
3
23
|
*
|
|
4
24
|
* @param matrix - 2D array where row 0 is headers and rows 1+ are data
|
|
5
|
-
* @param
|
|
25
|
+
* @param format - Output format: 'table' (default), 'json', or 'csv'
|
|
6
26
|
*/
|
|
7
|
-
export declare function renderTable(matrix: unknown[][],
|
|
27
|
+
export declare function renderTable(matrix: unknown[][], format: OutputFormat): void;
|
|
8
28
|
/**
|
|
9
|
-
* Renders a single item as key-value pairs or JSON
|
|
29
|
+
* Renders a single item as key-value pairs, JSON, or JSON (for CSV, since
|
|
30
|
+
* single items are not tabular, CSV falls back to JSON).
|
|
10
31
|
*
|
|
11
32
|
* @param item - Record to render
|
|
12
|
-
* @param
|
|
33
|
+
* @param format - Output format: 'table' (default), 'json', or 'csv'
|
|
13
34
|
*/
|
|
14
|
-
export declare function renderItem(item: object,
|
|
35
|
+
export declare function renderItem(item: object, format: OutputFormat): void;
|
|
15
36
|
//# sourceMappingURL=output.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/render/output.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/render/output.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,UAAU,GAChB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/D;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAS/E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAe3E;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAQnE"}
|
package/lib/render/output.js
CHANGED
|
@@ -1,26 +1,49 @@
|
|
|
1
1
|
import { formatTable, formatItem } from './table-formatter.js';
|
|
2
|
+
import { formatCsv } from './csv-formatter.js';
|
|
2
3
|
/**
|
|
3
|
-
* Renders a
|
|
4
|
+
* Renders a ListResult to stdout based on the active output format.
|
|
5
|
+
*/
|
|
6
|
+
export function renderListResult(result, format) {
|
|
7
|
+
if (result.kind === 'json') {
|
|
8
|
+
console.log(JSON.stringify(result.data, null, 2));
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
renderTable(result.matrix, format);
|
|
12
|
+
if (result.footer && format === 'table') {
|
|
13
|
+
console.log(result.footer);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Renders a 2D matrix as a formatted table, JSON, or CSV.
|
|
4
18
|
*
|
|
5
19
|
* @param matrix - 2D array where row 0 is headers and rows 1+ are data
|
|
6
|
-
* @param
|
|
20
|
+
* @param format - Output format: 'table' (default), 'json', or 'csv'
|
|
7
21
|
*/
|
|
8
|
-
export function renderTable(matrix,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
22
|
+
export function renderTable(matrix, format) {
|
|
23
|
+
switch (format) {
|
|
24
|
+
case 'json':
|
|
25
|
+
console.log(JSON.stringify(matrix, null, 2));
|
|
26
|
+
return;
|
|
27
|
+
case 'csv': {
|
|
28
|
+
const csv = formatCsv(matrix);
|
|
29
|
+
console.log(csv || 'No results found.');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
default: {
|
|
33
|
+
const formatted = formatTable(matrix);
|
|
34
|
+
console.log(formatted || 'No results found.');
|
|
35
|
+
}
|
|
12
36
|
}
|
|
13
|
-
const formatted = formatTable(matrix);
|
|
14
|
-
console.log(formatted || 'No results found.');
|
|
15
37
|
}
|
|
16
38
|
/**
|
|
17
|
-
* Renders a single item as key-value pairs or JSON
|
|
39
|
+
* Renders a single item as key-value pairs, JSON, or JSON (for CSV, since
|
|
40
|
+
* single items are not tabular, CSV falls back to JSON).
|
|
18
41
|
*
|
|
19
42
|
* @param item - Record to render
|
|
20
|
-
* @param
|
|
43
|
+
* @param format - Output format: 'table' (default), 'json', or 'csv'
|
|
21
44
|
*/
|
|
22
|
-
export function renderItem(item,
|
|
23
|
-
if (json) {
|
|
45
|
+
export function renderItem(item, format) {
|
|
46
|
+
if (format === 'json' || format === 'csv') {
|
|
24
47
|
console.log(JSON.stringify(item, null, 2));
|
|
25
48
|
return;
|
|
26
49
|
}
|
package/lib/render/output.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/render/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/render/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAe/C;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAkB,EAAE,MAAoB;IACrE,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAClD,OAAO;IACX,CAAC;IACD,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,MAAmB,EAAE,MAAoB;IACjE,QAAQ,MAAM,EAAE,CAAC;QACb,KAAK,MAAM;YACP,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC7C,OAAO;QACX,KAAK,KAAK,CAAC,CAAC,CAAC;YACT,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;YAC9B,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAC;YACxC,OAAO;QACX,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACN,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;YACtC,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,mBAAmB,CAAC,CAAC;QAClD,CAAC;IACL,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,MAAoB;IACzD,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3C,OAAO;IACX,CAAC;IAED,MAAM,SAAS,GAAG,UAAU,CAAC,IAA+B,CAAC,CAAC;IAC9D,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,mBAAmB,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-formatter.d.ts","sourceRoot":"","sources":["../../src/render/table-formatter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"table-formatter.d.ts","sourceRoot":"","sources":["../../src/render/table-formatter.ts"],"names":[],"mappings":"AAyBA;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,GAAG,MAAM,CAkEvD;AAoID;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAUhE"}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Maximum width for any single cell value.
|
|
3
3
|
* Values exceeding this width are truncated with an ellipsis (…).
|
|
4
|
-
* Header cells are never truncated.
|
|
4
|
+
* Header cells and ID columns are never truncated.
|
|
5
5
|
*/
|
|
6
6
|
const MAX_CELL_WIDTH = 40;
|
|
7
|
+
/**
|
|
8
|
+
* Checks whether a column header indicates an ID column.
|
|
9
|
+
* ID columns should never be truncated so users can copy-paste values into subsequent commands.
|
|
10
|
+
*/
|
|
11
|
+
function isIdColumn(header) {
|
|
12
|
+
return header === 'ID' || header.endsWith(' Id') || header.endsWith('Id');
|
|
13
|
+
}
|
|
7
14
|
/**
|
|
8
15
|
* Truncates a string to maxWidth, appending '…' if it exceeds the limit.
|
|
9
16
|
*/
|
|
@@ -30,11 +37,22 @@ export function formatTable(matrix) {
|
|
|
30
37
|
return '';
|
|
31
38
|
}
|
|
32
39
|
const COL_GAP = ' ';
|
|
40
|
+
// Determine which columns are ID columns (never truncated)
|
|
41
|
+
const headerRow = matrix[0];
|
|
42
|
+
const noTruncateCols = new Set();
|
|
43
|
+
for (let i = 0; i < headerRow.length; i++) {
|
|
44
|
+
const header = headerRow[i] == null ? '' : String(headerRow[i]);
|
|
45
|
+
if (isIdColumn(header)) {
|
|
46
|
+
noTruncateCols.add(i);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
33
49
|
// Convert all cells to strings
|
|
34
|
-
const rows = matrix.map((row, rowIndex) => row.map(cell => {
|
|
50
|
+
const rows = matrix.map((row, rowIndex) => row.map((cell, colIndex) => {
|
|
35
51
|
const str = cell == null ? '' : String(cell);
|
|
36
|
-
// Don't truncate header row
|
|
37
|
-
return rowIndex === 0
|
|
52
|
+
// Don't truncate header row or ID columns
|
|
53
|
+
return rowIndex === 0 || noTruncateCols.has(colIndex)
|
|
54
|
+
? str
|
|
55
|
+
: truncateCell(str, MAX_CELL_WIDTH);
|
|
38
56
|
}));
|
|
39
57
|
const headers = rows[0];
|
|
40
58
|
const dataRows = rows.slice(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-formatter.js","sourceRoot":"","sources":["../../src/render/table-formatter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B;;GAEG;AACH,SAAS,YAAY,CAAC,KAAa,EAAE,QAAgB;IACjD,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;AAC9C,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,MAAmB;IAC3C,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,EAAE,CAAC;IACd,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC;IAErB,+BAA+B;IAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CACtC,GAAG,CAAC,GAAG,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"table-formatter.js","sourceRoot":"","sources":["../../src/render/table-formatter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B;;;GAGG;AACH,SAAS,UAAU,CAAC,MAAc;IAC9B,OAAO,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC9E,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,KAAa,EAAE,QAAgB;IACjD,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACj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gC,CAAC,CAAC,MAAM,CACtE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CACzB,CAAC;IACF,OAAO,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,UAAU,CAAC,IAA6B;IACpD,6CAA6C;IAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAE5E,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,CAAC;IACd,CAAC;IAED,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACzC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utilities for collecting and reporting all errors at once.
|
|
3
|
+
*
|
|
4
|
+
* Instead of throwing on the first validation failure, commands should
|
|
5
|
+
* collect all errors and throw a single {@link ValidationError} so
|
|
6
|
+
* that users (and agents) can fix everything in one pass.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* An error that carries multiple validation messages.
|
|
10
|
+
*
|
|
11
|
+
* The {@link message} property joins all individual errors with newlines
|
|
12
|
+
* so it renders cleanly when printed by the CLI catch block.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ValidationError extends Error {
|
|
15
|
+
readonly errors: string[];
|
|
16
|
+
constructor(errors: string[]);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Specification for a required option.
|
|
20
|
+
*
|
|
21
|
+
* @param name - The option key as it appears in Commander's parsed `options`
|
|
22
|
+
* object (camelCase, e.g. "book" for `--book`).
|
|
23
|
+
* @param flag - The flag as the user types it (e.g. "--book", "--date").
|
|
24
|
+
*/
|
|
25
|
+
export interface RequiredOptionSpec {
|
|
26
|
+
name: string;
|
|
27
|
+
flag: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Checks all required options and returns an array of error strings
|
|
31
|
+
* for every option that is missing (`undefined` or `null`).
|
|
32
|
+
*/
|
|
33
|
+
export declare function validateRequiredOptions(options: Record<string, unknown>, specs: RequiredOptionSpec[]): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Throws a {@link ValidationError} if the errors array is non-empty.
|
|
36
|
+
*/
|
|
37
|
+
export declare function throwIfErrors(errors: string[]): void;
|
|
38
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;gBAEd,MAAM,EAAE,MAAM,EAAE;CAS/B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,KAAK,EAAE,kBAAkB,EAAE,GAC5B,MAAM,EAAE,CASV;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAIpD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utilities for collecting and reporting all errors at once.
|
|
3
|
+
*
|
|
4
|
+
* Instead of throwing on the first validation failure, commands should
|
|
5
|
+
* collect all errors and throw a single {@link ValidationError} so
|
|
6
|
+
* that users (and agents) can fix everything in one pass.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* An error that carries multiple validation messages.
|
|
10
|
+
*
|
|
11
|
+
* The {@link message} property joins all individual errors with newlines
|
|
12
|
+
* so it renders cleanly when printed by the CLI catch block.
|
|
13
|
+
*/
|
|
14
|
+
export class ValidationError extends Error {
|
|
15
|
+
constructor(errors) {
|
|
16
|
+
const message = errors.length === 1
|
|
17
|
+
? errors[0]
|
|
18
|
+
: 'Validation failed:\n' + errors.map(e => ` - ${e}`).join('\n');
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = 'ValidationError';
|
|
21
|
+
this.errors = errors;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Checks all required options and returns an array of error strings
|
|
26
|
+
* for every option that is missing (`undefined` or `null`).
|
|
27
|
+
*/
|
|
28
|
+
export function validateRequiredOptions(options, specs) {
|
|
29
|
+
const errors = [];
|
|
30
|
+
for (const spec of specs) {
|
|
31
|
+
const value = options[spec.name];
|
|
32
|
+
if (value === undefined || value === null) {
|
|
33
|
+
errors.push(`Missing required option: ${spec.flag}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return errors;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Throws a {@link ValidationError} if the errors array is non-empty.
|
|
40
|
+
*/
|
|
41
|
+
export function throwIfErrors(errors) {
|
|
42
|
+
if (errors.length > 0) {
|
|
43
|
+
throw new ValidationError(errors);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAGtC,YAAY,MAAgB;QACxB,MAAM,OAAO,GACT,MAAM,CAAC,MAAM,KAAK,CAAC;YACf,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YACX,CAAC,CAAC,sBAAsB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAcD;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACnC,OAAgC,EAChC,KAA2B;IAE3B,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,4BAA4B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACzD,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAgB;IAC1C,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;AACL,CAAC"}
|