@graphit/cli 0.2.82 → 0.2.94
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/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/bin/graphit +1 -1
- package/bin/graphit.ps1 +1 -1
- package/dist/commands/ds/refresh-history.d.ts +27 -0
- package/dist/commands/ds/refresh-history.js +51 -0
- package/dist/commands/ds/refresh-history.js.map +1 -0
- package/dist/commands/ds.d.ts +15 -1
- package/dist/commands/ds.js +76 -8
- package/dist/commands/ds.js.map +1 -1
- package/dist/commands/kb-create.d.ts +2 -0
- package/dist/commands/kb-create.js +290 -0
- package/dist/commands/kb-create.js.map +1 -0
- package/dist/commands/kb-delete.d.ts +2 -0
- package/dist/commands/kb-delete.js +25 -0
- package/dist/commands/kb-delete.js.map +1 -0
- package/dist/commands/kb-read.d.ts +2 -0
- package/dist/commands/kb-read.js +201 -0
- package/dist/commands/kb-read.js.map +1 -0
- package/dist/commands/kb-shared.d.ts +25 -0
- package/dist/commands/kb-shared.js +41 -0
- package/dist/commands/kb-shared.js.map +1 -0
- package/dist/commands/kb-update.d.ts +2 -0
- package/dist/commands/kb-update.js +231 -0
- package/dist/commands/kb-update.js.map +1 -0
- package/dist/commands/kb.js +14 -751
- package/dist/commands/kb.js.map +1 -1
- package/package.json +1 -1
- package/scripts/generate-commands-doc.mjs +3 -0
- package/skills/graphit/SKILL.md +8 -7
- package/skills/graphit/VERSION.json +1 -1
- package/skills/graphit/references/data-sources.md +20 -17
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { apiClient } from "../api/client.js";
|
|
3
|
+
import { output, errorOutput, getOutputFormat } from "../output/format.js";
|
|
4
|
+
import { styledIntro, styledOutro, styledSuccess, formatBold, } from "../output/styled.js";
|
|
5
|
+
import { parseConstraintFlags, parseApplyOnFlags } from "./kb-constraints.js";
|
|
6
|
+
import { renderValidation, } from "./kb-shared.js";
|
|
7
|
+
// Project #254 Phase 1: kb create verbs (metric/dimension/rule/domain/synonym/
|
|
8
|
+
// relationship/topic/template). Tables are created from data sources.
|
|
9
|
+
export function addKBCreateCommands(kb) {
|
|
10
|
+
const create = kb
|
|
11
|
+
.command("create")
|
|
12
|
+
.description("Create KB entities. Tables are created from data sources - use 'graphit ds create'.");
|
|
13
|
+
create
|
|
14
|
+
.command("metric")
|
|
15
|
+
.description("Create a new metric")
|
|
16
|
+
.requiredOption("--name <name>", "Metric name (UPPER_SNAKE_CASE)")
|
|
17
|
+
.requiredOption("--sql <expr>", "SQL calculation expression")
|
|
18
|
+
.requiredOption("--table <table>", "Primary table")
|
|
19
|
+
.option("--description <desc>", "Description", "")
|
|
20
|
+
.option("--topics <topics>", "Comma-separated topic names")
|
|
21
|
+
.option("--default-dimensions <dims>", "Comma-separated dimension names this metric naturally groups by")
|
|
22
|
+
.option("--parameters <json>", "JSON array of parameter definitions")
|
|
23
|
+
.option("--parameters-file <path>", "Read parameters JSON from file")
|
|
24
|
+
.option("--skip-validate", "Skip pre-creation data validation")
|
|
25
|
+
.option("--unverified", "Create as a draft instead of verified (default: verified)")
|
|
26
|
+
.action(async function () {
|
|
27
|
+
try {
|
|
28
|
+
const opts = this.opts();
|
|
29
|
+
const fmt = getOutputFormat(this);
|
|
30
|
+
const topics = opts.topics ? opts.topics.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
31
|
+
const defaultDimensions = opts.defaultDimensions ? opts.defaultDimensions.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
32
|
+
let parameters = [];
|
|
33
|
+
if (opts.parametersFile) {
|
|
34
|
+
parameters = JSON.parse(await readFile(opts.parametersFile, "utf-8"));
|
|
35
|
+
}
|
|
36
|
+
else if (opts.parameters) {
|
|
37
|
+
parameters = JSON.parse(opts.parameters);
|
|
38
|
+
}
|
|
39
|
+
const skipValidate = opts.skipValidate ? "true" : "false";
|
|
40
|
+
const resp = await apiClient.post(`/api/v1/cli/kb/metric?skip_validate=${skipValidate}`, {
|
|
41
|
+
name: opts.name,
|
|
42
|
+
calculation: opts.sql,
|
|
43
|
+
table: opts.table,
|
|
44
|
+
description: opts.description,
|
|
45
|
+
topics,
|
|
46
|
+
default_dimensions: defaultDimensions,
|
|
47
|
+
parameters,
|
|
48
|
+
unverified: Boolean(opts.unverified),
|
|
49
|
+
});
|
|
50
|
+
if (fmt === "styled") {
|
|
51
|
+
styledIntro(`graphit kb create metric`);
|
|
52
|
+
styledSuccess(`Metric ${formatBold(String(resp.entity.name))} created`);
|
|
53
|
+
renderValidation(this, resp);
|
|
54
|
+
styledOutro();
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const out = { ...resp.entity };
|
|
58
|
+
if (resp.validation)
|
|
59
|
+
out.validation = resp.validation;
|
|
60
|
+
output(this, out, { keyValue: true });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
errorOutput(err);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
create
|
|
68
|
+
.command("dimension")
|
|
69
|
+
.description("Create a new dimension")
|
|
70
|
+
.requiredOption("--name <name>", "Dimension name (UPPER_SNAKE_CASE)")
|
|
71
|
+
.requiredOption("--expr <expr>", "SQL expression")
|
|
72
|
+
.requiredOption("--table <table>", "Primary table")
|
|
73
|
+
.option("--type <type>", "Semantic type: categorical, temporal, quantitative, boolean, geographic (auto-inferred if omitted)")
|
|
74
|
+
.option("--output-type <outputType>", "SQL output type: VARCHAR, NUMBER, BOOLEAN, DATE, TIMESTAMP (auto-inferred if omitted)")
|
|
75
|
+
.option("--description <desc>", "Description", "")
|
|
76
|
+
.option("--topics <topics>", "Comma-separated topic names")
|
|
77
|
+
.option("--skip-validate", "Skip pre-creation data validation")
|
|
78
|
+
.option("--unverified", "Create as a draft instead of verified (default: verified)")
|
|
79
|
+
.action(async function () {
|
|
80
|
+
try {
|
|
81
|
+
const opts = this.opts();
|
|
82
|
+
const fmt = getOutputFormat(this);
|
|
83
|
+
const topics = opts.topics ? opts.topics.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
84
|
+
const body = {
|
|
85
|
+
name: opts.name,
|
|
86
|
+
expression: opts.expr,
|
|
87
|
+
table: opts.table,
|
|
88
|
+
description: opts.description,
|
|
89
|
+
topics,
|
|
90
|
+
unverified: Boolean(opts.unverified),
|
|
91
|
+
};
|
|
92
|
+
if (opts.type)
|
|
93
|
+
body.semantic_type = opts.type;
|
|
94
|
+
if (opts.outputType)
|
|
95
|
+
body.output_type = opts.outputType;
|
|
96
|
+
const skipValidate = opts.skipValidate ? "true" : "false";
|
|
97
|
+
const resp = await apiClient.post(`/api/v1/cli/kb/dimension?skip_validate=${skipValidate}`, body);
|
|
98
|
+
if (fmt === "styled") {
|
|
99
|
+
styledIntro(`graphit kb create dimension`);
|
|
100
|
+
styledSuccess(`Dimension ${formatBold(String(resp.entity.name))} created`);
|
|
101
|
+
renderValidation(this, resp);
|
|
102
|
+
styledOutro();
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const out = { ...resp.entity };
|
|
106
|
+
if (resp.validation)
|
|
107
|
+
out.validation = resp.validation;
|
|
108
|
+
output(this, out, { keyValue: true });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
errorOutput(err);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
create
|
|
116
|
+
.command("rule")
|
|
117
|
+
.description("Create a new rule. Without --apply-on the rule governs the whole --table, which cascades to every metric and dimension on it. Use --apply-on metric:NAME / dimension:NAME to govern only specific assets instead. A rule must apply to at least one asset (targetless rules are rejected).")
|
|
118
|
+
.requiredOption("--name <name>", "Rule name (UPPER_SNAKE_CASE)")
|
|
119
|
+
.requiredOption("--sql <expr>", "Rule content/SQL")
|
|
120
|
+
.requiredOption("--table <table>", "Table the rule is about (validation context, and the whole-table target unless --apply-on narrows it)")
|
|
121
|
+
.option("--description <desc>", "Description", "")
|
|
122
|
+
.option("--topics <topics>", "Comma-separated topic names")
|
|
123
|
+
.option("--constraint <spec...>", "Enforceable constraints (e.g., required_where:\"x=1\" forbidden_column:email)")
|
|
124
|
+
.option("--apply-on <targets...>", "What the rule governs. Omit to govern the whole --table (cascades to every metric/dimension on it). Use metric:NAME / dimension:NAME to govern only those assets. Cannot mix a table target with metric/dimension targets.")
|
|
125
|
+
.option("--override-policy <policy>", "Override policy: anyone|analyst_only|admin_only|never", "anyone")
|
|
126
|
+
.option("--skip-validate", "Skip pre-creation data validation")
|
|
127
|
+
.option("--unverified", "Create as a draft instead of verified (default: verified)")
|
|
128
|
+
.action(async function () {
|
|
129
|
+
try {
|
|
130
|
+
const opts = this.opts();
|
|
131
|
+
const fmt = getOutputFormat(this);
|
|
132
|
+
const topics = opts.topics ? opts.topics.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
133
|
+
const constraints = opts.constraint ? parseConstraintFlags(opts.constraint) : undefined;
|
|
134
|
+
const applyOn = opts.applyOn ? parseApplyOnFlags(opts.applyOn) : undefined;
|
|
135
|
+
const skipValidate = opts.skipValidate ? "true" : "false";
|
|
136
|
+
const resp = await apiClient.post(`/api/v1/cli/kb/rule?skip_validate=${skipValidate}`, {
|
|
137
|
+
name: opts.name,
|
|
138
|
+
content: opts.sql,
|
|
139
|
+
table: opts.table,
|
|
140
|
+
description: opts.description,
|
|
141
|
+
topics,
|
|
142
|
+
constraints,
|
|
143
|
+
apply_on: applyOn,
|
|
144
|
+
override_policy: opts.overridePolicy,
|
|
145
|
+
unverified: Boolean(opts.unverified),
|
|
146
|
+
});
|
|
147
|
+
if (fmt === "styled") {
|
|
148
|
+
styledIntro(`graphit kb create rule`);
|
|
149
|
+
styledSuccess(`Rule ${formatBold(String(resp.entity.name))} created`);
|
|
150
|
+
renderValidation(this, resp);
|
|
151
|
+
styledOutro();
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const out = { ...resp.entity };
|
|
155
|
+
if (resp.validation)
|
|
156
|
+
out.validation = resp.validation;
|
|
157
|
+
output(this, out, { keyValue: true });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
errorOutput(err);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
create
|
|
165
|
+
.command("domain")
|
|
166
|
+
.description("Create a new domain")
|
|
167
|
+
.requiredOption("--name <name>", "Domain name (UPPER_SNAKE_CASE)")
|
|
168
|
+
.option("--description <desc>", "Description", "")
|
|
169
|
+
.option("--color <hex>", "Hex color for UI", "#4DB6AC")
|
|
170
|
+
.action(async function () {
|
|
171
|
+
try {
|
|
172
|
+
const opts = this.opts();
|
|
173
|
+
const resp = await apiClient.post("/api/v1/cli/kb/domain", {
|
|
174
|
+
name: opts.name,
|
|
175
|
+
description: opts.description,
|
|
176
|
+
color: opts.color,
|
|
177
|
+
});
|
|
178
|
+
output(this, resp.entity, { keyValue: true });
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
errorOutput(err);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
create
|
|
185
|
+
.command("synonym")
|
|
186
|
+
.description("Create a new synonym")
|
|
187
|
+
.requiredOption("--term <term>", "Synonym term (e.g., GMV)")
|
|
188
|
+
.requiredOption("--canonical <name>", "Canonical asset name (e.g., TOTAL_REVENUE)")
|
|
189
|
+
.requiredOption("--type <type>", "Canonical type: metric, column, or table")
|
|
190
|
+
.option("--description <desc>", "Description", "")
|
|
191
|
+
.option("--unverified", "Create as a draft instead of verified (default: verified)")
|
|
192
|
+
.action(async function () {
|
|
193
|
+
try {
|
|
194
|
+
const opts = this.opts();
|
|
195
|
+
const resp = await apiClient.post("/api/v1/cli/kb/synonym", {
|
|
196
|
+
term: opts.term,
|
|
197
|
+
canonical: opts.canonical,
|
|
198
|
+
canonical_type: opts.type,
|
|
199
|
+
description: opts.description,
|
|
200
|
+
unverified: Boolean(opts.unverified),
|
|
201
|
+
});
|
|
202
|
+
output(this, resp.entity, { keyValue: true });
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
errorOutput(err);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
create
|
|
209
|
+
.command("relationship")
|
|
210
|
+
.description("Create a new relationship (JOIN between tables)")
|
|
211
|
+
.requiredOption("--name <name>", "Relationship name (e.g., ORDERS_TO_CUSTOMERS)")
|
|
212
|
+
.requiredOption("--primary-table <table>", "Primary table")
|
|
213
|
+
.requiredOption("--primary-column <col>", "Primary column")
|
|
214
|
+
.requiredOption("--related-table <table>", "Related table")
|
|
215
|
+
.requiredOption("--related-column <col>", "Related column")
|
|
216
|
+
.option("--description <desc>", "Description", "")
|
|
217
|
+
.action(async function () {
|
|
218
|
+
try {
|
|
219
|
+
const opts = this.opts();
|
|
220
|
+
const resp = await apiClient.post("/api/v1/cli/kb/relationship", {
|
|
221
|
+
name: opts.name,
|
|
222
|
+
primary_table: opts.primaryTable,
|
|
223
|
+
primary_column: opts.primaryColumn,
|
|
224
|
+
related_table: opts.relatedTable,
|
|
225
|
+
related_column: opts.relatedColumn,
|
|
226
|
+
description: opts.description,
|
|
227
|
+
});
|
|
228
|
+
output(this, resp.entity, { keyValue: true });
|
|
229
|
+
}
|
|
230
|
+
catch (err) {
|
|
231
|
+
errorOutput(err);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
create
|
|
235
|
+
.command("topic")
|
|
236
|
+
.description("Create a new topic (business-concept tag)")
|
|
237
|
+
.requiredOption("--name <name>", "Topic name (UPPER_SNAKE_CASE)")
|
|
238
|
+
.option("--description <desc>", "Description", "")
|
|
239
|
+
.action(async function () {
|
|
240
|
+
try {
|
|
241
|
+
const opts = this.opts();
|
|
242
|
+
const resp = await apiClient.post("/api/v1/cli/kb/topic", {
|
|
243
|
+
name: opts.name,
|
|
244
|
+
description: opts.description,
|
|
245
|
+
});
|
|
246
|
+
output(this, resp.entity, { keyValue: true });
|
|
247
|
+
}
|
|
248
|
+
catch (err) {
|
|
249
|
+
errorOutput(err);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
create
|
|
253
|
+
.command("template")
|
|
254
|
+
.description("Create a reusable chart template")
|
|
255
|
+
.requiredOption("--name <name>", "Template name (UPPER_SNAKE_CASE)")
|
|
256
|
+
.option("--render-code <code>", "JS function body for rendering")
|
|
257
|
+
.option("--file <path>", "Read render code from a local file")
|
|
258
|
+
.option("--description <desc>", "Description", "")
|
|
259
|
+
.option("--chart-types <types>", "Related chart types (comma-separated)", "")
|
|
260
|
+
.action(async function () {
|
|
261
|
+
try {
|
|
262
|
+
const opts = this.opts();
|
|
263
|
+
let renderCode;
|
|
264
|
+
if (opts.file) {
|
|
265
|
+
renderCode = await readFile(opts.file, "utf-8");
|
|
266
|
+
}
|
|
267
|
+
else if (opts.renderCode) {
|
|
268
|
+
renderCode = opts.renderCode;
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
console.error(JSON.stringify({ error: "Provide --render-code or --file" }));
|
|
272
|
+
process.exit(1);
|
|
273
|
+
}
|
|
274
|
+
const chartTypes = opts.chartTypes
|
|
275
|
+
? opts.chartTypes.split(",").map((s) => s.trim()).filter(Boolean)
|
|
276
|
+
: [];
|
|
277
|
+
const resp = await apiClient.post("/api/v1/cli/kb/template", {
|
|
278
|
+
name: opts.name,
|
|
279
|
+
render_code: renderCode,
|
|
280
|
+
description: opts.description,
|
|
281
|
+
chart_types: chartTypes,
|
|
282
|
+
});
|
|
283
|
+
output(this, resp.entity, { keyValue: true });
|
|
284
|
+
}
|
|
285
|
+
catch (err) {
|
|
286
|
+
errorOutput(err);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=kb-create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kb-create.js","sourceRoot":"","sources":["../../src/commands/kb-create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAA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EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QAChD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { apiClient } from "../api/client.js";
|
|
2
|
+
import { errorOutput } from "../output/format.js";
|
|
3
|
+
// Project #254 Phase 1: kb delete verb.
|
|
4
|
+
export function addKBDeleteCommands(kb) {
|
|
5
|
+
kb.command("delete <type> <name>")
|
|
6
|
+
.description("Delete a KB entity (requires --yes flag)")
|
|
7
|
+
.requiredOption("--yes", "Confirm deletion")
|
|
8
|
+
.action(async function (type, name) {
|
|
9
|
+
try {
|
|
10
|
+
const validTypes = ["metric", "dimension", "rule", "template", "synonym", "domain", "relationship", "topic"];
|
|
11
|
+
if (!validTypes.includes(type)) {
|
|
12
|
+
console.error(JSON.stringify({
|
|
13
|
+
error: `Delete not supported for '${type}'. Supported: ${validTypes.join(", ")}`,
|
|
14
|
+
}));
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
await apiClient.delete(`/api/v1/cli/kb/${type}/${encodeURIComponent(name)}`);
|
|
18
|
+
console.log(JSON.stringify({ status: "deleted", type, name: name.toUpperCase() }));
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
errorOutput(err);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=kb-delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kb-delete.js","sourceRoot":"","sources":["../../src/commands/kb-delete.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,wCAAwC;AAExC,MAAM,UAAU,mBAAmB,CAAC,EAAW;IAC7C,EAAE,CAAC,OAAO,CAAC,sBAAsB,CAAC;SAC/B,WAAW,CAAC,0CAA0C,CAAC;SACvD,cAAc,CAAC,OAAO,EAAE,kBAAkB,CAAC;SAC3C,MAAM,CAAC,KAAK,WAA0B,IAAY,EAAE,IAAY;QAC/D,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;YAC7G,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC/B,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;oBAC3B,KAAK,EAAE,6BAA6B,IAAI,iBAAiB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;iBACjF,CAAC,CAAC,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YACD,MAAM,SAAS,CAAC,MAAM,CAAC,kBAAkB,IAAI,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC7E,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;QACrF,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { apiClient } from "../api/client.js";
|
|
2
|
+
import { output, errorOutput, getOutputFormat, note } from "../output/format.js";
|
|
3
|
+
import { styledIntro, styledOutro, styledInfo, styledMessage, styledTable, styledNote, formatBold, } from "../output/styled.js";
|
|
4
|
+
import { ENTITY_COLUMNS, } from "./kb-shared.js";
|
|
5
|
+
// Project #254 Phase 1: kb read verbs (list/get/search/explore/usage/verify/unverify).
|
|
6
|
+
export function addKBReadCommands(kb) {
|
|
7
|
+
kb.command("list <type>")
|
|
8
|
+
.description("List KB entities (metric, dimension, table, rule, domain, synonym) - the inventory verb. " +
|
|
9
|
+
"Parameterized metrics are collapsed: each template shows a variant_count, child variants are hidden. " +
|
|
10
|
+
"Use --include-variants for the full flat set, kb explore metric <name> to enumerate one template's variants, " +
|
|
11
|
+
"kb get for the full definition. The response carries total/truncated, so fewer rows than total means raise --limit.")
|
|
12
|
+
.option("--limit <n>", "Max results", "50")
|
|
13
|
+
.option("--verified", "Only verified entities")
|
|
14
|
+
.option("--unverified", "Only unverified entities")
|
|
15
|
+
.option("--include-variants", "metric: expand parameterized child variants instead of collapsing them under their template")
|
|
16
|
+
.action(async function (type) {
|
|
17
|
+
try {
|
|
18
|
+
const opts = this.opts();
|
|
19
|
+
const fmt = getOutputFormat(this);
|
|
20
|
+
const params = new URLSearchParams({ limit: opts.limit });
|
|
21
|
+
if (opts.verified)
|
|
22
|
+
params.set("verified", "true");
|
|
23
|
+
if (opts.unverified)
|
|
24
|
+
params.set("verified", "false");
|
|
25
|
+
if (opts.includeVariants)
|
|
26
|
+
params.set("include_variants", "true");
|
|
27
|
+
const resp = await apiClient.get(`/api/v1/cli/kb/${type}?${params}`);
|
|
28
|
+
let entities = resp.entities;
|
|
29
|
+
if (type === "metric") {
|
|
30
|
+
entities = entities.map((e) => {
|
|
31
|
+
const calc = e.calculation || "";
|
|
32
|
+
const paramMatches = calc.match(/\$\{PARAM:(\w+)\}/g);
|
|
33
|
+
return { ...e, params: paramMatches ? paramMatches.map((m) => m.replace(/\$\{PARAM:|}/g, "")).join(", ") : "" };
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (fmt === "styled") {
|
|
37
|
+
styledIntro(`graphit kb list ${type}`);
|
|
38
|
+
styledInfo(`${resp.count} ${type}${resp.count !== 1 ? "s" : ""}`);
|
|
39
|
+
const cols = ENTITY_COLUMNS[type] ?? Object.keys(entities[0] ?? {});
|
|
40
|
+
const displayCols = cols.filter((c) => c !== "id");
|
|
41
|
+
const tableRows = entities.map((e) => displayCols.map((c) => c === "name" || c === "term"
|
|
42
|
+
? formatBold(String(e[c] ?? ""))
|
|
43
|
+
: String(e[c] ?? "")));
|
|
44
|
+
if (tableRows.length) {
|
|
45
|
+
styledMessage(styledTable(displayCols, tableRows));
|
|
46
|
+
}
|
|
47
|
+
if (resp.truncated) {
|
|
48
|
+
styledNote(`Showing ${resp.count} of ${resp.total} - raise --limit to see the rest.`, "Truncated");
|
|
49
|
+
}
|
|
50
|
+
styledOutro();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
output(this, entities, { columns: ENTITY_COLUMNS[type] });
|
|
54
|
+
if (resp.truncated) {
|
|
55
|
+
note(`Showing ${resp.count} of ${resp.total} ${type}s - raise --limit to see the rest (a missing asset may be truncated, not absent).`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
errorOutput(err);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
kb.command("get <type> <name>")
|
|
64
|
+
.description("Get a KB entity by name")
|
|
65
|
+
.action(async function (type, name) {
|
|
66
|
+
try {
|
|
67
|
+
const resp = await apiClient.get(`/api/v1/cli/kb/${type}/by-name/${encodeURIComponent(name)}`);
|
|
68
|
+
output(this, resp.entity, { keyValue: true });
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
errorOutput(err);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
kb.command("search <query>")
|
|
75
|
+
.description("Semantic + substring search across KB assets, ranked by relevance")
|
|
76
|
+
.option("--type <type>", "Filter by entity type")
|
|
77
|
+
.option("--limit <n>", "Max results", "50")
|
|
78
|
+
.action(async function (query) {
|
|
79
|
+
try {
|
|
80
|
+
const opts = this.opts();
|
|
81
|
+
const params = new URLSearchParams({ q: query, limit: opts.limit });
|
|
82
|
+
if (opts.type)
|
|
83
|
+
params.set("type", opts.type);
|
|
84
|
+
const resp = await apiClient.get(`/api/v1/cli/kb/search?${params}`);
|
|
85
|
+
// json (default): emit the full payload so callers see count/total/truncated
|
|
86
|
+
// (a miss may be truncation, not absence). table: clean rows + a stderr note.
|
|
87
|
+
if (getOutputFormat(this) === "json") {
|
|
88
|
+
output(this, resp);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
output(this, resp.results, { columns: ["score", "type", "name", "description"] });
|
|
92
|
+
if (resp.truncated) {
|
|
93
|
+
note(`Showing ${resp.count} of ${resp.total} matches - narrow with --type or raise --limit (max 100).`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
errorOutput(err);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
kb.command("explore <type> <name>")
|
|
102
|
+
.description("Traverse the KB graph - the relationships verb. metric: tables, dimensions, parameters + its concrete variants; " +
|
|
103
|
+
"table/domain/topic: every bound metric (collapsed, with variant_count), dimension and rule plus counts. " +
|
|
104
|
+
"Use this for what's bound to a table X or show me this template's variants.")
|
|
105
|
+
.action(async function (type, name) {
|
|
106
|
+
try {
|
|
107
|
+
const resp = await apiClient.get(`/api/v1/cli/kb/explore/${type}/${encodeURIComponent(name)}`);
|
|
108
|
+
output(this, resp, { keyValue: true });
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
errorOutput(err);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
kb.command("usage [type] [name]")
|
|
115
|
+
.description("Reverse lookup: which custom dashboards present a metric, use a dimension, or enforce a rule. " +
|
|
116
|
+
"[type] [name] = primary facet; --metric/--dimension/--rule AND together. Governed macros only - raw SQL invisible.")
|
|
117
|
+
.option("--metric <name>", "Filter to entities presenting this metric")
|
|
118
|
+
.option("--dimension <name>", "Filter to entities using this dimension")
|
|
119
|
+
.option("--rule <name>", "Filter to entities where this rule is enforced")
|
|
120
|
+
.action(async function (type, name) {
|
|
121
|
+
try {
|
|
122
|
+
const opts = this.opts();
|
|
123
|
+
const facets = {
|
|
124
|
+
metric: opts.metric,
|
|
125
|
+
dimension: opts.dimension,
|
|
126
|
+
rule: opts.rule,
|
|
127
|
+
};
|
|
128
|
+
// Positional <type> <name> sets the primary facet (flags take precedence).
|
|
129
|
+
if (type && name) {
|
|
130
|
+
const t = type.toLowerCase();
|
|
131
|
+
if (t === "metric" || t === "dimension" || t === "rule") {
|
|
132
|
+
facets[t] = facets[t] ?? name;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
errorOutput(new Error(`Unknown usage type '${type}'. Use metric, dimension, or rule.`));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const params = new URLSearchParams();
|
|
140
|
+
if (facets.metric)
|
|
141
|
+
params.set("metric", facets.metric);
|
|
142
|
+
if (facets.dimension)
|
|
143
|
+
params.set("dimension", facets.dimension);
|
|
144
|
+
if (facets.rule)
|
|
145
|
+
params.set("rule", facets.rule);
|
|
146
|
+
if ([...params.keys()].length === 0) {
|
|
147
|
+
errorOutput(new Error("Provide a facet: usage <metric|dimension|rule> <name>, or --metric/--dimension/--rule."));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const resp = await apiClient.get(`/api/v1/cli/kb/usage?${params}`);
|
|
151
|
+
if (getOutputFormat(this) === "json") {
|
|
152
|
+
output(this, resp);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const rows = resp.used_in.map((h) => ({
|
|
156
|
+
dashboard: h.dashboard_name,
|
|
157
|
+
entity: h.entity_id,
|
|
158
|
+
label: h.label,
|
|
159
|
+
metrics: h.metrics.join(", "),
|
|
160
|
+
dimensions: h.dimensions.join(", "),
|
|
161
|
+
rules: h.rules.map((r) => r.name).join(", "),
|
|
162
|
+
}));
|
|
163
|
+
output(this, rows, {
|
|
164
|
+
columns: ["dashboard", "entity", "label", "metrics", "dimensions", "rules"],
|
|
165
|
+
});
|
|
166
|
+
if (resp.subject) {
|
|
167
|
+
const s = resp.subject;
|
|
168
|
+
note(`${s.name} (${s.type}${s.home_table ? ` on ${s.home_table}` : ""})` +
|
|
169
|
+
(s.expression ? `: ${s.expression}` : ""));
|
|
170
|
+
}
|
|
171
|
+
note(`Presented in ${resp.dashboard_count} dashboard(s), ${resp.hit_count} chart(s).`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
errorOutput(err);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
kb.command("verify <type> <name>")
|
|
179
|
+
.description("Verify a KB asset by name; metric templates cascade to all variants")
|
|
180
|
+
.action(async function (type, name) {
|
|
181
|
+
try {
|
|
182
|
+
const resp = await apiClient.post(`/api/v1/cli/kb/${encodeURIComponent(type)}/${encodeURIComponent(name)}/verify`, {});
|
|
183
|
+
output(this, resp, { keyValue: true });
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
errorOutput(err);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
kb.command("unverify <type> <name>")
|
|
190
|
+
.description("Unverify a KB asset (mark as draft); cascades to metric variants")
|
|
191
|
+
.action(async function (type, name) {
|
|
192
|
+
try {
|
|
193
|
+
const resp = await apiClient.post(`/api/v1/cli/kb/${encodeURIComponent(type)}/${encodeURIComponent(name)}/verify?unverify=true`, {});
|
|
194
|
+
output(this, resp, { keyValue: true });
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
errorOutput(err);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=kb-read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kb-read.js","sourceRoot":"","sources":["../../src/commands/kb-read.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SA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F,MAAM,CAAC,KAAK,WAA0B,IAAY,EAAE,IAAY;QAC/D,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,IAAI,CAC/B,kBAAkB,kBAAkB,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAC/E,EAAE,CACH,CAAC;YACF,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC;SACjC,WAAW,CAAC,kEAAkE,CAAC;SAC/E,MAAM,CAAC,KAAK,WAA0B,IAAY,EAAE,IAAY;QAC/D,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,IAAI,CAC/B,kBAAkB,kBAAkB,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,uBAAuB,EAC7F,EAAE,CACH,CAAC;YACF,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
export interface KBListResponse {
|
|
3
|
+
entity_type: string;
|
|
4
|
+
count: number;
|
|
5
|
+
total?: number;
|
|
6
|
+
truncated?: boolean;
|
|
7
|
+
entities: Record<string, unknown>[];
|
|
8
|
+
}
|
|
9
|
+
export interface KBCreateResponse {
|
|
10
|
+
entity: Record<string, unknown>;
|
|
11
|
+
validation?: {
|
|
12
|
+
status: string;
|
|
13
|
+
sample_query?: string;
|
|
14
|
+
sample_data?: Record<string, unknown>[];
|
|
15
|
+
sample_columns?: string[];
|
|
16
|
+
warnings?: string[];
|
|
17
|
+
skip_reason?: string;
|
|
18
|
+
display_instruction?: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface KBGetResponse {
|
|
22
|
+
entity: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
export declare const ENTITY_COLUMNS: Record<string, string[]>;
|
|
25
|
+
export declare function renderValidation(cmd: Command, resp: KBCreateResponse): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getOutputFormat } from "../output/format.js";
|
|
2
|
+
import { styledSuccess, styledInfo, styledMessage, styledWarn, styledNote, styledTable, } from "../output/styled.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
export const ENTITY_COLUMNS = {
|
|
5
|
+
metric: ["id", "name", "description", "calculation", "params", "variant_count", "verified"],
|
|
6
|
+
dimension: ["id", "name", "description", "expression", "verified"],
|
|
7
|
+
table: ["id", "name", "description", "verified"],
|
|
8
|
+
rule: ["id", "name", "description", "verified"],
|
|
9
|
+
domain: ["id", "name", "description", "color"],
|
|
10
|
+
synonym: ["id", "term", "canonical", "canonical_type", "description"],
|
|
11
|
+
template: ["id", "name", "description", "chart_types"],
|
|
12
|
+
relationship: ["id", "name", "primary_table", "primary_column", "description"],
|
|
13
|
+
topic: ["id", "name", "description", "verified"],
|
|
14
|
+
};
|
|
15
|
+
export function renderValidation(cmd, resp) {
|
|
16
|
+
const fmt = getOutputFormat(cmd);
|
|
17
|
+
const v = resp.validation;
|
|
18
|
+
if (!v)
|
|
19
|
+
return;
|
|
20
|
+
if (fmt === "styled") {
|
|
21
|
+
if (v.status === "pass") {
|
|
22
|
+
styledSuccess("Validated against real data");
|
|
23
|
+
if (v.sample_query) {
|
|
24
|
+
styledNote(chalk.dim(v.sample_query), "Validation SQL");
|
|
25
|
+
}
|
|
26
|
+
if (v.sample_data?.length && v.sample_columns?.length) {
|
|
27
|
+
const cols = v.sample_columns;
|
|
28
|
+
const rows = v.sample_data.map((r) => cols.map((c) => String(r[c] ?? "")));
|
|
29
|
+
styledMessage(styledTable(cols, rows));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (v.status === "skipped") {
|
|
33
|
+
styledInfo(`Validation skipped: ${v.skip_reason ?? "unknown reason"}`);
|
|
34
|
+
}
|
|
35
|
+
if (v.warnings?.length) {
|
|
36
|
+
for (const w of v.warnings)
|
|
37
|
+
styledWarn(w);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=kb-shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kb-shared.js","sourceRoot":"","sources":["../../src/commands/kb-shared.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACL,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAChE,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAC;AA+B1B,MAAM,CAAC,MAAM,cAAc,GAA6B;IACtD,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,CAAC;IAC3F,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,CAAC;IAClE,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,CAAC;IAChD,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,CAAC;IAC/C,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC;IAC9C,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB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