@platforma-open/milaboratories.immune-assay-data.model 1.3.0 → 1.4.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,17 +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";
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;
27
+ }
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);
49
+ }
50
+ };
51
+ futureResolves.set(handle, []);
52
+ }
53
+ futureResolves.get(handle).push(onResolve);
54
+ }
5
55
  var util;
6
56
  (function(util2) {
7
57
  util2.assertEqual = (val) => val;
8
58
  function assertIs(_arg) {
9
59
  }
10
60
  util2.assertIs = assertIs;
11
- function assertNever(_x) {
61
+ function assertNever2(_x) {
12
62
  throw new Error();
13
63
  }
14
- util2.assertNever = assertNever;
64
+ util2.assertNever = assertNever2;
15
65
  util2.arrayToEnum = (items) => {
16
66
  const obj = {};
17
67
  for (const item of items) {
@@ -20,10 +70,10 @@
20
70
  return obj;
21
71
  };
22
72
  util2.getValidEnumValues = (obj) => {
23
- 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");
24
74
  const filtered = {};
25
- for (const k2 of validKeys) {
26
- filtered[k2] = obj[k2];
75
+ for (const k of validKeys) {
76
+ filtered[k] = obj[k];
27
77
  }
28
78
  return util2.objectValues(filtered);
29
79
  };
@@ -368,7 +418,7 @@
368
418
  };
369
419
  }
370
420
  let errorMessage = "";
371
- const maps = errorMaps.filter((m2) => !!m2).slice().reverse();
421
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
372
422
  for (const map of maps) {
373
423
  errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
374
424
  }
@@ -409,12 +459,12 @@
409
459
  }
410
460
  static mergeArray(status, results) {
411
461
  const arrayValue = [];
412
- for (const s2 of results) {
413
- if (s2.status === "aborted")
462
+ for (const s of results) {
463
+ if (s.status === "aborted")
414
464
  return INVALID;
415
- if (s2.status === "dirty")
465
+ if (s.status === "dirty")
416
466
  status.dirty();
417
- arrayValue.push(s2.value);
467
+ arrayValue.push(s.value);
418
468
  }
419
469
  return { status: status.value, value: arrayValue };
420
470
  }
@@ -458,11 +508,11 @@
458
508
  const isDirty = (x) => x.status === "dirty";
459
509
  const isValid = (x) => x.status === "valid";
460
510
  const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
461
- function __classPrivateFieldGet(receiver, state, kind, f2) {
511
+ function __classPrivateFieldGet(receiver, state, kind, f) {
462
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");
463
513
  return state.get(receiver);
464
514
  }
465
- function __classPrivateFieldSet(receiver, state, value, kind, f2) {
515
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
466
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");
467
517
  return state.set(receiver, value), value;
468
518
  }
@@ -816,11 +866,11 @@
816
866
  regex = `${regex}(${opts.join("|")})`;
817
867
  return new RegExp(`^${regex}$`);
818
868
  }
819
- function isValidIP(ip, version) {
820
- if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
869
+ function isValidIP(ip, version2) {
870
+ if ((version2 === "v4" || !version2) && ipv4Regex.test(ip)) {
821
871
  return true;
822
872
  }
823
- if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
873
+ if ((version2 === "v6" || !version2) && ipv6Regex.test(ip)) {
824
874
  return true;
825
875
  }
826
876
  return false;
@@ -3069,7 +3119,7 @@
3069
3119
  });
3070
3120
  }
3071
3121
  const params = { errorMap: ctx.common.contextualErrorMap };
3072
- const fn2 = ctx.data;
3122
+ const fn = ctx.data;
3073
3123
  if (this._def.returns instanceof ZodPromise) {
3074
3124
  const me = this;
3075
3125
  return OK(async function(...args) {
@@ -3078,7 +3128,7 @@
3078
3128
  error.addIssue(makeArgsIssue(args, e));
3079
3129
  throw error;
3080
3130
  });
3081
- const result = await Reflect.apply(fn2, this, parsedArgs);
3131
+ const result = await Reflect.apply(fn, this, parsedArgs);
3082
3132
  const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
3083
3133
  error.addIssue(makeReturnsIssue(result, e));
3084
3134
  throw error;
@@ -3092,7 +3142,7 @@
3092
3142
  if (!parsedArgs.success) {
3093
3143
  throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3094
3144
  }
3095
- const result = Reflect.apply(fn2, this, parsedArgs.data);
3145
+ const result = Reflect.apply(fn, this, parsedArgs.data);
3096
3146
  const parsedReturns = me._def.returns.safeParse(result, params);
3097
3147
  if (!parsedReturns.success) {
3098
3148
  throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
@@ -3697,10 +3747,10 @@
3697
3747
  return ZodAny.create().superRefine((data, ctx) => {
3698
3748
  var _a, _b;
3699
3749
  if (!check(data)) {
3700
- const p2 = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
3701
- const _fatal = (_b = (_a = p2.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
3702
- const p22 = typeof p2 === "string" ? { message: p2 } : p2;
3703
- 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 });
3704
3754
  }
3705
3755
  });
3706
3756
  return ZodAny.create();
@@ -3798,7 +3848,7 @@
3798
3848
  date: (arg) => ZodDate.create({ ...arg, coerce: true })
3799
3849
  };
3800
3850
  const NEVER = INVALID;
3801
- var z$1 = /* @__PURE__ */ Object.freeze({
3851
+ var z = /* @__PURE__ */ Object.freeze({
3802
3852
  __proto__: null,
3803
3853
  defaultErrorMap: errorMap,
3804
3854
  setErrorMap,
@@ -3914,281 +3964,439 @@
3914
3964
  quotelessJson,
3915
3965
  ZodError
3916
3966
  });
3917
- function getDefaultExportFromCjs(x) {
3918
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
3919
- }
3920
- var canonicalize;
3921
- var hasRequiredCanonicalize;
3922
- function requireCanonicalize() {
3923
- if (hasRequiredCanonicalize) return canonicalize;
3924
- hasRequiredCanonicalize = 1;
3925
- canonicalize = function serialize(object) {
3926
- if (typeof object === "number" && isNaN(object)) {
3927
- throw new Error("NaN is not allowed");
3928
- }
3929
- if (typeof object === "number" && !isFinite(object)) {
3930
- throw new Error("Infinity is not allowed");
3931
- }
3932
- if (object === null || typeof object !== "object") {
3933
- return JSON.stringify(object);
3934
- }
3935
- if (object.toJSON instanceof Function) {
3936
- return serialize(object.toJSON());
3937
- }
3938
- if (Array.isArray(object)) {
3939
- const values2 = object.reduce((t, cv, ci) => {
3940
- const comma = ci === 0 ? "" : ",";
3941
- const value = cv === void 0 || typeof cv === "symbol" ? null : cv;
3942
- return `${t}${comma}${serialize(value)}`;
3943
- }, "");
3944
- return `[${values2}]`;
3945
- }
3946
- const values = Object.keys(object).sort().reduce((t, cv) => {
3947
- if (object[cv] === void 0 || typeof object[cv] === "symbol") {
3948
- return t;
3949
- }
3950
- const comma = t.length === 0 ? "" : ",";
3951
- return `${t}${comma}${serialize(cv)}:${serialize(object[cv])}`;
3952
- }, "");
3953
- return `{${values}}`;
3954
- };
3955
- return canonicalize;
3956
- }
3957
- var canonicalizeExports = requireCanonicalize();
3958
- const Re = /* @__PURE__ */ getDefaultExportFromCjs(canonicalizeExports);
3959
- var B$1 = Object.defineProperty;
3960
- var j = (n2, e, t) => e in n2 ? B$1(n2, e, { enumerable: true, configurable: true, writable: true, value: t }) : n2[e] = t;
3961
- var l$1 = (n2, e, t) => j(n2, typeof e != "symbol" ? e + "" : e, t);
3962
- z$1.object({
3967
+ z.object({
3963
3968
  /** Included left border. */
3964
- from: z$1.number(),
3969
+ from: z.number().min(0),
3965
3970
  /** Excluded right border. */
3966
- to: z$1.number()
3971
+ to: z.number().min(1)
3967
3972
  });
3968
- function w(n2) {
3969
- throw new Error("Unexpected object: " + n2);
3973
+ function assertNever(x) {
3974
+ throw new Error("Unexpected object: " + x);
3975
+ }
3976
+ function uniqueBy(array, makeId) {
3977
+ return [...new Map(array.map((e) => [makeId(e), e])).values()];
3970
3978
  }
3971
- function En(n2) {
3972
- if (!n2 || typeof n2 != "object")
3979
+ function isDataInfo(value) {
3980
+ if (!value || typeof value !== "object") {
3973
3981
  return false;
3974
- const e = n2;
3975
- if (!("type" in e))
3982
+ }
3983
+ const data = value;
3984
+ if (!("type" in data)) {
3976
3985
  return false;
3977
- switch (e.type) {
3986
+ }
3987
+ switch (data.type) {
3978
3988
  case "Json":
3979
- return typeof e.keyLength == "number" && e.data !== void 0 && typeof e.data == "object";
3989
+ return typeof data.keyLength === "number" && data.data !== void 0 && typeof data.data === "object";
3980
3990
  case "JsonPartitioned":
3981
- return typeof e.partitionKeyLength == "number" && e.parts !== void 0 && typeof e.parts == "object";
3982
3991
  case "BinaryPartitioned":
3983
- return typeof e.partitionKeyLength == "number" && e.parts !== void 0 && typeof e.parts == "object";
3992
+ case "ParquetPartitioned":
3993
+ return typeof data.partitionKeyLength === "number" && data.parts !== void 0 && typeof data.parts === "object";
3984
3994
  default:
3985
3995
  return false;
3986
3996
  }
3987
3997
  }
3988
- function Nn(n2, e) {
3989
- if (n2 !== void 0)
3990
- switch (n2.type) {
3991
- case "Json":
3992
- return n2;
3993
- case "JsonPartitioned": {
3994
- const t = {};
3995
- for (const [r, o] of Object.entries(n2.parts))
3996
- t[r] = e(o);
3997
- return {
3998
- ...n2,
3999
- parts: t
4000
- };
3998
+ function mapDataInfo(dataInfo, mapFn) {
3999
+ if (dataInfo === void 0) {
4000
+ return void 0;
4001
+ }
4002
+ switch (dataInfo.type) {
4003
+ case "Json":
4004
+ return dataInfo;
4005
+ case "JsonPartitioned": {
4006
+ const newParts = {};
4007
+ for (const [key, blob] of Object.entries(dataInfo.parts)) {
4008
+ newParts[key] = mapFn(blob);
4001
4009
  }
4002
- case "BinaryPartitioned": {
4003
- const t = {};
4004
- for (const [r, o] of Object.entries(n2.parts))
4005
- t[r] = {
4006
- index: e(o.index),
4007
- values: e(o.values)
4008
- };
4009
- return {
4010
- ...n2,
4011
- parts: t
4010
+ return {
4011
+ ...dataInfo,
4012
+ parts: newParts
4013
+ };
4014
+ }
4015
+ case "BinaryPartitioned": {
4016
+ const newParts = {};
4017
+ for (const [key, chunk] of Object.entries(dataInfo.parts)) {
4018
+ newParts[key] = {
4019
+ index: mapFn(chunk.index),
4020
+ values: mapFn(chunk.values)
4012
4021
  };
4013
4022
  }
4023
+ return {
4024
+ ...dataInfo,
4025
+ parts: newParts
4026
+ };
4014
4027
  }
4028
+ case "ParquetPartitioned": {
4029
+ const newParts = {};
4030
+ for (const [key, blob] of Object.entries(dataInfo.parts)) {
4031
+ newParts[key] = mapFn(blob);
4032
+ }
4033
+ return {
4034
+ ...dataInfo,
4035
+ parts: newParts
4036
+ };
4037
+ }
4038
+ }
4015
4039
  }
4016
- function K(n2) {
4017
- if (!n2 || typeof n2 != "object")
4040
+ function isDataInfoEntries(value) {
4041
+ if (!value || typeof value !== "object") {
4018
4042
  return false;
4019
- const e = n2;
4020
- if (!("type" in e))
4043
+ }
4044
+ const data = value;
4045
+ if (!("type" in data)) {
4021
4046
  return false;
4022
- switch (e.type) {
4047
+ }
4048
+ switch (data.type) {
4023
4049
  case "Json":
4024
- return typeof e.keyLength == "number" && Array.isArray(e.data);
4050
+ return typeof data.keyLength === "number" && Array.isArray(data.data);
4025
4051
  case "JsonPartitioned":
4026
- return typeof e.partitionKeyLength == "number" && Array.isArray(e.parts);
4027
4052
  case "BinaryPartitioned":
4028
- return typeof e.partitionKeyLength == "number" && Array.isArray(e.parts);
4053
+ case "ParquetPartitioned":
4054
+ return typeof data.partitionKeyLength === "number" && Array.isArray(data.parts);
4029
4055
  default:
4030
4056
  return false;
4031
4057
  }
4032
4058
  }
4033
- function Sn(n2) {
4034
- return K(n2) ? n2.type === "JsonPartitioned" || n2.type === "BinaryPartitioned" : false;
4059
+ function isPartitionedDataInfoEntries(value) {
4060
+ if (!isDataInfoEntries(value))
4061
+ return false;
4062
+ switch (value.type) {
4063
+ case "JsonPartitioned":
4064
+ case "BinaryPartitioned":
4065
+ case "ParquetPartitioned":
4066
+ return true;
4067
+ default:
4068
+ return false;
4069
+ }
4035
4070
  }
4036
- function Cn(n2) {
4037
- switch (n2.type) {
4038
- case "Json": {
4039
- const e = Object.entries(n2.data).map(([t, r]) => ({ key: JSON.parse(t), value: r }));
4071
+ function dataInfoToEntries(dataInfo) {
4072
+ switch (dataInfo.type) {
4073
+ case "Json":
4040
4074
  return {
4041
4075
  type: "Json",
4042
- keyLength: n2.keyLength,
4043
- data: e
4076
+ keyLength: dataInfo.keyLength,
4077
+ data: Object.entries(dataInfo.data).map(([keyStr, value]) => {
4078
+ const key = JSON.parse(keyStr);
4079
+ return { key, value };
4080
+ })
4044
4081
  };
4045
- }
4046
- case "JsonPartitioned": {
4047
- const e = Object.entries(n2.parts).map(([t, r]) => ({ key: JSON.parse(t), value: r }));
4082
+ case "JsonPartitioned":
4048
4083
  return {
4049
4084
  type: "JsonPartitioned",
4050
- partitionKeyLength: n2.partitionKeyLength,
4051
- parts: e
4085
+ partitionKeyLength: dataInfo.partitionKeyLength,
4086
+ parts: Object.entries(dataInfo.parts).map(([keyStr, blob]) => {
4087
+ const key = JSON.parse(keyStr);
4088
+ return { key, value: blob };
4089
+ })
4052
4090
  };
4053
- }
4054
- case "BinaryPartitioned": {
4055
- const e = Object.entries(n2.parts).map(([t, r]) => ({ key: JSON.parse(t), value: r }));
4091
+ case "BinaryPartitioned":
4056
4092
  return {
4057
4093
  type: "BinaryPartitioned",
4058
- partitionKeyLength: n2.partitionKeyLength,
4059
- parts: e
4094
+ partitionKeyLength: dataInfo.partitionKeyLength,
4095
+ parts: Object.entries(dataInfo.parts).map(([keyStr, chunk]) => {
4096
+ const key = JSON.parse(keyStr);
4097
+ return { key, value: chunk };
4098
+ })
4060
4099
  };
4061
- }
4100
+ case "ParquetPartitioned":
4101
+ return {
4102
+ type: "ParquetPartitioned",
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
+ })
4108
+ };
4109
+ default:
4110
+ assertNever(dataInfo);
4062
4111
  }
4063
4112
  }
4064
- function Jn(n2) {
4065
- switch (n2.type) {
4066
- case "Json": {
4067
- const e = {};
4068
- for (const t of n2.data)
4069
- e[JSON.stringify(t.key)] = t.value;
4113
+ function entriesToDataInfo(dataInfoEntries) {
4114
+ switch (dataInfoEntries.type) {
4115
+ case "Json":
4070
4116
  return {
4071
4117
  type: "Json",
4072
- keyLength: n2.keyLength,
4073
- data: e
4118
+ keyLength: dataInfoEntries.keyLength,
4119
+ data: Object.fromEntries(dataInfoEntries.data.map(({ key, value }) => [JSON.stringify(key), value]))
4074
4120
  };
4075
- }
4076
- case "JsonPartitioned": {
4077
- const e = {};
4078
- for (const t of n2.parts)
4079
- e[JSON.stringify(t.key)] = t.value;
4121
+ case "JsonPartitioned":
4080
4122
  return {
4081
4123
  type: "JsonPartitioned",
4082
- partitionKeyLength: n2.partitionKeyLength,
4083
- parts: e
4124
+ partitionKeyLength: dataInfoEntries.partitionKeyLength,
4125
+ parts: Object.fromEntries(dataInfoEntries.parts.map(({ key, value }) => [JSON.stringify(key), value]))
4084
4126
  };
4085
- }
4086
- case "BinaryPartitioned": {
4087
- const e = {};
4088
- for (const t of n2.parts)
4089
- e[JSON.stringify(t.key)] = t.value;
4127
+ case "BinaryPartitioned":
4090
4128
  return {
4091
4129
  type: "BinaryPartitioned",
4092
- partitionKeyLength: n2.partitionKeyLength,
4093
- parts: e
4130
+ partitionKeyLength: dataInfoEntries.partitionKeyLength,
4131
+ parts: Object.fromEntries(dataInfoEntries.parts.map(({ key, value }) => [JSON.stringify(key), value]))
4132
+ };
4133
+ case "ParquetPartitioned":
4134
+ return {
4135
+ type: "ParquetPartitioned",
4136
+ partitionKeyLength: dataInfoEntries.partitionKeyLength,
4137
+ parts: Object.fromEntries(dataInfoEntries.parts.map(({ key, value }) => [JSON.stringify(key), value]))
4094
4138
  };
4139
+ default:
4140
+ assertNever(dataInfoEntries);
4141
+ }
4142
+ }
4143
+ function stringifyValue(value) {
4144
+ if (typeof value === "string") {
4145
+ return `String value was thrown: ${value}`;
4146
+ }
4147
+ if (value && typeof value === "object") {
4148
+ try {
4149
+ return `Plain object was thrown: ${JSON.stringify(value)}`;
4150
+ } catch (jsonError) {
4151
+ const errorMessage = jsonError instanceof Error ? jsonError.message : String(jsonError);
4152
+ return `Non-serializable object was thrown (JSON.stringify failed: ${errorMessage}): ${String(value)}`;
4095
4153
  }
4096
4154
  }
4155
+ return String(`Non-Error value (${typeof value}) was thrown: ${value}`);
4097
4156
  }
4098
- function Fn(n2) {
4157
+ function ensureError(value) {
4158
+ if (value instanceof Error) {
4159
+ return value;
4160
+ }
4161
+ return new Error(stringifyValue(value));
4162
+ }
4163
+ function getDefaultExportFromCjs(x) {
4164
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
4165
+ }
4166
+ var canonicalize$1;
4167
+ var hasRequiredCanonicalize;
4168
+ function requireCanonicalize() {
4169
+ if (hasRequiredCanonicalize) return canonicalize$1;
4170
+ hasRequiredCanonicalize = 1;
4171
+ canonicalize$1 = function serialize(object) {
4172
+ if (typeof object === "number" && isNaN(object)) {
4173
+ throw new Error("NaN is not allowed");
4174
+ }
4175
+ if (typeof object === "number" && !isFinite(object)) {
4176
+ throw new Error("Infinity is not allowed");
4177
+ }
4178
+ if (object === null || typeof object !== "object") {
4179
+ return JSON.stringify(object);
4180
+ }
4181
+ if (object.toJSON instanceof Function) {
4182
+ return serialize(object.toJSON());
4183
+ }
4184
+ if (Array.isArray(object)) {
4185
+ const values2 = object.reduce((t, cv, ci) => {
4186
+ const comma = ci === 0 ? "" : ",";
4187
+ const value = cv === void 0 || typeof cv === "symbol" ? null : cv;
4188
+ return `${t}${comma}${serialize(value)}`;
4189
+ }, "");
4190
+ return `[${values2}]`;
4191
+ }
4192
+ const values = Object.keys(object).sort().reduce((t, cv) => {
4193
+ if (object[cv] === void 0 || typeof object[cv] === "symbol") {
4194
+ return t;
4195
+ }
4196
+ const comma = t.length === 0 ? "" : ",";
4197
+ return `${t}${comma}${serialize(cv)}:${serialize(object[cv])}`;
4198
+ }, "");
4199
+ return `{${values}}`;
4200
+ };
4201
+ return canonicalize$1;
4202
+ }
4203
+ var canonicalizeExports = requireCanonicalize();
4204
+ const canonicalize = /* @__PURE__ */ getDefaultExportFromCjs(canonicalizeExports);
4205
+ function canonicalizeJson(value) {
4206
+ return canonicalize(value);
4207
+ }
4208
+ function parseJson(value) {
4209
+ return JSON.parse(value);
4210
+ }
4211
+ function readMetadata(metadata, key) {
4212
+ return metadata == null ? void 0 : metadata[key];
4213
+ }
4214
+ function readMetadataJsonOrThrow(metadata, metadataJson, key, methodNameInError = "readMetadataJsonOrThrow") {
4215
+ const json = readMetadata(metadata, key);
4216
+ if (json === void 0)
4217
+ return void 0;
4218
+ const schema = metadataJson[key];
4219
+ try {
4220
+ const value = JSON.parse(json);
4221
+ return schema.parse(value);
4222
+ } catch (error) {
4223
+ throw new Error(`${methodNameInError} failed, key: ${String(key)}, value: ${json}, error: ${ensureError(error)}`);
4224
+ }
4225
+ }
4226
+ function readMetadataJson(metadata, metadataJson, key) {
4227
+ try {
4228
+ return readMetadataJsonOrThrow(metadata, metadataJson, key);
4229
+ } catch {
4230
+ return void 0;
4231
+ }
4232
+ }
4233
+ const Annotation = {
4234
+ DiscreteValues: "pl7.app/discreteValues",
4235
+ Graph: {
4236
+ IsVirtual: "pl7.app/graph/isVirtual"
4237
+ },
4238
+ HideDataFromUi: "pl7.app/hideDataFromUi",
4239
+ HideDataFromGraphs: "pl7.app/hideDataFromGraphs",
4240
+ IsLinkerColumn: "pl7.app/isLinkerColumn",
4241
+ Label: "pl7.app/label",
4242
+ Max: "pl7.app/max",
4243
+ Min: "pl7.app/min",
4244
+ Parents: "pl7.app/parents",
4245
+ Sequence: {
4246
+ Annotation: {
4247
+ Mapping: "pl7.app/sequence/annotation/mapping"
4248
+ },
4249
+ IsAnnotation: "pl7.app/sequence/isAnnotation"
4250
+ },
4251
+ Table: {
4252
+ OrderPriority: "pl7.app/table/orderPriority",
4253
+ Visibility: "pl7.app/table/visibility"
4254
+ },
4255
+ Trace: "pl7.app/trace"
4256
+ };
4257
+ const AnnotationJson = {
4258
+ [Annotation.DiscreteValues]: z.array(z.string()).or(z.array(z.number())),
4259
+ [Annotation.Graph.IsVirtual]: z.boolean(),
4260
+ [Annotation.HideDataFromUi]: z.boolean(),
4261
+ [Annotation.HideDataFromGraphs]: z.boolean(),
4262
+ [Annotation.IsLinkerColumn]: z.boolean(),
4263
+ [Annotation.Max]: z.number(),
4264
+ [Annotation.Min]: z.number(),
4265
+ [Annotation.Parents]: z.array(z.string()),
4266
+ [Annotation.Sequence.Annotation.Mapping]: z.record(z.string(), z.string()),
4267
+ [Annotation.Sequence.IsAnnotation]: z.boolean(),
4268
+ [Annotation.Table.OrderPriority]: z.number(),
4269
+ [Annotation.Trace]: z.record(z.string(), z.unknown())
4270
+ };
4271
+ function readAnnotation(spec, key) {
4272
+ return readMetadata(spec == null ? void 0 : spec.annotations, key);
4273
+ }
4274
+ function readAnnotationJson(spec, key) {
4275
+ return readMetadataJson(spec == null ? void 0 : spec.annotations, AnnotationJson, key);
4276
+ }
4277
+ const PColumnName = {
4278
+ Label: "pl7.app/label"
4279
+ };
4280
+ function getColumnIdAndSpec(column) {
4099
4281
  return {
4100
- columnId: n2.id,
4101
- spec: n2.spec
4282
+ columnId: column.id,
4283
+ spec: column.spec
4102
4284
  };
4103
4285
  }
4104
- function p$1(n2) {
4105
- const { type: e, name: t, domain: r } = n2, o = { type: e, name: t };
4106
- return r && Object.entries(r).length > 0 && Object.assign(o, { domain: r }), o;
4286
+ function getAxisId(spec) {
4287
+ const { type, name, domain } = spec;
4288
+ const result = { type, name };
4289
+ if (domain && Object.entries(domain).length > 0) {
4290
+ Object.assign(result, { domain });
4291
+ }
4292
+ return result;
4107
4293
  }
4108
- function J(n2) {
4109
- return n2.map(p$1);
4294
+ function getAxesId(spec) {
4295
+ return spec.map(getAxisId);
4110
4296
  }
4111
- function Rn(n2) {
4112
- return Re(p$1(n2));
4297
+ function canonicalizeAxisId(id) {
4298
+ return canonicalizeJson(getAxisId(id));
4113
4299
  }
4114
- function Y$1(n2, e) {
4115
- if (n2 === void 0) return e === void 0;
4116
- if (e === void 0) return true;
4117
- for (const t in e)
4118
- if (n2[t] !== e[t]) return false;
4300
+ function matchDomain$1(query, target) {
4301
+ if (query === void 0)
4302
+ return target === void 0;
4303
+ if (target === void 0)
4304
+ return true;
4305
+ for (const k in target) {
4306
+ if (query[k] !== target[k])
4307
+ return false;
4308
+ }
4119
4309
  return true;
4120
4310
  }
4121
- function Z$1(n2, e) {
4122
- return n2.name === e.name && Y$1(n2.domain, e.domain);
4311
+ function matchAxisId(query, target) {
4312
+ return query.name === target.name && matchDomain$1(query.domain, target.domain);
4123
4313
  }
4124
- function Un(n2, e) {
4125
- return { ...n2, src: h(n2.src, e) };
4314
+ function mapPTableDef(def, cb) {
4315
+ return { ...def, src: mapJoinEntry(def.src, cb) };
4126
4316
  }
4127
- function h(n2, e) {
4128
- switch (n2.type) {
4317
+ function mapJoinEntry(entry, cb) {
4318
+ switch (entry.type) {
4129
4319
  case "column":
4130
4320
  return {
4131
4321
  type: "column",
4132
- column: e(n2.column)
4322
+ column: cb(entry.column)
4133
4323
  };
4134
4324
  case "slicedColumn":
4135
4325
  return {
4136
4326
  type: "slicedColumn",
4137
- column: e(n2.column),
4138
- newId: n2.newId,
4139
- axisFilters: n2.axisFilters
4327
+ column: cb(entry.column),
4328
+ newId: entry.newId,
4329
+ axisFilters: entry.axisFilters
4330
+ };
4331
+ case "artificialColumn":
4332
+ return {
4333
+ type: "artificialColumn",
4334
+ column: cb(entry.column),
4335
+ newId: entry.newId,
4336
+ axesIndices: entry.axesIndices
4140
4337
  };
4141
4338
  case "inlineColumn":
4142
- return n2;
4339
+ return entry;
4143
4340
  case "inner":
4144
4341
  case "full":
4145
4342
  return {
4146
- type: n2.type,
4147
- entries: n2.entries.map((t) => h(t, e))
4343
+ type: entry.type,
4344
+ entries: entry.entries.map((col) => mapJoinEntry(col, cb))
4148
4345
  };
4149
4346
  case "outer":
4150
4347
  return {
4151
4348
  type: "outer",
4152
- primary: h(n2.primary, e),
4153
- secondary: n2.secondary.map((t) => h(t, e))
4349
+ primary: mapJoinEntry(entry.primary, cb),
4350
+ secondary: entry.secondary.map((col) => mapJoinEntry(col, cb))
4154
4351
  };
4155
4352
  default:
4156
- w(n2);
4353
+ assertNever(entry);
4157
4354
  }
4158
4355
  }
4159
- function nn(n2) {
4160
- return Re(n2);
4356
+ function stringifyColumnId(id) {
4357
+ return canonicalize(id);
4161
4358
  }
4162
- function P(n2) {
4163
- return Re(p$1(n2));
4359
+ function axisKey(axis) {
4360
+ return canonicalize(getAxisId(axis));
4164
4361
  }
4165
- function k$1(n2, e) {
4166
- return JSON.stringify([n2, e]);
4362
+ function domainKey(key, value) {
4363
+ return JSON.stringify([key, value]);
4167
4364
  }
4168
- class _n {
4365
+ class AnchoredIdDeriver {
4169
4366
  /**
4170
4367
  * Creates a new anchor context from a set of anchor column specifications
4171
4368
  * @param anchors Record of anchor column specifications indexed by anchor ID
4172
4369
  */
4173
- constructor(e) {
4174
- l$1(this, "domains", /* @__PURE__ */ new Map());
4175
- l$1(this, "axes", /* @__PURE__ */ new Map());
4176
- l$1(this, "domainPacks", []);
4177
- l$1(this, "domainPackToAnchor", /* @__PURE__ */ new Map());
4178
- this.anchors = e;
4179
- const t = Object.entries(e);
4180
- t.sort((r, o) => r[0].localeCompare(o[0]));
4181
- for (const [r, o] of t) {
4182
- for (let s2 = 0; s2 < o.axesSpec.length; s2++) {
4183
- const a = o.axesSpec[s2], i = P(a);
4184
- this.axes.set(i, { anchor: r, idx: s2 });
4370
+ constructor(anchors) {
4371
+ __publicField(this, "anchors");
4372
+ __publicField(this, "domains", /* @__PURE__ */ new Map());
4373
+ __publicField(this, "axes", /* @__PURE__ */ new Map());
4374
+ /**
4375
+ * Domain packs are used to group domain keys that can be anchored to the same anchor
4376
+ * This is used to optimize the lookup of domain anchors
4377
+ */
4378
+ __publicField(this, "domainPacks", []);
4379
+ /**
4380
+ * Maps domain packs to anchors
4381
+ */
4382
+ __publicField(this, "domainPackToAnchor", /* @__PURE__ */ new Map());
4383
+ this.anchors = anchors;
4384
+ const anchorEntries = Object.entries(anchors);
4385
+ anchorEntries.sort((a, b) => a[0].localeCompare(b[0]));
4386
+ for (const [anchorId, spec] of anchorEntries) {
4387
+ for (let axisIdx = 0; axisIdx < spec.axesSpec.length; axisIdx++) {
4388
+ const axis = spec.axesSpec[axisIdx];
4389
+ const key = axisKey(axis);
4390
+ this.axes.set(key, { anchor: anchorId, idx: axisIdx });
4185
4391
  }
4186
- if (o.domain !== void 0) {
4187
- const s2 = Object.entries(o.domain);
4188
- s2.sort((a, i) => a[0].localeCompare(i[0])), this.domainPackToAnchor.set(JSON.stringify(s2), r), this.domainPacks.push(s2.map(([a]) => a));
4189
- for (const [a, i] of s2) {
4190
- const u2 = k$1(a, i);
4191
- this.domains.set(u2, r);
4392
+ if (spec.domain !== void 0) {
4393
+ const domainEntries = Object.entries(spec.domain);
4394
+ domainEntries.sort((a, b) => a[0].localeCompare(b[0]));
4395
+ this.domainPackToAnchor.set(JSON.stringify(domainEntries), anchorId);
4396
+ this.domainPacks.push(domainEntries.map(([dKey]) => dKey));
4397
+ for (const [dKey, dValue] of domainEntries) {
4398
+ const key = domainKey(dKey, dValue);
4399
+ this.domains.set(key, anchorId);
4192
4400
  }
4193
4401
  }
4194
4402
  }
@@ -4196,57 +4404,69 @@
4196
4404
  /**
4197
4405
  * Implementation of derive method
4198
4406
  */
4199
- derive(e, t) {
4200
- const r = {
4201
- name: e.name,
4407
+ derive(spec, axisFilters) {
4408
+ const result = {
4409
+ name: spec.name,
4202
4410
  axes: []
4203
4411
  };
4204
- let o;
4205
- if (e.domain !== void 0)
4206
- n:
4207
- for (const a of this.domainPacks) {
4208
- const i = [];
4209
- for (const c2 of a) {
4210
- const m2 = e.domain[c2];
4211
- if (m2 !== void 0)
4212
- i.push([c2, m2]);
4213
- else
4214
- break n;
4215
- }
4216
- const u2 = this.domainPackToAnchor.get(JSON.stringify(i));
4217
- if (u2 !== void 0) {
4218
- r.domainAnchor = u2, o = new Set(a);
4219
- break;
4220
- }
4412
+ let skipDomains = void 0;
4413
+ if (spec.domain !== void 0) {
4414
+ outer: for (const domainPack of this.domainPacks) {
4415
+ const dAnchor = [];
4416
+ for (const domainKey2 of domainPack) {
4417
+ const dValue = spec.domain[domainKey2];
4418
+ if (dValue !== void 0)
4419
+ dAnchor.push([domainKey2, dValue]);
4420
+ else
4421
+ break outer;
4422
+ }
4423
+ const domainAnchor = this.domainPackToAnchor.get(JSON.stringify(dAnchor));
4424
+ if (domainAnchor !== void 0) {
4425
+ result.domainAnchor = domainAnchor;
4426
+ skipDomains = new Set(domainPack);
4427
+ break;
4221
4428
  }
4222
- for (const [a, i] of Object.entries(e.domain ?? {})) {
4223
- if (o !== void 0 && o.has(a))
4429
+ }
4430
+ }
4431
+ for (const [dKey, dValue] of Object.entries(spec.domain ?? {})) {
4432
+ if (skipDomains !== void 0 && skipDomains.has(dKey))
4224
4433
  continue;
4225
- const u2 = k$1(a, i), c2 = this.domains.get(u2);
4226
- r.domain ?? (r.domain = {}), r.domain[a] = c2 ? { anchor: c2 } : i;
4227
- }
4228
- if (r.axes = e.axesSpec.map((a) => {
4229
- const i = P(a), u2 = this.axes.get(i);
4230
- return u2 === void 0 ? p$1(a) : u2;
4231
- }), !t || t.length === 0)
4232
- return r;
4233
- const s2 = [];
4234
- for (const a of t) {
4235
- const [i, u2] = a;
4236
- if (typeof i == "number") {
4237
- if (i < 0 || i >= e.axesSpec.length)
4238
- throw new Error(`Axis index ${i} is out of bounds (0-${e.axesSpec.length - 1})`);
4239
- s2.push([i, u2]);
4434
+ const key = domainKey(dKey, dValue);
4435
+ const anchorId = this.domains.get(key);
4436
+ result.domain ?? (result.domain = {});
4437
+ result.domain[dKey] = anchorId ? { anchor: anchorId } : dValue;
4438
+ }
4439
+ result.axes = spec.axesSpec.map((axis) => {
4440
+ const key = axisKey(axis);
4441
+ const anchorAxisRef = this.axes.get(key);
4442
+ if (anchorAxisRef === void 0)
4443
+ return getAxisId(axis);
4444
+ else
4445
+ return anchorAxisRef;
4446
+ });
4447
+ if (!axisFilters || axisFilters.length === 0) {
4448
+ return result;
4449
+ }
4450
+ const resolvedFilters = [];
4451
+ for (const filter of axisFilters) {
4452
+ const [axisIdOrIndex, value] = filter;
4453
+ if (typeof axisIdOrIndex === "number") {
4454
+ if (axisIdOrIndex < 0 || axisIdOrIndex >= spec.axesSpec.length) {
4455
+ throw new Error(`Axis index ${axisIdOrIndex} is out of bounds (0-${spec.axesSpec.length - 1})`);
4456
+ }
4457
+ resolvedFilters.push([axisIdOrIndex, value]);
4240
4458
  } else {
4241
- const c2 = e.axesSpec.findIndex((m2) => m2.name === i);
4242
- if (c2 === -1)
4243
- throw new Error(`Axis with name "${i}" not found in the column specification`);
4244
- s2.push([c2, u2]);
4459
+ const axisIndex = spec.axesSpec.findIndex((axis) => axis.name === axisIdOrIndex);
4460
+ if (axisIndex === -1) {
4461
+ throw new Error(`Axis with name "${axisIdOrIndex}" not found in the column specification`);
4462
+ }
4463
+ resolvedFilters.push([axisIndex, value]);
4245
4464
  }
4246
4465
  }
4247
- return s2.sort((a, i) => a[0] - i[0]), {
4248
- source: r,
4249
- axisFilters: s2
4466
+ resolvedFilters.sort((a, b) => a[0] - b[0]);
4467
+ return {
4468
+ source: result,
4469
+ axisFilters: resolvedFilters
4250
4470
  };
4251
4471
  }
4252
4472
  /**
@@ -4255,467 +4475,389 @@
4255
4475
  * @param axisFilters Optional axis filters to apply to the column
4256
4476
  * @returns A canonicalized string representation of the anchored column identifier
4257
4477
  */
4258
- deriveS(e, t) {
4259
- return nn(this.derive(e, t));
4260
- }
4261
- }
4262
- function Mn(n2, e, t) {
4263
- const r = { ...e }, o = (t == null ? void 0 : t.ignoreMissingDomains) ?? false;
4264
- if (r.domainAnchor !== void 0) {
4265
- const s2 = n2[r.domainAnchor];
4266
- if (!s2)
4267
- throw new Error(`Anchor "${r.domainAnchor}" not found`);
4268
- const a = s2.domain || {};
4269
- r.domain = { ...a, ...r.domain }, delete r.domainAnchor;
4270
- }
4271
- if (r.domain) {
4272
- const s2 = {};
4273
- for (const [a, i] of Object.entries(r.domain))
4274
- if (typeof i == "string")
4275
- s2[a] = i;
4276
- else {
4277
- const u2 = n2[i.anchor];
4278
- if (!u2)
4279
- throw new Error(`Anchor "${i.anchor}" not found for domain key "${a}"`);
4280
- if (!u2.domain || u2.domain[a] === void 0) {
4281
- if (!o)
4282
- throw new Error(`Domain key "${a}" not found in anchor "${i.anchor}"`);
4478
+ deriveS(spec, axisFilters) {
4479
+ return stringifyColumnId(this.derive(spec, axisFilters));
4480
+ }
4481
+ }
4482
+ function resolveAnchors(anchors, matcher, options) {
4483
+ const result = { ...matcher };
4484
+ const ignoreMissingDomains = (options == null ? void 0 : options.ignoreMissingDomains) ?? false;
4485
+ if (result.domainAnchor !== void 0) {
4486
+ const anchorSpec = anchors[result.domainAnchor];
4487
+ if (!anchorSpec)
4488
+ throw new Error(`Anchor "${result.domainAnchor}" not found`);
4489
+ const anchorDomains = anchorSpec.domain || {};
4490
+ result.domain = { ...anchorDomains, ...result.domain };
4491
+ delete result.domainAnchor;
4492
+ }
4493
+ if (result.domain) {
4494
+ const resolvedDomain = {};
4495
+ for (const [key, value] of Object.entries(result.domain)) {
4496
+ if (typeof value === "string") {
4497
+ resolvedDomain[key] = value;
4498
+ } else {
4499
+ const anchorSpec = anchors[value.anchor];
4500
+ if (!anchorSpec)
4501
+ throw new Error(`Anchor "${value.anchor}" not found for domain key "${key}"`);
4502
+ if (!anchorSpec.domain || anchorSpec.domain[key] === void 0) {
4503
+ if (!ignoreMissingDomains)
4504
+ throw new Error(`Domain key "${key}" not found in anchor "${value.anchor}"`);
4283
4505
  continue;
4284
4506
  }
4285
- s2[a] = u2.domain[a];
4507
+ resolvedDomain[key] = anchorSpec.domain[key];
4286
4508
  }
4287
- r.domain = s2;
4288
- }
4289
- return r.axes && (r.axes = r.axes.map((s2) => en(n2, s2))), r;
4290
- }
4291
- function en(n2, e) {
4292
- if (!tn(e))
4293
- return e;
4294
- const t = e.anchor, r = n2[t];
4295
- if (!r)
4296
- throw new Error(`Anchor "${t}" not found for axis reference`);
4297
- if ("idx" in e) {
4298
- if (e.idx < 0 || e.idx >= r.axesSpec.length)
4299
- throw new Error(`Axis index ${e.idx} out of bounds for anchor "${t}"`);
4300
- return r.axesSpec[e.idx];
4301
- } else if ("name" in e) {
4302
- const o = r.axesSpec.filter((s2) => s2.name === e.name);
4303
- if (o.length > 1)
4304
- throw new Error(`Multiple axes with name "${e.name}" found in anchor "${t}"`);
4305
- if (o.length === 0)
4306
- throw new Error(`Axis with name "${e.name}" not found in anchor "${t}"`);
4307
- return o[0];
4308
- } else if ("id" in e) {
4309
- const o = r.axesSpec.filter((s2) => Z$1(e.id, p$1(s2)));
4310
- if (o.length > 1)
4311
- throw new Error(`Multiple matching axes found for matcher in anchor "${t}"`);
4312
- if (o.length === 0)
4313
- throw new Error(`No matching axis found for matcher in anchor "${t}"`);
4314
- return o[0];
4315
- }
4316
- throw new Error("Unsupported axis reference type");
4317
- }
4318
- function tn(n2) {
4319
- return typeof n2 == "object" && "anchor" in n2;
4320
- }
4321
- function f(n2) {
4322
- return n2.kind === "PColumn";
4323
- }
4324
- function rn(n2) {
4325
- return f(n2.spec);
4326
- }
4327
- function qn(n2) {
4328
- if (!rn(n2)) throw new Error(`not a PColumn (kind = ${n2.spec.kind})`);
4329
- return n2;
4330
- }
4331
- function Wn(n2, e) {
4332
- return n2 === void 0 ? void 0 : {
4333
- ...n2,
4334
- data: e(n2.data)
4509
+ }
4510
+ result.domain = resolvedDomain;
4511
+ }
4512
+ if (result.axes)
4513
+ result.axes = result.axes.map((axis) => resolveAxisReference(anchors, axis));
4514
+ return result;
4515
+ }
4516
+ function resolveAxisReference(anchors, axisRef) {
4517
+ if (!isAnchorAxisRef(axisRef))
4518
+ return axisRef;
4519
+ const anchorId = axisRef.anchor;
4520
+ const anchorSpec = anchors[anchorId];
4521
+ if (!anchorSpec)
4522
+ throw new Error(`Anchor "${anchorId}" not found for axis reference`);
4523
+ if ("idx" in axisRef) {
4524
+ if (axisRef.idx < 0 || axisRef.idx >= anchorSpec.axesSpec.length)
4525
+ throw new Error(`Axis index ${axisRef.idx} out of bounds for anchor "${anchorId}"`);
4526
+ return anchorSpec.axesSpec[axisRef.idx];
4527
+ } else if ("name" in axisRef) {
4528
+ const matches = anchorSpec.axesSpec.filter((axis) => axis.name === axisRef.name);
4529
+ if (matches.length > 1)
4530
+ throw new Error(`Multiple axes with name "${axisRef.name}" found in anchor "${anchorId}"`);
4531
+ if (matches.length === 0)
4532
+ throw new Error(`Axis with name "${axisRef.name}" not found in anchor "${anchorId}"`);
4533
+ return matches[0];
4534
+ } else if ("id" in axisRef) {
4535
+ const matches = anchorSpec.axesSpec.filter((axis) => matchAxisId(axisRef.id, getAxisId(axis)));
4536
+ if (matches.length > 1)
4537
+ throw new Error(`Multiple matching axes found for matcher in anchor "${anchorId}"`);
4538
+ if (matches.length === 0)
4539
+ throw new Error(`No matching axis found for matcher in anchor "${anchorId}"`);
4540
+ return matches[0];
4541
+ }
4542
+ throw new Error(`Unsupported axis reference type`);
4543
+ }
4544
+ function isAnchorAxisRef(value) {
4545
+ return typeof value === "object" && "anchor" in value;
4546
+ }
4547
+ function isPColumnSpec(spec) {
4548
+ return spec.kind === "PColumn";
4549
+ }
4550
+ function isPColumn(obj) {
4551
+ return isPColumnSpec(obj.spec);
4552
+ }
4553
+ function ensurePColumn(obj) {
4554
+ if (!isPColumn(obj))
4555
+ throw new Error(`not a PColumn (kind = ${obj.spec.kind})`);
4556
+ return obj;
4557
+ }
4558
+ function mapPObjectData(pObj, cb) {
4559
+ return pObj === void 0 ? void 0 : {
4560
+ ...pObj,
4561
+ data: cb(pObj.data)
4335
4562
  };
4336
4563
  }
4337
- function Xn(n2) {
4338
- const e = /* @__PURE__ */ new Map(), t = (r) => {
4339
- switch (r.type) {
4564
+ function extractAllColumns(entry) {
4565
+ const columns = /* @__PURE__ */ new Map();
4566
+ const addAllColumns = (entry2) => {
4567
+ switch (entry2.type) {
4340
4568
  case "column":
4341
- e.set(r.column.id, r.column);
4569
+ columns.set(entry2.column.id, entry2.column);
4342
4570
  return;
4343
4571
  case "slicedColumn":
4344
- e.set(r.column.id, r.column);
4572
+ columns.set(entry2.column.id, entry2.column);
4573
+ return;
4574
+ case "artificialColumn":
4575
+ columns.set(entry2.column.id, entry2.column);
4345
4576
  return;
4346
4577
  case "inlineColumn":
4347
4578
  return;
4348
4579
  case "full":
4349
4580
  case "inner":
4350
- for (const o of r.entries) t(o);
4581
+ for (const e of entry2.entries)
4582
+ addAllColumns(e);
4351
4583
  return;
4352
4584
  case "outer":
4353
- t(r.primary);
4354
- for (const o of r.secondary) t(o);
4585
+ addAllColumns(entry2.primary);
4586
+ for (const e of entry2.secondary)
4587
+ addAllColumns(e);
4355
4588
  return;
4356
4589
  default:
4357
- w(r);
4590
+ assertNever(entry2);
4358
4591
  }
4359
4592
  };
4360
- return t(n2), [...e.values()];
4593
+ addAllColumns(entry);
4594
+ return [...columns.values()];
4361
4595
  }
4362
- function E$1(n2, e) {
4363
- if (n2.name !== void 0 && n2.name !== e.name)
4596
+ function matchAxis(selector, axis) {
4597
+ if (selector.name !== void 0 && selector.name !== axis.name)
4364
4598
  return false;
4365
- if (n2.type !== void 0) {
4366
- if (Array.isArray(n2.type)) {
4367
- if (!n2.type.includes(e.type))
4599
+ if (selector.type !== void 0) {
4600
+ if (Array.isArray(selector.type)) {
4601
+ if (!selector.type.includes(axis.type))
4368
4602
  return false;
4369
- } else if (n2.type !== e.type)
4603
+ } else if (selector.type !== axis.type) {
4370
4604
  return false;
4605
+ }
4371
4606
  }
4372
- if (n2.domain !== void 0) {
4373
- const t = e.domain || {};
4374
- for (const [r, o] of Object.entries(n2.domain))
4375
- if (t[r] !== o)
4607
+ if (selector.domain !== void 0) {
4608
+ const axisDomain = axis.domain || {};
4609
+ for (const [key, value] of Object.entries(selector.domain))
4610
+ if (axisDomain[key] !== value)
4376
4611
  return false;
4377
4612
  }
4378
4613
  return true;
4379
4614
  }
4380
- function N(n2, e) {
4381
- if (e.name !== void 0 && n2.name !== e.name || e.namePattern !== void 0 && !new RegExp(e.namePattern).test(n2.name))
4615
+ function matchPColumn(pcolumn, selector) {
4616
+ if (selector.name !== void 0 && pcolumn.name !== selector.name)
4382
4617
  return false;
4383
- if (e.type !== void 0) {
4384
- if (Array.isArray(e.type)) {
4385
- if (!e.type.includes(n2.valueType))
4618
+ if (selector.namePattern !== void 0 && !new RegExp(selector.namePattern).test(pcolumn.name))
4619
+ return false;
4620
+ if (selector.type !== void 0) {
4621
+ if (Array.isArray(selector.type)) {
4622
+ if (!selector.type.includes(pcolumn.valueType))
4386
4623
  return false;
4387
- } else if (e.type !== n2.valueType)
4624
+ } else if (selector.type !== pcolumn.valueType) {
4388
4625
  return false;
4626
+ }
4389
4627
  }
4390
- if (e.domain !== void 0) {
4391
- const t = n2.domain || {};
4392
- for (const [r, o] of Object.entries(e.domain))
4393
- if (t[r] !== o)
4628
+ if (selector.domain !== void 0) {
4629
+ const columnDomain = pcolumn.domain || {};
4630
+ for (const [key, value] of Object.entries(selector.domain))
4631
+ if (columnDomain[key] !== value)
4394
4632
  return false;
4395
4633
  }
4396
- if (e.axes !== void 0) {
4397
- const t = n2.axesSpec.map(p$1);
4398
- if (e.partialAxesMatch) {
4399
- for (const r of e.axes)
4400
- if (!t.some((o) => E$1(r, o)))
4634
+ if (selector.axes !== void 0) {
4635
+ const pcolumnAxes = pcolumn.axesSpec.map(getAxisId);
4636
+ if (selector.partialAxesMatch) {
4637
+ for (const selectorAxis of selector.axes)
4638
+ if (!pcolumnAxes.some((columnAxis) => matchAxis(selectorAxis, columnAxis)))
4401
4639
  return false;
4402
4640
  } else {
4403
- if (t.length !== e.axes.length)
4641
+ if (pcolumnAxes.length !== selector.axes.length)
4404
4642
  return false;
4405
- for (let r = 0; r < e.axes.length; r++)
4406
- if (!E$1(e.axes[r], t[r]))
4643
+ for (let i = 0; i < selector.axes.length; i++)
4644
+ if (!matchAxis(selector.axes[i], pcolumnAxes[i]))
4407
4645
  return false;
4408
4646
  }
4409
4647
  }
4410
- if (e.annotations !== void 0) {
4411
- const t = n2.annotations || {};
4412
- for (const [r, o] of Object.entries(e.annotations))
4413
- if (t[r] !== o)
4648
+ if (selector.annotations !== void 0) {
4649
+ const columnAnnotations = pcolumn.annotations || {};
4650
+ for (const [key, value] of Object.entries(selector.annotations))
4651
+ if (columnAnnotations[key] !== value)
4414
4652
  return false;
4415
4653
  }
4416
- if (e.annotationPatterns !== void 0) {
4417
- const t = n2.annotations || {};
4418
- for (const [r, o] of Object.entries(e.annotationPatterns)) {
4419
- const s2 = t[r];
4420
- if (s2 === void 0 || !new RegExp(o).test(s2))
4654
+ if (selector.annotationPatterns !== void 0) {
4655
+ const columnAnnotations = pcolumn.annotations || {};
4656
+ for (const [key, pattern] of Object.entries(selector.annotationPatterns)) {
4657
+ const value = columnAnnotations[key];
4658
+ if (value === void 0 || !new RegExp(pattern).test(value))
4421
4659
  return false;
4422
4660
  }
4423
4661
  }
4424
4662
  return true;
4425
4663
  }
4426
- function Gn(n2) {
4427
- return Array.isArray(n2) ? (e) => n2.some((t) => f(e) && N(e, t)) : (e) => f(e) && N(e, n2);
4664
+ function selectorsToPredicate(predicateOrSelectors) {
4665
+ if (Array.isArray(predicateOrSelectors))
4666
+ return (spec) => predicateOrSelectors.some((selector) => isPColumnSpec(spec) && matchPColumn(spec, selector));
4667
+ else
4668
+ return (spec) => isPColumnSpec(spec) && matchPColumn(spec, predicateOrSelectors);
4428
4669
  }
4429
- function Qn(n2) {
4430
- const e = {
4431
- kind: n2.kind,
4432
- name: n2.name
4670
+ function deriveNativeId(spec) {
4671
+ const result = {
4672
+ kind: spec.kind,
4673
+ name: spec.name
4433
4674
  };
4434
- return n2.domain !== void 0 && (e.domain = n2.domain), f(n2) && (e.axesSpec = J(n2.axesSpec)), Re(e);
4435
- }
4436
- z$1.object({
4437
- __isRef: z$1.literal(true).describe("Crucial marker for the block dependency tree reconstruction"),
4438
- blockId: z$1.string().describe("Upstream block id"),
4439
- name: z$1.string().describe("Name of the output provided to the upstream block's output context"),
4440
- requireEnrichments: z$1.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")
4441
- }).describe(
4442
- "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."
4443
- ).readonly();
4444
- function ne(n2) {
4445
- return typeof n2 == "object" && n2 !== null && "__isRef" in n2 && n2.__isRef === true && "blockId" in n2 && "name" in n2;
4446
- }
4447
- function te$1(n2, e = true) {
4448
- if (e)
4675
+ if (spec.domain !== void 0)
4676
+ result.domain = spec.domain;
4677
+ if (isPColumnSpec(spec))
4678
+ result.axesSpec = getAxesId(spec.axesSpec);
4679
+ return canonicalize(result);
4680
+ }
4681
+ const PlIdLength = 24;
4682
+ z.string().length(PlIdLength).regex(/[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]/).brand("PlId");
4683
+ z.object({
4684
+ __isRef: z.literal(true).describe("Crucial marker for the block dependency tree reconstruction"),
4685
+ blockId: z.string().describe("Upstream block id"),
4686
+ name: z.string().describe("Name of the output provided to the upstream block's output context"),
4687
+ 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")
4688
+ }).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();
4689
+ function isPlRef(value) {
4690
+ return typeof value === "object" && value !== null && "__isRef" in value && value.__isRef === true && "blockId" in value && "name" in value;
4691
+ }
4692
+ function withEnrichments(ref, requireEnrichments = true) {
4693
+ if (requireEnrichments)
4449
4694
  return {
4450
- ...n2,
4695
+ ...ref,
4451
4696
  requireEnrichments: true
4452
4697
  };
4453
- {
4454
- const { requireEnrichments: t, ...r } = n2;
4455
- return r;
4456
- }
4457
- }
4458
- function oe$1(n2, e) {
4459
- return n2.ok ? { ok: true, value: e(n2.value) } : n2;
4460
- }
4461
- const fn = 24;
4462
- z$1.string().length(fn).regex(/[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]/).brand("PlId");
4463
- function ue$1(n2) {
4464
- return Re(n2);
4465
- }
4466
- var stringify = { exports: {} };
4467
- var hasRequiredStringify;
4468
- function requireStringify() {
4469
- if (hasRequiredStringify) return stringify.exports;
4470
- hasRequiredStringify = 1;
4471
- (function(module2, exports3) {
4472
- exports3 = module2.exports = stringify2;
4473
- exports3.getSerialize = serializer;
4474
- function stringify2(obj, replacer, spaces, cycleReplacer) {
4475
- return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces);
4476
- }
4477
- function serializer(replacer, cycleReplacer) {
4478
- var stack = [], keys = [];
4479
- if (cycleReplacer == null) cycleReplacer = function(key, value) {
4480
- if (stack[0] === value) return "[Circular ~]";
4481
- return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
4482
- };
4483
- return function(key, value) {
4484
- if (stack.length > 0) {
4485
- var thisPos = stack.indexOf(this);
4486
- ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
4487
- ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
4488
- if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value);
4489
- } else stack.push(value);
4490
- return replacer == null ? value : replacer.call(this, key, value);
4491
- };
4492
- }
4493
- })(stringify, stringify.exports);
4494
- return stringify.exports;
4495
- }
4496
- requireStringify();
4497
- const l = z$1.object({
4498
- type: z$1.literal("PlError"),
4499
- name: z$1.string(),
4500
- message: z$1.string(),
4501
- /** The message with all details needed for SDK developers. */
4502
- fullMessage: z$1.string().optional(),
4503
- stack: z$1.string().optional()
4504
- }), c = l.extend({
4505
- cause: z$1.lazy(() => s).optional(),
4506
- errors: z$1.lazy(() => s.array()).optional()
4507
- }), m = z$1.object({
4508
- type: z$1.literal("StandardError"),
4509
- name: z$1.string(),
4510
- message: z$1.string(),
4511
- stack: z$1.string().optional()
4512
- }), p = m.extend({
4513
- cause: z$1.lazy(() => s).optional(),
4514
- errors: z$1.lazy(() => s.array()).optional()
4515
- }), s = z$1.union([p, c]);
4516
- const u = z$1.object({
4517
- name: z$1.string(),
4518
- message: z$1.string(),
4519
- fullMessage: z$1.string().optional(),
4520
- stack: z$1.string().optional()
4521
- }), n = u.extend({
4522
- cause: z$1.lazy(() => n).optional(),
4523
- errors: z$1.lazy(() => n.array()).optional()
4524
- });
4525
- var Ye = Object.defineProperty;
4526
- var Xe = (t, e, n2) => e in t ? Ye(t, e, { enumerable: true, configurable: true, writable: true, value: n2 }) : t[e] = n2;
4527
- var k = (t, e, n2) => Xe(t, typeof e != "symbol" ? e + "" : e, n2);
4528
- function re(t) {
4529
- return { type: "Immediate", value: t };
4530
- }
4531
- function ht() {
4532
- return typeof globalThis.getPlatforma < "u" || typeof globalThis.platforma < "u";
4533
- }
4534
- function Ke(t) {
4535
- if (t && typeof globalThis.getPlatforma == "function")
4536
- return globalThis.getPlatforma(t);
4537
- if (typeof globalThis.platforma < "u") return globalThis.platforma;
4538
- throw new Error("Can't get platforma instance.");
4539
- }
4540
- function gt() {
4541
- if (typeof globalThis.cfgRenderCtx < "u") return globalThis.cfgRenderCtx;
4542
- }
4543
- function y() {
4544
- if (typeof globalThis.cfgRenderCtx < "u") return globalThis.cfgRenderCtx;
4545
- throw new Error("Not in config rendering context");
4546
- }
4547
- function H(t, e) {
4548
- const n2 = gt();
4549
- if (n2 === void 0) return false;
4550
- if (t in n2.callbackRegistry) throw new Error(`Callback with key ${t} already registered.`);
4551
- return n2.callbackRegistry[t] = e, true;
4552
- }
4553
- const de = /* @__PURE__ */ new Map();
4554
- function mt(t, e) {
4555
- t in y().callbackRegistry || (y().callbackRegistry[t] = (n2) => {
4556
- for (const r of de.get(t))
4557
- r(n2);
4558
- }, de.set(t, [])), de.get(t).push(e);
4559
- }
4560
- class I {
4561
- constructor(e, n2 = (r) => r) {
4562
- k(this, "isResolved", false);
4563
- k(this, "resolvedValue");
4564
- this.handle = e, this.postProcess = n2, mt(e, (r) => {
4565
- this.resolvedValue = n2(r), this.isResolved = true;
4698
+ else {
4699
+ const { requireEnrichments: _, ...rest } = ref;
4700
+ return rest;
4701
+ }
4702
+ }
4703
+ function mapValueInVOE(voe, cb) {
4704
+ return voe.ok ? { ok: true, value: cb(voe.value) } : voe;
4705
+ }
4706
+ class FutureRef {
4707
+ constructor(handle, postProcess = (v) => v) {
4708
+ __publicField(this, "handle");
4709
+ __publicField(this, "postProcess");
4710
+ __publicField(this, "isResolved", false);
4711
+ __publicField(this, "resolvedValue");
4712
+ this.handle = handle;
4713
+ this.postProcess = postProcess;
4714
+ registerFutureAwait(handle, (value) => {
4715
+ this.resolvedValue = postProcess(value);
4716
+ this.isResolved = true;
4566
4717
  });
4567
4718
  }
4568
- map(e) {
4569
- return new I(this.handle, (n2) => e(this.postProcess(n2)));
4719
+ map(mapping) {
4720
+ return new FutureRef(this.handle, (v) => mapping(this.postProcess(v)));
4570
4721
  }
4571
- mapDefined(e) {
4572
- return new I(this.handle, (n2) => {
4573
- const r = this.postProcess(n2);
4574
- return r ? e(r) : void 0;
4722
+ mapDefined(mapping) {
4723
+ return new FutureRef(this.handle, (v) => {
4724
+ const vv = this.postProcess(v);
4725
+ return vv ? mapping(vv) : void 0;
4575
4726
  });
4576
4727
  }
4577
4728
  toJSON() {
4578
4729
  return this.isResolved ? this.resolvedValue : { __awaited_futures__: [this.handle] };
4579
4730
  }
4580
4731
  }
4581
- function ge(t, e) {
4582
- return t === void 0 ? void 0 : e(t);
4732
+ function ifDef(value, cb) {
4733
+ return value === void 0 ? void 0 : cb(value);
4583
4734
  }
4584
- class E {
4585
- constructor(e, n2) {
4586
- this.handle = e, this.resolvePath = n2;
4735
+ class TreeNodeAccessor {
4736
+ constructor(handle, resolvePath) {
4737
+ __publicField(this, "handle");
4738
+ __publicField(this, "resolvePath");
4739
+ this.handle = handle;
4740
+ this.resolvePath = resolvePath;
4587
4741
  }
4588
- resolve(...e) {
4589
- const n2 = e.map(
4590
- (r) => ({
4591
- assertFieldType: "Input",
4592
- ...typeof r == "string" ? { field: r } : r
4593
- })
4594
- );
4595
- return this.resolveWithCommon({}, ...n2);
4596
- }
4597
- resolveOutput(...e) {
4598
- const n2 = e.map(
4599
- (r) => ({
4600
- assertFieldType: "Output",
4601
- ...typeof r == "string" ? { field: r } : r
4602
- })
4603
- );
4604
- return this.resolveWithCommon({}, ...n2);
4605
- }
4606
- resolveInput(...e) {
4607
- const n2 = e.map(
4608
- (r) => ({
4609
- assertFieldType: "Input",
4610
- ...typeof r == "string" ? { field: r } : r
4611
- })
4612
- );
4613
- return this.resolveWithCommon({}, ...n2);
4742
+ resolve(...steps) {
4743
+ const transformedSteps = steps.map((s) => ({
4744
+ assertFieldType: "Input",
4745
+ ...typeof s === "string" ? { field: s } : s
4746
+ }));
4747
+ return this.resolveWithCommon({}, ...transformedSteps);
4748
+ }
4749
+ resolveOutput(...steps) {
4750
+ const transformedSteps = steps.map((s) => ({
4751
+ assertFieldType: "Output",
4752
+ ...typeof s === "string" ? { field: s } : s
4753
+ }));
4754
+ return this.resolveWithCommon({}, ...transformedSteps);
4614
4755
  }
4615
- resolveAny(...e) {
4616
- return this.resolveWithCommon({}, ...e);
4756
+ resolveInput(...steps) {
4757
+ const transformedSteps = steps.map((s) => ({
4758
+ assertFieldType: "Input",
4759
+ ...typeof s === "string" ? { field: s } : s
4760
+ }));
4761
+ return this.resolveWithCommon({}, ...transformedSteps);
4762
+ }
4763
+ resolveAny(...steps) {
4764
+ return this.resolveWithCommon({}, ...steps);
4617
4765
  }
4618
- resolveWithCommon(e, ...n2) {
4619
- const r = [
4766
+ resolveWithCommon(commonOptions, ...steps) {
4767
+ const resolvePath = [
4620
4768
  ...this.resolvePath,
4621
- ...n2.map((i) => typeof i == "string" ? i : i.field)
4769
+ ...steps.map((step) => typeof step === "string" ? step : step.field)
4622
4770
  ];
4623
- return ge(
4624
- y().resolveWithCommon(this.handle, e, ...n2),
4625
- (i) => new E(i, r)
4626
- );
4771
+ return ifDef(getCfgRenderCtx().resolveWithCommon(this.handle, commonOptions, ...steps), (accessor) => new TreeNodeAccessor(accessor, resolvePath));
4627
4772
  }
4628
4773
  get resourceType() {
4629
- return y().getResourceType(this.handle);
4774
+ return getCfgRenderCtx().getResourceType(this.handle);
4630
4775
  }
4631
4776
  getInputsLocked() {
4632
- return y().getInputsLocked(this.handle);
4777
+ return getCfgRenderCtx().getInputsLocked(this.handle);
4633
4778
  }
4634
4779
  getOutputsLocked() {
4635
- return y().getOutputsLocked(this.handle);
4780
+ return getCfgRenderCtx().getOutputsLocked(this.handle);
4636
4781
  }
4637
4782
  getIsReadyOrError() {
4638
- return y().getIsReadyOrError(this.handle);
4783
+ return getCfgRenderCtx().getIsReadyOrError(this.handle);
4639
4784
  }
4640
4785
  getIsFinal() {
4641
- return y().getIsFinal(this.handle);
4786
+ return getCfgRenderCtx().getIsFinal(this.handle);
4642
4787
  }
4643
4788
  getError() {
4644
- const e = [...this.resolvePath, "error"];
4645
- return ge(
4646
- y().getError(this.handle),
4647
- (n2) => new E(n2, e)
4648
- );
4789
+ const resolvePath = [...this.resolvePath, "error"];
4790
+ return ifDef(getCfgRenderCtx().getError(this.handle), (accsessor) => new TreeNodeAccessor(accsessor, resolvePath));
4649
4791
  }
4650
4792
  listInputFields() {
4651
- return y().listInputFields(this.handle);
4793
+ return getCfgRenderCtx().listInputFields(this.handle);
4652
4794
  }
4653
4795
  listOutputFields() {
4654
- return y().listOutputFields(this.handle);
4796
+ return getCfgRenderCtx().listOutputFields(this.handle);
4655
4797
  }
4656
4798
  listDynamicFields() {
4657
- return y().listDynamicFields(this.handle);
4799
+ return getCfgRenderCtx().listDynamicFields(this.handle);
4658
4800
  }
4659
- getKeyValueBase64(e) {
4660
- return y().getKeyValueBase64(this.handle, e);
4801
+ getKeyValueBase64(key) {
4802
+ return getCfgRenderCtx().getKeyValueBase64(this.handle, key);
4661
4803
  }
4662
- getKeyValueAsString(e) {
4663
- return y().getKeyValueAsString(this.handle, e);
4804
+ getKeyValueAsString(key) {
4805
+ return getCfgRenderCtx().getKeyValueAsString(this.handle, key);
4664
4806
  }
4665
- getKeyValueAsJson(e) {
4666
- const n2 = this.getKeyValueAsString(e);
4667
- if (n2 == null) throw new Error("Resource has no content.");
4668
- return JSON.parse(n2);
4807
+ getKeyValueAsJson(key) {
4808
+ const content = this.getKeyValueAsString(key);
4809
+ if (content == void 0)
4810
+ throw new Error("Resource has no content.");
4811
+ return JSON.parse(content);
4669
4812
  }
4670
4813
  getDataBase64() {
4671
- return y().getDataBase64(this.handle);
4814
+ return getCfgRenderCtx().getDataBase64(this.handle);
4672
4815
  }
4673
4816
  getDataAsString() {
4674
- return y().getDataAsString(this.handle);
4817
+ return getCfgRenderCtx().getDataAsString(this.handle);
4675
4818
  }
4676
4819
  getDataAsJson() {
4677
- const e = this.getDataAsString();
4678
- if (e == null) throw new Error("Resource has no content.");
4679
- return JSON.parse(e);
4820
+ const content = this.getDataAsString();
4821
+ if (content == void 0)
4822
+ throw new Error("Resource has no content.");
4823
+ return JSON.parse(content);
4680
4824
  }
4681
4825
  /**
4682
4826
  *
4683
4827
  */
4684
- getPColumns(e = false, n2 = "") {
4685
- const r = this.parsePObjectCollection(e, n2);
4686
- return r === void 0 ? void 0 : Object.entries(r).map(([, s2]) => {
4687
- if (!rn(s2)) throw new Error(`not a PColumn (kind = ${s2.spec.kind})`);
4688
- return s2;
4828
+ getPColumns(errorOnUnknownField = false, prefix = "") {
4829
+ const result = this.parsePObjectCollection(errorOnUnknownField, prefix);
4830
+ if (result === void 0)
4831
+ return void 0;
4832
+ const pf = Object.entries(result).map(([, obj]) => {
4833
+ if (!isPColumn(obj))
4834
+ throw new Error(`not a PColumn (kind = ${obj.spec.kind})`);
4835
+ return obj;
4689
4836
  });
4837
+ return pf;
4690
4838
  }
4691
4839
  /**
4692
4840
  *
4693
4841
  */
4694
- parsePObjectCollection(e = false, n2 = "") {
4695
- const r = y().parsePObjectCollection(
4696
- this.handle,
4697
- e,
4698
- n2,
4699
- ...this.resolvePath
4700
- );
4701
- if (r === void 0) return;
4702
- const i = {};
4703
- for (const [s2, o] of Object.entries(r)) {
4704
- const a = [...this.resolvePath, s2];
4705
- i[s2] = Wn(o, (l2) => new E(l2, a));
4706
- }
4707
- return i;
4708
- }
4709
- getFileContentAsBase64(e) {
4710
- return new I(y().getBlobContentAsBase64(this.handle, e));
4711
- }
4712
- getFileContentAsString(e) {
4713
- return new I(y().getBlobContentAsString(this.handle, e));
4714
- }
4715
- getFileContentAsJson(e) {
4716
- return new I(
4717
- y().getBlobContentAsString(this.handle, e)
4718
- ).mapDefined((n2) => JSON.parse(n2));
4842
+ parsePObjectCollection(errorOnUnknownField = false, prefix = "") {
4843
+ const pObjects = getCfgRenderCtx().parsePObjectCollection(this.handle, errorOnUnknownField, prefix, ...this.resolvePath);
4844
+ if (pObjects === void 0)
4845
+ return void 0;
4846
+ const result = {};
4847
+ for (const [key, value] of Object.entries(pObjects)) {
4848
+ const resolvePath = [...this.resolvePath, key];
4849
+ result[key] = mapPObjectData(value, (c) => new TreeNodeAccessor(c, resolvePath));
4850
+ }
4851
+ return result;
4852
+ }
4853
+ getFileContentAsBase64(range) {
4854
+ return new FutureRef(getCfgRenderCtx().getBlobContentAsBase64(this.handle, range));
4855
+ }
4856
+ getFileContentAsString(range) {
4857
+ return new FutureRef(getCfgRenderCtx().getBlobContentAsString(this.handle, range));
4858
+ }
4859
+ getFileContentAsJson(range) {
4860
+ return new FutureRef(getCfgRenderCtx().getBlobContentAsString(this.handle, range)).mapDefined((v) => JSON.parse(v));
4719
4861
  }
4720
4862
  /**
4721
4863
  * @deprecated use getFileContentAsBase64
@@ -4733,7 +4875,7 @@
4733
4875
  * @returns downloaded file handle
4734
4876
  */
4735
4877
  getFileHandle() {
4736
- return new I(y().getDownloadedBlobContentHandle(this.handle));
4878
+ return new FutureRef(getCfgRenderCtx().getDownloadedBlobContentHandle(this.handle));
4737
4879
  }
4738
4880
  /**
4739
4881
  * @deprecated use getFileHandle
@@ -4745,7 +4887,7 @@
4745
4887
  * @returns downloaded file handle
4746
4888
  */
4747
4889
  getRemoteFileHandle() {
4748
- return new I(y().getOnDemandBlobContentHandle(this.handle));
4890
+ return new FutureRef(getCfgRenderCtx().getOnDemandBlobContentHandle(this.handle));
4749
4891
  }
4750
4892
  /**
4751
4893
  * @deprecated use getRemoteFileHandle
@@ -4756,655 +4898,898 @@
4756
4898
  /**
4757
4899
  * @returns the url to the extracted folder
4758
4900
  */
4759
- extractArchiveAndGetURL(e) {
4760
- return new I(y().extractArchiveAndGetURL(this.handle, e));
4901
+ extractArchiveAndGetURL(format) {
4902
+ return new FutureRef(getCfgRenderCtx().extractArchiveAndGetURL(this.handle, format));
4761
4903
  }
4762
4904
  getImportProgress() {
4763
- return new I(y().getImportProgress(this.handle));
4905
+ return new FutureRef(getCfgRenderCtx().getImportProgress(this.handle));
4764
4906
  }
4765
- getLastLogs(e) {
4766
- return new I(y().getLastLogs(this.handle, e));
4907
+ getLastLogs(nLines) {
4908
+ return new FutureRef(getCfgRenderCtx().getLastLogs(this.handle, nLines));
4767
4909
  }
4768
- getProgressLog(e) {
4769
- return new I(y().getProgressLog(this.handle, e));
4910
+ getProgressLog(patternToSearch) {
4911
+ return new FutureRef(getCfgRenderCtx().getProgressLog(this.handle, patternToSearch));
4770
4912
  }
4771
- getProgressLogWithInfo(e) {
4772
- return new I(y().getProgressLogWithInfo(this.handle, e));
4913
+ getProgressLogWithInfo(patternToSearch) {
4914
+ return new FutureRef(getCfgRenderCtx().getProgressLogWithInfo(this.handle, patternToSearch));
4773
4915
  }
4774
4916
  getLogHandle() {
4775
- return new I(y().getLogHandle(this.handle));
4917
+ return new FutureRef(getCfgRenderCtx().getLogHandle(this.handle));
4776
4918
  }
4777
- allFieldsResolved(e = "Input") {
4778
- switch (e) {
4919
+ allFieldsResolved(fieldType = "Input") {
4920
+ switch (fieldType) {
4779
4921
  case "Input":
4780
- return this.getInputsLocked() && this.listInputFields().every(
4781
- (n2) => this.resolve({ field: n2, assertFieldType: "Input" }) !== void 0
4782
- );
4922
+ return this.getInputsLocked() && this.listInputFields().every((field) => this.resolve({ field, assertFieldType: "Input" }) !== void 0);
4783
4923
  case "Output":
4784
- return this.getOutputsLocked() && this.listOutputFields().every(
4785
- (n2) => this.resolve({ field: n2, assertFieldType: "Output" }) !== void 0
4786
- );
4924
+ return this.getOutputsLocked() && this.listOutputFields().every((field) => this.resolve({ field, assertFieldType: "Output" }) !== void 0);
4787
4925
  }
4788
4926
  }
4789
- mapFields(e, n2) {
4790
- const { fieldType: r, requireLocked: i, skipUnresolved: s2 } = {
4927
+ mapFields(_mapping, _ops) {
4928
+ const { fieldType, requireLocked, skipUnresolved } = {
4791
4929
  fieldType: "Input",
4792
4930
  requireLocked: true,
4793
4931
  skipUnresolved: false,
4794
- ...n2
4795
- }, o = e;
4796
- if (i && (r === "Input" && !this.getInputsLocked() || r === "Output" && !this.getOutputsLocked()))
4797
- return;
4798
- let l2 = (r === "Input" ? this.listInputFields() : r === "Output" ? this.listOutputFields() : this.listDynamicFields()).map(
4799
- (u2) => [u2, this.resolve({ field: u2, assertFieldType: r })]
4800
- );
4801
- return s2 && (l2 = l2.filter((u2) => u2[1] !== void 0)), l2.map(([u2, c2]) => o(u2, c2));
4802
- }
4803
- }
4804
- const Ve = "staging", je = "main";
4805
- const bt = "pl7.app/label", wt = "pl7.app/trace", At = z$1.object({
4806
- type: z$1.string(),
4807
- importance: z$1.number().optional(),
4808
- id: z$1.string().optional(),
4809
- label: z$1.string()
4810
- }), xt = z$1.array(At), Ct = 1e-3, Pt = "__LABEL__", Te = "__LABEL__@1";
4811
- function $e(t, e, n2 = {}) {
4812
- const r = /* @__PURE__ */ new Map(), i = n2.forceTraceElements !== void 0 && n2.forceTraceElements.length > 0 ? new Set(n2.forceTraceElements) : void 0, s2 = /* @__PURE__ */ new Map(), o = t.map((p2) => {
4813
- var S, F;
4814
- const m2 = e(p2);
4815
- let f2, v, b;
4816
- "spec" in m2 && typeof m2.spec == "object" ? (f2 = m2.spec, v = m2.prefixTrace, b = m2.suffixTrace) : f2 = m2;
4817
- const g = (S = f2.annotations) == null ? void 0 : S[bt], x = (F = f2.annotations) == null ? void 0 : F[wt], A = (x ? xt.safeParse(JSON.parse(x)).data : void 0) ?? [], C = [
4818
- ...v ?? [],
4819
- ...A,
4820
- ...b ?? []
4932
+ ..._ops
4933
+ };
4934
+ const mapping = _mapping;
4935
+ if (requireLocked) {
4936
+ if (fieldType === "Input" && !this.getInputsLocked())
4937
+ return void 0;
4938
+ if (fieldType === "Output" && !this.getOutputsLocked())
4939
+ return void 0;
4940
+ }
4941
+ const fieldList = fieldType === "Input" ? this.listInputFields() : fieldType === "Output" ? this.listOutputFields() : this.listDynamicFields();
4942
+ let fieldEntries = fieldList.map((field) => [field, this.resolve({ field, assertFieldType: fieldType })]);
4943
+ if (skipUnresolved)
4944
+ fieldEntries = fieldEntries.filter((e) => e[1] !== void 0);
4945
+ return fieldEntries.map(([name, value]) => mapping(name, value));
4946
+ }
4947
+ }
4948
+ const StagingAccessorName = "staging";
4949
+ const MainAccessorName = "main";
4950
+ const TraceEntry = z.object({
4951
+ type: z.string(),
4952
+ importance: z.number().optional(),
4953
+ id: z.string().optional(),
4954
+ label: z.string()
4955
+ });
4956
+ const Trace = z.array(TraceEntry);
4957
+ const DistancePenalty = 1e-3;
4958
+ const LabelType = "__LABEL__";
4959
+ const LabelTypeFull = "__LABEL__@1";
4960
+ function deriveLabels(values, specExtractor, ops = {}) {
4961
+ const importances = /* @__PURE__ */ new Map();
4962
+ const forceTraceElements = ops.forceTraceElements !== void 0 && ops.forceTraceElements.length > 0 ? new Set(ops.forceTraceElements) : void 0;
4963
+ const numberOfRecordsWithType = /* @__PURE__ */ new Map();
4964
+ const enrichedRecords = values.map((value) => {
4965
+ const extractorResult = specExtractor(value);
4966
+ let spec;
4967
+ let prefixTrace;
4968
+ let suffixTrace;
4969
+ if ("spec" in extractorResult && typeof extractorResult.spec === "object") {
4970
+ spec = extractorResult.spec;
4971
+ prefixTrace = extractorResult.prefixTrace;
4972
+ suffixTrace = extractorResult.suffixTrace;
4973
+ } else {
4974
+ spec = extractorResult;
4975
+ }
4976
+ const label = readAnnotation(spec, Annotation.Label);
4977
+ const traceStr = readAnnotation(spec, Annotation.Trace);
4978
+ const baseTrace = (traceStr ? Trace.safeParse(parseJson(traceStr)).data : void 0) ?? [];
4979
+ const trace = [
4980
+ ...prefixTrace ?? [],
4981
+ ...baseTrace,
4982
+ ...suffixTrace ?? []
4821
4983
  ];
4822
- if (g !== void 0) {
4823
- const D = { label: g, type: Pt, importance: -2 };
4824
- n2.addLabelAsSuffix ? C.push(D) : C.splice(0, 0, D);
4825
- }
4826
- const w2 = [], T = /* @__PURE__ */ new Map();
4827
- for (let D = C.length - 1; D >= 0; --D) {
4828
- const { type: W } = C[D], j2 = C[D].importance ?? 0, $ = (T.get(W) ?? 0) + 1;
4829
- T.set(W, $);
4830
- const K2 = `${W}@${$}`;
4831
- s2.set(K2, (s2.get(K2) ?? 0) + 1), r.set(
4832
- K2,
4833
- Math.max(
4834
- r.get(K2) ?? Number.NEGATIVE_INFINITY,
4835
- j2 - (C.length - D) * Ct
4836
- )
4837
- ), w2.push({ ...C[D], fullType: K2, occurrenceIndex: $ });
4838
- }
4839
- return w2.reverse(), {
4840
- value: p2,
4841
- spec: f2,
4842
- label: g,
4843
- fullTrace: w2
4984
+ if (label !== void 0) {
4985
+ const labelEntry = { label, type: LabelType, importance: -2 };
4986
+ if (ops.addLabelAsSuffix)
4987
+ trace.push(labelEntry);
4988
+ else
4989
+ trace.splice(0, 0, labelEntry);
4990
+ }
4991
+ const fullTrace = [];
4992
+ const occurrences = /* @__PURE__ */ new Map();
4993
+ for (let i = trace.length - 1; i >= 0; --i) {
4994
+ const { type: typeName } = trace[i];
4995
+ const importance = trace[i].importance ?? 0;
4996
+ const occurrenceIndex = (occurrences.get(typeName) ?? 0) + 1;
4997
+ occurrences.set(typeName, occurrenceIndex);
4998
+ const fullType = `${typeName}@${occurrenceIndex}`;
4999
+ numberOfRecordsWithType.set(fullType, (numberOfRecordsWithType.get(fullType) ?? 0) + 1);
5000
+ importances.set(fullType, Math.max(importances.get(fullType) ?? Number.NEGATIVE_INFINITY, importance - (trace.length - i) * DistancePenalty));
5001
+ fullTrace.push({ ...trace[i], fullType, occurrenceIndex });
5002
+ }
5003
+ fullTrace.reverse();
5004
+ return {
5005
+ value,
5006
+ spec,
5007
+ label,
5008
+ fullTrace
4844
5009
  };
4845
- }), a = [], l2 = [], u2 = [...r];
4846
- u2.sort(([, p2], [, m2]) => m2 - p2);
4847
- for (const [p2] of u2)
4848
- p2.endsWith("@1") || s2.get(p2) === t.length ? a.push(p2) : l2.push(p2);
4849
- const c2 = (p2, m2 = false) => {
4850
- const f2 = [];
4851
- for (let v = 0; v < o.length; v++) {
4852
- const b = o[v], g = b.fullTrace.filter((C) => p2.has(C.fullType) || i && i.has(C.type));
4853
- if (g.length === 0)
4854
- if (m2)
4855
- f2.push({
5010
+ });
5011
+ const mainTypes = [];
5012
+ const secondaryTypes = [];
5013
+ const allTypeRecords = [...importances];
5014
+ allTypeRecords.sort(([, i1], [, i2]) => i2 - i1);
5015
+ for (const [typeName] of allTypeRecords) {
5016
+ if (typeName.endsWith("@1") || numberOfRecordsWithType.get(typeName) === values.length)
5017
+ mainTypes.push(typeName);
5018
+ else
5019
+ secondaryTypes.push(typeName);
5020
+ }
5021
+ const calculate = (includedTypes2, force = false) => {
5022
+ const result = [];
5023
+ for (let i = 0; i < enrichedRecords.length; i++) {
5024
+ const r = enrichedRecords[i];
5025
+ const includedTrace = r.fullTrace.filter((fm) => includedTypes2.has(fm.fullType) || forceTraceElements && forceTraceElements.has(fm.type));
5026
+ if (includedTrace.length === 0) {
5027
+ if (force)
5028
+ result.push({
4856
5029
  label: "Unlabeled",
4857
- value: b.value
5030
+ value: r.value
4858
5031
  });
4859
- else return;
4860
- const x = g.map((C) => C.label), A = n2.separator ?? " / ";
4861
- f2.push({
4862
- label: x.join(A),
4863
- value: b.value
5032
+ else
5033
+ return void 0;
5034
+ }
5035
+ const labelSet = includedTrace.map((fm) => fm.label);
5036
+ const sep = ops.separator ?? " / ";
5037
+ result.push({
5038
+ label: labelSet.join(sep),
5039
+ value: r.value
4864
5040
  });
4865
5041
  }
4866
- return f2;
5042
+ return result;
4867
5043
  };
4868
- if (a.length === 0) {
4869
- if (l2.length !== 0) throw new Error("Non-empty secondary types list while main types list is empty.");
4870
- return c2(new Set(Te), true);
4871
- }
4872
- let d = 0, h2 = -1;
4873
- for (; d < a.length; ) {
4874
- const p2 = /* @__PURE__ */ new Set();
4875
- n2.includeNativeLabel && p2.add(Te);
4876
- for (let f2 = 0; f2 < d; ++f2) p2.add(a[f2]);
4877
- h2 >= 0 && p2.add(a[h2]);
4878
- const m2 = c2(p2);
4879
- if (m2 !== void 0 && new Set(m2.map((f2) => f2.label)).size === t.length) return m2;
4880
- h2++, h2 >= a.length && (d++, h2 = d);
4881
- }
4882
- return c2(/* @__PURE__ */ new Set([...a, ...l2]), true);
4883
- }
4884
- const Z = "PColumnData/", se = Z + "ResourceMap", oe = Z + "Partitioned/ResourceMap", q = Z + "JsonPartitioned", B = Z + "BinaryPartitioned", Je = Z + "Partitioned/", ae = Je + "JsonPartitioned", z = Je + "BinaryPartitioned";
4885
- const ye = (t) => {
4886
- if (t.endsWith(".index"))
4887
- return { baseKey: t.substring(0, t.length - 6), type: "index" };
4888
- if (t.endsWith(".values"))
4889
- return { baseKey: t.substring(0, t.length - 7), type: "values" };
4890
- throw new Error(`key must ends on .index/.values for binary p-column, got: ${t}`);
5044
+ if (mainTypes.length === 0) {
5045
+ if (secondaryTypes.length !== 0)
5046
+ throw new Error("Non-empty secondary types list while main types list is empty.");
5047
+ return calculate(new Set(LabelTypeFull), true);
5048
+ }
5049
+ let includedTypes = 0;
5050
+ let additionalType = -1;
5051
+ while (includedTypes < mainTypes.length) {
5052
+ const currentSet = /* @__PURE__ */ new Set();
5053
+ if (ops.includeNativeLabel)
5054
+ currentSet.add(LabelTypeFull);
5055
+ for (let i = 0; i < includedTypes; ++i)
5056
+ currentSet.add(mainTypes[i]);
5057
+ if (additionalType >= 0)
5058
+ currentSet.add(mainTypes[additionalType]);
5059
+ const candidateResult = calculate(currentSet);
5060
+ if (candidateResult !== void 0 && new Set(candidateResult.map((c) => c.label)).size === values.length)
5061
+ return candidateResult;
5062
+ additionalType++;
5063
+ if (additionalType >= mainTypes.length) {
5064
+ includedTypes++;
5065
+ additionalType = includedTypes;
5066
+ }
5067
+ }
5068
+ return calculate(/* @__PURE__ */ new Set([...mainTypes, ...secondaryTypes]), true);
5069
+ }
5070
+ const PCD_PREFIX = "PColumnData/";
5071
+ const RT_RESOURCE_MAP = PCD_PREFIX + "ResourceMap";
5072
+ const RT_RESOURCE_MAP_PARTITIONED = PCD_PREFIX + "Partitioned/ResourceMap";
5073
+ const RT_JSON_PARTITIONED = PCD_PREFIX + "JsonPartitioned";
5074
+ const RT_BINARY_PARTITIONED = PCD_PREFIX + "BinaryPartitioned";
5075
+ const PCD_SUP_PREFIX = PCD_PREFIX + "Partitioned/";
5076
+ const RT_JSON_SUPER_PARTITIONED = PCD_SUP_PREFIX + "JsonPartitioned";
5077
+ const RT_BINARY_SUPER_PARTITIONED = PCD_SUP_PREFIX + "BinaryPartitioned";
5078
+ const removeIndexSuffix = (keyStr) => {
5079
+ if (keyStr.endsWith(".index")) {
5080
+ return { baseKey: keyStr.substring(0, keyStr.length - 6), type: "index" };
5081
+ } else if (keyStr.endsWith(".values")) {
5082
+ return { baseKey: keyStr.substring(0, keyStr.length - 7), type: "values" };
5083
+ } else {
5084
+ throw new Error(`key must ends on .index/.values for binary p-column, got: ${keyStr}`);
5085
+ }
4891
5086
  };
4892
- function St(t) {
4893
- if (!t) return;
4894
- const e = t.resourceType.name, n2 = t.getDataAsJson(), r = [];
4895
- let i = 0;
4896
- switch (e) {
4897
- case se:
4898
- i = n2.keyLength;
5087
+ function getPartitionKeysList(acc) {
5088
+ if (!acc)
5089
+ return void 0;
5090
+ const rt = acc.resourceType.name;
5091
+ const meta = acc.getDataAsJson();
5092
+ const data = [];
5093
+ let keyLength = 0;
5094
+ switch (rt) {
5095
+ case RT_RESOURCE_MAP:
5096
+ keyLength = meta["keyLength"];
4899
5097
  break;
4900
- case oe:
4901
- i = n2.partitionKeyLength + n2.keyLength;
5098
+ case RT_RESOURCE_MAP_PARTITIONED:
5099
+ keyLength = meta["partitionKeyLength"] + meta["keyLength"];
4902
5100
  break;
4903
- case q:
4904
- case B:
4905
- i = n2.partitionKeyLength;
5101
+ case RT_JSON_PARTITIONED:
5102
+ case RT_BINARY_PARTITIONED:
5103
+ keyLength = meta["partitionKeyLength"];
4906
5104
  break;
4907
- case z:
4908
- case ae:
4909
- i = n2.superPartitionKeyLength + n2.partitionKeyLength;
5105
+ case RT_BINARY_SUPER_PARTITIONED:
5106
+ case RT_JSON_SUPER_PARTITIONED:
5107
+ keyLength = meta["superPartitionKeyLength"] + meta["partitionKeyLength"];
4910
5108
  break;
4911
5109
  }
4912
- switch (e) {
4913
- case se:
4914
- case q:
4915
- case B:
4916
- for (let s2 of t.listInputFields()) {
4917
- e === B && (s2 = ye(s2).baseKey);
4918
- const o = [...JSON.parse(s2)];
4919
- r.push(o);
5110
+ switch (rt) {
5111
+ case RT_RESOURCE_MAP:
5112
+ case RT_JSON_PARTITIONED:
5113
+ case RT_BINARY_PARTITIONED:
5114
+ for (let keyStr of acc.listInputFields()) {
5115
+ if (rt === RT_BINARY_PARTITIONED) {
5116
+ keyStr = removeIndexSuffix(keyStr).baseKey;
5117
+ }
5118
+ const key = [...JSON.parse(keyStr)];
5119
+ data.push(key);
4920
5120
  }
4921
5121
  break;
4922
- case oe:
4923
- case z:
4924
- case ae:
4925
- for (const s2 of t.listInputFields()) {
4926
- const o = [...JSON.parse(s2)], a = t.resolve({ field: s2, assertFieldType: "Input" });
4927
- if (a !== void 0)
4928
- for (let l2 of a.listInputFields()) {
4929
- e === z && (l2 = ye(l2).baseKey);
4930
- const u2 = [...o, ...JSON.parse(l2)];
4931
- r.push(u2);
5122
+ case RT_RESOURCE_MAP_PARTITIONED:
5123
+ case RT_BINARY_SUPER_PARTITIONED:
5124
+ case RT_JSON_SUPER_PARTITIONED:
5125
+ for (const supKeyStr of acc.listInputFields()) {
5126
+ const keyPrefix = [...JSON.parse(supKeyStr)];
5127
+ const value = acc.resolve({ field: supKeyStr, assertFieldType: "Input" });
5128
+ if (value !== void 0) {
5129
+ for (let keyStr of value.listInputFields()) {
5130
+ if (rt === RT_BINARY_SUPER_PARTITIONED) {
5131
+ keyStr = removeIndexSuffix(keyStr).baseKey;
5132
+ }
5133
+ const key = [...keyPrefix, ...JSON.parse(keyStr)];
5134
+ data.push(key);
4932
5135
  }
5136
+ }
4933
5137
  }
4934
5138
  break;
4935
5139
  }
4936
- return { data: r, keyLength: i };
4937
- }
4938
- function _t(t) {
4939
- if (t.type !== "JsonPartitioned" && t.type !== "BinaryPartitioned")
4940
- throw new Error(`Splitting requires Partitioned DataInfoEntries, got ${t.type}`);
4941
- const { parts: e, partitionKeyLength: n2 } = t, r = [];
4942
- for (let i = 0; i < n2; ++i)
4943
- r.push(/* @__PURE__ */ new Set());
4944
- for (const i of e) {
4945
- const s2 = i.key;
4946
- if (s2.length !== n2)
4947
- throw new Error(
4948
- `Key length (${s2.length}) does not match partition length (${n2}) for key: ${JSON.stringify(
4949
- s2
4950
- )}`
4951
- );
4952
- for (let o = 0; o < n2; ++o)
4953
- r[o].add(s2[o]);
4954
- }
4955
- return r.map((i) => Array.from(i.values()));
4956
- }
4957
- function It(t) {
4958
- if (t === void 0) return;
4959
- if (K(t))
4960
- return _t(t);
4961
- const e = St(t);
4962
- if (!e) return;
4963
- const { data: n2, keyLength: r } = e, i = [];
4964
- for (let s2 = 0; s2 < r; ++s2)
4965
- i.push(/* @__PURE__ */ new Set());
4966
- for (const s2 of n2) {
4967
- if (s2.length !== r)
5140
+ return { data, keyLength };
5141
+ }
5142
+ function getUniquePartitionKeysForDataEntries(list) {
5143
+ if (list.type !== "JsonPartitioned" && list.type !== "BinaryPartitioned")
5144
+ throw new Error(`Splitting requires Partitioned DataInfoEntries, got ${list.type}`);
5145
+ const { parts, partitionKeyLength } = list;
5146
+ const result = [];
5147
+ for (let i = 0; i < partitionKeyLength; ++i) {
5148
+ result.push(/* @__PURE__ */ new Set());
5149
+ }
5150
+ for (const part of parts) {
5151
+ const key = part.key;
5152
+ if (key.length !== partitionKeyLength) {
5153
+ throw new Error(`Key length (${key.length}) does not match partition length (${partitionKeyLength}) for key: ${JSON.stringify(key)}`);
5154
+ }
5155
+ for (let i = 0; i < partitionKeyLength; ++i) {
5156
+ result[i].add(key[i]);
5157
+ }
5158
+ }
5159
+ return result.map((s) => Array.from(s.values()));
5160
+ }
5161
+ function getUniquePartitionKeys(acc) {
5162
+ if (acc === void 0)
5163
+ return void 0;
5164
+ if (isDataInfoEntries(acc))
5165
+ return getUniquePartitionKeysForDataEntries(acc);
5166
+ const list = getPartitionKeysList(acc);
5167
+ if (!list)
5168
+ return void 0;
5169
+ const { data, keyLength } = list;
5170
+ const result = [];
5171
+ for (let i = 0; i < keyLength; ++i) {
5172
+ result.push(/* @__PURE__ */ new Set());
5173
+ }
5174
+ for (const l of data) {
5175
+ if (l.length !== keyLength) {
4968
5176
  throw new Error("key length does not match partition length");
4969
- for (let o = 0; o < r; ++o)
4970
- i[o].add(s2[o]);
4971
- }
4972
- return i.map((s2) => Array.from(s2.values()));
4973
- }
4974
- function ve(t, e = []) {
4975
- if (t === void 0 || !t.getIsReadyOrError()) return;
4976
- const n2 = t.resourceType.name, r = t.getDataAsJson();
4977
- if (e.length > 0 && (n2 === ae || n2 === z))
4978
- throw new Error(`Unexpected nested super-partitioned resource: ${n2}`);
4979
- switch (n2) {
4980
- case se:
4981
- case oe:
4982
- throw new Error(`Only data columns are supported, got: ${n2}`);
4983
- case q: {
4984
- if (typeof (r == null ? void 0 : r.partitionKeyLength) != "number")
4985
- throw new Error(`Missing partitionKeyLength in metadata for ${n2}`);
4986
- const i = [];
4987
- for (const s2 of t.listInputFields()) {
4988
- const o = t.resolve({ field: s2, assertFieldType: "Input" });
4989
- if (o === void 0) return;
4990
- const a = [...e, ...JSON.parse(s2)];
4991
- i.push({ key: a, value: o });
5177
+ }
5178
+ for (let i = 0; i < keyLength; ++i) {
5179
+ result[i].add(l[i]);
5180
+ }
5181
+ }
5182
+ return result.map((s) => Array.from(s.values()));
5183
+ }
5184
+ function parsePColumnData(acc, keyPrefix = []) {
5185
+ if (acc === void 0)
5186
+ return void 0;
5187
+ if (!acc.getIsReadyOrError())
5188
+ return void 0;
5189
+ const resourceType = acc.resourceType.name;
5190
+ const meta = acc.getDataAsJson();
5191
+ if (keyPrefix.length > 0 && (resourceType === RT_JSON_SUPER_PARTITIONED || resourceType === RT_BINARY_SUPER_PARTITIONED)) {
5192
+ throw new Error(`Unexpected nested super-partitioned resource: ${resourceType}`);
5193
+ }
5194
+ switch (resourceType) {
5195
+ case RT_RESOURCE_MAP:
5196
+ case RT_RESOURCE_MAP_PARTITIONED:
5197
+ throw new Error(`Only data columns are supported, got: ${resourceType}`);
5198
+ case RT_JSON_PARTITIONED: {
5199
+ if (typeof (meta == null ? void 0 : meta.partitionKeyLength) !== "number") {
5200
+ throw new Error(`Missing partitionKeyLength in metadata for ${resourceType}`);
5201
+ }
5202
+ const parts = [];
5203
+ for (const keyStr of acc.listInputFields()) {
5204
+ const value = acc.resolve({ field: keyStr, assertFieldType: "Input" });
5205
+ if (value === void 0)
5206
+ return void 0;
5207
+ const key = [...keyPrefix, ...JSON.parse(keyStr)];
5208
+ parts.push({ key, value });
4992
5209
  }
4993
5210
  return {
4994
5211
  type: "JsonPartitioned",
4995
- partitionKeyLength: r.partitionKeyLength,
4996
- parts: i
5212
+ partitionKeyLength: meta.partitionKeyLength,
5213
+ parts
4997
5214
  };
4998
5215
  }
4999
- case B: {
5000
- if (typeof (r == null ? void 0 : r.partitionKeyLength) != "number")
5001
- throw new Error(`Missing partitionKeyLength in metadata for ${n2}`);
5002
- const i = [], s2 = /* @__PURE__ */ new Map();
5003
- for (const o of t.listInputFields()) {
5004
- const a = ye(o), l2 = t.resolve({ field: o, assertFieldType: "Input" });
5005
- if (l2 === void 0) return;
5006
- let u2 = s2.get(a.baseKey);
5007
- u2 || (u2 = {}, s2.set(a.baseKey, u2)), a.type === "index" ? u2.index = l2 : u2.values = l2;
5216
+ case RT_BINARY_PARTITIONED: {
5217
+ if (typeof (meta == null ? void 0 : meta.partitionKeyLength) !== "number") {
5218
+ throw new Error(`Missing partitionKeyLength in metadata for ${resourceType}`);
5008
5219
  }
5009
- for (const [o, a] of s2.entries()) {
5010
- if (!a.index || !a.values) return;
5011
- const l2 = [...e, ...JSON.parse(o)];
5012
- i.push({
5013
- key: l2,
5220
+ const parts = [];
5221
+ const baseKeys = /* @__PURE__ */ new Map();
5222
+ for (const keyStr of acc.listInputFields()) {
5223
+ const suffix = removeIndexSuffix(keyStr);
5224
+ const value = acc.resolve({ field: keyStr, assertFieldType: "Input" });
5225
+ if (value === void 0)
5226
+ return void 0;
5227
+ let entry = baseKeys.get(suffix.baseKey);
5228
+ if (!entry) {
5229
+ entry = {};
5230
+ baseKeys.set(suffix.baseKey, entry);
5231
+ }
5232
+ if (suffix.type === "index") {
5233
+ entry.index = value;
5234
+ } else {
5235
+ entry.values = value;
5236
+ }
5237
+ }
5238
+ for (const [baseKeyStr, entry] of baseKeys.entries()) {
5239
+ if (!entry.index || !entry.values)
5240
+ return void 0;
5241
+ const key = [...keyPrefix, ...JSON.parse(baseKeyStr)];
5242
+ parts.push({
5243
+ key,
5014
5244
  value: {
5015
- index: a.index,
5016
- values: a.values
5245
+ index: entry.index,
5246
+ values: entry.values
5017
5247
  }
5018
5248
  });
5019
5249
  }
5020
5250
  return {
5021
5251
  type: "BinaryPartitioned",
5022
- partitionKeyLength: r.partitionKeyLength,
5023
- parts: i
5252
+ partitionKeyLength: meta.partitionKeyLength,
5253
+ parts
5024
5254
  };
5025
5255
  }
5026
- case ae: {
5027
- if (typeof (r == null ? void 0 : r.superPartitionKeyLength) != "number" || typeof (r == null ? void 0 : r.partitionKeyLength) != "number")
5028
- throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${n2}`);
5029
- const i = r.superPartitionKeyLength + r.partitionKeyLength, s2 = [];
5030
- for (const o of t.listInputFields()) {
5031
- const a = t.resolve({ field: o, assertFieldType: "Input" });
5032
- if (a === void 0) return;
5033
- if (a.resourceType.name !== q)
5034
- throw new Error(`Expected ${q} inside ${n2}, but got ${a.resourceType.name}`);
5035
- const l2 = ve(a, JSON.parse(o));
5036
- if (l2 === void 0) return;
5037
- if (l2.type !== "JsonPartitioned")
5038
- throw new Error(`Unexpected inner result type for ${n2}: ${l2.type}`);
5039
- s2.push(...l2.parts);
5256
+ case RT_JSON_SUPER_PARTITIONED: {
5257
+ if (typeof (meta == null ? void 0 : meta.superPartitionKeyLength) !== "number" || typeof (meta == null ? void 0 : meta.partitionKeyLength) !== "number") {
5258
+ throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${resourceType}`);
5259
+ }
5260
+ const totalKeyLength = meta.superPartitionKeyLength + meta.partitionKeyLength;
5261
+ const parts = [];
5262
+ for (const supKeyStr of acc.listInputFields()) {
5263
+ const superPartition = acc.resolve({ field: supKeyStr, assertFieldType: "Input" });
5264
+ if (superPartition === void 0)
5265
+ return void 0;
5266
+ if (superPartition.resourceType.name !== RT_JSON_PARTITIONED) {
5267
+ throw new Error(`Expected ${RT_JSON_PARTITIONED} inside ${resourceType}, but got ${superPartition.resourceType.name}`);
5268
+ }
5269
+ const innerResult = parsePColumnData(superPartition, JSON.parse(supKeyStr));
5270
+ if (innerResult === void 0)
5271
+ return void 0;
5272
+ if (innerResult.type !== "JsonPartitioned")
5273
+ throw new Error(`Unexpected inner result type for ${resourceType}: ${innerResult.type}`);
5274
+ parts.push(...innerResult.parts);
5040
5275
  }
5041
5276
  return {
5042
5277
  type: "JsonPartitioned",
5043
- partitionKeyLength: i,
5044
- parts: s2
5278
+ partitionKeyLength: totalKeyLength,
5279
+ parts
5045
5280
  };
5046
5281
  }
5047
- case z: {
5048
- if (typeof (r == null ? void 0 : r.superPartitionKeyLength) != "number" || typeof (r == null ? void 0 : r.partitionKeyLength) != "number")
5049
- throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${n2}`);
5050
- const i = r.superPartitionKeyLength + r.partitionKeyLength, s2 = [];
5051
- for (const o of t.listInputFields()) {
5052
- const a = t.resolve({ field: o, assertFieldType: "Input" });
5053
- if (a === void 0) return;
5054
- if (a.resourceType.name !== B)
5055
- throw new Error(`Expected ${B} inside ${n2}, but got ${a.resourceType.name}`);
5056
- const l2 = ve(a, JSON.parse(o));
5057
- if (l2 === void 0) return;
5058
- if (l2.type !== "BinaryPartitioned")
5059
- throw new Error(`Unexpected inner result type for ${n2}: ${l2.type}`);
5060
- s2.push(...l2.parts);
5282
+ case RT_BINARY_SUPER_PARTITIONED: {
5283
+ if (typeof (meta == null ? void 0 : meta.superPartitionKeyLength) !== "number" || typeof (meta == null ? void 0 : meta.partitionKeyLength) !== "number") {
5284
+ throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${resourceType}`);
5285
+ }
5286
+ const totalKeyLength = meta.superPartitionKeyLength + meta.partitionKeyLength;
5287
+ const parts = [];
5288
+ for (const supKeyStr of acc.listInputFields()) {
5289
+ const superPartition = acc.resolve({ field: supKeyStr, assertFieldType: "Input" });
5290
+ if (superPartition === void 0)
5291
+ return void 0;
5292
+ if (superPartition.resourceType.name !== RT_BINARY_PARTITIONED) {
5293
+ throw new Error(`Expected ${RT_BINARY_PARTITIONED} inside ${resourceType}, but got ${superPartition.resourceType.name}`);
5294
+ }
5295
+ const innerResult = parsePColumnData(superPartition, JSON.parse(supKeyStr));
5296
+ if (innerResult === void 0)
5297
+ return void 0;
5298
+ if (innerResult.type !== "BinaryPartitioned")
5299
+ throw new Error(`Unexpected inner result type for ${resourceType}: ${innerResult.type}`);
5300
+ parts.push(...innerResult.parts);
5061
5301
  }
5062
5302
  return {
5063
5303
  type: "BinaryPartitioned",
5064
- partitionKeyLength: i,
5065
- parts: s2
5304
+ partitionKeyLength: totalKeyLength,
5305
+ parts
5066
5306
  };
5067
5307
  }
5068
5308
  default:
5069
- throw new Error(`Unknown resource type: ${n2}`);
5070
- }
5071
- }
5072
- function Tt(t) {
5073
- if (t !== void 0) {
5074
- if (K(t)) return t;
5075
- if (En(t)) return Cn(t);
5076
- if (t instanceof E) return ve(t);
5077
- throw new Error(`Unexpected input type: ${typeof t}`);
5078
- }
5079
- }
5080
- function Lt(t, e) {
5081
- const n2 = [...e].sort((s2, o) => o[0] - s2[0]);
5082
- if (t.type === "JsonPartitioned" || t.type === "BinaryPartitioned") {
5083
- const { partitionKeyLength: s2 } = t;
5084
- for (const [o] of e)
5085
- if (o >= s2)
5086
- throw new Error(`Can't filter on non-partitioned axis ${o}. Must be >= ${s2}`);
5087
- } else if (t.type === "Json") {
5088
- const { keyLength: s2 } = t;
5089
- for (const [o] of e)
5090
- if (o >= s2)
5091
- throw new Error(`Can't filter on non-data axis ${o}. Must be >= ${s2}`);
5092
- }
5093
- const r = (s2) => {
5094
- for (const [o, a] of n2)
5095
- if (s2[o] !== a)
5309
+ throw new Error(`Unknown resource type: ${resourceType}`);
5310
+ }
5311
+ }
5312
+ function convertOrParsePColumnData(acc) {
5313
+ if (acc === void 0)
5314
+ return void 0;
5315
+ if (isDataInfoEntries(acc))
5316
+ return acc;
5317
+ if (isDataInfo(acc))
5318
+ return dataInfoToEntries(acc);
5319
+ if (acc instanceof TreeNodeAccessor)
5320
+ return parsePColumnData(acc);
5321
+ throw new Error(`Unexpected input type: ${typeof acc}`);
5322
+ }
5323
+ function filterDataInfoEntries(dataInfoEntries, axisFilters) {
5324
+ const sortedFilters = [...axisFilters].sort((a, b) => b[0] - a[0]);
5325
+ const { type } = dataInfoEntries;
5326
+ switch (type) {
5327
+ case "Json": {
5328
+ const { keyLength } = dataInfoEntries;
5329
+ for (const [axisIdx] of axisFilters)
5330
+ if (axisIdx >= keyLength)
5331
+ throw new Error(`Can't filter on non-data axis ${axisIdx}. Must be >= ${keyLength}`);
5332
+ break;
5333
+ }
5334
+ case "JsonPartitioned":
5335
+ case "BinaryPartitioned":
5336
+ case "ParquetPartitioned": {
5337
+ const { partitionKeyLength } = dataInfoEntries;
5338
+ for (const [axisIdx] of axisFilters)
5339
+ if (axisIdx >= partitionKeyLength)
5340
+ throw new Error(`Can't filter on non-partitioned axis ${axisIdx}. Must be >= ${partitionKeyLength}`);
5341
+ break;
5342
+ }
5343
+ default:
5344
+ throw new Error(`Unsupported data info type: ${type}`);
5345
+ }
5346
+ const keyMatchesFilters = (key) => {
5347
+ for (const [axisIdx, axisValue] of sortedFilters)
5348
+ if (key[axisIdx] !== axisValue)
5096
5349
  return false;
5097
5350
  return true;
5098
- }, i = (s2) => {
5099
- const o = [...s2];
5100
- for (const [a] of n2)
5101
- o.splice(a, 1);
5102
- return o;
5103
5351
  };
5104
- switch (t.type) {
5105
- case "Json": {
5106
- const s2 = t.data.filter((o) => r(o.key)).map((o) => ({
5107
- key: i(o.key),
5108
- value: o.value
5109
- }));
5352
+ const removeFilteredAxes = (key) => {
5353
+ const newKey = [...key];
5354
+ for (const [axisIdx] of sortedFilters)
5355
+ newKey.splice(axisIdx, 1);
5356
+ return newKey;
5357
+ };
5358
+ switch (dataInfoEntries.type) {
5359
+ case "Json":
5110
5360
  return {
5111
5361
  type: "Json",
5112
- keyLength: t.keyLength - e.length,
5113
- data: s2
5362
+ keyLength: dataInfoEntries.keyLength - axisFilters.length,
5363
+ data: dataInfoEntries.data.filter((entry) => keyMatchesFilters(entry.key)).map((entry) => ({
5364
+ key: removeFilteredAxes(entry.key),
5365
+ value: entry.value
5366
+ }))
5114
5367
  };
5115
- }
5116
- case "JsonPartitioned": {
5117
- const s2 = t.parts.filter((o) => r(o.key)).map((o) => ({
5118
- key: i(o.key),
5119
- value: o.value
5120
- }));
5368
+ case "JsonPartitioned":
5121
5369
  return {
5122
5370
  type: "JsonPartitioned",
5123
- partitionKeyLength: t.partitionKeyLength - e.length,
5124
- parts: s2
5371
+ partitionKeyLength: dataInfoEntries.partitionKeyLength - axisFilters.length,
5372
+ parts: dataInfoEntries.parts.filter((entry) => keyMatchesFilters(entry.key)).map((entry) => ({
5373
+ key: removeFilteredAxes(entry.key),
5374
+ value: entry.value
5375
+ }))
5125
5376
  };
5126
- }
5127
- case "BinaryPartitioned": {
5128
- const s2 = t.parts.filter((o) => r(o.key)).map((o) => ({
5129
- key: i(o.key),
5130
- value: o.value
5131
- }));
5377
+ case "BinaryPartitioned":
5132
5378
  return {
5133
5379
  type: "BinaryPartitioned",
5134
- partitionKeyLength: t.partitionKeyLength - e.length,
5135
- parts: s2
5380
+ partitionKeyLength: dataInfoEntries.partitionKeyLength - axisFilters.length,
5381
+ parts: dataInfoEntries.parts.filter((entry) => keyMatchesFilters(entry.key)).map((entry) => ({
5382
+ key: removeFilteredAxes(entry.key),
5383
+ value: entry.value
5384
+ }))
5385
+ };
5386
+ case "ParquetPartitioned":
5387
+ return {
5388
+ type: "ParquetPartitioned",
5389
+ partitionKeyLength: dataInfoEntries.partitionKeyLength - axisFilters.length,
5390
+ parts: dataInfoEntries.parts.filter((entry) => keyMatchesFilters(entry.key)).map((entry) => ({
5391
+ key: removeFilteredAxes(entry.key),
5392
+ value: entry.value
5393
+ }))
5136
5394
  };
5137
- }
5138
5395
  }
5139
5396
  }
5140
- function Et(t) {
5141
- if (!Array.isArray(t)) return false;
5142
- if (t.length === 0) return true;
5143
- const e = t[0];
5144
- return typeof e == "object" && e !== null && "key" in e && "val" in e;
5397
+ function isPColumnValues(value) {
5398
+ if (!Array.isArray(value))
5399
+ return false;
5400
+ if (value.length === 0)
5401
+ return true;
5402
+ const first = value[0];
5403
+ return typeof first === "object" && first !== null && "key" in first && "val" in first;
5145
5404
  }
5146
- class Dt {
5147
- constructor(e) {
5148
- this.columns = e;
5405
+ class ArrayColumnProvider {
5406
+ constructor(columns) {
5407
+ __publicField(this, "columns");
5408
+ this.columns = columns;
5149
5409
  }
5150
- selectColumns(e) {
5151
- const n2 = typeof e == "function" ? e : Gn(e);
5152
- return this.columns.filter((r) => n2(r.spec));
5410
+ selectColumns(selectors) {
5411
+ const predicate = typeof selectors === "function" ? selectors : selectorsToPredicate(selectors);
5412
+ return this.columns.filter((column) => predicate(column.spec));
5153
5413
  }
5154
5414
  }
5155
- function kt(t) {
5156
- if (t)
5157
- return t.map((e) => ({
5158
- type: `split:${Rn(e.axisId)}`,
5159
- label: e.label,
5160
- importance: 1e6
5161
- // High importance for split filters in labels
5162
- }));
5163
- }
5164
- function Ot(t) {
5165
- if (t)
5166
- return t.map((e) => [e.axisIdx, e.value]);
5415
+ function splitFiltersToTrace(splitFilters) {
5416
+ if (!splitFilters)
5417
+ return void 0;
5418
+ return splitFilters.map((filter) => ({
5419
+ type: `split:${canonicalizeAxisId(filter.axisId)}`,
5420
+ label: filter.label,
5421
+ importance: 1e6
5422
+ // High importance for split filters in labels
5423
+ }));
5424
+ }
5425
+ function splitFiltersToAxisFilter(splitFilters) {
5426
+ if (!splitFilters)
5427
+ return void 0;
5428
+ return splitFilters.map((filter) => [filter.axisIdx, filter.value]);
5167
5429
  }
5168
- function Rt(t, e) {
5169
- if (!e || e.length === 0) return t;
5170
- const n2 = [...e].sort((r, i) => r[0] - i[0]);
5171
- return Re({ id: t, axisFilters: n2 });
5430
+ function fallbackIdDeriver(originalId, axisFilters) {
5431
+ if (!axisFilters || axisFilters.length === 0)
5432
+ return originalId;
5433
+ const filtersToCanonicalize = [...axisFilters].sort((a, b) => a[0] - b[0]);
5434
+ return canonicalize({ id: originalId, axisFilters: filtersToCanonicalize });
5172
5435
  }
5173
- function Le(t) {
5174
- if (!t || typeof t != "object") return false;
5175
- 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);
5176
- return !!e.domainAnchor || n2 || r;
5436
+ function hasAnchors(selector) {
5437
+ if (!selector || typeof selector !== "object")
5438
+ return false;
5439
+ const potentialAnchored = selector;
5440
+ const domainHasAnchors = potentialAnchored["domain"] && typeof potentialAnchored["domain"] === "object" && Object.values(potentialAnchored["domain"]).some((v) => typeof v === "object" && v !== null && "anchor" in v);
5441
+ const axesHaveAnchors = potentialAnchored["axes"] && Array.isArray(potentialAnchored["axes"]) && potentialAnchored["axes"].some((a) => typeof a === "object" && a !== null && "anchor" in a);
5442
+ return !!potentialAnchored["domainAnchor"] || domainHasAnchors || axesHaveAnchors;
5177
5443
  }
5178
- function Ft(t) {
5179
- if (typeof t != "object" || !("axes" in t) || t.axes === void 0)
5444
+ function getSplitAxisIndices(selector) {
5445
+ if (typeof selector !== "object" || !("axes" in selector) || selector.axes === void 0) {
5180
5446
  return [];
5181
- const e = t.axes.map((n2, r) => typeof n2 == "object" && "split" in n2 && n2.split === true ? r : -1).filter((n2) => n2 !== -1);
5182
- if (e.length > 0 && t.partialAxesMatch !== void 0)
5447
+ }
5448
+ const splitIndices = selector.axes.map((axis, index) => typeof axis === "object" && "split" in axis && axis.split === true ? index : -1).filter((index) => index !== -1);
5449
+ if (splitIndices.length > 0 && selector.partialAxesMatch !== void 0) {
5183
5450
  throw new Error("Axis splitting is not supported when `partialAxesMatch` is defined.");
5184
- return e.sort((n2, r) => n2 - r), e;
5451
+ }
5452
+ splitIndices.sort((a, b) => a - b);
5453
+ return splitIndices;
5185
5454
  }
5186
- class le {
5455
+ class PColumnCollection {
5187
5456
  constructor() {
5188
- k(this, "defaultProviderStore", []);
5189
- k(this, "providers", [new Dt(this.defaultProviderStore)]);
5190
- k(this, "axisLabelProviders", []);
5457
+ __publicField(this, "defaultProviderStore", []);
5458
+ __publicField(this, "providers", [new ArrayColumnProvider(this.defaultProviderStore)]);
5459
+ __publicField(this, "axisLabelProviders", []);
5191
5460
  }
5192
- addColumnProvider(e) {
5193
- return this.providers.push(e), this;
5461
+ addColumnProvider(provider) {
5462
+ this.providers.push(provider);
5463
+ return this;
5194
5464
  }
5195
- addAxisLabelProvider(e) {
5196
- return this.axisLabelProviders.push(e), this;
5465
+ addAxisLabelProvider(provider) {
5466
+ this.axisLabelProviders.push(provider);
5467
+ return this;
5197
5468
  }
5198
- addColumns(e) {
5199
- return this.defaultProviderStore.push(...e), this;
5469
+ addColumns(columns) {
5470
+ this.defaultProviderStore.push(...columns);
5471
+ return this;
5200
5472
  }
5201
- addColumn(e) {
5202
- return this.defaultProviderStore.push(e), this;
5473
+ addColumn(column) {
5474
+ this.defaultProviderStore.push(column);
5475
+ return this;
5203
5476
  }
5204
5477
  /** Fetches labels for a given axis from the registered providers */
5205
- findLabels(e) {
5206
- for (const n2 of this.axisLabelProviders) {
5207
- const r = n2.findLabels(e);
5208
- if (r) return r;
5478
+ findLabels(axis) {
5479
+ for (const provider of this.axisLabelProviders) {
5480
+ const labels = provider.findLabels(axis);
5481
+ if (labels)
5482
+ return labels;
5209
5483
  }
5484
+ return void 0;
5210
5485
  }
5211
- getUniversalEntries(e, n2) {
5212
- const { anchorCtx: r, labelOps: i, dontWaitAllData: s2 = false, overrideLabelAnnotation: o = false, exclude: a } = n2 ?? {}, l2 = {
5213
- ...o && (i == null ? void 0 : i.includeNativeLabel) !== false ? { includeNativeLabel: true } : {},
5214
- ...i ?? {}
5486
+ getUniversalEntries(predicateOrSelectors, opts) {
5487
+ const { anchorCtx, labelOps: rawLabelOps, dontWaitAllData = false, overrideLabelAnnotation = false, exclude } = opts ?? {};
5488
+ const labelOps = {
5489
+ ...overrideLabelAnnotation && (rawLabelOps == null ? void 0 : rawLabelOps.includeNativeLabel) !== false ? { includeNativeLabel: true } : {},
5490
+ ...rawLabelOps ?? {}
5215
5491
  };
5216
- let u2 = () => false;
5217
- if (a) {
5218
- const f2 = (Array.isArray(a) ? a : [a]).map((v) => {
5219
- if (Le(v)) {
5220
- if (!r)
5492
+ let excludePredicate = () => false;
5493
+ if (exclude) {
5494
+ const excludePredicartes = (Array.isArray(exclude) ? exclude : [exclude]).map((selector) => {
5495
+ if (hasAnchors(selector)) {
5496
+ if (!anchorCtx)
5221
5497
  throw new Error("Anchored selectors in exclude require an AnchoredIdDeriver to be provided in options.");
5222
- return Gn(Mn(r.anchors, v, n2));
5498
+ return selectorsToPredicate(resolveAnchors(anchorCtx.anchors, selector, opts));
5223
5499
  } else
5224
- return Gn(v);
5500
+ return selectorsToPredicate(selector);
5225
5501
  });
5226
- u2 = (v) => f2.some((b) => b(v));
5227
- }
5228
- const c2 = typeof e == "function" ? [e] : Array.isArray(e) ? e : [e], d = [], h2 = /* @__PURE__ */ new Set();
5229
- for (const f$1 of c2) {
5230
- const v = Le(f$1);
5231
- let b;
5232
- if (v) {
5233
- if (!r)
5502
+ excludePredicate = (spec) => excludePredicartes.some((predicate) => predicate(spec));
5503
+ }
5504
+ const selectorsArray = typeof predicateOrSelectors === "function" ? [predicateOrSelectors] : Array.isArray(predicateOrSelectors) ? predicateOrSelectors : [predicateOrSelectors];
5505
+ const intermediateResults = [];
5506
+ const selectedNativeIds = /* @__PURE__ */ new Set();
5507
+ for (const rawSelector of selectorsArray) {
5508
+ const usesAnchors = hasAnchors(rawSelector);
5509
+ let currentSelector;
5510
+ if (usesAnchors) {
5511
+ if (!anchorCtx)
5234
5512
  throw new Error("Anchored selectors require an AnchoredIdDeriver to be provided in options.");
5235
- b = Mn(r.anchors, f$1, n2);
5513
+ currentSelector = resolveAnchors(anchorCtx.anchors, rawSelector, opts);
5236
5514
  } else
5237
- b = f$1;
5238
- const g = /* @__PURE__ */ new Set(), x = [];
5239
- for (const w2 of this.providers) {
5240
- const T = w2.selectColumns(b);
5241
- for (const S of T) {
5242
- if (u2(S.spec)) continue;
5243
- if (g.has(S.id))
5244
- throw new Error(`Duplicate column id ${S.id} in provider ${w2.constructor.name}`);
5245
- const F = Qn(S.spec);
5246
- h2.has(F) || (g.add(S.id), h2.add(F), x.push(S));
5515
+ currentSelector = rawSelector;
5516
+ const selectedIds = /* @__PURE__ */ new Set();
5517
+ const selectedColumns = [];
5518
+ for (const provider of this.providers) {
5519
+ const providerColumns = provider.selectColumns(currentSelector);
5520
+ for (const col of providerColumns) {
5521
+ if (excludePredicate(col.spec))
5522
+ continue;
5523
+ if (selectedIds.has(col.id))
5524
+ throw new Error(`Duplicate column id ${col.id} in provider ${provider.constructor.name}`);
5525
+ const nativeId = deriveNativeId(col.spec);
5526
+ if (selectedNativeIds.has(nativeId))
5527
+ continue;
5528
+ selectedIds.add(col.id);
5529
+ selectedNativeIds.add(nativeId);
5530
+ selectedColumns.push(col);
5247
5531
  }
5248
5532
  }
5249
- if (x.length === 0) continue;
5250
- const A = Ft(f$1), C = A.length > 0;
5251
- for (const w2 of x) {
5252
- if (!f(w2.spec)) continue;
5253
- const T = w2.spec;
5254
- if (C) {
5255
- if (Et(w2.data))
5256
- throw new Error(`Splitting is not supported for PColumns with PColumnValues data format. Column id: ${w2.id}`);
5257
- const S = Tt(w2.data);
5258
- if (!S) {
5259
- if (s2) continue;
5260
- return;
5533
+ if (selectedColumns.length === 0)
5534
+ continue;
5535
+ const splitAxisIdxs = getSplitAxisIndices(rawSelector);
5536
+ const needsSplitting = splitAxisIdxs.length > 0;
5537
+ for (const column of selectedColumns) {
5538
+ if (!isPColumnSpec(column.spec))
5539
+ continue;
5540
+ const originalSpec = column.spec;
5541
+ if (needsSplitting) {
5542
+ if (isPColumnValues(column.data))
5543
+ throw new Error(`Splitting is not supported for PColumns with PColumnValues data format. Column id: ${column.id}`);
5544
+ const dataEntries = convertOrParsePColumnData(column.data);
5545
+ if (!dataEntries) {
5546
+ if (dontWaitAllData)
5547
+ continue;
5548
+ return void 0;
5261
5549
  }
5262
- if (!Sn(S))
5263
- throw new Error(`Splitting requires Partitioned DataInfoEntries, but parsing resulted in ${S.type} for column ${w2.id}`);
5264
- const F = It(S), D = A[A.length - 1];
5265
- if (D >= S.partitionKeyLength)
5266
- throw new Error(`Not enough partition keys (${S.partitionKeyLength}) for requested split axes (max index ${D}) in column ${T.name}`);
5267
- const W = A.map((_) => this.findLabels(p$1(T.axesSpec[_]))), j2 = [], $ = (_, G) => {
5268
- if (G >= A.length) {
5269
- if (j2.push([..._]), j2.length > 1e4)
5550
+ if (!isPartitionedDataInfoEntries(dataEntries))
5551
+ throw new Error(`Splitting requires Partitioned DataInfoEntries, but parsing resulted in ${dataEntries.type} for column ${column.id}`);
5552
+ const uniqueKeys = getUniquePartitionKeys(dataEntries);
5553
+ const maxSplitIdx = splitAxisIdxs[splitAxisIdxs.length - 1];
5554
+ if (maxSplitIdx >= dataEntries.partitionKeyLength)
5555
+ throw new Error(`Not enough partition keys (${dataEntries.partitionKeyLength}) for requested split axes (max index ${maxSplitIdx}) in column ${originalSpec.name}`);
5556
+ const axesLabels = splitAxisIdxs.map((idx) => this.findLabels(getAxisId(originalSpec.axesSpec[idx])));
5557
+ const keyCombinations = [];
5558
+ const generateCombinations = (currentCombo, sAxisIdx) => {
5559
+ if (sAxisIdx >= splitAxisIdxs.length) {
5560
+ keyCombinations.push([...currentCombo]);
5561
+ if (keyCombinations.length > 1e4)
5270
5562
  throw new Error("Too many key combinations, aborting.");
5271
5563
  return;
5272
5564
  }
5273
- const N2 = A[G];
5274
- if (N2 >= F.length)
5275
- throw new Error(`Axis index ${N2} out of bounds for unique keys array (length ${F.length}) during split key generation for column ${w2.id}`);
5276
- const J2 = F[N2];
5277
- if (!J2 || J2.length === 0) {
5278
- j2.length = 0;
5565
+ const axisIdx = splitAxisIdxs[sAxisIdx];
5566
+ if (axisIdx >= uniqueKeys.length)
5567
+ throw new Error(`Axis index ${axisIdx} out of bounds for unique keys array (length ${uniqueKeys.length}) during split key generation for column ${column.id}`);
5568
+ const axisValues = uniqueKeys[axisIdx];
5569
+ if (!axisValues || axisValues.length === 0) {
5570
+ keyCombinations.length = 0;
5279
5571
  return;
5280
5572
  }
5281
- for (const ee of J2)
5282
- _.push(ee), $(_, G + 1), _.pop();
5573
+ for (const val of axisValues) {
5574
+ currentCombo.push(val);
5575
+ generateCombinations(currentCombo, sAxisIdx + 1);
5576
+ currentCombo.pop();
5577
+ }
5283
5578
  };
5284
- if ($([], 0), j2.length === 0)
5579
+ generateCombinations([], 0);
5580
+ if (keyCombinations.length === 0)
5285
5581
  continue;
5286
- const K2 = [...T.axesSpec], Ge = A.map((_) => _);
5287
- for (let _ = A.length - 1; _ >= 0; _--)
5288
- K2.splice(A[_], 1);
5289
- const He = { ...T, axesSpec: K2 };
5290
- for (const _ of j2) {
5291
- const G = _.map((N2, J2) => {
5292
- const ee = Ge[J2], qe = p$1(T.axesSpec[ee]), ce = W[J2], ze = (ce == null ? void 0 : ce[N2]) ?? String(N2);
5293
- return { axisIdx: ee, axisId: qe, value: N2, label: ze };
5582
+ const newAxesSpec = [...originalSpec.axesSpec];
5583
+ const splitAxisOriginalIdxs = splitAxisIdxs.map((idx) => idx);
5584
+ for (let i = splitAxisIdxs.length - 1; i >= 0; i--) {
5585
+ newAxesSpec.splice(splitAxisIdxs[i], 1);
5586
+ }
5587
+ const adjustedSpec = { ...originalSpec, axesSpec: newAxesSpec };
5588
+ for (const keyCombo of keyCombinations) {
5589
+ const splitFilters = keyCombo.map((value, sAxisIdx) => {
5590
+ const axisIdx = splitAxisOriginalIdxs[sAxisIdx];
5591
+ const axisId = getAxisId(originalSpec.axesSpec[axisIdx]);
5592
+ const axisLabelMap = axesLabels[sAxisIdx];
5593
+ const label = (axisLabelMap == null ? void 0 : axisLabelMap[value]) ?? String(value);
5594
+ return { axisIdx, axisId, value, label };
5294
5595
  });
5295
- d.push({
5596
+ intermediateResults.push({
5296
5597
  type: "split",
5297
- originalColumn: w2,
5298
- spec: T,
5299
- adjustedSpec: He,
5300
- dataEntries: S,
5301
- axisFilters: G
5598
+ originalColumn: column,
5599
+ spec: originalSpec,
5600
+ adjustedSpec,
5601
+ dataEntries,
5602
+ axisFilters: splitFilters
5302
5603
  });
5303
5604
  }
5304
- } else
5305
- d.push({
5605
+ } else {
5606
+ intermediateResults.push({
5306
5607
  type: "direct",
5307
- originalColumn: w2,
5308
- spec: T,
5309
- adjustedSpec: T
5608
+ originalColumn: column,
5609
+ spec: originalSpec,
5610
+ adjustedSpec: originalSpec
5310
5611
  });
5612
+ }
5311
5613
  }
5312
5614
  }
5313
- if (d.length === 0) return [];
5314
- const p2 = $e(
5315
- d,
5316
- (f2) => ({
5317
- spec: f2.spec,
5318
- suffixTrace: f2.type === "split" ? kt(f2.axisFilters) : void 0
5319
- }),
5320
- l2
5321
- ), m2 = [];
5322
- for (const { value: f2, label: v } of p2) {
5323
- const { originalColumn: b, spec: g } = f2, x = f2.type === "split" ? f2.axisFilters : void 0, A = Ot(x);
5324
- let C;
5325
- r ? C = r.deriveS(g, A) : C = Rt(b.id, A);
5326
- let w2 = { ...f2.adjustedSpec };
5327
- o && (w2 = {
5328
- ...w2,
5329
- annotations: {
5330
- ...w2.annotations ?? {},
5331
- "pl7.app/label": v
5332
- }
5333
- }), m2.push({
5334
- id: C,
5335
- spec: w2,
5336
- data: () => f2.type === "split" ? Jn(Lt(f2.dataEntries, A)) : f2.originalColumn.data,
5337
- label: v
5615
+ if (intermediateResults.length === 0)
5616
+ return [];
5617
+ const labeledResults = deriveLabels(intermediateResults, (entry) => ({
5618
+ spec: entry.spec,
5619
+ suffixTrace: entry.type === "split" ? splitFiltersToTrace(entry.axisFilters) : void 0
5620
+ }), labelOps);
5621
+ const result = [];
5622
+ for (const { value: entry, label } of labeledResults) {
5623
+ const { originalColumn, spec: originalSpec } = entry;
5624
+ const axisFilters = entry.type === "split" ? entry.axisFilters : void 0;
5625
+ const axisFiltersTuple = splitFiltersToAxisFilter(axisFilters);
5626
+ let finalId;
5627
+ if (anchorCtx)
5628
+ finalId = anchorCtx.deriveS(originalSpec, axisFiltersTuple);
5629
+ else
5630
+ finalId = fallbackIdDeriver(originalColumn.id, axisFiltersTuple);
5631
+ let finalSpec = { ...entry.adjustedSpec };
5632
+ if (overrideLabelAnnotation) {
5633
+ finalSpec = {
5634
+ ...finalSpec,
5635
+ annotations: {
5636
+ ...finalSpec.annotations ?? {},
5637
+ [Annotation.Label]: label
5638
+ }
5639
+ };
5640
+ }
5641
+ result.push({
5642
+ id: finalId,
5643
+ spec: finalSpec,
5644
+ data: () => entry.type === "split" ? entriesToDataInfo(filterDataInfoEntries(entry.dataEntries, axisFiltersTuple)) : entry.originalColumn.data,
5645
+ label
5338
5646
  });
5339
5647
  }
5340
- return m2;
5648
+ return result;
5341
5649
  }
5342
- getColumns(e, n2) {
5343
- const r = this.getUniversalEntries(e, {
5650
+ getColumns(predicateOrSelectors, opts) {
5651
+ const entries = this.getUniversalEntries(predicateOrSelectors, {
5344
5652
  overrideLabelAnnotation: true,
5345
5653
  // default for getColumns
5346
- ...n2 ?? {}
5654
+ ...opts ?? {}
5347
5655
  });
5348
- if (!r) return;
5349
- const i = [];
5350
- for (const s2 of r) {
5351
- const o = s2.data();
5352
- if (!o) {
5353
- if (n2 != null && n2.dontWaitAllData) continue;
5354
- return;
5656
+ if (!entries)
5657
+ return void 0;
5658
+ const columns = [];
5659
+ for (const entry of entries) {
5660
+ const data = entry.data();
5661
+ if (!data) {
5662
+ if (opts == null ? void 0 : opts.dontWaitAllData)
5663
+ continue;
5664
+ return void 0;
5355
5665
  }
5356
- i.push({
5357
- id: s2.id,
5358
- spec: s2.spec,
5359
- data: o
5666
+ columns.push({
5667
+ id: entry.id,
5668
+ spec: entry.spec,
5669
+ data
5360
5670
  });
5361
5671
  }
5362
- return i;
5672
+ return columns;
5363
5673
  }
5364
5674
  }
5365
- function pe(t, e) {
5366
- if (t === void 0) return e === void 0;
5367
- if (e === void 0) return true;
5368
- for (const n2 in e)
5369
- if (t[n2] !== e[n2]) return false;
5675
+ function patchInSetFilters(filters) {
5676
+ const inSetToOrEqual = (predicate) => {
5677
+ if (predicate.operator !== "InSet")
5678
+ return predicate;
5679
+ return {
5680
+ operator: "Or",
5681
+ operands: predicate.references.map((reference) => ({
5682
+ operator: "Equal",
5683
+ reference
5684
+ }))
5685
+ };
5686
+ };
5687
+ const mapSingleValuePredicate = (filter, cb) => {
5688
+ const operator = filter.operator;
5689
+ switch (operator) {
5690
+ case "And":
5691
+ return {
5692
+ ...filter,
5693
+ operands: filter.operands.map((operand) => mapSingleValuePredicate(operand, cb))
5694
+ };
5695
+ case "Or":
5696
+ return {
5697
+ ...filter,
5698
+ operands: filter.operands.map((operand) => mapSingleValuePredicate(operand, cb))
5699
+ };
5700
+ case "Not":
5701
+ return {
5702
+ ...filter,
5703
+ operand: mapSingleValuePredicate(filter.operand, cb)
5704
+ };
5705
+ default:
5706
+ return cb(filter);
5707
+ }
5708
+ };
5709
+ const mapFilter = (filter, cb) => {
5710
+ return {
5711
+ ...filter,
5712
+ predicate: mapSingleValuePredicate(filter.predicate, cb)
5713
+ };
5714
+ };
5715
+ return filters.map((filter) => mapFilter(filter, inSetToOrEqual));
5716
+ }
5717
+ function matchDomain(query, target) {
5718
+ if (query === void 0)
5719
+ return target === void 0;
5720
+ if (target === void 0)
5721
+ return true;
5722
+ for (const k in target) {
5723
+ if (query[k] !== target[k])
5724
+ return false;
5725
+ }
5370
5726
  return true;
5371
5727
  }
5372
- function Ee(t) {
5373
- return Wn(t, (e) => e instanceof E ? e.handle : En(e) ? Nn(e, (n2) => n2.handle) : e);
5728
+ function transformPColumnData(data) {
5729
+ return mapPObjectData(data, (d) => {
5730
+ if (d instanceof TreeNodeAccessor) {
5731
+ return d.handle;
5732
+ } else if (isDataInfo(d)) {
5733
+ return mapDataInfo(d, (accessor) => accessor.handle);
5734
+ } else {
5735
+ return d;
5736
+ }
5737
+ });
5374
5738
  }
5375
- class Kt {
5739
+ class ResultPool {
5376
5740
  constructor() {
5377
- k(this, "ctx", y());
5741
+ __publicField(this, "ctx", getCfgRenderCtx());
5378
5742
  }
5379
5743
  /**
5380
5744
  * @deprecated use getOptions()
5381
5745
  */
5382
- calculateOptions(e) {
5383
- return this.ctx.calculateOptions(e);
5384
- }
5385
- getOptions(e, n2) {
5386
- const r = typeof e == "function" ? e : Gn(e), i = this.getSpecs().entries.filter((a) => r(a.obj));
5387
- let s2 = {}, o = false;
5388
- return typeof n2 < "u" && (typeof n2 == "function" ? s2 = n2 : typeof n2 == "object" && ("includeNativeLabel" in n2 || "separator" in n2 || "addLabelAsSuffix" in n2 ? s2 = n2 : (n2 = n2, s2 = n2.label ?? {}, o = n2.refsWithEnrichments ?? false))), typeof s2 == "object" ? $e(i, (a) => a.obj, s2 ?? {}).map(({ value: { ref: a }, label: l2 }) => ({
5389
- ref: te$1(a, o),
5390
- label: l2
5391
- })) : i.map(({ ref: a, obj: l2 }) => ({
5392
- ref: te$1(a, o),
5393
- label: s2(l2, a)
5394
- }));
5746
+ calculateOptions(predicate) {
5747
+ return this.ctx.calculateOptions(predicate);
5748
+ }
5749
+ getOptions(predicateOrSelector, opts) {
5750
+ const predicate = typeof predicateOrSelector === "function" ? predicateOrSelector : selectorsToPredicate(predicateOrSelector);
5751
+ const filtered = this.getSpecs().entries.filter((s) => predicate(s.obj));
5752
+ let labelOps = {};
5753
+ let refsWithEnrichments = false;
5754
+ if (typeof opts !== "undefined") {
5755
+ if (typeof opts === "function") {
5756
+ labelOps = opts;
5757
+ } else if (typeof opts === "object") {
5758
+ if ("includeNativeLabel" in opts || "separator" in opts || "addLabelAsSuffix" in opts) {
5759
+ labelOps = opts;
5760
+ } else {
5761
+ opts = opts;
5762
+ labelOps = opts.label ?? {};
5763
+ refsWithEnrichments = opts.refsWithEnrichments ?? false;
5764
+ }
5765
+ }
5766
+ }
5767
+ if (typeof labelOps === "object")
5768
+ return deriveLabels(filtered, (o) => o.obj, labelOps ?? {}).map(({ value: { ref }, label }) => ({
5769
+ ref: withEnrichments(ref, refsWithEnrichments),
5770
+ label
5771
+ }));
5772
+ else
5773
+ return filtered.map(({ ref, obj }) => ({
5774
+ ref: withEnrichments(ref, refsWithEnrichments),
5775
+ label: labelOps(obj, ref)
5776
+ }));
5395
5777
  }
5396
- resolveAnchorCtx(e) {
5397
- if (e instanceof _n) return e;
5398
- const n2 = {};
5399
- for (const [r, i] of Object.entries(e))
5400
- if (ne(i)) {
5401
- const s2 = this.getPColumnSpecByRef(i);
5402
- if (!s2)
5403
- return;
5404
- n2[r] = s2;
5405
- } else
5406
- n2[r] = i;
5407
- return new _n(n2);
5778
+ resolveAnchorCtx(anchorsOrCtx) {
5779
+ if (anchorsOrCtx instanceof AnchoredIdDeriver)
5780
+ return anchorsOrCtx;
5781
+ const resolvedAnchors = {};
5782
+ for (const [key, value] of Object.entries(anchorsOrCtx)) {
5783
+ if (isPlRef(value)) {
5784
+ const resolvedSpec = this.getPColumnSpecByRef(value);
5785
+ if (!resolvedSpec)
5786
+ return void 0;
5787
+ resolvedAnchors[key] = resolvedSpec;
5788
+ } else {
5789
+ resolvedAnchors[key] = value;
5790
+ }
5791
+ }
5792
+ return new AnchoredIdDeriver(resolvedAnchors);
5408
5793
  }
5409
5794
  /**
5410
5795
  * Returns columns that match the provided anchors and selectors. It applies axis filters and label derivation.
@@ -5414,13 +5799,14 @@
5414
5799
  * @param opts - Optional configuration for label generation and data waiting
5415
5800
  * @returns A PFrameHandle for the created PFrame, or undefined if any required data is missing
5416
5801
  */
5417
- getAnchoredPColumns(e, n2, r) {
5418
- const i = this.resolveAnchorCtx(e);
5419
- if (i)
5420
- return new le().addColumnProvider(this).addAxisLabelProvider(this).getColumns(n2, {
5421
- ...r,
5422
- anchorCtx: i
5423
- });
5802
+ getAnchoredPColumns(anchorsOrCtx, predicateOrSelectors, opts) {
5803
+ const anchorCtx = this.resolveAnchorCtx(anchorsOrCtx);
5804
+ if (!anchorCtx)
5805
+ return void 0;
5806
+ return new PColumnCollection().addColumnProvider(this).addAxisLabelProvider(this).getColumns(predicateOrSelectors, {
5807
+ ...opts,
5808
+ anchorCtx
5809
+ });
5424
5810
  }
5425
5811
  /**
5426
5812
  * Calculates anchored identifier options for columns matching a given predicate and returns their
@@ -5451,18 +5837,20 @@
5451
5837
  * @returns An array of objects with `label` (display text) and `value` (anchored ID string) properties,
5452
5838
  * or undefined if any PlRef resolution fails.
5453
5839
  */
5454
- getCanonicalOptions(e, n2, r) {
5455
- const i = this.resolveAnchorCtx(e);
5456
- if (!i) return;
5457
- const s2 = new le().addColumnProvider(this).addAxisLabelProvider(this).getUniversalEntries(n2, {
5458
- ...r,
5459
- anchorCtx: i
5840
+ getCanonicalOptions(anchorsOrCtx, predicateOrSelectors, opts) {
5841
+ const anchorCtx = this.resolveAnchorCtx(anchorsOrCtx);
5842
+ if (!anchorCtx)
5843
+ return void 0;
5844
+ const entries = new PColumnCollection().addColumnProvider(this).addAxisLabelProvider(this).getUniversalEntries(predicateOrSelectors, {
5845
+ ...opts,
5846
+ anchorCtx
5460
5847
  });
5461
- if (s2)
5462
- return s2.map((o) => ({
5463
- value: o.id,
5464
- label: o.label
5465
- }));
5848
+ if (!entries)
5849
+ return void 0;
5850
+ return entries.map((item) => ({
5851
+ value: item.id,
5852
+ label: item.label
5853
+ }));
5466
5854
  }
5467
5855
  /**
5468
5856
  * @deprecated use getData()
@@ -5471,14 +5859,14 @@
5471
5859
  return this.getData();
5472
5860
  }
5473
5861
  getData() {
5474
- const e = this.ctx.getDataFromResultPool();
5862
+ const result = this.ctx.getDataFromResultPool();
5475
5863
  return {
5476
- isComplete: e.isComplete,
5477
- entries: e.entries.map((n2) => ({
5478
- ref: n2.ref,
5864
+ isComplete: result.isComplete,
5865
+ entries: result.entries.map((e) => ({
5866
+ ref: e.ref,
5479
5867
  obj: {
5480
- ...n2.obj,
5481
- data: new E(n2.obj.data, [n2.ref.blockId, n2.ref.name])
5868
+ ...e.obj,
5869
+ data: new TreeNodeAccessor(e.obj.data, [e.ref.blockId, e.ref.name])
5482
5870
  }
5483
5871
  }))
5484
5872
  };
@@ -5490,17 +5878,14 @@
5490
5878
  return this.getDataWithErrors();
5491
5879
  }
5492
5880
  getDataWithErrors() {
5493
- const e = this.ctx.getDataWithErrorsFromResultPool();
5881
+ const result = this.ctx.getDataWithErrorsFromResultPool();
5494
5882
  return {
5495
- isComplete: e.isComplete,
5496
- entries: e.entries.map((n2) => ({
5497
- ref: n2.ref,
5883
+ isComplete: result.isComplete,
5884
+ entries: result.entries.map((e) => ({
5885
+ ref: e.ref,
5498
5886
  obj: {
5499
- ...n2.obj,
5500
- data: oe$1(
5501
- n2.obj.data,
5502
- (r) => new E(r, [n2.ref.blockId, n2.ref.name])
5503
- )
5887
+ ...e.obj,
5888
+ data: mapValueInVOE(e.obj.data, (handle) => new TreeNodeAccessor(handle, [e.ref.blockId, e.ref.name]))
5504
5889
  }
5505
5890
  }))
5506
5891
  };
@@ -5518,89 +5903,106 @@
5518
5903
  * @param ref a Ref
5519
5904
  * @returns data associated with the ref
5520
5905
  */
5521
- getDataByRef(e) {
5522
- var r;
5523
- if (typeof this.ctx.getDataFromResultPoolByRef > "u")
5524
- return (r = this.getData().entries.find(
5525
- (i) => i.ref.blockId === e.blockId && i.ref.name === e.name
5526
- )) == null ? void 0 : r.obj;
5527
- const n2 = this.ctx.getDataFromResultPoolByRef(e.blockId, e.name);
5528
- if (n2)
5529
- return Wn(
5530
- n2,
5531
- (i) => new E(i, [e.blockId, e.name])
5532
- );
5906
+ getDataByRef(ref) {
5907
+ var _a;
5908
+ if (typeof this.ctx.getDataFromResultPoolByRef === "undefined")
5909
+ return (_a = this.getData().entries.find((f) => f.ref.blockId === ref.blockId && f.ref.name === ref.name)) == null ? void 0 : _a.obj;
5910
+ const data = this.ctx.getDataFromResultPoolByRef(ref.blockId, ref.name);
5911
+ if (!data)
5912
+ return void 0;
5913
+ return mapPObjectData(data, (handle) => new TreeNodeAccessor(handle, [ref.blockId, ref.name]));
5533
5914
  }
5534
5915
  /**
5535
5916
  * Returns data associated with the ref ensuring that it is a p-column.
5536
5917
  * @param ref a Ref
5537
5918
  * @returns p-column associated with the ref
5538
5919
  */
5539
- getPColumnByRef(e) {
5540
- const n2 = this.getDataByRef(e);
5541
- if (n2)
5542
- return qn(n2);
5920
+ getPColumnByRef(ref) {
5921
+ const data = this.getDataByRef(ref);
5922
+ if (!data)
5923
+ return void 0;
5924
+ return ensurePColumn(data);
5543
5925
  }
5544
5926
  /**
5545
5927
  * Returns spec associated with the ref ensuring that it is a p-column spec.
5546
5928
  * @param ref a Ref
5547
5929
  * @returns p-column spec associated with the ref
5548
5930
  */
5549
- getPColumnSpecByRef(e) {
5550
- const n2 = this.getSpecByRef(e);
5551
- if (n2) {
5552
- if (!f(n2)) throw new Error(`not a PColumn spec (kind = ${n2.kind})`);
5553
- return n2;
5554
- }
5931
+ getPColumnSpecByRef(ref) {
5932
+ const spec = this.getSpecByRef(ref);
5933
+ if (!spec)
5934
+ return void 0;
5935
+ if (!isPColumnSpec(spec))
5936
+ throw new Error(`not a PColumn spec (kind = ${spec.kind})`);
5937
+ return spec;
5555
5938
  }
5556
5939
  /**
5557
5940
  * @param ref a Ref
5558
5941
  * @returns object spec associated with the ref
5559
5942
  */
5560
- getSpecByRef(e) {
5561
- return this.ctx.getSpecFromResultPoolByRef(e.blockId, e.name);
5943
+ getSpecByRef(ref) {
5944
+ return this.ctx.getSpecFromResultPoolByRef(ref.blockId, ref.name);
5562
5945
  }
5563
5946
  /**
5564
5947
  * @param spec object specification
5565
5948
  * @returns array of data objects with compatible specs
5566
5949
  * @deprecated delete this method after Jan 1, 2025
5567
5950
  */
5568
- findDataWithCompatibleSpec(e) {
5569
- const n2 = [];
5570
- e: for (const r of this.getData().entries) {
5571
- if (!f(r.obj.spec))
5951
+ findDataWithCompatibleSpec(spec) {
5952
+ const result = [];
5953
+ out: for (const data of this.getData().entries) {
5954
+ if (!isPColumnSpec(data.obj.spec)) {
5572
5955
  continue;
5573
- const i = r.obj.spec;
5574
- if (e.name === i.name && e.valueType === i.valueType && e.axesSpec.length === i.axesSpec.length && pe(e.domain, i.domain)) {
5575
- for (let s2 = 0; s2 < e.axesSpec.length; ++s2) {
5576
- const o = e.axesSpec[s2], a = i.axesSpec[s2];
5577
- if (o.name !== a.name || o.type !== a.type || !pe(o.domain, a.domain))
5578
- continue e;
5956
+ }
5957
+ const oth = data.obj.spec;
5958
+ if (spec.name !== oth.name) {
5959
+ continue;
5960
+ }
5961
+ if (spec.valueType !== oth.valueType) {
5962
+ continue;
5963
+ }
5964
+ if (spec.axesSpec.length !== oth.axesSpec.length) {
5965
+ continue;
5966
+ }
5967
+ if (!matchDomain(spec.domain, oth.domain)) {
5968
+ continue;
5969
+ }
5970
+ for (let i = 0; i < spec.axesSpec.length; ++i) {
5971
+ const qAx = spec.axesSpec[i];
5972
+ const tAx = oth.axesSpec[i];
5973
+ if (qAx.name !== tAx.name) {
5974
+ continue out;
5975
+ }
5976
+ if (qAx.type !== tAx.type) {
5977
+ continue out;
5978
+ }
5979
+ if (!matchDomain(qAx.domain, tAx.domain)) {
5980
+ continue out;
5579
5981
  }
5580
- n2.push(r.obj);
5581
5982
  }
5983
+ result.push(data.obj);
5582
5984
  }
5583
- return n2;
5985
+ return result;
5584
5986
  }
5585
5987
  /**
5586
5988
  * Find labels data for a given axis id. It will search for a label column and return its data as a map.
5587
5989
  * @returns a map of axis value => label
5588
5990
  */
5589
- findLabels(e) {
5590
- const n2 = this.getData();
5591
- for (const r of n2.entries) {
5592
- if (!rn(r.obj)) continue;
5593
- const i = r.obj.spec;
5594
- if (i.name === "pl7.app/label" && i.axesSpec.length === 1 && i.axesSpec[0].name === e.name && i.axesSpec[0].type === e.type && pe(e.domain, i.axesSpec[0].domain)) {
5595
- if (r.obj.data.resourceType.name !== "PColumnData/Json")
5596
- throw Error(`Expected JSON column for labels, got: ${r.obj.data.resourceType.name}`);
5597
- return Object.fromEntries(
5598
- Object.entries(
5599
- r.obj.data.getDataAsJson().data
5600
- ).map((o) => [JSON.parse(o[0])[0], o[1]])
5601
- );
5991
+ findLabels(axis) {
5992
+ const dataPool = this.getData();
5993
+ for (const column of dataPool.entries) {
5994
+ if (!isPColumn(column.obj))
5995
+ continue;
5996
+ const spec = column.obj.spec;
5997
+ 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)) {
5998
+ if (column.obj.data.resourceType.name !== "PColumnData/Json") {
5999
+ throw Error(`Expected JSON column for labels, got: ${column.obj.data.resourceType.name}`);
6000
+ }
6001
+ const labels = Object.fromEntries(Object.entries(column.obj.data.getDataAsJson().data).map((e) => [JSON.parse(e[0])[0], e[1]]));
6002
+ return labels;
5602
6003
  }
5603
6004
  }
6005
+ return void 0;
5604
6006
  }
5605
6007
  /**
5606
6008
  * Selects columns based on the provided selectors, returning PColumn objects
@@ -5609,18 +6011,27 @@
5609
6011
  * @param selectors - A predicate function, a single selector, or an array of selectors.
5610
6012
  * @returns An array of PColumn objects matching the selectors. Data is loaded on first access.
5611
6013
  */
5612
- selectColumns(e) {
5613
- const n2 = typeof e == "function" ? e : Gn(e);
5614
- return this.getSpecs().entries.filter(({ obj: i }) => f(i) ? n2(i) : false).map(({ ref: i, obj: s2 }) => {
5615
- const o = s2;
5616
- let a = null;
5617
- const l2 = this;
6014
+ selectColumns(selectors) {
6015
+ const predicate = typeof selectors === "function" ? selectors : selectorsToPredicate(selectors);
6016
+ const matchedSpecs = this.getSpecs().entries.filter(({ obj: spec }) => {
6017
+ if (!isPColumnSpec(spec))
6018
+ return false;
6019
+ return predicate(spec);
6020
+ });
6021
+ return matchedSpecs.map(({ ref, obj: spec }) => {
6022
+ const pcolumnSpec = spec;
6023
+ let _cachedData = null;
6024
+ const self2 = this;
5618
6025
  return {
5619
- id: Re(i),
5620
- spec: o,
6026
+ id: canonicalize(ref),
6027
+ spec: pcolumnSpec,
5621
6028
  get data() {
5622
- var u2;
5623
- return a !== null || (a = (u2 = l2.getPColumnByRef(i)) == null ? void 0 : u2.data), a;
6029
+ var _a;
6030
+ if (_cachedData !== null) {
6031
+ return _cachedData;
6032
+ }
6033
+ _cachedData = (_a = self2.getPColumnByRef(ref)) == null ? void 0 : _a.data;
6034
+ return _cachedData;
5624
6035
  }
5625
6036
  };
5626
6037
  });
@@ -5629,288 +6040,272 @@
5629
6040
  * Find labels data for a given axis id of a p-column.
5630
6041
  * @returns a map of axis value => label
5631
6042
  */
5632
- findLabelsForColumnAxis(e, n2) {
5633
- var s2;
5634
- const r = this.findLabels(e.axesSpec[n2]);
5635
- if (!r) return;
5636
- const i = (s2 = e.annotations) == null ? void 0 : s2["pl7.app/axisKeys/" + n2];
5637
- if (i !== void 0) {
5638
- const o = JSON.parse(i);
5639
- return Object.fromEntries(o.map((a) => [a, r[a] ?? "Unlabelled"]));
5640
- } else
5641
- return r;
6043
+ findLabelsForColumnAxis(column, axisIdx) {
6044
+ const labels = this.findLabels(column.axesSpec[axisIdx]);
6045
+ if (!labels)
6046
+ return void 0;
6047
+ const axisKeys = readAnnotation(column, `pl7.app/axisKeys/${axisIdx}`);
6048
+ if (axisKeys !== void 0) {
6049
+ const keys = JSON.parse(axisKeys);
6050
+ return Object.fromEntries(keys.map((key) => {
6051
+ return [key, labels[key] ?? "Unlabelled"];
6052
+ }));
6053
+ } else {
6054
+ return labels;
6055
+ }
5642
6056
  }
5643
6057
  }
5644
- class te {
6058
+ class RenderCtx {
5645
6059
  constructor() {
5646
- k(this, "ctx");
5647
- k(this, "args");
5648
- k(this, "uiState");
5649
- k(this, "_activeArgsCache");
5650
- k(this, "resultPool", new Kt());
5651
- this.ctx = y(), this.args = JSON.parse(this.ctx.args), this.uiState = this.ctx.uiState !== void 0 ? JSON.parse(this.ctx.uiState) : {};
6060
+ __publicField(this, "ctx");
6061
+ __publicField(this, "_argsCache");
6062
+ __publicField(this, "_uiStateCache");
6063
+ // lazy rendering because this feature is rarely used
6064
+ __publicField(this, "_activeArgsCache");
6065
+ __publicField(this, "resultPool", new ResultPool());
6066
+ this.ctx = getCfgRenderCtx();
6067
+ }
6068
+ get args() {
6069
+ if (this._argsCache === void 0) {
6070
+ const raw = this.ctx.args;
6071
+ const value = typeof raw === "function" ? raw() : raw;
6072
+ this._argsCache = { v: JSON.parse(value) };
6073
+ }
6074
+ return this._argsCache.v;
6075
+ }
6076
+ get uiState() {
6077
+ if (this._uiStateCache === void 0) {
6078
+ const raw = this.ctx.uiState;
6079
+ const value = typeof raw === "function" ? raw() : raw;
6080
+ this._uiStateCache = { v: value ? JSON.parse(value) : {} };
6081
+ }
6082
+ return this._uiStateCache.v;
5652
6083
  }
5653
6084
  /**
5654
6085
  * Returns args snapshot the block was executed for (i.e. when "Run" button was pressed).
5655
6086
  * Returns undefined, if block was never executed or stopped mid-way execution, so that the result was cleared.
5656
6087
  * */
5657
6088
  get activeArgs() {
5658
- return this._activeArgsCache === void 0 && (this._activeArgsCache = {
5659
- v: this.ctx.activeArgs ? JSON.parse(this.ctx.activeArgs) : void 0
5660
- }), this._activeArgsCache.v;
6089
+ if (this._activeArgsCache === void 0) {
6090
+ const raw = this.ctx.activeArgs;
6091
+ const value = typeof raw === "function" ? raw() : raw;
6092
+ this._activeArgsCache = {
6093
+ v: value ? JSON.parse(value) : void 0
6094
+ };
6095
+ }
6096
+ return this._activeArgsCache.v;
5661
6097
  }
5662
6098
  // /** Can be used to determine features provided by the desktop instance. */
5663
6099
  // public get featureFlags() {
5664
6100
  // return this.ctx.featureFlags;
5665
6101
  // }
5666
- getNamedAccessor(e) {
5667
- return ge(
5668
- this.ctx.getAccessorHandleByName(e),
5669
- (n2) => new E(n2, [e])
5670
- );
6102
+ getNamedAccessor(name) {
6103
+ return ifDef(this.ctx.getAccessorHandleByName(name), (accessor) => new TreeNodeAccessor(accessor, [name]));
5671
6104
  }
5672
6105
  get prerun() {
5673
- return this.getNamedAccessor(Ve);
6106
+ return this.getNamedAccessor(StagingAccessorName);
5674
6107
  }
5675
6108
  get outputs() {
5676
- return this.getNamedAccessor(je);
6109
+ return this.getNamedAccessor(MainAccessorName);
5677
6110
  }
5678
6111
  /**
5679
6112
  * Find labels data for a given axis id. It will search for a label column and return its data as a map.
5680
6113
  * @returns a map of axis value => label
5681
6114
  * @deprecated Use resultPool.findLabels instead
5682
6115
  */
5683
- findLabels(e) {
5684
- return this.resultPool.findLabels(e);
6116
+ findLabels(axis) {
6117
+ return this.resultPool.findLabels(axis);
6118
+ }
6119
+ verifyInlineAndExplicitColumnsSupport(columns) {
6120
+ var _a;
6121
+ const hasInlineColumns = columns.some((c) => !(c.data instanceof TreeNodeAccessor) || isDataInfo(c.data));
6122
+ const inlineColumnsSupport = ((_a = this.ctx.featureFlags) == null ? void 0 : _a.inlineColumnsSupport) === true;
6123
+ if (hasInlineColumns && !inlineColumnsSupport)
6124
+ throw Error(`Inline or explicit columns not supported`);
5685
6125
  }
5686
- verifyInlineAndExplicitColumnsSupport(e) {
5687
- var i;
5688
- const n2 = e.some((s2) => !(s2.data instanceof E) || En(s2.data)), r = ((i = this.ctx.featureFlags) == null ? void 0 : i.inlineColumnsSupport) === true;
5689
- if (n2 && !r) throw Error("Inline or explicit columns not supported");
6126
+ patchPTableDef(def) {
6127
+ var _a, _b;
6128
+ if (!((_a = this.ctx.featureFlags) == null ? void 0 : _a.pTablePartitionFiltersSupport)) {
6129
+ def = {
6130
+ ...def,
6131
+ partitionFilters: [],
6132
+ filters: [...def.partitionFilters, ...def.filters]
6133
+ };
6134
+ }
6135
+ if (!((_b = this.ctx.featureFlags) == null ? void 0 : _b.pFrameInSetFilterSupport)) {
6136
+ def = {
6137
+ ...def,
6138
+ partitionFilters: patchInSetFilters(def.partitionFilters),
6139
+ filters: patchInSetFilters(def.filters)
6140
+ };
6141
+ }
6142
+ return def;
5690
6143
  }
5691
6144
  // TODO remove all non-PColumn fields
5692
- createPFrame(e) {
5693
- return this.verifyInlineAndExplicitColumnsSupport(e), this.ctx.createPFrame(
5694
- e.map((n2) => Ee(n2))
5695
- );
5696
- }
5697
- createPTable(e) {
5698
- let n2;
5699
- return "columns" in e ? n2 = {
5700
- src: {
5701
- type: "full",
5702
- entries: e.columns.map((r) => ({ type: "column", column: r }))
5703
- },
5704
- filters: e.filters ?? [],
5705
- sorting: e.sorting ?? []
5706
- } : n2 = e, this.verifyInlineAndExplicitColumnsSupport(Xn(n2.src)), this.ctx.createPTable(
5707
- Un(n2, (r) => Ee(r))
5708
- );
6145
+ createPFrame(def) {
6146
+ this.verifyInlineAndExplicitColumnsSupport(def);
6147
+ return this.ctx.createPFrame(def.map((c) => transformPColumnData(c)));
6148
+ }
6149
+ createPTable(def) {
6150
+ let rawDef;
6151
+ if ("columns" in def) {
6152
+ rawDef = this.patchPTableDef({
6153
+ src: {
6154
+ type: "full",
6155
+ entries: def.columns.map((c) => ({ type: "column", column: c }))
6156
+ },
6157
+ partitionFilters: def.filters ?? [],
6158
+ filters: [],
6159
+ sorting: def.sorting ?? []
6160
+ });
6161
+ } else {
6162
+ rawDef = this.patchPTableDef(def);
6163
+ }
6164
+ this.verifyInlineAndExplicitColumnsSupport(extractAllColumns(rawDef.src));
6165
+ return this.ctx.createPTable(mapPTableDef(rawDef, (po) => transformPColumnData(po)));
5709
6166
  }
5710
6167
  /** @deprecated scheduled for removal from SDK */
5711
- getBlockLabel(e) {
5712
- return this.ctx.getBlockLabel(e);
6168
+ getBlockLabel(blockId) {
6169
+ return this.ctx.getBlockLabel(blockId);
5713
6170
  }
5714
6171
  getCurrentUnstableMarker() {
5715
6172
  return this.ctx.getCurrentUnstableMarker();
5716
6173
  }
5717
- logInfo(e) {
5718
- this.ctx.logInfo(e);
5719
- }
5720
- logWarn(e) {
5721
- this.ctx.logWarn(e);
5722
- }
5723
- logError(e) {
5724
- this.ctx.logError(e);
5725
- }
5726
- }
5727
- const Y = "1.37.2";
5728
- function Vt(t) {
5729
- return t.__renderLambda === true;
5730
- }
5731
- function fe(t) {
5732
- if (t !== void 0)
5733
- return Vt(t) ? t.handle : t;
5734
- }
5735
- class L {
5736
- constructor(e, n2, r, i, s2, o, a, l2) {
5737
- this._renderingMode = e, this._initialArgs = n2, this._initialUiState = r, this._outputs = i, this._inputsValid = s2, this._sections = o, this._title = a, this._enrichmentTargets = l2;
5738
- }
5739
- static create(e = "Heavy") {
5740
- return new L(
5741
- e,
5742
- void 0,
5743
- {},
5744
- {},
5745
- re(true),
5746
- re([]),
5747
- void 0,
5748
- void 0
5749
- );
5750
- }
5751
- output(e, n2, r = {}) {
5752
- if (typeof n2 == "function") {
5753
- const i = `output#${e}`;
5754
- return H(i, () => n2(new te())), new L(
5755
- this._renderingMode,
5756
- this._initialArgs,
5757
- this._initialUiState,
5758
- {
5759
- ...this._outputs,
5760
- [e]: {
5761
- __renderLambda: true,
5762
- handle: i,
5763
- ...r
5764
- }
5765
- },
5766
- this._inputsValid,
5767
- this._sections,
5768
- this._title,
5769
- this._enrichmentTargets
5770
- );
6174
+ logInfo(msg) {
6175
+ this.ctx.logInfo(msg);
6176
+ }
6177
+ logWarn(msg) {
6178
+ this.ctx.logWarn(msg);
6179
+ }
6180
+ logError(msg) {
6181
+ this.ctx.logError(msg);
6182
+ }
6183
+ }
6184
+ var version = "1.43.2";
6185
+ const PlatformaSDKVersion = version;
6186
+ function isConfigLambda(cfgOrFh) {
6187
+ return cfgOrFh.__renderLambda === true;
6188
+ }
6189
+ function downgradeCfgOrLambda(data) {
6190
+ if (data === void 0)
6191
+ return void 0;
6192
+ if (isConfigLambda(data))
6193
+ return data.handle;
6194
+ return data;
6195
+ }
6196
+ const _BlockModel = class _BlockModel {
6197
+ constructor(_renderingMode, _initialArgs, _initialUiState, _outputs, _inputsValid, _sections, _title, _enrichmentTargets, _featureFlags) {
6198
+ __publicField(this, "_renderingMode");
6199
+ __publicField(this, "_initialArgs");
6200
+ __publicField(this, "_initialUiState");
6201
+ __publicField(this, "_outputs");
6202
+ __publicField(this, "_inputsValid");
6203
+ __publicField(this, "_sections");
6204
+ __publicField(this, "_title");
6205
+ __publicField(this, "_enrichmentTargets");
6206
+ __publicField(this, "_featureFlags");
6207
+ this._renderingMode = _renderingMode;
6208
+ this._initialArgs = _initialArgs;
6209
+ this._initialUiState = _initialUiState;
6210
+ this._outputs = _outputs;
6211
+ this._inputsValid = _inputsValid;
6212
+ this._sections = _sections;
6213
+ this._title = _title;
6214
+ this._enrichmentTargets = _enrichmentTargets;
6215
+ this._featureFlags = _featureFlags;
6216
+ }
6217
+ static create(renderingMode = "Heavy") {
6218
+ return new _BlockModel(renderingMode, void 0, {}, {}, getImmediate(true), getImmediate([]), void 0, void 0, { ..._BlockModel.INITIAL_BLOCK_FEATURE_FLAGS });
6219
+ }
6220
+ output(key, cfgOrRf, flags = {}) {
6221
+ if (typeof cfgOrRf === "function") {
6222
+ const handle = `output#${key}`;
6223
+ tryRegisterCallback(handle, () => cfgOrRf(new RenderCtx()));
6224
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, {
6225
+ ...this._outputs,
6226
+ [key]: {
6227
+ __renderLambda: true,
6228
+ handle,
6229
+ ...flags
6230
+ }
6231
+ }, this._inputsValid, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
5771
6232
  } else
5772
- return new L(
5773
- this._renderingMode,
5774
- this._initialArgs,
5775
- this._initialUiState,
5776
- {
5777
- ...this._outputs,
5778
- [e]: n2
5779
- },
5780
- this._inputsValid,
5781
- this._sections,
5782
- this._title,
5783
- this._enrichmentTargets
5784
- );
6233
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, {
6234
+ ...this._outputs,
6235
+ [key]: cfgOrRf
6236
+ }, this._inputsValid, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
5785
6237
  }
5786
6238
  /** Shortcut for {@link output} with retentive flag set to true. */
5787
- retentiveOutput(e, n2) {
5788
- return this.output(e, n2, { retentive: true });
5789
- }
5790
- argsValid(e) {
5791
- return typeof e == "function" ? (H("inputsValid", () => e(new te())), new L(
5792
- this._renderingMode,
5793
- this._initialArgs,
5794
- this._initialUiState,
5795
- this._outputs,
5796
- {
6239
+ retentiveOutput(key, rf) {
6240
+ return this.output(key, rf, { retentive: true });
6241
+ }
6242
+ argsValid(cfgOrRf) {
6243
+ if (typeof cfgOrRf === "function") {
6244
+ tryRegisterCallback("inputsValid", () => cfgOrRf(new RenderCtx()));
6245
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, {
5797
6246
  __renderLambda: true,
5798
6247
  handle: "inputsValid"
5799
- },
5800
- this._sections,
5801
- this._title,
5802
- this._enrichmentTargets
5803
- )) : new L(
5804
- this._renderingMode,
5805
- this._initialArgs,
5806
- this._initialUiState,
5807
- this._outputs,
5808
- e,
5809
- this._sections,
5810
- this._title,
5811
- this._enrichmentTargets
5812
- );
5813
- }
5814
- sections(e) {
5815
- return Array.isArray(e) ? this.sections(re(e)) : typeof e == "function" ? (H("sections", () => e(new te())), new L(
5816
- this._renderingMode,
5817
- this._initialArgs,
5818
- this._initialUiState,
5819
- this._outputs,
5820
- this._inputsValid,
5821
- { __renderLambda: true, handle: "sections" },
5822
- this._title,
5823
- this._enrichmentTargets
5824
- )) : new L(
5825
- this._renderingMode,
5826
- this._initialArgs,
5827
- this._initialUiState,
5828
- this._outputs,
5829
- this._inputsValid,
5830
- e,
5831
- this._title,
5832
- this._enrichmentTargets
5833
- );
6248
+ }, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
6249
+ } else
6250
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, cfgOrRf, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
6251
+ }
6252
+ sections(arrOrCfgOrRf) {
6253
+ if (Array.isArray(arrOrCfgOrRf)) {
6254
+ return this.sections(getImmediate(arrOrCfgOrRf));
6255
+ } else if (typeof arrOrCfgOrRf === "function") {
6256
+ tryRegisterCallback("sections", () => arrOrCfgOrRf(new RenderCtx()));
6257
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, this._inputsValid, { __renderLambda: true, handle: "sections" }, this._title, this._enrichmentTargets, this._featureFlags);
6258
+ } else
6259
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, this._inputsValid, arrOrCfgOrRf, this._title, this._enrichmentTargets, this._featureFlags);
5834
6260
  }
5835
6261
  /** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
5836
- title(e) {
5837
- return H("title", () => e(new te())), new L(
5838
- this._renderingMode,
5839
- this._initialArgs,
5840
- this._initialUiState,
5841
- this._outputs,
5842
- this._inputsValid,
5843
- this._sections,
5844
- { __renderLambda: true, handle: "title" },
5845
- this._enrichmentTargets
5846
- );
6262
+ title(rf) {
6263
+ tryRegisterCallback("title", () => rf(new RenderCtx()));
6264
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, this._inputsValid, this._sections, { __renderLambda: true, handle: "title" }, this._enrichmentTargets, this._featureFlags);
5847
6265
  }
5848
6266
  /**
5849
6267
  * Sets initial args for the block, this value must be specified.
5850
6268
  * @deprecated use {@link withArgs}
5851
6269
  * */
5852
- initialArgs(e) {
5853
- return new L(
5854
- this._renderingMode,
5855
- e,
5856
- this._initialUiState,
5857
- this._outputs,
5858
- this._inputsValid,
5859
- this._sections,
5860
- this._title,
5861
- this._enrichmentTargets
5862
- );
6270
+ initialArgs(value) {
6271
+ return new _BlockModel(this._renderingMode, value, this._initialUiState, this._outputs, this._inputsValid, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
5863
6272
  }
5864
6273
  /** Sets initial args for the block, this value must be specified. */
5865
- withArgs(e) {
5866
- return new L(
5867
- this._renderingMode,
5868
- e,
5869
- this._initialUiState,
5870
- this._outputs,
5871
- this._inputsValid,
5872
- this._sections,
5873
- this._title,
5874
- this._enrichmentTargets
5875
- );
6274
+ withArgs(initialValue) {
6275
+ return new _BlockModel(this._renderingMode, initialValue, this._initialUiState, this._outputs, this._inputsValid, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
5876
6276
  }
5877
6277
  /** Defines type and sets initial value for block UiState. */
5878
- withUiState(e) {
5879
- return new L(
5880
- this._renderingMode,
5881
- this._initialArgs,
5882
- e,
5883
- this._outputs,
5884
- this._inputsValid,
5885
- this._sections,
5886
- this._title,
5887
- this._enrichmentTargets
5888
- );
6278
+ withUiState(initialValue) {
6279
+ return new _BlockModel(this._renderingMode, this._initialArgs, initialValue, this._outputs, this._inputsValid, this._sections, this._title, this._enrichmentTargets, this._featureFlags);
6280
+ }
6281
+ /** Sets or overrides feature flags for the block. */
6282
+ withFeatureFlags(flags) {
6283
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, this._inputsValid, this._sections, this._title, this._enrichmentTargets, { ...this._featureFlags, ...flags });
5889
6284
  }
5890
6285
  /**
5891
6286
  * Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.
5892
6287
  * Influences dependency graph construction.
5893
6288
  */
5894
- enriches(e) {
5895
- return H("enrichmentTargets", e), new L(
5896
- this._renderingMode,
5897
- this._initialArgs,
5898
- this._initialUiState,
5899
- this._outputs,
5900
- this._inputsValid,
5901
- this._sections,
5902
- this._title,
5903
- { __renderLambda: true, handle: "enrichmentTargets" }
5904
- );
6289
+ enriches(lambda) {
6290
+ tryRegisterCallback("enrichmentTargets", lambda);
6291
+ return new _BlockModel(this._renderingMode, this._initialArgs, this._initialUiState, this._outputs, this._inputsValid, this._sections, this._title, { __renderLambda: true, handle: "enrichmentTargets" }, this._featureFlags);
5905
6292
  }
5906
6293
  /** Renders all provided block settings into a pre-configured platforma API
5907
6294
  * instance, that can be used in frontend to interact with block state, and
5908
6295
  * other features provided by the platforma to the block. */
5909
- done() {
5910
- if (this._initialArgs === void 0) throw new Error("Initial arguments not set.");
5911
- const e = {
6296
+ done(apiVersion) {
6297
+ const requiresUIAPIVersion = apiVersion ?? 1;
6298
+ return this.withFeatureFlags({
6299
+ ...this._featureFlags,
6300
+ requiresUIAPIVersion
6301
+ })._done(requiresUIAPIVersion);
6302
+ }
6303
+ _done(apiVersion) {
6304
+ if (this._initialArgs === void 0)
6305
+ throw new Error("Initial arguments not set.");
6306
+ const config = {
5912
6307
  v3: {
5913
- sdkVersion: Y,
6308
+ sdkVersion: PlatformaSDKVersion,
5914
6309
  renderingMode: this._renderingMode,
5915
6310
  initialArgs: this._initialArgs,
5916
6311
  initialUiState: this._initialUiState,
@@ -5918,152 +6313,340 @@
5918
6313
  sections: this._sections,
5919
6314
  title: this._title,
5920
6315
  outputs: this._outputs,
5921
- enrichmentTargets: this._enrichmentTargets
6316
+ enrichmentTargets: this._enrichmentTargets,
6317
+ featureFlags: this._featureFlags
5922
6318
  },
5923
6319
  // fields below are added to allow previous desktop versions read generated configs
5924
- sdkVersion: Y,
6320
+ sdkVersion: PlatformaSDKVersion,
5925
6321
  renderingMode: this._renderingMode,
5926
6322
  initialArgs: this._initialArgs,
5927
- inputsValid: fe(this._inputsValid),
5928
- sections: fe(this._sections),
5929
- outputs: Object.fromEntries(
5930
- Object.entries(this._outputs).map(([n2, r]) => [n2, fe(r)])
5931
- )
6323
+ inputsValid: downgradeCfgOrLambda(this._inputsValid),
6324
+ sections: downgradeCfgOrLambda(this._sections),
6325
+ outputs: Object.fromEntries(Object.entries(this._outputs).map(([key, value]) => [key, downgradeCfgOrLambda(value)]))
5932
6326
  };
5933
- return ht() ? Ke({ sdkVersion: Y }) : { config: e };
6327
+ globalThis.platformaApiVersion = apiVersion;
6328
+ if (!isInUI())
6329
+ return { config };
6330
+ else
6331
+ return getPlatformaInstance({ sdkVersion: PlatformaSDKVersion, apiVersion: platformaApiVersion });
5934
6332
  }
6333
+ };
6334
+ __publicField(_BlockModel, "INITIAL_BLOCK_FEATURE_FLAGS", {
6335
+ supportsLazyState: true,
6336
+ requiresUIAPIVersion: 1,
6337
+ requiresModelAPIVersion: 1
6338
+ });
6339
+ let BlockModel = _BlockModel;
6340
+ function makeDefaultPTableParams() {
6341
+ return {
6342
+ sourceId: null,
6343
+ hiddenColIds: null,
6344
+ partitionFilters: [],
6345
+ filters: [],
6346
+ sorting: []
6347
+ };
5935
6348
  }
5936
- function Ue() {
6349
+ function createPlDataTableStateV2() {
5937
6350
  return {
5938
- version: 2,
6351
+ version: 4,
5939
6352
  stateCache: [],
5940
- pTableParams: {
5941
- sorting: [],
5942
- filters: [],
5943
- hiddenColIds: null
5944
- }
6353
+ pTableParams: makeDefaultPTableParams()
5945
6354
  };
5946
6355
  }
5947
- function jt(t) {
5948
- return "version" in t ? t : Ue();
6356
+ function upgradePlDataTableStateV2(state) {
6357
+ if (!state) {
6358
+ return createPlDataTableStateV2();
6359
+ }
6360
+ if (!("version" in state)) {
6361
+ state = createPlDataTableStateV2();
6362
+ }
6363
+ if (state.version === 2) {
6364
+ state = {
6365
+ version: 3,
6366
+ stateCache: state.stateCache.map((entry) => ({
6367
+ ...entry,
6368
+ filtersState: []
6369
+ })),
6370
+ pTableParams: makeDefaultPTableParams()
6371
+ };
6372
+ }
6373
+ if (state.version === 3) {
6374
+ state = createPlDataTableStateV2();
6375
+ }
6376
+ return state;
5949
6377
  }
5950
- function be(t) {
5951
- return t.axesSpec.length === 1 && t.name === "pl7.app/label";
6378
+ function isLabelColumn(column) {
6379
+ return column.axesSpec.length === 1 && column.name === PColumnName.Label;
5952
6380
  }
5953
- function Be(t) {
5954
- return new le().addAxisLabelProvider(t).addColumnProvider(t).getColumns({
5955
- name: "pl7.app/label",
6381
+ function getAllLabelColumns(resultPool) {
6382
+ return new PColumnCollection().addAxisLabelProvider(resultPool).addColumnProvider(resultPool).getColumns({
6383
+ name: PColumnName.Label,
5956
6384
  axes: [{}]
5957
6385
  // exactly one axis
5958
6386
  }, { dontWaitAllData: true });
5959
6387
  }
5960
- function we(t, e) {
5961
- const n2 = [], r = [];
5962
- for (const a of t)
5963
- be(a.spec) ? n2.push(a) : r.push(a);
5964
- const i = [];
5965
- for (const a of r)
5966
- for (const l2 of a.spec.axesSpec) {
5967
- const u2 = p$1(l2);
5968
- i.some((c2) => Z$1(c2, u2)) || i.push(u2);
5969
- }
5970
- for (const a of n2) {
5971
- const l2 = p$1(a.spec.axesSpec[0]), u2 = i.findIndex((c2) => Z$1(c2, l2));
5972
- u2 !== -1 && i.splice(u2, 1);
5973
- }
5974
- const s2 = (a, l2) => {
5975
- let u2 = a.toString();
5976
- if (l2)
5977
- for (const c2 in l2)
5978
- u2 += c2, u2 += l2[c2];
5979
- return u2;
5980
- }, o = [];
5981
- for (const a of e) {
5982
- const l2 = a.spec.axesSpec[0], u2 = p$1(l2), c2 = i.findIndex((d) => Z$1(d, u2));
5983
- if (c2 !== -1) {
5984
- const d = i[c2], h2 = Object.keys(d.domain ?? {}).length, p2 = Object.keys(l2.domain ?? {}).length;
5985
- h2 > p2 ? o.push({
5986
- id: s2(a.id, d.domain),
5987
- spec: {
5988
- ...a.spec,
5989
- axesSpec: [{ ...d, annotations: l2.annotations }]
5990
- },
5991
- data: a.data
5992
- }) : o.push(a), i.splice(c2, 1);
6388
+ function getMatchingLabelColumns(columns, allLabelColumns) {
6389
+ const inputLabelColumns = [];
6390
+ const inputValueColumns = [];
6391
+ for (const column of columns) {
6392
+ if (isLabelColumn(column.spec)) {
6393
+ inputLabelColumns.push(column);
6394
+ } else {
6395
+ inputValueColumns.push(column);
6396
+ }
6397
+ }
6398
+ const unlabeledAxes = [];
6399
+ for (const column of inputValueColumns) {
6400
+ for (const axis of column.spec.axesSpec) {
6401
+ const axisId = getAxisId(axis);
6402
+ if (!unlabeledAxes.some((id) => matchAxisId(id, axisId))) {
6403
+ unlabeledAxes.push(axisId);
6404
+ }
6405
+ }
6406
+ }
6407
+ for (const labelColumn of inputLabelColumns) {
6408
+ const labelAxisId = getAxisId(labelColumn.spec.axesSpec[0]);
6409
+ const labelMatch = unlabeledAxes.findIndex((axisId) => matchAxisId(axisId, labelAxisId));
6410
+ if (labelMatch !== -1) {
6411
+ unlabeledAxes.splice(labelMatch, 1);
6412
+ }
6413
+ }
6414
+ const colId = (id, domain) => {
6415
+ let wid = id.toString();
6416
+ if (domain) {
6417
+ for (const k in domain) {
6418
+ wid += k;
6419
+ wid += domain[k];
6420
+ }
6421
+ }
6422
+ return wid;
6423
+ };
6424
+ const labelColumns = [];
6425
+ for (const labelColumn of allLabelColumns) {
6426
+ const labelAxis = labelColumn.spec.axesSpec[0];
6427
+ const labelAxisId = getAxisId(labelAxis);
6428
+ const labelMatch = unlabeledAxes.findIndex((axisId) => matchAxisId(axisId, labelAxisId));
6429
+ if (labelMatch !== -1) {
6430
+ const axisId = unlabeledAxes[labelMatch];
6431
+ const dataDomainLen = Object.keys(axisId.domain ?? {}).length;
6432
+ const labelDomainLen = Object.keys(labelAxis.domain ?? {}).length;
6433
+ if (dataDomainLen > labelDomainLen) {
6434
+ labelColumns.push({
6435
+ id: colId(labelColumn.id, axisId.domain),
6436
+ spec: {
6437
+ ...labelColumn.spec,
6438
+ axesSpec: [{ ...axisId, annotations: labelAxis.annotations }]
6439
+ },
6440
+ data: labelColumn.data
6441
+ });
6442
+ } else {
6443
+ labelColumns.push(labelColumn);
6444
+ }
6445
+ unlabeledAxes.splice(labelMatch, 1);
5993
6446
  }
5994
6447
  }
5995
- return o;
6448
+ return labelColumns;
5996
6449
  }
5997
- function We(t) {
5998
- const e = (i) => Array.isArray(i), n2 = (i) => i instanceof E, r = (i) => typeof i == "object" && "type" in i;
5999
- return t.map((i) => i.data).every((i) => {
6000
- if (e(i))
6450
+ function allColumnsComputed(columns) {
6451
+ const isValues = (d) => Array.isArray(d);
6452
+ const isAccessor = (d) => d instanceof TreeNodeAccessor;
6453
+ const isDataInfo2 = (d) => typeof d === "object" && "type" in d;
6454
+ return columns.map((c) => c.data).every((d) => {
6455
+ if (isValues(d)) {
6001
6456
  return true;
6002
- if (n2(i))
6003
- return i.getIsReadyOrError();
6004
- if (r(i))
6005
- switch (i.type) {
6457
+ } else if (isAccessor(d)) {
6458
+ return d.getIsReadyOrError();
6459
+ } else if (isDataInfo2(d)) {
6460
+ const type = d.type;
6461
+ switch (type) {
6006
6462
  case "Json":
6007
6463
  return true;
6008
6464
  case "JsonPartitioned":
6009
- return Object.values(i.parts).every((o) => o.getIsReadyOrError());
6465
+ return Object.values(d.parts).every((p) => p.getIsReadyOrError());
6010
6466
  case "BinaryPartitioned":
6011
- return Object.values(i.parts).every((o) => o.index.getIsReadyOrError() && o.values.getIsReadyOrError());
6467
+ return Object.values(d.parts).every((p) => p.index.getIsReadyOrError() && p.values.getIsReadyOrError());
6468
+ case "ParquetPartitioned":
6469
+ return Object.values(d.parts).every((p) => p.getIsReadyOrError());
6012
6470
  }
6013
- else
6014
- throw Error(`unsupported column data type: ${i}`);
6471
+ } else {
6472
+ throw Error(`unsupported column data type: ${d}`);
6473
+ }
6015
6474
  });
6016
6475
  }
6017
- function Ae(t, e, n2, r, i, s2) {
6018
- let o = t;
6019
- const a = [];
6020
- return a.push(...e), {
6476
+ function createPTableDef(params) {
6477
+ let coreColumns = params.columns;
6478
+ const secondaryColumns = [];
6479
+ if (params.coreColumnPredicate) {
6480
+ coreColumns = [];
6481
+ for (const c of params.columns)
6482
+ if (params.coreColumnPredicate(c.spec))
6483
+ coreColumns.push(c);
6484
+ else
6485
+ secondaryColumns.push(c);
6486
+ }
6487
+ secondaryColumns.push(...params.labelColumns);
6488
+ return {
6021
6489
  src: {
6022
6490
  type: "outer",
6023
6491
  primary: {
6024
- type: n2,
6025
- entries: o.map((l2) => ({ type: "column", column: l2 }))
6492
+ type: params.coreJoinType,
6493
+ entries: coreColumns.map((c) => ({ type: "column", column: c }))
6026
6494
  },
6027
- secondary: a.map((l2) => ({ type: "column", column: l2 }))
6495
+ secondary: secondaryColumns.map((c) => ({ type: "column", column: c }))
6028
6496
  },
6029
- filters: r,
6030
- sorting: i
6497
+ partitionFilters: params.partitionFilters,
6498
+ filters: params.filters,
6499
+ sorting: params.sorting
6031
6500
  };
6032
6501
  }
6033
- function Nt(t) {
6034
- var e;
6035
- return ((e = t.annotations) == null ? void 0 : e["pl7.app/table/visibility"]) === "hidden";
6036
- }
6037
- function $t(t) {
6038
- var e;
6039
- return ((e = t.annotations) == null ? void 0 : e["pl7.app/table/visibility"]) === "optional";
6040
- }
6041
- function ue(t, e) {
6042
- return [...new Map(t.map((n2) => [e(n2), n2])).values()];
6043
- }
6044
- function Kn(t, e, n2, r) {
6045
- const i = jt(n2 ?? Ue()), s2 = "full", o = ue(
6046
- [...[], ...i.pTableParams.filters],
6047
- (g) => ue$1(g.column)
6048
- ), a = ue(
6049
- [...[], ...i.pTableParams.sorting],
6050
- (g) => ue$1(g.column)
6051
- ), l2 = e.filter((g) => !Nt(g.spec)), u2 = Be(t.resultPool);
6052
- if (!u2) return;
6053
- const c2 = we(l2.map(Fn), u2), d = Ae(l2, c2, s2, o, a), h2 = t.createPTable(d), p2 = new Set((() => {
6054
- const g = i.pTableParams.hiddenColIds;
6055
- return g || l2.filter((x) => $t(x.spec)).map((x) => x.id);
6502
+ function isColumnHidden(spec) {
6503
+ return readAnnotation(spec, Annotation.Table.Visibility) === "hidden";
6504
+ }
6505
+ function isColumnOptional(spec) {
6506
+ return readAnnotation(spec, Annotation.Table.Visibility) === "optional";
6507
+ }
6508
+ function createPlDataTableV2(ctx, inputColumns, tableState, ops) {
6509
+ if (inputColumns.length === 0)
6510
+ return void 0;
6511
+ const columns = inputColumns.filter((c) => isLinkerColumn(c.spec) || !isColumnHidden(c.spec));
6512
+ const tableStateNormalized = upgradePlDataTableStateV2(tableState);
6513
+ const allLabelColumns = getAllLabelColumns(ctx.resultPool);
6514
+ if (!allLabelColumns)
6515
+ return void 0;
6516
+ const fullLabelColumns = getMatchingLabelColumns(columns.map(getColumnIdAndSpec), allLabelColumns);
6517
+ const fullColumns = [...columns, ...fullLabelColumns];
6518
+ const fullColumnsAxes = uniqueBy([...fullColumns.flatMap((c) => c.spec.axesSpec.map((a) => getAxisId(a)))], (a) => canonicalizeJson(a));
6519
+ const fullColumnsIds = [
6520
+ ...fullColumnsAxes.map((a) => ({ type: "axis", id: a })),
6521
+ ...fullColumns.map((c) => ({ type: "column", id: c.id }))
6522
+ ];
6523
+ const fullColumnsIdsSet = new Set(fullColumnsIds.map((c) => canonicalizeJson(c)));
6524
+ const isValidColumnId = (id) => fullColumnsIdsSet.has(canonicalizeJson(id));
6525
+ const coreJoinType = "full";
6526
+ const partitionFilters = tableStateNormalized.pTableParams.partitionFilters.filter((f) => {
6527
+ const valid = isValidColumnId(f.column);
6528
+ if (!valid)
6529
+ ctx.logWarn(`Partition filter ${JSON.stringify(f)} does not match provided columns, skipping`);
6530
+ return valid;
6531
+ });
6532
+ const filters = uniqueBy([...[], ...tableStateNormalized.pTableParams.filters], (f) => canonicalizeJson(f.column)).filter((f) => {
6533
+ const valid = isValidColumnId(f.column);
6534
+ if (!valid)
6535
+ ctx.logWarn(`Filter ${JSON.stringify(f)} does not match provided columns, skipping`);
6536
+ return valid;
6537
+ });
6538
+ const sorting = uniqueBy([...[], ...tableStateNormalized.pTableParams.sorting], (s) => canonicalizeJson(s.column)).filter((s) => {
6539
+ const valid = isValidColumnId(s.column);
6540
+ if (!valid)
6541
+ ctx.logWarn(`Sorting ${JSON.stringify(s)} does not match provided columns, skipping`);
6542
+ return valid;
6543
+ });
6544
+ const fullDef = createPTableDef({
6545
+ columns,
6546
+ labelColumns: fullLabelColumns,
6547
+ coreJoinType,
6548
+ partitionFilters,
6549
+ filters,
6550
+ sorting,
6551
+ coreColumnPredicate: ops == null ? void 0 : ops.coreColumnPredicate
6552
+ });
6553
+ const fullHandle = ctx.createPTable(fullDef);
6554
+ const hiddenColumns = new Set((() => {
6555
+ const hiddenColIds = tableStateNormalized.pTableParams.hiddenColIds;
6556
+ if (hiddenColIds)
6557
+ return hiddenColIds;
6558
+ return columns.filter((c) => isColumnOptional(c.spec)).map((c) => c.id);
6056
6559
  })());
6057
- [...o.map((g) => g.column), ...a.map((g) => g.column)].filter((g) => g.type === "column").map((g) => p2.delete(g.id));
6058
- const m2 = l2.filter((g) => !p2.has(g.id)), f2 = we(m2.map(Fn), u2);
6059
- if (!We([...m2, ...f2])) return;
6060
- const v = Ae(m2, f2, s2, o, a), b = t.createPTable(v);
6560
+ columns.filter((c) => isLinkerColumn(c.spec)).forEach((c) => hiddenColumns.delete(c.id));
6561
+ [...partitionFilters.map((f) => f.column), ...filters.map((f) => f.column), ...sorting.map((s) => s.column)].filter((c) => c.type === "column").forEach((c) => hiddenColumns.delete(c.id));
6562
+ const visibleColumns = columns.filter((c) => !hiddenColumns.has(c.id));
6563
+ const visibleLabelColumns = getMatchingLabelColumns(visibleColumns.map(getColumnIdAndSpec), allLabelColumns);
6564
+ if (!allColumnsComputed([...visibleColumns, ...visibleLabelColumns]))
6565
+ return void 0;
6566
+ const visibleDef = createPTableDef({
6567
+ columns: visibleColumns,
6568
+ labelColumns: visibleLabelColumns,
6569
+ coreJoinType,
6570
+ partitionFilters,
6571
+ filters,
6572
+ sorting,
6573
+ coreColumnPredicate: ops == null ? void 0 : ops.coreColumnPredicate
6574
+ });
6575
+ const visibleHandle = ctx.createPTable(visibleDef);
6061
6576
  return {
6062
- fullTableHandle: h2,
6063
- visibleTableHandle: b
6577
+ sourceId: tableStateNormalized.pTableParams.sourceId,
6578
+ fullTableHandle: fullHandle,
6579
+ visibleTableHandle: visibleHandle
6064
6580
  };
6065
6581
  }
6066
- const model = L.create().withArgs({
6582
+ function isLinkerColumn(column) {
6583
+ return !!readAnnotationJson(column, Annotation.IsLinkerColumn);
6584
+ }
6585
+ var stringify = { exports: {} };
6586
+ var hasRequiredStringify;
6587
+ function requireStringify() {
6588
+ if (hasRequiredStringify) return stringify.exports;
6589
+ hasRequiredStringify = 1;
6590
+ (function(module2, exports3) {
6591
+ exports3 = module2.exports = stringify2;
6592
+ exports3.getSerialize = serializer;
6593
+ function stringify2(obj, replacer, spaces, cycleReplacer) {
6594
+ return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces);
6595
+ }
6596
+ function serializer(replacer, cycleReplacer) {
6597
+ var stack = [], keys = [];
6598
+ if (cycleReplacer == null) cycleReplacer = function(key, value) {
6599
+ if (stack[0] === value) return "[Circular ~]";
6600
+ return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
6601
+ };
6602
+ return function(key, value) {
6603
+ if (stack.length > 0) {
6604
+ var thisPos = stack.indexOf(this);
6605
+ ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
6606
+ ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
6607
+ if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value);
6608
+ } else stack.push(value);
6609
+ return replacer == null ? value : replacer.call(this, key, value);
6610
+ };
6611
+ }
6612
+ })(stringify, stringify.exports);
6613
+ return stringify.exports;
6614
+ }
6615
+ requireStringify();
6616
+ const BasePlErrorLike = z.object({
6617
+ type: z.literal("PlError"),
6618
+ name: z.string(),
6619
+ message: z.string(),
6620
+ /** The message with all details needed for SDK developers. */
6621
+ fullMessage: z.string().optional(),
6622
+ stack: z.string().optional()
6623
+ });
6624
+ const PlErrorLike = BasePlErrorLike.extend({
6625
+ cause: z.lazy(() => ErrorLike).optional(),
6626
+ errors: z.lazy(() => ErrorLike.array()).optional()
6627
+ });
6628
+ const BaseStandardErrorLike = z.object({
6629
+ type: z.literal("StandardError"),
6630
+ name: z.string(),
6631
+ message: z.string(),
6632
+ stack: z.string().optional()
6633
+ });
6634
+ const StandardErrorLike = BaseStandardErrorLike.extend({
6635
+ cause: z.lazy(() => ErrorLike).optional(),
6636
+ errors: z.lazy(() => ErrorLike.array()).optional()
6637
+ });
6638
+ const ErrorLike = z.union([StandardErrorLike, PlErrorLike]);
6639
+ const baseErrorShape = z.object({
6640
+ name: z.string(),
6641
+ message: z.string(),
6642
+ fullMessage: z.string().optional(),
6643
+ stack: z.string().optional()
6644
+ });
6645
+ const ErrorShape = baseErrorShape.extend({
6646
+ cause: z.lazy(() => ErrorShape).optional(),
6647
+ errors: z.lazy(() => ErrorShape.array()).optional()
6648
+ });
6649
+ const model = BlockModel.create().withArgs({
6067
6650
  settings: {
6068
6651
  coverageThreshold: 0.95,
6069
6652
  // default value matching MMseqs2 default
@@ -6073,7 +6656,7 @@
6073
6656
  selectedColumns: []
6074
6657
  }).withUiState({
6075
6658
  title: "Immune Assay Data",
6076
- tableState: Ue()
6659
+ tableState: createPlDataTableStateV2()
6077
6660
  }).argsValid(
6078
6661
  (ctx) => ctx.args.datasetRef !== void 0 && ctx.args.fileHandle !== void 0 && ctx.args.importColumns !== void 0 && ctx.args.sequenceColumnHeader !== void 0 && ctx.args.targetRef !== void 0 && ctx.uiState.fileImportError === void 0
6079
6662
  ).output(
@@ -6140,7 +6723,7 @@
6140
6723
  const cols = (_d = (_c = ctx.outputs) == null ? void 0 : _c.resolve("table")) == null ? void 0 : _d.getPColumns();
6141
6724
  if (cols === void 0)
6142
6725
  return void 0;
6143
- return Kn(
6726
+ return createPlDataTableV2(
6144
6727
  ctx,
6145
6728
  cols,
6146
6729
  ctx.uiState.tableState
@@ -6150,7 +6733,7 @@
6150
6733
  return ((_a = ctx.outputs) == null ? void 0 : _a.getIsReadyOrError()) === false;
6151
6734
  }).title((ctx) => ctx.uiState.title).sections((_ctx) => [
6152
6735
  { type: "link", href: "/", label: "Main" }
6153
- ]).done();
6736
+ ]).done(2);
6154
6737
  exports2.model = model;
6155
6738
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
6156
6739
  });