@platforma-open/milaboratories.vj-usage.model 2.0.1 → 2.1.1

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/bundle.js CHANGED
@@ -1,59 +1,67 @@
1
1
  (function(global, factory) {
2
2
  typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.model = {}));
3
3
  })(this, function(exports2) {
4
- "use strict";
5
- function getDefaultExportFromCjs(x2) {
6
- return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
4
+ "use strict";var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+
8
+ function getImmediate(value) {
9
+ return { type: "Immediate", value };
10
+ }
11
+ function isInUI() {
12
+ return typeof globalThis.getPlatforma !== "undefined" || typeof globalThis.platforma !== "undefined";
13
+ }
14
+ function getPlatformaInstance(config) {
15
+ if (config && typeof globalThis.getPlatforma === "function")
16
+ return globalThis.getPlatforma(config);
17
+ else if (typeof globalThis.platforma !== "undefined")
18
+ return globalThis.platforma;
19
+ else
20
+ throw new Error("Can't get platforma instance.");
21
+ }
22
+ function tryGetCfgRenderCtx() {
23
+ if (typeof globalThis.cfgRenderCtx !== "undefined")
24
+ return globalThis.cfgRenderCtx;
25
+ else
26
+ return void 0;
7
27
  }
8
- var canonicalize;
9
- var hasRequiredCanonicalize;
10
- function requireCanonicalize() {
11
- if (hasRequiredCanonicalize) return canonicalize;
12
- hasRequiredCanonicalize = 1;
13
- canonicalize = function serialize(object) {
14
- if (typeof object === "number" && isNaN(object)) {
15
- throw new Error("NaN is not allowed");
16
- }
17
- if (typeof object === "number" && !isFinite(object)) {
18
- throw new Error("Infinity is not allowed");
19
- }
20
- if (object === null || typeof object !== "object") {
21
- return JSON.stringify(object);
22
- }
23
- if (object.toJSON instanceof Function) {
24
- return serialize(object.toJSON());
25
- }
26
- if (Array.isArray(object)) {
27
- const values2 = object.reduce((t, cv, ci) => {
28
- const comma = ci === 0 ? "" : ",";
29
- const value = cv === void 0 || typeof cv === "symbol" ? null : cv;
30
- return `${t}${comma}${serialize(value)}`;
31
- }, "");
32
- return `[${values2}]`;
33
- }
34
- const values = Object.keys(object).sort().reduce((t, cv) => {
35
- if (object[cv] === void 0 || typeof object[cv] === "symbol") {
36
- return t;
28
+ function getCfgRenderCtx() {
29
+ if (typeof globalThis.cfgRenderCtx !== "undefined")
30
+ return globalThis.cfgRenderCtx;
31
+ else
32
+ throw new Error("Not in config rendering context");
33
+ }
34
+ function tryRegisterCallback(key, callback) {
35
+ const ctx = tryGetCfgRenderCtx();
36
+ if (ctx === void 0)
37
+ return false;
38
+ if (key in ctx.callbackRegistry)
39
+ throw new Error(`Callback with key ${key} already registered.`);
40
+ ctx.callbackRegistry[key] = callback;
41
+ return true;
42
+ }
43
+ const futureResolves = /* @__PURE__ */ new Map();
44
+ function registerFutureAwait(handle, onResolve) {
45
+ if (!(handle in getCfgRenderCtx().callbackRegistry)) {
46
+ getCfgRenderCtx().callbackRegistry[handle] = (value) => {
47
+ for (const res of futureResolves.get(handle)) {
48
+ res(value);
37
49
  }
38
- const comma = t.length === 0 ? "" : ",";
39
- return `${t}${comma}${serialize(cv)}:${serialize(object[cv])}`;
40
- }, "");
41
- return `{${values}}`;
42
- };
43
- return canonicalize;
50
+ };
51
+ futureResolves.set(handle, []);
52
+ }
53
+ futureResolves.get(handle).push(onResolve);
44
54
  }
45
- var canonicalizeExports = requireCanonicalize();
46
- const _e = /* @__PURE__ */ getDefaultExportFromCjs(canonicalizeExports);
47
55
  var util;
48
56
  (function(util2) {
49
57
  util2.assertEqual = (val) => val;
50
58
  function assertIs(_arg) {
51
59
  }
52
60
  util2.assertIs = assertIs;
53
- function assertNever(_x) {
61
+ function assertNever2(_x) {
54
62
  throw new Error();
55
63
  }
56
- util2.assertNever = assertNever;
64
+ util2.assertNever = assertNever2;
57
65
  util2.arrayToEnum = (items) => {
58
66
  const obj = {};
59
67
  for (const item of items) {
@@ -62,10 +70,10 @@
62
70
  return obj;
63
71
  };
64
72
  util2.getValidEnumValues = (obj) => {
65
- const validKeys = util2.objectKeys(obj).filter((k2) => typeof obj[obj[k2]] !== "number");
73
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
66
74
  const filtered = {};
67
- for (const k2 of validKeys) {
68
- filtered[k2] = obj[k2];
75
+ for (const k of validKeys) {
76
+ filtered[k] = obj[k];
69
77
  }
70
78
  return util2.objectValues(filtered);
71
79
  };
@@ -410,7 +418,7 @@
410
418
  };
411
419
  }
412
420
  let errorMessage = "";
413
- const maps = errorMaps.filter((m2) => !!m2).slice().reverse();
421
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
414
422
  for (const map of maps) {
415
423
  errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
416
424
  }
@@ -433,7 +441,7 @@
433
441
  overrideMap,
434
442
  overrideMap === errorMap ? void 0 : errorMap
435
443
  // then global default map
436
- ].filter((x2) => !!x2)
444
+ ].filter((x) => !!x)
437
445
  });
438
446
  ctx.common.issues.push(issue);
439
447
  }
@@ -451,12 +459,12 @@
451
459
  }
452
460
  static mergeArray(status, results) {
453
461
  const arrayValue = [];
454
- for (const s2 of results) {
455
- if (s2.status === "aborted")
462
+ for (const s of results) {
463
+ if (s.status === "aborted")
456
464
  return INVALID;
457
- if (s2.status === "dirty")
465
+ if (s.status === "dirty")
458
466
  status.dirty();
459
- arrayValue.push(s2.value);
467
+ arrayValue.push(s.value);
460
468
  }
461
469
  return { status: status.value, value: arrayValue };
462
470
  }
@@ -496,15 +504,15 @@
496
504
  });
497
505
  const DIRTY = (value) => ({ status: "dirty", value });
498
506
  const OK = (value) => ({ status: "valid", value });
499
- const isAborted = (x2) => x2.status === "aborted";
500
- const isDirty = (x2) => x2.status === "dirty";
501
- const isValid = (x2) => x2.status === "valid";
502
- const isAsync = (x2) => typeof Promise !== "undefined" && x2 instanceof Promise;
503
- function __classPrivateFieldGet(receiver, state, kind, f2) {
507
+ const isAborted = (x) => x.status === "aborted";
508
+ const isDirty = (x) => x.status === "dirty";
509
+ const isValid = (x) => x.status === "valid";
510
+ const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
511
+ function __classPrivateFieldGet(receiver, state, kind, f) {
504
512
  if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
505
513
  return state.get(receiver);
506
514
  }
507
- function __classPrivateFieldSet(receiver, state, value, kind, f2) {
515
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
508
516
  if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
509
517
  return state.set(receiver, value), value;
510
518
  }
@@ -858,11 +866,11 @@
858
866
  regex = `${regex}(${opts.join("|")})`;
859
867
  return new RegExp(`^${regex}$`);
860
868
  }
861
- function isValidIP(ip, version) {
862
- if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
869
+ function isValidIP(ip, version2) {
870
+ if ((version2 === "v4" || !version2) && ipv4Regex.test(ip)) {
863
871
  return true;
864
872
  }
865
- if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
873
+ if ((version2 === "v6" || !version2) && ipv6Regex.test(ip)) {
866
874
  return true;
867
875
  }
868
876
  return false;
@@ -2829,7 +2837,7 @@
2829
2837
  if (!schema)
2830
2838
  return null;
2831
2839
  return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
2832
- }).filter((x2) => !!x2);
2840
+ }).filter((x) => !!x);
2833
2841
  if (ctx.common.async) {
2834
2842
  return Promise.all(items).then((results) => {
2835
2843
  return ParseStatus.mergeArray(status, results);
@@ -3087,7 +3095,7 @@
3087
3095
  ctx.schemaErrorMap,
3088
3096
  getErrorMap(),
3089
3097
  errorMap
3090
- ].filter((x2) => !!x2),
3098
+ ].filter((x) => !!x),
3091
3099
  issueData: {
3092
3100
  code: ZodIssueCode.invalid_arguments,
3093
3101
  argumentsError: error
@@ -3103,7 +3111,7 @@
3103
3111
  ctx.schemaErrorMap,
3104
3112
  getErrorMap(),
3105
3113
  errorMap
3106
- ].filter((x2) => !!x2),
3114
+ ].filter((x) => !!x),
3107
3115
  issueData: {
3108
3116
  code: ZodIssueCode.invalid_return_type,
3109
3117
  returnTypeError: error
@@ -3739,10 +3747,10 @@
3739
3747
  return ZodAny.create().superRefine((data, ctx) => {
3740
3748
  var _a, _b;
3741
3749
  if (!check(data)) {
3742
- const p2 = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
3743
- const _fatal = (_b = (_a = p2.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
3744
- const p22 = typeof p2 === "string" ? { message: p2 } : p2;
3745
- ctx.addIssue({ code: "custom", ...p22, fatal: _fatal });
3750
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
3751
+ const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
3752
+ const p2 = typeof p === "string" ? { message: p } : p;
3753
+ ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
3746
3754
  }
3747
3755
  });
3748
3756
  return ZodAny.create();
@@ -3840,7 +3848,7 @@
3840
3848
  date: (arg) => ZodDate.create({ ...arg, coerce: true })
3841
3849
  };
3842
3850
  const NEVER = INVALID;
3843
- var z$1 = /* @__PURE__ */ Object.freeze({
3851
+ var z = /* @__PURE__ */ Object.freeze({
3844
3852
  __proto__: null,
3845
3853
  defaultErrorMap: errorMap,
3846
3854
  setErrorMap,
@@ -3956,235 +3964,588 @@
3956
3964
  quotelessJson,
3957
3965
  ZodError
3958
3966
  });
3959
- var I$1 = Object.defineProperty;
3960
- var $ = (n2, t, e) => t in n2 ? I$1(n2, t, { enumerable: true, configurable: true, writable: true, value: e }) : n2[t] = e;
3961
- var m$2 = (n2, t, e) => $(n2, typeof t != "symbol" ? t + "" : t, e);
3962
- function w(n2) {
3963
- throw new Error("Unexpected object: " + n2);
3964
- }
3965
- function mn(n2) {
3966
- if (!n2 || typeof n2 != "object")
3967
+ z.object({
3968
+ /** Included left border. */
3969
+ from: z.number(),
3970
+ /** Excluded right border. */
3971
+ to: z.number()
3972
+ });
3973
+ function assertNever(x) {
3974
+ throw new Error("Unexpected object: " + x);
3975
+ }
3976
+ function isDataInfo(value) {
3977
+ if (!value || typeof value !== "object") {
3967
3978
  return false;
3968
- const t = n2;
3969
- if (!("type" in t))
3979
+ }
3980
+ const data = value;
3981
+ if (!("type" in data)) {
3970
3982
  return false;
3971
- switch (t.type) {
3983
+ }
3984
+ switch (data.type) {
3972
3985
  case "Json":
3973
- return typeof t.keyLength == "number" && t.data !== void 0 && typeof t.data == "object";
3986
+ return typeof data.keyLength === "number" && data.data !== void 0 && typeof data.data === "object";
3974
3987
  case "JsonPartitioned":
3975
- return typeof t.partitionKeyLength == "number" && t.parts !== void 0 && typeof t.parts == "object";
3976
3988
  case "BinaryPartitioned":
3977
- return typeof t.partitionKeyLength == "number" && t.parts !== void 0 && typeof t.parts == "object";
3989
+ case "ParquetPartitioned":
3990
+ return typeof data.partitionKeyLength === "number" && data.parts !== void 0 && typeof data.parts === "object";
3978
3991
  default:
3979
3992
  return false;
3980
3993
  }
3981
3994
  }
3982
- function yn(n2, t) {
3983
- if (n2 !== void 0)
3984
- switch (n2.type) {
3985
- case "Json":
3986
- return n2;
3987
- case "JsonPartitioned": {
3988
- const e = {};
3989
- for (const [r, o] of Object.entries(n2.parts))
3990
- e[r] = t(o);
3991
- return {
3992
- ...n2,
3993
- parts: e
3994
- };
3995
+ function mapDataInfo(dataInfo, mapFn) {
3996
+ if (dataInfo === void 0) {
3997
+ return void 0;
3998
+ }
3999
+ switch (dataInfo.type) {
4000
+ case "Json":
4001
+ return dataInfo;
4002
+ case "JsonPartitioned": {
4003
+ const newParts = {};
4004
+ for (const [key, blob] of Object.entries(dataInfo.parts)) {
4005
+ newParts[key] = mapFn(blob);
3995
4006
  }
3996
- case "BinaryPartitioned": {
3997
- const e = {};
3998
- for (const [r, o] of Object.entries(n2.parts))
3999
- e[r] = {
4000
- index: t(o.index),
4001
- values: t(o.values)
4002
- };
4003
- return {
4004
- ...n2,
4005
- parts: e
4007
+ return {
4008
+ ...dataInfo,
4009
+ parts: newParts
4010
+ };
4011
+ }
4012
+ case "BinaryPartitioned": {
4013
+ const newParts = {};
4014
+ for (const [key, chunk] of Object.entries(dataInfo.parts)) {
4015
+ newParts[key] = {
4016
+ index: mapFn(chunk.index),
4017
+ values: mapFn(chunk.values)
4006
4018
  };
4007
4019
  }
4020
+ return {
4021
+ ...dataInfo,
4022
+ parts: newParts
4023
+ };
4024
+ }
4025
+ case "ParquetPartitioned": {
4026
+ const newParts = {};
4027
+ for (const [key, blob] of Object.entries(dataInfo.parts)) {
4028
+ newParts[key] = mapFn(blob);
4029
+ }
4030
+ return {
4031
+ ...dataInfo,
4032
+ parts: newParts
4033
+ };
4034
+ }
4035
+ }
4036
+ }
4037
+ function visitDataInfo(dataInfo, cb) {
4038
+ switch (dataInfo.type) {
4039
+ case "Json":
4040
+ break;
4041
+ case "JsonPartitioned": {
4042
+ Object.values(dataInfo.parts).forEach(cb);
4043
+ break;
4044
+ }
4045
+ case "BinaryPartitioned": {
4046
+ Object.values(dataInfo.parts).forEach((chunk) => {
4047
+ cb(chunk.index);
4048
+ cb(chunk.values);
4049
+ });
4050
+ break;
4008
4051
  }
4052
+ case "ParquetPartitioned": {
4053
+ Object.values(dataInfo.parts).forEach(cb);
4054
+ break;
4055
+ }
4056
+ }
4009
4057
  }
4010
- function j(n2) {
4011
- if (!n2 || typeof n2 != "object")
4058
+ function isDataInfoEntries(value) {
4059
+ if (!value || typeof value !== "object") {
4012
4060
  return false;
4013
- const t = n2;
4014
- if (!("type" in t))
4061
+ }
4062
+ const data = value;
4063
+ if (!("type" in data)) {
4015
4064
  return false;
4016
- switch (t.type) {
4065
+ }
4066
+ switch (data.type) {
4017
4067
  case "Json":
4018
- return typeof t.keyLength == "number" && Array.isArray(t.data);
4068
+ return typeof data.keyLength === "number" && Array.isArray(data.data);
4019
4069
  case "JsonPartitioned":
4020
- return typeof t.partitionKeyLength == "number" && Array.isArray(t.parts);
4021
4070
  case "BinaryPartitioned":
4022
- return typeof t.partitionKeyLength == "number" && Array.isArray(t.parts);
4071
+ case "ParquetPartitioned":
4072
+ return typeof data.partitionKeyLength === "number" && Array.isArray(data.parts);
4023
4073
  default:
4024
4074
  return false;
4025
4075
  }
4026
4076
  }
4027
- function ln(n2) {
4028
- return j(n2) ? n2.type === "JsonPartitioned" || n2.type === "BinaryPartitioned" : false;
4077
+ function isPartitionedDataInfoEntries(value) {
4078
+ if (!isDataInfoEntries(value))
4079
+ return false;
4080
+ switch (value.type) {
4081
+ case "JsonPartitioned":
4082
+ case "BinaryPartitioned":
4083
+ case "ParquetPartitioned":
4084
+ return true;
4085
+ default:
4086
+ return false;
4087
+ }
4029
4088
  }
4030
- function hn(n2) {
4031
- switch (n2.type) {
4032
- case "Json": {
4033
- const t = Object.entries(n2.data).map(([e, r]) => ({ key: JSON.parse(e), value: r }));
4089
+ function dataInfoToEntries(dataInfo) {
4090
+ switch (dataInfo.type) {
4091
+ case "Json":
4034
4092
  return {
4035
4093
  type: "Json",
4036
- keyLength: n2.keyLength,
4037
- data: t
4094
+ keyLength: dataInfo.keyLength,
4095
+ data: Object.entries(dataInfo.data).map(([keyStr, value]) => {
4096
+ const key = JSON.parse(keyStr);
4097
+ return { key, value };
4098
+ })
4038
4099
  };
4039
- }
4040
- case "JsonPartitioned": {
4041
- const t = Object.entries(n2.parts).map(([e, r]) => ({ key: JSON.parse(e), value: r }));
4100
+ case "JsonPartitioned":
4042
4101
  return {
4043
4102
  type: "JsonPartitioned",
4044
- partitionKeyLength: n2.partitionKeyLength,
4045
- parts: t
4103
+ partitionKeyLength: dataInfo.partitionKeyLength,
4104
+ parts: Object.entries(dataInfo.parts).map(([keyStr, blob]) => {
4105
+ const key = JSON.parse(keyStr);
4106
+ return { key, value: blob };
4107
+ })
4046
4108
  };
4047
- }
4048
- case "BinaryPartitioned": {
4049
- const t = Object.entries(n2.parts).map(([e, r]) => ({ key: JSON.parse(e), value: r }));
4109
+ case "BinaryPartitioned":
4050
4110
  return {
4051
4111
  type: "BinaryPartitioned",
4052
- partitionKeyLength: n2.partitionKeyLength,
4053
- parts: t
4112
+ partitionKeyLength: dataInfo.partitionKeyLength,
4113
+ parts: Object.entries(dataInfo.parts).map(([keyStr, chunk]) => {
4114
+ const key = JSON.parse(keyStr);
4115
+ return { key, value: chunk };
4116
+ })
4054
4117
  };
4055
- }
4118
+ case "ParquetPartitioned":
4119
+ return {
4120
+ type: "ParquetPartitioned",
4121
+ partitionKeyLength: dataInfo.partitionKeyLength,
4122
+ parts: Object.entries(dataInfo.parts).map(([keyStr, blob]) => {
4123
+ const key = JSON.parse(keyStr);
4124
+ return { key, value: blob };
4125
+ })
4126
+ };
4127
+ default:
4128
+ assertNever(dataInfo);
4056
4129
  }
4057
4130
  }
4058
- function gn(n2) {
4059
- switch (n2.type) {
4060
- case "Json": {
4061
- const t = {};
4062
- for (const e of n2.data)
4063
- t[JSON.stringify(e.key)] = e.value;
4131
+ function entriesToDataInfo(dataInfoEntries) {
4132
+ switch (dataInfoEntries.type) {
4133
+ case "Json":
4064
4134
  return {
4065
4135
  type: "Json",
4066
- keyLength: n2.keyLength,
4067
- data: t
4136
+ keyLength: dataInfoEntries.keyLength,
4137
+ data: Object.fromEntries(dataInfoEntries.data.map(({ key, value }) => [JSON.stringify(key), value]))
4068
4138
  };
4069
- }
4070
- case "JsonPartitioned": {
4071
- const t = {};
4072
- for (const e of n2.parts)
4073
- t[JSON.stringify(e.key)] = e.value;
4139
+ case "JsonPartitioned":
4074
4140
  return {
4075
4141
  type: "JsonPartitioned",
4076
- partitionKeyLength: n2.partitionKeyLength,
4077
- parts: t
4142
+ partitionKeyLength: dataInfoEntries.partitionKeyLength,
4143
+ parts: Object.fromEntries(dataInfoEntries.parts.map(({ key, value }) => [JSON.stringify(key), value]))
4078
4144
  };
4079
- }
4080
- case "BinaryPartitioned": {
4081
- const t = {};
4082
- for (const e of n2.parts)
4083
- t[JSON.stringify(e.key)] = e.value;
4145
+ case "BinaryPartitioned":
4084
4146
  return {
4085
4147
  type: "BinaryPartitioned",
4086
- partitionKeyLength: n2.partitionKeyLength,
4087
- parts: t
4148
+ partitionKeyLength: dataInfoEntries.partitionKeyLength,
4149
+ parts: Object.fromEntries(dataInfoEntries.parts.map(({ key, value }) => [JSON.stringify(key), value]))
4150
+ };
4151
+ case "ParquetPartitioned":
4152
+ return {
4153
+ type: "ParquetPartitioned",
4154
+ partitionKeyLength: dataInfoEntries.partitionKeyLength,
4155
+ parts: Object.fromEntries(dataInfoEntries.parts.map(({ key, value }) => [JSON.stringify(key), value]))
4088
4156
  };
4157
+ default:
4158
+ assertNever(dataInfoEntries);
4159
+ }
4160
+ }
4161
+ function stringifyValue(value) {
4162
+ if (typeof value === "string") {
4163
+ return `String value was thrown: ${value}`;
4164
+ }
4165
+ if (value && typeof value === "object") {
4166
+ try {
4167
+ return `Plain object was thrown: ${JSON.stringify(value)}`;
4168
+ } catch (jsonError) {
4169
+ const errorMessage = jsonError instanceof Error ? jsonError.message : String(jsonError);
4170
+ return `Non-serializable object was thrown (JSON.stringify failed: ${errorMessage}): ${String(value)}`;
4171
+ }
4172
+ }
4173
+ return String(`Non-Error value (${typeof value}) was thrown: ${value}`);
4174
+ }
4175
+ function ensureError(value) {
4176
+ if (value instanceof Error) {
4177
+ return value;
4178
+ }
4179
+ return new Error(stringifyValue(value));
4180
+ }
4181
+ function getDefaultExportFromCjs(x) {
4182
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
4183
+ }
4184
+ var canonicalize$1;
4185
+ var hasRequiredCanonicalize;
4186
+ function requireCanonicalize() {
4187
+ if (hasRequiredCanonicalize) return canonicalize$1;
4188
+ hasRequiredCanonicalize = 1;
4189
+ canonicalize$1 = function serialize(object) {
4190
+ if (typeof object === "number" && isNaN(object)) {
4191
+ throw new Error("NaN is not allowed");
4192
+ }
4193
+ if (typeof object === "number" && !isFinite(object)) {
4194
+ throw new Error("Infinity is not allowed");
4089
4195
  }
4196
+ if (object === null || typeof object !== "object") {
4197
+ return JSON.stringify(object);
4198
+ }
4199
+ if (object.toJSON instanceof Function) {
4200
+ return serialize(object.toJSON());
4201
+ }
4202
+ if (Array.isArray(object)) {
4203
+ const values2 = object.reduce((t, cv, ci) => {
4204
+ const comma = ci === 0 ? "" : ",";
4205
+ const value = cv === void 0 || typeof cv === "symbol" ? null : cv;
4206
+ return `${t}${comma}${serialize(value)}`;
4207
+ }, "");
4208
+ return `[${values2}]`;
4209
+ }
4210
+ const values = Object.keys(object).sort().reduce((t, cv) => {
4211
+ if (object[cv] === void 0 || typeof object[cv] === "symbol") {
4212
+ return t;
4213
+ }
4214
+ const comma = t.length === 0 ? "" : ",";
4215
+ return `${t}${comma}${serialize(cv)}:${serialize(object[cv])}`;
4216
+ }, "");
4217
+ return `{${values}}`;
4218
+ };
4219
+ return canonicalize$1;
4220
+ }
4221
+ var canonicalizeExports = requireCanonicalize();
4222
+ const canonicalize = /* @__PURE__ */ getDefaultExportFromCjs(canonicalizeExports);
4223
+ function stringifyJson(value) {
4224
+ return JSON.stringify(value);
4225
+ }
4226
+ function canonicalizeJson(value) {
4227
+ return canonicalize(value);
4228
+ }
4229
+ function parseJson(value) {
4230
+ return JSON.parse(value);
4231
+ }
4232
+ const ValueType = {
4233
+ Int: "Int",
4234
+ Long: "Long",
4235
+ Float: "Float",
4236
+ Double: "Double",
4237
+ String: "String",
4238
+ Bytes: "Bytes"
4239
+ };
4240
+ function readMetadata(metadata, key) {
4241
+ return metadata == null ? void 0 : metadata[key];
4242
+ }
4243
+ function readMetadataJsonOrThrow(metadata, metadataJson, key, methodNameInError = "readMetadataJsonOrThrow") {
4244
+ const json = readMetadata(metadata, key);
4245
+ if (json === void 0)
4246
+ return void 0;
4247
+ const schema = metadataJson[key];
4248
+ try {
4249
+ const value = JSON.parse(json);
4250
+ return schema.parse(value);
4251
+ } catch (error) {
4252
+ throw new Error(`${methodNameInError} failed, key: ${String(key)}, value: ${json}, error: ${ensureError(error)}`);
4253
+ }
4254
+ }
4255
+ function readMetadataJson(metadata, metadataJson, key) {
4256
+ try {
4257
+ return readMetadataJsonOrThrow(metadata, metadataJson, key);
4258
+ } catch {
4259
+ return void 0;
4260
+ }
4261
+ }
4262
+ const Annotation = {
4263
+ DiscreteValues: "pl7.app/discreteValues",
4264
+ Graph: {
4265
+ IsVirtual: "pl7.app/graph/isVirtual"
4266
+ },
4267
+ HideDataFromUi: "pl7.app/hideDataFromUi",
4268
+ IsLinkerColumn: "pl7.app/isLinkerColumn",
4269
+ Label: "pl7.app/label",
4270
+ Max: "pl7.app/max",
4271
+ Min: "pl7.app/min",
4272
+ Parents: "pl7.app/parents",
4273
+ Sequence: {
4274
+ Annotation: {
4275
+ Mapping: "pl7.app/sequence/annotation/mapping"
4276
+ },
4277
+ IsAnnotation: "pl7.app/sequence/isAnnotation"
4278
+ },
4279
+ Table: {
4280
+ OrderPriority: "pl7.app/table/orderPriority"
4281
+ },
4282
+ Trace: "pl7.app/trace"
4283
+ };
4284
+ const AxisSpec = z.object({
4285
+ type: z.nativeEnum(ValueType),
4286
+ name: z.string(),
4287
+ domain: z.record(z.string(), z.string()).optional(),
4288
+ annotations: z.record(z.string(), z.string()).optional(),
4289
+ parentAxes: z.array(z.number()).optional()
4290
+ }).passthrough();
4291
+ const AnnotationJson = {
4292
+ [Annotation.DiscreteValues]: z.array(z.string()).or(z.array(z.number())),
4293
+ [Annotation.Graph.IsVirtual]: z.boolean(),
4294
+ [Annotation.HideDataFromUi]: z.boolean(),
4295
+ [Annotation.IsLinkerColumn]: z.boolean(),
4296
+ [Annotation.Max]: z.number(),
4297
+ [Annotation.Min]: z.number(),
4298
+ [Annotation.Parents]: z.array(AxisSpec),
4299
+ [Annotation.Sequence.Annotation.Mapping]: z.record(z.string(), z.string()),
4300
+ [Annotation.Sequence.IsAnnotation]: z.boolean(),
4301
+ [Annotation.Table.OrderPriority]: z.number(),
4302
+ [Annotation.Trace]: z.record(z.string(), z.unknown())
4303
+ };
4304
+ function readAnnotation(spec, key) {
4305
+ return readMetadata(spec == null ? void 0 : spec.annotations, key);
4306
+ }
4307
+ function readAnnotationJson(spec, key) {
4308
+ return readMetadataJson(spec == null ? void 0 : spec.annotations, AnnotationJson, key);
4309
+ }
4310
+ function makeAxisTree(axis) {
4311
+ return { axis, children: [] };
4312
+ }
4313
+ function getAxesTree(rootAxis) {
4314
+ const root = makeAxisTree(rootAxis);
4315
+ let nodesQ = [root];
4316
+ while (nodesQ.length) {
4317
+ const nextNodes = [];
4318
+ for (const node of nodesQ) {
4319
+ node.children = node.axis.parentAxesSpec.map(makeAxisTree);
4320
+ nextNodes.push(...node.children);
4321
+ }
4322
+ nodesQ = nextNodes;
4323
+ }
4324
+ return root;
4325
+ }
4326
+ function getArrayFromAxisTree(tree) {
4327
+ const res = [tree.axis];
4328
+ let nodesQ = [tree];
4329
+ while (nodesQ.length) {
4330
+ const nextNodes = [];
4331
+ for (const node of nodesQ) {
4332
+ for (const parent of node.children) {
4333
+ res.push(parent.axis);
4334
+ nextNodes.push(parent);
4335
+ }
4336
+ }
4337
+ nodesQ = nextNodes;
4338
+ }
4339
+ return res;
4340
+ }
4341
+ function canonicalizeAxisWithParents(axis) {
4342
+ return canonicalizeJson(getArrayFromAxisTree(getAxesTree(axis)).map(getAxisId));
4343
+ }
4344
+ function normalizingAxesComparator(axis1, axis2) {
4345
+ if (axis1.name !== axis2.name) {
4346
+ return axis1.name < axis2.name ? 1 : -1;
4347
+ }
4348
+ if (axis1.type !== axis2.type) {
4349
+ return axis1.type < axis2.type ? 1 : -1;
4350
+ }
4351
+ const domain1 = canonicalizeJson(axis1.domain ?? {});
4352
+ const domain2 = canonicalizeJson(axis2.domain ?? {});
4353
+ if (domain1 !== domain2) {
4354
+ return domain1 < domain2 ? 1 : -1;
4355
+ }
4356
+ const parents1 = canonicalizeAxisWithParents(axis1);
4357
+ const parents2 = canonicalizeAxisWithParents(axis2);
4358
+ if (parents1 !== parents2) {
4359
+ return parents1 < parents2 ? 1 : -1;
4360
+ }
4361
+ const annotation1 = canonicalizeJson(axis1.annotations ?? {});
4362
+ const annotation2 = canonicalizeJson(axis2.annotations ?? {});
4363
+ if (annotation1 !== annotation2) {
4364
+ return annotation1 < annotation2 ? 1 : -1;
4365
+ }
4366
+ return 0;
4367
+ }
4368
+ function parseParentsFromAnnotations(axis) {
4369
+ const parentsList = readAnnotationJson(axis, Annotation.Parents);
4370
+ if (parentsList === void 0) {
4371
+ return [];
4372
+ }
4373
+ return parentsList;
4374
+ }
4375
+ function sortParentsDeep(axisSpec) {
4376
+ axisSpec.parentAxesSpec.forEach(sortParentsDeep);
4377
+ axisSpec.parentAxesSpec.sort(normalizingAxesComparator);
4378
+ }
4379
+ function hasCycleOfParents(axisSpec) {
4380
+ const root = makeAxisTree(axisSpec);
4381
+ let nodesQ = [root];
4382
+ const ancestors = new Set(canonicalizeJson(getAxisId(axisSpec)));
4383
+ while (nodesQ.length) {
4384
+ const nextNodes = [];
4385
+ const levelIds = /* @__PURE__ */ new Set();
4386
+ for (const node of nodesQ) {
4387
+ node.children = node.axis.parentAxesSpec.map(makeAxisTree);
4388
+ for (const child of node.children) {
4389
+ const childId = canonicalizeJson(getAxisId(child.axis));
4390
+ if (!levelIds.has(childId)) {
4391
+ nextNodes.push(child);
4392
+ levelIds.add(childId);
4393
+ if (ancestors.has(childId)) {
4394
+ return true;
4395
+ }
4396
+ ancestors.add(childId);
4397
+ }
4398
+ }
4399
+ }
4400
+ nodesQ = nextNodes;
4401
+ }
4402
+ return false;
4403
+ }
4404
+ function getNormalizedAxesList(axes) {
4405
+ if (!axes.length) {
4406
+ return [];
4407
+ }
4408
+ const modifiedAxes = axes.map((axis) => {
4409
+ const { parentAxes: _, ...copiedRest } = axis;
4410
+ return { ...copiedRest, annotations: { ...copiedRest.annotations }, parentAxesSpec: [] };
4411
+ });
4412
+ axes.forEach((axis, idx) => {
4413
+ var _a;
4414
+ const modifiedAxis = modifiedAxes[idx];
4415
+ if (axis.parentAxes) {
4416
+ modifiedAxis.parentAxesSpec = axis.parentAxes.map((idx2) => modifiedAxes[idx2]);
4417
+ } else {
4418
+ modifiedAxis.parentAxesSpec = getNormalizedAxesList(parseParentsFromAnnotations(axis));
4419
+ (_a = modifiedAxis.annotations) == null ? true : delete _a[Annotation.Parents];
4420
+ }
4421
+ });
4422
+ if (modifiedAxes.some(hasCycleOfParents)) {
4423
+ modifiedAxes.forEach((axis) => {
4424
+ axis.parentAxesSpec = [];
4425
+ });
4426
+ } else {
4427
+ modifiedAxes.forEach((axis) => {
4428
+ sortParentsDeep(axis);
4429
+ });
4090
4430
  }
4431
+ return modifiedAxes;
4091
4432
  }
4092
- function En(n2) {
4433
+ const PColumnName = {
4434
+ Label: "pl7.app/label"
4435
+ };
4436
+ function getColumnIdAndSpec(column) {
4093
4437
  return {
4094
- kind: n2.kind,
4095
- valueType: n2.valueType,
4096
- name: n2.name,
4097
- domain: n2.domain,
4098
- parentAxes: n2.parentAxes,
4099
- axesId: z(n2.axesSpec)
4438
+ columnId: column.id,
4439
+ spec: column.spec
4100
4440
  };
4101
4441
  }
4102
- function p$1(n2) {
4103
- const { type: t, name: e, domain: r } = n2;
4104
- return { type: t, name: e, ...r && { domain: r } };
4442
+ function getAxisId(spec) {
4443
+ const { type, name, domain } = spec;
4444
+ const result = { type, name };
4445
+ if (domain && Object.entries(domain).length > 0) {
4446
+ Object.assign(result, { domain });
4447
+ }
4448
+ return result;
4105
4449
  }
4106
- function z(n2) {
4107
- return n2.map(p$1);
4450
+ function getAxesId(spec) {
4451
+ return spec.map(getAxisId);
4108
4452
  }
4109
- function Jn(n2) {
4110
- return _e(p$1(n2));
4453
+ function canonicalizeAxisId(id) {
4454
+ return canonicalizeJson(getAxisId(id));
4111
4455
  }
4112
- function X$1(n2, t) {
4113
- if (n2 === void 0) return t === void 0;
4114
- if (t === void 0) return true;
4115
- for (const e in t)
4116
- if (n2[e] !== t[e]) return false;
4456
+ function matchDomain$1(query, target) {
4457
+ if (query === void 0)
4458
+ return target === void 0;
4459
+ if (target === void 0)
4460
+ return true;
4461
+ for (const k in target) {
4462
+ if (query[k] !== target[k])
4463
+ return false;
4464
+ }
4117
4465
  return true;
4118
4466
  }
4119
- function G(n2, t) {
4120
- return n2.name === t.name && X$1(n2.domain, t.domain);
4467
+ function matchAxisId(query, target) {
4468
+ return query.name === target.name && matchDomain$1(query.domain, target.domain);
4121
4469
  }
4122
- function On(n2, t) {
4123
- return { ...n2, src: l$1(n2.src, t) };
4470
+ function mapPTableDef(def, cb) {
4471
+ return { ...def, src: mapJoinEntry(def.src, cb) };
4124
4472
  }
4125
- function l$1(n2, t) {
4126
- switch (n2.type) {
4473
+ function mapJoinEntry(entry, cb) {
4474
+ switch (entry.type) {
4127
4475
  case "column":
4128
4476
  return {
4129
4477
  type: "column",
4130
- column: t(n2.column)
4478
+ column: cb(entry.column)
4131
4479
  };
4132
4480
  case "slicedColumn":
4133
4481
  return {
4134
4482
  type: "slicedColumn",
4135
- column: t(n2.column),
4136
- newId: n2.newId,
4137
- axisFilters: n2.axisFilters
4483
+ column: cb(entry.column),
4484
+ newId: entry.newId,
4485
+ axisFilters: entry.axisFilters
4138
4486
  };
4487
+ case "inlineColumn":
4488
+ return entry;
4139
4489
  case "inner":
4140
4490
  case "full":
4141
4491
  return {
4142
- type: n2.type,
4143
- entries: n2.entries.map((e) => l$1(e, t))
4492
+ type: entry.type,
4493
+ entries: entry.entries.map((col) => mapJoinEntry(col, cb))
4144
4494
  };
4145
4495
  case "outer":
4146
4496
  return {
4147
4497
  type: "outer",
4148
- primary: l$1(n2.primary, t),
4149
- secondary: n2.secondary.map((e) => l$1(e, t))
4498
+ primary: mapJoinEntry(entry.primary, cb),
4499
+ secondary: entry.secondary.map((col) => mapJoinEntry(col, cb))
4150
4500
  };
4151
4501
  default:
4152
- w(n2);
4502
+ assertNever(entry);
4153
4503
  }
4154
4504
  }
4155
- function Q(n2) {
4156
- return _e(n2);
4505
+ function stringifyColumnId(id) {
4506
+ return canonicalize(id);
4157
4507
  }
4158
- function x(n2) {
4159
- return _e(p$1(n2));
4508
+ function axisKey(axis) {
4509
+ return canonicalize(getAxisId(axis));
4160
4510
  }
4161
- function A(n2, t) {
4162
- return JSON.stringify([n2, t]);
4511
+ function domainKey(key, value) {
4512
+ return JSON.stringify([key, value]);
4163
4513
  }
4164
- class $n {
4514
+ class AnchoredIdDeriver {
4165
4515
  /**
4166
4516
  * Creates a new anchor context from a set of anchor column specifications
4167
4517
  * @param anchors Record of anchor column specifications indexed by anchor ID
4168
4518
  */
4169
- constructor(t) {
4170
- m$2(this, "domains", /* @__PURE__ */ new Map());
4171
- m$2(this, "axes", /* @__PURE__ */ new Map());
4172
- m$2(this, "domainPacks", []);
4173
- m$2(this, "domainPackToAnchor", /* @__PURE__ */ new Map());
4174
- this.anchors = t;
4175
- const e = Object.entries(t);
4176
- e.sort((r, o) => r[0].localeCompare(o[0]));
4177
- for (const [r, o] of e) {
4178
- for (let s2 = 0; s2 < o.axesSpec.length; s2++) {
4179
- const a = o.axesSpec[s2], i = x(a);
4180
- this.axes.set(i, { anchor: r, idx: s2 });
4519
+ constructor(anchors) {
4520
+ __publicField(this, "anchors");
4521
+ __publicField(this, "domains", /* @__PURE__ */ new Map());
4522
+ __publicField(this, "axes", /* @__PURE__ */ new Map());
4523
+ /**
4524
+ * Domain packs are used to group domain keys that can be anchored to the same anchor
4525
+ * This is used to optimize the lookup of domain anchors
4526
+ */
4527
+ __publicField(this, "domainPacks", []);
4528
+ /**
4529
+ * Maps domain packs to anchors
4530
+ */
4531
+ __publicField(this, "domainPackToAnchor", /* @__PURE__ */ new Map());
4532
+ this.anchors = anchors;
4533
+ const anchorEntries = Object.entries(anchors);
4534
+ anchorEntries.sort((a, b) => a[0].localeCompare(b[0]));
4535
+ for (const [anchorId, spec] of anchorEntries) {
4536
+ for (let axisIdx = 0; axisIdx < spec.axesSpec.length; axisIdx++) {
4537
+ const axis = spec.axesSpec[axisIdx];
4538
+ const key = axisKey(axis);
4539
+ this.axes.set(key, { anchor: anchorId, idx: axisIdx });
4181
4540
  }
4182
- if (o.domain !== void 0) {
4183
- const s2 = Object.entries(o.domain);
4184
- s2.sort((a, i) => a[0].localeCompare(i[0])), this.domainPackToAnchor.set(JSON.stringify(s2), r), this.domainPacks.push(s2.map(([a]) => a));
4185
- for (const [a, i] of s2) {
4186
- const u2 = A(a, i);
4187
- this.domains.set(u2, r);
4541
+ if (spec.domain !== void 0) {
4542
+ const domainEntries = Object.entries(spec.domain);
4543
+ domainEntries.sort((a, b) => a[0].localeCompare(b[0]));
4544
+ this.domainPackToAnchor.set(JSON.stringify(domainEntries), anchorId);
4545
+ this.domainPacks.push(domainEntries.map(([dKey]) => dKey));
4546
+ for (const [dKey, dValue] of domainEntries) {
4547
+ const key = domainKey(dKey, dValue);
4548
+ this.domains.set(key, anchorId);
4188
4549
  }
4189
4550
  }
4190
4551
  }
@@ -4192,57 +4553,69 @@
4192
4553
  /**
4193
4554
  * Implementation of derive method
4194
4555
  */
4195
- derive(t, e) {
4196
- const r = {
4197
- name: t.name,
4556
+ derive(spec, axisFilters) {
4557
+ const result = {
4558
+ name: spec.name,
4198
4559
  axes: []
4199
4560
  };
4200
- let o;
4201
- if (t.domain !== void 0)
4202
- n:
4203
- for (const a of this.domainPacks) {
4204
- const i = [];
4205
- for (const c2 of a) {
4206
- const d = t.domain[c2];
4207
- if (d !== void 0)
4208
- i.push([c2, d]);
4209
- else
4210
- break n;
4211
- }
4212
- const u2 = this.domainPackToAnchor.get(JSON.stringify(i));
4213
- if (u2 !== void 0) {
4214
- r.domainAnchor = u2, o = new Set(a);
4215
- break;
4216
- }
4561
+ let skipDomains = void 0;
4562
+ if (spec.domain !== void 0) {
4563
+ outer: for (const domainPack of this.domainPacks) {
4564
+ const dAnchor = [];
4565
+ for (const domainKey2 of domainPack) {
4566
+ const dValue = spec.domain[domainKey2];
4567
+ if (dValue !== void 0)
4568
+ dAnchor.push([domainKey2, dValue]);
4569
+ else
4570
+ break outer;
4571
+ }
4572
+ const domainAnchor = this.domainPackToAnchor.get(JSON.stringify(dAnchor));
4573
+ if (domainAnchor !== void 0) {
4574
+ result.domainAnchor = domainAnchor;
4575
+ skipDomains = new Set(domainPack);
4576
+ break;
4217
4577
  }
4218
- for (const [a, i] of Object.entries(t.domain ?? {})) {
4219
- if (o !== void 0 && o.has(a))
4578
+ }
4579
+ }
4580
+ for (const [dKey, dValue] of Object.entries(spec.domain ?? {})) {
4581
+ if (skipDomains !== void 0 && skipDomains.has(dKey))
4220
4582
  continue;
4221
- const u2 = A(a, i), c2 = this.domains.get(u2);
4222
- r.domain ?? (r.domain = {}), r.domain[a] = c2 ? { anchor: c2 } : i;
4223
- }
4224
- if (r.axes = t.axesSpec.map((a) => {
4225
- const i = x(a), u2 = this.axes.get(i);
4226
- return u2 === void 0 ? p$1(a) : u2;
4227
- }), !e || e.length === 0)
4228
- return r;
4229
- const s2 = [];
4230
- for (const a of e) {
4231
- const [i, u2] = a;
4232
- if (typeof i == "number") {
4233
- if (i < 0 || i >= t.axesSpec.length)
4234
- throw new Error(`Axis index ${i} is out of bounds (0-${t.axesSpec.length - 1})`);
4235
- s2.push([i, u2]);
4583
+ const key = domainKey(dKey, dValue);
4584
+ const anchorId = this.domains.get(key);
4585
+ result.domain ?? (result.domain = {});
4586
+ result.domain[dKey] = anchorId ? { anchor: anchorId } : dValue;
4587
+ }
4588
+ result.axes = spec.axesSpec.map((axis) => {
4589
+ const key = axisKey(axis);
4590
+ const anchorAxisRef = this.axes.get(key);
4591
+ if (anchorAxisRef === void 0)
4592
+ return getAxisId(axis);
4593
+ else
4594
+ return anchorAxisRef;
4595
+ });
4596
+ if (!axisFilters || axisFilters.length === 0) {
4597
+ return result;
4598
+ }
4599
+ const resolvedFilters = [];
4600
+ for (const filter of axisFilters) {
4601
+ const [axisIdOrIndex, value] = filter;
4602
+ if (typeof axisIdOrIndex === "number") {
4603
+ if (axisIdOrIndex < 0 || axisIdOrIndex >= spec.axesSpec.length) {
4604
+ throw new Error(`Axis index ${axisIdOrIndex} is out of bounds (0-${spec.axesSpec.length - 1})`);
4605
+ }
4606
+ resolvedFilters.push([axisIdOrIndex, value]);
4236
4607
  } else {
4237
- const c2 = t.axesSpec.findIndex((d) => d.name === i);
4238
- if (c2 === -1)
4239
- throw new Error(`Axis with name "${i}" not found in the column specification`);
4240
- s2.push([c2, u2]);
4608
+ const axisIndex = spec.axesSpec.findIndex((axis) => axis.name === axisIdOrIndex);
4609
+ if (axisIndex === -1) {
4610
+ throw new Error(`Axis with name "${axisIdOrIndex}" not found in the column specification`);
4611
+ }
4612
+ resolvedFilters.push([axisIndex, value]);
4241
4613
  }
4242
4614
  }
4243
- return s2.sort((a, i) => a[0] - i[0]), {
4244
- source: r,
4245
- axisFilters: s2
4615
+ resolvedFilters.sort((a, b) => a[0] - b[0]);
4616
+ return {
4617
+ source: result,
4618
+ axisFilters: resolvedFilters
4246
4619
  };
4247
4620
  }
4248
4621
  /**
@@ -4251,446 +4624,580 @@
4251
4624
  * @param axisFilters Optional axis filters to apply to the column
4252
4625
  * @returns A canonicalized string representation of the anchored column identifier
4253
4626
  */
4254
- deriveS(t, e) {
4255
- return Q(this.derive(t, e));
4256
- }
4257
- }
4258
- function Dn(n2, t, e) {
4259
- const r = { ...t }, o = (e == null ? void 0 : e.ignoreMissingDomains) ?? false;
4260
- if (r.domainAnchor !== void 0) {
4261
- const s2 = n2[r.domainAnchor];
4262
- if (!s2)
4263
- throw new Error(`Anchor "${r.domainAnchor}" not found`);
4264
- const a = s2.domain || {};
4265
- r.domain = { ...a, ...r.domain }, delete r.domainAnchor;
4266
- }
4267
- if (r.domain) {
4268
- const s2 = {};
4269
- for (const [a, i] of Object.entries(r.domain))
4270
- if (typeof i == "string")
4271
- s2[a] = i;
4272
- else {
4273
- const u2 = n2[i.anchor];
4274
- if (!u2)
4275
- throw new Error(`Anchor "${i.anchor}" not found for domain key "${a}"`);
4276
- if (!u2.domain || u2.domain[a] === void 0) {
4277
- if (!o)
4278
- throw new Error(`Domain key "${a}" not found in anchor "${i.anchor}"`);
4627
+ deriveS(spec, axisFilters) {
4628
+ return stringifyColumnId(this.derive(spec, axisFilters));
4629
+ }
4630
+ }
4631
+ function resolveAnchors(anchors, matcher, options) {
4632
+ const result = { ...matcher };
4633
+ const ignoreMissingDomains = (options == null ? void 0 : options.ignoreMissingDomains) ?? false;
4634
+ if (result.domainAnchor !== void 0) {
4635
+ const anchorSpec = anchors[result.domainAnchor];
4636
+ if (!anchorSpec)
4637
+ throw new Error(`Anchor "${result.domainAnchor}" not found`);
4638
+ const anchorDomains = anchorSpec.domain || {};
4639
+ result.domain = { ...anchorDomains, ...result.domain };
4640
+ delete result.domainAnchor;
4641
+ }
4642
+ if (result.domain) {
4643
+ const resolvedDomain = {};
4644
+ for (const [key, value] of Object.entries(result.domain)) {
4645
+ if (typeof value === "string") {
4646
+ resolvedDomain[key] = value;
4647
+ } else {
4648
+ const anchorSpec = anchors[value.anchor];
4649
+ if (!anchorSpec)
4650
+ throw new Error(`Anchor "${value.anchor}" not found for domain key "${key}"`);
4651
+ if (!anchorSpec.domain || anchorSpec.domain[key] === void 0) {
4652
+ if (!ignoreMissingDomains)
4653
+ throw new Error(`Domain key "${key}" not found in anchor "${value.anchor}"`);
4279
4654
  continue;
4280
4655
  }
4281
- s2[a] = u2.domain[a];
4656
+ resolvedDomain[key] = anchorSpec.domain[key];
4282
4657
  }
4283
- r.domain = s2;
4284
- }
4285
- return r.axes && (r.axes = r.axes.map((s2) => Y$1(n2, s2))), r;
4286
- }
4287
- function Y$1(n2, t) {
4288
- if (!Z$1(t))
4289
- return t;
4290
- const e = t.anchor, r = n2[e];
4291
- if (!r)
4292
- throw new Error(`Anchor "${e}" not found for axis reference`);
4293
- if ("idx" in t) {
4294
- if (t.idx < 0 || t.idx >= r.axesSpec.length)
4295
- throw new Error(`Axis index ${t.idx} out of bounds for anchor "${e}"`);
4296
- return r.axesSpec[t.idx];
4297
- } else if ("name" in t) {
4298
- const o = r.axesSpec.filter((s2) => s2.name === t.name);
4299
- if (o.length > 1)
4300
- throw new Error(`Multiple axes with name "${t.name}" found in anchor "${e}"`);
4301
- if (o.length === 0)
4302
- throw new Error(`Axis with name "${t.name}" not found in anchor "${e}"`);
4303
- return o[0];
4304
- } else if ("id" in t) {
4305
- const o = r.axesSpec.filter((s2) => G(t.id, p$1(s2)));
4306
- if (o.length > 1)
4307
- throw new Error(`Multiple matching axes found for matcher in anchor "${e}"`);
4308
- if (o.length === 0)
4309
- throw new Error(`No matching axis found for matcher in anchor "${e}"`);
4310
- return o[0];
4311
- }
4312
- throw new Error("Unsupported axis reference type");
4313
- }
4314
- function Z$1(n2) {
4315
- return typeof n2 == "object" && "anchor" in n2;
4316
- }
4317
- function f(n2) {
4318
- return n2.kind === "PColumn";
4319
- }
4320
- function q(n2) {
4321
- return f(n2.spec);
4322
- }
4323
- function jn(n2) {
4324
- if (!q(n2)) throw new Error(`not a PColumn (kind = ${n2.spec.kind})`);
4325
- return n2;
4326
- }
4327
- function Fn(n2, t) {
4328
- return n2 === void 0 ? void 0 : {
4329
- ...n2,
4330
- data: t(n2.data)
4658
+ }
4659
+ result.domain = resolvedDomain;
4660
+ }
4661
+ if (result.axes)
4662
+ result.axes = result.axes.map((axis) => resolveAxisReference(anchors, axis));
4663
+ return result;
4664
+ }
4665
+ function resolveAxisReference(anchors, axisRef) {
4666
+ if (!isAnchorAxisRef(axisRef))
4667
+ return axisRef;
4668
+ const anchorId = axisRef.anchor;
4669
+ const anchorSpec = anchors[anchorId];
4670
+ if (!anchorSpec)
4671
+ throw new Error(`Anchor "${anchorId}" not found for axis reference`);
4672
+ if ("idx" in axisRef) {
4673
+ if (axisRef.idx < 0 || axisRef.idx >= anchorSpec.axesSpec.length)
4674
+ throw new Error(`Axis index ${axisRef.idx} out of bounds for anchor "${anchorId}"`);
4675
+ return anchorSpec.axesSpec[axisRef.idx];
4676
+ } else if ("name" in axisRef) {
4677
+ const matches = anchorSpec.axesSpec.filter((axis) => axis.name === axisRef.name);
4678
+ if (matches.length > 1)
4679
+ throw new Error(`Multiple axes with name "${axisRef.name}" found in anchor "${anchorId}"`);
4680
+ if (matches.length === 0)
4681
+ throw new Error(`Axis with name "${axisRef.name}" not found in anchor "${anchorId}"`);
4682
+ return matches[0];
4683
+ } else if ("id" in axisRef) {
4684
+ const matches = anchorSpec.axesSpec.filter((axis) => matchAxisId(axisRef.id, getAxisId(axis)));
4685
+ if (matches.length > 1)
4686
+ throw new Error(`Multiple matching axes found for matcher in anchor "${anchorId}"`);
4687
+ if (matches.length === 0)
4688
+ throw new Error(`No matching axis found for matcher in anchor "${anchorId}"`);
4689
+ return matches[0];
4690
+ }
4691
+ throw new Error(`Unsupported axis reference type`);
4692
+ }
4693
+ function isAnchorAxisRef(value) {
4694
+ return typeof value === "object" && "anchor" in value;
4695
+ }
4696
+ function isPColumnSpec(spec) {
4697
+ return spec.kind === "PColumn";
4698
+ }
4699
+ function isPColumn(obj) {
4700
+ return isPColumnSpec(obj.spec);
4701
+ }
4702
+ function ensurePColumn(obj) {
4703
+ if (!isPColumn(obj))
4704
+ throw new Error(`not a PColumn (kind = ${obj.spec.kind})`);
4705
+ return obj;
4706
+ }
4707
+ function mapPObjectData(pObj, cb) {
4708
+ return pObj === void 0 ? void 0 : {
4709
+ ...pObj,
4710
+ data: cb(pObj.data)
4331
4711
  };
4332
4712
  }
4333
- function Un(n2) {
4334
- const t = /* @__PURE__ */ new Map(), e = (r) => {
4335
- switch (r.type) {
4713
+ function extractAllColumns(entry) {
4714
+ const columns = /* @__PURE__ */ new Map();
4715
+ const addAllColumns = (entry2) => {
4716
+ switch (entry2.type) {
4336
4717
  case "column":
4337
- t.set(r.column.id, r.column);
4718
+ columns.set(entry2.column.id, entry2.column);
4338
4719
  return;
4339
4720
  case "slicedColumn":
4340
- t.set(r.column.id, r.column);
4721
+ columns.set(entry2.column.id, entry2.column);
4722
+ return;
4723
+ case "inlineColumn":
4341
4724
  return;
4342
4725
  case "full":
4343
4726
  case "inner":
4344
- for (const o of r.entries) e(o);
4727
+ for (const e of entry2.entries)
4728
+ addAllColumns(e);
4345
4729
  return;
4346
4730
  case "outer":
4347
- e(r.primary);
4348
- for (const o of r.secondary) e(o);
4731
+ addAllColumns(entry2.primary);
4732
+ for (const e of entry2.secondary)
4733
+ addAllColumns(e);
4349
4734
  return;
4350
4735
  default:
4351
- w(r);
4736
+ assertNever(entry2);
4352
4737
  }
4353
4738
  };
4354
- return e(n2), [...t.values()];
4739
+ addAllColumns(entry);
4740
+ return [...columns.values()];
4355
4741
  }
4356
- function k(n2, t) {
4357
- if (n2.name !== void 0 && n2.name !== t.name)
4742
+ function matchAxis(selector, axis) {
4743
+ if (selector.name !== void 0 && selector.name !== axis.name)
4358
4744
  return false;
4359
- if (n2.type !== void 0) {
4360
- if (Array.isArray(n2.type)) {
4361
- if (!n2.type.includes(t.type))
4745
+ if (selector.type !== void 0) {
4746
+ if (Array.isArray(selector.type)) {
4747
+ if (!selector.type.includes(axis.type))
4362
4748
  return false;
4363
- } else if (n2.type !== t.type)
4749
+ } else if (selector.type !== axis.type) {
4364
4750
  return false;
4751
+ }
4365
4752
  }
4366
- if (n2.domain !== void 0) {
4367
- const e = t.domain || {};
4368
- for (const [r, o] of Object.entries(n2.domain))
4369
- if (e[r] !== o)
4753
+ if (selector.domain !== void 0) {
4754
+ const axisDomain = axis.domain || {};
4755
+ for (const [key, value] of Object.entries(selector.domain))
4756
+ if (axisDomain[key] !== value)
4370
4757
  return false;
4371
4758
  }
4372
4759
  return true;
4373
4760
  }
4374
- function N(n2, t) {
4375
- if (t.name !== void 0 && n2.name !== t.name || t.namePattern !== void 0 && !new RegExp(t.namePattern).test(n2.name))
4761
+ function matchPColumn(pcolumn, selector) {
4762
+ if (selector.name !== void 0 && pcolumn.name !== selector.name)
4376
4763
  return false;
4377
- if (t.type !== void 0) {
4378
- if (Array.isArray(t.type)) {
4379
- if (!t.type.includes(n2.valueType))
4764
+ if (selector.namePattern !== void 0 && !new RegExp(selector.namePattern).test(pcolumn.name))
4765
+ return false;
4766
+ if (selector.type !== void 0) {
4767
+ if (Array.isArray(selector.type)) {
4768
+ if (!selector.type.includes(pcolumn.valueType))
4380
4769
  return false;
4381
- } else if (t.type !== n2.valueType)
4770
+ } else if (selector.type !== pcolumn.valueType) {
4382
4771
  return false;
4772
+ }
4383
4773
  }
4384
- if (t.domain !== void 0) {
4385
- const e = n2.domain || {};
4386
- for (const [r, o] of Object.entries(t.domain))
4387
- if (e[r] !== o)
4774
+ if (selector.domain !== void 0) {
4775
+ const columnDomain = pcolumn.domain || {};
4776
+ for (const [key, value] of Object.entries(selector.domain))
4777
+ if (columnDomain[key] !== value)
4388
4778
  return false;
4389
4779
  }
4390
- if (t.axes !== void 0) {
4391
- const e = n2.axesSpec.map(p$1);
4392
- if (t.partialAxesMatch) {
4393
- for (const r of t.axes)
4394
- if (!e.some((o) => k(r, o)))
4780
+ if (selector.axes !== void 0) {
4781
+ const pcolumnAxes = pcolumn.axesSpec.map(getAxisId);
4782
+ if (selector.partialAxesMatch) {
4783
+ for (const selectorAxis of selector.axes)
4784
+ if (!pcolumnAxes.some((columnAxis) => matchAxis(selectorAxis, columnAxis)))
4395
4785
  return false;
4396
4786
  } else {
4397
- if (e.length !== t.axes.length)
4787
+ if (pcolumnAxes.length !== selector.axes.length)
4398
4788
  return false;
4399
- for (let r = 0; r < t.axes.length; r++)
4400
- if (!k(t.axes[r], e[r]))
4789
+ for (let i = 0; i < selector.axes.length; i++)
4790
+ if (!matchAxis(selector.axes[i], pcolumnAxes[i]))
4401
4791
  return false;
4402
4792
  }
4403
4793
  }
4404
- if (t.annotations !== void 0) {
4405
- const e = n2.annotations || {};
4406
- for (const [r, o] of Object.entries(t.annotations))
4407
- if (e[r] !== o)
4794
+ if (selector.annotations !== void 0) {
4795
+ const columnAnnotations = pcolumn.annotations || {};
4796
+ for (const [key, value] of Object.entries(selector.annotations))
4797
+ if (columnAnnotations[key] !== value)
4408
4798
  return false;
4409
4799
  }
4410
- if (t.annotationPatterns !== void 0) {
4411
- const e = n2.annotations || {};
4412
- for (const [r, o] of Object.entries(t.annotationPatterns)) {
4413
- const s2 = e[r];
4414
- if (s2 === void 0 || !new RegExp(o).test(s2))
4800
+ if (selector.annotationPatterns !== void 0) {
4801
+ const columnAnnotations = pcolumn.annotations || {};
4802
+ for (const [key, pattern] of Object.entries(selector.annotationPatterns)) {
4803
+ const value = columnAnnotations[key];
4804
+ if (value === void 0 || !new RegExp(pattern).test(value))
4415
4805
  return false;
4416
4806
  }
4417
4807
  }
4418
4808
  return true;
4419
4809
  }
4420
- function Kn(n2) {
4421
- return Array.isArray(n2) ? (t) => n2.some((e) => f(t) && N(t, e)) : (t) => f(t) && N(t, n2);
4422
- }
4423
- z$1.object({
4424
- __isRef: z$1.literal(true).describe("Crucial marker for the block dependency tree reconstruction"),
4425
- blockId: z$1.string().describe("Upstream block id"),
4426
- name: z$1.string().describe("Name of the output provided to the upstream block's output context")
4427
- }).describe(
4428
- "Universal reference type, allowing to set block connections. It is crucial that {@link __isRef} is present and equal to true, internal logic relies on this marker to build block dependency trees."
4429
- ).strict().readonly();
4430
- function Tn(n2) {
4431
- return typeof n2 == "object" && n2 !== null && "__isRef" in n2 && n2.__isRef === true && "blockId" in n2 && "name" in n2;
4432
- }
4433
- function _n$1(n2, t) {
4434
- return n2.ok ? { ok: true, value: t(n2.value) } : n2;
4810
+ function selectorsToPredicate(predicateOrSelectors) {
4811
+ if (Array.isArray(predicateOrSelectors))
4812
+ return (spec) => predicateOrSelectors.some((selector) => isPColumnSpec(spec) && matchPColumn(spec, selector));
4813
+ else
4814
+ return (spec) => isPColumnSpec(spec) && matchPColumn(spec, predicateOrSelectors);
4435
4815
  }
4436
- const sn = 24;
4437
- z$1.string().length(sn).regex(/[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]/).brand("PlId");
4438
- function Xn(n2) {
4439
- return _e(n2);
4440
- }
4441
- var stringify = { exports: {} };
4442
- var hasRequiredStringify;
4443
- function requireStringify() {
4444
- if (hasRequiredStringify) return stringify.exports;
4445
- hasRequiredStringify = 1;
4446
- (function(module2, exports3) {
4447
- exports3 = module2.exports = stringify2;
4448
- exports3.getSerialize = serializer;
4449
- function stringify2(obj, replacer, spaces, cycleReplacer) {
4450
- return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces);
4451
- }
4452
- function serializer(replacer, cycleReplacer) {
4453
- var stack = [], keys = [];
4454
- if (cycleReplacer == null) cycleReplacer = function(key, value) {
4455
- if (stack[0] === value) return "[Circular ~]";
4456
- return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
4457
- };
4458
- return function(key, value) {
4459
- if (stack.length > 0) {
4460
- var thisPos = stack.indexOf(this);
4461
- ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
4462
- ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
4463
- if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value);
4464
- } else stack.push(value);
4465
- return replacer == null ? value : replacer.call(this, key, value);
4466
- };
4467
- }
4468
- })(stringify, stringify.exports);
4469
- return stringify.exports;
4816
+ function deriveNativeId(spec) {
4817
+ const result = {
4818
+ kind: spec.kind,
4819
+ name: spec.name
4820
+ };
4821
+ if (spec.domain !== void 0)
4822
+ result.domain = spec.domain;
4823
+ if (isPColumnSpec(spec))
4824
+ result.axesSpec = getAxesId(spec.axesSpec);
4825
+ return canonicalize(result);
4470
4826
  }
4471
- requireStringify();
4472
- const l = z$1.object({
4473
- type: z$1.literal("PlError"),
4474
- name: z$1.string(),
4475
- message: z$1.string(),
4476
- /** The message with all details needed for SDK developers. */
4477
- fullMessage: z$1.string().optional(),
4478
- stack: z$1.string().optional()
4479
- }), c = l.extend({
4480
- cause: z$1.lazy(() => s).optional(),
4481
- errors: z$1.lazy(() => s.array()).optional()
4482
- }), m$1 = z$1.object({
4483
- type: z$1.literal("StandardError"),
4484
- name: z$1.string(),
4485
- message: z$1.string(),
4486
- stack: z$1.string().optional()
4487
- }), p = m$1.extend({
4488
- cause: z$1.lazy(() => s).optional(),
4489
- errors: z$1.lazy(() => s.array()).optional()
4490
- }), s = z$1.union([p, c]);
4491
- const u = z$1.object({
4492
- name: z$1.string(),
4493
- message: z$1.string(),
4494
- fullMessage: z$1.string().optional(),
4495
- stack: z$1.string().optional()
4496
- }), n = u.extend({
4497
- cause: z$1.lazy(() => n).optional(),
4498
- errors: z$1.lazy(() => n.array()).optional()
4499
- });
4500
- var Ue = Object.defineProperty;
4501
- var Me = (t, e, n2) => e in t ? Ue(t, e, { enumerable: true, configurable: true, writable: true, value: n2 }) : t[e] = n2;
4502
- var L = (t, e, n2) => Me(t, typeof e != "symbol" ? e + "" : e, n2);
4503
- function Z(t) {
4504
- return { type: "Immediate", value: t };
4505
- }
4506
- function it() {
4507
- return typeof globalThis.getPlatforma < "u" || typeof globalThis.platforma < "u";
4508
- }
4509
- function Te(t) {
4510
- if (t && typeof globalThis.getPlatforma == "function")
4511
- return globalThis.getPlatforma(t);
4512
- if (typeof globalThis.platforma < "u") return globalThis.platforma;
4513
- throw new Error("Can't get platforma instance.");
4514
- }
4515
- function st() {
4516
- if (typeof globalThis.cfgRenderCtx < "u") return globalThis.cfgRenderCtx;
4517
- }
4518
- function m() {
4519
- if (typeof globalThis.cfgRenderCtx < "u") return globalThis.cfgRenderCtx;
4520
- throw new Error("Not in config rendering context");
4521
- }
4522
- function Y(t, e) {
4523
- const n2 = st();
4524
- if (n2 === void 0) return false;
4525
- if (t in n2.callbackRegistry) throw new Error(`Callback with key ${t} already registered.`);
4526
- return n2.callbackRegistry[t] = e, true;
4527
- }
4528
- const ae = /* @__PURE__ */ new Map();
4529
- function ot(t, e) {
4530
- t in m().callbackRegistry || (m().callbackRegistry[t] = (n2) => {
4531
- for (const r of ae.get(t))
4532
- r(n2);
4533
- }, ae.set(t, [])), ae.get(t).push(e);
4534
- }
4535
- class S {
4536
- constructor(e, n2 = (r) => r) {
4537
- L(this, "isResolved", false);
4538
- L(this, "resolvedValue");
4539
- this.handle = e, this.postProcess = n2, ot(e, (r) => {
4540
- this.resolvedValue = n2(r), this.isResolved = true;
4541
- });
4827
+ class LinkerMap {
4828
+ constructor(linkerMap) {
4829
+ /** Graph of linkers connected by axes (single or grouped by parents) */
4830
+ __publicField(this, "data");
4831
+ this.data = linkerMap;
4542
4832
  }
4543
- map(e) {
4544
- return new S(this.handle, (n2) => e(this.postProcess(n2)));
4833
+ get keys() {
4834
+ return this.data.keys();
4545
4835
  }
4546
- mapDefined(e) {
4547
- return new S(this.handle, (n2) => {
4548
- const r = this.postProcess(n2);
4549
- return r ? e(r) : void 0;
4550
- });
4836
+ get keyAxesIds() {
4837
+ return [...this.data.keys()].map(parseJson);
4838
+ }
4839
+ static fromColumns(columns) {
4840
+ var _a, _b;
4841
+ const result = /* @__PURE__ */ new Map();
4842
+ for (const linker of columns.filter((l) => !!readAnnotationJson(l.spec, Annotation.IsLinkerColumn))) {
4843
+ const groups = LinkerMap.getAxesGroups(getNormalizedAxesList(linker.spec.axesSpec));
4844
+ if (groups.length !== 2) {
4845
+ continue;
4846
+ }
4847
+ const [left, right] = groups;
4848
+ const leftKeyVariants = LinkerMap.getAxesRoots(left).map((axis) => {
4849
+ const axes = getArrayFromAxisTree(getAxesTree(axis));
4850
+ const key = canonicalizeJson(axes.map(getAxisId));
4851
+ return [key, axes];
4852
+ });
4853
+ const rightKeyVariants = LinkerMap.getAxesRoots(right).map((axis) => {
4854
+ const axes = getArrayFromAxisTree(getAxesTree(axis));
4855
+ const key = canonicalizeJson(axes.map(getAxisId));
4856
+ return [key, axes];
4857
+ });
4858
+ for (const [keyLeft, spec] of leftKeyVariants) {
4859
+ if (!result.has(keyLeft)) {
4860
+ result.set(keyLeft, { keyAxesSpec: spec, linkWith: /* @__PURE__ */ new Map() });
4861
+ }
4862
+ }
4863
+ for (const [keyRight, spec] of rightKeyVariants) {
4864
+ if (!result.has(keyRight)) {
4865
+ result.set(keyRight, { keyAxesSpec: spec, linkWith: /* @__PURE__ */ new Map() });
4866
+ }
4867
+ }
4868
+ for (const [keyLeft] of leftKeyVariants) {
4869
+ for (const [keyRight] of rightKeyVariants) {
4870
+ (_a = result.get(keyLeft)) == null ? void 0 : _a.linkWith.set(keyRight, linker);
4871
+ (_b = result.get(keyRight)) == null ? void 0 : _b.linkWith.set(keyLeft, linker);
4872
+ }
4873
+ }
4874
+ }
4875
+ return new this(result);
4876
+ }
4877
+ /** Get all available nodes of linker graphs if start from sourceAxesKeys */
4878
+ searchAvailableAxesKeys(sourceAxesKeys) {
4879
+ const startKeys = new Set(sourceAxesKeys);
4880
+ const allAvailableKeys = /* @__PURE__ */ new Set();
4881
+ let nextKeys = sourceAxesKeys;
4882
+ while (nextKeys.length) {
4883
+ const next = [];
4884
+ for (const key of nextKeys) {
4885
+ const node = this.data.get(key);
4886
+ if (!node)
4887
+ continue;
4888
+ for (const availableKey of node.linkWith.keys()) {
4889
+ if (!allAvailableKeys.has(availableKey) && !startKeys.has(availableKey)) {
4890
+ next.push(availableKey);
4891
+ allAvailableKeys.add(availableKey);
4892
+ }
4893
+ }
4894
+ }
4895
+ nextKeys = next;
4896
+ }
4897
+ return allAvailableKeys;
4898
+ }
4899
+ /** Get all linker columns that are necessary to reach endKey from startKey */
4900
+ searchLinkerPath(startKey, endKey) {
4901
+ const previous = {};
4902
+ let nextIds = /* @__PURE__ */ new Set([startKey]);
4903
+ const visited = /* @__PURE__ */ new Set([startKey]);
4904
+ while (nextIds.size) {
4905
+ const next = /* @__PURE__ */ new Set();
4906
+ for (const nextId of nextIds) {
4907
+ const node = this.data.get(nextId);
4908
+ if (!node)
4909
+ continue;
4910
+ for (const availableId of node.linkWith.keys()) {
4911
+ previous[availableId] = nextId;
4912
+ if (availableId === endKey) {
4913
+ const ids = [];
4914
+ let current = endKey;
4915
+ while (previous[current] !== startKey) {
4916
+ ids.push(current);
4917
+ current = previous[current];
4918
+ }
4919
+ ids.push(current);
4920
+ return ids.map((id) => this.data.get(id).linkWith.get(previous[id]));
4921
+ } else if (!visited.has(availableId)) {
4922
+ next.add(availableId);
4923
+ visited.add(availableId);
4924
+ }
4925
+ }
4926
+ }
4927
+ nextIds = next;
4928
+ }
4929
+ return [];
4930
+ }
4931
+ getLinkerColumnsForAxes({ from: sourceAxes, to: targetAxes, throwWhenNoLinkExists = true }) {
4932
+ const startKeys = sourceAxes.map(LinkerMap.getLinkerKeyFromAxisSpec);
4933
+ return Array.from(new Map(LinkerMap.getAxesRoots(targetAxes).map(LinkerMap.getLinkerKeyFromAxisSpec).flatMap((targetKey) => {
4934
+ const linkers = startKeys.map((startKey) => this.searchLinkerPath(startKey, targetKey)).reduce((shortestPath, path) => shortestPath.length && shortestPath.length < path.length || !path.length ? shortestPath : path, []).map((linker) => [linker.columnId, linker]);
4935
+ if (!linkers.length && throwWhenNoLinkExists) {
4936
+ throw Error(`Unable to find linker column for ${targetKey}`);
4937
+ }
4938
+ return linkers;
4939
+ })).values());
4940
+ }
4941
+ /** Get list of axisSpecs from keys of linker columns map */
4942
+ getAxesListFromKeysList(keys) {
4943
+ return Array.from(new Map(keys.flatMap((key) => {
4944
+ var _a;
4945
+ return ((_a = this.data.get(key)) == null ? void 0 : _a.keyAxesSpec) ?? [];
4946
+ }).map((axis) => [canonicalizeJson(getAxisId(axis)), axis])).values());
4947
+ }
4948
+ /** Get axes of target axes that are impossible to be linked to source axes with current linker map */
4949
+ getNonLinkableAxes(sourceAxes, targetAxes) {
4950
+ const startKeys = sourceAxes.map(LinkerMap.getLinkerKeyFromAxisSpec);
4951
+ const targetKeys = targetAxes.map(LinkerMap.getLinkerKeyFromAxisSpec);
4952
+ const axes = Array.from(new Map(targetAxes.filter((_targetAxis, idx) => {
4953
+ const targetKey = targetKeys[idx];
4954
+ return !startKeys.some((startKey) => this.searchLinkerPath(startKey, targetKey).length);
4955
+ }).flatMap((axis) => getArrayFromAxisTree(getAxesTree(axis)).map((axis2) => [canonicalizeJson(getAxisId(axis2)), axis2]))).values());
4956
+ return axes;
4957
+ }
4958
+ /** Get all axes that can be connected to sourceAxes by linkers */
4959
+ getReachableByLinkersAxesFromAxes(sourceAxes) {
4960
+ const startKeys = sourceAxes.map(LinkerMap.getLinkerKeyFromAxisSpec);
4961
+ const availableKeys = this.searchAvailableAxesKeys(startKeys);
4962
+ return this.getAxesListFromKeysList([...availableKeys]);
4963
+ }
4964
+ static getLinkerKeyFromAxisSpec(axis) {
4965
+ return canonicalizeJson(getArrayFromAxisTree(getAxesTree(axis)).map(getAxisId));
4966
+ }
4967
+ /** Split array of axes into several arrays by parents: axes of one group are parents for each other.
4968
+ There are no order inside every group. */
4969
+ static getAxesGroups(axesSpec) {
4970
+ switch (axesSpec.length) {
4971
+ case 0:
4972
+ return [];
4973
+ case 1:
4974
+ return [[axesSpec[0]]];
4975
+ }
4976
+ const axisKeys = axesSpec.map((spec) => canonicalizeJson(getAxisId(spec)));
4977
+ const axisParentsIdxs = axesSpec.map((spec) => new Set(spec.parentAxesSpec.map((spec2) => canonicalizeJson(getAxisId(spec2))).map((el) => {
4978
+ const idx = axisKeys.indexOf(el);
4979
+ if (idx === -1) {
4980
+ throw new Error(`malformed axesSpec: ${JSON.stringify(axesSpec)}, unable to locate parent ${el}`);
4981
+ }
4982
+ return idx;
4983
+ })));
4984
+ const allIdxs = [...axesSpec.keys()];
4985
+ const groups = [];
4986
+ const usedIdxs = /* @__PURE__ */ new Set();
4987
+ let nextFreeEl = allIdxs.find((idx) => !usedIdxs.has(idx));
4988
+ while (nextFreeEl !== void 0) {
4989
+ const currentGroup = [nextFreeEl];
4990
+ usedIdxs.add(nextFreeEl);
4991
+ let nextElsOfCurrentGroup = [nextFreeEl];
4992
+ while (nextElsOfCurrentGroup.length) {
4993
+ const next = /* @__PURE__ */ new Set();
4994
+ for (const groupIdx of nextElsOfCurrentGroup) {
4995
+ const groupElementParents = axisParentsIdxs[groupIdx];
4996
+ allIdxs.forEach((idx) => {
4997
+ if (idx === groupIdx || usedIdxs.has(idx)) {
4998
+ return;
4999
+ }
5000
+ const parents = axisParentsIdxs[idx];
5001
+ if (parents.has(groupIdx) || groupElementParents.has(idx)) {
5002
+ currentGroup.push(idx);
5003
+ next.add(idx);
5004
+ usedIdxs.add(idx);
5005
+ }
5006
+ });
5007
+ }
5008
+ nextElsOfCurrentGroup = [...next];
5009
+ }
5010
+ groups.push([...currentGroup]);
5011
+ nextFreeEl = allIdxs.find((idx) => !usedIdxs.has(idx));
5012
+ }
5013
+ return groups.map((group) => group.map((idx) => axesSpec[idx]));
5014
+ }
5015
+ /** Get all axes that are not parents of any other axis */
5016
+ static getAxesRoots(axes) {
5017
+ const parentsSet = new Set(axes.flatMap((axis) => axis.parentAxesSpec).map((spec) => canonicalizeJson(getAxisId(spec))));
5018
+ return axes.filter((axis) => !parentsSet.has(canonicalizeJson(getAxisId(axis))));
5019
+ }
5020
+ }
5021
+ const PlIdLength = 24;
5022
+ z.string().length(PlIdLength).regex(/[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]/).brand("PlId");
5023
+ z.object({
5024
+ __isRef: z.literal(true).describe("Crucial marker for the block dependency tree reconstruction"),
5025
+ blockId: z.string().describe("Upstream block id"),
5026
+ name: z.string().describe("Name of the output provided to the upstream block's output context"),
5027
+ requireEnrichments: z.literal(true).optional().describe("True if current block that stores this reference in its args, may need enrichments for the references value originating from the blocks in between current and referenced block")
5028
+ }).describe("Universal reference type, allowing to set block connections. It is crucial that {@link __isRef} is present and equal to true, internal logic relies on this marker to build block dependency trees.").readonly();
5029
+ function isPlRef(value) {
5030
+ return typeof value === "object" && value !== null && "__isRef" in value && value.__isRef === true && "blockId" in value && "name" in value;
5031
+ }
5032
+ function withEnrichments(ref, requireEnrichments = true) {
5033
+ if (requireEnrichments)
5034
+ return {
5035
+ ...ref,
5036
+ requireEnrichments: true
5037
+ };
5038
+ else {
5039
+ const { requireEnrichments: _, ...rest } = ref;
5040
+ return rest;
5041
+ }
5042
+ }
5043
+ function mapValueInVOE(voe, cb) {
5044
+ return voe.ok ? { ok: true, value: cb(voe.value) } : voe;
5045
+ }
5046
+ class FutureRef {
5047
+ constructor(handle, postProcess = (v) => v) {
5048
+ __publicField(this, "handle");
5049
+ __publicField(this, "postProcess");
5050
+ __publicField(this, "isResolved", false);
5051
+ __publicField(this, "resolvedValue");
5052
+ this.handle = handle;
5053
+ this.postProcess = postProcess;
5054
+ registerFutureAwait(handle, (value) => {
5055
+ this.resolvedValue = postProcess(value);
5056
+ this.isResolved = true;
5057
+ });
5058
+ }
5059
+ map(mapping) {
5060
+ return new FutureRef(this.handle, (v) => mapping(this.postProcess(v)));
5061
+ }
5062
+ mapDefined(mapping) {
5063
+ return new FutureRef(this.handle, (v) => {
5064
+ const vv = this.postProcess(v);
5065
+ return vv ? mapping(vv) : void 0;
5066
+ });
4551
5067
  }
4552
5068
  toJSON() {
4553
5069
  return this.isResolved ? this.resolvedValue : { __awaited_futures__: [this.handle] };
4554
5070
  }
4555
5071
  }
4556
- function pe(t, e) {
4557
- return t === void 0 ? void 0 : e(t);
5072
+ function ifDef(value, cb) {
5073
+ return value === void 0 ? void 0 : cb(value);
4558
5074
  }
4559
- class I {
4560
- constructor(e, n2) {
4561
- this.handle = e, this.resolvePath = n2;
5075
+ class TreeNodeAccessor {
5076
+ constructor(handle, resolvePath) {
5077
+ __publicField(this, "handle");
5078
+ __publicField(this, "resolvePath");
5079
+ this.handle = handle;
5080
+ this.resolvePath = resolvePath;
4562
5081
  }
4563
- resolve(...e) {
4564
- const n2 = e.map(
4565
- (r) => ({
4566
- assertFieldType: "Input",
4567
- ...typeof r == "string" ? { field: r } : r
4568
- })
4569
- );
4570
- return this.resolveWithCommon({}, ...n2);
4571
- }
4572
- resolveOutput(...e) {
4573
- const n2 = e.map(
4574
- (r) => ({
4575
- assertFieldType: "Output",
4576
- ...typeof r == "string" ? { field: r } : r
4577
- })
4578
- );
4579
- return this.resolveWithCommon({}, ...n2);
4580
- }
4581
- resolveInput(...e) {
4582
- const n2 = e.map(
4583
- (r) => ({
4584
- assertFieldType: "Input",
4585
- ...typeof r == "string" ? { field: r } : r
4586
- })
4587
- );
4588
- return this.resolveWithCommon({}, ...n2);
5082
+ resolve(...steps) {
5083
+ const transformedSteps = steps.map((s) => ({
5084
+ assertFieldType: "Input",
5085
+ ...typeof s === "string" ? { field: s } : s
5086
+ }));
5087
+ return this.resolveWithCommon({}, ...transformedSteps);
4589
5088
  }
4590
- resolveAny(...e) {
4591
- return this.resolveWithCommon({}, ...e);
5089
+ resolveOutput(...steps) {
5090
+ const transformedSteps = steps.map((s) => ({
5091
+ assertFieldType: "Output",
5092
+ ...typeof s === "string" ? { field: s } : s
5093
+ }));
5094
+ return this.resolveWithCommon({}, ...transformedSteps);
4592
5095
  }
4593
- resolveWithCommon(e, ...n2) {
4594
- const r = [
5096
+ resolveInput(...steps) {
5097
+ const transformedSteps = steps.map((s) => ({
5098
+ assertFieldType: "Input",
5099
+ ...typeof s === "string" ? { field: s } : s
5100
+ }));
5101
+ return this.resolveWithCommon({}, ...transformedSteps);
5102
+ }
5103
+ resolveAny(...steps) {
5104
+ return this.resolveWithCommon({}, ...steps);
5105
+ }
5106
+ resolveWithCommon(commonOptions, ...steps) {
5107
+ const resolvePath = [
4595
5108
  ...this.resolvePath,
4596
- ...n2.map((i) => typeof i == "string" ? i : i.field)
5109
+ ...steps.map((step) => typeof step === "string" ? step : step.field)
4597
5110
  ];
4598
- return pe(
4599
- m().resolveWithCommon(this.handle, e, ...n2),
4600
- (i) => new I(i, r)
4601
- );
5111
+ return ifDef(getCfgRenderCtx().resolveWithCommon(this.handle, commonOptions, ...steps), (accessor) => new TreeNodeAccessor(accessor, resolvePath));
4602
5112
  }
4603
5113
  get resourceType() {
4604
- return m().getResourceType(this.handle);
5114
+ return getCfgRenderCtx().getResourceType(this.handle);
4605
5115
  }
4606
5116
  getInputsLocked() {
4607
- return m().getInputsLocked(this.handle);
5117
+ return getCfgRenderCtx().getInputsLocked(this.handle);
4608
5118
  }
4609
5119
  getOutputsLocked() {
4610
- return m().getOutputsLocked(this.handle);
5120
+ return getCfgRenderCtx().getOutputsLocked(this.handle);
4611
5121
  }
4612
5122
  getIsReadyOrError() {
4613
- return m().getIsReadyOrError(this.handle);
5123
+ return getCfgRenderCtx().getIsReadyOrError(this.handle);
4614
5124
  }
4615
5125
  getIsFinal() {
4616
- return m().getIsFinal(this.handle);
5126
+ return getCfgRenderCtx().getIsFinal(this.handle);
4617
5127
  }
4618
5128
  getError() {
4619
- const e = [...this.resolvePath, "error"];
4620
- return pe(
4621
- m().getError(this.handle),
4622
- (n2) => new I(n2, e)
4623
- );
5129
+ const resolvePath = [...this.resolvePath, "error"];
5130
+ return ifDef(getCfgRenderCtx().getError(this.handle), (accsessor) => new TreeNodeAccessor(accsessor, resolvePath));
4624
5131
  }
4625
5132
  listInputFields() {
4626
- return m().listInputFields(this.handle);
5133
+ return getCfgRenderCtx().listInputFields(this.handle);
4627
5134
  }
4628
5135
  listOutputFields() {
4629
- return m().listOutputFields(this.handle);
5136
+ return getCfgRenderCtx().listOutputFields(this.handle);
4630
5137
  }
4631
5138
  listDynamicFields() {
4632
- return m().listDynamicFields(this.handle);
5139
+ return getCfgRenderCtx().listDynamicFields(this.handle);
4633
5140
  }
4634
- getKeyValueBase64(e) {
4635
- return m().getKeyValueBase64(this.handle, e);
5141
+ getKeyValueBase64(key) {
5142
+ return getCfgRenderCtx().getKeyValueBase64(this.handle, key);
4636
5143
  }
4637
- getKeyValueAsString(e) {
4638
- return m().getKeyValueAsString(this.handle, e);
5144
+ getKeyValueAsString(key) {
5145
+ return getCfgRenderCtx().getKeyValueAsString(this.handle, key);
4639
5146
  }
4640
- getKeyValueAsJson(e) {
4641
- const n2 = this.getKeyValueAsString(e);
4642
- if (n2 == null) throw new Error("Resource has no content.");
4643
- return JSON.parse(n2);
5147
+ getKeyValueAsJson(key) {
5148
+ const content = this.getKeyValueAsString(key);
5149
+ if (content == void 0)
5150
+ throw new Error("Resource has no content.");
5151
+ return JSON.parse(content);
4644
5152
  }
4645
5153
  getDataBase64() {
4646
- return m().getDataBase64(this.handle);
5154
+ return getCfgRenderCtx().getDataBase64(this.handle);
4647
5155
  }
4648
5156
  getDataAsString() {
4649
- return m().getDataAsString(this.handle);
5157
+ return getCfgRenderCtx().getDataAsString(this.handle);
4650
5158
  }
4651
5159
  getDataAsJson() {
4652
- const e = this.getDataAsString();
4653
- if (e == null) throw new Error("Resource has no content.");
4654
- return JSON.parse(e);
5160
+ const content = this.getDataAsString();
5161
+ if (content == void 0)
5162
+ throw new Error("Resource has no content.");
5163
+ return JSON.parse(content);
4655
5164
  }
4656
5165
  /**
4657
5166
  *
4658
5167
  */
4659
- getPColumns(e = false, n2 = "") {
4660
- const r = this.parsePObjectCollection(e, n2);
4661
- return r === void 0 ? void 0 : Object.entries(r).map(([, s2]) => {
4662
- if (!q(s2)) throw new Error(`not a PColumn (kind = ${s2.spec.kind})`);
4663
- return s2;
5168
+ getPColumns(errorOnUnknownField = false, prefix = "") {
5169
+ const result = this.parsePObjectCollection(errorOnUnknownField, prefix);
5170
+ if (result === void 0)
5171
+ return void 0;
5172
+ const pf = Object.entries(result).map(([, obj]) => {
5173
+ if (!isPColumn(obj))
5174
+ throw new Error(`not a PColumn (kind = ${obj.spec.kind})`);
5175
+ return obj;
4664
5176
  });
5177
+ return pf;
4665
5178
  }
4666
5179
  /**
4667
5180
  *
4668
5181
  */
4669
- parsePObjectCollection(e = false, n2 = "") {
4670
- const r = m().parsePObjectCollection(
4671
- this.handle,
4672
- e,
4673
- n2,
4674
- ...this.resolvePath
4675
- );
4676
- if (r === void 0) return;
4677
- const i = {};
4678
- for (const [s2, o] of Object.entries(r)) {
4679
- const a = [...this.resolvePath, s2];
4680
- i[s2] = Fn(o, (l2) => new I(l2, a));
4681
- }
4682
- return i;
4683
- }
4684
- getFileContentAsBase64() {
4685
- return new S(m().getBlobContentAsBase64(this.handle));
4686
- }
4687
- getFileContentAsString() {
4688
- return new S(m().getBlobContentAsString(this.handle));
4689
- }
4690
- getFileContentAsJson() {
4691
- return new S(
4692
- m().getBlobContentAsString(this.handle)
4693
- ).mapDefined((e) => JSON.parse(e));
5182
+ parsePObjectCollection(errorOnUnknownField = false, prefix = "") {
5183
+ const pObjects = getCfgRenderCtx().parsePObjectCollection(this.handle, errorOnUnknownField, prefix, ...this.resolvePath);
5184
+ if (pObjects === void 0)
5185
+ return void 0;
5186
+ const result = {};
5187
+ for (const [key, value] of Object.entries(pObjects)) {
5188
+ const resolvePath = [...this.resolvePath, key];
5189
+ result[key] = mapPObjectData(value, (c) => new TreeNodeAccessor(c, resolvePath));
5190
+ }
5191
+ return result;
5192
+ }
5193
+ getFileContentAsBase64(range) {
5194
+ return new FutureRef(getCfgRenderCtx().getBlobContentAsBase64(this.handle, range));
5195
+ }
5196
+ getFileContentAsString(range) {
5197
+ return new FutureRef(getCfgRenderCtx().getBlobContentAsString(this.handle, range));
5198
+ }
5199
+ getFileContentAsJson(range) {
5200
+ return new FutureRef(getCfgRenderCtx().getBlobContentAsString(this.handle, range)).mapDefined((v) => JSON.parse(v));
4694
5201
  }
4695
5202
  /**
4696
5203
  * @deprecated use getFileContentAsBase64
@@ -4708,7 +5215,7 @@
4708
5215
  * @returns downloaded file handle
4709
5216
  */
4710
5217
  getFileHandle() {
4711
- return new S(m().getDownloadedBlobContentHandle(this.handle));
5218
+ return new FutureRef(getCfgRenderCtx().getDownloadedBlobContentHandle(this.handle));
4712
5219
  }
4713
5220
  /**
4714
5221
  * @deprecated use getFileHandle
@@ -4720,7 +5227,7 @@
4720
5227
  * @returns downloaded file handle
4721
5228
  */
4722
5229
  getRemoteFileHandle() {
4723
- return new S(m().getOnDemandBlobContentHandle(this.handle));
5230
+ return new FutureRef(getCfgRenderCtx().getOnDemandBlobContentHandle(this.handle));
4724
5231
  }
4725
5232
  /**
4726
5233
  * @deprecated use getRemoteFileHandle
@@ -4731,629 +5238,898 @@
4731
5238
  /**
4732
5239
  * @returns the url to the extracted folder
4733
5240
  */
4734
- extractArchiveAndGetURL(e) {
4735
- return new S(m().extractArchiveAndGetURL(this.handle, e));
5241
+ extractArchiveAndGetURL(format) {
5242
+ return new FutureRef(getCfgRenderCtx().extractArchiveAndGetURL(this.handle, format));
4736
5243
  }
4737
5244
  getImportProgress() {
4738
- return new S(m().getImportProgress(this.handle));
5245
+ return new FutureRef(getCfgRenderCtx().getImportProgress(this.handle));
4739
5246
  }
4740
- getLastLogs(e) {
4741
- return new S(m().getLastLogs(this.handle, e));
5247
+ getLastLogs(nLines) {
5248
+ return new FutureRef(getCfgRenderCtx().getLastLogs(this.handle, nLines));
4742
5249
  }
4743
- getProgressLog(e) {
4744
- return new S(m().getProgressLog(this.handle, e));
5250
+ getProgressLog(patternToSearch) {
5251
+ return new FutureRef(getCfgRenderCtx().getProgressLog(this.handle, patternToSearch));
4745
5252
  }
4746
- getProgressLogWithInfo(e) {
4747
- return new S(m().getProgressLogWithInfo(this.handle, e));
5253
+ getProgressLogWithInfo(patternToSearch) {
5254
+ return new FutureRef(getCfgRenderCtx().getProgressLogWithInfo(this.handle, patternToSearch));
4748
5255
  }
4749
5256
  getLogHandle() {
4750
- return new S(m().getLogHandle(this.handle));
5257
+ return new FutureRef(getCfgRenderCtx().getLogHandle(this.handle));
4751
5258
  }
4752
- allFieldsResolved(e = "Input") {
4753
- switch (e) {
5259
+ allFieldsResolved(fieldType = "Input") {
5260
+ switch (fieldType) {
4754
5261
  case "Input":
4755
- return this.getInputsLocked() && this.listInputFields().every(
4756
- (n2) => this.resolve({ field: n2, assertFieldType: "Input" }) !== void 0
4757
- );
5262
+ return this.getInputsLocked() && this.listInputFields().every((field) => this.resolve({ field, assertFieldType: "Input" }) !== void 0);
4758
5263
  case "Output":
4759
- return this.getOutputsLocked() && this.listOutputFields().every(
4760
- (n2) => this.resolve({ field: n2, assertFieldType: "Output" }) !== void 0
4761
- );
5264
+ return this.getOutputsLocked() && this.listOutputFields().every((field) => this.resolve({ field, assertFieldType: "Output" }) !== void 0);
4762
5265
  }
4763
5266
  }
4764
- mapFields(e, n2) {
4765
- const { fieldType: r, requireLocked: i, skipUnresolved: s2 } = {
5267
+ mapFields(_mapping, _ops) {
5268
+ const { fieldType, requireLocked, skipUnresolved } = {
4766
5269
  fieldType: "Input",
4767
5270
  requireLocked: true,
4768
5271
  skipUnresolved: false,
4769
- ...n2
4770
- }, o = e;
4771
- if (i && (r === "Input" && !this.getInputsLocked() || r === "Output" && !this.getOutputsLocked()))
4772
- return;
4773
- let l2 = (r === "Input" ? this.listInputFields() : r === "Output" ? this.listOutputFields() : this.listDynamicFields()).map(
4774
- (u2) => [u2, this.resolve({ field: u2, assertFieldType: r })]
4775
- );
4776
- return s2 && (l2 = l2.filter((u2) => u2[1] !== void 0)), l2.map(([u2, y]) => o(u2, y));
4777
- }
4778
- }
4779
- const Ee = "staging", Fe = "main";
4780
- const ut = "pl7.app/label", ct = "pl7.app/trace", pt = z$1.object({
4781
- type: z$1.string(),
4782
- importance: z$1.number().optional(),
4783
- id: z$1.string().optional(),
4784
- label: z$1.string()
4785
- }), dt = z$1.array(pt), ft = 1e-3, ht = "__LABEL__", Ae = "__LABEL__@1";
4786
- function Oe(t, e, n2 = {}) {
4787
- const r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s2 = t.map((f2) => {
4788
- var q2, F;
4789
- const h = e(f2);
4790
- let d, x2, c2;
4791
- "spec" in h && typeof h.spec == "object" ? (d = h.spec, x2 = h.prefixTrace, c2 = h.suffixTrace) : d = h;
4792
- const v = (q2 = d.annotations) == null ? void 0 : q2[ut], g = (F = d.annotations) == null ? void 0 : F[ct], b = (g ? dt.safeParse(JSON.parse(g)).data : void 0) ?? [], A2 = [
4793
- ...x2 ?? [],
4794
- ...b,
4795
- ...c2 ?? []
5272
+ ..._ops
5273
+ };
5274
+ const mapping = _mapping;
5275
+ if (requireLocked) {
5276
+ if (fieldType === "Input" && !this.getInputsLocked())
5277
+ return void 0;
5278
+ if (fieldType === "Output" && !this.getOutputsLocked())
5279
+ return void 0;
5280
+ }
5281
+ const fieldList = fieldType === "Input" ? this.listInputFields() : fieldType === "Output" ? this.listOutputFields() : this.listDynamicFields();
5282
+ let fieldEntries = fieldList.map((field) => [field, this.resolve({ field, assertFieldType: fieldType })]);
5283
+ if (skipUnresolved)
5284
+ fieldEntries = fieldEntries.filter((e) => e[1] !== void 0);
5285
+ return fieldEntries.map(([name, value]) => mapping(name, value));
5286
+ }
5287
+ }
5288
+ const StagingAccessorName = "staging";
5289
+ const MainAccessorName = "main";
5290
+ const TraceEntry = z.object({
5291
+ type: z.string(),
5292
+ importance: z.number().optional(),
5293
+ id: z.string().optional(),
5294
+ label: z.string()
5295
+ });
5296
+ const Trace = z.array(TraceEntry);
5297
+ const DistancePenalty = 1e-3;
5298
+ const LabelType = "__LABEL__";
5299
+ const LabelTypeFull = "__LABEL__@1";
5300
+ function deriveLabels(values, specExtractor, ops = {}) {
5301
+ const importances = /* @__PURE__ */ new Map();
5302
+ const forceTraceElements = ops.forceTraceElements !== void 0 && ops.forceTraceElements.length > 0 ? new Set(ops.forceTraceElements) : void 0;
5303
+ const numberOfRecordsWithType = /* @__PURE__ */ new Map();
5304
+ const enrichedRecords = values.map((value) => {
5305
+ const extractorResult = specExtractor(value);
5306
+ let spec;
5307
+ let prefixTrace;
5308
+ let suffixTrace;
5309
+ if ("spec" in extractorResult && typeof extractorResult.spec === "object") {
5310
+ spec = extractorResult.spec;
5311
+ prefixTrace = extractorResult.prefixTrace;
5312
+ suffixTrace = extractorResult.suffixTrace;
5313
+ } else {
5314
+ spec = extractorResult;
5315
+ }
5316
+ const label = readAnnotation(spec, Annotation.Label);
5317
+ const traceStr = readAnnotation(spec, Annotation.Trace);
5318
+ const baseTrace = (traceStr ? Trace.safeParse(parseJson(traceStr)).data : void 0) ?? [];
5319
+ const trace = [
5320
+ ...prefixTrace ?? [],
5321
+ ...baseTrace,
5322
+ ...suffixTrace ?? []
4796
5323
  ];
4797
- if (v) {
4798
- const _ = { label: v, type: ht, importance: -2 };
4799
- n2.addLabelAsSuffix ? A2.push(_) : A2.splice(0, 0, _);
4800
- }
4801
- const D = [], $2 = /* @__PURE__ */ new Map();
4802
- for (let _ = A2.length - 1; _ >= 0; --_) {
4803
- const { type: R } = A2[_], se = A2[_].importance ?? 0, J = ($2.get(R) ?? 0) + 1;
4804
- $2.set(R, J);
4805
- const P = `${R}@${J}`;
4806
- i.set(P, (i.get(P) ?? 0) + 1), r.set(
4807
- P,
4808
- Math.max(
4809
- r.get(P) ?? Number.NEGATIVE_INFINITY,
4810
- se - (A2.length - _) * ft
4811
- )
4812
- ), D.push({ ...A2[_], fullType: P, occurenceIndex: J });
4813
- }
4814
- return D.reverse(), {
4815
- value: f2,
4816
- spec: d,
4817
- label: v,
4818
- fullTrace: D
5324
+ if (label !== void 0) {
5325
+ const labelEntry = { label, type: LabelType, importance: -2 };
5326
+ if (ops.addLabelAsSuffix)
5327
+ trace.push(labelEntry);
5328
+ else
5329
+ trace.splice(0, 0, labelEntry);
5330
+ }
5331
+ const fullTrace = [];
5332
+ const occurrences = /* @__PURE__ */ new Map();
5333
+ for (let i = trace.length - 1; i >= 0; --i) {
5334
+ const { type: typeName } = trace[i];
5335
+ const importance = trace[i].importance ?? 0;
5336
+ const occurrenceIndex = (occurrences.get(typeName) ?? 0) + 1;
5337
+ occurrences.set(typeName, occurrenceIndex);
5338
+ const fullType = `${typeName}@${occurrenceIndex}`;
5339
+ numberOfRecordsWithType.set(fullType, (numberOfRecordsWithType.get(fullType) ?? 0) + 1);
5340
+ importances.set(fullType, Math.max(importances.get(fullType) ?? Number.NEGATIVE_INFINITY, importance - (trace.length - i) * DistancePenalty));
5341
+ fullTrace.push({ ...trace[i], fullType, occurrenceIndex });
5342
+ }
5343
+ fullTrace.reverse();
5344
+ return {
5345
+ value,
5346
+ spec,
5347
+ label,
5348
+ fullTrace
4819
5349
  };
4820
- }), o = [], a = [], l2 = [...r];
4821
- l2.sort(([, f2], [, h]) => h - f2);
4822
- for (const [f2] of l2)
4823
- f2.endsWith("@1") || i.get(f2) === t.length ? o.push(f2) : a.push(f2);
4824
- const u2 = (f2) => {
4825
- const h = [];
4826
- for (let d = 0; d < s2.length; d++) {
4827
- const x2 = s2[d], c2 = x2.fullTrace.filter((b) => f2.has(b.fullType));
4828
- if (c2.length === 0)
4829
- return;
4830
- const v = c2.map((b) => b.label), g = n2.separator ?? " / ";
4831
- h.push({
4832
- label: v.join(g),
4833
- value: x2.value
5350
+ });
5351
+ const mainTypes = [];
5352
+ const secondaryTypes = [];
5353
+ const allTypeRecords = [...importances];
5354
+ allTypeRecords.sort(([, i1], [, i2]) => i2 - i1);
5355
+ for (const [typeName] of allTypeRecords) {
5356
+ if (typeName.endsWith("@1") || numberOfRecordsWithType.get(typeName) === values.length)
5357
+ mainTypes.push(typeName);
5358
+ else
5359
+ secondaryTypes.push(typeName);
5360
+ }
5361
+ const calculate = (includedTypes2, force = false) => {
5362
+ const result = [];
5363
+ for (let i = 0; i < enrichedRecords.length; i++) {
5364
+ const r = enrichedRecords[i];
5365
+ const includedTrace = r.fullTrace.filter((fm) => includedTypes2.has(fm.fullType) || forceTraceElements && forceTraceElements.has(fm.type));
5366
+ if (includedTrace.length === 0) {
5367
+ if (force)
5368
+ result.push({
5369
+ label: "Unlabeled",
5370
+ value: r.value
5371
+ });
5372
+ else
5373
+ return void 0;
5374
+ }
5375
+ const labelSet = includedTrace.map((fm) => fm.label);
5376
+ const sep = ops.separator ?? " / ";
5377
+ result.push({
5378
+ label: labelSet.join(sep),
5379
+ value: r.value
4834
5380
  });
4835
5381
  }
4836
- return h;
5382
+ return result;
4837
5383
  };
4838
- if (o.length === 0) {
4839
- if (a.length !== 0) throw new Error("Assertion error.");
4840
- const f2 = u2(new Set(Ae));
4841
- if (f2 === void 0) throw new Error("Assertion error.");
4842
- return f2;
4843
- }
4844
- let y = 0, w2 = 0;
4845
- for (; y < o.length; ) {
4846
- const f2 = /* @__PURE__ */ new Set();
4847
- n2.includeNativeLabel && f2.add(Ae);
4848
- for (let d = 0; d < y; ++d) f2.add(o[d]);
4849
- f2.add(o[w2]);
4850
- const h = u2(f2);
4851
- if (h !== void 0 && new Set(h.map((d) => d.label)).size === t.length) return h;
4852
- w2++, w2 >= o.length && (y++, w2 = y);
4853
- }
4854
- const p2 = u2(/* @__PURE__ */ new Set([...o, ...a]));
4855
- if (p2 === void 0) throw new Error("Assertion error.");
4856
- return p2;
4857
- }
4858
- const H = "PColumnData/", ne = H + "ResourceMap", re = H + "Partitioned/ResourceMap", B = H + "JsonPartitioned", K = H + "BinaryPartitioned", Re = H + "Partitioned/", ie = Re + "JsonPartitioned", U = Re + "BinaryPartitioned";
4859
- const fe = (t) => {
4860
- if (t.endsWith(".index"))
4861
- return { baseKey: t.substring(0, t.length - 6), type: "index" };
4862
- if (t.endsWith(".values"))
4863
- return { baseKey: t.substring(0, t.length - 7), type: "values" };
4864
- throw new Error(`key must ends on .index/.values for binary p-column, got: ${t}`);
5384
+ if (mainTypes.length === 0) {
5385
+ if (secondaryTypes.length !== 0)
5386
+ throw new Error("Non-empty secondary types list while main types list is empty.");
5387
+ return calculate(new Set(LabelTypeFull), true);
5388
+ }
5389
+ let includedTypes = 0;
5390
+ let additionalType = -1;
5391
+ while (includedTypes < mainTypes.length) {
5392
+ const currentSet = /* @__PURE__ */ new Set();
5393
+ if (ops.includeNativeLabel)
5394
+ currentSet.add(LabelTypeFull);
5395
+ for (let i = 0; i < includedTypes; ++i)
5396
+ currentSet.add(mainTypes[i]);
5397
+ if (additionalType >= 0)
5398
+ currentSet.add(mainTypes[additionalType]);
5399
+ const candidateResult = calculate(currentSet);
5400
+ if (candidateResult !== void 0 && new Set(candidateResult.map((c) => c.label)).size === values.length)
5401
+ return candidateResult;
5402
+ additionalType++;
5403
+ if (additionalType >= mainTypes.length) {
5404
+ includedTypes++;
5405
+ additionalType = includedTypes;
5406
+ }
5407
+ }
5408
+ return calculate(/* @__PURE__ */ new Set([...mainTypes, ...secondaryTypes]), true);
5409
+ }
5410
+ const PCD_PREFIX = "PColumnData/";
5411
+ const RT_RESOURCE_MAP = PCD_PREFIX + "ResourceMap";
5412
+ const RT_RESOURCE_MAP_PARTITIONED = PCD_PREFIX + "Partitioned/ResourceMap";
5413
+ const RT_JSON_PARTITIONED = PCD_PREFIX + "JsonPartitioned";
5414
+ const RT_BINARY_PARTITIONED = PCD_PREFIX + "BinaryPartitioned";
5415
+ const PCD_SUP_PREFIX = PCD_PREFIX + "Partitioned/";
5416
+ const RT_JSON_SUPER_PARTITIONED = PCD_SUP_PREFIX + "JsonPartitioned";
5417
+ const RT_BINARY_SUPER_PARTITIONED = PCD_SUP_PREFIX + "BinaryPartitioned";
5418
+ const removeIndexSuffix = (keyStr) => {
5419
+ if (keyStr.endsWith(".index")) {
5420
+ return { baseKey: keyStr.substring(0, keyStr.length - 6), type: "index" };
5421
+ } else if (keyStr.endsWith(".values")) {
5422
+ return { baseKey: keyStr.substring(0, keyStr.length - 7), type: "values" };
5423
+ } else {
5424
+ throw new Error(`key must ends on .index/.values for binary p-column, got: ${keyStr}`);
5425
+ }
4865
5426
  };
4866
- function gt(t) {
4867
- if (!t) return;
4868
- const e = t.resourceType.name, n2 = t.getDataAsJson(), r = [];
4869
- let i = 0;
4870
- switch (e) {
4871
- case ne:
4872
- i = n2.keyLength;
5427
+ function getPartitionKeysList(acc) {
5428
+ if (!acc)
5429
+ return void 0;
5430
+ const rt = acc.resourceType.name;
5431
+ const meta = acc.getDataAsJson();
5432
+ const data = [];
5433
+ let keyLength = 0;
5434
+ switch (rt) {
5435
+ case RT_RESOURCE_MAP:
5436
+ keyLength = meta["keyLength"];
4873
5437
  break;
4874
- case re:
4875
- i = n2.partitionKeyLength + n2.keyLength;
5438
+ case RT_RESOURCE_MAP_PARTITIONED:
5439
+ keyLength = meta["partitionKeyLength"] + meta["keyLength"];
4876
5440
  break;
4877
- case B:
4878
- case K:
4879
- i = n2.partitionKeyLength;
5441
+ case RT_JSON_PARTITIONED:
5442
+ case RT_BINARY_PARTITIONED:
5443
+ keyLength = meta["partitionKeyLength"];
4880
5444
  break;
4881
- case U:
4882
- case ie:
4883
- i = n2.superPartitionKeyLength + n2.partitionKeyLength;
5445
+ case RT_BINARY_SUPER_PARTITIONED:
5446
+ case RT_JSON_SUPER_PARTITIONED:
5447
+ keyLength = meta["superPartitionKeyLength"] + meta["partitionKeyLength"];
4884
5448
  break;
4885
5449
  }
4886
- switch (e) {
4887
- case ne:
4888
- case B:
4889
- case K:
4890
- for (let s2 of t.listInputFields()) {
4891
- e === K && (s2 = fe(s2).baseKey);
4892
- const o = [...JSON.parse(s2)];
4893
- r.push(o);
5450
+ switch (rt) {
5451
+ case RT_RESOURCE_MAP:
5452
+ case RT_JSON_PARTITIONED:
5453
+ case RT_BINARY_PARTITIONED:
5454
+ for (let keyStr of acc.listInputFields()) {
5455
+ if (rt === RT_BINARY_PARTITIONED) {
5456
+ keyStr = removeIndexSuffix(keyStr).baseKey;
5457
+ }
5458
+ const key = [...JSON.parse(keyStr)];
5459
+ data.push(key);
4894
5460
  }
4895
5461
  break;
4896
- case re:
4897
- case U:
4898
- case ie:
4899
- for (const s2 of t.listInputFields()) {
4900
- const o = [...JSON.parse(s2)], a = t.resolve({ field: s2, assertFieldType: "Input" });
4901
- if (a !== void 0)
4902
- for (let l2 of a.listInputFields()) {
4903
- e === U && (l2 = fe(l2).baseKey);
4904
- const u2 = [...o, ...JSON.parse(l2)];
4905
- r.push(u2);
5462
+ case RT_RESOURCE_MAP_PARTITIONED:
5463
+ case RT_BINARY_SUPER_PARTITIONED:
5464
+ case RT_JSON_SUPER_PARTITIONED:
5465
+ for (const supKeyStr of acc.listInputFields()) {
5466
+ const keyPrefix = [...JSON.parse(supKeyStr)];
5467
+ const value = acc.resolve({ field: supKeyStr, assertFieldType: "Input" });
5468
+ if (value !== void 0) {
5469
+ for (let keyStr of value.listInputFields()) {
5470
+ if (rt === RT_BINARY_SUPER_PARTITIONED) {
5471
+ keyStr = removeIndexSuffix(keyStr).baseKey;
5472
+ }
5473
+ const key = [...keyPrefix, ...JSON.parse(keyStr)];
5474
+ data.push(key);
4906
5475
  }
5476
+ }
4907
5477
  }
4908
5478
  break;
4909
5479
  }
4910
- return { data: r, keyLength: i };
4911
- }
4912
- function mt(t) {
4913
- if (t.type !== "JsonPartitioned" && t.type !== "BinaryPartitioned")
4914
- throw new Error(`Splitting requires Partitioned DataInfoEntries, got ${t.type}`);
4915
- const { parts: e, partitionKeyLength: n2 } = t, r = [];
4916
- for (let i = 0; i < n2; ++i)
4917
- r.push(/* @__PURE__ */ new Set());
4918
- for (const i of e) {
4919
- const s2 = i.key;
4920
- if (s2.length !== n2)
4921
- throw new Error(
4922
- `Key length (${s2.length}) does not match partition length (${n2}) for key: ${JSON.stringify(
4923
- s2
4924
- )}`
4925
- );
4926
- for (let o = 0; o < n2; ++o)
4927
- r[o].add(s2[o]);
4928
- }
4929
- return r.map((i) => Array.from(i.values()));
4930
- }
4931
- function yt(t) {
4932
- if (t === void 0) return;
4933
- if (j(t))
4934
- return mt(t);
4935
- const e = gt(t);
4936
- if (!e) return;
4937
- const { data: n2, keyLength: r } = e, i = [];
4938
- for (let s2 = 0; s2 < r; ++s2)
4939
- i.push(/* @__PURE__ */ new Set());
4940
- for (const s2 of n2) {
4941
- if (s2.length !== r)
5480
+ return { data, keyLength };
5481
+ }
5482
+ function getUniquePartitionKeysForDataEntries(list) {
5483
+ if (list.type !== "JsonPartitioned" && list.type !== "BinaryPartitioned")
5484
+ throw new Error(`Splitting requires Partitioned DataInfoEntries, got ${list.type}`);
5485
+ const { parts, partitionKeyLength } = list;
5486
+ const result = [];
5487
+ for (let i = 0; i < partitionKeyLength; ++i) {
5488
+ result.push(/* @__PURE__ */ new Set());
5489
+ }
5490
+ for (const part of parts) {
5491
+ const key = part.key;
5492
+ if (key.length !== partitionKeyLength) {
5493
+ throw new Error(`Key length (${key.length}) does not match partition length (${partitionKeyLength}) for key: ${JSON.stringify(key)}`);
5494
+ }
5495
+ for (let i = 0; i < partitionKeyLength; ++i) {
5496
+ result[i].add(key[i]);
5497
+ }
5498
+ }
5499
+ return result.map((s) => Array.from(s.values()));
5500
+ }
5501
+ function getUniquePartitionKeys(acc) {
5502
+ if (acc === void 0)
5503
+ return void 0;
5504
+ if (isDataInfoEntries(acc))
5505
+ return getUniquePartitionKeysForDataEntries(acc);
5506
+ const list = getPartitionKeysList(acc);
5507
+ if (!list)
5508
+ return void 0;
5509
+ const { data, keyLength } = list;
5510
+ const result = [];
5511
+ for (let i = 0; i < keyLength; ++i) {
5512
+ result.push(/* @__PURE__ */ new Set());
5513
+ }
5514
+ for (const l of data) {
5515
+ if (l.length !== keyLength) {
4942
5516
  throw new Error("key length does not match partition length");
4943
- for (let o = 0; o < r; ++o)
4944
- i[o].add(s2[o]);
4945
- }
4946
- return i.map((s2) => Array.from(s2.values()));
4947
- }
4948
- function he(t, e = []) {
4949
- if (t === void 0 || !t.getIsReadyOrError()) return;
4950
- const n2 = t.resourceType.name, r = t.getDataAsJson();
4951
- if (e.length > 0 && (n2 === ie || n2 === U))
4952
- throw new Error(`Unexpected nested super-partitioned resource: ${n2}`);
4953
- switch (n2) {
4954
- case ne:
4955
- case re:
4956
- throw new Error(`Only data columns are supported, got: ${n2}`);
4957
- case B: {
4958
- if (typeof (r == null ? void 0 : r.partitionKeyLength) != "number")
4959
- throw new Error(`Missing partitionKeyLength in metadata for ${n2}`);
4960
- const i = [];
4961
- for (const s2 of t.listInputFields()) {
4962
- const o = t.resolve({ field: s2, assertFieldType: "Input" });
4963
- if (o === void 0) return;
4964
- const a = [...e, ...JSON.parse(s2)];
4965
- i.push({ key: a, value: o });
5517
+ }
5518
+ for (let i = 0; i < keyLength; ++i) {
5519
+ result[i].add(l[i]);
5520
+ }
5521
+ }
5522
+ return result.map((s) => Array.from(s.values()));
5523
+ }
5524
+ function parsePColumnData(acc, keyPrefix = []) {
5525
+ if (acc === void 0)
5526
+ return void 0;
5527
+ if (!acc.getIsReadyOrError())
5528
+ return void 0;
5529
+ const resourceType = acc.resourceType.name;
5530
+ const meta = acc.getDataAsJson();
5531
+ if (keyPrefix.length > 0 && (resourceType === RT_JSON_SUPER_PARTITIONED || resourceType === RT_BINARY_SUPER_PARTITIONED)) {
5532
+ throw new Error(`Unexpected nested super-partitioned resource: ${resourceType}`);
5533
+ }
5534
+ switch (resourceType) {
5535
+ case RT_RESOURCE_MAP:
5536
+ case RT_RESOURCE_MAP_PARTITIONED:
5537
+ throw new Error(`Only data columns are supported, got: ${resourceType}`);
5538
+ case RT_JSON_PARTITIONED: {
5539
+ if (typeof (meta == null ? void 0 : meta.partitionKeyLength) !== "number") {
5540
+ throw new Error(`Missing partitionKeyLength in metadata for ${resourceType}`);
5541
+ }
5542
+ const parts = [];
5543
+ for (const keyStr of acc.listInputFields()) {
5544
+ const value = acc.resolve({ field: keyStr, assertFieldType: "Input" });
5545
+ if (value === void 0)
5546
+ return void 0;
5547
+ const key = [...keyPrefix, ...JSON.parse(keyStr)];
5548
+ parts.push({ key, value });
4966
5549
  }
4967
5550
  return {
4968
5551
  type: "JsonPartitioned",
4969
- partitionKeyLength: r.partitionKeyLength,
4970
- parts: i
5552
+ partitionKeyLength: meta.partitionKeyLength,
5553
+ parts
4971
5554
  };
4972
5555
  }
4973
- case K: {
4974
- if (typeof (r == null ? void 0 : r.partitionKeyLength) != "number")
4975
- throw new Error(`Missing partitionKeyLength in metadata for ${n2}`);
4976
- const i = [], s2 = /* @__PURE__ */ new Map();
4977
- for (const o of t.listInputFields()) {
4978
- const a = fe(o), l2 = t.resolve({ field: o, assertFieldType: "Input" });
4979
- if (l2 === void 0) return;
4980
- let u2 = s2.get(a.baseKey);
4981
- u2 || (u2 = {}, s2.set(a.baseKey, u2)), a.type === "index" ? u2.index = l2 : u2.values = l2;
5556
+ case RT_BINARY_PARTITIONED: {
5557
+ if (typeof (meta == null ? void 0 : meta.partitionKeyLength) !== "number") {
5558
+ throw new Error(`Missing partitionKeyLength in metadata for ${resourceType}`);
5559
+ }
5560
+ const parts = [];
5561
+ const baseKeys = /* @__PURE__ */ new Map();
5562
+ for (const keyStr of acc.listInputFields()) {
5563
+ const suffix = removeIndexSuffix(keyStr);
5564
+ const value = acc.resolve({ field: keyStr, assertFieldType: "Input" });
5565
+ if (value === void 0)
5566
+ return void 0;
5567
+ let entry = baseKeys.get(suffix.baseKey);
5568
+ if (!entry) {
5569
+ entry = {};
5570
+ baseKeys.set(suffix.baseKey, entry);
5571
+ }
5572
+ if (suffix.type === "index") {
5573
+ entry.index = value;
5574
+ } else {
5575
+ entry.values = value;
5576
+ }
4982
5577
  }
4983
- for (const [o, a] of s2.entries()) {
4984
- if (!a.index || !a.values) return;
4985
- const l2 = [...e, ...JSON.parse(o)];
4986
- i.push({
4987
- key: l2,
5578
+ for (const [baseKeyStr, entry] of baseKeys.entries()) {
5579
+ if (!entry.index || !entry.values)
5580
+ return void 0;
5581
+ const key = [...keyPrefix, ...JSON.parse(baseKeyStr)];
5582
+ parts.push({
5583
+ key,
4988
5584
  value: {
4989
- index: a.index,
4990
- values: a.values
5585
+ index: entry.index,
5586
+ values: entry.values
4991
5587
  }
4992
5588
  });
4993
5589
  }
4994
5590
  return {
4995
5591
  type: "BinaryPartitioned",
4996
- partitionKeyLength: r.partitionKeyLength,
4997
- parts: i
5592
+ partitionKeyLength: meta.partitionKeyLength,
5593
+ parts
4998
5594
  };
4999
5595
  }
5000
- case ie: {
5001
- if (typeof (r == null ? void 0 : r.superPartitionKeyLength) != "number" || typeof (r == null ? void 0 : r.partitionKeyLength) != "number")
5002
- throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${n2}`);
5003
- const i = r.superPartitionKeyLength + r.partitionKeyLength, s2 = [];
5004
- for (const o of t.listInputFields()) {
5005
- const a = t.resolve({ field: o, assertFieldType: "Input" });
5006
- if (a === void 0) return;
5007
- if (a.resourceType.name !== B)
5008
- throw new Error(`Expected ${B} inside ${n2}, but got ${a.resourceType.name}`);
5009
- const l2 = he(a, JSON.parse(o));
5010
- if (l2 === void 0) return;
5011
- if (l2.type !== "JsonPartitioned")
5012
- throw new Error(`Unexpected inner result type for ${n2}: ${l2.type}`);
5013
- s2.push(...l2.parts);
5596
+ case RT_JSON_SUPER_PARTITIONED: {
5597
+ if (typeof (meta == null ? void 0 : meta.superPartitionKeyLength) !== "number" || typeof (meta == null ? void 0 : meta.partitionKeyLength) !== "number") {
5598
+ throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${resourceType}`);
5599
+ }
5600
+ const totalKeyLength = meta.superPartitionKeyLength + meta.partitionKeyLength;
5601
+ const parts = [];
5602
+ for (const supKeyStr of acc.listInputFields()) {
5603
+ const superPartition = acc.resolve({ field: supKeyStr, assertFieldType: "Input" });
5604
+ if (superPartition === void 0)
5605
+ return void 0;
5606
+ if (superPartition.resourceType.name !== RT_JSON_PARTITIONED) {
5607
+ throw new Error(`Expected ${RT_JSON_PARTITIONED} inside ${resourceType}, but got ${superPartition.resourceType.name}`);
5608
+ }
5609
+ const innerResult = parsePColumnData(superPartition, JSON.parse(supKeyStr));
5610
+ if (innerResult === void 0)
5611
+ return void 0;
5612
+ if (innerResult.type !== "JsonPartitioned")
5613
+ throw new Error(`Unexpected inner result type for ${resourceType}: ${innerResult.type}`);
5614
+ parts.push(...innerResult.parts);
5014
5615
  }
5015
5616
  return {
5016
5617
  type: "JsonPartitioned",
5017
- partitionKeyLength: i,
5018
- parts: s2
5618
+ partitionKeyLength: totalKeyLength,
5619
+ parts
5019
5620
  };
5020
5621
  }
5021
- case U: {
5022
- if (typeof (r == null ? void 0 : r.superPartitionKeyLength) != "number" || typeof (r == null ? void 0 : r.partitionKeyLength) != "number")
5023
- throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${n2}`);
5024
- const i = r.superPartitionKeyLength + r.partitionKeyLength, s2 = [];
5025
- for (const o of t.listInputFields()) {
5026
- const a = t.resolve({ field: o, assertFieldType: "Input" });
5027
- if (a === void 0) return;
5028
- if (a.resourceType.name !== K)
5029
- throw new Error(`Expected ${K} inside ${n2}, but got ${a.resourceType.name}`);
5030
- const l2 = he(a, JSON.parse(o));
5031
- if (l2 === void 0) return;
5032
- if (l2.type !== "BinaryPartitioned")
5033
- throw new Error(`Unexpected inner result type for ${n2}: ${l2.type}`);
5034
- s2.push(...l2.parts);
5622
+ case RT_BINARY_SUPER_PARTITIONED: {
5623
+ if (typeof (meta == null ? void 0 : meta.superPartitionKeyLength) !== "number" || typeof (meta == null ? void 0 : meta.partitionKeyLength) !== "number") {
5624
+ throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${resourceType}`);
5625
+ }
5626
+ const totalKeyLength = meta.superPartitionKeyLength + meta.partitionKeyLength;
5627
+ const parts = [];
5628
+ for (const supKeyStr of acc.listInputFields()) {
5629
+ const superPartition = acc.resolve({ field: supKeyStr, assertFieldType: "Input" });
5630
+ if (superPartition === void 0)
5631
+ return void 0;
5632
+ if (superPartition.resourceType.name !== RT_BINARY_PARTITIONED) {
5633
+ throw new Error(`Expected ${RT_BINARY_PARTITIONED} inside ${resourceType}, but got ${superPartition.resourceType.name}`);
5634
+ }
5635
+ const innerResult = parsePColumnData(superPartition, JSON.parse(supKeyStr));
5636
+ if (innerResult === void 0)
5637
+ return void 0;
5638
+ if (innerResult.type !== "BinaryPartitioned")
5639
+ throw new Error(`Unexpected inner result type for ${resourceType}: ${innerResult.type}`);
5640
+ parts.push(...innerResult.parts);
5035
5641
  }
5036
5642
  return {
5037
5643
  type: "BinaryPartitioned",
5038
- partitionKeyLength: i,
5039
- parts: s2
5644
+ partitionKeyLength: totalKeyLength,
5645
+ parts
5040
5646
  };
5041
5647
  }
5042
5648
  default:
5043
- throw new Error(`Unknown resource type: ${n2}`);
5044
- }
5045
- }
5046
- function vt(t) {
5047
- if (t !== void 0) {
5048
- if (j(t)) return t;
5049
- if (mn(t)) return hn(t);
5050
- if (t instanceof I) return he(t);
5051
- throw new Error(`Unexpected input type: ${typeof t}`);
5052
- }
5053
- }
5054
- function bt(t, e) {
5055
- const n2 = [...e].sort((s2, o) => o[0] - s2[0]);
5056
- if (t.type === "JsonPartitioned" || t.type === "BinaryPartitioned") {
5057
- const { partitionKeyLength: s2 } = t;
5058
- for (const [o] of e)
5059
- if (o >= s2)
5060
- throw new Error(`Can't filter on non-partitioned axis ${o}. Must be >= ${s2}`);
5061
- } else if (t.type === "Json") {
5062
- const { keyLength: s2 } = t;
5063
- for (const [o] of e)
5064
- if (o >= s2)
5065
- throw new Error(`Can't filter on non-data axis ${o}. Must be >= ${s2}`);
5066
- }
5067
- const r = (s2) => {
5068
- for (const [o, a] of n2)
5069
- if (s2[o] !== a)
5649
+ throw new Error(`Unknown resource type: ${resourceType}`);
5650
+ }
5651
+ }
5652
+ function convertOrParsePColumnData(acc) {
5653
+ if (acc === void 0)
5654
+ return void 0;
5655
+ if (isDataInfoEntries(acc))
5656
+ return acc;
5657
+ if (isDataInfo(acc))
5658
+ return dataInfoToEntries(acc);
5659
+ if (acc instanceof TreeNodeAccessor)
5660
+ return parsePColumnData(acc);
5661
+ throw new Error(`Unexpected input type: ${typeof acc}`);
5662
+ }
5663
+ function filterDataInfoEntries(dataInfoEntries, axisFilters) {
5664
+ const sortedFilters = [...axisFilters].sort((a, b) => b[0] - a[0]);
5665
+ const { type } = dataInfoEntries;
5666
+ switch (type) {
5667
+ case "Json": {
5668
+ const { keyLength } = dataInfoEntries;
5669
+ for (const [axisIdx] of axisFilters)
5670
+ if (axisIdx >= keyLength)
5671
+ throw new Error(`Can't filter on non-data axis ${axisIdx}. Must be >= ${keyLength}`);
5672
+ break;
5673
+ }
5674
+ case "JsonPartitioned":
5675
+ case "BinaryPartitioned":
5676
+ case "ParquetPartitioned": {
5677
+ const { partitionKeyLength } = dataInfoEntries;
5678
+ for (const [axisIdx] of axisFilters)
5679
+ if (axisIdx >= partitionKeyLength)
5680
+ throw new Error(`Can't filter on non-partitioned axis ${axisIdx}. Must be >= ${partitionKeyLength}`);
5681
+ break;
5682
+ }
5683
+ default:
5684
+ throw new Error(`Unsupported data info type: ${type}`);
5685
+ }
5686
+ const keyMatchesFilters = (key) => {
5687
+ for (const [axisIdx, axisValue] of sortedFilters)
5688
+ if (key[axisIdx] !== axisValue)
5070
5689
  return false;
5071
5690
  return true;
5072
- }, i = (s2) => {
5073
- const o = [...s2];
5074
- for (const [a] of n2)
5075
- o.splice(a, 1);
5076
- return o;
5077
5691
  };
5078
- switch (t.type) {
5079
- case "Json": {
5080
- const s2 = t.data.filter((o) => r(o.key)).map((o) => ({
5081
- key: i(o.key),
5082
- value: o.value
5083
- }));
5692
+ const removeFilteredAxes = (key) => {
5693
+ const newKey = [...key];
5694
+ for (const [axisIdx] of sortedFilters)
5695
+ newKey.splice(axisIdx, 1);
5696
+ return newKey;
5697
+ };
5698
+ switch (dataInfoEntries.type) {
5699
+ case "Json":
5084
5700
  return {
5085
5701
  type: "Json",
5086
- keyLength: t.keyLength - e.length,
5087
- data: s2
5702
+ keyLength: dataInfoEntries.keyLength - axisFilters.length,
5703
+ data: dataInfoEntries.data.filter((entry) => keyMatchesFilters(entry.key)).map((entry) => ({
5704
+ key: removeFilteredAxes(entry.key),
5705
+ value: entry.value
5706
+ }))
5088
5707
  };
5089
- }
5090
- case "JsonPartitioned": {
5091
- const s2 = t.parts.filter((o) => r(o.key)).map((o) => ({
5092
- key: i(o.key),
5093
- value: o.value
5094
- }));
5708
+ case "JsonPartitioned":
5095
5709
  return {
5096
5710
  type: "JsonPartitioned",
5097
- partitionKeyLength: t.partitionKeyLength - e.length,
5098
- parts: s2
5711
+ partitionKeyLength: dataInfoEntries.partitionKeyLength - axisFilters.length,
5712
+ parts: dataInfoEntries.parts.filter((entry) => keyMatchesFilters(entry.key)).map((entry) => ({
5713
+ key: removeFilteredAxes(entry.key),
5714
+ value: entry.value
5715
+ }))
5099
5716
  };
5100
- }
5101
- case "BinaryPartitioned": {
5102
- const s2 = t.parts.filter((o) => r(o.key)).map((o) => ({
5103
- key: i(o.key),
5104
- value: o.value
5105
- }));
5717
+ case "BinaryPartitioned":
5106
5718
  return {
5107
5719
  type: "BinaryPartitioned",
5108
- partitionKeyLength: t.partitionKeyLength - e.length,
5109
- parts: s2
5720
+ partitionKeyLength: dataInfoEntries.partitionKeyLength - axisFilters.length,
5721
+ parts: dataInfoEntries.parts.filter((entry) => keyMatchesFilters(entry.key)).map((entry) => ({
5722
+ key: removeFilteredAxes(entry.key),
5723
+ value: entry.value
5724
+ }))
5725
+ };
5726
+ case "ParquetPartitioned":
5727
+ return {
5728
+ type: "ParquetPartitioned",
5729
+ partitionKeyLength: dataInfoEntries.partitionKeyLength - axisFilters.length,
5730
+ parts: dataInfoEntries.parts.filter((entry) => keyMatchesFilters(entry.key)).map((entry) => ({
5731
+ key: removeFilteredAxes(entry.key),
5732
+ value: entry.value
5733
+ }))
5110
5734
  };
5111
- }
5112
5735
  }
5113
5736
  }
5114
- class wt {
5115
- constructor(e) {
5116
- this.columns = e;
5737
+ function isPColumnValues(value) {
5738
+ if (!Array.isArray(value))
5739
+ return false;
5740
+ if (value.length === 0)
5741
+ return true;
5742
+ const first = value[0];
5743
+ return typeof first === "object" && first !== null && "key" in first && "val" in first;
5744
+ }
5745
+ class ArrayColumnProvider {
5746
+ constructor(columns) {
5747
+ __publicField(this, "columns");
5748
+ this.columns = columns;
5117
5749
  }
5118
- selectColumns(e) {
5119
- const n2 = typeof e == "function" ? e : Kn(e);
5120
- return this.columns.filter((r) => n2(r.spec));
5750
+ selectColumns(selectors) {
5751
+ const predicate = typeof selectors === "function" ? selectors : selectorsToPredicate(selectors);
5752
+ return this.columns.filter((column) => predicate(column.spec));
5121
5753
  }
5122
5754
  }
5123
- function At(t) {
5124
- if (t)
5125
- return t.map((e) => ({
5126
- type: `split:${Jn(e.axisId)}`,
5127
- label: e.label,
5128
- importance: 1e6
5129
- // High importance for split filters in labels
5130
- }));
5131
- }
5132
- function Pt(t) {
5133
- if (t)
5134
- return t.map((e) => [e.axisIdx, e.value]);
5755
+ function splitFiltersToTrace(splitFilters) {
5756
+ if (!splitFilters)
5757
+ return void 0;
5758
+ return splitFilters.map((filter) => ({
5759
+ type: `split:${canonicalizeAxisId(filter.axisId)}`,
5760
+ label: filter.label,
5761
+ importance: 1e6
5762
+ // High importance for split filters in labels
5763
+ }));
5764
+ }
5765
+ function splitFiltersToAxisFilter(splitFilters) {
5766
+ if (!splitFilters)
5767
+ return void 0;
5768
+ return splitFilters.map((filter) => [filter.axisIdx, filter.value]);
5135
5769
  }
5136
- function xt(t, e) {
5137
- if (!e || e.length === 0) return t;
5138
- const n2 = [...e].sort((r, i) => r[0] - i[0]);
5139
- return _e({ id: t, axisFilters: n2 });
5770
+ function fallbackIdDeriver(originalId, axisFilters) {
5771
+ if (!axisFilters || axisFilters.length === 0)
5772
+ return originalId;
5773
+ const filtersToCanonicalize = [...axisFilters].sort((a, b) => a[0] - b[0]);
5774
+ return canonicalize({ id: originalId, axisFilters: filtersToCanonicalize });
5140
5775
  }
5141
- function Ct(t) {
5142
- if (!t || typeof t != "object") return false;
5143
- const e = t, n2 = e.domain && typeof e.domain == "object" && Object.values(e.domain).some((i) => typeof i == "object" && i !== null && "anchor" in i), r = e.axes && Array.isArray(e.axes) && e.axes.some((i) => typeof i == "object" && i !== null && "anchor" in i);
5144
- return !!e.domainAnchor || n2 || r;
5776
+ function hasAnchors(selector) {
5777
+ if (!selector || typeof selector !== "object")
5778
+ return false;
5779
+ const potentialAnchored = selector;
5780
+ const domainHasAnchors = potentialAnchored["domain"] && typeof potentialAnchored["domain"] === "object" && Object.values(potentialAnchored["domain"]).some((v) => typeof v === "object" && v !== null && "anchor" in v);
5781
+ const axesHaveAnchors = potentialAnchored["axes"] && Array.isArray(potentialAnchored["axes"]) && potentialAnchored["axes"].some((a) => typeof a === "object" && a !== null && "anchor" in a);
5782
+ return !!potentialAnchored["domainAnchor"] || domainHasAnchors || axesHaveAnchors;
5145
5783
  }
5146
- function St(t) {
5147
- if (typeof t != "object" || !("axes" in t) || t.axes === void 0)
5784
+ function getSplitAxisIndices(selector) {
5785
+ if (typeof selector !== "object" || !("axes" in selector) || selector.axes === void 0) {
5148
5786
  return [];
5149
- const e = t.axes.map((n2, r) => typeof n2 == "object" && "split" in n2 && n2.split === true ? r : -1).filter((n2) => n2 !== -1);
5150
- if (e.length > 0 && t.partialAxesMatch !== void 0)
5787
+ }
5788
+ const splitIndices = selector.axes.map((axis, index) => typeof axis === "object" && "split" in axis && axis.split === true ? index : -1).filter((index) => index !== -1);
5789
+ if (splitIndices.length > 0 && selector.partialAxesMatch !== void 0) {
5151
5790
  throw new Error("Axis splitting is not supported when `partialAxesMatch` is defined.");
5152
- return e.sort((n2, r) => n2 - r), e;
5791
+ }
5792
+ splitIndices.sort((a, b) => a - b);
5793
+ return splitIndices;
5153
5794
  }
5154
- class ge {
5795
+ class PColumnCollection {
5155
5796
  constructor() {
5156
- L(this, "defaultProviderStore", []);
5157
- L(this, "providers", [new wt(this.defaultProviderStore)]);
5158
- L(this, "axisLabelProviders", []);
5797
+ __publicField(this, "defaultProviderStore", []);
5798
+ __publicField(this, "providers", [new ArrayColumnProvider(this.defaultProviderStore)]);
5799
+ __publicField(this, "axisLabelProviders", []);
5159
5800
  }
5160
- addColumnProvider(e) {
5161
- return this.providers.push(e), this;
5801
+ addColumnProvider(provider) {
5802
+ this.providers.push(provider);
5803
+ return this;
5162
5804
  }
5163
- addAxisLabelProvider(e) {
5164
- return this.axisLabelProviders.push(e), this;
5805
+ addAxisLabelProvider(provider) {
5806
+ this.axisLabelProviders.push(provider);
5807
+ return this;
5165
5808
  }
5166
- addColumns(e) {
5167
- return this.defaultProviderStore.push(...e), this;
5809
+ addColumns(columns) {
5810
+ this.defaultProviderStore.push(...columns);
5811
+ return this;
5168
5812
  }
5169
- addColumn(e) {
5170
- return this.defaultProviderStore.push(e), this;
5813
+ addColumn(column) {
5814
+ this.defaultProviderStore.push(column);
5815
+ return this;
5171
5816
  }
5172
5817
  /** Fetches labels for a given axis from the registered providers */
5173
- findLabels(e) {
5174
- for (const n2 of this.axisLabelProviders) {
5175
- const r = n2.findLabels(e);
5176
- if (r) return r;
5177
- }
5178
- }
5179
- getUniversalEntries(e, n2) {
5180
- const { anchorCtx: r, labelOps: i, dontWaitAllData: s2 = false, overrideLabelAnnotation: o = false } = n2 ?? {}, a = {
5181
- ...o && (i == null ? void 0 : i.includeNativeLabel) !== false ? { includeNativeLabel: true } : {},
5182
- ...i ?? {}
5183
- }, l2 = typeof e == "function" ? [e] : Array.isArray(e) ? e : [e], u2 = [];
5184
- for (const p2 of l2) {
5185
- const f$1 = Ct(p2);
5186
- let h;
5187
- if (f$1) {
5188
- if (!r)
5818
+ findLabels(axis) {
5819
+ for (const provider of this.axisLabelProviders) {
5820
+ const labels = provider.findLabels(axis);
5821
+ if (labels)
5822
+ return labels;
5823
+ }
5824
+ return void 0;
5825
+ }
5826
+ getUniversalEntries(predicateOrSelectors, opts) {
5827
+ const { anchorCtx, labelOps: rawLabelOps, dontWaitAllData = false, overrideLabelAnnotation = false, exclude } = opts ?? {};
5828
+ const labelOps = {
5829
+ ...overrideLabelAnnotation && (rawLabelOps == null ? void 0 : rawLabelOps.includeNativeLabel) !== false ? { includeNativeLabel: true } : {},
5830
+ ...rawLabelOps ?? {}
5831
+ };
5832
+ let excludePredicate = () => false;
5833
+ if (exclude) {
5834
+ const excludePredicartes = (Array.isArray(exclude) ? exclude : [exclude]).map((selector) => {
5835
+ if (hasAnchors(selector)) {
5836
+ if (!anchorCtx)
5837
+ throw new Error("Anchored selectors in exclude require an AnchoredIdDeriver to be provided in options.");
5838
+ return selectorsToPredicate(resolveAnchors(anchorCtx.anchors, selector, opts));
5839
+ } else
5840
+ return selectorsToPredicate(selector);
5841
+ });
5842
+ excludePredicate = (spec) => excludePredicartes.some((predicate) => predicate(spec));
5843
+ }
5844
+ const selectorsArray = typeof predicateOrSelectors === "function" ? [predicateOrSelectors] : Array.isArray(predicateOrSelectors) ? predicateOrSelectors : [predicateOrSelectors];
5845
+ const intermediateResults = [];
5846
+ const selectedNativeIds = /* @__PURE__ */ new Set();
5847
+ for (const rawSelector of selectorsArray) {
5848
+ const usesAnchors = hasAnchors(rawSelector);
5849
+ let currentSelector;
5850
+ if (usesAnchors) {
5851
+ if (!anchorCtx)
5189
5852
  throw new Error("Anchored selectors require an AnchoredIdDeriver to be provided in options.");
5190
- h = Dn(r.anchors, p2, n2);
5853
+ currentSelector = resolveAnchors(anchorCtx.anchors, rawSelector, opts);
5191
5854
  } else
5192
- h = p2;
5193
- const d = /* @__PURE__ */ new Set(), x2 = [];
5194
- for (const g of this.providers) {
5195
- const b = g.selectColumns(h);
5196
- for (const A2 of b) {
5197
- if (d.has(A2.id)) throw new Error(`Duplicate column id ${A2.id} in provider ${g.constructor.name}`);
5198
- d.add(A2.id), x2.push(A2);
5855
+ currentSelector = rawSelector;
5856
+ const selectedIds = /* @__PURE__ */ new Set();
5857
+ const selectedColumns = [];
5858
+ for (const provider of this.providers) {
5859
+ const providerColumns = provider.selectColumns(currentSelector);
5860
+ for (const col of providerColumns) {
5861
+ if (excludePredicate(col.spec))
5862
+ continue;
5863
+ if (selectedIds.has(col.id))
5864
+ throw new Error(`Duplicate column id ${col.id} in provider ${provider.constructor.name}`);
5865
+ const nativeId = deriveNativeId(col.spec);
5866
+ if (selectedNativeIds.has(nativeId))
5867
+ continue;
5868
+ selectedIds.add(col.id);
5869
+ selectedNativeIds.add(nativeId);
5870
+ selectedColumns.push(col);
5199
5871
  }
5200
5872
  }
5201
- if (x2.length === 0) continue;
5202
- const c2 = St(p2), v = c2.length > 0;
5203
- for (const g of x2) {
5204
- if (!f(g.spec)) continue;
5205
- const b = g.spec;
5206
- if (v) {
5207
- const A2 = vt(g.data);
5208
- if (!A2) {
5209
- if (s2) continue;
5210
- return;
5873
+ if (selectedColumns.length === 0)
5874
+ continue;
5875
+ const splitAxisIdxs = getSplitAxisIndices(rawSelector);
5876
+ const needsSplitting = splitAxisIdxs.length > 0;
5877
+ for (const column of selectedColumns) {
5878
+ if (!isPColumnSpec(column.spec))
5879
+ continue;
5880
+ const originalSpec = column.spec;
5881
+ if (needsSplitting) {
5882
+ if (isPColumnValues(column.data))
5883
+ throw new Error(`Splitting is not supported for PColumns with PColumnValues data format. Column id: ${column.id}`);
5884
+ const dataEntries = convertOrParsePColumnData(column.data);
5885
+ if (!dataEntries) {
5886
+ if (dontWaitAllData)
5887
+ continue;
5888
+ return void 0;
5211
5889
  }
5212
- if (!ln(A2))
5213
- throw new Error(`Splitting requires Partitioned DataInfoEntries, but parsing resulted in ${A2.type} for column ${g.id}`);
5214
- const D = yt(A2), $2 = c2[c2.length - 1];
5215
- if ($2 >= A2.partitionKeyLength)
5216
- throw new Error(`Not enough partition keys (${A2.partitionKeyLength}) for requested split axes (max index ${$2}) in column ${b.name}`);
5217
- const q2 = c2.map((P) => this.findLabels(p$1(b.axesSpec[P]))), F = [], _ = (P, N2) => {
5218
- if (N2 >= c2.length) {
5219
- if (F.push([...P]), F.length > 1e4)
5890
+ if (!isPartitionedDataInfoEntries(dataEntries))
5891
+ throw new Error(`Splitting requires Partitioned DataInfoEntries, but parsing resulted in ${dataEntries.type} for column ${column.id}`);
5892
+ const uniqueKeys = getUniquePartitionKeys(dataEntries);
5893
+ const maxSplitIdx = splitAxisIdxs[splitAxisIdxs.length - 1];
5894
+ if (maxSplitIdx >= dataEntries.partitionKeyLength)
5895
+ throw new Error(`Not enough partition keys (${dataEntries.partitionKeyLength}) for requested split axes (max index ${maxSplitIdx}) in column ${originalSpec.name}`);
5896
+ const axesLabels = splitAxisIdxs.map((idx) => this.findLabels(getAxisId(originalSpec.axesSpec[idx])));
5897
+ const keyCombinations = [];
5898
+ const generateCombinations = (currentCombo, sAxisIdx) => {
5899
+ if (sAxisIdx >= splitAxisIdxs.length) {
5900
+ keyCombinations.push([...currentCombo]);
5901
+ if (keyCombinations.length > 1e4)
5220
5902
  throw new Error("Too many key combinations, aborting.");
5221
5903
  return;
5222
5904
  }
5223
- const O = c2[N2];
5224
- if (O >= D.length)
5225
- throw new Error(`Axis index ${O} out of bounds for unique keys array (length ${D.length}) during split key generation for column ${g.id}`);
5226
- const k2 = D[O];
5227
- if (!k2 || k2.length === 0) {
5228
- F.length = 0;
5905
+ const axisIdx = splitAxisIdxs[sAxisIdx];
5906
+ if (axisIdx >= uniqueKeys.length)
5907
+ throw new Error(`Axis index ${axisIdx} out of bounds for unique keys array (length ${uniqueKeys.length}) during split key generation for column ${column.id}`);
5908
+ const axisValues = uniqueKeys[axisIdx];
5909
+ if (!axisValues || axisValues.length === 0) {
5910
+ keyCombinations.length = 0;
5229
5911
  return;
5230
5912
  }
5231
- for (const z2 of k2)
5232
- P.push(z2), _(P, N2 + 1), P.pop();
5913
+ for (const val of axisValues) {
5914
+ currentCombo.push(val);
5915
+ generateCombinations(currentCombo, sAxisIdx + 1);
5916
+ currentCombo.pop();
5917
+ }
5233
5918
  };
5234
- if (_([], 0), F.length === 0)
5919
+ generateCombinations([], 0);
5920
+ if (keyCombinations.length === 0)
5235
5921
  continue;
5236
- const R = [...b.axesSpec], se = c2.map((P) => P);
5237
- for (let P = c2.length - 1; P >= 0; P--)
5238
- R.splice(c2[P], 1);
5239
- const J = { ...b, axesSpec: R };
5240
- for (const P of F) {
5241
- const N2 = P.map((O, k2) => {
5242
- const z2 = se[k2], Ne = p$1(b.axesSpec[z2]), oe = q2[k2], Be = (oe == null ? void 0 : oe[O]) ?? String(O);
5243
- return { axisIdx: z2, axisId: Ne, value: O, label: Be };
5922
+ const newAxesSpec = [...originalSpec.axesSpec];
5923
+ const splitAxisOriginalIdxs = splitAxisIdxs.map((idx) => idx);
5924
+ for (let i = splitAxisIdxs.length - 1; i >= 0; i--) {
5925
+ newAxesSpec.splice(splitAxisIdxs[i], 1);
5926
+ }
5927
+ const adjustedSpec = { ...originalSpec, axesSpec: newAxesSpec };
5928
+ for (const keyCombo of keyCombinations) {
5929
+ const splitFilters = keyCombo.map((value, sAxisIdx) => {
5930
+ const axisIdx = splitAxisOriginalIdxs[sAxisIdx];
5931
+ const axisId = getAxisId(originalSpec.axesSpec[axisIdx]);
5932
+ const axisLabelMap = axesLabels[sAxisIdx];
5933
+ const label = (axisLabelMap == null ? void 0 : axisLabelMap[value]) ?? String(value);
5934
+ return { axisIdx, axisId, value, label };
5244
5935
  });
5245
- u2.push({
5936
+ intermediateResults.push({
5246
5937
  type: "split",
5247
- originalColumn: g,
5248
- spec: b,
5249
- adjustedSpec: J,
5250
- dataEntries: A2,
5251
- axisFilters: N2
5938
+ originalColumn: column,
5939
+ spec: originalSpec,
5940
+ adjustedSpec,
5941
+ dataEntries,
5942
+ axisFilters: splitFilters
5252
5943
  });
5253
5944
  }
5254
- } else
5255
- u2.push({
5945
+ } else {
5946
+ intermediateResults.push({
5256
5947
  type: "direct",
5257
- originalColumn: g,
5258
- spec: b,
5259
- adjustedSpec: b
5948
+ originalColumn: column,
5949
+ spec: originalSpec,
5950
+ adjustedSpec: originalSpec
5260
5951
  });
5952
+ }
5261
5953
  }
5262
5954
  }
5263
- if (u2.length === 0) return [];
5264
- const y = Oe(
5265
- u2,
5266
- (p2) => ({
5267
- spec: p2.spec,
5268
- suffixTrace: p2.type === "split" ? At(p2.axisFilters) : void 0
5269
- }),
5270
- a
5271
- ), w2 = [];
5272
- for (const { value: p2, label: f2 } of y) {
5273
- const { originalColumn: h, spec: d } = p2, x2 = p2.type === "split" ? p2.axisFilters : void 0, c2 = Pt(x2);
5274
- let v;
5275
- r ? v = r.deriveS(d, c2) : v = xt(h.id, c2);
5276
- let g = { ...p2.adjustedSpec };
5277
- o && (g = {
5278
- ...g,
5279
- annotations: {
5280
- ...g.annotations ?? {},
5281
- "pl7.app/label": f2
5282
- }
5283
- }), w2.push({
5284
- id: v,
5285
- spec: g,
5286
- data: () => p2.type === "split" ? gn(bt(p2.dataEntries, c2)) : p2.originalColumn.data,
5287
- label: f2
5955
+ if (intermediateResults.length === 0)
5956
+ return [];
5957
+ const labeledResults = deriveLabels(intermediateResults, (entry) => ({
5958
+ spec: entry.spec,
5959
+ suffixTrace: entry.type === "split" ? splitFiltersToTrace(entry.axisFilters) : void 0
5960
+ }), labelOps);
5961
+ const result = [];
5962
+ for (const { value: entry, label } of labeledResults) {
5963
+ const { originalColumn, spec: originalSpec } = entry;
5964
+ const axisFilters = entry.type === "split" ? entry.axisFilters : void 0;
5965
+ const axisFiltersTuple = splitFiltersToAxisFilter(axisFilters);
5966
+ let finalId;
5967
+ if (anchorCtx)
5968
+ finalId = anchorCtx.deriveS(originalSpec, axisFiltersTuple);
5969
+ else
5970
+ finalId = fallbackIdDeriver(originalColumn.id, axisFiltersTuple);
5971
+ let finalSpec = { ...entry.adjustedSpec };
5972
+ if (overrideLabelAnnotation) {
5973
+ finalSpec = {
5974
+ ...finalSpec,
5975
+ annotations: {
5976
+ ...finalSpec.annotations ?? {},
5977
+ [Annotation.Label]: label
5978
+ }
5979
+ };
5980
+ }
5981
+ result.push({
5982
+ id: finalId,
5983
+ spec: finalSpec,
5984
+ data: () => entry.type === "split" ? entriesToDataInfo(filterDataInfoEntries(entry.dataEntries, axisFiltersTuple)) : entry.originalColumn.data,
5985
+ label
5288
5986
  });
5289
5987
  }
5290
- return w2;
5988
+ return result;
5291
5989
  }
5292
- getColumns(e, n2) {
5293
- const r = this.getUniversalEntries(e, {
5990
+ getColumns(predicateOrSelectors, opts) {
5991
+ const entries = this.getUniversalEntries(predicateOrSelectors, {
5294
5992
  overrideLabelAnnotation: true,
5295
5993
  // default for getColumns
5296
- ...n2 ?? {}
5994
+ ...opts ?? {}
5297
5995
  });
5298
- if (!r) return;
5299
- const i = [];
5300
- for (const s2 of r) {
5301
- const o = s2.data();
5302
- if (!o) {
5303
- if (n2 != null && n2.dontWaitAllData) continue;
5304
- return;
5996
+ if (!entries)
5997
+ return void 0;
5998
+ const columns = [];
5999
+ for (const entry of entries) {
6000
+ const data = entry.data();
6001
+ if (!data) {
6002
+ if (opts == null ? void 0 : opts.dontWaitAllData)
6003
+ continue;
6004
+ return void 0;
5305
6005
  }
5306
- i.push({
5307
- id: s2.id,
5308
- spec: s2.spec,
5309
- data: o
6006
+ columns.push({
6007
+ id: entry.id,
6008
+ spec: entry.spec,
6009
+ data
5310
6010
  });
5311
6011
  }
5312
- return i;
6012
+ return columns;
5313
6013
  }
5314
6014
  }
5315
- function le(t, e) {
5316
- if (t === void 0) return e === void 0;
5317
- if (e === void 0) return true;
5318
- for (const n2 in e)
5319
- if (t[n2] !== e[n2]) return false;
6015
+ function patchInSetFilters(filters) {
6016
+ const inSetToOrEqual = (predicate) => {
6017
+ if (predicate.operator !== "InSet")
6018
+ return predicate;
6019
+ return {
6020
+ operator: "Or",
6021
+ operands: predicate.references.map((reference) => ({
6022
+ operator: "Equal",
6023
+ reference
6024
+ }))
6025
+ };
6026
+ };
6027
+ const mapSingleValuePredicate = (filter, cb) => {
6028
+ const operator = filter.operator;
6029
+ switch (operator) {
6030
+ case "And":
6031
+ return {
6032
+ ...filter,
6033
+ operands: filter.operands.map((operand) => mapSingleValuePredicate(operand, cb))
6034
+ };
6035
+ case "Or":
6036
+ return {
6037
+ ...filter,
6038
+ operands: filter.operands.map((operand) => mapSingleValuePredicate(operand, cb))
6039
+ };
6040
+ case "Not":
6041
+ return {
6042
+ ...filter,
6043
+ operand: mapSingleValuePredicate(filter.operand, cb)
6044
+ };
6045
+ default:
6046
+ return cb(filter);
6047
+ }
6048
+ };
6049
+ const mapFilter = (filter, cb) => {
6050
+ return {
6051
+ ...filter,
6052
+ predicate: mapSingleValuePredicate(filter.predicate, cb)
6053
+ };
6054
+ };
6055
+ return filters.map((filter) => mapFilter(filter, inSetToOrEqual));
6056
+ }
6057
+ function matchDomain(query, target) {
6058
+ if (query === void 0)
6059
+ return target === void 0;
6060
+ if (target === void 0)
6061
+ return true;
6062
+ for (const k in target) {
6063
+ if (query[k] !== target[k])
6064
+ return false;
6065
+ }
5320
6066
  return true;
5321
6067
  }
5322
- function Pe(t) {
5323
- return Fn(t, (e) => e instanceof I ? e.handle : mn(e) ? yn(e, (n2) => n2.handle) : e);
6068
+ function transformPColumnData(data) {
6069
+ return mapPObjectData(data, (d) => {
6070
+ if (d instanceof TreeNodeAccessor) {
6071
+ return d.handle;
6072
+ } else if (isDataInfo(d)) {
6073
+ return mapDataInfo(d, (accessor) => accessor.handle);
6074
+ } else {
6075
+ return d;
6076
+ }
6077
+ });
5324
6078
  }
5325
- class It {
6079
+ class ResultPool {
5326
6080
  constructor() {
5327
- L(this, "ctx", m());
6081
+ __publicField(this, "ctx", getCfgRenderCtx());
5328
6082
  }
5329
6083
  /**
5330
6084
  * @deprecated use getOptions()
5331
6085
  */
5332
- calculateOptions(e) {
5333
- return this.ctx.calculateOptions(e);
5334
- }
5335
- getOptions(e, n2) {
5336
- const r = typeof e == "function" ? e : Kn(e), i = this.getSpecs().entries.filter((s2) => r(s2.obj));
5337
- return typeof n2 == "object" || typeof n2 > "u" ? Oe(i, (s2) => s2.obj, n2 ?? {}).map(({ value: { ref: s2 }, label: o }) => ({
5338
- ref: s2,
5339
- label: o
5340
- })) : i.map((s2) => ({
5341
- ref: s2.ref,
5342
- label: n2(s2.obj, s2.ref)
5343
- }));
6086
+ calculateOptions(predicate) {
6087
+ return this.ctx.calculateOptions(predicate);
6088
+ }
6089
+ getOptions(predicateOrSelector, opts) {
6090
+ const predicate = typeof predicateOrSelector === "function" ? predicateOrSelector : selectorsToPredicate(predicateOrSelector);
6091
+ const filtered = this.getSpecs().entries.filter((s) => predicate(s.obj));
6092
+ let labelOps = {};
6093
+ let refsWithEnrichments = false;
6094
+ if (typeof opts !== "undefined") {
6095
+ if (typeof opts === "function") {
6096
+ labelOps = opts;
6097
+ } else if (typeof opts === "object") {
6098
+ if ("includeNativeLabel" in opts || "separator" in opts || "addLabelAsSuffix" in opts) {
6099
+ labelOps = opts;
6100
+ } else {
6101
+ opts = opts;
6102
+ labelOps = opts.label ?? {};
6103
+ refsWithEnrichments = opts.refsWithEnrichments ?? false;
6104
+ }
6105
+ }
6106
+ }
6107
+ if (typeof labelOps === "object")
6108
+ return deriveLabels(filtered, (o) => o.obj, labelOps ?? {}).map(({ value: { ref }, label }) => ({
6109
+ ref: withEnrichments(ref, refsWithEnrichments),
6110
+ label
6111
+ }));
6112
+ else
6113
+ return filtered.map(({ ref, obj }) => ({
6114
+ ref: withEnrichments(ref, refsWithEnrichments),
6115
+ label: labelOps(obj, ref)
6116
+ }));
5344
6117
  }
5345
- resolveAnchorCtx(e) {
5346
- if (e instanceof $n) return e;
5347
- const n2 = {};
5348
- for (const [r, i] of Object.entries(e))
5349
- if (Tn(i)) {
5350
- const s2 = this.getPColumnSpecByRef(i);
5351
- if (!s2)
5352
- return;
5353
- n2[r] = s2;
5354
- } else
5355
- n2[r] = i;
5356
- return new $n(n2);
6118
+ resolveAnchorCtx(anchorsOrCtx) {
6119
+ if (anchorsOrCtx instanceof AnchoredIdDeriver)
6120
+ return anchorsOrCtx;
6121
+ const resolvedAnchors = {};
6122
+ for (const [key, value] of Object.entries(anchorsOrCtx)) {
6123
+ if (isPlRef(value)) {
6124
+ const resolvedSpec = this.getPColumnSpecByRef(value);
6125
+ if (!resolvedSpec)
6126
+ return void 0;
6127
+ resolvedAnchors[key] = resolvedSpec;
6128
+ } else {
6129
+ resolvedAnchors[key] = value;
6130
+ }
6131
+ }
6132
+ return new AnchoredIdDeriver(resolvedAnchors);
5357
6133
  }
5358
6134
  /**
5359
6135
  * Returns columns that match the provided anchors and selectors. It applies axis filters and label derivation.
@@ -5363,13 +6139,14 @@
5363
6139
  * @param opts - Optional configuration for label generation and data waiting
5364
6140
  * @returns A PFrameHandle for the created PFrame, or undefined if any required data is missing
5365
6141
  */
5366
- getAnchoredPColumns(e, n2, r) {
5367
- const i = this.resolveAnchorCtx(e);
5368
- if (i)
5369
- return new ge().addColumnProvider(this).addAxisLabelProvider(this).getColumns(n2, {
5370
- ...r,
5371
- anchorCtx: i
5372
- });
6142
+ getAnchoredPColumns(anchorsOrCtx, predicateOrSelectors, opts) {
6143
+ const anchorCtx = this.resolveAnchorCtx(anchorsOrCtx);
6144
+ if (!anchorCtx)
6145
+ return void 0;
6146
+ return new PColumnCollection().addColumnProvider(this).addAxisLabelProvider(this).getColumns(predicateOrSelectors, {
6147
+ ...opts,
6148
+ anchorCtx
6149
+ });
5373
6150
  }
5374
6151
  /**
5375
6152
  * Calculates anchored identifier options for columns matching a given predicate and returns their
@@ -5400,18 +6177,20 @@
5400
6177
  * @returns An array of objects with `label` (display text) and `value` (anchored ID string) properties,
5401
6178
  * or undefined if any PlRef resolution fails.
5402
6179
  */
5403
- getCanonicalOptions(e, n2, r) {
5404
- const i = this.resolveAnchorCtx(e);
5405
- if (!i) return;
5406
- const s2 = new ge().addColumnProvider(this).addAxisLabelProvider(this).getUniversalEntries(n2, {
5407
- ...r,
5408
- anchorCtx: i
6180
+ getCanonicalOptions(anchorsOrCtx, predicateOrSelectors, opts) {
6181
+ const anchorCtx = this.resolveAnchorCtx(anchorsOrCtx);
6182
+ if (!anchorCtx)
6183
+ return void 0;
6184
+ const entries = new PColumnCollection().addColumnProvider(this).addAxisLabelProvider(this).getUniversalEntries(predicateOrSelectors, {
6185
+ ...opts,
6186
+ anchorCtx
5409
6187
  });
5410
- if (s2)
5411
- return s2.map((o) => ({
5412
- value: o.id,
5413
- label: o.label
5414
- }));
6188
+ if (!entries)
6189
+ return void 0;
6190
+ return entries.map((item) => ({
6191
+ value: item.id,
6192
+ label: item.label
6193
+ }));
5415
6194
  }
5416
6195
  /**
5417
6196
  * @deprecated use getData()
@@ -5420,14 +6199,14 @@
5420
6199
  return this.getData();
5421
6200
  }
5422
6201
  getData() {
5423
- const e = this.ctx.getDataFromResultPool();
6202
+ const result = this.ctx.getDataFromResultPool();
5424
6203
  return {
5425
- isComplete: e.isComplete,
5426
- entries: e.entries.map((n2) => ({
5427
- ref: n2.ref,
6204
+ isComplete: result.isComplete,
6205
+ entries: result.entries.map((e) => ({
6206
+ ref: e.ref,
5428
6207
  obj: {
5429
- ...n2.obj,
5430
- data: new I(n2.obj.data, [n2.ref.blockId, n2.ref.name])
6208
+ ...e.obj,
6209
+ data: new TreeNodeAccessor(e.obj.data, [e.ref.blockId, e.ref.name])
5431
6210
  }
5432
6211
  }))
5433
6212
  };
@@ -5439,17 +6218,14 @@
5439
6218
  return this.getDataWithErrors();
5440
6219
  }
5441
6220
  getDataWithErrors() {
5442
- const e = this.ctx.getDataWithErrorsFromResultPool();
6221
+ const result = this.ctx.getDataWithErrorsFromResultPool();
5443
6222
  return {
5444
- isComplete: e.isComplete,
5445
- entries: e.entries.map((n2) => ({
5446
- ref: n2.ref,
6223
+ isComplete: result.isComplete,
6224
+ entries: result.entries.map((e) => ({
6225
+ ref: e.ref,
5447
6226
  obj: {
5448
- ...n2.obj,
5449
- data: _n$1(
5450
- n2.obj.data,
5451
- (r) => new I(r, [n2.ref.blockId, n2.ref.name])
5452
- )
6227
+ ...e.obj,
6228
+ data: mapValueInVOE(e.obj.data, (handle) => new TreeNodeAccessor(handle, [e.ref.blockId, e.ref.name]))
5453
6229
  }
5454
6230
  }))
5455
6231
  };
@@ -5467,89 +6243,106 @@
5467
6243
  * @param ref a Ref
5468
6244
  * @returns data associated with the ref
5469
6245
  */
5470
- getDataByRef(e) {
5471
- var r;
5472
- if (typeof this.ctx.getDataFromResultPoolByRef > "u")
5473
- return (r = this.getData().entries.find(
5474
- (i) => i.ref.blockId === e.blockId && i.ref.name === e.name
5475
- )) == null ? void 0 : r.obj;
5476
- const n2 = this.ctx.getDataFromResultPoolByRef(e.blockId, e.name);
5477
- if (n2)
5478
- return Fn(
5479
- n2,
5480
- (i) => new I(i, [e.blockId, e.name])
5481
- );
6246
+ getDataByRef(ref) {
6247
+ var _a;
6248
+ if (typeof this.ctx.getDataFromResultPoolByRef === "undefined")
6249
+ return (_a = this.getData().entries.find((f) => f.ref.blockId === ref.blockId && f.ref.name === ref.name)) == null ? void 0 : _a.obj;
6250
+ const data = this.ctx.getDataFromResultPoolByRef(ref.blockId, ref.name);
6251
+ if (!data)
6252
+ return void 0;
6253
+ return mapPObjectData(data, (handle) => new TreeNodeAccessor(handle, [ref.blockId, ref.name]));
5482
6254
  }
5483
6255
  /**
5484
6256
  * Returns data associated with the ref ensuring that it is a p-column.
5485
6257
  * @param ref a Ref
5486
6258
  * @returns p-column associated with the ref
5487
6259
  */
5488
- getPColumnByRef(e) {
5489
- const n2 = this.getDataByRef(e);
5490
- if (n2)
5491
- return jn(n2);
6260
+ getPColumnByRef(ref) {
6261
+ const data = this.getDataByRef(ref);
6262
+ if (!data)
6263
+ return void 0;
6264
+ return ensurePColumn(data);
5492
6265
  }
5493
6266
  /**
5494
6267
  * Returns spec associated with the ref ensuring that it is a p-column spec.
5495
6268
  * @param ref a Ref
5496
6269
  * @returns p-column spec associated with the ref
5497
6270
  */
5498
- getPColumnSpecByRef(e) {
5499
- const n2 = this.getSpecByRef(e);
5500
- if (n2) {
5501
- if (!f(n2)) throw new Error(`not a PColumn spec (kind = ${n2.kind})`);
5502
- return n2;
5503
- }
6271
+ getPColumnSpecByRef(ref) {
6272
+ const spec = this.getSpecByRef(ref);
6273
+ if (!spec)
6274
+ return void 0;
6275
+ if (!isPColumnSpec(spec))
6276
+ throw new Error(`not a PColumn spec (kind = ${spec.kind})`);
6277
+ return spec;
5504
6278
  }
5505
6279
  /**
5506
6280
  * @param ref a Ref
5507
6281
  * @returns object spec associated with the ref
5508
6282
  */
5509
- getSpecByRef(e) {
5510
- return this.ctx.getSpecFromResultPoolByRef(e.blockId, e.name);
6283
+ getSpecByRef(ref) {
6284
+ return this.ctx.getSpecFromResultPoolByRef(ref.blockId, ref.name);
5511
6285
  }
5512
6286
  /**
5513
6287
  * @param spec object specification
5514
6288
  * @returns array of data objects with compatible specs
5515
6289
  * @deprecated delete this method after Jan 1, 2025
5516
6290
  */
5517
- findDataWithCompatibleSpec(e) {
5518
- const n2 = [];
5519
- e: for (const r of this.getData().entries) {
5520
- if (!f(r.obj.spec))
6291
+ findDataWithCompatibleSpec(spec) {
6292
+ const result = [];
6293
+ out: for (const data of this.getData().entries) {
6294
+ if (!isPColumnSpec(data.obj.spec)) {
6295
+ continue;
6296
+ }
6297
+ const oth = data.obj.spec;
6298
+ if (spec.name !== oth.name) {
5521
6299
  continue;
5522
- const i = r.obj.spec;
5523
- if (e.name === i.name && e.valueType === i.valueType && e.axesSpec.length === i.axesSpec.length && le(e.domain, i.domain)) {
5524
- for (let s2 = 0; s2 < e.axesSpec.length; ++s2) {
5525
- const o = e.axesSpec[s2], a = i.axesSpec[s2];
5526
- if (o.name !== a.name || o.type !== a.type || !le(o.domain, a.domain))
5527
- continue e;
6300
+ }
6301
+ if (spec.valueType !== oth.valueType) {
6302
+ continue;
6303
+ }
6304
+ if (spec.axesSpec.length !== oth.axesSpec.length) {
6305
+ continue;
6306
+ }
6307
+ if (!matchDomain(spec.domain, oth.domain)) {
6308
+ continue;
6309
+ }
6310
+ for (let i = 0; i < spec.axesSpec.length; ++i) {
6311
+ const qAx = spec.axesSpec[i];
6312
+ const tAx = oth.axesSpec[i];
6313
+ if (qAx.name !== tAx.name) {
6314
+ continue out;
6315
+ }
6316
+ if (qAx.type !== tAx.type) {
6317
+ continue out;
6318
+ }
6319
+ if (!matchDomain(qAx.domain, tAx.domain)) {
6320
+ continue out;
5528
6321
  }
5529
- n2.push(r.obj);
5530
6322
  }
6323
+ result.push(data.obj);
5531
6324
  }
5532
- return n2;
6325
+ return result;
5533
6326
  }
5534
6327
  /**
5535
6328
  * Find labels data for a given axis id. It will search for a label column and return its data as a map.
5536
6329
  * @returns a map of axis value => label
5537
6330
  */
5538
- findLabels(e) {
5539
- const n2 = this.getData();
5540
- for (const r of n2.entries) {
5541
- if (!q(r.obj)) continue;
5542
- const i = r.obj.spec;
5543
- if (i.name === "pl7.app/label" && i.axesSpec.length === 1 && i.axesSpec[0].name === e.name && i.axesSpec[0].type === e.type && le(e.domain, i.axesSpec[0].domain)) {
5544
- if (r.obj.data.resourceType.name !== "PColumnData/Json")
5545
- throw Error(`Expected JSON column for labels, got: ${r.obj.data.resourceType.name}`);
5546
- return Object.fromEntries(
5547
- Object.entries(
5548
- r.obj.data.getDataAsJson().data
5549
- ).map((o) => [JSON.parse(o[0])[0], o[1]])
5550
- );
6331
+ findLabels(axis) {
6332
+ const dataPool = this.getData();
6333
+ for (const column of dataPool.entries) {
6334
+ if (!isPColumn(column.obj))
6335
+ continue;
6336
+ const spec = column.obj.spec;
6337
+ if (spec.name === PColumnName.Label && spec.axesSpec.length === 1 && spec.axesSpec[0].name === axis.name && spec.axesSpec[0].type === axis.type && matchDomain(axis.domain, spec.axesSpec[0].domain)) {
6338
+ if (column.obj.data.resourceType.name !== "PColumnData/Json") {
6339
+ throw Error(`Expected JSON column for labels, got: ${column.obj.data.resourceType.name}`);
6340
+ }
6341
+ const labels = Object.fromEntries(Object.entries(column.obj.data.getDataAsJson().data).map((e) => [JSON.parse(e[0])[0], e[1]]));
6342
+ return labels;
5551
6343
  }
5552
6344
  }
6345
+ return void 0;
5553
6346
  }
5554
6347
  /**
5555
6348
  * Selects columns based on the provided selectors, returning PColumn objects
@@ -5558,18 +6351,27 @@
5558
6351
  * @param selectors - A predicate function, a single selector, or an array of selectors.
5559
6352
  * @returns An array of PColumn objects matching the selectors. Data is loaded on first access.
5560
6353
  */
5561
- selectColumns(e) {
5562
- const n2 = typeof e == "function" ? e : Kn(e);
5563
- return this.getSpecs().entries.filter(({ obj: i }) => f(i) ? n2(i) : false).map(({ ref: i, obj: s2 }) => {
5564
- const o = s2;
5565
- let a = null;
5566
- const l2 = this;
6354
+ selectColumns(selectors) {
6355
+ const predicate = typeof selectors === "function" ? selectors : selectorsToPredicate(selectors);
6356
+ const matchedSpecs = this.getSpecs().entries.filter(({ obj: spec }) => {
6357
+ if (!isPColumnSpec(spec))
6358
+ return false;
6359
+ return predicate(spec);
6360
+ });
6361
+ return matchedSpecs.map(({ ref, obj: spec }) => {
6362
+ const pcolumnSpec = spec;
6363
+ let _cachedData = null;
6364
+ const self2 = this;
5567
6365
  return {
5568
- id: _e(i),
5569
- spec: o,
6366
+ id: canonicalize(ref),
6367
+ spec: pcolumnSpec,
5570
6368
  get data() {
5571
- var u2;
5572
- return a !== null || (a = (u2 = l2.getPColumnByRef(i)) == null ? void 0 : u2.data), a;
6369
+ var _a;
6370
+ if (_cachedData !== null) {
6371
+ return _cachedData;
6372
+ }
6373
+ _cachedData = (_a = self2.getPColumnByRef(ref)) == null ? void 0 : _a.data;
6374
+ return _cachedData;
5573
6375
  }
5574
6376
  };
5575
6377
  });
@@ -5578,458 +6380,646 @@
5578
6380
  * Find labels data for a given axis id of a p-column.
5579
6381
  * @returns a map of axis value => label
5580
6382
  */
5581
- findLabelsForColumnAxis(e, n2) {
5582
- var s2;
5583
- const r = this.findLabels(e.axesSpec[n2]);
5584
- if (!r) return;
5585
- const i = (s2 = e.annotations) == null ? void 0 : s2["pl7.app/axisKeys/" + n2];
5586
- if (i !== void 0) {
5587
- const o = JSON.parse(i);
5588
- return Object.fromEntries(o.map((a) => [a, r[a] ?? "Unlabelled"]));
5589
- } else
5590
- return r;
6383
+ findLabelsForColumnAxis(column, axisIdx) {
6384
+ const labels = this.findLabels(column.axesSpec[axisIdx]);
6385
+ if (!labels)
6386
+ return void 0;
6387
+ const axisKeys = readAnnotation(column, `pl7.app/axisKeys/${axisIdx}`);
6388
+ if (axisKeys !== void 0) {
6389
+ const keys = JSON.parse(axisKeys);
6390
+ return Object.fromEntries(keys.map((key) => {
6391
+ return [key, labels[key] ?? "Unlabelled"];
6392
+ }));
6393
+ } else {
6394
+ return labels;
6395
+ }
5591
6396
  }
5592
6397
  }
5593
- class X {
6398
+ class RenderCtx {
5594
6399
  constructor() {
5595
- L(this, "ctx");
5596
- L(this, "args");
5597
- L(this, "uiState");
5598
- L(this, "_activeArgsCache");
5599
- L(this, "resultPool", new It());
5600
- this.ctx = m(), this.args = JSON.parse(this.ctx.args), this.uiState = this.ctx.uiState !== void 0 ? JSON.parse(this.ctx.uiState) : {};
6400
+ __publicField(this, "ctx");
6401
+ __publicField(this, "_argsCache");
6402
+ __publicField(this, "_uiStateCache");
6403
+ // lazy rendering because this feature is rarely used
6404
+ __publicField(this, "_activeArgsCache");
6405
+ __publicField(this, "resultPool", new ResultPool());
6406
+ this.ctx = getCfgRenderCtx();
6407
+ }
6408
+ get args() {
6409
+ if (this._argsCache === void 0) {
6410
+ const raw = this.ctx.args;
6411
+ const value = typeof raw === "function" ? raw() : raw;
6412
+ this._argsCache = { v: JSON.parse(value) };
6413
+ }
6414
+ return this._argsCache.v;
6415
+ }
6416
+ get uiState() {
6417
+ if (this._uiStateCache === void 0) {
6418
+ const raw = this.ctx.uiState;
6419
+ const value = typeof raw === "function" ? raw() : raw;
6420
+ this._uiStateCache = { v: value ? JSON.parse(value) : {} };
6421
+ }
6422
+ return this._uiStateCache.v;
5601
6423
  }
5602
6424
  /**
5603
6425
  * Returns args snapshot the block was executed for (i.e. when "Run" button was pressed).
5604
6426
  * Returns undefined, if block was never executed or stopped mid-way execution, so that the result was cleared.
5605
6427
  * */
5606
6428
  get activeArgs() {
5607
- return this._activeArgsCache === void 0 && (this._activeArgsCache = {
5608
- v: this.ctx.activeArgs ? JSON.parse(this.ctx.activeArgs) : void 0
5609
- }), this._activeArgsCache.v;
6429
+ if (this._activeArgsCache === void 0) {
6430
+ const raw = this.ctx.activeArgs;
6431
+ const value = typeof raw === "function" ? raw() : raw;
6432
+ this._activeArgsCache = {
6433
+ v: value ? JSON.parse(value) : void 0
6434
+ };
6435
+ }
6436
+ return this._activeArgsCache.v;
5610
6437
  }
5611
6438
  // /** Can be used to determine features provided by the desktop instance. */
5612
6439
  // public get featureFlags() {
5613
6440
  // return this.ctx.featureFlags;
5614
6441
  // }
5615
- getNamedAccessor(e) {
5616
- return pe(
5617
- this.ctx.getAccessorHandleByName(e),
5618
- (n2) => new I(n2, [e])
5619
- );
6442
+ getNamedAccessor(name) {
6443
+ return ifDef(this.ctx.getAccessorHandleByName(name), (accessor) => new TreeNodeAccessor(accessor, [name]));
5620
6444
  }
5621
6445
  get prerun() {
5622
- return this.getNamedAccessor(Ee);
6446
+ return this.getNamedAccessor(StagingAccessorName);
5623
6447
  }
5624
6448
  get outputs() {
5625
- return this.getNamedAccessor(Fe);
6449
+ return this.getNamedAccessor(MainAccessorName);
5626
6450
  }
5627
6451
  /**
5628
6452
  * Find labels data for a given axis id. It will search for a label column and return its data as a map.
5629
6453
  * @returns a map of axis value => label
5630
6454
  * @deprecated Use resultPool.findLabels instead
5631
6455
  */
5632
- findLabels(e) {
5633
- return this.resultPool.findLabels(e);
6456
+ findLabels(axis) {
6457
+ return this.resultPool.findLabels(axis);
5634
6458
  }
5635
- verifyInlineAndExplicitColumnsSupport(e) {
5636
- var i;
5637
- const n2 = e.some((s2) => !(s2.data instanceof I) || mn(s2.data)), r = ((i = this.ctx.featureFlags) == null ? void 0 : i.inlineColumnsSupport) === true;
5638
- if (n2 && !r) throw Error("Inline or explicit columns not supported");
6459
+ verifyInlineAndExplicitColumnsSupport(columns) {
6460
+ var _a;
6461
+ const hasInlineColumns = columns.some((c) => !(c.data instanceof TreeNodeAccessor) || isDataInfo(c.data));
6462
+ const inlineColumnsSupport = ((_a = this.ctx.featureFlags) == null ? void 0 : _a.inlineColumnsSupport) === true;
6463
+ if (hasInlineColumns && !inlineColumnsSupport)
6464
+ throw Error(`Inline or explicit columns not supported`);
6465
+ }
6466
+ patchPTableDef(def) {
6467
+ var _a, _b;
6468
+ if (!((_a = this.ctx.featureFlags) == null ? void 0 : _a.pTablePartitionFiltersSupport)) {
6469
+ def = {
6470
+ ...def,
6471
+ partitionFilters: [],
6472
+ filters: [...def.partitionFilters, ...def.filters]
6473
+ };
6474
+ }
6475
+ if (!((_b = this.ctx.featureFlags) == null ? void 0 : _b.pFrameInSetFilterSupport)) {
6476
+ def = {
6477
+ ...def,
6478
+ partitionFilters: patchInSetFilters(def.partitionFilters),
6479
+ filters: patchInSetFilters(def.filters)
6480
+ };
6481
+ }
6482
+ return def;
5639
6483
  }
5640
6484
  // TODO remove all non-PColumn fields
5641
- createPFrame(e) {
5642
- return this.verifyInlineAndExplicitColumnsSupport(e), this.ctx.createPFrame(
5643
- e.map((n2) => Pe(n2))
5644
- );
5645
- }
5646
- createPTable(e) {
5647
- let n2;
5648
- return "columns" in e ? n2 = {
5649
- src: {
5650
- type: "full",
5651
- entries: e.columns.map((r) => ({ type: "column", column: r }))
5652
- },
5653
- filters: e.filters ?? [],
5654
- sorting: e.sorting ?? []
5655
- } : n2 = e, this.verifyInlineAndExplicitColumnsSupport(Un(n2.src)), this.ctx.createPTable(
5656
- On(n2, (r) => Pe(r))
5657
- );
6485
+ createPFrame(def) {
6486
+ this.verifyInlineAndExplicitColumnsSupport(def);
6487
+ return this.ctx.createPFrame(def.map((c) => transformPColumnData(c)));
6488
+ }
6489
+ createPTable(def) {
6490
+ let rawDef;
6491
+ if ("columns" in def) {
6492
+ rawDef = this.patchPTableDef({
6493
+ src: {
6494
+ type: "full",
6495
+ entries: def.columns.map((c) => ({ type: "column", column: c }))
6496
+ },
6497
+ partitionFilters: def.filters ?? [],
6498
+ filters: [],
6499
+ sorting: def.sorting ?? []
6500
+ });
6501
+ } else {
6502
+ rawDef = this.patchPTableDef(def);
6503
+ }
6504
+ this.verifyInlineAndExplicitColumnsSupport(extractAllColumns(rawDef.src));
6505
+ return this.ctx.createPTable(mapPTableDef(rawDef, (po) => transformPColumnData(po)));
5658
6506
  }
5659
6507
  /** @deprecated scheduled for removal from SDK */
5660
- getBlockLabel(e) {
5661
- return this.ctx.getBlockLabel(e);
6508
+ getBlockLabel(blockId) {
6509
+ return this.ctx.getBlockLabel(blockId);
5662
6510
  }
5663
6511
  getCurrentUnstableMarker() {
5664
- if (!(typeof this.ctx.getCurrentUnstableMarker > "u"))
5665
- return this.ctx.getCurrentUnstableMarker();
5666
- }
5667
- }
5668
- const M = "1.29.17";
5669
- function _t(t) {
5670
- return t.__renderLambda === true;
5671
- }
5672
- function ue(t) {
5673
- if (t !== void 0)
5674
- return _t(t) ? t.handle : t;
5675
- }
5676
- class T {
5677
- constructor(e, n2, r, i, s2, o, a) {
5678
- this._renderingMode = e, this._initialArgs = n2, this._initialUiState = r, this._outputs = i, this._inputsValid = s2, this._sections = o, this._title = a;
5679
- }
5680
- static create(e = "Heavy") {
5681
- return new T(
5682
- e,
5683
- void 0,
5684
- {},
5685
- {},
5686
- Z(true),
5687
- Z([]),
5688
- void 0
5689
- );
5690
- }
5691
- output(e, n2, r = {}) {
5692
- if (typeof n2 == "function") {
5693
- const i = `output#${e}`;
5694
- return Y(i, () => n2(new X())), new T(
5695
- this._renderingMode,
5696
- this._initialArgs,
5697
- this._initialUiState,
5698
- {
5699
- ...this._outputs,
5700
- [e]: {
5701
- __renderLambda: true,
5702
- handle: i,
5703
- ...r
5704
- }
5705
- },
5706
- this._inputsValid,
5707
- this._sections,
5708
- this._title
5709
- );
6512
+ return this.ctx.getCurrentUnstableMarker();
6513
+ }
6514
+ logInfo(msg) {
6515
+ this.ctx.logInfo(msg);
6516
+ }
6517
+ logWarn(msg) {
6518
+ this.ctx.logWarn(msg);
6519
+ }
6520
+ logError(msg) {
6521
+ this.ctx.logError(msg);
6522
+ }
6523
+ }
6524
+ var version = "1.42.20";
6525
+ const PlatformaSDKVersion = version;
6526
+ function isConfigLambda(cfgOrFh) {
6527
+ return cfgOrFh.__renderLambda === true;
6528
+ }
6529
+ function downgradeCfgOrLambda(data) {
6530
+ if (data === void 0)
6531
+ return void 0;
6532
+ if (isConfigLambda(data))
6533
+ return data.handle;
6534
+ return data;
6535
+ }
6536
+ const _BlockModel = class _BlockModel {
6537
+ constructor(_renderingMode, _initialArgs, _initialUiState, _outputs, _inputsValid, _sections, _title, _enrichmentTargets, _featureFlags) {
6538
+ __publicField(this, "_renderingMode");
6539
+ __publicField(this, "_initialArgs");
6540
+ __publicField(this, "_initialUiState");
6541
+ __publicField(this, "_outputs");
6542
+ __publicField(this, "_inputsValid");
6543
+ __publicField(this, "_sections");
6544
+ __publicField(this, "_title");
6545
+ __publicField(this, "_enrichmentTargets");
6546
+ __publicField(this, "_featureFlags");
6547
+ this._renderingMode = _renderingMode;
6548
+ this._initialArgs = _initialArgs;
6549
+ this._initialUiState = _initialUiState;
6550
+ this._outputs = _outputs;
6551
+ this._inputsValid = _inputsValid;
6552
+ this._sections = _sections;
6553
+ this._title = _title;
6554
+ this._enrichmentTargets = _enrichmentTargets;
6555
+ this._featureFlags = _featureFlags;
6556
+ }
6557
+ static create(renderingMode = "Heavy") {
6558
+ return new _BlockModel(renderingMode, void 0, {}, {}, getImmediate(true), getImmediate([]), void 0, void 0, { ..._BlockModel.INITIAL_BLOCK_FEATURE_FLAGS });
6559
+ }
6560
+ output(key, cfgOrRf, flags = {}) {
6561
+ if (typeof cfgOrRf === "function") {
6562
+ const handle = `output#${key}`;
6563
+ tryRegisterCallback(handle, () => cfgOrRf(new RenderCtx()));
6564
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, {
6565
+ ...this._outputs,
6566
+ [key]: {
6567
+ __renderLambda: true,
6568
+ handle,
6569
+ ...flags
6570
+ }
6571
+ }, this._inputsValid, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
5710
6572
  } else
5711
- return new T(
5712
- this._renderingMode,
5713
- this._initialArgs,
5714
- this._initialUiState,
5715
- {
5716
- ...this._outputs,
5717
- [e]: n2
5718
- },
5719
- this._inputsValid,
5720
- this._sections,
5721
- this._title
5722
- );
6573
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, {
6574
+ ...this._outputs,
6575
+ [key]: cfgOrRf
6576
+ }, this._inputsValid, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
5723
6577
  }
5724
6578
  /** Shortcut for {@link output} with retentive flag set to true. */
5725
- retentiveOutput(e, n2) {
5726
- return this.output(e, n2, { retentive: true });
5727
- }
5728
- argsValid(e) {
5729
- return typeof e == "function" ? (Y("inputsValid", () => e(new X())), new T(
5730
- this._renderingMode,
5731
- this._initialArgs,
5732
- this._initialUiState,
5733
- this._outputs,
5734
- {
6579
+ retentiveOutput(key, rf) {
6580
+ return this.output(key, rf, { retentive: true });
6581
+ }
6582
+ argsValid(cfgOrRf) {
6583
+ if (typeof cfgOrRf === "function") {
6584
+ tryRegisterCallback("inputsValid", () => cfgOrRf(new RenderCtx()));
6585
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, {
5735
6586
  __renderLambda: true,
5736
6587
  handle: "inputsValid"
5737
- },
5738
- this._sections,
5739
- this._title
5740
- )) : new T(
5741
- this._renderingMode,
5742
- this._initialArgs,
5743
- this._initialUiState,
5744
- this._outputs,
5745
- e,
5746
- this._sections,
5747
- this._title
5748
- );
5749
- }
5750
- sections(e) {
5751
- return Array.isArray(e) ? this.sections(Z(e)) : typeof e == "function" ? (Y("sections", () => e(new X())), new T(
5752
- this._renderingMode,
5753
- this._initialArgs,
5754
- this._initialUiState,
5755
- this._outputs,
5756
- this._inputsValid,
5757
- { __renderLambda: true, handle: "sections" },
5758
- this._title
5759
- )) : new T(
5760
- this._renderingMode,
5761
- this._initialArgs,
5762
- this._initialUiState,
5763
- this._outputs,
5764
- this._inputsValid,
5765
- e,
5766
- this._title
5767
- );
6588
+ }, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
6589
+ } else
6590
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, cfgOrRf, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
6591
+ }
6592
+ sections(arrOrCfgOrRf) {
6593
+ if (Array.isArray(arrOrCfgOrRf)) {
6594
+ return this.sections(getImmediate(arrOrCfgOrRf));
6595
+ } else if (typeof arrOrCfgOrRf === "function") {
6596
+ tryRegisterCallback("sections", () => arrOrCfgOrRf(new RenderCtx()));
6597
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, this._inputsValid, { __renderLambda: true, handle: "sections" }, this._title, this._enrichmentTargets, this._featureFlags);
6598
+ } else
6599
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, this._inputsValid, arrOrCfgOrRf, this._title, this._enrichmentTargets, this._featureFlags);
5768
6600
  }
5769
6601
  /** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
5770
- title(e) {
5771
- return Y("title", () => e(new X())), new T(
5772
- this._renderingMode,
5773
- this._initialArgs,
5774
- this._initialUiState,
5775
- this._outputs,
5776
- this._inputsValid,
5777
- this._sections,
5778
- { __renderLambda: true, handle: "title" }
5779
- );
6602
+ title(rf) {
6603
+ tryRegisterCallback("title", () => rf(new RenderCtx()));
6604
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, this._inputsValid, this._sections, { __renderLambda: true, handle: "title" }, this._enrichmentTargets, this._featureFlags);
5780
6605
  }
5781
6606
  /**
5782
6607
  * Sets initial args for the block, this value must be specified.
5783
6608
  * @deprecated use {@link withArgs}
5784
6609
  * */
5785
- initialArgs(e) {
5786
- return new T(
5787
- this._renderingMode,
5788
- e,
5789
- this._initialUiState,
5790
- this._outputs,
5791
- this._inputsValid,
5792
- this._sections,
5793
- this._title
5794
- );
6610
+ initialArgs(value) {
6611
+ return new _BlockModel(this._renderingMode, value, this._initialUiState, this._outputs, this._inputsValid, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
5795
6612
  }
5796
6613
  /** Sets initial args for the block, this value must be specified. */
5797
- withArgs(e) {
5798
- return new T(
5799
- this._renderingMode,
5800
- e,
5801
- this._initialUiState,
5802
- this._outputs,
5803
- this._inputsValid,
5804
- this._sections,
5805
- this._title
5806
- );
6614
+ withArgs(initialValue) {
6615
+ return new _BlockModel(this._renderingMode, initialValue, this._initialUiState, this._outputs, this._inputsValid, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
5807
6616
  }
5808
6617
  /** Defines type and sets initial value for block UiState. */
5809
- withUiState(e) {
5810
- return new T(
5811
- this._renderingMode,
5812
- this._initialArgs,
5813
- e,
5814
- this._outputs,
5815
- this._inputsValid,
5816
- this._sections,
5817
- this._title
5818
- );
6618
+ withUiState(initialValue) {
6619
+ return new _BlockModel(this._renderingMode, this._initialArgs, initialValue, this._outputs, this._inputsValid, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
6620
+ }
6621
+ /** Sets or overrides feature flags for the block. */
6622
+ withFeatureFlags(flags) {
6623
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, this._inputsValid, this._sections, this._title, this._enrichmentTargets, { ...this._featureFlags, ...flags });
6624
+ }
6625
+ /**
6626
+ * Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.
6627
+ * Influences dependency graph construction.
6628
+ */
6629
+ enriches(lambda) {
6630
+ tryRegisterCallback("enrichmentTargets", lambda);
6631
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, this._inputsValid, this._sections, this._title, { __renderLambda: true, handle: "enrichmentTargets" }, this._featureFlags);
5819
6632
  }
5820
6633
  /** Renders all provided block settings into a pre-configured platforma API
5821
6634
  * instance, that can be used in frontend to interact with block state, and
5822
6635
  * other features provided by the platforma to the block. */
5823
- done() {
5824
- if (this._initialArgs === void 0) throw new Error("Initial arguments not set.");
5825
- const e = {
6636
+ done(apiVersion) {
6637
+ const requiresUIAPIVersion = apiVersion ?? 1;
6638
+ return this.withFeatureFlags({
6639
+ ...this._featureFlags,
6640
+ requiresUIAPIVersion
6641
+ })._done(requiresUIAPIVersion);
6642
+ }
6643
+ _done(apiVersion) {
6644
+ if (this._initialArgs === void 0)
6645
+ throw new Error("Initial arguments not set.");
6646
+ const config = {
5826
6647
  v3: {
5827
- sdkVersion: M,
6648
+ sdkVersion: PlatformaSDKVersion,
5828
6649
  renderingMode: this._renderingMode,
5829
6650
  initialArgs: this._initialArgs,
5830
6651
  initialUiState: this._initialUiState,
5831
6652
  inputsValid: this._inputsValid,
5832
6653
  sections: this._sections,
5833
6654
  title: this._title,
5834
- outputs: this._outputs
6655
+ outputs: this._outputs,
6656
+ enrichmentTargets: this._enrichmentTargets,
6657
+ featureFlags: this._featureFlags
5835
6658
  },
5836
6659
  // fields below are added to allow previous desktop versions read generated configs
5837
- sdkVersion: M,
6660
+ sdkVersion: PlatformaSDKVersion,
5838
6661
  renderingMode: this._renderingMode,
5839
6662
  initialArgs: this._initialArgs,
5840
- inputsValid: ue(this._inputsValid),
5841
- sections: ue(this._sections),
5842
- outputs: Object.fromEntries(
5843
- Object.entries(this._outputs).map(([n2, r]) => [n2, ue(r)])
5844
- )
6663
+ inputsValid: downgradeCfgOrLambda(this._inputsValid),
6664
+ sections: downgradeCfgOrLambda(this._sections),
6665
+ outputs: Object.fromEntries(Object.entries(this._outputs).map(([key, value]) => [key, downgradeCfgOrLambda(value)]))
5845
6666
  };
5846
- return it() ? Te({ sdkVersion: M }) : { config: e };
6667
+ globalThis.platformaApiVersion = apiVersion;
6668
+ if (!isInUI())
6669
+ return { config };
6670
+ else
6671
+ return getPlatformaInstance({ sdkVersion: PlatformaSDKVersion, apiVersion: platformaApiVersion });
5847
6672
  }
5848
- }
5849
- const Et = (t, e) => {
5850
- let n2 = t.toString();
5851
- return e == null || e.forEach((r) => {
5852
- if (r)
5853
- for (const [i, s2] of Object.entries(r))
5854
- n2 += i, n2 += s2;
5855
- }), n2;
5856
6673
  };
5857
- function Ft(t) {
5858
- if (!t.length)
5859
- return [];
5860
- let e = [[]];
5861
- return t.forEach((n2) => {
5862
- const r = [];
5863
- n2.forEach((i) => {
5864
- r.push(...e.map((s2) => [...s2, i]));
5865
- }), e = r;
5866
- }), e;
5867
- }
5868
- function Dt(t, e) {
5869
- const n2 = t.spec.axesSpec.map(p$1);
5870
- return e.spec.axesSpec.map(p$1).every((i) => n2.some((s2) => G(s2, i) && G(i, s2)));
5871
- }
5872
- function Je(t, e) {
5873
- const n2 = t.spec.axesSpec.map(p$1);
5874
- return e.spec.axesSpec.map(p$1).every((i) => n2.some((s2) => G(s2, i)));
5875
- }
5876
- const Ot = "pl7.app/graph/isVirtual", xe = "pl7.app/label";
5877
- function Ce(t, e) {
5878
- const n2 = t.spec.axesSpec.map(p$1), r = e.spec.axesSpec.map(p$1);
5879
- if (Dt(t, e))
5880
- return [];
5881
- if (!Je(t, e))
6674
+ __publicField(_BlockModel, "INITIAL_BLOCK_FEATURE_FLAGS", {
6675
+ supportsLazyState: true,
6676
+ requiresUIAPIVersion: 1,
6677
+ requiresModelAPIVersion: 1
6678
+ });
6679
+ let BlockModel = _BlockModel;
6680
+ function isLabelColumn(column) {
6681
+ return column.axesSpec.length === 1 && column.name === PColumnName.Label;
6682
+ }
6683
+ const colId = (id, domains) => {
6684
+ let wid = id.toString();
6685
+ domains == null ? void 0 : domains.forEach((domain) => {
6686
+ if (domain) {
6687
+ for (const [k, v] of Object.entries(domain)) {
6688
+ wid += k;
6689
+ wid += v;
6690
+ }
6691
+ }
6692
+ });
6693
+ return wid;
6694
+ };
6695
+ function getKeysCombinations(idsLists) {
6696
+ if (!idsLists.length) {
5882
6697
  return [];
5883
- const o = r.map((w2) => n2.filter((p2) => G(p2, w2))), a = Ft(o), l2 = /* @__PURE__ */ new Set(), u2 = /* @__PURE__ */ new Set(), y = a.map((w2) => {
5884
- const p2 = /* @__PURE__ */ new Set();
5885
- return w2.map((f2, h) => {
5886
- const d = e.spec.axesSpec[h].domain, x2 = f2.domain;
5887
- return Object.entries(x2 ?? {}).forEach(([c2, v]) => {
5888
- if ((d == null ? void 0 : d[c2]) === void 0) {
5889
- const g = JSON.stringify([c2, v]);
5890
- p2.add(g), l2.add(g);
6698
+ }
6699
+ let result = [[]];
6700
+ idsLists.forEach((list) => {
6701
+ const nextResult = [];
6702
+ list.forEach((key) => {
6703
+ nextResult.push(...result.map((resultItem) => [...resultItem, key]));
6704
+ });
6705
+ result = nextResult;
6706
+ });
6707
+ return result;
6708
+ }
6709
+ function isLinkerColumn(column) {
6710
+ return !!readAnnotationJson(column, Annotation.IsLinkerColumn);
6711
+ }
6712
+ function getAvailableWithLinkersAxes(linkerColumns, blockAxes) {
6713
+ const linkerMap = LinkerMap.fromColumns(linkerColumns.map(getColumnIdAndSpec));
6714
+ const startKeys = [];
6715
+ const blockAxesGrouped = [...blockAxes.values()].map((axis) => getArrayFromAxisTree(getAxesTree(axis)).map(getAxisId));
6716
+ for (const axesGroupBlock of blockAxesGrouped) {
6717
+ const matched = linkerMap.keyAxesIds.find((keyIds) => keyIds.every((keySourceAxis) => axesGroupBlock.find((axisSpecFromBlock) => matchAxisId(axisSpecFromBlock, keySourceAxis))));
6718
+ if (matched) {
6719
+ startKeys.push(canonicalizeJson(matched));
6720
+ }
6721
+ }
6722
+ const availableKeys = linkerMap.searchAvailableAxesKeys(startKeys);
6723
+ const availableAxes = linkerMap.getAxesListFromKeysList([...availableKeys]);
6724
+ return new Map(availableAxes.map((axisSpec) => {
6725
+ const id = getAxisId(axisSpec);
6726
+ return [canonicalizeJson(id), axisSpec];
6727
+ }));
6728
+ }
6729
+ function enrichCompatible(blockAxes, columns) {
6730
+ const result = [];
6731
+ columns.forEach((column) => {
6732
+ result.push(...getAdditionalColumnsForColumn(blockAxes, column));
6733
+ });
6734
+ return result;
6735
+ }
6736
+ function getAdditionalColumnsForColumn(blockAxes, column) {
6737
+ const columnAxesIds = column.spec.axesSpec.map(getAxisId);
6738
+ if (columnAxesIds.every((id) => blockAxes.has(canonicalizeJson(id)))) {
6739
+ return [column];
6740
+ }
6741
+ const secondaryIdsOptions = columnAxesIds.map((id) => {
6742
+ const result = [];
6743
+ for (const [_, mainId] of blockAxes) {
6744
+ if (matchAxisId(mainId, id) && !matchAxisId(id, mainId)) {
6745
+ result.push(mainId);
6746
+ }
6747
+ }
6748
+ return result;
6749
+ });
6750
+ const secondaryIdsVariants = getKeysCombinations(secondaryIdsOptions);
6751
+ const allAddedDomainValues = /* @__PURE__ */ new Set();
6752
+ const addedNotToAllVariantsDomainValues = /* @__PURE__ */ new Set();
6753
+ const addedByVariantsDomainValues = secondaryIdsVariants.map((idsList) => {
6754
+ const addedSet = /* @__PURE__ */ new Set();
6755
+ idsList.map((axisId, idx) => {
6756
+ const d1 = column.spec.axesSpec[idx].domain;
6757
+ const d2 = axisId.domain;
6758
+ Object.entries(d2 ?? {}).forEach(([key, value]) => {
6759
+ if ((d1 == null ? void 0 : d1[key]) === void 0) {
6760
+ const item = JSON.stringify([key, value]);
6761
+ addedSet.add(item);
6762
+ allAddedDomainValues.add(item);
5891
6763
  }
5892
- }), {
5893
- ...f2,
5894
- annotations: e.spec.axesSpec[h].annotations
6764
+ });
6765
+ return {
6766
+ ...axisId,
6767
+ annotations: column.spec.axesSpec[idx].annotations
5895
6768
  };
5896
- }), p2;
6769
+ });
6770
+ return addedSet;
6771
+ });
6772
+ [...allAddedDomainValues].forEach((addedPart) => {
6773
+ if (addedByVariantsDomainValues.some((s) => !s.has(addedPart))) {
6774
+ addedNotToAllVariantsDomainValues.add(addedPart);
6775
+ }
5897
6776
  });
5898
- return [...l2].forEach((w2) => {
5899
- y.some((p2) => !p2.has(w2)) && u2.add(w2);
5900
- }), a.map((w2, p2) => {
5901
- var c2;
5902
- const f2 = Et(e.id, w2.map((v) => v.domain)), h = ((c2 = e.spec.annotations) == null ? void 0 : c2[xe]) ?? "", d = [...y[p2]].filter((v) => u2.has(v)).sort().map((v) => {
5903
- var g;
5904
- return (g = JSON.parse(v)) == null ? void 0 : g[1];
5905
- }).join(" / "), x2 = {
5906
- ...e.spec.annotations,
5907
- [Ot]: "true"
6777
+ const additionalColumns = secondaryIdsVariants.map((idsList, idx) => {
6778
+ const id = colId(column.id, idsList.map((id2) => id2.domain));
6779
+ const label = readAnnotation(column.spec, Annotation.Label) ?? "";
6780
+ const labelDomainPart = [...addedByVariantsDomainValues[idx]].filter((str) => addedNotToAllVariantsDomainValues.has(str)).sort().map((v) => {
6781
+ var _a;
6782
+ return (_a = JSON.parse(v)) == null ? void 0 : _a[1];
6783
+ }).join(" / ");
6784
+ const annotations = {
6785
+ ...column.spec.annotations,
6786
+ [Annotation.Graph.IsVirtual]: stringifyJson(true)
5908
6787
  };
5909
- return (h || d) && (x2[xe] = h && d ? h + " / " + d : h + d), {
5910
- id: f2,
6788
+ if (label || labelDomainPart) {
6789
+ annotations[Annotation.Label] = label && labelDomainPart ? label + " / " + labelDomainPart : label + labelDomainPart;
6790
+ }
6791
+ return {
6792
+ id,
5911
6793
  spec: {
5912
- ...e.spec,
5913
- axesSpec: w2.map((v, g) => ({
5914
- ...v,
5915
- annotations: e.spec.axesSpec[g].annotations
6794
+ ...column.spec,
6795
+ axesSpec: idsList.map((axisId, idx2) => ({
6796
+ ...axisId,
6797
+ annotations: column.spec.axesSpec[idx2].annotations
5916
6798
  })),
5917
- annotations: x2
6799
+ annotations
5918
6800
  },
5919
- data: e.data
6801
+ data: column.data
5920
6802
  };
5921
6803
  });
6804
+ return [column, ...additionalColumns];
6805
+ }
6806
+ function isColumnReady(c) {
6807
+ let ready = true;
6808
+ if (c.data instanceof TreeNodeAccessor) {
6809
+ ready = ready && c.data.getIsReadyOrError();
6810
+ } else if (isDataInfo(c.data)) {
6811
+ visitDataInfo(c.data, (v) => {
6812
+ ready = ready && v.getIsReadyOrError();
6813
+ });
6814
+ }
6815
+ return ready;
5922
6816
  }
5923
- function Rt(t) {
5924
- const e = [];
5925
- for (let n2 = 0; n2 < t.length; n2++)
5926
- for (let r = n2 + 1; r < t.length; r++) {
5927
- const i = t[n2], s2 = t[r];
5928
- e.push(
5929
- ...Ce(i, s2),
5930
- ...Ce(s2, i)
5931
- );
5932
- }
5933
- return e;
5934
- }
5935
- function kt(t, e) {
5936
- const n2 = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Map();
5937
- t.forEach((s2) => {
5938
- n2.add(s2.id), r.set(Xn(En(s2.spec)), s2);
5939
- });
5940
- const i = /* @__PURE__ */ new Map();
5941
- for (const s2 of e) {
5942
- if (n2.has(s2.id)) continue;
5943
- const o = Xn(En(s2.spec));
5944
- if (!r.has(o)) {
5945
- for (const a of r.values())
5946
- if (Je(a, s2)) {
5947
- i.set(o, s2);
5948
- break;
5949
- }
6817
+ function allColumnsReady(columns) {
6818
+ return columns.every(isColumnReady);
6819
+ }
6820
+ function createPFrameForGraphs(ctx, blockColumns) {
6821
+ if (!blockColumns) {
6822
+ const columns2 = new PColumnCollection();
6823
+ columns2.addColumnProvider(ctx.resultPool);
6824
+ const allColumns = columns2.getColumns(() => true, { dontWaitAllData: true, overrideLabelAnnotation: false }) ?? [];
6825
+ if (!allColumnsReady(allColumns)) {
6826
+ return void 0;
5950
6827
  }
6828
+ const allAxes2 = new Map(allColumns.flatMap((column) => getNormalizedAxesList(column.spec.axesSpec)).map((axisSpec) => {
6829
+ const axisId = getAxisId(axisSpec);
6830
+ return [canonicalizeJson(axisId), axisSpec];
6831
+ }));
6832
+ const extendedColumns2 = enrichCompatible(allAxes2, allColumns);
6833
+ return ctx.createPFrame(extendedColumns2);
6834
+ }
6835
+ if (!allColumnsReady(blockColumns)) {
6836
+ return void 0;
5951
6837
  }
5952
- return [...r.values(), ...i.values()];
5953
- }
5954
- const jt = [
5955
- "Int",
5956
- "Long",
5957
- "Float",
5958
- "Double",
5959
- "String",
5960
- "Bytes"
5961
- ];
5962
- function _n(t, e) {
5963
- if (e === void 0) return;
5964
- const n2 = t.resultPool.getData().entries.map((s2) => s2.obj).filter(q).filter((s2) => jt.includes(s2.spec.valueType)), r = kt(e, n2), i = [...r, ...Rt(r)];
5965
- if (!i.some(
5966
- (s2) => s2.data instanceof I && !s2.data.getIsReadyOrError()
5967
- ))
5968
- return t.createPFrame(i);
5969
- }
5970
- const model = T.create().withArgs({}).withUiState({
6838
+ const columns = new PColumnCollection();
6839
+ columns.addColumnProvider(ctx.resultPool);
6840
+ columns.addColumns(blockColumns);
6841
+ const blockAxes = /* @__PURE__ */ new Map();
6842
+ const allAxes = /* @__PURE__ */ new Map();
6843
+ for (const c of blockColumns) {
6844
+ for (const spec of getNormalizedAxesList(c.spec.axesSpec)) {
6845
+ const aid = getAxisId(spec);
6846
+ blockAxes.set(canonicalizeJson(aid), spec);
6847
+ allAxes.set(canonicalizeJson(aid), spec);
6848
+ }
6849
+ }
6850
+ const linkerColumns = columns.getColumns((spec) => isLinkerColumn(spec)) ?? [];
6851
+ const availableWithLinkersAxes = getAvailableWithLinkersAxes(linkerColumns, blockAxes);
6852
+ for (const item of availableWithLinkersAxes) {
6853
+ blockAxes.set(...item);
6854
+ allAxes.set(...item);
6855
+ }
6856
+ const compatibleWithoutLabels = (columns.getColumns((spec) => spec.axesSpec.some((axisSpec) => {
6857
+ const axisId = getAxisId(axisSpec);
6858
+ for (const selectorAxisSpec of blockAxes.values()) {
6859
+ if (matchAxisId(getAxisId(selectorAxisSpec), axisId)) {
6860
+ return true;
6861
+ }
6862
+ }
6863
+ return false;
6864
+ }), { dontWaitAllData: true, overrideLabelAnnotation: false }) ?? []).filter((column) => !isLabelColumn(column.spec));
6865
+ if (!allColumnsReady(compatibleWithoutLabels)) {
6866
+ return void 0;
6867
+ }
6868
+ for (const c of compatibleWithoutLabels) {
6869
+ for (const spec of getNormalizedAxesList(c.spec.axesSpec)) {
6870
+ const aid = getAxisId(spec);
6871
+ allAxes.set(canonicalizeJson(aid), spec);
6872
+ }
6873
+ }
6874
+ const compatibleLabels = (columns.getColumns((spec) => spec.axesSpec.some((axisSpec) => {
6875
+ const axisId = getAxisId(axisSpec);
6876
+ for (const selectorAxisSpec of allAxes.values()) {
6877
+ if (matchAxisId(getAxisId(selectorAxisSpec), axisId)) {
6878
+ return true;
6879
+ }
6880
+ }
6881
+ return false;
6882
+ }), { dontWaitAllData: true, overrideLabelAnnotation: false }) ?? []).filter((column) => isLabelColumn(column.spec));
6883
+ if (!allColumnsReady(compatibleLabels)) {
6884
+ return void 0;
6885
+ }
6886
+ const compatible = [...compatibleWithoutLabels, ...compatibleLabels];
6887
+ const extendedColumns = enrichCompatible(blockAxes, compatible);
6888
+ return ctx.createPFrame(extendedColumns);
6889
+ }
6890
+ var stringify = { exports: {} };
6891
+ var hasRequiredStringify;
6892
+ function requireStringify() {
6893
+ if (hasRequiredStringify) return stringify.exports;
6894
+ hasRequiredStringify = 1;
6895
+ (function(module2, exports3) {
6896
+ exports3 = module2.exports = stringify2;
6897
+ exports3.getSerialize = serializer;
6898
+ function stringify2(obj, replacer, spaces, cycleReplacer) {
6899
+ return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces);
6900
+ }
6901
+ function serializer(replacer, cycleReplacer) {
6902
+ var stack = [], keys = [];
6903
+ if (cycleReplacer == null) cycleReplacer = function(key, value) {
6904
+ if (stack[0] === value) return "[Circular ~]";
6905
+ return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
6906
+ };
6907
+ return function(key, value) {
6908
+ if (stack.length > 0) {
6909
+ var thisPos = stack.indexOf(this);
6910
+ ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
6911
+ ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
6912
+ if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value);
6913
+ } else stack.push(value);
6914
+ return replacer == null ? value : replacer.call(this, key, value);
6915
+ };
6916
+ }
6917
+ })(stringify, stringify.exports);
6918
+ return stringify.exports;
6919
+ }
6920
+ requireStringify();
6921
+ const BasePlErrorLike = z.object({
6922
+ type: z.literal("PlError"),
6923
+ name: z.string(),
6924
+ message: z.string(),
6925
+ /** The message with all details needed for SDK developers. */
6926
+ fullMessage: z.string().optional(),
6927
+ stack: z.string().optional()
6928
+ });
6929
+ const PlErrorLike = BasePlErrorLike.extend({
6930
+ cause: z.lazy(() => ErrorLike).optional(),
6931
+ errors: z.lazy(() => ErrorLike.array()).optional()
6932
+ });
6933
+ const BaseStandardErrorLike = z.object({
6934
+ type: z.literal("StandardError"),
6935
+ name: z.string(),
6936
+ message: z.string(),
6937
+ stack: z.string().optional()
6938
+ });
6939
+ const StandardErrorLike = BaseStandardErrorLike.extend({
6940
+ cause: z.lazy(() => ErrorLike).optional(),
6941
+ errors: z.lazy(() => ErrorLike.array()).optional()
6942
+ });
6943
+ const ErrorLike = z.union([StandardErrorLike, PlErrorLike]);
6944
+ const baseErrorShape = z.object({
6945
+ name: z.string(),
6946
+ message: z.string(),
6947
+ fullMessage: z.string().optional(),
6948
+ stack: z.string().optional()
6949
+ });
6950
+ const ErrorShape = baseErrorShape.extend({
6951
+ cause: z.lazy(() => ErrorShape).optional(),
6952
+ errors: z.lazy(() => ErrorShape.array()).optional()
6953
+ });
6954
+ const model = BlockModel.create().withArgs({
6955
+ scChain: "A",
6956
+ allele: false
6957
+ }).withUiState({
5971
6958
  blockTitle: "V/J Usage",
5972
6959
  weightedFlag: true,
5973
6960
  vUsagePlotState: {
5974
6961
  title: "V Usage",
5975
- template: "heatmap",
5976
- currentTab: "settings"
6962
+ template: "heatmapClustered",
6963
+ currentTab: "settings",
6964
+ layersSettings: {
6965
+ heatmapClustered: {
6966
+ normalizationDirection: null
6967
+ }
6968
+ }
5977
6969
  },
5978
6970
  jUsagePlotState: {
5979
6971
  title: "V Usage",
5980
- template: "heatmap",
5981
- currentTab: null
6972
+ template: "heatmapClustered",
6973
+ currentTab: null,
6974
+ layersSettings: {
6975
+ heatmapClustered: {
6976
+ normalizationDirection: null
6977
+ }
6978
+ }
5982
6979
  },
5983
6980
  vjUsagePlotState: {
5984
6981
  title: "V/J Usage",
5985
- template: "heatmap",
5986
- currentTab: null
5987
- }
5988
- }).argsValid(
5989
- (ctx) => ctx.args.vGeneRef !== void 0 && ctx.args.jGeneRef !== void 0 && ctx.args.abundanceRef !== void 0
5990
- ).output("vGeneOptions", (ctx) => ctx.resultPool.getOptions(
5991
- (c2) => {
5992
- var _a;
5993
- return f(c2) && c2.valueType === "String" && (c2.name === "pl7.app/vdj/geneHit" || c2.name === "pl7.app/vdj/geneHitWithAllele") && ((_a = c2.domain) == null ? void 0 : _a["pl7.app/vdj/reference"]) === "VGene";
5994
- }
5995
- )).output("jGeneOptions", (ctx) => {
5996
- const inputRef = ctx.args.vGeneRef;
5997
- if (inputRef === void 0) return void 0;
5998
- const vGeneSpec = ctx.resultPool.getPColumnSpecByRef(inputRef);
5999
- if (vGeneSpec === void 0) return void 0;
6000
- return ctx.resultPool.getCanonicalOptions({ main: inputRef }, [
6001
- {
6002
- axes: [{ anchor: "main", idx: 0 }],
6003
- name: vGeneSpec.name,
6004
- domain: {
6005
- "pl7.app/vdj/reference": "JGene",
6006
- "pl7.app/vdj/scClonotypeChain": { anchor: "main" },
6007
- "pl7.app/vdj/scClonotypeChain/index": { anchor: "main" }
6982
+ template: "heatmapClustered",
6983
+ currentTab: null,
6984
+ layersSettings: {
6985
+ heatmapClustered: {
6986
+ normalizationDirection: null
6008
6987
  }
6009
6988
  }
6010
- ], { ignoreMissingDomains: true });
6011
- }).output("abundanceOptions", (ctx) => {
6012
- const inputRef = ctx.args.vGeneRef;
6013
- if (inputRef === void 0) return void 0;
6014
- return ctx.resultPool.getCanonicalOptions(
6015
- { main: inputRef },
6989
+ }
6990
+ }).argsValid((ctx) => ctx.args.datasetRef !== void 0).output(
6991
+ "datasetOptions",
6992
+ (ctx) => ctx.resultPool.getOptions(
6993
+ [{
6994
+ axes: [
6995
+ { name: "pl7.app/sampleId" },
6996
+ { name: "pl7.app/vdj/clonotypeKey" }
6997
+ ],
6998
+ annotations: { "pl7.app/isAnchor": "true" }
6999
+ }, {
7000
+ axes: [
7001
+ { name: "pl7.app/sampleId" },
7002
+ { name: "pl7.app/vdj/scClonotypeKey" }
7003
+ ],
7004
+ annotations: { "pl7.app/isAnchor": "true" }
7005
+ }],
6016
7006
  {
6017
- axes: [{
6018
- /* sampleId */
6019
- }, { anchor: "main", idx: 0 }],
6020
- annotations: {
6021
- "pl7.app/isAbundance": "true",
6022
- "pl7.app/abundance/normalized": "false"
6023
- }
7007
+ // suppress native label of the column (e.g. "Number of Reads") to show only the dataset label
7008
+ label: { includeNativeLabel: false }
6024
7009
  }
6025
- );
7010
+ )
7011
+ ).output("datasetSpec", (ctx) => {
7012
+ if (ctx.args.datasetRef === void 0) {
7013
+ return void 0;
7014
+ }
7015
+ return ctx.resultPool.getPColumnSpecByRef(ctx.args.datasetRef);
6026
7016
  }).output("pf", (ctx) => {
6027
7017
  var _a, _b;
6028
7018
  const pCols = (_b = (_a = ctx.outputs) == null ? void 0 : _a.resolve("pf")) == null ? void 0 : _b.getPColumns();
6029
7019
  if (pCols === void 0) {
6030
7020
  return void 0;
6031
7021
  }
6032
- return _n(ctx, pCols);
7022
+ return createPFrameForGraphs(ctx, pCols);
6033
7023
  }).output("isRunning", (ctx) => {
6034
7024
  var _a;
6035
7025
  return ((_a = ctx.outputs) == null ? void 0 : _a.getIsReadyOrError()) === false;