@platforma-sdk/model 1.22.97 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +459 -442
- package/dist/index.mjs.map +1 -1
- package/dist/render/api.d.ts +39 -2
- package/dist/render/api.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/render/api.ts +144 -45
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 d=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 we(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?L(t):t}function R(t){return{type:"GetFromCtx",variable:t}}function Re(t){return{type:"Isolate",cfg:t}}const Oe=R("$args"),Te=R("$it"),xe=R("$prod"),Fe=R("$staging"),Le=R("$ui");function L(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 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 Ve(t){return{type:"Flatten",source:t}}function je(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 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 nt(){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=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 c().callbackRegistry||(c().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(c().resolveWithCommon(this.handle,e,...n),s=>new A(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 M(c().getError(this.handle),n=>new A(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(!d.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 a=[...this.resolvePath,i];s[i]=d.mapPObjectData(o,l=>new A(l,a))}return s}getFileContentAsBase64(){return new b(c().getBlobContentAsBase64(this.handle))}getFileContentAsString(){return new b(c().getBlobContentAsString(this.handle))}getFileContentAsJson(){return new b(c().getBlobContentAsString(this.handle)).mapDefined(e=>JSON.parse(e))}getBlobContentAsBase64(){return this.getFileContentAsBase64()}getBlobContentAsString(){return this.getFileContentAsString()}getFileHandle(){return new b(c().getDownloadedBlobContentHandle(this.handle))}getDownloadedBlobHandle(){return this.getFileHandle()}getRemoteFileHandle(){return new b(c().getOnDemandBlobContentHandle(this.handle))}getOnDemandBlobHandle(){return this.getRemoteFileHandle()}extractArchiveAndGetURL(e){return new b(c().extractArchiveAndGetURL(this.handle,e))}getImportProgress(){return new b(c().getImportProgress(this.handle))}getLastLogs(e){return new b(c().getLastLogs(this.handle,e))}getProgressLog(e){return new b(c().getProgressLog(this.handle,e))}getProgressLogWithInfo(e){return new b(c().getProgressLogWithInfo(this.handle,e))}getLogHandle(){return new b(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 l=(r==="Input"?this.listInputFields():r==="Output"?this.listOutputFields():this.listDynamicFields()).map(u=>[u,this.resolve({field:u,assertFieldType:r})]);return i&&(l=l.filter(u=>u[1]!==void 0)),l.map(([u,g])=>o(u,g))}}const ie="staging",oe="main",st={inlineColumnsSupport:!0,activeArgs:!0};function ae(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(ae(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:oe,StagingAccessorName:ie,getAllFutureAwaits:it,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),at=.001,lt="__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],S=(Q=m.annotations)==null?void 0:Q[ue],v=(S?de.safeParse(JSON.parse(S)).data:void 0)??[];if(h){const P={label:h,type:lt,importance:-2};n.addLabelAsSuffix?v.push(P):v.splice(0,0,P)}const O=[],V=new Map;for(let P=v.length-1;P>=0;--P){const{type:G}=v[P],Pe=v[P].importance??0,W=(V.get(G)??0)+1;V.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)),O.push({...v[P],fullType:x,occurenceIndex:W})}return O.reverse(),{value:f,spec:m,label:h,fullTrace:O}}),o=[],a=[],l=[...r];l.sort(([,f],[,m])=>m-f);for(const[f]of l)f.endsWith("@1")||s.get(f)===t.length?o.push(f):a.push(f);const u=f=>i.map(m=>{const h=m.fullTrace.filter(v=>f.has(v.fullType)).map(v=>v.label),S=n.separator??" / ";return{label:h.join(S),value:m.value}});if(o.length===0){if(a.length!==0)throw new Error("Assertion error.");return u(new Set(Z))}let g=0,p=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[p]);const m=u(f);if(new Set(m.map(h=>h.label)).size===t.length)return m;p++,p==o.length&&(g++,p=g)}return u(new Set([...o,...a]))}class fe{constructor(){I(this,"ctx",c());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=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 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:d.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:d.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 d.ensurePColumn(n)}getPColumnSpecByRef(e){const n=this.getSpecByRef(e);if(n){if(!d.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(!d.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 F{constructor(){I(this,"ctx");I(this,"args");I(this,"uiState");I(this,"_activeArgsCache");I(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):{}}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(ie)}get outputs(){return this.getNamedAccessor(oe)}findLabels(e){const n=this.resultPool.getData();for(const r of n.entries){if(!d.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 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=>d.mapPObjectData(n,r=>r instanceof A?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(d.extractAllColumns(n.src)),this.ctx.createPTable(d.mapPTableDef(n,r=>d.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",q=k+"JsonPartitioned",U=k+"BinaryPartitioned",he=k+"Partitioned/",Y=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 a=t.resolve({field:o,assertFieldType:"Input"}),l=[...r,...JSON.parse(o)],u=a===void 0?void 0:e(a);u===void 0&&(i=!1),(u!==void 0||s)&&n.push({key:l,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 l=[...r,...JSON.parse(o)],u=ge(a,e,n,l,s);i=i&&u}}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 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 U:s=n.partitionKeyLength;break;case N:case Y:s=n.superPartitionKeyLength+n.partitionKeyLength;break}switch(e){case J:case q:case U:for(let i of t.listInputFields()){if(e===U){const a=ee(i);if(a)i=a;else continue}const o=[...JSON.parse(i)];r.push(o)}break;case $:case N: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 l of a.listInputFields()){if(e===N){const g=ee(l);if(g)l=g;else continue}const u=[...o,...JSON.parse(l)];r.push(u)}}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.22.97";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:a,title:l}=t.v3,{code:u}=t;return{initialArgs:e,initialUiState:n,inputsValid:r,outputs:s,renderingMode:i,sdkVersion:o,sections:a,title:l,code:u}}else if(t.inputsValid!==void 0){const{sdkVersion:e,renderingMode:n,outputs:r,inputsValid:s,sections:i,initialArgs:o,code:a}=t,l=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 = ${l.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:a}}else if(t.renderingMode!==void 0){const{sdkVersion:e,canRun:n,renderingMode:r,outputs:s,sections:i,initialArgs:o,code:a}=t,l=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 = ${l.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: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,{},{},L(!0),L([]),void 0)}output(e,n,r={}){if(typeof n=="function"){const s=`output#${e}`;return j(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"?(j("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"?(j("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 j("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()?se({sdkVersion:D}):{config:e}}}function pt(t,e,n,r){var u,g;Array.isArray(r)&&(r={filters:r});const s=t.resultPool.getData().entries.map(p=>p.obj).filter(d.isPColumn).filter(p=>p.spec.name==="pl7.app/label"&&p.spec.axesSpec.length===1),i=(p,f)=>{let m=p.toString();if(f)for(const h in f)m+=h,m+=f[h];return m},o=new Map;for(const p of e)for(const f of p.spec.axesSpec){const m=d.getAxisId(f);for(const h of s){const S=h.spec.axesSpec[0],v=d.getAxisId(h.spec.axesSpec[0]);if(d.matchAxisId(m,v)){const O=Object.keys(m.domain??{}).length,V=Object.keys(v.domain??{}).length;if(O>V){const T=i(h.id,m.domain);o.set(T,{id:T,spec:{...h.spec,axesSpec:[{...m,annotations:S.annotations}]},data:h.data})}else o.set(i(h.id),h)}}}if([...e,...o.values()].some(p=>p.data instanceof A&&!p.data.getIsReadyOrError()))return;let a=e;const l=[];if(r!=null&&r.coreColumnPredicate){a=[];for(const p of e)r.coreColumnPredicate(p.spec)?a.push(p):l.push(p)}return l.push(...o.values()),t.createPTable({src:{type:"outer",primary:{type:(r==null?void 0:r.coreJoinType)??"full",entries:a.map(p=>({type:"column",column:p}))},secondary:l.map(p=>({type:"column",column:p}))},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 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(d.getAxisId);return e.spec.axesSpec.map(d.getAxisId).every(s=>n.some(i=>d.matchAxisId(i,s)&&d.matchAxisId(s,i)))}function be(t,e){const n=t.spec.axesSpec.map(d.getAxisId);return e.spec.axesSpec.map(d.getAxisId).every(s=>n.some(i=>d.matchAxisId(i,s)))}const ve="pl7.app/graph/isVirtual";function te(t,e){const n=t.spec.axesSpec.map(d.getAxisId),r=e.spec.axesSpec.map(d.getAxisId);if(mt(t,e))return[];if(!be(t,e))return[];const o=r.map(l=>n.filter(u=>d.matchAxisId(u,l)));return gt(o).map(l=>({id:ht(e.id,l.map(g=>g.domain)),spec:{...e.spec,axesSpec:l.map((g,p)=>({...g,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(...te(s,i),...te(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(d.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 X({__isRef:!0,blockId:E(t,"blockId"),name:E(t,"name")})}function At(t){return X({ref:Ie(E(t,"ref")),label:E(t,"label")})}const _t={sdkVersion:D};function It(){return se({sdkVersion:D})}function Pt(t){if(typeof globalThis.getEnvironmentValue=="function")return globalThis.getEnvironmentValue(t)}exports.Args=Oe;exports.BlockModel=_;exports.CurrentSdkInfo=_t;exports.FutureRef=b;exports.IS_VIRTUAL_COLUMN=ve;exports.It=Te;exports.JsRenderInternal=ot;exports.MainOutputs=xe;exports.OutputError=ne;exports.PAnnotationLabel=le;exports.PAnnotationTrace=ue;exports.PFrameImpl=vt;exports.RT_BINARY_PARTITIONED=U;exports.RT_BINARY_SUPER_PARTITIONED=N;exports.RT_JSON_PARTITIONED=q;exports.RT_JSON_SUPER_PARTITIONED=Y;exports.RT_RESOURCE_MAP=J;exports.RT_RESOURCE_MAP_PARTITIONED=$;exports.RenderCtx=F;exports.ResultPool=fe;exports.StagingOutputs=Fe;exports.Trace=de;exports.TraceEntry=ce;exports.TreeNodeAccessor=A;exports.UiState=Le;exports.and=Ne;exports.createPFrameForGraphs=bt;exports.createPlDataTable=pt;exports.createPlDataTableSheet=ft;exports.deriveLabels=pe;exports.downgradeCfgOrLambda=B;exports.enrichColumnsWithCompatible=_e;exports.extractArchiveAndGetURL=qe;exports.extractConfig=dt;exports.flatten=Ve;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=je;exports.isolate=Re;exports.makeArray=De;exports.makeObject=X;exports.mapArrayValues=ke;exports.mapRecordValues=Ee;exports.mapResourceFields=$e;exports.not=Ue;exports.or=Be;exports.parseResourceMap=ut;exports.readOutput=re;exports.wrapOutputs=we;Object.keys(d).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>d[t]})});
|
|
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]})});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|