@milaboratories/pl-tree 1.6.12 → 1.7.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,41 +1,41 @@
1
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 F, isNullResourceId as V, stringifyWithResourceId as L, isTimeoutOrCancelError as q } from "@milaboratories/pl-client";
5
- import { ChangeSource as m, PollingComputableHooks as z } from "@milaboratories/computable";
6
- import { parsePlError as P } from "@milaboratories/pl-errors";
7
- import { notEmpty as p, cachedDecode as $, cachedDeserialize as b, msToHumanReadable as H } from "@milaboratories/ts-helpers";
8
- import j from "denque";
9
- import * as Y from "node:timers/promises";
10
- function ne(n, e) {
11
- if (n !== void 0)
12
- return N(n, e);
2
+ var U = (o, e, t) => e in o ? M(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var u = (o, e, t) => U(o, typeof e != "symbol" ? e + "" : e, t);
4
+ import { resourceIdToString as g, resourceTypesEqual as _, resourceTypeToString as J, isNotNullResourceId as y, NullResourceId as D, isNullResourceId as O, stringifyWithResourceId as F, isTimeoutOrCancelError as q } from "@milaboratories/pl-client";
5
+ import { ChangeSource as C, KeyedChangeSource as z, PollingComputableHooks as H } from "@milaboratories/computable";
6
+ import { parsePlError as V } from "@milaboratories/pl-errors";
7
+ import { notEmpty as p, cachedDecode as A, cachedDeserialize as b, msToHumanReadable as j } from "@milaboratories/ts-helpers";
8
+ import Y from "denque";
9
+ import * as G from "node:timers/promises";
10
+ function oe(o, e) {
11
+ if (o !== void 0)
12
+ return K(o, e);
13
13
  }
14
- function N(n, e) {
14
+ function K(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
- class oe extends Error {
18
+ class de extends Error {
19
19
  constructor(e) {
20
20
  super(e);
21
21
  }
22
22
  }
23
- function ue(n) {
24
- return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeEntry";
23
+ function ue(o) {
24
+ return typeof o == "object" && o !== null && o.__pl_tree_type_marker__ === "PlTreeEntry";
25
25
  }
26
- function de(n) {
27
- return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeEntryAccessor";
26
+ function ce(o) {
27
+ return typeof o == "object" && o !== null && o.__pl_tree_type_marker__ === "PlTreeEntryAccessor";
28
28
  }
29
- function ce(n) {
30
- return typeof n == "object" && n !== null && n.__pl_tree_type_marker__ === "PlTreeNodeAccessor";
29
+ function he(o) {
30
+ return typeof o == "object" && o !== null && o.__pl_tree_type_marker__ === "PlTreeNodeAccessor";
31
31
  }
32
- class C {
32
+ class R {
33
33
  constructor(e, t) {
34
- d(this, "__pl_tree_type_marker__", "PlTreeEntry");
34
+ u(this, "__pl_tree_type_marker__", "PlTreeEntry");
35
35
  this.accessorData = e, this.rid = t;
36
36
  }
37
37
  createAccessor(e, t) {
38
- return new E(this.accessorData, this.accessorData.treeProvider(), this.rid, {
38
+ return new T(this.accessorData, this.accessorData.treeProvider(), this.rid, {
39
39
  ctx: e,
40
40
  guard: t
41
41
  });
@@ -44,47 +44,47 @@ class C {
44
44
  return this.toString();
45
45
  }
46
46
  toString() {
47
- return `[ENTRY:${S(this.rid)}]`;
47
+ return `[ENTRY:${g(this.rid)}]`;
48
48
  }
49
49
  }
50
- function K(n, e, t, r, a) {
51
- const o = new G(
52
- n,
50
+ function N(o, e, t, i, n) {
51
+ const d = new Q(
52
+ o,
53
53
  e,
54
- e.get(t.ctx.watcher, r),
54
+ e.get(t.ctx.watcher, i),
55
55
  t
56
56
  );
57
- if (!a.ignoreError) {
58
- const s = o.getError();
59
- if (s !== void 0)
60
- throw P(p(s.getDataAsString()), o.id, o.resourceType);
57
+ if (!n.ignoreError) {
58
+ const a = d.getError();
59
+ if (a !== void 0)
60
+ throw V(p(a.getDataAsString()), d.id, d.resourceType);
61
61
  }
62
- if (a.assertResourceType !== void 0 && (Array.isArray(a.assertResourceType) ? a.assertResourceType.findIndex((s) => A(s, o.resourceType)) === -1 : !A(a.assertResourceType, o.resourceType)))
62
+ if (n.assertResourceType !== void 0 && (Array.isArray(n.assertResourceType) ? n.assertResourceType.findIndex((a) => _(a, d.resourceType)) === -1 : !_(n.assertResourceType, d.resourceType)))
63
63
  throw new Error(
64
64
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
65
- `wrong resource type ${J(o.resourceType)} but expected ${a.assertResourceType}`
65
+ `wrong resource type ${J(d.resourceType)} but expected ${n.assertResourceType}`
66
66
  );
67
- return o;
67
+ return d;
68
68
  }
69
- class E {
70
- constructor(e, t, r, a) {
71
- d(this, "__pl_tree_type_marker__", "PlTreeEntryAccessor");
72
- this.accessorData = e, this.tree = t, this.rid = r, this.instanceData = a;
69
+ class T {
70
+ constructor(e, t, i, n) {
71
+ u(this, "__pl_tree_type_marker__", "PlTreeEntryAccessor");
72
+ this.accessorData = e, this.tree = t, this.rid = i, this.instanceData = n;
73
73
  }
74
74
  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);
75
+ return this.instanceData.guard(), this.accessorData.hooks !== void 0 && this.instanceData.ctx.attacheHooks(this.accessorData.hooks), N(this.accessorData, this.tree, this.instanceData, this.rid, e);
76
76
  }
77
77
  }
78
- function he(n, e) {
79
- return n instanceof C ? e.accessor(n).node().resourceInfo : n;
78
+ function le(o, e) {
79
+ return o instanceof R ? e.accessor(o).node().resourceInfo : o;
80
80
  }
81
- class G {
82
- constructor(e, t, r, a) {
83
- d(this, "__pl_tree_type_marker__", "PlTreeNodeAccessor");
84
- d(this, "onUnstableLambda", (e) => {
81
+ class Q {
82
+ constructor(e, t, i, n) {
83
+ u(this, "__pl_tree_type_marker__", "PlTreeNodeAccessor");
84
+ u(this, "onUnstableLambda", (e) => {
85
85
  this.instanceData.ctx.markUnstable(e);
86
86
  });
87
- this.accessorData = e, this.tree = t, this.resource = r, this.instanceData = a;
87
+ this.accessorData = e, this.tree = t, this.resource = i, this.instanceData = n;
88
88
  }
89
89
  get id() {
90
90
  return this.instanceData.guard(), this.resource.id;
@@ -99,7 +99,7 @@ class G {
99
99
  return { id: this.id, type: this.resourceType };
100
100
  }
101
101
  getResourceFromTree(e, t) {
102
- return K(this.accessorData, this.tree, this.instanceData, e, t);
102
+ return N(this.accessorData, this.tree, this.instanceData, e, t);
103
103
  }
104
104
  traverse(...e) {
105
105
  return this.traverseWithCommon({}, ...e);
@@ -108,50 +108,50 @@ class G {
108
108
  return this.traverseOrErrorWithCommon({}, ...e);
109
109
  }
110
110
  traverseWithCommon(e, ...t) {
111
- const r = this.traverseOrErrorWithCommon(e, ...t);
112
- if (r !== void 0) {
113
- if (!r.ok) throw r.error;
114
- return r.value;
111
+ const i = this.traverseOrErrorWithCommon(e, ...t);
112
+ if (i !== void 0) {
113
+ if (!i.ok) throw i.error;
114
+ return i.value;
115
115
  }
116
116
  }
117
117
  traverseOrErrorWithCommon(e, ...t) {
118
- let r = this;
119
- for (const a of t) {
120
- const o = typeof a == "string" ? {
118
+ let i = this;
119
+ for (const n of t) {
120
+ const d = typeof n == "string" ? {
121
121
  ...e,
122
- field: a
123
- } : { ...e, ...a }, s = r.getField(a);
124
- if (s === void 0 || o.pureFieldErrorToUndefined && s.value === void 0 && s.error !== void 0)
122
+ field: n
123
+ } : { ...e, ...n }, a = i.getField(n);
124
+ if (a === void 0 || d.pureFieldErrorToUndefined && a.value === void 0 && a.error !== void 0)
125
125
  return;
126
- if ((!o.ignoreError || s.value === void 0) && s.error !== void 0)
126
+ if ((!d.ignoreError || a.value === void 0) && a.error !== void 0)
127
127
  return {
128
128
  ok: !1,
129
129
  // FIXME: in next tickets we'll allow Errors to be thrown.
130
- error: P(
131
- p(s.error.getDataAsString()),
132
- r.id,
133
- r.resourceType,
134
- o.field
130
+ error: V(
131
+ p(a.error.getDataAsString()),
132
+ i.id,
133
+ i.resourceType,
134
+ d.field
135
135
  )
136
136
  };
137
- if (s.value === void 0) {
138
- if (o.errorIfFieldNotSet)
137
+ if (a.value === void 0) {
138
+ if (d.errorIfFieldNotSet)
139
139
  return {
140
140
  ok: !1,
141
- error: new Error(`field have no assigned value ${o.field} of ${S(r.id)}`)
141
+ error: new Error(`field have no assigned value ${d.field} of ${g(i.id)}`)
142
142
  };
143
- this.onUnstableLambda("unpopulated_field:" + o.field);
143
+ this.onUnstableLambda("unpopulated_field:" + d.field);
144
144
  return;
145
145
  }
146
- r = s.value;
146
+ i = a.value;
147
147
  }
148
- return { ok: !0, value: r };
148
+ return { ok: !0, value: i };
149
149
  }
150
150
  getField(e) {
151
151
  this.instanceData.guard();
152
- const t = typeof e == "string" ? { field: e } : e, r = this.resource.getField(this.instanceData.ctx.watcher, t, this.onUnstableLambda);
153
- if (r !== void 0)
154
- return N(r, (a) => this.getResourceFromTree(a, { ignoreError: !0 }));
152
+ const t = typeof e == "string" ? { field: e } : e, i = this.resource.getField(this.instanceData.ctx.watcher, t, this.onUnstableLambda);
153
+ if (i !== void 0)
154
+ return K(i, (n) => this.getResourceFromTree(n, { ignoreError: !0 }));
155
155
  }
156
156
  getInputsLocked() {
157
157
  this.instanceData.guard();
@@ -197,8 +197,8 @@ class G {
197
197
  }
198
198
  getKeyValue(e, t = !1) {
199
199
  this.instanceData.guard();
200
- const r = this.resource.getKeyValue(this.instanceData.ctx.watcher, e);
201
- return r === void 0 && t && this.instanceData.ctx.markUnstable("key_not_found_b:" + e), r;
200
+ const i = this.resource.getKeyValue(this.instanceData.ctx.watcher, e);
201
+ return i === void 0 && t && this.instanceData.ctx.markUnstable("key_not_found_b:" + e), i;
202
202
  }
203
203
  /** @deprecated */
204
204
  getKeyValueString(e) {
@@ -206,38 +206,38 @@ class G {
206
206
  }
207
207
  getKeyValueAsString(e, t = !1) {
208
208
  this.instanceData.guard();
209
- const r = this.resource.getKeyValueString(this.instanceData.ctx.watcher, e);
210
- return r === void 0 && t && this.instanceData.ctx.markUnstable("key_not_found_s:" + e), r;
209
+ const i = this.resource.getKeyValueString(this.instanceData.ctx.watcher, e);
210
+ return i === void 0 && t && this.instanceData.ctx.markUnstable("key_not_found_s:" + e), i;
211
211
  }
212
212
  getKeyValueAsJson(e, t = !1) {
213
- const r = this.resource.getKeyValueAsJson(this.instanceData.ctx.watcher, e);
214
- if (r === void 0) {
213
+ const i = this.resource.getKeyValueAsJson(this.instanceData.ctx.watcher, e);
214
+ if (i === void 0) {
215
215
  t && this.instanceData.ctx.markUnstable("key_not_found_j:" + e);
216
216
  return;
217
217
  }
218
- return r;
218
+ return i;
219
219
  }
220
220
  /**
221
221
  * Can be used to pass a higher level accessor that will wrap the resource and throw its
222
222
  * errors on node resolution.
223
223
  * */
224
224
  toEntryAccessor() {
225
- return new E(this.accessorData, this.tree, this.id, this.instanceData);
225
+ return new T(this.accessorData, this.tree, this.id, this.instanceData);
226
226
  }
227
227
  /** Can be passed to nested computable. */
228
228
  persist() {
229
- return new C(this.accessorData, this.resource.id);
229
+ return new R(this.accessorData, this.resource.id);
230
230
  }
231
231
  }
232
- class R extends Error {
232
+ class S extends Error {
233
233
  constructor(e) {
234
234
  super(e);
235
235
  }
236
236
  }
237
237
  class x {
238
- constructor(e, t, r, a, o, s, i) {
239
- d(this, "change", new m());
240
- this.name = e, this.type = t, this.value = r, this.error = a, this.status = o, this.valueIsFinal = s, this.resourceVersion = i;
238
+ constructor(e, t, i, n, d, a, r) {
239
+ u(this, "change", new C());
240
+ this.name = e, this.type = t, this.value = i, this.error = n, this.status = d, this.valueIsFinal = a, this.resourceVersion = r;
241
241
  }
242
242
  get state() {
243
243
  return {
@@ -250,41 +250,42 @@ class x {
250
250
  };
251
251
  }
252
252
  }
253
- const T = 0;
254
- class Q {
253
+ const L = 0;
254
+ class X {
255
255
  constructor(e, t) {
256
256
  /** Tracks number of other resources referencing this resource. Used to perform garbage collection in tree patching procedure */
257
- d(this, "refCount", 0);
257
+ u(this, "refCount", 0);
258
258
  /** Increments each time resource is checked for difference with new state */
259
- d(this, "version", T);
259
+ u(this, "version", L);
260
260
  /** Set to resource version when resource state, or it's fields have changed */
261
- d(this, "dataVersion", T);
262
- d(this, "fieldsMap", /* @__PURE__ */ new Map());
263
- d(this, "kv", /* @__PURE__ */ new Map());
264
- d(this, "resourceRemoved", new m());
261
+ u(this, "dataVersion", L);
262
+ u(this, "fieldsMap", /* @__PURE__ */ new Map());
263
+ u(this, "kv", /* @__PURE__ */ new Map());
264
+ u(this, "resourceRemoved", new C());
265
265
  // following change source are removed when resource is marked as final
266
- d(this, "finalChanged", new m());
267
- d(this, "resourceStateChange", new m());
268
- d(this, "lockedChange", new m());
269
- d(this, "inputAndServiceFieldListChanged", new m());
270
- d(this, "outputFieldListChanged", new m());
271
- d(this, "dynamicFieldListChanged", new m());
272
- d(this, "kvChanged", new m());
273
- d(this, "id");
274
- d(this, "originalResourceId");
275
- d(this, "kind");
276
- d(this, "type");
277
- d(this, "data");
278
- d(this, "dataAsString");
279
- d(this, "dataAsJson");
280
- d(this, "error");
281
- d(this, "inputsLocked");
282
- d(this, "outputsLocked");
283
- d(this, "resourceReady");
284
- d(this, "finalFlag");
266
+ u(this, "finalChanged", new C());
267
+ u(this, "resourceStateChange", new C());
268
+ u(this, "lockedChange", new C());
269
+ u(this, "inputAndServiceFieldListChanged", new C());
270
+ u(this, "outputFieldListChanged", new C());
271
+ u(this, "dynamicFieldListChanged", new C());
272
+ // kvChangedGlobal? = new ChangeSource();
273
+ u(this, "kvChangedPerKey", new z());
274
+ u(this, "id");
275
+ u(this, "originalResourceId");
276
+ u(this, "kind");
277
+ u(this, "type");
278
+ u(this, "data");
279
+ u(this, "dataAsString");
280
+ u(this, "dataAsJson");
281
+ u(this, "error");
282
+ u(this, "inputsLocked");
283
+ u(this, "outputsLocked");
284
+ u(this, "resourceReady");
285
+ u(this, "finalFlag");
285
286
  /** Set externally by the tree, using {@link FinalResourceDataPredicate} */
286
- d(this, "_finalState", !1);
287
- d(this, "logger");
287
+ u(this, "_finalState", !1);
288
+ u(this, "logger");
288
289
  this.id = e.id, this.originalResourceId = e.originalResourceId, this.kind = e.kind, this.type = e.type, this.data = e.data, this.error = e.error, this.inputsLocked = e.inputsLocked, this.outputsLocked = e.outputsLocked, this.resourceReady = e.resourceReady, this.finalFlag = e.final, this.logger = t;
289
290
  }
290
291
  // TODO add logging
@@ -303,36 +304,36 @@ class Q {
303
304
  get fields() {
304
305
  return [...this.fieldsMap.values()];
305
306
  }
306
- getField(e, t, r = () => {
307
+ getField(e, t, i = () => {
307
308
  }) {
308
- var s, i, f;
309
- const a = typeof t == "string" ? { field: t } : t, o = this.fieldsMap.get(a.field);
310
- if (o === void 0) {
311
- if (a.errorIfFieldNotFound || a.errorIfFieldNotSet)
309
+ var a, r, f;
310
+ const n = typeof t == "string" ? { field: t } : t, d = this.fieldsMap.get(n.field);
311
+ if (d === void 0) {
312
+ if (n.errorIfFieldNotFound || n.errorIfFieldNotSet)
312
313
  throw new Error(
313
- `Field "${a.field}" not found in resource ${S(this.id)}`
314
+ `Field "${n.field}" not found in resource ${g(this.id)}`
314
315
  );
315
- if (!this.inputsLocked) (s = this.inputAndServiceFieldListChanged) == null || s.attachWatcher(e);
316
- else if (a.assertFieldType === "Service" || a.assertFieldType === "Input") {
317
- if (a.allowPermanentAbsence)
316
+ if (!this.inputsLocked) (a = this.inputAndServiceFieldListChanged) == null || a.attachWatcher(e);
317
+ else if (n.assertFieldType === "Service" || n.assertFieldType === "Input") {
318
+ if (n.allowPermanentAbsence)
318
319
  return;
319
- throw new Error(`Service or input field not found ${a.field}.`);
320
+ throw new Error(`Service or input field not found ${n.field}.`);
320
321
  }
321
- if (!this.outputsLocked) (i = this.outputFieldListChanged) == null || i.attachWatcher(e);
322
- else if (a.assertFieldType === "Output") {
323
- if (a.allowPermanentAbsence)
322
+ if (!this.outputsLocked) (r = this.outputFieldListChanged) == null || r.attachWatcher(e);
323
+ else if (n.assertFieldType === "Output") {
324
+ if (n.allowPermanentAbsence)
324
325
  return;
325
- throw new Error(`Output field not found ${a.field}.`);
326
+ throw new Error(`Output field not found ${n.field}.`);
326
327
  }
327
- (f = this.dynamicFieldListChanged) == null || f.attachWatcher(e), !this._finalState && !a.stableIfNotFound && r("field_not_found:" + a.field);
328
+ (f = this.dynamicFieldListChanged) == null || f.attachWatcher(e), !this._finalState && !n.stableIfNotFound && i("field_not_found:" + n.field);
328
329
  return;
329
330
  } else {
330
- if (a.assertFieldType !== void 0 && o.type !== a.assertFieldType)
331
+ if (n.assertFieldType !== void 0 && d.type !== n.assertFieldType)
331
332
  throw new Error(
332
- `Unexpected field type: expected ${a.assertFieldType} but got ${o.type} for the field name ${a.field}`
333
+ `Unexpected field type: expected ${n.assertFieldType} but got ${d.type} for the field name ${n.field}`
333
334
  );
334
335
  const l = {};
335
- return g(o.value) && (l.value = o.value), g(o.error) && (l.error = o.error), l.value === void 0 && l.error === void 0 && r("field_not_resolved:" + a.field), o.change.attachWatcher(e), l;
336
+ return y(d.value) && (l.value = d.value), y(d.error) && (l.error = d.error), l.value === void 0 && l.error === void 0 && i("field_not_resolved:" + n.field), d.change.attachWatcher(e), l;
336
337
  }
337
338
  }
338
339
  getInputsLocked(e) {
@@ -344,7 +345,7 @@ class Q {
344
345
  return this.outputsLocked || (t = this.resourceStateChange) == null || t.attachWatcher(e), this.outputsLocked;
345
346
  }
346
347
  get isReadyOrError() {
347
- return this.error !== F || this.resourceReady || this.originalResourceId !== F;
348
+ return this.error !== D || this.resourceReady || this.originalResourceId !== D;
348
349
  }
349
350
  getIsFinal(e) {
350
351
  var t;
@@ -356,50 +357,50 @@ class Q {
356
357
  }
357
358
  getError(e) {
358
359
  var t;
359
- if (V(this.error)) {
360
+ if (O(this.error)) {
360
361
  (t = this.resourceStateChange) == null || t.attachWatcher(e);
361
362
  return;
362
363
  } else
363
364
  return this.error;
364
365
  }
365
366
  listInputFields(e) {
366
- var r;
367
+ var i;
367
368
  const t = [];
368
- return this.fieldsMap.forEach((a, o) => {
369
- (a.type === "Input" || a.type === "Service") && t.push(o);
370
- }), this.inputsLocked || (r = this.inputAndServiceFieldListChanged) == null || r.attachWatcher(e), t;
369
+ return this.fieldsMap.forEach((n, d) => {
370
+ (n.type === "Input" || n.type === "Service") && t.push(d);
371
+ }), this.inputsLocked || (i = this.inputAndServiceFieldListChanged) == null || i.attachWatcher(e), t;
371
372
  }
372
373
  listOutputFields(e) {
373
- var r;
374
+ var i;
374
375
  const t = [];
375
- return this.fieldsMap.forEach((a, o) => {
376
- a.type === "Output" && t.push(o);
377
- }), this.outputsLocked || (r = this.outputFieldListChanged) == null || r.attachWatcher(e), t;
376
+ return this.fieldsMap.forEach((n, d) => {
377
+ n.type === "Output" && t.push(d);
378
+ }), this.outputsLocked || (i = this.outputFieldListChanged) == null || i.attachWatcher(e), t;
378
379
  }
379
380
  listDynamicFields(e) {
380
- var r;
381
+ var i;
381
382
  const t = [];
382
- return this.fieldsMap.forEach((a, o) => {
383
- a.type !== "Input" && a.type !== "Output" && t.push(o);
384
- }), (r = this.dynamicFieldListChanged) == null || r.attachWatcher(e), t;
383
+ return this.fieldsMap.forEach((n, d) => {
384
+ n.type !== "Input" && n.type !== "Output" && t.push(d);
385
+ }), (i = this.dynamicFieldListChanged) == null || i.attachWatcher(e), t;
385
386
  }
386
387
  getKeyValue(e, t) {
387
- var r;
388
- return (r = this.kvChanged) == null || r.attachWatcher(e), this.kv.get(t);
388
+ var i;
389
+ return (i = this.kvChangedPerKey) == null || i.attachWatcher(t, e), this.kv.get(t);
389
390
  }
390
391
  getKeyValueString(e, t) {
391
- const r = this.getKeyValue(e, t);
392
- if (r !== void 0)
393
- return $(r);
392
+ const i = this.getKeyValue(e, t);
393
+ if (i !== void 0)
394
+ return A(i);
394
395
  }
395
396
  getKeyValueAsJson(e, t) {
396
- const r = this.getKeyValue(e, t);
397
- if (r !== void 0)
398
- return b(r);
397
+ const i = this.getKeyValue(e, t);
398
+ if (i !== void 0)
399
+ return b(i);
399
400
  }
400
401
  getDataAsString() {
401
402
  if (this.data !== void 0)
402
- return this.dataAsString === void 0 && (this.dataAsString = $(this.data)), this.dataAsString;
403
+ return this.dataAsString === void 0 && (this.dataAsString = A(this.data)), this.dataAsString;
403
404
  }
404
405
  getDataAsJson() {
405
406
  if (this.data !== void 0)
@@ -407,7 +408,7 @@ class Q {
407
408
  }
408
409
  verifyReadyState() {
409
410
  if (this.resourceReady && !this.inputsLocked)
410
- throw new Error(`ready without input or output lock: ${L(this.basicState)}`);
411
+ throw new Error(`ready without input or output lock: ${F(this.basicState)}`);
411
412
  }
412
413
  get basicState() {
413
414
  return {
@@ -432,23 +433,23 @@ class Q {
432
433
  }
433
434
  /** Called when {@link FinalResourceDataPredicate} returns true for the state. */
434
435
  markFinal() {
435
- 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);
436
+ this._finalState || (this._finalState = !0, p(this.finalChanged).markChanged("marked final"), this.finalChanged = void 0, this.resourceStateChange = void 0, this.dynamicFieldListChanged = void 0, this.inputAndServiceFieldListChanged = void 0, this.outputFieldListChanged = void 0, this.lockedChange = void 0, this.kvChangedPerKey = void 0);
436
437
  }
437
438
  /** Used for invalidation */
438
439
  markAllChanged() {
439
- var e, t, r, a, o, s, i;
440
- 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(), (a = this.inputAndServiceFieldListChanged) == null || a.markChanged(), (o = this.outputFieldListChanged) == null || o.markChanged(), (s = this.dynamicFieldListChanged) == null || s.markChanged(), (i = this.kvChanged) == null || i.markChanged(), this.resourceRemoved.markChanged();
440
+ var e, t, i, n, d, a, r;
441
+ this.fieldsMap.forEach((f) => f.change.markChanged("marked all changed")), (e = this.finalChanged) == null || e.markChanged("marked all changed"), (t = this.resourceStateChange) == null || t.markChanged("marked all changed"), (i = this.lockedChange) == null || i.markChanged("marked all changed"), (n = this.inputAndServiceFieldListChanged) == null || n.markChanged("marked all changed"), (d = this.outputFieldListChanged) == null || d.markChanged("marked all changed"), (a = this.dynamicFieldListChanged) == null || a.markChanged("marked all changed"), (r = this.kvChangedPerKey) == null || r.markAllChanged("marked all changed"), this.resourceRemoved.markChanged("marked all changed");
441
442
  }
442
443
  }
443
- class O {
444
+ class P {
444
445
  constructor(e, t) {
445
446
  /** resource heap */
446
- d(this, "resources", /* @__PURE__ */ new Map());
447
- d(this, "resourcesAdded", new m());
447
+ u(this, "resources", /* @__PURE__ */ new Map());
448
+ u(this, "resourcesAdded", new C());
448
449
  /** Resets to false if any invalid state transitions are registered,
449
450
  * after that tree will produce errors for any read or write operations */
450
- d(this, "_isValid", !0);
451
- d(this, "invalidationMessage");
451
+ u(this, "_isValid", !0);
452
+ u(this, "invalidationMessage");
452
453
  this.root = e, this.isFinalPredicate = t;
453
454
  }
454
455
  forEachResource(e) {
@@ -459,109 +460,108 @@ class O {
459
460
  }
460
461
  get(e, t) {
461
462
  this.checkValid();
462
- const r = this.resources.get(t);
463
- if (r === void 0)
464
- throw this.resourcesAdded.attachWatcher(e), new Error(`resource ${S(t)} not found in the tree`);
465
- return r.resourceRemoved.attachWatcher(e), r;
463
+ const i = this.resources.get(t);
464
+ if (i === void 0)
465
+ throw this.resourcesAdded.attachWatcher(e), new Error(`resource ${g(t)} not found in the tree`);
466
+ return i.resourceRemoved.attachWatcher(e), i;
466
467
  }
467
468
  updateFromResourceData(e, t = !1) {
468
469
  this.checkValid();
469
- const r = [], a = [];
470
- for (const s of e) {
471
- let i = this.resources.get(s.id);
472
- const f = i == null ? void 0 : i.basicState, l = (h) => {
473
- const { fields: k, ...u } = s;
474
- throw this.invalidateTree(), new R(
475
- `Unexpected resource state transition (${h}): ${L(
476
- u
477
- )} -> ${L(f)}`
470
+ const i = [], n = [];
471
+ for (const a of e) {
472
+ let r = this.resources.get(a.id);
473
+ const f = r == null ? void 0 : r.basicState, l = (h) => {
474
+ const { fields: s, ...c } = a;
475
+ throw this.invalidateTree(), new S(
476
+ `Unexpected resource state transition (${h}): ${F(
477
+ c
478
+ )} -> ${F(f)}`
478
479
  );
479
480
  };
480
- if (i !== void 0) {
481
- i.finalState && l("resource state can be updated after it is marked as final");
481
+ if (r !== void 0) {
482
+ r.finalState && l("resource state can be updated after it is marked as final");
482
483
  let h = !1;
483
- i.version += 1, i.originalResourceId !== s.originalResourceId && (i.originalResourceId !== F && l("originalResourceId can't change after it is set"), i.originalResourceId = s.originalResourceId, p(i.resourceStateChange).markChanged(), h = !0), i.error !== s.error && (g(i.error) && l("resource can't change attached error after it is set"), i.error = s.error, r.push(i.error), p(i.resourceStateChange).markChanged(), h = !0);
484
- for (const u of s.fields) {
485
- let c = i.fieldsMap.get(u.name);
486
- 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(
487
- `adding input field "${u.name}", while corresponding list is locked`
488
- ), p(i.inputAndServiceFieldListChanged).markChanged()), c.type === "Output" && (i.outputsLocked && l(
489
- `adding output field "${u.name}", while corresponding list is locked`
490
- ), p(i.outputFieldListChanged).markChanged()), c.type = u.type, c.change.markChanged(), h = !0), c.value !== u.value && (g(c.value) && a.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) && a.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 x(
491
- u.name,
492
- u.type,
493
- u.value,
494
- u.error,
495
- u.status,
496
- u.valueIsFinal,
497
- i.version
498
- ), g(u.value) && r.push(u.value), g(u.error) && r.push(u.error), u.type === "Input" || u.type === "Service" ? (i.inputsLocked && l(
499
- `adding ${u.type} (${u.name}) field while inputs locked`
500
- ), p(i.inputAndServiceFieldListChanged).markChanged()) : u.type === "Output" ? (i.outputsLocked && l(
501
- `adding ${u.type} (${u.name}) field while outputs locked`
502
- ), p(i.outputFieldListChanged).markChanged()) : p(i.dynamicFieldListChanged).markChanged(), i.fieldsMap.set(u.name, c), h = !0);
484
+ 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(`originalResourceId changed for ${g(r.id)}`), h = !0), r.error !== a.error && (y(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(`error changed for ${g(r.id)}`), h = !0);
485
+ for (const s of a.fields) {
486
+ let c = r.fieldsMap.get(s.name);
487
+ c ? (c.type !== s.type && (c.type !== "Dynamic" && l(`field changed type ${c.type} -> ${s.type}`), p(r.dynamicFieldListChanged).markChanged(`field ${s.name} changed type from Dynamic to ${s.type} in ${g(r.id)}`), (c.type === "Input" || c.type === "Service") && (r.inputsLocked && l(
488
+ `adding input field "${s.name}", while corresponding list is locked`
489
+ ), p(r.inputAndServiceFieldListChanged).markChanged(`field ${s.name} changed to type ${s.type} in ${g(r.id)}`)), c.type === "Output" && (r.outputsLocked && l(
490
+ `adding output field "${s.name}", while corresponding list is locked`
491
+ ), p(r.outputFieldListChanged).markChanged(`field ${s.name} changed to type ${s.type} in ${g(r.id)}`)), c.type = s.type, c.change.markChanged(`field ${s.name} type changed to ${s.type} in ${g(r.id)}`), h = !0), c.value !== s.value && (y(c.value) && n.push(c.value), c.value = s.value, y(s.value) && i.push(s.value), c.change.markChanged(`field ${s.name} value changed in ${g(r.id)}`), h = !0), c.error !== s.error && (y(c.error) && n.push(c.error), c.error = s.error, y(s.error) && i.push(s.error), c.change.markChanged(`field ${s.name} error changed in ${g(r.id)}`), h = !0), c.status !== s.status && (c.status = s.status, c.change.markChanged(`field ${s.name} status changed to ${s.status} in ${g(r.id)}`), h = !0), c.valueIsFinal !== s.valueIsFinal && (c.valueIsFinal = s.valueIsFinal, c.change.markChanged(`field ${s.name} valueIsFinal changed to ${s.valueIsFinal} in ${g(r.id)}`), h = !0), c.resourceVersion = r.version) : (c = new x(
492
+ s.name,
493
+ s.type,
494
+ s.value,
495
+ s.error,
496
+ s.status,
497
+ s.valueIsFinal,
498
+ r.version
499
+ ), y(s.value) && i.push(s.value), y(s.error) && i.push(s.error), s.type === "Input" || s.type === "Service" ? (r.inputsLocked && l(
500
+ `adding ${s.type} (${s.name}) field while inputs locked`
501
+ ), p(r.inputAndServiceFieldListChanged).markChanged(`new ${s.type} field ${s.name} added to ${g(r.id)}`)) : s.type === "Output" ? (r.outputsLocked && l(
502
+ `adding ${s.type} (${s.name}) field while outputs locked`
503
+ ), p(r.outputFieldListChanged).markChanged(`new ${s.type} field ${s.name} added to ${g(r.id)}`)) : p(r.dynamicFieldListChanged).markChanged(`new ${s.type} field ${s.name} added to ${g(r.id)}`), r.fieldsMap.set(s.name, c), h = !0);
503
504
  }
504
- if (i.fieldsMap.forEach((u, c, v) => {
505
- 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) && a.push(u.value), g(u.error) && a.push(u.error), p(i.dynamicFieldListChanged).markChanged());
506
- }), i.inputsLocked !== s.inputsLocked && (i.inputsLocked && l("inputs unlocking is not permitted"), i.inputsLocked = s.inputsLocked, p(i.lockedChange).markChanged(), h = !0), i.outputsLocked !== s.outputsLocked && (i.outputsLocked && l("outputs unlocking is not permitted"), i.outputsLocked = s.outputsLocked, p(i.lockedChange).markChanged(), h = !0), i.resourceReady !== s.resourceReady) {
507
- const u = i.resourceReady;
508
- i.resourceReady = s.resourceReady, i.verifyReadyState(), i.isReadyOrError || l(
509
- `resource can't lose it's ready or error state (ready state before ${u})`
510
- ), p(i.resourceStateChange).markChanged(), h = !0;
505
+ if (r.fieldsMap.forEach((s, c, m) => {
506
+ s.resourceVersion !== r.version && ((s.type === "Input" || s.type === "Service" || s.type === "Output") && l(`removal of ${s.type} field ${c}`), s.change.markChanged(`dynamic field ${c} removed from ${g(r.id)}`), m.delete(c), y(s.value) && n.push(s.value), y(s.error) && n.push(s.error), p(r.dynamicFieldListChanged).markChanged(`dynamic field ${c} removed from ${g(r.id)}`));
507
+ }), r.inputsLocked !== a.inputsLocked && (r.inputsLocked && l("inputs unlocking is not permitted"), r.inputsLocked = a.inputsLocked, p(r.lockedChange).markChanged(`inputs locked for ${g(r.id)}`), h = !0), r.outputsLocked !== a.outputsLocked && (r.outputsLocked && l("outputs unlocking is not permitted"), r.outputsLocked = a.outputsLocked, p(r.lockedChange).markChanged(`outputs locked for ${g(r.id)}`), h = !0), r.resourceReady !== a.resourceReady) {
508
+ const s = r.resourceReady;
509
+ r.resourceReady = a.resourceReady, r.verifyReadyState(), r.isReadyOrError || l(
510
+ `resource can't lose it's ready or error state (ready state before ${s})`
511
+ ), p(r.resourceStateChange).markChanged(`ready flag changed to ${a.resourceReady} for ${g(r.id)}`), h = !0;
511
512
  }
512
- let k = !1;
513
- for (const u of s.kv) {
514
- const c = i.kv.get(u.key);
515
- (c === void 0 || Buffer.compare(c, u.value) !== 0) && (i.kv.set(u.key, u.value), k = !0);
513
+ for (const s of a.kv) {
514
+ const c = r.kv.get(s.key);
515
+ c === void 0 ? (r.kv.set(s.key, s.value), p(r.kvChangedPerKey).markChanged(s.key, `kv added for ${g(r.id)}: ${s.key}`)) : Buffer.compare(c, s.value) !== 0 && (r.kv.set(s.key, s.value), p(r.kvChangedPerKey).markChanged(s.key, `kv changed for ${g(r.id)}: ${s.key}`));
516
516
  }
517
- if (i.kv.size > s.kv.length) {
518
- const u = new Set(s.kv.map((c) => c.key));
519
- i.kv.forEach((c, v, y) => {
520
- u.has(v) || y.delete(v);
521
- }), k = !0;
517
+ if (r.kv.size > a.kv.length) {
518
+ const s = new Set(a.kv.map((c) => c.key));
519
+ r.kv.forEach((c, m, k) => {
520
+ s.has(m) || (k.delete(m), p(r.kvChangedPerKey).markChanged(m, `kv deleted for ${g(r.id)}: ${m}`));
521
+ });
522
522
  }
523
- k && p(i.kvChanged).markChanged(), h && (i.dataVersion = i.version, this.isFinalPredicate(i) && i.markFinal());
523
+ h && (r.dataVersion = r.version, this.isFinalPredicate(r) && r.markFinal());
524
524
  } else {
525
- i = new Q(s), i.verifyReadyState(), g(i.error) && r.push(i.error);
526
- for (const h of s.fields) {
527
- const k = new x(
525
+ r = new X(a), r.verifyReadyState(), y(r.error) && i.push(r.error);
526
+ for (const h of a.fields) {
527
+ const s = new x(
528
528
  h.name,
529
529
  h.type,
530
530
  h.value,
531
531
  h.error,
532
532
  h.status,
533
533
  h.valueIsFinal,
534
- T
534
+ L
535
535
  );
536
- g(h.value) && r.push(h.value), g(h.error) && r.push(h.error), i.fieldsMap.set(h.name, k);
536
+ y(h.value) && i.push(h.value), y(h.error) && i.push(h.error), r.fieldsMap.set(h.name, s);
537
537
  }
538
- for (const h of s.kv) i.kv.set(h.key, h.value);
539
- this.isFinalPredicate(i) && i.markFinal(), this.resources.set(i.id, i), this.resourcesAdded.markChanged();
538
+ for (const h of a.kv) r.kv.set(h.key, h.value);
539
+ this.isFinalPredicate(r) && r.markFinal(), this.resources.set(r.id, r), this.resourcesAdded.markChanged(`new resource ${g(r.id)} added`);
540
540
  }
541
541
  }
542
- for (const s of r) {
543
- const i = this.resources.get(s);
544
- if (!i)
545
- throw this.invalidateTree(), new R(`orphan resource ${s}`);
546
- i.refCount++;
542
+ for (const a of i) {
543
+ const r = this.resources.get(a);
544
+ if (!r)
545
+ throw this.invalidateTree(), new S(`orphan resource ${a}`);
546
+ r.refCount++;
547
547
  }
548
- let o = a;
549
- for (; o.length > 0; ) {
550
- const s = [];
551
- for (const i of o) {
552
- const f = this.resources.get(i);
548
+ let d = n;
549
+ for (; d.length > 0; ) {
550
+ const a = [];
551
+ for (const r of d) {
552
+ const f = this.resources.get(r);
553
553
  if (!f)
554
- throw this.invalidateTree(), new R(`orphan resource ${i}`);
554
+ throw this.invalidateTree(), new S(`orphan resource ${r}`);
555
555
  f.refCount--, f.refCount === 0 && f.id !== this.root && (f.fieldsMap.forEach((l) => {
556
- g(l.value) && s.push(l.value), g(l.error) && s.push(l.error), l.change.markChanged();
557
- }), g(f.error) && s.push(f.error), f.resourceRemoved.markChanged(), this.resources.delete(i));
556
+ y(l.value) && a.push(l.value), y(l.error) && a.push(l.error), l.change.markChanged(`field ${l.name} removed during garbage collection of ${g(f.id)}`);
557
+ }), y(f.error) && a.push(f.error), f.resourceRemoved.markChanged(`resource removed during garbage collection: ${g(f.id)}`), this.resources.delete(r));
558
558
  }
559
- o = s;
559
+ d = a;
560
560
  }
561
561
  if (!t) {
562
- for (const s of e)
563
- if (!this.resources.has(s.id))
564
- throw this.invalidateTree(), new R(`orphan input resource ${s.id}`);
562
+ for (const a of e)
563
+ if (!this.resources.has(a.id))
564
+ throw this.invalidateTree(), new S(`orphan input resource ${a.id}`);
565
565
  }
566
566
  }
567
567
  /** @deprecated use "entry" instead */
@@ -569,7 +569,7 @@ class O {
569
569
  return this.checkValid(), this.entry(e);
570
570
  }
571
571
  entry(e = this.root) {
572
- return this.checkValid(), new C({ treeProvider: () => this }, e);
572
+ return this.checkValid(), new R({ treeProvider: () => this }, e);
573
573
  }
574
574
  invalidateTree(e) {
575
575
  this._isValid = !1, this.invalidationMessage = e, this.resources.forEach((t) => {
@@ -580,13 +580,13 @@ class O {
580
580
  return Array.from(this.resources.values()).map((e) => e.extendedState);
581
581
  }
582
582
  }
583
- function X(n, e) {
584
- const t = [], r = /* @__PURE__ */ new Set();
585
- return n.forEachResource((a) => {
586
- a.finalState ? r.add(a.id) : t.push(a.id);
587
- }), t.length === 0 && r.size === 0 && t.push(n.root), { seedResources: t, finalResources: r, pruningFunction: e };
583
+ function Z(o, e) {
584
+ const t = [], i = /* @__PURE__ */ new Set();
585
+ return o.forEachResource((n) => {
586
+ n.finalState ? i.add(n.id) : t.push(n.id);
587
+ }), t.length === 0 && i.size === 0 && t.push(o.root), { seedResources: t, finalResources: i, pruningFunction: e };
588
588
  }
589
- function D() {
589
+ function $() {
590
590
  return {
591
591
  requests: 0,
592
592
  roundTrips: 0,
@@ -600,144 +600,144 @@ function D() {
600
600
  millisSpent: 0
601
601
  };
602
602
  }
603
- function le(n) {
604
- let e = `Requests: ${n.requests}
603
+ function fe(o) {
604
+ let e = `Requests: ${o.requests}
605
605
  `;
606
- return e += `Total time: ${H(n.millisSpent)}
607
- `, e += `Round-trips: ${n.roundTrips}
608
- `, e += `Resources: ${n.retrievedResources}
609
- `, e += `Fields: ${n.retrievedFields}
610
- `, e += `KV: ${n.retrievedKeyValues}
611
- `, e += `Data Bytes: ${n.retrievedResourceDataBytes}
612
- `, e += `KV Bytes: ${n.retrievedKeyValueBytes}
613
- `, e += `Pruned fields: ${n.prunedFields}
614
- `, e += `Final resources skipped: ${n.finalResourcesSkipped}`, e;
606
+ return e += `Total time: ${j(o.millisSpent)}
607
+ `, e += `Round-trips: ${o.roundTrips}
608
+ `, e += `Resources: ${o.retrievedResources}
609
+ `, e += `Fields: ${o.retrievedFields}
610
+ `, e += `KV: ${o.retrievedKeyValues}
611
+ `, e += `Data Bytes: ${o.retrievedResourceDataBytes}
612
+ `, e += `KV Bytes: ${o.retrievedKeyValueBytes}
613
+ `, e += `Pruned fields: ${o.prunedFields}
614
+ `, e += `Final resources skipped: ${o.finalResourcesSkipped}`, e;
615
615
  }
616
- async function Z(n, e, t) {
617
- var c;
618
- const r = Date.now();
616
+ async function ee(o, e, t) {
617
+ var m;
618
+ const i = Date.now();
619
619
  t && t.requests++;
620
- const { seedResources: a, finalResources: o, pruningFunction: s } = e, i = new j();
620
+ const { seedResources: n, finalResources: d, pruningFunction: a } = e, r = new Y();
621
621
  let f = !0, l = 0;
622
- const h = /* @__PURE__ */ new Set(), k = (v) => {
623
- if (V(v) || h.has(v)) return;
624
- if (o.has(v)) {
622
+ const h = /* @__PURE__ */ new Set(), s = (k) => {
623
+ if (O(k) || h.has(k)) return;
624
+ if (d.has(k)) {
625
625
  t && t.finalResourcesSkipped++;
626
626
  return;
627
627
  }
628
- h.add(v);
629
- const y = n.getResourceDataIfExists(v, !0), w = n.listKeyValuesIfResourceExists(v), W = f;
630
- f && (f = !1), i.push(
628
+ h.add(k);
629
+ const v = o.getResourceDataIfExists(k, !0), w = o.listKeyValuesIfResourceExists(k), W = f;
630
+ f && (f = !1), r.push(
631
631
  (async () => {
632
- const [I, _] = await Promise.all([y, w]);
632
+ const [I, E] = await Promise.all([v, w]);
633
633
  if (W && (l++, f = !0), I !== void 0) {
634
- if (_ === void 0) throw new Error("Inconsistent replies");
635
- return { ...I, kv: _ };
634
+ if (E === void 0) throw new Error("Inconsistent replies");
635
+ return { ...I, kv: E };
636
636
  }
637
637
  })()
638
638
  );
639
639
  };
640
- a.forEach((v) => k(v));
641
- const u = [];
640
+ n.forEach((k) => s(k));
641
+ const c = [];
642
642
  for (; ; ) {
643
- const v = i.shift();
644
- if (v === void 0)
643
+ const k = r.shift();
644
+ if (k === void 0)
645
645
  break;
646
- let y = await v;
647
- if (y !== void 0) {
648
- if (s !== void 0) {
649
- const w = s(y);
650
- t && (t.prunedFields += y.fields.length - w.length), y = { ...y, fields: w };
646
+ let v = await k;
647
+ if (v !== void 0) {
648
+ if (a !== void 0) {
649
+ const w = a(v);
650
+ t && (t.prunedFields += v.fields.length - w.length), v = { ...v, fields: w };
651
651
  }
652
- k(y.error);
653
- for (const w of y.fields)
654
- k(w.value), k(w.error);
652
+ s(v.error);
653
+ for (const w of v.fields)
654
+ s(w.value), s(w.error);
655
655
  if (t) {
656
- t.retrievedResources++, t.retrievedFields += y.fields.length, t.retrievedKeyValues += y.kv.length, t.retrievedResourceDataBytes += ((c = y.data) == null ? void 0 : c.length) ?? 0;
657
- for (const w of y.kv) t.retrievedKeyValueBytes += w.value.length;
656
+ t.retrievedResources++, t.retrievedFields += v.fields.length, t.retrievedKeyValues += v.kv.length, t.retrievedResourceDataBytes += ((m = v.data) == null ? void 0 : m.length) ?? 0;
657
+ for (const w of v.kv) t.retrievedKeyValueBytes += w.value.length;
658
658
  }
659
- u.push(y);
659
+ c.push(v);
660
660
  }
661
661
  }
662
- return t && (t.millisSpent += Date.now() - r, t.roundTrips += l), u;
662
+ return t && (t.millisSpent += Date.now() - i, t.roundTrips += l), c;
663
663
  }
664
- function fe(n) {
665
- return n;
664
+ function ge(o) {
665
+ return o;
666
666
  }
667
- function ge(n, e, t) {
668
- var s;
669
- const r = n instanceof C ? p(t).accessor(n).node() : n instanceof E ? n.node() : n, o = { ...r.resourceInfo };
670
- if (e.data !== void 0 && (e.data === "raw" ? o.data = r.getData() : o.data = e.data.parse(r.getDataAsJson())), e.fields !== void 0) {
671
- const i = {};
667
+ function pe(o, e, t) {
668
+ var a;
669
+ const i = o instanceof R ? p(t).accessor(o).node() : o instanceof T ? o.node() : o, d = { ...i.resourceInfo };
670
+ if (e.data !== void 0 && (e.data === "raw" ? d.data = i.getData() : d.data = e.data.parse(i.getDataAsJson())), e.fields !== void 0) {
671
+ const r = {};
672
672
  for (const [f, l] of Object.entries(e.fields))
673
- i[f] = (s = r.traverse({
673
+ r[f] = (a = i.traverse({
674
674
  field: f,
675
675
  errorIfFieldNotSet: l,
676
676
  stableIfNotFound: !l
677
- })) == null ? void 0 : s.id;
678
- o.fields = i;
677
+ })) == null ? void 0 : a.id;
678
+ d.fields = r;
679
679
  }
680
680
  if (e.kv !== void 0) {
681
- const i = {};
681
+ const r = {};
682
682
  for (const [f, l] of Object.entries(e.kv)) {
683
- const h = r.getKeyValue(f);
683
+ const h = i.getKeyValue(f);
684
684
  if (h === void 0)
685
685
  throw new Error(`Key not found ${f}`);
686
- l === "raw" ? i[f] = h : i[f] = l.parse(JSON.parse(Buffer.from(h).toString("utf-8")));
686
+ l === "raw" ? r[f] = h : r[f] = l.parse(JSON.parse(Buffer.from(h).toString("utf-8")));
687
687
  }
688
- o.kv = i;
688
+ d.kv = r;
689
689
  }
690
- return o;
690
+ return d;
691
691
  }
692
- function pe(n, e, t) {
693
- if (n instanceof C) {
694
- const r = t.accessor(n).node(), a = r.resourceInfo, o = e.map((s) => {
695
- var i, f;
692
+ function ye(o, e, t) {
693
+ if (o instanceof R) {
694
+ const i = t.accessor(o).node(), n = i.resourceInfo, d = e.map((a) => {
695
+ var r, f;
696
696
  return [
697
- s,
698
- (f = (i = r.getField(s)) == null ? void 0 : i.value) == null ? void 0 : f.id
697
+ a,
698
+ (f = (r = i.getField(a)) == null ? void 0 : r.value) == null ? void 0 : f.id
699
699
  ];
700
700
  });
701
701
  return {
702
- ...a,
703
- fields: new Map(o),
704
- data: r.getData() ?? new Uint8Array()
702
+ ...n,
703
+ fields: new Map(d),
704
+ data: i.getData() ?? new Uint8Array()
705
705
  };
706
706
  }
707
- return n;
707
+ return o;
708
708
  }
709
- function ve(n, e, t) {
710
- if (!(n instanceof C)) return n;
711
- const r = t.accessor(n).node(), a = r.resourceInfo, o = e.map((s) => [s, r.getKeyValue(s)]);
709
+ function ve(o, e, t) {
710
+ if (!(o instanceof R)) return o;
711
+ const i = t.accessor(o).node(), n = i.resourceInfo, d = e.map((a) => [a, i.getKeyValue(a)]);
712
712
  return {
713
- ...a,
714
- metadata: Object.fromEntries(o)
713
+ ...n,
714
+ metadata: Object.fromEntries(d)
715
715
  };
716
716
  }
717
717
  class B {
718
- constructor(e, t, r, a) {
719
- d(this, "finalPredicate");
720
- d(this, "state");
721
- d(this, "pollingInterval");
722
- d(this, "pruning");
723
- d(this, "logStat");
724
- d(this, "hooks");
725
- d(this, "abortController", new AbortController());
726
- d(this, "currentLoopDelayInterrupt");
727
- d(this, "scheduledOnNextState", []);
718
+ constructor(e, t, i, n) {
719
+ u(this, "finalPredicate");
720
+ u(this, "state");
721
+ u(this, "pollingInterval");
722
+ u(this, "pruning");
723
+ u(this, "logStat");
724
+ u(this, "hooks");
725
+ u(this, "abortController", new AbortController());
726
+ u(this, "currentLoopDelayInterrupt");
727
+ u(this, "scheduledOnNextState", []);
728
728
  /** If true, main loop will continue polling pl state. */
729
- d(this, "keepRunning", !1);
729
+ u(this, "keepRunning", !1);
730
730
  /** Actual state of main loop. */
731
- d(this, "currentLoop");
731
+ u(this, "currentLoop");
732
732
  /** If true this tree state is permanently terminaed. */
733
- d(this, "terminated", !1);
734
- this.pl = e, this.root = t, this.logger = a;
735
- const { finalPredicateOverride: o, pruning: s, pollingInterval: i, stopPollingDelay: f, logStat: l } = r;
736
- this.pruning = s, this.pollingInterval = i, this.finalPredicate = o ?? e.finalPredicate, this.logStat = l, this.state = new O(t, this.finalPredicate), this.hooks = new z(
733
+ u(this, "terminated", !1);
734
+ this.pl = e, this.root = t, this.logger = n;
735
+ const { finalPredicateOverride: d, pruning: a, pollingInterval: r, stopPollingDelay: f, logStat: l } = i;
736
+ this.pruning = a, this.pollingInterval = r, this.finalPredicate = d ?? e.finalPredicate, this.logStat = l, this.state = new P(t, this.finalPredicate), this.hooks = new H(
737
737
  () => this.startUpdating(),
738
738
  () => this.stopUpdating(),
739
739
  { stopDebounce: f },
740
- (h, k) => this.scheduleOnNextState(h, k)
740
+ (h, s) => this.scheduleOnNextState(h, s)
741
741
  );
742
742
  }
743
743
  /** @deprecated use "entry" instead */
@@ -747,7 +747,7 @@ class B {
747
747
  }
748
748
  entry(e = this.root) {
749
749
  if (this.terminated) throw new Error("tree synchronization is terminated");
750
- return new C({ treeProvider: () => this.state, hooks: this.hooks }, e);
750
+ return new R({ treeProvider: () => this.state, hooks: this.hooks }, e);
751
751
  }
752
752
  /** Can be used to externally kick off the synchronization polling loop, and
753
753
  * await for the first synchronization to happen. */
@@ -770,33 +770,33 @@ class B {
770
770
  /** Executed from the main loop, and initialization procedure. */
771
771
  async refresh(e, t) {
772
772
  if (this.terminated) throw new Error("tree synchronization is terminated");
773
- const r = X(this.state, this.pruning), a = await this.pl.withReadTx("ReadingTree", async (o) => await Z(o, r, e), t);
774
- this.state.updateFromResourceData(a, !0);
773
+ const i = Z(this.state, this.pruning), n = await this.pl.withReadTx("ReadingTree", async (d) => await ee(d, i, e), t);
774
+ this.state.updateFromResourceData(n, !0);
775
775
  }
776
776
  async mainLoop() {
777
- var r, a;
778
- let e = this.logStat ? D() : void 0, t = Date.now();
777
+ var i, n;
778
+ let e = this.logStat ? $() : void 0, t = Date.now();
779
779
  for (; !(!this.keepRunning || this.terminated); ) {
780
- let o;
781
- this.scheduledOnNextState.length > 0 && (o = this.scheduledOnNextState, this.scheduledOnNextState = []);
780
+ let d;
781
+ this.scheduledOnNextState.length > 0 && (d = this.scheduledOnNextState, this.scheduledOnNextState = []);
782
782
  try {
783
- if (this.logStat === "per-request" && (e = D()), await this.refresh(e), e && this.logger && this.logger.info(`Tree stat (success, after ${Date.now() - t}ms): ${JSON.stringify(e)}`), t = Date.now(), o !== void 0) for (const s of o) s.resolve();
784
- } catch (s) {
785
- if (e && this.logger && this.logger.info(`Tree stat (error, after ${Date.now() - t}ms): ${JSON.stringify(e)}`), t = Date.now(), o !== void 0) for (const i of o) i.reject(s);
786
- if (s instanceof R) {
787
- (r = this.logger) == null || r.error(s), this.state.invalidateTree("stat update error"), this.state = new O(this.root, this.finalPredicate);
783
+ if (this.logStat === "per-request" && (e = $()), await this.refresh(e), e && this.logger && this.logger.info(`Tree stat (success, after ${Date.now() - t}ms): ${JSON.stringify(e)}`), t = Date.now(), d !== void 0) for (const a of d) a.resolve();
784
+ } catch (a) {
785
+ if (e && this.logger && this.logger.info(`Tree stat (error, after ${Date.now() - t}ms): ${JSON.stringify(e)}`), t = Date.now(), d !== void 0) for (const r of d) r.reject(a);
786
+ if (a instanceof S) {
787
+ (i = this.logger) == null || i.error(a), this.state.invalidateTree("stat update error"), this.state = new P(this.root, this.finalPredicate);
788
788
  continue;
789
- } else (a = this.logger) == null || a.warn(s);
789
+ } else (n = this.logger) == null || n.warn(a);
790
790
  }
791
791
  if (!this.keepRunning || this.terminated) break;
792
792
  if (this.scheduledOnNextState.length === 0)
793
793
  try {
794
- this.currentLoopDelayInterrupt = new AbortController(), await Y.setTimeout(
794
+ this.currentLoopDelayInterrupt = new AbortController(), await G.setTimeout(
795
795
  this.pollingInterval,
796
796
  AbortSignal.any([this.abortController.signal, this.currentLoopDelayInterrupt.signal])
797
797
  );
798
- } catch (s) {
799
- if (!q(s)) throw new Error("Unexpected error", { cause: s });
798
+ } catch (a) {
799
+ if (!q(a)) throw new Error("Unexpected error", { cause: a });
800
800
  break;
801
801
  } finally {
802
802
  this.currentLoopDelayInterrupt = void 0;
@@ -822,22 +822,22 @@ class B {
822
822
  async awaitSyncLoopTermination() {
823
823
  this.currentLoop !== void 0 && await this.currentLoop;
824
824
  }
825
- static async init(e, t, r, a) {
826
- const o = new B(e, t, r, a), s = r.logStat ? D() : void 0;
827
- let i = !1;
825
+ static async init(e, t, i, n) {
826
+ const d = new B(e, t, i, n), a = i.logStat ? $() : void 0;
827
+ let r = !1;
828
828
  try {
829
- await o.refresh(s, {
830
- timeout: r.initialTreeLoadingTimeout
831
- }), i = !0;
829
+ await d.refresh(a, {
830
+ timeout: i.initialTreeLoadingTimeout
831
+ }), r = !0;
832
832
  } finally {
833
- s && a && a.info(
834
- `Tree stat (initial load, ${i ? "success" : "failure"}): ${JSON.stringify(s)}`
833
+ a && n && n.info(
834
+ `Tree stat (initial load, ${r ? "success" : "failure"}): ${JSON.stringify(a)}`
835
835
  );
836
836
  }
837
- return o;
837
+ return d;
838
838
  }
839
839
  }
840
- function ye(n) {
840
+ function ke(o) {
841
841
  var t;
842
842
  const e = {
843
843
  total: {
@@ -850,9 +850,9 @@ function ye(n) {
850
850
  },
851
851
  byResourceType: {}
852
852
  };
853
- for (const r of n) {
854
- const a = `${r.type.name}/${r.type.version}`;
855
- e.byResourceType[a] || (e.byResourceType[a] = {
853
+ for (const i of o) {
854
+ const n = `${i.type.name}/${i.type.version}`;
855
+ e.byResourceType[n] || (e.byResourceType[n] = {
856
856
  count: 0,
857
857
  fieldNameBytes: 0,
858
858
  fieldsCount: 0,
@@ -860,45 +860,45 @@ function ye(n) {
860
860
  kvCount: 0,
861
861
  kvBytes: 0
862
862
  });
863
- const o = e.byResourceType[a];
864
- o.count++, e.total.count++;
865
- for (const s of r.fields)
866
- o.fieldNameBytes += s.name.length, o.fieldsCount++, e.total.fieldNameBytes += s.name.length, e.total.fieldsCount++;
867
- if (r.data) {
868
- const s = ((t = r.data) == null ? void 0 : t.length) ?? 0;
869
- o.dataBytes += s, e.total.dataBytes += s;
863
+ const d = e.byResourceType[n];
864
+ d.count++, e.total.count++;
865
+ for (const a of i.fields)
866
+ d.fieldNameBytes += a.name.length, d.fieldsCount++, e.total.fieldNameBytes += a.name.length, e.total.fieldsCount++;
867
+ if (i.data) {
868
+ const a = ((t = i.data) == null ? void 0 : t.length) ?? 0;
869
+ d.dataBytes += a, e.total.dataBytes += a;
870
870
  }
871
- o.kvCount += r.kv.length, e.total.kvCount += r.kv.length;
872
- for (const s of r.kv) {
873
- const i = s.key.length + s.value.length;
874
- o.kvBytes += i, e.total.kvBytes += i;
871
+ d.kvCount += i.kv.length, e.total.kvCount += i.kv.length;
872
+ for (const a of i.kv) {
873
+ const r = a.key.length + a.value.length;
874
+ d.kvBytes += r, e.total.kvBytes += r;
875
875
  }
876
876
  }
877
877
  return e;
878
878
  }
879
879
  export {
880
- oe as PlError,
881
- C as PlTreeEntry,
882
- E as PlTreeEntryAccessor,
883
- G as PlTreeNodeAccessor,
884
- Q as PlTreeResource,
885
- O as PlTreeState,
880
+ de as PlError,
881
+ R as PlTreeEntry,
882
+ T as PlTreeEntryAccessor,
883
+ Q as PlTreeNodeAccessor,
884
+ X as PlTreeResource,
885
+ P as PlTreeState,
886
886
  B as SynchronizedTreeState,
887
- R as TreeStateUpdateError,
888
- X as constructTreeLoadingRequest,
889
- le as formatTreeLoadingStat,
890
- D as initialTreeLoadingStat,
887
+ S as TreeStateUpdateError,
888
+ Z as constructTreeLoadingRequest,
889
+ fe as formatTreeLoadingStat,
890
+ $ as initialTreeLoadingStat,
891
891
  ue as isPlTreeEntry,
892
- de as isPlTreeEntryAccessor,
893
- ce as isPlTreeNodeAccessor,
894
- Z as loadTreeState,
895
- ge as makeResourceSnapshot,
896
- N as mapValueAndError,
897
- ne as mapValueAndErrorIfDefined,
898
- fe as rsSchema,
899
- ye as treeDumpStats,
900
- he as treeEntryToResourceInfo,
901
- pe as treeEntryToResourceWithData,
892
+ ce as isPlTreeEntryAccessor,
893
+ he as isPlTreeNodeAccessor,
894
+ ee as loadTreeState,
895
+ pe as makeResourceSnapshot,
896
+ K as mapValueAndError,
897
+ oe as mapValueAndErrorIfDefined,
898
+ ge as rsSchema,
899
+ ke as treeDumpStats,
900
+ le as treeEntryToResourceInfo,
901
+ ye as treeEntryToResourceWithData,
902
902
  ve as treeEntryToResourceWithMetadata
903
903
  };
904
904
  //# sourceMappingURL=index.mjs.map