@platforma-sdk/model 1.20.11 → 1.20.24

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 _e=Object.defineProperty;var ve=(t,e,n)=>e in t?_e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var w=(t,e,n)=>ve(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@milaboratories/pl-model-common"),I=require("zod");class te extends Error{constructor(e,n){super(`${e.length}${n?"+":""} errors, first error: `+e[0]),this.errors=e,this.moreErrors=n}}function ne(t){if(!t.ok)throw new te(t.errors,t.moreErrors);return t.value}function Se(t){return new Proxy(t,{get(e,n){return ne(e[n])}})}function g(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||t===null?D(t):t}function T(t){return{type:"GetFromCtx",variable:t}}function Pe(t){return{type:"Isolate",cfg:t}}const we=T("$args"),Ae=T("$it"),Re=T("$prod"),Ce=T("$staging"),Ie=T("$ui");function D(t){return{type:"Immediate",value:t}}function z(t){const e={};for(const[n,r]of Object.entries(t))e[n]=g(r);return{type:"MakeObject",template:e}}function Te(...t){const e=[];for(const n of t)e.push(g(n));return{type:"MakeArray",template:e}}function L(t,e){return{type:"GetJsonField",source:g(t),field:g(e)}}function Oe(t,e,n="$it"){return{type:"MapRecordValues",source:t,mapping:e,itVar:n}}function Fe(t,e,n="$it"){return{type:"MapArrayValues",source:t,mapping:e,itVar:n}}function De(t){return{type:"Flatten",source:t}}function Ee(t){return{type:"IsEmpty",arg:t}}function Le(t){return{type:"Not",operand:t}}function ke(t,e){return{type:"And",operand1:t,operand2:e}}function xe(t,e){return{type:"Or",operand1:t,operand2:e}}function Ve(t,e){return{type:"GetResourceField",source:g(t),field:g(e)}}function je(){return function(t){return{type:"GetResourceValueAsJson",source:g(t)}}}function Ne(t,e,n="$it"){return{type:"MapResourceFields",source:t,mapping:e,itVar:n}}function Be(t){return{type:"GetBlobContent",source:g(t)}}function Me(t){return{type:"GetBlobContentAsString",source:g(t)}}function Ue(){return function(t){return{type:"GetBlobContentAsJson",source:g(t)}}}function Je(t){return{type:"GetDownloadedBlobContent",source:g(t)}}function $e(t){return{type:"GetOnDemandBlobContent",source:g(t)}}function Ke(t){return{type:"GetImportProgress",source:g(t)}}function Ge(t,e){return{type:"GetLastLogs",source:g(t),lines:e}}function He(t,e){return{type:"GetProgressLog",source:g(t),patternToSearch:e}}function We(t){return{type:"GetLogHandle",source:g(t)}}function ze(){return typeof globalThis.getPlatforma<"u"||typeof globalThis.platforma<"u"}function re(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 qe(){if(typeof globalThis.cfgRenderCtx<"u")return globalThis.cfgRenderCtx}function u(){if(typeof globalThis.cfgRenderCtx<"u")return globalThis.cfgRenderCtx;throw new Error("Not in config rendering context")}function x(t,e){const n=qe();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 $=new Map;function Ye(t,e){t in u().callbackRegistry||(u().callbackRegistry[t]=n=>{for(const r of $.get(t))r(n)},$.set(t,[])),$.get(t).push(e)}class v{constructor(e,n=r=>r){w(this,"isResolved",!1);w(this,"resolvedValue");this.handle=e,this.postProcess=n,Ye(e,r=>{this.resolvedValue=n(r),this.isResolved=!0})}map(e){return new v(this.handle,n=>e(this.postProcess(n)))}mapDefined(e){return new v(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 Q(t){return t===void 0?void 0:new S(t)}class S{constructor(e){this.handle=e}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){return Q(u().resolveWithCommon(this.handle,e,...n))}get resourceType(){return u().getResourceType(this.handle)}getInputsLocked(){return u().getInputsLocked(this.handle)}getOutputsLocked(){return u().getOutputsLocked(this.handle)}getIsReadyOrError(){return u().getIsReadyOrError(this.handle)}getIsFinal(){return u().getIsFinal(this.handle)}getError(){return Q(u().getError(this.handle))}listInputFields(){return u().listInputFields(this.handle)}listOutputFields(){return u().listOutputFields(this.handle)}listDynamicFields(){return u().listDynamicFields(this.handle)}getKeyValueBase64(e){return u().getKeyValueBase64(this.handle,e)}getKeyValueAsString(e){return u().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 u().getDataBase64(this.handle)}getDataAsString(){return u().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(([,i])=>{if(!f.isPColumn(i))throw new Error(`not a PColumn (kind = ${i.spec.kind})`);return i})}parsePObjectCollection(e=!1,n=""){const r=u().parsePObjectCollection(this.handle,e,n);if(r===void 0)return;const s={};for(const[i,o]of Object.entries(r))s[i]=f.mapPObjectData(o,l=>new S(l));return s}getFileContentAsBase64(){return new v(u().getBlobContentAsBase64(this.handle))}getFileContentAsString(){return new v(u().getBlobContentAsString(this.handle))}getFileContentAsJson(){return new v(u().getBlobContentAsString(this.handle)).mapDefined(e=>JSON.parse(e))}getBlobContentAsBase64(){return this.getFileContentAsBase64()}getBlobContentAsString(){return this.getFileContentAsString()}getFileHandle(){return new v(u().getDownloadedBlobContentHandle(this.handle))}getDownloadedBlobHandle(){return this.getFileHandle()}getRemoteFileHandle(){return new v(u().getOnDemandBlobContentHandle(this.handle))}getOnDemandBlobHandle(){return this.getRemoteFileHandle()}getImportProgress(){return new v(u().getImportProgress(this.handle))}getLastLogs(e){return new v(u().getLastLogs(this.handle,e))}getProgressLog(e){return new v(u().getProgressLog(this.handle,e))}getLogHandle(){return new v(u().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:s,skipUnresolved:i}={fieldType:"Input",requireLocked:!0,skipUnresolved:!1,...n},o=e;if(s&&(r==="Input"&&!this.getInputsLocked()||r==="Output"&&!this.getOutputsLocked()))return;let d=(r==="Input"?this.listInputFields():r==="Output"?this.listOutputFields():this.listDynamicFields()).map(a=>[a,this.resolve({field:a,assertFieldType:r})]);return i&&(d=d.filter(a=>a[1]!==void 0)),d.map(([a,p])=>o(a,p))}}const se="staging",ie="main",Xe={inlineColumnsSupport:!0};function oe(t){return typeof t=="object"&&t!==null&&"__awaited_futures__"in t}function K(t,e,n){if(e.has(n))return;if(e.add(n),typeof n==="object")if(oe(n))n.__awaited_futures__.forEach(s=>t.add(s));else if(Array.isArray(n))for(const s of n)K(t,e,s);else for(const[,s]of Object.entries(n))s!==n&&K(t,e,s)}function Qe(t){const e=new Set;return K(e,new Set,t),e}const Ze=Object.freeze(Object.defineProperty({__proto__:null,GlobalCfgRenderCtxFeatureFlags:Xe,MainAccessorName:ie,StagingAccessorName:se,getAllFutureAwaits:Qe,isFutureAwait:oe},Symbol.toStringTag,{value:"Module"})),ae="pl7.app/label",le="pl7.app/trace",ue=I.z.object({type:I.z.string(),importance:I.z.number().optional(),id:I.z.string().optional(),label:I.z.string()}),ce=I.z.array(ue),et=.001,tt="__LABEL__",Z="__LABEL__@1";function de(t,e,n={}){const r=new Map,s=new Map,i=t.map(c=>{var Y,X;const y=e(c),h=(Y=y.annotations)==null?void 0:Y[ae],A=(X=y.annotations)==null?void 0:X[le],b=(A?ce.safeParse(JSON.parse(A)).data:void 0)??[];if(h){const P={label:h,type:tt,importance:-2};n.addLabelAsSuffix?b.push(P):b.splice(0,0,P)}const R=[],q=new Map;for(let P=b.length-1;P>=0;--P){const{type:U}=b[P],be=b[P].importance??0,J=(q.get(U)??0)+1;q.set(U,J);const O=`${U}@${J}`;s.set(O,(s.get(O)??0)+1),r.set(O,Math.max(r.get(O)??Number.NEGATIVE_INFINITY,be-(b.length-P)*et)),R.push({...b[P],fullType:O,occurenceIndex:J})}return R.reverse(),{value:c,spec:y,label:h,fullTrace:R}}),o=[],l=[],d=[...r];d.sort(([,c],[,y])=>y-c);for(const[c]of d)c.endsWith("@1")||s.get(c)===t.length?o.push(c):l.push(c);const a=c=>i.map(y=>{const h=y.fullTrace.filter(b=>c.has(b.fullType)).map(b=>b.label),A=n.separator??" / ";return{label:h.join(A),value:y.value}});if(o.length===0){if(l.length!==0)throw new Error("Assertion error.");return a(new Set(Z))}let p=0,m=0;for(;p<o.length;){const c=new Set;n.includeNativeLabel&&c.add(Z);for(let h=0;h<p;++h)c.add(o[h]);c.add(o[m]);const y=a(c);if(new Set(y.map(h=>h.label)).size===t.length)return y;m++,m==o.length&&(p++,m=p)}return a(new Set([...o,...l]))}class pe{constructor(){w(this,"ctx",u());w(this,"defaultLabelFn",(e,n)=>{var r;return((r=e.annotations)==null?void 0:r["pl7.app/label"])??"Unlabelled"})}calculateOptions(e){return this.ctx.calculateOptions(e)}getOptions(e,n){const r=this.getSpecs().entries.filter(s=>e(s.obj));return typeof n=="object"||typeof n>"u"?de(r,s=>s.obj,n??{}).map(({value:{ref:s},label:i})=>({ref:s,label:i})):r.map(s=>({ref:s.ref,label:n(s.obj,s.ref)}))}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 S(n.obj.data)}}))}}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:f.mapValueInVOE(n.obj.data,r=>new S(r))}}))}}getSpecsFromResultPool(){return this.getSpecs()}getSpecs(){return this.ctx.getSpecsFromResultPool()}getDataByRef(e){var n;return typeof this.ctx.getDataFromResultPoolByRef>"u"?(n=this.getData().entries.find(r=>r.ref.blockId===e.blockId&&r.ref.name===e.name))==null?void 0:n.obj:f.mapPObjectData(this.ctx.getDataFromResultPoolByRef(e.blockId,e.name),r=>new S(r))}getPColumnByRef(e){const n=this.getDataByRef(e);if(n)return f.ensurePColumn(n)}getPColumnSpecByRef(e){const n=this.getSpecByRef(e);if(n){if(!f.isPColumnSpec(n))throw new Error(`not a PColumn spec (kind = ${n.kind})`);return n}}getSpecByRef(e){var n;return typeof this.ctx.getSpecFromResultPoolByRef>"u"?(n=this.getSpecs().entries.find(r=>r.ref.blockId===e.blockId&&r.ref.name===e.name))==null?void 0:n.obj:this.ctx.getSpecFromResultPoolByRef(e.blockId,e.name)}findDataWithCompatibleSpec(e){const n=[];e:for(const r of this.getData().entries){if(!f.isPColumnSpec(r.obj.spec))continue;const s=r.obj.spec;if(e.name===s.name&&e.valueType===s.valueType&&e.axesSpec.length===s.axesSpec.length&&G(e.domain,s.domain)){for(let i=0;i<e.axesSpec.length;++i){const o=e.axesSpec[i],l=s.axesSpec[i];if(o.name!==l.name||o.type!==l.type||!G(o.domain,l.domain))continue e}n.push(r.obj)}}return n}}function G(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}class F{constructor(){w(this,"ctx");w(this,"args");w(this,"uiState");w(this,"resultPool",new pe);this.ctx=u(),this.args=JSON.parse(this.ctx.args),this.uiState=this.ctx.uiState!==void 0?JSON.parse(this.ctx.uiState):void 0}getNamedAccessor(e){const n=this.ctx.getAccessorHandleByName(e);return n?new S(n):void 0}get prerun(){return this.getNamedAccessor(se)}get precalc(){return this.prerun}get stagingOutput(){return this.precalc}get outputs(){return this.getNamedAccessor(ie)}get mainOutput(){return this.outputs}findLabels(e){const n=this.resultPool.getData();for(const r of n.entries){if(!f.isPColumn(r.obj))continue;const s=r.obj.spec;if(s.name==="pl7.app/label"&&s.axesSpec.length===1&&s.axesSpec[0].name===e.name&&s.axesSpec[0].type===e.type&&G(e.domain,s.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]]))}}}verifyInlineColumnsSupport(e){var s;const n=e.some(i=>!(i.data instanceof S)),r=((s=this.ctx.featureFlags)==null?void 0:s.inlineColumnsSupport)===!0;if(n&&!r)throw Error("inline columns not supported")}createPFrame(e){return this.verifyInlineColumnsSupport(e),this.ctx.createPFrame(e.map(n=>f.mapPObjectData(n,r=>r instanceof S?r.handle:r)))}createPTable(e){var 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.verifyInlineColumnsSupport(f.extractAllColumns(n.src)),this.ctx.createPTable(f.mapPTableDef(n,r=>f.mapPObjectData(r,s=>s instanceof S?s.handle:s)))}getBlockLabel(e){return this.ctx.getBlockLabel(e)}getCurrentUnstableMarker(){if(!(typeof this.ctx.getCurrentUnstableMarker>"u"))return this.ctx.getCurrentUnstableMarker()}}const k="PColumnData/",B=k+"ResourceMap",M=k+"Partitioned/ResourceMap",H=k+"JsonPartitioned",V=k+"BinaryPartitioned",fe=k+"Partitioned/",W=fe+"JsonPartitioned",j=fe+"BinaryPartitioned";function ge(t,e,n,r=[],s){if(t===void 0)return!1;switch(t.resourceType.name){case B:{let i=t.getInputsLocked();for(const o of t.listInputFields()){const l=t.resolve({field:o,assertFieldType:"Input"}),d=[...r,...JSON.parse(o)],a=l===void 0?void 0:e(l);a===void 0&&(i=!1),(a!==void 0||s)&&n.push({key:d,value:a})}return i}case M:{let i=t.getInputsLocked();for(const o of t.listInputFields()){const l=t.resolve({field:o,assertFieldType:"Input"});if(l===void 0)i=!1;else{const d=[...r,...JSON.parse(o)],a=ge(l,e,n,d,s);i=i&&a}}return i}default:throw new Error(`Unknown resource type: ${t.resourceType.name}`)}}function nt(t,e,n=!1){const r=[];return{isComplete:ge(t,e,r,[],n),data:r}}const ee=t=>{if(!t.endsWith(".index")){if(t.endsWith(".values"))return t.substring(0,t.length-7);throw Error(`key must ends on .index/.values for binary p-column, got: ${t}`)}};function he(t){if(!t)return;const e=t.resourceType.name,n=t.getDataAsJson(),r=[];let s=0;switch(e){case B:s=n.keyLength;break;case M:s=n.partitionKeyLength+n.keyLength;break;case H:case V:s=n.partitionKeyLength;break;case j:case W:s=n.superPartitionKeyLength+n.partitionKeyLength;break}switch(e){case B:case H:case V:for(let i of t.listInputFields()){if(e===V){const l=ee(i);if(l)i=l;else continue}const o=[...JSON.parse(i)];r.push(o)}break;case M:case j:case W:for(const i of t.listInputFields()){const o=[...JSON.parse(i)],l=t.resolve({field:i,assertFieldType:"Input"});if(l!==void 0)for(let d of l.listInputFields()){if(e===j){const p=ee(d);if(p)d=p;else continue}const a=[...o,...JSON.parse(d)];r.push(a)}}break}return{data:r,keyLength:s}}function rt(t){const e=he(t);if(!e)return;const{data:n,keyLength:r}=e,s=[];for(let i=0;i<r;++i)s.push(new Set);for(const i of n){if(i.length!==r)throw new Error("key length does not match partition length");for(let o=0;o<r;++o)s[o].add(i[o])}return s.map(i=>Array.from(i.values()))}const E="1.20.11";function me(t){return t.__renderLambda===!0}function N(t){if(t!==void 0)return me(t)?t.handle:t}function C(t){if(t!==void 0)return typeof t=="string"?{__renderLambda:!0,handle:t,retentive:!1}:t}function st(t){if(t.v3!==void 0){const{initialArgs:e,initialUiState:n,inputsValid:r,outputs:s,renderingMode:i,sdkVersion:o,sections:l,title:d}=t.v3,{code:a}=t;return{initialArgs:e,initialUiState:n,inputsValid:r,outputs:s,renderingMode:i,sdkVersion:o,sections:l,title:d,code:a}}else if(t.inputsValid!==void 0){const{sdkVersion:e,renderingMode:n,outputs:r,inputsValid:s,sections:i,initialArgs:o,code:l}=t,d=Object.keys(t);if(e===void 0||n===void 0||r===void 0||s===void 0||i===void 0||o===void 0)throw new Error(`Malformed config v2. SDK version ${e}; Fields = ${d.join(", ")}`);return{sdkVersion:e,renderingMode:n,initialArgs:o,outputs:Object.fromEntries(Object.entries(r).map(([a,p])=>[a,C(p)])),inputsValid:C(s),sections:C(i),initialUiState:void 0,code:l}}else if(t.renderingMode!==void 0){const{sdkVersion:e,canRun:n,renderingMode:r,outputs:s,sections:i,initialArgs:o,code:l}=t,d=Object.keys(t);if(r===void 0||s===void 0||n===void 0||i===void 0||o===void 0)throw new Error(`Malformed config v1. SDK version ${e}; Fields = ${d.join(", ")}`);return{sdkVersion:e??"unknown",renderingMode:r,initialArgs:o,outputs:Object.fromEntries(Object.entries(s).map(([a,p])=>[a,C(p)])),inputsValid:C(n),sections:C(i),initialUiState:void 0,code:l}}else{const{sdkVersion:e}=t,n=Object.keys(t);throw new Error(`Config format not supported: SDK = ${e}; Fields = ${n.join(", ")}`)}}class _{constructor(e,n,r,s,i,o,l){this._renderingMode=e,this._initialArgs=n,this._initialUiState=r,this._outputs=s,this._inputsValid=i,this._sections=o,this._title=l}static create(e="Heavy"){return new _(e,void 0,{},{},D(!0),D([]),void 0)}output(e,n,r={}){if(typeof n=="function"){const s=`output#${e}`;return x(s,()=>n(new F)),new _(this._renderingMode,this._initialArgs,this._initialUiState,{...this._outputs,[e]:{__renderLambda:!0,handle:s,...r}},this._inputsValid,this._sections,this._title)}else return new _(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})}canRun(e){return this.inputsValid(e)}argsValid(e){return typeof e=="function"?(x("inputsValid",()=>e(new F)),new _(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,{__renderLambda:!0,handle:"inputsValid"},this._sections,this._title)):new _(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,e,this._sections,this._title)}inputsValid(e){return this.argsValid(e)}sections(e){return Array.isArray(e)?this.sections(D(e)):typeof e=="function"?(x("sections",()=>e(new F)),new _(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,this._inputsValid,{__renderLambda:!0,handle:"sections"},this._title)):new _(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,this._inputsValid,e,this._title)}title(e){return x("title",()=>e(new F)),new _(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,this._inputsValid,this._sections,{__renderLambda:!0,handle:"title"})}initialArgs(e){return new _(this._renderingMode,e,this._initialUiState,this._outputs,this._inputsValid,this._sections,this._title)}withArgs(e){return new _(this._renderingMode,e,this._initialUiState,this._outputs,this._inputsValid,this._sections,this._title)}withUiState(e){return new _(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:E,renderingMode:this._renderingMode,initialArgs:this._initialArgs,initialUiState:this._initialUiState,inputsValid:this._inputsValid,sections:this._sections,title:this._title,outputs:this._outputs},sdkVersion:E,renderingMode:this._renderingMode,initialArgs:this._initialArgs,inputsValid:N(this._inputsValid),sections:N(this._sections),outputs:Object.fromEntries(Object.entries(this._outputs).map(([n,r])=>[n,N(r)]))};return ze()?re({sdkVersion:E}):{config:e}}}function it(t,e,n,r){var l,d;const s=t.resultPool.getData().entries.map(a=>a.obj).filter(f.isPColumn).filter(a=>a.spec.name==="pl7.app/label"&&a.spec.axesSpec.length===1),i=(a,p)=>{let m=a.toString();if(p)for(const c in p)m+=c,m+=p[c];return m},o=new Map;for(const a of e)for(const p of a.spec.axesSpec){const m=f.getAxisId(p);for(const c of s){const y=c.spec.axesSpec[0],h=f.getAxisId(c.spec.axesSpec[0]);if(f.matchAxisId(m,h)){const A=Object.keys(m.domain??{}).length,b=Object.keys(h.domain??{}).length;if(A>b){const R=i(c.id,m.domain);o.set(R,{id:R,spec:{...c.spec,axesSpec:[{...m,annotations:y.annotations}]},data:c.data})}else o.set(i(c.id),c)}}}if(![...e,...o.values()].some(a=>a.data instanceof S&&!a.data.getIsReadyOrError()))return t.createPTable({src:{type:"outer",primary:{type:"full",entries:e.map(a=>({type:"column",column:a}))},secondary:[...o.values()].map(a=>({type:"column",column:a}))},filters:[...((l=n==null?void 0:n.pTableParams)==null?void 0:l.filters)??[],...r??[]],sorting:((d=n==null?void 0:n.pTableParams)==null?void 0:d.sorting)??[]})}function ot(t,e,n){const r=t.findLabels(e);return{axis:e,options:n.map(s=>({value:s,label:(r==null?void 0:r[s])??s.toString()})),defaultValue:n[0]}}class at{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 ye(t){return z({__isRef:!0,blockId:L(t,"blockId"),name:L(t,"name")})}function lt(t){return z({ref:ye(L(t,"ref")),label:L(t,"label")})}const ut={sdkVersion:E};function ct(){return re({sdkVersion:E})}function dt(t){if(typeof globalThis.getEnvironmentValue=="function")return globalThis.getEnvironmentValue(t)}exports.Args=we;exports.BlockModel=_;exports.CurrentSdkInfo=ut;exports.FutureRef=v;exports.It=Ae;exports.JsRenderInternal=Ze;exports.MainOutputs=Re;exports.OutputError=te;exports.PAnnotationLabel=ae;exports.PAnnotationTrace=le;exports.PFrameImpl=at;exports.RT_BINARY_PARTITIONED=V;exports.RT_BINARY_SUPER_PARTITIONED=j;exports.RT_JSON_PARTITIONED=H;exports.RT_JSON_SUPER_PARTITIONED=W;exports.RT_RESOURCE_MAP=B;exports.RT_RESOURCE_MAP_PARTITIONED=M;exports.RenderCtx=F;exports.ResultPool=pe;exports.StagingOutputs=Ce;exports.Trace=ce;exports.TraceEntry=ue;exports.TreeNodeAccessor=S;exports.UiState=Ie;exports.and=ke;exports.createPlDataTable=it;exports.createPlDataTableSheet=ot;exports.deriveLabels=de;exports.downgradeCfgOrLambda=N;exports.extractConfig=st;exports.flatten=De;exports.fromPlOption=lt;exports.fromPlRef=ye;exports.getBlobContent=Be;exports.getBlobContentAsJson=Ue;exports.getBlobContentAsString=Me;exports.getDownloadedBlobContent=Je;exports.getEnvironmentValue=dt;exports.getFromCfg=T;exports.getImmediate=D;exports.getImportProgress=Ke;exports.getJsonField=L;exports.getLastLogs=Ge;exports.getLogHandle=We;exports.getOnDemandBlobContent=$e;exports.getPartitionKeysList=he;exports.getProgressLog=He;exports.getRawPlatformaInstance=ct;exports.getResourceField=Ve;exports.getResourceValueAsJson=je;exports.getUniquePartitionKeys=rt;exports.isConfigLambda=me;exports.isEmpty=Ee;exports.isolate=Pe;exports.makeArray=Te;exports.makeObject=z;exports.mapArrayValues=Fe;exports.mapRecordValues=Oe;exports.mapResourceFields=Ne;exports.not=Le;exports.or=xe;exports.parseResourceMap=nt;exports.readOutput=ne;exports.wrapOutputs=Se;Object.keys(f).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>f[t]})});
1
+ "use strict";var _e=Object.defineProperty;var ve=(t,e,n)=>e in t?_e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var w=(t,e,n)=>ve(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@milaboratories/pl-model-common"),I=require("zod");class te extends Error{constructor(e,n){super(`${e.length}${n?"+":""} errors, first error: `+e[0]),this.errors=e,this.moreErrors=n}}function ne(t){if(!t.ok)throw new te(t.errors,t.moreErrors);return t.value}function Pe(t){return new Proxy(t,{get(e,n){return ne(e[n])}})}function h(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||t===null?D(t):t}function O(t){return{type:"GetFromCtx",variable:t}}function Se(t){return{type:"Isolate",cfg:t}}const we=O("$args"),Re=O("$it"),Ce=O("$prod"),Ae=O("$staging"),Ie=O("$ui");function D(t){return{type:"Immediate",value:t}}function q(t){const e={};for(const[n,r]of Object.entries(t))e[n]=h(r);return{type:"MakeObject",template:e}}function Oe(...t){const e=[];for(const n of t)e.push(h(n));return{type:"MakeArray",template:e}}function L(t,e){return{type:"GetJsonField",source:h(t),field:h(e)}}function Te(t,e,n="$it"){return{type:"MapRecordValues",source:t,mapping:e,itVar:n}}function Fe(t,e,n="$it"){return{type:"MapArrayValues",source:t,mapping:e,itVar:n}}function De(t){return{type:"Flatten",source:t}}function Ee(t){return{type:"IsEmpty",arg:t}}function Le(t){return{type:"Not",operand:t}}function ke(t,e){return{type:"And",operand1:t,operand2:e}}function xe(t,e){return{type:"Or",operand1:t,operand2:e}}function Ve(t,e){return{type:"GetResourceField",source:h(t),field:h(e)}}function je(){return function(t){return{type:"GetResourceValueAsJson",source:h(t)}}}function Ne(t,e,n="$it"){return{type:"MapResourceFields",source:t,mapping:e,itVar:n}}function Be(t){return{type:"GetBlobContent",source:h(t)}}function Me(t){return{type:"GetBlobContentAsString",source:h(t)}}function Ue(){return function(t){return{type:"GetBlobContentAsJson",source:h(t)}}}function Je(t){return{type:"GetDownloadedBlobContent",source:h(t)}}function $e(t){return{type:"GetOnDemandBlobContent",source:h(t)}}function Ke(t){return{type:"GetImportProgress",source:h(t)}}function Ge(t,e){return{type:"GetLastLogs",source:h(t),lines:e}}function He(t,e){return{type:"GetProgressLog",source:h(t),patternToSearch:e}}function We(t){return{type:"GetLogHandle",source:h(t)}}function ze(){return typeof globalThis.getPlatforma<"u"||typeof globalThis.platforma<"u"}function re(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 qe(){if(typeof globalThis.cfgRenderCtx<"u")return globalThis.cfgRenderCtx}function u(){if(typeof globalThis.cfgRenderCtx<"u")return globalThis.cfgRenderCtx;throw new Error("Not in config rendering context")}function x(t,e){const n=qe();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 K=new Map;function Ye(t,e){t in u().callbackRegistry||(u().callbackRegistry[t]=n=>{for(const r of K.get(t))r(n)},K.set(t,[])),K.get(t).push(e)}class v{constructor(e,n=r=>r){w(this,"isResolved",!1);w(this,"resolvedValue");this.handle=e,this.postProcess=n,Ye(e,r=>{this.resolvedValue=n(r),this.isResolved=!0})}map(e){return new v(this.handle,n=>e(this.postProcess(n)))}mapDefined(e){return new v(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 B(t,e){return t===void 0?void 0:e(t)}class P{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(s=>typeof s=="string"?s:s.field)];return B(u().resolveWithCommon(this.handle,e,...n),s=>new P(s,r))}get resourceType(){return u().getResourceType(this.handle)}getInputsLocked(){return u().getInputsLocked(this.handle)}getOutputsLocked(){return u().getOutputsLocked(this.handle)}getIsReadyOrError(){return u().getIsReadyOrError(this.handle)}getIsFinal(){return u().getIsFinal(this.handle)}getError(){const e=[...this.resolvePath,"error"];return B(u().getError(this.handle),n=>new P(n,e))}listInputFields(){return u().listInputFields(this.handle)}listOutputFields(){return u().listOutputFields(this.handle)}listDynamicFields(){return u().listDynamicFields(this.handle)}getKeyValueBase64(e){return u().getKeyValueBase64(this.handle,e)}getKeyValueAsString(e){return u().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 u().getDataBase64(this.handle)}getDataAsString(){return u().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(([,i])=>{if(!f.isPColumn(i))throw new Error(`not a PColumn (kind = ${i.spec.kind})`);return i})}parsePObjectCollection(e=!1,n=""){const r=u().parsePObjectCollection(this.handle,e,n,...this.resolvePath);if(r===void 0)return;const s={};for(const[i,o]of Object.entries(r)){const l=[...this.resolvePath,i];s[i]=f.mapPObjectData(o,d=>new P(d,l))}return s}getFileContentAsBase64(){return new v(u().getBlobContentAsBase64(this.handle))}getFileContentAsString(){return new v(u().getBlobContentAsString(this.handle))}getFileContentAsJson(){return new v(u().getBlobContentAsString(this.handle)).mapDefined(e=>JSON.parse(e))}getBlobContentAsBase64(){return this.getFileContentAsBase64()}getBlobContentAsString(){return this.getFileContentAsString()}getFileHandle(){return new v(u().getDownloadedBlobContentHandle(this.handle))}getDownloadedBlobHandle(){return this.getFileHandle()}getRemoteFileHandle(){return new v(u().getOnDemandBlobContentHandle(this.handle))}getOnDemandBlobHandle(){return this.getRemoteFileHandle()}getImportProgress(){return new v(u().getImportProgress(this.handle))}getLastLogs(e){return new v(u().getLastLogs(this.handle,e))}getProgressLog(e){return new v(u().getProgressLog(this.handle,e))}getLogHandle(){return new v(u().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:s,skipUnresolved:i}={fieldType:"Input",requireLocked:!0,skipUnresolved:!1,...n},o=e;if(s&&(r==="Input"&&!this.getInputsLocked()||r==="Output"&&!this.getOutputsLocked()))return;let d=(r==="Input"?this.listInputFields():r==="Output"?this.listOutputFields():this.listDynamicFields()).map(a=>[a,this.resolve({field:a,assertFieldType:r})]);return i&&(d=d.filter(a=>a[1]!==void 0)),d.map(([a,p])=>o(a,p))}}const se="staging",ie="main",Xe={inlineColumnsSupport:!0};function oe(t){return typeof t=="object"&&t!==null&&"__awaited_futures__"in t}function G(t,e,n){if(e.has(n))return;if(e.add(n),typeof n==="object")if(oe(n))n.__awaited_futures__.forEach(s=>t.add(s));else if(Array.isArray(n))for(const s of n)G(t,e,s);else for(const[,s]of Object.entries(n))s!==n&&G(t,e,s)}function Qe(t){const e=new Set;return G(e,new Set,t),e}const Ze=Object.freeze(Object.defineProperty({__proto__:null,GlobalCfgRenderCtxFeatureFlags:Xe,MainAccessorName:ie,StagingAccessorName:se,getAllFutureAwaits:Qe,isFutureAwait:oe},Symbol.toStringTag,{value:"Module"})),ae="pl7.app/label",le="pl7.app/trace",ue=I.z.object({type:I.z.string(),importance:I.z.number().optional(),id:I.z.string().optional(),label:I.z.string()}),ce=I.z.array(ue),et=.001,tt="__LABEL__",Z="__LABEL__@1";function de(t,e,n={}){const r=new Map,s=new Map,i=t.map(c=>{var X,Q;const y=e(c),g=(X=y.annotations)==null?void 0:X[ae],R=(Q=y.annotations)==null?void 0:Q[le],b=(R?ce.safeParse(JSON.parse(R)).data:void 0)??[];if(g){const S={label:g,type:tt,importance:-2};n.addLabelAsSuffix?b.push(S):b.splice(0,0,S)}const C=[],Y=new Map;for(let S=b.length-1;S>=0;--S){const{type:J}=b[S],be=b[S].importance??0,$=(Y.get(J)??0)+1;Y.set(J,$);const T=`${J}@${$}`;s.set(T,(s.get(T)??0)+1),r.set(T,Math.max(r.get(T)??Number.NEGATIVE_INFINITY,be-(b.length-S)*et)),C.push({...b[S],fullType:T,occurenceIndex:$})}return C.reverse(),{value:c,spec:y,label:g,fullTrace:C}}),o=[],l=[],d=[...r];d.sort(([,c],[,y])=>y-c);for(const[c]of d)c.endsWith("@1")||s.get(c)===t.length?o.push(c):l.push(c);const a=c=>i.map(y=>{const g=y.fullTrace.filter(b=>c.has(b.fullType)).map(b=>b.label),R=n.separator??" / ";return{label:g.join(R),value:y.value}});if(o.length===0){if(l.length!==0)throw new Error("Assertion error.");return a(new Set(Z))}let p=0,m=0;for(;p<o.length;){const c=new Set;n.includeNativeLabel&&c.add(Z);for(let g=0;g<p;++g)c.add(o[g]);c.add(o[m]);const y=a(c);if(new Set(y.map(g=>g.label)).size===t.length)return y;m++,m==o.length&&(p++,m=p)}return a(new Set([...o,...l]))}class pe{constructor(){w(this,"ctx",u());w(this,"defaultLabelFn",(e,n)=>{var r;return((r=e.annotations)==null?void 0:r["pl7.app/label"])??"Unlabelled"})}calculateOptions(e){return this.ctx.calculateOptions(e)}getOptions(e,n){const r=this.getSpecs().entries.filter(s=>e(s.obj));return typeof n=="object"||typeof n>"u"?de(r,s=>s.obj,n??{}).map(({value:{ref:s},label:i})=>({ref:s,label:i})):r.map(s=>({ref:s.ref,label:n(s.obj,s.ref)}))}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 P(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:f.mapValueInVOE(n.obj.data,r=>new P(r,[n.ref.blockId,n.ref.name]))}}))}}getSpecsFromResultPool(){return this.getSpecs()}getSpecs(){return this.ctx.getSpecsFromResultPool()}getDataByRef(e){var n;return typeof this.ctx.getDataFromResultPoolByRef>"u"?(n=this.getData().entries.find(r=>r.ref.blockId===e.blockId&&r.ref.name===e.name))==null?void 0:n.obj:f.mapPObjectData(this.ctx.getDataFromResultPoolByRef(e.blockId,e.name),r=>new P(r,[e.blockId,e.name]))}getPColumnByRef(e){const n=this.getDataByRef(e);if(n)return f.ensurePColumn(n)}getPColumnSpecByRef(e){const n=this.getSpecByRef(e);if(n){if(!f.isPColumnSpec(n))throw new Error(`not a PColumn spec (kind = ${n.kind})`);return n}}getSpecByRef(e){var n;return typeof this.ctx.getSpecFromResultPoolByRef>"u"?(n=this.getSpecs().entries.find(r=>r.ref.blockId===e.blockId&&r.ref.name===e.name))==null?void 0:n.obj:this.ctx.getSpecFromResultPoolByRef(e.blockId,e.name)}findDataWithCompatibleSpec(e){const n=[];e:for(const r of this.getData().entries){if(!f.isPColumnSpec(r.obj.spec))continue;const s=r.obj.spec;if(e.name===s.name&&e.valueType===s.valueType&&e.axesSpec.length===s.axesSpec.length&&H(e.domain,s.domain)){for(let i=0;i<e.axesSpec.length;++i){const o=e.axesSpec[i],l=s.axesSpec[i];if(o.name!==l.name||o.type!==l.type||!H(o.domain,l.domain))continue e}n.push(r.obj)}}return n}}function H(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}class F{constructor(){w(this,"ctx");w(this,"args");w(this,"uiState");w(this,"resultPool",new pe);this.ctx=u(),this.args=JSON.parse(this.ctx.args),this.uiState=this.ctx.uiState!==void 0?JSON.parse(this.ctx.uiState):void 0}getNamedAccessor(e){return B(this.ctx.getAccessorHandleByName(e),n=>new P(n,[e]))}get prerun(){return this.getNamedAccessor(se)}get precalc(){return this.prerun}get stagingOutput(){return this.precalc}get outputs(){return this.getNamedAccessor(ie)}get mainOutput(){return this.outputs}findLabels(e){const n=this.resultPool.getData();for(const r of n.entries){if(!f.isPColumn(r.obj))continue;const s=r.obj.spec;if(s.name==="pl7.app/label"&&s.axesSpec.length===1&&s.axesSpec[0].name===e.name&&s.axesSpec[0].type===e.type&&H(e.domain,s.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]]))}}}verifyInlineColumnsSupport(e){var s;const n=e.some(i=>!(i.data instanceof P)),r=((s=this.ctx.featureFlags)==null?void 0:s.inlineColumnsSupport)===!0;if(n&&!r)throw Error("inline columns not supported")}createPFrame(e){return this.verifyInlineColumnsSupport(e),this.ctx.createPFrame(e.map(n=>f.mapPObjectData(n,r=>r instanceof P?r.handle:r)))}createPTable(e){var 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.verifyInlineColumnsSupport(f.extractAllColumns(n.src)),this.ctx.createPTable(f.mapPTableDef(n,r=>f.mapPObjectData(r,s=>s instanceof P?s.handle:s)))}getBlockLabel(e){return this.ctx.getBlockLabel(e)}getCurrentUnstableMarker(){if(!(typeof this.ctx.getCurrentUnstableMarker>"u"))return this.ctx.getCurrentUnstableMarker()}}const k="PColumnData/",M=k+"ResourceMap",U=k+"Partitioned/ResourceMap",W=k+"JsonPartitioned",V=k+"BinaryPartitioned",fe=k+"Partitioned/",z=fe+"JsonPartitioned",j=fe+"BinaryPartitioned";function he(t,e,n,r=[],s){if(t===void 0)return!1;switch(t.resourceType.name){case M:{let i=t.getInputsLocked();for(const o of t.listInputFields()){const l=t.resolve({field:o,assertFieldType:"Input"}),d=[...r,...JSON.parse(o)],a=l===void 0?void 0:e(l);a===void 0&&(i=!1),(a!==void 0||s)&&n.push({key:d,value:a})}return i}case U:{let i=t.getInputsLocked();for(const o of t.listInputFields()){const l=t.resolve({field:o,assertFieldType:"Input"});if(l===void 0)i=!1;else{const d=[...r,...JSON.parse(o)],a=he(l,e,n,d,s);i=i&&a}}return i}default:throw new Error(`Unknown resource type: ${t.resourceType.name}`)}}function nt(t,e,n=!1){const r=[];return{isComplete:he(t,e,r,[],n),data:r}}const ee=t=>{if(!t.endsWith(".index")){if(t.endsWith(".values"))return t.substring(0,t.length-7);throw Error(`key must ends on .index/.values for binary p-column, got: ${t}`)}};function ge(t){if(!t)return;const e=t.resourceType.name,n=t.getDataAsJson(),r=[];let s=0;switch(e){case M:s=n.keyLength;break;case U:s=n.partitionKeyLength+n.keyLength;break;case W:case V:s=n.partitionKeyLength;break;case j:case z:s=n.superPartitionKeyLength+n.partitionKeyLength;break}switch(e){case M:case W:case V:for(let i of t.listInputFields()){if(e===V){const l=ee(i);if(l)i=l;else continue}const o=[...JSON.parse(i)];r.push(o)}break;case U:case j:case z:for(const i of t.listInputFields()){const o=[...JSON.parse(i)],l=t.resolve({field:i,assertFieldType:"Input"});if(l!==void 0)for(let d of l.listInputFields()){if(e===j){const p=ee(d);if(p)d=p;else continue}const a=[...o,...JSON.parse(d)];r.push(a)}}break}return{data:r,keyLength:s}}function rt(t){const e=ge(t);if(!e)return;const{data:n,keyLength:r}=e,s=[];for(let i=0;i<r;++i)s.push(new Set);for(const i of n){if(i.length!==r)throw new Error("key length does not match partition length");for(let o=0;o<r;++o)s[o].add(i[o])}return s.map(i=>Array.from(i.values()))}const E="1.20.24";function me(t){return t.__renderLambda===!0}function N(t){if(t!==void 0)return me(t)?t.handle:t}function A(t){if(t!==void 0)return typeof t=="string"?{__renderLambda:!0,handle:t,retentive:!1}:t}function st(t){if(t.v3!==void 0){const{initialArgs:e,initialUiState:n,inputsValid:r,outputs:s,renderingMode:i,sdkVersion:o,sections:l,title:d}=t.v3,{code:a}=t;return{initialArgs:e,initialUiState:n,inputsValid:r,outputs:s,renderingMode:i,sdkVersion:o,sections:l,title:d,code:a}}else if(t.inputsValid!==void 0){const{sdkVersion:e,renderingMode:n,outputs:r,inputsValid:s,sections:i,initialArgs:o,code:l}=t,d=Object.keys(t);if(e===void 0||n===void 0||r===void 0||s===void 0||i===void 0||o===void 0)throw new Error(`Malformed config v2. SDK version ${e}; Fields = ${d.join(", ")}`);return{sdkVersion:e,renderingMode:n,initialArgs:o,outputs:Object.fromEntries(Object.entries(r).map(([a,p])=>[a,A(p)])),inputsValid:A(s),sections:A(i),initialUiState:void 0,code:l}}else if(t.renderingMode!==void 0){const{sdkVersion:e,canRun:n,renderingMode:r,outputs:s,sections:i,initialArgs:o,code:l}=t,d=Object.keys(t);if(r===void 0||s===void 0||n===void 0||i===void 0||o===void 0)throw new Error(`Malformed config v1. SDK version ${e}; Fields = ${d.join(", ")}`);return{sdkVersion:e??"unknown",renderingMode:r,initialArgs:o,outputs:Object.fromEntries(Object.entries(s).map(([a,p])=>[a,A(p)])),inputsValid:A(n),sections:A(i),initialUiState:void 0,code:l}}else{const{sdkVersion:e}=t,n=Object.keys(t);throw new Error(`Config format not supported: SDK = ${e}; Fields = ${n.join(", ")}`)}}class _{constructor(e,n,r,s,i,o,l){this._renderingMode=e,this._initialArgs=n,this._initialUiState=r,this._outputs=s,this._inputsValid=i,this._sections=o,this._title=l}static create(e="Heavy"){return new _(e,void 0,{},{},D(!0),D([]),void 0)}output(e,n,r={}){if(typeof n=="function"){const s=`output#${e}`;return x(s,()=>n(new F)),new _(this._renderingMode,this._initialArgs,this._initialUiState,{...this._outputs,[e]:{__renderLambda:!0,handle:s,...r}},this._inputsValid,this._sections,this._title)}else return new _(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})}canRun(e){return this.inputsValid(e)}argsValid(e){return typeof e=="function"?(x("inputsValid",()=>e(new F)),new _(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,{__renderLambda:!0,handle:"inputsValid"},this._sections,this._title)):new _(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,e,this._sections,this._title)}inputsValid(e){return this.argsValid(e)}sections(e){return Array.isArray(e)?this.sections(D(e)):typeof e=="function"?(x("sections",()=>e(new F)),new _(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,this._inputsValid,{__renderLambda:!0,handle:"sections"},this._title)):new _(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,this._inputsValid,e,this._title)}title(e){return x("title",()=>e(new F)),new _(this._renderingMode,this._initialArgs,this._initialUiState,this._outputs,this._inputsValid,this._sections,{__renderLambda:!0,handle:"title"})}initialArgs(e){return new _(this._renderingMode,e,this._initialUiState,this._outputs,this._inputsValid,this._sections,this._title)}withArgs(e){return new _(this._renderingMode,e,this._initialUiState,this._outputs,this._inputsValid,this._sections,this._title)}withUiState(e){return new _(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:E,renderingMode:this._renderingMode,initialArgs:this._initialArgs,initialUiState:this._initialUiState,inputsValid:this._inputsValid,sections:this._sections,title:this._title,outputs:this._outputs},sdkVersion:E,renderingMode:this._renderingMode,initialArgs:this._initialArgs,inputsValid:N(this._inputsValid),sections:N(this._sections),outputs:Object.fromEntries(Object.entries(this._outputs).map(([n,r])=>[n,N(r)]))};return ze()?re({sdkVersion:E}):{config:e}}}function it(t,e,n,r){var l,d;const s=t.resultPool.getData().entries.map(a=>a.obj).filter(f.isPColumn).filter(a=>a.spec.name==="pl7.app/label"&&a.spec.axesSpec.length===1),i=(a,p)=>{let m=a.toString();if(p)for(const c in p)m+=c,m+=p[c];return m},o=new Map;for(const a of e)for(const p of a.spec.axesSpec){const m=f.getAxisId(p);for(const c of s){const y=c.spec.axesSpec[0],g=f.getAxisId(c.spec.axesSpec[0]);if(f.matchAxisId(m,g)){const R=Object.keys(m.domain??{}).length,b=Object.keys(g.domain??{}).length;if(R>b){const C=i(c.id,m.domain);o.set(C,{id:C,spec:{...c.spec,axesSpec:[{...m,annotations:y.annotations}]},data:c.data})}else o.set(i(c.id),c)}}}if(![...e,...o.values()].some(a=>a.data instanceof P&&!a.data.getIsReadyOrError()))return t.createPTable({src:{type:"outer",primary:{type:"full",entries:e.map(a=>({type:"column",column:a}))},secondary:[...o.values()].map(a=>({type:"column",column:a}))},filters:[...((l=n==null?void 0:n.pTableParams)==null?void 0:l.filters)??[],...r??[]],sorting:((d=n==null?void 0:n.pTableParams)==null?void 0:d.sorting)??[]})}function ot(t,e,n){const r=t.findLabels(e);return{axis:e,options:n.map(s=>({value:s,label:(r==null?void 0:r[s])??s.toString()})),defaultValue:n[0]}}class at{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 ye(t){return q({__isRef:!0,blockId:L(t,"blockId"),name:L(t,"name")})}function lt(t){return q({ref:ye(L(t,"ref")),label:L(t,"label")})}const ut={sdkVersion:E};function ct(){return re({sdkVersion:E})}function dt(t){if(typeof globalThis.getEnvironmentValue=="function")return globalThis.getEnvironmentValue(t)}exports.Args=we;exports.BlockModel=_;exports.CurrentSdkInfo=ut;exports.FutureRef=v;exports.It=Re;exports.JsRenderInternal=Ze;exports.MainOutputs=Ce;exports.OutputError=te;exports.PAnnotationLabel=ae;exports.PAnnotationTrace=le;exports.PFrameImpl=at;exports.RT_BINARY_PARTITIONED=V;exports.RT_BINARY_SUPER_PARTITIONED=j;exports.RT_JSON_PARTITIONED=W;exports.RT_JSON_SUPER_PARTITIONED=z;exports.RT_RESOURCE_MAP=M;exports.RT_RESOURCE_MAP_PARTITIONED=U;exports.RenderCtx=F;exports.ResultPool=pe;exports.StagingOutputs=Ae;exports.Trace=ce;exports.TraceEntry=ue;exports.TreeNodeAccessor=P;exports.UiState=Ie;exports.and=ke;exports.createPlDataTable=it;exports.createPlDataTableSheet=ot;exports.deriveLabels=de;exports.downgradeCfgOrLambda=N;exports.extractConfig=st;exports.flatten=De;exports.fromPlOption=lt;exports.fromPlRef=ye;exports.getBlobContent=Be;exports.getBlobContentAsJson=Ue;exports.getBlobContentAsString=Me;exports.getDownloadedBlobContent=Je;exports.getEnvironmentValue=dt;exports.getFromCfg=O;exports.getImmediate=D;exports.getImportProgress=Ke;exports.getJsonField=L;exports.getLastLogs=Ge;exports.getLogHandle=We;exports.getOnDemandBlobContent=$e;exports.getPartitionKeysList=ge;exports.getProgressLog=He;exports.getRawPlatformaInstance=ct;exports.getResourceField=Ve;exports.getResourceValueAsJson=je;exports.getUniquePartitionKeys=rt;exports.ifDef=B;exports.isConfigLambda=me;exports.isEmpty=Ee;exports.isolate=Se;exports.makeArray=Oe;exports.makeObject=q;exports.mapArrayValues=Fe;exports.mapRecordValues=Te;exports.mapResourceFields=Ne;exports.not=Le;exports.or=xe;exports.parseResourceMap=nt;exports.readOutput=ne;exports.wrapOutputs=Pe;Object.keys(f).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>f[t]})});
2
2
  //# sourceMappingURL=index.js.map