@milaboratories/pl-tree 1.4.31 → 1.4.33

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/index.mjs CHANGED
@@ -1,32 +1,28 @@
1
- var U = Object.defineProperty;
2
- var J = (a, e, t) => e in a ? U(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
- var d = (a, e, t) => J(a, typeof e != "symbol" ? e + "" : e, t);
4
- import { resourceIdToString as C, resourceTypeToString as A, resourceTypesEqual as $, isNotNullResourceId as g, NullResourceId as D, isNullResourceId as P, stringifyWithResourceId as L, isTimeoutOrCancelError as q } from "@milaboratories/pl-client";
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 { notEmpty as y, msToHumanReadable as z } from "@milaboratories/ts-helpers";
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 se(a, e) {
10
- if (a !== void 0)
11
- return b(a, e);
10
+ function ae(n, e) {
11
+ if (n !== void 0)
12
+ return b(n, e);
12
13
  }
13
- function b(a, e) {
14
+ function b(n, e) {
14
15
  const t = {};
15
- return a.value !== void 0 && (t.value = e(a.value)), a.error !== void 0 && (t.error = e(a.error)), t;
16
+ return n.value !== void 0 && (t.value = e(n.value)), n.error !== void 0 && (t.error = e(n.error)), t;
16
17
  }
17
- class N extends Error {
18
- constructor(e) {
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 ae(a) {
23
- return typeof a == "object" && a !== null && a.__pl_tree_type_marker__ === "PlTreeEntry";
21
+ function oe(n) {
22
+ return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeEntryAccessor";
24
23
  }
25
- function ne(a) {
26
- return typeof a == "object" && a !== null && a.__pl_tree_type_marker__ === "PlTreeEntryAccessor";
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:${C(this.rid)}]`;
42
+ return `[ENTRY:${S(this.rid)}]`;
47
43
  }
48
44
  }
49
- function K(a, e, t, i, s) {
45
+ function N(n, e, t, i, s) {
50
46
  const o = new Y(
51
- a,
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 n = o.getError();
58
- if (n !== void 0)
59
- throw new N(
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((n) => $(n, o.resourceType)) === -1 : !$(s.assertResourceType, o.resourceType)))
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 ${A(o.resourceType)} but expected ${s.assertResourceType}`
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), K(this.accessorData, this.tree, this.instanceData, this.rid, e);
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 ue(a, e) {
79
- return a instanceof R ? e.accessor(a).node().resourceInfo : a;
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 K(this.accessorData, this.tree, this.instanceData, e, t);
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 new N(i.error);
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 }, n = i.getField(s);
124
- if (n === void 0 || o.pureFieldErrorToUndefined && n.value === void 0 && n.error !== void 0)
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 || n.value === void 0) && n.error !== void 0)
120
+ if ((!o.ignoreError || a.value === void 0) && a.error !== void 0)
127
121
  return {
128
122
  ok: !1,
129
- error: `error in field ${o.field} of ${C(i.id)}: ${n.error.getDataAsString()}`
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 (n.value === void 0) {
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 ${C(i.id)}`
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 = n.value;
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 S extends Error {
226
+ class C extends Error {
227
227
  constructor(e) {
228
228
  super(e);
229
229
  }
230
230
  }
231
- class x {
232
- constructor(e, t, i, s, o, n, r) {
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 = n, this.resourceVersion = r;
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 T = 0, O = new TextDecoder();
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", T);
243
+ d(this, "version", L);
244
244
  /** Set to resource version when resource state, or it's fields have changed */
245
- d(this, "dataVersion", T);
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 n, r, f;
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 ${C(this.id)}`
297
+ `Field "${s.field}" not found in resource ${S(this.id)}`
298
298
  );
299
- if (!this.inputsLocked) (n = this.inputAndServiceFieldListChanged) == null || n.attachWatcher(e);
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 (P(this.error)) {
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 O.decode(i);
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 = O.decode(this.data)), 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: ${L(this.state)}`);
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, y(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);
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, n, 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(), (n = this.dynamicFieldListChanged) == null || n.markChanged(), (r = this.kvChanged) == null || r.markChanged(), this.resourceRemoved.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 V {
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 ${C(t)} not found in the tree`);
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 n of e) {
443
- let r = this.resources.get(n.id);
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 } = n;
446
- throw this.invalidateTree(), new S(
447
- `Unexpected resource state transition (${h}): ${L(
445
+ const { fields: k, ...u } = a;
446
+ throw this.invalidateTree(), new C(
447
+ `Unexpected resource state transition (${h}): ${T(
448
448
  u
449
- )} -> ${L(f)}`
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 !== n.originalResourceId && (r.originalResourceId !== D && l("originalResourceId can't change after it is set"), r.originalResourceId = n.originalResourceId, y(r.resourceStateChange).markChanged(), h = !0), r.error !== n.error && (g(r.error) && l("resource can't change attached error after it is set"), r.error = n.error, i.push(r.error), y(r.resourceStateChange).markChanged(), h = !0);
456
- for (const u of n.fields) {
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}`), y(r.dynamicFieldListChanged).markChanged(), (c.type === "Input" || c.type === "Service") && (r.inputsLocked && l(
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
- ), y(r.inputAndServiceFieldListChanged).markChanged()), c.type === "Output" && (r.outputsLocked && l(
460
+ ), p(r.inputAndServiceFieldListChanged).markChanged()), c.type === "Output" && (r.outputsLocked && l(
461
461
  `adding output field "${u.name}", while corresponding list is locked`
462
- ), y(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 x(
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
- ), y(r.inputAndServiceFieldListChanged).markChanged()) : u.type === "Output" ? (r.outputsLocked && l(
472
+ ), p(r.inputAndServiceFieldListChanged).markChanged()) : u.type === "Output" ? (r.outputsLocked && l(
473
473
  `adding ${u.type} (${u.name}) field while outputs locked`
474
- ), y(r.outputFieldListChanged).markChanged()) : y(r.dynamicFieldListChanged).markChanged(), r.fieldsMap.set(u.name, c), h = !0);
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, p) => {
477
- u.resourceVersion !== r.version && ((u.type === "Input" || u.type === "Service" || u.type === "Output") && l(`removal of ${u.type} field ${c}`), u.change.markChanged(), p.delete(c), g(u.value) && s.push(u.value), g(u.error) && s.push(u.error), y(r.dynamicFieldListChanged).markChanged());
478
- }), r.inputsLocked !== n.inputsLocked && (r.inputsLocked && l("inputs unlocking is not permitted"), r.inputsLocked = n.inputsLocked, y(r.lockedChange).markChanged(), h = !0), r.outputsLocked !== n.outputsLocked && (r.outputsLocked && l("outputs unlocking is not permitted"), r.outputsLocked = n.outputsLocked, y(r.lockedChange).markChanged(), h = !0), r.resourceReady !== n.resourceReady) {
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 = n.resourceReady, r.verifyReadyState(), r.isReadyOrError || l(
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
- ), y(r.resourceStateChange).markChanged(), h = !0;
482
+ ), p(r.resourceStateChange).markChanged(), h = !0;
483
483
  }
