@milaboratories/pl-tree 1.5.2 → 1.5.3
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/accessors.d.ts +7 -3
- package/dist/accessors.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +122 -116
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
- package/src/accessors.ts +14 -8
package/dist/index.mjs
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
1
|
var W = Object.defineProperty;
|
|
2
|
-
var M = (
|
|
3
|
-
var d = (
|
|
2
|
+
var M = (n, e, t) => e in n ? W(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var d = (n, e, t) => M(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
import { resourceIdToString as R, resourceTypesEqual as A, resourceTypeToString as U, isNotNullResourceId as g, NullResourceId as T, isNullResourceId as b, stringifyWithResourceId as D, isTimeoutOrCancelError as J } from "@milaboratories/pl-client";
|
|
5
5
|
import { ChangeSource as m, PollingComputableHooks as q } from "@milaboratories/computable";
|
|
6
6
|
import { parsePlError as V } from "@milaboratories/pl-errors";
|
|
7
7
|
import { notEmpty as p, msToHumanReadable as z } from "@milaboratories/ts-helpers";
|
|
8
8
|
import H from "denque";
|
|
9
9
|
import * as j from "node:timers/promises";
|
|
10
|
-
function ae(
|
|
11
|
-
if (
|
|
12
|
-
return P(
|
|
10
|
+
function ae(n, e) {
|
|
11
|
+
if (n !== void 0)
|
|
12
|
+
return P(n, e);
|
|
13
13
|
}
|
|
14
|
-
function P(
|
|
14
|
+
function P(n, e) {
|
|
15
15
|
const t = {};
|
|
16
|
-
return
|
|
16
|
+
return n.value !== void 0 && (t.value = e(n.value)), n.error !== void 0 && (t.error = e(n.error)), t;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
class ne extends Error {
|
|
19
|
+
constructor(e) {
|
|
20
|
+
super(e);
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
|
-
function oe(
|
|
22
|
-
return typeof
|
|
23
|
+
function oe(n) {
|
|
24
|
+
return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeEntry";
|
|
23
25
|
}
|
|
24
|
-
function ue(
|
|
25
|
-
return typeof
|
|
26
|
+
function ue(n) {
|
|
27
|
+
return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeEntryAccessor";
|
|
28
|
+
}
|
|
29
|
+
function de(n) {
|
|
30
|
+
return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeNodeAccessor";
|
|
26
31
|
}
|
|
27
32
|
class C {
|
|
28
33
|
constructor(e, t) {
|
|
@@ -42,24 +47,24 @@ class C {
|
|
|
42
47
|
return `[ENTRY:${R(this.rid)}]`;
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
|
-
function N(
|
|
46
|
-
const
|
|
47
|
-
|
|
50
|
+
function N(n, e, t, r, s) {
|
|
51
|
+
const o = new Y(
|
|
52
|
+
n,
|
|
48
53
|
e,
|
|
49
54
|
e.get(t.ctx.watcher, r),
|
|
50
55
|
t
|
|
51
56
|
);
|
|
52
57
|
if (!s.ignoreError) {
|
|
53
|
-
const a =
|
|
58
|
+
const a = o.getError();
|
|
54
59
|
if (a !== void 0)
|
|
55
|
-
throw V(p(a.getDataAsString()),
|
|
60
|
+
throw V(p(a.getDataAsString()), o.id, o.resourceType);
|
|
56
61
|
}
|
|
57
|
-
if (s.assertResourceType !== void 0 && (Array.isArray(s.assertResourceType) ? s.assertResourceType.findIndex((a) => A(a,
|
|
62
|
+
if (s.assertResourceType !== void 0 && (Array.isArray(s.assertResourceType) ? s.assertResourceType.findIndex((a) => A(a, o.resourceType)) === -1 : !A(s.assertResourceType, o.resourceType)))
|
|
58
63
|
throw new Error(
|
|
59
64
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
60
|
-
`wrong resource type ${U(
|
|
65
|
+
`wrong resource type ${U(o.resourceType)} but expected ${s.assertResourceType}`
|
|
61
66
|
);
|
|
62
|
-
return
|
|
67
|
+
return o;
|
|
63
68
|
}
|
|
64
69
|
class E {
|
|
65
70
|
constructor(e, t, r, s) {
|
|
@@ -70,8 +75,8 @@ class E {
|
|
|
70
75
|
return this.instanceData.guard(), this.accessorData.hooks !== void 0 && this.instanceData.ctx.attacheHooks(this.accessorData.hooks), N(this.accessorData, this.tree, this.instanceData, this.rid, e);
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
|
-
function
|
|
74
|
-
return
|
|
78
|
+
function ce(n, e) {
|
|
79
|
+
return n instanceof C ? e.accessor(n).node().resourceInfo : n;
|
|
75
80
|
}
|
|
76
81
|
class Y {
|
|
77
82
|
constructor(e, t, r, s) {
|
|
@@ -112,13 +117,13 @@ class Y {
|
|
|
112
117
|
traverseOrErrorWithCommon(e, ...t) {
|
|
113
118
|
let r = this;
|
|
114
119
|
for (const s of t) {
|
|
115
|
-
const
|
|
120
|
+
const o = typeof s == "string" ? {
|
|
116
121
|
...e,
|
|
117
122
|
field: s
|
|
118
123
|
} : { ...e, ...s }, a = r.getField(s);
|
|
119
|
-
if (a === void 0 ||
|
|
124
|
+
if (a === void 0 || o.pureFieldErrorToUndefined && a.value === void 0 && a.error !== void 0)
|
|
120
125
|
return;
|
|
121
|
-
if ((!
|
|
126
|
+
if ((!o.ignoreError || a.value === void 0) && a.error !== void 0)
|
|
122
127
|
return {
|
|
123
128
|
ok: !1,
|
|
124
129
|
// FIXME: in next tickets we'll allow Errors to be thrown.
|
|
@@ -126,16 +131,16 @@ class Y {
|
|
|
126
131
|
p(a.error.getDataAsString()),
|
|
127
132
|
r.id,
|
|
128
133
|
r.resourceType,
|
|
129
|
-
|
|
134
|
+
o.field
|
|
130
135
|
)
|
|
131
136
|
};
|
|
132
137
|
if (a.value === void 0) {
|
|
133
|
-
if (
|
|
138
|
+
if (o.errorIfFieldNotSet)
|
|
134
139
|
return {
|
|
135
140
|
ok: !1,
|
|
136
|
-
error: `field have no assigned value ${
|
|
141
|
+
error: new Error(`field have no assigned value ${o.field} of ${R(r.id)}`)
|
|
137
142
|
};
|
|
138
|
-
this.onUnstableLambda("unpopulated_field:" +
|
|
143
|
+
this.onUnstableLambda("unpopulated_field:" + o.field);
|
|
139
144
|
return;
|
|
140
145
|
}
|
|
141
146
|
r = a.value;
|
|
@@ -230,9 +235,9 @@ class S extends Error {
|
|
|
230
235
|
}
|
|
231
236
|
}
|
|
232
237
|
class $ {
|
|
233
|
-
constructor(e, t, r, s,
|
|
238
|
+
constructor(e, t, r, s, o, a, i) {
|
|
234
239
|
d(this, "change", new m());
|
|
235
|
-
this.name = e, this.type = t, this.value = r, this.error = s, this.status =
|
|
240
|
+
this.name = e, this.type = t, this.value = r, this.error = s, this.status = o, this.valueIsFinal = a, this.resourceVersion = i;
|
|
236
241
|
}
|
|
237
242
|
get state() {
|
|
238
243
|
return {
|
|
@@ -301,8 +306,8 @@ class G {
|
|
|
301
306
|
getField(e, t, r = () => {
|
|
302
307
|
}) {
|
|
303
308
|
var a, i, f;
|
|
304
|
-
const s = typeof t == "string" ? { field: t } : t,
|
|
305
|
-
if (
|
|
309
|
+
const s = typeof t == "string" ? { field: t } : t, o = this.fieldsMap.get(s.field);
|
|
310
|
+
if (o === void 0) {
|
|
306
311
|
if (s.errorIfFieldNotFound || s.errorIfFieldNotSet)
|
|
307
312
|
throw new Error(
|
|
308
313
|
`Field "${s.field}" not found in resource ${R(this.id)}`
|
|
@@ -322,12 +327,12 @@ class G {
|
|
|
322
327
|
(f = this.dynamicFieldListChanged) == null || f.attachWatcher(e), !this._finalState && !s.stableIfNotFound && r("field_not_found:" + s.field);
|
|
323
328
|
return;
|
|
324
329
|
} else {
|
|
325
|
-
if (s.assertFieldType !== void 0 &&
|
|
330
|
+
if (s.assertFieldType !== void 0 && o.type !== s.assertFieldType)
|
|
326
331
|
throw new Error(
|
|
327
|
-
`Unexpected field type: expected ${s.assertFieldType} but got ${
|
|
332
|
+
`Unexpected field type: expected ${s.assertFieldType} but got ${o.type} for the field name ${s.field}`
|
|
328
333
|
);
|
|
329
334
|
const l = {};
|
|
330
|
-
return g(
|
|
335
|
+
return g(o.value) && (l.value = o.value), g(o.error) && (l.error = o.error), l.value === void 0 && l.error === void 0 && r("field_not_resolved:" + s.field), o.change.attachWatcher(e), l;
|
|
331
336
|
}
|
|
332
337
|
}
|
|
333
338
|
getInputsLocked(e) {
|
|
@@ -360,22 +365,22 @@ class G {
|
|
|
360
365
|
listInputFields(e) {
|
|
361
366
|
var r;
|
|
362
367
|
const t = [];
|
|
363
|
-
return this.fieldsMap.forEach((s,
|
|
364
|
-
(s.type === "Input" || s.type === "Service") && t.push(
|
|
368
|
+
return this.fieldsMap.forEach((s, o) => {
|
|
369
|
+
(s.type === "Input" || s.type === "Service") && t.push(o);
|
|
365
370
|
}), this.inputsLocked || (r = this.inputAndServiceFieldListChanged) == null || r.attachWatcher(e), t;
|
|
366
371
|
}
|
|
367
372
|
listOutputFields(e) {
|
|
368
373
|
var r;
|
|
369
374
|
const t = [];
|
|
370
|
-
return this.fieldsMap.forEach((s,
|
|
371
|
-
s.type === "Output" && t.push(
|
|
375
|
+
return this.fieldsMap.forEach((s, o) => {
|
|
376
|
+
s.type === "Output" && t.push(o);
|
|
372
377
|
}), this.outputsLocked || (r = this.outputFieldListChanged) == null || r.attachWatcher(e), t;
|
|
373
378
|
}
|
|
374
379
|
listDynamicFields(e) {
|
|
375
380
|
var r;
|
|
376
381
|
const t = [];
|
|
377
|
-
return this.fieldsMap.forEach((s,
|
|
378
|
-
s.type !== "Input" && s.type !== "Output" && t.push(
|
|
382
|
+
return this.fieldsMap.forEach((s, o) => {
|
|
383
|
+
s.type !== "Input" && s.type !== "Output" && t.push(o);
|
|
379
384
|
}), (r = this.dynamicFieldListChanged) == null || r.attachWatcher(e), t;
|
|
380
385
|
}
|
|
381
386
|
getKeyValue(e, t) {
|
|
@@ -426,8 +431,8 @@ class G {
|
|
|
426
431
|
}
|
|
427
432
|
/** Used for invalidation */
|
|
428
433
|
markAllChanged() {
|
|
429
|
-
var e, t, r, s,
|
|
430
|
-
this.fieldsMap.forEach((f) => f.change.markChanged()), (e = this.finalChanged) == null || e.markChanged(), (t = this.resourceStateChange) == null || t.markChanged(), (r = this.lockedChange) == null || r.markChanged(), (s = this.inputAndServiceFieldListChanged) == null || s.markChanged(), (
|
|
434
|
+
var e, t, r, s, o, a, i;
|
|
435
|
+
this.fieldsMap.forEach((f) => f.change.markChanged()), (e = this.finalChanged) == null || e.markChanged(), (t = this.resourceStateChange) == null || t.markChanged(), (r = this.lockedChange) == null || r.markChanged(), (s = this.inputAndServiceFieldListChanged) == null || s.markChanged(), (o = this.outputFieldListChanged) == null || o.markChanged(), (a = this.dynamicFieldListChanged) == null || a.markChanged(), (i = this.kvChanged) == null || i.markChanged(), this.resourceRemoved.markChanged();
|
|
431
436
|
}
|
|
432
437
|
}
|
|
433
438
|
class O {
|
|
@@ -535,10 +540,10 @@ class O {
|
|
|
535
540
|
throw this.invalidateTree(), new S(`orphan resource ${a}`);
|
|
536
541
|
i.refCount++;
|
|
537
542
|
}
|
|
538
|
-
let
|
|
539
|
-
for (;
|
|
543
|
+
let o = s;
|
|
544
|
+
for (; o.length > 0; ) {
|
|
540
545
|
const a = [];
|
|
541
|
-
for (const i of
|
|
546
|
+
for (const i of o) {
|
|
542
547
|
const f = this.resources.get(i);
|
|
543
548
|
if (!f)
|
|
544
549
|
throw this.invalidateTree(), new S(`orphan resource ${i}`);
|
|
@@ -546,7 +551,7 @@ class O {
|
|
|
546
551
|
g(l.value) && a.push(l.value), g(l.error) && a.push(l.error), l.change.markChanged();
|
|
547
552
|
}), g(f.error) && a.push(f.error), f.resourceRemoved.markChanged(), this.resources.delete(i));
|
|
548
553
|
}
|
|
549
|
-
|
|
554
|
+
o = a;
|
|
550
555
|
}
|
|
551
556
|
if (!t) {
|
|
552
557
|
for (const a of e)
|
|
@@ -570,11 +575,11 @@ class O {
|
|
|
570
575
|
return Array.from(this.resources.values()).map((e) => e.extendedState);
|
|
571
576
|
}
|
|
572
577
|
}
|
|
573
|
-
function Q(
|
|
578
|
+
function Q(n, e) {
|
|
574
579
|
const t = [], r = /* @__PURE__ */ new Set();
|
|
575
|
-
return
|
|
580
|
+
return n.forEachResource((s) => {
|
|
576
581
|
s.finalState ? r.add(s.id) : t.push(s.id);
|
|
577
|
-
}), t.length === 0 && r.size === 0 && t.push(
|
|
582
|
+
}), t.length === 0 && r.size === 0 && t.push(n.root), { seedResources: t, finalResources: r, pruningFunction: e };
|
|
578
583
|
}
|
|
579
584
|
function F() {
|
|
580
585
|
return {
|
|
@@ -590,33 +595,33 @@ function F() {
|
|
|
590
595
|
millisSpent: 0
|
|
591
596
|
};
|
|
592
597
|
}
|
|
593
|
-
function
|
|
594
|
-
let e = `Requests: ${
|
|
598
|
+
function he(n) {
|
|
599
|
+
let e = `Requests: ${n.requests}
|
|
595
600
|
`;
|
|
596
|
-
return e += `Total time: ${z(
|
|
597
|
-
`, e += `Round-trips: ${
|
|
598
|
-
`, e += `Resources: ${
|
|
599
|
-
`, e += `Fields: ${
|
|
600
|
-
`, e += `KV: ${
|
|
601
|
-
`, e += `Data Bytes: ${
|
|
602
|
-
`, e += `KV Bytes: ${
|
|
603
|
-
`, e += `Pruned fields: ${
|
|
604
|
-
`, e += `Final resources skipped: ${
|
|
601
|
+
return e += `Total time: ${z(n.millisSpent)}
|
|
602
|
+
`, e += `Round-trips: ${n.roundTrips}
|
|
603
|
+
`, e += `Resources: ${n.retrievedResources}
|
|
604
|
+
`, e += `Fields: ${n.retrievedFields}
|
|
605
|
+
`, e += `KV: ${n.retrievedKeyValues}
|
|
606
|
+
`, e += `Data Bytes: ${n.retrievedResourceDataBytes}
|
|
607
|
+
`, e += `KV Bytes: ${n.retrievedKeyValueBytes}
|
|
608
|
+
`, e += `Pruned fields: ${n.prunedFields}
|
|
609
|
+
`, e += `Final resources skipped: ${n.finalResourcesSkipped}`, e;
|
|
605
610
|
}
|
|
606
|
-
async function X(
|
|
611
|
+
async function X(n, e, t) {
|
|
607
612
|
var c;
|
|
608
613
|
const r = Date.now();
|
|
609
614
|
t && t.requests++;
|
|
610
|
-
const { seedResources: s, finalResources:
|
|
615
|
+
const { seedResources: s, finalResources: o, pruningFunction: a } = e, i = new H();
|
|
611
616
|
let f = !0, l = 0;
|
|
612
617
|
const h = /* @__PURE__ */ new Set(), k = (v) => {
|
|
613
618
|
if (b(v) || h.has(v)) return;
|
|
614
|
-
if (
|
|
619
|
+
if (o.has(v)) {
|
|
615
620
|
t && t.finalResourcesSkipped++;
|
|
616
621
|
return;
|
|
617
622
|
}
|
|
618
623
|
h.add(v);
|
|
619
|
-
const y =
|
|
624
|
+
const y = n.getResourceDataIfExists(v, !0), w = n.listKeyValuesIfResourceExists(v), B = f;
|
|
620
625
|
f && (f = !1), i.push(
|
|
621
626
|
(async () => {
|
|
622
627
|
const [I, _] = await Promise.all([y, w]);
|
|
@@ -651,13 +656,13 @@ async function X(o, e, t) {
|
|
|
651
656
|
}
|
|
652
657
|
return t && (t.millisSpent += Date.now() - r, t.roundTrips += l), u;
|
|
653
658
|
}
|
|
654
|
-
function
|
|
655
|
-
return
|
|
659
|
+
function le(n) {
|
|
660
|
+
return n;
|
|
656
661
|
}
|
|
657
|
-
function
|
|
662
|
+
function fe(n, e, t) {
|
|
658
663
|
var a;
|
|
659
|
-
const r =
|
|
660
|
-
if (e.data !== void 0 && (e.data === "raw" ?
|
|
664
|
+
const r = n instanceof C ? p(t).accessor(n).node() : n instanceof E ? n.node() : n, o = { ...r.resourceInfo };
|
|
665
|
+
if (e.data !== void 0 && (e.data === "raw" ? o.data = r.getData() : o.data = e.data.parse(r.getDataAsJson())), e.fields !== void 0) {
|
|
661
666
|
const i = {};
|
|
662
667
|
for (const [f, l] of Object.entries(e.fields))
|
|
663
668
|
i[f] = (a = r.traverse({
|
|
@@ -665,7 +670,7 @@ function le(o, e, t) {
|
|
|
665
670
|
errorIfFieldNotSet: l,
|
|
666
671
|
stableIfNotFound: !l
|
|
667
672
|
})) == null ? void 0 : a.id;
|
|
668
|
-
|
|
673
|
+
o.fields = i;
|
|
669
674
|
}
|
|
670
675
|
if (e.kv !== void 0) {
|
|
671
676
|
const i = {};
|
|
@@ -675,13 +680,13 @@ function le(o, e, t) {
|
|
|
675
680
|
throw new Error(`Key not found ${f}`);
|
|
676
681
|
l === "raw" ? i[f] = h : i[f] = l.parse(JSON.parse(Buffer.from(h).toString("utf-8")));
|
|
677
682
|
}
|
|
678
|
-
|
|
683
|
+
o.kv = i;
|
|
679
684
|
}
|
|
680
|
-
return
|
|
685
|
+
return o;
|
|
681
686
|
}
|
|
682
|
-
function
|
|
683
|
-
if (
|
|
684
|
-
const r = t.accessor(
|
|
687
|
+
function ge(n, e, t) {
|
|
688
|
+
if (n instanceof C) {
|
|
689
|
+
const r = t.accessor(n).node(), s = r.resourceInfo, o = e.map((a) => {
|
|
685
690
|
var i, f;
|
|
686
691
|
return [
|
|
687
692
|
a,
|
|
@@ -690,18 +695,18 @@ function fe(o, e, t) {
|
|
|
690
695
|
});
|
|
691
696
|
return {
|
|
692
697
|
...s,
|
|
693
|
-
fields: new Map(
|
|
698
|
+
fields: new Map(o),
|
|
694
699
|
data: r.getData() ?? new Uint8Array()
|
|
695
700
|
};
|
|
696
701
|
}
|
|
697
|
-
return
|
|
702
|
+
return n;
|
|
698
703
|
}
|
|
699
|
-
function
|
|
700
|
-
if (!(
|
|
701
|
-
const r = t.accessor(
|
|
704
|
+
function pe(n, e, t) {
|
|
705
|
+
if (!(n instanceof C)) return n;
|
|
706
|
+
const r = t.accessor(n).node(), s = r.resourceInfo, o = e.map((a) => [a, r.getKeyValue(a)]);
|
|
702
707
|
return {
|
|
703
708
|
...s,
|
|
704
|
-
metadata: Object.fromEntries(
|
|
709
|
+
metadata: Object.fromEntries(o)
|
|
705
710
|
};
|
|
706
711
|
}
|
|
707
712
|
class K {
|
|
@@ -721,8 +726,8 @@ class K {
|
|
|
721
726
|
/** If true this tree state is permanently terminaed. */
|
|
722
727
|
d(this, "terminated", !1);
|
|
723
728
|
this.pl = e, this.root = t, this.logger = s;
|
|
724
|
-
const { finalPredicateOverride:
|
|
725
|
-
this.pruning = a, this.pollingInterval = i, this.finalPredicate =
|
|
729
|
+
const { finalPredicateOverride: o, pruning: a, pollingInterval: i, stopPollingDelay: f, logStat: l } = r;
|
|
730
|
+
this.pruning = a, this.pollingInterval = i, this.finalPredicate = o ?? e.finalPredicate, this.logStat = l, this.state = new O(t, this.finalPredicate), this.hooks = new q(
|
|
726
731
|
() => this.startUpdating(),
|
|
727
732
|
() => this.stopUpdating(),
|
|
728
733
|
{ stopDebounce: f },
|
|
@@ -758,7 +763,7 @@ class K {
|
|
|
758
763
|
/** Executed from the main loop, and initialization procedure. */
|
|
759
764
|
async refresh(e, t) {
|
|
760
765
|
if (this.terminated) throw new Error("tree synchronization is terminated");
|
|
761
|
-
const r = Q(this.state, this.pruning), s = await this.pl.withReadTx("ReadingTree", async (
|
|
766
|
+
const r = Q(this.state, this.pruning), s = await this.pl.withReadTx("ReadingTree", async (o) => await X(o, r, e), t);
|
|
762
767
|
this.state.updateFromResourceData(s, !0);
|
|
763
768
|
}
|
|
764
769
|
async mainLoop() {
|
|
@@ -768,19 +773,19 @@ class K {
|
|
|
768
773
|
let s;
|
|
769
774
|
this.scheduledOnNextState.length > 0 && (s = this.scheduledOnNextState, this.scheduledOnNextState = []);
|
|
770
775
|
try {
|
|
771
|
-
if (this.logStat === "per-request" && (e = F()), await this.refresh(e), e && this.logger && this.logger.info(`Tree stat (success): ${JSON.stringify(e)}`), s !== void 0) for (const
|
|
772
|
-
} catch (
|
|
773
|
-
if (e && this.logger && this.logger.info(`Tree stat (error): ${JSON.stringify(e)}`), s !== void 0) for (const a of s) a.reject(
|
|
774
|
-
if (
|
|
775
|
-
(t = this.logger) == null || t.error(
|
|
776
|
+
if (this.logStat === "per-request" && (e = F()), await this.refresh(e), e && this.logger && this.logger.info(`Tree stat (success): ${JSON.stringify(e)}`), s !== void 0) for (const o of s) o.resolve();
|
|
777
|
+
} catch (o) {
|
|
778
|
+
if (e && this.logger && this.logger.info(`Tree stat (error): ${JSON.stringify(e)}`), s !== void 0) for (const a of s) a.reject(o);
|
|
779
|
+
if (o instanceof S) {
|
|
780
|
+
(t = this.logger) == null || t.error(o), this.state.invalidateTree("stat update error"), this.state = new O(this.root, this.finalPredicate);
|
|
776
781
|
continue;
|
|
777
|
-
} else (r = this.logger) == null || r.warn(
|
|
782
|
+
} else (r = this.logger) == null || r.warn(o);
|
|
778
783
|
}
|
|
779
784
|
if (!this.keepRunning || this.terminated) break;
|
|
780
785
|
try {
|
|
781
786
|
await j.setTimeout(this.pollingInterval, this.abortController.signal);
|
|
782
|
-
} catch (
|
|
783
|
-
if (!J(
|
|
787
|
+
} catch (o) {
|
|
788
|
+
if (!J(o)) throw new Error("Unexpected error", { cause: o });
|
|
784
789
|
break;
|
|
785
790
|
}
|
|
786
791
|
}
|
|
@@ -805,10 +810,10 @@ class K {
|
|
|
805
810
|
this.currentLoop !== void 0 && await this.currentLoop;
|
|
806
811
|
}
|
|
807
812
|
static async init(e, t, r, s) {
|
|
808
|
-
const
|
|
813
|
+
const o = new K(e, t, r, s), a = r.logStat ? F() : void 0;
|
|
809
814
|
let i = !1;
|
|
810
815
|
try {
|
|
811
|
-
await
|
|
816
|
+
await o.refresh(a, {
|
|
812
817
|
timeout: r.initialTreeLoadingTimeout
|
|
813
818
|
}), i = !0;
|
|
814
819
|
} finally {
|
|
@@ -816,10 +821,10 @@ class K {
|
|
|
816
821
|
`Tree stat (initial load, ${i ? "success" : "failure"}): ${JSON.stringify(a)}`
|
|
817
822
|
);
|
|
818
823
|
}
|
|
819
|
-
return
|
|
824
|
+
return o;
|
|
820
825
|
}
|
|
821
826
|
}
|
|
822
|
-
function
|
|
827
|
+
function ve(n) {
|
|
823
828
|
var t;
|
|
824
829
|
const e = {
|
|
825
830
|
total: {
|
|
@@ -832,7 +837,7 @@ function pe(o) {
|
|
|
832
837
|
},
|
|
833
838
|
byResourceType: {}
|
|
834
839
|
};
|
|
835
|
-
for (const r of
|
|
840
|
+
for (const r of n) {
|
|
836
841
|
const s = `${r.type.name}/${r.type.version}`;
|
|
837
842
|
e.byResourceType[s] || (e.byResourceType[s] = {
|
|
838
843
|
count: 0,
|
|
@@ -842,23 +847,24 @@ function pe(o) {
|
|
|
842
847
|
kvCount: 0,
|
|
843
848
|
kvBytes: 0
|
|
844
849
|
});
|
|
845
|
-
const
|
|
846
|
-
|
|
850
|
+
const o = e.byResourceType[s];
|
|
851
|
+
o.count++, e.total.count++;
|
|
847
852
|
for (const a of r.fields)
|
|
848
|
-
|
|
853
|
+
o.fieldNameBytes += a.name.length, o.fieldsCount++, e.total.fieldNameBytes += a.name.length, e.total.fieldsCount++;
|
|
849
854
|
if (r.data) {
|
|
850
855
|
const a = ((t = r.data) == null ? void 0 : t.length) ?? 0;
|
|
851
|
-
|
|
856
|
+
o.dataBytes += a, e.total.dataBytes += a;
|
|
852
857
|
}
|
|
853
|
-
|
|
858
|
+
o.kvCount += r.kv.length, e.total.kvCount += r.kv.length;
|
|
854
859
|
for (const a of r.kv) {
|
|
855
860
|
const i = a.key.length + a.value.length;
|
|
856
|
-
|
|
861
|
+
o.kvBytes += i, e.total.kvBytes += i;
|
|
857
862
|
}
|
|
858
863
|
}
|
|
859
864
|
return e;
|
|
860
865
|
}
|
|
861
866
|
export {
|
|
867
|
+
ne as PlError,
|
|
862
868
|
C as PlTreeEntry,
|
|
863
869
|
E as PlTreeEntryAccessor,
|
|
864
870
|
Y as PlTreeNodeAccessor,
|
|
@@ -867,19 +873,19 @@ export {
|
|
|
867
873
|
K as SynchronizedTreeState,
|
|
868
874
|
S as TreeStateUpdateError,
|
|
869
875
|
Q as constructTreeLoadingRequest,
|
|
870
|
-
|
|
876
|
+
he as formatTreeLoadingStat,
|
|
871
877
|
F as initialTreeLoadingStat,
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
878
|
+
oe as isPlTreeEntry,
|
|
879
|
+
ue as isPlTreeEntryAccessor,
|
|
880
|
+
de as isPlTreeNodeAccessor,
|
|
875
881
|
X as loadTreeState,
|
|
876
|
-
|
|
882
|
+
fe as makeResourceSnapshot,
|
|
877
883
|
P as mapValueAndError,
|
|
878
884
|
ae as mapValueAndErrorIfDefined,
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
885
|
+
le as rsSchema,
|
|
886
|
+
ve as treeDumpStats,
|
|
887
|
+
ce as treeEntryToResourceInfo,
|
|
888
|
+
ge as treeEntryToResourceWithData,
|
|
889
|
+
pe as treeEntryToResourceWithMetadata
|
|
884
890
|
};
|
|
885
891
|
//# sourceMappingURL=index.mjs.map
|