@turingcode/cli 0.2.3 → 0.2.5

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.
@@ -49,17 +49,21 @@ function valueOf(v, col, missing) {
49
49
  return v === "true";
50
50
  return v;
51
51
  }
52
- /** Rows of a table keyed by its header; the label is the primary key, or `#n`. */
52
+ /**
53
+ * Rows of a table keyed by its header; the label is the primary key, or `#n`. A row with the wrong
54
+ * number of cells is kept (it still counts, and its values can be referenced), with cells by position.
55
+ */
53
56
  function rowsOf(t, table, name, missing) {
54
57
  const parsed = t.tables.get(name);
55
58
  const key = table ? keyColumns(table) : [];
56
59
  const columns = new Map((table?.columns ?? []).map(c => [c.name, c]));
57
- return parsed.rows.filter(r => r.length === parsed.header.length).map((r, k) => {
58
- const cells = Object.fromEntries(parsed.header.map((h, i) => [h, r[i]]));
60
+ return parsed.rows.map((r, k) => {
61
+ const cells = Object.fromEntries(parsed.header.flatMap((h, i) => (r[i] === undefined ? [] : [[h, r[i]]])));
59
62
  const names = new Set([...parsed.header, ...columns.keys()]);
60
63
  const doc = Object.fromEntries([...names].map(n => [n, valueOf(cells[n], columns.get(n), missing)]));
61
64
  const keyValues = key.map(c => cells[c] ?? "");
62
- return { label: key.length && keyValues.every(v => !missing(v)) ? keyValues.join("/") : `#${k + 1}`, cells, doc };
65
+ const label = key.length && keyValues.every(v => !missing(v)) ? keyValues.join("/") : `#${k + 1}`;
66
+ return { label, cells, doc, shapeError: r.length !== parsed.header.length };
63
67
  });
64
68
  }
65
69
  /**
@@ -140,6 +144,15 @@ export function tableCheck(input) {
140
144
  const tableRows = file?.rows.get(p.table);
141
145
  return column && tableRows ? { rows: tableRows, column } : null;
142
146
  };
147
+ /**
148
+ * Whether a reference points at a table of the checked document that could not be read (missing,
149
+ * or a broken header). Its structure error is already reported, so checks against it are skipped
150
+ * instead of failing every value. Dependency tables are not structure-checked, so they never skip.
151
+ */
152
+ const unread = (ref) => {
153
+ const p = parseRef(ref);
154
+ return !p.alias && !rows.has(p.table);
155
+ };
143
156
  /** Non-missing values (list items split) of a reference. */
144
157
  const refValues = (ref) => {
145
158
  const r = refRows(ref);
@@ -174,11 +187,13 @@ export function tableCheck(input) {
174
187
  };
175
188
  return {
176
189
  ref: (ref, v) => {
190
+ if (unread(ref))
191
+ return true;
177
192
  if (!known.has(ref))
178
193
  known.set(ref, refValues(ref));
179
194
  return known.get(ref).has(v);
180
195
  },
181
- mentioned: (targets, v) => mentions(textOf(targets), v),
196
+ mentioned: (targets, v) => targets.some(t => t !== "*" && unread(t)) || mentions(textOf(targets), v),
182
197
  calc: (param, doc) => evaluateCalc(calc(param), doc, numbers)?.holds ?? true,
183
198
  calcValues: (param, doc) => evaluateCalc(calc(param), doc, numbers),
184
199
  };
@@ -205,7 +220,7 @@ export function tableCheck(input) {
205
220
  continue;
206
221
  const hooks = hooksFor(t, true);
207
222
  for (const col of t.columns.filter(c => c.match)) {
208
- runParts({ [col.name]: col.match }, tableRows, hooks, r => r.doc[col.name] === null || !!badCells.get(r)?.has(col.name), (f, r) => diags.push(diag(f.code, f.message, { table: t.name, row: r.label, column: f.column }, f.found, f.expected)));
223
+ runParts({ [col.name]: col.match }, tableRows, hooks, r => r.shapeError || r.doc[col.name] === null || !!badCells.get(r)?.has(col.name), (f, r) => diags.push(diag(f.code, f.message, { table: t.name, row: r.label, column: f.column }, f.found, f.expected)));
209
224
  }
210
225
  (t.rules ?? []).forEach((rule, i) => checkRule(rule, `${t.name}.rules[${i}]`, t));
211
226
  }
@@ -236,7 +251,7 @@ export function tableCheck(input) {
236
251
  }
237
252
  return;
238
253
  }
239
- runParts(rule.require, matching, hooks, () => false, (f, r) => diags.push(diag(f.code, f.message, { ...where, row: r.label, column: f.column }, f.found, rule.description ?? f.expected, severity)));
254
+ runParts(rule.require, matching, hooks, r => r.shapeError, (f, r) => diags.push(diag(f.code, f.message, { ...where, row: r.label, column: f.column }, f.found, rule.description ?? f.expected, severity)));
240
255
  }
241
256
  }
242
257
  /**
@@ -299,7 +314,7 @@ function checkStructure(c, doc, missing, out) {
299
314
  const tableRows = rowsOf(doc, t, t.name, missing);
300
315
  const key = keyColumns(t);
301
316
  const seenKeys = new Set();
302
- for (const r of tableRows) {
317
+ for (const r of tableRows.filter(row => !row.shapeError)) {
303
318
  const at = (column) => ({ table: t.name, row: r.label, column });
304
319
  for (const col of t.columns.filter(col => header.includes(col.name))) {
305
320
  const v = r.cells[col.name];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turingcode/cli",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Turing Code toolkit for AI agents: check Markdown/CSV tables against table contracts, e.g. `turingcode table check`.",
5
5
  "type": "module",
6
6
  "bin": {