@jayesol/jayeson.lib.sports 2.2.5 → 2.2.6-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,208 @@
1
- "use strict";var __extends=this&&this.__extends||function(){var r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}();Object.defineProperty(exports,"__esModule",{value:!0});var Collections=require("typescript-collections"),jayeson_lib_record_1=require("@jayesol/jayeson.lib.record"),Incoming=function(){function t(t,e,n){this._msgType=t,this._stream=e,this._data=n}return t.prototype.msgType=function(){return this._msgType},t.prototype.stream=function(){return this._stream},t.prototype.data=function(){return this._data},t}();exports.Incoming=Incoming;var IndexedSnapshotImpl=function(r){function t(t,e){void 0===t&&(t={}),void 0===e&&(e=new Collections.Dictionary);var n=r.call(this,t)||this;return n.partitions=e,n}return __extends(t,r),t.prototype.getPartitions=function(){for(var t=new Collections.Set,e=0,n=this.partitions.keys();e<n.length;e++){var r=n[e];t.add(r)}return t},t.prototype.getPartitionMap=function(){return this.partitions},t.EMPTY_SNAPSHOT=new t,t}(jayeson_lib_record_1.Snapshot);exports.IndexedSnapshotImpl=IndexedSnapshotImpl;var OutgoingImpl=function(){function t(t,e){this._msgType=t,this._msg=e}return t.prototype.msgType=function(){return this._msgType},t.prototype.msg=function(){return this._msg},t}(),DeltaOutgoingImpl=function(s){function t(t,e,n,r){var o=s.call(this,t,e)||this;return o._delta=e,o._after=n,o._before=r,o}return __extends(t,s),t.prototype.after=function(){return this._after},t.prototype.delta=function(){return this._delta},t.prototype.before=function(){return this._before},t}(exports.OutgoingImpl=OutgoingImpl);exports.DeltaOutgoingImpl=DeltaOutgoingImpl;var ConvertedMsg,MessageBeforeTransform=function(){function t(){this.transformEvent=[],this.suppressMatch=[],this.insertMatch=[],this.deleteMatch=[],this.insertEvent=[],this.deleteEvent=[],this.afterSs=IndexedSnapshotImpl.EMPTY_SNAPSHOT,this.beforeSs=IndexedSnapshotImpl.EMPTY_SNAPSHOT}return t.prototype.getTransformEvent=function(){return this.transformEvent},t.prototype.setTransformEvent=function(t){this.transformEvent.push(t)},t.prototype.getSuppressMatch=function(){return this.suppressMatch},t.prototype.setSuppressMatch=function(t){this.suppressMatch.push(t)},t.prototype.setAfterSs=function(t){this.afterSs=t},t.prototype.getAfterSs=function(){return this.afterSs},t.prototype.setBeforeSs=function(t){this.beforeSs=t},t.prototype.getBeforeSs=function(){return this.beforeSs},t.prototype.setInsertEvent=function(t){this.insertEvent.push(t)},t.prototype.getInsertEvent=function(){return this.insertEvent},t.prototype.setDeleteEvent=function(t){this.deleteEvent.push(t)},t.prototype.getDeleteEvent=function(){return this.deleteEvent},t.prototype.setInsertMatch=function(t){this.insertMatch.push(t)},t.prototype.getInsertMatch=function(){return this.insertMatch},t.prototype.setDeleteMatch=function(t){this.deleteMatch.push(t)},t.prototype.getDeleteMatch=function(){return this.deleteMatch},t}();exports.MessageBeforeTransform=MessageBeforeTransform,function(t){t[t.INSERT_EVENT_TO_UPDATE=0]="INSERT_EVENT_TO_UPDATE",t[t.DELETE_EVENT_TO_UPDATE=1]="DELETE_EVENT_TO_UPDATE",t[t.INSERT_MATCH_SUPPRESS=2]="INSERT_MATCH_SUPPRESS",t[t.DELETE_MATCH_SUPPRESS=3]="DELETE_MATCH_SUPPRESS",t[t.ORIGINAL=4]="ORIGINAL"}(ConvertedMsg=exports.ConvertedMsg||(exports.ConvertedMsg={}));var MergeableWrapper=function(){function t(){this.snap=IndexedSnapshotImpl.EMPTY_SNAPSHOT}return t.prototype.setDeltaOut=function(t){this.deltaOut=t},t.prototype.setAfter=function(t){this.snap=t},t.prototype.getDeltaOut=function(){return this.deltaOut},t.prototype.getAfter=function(){return this.snap},t}();exports.MergeableWrapper=MergeableWrapper;var TTLWrapper=function(){function t(){}return t.prototype._RemovedKey=function(){this.removedSs=IndexedSnapshotImpl.EMPTY_SNAPSHOT,this.remainingSs=IndexedSnapshotImpl.EMPTY_SNAPSHOT,this.restoredSs=IndexedSnapshotImpl.EMPTY_SNAPSHOT},t.prototype.setRemovedSs=function(t){this.removedSs=t},t.prototype.getRemovedSs=function(){return this.removedSs},t.prototype.setRemainingSs=function(t){this.remainingSs=t},t.prototype.getRemainingSs=function(){return this.remainingSs},t.prototype.getRestoredSs=function(){return this.restoredSs},t.prototype.setRestoredSs=function(t){this.restoredSs=t},t}();exports.TTLWrapper=TTLWrapper;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.TTLWrapper = exports.MergeableWrapper = exports.ConvertedMsg = exports.MessageBeforeTransform = exports.DeltaOutgoingImpl = exports.OutgoingImpl = exports.IndexedSnapshotImpl = exports.Incoming = void 0;
27
+ const Collections = __importStar(require("typescript-collections"));
28
+ const jayeson_lib_record_1 = require("@jayesol/jayeson.lib.record");
29
+ class Incoming {
30
+ constructor(_msgType, _stream, _data) {
31
+ this._msgType = _msgType;
32
+ this._stream = _stream;
33
+ this._data = _data;
34
+ }
35
+ msgType() {
36
+ return this._msgType;
37
+ }
38
+ stream() {
39
+ return this._stream;
40
+ }
41
+ data() {
42
+ return this._data;
43
+ }
44
+ }
45
+ exports.Incoming = Incoming;
46
+ class IndexedSnapshotImpl extends jayeson_lib_record_1.Snapshot {
47
+ constructor(matches = {}, partitions = new Collections.Dictionary()) {
48
+ super(matches);
49
+ this.partitions = partitions;
50
+ }
51
+ getPartitions() {
52
+ let keys = new Collections.Set();
53
+ for (var partition of this.partitions.keys()) {
54
+ keys.add(partition);
55
+ }
56
+ return keys;
57
+ }
58
+ //TODO Return Immutable Map/clone??
59
+ getPartitionMap() {
60
+ return this.partitions;
61
+ }
62
+ }
63
+ exports.IndexedSnapshotImpl = IndexedSnapshotImpl;
64
+ IndexedSnapshotImpl.EMPTY_SNAPSHOT = new IndexedSnapshotImpl();
65
+ class OutgoingImpl {
66
+ constructor(_msgType, _msg) {
67
+ this._msgType = _msgType;
68
+ this._msg = _msg;
69
+ }
70
+ msgType() {
71
+ return this._msgType;
72
+ }
73
+ msg() {
74
+ return this._msg;
75
+ }
76
+ }
77
+ exports.OutgoingImpl = OutgoingImpl;
78
+ class DeltaOutgoingImpl extends OutgoingImpl {
79
+ constructor(_msgType, _delta, _after, _before) {
80
+ super(_msgType, _delta);
81
+ this._delta = _delta;
82
+ this._after = _after;
83
+ this._before = _before;
84
+ }
85
+ after() {
86
+ return this._after;
87
+ }
88
+ delta() {
89
+ return this._delta;
90
+ }
91
+ before() {
92
+ return this._before;
93
+ }
94
+ }
95
+ exports.DeltaOutgoingImpl = DeltaOutgoingImpl;
96
+ class MessageBeforeTransform {
97
+ constructor() {
98
+ this.transformEvent = [];
99
+ this.suppressMatch = [];
100
+ this.insertMatch = [];
101
+ this.deleteMatch = [];
102
+ this.insertEvent = [];
103
+ this.deleteEvent = [];
104
+ this.afterSs = IndexedSnapshotImpl.EMPTY_SNAPSHOT;
105
+ this.beforeSs = IndexedSnapshotImpl.EMPTY_SNAPSHOT;
106
+ }
107
+ getTransformEvent() {
108
+ return this.transformEvent;
109
+ }
110
+ setTransformEvent(eventId) {
111
+ this.transformEvent.push(eventId);
112
+ }
113
+ getSuppressMatch() {
114
+ return this.suppressMatch;
115
+ }
116
+ setSuppressMatch(matchId) {
117
+ this.suppressMatch.push(matchId);
118
+ }
119
+ setAfterSs(afterSs) {
120
+ this.afterSs = afterSs;
121
+ }
122
+ getAfterSs() {
123
+ return this.afterSs;
124
+ }
125
+ setBeforeSs(beforeSs) {
126
+ this.beforeSs = beforeSs;
127
+ }
128
+ getBeforeSs() {
129
+ return this.beforeSs;
130
+ }
131
+ setInsertEvent(eventId) {
132
+ this.insertEvent.push(eventId);
133
+ }
134
+ getInsertEvent() {
135
+ return this.insertEvent;
136
+ }
137
+ setDeleteEvent(eventId) {
138
+ this.deleteEvent.push(eventId);
139
+ }
140
+ getDeleteEvent() {
141
+ return this.deleteEvent;
142
+ }
143
+ setInsertMatch(matchId) {
144
+ this.insertMatch.push(matchId);
145
+ }
146
+ getInsertMatch() {
147
+ return this.insertMatch;
148
+ }
149
+ setDeleteMatch(matchId) {
150
+ this.deleteMatch.push(matchId);
151
+ }
152
+ getDeleteMatch() {
153
+ return this.deleteMatch;
154
+ }
155
+ }
156
+ exports.MessageBeforeTransform = MessageBeforeTransform;
157
+ var ConvertedMsg;
158
+ (function (ConvertedMsg) {
159
+ ConvertedMsg[ConvertedMsg["INSERT_EVENT_TO_UPDATE"] = 0] = "INSERT_EVENT_TO_UPDATE";
160
+ ConvertedMsg[ConvertedMsg["DELETE_EVENT_TO_UPDATE"] = 1] = "DELETE_EVENT_TO_UPDATE";
161
+ ConvertedMsg[ConvertedMsg["INSERT_MATCH_SUPPRESS"] = 2] = "INSERT_MATCH_SUPPRESS";
162
+ ConvertedMsg[ConvertedMsg["DELETE_MATCH_SUPPRESS"] = 3] = "DELETE_MATCH_SUPPRESS";
163
+ ConvertedMsg[ConvertedMsg["ORIGINAL"] = 4] = "ORIGINAL";
164
+ })(ConvertedMsg = exports.ConvertedMsg || (exports.ConvertedMsg = {}));
165
+ class MergeableWrapper {
166
+ constructor() {
167
+ this.snap = IndexedSnapshotImpl.EMPTY_SNAPSHOT;
168
+ }
169
+ setDeltaOut(out) {
170
+ this.deltaOut = out;
171
+ }
172
+ setAfter(after) {
173
+ this.snap = after;
174
+ }
175
+ getDeltaOut() {
176
+ return this.deltaOut;
177
+ }
178
+ getAfter() {
179
+ return this.snap;
180
+ }
181
+ }
182
+ exports.MergeableWrapper = MergeableWrapper;
183
+ class TTLWrapper {
184
+ _RemovedKey() {
185
+ this.removedSs = IndexedSnapshotImpl.EMPTY_SNAPSHOT;
186
+ this.remainingSs = IndexedSnapshotImpl.EMPTY_SNAPSHOT;
187
+ this.restoredSs = IndexedSnapshotImpl.EMPTY_SNAPSHOT;
188
+ }
189
+ setRemovedSs(remove) {
190
+ this.removedSs = remove;
191
+ }
192
+ getRemovedSs() {
193
+ return this.removedSs;
194
+ }
195
+ setRemainingSs(remain) {
196
+ this.remainingSs = remain;
197
+ }
198
+ getRemainingSs() {
199
+ return this.remainingSs;
200
+ }
201
+ getRestoredSs() {
202
+ return this.restoredSs;
203
+ }
204
+ setRestoredSs(restore) {
205
+ this.restoredSs = restore;
206
+ }
207
+ }
208
+ exports.TTLWrapper = TTLWrapper;
package/lib/dispatch.js CHANGED
@@ -1 +1,325 @@
1
- "use strict";var __extends=this&&this.__extends||function(){var s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(t,e){function r(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),__decorate=this&&this.__decorate||function(t,e,r,s){var o,n=arguments.length,p=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)p=Reflect.decorate(t,e,r,s);else for(var a=t.length-1;0<=a;a--)(o=t[a])&&(p=(n<3?o(p):3<n?o(e,r,p):o(e,r))||p);return 3<n&&p&&Object.defineProperty(e,r,p),p},__metadata=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},__param=this&&this.__param||function(r,s){return function(t,e){s(t,e,r)}};Object.defineProperty(exports,"__esModule",{value:!0});var data_structure_1=require("./data_structure"),core_1=require("./core"),message_class_1=require("./message_class"),injection_js_1=require("injection-js");exports.EPGM_IMPL=new injection_js_1.InjectionToken("EpgmInstance");var WrapperImpl=function(){function t(t,e){this.__epg=t,this.__stream=e}return t.prototype.epg=function(){return this.__epg},t.prototype.stream=function(){return this.__stream},t}(),FullSnapshotWrapper=function(n){function t(t,e,r,s){var o=n.call(this,t,e)||this;return o._epg=t,o._stream=e,o._epd=r,o.fullSnapshot=s,o}return __extends(t,n),t.prototype.epg=function(){return this._epg},t.prototype.stream=function(){return this._stream},t.prototype.epd=function(){return this._epd},t.prototype.process=function(){this._epd.readyToDispatch();var t=this._epg.generateFull(this);if(null!=t)for(var e=0;e<t.length;e++){var r=t[e];this._epd.submit(r)}},t.prototype.getFullSnapshot=function(){return this.fullSnapshot},t.prototype.setFullSnapshot=function(t){this.fullSnapshot=t},t}(exports.WrapperImpl=WrapperImpl);exports.FullSnapshotWrapper=FullSnapshotWrapper;var PartialSnapshotWrapper=function(o){function t(t,e,r){var s=o.call(this,e,r)||this;return s._delta=t,s._epg=e,s._stream=r,s}return __extends(t,o),t.prototype.epg=function(){return this._epg},t.prototype.stream=function(){return this._stream},t.prototype.delta=function(){return this._delta},t.prototype.process=function(){for(var t=this._epg.generatePartial(this),e=this._epg.getEPDs(this._stream),r=0;r<e.length;r++)for(var s=e[r],o=0;o<t.length;o++)if(s.isReadyToDispatch()){var n=t[o];s.submit(n)}},t}(WrapperImpl);exports.PartialSnapshotWrapper=PartialSnapshotWrapper;var IndicatorWrapper=function(o){function t(t,e,r){var s=o.call(this,e,r)||this;return s._delta=t,s._epg=e,s._stream=r,s}return __extends(t,o),t.prototype.process=function(){for(var t=this._epg.getEPDs(this._stream),e=0;e<t.length;e++){t[e].submit(this._delta)}},t}(WrapperImpl);exports.IndicatorWrapper=IndicatorWrapper;var EPDispatcherException=function(e){function t(t){return e.call(this,t)||this}return __extends(t,e),t}(Error);exports.EPDispatcherException=EPDispatcherException;var EndPointGroupManager=function(){function t(t,e){this._fsRepo=t,this._grp=e,this.relayEPG=new RelayEPG(e),this.relayEPG.startGetingDeltaSnapshot(t)}return t.prototype.fsRepo=function(){return this._fsRepo},t.prototype.grp=function(){return this._grp},t.prototype.pushFullSnapshotWrapper=function(s,o){var n=this,p=o.stream();o.isInitialized().then(function(t){if(t){var e=n._fsRepo.getSnapshot(p),r=new FullSnapshotWrapper(s,p,o,e);s.submitForProcess(r)}})},t.prototype.registerEPD=function(t){if(this.relayEPG.hasEPD(t.stream(),t.id()))throw new EPDispatcherException("EPD already exists in a group.Id: "+t.id+" Stream: "+t.stream);this.relayEPG.addEPD(t),this.pushFullSnapshotWrapper(this.relayEPG,t)},t.prototype.deregisterEPD=function(t){this.relayEPG.removeEPD(t)},t=__decorate([injection_js_1.Injectable(),__param(0,injection_js_1.Inject(core_1.FSREPO_IMPL)),__metadata("design:paramtypes",[Object,message_class_1.SportsFeedMessageGroup])],t)}();exports.EndPointGroupManager=EndPointGroupManager;var DispatchersGroup=function(){function t(t){this.streamName=t,this.dispatchers={}}return t.prototype.addEpd=function(t){this.dispatchers[t.id()]=t},t.prototype.removeEpd=function(t){var e=this.dispatchers[t.id()];return delete this.dispatchers[t.id()],e},t.prototype.get=function(t){return this.dispatchers[t]},t.prototype.getAll=function(){var e=this;return Object.keys(this.dispatchers).map(function(t){return e.dispatchers[t]})},t.prototype.isEmpty=function(){return 0==Object.keys(this.dispatchers).length},t}();exports.DispatchersGroup=DispatchersGroup;var AbstractEPG=function(){function t(t){this.sportsFeedGroup=t,this.dispatchers={}}return t.prototype.hasEPD=function(t,e){var r=this.dispatchers[t];return void 0!==r&&void 0!==r.get(e)},t.prototype.addEPD=function(t){void 0===this.dispatchers[t.stream()]&&(this.dispatchers[t.stream()]=new DispatchersGroup(t.stream())),this.dispatchers[t.stream()].addEpd(t)},t.prototype.removeEPD=function(t){var e=this.dispatchers[t.stream()];void 0!==e&&(e.removeEpd(t),e.isEmpty()&&delete this.dispatchers[t.stream()])},t.prototype.isEmpty=function(){return 0==Object.keys(this.dispatchers).length},t.prototype.getEPDs=function(t){var e=this.dispatchers[t];return void 0!==e?e.getAll():[]},t.prototype.getStreams=function(){return Object.keys(this.dispatchers)},t.prototype.startGetingDeltaSnapshot=function(t){t.registerSnapshotHandler(this)},t.prototype.stopGetingDeltaSnapshot=function(t){t.deRegisterSnapshotHandler(this)},t.prototype.process=function(t,e){if(this.sportsFeedGroup.isIndicatorMessage(e.msgType())){var r=new IndicatorWrapper(e,this,t);this.submitForProcess(r)}else{var s=new PartialSnapshotWrapper(e,this,t);this.submitForProcess(s)}},t.prototype.getSportsFeedGrp=function(){return this.sportsFeedGroup},t.prototype.generateFull=function(t){throw new Error("Method not implemented.")},t.prototype.generatePartial=function(t){throw new Error("Method not implemented.")},t}(),RelayEPG=function(r){function t(t){var e=r.call(this,t)||this;return e._sportsFeedGroup=t,e}return __extends(t,r),t.prototype.submitForProcess=function(t){t.process()},t.prototype.onException=function(t){return console.error("Exception when dispatching snapshots to EPDs from RelayEPG. ",t),null},t.prototype.generateFull=function(t){var e=t.getFullSnapshot();return[new data_structure_1.OutgoingImpl(this._sportsFeedGroup.FULLSNAPSHOT_START(),new Object),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_RESET(),e,e,data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_MATCH(),e,e,data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_EVENT(),e,e,data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_ODD(),e,e,data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.OutgoingImpl(this._sportsFeedGroup.FULLSNAPSHOT_END(),new Object)]},t.prototype.generatePartial=function(t){var e=t.delta();return"TTLOutgoing"==e.constructor.name?this.generateTtl(e):[e]},t.prototype.generateTtl=function(t){return this.isSameFormat(t.msgType(),this._sportsFeedGroup.ADMIN_REFRESH())?[]:t.getTtlType()==core_1.TTLType.REMOVE?[t]:this.generateTtlRestore(t)},t.prototype.generateTtlRestore=function(t){return[new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_MATCH(),t.delta(),t.delta(),data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_EVENT(),t.delta(),t.delta(),data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_ODD(),t.delta(),t.delta(),data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT)]},t.prototype.isSameFormat=function(t,e){return t.instanceClass()==e.instanceClass()&&t.constructor.name==e.constructor.name},t=__decorate([injection_js_1.Injectable(),__metadata("design:paramtypes",[message_class_1.SportsFeedMessageGroup])],t)}(exports.AbstractEPG=AbstractEPG);exports.RelayEPG=RelayEPG;
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.RelayEPG = exports.AbstractEPG = exports.DispatchersGroup = exports.EndPointGroupManager = exports.EPDispatcherException = exports.IndicatorWrapper = exports.PartialSnapshotWrapper = exports.FullSnapshotWrapper = exports.WrapperImpl = exports.EPGM_IMPL = void 0;
16
+ const data_structure_1 = require("./data_structure");
17
+ const core_1 = require("./core");
18
+ const message_class_1 = require("./message_class");
19
+ const injection_js_1 = require("injection-js");
20
+ exports.EPGM_IMPL = new injection_js_1.InjectionToken('EpgmInstance');
21
+ class WrapperImpl {
22
+ constructor(__epg, __stream) {
23
+ this.__epg = __epg;
24
+ this.__stream = __stream;
25
+ }
26
+ epg() {
27
+ return this.__epg;
28
+ }
29
+ stream() {
30
+ return this.__stream;
31
+ }
32
+ }
33
+ exports.WrapperImpl = WrapperImpl;
34
+ class FullSnapshotWrapper extends WrapperImpl {
35
+ constructor(_epg, _stream, _epd, fullSnapshot) {
36
+ super(_epg, _stream);
37
+ this._epg = _epg;
38
+ this._stream = _stream;
39
+ this._epd = _epd;
40
+ this.fullSnapshot = fullSnapshot;
41
+ }
42
+ epg() {
43
+ return this._epg;
44
+ }
45
+ stream() {
46
+ return this._stream;
47
+ }
48
+ epd() {
49
+ return this._epd;
50
+ }
51
+ process() {
52
+ this._epd.readyToDispatch();
53
+ let mwList = this._epg.generateFull(this);
54
+ if (mwList != null) {
55
+ for (let i = 0; i < mwList.length; i++) {
56
+ let mw = mwList[i];
57
+ this._epd.submit(mw);
58
+ }
59
+ }
60
+ }
61
+ getFullSnapshot() {
62
+ return this.fullSnapshot;
63
+ }
64
+ setFullSnapshot(fullSnapshot) {
65
+ this.fullSnapshot = fullSnapshot;
66
+ }
67
+ }
68
+ exports.FullSnapshotWrapper = FullSnapshotWrapper;
69
+ class PartialSnapshotWrapper extends WrapperImpl {
70
+ constructor(_delta, _epg, _stream) {
71
+ super(_epg, _stream);
72
+ this._delta = _delta;
73
+ this._epg = _epg;
74
+ this._stream = _stream;
75
+ }
76
+ epg() {
77
+ return this._epg;
78
+ }
79
+ stream() {
80
+ return this._stream;
81
+ }
82
+ delta() {
83
+ return this._delta;
84
+ }
85
+ process() {
86
+ //console.log("the partial snapshot"+JSON.stringify(this.epg.getEPDs(this.stream))+"out going length: "+this.epg.generatePartial(this).length);
87
+ let outgoingList = this._epg.generatePartial(this);
88
+ let epds = this._epg.getEPDs(this._stream);
89
+ for (let i = 0; i < epds.length; i++) {
90
+ let epd = epds[i];
91
+ for (let j = 0; j < outgoingList.length; j++) {
92
+ if (epd.isReadyToDispatch()) {
93
+ let out = outgoingList[j];
94
+ epd.submit(out);
95
+ }
96
+ }
97
+ }
98
+ }
99
+ }
100
+ exports.PartialSnapshotWrapper = PartialSnapshotWrapper;
101
+ class IndicatorWrapper extends WrapperImpl {
102
+ constructor(_delta, _epg, _stream) {
103
+ super(_epg, _stream);
104
+ this._delta = _delta;
105
+ this._epg = _epg;
106
+ this._stream = _stream;
107
+ }
108
+ process() {
109
+ let epds = this._epg.getEPDs(this._stream);
110
+ for (let i = 0; i < epds.length; i++) {
111
+ let epd = epds[i];
112
+ epd.submit(this._delta);
113
+ }
114
+ }
115
+ }
116
+ exports.IndicatorWrapper = IndicatorWrapper;
117
+ class EPDispatcherException extends Error {
118
+ constructor(message) {
119
+ super(message);
120
+ }
121
+ }
122
+ exports.EPDispatcherException = EPDispatcherException;
123
+ let EndPointGroupManager = class EndPointGroupManager {
124
+ constructor(_fsRepo, _grp) {
125
+ this._fsRepo = _fsRepo;
126
+ this._grp = _grp;
127
+ this.relayEPG = new RelayEPG(_grp);
128
+ this.relayEPG.startGetingDeltaSnapshot(_fsRepo);
129
+ }
130
+ fsRepo() {
131
+ return this._fsRepo;
132
+ }
133
+ grp() {
134
+ return this._grp;
135
+ }
136
+ pushFullSnapshotWrapper(epg, epd) {
137
+ console.log("FULL SNAPSHOT: " + epd);
138
+ let stream = epd.stream();
139
+ epd.isInitialized().then((ready) => {
140
+ if (ready) {
141
+ let rawSnapshot = this._fsRepo.getSnapshot(stream);
142
+ let sw = new FullSnapshotWrapper(epg, stream, epd, rawSnapshot);
143
+ epg.submitForProcess(sw);
144
+ }
145
+ });
146
+ }
147
+ registerEPD(epd) {
148
+ if (this.relayEPG.hasEPD(epd.stream(), epd.id())) {
149
+ throw new EPDispatcherException("EPD already exists in a group.Id: " + epd.id + " Stream: " + epd.stream);
150
+ }
151
+ this.relayEPG.addEPD(epd);
152
+ this.pushFullSnapshotWrapper(this.relayEPG, epd);
153
+ }
154
+ deregisterEPD(epd) {
155
+ // Clean up EPD
156
+ this.relayEPG.removeEPD(epd);
157
+ }
158
+ };
159
+ EndPointGroupManager = __decorate([
160
+ (0, injection_js_1.Injectable)(),
161
+ __param(0, (0, injection_js_1.Inject)(core_1.FSREPO_IMPL)),
162
+ __metadata("design:paramtypes", [Object, message_class_1.SportsFeedMessageGroup])
163
+ ], EndPointGroupManager);
164
+ exports.EndPointGroupManager = EndPointGroupManager;
165
+ class DispatchersGroup {
166
+ constructor(streamName) {
167
+ this.streamName = streamName;
168
+ this.dispatchers = {};
169
+ }
170
+ addEpd(epd) {
171
+ this.dispatchers[epd.id()] = epd;
172
+ }
173
+ removeEpd(epd) {
174
+ let current = this.dispatchers[epd.id()];
175
+ delete this.dispatchers[epd.id()];
176
+ return current;
177
+ }
178
+ get(id) {
179
+ return this.dispatchers[id];
180
+ }
181
+ getAll() {
182
+ return Object.keys(this.dispatchers).map((k) => {
183
+ return this.dispatchers[k];
184
+ });
185
+ }
186
+ isEmpty() {
187
+ return Object.keys(this.dispatchers).length == 0;
188
+ }
189
+ }
190
+ exports.DispatchersGroup = DispatchersGroup;
191
+ class AbstractEPG {
192
+ constructor(sportsFeedGroup) {
193
+ this.sportsFeedGroup = sportsFeedGroup;
194
+ this.dispatchers = {};
195
+ }
196
+ hasEPD(stream, id) {
197
+ let dGrp = this.dispatchers[stream];
198
+ if (dGrp !== undefined) {
199
+ return dGrp.get(id) !== undefined;
200
+ }
201
+ else {
202
+ return false;
203
+ }
204
+ }
205
+ addEPD(epd) {
206
+ let grp = this.dispatchers[epd.stream()];
207
+ if (grp === undefined) {
208
+ this.dispatchers[epd.stream()] = new DispatchersGroup(epd.stream());
209
+ }
210
+ this.dispatchers[epd.stream()].addEpd(epd);
211
+ }
212
+ removeEPD(epd) {
213
+ let grp = this.dispatchers[epd.stream()];
214
+ if (grp !== undefined) {
215
+ grp.removeEpd(epd);
216
+ if (grp.isEmpty()) {
217
+ delete this.dispatchers[epd.stream()];
218
+ }
219
+ }
220
+ }
221
+ isEmpty() {
222
+ return Object.keys(this.dispatchers).length == 0;
223
+ }
224
+ getEPDs(stream) {
225
+ let dGrp = this.dispatchers[stream];
226
+ if (dGrp !== undefined) {
227
+ return dGrp.getAll();
228
+ }
229
+ else {
230
+ return [];
231
+ }
232
+ }
233
+ getStreams() {
234
+ return Object.keys(this.dispatchers);
235
+ }
236
+ startGetingDeltaSnapshot(fsRepo) {
237
+ fsRepo.registerSnapshotHandler(this);
238
+ }
239
+ stopGetingDeltaSnapshot(fsRepo) {
240
+ fsRepo.deRegisterSnapshotHandler(this);
241
+ }
242
+ process(stream, snapshot) {
243
+ if (this.sportsFeedGroup.isIndicatorMessage(snapshot.msgType())) {
244
+ let filterIndicatorWrapper = new IndicatorWrapper(snapshot, this, stream);
245
+ this.submitForProcess(filterIndicatorWrapper);
246
+ }
247
+ else {
248
+ let partWrapper = new PartialSnapshotWrapper(snapshot, this, stream);
249
+ this.submitForProcess(partWrapper);
250
+ }
251
+ }
252
+ getSportsFeedGrp() {
253
+ return this.sportsFeedGroup;
254
+ }
255
+ generateFull(wrapper) {
256
+ throw new Error("Method not implemented.");
257
+ }
258
+ generatePartial(wrapper) {
259
+ throw new Error("Method not implemented.");
260
+ }
261
+ }
262
+ exports.AbstractEPG = AbstractEPG;
263
+ let RelayEPG = class RelayEPG extends AbstractEPG {
264
+ constructor(_sportsFeedGroup) {
265
+ super(_sportsFeedGroup);
266
+ this._sportsFeedGroup = _sportsFeedGroup;
267
+ }
268
+ submitForProcess(wrapper) {
269
+ wrapper.process();
270
+ }
271
+ onException(e) {
272
+ console.error("Exception when dispatching snapshots to EPDs from RelayEPG. ", e);
273
+ return null;
274
+ }
275
+ generateFull(wrapper) {
276
+ let ss = wrapper.getFullSnapshot();
277
+ let fssStart = new data_structure_1.OutgoingImpl(this._sportsFeedGroup.FULLSNAPSHOT_START(), new Object());
278
+ let reset = new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_RESET(), ss, ss, data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT);
279
+ let insertMatch = new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_MATCH(), ss, ss, data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT);
280
+ let insertEvent = new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_EVENT(), ss, ss, data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT);
281
+ let insertRecord = new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_ODD(), ss, ss, data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT);
282
+ let fssEnd = new data_structure_1.OutgoingImpl(this._sportsFeedGroup.FULLSNAPSHOT_END(), new Object());
283
+ return [fssStart, reset, insertMatch, insertEvent, insertRecord, fssEnd];
284
+ }
285
+ generatePartial(wrapper) {
286
+ let delta = wrapper.delta();
287
+ if (delta.constructor.name == "TTLOutgoing") {
288
+ return this.generateTtl(delta);
289
+ }
290
+ return [delta];
291
+ }
292
+ generateTtl(outGng) {
293
+ // Return if Message Type is Refresh
294
+ if (this.isSameFormat(outGng.msgType(), this._sportsFeedGroup.ADMIN_REFRESH())) {
295
+ return [];
296
+ }
297
+ let ttlType = outGng.getTtlType();
298
+ if (ttlType == core_1.TTLType.REMOVE) {
299
+ // Process Remove Message as Normal Partial Message
300
+ return [outGng];
301
+ }
302
+ else {
303
+ return this.generateTtlRestore(outGng);
304
+ }
305
+ }
306
+ generateTtlRestore(outGng) {
307
+ let insertMatch = new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_MATCH(), outGng.delta(), outGng.delta(), data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT);
308
+ let insertEvent = new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_EVENT(), outGng.delta(), outGng.delta(), data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT);
309
+ let insertRecord = new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_ODD(), outGng.delta(), outGng.delta(), data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT);
310
+ return [insertMatch, insertEvent, insertRecord];
311
+ }
312
+ isSameFormat(lhs, messageClass) {
313
+ if (lhs.instanceClass() == messageClass.instanceClass() && lhs.constructor.name == messageClass.constructor.name) {
314
+ return true;
315
+ }
316
+ else {
317
+ return false;
318
+ }
319
+ }
320
+ };
321
+ RelayEPG = __decorate([
322
+ (0, injection_js_1.Injectable)(),
323
+ __metadata("design:paramtypes", [message_class_1.SportsFeedMessageGroup])
324
+ ], RelayEPG);
325
+ exports.RelayEPG = RelayEPG;
package/lib/index.js CHANGED
@@ -1 +1,27 @@
1
- "use strict";function __export(e){for(var r in e)exports.hasOwnProperty(r)||(exports[r]=e[r])}Object.defineProperty(exports,"__esModule",{value:!0}),__export(require("./basketball_codec")),__export(require("./client")),__export(require("./codec")),__export(require("./core")),__export(require("./data_structure")),__export(require("./dispatch")),__export(require("./message_class")),__export(require("./module")),__export(require("./receive")),__export(require("./soccer_codec")),__export(require("./tennis_codec"));
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./basketball_codec"), exports);
18
+ __exportStar(require("./client"), exports);
19
+ __exportStar(require("./codec"), exports);
20
+ __exportStar(require("./core"), exports);
21
+ __exportStar(require("./data_structure"), exports);
22
+ __exportStar(require("./dispatch"), exports);
23
+ __exportStar(require("./message_class"), exports);
24
+ __exportStar(require("./module"), exports);
25
+ __exportStar(require("./receive"), exports);
26
+ __exportStar(require("./soccer_codec"), exports);
27
+ __exportStar(require("./tennis_codec"), exports);