@nodii/dev 0.6.152 → 0.6.153

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.js CHANGED
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
4
4
  import { homedir, platform } from "node:os";
5
5
  import { dirname, join } from "node:path";
6
6
 
7
- export const VERSION = "0.6.152";
7
+ export const VERSION = "0.6.153";
8
8
  export const configPath = () =>
9
9
  process.env.NODII_DEV_CONFIG_PATH ??
10
10
  join(homedir(), ".config/nodii-dev/config.json");
package/dist/surface.js CHANGED
@@ -564,12 +564,13 @@ export function emitSurface(tree, row, ds) {
564
564
  if (emitted.trimStart().startsWith("{/*")) {
565
565
  throw new CliError("SURFACE_VIEW_NOT_LAID_OUT", `${row.id}: view ${JSON.stringify(variant.name)} has no auto layout, so it would generate as an empty page; give the variant (or the App Frame's mainContent) auto layout in Figma, publish, and refetch`, 1);
566
566
  }
567
- return { state, fn, body: emitted };
567
+ return { state, fn, body: emitted, variant: variant.name };
568
568
  });
569
569
  const component = `${pascal(row.id)}Surface`;
570
570
  const stateType = `${component}State`;
571
571
  const propsType = `${component}Props`;
572
572
  const named = resolveScopes(views, scopes, layers);
573
+ settlePiiColumns(views, unmapped);
573
574
  const data = dataProps(views, propsType);
574
575
  // A prop is optional when every template that draws it lists it in `metadata.optionalProps`.
575
576
  const optionalNames = new Map();
@@ -1795,6 +1796,11 @@ function dataProps(views, propsType) {
1795
1796
  const list = itemList(m.index, m[2]);
1796
1797
  if (list) member(entry(list), m[3]).set("\u0000child", { raw: "ReactNode" });
1797
1798
  }
1799
+ // A lifted row's PII column is PiiText's served pair (cli-140).
1800
+ for (const m of body.matchAll(PII_ROW_READ)) {
1801
+ const list = itemList(m.index, m[1]);
1802
+ if (list) member(entry(list), m[2]).set("\u0000pii", { raw: PII_ROW_FIELD });
1803
+ }
1798
1804
  for (const m of body.matchAll(/(^|>)\s*\{([a-z][A-Za-z0-9]*)\}/gm)) {
1799
1805
  if (JS_LITERALS.has(m[2])) continue;
1800
1806
  entry(m[2]).child = true;
@@ -2426,6 +2432,69 @@ function tabStrip(run, ctx) {
2426
2432
  ].join("\n");
2427
2433
  }
2428
2434
 
