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

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