484
484
  let k = !1;
485
- for (const u of n.kv) {
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 > n.kv.length) {
490
- const u = new Set(n.kv.map((c) => c.key));
491
- r.kv.forEach((c, p, v) => {
492
- u.has(p) || v.delete(p);
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 && y(r.kvChanged).markChanged(), h && (r.dataVersion = r.version, this.isFinalPredicate(r) && r.markFinal());
495
+ k && p(r.kvChanged).markChanged(), h && (r.dataVersion = r.version, this.isFinalPredicate(r) && r.markFinal());
496
496
  } else {
497
- r = new G(n), r.verifyReadyState(), g(r.error) && i.push(r.error);
498
- for (const h of n.fields) {
499
- const k = new x(
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
- T
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 n.kv) r.kv.set(h.key, h.value);
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 n of i) {
515
- const r = this.resources.get(n);
514
+ for (const a of i) {
515
+ const r = this.resources.get(a);
516
516
  if (!r)
517
- throw this.invalidateTree(), new S(`orphan resource ${n}`);
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 n = [];
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 S(`orphan resource ${r}`);
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) && n.push(l.value), g(l.error) && n.push(l.error), l.change.markChanged();
529
- }), g(f.error) && n.push(f.error), f.resourceRemoved.markChanged(), this.resources.delete(r));
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 = n;
531
+ o = a;
532
532
  }