2435
+ /**
2436
+ * A lifted row's PII field: PiiText's served pair, as the page's own PiiText takes it
2437
+ * (`value`, `model`, `relation`, and the server's `maskHint` when it sent one). Nothing else of
2438
+ * PiiText's is offered, so a row can never force a value visible (U05; cli-140).
2439
+ */
2440
+ const PII_KINDS = new Set(["name", "email", "phone", "address", "dob", "document", "text"]);
2441
+ const PII_ROW_FIELD = `{ ${["maskHint?", "model", "relation", "value"].map((k) => `${k}: ComponentProps<typeof PiiText>[${JSON.stringify(k.replace("?", ""))}]`).join("; ")} }`;
2442
+ const PII_ROW_READ = /<PiiText value=\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\.value\} kind="/g;
2443
+
2444
+ /**
2445
+ * One list's rows are one type across the views and tables that share it. A column that is
2446
+ * PiiText in one of them and a node in another (two tables whose heads still show Figma's
2447
+ * placeholder, so both are `column1`) can be neither: it stays a node everywhere, as before
2448
+ * cli-140, and the report names it.
2449
+ */
2450
+ function settlePiiColumns(views, unmapped) {
2451
+ const NODE_READ = /(^|>)\s*\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\}/gm;
2452
+ const PII_CELL = />\n[ \t]*<PiiText value=\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\.value\} kind="[^\n]*\/>\n[ \t]*<\/TableCell>/g;
2453
+ const reads = new Map();
2454
+ const count = (view, openers, at, param, key, how) => {
2455
+ const list = listAt(openers, at, param);
2456
+ if (!list) return;
2457
+ const id = `${list}.${key}`;
2458
+ const r = reads.get(id) ?? reads.set(id, { list, key, pii: 0, node: 0, variant: view.variant }).get(id);
2459
+ r[how]++;
2460
+ };
2461
+ for (const view of views) {
2462
+ const openers = listOpeners(view.body);
2463
+ for (const m of view.body.matchAll(PII_ROW_READ)) count(view, openers, m.index, m[1], m[2], "pii");
2464
+ for (const m of view.body.matchAll(NODE_READ)) count(view, openers, m.index, m[2], m[3], "node");
2465
+ }
2466
+ const mixed = new Map([...reads].filter(([, r]) => r.pii && r.node));
2467
+ if (!mixed.size) return;
2468
+ for (const view of views) {
2469
+ const openers = listOpeners(view.body);
2470
+ view.body = view.body.replace(PII_CELL, (all, param, key, at) => (mixed.has(`${listAt(openers, at, param)}.${key}`) ? `>{${param}.${key}}</TableCell>` : all));
2471
+ }
2472
+ for (const r of mixed.values()) {
2473
+ unmapped.push({ variant: r.variant, path: r.list, kind: LIFTED, detail: `column ${r.key} of ${r.list} is PiiText in ${r.pii} of the ${r.pii + r.node} tables that share its rows: it stays a ReactNode, and the page must draw its people through PiiText itself (U05; cli-140)` });
2474
+ }
2475
+ }
2476
+
2477
+ /** The attributes of the PiiText a body cell's template draws as its whole content (Table cell, Content=PII); null for any other cell. */
2478
+ function piiCellAttrs({ code, held }) {
2479
+ const own = (code ?? "").trim();
2480
+ if (held || !/^<TableCell\b/.test(own)) return null;
2481
+ const inner = own.slice(openTagEnd(own) + 1).replace(/<\/TableCell>$/, "").trim();
2482
+ return /^<PiiText\b([^<>]*?)\s*\/>$/.exec(inner)?.[1] ?? null;
2483
+ }
2484
+
2485
+ function piiTreeKind(cell) {
2486
+ const exposed = Object.entries(cell.instance?.exposed ?? {}).find(([name]) => name.toLowerCase() === "piitext")?.[1];
2487
+ return exposed?.props?.kind;
2488
+ }
2489
+
2490
+ /** That cell's PiiText, reading the served pair at `ref` (`row.employee`), with the kind the tree states for it. */
2491
+ function piiCellText({ cell, code }, ref) {
2492
+ const attrs = piiCellAttrs({ code }) ?? "";
2493
+ const kind = piiTreeKind(cell);
2494
+ const size = /\ssize="\w+"/.exec(attrs)?.[0] ?? "";
2495
+ return `<PiiText value={${ref}.value} kind="${kind}" model={${ref}.model} relation={${ref}.relation} maskHint={${ref}.maskHint}${size} />`;
2496
+ }
2497
+
2429
2498
  /**
2430
2499
  * A table a Surface draws as frames: rows of Table-part instances (what the
2431
2500
  * templates emit as TableHead or TableCell). Those parts are valid only inside
@@ -2683,6 +2752,27 @@ function tableOf(node, ctx) {
2683
2752
  // A row is a door to its record when the page passes a handler (U03-7; NODII-DEV-CLI-83).
2684
2753
  const rowClick = mark(ctx, listName, "onRowClick", null);
2685
2754
  ctx.note(ctx.path, LIFTED, `${dataRows.length} body row${dataRows.length === 1 ? "" : "s"} lifted as data: rows of { id, ${keys.join(", ")} } (NODII-DEV-CLI-82)`);
2755
+ // A column whose every body cell is a PiiText is a person's value: its row field is the
2756
+ // served pair and the cell draws PiiText from it, never a node the page could fill with a
2757
+ // raw name (U05; cli-140). A column that is PiiText in only some rows stays a node, and
2758
+ // the report names it.
2759
+ const invalidPii = new Map();
2760
+ const piiColumn = keys.map((key, i) => {
2761
+ const drawn = dataRows.filter((p) => piiCellAttrs(p.cells[i]) !== null).length;
2762
+ if (drawn > 0 && drawn < dataRows.length) ctx.note(ctx.path, LIFTED, `column ${key} is PiiText in ${drawn} of ${dataRows.length} body rows: it stays a ReactNode, and the page must draw its people through PiiText itself (U05; cli-140)`);
2763
+ if (drawn === dataRows.length) {
2764
+ const kinds = dataRows.map((p) => piiTreeKind(p.cells[i].cell));
2765
+ const why = kinds.some((kind) => !PII_KINDS.has(kind))
2766
+ ? `column ${key} has no recognised PiiText kind in one or more body rows`
2767
+ : new Set(kinds).size !== 1 ? `column ${key} has incompatible PiiText kinds` : null;
2768
+ if (why) {
2769
+ ctx.note(ctx.path, "table", `${why}: left unmapped (MW8-17.3; cli-140)`);
2770
+ invalidPii.set(i, why);
2771
+ return false;
2772
+ }
2773
+ }
2774
+ return drawn === dataRows.length;
2775
+ });
2686
2776
  const cells = first.cells.map((c, i) => {
2687
2777
  const w = columnWidth(c.cell);
2688
2778
  let open = `<TableCell${wrapperAttrs(w, first.row)}>`;
@@ -2694,6 +2784,8 @@ function tableOf(node, ctx) {
2694
2784
  open = own.slice(0, end + 1).replace(/\s*\/>$/, ">");
2695
2785
  close = `</${tag}>`;
2696
2786
  }
2787
+ if (invalidPii.has(i)) return indent(`${open}${comment(`unmapped: ${invalidPii.get(i)}`)}${close}`, depth + 4);
2788
+ if (piiColumn[i]) return indent(`${open}\n ${piiCellText(c, `row.${keys[i]}`)}\n${close}`, depth + 4);
2697
2789
  return indent(`${open}{row.${keys[i]}}${close}`, depth + 4);
2698
2790
  });
2699
2791
  return [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.152",
3
+ "version": "0.6.153",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {