← back to Mfr Review Viewer Corruption

scripts/diagnostics/probe-layout-get-matrix.mjs

32 lines

import { readFileSync, existsSync, writeFileSync } from 'node:fs';
import path from 'node:path'; import os from 'node:os';
const SP='/private/tmp/claude-501/-Users-macstudio3-Projects-mfr-review-viewer-corruption/a26937d9-cc11-4299-9dfb-d661aa523a33/scratchpad';
const FM_PROJECT = path.join(os.homedir(),'Projects','filemaker-mcp');
const FM_ENV = path.join(FM_PROJECT,'.env');
if (existsSync(FM_ENV)) for (const line of readFileSync(FM_ENV,'utf8').split('\n')) { const m=line.match(/^([A-Z_]+)=(.*)$/); if(m&&!process.env[m[1]]) process.env[m[1]]=m[2]; }
process.env.FM_READONLY='1';
const fm = await import('file://'+path.join(FM_PROJECT,'src','fm-client.js'));
const ls = await fm.layouts('WALLPAPER');
const flat=[]; (function walk(a){for(const l of a){ if(l.isFolder) walk(l.folderLayoutNames||[]); else flat.push(l.name);}})(ls);
const uniq=[...new Set(flat)];
const RID='129453';
await fm.getRecord('WALLPAPER','Basic List of Fields',RID); // warm session
const out=[]; let i=0;
async function worker(){
  while(true){ const k=i++; if(k>=uniq.length) return; const lay=uniq[k];
    try { const rec = await fm.getRecord('WALLPAPER', lay, RID);
      const fd=rec?.fieldData||{}; const keys=Object.keys(fd);
      out.push({layout:lay, ok:true, combo:fd['combo sku']??null, series:fd['Series']??null, jsp:fd['JS Pattern']??null, mfr:fd['Mfr Pattern']??null, nFields:keys.length, relatedFields:keys.filter(k=>k.includes('::')), portals:Object.keys(rec?.portalData||{})});
    } catch(e){ out.push({layout:lay, ok:false, code:String(e.fmCode||''), msg:String(e.message).slice(0,100)}); }
  }
}
await Promise.all(Array.from({length:10},worker));
writeFileSync(SP+'/probe1.json', JSON.stringify(out,null,1));
const okr=out.filter(o=>o.ok);
console.log('total',uniq.length,'GET-ok',okr.length);
const codes={}; for(const o of out.filter(x=>!x.ok)) codes[o.code]=(codes[o.code]||0)+1;
console.log('fail codes', JSON.stringify(codes));
const clean=okr.filter(o=>o.relatedFields.length===0&&o.portals.length===0);
console.log('CLEAN (0 related, 0 portals):', clean.length);
console.log(clean.map(c=>`${c.layout} | f=${c.nFields} | combo=${c.combo} | mfr=${c.mfr}`).join('\n'));