533
533
  if (!t) {
534
- for (const n of e)
535
- if (!this.resources.has(n.id))
536
- throw this.invalidateTree(), new S(`orphan input resource ${n.id}`);
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(a, e) {
552
+ function Q(n, e) {
553
553
  const t = [], i = /* @__PURE__ */ new Set();
554
- return a.forEachResource((s) => {
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(a.root), { seedResources: t, finalResources: i, pruningFunction: e };
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 de(a) {
573
- let e = `Requests: ${a.requests}
572
+ function ce(n) {
573
+ let e = `Requests: ${n.requests}
574
574
  `;
575
- return e += `Total time: ${z(a.millisSpent)}
576
- `, e += `Round-trips: ${a.roundTrips}
577
- `, e += `Resources: ${a.retrievedResources}
578
- `, e += `Fields: ${a.retrievedFields}
579
- `, e += `KV: ${a.retrievedKeyValues}
580
- `, e += `Data Bytes: ${a.retrievedResourceDataBytes}
581
- `, e += `KV Bytes: ${a.retrievedKeyValueBytes}
582
- `, e += `Pruned fields: ${a.prunedFields}
583
- `, e += `Final resources skipped: ${a.finalResourcesSkipped}`, e;
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(a, e, t) {
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: n } = e, r = new H();
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 = (p) => {
592
- if (P(p) || h.has(p)) return;
593
- if (o.has(p)) {
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(p);
598
- const v = a.getResourceDataIfExists(p, !0), w = a.listKeyValuesIfResourceExists(p), M = f;
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([v, w]);
602
- if (M && (l++, f = !0), I !== void 0) {
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((p) => k(p));
609
+ s.forEach((v) => k(v));
610
610
  const u = [];
611
611
  for (; ; ) {
612
- const p = r.shift();
613
- if (p === void 0)
612
+ const v = r.shift();
613
+ if (v === void 0)
614
614
  break;
615
- let v = await p;
616
- if (v !== void 0) {
617
- if (n !== void 0) {
618
- const w = n(v);
619
- t && (t.prunedFields += v.fields.length - w.length), v = { ...v, fields: w };
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(v.error);
622
- for (const w of v.fields)
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 += v.fields.length, t.retrievedKeyValues += v.kv.length, t.retrievedResourceDataBytes += ((c = v.data) == null ? void 0 : c.length) ?? 0;
626
- for (const w of v.kv) t.retrievedKeyValueBytes += w.value.length;
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(v);
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 ce(a) {
634
- return a;
633
+ function he(n) {
634
+ return n;
635
635
  }
636
- function he(a, e, t) {
637
- var n;
638
- const i = a instanceof R ? y(t).accessor(a).node() : a instanceof E ? a.node() : a, o = { ...i.resourceInfo };
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] = (n = i.traverse({
642
+ r[f] = (a = i.traverse({
643
643
  field: f,
644
644
  errorIfFieldNotSet: l,
645
645
  stableIfNotFound: !l
646
- })) == null ? void 0 : n.id;
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 le(a, e, t) {
662
- if (a instanceof R) {
663
- const i = t.accessor(a).node(), s = i.resourceInfo, o = e.map((n) => {
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
- n,
667
- (f = (r = i.getField(n)) == null ? void 0 : r.value) == null ? void 0 : f.id
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 a;
676
+ return n;
677
677
  }
678
- function fe(a, e, t) {
679
- if (!(a instanceof R)) return a;
680
- const i = t.accessor(a).node(), s = i.resourceInfo, o = e.map((n) => [n, i.getKeyValue(n)]);
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 W {
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: n, pollingInterval: r, stopPollingDelay: f, logStat: l } = i;
704
- this.pruning = n, this.pollingInterval = r, this.finalPredicate = o ?? e.finalPredicate, this.logStat = l, this.state = new V(t, this.finalPredicate), this.hooks = new B(
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 },
@@ -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 n of s) n.reject(o);
753
- if (o instanceof S) {
754
- (t = this.logger) == null || t.error(o), this.state.invalidateTree("stat update error"), this.state = new V(this.root, this.finalPredicate);
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,39 @@ 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 W(e, t, i, s);
781
- let n = i.logStat ? F() : void 0, r = !1;
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(n), r = !0;
783
+ await o.refresh(a), r = !0;
784
784
  } finally {
785
- n && s && s.info(
786
- `Tree stat (initial load, ${r ? "success" : "failure"}): ${JSON.stringify(n)}`
785
+ a && s && s.info(
786
+ `Tree stat (initial load, ${r ? "success" : "failure"}): ${JSON.stringify(a)}`
787
787
  );
788
788
  }
789
789
  return o;
790
790
  }
791
791
  }
792
792
  export {
793
- N as PlError,
794
793
  R as PlTreeEntry,
795
794
  E as PlTreeEntryAccessor,
796
795
  Y as PlTreeNodeAccessor,
797
796
  G as PlTreeResource,
798
- V as PlTreeState,
799
- W as SynchronizedTreeState,
800
- S as TreeStateUpdateError,
797
+ O as PlTreeState,
798
+ K as SynchronizedTreeState,
799
+ C as TreeStateUpdateError,
801
800
  Q as constructTreeLoadingRequest,
802
- de as formatTreeLoadingStat,
801
+ ce as formatTreeLoadingStat,
803
802
  F as initialTreeLoadingStat,
804
- ae as isPlTreeEntry,
805
- ne as isPlTreeEntryAccessor,
806
- oe as isPlTreeNodeAccessor,
803
+ ne as isPlTreeEntry,
804
+ oe as isPlTreeEntryAccessor,
805
+ ue as isPlTreeNodeAccessor,
807
806
  X as loadTreeState,
808
- he as makeResourceSnapshot,
807
+ le as makeResourceSnapshot,
809
808
  b as mapValueAndError,
810
- se as mapValueAndErrorIfDefined,
811
- ce as rsSchema,
812
- ue as treeEntryToResourceInfo,
813
- le as treeEntryToResourceWithData,
814
- fe as treeEntryToResourceWithMetadata
809
+ ae as mapValueAndErrorIfDefined,
810
+ he as rsSchema,
811
+ de as treeEntryToResourceInfo,
812
+ fe as treeEntryToResourceWithData,
813
+ ge as treeEntryToResourceWithMetadata
815
814
  };
816
815
  //# sourceMappingURL=index.mjs.map