@openbkn/bkn-sdk 0.1.1-alpha.0 → 0.1.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js
CHANGED
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
usersOf,
|
|
29
29
|
whoami,
|
|
30
30
|
writePlatformConfig
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-ADZ23DPF.js";
|
|
32
32
|
|
|
33
33
|
// src/cli.ts
|
|
34
34
|
import { Command as Command16 } from "commander";
|
|
@@ -36,7 +36,7 @@ import { Command as Command16 } from "commander";
|
|
|
36
36
|
// package.json
|
|
37
37
|
var package_default = {
|
|
38
38
|
name: "@openbkn/bkn-sdk",
|
|
39
|
-
version: "0.1.1-alpha.
|
|
39
|
+
version: "0.1.1-alpha.1",
|
|
40
40
|
description: "Unified TypeScript SDK + CLI for the BKN (Business Knowledge Network) platform.",
|
|
41
41
|
type: "module",
|
|
42
42
|
license: "Apache-2.0",
|
|
@@ -77,7 +77,6 @@ var package_default = {
|
|
|
77
77
|
dependencies: {
|
|
78
78
|
"@clack/prompts": "^0.9.1",
|
|
79
79
|
chalk: "^5.4.1",
|
|
80
|
-
"cli-table3": "^0.6.5",
|
|
81
80
|
commander: "^13.1.0",
|
|
82
81
|
"csv-parse": "^6.2.1",
|
|
83
82
|
"js-yaml": "^4.2.0",
|
|
@@ -150,7 +149,6 @@ function installGroupedHelp(root) {
|
|
|
150
149
|
}
|
|
151
150
|
|
|
152
151
|
// src/utils/output.ts
|
|
153
|
-
import Table from "cli-table3";
|
|
154
152
|
function printJson(value, opts = {}) {
|
|
155
153
|
if (opts.json || opts.compact) {
|
|
156
154
|
process.stdout.write(`${JSON.stringify(value, null, opts.compact ? 0 : 2)}
|
|
@@ -159,9 +157,14 @@ function printJson(value, opts = {}) {
|
|
|
159
157
|
}
|
|
160
158
|
const rows = toRows(value);
|
|
161
159
|
if (rows) {
|
|
162
|
-
const columns = columnsOf(rows);
|
|
160
|
+
const columns = opts.full ? columnsOf(rows).filter((c) => rows.some((r) => stringifyCell(r[c]) !== "")) : selectColumns(rows);
|
|
163
161
|
if (columns.length > 0) {
|
|
164
162
|
printTable(rows, columns);
|
|
163
|
+
const hidden = columnsOf(rows).length - columns.length;
|
|
164
|
+
if (hidden > 0 && !opts.full) {
|
|
165
|
+
process.stdout.write(`\u2026 ${hidden} more column(s); use --full or --json for everything
|
|
166
|
+
`);
|
|
167
|
+
}
|
|
165
168
|
return;
|
|
166
169
|
}
|
|
167
170
|
}
|
|
@@ -187,22 +190,68 @@ function columnsOf(rows) {
|
|
|
187
190
|
}
|
|
188
191
|
return seen;
|
|
189
192
|
}
|
|
193
|
+
var MAX_COLS = 8;
|
|
194
|
+
var NOISE_COLS = /* @__PURE__ */ new Set([
|
|
195
|
+
"creator",
|
|
196
|
+
"updater",
|
|
197
|
+
"create_by",
|
|
198
|
+
"update_by",
|
|
199
|
+
"create_user",
|
|
200
|
+
"update_user",
|
|
201
|
+
"operations",
|
|
202
|
+
"status_message",
|
|
203
|
+
"last_check_time",
|
|
204
|
+
"last_discover_status",
|
|
205
|
+
"health_check_result",
|
|
206
|
+
"health_check_enabled"
|
|
207
|
+
]);
|
|
208
|
+
var isNoiseCol = (c) => NOISE_COLS.has(c) || /_time$/.test(c);
|
|
209
|
+
var isKeyCol = (c) => /^(id|name|key|title|label)$/i.test(c) || /_(id|name|key)$/i.test(c) || /^(status|state|type|category|mode|enabled|version|branch)$/i.test(c);
|
|
210
|
+
function selectColumns(rows) {
|
|
211
|
+
const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
212
|
+
const kept = columnsOf(rows).filter((c) => {
|
|
213
|
+
if (isNoiseCol(c)) return false;
|
|
214
|
+
const vals = rows.map((r) => r[c]);
|
|
215
|
+
if (!vals.some((v) => stringifyCell(v) !== "")) return false;
|
|
216
|
+
if (vals.every((v) => v === null || v === void 0 || isObj(v))) return false;
|
|
217
|
+
return true;
|
|
218
|
+
});
|
|
219
|
+
const isLongText = (c) => rows.every((r) => {
|
|
220
|
+
const s = stringifyCell(r[c]);
|
|
221
|
+
return s === "" || s.length >= CELL_MAX - 1;
|
|
222
|
+
});
|
|
223
|
+
const rank = (c) => isKeyCol(c) ? 0 : isLongText(c) ? 2 : 1;
|
|
224
|
+
const ordered = kept.map((c, i) => ({ c, i, r: rank(c) })).sort((a, b) => a.r - b.r || a.i - b.i).map((x) => x.c);
|
|
225
|
+
return ordered.slice(0, MAX_COLS);
|
|
226
|
+
}
|
|
190
227
|
function printTable(rows, columns, opts = {}) {
|
|
191
228
|
if (opts.json || opts.compact) {
|
|
192
229
|
printJson(rows, opts);
|
|
193
230
|
return;
|
|
194
231
|
}
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
232
|
+
const cells = rows.map((row) => columns.map((c) => stringifyCell(row[c])));
|
|
233
|
+
const widths = columns.map(
|
|
234
|
+
(col, i) => Math.max(displayWidth(col), ...cells.map((r) => displayWidth(r[i] ?? "")))
|
|
235
|
+
);
|
|
236
|
+
const fmt = (parts) => parts.map((p, i) => i === parts.length - 1 ? p : pad(p, widths[i] ?? 0)).join(" ").trimEnd();
|
|
237
|
+
const lines = [fmt(columns), ...cells.map(fmt)];
|
|
238
|
+
process.stdout.write(`${lines.join("\n")}
|
|
200
239
|
`);
|
|
201
240
|
}
|
|
202
241
|
var CELL_MAX = 48;
|
|
242
|
+
function displayWidth(s) {
|
|
243
|
+
let w = 0;
|
|
244
|
+
for (const ch of s) w += /[ᄀ-ᅟ⺀-가-힣豈-︰-﹏-⦆¢-₩]/.test(ch) ? 2 : 1;
|
|
245
|
+
return w;
|
|
246
|
+
}
|
|
247
|
+
function pad(s, width) {
|
|
248
|
+
const gap = width - displayWidth(s);
|
|
249
|
+
return gap > 0 ? s + " ".repeat(gap) : s;
|
|
250
|
+
}
|
|
203
251
|
function stringifyCell(v) {
|
|
204
252
|
if (v === null || v === void 0) return "";
|
|
205
|
-
const
|
|
253
|
+
const raw = Array.isArray(v) && v.every((x) => x === null || typeof x !== "object") ? v.join(",") : typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
254
|
+
const s = raw.replace(/\s+/g, " ").trim();
|
|
206
255
|
return s.length > CELL_MAX ? `${s.slice(0, CELL_MAX - 1)}\u2026` : s;
|
|
207
256
|
}
|
|
208
257
|
|
|
@@ -220,7 +269,7 @@ function clientFrom(cmd) {
|
|
|
220
269
|
}
|
|
221
270
|
function outputOptions(cmd) {
|
|
222
271
|
const o = cmd.optsWithGlobals();
|
|
223
|
-
return { json: Boolean(o.json), compact: Boolean(o.compact) };
|
|
272
|
+
return { json: Boolean(o.json), compact: Boolean(o.compact), full: Boolean(o.full) };
|
|
224
273
|
}
|
|
225
274
|
function csv(value) {
|
|
226
275
|
if (!value) return void 0;
|
|
@@ -1872,18 +1921,18 @@ import { Command as Command11 } from "commander";
|
|
|
1872
1921
|
var int8 = (v) => Number.parseInt(v, 10);
|
|
1873
1922
|
function resourceCommand() {
|
|
1874
1923
|
const cmd = new Command11("resource").alias("res").description("Resources \u2014 list, find, get, query, delete");
|
|
1875
|
-
cmd.command("list").description("List resources under a
|
|
1924
|
+
cmd.command("list").description("List resources under a catalog").option("--catalog-id <id>", "filter by catalog id").option("--datasource-id <id>", "alias of --catalog-id").option("--category <c>", "resource category (table | logicview | dataset)").option("--type <c>", "alias of --category").option("--limit <n>", "page size", int8, DEFAULT_LIST_LIMIT).action(async (opts, cmd2) => {
|
|
1876
1925
|
const data = await clientFrom(cmd2).resource.list({
|
|
1877
|
-
datasourceId: opts.datasourceId,
|
|
1878
|
-
category: opts.type,
|
|
1926
|
+
datasourceId: opts.catalogId ?? opts.datasourceId,
|
|
1927
|
+
category: opts.category ?? opts.type,
|
|
1879
1928
|
limit: opts.limit
|
|
1880
1929
|
});
|
|
1881
1930
|
printJson(data, outputOptions(cmd2));
|
|
1882
1931
|
});
|
|
1883
|
-
cmd.command("find").description("Search resources by name (fuzzy; --exact for strict)").requiredOption("--name <name>", "resource name to search").option("--exact", "exact name match").option("--
|
|
1932
|
+
cmd.command("find").description("Search resources by name (fuzzy; --exact for strict)").requiredOption("--name <name>", "resource name to search").option("--exact", "exact name match").option("--catalog-id <id>", "limit to a catalog").option("--datasource-id <id>", "alias of --catalog-id").action(async (opts, cmd2) => {
|
|
1884
1933
|
const data = await clientFrom(cmd2).resource.find(opts.name, {
|
|
1885
1934
|
exact: opts.exact,
|
|
1886
|
-
datasourceId: opts.datasourceId
|
|
1935
|
+
datasourceId: opts.catalogId ?? opts.datasourceId
|
|
1887
1936
|
});
|
|
1888
1937
|
printJson(data, outputOptions(cmd2));
|
|
1889
1938
|
});
|
|
@@ -2338,7 +2387,7 @@ function vegaCommand() {
|
|
|
2338
2387
|
|
|
2339
2388
|
// src/cli.ts
|
|
2340
2389
|
var program = new Command16();
|
|
2341
|
-
program.name("openbkn").description("Operate the BKN platform from the CLI").version(package_default.version, "-V, --version", "output the version number").option("--base-url <url>", "platform base URL (env: BKN_BASE_URL)").option("--token <value>", "access token (env: BKN_TOKEN)").option("--user <id|name>", "use specific user credentials (env: BKN_USER)").option("--json", "machine-readable JSON output").option("--compact", "single-line JSON output").option("--biz-domain <s>", "business domain (alias: -bd)").option("-k, --insecure", "skip TLS verification (dev / self-signed only)").showHelpAfterError();
|
|
2390
|
+
program.name("openbkn").description("Operate the BKN platform from the CLI").version(package_default.version, "-V, --version", "output the version number").option("--base-url <url>", "platform base URL (env: BKN_BASE_URL)").option("--token <value>", "access token (env: BKN_TOKEN)").option("--user <id|name>", "use specific user credentials (env: BKN_USER)").option("--json", "machine-readable JSON output").option("--compact", "single-line JSON output").option("--full", "human view: show all columns (default trims to the key ones)").option("--biz-domain <s>", "business domain (alias: -bd)").option("-k, --insecure", "skip TLS verification (dev / self-signed only)").showHelpAfterError();
|
|
2342
2391
|
program.addCommand(authCommand());
|
|
2343
2392
|
program.addCommand(callCommand());
|
|
2344
2393
|
program.addCommand(configCommand());
|