@bicharts/shape-core 0.6.0 → 0.6.1
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 +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/wire.d.ts +35 -0
- package/package.json +1 -1
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 dt,b as gt}from"./chunk-UQU75XXR.mjs";import{a as mt,b as pt}from"./chunk-IJXTU62R.mjs";import{A as
|
|
2
|
+
import{a as dt,b as gt}from"./chunk-UQU75XXR.mjs";import{a as mt,b as pt}from"./chunk-IJXTU62R.mjs";import{A as rt,B as it,C as st,D as at,E as ut,F as lt,G as ct,I as ft,a as we,b as ke,c as _e,d as De,e as Ee,f as Fe,g as Oe,h as ze,i as $e,j as He,k as Be,l as Ke,m as Ue,n as We,o as Ve,p as je,q as qe,r as Ze,s as Xe,t as Je,u as Ye,v as Qe,w as et,x as tt,y as nt,z as ot}from"./chunk-TDTXRIHS.mjs";import{a as Ge}from"./chunk-QEH7WTLB.mjs";import{a as Le,b as Ne}from"./chunk-2LR73DNS.mjs";import{a as W,b as V,c as be,d as Me,e as ve,f as Ie}from"./chunk-OZEOA6ZE.mjs";import{a as b,f as M,g as C,h as v,i as L,j as ge,k as ye,l as U,m as d,n as Ce,o as he,p as Se,q as I,r as xe,s as Pe,t as Te,u as Ae,v as N,w as Re}from"./chunk-E6SVTFAW.mjs";import"./chunk-5MRZID36.mjs";import{a as me,b as pe,c as de}from"./chunk-DMLWYEQ2.mjs";import{a as te,b as ne,d as G,e as oe,f as re,g as ie,h as se,i as ae,j as ue,k as le,l as ce,m as fe}from"./chunk-FUTSF2X5.mjs";var E=2,Z=400;function O(o){return!!M(o)}function P(o){let e=new Set;for(let t of o){if(t==null)continue;let i=b(String(t));if(!v(i)&&!e.has(i)&&(e.add(i),e.size>=Z))break}return Array.from(e)}function x(o){let e=P(o);if(e.length===0||z(o)<95)return!1;let t=e.filter(c=>O(c)&&!d(c)).length,i=e.filter(c=>!O(c)&&!!d(c)).length;return t>=1&&t>=i}function j(o,e){if(!d(o))return!1;let t=M(o);return t?e==="world"?!0:U.has(t):!1}function z(o){let e=P(o);if(e.length===0)return 0;let t=0;for(let i of e)O(i)&&t++;return Math.round(t/e.length*1e3)/10}function w(o){let e=P(o);if(e.length===0)return 0;let t=0;for(let i of e)d(i)&&t++;return Math.round(t/e.length*1e3)/10}function H(o){let e=new Set;for(let t of o){if(t==null)continue;let i=String(t).trim();if(!v(b(i))&&!e.has(i)&&(e.add(i),e.size>=Z))break}return Array.from(e)}function $(o){let e=H(o);if(e.length===0)return 0;let t=0;for(let i of e)I(i).length>0&&t++;return Math.round(t/e.length*1e3)/10}function q(o,e){return V(e,W)?!0:H(o).some(t=>/^\d{5}(-\d{4})?$/.test(t.replace(/\.0+$/,"")))}function yt(o,e){let t=P(o);if(t.length===0)return 0;let i=0;for(let c of t)N(c,e)&&i++;return Math.round(i/t.length*1e3)/10}function F(o,e){let t=0;for(let i of P(o))e(i)&&t++;return t}function Ct(o,e){let t=0;for(let i of H(o))e(i)&&t++;return t}function ht(o,e,t,i,c){let u=[],a=[],r={},T={},h=new Set(o),f=n=>e.map(s=>s[n]);for(let n of["city","country"]){let s=t?.[n];s&&h.has(s)&&(r[n]=s)}let Y=new Set(c??o);for(let n of["lat","lon"]){let s=t?.[n];s&&Y.has(s)&&(r[n]=s)}let g=t?.zip;if(g&&h.has(g)){let n=f(g),s=$(n);s<95?a.push(`zip=${g} (only ${s}% of values read as ZIPs)`):q(n,g)?r.zip=g:a.push(`zip=${g} (all values are 3-4 digits with nothing to say they are postal)`)}let p=t?.state;if(p&&h.has(p)){let n=f(p),s=P(n);s.length>0&&s.every(l=>j(l,i))?a.push(`state=${p} (every value is "CA", which is both Canada and California)`):x(n)?(a.push(`state=${p} (every value is a country, not a state)`),r.country||(r.country=p)):w(n)<95?a.push(`state=${p} (only ${w(n)}% of values are states/provinces)`):r.state=p}let y=new Set(Object.values(r).filter(Boolean)),A=o.filter(n=>!y.has(n)&&!n.startsWith("__"));if(!r.state){let n=null;for(let s of A){let l=f(s);if(x(l))continue;let m=w(l);if(m<95)continue;let D=F(l,R=>!!d(R)),ee=F(l,R=>!!d(R)&&!j(R,i));D<E&&ee<1||(!n||m>n.pct)&&(n={name:s,pct:m})}n&&(r.state=n.name,y.add(n.name),u.push(`state=${n.name} (${n.pct}% states/provinces)`))}if(!r.zip)for(let n of A){if(y.has(n))continue;let s=f(n),l=$(s);if(!(l<95)&&q(s,n)&&!(Ct(s,m=>I(m).length>0)<E)){r.zip=n,y.add(n),u.push(`zip=${n} (${l}% ZIP codes)`);break}}let S=r.country;if(!S||!x(f(S))){let n=null;for(let s of A){if(y.has(s)||!x(f(s)))continue;let l=z(f(s));(!n||l>n.pct)&&(n={name:s,pct:l})}n&&(S&&(a.push(`country=${S} (only ${z(f(S))}% of values are country identifiers; using ${n.name} instead)`),T.country=S),r.country=n.name,y.add(n.name),u.push(`country=${n.name}`))}if(!r.city){let n=null;for(let s of A){if(y.has(s))continue;let l=f(s),m=yt(l,i);m<L||F(l,D=>N(D,i))<E||(!n||m>n.pct)&&(n={name:s,pct:m})}n&&(r.city=n.name,u.push(`city=${n.name} (${n.pct}% known cities)`))}let B=r.country?f(r.country):[],k=!!r.country&&x(B),Q=k?new Set(B.map(n=>M(n==null?null:String(n))).filter(Boolean)).size:0,K=k&&Q>=2,_=!!(r.lat&&r.lon)&&e.some(n=>{let s=+String(n[r.lat]??"").trim(),l=+String(n[r.lon]??"").trim();return isFinite(s)&&isFinite(l)&&s>=-90&&s<=90&&l>=-180&&l<=180&&String(n[r.lat]??"").trim()!==""&&String(n[r.lon]??"").trim()!==""});return r.lat&&r.lon&&!_&&a.push(`lat/lon=${r.lat}/${r.lon} (no row holds a usable coordinate pair)`),r.country&&!K&&!(r.city||r.state||r.zip||_)&&a.push(k?`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||K||_)?r:null,backfilled:u,refused:a,...Object.keys(T).length?{labelFallback:T}:{}}}function X(o,e){let t=e?.freemiumMaxShapeColumns;return typeof t!="number"||!isFinite(t)||t<1?null:!isFinite(o)||o<=t?0:Math.round(o-t)}function St(o,e,t){let i=X(o,e);if(i===null||i<=0)return null;let c=typeof e?.freemiumColumnCapPivot=="number"?e.freemiumColumnCapPivot:4,u=i>c?e?.freemiumColumnCapMessageMany:e?.freemiumColumnCapMessageFew;if(typeof u!="string"||u.trim().length===0)return null;let a=u.split("{n}").join(String(i)).split("{fields}").join(i===1?"field":"fields"),r=J(t);return r.length===0?a:a+" "+r.join(" ")}function J(o){if(!o||o.length===0)return[];let e=[],t=new Map,i=new Map;for(let u of o){let a=typeof u?.dateGroupId=="string"?u.dateGroupId.trim():"";if(a!==""&&(t.has(a)||(e.push(a),t.set(a,0)),u.isDatePart===!0&&t.set(a,t.get(a)+1),u.isReassembledDate===!0&&!i.has(a))){let r=typeof u.sourceField=="string"?u.sourceField.trim():"",T=typeof u.name=="string"?u.name.trim():"",h=r!==""?r:T;h!==""&&i.set(a,h)}}let c=[];for(let u of e){let a=i.get(u),r=t.get(u)??0;!a||r===0||c.push(`'${a}' is a date hierarchy and counts as ${r+1} fields - bind the date itself instead of its hierarchy.`)}return c}function xt(o,e){if(typeof e!="function")throw new TypeError("encodePayload needs the host's gzip function");return Pt(e(JSON.stringify(o))).replace(/\//g,".")}function Pt(o){let e="";for(let i=0;i<o.length;i+=32768)e+=String.fromCharCode(...o.subarray(i,i+32768));return btoa(e)}function Tt(o){if(typeof o!="string"||o==="")throw new TypeError("keyedSigner needs the host's signing key");return{sign:e=>String(G(e+o))}}function At(o,e){let t=e.sign(o);if(typeof t!="string"||t.trim()==="")throw new TypeError("the host's signer returned a blank signature");return t}function Rt(o,e){if(o==null||typeof o!="object")return;let t=o,i=t[e];return i??t[e.charAt(0).toUpperCase()+e.slice(1)]}export{L as CITY_ROLE_MATCH_PCT,tt as DEFAULT_GAP_FACTOR,ie as DEFAULT_TEMPERATURE,oe as GET_RANDOM,Fe as INTENSIVE_SUFFIX_TOKENS,Ee as INTENSIVE_WORD_TOKENS,ft as IndexedText,nt as MAX_RUN_BOUNDS,ze as POSITIONAL_SUFFIX_TOKENS,Oe as POSITIONAL_WORD_TOKENS,dt as PREVIEW_OMITTED_FIELDS,C as ROLE_MATCH_PCT,G as SIMPLE_STRING_HASH,ne as STR,w as admin1MatchPct,qe as allowedAggregations,Ie as buildGeoIsoColumn,Te as buildGeoPointColumns,Re as cityMatchPct,Ae as cityTagsFor,lt as classifyAdditivity,je as classifyForAggregation,ct as classifyNumericValueNature,at as classifyTemporal,Ke as codeNeedsLegacyAggNames,Ye as codeReadsColumn,Qe as codeReadsColumnsByRoleOrPosition,Be as collapseRepeatedAggPrefix,et as columnsTheCodeReads,_e as countryRegion,Ze as defaultAggregation,Ge as detectFormatSignature,be as detectGeo,de as detectOrdinalDomain,st as detectTextDatePattern,xt as encodePayload,mt as engineTypeForSqlType,Ue as englishImplicitAggNames,St as freemiumColumnCapRefusal,X as freemiumColumnsOverCap,J as freemiumDateHierarchyClauses,He as hasDefaultAggPrefix,ut as hostAggHint,pt as ingest,Xe as isAggregationAllowed,v as isBlankLike,ye as isCityTableLoaded,re as isDeterministicRefusal,xe as isGeoPointAmbiguity,it as isIdentifierName,ve as isJoinGeoKind,me as isOrdinalFriendlyName,Tt as keyedSigner,ce as localMidnightDateColumns,le as localMidnightToUtcDay,x as looksLikeCountryColumn,rt as measureCadence,At as messageSignature,Ne as monthLookupFor,Ve as nameLooksIntensiveRate,We as nameLooksPositional,te as nameWords,Ce as normalizeCountry,fe as normalizeLocalMidnightDates,Le as normalizeMonthKey,b as normalizePlaceName,Se as normalizeZip5,se as parseDateStable,ot as parseTemporalPoint,gt as payloadPreview,Rt as readWireField,ge as registerCityTable,ke as registerIso3Regions,d as resolveAdmin1,Pe as resolveGeoPoint,ht as resolvePointRoles,pe as safeDistinctValuesToShip,Je as shareOfTotalIsHonest,$e as stripHostAggPrefix,De as summarizeCountryRegions,we as summarizeGeoExtent,Me as toGeoIso,ae as wholeDayFrame,ue as wholeDayIso,$ as zipMatchPct,I as zipPrefixCandidates,he as zipToPrefix3};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -31,3 +31,5 @@ export { codeReadsColumn, codeReadsColumnsByRoleOrPosition, columnsTheCodeReads
|
|
|
31
31
|
export { freemiumColumnsOverCap, freemiumColumnCapRefusal, freemiumDateHierarchyClauses } from "./freemiumCaps";
|
|
32
32
|
export type { FreemiumColumnCapStatus, FreemiumDateGroupColumn } from "./freemiumCaps";
|
|
33
33
|
export type { WireSigner, WireTransport, WireResponse, CredentialTriple, CredentialSource, ViewportSource, Clock, DiagnosticEntry, DiagnosticsSink, RendererId, WireServices, } from "./host/services";
|
|
34
|
+
export { encodePayload, keyedSigner, messageSignature, readWireField } from "./wire";
|
|
35
|
+
export type { GzipText } from "./wire";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { WireSigner } from "./host/services";
|
|
2
|
+
/**
|
|
3
|
+
* Gzip one string (the request's JSON) to bytes. The HOST passes its compressor, and that is
|
|
4
|
+
* deliberate rather than a missing dependency: two gzip implementations at the same level emit
|
|
5
|
+
* different - equally valid - byte streams for the same text, and each host's requests stay
|
|
6
|
+
* byte-identical to what it sent before this function existed only if it keeps its own. The
|
|
7
|
+
* server inflates any valid gzip.
|
|
8
|
+
*/
|
|
9
|
+
export type GzipText = (text: string) => Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* JSON -> gzip -> base64 -> '/' to '.'. The body every signed request sends.
|
|
12
|
+
*
|
|
13
|
+
* `gzip` is required: a request that silently went out uncompressed would fail to inflate on
|
|
14
|
+
* the server and read as a network fault.
|
|
15
|
+
*/
|
|
16
|
+
export declare function encodePayload(payload: unknown, gzip: GzipText): string;
|
|
17
|
+
/**
|
|
18
|
+
* The signer every host builds: the shared 53-bit FNV-1a hash over the encoded body with the
|
|
19
|
+
* host's key appended, as a decimal string. The key is the host's to hold - each keeps it out
|
|
20
|
+
* of plain text in its own way - and this package never sees it except as an argument.
|
|
21
|
+
*/
|
|
22
|
+
export declare function keyedSigner(key: string): WireSigner;
|
|
23
|
+
/**
|
|
24
|
+
* The signature header value for an already-encoded body. Throws when the signer returns
|
|
25
|
+
* anything but a non-blank string: a well-formed-looking signature that every request fails
|
|
26
|
+
* on reads as a network fault, which is far harder to diagnose than this throw.
|
|
27
|
+
*/
|
|
28
|
+
export declare function messageSignature(encodedBody: string, signer: WireSigner): string;
|
|
29
|
+
/**
|
|
30
|
+
* A response field read in either casing. The server may serialise camelCase or PascalCase,
|
|
31
|
+
* so `readWireField(data, "errorMessage")` returns `data.errorMessage` and falls back to
|
|
32
|
+
* `data.ErrorMessage` when the camel form is absent or null. A null or non-object `data`
|
|
33
|
+
* reads as absent.
|
|
34
|
+
*/
|
|
35
|
+
export declare function readWireField(data: unknown, camelName: string): any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bicharts/shape-core",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
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",
|