@reporting-bi/cli 0.1.9 → 0.1.11

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.
Files changed (2) hide show
  1. package/dist/index.js +173 -54
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4776,9 +4776,9 @@ var require_keyword = __commonJS({
4776
4776
  if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword) : def2.keyword !== keyword) {
4777
4777
  throw new Error("ajv implementation error");
4778
4778
  }
4779
- const deps = def2.dependencies;
4780
- if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
4781
- throw new Error(`parent schema must have dependencies of ${keyword}: ${deps.join(",")}`);
4779
+ const deps2 = def2.dependencies;
4780
+ if (deps2 === null || deps2 === void 0 ? void 0 : deps2.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
4781
+ throw new Error(`parent schema must have dependencies of ${keyword}: ${deps2.join(",")}`);
4782
4782
  }
4783
4783
  if (def2.validateSchema) {
4784
4784
  const valid = def2.validateSchema(schema[keyword]);
@@ -8198,14 +8198,14 @@ var require_dependencies = __commonJS({
8198
8198
  var util_1 = require_util();
8199
8199
  var code_1 = require_code2();
8200
8200
  exports2.error = {
8201
- message: ({ params: { property, depsCount, deps } }) => {
8201
+ message: ({ params: { property, depsCount, deps: deps2 } }) => {
8202
8202
  const property_ies = depsCount === 1 ? "property" : "properties";
8203
- return (0, codegen_1.str)`must have ${property_ies} ${deps} when property ${property} is present`;
8203
+ return (0, codegen_1.str)`must have ${property_ies} ${deps2} when property ${property} is present`;
8204
8204
  },
8205
- params: ({ params: { property, depsCount, deps, missingProperty } }) => (0, codegen_1._)`{property: ${property},
8205
+ params: ({ params: { property, depsCount, deps: deps2, missingProperty } }) => (0, codegen_1._)`{property: ${property},
8206
8206
  missingProperty: ${missingProperty},
8207
8207
  depsCount: ${depsCount},
8208
- deps: ${deps}}`
8208
+ deps: ${deps2}}`
8209
8209
  // TODO change to reference
8210
8210
  };
8211
8211
  var def2 = {
@@ -8225,8 +8225,8 @@ var require_dependencies = __commonJS({
8225
8225
  for (const key in schema) {
8226
8226
  if (key === "__proto__")
8227
8227
  continue;
8228
- const deps = Array.isArray(schema[key]) ? propertyDeps : schemaDeps;
8229
- deps[key] = schema[key];
8228
+ const deps2 = Array.isArray(schema[key]) ? propertyDeps : schemaDeps;
8229
+ deps2[key] = schema[key];
8230
8230
  }
8231
8231
  return [propertyDeps, schemaDeps];
8232
8232
  }
@@ -8236,23 +8236,23 @@ var require_dependencies = __commonJS({
8236
8236
  return;
8237
8237
  const missing = gen.let("missing");
8238
8238
  for (const prop in propertyDeps) {
8239
- const deps = propertyDeps[prop];
8240
- if (deps.length === 0)
8239
+ const deps2 = propertyDeps[prop];
8240
+ if (deps2.length === 0)
8241
8241
  continue;
8242
8242
  const hasProperty = (0, code_1.propertyInData)(gen, data, prop, it.opts.ownProperties);
8243
8243
  cxt.setParams({
8244
8244
  property: prop,
8245
- depsCount: deps.length,
8246
- deps: deps.join(", ")
8245
+ depsCount: deps2.length,
8246
+ deps: deps2.join(", ")
8247
8247
  });
8248
8248
  if (it.allErrors) {
8249
8249
  gen.if(hasProperty, () => {
8250
- for (const depProp of deps) {
8250
+ for (const depProp of deps2) {
8251
8251
  (0, code_1.checkReportMissingProp)(cxt, depProp);
8252
8252
  }
8253
8253
  });
8254
8254
  } else {
8255
- gen.if((0, codegen_1._)`${hasProperty} && (${(0, code_1.checkMissingProp)(cxt, deps, missing)})`);
8255
+ gen.if((0, codegen_1._)`${hasProperty} && (${(0, code_1.checkMissingProp)(cxt, deps2, missing)})`);
8256
8256
  (0, code_1.reportMissingProp)(cxt, missing);
8257
8257
  gen.else();
8258
8258
  }
@@ -10551,6 +10551,35 @@ function writeFileSync4(filePath, content4) {
10551
10551
  function isInternalPath(relPath) {
10552
10552
  return relPath === RPBI_DIR || relPath.startsWith(`${RPBI_DIR}/`);
10553
10553
  }
10554
+ function optimizeForLlm(data) {
10555
+ if (data === null || data === void 0) return void 0;
10556
+ if (Array.isArray(data)) {
10557
+ const result = data.map((item) => optimizeForLlm(item)).filter((item) => item !== void 0);
10558
+ return result.length > 0 ? result : void 0;
10559
+ }
10560
+ if (typeof data === "object") {
10561
+ const result = {};
10562
+ let hasKeys = false;
10563
+ for (const [key, value] of Object.entries(data)) {
10564
+ const optimized = optimizeForLlm(value);
10565
+ if (optimized !== void 0) {
10566
+ result[key] = optimized;
10567
+ hasKeys = true;
10568
+ }
10569
+ }
10570
+ return hasKeys ? result : void 0;
10571
+ }
10572
+ return data;
10573
+ }
10574
+ function stripFields(obj, excludeFields) {
10575
+ const result = {};
10576
+ for (const [key, value] of Object.entries(obj)) {
10577
+ if (!excludeFields.includes(key)) {
10578
+ result[key] = value;
10579
+ }
10580
+ }
10581
+ return result;
10582
+ }
10554
10583
  function isNestedWorkspace(dir) {
10555
10584
  return fs4.existsSync(path3.join(dir, RPBI_DIR, CONFIG_FILE));
10556
10585
  }
@@ -11261,26 +11290,6 @@ var CONTEXT_SCHEMA_DIRS = {
11261
11290
  "schema/db_super/procedures": { db: "db_super", objectType: "procedures" },
11262
11291
  "schema/db_super/functions": { db: "db_super", objectType: "functions" }
11263
11292
  };
11264
- function optimizeForLlm(data) {
11265
- if (data === null || data === void 0) return void 0;
11266
- if (Array.isArray(data)) {
11267
- const result = data.map((item) => optimizeForLlm(item)).filter((item) => item !== void 0);
11268
- return result.length > 0 ? result : void 0;
11269
- }
11270
- if (typeof data === "object") {
11271
- const result = {};
11272
- let hasKeys = false;
11273
- for (const [key, value] of Object.entries(data)) {
11274
- const optimized = optimizeForLlm(value);
11275
- if (optimized !== void 0) {
11276
- result[key] = optimized;
11277
- hasKeys = true;
11278
- }
11279
- }
11280
- return hasKeys ? result : void 0;
11281
- }
11282
- return data;
11283
- }
11284
11293
  function getFilePath(description, extension = ".sql") {
11285
11294
  const parts = description.split("/");
11286
11295
  const name = parts.pop();
@@ -11309,15 +11318,6 @@ function threadToMetaPath(thread) {
11309
11318
  const segments = getFilePath(thread.description || "", ".yaml");
11310
11319
  return [".rpbi", "threads", typeToDirName(thread.type), ...segments].join("/");
11311
11320
  }
11312
- function stripFields(obj, excludeFields) {
11313
- const result = {};
11314
- for (const [key, value] of Object.entries(obj)) {
11315
- if (!excludeFields.includes(key)) {
11316
- result[key] = value;
11317
- }
11318
- }
11319
- return result;
11320
- }
11321
11321
  async function pull2(flags) {
11322
11322
  const dir = path5.resolve(flags.dir || ".");
11323
11323
  const conn = getActiveConnection(dir);
@@ -12199,7 +12199,9 @@ var path7 = __toESM(require("node:path"));
12199
12199
  var QUERIES_DIR = "queries";
12200
12200
  var RESOURCE_FIELDS = ["id_custom_resource", "id_custom_page", "name", "date_created"];
12201
12201
  var QUERY_FIELDS = ["id_thread", "id_custom_page", "description", "type", "date_created"];
12202
- var PROJECT_FIELDS = ["id_custom_page", "name"];
12202
+ var PROJECT_FIELDS = ["id_custom_page", "name", "description", "version"];
12203
+ var META_EXCLUDE_FIELDS = ["accounting", "id_custom_page", "idz", "validate_flag", "date_created", "who_created", "date_deleted", "who_deleted"];
12204
+ var PARAM_META_EXCLUDE_FIELDS = [...META_EXCLUDE_FIELDS, "id_thread", "content"];
12203
12205
  function resourceToRelPath(projectName, resource) {
12204
12206
  return `${projectName}/${resource.name}`;
12205
12207
  }
@@ -12216,6 +12218,45 @@ function splitProjectPath(relPath) {
12216
12218
  async function fetchProjects(service) {
12217
12219
  return await service.get("projects", { fields: PROJECT_FIELDS }) || [];
12218
12220
  }
12221
+ async function refreshProjectMeta(service, dir, project, queries2) {
12222
+ if (!project.id_custom_page || !project.name) return;
12223
+ const id = project.id_custom_page;
12224
+ try {
12225
+ if (!queries2) {
12226
+ queries2 = await service.get("queries", { fields: QUERY_FIELDS, where: { id_custom_page: id } }) || [];
12227
+ }
12228
+ const parameters = await service.get(`projects/${id}/parameters`) || [];
12229
+ const externalResources = await service.get(`externalResources/${id}`) || [];
12230
+ const dependencies = await service.get("queryDependencies", { where: { id_custom_page: id } }) || [];
12231
+ const paramsByThread = /* @__PURE__ */ new Map();
12232
+ for (const param of parameters) {
12233
+ if (!param.id_thread) continue;
12234
+ const list8 = paramsByThread.get(param.id_thread) || [];
12235
+ list8.push(stripFields(param, PARAM_META_EXCLUDE_FIELDS));
12236
+ paramsByThread.set(param.id_thread, list8);
12237
+ }
12238
+ const meta3 = {
12239
+ id_custom_page: id,
12240
+ name: project.name,
12241
+ description: project.description,
12242
+ version: project.version,
12243
+ queries: queries2.filter((q) => q.id_thread).map((q) => ({
12244
+ id_thread: q.id_thread,
12245
+ description: q.description,
12246
+ type: q.type,
12247
+ file: queryToRelPath(project.name, q),
12248
+ parameters: paramsByThread.get(q.id_thread)
12249
+ })),
12250
+ external_resources: externalResources.map((e) => stripFields(e, META_EXCLUDE_FIELDS)),
12251
+ dependencies: dependencies.map((d) => stripFields(d, META_EXCLUDE_FIELDS))
12252
+ };
12253
+ const optimized = optimizeForLlm(meta3);
12254
+ if (!optimized) return;
12255
+ writeFileSync4(path7.join(dir, ".rpbi", "projects", `${project.name}.yaml`), toYaml(optimized) + "\n");
12256
+ } catch (err) {
12257
+ console.error(` Failed to pull metadata for ${project.name}: ${err instanceof Error ? err.message : err}`);
12258
+ }
12259
+ }
12219
12260
  function buildProjectMap(projects2) {
12220
12261
  const map2 = /* @__PURE__ */ new Map();
12221
12262
  const seen = /* @__PURE__ */ new Set();
@@ -12308,6 +12349,11 @@ async function pull4(flags) {
12308
12349
  }
12309
12350
  }
12310
12351
  console.log(` Pulled ${pulledQueries} queries`);
12352
+ console.log("Pulling project metadata...");
12353
+ for (const project of projects2) {
12354
+ if (!project.id_custom_page || !project.name) continue;
12355
+ await refreshProjectMeta(service, dir, project, queries2.filter((q) => q.id_custom_page === project.id_custom_page));
12356
+ }
12311
12357
  writeConfig(dir, {
12312
12358
  domain: conn.domain,
12313
12359
  accounting: conn.tokens.accounting,
@@ -12561,21 +12607,89 @@ async function content3(id, flags) {
12561
12607
  const text2 = await service.get(endpoint, void 0, { parseResponse: false });
12562
12608
  process.stdout.write(text2 || "");
12563
12609
  }
12610
+ async function refreshMetaForProject(service, flags, idProject) {
12611
+ if (!idProject) return;
12612
+ const root = findProjectRoot(flags.dir || ".");
12613
+ if (!root || readConfig(root)?.type !== "ext") return;
12614
+ try {
12615
+ const project = await service.get(`projects/${idProject}`);
12616
+ if (!project?.name) return;
12617
+ await refreshProjectMeta(service, root, project);
12618
+ console.error(`Updated .rpbi/projects/${project.name}.yaml`);
12619
+ } catch {
12620
+ }
12621
+ }
12564
12622
  async function params2(id, flags) {
12565
12623
  const service = await createService("extensions", { cwd: flags.dir || "." });
12624
+ const refreshMeta = async () => {
12625
+ try {
12626
+ const query = await service.get(`queries/${id}`, { fields: ["id_custom_page"] });
12627
+ await refreshMetaForProject(service, flags, query?.id_custom_page);
12628
+ } catch {
12629
+ }
12630
+ };
12566
12631
  if (flags.save) {
12567
12632
  const data = JSON.parse(fs12.readFileSync(flags.save, "utf-8"));
12568
12633
  data.id_thread ??= parseInt(id);
12569
12634
  const result = await service.post("parameters", data);
12635
+ await refreshMeta();
12570
12636
  output(result, flags);
12571
12637
  } else if (flags.delete) {
12572
12638
  await service.delete(`parameters/${flags.delete}`);
12639
+ await refreshMeta();
12573
12640
  console.log(`Parameter ${flags.delete} deleted.`);
12574
12641
  } else {
12575
12642
  const result = await service.get(`queries/${id}/parameters`);
12576
12643
  output(result || [], flags);
12577
12644
  }
12578
12645
  }
12646
+ var DEFAULT_DEP_FIELDS = ["idz", "id_custom_page", "id_custom_resource", "resource_name", "id_thread", "thread_name"];
12647
+ async function deps(flags) {
12648
+ const service = await createService("extensions", { cwd: flags.dir || "." });
12649
+ if (flags.add) {
12650
+ if (!flags.query && !flags.resource) {
12651
+ console.error("Usage: rpbi ext deps --query <id> --add <resource_id> | --resource <id> --add <query_id>");
12652
+ process.exit(1);
12653
+ }
12654
+ const idThread = flags.query ? parseInt(flags.query) : parseInt(flags.add);
12655
+ const idResource = flags.resource ? parseInt(flags.resource) : parseInt(flags.add);
12656
+ const created = await service.post("queryDependencies", {
12657
+ id_thread: idThread,
12658
+ id_custom_resource: idResource
12659
+ });
12660
+ try {
12661
+ const query = await service.get(`queries/${idThread}`, { fields: ["id_custom_page"] });
12662
+ await refreshMetaForProject(service, flags, query?.id_custom_page);
12663
+ } catch {
12664
+ }
12665
+ output(created, flags);
12666
+ } else if (flags.remove) {
12667
+ let idProject;
12668
+ try {
12669
+ const rows = await service.get("queryDependencies", { where: { idz: parseInt(flags.remove) } });
12670
+ idProject = rows?.[0]?.id_custom_page;
12671
+ } catch {
12672
+ }
12673
+ await service.delete(`queryDependencies/${flags.remove}`);
12674
+ await refreshMetaForProject(service, flags, idProject);
12675
+ console.log(`Dependency ${flags.remove} deleted.`);
12676
+ } else {
12677
+ let where = null;
12678
+ if (flags.query) where = { id_thread: parseInt(flags.query) };
12679
+ else if (flags.resource) where = { id_custom_resource: parseInt(flags.resource) };
12680
+ else if (flags.project) where = { id_custom_page: parseInt(flags.project) };
12681
+ if (!where) {
12682
+ console.error("Usage: rpbi ext deps --project <id> | --query <id> | --resource <id> [--add <id>] [--remove <idz>]");
12683
+ process.exit(1);
12684
+ }
12685
+ const result = await service.get("queryDependencies", {
12686
+ ...getListParams(flags, DEFAULT_DEP_FIELDS),
12687
+ where,
12688
+ order: [["resource_name", "asc"], ["thread_name", "asc"]]
12689
+ });
12690
+ output(result || [], flags);
12691
+ }
12692
+ }
12579
12693
  async function exec4(id, flags) {
12580
12694
  const service = await createService("extensions", { cwd: flags.dir || "." });
12581
12695
  let body = void 0;
@@ -12631,6 +12745,8 @@ async function ext(args) {
12631
12745
  process.exit(1);
12632
12746
  }
12633
12747
  return params2(rest[0], flags);
12748
+ case "deps":
12749
+ return deps(flags);
12634
12750
  case "pull":
12635
12751
  return pull4(flags);
12636
12752
  case "push":
@@ -12640,7 +12756,7 @@ async function ext(args) {
12640
12756
  case "watch":
12641
12757
  return watch6(flags);
12642
12758
  default:
12643
- console.log("Usage: rpbi ext <projects|resources|queries|content|exec|params|pull|push|status|watch> [options]");
12759
+ console.log("Usage: rpbi ext <projects|resources|queries|content|exec|params|deps|pull|push|status|watch> [options]");
12644
12760
  break;
12645
12761
  }
12646
12762
  }
@@ -36169,7 +36285,7 @@ function text(data) {
36169
36285
  async function mcp() {
36170
36286
  const server = new McpServer({
36171
36287
  name: "reporting-bi",
36172
- version: "0.1.9"
36288
+ version: "0.1.11"
36173
36289
  });
36174
36290
  server.tool(
36175
36291
  "status",
@@ -36715,8 +36831,8 @@ async function checkForUpdate() {
36715
36831
  saveUpdateCheck({ lastCheck: now });
36716
36832
  const latest = await fetchLatestVersion();
36717
36833
  if (!latest) return;
36718
- if (!isNewer(latest, "0.1.9")) return;
36719
- console.log(`\x1B[33mUpdating ${PACKAGE_NAME} ${"0.1.9"} \u2192 ${latest}...\x1B[0m`);
36834
+ if (!isNewer(latest, "0.1.11")) return;
36835
+ console.log(`\x1B[33mUpdating ${PACKAGE_NAME} ${"0.1.11"} \u2192 ${latest}...\x1B[0m`);
36720
36836
  (0, import_node_child_process3.execSync)(npmInstallCmd(latest), { stdio: "inherit" });
36721
36837
  console.log(`\x1B[32mUpdated to ${latest}.\x1B[0m`);
36722
36838
  } catch {
@@ -36728,11 +36844,11 @@ async function forceUpdate() {
36728
36844
  console.error("Could not fetch latest version from npm.");
36729
36845
  process.exit(1);
36730
36846
  }
36731
- if (!isNewer(latest, "0.1.9")) {
36732
- console.log(`Already up to date (${"0.1.9"}).`);
36847
+ if (!isNewer(latest, "0.1.11")) {
36848
+ console.log(`Already up to date (${"0.1.11"}).`);
36733
36849
  return;
36734
36850
  }
36735
- console.log(`Updating ${PACKAGE_NAME} ${"0.1.9"} \u2192 ${latest}...`);
36851
+ console.log(`Updating ${PACKAGE_NAME} ${"0.1.11"} \u2192 ${latest}...`);
36736
36852
  (0, import_node_child_process3.execSync)(npmInstallCmd(latest), { stdio: "inherit" });
36737
36853
  console.log(`\x1B[32mUpdated to ${latest}.\x1B[0m`);
36738
36854
  saveUpdateCheck({ lastCheck: Date.now() });
@@ -36786,7 +36902,10 @@ Extensions (requires the "custom.define" right):
36786
36902
  ext content <id> [--query] Get resource content (--query for query SQL)
36787
36903
  ext exec <query_id> [--sql "..."|--file f] Execute query (optionally with custom SQL)
36788
36904
  ext params <query_id> [--save <json>|--delete <idz>] List, save or delete query parameters
36789
- ext pull [--dir <path>] Pull all projects (resources & queries) to local files
36905
+ ext deps --project <id>|--query <id>|--resource <id> List SQL dependencies (resource \u2194 query links)
36906
+ ext deps --query <id> --add <resource_id> Link a query to a resource (or --resource <id> --add <query_id>)
36907
+ ext deps --remove <idz> Unlink a dependency
36908
+ ext pull [--dir <path>] Pull all projects (resources, queries & project metadata) to local files
36790
36909
  ext push [files...] [--dir <path>] [--force] Push modified/new files back to server
36791
36910
  ext status [--dir <path>] [--remote] [--json] Show local changes (--remote compares with server)
36792
36911
  ext watch [--dir <path>] [--debounce <ms>] Watch for file changes and auto-push
@@ -36906,7 +37025,7 @@ Examples:
36906
37025
  (async () => {
36907
37026
  const [command, ...args] = process.argv.slice(2);
36908
37027
  if (command === "--version" || command === "-v") {
36909
- console.log("0.1.9");
37028
+ console.log("0.1.11");
36910
37029
  return;
36911
37030
  }
36912
37031
  await checkForUpdate();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporting-bi/cli",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Reporting.bi CLI — command-line interface for the Reporting.bi platform",
6
6
  "main": "./dist/index.js",