@platforma-sdk/model 1.21.10 → 1.22.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.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  var fe = Object.defineProperty;
2
2
  var he = (n, e, t) => e in n ? fe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var w = (n, e, t) => he(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { isPColumn as X, mapPObjectData as j, mapValueInVOE as ge, ensurePColumn as me, isPColumnSpec as Z, extractAllColumns as ye, mapPTableDef as be, getAxisId as B, matchAxisId as O } from "@milaboratories/pl-model-common";
3
+ var S = (n, e, t) => he(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { isPColumn as X, mapPObjectData as j, mapValueInVOE as ge, ensurePColumn as me, isPColumnSpec as Z, extractAllColumns as ye, mapPTableDef as be, getAxisId as B, matchAxisId as T } from "@milaboratories/pl-model-common";
5
5
  export * from "@milaboratories/pl-model-common";
6
- import { z as A } from "zod";
6
+ import { z as P } from "zod";
7
7
  class ve extends Error {
8
8
  constructor(e, t) {
9
9
  super(`${e.length}${t ? "+" : ""} errors, first error: ` + e[0]), this.errors = e, this.moreErrors = t;
@@ -23,7 +23,7 @@ function $e(n) {
23
23
  function m(n) {
24
24
  return typeof n == "string" || typeof n == "number" || typeof n == "boolean" || n === null ? V(n) : n;
25
25
  }
26
- function k(n) {
26
+ function x(n) {
27
27
  return { type: "GetFromCtx", variable: n };
28
28
  }
29
29
  function Ke(n) {
@@ -32,7 +32,7 @@ function Ke(n) {
32
32
  cfg: n
33
33
  };
34
34
  }
35
- const Ge = k("$args"), He = k("$it"), We = k("$prod"), qe = k("$staging"), ze = k("$ui");
35
+ const Ge = x("$args"), He = x("$it"), We = x("$prod"), qe = x("$staging"), ze = x("$ui");
36
36
  function V(n) {
37
37
  return { type: "Immediate", value: n };
38
38
  }
@@ -210,17 +210,17 @@ function E(n, e) {
210
210
  if (n in t.callbackRegistry) throw new Error(`Callback with key ${n} already registered.`);
211
211
  return t.callbackRegistry[n] = e, !0;
212
212
  }
213
- const J = /* @__PURE__ */ new Map();
213
+ const U = /* @__PURE__ */ new Map();
214
214
  function Ce(n, e) {
215
215
  n in c().callbackRegistry || (c().callbackRegistry[n] = (t) => {
216
- for (const r of J.get(n))
216
+ for (const r of U.get(n))
217
217
  r(t);
218
- }, J.set(n, [])), J.get(n).push(e);
218
+ }, U.set(n, [])), U.get(n).push(e);
219
219
  }
220
220
  class _ {
221
221
  constructor(e, t = (r) => r) {
222
- w(this, "isResolved", !1);
223
- w(this, "resolvedValue");
222
+ S(this, "isResolved", !1);
223
+ S(this, "resolvedValue");
224
224
  this.handle = e, this.postProcess = t, Ce(e, (r) => {
225
225
  this.resolvedValue = t(r), this.isResolved = !0;
226
226
  });
@@ -452,8 +452,9 @@ class b {
452
452
  return i && (a = a.filter((u) => u[1] !== void 0)), a.map(([u, h]) => o(u, h));
453
453
  }
454
454
  }
455
- const ae = "staging", le = "main", Pe = {
456
- inlineColumnsSupport: !0
455
+ const ae = "staging", le = "main", Ae = {
456
+ inlineColumnsSupport: !0,
457
+ activeArgs: !0
457
458
  };
458
459
  function ue(n) {
459
460
  return typeof n == "object" && n !== null && "__awaited_futures__" in n;
@@ -468,43 +469,43 @@ function W(n, e, t) {
468
469
  for (const [, s] of Object.entries(t))
469
470
  s !== t && W(n, e, s);
470
471
  }
471
- function Ae(n) {
472
+ function Pe(n) {
472
473
  const e = /* @__PURE__ */ new Set();
473
474
  return W(e, /* @__PURE__ */ new Set(), n), e;
474
475
  }
475
476
  const mt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
476
477
  __proto__: null,
477
- GlobalCfgRenderCtxFeatureFlags: Pe,
478
+ GlobalCfgRenderCtxFeatureFlags: Ae,
478
479
  MainAccessorName: le,
479
480
  StagingAccessorName: ae,
480
- getAllFutureAwaits: Ae,
481
+ getAllFutureAwaits: Pe,
481
482
  isFutureAwait: ue
482
- }, Symbol.toStringTag, { value: "Module" })), Ie = "pl7.app/label", Fe = "pl7.app/trace", Re = A.object({
483
- type: A.string(),
484
- importance: A.number().optional(),
485
- id: A.string().optional(),
486
- label: A.string()
487
- }), Oe = A.array(Re), Te = 1e-3, ke = "__LABEL__", ee = "__LABEL__@1";
488
- function xe(n, e, t = {}) {
483
+ }, Symbol.toStringTag, { value: "Module" })), Ie = "pl7.app/label", Fe = "pl7.app/trace", Re = P.object({
484
+ type: P.string(),
485
+ importance: P.number().optional(),
486
+ id: P.string().optional(),
487
+ label: P.string()
488
+ }), Te = P.array(Re), Oe = 1e-3, xe = "__LABEL__", ee = "__LABEL__@1";
489
+ function ke(n, e, t = {}) {
489
490
  const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), i = n.map((p) => {
490
491
  var F, Q;
491
- const g = e(p), f = (F = g.annotations) == null ? void 0 : F[Ie], C = (Q = g.annotations) == null ? void 0 : Q[Fe], y = (C ? Oe.safeParse(JSON.parse(C)).data : void 0) ?? [];
492
+ const g = e(p), f = (F = g.annotations) == null ? void 0 : F[Ie], C = (Q = g.annotations) == null ? void 0 : Q[Fe], y = (C ? Te.safeParse(JSON.parse(C)).data : void 0) ?? [];
492
493
  if (f) {
493
- const S = { label: f, type: ke, importance: -2 };
494
- t.addLabelAsSuffix ? y.push(S) : y.splice(0, 0, S);
494
+ const w = { label: f, type: xe, importance: -2 };
495
+ t.addLabelAsSuffix ? y.push(w) : y.splice(0, 0, w);
495
496
  }
496
497
  const I = [], D = /* @__PURE__ */ new Map();
497
- for (let S = y.length - 1; S >= 0; --S) {
498
- const { type: M } = y[S], pe = y[S].importance ?? 0, U = (D.get(M) ?? 0) + 1;
499
- D.set(M, U);
500
- const R = `${M}@${U}`;
498
+ for (let w = y.length - 1; w >= 0; --w) {
499
+ const { type: M } = y[w], pe = y[w].importance ?? 0, J = (D.get(M) ?? 0) + 1;
500
+ D.set(M, J);
501
+ const R = `${M}@${J}`;
501
502
  s.set(R, (s.get(R) ?? 0) + 1), r.set(
502
503
  R,
503
504
  Math.max(
504
505
  r.get(R) ?? Number.NEGATIVE_INFINITY,
505
- pe - (y.length - S) * Te
506
+ pe - (y.length - w) * Oe
506
507
  )
507
- ), I.push({ ...y[S], fullType: R, occurenceIndex: U });
508
+ ), I.push({ ...y[w], fullType: R, occurenceIndex: J });
508
509
  }
509
510
  return I.reverse(), {
510
511
  value: p,
@@ -541,8 +542,8 @@ function xe(n, e, t = {}) {
541
542
  }
542
543
  class De {
543
544
  constructor() {
544
- w(this, "ctx", c());
545
- w(this, "defaultLabelFn", (e, t) => {
545
+ S(this, "ctx", c());
546
+ S(this, "defaultLabelFn", (e, t) => {
546
547
  var r;
547
548
  return ((r = e.annotations) == null ? void 0 : r["pl7.app/label"]) ?? "Unlabelled";
548
549
  });
@@ -555,7 +556,7 @@ class De {
555
556
  }
556
557
  getOptions(e, t) {
557
558
  const r = this.getSpecs().entries.filter((s) => e(s.obj));
558
- return typeof t == "object" || typeof t > "u" ? xe(r, (s) => s.obj, t ?? {}).map(({ value: { ref: s }, label: i }) => ({
559
+ return typeof t == "object" || typeof t > "u" ? ke(r, (s) => s.obj, t ?? {}).map(({ value: { ref: s }, label: i }) => ({
559
560
  ref: s,
560
561
  label: i
561
562
  })) : r.map((s) => ({
@@ -690,12 +691,27 @@ function q(n, e) {
690
691
  }
691
692
  class L {
692
693
  constructor() {
693
- w(this, "ctx");
694
- w(this, "args");
695
- w(this, "uiState");
696
- w(this, "resultPool", new De());
694
+ S(this, "ctx");
695
+ S(this, "args");
696
+ S(this, "uiState");
697
+ // lazy rendering because this feature is rarely used
698
+ S(this, "_activeArgsCache");
699
+ S(this, "resultPool", new De());
697
700
  this.ctx = c(), this.args = JSON.parse(this.ctx.args), this.uiState = this.ctx.uiState !== void 0 ? JSON.parse(this.ctx.uiState) : {};
698
701
  }
702
+ /**
703
+ * Returns args snapshot the block was executed for (i.e. when "Run" button was pressed).
704
+ * Returns undefined, if block was never executed or stopped mid-way execution, so that the result was cleared.
705
+ * */
706
+ get activeArgs() {
707
+ return this._activeArgsCache === void 0 && (this._activeArgsCache = {
708
+ v: this.ctx.activeArgs ? JSON.parse(this.ctx.activeArgs) : void 0
709
+ }), this._activeArgsCache.v;
710
+ }
711
+ // /** Can be used to determine features provided by the desktop instance. */
712
+ // public get featureFlags() {
713
+ // return this.ctx.featureFlags;
714
+ // }
699
715
  getNamedAccessor(e) {
700
716
  return H(
701
717
  this.ctx.getAccessorHandleByName(e),
@@ -705,27 +721,9 @@ class L {
705
721
  get prerun() {
706
722
  return this.getNamedAccessor(ae);
707
723
  }
708
- /**
709
- * @deprecated use prerun
710
- */
711
- get precalc() {
712
- return this.prerun;
713
- }
714
- /**
715
- * @deprecated use prerun
716
- */
717
- get stagingOutput() {
718
- return this.precalc;
719
- }
720
724
  get outputs() {
721
725
  return this.getNamedAccessor(le);
722
726
  }
723
- /**
724
- * @deprecated use outputs
725
- */
726
- get mainOutput() {
727
- return this.outputs;
728
- }
729
727
  /**
730
728
  * Find labels data for a given axis id. It will search for a label column and return its data as a map.
731
729
  * @returns a map of axis value => label
@@ -781,7 +779,7 @@ class L {
781
779
  return this.ctx.getCurrentUnstableMarker();
782
780
  }
783
781
  }
784
- const x = "PColumnData/", z = x + "ResourceMap", Y = x + "Partitioned/ResourceMap", te = x + "JsonPartitioned", $ = x + "BinaryPartitioned", ce = x + "Partitioned/", ne = ce + "JsonPartitioned", K = ce + "BinaryPartitioned";
782
+ const k = "PColumnData/", z = k + "ResourceMap", Y = k + "Partitioned/ResourceMap", te = k + "JsonPartitioned", $ = k + "BinaryPartitioned", ce = k + "Partitioned/", ne = ce + "JsonPartitioned", K = ce + "BinaryPartitioned";
785
783
  function de(n, e, t, r = [], s) {
786
784
  if (n === void 0) return !1;
787
785
  switch (n.resourceType.name) {
@@ -894,7 +892,7 @@ function bt(n) {
894
892
  }
895
893
  return s.map((i) => Array.from(i.values()));
896
894
  }
897
- const T = "1.21.10";
895
+ const O = "1.22.0";
898
896
  function Le(n) {
899
897
  return n.__renderLambda === !0;
900
898
  }
@@ -902,7 +900,7 @@ function G(n) {
902
900
  if (n !== void 0)
903
901
  return Le(n) ? n.handle : n;
904
902
  }
905
- function P(n) {
903
+ function A(n) {
906
904
  if (n !== void 0)
907
905
  return typeof n == "string" ? { __renderLambda: !0, handle: n, retentive: !1 } : n;
908
906
  }
@@ -940,10 +938,10 @@ function vt(n) {
940
938
  renderingMode: t,
941
939
  initialArgs: o,
942
940
  outputs: Object.fromEntries(
943
- Object.entries(r).map(([u, h]) => [u, P(h)])
941
+ Object.entries(r).map(([u, h]) => [u, A(h)])
944
942
  ),
945
- inputsValid: P(s),
946
- sections: P(i),
943
+ inputsValid: A(s),
944
+ sections: A(i),
947
945
  initialUiState: void 0,
948
946
  code: l
949
947
  };
@@ -958,10 +956,10 @@ function vt(n) {
958
956
  renderingMode: r,
959
957
  initialArgs: o,
960
958
  outputs: Object.fromEntries(
961
- Object.entries(s).map(([u, h]) => [u, P(h)])
959
+ Object.entries(s).map(([u, h]) => [u, A(h)])
962
960
  ),
963
- inputsValid: P(t),
964
- sections: P(i),
961
+ inputsValid: A(t),
962
+ sections: A(i),
965
963
  initialUiState: void 0,
966
964
  code: l
967
965
  };
@@ -1024,10 +1022,6 @@ class v {
1024
1022
  retentiveOutput(e, t) {
1025
1023
  return this.output(e, t, { retentive: !0 });
1026
1024
  }
1027
- /** @deprecated */
1028
- canRun(e) {
1029
- return this.inputsValid(e);
1030
- }
1031
1025
  argsValid(e) {
1032
1026
  return typeof e == "function" ? (E("inputsValid", () => e(new L())), new v(
1033
1027
  this._renderingMode,
@@ -1050,9 +1044,6 @@ class v {
1050
1044
  this._title
1051
1045
  );
1052
1046
  }
1053
- inputsValid(e) {
1054
- return this.argsValid(e);
1055
- }
1056
1047
  sections(e) {
1057
1048
  return Array.isArray(e) ? this.sections(V(e)) : typeof e == "function" ? (E("sections", () => e(new L())), new v(
1058
1049
  this._renderingMode,
@@ -1072,6 +1063,7 @@ class v {
1072
1063
  this._title
1073
1064
  );
1074
1065
  }
1066
+ /** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
1075
1067
  title(e) {
1076
1068
  return E("title", () => e(new L())), new v(
1077
1069
  this._renderingMode,
@@ -1129,7 +1121,7 @@ class v {
1129
1121
  if (this._initialArgs === void 0) throw new Error("Initial arguments not set.");
1130
1122
  const e = {
1131
1123
  v3: {
1132
- sdkVersion: T,
1124
+ sdkVersion: O,
1133
1125
  renderingMode: this._renderingMode,
1134
1126
  initialArgs: this._initialArgs,
1135
1127
  initialUiState: this._initialUiState,
@@ -1139,7 +1131,7 @@ class v {
1139
1131
  outputs: this._outputs
1140
1132
  },
1141
1133
  // fields below are added to allow previous desktop versions read generated configs
1142
- sdkVersion: T,
1134
+ sdkVersion: O,
1143
1135
  renderingMode: this._renderingMode,
1144
1136
  initialArgs: this._initialArgs,
1145
1137
  inputsValid: G(this._inputsValid),
@@ -1148,7 +1140,7 @@ class v {
1148
1140
  Object.entries(this._outputs).map(([t, r]) => [t, G(r)])
1149
1141
  )
1150
1142
  };
1151
- return Se() ? oe({ sdkVersion: T }) : { config: e };
1143
+ return Se() ? oe({ sdkVersion: O }) : { config: e };
1152
1144
  }
1153
1145
  }
1154
1146
  function _t(n, e, t, r) {
@@ -1166,7 +1158,7 @@ function _t(n, e, t, r) {
1166
1158
  const g = B(p);
1167
1159
  for (const f of s) {
1168
1160
  const C = f.spec.axesSpec[0], y = B(f.spec.axesSpec[0]);
1169
- if (O(g, y)) {
1161
+ if (T(g, y)) {
1170
1162
  const I = Object.keys(g.domain ?? {}).length, D = Object.keys(y.domain ?? {}).length;
1171
1163
  if (I > D) {
1172
1164
  const F = i(f.id, g.domain);
@@ -1239,11 +1231,11 @@ function je(n) {
1239
1231
  }
1240
1232
  function se(n, e) {
1241
1233
  const t = n.spec.axesSpec.map(B), r = e.spec.axesSpec.map(B);
1242
- if (r.every((a) => t.some((u) => O(u, a) && O(a, u))))
1234
+ if (r.every((a) => t.some((u) => T(u, a) && T(a, u))))
1243
1235
  return [];
1244
- if (!r.every((a) => t.some((u) => O(u, a))))
1236
+ if (!r.every((a) => t.some((u) => T(u, a))))
1245
1237
  return [];
1246
- const o = r.map((a) => t.filter((u) => O(u, a)));
1238
+ const o = r.map((a) => t.filter((u) => T(u, a)));
1247
1239
  return je(o).map((a) => ({
1248
1240
  id: Ve(e.id, a.map((h) => h.domain)),
1249
1241
  spec: {
@@ -1302,17 +1294,17 @@ function Ne(n) {
1302
1294
  name: N(n, "name")
1303
1295
  });
1304
1296
  }
1305
- function Pt(n) {
1297
+ function At(n) {
1306
1298
  return ie({
1307
1299
  ref: Ne(N(n, "ref")),
1308
1300
  label: N(n, "label")
1309
1301
  });
1310
1302
  }
1311
- const At = {
1312
- sdkVersion: T
1303
+ const Pt = {
1304
+ sdkVersion: O
1313
1305
  };
1314
1306
  function It() {
1315
- return oe({ sdkVersion: T });
1307
+ return oe({ sdkVersion: O });
1316
1308
  }
1317
1309
  function Ft(n) {
1318
1310
  if (typeof globalThis.getEnvironmentValue == "function")
@@ -1321,7 +1313,7 @@ function Ft(n) {
1321
1313
  export {
1322
1314
  Ge as Args,
1323
1315
  v as BlockModel,
1324
- At as CurrentSdkInfo,
1316
+ Pt as CurrentSdkInfo,
1325
1317
  _ as FutureRef,
1326
1318
  He as It,
1327
1319
  mt as JsRenderInternal,
@@ -1339,7 +1331,7 @@ export {
1339
1331
  L as RenderCtx,
1340
1332
  De as ResultPool,
1341
1333
  qe as StagingOutputs,
1342
- Oe as Trace,
1334
+ Te as Trace,
1343
1335
  Re as TraceEntry,
1344
1336
  b as TreeNodeAccessor,
1345
1337
  ze as UiState,
@@ -1347,11 +1339,11 @@ export {
1347
1339
  wt as createPFrameForGraphs,
1348
1340
  _t as createPlDataTable,
1349
1341
  St as createPlDataTableSheet,
1350
- xe as deriveLabels,
1342
+ ke as deriveLabels,
1351
1343
  G as downgradeCfgOrLambda,
1352
1344
  vt as extractConfig,
1353
1345
  Ze as flatten,
1354
- Pt as fromPlOption,
1346
+ At as fromPlOption,
1355
1347
  Ne as fromPlRef,
1356
1348
  Be as getAdditionalColumns,
1357
1349
  at as getBlobContent,
@@ -1359,7 +1351,7 @@ export {
1359
1351
  lt as getBlobContentAsString,
1360
1352
  ct as getDownloadedBlobContent,
1361
1353
  Ft as getEnvironmentValue,
1362
- k as getFromCfg,
1354
+ x as getFromCfg,
1363
1355
  V as getImmediate,
1364
1356
  pt as getImportProgress,
1365
1357
  N as getJsonField,