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

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