@milaboratories/pl-tree 1.4.34 → 1.5.1

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,30 +1,30 @@
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
- import { ChangeSource as m, PollingComputableHooks as B } from "@milaboratories/computable";
6
- import { parsePlError as P } from "@milaboratories/pl-errors";
1
+ var W = Object.defineProperty;
2
+ var M = (o, e, t) => e in o ? W(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var d = (o, e, t) => M(o, typeof e != "symbol" ? e + "" : e, t);
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
+ import { ChangeSource as m, PollingComputableHooks as q } from "@milaboratories/computable";
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(n, e) {
11
- if (n !== void 0)
12
- return b(n, e);
10
+ function ae(o, e) {
11
+ if (o !== void 0)
12
+ return P(o, e);
13
13
  }
14
- function b(n, e) {
14
+ function P(o, e) {
15
15
  const t = {};
16
- return n.value !== void 0 && (t.value = e(n.value)), n.error !== void 0 && (t.error = e(n.error)), t;
16
+ return o.value !== void 0 && (t.value = e(o.value)), o.error !== void 0 && (t.error = e(o.error)), t;
17
17
  }
18
- function ne(n) {
19
- return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeEntry";
18
+ function ne(o) {
19
+ return typeof o == "object" && o !== null && o.__pl_tree_type_marker__ === "PlTreeEntry";
20
20
  }
21
- function oe(n) {
22
- return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeEntryAccessor";
21
+ function oe(o) {
22
+ return typeof o == "object" && o !== null && o.__pl_tree_type_marker__ === "PlTreeEntryAccessor";
23
23
  }
24
- function ue(n) {
25
- return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeNodeAccessor";
24
+ function ue(o) {
25
+ return typeof o == "object" && o !== null && o.__pl_tree_type_marker__ === "PlTreeNodeAccessor";
26
26
  }
27
- class R {
27
+ class C {
28
28
  constructor(e, t) {
29
29
  d(this, "__pl_tree_type_marker__", "PlTreeEntry");
30
30
  this.accessorData = e, this.rid = t;
@@ -39,46 +39,46 @@ class R {
39
39
  return this.toString();
40
40
  }
41
41
  toString() {
42
- return `[ENTRY:${S(this.rid)}]`;
42
+ return `[ENTRY:${R(this.rid)}]`;
43
43
  }
44
44
  }
45
- function N(n, e, t, i, s) {
46
- const o = new Y(
47
- n,
45
+ function N(o, e, t, r, s) {
46
+ const n = new Y(
47
+ o,
48
48
  e,
49
- e.get(t.ctx.watcher, i),
49
+ e.get(t.ctx.watcher, r),
50
50
  t
51
51
  );
52
52
  if (!s.ignoreError) {
53
- const a = o.getError();
53
+ const a = n.getError();
54
54
  if (a !== void 0)
55
- throw P(p(a.getDataAsString()), o.id, o.resourceType);
55
+ throw V(p(a.getDataAsString()), n.id, n.resourceType);
56
56
  }
57
- if (s.assertResourceType !== void 0 && (Array.isArray(s.assertResourceType) ? s.assertResourceType.findIndex((a) => A(a, o.resourceType)) === -1 : !A(s.assertResourceType, o.resourceType)))
57
+ if (s.assertResourceType !== void 0 && (Array.isArray(s.assertResourceType) ? s.assertResourceType.findIndex((a) => A(a, n.resourceType)) === -1 : !A(s.assertResourceType, n.resourceType)))
58
58
  throw new Error(
59
- `wrong resource type ${J(o.resourceType)} but expected ${s.assertResourceType}`
59
+ `wrong resource type ${U(n.resourceType)} but expected ${s.assertResourceType}`
60
60
  );
61
- return o;
61
+ return n;
62
62
  }
63
63
  class E {
64
- constructor(e, t, i, s) {
64
+ constructor(e, t, r, s) {
65
65
  d(this, "__pl_tree_type_marker__", "PlTreeEntryAccessor");
66
- this.accessorData = e, this.tree = t, this.rid = i, this.instanceData = s;
66
+ this.accessorData = e, this.tree = t, this.rid = r, this.instanceData = s;
67
67
  }
68
68
  node(e = {}) {
69
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);
70
70
  }
71
71
  }
72
- function de(n, e) {
73
- return n instanceof R ? e.accessor(n).node().resourceInfo : n;
72
+ function de(o, e) {
73
+ return o instanceof C ? e.accessor(o).node().resourceInfo : o;
74
74
  }
75
75
  class Y {
76
- constructor(e, t, i, s) {
76
+ constructor(e, t, r, s) {
77
77
  d(this, "__pl_tree_type_marker__", "PlTreeNodeAccessor");
78
78
  d(this, "onUnstableLambda", (e) => {
79
79
  this.instanceData.ctx.markUnstable(e);
80
80
  });
81
- this.accessorData = e, this.tree = t, this.resource = i, this.instanceData = s;
81
+ this.accessorData = e, this.tree = t, this.resource = r, this.instanceData = s;
82
82
  }
83
83
  get id() {
84
84
  return this.instanceData.guard(), this.resource.id;
@@ -102,50 +102,50 @@ class Y {
102
102
  return this.traverseOrErrorWithCommon({}, ...e);
103
103
  }
104
104
  traverseWithCommon(e, ...t) {
105
- const i = this.traverseOrErrorWithCommon(e, ...t);
106
- if (i !== void 0) {
107
- if (!i.ok) throw i.error;
108
- return i.value;
105
+ const r = this.traverseOrErrorWithCommon(e, ...t);
106
+ if (r !== void 0) {
107
+ if (!r.ok) throw r.error;
108
+ return r.value;
109
109
  }
110
110
  }
111
111
  traverseOrErrorWithCommon(e, ...t) {
112
- let i = this;
112
+ let r = this;
113
113
  for (const s of t) {
114
- const o = typeof s == "string" ? {
114
+ const n = typeof s == "string" ? {
115
115
  ...e,
116
116
  field: s
117
- } : { ...e, ...s }, a = i.getField(s);
118
- if (a === void 0 || o.pureFieldErrorToUndefined && a.value === void 0 && a.error !== void 0)
117
+ } : { ...e, ...s }, a = r.getField(s);
118
+ if (a === void 0 || n.pureFieldErrorToUndefined && a.value === void 0 && a.error !== void 0)
119
119
  return;
120
- if ((!o.ignoreError || a.value === void 0) && a.error !== void 0)
120
+ if ((!n.ignoreError || a.value === void 0) && a.error !== void 0)
121
121
  return {
122
122
  ok: !1,
123
123
  // FIXME: in next tickets we'll allow Errors to be thrown.
124
- error: P(
124
+ error: V(
125
125
  p(a.error.getDataAsString()),
126
- i.id,
127
- i.resourceType,
128
- o.field
126
+ r.id,
127
+ r.resourceType,
128
+ n.field
129
129
  )
130
130
  };
131
131
  if (a.value === void 0) {
132
- if (o.errorIfFieldNotSet)
132
+ if (n.errorIfFieldNotSet)
133
133
  return {
134
134
  ok: !1,
135
- error: `field have no assigned value ${o.field} of ${S(i.id)}`
135
+ error: `field have no assigned value ${n.field} of ${R(r.id)}`
136
136
  };
137
- this.onUnstableLambda("unpopulated_field:" + o.field);
137
+ this.onUnstableLambda("unpopulated_field:" + n.field);
138
138
  return;
139
139
  }
140
- i = a.value;
140
+ r = a.value;
141
141
  }
142
- return { ok: !0, value: i };
142
+ return { ok: !0, value: r };
143
143
  }
144
144
  getField(e) {
145
145
  this.instanceData.guard();
146
- const t = typeof e == "string" ? { field: e } : e, i = this.resource.getField(this.instanceData.ctx.watcher, t, this.onUnstableLambda);
147
- if (i !== void 0)
148
- return b(i, (s) => this.getResourceFromTree(s, { ignoreError: !0 }));
146
+ const t = typeof e == "string" ? { field: e } : e, r = this.resource.getField(this.instanceData.ctx.watcher, t, this.onUnstableLambda);
147
+ if (r !== void 0)
148
+ return P(r, (s) => this.getResourceFromTree(s, { ignoreError: !0 }));
149
149
  }
150
150
  getInputsLocked() {
151
151
  this.instanceData.guard();
@@ -191,8 +191,8 @@ class Y {
191
191
  }
192
192
  getKeyValue(e, t = !1) {
193
193
  this.instanceData.guard();
194
- const i = this.resource.getKeyValue(this.instanceData.ctx.watcher, e);
195
- return i === void 0 && t && this.instanceData.ctx.markUnstable("key_not_found_b:" + e), i;
194
+ const r = this.resource.getKeyValue(this.instanceData.ctx.watcher, e);
195
+ return r === void 0 && t && this.instanceData.ctx.markUnstable("key_not_found_b:" + e), r;
196
196
  }
197
197
  /** @deprecated */
198
198
  getKeyValueString(e) {
@@ -200,16 +200,16 @@ class Y {
200
200
  }
201
201
  getKeyValueAsString(e, t = !1) {
202
202
  this.instanceData.guard();
203
- const i = this.resource.getKeyValueString(this.instanceData.ctx.watcher, e);
204
- return i === void 0 && t && this.instanceData.ctx.markUnstable("key_not_found_s:" + e), i;
203
+ const r = this.resource.getKeyValueString(this.instanceData.ctx.watcher, e);
204
+ return r === void 0 && t && this.instanceData.ctx.markUnstable("key_not_found_s:" + e), r;
205
205
  }
206
206
  getKeyValueAsJson(e, t = !1) {
207
- const i = this.resource.getKeyValueString(this.instanceData.ctx.watcher, e);
208
- if (i === void 0) {
207
+ const r = this.resource.getKeyValueString(this.instanceData.ctx.watcher, e);
208
+ if (r === void 0) {
209
209
  t && this.instanceData.ctx.markUnstable("key_not_found_j:" + e);
210
210
  return;
211
211
  }
212
- return JSON.parse(i);
212
+ return JSON.parse(r);
213
213
  }
214
214
  /**
215
215
  * Can be used to pass a higher level accessor that will wrap the resource and throw its
@@ -220,18 +220,28 @@ class Y {
220
220
  }
221
221
  /** Can be passed to nested computable. */
222
222
  persist() {
223
- return new R(this.accessorData, this.resource.id);
223
+ return new C(this.accessorData, this.resource.id);
224
224
  }
225
225
  }
226
- class C extends Error {
226
+ class S extends Error {
227
227
  constructor(e) {
228
228
  super(e);
229
229
  }
230
230
  }
231
231
  class $ {
232
- constructor(e, t, i, s, o, a, r) {
232
+ constructor(e, t, r, s, n, a, i) {
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 = a, this.resourceVersion = r;
234
+ this.name = e, this.type = t, this.value = r, this.error = s, this.status = n, this.valueIsFinal = a, this.resourceVersion = i;
235
+ }
236
+ get state() {
237
+ return {
238
+ name: this.name,
239
+ type: this.type,
240
+ status: this.status,
241
+ value: this.value,
242
+ error: this.error,
243
+ valueIsFinal: this.valueIsFinal
244
+ };
235
245
  }
236
246
  }
237
247
  const L = 0, x = new TextDecoder();
@@ -287,14 +297,14 @@ class G {
287
297
  get fields() {
288
298
  return [...this.fieldsMap.values()];
289
299
  }
290
- getField(e, t, i = () => {
300
+ getField(e, t, r = () => {
291
301
  }) {
292
- var a, r, f;
293
- const s = typeof t == "string" ? { field: t } : t, o = this.fieldsMap.get(s.field);
294
- if (o === void 0) {
302
+ var a, i, f;
303
+ const s = typeof t == "string" ? { field: t } : t, n = this.fieldsMap.get(s.field);
304
+ if (n === void 0) {
295
305
  if (s.errorIfFieldNotFound || s.errorIfFieldNotSet)
296
306
  throw new Error(
297
- `Field "${s.field}" not found in resource ${S(this.id)}`
307
+ `Field "${s.field}" not found in resource ${R(this.id)}`
298
308
  );
299
309
  if (!this.inputsLocked) (a = this.inputAndServiceFieldListChanged) == null || a.attachWatcher(e);
300
310
  else if (s.assertFieldType === "Service" || s.assertFieldType === "Input") {
@@ -302,21 +312,21 @@ class G {
302
312
  return;
303
313
  throw new Error(`Service or input field not found ${s.field}.`);
304
314
  }
305
- if (!this.outputsLocked) (r = this.outputFieldListChanged) == null || r.attachWatcher(e);
315
+ if (!this.outputsLocked) (i = this.outputFieldListChanged) == null || i.attachWatcher(e);
306
316
  else if (s.assertFieldType === "Output") {
307
317
  if (s.allowPermanentAbsence)
308
318
  return;
309
319
  throw new Error(`Output field not found ${s.field}.`);
310
320
  }
311
- (f = this.dynamicFieldListChanged) == null || f.attachWatcher(e), !this._finalState && !s.stableIfNotFound && i("field_not_found:" + s.field);
321
+ (f = this.dynamicFieldListChanged) == null || f.attachWatcher(e), !this._finalState && !s.stableIfNotFound && r("field_not_found:" + s.field);
312
322
  return;
313
323
  } else {
314
- if (s.assertFieldType !== void 0 && o.type !== s.assertFieldType)
324
+ if (s.assertFieldType !== void 0 && n.type !== s.assertFieldType)
315
325
  throw new Error(
316
- `Unexpected field type: expected ${s.assertFieldType} but got ${o.type} for the field name ${s.field}`
326
+ `Unexpected field type: expected ${s.assertFieldType} but got ${n.type} for the field name ${s.field}`
317
327
  );
318
328
  const l = {};
319
- return g(o.value) && (l.value = o.value), g(o.error) && (l.error = o.error), l.value === void 0 && l.error === void 0 && i("field_not_resolved:" + s.field), o.change.attachWatcher(e), l;
329
+ return g(n.value) && (l.value = n.value), g(n.error) && (l.error = n.error), l.value === void 0 && l.error === void 0 && r("field_not_resolved:" + s.field), n.change.attachWatcher(e), l;
320
330
  }
321
331
  }
322
332
  getInputsLocked(e) {
@@ -328,7 +338,7 @@ class G {
328
338
  return this.outputsLocked || (t = this.resourceStateChange) == null || t.attachWatcher(e), this.outputsLocked;
329
339
  }
330
340
  get isReadyOrError() {
331
- return this.error !== D || this.resourceReady || this.originalResourceId !== D;
341
+ return this.error !== T || this.resourceReady || this.originalResourceId !== T;
332
342
  }
333
343
  getIsFinal(e) {
334
344
  var t;
@@ -340,41 +350,41 @@ class G {
340
350
  }
341
351
  getError(e) {
342
352
  var t;
343
- if (V(this.error)) {
353
+ if (b(this.error)) {
344
354
  (t = this.resourceStateChange) == null || t.attachWatcher(e);
345
355
  return;
346
356
  } else
347
357
  return this.error;
348
358
  }
349
359
  listInputFields(e) {
350
- var i;
360
+ var r;
351
361
  const t = [];
352
- return this.fieldsMap.forEach((s, o) => {
353
- (s.type === "Input" || s.type === "Service") && t.push(o);
354
- }), this.inputsLocked || (i = this.inputAndServiceFieldListChanged) == null || i.attachWatcher(e), t;
362
+ return this.fieldsMap.forEach((s, n) => {
363
+ (s.type === "Input" || s.type === "Service") && t.push(n);
364
+ }), this.inputsLocked || (r = this.inputAndServiceFieldListChanged) == null || r.attachWatcher(e), t;
355
365
  }
356
366
  listOutputFields(e) {
357
- var i;
367
+ var r;
358
368
  const t = [];
359
- return this.fieldsMap.forEach((s, o) => {
360
- s.type === "Output" && t.push(o);
361
- }), this.outputsLocked || (i = this.outputFieldListChanged) == null || i.attachWatcher(e), t;
369
+ return this.fieldsMap.forEach((s, n) => {
370
+ s.type === "Output" && t.push(n);
371
+ }), this.outputsLocked || (r = this.outputFieldListChanged) == null || r.attachWatcher(e), t;
362
372
  }
363
373
  listDynamicFields(e) {
364
- var i;
374
+ var r;
365
375
  const t = [];
366
- return this.fieldsMap.forEach((s, o) => {
367
- s.type !== "Input" && s.type !== "Output" && t.push(o);
368
- }), (i = this.dynamicFieldListChanged) == null || i.attachWatcher(e), t;
376
+ return this.fieldsMap.forEach((s, n) => {
377
+ s.type !== "Input" && s.type !== "Output" && t.push(n);
378
+ }), (r = this.dynamicFieldListChanged) == null || r.attachWatcher(e), t;
369
379
  }
370
380
  getKeyValue(e, t) {
371
- var i;
372
- return (i = this.kvChanged) == null || i.attachWatcher(e), this.kv.get(t);
381
+ var r;
382
+ return (r = this.kvChanged) == null || r.attachWatcher(e), this.kv.get(t);
373
383
  }
374
384
  getKeyValueString(e, t) {
375
- const i = this.getKeyValue(e, t);
376
- if (i !== void 0)
377
- return x.decode(i);
385
+ const r = this.getKeyValue(e, t);
386
+ if (r !== void 0)
387
+ return x.decode(r);
378
388
  }
379
389
  getDataAsString() {
380
390
  if (this.data !== void 0)
@@ -386,9 +396,9 @@ class G {
386
396
  }
387
397
  verifyReadyState() {
388
398
  if (this.resourceReady && !this.inputsLocked)
389
- throw new Error(`ready without input or output lock: ${T(this.state)}`);
399
+ throw new Error(`ready without input or output lock: ${D(this.basicState)}`);
390
400
  }
391
- get state() {
401
+ get basicState() {
392
402
  return {
393
403
  id: this.id,
394
404
  kind: this.kind,
@@ -402,14 +412,21 @@ class G {
402
412
  final: this.finalFlag
403
413
  };
404
414
  }
415
+ get extendedState() {
416
+ return {
417
+ ...this.basicState,
418
+ fields: this.fields,
419
+ kv: Array.from(this.kv.entries()).map(([e, t]) => ({ key: e, value: t }))
420
+ };
421
+ }
405
422
  /** Called when {@link FinalResourceDataPredicate} returns true for the state. */
406
423
  markFinal() {
407
424
  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
425
  }
409
426
  /** Used for invalidation */
410
427
  markAllChanged() {
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();
428
+ var e, t, r, s, n, a, i;
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(), (n = this.outputFieldListChanged) == null || n.markChanged(), (a = this.dynamicFieldListChanged) == null || a.markChanged(), (i = this.kvChanged) == null || i.markChanged(), this.resourceRemoved.markChanged();
413
430
  }
414
431
  }
415
432
  class O {
@@ -431,70 +448,70 @@ class O {
431
448
  }
432
449
  get(e, t) {
433
450
  this.checkValid();
434
- const i = this.resources.get(t);
435
- if (i === void 0)
436
- throw this.resourcesAdded.attachWatcher(e), new Error(`resource ${S(t)} not found in the tree`);
437
- return i.resourceRemoved.attachWatcher(e), i;
451
+ const r = this.resources.get(t);
452
+ if (r === void 0)
453
+ throw this.resourcesAdded.attachWatcher(e), new Error(`resource ${R(t)} not found in the tree`);
454
+ return r.resourceRemoved.attachWatcher(e), r;
438
455
  }
439
456
  updateFromResourceData(e, t = !1) {
440
457
  this.checkValid();
441
- const i = [], s = [];
458
+ const r = [], s = [];
442
459
  for (const a of e) {
443
- let r = this.resources.get(a.id);
444
- const f = r == null ? void 0 : r.state, l = (h) => {
460
+ let i = this.resources.get(a.id);
461
+ const f = i == null ? void 0 : i.basicState, l = (h) => {
445
462
  const { fields: k, ...u } = a;
446
- throw this.invalidateTree(), new C(
447
- `Unexpected resource state transition (${h}): ${T(
463
+ throw this.invalidateTree(), new S(
464
+ `Unexpected resource state transition (${h}): ${D(
448
465
  u
449
- )} -> ${T(f)}`
466
+ )} -> ${D(f)}`
450
467
  );
451
468
  };
452
- if (r !== void 0) {
453
- r.finalState && l("resource state can be updated after it is marked as final");
469
+ if (i !== void 0) {
470
+ i.finalState && l("resource state can be updated after it is marked as final");
454
471
  let h = !1;
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);
472
+ i.version += 1, i.originalResourceId !== a.originalResourceId && (i.originalResourceId !== T && l("originalResourceId can't change after it is set"), i.originalResourceId = a.originalResourceId, p(i.resourceStateChange).markChanged(), h = !0), i.error !== a.error && (g(i.error) && l("resource can't change attached error after it is set"), i.error = a.error, r.push(i.error), p(i.resourceStateChange).markChanged(), h = !0);
456
473
  for (const u of a.fields) {
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}`), p(r.dynamicFieldListChanged).markChanged(), (c.type === "Input" || c.type === "Service") && (r.inputsLocked && l(
474
+ let c = i.fieldsMap.get(u.name);
475
+ c ? (c.type !== u.type && (c.type !== "Dynamic" && l(`field changed type ${c.type} -> ${u.type}`), p(i.dynamicFieldListChanged).markChanged(), (c.type === "Input" || c.type === "Service") && (i.inputsLocked && l(
459
476
  `adding input field "${u.name}", while corresponding list is locked`
460
- ), p(r.inputAndServiceFieldListChanged).markChanged()), c.type === "Output" && (r.outputsLocked && l(
477
+ ), p(i.inputAndServiceFieldListChanged).markChanged()), c.type === "Output" && (i.outputsLocked && l(
461
478
  `adding output field "${u.name}", while corresponding list is locked`
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 $(
479
+ ), p(i.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) && r.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) && r.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 = i.version) : (c = new $(
463
480
  u.name,
464
481
  u.type,
465
482
  u.value,
466
483
  u.error,
467
484
  u.status,
468
485
  u.valueIsFinal,
469
- r.version
470
- ), g(u.value) && i.push(u.value), g(u.error) && i.push(u.error), u.type === "Input" || u.type === "Service" ? (r.inputsLocked && l(
486
+ i.version
487
+ ), g(u.value) && r.push(u.value), g(u.error) && r.push(u.error), u.type === "Input" || u.type === "Service" ? (i.inputsLocked && l(
471
488
  `adding ${u.type} (${u.name}) field while inputs locked`
472
- ), p(r.inputAndServiceFieldListChanged).markChanged()) : u.type === "Output" ? (r.outputsLocked && l(
489
+ ), p(i.inputAndServiceFieldListChanged).markChanged()) : u.type === "Output" ? (i.outputsLocked && l(
473
490
  `adding ${u.type} (${u.name}) field while outputs locked`
474
- ), p(r.outputFieldListChanged).markChanged()) : p(r.dynamicFieldListChanged).markChanged(), r.fieldsMap.set(u.name, c), h = !0);
491
+ ), p(i.outputFieldListChanged).markChanged()) : p(i.dynamicFieldListChanged).markChanged(), i.fieldsMap.set(u.name, c), h = !0);
475
492
  }
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
- const u = r.resourceReady;
480
- r.resourceReady = a.resourceReady, r.verifyReadyState(), r.isReadyOrError || l(
493
+ if (i.fieldsMap.forEach((u, c, v) => {
494
+ u.resourceVersion !== i.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(i.dynamicFieldListChanged).markChanged());
495
+ }), i.inputsLocked !== a.inputsLocked && (i.inputsLocked && l("inputs unlocking is not permitted"), i.inputsLocked = a.inputsLocked, p(i.lockedChange).markChanged(), h = !0), i.outputsLocked !== a.outputsLocked && (i.outputsLocked && l("outputs unlocking is not permitted"), i.outputsLocked = a.outputsLocked, p(i.lockedChange).markChanged(), h = !0), i.resourceReady !== a.resourceReady) {
496
+ const u = i.resourceReady;
497
+ i.resourceReady = a.resourceReady, i.verifyReadyState(), i.isReadyOrError || l(
481
498
  `resource can't lose it's ready or error state (ready state before ${u})`
482
- ), p(r.resourceStateChange).markChanged(), h = !0;
499
+ ), p(i.resourceStateChange).markChanged(), h = !0;
483
500
  }
484
501
  let k = !1;
485
502
  for (const u of a.kv) {
486
- const c = r.kv.get(u.key);
487
- (c === void 0 || Buffer.compare(c, u.value) !== 0) && (r.kv.set(u.key, u.value), k = !0);
503
+ const c = i.kv.get(u.key);
504
+ (c === void 0 || Buffer.compare(c, u.value) !== 0) && (i.kv.set(u.key, u.value), k = !0);
488
505
  }
489
- if (r.kv.size > a.kv.length) {
506
+ if (i.kv.size > a.kv.length) {
490
507
  const u = new Set(a.kv.map((c) => c.key));
491
- r.kv.forEach((c, v, y) => {
508
+ i.kv.forEach((c, v, y) => {
492
509
  u.has(v) || y.delete(v);
493
510
  }), k = !0;
494
511
  }
495
- k && p(r.kvChanged).markChanged(), h && (r.dataVersion = r.version, this.isFinalPredicate(r) && r.markFinal());
512
+ k && p(i.kvChanged).markChanged(), h && (i.dataVersion = i.version, this.isFinalPredicate(i) && i.markFinal());
496
513
  } else {
497
- r = new G(a), r.verifyReadyState(), g(r.error) && i.push(r.error);
514
+ i = new G(a), i.verifyReadyState(), g(i.error) && r.push(i.error);
498
515
  for (const h of a.fields) {
499
516
  const k = new $(
500
517
  h.name,
@@ -505,35 +522,35 @@ class O {
505
522
  h.valueIsFinal,
506
523
  L
507
524
  );
508
- g(h.value) && i.push(h.value), g(h.error) && i.push(h.error), r.fieldsMap.set(h.name, k);
525
+ g(h.value) && r.push(h.value), g(h.error) && r.push(h.error), i.fieldsMap.set(h.name, k);
509
526
  }
510
- for (const h of a.kv) r.kv.set(h.key, h.value);
511
- this.isFinalPredicate(r) && r.markFinal(), this.resources.set(r.id, r), this.resourcesAdded.markChanged();
527
+ for (const h of a.kv) i.kv.set(h.key, h.value);
528
+ this.isFinalPredicate(i) && i.markFinal(), this.resources.set(i.id, i), this.resourcesAdded.markChanged();
512
529
  }
513
530
  }
514
- for (const a of i) {
515
- const r = this.resources.get(a);
516
- if (!r)
517
- throw this.invalidateTree(), new C(`orphan resource ${a}`);
518
- r.refCount++;
531
+ for (const a of r) {
532
+ const i = this.resources.get(a);
533
+ if (!i)
534
+ throw this.invalidateTree(), new S(`orphan resource ${a}`);
535
+ i.refCount++;
519
536
  }
520
- let o = s;
521
- for (; o.length > 0; ) {
537
+ let n = s;
538
+ for (; n.length > 0; ) {
522
539
  const a = [];
523
- for (const r of o) {
524
- const f = this.resources.get(r);
540
+ for (const i of n) {
541
+ const f = this.resources.get(i);
525
542
  if (!f)
526
- throw this.invalidateTree(), new C(`orphan resource ${r}`);
543
+ throw this.invalidateTree(), new S(`orphan resource ${i}`);
527
544
  f.refCount--, f.refCount === 0 && f.id !== this.root && (f.fieldsMap.forEach((l) => {
528
545
  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));
546
+ }), g(f.error) && a.push(f.error), f.resourceRemoved.markChanged(), this.resources.delete(i));
530
547
  }
531
- o = a;
548
+ n = a;
532
549
  }
533
550
  if (!t) {
534
551
  for (const a of e)
535
552
  if (!this.resources.has(a.id))
536
- throw this.invalidateTree(), new C(`orphan input resource ${a.id}`);
553
+ throw this.invalidateTree(), new S(`orphan input resource ${a.id}`);
537
554
  }
538
555
  }
539
556
  /** @deprecated use "entry" instead */
@@ -541,19 +558,22 @@ class O {
541
558
  return this.checkValid(), this.entry(e);
542
559
  }
543
560
  entry(e = this.root) {
544
- return this.checkValid(), new R({ treeProvider: () => this }, e);
561
+ return this.checkValid(), new C({ treeProvider: () => this }, e);
545
562
  }
546
563
  invalidateTree(e) {
547
564
  this._isValid = !1, this.invalidationMessage = e, this.resources.forEach((t) => {
548
565
  t.markAllChanged();
549
566
  });
550
567
  }
568
+ dumpState() {
569
+ return Array.from(this.resources.values()).map((e) => e.extendedState);
570
+ }
551
571
  }
552
- function Q(n, e) {
553
- const t = [], i = /* @__PURE__ */ new Set();
554
- return n.forEachResource((s) => {
555
- s.finalState ? i.add(s.id) : t.push(s.id);
556
- }), t.length === 0 && i.size === 0 && t.push(n.root), { seedResources: t, finalResources: i, pruningFunction: e };
572
+ function Q(o, e) {
573
+ const t = [], r = /* @__PURE__ */ new Set();
574
+ return o.forEachResource((s) => {
575
+ s.finalState ? r.add(s.id) : t.push(s.id);
576
+ }), t.length === 0 && r.size === 0 && t.push(o.root), { seedResources: t, finalResources: r, pruningFunction: e };
557
577
  }
558
578
  function F() {
559
579
  return {
@@ -569,37 +589,37 @@ function F() {
569
589
  millisSpent: 0
570
590
  };
571
591
  }
572
- function ce(n) {
573
- let e = `Requests: ${n.requests}
592
+ function ce(o) {
593
+ let e = `Requests: ${o.requests}
574
594
  `;
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;
595
+ return e += `Total time: ${z(o.millisSpent)}
596
+ `, e += `Round-trips: ${o.roundTrips}
597
+ `, e += `Resources: ${o.retrievedResources}
598
+ `, e += `Fields: ${o.retrievedFields}
599
+ `, e += `KV: ${o.retrievedKeyValues}
600
+ `, e += `Data Bytes: ${o.retrievedResourceDataBytes}
601
+ `, e += `KV Bytes: ${o.retrievedKeyValueBytes}
602
+ `, e += `Pruned fields: ${o.prunedFields}
603
+ `, e += `Final resources skipped: ${o.finalResourcesSkipped}`, e;
584
604
  }
585
- async function X(n, e, t) {
605
+ async function X(o, e, t) {
586
606
  var c;
587
- const i = Date.now();
607
+ const r = Date.now();
588
608
  t && t.requests++;
589
- const { seedResources: s, finalResources: o, pruningFunction: a } = e, r = new H();
609
+ const { seedResources: s, finalResources: n, pruningFunction: a } = e, i = new H();
590
610
  let f = !0, l = 0;
591
611
  const h = /* @__PURE__ */ new Set(), k = (v) => {
592
- if (V(v) || h.has(v)) return;
593
- if (o.has(v)) {
612
+ if (b(v) || h.has(v)) return;
613
+ if (n.has(v)) {
594
614
  t && t.finalResourcesSkipped++;
595
615
  return;
596
616
  }
597
617
  h.add(v);
598
- const y = n.getResourceDataIfExists(v, !0), w = n.listKeyValuesIfResourceExists(v), W = f;
599
- f && (f = !1), r.push(
618
+ const y = o.getResourceDataIfExists(v, !0), w = o.listKeyValuesIfResourceExists(v), B = f;
619
+ f && (f = !1), i.push(
600
620
  (async () => {
601
621
  const [I, _] = await Promise.all([y, w]);
602
- if (W && (l++, f = !0), I !== void 0) {
622
+ if (B && (l++, f = !0), I !== void 0) {
603
623
  if (_ === void 0) throw new Error("Inconsistent replies");
604
624
  return { ...I, kv: _ };
605
625
  }
@@ -609,7 +629,7 @@ async function X(n, e, t) {
609
629
  s.forEach((v) => k(v));
610
630
  const u = [];
611
631
  for (; ; ) {
612
- const v = r.shift();
632
+ const v = i.shift();
613
633
  if (v === void 0)
614
634
  break;
615
635
  let y = await v;
@@ -628,63 +648,63 @@ async function X(n, e, t) {
628
648
  u.push(y);
629
649
  }
630
650
  }
631
- return t && (t.millisSpent += Date.now() - i, t.roundTrips += l), u;
651
+ return t && (t.millisSpent += Date.now() - r, t.roundTrips += l), u;
632
652
  }
633
- function he(n) {
634
- return n;
653
+ function he(o) {
654
+ return o;
635
655
  }
636
- function le(n, e, t) {
656
+ function le(o, e, t) {
637
657
  var a;
638
- const i = n instanceof R ? p(t).accessor(n).node() : n instanceof E ? n.node() : n, o = { ...i.resourceInfo };
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
- const r = {};
658
+ const r = o instanceof C ? p(t).accessor(o).node() : o instanceof E ? o.node() : o, n = { ...r.resourceInfo };
659
+ if (e.data !== void 0 && (e.data === "raw" ? n.data = r.getData() : n.data = e.data.parse(r.getDataAsJson())), e.fields !== void 0) {
660
+ const i = {};
641
661
  for (const [f, l] of Object.entries(e.fields))
642
- r[f] = (a = i.traverse({
662
+ i[f] = (a = r.traverse({
643
663
  field: f,
644
664
  errorIfFieldNotSet: l,
645
665
  stableIfNotFound: !l
646
666
  })) == null ? void 0 : a.id;
647
- o.fields = r;
667
+ n.fields = i;
648
668
  }
649
669
  if (e.kv !== void 0) {
650
- const r = {};
670
+ const i = {};
651
671
  for (const [f, l] of Object.entries(e.kv)) {
652
- const h = i.getKeyValue(f);
672
+ const h = r.getKeyValue(f);
653
673
  if (h === void 0)
654
674
  throw new Error(`Key not found ${f}`);
655
- l === "raw" ? r[f] = h : r[f] = l.parse(JSON.parse(Buffer.from(h).toString("utf-8")));
675
+ l === "raw" ? i[f] = h : i[f] = l.parse(JSON.parse(Buffer.from(h).toString("utf-8")));
656
676
  }
657
- o.kv = r;
677
+ n.kv = i;
658
678
  }
659
- return o;
679
+ return n;
660
680
  }
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
- var r, f;
681
+ function fe(o, e, t) {
682
+ if (o instanceof C) {
683
+ const r = t.accessor(o).node(), s = r.resourceInfo, n = e.map((a) => {
684
+ var i, f;
665
685
  return [
666
686
  a,
667
- (f = (r = i.getField(a)) == null ? void 0 : r.value) == null ? void 0 : f.id
687
+ (f = (i = r.getField(a)) == null ? void 0 : i.value) == null ? void 0 : f.id
668
688
  ];
669
689
  });
670
690
  return {
671
691
  ...s,
672
- fields: new Map(o),
673
- data: i.getData() ?? new Uint8Array()
692
+ fields: new Map(n),
693
+ data: r.getData() ?? new Uint8Array()
674
694
  };
675
695
  }
676
- return n;
696
+ return o;
677
697
  }
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)]);
698
+ function ge(o, e, t) {
699
+ if (!(o instanceof C)) return o;
700
+ const r = t.accessor(o).node(), s = r.resourceInfo, n = e.map((a) => [a, r.getKeyValue(a)]);
681
701
  return {
682
702
  ...s,
683
- metadata: Object.fromEntries(o)
703
+ metadata: Object.fromEntries(n)
684
704
  };
685
705
  }
686
706
  class K {
687
- constructor(e, t, i, s) {
707
+ constructor(e, t, r, s) {
688
708
  d(this, "finalPredicate");
689
709
  d(this, "state");
690
710
  d(this, "pollingInterval");
@@ -700,8 +720,8 @@ class K {
700
720
  /** If true this tree state is permanently terminaed. */
701
721
  d(this, "terminated", !1);
702
722
  this.pl = e, this.root = t, this.logger = s;
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(
723
+ const { finalPredicateOverride: n, pruning: a, pollingInterval: i, stopPollingDelay: f, logStat: l } = r;
724
+ this.pruning = a, this.pollingInterval = i, this.finalPredicate = n ?? e.finalPredicate, this.logStat = l, this.state = new O(t, this.finalPredicate), this.hooks = new q(
705
725
  () => this.startUpdating(),
706
726
  () => this.stopUpdating(),
707
727
  { stopDebounce: f },
@@ -715,7 +735,7 @@ class K {
715
735
  }
716
736
  entry(e = this.root) {
717
737
  if (this.terminated) throw new Error("tree synchronization is terminated");
718
- return new R({ treeProvider: () => this.state, hooks: this.hooks }, e);
738
+ return new C({ treeProvider: () => this.state, hooks: this.hooks }, e);
719
739
  }
720
740
  /** Can be used to externally kick off the synchronization polling loop, and
721
741
  * await for the first synchronization to happen. */
@@ -737,34 +757,41 @@ class K {
737
757
  /** Executed from the main loop, and initialization procedure. */
738
758
  async refresh(e, t) {
739
759
  if (this.terminated) throw new Error("tree synchronization is terminated");
740
- const i = Q(this.state, this.pruning), s = await this.pl.withReadTx("ReadingTree", async (o) => await X(o, i, e), t);
760
+ const r = Q(this.state, this.pruning), s = await this.pl.withReadTx("ReadingTree", async (n) => await X(n, r, e), t);
741
761
  this.state.updateFromResourceData(s, !0);
742
762
  }
743
763
  async mainLoop() {
744
- var t, i;
764
+ var t, r;
745
765
  let e = this.logStat ? F() : void 0;
746
766
  for (; this.keepRunning; ) {
747
767
  let s;
748
768
  this.scheduledOnNextState.length > 0 && (s = this.scheduledOnNextState, this.scheduledOnNextState = []);
749
769
  try {
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
- } catch (o) {
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);
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 n of s) n.resolve();
771
+ } catch (n) {
772
+ if (e && this.logger && this.logger.info(`Tree stat (error): ${JSON.stringify(e)}`), s !== void 0) for (const a of s) a.reject(n);
773
+ if (n instanceof S) {
774
+ (t = this.logger) == null || t.error(n), this.state.invalidateTree("stat update error"), this.state = new O(this.root, this.finalPredicate);
755
775
  continue;
756
- } else (i = this.logger) == null || i.warn(o);
776
+ } else (r = this.logger) == null || r.warn(n);
757
777
  }
758
778
  if (!this.keepRunning || this.terminated) break;
759
779
  try {
760
780
  await j.setTimeout(this.pollingInterval, this.abortController.signal);
761
- } catch (o) {
762
- if (!q(o)) throw new Error("Unexpected error", { cause: o });
781
+ } catch (n) {
782
+ if (!J(n)) throw new Error("Unexpected error", { cause: n });
763
783
  break;
764
784
  }
765
785
  }
766
786
  this.currentLoop = void 0;
767
787
  }
788
+ /**
789
+ * Dumps the current state of the tree.
790
+ * @returns An array of ExtendedResourceData objects representing the current state of the tree.
791
+ */
792
+ dumpState() {
793
+ return this.state.dumpState();
794
+ }
768
795
  /**
769
796
  * Terminates the internal loop, and permanently destoys all internal state, so
770
797
  * all computables using this state will resolve to errors.
@@ -776,29 +803,68 @@ class K {
776
803
  async awaitSyncLoopTermination() {
777
804
  this.currentLoop !== void 0 && await this.currentLoop;
778
805
  }
779
- static async init(e, t, i, s) {
780
- const o = new K(e, t, i, s);
781
- let a = i.logStat ? F() : void 0, r = !1;
806
+ static async init(e, t, r, s) {
807
+ const n = new K(e, t, r, s);
808
+ let a = r.logStat ? F() : void 0, i = !1;
782
809
  try {
783
- await o.refresh(a, {
784
- timeout: i.initialTreeLoadingTimeout
785
- }), r = !0;
810
+ await n.refresh(a, {
811
+ timeout: r.initialTreeLoadingTimeout
812
+ }), i = !0;
786
813
  } finally {
787
814
  a && s && s.info(
788
- `Tree stat (initial load, ${r ? "success" : "failure"}): ${JSON.stringify(a)}`
815
+ `Tree stat (initial load, ${i ? "success" : "failure"}): ${JSON.stringify(a)}`
789
816
  );
790
817
  }
791
- return o;
818
+ return n;
819
+ }
820
+ }
821
+ function pe(o) {
822
+ var t;
823
+ const e = {
824
+ total: {
825
+ count: 0,
826
+ fieldNameBytes: 0,
827
+ fieldsCount: 0,
828
+ dataBytes: 0,
829
+ kvCount: 0,
830
+ kvBytes: 0
831
+ },
832
+ byResourceType: {}
833
+ };
834
+ for (const r of o) {
835
+ const s = `${r.type.name}/${r.type.version}`;
836
+ e.byResourceType[s] || (e.byResourceType[s] = {
837
+ count: 0,
838
+ fieldNameBytes: 0,
839
+ fieldsCount: 0,
840
+ dataBytes: 0,
841
+ kvCount: 0,
842
+ kvBytes: 0
843
+ });
844
+ const n = e.byResourceType[s];
845
+ n.count++, e.total.count++;
846
+ for (const a of r.fields)
847
+ n.fieldNameBytes += a.name.length, n.fieldsCount++, e.total.fieldNameBytes += a.name.length, e.total.fieldsCount++;
848
+ if (r.data) {
849
+ const a = ((t = r.data) == null ? void 0 : t.length) ?? 0;
850
+ n.dataBytes += a, e.total.dataBytes += a;
851
+ }
852
+ n.kvCount += r.kv.length, e.total.kvCount += r.kv.length;
853
+ for (const a of r.kv) {
854
+ const i = a.key.length + a.value.length;
855
+ n.kvBytes += i, e.total.kvBytes += i;
856
+ }
792
857
  }
858
+ return e;
793
859
  }
794
860
  export {
795
- R as PlTreeEntry,
861
+ C as PlTreeEntry,
796
862
  E as PlTreeEntryAccessor,
797
863
  Y as PlTreeNodeAccessor,
798
864
  G as PlTreeResource,
799
865
  O as PlTreeState,
800
866
  K as SynchronizedTreeState,
801
- C as TreeStateUpdateError,
867
+ S as TreeStateUpdateError,
802
868
  Q as constructTreeLoadingRequest,
803
869
  ce as formatTreeLoadingStat,
804
870
  F as initialTreeLoadingStat,
@@ -807,9 +873,10 @@ export {
807
873
  ue as isPlTreeNodeAccessor,
808
874
  X as loadTreeState,
809
875
  le as makeResourceSnapshot,
810
- b as mapValueAndError,
876
+ P as mapValueAndError,
811
877
  ae as mapValueAndErrorIfDefined,
812
878
  he as rsSchema,
879
+ pe as treeDumpStats,
813
880
  de as treeEntryToResourceInfo,
814
881
  fe as treeEntryToResourceWithData,
815
882
  ge as treeEntryToResourceWithMetadata