@milaboratories/uikit 2.3.0 → 2.3.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.
@@ -1,34 +1,1553 @@
1
- import { PlIdLength as m, getFileNameFromHandle as f, getFilePathFromHandle as p, isImportFileHandleIndex as g, isImportFileHandleUpload as d } from "../../../lib/model/common/dist/index.js";
2
- import r from "../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/index.js";
3
- import { BasePlErrorLike as u, ErrorLike as b, PlErrorLike as h, StandardErrorLike as P } from "../../../lib/model/pl-error-like/dist/index.js";
4
- function o(t) {
5
- if (t && typeof globalThis.getPlatforma == "function")
6
- return globalThis.getPlatforma(t);
1
+ import { isDataInfo as ae, extractAllColumns as Ee, mapPTableDef as Te, selectorsToPredicate as W, withEnrichments as ce, AnchoredIdDeriver as he, isPlRef as Fe, mapValueInVOE as Oe, mapPObjectData as le, ensurePColumn as ke, isPColumnSpec as G, isPColumn as be, resolveAnchors as de, deriveNativeId as Re, isPartitionedDataInfoEntries as De, getAxisId as pe, entriesToDataInfo as $e, isDataInfoEntries as _e, dataInfoToEntries as Ke, canonicalizeAxisId as Ne, mapDataInfo as je } from "../../../lib/model/common/dist/index.js";
2
+ import { PlIdLength as bt, getAxesId as _t, getFileNameFromHandle as wt, getFilePathFromHandle as Pt, isImportFileHandleIndex as At, isImportFileHandleUpload as xt, mapJoinEntry as It, matchAxis as St, matchAxisId as Ct, matchPColumn as Lt, stringifyColumnId as Et } from "../../../lib/model/common/dist/index.js";
3
+ import we from "../../../_virtual/canonicalize.js";
4
+ import K from "../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/index.js";
5
+ import { BasePlErrorLike as Ft, ErrorLike as Ot, PlErrorLike as kt, StandardErrorLike as Rt } from "../../../lib/model/pl-error-like/dist/index.js";
6
+ var Be = Object.defineProperty, Je = (n, e, t) => e in n ? Be(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, I = (n, e, t) => Je(n, typeof e != "symbol" ? e + "" : e, t);
7
+ function Q(n) {
8
+ return { type: "Immediate", value: n };
9
+ }
10
+ function Ve() {
11
+ return typeof globalThis.getPlatforma < "u" || typeof globalThis.platforma < "u";
12
+ }
13
+ function Pe(n) {
14
+ if (n && typeof globalThis.getPlatforma == "function")
15
+ return globalThis.getPlatforma(n);
7
16
  if (typeof globalThis.platforma < "u") return globalThis.platforma;
8
17
  throw new Error("Can't get platforma instance.");
9
18
  }
10
- const e = r.object({
11
- type: r.string(),
12
- importance: r.number().optional(),
13
- id: r.string().optional(),
14
- label: r.string()
19
+ function Ue() {
20
+ if (typeof globalThis.cfgRenderCtx < "u") return globalThis.cfgRenderCtx;
21
+ }
22
+ function c() {
23
+ if (typeof globalThis.cfgRenderCtx < "u") return globalThis.cfgRenderCtx;
24
+ throw new Error("Not in config rendering context");
25
+ }
26
+ function V(n, e) {
27
+ const t = Ue();
28
+ if (t === void 0) return !1;
29
+ if (n in t.callbackRegistry) throw new Error(`Callback with key ${n} already registered.`);
30
+ return t.callbackRegistry[n] = e, !0;
31
+ }
32
+ const X = /* @__PURE__ */ new Map();
33
+ function Me(n, e) {
34
+ n in c().callbackRegistry || (c().callbackRegistry[n] = (t) => {
35
+ for (const r of X.get(n))
36
+ r(t);
37
+ }, X.set(n, [])), X.get(n).push(e);
38
+ }
39
+ class w {
40
+ constructor(e, t = (r) => r) {
41
+ I(this, "isResolved", !1), I(this, "resolvedValue"), this.handle = e, this.postProcess = t, Me(e, (r) => {
42
+ this.resolvedValue = t(r), this.isResolved = !0;
43
+ });
44
+ }
45
+ map(e) {
46
+ return new w(this.handle, (t) => e(this.postProcess(t)));
47
+ }
48
+ mapDefined(e) {
49
+ return new w(this.handle, (t) => {
50
+ const r = this.postProcess(t);
51
+ return r ? e(r) : void 0;
52
+ });
53
+ }
54
+ toJSON() {
55
+ return this.isResolved ? this.resolvedValue : { __awaited_futures__: [this.handle] };
56
+ }
57
+ }
58
+ function re(n, e) {
59
+ return n === void 0 ? void 0 : e(n);
60
+ }
61
+ class S {
62
+ constructor(e, t) {
63
+ this.handle = e, this.resolvePath = t;
64
+ }
65
+ resolve(...e) {
66
+ const t = e.map(
67
+ (r) => ({
68
+ assertFieldType: "Input",
69
+ ...typeof r == "string" ? { field: r } : r
70
+ })
71
+ );
72
+ return this.resolveWithCommon({}, ...t);
73
+ }
74
+ resolveOutput(...e) {
75
+ const t = e.map(
76
+ (r) => ({
77
+ assertFieldType: "Output",
78
+ ...typeof r == "string" ? { field: r } : r
79
+ })
80
+ );
81
+ return this.resolveWithCommon({}, ...t);
82
+ }
83
+ resolveInput(...e) {
84
+ const t = e.map(
85
+ (r) => ({
86
+ assertFieldType: "Input",
87
+ ...typeof r == "string" ? { field: r } : r
88
+ })
89
+ );
90
+ return this.resolveWithCommon({}, ...t);
91
+ }
92
+ resolveAny(...e) {
93
+ return this.resolveWithCommon({}, ...e);
94
+ }
95
+ resolveWithCommon(e, ...t) {
96
+ const r = [
97
+ ...this.resolvePath,
98
+ ...t.map((i) => typeof i == "string" ? i : i.field)
99
+ ];
100
+ return re(
101
+ c().resolveWithCommon(this.handle, e, ...t),
102
+ (i) => new S(i, r)
103
+ );
104
+ }
105
+ get resourceType() {
106
+ return c().getResourceType(this.handle);
107
+ }
108
+ getInputsLocked() {
109
+ return c().getInputsLocked(this.handle);
110
+ }
111
+ getOutputsLocked() {
112
+ return c().getOutputsLocked(this.handle);
113
+ }
114
+ getIsReadyOrError() {
115
+ return c().getIsReadyOrError(this.handle);
116
+ }
117
+ getIsFinal() {
118
+ return c().getIsFinal(this.handle);
119
+ }
120
+ getError() {
121
+ const e = [...this.resolvePath, "error"];
122
+ return re(
123
+ c().getError(this.handle),
124
+ (t) => new S(t, e)
125
+ );
126
+ }
127
+ listInputFields() {
128
+ return c().listInputFields(this.handle);
129
+ }
130
+ listOutputFields() {
131
+ return c().listOutputFields(this.handle);
132
+ }
133
+ listDynamicFields() {
134
+ return c().listDynamicFields(this.handle);
135
+ }
136
+ getKeyValueBase64(e) {
137
+ return c().getKeyValueBase64(this.handle, e);
138
+ }
139
+ getKeyValueAsString(e) {
140
+ return c().getKeyValueAsString(this.handle, e);
141
+ }
142
+ getKeyValueAsJson(e) {
143
+ const t = this.getKeyValueAsString(e);
144
+ if (t == null) throw new Error("Resource has no content.");
145
+ return JSON.parse(t);
146
+ }
147
+ getDataBase64() {
148
+ return c().getDataBase64(this.handle);
149
+ }
150
+ getDataAsString() {
151
+ return c().getDataAsString(this.handle);
152
+ }
153
+ getDataAsJson() {
154
+ const e = this.getDataAsString();
155
+ if (e == null) throw new Error("Resource has no content.");
156
+ return JSON.parse(e);
157
+ }
158
+ /**
159
+ *
160
+ */
161
+ getPColumns(e = !1, t = "") {
162
+ const r = this.parsePObjectCollection(e, t);
163
+ return r === void 0 ? void 0 : Object.entries(r).map(([, i]) => {
164
+ if (!be(i)) throw new Error(`not a PColumn (kind = ${i.spec.kind})`);
165
+ return i;
166
+ });
167
+ }
168
+ /**
169
+ *
170
+ */
171
+ parsePObjectCollection(e = !1, t = "") {
172
+ const r = c().parsePObjectCollection(
173
+ this.handle,
174
+ e,
175
+ t,
176
+ ...this.resolvePath
177
+ );
178
+ if (r === void 0) return;
179
+ const i = {};
180
+ for (const [s, o] of Object.entries(r)) {
181
+ const a = [...this.resolvePath, s];
182
+ i[s] = le(o, (l) => new S(l, a));
183
+ }
184
+ return i;
185
+ }
186
+ getFileContentAsBase64(e) {
187
+ return new w(c().getBlobContentAsBase64(this.handle, e));
188
+ }
189
+ getFileContentAsString(e) {
190
+ return new w(c().getBlobContentAsString(this.handle, e));
191
+ }
192
+ getFileContentAsJson(e) {
193
+ return new w(
194
+ c().getBlobContentAsString(this.handle, e)
195
+ ).mapDefined((t) => JSON.parse(t));
196
+ }
197
+ /**
198
+ * @deprecated use getFileContentAsBase64
199
+ */
200
+ getBlobContentAsBase64() {
201
+ return this.getFileContentAsBase64();
202
+ }
203
+ /**
204
+ * @deprecated use getFileContentAsString
205
+ */
206
+ getBlobContentAsString() {
207
+ return this.getFileContentAsString();
208
+ }
209
+ /**
210
+ * @returns downloaded file handle
211
+ */
212
+ getFileHandle() {
213
+ return new w(c().getDownloadedBlobContentHandle(this.handle));
214
+ }
215
+ /**
216
+ * @deprecated use getFileHandle
217
+ */
218
+ getDownloadedBlobHandle() {
219
+ return this.getFileHandle();
220
+ }
221
+ /**
222
+ * @returns downloaded file handle
223
+ */
224
+ getRemoteFileHandle() {
225
+ return new w(c().getOnDemandBlobContentHandle(this.handle));
226
+ }
227
+ /**
228
+ * @deprecated use getRemoteFileHandle
229
+ */
230
+ getOnDemandBlobHandle() {
231
+ return this.getRemoteFileHandle();
232
+ }
233
+ /**
234
+ * @returns the url to the extracted folder
235
+ */
236
+ extractArchiveAndGetURL(e) {
237
+ return new w(c().extractArchiveAndGetURL(this.handle, e));
238
+ }
239
+ getImportProgress() {
240
+ return new w(c().getImportProgress(this.handle));
241
+ }
242
+ getLastLogs(e) {
243
+ return new w(c().getLastLogs(this.handle, e));
244
+ }
245
+ getProgressLog(e) {
246
+ return new w(c().getProgressLog(this.handle, e));
247
+ }
248
+ getProgressLogWithInfo(e) {
249
+ return new w(c().getProgressLogWithInfo(this.handle, e));
250
+ }
251
+ getLogHandle() {
252
+ return new w(c().getLogHandle(this.handle));
253
+ }
254
+ allFieldsResolved(e = "Input") {
255
+ switch (e) {
256
+ case "Input":
257
+ return this.getInputsLocked() && this.listInputFields().every(
258
+ (t) => this.resolve({ field: t, assertFieldType: "Input" }) !== void 0
259
+ );
260
+ case "Output":
261
+ return this.getOutputsLocked() && this.listOutputFields().every(
262
+ (t) => this.resolve({ field: t, assertFieldType: "Output" }) !== void 0
263
+ );
264
+ }
265
+ }
266
+ mapFields(e, t) {
267
+ const { fieldType: r, requireLocked: i, skipUnresolved: s } = {
268
+ fieldType: "Input",
269
+ requireLocked: !0,
270
+ skipUnresolved: !1,
271
+ ...t
272
+ }, o = e;
273
+ if (i && (r === "Input" && !this.getInputsLocked() || r === "Output" && !this.getOutputsLocked()))
274
+ return;
275
+ let a = (r === "Input" ? this.listInputFields() : r === "Output" ? this.listOutputFields() : this.listDynamicFields()).map(
276
+ (l) => [l, this.resolve({ field: l, assertFieldType: r })]
277
+ );
278
+ return s && (a = a.filter((l) => l[1] !== void 0)), a.map(([l, y]) => o(l, y));
279
+ }
280
+ }
281
+ const We = "staging", He = "main", qe = "pl7.app/label", ze = "pl7.app/trace", Ge = K.object({
282
+ type: K.string(),
283
+ importance: K.number().optional(),
284
+ id: K.string().optional(),
285
+ label: K.string()
286
+ }), Ye = K.array(Ge), Ze = 1e-3, Qe = "__LABEL__", fe = "__LABEL__@1";
287
+ function Ae(n, e, t = {}) {
288
+ const r = /* @__PURE__ */ new Map(), i = t.forceTraceElements !== void 0 && t.forceTraceElements.length > 0 ? new Set(t.forceTraceElements) : void 0, s = /* @__PURE__ */ new Map(), o = n.map((f) => {
289
+ var P, u;
290
+ const h = e(f);
291
+ let v, C, L;
292
+ "spec" in h && typeof h.spec == "object" ? (v = h.spec, C = h.prefixTrace, L = h.suffixTrace) : v = h;
293
+ const d = (P = v.annotations) == null ? void 0 : P[qe], A = (u = v.annotations) == null ? void 0 : u[ze], p = (A ? Ye.safeParse(JSON.parse(A)).data : void 0) ?? [], g = [
294
+ ...C ?? [],
295
+ ...p,
296
+ ...L ?? []
297
+ ];
298
+ if (d !== void 0) {
299
+ const x = { label: d, type: Qe, importance: -2 };
300
+ t.addLabelAsSuffix ? g.push(x) : g.splice(0, 0, x);
301
+ }
302
+ const m = [], T = /* @__PURE__ */ new Map();
303
+ for (let x = g.length - 1; x >= 0; --x) {
304
+ const { type: B } = g[x], k = g[x].importance ?? 0, D = (T.get(B) ?? 0) + 1;
305
+ T.set(B, D);
306
+ const O = `${B}@${D}`;
307
+ s.set(O, (s.get(O) ?? 0) + 1), r.set(
308
+ O,
309
+ Math.max(
310
+ r.get(O) ?? Number.NEGATIVE_INFINITY,
311
+ k - (g.length - x) * Ze
312
+ )
313
+ ), m.push({ ...g[x], fullType: O, occurrenceIndex: D });
314
+ }
315
+ return m.reverse(), {
316
+ value: f,
317
+ spec: v,
318
+ label: d,
319
+ fullTrace: m
320
+ };
321
+ }), a = [], l = [], y = [...r];
322
+ y.sort(([, f], [, P]) => P - f);
323
+ for (const [f] of y)
324
+ f.endsWith("@1") || s.get(f) === n.length ? a.push(f) : l.push(f);
325
+ const j = (f, P = !1) => {
326
+ const u = [];
327
+ for (let h = 0; h < o.length; h++) {
328
+ const v = o[h], C = v.fullTrace.filter((A) => f.has(A.fullType) || i && i.has(A.type));
329
+ if (C.length === 0)
330
+ if (P)
331
+ u.push({
332
+ label: "Unlabeled",
333
+ value: v.value
334
+ });
335
+ else return;
336
+ const L = C.map((A) => A.label), d = t.separator ?? " / ";
337
+ u.push({
338
+ label: L.join(d),
339
+ value: v.value
340
+ });
341
+ }
342
+ return u;
343
+ };
344
+ if (a.length === 0) {
345
+ if (l.length !== 0) throw new Error("Non-empty secondary types list while main types list is empty.");
346
+ return j(new Set(fe), !0);
347
+ }
348
+ let E = 0, F = -1;
349
+ for (; E < a.length; ) {
350
+ const f = /* @__PURE__ */ new Set();
351
+ t.includeNativeLabel && f.add(fe);
352
+ for (let u = 0; u < E; ++u) f.add(a[u]);
353
+ F >= 0 && f.add(a[F]);
354
+ const P = j(f);
355
+ if (P !== void 0 && new Set(P.map((u) => u.label)).size === n.length) return P;
356
+ F++, F >= a.length && (E++, F = E);
357
+ }
358
+ return j(/* @__PURE__ */ new Set([...a, ...l]), !0);
359
+ }
360
+ const H = "PColumnData/", ne = H + "ResourceMap", ie = H + "Partitioned/ResourceMap", U = H + "JsonPartitioned", N = H + "BinaryPartitioned", xe = H + "Partitioned/", Z = xe + "JsonPartitioned", M = xe + "BinaryPartitioned", se = (n) => {
361
+ if (n.endsWith(".index"))
362
+ return { baseKey: n.substring(0, n.length - 6), type: "index" };
363
+ if (n.endsWith(".values"))
364
+ return { baseKey: n.substring(0, n.length - 7), type: "values" };
365
+ throw new Error(`key must ends on .index/.values for binary p-column, got: ${n}`);
366
+ };
367
+ function Xe(n) {
368
+ if (!n) return;
369
+ const e = n.resourceType.name, t = n.getDataAsJson(), r = [];
370
+ let i = 0;
371
+ switch (e) {
372
+ case ne:
373
+ i = t.keyLength;
374
+ break;
375
+ case ie:
376
+ i = t.partitionKeyLength + t.keyLength;
377
+ break;
378
+ case U:
379
+ case N:
380
+ i = t.partitionKeyLength;
381
+ break;
382
+ case M:
383
+ case Z:
384
+ i = t.superPartitionKeyLength + t.partitionKeyLength;
385
+ break;
386
+ }
387
+ switch (e) {
388
+ case ne:
389
+ case U:
390
+ case N:
391
+ for (let s of n.listInputFields()) {
392
+ e === N && (s = se(s).baseKey);
393
+ const o = [...JSON.parse(s)];
394
+ r.push(o);
395
+ }
396
+ break;
397
+ case ie:
398
+ case M:
399
+ case Z:
400
+ for (const s of n.listInputFields()) {
401
+ const o = [...JSON.parse(s)], a = n.resolve({ field: s, assertFieldType: "Input" });
402
+ if (a !== void 0)
403
+ for (let l of a.listInputFields()) {
404
+ e === M && (l = se(l).baseKey);
405
+ const y = [...o, ...JSON.parse(l)];
406
+ r.push(y);
407
+ }
408
+ }
409
+ break;
410
+ }
411
+ return { data: r, keyLength: i };
412
+ }
413
+ function et(n) {
414
+ if (n.type !== "JsonPartitioned" && n.type !== "BinaryPartitioned")
415
+ throw new Error(`Splitting requires Partitioned DataInfoEntries, got ${n.type}`);
416
+ const { parts: e, partitionKeyLength: t } = n, r = [];
417
+ for (let i = 0; i < t; ++i)
418
+ r.push(/* @__PURE__ */ new Set());
419
+ for (const i of e) {
420
+ const s = i.key;
421
+ if (s.length !== t)
422
+ throw new Error(
423
+ `Key length (${s.length}) does not match partition length (${t}) for key: ${JSON.stringify(
424
+ s
425
+ )}`
426
+ );
427
+ for (let o = 0; o < t; ++o)
428
+ r[o].add(s[o]);
429
+ }
430
+ return r.map((i) => Array.from(i.values()));
431
+ }
432
+ function tt(n) {
433
+ if (n === void 0) return;
434
+ if (_e(n))
435
+ return et(n);
436
+ const e = Xe(n);
437
+ if (!e) return;
438
+ const { data: t, keyLength: r } = e, i = [];
439
+ for (let s = 0; s < r; ++s)
440
+ i.push(/* @__PURE__ */ new Set());
441
+ for (const s of t) {
442
+ if (s.length !== r)
443
+ throw new Error("key length does not match partition length");
444
+ for (let o = 0; o < r; ++o)
445
+ i[o].add(s[o]);
446
+ }
447
+ return i.map((s) => Array.from(s.values()));
448
+ }
449
+ function oe(n, e = []) {
450
+ if (n === void 0 || !n.getIsReadyOrError()) return;
451
+ const t = n.resourceType.name, r = n.getDataAsJson();
452
+ if (e.length > 0 && (t === Z || t === M))
453
+ throw new Error(`Unexpected nested super-partitioned resource: ${t}`);
454
+ switch (t) {
455
+ case ne:
456
+ case ie:
457
+ throw new Error(`Only data columns are supported, got: ${t}`);
458
+ case U: {
459
+ if (typeof (r == null ? void 0 : r.partitionKeyLength) != "number")
460
+ throw new Error(`Missing partitionKeyLength in metadata for ${t}`);
461
+ const i = [];
462
+ for (const s of n.listInputFields()) {
463
+ const o = n.resolve({ field: s, assertFieldType: "Input" });
464
+ if (o === void 0) return;
465
+ const a = [...e, ...JSON.parse(s)];
466
+ i.push({ key: a, value: o });
467
+ }
468
+ return {
469
+ type: "JsonPartitioned",
470
+ partitionKeyLength: r.partitionKeyLength,
471
+ parts: i
472
+ };
473
+ }
474
+ case N: {
475
+ if (typeof (r == null ? void 0 : r.partitionKeyLength) != "number")
476
+ throw new Error(`Missing partitionKeyLength in metadata for ${t}`);
477
+ const i = [], s = /* @__PURE__ */ new Map();
478
+ for (const o of n.listInputFields()) {
479
+ const a = se(o), l = n.resolve({ field: o, assertFieldType: "Input" });
480
+ if (l === void 0) return;
481
+ let y = s.get(a.baseKey);
482
+ y || (y = {}, s.set(a.baseKey, y)), a.type === "index" ? y.index = l : y.values = l;
483
+ }
484
+ for (const [o, a] of s.entries()) {
485
+ if (!a.index || !a.values) return;
486
+ const l = [...e, ...JSON.parse(o)];
487
+ i.push({
488
+ key: l,
489
+ value: {
490
+ index: a.index,
491
+ values: a.values
492
+ }
493
+ });
494
+ }
495
+ return {
496
+ type: "BinaryPartitioned",
497
+ partitionKeyLength: r.partitionKeyLength,
498
+ parts: i
499
+ };
500
+ }
501
+ case Z: {
502
+ if (typeof (r == null ? void 0 : r.superPartitionKeyLength) != "number" || typeof (r == null ? void 0 : r.partitionKeyLength) != "number")
503
+ throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${t}`);
504
+ const i = r.superPartitionKeyLength + r.partitionKeyLength, s = [];
505
+ for (const o of n.listInputFields()) {
506
+ const a = n.resolve({ field: o, assertFieldType: "Input" });
507
+ if (a === void 0) return;
508
+ if (a.resourceType.name !== U)
509
+ throw new Error(`Expected ${U} inside ${t}, but got ${a.resourceType.name}`);
510
+ const l = oe(a, JSON.parse(o));
511
+ if (l === void 0) return;
512
+ if (l.type !== "JsonPartitioned")
513
+ throw new Error(`Unexpected inner result type for ${t}: ${l.type}`);
514
+ s.push(...l.parts);
515
+ }
516
+ return {
517
+ type: "JsonPartitioned",
518
+ partitionKeyLength: i,
519
+ parts: s
520
+ };
521
+ }
522
+ case M: {
523
+ if (typeof (r == null ? void 0 : r.superPartitionKeyLength) != "number" || typeof (r == null ? void 0 : r.partitionKeyLength) != "number")
524
+ throw new Error(`Missing superPartitionKeyLength or partitionKeyLength in metadata for ${t}`);
525
+ const i = r.superPartitionKeyLength + r.partitionKeyLength, s = [];
526
+ for (const o of n.listInputFields()) {
527
+ const a = n.resolve({ field: o, assertFieldType: "Input" });
528
+ if (a === void 0) return;
529
+ if (a.resourceType.name !== N)
530
+ throw new Error(`Expected ${N} inside ${t}, but got ${a.resourceType.name}`);
531
+ const l = oe(a, JSON.parse(o));
532
+ if (l === void 0) return;
533
+ if (l.type !== "BinaryPartitioned")
534
+ throw new Error(`Unexpected inner result type for ${t}: ${l.type}`);
535
+ s.push(...l.parts);
536
+ }
537
+ return {
538
+ type: "BinaryPartitioned",
539
+ partitionKeyLength: i,
540
+ parts: s
541
+ };
542
+ }
543
+ default:
544
+ throw new Error(`Unknown resource type: ${t}`);
545
+ }
546
+ }
547
+ function rt(n) {
548
+ if (n !== void 0) {
549
+ if (_e(n)) return n;
550
+ if (ae(n)) return Ke(n);
551
+ if (n instanceof S) return oe(n);
552
+ throw new Error(`Unexpected input type: ${typeof n}`);
553
+ }
554
+ }
555
+ function nt(n, e) {
556
+ const t = [...e].sort((s, o) => o[0] - s[0]);
557
+ if (n.type === "JsonPartitioned" || n.type === "BinaryPartitioned") {
558
+ const { partitionKeyLength: s } = n;
559
+ for (const [o] of e)
560
+ if (o >= s)
561
+ throw new Error(`Can't filter on non-partitioned axis ${o}. Must be >= ${s}`);
562
+ } else if (n.type === "Json") {
563
+ const { keyLength: s } = n;
564
+ for (const [o] of e)
565
+ if (o >= s)
566
+ throw new Error(`Can't filter on non-data axis ${o}. Must be >= ${s}`);
567
+ }
568
+ const r = (s) => {
569
+ for (const [o, a] of t)
570
+ if (s[o] !== a)
571
+ return !1;
572
+ return !0;
573
+ }, i = (s) => {
574
+ const o = [...s];
575
+ for (const [a] of t)
576
+ o.splice(a, 1);
577
+ return o;
578
+ };
579
+ switch (n.type) {
580
+ case "Json": {
581
+ const s = n.data.filter((o) => r(o.key)).map((o) => ({
582
+ key: i(o.key),
583
+ value: o.value
584
+ }));
585
+ return {
586
+ type: "Json",
587
+ keyLength: n.keyLength - e.length,
588
+ data: s
589
+ };
590
+ }
591
+ case "JsonPartitioned": {
592
+ const s = n.parts.filter((o) => r(o.key)).map((o) => ({
593
+ key: i(o.key),
594
+ value: o.value
595
+ }));
596
+ return {
597
+ type: "JsonPartitioned",
598
+ partitionKeyLength: n.partitionKeyLength - e.length,
599
+ parts: s
600
+ };
601
+ }
602
+ case "BinaryPartitioned": {
603
+ const s = n.parts.filter((o) => r(o.key)).map((o) => ({
604
+ key: i(o.key),
605
+ value: o.value
606
+ }));
607
+ return {
608
+ type: "BinaryPartitioned",
609
+ partitionKeyLength: n.partitionKeyLength - e.length,
610
+ parts: s
611
+ };
612
+ }
613
+ }
614
+ }
615
+ function it(n) {
616
+ if (!Array.isArray(n)) return !1;
617
+ if (n.length === 0) return !0;
618
+ const e = n[0];
619
+ return typeof e == "object" && e !== null && "key" in e && "val" in e;
620
+ }
621
+ class st {
622
+ constructor(e) {
623
+ this.columns = e;
624
+ }
625
+ selectColumns(e) {
626
+ const t = typeof e == "function" ? e : W(e);
627
+ return this.columns.filter((r) => t(r.spec));
628
+ }
629
+ }
630
+ function ot(n) {
631
+ if (n)
632
+ return n.map((e) => ({
633
+ type: `split:${Ne(e.axisId)}`,
634
+ label: e.label,
635
+ importance: 1e6
636
+ // High importance for split filters in labels
637
+ }));
638
+ }
639
+ function at(n) {
640
+ if (n)
641
+ return n.map((e) => [e.axisIdx, e.value]);
642
+ }
643
+ function lt(n, e) {
644
+ if (!e || e.length === 0) return n;
645
+ const t = [...e].sort((r, i) => r[0] - i[0]);
646
+ return we({ id: n, axisFilters: t });
647
+ }
648
+ function ge(n) {
649
+ if (!n || typeof n != "object") return !1;
650
+ const e = n, t = 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);
651
+ return !!e.domainAnchor || t || r;
652
+ }
653
+ function ut(n) {
654
+ if (typeof n != "object" || !("axes" in n) || n.axes === void 0)
655
+ return [];
656
+ const e = n.axes.map((t, r) => typeof t == "object" && "split" in t && t.split === !0 ? r : -1).filter((t) => t !== -1);
657
+ if (e.length > 0 && n.partialAxesMatch !== void 0)
658
+ throw new Error("Axis splitting is not supported when `partialAxesMatch` is defined.");
659
+ return e.sort((t, r) => t - r), e;
660
+ }
661
+ class me {
662
+ constructor() {
663
+ I(this, "defaultProviderStore", []), I(this, "providers", [new st(this.defaultProviderStore)]), I(this, "axisLabelProviders", []);
664
+ }
665
+ addColumnProvider(e) {
666
+ return this.providers.push(e), this;
667
+ }
668
+ addAxisLabelProvider(e) {
669
+ return this.axisLabelProviders.push(e), this;
670
+ }
671
+ addColumns(e) {
672
+ return this.defaultProviderStore.push(...e), this;
673
+ }
674
+ addColumn(e) {
675
+ return this.defaultProviderStore.push(e), this;
676
+ }
677
+ /** Fetches labels for a given axis from the registered providers */
678
+ findLabels(e) {
679
+ for (const t of this.axisLabelProviders) {
680
+ const r = t.findLabels(e);
681
+ if (r) return r;
682
+ }
683
+ }
684
+ getUniversalEntries(e, t) {
685
+ const { anchorCtx: r, labelOps: i, dontWaitAllData: s = !1, overrideLabelAnnotation: o = !1, exclude: a } = t ?? {}, l = {
686
+ ...o && (i == null ? void 0 : i.includeNativeLabel) !== !1 ? { includeNativeLabel: !0 } : {},
687
+ ...i ?? {}
688
+ };
689
+ let y = () => !1;
690
+ if (a) {
691
+ const u = (Array.isArray(a) ? a : [a]).map((h) => {
692
+ if (ge(h)) {
693
+ if (!r)
694
+ throw new Error("Anchored selectors in exclude require an AnchoredIdDeriver to be provided in options.");
695
+ return W(de(r.anchors, h, t));
696
+ } else
697
+ return W(h);
698
+ });
699
+ y = (h) => u.some((v) => v(h));
700
+ }
701
+ const j = typeof e == "function" ? [e] : Array.isArray(e) ? e : [e], E = [], F = /* @__PURE__ */ new Set();
702
+ for (const u of j) {
703
+ const h = ge(u);
704
+ let v;
705
+ if (h) {
706
+ if (!r)
707
+ throw new Error("Anchored selectors require an AnchoredIdDeriver to be provided in options.");
708
+ v = de(r.anchors, u, t);
709
+ } else
710
+ v = u;
711
+ const C = /* @__PURE__ */ new Set(), L = [];
712
+ for (const p of this.providers) {
713
+ const g = p.selectColumns(v);
714
+ for (const m of g) {
715
+ if (y(m.spec)) continue;
716
+ if (C.has(m.id))
717
+ throw new Error(`Duplicate column id ${m.id} in provider ${p.constructor.name}`);
718
+ const T = Re(m.spec);
719
+ F.has(T) || (C.add(m.id), F.add(T), L.push(m));
720
+ }
721
+ }
722
+ if (L.length === 0) continue;
723
+ const d = ut(u), A = d.length > 0;
724
+ for (const p of L) {
725
+ if (!G(p.spec)) continue;
726
+ const g = p.spec;
727
+ if (A) {
728
+ if (it(p.data))
729
+ throw new Error(`Splitting is not supported for PColumns with PColumnValues data format. Column id: ${p.id}`);
730
+ const m = rt(p.data);
731
+ if (!m) {
732
+ if (s) continue;
733
+ return;
734
+ }
735
+ if (!De(m))
736
+ throw new Error(`Splitting requires Partitioned DataInfoEntries, but parsing resulted in ${m.type} for column ${p.id}`);
737
+ const T = tt(m), x = d[d.length - 1];
738
+ if (x >= m.partitionKeyLength)
739
+ throw new Error(`Not enough partition keys (${m.partitionKeyLength}) for requested split axes (max index ${x}) in column ${g.name}`);
740
+ const B = d.map((b) => this.findLabels(pe(g.axesSpec[b]))), k = [], D = (b, J) => {
741
+ if (J >= d.length) {
742
+ if (k.push([...b]), k.length > 1e4)
743
+ throw new Error("Too many key combinations, aborting.");
744
+ return;
745
+ }
746
+ const R = d[J];
747
+ if (R >= T.length)
748
+ throw new Error(`Axis index ${R} out of bounds for unique keys array (length ${T.length}) during split key generation for column ${p.id}`);
749
+ const $ = T[R];
750
+ if (!$ || $.length === 0) {
751
+ k.length = 0;
752
+ return;
753
+ }
754
+ for (const q of $)
755
+ b.push(q), D(b, J + 1), b.pop();
756
+ };
757
+ if (D([], 0), k.length === 0)
758
+ continue;
759
+ const O = [...g.axesSpec], Ie = d.map((b) => b);
760
+ for (let b = d.length - 1; b >= 0; b--)
761
+ O.splice(d[b], 1);
762
+ const Se = { ...g, axesSpec: O };
763
+ for (const b of k) {
764
+ const J = b.map((R, $) => {
765
+ const q = Ie[$], Ce = pe(g.axesSpec[q]), ue = B[$], Le = (ue == null ? void 0 : ue[R]) ?? String(R);
766
+ return { axisIdx: q, axisId: Ce, value: R, label: Le };
767
+ });
768
+ E.push({
769
+ type: "split",
770
+ originalColumn: p,
771
+ spec: g,
772
+ adjustedSpec: Se,
773
+ dataEntries: m,
774
+ axisFilters: J
775
+ });
776
+ }
777
+ } else
778
+ E.push({
779
+ type: "direct",
780
+ originalColumn: p,
781
+ spec: g,
782
+ adjustedSpec: g
783
+ });
784
+ }
785
+ }
786
+ if (E.length === 0) return [];
787
+ const f = Ae(
788
+ E,
789
+ (u) => ({
790
+ spec: u.spec,
791
+ suffixTrace: u.type === "split" ? ot(u.axisFilters) : void 0
792
+ }),
793
+ l
794
+ ), P = [];
795
+ for (const { value: u, label: h } of f) {
796
+ const { originalColumn: v, spec: C } = u, L = u.type === "split" ? u.axisFilters : void 0, d = at(L);
797
+ let A;
798
+ r ? A = r.deriveS(C, d) : A = lt(v.id, d);
799
+ let p = { ...u.adjustedSpec };
800
+ o && (p = {
801
+ ...p,
802
+ annotations: {
803
+ ...p.annotations ?? {},
804
+ "pl7.app/label": h
805
+ }
806
+ }), P.push({
807
+ id: A,
808
+ spec: p,
809
+ data: () => u.type === "split" ? $e(nt(u.dataEntries, d)) : u.originalColumn.data,
810
+ label: h
811
+ });
812
+ }
813
+ return P;
814
+ }
815
+ getColumns(e, t) {
816
+ const r = this.getUniversalEntries(e, {
817
+ overrideLabelAnnotation: !0,
818
+ // default for getColumns
819
+ ...t ?? {}
820
+ });
821
+ if (!r) return;
822
+ const i = [];
823
+ for (const s of r) {
824
+ const o = s.data();
825
+ if (!o) {
826
+ if (t != null && t.dontWaitAllData) continue;
827
+ return;
828
+ }
829
+ i.push({
830
+ id: s.id,
831
+ spec: s.spec,
832
+ data: o
833
+ });
834
+ }
835
+ return i;
836
+ }
837
+ }
838
+ function ye(n) {
839
+ const e = (i) => i.operator !== "InSet" ? i : {
840
+ operator: "Or",
841
+ operands: i.references.map((s) => ({
842
+ operator: "Equal",
843
+ reference: s
844
+ }))
845
+ }, t = (i, s) => {
846
+ switch (i.operator) {
847
+ case "And":
848
+ return {
849
+ ...i,
850
+ operands: i.operands.map((o) => t(o, s))
851
+ };
852
+ case "Or":
853
+ return {
854
+ ...i,
855
+ operands: i.operands.map((o) => t(o, s))
856
+ };
857
+ case "Not":
858
+ return {
859
+ ...i,
860
+ operand: t(i.operand, s)
861
+ };
862
+ default:
863
+ return s(i);
864
+ }
865
+ }, r = (i, s) => ({
866
+ ...i,
867
+ predicate: t(i.predicate, s)
868
+ });
869
+ return n.map((i) => r(i, e));
870
+ }
871
+ function ee(n, e) {
872
+ if (n === void 0) return e === void 0;
873
+ if (e === void 0) return !0;
874
+ for (const t in e)
875
+ if (n[t] !== e[t]) return !1;
876
+ return !0;
877
+ }
878
+ function ve(n) {
879
+ return le(n, (e) => e instanceof S ? e.handle : ae(e) ? je(e, (t) => t.handle) : e);
880
+ }
881
+ class ct {
882
+ constructor() {
883
+ I(this, "ctx", c());
884
+ }
885
+ /**
886
+ * @deprecated use getOptions()
887
+ */
888
+ calculateOptions(e) {
889
+ return this.ctx.calculateOptions(e);
890
+ }
891
+ getOptions(e, t) {
892
+ const r = typeof e == "function" ? e : W(e), i = this.getSpecs().entries.filter((a) => r(a.obj));
893
+ let s = {}, o = !1;
894
+ return typeof t < "u" && (typeof t == "function" ? s = t : typeof t == "object" && ("includeNativeLabel" in t || "separator" in t || "addLabelAsSuffix" in t ? s = t : (t = t, s = t.label ?? {}, o = t.refsWithEnrichments ?? !1))), typeof s == "object" ? Ae(i, (a) => a.obj, s ?? {}).map(({ value: { ref: a }, label: l }) => ({
895
+ ref: ce(a, o),
896
+ label: l
897
+ })) : i.map(({ ref: a, obj: l }) => ({
898
+ ref: ce(a, o),
899
+ label: s(l, a)
900
+ }));
901
+ }
902
+ resolveAnchorCtx(e) {
903
+ if (e instanceof he) return e;
904
+ const t = {};
905
+ for (const [r, i] of Object.entries(e))
906
+ if (Fe(i)) {
907
+ const s = this.getPColumnSpecByRef(i);
908
+ if (!s)
909
+ return;
910
+ t[r] = s;
911
+ } else
912
+ t[r] = i;
913
+ return new he(t);
914
+ }
915
+ /**
916
+ * Returns columns that match the provided anchors and selectors. It applies axis filters and label derivation.
917
+ *
918
+ * @param anchorsOrCtx - Anchor context for column selection (same as in getCanonicalOptions)
919
+ * @param predicateOrSelectors - Predicate or selectors for filtering columns (same as in getCanonicalOptions)
920
+ * @param opts - Optional configuration for label generation and data waiting
921
+ * @returns A PFrameHandle for the created PFrame, or undefined if any required data is missing
922
+ */
923
+ getAnchoredPColumns(e, t, r) {
924
+ const i = this.resolveAnchorCtx(e);
925
+ if (i)
926
+ return new me().addColumnProvider(this).addAxisLabelProvider(this).getColumns(t, {
927
+ ...r,
928
+ anchorCtx: i
929
+ });
930
+ }
931
+ /**
932
+ * Calculates anchored identifier options for columns matching a given predicate and returns their
933
+ * canonicalized representations.
934
+ *
935
+ * This function filters column specifications from the result pool that match the provided predicate,
936
+ * creates a standardized AnchorCtx from the provided anchors, and generates a list of label-value
937
+ * pairs for UI components (like dropdowns).
938
+ *
939
+ * @param anchorsOrCtx - Either:
940
+ * - An existing AnchorCtx instance
941
+ * - A record mapping anchor IDs to PColumnSpec objects
942
+ * - A record mapping anchor IDs to PlRef objects (which will be resolved to PColumnSpec)
943
+ * @param predicateOrSelectors - Either:
944
+ * - A predicate function that takes a PColumnSpec and returns a boolean.
945
+ * Only specs that return true will be included.
946
+ * - An APColumnSelector object for declarative filtering, which will be
947
+ * resolved against the provided anchors and matched using matchPColumn.
948
+ * - An array of APColumnSelector objects - columns matching ANY selector
949
+ * in the array will be included (OR operation).
950
+ * @param opts - Optional configuration for label generation:
951
+ * - labelOps: Optional configuration for label generation:
952
+ * - includeNativeLabel: Whether to include native column labels
953
+ * - separator: String to use between label parts (defaults to " / ")
954
+ * - addLabelAsSuffix: Whether to add labels as suffix instead of prefix
955
+ * - dontWaitAllData: Whether to skip columns that don't have all data (if not set, will return undefined,
956
+ * if at least one column that requires splitting is missing data)
957
+ * @returns An array of objects with `label` (display text) and `value` (anchored ID string) properties,
958
+ * or undefined if any PlRef resolution fails.
959
+ */
960
+ getCanonicalOptions(e, t, r) {
961
+ const i = this.resolveAnchorCtx(e);
962
+ if (!i) return;
963
+ const s = new me().addColumnProvider(this).addAxisLabelProvider(this).getUniversalEntries(t, {
964
+ ...r,
965
+ anchorCtx: i
966
+ });
967
+ if (s)
968
+ return s.map((o) => ({
969
+ value: o.id,
970
+ label: o.label
971
+ }));
972
+ }
973
+ /**
974
+ * @deprecated use getData()
975
+ */
976
+ getDataFromResultPool() {
977
+ return this.getData();
978
+ }
979
+ getData() {
980
+ const e = this.ctx.getDataFromResultPool();
981
+ return {
982
+ isComplete: e.isComplete,
983
+ entries: e.entries.map((t) => ({
984
+ ref: t.ref,
985
+ obj: {
986
+ ...t.obj,
987
+ data: new S(t.obj.data, [t.ref.blockId, t.ref.name])
988
+ }
989
+ }))
990
+ };
991
+ }
992
+ /**
993
+ * @deprecated use getDataWithErrors()
994
+ */
995
+ getDataWithErrorsFromResultPool() {
996
+ return this.getDataWithErrors();
997
+ }
998
+ getDataWithErrors() {
999
+ const e = this.ctx.getDataWithErrorsFromResultPool();
1000
+ return {
1001
+ isComplete: e.isComplete,
1002
+ entries: e.entries.map((t) => ({
1003
+ ref: t.ref,
1004
+ obj: {
1005
+ ...t.obj,
1006
+ data: Oe(
1007
+ t.obj.data,
1008
+ (r) => new S(r, [t.ref.blockId, t.ref.name])
1009
+ )
1010
+ }
1011
+ }))
1012
+ };
1013
+ }
1014
+ /**
1015
+ * @deprecated use getSpecs()
1016
+ */
1017
+ getSpecsFromResultPool() {
1018
+ return this.getSpecs();
1019
+ }
1020
+ getSpecs() {
1021
+ return this.ctx.getSpecsFromResultPool();
1022
+ }
1023
+ /**
1024
+ * @param ref a Ref
1025
+ * @returns data associated with the ref
1026
+ */
1027
+ getDataByRef(e) {
1028
+ var t;
1029
+ if (typeof this.ctx.getDataFromResultPoolByRef > "u")
1030
+ return (t = this.getData().entries.find(
1031
+ (i) => i.ref.blockId === e.blockId && i.ref.name === e.name
1032
+ )) == null ? void 0 : t.obj;
1033
+ const r = this.ctx.getDataFromResultPoolByRef(e.blockId, e.name);
1034
+ if (r)
1035
+ return le(
1036
+ r,
1037
+ (i) => new S(i, [e.blockId, e.name])
1038
+ );
1039
+ }
1040
+ /**
1041
+ * Returns data associated with the ref ensuring that it is a p-column.
1042
+ * @param ref a Ref
1043
+ * @returns p-column associated with the ref
1044
+ */
1045
+ getPColumnByRef(e) {
1046
+ const t = this.getDataByRef(e);
1047
+ if (t)
1048
+ return ke(t);
1049
+ }
1050
+ /**
1051
+ * Returns spec associated with the ref ensuring that it is a p-column spec.
1052
+ * @param ref a Ref
1053
+ * @returns p-column spec associated with the ref
1054
+ */
1055
+ getPColumnSpecByRef(e) {
1056
+ const t = this.getSpecByRef(e);
1057
+ if (t) {
1058
+ if (!G(t)) throw new Error(`not a PColumn spec (kind = ${t.kind})`);
1059
+ return t;
1060
+ }
1061
+ }
1062
+ /**
1063
+ * @param ref a Ref
1064
+ * @returns object spec associated with the ref
1065
+ */
1066
+ getSpecByRef(e) {
1067
+ return this.ctx.getSpecFromResultPoolByRef(e.blockId, e.name);
1068
+ }
1069
+ /**
1070
+ * @param spec object specification
1071
+ * @returns array of data objects with compatible specs
1072
+ * @deprecated delete this method after Jan 1, 2025
1073
+ */
1074
+ findDataWithCompatibleSpec(e) {
1075
+ const t = [];
1076
+ e: for (const r of this.getData().entries) {
1077
+ if (!G(r.obj.spec))
1078
+ continue;
1079
+ const i = r.obj.spec;
1080
+ if (e.name === i.name && e.valueType === i.valueType && e.axesSpec.length === i.axesSpec.length && ee(e.domain, i.domain)) {
1081
+ for (let s = 0; s < e.axesSpec.length; ++s) {
1082
+ const o = e.axesSpec[s], a = i.axesSpec[s];
1083
+ if (o.name !== a.name || o.type !== a.type || !ee(o.domain, a.domain))
1084
+ continue e;
1085
+ }
1086
+ t.push(r.obj);
1087
+ }
1088
+ }
1089
+ return t;
1090
+ }
1091
+ /**
1092
+ * Find labels data for a given axis id. It will search for a label column and return its data as a map.
1093
+ * @returns a map of axis value => label
1094
+ */
1095
+ findLabels(e) {
1096
+ const t = this.getData();
1097
+ for (const r of t.entries) {
1098
+ if (!be(r.obj)) continue;
1099
+ const i = r.obj.spec;
1100
+ if (i.name === "pl7.app/label" && i.axesSpec.length === 1 && i.axesSpec[0].name === e.name && i.axesSpec[0].type === e.type && ee(e.domain, i.axesSpec[0].domain)) {
1101
+ if (r.obj.data.resourceType.name !== "PColumnData/Json")
1102
+ throw Error(`Expected JSON column for labels, got: ${r.obj.data.resourceType.name}`);
1103
+ return Object.fromEntries(
1104
+ Object.entries(
1105
+ r.obj.data.getDataAsJson().data
1106
+ ).map((s) => [JSON.parse(s[0])[0], s[1]])
1107
+ );
1108
+ }
1109
+ }
1110
+ }
1111
+ /**
1112
+ * Selects columns based on the provided selectors, returning PColumn objects
1113
+ * with lazily loaded data.
1114
+ *
1115
+ * @param selectors - A predicate function, a single selector, or an array of selectors.
1116
+ * @returns An array of PColumn objects matching the selectors. Data is loaded on first access.
1117
+ */
1118
+ selectColumns(e) {
1119
+ const t = typeof e == "function" ? e : W(e);
1120
+ return this.getSpecs().entries.filter(({ obj: r }) => G(r) ? t(r) : !1).map(({ ref: r, obj: i }) => {
1121
+ const s = i;
1122
+ let o = null;
1123
+ const a = this;
1124
+ return {
1125
+ id: we(r),
1126
+ spec: s,
1127
+ get data() {
1128
+ var l;
1129
+ return o !== null || (o = (l = a.getPColumnByRef(r)) == null ? void 0 : l.data), o;
1130
+ }
1131
+ };
1132
+ });
1133
+ }
1134
+ /**
1135
+ * Find labels data for a given axis id of a p-column.
1136
+ * @returns a map of axis value => label
1137
+ */
1138
+ findLabelsForColumnAxis(e, t) {
1139
+ var r;
1140
+ const i = this.findLabels(e.axesSpec[t]);
1141
+ if (!i) return;
1142
+ const s = (r = e.annotations) == null ? void 0 : r["pl7.app/axisKeys/" + t];
1143
+ if (s !== void 0) {
1144
+ const o = JSON.parse(s);
1145
+ return Object.fromEntries(o.map((a) => [a, i[a] ?? "Unlabelled"]));
1146
+ } else
1147
+ return i;
1148
+ }
1149
+ }
1150
+ class z {
1151
+ constructor() {
1152
+ I(this, "ctx"), I(this, "_argsCache"), I(this, "_uiStateCache"), I(this, "_activeArgsCache"), I(this, "resultPool", new ct()), this.ctx = c();
1153
+ }
1154
+ get args() {
1155
+ if (this._argsCache === void 0) {
1156
+ const e = this.ctx.args, t = typeof e == "function" ? e() : e;
1157
+ this._argsCache = { v: JSON.parse(t) };
1158
+ }
1159
+ return this._argsCache.v;
1160
+ }
1161
+ get uiState() {
1162
+ if (this._uiStateCache === void 0) {
1163
+ const e = this.ctx.uiState, t = typeof e == "function" ? e() : e;
1164
+ this._uiStateCache = { v: t ? JSON.parse(t) : {} };
1165
+ }
1166
+ return this._uiStateCache.v;
1167
+ }
1168
+ /**
1169
+ * Returns args snapshot the block was executed for (i.e. when "Run" button was pressed).
1170
+ * Returns undefined, if block was never executed or stopped mid-way execution, so that the result was cleared.
1171
+ * */
1172
+ get activeArgs() {
1173
+ if (this._activeArgsCache === void 0) {
1174
+ const e = this.ctx.activeArgs, t = typeof e == "function" ? e() : e;
1175
+ this._activeArgsCache = {
1176
+ v: t ? JSON.parse(t) : void 0
1177
+ };
1178
+ }
1179
+ return this._activeArgsCache.v;
1180
+ }
1181
+ // /** Can be used to determine features provided by the desktop instance. */
1182
+ // public get featureFlags() {
1183
+ // return this.ctx.featureFlags;
1184
+ // }
1185
+ getNamedAccessor(e) {
1186
+ return re(
1187
+ this.ctx.getAccessorHandleByName(e),
1188
+ (t) => new S(t, [e])
1189
+ );
1190
+ }
1191
+ get prerun() {
1192
+ return this.getNamedAccessor(We);
1193
+ }
1194
+ get outputs() {
1195
+ return this.getNamedAccessor(He);
1196
+ }
1197
+ /**
1198
+ * Find labels data for a given axis id. It will search for a label column and return its data as a map.
1199
+ * @returns a map of axis value => label
1200
+ * @deprecated Use resultPool.findLabels instead
1201
+ */
1202
+ findLabels(e) {
1203
+ return this.resultPool.findLabels(e);
1204
+ }
1205
+ verifyInlineAndExplicitColumnsSupport(e) {
1206
+ var t;
1207
+ const r = e.some((s) => !(s.data instanceof S) || ae(s.data)), i = ((t = this.ctx.featureFlags) == null ? void 0 : t.inlineColumnsSupport) === !0;
1208
+ if (r && !i) throw Error("Inline or explicit columns not supported");
1209
+ }
1210
+ patchPTableDef(e) {
1211
+ var t, r;
1212
+ return (t = this.ctx.featureFlags) != null && t.pTablePartitionFiltersSupport || (e = {
1213
+ ...e,
1214
+ partitionFilters: [],
1215
+ filters: [...e.partitionFilters, ...e.filters]
1216
+ }), (r = this.ctx.featureFlags) != null && r.pFrameInSetFilterSupport || (e = {
1217
+ ...e,
1218
+ partitionFilters: ye(e.partitionFilters),
1219
+ filters: ye(e.filters)
1220
+ }), e;
1221
+ }
1222
+ // TODO remove all non-PColumn fields
1223
+ createPFrame(e) {
1224
+ return this.verifyInlineAndExplicitColumnsSupport(e), this.ctx.createPFrame(
1225
+ e.map((t) => ve(t))
1226
+ );
1227
+ }
1228
+ createPTable(e) {
1229
+ let t;
1230
+ return "columns" in e ? t = this.patchPTableDef({
1231
+ src: {
1232
+ type: "full",
1233
+ entries: e.columns.map((r) => ({ type: "column", column: r }))
1234
+ },
1235
+ partitionFilters: e.filters ?? [],
1236
+ filters: [],
1237
+ sorting: e.sorting ?? []
1238
+ }) : t = this.patchPTableDef(e), this.verifyInlineAndExplicitColumnsSupport(Ee(t.src)), this.ctx.createPTable(
1239
+ Te(t, (r) => ve(r))
1240
+ );
1241
+ }
1242
+ /** @deprecated scheduled for removal from SDK */
1243
+ getBlockLabel(e) {
1244
+ return this.ctx.getBlockLabel(e);
1245
+ }
1246
+ getCurrentUnstableMarker() {
1247
+ return this.ctx.getCurrentUnstableMarker();
1248
+ }
1249
+ logInfo(e) {
1250
+ this.ctx.logInfo(e);
1251
+ }
1252
+ logWarn(e) {
1253
+ this.ctx.logWarn(e);
1254
+ }
1255
+ logError(e) {
1256
+ this.ctx.logError(e);
1257
+ }
1258
+ }
1259
+ const Y = "1.39.6";
1260
+ function ht(n) {
1261
+ return n.__renderLambda === !0;
1262
+ }
1263
+ function te(n) {
1264
+ if (n !== void 0)
1265
+ return ht(n) ? n.handle : n;
1266
+ }
1267
+ const dt = class _ {
1268
+ constructor(e, t, r, i, s, o, a, l, y) {
1269
+ this._renderingMode = e, this._initialArgs = t, this._initialUiState = r, this._outputs = i, this._inputsValid = s, this._sections = o, this._title = a, this._enrichmentTargets = l, this._featureFlags = y;
1270
+ }
1271
+ static create(e = "Heavy") {
1272
+ return new _(
1273
+ e,
1274
+ void 0,
1275
+ {},
1276
+ {},
1277
+ Q(!0),
1278
+ Q([]),
1279
+ void 0,
1280
+ void 0,
1281
+ { ..._.INITIAL_BLOCK_FEATURE_FLAGS }
1282
+ );
1283
+ }
1284
+ output(e, t, r = {}) {
1285
+ if (typeof t == "function") {
1286
+ const i = `output#${e}`;
1287
+ return V(i, () => t(new z())), new _(
1288
+ this._renderingMode,
1289
+ this._initialArgs,
1290
+ this._initialUiState,
1291
+ {
1292
+ ...this._outputs,
1293
+ [e]: {
1294
+ __renderLambda: !0,
1295
+ handle: i,
1296
+ ...r
1297
+ }
1298
+ },
1299
+ this._inputsValid,
1300
+ this._sections,
1301
+ this._title,
1302
+ this._enrichmentTargets,
1303
+ this._featureFlags
1304
+ );
1305
+ } else
1306
+ return new _(
1307
+ this._renderingMode,
1308
+ this._initialArgs,
1309
+ this._initialUiState,
1310
+ {
1311
+ ...this._outputs,
1312
+ [e]: t
1313
+ },
1314
+ this._inputsValid,
1315
+ this._sections,
1316
+ this._title,
1317
+ this._enrichmentTargets,
1318
+ this._featureFlags
1319
+ );
1320
+ }
1321
+ /** Shortcut for {@link output} with retentive flag set to true. */
1322
+ retentiveOutput(e, t) {
1323
+ return this.output(e, t, { retentive: !0 });
1324
+ }
1325
+ argsValid(e) {
1326
+ return typeof e == "function" ? (V("inputsValid", () => e(new z())), new _(
1327
+ this._renderingMode,
1328
+ this._initialArgs,
1329
+ this._initialUiState,
1330
+ this._outputs,
1331
+ {
1332
+ __renderLambda: !0,
1333
+ handle: "inputsValid"
1334
+ },
1335
+ this._sections,
1336
+ this._title,
1337
+ this._enrichmentTargets,
1338
+ this._featureFlags
1339
+ )) : new _(
1340
+ this._renderingMode,
1341
+ this._initialArgs,
1342
+ this._initialUiState,
1343
+ this._outputs,
1344
+ e,
1345
+ this._sections,
1346
+ this._title,
1347
+ this._enrichmentTargets,
1348
+ this._featureFlags
1349
+ );
1350
+ }
1351
+ sections(e) {
1352
+ return Array.isArray(e) ? this.sections(Q(e)) : typeof e == "function" ? (V("sections", () => e(new z())), new _(
1353
+ this._renderingMode,
1354
+ this._initialArgs,
1355
+ this._initialUiState,
1356
+ this._outputs,
1357
+ this._inputsValid,
1358
+ { __renderLambda: !0, handle: "sections" },
1359
+ this._title,
1360
+ this._enrichmentTargets,
1361
+ this._featureFlags
1362
+ )) : new _(
1363
+ this._renderingMode,
1364
+ this._initialArgs,
1365
+ this._initialUiState,
1366
+ this._outputs,
1367
+ this._inputsValid,
1368
+ e,
1369
+ this._title,
1370
+ this._enrichmentTargets,
1371
+ this._featureFlags
1372
+ );
1373
+ }
1374
+ /** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
1375
+ title(e) {
1376
+ return V("title", () => e(new z())), new _(
1377
+ this._renderingMode,
1378
+ this._initialArgs,
1379
+ this._initialUiState,
1380
+ this._outputs,
1381
+ this._inputsValid,
1382
+ this._sections,
1383
+ { __renderLambda: !0, handle: "title" },
1384
+ this._enrichmentTargets,
1385
+ this._featureFlags
1386
+ );
1387
+ }
1388
+ /**
1389
+ * Sets initial args for the block, this value must be specified.
1390
+ * @deprecated use {@link withArgs}
1391
+ * */
1392
+ initialArgs(e) {
1393
+ return new _(
1394
+ this._renderingMode,
1395
+ e,
1396
+ this._initialUiState,
1397
+ this._outputs,
1398
+ this._inputsValid,
1399
+ this._sections,
1400
+ this._title,
1401
+ this._enrichmentTargets,
1402
+ this._featureFlags
1403
+ );
1404
+ }
1405
+ /** Sets initial args for the block, this value must be specified. */
1406
+ withArgs(e) {
1407
+ return new _(
1408
+ this._renderingMode,
1409
+ e,
1410
+ this._initialUiState,
1411
+ this._outputs,
1412
+ this._inputsValid,
1413
+ this._sections,
1414
+ this._title,
1415
+ this._enrichmentTargets,
1416
+ this._featureFlags
1417
+ );
1418
+ }
1419
+ /** Defines type and sets initial value for block UiState. */
1420
+ withUiState(e) {
1421
+ return new _(
1422
+ this._renderingMode,
1423
+ this._initialArgs,
1424
+ e,
1425
+ this._outputs,
1426
+ this._inputsValid,
1427
+ this._sections,
1428
+ this._title,
1429
+ this._enrichmentTargets,
1430
+ this._featureFlags
1431
+ );
1432
+ }
1433
+ /**
1434
+ * Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.
1435
+ * Influences dependency graph construction.
1436
+ */
1437
+ enriches(e) {
1438
+ return V("enrichmentTargets", e), new _(
1439
+ this._renderingMode,
1440
+ this._initialArgs,
1441
+ this._initialUiState,
1442
+ this._outputs,
1443
+ this._inputsValid,
1444
+ this._sections,
1445
+ this._title,
1446
+ { __renderLambda: !0, handle: "enrichmentTargets" },
1447
+ this._featureFlags
1448
+ );
1449
+ }
1450
+ /** Renders all provided block settings into a pre-configured platforma API
1451
+ * instance, that can be used in frontend to interact with block state, and
1452
+ * other features provided by the platforma to the block. */
1453
+ done() {
1454
+ if (this._initialArgs === void 0) throw new Error("Initial arguments not set.");
1455
+ const e = {
1456
+ v3: {
1457
+ sdkVersion: Y,
1458
+ renderingMode: this._renderingMode,
1459
+ initialArgs: this._initialArgs,
1460
+ initialUiState: this._initialUiState,
1461
+ inputsValid: this._inputsValid,
1462
+ sections: this._sections,
1463
+ title: this._title,
1464
+ outputs: this._outputs,
1465
+ enrichmentTargets: this._enrichmentTargets,
1466
+ featureFlags: this._featureFlags
1467
+ },
1468
+ // fields below are added to allow previous desktop versions read generated configs
1469
+ sdkVersion: Y,
1470
+ renderingMode: this._renderingMode,
1471
+ initialArgs: this._initialArgs,
1472
+ inputsValid: te(this._inputsValid),
1473
+ sections: te(this._sections),
1474
+ outputs: Object.fromEntries(
1475
+ Object.entries(this._outputs).map(([t, r]) => [t, te(r)])
1476
+ )
1477
+ };
1478
+ return Ve() ? Pe({ sdkVersion: Y }) : { config: e };
1479
+ }
1480
+ };
1481
+ I(dt, "INITIAL_BLOCK_FEATURE_FLAGS", {
1482
+ supportsLazyState: !0,
1483
+ requiresUIAPIVersion: 1,
1484
+ requiresModelAPIVersion: 1
15
1485
  });
16
- r.array(e);
17
- const a = "1.38.0";
18
- function l() {
19
- return o({ sdkVersion: a });
1486
+ function mt() {
1487
+ return Pe({ sdkVersion: Y });
20
1488
  }
21
1489
  export {
22
- u as BasePlErrorLike,
23
- b as ErrorLike,
24
- h as PlErrorLike,
25
- m as PlIdLength,
26
- P as StandardErrorLike,
27
- e as TraceEntry,
28
- f as getFileNameFromHandle,
29
- p as getFilePathFromHandle,
30
- l as getRawPlatformaInstance,
31
- g as isImportFileHandleIndex,
32
- d as isImportFileHandleUpload
1490
+ he as AnchoredIdDeriver,
1491
+ Ft as BasePlErrorLike,
1492
+ Ot as ErrorLike,
1493
+ w as FutureRef,
1494
+ qe as PAnnotationLabel,
1495
+ ze as PAnnotationTrace,
1496
+ me as PColumnCollection,
1497
+ kt as PlErrorLike,
1498
+ bt as PlIdLength,
1499
+ N as RT_BINARY_PARTITIONED,
1500
+ M as RT_BINARY_SUPER_PARTITIONED,
1501
+ U as RT_JSON_PARTITIONED,
1502
+ Z as RT_JSON_SUPER_PARTITIONED,
1503
+ ne as RT_RESOURCE_MAP,
1504
+ ie as RT_RESOURCE_MAP_PARTITIONED,
1505
+ z as RenderCtx,
1506
+ ct as ResultPool,
1507
+ Rt as StandardErrorLike,
1508
+ Ye as Trace,
1509
+ Ge as TraceEntry,
1510
+ S as TreeNodeAccessor,
1511
+ Ne as canonicalizeAxisId,
1512
+ rt as convertOrParsePColumnData,
1513
+ Ke as dataInfoToEntries,
1514
+ Ae as deriveLabels,
1515
+ Re as deriveNativeId,
1516
+ te as downgradeCfgOrLambda,
1517
+ ke as ensurePColumn,
1518
+ $e as entriesToDataInfo,
1519
+ Ee as extractAllColumns,
1520
+ nt as filterDataInfoEntries,
1521
+ _t as getAxesId,
1522
+ pe as getAxisId,
1523
+ wt as getFileNameFromHandle,
1524
+ Pt as getFilePathFromHandle,
1525
+ Q as getImmediate,
1526
+ Xe as getPartitionKeysList,
1527
+ mt as getRawPlatformaInstance,
1528
+ tt as getUniquePartitionKeys,
1529
+ re as ifDef,
1530
+ ht as isConfigLambda,
1531
+ ae as isDataInfo,
1532
+ _e as isDataInfoEntries,
1533
+ At as isImportFileHandleIndex,
1534
+ xt as isImportFileHandleUpload,
1535
+ be as isPColumn,
1536
+ G as isPColumnSpec,
1537
+ De as isPartitionedDataInfoEntries,
1538
+ Fe as isPlRef,
1539
+ je as mapDataInfo,
1540
+ It as mapJoinEntry,
1541
+ le as mapPObjectData,
1542
+ Te as mapPTableDef,
1543
+ Oe as mapValueInVOE,
1544
+ St as matchAxis,
1545
+ Ct as matchAxisId,
1546
+ Lt as matchPColumn,
1547
+ oe as parsePColumnData,
1548
+ de as resolveAnchors,
1549
+ W as selectorsToPredicate,
1550
+ Et as stringifyColumnId,
1551
+ ce as withEnrichments
33
1552
  };
34
1553
  //# sourceMappingURL=index.js.map