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