@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/dump.d.ts +59 -0
- package/dist/dump.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +292 -225
- package/dist/index.mjs.map +1 -1
- package/dist/state.d.ts +4 -1
- package/dist/state.d.ts.map +1 -1
- package/dist/synchronized_tree.d.ts +6 -0
- package/dist/synchronized_tree.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/dump.ts +115 -0
- package/src/index.ts +1 -0
- package/src/state.ts +26 -3
- package/src/synchronized_tree.ts +9 -1
package/dist/index.mjs
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var d = (
|
|
4
|
-
import { resourceIdToString as
|
|
5
|
-
import { ChangeSource as m, PollingComputableHooks as
|
|
6
|
-
import { parsePlError as
|
|
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(
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
10
|
+
function ae(o, e) {
|
|
11
|
+
if (o !== void 0)
|
|
12
|
+
return P(o, e);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function P(o, e) {
|
|
15
15
|
const t = {};
|
|
16
|
-
return
|
|
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(
|
|
19
|
-
return typeof
|
|
18
|
+
function ne(o) {
|
|
19
|
+
return typeof o == "object" && o !== null && o.__pl_tree_type_marker__ === "PlTreeEntry";
|
|
20
20
|
}
|
|
21
|
-
function oe(
|
|
22
|
-
return typeof
|
|
21
|
+
function oe(o) {
|
|
22
|
+
return typeof o == "object" && o !== null && o.__pl_tree_type_marker__ === "PlTreeEntryAccessor";
|
|
23
23
|
}
|
|
24
|
-
function ue(
|
|
25
|
-
return typeof
|
|
24
|
+
function ue(o) {
|
|
25
|
+
return typeof o == "object" && o !== null && o.__pl_tree_type_marker__ === "PlTreeNodeAccessor";
|
|
26
26
|
}
|
|
27
|
-
class
|
|
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:${
|
|
42
|
+
return `[ENTRY:${R(this.rid)}]`;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
function N(
|
|
46
|
-
const
|
|
47
|
-
|
|
45
|
+
function N(o, e, t, r, s) {
|
|
46
|
+
const n = new Y(
|
|
47
|
+
o,
|
|
48
48
|
e,
|
|
49
|
-
e.get(t.ctx.watcher,
|
|
49
|
+
e.get(t.ctx.watcher, r),
|
|
50
50
|
t
|
|
51
51
|
);
|
|
52
52
|
if (!s.ignoreError) {
|
|
53
|
-
const a =
|
|
53
|
+
const a = n.getError();
|
|
54
54
|
if (a !== void 0)
|
|
55
|
-
throw
|
|
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,
|
|
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 ${
|
|
59
|
+
`wrong resource type ${U(n.resourceType)} but expected ${s.assertResourceType}`
|
|
60
60
|
);
|
|
61
|
-
return
|
|
61
|
+
return n;
|
|
62
62
|
}
|
|
63
63
|
class E {
|
|
64
|
-
constructor(e, t,
|
|
64
|
+
constructor(e, t, r, s) {
|
|
65
65
|
d(this, "__pl_tree_type_marker__", "PlTreeEntryAccessor");
|
|
66
|
-
this.accessorData = e, this.tree = t, this.rid =
|
|
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(
|
|
73
|
-
return
|
|
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,
|
|
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 =
|
|
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
|
|
106
|
-
if (
|
|
107
|
-
if (!
|
|
108
|
-
return
|
|
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
|
|
112
|
+
let r = this;
|
|
113
113
|
for (const s of t) {
|
|
114
|
-
const
|
|
114
|
+
const n = typeof s == "string" ? {
|
|
115
115
|
...e,
|
|
116
116
|
field: s
|
|
117
|
-
} : { ...e, ...s }, a =
|
|
118
|
-
if (a === 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 ((!
|
|
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:
|
|
124
|
+
error: V(
|
|
125
125
|
p(a.error.getDataAsString()),
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
r.id,
|
|
127
|
+
r.resourceType,
|
|
128
|
+
n.field
|
|
129
129
|
)
|
|
130
130
|
};
|
|
131
131
|
if (a.value === void 0) {
|
|
132
|
-
if (
|
|
132
|
+
if (n.errorIfFieldNotSet)
|
|
133
133
|
return {
|
|
134
134
|
ok: !1,
|
|
135
|
-
error: `field have no assigned value ${
|
|
135
|
+
error: `field have no assigned value ${n.field} of ${R(r.id)}`
|
|
136
136
|
};
|
|
137
|
-
this.onUnstableLambda("unpopulated_field:" +
|
|
137
|
+
this.onUnstableLambda("unpopulated_field:" + n.field);
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
|
-
|
|
140
|
+
r = a.value;
|
|
141
141
|
}
|
|
142
|
-
return { ok: !0, value:
|
|
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,
|
|
147
|
-
if (
|
|
148
|
-
return
|
|
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
|
|
195
|
-
return
|
|
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
|
|
204
|
-
return
|
|
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
|
|
208
|
-
if (
|
|
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(
|
|
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
|
|
223
|
+
return new C(this.accessorData, this.resource.id);
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
-
class
|
|
226
|
+
class S extends Error {
|
|
227
227
|
constructor(e) {
|
|
228
228
|
super(e);
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
class $ {
|
|
232
|
-
constructor(e, t,
|
|
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 =
|
|
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,
|
|
300
|
+
getField(e, t, r = () => {
|
|
291
301
|
}) {
|
|
292
|
-
var a,
|
|
293
|
-
const s = typeof t == "string" ? { field: t } : t,
|
|
294
|
-
if (
|
|
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 ${
|
|
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) (
|
|
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 &&
|
|
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 &&
|
|
324
|
+
if (s.assertFieldType !== void 0 && n.type !== s.assertFieldType)
|
|
315
325
|
throw new Error(
|
|
316
|
-
`Unexpected field type: expected ${s.assertFieldType} but got ${
|
|
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(
|
|
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 !==
|
|
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 (
|
|
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
|
|
360
|
+
var r;
|
|
351
361
|
const t = [];
|
|
352
|
-
return this.fieldsMap.forEach((s,
|
|
353
|
-
(s.type === "Input" || s.type === "Service") && t.push(
|
|
354
|
-
}), this.inputsLocked || (
|
|
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
|
|
367
|
+
var r;
|
|
358
368
|
const t = [];
|
|
359
|
-
return this.fieldsMap.forEach((s,
|
|
360
|
-
s.type === "Output" && t.push(
|
|
361
|
-
}), this.outputsLocked || (
|
|
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
|
|
374
|
+
var r;
|
|
365
375
|
const t = [];
|
|
366
|
-
return this.fieldsMap.forEach((s,
|
|
367
|
-
s.type !== "Input" && s.type !== "Output" && t.push(
|
|
368
|
-
}), (
|
|
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
|
|
372
|
-
return (
|
|
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
|
|
376
|
-
if (
|
|
377
|
-
return x.decode(
|
|
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: ${
|
|
399
|
+
throw new Error(`ready without input or output lock: ${D(this.basicState)}`);
|
|
390
400
|
}
|
|
391
|
-
get
|
|
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,
|
|
412
|
-
this.fieldsMap.forEach((f) => f.change.markChanged()), (e = this.finalChanged) == null || e.markChanged(), (t = this.resourceStateChange) == null || t.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
|
|
435
|
-
if (
|
|
436
|
-
throw this.resourcesAdded.attachWatcher(e), new Error(`resource ${
|
|
437
|
-
return
|
|
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
|
|
458
|
+
const r = [], s = [];
|
|
442
459
|
for (const a of e) {
|
|
443
|
-
let
|
|
444
|
-
const f =
|
|
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
|
|
447
|
-
`Unexpected resource state transition (${h}): ${
|
|
463
|
+
throw this.invalidateTree(), new S(
|
|
464
|
+
`Unexpected resource state transition (${h}): ${D(
|
|
448
465
|
u
|
|
449
|
-
)} -> ${
|
|
466
|
+
)} -> ${D(f)}`
|
|
450
467
|
);
|
|
451
468
|
};
|
|
452
|
-
if (
|
|
453
|
-
|
|
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
|
-
|
|
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 =
|
|
458
|
-
c ? (c.type !== u.type && (c.type !== "Dynamic" && l(`field changed type ${c.type} -> ${u.type}`), p(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
470
|
-
), g(u.value) &&
|
|
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(
|
|
489
|
+
), p(i.inputAndServiceFieldListChanged).markChanged()) : u.type === "Output" ? (i.outputsLocked && l(
|
|
473
490
|
`adding ${u.type} (${u.name}) field while outputs locked`
|
|
474
|
-
), p(
|
|
491
|
+
), p(i.outputFieldListChanged).markChanged()) : p(i.dynamicFieldListChanged).markChanged(), i.fieldsMap.set(u.name, c), h = !0);
|
|
475
492
|
}
|
|
476
|
-
if (
|
|
477
|
-
u.resourceVersion !==
|
|
478
|
-
}),
|
|
479
|
-
const u =
|
|
480
|
-
|
|
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(
|
|
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 =
|
|
487
|
-
(c === void 0 || Buffer.compare(c, u.value) !== 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 (
|
|
506
|
+
if (i.kv.size > a.kv.length) {
|
|
490
507
|
const u = new Set(a.kv.map((c) => c.key));
|
|
491
|
-
|
|
508
|
+
i.kv.forEach((c, v, y) => {
|
|
492
509
|
u.has(v) || y.delete(v);
|
|
493
510
|
}), k = !0;
|
|
494
511
|
}
|
|
495
|
-
k && p(
|
|
512
|
+
k && p(i.kvChanged).markChanged(), h && (i.dataVersion = i.version, this.isFinalPredicate(i) && i.markFinal());
|
|
496
513
|
} else {
|
|
497
|
-
|
|
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) &&
|
|
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)
|
|
511
|
-
this.isFinalPredicate(
|
|
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
|
|
515
|
-
const
|
|
516
|
-
if (!
|
|
517
|
-
throw this.invalidateTree(), new
|
|
518
|
-
|
|
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
|
|
521
|
-
for (;
|
|
537
|
+
let n = s;
|
|
538
|
+
for (; n.length > 0; ) {
|
|
522
539
|
const a = [];
|
|
523
|
-
for (const
|
|
524
|
-
const f = this.resources.get(
|
|
540
|
+
for (const i of n) {
|
|
541
|
+
const f = this.resources.get(i);
|
|
525
542
|
if (!f)
|
|
526
|
-
throw this.invalidateTree(), new
|
|
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(
|
|
546
|
+
}), g(f.error) && a.push(f.error), f.resourceRemoved.markChanged(), this.resources.delete(i));
|
|
530
547
|
}
|
|
531
|
-
|
|
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
|
|
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
|
|
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(
|
|
553
|
-
const t = [],
|
|
554
|
-
return
|
|
555
|
-
s.finalState ?
|
|
556
|
-
}), t.length === 0 &&
|
|
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(
|
|
573
|
-
let e = `Requests: ${
|
|
592
|
+
function ce(o) {
|
|
593
|
+
let e = `Requests: ${o.requests}
|
|
574
594
|
`;
|
|
575
|
-
return e += `Total time: ${z(
|
|
576
|
-
`, e += `Round-trips: ${
|
|
577
|
-
`, e += `Resources: ${
|
|
578
|
-
`, e += `Fields: ${
|
|
579
|
-
`, e += `KV: ${
|
|
580
|
-
`, e += `Data Bytes: ${
|
|
581
|
-
`, e += `KV Bytes: ${
|
|
582
|
-
`, e += `Pruned fields: ${
|
|
583
|
-
`, e += `Final resources skipped: ${
|
|
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(
|
|
605
|
+
async function X(o, e, t) {
|
|
586
606
|
var c;
|
|
587
|
-
const
|
|
607
|
+
const r = Date.now();
|
|
588
608
|
t && t.requests++;
|
|
589
|
-
const { seedResources: s, finalResources:
|
|
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 (
|
|
593
|
-
if (
|
|
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 =
|
|
599
|
-
f && (f = !1),
|
|
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 (
|
|
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 =
|
|
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() -
|
|
651
|
+
return t && (t.millisSpent += Date.now() - r, t.roundTrips += l), u;
|
|
632
652
|
}
|
|
633
|
-
function he(
|
|
634
|
-
return
|
|
653
|
+
function he(o) {
|
|
654
|
+
return o;
|
|
635
655
|
}
|
|
636
|
-
function le(
|
|
656
|
+
function le(o, e, t) {
|
|
637
657
|
var a;
|
|
638
|
-
const
|
|
639
|
-
if (e.data !== void 0 && (e.data === "raw" ?
|
|
640
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
667
|
+
n.fields = i;
|
|
648
668
|
}
|
|
649
669
|
if (e.kv !== void 0) {
|
|
650
|
-
const
|
|
670
|
+
const i = {};
|
|
651
671
|
for (const [f, l] of Object.entries(e.kv)) {
|
|
652
|
-
const h =
|
|
672
|
+
const h = r.getKeyValue(f);
|
|
653
673
|
if (h === void 0)
|
|
654
674
|
throw new Error(`Key not found ${f}`);
|
|
655
|
-
l === "raw" ?
|
|
675
|
+
l === "raw" ? i[f] = h : i[f] = l.parse(JSON.parse(Buffer.from(h).toString("utf-8")));
|
|
656
676
|
}
|
|
657
|
-
|
|
677
|
+
n.kv = i;
|
|
658
678
|
}
|
|
659
|
-
return
|
|
679
|
+
return n;
|
|
660
680
|
}
|
|
661
|
-
function fe(
|
|
662
|
-
if (
|
|
663
|
-
const
|
|
664
|
-
var
|
|
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 = (
|
|
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(
|
|
673
|
-
data:
|
|
692
|
+
fields: new Map(n),
|
|
693
|
+
data: r.getData() ?? new Uint8Array()
|
|
674
694
|
};
|
|
675
695
|
}
|
|
676
|
-
return
|
|
696
|
+
return o;
|
|
677
697
|
}
|
|
678
|
-
function ge(
|
|
679
|
-
if (!(
|
|
680
|
-
const
|
|
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(
|
|
703
|
+
metadata: Object.fromEntries(n)
|
|
684
704
|
};
|
|
685
705
|
}
|
|
686
706
|
class K {
|
|
687
|
-
constructor(e, t,
|
|
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:
|
|
704
|
-
this.pruning = a, this.pollingInterval =
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
751
|
-
} catch (
|
|
752
|
-
if (e && this.logger && this.logger.info(`Tree stat (error): ${JSON.stringify(e)}`), s !== void 0) for (const a of s) a.reject(
|
|
753
|
-
if (
|
|
754
|
-
(t = this.logger) == null || t.error(
|
|
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 (
|
|
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 (
|
|
762
|
-
if (!
|
|
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,
|
|
780
|
-
const
|
|
781
|
-
let a =
|
|
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
|
|
784
|
-
timeout:
|
|
785
|
-
}),
|
|
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, ${
|
|
815
|
+
`Tree stat (initial load, ${i ? "success" : "failure"}): ${JSON.stringify(a)}`
|
|
789
816
|
);
|
|
790
817
|
}
|
|
791
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|