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