@milaboratories/pl-tree 1.4.32 → 1.4.34
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 +0 -4
- package/dist/accessors.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +183 -182
- package/dist/index.mjs.map +1 -1
- package/dist/synchronized_tree.d.ts +2 -0
- package/dist/synchronized_tree.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/accessors.ts +13 -14
- package/src/synchronized_tree.ts +10 -4
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var d = (
|
|
4
|
-
import { resourceIdToString as
|
|
1
|
+
var M = Object.defineProperty;
|
|
2
|
+
var U = (n, e, t) => e in n ? M(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var d = (n, e, t) => U(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { resourceIdToString as S, resourceTypesEqual as A, resourceTypeToString as J, isNotNullResourceId as g, NullResourceId as D, isNullResourceId as V, stringifyWithResourceId as T, isTimeoutOrCancelError as q } from "@milaboratories/pl-client";
|
|
5
5
|
import { ChangeSource as m, PollingComputableHooks as B } from "@milaboratories/computable";
|
|
6
|
-
import {
|
|
6
|
+
import { parsePlError as P } from "@milaboratories/pl-errors";
|
|
7
|
+
import { notEmpty as p, msToHumanReadable as z } from "@milaboratories/ts-helpers";
|
|
7
8
|
import H from "denque";
|
|
8
9
|
import * as j from "node:timers/promises";
|
|
9
|
-
function
|
|
10
|
-
if (
|
|
11
|
-
return b(
|
|
10
|
+
function ae(n, e) {
|
|
11
|
+
if (n !== void 0)
|
|
12
|
+
return b(n, e);
|
|
12
13
|
}
|
|
13
|
-
function b(
|
|
14
|
+
function b(n, e) {
|
|
14
15
|
const t = {};
|
|
15
|
-
return
|
|
16
|
+
return n.value !== void 0 && (t.value = e(n.value)), n.error !== void 0 && (t.error = e(n.error)), t;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
super(e);
|
|
20
|
-
}
|
|
18
|
+
function ne(n) {
|
|
19
|
+
return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeEntry";
|
|
21
20
|
}
|
|
22
|
-
function
|
|
23
|
-
return typeof
|
|
21
|
+
function oe(n) {
|
|
22
|
+
return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeEntryAccessor";
|
|
24
23
|
}
|
|
25
|
-
function
|
|
26
|
-
return typeof
|
|
27
|
-
}
|
|
28
|
-
function oe(a) {
|
|
29
|
-
return typeof a == "object" && a !== null && a.__pl_tree_type_marker__ === "PlTreeNodeAccessor";
|
|
24
|
+
function ue(n) {
|
|
25
|
+
return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeNodeAccessor";
|
|
30
26
|
}
|
|
31
27
|
class R {
|
|
32
28
|
constructor(e, t) {
|
|
@@ -43,26 +39,24 @@ class R {
|
|
|
43
39
|
return this.toString();
|
|
44
40
|
}
|
|
45
41
|
toString() {
|
|
46
|
-
return `[ENTRY:${
|
|
42
|
+
return `[ENTRY:${S(this.rid)}]`;
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
|
-
function
|
|
45
|
+
function N(n, e, t, i, s) {
|
|
50
46
|
const o = new Y(
|
|
51
|
-
|
|
47
|
+
n,
|
|
52
48
|
e,
|
|
53
49
|
e.get(t.ctx.watcher, i),
|
|
54
50
|
t
|
|
55
51
|
);
|
|
56
52
|
if (!s.ignoreError) {
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
throw
|
|
60
|
-
`error encountered on resource ${C(o.id)} (${A(o.resourceType)}): ${n.getDataAsString()}`
|
|
61
|
-
);
|
|
53
|
+
const a = o.getError();
|
|
54
|
+
if (a !== void 0)
|
|
55
|
+
throw P(p(a.getDataAsString()), o.id, o.resourceType);
|
|
62
56
|
}
|
|
63
|
-
if (s.assertResourceType !== void 0 && (Array.isArray(s.assertResourceType) ? s.assertResourceType.findIndex((
|
|
57
|
+
if (s.assertResourceType !== void 0 && (Array.isArray(s.assertResourceType) ? s.assertResourceType.findIndex((a) => A(a, o.resourceType)) === -1 : !A(s.assertResourceType, o.resourceType)))
|
|
64
58
|
throw new Error(
|
|
65
|
-
`wrong resource type ${
|
|
59
|
+
`wrong resource type ${J(o.resourceType)} but expected ${s.assertResourceType}`
|
|
66
60
|
);
|
|
67
61
|
return o;
|
|
68
62
|
}
|
|
@@ -72,11 +66,11 @@ class E {
|
|
|
72
66
|
this.accessorData = e, this.tree = t, this.rid = i, this.instanceData = s;
|
|
73
67
|
}
|
|
74
68
|
node(e = {}) {
|
|
75
|
-
return this.instanceData.guard(), this.accessorData.hooks !== void 0 && this.instanceData.ctx.attacheHooks(this.accessorData.hooks),
|
|
69
|
+
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);
|
|
76
70
|
}
|
|
77
71
|
}
|
|
78
|
-
function
|
|
79
|
-
return
|
|
72
|
+
function de(n, e) {
|
|
73
|
+
return n instanceof R ? e.accessor(n).node().resourceInfo : n;
|
|
80
74
|
}
|
|
81
75
|
class Y {
|
|
82
76
|
constructor(e, t, i, s) {
|
|
@@ -99,7 +93,7 @@ class Y {
|
|
|
99
93
|
return { id: this.id, type: this.resourceType };
|
|
100
94
|
}
|
|
101
95
|
getResourceFromTree(e, t) {
|
|
102
|
-
return
|
|
96
|
+
return N(this.accessorData, this.tree, this.instanceData, e, t);
|
|
103
97
|
}
|
|
104
98
|
traverse(...e) {
|
|
105
99
|
return this.traverseWithCommon({}, ...e);
|
|
@@ -110,7 +104,7 @@ class Y {
|
|
|
110
104
|
traverseWithCommon(e, ...t) {
|
|
111
105
|
const i = this.traverseOrErrorWithCommon(e, ...t);
|
|
112
106
|
if (i !== void 0) {
|
|
113
|
-
if (!i.ok) throw
|
|
107
|
+
if (!i.ok) throw i.error;
|
|
114
108
|
return i.value;
|
|
115
109
|
}
|
|
116
110
|
}
|
|
@@ -120,24 +114,30 @@ class Y {
|
|
|
120
114
|
const o = typeof s == "string" ? {
|
|
121
115
|
...e,
|
|
122
116
|
field: s
|
|
123
|
-
} : { ...e, ...s },
|
|
124
|
-
if (
|
|
117
|
+
} : { ...e, ...s }, a = i.getField(s);
|
|
118
|
+
if (a === void 0 || o.pureFieldErrorToUndefined && a.value === void 0 && a.error !== void 0)
|
|
125
119
|
return;
|
|
126
|
-
if ((!o.ignoreError ||
|
|
120
|
+
if ((!o.ignoreError || a.value === void 0) && a.error !== void 0)
|
|
127
121
|
return {
|
|
128
122
|
ok: !1,
|
|
129
|
-
|
|
123
|
+
// FIXME: in next tickets we'll allow Errors to be thrown.
|
|
124
|
+
error: P(
|
|
125
|
+
p(a.error.getDataAsString()),
|
|
126
|
+
i.id,
|
|
127
|
+
i.resourceType,
|
|
128
|
+
o.field
|
|
129
|
+
)
|
|
130
130
|
};
|
|
131
|
-
if (
|
|
131
|
+
if (a.value === void 0) {
|
|
132
132
|
if (o.errorIfFieldNotSet)
|
|
133
133
|
return {
|
|
134
134
|
ok: !1,
|
|
135
|
-
error: `field have no assigned value ${o.field} of ${
|
|
135
|
+
error: `field have no assigned value ${o.field} of ${S(i.id)}`
|
|
136
136
|
};
|
|
137
137
|
this.onUnstableLambda("unpopulated_field:" + o.field);
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
|
-
i =
|
|
140
|
+
i = a.value;
|
|
141
141
|
}
|
|
142
142
|
return { ok: !0, value: i };
|
|
143
143
|
}
|
|
@@ -223,26 +223,26 @@ class Y {
|
|
|
223
223
|
return new R(this.accessorData, this.resource.id);
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
-
class
|
|
226
|
+
class C extends Error {
|
|
227
227
|
constructor(e) {
|
|
228
228
|
super(e);
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
|
-
class
|
|
232
|
-
constructor(e, t, i, s, o,
|
|
231
|
+
class $ {
|
|
232
|
+
constructor(e, t, i, s, o, a, r) {
|
|
233
233
|
d(this, "change", new m());
|
|
234
|
-
this.name = e, this.type = t, this.value = i, this.error = s, this.status = o, this.valueIsFinal =
|
|
234
|
+
this.name = e, this.type = t, this.value = i, this.error = s, this.status = o, this.valueIsFinal = a, this.resourceVersion = r;
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
const
|
|
237
|
+
const L = 0, x = new TextDecoder();
|
|
238
238
|
class G {
|
|
239
239
|
constructor(e, t) {
|
|
240
240
|
/** Tracks number of other resources referencing this resource. Used to perform garbage collection in tree patching procedure */
|
|
241
241
|
d(this, "refCount", 0);
|
|
242
242
|
/** Increments each time resource is checked for difference with new state */
|
|
243
|
-
d(this, "version",
|
|
243
|
+
d(this, "version", L);
|
|
244
244
|
/** Set to resource version when resource state, or it's fields have changed */
|
|
245
|
-
d(this, "dataVersion",
|
|
245
|
+
d(this, "dataVersion", L);
|
|
246
246
|
d(this, "fieldsMap", /* @__PURE__ */ new Map());
|
|
247
247
|
d(this, "kv", /* @__PURE__ */ new Map());
|
|
248
248
|
d(this, "resourceRemoved", new m());
|
|
@@ -289,14 +289,14 @@ class G {
|
|
|
289
289
|
}
|
|
290
290
|
getField(e, t, i = () => {
|
|
291
291
|
}) {
|
|
292
|
-
var
|
|
292
|
+
var a, r, f;
|
|
293
293
|
const s = typeof t == "string" ? { field: t } : t, o = this.fieldsMap.get(s.field);
|
|
294
294
|
if (o === void 0) {
|
|
295
295
|
if (s.errorIfFieldNotFound || s.errorIfFieldNotSet)
|
|
296
296
|
throw new Error(
|
|
297
|
-
`Field "${s.field}" not found in resource ${
|
|
297
|
+
`Field "${s.field}" not found in resource ${S(this.id)}`
|
|
298
298
|
);
|
|
299
|
-
if (!this.inputsLocked) (
|
|
299
|
+
if (!this.inputsLocked) (a = this.inputAndServiceFieldListChanged) == null || a.attachWatcher(e);
|
|
300
300
|
else if (s.assertFieldType === "Service" || s.assertFieldType === "Input") {
|
|
301
301
|
if (s.allowPermanentAbsence)
|
|
302
302
|
return;
|
|
@@ -340,7 +340,7 @@ class G {
|
|
|
340
340
|
}
|
|
341
341
|
getError(e) {
|
|
342
342
|
var t;
|
|
343
|
-
if (
|
|
343
|
+
if (V(this.error)) {
|
|
344
344
|
(t = this.resourceStateChange) == null || t.attachWatcher(e);
|
|
345
345
|
return;
|
|
346
346
|
} else
|
|
@@ -374,11 +374,11 @@ class G {
|
|
|
374
374
|
getKeyValueString(e, t) {
|
|
375
375
|
const i = this.getKeyValue(e, t);
|
|
376
376
|
if (i !== void 0)
|
|
377
|
-
return
|
|
377
|
+
return x.decode(i);
|
|
378
378
|
}
|
|
379
379
|
getDataAsString() {
|
|
380
380
|
if (this.data !== void 0)
|
|
381
|
-
return this.dataAsString === void 0 && (this.dataAsString =
|
|
381
|
+
return this.dataAsString === void 0 && (this.dataAsString = x.decode(this.data)), this.dataAsString;
|
|
382
382
|
}
|
|
383
383
|
getDataAsJson() {
|
|
384
384
|
if (this.data !== void 0)
|
|
@@ -386,7 +386,7 @@ class G {
|
|
|
386
386
|
}
|
|
387
387
|
verifyReadyState() {
|
|
388
388
|
if (this.resourceReady && !this.inputsLocked)
|
|
389
|
-
throw new Error(`ready without input or output lock: ${
|
|
389
|
+
throw new Error(`ready without input or output lock: ${T(this.state)}`);
|
|
390
390
|
}
|
|
391
391
|
get state() {
|
|
392
392
|
return {
|
|
@@ -404,15 +404,15 @@ class G {
|
|
|
404
404
|
}
|
|
405
405
|
/** Called when {@link FinalResourceDataPredicate} returns true for the state. */
|
|
406
406
|
markFinal() {
|
|
407
|
-
this._finalState || (this._finalState = !0,
|
|
407
|
+
this._finalState || (this._finalState = !0, p(this.finalChanged).markChanged(), this.finalChanged = void 0, this.resourceStateChange = void 0, this.dynamicFieldListChanged = void 0, this.inputAndServiceFieldListChanged = void 0, this.outputFieldListChanged = void 0, this.lockedChange = void 0);
|
|
408
408
|
}
|
|
409
409
|
/** Used for invalidation */
|
|
410
410
|
markAllChanged() {
|
|
411
|
-
var e, t, i, s, o,
|
|
412
|
-
this.fieldsMap.forEach((f) => f.change.markChanged()), (e = this.finalChanged) == null || e.markChanged(), (t = this.resourceStateChange) == null || t.markChanged(), (i = this.lockedChange) == null || i.markChanged(), (s = this.inputAndServiceFieldListChanged) == null || s.markChanged(), (o = this.outputFieldListChanged) == null || o.markChanged(), (
|
|
411
|
+
var e, t, i, s, o, a, r;
|
|
412
|
+
this.fieldsMap.forEach((f) => f.change.markChanged()), (e = this.finalChanged) == null || e.markChanged(), (t = this.resourceStateChange) == null || t.markChanged(), (i = this.lockedChange) == null || i.markChanged(), (s = this.inputAndServiceFieldListChanged) == null || s.markChanged(), (o = this.outputFieldListChanged) == null || o.markChanged(), (a = this.dynamicFieldListChanged) == null || a.markChanged(), (r = this.kvChanged) == null || r.markChanged(), this.resourceRemoved.markChanged();
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
|
-
class
|
|
415
|
+
class O {
|
|
416
416
|
constructor(e, t) {
|
|
417
417
|
/** resource heap */
|
|
418
418
|
d(this, "resources", /* @__PURE__ */ new Map());
|
|
@@ -433,33 +433,33 @@ class V {
|
|
|
433
433
|
this.checkValid();
|
|
434
434
|
const i = this.resources.get(t);
|
|
435
435
|
if (i === void 0)
|
|
436
|
-
throw this.resourcesAdded.attachWatcher(e), new Error(`resource ${
|
|
436
|
+
throw this.resourcesAdded.attachWatcher(e), new Error(`resource ${S(t)} not found in the tree`);
|
|
437
437
|
return i.resourceRemoved.attachWatcher(e), i;
|
|
438
438
|
}
|
|
439
439
|
updateFromResourceData(e, t = !1) {
|
|
440
440
|
this.checkValid();
|
|
441
441
|
const i = [], s = [];
|
|
442
|
-
for (const
|
|
443
|
-
let r = this.resources.get(
|
|
442
|
+
for (const a of e) {
|
|
443
|
+
let r = this.resources.get(a.id);
|
|
444
444
|
const f = r == null ? void 0 : r.state, l = (h) => {
|
|
445
|
-
const { fields: k, ...u } =
|
|
446
|
-
throw this.invalidateTree(), new
|
|
447
|
-
`Unexpected resource state transition (${h}): ${
|
|
445
|
+
const { fields: k, ...u } = a;
|
|
446
|
+
throw this.invalidateTree(), new C(
|
|
447
|
+
`Unexpected resource state transition (${h}): ${T(
|
|
448
448
|
u
|
|
449
|
-
)} -> ${
|
|
449
|
+
)} -> ${T(f)}`
|
|
450
450
|
);
|
|
451
451
|
};
|
|
452
452
|
if (r !== void 0) {
|
|
453
453
|
r.finalState && l("resource state can be updated after it is marked as final");
|
|
454
454
|
let h = !1;
|
|
455
|
-
r.version += 1, r.originalResourceId !==
|
|
456
|
-
for (const u of
|
|
455
|
+
r.version += 1, r.originalResourceId !== a.originalResourceId && (r.originalResourceId !== D && l("originalResourceId can't change after it is set"), r.originalResourceId = a.originalResourceId, p(r.resourceStateChange).markChanged(), h = !0), r.error !== a.error && (g(r.error) && l("resource can't change attached error after it is set"), r.error = a.error, i.push(r.error), p(r.resourceStateChange).markChanged(), h = !0);
|
|
456
|
+
for (const u of a.fields) {
|
|
457
457
|
let c = r.fieldsMap.get(u.name);
|
|
458
|
-
c ? (c.type !== u.type && (c.type !== "Dynamic" && l(`field changed type ${c.type} -> ${u.type}`),
|
|
458
|
+
c ? (c.type !== u.type && (c.type !== "Dynamic" && l(`field changed type ${c.type} -> ${u.type}`), p(r.dynamicFieldListChanged).markChanged(), (c.type === "Input" || c.type === "Service") && (r.inputsLocked && l(
|
|
459
459
|
`adding input field "${u.name}", while corresponding list is locked`
|
|
460
|
-
),
|
|
460
|
+
), p(r.inputAndServiceFieldListChanged).markChanged()), c.type === "Output" && (r.outputsLocked && l(
|
|
461
461
|
`adding output field "${u.name}", while corresponding list is locked`
|
|
462
|
-
),
|
|
462
|
+
), p(r.outputFieldListChanged).markChanged()), c.type = u.type, c.change.markChanged(), h = !0), c.value !== u.value && (g(c.value) && s.push(c.value), c.value = u.value, g(u.value) && i.push(u.value), c.change.markChanged(), h = !0), c.error !== u.error && (g(c.error) && s.push(c.error), c.error = u.error, g(u.error) && i.push(u.error), c.change.markChanged(), h = !0), c.status !== u.status && (c.status = u.status, c.change.markChanged(), h = !0), c.valueIsFinal !== u.valueIsFinal && (c.valueIsFinal = u.valueIsFinal, c.change.markChanged(), h = !0), c.resourceVersion = r.version) : (c = new $(
|
|
463
463
|
u.name,
|
|
464
464
|
u.type,
|
|
465
465
|
u.value,
|
|
@@ -469,71 +469,71 @@ class V {
|
|
|
469
469
|
r.version
|
|
470
470
|
), g(u.value) && i.push(u.value), g(u.error) && i.push(u.error), u.type === "Input" || u.type === "Service" ? (r.inputsLocked && l(
|
|
471
471
|
`adding ${u.type} (${u.name}) field while inputs locked`
|
|
472
|
-
),
|
|
472
|
+
), p(r.inputAndServiceFieldListChanged).markChanged()) : u.type === "Output" ? (r.outputsLocked && l(
|
|
473
473
|
`adding ${u.type} (${u.name}) field while outputs locked`
|
|
474
|
-
),
|
|
474
|
+
), p(r.outputFieldListChanged).markChanged()) : p(r.dynamicFieldListChanged).markChanged(), r.fieldsMap.set(u.name, c), h = !0);
|
|
475
475
|
}
|
|
476
|
-
if (r.fieldsMap.forEach((u, c,
|
|
477
|
-
u.resourceVersion !== r.version && ((u.type === "Input" || u.type === "Service" || u.type === "Output") && l(`removal of ${u.type} field ${c}`), u.change.markChanged(),
|
|
478
|
-
}), r.inputsLocked !==
|
|
476
|
+
if (r.fieldsMap.forEach((u, c, v) => {
|
|
477
|
+
u.resourceVersion !== r.version && ((u.type === "Input" || u.type === "Service" || u.type === "Output") && l(`removal of ${u.type} field ${c}`), u.change.markChanged(), v.delete(c), g(u.value) && s.push(u.value), g(u.error) && s.push(u.error), p(r.dynamicFieldListChanged).markChanged());
|
|
478
|
+
}), r.inputsLocked !== a.inputsLocked && (r.inputsLocked && l("inputs unlocking is not permitted"), r.inputsLocked = a.inputsLocked, p(r.lockedChange).markChanged(), h = !0), r.outputsLocked !== a.outputsLocked && (r.outputsLocked && l("outputs unlocking is not permitted"), r.outputsLocked = a.outputsLocked, p(r.lockedChange).markChanged(), h = !0), r.resourceReady !== a.resourceReady) {
|
|
479
479
|
const u = r.resourceReady;
|
|
480
|
-
r.resourceReady =
|
|
480
|
+
r.resourceReady = a.resourceReady, r.verifyReadyState(), r.isReadyOrError || l(
|
|
481
481
|
`resource can't lose it's ready or error state (ready state before ${u})`
|
|
482
|
-
),
|
|
482
|
+
), p(r.resourceStateChange).markChanged(), h = !0;
|
|
483
483
|
}
|
|
484
484
|
let k = !1;
|
|
485
|
-
for (const u of
|
|
485
|
+
for (const u of a.kv) {
|
|
486
486
|
const c = r.kv.get(u.key);
|
|
487
487
|
(c === void 0 || Buffer.compare(c, u.value) !== 0) && (r.kv.set(u.key, u.value), k = !0);
|
|
488
488
|
}
|
|
489
|
-
if (r.kv.size >
|
|
490
|
-
const u = new Set(
|
|
491
|
-
r.kv.forEach((c,
|
|
492
|
-
u.has(
|
|
489
|
+
if (r.kv.size > a.kv.length) {
|
|
490
|
+
const u = new Set(a.kv.map((c) => c.key));
|
|
491
|
+
r.kv.forEach((c, v, y) => {
|
|
492
|
+
u.has(v) || y.delete(v);
|
|
493
493
|
}), k = !0;
|
|
494
494
|
}
|
|
495
|
-
k &&
|
|
495
|
+
k && p(r.kvChanged).markChanged(), h && (r.dataVersion = r.version, this.isFinalPredicate(r) && r.markFinal());
|
|
496
496
|
} else {
|
|
497
|
-
r = new G(
|
|
498
|
-
for (const h of
|
|
499
|
-
const k = new
|
|
497
|
+
r = new G(a), r.verifyReadyState(), g(r.error) && i.push(r.error);
|
|
498
|
+
for (const h of a.fields) {
|
|
499
|
+
const k = new $(
|
|
500
500
|
h.name,
|
|
501
501
|
h.type,
|
|
502
502
|
h.value,
|
|
503
503
|
h.error,
|
|
504
504
|
h.status,
|
|
505
505
|
h.valueIsFinal,
|
|
506
|
-
|
|
506
|
+
L
|
|
507
507
|
);
|
|
508
508
|
g(h.value) && i.push(h.value), g(h.error) && i.push(h.error), r.fieldsMap.set(h.name, k);
|
|
509
509
|
}
|
|
510
|
-
for (const h of
|
|
510
|
+
for (const h of a.kv) r.kv.set(h.key, h.value);
|
|
511
511
|
this.isFinalPredicate(r) && r.markFinal(), this.resources.set(r.id, r), this.resourcesAdded.markChanged();
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
|
-
for (const
|
|
515
|
-
const r = this.resources.get(
|
|
514
|
+
for (const a of i) {
|
|
515
|
+
const r = this.resources.get(a);
|
|
516
516
|
if (!r)
|
|
517
|
-
throw this.invalidateTree(), new
|
|
517
|
+
throw this.invalidateTree(), new C(`orphan resource ${a}`);
|
|
518
518
|
r.refCount++;
|
|
519
519
|
}
|
|
520
520
|
let o = s;
|
|
521
521
|
for (; o.length > 0; ) {
|
|
522
|
-
const
|
|
522
|
+
const a = [];
|
|
523
523
|
for (const r of o) {
|
|
524
524
|
const f = this.resources.get(r);
|
|
525
525
|
if (!f)
|
|
526
|
-
throw this.invalidateTree(), new
|
|
526
|
+
throw this.invalidateTree(), new C(`orphan resource ${r}`);
|
|
527
527
|
f.refCount--, f.refCount === 0 && f.id !== this.root && (f.fieldsMap.forEach((l) => {
|
|
528
|
-
g(l.value) &&
|
|
529
|
-
}), g(f.error) &&
|
|
528
|
+
g(l.value) && a.push(l.value), g(l.error) && a.push(l.error), l.change.markChanged();
|
|
529
|
+
}), g(f.error) && a.push(f.error), f.resourceRemoved.markChanged(), this.resources.delete(r));
|
|
530
530
|
}
|
|
531
|
-
o =
|
|
531
|
+
o = a;
|
|
532
532
|
}
|
|
533
533
|
if (!t) {
|
|
534
|
-
for (const
|
|
535
|
-
if (!this.resources.has(
|
|
536
|
-
throw this.invalidateTree(), new
|
|
534
|
+
for (const a of e)
|
|
535
|
+
if (!this.resources.has(a.id))
|
|
536
|
+
throw this.invalidateTree(), new C(`orphan input resource ${a.id}`);
|
|
537
537
|
}
|
|
538
538
|
}
|
|
539
539
|
/** @deprecated use "entry" instead */
|
|
@@ -549,11 +549,11 @@ class V {
|
|
|
549
549
|
});
|
|
550
550
|
}
|
|
551
551
|
}
|
|
552
|
-
function Q(
|
|
552
|
+
function Q(n, e) {
|
|
553
553
|
const t = [], i = /* @__PURE__ */ new Set();
|
|
554
|
-
return
|
|
554
|
+
return n.forEachResource((s) => {
|
|
555
555
|
s.finalState ? i.add(s.id) : t.push(s.id);
|
|
556
|
-
}), t.length === 0 && i.size === 0 && t.push(
|
|
556
|
+
}), t.length === 0 && i.size === 0 && t.push(n.root), { seedResources: t, finalResources: i, pruningFunction: e };
|
|
557
557
|
}
|
|
558
558
|
function F() {
|
|
559
559
|
return {
|
|
@@ -569,81 +569,81 @@ function F() {
|
|
|
569
569
|
millisSpent: 0
|
|
570
570
|
};
|
|
571
571
|
}
|
|
572
|
-
function
|
|
573
|
-
let e = `Requests: ${
|
|
572
|
+
function ce(n) {
|
|
573
|
+
let e = `Requests: ${n.requests}
|
|
574
574
|
`;
|
|
575
|
-
return e += `Total time: ${z(
|
|
576
|
-
`, e += `Round-trips: ${
|
|
577
|
-
`, e += `Resources: ${
|
|
578
|
-
`, e += `Fields: ${
|
|
579
|
-
`, e += `KV: ${
|
|
580
|
-
`, e += `Data Bytes: ${
|
|
581
|
-
`, e += `KV Bytes: ${
|
|
582
|
-
`, e += `Pruned fields: ${
|
|
583
|
-
`, e += `Final resources skipped: ${
|
|
575
|
+
return e += `Total time: ${z(n.millisSpent)}
|
|
576
|
+
`, e += `Round-trips: ${n.roundTrips}
|
|
577
|
+
`, e += `Resources: ${n.retrievedResources}
|
|
578
|
+
`, e += `Fields: ${n.retrievedFields}
|
|
579
|
+
`, e += `KV: ${n.retrievedKeyValues}
|
|
580
|
+
`, e += `Data Bytes: ${n.retrievedResourceDataBytes}
|
|
581
|
+
`, e += `KV Bytes: ${n.retrievedKeyValueBytes}
|
|
582
|
+
`, e += `Pruned fields: ${n.prunedFields}
|
|
583
|
+
`, e += `Final resources skipped: ${n.finalResourcesSkipped}`, e;
|
|
584
584
|
}
|
|
585
|
-
async function X(
|
|
585
|
+
async function X(n, e, t) {
|
|
586
586
|
var c;
|
|
587
587
|
const i = Date.now();
|
|
588
588
|
t && t.requests++;
|
|
589
|
-
const { seedResources: s, finalResources: o, pruningFunction:
|
|
589
|
+
const { seedResources: s, finalResources: o, pruningFunction: a } = e, r = new H();
|
|
590
590
|
let f = !0, l = 0;
|
|
591
|
-
const h = /* @__PURE__ */ new Set(), k = (
|
|
592
|
-
if (
|
|
593
|
-
if (o.has(
|
|
591
|
+
const h = /* @__PURE__ */ new Set(), k = (v) => {
|
|
592
|
+
if (V(v) || h.has(v)) return;
|
|
593
|
+
if (o.has(v)) {
|
|
594
594
|
t && t.finalResourcesSkipped++;
|
|
595
595
|
return;
|
|
596
596
|
}
|
|
597
|
-
h.add(
|
|
598
|
-
const
|
|
597
|
+
h.add(v);
|
|
598
|
+
const y = n.getResourceDataIfExists(v, !0), w = n.listKeyValuesIfResourceExists(v), W = f;
|
|
599
599
|
f && (f = !1), r.push(
|
|
600
600
|
(async () => {
|
|
601
|
-
const [I, _] = await Promise.all([
|
|
602
|
-
if (
|
|
601
|
+
const [I, _] = await Promise.all([y, w]);
|
|
602
|
+
if (W && (l++, f = !0), I !== void 0) {
|
|
603
603
|
if (_ === void 0) throw new Error("Inconsistent replies");
|
|
604
604
|
return { ...I, kv: _ };
|
|
605
605
|
}
|
|
606
606
|
})()
|
|
607
607
|
);
|
|
608
608
|
};
|
|
609
|
-
s.forEach((
|
|
609
|
+
s.forEach((v) => k(v));
|
|
610
610
|
const u = [];
|
|
611
611
|
for (; ; ) {
|
|
612
|
-
const
|
|
613
|
-
if (
|
|
612
|
+
const v = r.shift();
|
|
613
|
+
if (v === void 0)
|
|
614
614
|
break;
|
|
615
|
-
let
|
|
616
|
-
if (
|
|
617
|
-
if (
|
|
618
|
-
const w =
|
|
619
|
-
t && (t.prunedFields +=
|
|
615
|
+
let y = await v;
|
|
616
|
+
if (y !== void 0) {
|
|
617
|
+
if (a !== void 0) {
|
|
618
|
+
const w = a(y);
|
|
619
|
+
t && (t.prunedFields += y.fields.length - w.length), y = { ...y, fields: w };
|
|
620
620
|
}
|
|
621
|
-
k(
|
|
622
|
-
for (const w of
|
|
621
|
+
k(y.error);
|
|
622
|
+
for (const w of y.fields)
|
|
623
623
|
k(w.value), k(w.error);
|
|
624
624
|
if (t) {
|
|
625
|
-
t.retrievedResources++, t.retrievedFields +=
|
|
626
|
-
for (const w of
|
|
625
|
+
t.retrievedResources++, t.retrievedFields += y.fields.length, t.retrievedKeyValues += y.kv.length, t.retrievedResourceDataBytes += ((c = y.data) == null ? void 0 : c.length) ?? 0;
|
|
626
|
+
for (const w of y.kv) t.retrievedKeyValueBytes += w.value.length;
|
|
627
627
|
}
|
|
628
|
-
u.push(
|
|
628
|
+
u.push(y);
|
|
629
629
|
}
|
|
630
630
|
}
|
|
631
631
|
return t && (t.millisSpent += Date.now() - i, t.roundTrips += l), u;
|
|
632
632
|
}
|
|
633
|
-
function
|
|
634
|
-
return
|
|
633
|
+
function he(n) {
|
|
634
|
+
return n;
|
|
635
635
|
}
|
|
636
|
-
function
|
|
637
|
-
var
|
|
638
|
-
const i =
|
|
636
|
+
function le(n, e, t) {
|
|
637
|
+
var a;
|
|
638
|
+
const i = n instanceof R ? p(t).accessor(n).node() : n instanceof E ? n.node() : n, o = { ...i.resourceInfo };
|
|
639
639
|
if (e.data !== void 0 && (e.data === "raw" ? o.data = i.getData() : o.data = e.data.parse(i.getDataAsJson())), e.fields !== void 0) {
|
|
640
640
|
const r = {};
|
|
641
641
|
for (const [f, l] of Object.entries(e.fields))
|
|
642
|
-
r[f] = (
|
|
642
|
+
r[f] = (a = i.traverse({
|
|
643
643
|
field: f,
|
|
644
644
|
errorIfFieldNotSet: l,
|
|
645
645
|
stableIfNotFound: !l
|
|
646
|
-
})) == null ? void 0 :
|
|
646
|
+
})) == null ? void 0 : a.id;
|
|
647
647
|
o.fields = r;
|
|
648
648
|
}
|
|
649
649
|
if (e.kv !== void 0) {
|
|
@@ -658,13 +658,13 @@ function he(a, e, t) {
|
|
|
658
658
|
}
|
|
659
659
|
return o;
|
|
660
660
|
}
|
|
661
|
-
function
|
|
662
|
-
if (
|
|
663
|
-
const i = t.accessor(
|
|
661
|
+
function fe(n, e, t) {
|
|
662
|
+
if (n instanceof R) {
|
|
663
|
+
const i = t.accessor(n).node(), s = i.resourceInfo, o = e.map((a) => {
|
|
664
664
|
var r, f;
|
|
665
665
|
return [
|
|
666
|
-
|
|
667
|
-
(f = (r = i.getField(
|
|
666
|
+
a,
|
|
667
|
+
(f = (r = i.getField(a)) == null ? void 0 : r.value) == null ? void 0 : f.id
|
|
668
668
|
];
|
|
669
669
|
});
|
|
670
670
|
return {
|
|
@@ -673,17 +673,17 @@ function le(a, e, t) {
|
|
|
673
673
|
data: i.getData() ?? new Uint8Array()
|
|
674
674
|
};
|
|
675
675
|
}
|
|
676
|
-
return
|
|
676
|
+
return n;
|
|
677
677
|
}
|
|
678
|
-
function
|
|
679
|
-
if (!(
|
|
680
|
-
const i = t.accessor(
|
|
678
|
+
function ge(n, e, t) {
|
|
679
|
+
if (!(n instanceof R)) return n;
|
|
680
|
+
const i = t.accessor(n).node(), s = i.resourceInfo, o = e.map((a) => [a, i.getKeyValue(a)]);
|
|
681
681
|
return {
|
|
682
682
|
...s,
|
|
683
683
|
metadata: Object.fromEntries(o)
|
|
684
684
|
};
|
|
685
685
|
}
|
|
686
|
-
class
|
|
686
|
+
class K {
|
|
687
687
|
constructor(e, t, i, s) {
|
|
688
688
|
d(this, "finalPredicate");
|
|
689
689
|
d(this, "state");
|
|
@@ -700,8 +700,8 @@ class W {
|
|
|
700
700
|
/** If true this tree state is permanently terminaed. */
|
|
701
701
|
d(this, "terminated", !1);
|
|
702
702
|
this.pl = e, this.root = t, this.logger = s;
|
|
703
|
-
const { finalPredicateOverride: o, pruning:
|
|
704
|
-
this.pruning =
|
|
703
|
+
const { finalPredicateOverride: o, pruning: a, pollingInterval: r, stopPollingDelay: f, logStat: l } = i;
|
|
704
|
+
this.pruning = a, this.pollingInterval = r, this.finalPredicate = o ?? e.finalPredicate, this.logStat = l, this.state = new O(t, this.finalPredicate), this.hooks = new B(
|
|
705
705
|
() => this.startUpdating(),
|
|
706
706
|
() => this.stopUpdating(),
|
|
707
707
|
{ stopDebounce: f },
|
|
@@ -735,10 +735,10 @@ class W {
|
|
|
735
735
|
this.keepRunning = !1;
|
|
736
736
|
}
|
|
737
737
|
/** Executed from the main loop, and initialization procedure. */
|
|
738
|
-
async refresh(e) {
|
|
738
|
+
async refresh(e, t) {
|
|
739
739
|
if (this.terminated) throw new Error("tree synchronization is terminated");
|
|
740
|
-
const
|
|
741
|
-
this.state.updateFromResourceData(
|
|
740
|
+
const i = Q(this.state, this.pruning), s = await this.pl.withReadTx("ReadingTree", async (o) => await X(o, i, e), t);
|
|
741
|
+
this.state.updateFromResourceData(s, !0);
|
|
742
742
|
}
|
|
743
743
|
async mainLoop() {
|
|
744
744
|
var t, i;
|
|
@@ -749,9 +749,9 @@ class W {
|
|
|
749
749
|
try {
|
|
750
750
|
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();
|
|
751
751
|
} catch (o) {
|
|
752
|
-
if (e && this.logger && this.logger.info(`Tree stat (error): ${JSON.stringify(e)}`), s !== void 0) for (const
|
|
753
|
-
if (o instanceof
|
|
754
|
-
(t = this.logger) == null || t.error(o), this.state.invalidateTree("stat update error"), this.state = new
|
|
752
|
+
if (e && this.logger && this.logger.info(`Tree stat (error): ${JSON.stringify(e)}`), s !== void 0) for (const a of s) a.reject(o);
|
|
753
|
+
if (o instanceof C) {
|
|
754
|
+
(t = this.logger) == null || t.error(o), this.state.invalidateTree("stat update error"), this.state = new O(this.root, this.finalPredicate);
|
|
755
755
|
continue;
|
|
756
756
|
} else (i = this.logger) == null || i.warn(o);
|
|
757
757
|
}
|
|
@@ -777,40 +777,41 @@ class W {
|
|
|
777
777
|
this.currentLoop !== void 0 && await this.currentLoop;
|
|
778
778
|
}
|
|
779
779
|
static async init(e, t, i, s) {
|
|
780
|
-
const o = new
|
|
781
|
-
let
|
|
780
|
+
const o = new K(e, t, i, s);
|
|
781
|
+
let a = i.logStat ? F() : void 0, r = !1;
|
|
782
782
|
try {
|
|
783
|
-
await o.refresh(
|
|
783
|
+
await o.refresh(a, {
|
|
784
|
+
timeout: i.initialTreeLoadingTimeout
|
|
785
|
+
}), r = !0;
|
|
784
786
|
} finally {
|
|
785
|
-
|
|
786
|
-
`Tree stat (initial load, ${r ? "success" : "failure"}): ${JSON.stringify(
|
|
787
|
+
a && s && s.info(
|
|
788
|
+
`Tree stat (initial load, ${r ? "success" : "failure"}): ${JSON.stringify(a)}`
|
|
787
789
|
);
|
|
788
790
|
}
|
|
789
791
|
return o;
|
|
790
792
|
}
|
|
791
793
|
}
|
|
792
794
|
export {
|
|
793
|
-
N as PlError,
|
|
794
795
|
R as PlTreeEntry,
|
|
795
796
|
E as PlTreeEntryAccessor,
|
|
796
797
|
Y as PlTreeNodeAccessor,
|
|
797
798
|
G as PlTreeResource,
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
799
|
+
O as PlTreeState,
|
|
800
|
+
K as SynchronizedTreeState,
|
|
801
|
+
C as TreeStateUpdateError,
|
|
801
802
|
Q as constructTreeLoadingRequest,
|
|
802
|
-
|
|
803
|
+
ce as formatTreeLoadingStat,
|
|
803
804
|
F as initialTreeLoadingStat,
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
805
|
+
ne as isPlTreeEntry,
|
|
806
|
+
oe as isPlTreeEntryAccessor,
|
|
807
|
+
ue as isPlTreeNodeAccessor,
|
|
807
808
|
X as loadTreeState,
|
|
808
|
-
|
|
809
|
+
le as makeResourceSnapshot,
|
|
809
810
|
b as mapValueAndError,
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
811
|
+
ae as mapValueAndErrorIfDefined,
|
|
812
|
+
he as rsSchema,
|
|
813
|
+
de as treeEntryToResourceInfo,
|
|
814
|
+
fe as treeEntryToResourceWithData,
|
|
815
|
+
ge as treeEntryToResourceWithMetadata
|
|
815
816
|
};
|
|
816
817
|
//# sourceMappingURL=index.mjs.map
|