@webex/plugin-meetings 3.0.0-beta.186 → 3.0.0-beta.187
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/breakouts/breakout.js +1 -1
- package/dist/breakouts/index.js +1 -1
- package/dist/common/queue.js +24 -9
- package/dist/common/queue.js.map +1 -1
- package/dist/interpretation/index.js +1 -1
- package/dist/interpretation/siLanguage.js +1 -1
- package/dist/locus-info/index.js +5 -3
- package/dist/locus-info/index.js.map +1 -1
- package/dist/locus-info/parser.js +174 -59
- package/dist/locus-info/parser.js.map +1 -1
- package/dist/types/common/queue.d.ts +9 -7
- package/dist/types/locus-info/parser.d.ts +50 -7
- package/package.json +19 -19
- package/src/common/queue.ts +22 -8
- package/src/locus-info/index.ts +21 -16
- package/src/locus-info/parser.ts +180 -38
- package/test/unit/spec/common/queue.js +31 -2
- package/test/unit/spec/locus-info/index.js +296 -6
- package/test/unit/spec/locus-info/parser.js +0 -22
|
@@ -14,6 +14,9 @@ var _difference2 = _interopRequireDefault(require("lodash/difference"));
|
|
|
14
14
|
var _queue = _interopRequireDefault(require("../common/queue"));
|
|
15
15
|
var _loggerProxy = _interopRequireDefault(require("../common/logs/logger-proxy"));
|
|
16
16
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10;
|
|
17
|
+
var MAX_OOO_DELTA_COUNT = 5; // when we receive an out-of-order delta and the queue builds up to MAX_OOO_DELTA_COUNT, we do a sync with Locus
|
|
18
|
+
var OOO_DELTA_WAIT_TIME = 10000; // [ms] minimum wait time before we do a sync if we get out-of-order deltas
|
|
19
|
+
var OOO_DELTA_WAIT_TIME_RANDOM_DELAY = 5000; // [ms] max random delay added to OOO_DELTA_WAIT_TIME
|
|
17
20
|
/**
|
|
18
21
|
* Locus Delta Parser
|
|
19
22
|
* @private
|
|
@@ -22,6 +25,8 @@ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _temp
|
|
|
22
25
|
var Parser = /*#__PURE__*/function () {
|
|
23
26
|
// processing status
|
|
24
27
|
|
|
28
|
+
// received an out-of-order delta, so waiting for the missing one
|
|
29
|
+
|
|
25
30
|
// loci comparison states
|
|
26
31
|
|
|
27
32
|
/**
|
|
@@ -29,22 +34,42 @@ var Parser = /*#__PURE__*/function () {
|
|
|
29
34
|
*/
|
|
30
35
|
function Parser() {
|
|
31
36
|
(0, _classCallCheck2.default)(this, Parser);
|
|
37
|
+
(0, _defineProperty2.default)(this, "status", void 0);
|
|
32
38
|
(0, _defineProperty2.default)(this, "queue", void 0);
|
|
33
39
|
(0, _defineProperty2.default)(this, "workingCopy", void 0);
|
|
34
|
-
this
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
(0, _defineProperty2.default)(this, "syncTimer", void 0);
|
|
41
|
+
var deltaCompareFunc = function deltaCompareFunc(left, right) {
|
|
42
|
+
var _Parser$loci = Parser.loci,
|
|
43
|
+
LT = _Parser$loci.LT,
|
|
44
|
+
GT = _Parser$loci.GT;
|
|
45
|
+
var extract = Parser.extractComparisonState;
|
|
46
|
+
if (Parser.isSequenceEmpty(left)) {
|
|
47
|
+
return -1;
|
|
48
|
+
}
|
|
49
|
+
if (Parser.isSequenceEmpty(right)) {
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
var result = extract(Parser.compareSequence(left.baseSequence, right.baseSequence));
|
|
53
|
+
if (result === LT) {
|
|
54
|
+
return -1;
|
|
55
|
+
}
|
|
56
|
+
if (result === GT) {
|
|
57
|
+
return 1;
|
|
58
|
+
}
|
|
59
|
+
return 0;
|
|
60
|
+
};
|
|
61
|
+
this.queue = new _queue.default(deltaCompareFunc);
|
|
62
|
+
this.status = 'IDLE';
|
|
37
63
|
this.onDeltaAction = null;
|
|
38
64
|
this.workingCopy = null;
|
|
65
|
+
this.syncTimer = null;
|
|
39
66
|
}
|
|
40
67
|
|
|
41
68
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @
|
|
46
|
-
* @param {Types~Locus} incoming
|
|
47
|
-
* @returns {string} loci comparison state
|
|
69
|
+
* Returns a debug string representing a locus delta - useful for logging
|
|
70
|
+
*
|
|
71
|
+
* @param {LocusDeltaDto} locus Locus delta
|
|
72
|
+
* @returns {string}
|
|
48
73
|
*/
|
|
49
74
|
(0, _createClass2.default)(Parser, [{
|
|
50
75
|
key: "isNewFullLocus",
|
|
@@ -83,19 +108,11 @@ var Parser = /*#__PURE__*/function () {
|
|
|
83
108
|
* @returns {boolean}
|
|
84
109
|
*/
|
|
85
110
|
function isValidLocus(newLoci) {
|
|
86
|
-
var _this = this;
|
|
87
111
|
var isValid = false;
|
|
88
|
-
var IDLE = Parser.status.IDLE;
|
|
89
112
|
var isLoci = Parser.isLoci;
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
var setStatus = function setStatus(status) {
|
|
92
|
-
// @ts-ignore
|
|
93
|
-
_this.status = status;
|
|
94
|
-
};
|
|
95
113
|
|
|
96
114
|
// one or both objects are not locus delta events
|
|
97
115
|
if (!isLoci(this.workingCopy) || !isLoci(newLoci)) {
|
|
98
|
-
setStatus(IDLE);
|
|
99
116
|
_loggerProxy.default.logger.info('Locus-info:parser#processDeltaEvent --> Ignoring non-locus object. workingCopy:', this.workingCopy, 'newLoci:', newLoci);
|
|
100
117
|
} else {
|
|
101
118
|
isValid = true;
|
|
@@ -117,18 +134,20 @@ var Parser = /*#__PURE__*/function () {
|
|
|
117
134
|
* @returns {undefined}
|
|
118
135
|
*/
|
|
119
136
|
function nextEvent() {
|
|
120
|
-
|
|
121
|
-
if (this.status === Parser.status.PAUSED) {
|
|
137
|
+
if (this.status === 'PAUSED') {
|
|
122
138
|
_loggerProxy.default.logger.info('Locus-info:parser#nextEvent --> Locus parser paused.');
|
|
123
139
|
return;
|
|
124
140
|
}
|
|
141
|
+
if (this.status === 'BLOCKED') {
|
|
142
|
+
_loggerProxy.default.logger.info('Locus-info:parser#nextEvent --> Locus parser blocked by out-of-order delta.');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
125
145
|
|
|
126
146
|
// continue processing until queue is empty
|
|
127
147
|
if (this.queue.size() > 0) {
|
|
128
148
|
this.processDeltaEvent();
|
|
129
149
|
} else {
|
|
130
|
-
|
|
131
|
-
this.status = Parser.status.IDLE;
|
|
150
|
+
this.status = 'IDLE';
|
|
132
151
|
}
|
|
133
152
|
}
|
|
134
153
|
|
|
@@ -154,14 +173,18 @@ var Parser = /*#__PURE__*/function () {
|
|
|
154
173
|
value: function onDeltaEvent(loci) {
|
|
155
174
|
// enqueue the new loci
|
|
156
175
|
this.queue.enqueue(loci);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this.
|
|
176
|
+
if (this.onDeltaAction) {
|
|
177
|
+
if (this.status === 'BLOCKED') {
|
|
178
|
+
if (this.queue.size() > MAX_OOO_DELTA_COUNT) {
|
|
179
|
+
this.triggerSync('queue too big, blocked on out-of-order delta');
|
|
180
|
+
} else {
|
|
181
|
+
this.processDeltaEvent();
|
|
182
|
+
}
|
|
183
|
+
} else if (this.status === 'IDLE') {
|
|
184
|
+
// Update status, ensure we only process one event at a time.
|
|
185
|
+
this.status = 'WORKING';
|
|
186
|
+
this.processDeltaEvent();
|
|
187
|
+
}
|
|
165
188
|
}
|
|
166
189
|
}
|
|
167
190
|
|
|
@@ -179,11 +202,61 @@ var Parser = /*#__PURE__*/function () {
|
|
|
179
202
|
* @returns {undefined}
|
|
180
203
|
*/
|
|
181
204
|
function pause() {
|
|
182
|
-
|
|
183
|
-
this.status = Parser.status.PAUSED;
|
|
205
|
+
this.status = 'PAUSED';
|
|
184
206
|
_loggerProxy.default.logger.info('Locus-info:parser#pause --> Locus parser paused.');
|
|
185
207
|
}
|
|
186
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Triggers a sync with Locus
|
|
211
|
+
*
|
|
212
|
+
* @param {string} reason used just for logging
|
|
213
|
+
* @returns {undefined}
|
|
214
|
+
*/
|
|
215
|
+
}, {
|
|
216
|
+
key: "triggerSync",
|
|
217
|
+
value: function triggerSync(reason) {
|
|
218
|
+
_loggerProxy.default.logger.info("Locus-info:parser#triggerSync --> doing sync, reason: ".concat(reason));
|
|
219
|
+
this.stopSyncTimer();
|
|
220
|
+
this.pause();
|
|
221
|
+
this.onDeltaAction(Parser.loci.DESYNC, this.workingCopy);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Starts a timer with a random delay. When that timer expires we will do a sync.
|
|
226
|
+
*
|
|
227
|
+
* The main purpose of this timer is to handle a case when we get some out-of-order deltas,
|
|
228
|
+
* so we start waiting to receive the missing delta. If that delta never arrives, this timer
|
|
229
|
+
* will trigger a sync with Locus.
|
|
230
|
+
*
|
|
231
|
+
* @returns {undefined}
|
|
232
|
+
*/
|
|
233
|
+
}, {
|
|
234
|
+
key: "startSyncTimer",
|
|
235
|
+
value: function startSyncTimer() {
|
|
236
|
+
var _this = this;
|
|
237
|
+
if (this.syncTimer === null) {
|
|
238
|
+
var timeout = OOO_DELTA_WAIT_TIME + Math.random() * OOO_DELTA_WAIT_TIME_RANDOM_DELAY;
|
|
239
|
+
this.syncTimer = setTimeout(function () {
|
|
240
|
+
_this.syncTimer = null;
|
|
241
|
+
_this.triggerSync('timer expired, blocked on out-of-order delta');
|
|
242
|
+
}, timeout);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Stops the timer for triggering a sync
|
|
248
|
+
*
|
|
249
|
+
* @returns {undefined}
|
|
250
|
+
*/
|
|
251
|
+
}, {
|
|
252
|
+
key: "stopSyncTimer",
|
|
253
|
+
value: function stopSyncTimer() {
|
|
254
|
+
if (this.syncTimer !== null) {
|
|
255
|
+
clearTimeout(this.syncTimer);
|
|
256
|
+
this.syncTimer = null;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
187
260
|
/**
|
|
188
261
|
* Processes next locus delta in the queue,
|
|
189
262
|
* continues until the queue is empty
|
|
@@ -193,12 +266,14 @@ var Parser = /*#__PURE__*/function () {
|
|
|
193
266
|
}, {
|
|
194
267
|
key: "processDeltaEvent",
|
|
195
268
|
value: function processDeltaEvent() {
|
|
196
|
-
var _Parser$
|
|
197
|
-
DESYNC = _Parser$
|
|
198
|
-
USE_INCOMING = _Parser$
|
|
269
|
+
var _Parser$loci2 = Parser.loci,
|
|
270
|
+
DESYNC = _Parser$loci2.DESYNC,
|
|
271
|
+
USE_INCOMING = _Parser$loci2.USE_INCOMING,
|
|
272
|
+
WAIT = _Parser$loci2.WAIT;
|
|
199
273
|
var extract = Parser.extractComparisonState;
|
|
200
274
|
var newLoci = this.queue.dequeue();
|
|
201
275
|
if (!this.isValidLocus(newLoci)) {
|
|
276
|
+
this.nextEvent();
|
|
202
277
|
return;
|
|
203
278
|
}
|
|
204
279
|
var result = Parser.compare(this.workingCopy, newLoci);
|
|
@@ -207,6 +282,7 @@ var Parser = /*#__PURE__*/function () {
|
|
|
207
282
|
// limited debugging, use chrome extension
|
|
208
283
|
// for full debugging.
|
|
209
284
|
_loggerProxy.default.logger.debug("Locus-info:parser#processDeltaEvent --> Locus Debug: ".concat(result));
|
|
285
|
+
var needToWait = false;
|
|
210
286
|
if (lociComparison === DESYNC) {
|
|
211
287
|
// wait for desync response
|
|
212
288
|
this.pause();
|
|
@@ -215,12 +291,26 @@ var Parser = /*#__PURE__*/function () {
|
|
|
215
291
|
// Note: The working copy of parser gets updated in .onFullLocus()
|
|
216
292
|
// and here when USE_INCOMING locus.
|
|
217
293
|
this.workingCopy = newLoci;
|
|
294
|
+
} else if (lociComparison === WAIT) {
|
|
295
|
+
// we've taken newLoci from the front of the queue, so put it back there as we have to wait
|
|
296
|
+
// for the one that should be in front of it, before we can process it
|
|
297
|
+
this.queue.enqueue(newLoci);
|
|
298
|
+
needToWait = true;
|
|
299
|
+
}
|
|
300
|
+
if (needToWait) {
|
|
301
|
+
this.status = 'BLOCKED';
|
|
302
|
+
this.startSyncTimer();
|
|
303
|
+
} else {
|
|
304
|
+
this.stopSyncTimer();
|
|
305
|
+
if (this.status === 'BLOCKED') {
|
|
306
|
+
// we are not blocked anymore
|
|
307
|
+
this.status = 'WORKING';
|
|
308
|
+
_loggerProxy.default.logger.info("Locus-info:parser#processDeltaEvent --> received delta that we were waiting for ".concat(Parser.locus2string(newLoci), ", not blocked anymore"));
|
|
309
|
+
}
|
|
218
310
|
}
|
|
219
311
|
if (this.onDeltaAction) {
|
|
220
|
-
_loggerProxy.default.logger.info("Locus-info:parser#processDeltaEvent --> Locus Delta Action: ".concat(lociComparison));
|
|
221
|
-
|
|
222
|
-
// eslint-disable-next-line no-useless-call
|
|
223
|
-
this.onDeltaAction.call(this, lociComparison, newLoci);
|
|
312
|
+
_loggerProxy.default.logger.info("Locus-info:parser#processDeltaEvent --> Locus Delta ".concat(Parser.locus2string(newLoci), ", Action: ").concat(lociComparison));
|
|
313
|
+
this.onDeltaAction(lociComparison, newLoci);
|
|
224
314
|
}
|
|
225
315
|
this.nextEvent();
|
|
226
316
|
}
|
|
@@ -233,8 +323,7 @@ var Parser = /*#__PURE__*/function () {
|
|
|
233
323
|
key: "resume",
|
|
234
324
|
value: function resume() {
|
|
235
325
|
_loggerProxy.default.logger.info('Locus-info:parser#resume --> Locus parser resumed.');
|
|
236
|
-
|
|
237
|
-
this.status = Parser.status.WORKING;
|
|
326
|
+
this.status = 'WORKING';
|
|
238
327
|
this.nextEvent();
|
|
239
328
|
}
|
|
240
329
|
|
|
@@ -245,6 +334,24 @@ var Parser = /*#__PURE__*/function () {
|
|
|
245
334
|
* @returns {object} Debug message
|
|
246
335
|
*/
|
|
247
336
|
}], [{
|
|
337
|
+
key: "locus2string",
|
|
338
|
+
value: function locus2string(locus) {
|
|
339
|
+
var _locus$sequence;
|
|
340
|
+
if (!((_locus$sequence = locus.sequence) !== null && _locus$sequence !== void 0 && _locus$sequence.entries)) {
|
|
341
|
+
return 'invalid';
|
|
342
|
+
}
|
|
343
|
+
return locus.sequence.entries.length ? "seq=".concat(locus.sequence.entries.at(-1)) : 'empty';
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Checks if two sequences overlap in time,
|
|
348
|
+
* the sequence with the higher minimum value is greater.
|
|
349
|
+
* Chooses sequence with most recent data.
|
|
350
|
+
* @param {Types~Locus} current
|
|
351
|
+
* @param {Types~Locus} incoming
|
|
352
|
+
* @returns {string} loci comparison state
|
|
353
|
+
*/
|
|
354
|
+
}, {
|
|
248
355
|
key: "checkSequenceOverlap",
|
|
249
356
|
value: function checkSequenceOverlap(current, incoming) {
|
|
250
357
|
var comparison = null;
|
|
@@ -409,12 +516,13 @@ var Parser = /*#__PURE__*/function () {
|
|
|
409
516
|
}, {
|
|
410
517
|
key: "compareDelta",
|
|
411
518
|
value: function compareDelta(current, incoming) {
|
|
412
|
-
var _Parser$
|
|
413
|
-
LT = _Parser$
|
|
414
|
-
GT = _Parser$
|
|
415
|
-
EQ = _Parser$
|
|
416
|
-
DESYNC = _Parser$
|
|
417
|
-
USE_INCOMING = _Parser$
|
|
519
|
+
var _Parser$loci3 = Parser.loci,
|
|
520
|
+
LT = _Parser$loci3.LT,
|
|
521
|
+
GT = _Parser$loci3.GT,
|
|
522
|
+
EQ = _Parser$loci3.EQ,
|
|
523
|
+
DESYNC = _Parser$loci3.DESYNC,
|
|
524
|
+
USE_INCOMING = _Parser$loci3.USE_INCOMING,
|
|
525
|
+
WAIT = _Parser$loci3.WAIT;
|
|
418
526
|
var extract = Parser.extractComparisonState;
|
|
419
527
|
var pack = Parser.packComparisonResult;
|
|
420
528
|
var result = Parser.compareSequence(current.sequence, incoming.sequence);
|
|
@@ -428,6 +536,17 @@ var Parser = /*#__PURE__*/function () {
|
|
|
428
536
|
case EQ:
|
|
429
537
|
comparison = USE_INCOMING;
|
|
430
538
|
break;
|
|
539
|
+
case LT:
|
|
540
|
+
if (extract(Parser.compareSequence(incoming.baseSequence, incoming.sequence)) === EQ) {
|
|
541
|
+
// special case where Locus sends a delta with baseSequence === sequence to trigger a sync,
|
|
542
|
+
// because the delta event is too large to be sent over mercury connection
|
|
543
|
+
comparison = DESYNC;
|
|
544
|
+
} else {
|
|
545
|
+
// the incoming locus has baseSequence from the future, so it is out-of-order,
|
|
546
|
+
// we are missing 1 or more locus that should be in front of it, we need to wait for it
|
|
547
|
+
comparison = WAIT;
|
|
548
|
+
}
|
|
549
|
+
break;
|
|
431
550
|
default:
|
|
432
551
|
comparison = DESYNC;
|
|
433
552
|
}
|
|
@@ -493,14 +612,14 @@ var Parser = /*#__PURE__*/function () {
|
|
|
493
612
|
}, {
|
|
494
613
|
key: "compareToAction",
|
|
495
614
|
value: function compareToAction(result) {
|
|
496
|
-
var _Parser$
|
|
497
|
-
DESYNC = _Parser$
|
|
498
|
-
EQ = _Parser$
|
|
499
|
-
ERROR = _Parser$
|
|
500
|
-
GT = _Parser$
|
|
501
|
-
LT = _Parser$
|
|
502
|
-
USE_CURRENT = _Parser$
|
|
503
|
-
USE_INCOMING = _Parser$
|
|
615
|
+
var _Parser$loci4 = Parser.loci,
|
|
616
|
+
DESYNC = _Parser$loci4.DESYNC,
|
|
617
|
+
EQ = _Parser$loci4.EQ,
|
|
618
|
+
ERROR = _Parser$loci4.ERROR,
|
|
619
|
+
GT = _Parser$loci4.GT,
|
|
620
|
+
LT = _Parser$loci4.LT,
|
|
621
|
+
USE_CURRENT = _Parser$loci4.USE_CURRENT,
|
|
622
|
+
USE_INCOMING = _Parser$loci4.USE_INCOMING;
|
|
504
623
|
var action = ERROR;
|
|
505
624
|
switch (result) {
|
|
506
625
|
case EQ:
|
|
@@ -716,11 +835,6 @@ var Parser = /*#__PURE__*/function () {
|
|
|
716
835
|
return Parser;
|
|
717
836
|
}();
|
|
718
837
|
exports.default = Parser;
|
|
719
|
-
(0, _defineProperty2.default)(Parser, "status", {
|
|
720
|
-
IDLE: 'IDLE',
|
|
721
|
-
PAUSED: 'PAUSED',
|
|
722
|
-
WORKING: 'WORKING'
|
|
723
|
-
});
|
|
724
838
|
(0, _defineProperty2.default)(Parser, "loci", {
|
|
725
839
|
EQ: 'EQUAL',
|
|
726
840
|
GT: 'GREATER_THAN',
|
|
@@ -728,6 +842,7 @@ exports.default = Parser;
|
|
|
728
842
|
DESYNC: 'DESYNC',
|
|
729
843
|
USE_INCOMING: 'USE_INCOMING',
|
|
730
844
|
USE_CURRENT: 'USE_CURRENT',
|
|
845
|
+
WAIT: 'WAIT',
|
|
731
846
|
ERROR: 'ERROR'
|
|
732
847
|
});
|
|
733
848
|
//# sourceMappingURL=parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Parser","queue","SimpleQueue","status","IDLE","onDeltaAction","workingCopy","incomingFullDto","isLoci","LoggerProxy","logger","info","comparisonResult","compareFullDtoSequence","loci","USE_INCOMING","newLoci","isValid","setStatus","PAUSED","size","processDeltaEvent","action","locus","enqueue","WORKING","DESYNC","extract","extractComparisonState","dequeue","isValidLocus","result","compare","lociComparison","debug","pause","call","nextEvent","current","incoming","comparison","min","max","GT","LT","currentIsNotUnique","unique","length","incomingIsNotUnique","currentTotalRange","end","incomingTotalRange","EQ","currentIsUnique","incomingIsUnique","currentUniqueMin","incomingUniqueMin","currentHasNoRange","start","incomingHasNoRange","neitherSeqHasRange","hasUniqOverlap","list","some","seq","currentUniqOverlap","incomingUniqOverlap","debugInfo","isSequenceEmpty","pack","packComparisonResult","baseSequence","compareDelta","compareSequence","sequence","compareToAction","entries","slice","USE_CURRENT","local","getMetaData","delta","getUniqueSequences","rules","checkSequenceOverlap","checkUnequalRanges","checkForUniqueEntries","checkIfOutOfSync","rule","ERROR","lociComparisonResult","split","first","last","rangeStart","rangeEnd","baseLoci","otherLoci","diff","getNumbersOutOfRange","output","filter","num","sort","a","b","hasEmptyEntries","hasEmptyRange","hasProp","prop","Object","prototype","hasOwnProperty","newData","oldData","debugCode","mStr","strings","join","replace","resolutionMap","debugMap","SO001","title","description","logic","SO002","UR001","UR002","UR003","UE001","UE002","OOS001","OOS002","OOS003","debugObj","resolution"],"sources":["parser.ts"],"sourcesContent":["import {difference} from 'lodash';\n\nimport SimpleQueue from '../common/queue';\nimport LoggerProxy from '../common/logs/logger-proxy';\n\n/**\n * Locus Delta Parser\n * @private\n * https://sqbu-github.cisco.com/WebExSquared/cloud-apps/wiki/Locus-Delta-Events\n */\nexport default class Parser {\n // processing status\n static status = {\n IDLE: 'IDLE',\n PAUSED: 'PAUSED',\n WORKING: 'WORKING',\n };\n\n // loci comparison states\n static loci = {\n EQ: 'EQUAL',\n GT: 'GREATER_THAN',\n LT: 'LESS_THAN',\n DESYNC: 'DESYNC',\n USE_INCOMING: 'USE_INCOMING',\n USE_CURRENT: 'USE_CURRENT',\n ERROR: 'ERROR',\n };\n\n queue: SimpleQueue;\n workingCopy: any;\n\n /**\n * @constructs Parser\n */\n constructor() {\n this.queue = new SimpleQueue();\n // @ts-ignore - This is declared as static class member and again being initialized here from same\n this.status = Parser.status.IDLE;\n this.onDeltaAction = null;\n this.workingCopy = null;\n }\n\n /**\n * Checks if two sequences overlap in time,\n * the sequence with the higher minimum value is greater.\n * Chooses sequence with most recent data.\n * @param {Types~Locus} current\n * @param {Types~Locus} incoming\n * @returns {string} loci comparison state\n */\n static checkSequenceOverlap(current, incoming) {\n let comparison = null;\n\n // if earliest working copy sequence is more recent than last incoming sequence\n if (current.min > incoming.max) {\n // choose left side (current)\n comparison = `${Parser.loci.GT}:SO001`;\n }\n // if last working copy sequence is before the earliest incoming sequence\n else if (current.max < incoming.min) {\n // choose right side (incoming)\n comparison = `${Parser.loci.LT}:SO002`;\n }\n\n // if no match above, defaults to null\n return comparison;\n }\n\n /**\n * Checks if two sequences have unequal ranges.\n * Chooses sequence with most larger range.\n * @param {Types~Locus} current\n * @param {Types~Locus} incoming\n * @returns {object} loci comparison\n */\n static checkUnequalRanges(current, incoming) {\n let comparison = null;\n const currentIsNotUnique = current.unique.length === 0;\n const incomingIsNotUnique = incoming.unique.length === 0;\n const currentTotalRange = current.end - current.min;\n const incomingTotalRange = incoming.end - incoming.min;\n\n // no unique values for both loci\n if (currentIsNotUnique && incomingIsNotUnique) {\n // current working copy loci has a larger range\n if (currentTotalRange > incomingTotalRange) {\n // choose left side (current)\n comparison = `${Parser.loci.GT}:UR001`;\n }\n // incoming delta loci has a larger range\n else if (currentTotalRange < incomingTotalRange) {\n // choose right side (incoming)\n comparison = `${Parser.loci.LT}:UR002`;\n } else {\n // with no unique entries and with ranges either absent or\n // of the same size, the sequences are considered equal.\n comparison = `${Parser.loci.EQ}:UR003`;\n }\n }\n\n return comparison;\n }\n\n /**\n * Checks if either sequences has unique entries.\n * Entries are considered unique if they do not overlap\n * with other Loci sequences or range values.\n * Chooses sequence with the unique entries.\n * @param {Types~Locus} current\n * @param {Types~Locus} incoming\n * @returns {string} loci comparison state\n */\n static checkForUniqueEntries(current, incoming) {\n let comparison = null;\n const currentIsUnique = current.unique.length > 0;\n const incomingIsUnique = incoming.unique.length > 0;\n\n // current has unique entries and incoming does not\n if (currentIsUnique && !incomingIsUnique) {\n // choose left side (current)\n comparison = `${Parser.loci.GT}:UE001`;\n }\n // current has no unique entries but incoming does\n else if (!currentIsUnique && incomingIsUnique) {\n // choose right side (incoming)\n comparison = `${Parser.loci.LT}:UE002`;\n }\n\n return comparison;\n }\n\n /**\n * Checks both Locus Delta objects to see if they are\n * out of sync with one another. If so sends a DESYNC\n * request to the server.\n * @param {Types~Locus} current\n * @param {Types~Locus} incoming\n * @returns {string} loci comparison state\n */\n static checkIfOutOfSync(current, incoming) {\n let comparison = null;\n const currentUniqueMin = current.unique[0];\n const incomingUniqueMin = incoming.unique[0];\n\n const currentHasNoRange = !current.start && !current.end;\n const incomingHasNoRange = !incoming.start && !incoming.end;\n const neitherSeqHasRange = currentHasNoRange && incomingHasNoRange;\n\n const hasUniqOverlap = (list, min, max) => list.some((seq) => min < seq && seq < max);\n // current unique entries overlap the total range of incoming\n const currentUniqOverlap = hasUniqOverlap(current.unique, incoming.min, incoming.max);\n // vice-versa, incoming unique entries overlap the total range of current\n const incomingUniqOverlap = hasUniqOverlap(incoming.unique, current.min, current.max);\n\n if (neitherSeqHasRange || currentUniqOverlap || incomingUniqOverlap) {\n // outputs string indicating which condition occurred. ex: 0,1,0\n const debugInfo = `${+neitherSeqHasRange},${+currentUniqOverlap},${+incomingUniqOverlap}`;\n\n // send DESYNC to server\n comparison = `${Parser.loci.DESYNC}:OOS001:${debugInfo}`;\n } else if (currentUniqueMin > incomingUniqueMin) {\n // choose left side (current)\n comparison = `${Parser.loci.GT}:OOS002`;\n } else {\n // choose right side (incoming)\n comparison = `${Parser.loci.LT}:OOS003`;\n }\n\n return comparison;\n }\n\n /**\n * Compares two loci to determine which one contains the most recent state\n * @instance\n * @memberof Locus\n * @param {Types~Locus} current\n * @param {Types~Locus} incoming\n * @returns {string} loci comparison state\n */\n static compare(current, incoming) {\n const {isSequenceEmpty} = Parser;\n const {extractComparisonState: extract} = Parser;\n const {packComparisonResult: pack} = Parser;\n\n if (isSequenceEmpty(current) || isSequenceEmpty(incoming)) {\n return pack(Parser.loci.USE_INCOMING, 'C001');\n }\n\n if (incoming.baseSequence) {\n return pack(Parser.compareDelta(current, incoming), 'C002');\n }\n\n const result = Parser.compareSequence(current.sequence, incoming.sequence);\n const action = Parser.compareToAction(extract(result));\n\n return pack(action, result);\n }\n\n /**\n * Compares two loci sequences (with delta params) and indicates what action\n * to take.\n * @instance\n * @memberof Locus\n * @param {Types~Locus} current\n * @param {Types~Locus} incoming\n * @private\n * @returns {string} loci comparison state\n */\n private static compareDelta(current, incoming) {\n const {LT, GT, EQ, DESYNC, USE_INCOMING} = Parser.loci;\n\n const {extractComparisonState: extract} = Parser;\n const {packComparisonResult: pack} = Parser;\n\n const result = Parser.compareSequence(current.sequence, incoming.sequence);\n let comparison = extract(result);\n\n if (comparison !== LT) {\n return pack(Parser.compareToAction(comparison), result);\n }\n\n comparison = Parser.compareSequence(current.sequence, incoming.baseSequence);\n\n switch (extract(comparison)) {\n case GT:\n case EQ:\n comparison = USE_INCOMING;\n break;\n\n default:\n comparison = DESYNC;\n }\n\n return pack(comparison, result);\n }\n\n /**\n * Compares Locus sequences - it should be called only for full Locus DTOs, not deltas\n *\n * @param {Types~Locus} current Current working copy\n * @param {Types~Locus} incomingFullDto New Full Locus DTO\n * @returns {string} either Parser.loci.USE_INCOMING or Parser.loci.USE_CURRENT\n */\n static compareFullDtoSequence(current, incomingFullDto) {\n if (Parser.isSequenceEmpty(current) || Parser.isSequenceEmpty(incomingFullDto)) {\n return Parser.loci.USE_INCOMING;\n }\n\n // the sequence.entries list will always contain at least 1 entry\n // https://sqbu-github.cisco.com/WebExSquared/cloud-apps/wiki/Locus-Sequence-Comparison-Algorithm\n\n return incomingFullDto.sequence.entries.slice(-1)[0] > current.sequence.entries.slice(-1)[0]\n ? Parser.loci.USE_INCOMING\n : Parser.loci.USE_CURRENT;\n }\n\n /**\n * Returns true if the incoming full locus DTO is newer than the current working copy\n *\n * @param {Types~Locus} incomingFullDto New Full Locus DTO\n * @returns {string} either Parser.loci.USE_INCOMING or Parser.loci.USE_CURRENT\n */\n isNewFullLocus(incomingFullDto) {\n if (!Parser.isLoci(incomingFullDto)) {\n LoggerProxy.logger.info('Locus-info:parser#isNewFullLocus --> Ignoring non-locus object.');\n\n return false;\n }\n\n if (!this.workingCopy) {\n // we don't have a working copy yet, so any full locus is better than nothing\n return true;\n }\n\n const comparisonResult = Parser.compareFullDtoSequence(this.workingCopy, incomingFullDto);\n\n return comparisonResult === Parser.loci.USE_INCOMING;\n }\n\n /**\n * Compares Locus sequences\n * @param {Types~Locus} current Current working copy\n * @param {Types~Locus} incoming New Locus delta\n * @returns {string}\n */\n static compareSequence(current, incoming) {\n // Locus sequence comparison rules in order of priority.\n // https://sqbu-github.cisco.com/WebExSquared/cloud-apps/wiki/Locus-Sequence-Comparison-Algorithm\n\n const local: any = Parser.getMetaData(current);\n const delta: any = Parser.getMetaData(incoming);\n\n // update loci metadata\n local.unique = Parser.getUniqueSequences(local, delta);\n delta.unique = Parser.getUniqueSequences(delta, local);\n\n // Locus sequence comparison rules\n // order matters\n const rules = [\n Parser.checkSequenceOverlap,\n Parser.checkUnequalRanges,\n Parser.checkForUniqueEntries,\n Parser.checkIfOutOfSync,\n ];\n\n for (const rule of rules) {\n // Rule only returns a value if the rule applies,\n // otherwise returns null.\n const result = rule(local, delta);\n\n if (result) {\n return result;\n }\n }\n\n // error, none of rules above applied\n // should never get here as last rule\n // should be catch all.\n return Parser.loci.ERROR;\n }\n\n /**\n * Transates the result of a sequence comparison into an intended behavior\n * @param {string} result\n * @returns {string} Locus comparison action\n */\n static compareToAction(result: string) {\n const {DESYNC, EQ, ERROR, GT, LT, USE_CURRENT, USE_INCOMING} = Parser.loci;\n\n let action = ERROR;\n\n switch (result) {\n case EQ:\n case GT:\n action = USE_CURRENT;\n break;\n case LT:\n action = USE_INCOMING;\n break;\n case DESYNC:\n action = DESYNC;\n break;\n default:\n LoggerProxy.logger.info(\n `Locus-info:parser#compareToAction --> Error: ${result} is not a recognized sequence comparison result.`\n );\n }\n\n return action;\n }\n\n /**\n * Extracts a loci comparison from a string of data.\n * @param {string} lociComparisonResult Comparison result with extra data\n * @returns {string} Comparison of EQ, LT, GT, or DESYNC.\n */\n static extractComparisonState(lociComparisonResult: string) {\n return lociComparisonResult.split(':')[0];\n }\n\n /**\n * @typedef {object} LociMetadata\n * @property {number} start - Starting sequence number\n * @property {number} end - Ending sequence number\n * @property {number} first - First sequence number\n * @property {number} last - Last sequence number\n * @property {number} min - Minimum sequence number\n * @property {number} max - Maximum sequence number\n * @property {number} entries - Loci sequence entries\n */\n\n /**\n * Metadata for Locus delta\n * @param {Array.<number>} sequence Locus delta sequence\n * @returns {LociMetadata} Locus Delta Metadata\n */\n static getMetaData(sequence: any) {\n const {entries} = sequence;\n const first = entries[0];\n const last = entries.slice(-1)[0];\n\n // rangeStart or rangeEnd is 0 if a range doesn't exist\n const start = sequence.rangeStart;\n const end = sequence.rangeEnd;\n\n // sequence data\n return {\n start,\n end,\n first,\n last,\n // Rule is: rangeStart <= rangeEnd <= min(entries)\n min: start || first,\n // Grab last entry if exist else default to rangeEnd\n max: last || end,\n // keep reference to actual sequence entries\n entries,\n };\n }\n\n /**\n * Compares two Locus delta objects and notes unique\n * values contained within baseLoci.\n * @param {LociMetadata} baseLoci\n * @param {LociMetadata} otherLoci\n * @returns {Array.<number>} List of unique sequences\n */\n static getUniqueSequences(baseLoci: any, otherLoci: any) {\n const diff: any = difference(baseLoci.entries, otherLoci.entries);\n\n const {start, end} = otherLoci;\n\n return Parser.getNumbersOutOfRange(diff, start, end);\n }\n\n /**\n * Returns an array of numbers outside of a given range.\n * @param {Array.<number>} list Array to filter\n * @param {number} rangeStart Start of range\n * @param {number} rangeEnd End of range\n * @returns {Array.<number>} Array of numbers sorted ASC\n */\n static getNumbersOutOfRange(list: Array<number>, rangeStart: number, rangeEnd: number) {\n // Collect all numbers if number is outside of specified range\n const output = list.filter((num) => num < rangeStart || num > rangeEnd);\n\n // sort ascending\n return output.sort((a, b) => a - b);\n }\n\n /**\n * Checks if newLoci or workingCopy is invalid.\n * @param {Types~Locus} newLoci\n * @returns {boolean}\n */\n isValidLocus(newLoci) {\n let isValid = false;\n const {IDLE} = Parser.status;\n const {isLoci} = Parser;\n // @ts-ignore\n const setStatus = (status) => {\n // @ts-ignore\n this.status = status;\n };\n\n // one or both objects are not locus delta events\n if (!isLoci(this.workingCopy) || !isLoci(newLoci)) {\n setStatus(IDLE);\n LoggerProxy.logger.info(\n 'Locus-info:parser#processDeltaEvent --> Ignoring non-locus object. workingCopy:',\n this.workingCopy,\n 'newLoci:',\n newLoci\n );\n } else {\n isValid = true;\n }\n\n return isValid;\n }\n\n /**\n * Determines if a paricular locus's sequence is empty\n * @param {Types~Locus} locus\n * @returns {bool}\n */\n static isSequenceEmpty(locus) {\n const {sequence} = locus;\n const hasEmptyEntries = !sequence.entries?.length;\n const hasEmptyRange = sequence.rangeStart === 0 && sequence.rangeEnd === 0;\n\n return hasEmptyEntries && hasEmptyRange;\n }\n\n /**\n * Determines if an object has basic\n * structure of a locus object.\n * @param {Types~Locus} loci\n * @returns {boolean}\n */\n static isLoci(loci) {\n if (!loci || !loci.sequence) {\n return false;\n }\n const hasProp = (prop) => Object.prototype.hasOwnProperty.call(loci.sequence, prop);\n\n if (hasProp('rangeStart') && hasProp('rangeEnd')) {\n return true;\n }\n\n return false;\n }\n\n /**\n * Processes next event in queue,\n * if queue is empty sets status to idle.\n * @returns {undefined}\n */\n nextEvent() {\n // @ts-ignore\n if (this.status === Parser.status.PAUSED) {\n LoggerProxy.logger.info('Locus-info:parser#nextEvent --> Locus parser paused.');\n\n return;\n }\n\n // continue processing until queue is empty\n if (this.queue.size() > 0) {\n this.processDeltaEvent();\n } else {\n // @ts-ignore\n this.status = Parser.status.IDLE;\n }\n }\n\n /**\n * Function handler for delta actions,\n * is set by instance callee.\n * @param {string} action Locus delta action\n * @param {Types~Locus} locus Locus delta\n * @returns {undefined}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onDeltaAction(action: string, locus) {}\n\n /**\n * Event handler for locus delta events\n * @param {Types~Locus} loci Locus Delta\n * @returns {undefined}\n */\n onDeltaEvent(loci) {\n // enqueue the new loci\n this.queue.enqueue(loci);\n // start processing events in the queue if idle\n // and a function handler is defined\n // @ts-ignore\n if (this.status === Parser.status.IDLE && this.onDeltaAction) {\n // Update status, ensure we only process one event at a time.\n // @ts-ignore\n this.status = Parser.status.WORKING;\n\n this.processDeltaEvent();\n }\n }\n\n /**\n * Appends new data onto a string of existing data.\n * @param {string} newData\n * @param {string} oldData\n * @returns {string}\n */\n static packComparisonResult(newData: string, oldData: string) {\n return `${newData}:${oldData}`;\n }\n\n /**\n * Pause locus processing\n * @returns {undefined}\n */\n pause() {\n // @ts-ignore\n this.status = Parser.status.PAUSED;\n LoggerProxy.logger.info('Locus-info:parser#pause --> Locus parser paused.');\n }\n\n /**\n * Processes next locus delta in the queue,\n * continues until the queue is empty\n * or cleared.\n * @returns {undefined}\n */\n processDeltaEvent() {\n const {DESYNC, USE_INCOMING} = Parser.loci;\n const {extractComparisonState: extract} = Parser;\n const newLoci = this.queue.dequeue();\n\n if (!this.isValidLocus(newLoci)) {\n return;\n }\n\n const result = Parser.compare(this.workingCopy, newLoci);\n const lociComparison = extract(result);\n\n // limited debugging, use chrome extension\n // for full debugging.\n LoggerProxy.logger.debug(`Locus-info:parser#processDeltaEvent --> Locus Debug: ${result}`);\n\n if (lociComparison === DESYNC) {\n // wait for desync response\n this.pause();\n } else if (lociComparison === USE_INCOMING) {\n // update working copy for future comparisons.\n // Note: The working copy of parser gets updated in .onFullLocus()\n // and here when USE_INCOMING locus.\n this.workingCopy = newLoci;\n }\n\n if (this.onDeltaAction) {\n LoggerProxy.logger.info(\n `Locus-info:parser#processDeltaEvent --> Locus Delta Action: ${lociComparison}`\n );\n\n // eslint-disable-next-line no-useless-call\n this.onDeltaAction.call(this, lociComparison, newLoci);\n }\n\n this.nextEvent();\n }\n\n /**\n * Resume from a paused state\n * @returns {undefined}\n */\n resume() {\n LoggerProxy.logger.info('Locus-info:parser#resume --> Locus parser resumed.');\n // @ts-ignore\n this.status = Parser.status.WORKING;\n this.nextEvent();\n }\n\n /**\n * Gets related debug info for given error code\n * @param {string} debugCode Debug code\n * @param {string} comparison Locus comparison string\n * @returns {object} Debug message\n */\n static getDebugMessage(debugCode: string, comparison: string) {\n // removes extra spaces from multiline string\n const mStr = (strings) => strings.join('').replace(/\\s{2,}/g, ' ');\n\n const resolutionMap = {\n EQ: `${Parser.loci.LT}: is equal (current == incoming).`,\n LT: `${Parser.loci.LT}: choose right side (incoming).`,\n GT: `${Parser.loci.GT}: choose left side (current).`,\n };\n\n const debugMap = {\n SO001: {\n title: 'checkSequenceOverlap-001',\n description: mStr`Occurs if earliest working copy sequence is more \\\n recent than last incoming sequence.`,\n logic: 'current.min > incoming.max',\n },\n\n SO002: {\n title: 'checkSequenceOverlap-002',\n description: mStr`Occurs if last working copy sequence is before the \\\n earliest incoming sequence.`,\n logic: 'current.max < incoming.min',\n },\n\n UR001: {\n title: 'checkUnequalRanges-001',\n description: mStr`Occurs if there are no unique values for both loci, \\\n and the current working copy loci has a larger range.`,\n logic: 'currentTotalRange > incomingTotalRange',\n },\n\n UR002: {\n title: 'checkUnequalRanges-002',\n description: mStr`Occurs if there are no unique values for both loci, \\\n and the incoming delta loci has a larger range.`,\n logic: 'currentTotalRange < incomingTotalRange',\n },\n\n UR003: {\n title: 'checkUnequalRanges-003',\n description: mStr`Occurs if there are no unique values for both loci, \\\n and with ranges either absent or of the same size, the sequences \\\n are considered equal.`,\n logic: 'currentTotalRange == incomingTotalRange',\n },\n\n UE001: {\n title: 'checkForUniqueEntries-001',\n description: mStr`Occurs if current loci has unique entries and \\\n incoming does not. Entries are considered unique if they \\\n do not overlap with other Loci sequences or range values.`,\n logic: 'currentIsUnique && !incomingIsUnique',\n },\n\n UE002: {\n title: 'checkForUniqueEntries-002',\n description: mStr`Occurs if current has no unique entries but \\\n incoming does. Entries are considered unique if they \\\n do not overlap with other Loci sequences or range values.`,\n logic: '!currentIsUnique && incomingIsUnique',\n },\n\n OOS001: {\n title: 'checkIfOutOfSync-001',\n description: mStr`Occurs if neither sequence has a range, or \\\n if the current loci unique entries overlap the total range of the \\\n incoming sequence, or if the incoming unique entries overlap \\\n the total range of current sequence.`,\n logic: 'neitherSeqHasRange || currentUniqOverlap || incomingUniqOverlap',\n },\n\n OOS002: {\n title: 'checkIfOutOfSync-002',\n description: mStr`Occurs if the minimum value from sequences that are \\\n unique to the current loci is greater than the minimum value from \\\n sequences that are unique to the incoming loci.`,\n logic: 'currentUniqueMin > incomingUniqueMin',\n },\n\n OOS003: {\n title: 'checkIfOutOfSync-003',\n description: mStr`Occurs if none of the comparison rules applied. \\\n It is a catch all.`,\n logic: 'else (catch all)',\n },\n };\n\n const debugObj = debugMap[debugCode];\n\n debugObj.title = `Debug: ${debugObj.title}`;\n debugObj.resolution = resolutionMap[comparison];\n\n return debugObj;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAEA;AACA;AAAsD;AAEtD;AACA;AACA;AACA;AACA;AAJA,IAKqBA,MAAM;EACzB;;EAOA;;EAcA;AACF;AACA;EACE,kBAAc;IAAA;IAAA;IAAA;IACZ,IAAI,CAACC,KAAK,GAAG,IAAIC,cAAW,EAAE;IAC9B;IACA,IAAI,CAACC,MAAM,GAAGH,MAAM,CAACG,MAAM,CAACC,IAAI;IAChC,IAAI,CAACC,aAAa,GAAG,IAAI;IACzB,IAAI,CAACC,WAAW,GAAG,IAAI;EACzB;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EAPE;IAAA;IAAA;IAsNA;AACF;AACA;AACA;AACA;AACA;IACE,wBAAeC,eAAe,EAAE;MAC9B,IAAI,CAACP,MAAM,CAACQ,MAAM,CAACD,eAAe,CAAC,EAAE;QACnCE,oBAAW,CAACC,MAAM,CAACC,IAAI,CAAC,iEAAiE,CAAC;QAE1F,OAAO,KAAK;MACd;MAEA,IAAI,CAAC,IAAI,CAACL,WAAW,EAAE;QACrB;QACA,OAAO,IAAI;MACb;MAEA,IAAMM,gBAAgB,GAAGZ,MAAM,CAACa,sBAAsB,CAAC,IAAI,CAACP,WAAW,EAAEC,eAAe,CAAC;MAEzF,OAAOK,gBAAgB,KAAKZ,MAAM,CAACc,IAAI,CAACC,YAAY;IACtD;;IAEA;AACF;AACA;AACA;AACA;AACA;EALE;IAAA;IAAA;IAuJA;AACF;AACA;AACA;AACA;IACE,sBAAaC,OAAO,EAAE;MAAA;MACpB,IAAIC,OAAO,GAAG,KAAK;MACnB,IAAOb,IAAI,GAAIJ,MAAM,CAACG,MAAM,CAArBC,IAAI;MACX,IAAOI,MAAM,GAAIR,MAAM,CAAhBQ,MAAM;MACb;MACA,IAAMU,SAAS,GAAG,SAAZA,SAAS,CAAIf,MAAM,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AAK,EAAE;QACT,CAAC;QAEDQ,MAAM,EAAE;UACNV,KAAK,EAAE,sBAAsB;UAC7BC,WAAW,EAAER,IAAI,qdAEiC;UAClDS,KAAK,EAAE;QACT,CAAC;QAEDS,MAAM,EAAE;UACNX,KAAK,EAAE,sBAAsB;UAC7BC,WAAW,EAAER,IAAI,yPACI;UACrBS,KAAK,EAAE;QACT;MACF,CAAC;MAED,IAAMU,QAAQ,GAAGd,QAAQ,CAACN,SAAS,CAAC;MAEpCoB,QAAQ,CAACZ,KAAK,oBAAaY,QAAQ,CAACZ,KAAK,CAAE;MAC3CY,QAAQ,CAACC,UAAU,GAAGhB,aAAa,CAAChF,UAAU,CAAC;MAE/C,OAAO+F,QAAQ;IACjB;EAAC;EAAA;AAAA;AAAA;AAAA,8BAvsBkBvI,MAAM,YAET;EACdI,IAAI,EAAE,MAAM;EACZe,MAAM,EAAE,QAAQ;EAChBM,OAAO,EAAE;AACX,CAAC;AAAA,8BANkBzB,MAAM,UASX;EACZoD,EAAE,EAAE,OAAO;EACXT,EAAE,EAAE,cAAc;EAClBC,EAAE,EAAE,WAAW;EACflB,MAAM,EAAE,QAAQ;EAChBX,YAAY,EAAE,cAAc;EAC5B+D,WAAW,EAAE,aAAa;EAC1BW,KAAK,EAAE;AACT,CAAC"}
|
|
1
|
+
{"version":3,"names":["MAX_OOO_DELTA_COUNT","OOO_DELTA_WAIT_TIME","OOO_DELTA_WAIT_TIME_RANDOM_DELAY","Parser","deltaCompareFunc","left","right","loci","LT","GT","extract","extractComparisonState","isSequenceEmpty","result","compareSequence","baseSequence","queue","SortedQueue","status","onDeltaAction","workingCopy","syncTimer","incomingFullDto","isLoci","LoggerProxy","logger","info","comparisonResult","compareFullDtoSequence","USE_INCOMING","newLoci","isValid","size","processDeltaEvent","action","locus","enqueue","triggerSync","reason","stopSyncTimer","pause","DESYNC","timeout","Math","random","setTimeout","clearTimeout","WAIT","dequeue","isValidLocus","nextEvent","compare","lociComparison","debug","needToWait","startSyncTimer","locus2string","sequence","entries","length","at","current","incoming","comparison","min","max","currentIsNotUnique","unique","incomingIsNotUnique","currentTotalRange","end","incomingTotalRange","EQ","currentIsUnique","incomingIsUnique","currentUniqueMin","incomingUniqueMin","currentHasNoRange","start","incomingHasNoRange","neitherSeqHasRange","hasUniqOverlap","list","some","seq","currentUniqOverlap","incomingUniqOverlap","debugInfo","pack","packComparisonResult","compareDelta","compareToAction","slice","USE_CURRENT","local","getMetaData","delta","getUniqueSequences","rules","checkSequenceOverlap","checkUnequalRanges","checkForUniqueEntries","checkIfOutOfSync","rule","ERROR","lociComparisonResult","split","first","last","rangeStart","rangeEnd","baseLoci","otherLoci","diff","getNumbersOutOfRange","output","filter","num","sort","a","b","hasEmptyEntries","hasEmptyRange","hasProp","prop","Object","prototype","hasOwnProperty","call","newData","oldData","debugCode","mStr","strings","join","replace","resolutionMap","debugMap","SO001","title","description","logic","SO002","UR001","UR002","UR003","UE001","UE002","OOS001","OOS002","OOS003","debugObj","resolution"],"sources":["parser.ts"],"sourcesContent":["import {difference} from 'lodash';\n\nimport SortedQueue from '../common/queue';\nimport LoggerProxy from '../common/logs/logger-proxy';\n\nconst MAX_OOO_DELTA_COUNT = 5; // when we receive an out-of-order delta and the queue builds up to MAX_OOO_DELTA_COUNT, we do a sync with Locus\nconst OOO_DELTA_WAIT_TIME = 10000; // [ms] minimum wait time before we do a sync if we get out-of-order deltas\nconst OOO_DELTA_WAIT_TIME_RANDOM_DELAY = 5000; // [ms] max random delay added to OOO_DELTA_WAIT_TIME\n\ntype LocusDeltaDto = {\n baseSequence: {\n rangeStart: number;\n rangeEnd: number;\n entries: number[];\n };\n sequence: {\n rangeStart: number;\n rangeEnd: number;\n entries: number[];\n };\n syncUrl: string;\n};\n\n/**\n * Locus Delta Parser\n * @private\n * https://sqbu-github.cisco.com/WebExSquared/cloud-apps/wiki/Locus-Delta-Events\n */\nexport default class Parser {\n // processing status\n status:\n | 'IDLE' // not doing anything\n | 'PAUSED' // paused, because we are doing a sync\n | 'WORKING' // processing a delta event\n | 'BLOCKED'; // received an out-of-order delta, so waiting for the missing one\n\n // loci comparison states\n static loci = {\n EQ: 'EQUAL',\n GT: 'GREATER_THAN',\n LT: 'LESS_THAN',\n DESYNC: 'DESYNC',\n USE_INCOMING: 'USE_INCOMING',\n USE_CURRENT: 'USE_CURRENT',\n WAIT: 'WAIT',\n ERROR: 'ERROR',\n };\n\n queue: SortedQueue<LocusDeltaDto>;\n workingCopy: any;\n syncTimer: null | number | NodeJS.Timeout;\n\n /**\n * @constructs Parser\n */\n constructor() {\n const deltaCompareFunc = (left: LocusDeltaDto, right: LocusDeltaDto) => {\n const {LT, GT} = Parser.loci;\n const {extractComparisonState: extract} = Parser;\n\n if (Parser.isSequenceEmpty(left)) {\n return -1;\n }\n if (Parser.isSequenceEmpty(right)) {\n return 1;\n }\n const result = extract(Parser.compareSequence(left.baseSequence, right.baseSequence));\n\n if (result === LT) {\n return -1;\n }\n if (result === GT) {\n return 1;\n }\n\n return 0;\n };\n\n this.queue = new SortedQueue<LocusDeltaDto>(deltaCompareFunc);\n this.status = 'IDLE';\n this.onDeltaAction = null;\n this.workingCopy = null;\n this.syncTimer = null;\n }\n\n /**\n * Returns a debug string representing a locus delta - useful for logging\n *\n * @param {LocusDeltaDto} locus Locus delta\n * @returns {string}\n */\n static locus2string(locus: LocusDeltaDto) {\n if (!locus.sequence?.entries) {\n return 'invalid';\n }\n\n return locus.sequence.entries.length ? `seq=${locus.sequence.entries.at(-1)}` : 'empty';\n }\n\n /**\n * Checks if two sequences overlap in time,\n * the sequence with the higher minimum value is greater.\n * Chooses sequence with most recent data.\n * @param {Types~Locus} current\n * @param {Types~Locus} incoming\n * @returns {string} loci comparison state\n */\n static checkSequenceOverlap(current, incoming) {\n let comparison = null;\n\n // if earliest working copy sequence is more recent than last incoming sequence\n if (current.min > incoming.max) {\n // choose left side (current)\n comparison = `${Parser.loci.GT}:SO001`;\n }\n // if last working copy sequence is before the earliest incoming sequence\n else if (current.max < incoming.min) {\n // choose right side (incoming)\n comparison = `${Parser.loci.LT}:SO002`;\n }\n\n // if no match above, defaults to null\n return comparison;\n }\n\n /**\n * Checks if two sequences have unequal ranges.\n * Chooses sequence with most larger range.\n * @param {Types~Locus} current\n * @param {Types~Locus} incoming\n * @returns {object} loci comparison\n */\n static checkUnequalRanges(current, incoming) {\n let comparison = null;\n const currentIsNotUnique = current.unique.length === 0;\n const incomingIsNotUnique = incoming.unique.length === 0;\n const currentTotalRange = current.end - current.min;\n const incomingTotalRange = incoming.end - incoming.min;\n\n // no unique values for both loci\n if (currentIsNotUnique && incomingIsNotUnique) {\n // current working copy loci has a larger range\n if (currentTotalRange > incomingTotalRange) {\n // choose left side (current)\n comparison = `${Parser.loci.GT}:UR001`;\n }\n // incoming delta loci has a larger range\n else if (currentTotalRange < incomingTotalRange) {\n // choose right side (incoming)\n comparison = `${Parser.loci.LT}:UR002`;\n } else {\n // with no unique entries and with ranges either absent or\n // of the same size, the sequences are considered equal.\n comparison = `${Parser.loci.EQ}:UR003`;\n }\n }\n\n return comparison;\n }\n\n /**\n * Checks if either sequences has unique entries.\n * Entries are considered unique if they do not overlap\n * with other Loci sequences or range values.\n * Chooses sequence with the unique entries.\n * @param {Types~Locus} current\n * @param {Types~Locus} incoming\n * @returns {string} loci comparison state\n */\n static checkForUniqueEntries(current, incoming) {\n let comparison = null;\n const currentIsUnique = current.unique.length > 0;\n const incomingIsUnique = incoming.unique.length > 0;\n\n // current has unique entries and incoming does not\n if (currentIsUnique && !incomingIsUnique) {\n // choose left side (current)\n comparison = `${Parser.loci.GT}:UE001`;\n }\n // current has no unique entries but incoming does\n else if (!currentIsUnique && incomingIsUnique) {\n // choose right side (incoming)\n comparison = `${Parser.loci.LT}:UE002`;\n }\n\n return comparison;\n }\n\n /**\n * Checks both Locus Delta objects to see if they are\n * out of sync with one another. If so sends a DESYNC\n * request to the server.\n * @param {Types~Locus} current\n * @param {Types~Locus} incoming\n * @returns {string} loci comparison state\n */\n static checkIfOutOfSync(current, incoming) {\n let comparison = null;\n const currentUniqueMin = current.unique[0];\n const incomingUniqueMin = incoming.unique[0];\n\n const currentHasNoRange = !current.start && !current.end;\n const incomingHasNoRange = !incoming.start && !incoming.end;\n const neitherSeqHasRange = currentHasNoRange && incomingHasNoRange;\n\n const hasUniqOverlap = (list, min, max) => list.some((seq) => min < seq && seq < max);\n // current unique entries overlap the total range of incoming\n const currentUniqOverlap = hasUniqOverlap(current.unique, incoming.min, incoming.max);\n // vice-versa, incoming unique entries overlap the total range of current\n const incomingUniqOverlap = hasUniqOverlap(incoming.unique, current.min, current.max);\n\n if (neitherSeqHasRange || currentUniqOverlap || incomingUniqOverlap) {\n // outputs string indicating which condition occurred. ex: 0,1,0\n const debugInfo = `${+neitherSeqHasRange},${+currentUniqOverlap},${+incomingUniqOverlap}`;\n\n // send DESYNC to server\n comparison = `${Parser.loci.DESYNC}:OOS001:${debugInfo}`;\n } else if (currentUniqueMin > incomingUniqueMin) {\n // choose left side (current)\n comparison = `${Parser.loci.GT}:OOS002`;\n } else {\n // choose right side (incoming)\n comparison = `${Parser.loci.LT}:OOS003`;\n }\n\n return comparison;\n }\n\n /**\n * Compares two loci to determine which one contains the most recent state\n * @instance\n * @memberof Locus\n * @param {Types~Locus} current\n * @param {Types~Locus} incoming\n * @returns {string} loci comparison state\n */\n static compare(current, incoming) {\n const {isSequenceEmpty} = Parser;\n const {extractComparisonState: extract} = Parser;\n const {packComparisonResult: pack} = Parser;\n\n if (isSequenceEmpty(current) || isSequenceEmpty(incoming)) {\n return pack(Parser.loci.USE_INCOMING, 'C001');\n }\n\n if (incoming.baseSequence) {\n return pack(Parser.compareDelta(current, incoming), 'C002');\n }\n\n const result = Parser.compareSequence(current.sequence, incoming.sequence);\n const action = Parser.compareToAction(extract(result));\n\n return pack(action, result);\n }\n\n /**\n * Compares two loci sequences (with delta params) and indicates what action\n * to take.\n * @instance\n * @memberof Locus\n * @param {Types~Locus} current\n * @param {Types~Locus} incoming\n * @private\n * @returns {string} loci comparison state\n */\n private static compareDelta(current, incoming) {\n const {LT, GT, EQ, DESYNC, USE_INCOMING, WAIT} = Parser.loci;\n\n const {extractComparisonState: extract} = Parser;\n const {packComparisonResult: pack} = Parser;\n\n const result = Parser.compareSequence(current.sequence, incoming.sequence);\n let comparison = extract(result);\n\n if (comparison !== LT) {\n return pack(Parser.compareToAction(comparison), result);\n }\n\n comparison = Parser.compareSequence(current.sequence, incoming.baseSequence);\n\n switch (extract(comparison)) {\n case GT:\n case EQ:\n comparison = USE_INCOMING;\n break;\n\n case LT:\n if (extract(Parser.compareSequence(incoming.baseSequence, incoming.sequence)) === EQ) {\n // special case where Locus sends a delta with baseSequence === sequence to trigger a sync,\n // because the delta event is too large to be sent over mercury connection\n comparison = DESYNC;\n } else {\n // the incoming locus has baseSequence from the future, so it is out-of-order,\n // we are missing 1 or more locus that should be in front of it, we need to wait for it\n comparison = WAIT;\n }\n break;\n default:\n comparison = DESYNC;\n }\n\n return pack(comparison, result);\n }\n\n /**\n * Compares Locus sequences - it should be called only for full Locus DTOs, not deltas\n *\n * @param {Types~Locus} current Current working copy\n * @param {Types~Locus} incomingFullDto New Full Locus DTO\n * @returns {string} either Parser.loci.USE_INCOMING or Parser.loci.USE_CURRENT\n */\n static compareFullDtoSequence(current, incomingFullDto) {\n if (Parser.isSequenceEmpty(current) || Parser.isSequenceEmpty(incomingFullDto)) {\n return Parser.loci.USE_INCOMING;\n }\n\n // the sequence.entries list will always contain at least 1 entry\n // https://sqbu-github.cisco.com/WebExSquared/cloud-apps/wiki/Locus-Sequence-Comparison-Algorithm\n\n return incomingFullDto.sequence.entries.slice(-1)[0] > current.sequence.entries.slice(-1)[0]\n ? Parser.loci.USE_INCOMING\n : Parser.loci.USE_CURRENT;\n }\n\n /**\n * Returns true if the incoming full locus DTO is newer than the current working copy\n *\n * @param {Types~Locus} incomingFullDto New Full Locus DTO\n * @returns {string} either Parser.loci.USE_INCOMING or Parser.loci.USE_CURRENT\n */\n isNewFullLocus(incomingFullDto) {\n if (!Parser.isLoci(incomingFullDto)) {\n LoggerProxy.logger.info('Locus-info:parser#isNewFullLocus --> Ignoring non-locus object.');\n\n return false;\n }\n\n if (!this.workingCopy) {\n // we don't have a working copy yet, so any full locus is better than nothing\n return true;\n }\n\n const comparisonResult = Parser.compareFullDtoSequence(this.workingCopy, incomingFullDto);\n\n return comparisonResult === Parser.loci.USE_INCOMING;\n }\n\n /**\n * Compares Locus sequences\n * @param {Types~Locus} current Current working copy\n * @param {Types~Locus} incoming New Locus delta\n * @returns {string}\n */\n static compareSequence(current, incoming) {\n // Locus sequence comparison rules in order of priority.\n // https://sqbu-github.cisco.com/WebExSquared/cloud-apps/wiki/Locus-Sequence-Comparison-Algorithm\n\n const local: any = Parser.getMetaData(current);\n const delta: any = Parser.getMetaData(incoming);\n\n // update loci metadata\n local.unique = Parser.getUniqueSequences(local, delta);\n delta.unique = Parser.getUniqueSequences(delta, local);\n\n // Locus sequence comparison rules\n // order matters\n const rules = [\n Parser.checkSequenceOverlap,\n Parser.checkUnequalRanges,\n Parser.checkForUniqueEntries,\n Parser.checkIfOutOfSync,\n ];\n\n for (const rule of rules) {\n // Rule only returns a value if the rule applies,\n // otherwise returns null.\n const result = rule(local, delta);\n\n if (result) {\n return result;\n }\n }\n\n // error, none of rules above applied\n // should never get here as last rule\n // should be catch all.\n return Parser.loci.ERROR;\n }\n\n /**\n * Transates the result of a sequence comparison into an intended behavior\n * @param {string} result\n * @returns {string} Locus comparison action\n */\n static compareToAction(result: string) {\n const {DESYNC, EQ, ERROR, GT, LT, USE_CURRENT, USE_INCOMING} = Parser.loci;\n\n let action = ERROR;\n\n switch (result) {\n case EQ:\n case GT:\n action = USE_CURRENT;\n break;\n case LT:\n action = USE_INCOMING;\n break;\n case DESYNC:\n action = DESYNC;\n break;\n default:\n LoggerProxy.logger.info(\n `Locus-info:parser#compareToAction --> Error: ${result} is not a recognized sequence comparison result.`\n );\n }\n\n return action;\n }\n\n /**\n * Extracts a loci comparison from a string of data.\n * @param {string} lociComparisonResult Comparison result with extra data\n * @returns {string} Comparison of EQ, LT, GT, or DESYNC.\n */\n static extractComparisonState(lociComparisonResult: string) {\n return lociComparisonResult.split(':')[0];\n }\n\n /**\n * @typedef {object} LociMetadata\n * @property {number} start - Starting sequence number\n * @property {number} end - Ending sequence number\n * @property {number} first - First sequence number\n * @property {number} last - Last sequence number\n * @property {number} min - Minimum sequence number\n * @property {number} max - Maximum sequence number\n * @property {number} entries - Loci sequence entries\n */\n\n /**\n * Metadata for Locus delta\n * @param {Array.<number>} sequence Locus delta sequence\n * @returns {LociMetadata} Locus Delta Metadata\n */\n static getMetaData(sequence: any) {\n const {entries} = sequence;\n const first = entries[0];\n const last = entries.slice(-1)[0];\n\n // rangeStart or rangeEnd is 0 if a range doesn't exist\n const start = sequence.rangeStart;\n const end = sequence.rangeEnd;\n\n // sequence data\n return {\n start,\n end,\n first,\n last,\n // Rule is: rangeStart <= rangeEnd <= min(entries)\n min: start || first,\n // Grab last entry if exist else default to rangeEnd\n max: last || end,\n // keep reference to actual sequence entries\n entries,\n };\n }\n\n /**\n * Compares two Locus delta objects and notes unique\n * values contained within baseLoci.\n * @param {LociMetadata} baseLoci\n * @param {LociMetadata} otherLoci\n * @returns {Array.<number>} List of unique sequences\n */\n static getUniqueSequences(baseLoci: any, otherLoci: any) {\n const diff: any = difference(baseLoci.entries, otherLoci.entries);\n\n const {start, end} = otherLoci;\n\n return Parser.getNumbersOutOfRange(diff, start, end);\n }\n\n /**\n * Returns an array of numbers outside of a given range.\n * @param {Array.<number>} list Array to filter\n * @param {number} rangeStart Start of range\n * @param {number} rangeEnd End of range\n * @returns {Array.<number>} Array of numbers sorted ASC\n */\n static getNumbersOutOfRange(list: Array<number>, rangeStart: number, rangeEnd: number) {\n // Collect all numbers if number is outside of specified range\n const output = list.filter((num) => num < rangeStart || num > rangeEnd);\n\n // sort ascending\n return output.sort((a, b) => a - b);\n }\n\n /**\n * Checks if newLoci or workingCopy is invalid.\n * @param {Types~Locus} newLoci\n * @returns {boolean}\n */\n isValidLocus(newLoci) {\n let isValid = false;\n const {isLoci} = Parser;\n\n // one or both objects are not locus delta events\n if (!isLoci(this.workingCopy) || !isLoci(newLoci)) {\n LoggerProxy.logger.info(\n 'Locus-info:parser#processDeltaEvent --> Ignoring non-locus object. workingCopy:',\n this.workingCopy,\n 'newLoci:',\n newLoci\n );\n } else {\n isValid = true;\n }\n\n return isValid;\n }\n\n /**\n * Determines if a paricular locus's sequence is empty\n * @param {Types~Locus} locus\n * @returns {bool}\n */\n static isSequenceEmpty(locus) {\n const {sequence} = locus;\n const hasEmptyEntries = !sequence.entries?.length;\n const hasEmptyRange = sequence.rangeStart === 0 && sequence.rangeEnd === 0;\n\n return hasEmptyEntries && hasEmptyRange;\n }\n\n /**\n * Determines if an object has basic\n * structure of a locus object.\n * @param {Types~Locus} loci\n * @returns {boolean}\n */\n static isLoci(loci) {\n if (!loci || !loci.sequence) {\n return false;\n }\n const hasProp = (prop) => Object.prototype.hasOwnProperty.call(loci.sequence, prop);\n\n if (hasProp('rangeStart') && hasProp('rangeEnd')) {\n return true;\n }\n\n return false;\n }\n\n /**\n * Processes next event in queue,\n * if queue is empty sets status to idle.\n * @returns {undefined}\n */\n nextEvent() {\n if (this.status === 'PAUSED') {\n LoggerProxy.logger.info('Locus-info:parser#nextEvent --> Locus parser paused.');\n\n return;\n }\n\n if (this.status === 'BLOCKED') {\n LoggerProxy.logger.info(\n 'Locus-info:parser#nextEvent --> Locus parser blocked by out-of-order delta.'\n );\n\n return;\n }\n\n // continue processing until queue is empty\n if (this.queue.size() > 0) {\n this.processDeltaEvent();\n } else {\n this.status = 'IDLE';\n }\n }\n\n /**\n * Function handler for delta actions,\n * is set by instance callee.\n * @param {string} action Locus delta action\n * @param {Types~Locus} locus Locus delta\n * @returns {undefined}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onDeltaAction(action: string, locus) {}\n\n /**\n * Event handler for locus delta events\n * @param {Types~Locus} loci Locus Delta\n * @returns {undefined}\n */\n onDeltaEvent(loci) {\n // enqueue the new loci\n this.queue.enqueue(loci);\n\n if (this.onDeltaAction) {\n if (this.status === 'BLOCKED') {\n if (this.queue.size() > MAX_OOO_DELTA_COUNT) {\n this.triggerSync('queue too big, blocked on out-of-order delta');\n } else {\n this.processDeltaEvent();\n }\n } else if (this.status === 'IDLE') {\n // Update status, ensure we only process one event at a time.\n this.status = 'WORKING';\n\n this.processDeltaEvent();\n }\n }\n }\n\n /**\n * Appends new data onto a string of existing data.\n * @param {string} newData\n * @param {string} oldData\n * @returns {string}\n */\n static packComparisonResult(newData: string, oldData: string) {\n return `${newData}:${oldData}`;\n }\n\n /**\n * Pause locus processing\n * @returns {undefined}\n */\n pause() {\n this.status = 'PAUSED';\n LoggerProxy.logger.info('Locus-info:parser#pause --> Locus parser paused.');\n }\n\n /**\n * Triggers a sync with Locus\n *\n * @param {string} reason used just for logging\n * @returns {undefined}\n */\n private triggerSync(reason: string) {\n LoggerProxy.logger.info(`Locus-info:parser#triggerSync --> doing sync, reason: ${reason}`);\n this.stopSyncTimer();\n this.pause();\n this.onDeltaAction(Parser.loci.DESYNC, this.workingCopy);\n }\n\n /**\n * Starts a timer with a random delay. When that timer expires we will do a sync.\n *\n * The main purpose of this timer is to handle a case when we get some out-of-order deltas,\n * so we start waiting to receive the missing delta. If that delta never arrives, this timer\n * will trigger a sync with Locus.\n *\n * @returns {undefined}\n */\n private startSyncTimer() {\n if (this.syncTimer === null) {\n const timeout = OOO_DELTA_WAIT_TIME + Math.random() * OOO_DELTA_WAIT_TIME_RANDOM_DELAY;\n\n this.syncTimer = setTimeout(() => {\n this.syncTimer = null;\n this.triggerSync('timer expired, blocked on out-of-order delta');\n }, timeout);\n }\n }\n\n /**\n * Stops the timer for triggering a sync\n *\n * @returns {undefined}\n */\n private stopSyncTimer() {\n if (this.syncTimer !== null) {\n clearTimeout(this.syncTimer);\n this.syncTimer = null;\n }\n }\n\n /**\n * Processes next locus delta in the queue,\n * continues until the queue is empty\n * or cleared.\n * @returns {undefined}\n */\n processDeltaEvent() {\n const {DESYNC, USE_INCOMING, WAIT} = Parser.loci;\n const {extractComparisonState: extract} = Parser;\n const newLoci = this.queue.dequeue();\n\n if (!this.isValidLocus(newLoci)) {\n this.nextEvent();\n\n return;\n }\n\n const result = Parser.compare(this.workingCopy, newLoci);\n const lociComparison = extract(result);\n\n // limited debugging, use chrome extension\n // for full debugging.\n LoggerProxy.logger.debug(`Locus-info:parser#processDeltaEvent --> Locus Debug: ${result}`);\n\n let needToWait = false;\n\n if (lociComparison === DESYNC) {\n // wait for desync response\n this.pause();\n } else if (lociComparison === USE_INCOMING) {\n // update working copy for future comparisons.\n // Note: The working copy of parser gets updated in .onFullLocus()\n // and here when USE_INCOMING locus.\n this.workingCopy = newLoci;\n } else if (lociComparison === WAIT) {\n // we've taken newLoci from the front of the queue, so put it back there as we have to wait\n // for the one that should be in front of it, before we can process it\n this.queue.enqueue(newLoci);\n needToWait = true;\n }\n\n if (needToWait) {\n this.status = 'BLOCKED';\n this.startSyncTimer();\n } else {\n this.stopSyncTimer();\n\n if (this.status === 'BLOCKED') {\n // we are not blocked anymore\n this.status = 'WORKING';\n\n LoggerProxy.logger.info(\n `Locus-info:parser#processDeltaEvent --> received delta that we were waiting for ${Parser.locus2string(\n newLoci\n )}, not blocked anymore`\n );\n }\n }\n\n if (this.onDeltaAction) {\n LoggerProxy.logger.info(\n `Locus-info:parser#processDeltaEvent --> Locus Delta ${Parser.locus2string(\n newLoci\n )}, Action: ${lociComparison}`\n );\n\n this.onDeltaAction(lociComparison, newLoci);\n }\n\n this.nextEvent();\n }\n\n /**\n * Resume from a paused state\n * @returns {undefined}\n */\n resume() {\n LoggerProxy.logger.info('Locus-info:parser#resume --> Locus parser resumed.');\n this.status = 'WORKING';\n this.nextEvent();\n }\n\n /**\n * Gets related debug info for given error code\n * @param {string} debugCode Debug code\n * @param {string} comparison Locus comparison string\n * @returns {object} Debug message\n */\n static getDebugMessage(debugCode: string, comparison: string) {\n // removes extra spaces from multiline string\n const mStr = (strings) => strings.join('').replace(/\\s{2,}/g, ' ');\n\n const resolutionMap = {\n EQ: `${Parser.loci.LT}: is equal (current == incoming).`,\n LT: `${Parser.loci.LT}: choose right side (incoming).`,\n GT: `${Parser.loci.GT}: choose left side (current).`,\n };\n\n const debugMap = {\n SO001: {\n title: 'checkSequenceOverlap-001',\n description: mStr`Occurs if earliest working copy sequence is more \\\n recent than last incoming sequence.`,\n logic: 'current.min > incoming.max',\n },\n\n SO002: {\n title: 'checkSequenceOverlap-002',\n description: mStr`Occurs if last working copy sequence is before the \\\n earliest incoming sequence.`,\n logic: 'current.max < incoming.min',\n },\n\n UR001: {\n title: 'checkUnequalRanges-001',\n description: mStr`Occurs if there are no unique values for both loci, \\\n and the current working copy loci has a larger range.`,\n logic: 'currentTotalRange > incomingTotalRange',\n },\n\n UR002: {\n title: 'checkUnequalRanges-002',\n description: mStr`Occurs if there are no unique values for both loci, \\\n and the incoming delta loci has a larger range.`,\n logic: 'currentTotalRange < incomingTotalRange',\n },\n\n UR003: {\n title: 'checkUnequalRanges-003',\n description: mStr`Occurs if there are no unique values for both loci, \\\n and with ranges either absent or of the same size, the sequences \\\n are considered equal.`,\n logic: 'currentTotalRange == incomingTotalRange',\n },\n\n UE001: {\n title: 'checkForUniqueEntries-001',\n description: mStr`Occurs if current loci has unique entries and \\\n incoming does not. Entries are considered unique if they \\\n do not overlap with other Loci sequences or range values.`,\n logic: 'currentIsUnique && !incomingIsUnique',\n },\n\n UE002: {\n title: 'checkForUniqueEntries-002',\n description: mStr`Occurs if current has no unique entries but \\\n incoming does. Entries are considered unique if they \\\n do not overlap with other Loci sequences or range values.`,\n logic: '!currentIsUnique && incomingIsUnique',\n },\n\n OOS001: {\n title: 'checkIfOutOfSync-001',\n description: mStr`Occurs if neither sequence has a range, or \\\n if the current loci unique entries overlap the total range of the \\\n incoming sequence, or if the incoming unique entries overlap \\\n the total range of current sequence.`,\n logic: 'neitherSeqHasRange || currentUniqOverlap || incomingUniqOverlap',\n },\n\n OOS002: {\n title: 'checkIfOutOfSync-002',\n description: mStr`Occurs if the minimum value from sequences that are \\\n unique to the current loci is greater than the minimum value from \\\n sequences that are unique to the incoming loci.`,\n logic: 'currentUniqueMin > incomingUniqueMin',\n },\n\n OOS003: {\n title: 'checkIfOutOfSync-003',\n description: mStr`Occurs if none of the comparison rules applied. \\\n It is a catch all.`,\n logic: 'else (catch all)',\n },\n };\n\n const debugObj = debugMap[debugCode];\n\n debugObj.title = `Debug: ${debugObj.title}`;\n debugObj.resolution = resolutionMap[comparison];\n\n return debugObj;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAEA;AACA;AAAsD;AAEtD,IAAMA,mBAAmB,GAAG,CAAC,CAAC,CAAC;AAC/B,IAAMC,mBAAmB,GAAG,KAAK,CAAC,CAAC;AACnC,IAAMC,gCAAgC,GAAG,IAAI,CAAC,CAAC;AAgB/C;AACA;AACA;AACA;AACA;AAJA,IAKqBC,MAAM;EACzB;;EAKe;;EAEf;;EAgBA;AACF;AACA;EACE,kBAAc;IAAA;IAAA;IAAA;IAAA;IAAA;IACZ,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAgB,CAAIC,IAAmB,EAAEC,KAAoB,EAAK;MACtE,mBAAiBH,MAAM,CAACI,IAAI;QAArBC,EAAE,gBAAFA,EAAE;QAAEC,EAAE,gBAAFA,EAAE;MACb,IAA+BC,OAAO,GAAIP,MAAM,CAAzCQ,sBAAsB;MAE7B,IAAIR,MAAM,CAACS,eAAe,CAACP,IAAI,CAAC,EAAE;QAChC,OAAO,CAAC,CAAC;MACX;MACA,IAAIF,MAAM,CAACS,eAAe,CAACN,KAAK,CAAC,EAAE;QACjC,OAAO,CAAC;MACV;MACA,IAAMO,MAAM,GAAGH,OAAO,CAACP,MAAM,CAACW,eAAe,CAACT,IAAI,CAACU,YAAY,EAAET,KAAK,CAACS,YAAY,CAAC,CAAC;MAErF,IAAIF,MAAM,KAAKL,EAAE,EAAE;QACj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E,EAAE,EAAE,OAAO;EACX/D,EAAE,EAAE,cAAc;EAClBD,EAAE,EAAE,WAAW;EACfiC,MAAM,EAAE,QAAQ;EAChBZ,YAAY,EAAE,cAAc;EAC5BgE,WAAW,EAAE,aAAa;EAC1B9C,IAAI,EAAE,MAAM;EACZyD,KAAK,EAAE;AACT,CAAC"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Simple queue
|
|
2
|
+
* Simple queue in which the elements are always sorted
|
|
3
3
|
*/
|
|
4
|
-
export default class
|
|
5
|
-
queue:
|
|
4
|
+
export default class SortedQueue<ItemType> {
|
|
5
|
+
queue: ItemType[];
|
|
6
|
+
compareFunc: (left: ItemType, right: ItemType) => number;
|
|
6
7
|
/**
|
|
7
|
-
* @constructs
|
|
8
|
+
* @constructs SortedQueue
|
|
9
|
+
* @param {Function} compareFunc comparison function used for sorting the elements of the queue
|
|
8
10
|
*/
|
|
9
|
-
constructor();
|
|
11
|
+
constructor(compareFunc: (left: ItemType, right: ItemType) => number);
|
|
10
12
|
/**
|
|
11
13
|
* Removes all of the elements from queue.
|
|
12
14
|
* @returns {undefined}
|
|
@@ -17,13 +19,13 @@ export default class SimpleQueue {
|
|
|
17
19
|
* @param {object} item
|
|
18
20
|
* @returns {undefined}
|
|
19
21
|
*/
|
|
20
|
-
enqueue(item:
|
|
22
|
+
enqueue(item: ItemType): void;
|
|
21
23
|
/**
|
|
22
24
|
* Returns and removes the head of the queue.
|
|
23
25
|
* Returns null if the queue is empty.
|
|
24
26
|
* @returns {(object|null)} Queue item or null.
|
|
25
27
|
*/
|
|
26
|
-
dequeue():
|
|
28
|
+
dequeue(): ItemType;
|
|
27
29
|
/**
|
|
28
30
|
* Returns the number of items in queue.
|
|
29
31
|
* @returns {number}
|