@jayesol/jayeson.lib.sports 2.2.6-beta.0 → 2.2.6

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/lib/merge.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import { IndexedSnapshot, Incoming, MessageBeforeTransform, MergeableWrapper } from './data_structure';
2
- import { SportsFeedMessageGroup } from './message_class';
3
- import { IMessageClass } from '@jayesol/jayeson.lib.delivery';
4
- import { IBetMatch, PartitionKey } from '@jayesol/jayeson.lib.record';
5
- import * as Collections from 'typescript-collections';
6
- export declare enum MsgType {
7
- INSERT = 0,
8
- UPDATE = 1,
9
- DELETE = 2
10
- }
11
- export declare class SnapshotUtil {
12
- private static readonly SPORTS_GROUP;
13
- static combineSnapshots(msgType: IMessageClass, childSs: IndexedSnapshot, parentSs: IndexedSnapshot): MessageBeforeTransform;
14
- static processRefresh(childSs: IndexedSnapshot, parentSs: IndexedSnapshot): MessageBeforeTransform;
15
- static processReset(childSs: IndexedSnapshot, parentSs: IndexedSnapshot): MessageBeforeTransform;
16
- static processMatches(msgType: MsgType, childSs: IndexedSnapshot, parentSs: IndexedSnapshot): MessageBeforeTransform;
17
- static processEvents(msgType: MsgType, childSs: IndexedSnapshot, parentSs: IndexedSnapshot): MessageBeforeTransform;
18
- static processOdds(msgType: MsgType, childSs: IndexedSnapshot, parentSs: IndexedSnapshot): MessageBeforeTransform;
19
- }
20
- export declare class DeltaTransformingLogicImpl {
21
- static transform(sportsGrp: SportsFeedMessageGroup, stream: string, msgType: IMessageClass, delta: IndexedSnapshot, msgBefore: MessageBeforeTransform): Incoming[];
22
- static combineEventState(msgBefore: MessageBeforeTransform, sportsGrp: SportsFeedMessageGroup, msgType: IMessageClass, stream: string, delta: IndexedSnapshot, msg: Incoming[]): Incoming[];
23
- static suppressInsertEvent(msgBefore: MessageBeforeTransform, sportsGrp: SportsFeedMessageGroup, msgType: IMessageClass, stream: string, delta: IndexedSnapshot, msg: Incoming[]): Incoming[];
24
- static transformTTLRestore(ttlRestoredList: IndexedSnapshot[], grp: SportsFeedMessageGroup, stream: string, before: IndexedSnapshot, after: IndexedSnapshot, matches: {
25
- [sport: number]: IBetMatch[];
26
- }, restoredKeys: Collections.Dictionary<PartitionKey, number>): MergeableWrapper;
27
- static transformTTLRemove(ttlRemoveList: IndexedSnapshot[], grp: SportsFeedMessageGroup, stream: string, before: IndexedSnapshot, after: IndexedSnapshot, keysRemoved: Collections.Dictionary<PartitionKey, number>): MergeableWrapper;
28
- static breakdownTTL(grp: SportsFeedMessageGroup, stream: string, restoredSS: IndexedSnapshot): Incoming[];
29
- static breakdownReset(grp: SportsFeedMessageGroup, stream: string, removeSs: IndexedSnapshot): Incoming[];
30
- static suppressInsertMatch(msgBefore: MessageBeforeTransform, sportsGrp: SportsFeedMessageGroup, msgType: IMessageClass, stream: string, delta: IndexedSnapshot, msg: Incoming[]): Incoming[];
31
- static suppressDeleteEvent(msgBefore: MessageBeforeTransform, sportsGrp: SportsFeedMessageGroup, msgType: IMessageClass, stream: string, delta: IndexedSnapshot, msg: Incoming[]): Incoming[];
32
- static suppressDeleteMatch(msgBefore: MessageBeforeTransform, sportsGrp: SportsFeedMessageGroup, msgType: IMessageClass, stream: string, delta: IndexedSnapshot, msg: Incoming[]): Incoming[];
33
- }
package/lib/merge.js DELETED
@@ -1,569 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeltaTransformingLogicImpl = exports.SnapshotUtil = exports.MsgType = void 0;
4
- const data_structure_1 = require("./data_structure");
5
- const message_class_1 = require("./message_class");
6
- const mutable_1 = require("./mutable");
7
- const core_1 = require("./core");
8
- const data_structure_2 = require("./data_structure");
9
- var MsgType;
10
- (function (MsgType) {
11
- MsgType[MsgType["INSERT"] = 0] = "INSERT";
12
- MsgType[MsgType["UPDATE"] = 1] = "UPDATE";
13
- MsgType[MsgType["DELETE"] = 2] = "DELETE";
14
- })(MsgType = exports.MsgType || (exports.MsgType = {}));
15
- ;
16
- /*
17
- * This file has all the functions to merge various Message Types
18
- */
19
- class SnapshotUtil {
20
- static combineSnapshots(msgType, childSs, parentSs) {
21
- //Validate that message belongs to sports group
22
- if (msgType.group().id() != SnapshotUtil.SPORTS_GROUP.id()) {
23
- console.error("FATAL: Received non feed message group's class %s.Shouldnt come here", msgType);
24
- let messageBefore = new data_structure_1.MessageBeforeTransform();
25
- messageBefore.setAfterSs(parentSs);
26
- return messageBefore;
27
- }
28
- let classId = msgType.id();
29
- switch (classId) {
30
- case SnapshotUtil.SPORTS_GROUP.DATA_INSERT_MATCH().id(): {
31
- return SnapshotUtil.processMatches(MsgType.INSERT, childSs, parentSs);
32
- }
33
- case SnapshotUtil.SPORTS_GROUP.DATA_UPDATE_MATCH().id(): {
34
- return SnapshotUtil.processMatches(MsgType.UPDATE, childSs, parentSs);
35
- }
36
- case SnapshotUtil.SPORTS_GROUP.DATA_DELETE_MATCH().id(): {
37
- return SnapshotUtil.processMatches(MsgType.DELETE, childSs, parentSs);
38
- }
39
- case SnapshotUtil.SPORTS_GROUP.DATA_INSERT_EVENT().id(): {
40
- return SnapshotUtil.processEvents(MsgType.INSERT, childSs, parentSs);
41
- }
42
- case SnapshotUtil.SPORTS_GROUP.DATA_UPDATE_EVENT().id(): {
43
- return SnapshotUtil.processEvents(MsgType.UPDATE, childSs, parentSs);
44
- }
45
- case SnapshotUtil.SPORTS_GROUP.DATA_DELETE_EVENT().id(): {
46
- return SnapshotUtil.processEvents(MsgType.DELETE, childSs, parentSs);
47
- }
48
- case SnapshotUtil.SPORTS_GROUP.DATA_INSERT_ODD().id(): {
49
- return SnapshotUtil.processOdds(MsgType.INSERT, childSs, parentSs);
50
- }
51
- case SnapshotUtil.SPORTS_GROUP.DATA_UPDATE_ODD().id(): {
52
- return SnapshotUtil.processOdds(MsgType.UPDATE, childSs, parentSs);
53
- }
54
- case SnapshotUtil.SPORTS_GROUP.DATA_DELETE_ODD().id(): {
55
- return SnapshotUtil.processOdds(MsgType.DELETE, childSs, parentSs);
56
- }
57
- case SnapshotUtil.SPORTS_GROUP.DATA_RESET().id(): {
58
- return SnapshotUtil.processReset(childSs, parentSs);
59
- }
60
- case SnapshotUtil.SPORTS_GROUP.ADMIN_REFRESH().id(): {
61
- return SnapshotUtil.processRefresh(childSs, parentSs);
62
- }
63
- default: {
64
- console.error("FATAL: Received non data message class %s.Shouldnt come here", msgType);
65
- let messageBefore = new data_structure_1.MessageBeforeTransform();
66
- messageBefore.setAfterSs(parentSs);
67
- return messageBefore;
68
- }
69
- }
70
- }
71
- /*
72
- * Mark all the keys in child Snapshot as refreshed
73
- */
74
- static processRefresh(childSs, parentSs) {
75
- let sBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(parentSs);
76
- let messageBefore = new data_structure_1.MessageBeforeTransform();
77
- // Mark child keys as last updated in builder
78
- let ps = childSs.getPartitions().toArray();
79
- for (let key of ps) {
80
- let time = childSs.getPartitionMap().getValue(key);
81
- sBuilder.markPartitionAsUpdated(key, time);
82
- }
83
- messageBefore.setAfterSs(sBuilder.build());
84
- return messageBefore;
85
- }
86
- /*
87
- * Remove all the data corresponding to keys from Reset Message
88
- */
89
- static processReset(childSs, parentSs) {
90
- let sBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(parentSs);
91
- let messageBefore = new data_structure_1.MessageBeforeTransform();
92
- //Reset Child keys
93
- let ps = childSs.getPartitions().toArray();
94
- for (let key of ps) {
95
- sBuilder.reset(key);
96
- let time = childSs.getPartitionMap().getValue(key);
97
- sBuilder.markPartitionAsUpdated(key, time);
98
- }
99
- messageBefore.setAfterSs(sBuilder.build());
100
- return messageBefore;
101
- }
102
- static processMatches(msgType, childSs, parentSs) {
103
- let sBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(parentSs);
104
- let messageBefore = new data_structure_1.MessageBeforeTransform();
105
- let suppressId = null;
106
- // iterate child's matches
107
- for (let childMatch of childSs.matches()) {
108
- suppressId = null;
109
- switch (msgType) {
110
- case MsgType.INSERT: {
111
- suppressId = sBuilder.insertChild(childMatch);
112
- if (suppressId != null) {
113
- messageBefore.setSuppressMatch(suppressId);
114
- }
115
- else {
116
- messageBefore.setInsertMatch(childMatch.id());
117
- }
118
- break;
119
- }
120
- case MsgType.UPDATE: {
121
- sBuilder.updateChild(childMatch);
122
- break;
123
- }
124
- case MsgType.DELETE: {
125
- suppressId = sBuilder.deleteChild(childMatch);
126
- if (suppressId != null) {
127
- messageBefore.setSuppressMatch(suppressId);
128
- }
129
- else {
130
- messageBefore.setDeleteMatch(childMatch.id());
131
- }
132
- break;
133
- }
134
- default: {
135
- console.error("[Match] FATAL: Shouldn't come here");
136
- break;
137
- }
138
- }
139
- }
140
- // Mark child keys as last updated
141
- let ps = childSs.getPartitions().toArray();
142
- for (let key of ps) {
143
- let time = childSs.getPartitionMap().getValue(key);
144
- sBuilder.markPartitionAsUpdated(key, time);
145
- }
146
- messageBefore.setAfterSs(sBuilder.build());
147
- return messageBefore;
148
- }
149
- static processEvents(msgType, childSs, parentSs) {
150
- let sBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(parentSs);
151
- let suppressId = null;
152
- let messageBefore = new data_structure_1.MessageBeforeTransform();
153
- // iterate child's matches
154
- for (let childMatch of childSs.matches()) {
155
- // Check if parent exists
156
- let parentMatch = parentSs.match(childMatch.id());
157
- if (parentMatch == null) {
158
- console.error("Cannot find Match %s while processing %s", childMatch.id(), MsgType);
159
- continue;
160
- }
161
- let matchBuilder = mutable_1.BuilderProvider.getMatchBuilder(parentMatch);
162
- // Iterate child's events
163
- for (let childEvent of childMatch.events()) {
164
- switch (msgType) {
165
- case MsgType.INSERT: {
166
- suppressId = matchBuilder.insertChild(childEvent);
167
- if (suppressId != null) {
168
- messageBefore.setTransformEvent(childEvent.matchId() + "_" + childEvent.id());
169
- }
170
- else {
171
- messageBefore.setInsertEvent(childEvent.matchId() + "_" + childEvent.id());
172
- }
173
- break;
174
- }
175
- case MsgType.UPDATE: {
176
- matchBuilder.updateChild(childEvent);
177
- break;
178
- }
179
- case MsgType.DELETE: {
180
- suppressId = matchBuilder.deleteChild(childEvent);
181
- if (suppressId != null) {
182
- messageBefore.setTransformEvent(childEvent.matchId() + "_" + childEvent.id());
183
- }
184
- else {
185
- messageBefore.setDeleteEvent(childEvent.matchId() + "_" + childEvent.id());
186
- }
187
- break;
188
- }
189
- default: {
190
- console.error("[Event] FATAL: Shouldn't come here");
191
- break;
192
- }
193
- }
194
- }
195
- // Finally add updated match to snapshot
196
- sBuilder.replaceMatch(matchBuilder.build());
197
- }
198
- //Mark partition keys as updated
199
- let ps = childSs.getPartitions().toArray();
200
- for (let key of ps) {
201
- let time = childSs.getPartitionMap().getValue(key);
202
- sBuilder.markPartitionAsUpdated(key, time);
203
- }
204
- messageBefore.setAfterSs(sBuilder.build());
205
- messageBefore.setBeforeSs(parentSs);
206
- return messageBefore;
207
- }
208
- static processOdds(msgType, childSs, parentSs) {
209
- let sBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(parentSs);
210
- let messageBefore = new data_structure_1.MessageBeforeTransform();
211
- // iterate child's matches
212
- for (let childMatch of childSs.matches()) {
213
- // Check if parent exists
214
- let parentMatch = parentSs.match(childMatch.id());
215
- if (parentMatch == null) {
216
- console.error("Cannot find Match %s while processing %s", childMatch.id(), msgType);
217
- continue;
218
- }
219
- let matchBuilder = mutable_1.BuilderProvider.getMatchBuilder(parentMatch);
220
- // Iterate child's events
221
- for (let childEvent of childMatch.events()) {
222
- let parentEvent = parentMatch.event(childEvent.id());
223
- if (parentEvent == null) {
224
- console.error("Cannot find Event %s_%s while processing %s", childMatch.id(), childEvent.id(), msgType);
225
- continue;
226
- }
227
- let clonedparentEvent = mutable_1.BuilderProvider.getEventBuilder(parentEvent);
228
- for (let rec of childEvent.records()) {
229
- switch (msgType) {
230
- case MsgType.INSERT: {
231
- clonedparentEvent.insertChild(rec);
232
- break;
233
- }
234
- case MsgType.UPDATE: {
235
- clonedparentEvent.updateChild(rec);
236
- break;
237
- }
238
- case MsgType.DELETE: {
239
- clonedparentEvent.deleteChild(rec);
240
- break;
241
- }
242
- default: {
243
- console.error("[Record] FATAL: Shouldn't come here");
244
- break;
245
- }
246
- }
247
- }
248
- // Finally add updated event to match
249
- matchBuilder.replaceEvent(clonedparentEvent.build());
250
- }
251
- // Finally add updated match to snapshot
252
- sBuilder.replaceMatch(matchBuilder.build());
253
- }
254
- //Mark partition keys as updated
255
- let ps = childSs.getPartitions().toArray();
256
- for (let key of ps) {
257
- let time = childSs.getPartitionMap().getValue(key);
258
- sBuilder.markPartitionAsUpdated(key, time);
259
- }
260
- messageBefore.setAfterSs(sBuilder.build());
261
- return messageBefore;
262
- }
263
- }
264
- exports.SnapshotUtil = SnapshotUtil;
265
- SnapshotUtil.SPORTS_GROUP = new message_class_1.SportsFeedMessageGroup();
266
- class DeltaTransformingLogicImpl {
267
- static transform(sportsGrp, stream, msgType, delta, msgBefore) {
268
- let classId = msgType.id();
269
- switch (classId) {
270
- case sportsGrp.DATA_INSERT_MATCH().id(): {
271
- return this.suppressInsertMatch(msgBefore, sportsGrp, msgType, stream, delta, []);
272
- }
273
- case sportsGrp.DATA_DELETE_MATCH().id(): {
274
- return this.suppressDeleteMatch(msgBefore, sportsGrp, msgType, stream, delta, []);
275
- }
276
- case sportsGrp.DATA_INSERT_EVENT().id(): {
277
- return this.suppressInsertEvent(msgBefore, sportsGrp, msgType, stream, delta, []);
278
- }
279
- case sportsGrp.DATA_DELETE_EVENT().id(): {
280
- return this.suppressDeleteEvent(msgBefore, sportsGrp, msgType, stream, delta, []);
281
- }
282
- case sportsGrp.DATA_UPDATE_EVENT().id(): {
283
- return this.combineEventState(msgBefore, sportsGrp, msgType, stream, delta, []);
284
- }
285
- }
286
- let msg = [];
287
- msg.push(new data_structure_1.Incoming(msgType, stream, delta));
288
- return msg;
289
- }
290
- static combineEventState(msgBefore, sportsGrp, msgType, stream, delta, msg) {
291
- let updateEventSnapshotBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(delta);
292
- for (let m of delta.matches()) {
293
- let upadateMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(m);
294
- for (let e of m.events()) {
295
- let updateEventBuilder = mutable_1.BuilderProvider.getEventBuilder(e);
296
- updateEventBuilder.aggregateInsert(msgBefore.getAfterSs().match(m.id()).event(e.id()));
297
- upadateMatchBuilder.replaceEvent(updateEventBuilder.build());
298
- }
299
- updateEventSnapshotBuilder.replaceMatch(upadateMatchBuilder.build());
300
- }
301
- msg.push(new data_structure_1.Incoming(sportsGrp.DATA_UPDATE_EVENT(), stream, updateEventSnapshotBuilder.build()));
302
- return msg;
303
- }
304
- static suppressInsertEvent(msgBefore, sportsGrp, msgType, stream, delta, msg) {
305
- let insertEventSnapshotBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(delta);
306
- let updateEventSnapshotBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(delta);
307
- if (delta.matches().length != 0) {
308
- if (msgBefore.getInsertEvent().length != 0) {
309
- let insertEvents = {};
310
- for (let id of msgBefore.getTransformEvent()) {
311
- let matchId = id.split("_")[0];
312
- let eventId = id.split("_")[1];
313
- let match = delta.match(matchId);
314
- let suppressMatchBuilder = insertEvents[matchId];
315
- if (suppressMatchBuilder === undefined) {
316
- suppressMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(match);
317
- insertEvents[matchId] = suppressMatchBuilder;
318
- }
319
- suppressMatchBuilder.deleteChild(match.event(eventId));
320
- }
321
- for (let matchId in insertEvents) {
322
- insertEventSnapshotBuilder.replaceMatch(insertEvents[matchId].build());
323
- }
324
- msg.push(new data_structure_1.Incoming(sportsGrp.DATA_INSERT_EVENT(), stream, insertEventSnapshotBuilder.build()));
325
- }
326
- if (msgBefore.getTransformEvent().length != 0) {
327
- let updateEvents = {};
328
- for (let id of msgBefore.getInsertEvent()) {
329
- let matchId = id.split("_")[0];
330
- let eventId = id.split("_")[1];
331
- let match = delta.match(matchId);
332
- let insertMatchBuilder = updateEvents[matchId];
333
- if (insertMatchBuilder === undefined) {
334
- insertMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(match);
335
- updateEvents[matchId] = insertMatchBuilder;
336
- }
337
- insertMatchBuilder.deleteChild(match.event(eventId));
338
- }
339
- for (let id of msgBefore.getTransformEvent()) {
340
- let matchId = id.split("_")[0];
341
- let eventId = id.split("_")[1];
342
- let match = delta.match(matchId);
343
- let updateMatchBuilder = updateEvents[matchId];
344
- if (updateMatchBuilder === undefined) {
345
- updateMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(match);
346
- updateEvents[matchId] = updateMatchBuilder;
347
- }
348
- let updateEventBuilder = mutable_1.BuilderProvider.getEventBuilder(match.event(eventId));
349
- updateEventBuilder.aggregateInsert(msgBefore.getAfterSs().match(matchId).event(eventId));
350
- updateMatchBuilder.replaceEvent(updateEventBuilder.build());
351
- }
352
- for (let matchId in updateEvents) {
353
- updateEventSnapshotBuilder.replaceMatch(updateEvents[matchId].build());
354
- }
355
- msg.push(new data_structure_1.Incoming(sportsGrp.DATA_UPDATE_EVENT(), stream, updateEventSnapshotBuilder.build()));
356
- }
357
- }
358
- return msg;
359
- }
360
- static transformTTLRestore(ttlRestoredList, grp, stream, before, after, matches, restoredKeys) {
361
- let combineSs = data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT;
362
- let wrap = new data_structure_1.MergeableWrapper();
363
- for (let ssRestored of ttlRestoredList) {
364
- combineSs = SnapshotUtil.combineSnapshots(grp.DATA_INSERT_MATCH(), ssRestored, combineSs).getAfterSs();
365
- combineSs = SnapshotUtil.combineSnapshots(grp.DATA_INSERT_EVENT(), ssRestored, combineSs).getAfterSs();
366
- combineSs = SnapshotUtil.combineSnapshots(grp.DATA_INSERT_ODD(), ssRestored, combineSs).getAfterSs();
367
- }
368
- let breakdownCol = this.breakdownTTL(grp, stream, new data_structure_2.IndexedSnapshotImpl(combineSs.matchesSport, restoredKeys));
369
- let beforeSnap = before;
370
- let outgoCol = [];
371
- for (let i of breakdownCol) {
372
- let msgBefore = SnapshotUtil.combineSnapshots(i.msgType(), i.data(), beforeSnap);
373
- if (i.msgType().id() == grp.DATA_INSERT_MATCH().id() || i.msgType().id() == grp.DATA_INSERT_EVENT().id()) {
374
- let incomeCol = DeltaTransformingLogicImpl.transform(grp, stream, i.msgType(), i.data(), msgBefore);
375
- for (let incomingAfterTransform of incomeCol) {
376
- let iDelta = new core_1.Delta(incomingAfterTransform, msgBefore.getAfterSs(), beforeSnap);
377
- outgoCol.push(iDelta);
378
- beforeSnap = msgBefore.getAfterSs();
379
- }
380
- }
381
- else {
382
- let iDelta = new core_1.Delta(i, msgBefore.getAfterSs(), before);
383
- outgoCol.push(iDelta);
384
- }
385
- }
386
- wrap.setAfter(after);
387
- wrap.setDeltaOut(outgoCol);
388
- return wrap;
389
- }
390
- static transformTTLRemove(ttlRemoveList, grp, stream, before, after, keysRemoved) {
391
- let wrapper = new data_structure_1.MergeableWrapper();
392
- let combineSs = data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT;
393
- let beforeSnap;
394
- for (let ssRemoved of ttlRemoveList) {
395
- combineSs = SnapshotUtil.combineSnapshots(grp.DATA_INSERT_MATCH(), ssRemoved, combineSs).getAfterSs();
396
- combineSs = SnapshotUtil.combineSnapshots(grp.DATA_INSERT_EVENT(), ssRemoved, combineSs).getAfterSs();
397
- combineSs = SnapshotUtil.combineSnapshots(grp.DATA_INSERT_ODD(), ssRemoved, combineSs).getAfterSs();
398
- }
399
- let breakdownResetCol = DeltaTransformingLogicImpl.breakdownReset(grp, stream, combineSs);
400
- beforeSnap = before;
401
- let outgoCol = [];
402
- for (let i of breakdownResetCol) {
403
- let msgBefore = SnapshotUtil.combineSnapshots(i.msgType(), i.data(), beforeSnap);
404
- if (i.msgType().id() == grp.DATA_DELETE_MATCH().id() || i.msgType().id() == grp.DATA_DELETE_EVENT().id()) {
405
- let incomeCol = DeltaTransformingLogicImpl.transform(grp, stream, i.msgType(), i.data(), msgBefore);
406
- for (let incomingAfterTransform of incomeCol) {
407
- let iDelta = new core_1.Delta(incomingAfterTransform, msgBefore.getAfterSs(), beforeSnap);
408
- outgoCol.push(iDelta);
409
- beforeSnap = msgBefore.getAfterSs();
410
- }
411
- }
412
- else {
413
- let iDelta = new core_1.Delta(i, msgBefore.getAfterSs(), before);
414
- outgoCol.push(iDelta);
415
- }
416
- }
417
- wrapper.setDeltaOut(outgoCol);
418
- wrapper.setAfter(after);
419
- return wrapper;
420
- }
421
- static breakdownTTL(grp, stream, restoredSS) {
422
- let noEventSs = data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT;
423
- let noRecordSs = data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT;
424
- let iMatchBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(restoredSS);
425
- let iEventBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(restoredSS);
426
- for (let m of restoredSS.matches()) {
427
- let noEventMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(m);
428
- let noRecordEventBuilder = mutable_1.BuilderProvider.getMatchBuilder(m);
429
- for (let e of m.events()) {
430
- noEventMatchBuilder.deleteChild(e);
431
- let noRecord = mutable_1.BuilderProvider.getEventBuilder(e);
432
- for (let r of e.records()) {
433
- noRecord.deleteChild(r);
434
- }
435
- noRecordEventBuilder.replaceEvent(noRecord.build());
436
- }
437
- iMatchBuilder.replaceMatch(noEventMatchBuilder.build());
438
- iEventBuilder.replaceMatch(noRecordEventBuilder.build());
439
- }
440
- noEventSs = iMatchBuilder.build();
441
- noRecordSs = iEventBuilder.build();
442
- let msg = [];
443
- msg.push(new data_structure_1.Incoming(grp.DATA_INSERT_MATCH(), stream, noEventSs));
444
- msg.push(new data_structure_1.Incoming(grp.DATA_INSERT_EVENT(), stream, noRecordSs));
445
- msg.push(new data_structure_1.Incoming(grp.DATA_INSERT_ODD(), stream, restoredSS));
446
- return msg;
447
- }
448
- static breakdownReset(grp, stream, removeSs) {
449
- let noEventSs = data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT;
450
- let noRecordSs = data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT;
451
- let iMatchBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(removeSs);
452
- let iEventBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(removeSs);
453
- for (let m of removeSs.matches()) {
454
- let noEventMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(m);
455
- let noRecordEventBuilder = mutable_1.BuilderProvider.getMatchBuilder(m);
456
- for (let e of m.events()) {
457
- noEventMatchBuilder.deleteChild(e);
458
- let noRecord = mutable_1.BuilderProvider.getEventBuilder(e);
459
- for (let r of e.records()) {
460
- noRecord.deleteChild(r);
461
- }
462
- noRecordEventBuilder.replaceEvent(noRecord.build());
463
- }
464
- iMatchBuilder.replaceMatch(noEventMatchBuilder.build());
465
- iEventBuilder.replaceMatch(noRecordEventBuilder.build());
466
- }
467
- noEventSs = iMatchBuilder.build();
468
- noRecordSs = iEventBuilder.build();
469
- let msg = [];
470
- msg.push(new data_structure_1.Incoming(grp.DATA_DELETE_ODD(), stream, removeSs));
471
- msg.push(new data_structure_1.Incoming(grp.DATA_DELETE_EVENT(), stream, noRecordSs));
472
- msg.push(new data_structure_1.Incoming(grp.DATA_DELETE_MATCH(), stream, noEventSs));
473
- return msg;
474
- }
475
- static suppressInsertMatch(msgBefore, sportsGrp, msgType, stream, delta, msg) {
476
- let insertMatchSnapshotBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(delta);
477
- let updateMatchSnapshotBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(delta);
478
- if (msgBefore.getSuppressMatch().length != 0) {
479
- for (let id of msgBefore.getSuppressMatch()) {
480
- let suppressMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(delta.match(id.split("_")[0]));
481
- insertMatchSnapshotBuilder.deleteChild(suppressMatchBuilder.build());
482
- }
483
- }
484
- if (msgBefore.getInsertMatch().length != 0) {
485
- for (let id of msgBefore.getInsertMatch()) {
486
- let suppressMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(delta.match(id.split("_")[0]));
487
- updateMatchSnapshotBuilder.deleteChild(suppressMatchBuilder.build());
488
- }
489
- }
490
- if (insertMatchSnapshotBuilder.build().matches().length != 0) {
491
- msg.push(new data_structure_1.Incoming(sportsGrp.DATA_INSERT_MATCH(), stream, insertMatchSnapshotBuilder.build()));
492
- }
493
- return msg;
494
- }
495
- static suppressDeleteEvent(msgBefore, sportsGrp, msgType, stream, delta, msg) {
496
- let deleteEventSnapshotBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(delta);
497
- let updateEventSnapshotBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(delta);
498
- if (msgBefore.getDeleteEvent().length != 0) {
499
- let suppressedMatches = {};
500
- for (let id of msgBefore.getTransformEvent()) {
501
- let matchId = id.split("_")[0];
502
- let eventId = id.split("_")[1];
503
- let match = msgBefore.getBeforeSs().match(matchId);
504
- let suppressMatchBuilder = suppressedMatches[matchId];
505
- if (suppressMatchBuilder === undefined) {
506
- suppressMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(match);
507
- suppressedMatches[matchId] = suppressMatchBuilder;
508
- }
509
- suppressMatchBuilder.deleteChild(match.event(eventId));
510
- }
511
- for (let matchId in suppressedMatches) {
512
- deleteEventSnapshotBuilder.replaceMatch(suppressedMatches[matchId].build());
513
- }
514
- msg.push(new data_structure_1.Incoming(sportsGrp.DATA_DELETE_EVENT(), stream, deleteEventSnapshotBuilder.build()));
515
- }
516
- if (msgBefore.getTransformEvent().length != 0) {
517
- let matches = {};
518
- for (let id of msgBefore.getDeleteEvent()) {
519
- let matchId = id.split("_")[0];
520
- let eventId = id.split("_")[1];
521
- let match = msgBefore.getBeforeSs().match(matchId);
522
- let deleteMatchBuilder = matches[matchId];
523
- if (deleteMatchBuilder === undefined) {
524
- deleteMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(match);
525
- matches[matchId] = deleteMatchBuilder;
526
- }
527
- deleteMatchBuilder.deleteChild(match.event(eventId));
528
- }
529
- for (let id of msgBefore.getTransformEvent()) {
530
- let matchId = id.split("_")[0];
531
- let eventId = id.split("_")[1];
532
- let updateMatchBuilder = matches[matchId];
533
- if (updateMatchBuilder === undefined) {
534
- updateMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(msgBefore.getBeforeSs().match(matchId));
535
- matches[matchId] = updateMatchBuilder;
536
- }
537
- let updateEventBuilder = mutable_1.BuilderProvider.getEventBuilder(updateMatchBuilder.build().event(eventId));
538
- updateEventBuilder.aggregateDelete(delta.match(matchId).event(eventId));
539
- updateMatchBuilder.replaceEvent(updateEventBuilder.build());
540
- }
541
- for (let matchId in matches) {
542
- updateEventSnapshotBuilder.replaceMatch(matches[matchId].build());
543
- }
544
- msg.push(new data_structure_1.Incoming(sportsGrp.DATA_UPDATE_EVENT(), stream, updateEventSnapshotBuilder.build()));
545
- }
546
- return msg;
547
- }
548
- static suppressDeleteMatch(msgBefore, sportsGrp, msgType, stream, delta, msg) {
549
- let deleteMatchSnapshotBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(delta);
550
- let updateMatchSnapshotBuilder = mutable_1.BuilderProvider.getSnapshotBuilder(delta);
551
- if (msgBefore.getSuppressMatch().length != 0) {
552
- for (let id of msgBefore.getSuppressMatch()) {
553
- let suppressMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(delta.match(id.split("_")[0]));
554
- deleteMatchSnapshotBuilder.deleteChild(suppressMatchBuilder.build());
555
- }
556
- }
557
- if (msgBefore.getDeleteMatch().length != 0) {
558
- for (let id of msgBefore.getDeleteMatch()) {
559
- let suppressMatchBuilder = mutable_1.BuilderProvider.getMatchBuilder(delta.match(id.split("_")[0]));
560
- updateMatchSnapshotBuilder.deleteChild(suppressMatchBuilder.build());
561
- }
562
- }
563
- if (deleteMatchSnapshotBuilder.build().matches().length != 0) {
564
- msg.push(new data_structure_1.Incoming(sportsGrp.DATA_DELETE_MATCH(), stream, deleteMatchSnapshotBuilder.build()));
565
- }
566
- return msg;
567
- }
568
- }
569
- exports.DeltaTransformingLogicImpl = DeltaTransformingLogicImpl;