@bicharts/shape-core 0.5.109 → 0.5.111

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/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
2
- import{a as le,b as ce}from"./chunk-UQU75XXR.mjs";import{a as se,b as ae}from"./chunk-3PMDGEN2.mjs";import{A as ne,B as oe,C as ie,D as re,a as Mt,b as _t,c as vt,d as Lt,e as wt,f as Ot,g as Dt,h as zt,i as Gt,j as $t,k as Ft,l as Bt,m as Kt,n as Ht,o as Ut,p as Vt,q as Wt,r as qt,s as Zt,t as Xt,u as jt,v as Yt,w as Jt,x as Qt,y as te,z as ee}from"./chunk-SV3JH46V.mjs";import{a as Nt}from"./chunk-QEH7WTLB.mjs";import{a as kt,b as Et}from"./chunk-2LR73DNS.mjs";import{a as U,b as V,c as Rt,d as St,e as It,f as bt}from"./chunk-OZEOA6ZE.mjs";import{a as R,f as S,g as y,h as I,i as E,j as mt,k as dt,l as H,m,n as gt,o as yt,p as ht,q as b,r as Pt,s as At,t as Ct,u as Tt,v as w,w as xt}from"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import{a as ut,b as ft,c as pt}from"./chunk-N3ZYRMZJ.mjs";import{a as J,b as Q,d as tt,e as et,f as nt,g as ot,h as it,i as rt,j as st,k as at,l as lt,m as ct}from"./chunk-FUTSF2X5.mjs";var O=2,Z=400;function z(r){return!!S(r)}function A(r){let n=new Set;for(let e of r){if(e==null)continue;let s=R(String(e));if(!I(s)&&!n.has(s)&&(n.add(s),n.size>=Z))break}return Array.from(n)}function P(r){let n=A(r);if(n.length===0||G(r)<95)return!1;let e=n.filter(c=>z(c)&&!m(c)).length,s=n.filter(c=>!z(c)&&!!m(c)).length;return e>=1&&e>=s}function W(r,n){if(!m(r))return!1;let e=S(r);return e?n==="world"?!0:H.has(e):!1}function G(r){let n=A(r);if(n.length===0)return 0;let e=0;for(let s of n)z(s)&&e++;return Math.round(e/n.length*1e3)/10}function M(r){let n=A(r);if(n.length===0)return 0;let e=0;for(let s of n)m(s)&&e++;return Math.round(e/n.length*1e3)/10}function F(r){let n=new Set;for(let e of r){if(e==null)continue;let s=String(e).trim();if(!I(R(s))&&!n.has(s)&&(n.add(s),n.size>=Z))break}return Array.from(n)}function $(r){let n=F(r);if(n.length===0)return 0;let e=0;for(let s of n)b(s).length>0&&e++;return Math.round(e/n.length*1e3)/10}function q(r,n){return V(n,U)?!0:F(r).some(e=>/^\d{5}(-\d{4})?$/.test(e.replace(/\.0+$/,"")))}function ue(r,n){let e=A(r);if(e.length===0)return 0;let s=0;for(let c of e)w(c,n)&&s++;return Math.round(s/e.length*1e3)/10}function D(r,n){let e=0;for(let s of A(r))n(s)&&e++;return e}function fe(r,n){let e=0;for(let s of F(r))n(s)&&e++;return e}function pe(r,n,e,s,c){let C=[],u=[],o={},_={},v=new Set(r),l=t=>n.map(i=>i[t]);for(let t of["city","country"]){let i=e?.[t];i&&v.has(i)&&(o[t]=i)}let X=new Set(c??r);for(let t of["lat","lon"]){let i=e?.[t];i&&X.has(i)&&(o[t]=i)}let d=e?.zip;if(d&&v.has(d)){let t=l(d),i=$(t);i<95?u.push(`zip=${d} (only ${i}% of values read as ZIPs)`):q(t,d)?o.zip=d:u.push(`zip=${d} (all values are 3-4 digits with nothing to say they are postal)`)}let p=e?.state;if(p&&v.has(p)){let t=l(p),i=A(t);i.length>0&&i.every(a=>W(a,s))?u.push(`state=${p} (every value is "CA", which is both Canada and California)`):P(t)?(u.push(`state=${p} (every value is a country, not a state)`),o.country||(o.country=p)):M(t)<95?u.push(`state=${p} (only ${M(t)}% of values are states/provinces)`):o.state=p}let g=new Set(Object.values(o).filter(Boolean)),T=r.filter(t=>!g.has(t)&&!t.startsWith("__"));if(!o.state){let t=null;for(let i of T){let a=l(i);if(P(a))continue;let f=M(a);if(f<95)continue;let k=D(a,x=>!!m(x)),Y=D(a,x=>!!m(x)&&!W(x,s));k<O&&Y<1||(!t||f>t.pct)&&(t={name:i,pct:f})}t&&(o.state=t.name,g.add(t.name),C.push(`state=${t.name} (${t.pct}% states/provinces)`))}if(!o.zip)for(let t of T){if(g.has(t))continue;let i=l(t),a=$(i);if(!(a<95)&&q(i,t)&&!(fe(i,f=>b(f).length>0)<O)){o.zip=t,g.add(t),C.push(`zip=${t} (${a}% ZIP codes)`);break}}let h=o.country;if(!h||!P(l(h))){let t=null;for(let i of T){if(g.has(i)||!P(l(i)))continue;let a=G(l(i));(!t||a>t.pct)&&(t={name:i,pct:a})}t&&(h&&(u.push(`country=${h} (only ${G(l(h))}% of values are country identifiers; using ${t.name} instead)`),_.country=h),o.country=t.name,g.add(t.name),C.push(`country=${t.name}`))}if(!o.city){let t=null;for(let i of T){if(g.has(i))continue;let a=l(i),f=ue(a,s);f<E||D(a,k=>w(k,s))<O||(!t||f>t.pct)&&(t={name:i,pct:f})}t&&(o.city=t.name,C.push(`city=${t.name} (${t.pct}% known cities)`))}let B=o.country?l(o.country):[],L=!!o.country&&P(B),j=L?new Set(B.map(t=>S(t==null?null:String(t))).filter(Boolean)).size:0,K=L&&j>=2,N=!!(o.lat&&o.lon)&&n.some(t=>{let i=+String(t[o.lat]??"").trim(),a=+String(t[o.lon]??"").trim();return isFinite(i)&&isFinite(a)&&i>=-90&&i<=90&&a>=-180&&a<=180&&String(t[o.lat]??"").trim()!==""&&String(t[o.lon]??"").trim()!==""});return o.lat&&o.lon&&!N&&u.push(`lat/lon=${o.lat}/${o.lon} (no row holds a usable coordinate pair)`),o.country&&!K&&!(o.city||o.state||o.zip||N)&&u.push(L?`country=${o.country} (every row resolves to the same country - nothing to place apart)`:`country=${o.country} (values are not country identifiers)`),{bind:!!(o.city||o.state||o.zip||K||N)?o:null,backfilled:C,refused:u,...Object.keys(_).length?{labelFallback:_}:{}}}export{E as CITY_ROLE_MATCH_PCT,Xt as DEFAULT_GAP_FACTOR,ot as DEFAULT_TEMPERATURE,et as GET_RANDOM,Ot as INTENSIVE_SUFFIX_TOKENS,wt as INTENSIVE_WORD_TOKENS,re as IndexedText,jt as MAX_RUN_BOUNDS,zt as POSITIONAL_SUFFIX_TOKENS,Dt as POSITIONAL_WORD_TOKENS,le as PREVIEW_OMITTED_FIELDS,y as ROLE_MATCH_PCT,tt as SIMPLE_STRING_HASH,Q as STR,M as admin1MatchPct,Vt as allowedAggregations,bt as buildGeoIsoColumn,Ct as buildGeoPointColumns,xt as cityMatchPct,Tt as cityTagsFor,oe as classifyAdditivity,Ut as classifyForAggregation,ie as classifyNumericValueNature,ee as classifyTemporal,Bt as codeNeedsLegacyAggNames,Ft as collapseRepeatedAggPrefix,vt as countryRegion,Wt as defaultAggregation,Nt as detectFormatSignature,Rt as detectGeo,pt as detectOrdinalDomain,te as detectTextDatePattern,se as engineTypeForSqlType,$t as hasDefaultAggPrefix,ne as hostAggHint,ae as ingest,qt as isAggregationAllowed,I as isBlankLike,dt as isCityTableLoaded,nt as isDeterministicRefusal,Pt as isGeoPointAmbiguity,Qt as isIdentifierName,It as isJoinGeoKind,ut as isOrdinalFriendlyName,lt as localMidnightDateColumns,at as localMidnightToUtcDay,P as looksLikeCountryColumn,Jt as measureCadence,Et as monthLookupFor,Ht as nameLooksIntensiveRate,Kt as nameLooksPositional,J as nameWords,gt as normalizeCountry,ct as normalizeLocalMidnightDates,kt as normalizeMonthKey,R as normalizePlaceName,ht as normalizeZip5,it as parseDateStable,Yt as parseTemporalPoint,ce as payloadPreview,mt as registerCityTable,_t as registerIso3Regions,m as resolveAdmin1,At as resolveGeoPoint,pe as resolvePointRoles,ft as safeDistinctValuesToShip,Zt as shareOfTotalIsHonest,Gt as stripHostAggPrefix,Lt as summarizeCountryRegions,Mt as summarizeGeoExtent,St as toGeoIso,rt as wholeDayFrame,st as wholeDayIso,$ as zipMatchPct,b as zipPrefixCandidates,yt as zipToPrefix3};
2
+ import{a as ce,b as fe}from"./chunk-UQU75XXR.mjs";import{a as le,b as ue}from"./chunk-3PMDGEN2.mjs";import{A as re,B as ie,C as se,D as ae,a as Mt,b as Et,c as vt,d as Ot,e as zt,f as Dt,g as $t,h as Gt,i as Ft,j as Bt,k as Kt,l as Ht,m as Ut,n as Vt,o as Zt,p as Wt,q as qt,r as jt,s as Xt,t as Yt,u as Jt,v as Qt,w as te,x as ee,y as ne,z as oe}from"./chunk-SV3JH46V.mjs";import{a as Lt}from"./chunk-QEH7WTLB.mjs";import{a as kt,b as Nt}from"./chunk-2LR73DNS.mjs";import{a as V,b as Z,c as Tt,d as _t,e as wt,f as It}from"./chunk-OZEOA6ZE.mjs";import{a as P,f as x,g as y,h as T,i as L,j as mt,k as yt,l as U,m as p,n as ht,o as Rt,p as Ct,q as _,r as bt,s as St,t as At,u as Pt,v as k,w as xt}from"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import{a as dt,b as pt,c as gt}from"./chunk-N3ZYRMZJ.mjs";import{a as tt,b as et,d as nt,e as ot,f as rt,g as it,h as st,i as at,j as lt,k as ut,l as ct,m as ft}from"./chunk-FUTSF2X5.mjs";var N=2,j=400;function D(o){return!!x(o)}function C(o){let e=new Set;for(let n of o){if(n==null)continue;let s=P(String(n));if(!T(s)&&!e.has(s)&&(e.add(s),e.size>=j))break}return Array.from(e)}function R(o){let e=C(o);if(e.length===0||$(o)<95)return!1;let n=e.filter(u=>D(u)&&!p(u)).length,s=e.filter(u=>!D(u)&&!!p(u)).length;return n>=1&&n>=s}function W(o,e){if(!p(o))return!1;let n=x(o);return n?e==="world"?!0:U.has(n):!1}function $(o){let e=C(o);if(e.length===0)return 0;let n=0;for(let s of e)D(s)&&n++;return Math.round(n/e.length*1e3)/10}function w(o){let e=C(o);if(e.length===0)return 0;let n=0;for(let s of e)p(s)&&n++;return Math.round(n/e.length*1e3)/10}function F(o){let e=new Set;for(let n of o){if(n==null)continue;let s=String(n).trim();if(!T(P(s))&&!e.has(s)&&(e.add(s),e.size>=j))break}return Array.from(e)}function G(o){let e=F(o);if(e.length===0)return 0;let n=0;for(let s of e)_(s).length>0&&n++;return Math.round(n/e.length*1e3)/10}function q(o,e){return Z(e,V)?!0:F(o).some(n=>/^\d{5}(-\d{4})?$/.test(n.replace(/\.0+$/,"")))}function de(o,e){let n=C(o);if(n.length===0)return 0;let s=0;for(let u of n)k(u,e)&&s++;return Math.round(s/n.length*1e3)/10}function z(o,e){let n=0;for(let s of C(o))e(s)&&n++;return n}function pe(o,e){let n=0;for(let s of F(o))e(s)&&n++;return n}function ge(o,e,n,s,u){let b=[],c=[],r={},I={},M=new Set(o),l=t=>e.map(i=>i[t]);for(let t of["city","country"]){let i=n?.[t];i&&M.has(i)&&(r[t]=i)}let Y=new Set(u??o);for(let t of["lat","lon"]){let i=n?.[t];i&&Y.has(i)&&(r[t]=i)}let g=n?.zip;if(g&&M.has(g)){let t=l(g),i=G(t);i<95?c.push(`zip=${g} (only ${i}% of values read as ZIPs)`):q(t,g)?r.zip=g:c.push(`zip=${g} (all values are 3-4 digits with nothing to say they are postal)`)}let d=n?.state;if(d&&M.has(d)){let t=l(d),i=C(t);i.length>0&&i.every(a=>W(a,s))?c.push(`state=${d} (every value is "CA", which is both Canada and California)`):R(t)?(c.push(`state=${d} (every value is a country, not a state)`),r.country||(r.country=d)):w(t)<95?c.push(`state=${d} (only ${w(t)}% of values are states/provinces)`):r.state=d}let m=new Set(Object.values(r).filter(Boolean)),S=o.filter(t=>!m.has(t)&&!t.startsWith("__"));if(!r.state){let t=null;for(let i of S){let a=l(i);if(R(a))continue;let f=w(a);if(f<95)continue;let O=z(a,A=>!!p(A)),Q=z(a,A=>!!p(A)&&!W(A,s));O<N&&Q<1||(!t||f>t.pct)&&(t={name:i,pct:f})}t&&(r.state=t.name,m.add(t.name),b.push(`state=${t.name} (${t.pct}% states/provinces)`))}if(!r.zip)for(let t of S){if(m.has(t))continue;let i=l(t),a=G(i);if(!(a<95)&&q(i,t)&&!(pe(i,f=>_(f).length>0)<N)){r.zip=t,m.add(t),b.push(`zip=${t} (${a}% ZIP codes)`);break}}let h=r.country;if(!h||!R(l(h))){let t=null;for(let i of S){if(m.has(i)||!R(l(i)))continue;let a=$(l(i));(!t||a>t.pct)&&(t={name:i,pct:a})}t&&(h&&(c.push(`country=${h} (only ${$(l(h))}% of values are country identifiers; using ${t.name} instead)`),I.country=h),r.country=t.name,m.add(t.name),b.push(`country=${t.name}`))}if(!r.city){let t=null;for(let i of S){if(m.has(i))continue;let a=l(i),f=de(a,s);f<L||z(a,O=>k(O,s))<N||(!t||f>t.pct)&&(t={name:i,pct:f})}t&&(r.city=t.name,b.push(`city=${t.name} (${t.pct}% known cities)`))}let K=r.country?l(r.country):[],E=!!r.country&&R(K),J=E?new Set(K.map(t=>x(t==null?null:String(t))).filter(Boolean)).size:0,H=E&&J>=2,v=!!(r.lat&&r.lon)&&e.some(t=>{let i=+String(t[r.lat]??"").trim(),a=+String(t[r.lon]??"").trim();return isFinite(i)&&isFinite(a)&&i>=-90&&i<=90&&a>=-180&&a<=180&&String(t[r.lat]??"").trim()!==""&&String(t[r.lon]??"").trim()!==""});return r.lat&&r.lon&&!v&&c.push(`lat/lon=${r.lat}/${r.lon} (no row holds a usable coordinate pair)`),r.country&&!H&&!(r.city||r.state||r.zip||v)&&c.push(E?`country=${r.country} (every row resolves to the same country - nothing to place apart)`:`country=${r.country} (values are not country identifiers)`),{bind:!!(r.city||r.state||r.zip||H||v)?r:null,backfilled:b,refused:c,...Object.keys(I).length?{labelFallback:I}:{}}}var me=/^[A-Za-z_$][A-Za-z0-9_$]*$/,ye=o=>o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),he=new RegExp([String.raw`\bisMeasure\b`,String.raw`\bdataType\b`,String.raw`\bcolumns\s*\[\s*-?\d`,String.raw`\.iloc\s*\[[^\]]*,`,String.raw`\.iat\s*\[`,String.raw`\bselect_dtypes\b`,String.raw`\b_get_numeric_data\b`,String.raw`\bis_numeric_dtype\b`,String.raw`\bfor\s+\w+\s+in\s+(?:list\s*\(\s*)?df\.columns\b`,String.raw`\bdf\.columns\s*\.\s*(?:tolist|to_list|difference|drop)\b`,String.raw`\bdf\.dtypes\b`,String.raw`\bObject\s*\.\s*(?:keys|values|entries)\s*\(\s*(?:rows|data|df)?\s*\[\s*0\s*\]`,String.raw`\b(?:row|rw|r)\s*\[\s*\d+\s*\]`].join("|"));function B(o,e){if(!o||!e)return!1;let n=ye(e);return new RegExp("['\"`]"+n+"['\"`]").test(o)?!0:me.test(e)&&new RegExp("\\."+n+"(?![A-Za-z0-9_$])").test(o)}function X(o){return!!o&&he.test(o)}function Re(o,e,n){return o?X(o)?[...e]:[...n,...e].some(s=>B(o,s))?e.filter(s=>B(o,s)):[...e]:[]}export{L as CITY_ROLE_MATCH_PCT,Yt as DEFAULT_GAP_FACTOR,it as DEFAULT_TEMPERATURE,ot as GET_RANDOM,Dt as INTENSIVE_SUFFIX_TOKENS,zt as INTENSIVE_WORD_TOKENS,ae as IndexedText,Jt as MAX_RUN_BOUNDS,Gt as POSITIONAL_SUFFIX_TOKENS,$t as POSITIONAL_WORD_TOKENS,ce as PREVIEW_OMITTED_FIELDS,y as ROLE_MATCH_PCT,nt as SIMPLE_STRING_HASH,et as STR,w as admin1MatchPct,Wt as allowedAggregations,It as buildGeoIsoColumn,At as buildGeoPointColumns,xt as cityMatchPct,Pt as cityTagsFor,ie as classifyAdditivity,Zt as classifyForAggregation,se as classifyNumericValueNature,oe as classifyTemporal,Ht as codeNeedsLegacyAggNames,B as codeReadsColumn,X as codeReadsColumnsByRoleOrPosition,Kt as collapseRepeatedAggPrefix,Re as columnsTheCodeReads,vt as countryRegion,qt as defaultAggregation,Lt as detectFormatSignature,Tt as detectGeo,gt as detectOrdinalDomain,ne as detectTextDatePattern,le as engineTypeForSqlType,Bt as hasDefaultAggPrefix,re as hostAggHint,ue as ingest,jt as isAggregationAllowed,T as isBlankLike,yt as isCityTableLoaded,rt as isDeterministicRefusal,bt as isGeoPointAmbiguity,ee as isIdentifierName,wt as isJoinGeoKind,dt as isOrdinalFriendlyName,ct as localMidnightDateColumns,ut as localMidnightToUtcDay,R as looksLikeCountryColumn,te as measureCadence,Nt as monthLookupFor,Vt as nameLooksIntensiveRate,Ut as nameLooksPositional,tt as nameWords,ht as normalizeCountry,ft as normalizeLocalMidnightDates,kt as normalizeMonthKey,P as normalizePlaceName,Ct as normalizeZip5,st as parseDateStable,Qt as parseTemporalPoint,fe as payloadPreview,mt as registerCityTable,Et as registerIso3Regions,p as resolveAdmin1,St as resolveGeoPoint,ge as resolvePointRoles,pt as safeDistinctValuesToShip,Xt as shareOfTotalIsHonest,Ft as stripHostAggPrefix,Ot as summarizeCountryRegions,Mt as summarizeGeoExtent,_t as toGeoIso,at as wholeDayFrame,lt as wholeDayIso,G as zipMatchPct,_ as zipPrefixCandidates,Rt as zipToPrefix3};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Does `code` read the column `name` by name? A quoted string literal of the exact name, or a
3
+ * member access `.name` when the name is a plain identifier. Empty code reads nothing.
4
+ */
5
+ export declare function codeReadsColumn(code: string | null | undefined, name: string): boolean;
6
+ /** Does `code` pick any column by role, type or position, where a name test cannot see the use? */
7
+ export declare function codeReadsColumnsByRoleOrPosition(code: string | null | undefined): boolean;
8
+ /**
9
+ * The subset of `goneNames` (in their original order) that `code` may depend on - the columns a
10
+ * drift warning can truthfully say will draw blank. `writtenFor` is every column the code was
11
+ * written against; the gone ones may be included or not.
12
+ *
13
+ * Empty code gives none. Code that reads columns by role or position, or that names none of the
14
+ * columns it was written for, gives all of them. Otherwise only the names the code reads by name.
15
+ */
16
+ export declare function columnsTheCodeReads(code: string | null | undefined, goneNames: readonly string[], writtenFor: readonly string[]): string[];
@@ -27,3 +27,4 @@ export { ingest, engineTypeForSqlType } from "./ingest";
27
27
  export type { DataSource, IngestOptions, IngestResult, ColumnDescriptor, SqlColumnMeta, EngineDataType, } from "./ingest";
28
28
  export { payloadPreview, PREVIEW_OMITTED_FIELDS } from "./payloadPreview";
29
29
  export type { PayloadPreviewOptions } from "./payloadPreview";
30
+ export { codeReadsColumn, codeReadsColumnsByRoleOrPosition, columnsTheCodeReads } from "./codeColumnReads";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bicharts/shape-core",
3
- "version": "0.5.109",
3
+ "version": "0.5.111",
4
4
  "description": "Host-agnostic data-shape profiler: ingest a dataset's rows through IValueCollection.addRow and read back the measured shape as an LLMColumnWithValue[] payload — types, cardinality, temporal/ordinal detection, geographic region and point resolution, cross-column signals. MEASUREMENT only: the policy that decides what a measured shape means for chart selection lives server-side.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",