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