@milaboratories/pl-tree 1.4.1 → 1.4.3
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.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +282 -259
- package/dist/index.mjs.map +1 -1
- package/dist/state.d.ts +18 -23
- package/dist/state.d.ts.map +1 -1
- package/dist/sync.d.ts +2 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/synchronized_tree.d.ts +5 -3
- package/dist/synchronized_tree.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/snapshot.test.ts +2 -2
- package/src/state.test.ts +10 -10
- package/src/state.ts +73 -44
- package/src/sync.test.ts +2 -2
- package/src/sync.ts +18 -19
- package/src/synchronized_tree.ts +16 -7
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var d = (
|
|
4
|
-
import { resourceIdToString as C, resourceTypeToString as A, resourceTypesEqual as $, isNotNullResourceId as g, NullResourceId as
|
|
5
|
-
import { ChangeSource as m, PollingComputableHooks as
|
|
1
|
+
var U = Object.defineProperty;
|
|
2
|
+
var J = (a, e, t) => e in a ? U(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
|
+
var d = (a, e, t) => J(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { resourceIdToString as C, resourceTypeToString as A, resourceTypesEqual as $, isNotNullResourceId as g, NullResourceId as D, isNullResourceId as P, stringifyWithResourceId as L, isTimeoutOrCancelError as q } from "@milaboratories/pl-client";
|
|
5
|
+
import { ChangeSource as m, PollingComputableHooks as B } from "@milaboratories/computable";
|
|
6
6
|
import { notEmpty as y, msToHumanReadable as z } from "@milaboratories/ts-helpers";
|
|
7
7
|
import H from "denque";
|
|
8
8
|
import * as j from "node:timers/promises";
|
|
9
|
-
function se(
|
|
10
|
-
if (
|
|
11
|
-
return
|
|
9
|
+
function se(a, e) {
|
|
10
|
+
if (a !== void 0)
|
|
11
|
+
return b(a, e);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function b(a, e) {
|
|
14
14
|
const t = {};
|
|
15
|
-
return
|
|
15
|
+
return a.value !== void 0 && (t.value = e(a.value)), a.error !== void 0 && (t.error = e(a.error)), t;
|
|
16
16
|
}
|
|
17
17
|
class N extends Error {
|
|
18
18
|
constructor(e) {
|
|
19
19
|
super(e);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
return typeof
|
|
22
|
+
function ae(a) {
|
|
23
|
+
return typeof a == "object" && a !== null && a.__pl_tree_type_marker__ === "PlTreeEntry";
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
return typeof
|
|
25
|
+
function ne(a) {
|
|
26
|
+
return typeof a == "object" && a !== null && a.__pl_tree_type_marker__ === "PlTreeEntryAccessor";
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
return typeof
|
|
28
|
+
function oe(a) {
|
|
29
|
+
return typeof a == "object" && a !== null && a.__pl_tree_type_marker__ === "PlTreeNodeAccessor";
|
|
30
30
|
}
|
|
31
31
|
class R {
|
|
32
32
|
constructor(e, t) {
|
|
@@ -46,45 +46,45 @@ class R {
|
|
|
46
46
|
return `[ENTRY:${C(this.rid)}]`;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
function K(
|
|
50
|
-
const
|
|
51
|
-
|
|
49
|
+
function K(a, e, t, i, s) {
|
|
50
|
+
const o = new Y(
|
|
51
|
+
a,
|
|
52
52
|
e,
|
|
53
|
-
e.get(t.ctx.watcher,
|
|
53
|
+
e.get(t.ctx.watcher, i),
|
|
54
54
|
t
|
|
55
55
|
);
|
|
56
56
|
if (!s.ignoreError) {
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
57
|
+
const n = o.getError();
|
|
58
|
+
if (n !== void 0)
|
|
59
59
|
throw new N(
|
|
60
|
-
`error encountered on resource ${C(
|
|
60
|
+
`error encountered on resource ${C(o.id)} (${A(o.resourceType)}): ${n.getDataAsString()}`
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
|
-
if (s.assertResourceType !== void 0 && (Array.isArray(s.assertResourceType) ? s.assertResourceType.findIndex((
|
|
63
|
+
if (s.assertResourceType !== void 0 && (Array.isArray(s.assertResourceType) ? s.assertResourceType.findIndex((n) => $(n, o.resourceType)) === -1 : !$(s.assertResourceType, o.resourceType)))
|
|
64
64
|
throw new Error(
|
|
65
|
-
`wrong resource type ${A(
|
|
65
|
+
`wrong resource type ${A(o.resourceType)} but expected ${s.assertResourceType}`
|
|
66
66
|
);
|
|
67
|
-
return
|
|
67
|
+
return o;
|
|
68
68
|
}
|
|
69
69
|
class E {
|
|
70
|
-
constructor(e, t,
|
|
70
|
+
constructor(e, t, i, s) {
|
|
71
71
|
d(this, "__pl_tree_type_marker__", "PlTreeEntryAccessor");
|
|
72
|
-
this.accessorData = e, this.tree = t, this.rid =
|
|
72
|
+
this.accessorData = e, this.tree = t, this.rid = i, this.instanceData = s;
|
|
73
73
|
}
|
|
74
74
|
node(e = {}) {
|
|
75
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);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
function ue(
|
|
79
|
-
return
|
|
78
|
+
function ue(a, e) {
|
|
79
|
+
return a instanceof R ? e.accessor(a).node().resourceInfo : a;
|
|
80
80
|
}
|
|
81
81
|
class Y {
|
|
82
|
-
constructor(e, t,
|
|
82
|
+
constructor(e, t, i, s) {
|
|
83
83
|
d(this, "__pl_tree_type_marker__", "PlTreeNodeAccessor");
|
|
84
84
|
d(this, "onUnstableLambda", (e) => {
|
|
85
85
|
this.instanceData.ctx.markUnstable(e);
|
|
86
86
|
});
|
|
87
|
-
this.accessorData = e, this.tree = t, this.resource =
|
|
87
|
+
this.accessorData = e, this.tree = t, this.resource = i, this.instanceData = s;
|
|
88
88
|
}
|
|
89
89
|
get id() {
|
|
90
90
|
return this.instanceData.guard(), this.resource.id;
|
|
@@ -108,44 +108,44 @@ class Y {
|
|
|
108
108
|
return this.traverseOrErrorWithCommon({}, ...e);
|
|
109
109
|
}
|
|
110
110
|
traverseWithCommon(e, ...t) {
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
113
|
-
if (!
|
|
114
|
-
return
|
|
111
|
+
const i = this.traverseOrErrorWithCommon(e, ...t);
|
|
112
|
+
if (i !== void 0) {
|
|
113
|
+
if (!i.ok) throw new N(i.error);
|
|
114
|
+
return i.value;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
traverseOrErrorWithCommon(e, ...t) {
|
|
118
|
-
let
|
|
118
|
+
let i = this;
|
|
119
119
|
for (const s of t) {
|
|
120
|
-
const
|
|
120
|
+
const o = typeof s == "string" ? {
|
|
121
121
|
...e,
|
|
122
122
|
field: s
|
|
123
|
-
} : { ...e, ...s },
|
|
124
|
-
if (
|
|
123
|
+
} : { ...e, ...s }, n = i.getField(s);
|
|
124
|
+
if (n === void 0 || o.pureFieldErrorToUndefined && n.value === void 0 && n.error !== void 0)
|
|
125
125
|
return;
|
|
126
|
-
if ((!
|
|
126
|
+
if ((!o.ignoreError || n.value === void 0) && n.error !== void 0)
|
|
127
127
|
return {
|
|
128
128
|
ok: !1,
|
|
129
|
-
error: `error in field ${
|
|
129
|
+
error: `error in field ${o.field} of ${C(i.id)}: ${n.error.getDataAsString()}`
|
|
130
130
|
};
|
|
131
|
-
if (
|
|
132
|
-
if (
|
|
131
|
+
if (n.value === void 0) {
|
|
132
|
+
if (o.errorIfFieldNotSet)
|
|
133
133
|
return {
|
|
134
134
|
ok: !1,
|
|
135
|
-
error: `field have no assigned value ${
|
|
135
|
+
error: `field have no assigned value ${o.field} of ${C(i.id)}`
|
|
136
136
|
};
|
|
137
|
-
this.onUnstableLambda("unpopulated_field:" +
|
|
137
|
+
this.onUnstableLambda("unpopulated_field:" + o.field);
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
|
-
|
|
140
|
+
i = n.value;
|
|
141
141
|
}
|
|
142
|
-
return { ok: !0, value:
|
|
142
|
+
return { ok: !0, value: i };
|
|
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, i = this.resource.getField(this.instanceData.ctx.watcher, t, this.onUnstableLambda);
|
|
147
|
+
if (i !== void 0)
|
|
148
|
+
return b(i, (s) => this.getResourceFromTree(s, { ignoreError: !0 }));
|
|
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 i = this.resource.getKeyValue(this.instanceData.ctx.watcher, e);
|
|
195
|
+
return i === void 0 && t && this.instanceData.ctx.markUnstable("key_not_found_b:" + e), i;
|
|
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 i = this.resource.getKeyValueString(this.instanceData.ctx.watcher, e);
|
|
204
|
+
return i === void 0 && t && this.instanceData.ctx.markUnstable("key_not_found_s:" + e), i;
|
|
205
205
|
}
|
|
206
206
|
getKeyValueAsJson(e, t = !1) {
|
|
207
|
-
const
|
|
208
|
-
if (
|
|
207
|
+
const i = this.resource.getKeyValueString(this.instanceData.ctx.watcher, e);
|
|
208
|
+
if (i === 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(i);
|
|
213
213
|
}
|
|
214
214
|
/**
|
|
215
215
|
* Can be used to passe a higher level accessor that will wrap the resource and throw its
|
|
@@ -229,9 +229,9 @@ class S extends Error {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
class x {
|
|
232
|
-
constructor(e, t,
|
|
232
|
+
constructor(e, t, i, s, o, n, r) {
|
|
233
233
|
d(this, "change", new m());
|
|
234
|
-
this.
|
|
234
|
+
this.name = e, this.type = t, this.value = i, this.error = s, this.status = o, this.valueIsFinal = n, this.resourceVersion = r;
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
const T = 0, O = new TextDecoder();
|
|
@@ -243,7 +243,7 @@ class G {
|
|
|
243
243
|
d(this, "version", T);
|
|
244
244
|
/** Set to resource version when resource state, or it's fields have changed */
|
|
245
245
|
d(this, "dataVersion", T);
|
|
246
|
-
d(this, "
|
|
246
|
+
d(this, "fieldsMap", /* @__PURE__ */ new Map());
|
|
247
247
|
d(this, "kv", /* @__PURE__ */ new Map());
|
|
248
248
|
d(this, "resourceRemoved", new m());
|
|
249
249
|
// following change source are removed when resource is marked as final
|
|
@@ -266,8 +266,8 @@ class G {
|
|
|
266
266
|
d(this, "outputsLocked");
|
|
267
267
|
d(this, "resourceReady");
|
|
268
268
|
d(this, "finalFlag");
|
|
269
|
-
/** Set externally by the tree, using {@link
|
|
270
|
-
d(this, "
|
|
269
|
+
/** Set externally by the tree, using {@link FinalResourceDataPredicate} */
|
|
270
|
+
d(this, "_finalState", !1);
|
|
271
271
|
d(this, "logger");
|
|
272
272
|
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;
|
|
273
273
|
}
|
|
@@ -279,38 +279,44 @@ class G {
|
|
|
279
279
|
this.logger !== void 0 && this.logger.warn(e);
|
|
280
280
|
}
|
|
281
281
|
get final() {
|
|
282
|
-
return this.
|
|
282
|
+
return this.finalFlag;
|
|
283
|
+
}
|
|
284
|
+
get finalState() {
|
|
285
|
+
return this._finalState;
|
|
283
286
|
}
|
|
284
|
-
|
|
287
|
+
get fields() {
|
|
288
|
+
return [...this.fieldsMap.values()];
|
|
289
|
+
}
|
|
290
|
+
getField(e, t, i = () => {
|
|
285
291
|
}) {
|
|
286
|
-
var
|
|
287
|
-
const s = typeof t == "string" ? { field: t } : t,
|
|
288
|
-
if (
|
|
292
|
+
var n, r, f;
|
|
293
|
+
const s = typeof t == "string" ? { field: t } : t, o = this.fieldsMap.get(s.field);
|
|
294
|
+
if (o === void 0) {
|
|
289
295
|
if (s.errorIfFieldNotFound || s.errorIfFieldNotSet)
|
|
290
296
|
throw new Error(
|
|
291
297
|
`Field "${s.field}" not found in resource ${C(this.id)}`
|
|
292
298
|
);
|
|
293
|
-
if (!this.inputsLocked) (
|
|
299
|
+
if (!this.inputsLocked) (n = this.inputAndServiceFieldListChanged) == null || n.attachWatcher(e);
|
|
294
300
|
else if (s.assertFieldType === "Service" || s.assertFieldType === "Input") {
|
|
295
301
|
if (s.allowPermanentAbsence)
|
|
296
302
|
return;
|
|
297
303
|
throw new Error(`Service or input field not found ${s.field}.`);
|
|
298
304
|
}
|
|
299
|
-
if (!this.outputsLocked) (
|
|
305
|
+
if (!this.outputsLocked) (r = this.outputFieldListChanged) == null || r.attachWatcher(e);
|
|
300
306
|
else if (s.assertFieldType === "Output") {
|
|
301
307
|
if (s.allowPermanentAbsence)
|
|
302
308
|
return;
|
|
303
309
|
throw new Error(`Output field not found ${s.field}.`);
|
|
304
310
|
}
|
|
305
|
-
(
|
|
311
|
+
(f = this.dynamicFieldListChanged) == null || f.attachWatcher(e), !this._finalState && !s.stableIfNotFound && i("field_not_found:" + s.field);
|
|
306
312
|
return;
|
|
307
313
|
} else {
|
|
308
|
-
if (s.assertFieldType !== void 0 &&
|
|
314
|
+
if (s.assertFieldType !== void 0 && o.type !== s.assertFieldType)
|
|
309
315
|
throw new Error(
|
|
310
|
-
`Unexpected field type: expected ${s.assertFieldType} but got ${
|
|
316
|
+
`Unexpected field type: expected ${s.assertFieldType} but got ${o.type} for the field name ${s.field}`
|
|
311
317
|
);
|
|
312
|
-
const
|
|
313
|
-
return g(
|
|
318
|
+
const l = {};
|
|
319
|
+
return g(o.value) && (l.value = o.value), g(o.error) && (l.error = o.error), l.value === void 0 && l.error === void 0 && i("field_not_resolved:" + s.field), o.change.attachWatcher(e), l;
|
|
314
320
|
}
|
|
315
321
|
}
|
|
316
322
|
getInputsLocked(e) {
|
|
@@ -322,11 +328,11 @@ class G {
|
|
|
322
328
|
return this.outputsLocked || (t = this.resourceStateChange) == null || t.attachWatcher(e), this.outputsLocked;
|
|
323
329
|
}
|
|
324
330
|
get isReadyOrError() {
|
|
325
|
-
return this.error !==
|
|
331
|
+
return this.error !== D || this.resourceReady || this.originalResourceId !== D;
|
|
326
332
|
}
|
|
327
333
|
getIsFinal(e) {
|
|
328
334
|
var t;
|
|
329
|
-
return (t = this.finalChanged) == null || t.attachWatcher(e), this.
|
|
335
|
+
return (t = this.finalChanged) == null || t.attachWatcher(e), this._finalState;
|
|
330
336
|
}
|
|
331
337
|
getIsReadyOrError(e) {
|
|
332
338
|
var t;
|
|
@@ -334,41 +340,41 @@ class G {
|
|
|
334
340
|
}
|
|
335
341
|
getError(e) {
|
|
336
342
|
var t;
|
|
337
|
-
if (
|
|
343
|
+
if (P(this.error)) {
|
|
338
344
|
(t = this.resourceStateChange) == null || t.attachWatcher(e);
|
|
339
345
|
return;
|
|
340
346
|
} else
|
|
341
347
|
return this.error;
|
|
342
348
|
}
|
|
343
349
|
listInputFields(e) {
|
|
344
|
-
var
|
|
350
|
+
var i;
|
|
345
351
|
const t = [];
|
|
346
|
-
return this.
|
|
347
|
-
(s.type === "Input" || s.type === "Service") && t.push(
|
|
348
|
-
}), this.inputsLocked || (
|
|
352
|
+
return this.fieldsMap.forEach((s, o) => {
|
|
353
|
+
(s.type === "Input" || s.type === "Service") && t.push(o);
|
|
354
|
+
}), this.inputsLocked || (i = this.inputAndServiceFieldListChanged) == null || i.attachWatcher(e), t;
|
|
349
355
|
}
|
|
350
356
|
listOutputFields(e) {
|
|
351
|
-
var
|
|
357
|
+
var i;
|
|
352
358
|
const t = [];
|
|
353
|
-
return this.
|
|
354
|
-
s.type === "Output" && t.push(
|
|
355
|
-
}), this.outputsLocked || (
|
|
359
|
+
return this.fieldsMap.forEach((s, o) => {
|
|
360
|
+
s.type === "Output" && t.push(o);
|
|
361
|
+
}), this.outputsLocked || (i = this.outputFieldListChanged) == null || i.attachWatcher(e), t;
|
|
356
362
|
}
|
|
357
363
|
listDynamicFields(e) {
|
|
358
|
-
var
|
|
364
|
+
var i;
|
|
359
365
|
const t = [];
|
|
360
|
-
return this.
|
|
361
|
-
s.type !== "Input" && s.type !== "Output" && t.push(
|
|
362
|
-
}), (
|
|
366
|
+
return this.fieldsMap.forEach((s, o) => {
|
|
367
|
+
s.type !== "Input" && s.type !== "Output" && t.push(o);
|
|
368
|
+
}), (i = this.dynamicFieldListChanged) == null || i.attachWatcher(e), t;
|
|
363
369
|
}
|
|
364
370
|
getKeyValue(e, t) {
|
|
365
|
-
var
|
|
366
|
-
return (
|
|
371
|
+
var i;
|
|
372
|
+
return (i = this.kvChanged) == null || i.attachWatcher(e), this.kv.get(t);
|
|
367
373
|
}
|
|
368
374
|
getKeyValueString(e, t) {
|
|
369
|
-
const
|
|
370
|
-
if (
|
|
371
|
-
return O.decode(
|
|
375
|
+
const i = this.getKeyValue(e, t);
|
|
376
|
+
if (i !== void 0)
|
|
377
|
+
return O.decode(i);
|
|
372
378
|
}
|
|
373
379
|
getDataAsString() {
|
|
374
380
|
if (this.data !== void 0)
|
|
@@ -396,17 +402,18 @@ class G {
|
|
|
396
402
|
final: this.finalFlag
|
|
397
403
|
};
|
|
398
404
|
}
|
|
405
|
+
/** Called when {@link FinalResourceDataPredicate} returns true for the state. */
|
|
399
406
|
markFinal() {
|
|
400
|
-
this.
|
|
407
|
+
this._finalState || (this._finalState = !0, y(this.finalChanged).markChanged(), this.finalChanged = void 0, this.resourceStateChange = void 0, this.dynamicFieldListChanged = void 0, this.inputAndServiceFieldListChanged = void 0, this.outputFieldListChanged = void 0, this.lockedChange = void 0);
|
|
401
408
|
}
|
|
402
409
|
/** Used for invalidation */
|
|
403
410
|
markAllChanged() {
|
|
404
|
-
var e, t,
|
|
405
|
-
this.
|
|
411
|
+
var e, t, i, s, o, n, r;
|
|
412
|
+
this.fieldsMap.forEach((f) => f.change.markChanged()), (e = this.finalChanged) == null || e.markChanged(), (t = this.resourceStateChange) == null || t.markChanged(), (i = this.lockedChange) == null || i.markChanged(), (s = this.inputAndServiceFieldListChanged) == null || s.markChanged(), (o = this.outputFieldListChanged) == null || o.markChanged(), (n = this.dynamicFieldListChanged) == null || n.markChanged(), (r = this.kvChanged) == null || r.markChanged(), this.resourceRemoved.markChanged();
|
|
406
413
|
}
|
|
407
414
|
}
|
|
408
415
|
class V {
|
|
409
|
-
constructor(e, t
|
|
416
|
+
constructor(e, t) {
|
|
410
417
|
/** resource heap */
|
|
411
418
|
d(this, "resources", /* @__PURE__ */ new Map());
|
|
412
419
|
d(this, "resourcesAdded", new m());
|
|
@@ -424,93 +431,109 @@ class V {
|
|
|
424
431
|
}
|
|
425
432
|
get(e, t) {
|
|
426
433
|
this.checkValid();
|
|
427
|
-
const
|
|
428
|
-
if (
|
|
434
|
+
const i = this.resources.get(t);
|
|
435
|
+
if (i === void 0)
|
|
429
436
|
throw this.resourcesAdded.attachWatcher(e), new Error(`resource ${C(t)} not found in the tree`);
|
|
430
|
-
return
|
|
437
|
+
return i.resourceRemoved.attachWatcher(e), i;
|
|
431
438
|
}
|
|
432
439
|
updateFromResourceData(e, t = !1) {
|
|
433
440
|
this.checkValid();
|
|
434
|
-
const
|
|
435
|
-
for (const
|
|
436
|
-
let
|
|
437
|
-
const
|
|
438
|
-
const { fields: k, ...u } =
|
|
441
|
+
const i = [], s = [];
|
|
442
|
+
for (const n of e) {
|
|
443
|
+
let r = this.resources.get(n.id);
|
|
444
|
+
const f = r == null ? void 0 : r.state, l = (h) => {
|
|
445
|
+
const { fields: k, ...u } = n;
|
|
439
446
|
throw this.invalidateTree(), new S(
|
|
440
|
-
`Unexpected resource state transition (${
|
|
447
|
+
`Unexpected resource state transition (${h}): ${L(
|
|
441
448
|
u
|
|
442
|
-
)} -> ${L(
|
|
449
|
+
)} -> ${L(f)}`
|
|
443
450
|
);
|
|
444
451
|
};
|
|
445
|
-
if (
|
|
446
|
-
|
|
447
|
-
let
|
|
448
|
-
|
|
449
|
-
for (const u of
|
|
450
|
-
let
|
|
451
|
-
|
|
452
|
+
if (r !== void 0) {
|
|
453
|
+
r.finalState && l("resource state can be updated after it is marked as final");
|
|
454
|
+
let h = !1;
|
|
455
|
+
r.version += 1, r.originalResourceId !== n.originalResourceId && (r.originalResourceId !== D && l("originalResourceId can't change after it is set"), r.originalResourceId = n.originalResourceId, y(r.resourceStateChange).markChanged(), h = !0), r.error !== n.error && (g(r.error) && l("resource can't change attached error after it is set"), r.error = n.error, i.push(r.error), y(r.resourceStateChange).markChanged(), h = !0);
|
|
456
|
+
for (const u of n.fields) {
|
|
457
|
+
let c = r.fieldsMap.get(u.name);
|
|
458
|
+
c ? (c.type !== u.type && (c.type !== "Dynamic" && l(`field changed type ${c.type} -> ${u.type}`), y(r.dynamicFieldListChanged).markChanged(), (c.type === "Input" || c.type === "Service") && (r.inputsLocked && l(
|
|
452
459
|
`adding input field "${u.name}", while corresponding list is locked`
|
|
453
|
-
), y(
|
|
460
|
+
), y(r.inputAndServiceFieldListChanged).markChanged()), c.type === "Output" && (r.outputsLocked && l(
|
|
454
461
|
`adding output field "${u.name}", while corresponding list is locked`
|
|
455
|
-
), y(
|
|
462
|
+
), y(r.outputFieldListChanged).markChanged()), c.type = u.type, c.change.markChanged(), h = !0), c.value !== u.value && (g(c.value) && s.push(c.value), c.value = u.value, g(u.value) && i.push(u.value), c.change.markChanged(), h = !0), c.error !== u.error && (g(c.error) && s.push(c.error), c.error = u.error, g(u.error) && i.push(u.error), c.change.markChanged(), h = !0), c.status !== u.status && (c.status = u.status, c.change.markChanged(), h = !0), c.valueIsFinal !== u.valueIsFinal && (c.valueIsFinal = u.valueIsFinal, c.change.markChanged(), h = !0), c.resourceVersion = r.version) : (c = new x(
|
|
463
|
+
u.name,
|
|
464
|
+
u.type,
|
|
465
|
+
u.value,
|
|
466
|
+
u.error,
|
|
467
|
+
u.status,
|
|
468
|
+
u.valueIsFinal,
|
|
469
|
+
r.version
|
|
470
|
+
), g(u.value) && i.push(u.value), g(u.error) && i.push(u.error), u.type === "Input" || u.type === "Service" ? (r.inputsLocked && l(
|
|
456
471
|
`adding ${u.type} (${u.name}) field while inputs locked`
|
|
457
|
-
), y(
|
|
472
|
+
), y(r.inputAndServiceFieldListChanged).markChanged()) : u.type === "Output" ? (r.outputsLocked && l(
|
|
458
473
|
`adding ${u.type} (${u.name}) field while outputs locked`
|
|
459
|
-
), y(
|
|
474
|
+
), y(r.outputFieldListChanged).markChanged()) : y(r.dynamicFieldListChanged).markChanged(), r.fieldsMap.set(u.name, c), h = !0);
|
|
460
475
|
}
|
|
461
|
-
if (
|
|
462
|
-
u.resourceVersion !==
|
|
463
|
-
}),
|
|
464
|
-
const u =
|
|
465
|
-
|
|
476
|
+
if (r.fieldsMap.forEach((u, c, p) => {
|
|
477
|
+
u.resourceVersion !== r.version && ((u.type === "Input" || u.type === "Service" || u.type === "Output") && l(`removal of ${u.type} field ${c}`), u.change.markChanged(), p.delete(c), g(u.value) && s.push(u.value), g(u.error) && s.push(u.error), y(r.dynamicFieldListChanged).markChanged());
|
|
478
|
+
}), r.inputsLocked !== n.inputsLocked && (r.inputsLocked && l("inputs unlocking is not permitted"), r.inputsLocked = n.inputsLocked, y(r.lockedChange).markChanged(), h = !0), r.outputsLocked !== n.outputsLocked && (r.outputsLocked && l("outputs unlocking is not permitted"), r.outputsLocked = n.outputsLocked, y(r.lockedChange).markChanged(), h = !0), r.resourceReady !== n.resourceReady) {
|
|
479
|
+
const u = r.resourceReady;
|
|
480
|
+
r.resourceReady = n.resourceReady, r.verifyReadyState(), r.isReadyOrError || l(
|
|
466
481
|
`resource can't lose it's ready or error state (ready state before ${u})`
|
|
467
|
-
), y(
|
|
482
|
+
), y(r.resourceStateChange).markChanged(), h = !0;
|
|
468
483
|
}
|
|
469
484
|
let k = !1;
|
|
470
|
-
for (const u of
|
|
471
|
-
const
|
|
472
|
-
(
|
|
485
|
+
for (const u of n.kv) {
|
|
486
|
+
const c = r.kv.get(u.key);
|
|
487
|
+
(c === void 0 || Buffer.compare(c, u.value) !== 0) && (r.kv.set(u.key, u.value), k = !0);
|
|
473
488
|
}
|
|
474
|
-
if (
|
|
475
|
-
const u = new Set(
|
|
476
|
-
|
|
489
|
+
if (r.kv.size > n.kv.length) {
|
|
490
|
+
const u = new Set(n.kv.map((c) => c.key));
|
|
491
|
+
r.kv.forEach((c, p, v) => {
|
|
477
492
|
u.has(p) || v.delete(p);
|
|
478
493
|
}), k = !0;
|
|
479
494
|
}
|
|
480
|
-
k && y(
|
|
495
|
+
k && y(r.kvChanged).markChanged(), h && (r.dataVersion = r.version, this.isFinalPredicate(r) && r.markFinal());
|
|
481
496
|
} else {
|
|
482
|
-
|
|
483
|
-
for (const
|
|
484
|
-
const k = new x(
|
|
485
|
-
|
|
497
|
+
r = new G(n), r.verifyReadyState(), g(r.error) && i.push(r.error);
|
|
498
|
+
for (const h of n.fields) {
|
|
499
|
+
const k = new x(
|
|
500
|
+
h.name,
|
|
501
|
+
h.type,
|
|
502
|
+
h.value,
|
|
503
|
+
h.error,
|
|
504
|
+
h.status,
|
|
505
|
+
h.valueIsFinal,
|
|
506
|
+
T
|
|
507
|
+
);
|
|
508
|
+
g(h.value) && i.push(h.value), g(h.error) && i.push(h.error), r.fieldsMap.set(h.name, k);
|
|
486
509
|
}
|
|
487
|
-
for (const
|
|
488
|
-
this.isFinalPredicate(
|
|
510
|
+
for (const h of n.kv) r.kv.set(h.key, h.value);
|
|
511
|
+
this.isFinalPredicate(r) && r.markFinal(), this.resources.set(r.id, r), this.resourcesAdded.markChanged();
|
|
489
512
|
}
|
|
490
513
|
}
|
|
491
|
-
for (const
|
|
492
|
-
const
|
|
493
|
-
if (!
|
|
494
|
-
throw this.invalidateTree(), new S(`orphan resource ${
|
|
495
|
-
|
|
514
|
+
for (const n of i) {
|
|
515
|
+
const r = this.resources.get(n);
|
|
516
|
+
if (!r)
|
|
517
|
+
throw this.invalidateTree(), new S(`orphan resource ${n}`);
|
|
518
|
+
r.refCount++;
|
|
496
519
|
}
|
|
497
|
-
let
|
|
498
|
-
for (;
|
|
499
|
-
const
|
|
500
|
-
for (const
|
|
501
|
-
const
|
|
502
|
-
if (!
|
|
503
|
-
throw this.invalidateTree(), new S(`orphan resource ${
|
|
504
|
-
|
|
505
|
-
g(
|
|
506
|
-
}), g(
|
|
520
|
+
let o = s;
|
|
521
|
+
for (; o.length > 0; ) {
|
|
522
|
+
const n = [];
|
|
523
|
+
for (const r of o) {
|
|
524
|
+
const f = this.resources.get(r);
|
|
525
|
+
if (!f)
|
|
526
|
+
throw this.invalidateTree(), new S(`orphan resource ${r}`);
|
|
527
|
+
f.refCount--, f.refCount === 0 && f.id !== this.root && (f.fieldsMap.forEach((l) => {
|
|
528
|
+
g(l.value) && n.push(l.value), g(l.error) && n.push(l.error), l.change.markChanged();
|
|
529
|
+
}), g(f.error) && n.push(f.error), f.resourceRemoved.markChanged(), this.resources.delete(r));
|
|
507
530
|
}
|
|
508
|
-
|
|
531
|
+
o = n;
|
|
509
532
|
}
|
|
510
533
|
if (!t) {
|
|
511
|
-
for (const
|
|
512
|
-
if (!this.resources.has(
|
|
513
|
-
throw this.invalidateTree(), new S(`orphan input resource ${
|
|
534
|
+
for (const n of e)
|
|
535
|
+
if (!this.resources.has(n.id))
|
|
536
|
+
throw this.invalidateTree(), new S(`orphan input resource ${n.id}`);
|
|
514
537
|
}
|
|
515
538
|
}
|
|
516
539
|
/** @deprecated use "entry" instead */
|
|
@@ -526,59 +549,59 @@ class V {
|
|
|
526
549
|
});
|
|
527
550
|
}
|
|
528
551
|
}
|
|
529
|
-
function Q(
|
|
530
|
-
const t = [],
|
|
531
|
-
return
|
|
532
|
-
s.
|
|
533
|
-
}), t.length === 0 &&
|
|
552
|
+
function Q(a, e) {
|
|
553
|
+
const t = [], i = /* @__PURE__ */ new Set();
|
|
554
|
+
return a.forEachResource((s) => {
|
|
555
|
+
s.finalState ? i.add(s.id) : t.push(s.id);
|
|
556
|
+
}), t.length === 0 && i.size === 0 && t.push(a.root), { seedResources: t, finalResources: i, pruningFunction: e };
|
|
534
557
|
}
|
|
535
|
-
function
|
|
558
|
+
function F() {
|
|
536
559
|
return {
|
|
537
560
|
requests: 0,
|
|
538
|
-
|
|
561
|
+
roundTrips: 0,
|
|
539
562
|
retrievedResources: 0,
|
|
540
563
|
retrievedFields: 0,
|
|
541
564
|
retrievedKeyValues: 0,
|
|
542
565
|
retrievedResourceDataBytes: 0,
|
|
543
566
|
retrievedKeyValueBytes: 0,
|
|
544
|
-
|
|
567
|
+
prunedFields: 0,
|
|
545
568
|
finalResourcesSkipped: 0,
|
|
546
569
|
millisSpent: 0
|
|
547
570
|
};
|
|
548
571
|
}
|
|
549
|
-
function de(
|
|
550
|
-
let e = `Requests: ${
|
|
572
|
+
function de(a) {
|
|
573
|
+
let e = `Requests: ${a.requests}
|
|
551
574
|
`;
|
|
552
|
-
return e += `Total time: ${z(
|
|
553
|
-
`, e += `
|
|
554
|
-
`, e += `Resources: ${
|
|
555
|
-
`, e += `Fields: ${
|
|
556
|
-
`, e += `KV: ${
|
|
557
|
-
`, e += `Data Bytes: ${
|
|
558
|
-
`, e += `KV Bytes: ${
|
|
559
|
-
`, e += `Pruned fields: ${
|
|
560
|
-
`, e += `Final resources skipped: ${
|
|
575
|
+
return e += `Total time: ${z(a.millisSpent)}
|
|
576
|
+
`, e += `Round-trips: ${a.roundTrips}
|
|
577
|
+
`, e += `Resources: ${a.retrievedResources}
|
|
578
|
+
`, e += `Fields: ${a.retrievedFields}
|
|
579
|
+
`, e += `KV: ${a.retrievedKeyValues}
|
|
580
|
+
`, e += `Data Bytes: ${a.retrievedResourceDataBytes}
|
|
581
|
+
`, e += `KV Bytes: ${a.retrievedKeyValueBytes}
|
|
582
|
+
`, e += `Pruned fields: ${a.prunedFields}
|
|
583
|
+
`, e += `Final resources skipped: ${a.finalResourcesSkipped}`, e;
|
|
561
584
|
}
|
|
562
|
-
async function X(
|
|
563
|
-
var
|
|
564
|
-
const
|
|
585
|
+
async function X(a, e, t) {
|
|
586
|
+
var c;
|
|
587
|
+
const i = Date.now();
|
|
565
588
|
t && t.requests++;
|
|
566
|
-
const { seedResources: s, finalResources:
|
|
567
|
-
let
|
|
568
|
-
const
|
|
569
|
-
if (
|
|
570
|
-
if (
|
|
589
|
+
const { seedResources: s, finalResources: o, pruningFunction: n } = e, r = new H();
|
|
590
|
+
let f = !0, l = 0;
|
|
591
|
+
const h = /* @__PURE__ */ new Set(), k = (p) => {
|
|
592
|
+
if (P(p) || h.has(p)) return;
|
|
593
|
+
if (o.has(p)) {
|
|
571
594
|
t && t.finalResourcesSkipped++;
|
|
572
595
|
return;
|
|
573
596
|
}
|
|
574
|
-
|
|
575
|
-
const v =
|
|
576
|
-
|
|
597
|
+
h.add(p);
|
|
598
|
+
const v = a.getResourceDataIfExists(p, !0), w = a.listKeyValuesIfResourceExists(p), M = f;
|
|
599
|
+
f && (f = !1), r.push(
|
|
577
600
|
(async () => {
|
|
578
|
-
const [
|
|
579
|
-
if (
|
|
580
|
-
if (
|
|
581
|
-
return { ...
|
|
601
|
+
const [I, _] = await Promise.all([v, w]);
|
|
602
|
+
if (M && (l++, f = !0), I !== void 0) {
|
|
603
|
+
if (_ === void 0) throw new Error("Inconsistent replies");
|
|
604
|
+
return { ...I, kv: _ };
|
|
582
605
|
}
|
|
583
606
|
})()
|
|
584
607
|
);
|
|
@@ -586,82 +609,82 @@ async function X(n, e, t) {
|
|
|
586
609
|
s.forEach((p) => k(p));
|
|
587
610
|
const u = [];
|
|
588
611
|
for (; ; ) {
|
|
589
|
-
const p =
|
|
612
|
+
const p = r.shift();
|
|
590
613
|
if (p === void 0)
|
|
591
614
|
break;
|
|
592
615
|
let v = await p;
|
|
593
616
|
if (v !== void 0) {
|
|
594
|
-
if (
|
|
595
|
-
const w =
|
|
596
|
-
t && (t.
|
|
617
|
+
if (n !== void 0) {
|
|
618
|
+
const w = n(v);
|
|
619
|
+
t && (t.prunedFields += v.fields.length - w.length), v = { ...v, fields: w };
|
|
597
620
|
}
|
|
598
621
|
k(v.error);
|
|
599
622
|
for (const w of v.fields)
|
|
600
623
|
k(w.value), k(w.error);
|
|
601
624
|
if (t) {
|
|
602
|
-
t.retrievedResources++, t.retrievedFields += v.fields.length, t.retrievedKeyValues += v.kv.length, t.retrievedResourceDataBytes += ((
|
|
625
|
+
t.retrievedResources++, t.retrievedFields += v.fields.length, t.retrievedKeyValues += v.kv.length, t.retrievedResourceDataBytes += ((c = v.data) == null ? void 0 : c.length) ?? 0;
|
|
603
626
|
for (const w of v.kv) t.retrievedKeyValueBytes += w.value.length;
|
|
604
627
|
}
|
|
605
628
|
u.push(v);
|
|
606
629
|
}
|
|
607
630
|
}
|
|
608
|
-
return t && (t.millisSpent += Date.now() -
|
|
631
|
+
return t && (t.millisSpent += Date.now() - i, t.roundTrips += l), u;
|
|
609
632
|
}
|
|
610
|
-
function ce(
|
|
611
|
-
return
|
|
633
|
+
function ce(a) {
|
|
634
|
+
return a;
|
|
612
635
|
}
|
|
613
|
-
function he(
|
|
614
|
-
var
|
|
615
|
-
const
|
|
616
|
-
if (e.data !== void 0 && (e.data === "raw" ?
|
|
617
|
-
const
|
|
618
|
-
for (const [
|
|
619
|
-
|
|
620
|
-
field:
|
|
621
|
-
errorIfFieldNotSet:
|
|
622
|
-
stableIfNotFound: !
|
|
623
|
-
})) == null ? void 0 :
|
|
624
|
-
|
|
636
|
+
function he(a, e, t) {
|
|
637
|
+
var n;
|
|
638
|
+
const i = a instanceof R ? y(t).accessor(a).node() : a instanceof E ? a.node() : a, o = { ...i.resourceInfo };
|
|
639
|
+
if (e.data !== void 0 && (e.data === "raw" ? o.data = i.getData() : o.data = e.data.parse(i.getDataAsJson())), e.fields !== void 0) {
|
|
640
|
+
const r = {};
|
|
641
|
+
for (const [f, l] of Object.entries(e.fields))
|
|
642
|
+
r[f] = (n = i.traverse({
|
|
643
|
+
field: f,
|
|
644
|
+
errorIfFieldNotSet: l,
|
|
645
|
+
stableIfNotFound: !l
|
|
646
|
+
})) == null ? void 0 : n.id;
|
|
647
|
+
o.fields = r;
|
|
625
648
|
}
|
|
626
649
|
if (e.kv !== void 0) {
|
|
627
|
-
const
|
|
628
|
-
for (const [
|
|
629
|
-
const
|
|
630
|
-
if (
|
|
631
|
-
throw new Error(`Key not found ${
|
|
632
|
-
|
|
650
|
+
const r = {};
|
|
651
|
+
for (const [f, l] of Object.entries(e.kv)) {
|
|
652
|
+
const h = i.getKeyValue(f);
|
|
653
|
+
if (h === void 0)
|
|
654
|
+
throw new Error(`Key not found ${f}`);
|
|
655
|
+
l === "raw" ? r[f] = h : r[f] = l.parse(JSON.parse(Buffer.from(h).toString("utf-8")));
|
|
633
656
|
}
|
|
634
|
-
|
|
657
|
+
o.kv = r;
|
|
635
658
|
}
|
|
636
|
-
return
|
|
659
|
+
return o;
|
|
637
660
|
}
|
|
638
|
-
function le(
|
|
639
|
-
if (
|
|
640
|
-
const
|
|
641
|
-
var
|
|
661
|
+
function le(a, e, t) {
|
|
662
|
+
if (a instanceof R) {
|
|
663
|
+
const i = t.accessor(a).node(), s = i.resourceInfo, o = e.map((n) => {
|
|
664
|
+
var r, f;
|
|
642
665
|
return [
|
|
643
|
-
|
|
644
|
-
(
|
|
666
|
+
n,
|
|
667
|
+
(f = (r = i.getField(n)) == null ? void 0 : r.value) == null ? void 0 : f.id
|
|
645
668
|
];
|
|
646
669
|
});
|
|
647
670
|
return {
|
|
648
671
|
...s,
|
|
649
|
-
fields: new Map(
|
|
650
|
-
data:
|
|
672
|
+
fields: new Map(o),
|
|
673
|
+
data: i.getData() ?? new Uint8Array()
|
|
651
674
|
};
|
|
652
675
|
}
|
|
653
|
-
return
|
|
676
|
+
return a;
|
|
654
677
|
}
|
|
655
|
-
function fe(
|
|
656
|
-
if (!(
|
|
657
|
-
const
|
|
678
|
+
function fe(a, e, t) {
|
|
679
|
+
if (!(a instanceof R)) return a;
|
|
680
|
+
const i = t.accessor(a).node(), s = i.resourceInfo, o = e.map((n) => [n, i.getKeyValue(n)]);
|
|
658
681
|
return {
|
|
659
682
|
...s,
|
|
660
|
-
metadata: Object.fromEntries(
|
|
683
|
+
metadata: Object.fromEntries(o)
|
|
661
684
|
};
|
|
662
685
|
}
|
|
663
686
|
class W {
|
|
664
|
-
constructor(e, t,
|
|
687
|
+
constructor(e, t, i, s) {
|
|
665
688
|
d(this, "finalPredicate");
|
|
666
689
|
d(this, "state");
|
|
667
690
|
d(this, "pollingInterval");
|
|
@@ -677,12 +700,12 @@ class W {
|
|
|
677
700
|
/** If true this tree state is permanently terminaed. */
|
|
678
701
|
d(this, "terminated", !1);
|
|
679
702
|
this.pl = e, this.root = t, this.logger = s;
|
|
680
|
-
const {
|
|
681
|
-
this.pruning =
|
|
703
|
+
const { finalPredicateOverride: o, pruning: n, pollingInterval: r, stopPollingDelay: f, logStat: l } = i;
|
|
704
|
+
this.pruning = n, this.pollingInterval = r, this.finalPredicate = o ?? e.finalPredicate, this.logStat = l, this.state = new V(t, this.finalPredicate), this.hooks = new B(
|
|
682
705
|
() => this.startUpdating(),
|
|
683
706
|
() => this.stopUpdating(),
|
|
684
|
-
{ stopDebounce:
|
|
685
|
-
(
|
|
707
|
+
{ stopDebounce: f },
|
|
708
|
+
(h, k) => this.scheduleOnNextState(h, k)
|
|
686
709
|
);
|
|
687
710
|
}
|
|
688
711
|
/** @deprecated use "entry" instead */
|
|
@@ -714,29 +737,29 @@ class W {
|
|
|
714
737
|
/** Executed from the main loop, and initialization procedure. */
|
|
715
738
|
async refresh(e) {
|
|
716
739
|
if (this.terminated) throw new Error("tree synchronization is terminated");
|
|
717
|
-
const t = Q(this.state, this.pruning),
|
|
718
|
-
this.state.updateFromResourceData(
|
|
740
|
+
const t = Q(this.state, this.pruning), i = await this.pl.withReadTx("ReadingTree", async (s) => await X(s, t, e));
|
|
741
|
+
this.state.updateFromResourceData(i, !0);
|
|
719
742
|
}
|
|
720
743
|
async mainLoop() {
|
|
721
|
-
var t,
|
|
722
|
-
let e = this.logStat ?
|
|
744
|
+
var t, i;
|
|
745
|
+
let e = this.logStat ? F() : void 0;
|
|
723
746
|
for (; this.keepRunning; ) {
|
|
724
747
|
let s;
|
|
725
748
|
this.scheduledOnNextState.length > 0 && (s = this.scheduledOnNextState, this.scheduledOnNextState = []);
|
|
726
749
|
try {
|
|
727
|
-
if (this.logStat === "per-request" && (e =
|
|
728
|
-
} catch (
|
|
729
|
-
if (e && this.logger && this.logger.info(`Tree stat (error): ${JSON.stringify(e)}`), s !== void 0) for (const
|
|
730
|
-
if (
|
|
731
|
-
(t = this.logger) == null || t.error(
|
|
750
|
+
if (this.logStat === "per-request" && (e = F()), await this.refresh(e), e && this.logger && this.logger.info(`Tree stat (success): ${JSON.stringify(e)}`), s !== void 0) for (const o of s) o.resolve();
|
|
751
|
+
} catch (o) {
|
|
752
|
+
if (e && this.logger && this.logger.info(`Tree stat (error): ${JSON.stringify(e)}`), s !== void 0) for (const n of s) n.reject(o);
|
|
753
|
+
if (o instanceof S) {
|
|
754
|
+
(t = this.logger) == null || t.error(o), this.state.invalidateTree("stat update error"), this.state = new V(this.root, this.finalPredicate);
|
|
732
755
|
continue;
|
|
733
|
-
} else (
|
|
756
|
+
} else (i = this.logger) == null || i.warn(o);
|
|
734
757
|
}
|
|
735
758
|
if (!this.keepRunning || this.terminated) break;
|
|
736
759
|
try {
|
|
737
760
|
await j.setTimeout(this.pollingInterval, this.abortController.signal);
|
|
738
|
-
} catch (
|
|
739
|
-
if (!
|
|
761
|
+
} catch (o) {
|
|
762
|
+
if (!q(o)) throw new Error("Unexpected error", { cause: o });
|
|
740
763
|
break;
|
|
741
764
|
}
|
|
742
765
|
}
|
|
@@ -753,10 +776,10 @@ class W {
|
|
|
753
776
|
async awaitSyncLoopTermination() {
|
|
754
777
|
this.currentLoop !== void 0 && await this.currentLoop;
|
|
755
778
|
}
|
|
756
|
-
static async init(e, t,
|
|
757
|
-
const
|
|
758
|
-
let
|
|
759
|
-
return await
|
|
779
|
+
static async init(e, t, i, s) {
|
|
780
|
+
const o = new W(e, t, i, s);
|
|
781
|
+
let n = i.logStat ? F() : void 0;
|
|
782
|
+
return await o.refresh(n), n && s && s.info(`Tree stat (initial load): ${JSON.stringify(n)}`), o;
|
|
760
783
|
}
|
|
761
784
|
}
|
|
762
785
|
export {
|
|
@@ -770,13 +793,13 @@ export {
|
|
|
770
793
|
S as TreeStateUpdateError,
|
|
771
794
|
Q as constructTreeLoadingRequest,
|
|
772
795
|
de as formatTreeLoadingStat,
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
796
|
+
F as initialTreeLoadingStat,
|
|
797
|
+
ae as isPlTreeEntry,
|
|
798
|
+
ne as isPlTreeEntryAccessor,
|
|
799
|
+
oe as isPlTreeNodeAccessor,
|
|
777
800
|
X as loadTreeState,
|
|
778
801
|
he as makeResourceSnapshot,
|
|
779
|
-
|
|
802
|
+
b as mapValueAndError,
|
|
780
803
|
se as mapValueAndErrorIfDefined,
|
|
781
804
|
ce as rsSchema,
|
|
782
805
|
ue as treeEntryToResourceInfo,
|