@datarails-ai/dr-appspace-cli 0.12.55 → 0.12.57

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/cli.js +314 -47
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -13,7 +13,7 @@ import { fileURLToPath as fileURLToPath6 } from "url";
13
13
  // package.json
14
14
  var package_default = {
15
15
  name: "@datarails-ai/dr-appspace-cli",
16
- version: "0.12.55",
16
+ version: "0.12.57",
17
17
  description: "Datarails App Space CLI \u2014 build, try, push and publish App Space apps",
18
18
  type: "module",
19
19
  engines: {
@@ -57,7 +57,7 @@ var package_default = {
57
57
  };
58
58
 
59
59
  // src/buildInfo.ts
60
- var BUILD_TIME = "2026-10-29T10:06:14.051Z";
60
+ var BUILD_TIME = "2026-11-01T08:07:48.779Z";
61
61
  function formatBuildTime(iso) {
62
62
  if (iso === "") return "";
63
63
  const d = new Date(iso);
@@ -11409,8 +11409,8 @@ function cardOf(element, uid, path3, handlerName, sections, refuse2, parent = nu
11409
11409
  const row = rows2[spec ?? uid];
11410
11410
  const stated2 = Array.isArray(props.params) ? props.params.filter(named5) : [];
11411
11411
  const declared = props.params === void 0 && named5(props.card) && isPlainObject7(row) && isPlainObject7(row.params) ? Object.keys(row.params).filter(named5) : [];
11412
- const params = stated2.length > 0 ? stated2 : declared;
11413
- if (params.length > 0) out.params = params;
11412
+ if (Array.isArray(props.params) || !named5(props.card)) out.params = stated2;
11413
+ else if (declared.length > 0) out.params = declared;
11414
11414
  const kpi = kind === "kpi" || kind === "" && isPlainObject7(row) && row.kind === "kpi";
11415
11415
  let frame2 = isPlainObject7(element.card) ? element.card : {};
11416
11416
  const filledIn = kpi && Object.keys(frame2).every((key) => (key === "title" || key === "subtitle") && frame2[key] === props[key]);
@@ -17726,7 +17726,7 @@ function attrsOf(element) {
17726
17726
  if (card !== "") out.push(["card", card]);
17727
17727
  if (named5(element.emphasis)) out.push(["emphasis", element.emphasis]);
17728
17728
  if (isRuntimeCard(element)) {
17729
- if (Array.isArray(props.params) && props.params.length > 0) out.push(["widget-params", props.params.join(" ")]);
17729
+ if (Array.isArray(props.params)) out.push(["widget-params", props.params.join(" ")]);
17730
17730
  for (const key of RUNTIME_CARD_WORDS) if (named5(props[key])) out.push([`widget-${key}`, props[key]]);
17731
17731
  }
17732
17732
  return gridAttrs(element) + out.map(([key, value]) => ` ${ATTR_NAME.get(key) ?? `data-dr-${key}`}="${attr2(value)}"`).join("");
@@ -19662,8 +19662,8 @@ function assemble(input) {
19662
19662
  did.push(
19663
19663
  `${draftName}: ${cards.length} card(s) on ${path3}` + (merging && kept.length > 0 ? `, beside ${kept.length} already there` : "") + (dropped > 0 ? `, replacing ${dropped}` : "") + (renamed.length > 0 ? `; ids another page already uses: ${renamed.join(", ")}` : "")
19664
19664
  );
19665
- const present = (card) => cards.some((one) => one.id === card.id) || merging && taken.has(ids?.get(`${path3} ${card.id}`) ?? card.id);
19666
- const unbuilt = plan?.cards.filter((card) => !present(card)).map((card) => card.id) ?? [];
19665
+ const present3 = (card) => cards.some((one) => one.id === card.id) || merging && taken.has(ids?.get(`${path3} ${card.id}`) ?? card.id);
19666
+ const unbuilt = plan?.cards.filter((card) => !present3(card)).map((card) => card.id) ?? [];
19667
19667
  if (unbuilt.length > 0) {
19668
19668
  did.push(
19669
19669
  merging ? ` still to come on ${path3}: ${unbuilt.join(", ")}` : ` not in ${draftName}, so not on the page: ${unbuilt.join(", ")}`
@@ -20214,9 +20214,9 @@ function pointAt(dataset, readAs) {
20214
20214
  if (typeof out["read"] === "string" && readAs.has(out["read"])) out["read"] = readAs.get(out["read"]);
20215
20215
  if (Array.isArray(out["steps"])) {
20216
20216
  for (const step of out["steps"]) {
20217
- const classify3 = isObj(step) ? step["classify"] : void 0;
20218
- if (isObj(classify3) && typeof classify3["lookup"] === "string" && readAs.has(classify3["lookup"])) {
20219
- classify3["lookup"] = readAs.get(classify3["lookup"]);
20217
+ const classify5 = isObj(step) ? step["classify"] : void 0;
20218
+ if (isObj(classify5) && typeof classify5["lookup"] === "string" && readAs.has(classify5["lookup"])) {
20219
+ classify5["lookup"] = readAs.get(classify5["lookup"]);
20220
20220
  }
20221
20221
  }
20222
20222
  }
@@ -21975,7 +21975,7 @@ function calcReuseKey(formula, idOf4) {
21975
21975
  const shape = calcSkeleton(formula, idOf4);
21976
21976
  return shape === null ? null : `calc:${shape.skeleton}|${shape.ids.join(",")}`;
21977
21977
  }
21978
- function rowReuseKey(row, byName) {
21978
+ function rowReuseKey(row, byName3) {
21979
21979
  if (row.kind === "BASE") {
21980
21980
  if (row.template === null || row.value_field === null || row.date_field === null || row.aggregator === null) return null;
21981
21981
  return baseReuseKey({
@@ -21988,7 +21988,7 @@ function rowReuseKey(row, byName) {
21988
21988
  filters: row.filters
21989
21989
  });
21990
21990
  }
21991
- if (row.kind === "CALC" && row.formula !== null) return calcReuseKey(row.formula, (name) => byName.get(name)?.id ?? null);
21991
+ if (row.kind === "CALC" && row.formula !== null) return calcReuseKey(row.formula, (name) => byName3.get(name)?.id ?? null);
21992
21992
  return null;
21993
21993
  }
21994
21994
  var METRIC_CREATED_FOOTER = "Created by App Space for the app";
@@ -22138,9 +22138,9 @@ async function planMetrics(contract, t, opts) {
22138
22138
  const catalog = await readCatalog(t);
22139
22139
  const claims = t.claims();
22140
22140
  const credential = credentialOf(claims);
22141
- const byName = new Map(catalog.map((row) => [row.name, row]));
22141
+ const byName3 = new Map(catalog.map((row) => [row.name, row]));
22142
22142
  const byId = new Map(catalog.map((row) => [row.id, row]));
22143
- const rowKeys2 = new Map(catalog.map((row) => [row.id, rowReuseKey(row, byName)]));
22143
+ const rowKeys2 = new Map(catalog.map((row) => [row.id, rowReuseKey(row, byName3)]));
22144
22144
  const usageRead = /* @__PURE__ */ new Map();
22145
22145
  const usageOf = (appId, id) => {
22146
22146
  let held = usageRead.get(id);
@@ -22284,7 +22284,7 @@ async function planMetrics(contract, t, opts) {
22284
22284
  }
22285
22285
  }
22286
22286
  }
22287
- const named13 = byName.get(decl.name);
22287
+ const named13 = byName3.get(decl.name);
22288
22288
  if (entry.reuse_key !== null) {
22289
22289
  const same5 = catalog.filter((row) => rowKeys2.get(row.id) === entry.reuse_key).sort((a, b) => Number(b.name === decl.name) - Number(a.name === decl.name) || (a.created_at ?? "").localeCompare(b.created_at ?? "") || a.id - b.id);
22290
22290
  const hit = same5[0];
@@ -22492,12 +22492,12 @@ async function applyPlan(plan, t, opts) {
22492
22492
  } catch (err) {
22493
22493
  return fail(key, `metric "${key}": Datarails says a metric named "${decl.name}" exists, and the catalog could not be read again to tell whose (${firstLine(err)})`);
22494
22494
  }
22495
- const byName = new Map(again.map((row) => [row.name, row]));
22496
- const holder = byName.get(decl.name);
22495
+ const byName3 = new Map(again.map((row) => [row.name, row]));
22496
+ const holder = byName3.get(decl.name);
22497
22497
  if (holder === void 0) {
22498
22498
  return fail(key, `metric "${key}": a metric named "${decl.name}" exists in this company, but its source tables are not shared with you`);
22499
22499
  }
22500
- if (entry.reuse_key !== null && rowReuseKey(holder, byName) === entry.reuse_key) {
22500
+ if (entry.reuse_key !== null && rowReuseKey(holder, byName3) === entry.reuse_key) {
22501
22501
  entry.action = "reuse";
22502
22502
  entry.origin = "reused";
22503
22503
  entry.metric_id = holder.id;
@@ -22556,7 +22556,7 @@ async function readBack(t, plan, written) {
22556
22556
  )
22557
22557
  ];
22558
22558
  }
22559
- const byName = new Map(catalog.map((row) => [row.name, row]));
22559
+ const byName3 = new Map(catalog.map((row) => [row.name, row]));
22560
22560
  const problems = [];
22561
22561
  for (const entry of written) {
22562
22562
  const label = `"${entry.metric_name ?? entry.name}" (id ${String(entry.metric_id)})`;
@@ -22565,7 +22565,7 @@ async function readBack(t, plan, written) {
22565
22565
  problems.push(problem4("metric_changed", entry.key, `metric "${entry.key}": ${label} is not among this company's metrics you can read, just after this ship wrote it; nothing was pushed`));
22566
22566
  continue;
22567
22567
  }
22568
- const held = rowReuseKey(row, byName);
22568
+ const held = rowReuseKey(row, byName3);
22569
22569
  if (held === null || entry.reuse_key === null) {
22570
22570
  problems.push(
22571
22571
  problem4(
@@ -22867,12 +22867,12 @@ function describeSeeding(result) {
22867
22867
  if (seeded.length === 0) return "";
22868
22868
  const applied = result.seed_links ?? 0;
22869
22869
  const unlinked = result.seed_unlinked ?? 0;
22870
- const present = result.seed_links_present ?? 0;
22871
- const links = applied === 0 && unlinked === 0 && present === 0 ? "" : `, ${String(applied)} link(s)`;
22870
+ const present3 = result.seed_links_present ?? 0;
22871
+ const links = applied === 0 && unlinked === 0 && present3 === 0 ? "" : `, ${String(applied)} link(s)`;
22872
22872
  let out = `seeded: ${seeded.map(([t, n]) => `${t}=${String(n)}`).join(", ")}${links}
22873
22873
  `;
22874
- if (present > 0) {
22875
- out += `${String(present)} link(s) were already in place \u2014 left as they are.
22874
+ if (present3 > 0) {
22875
+ out += `${String(present3)} link(s) were already in place \u2014 left as they are.
22876
22876
  `;
22877
22877
  }
22878
22878
  if (unlinked > 0) {
@@ -25028,6 +25028,131 @@ function checkManifest(app) {
25028
25028
  return violations;
25029
25029
  }
25030
25030
 
25031
+ // ../flows/insights-builder/kit/contract/figures.mjs
25032
+ var APP_COMPUTED = "app_computed";
25033
+ var APP_ROWS = "app_rows";
25034
+ var APP_RECORDS = "app_records";
25035
+ var KINDS = [APP_COMPUTED, APP_ROWS, APP_RECORDS];
25036
+ var FIGURE_PARTS = /* @__PURE__ */ new Set(["widget", "stat", "chart", "callout", "variance_table", "scenario_columns", "progress"]);
25037
+ var ALTERNATIVE = "Get the figure from Datarails instead: a metric (declared in data.metrics), a tier-3 formula (expr over from Datarails reads), or a direct FinanceOS read";
25038
+ var isObject5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
25039
+ var rowsOf = (table) => isObject5(table) ? Object.entries(table).filter(([, row]) => isObject5(row)) : [];
25040
+ var byName = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0;
25041
+ var present = (value) => value !== void 0 && value !== null;
25042
+ function hookName(value) {
25043
+ const name = isObject5(value) ? value.$callable : void 0;
25044
+ return typeof name === "string" && name !== "" ? name.split(".").at(-1) : null;
25045
+ }
25046
+ function transformName(value) {
25047
+ if (typeof value === "string" && value !== "") return value;
25048
+ return hookName(value) ?? "a transform";
25049
+ }
25050
+ function dashboardWhy(row) {
25051
+ if (present(row.compute)) {
25052
+ const name = hookName(row.compute);
25053
+ return name ? `computed by its compute hook ${name}` : "computed by its compute hook";
25054
+ }
25055
+ if (present(row.transform)) return `drawn through ${transformName(row.transform)}`;
25056
+ return null;
25057
+ }
25058
+ function origins(rows2, name, seen = /* @__PURE__ */ new Set()) {
25059
+ if (seen.has(name)) return /* @__PURE__ */ new Set();
25060
+ seen.add(name);
25061
+ const origin = rows2[name]?.from;
25062
+ if (Array.isArray(origin)) {
25063
+ const out = /* @__PURE__ */ new Set();
25064
+ for (const one of origin) if (typeof one === "string") for (const kind of origins(rows2, one, seen)) out.add(kind);
25065
+ return out;
25066
+ }
25067
+ if (isObject5(origin)) {
25068
+ if ("table" in origin) return /* @__PURE__ */ new Set(["app_table"]);
25069
+ if ("financeos" in origin || "call" in origin) return /* @__PURE__ */ new Set(["datarails"]);
25070
+ }
25071
+ return /* @__PURE__ */ new Set();
25072
+ }
25073
+ function appTables(rows2, name, seen = /* @__PURE__ */ new Set()) {
25074
+ if (seen.has(name)) return [];
25075
+ seen.add(name);
25076
+ const origin = rows2[name]?.from;
25077
+ if (isObject5(origin) && typeof origin.table === "string") return [origin.table];
25078
+ const out = [];
25079
+ if (Array.isArray(origin)) {
25080
+ for (const one of origin) {
25081
+ if (typeof one !== "string") continue;
25082
+ for (const table of appTables(rows2, one, seen)) if (!out.includes(table)) out.push(table);
25083
+ }
25084
+ }
25085
+ return out;
25086
+ }
25087
+ function sourceFinding(card, row, rows2, readers) {
25088
+ const figure2 = typeof row.shape === "string" && row.shape !== "rows" || readers.some((part) => FIGURE_PARTS.has(part));
25089
+ const from = origins(rows2, card);
25090
+ const transform = row.transform;
25091
+ if (present(transform) && transform !== false && transform !== "") {
25092
+ const through = transformName(transform);
25093
+ if (from.has("datarails")) {
25094
+ return figure2 ? { card, kind: APP_COMPUTED, why: `drawn through ${through}` } : { card, kind: APP_ROWS, why: `rows shaped by ${through}` };
25095
+ }
25096
+ if (from.size === 1 && from.has("app_table")) {
25097
+ return { card, kind: APP_RECORDS, why: `${through} over ${appTables(rows2, card).join(", ")}, the app's own records` };
25098
+ }
25099
+ return null;
25100
+ }
25101
+ const origin = row.from;
25102
+ if (isObject5(origin) && typeof origin.table === "string" && figure2) {
25103
+ return { card, kind: APP_RECORDS, why: `a figure over ${origin.table}, the app's own records` };
25104
+ }
25105
+ return null;
25106
+ }
25107
+ function classify2({ widgets, sources, summaries, readers } = {}) {
25108
+ const found = [];
25109
+ for (const [card, row] of rowsOf(widgets).sort(byName)) {
25110
+ if (card.startsWith("_")) continue;
25111
+ const why = dashboardWhy(row);
25112
+ if (why !== null) found.push({ card, kind: APP_COMPUTED, why });
25113
+ }
25114
+ const rows2 = Object.fromEntries(rowsOf(sources));
25115
+ for (const [card, row] of Object.entries(rows2).sort(byName)) {
25116
+ const finding = sourceFinding(card, row, rows2, isObject5(readers) && readers[card] || []);
25117
+ if (finding !== null) found.push(finding);
25118
+ }
25119
+ for (const [card, row] of rowsOf(summaries).sort(byName)) {
25120
+ if (row.role !== "summary") continue;
25121
+ const named13 = typeof row.table === "string" ? ` of ${row.table}` : "";
25122
+ found.push({ card, kind: APP_RECORDS, why: `counts and sums${named13}, the app's own records` });
25123
+ }
25124
+ const order2 = (kind) => KINDS.indexOf(kind);
25125
+ return found.sort((a, b) => order2(a.kind) - order2(b.kind) || (a.card < b.card ? -1 : a.card > b.card ? 1 : 0));
25126
+ }
25127
+ function readersOf2(elements) {
25128
+ const out = {};
25129
+ if (!isObject5(elements)) return out;
25130
+ for (const element of Object.values(elements)) {
25131
+ if (!isObject5(element) || typeof element.type !== "string") continue;
25132
+ const props = isObject5(element.props) ? element.props : {};
25133
+ const inner = isObject5(props.props) ? props.props : {};
25134
+ const source = "source" in props ? props.source : inner.source;
25135
+ if (typeof source === "string") (out[source] ??= []).push(element.type);
25136
+ }
25137
+ return out;
25138
+ }
25139
+ function figuresOf(contract) {
25140
+ if (!isObject5(contract)) return [];
25141
+ const data = isObject5(contract.data) ? contract.data : {};
25142
+ const app = isObject5(data.app) ? data.app : {};
25143
+ return classify2({ widgets: data.widgets, sources: data.sources, summaries: app.handlers, readers: readersOf2(contract.elements) });
25144
+ }
25145
+
25146
+ // ../flows/insights-builder/kit/checks/rules/figures.mjs
25147
+ function checkFigures(contract, { handlerWhere = "handlers" } = {}) {
25148
+ const warnings = figuresOf(contract).filter((one) => one.kind === APP_COMPUTED).map((one) => ({
25149
+ rule: "R6.1",
25150
+ where: `${handlerWhere}#SPEC.${one.card}`,
25151
+ message: `"${one.card}" draws a figure the app computes in its own code (${one.why}), not one from Datarails. ${ALTERNATIVE}.`
25152
+ }));
25153
+ return { warnings };
25154
+ }
25155
+
25031
25156
  // ../flows/insights-builder/kit/checks/rules/platform.mjs
25032
25157
  var ID_IN_SOURCE = /\b(?:id|#)\s*:?\s*(\d+)\b/gi;
25033
25158
  var ALIAS_IN_SOURCE = /\balias\s*:?\s*([A-Za-z_][\w-]*)/i;
@@ -25292,6 +25417,9 @@ function verify({ app: appRef, catalog, agent, describe: describe7, load }, { ex
25292
25417
  const liveness2 = checkLiveness(contract, load, {
25293
25418
  handlerWhere: app.handlers[0]?.file || app.handlersSource
25294
25419
  });
25420
+ const figures = checkFigures(contract, {
25421
+ handlerWhere: app.handlers[0]?.file || app.handlersSource
25422
+ });
25295
25423
  const violations = [
25296
25424
  ...checkManifest(app),
25297
25425
  ...checkHandlers(app, frontend.scriptText, frontend.cardHandlers),
@@ -25311,6 +25439,7 @@ function verify({ app: appRef, catalog, agent, describe: describe7, load }, { ex
25311
25439
  return {
25312
25440
  ok: violations.length === 0,
25313
25441
  violations,
25442
+ warnings: figures.warnings.sort(byRuleThenWhere),
25314
25443
  skipped,
25315
25444
  app: { id: appRef.id ?? app.manifest.id, version: appRef.version ?? null },
25316
25445
  kit: KIT.name,
@@ -26728,7 +26857,7 @@ function readPage2(app, page, spec, elements, problems) {
26728
26857
  }
26729
26858
  const significant = [];
26730
26859
  for (const node of tree.nodes) {
26731
- const kind = classify2(node);
26860
+ const kind = classify3(node);
26732
26861
  if (kind !== null) significant.push({ node, ...kind });
26733
26862
  }
26734
26863
  const isSignificant = new Set(significant.map((entry) => entry.node.index));
@@ -26755,7 +26884,7 @@ function readPage2(app, page, spec, elements, problems) {
26755
26884
  const uid = uids.get(node.index);
26756
26885
  const parent = parentOf2.get(node.index);
26757
26886
  const siblings = childrenOf2.get(parent === null ? "root" : parent) ?? [];
26758
- const parentKind = parent === null ? null : classify2(tree.nodes[parent]);
26887
+ const parentKind = parent === null ? null : classify3(tree.nodes[parent]);
26759
26888
  elements[uid] = {
26760
26889
  uid,
26761
26890
  page: page.path,
@@ -26943,7 +27072,7 @@ function ownedIn2(tree) {
26943
27072
  function isDashboardCard2(element) {
26944
27073
  return element?.type === "widget" && typeof element.id === "string";
26945
27074
  }
26946
- function classify2(node) {
27075
+ function classify3(node) {
26947
27076
  if (WIDGET_ATTR2 in node.attrs) return { type: "widget", role: node.attrs[WIDGET_ATTR2 + "-kind"] ?? null };
26948
27077
  if (CONTROL_ATTR2 in node.attrs) return { type: "control", role: node.attrs[CONTROL_ATTR2 + "-kind"] ?? null };
26949
27078
  if (COMPONENT_TYPE_SET2.has(node.attrs[COMPONENT_ATTR3])) return { type: node.attrs[COMPONENT_ATTR3], role: null };
@@ -27029,7 +27158,7 @@ function gridOf3(node, parent, parentKind, uids, siblings, tree) {
27029
27158
  const rows2 = numberAttr2(node, ROWS_ATTR2);
27030
27159
  const inGrid = parentKind !== null && parentKind.type === "grid";
27031
27160
  if (!inGrid && span === null && rows2 === null) return null;
27032
- const cells = inGrid ? siblings.filter((index) => classify2(tree.nodes[index])?.type !== "slot") : [];
27161
+ const cells = inGrid ? siblings.filter((index) => classify3(tree.nodes[index])?.type !== "slot") : [];
27033
27162
  return {
27034
27163
  uid: inGrid ? uids.get(parent) : null,
27035
27164
  position: inGrid ? cells.indexOf(node.index) : null,
@@ -27122,7 +27251,7 @@ function slotsOf2(node, tree) {
27122
27251
  const slots = {};
27123
27252
  const walk5 = (index) => {
27124
27253
  for (const child of tree.nodes[index].children) {
27125
- const kind = classify2(tree.nodes[child]);
27254
+ const kind = classify3(tree.nodes[child]);
27126
27255
  if (kind?.type === "slot") slots[kind.role] = kind.role === "body" ? classesOf3(tree.nodes[child])[0] ?? true : true;
27127
27256
  else walk5(child);
27128
27257
  }
@@ -27934,7 +28063,7 @@ function problem5(at, why, kind = "other") {
27934
28063
  return { at: at || "/", why, kind };
27935
28064
  }
27936
28065
  function describe4(node, ctx) {
27937
- return ctx.inBranch && isObject5(node) && typeof node.description === "string" ? ` \u2014 ${firstSentence3(node.description)}` : "";
28066
+ return ctx.inBranch && isObject6(node) && typeof node.description === "string" ? ` \u2014 ${firstSentence3(node.description)}` : "";
27938
28067
  }
27939
28068
  function firstSentence3(text3) {
27940
28069
  let start = 0;
@@ -27959,7 +28088,7 @@ function truncate5(text3) {
27959
28088
  return `${cut3.join("").replace(/[,;:]+$/u, "")}\u2026`;
27960
28089
  }
27961
28090
  function check3(instance, node, at, root, problems, ctx) {
27962
- if (!isObject5(node)) return;
28091
+ if (!isObject6(node)) return;
27963
28092
  const start = problems.length;
27964
28093
  const hint = describe4(node, ctx);
27965
28094
  if (typeof node.$ref === "string") {
@@ -27997,7 +28126,7 @@ function check3(instance, node, at, root, problems, ctx) {
27997
28126
  if (typeof node.maxLength === "number" && typeof instance === "string" && [...instance].length > node.maxLength) {
27998
28127
  problems.push(problem5(at, `longer than this contract allows${hint}`));
27999
28128
  }
28000
- if (isObject5(instance)) checkObject3(instance, node, at, root, problems, ctx);
28129
+ if (isObject6(instance)) checkObject3(instance, node, at, root, problems, ctx);
28001
28130
  if (Array.isArray(instance)) checkArray3(instance, node, at, root, problems, ctx, hint);
28002
28131
  for (const [keyword, wanted] of [
28003
28132
  ["oneOf", 1],
@@ -28060,15 +28189,15 @@ function shapeMisses3(found, at) {
28060
28189
  function shapes3(branches, root) {
28061
28190
  const named13 = branches.map((branch) => {
28062
28191
  let node = branch;
28063
- for (let hops = 0; isObject5(node) && typeof node.$ref === "string" && hops < 8; hops += 1) {
28192
+ for (let hops = 0; isObject6(node) && typeof node.$ref === "string" && hops < 8; hops += 1) {
28064
28193
  const target = resolve10(node.$ref, root);
28065
28194
  if (target === null) break;
28066
28195
  node = target;
28067
28196
  }
28068
- if (!isObject5(node)) return "a shape";
28069
- const properties = isObject5(node.properties) ? node.properties : {};
28197
+ if (!isObject6(node)) return "a shape";
28198
+ const properties = isObject6(node.properties) ? node.properties : {};
28070
28199
  for (const [name, value] of Object.entries(properties)) {
28071
- if (isObject5(value) && "const" in value) return `{${name}: ${JSON.stringify(value.const)}}`;
28200
+ if (isObject6(value) && "const" in value) return `{${name}: ${JSON.stringify(value.const)}}`;
28072
28201
  }
28073
28202
  if (Array.isArray(node.required) && node.required.length > 0) return `{${node.required.map(String).join(", ")}}`;
28074
28203
  if ("type" in node) return (Array.isArray(node.type) ? node.type : [node.type]).map(String).join(" or ");
@@ -28078,7 +28207,7 @@ function shapes3(branches, root) {
28078
28207
  return `${shown2.join(" | ")}${named13.length > shown2.length ? ` | ${named13.length - shown2.length} more` : ""}`;
28079
28208
  }
28080
28209
  function checkObject3(instance, node, at, root, problems, ctx) {
28081
- const properties = isObject5(node.properties) ? node.properties : {};
28210
+ const properties = isObject6(node.properties) ? node.properties : {};
28082
28211
  for (const name of Array.isArray(node.required) ? node.required : []) {
28083
28212
  if (Object.prototype.hasOwnProperty.call(instance, name)) continue;
28084
28213
  const wanted = Object.prototype.hasOwnProperty.call(properties, name) ? properties[name] : null;
@@ -28092,17 +28221,17 @@ function checkObject3(instance, node, at, root, problems, ctx) {
28092
28221
  }
28093
28222
  const extra = node.additionalProperties ?? true;
28094
28223
  if (extra === false) problems.push(problem5(where2, "not a key this contract carries"));
28095
- else if (isObject5(extra)) check3(value, extra, node["x-tenant-keys"] === true && !ctx.quote ? `${at}/*` : where2, root, problems, ctx);
28224
+ else if (isObject6(extra)) check3(value, extra, node["x-tenant-keys"] === true && !ctx.quote ? `${at}/*` : where2, root, problems, ctx);
28096
28225
  }
28097
28226
  }
28098
28227
  function checkArray3(instance, node, at, root, problems, ctx, hint) {
28099
28228
  if (typeof node.minItems === "number" && instance.length < node.minItems) problems.push(problem5(at, `shorter than this contract allows${hint}`));
28100
- if (isObject5(node.items)) instance.forEach((value, index) => check3(value, node.items, `${at}/${index}`, root, problems, ctx));
28229
+ if (isObject6(node.items)) instance.forEach((value, index) => check3(value, node.items, `${at}/${index}`, root, problems, ctx));
28101
28230
  }
28102
28231
  function isType3(instance, name) {
28103
28232
  switch (name) {
28104
28233
  case "object":
28105
- return isObject5(instance);
28234
+ return isObject6(instance);
28106
28235
  case "array":
28107
28236
  return Array.isArray(instance);
28108
28237
  case "string":
@@ -28128,7 +28257,7 @@ function resolve10(ref, root) {
28128
28257
  let node = root;
28129
28258
  for (const token of ref.slice(2).split("/")) {
28130
28259
  const key = token.replace(/~1/g, "/").replace(/~0/g, "~");
28131
- if (!isObject5(node) || !Object.prototype.hasOwnProperty.call(node, key)) return null;
28260
+ if (!isObject6(node) || !Object.prototype.hasOwnProperty.call(node, key)) return null;
28132
28261
  node = node[key];
28133
28262
  }
28134
28263
  return node;
@@ -28136,7 +28265,7 @@ function resolve10(ref, root) {
28136
28265
  function escape3(name) {
28137
28266
  return String(name).replace(/~/g, "~0").replace(/\//g, "~1");
28138
28267
  }
28139
- function isObject5(value) {
28268
+ function isObject6(value) {
28140
28269
  return typeof value === "object" && value !== null && !Array.isArray(value);
28141
28270
  }
28142
28271
 
@@ -29042,6 +29171,143 @@ function whereOf(binding) {
29042
29171
  return binding?.components?.[0] ?? binding?.reads?.[0] ?? "ui/";
29043
29172
  }
29044
29173
 
29174
+ // ../flows/appspace-builder/kit/contract/figures.mjs
29175
+ var APP_COMPUTED2 = "app_computed";
29176
+ var APP_ROWS2 = "app_rows";
29177
+ var APP_RECORDS2 = "app_records";
29178
+ var KINDS2 = [APP_COMPUTED2, APP_ROWS2, APP_RECORDS2];
29179
+ var FIGURE_PARTS2 = /* @__PURE__ */ new Set(["widget", "stat", "chart", "callout", "variance_table", "scenario_columns", "progress"]);
29180
+ var ALTERNATIVE2 = "Get the figure from Datarails instead: a metric (declared in data.metrics), a tier-3 formula (expr over from Datarails reads), or a direct FinanceOS read";
29181
+ var isObject7 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
29182
+ var rowsOf2 = (table) => isObject7(table) ? Object.entries(table).filter(([, row]) => isObject7(row)) : [];
29183
+ var byName2 = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0;
29184
+ var present2 = (value) => value !== void 0 && value !== null;
29185
+ function hookName2(value) {
29186
+ const name = isObject7(value) ? value.$callable : void 0;
29187
+ return typeof name === "string" && name !== "" ? name.split(".").at(-1) : null;
29188
+ }
29189
+ function transformName2(value) {
29190
+ if (typeof value === "string" && value !== "") return value;
29191
+ return hookName2(value) ?? "a transform";
29192
+ }
29193
+ function dashboardWhy2(row) {
29194
+ if (present2(row.compute)) {
29195
+ const name = hookName2(row.compute);
29196
+ return name ? `computed by its compute hook ${name}` : "computed by its compute hook";
29197
+ }
29198
+ if (present2(row.transform)) return `drawn through ${transformName2(row.transform)}`;
29199
+ return null;
29200
+ }
29201
+ function origins2(rows2, name, seen = /* @__PURE__ */ new Set()) {
29202
+ if (seen.has(name)) return /* @__PURE__ */ new Set();
29203
+ seen.add(name);
29204
+ const origin = rows2[name]?.from;
29205
+ if (Array.isArray(origin)) {
29206
+ const out = /* @__PURE__ */ new Set();
29207
+ for (const one of origin) if (typeof one === "string") for (const kind of origins2(rows2, one, seen)) out.add(kind);
29208
+ return out;
29209
+ }
29210
+ if (isObject7(origin)) {
29211
+ if ("table" in origin) return /* @__PURE__ */ new Set(["app_table"]);
29212
+ if ("financeos" in origin || "call" in origin) return /* @__PURE__ */ new Set(["datarails"]);
29213
+ }
29214
+ return /* @__PURE__ */ new Set();
29215
+ }
29216
+ function appTables2(rows2, name, seen = /* @__PURE__ */ new Set()) {
29217
+ if (seen.has(name)) return [];
29218
+ seen.add(name);
29219
+ const origin = rows2[name]?.from;
29220
+ if (isObject7(origin) && typeof origin.table === "string") return [origin.table];
29221
+ const out = [];
29222
+ if (Array.isArray(origin)) {
29223
+ for (const one of origin) {
29224
+ if (typeof one !== "string") continue;
29225
+ for (const table of appTables2(rows2, one, seen)) if (!out.includes(table)) out.push(table);
29226
+ }
29227
+ }
29228
+ return out;
29229
+ }
29230
+ function sourceFinding2(card, row, rows2, readers) {
29231
+ const figure2 = typeof row.shape === "string" && row.shape !== "rows" || readers.some((part) => FIGURE_PARTS2.has(part));
29232
+ const from = origins2(rows2, card);
29233
+ const transform = row.transform;
29234
+ if (present2(transform) && transform !== false && transform !== "") {
29235
+ const through = transformName2(transform);
29236
+ if (from.has("datarails")) {
29237
+ return figure2 ? { card, kind: APP_COMPUTED2, why: `drawn through ${through}` } : { card, kind: APP_ROWS2, why: `rows shaped by ${through}` };
29238
+ }
29239
+ if (from.size === 1 && from.has("app_table")) {
29240
+ return { card, kind: APP_RECORDS2, why: `${through} over ${appTables2(rows2, card).join(", ")}, the app's own records` };
29241
+ }
29242
+ return null;
29243
+ }
29244
+ const origin = row.from;
29245
+ if (isObject7(origin) && typeof origin.table === "string" && figure2) {
29246
+ return { card, kind: APP_RECORDS2, why: `a figure over ${origin.table}, the app's own records` };
29247
+ }
29248
+ return null;
29249
+ }
29250
+ function classify4({ widgets, sources, summaries, readers } = {}) {
29251
+ const found = [];
29252
+ for (const [card, row] of rowsOf2(widgets).sort(byName2)) {
29253
+ if (card.startsWith("_")) continue;
29254
+ const why = dashboardWhy2(row);
29255
+ if (why !== null) found.push({ card, kind: APP_COMPUTED2, why });
29256
+ }
29257
+ const rows2 = Object.fromEntries(rowsOf2(sources));
29258
+ for (const [card, row] of Object.entries(rows2).sort(byName2)) {
29259
+ const finding = sourceFinding2(card, row, rows2, isObject7(readers) && readers[card] || []);
29260
+ if (finding !== null) found.push(finding);
29261
+ }
29262
+ for (const [card, row] of rowsOf2(summaries).sort(byName2)) {
29263
+ if (row.role !== "summary") continue;
29264
+ const named13 = typeof row.table === "string" ? ` of ${row.table}` : "";
29265
+ found.push({ card, kind: APP_RECORDS2, why: `counts and sums${named13}, the app's own records` });
29266
+ }
29267
+ const order2 = (kind) => KINDS2.indexOf(kind);
29268
+ return found.sort((a, b) => order2(a.kind) - order2(b.kind) || (a.card < b.card ? -1 : a.card > b.card ? 1 : 0));
29269
+ }
29270
+ function readersOf3(elements) {
29271
+ const out = {};
29272
+ if (!isObject7(elements)) return out;
29273
+ for (const element of Object.values(elements)) {
29274
+ if (!isObject7(element) || typeof element.type !== "string") continue;
29275
+ const props = isObject7(element.props) ? element.props : {};
29276
+ const inner = isObject7(props.props) ? props.props : {};
29277
+ const source = "source" in props ? props.source : inner.source;
29278
+ if (typeof source === "string") (out[source] ??= []).push(element.type);
29279
+ }
29280
+ return out;
29281
+ }
29282
+ function figuresOf2(contract) {
29283
+ if (!isObject7(contract)) return [];
29284
+ const data = isObject7(contract.data) ? contract.data : {};
29285
+ const app = isObject7(data.app) ? data.app : {};
29286
+ return classify4({ widgets: data.widgets, sources: data.sources, summaries: app.handlers, readers: readersOf3(contract.elements) });
29287
+ }
29288
+
29289
+ // ../flows/appspace-builder/kit/checks/rules/figures.mjs
29290
+ function checkFigures2(contract) {
29291
+ const violations = [];
29292
+ for (const one of figuresOf2(contract)) {
29293
+ const where2 = `data.sources.${one.card}`;
29294
+ if (one.kind === APP_COMPUTED2) {
29295
+ violations.push({
29296
+ rule: "A4.1",
29297
+ where: where2,
29298
+ message: `source "${one.card}" draws a figure the app computes in its own code (${one.why}), not one from Datarails. ${ALTERNATIVE2}.`
29299
+ });
29300
+ } else if (one.kind === APP_ROWS2) {
29301
+ violations.push({
29302
+ rule: "A4.2",
29303
+ where: where2,
29304
+ message: `source "${one.card}" is ${one.why}, over Datarails reads: filtering and badges are fine, a figure computed there is not \u2014 filter with the read's where or honors, and get a figure from Datarails (a metric, a tier-3 expr, or a direct read).`
29305
+ });
29306
+ }
29307
+ }
29308
+ return { violations };
29309
+ }
29310
+
29045
29311
  // ../flows/appspace-builder/kit/checks/rules/handlers.mjs
29046
29312
  var ROLE_READ = /ctx\.role\b/;
29047
29313
  function checkHandlers2(app, pageText, attributeRefs = /* @__PURE__ */ new Set()) {
@@ -30864,7 +31130,7 @@ function kitFromDisk2() {
30864
31130
  }
30865
31131
  return kitOnDisk2;
30866
31132
  }
30867
- var ADVISORY = /* @__PURE__ */ new Set(["L6", "L7", "L8", "L9", "A1.5", "A1.6", "A2.5", "A2.6", "A3.15", "A3.17", "A3.19", "A3.20", "A3.21", "A3.22", "A3.23", "A3.24", "A3.25", "A3.26", "A3.27", "A3.28", "A3.29"]);
31133
+ var ADVISORY = /* @__PURE__ */ new Set(["A4.1", "A4.2", "L6", "L7", "L8", "L9", "A1.5", "A1.6", "A2.5", "A2.6", "A3.15", "A3.17", "A3.19", "A3.20", "A3.21", "A3.22", "A3.23", "A3.24", "A3.25", "A3.26", "A3.27", "A3.28", "A3.29"]);
30868
31134
  function verify2({ app: appRef }, { extractContract: extractContract2 = extract2, kit } = {}) {
30869
31135
  const KIT = kit ?? kitFromDisk2();
30870
31136
  const app = loadApp2(resolve12(appRef.dir));
@@ -30890,7 +31156,8 @@ function verify2({ app: appRef }, { extractContract: extractContract2 = extract2
30890
31156
  ...levers.violations,
30891
31157
  ...look.violations,
30892
31158
  ...workflow.violations,
30893
- ...ux.violations
31159
+ ...ux.violations,
31160
+ ...checkFigures2(contract).violations
30894
31161
  ];
30895
31162
  const ownedPaths2 = new Set((contract?.pages ?? []).filter((p) => p?.owned === true).map((p) => p.path));
30896
31163
  const ownedPages = app.pages.filter((page2) => ownedPaths2.has(page2.path));
@@ -39483,15 +39750,15 @@ async function checkTarget(dir, force) {
39483
39750
  }
39484
39751
  }
39485
39752
  async function existingFiles(dir, relPaths) {
39486
- const present = [];
39753
+ const present3 = [];
39487
39754
  for (const rel of relPaths) {
39488
39755
  try {
39489
39756
  await stat3(join20(dir, rel));
39490
- present.push(rel);
39757
+ present3.push(rel);
39491
39758
  } catch {
39492
39759
  }
39493
39760
  }
39494
- return present;
39761
+ return present3;
39495
39762
  }
39496
39763
  function shellArg(value) {
39497
39764
  if (/^[A-Za-z0-9._/@:+-]+$/.test(value)) return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarails-ai/dr-appspace-cli",
3
- "version": "0.12.55",
3
+ "version": "0.12.57",
4
4
  "description": "Datarails App Space CLI — build, try, push and publish App Space apps",
5
5
  "type": "module",
6
6
  "engines": {