@platforma-sdk/model 1.27.10 → 1.28.0

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.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var ke=Object.defineProperty;var je=(t,e,n)=>e in t?ke(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var L=(t,e,n)=>je(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@milaboratories/pl-model-common"),k=require("zod"),le=require("@milaboratories/pl-error-like");class de extends Error{constructor(e,n){super(`${e.length}${n?"+":""} errors, first error: `+e[0].message),this.errors=e,this.moreErrors=n}}function fe(t){if(!t.ok)throw new de(t.errors,t.moreErrors);return t.value}function Ve(t){return new Proxy(t,{get(e,n){return fe(e[n])}})}function v(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||t===null?$(t):t}function N(t){return{type:"GetFromCtx",variable:t}}function Ne(t){return{type:"Isolate",cfg:t}}const Ke=N("$args"),Be=N("$it"),Ue=N("$prod"),Je=N("$staging"),Me=N("$ui");function $(t){return{type:"Immediate",value:t}}function ae(t){const e={};for(const[n,r]of Object.entries(t))e[n]=v(r);return{type:"MakeObject",template:e}}function $e(...t){const e=[];for(const n of t)e.push(v(n));return{type:"MakeArray",template:e}}function W(t,e){return{type:"GetJsonField",source:v(t),field:v(e)}}function Ge(t,e,n="$it"){return{type:"MapRecordValues",source:t,mapping:e,itVar:n}}function We(t,e,n="$it"){return{type:"MapArrayValues",source:t,mapping:e,itVar:n}}function He(t){return{type:"Flatten",source:t}}function ze(t){return{type:"IsEmpty",arg:t}}function qe(t){return{type:"Not",operand:t}}function Ye(t,e){return{type:"And",operand1:t,operand2:e}}function Xe(t,e){return{type:"Or",operand1:t,operand2:e}}function Qe(t,e){return{type:"GetResourceField",source:v(t),field:v(e)}}function Ze(){return function(t){return{type:"GetResourceValueAsJson",source:v(t)}}}function et(t,e,n="$it"){return{type:"MapResourceFields",source:t,mapping:e,itVar:n}}function tt(t){return{type:"GetBlobContent",source:v(t)}}function nt(t){return{type:"GetBlobContentAsString",source:v(t)}}function rt(){return function(t){return{type:"GetBlobContentAsJson",source:v(t)}}}function st(t){return{type:"GetDownloadedBlobContent",source:v(t)}}function it(t){return{type:"GetOnDemandBlobContent",source:v(t)}}function ot(t,e){return{type:"ExtractArchiveAndGetURL",format:e,source:v(t)}}function at(t){return{type:"GetImportProgress",source:v(t)}}function lt(t,e){return{type:"GetLastLogs",source:v(t),lines:e}}function ut(t,e){return{type:"GetProgressLog",source:v(t),patternToSearch:e}}function ct(t,e){return{type:"GetProgressLogWithInfo",source:v(t),patternToSearch:e}}function pt(t){return{type:"GetLogHandle",source:v(t)}}function dt(){return typeof globalThis.getPlatforma<"u"||typeof globalThis.platforma<"u"}function he(t){if(t&&typeof globalThis.getPlatforma=="function")return globalThis.getPlatforma(t);if(typeof globalThis.platforma<"u")return globalThis.platforma;throw new Error("Can't get platforma instance.")}function ft(){if(typeof globalThis.cfgRenderCtx<"u")return globalThis.cfgRenderCtx}function g(){if(typeof globalThis.cfgRenderCtx<"u")return globalThis.cfgRenderCtx;throw new Error("Not in config rendering context")}function X(t,e){const n=ft();if(n===void 0)return!1;if(t in n.callbackRegistry)throw new Error(`Callback with key ${t} already registered.`);return n.callbackRegistry[t]=e,!0}const te=new Map;function ht(t,e){t in g().callbackRegistry||(g().callbackRegistry[t]=n=>{for(const r of te.get(t))r(n)},te.set(t,[])),te.get(t).push(e)}class I{constructor(e,n=r=>r){L(this,"isResolved",!1);L(this,"resolvedValue");this.handle=e,this.postProcess=n,ht(e,r=>{this.resolvedValue=n(r),this.isResolved=!0})}map(e){return new I(this.handle,n=>e(this.postProcess(n)))}mapDefined(e){return new I(this.handle,n=>{const r=this.postProcess(n);return r?e(r):void 0})}toJSON(){return this.isResolved?this.resolvedValue:{__awaited_futures__:[this.handle]}}}function Z(t,e){return t===void 0?void 0:e(t)}class _{constructor(e,n){this.handle=e,this.resolvePath=n}resolve(...e){const n=e.map(r=>({assertFieldType:"Input",...typeof r=="string"?{field:r}:r}));return this.resolveWithCommon({},...n)}resolveOutput(...e){const n=e.map(r=>({assertFieldType:"Output",...typeof r=="string"?{field:r}:r}));return this.resolveWithCommon({},...n)}resolveInput(...e){const n=e.map(r=>({assertFieldType:"Input",...typeof r=="string"?{field:r}:r}));return this.resolveWithCommon({},...n)}resolveAny(...e){return this.resolveWithCommon({},...e)}resolveWithCommon(e,...n){const r=[...this.resolvePath,...n.map(i=>typeof i=="string"?i:i.field)];return Z(g().resolveWithCommon(this.handle,e,...n),i=>new _(i,r))}get resourceType(){return g().getResourceType(this.handle)}getInputsLocked(){return g().getInputsLocked(this.handle)}getOutputsLocked(){return g().getOutputsLocked(this.handle)}getIsReadyOrError(){return g().getIsReadyOrError(this.handle)}getIsFinal(){return g().getIsFinal(this.handle)}getError(){const e=[...this.resolvePath,"error"];return Z(g().getError(this.handle),n=>new _(n,e))}listInputFields(){return g().listInputFields(this.handle)}listOutputFields(){return g().listOutputFields(this.handle)}listDynamicFields(){return g().listDynamicFields(this.handle)}getKeyValueBase64(e){return g().getKeyValueBase64(this.handle,e)}getKeyValueAsString(e){return g().getKeyValueAsString(this.handle,e)}getKeyValueAsJson(e){const n=this.getKeyValueAsString(e);if(n==null)throw new Error("Resource has no content.");return JSON.parse(n)}getDataBase64(){return g().getDataBase64(this.handle)}getDataAsString(){return g().getDataAsString(this.handle)}getDataAsJson(){const e=this.getDataAsString();if(e==null)throw new Error("Resource has no content.");return JSON.parse(e)}getPColumns(e=!1,n=""){const r=this.parsePObjectCollection(e,n);return r===void 0?void 0:Object.entries(r).map(([,s])=>{if(!p.isPColumn(s))throw new Error(`not a PColumn (kind = ${s.spec.kind})`);return s})}parsePObjectCollection(e=!1,n=""){const r=g().parsePObjectCollection(this.handle,e,n,...this.resolvePath);if(r===void 0)return;const i={};for(const[s,o]of Object.entries(r)){const a=[...this.resolvePath,s];i[s]=p.mapPObjectData(o,c=>new _(c,a))}return i}getFileContentAsBase64(){return new I(g().getBlobContentAsBase64(this.handle))}getFileContentAsString(){return new I(g().getBlobContentAsString(this.handle))}getFileContentAsJson(){return new I(g().getBlobContentAsString(this.handle)).mapDefined(e=>JSON.parse(e))}getBlobContentAsBase64(){return this.getFileContentAsBase64()}getBlobContentAsString(){return this.getFileContentAsString()}getFileHandle(){return new I(g().getDownloadedBlobContentHandle(this.handle))}getDownloadedBlobHandle(){return this.getFileHandle()}getRemoteFileHandle(){return new I(g().getOnDemandBlobContentHandle(this.handle))}getOnDemandBlobHandle(){return this.getRemoteFileHandle()}extractArchiveAndGetURL(e){return new I(g().extractArchiveAndGetURL(this.handle,e))}getImportProgress(){return new I(g().getImportProgress(this.handle))}getLastLogs(e){return new I(g().getLastLogs(this.handle,e))}getProgressLog(e){return new I(g().getProgressLog(this.handle,e))}getProgressLogWithInfo(e){return new I(g().getProgressLogWithInfo(this.handle,e))}getLogHandle(){return new I(g().getLogHandle(this.handle))}allFieldsResolved(e="Input"){switch(e){case"Input":return this.getInputsLocked()&&this.listInputFields().every(n=>this.resolve({field:n,assertFieldType:"Input"})!==void 0);case"Output":return this.getOutputsLocked()&&this.listOutputFields().every(n=>this.resolve({field:n,assertFieldType:"Output"})!==void 0)}}mapFields(e,n){const{fieldType:r,requireLocked:i,skipUnresolved:s}={fieldType:"Input",requireLocked:!0,skipUnresolved:!1,...n},o=e;if(i&&(r==="Input"&&!this.getInputsLocked()||r==="Output"&&!this.getOutputsLocked()))return;let c=(r==="Input"?this.listInputFields():r==="Output"?this.listOutputFields():this.listDynamicFields()).map(l=>[l,this.resolve({field:l,assertFieldType:r})]);return s&&(c=c.filter(l=>l[1]!==void 0)),c.map(([l,y])=>o(l,y))}}const ge="staging",me="main",gt={explicitColumnsSupport:!0,inlineColumnsSupport:!0,activeArgs:!0};function ye(t){return typeof t=="object"&&t!==null&&"__awaited_futures__"in t}function re(t,e,n){if(e.has(n))return;if(e.add(n),typeof n==="object")if(ye(n))n.__awaited_futures__.forEach(i=>t.add(i));else if(Array.isArray(n))for(const i of n)re(t,e,i);else for(const[,i]of Object.entries(n))i!==n&&re(t,e,i)}function mt(t){const e=new Set;return re(e,new Set,t),e}const yt=Object.freeze(Object.defineProperty({__proto__:null,GlobalCfgRenderCtxFeatureFlags:gt,MainAccessorName:me,StagingAccessorName:ge,getAllFutureAwaits:mt,isFutureAwait:ye},Symbol.toStringTag,{value:"Module"})),be="pl7.app/label",ve="pl7.app/trace",Ae=k.z.object({type:k.z.string(),importance:k.z.number().optional(),id:k.z.string().optional(),label:k.z.string()}),Pe=k.z.array(Ae),bt=.001,vt="__LABEL__",ue="__LABEL__@1";function se(t,e,n={}){const r=new Map,i=new Map,s=t.map(h=>{var O,F;const d=e(h);let f,b,m;"spec"in d&&typeof d.spec=="object"?(f=d.spec,b=d.prefixTrace,m=d.suffixTrace):f=d;const A=(O=f.annotations)==null?void 0:O[be],P=(F=f.annotations)==null?void 0:F[ve],w=(P?Pe.safeParse(JSON.parse(P)).data:void 0)??[],T=[...b??[],...w,...m??[]];if(A){const x={label:A,type:vt,importance:-2};n.addLabelAsSuffix?T.push(x):T.splice(0,0,x)}const C=[],R=new Map;for(let x=T.length-1;x>=0;--x){const{type:K}=T[x],B=T[x].importance??0,U=(R.get(K)??0)+1;R.set(K,U);const J=`${K}@${U}`;i.set(J,(i.get(J)??0)+1),r.set(J,Math.max(r.get(J)??Number.NEGATIVE_INFINITY,B-(T.length-x)*bt)),C.push({...T[x],fullType:J,occurenceIndex:U})}return C.reverse(),{value:h,spec:f,label:A,fullTrace:C}}),o=[],a=[],c=[...r];c.sort(([,h],[,d])=>d-h);for(const[h]of c)h.endsWith("@1")||i.get(h)===t.length?o.push(h):a.push(h);const l=h=>s.map(d=>{const f=d.fullTrace.filter(m=>h.has(m.fullType)).map(m=>m.label),b=n.separator??" / ";return{label:f.join(b),value:d.value}});if(o.length===0){if(a.length!==0)throw new Error("Assertion error.");return l(new Set(ue))}let y=0,u=0;for(;y<o.length;){const h=new Set;n.includeNativeLabel&&h.add(ue);for(let f=0;f<y;++f)h.add(o[f]);h.add(o[u]);const d=l(h);if(new Set(d.map(f=>f.label)).size===t.length)return d;u++,u==o.length&&(y++,u=y)}return l(new Set([...o,...a]))}const Y="PColumnData/",H=Y+"ResourceMap",z=Y+"Partitioned/ResourceMap",j=Y+"JsonPartitioned",D=Y+"BinaryPartitioned",we=Y+"Partitioned/",q=we+"JsonPartitioned",V=we+"BinaryPartitioned";function Ie(t,e,n,r=[],i){if(t===void 0)return!1;switch(t.resourceType.name){case H:{let s=t.getInputsLocked();for(const o of t.listInputFields()){const a=t.resolve({field:o,assertFieldType:"Input"}),c=[...r,...JSON.parse(o)],l=a===void 0?void 0:e(a);l===void 0&&(s=!1),(l!==void 0||i)&&n.push({key:c,value:l})}return s}case z:{let s=t.getInputsLocked();for(const o of t.listInputFields()){const a=t.resolve({field:o,assertFieldType:"Input"});if(a===void 0)s=!1;else{const c=[...r,...JSON.parse(o)],l=Ie(a,e,n,c,i);s=s&&l}}return s}default:throw new Error(`Unknown resource type: ${t.resourceType.name}`)}}function At(t,e,n=!1){const r=[];return{isComplete:Ie(t,e,r,[],n),data:r}}const ie=t=>{if(t.endsWith(".index"))return{baseKey:t.substring(0,t.length-6),type:"index"};if(t.endsWith(".values"))return{baseKey:t.substring(0,t.length-7),type:"values"};throw new Error(`key must ends on .index/.values for binary p-column, got: ${t}`)};function xe(t){if(!t)return;const e=t.resourceType.name,n=t.getDataAsJson(),r=[];let i=0;switch(e){case H:i=n.keyLength;break;case z:i=n.partitionKeyLength+n.keyLength;break;case j:case D:i=n.partitionKeyLength;break;case V:case q:i=n.superPartitionKeyLength+n.partitionKeyLength;break}switch(e){case H:case j:case D:for(let s of t.listInputFields()){e===D&&(s=ie(s).baseKey);const o=[...JSON.parse(s)];r.push(o)}break;case z:case V:case q:for(const s of t.listInputFields()){const o=[...JSON.parse(s)],a=t.resolve({field:s,assertFieldType:"Input"});if(a!==void 0)for(let c of a.listInputFields()){e===V&&(c=ie(c).baseKey);const l=[...o,...JSON.parse(c)];r.push(l)}}break}return{data:r,keyLength:i}}function Se(t){const e=xe(t);if(!e)return;const{data:n,keyLength:r}=e,i=[];for(let s=0;s<r;++s)i.push(new Set);for(const s of n){if(s.length!==r)throw new Error("key length does not match partition length");for(let o=0;o<r;++o)i[o].add(s[o])}return i.map(s=>Array.from(s.values()))}function ee(t,e=[]){if(t===void 0)return;const n=t.resourceType.name,r=t.getDataAsJson();if(e.length>0&&(n===q||n===V))throw new Error(`Unexpected nested super-partitioned resource: ${n}`);switch(n){case H:case z:throw new Error(`Only data columns are supported, got: ${n}`);case j:{if(typeof(r==null?void 0:r.partitionKeyLength)!="number")throw new Error(`Missing partitionKeyLength in metadata for ${n}`);const i=[];for(const s of t.listInputFields()){const o=t.resolve({field:s,assertFieldType:"Input"});if(o===void 0)return;const a=[...e,...JSON.parse(s)];i.push({key:a,value:o})}return{type:"JsonPartitioned",partitionKeyLength:r.partitionKeyLength,parts:i}}case D:{if(typeof(r==null?void 0:r.partitionKeyLength)!="number")throw new Error(`Missing partitionKeyLength in metadata for ${n}`);const i=[],s=new Map;for(const o of t.listInputFields()){const a=ie(o),c=t.resolve({field:o,assertFieldType:"Input"});if(c===void 0)return;let l=s.get(a.baseKey);l||(l={},s.set(a.baseKey,l)),a.type==="index"?l.index=c:l.values=c}for(const[o,a]of s.entries()){if(!a.index||!a.values)return;const c=[...e,...JSON.parse(o)];i.push({key:c,value:{index:a.index,values:a.values}})}return{type:"BinaryPartitioned",partitionKeyLength:r.partitionKeyLength,parts:i}}case q:{if(typeof(r==null?void 0:r.superPartitionKeyLength)!="number"||typeof(r==null?void 0:r.partitionKeyLength)!="number")throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${n}`);const i=r.superPartitionKeyLength+r.partitionKeyLength,s=[];for(const o of t.listInputFields()){const a=t.resolve({field:o,assertFieldType:"Input"});if(a===void 0)return;if(a.resourceType.name!==j)throw new Error(`Expected ${j} inside ${n}, but got ${a.resourceType.name}`);const c=ee(a,JSON.parse(o));if(c===void 0)return;if(c.type!=="JsonPartitioned")throw new Error(`Unexpected inner result type for ${n}: ${c.type}`);s.push(...c.parts)}return{type:"JsonPartitioned",partitionKeyLength:i,parts:s}}case V:{if(typeof(r==null?void 0:r.superPartitionKeyLength)!="number"||typeof(r==null?void 0:r.partitionKeyLength)!="number")throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${n}`);const i=r.superPartitionKeyLength+r.partitionKeyLength,s=[];for(const o of t.listInputFields()){const a=t.resolve({field:o,assertFieldType:"Input"});if(a===void 0)return;if(a.resourceType.name!==D)throw new Error(`Expected ${D} inside ${n}, but got ${a.resourceType.name}`);const c=ee(a,JSON.parse(o));if(c===void 0)return;if(c.type!=="BinaryPartitioned")throw new Error(`Unexpected inner result type for ${n}: ${c.type}`);s.push(...c.parts)}return{type:"BinaryPartitioned",partitionKeyLength:i,parts:s}}default:throw new Error(`Unknown resource type: ${n}`)}}function _e(t,e){const n=[...e].sort((s,o)=>o[0]-s[0]);if(t.type==="JsonPartitioned"||t.type==="BinaryPartitioned"){const{partitionKeyLength:s}=t;for(const[o]of e)if(o>=s)throw new Error(`Can't filter on non-partitioned axis ${o}. Must be >= ${s}`)}else if(t.type==="Json"){const{keyLength:s}=t;for(const[o]of e)if(o>=s)throw new Error(`Can't filter on non-data axis ${o}. Must be >= ${s}`)}const r=s=>{for(const[o,a]of n)if(s[o]!==a)return!1;return!0},i=s=>{const o=[...s];for(const[a]of n)o.splice(a,1);return o};switch(t.type){case"Json":{const s=t.data.filter(o=>r(o.key)).map(o=>({key:i(o.key),value:o.value}));return{type:"Json",keyLength:t.keyLength-e.length,data:s}}case"JsonPartitioned":{const s=t.parts.filter(o=>r(o.key)).map(o=>({key:i(o.key),value:o.value}));return{type:"JsonPartitioned",partitionKeyLength:t.partitionKeyLength-e.length,parts:s}}case"BinaryPartitioned":{const s=t.parts.filter(o=>r(o.key)).map(o=>({key:i(o.key),value:o.value}));return{type:"BinaryPartitioned",partitionKeyLength:t.partitionKeyLength-e.length,parts:s}}}}function ne(t,e){if(t===void 0)return e===void 0;if(e===void 0)return!0;for(const n in e)if(t[n]!==e[n])return!1;return!0}function ce(t){return p.mapPObjectData(t,e=>e instanceof _?e.handle:p.isDataInfo(e)?p.mapDataInfo(e,n=>n.handle):e)}function Pt(t){if(t)return t.map(e=>({type:`split:${p.canonicalizeAxisId(e.axisId)}`,label:e.label,importance:1e6}))}function wt(t){if(t)return t.map(e=>[e.axisIdx,e.value])}class Ce{constructor(){L(this,"ctx",g())}calculateOptions(e){return this.ctx.calculateOptions(e)}getOptions(e,n){const r=typeof e=="function"?e:p.selectorsToPredicate(e),i=this.getSpecs().entries.filter(s=>r(s.obj));return typeof n=="object"||typeof n>"u"?se(i,s=>s.obj,n??{}).map(({value:{ref:s},label:o})=>({ref:s,label:o})):i.map(s=>({ref:s.ref,label:n(s.obj,s.ref)}))}getUniversalPColumnEntries(e,n,r){const i={};if(!(e instanceof p.AnchoredIdDeriver))for(const[l,y]of Object.entries(e))if(p.isPlRef(y)){const u=this.getPColumnSpecByRef(y);if(!u)return;i[l]=u}else i[l]=y;const s=typeof n=="function"?[n]:Array.isArray(n)?n:[n],o=e instanceof p.AnchoredIdDeriver?e:new p.AnchoredIdDeriver(i),a=[];for(const l of s){const y=typeof l=="function"?l:p.selectorsToPredicate(p.resolveAnchors(i,l)),u=this.getSpecs().entries.filter(({obj:d})=>p.isPColumnSpec(d)?y(d):!1);if(u.length===0)continue;const h=typeof l=="object"&&"axes"in l&&l.axes!==void 0&&l.partialAxesMatch===void 0?l.axes.map((d,f)=>"split"in d&&d.split===!0?f:-1).filter(d=>d!==-1):[];if(h.sort((d,f)=>d-f),h.length>0){const d=h[h.length-1];for(const{ref:f,obj:b}of u){if(!p.isPColumnSpec(b))throw new Error(`Assertion failed: expected PColumnSpec, got ${b.kind}`);const m=this.getDataByRef(f);if(!m){if(r!=null&&r.dontWaitAllData)continue;return}if(!p.isPColumn(m))throw new Error(`Assertion failed: expected PColumn, got ${m.spec.kind}`);const A=Se(m.data);if(!A){if(r!=null&&r.dontWaitAllData)continue;return}if(d>=A.length)throw new Error(`Not enough partition keys for the requested split axes in column ${b.name}`);const P=h.map(C=>this.findLabels(p.getAxisId(b.axesSpec[C]))),w=[],T=(C,R)=>{if(R>=h.length){w.push([...C]);return}const O=h[R],F=A[O];for(const x of F)C.push(x),T(C,R+1),C.pop()};T([],0);for(const C of w){const R=C.map((O,F)=>{const x=h[F],K=p.getAxisId(b.axesSpec[x]),B=P[F],U=(B==null?void 0:B[O])??String(O);return{axisIdx:x,axisId:K,value:O,label:U}});a.push({obj:b,ref:f,axisFilters:R})}}}else for(const{ref:d,obj:f}of u)p.isPColumnSpec(f)&&a.push({obj:f,ref:d})}return a.length===0?[]:se(a,l=>({spec:l.obj,suffixTrace:Pt(l.axisFilters)}),(r==null?void 0:r.labelOps)??{}).map(l=>({id:o.deriveS(l.value.obj,wt(l.value.axisFilters)),obj:l.value.obj,ref:l.value.ref,axisFilters:l.value.axisFilters,label:l.label}))}getAnchoredPColumns(e,n,r){const i={...r,labelOps:{includeNativeLabel:!0,...(r==null?void 0:r.labelOps)||{}}},s=this.getUniversalPColumnEntries(e,n,i);if(!s||s.length===0)return;const o=[];for(const a of s){const c=this.getPColumnByRef(a.ref);if(!c)return;const l=ee(c.data);if(!l)return;let y=l,u={...c.spec};if(a.axisFilters&&a.axisFilters.length>0){const d=a.axisFilters.map(m=>[m.axisIdx,m.value]);y=_e(l,d);const f=[...a.axisFilters].map(m=>m.axisIdx).sort((m,A)=>A-m),b=[...u.axesSpec];for(const m of f)b.splice(m,1);u={...u,axesSpec:b}}const h=p.entriesToDataInfo(y);u.annotations?u={...u,annotations:{...u.annotations,"pl7.app/label":a.label}}:u={...u,annotations:{"pl7.app/label":a.label}},o.push({id:a.id,spec:u,data:h})}return o}getCanonicalOptions(e,n,r){const i=this.getUniversalPColumnEntries(e,n,r);if(i)return i.map(s=>({value:s.id,label:s.label}))}getDataFromResultPool(){return this.getData()}getData(){const e=this.ctx.getDataFromResultPool();return{isComplete:e.isComplete,entries:e.entries.map(n=>({ref:n.ref,obj:{...n.obj,data:new _(n.obj.data,[n.ref.blockId,n.ref.name])}}))}}getDataWithErrorsFromResultPool(){return this.getDataWithErrors()}getDataWithErrors(){const e=this.ctx.getDataWithErrorsFromResultPool();return{isComplete:e.isComplete,entries:e.entries.map(n=>({ref:n.ref,obj:{...n.obj,data:p.mapValueInVOE(n.obj.data,r=>new _(r,[n.ref.blockId,n.ref.name]))}}))}}getSpecsFromResultPool(){return this.getSpecs()}getSpecs(){return this.ctx.getSpecsFromResultPool()}getDataByRef(e){var r;if(typeof this.ctx.getDataFromResultPoolByRef>"u")return(r=this.getData().entries.find(i=>i.ref.blockId===e.blockId&&i.ref.name===e.name))==null?void 0:r.obj;const n=this.ctx.getDataFromResultPoolByRef(e.blockId,e.name);if(n)return p.mapPObjectData(n,i=>new _(i,[e.blockId,e.name]))}getPColumnByRef(e){const n=this.getDataByRef(e);if(n)return p.ensurePColumn(n)}getPColumnSpecByRef(e){const n=this.getSpecByRef(e);if(n){if(!p.isPColumnSpec(n))throw new Error(`not a PColumn spec (kind = ${n.kind})`);return n}}getSpecByRef(e){return this.ctx.getSpecFromResultPoolByRef(e.blockId,e.name)}findDataWithCompatibleSpec(e){const n=[];e:for(const r of this.getData().entries){if(!p.isPColumnSpec(r.obj.spec))continue;const i=r.obj.spec;if(e.name===i.name&&e.valueType===i.valueType&&e.axesSpec.length===i.axesSpec.length&&ne(e.domain,i.domain)){for(let s=0;s<e.axesSpec.length;++s){const o=e.axesSpec[s],a=i.axesSpec[s];if(o.name!==a.name||o.type!==a.type||!ne(o.domain,a.domain))continue e}n.push(r.obj)}}return n}findLabels(e){const n=this.getData();for(const r of n.entries){if(!p.isPColumn(r.obj))continue;const i=r.obj.spec;if(i.name==="pl7.app/label"&&i.axesSpec.length===1&&i.axesSpec[0].name===e.name&&i.axesSpec[0].type===e.type&&ne(e.domain,i.axesSpec[0].domain)){if(r.obj.data.resourceType.name!=="PColumnData/Json")throw Error(`Expected JSON column for labels, got: ${r.obj.data.resourceType.name}`);return Object.fromEntries(Object.entries(r.obj.data.getDataAsJson().data).map(o=>[JSON.parse(o[0])[0],o[1]]))}}}}class M{constructor(){L(this,"ctx");L(this,"args");L(this,"uiState");L(this,"_activeArgsCache");L(this,"resultPool",new Ce);this.ctx=g(),this.args=JSON.parse(this.ctx.args),this.uiState=this.ctx.uiState!==void 0?JSON.parse(this.ctx.uiState):{}}get activeArgs(){return this._activeArgsCache===void 0&&(this._activeArgsCache={v:this.ctx.activeArgs?JSON.parse(this.ctx.activeArgs):void 0}),this._activeArgsCache.v}getNamedAccessor(e){return Z(this.ctx.getAccessorHandleByName(e),n=>new _(n,[e]))}get prerun(){return this.getNamedAccessor(ge)}get outputs(){return this.getNamedAccessor(me)}findLabels(e){return this.resultPool.findLabels(e)}verifyInlineAndExplicitColumnsSupport(e){var i;const n=e.some(s=>!(s.data instanceof _)||p.isDataInfo(s.data)),r=((i=this.ctx.featureFlags)==null?void 0:i.inlineColumnsSupport)===!0;if(n&&!r)throw Error("Inline or explicit columns not supported")}createPFrame(e){return this.verifyInlineAndExplicitColumnsSupport(e),this.ctx.createPFrame(e.map(n=>ce(n)))}createPTable(e){let n;return"columns"in e?n={src:{type:"full",entries:e.columns.map(r=>({type:"column",column:r}))},filters:e.filters??[],sorting:e.sorting??[]}:n=e,this.verifyInlineAndExplicitColumnsSupport(p.extractAllColumns(n.src)),this.ctx.createPTable(p.mapPTableDef(n,r=>ce(r)))}getBlockLabel(e){return this.ctx.getBlockLabel(e)}getCurrentUnstableMarker(){if(!(typeof this.ctx.getCurrentUnstableMarker>"u"))return this.ctx.getCurrentUnstableMarker()}}const G="1.27.10";function Te(t){return t.__renderLambda===!0}function Q(t){if(t!==void 0)return Te(t)?t.handle:t}function E(t){if(t!==void 0)return typeof t=="string"?{__renderLambda:!0,handle:t,retentive:!1}:t}function It(t){if(t.v3!==void 0){const{initialArgs:e,initialUiState:n,inputsValid:r,outputs:i,renderingMode:s,sdkVersion:o,sections:a,title:c}=t.v3,{code:l}=t;return{initialArgs:e,initialUiState:n,inputsValid:r,outputs:i,renderingMode:s,sdkVersion:o,sections:a,title:c,code:l}}else if(t.inputsValid!==void 0){const{sdkVersion:e,renderingMode:n,outputs:r,inputsValid:i,sections:s,initialArgs:o,code:a}=t,c=Object.keys(t);if(e===void 0||n===void 0||r===void 0||i===void 0||s===void 0||o===void 0)throw new Error(`Malformed config v2. SDK version ${e}; Fields = ${c.join(", ")}`);return{sdkVersion:e,renderingMode:n,initialArgs:o,outputs:Object.fromEntries(Object.entries(r).map(([l,y])=>[l,E(y)])),inputsValid:E(i),sections:E(s),initialUiState:void 0,code:a}}else if(t.renderingMode!==void 0){const{sdkVersion:e,canRun:n,renderingMode:r,outputs:i,sections:s,initialArgs:o,code:a}=t,c=Object.keys(t);if(r===void 0||i===void 0||n===void 0||s===void 0||o===void 0)throw new Error(`Malformed config v1. SDK version ${e}; Fields = ${c.join(", ")}`);return{sdkVersion:e??"unknown",renderingMode:r,initialArgs:o,outputs:Object.fromEntries(Object.entries(i).map(([l,y])=>[l,E(y)])),inputsValid:E(n),sections:E(s),initialUiState:void 0,code:a}}else{const{sdkVersion:e}=t,n=Object.keys(t);throw new Error(`Config format not supported: SDK = ${e}; Fields = ${n.join(", ")}`)}}class S{constructor(e,n,r,i,s,o,a){this._renderingMode=e,this._initialArgs=n,this._initialUiState=r,this._outputs=i,this._inputsValid=s,this._sections=o,this._title=a}static create(e="Heavy"){return new S(e,void 0,{},{},$(!0),$([]),void 0)}output(e,n,r={}){if(typeof n=="function"){const i=`output#${e}`;return X(i,()=>n(new M)),new S(this._renderingMode,this._initialArgs,this._initialUiState,{...this._outputs,[e]:{__renderLambda:!0,handle:i,...r}},this._inputsValid,this._sections,this._title)}else return new S(this._renderingMode,this._initialArgs,this._initialUiState,{...this._outputs,[e]:n},this._inputsValid,this._sections,this._title)}retentiveOutput(e,n){return this.output(e,n,{retentive:!0})}argsValid(e){return typeof e=="function"?(X("inputsValid",()=>e(new M)),new S(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,{__renderLambda:!0,handle:"inputsValid"},this._sections,this._title)):new S(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,e,this._sections,this._title)}sections(e){return Array.isArray(e)?this.sections($(e)):typeof e=="function"?(X("sections",()=>e(new M)),new S(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,this._inputsValid,{__renderLambda:!0,handle:"sections"},this._title)):new S(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,this._inputsValid,e,this._title)}title(e){return X("title",()=>e(new M)),new S(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,this._inputsValid,this._sections,{__renderLambda:!0,handle:"title"})}initialArgs(e){return new S(this._renderingMode,e,this._initialUiState,this._outputs,this._inputsValid,this._sections,this._title)}withArgs(e){return new S(this._renderingMode,e,this._initialUiState,this._outputs,this._inputsValid,this._sections,this._title)}withUiState(e){return new S(this._renderingMode,this._initialArgs,e,this._outputs,this._inputsValid,this._sections,this._title)}done(){if(this._initialArgs===void 0)throw new Error("Initial arguments not set.");const e={v3:{sdkVersion:G,renderingMode:this._renderingMode,initialArgs:this._initialArgs,initialUiState:this._initialUiState,inputsValid:this._inputsValid,sections:this._sections,title:this._title,outputs:this._outputs},sdkVersion:G,renderingMode:this._renderingMode,initialArgs:this._initialArgs,inputsValid:Q(this._inputsValid),sections:Q(this._sections),outputs:Object.fromEntries(Object.entries(this._outputs).map(([n,r])=>[n,Q(r)]))};return dt()?he({sdkVersion:G}):{config:e}}}function xt(t,e,n,r){var l,y;Array.isArray(r)&&(r={filters:r});const i=t.resultPool.getData().entries.map(u=>u.obj).filter(p.isPColumn).filter(u=>u.spec.name==="pl7.app/label"&&u.spec.axesSpec.length===1),s=(u,h)=>{let d=u.toString();if(h)for(const f in h)d+=f,d+=h[f];return d},o=new Map;for(const u of e)for(const h of u.spec.axesSpec){const d=p.getAxisId(h);for(const f of i){const b=f.spec.axesSpec[0],m=p.getAxisId(f.spec.axesSpec[0]);if(p.matchAxisId(d,m)){const A=Object.keys(d.domain??{}).length,P=Object.keys(m.domain??{}).length;if(A>P){const w=s(f.id,d.domain);o.set(w,{id:w,spec:{...f.spec,axesSpec:[{...d,annotations:b.annotations}]},data:f.data})}else o.set(s(f.id),f)}}}if([...e,...o.values()].some(u=>u.data instanceof _&&!u.data.getIsReadyOrError()))return;let a=e;const c=[];if(r!=null&&r.coreColumnPredicate){a=[];for(const u of e)r.coreColumnPredicate(u.spec)?a.push(u):c.push(u)}return c.push(...o.values()),t.createPTable({src:{type:"outer",primary:{type:(r==null?void 0:r.coreJoinType)??"full",entries:a.map(u=>({type:"column",column:u}))},secondary:c.map(u=>({type:"column",column:u}))},filters:[...(r==null?void 0:r.filters)??[],...((l=n==null?void 0:n.pTableParams)==null?void 0:l.filters)??[]],sorting:((y=n==null?void 0:n.pTableParams)==null?void 0:y.sorting)??[]})}function St(t,e,n){const r=t.resultPool.findLabels(e);return{axis:e,options:n.map(i=>({value:i,label:(r==null?void 0:r[i])??i.toString()})),defaultValue:n[0]}}const _t=(t,e)=>{let n=t.toString();return e==null||e.forEach(r=>{if(r)for(const[i,s]of Object.entries(r))n+=i,n+=s}),n};function Ct(t){if(!t.length)return[];let e=[[]];return t.forEach(n=>{const r=[];n.forEach(i=>{r.push(...e.map(s=>[...s,i]))}),e=r}),e}function Tt(t,e){const n=t.spec.axesSpec.map(p.getAxisId);return e.spec.axesSpec.map(p.getAxisId).every(i=>n.some(s=>p.matchAxisId(s,i)&&p.matchAxisId(i,s)))}function Le(t,e){const n=t.spec.axesSpec.map(p.getAxisId);return e.spec.axesSpec.map(p.getAxisId).every(i=>n.some(s=>p.matchAxisId(s,i)))}const Re="pl7.app/graph/isVirtual",oe="pl7.app/label";function pe(t,e){const n=t.spec.axesSpec.map(p.getAxisId),r=e.spec.axesSpec.map(p.getAxisId);if(Tt(t,e))return[];if(!Le(t,e))return[];const o=r.map(u=>n.filter(h=>p.matchAxisId(h,u))),a=Ct(o),c=new Set,l=new Set,y=a.map(u=>{const h=new Set;return u.map((d,f)=>{const b=e.spec.axesSpec[f].domain,m=d.domain;return Object.entries(m??{}).forEach(([A,P])=>{if((b==null?void 0:b[A])===void 0){const w=JSON.stringify([A,P]);h.add(w),c.add(w)}}),{...d,annotations:e.spec.axesSpec[f].annotations}}),h});return[...c].forEach(u=>{y.some(h=>!h.has(u))&&l.add(u)}),a.map((u,h)=>{var A;const d=_t(e.id,u.map(P=>P.domain)),f=((A=e.spec.annotations)==null?void 0:A[oe])??"",b=[...y[h]].filter(P=>l.has(P)).sort().map(P=>{var w;return(w=JSON.parse(P))==null?void 0:w[1]}).join(" / "),m={...e.spec.annotations,[Re]:"true"};return(f||b)&&(m[oe]=f&&b?f+" / "+b:f+b),{id:d,spec:{...e.spec,axesSpec:u.map((P,w)=>({...P,annotations:e.spec.axesSpec[w].annotations})),annotations:m},data:e.data}})}function Oe(t){const e=[];for(let n=0;n<t.length;n++)for(let r=n+1;r<t.length;r++){const i=t[n],s=t[r];e.push(...pe(i,s),...pe(s,i))}return e}function Fe(t,e){const n=[...t];for(const r of e)for(const i of t){if(i.id===r.id)break;if(Le(i,r)){n.push(r);break}}return n}const Lt=["Int","Long","Float","Double","String","Bytes"];function Rt(t,e){if(e===void 0)return;const n=t.resultPool.getData().entries.map(s=>s.obj).filter(p.isPColumn).filter(s=>Lt.includes(s.spec.valueType)),r=Fe(e,n),i=[...r,...Oe(r)];if(!i.some(s=>s.data instanceof _&&!s.data.getIsReadyOrError()))return t.createPFrame(i)}class Ot{constructor(e){this.handle=e}async findColumns(e){return await platforma.pFrameDriver.findColumns(this.handle,e)}async getColumnSpec(e){return await platforma.pFrameDriver.getColumnSpec(this.handle,e)}async listColumns(){return await platforma.pFrameDriver.listColumns(this.handle)}async calculateTableData(e){return await platforma.pFrameDriver.calculateTableData(this.handle,e)}async getUniqueValues(e){return await platforma.pFrameDriver.getUniqueValues(this.handle,e)}}function De(t){return ae({__isRef:!0,blockId:W(t,"blockId"),name:W(t,"name")})}function Ft(t){return ae({ref:De(W(t,"ref")),label:W(t,"label")})}const Dt={sdkVersion:G};function Ee(){return he({sdkVersion:G})}function Et(t){try{return Ee()}catch{return t}}function kt(t){if(typeof globalThis.getEnvironmentValue=="function")return globalThis.getEnvironmentValue(t)}exports.Args=Ke;exports.BlockModel=S;exports.CurrentSdkInfo=Dt;exports.FutureRef=I;exports.IS_VIRTUAL_COLUMN=Re;exports.It=Be;exports.JsRenderInternal=yt;exports.LABEL_ANNOTATION=oe;exports.MainOutputs=Ue;exports.OutputError=de;exports.PAnnotationLabel=be;exports.PAnnotationTrace=ve;exports.PFrameImpl=Ot;exports.RT_BINARY_PARTITIONED=D;exports.RT_BINARY_SUPER_PARTITIONED=V;exports.RT_JSON_PARTITIONED=j;exports.RT_JSON_SUPER_PARTITIONED=q;exports.RT_RESOURCE_MAP=H;exports.RT_RESOURCE_MAP_PARTITIONED=z;exports.RenderCtx=M;exports.ResultPool=Ce;exports.StagingOutputs=Je;exports.Trace=Pe;exports.TraceEntry=Ae;exports.TreeNodeAccessor=_;exports.UiState=Me;exports.and=Ye;exports.createPFrameForGraphs=Rt;exports.createPlDataTable=xt;exports.createPlDataTableSheet=St;exports.deriveLabels=se;exports.downgradeCfgOrLambda=Q;exports.enrichColumnsWithCompatible=Fe;exports.extractArchiveAndGetURL=ot;exports.extractConfig=It;exports.filterDataInfoEntries=_e;exports.flatten=He;exports.fromPlOption=Ft;exports.fromPlRef=De;exports.getAdditionalColumns=Oe;exports.getBlobContent=tt;exports.getBlobContentAsJson=rt;exports.getBlobContentAsString=nt;exports.getDownloadedBlobContent=st;exports.getEnvironmentValue=kt;exports.getFromCfg=N;exports.getImmediate=$;exports.getImportProgress=at;exports.getJsonField=W;exports.getLastLogs=lt;exports.getLogHandle=pt;exports.getOnDemandBlobContent=it;exports.getPartitionKeysList=xe;exports.getPlatformaOrDefault=Et;exports.getProgressLog=ut;exports.getProgressLogWithInfo=ct;exports.getRawPlatformaInstance=Ee;exports.getResourceField=Qe;exports.getResourceValueAsJson=Ze;exports.getUniquePartitionKeys=Se;exports.ifDef=Z;exports.isConfigLambda=Te;exports.isEmpty=ze;exports.isolate=Ne;exports.makeArray=$e;exports.makeObject=ae;exports.mapArrayValues=We;exports.mapRecordValues=Ge;exports.mapResourceFields=et;exports.not=qe;exports.or=Xe;exports.parsePColumnData=ee;exports.parseResourceMap=At;exports.readOutput=fe;exports.wrapOutputs=Ve;Object.keys(p).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>p[t]})});Object.keys(le).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>le[t]})});
1
+ "use strict";var We=Object.defineProperty;var qe=(t,e,n)=>e in t?We(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var R=(t,e,n)=>qe(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@milaboratories/pl-model-common"),K=require("zod"),ve=require("canonicalize"),ge=require("@milaboratories/pl-error-like");class Ae extends Error{constructor(e,n){super(`${e.length}${n?"+":""} errors, first error: `+e[0].message),this.errors=e,this.moreErrors=n}}function Pe(t){if(!t.ok)throw new Ae(t.errors,t.moreErrors);return t.value}function He(t){return new Proxy(t,{get(e,n){return Pe(e[n])}})}function w(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||t===null?W(t):t}function U(t){return{type:"GetFromCtx",variable:t}}function ze(t){return{type:"Isolate",cfg:t}}const Ye=U("$args"),Xe=U("$it"),Qe=U("$prod"),Ze=U("$staging"),et=U("$ui");function W(t){return{type:"Immediate",value:t}}function fe(t){const e={};for(const[n,r]of Object.entries(t))e[n]=w(r);return{type:"MakeObject",template:e}}function tt(...t){const e=[];for(const n of t)e.push(w(n));return{type:"MakeArray",template:e}}function H(t,e){return{type:"GetJsonField",source:w(t),field:w(e)}}function nt(t,e,n="$it"){return{type:"MapRecordValues",source:t,mapping:e,itVar:n}}function rt(t,e,n="$it"){return{type:"MapArrayValues",source:t,mapping:e,itVar:n}}function it(t){return{type:"Flatten",source:t}}function st(t){return{type:"IsEmpty",arg:t}}function ot(t){return{type:"Not",operand:t}}function at(t,e){return{type:"And",operand1:t,operand2:e}}function lt(t,e){return{type:"Or",operand1:t,operand2:e}}function ut(t,e){return{type:"GetResourceField",source:w(t),field:w(e)}}function ct(){return function(t){return{type:"GetResourceValueAsJson",source:w(t)}}}function dt(t,e,n="$it"){return{type:"MapResourceFields",source:t,mapping:e,itVar:n}}function pt(t){return{type:"GetBlobContent",source:w(t)}}function ft(t){return{type:"GetBlobContentAsString",source:w(t)}}function ht(){return function(t){return{type:"GetBlobContentAsJson",source:w(t)}}}function gt(t){return{type:"GetDownloadedBlobContent",source:w(t)}}function mt(t){return{type:"GetOnDemandBlobContent",source:w(t)}}function yt(t,e){return{type:"ExtractArchiveAndGetURL",format:e,source:w(t)}}function bt(t){return{type:"GetImportProgress",source:w(t)}}function vt(t,e){return{type:"GetLastLogs",source:w(t),lines:e}}function At(t,e){return{type:"GetProgressLog",source:w(t),patternToSearch:e}}function Pt(t,e){return{type:"GetProgressLogWithInfo",source:w(t),patternToSearch:e}}function St(t){return{type:"GetLogHandle",source:w(t)}}function wt(){return typeof globalThis.getPlatforma<"u"||typeof globalThis.platforma<"u"}function Se(t){if(t&&typeof globalThis.getPlatforma=="function")return globalThis.getPlatforma(t);if(typeof globalThis.platforma<"u")return globalThis.platforma;throw new Error("Can't get platforma instance.")}function xt(){if(typeof globalThis.cfgRenderCtx<"u")return globalThis.cfgRenderCtx}function g(){if(typeof globalThis.cfgRenderCtx<"u")return globalThis.cfgRenderCtx;throw new Error("Not in config rendering context")}function ne(t,e){const n=xt();if(n===void 0)return!1;if(t in n.callbackRegistry)throw new Error(`Callback with key ${t} already registered.`);return n.callbackRegistry[t]=e,!0}const ae=new Map;function It(t,e){t in g().callbackRegistry||(g().callbackRegistry[t]=n=>{for(const r of ae.get(t))r(n)},ae.set(t,[])),ae.get(t).push(e)}class I{constructor(e,n=r=>r){R(this,"isResolved",!1);R(this,"resolvedValue");this.handle=e,this.postProcess=n,It(e,r=>{this.resolvedValue=n(r),this.isResolved=!0})}map(e){return new I(this.handle,n=>e(this.postProcess(n)))}mapDefined(e){return new I(this.handle,n=>{const r=this.postProcess(n);return r?e(r):void 0})}toJSON(){return this.isResolved?this.resolvedValue:{__awaited_futures__:[this.handle]}}}function ie(t,e){return t===void 0?void 0:e(t)}class L{constructor(e,n){this.handle=e,this.resolvePath=n}resolve(...e){const n=e.map(r=>({assertFieldType:"Input",...typeof r=="string"?{field:r}:r}));return this.resolveWithCommon({},...n)}resolveOutput(...e){const n=e.map(r=>({assertFieldType:"Output",...typeof r=="string"?{field:r}:r}));return this.resolveWithCommon({},...n)}resolveInput(...e){const n=e.map(r=>({assertFieldType:"Input",...typeof r=="string"?{field:r}:r}));return this.resolveWithCommon({},...n)}resolveAny(...e){return this.resolveWithCommon({},...e)}resolveWithCommon(e,...n){const r=[...this.resolvePath,...n.map(i=>typeof i=="string"?i:i.field)];return ie(g().resolveWithCommon(this.handle,e,...n),i=>new L(i,r))}get resourceType(){return g().getResourceType(this.handle)}getInputsLocked(){return g().getInputsLocked(this.handle)}getOutputsLocked(){return g().getOutputsLocked(this.handle)}getIsReadyOrError(){return g().getIsReadyOrError(this.handle)}getIsFinal(){return g().getIsFinal(this.handle)}getError(){const e=[...this.resolvePath,"error"];return ie(g().getError(this.handle),n=>new L(n,e))}listInputFields(){return g().listInputFields(this.handle)}listOutputFields(){return g().listOutputFields(this.handle)}listDynamicFields(){return g().listDynamicFields(this.handle)}getKeyValueBase64(e){return g().getKeyValueBase64(this.handle,e)}getKeyValueAsString(e){return g().getKeyValueAsString(this.handle,e)}getKeyValueAsJson(e){const n=this.getKeyValueAsString(e);if(n==null)throw new Error("Resource has no content.");return JSON.parse(n)}getDataBase64(){return g().getDataBase64(this.handle)}getDataAsString(){return g().getDataAsString(this.handle)}getDataAsJson(){const e=this.getDataAsString();if(e==null)throw new Error("Resource has no content.");return JSON.parse(e)}getPColumns(e=!1,n=""){const r=this.parsePObjectCollection(e,n);return r===void 0?void 0:Object.entries(r).map(([,s])=>{if(!u.isPColumn(s))throw new Error(`not a PColumn (kind = ${s.spec.kind})`);return s})}parsePObjectCollection(e=!1,n=""){const r=g().parsePObjectCollection(this.handle,e,n,...this.resolvePath);if(r===void 0)return;const i={};for(const[s,o]of Object.entries(r)){const a=[...this.resolvePath,s];i[s]=u.mapPObjectData(o,l=>new L(l,a))}return i}getFileContentAsBase64(){return new I(g().getBlobContentAsBase64(this.handle))}getFileContentAsString(){return new I(g().getBlobContentAsString(this.handle))}getFileContentAsJson(){return new I(g().getBlobContentAsString(this.handle)).mapDefined(e=>JSON.parse(e))}getBlobContentAsBase64(){return this.getFileContentAsBase64()}getBlobContentAsString(){return this.getFileContentAsString()}getFileHandle(){return new I(g().getDownloadedBlobContentHandle(this.handle))}getDownloadedBlobHandle(){return this.getFileHandle()}getRemoteFileHandle(){return new I(g().getOnDemandBlobContentHandle(this.handle))}getOnDemandBlobHandle(){return this.getRemoteFileHandle()}extractArchiveAndGetURL(e){return new I(g().extractArchiveAndGetURL(this.handle,e))}getImportProgress(){return new I(g().getImportProgress(this.handle))}getLastLogs(e){return new I(g().getLastLogs(this.handle,e))}getProgressLog(e){return new I(g().getProgressLog(this.handle,e))}getProgressLogWithInfo(e){return new I(g().getProgressLogWithInfo(this.handle,e))}getLogHandle(){return new I(g().getLogHandle(this.handle))}allFieldsResolved(e="Input"){switch(e){case"Input":return this.getInputsLocked()&&this.listInputFields().every(n=>this.resolve({field:n,assertFieldType:"Input"})!==void 0);case"Output":return this.getOutputsLocked()&&this.listOutputFields().every(n=>this.resolve({field:n,assertFieldType:"Output"})!==void 0)}}mapFields(e,n){const{fieldType:r,requireLocked:i,skipUnresolved:s}={fieldType:"Input",requireLocked:!0,skipUnresolved:!1,...n},o=e;if(i&&(r==="Input"&&!this.getInputsLocked()||r==="Output"&&!this.getOutputsLocked()))return;let l=(r==="Input"?this.listInputFields():r==="Output"?this.listOutputFields():this.listDynamicFields()).map(d=>[d,this.resolve({field:d,assertFieldType:r})]);return s&&(l=l.filter(d=>d[1]!==void 0)),l.map(([d,P])=>o(d,P))}}const we="staging",xe="main",Ct={explicitColumnsSupport:!0,inlineColumnsSupport:!0,activeArgs:!0};function Ie(t){return typeof t=="object"&&t!==null&&"__awaited_futures__"in t}function ue(t,e,n){if(e.has(n))return;if(e.add(n),typeof n==="object")if(Ie(n))n.__awaited_futures__.forEach(i=>t.add(i));else if(Array.isArray(n))for(const i of n)ue(t,e,i);else for(const[,i]of Object.entries(n))i!==n&&ue(t,e,i)}function _t(t){const e=new Set;return ue(e,new Set,t),e}const Lt=Object.freeze(Object.defineProperty({__proto__:null,GlobalCfgRenderCtxFeatureFlags:Ct,MainAccessorName:xe,StagingAccessorName:we,getAllFutureAwaits:_t,isFutureAwait:Ie},Symbol.toStringTag,{value:"Module"})),Ce="pl7.app/label",_e="pl7.app/trace",Le=K.z.object({type:K.z.string(),importance:K.z.number().optional(),id:K.z.string().optional(),label:K.z.string()}),Te=K.z.array(Le),Tt=.001,Rt="__LABEL__",me="__LABEL__@1";function he(t,e,n={}){const r=new Map,i=new Map,s=t.map(c=>{var J,Z;const h=e(c);let p,b,v;"spec"in h&&typeof h.spec=="object"?(p=h.spec,b=h.prefixTrace,v=h.suffixTrace):p=h;const y=(J=p.annotations)==null?void 0:J[Ce],A=(Z=p.annotations)==null?void 0:Z[_e],m=(A?Te.safeParse(JSON.parse(A)).data:void 0)??[],S=[...b??[],...m,...v??[]];if(y){const C={label:y,type:Rt,importance:-2};n.addLabelAsSuffix?S.push(C):S.splice(0,0,C)}const x=[],F=new Map;for(let C=S.length-1;C>=0;--C){const{type:k}=S[C],ee=S[C].importance??0,B=(F.get(k)??0)+1;F.set(k,B);const O=`${k}@${B}`;i.set(O,(i.get(O)??0)+1),r.set(O,Math.max(r.get(O)??Number.NEGATIVE_INFINITY,ee-(S.length-C)*Tt)),x.push({...S[C],fullType:O,occurenceIndex:B})}return x.reverse(),{value:c,spec:p,label:y,fullTrace:x}}),o=[],a=[],l=[...r];l.sort(([,c],[,h])=>h-c);for(const[c]of l)c.endsWith("@1")||i.get(c)===t.length?o.push(c):a.push(c);const d=c=>s.map(h=>{const p=h.fullTrace.filter(v=>c.has(v.fullType)).map(v=>v.label),b=n.separator??" / ";return{label:p.join(b),value:h.value}});if(o.length===0){if(a.length!==0)throw new Error("Assertion error.");return d(new Set(me))}let P=0,f=0;for(;P<o.length;){const c=new Set;n.includeNativeLabel&&c.add(me);for(let p=0;p<P;++p)c.add(o[p]);c.add(o[f]);const h=d(c);if(new Set(h.map(p=>p.label)).size===t.length)return h;f++,f==o.length&&(P++,f=P)}return d(new Set([...o,...a]))}const Q="PColumnData/",z=Q+"ResourceMap",Y=Q+"Partitioned/ResourceMap",N=Q+"JsonPartitioned",D=Q+"BinaryPartitioned",Re=Q+"Partitioned/",X=Re+"JsonPartitioned",$=Re+"BinaryPartitioned";function Oe(t,e,n,r=[],i){if(t===void 0)return!1;switch(t.resourceType.name){case z:{let s=t.getInputsLocked();for(const o of t.listInputFields()){const a=t.resolve({field:o,assertFieldType:"Input"}),l=[...r,...JSON.parse(o)],d=a===void 0?void 0:e(a);d===void 0&&(s=!1),(d!==void 0||i)&&n.push({key:l,value:d})}return s}case Y:{let s=t.getInputsLocked();for(const o of t.listInputFields()){const a=t.resolve({field:o,assertFieldType:"Input"});if(a===void 0)s=!1;else{const l=[...r,...JSON.parse(o)],d=Oe(a,e,n,l,i);s=s&&d}}return s}default:throw new Error(`Unknown resource type: ${t.resourceType.name}`)}}function Ot(t,e,n=!1){const r=[];return{isComplete:Oe(t,e,r,[],n),data:r}}const ce=t=>{if(t.endsWith(".index"))return{baseKey:t.substring(0,t.length-6),type:"index"};if(t.endsWith(".values"))return{baseKey:t.substring(0,t.length-7),type:"values"};throw new Error(`key must ends on .index/.values for binary p-column, got: ${t}`)};function Ee(t){if(!t)return;const e=t.resourceType.name,n=t.getDataAsJson(),r=[];let i=0;switch(e){case z:i=n.keyLength;break;case Y:i=n.partitionKeyLength+n.keyLength;break;case N:case D:i=n.partitionKeyLength;break;case $:case X:i=n.superPartitionKeyLength+n.partitionKeyLength;break}switch(e){case z:case N:case D:for(let s of t.listInputFields()){e===D&&(s=ce(s).baseKey);const o=[...JSON.parse(s)];r.push(o)}break;case Y:case $:case X:for(const s of t.listInputFields()){const o=[...JSON.parse(s)],a=t.resolve({field:s,assertFieldType:"Input"});if(a!==void 0)for(let l of a.listInputFields()){e===$&&(l=ce(l).baseKey);const d=[...o,...JSON.parse(l)];r.push(d)}}break}return{data:r,keyLength:i}}function Et(t){if(t.type!=="JsonPartitioned"&&t.type!=="BinaryPartitioned")throw new Error(`Splitting requires Partitioned DataInfoEntries, got ${t.type}`);const{parts:e,partitionKeyLength:n}=t,r=[];for(let i=0;i<n;++i)r.push(new Set);for(const i of e){const s=i.key;if(s.length!==n)throw new Error(`Key length (${s.length}) does not match partition length (${n}) for key: ${JSON.stringify(s)}`);for(let o=0;o<n;++o)r[o].add(s[o])}return r.map(i=>Array.from(i.values()))}function De(t){if(t===void 0)return;if(u.isDataInfoEntries(t))return Et(t);const e=Ee(t);if(!e)return;const{data:n,keyLength:r}=e,i=[];for(let s=0;s<r;++s)i.push(new Set);for(const s of n){if(s.length!==r)throw new Error("key length does not match partition length");for(let o=0;o<r;++o)i[o].add(s[o])}return i.map(s=>Array.from(s.values()))}function se(t,e=[]){if(t===void 0||!t.getIsReadyOrError())return;const n=t.resourceType.name,r=t.getDataAsJson();if(e.length>0&&(n===X||n===$))throw new Error(`Unexpected nested super-partitioned resource: ${n}`);switch(n){case z:case Y:throw new Error(`Only data columns are supported, got: ${n}`);case N:{if(typeof(r==null?void 0:r.partitionKeyLength)!="number")throw new Error(`Missing partitionKeyLength in metadata for ${n}`);const i=[];for(const s of t.listInputFields()){const o=t.resolve({field:s,assertFieldType:"Input"});if(o===void 0)return;const a=[...e,...JSON.parse(s)];i.push({key:a,value:o})}return{type:"JsonPartitioned",partitionKeyLength:r.partitionKeyLength,parts:i}}case D:{if(typeof(r==null?void 0:r.partitionKeyLength)!="number")throw new Error(`Missing partitionKeyLength in metadata for ${n}`);const i=[],s=new Map;for(const o of t.listInputFields()){const a=ce(o),l=t.resolve({field:o,assertFieldType:"Input"});if(l===void 0)return;let d=s.get(a.baseKey);d||(d={},s.set(a.baseKey,d)),a.type==="index"?d.index=l:d.values=l}for(const[o,a]of s.entries()){if(!a.index||!a.values)return;const l=[...e,...JSON.parse(o)];i.push({key:l,value:{index:a.index,values:a.values}})}return{type:"BinaryPartitioned",partitionKeyLength:r.partitionKeyLength,parts:i}}case X:{if(typeof(r==null?void 0:r.superPartitionKeyLength)!="number"||typeof(r==null?void 0:r.partitionKeyLength)!="number")throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${n}`);const i=r.superPartitionKeyLength+r.partitionKeyLength,s=[];for(const o of t.listInputFields()){const a=t.resolve({field:o,assertFieldType:"Input"});if(a===void 0)return;if(a.resourceType.name!==N)throw new Error(`Expected ${N} inside ${n}, but got ${a.resourceType.name}`);const l=se(a,JSON.parse(o));if(l===void 0)return;if(l.type!=="JsonPartitioned")throw new Error(`Unexpected inner result type for ${n}: ${l.type}`);s.push(...l.parts)}return{type:"JsonPartitioned",partitionKeyLength:i,parts:s}}case $:{if(typeof(r==null?void 0:r.superPartitionKeyLength)!="number"||typeof(r==null?void 0:r.partitionKeyLength)!="number")throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${n}`);const i=r.superPartitionKeyLength+r.partitionKeyLength,s=[];for(const o of t.listInputFields()){const a=t.resolve({field:o,assertFieldType:"Input"});if(a===void 0)return;if(a.resourceType.name!==D)throw new Error(`Expected ${D} inside ${n}, but got ${a.resourceType.name}`);const l=se(a,JSON.parse(o));if(l===void 0)return;if(l.type!=="BinaryPartitioned")throw new Error(`Unexpected inner result type for ${n}: ${l.type}`);s.push(...l.parts)}return{type:"BinaryPartitioned",partitionKeyLength:i,parts:s}}default:throw new Error(`Unknown resource type: ${n}`)}}function Fe(t){if(t!==void 0){if(u.isDataInfoEntries(t))return t;if(u.isDataInfo(t))return u.dataInfoToEntries(t);if(t instanceof L)return se(t);throw new Error(`Unexpected input type: ${typeof t}`)}}function ke(t,e){const n=[...e].sort((s,o)=>o[0]-s[0]);if(t.type==="JsonPartitioned"||t.type==="BinaryPartitioned"){const{partitionKeyLength:s}=t;for(const[o]of e)if(o>=s)throw new Error(`Can't filter on non-partitioned axis ${o}. Must be >= ${s}`)}else if(t.type==="Json"){const{keyLength:s}=t;for(const[o]of e)if(o>=s)throw new Error(`Can't filter on non-data axis ${o}. Must be >= ${s}`)}const r=s=>{for(const[o,a]of n)if(s[o]!==a)return!1;return!0},i=s=>{const o=[...s];for(const[a]of n)o.splice(a,1);return o};switch(t.type){case"Json":{const s=t.data.filter(o=>r(o.key)).map(o=>({key:i(o.key),value:o.value}));return{type:"Json",keyLength:t.keyLength-e.length,data:s}}case"JsonPartitioned":{const s=t.parts.filter(o=>r(o.key)).map(o=>({key:i(o.key),value:o.value}));return{type:"JsonPartitioned",partitionKeyLength:t.partitionKeyLength-e.length,parts:s}}case"BinaryPartitioned":{const s=t.parts.filter(o=>r(o.key)).map(o=>({key:i(o.key),value:o.value}));return{type:"BinaryPartitioned",partitionKeyLength:t.partitionKeyLength-e.length,parts:s}}}}class Dt{constructor(e){this.columns=e}selectColumns(e){const n=typeof e=="function"?e:u.selectorsToPredicate(e);return this.columns.filter(r=>n(r.spec))}}function Ft(t){if(t)return t.map(e=>({type:`split:${u.canonicalizeAxisId(e.axisId)}`,label:e.label,importance:1e6}))}function kt(t){if(t)return t.map(e=>[e.axisIdx,e.value])}function jt(t,e){if(!e||e.length===0)return t;const n=[...e].sort((r,i)=>r[0]-i[0]);return ve({id:t,axisFilters:n})}function Vt(t){if(!t||typeof t!="object")return!1;const e=t,n=e.domain&&typeof e.domain=="object"&&Object.values(e.domain).some(i=>typeof i=="object"&&i!==null&&"anchor"in i),r=e.axes&&Array.isArray(e.axes)&&e.axes.some(i=>typeof i=="object"&&i!==null&&"anchor"in i);return!!e.domainAnchor||n||r}function Kt(t){if(typeof t!="object"||!("axes"in t)||t.axes===void 0)return[];const e=t.axes.map((n,r)=>typeof n=="object"&&"split"in n&&n.split===!0?r:-1).filter(n=>n!==-1);if(e.length>0&&t.partialAxesMatch!==void 0)throw new Error("Axis splitting is not supported when `partialAxesMatch` is defined.");return e.sort((n,r)=>n-r),e}class de{constructor(){R(this,"defaultProviderStore",[]);R(this,"providers",[new Dt(this.defaultProviderStore)]);R(this,"axisLabelProviders",[])}addColumnProvider(e){return this.providers.push(e),this}addAxisLabelProvider(e){return this.axisLabelProviders.push(e),this}addColumns(e){return this.defaultProviderStore.push(...e),this}addColumn(e){return this.defaultProviderStore.push(e),this}findLabels(e){for(const n of this.axisLabelProviders){const r=n.findLabels(e);if(r)return r}}getUniversalEntries(e,n){const{anchorCtx:r,labelOps:i,dontWaitAllData:s=!1,overrideLabelAnnotation:o=!1}=n??{},a={...o&&(i==null?void 0:i.includeNativeLabel)!==!1?{includeNativeLabel:!0}:{},...i??{}},l=typeof e=="function"?[e]:Array.isArray(e)?e:[e],d=[];for(const c of l){const h=Vt(c);let p;if(h){if(!r)throw new Error("Anchored selectors require an AnchoredIdDeriver to be provided in options.");p=u.resolveAnchors(r.anchors,c)}else p=c;const b=new Set,v=[];for(const m of this.providers){const S=m.selectColumns(p);for(const x of S){if(b.has(x.id))throw new Error(`Duplicate column id ${x.id} in provider ${m.constructor.name}`);b.add(x.id),v.push(x)}}if(v.length===0)continue;const y=Kt(c),A=y.length>0;for(const m of v){if(!u.isPColumnSpec(m.spec))continue;const S=m.spec;if(A){const x=Fe(m.data);if(!x){if(s)continue;return}if(!u.isPartitionedDataInfoEntries(x))throw new Error(`Splitting requires Partitioned DataInfoEntries, but parsing resulted in ${x.type} for column ${m.id}`);const F=De(x),J=y[y.length-1];if(J>=x.partitionKeyLength)throw new Error(`Not enough partition keys (${x.partitionKeyLength}) for requested split axes (max index ${J}) in column ${S.name}`);const Z=y.map(_=>this.findLabels(u.getAxisId(S.axesSpec[_]))),C=[],k=(_,M)=>{if(M>=y.length){C.push([..._]);return}const E=y[M];if(E>=F.length)throw new Error(`Axis index ${E} out of bounds for unique keys array (length ${F.length}) during split key generation for column ${m.id}`);const j=F[E];if(!j||j.length===0){C.length=0;return}for(const te of j)_.push(te),k(_,M+1),_.pop()};if(k([],0),C.length===0)continue;const ee=[...S.axesSpec],B=y.map(_=>_);for(let _=y.length-1;_>=0;_--)ee.splice(y[_],1);const O={...S,axesSpec:ee};for(const _ of C){const M=_.map((E,j)=>{const te=B[j],Me=u.getAxisId(S.axesSpec[te]),oe=Z[j],Ge=(oe==null?void 0:oe[E])??String(E);return{axisIdx:te,axisId:Me,value:E,label:Ge}});d.push({type:"split",originalColumn:m,spec:S,adjustedSpec:O,dataEntries:x,axisFilters:M})}}else d.push({type:"direct",originalColumn:m,spec:S,adjustedSpec:S})}}if(d.length===0)return[];const P=he(d,c=>({spec:c.spec,suffixTrace:c.type==="split"?Ft(c.axisFilters):void 0}),a),f=[];for(const{value:c,label:h}of P){const{originalColumn:p,spec:b}=c,v=c.type==="split"?c.axisFilters:void 0,y=kt(v);let A;r?A=r.deriveS(b,y):A=jt(p.id,y);let m={...c.adjustedSpec};o&&(m={...m,annotations:{...m.annotations??{},"pl7.app/label":h}}),f.push({id:A,spec:m,data:()=>c.type==="split"?u.entriesToDataInfo(ke(c.dataEntries,y)):c.originalColumn.data,label:h})}return f}getColumns(e,n){const r=this.getUniversalEntries(e,{overrideLabelAnnotation:!0,...n??{}});if(!r)return;const i=[];for(const s of r){const o=s.data();if(!o){if(n!=null&&n.dontWaitAllData)continue;return}i.push({id:s.id,spec:s.spec,data:o})}return i}}function le(t,e){if(t===void 0)return e===void 0;if(e===void 0)return!0;for(const n in e)if(t[n]!==e[n])return!1;return!0}function ye(t){return u.mapPObjectData(t,e=>e instanceof L?e.handle:u.isDataInfo(e)?u.mapDataInfo(e,n=>n.handle):e)}class je{constructor(){R(this,"ctx",g())}calculateOptions(e){return this.ctx.calculateOptions(e)}getOptions(e,n){const r=typeof e=="function"?e:u.selectorsToPredicate(e),i=this.getSpecs().entries.filter(s=>r(s.obj));return typeof n=="object"||typeof n>"u"?he(i,s=>s.obj,n??{}).map(({value:{ref:s},label:o})=>({ref:s,label:o})):i.map(s=>({ref:s.ref,label:n(s.obj,s.ref)}))}resolveAnchorCtx(e){if(e instanceof u.AnchoredIdDeriver)return e;const n={};for(const[r,i]of Object.entries(e))if(u.isPlRef(i)){const s=this.getPColumnSpecByRef(i);if(!s)return;n[r]=s}else n[r]=i;return new u.AnchoredIdDeriver(n)}getAnchoredPColumns(e,n,r){const i=this.resolveAnchorCtx(e);if(i)return new de().addColumnProvider(this).addAxisLabelProvider(this).getColumns(n,{...r,anchorCtx:i})}getCanonicalOptions(e,n,r){const i=this.resolveAnchorCtx(e);if(!i)return;const s=new de().addColumnProvider(this).addAxisLabelProvider(this).getUniversalEntries(n,{...r,anchorCtx:i});if(s)return s.map(o=>({value:o.id,label:o.label}))}getDataFromResultPool(){return this.getData()}getData(){const e=this.ctx.getDataFromResultPool();return{isComplete:e.isComplete,entries:e.entries.map(n=>({ref:n.ref,obj:{...n.obj,data:new L(n.obj.data,[n.ref.blockId,n.ref.name])}}))}}getDataWithErrorsFromResultPool(){return this.getDataWithErrors()}getDataWithErrors(){const e=this.ctx.getDataWithErrorsFromResultPool();return{isComplete:e.isComplete,entries:e.entries.map(n=>({ref:n.ref,obj:{...n.obj,data:u.mapValueInVOE(n.obj.data,r=>new L(r,[n.ref.blockId,n.ref.name]))}}))}}getSpecsFromResultPool(){return this.getSpecs()}getSpecs(){return this.ctx.getSpecsFromResultPool()}getDataByRef(e){var r;if(typeof this.ctx.getDataFromResultPoolByRef>"u")return(r=this.getData().entries.find(i=>i.ref.blockId===e.blockId&&i.ref.name===e.name))==null?void 0:r.obj;const n=this.ctx.getDataFromResultPoolByRef(e.blockId,e.name);if(n)return u.mapPObjectData(n,i=>new L(i,[e.blockId,e.name]))}getPColumnByRef(e){const n=this.getDataByRef(e);if(n)return u.ensurePColumn(n)}getPColumnSpecByRef(e){const n=this.getSpecByRef(e);if(n){if(!u.isPColumnSpec(n))throw new Error(`not a PColumn spec (kind = ${n.kind})`);return n}}getSpecByRef(e){return this.ctx.getSpecFromResultPoolByRef(e.blockId,e.name)}findDataWithCompatibleSpec(e){const n=[];e:for(const r of this.getData().entries){if(!u.isPColumnSpec(r.obj.spec))continue;const i=r.obj.spec;if(e.name===i.name&&e.valueType===i.valueType&&e.axesSpec.length===i.axesSpec.length&&le(e.domain,i.domain)){for(let s=0;s<e.axesSpec.length;++s){const o=e.axesSpec[s],a=i.axesSpec[s];if(o.name!==a.name||o.type!==a.type||!le(o.domain,a.domain))continue e}n.push(r.obj)}}return n}findLabels(e){const n=this.getData();for(const r of n.entries){if(!u.isPColumn(r.obj))continue;const i=r.obj.spec;if(i.name==="pl7.app/label"&&i.axesSpec.length===1&&i.axesSpec[0].name===e.name&&i.axesSpec[0].type===e.type&&le(e.domain,i.axesSpec[0].domain)){if(r.obj.data.resourceType.name!=="PColumnData/Json")throw Error(`Expected JSON column for labels, got: ${r.obj.data.resourceType.name}`);return Object.fromEntries(Object.entries(r.obj.data.getDataAsJson().data).map(o=>[JSON.parse(o[0])[0],o[1]]))}}}selectColumns(e){const n=typeof e=="function"?e:u.selectorsToPredicate(e);return this.getSpecs().entries.filter(({obj:i})=>u.isPColumnSpec(i)?n(i):!1).map(({ref:i,obj:s})=>{const o=s;let a=null;const l=this;return{id:ve(i),spec:o,get data(){var d;return a!==null||(a=(d=l.getPColumnByRef(i))==null?void 0:d.data),a}}})}findLabelsForColumnAxis(e,n){const r=this.findLabels(e.spec.axesSpec[n]);if(r)return Object.fromEntries(e.data.listInputFields().map(i=>{const s=JSON.parse(i);return[s[n],r[s[n]]??"Unlabelled"]}))}}class G{constructor(){R(this,"ctx");R(this,"args");R(this,"uiState");R(this,"_activeArgsCache");R(this,"resultPool",new je);this.ctx=g(),this.args=JSON.parse(this.ctx.args),this.uiState=this.ctx.uiState!==void 0?JSON.parse(this.ctx.uiState):{}}get activeArgs(){return this._activeArgsCache===void 0&&(this._activeArgsCache={v:this.ctx.activeArgs?JSON.parse(this.ctx.activeArgs):void 0}),this._activeArgsCache.v}getNamedAccessor(e){return ie(this.ctx.getAccessorHandleByName(e),n=>new L(n,[e]))}get prerun(){return this.getNamedAccessor(we)}get outputs(){return this.getNamedAccessor(xe)}findLabels(e){return this.resultPool.findLabels(e)}verifyInlineAndExplicitColumnsSupport(e){var i;const n=e.some(s=>!(s.data instanceof L)||u.isDataInfo(s.data)),r=((i=this.ctx.featureFlags)==null?void 0:i.inlineColumnsSupport)===!0;if(n&&!r)throw Error("Inline or explicit columns not supported")}createPFrame(e){return this.verifyInlineAndExplicitColumnsSupport(e),this.ctx.createPFrame(e.map(n=>ye(n)))}createPTable(e){let n;return"columns"in e?n={src:{type:"full",entries:e.columns.map(r=>({type:"column",column:r}))},filters:e.filters??[],sorting:e.sorting??[]}:n=e,this.verifyInlineAndExplicitColumnsSupport(u.extractAllColumns(n.src)),this.ctx.createPTable(u.mapPTableDef(n,r=>ye(r)))}getBlockLabel(e){return this.ctx.getBlockLabel(e)}getCurrentUnstableMarker(){if(!(typeof this.ctx.getCurrentUnstableMarker>"u"))return this.ctx.getCurrentUnstableMarker()}}const q="1.28.0";function Ve(t){return t.__renderLambda===!0}function re(t){if(t!==void 0)return Ve(t)?t.handle:t}function V(t){if(t!==void 0)return typeof t=="string"?{__renderLambda:!0,handle:t,retentive:!1}:t}function Nt(t){if(t.v3!==void 0){const{initialArgs:e,initialUiState:n,inputsValid:r,outputs:i,renderingMode:s,sdkVersion:o,sections:a,title:l}=t.v3,{code:d}=t;return{initialArgs:e,initialUiState:n,inputsValid:r,outputs:i,renderingMode:s,sdkVersion:o,sections:a,title:l,code:d}}else if(t.inputsValid!==void 0){const{sdkVersion:e,renderingMode:n,outputs:r,inputsValid:i,sections:s,initialArgs:o,code:a}=t,l=Object.keys(t);if(e===void 0||n===void 0||r===void 0||i===void 0||s===void 0||o===void 0)throw new Error(`Malformed config v2. SDK version ${e}; Fields = ${l.join(", ")}`);return{sdkVersion:e,renderingMode:n,initialArgs:o,outputs:Object.fromEntries(Object.entries(r).map(([d,P])=>[d,V(P)])),inputsValid:V(i),sections:V(s),initialUiState:void 0,code:a}}else if(t.renderingMode!==void 0){const{sdkVersion:e,canRun:n,renderingMode:r,outputs:i,sections:s,initialArgs:o,code:a}=t,l=Object.keys(t);if(r===void 0||i===void 0||n===void 0||s===void 0||o===void 0)throw new Error(`Malformed config v1. SDK version ${e}; Fields = ${l.join(", ")}`);return{sdkVersion:e??"unknown",renderingMode:r,initialArgs:o,outputs:Object.fromEntries(Object.entries(i).map(([d,P])=>[d,V(P)])),inputsValid:V(n),sections:V(s),initialUiState:void 0,code:a}}else{const{sdkVersion:e}=t,n=Object.keys(t);throw new Error(`Config format not supported: SDK = ${e}; Fields = ${n.join(", ")}`)}}class T{constructor(e,n,r,i,s,o,a){this._renderingMode=e,this._initialArgs=n,this._initialUiState=r,this._outputs=i,this._inputsValid=s,this._sections=o,this._title=a}static create(e="Heavy"){return new T(e,void 0,{},{},W(!0),W([]),void 0)}output(e,n,r={}){if(typeof n=="function"){const i=`output#${e}`;return ne(i,()=>n(new G)),new T(this._renderingMode,this._initialArgs,this._initialUiState,{...this._outputs,[e]:{__renderLambda:!0,handle:i,...r}},this._inputsValid,this._sections,this._title)}else return new T(this._renderingMode,this._initialArgs,this._initialUiState,{...this._outputs,[e]:n},this._inputsValid,this._sections,this._title)}retentiveOutput(e,n){return this.output(e,n,{retentive:!0})}argsValid(e){return typeof e=="function"?(ne("inputsValid",()=>e(new G)),new T(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,{__renderLambda:!0,handle:"inputsValid"},this._sections,this._title)):new T(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,e,this._sections,this._title)}sections(e){return Array.isArray(e)?this.sections(W(e)):typeof e=="function"?(ne("sections",()=>e(new G)),new T(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,this._inputsValid,{__renderLambda:!0,handle:"sections"},this._title)):new T(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,this._inputsValid,e,this._title)}title(e){return ne("title",()=>e(new G)),new T(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,this._inputsValid,this._sections,{__renderLambda:!0,handle:"title"})}initialArgs(e){return new T(this._renderingMode,e,this._initialUiState,this._outputs,this._inputsValid,this._sections,this._title)}withArgs(e){return new T(this._renderingMode,e,this._initialUiState,this._outputs,this._inputsValid,this._sections,this._title)}withUiState(e){return new T(this._renderingMode,this._initialArgs,e,this._outputs,this._inputsValid,this._sections,this._title)}done(){if(this._initialArgs===void 0)throw new Error("Initial arguments not set.");const e={v3:{sdkVersion:q,renderingMode:this._renderingMode,initialArgs:this._initialArgs,initialUiState:this._initialUiState,inputsValid:this._inputsValid,sections:this._sections,title:this._title,outputs:this._outputs},sdkVersion:q,renderingMode:this._renderingMode,initialArgs:this._initialArgs,inputsValid:re(this._inputsValid),sections:re(this._sections),outputs:Object.fromEntries(Object.entries(this._outputs).map(([n,r])=>[n,re(r)]))};return wt()?Se({sdkVersion:q}):{config:e}}}function $t(t,e,n,r){var d,P;Array.isArray(r)&&(r={filters:r});const i=t.resultPool.getData().entries.map(f=>f.obj).filter(u.isPColumn).filter(f=>f.spec.name==="pl7.app/label"&&f.spec.axesSpec.length===1),s=(f,c)=>{let h=f.toString();if(c)for(const p in c)h+=p,h+=c[p];return h},o=new Map;for(const f of e)for(const c of f.spec.axesSpec){const h=u.getAxisId(c);for(const p of i){const b=p.spec.axesSpec[0],v=u.getAxisId(p.spec.axesSpec[0]);if(u.matchAxisId(h,v)){const y=Object.keys(h.domain??{}).length,A=Object.keys(v.domain??{}).length;if(y>A){const m=s(p.id,h.domain);o.set(m,{id:m,spec:{...p.spec,axesSpec:[{...h,annotations:b.annotations}]},data:p.data})}else o.set(s(p.id),p)}}}if([...e,...o.values()].some(f=>f.data instanceof L&&!f.data.getIsReadyOrError()))return;let a=e;const l=[];if(r!=null&&r.coreColumnPredicate){a=[];for(const f of e)r.coreColumnPredicate(f.spec)?a.push(f):l.push(f)}return l.push(...o.values()),t.createPTable({src:{type:"outer",primary:{type:(r==null?void 0:r.coreJoinType)??"full",entries:a.map(f=>({type:"column",column:f}))},secondary:l.map(f=>({type:"column",column:f}))},filters:[...(r==null?void 0:r.filters)??[],...((d=n==null?void 0:n.pTableParams)==null?void 0:d.filters)??[]],sorting:((P=n==null?void 0:n.pTableParams)==null?void 0:P.sorting)??[]})}function Ut(t,e,n){const r=t.resultPool.findLabels(e);return{axis:e,options:n.map(i=>({value:i,label:(r==null?void 0:r[i])??i.toString()})),defaultValue:n[0]}}const Jt=(t,e)=>{let n=t.toString();return e==null||e.forEach(r=>{if(r)for(const[i,s]of Object.entries(r))n+=i,n+=s}),n};function Bt(t){if(!t.length)return[];let e=[[]];return t.forEach(n=>{const r=[];n.forEach(i=>{r.push(...e.map(s=>[...s,i]))}),e=r}),e}function Mt(t,e){const n=t.spec.axesSpec.map(u.getAxisId);return e.spec.axesSpec.map(u.getAxisId).every(i=>n.some(s=>u.matchAxisId(s,i)&&u.matchAxisId(i,s)))}function Ke(t,e){const n=t.spec.axesSpec.map(u.getAxisId);return e.spec.axesSpec.map(u.getAxisId).every(i=>n.some(s=>u.matchAxisId(s,i)))}const Ne="pl7.app/graph/isVirtual",pe="pl7.app/label";function be(t,e){const n=t.spec.axesSpec.map(u.getAxisId),r=e.spec.axesSpec.map(u.getAxisId);if(Mt(t,e))return[];if(!Ke(t,e))return[];const o=r.map(f=>n.filter(c=>u.matchAxisId(c,f))),a=Bt(o),l=new Set,d=new Set,P=a.map(f=>{const c=new Set;return f.map((h,p)=>{const b=e.spec.axesSpec[p].domain,v=h.domain;return Object.entries(v??{}).forEach(([y,A])=>{if((b==null?void 0:b[y])===void 0){const m=JSON.stringify([y,A]);c.add(m),l.add(m)}}),{...h,annotations:e.spec.axesSpec[p].annotations}}),c});return[...l].forEach(f=>{P.some(c=>!c.has(f))&&d.add(f)}),a.map((f,c)=>{var y;const h=Jt(e.id,f.map(A=>A.domain)),p=((y=e.spec.annotations)==null?void 0:y[pe])??"",b=[...P[c]].filter(A=>d.has(A)).sort().map(A=>{var m;return(m=JSON.parse(A))==null?void 0:m[1]}).join(" / "),v={...e.spec.annotations,[Ne]:"true"};return(p||b)&&(v[pe]=p&&b?p+" / "+b:p+b),{id:h,spec:{...e.spec,axesSpec:f.map((A,m)=>({...A,annotations:e.spec.axesSpec[m].annotations})),annotations:v},data:e.data}})}function $e(t){const e=[];for(let n=0;n<t.length;n++)for(let r=n+1;r<t.length;r++){const i=t[n],s=t[r];e.push(...be(i,s),...be(s,i))}return e}function Ue(t,e){const n=[...t];for(const r of e)for(const i of t){if(i.id===r.id)break;if(Ke(i,r)){n.push(r);break}}return n}const Gt=["Int","Long","Float","Double","String","Bytes"];function Wt(t,e){if(e===void 0)return;const n=t.resultPool.getData().entries.map(s=>s.obj).filter(u.isPColumn).filter(s=>Gt.includes(s.spec.valueType)),r=Ue(e,n),i=[...r,...$e(r)];if(!i.some(s=>s.data instanceof L&&!s.data.getIsReadyOrError()))return t.createPFrame(i)}class qt{constructor(e){this.handle=e}async findColumns(e){return await platforma.pFrameDriver.findColumns(this.handle,e)}async getColumnSpec(e){return await platforma.pFrameDriver.getColumnSpec(this.handle,e)}async listColumns(){return await platforma.pFrameDriver.listColumns(this.handle)}async calculateTableData(e){return await platforma.pFrameDriver.calculateTableData(this.handle,e)}async getUniqueValues(e){return await platforma.pFrameDriver.getUniqueValues(this.handle,e)}}function Je(t){return fe({__isRef:!0,blockId:H(t,"blockId"),name:H(t,"name")})}function Ht(t){return fe({ref:Je(H(t,"ref")),label:H(t,"label")})}const zt={sdkVersion:q};function Be(){return Se({sdkVersion:q})}function Yt(t){try{return Be()}catch{return t}}function Xt(t){if(typeof globalThis.getEnvironmentValue=="function")return globalThis.getEnvironmentValue(t)}exports.Args=Ye;exports.BlockModel=T;exports.CurrentSdkInfo=zt;exports.FutureRef=I;exports.IS_VIRTUAL_COLUMN=Ne;exports.It=Xe;exports.JsRenderInternal=Lt;exports.LABEL_ANNOTATION=pe;exports.MainOutputs=Qe;exports.OutputError=Ae;exports.PAnnotationLabel=Ce;exports.PAnnotationTrace=_e;exports.PColumnCollection=de;exports.PFrameImpl=qt;exports.RT_BINARY_PARTITIONED=D;exports.RT_BINARY_SUPER_PARTITIONED=$;exports.RT_JSON_PARTITIONED=N;exports.RT_JSON_SUPER_PARTITIONED=X;exports.RT_RESOURCE_MAP=z;exports.RT_RESOURCE_MAP_PARTITIONED=Y;exports.RenderCtx=G;exports.ResultPool=je;exports.StagingOutputs=Ze;exports.Trace=Te;exports.TraceEntry=Le;exports.TreeNodeAccessor=L;exports.UiState=et;exports.and=at;exports.convertOrParsePColumnData=Fe;exports.createPFrameForGraphs=Wt;exports.createPlDataTable=$t;exports.createPlDataTableSheet=Ut;exports.deriveLabels=he;exports.downgradeCfgOrLambda=re;exports.enrichColumnsWithCompatible=Ue;exports.extractArchiveAndGetURL=yt;exports.extractConfig=Nt;exports.filterDataInfoEntries=ke;exports.flatten=it;exports.fromPlOption=Ht;exports.fromPlRef=Je;exports.getAdditionalColumns=$e;exports.getBlobContent=pt;exports.getBlobContentAsJson=ht;exports.getBlobContentAsString=ft;exports.getDownloadedBlobContent=gt;exports.getEnvironmentValue=Xt;exports.getFromCfg=U;exports.getImmediate=W;exports.getImportProgress=bt;exports.getJsonField=H;exports.getLastLogs=vt;exports.getLogHandle=St;exports.getOnDemandBlobContent=mt;exports.getPartitionKeysList=Ee;exports.getPlatformaOrDefault=Yt;exports.getProgressLog=At;exports.getProgressLogWithInfo=Pt;exports.getRawPlatformaInstance=Be;exports.getResourceField=ut;exports.getResourceValueAsJson=ct;exports.getUniquePartitionKeys=De;exports.ifDef=ie;exports.isConfigLambda=Ve;exports.isEmpty=st;exports.isolate=ze;exports.makeArray=tt;exports.makeObject=fe;exports.mapArrayValues=rt;exports.mapRecordValues=nt;exports.mapResourceFields=dt;exports.not=ot;exports.or=lt;exports.parsePColumnData=se;exports.parseResourceMap=Ot;exports.readOutput=Pe;exports.wrapOutputs=He;Object.keys(u).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>u[t]})});Object.keys(ge).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>ge[t]})});
2
2
  //# sourceMappingURL=index.js.map