techtools

schema.cjs

Текст · 18 рядків

1// Профіль полів вивантажень ERP (R-28). Запуск з кореня: node research/lab/erp-profile/schema.cjs inc.19.10.json mvd.19.10.json sales.19.10.json
2const fs=require('fs');
3for (const f of process.argv.slice(2)) {
4  const j=JSON.parse(fs.readFileSync(f,'utf8').replace(/^/,''));
5  console.log('=== '+f+' top type:', Array.isArray(j)?'array['+j.length+']':Object.keys(j));
6  const stats={};
7  const walk=(v,p)=>{
8    const t=Array.isArray(v)?'array':v===null?'null':typeof v;
9    const s=stats[p]??={types:{},n:0,ex:new Set(),distinct:new Set()};
10    s.n++; s.types[t]=(s.types[t]||0)+1;
11    if(t==='array') v.forEach(x=>walk(x,p+'[]'));
12    else if(t==='object') for(const k in v) walk(v[k],p+'.'+k);
13    else { if(s.distinct.size<2000) s.distinct.add(String(v)); if(s.ex.size<4) s.ex.add(JSON.stringify(v)); }
14  };
15  walk(j,'$');
16  for(const [p,s] of Object.entries(stats)) console.log(p, JSON.stringify(s.types), 'distinct='+(s.distinct.size>=2000?'2000+':s.distinct.size), [...s.ex].join(' | ').slice(0,160));
17}
18