@jayesol/jayeson.lib.sports 2.2.7-beta3 → 2.2.7-beta5

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 @@
1
- var __createBinding=this&&this.__createBinding||(Object.create?function(e,a,t,r){void 0===r&&(r=t);var o=Object.getOwnPropertyDescriptor(a,t);o&&("get"in o?a.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return a[t]}}),Object.defineProperty(e,r,o)}:function(e,a,t,r){e[r=void 0===r?t:r]=a[t]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,a){Object.defineProperty(e,"default",{enumerable:!0,value:a})}:function(e,a){e.default=a}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var a={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&__createBinding(a,e,t);return __setModuleDefault(a,e),a};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BasketballCodec=void 0;let jayeson_lib_record_1=require("@jayesol/jayeson.lib.record"),proto=__importStar(require("./protobuf_bundle")),codec_1=require("./codec");class BasketballCodec{constructor(e=new codec_1.CodecHelper){this.codecHelper=e}decodeMatch(e,c,a,i){return e.map(e=>{var a=c[e.participants[0]],t=c[e.participants[1]],r=c[e.id],o=this.codecHelper.coerceInt64(e.startTime),l=c[e.league],s=c[e.country];let n=null,_={};null!=e.metaInfo&&(_=e.metaInfo);e=e.basketballMatch;if(e)switch(e.gender){case proto.BasketballMatch.Gender.MEN:n=jayeson_lib_record_1.BasketballGender.MEN;break;case proto.BasketballMatch.Gender.WOMEN:n=jayeson_lib_record_1.BasketballGender.WOMEN}return _=this.codecHelper.populatePKIntoMetaInfo(_,i),new jayeson_lib_record_1.BasketballMatchImpl(a,t,o,[],r,l,n,s,_)})}decodeEvent(e,s,n,_){let a=[],c={};for(var t in e.forEach(e=>{var a=s[e.id],t=e.metaInfo;let r=jayeson_lib_record_1.BasketballEventType.NONE;switch(e.eventType.basketballEventType){case proto.BasketballEvent.Type.NONE:r=jayeson_lib_record_1.BasketballEventType.NONE;break;case proto.BasketballEvent.Type.FIRST_TO_20:r=jayeson_lib_record_1.BasketballEventType.FIRST_TO_20;break;case proto.BasketballEvent.Type.LAST_BASKET:r=jayeson_lib_record_1.BasketballEventType.LAST_BASKET;break;case proto.BasketballEvent.Type.TEAM_POINTS:r=jayeson_lib_record_1.BasketballEventType.TEAM_POINTS;break;case proto.BasketballEvent.Type.THREE_POINTERS:r=jayeson_lib_record_1.BasketballEventType.THREE_POINTERS;break;case proto.BasketballEvent.Type.HOME_POINT:r=jayeson_lib_record_1.BasketballEventType.HOME_POINT;break;case proto.BasketballEvent.Type.AWAY_POINT:r=jayeson_lib_record_1.BasketballEventType.AWAY_POINT}var o=s[e.matchId],l=[],e=(null!=e.state&&l.push(this.decodeState(o,a,e.state,s,n,_)),new jayeson_lib_record_1.BasketballEventImpl(a,[],l,o,r,t));void 0===c[o]&&(c[o]=[]),c[o].push(e)}),c){t=new jayeson_lib_record_1.BasketballMatchImpl("","",0,c[t],t,"",jayeson_lib_record_1.BasketballGender.MEN,"",{});a.push(t)}return a}decodeRecord(e,B,a,t){var r,o=[];let E={};for(r in e.forEach(e=>{var a=this.codecHelper.coerceInt64(e.id),t=jayeson_lib_record_1.OddType[e.oddType.toString()],r=jayeson_lib_record_1.LBType[e.lbType.toString()];let o=null;var l=e.timeType.basketballTimeType;switch(proto.BasketballTimeType.SettleOn[l.settle.toString()]){case"FT":o=jayeson_lib_record_1.BasketballTimeType.FT;break;case"H1":o=jayeson_lib_record_1.BasketballTimeType.H1;break;case"H2":o=jayeson_lib_record_1.BasketballTimeType.H2;break;case"Q1":o=jayeson_lib_record_1.BasketballTimeType.Q1;break;case"Q2":o=jayeson_lib_record_1.BasketballTimeType.Q2;break;case"Q3":o=jayeson_lib_record_1.BasketballTimeType.Q3;break;case"Q4":o=jayeson_lib_record_1.BasketballTimeType.Q4}var l=B[e.source],s=jayeson_lib_record_1.OddFormat[e.format.toString()],n=e.metaInfo,_=e.pivotValue,c=jayeson_lib_record_1.PivotType[e.pivotType.toString()],i=jayeson_lib_record_1.PivotBias[e.pivotBias.toString()],b=e.basketballRecord;let d=!1;b&&(d=b.swapped);var b=this.codecHelper.formatRate(e.rates[0]),p=this.codecHelper.formatRate(e.rates[1]),y=this.codecHelper.formatRate(e.rates[2]),T=B[e.rateIds[0]],k=B[e.rateIds[1]],v=B[e.rateIds[2]],u=B[e.eventId],e=B[e.matchId],a=new jayeson_lib_record_1.BasketballRecord(e,u,a,t,r,o,l,s,n,b,p,y,_,c,i,T,k,v,d);void 0===E[e]&&(E[e]={}),void 0===E[e][u]&&(E[e][u]=[]),E[e][u].push(a)}),E){var l,s=E[r],n=[];for(l in s){var _=new jayeson_lib_record_1.BasketballEventImpl(l,s[l],[],r,jayeson_lib_record_1.BasketballEventType.NONE,{});n.push(_)}var c=new jayeson_lib_record_1.BasketballMatchImpl("","",0,n,r,"",jayeson_lib_record_1.BasketballGender.MEN,"",{});o.push(c)}return o}decodeState(e,a,t,r,o,l,s=Date.now()){var n=t.duration,_=t.basketballEventState,c=jayeson_lib_record_1.BasketballSegment[t.basketballEventState.segment.toString()],i=_.timeout,b=t.participantStats[0].scores,d=t.participantStats[1].scores;if(b.length<7)for(var p=b.length,y=0;p+y<7;y++)b.push(-1);if(d.length<7)for(var T=d.length,y=0;T+y<7;y++)d.push(-1);var t=new jayeson_lib_record_1.BasketballStats(b[0],b[1],b[2],b[3],b[4],b[5],b[6]),k=new jayeson_lib_record_1.BasketballStats(d[0],d[1],d[2],d[3],d[4],d[5],d[6]),_=_.bookPriority;return new jayeson_lib_record_1.BasketballEventState(t,k,n,l,e,a,s,c,i,_)}}exports.BasketballCodec=BasketballCodec;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BasketballCodec=void 0;var tslib_1=require("tslib"),jayeson_lib_record_1=require("@jayesol/jayeson.lib.record"),proto=tslib_1.__importStar(require("./protobuf_bundle")),codec_1=require("./codec"),BasketballCodec=function(){function e(e){void 0===e&&(e=new codec_1.CodecHelper),this.codecHelper=e}return e.prototype.decodeMatch=function(e,a,t,r){var o=this;return e.map(function(e){var t=a[e.participants[0]],l=a[e.participants[1]],s=a[e.id],n=o.codecHelper.coerceInt64(e.startTime),_=a[e.league],c=a[e.country],i=null,b={};null!=e.metaInfo&&(b=e.metaInfo);var d=e.basketballMatch;if(d)switch(d.gender){case proto.BasketballMatch.Gender.MEN:i=jayeson_lib_record_1.BasketballGender.MEN;break;case proto.BasketballMatch.Gender.WOMEN:i=jayeson_lib_record_1.BasketballGender.WOMEN}return b=o.codecHelper.populatePKIntoMetaInfo(b,r),new jayeson_lib_record_1.BasketballMatchImpl(t,l,n,[],s,_,i,c,b)})},e.prototype.decodeEvent=function(e,a,t,r){var o=this,l=[],s={};for(var n in e.forEach(function(e){var l=a[e.id],n=e.metaInfo,_=jayeson_lib_record_1.BasketballEventType.NONE;switch(e.eventType.basketballEventType){case proto.BasketballEvent.Type.NONE:_=jayeson_lib_record_1.BasketballEventType.NONE;break;case proto.BasketballEvent.Type.FIRST_TO_20:_=jayeson_lib_record_1.BasketballEventType.FIRST_TO_20;break;case proto.BasketballEvent.Type.LAST_BASKET:_=jayeson_lib_record_1.BasketballEventType.LAST_BASKET;break;case proto.BasketballEvent.Type.TEAM_POINTS:_=jayeson_lib_record_1.BasketballEventType.TEAM_POINTS;break;case proto.BasketballEvent.Type.THREE_POINTERS:_=jayeson_lib_record_1.BasketballEventType.THREE_POINTERS;break;case proto.BasketballEvent.Type.HOME_POINT:_=jayeson_lib_record_1.BasketballEventType.HOME_POINT;break;case proto.BasketballEvent.Type.AWAY_POINT:_=jayeson_lib_record_1.BasketballEventType.AWAY_POINT}var c=a[e.matchId],i=[];null!=e.state&&i.push(o.decodeState(c,l,e.state,a,t,r));var b=new jayeson_lib_record_1.BasketballEventImpl(l,[],i,c,_,n);void 0===s[c]&&(s[c]=[]),s[c].push(b)}),s){var _=new jayeson_lib_record_1.BasketballMatchImpl("","",0,s[n],n,"",jayeson_lib_record_1.BasketballGender.MEN,"",{});l.push(_)}return l},e.prototype.decodeRecord=function(e,a,t,r){var o=this,l=[],s={};for(var n in e.forEach(function(e){var t=o.codecHelper.coerceInt64(e.id),r=jayeson_lib_record_1.OddType[e.oddType.toString()],l=jayeson_lib_record_1.LBType[e.lbType.toString()],n=null,_=e.timeType.basketballTimeType;switch(proto.BasketballTimeType.SettleOn[_.settle.toString()]){case"FT":n=jayeson_lib_record_1.BasketballTimeType.FT;break;case"H1":n=jayeson_lib_record_1.BasketballTimeType.H1;break;case"H2":n=jayeson_lib_record_1.BasketballTimeType.H2;break;case"Q1":n=jayeson_lib_record_1.BasketballTimeType.Q1;break;case"Q2":n=jayeson_lib_record_1.BasketballTimeType.Q2;break;case"Q3":n=jayeson_lib_record_1.BasketballTimeType.Q3;break;case"Q4":n=jayeson_lib_record_1.BasketballTimeType.Q4}var c=a[e.source],i=jayeson_lib_record_1.OddFormat[e.format.toString()],b=e.metaInfo,d=e.pivotValue,p=jayeson_lib_record_1.PivotType[e.pivotType.toString()],y=jayeson_lib_record_1.PivotBias[e.pivotBias.toString()],T=e.basketballRecord,k=!1;T&&(k=T.swapped);var v=o.codecHelper.formatRate(e.rates[0]),B=o.codecHelper.formatRate(e.rates[1]),E=o.codecHelper.formatRate(e.rates[2]),u=a[e.rateIds[0]],j=a[e.rateIds[1]],m=a[e.rateIds[2]],f=a[e.eventId],h=a[e.matchId],I=new jayeson_lib_record_1.BasketballRecord(h,f,t,r,l,n,c,i,b,v,B,E,d,p,y,u,j,m,k);void 0===s[h]&&(s[h]={}),void 0===s[h][f]&&(s[h][f]=[]),s[h][f].push(I)}),s){var _=s[n],c=[];for(var i in _){var b=new jayeson_lib_record_1.BasketballEventImpl(i,_[i],[],n,jayeson_lib_record_1.BasketballEventType.NONE,{});c.push(b)}var d=new jayeson_lib_record_1.BasketballMatchImpl("","",0,c,n,"",jayeson_lib_record_1.BasketballGender.MEN,"",{});l.push(d)}return l},e.prototype.decodeState=function(e,a,t,r,o,l,s){void 0===s&&(s=Date.now());var n=t.duration,_=t.basketballEventState,c=jayeson_lib_record_1.BasketballSegment[t.basketballEventState.segment.toString()],i=_.timeout,b=t.participantStats[0].scores,d=t.participantStats[1].scores;if(b.length<7)for(var p=b.length,y=0;p+y<7;y++)b.push(-1);if(d.length<7){var T=d.length;for(y=0;T+y<7;y++)d.push(-1)}var k=new jayeson_lib_record_1.BasketballStats(b[0],b[1],b[2],b[3],b[4],b[5],b[6]),v=new jayeson_lib_record_1.BasketballStats(d[0],d[1],d[2],d[3],d[4],d[5],d[6]),B=_.bookPriority;return new jayeson_lib_record_1.BasketballEventState(k,v,n,l,e,a,s,c,i,B)},e}();exports.BasketballCodec=BasketballCodec;
package/lib/client.js CHANGED
@@ -1 +1 @@
1
- var MemoryDispatcher_1,__createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,i)}:function(e,t,r,s){e[s=void 0===s?r:s]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__decorate=this&&this.__decorate||function(e,t,r,s){var i,a=arguments.length,n=a<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,s);else for(var h=e.length-1;0<=h;h--)(i=e[h])&&(n=(a<3?i(n):3<a?i(t,r,n):i(t,r))||n);return 3<a&&n&&Object.defineProperty(t,r,n),n},__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__metadata=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},__param=this&&this.__param||function(r,s){return function(e,t){s(e,t,r)}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SportsFeedClient=exports.MemoryDispatcher=exports.AbstractComparableEPDispatcher=exports.FeedView=exports.Reset=exports.DeleteOdd=exports.UpdateOdd=exports.InsertOdd=exports.DeleteEvent=exports.UpdateEvent=exports.InsertEvent=exports.DeleteMatch=exports.UpdateMatch=exports.InsertMatch=void 0;let dispatch_1=require("./dispatch"),codec_1=require("./codec"),core_1=require("./core"),delivery=__importStar(require("@jayesol/jayeson.lib.delivery")),jayeson_lib_delivery_1=require("@jayesol/jayeson.lib.delivery"),Collections=__importStar(require("typescript-collections")),T=__importStar(require("ts-promise")),data_structure_1=require("./data_structure"),receive_1=require("./receive"),message_class_1=require("./message_class"),injection_js_1=(require("reflect-metadata"),require("injection-js"));class InsertMatch{constructor(e,t){this._after=e,this._get=t}after(){return this._after}get(){return this._get}}exports.InsertMatch=InsertMatch;class UpdateMatch{constructor(e,t){this._after=e,this._get=t}after(){return this._after}get(){return this._get}}exports.UpdateMatch=UpdateMatch;class DeleteMatch{constructor(e,t){this._after=e,this._get=t}after(){return this._after}get(){return this._get}}exports.DeleteMatch=DeleteMatch;class InsertEvent{constructor(e,t){this._after=e,this._get=t}after(){return this._after}get(){return this._get}}exports.InsertEvent=InsertEvent;class UpdateEvent{constructor(e,t){this._after=e,this._get=t}after(){return this._after}get(){return this._get}}exports.UpdateEvent=UpdateEvent;class DeleteEvent{constructor(e,t){this._after=e,this._get=t}after(){return this._after}get(){return this._get}}exports.DeleteEvent=DeleteEvent;class InsertOdd{constructor(e,t){this._after=e,this._get=t}after(){return this._after}get(){return this._get}}exports.InsertOdd=InsertOdd;class UpdateOdd{constructor(e,t){this._after=e,this._get=t}after(){return this._after}get(){return this._get}}exports.UpdateOdd=UpdateOdd;class DeleteOdd{constructor(e,t){this._after=e,this._get=t}after(){return this._after}get(){return this._get}}exports.DeleteOdd=DeleteOdd;class Reset{constructor(e,t){this._after=e,this._get=t}after(){return this._after}get(){return this._get}}exports.Reset=Reset;let FeedView=class{constructor(e,t,r){this._epgm=e,this._fsRepo=t,this._grp=r,this._handlers=[]}fsRepo(){return this._fsRepo}epgm(){return this._epgm}grp(){return this._grp}snapshot(){return this._fsRepo.getSnapshot("")}register(e){var t;this.hasHandler(e)?console.warn("Handler already registered."):(t=new MemoryDispatcher(this._fsRepo,this._grp,e),this._epgm.registerEPD(t),this._handlers.push(new HandlerDispatcherTuple(e,t)))}unregister(e){e=this.removeHandler(e);null!=e&&this._epgm.deregisterEPD(e)}hasHandler(t){return this._handlers.some(e=>e.handler===t)}removeHandler(t){var e,r=this._handlers.find(e=>e.handler===t);return void 0!==r?(e=this._handlers.indexOf(r),this._handlers.splice(e,1),r.dispatch):null}handlerSize(){return this._handlers.length}cleanUp(){var e;for(e of this._handlers.slice(0))this.unregister(e.handler)}};FeedView=__decorate([(0,injection_js_1.Injectable)(),__param(0,(0,injection_js_1.Inject)(dispatch_1.EPGM_IMPL)),__param(1,(0,injection_js_1.Inject)(core_1.FSREPO_IMPL)),__metadata("design:paramtypes",[Object,Object,message_class_1.SportsFeedMessageGroup])],FeedView),exports.FeedView=FeedView;class HandlerDispatcherTuple{constructor(e,t){this.handler=e,this.dispatch=t}}class AbstractComparableEPDispatcher{id(){throw new Error("Method not implemented.")}submit(e){throw new Error("Method not implemented.")}onException(e){throw new Error("Method not implemented.")}constructor(e,t){this._stream=e,this._grp=t}stream(){return this._stream}grp(){return this._grp}isInitialized(){return null}readyToDispatch(){this._readyToDispatch=!0}isReadyToDispatch(){return this._readyToDispatch}}exports.AbstractComparableEPDispatcher=AbstractComparableEPDispatcher;let MemoryDispatcher=MemoryDispatcher_1=class extends AbstractComparableEPDispatcher{constructor(e,t,r){super(MemoryDispatcher_1.MEMORY_STREAM,t),this._fsRepo=e,this.lastPushedSs=data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT,this._grp=t,this._handler=r,this._id=delivery.generateUUID()}grp(){return this._grp}handler(){return this._handler}id(){return this._id}submit(e){this.isInitialized().isFulfilled()&&this.isInitialized().value()&&this.handleMessage(e)}onException(e){console.error("Exception when dispatching outgoing messages to dispatchers:"+e)}handleMessage(e){var t;this.grp().isIndicatorMessage(e.msgType())?e.msgType()==this._grp.SWITCH_FILTER_START()?(t=Number(e.msg()),this.pushSwitchFilterStart(t)):e.msgType()==this._grp.SWITCH_FILTER_END()?this.pushSwitchFilterEnd():e.msgType()==this._grp.FULLSNAPSHOT_START()?this.pushFullSnapshotStart():e.msgType()==this._grp.FULLSNAPSHOT_END()?this.pushFullSnapshotEnd():e.msgType()==this._grp.SWITCH_FILTER_FAIL()?(t=Number(e.msg()),this.pushSwitchFilterFail(t)):e.msgType()==this._grp.TTL_RESTORE_START()?this.pushFullSnapshotStart():e.msgType()==this._grp.TTL_RESTORE_END()&&this.pushFullSnapshotEnd():this.isSame((t=e).msgType(),this._grp.DATA_INSERT_MATCH())?this.pushInsertMatch(t):this.isSame(t.msgType(),this._grp.DATA_INSERT_EVENT())?this.pushInsertEvent(t):this.isSame(t.msgType(),this._grp.DATA_INSERT_ODD())?this.pushInsertOdd(t):this.isSame(t.msgType(),this._grp.DATA_UPDATE_MATCH())?this.pushUpdateMatch(t):this.isSame(t.msgType(),this._grp.DATA_UPDATE_EVENT())?this.pushUpdateEvent(t):this.isSame(t.msgType(),this._grp.DATA_UPDATE_ODD())?this.pushUpdateOdd(t):this.isSame(t.msgType(),this._grp.DATA_DELETE_MATCH())?this.pushDeleteMatch(t):this.isSame(t.msgType(),this._grp.DATA_DELETE_EVENT())?this.pushDeleteEvent(t):this.isSame(t.msgType(),this._grp.DATA_DELETE_ODD())?this.pushDeleteOdd(t):this.isSame(t.msgType(),this._grp.DATA_RESET())&&this.pushReset(t)}pushSwitchFilterStart(e){this._handler.onSwitchFilterStart(e)}pushSwitchFilterEnd(){this._handler.onSwitchFilterEnd()}pushFullSnapshotStart(){this._handler.onFullSnapshotStart()}pushFullSnapshotEnd(){this._handler.onFullSnapshotEnd()}pushSwitchFilterFail(e){this._handler.onSwitchFilterFail(e)}pushInsertMatch(e){var t,r,s=[],i=[];for(t of e.delta().matches())(e.before().hasMatch(t.id())?i:s).push(t);0!=s.length&&(r=new InsertMatch(e.after(),s),this._handler.onInsertMatch(r)),0!=i.length&&(r=new UpdateMatch(e.after(),i),this._handler.onUpdateMatch(r))}pushInsertEvent(e){var t,r,s=[],i=[];for(t of this.events(e.delta().matches())){var a=e.before().match(t.matchId());(null!=a&&a.hasEvent(t.id())?i:s).push(t)}0!=s.length&&(r=new InsertEvent(e.after(),s),this._handler.onInsertEvent(r)),0<i.length&&(r=new UpdateEvent(e.after(),i),this._handler.onUpdateEvent(r))}pushInsertOdd(e){var t=this.records(this.events(e.delta().matches()));0<t.length&&(e=new InsertOdd(e.after(),t),this._handler.onInsertOdd(e))}pushUpdateMatch(e){var t=e.delta().matches();0<t.length&&(e=new UpdateMatch(e.after(),t),this._handler.onUpdateMatch(e))}pushUpdateEvent(e){var t=this.events(e.delta().matches());0<t.length&&(e=new UpdateEvent(e.after(),t),this._handler.onUpdateEvent(e))}pushUpdateOdd(e){var t=this.records(this.events(e.delta().matches()));0<t.length&&(e=new UpdateOdd(e.after(),t),this._handler.onUpdateOdd(e))}pushDeleteMatch(e){var t,r,s=[],i=[];for(t of e.delta().matches())(e.after().hasMatch(t.id())?s:i).push(t);0!=i.length&&(r=new DeleteMatch(e.after(),i),this._handler.onDeleteMatch(r)),0!=s.length&&(r=new UpdateMatch(e.after(),s),this._handler.onUpdateMatch(r))}pushDeleteEvent(e){var t,r,s=[],i=[];for(t of this.events(e.delta().matches())){var a=e.after().match(t.matchId());(null!=a&&a.hasEvent(t.id())?s:i).push(t)}0!=i.length&&(r=new DeleteEvent(e.after(),i),this._handler.onDeleteEvent(r)),0!=s.length&&(r=new UpdateEvent(e.after(),s),this._handler.onUpdateEvent(r))}pushDeleteOdd(e){var t=this.records(this.events(e.delta().matches()));0<t.length&&(e=new DeleteOdd(e.after(),t),this._handler.onDeleteOdd(e))}pushReset(e){var t=e.delta().getPartitions().toArray(),e=new Reset(e.after(),t);this._handler.onReset(e)}events(e){var t,r=[];for(t of e)for(var s of t.events())r.push(s);return r}records(e){var t,r=[];for(t of e)for(var s of t.records())r.push(s);return r}states(e){var t,r=[];for(t of e)for(var s of t.eventStates())r.push(s);return r}isSame(e,t){return e.id()==t.id()}isInitialized(){return this._fsRepo.isReady(this.stream())}},SportsFeedClient=(MemoryDispatcher.MEMORY_STREAM="MEMORY_AGGREGATED_STREAM",MemoryDispatcher=MemoryDispatcher_1=__decorate([(0,injection_js_1.Injectable)(),__metadata("design:paramtypes",[Object,message_class_1.SportsFeedMessageGroup,Object])],MemoryDispatcher),exports.MemoryDispatcher=MemoryDispatcher,class{constructor(e,t,r,s,i,a){this._subscriber=s,this._epgm=r,this._eventHandler=i,this.configureEventHandler(i),this._fsRepo=t,this._grp=e,this._views=new Set,this._viewTemplate=this.view(),this._viewTemplate.register(this);this.resolverMap=new Collections.Dictionary,this.filterRequestCounter=0,a.startTtlVerification()}subscriber(){return this._subscriber}epgm(){return this._epgm}InEndPointEventHandler(){return this._eventHandler}fsRepo(){return this._fsRepo}grp(){return this._grp}eventHandler(){return this._eventHandler}eventListener(e){var t,r;if(e instanceof jayeson_lib_delivery_1.Subscriber.Event.ConsumptionStart)for(t of e.streams)console.log("ConsumptionsStartEvent for streams "+t+" from "+e.endPoint);else if(e instanceof jayeson_lib_delivery_1.Subscriber.Event.ConsumptionError)for(r of e.streams)console.log("ConsumptionsStartEvent for streams "+r);else console.log("Received event "+e+" from "+e.endPoint)}configureEventHandler(e){this._subscriber.attachListener(e)}setUpStreamFilter(e){if(0===Object.keys(this._eventHandler.streamSources()).length){var t=new codec_1.FilterRequest(codec_1.FilterRequest.IGNORED_REQUEST_ID,e);this._eventHandler.updateFilter(t);let r=null;t=new T.Promise((e,t)=>{r=e});return r(!0),t}let r=this.filterRequestCounter++;t=new codec_1.FilterRequest(r,e),e=new T.Promise((e,t)=>{this.resolverMap.setValue(r,e)});return this._eventHandler.updateFilter(t),e}getSubscriber(){return this._subscriber}start(){this.getSubscriber().start()}view(){var e=new FeedView(this._epgm,this._fsRepo,this._grp);return this._views.add(e),e}removeView(e){this._views.has(e)&&(e.cleanUp(),this._views.delete(e))}onSwitchFilterFail(e){e!=codec_1.FilterRequest.IGNORED_REQUEST_ID&&this.resolverMap.remove(e)(!1)}onSwitchFilterStart(e){e!=codec_1.FilterRequest.IGNORED_REQUEST_ID&&this.resolverMap.remove(e)(!0)}onInsertMatch(e){}onUpdateMatch(e){}onDeleteMatch(e){}onInsertEvent(e){}onUpdateEvent(e){}onDeleteEvent(e){}onInsertOdd(e){}onUpdateOdd(e){}onDeleteOdd(e){}onReset(e){}onSwitchFilterEnd(){}onFullSnapshotStart(){}onFullSnapshotEnd(){}});SportsFeedClient=__decorate([(0,injection_js_1.Injectable)(),__param(1,(0,injection_js_1.Inject)(core_1.FSREPO_IMPL)),__param(2,(0,injection_js_1.Inject)(dispatch_1.EPGM_IMPL)),__metadata("design:paramtypes",[message_class_1.SportsFeedMessageGroup,Object,Object,jayeson_lib_delivery_1.Subscriber,receive_1.InEndPointEventHandler,receive_1.SportsFeedInProcessor])],SportsFeedClient),exports.SportsFeedClient=SportsFeedClient;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SportsFeedClient=exports.MemoryDispatcher=exports.AbstractComparableEPDispatcher=exports.FeedView=exports.Reset=exports.DeleteOdd=exports.UpdateOdd=exports.InsertOdd=exports.DeleteEvent=exports.UpdateEvent=exports.InsertEvent=exports.DeleteMatch=exports.UpdateMatch=exports.InsertMatch=void 0;var tslib_1=require("tslib"),dispatch_1=require("./dispatch"),codec_1=require("./codec"),core_1=require("./core"),delivery=tslib_1.__importStar(require("@jayesol/jayeson.lib.delivery")),jayeson_lib_delivery_1=require("@jayesol/jayeson.lib.delivery"),Collections=tslib_1.__importStar(require("typescript-collections")),T=tslib_1.__importStar(require("ts-promise")),data_structure_1=require("./data_structure"),receive_1=require("./receive"),message_class_1=require("./message_class");require("reflect-metadata");var injection_js_1=require("injection-js"),InsertMatch=function(){function t(t,e){this._after=t,this._get=e}return t.prototype.after=function(){return this._after},t.prototype.get=function(){return this._get},t}();exports.InsertMatch=InsertMatch;var UpdateMatch=function(){function t(t,e){this._after=t,this._get=e}return t.prototype.after=function(){return this._after},t.prototype.get=function(){return this._get},t}();exports.UpdateMatch=UpdateMatch;var DeleteMatch=function(){function t(t,e){this._after=t,this._get=e}return t.prototype.after=function(){return this._after},t.prototype.get=function(){return this._get},t}();exports.DeleteMatch=DeleteMatch;var InsertEvent=function(){function t(t,e){this._after=t,this._get=e}return t.prototype.after=function(){return this._after},t.prototype.get=function(){return this._get},t}();exports.InsertEvent=InsertEvent;var UpdateEvent=function(){function t(t,e){this._after=t,this._get=e}return t.prototype.after=function(){return this._after},t.prototype.get=function(){return this._get},t}();exports.UpdateEvent=UpdateEvent;var DeleteEvent=function(){function t(t,e){this._after=t,this._get=e}return t.prototype.after=function(){return this._after},t.prototype.get=function(){return this._get},t}();exports.DeleteEvent=DeleteEvent;var InsertOdd=function(){function t(t,e){this._after=t,this._get=e}return t.prototype.after=function(){return this._after},t.prototype.get=function(){return this._get},t}();exports.InsertOdd=InsertOdd;var UpdateOdd=function(){function t(t,e){this._after=t,this._get=e}return t.prototype.after=function(){return this._after},t.prototype.get=function(){return this._get},t}();exports.UpdateOdd=UpdateOdd;var DeleteOdd=function(){function t(t,e){this._after=t,this._get=e}return t.prototype.after=function(){return this._after},t.prototype.get=function(){return this._get},t}();exports.DeleteOdd=DeleteOdd;var Reset=function(){function t(t,e){this._after=t,this._get=e}return t.prototype.after=function(){return this._after},t.prototype.get=function(){return this._get},t}();exports.Reset=Reset;var FeedView=function(){function t(t,e,r){this._epgm=t,this._fsRepo=e,this._grp=r,this._handlers=[]}return t.prototype.fsRepo=function(){return this._fsRepo},t.prototype.epgm=function(){return this._epgm},t.prototype.grp=function(){return this._grp},t.prototype.snapshot=function(){return this._fsRepo.getSnapshot("")},t.prototype.register=function(t){if(this.hasHandler(t))console.warn("Handler already registered.");else{var e=new MemoryDispatcher(this._fsRepo,this._grp,t);this._epgm.registerEPD(e),this._handlers.push(new HandlerDispatcherTuple(t,e))}},t.prototype.unregister=function(t){var e=this.removeHandler(t);null!=e&&this._epgm.deregisterEPD(e)},t.prototype.hasHandler=function(t){return this._handlers.some(function(e){return e.handler===t})},t.prototype.removeHandler=function(t){var e=this._handlers.find(function(e){return e.handler===t});if(void 0!==e){var r=this._handlers.indexOf(e);return this._handlers.splice(r,1),e.dispatch}return null},t.prototype.handlerSize=function(){return this._handlers.length},t.prototype.cleanUp=function(){var t,e,r=this._handlers.slice(0);try{for(var n=tslib_1.__values(r),i=n.next();!i.done;i=n.next()){var s=i.value;this.unregister(s.handler)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}},t=tslib_1.__decorate([(0,injection_js_1.Injectable)(),tslib_1.__param(0,(0,injection_js_1.Inject)(dispatch_1.EPGM_IMPL)),tslib_1.__param(1,(0,injection_js_1.Inject)(core_1.FSREPO_IMPL)),tslib_1.__metadata("design:paramtypes",[Object,Object,message_class_1.SportsFeedMessageGroup])],t)}();exports.FeedView=FeedView;var HandlerDispatcherTuple=function(t,e){this.handler=t,this.dispatch=e},AbstractComparableEPDispatcher=function(){function t(t,e){this._stream=t,this._grp=e}return t.prototype.id=function(){throw new Error("Method not implemented.")},t.prototype.submit=function(t){throw new Error("Method not implemented.")},t.prototype.onException=function(t){throw new Error("Method not implemented.")},t.prototype.stream=function(){return this._stream},t.prototype.grp=function(){return this._grp},t.prototype.isInitialized=function(){return null},t.prototype.readyToDispatch=function(){this._readyToDispatch=!0},t.prototype.isReadyToDispatch=function(){return this._readyToDispatch},t}();exports.AbstractComparableEPDispatcher=AbstractComparableEPDispatcher;var MemoryDispatcher=function(t){function e(e,n,i){var s=t.call(this,r.MEMORY_STREAM,n)||this;return s._fsRepo=e,s.lastPushedSs=data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT,s._grp=n,s._handler=i,s._id=delivery.generateUUID(),s}var r;return tslib_1.__extends(e,t),r=e,e.prototype.grp=function(){return this._grp},e.prototype.handler=function(){return this._handler},e.prototype.id=function(){return this._id},e.prototype.submit=function(t){this.isInitialized().isFulfilled()&&this.isInitialized().value()&&this.handleMessage(t)},e.prototype.onException=function(t){console.error("Exception when dispatching outgoing messages to dispatchers:"+t)},e.prototype.handleMessage=function(t){if(this.grp().isIndicatorMessage(t.msgType()))if(t.msgType()==this._grp.SWITCH_FILTER_START()){var e=Number(t.msg());this.pushSwitchFilterStart(e)}else if(t.msgType()==this._grp.SWITCH_FILTER_END())this.pushSwitchFilterEnd();else if(t.msgType()==this._grp.FULLSNAPSHOT_START())this.pushFullSnapshotStart();else if(t.msgType()==this._grp.FULLSNAPSHOT_END())this.pushFullSnapshotEnd();else if(t.msgType()==this._grp.SWITCH_FILTER_FAIL()){e=Number(t.msg());this.pushSwitchFilterFail(e)}else t.msgType()==this._grp.TTL_RESTORE_START()?this.pushFullSnapshotStart():t.msgType()==this._grp.TTL_RESTORE_END()&&this.pushFullSnapshotEnd();else{var r=t;this.isSame(r.msgType(),this._grp.DATA_INSERT_MATCH())?this.pushInsertMatch(r):this.isSame(r.msgType(),this._grp.DATA_INSERT_EVENT())?this.pushInsertEvent(r):this.isSame(r.msgType(),this._grp.DATA_INSERT_ODD())?this.pushInsertOdd(r):this.isSame(r.msgType(),this._grp.DATA_UPDATE_MATCH())?this.pushUpdateMatch(r):this.isSame(r.msgType(),this._grp.DATA_UPDATE_EVENT())?this.pushUpdateEvent(r):this.isSame(r.msgType(),this._grp.DATA_UPDATE_ODD())?this.pushUpdateOdd(r):this.isSame(r.msgType(),this._grp.DATA_DELETE_MATCH())?this.pushDeleteMatch(r):this.isSame(r.msgType(),this._grp.DATA_DELETE_EVENT())?this.pushDeleteEvent(r):this.isSame(r.msgType(),this._grp.DATA_DELETE_ODD())?this.pushDeleteOdd(r):this.isSame(r.msgType(),this._grp.DATA_RESET())&&this.pushReset(r)}},e.prototype.pushSwitchFilterStart=function(t){this._handler.onSwitchFilterStart(t)},e.prototype.pushSwitchFilterEnd=function(){this._handler.onSwitchFilterEnd()},e.prototype.pushFullSnapshotStart=function(){this._handler.onFullSnapshotStart()},e.prototype.pushFullSnapshotEnd=function(){this._handler.onFullSnapshotEnd()},e.prototype.pushSwitchFilterFail=function(t){this._handler.onSwitchFilterFail(t)},e.prototype.pushInsertMatch=function(t){var e,r,n=[],i=[];try{for(var s=tslib_1.__values(t.delta().matches()),o=s.next();!o.done;o=s.next()){var a=o.value;t.before().hasMatch(a.id())?i.push(a):n.push(a)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}if(0!=n.length){var p=new InsertMatch(t.after(),n);this._handler.onInsertMatch(p)}if(0!=i.length){var h=new UpdateMatch(t.after(),i);this._handler.onUpdateMatch(h)}},e.prototype.pushInsertEvent=function(t){var e,r,n=[],i=[];try{for(var s=tslib_1.__values(this.events(t.delta().matches())),o=s.next();!o.done;o=s.next()){var a=o.value,p=t.before().match(a.matchId());null!=p&&p.hasEvent(a.id())?i.push(a):n.push(a)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}if(0!=n.length){var h=new InsertEvent(t.after(),n);this._handler.onInsertEvent(h)}if(i.length>0){var l=new UpdateEvent(t.after(),i);this._handler.onUpdateEvent(l)}},e.prototype.pushInsertOdd=function(t){var e=this.records(this.events(t.delta().matches()));if(e.length>0){var r=new InsertOdd(t.after(),e);this._handler.onInsertOdd(r)}},e.prototype.pushUpdateMatch=function(t){var e=t.delta().matches();if(e.length>0){var r=new UpdateMatch(t.after(),e);this._handler.onUpdateMatch(r)}},e.prototype.pushUpdateEvent=function(t){var e=this.events(t.delta().matches());if(e.length>0){var r=new UpdateEvent(t.after(),e);this._handler.onUpdateEvent(r)}},e.prototype.pushUpdateOdd=function(t){var e=this.records(this.events(t.delta().matches()));if(e.length>0){var r=new UpdateOdd(t.after(),e);this._handler.onUpdateOdd(r)}},e.prototype.pushDeleteMatch=function(t){var e,r,n=[],i=[];try{for(var s=tslib_1.__values(t.delta().matches()),o=s.next();!o.done;o=s.next()){var a=o.value;t.after().hasMatch(a.id())?n.push(a):i.push(a)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}if(0!=i.length){var p=new DeleteMatch(t.after(),i);this._handler.onDeleteMatch(p)}if(0!=n.length){var h=new UpdateMatch(t.after(),n);this._handler.onUpdateMatch(h)}},e.prototype.pushDeleteEvent=function(t){var e,r,n=[],i=[];try{for(var s=tslib_1.__values(this.events(t.delta().matches())),o=s.next();!o.done;o=s.next()){var a=o.value,p=t.after().match(a.matchId());null!=p&&p.hasEvent(a.id())?n.push(a):i.push(a)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}if(0!=i.length){var h=new DeleteEvent(t.after(),i);this._handler.onDeleteEvent(h)}if(0!=n.length){var l=new UpdateEvent(t.after(),n);this._handler.onUpdateEvent(l)}},e.prototype.pushDeleteOdd=function(t){var e=this.records(this.events(t.delta().matches()));if(e.length>0){var r=new DeleteOdd(t.after(),e);this._handler.onDeleteOdd(r)}},e.prototype.pushReset=function(t){var e=t.delta().getPartitions().toArray(),r=new Reset(t.after(),e);this._handler.onReset(r)},e.prototype.events=function(t){var e,r,n,i,s=[];try{for(var o=tslib_1.__values(t),a=o.next();!a.done;a=o.next()){var p=a.value;try{for(var h=(n=void 0,tslib_1.__values(p.events())),l=h.next();!l.done;l=h.next()){var u=l.value;s.push(u)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(i=h.return)&&i.call(h)}finally{if(n)throw n.error}}}}catch(t){e={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return s},e.prototype.records=function(t){var e,r,n,i,s=[];try{for(var o=tslib_1.__values(t),a=o.next();!a.done;a=o.next()){var p=a.value;try{for(var h=(n=void 0,tslib_1.__values(p.records())),l=h.next();!l.done;l=h.next()){var u=l.value;s.push(u)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(i=h.return)&&i.call(h)}finally{if(n)throw n.error}}}}catch(t){e={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return s},e.prototype.states=function(t){var e,r,n,i,s=[];try{for(var o=tslib_1.__values(t),a=o.next();!a.done;a=o.next()){var p=a.value;try{for(var h=(n=void 0,tslib_1.__values(p.eventStates())),l=h.next();!l.done;l=h.next()){var u=l.value;s.push(u)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(i=h.return)&&i.call(h)}finally{if(n)throw n.error}}}}catch(t){e={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return s},e.prototype.isSame=function(t,e){return t.id()==e.id()},e.prototype.isInitialized=function(){return this._fsRepo.isReady(this.stream())},e.MEMORY_STREAM="MEMORY_AGGREGATED_STREAM",e=r=tslib_1.__decorate([(0,injection_js_1.Injectable)(),tslib_1.__metadata("design:paramtypes",[Object,message_class_1.SportsFeedMessageGroup,Object])],e)}(AbstractComparableEPDispatcher);exports.MemoryDispatcher=MemoryDispatcher;var SportsFeedClient=function(){function t(t,e,r,n,i,s){this._subscriber=n,this._epgm=r,this._eventHandler=i,this.configureEventHandler(i),this._fsRepo=e,this._grp=t,this._views=new Set,this._viewTemplate=this.view(),this._viewTemplate.register(this);this.resolverMap=new Collections.Dictionary,this.filterRequestCounter=0,s.startTtlVerification()}return t.prototype.subscriber=function(){return this._subscriber},t.prototype.epgm=function(){return this._epgm},t.prototype.InEndPointEventHandler=function(){return this._eventHandler},t.prototype.fsRepo=function(){return this._fsRepo},t.prototype.grp=function(){return this._grp},t.prototype.eventHandler=function(){return this._eventHandler},t.prototype.eventListener=function(t){var e,r,n,i;if(t instanceof jayeson_lib_delivery_1.Subscriber.Event.ConsumptionStart){var s=t;try{for(var o=tslib_1.__values(s.streams),a=o.next();!a.done;a=o.next()){var p=a.value;console.log("ConsumptionsStartEvent for streams "+p+" from "+t.endPoint)}}catch(t){e={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}}else if(t instanceof jayeson_lib_delivery_1.Subscriber.Event.ConsumptionError){s=t;try{for(var h=tslib_1.__values(s.streams),l=h.next();!l.done;l=h.next()){p=l.value;console.log("ConsumptionsStartEvent for streams "+p)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(i=h.return)&&i.call(h)}finally{if(n)throw n.error}}}else console.log("Received event "+t+" from "+t.endPoint)},t.prototype.configureEventHandler=function(t){this._subscriber.attachListener(t)},t.prototype.setUpStreamFilter=function(t){var e=this;if(0===Object.keys(this._eventHandler.streamSources()).length){var r=new codec_1.FilterRequest(codec_1.FilterRequest.IGNORED_REQUEST_ID,t);this._eventHandler.updateFilter(r);var n=null,i=new T.Promise(function(t,e){n=t});return n(!0),i}var s=this.filterRequestCounter++,o=new codec_1.FilterRequest(s,t),a=new T.Promise(function(t,r){e.resolverMap.setValue(s,t)});return this._eventHandler.updateFilter(o),a},t.prototype.getSubscriber=function(){return this._subscriber},t.prototype.start=function(){this.getSubscriber().start()},t.prototype.view=function(){var t=new FeedView(this._epgm,this._fsRepo,this._grp);return this._views.add(t),t},t.prototype.removeView=function(t){this._views.has(t)&&(t.cleanUp(),this._views.delete(t))},t.prototype.onSwitchFilterFail=function(t){t!=codec_1.FilterRequest.IGNORED_REQUEST_ID&&this.resolverMap.remove(t)(!1)},t.prototype.onSwitchFilterStart=function(t){t!=codec_1.FilterRequest.IGNORED_REQUEST_ID&&this.resolverMap.remove(t)(!0)},t.prototype.onInsertMatch=function(t){},t.prototype.onUpdateMatch=function(t){},t.prototype.onDeleteMatch=function(t){},t.prototype.onInsertEvent=function(t){},t.prototype.onUpdateEvent=function(t){},t.prototype.onDeleteEvent=function(t){},t.prototype.onInsertOdd=function(t){},t.prototype.onUpdateOdd=function(t){},t.prototype.onDeleteOdd=function(t){},t.prototype.onReset=function(t){},t.prototype.onSwitchFilterEnd=function(){},t.prototype.onFullSnapshotStart=function(){},t.prototype.onFullSnapshotEnd=function(){},t=tslib_1.__decorate([(0,injection_js_1.Injectable)(),tslib_1.__param(1,(0,injection_js_1.Inject)(core_1.FSREPO_IMPL)),tslib_1.__param(2,(0,injection_js_1.Inject)(dispatch_1.EPGM_IMPL)),tslib_1.__metadata("design:paramtypes",[message_class_1.SportsFeedMessageGroup,Object,Object,jayeson_lib_delivery_1.Subscriber,receive_1.InEndPointEventHandler,receive_1.SportsFeedInProcessor])],t)}();exports.SportsFeedClient=SportsFeedClient;
package/lib/codec.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.Util=exports.FilterRequest=exports.CodecHelper=exports.EncodeAction=void 0;let mutable_1=require("./mutable");var EncodeAction;(e=>{e[e.INSERT=0]="INSERT",e[e.UPDATE=1]="UPDATE",e[e.DELETE=2]="DELETE"})(EncodeAction=exports.EncodeAction||(exports.EncodeAction={}));class CodecHelper{constructor(){}coerceInt64(e){return e.toNumber?e.toNumber():e}populatePKIntoMetaInfo(e,t){return e[mutable_1.Const.AGGREGATE_KEY]=t.toString(),e}formatRate(e){return Math.round(1e4*e)/1e4}}exports.CodecHelper=CodecHelper;class FilterRequest{constructor(e,t){this._requestId=e,this._ruleCombination=t}getRequestId(){return this._requestId}getFilterData(){return this._ruleCombination}toJSON(){return{requestId:this.getRequestId(),namespace:this._ruleCombination.namespace,filterRules:this._ruleCombination.filterRules}}}(exports.FilterRequest=FilterRequest).IGNORED_REQUEST_ID=-1;class Util{static addKey(e,t){if(-1!=t.search(Util.SEPARATOR))throw new TypeError("Incoming String cannot contain Separator: "+Util.SEPARATOR+" Incoming: "+t);return 0==e.length?t:-1===e.indexOf(t)?e+Util.SEPARATOR+t:e}static removeKey(e,t){var r,o=e.split(Util.SEPARATOR),e=t.split(Util.SEPARATOR);o.sort();for(r of e){var n=o.indexOf(r);if(!(n<0)&&(o.splice(n,1),0==o.length))return""}let i=o[0];for(let e=1;e<o.length;e++)i=Util.addKey(i,o[e]);return i}static containsKey(e,t){if(null==e)return!1;if(-1!=t.search(Util.SEPARATOR))throw new TypeError("Incoming String cannot contain Separator: "+Util.SEPARATOR+" Incoming: "+t);return!(e.split(Util.SEPARATOR).indexOf(t)<0)}}(exports.Util=Util).SEPARATOR=",";
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Util=exports.FilterRequest=exports.CodecHelper=exports.EncodeAction=void 0;var EncodeAction,tslib_1=require("tslib"),mutable_1=require("./mutable");!function(t){t[t.INSERT=0]="INSERT",t[t.UPDATE=1]="UPDATE",t[t.DELETE=2]="DELETE"}(EncodeAction=exports.EncodeAction||(exports.EncodeAction={}));var CodecHelper=function(){function t(){}return t.prototype.coerceInt64=function(t){return t.toNumber?t.toNumber():t},t.prototype.populatePKIntoMetaInfo=function(t,e){return t[mutable_1.Const.AGGREGATE_KEY]=e.toString(),t},t.prototype.formatRate=function(t){return Math.round(1e4*t)/1e4},t}();exports.CodecHelper=CodecHelper;var FilterRequest=function(){function t(t,e){this._requestId=t,this._ruleCombination=e}return t.prototype.getRequestId=function(){return this._requestId},t.prototype.getFilterData=function(){return this._ruleCombination},t.prototype.toJSON=function(){return{requestId:this.getRequestId(),namespace:this._ruleCombination.namespace,filterRules:this._ruleCombination.filterRules}},t.IGNORED_REQUEST_ID=-1,t}();exports.FilterRequest=FilterRequest;var Util=function(){function t(){}return t.addKey=function(e,r){if(-1!=r.search(t.SEPARATOR))throw new TypeError("Incoming String cannot contain Separator: "+t.SEPARATOR+" Incoming: "+r);return 0==e.length?r:-1===e.indexOf(r)?e+t.SEPARATOR+r:e},t.removeKey=function(e,r){var n,o,i=e.split(t.SEPARATOR),u=r.split(t.SEPARATOR);i.sort();try{for(var c=tslib_1.__values(u),l=c.next();!l.done;l=c.next()){var a=l.value,s=i.indexOf(a);if(!(s<0)&&(i.splice(s,1),0==i.length))return""}}catch(t){n={error:t}}finally{try{l&&!l.done&&(o=c.return)&&o.call(c)}finally{if(n)throw n.error}}for(var p=i[0],f=1;f<i.length;f++)p=t.addKey(p,i[f]);return p},t.containsKey=function(e,r){if(null==e)return!1;if(-1!=r.search(t.SEPARATOR))throw new TypeError("Incoming String cannot contain Separator: "+t.SEPARATOR+" Incoming: "+r);return!(e.split(t.SEPARATOR).indexOf(r)<0)},t.SEPARATOR=",",t}();exports.Util=Util;
package/lib/core.js CHANGED
@@ -1 +1 @@
1
- var FSRepoImpl_1,TTLType,__createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,i)}:function(e,t,r,s){e[s=void 0===s?r:s]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__decorate=this&&this.__decorate||function(e,t,r,s){var i,a=arguments.length,n=a<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,s);else for(var o=e.length-1;0<=o;o--)(i=e[o])&&(n=(a<3?i(n):3<a?i(t,r,n):i(t,r))||n);return 3<a&&n&&Object.defineProperty(t,r,n),n},__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__metadata=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},__param=this&&this.__param||function(r,s){return function(e,t){s(e,t,r)}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.RecycleBin=exports.TTLRemoveCheck=exports.TTLRestoreCheck=exports.TTLCheck=exports.TTLOutgoing=exports.TTLType=exports.TTLConfig=exports.Delta=exports.FSRepoImpl=exports.AbstractFSRepo=exports.FSREPO_IMPL=void 0;let data_structure_1=require("./data_structure"),Collections=__importStar(require("typescript-collections")),T=__importStar(require("ts-promise")),injection_js_1=(require("reflect-metadata"),require("injection-js")),jayeson_lib_record_1=require("@jayesol/jayeson.lib.record"),message_class_1=require("./message_class"),mutable_1=require("./mutable"),merge_1=require("./merge"),data_structure_2=require("./data_structure"),AbstractFSRepo=(exports.FSREPO_IMPL=new injection_js_1.InjectionToken("FSRepoInstance"),class{constructor(){this._handlers=new Collections.Set}handlers(){return this._handlers}appendSnapshot(e,t){throw new Error("appendSnapshot is not implemented")}getSnapshot(e){throw new Error("getSnapshot is not implemented")}registerSnapshotHandler(e){this.handlers().add(e)}deRegisterSnapshotHandler(e){this.handlers().remove(e)}getRegisteredHandlers(){return this.handlers().toArray()}push(e){throw new Error("push is not implemented")}isReady(e){return null}}),FSRepoImpl=(AbstractFSRepo=__decorate([(0,injection_js_1.Injectable)(),__metadata("design:paramtypes",[])],AbstractFSRepo),exports.AbstractFSRepo=AbstractFSRepo,FSRepoImpl_1=class extends AbstractFSRepo{constructor(e,t){super(),this.outputStreamName=e,this.sportsGroup=t,this._head=null;let r=this;this.fssEndReceived=new T.Promise((e,t)=>{r.promiseResolver=e,r.promiseRejector=t})}head(){return this._head}appendSnapshot(e,t){return null==this._head?this.result=t.apply(null):this.result=t.apply(this._head),this._head=this.result.getAfter(),this.result.getDeltaOut()}getSnapshot(e=0){return null==this._head?data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT:this._head}getTtlRemoveSnapshot(){return null==this._head?[]:[new TTLRemoveCheck(null,this._head.getPartitions().toArray(),this.outputStreamName)]}push(r){if(r.msgType()!=this.sportsGroup.FULLSNAPSHOT_START())if(r.msgType()==this.sportsGroup.FULLSNAPSHOT_END())this.promiseResolver(!0);else{let t=this;this._handlers.forEach(function(e){e.process(t.outputStreamName,r)})}}isReady(e){return this.fssEndReceived}});FSRepoImpl.outputStream=new injection_js_1.InjectionToken("aggregatedStreamName"),FSRepoImpl=FSRepoImpl_1=__decorate([(0,injection_js_1.Injectable)(),__param(0,(0,injection_js_1.Inject)(FSRepoImpl_1.outputStream)),__metadata("design:paramtypes",[String,message_class_1.SportsFeedMessageGroup])],FSRepoImpl),exports.FSRepoImpl=FSRepoImpl;class Delta{constructor(e,t,r){this._incoming=e,this._after=t,this._before=r}incoming(){return this._incoming}msgType(){return this._incoming.msgType()}after(){return this._after}delta(){return this._incoming.data()}before(){return this._before}}exports.Delta=Delta;let TTLConfig=class{constructor(){this.livettl=18e4,this.todayttl=18e4,this.earlyttl=18e4,this.enableTtl=!0}getLivettl(){return this.livettl}setLivettl(e){this.livettl=e}getTodayttl(){return this.todayttl}setTodayttl(e){this.todayttl=e}getEarlyttl(){return this.earlyttl}setEarlyttl(e){this.earlyttl=e}getRunInterval(){var e,t,r;return this.enableTtl?(r=this.getLivettl(),e=this.getTodayttl(),t=this.getEarlyttl(),(r=Math.min(r,e,t)/2)<1e3?1e4:r):-1}isEnableTtl(){return this.enableTtl}setEnableTtl(e){this.enableTtl=e}};TTLConfig=__decorate([(0,injection_js_1.Injectable)()],TTLConfig),exports.TTLConfig=TTLConfig,(e=>{e[e.REMOVE=0]="REMOVE",e[e.RESTORE=1]="RESTORE"})(TTLType=exports.TTLType||(exports.TTLType={}));class TTLOutgoing extends Delta{constructor(e,t,r,s){super(t,r,s),this.ttlType=e}getTtlType(){return this.ttlType}}exports.TTLOutgoing=TTLOutgoing;class TTLCheck{constructor(e,t,r,s){this.ttlType=e,this.recycleBin=t,this.keys=r,this.stream=s}getKeys(){return this.keys}getKeysMapping(){let t=new Collections.Dictionary;return this.keys.forEach(e=>{t.setValue(e,(new Date).getTime())}),t}getTtlType(){return this.ttlType}getRecycleBin(){return this.recycleBin}setRecycleBin(e){this.recycleBin=e}getStream(){return this.stream}}exports.TTLCheck=TTLCheck;class TTLRestoreCheck extends TTLCheck{constructor(e,t,r){super(TTLType.RESTORE,e,t,r)}apply(e){let s=e,i=!1,a=new Collections.Dictionary,n={},o=[];this.getKeys().forEach((e,t)=>{var r;this.getRecycleBin().containData(e)&&(i=!0,r=(new Date).getTime(),a.setValue(e,r),n=this.getRecycleBin().copyData(e,n),this.ttlRestoreWrapper=this.getRecycleBin().restoreData(new data_structure_2.TTLWrapper,s,e,r),s=this.ttlRestoreWrapper.getRemainingSs(),o.push(this.ttlRestoreWrapper.getRestoredSs()))});var t,r=[],l=new data_structure_2.MergeableWrapper;return l.setAfter(s),i?(console.log("restore -----\x3e"+JSON.stringify(a.keys())),merge_1.DeltaTransformingLogicImpl.transformTTLRestore(o,this.getRecycleBin().getGrp(),this.getStream(),e,s,n,a)):(t=new data_structure_1.Incoming(this.getRecycleBin().getGrp().ADMIN_REFRESH(),this.getStream(),new data_structure_1.IndexedSnapshotImpl(n,this.getKeysMapping())),r.push(new TTLOutgoing(this.getTtlType(),t,s,e)),l.setDeltaOut(r),l)}}exports.TTLRestoreCheck=TTLRestoreCheck;class TTLRemoveCheck extends TTLCheck{constructor(e,t,r){super(TTLType.REMOVE,e,t,r)}apply(e){var t=e.getPartitionMap(),r=new Collections.Dictionary;let s=e;var i,a=[],n=this.getRecycleBin().getTtlConfig();let o=!1;for(i of this.getKeys()){let e=0;if(t.containsKey(i)){switch(i.oddType()){case jayeson_lib_record_1.OddType.LIVE:e=t.getValue(i)+n.getLivettl();break;case jayeson_lib_record_1.OddType.TODAY:e=t.getValue(i)+n.getTodayttl();break;case jayeson_lib_record_1.OddType.EARLY:e=t.getValue(i)+n.getEarlyttl()}e<(new Date).getTime()&&(o=!0,r.setValue(i,t.getValue(i)),this.ttlRemoveWrapper=this.getRecycleBin().removeData(new data_structure_2.TTLWrapper,s,i),s=this.ttlRemoveWrapper.getRemainingSs(),a.push(this.ttlRemoveWrapper.getRemovedSs()))}}var l,p,c=[];return o?(console.log("reseting -----\x3e"+JSON.stringify(r.keys())),merge_1.DeltaTransformingLogicImpl.transformTTLRemove(a,this.getRecycleBin().getGrp(),this.getStream(),e,s,r)):(l=new data_structure_2.MergeableWrapper,p=new data_structure_1.Incoming(this.getRecycleBin().getGrp().ADMIN_REFRESH(),this.getStream(),new data_structure_1.IndexedSnapshotImpl({},this.getKeysMapping())),c.push(new TTLOutgoing(this.getTtlType(),p,s,e)),l.setDeltaOut(c),l.setAfter(s),l)}}exports.TTLRemoveCheck=TTLRemoveCheck;let RecycleBin=class{constructor(e,t,r){this.ttlConfig=e,this.grp=t,this.fsRepo=r,this.expiredMatches=new Collections.Dictionary,this.ttlStatus=new Collections.Set}removeData(e,t,r){var s,i;return t.getPartitions().contains(r)?(s=(i=mutable_1.BuilderProvider.getSnapshotBuilder(t)).reset(r).build(),i=i.build(),this.expiredMatches.setValue(r,s),e.setRemovedSs(s),e.setRemainingSs(i)):(e.setRemainingSs(t),e.setRemovedSs(null)),e}restoreData(e,t,r,s){var i,a=this.expiredMatches.getValue(r);return null==a?(e.setRemainingSs(t),e.setRestoredSs(null)):((new Collections.Dictionary).setValue(r,s),(i=mutable_1.BuilderProvider.getSnapshotBuilder(a)).markPartitionAsUpdated(r,s),a=i.build(),t=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_MATCH(),a,t).getAfterSs(),t=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_EVENT(),a,t).getAfterSs(),t=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_ODD(),a,t).getAfterSs(),e.setRestoredSs(a),e.setRemainingSs(t),this.expiredMatches.remove(r)),e}clearBin(e){this.expiredMatches.remove(e),this.ttlStatus.remove(e)}containData(e){return this.expiredMatches.containsKey(e)}getTtlConfig(){return this.ttlConfig}getFsRepo(){return this.fsRepo}getTtlRestoreSnapshot(s){let i=null;return this.ttlStatus.isEmpty()||(this.getGrp().DATA_RESET().id()==s.msgType().id()?s.data().getPartitions().forEach(e=>{console.log("Dropping partition "+e),this.expiredMatches.remove(e)}):s.data().getPartitionMap().forEach((e,t)=>{var r=[];this.ttlStatus.contains(e)&&(this.ttlStatus.remove(e),r.push(e)),0<r.length&&(i=new TTLRestoreCheck(this,r,s.stream()))})),i}getTtlRemoveSnapshot(){var e=this.getFsRepo().getTtlRemoveSnapshot();return e.forEach(e=>{e.setRecycleBin(this),e.getKeys().forEach(e=>{this.ttlStatus.add(e)})}),e}copyData(e,t){e=this.expiredMatches.getValue(e);return void 0===e?t:(t=new data_structure_1.IndexedSnapshotImpl(t),t=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_MATCH(),e,t).getAfterSs(),t=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_EVENT(),e,t).getAfterSs(),(t=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_ODD(),e,t).getAfterSs()).matchesSport)}getGrp(){return this.grp}};RecycleBin=__decorate([(0,injection_js_1.Injectable)(),__metadata("design:paramtypes",[TTLConfig,message_class_1.SportsFeedMessageGroup,AbstractFSRepo])],RecycleBin),exports.RecycleBin=RecycleBin;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RecycleBin=exports.TTLRemoveCheck=exports.TTLRestoreCheck=exports.TTLCheck=exports.TTLOutgoing=exports.TTLType=exports.TTLConfig=exports.Delta=exports.FSRepoImpl=exports.AbstractFSRepo=exports.FSREPO_IMPL=void 0;var tslib_1=require("tslib"),data_structure_1=require("./data_structure"),Collections=tslib_1.__importStar(require("typescript-collections")),T=tslib_1.__importStar(require("ts-promise"));require("reflect-metadata");var injection_js_1=require("injection-js"),jayeson_lib_record_1=require("@jayesol/jayeson.lib.record"),message_class_1=require("./message_class"),mutable_1=require("./mutable"),merge_1=require("./merge"),data_structure_2=require("./data_structure");exports.FSREPO_IMPL=new injection_js_1.InjectionToken("FSRepoInstance");var AbstractFSRepo=function(){function t(){this._handlers=new Collections.Set}return t.prototype.handlers=function(){return this._handlers},t.prototype.appendSnapshot=function(t,e){throw new Error("appendSnapshot is not implemented")},t.prototype.getSnapshot=function(t){throw new Error("getSnapshot is not implemented")},t.prototype.registerSnapshotHandler=function(t){this.handlers().add(t)},t.prototype.deRegisterSnapshotHandler=function(t){this.handlers().remove(t)},t.prototype.getRegisteredHandlers=function(){return this.handlers().toArray()},t.prototype.push=function(t){throw new Error("push is not implemented")},t.prototype.isReady=function(t){return null},t=tslib_1.__decorate([(0,injection_js_1.Injectable)(),tslib_1.__metadata("design:paramtypes",[])],t)}();exports.AbstractFSRepo=AbstractFSRepo;var FSRepoImpl=function(t){function e(e,r){var n=t.call(this)||this;n.outputStreamName=e,n.sportsGroup=r,n._head=null;var o=n;return n.fssEndReceived=new T.Promise(function(t,e){o.promiseResolver=t,o.promiseRejector=e}),n}var r;return tslib_1.__extends(e,t),r=e,e.prototype.head=function(){return this._head},e.prototype.appendSnapshot=function(t,e){return null==this._head?(this.result=e.apply(null),this._head=this.result.getAfter()):(this.result=e.apply(this._head),this._head=this.result.getAfter()),this.result.getDeltaOut()},e.prototype.getSnapshot=function(t){return void 0===t&&(t=""),null==this._head?data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT:this._head},e.prototype.getTtlRemoveSnapshot=function(){return null==this._head?[]:[new TTLRemoveCheck(null,this._head.getPartitions().toArray(),this.outputStreamName)]},e.prototype.push=function(t){if(t.msgType()==this.sportsGroup.FULLSNAPSHOT_START());else if(t.msgType()==this.sportsGroup.FULLSNAPSHOT_END())this.promiseResolver(!0);else{var e=this;this._handlers.forEach(function(r){r.process(e.outputStreamName,t)})}},e.prototype.isReady=function(t){return this.fssEndReceived},e.outputStream=new injection_js_1.InjectionToken("aggregatedStreamName"),e=r=tslib_1.__decorate([(0,injection_js_1.Injectable)(),tslib_1.__param(0,(0,injection_js_1.Inject)(r.outputStream)),tslib_1.__metadata("design:paramtypes",[String,message_class_1.SportsFeedMessageGroup])],e)}(AbstractFSRepo);exports.FSRepoImpl=FSRepoImpl;var Delta=function(){function t(t,e,r){this._incoming=t,this._after=e,this._before=r}return t.prototype.incoming=function(){return this._incoming},t.prototype.msgType=function(){return this._incoming.msgType()},t.prototype.after=function(){return this._after},t.prototype.delta=function(){return this._incoming.data()},t.prototype.before=function(){return this._before},t}();exports.Delta=Delta;var TTLType,TTLConfig=function(){function t(){this.livettl=18e4,this.todayttl=18e4,this.earlyttl=18e4,this.enableTtl=!0}return t.prototype.getLivettl=function(){return this.livettl},t.prototype.setLivettl=function(t){this.livettl=t},t.prototype.getTodayttl=function(){return this.todayttl},t.prototype.setTodayttl=function(t){this.todayttl=t},t.prototype.getEarlyttl=function(){return this.earlyttl},t.prototype.setEarlyttl=function(t){this.earlyttl=t},t.prototype.getRunInterval=function(){if(!this.enableTtl)return-1;var t=this.getLivettl(),e=this.getTodayttl(),r=this.getEarlyttl(),n=Math.min(t,e,r)/2;return n<1e3?1e4:n},t.prototype.isEnableTtl=function(){return this.enableTtl},t.prototype.setEnableTtl=function(t){this.enableTtl=t},t=tslib_1.__decorate([(0,injection_js_1.Injectable)()],t)}();exports.TTLConfig=TTLConfig,function(t){t[t.REMOVE=0]="REMOVE",t[t.RESTORE=1]="RESTORE"}(TTLType=exports.TTLType||(exports.TTLType={}));var TTLOutgoing=function(t){function e(e,r,n,o){var s=t.call(this,r,n,o)||this;return s.ttlType=e,s}return tslib_1.__extends(e,t),e.prototype.getTtlType=function(){return this.ttlType},e}(Delta);exports.TTLOutgoing=TTLOutgoing;var TTLCheck=function(){function t(t,e,r,n){this.ttlType=t,this.recycleBin=e,this.keys=r,this.stream=n}return t.prototype.getKeys=function(){return this.keys},t.prototype.getKeysMapping=function(){var t=new Collections.Dictionary;return this.keys.forEach(function(e){t.setValue(e,(new Date).getTime())}),t},t.prototype.getTtlType=function(){return this.ttlType},t.prototype.getRecycleBin=function(){return this.recycleBin},t.prototype.setRecycleBin=function(t){this.recycleBin=t},t.prototype.getStream=function(){return this.stream},t}();exports.TTLCheck=TTLCheck;var TTLRestoreCheck=function(t){function e(e,r,n){return t.call(this,TTLType.RESTORE,e,r,n)||this}return tslib_1.__extends(e,t),e.prototype.apply=function(t){var e=this,r=t,n=!1,o=new Collections.Dictionary,s={},i=[];this.getKeys().forEach(function(t,a){if(e.getRecycleBin().containData(t)){n=!0;var p=(new Date).getTime();o.setValue(t,p),s=e.getRecycleBin().copyData(t,s),e.ttlRestoreWrapper=e.getRecycleBin().restoreData(new data_structure_2.TTLWrapper,r,t,p),r=e.ttlRestoreWrapper.getRemainingSs(),i.push(e.ttlRestoreWrapper.getRestoredSs())}});var a=[],p=new data_structure_2.MergeableWrapper;if(p.setAfter(r),n)return console.log("restore -----\x3e"+JSON.stringify(o.keys())),merge_1.DeltaTransformingLogicImpl.transformTTLRestore(i,this.getRecycleBin().getGrp(),this.getStream(),t,r,s,o);var l=new data_structure_1.Incoming(this.getRecycleBin().getGrp().ADMIN_REFRESH(),this.getStream(),new data_structure_1.IndexedSnapshotImpl(s,this.getKeysMapping()));return a.push(new TTLOutgoing(this.getTtlType(),l,r,t)),p.setDeltaOut(a),p},e}(TTLCheck);exports.TTLRestoreCheck=TTLRestoreCheck;var TTLRemoveCheck=function(t){function e(e,r,n){return t.call(this,TTLType.REMOVE,e,r,n)||this}return tslib_1.__extends(e,t),e.prototype.apply=function(t){var e,r,n=t.getPartitionMap(),o=new Collections.Dictionary,s=t,i=[],a=this.getRecycleBin().getTtlConfig(),p=!1;try{for(var l=tslib_1.__values(this.getKeys()),c=l.next();!c.done;c=l.next()){var u=c.value,h=0;if(n.containsKey(u)){switch(u.oddType()){case jayeson_lib_record_1.OddType.LIVE:h=n.getValue(u)+a.getLivettl();break;case jayeson_lib_record_1.OddType.TODAY:h=n.getValue(u)+a.getTodayttl();break;case jayeson_lib_record_1.OddType.EARLY:h=n.getValue(u)+a.getEarlyttl()}h<(new Date).getTime()&&(p=!0,o.setValue(u,n.getValue(u)),this.ttlRemoveWrapper=this.getRecycleBin().removeData(new data_structure_2.TTLWrapper,s,u),s=this.ttlRemoveWrapper.getRemainingSs(),i.push(this.ttlRemoveWrapper.getRemovedSs()))}}}catch(t){e={error:t}}finally{try{c&&!c.done&&(r=l.return)&&r.call(l)}finally{if(e)throw e.error}}var g=[];if(p)return console.log("reseting -----\x3e"+JSON.stringify(o.keys())),merge_1.DeltaTransformingLogicImpl.transformTTLRemove(i,this.getRecycleBin().getGrp(),this.getStream(),t,s,o);var _=new data_structure_2.MergeableWrapper,T=new data_structure_1.Incoming(this.getRecycleBin().getGrp().ADMIN_REFRESH(),this.getStream(),new data_structure_1.IndexedSnapshotImpl({},this.getKeysMapping()));return g.push(new TTLOutgoing(this.getTtlType(),T,s,t)),_.setDeltaOut(g),_.setAfter(s),_},e}(TTLCheck);exports.TTLRemoveCheck=TTLRemoveCheck;var RecycleBin=function(){function t(t,e,r){this.ttlConfig=t,this.grp=e,this.fsRepo=r,this.expiredMatches=new Collections.Dictionary,this.ttlStatus=new Collections.Set}return t.prototype.removeData=function(t,e,r){if(!e.getPartitions().contains(r))return t.setRemainingSs(e),t.setRemovedSs(null),t;var n=mutable_1.BuilderProvider.getSnapshotBuilder(e),o=n.reset(r).build(),s=n.build();return this.expiredMatches.setValue(r,o),t.setRemovedSs(o),t.setRemainingSs(s),t},t.prototype.restoreData=function(t,e,r,n){var o=this.expiredMatches.getValue(r);if(null==o)return t.setRemainingSs(e),t.setRestoredSs(null),t;(new Collections.Dictionary).setValue(r,n);var s=mutable_1.BuilderProvider.getSnapshotBuilder(o);return s.markPartitionAsUpdated(r,n),o=s.build(),e=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_MATCH(),o,e).getAfterSs(),e=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_EVENT(),o,e).getAfterSs(),e=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_ODD(),o,e).getAfterSs(),t.setRestoredSs(o),t.setRemainingSs(e),this.expiredMatches.remove(r),t},t.prototype.clearBin=function(t){this.expiredMatches.remove(t),this.ttlStatus.remove(t)},t.prototype.containData=function(t){return this.expiredMatches.containsKey(t)},t.prototype.getTtlConfig=function(){return this.ttlConfig},t.prototype.getFsRepo=function(){return this.fsRepo},t.prototype.getTtlRestoreSnapshot=function(t){var e=this,r=null;return this.ttlStatus.isEmpty()||(this.getGrp().DATA_RESET().id()==t.msgType().id()?t.data().getPartitions().forEach(function(t){console.log("Dropping partition "+t),e.expiredMatches.remove(t)}):t.data().getPartitionMap().forEach(function(n,o){var s=[];e.ttlStatus.contains(n)&&(e.ttlStatus.remove(n),s.push(n)),s.length>0&&(r=new TTLRestoreCheck(e,s,t.stream()))})),r},t.prototype.getTtlRemoveSnapshot=function(){var t=this,e=this.getFsRepo().getTtlRemoveSnapshot();return e.forEach(function(e){e.setRecycleBin(t),e.getKeys().forEach(function(e){t.ttlStatus.add(e)})}),e},t.prototype.copyData=function(t,e){var r=this.expiredMatches.getValue(t);if(void 0===r)return e;var n=new data_structure_1.IndexedSnapshotImpl(e);return n=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_MATCH(),r,n).getAfterSs(),n=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_EVENT(),r,n).getAfterSs(),(n=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_ODD(),r,n).getAfterSs()).matchesSport},t.prototype.getGrp=function(){return this.grp},t=tslib_1.__decorate([(0,injection_js_1.Injectable)(),tslib_1.__metadata("design:paramtypes",[TTLConfig,message_class_1.SportsFeedMessageGroup,AbstractFSRepo])],t)}();exports.RecycleBin=RecycleBin;
@@ -1 +1 @@
1
- var ConvertedMsg,__createBinding=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var n=Object.getOwnPropertyDescriptor(t,s);n&&("get"in n?t.__esModule:!n.writable&&!n.configurable)||(n={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,n)}:function(e,t,s,r){e[r=void 0===r?s:r]=t[s]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s in e)"default"!==s&&Object.prototype.hasOwnProperty.call(e,s)&&__createBinding(t,e,s);return __setModuleDefault(t,e),t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.TTLWrapper=exports.MergeableWrapper=exports.ConvertedMsg=exports.MessageBeforeTransform=exports.DeltaOutgoingImpl=exports.OutgoingImpl=exports.IndexedSnapshotImpl=exports.Incoming=void 0;let Collections=__importStar(require("typescript-collections")),jayeson_lib_record_1=require("@jayesol/jayeson.lib.record");class Incoming{constructor(e,t,s){this._msgType=e,this._stream=t,this._data=s}msgType(){return this._msgType}stream(){return this._stream}data(){return this._data}}exports.Incoming=Incoming;class IndexedSnapshotImpl extends jayeson_lib_record_1.Snapshot{constructor(e={},t=new Collections.Dictionary){super(e),this.partitions=t}getPartitions(){var e,t=new Collections.Set;for(e of this.partitions.keys())t.add(e);return t}getPartitionMap(){return this.partitions}}(exports.IndexedSnapshotImpl=IndexedSnapshotImpl).EMPTY_SNAPSHOT=new IndexedSnapshotImpl;class OutgoingImpl{constructor(e,t){this._msgType=e,this._msg=t}msgType(){return this._msgType}msg(){return this._msg}}exports.OutgoingImpl=OutgoingImpl;class DeltaOutgoingImpl extends OutgoingImpl{constructor(e,t,s,r){super(e,t),this._delta=t,this._after=s,this._before=r}after(){return this._after}delta(){return this._delta}before(){return this._before}}exports.DeltaOutgoingImpl=DeltaOutgoingImpl;class MessageBeforeTransform{constructor(){this.transformEvent=[],this.suppressMatch=[],this.insertMatch=[],this.deleteMatch=[],this.insertEvent=[],this.deleteEvent=[],this.afterSs=IndexedSnapshotImpl.EMPTY_SNAPSHOT,this.beforeSs=IndexedSnapshotImpl.EMPTY_SNAPSHOT}getTransformEvent(){return this.transformEvent}setTransformEvent(e){this.transformEvent.push(e)}getSuppressMatch(){return this.suppressMatch}setSuppressMatch(e){this.suppressMatch.push(e)}setAfterSs(e){this.afterSs=e}getAfterSs(){return this.afterSs}setBeforeSs(e){this.beforeSs=e}getBeforeSs(){return this.beforeSs}setInsertEvent(e){this.insertEvent.push(e)}getInsertEvent(){return this.insertEvent}setDeleteEvent(e){this.deleteEvent.push(e)}getDeleteEvent(){return this.deleteEvent}setInsertMatch(e){this.insertMatch.push(e)}getInsertMatch(){return this.insertMatch}setDeleteMatch(e){this.deleteMatch.push(e)}getDeleteMatch(){return this.deleteMatch}}exports.MessageBeforeTransform=MessageBeforeTransform,(e=>{e[e.INSERT_EVENT_TO_UPDATE=0]="INSERT_EVENT_TO_UPDATE",e[e.DELETE_EVENT_TO_UPDATE=1]="DELETE_EVENT_TO_UPDATE",e[e.INSERT_MATCH_SUPPRESS=2]="INSERT_MATCH_SUPPRESS",e[e.DELETE_MATCH_SUPPRESS=3]="DELETE_MATCH_SUPPRESS",e[e.ORIGINAL=4]="ORIGINAL"})(ConvertedMsg=exports.ConvertedMsg||(exports.ConvertedMsg={}));class MergeableWrapper{constructor(){this.snap=IndexedSnapshotImpl.EMPTY_SNAPSHOT}setDeltaOut(e){this.deltaOut=e}setAfter(e){this.snap=e}getDeltaOut(){return this.deltaOut}getAfter(){return this.snap}}exports.MergeableWrapper=MergeableWrapper;class TTLWrapper{_RemovedKey(){this.removedSs=IndexedSnapshotImpl.EMPTY_SNAPSHOT,this.remainingSs=IndexedSnapshotImpl.EMPTY_SNAPSHOT,this.restoredSs=IndexedSnapshotImpl.EMPTY_SNAPSHOT}setRemovedSs(e){this.removedSs=e}getRemovedSs(){return this.removedSs}setRemainingSs(e){this.remainingSs=e}getRemainingSs(){return this.remainingSs}getRestoredSs(){return this.restoredSs}setRestoredSs(e){this.restoredSs=e}}exports.TTLWrapper=TTLWrapper;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TTLWrapper=exports.MergeableWrapper=exports.ConvertedMsg=exports.MessageBeforeTransform=exports.DeltaOutgoingImpl=exports.OutgoingImpl=exports.IndexedSnapshotImpl=exports.Incoming=void 0;var tslib_1=require("tslib"),Collections=tslib_1.__importStar(require("typescript-collections")),jayeson_lib_record_1=require("@jayesol/jayeson.lib.record"),Incoming=function(){function t(t,e,r){this._msgType=t,this._stream=e,this._data=r}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(t){function e(e,r){void 0===e&&(e={}),void 0===r&&(r=new Collections.Dictionary);var n=t.call(this,e)||this;return n.partitions=r,n}return tslib_1.__extends(e,t),e.prototype.getPartitions=function(){var t,e,r=new Collections.Set;try{for(var n=tslib_1.__values(this.partitions.keys()),o=n.next();!o.done;o=n.next()){var s=o.value;r.add(s)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}return r},e.prototype.getPartitionMap=function(){return this.partitions},e.EMPTY_SNAPSHOT=new e,e}(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}();exports.OutgoingImpl=OutgoingImpl;var DeltaOutgoingImpl=function(t){function e(e,r,n,o){var s=t.call(this,e,r)||this;return s._delta=r,s._after=n,s._before=o,s}return tslib_1.__extends(e,t),e.prototype.after=function(){return this._after},e.prototype.delta=function(){return this._delta},e.prototype.before=function(){return this._before},e}(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;
package/lib/dispatch.js CHANGED
@@ -1 +1 @@
1
- var __decorate=this&&this.__decorate||function(t,e,r,s){var a,p=arguments.length,o=p<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,r,s);else for(var i=t.length-1;0<=i;i--)(a=t[i])&&(o=(p<3?a(o):3<p?a(e,r,o):a(e,r))||o);return 3<p&&o&&Object.defineProperty(e,r,o),o},__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}),exports.RelayEPG=exports.AbstractEPG=exports.DispatchersGroup=exports.EndPointGroupManager=exports.EPDispatcherException=exports.IndicatorWrapper=exports.PartialSnapshotWrapper=exports.FullSnapshotWrapper=exports.WrapperImpl=exports.EPGM_IMPL=void 0;let 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");class WrapperImpl{constructor(t,e){this.__epg=t,this.__stream=e}epg(){return this.__epg}stream(){return this.__stream}}exports.WrapperImpl=WrapperImpl;class FullSnapshotWrapper extends WrapperImpl{constructor(t,e,r,s){super(t,e),this._epg=t,this._stream=e,this._epd=r,this.fullSnapshot=s}epg(){return this._epg}stream(){return this._stream}epd(){return this._epd}process(){this._epd.readyToDispatch();var e=this._epg.generateFull(this);if(null!=e)for(let t=0;t<e.length;t++){var r=e[t];this._epd.submit(r)}}getFullSnapshot(){return this.fullSnapshot}setFullSnapshot(t){this.fullSnapshot=t}}exports.FullSnapshotWrapper=FullSnapshotWrapper;class PartialSnapshotWrapper extends WrapperImpl{constructor(t,e,r){super(e,r),this._delta=t,this._epg=e,this._stream=r}epg(){return this._epg}stream(){return this._stream}delta(){return this._delta}process(){var e=this._epg.generatePartial(this),r=this._epg.getEPDs(this._stream);for(let t=0;t<r.length;t++){var s,a=r[t];for(let t=0;t<e.length;t++)a.isReadyToDispatch()&&(s=e[t],a.submit(s))}}}exports.PartialSnapshotWrapper=PartialSnapshotWrapper;class IndicatorWrapper extends WrapperImpl{constructor(t,e,r){super(e,r),this._delta=t,this._epg=e,this._stream=r}process(){var e=this._epg.getEPDs(this._stream);for(let t=0;t<e.length;t++)e[t].submit(this._delta)}}exports.IndicatorWrapper=IndicatorWrapper;class EPDispatcherException extends Error{constructor(t){super(t)}}exports.EPDispatcherException=EPDispatcherException;let EndPointGroupManager=class{constructor(t,e){this._fsRepo=t,this._grp=e,this.relayEPG=new RelayEPG(e),this.relayEPG.startGetingDeltaSnapshot(t)}fsRepo(){return this._fsRepo}grp(){return this._grp}pushFullSnapshotWrapper(e,r){let s=r.stream();r.isInitialized().then(t=>{t&&(t=this._fsRepo.getSnapshot(s),t=new FullSnapshotWrapper(e,s,r,t),e.submitForProcess(t))})}registerEPD(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)}deregisterEPD(t){this.relayEPG.removeEPD(t)}};EndPointGroupManager=__decorate([(0,injection_js_1.Injectable)(),__param(0,(0,injection_js_1.Inject)(core_1.FSREPO_IMPL)),__metadata("design:paramtypes",[Object,message_class_1.SportsFeedMessageGroup])],EndPointGroupManager),exports.EndPointGroupManager=EndPointGroupManager;class DispatchersGroup{constructor(t){this.streamName=t,this.dispatchers={}}addEpd(t){this.dispatchers[t.id()]=t}removeEpd(t){var e=this.dispatchers[t.id()];return delete this.dispatchers[t.id()],e}get(t){return this.dispatchers[t]}getAll(){return Object.keys(this.dispatchers).map(t=>this.dispatchers[t])}isEmpty(){return 0==Object.keys(this.dispatchers).length}}exports.DispatchersGroup=DispatchersGroup;class AbstractEPG{constructor(t){this.sportsFeedGroup=t,this.dispatchers={}}hasEPD(t,e){t=this.dispatchers[t];return void 0!==t&&void 0!==t.get(e)}addEPD(t){void 0===this.dispatchers[t.stream()]&&(this.dispatchers[t.stream()]=new DispatchersGroup(t.stream())),this.dispatchers[t.stream()].addEpd(t)}removeEPD(t){var e=this.dispatchers[t.stream()];void 0!==e&&(e.removeEpd(t),e.isEmpty())&&delete this.dispatchers[t.stream()]}isEmpty(){return 0==Object.keys(this.dispatchers).length}getEPDs(t){t=this.dispatchers[t];return void 0!==t?t.getAll():[]}getStreams(){return Object.keys(this.dispatchers)}startGetingDeltaSnapshot(t){t.registerSnapshotHandler(this)}stopGetingDeltaSnapshot(t){t.deRegisterSnapshotHandler(this)}process(t,e){var r;this.sportsFeedGroup.isIndicatorMessage(e.msgType())?(r=new IndicatorWrapper(e,this,t),this.submitForProcess(r)):(r=new PartialSnapshotWrapper(e,this,t),this.submitForProcess(r))}getSportsFeedGrp(){return this.sportsFeedGroup}generateFull(t){throw new Error("Method not implemented.")}generatePartial(t){throw new Error("Method not implemented.")}}exports.AbstractEPG=AbstractEPG;let RelayEPG=class extends AbstractEPG{constructor(t){super(t),this._sportsFeedGroup=t}submitForProcess(t){t.process()}onException(t){return console.error("Exception when dispatching snapshots to EPDs from RelayEPG. ",t),null}generateFull(t){t=t.getFullSnapshot();return[new data_structure_1.OutgoingImpl(this._sportsFeedGroup.FULLSNAPSHOT_START(),new Object),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_RESET(),t,t,data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_MATCH(),t,t,data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_EVENT(),t,t,data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_ODD(),t,t,data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.OutgoingImpl(this._sportsFeedGroup.FULLSNAPSHOT_END(),new Object)]}generatePartial(t){t=t.delta();return"TTLOutgoing"==t.constructor.name?this.generateTtl(t):[t]}generateTtl(t){return this.isSameFormat(t.msgType(),this._sportsFeedGroup.ADMIN_REFRESH())?[]:t.getTtlType()==core_1.TTLType.REMOVE?[t]:this.generateTtlRestore(t)}generateTtlRestore(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)]}isSameFormat(t,e){return t.instanceClass()==e.instanceClass()&&t.constructor.name==e.constructor.name}};RelayEPG=__decorate([(0,injection_js_1.Injectable)(),__metadata("design:paramtypes",[message_class_1.SportsFeedMessageGroup])],RelayEPG),exports.RelayEPG=RelayEPG;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RelayEPG=exports.AbstractEPG=exports.DispatchersGroup=exports.EndPointGroupManager=exports.EPDispatcherException=exports.IndicatorWrapper=exports.PartialSnapshotWrapper=exports.FullSnapshotWrapper=exports.WrapperImpl=exports.EPGM_IMPL=void 0;var tslib_1=require("tslib"),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}();exports.WrapperImpl=WrapperImpl;var FullSnapshotWrapper=function(t){function e(e,r,s,o){var p=t.call(this,e,r)||this;return p._epg=e,p._stream=r,p._epd=s,p.fullSnapshot=o,p}return tslib_1.__extends(e,t),e.prototype.epg=function(){return this._epg},e.prototype.stream=function(){return this._stream},e.prototype.epd=function(){return this._epd},e.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)}},e.prototype.getFullSnapshot=function(){return this.fullSnapshot},e.prototype.setFullSnapshot=function(t){this.fullSnapshot=t},e}(WrapperImpl);exports.FullSnapshotWrapper=FullSnapshotWrapper;var PartialSnapshotWrapper=function(t){function e(e,r,s){var o=t.call(this,r,s)||this;return o._delta=e,o._epg=r,o._stream=s,o}return tslib_1.__extends(e,t),e.prototype.epg=function(){return this._epg},e.prototype.stream=function(){return this._stream},e.prototype.delta=function(){return this._delta},e.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 p=t[o];s.submit(p)}},e}(WrapperImpl);exports.PartialSnapshotWrapper=PartialSnapshotWrapper;var IndicatorWrapper=function(t){function e(e,r,s){var o=t.call(this,r,s)||this;return o._delta=e,o._epg=r,o._stream=s,o}return tslib_1.__extends(e,t),e.prototype.process=function(){for(var t=this._epg.getEPDs(this._stream),e=0;e<t.length;e++){t[e].submit(this._delta)}},e}(WrapperImpl);exports.IndicatorWrapper=IndicatorWrapper;var EPDispatcherException=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e}(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(t,e){var r=this,s=e.stream();e.isInitialized().then(function(o){if(o){var p=r._fsRepo.getSnapshot(s),n=new FullSnapshotWrapper(t,s,e,p);t.submitForProcess(n)}})},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=tslib_1.__decorate([(0,injection_js_1.Injectable)(),tslib_1.__param(0,(0,injection_js_1.Inject)(core_1.FSREPO_IMPL)),tslib_1.__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 t=this;return Object.keys(this.dispatchers).map(function(e){return t.dispatchers[e]})},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}();exports.AbstractEPG=AbstractEPG;var RelayEPG=function(t){function e(e){var r=t.call(this,e)||this;return r._sportsFeedGroup=e,r}return tslib_1.__extends(e,t),e.prototype.submitForProcess=function(t){t.process()},e.prototype.onException=function(t){return console.error("Exception when dispatching snapshots to EPDs from RelayEPG. ",t),null},e.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)]},e.prototype.generatePartial=function(t){var e=t.delta();return"TTLOutgoing"==e.constructor.name?this.generateTtl(e):[e]},e.prototype.generateTtl=function(t){return this.isSameFormat(t.msgType(),this._sportsFeedGroup.ADMIN_REFRESH())?[]:t.getTtlType()==core_1.TTLType.REMOVE?[t]:this.generateTtlRestore(t)},e.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)]},e.prototype.isSameFormat=function(t,e){return t.instanceClass()==e.instanceClass()&&t.constructor.name==e.constructor.name},e=tslib_1.__decorate([(0,injection_js_1.Injectable)(),tslib_1.__metadata("design:paramtypes",[message_class_1.SportsFeedMessageGroup])],e)}(AbstractEPG);exports.RelayEPG=RelayEPG;
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var _=Object.getOwnPropertyDescriptor(r,t);_&&("get"in _?r.__esModule:!_.writable&&!_.configurable)||(_={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,_)}:function(e,r,t,o){e[o=void 0===o?t:o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./basketball_codec"),exports),__exportStar(require("./client"),exports),__exportStar(require("./codec"),exports),__exportStar(require("./core"),exports),__exportStar(require("./data_structure"),exports),__exportStar(require("./dispatch"),exports),__exportStar(require("./message_class"),exports),__exportStar(require("./module"),exports),__exportStar(require("./receive"),exports),__exportStar(require("./soccer_codec"),exports),__exportStar(require("./tennis_codec"),exports);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var tslib_1=require("tslib");tslib_1.__exportStar(require("./basketball_codec"),exports),tslib_1.__exportStar(require("./client"),exports),tslib_1.__exportStar(require("./codec"),exports),tslib_1.__exportStar(require("./core"),exports),tslib_1.__exportStar(require("./data_structure"),exports),tslib_1.__exportStar(require("./dispatch"),exports),tslib_1.__exportStar(require("./message_class"),exports),tslib_1.__exportStar(require("./module"),exports),tslib_1.__exportStar(require("./receive"),exports),tslib_1.__exportStar(require("./soccer_codec"),exports),tslib_1.__exportStar(require("./tennis_codec"),exports);
package/lib/merge.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.DeltaTransformingLogicImpl=exports.SnapshotUtil=exports.MsgType=void 0;let data_structure_1=require("./data_structure"),message_class_1=require("./message_class"),mutable_1=require("./mutable"),core_1=require("./core"),data_structure_2=require("./data_structure");var MsgType;(e=>{e[e.INSERT=0]="INSERT",e[e.UPDATE=1]="UPDATE",e[e.DELETE=2]="DELETE"})(MsgType=exports.MsgType||(exports.MsgType={}));class SnapshotUtil{static combineSnapshots(e,t,r){var a;if(e.group().id()!=SnapshotUtil.SPORTS_GROUP.id())return console.error("FATAL: Received non feed message group's class %s.Shouldnt come here",e),(a=new data_structure_1.MessageBeforeTransform).setAfterSs(r),a;switch(e.id()){case SnapshotUtil.SPORTS_GROUP.DATA_INSERT_MATCH().id():return SnapshotUtil.processMatches(MsgType.INSERT,t,r);case SnapshotUtil.SPORTS_GROUP.DATA_UPDATE_MATCH().id():return SnapshotUtil.processMatches(MsgType.UPDATE,t,r);case SnapshotUtil.SPORTS_GROUP.DATA_DELETE_MATCH().id():return SnapshotUtil.processMatches(MsgType.DELETE,t,r);case SnapshotUtil.SPORTS_GROUP.DATA_INSERT_EVENT().id():return SnapshotUtil.processEvents(MsgType.INSERT,t,r);case SnapshotUtil.SPORTS_GROUP.DATA_UPDATE_EVENT().id():return SnapshotUtil.processEvents(MsgType.UPDATE,t,r);case SnapshotUtil.SPORTS_GROUP.DATA_DELETE_EVENT().id():return SnapshotUtil.processEvents(MsgType.DELETE,t,r);case SnapshotUtil.SPORTS_GROUP.DATA_INSERT_ODD().id():return SnapshotUtil.processOdds(MsgType.INSERT,t,r);case SnapshotUtil.SPORTS_GROUP.DATA_UPDATE_ODD().id():return SnapshotUtil.processOdds(MsgType.UPDATE,t,r);case SnapshotUtil.SPORTS_GROUP.DATA_DELETE_ODD().id():return SnapshotUtil.processOdds(MsgType.DELETE,t,r);case SnapshotUtil.SPORTS_GROUP.DATA_RESET().id():return SnapshotUtil.processReset(t,r);case SnapshotUtil.SPORTS_GROUP.ADMIN_REFRESH().id():return SnapshotUtil.processRefresh(t,r);default:console.error("FATAL: Received non data message class %s.Shouldnt come here",e);var s=new data_structure_1.MessageBeforeTransform;return s.setAfterSs(r),s}}static processRefresh(e,t){var r,a=mutable_1.BuilderProvider.getSnapshotBuilder(t),t=new data_structure_1.MessageBeforeTransform;for(r of e.getPartitions().toArray()){var s=e.getPartitionMap().getValue(r);a.markPartitionAsUpdated(r,s)}return t.setAfterSs(a.build()),t}static processReset(e,t){var r,a=mutable_1.BuilderProvider.getSnapshotBuilder(t),t=new data_structure_1.MessageBeforeTransform;for(r of e.getPartitions().toArray()){a.reset(r);var s=e.getPartitionMap().getValue(r);a.markPartitionAsUpdated(r,s)}return t.setAfterSs(a.build()),t}static processMatches(e,t,r){var a,s,i=mutable_1.BuilderProvider.getSnapshotBuilder(r),l=new data_structure_1.MessageBeforeTransform;let o=null;for(a of t.matches())switch(o=null,e){case MsgType.INSERT:null!=(o=i.insertChild(a))?l.setSuppressMatch(o):l.setInsertMatch(a.id());break;case MsgType.UPDATE:i.updateChild(a);break;case MsgType.DELETE:null!=(o=i.deleteChild(a))?l.setSuppressMatch(o):l.setDeleteMatch(a.id());break;default:console.error("[Match] FATAL: Shouldn't come here")}for(s of t.getPartitions().toArray()){var d=t.getPartitionMap().getValue(s);i.markPartitionAsUpdated(s,d)}return l.setAfterSs(i.build()),l}static processEvents(e,t,r){var a=mutable_1.BuilderProvider.getSnapshotBuilder(r);let s=null;var i,l,o=new data_structure_1.MessageBeforeTransform;for(i of t.matches()){var d=r.match(i.id());if(null==d)console.error("Cannot find Match %s while processing %s",i.id(),MsgType);else{var n,u=mutable_1.BuilderProvider.getMatchBuilder(d);for(n of i.events())switch(e){case MsgType.INSERT:null!=(s=u.insertChild(n))?o.setTransformEvent(n.matchId()+"_"+n.id()):o.setInsertEvent(n.matchId()+"_"+n.id());break;case MsgType.UPDATE:u.updateChild(n);break;case MsgType.DELETE:null!=(s=u.deleteChild(n))?o.setTransformEvent(n.matchId()+"_"+n.id()):o.setDeleteEvent(n.matchId()+"_"+n.id());break;default:console.error("[Event] FATAL: Shouldn't come here")}a.replaceMatch(u.build())}}for(l of t.getPartitions().toArray()){var c=t.getPartitionMap().getValue(l);a.markPartitionAsUpdated(l,c)}return o.setAfterSs(a.build()),o.setBeforeSs(r),o}static processOdds(e,t,r){var a,s,i=mutable_1.BuilderProvider.getSnapshotBuilder(r),l=new data_structure_1.MessageBeforeTransform;for(a of t.matches()){var o=r.match(a.id());if(null==o)console.error("Cannot find Match %s while processing %s",a.id(),e);else{var d,n=mutable_1.BuilderProvider.getMatchBuilder(o);for(d of a.events()){var u=o.event(d.id());if(null==u)console.error("Cannot find Event %s_%s while processing %s",a.id(),d.id(),e);else{var c,p=mutable_1.BuilderProvider.getEventBuilder(u);for(c of d.records())switch(e){case MsgType.INSERT:p.insertChild(c);break;case MsgType.UPDATE:p.updateChild(c);break;case MsgType.DELETE:p.deleteChild(c);break;default:console.error("[Record] FATAL: Shouldn't come here")}n.replaceEvent(p.build())}}i.replaceMatch(n.build())}}for(s of t.getPartitions().toArray()){var _=t.getPartitionMap().getValue(s);i.markPartitionAsUpdated(s,_)}return l.setAfterSs(i.build()),l}}(exports.SnapshotUtil=SnapshotUtil).SPORTS_GROUP=new message_class_1.SportsFeedMessageGroup;class DeltaTransformingLogicImpl{static transform(e,t,r,a,s){switch(r.id()){case e.DATA_INSERT_MATCH().id():return this.suppressInsertMatch(s,e,r,t,a,[]);case e.DATA_DELETE_MATCH().id():return this.suppressDeleteMatch(s,e,r,t,a,[]);case e.DATA_INSERT_EVENT().id():return this.suppressInsertEvent(s,e,r,t,a,[]);case e.DATA_DELETE_EVENT().id():return this.suppressDeleteEvent(s,e,r,t,a,[]);case e.DATA_UPDATE_EVENT().id():return this.combineEventState(s,e,r,t,a,[])}var i=[];return i.push(new data_structure_1.Incoming(r,t,a)),i}static combineEventState(e,t,r,a,s,i){var l,o=mutable_1.BuilderProvider.getSnapshotBuilder(s);for(l of s.matches()){var d,n=mutable_1.BuilderProvider.getMatchBuilder(l);for(d of l.events()){var u=mutable_1.BuilderProvider.getEventBuilder(d);u.aggregateInsert(e.getAfterSs().match(l.id()).event(d.id())),n.replaceEvent(u.build())}o.replaceMatch(n.build())}return i.push(new data_structure_1.Incoming(t.DATA_UPDATE_EVENT(),a,o.build())),i}static suppressInsertEvent(t,e,r,a,s,i){var l=mutable_1.BuilderProvider.getSnapshotBuilder(s),o=mutable_1.BuilderProvider.getSnapshotBuilder(s);if(0!=s.matches().length){if(0!=t.getInsertEvent().length){var d,n,u={};for(d of t.getTransformEvent()){var c=d.split("_")[0],p=d.split("_")[1],_=s.match(c);let e=u[c];void 0===e&&(e=mutable_1.BuilderProvider.getMatchBuilder(_),u[c]=e),e.deleteChild(_.event(p))}for(n in u)l.replaceMatch(u[n].build());i.push(new data_structure_1.Incoming(e.DATA_INSERT_EVENT(),a,l.build()))}if(0!=t.getTransformEvent().length){var h,T,g,E={};for(h of t.getInsertEvent()){var S=h.split("_")[0],v=h.split("_")[1],m=s.match(S);let e=E[S];void 0===e&&(e=mutable_1.BuilderProvider.getMatchBuilder(m),E[S]=e),e.deleteChild(m.event(v))}for(T of t.getTransformEvent()){var f=T.split("_")[0],A=T.split("_")[1],D=s.match(f);let e=E[f];void 0===e&&(e=mutable_1.BuilderProvider.getMatchBuilder(D),E[f]=e);D=mutable_1.BuilderProvider.getEventBuilder(D.event(A));D.aggregateInsert(t.getAfterSs().match(f).event(A)),e.replaceEvent(D.build())}for(g in E)o.replaceMatch(E[g].build());i.push(new data_structure_1.Incoming(e.DATA_UPDATE_EVENT(),a,o.build()))}}return i}static transformTTLRestore(e,t,r,a,s,i,l){let o=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT;var d,n=new data_structure_1.MergeableWrapper;for(d of e)o=SnapshotUtil.combineSnapshots(t.DATA_INSERT_MATCH(),d,o).getAfterSs(),o=SnapshotUtil.combineSnapshots(t.DATA_INSERT_EVENT(),d,o).getAfterSs(),o=SnapshotUtil.combineSnapshots(t.DATA_INSERT_ODD(),d,o).getAfterSs();let u=a;var c,p=[];for(c of this.breakdownTTL(t,r,new data_structure_2.IndexedSnapshotImpl(o.matchesSport,l))){var _,h=SnapshotUtil.combineSnapshots(c.msgType(),c.data(),u);if(c.msgType().id()==t.DATA_INSERT_MATCH().id()||c.msgType().id()==t.DATA_INSERT_EVENT().id())for(_ of DeltaTransformingLogicImpl.transform(t,r,c.msgType(),c.data(),h)){var T=new core_1.Delta(_,h.getAfterSs(),u);p.push(T),u=h.getAfterSs()}else{var g=new core_1.Delta(c,h.getAfterSs(),a);p.push(g)}}return n.setAfter(s),n.setDeltaOut(p),n}static transformTTLRemove(e,t,r,a,s,i){var l,o=new data_structure_1.MergeableWrapper;let d=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,n;for(l of e)d=SnapshotUtil.combineSnapshots(t.DATA_INSERT_MATCH(),l,d).getAfterSs(),d=SnapshotUtil.combineSnapshots(t.DATA_INSERT_EVENT(),l,d).getAfterSs(),d=SnapshotUtil.combineSnapshots(t.DATA_INSERT_ODD(),l,d).getAfterSs();var u,e=DeltaTransformingLogicImpl.breakdownReset(t,r,d),c=(n=a,[]);for(u of e){var p,_=SnapshotUtil.combineSnapshots(u.msgType(),u.data(),n);if(u.msgType().id()==t.DATA_DELETE_MATCH().id()||u.msgType().id()==t.DATA_DELETE_EVENT().id())for(p of DeltaTransformingLogicImpl.transform(t,r,u.msgType(),u.data(),_)){var h=new core_1.Delta(p,_.getAfterSs(),n);c.push(h),n=_.getAfterSs()}else{var T=new core_1.Delta(u,_.getAfterSs(),a);c.push(T)}}return o.setDeltaOut(c),o.setAfter(s),o}static breakdownTTL(e,t,r){data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT;var a,s=mutable_1.BuilderProvider.getSnapshotBuilder(r),i=mutable_1.BuilderProvider.getSnapshotBuilder(r);for(a of r.matches()){var l,o=mutable_1.BuilderProvider.getMatchBuilder(a),d=mutable_1.BuilderProvider.getMatchBuilder(a);for(l of a.events()){o.deleteChild(l);var n,u=mutable_1.BuilderProvider.getEventBuilder(l);for(n of l.records())u.deleteChild(n);d.replaceEvent(u.build())}s.replaceMatch(o.build()),i.replaceMatch(d.build())}var c=s.build(),p=i.build(),_=[];return _.push(new data_structure_1.Incoming(e.DATA_INSERT_MATCH(),t,c)),_.push(new data_structure_1.Incoming(e.DATA_INSERT_EVENT(),t,p)),_.push(new data_structure_1.Incoming(e.DATA_INSERT_ODD(),t,r)),_}static breakdownReset(e,t,r){data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT;var a,s=mutable_1.BuilderProvider.getSnapshotBuilder(r),i=mutable_1.BuilderProvider.getSnapshotBuilder(r);for(a of r.matches()){var l,o=mutable_1.BuilderProvider.getMatchBuilder(a),d=mutable_1.BuilderProvider.getMatchBuilder(a);for(l of a.events()){o.deleteChild(l);var n,u=mutable_1.BuilderProvider.getEventBuilder(l);for(n of l.records())u.deleteChild(n);d.replaceEvent(u.build())}s.replaceMatch(o.build()),i.replaceMatch(d.build())}var c=s.build(),p=i.build(),_=[];return _.push(new data_structure_1.Incoming(e.DATA_DELETE_ODD(),t,r)),_.push(new data_structure_1.Incoming(e.DATA_DELETE_EVENT(),t,p)),_.push(new data_structure_1.Incoming(e.DATA_DELETE_MATCH(),t,c)),_}static suppressInsertMatch(e,t,r,a,s,i){var l=mutable_1.BuilderProvider.getSnapshotBuilder(s),o=mutable_1.BuilderProvider.getSnapshotBuilder(s);if(0!=e.getSuppressMatch().length)for(var d of e.getSuppressMatch()){d=mutable_1.BuilderProvider.getMatchBuilder(s.match(d.split("_")[0]));l.deleteChild(d.build())}if(0!=e.getInsertMatch().length)for(var n of e.getInsertMatch()){n=mutable_1.BuilderProvider.getMatchBuilder(s.match(n.split("_")[0]));o.deleteChild(n.build())}return 0!=l.build().matches().length&&i.push(new data_structure_1.Incoming(t.DATA_INSERT_MATCH(),a,l.build())),i}static suppressDeleteEvent(t,e,r,a,s,i){var l=mutable_1.BuilderProvider.getSnapshotBuilder(s),o=mutable_1.BuilderProvider.getSnapshotBuilder(s);if(0!=t.getDeleteEvent().length){var d,n,u={};for(d of t.getTransformEvent()){var c=d.split("_")[0],p=d.split("_")[1],_=t.getBeforeSs().match(c);let e=u[c];void 0===e&&(e=mutable_1.BuilderProvider.getMatchBuilder(_),u[c]=e),e.deleteChild(_.event(p))}for(n in u)l.replaceMatch(u[n].build());i.push(new data_structure_1.Incoming(e.DATA_DELETE_EVENT(),a,l.build()))}if(0!=t.getTransformEvent().length){var h,T,g,E={};for(h of t.getDeleteEvent()){var S=h.split("_")[0],v=h.split("_")[1],m=t.getBeforeSs().match(S);let e=E[S];void 0===e&&(e=mutable_1.BuilderProvider.getMatchBuilder(m),E[S]=e),e.deleteChild(m.event(v))}for(T of t.getTransformEvent()){var f=T.split("_")[0],A=T.split("_")[1];let e=E[f];void 0===e&&(e=mutable_1.BuilderProvider.getMatchBuilder(t.getBeforeSs().match(f)),E[f]=e);var D=mutable_1.BuilderProvider.getEventBuilder(e.build().event(A));D.aggregateDelete(s.match(f).event(A)),e.replaceEvent(D.build())}for(g in E)o.replaceMatch(E[g].build());i.push(new data_structure_1.Incoming(e.DATA_UPDATE_EVENT(),a,o.build()))}return i}static suppressDeleteMatch(e,t,r,a,s,i){var l=mutable_1.BuilderProvider.getSnapshotBuilder(s),o=mutable_1.BuilderProvider.getSnapshotBuilder(s);if(0!=e.getSuppressMatch().length)for(var d of e.getSuppressMatch()){d=mutable_1.BuilderProvider.getMatchBuilder(s.match(d.split("_")[0]));l.deleteChild(d.build())}if(0!=e.getDeleteMatch().length)for(var n of e.getDeleteMatch()){n=mutable_1.BuilderProvider.getMatchBuilder(s.match(n.split("_")[0]));o.deleteChild(n.build())}return 0!=l.build().matches().length&&i.push(new data_structure_1.Incoming(t.DATA_DELETE_MATCH(),a,l.build())),i}}exports.DeltaTransformingLogicImpl=DeltaTransformingLogicImpl;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DeltaTransformingLogicImpl=exports.SnapshotUtil=exports.MsgType=void 0;var MsgType,tslib_1=require("tslib"),data_structure_1=require("./data_structure"),message_class_1=require("./message_class"),mutable_1=require("./mutable"),core_1=require("./core"),data_structure_2=require("./data_structure");!function(e){e[e.INSERT=0]="INSERT",e[e.UPDATE=1]="UPDATE",e[e.DELETE=2]="DELETE"}(MsgType=exports.MsgType||(exports.MsgType={}));var SnapshotUtil=function(){function e(){}return e.combineSnapshots=function(r,t,a){if(r.group().id()!=e.SPORTS_GROUP.id())return console.error("FATAL: Received non feed message group's class %s.Shouldnt come here",r),(l=new data_structure_1.MessageBeforeTransform).setAfterSs(a),l;switch(r.id()){case e.SPORTS_GROUP.DATA_INSERT_MATCH().id():return e.processMatches(MsgType.INSERT,t,a);case e.SPORTS_GROUP.DATA_UPDATE_MATCH().id():return e.processMatches(MsgType.UPDATE,t,a);case e.SPORTS_GROUP.DATA_DELETE_MATCH().id():return e.processMatches(MsgType.DELETE,t,a);case e.SPORTS_GROUP.DATA_INSERT_EVENT().id():return e.processEvents(MsgType.INSERT,t,a);case e.SPORTS_GROUP.DATA_UPDATE_EVENT().id():return e.processEvents(MsgType.UPDATE,t,a);case e.SPORTS_GROUP.DATA_DELETE_EVENT().id():return e.processEvents(MsgType.DELETE,t,a);case e.SPORTS_GROUP.DATA_INSERT_ODD().id():return e.processOdds(MsgType.INSERT,t,a);case e.SPORTS_GROUP.DATA_UPDATE_ODD().id():return e.processOdds(MsgType.UPDATE,t,a);case e.SPORTS_GROUP.DATA_DELETE_ODD().id():return e.processOdds(MsgType.DELETE,t,a);case e.SPORTS_GROUP.DATA_RESET().id():return e.processReset(t,a);case e.SPORTS_GROUP.ADMIN_REFRESH().id():return e.processRefresh(t,a);default:var l;return console.error("FATAL: Received non data message class %s.Shouldnt come here",r),(l=new data_structure_1.MessageBeforeTransform).setAfterSs(a),l}},e.processRefresh=function(e,r){var t,a,l=mutable_1.BuilderProvider.getSnapshotBuilder(r),n=new data_structure_1.MessageBeforeTransform,i=e.getPartitions().toArray();try{for(var s=tslib_1.__values(i),o=s.next();!o.done;o=s.next()){var u=o.value,d=e.getPartitionMap().getValue(u);l.markPartitionAsUpdated(u,d)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(a=s.return)&&a.call(s)}finally{if(t)throw t.error}}return n.setAfterSs(l.build()),n},e.processReset=function(e,r){var t,a,l=mutable_1.BuilderProvider.getSnapshotBuilder(r),n=new data_structure_1.MessageBeforeTransform,i=e.getPartitions().toArray();try{for(var s=tslib_1.__values(i),o=s.next();!o.done;o=s.next()){var u=o.value;l.reset(u);var d=e.getPartitionMap().getValue(u);l.markPartitionAsUpdated(u,d)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(a=s.return)&&a.call(s)}finally{if(t)throw t.error}}return n.setAfterSs(l.build()),n},e.processMatches=function(e,r,t){var a,l,n,i,s=mutable_1.BuilderProvider.getSnapshotBuilder(t),o=new data_structure_1.MessageBeforeTransform,u=null;try{for(var d=tslib_1.__values(r.matches()),c=d.next();!c.done;c=d.next()){var _=c.value;switch(u=null,e){case MsgType.INSERT:null!=(u=s.insertChild(_))?o.setSuppressMatch(u):o.setInsertMatch(_.id());break;case MsgType.UPDATE:s.updateChild(_);break;case MsgType.DELETE:null!=(u=s.deleteChild(_))?o.setSuppressMatch(u):o.setDeleteMatch(_.id());break;default:console.error("[Match] FATAL: Shouldn't come here")}}}catch(e){a={error:e}}finally{try{c&&!c.done&&(l=d.return)&&l.call(d)}finally{if(a)throw a.error}}var v=r.getPartitions().toArray();try{for(var h=tslib_1.__values(v),f=h.next();!f.done;f=h.next()){var T=f.value,p=r.getPartitionMap().getValue(T);s.markPartitionAsUpdated(T,p)}}catch(e){n={error:e}}finally{try{f&&!f.done&&(i=h.return)&&i.call(h)}finally{if(n)throw n.error}}return o.setAfterSs(s.build()),o},e.processEvents=function(e,r,t){var a,l,n,i,s,o,u=mutable_1.BuilderProvider.getSnapshotBuilder(t),d=new data_structure_1.MessageBeforeTransform;try{for(var c=tslib_1.__values(r.matches()),_=c.next();!_.done;_=c.next()){var v=_.value,h=t.match(v.id());if(null!=h){var f=mutable_1.BuilderProvider.getMatchBuilder(h);try{for(var T=(n=void 0,tslib_1.__values(v.events())),p=T.next();!p.done;p=T.next()){var g=p.value;switch(e){case MsgType.INSERT:null!=f.insertChild(g)?d.setTransformEvent(g.matchId()+"_"+g.id()):d.setInsertEvent(g.matchId()+"_"+g.id());break;case MsgType.UPDATE:f.updateChild(g);break;case MsgType.DELETE:null!=f.deleteChild(g)?d.setTransformEvent(g.matchId()+"_"+g.id()):d.setDeleteEvent(g.matchId()+"_"+g.id());break;default:console.error("[Event] FATAL: Shouldn't come here")}}}catch(e){n={error:e}}finally{try{p&&!p.done&&(i=T.return)&&i.call(T)}finally{if(n)throw n.error}}u.replaceMatch(f.build())}else console.error("Cannot find Match %s while processing %s",v.id(),MsgType)}}catch(e){a={error:e}}finally{try{_&&!_.done&&(l=c.return)&&l.call(c)}finally{if(a)throw a.error}}var E=r.getPartitions().toArray();try{for(var y=tslib_1.__values(E),m=y.next();!m.done;m=y.next()){var A=m.value,S=r.getPartitionMap().getValue(A);u.markPartitionAsUpdated(A,S)}}catch(e){s={error:e}}finally{try{m&&!m.done&&(o=y.return)&&o.call(y)}finally{if(s)throw s.error}}return d.setAfterSs(u.build()),d.setBeforeSs(t),d},e.processOdds=function(e,r,t){var a,l,n,i,s,o,u,d,c=mutable_1.BuilderProvider.getSnapshotBuilder(t),_=new data_structure_1.MessageBeforeTransform;try{for(var v=tslib_1.__values(r.matches()),h=v.next();!h.done;h=v.next()){var f=h.value,T=t.match(f.id());if(null!=T){var p=mutable_1.BuilderProvider.getMatchBuilder(T);try{for(var g=(n=void 0,tslib_1.__values(f.events())),E=g.next();!E.done;E=g.next()){var y=E.value,m=T.event(y.id());if(null!=m){var A=mutable_1.BuilderProvider.getEventBuilder(m);try{for(var S=(s=void 0,tslib_1.__values(y.records())),b=S.next();!b.done;b=S.next()){var M=b.value;switch(e){case MsgType.INSERT:A.insertChild(M);break;case MsgType.UPDATE:A.updateChild(M);break;case MsgType.DELETE:A.deleteChild(M);break;default:console.error("[Record] FATAL: Shouldn't come here")}}}catch(e){s={error:e}}finally{try{b&&!b.done&&(o=S.return)&&o.call(S)}finally{if(s)throw s.error}}p.replaceEvent(A.build())}else console.error("Cannot find Event %s_%s while processing %s",f.id(),y.id(),e)}}catch(e){n={error:e}}finally{try{E&&!E.done&&(i=g.return)&&i.call(g)}finally{if(n)throw n.error}}c.replaceMatch(p.build())}else console.error("Cannot find Match %s while processing %s",f.id(),e)}}catch(e){a={error:e}}finally{try{h&&!h.done&&(l=v.return)&&l.call(v)}finally{if(a)throw a.error}}var P=r.getPartitions().toArray();try{for(var D=tslib_1.__values(P),B=D.next();!B.done;B=D.next()){var x=B.value,w=r.getPartitionMap().getValue(x);c.markPartitionAsUpdated(x,w)}}catch(e){u={error:e}}finally{try{B&&!B.done&&(d=D.return)&&d.call(D)}finally{if(u)throw u.error}}return _.setAfterSs(c.build()),_},e.SPORTS_GROUP=new message_class_1.SportsFeedMessageGroup,e}();exports.SnapshotUtil=SnapshotUtil;var DeltaTransformingLogicImpl=function(){function e(){}return e.transform=function(e,r,t,a,l){switch(t.id()){case e.DATA_INSERT_MATCH().id():return this.suppressInsertMatch(l,e,t,r,a,[]);case e.DATA_DELETE_MATCH().id():return this.suppressDeleteMatch(l,e,t,r,a,[]);case e.DATA_INSERT_EVENT().id():return this.suppressInsertEvent(l,e,t,r,a,[]);case e.DATA_DELETE_EVENT().id():return this.suppressDeleteEvent(l,e,t,r,a,[]);case e.DATA_UPDATE_EVENT().id():return this.combineEventState(l,e,t,r,a,[])}var n=[];return n.push(new data_structure_1.Incoming(t,r,a)),n},e.combineEventState=function(e,r,t,a,l,n){var i,s,o,u,d=mutable_1.BuilderProvider.getSnapshotBuilder(l);try{for(var c=tslib_1.__values(l.matches()),_=c.next();!_.done;_=c.next()){var v=_.value,h=mutable_1.BuilderProvider.getMatchBuilder(v);try{for(var f=(o=void 0,tslib_1.__values(v.events())),T=f.next();!T.done;T=f.next()){var p=T.value,g=mutable_1.BuilderProvider.getEventBuilder(p);g.aggregateInsert(e.getAfterSs().match(v.id()).event(p.id())),h.replaceEvent(g.build())}}catch(e){o={error:e}}finally{try{T&&!T.done&&(u=f.return)&&u.call(f)}finally{if(o)throw o.error}}d.replaceMatch(h.build())}}catch(e){i={error:e}}finally{try{_&&!_.done&&(s=c.return)&&s.call(c)}finally{if(i)throw i.error}}return n.push(new data_structure_1.Incoming(r.DATA_UPDATE_EVENT(),a,d.build())),n},e.suppressInsertEvent=function(e,r,t,a,l,n){var i,s,o,u,d,c,_=mutable_1.BuilderProvider.getSnapshotBuilder(l),v=mutable_1.BuilderProvider.getSnapshotBuilder(l);if(0!=l.matches().length){if(0!=e.getInsertEvent().length){var h={};try{for(var f=tslib_1.__values(e.getTransformEvent()),T=f.next();!T.done;T=f.next()){var p=(D=T.value).split("_")[0],g=D.split("_")[1],E=l.match(p),y=h[p];void 0===y&&(y=mutable_1.BuilderProvider.getMatchBuilder(E),h[p]=y),y.deleteChild(E.event(g))}}catch(e){i={error:e}}finally{try{T&&!T.done&&(s=f.return)&&s.call(f)}finally{if(i)throw i.error}}for(var p in h)_.replaceMatch(h[p].build());n.push(new data_structure_1.Incoming(r.DATA_INSERT_EVENT(),a,_.build()))}if(0!=e.getTransformEvent().length){var m={};try{for(var A=tslib_1.__values(e.getInsertEvent()),S=A.next();!S.done;S=A.next()){p=(D=S.value).split("_")[0],g=D.split("_")[1],E=l.match(p);var b=m[p];void 0===b&&(b=mutable_1.BuilderProvider.getMatchBuilder(E),m[p]=b),b.deleteChild(E.event(g))}}catch(e){o={error:e}}finally{try{S&&!S.done&&(u=A.return)&&u.call(A)}finally{if(o)throw o.error}}try{for(var M=tslib_1.__values(e.getTransformEvent()),P=M.next();!P.done;P=M.next()){p=(D=P.value).split("_")[0],g=D.split("_")[1],E=l.match(p);var D,B=m[p];void 0===B&&(B=mutable_1.BuilderProvider.getMatchBuilder(E),m[p]=B);var x=mutable_1.BuilderProvider.getEventBuilder(E.event(g));x.aggregateInsert(e.getAfterSs().match(p).event(g)),B.replaceEvent(x.build())}}catch(e){d={error:e}}finally{try{P&&!P.done&&(c=M.return)&&c.call(M)}finally{if(d)throw d.error}}for(var p in m)v.replaceMatch(m[p].build());n.push(new data_structure_1.Incoming(r.DATA_UPDATE_EVENT(),a,v.build()))}}return n},e.transformTTLRestore=function(r,t,a,l,n,i,s){var o,u,d,c,_,v,h=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,f=new data_structure_1.MergeableWrapper;try{for(var T=tslib_1.__values(r),p=T.next();!p.done;p=T.next()){var g=p.value;h=SnapshotUtil.combineSnapshots(t.DATA_INSERT_MATCH(),g,h).getAfterSs(),h=SnapshotUtil.combineSnapshots(t.DATA_INSERT_EVENT(),g,h).getAfterSs(),h=SnapshotUtil.combineSnapshots(t.DATA_INSERT_ODD(),g,h).getAfterSs()}}catch(e){o={error:e}}finally{try{p&&!p.done&&(u=T.return)&&u.call(T)}finally{if(o)throw o.error}}var E=this.breakdownTTL(t,a,new data_structure_2.IndexedSnapshotImpl(h.matchesSport,s)),y=l,m=[];try{for(var A=tslib_1.__values(E),S=A.next();!S.done;S=A.next()){var b=S.value,M=SnapshotUtil.combineSnapshots(b.msgType(),b.data(),y);if(b.msgType().id()==t.DATA_INSERT_MATCH().id()||b.msgType().id()==t.DATA_INSERT_EVENT().id()){var P=e.transform(t,a,b.msgType(),b.data(),M);try{for(var D=(_=void 0,tslib_1.__values(P)),B=D.next();!B.done;B=D.next()){var x=B.value,w=new core_1.Delta(x,M.getAfterSs(),y);m.push(w),y=M.getAfterSs()}}catch(e){_={error:e}}finally{try{B&&!B.done&&(v=D.return)&&v.call(D)}finally{if(_)throw _.error}}}else{w=new core_1.Delta(b,M.getAfterSs(),l);m.push(w)}}}catch(e){d={error:e}}finally{try{S&&!S.done&&(c=A.return)&&c.call(A)}finally{if(d)throw d.error}}return f.setAfter(n),f.setDeltaOut(m),f},e.transformTTLRemove=function(r,t,a,l,n,i){var s,o,u,d,c,_,v,h=new data_structure_1.MergeableWrapper,f=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT;try{for(var T=tslib_1.__values(r),p=T.next();!p.done;p=T.next()){var g=p.value;f=SnapshotUtil.combineSnapshots(t.DATA_INSERT_MATCH(),g,f).getAfterSs(),f=SnapshotUtil.combineSnapshots(t.DATA_INSERT_EVENT(),g,f).getAfterSs(),f=SnapshotUtil.combineSnapshots(t.DATA_INSERT_ODD(),g,f).getAfterSs()}}catch(e){s={error:e}}finally{try{p&&!p.done&&(o=T.return)&&o.call(T)}finally{if(s)throw s.error}}var E=e.breakdownReset(t,a,f);v=l;var y=[];try{for(var m=tslib_1.__values(E),A=m.next();!A.done;A=m.next()){var S=A.value,b=SnapshotUtil.combineSnapshots(S.msgType(),S.data(),v);if(S.msgType().id()==t.DATA_DELETE_MATCH().id()||S.msgType().id()==t.DATA_DELETE_EVENT().id()){var M=e.transform(t,a,S.msgType(),S.data(),b);try{for(var P=(c=void 0,tslib_1.__values(M)),D=P.next();!D.done;D=P.next()){var B=D.value,x=new core_1.Delta(B,b.getAfterSs(),v);y.push(x),v=b.getAfterSs()}}catch(e){c={error:e}}finally{try{D&&!D.done&&(_=P.return)&&_.call(P)}finally{if(c)throw c.error}}}else{x=new core_1.Delta(S,b.getAfterSs(),l);y.push(x)}}}catch(e){u={error:e}}finally{try{A&&!A.done&&(d=m.return)&&d.call(m)}finally{if(u)throw u.error}}return h.setDeltaOut(y),h.setAfter(n),h},e.breakdownTTL=function(e,r,t){var a,l,n,i,s,o,u=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,d=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,c=mutable_1.BuilderProvider.getSnapshotBuilder(t),_=mutable_1.BuilderProvider.getSnapshotBuilder(t);try{for(var v=tslib_1.__values(t.matches()),h=v.next();!h.done;h=v.next()){var f=h.value,T=mutable_1.BuilderProvider.getMatchBuilder(f),p=mutable_1.BuilderProvider.getMatchBuilder(f);try{for(var g=(n=void 0,tslib_1.__values(f.events())),E=g.next();!E.done;E=g.next()){var y=E.value;T.deleteChild(y);var m=mutable_1.BuilderProvider.getEventBuilder(y);try{for(var A=(s=void 0,tslib_1.__values(y.records())),S=A.next();!S.done;S=A.next()){var b=S.value;m.deleteChild(b)}}catch(e){s={error:e}}finally{try{S&&!S.done&&(o=A.return)&&o.call(A)}finally{if(s)throw s.error}}p.replaceEvent(m.build())}}catch(e){n={error:e}}finally{try{E&&!E.done&&(i=g.return)&&i.call(g)}finally{if(n)throw n.error}}c.replaceMatch(T.build()),_.replaceMatch(p.build())}}catch(e){a={error:e}}finally{try{h&&!h.done&&(l=v.return)&&l.call(v)}finally{if(a)throw a.error}}u=c.build(),d=_.build();var M=[];return M.push(new data_structure_1.Incoming(e.DATA_INSERT_MATCH(),r,u)),M.push(new data_structure_1.Incoming(e.DATA_INSERT_EVENT(),r,d)),M.push(new data_structure_1.Incoming(e.DATA_INSERT_ODD(),r,t)),M},e.breakdownReset=function(e,r,t){var a,l,n,i,s,o,u=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,d=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,c=mutable_1.BuilderProvider.getSnapshotBuilder(t),_=mutable_1.BuilderProvider.getSnapshotBuilder(t);try{for(var v=tslib_1.__values(t.matches()),h=v.next();!h.done;h=v.next()){var f=h.value,T=mutable_1.BuilderProvider.getMatchBuilder(f),p=mutable_1.BuilderProvider.getMatchBuilder(f);try{for(var g=(n=void 0,tslib_1.__values(f.events())),E=g.next();!E.done;E=g.next()){var y=E.value;T.deleteChild(y);var m=mutable_1.BuilderProvider.getEventBuilder(y);try{for(var A=(s=void 0,tslib_1.__values(y.records())),S=A.next();!S.done;S=A.next()){var b=S.value;m.deleteChild(b)}}catch(e){s={error:e}}finally{try{S&&!S.done&&(o=A.return)&&o.call(A)}finally{if(s)throw s.error}}p.replaceEvent(m.build())}}catch(e){n={error:e}}finally{try{E&&!E.done&&(i=g.return)&&i.call(g)}finally{if(n)throw n.error}}c.replaceMatch(T.build()),_.replaceMatch(p.build())}}catch(e){a={error:e}}finally{try{h&&!h.done&&(l=v.return)&&l.call(v)}finally{if(a)throw a.error}}u=c.build(),d=_.build();var M=[];return M.push(new data_structure_1.Incoming(e.DATA_DELETE_ODD(),r,t)),M.push(new data_structure_1.Incoming(e.DATA_DELETE_EVENT(),r,d)),M.push(new data_structure_1.Incoming(e.DATA_DELETE_MATCH(),r,u)),M},e.suppressInsertMatch=function(e,r,t,a,l,n){var i,s,o,u,d=mutable_1.BuilderProvider.getSnapshotBuilder(l),c=mutable_1.BuilderProvider.getSnapshotBuilder(l);if(0!=e.getSuppressMatch().length)try{for(var _=tslib_1.__values(e.getSuppressMatch()),v=_.next();!v.done;v=_.next()){var h=v.value,f=mutable_1.BuilderProvider.getMatchBuilder(l.match(h.split("_")[0]));d.deleteChild(f.build())}}catch(e){i={error:e}}finally{try{v&&!v.done&&(s=_.return)&&s.call(_)}finally{if(i)throw i.error}}if(0!=e.getInsertMatch().length)try{for(var T=tslib_1.__values(e.getInsertMatch()),p=T.next();!p.done;p=T.next()){h=p.value,f=mutable_1.BuilderProvider.getMatchBuilder(l.match(h.split("_")[0]));c.deleteChild(f.build())}}catch(e){o={error:e}}finally{try{p&&!p.done&&(u=T.return)&&u.call(T)}finally{if(o)throw o.error}}return 0!=d.build().matches().length&&n.push(new data_structure_1.Incoming(r.DATA_INSERT_MATCH(),a,d.build())),n},e.suppressDeleteEvent=function(e,r,t,a,l,n){var i,s,o,u,d,c,_=mutable_1.BuilderProvider.getSnapshotBuilder(l),v=mutable_1.BuilderProvider.getSnapshotBuilder(l);if(0!=e.getDeleteEvent().length){var h={};try{for(var f=tslib_1.__values(e.getTransformEvent()),T=f.next();!T.done;T=f.next()){var p=(D=T.value).split("_")[0],g=D.split("_")[1],E=e.getBeforeSs().match(p),y=h[p];void 0===y&&(y=mutable_1.BuilderProvider.getMatchBuilder(E),h[p]=y),y.deleteChild(E.event(g))}}catch(e){i={error:e}}finally{try{T&&!T.done&&(s=f.return)&&s.call(f)}finally{if(i)throw i.error}}for(var p in h)_.replaceMatch(h[p].build());n.push(new data_structure_1.Incoming(r.DATA_DELETE_EVENT(),a,_.build()))}if(0!=e.getTransformEvent().length){var m={};try{for(var A=tslib_1.__values(e.getDeleteEvent()),S=A.next();!S.done;S=A.next()){p=(D=S.value).split("_")[0],g=D.split("_")[1],E=e.getBeforeSs().match(p);var b=m[p];void 0===b&&(b=mutable_1.BuilderProvider.getMatchBuilder(E),m[p]=b),b.deleteChild(E.event(g))}}catch(e){o={error:e}}finally{try{S&&!S.done&&(u=A.return)&&u.call(A)}finally{if(o)throw o.error}}try{for(var M=tslib_1.__values(e.getTransformEvent()),P=M.next();!P.done;P=M.next()){p=(D=P.value).split("_")[0],g=D.split("_")[1];var D,B=m[p];void 0===B&&(B=mutable_1.BuilderProvider.getMatchBuilder(e.getBeforeSs().match(p)),m[p]=B);var x=mutable_1.BuilderProvider.getEventBuilder(B.build().event(g));x.aggregateDelete(l.match(p).event(g)),B.replaceEvent(x.build())}}catch(e){d={error:e}}finally{try{P&&!P.done&&(c=M.return)&&c.call(M)}finally{if(d)throw d.error}}for(var p in m)v.replaceMatch(m[p].build());n.push(new data_structure_1.Incoming(r.DATA_UPDATE_EVENT(),a,v.build()))}return n},e.suppressDeleteMatch=function(e,r,t,a,l,n){var i,s,o,u,d=mutable_1.BuilderProvider.getSnapshotBuilder(l),c=mutable_1.BuilderProvider.getSnapshotBuilder(l);if(0!=e.getSuppressMatch().length)try{for(var _=tslib_1.__values(e.getSuppressMatch()),v=_.next();!v.done;v=_.next()){var h=v.value,f=mutable_1.BuilderProvider.getMatchBuilder(l.match(h.split("_")[0]));d.deleteChild(f.build())}}catch(e){i={error:e}}finally{try{v&&!v.done&&(s=_.return)&&s.call(_)}finally{if(i)throw i.error}}if(0!=e.getDeleteMatch().length)try{for(var T=tslib_1.__values(e.getDeleteMatch()),p=T.next();!p.done;p=T.next()){h=p.value,f=mutable_1.BuilderProvider.getMatchBuilder(l.match(h.split("_")[0]));c.deleteChild(f.build())}}catch(e){o={error:e}}finally{try{p&&!p.done&&(u=T.return)&&u.call(T)}finally{if(o)throw o.error}}return 0!=d.build().matches().length&&n.push(new data_structure_1.Incoming(r.DATA_DELETE_MATCH(),a,d.build())),n},e}();exports.DeltaTransformingLogicImpl=DeltaTransformingLogicImpl;
@@ -1 +1 @@
1
- var __createBinding=this&&this.__createBinding||(Object.create?function(e,s,t,r){void 0===r&&(r=t);var a=Object.getOwnPropertyDescriptor(s,t);a&&("get"in a?s.__esModule:!a.writable&&!a.configurable)||(a={enumerable:!0,get:function(){return s[t]}}),Object.defineProperty(e,r,a)}:function(e,s,t,r){e[r=void 0===r?t:r]=s[t]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,s){Object.defineProperty(e,"default",{enumerable:!0,value:s})}:function(e,s){e.default=s}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var s={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&__createBinding(s,e,t);return __setModuleDefault(s,e),s};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SportsFeedMessageGroup=exports.RefreshMessageClass=exports.StartSubscribeFeed=exports.SwitchFilterFailMessageClass=exports.SwitchFilterEndMessageClass=exports.SwitchFilterStartMessageClass=exports.TTLRestoreMessageClass=exports.TTLRemoveMessageClass=exports.ResetMessageClass=exports.DeleteOddMessageClass=exports.DeleteEventMessageClass=exports.DeleteMatchMessageClass=exports.UpdateOddMessageClass=exports.UpdateEventMessageClass=exports.UpdateMatchMessageClass=exports.InsertOddMessageClass=exports.InsertEventMessageClass=exports.InsertMatchMessageClass=exports.PartitionCodec=exports.SportsCodecs=exports.FilterMessageClass=exports.AbstractMessageClass=void 0;let deliver=require("@jayesol/jayeson.lib.delivery"),jayeson_lib_record_1=require("@jayesol/jayeson.lib.record"),data_structure_1=require("./data_structure"),proto=__importStar(require("./protobuf_bundle")),Collections=__importStar(require("typescript-collections")),codec_1=require("./codec"),soccer_codec_1=require("./soccer_codec"),basketball_codec_1=require("./basketball_codec"),tennis_codec_1=require("./tennis_codec");class AbstractMessageClass extends deliver.IMessageClass{constructor(e,s,t,r,a){super(e,s,t),this._msgGroup=e,this._id=s,this._instanceClass=t,this._sportCodecs=r,this._partitionCodec=a,this.unpack=e=>{var s,t,r=proto.DataMessage.decode(e.message),a=(e.message=new data_structure_1.IndexedSnapshotImpl({}),r.stringPool),o=r.feedKey;void 0!==o&&null!=(s=this.asSportType(o.sport))&&null!=(t=this._sportCodecs.getCodec(s))&&(o=this._partitionCodec.decode(new proto.PartitionKey(o),a),r=this.read(r,t,a,o),(t={})[s]=r,(a=new Collections.Dictionary).setValue(o,(new Date).getTime()),e.message=new data_structure_1.IndexedSnapshotImpl(t,a))}}id(){return this._id}SportsFeedMessageGroup(){return this._msgGroup}instanceClass(){return this._instanceClass}sportCodecs(){return this._sportCodecs}partitionCodec(){return this._partitionCodec}inHandlers(){return[{unpack:this.unpack}]}outHandlers(){return[]}asSportType(e){e=proto.SportType[e];return jayeson_lib_record_1.SportType[e]}}exports.AbstractMessageClass=AbstractMessageClass;class FilterMessageClass extends deliver.JSonMessageClass{constructor(e,s){super(e,s,codec_1.FilterRequest)}}exports.FilterMessageClass=FilterMessageClass;class SportsCodecs{constructor(e=void 0){void 0===(this.sportsMappings=e)&&(this.sportsMappings=new Collections.Dictionary,this.sportsMappings.setValue(jayeson_lib_record_1.SportType.SOCCER,new soccer_codec_1.SoccerCodec),this.sportsMappings.setValue(jayeson_lib_record_1.SportType.TENNIS,new tennis_codec_1.TennisCodec),this.sportsMappings.setValue(jayeson_lib_record_1.SportType.BASKETBALL,new basketball_codec_1.BasketballCodec))}getCodec(e){return this.sportsMappings.getValue(e)}}exports.SportsCodecs=SportsCodecs;class PartitionCodec{decode(e,s){let t=jayeson_lib_record_1.OddType.LIVE;switch(e.oddType){case proto.OddType.LIVE:t=jayeson_lib_record_1.OddType.LIVE;break;case proto.OddType.TODAY:t=jayeson_lib_record_1.OddType.TODAY;break;case proto.OddType.EARLY:t=jayeson_lib_record_1.OddType.EARLY}let r=jayeson_lib_record_1.SportType.SOCCER;switch(e.sport){case proto.SportType.SOCCER:r=jayeson_lib_record_1.SportType.SOCCER;break;case proto.SportType.BASKETBALL:r=jayeson_lib_record_1.SportType.BASKETBALL;break;case proto.SportType.HOCKEY:r=jayeson_lib_record_1.SportType.HOCKEY;break;case proto.SportType.TENNIS:r=jayeson_lib_record_1.SportType.TENNIS;break;case proto.SportType.HORSE_RACING:r=jayeson_lib_record_1.SportType.HORSE_RACING;break;case proto.SportType.MOTOR_SPORT:r=jayeson_lib_record_1.SportType.MOTOR_SPORT;break;case proto.SportType.HANDBALL:r=jayeson_lib_record_1.SportType.HANDBALL;break;case proto.SportType.CRICKET:r=jayeson_lib_record_1.SportType.CRICKET;break;case proto.SportType.POOL:r=jayeson_lib_record_1.SportType.POOL}return new jayeson_lib_record_1.PartitionKey(s[e.source],t,r)}}exports.PartitionCodec=PartitionCodec;class InsertMatchMessageClass extends AbstractMessageClass{constructor(e,s,t,r){super(e,s,data_structure_1.IndexedSnapshotImpl,t,r)}read(e,s,t,r){e=e.matches.matches.map(e=>new proto.BaseMatch(e));return s.decodeMatch(e,t,codec_1.EncodeAction.INSERT,r)}}exports.InsertMatchMessageClass=InsertMatchMessageClass;class InsertEventMessageClass extends AbstractMessageClass{constructor(e,s,t,r){super(e,s,data_structure_1.IndexedSnapshotImpl,t,r)}read(e,s,t,r){e=e.events.events.map(e=>new proto.BaseEvent(e));return s.decodeEvent(e,t,codec_1.EncodeAction.INSERT,r)}}exports.InsertEventMessageClass=InsertEventMessageClass;class InsertOddMessageClass extends AbstractMessageClass{constructor(e,s,t,r){super(e,s,data_structure_1.IndexedSnapshotImpl,t,r)}read(e,s,t,r){e=e.odds.odds.map(e=>new proto.BaseRecord(e));return s.decodeRecord(e,t,codec_1.EncodeAction.INSERT,r)}}exports.InsertOddMessageClass=InsertOddMessageClass;class UpdateMatchMessageClass extends AbstractMessageClass{constructor(e,s,t,r){super(e,s,data_structure_1.IndexedSnapshotImpl,t,r)}read(e,s,t,r){e=e.matches.matches.map(e=>new proto.BaseMatch(e));return s.decodeMatch(e,t,codec_1.EncodeAction.UPDATE,r)}}exports.UpdateMatchMessageClass=UpdateMatchMessageClass;class UpdateEventMessageClass extends AbstractMessageClass{constructor(e,s,t,r){super(e,s,data_structure_1.IndexedSnapshotImpl,t,r)}read(e,s,t,r){e=e.events.events.map(e=>new proto.BaseEvent(e));return s.decodeEvent(e,t,codec_1.EncodeAction.UPDATE,r)}}exports.UpdateEventMessageClass=UpdateEventMessageClass;class UpdateOddMessageClass extends AbstractMessageClass{constructor(e,s,t,r){super(e,s,data_structure_1.IndexedSnapshotImpl,t,r)}read(e,s,t,r){e=e.odds.odds.map(e=>new proto.BaseRecord(e));return s.decodeRecord(e,t,codec_1.EncodeAction.UPDATE,r)}}exports.UpdateOddMessageClass=UpdateOddMessageClass;class DeleteMatchMessageClass extends AbstractMessageClass{constructor(e,s,t,r){super(e,s,data_structure_1.IndexedSnapshotImpl,t,r)}read(e,s,t,r){e=e.matches.matches.map(e=>new proto.BaseMatch(e));return s.decodeMatch(e,t,codec_1.EncodeAction.DELETE,r)}}exports.DeleteMatchMessageClass=DeleteMatchMessageClass;class DeleteEventMessageClass extends AbstractMessageClass{constructor(e,s,t,r){super(e,s,data_structure_1.IndexedSnapshotImpl,t,r)}read(e,s,t,r){e=e.events.events.map(e=>new proto.BaseEvent(e));return s.decodeEvent(e,t,codec_1.EncodeAction.DELETE,r)}}exports.DeleteEventMessageClass=DeleteEventMessageClass;class DeleteOddMessageClass extends AbstractMessageClass{constructor(e,s,t,r){super(e,s,data_structure_1.IndexedSnapshotImpl,t,r)}read(e,s,t,r){e=e.odds.odds.map(e=>new proto.BaseRecord(e));return s.decodeRecord(e,t,codec_1.EncodeAction.DELETE,r)}}exports.DeleteOddMessageClass=DeleteOddMessageClass;class ResetMessageClass extends AbstractMessageClass{constructor(e,s,t,r){super(e,s,data_structure_1.IndexedSnapshotImpl,t,r)}read(e,s,t,r){return[]}}exports.ResetMessageClass=ResetMessageClass;class TTLRemoveMessageClass extends AbstractMessageClass{constructor(e,s,t,r){super(e,s,data_structure_1.IndexedSnapshotImpl,t,r)}read(e,s,t,r){return[]}}exports.TTLRemoveMessageClass=TTLRemoveMessageClass;class TTLRestoreMessageClass extends AbstractMessageClass{constructor(e,s,t,r){super(e,s,data_structure_1.IndexedSnapshotImpl,t,r)}read(e,s,t,r){return[]}}exports.TTLRestoreMessageClass=TTLRestoreMessageClass;class SwitchFilterStartMessageClass extends deliver.EmptyMessageClass{constructor(e,s){super(e,s)}}exports.SwitchFilterStartMessageClass=SwitchFilterStartMessageClass;class SwitchFilterEndMessageClass extends deliver.EmptyMessageClass{constructor(e,s){super(e,s)}}exports.SwitchFilterEndMessageClass=SwitchFilterEndMessageClass;class SwitchFilterFailMessageClass extends deliver.EmptyMessageClass{constructor(e,s){super(e,s)}}exports.SwitchFilterFailMessageClass=SwitchFilterFailMessageClass;class StartSubscribeFeed{constructor(e,s){this.exclude=e,this.wireFormat=s}}exports.StartSubscribeFeed=StartSubscribeFeed;class RefreshMessage{}class RefreshMessageClass extends deliver.JSonMessageClass{constructor(e,s){super(e,s,RefreshMessage),this.unpack=e=>{var s=e.message;let t=new Collections.Dictionary;s.partitionKeys.forEach(e=>{t.setValue(jayeson_lib_record_1.PartitionKey.fromString(e),(new Date).getTime())}),e.message=new data_structure_1.IndexedSnapshotImpl({},t)}}inHandlers(){return super.inHandlers().concat([{unpack:this.unpack}])}}exports.RefreshMessageClass=RefreshMessageClass;class SportsFeedMessageGroup extends deliver.IMessageGroup{DATA_RESET(){return this._DATA_RESET}DATA_INSERT_ODD(){return this._DATA_INSERT_ODD}DATA_UPDATE_ODD(){return this._DATA_UPDATE_ODD}DATA_DELETE_ODD(){return this._DATA_DELETE_ODD}DATA_INSERT_EVENT(){return this._DATA_INSERT_EVENT}DATA_UPDATE_EVENT(){return this._DATA_UPDATE_EVENT}DATA_DELETE_EVENT(){return this._DATA_DELETE_EVENT}TTL_REMOVE(){return this._TTL_REMOVE}TTL_RESTORE(){return this._TTL_RESTORE}TTL_RESTORE_START(){return this._TTL_RESTORE_START}TTL_RESTORE_END(){return this._TTL_RESTORE_END}DATA_INSERT_MATCH(){return this._DATA_INSERT_MATCH}DATA_UPDATE_MATCH(){return this._DATA_UPDATE_MATCH}DATA_DELETE_MATCH(){return this._DATA_DELETE_MATCH}FILTER_REMOVE(){return this._FILTER_REMOVE}FILTER_SET(){return this._FILTER_SET}ADMIN_START_SUBSCRIBE_FEED(){return this._ADMIN_START_SUBSCRIBE_FEED}ADMIN_REFRESH(){return this._ADMIN_REFRESH}SWITCH_FILTER_START(){return this._SWITCH_FILTER_START}SWITCH_FILTER_END(){return this._SWITCH_FILTER_END}FULLSNAPSHOT_START(){return this._FULLSNAPSHOT_START}FULLSNAPSHOT_END(){return this._FULLSNAPSHOT_END}SWITCH_FILTER_FAIL(){return this._SWITCH_FILTER_FAIL}isIndicatorMessage(e){return e==this.SWITCH_FILTER_START()||e==this.SWITCH_FILTER_END()||e==this.FULLSNAPSHOT_START()||e==this.FULLSNAPSHOT_END()||e==this.SWITCH_FILTER_FAIL()||e==this.TTL_RESTORE_START()||e==this.TTL_RESTORE_END()}isSwitchFilterStatusMsg(e){return e==this.SWITCH_FILTER_START()||e==this.SWITCH_FILTER_FAIL()}constructor(e=new SportsCodecs,s=new PartitionCodec){super(70),this._DATA_RESET=new ResetMessageClass(this,0,e,s),this._DATA_INSERT_ODD=new InsertOddMessageClass(this,1,e,s),this._DATA_UPDATE_ODD=new UpdateOddMessageClass(this,2,e,s),this._DATA_DELETE_ODD=new DeleteOddMessageClass(this,3,e,s),this._DATA_INSERT_EVENT=new InsertEventMessageClass(this,4,e,s),this._DATA_UPDATE_EVENT=new UpdateEventMessageClass(this,5,e,s),this._DATA_DELETE_EVENT=new DeleteEventMessageClass(this,6,e,s),this._DATA_INSERT_MATCH=new InsertMatchMessageClass(this,7,e,s),this._DATA_UPDATE_MATCH=new UpdateMatchMessageClass(this,8,e,s),this._DATA_DELETE_MATCH=new DeleteMatchMessageClass(this,9,e,s),this._TTL_RESTORE=new TTLRestoreMessageClass(this,10,e,s),this._TTL_REMOVE=new TTLRestoreMessageClass(this,11,e,s),this._FILTER_REMOVE=new deliver.StringMessageClass(this,13),this._FILTER_SET=new FilterMessageClass(this,14),this._ADMIN_START_SUBSCRIBE_FEED=new deliver.JSonMessageClass(this,16,StartSubscribeFeed),this._ADMIN_REFRESH=new RefreshMessageClass(this,17),this._SWITCH_FILTER_START=new deliver.StringMessageClass(this,18),this._SWITCH_FILTER_END=new deliver.EmptyMessageClass(this,19),this._FULLSNAPSHOT_START=new deliver.EmptyMessageClass(this,20),this._FULLSNAPSHOT_END=new deliver.EmptyMessageClass(this,21),this._SWITCH_FILTER_FAIL=new deliver.StringMessageClass(this,22),this._TTL_RESTORE_START=new TTLRestoreMessageClass(this,23,e,s),this._TTL_RESTORE_END=new deliver.EmptyMessageClass(this,24),[this._DATA_RESET,this._DATA_INSERT_ODD,this._DATA_UPDATE_ODD,this._DATA_DELETE_ODD,this._DATA_INSERT_EVENT,this._DATA_UPDATE_EVENT,this._DATA_DELETE_EVENT,this._DATA_INSERT_MATCH,this._DATA_UPDATE_MATCH,this._DATA_DELETE_MATCH,this._TTL_RESTORE,this._TTL_REMOVE,this._FILTER_REMOVE,this._FILTER_SET,this._ADMIN_START_SUBSCRIBE_FEED,this._ADMIN_REFRESH,this._SWITCH_FILTER_START,this._SWITCH_FILTER_END,this._FULLSNAPSHOT_START,this._FULLSNAPSHOT_END,this._SWITCH_FILTER_FAIL,this._TTL_RESTORE_START,this._TTL_RESTORE_END].forEach(e=>{this._classes[e.id()]=e})}}exports.SportsFeedMessageGroup=SportsFeedMessageGroup;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SportsFeedMessageGroup=exports.RefreshMessageClass=exports.StartSubscribeFeed=exports.SwitchFilterFailMessageClass=exports.SwitchFilterEndMessageClass=exports.SwitchFilterStartMessageClass=exports.TTLRestoreMessageClass=exports.TTLRemoveMessageClass=exports.ResetMessageClass=exports.DeleteOddMessageClass=exports.DeleteEventMessageClass=exports.DeleteMatchMessageClass=exports.UpdateOddMessageClass=exports.UpdateEventMessageClass=exports.UpdateMatchMessageClass=exports.InsertOddMessageClass=exports.InsertEventMessageClass=exports.InsertMatchMessageClass=exports.PartitionCodec=exports.SportsCodecs=exports.FilterMessageClass=exports.AbstractMessageClass=void 0;var tslib_1=require("tslib"),deliver=require("@jayesol/jayeson.lib.delivery"),jayeson_lib_record_1=require("@jayesol/jayeson.lib.record"),data_structure_1=require("./data_structure"),proto=tslib_1.__importStar(require("./protobuf_bundle")),Collections=tslib_1.__importStar(require("typescript-collections")),codec_1=require("./codec"),soccer_codec_1=require("./soccer_codec"),basketball_codec_1=require("./basketball_codec"),tennis_codec_1=require("./tennis_codec"),AbstractMessageClass=function(e){function s(s,t,r,a,o){var n=e.call(this,s,t,r)||this;return n._msgGroup=s,n._id=t,n._instanceClass=r,n._sportCodecs=a,n._partitionCodec=o,n.unpack=function(e){var s=proto.DataMessage.decode(e.message);e.message=new data_structure_1.IndexedSnapshotImpl({});var t=s.stringPool,r=s.feedKey;if(void 0!==r){var a=n.asSportType(r.sport);if(null!=a){var o=n._sportCodecs.getCodec(a);if(null!=o){var _=n._partitionCodec.decode(new proto.PartitionKey(r),t),i=n.read(s,o,t,_),c={};c[a]=i;var p=new Collections.Dictionary;p.setValue(_,(new Date).getTime()),e.message=new data_structure_1.IndexedSnapshotImpl(c,p)}}}},n}return tslib_1.__extends(s,e),s.prototype.id=function(){return this._id},s.prototype.SportsFeedMessageGroup=function(){return this._msgGroup},s.prototype.instanceClass=function(){return this._instanceClass},s.prototype.sportCodecs=function(){return this._sportCodecs},s.prototype.partitionCodec=function(){return this._partitionCodec},s.prototype.inHandlers=function(){return[{unpack:this.unpack}]},s.prototype.outHandlers=function(){return[]},s.prototype.asSportType=function(e){var s=proto.SportType[e];return jayeson_lib_record_1.SportType[s]},s}(deliver.IMessageClass);exports.AbstractMessageClass=AbstractMessageClass;var FilterMessageClass=function(e){function s(s,t){return e.call(this,s,t,codec_1.FilterRequest)||this}return tslib_1.__extends(s,e),s}(deliver.JSonMessageClass);exports.FilterMessageClass=FilterMessageClass;var SportsCodecs=function(){function e(e){void 0===e&&(e=void 0),this.sportsMappings=e,void 0===e&&(this.sportsMappings=new Collections.Dictionary,this.sportsMappings.setValue(jayeson_lib_record_1.SportType.SOCCER,new soccer_codec_1.SoccerCodec),this.sportsMappings.setValue(jayeson_lib_record_1.SportType.TENNIS,new tennis_codec_1.TennisCodec),this.sportsMappings.setValue(jayeson_lib_record_1.SportType.BASKETBALL,new basketball_codec_1.BasketballCodec))}return e.prototype.getCodec=function(e){return this.sportsMappings.getValue(e)},e}();exports.SportsCodecs=SportsCodecs;var PartitionCodec=function(){function e(){}return e.prototype.decode=function(e,s){var t=jayeson_lib_record_1.OddType.LIVE;switch(e.oddType){case proto.OddType.LIVE:t=jayeson_lib_record_1.OddType.LIVE;break;case proto.OddType.TODAY:t=jayeson_lib_record_1.OddType.TODAY;break;case proto.OddType.EARLY:t=jayeson_lib_record_1.OddType.EARLY}var r=jayeson_lib_record_1.SportType.SOCCER;switch(e.sport){case proto.SportType.SOCCER:r=jayeson_lib_record_1.SportType.SOCCER;break;case proto.SportType.BASKETBALL:r=jayeson_lib_record_1.SportType.BASKETBALL;break;case proto.SportType.HOCKEY:r=jayeson_lib_record_1.SportType.HOCKEY;break;case proto.SportType.TENNIS:r=jayeson_lib_record_1.SportType.TENNIS;break;case proto.SportType.HORSE_RACING:r=jayeson_lib_record_1.SportType.HORSE_RACING;break;case proto.SportType.MOTOR_SPORT:r=jayeson_lib_record_1.SportType.MOTOR_SPORT;break;case proto.SportType.HANDBALL:r=jayeson_lib_record_1.SportType.HANDBALL;break;case proto.SportType.CRICKET:r=jayeson_lib_record_1.SportType.CRICKET;break;case proto.SportType.POOL:r=jayeson_lib_record_1.SportType.POOL}return new jayeson_lib_record_1.PartitionKey(s[e.source],t,r)},e}();exports.PartitionCodec=PartitionCodec;var InsertMatchMessageClass=function(e){function s(s,t,r,a){return e.call(this,s,t,data_structure_1.IndexedSnapshotImpl,r,a)||this}return tslib_1.__extends(s,e),s.prototype.read=function(e,s,t,r){var a=e.matches.matches.map(function(e){return new proto.BaseMatch(e)});return s.decodeMatch(a,t,codec_1.EncodeAction.INSERT,r)},s}(AbstractMessageClass);exports.InsertMatchMessageClass=InsertMatchMessageClass;var InsertEventMessageClass=function(e){function s(s,t,r,a){return e.call(this,s,t,data_structure_1.IndexedSnapshotImpl,r,a)||this}return tslib_1.__extends(s,e),s.prototype.read=function(e,s,t,r){var a=e.events.events.map(function(e){return new proto.BaseEvent(e)});return s.decodeEvent(a,t,codec_1.EncodeAction.INSERT,r)},s}(AbstractMessageClass);exports.InsertEventMessageClass=InsertEventMessageClass;var InsertOddMessageClass=function(e){function s(s,t,r,a){return e.call(this,s,t,data_structure_1.IndexedSnapshotImpl,r,a)||this}return tslib_1.__extends(s,e),s.prototype.read=function(e,s,t,r){var a=e.odds.odds.map(function(e){return new proto.BaseRecord(e)});return s.decodeRecord(a,t,codec_1.EncodeAction.INSERT,r)},s}(AbstractMessageClass);exports.InsertOddMessageClass=InsertOddMessageClass;var UpdateMatchMessageClass=function(e){function s(s,t,r,a){return e.call(this,s,t,data_structure_1.IndexedSnapshotImpl,r,a)||this}return tslib_1.__extends(s,e),s.prototype.read=function(e,s,t,r){var a=e.matches.matches.map(function(e){return new proto.BaseMatch(e)});return s.decodeMatch(a,t,codec_1.EncodeAction.UPDATE,r)},s}(AbstractMessageClass);exports.UpdateMatchMessageClass=UpdateMatchMessageClass;var UpdateEventMessageClass=function(e){function s(s,t,r,a){return e.call(this,s,t,data_structure_1.IndexedSnapshotImpl,r,a)||this}return tslib_1.__extends(s,e),s.prototype.read=function(e,s,t,r){var a=e.events.events.map(function(e){return new proto.BaseEvent(e)});return s.decodeEvent(a,t,codec_1.EncodeAction.UPDATE,r)},s}(AbstractMessageClass);exports.UpdateEventMessageClass=UpdateEventMessageClass;var UpdateOddMessageClass=function(e){function s(s,t,r,a){return e.call(this,s,t,data_structure_1.IndexedSnapshotImpl,r,a)||this}return tslib_1.__extends(s,e),s.prototype.read=function(e,s,t,r){var a=e.odds.odds.map(function(e){return new proto.BaseRecord(e)});return s.decodeRecord(a,t,codec_1.EncodeAction.UPDATE,r)},s}(AbstractMessageClass);exports.UpdateOddMessageClass=UpdateOddMessageClass;var DeleteMatchMessageClass=function(e){function s(s,t,r,a){return e.call(this,s,t,data_structure_1.IndexedSnapshotImpl,r,a)||this}return tslib_1.__extends(s,e),s.prototype.read=function(e,s,t,r){var a=e.matches.matches.map(function(e){return new proto.BaseMatch(e)});return s.decodeMatch(a,t,codec_1.EncodeAction.DELETE,r)},s}(AbstractMessageClass);exports.DeleteMatchMessageClass=DeleteMatchMessageClass;var DeleteEventMessageClass=function(e){function s(s,t,r,a){return e.call(this,s,t,data_structure_1.IndexedSnapshotImpl,r,a)||this}return tslib_1.__extends(s,e),s.prototype.read=function(e,s,t,r){var a=e.events.events.map(function(e){return new proto.BaseEvent(e)});return s.decodeEvent(a,t,codec_1.EncodeAction.DELETE,r)},s}(AbstractMessageClass);exports.DeleteEventMessageClass=DeleteEventMessageClass;var DeleteOddMessageClass=function(e){function s(s,t,r,a){return e.call(this,s,t,data_structure_1.IndexedSnapshotImpl,r,a)||this}return tslib_1.__extends(s,e),s.prototype.read=function(e,s,t,r){var a=e.odds.odds.map(function(e){return new proto.BaseRecord(e)});return s.decodeRecord(a,t,codec_1.EncodeAction.DELETE,r)},s}(AbstractMessageClass);exports.DeleteOddMessageClass=DeleteOddMessageClass;var ResetMessageClass=function(e){function s(s,t,r,a){return e.call(this,s,t,data_structure_1.IndexedSnapshotImpl,r,a)||this}return tslib_1.__extends(s,e),s.prototype.read=function(e,s,t,r){return[]},s}(AbstractMessageClass);exports.ResetMessageClass=ResetMessageClass;var TTLRemoveMessageClass=function(e){function s(s,t,r,a){return e.call(this,s,t,data_structure_1.IndexedSnapshotImpl,r,a)||this}return tslib_1.__extends(s,e),s.prototype.read=function(e,s,t,r){return[]},s}(AbstractMessageClass);exports.TTLRemoveMessageClass=TTLRemoveMessageClass;var TTLRestoreMessageClass=function(e){function s(s,t,r,a){return e.call(this,s,t,data_structure_1.IndexedSnapshotImpl,r,a)||this}return tslib_1.__extends(s,e),s.prototype.read=function(e,s,t,r){return[]},s}(AbstractMessageClass);exports.TTLRestoreMessageClass=TTLRestoreMessageClass;var SwitchFilterStartMessageClass=function(e){function s(s,t){return e.call(this,s,t)||this}return tslib_1.__extends(s,e),s}(deliver.EmptyMessageClass);exports.SwitchFilterStartMessageClass=SwitchFilterStartMessageClass;var SwitchFilterEndMessageClass=function(e){function s(s,t){return e.call(this,s,t)||this}return tslib_1.__extends(s,e),s}(deliver.EmptyMessageClass);exports.SwitchFilterEndMessageClass=SwitchFilterEndMessageClass;var SwitchFilterFailMessageClass=function(e){function s(s,t){return e.call(this,s,t)||this}return tslib_1.__extends(s,e),s}(deliver.EmptyMessageClass);exports.SwitchFilterFailMessageClass=SwitchFilterFailMessageClass;var StartSubscribeFeed=function(e,s){this.exclude=e,this.wireFormat=s};exports.StartSubscribeFeed=StartSubscribeFeed;var RefreshMessage=function(){},RefreshMessageClass=function(e){function s(s,t){var r=e.call(this,s,t,RefreshMessage)||this;return r.unpack=function(e){var s=e.message,t=new Collections.Dictionary;s.partitionKeys.forEach(function(e){t.setValue(jayeson_lib_record_1.PartitionKey.fromString(e),(new Date).getTime())}),e.message=new data_structure_1.IndexedSnapshotImpl({},t)},r}return tslib_1.__extends(s,e),s.prototype.inHandlers=function(){return e.prototype.inHandlers.call(this).concat([{unpack:this.unpack}])},s}(deliver.JSonMessageClass);exports.RefreshMessageClass=RefreshMessageClass;var SportsFeedMessageGroup=function(e){function s(s,t){void 0===s&&(s=new SportsCodecs),void 0===t&&(t=new PartitionCodec);var r=e.call(this,70)||this;return r._DATA_RESET=new ResetMessageClass(r,0,s,t),r._DATA_INSERT_ODD=new InsertOddMessageClass(r,1,s,t),r._DATA_UPDATE_ODD=new UpdateOddMessageClass(r,2,s,t),r._DATA_DELETE_ODD=new DeleteOddMessageClass(r,3,s,t),r._DATA_INSERT_EVENT=new InsertEventMessageClass(r,4,s,t),r._DATA_UPDATE_EVENT=new UpdateEventMessageClass(r,5,s,t),r._DATA_DELETE_EVENT=new DeleteEventMessageClass(r,6,s,t),r._DATA_INSERT_MATCH=new InsertMatchMessageClass(r,7,s,t),r._DATA_UPDATE_MATCH=new UpdateMatchMessageClass(r,8,s,t),r._DATA_DELETE_MATCH=new DeleteMatchMessageClass(r,9,s,t),r._TTL_RESTORE=new TTLRestoreMessageClass(r,10,s,t),r._TTL_REMOVE=new TTLRestoreMessageClass(r,11,s,t),r._FILTER_REMOVE=new deliver.StringMessageClass(r,13),r._FILTER_SET=new FilterMessageClass(r,14),r._ADMIN_START_SUBSCRIBE_FEED=new deliver.JSonMessageClass(r,16,StartSubscribeFeed),r._ADMIN_REFRESH=new RefreshMessageClass(r,17),r._SWITCH_FILTER_START=new deliver.StringMessageClass(r,18),r._SWITCH_FILTER_END=new deliver.EmptyMessageClass(r,19),r._FULLSNAPSHOT_START=new deliver.EmptyMessageClass(r,20),r._FULLSNAPSHOT_END=new deliver.EmptyMessageClass(r,21),r._SWITCH_FILTER_FAIL=new deliver.StringMessageClass(r,22),r._TTL_RESTORE_START=new TTLRestoreMessageClass(r,23,s,t),r._TTL_RESTORE_END=new deliver.EmptyMessageClass(r,24),[r._DATA_RESET,r._DATA_INSERT_ODD,r._DATA_UPDATE_ODD,r._DATA_DELETE_ODD,r._DATA_INSERT_EVENT,r._DATA_UPDATE_EVENT,r._DATA_DELETE_EVENT,r._DATA_INSERT_MATCH,r._DATA_UPDATE_MATCH,r._DATA_DELETE_MATCH,r._TTL_RESTORE,r._TTL_REMOVE,r._FILTER_REMOVE,r._FILTER_SET,r._ADMIN_START_SUBSCRIBE_FEED,r._ADMIN_REFRESH,r._SWITCH_FILTER_START,r._SWITCH_FILTER_END,r._FULLSNAPSHOT_START,r._FULLSNAPSHOT_END,r._SWITCH_FILTER_FAIL,r._TTL_RESTORE_START,r._TTL_RESTORE_END].forEach(function(e){r._classes[e.id()]=e}),r}return tslib_1.__extends(s,e),s.prototype.DATA_RESET=function(){return this._DATA_RESET},s.prototype.DATA_INSERT_ODD=function(){return this._DATA_INSERT_ODD},s.prototype.DATA_UPDATE_ODD=function(){return this._DATA_UPDATE_ODD},s.prototype.DATA_DELETE_ODD=function(){return this._DATA_DELETE_ODD},s.prototype.DATA_INSERT_EVENT=function(){return this._DATA_INSERT_EVENT},s.prototype.DATA_UPDATE_EVENT=function(){return this._DATA_UPDATE_EVENT},s.prototype.DATA_DELETE_EVENT=function(){return this._DATA_DELETE_EVENT},s.prototype.TTL_REMOVE=function(){return this._TTL_REMOVE},s.prototype.TTL_RESTORE=function(){return this._TTL_RESTORE},s.prototype.TTL_RESTORE_START=function(){return this._TTL_RESTORE_START},s.prototype.TTL_RESTORE_END=function(){return this._TTL_RESTORE_END},s.prototype.DATA_INSERT_MATCH=function(){return this._DATA_INSERT_MATCH},s.prototype.DATA_UPDATE_MATCH=function(){return this._DATA_UPDATE_MATCH},s.prototype.DATA_DELETE_MATCH=function(){return this._DATA_DELETE_MATCH},s.prototype.FILTER_REMOVE=function(){return this._FILTER_REMOVE},s.prototype.FILTER_SET=function(){return this._FILTER_SET},s.prototype.ADMIN_START_SUBSCRIBE_FEED=function(){return this._ADMIN_START_SUBSCRIBE_FEED},s.prototype.ADMIN_REFRESH=function(){return this._ADMIN_REFRESH},s.prototype.SWITCH_FILTER_START=function(){return this._SWITCH_FILTER_START},s.prototype.SWITCH_FILTER_END=function(){return this._SWITCH_FILTER_END},s.prototype.FULLSNAPSHOT_START=function(){return this._FULLSNAPSHOT_START},s.prototype.FULLSNAPSHOT_END=function(){return this._FULLSNAPSHOT_END},s.prototype.SWITCH_FILTER_FAIL=function(){return this._SWITCH_FILTER_FAIL},s.prototype.isIndicatorMessage=function(e){return e==this.SWITCH_FILTER_START()||e==this.SWITCH_FILTER_END()||e==this.FULLSNAPSHOT_START()||e==this.FULLSNAPSHOT_END()||e==this.SWITCH_FILTER_FAIL()||e==this.TTL_RESTORE_START()||e==this.TTL_RESTORE_END()},s.prototype.isSwitchFilterStatusMsg=function(e){return e==this.SWITCH_FILTER_START()||e==this.SWITCH_FILTER_FAIL()},s}(deliver.IMessageGroup);exports.SportsFeedMessageGroup=SportsFeedMessageGroup;
package/lib/module.js CHANGED
@@ -1 +1 @@
1
- var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var s=Object.getOwnPropertyDescriptor(r,t);s&&("get"in s?r.__esModule:!s.writable&&!s.configurable)||(s={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,s)}:function(e,r,t,o){e[o=void 0===o?t:o]=r[t]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&__createBinding(r,e,t);return __setModuleDefault(r,e),r};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SportsFeedCoreService=exports.SportsFeedCoreComponentModule=void 0;let D=__importStar(require("@jayesol/jayeson.lib.delivery")),injection_js_1=require("injection-js"),message_class_1=require("./message_class"),receive_1=require("./receive"),core_1=require("./core"),dispatch_1=require("./dispatch"),client_1=require("./client");class SportsFeedCoreComponentModule{static getBindingArray(e=[],r="",t=client_1.MemoryDispatcher.MEMORY_STREAM){return[{provide:message_class_1.StartSubscribeFeed,useValue:new message_class_1.StartSubscribeFeed(e,r)},{provide:message_class_1.SportsFeedMessageGroup,useValue:new message_class_1.SportsFeedMessageGroup},{provide:D.StreamNameCode,useClass:D.StreamNameCode},{provide:receive_1.InEndPointEventHandler,useClass:receive_1.InEndPointEventHandler},{provide:core_1.FSRepoImpl.outputStream,useValue:t},core_1.FSRepoImpl,{provide:core_1.AbstractFSRepo,useExisting:core_1.FSRepoImpl},{provide:core_1.FSREPO_IMPL,useExisting:core_1.FSRepoImpl},dispatch_1.RelayEPG,dispatch_1.EndPointGroupManager,core_1.TTLConfig,core_1.RecycleBin,receive_1.StreamCommandProcessor,receive_1.SportsFeedInProcessor,{provide:D.IMessageGroupProcessor,useExisting:receive_1.SportsFeedInProcessor},{provide:dispatch_1.EPGM_IMPL,useExisting:dispatch_1.EndPointGroupManager},client_1.FeedView,client_1.SportsFeedClient]}}exports.SportsFeedCoreComponentModule=SportsFeedCoreComponentModule;class SportsFeedCoreService{constructor(t,o){var e=injection_js_1.ReflectiveInjector.resolveAndCreate(SportsFeedCoreComponentModule.getBindingArray().concat([{provide:D.Subscriber,useFactory:function(e){var r=new D.SubscriberConfig;return r.streamFinder=t,r.discoveryPattern={70:[".*"]},r.processors={70:e},r.schemes=["ws","http","https","wss"],r.feedScope=o,new D.Subscriber(r)},deps:[receive_1.SportsFeedInProcessor]}]));this.client=e.get(client_1.SportsFeedClient),this.subscriber=e.get(D.Subscriber)}getClient(){return this.client}getSubscriber(){return this.subscriber}}exports.SportsFeedCoreService=SportsFeedCoreService;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SportsFeedCoreService=exports.SportsFeedCoreComponentModule=void 0;var tslib_1=require("tslib"),D=tslib_1.__importStar(require("@jayesol/jayeson.lib.delivery")),injection_js_1=require("injection-js"),message_class_1=require("./message_class"),receive_1=require("./receive"),core_1=require("./core"),dispatch_1=require("./dispatch"),client_1=require("./client"),SportsFeedCoreComponentModule=function(){function e(){}return e.getBindingArray=function(e,r,o){return void 0===e&&(e=[]),void 0===r&&(r=""),void 0===o&&(o=client_1.MemoryDispatcher.MEMORY_STREAM),[{provide:message_class_1.StartSubscribeFeed,useValue:new message_class_1.StartSubscribeFeed(e,r)},{provide:message_class_1.SportsFeedMessageGroup,useValue:new message_class_1.SportsFeedMessageGroup},{provide:D.StreamNameCode,useClass:D.StreamNameCode},{provide:receive_1.InEndPointEventHandler,useClass:receive_1.InEndPointEventHandler},{provide:core_1.FSRepoImpl.outputStream,useValue:o},core_1.FSRepoImpl,{provide:core_1.AbstractFSRepo,useExisting:core_1.FSRepoImpl},{provide:core_1.FSREPO_IMPL,useExisting:core_1.FSRepoImpl},dispatch_1.RelayEPG,dispatch_1.EndPointGroupManager,core_1.TTLConfig,core_1.RecycleBin,receive_1.StreamCommandProcessor,receive_1.SportsFeedInProcessor,{provide:D.IMessageGroupProcessor,useExisting:receive_1.SportsFeedInProcessor},{provide:dispatch_1.EPGM_IMPL,useExisting:dispatch_1.EndPointGroupManager},client_1.FeedView,client_1.SportsFeedClient]},e}();exports.SportsFeedCoreComponentModule=SportsFeedCoreComponentModule;var SportsFeedCoreService=function(){function e(e,r){var o=injection_js_1.ReflectiveInjector.resolveAndCreate(SportsFeedCoreComponentModule.getBindingArray().concat([{provide:D.Subscriber,useFactory:function(o){var s=new D.SubscriberConfig;return s.streamFinder=e,s.discoveryPattern={70:[".*"]},s.processors={70:o},s.schemes=["ws","http","https","wss"],s.feedScope=r,new D.Subscriber(s)},deps:[receive_1.SportsFeedInProcessor]}]));this.client=o.get(client_1.SportsFeedClient),this.subscriber=o.get(D.Subscriber)}return e.prototype.getClient=function(){return this.client},e.prototype.getSubscriber=function(){return this.subscriber},e}();exports.SportsFeedCoreService=SportsFeedCoreService;
package/lib/mutable.js CHANGED
@@ -1 +1 @@
1
- var Builder,__createBinding=this&&this.__createBinding||(Object.create?function(t,e,r,s){void 0===s&&(s=r);var i=Object.getOwnPropertyDescriptor(e,r);i&&("get"in i?e.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,s,i)}:function(t,e,r,s){t[s=void 0===s?r:s]=e[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),__importStar=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)"default"!==r&&Object.prototype.hasOwnProperty.call(t,r)&&__createBinding(e,t,r);return __setModuleDefault(e,t),e};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BuilderProvider=exports.B2RecordBuilder=exports.Const=void 0;let jayeson_lib_record_1=require("@jayesol/jayeson.lib.record"),data_structure_1=require("./data_structure"),codec_1=require("./codec"),Collections=__importStar(require("typescript-collections"));class Const{static generateKey(t){return t.source()+this.SEPARATOR+t.id()}}(exports.Const=Const).AGGREGATE_KEY="AGGREGATE_KEY",Const.SEPARATOR="_";class IndexedSnapshotBuilder{constructor(t){if(this._matches={},this._partitions=new Collections.Dictionary,null!=t){for(var e of t.matches())this._matches[e.id()]=e;for(var r of t.getPartitionMap().keys())this._partitions.setValue(r,t.getPartitionMap().getValue(r))}}matches(){return this._matches}partitions(){return this._partitions}setPartition(t){this._partitions=t}setPartitionValue(t,e){this._partitions.setValue(t,e)}removePartitionKey(t){return this._partitions.remove(t)}markPartitionAsUpdated(t,e){null==e&&(e=(new Date).getMilliseconds()),this._partitions.setValue(t,e)}replaceMatch(t){this._matches[t.id()]=t}reset(t){if(!this._partitions.containsKey(t))return null;var e,r=this._matches,s=BuilderProvider.getSnapshotBuilder(this.build()),i=(s._matches={},s._partitions.clear(),this.removePartitionKey(t));for(e in s.setPartitionValue(t,i),this._matches){var a=this._matches[e],n=BuilderProvider.getMatchBuilder(a),o=n.reset(t);null==o||o.isEmpty()||s.insertChild(o.build()),n.isEmpty()?delete r[a.id()]:r[a.id()]=n.build()}return this._matches=r,s}insertChild(t){var e=this._matches[t.id()];let r=null;return null==e?this._matches[t.id()]=t:(r=t.id(),(e=BuilderProvider.getMatchBuilder(e)).aggregateInsert(t),this._matches[t.id()]=e.build()),r}updateChild(t){var e=this._matches[t.id()];null==e?console.error("[UpdateMatch] Cannot found matchId %s to execute update match from %s",t.id(),t.meta()[Const.AGGREGATE_KEY]):((e=BuilderProvider.getMatchBuilder(e)).aggregateUpdate(t),this._matches[t.id()]=e.build())}deleteChild(t){var e=this._matches[t.id()];let r=null;if(null!=e)return(e=BuilderProvider.getMatchBuilder(e)).aggregateDelete(t)?delete this._matches[t.id()]:(this._matches[t.id()]=e.build(),r=t.id()),r;console.error("[DeleteMatch] Cannot found matchId %s to execute delete match from %s",t.id(),t.meta()[Const.AGGREGATE_KEY])}build(){var e,r={};for(e in this._matches){var s=this._matches[e];let t=r[s.sportType()];null==t&&(t=[],r[s.sportType()]=t),t.push(s)}return new data_structure_1.IndexedSnapshotImpl(r,this._partitions)}}class B2MatchBuilder{constructor(t){this._events={},this.mergeFrom(t)}meta(){return this._meta}startTime(){return this._startTime}events(){return this._events}id(){return this._id}league(){return this._league}sport(){return this._sport}meata(){return this._meta}p1(){return this._p1}p2(){return this._p2}setEvent(t){this._events=t}mergeFrom(t){for(var e in this._startTime=t.startTime(),this._id=t.id(),this._league=t.league(),this._sport=t.sportType(),this._meta={},t.meta())this._meta[e]=t.meta()[e];if(null!=t.events())for(var r of t.events())this._events[r.id()]=r;var s=t;this._p1=s.participantOne(),this._p2=s.participantTwo()}replaceEvent(t){this._events[t.id()]=t}reset(t){var e=t.toString(),r=this._meta[Const.AGGREGATE_KEY];if(!codec_1.Util.containsKey(r,e))return null;var s,i=BuilderProvider.getMatchBuilder(this.build()),r=codec_1.Util.removeKey(r,e),a=(this._meta[Const.AGGREGATE_KEY]=r,i._meta[Const.AGGREGATE_KEY]=e,{});for(s in i._events={},this._events){var n=this._events[s],o=BuilderProvider.getEventBuilder(n),d=o.reset(t);null==d||d.isEmpty()||i.insertChild(d.build()),o.isEmpty()?delete a[n.id()]:a[n.id()]=o.build()}return this._events=a,i}aggregateInsert(t){for(var e in t.meta())e!==Const.AGGREGATE_KEY&&(this._meta[e]=t.meta()[e]);var r=t.meta()[Const.AGGREGATE_KEY],s=this._meta[Const.AGGREGATE_KEY];this._meta[Const.AGGREGATE_KEY]=codec_1.Util.addKey(s,r)}aggregateUpdate(t){for(var e in t.meta())e!==Const.AGGREGATE_KEY&&(this._meta[e]=t.meta()[e])}aggregateDelete(t){var t=t.meta()[Const.AGGREGATE_KEY],e=this._meta[Const.AGGREGATE_KEY],e=codec_1.Util.removeKey(e,t);return""===(this._meta[Const.AGGREGATE_KEY]=e)}isEmpty(){var t=this._meta[Const.AGGREGATE_KEY];return null==t||""==t}insertChild(t){var e=this._events[t.id()];let r=null;return null==e?this._events[t.id()]=t:((e=BuilderProvider.getEventBuilder(e)).aggregateInsert(t),this._events[t.id()]=e.build(),r=t.id()),r}updateChild(t){var e=this._events[t.id()];null==e?console.error("[UpdateEvent] Cannot found eventId %s to execute update event from %s",t.id(),t.meta()[Const.AGGREGATE_KEY]):((e=BuilderProvider.getEventBuilder(e)).aggregateUpdate(t),this._events[t.id()]=e.build())}deleteChild(t){var e=this._events[t.id()];let r=null;if(null!=e)return(e=BuilderProvider.getEventBuilder(e)).aggregateDelete(t)?delete this._events[t.id()]:(r=t.id(),this._events[t.id()]=e.build()),r;console.error("[DeleteEvent] Cannot found eventId %s to execute delete event from %s",t.id(),t.meta()[Const.AGGREGATE_KEY])}build(){throw new TypeError("Not supported in Abstract class")}}class B2EventBuilder{constructor(t){this._records={},this._states={},this.mergeFrom(t)}id(){return this._id}records(){return this._records}matchId(){return this._matchId}eventType(){return this._eventType}meta(){return this._meta}states(){return this._states}mergeFrom(t){var e,r=t;if(this._id=t.id(),null!=t.records())for(var s of r.records()){var i=Const.generateKey(s);this._records[i]=s}for(e in this.setStates(r.eventStates()),this._matchId=t.matchId(),this._eventType=t.eventType(),this._meta={},t.meta())this._meta[e]=t.meta()[e]}setStates(t){if(null!=t)for(var e of t)this._states[e.partitionKey().toString()]=e}insertChild(t){return this._records[Const.generateKey(t)]=t,null}updateChild(t){var e,r=this._records[Const.generateKey(t)];null==r?console.error("[UpdateOdd] Cannot find record "+this._matchId+" "+this._id+" "+t.source()+" "+t.id()):((e=BuilderProvider.getRecordBuilder(r)).merge(t),this._records[Const.generateKey(r)]=e.build())}deleteChild(t){return delete this._records[Const.generateKey(t)],null}aggregateInsert(t){t.eventStates().forEach(t=>{this._states[t.partitionKey().toString()]=t})}aggregateUpdate(t){t.eventStates().forEach(t=>{this._states[t.partitionKey().toString()]=t})}aggregateDelete(t){return t.eventStates().forEach(t=>{delete this._states[t.partitionKey().toString()]}),0==Object.keys(this._states).length}reset(t){if(null==this._states[t.toString()])return null;var e,r=BuilderProvider.getEventBuilder(this.build()),s=(r._states={},r._records={},this._states[t.toString()]),s=(r._states[t.toString()]=s,delete this._states[t.toString()],Object.keys(this._records));for(e of s){var i=this._records[e];i.source()===t.source()&&this.getOddTypeInt(i.oddType())===this.getOddTypeInt(t.oddType())&&(r.insertChild(i),delete this._records[e])}return r}getOddTypeInt(t){return isNaN(t)?Number(jayeson_lib_record_1.OddType[t]):Number(t)}isEmpty(){return null==this._states||0==Object.keys(this._states).length}build(){throw new TypeError("Not Implemented for abstract class")}}class B2EventStateBuilder{constructor(t){this.mergeFrom(t)}statsOne(){return this._statsOne}stateTwo(){return this._statsTwo}duration(){return this._duration}key(){return this._key}matchId(){return this._matchId}eventId(){return this._eventId}createdTime(){return this._createdTime}build(){throw new TypeError("UnSupported Operation in abstract class")}mergeFrom(t){this._statsOne=t.statsOne(),this._statsTwo=t.statsTwo(),this._duration=t.duration(),this._key=t.partitionKey(),this._matchId=t.matchId(),this._eventId=t.eventId(),this._createdTime=(new Date).getMilliseconds()}merge(t){this.setStatsOne(t.statsOf(0)),this.setStatsTwo(t.statsOf(1)),this.setDuration(t.duration()),this.setEventId(t.eventId()),this.setMatchId(t.matchId()),this.setKey(t.partitionKey())}setStatsOne(t){this._statsOne=t}setStatsTwo(t){this._statsTwo=t}setDuration(t){this._duration=t}setKey(t){this._key=t}setMatchId(t){this._matchId=t}setEventId(t){this._eventId=t}setCreatedTime(t){this._createdTime=t}}class B2RecordBuilder{constructor(t){this.mergeFrom(t)}eventId(){return this._eventId}matchId(){return this._matchId}id(){return this._id}oddType(){return this._oddType}lbType(){return this._lbType}timetype(){return this._timetype}sportbook(){return this._sportbook}meta(){return this._meta}oddFormat(){return this._oddFormat}rateOver(){return this._rateOver}rateUnder(){return this._rateUnder}rateEqual(){return this._rateEqual}pivotValue(){return this._pivotValue}pivotType(){return this._pivotType}pivotBias(){return this._pivotBias}rateOverId(){return this._rateOverId}rateUnderId(){return this._rateUnderId}rateEqualId(){return this._rateEqualId}isSwapped(){return this._isSwapped}setEventId(t){this._eventId=t}setMatchId(t){this._matchId=t}setId(t){this._id=t}setOddType(t){this._oddType=t}setLbType(t){this._lbType=t}setTimeType(t){this._timetype=t}setSportbook(t){this._sportbook=t}setMeta(t){this._meta=t}setOddFormat(t){this._oddFormat=t}setRateOver(t){this._rateOver=t}setRateUnder(t){this._rateUnder=t}setRateEqual(t){this._rateEqual=t}setPivotValue(t){this._pivotValue=t}setPivotType(t){this._pivotType=t}setPivotBias(t){this._pivotBias=t}setRateOverId(t){this._rateOverId=t}setRateUnderId(t){this._rateUnderId=t}setRateEqualId(t){this._rateEqualId=t}setSwapped(t){this._isSwapped=t}build(){throw new TypeError("UnSupported in Abstract class")}merge(t){this.setRateOver(t.rateOver()),this.setRateUnder(t.rateUnder()),this.setRateEqual(t.rateEqual()),t.rateOverId&&this.setRateOverId(t.rateOverId()),t.rateUnderId&&this.setRateOverId(t.rateUnderId()),t.rateEqualId&&this.setRateOverId(t.rateEqualId())}mergeFrom(t){this._eventId=t.eventId(),this._matchId=t.matchId(),this._id=t.id(),this._oddType=t.oddType(),this._lbType=t.lbType(),this._timetype=t.timeType(),this._sportbook=t.source(),this._meta=t.meta(),this._oddFormat=t.oddFormat(),this._rateOver=t.rateOver(),this._rateUnder=t.rateUnder(),this._rateEqual=t.rateEqual(),this._pivotValue=t.pivotValue(),this._pivotType=t.pivotType(),this._pivotBias=t.pivotBias(),this._rateOverId=t.rateOverId(),this._rateUnderId=t.rateUnderId(),this._rateEqualId=t.rateEqualId(),this._isSwapped=t.isSwapped()}}exports.B2RecordBuilder=B2RecordBuilder,(t=>{class e extends IndexedSnapshotBuilder{constructor(t){super(t)}}t.Snapshot=e})(Builder=Builder||{}),(t=>{{t=t.Match||(t.Match={});class e extends B2MatchBuilder{constructor(t){super(t)}setGender(t){this.gender=t}setCountry(t){this.country=t}mergeFrom(t){super.mergeFrom(t);this.setGender(t.gender()),this.setCountry(t.country())}build(){var t,e=[];for(t of Object.keys(this._events))e.push(this._events[t]);return new jayeson_lib_record_1.TennisMatchImpl(this._p1,this._p2,this._startTime,e,this._id,this._league,this.gender,this.country,this._meta)}}t.Tennis=e;class r extends B2MatchBuilder{constructor(t){super(t)}leagueType(){return this._leagueType}gender(){return this._gender}country(){return this._country}setLeagueType(t){this._leagueType=t}setGender(t){this._gender=t}setCountry(t){this._country=t}mergeFrom(t){super.mergeFrom(t);var e=t;this.setLeagueType(e.leagueType()),this.setCountry(t.country()),this.setGender(e.gender())}build(){var t,e=[];for(t of Object.keys(this._events))e.push(this._events[t]);return new jayeson_lib_record_1.SoccerMatchImpl(this._p1,this._p2,this._startTime,e,this._id,this._league,this._meta,this._leagueType,this._gender,this._country)}}t.Soccer=r;class s extends B2MatchBuilder{constructor(t){super(t)}gender(){return this._gender}country(){return this._country}setGender(t){this._gender=t}setCountry(t){this._country=t}build(){var t,e=[];for(t of Object.keys(this._events))e.push(this._events[t]);return new jayeson_lib_record_1.BasketballMatchImpl(this._p1,this._p2,this._startTime,e,this._id,this._league,this._gender,this._country,this._meta)}mergeFrom(t){super.mergeFrom(t);this.setGender(t.gender()),this.setCountry(t.country())}}t.Basketball=s}})(Builder=Builder||{}),(t=>{{t=t.Event||(t.Event={});class e extends B2EventBuilder{constructor(t){super(t)}build(){var t,e=[];for(t of Object.keys(this._records))e.push(this._records[t]);var r,s=[];for(r of Object.keys(this._states))s.push(this._states[r]);return new jayeson_lib_record_1.TennisEventImpl(this._id,e,s,this._matchId,this._eventType,this._meta)}}t.Tennis=e;class r extends B2EventBuilder{constructor(t){super(t)}build(){var t,e=[];for(t of Object.keys(this._records))e.push(this._records[t]);var r,s=[];for(r of Object.keys(this._states))s.push(this._states[r]);return new jayeson_lib_record_1.SoccerEventImpl(this._id,e,s,this._matchId,this._eventType,this._meta)}}t.Soccer=r;class s extends B2EventBuilder{constructor(t){super(t)}build(){var t,e=[];for(t of Object.keys(this._records))e.push(this._records[t]);var r,s=[];for(r of Object.keys(this._states))s.push(this._states[r]);return new jayeson_lib_record_1.BasketballEventImpl(this._id,e,s,this._matchId,this._eventType,this._meta)}}t.Basketball=s}})(Builder=Builder||{}),(t=>{{t=t.Record||(t.Record={});class e extends B2RecordBuilder{constructor(t){super(t)}build(){return new jayeson_lib_record_1.TennisRecord(this._matchId,this._eventId,this._id,this._oddType,this._lbType,this._timetype,this._sportbook,this._oddFormat,this._meta,this._rateOver,this._rateUnder,this._rateEqual,this._pivotValue,this._pivotType,this._pivotBias,this._rateOverId,this._rateUnderId,this._rateEqualId,this._isSwapped)}}t.Tennis=e;class r extends B2RecordBuilder{constructor(t){super(t)}build(){return new jayeson_lib_record_1.SoccerRecord(this._matchId,this._eventId,this._id,this._oddType,this._lbType,this._timetype,this._sportbook,this._oddFormat,this._meta,this._rateOver,this._rateUnder,this._rateEqual,this._pivotValue,this._pivotType,this._pivotBias,this._rateOverId,this._rateUnderId,this._rateEqualId,this._isSwapped)}}t.Soccer=r;class s extends B2RecordBuilder{constructor(t){super(t)}build(){return new jayeson_lib_record_1.BasketballRecord(this._matchId,this._eventId,this._id,this._oddType,this._lbType,this._timetype,this._sportbook,this._oddFormat,this._meta,this._rateOver,this._rateUnder,this._rateEqual,this._pivotValue,this._pivotType,this._pivotBias,this._rateOverId,this._rateUnderId,this._rateEqualId,this._isSwapped)}}t.Basketball=s}})(Builder=Builder||{}),(t=>{{t=t.EventState||(t.EventState={});class e extends B2EventStateBuilder{constructor(t){super(t)}build(){return new jayeson_lib_record_1.SoccerEventState(this._duration,this._key,this._matchId,this._eventId,null,this._statsOne.getScores()[0],this._statsTwo.getScores()[0],this._statsOne.getScores()[1],this._statsTwo.getScores()[1],this.segment,this.bookPriority)}setHostScore(t){var e=this._statsOne.getScores();e[0]=t,this._statsOne.setScores(e)}setHostCard(t){var e=this._statsOne.getScores();e[1]=t,this._statsOne.setScores(e)}setGuestScore(t){var e=this._statsTwo.getScores();e[0]=t,this._statsTwo.setScores(e)}setGuestCard(t){var e=this._statsTwo.getScores();e[1]=t,this._statsTwo.setScores(e)}setSegment(t){this.segment=t}setBookPriority(t){this.bookPriority=t}mergeFrom(t){super.mergeFrom(t);this.setHostCard(t.hostCard()),this.setGuestCard(t.guestCard()),this.setHostScore(t.hostScore()),this.setGuestScore(t.guestScore()),this.setSegment(t.segment()),this.setBookPriority(t.bookPriority())}merge(t){super.merge(t);null!=t.segment&&this.setSegment(t.segment())}}t.Soccer=e;class r extends B2EventStateBuilder{constructor(t){super(t)}build(){return new jayeson_lib_record_1.TennisEventState(this._statsOne,this._statsTwo,this._duration,this._key,this._matchId,this._eventId,this._createdTime,this.setScore,this.game,this.bookPriority)}setSet(t){this.setScore=t}setGame(t){this.game=t}setBookPriority(t){this.bookPriority=t}mergeFrom(t){super.mergeFrom(t);this.setSet(t.set()),this.setGame(t.game()),this.setBookPriority(t.bookPriority())}}t.Tennis=r;class s extends B2EventStateBuilder{constructor(t){super(t)}build(){return new jayeson_lib_record_1.BasketballEventState(this._statsOne,this._statsTwo,this._duration,this._key,this._matchId,this._eventId,this._createdTime,this.segment,this.isTimeout,this.bookPriority)}setSegment(t){this.segment=t}setBookPriority(t){this.bookPriority=t}setTimeout(t){this.isTimeout=t}mergeFrom(t){super.mergeFrom(t)}}t.Basketball=s}})(Builder=Builder||{});class BuilderProvider{static getMatchBuilder(t){if(t instanceof jayeson_lib_record_1.SoccerMatchImpl)return new Builder.Match.Soccer(t);if(t instanceof jayeson_lib_record_1.TennisMatchImpl)return new Builder.Match.Tennis(t);if(t instanceof jayeson_lib_record_1.BasketballMatchImpl)return new Builder.Match.Basketball(t);throw new TypeError("Cannot Create Builder for "+t.constructor.toString())}static getEventBuilder(t){if(t instanceof jayeson_lib_record_1.SoccerEventImpl)return new Builder.Event.Soccer(t);if(t instanceof jayeson_lib_record_1.TennisEventImpl)return new Builder.Event.Tennis(t);if(t instanceof jayeson_lib_record_1.BasketballEventImpl)return new Builder.Event.Basketball(t);throw new TypeError("Cannot Create Builder for "+t.constructor.toString())}static getRecordBuilder(t){if(t instanceof jayeson_lib_record_1.SoccerRecord)return new Builder.Record.Soccer(t);if(t instanceof jayeson_lib_record_1.TennisRecord)return new Builder.Record.Tennis(t);if(t instanceof jayeson_lib_record_1.BasketballRecord)return new Builder.Record.Basketball(t);throw new TypeError("Cannot Create Builder for "+t.constructor.toString())}static getEventStateBuilder(t){if(t instanceof jayeson_lib_record_1.SoccerEventState)return new Builder.EventState.Soccer(t);if(t instanceof jayeson_lib_record_1.TennisEventState)return new Builder.EventState.Tennis(t);if(t instanceof jayeson_lib_record_1.BasketballEventState)return new Builder.EventState.Basketball(t);throw new TypeError("Cannot Create Builder for "+t.constructor.toString())}static getSnapshotBuilder(t){return new Builder.Snapshot(t)}}exports.BuilderProvider=BuilderProvider;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BuilderProvider=exports.B2RecordBuilder=exports.Const=void 0;var tslib_1=require("tslib"),jayeson_lib_record_1=require("@jayesol/jayeson.lib.record"),data_structure_1=require("./data_structure"),codec_1=require("./codec"),Collections=tslib_1.__importStar(require("typescript-collections")),Const=function(){function t(){}return t.generateKey=function(t){return t.source()+this.SEPARATOR+t.id()},t.AGGREGATE_KEY="AGGREGATE_KEY",t.SEPARATOR="_",t}();exports.Const=Const;var Builder,IndexedSnapshotBuilder=function(){function t(t){var e,r,i,n;if(this._matches={},this._partitions=new Collections.Dictionary,null!=t){try{for(var o=tslib_1.__values(t.matches()),s=o.next();!s.done;s=o.next()){var a=s.value;this._matches[a.id()]=a}}catch(t){e={error:t}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}try{for(var u=tslib_1.__values(t.getPartitionMap().keys()),c=u.next();!c.done;c=u.next()){var d=c.value;this._partitions.setValue(d,t.getPartitionMap().getValue(d))}}catch(t){i={error:t}}finally{try{c&&!c.done&&(n=u.return)&&n.call(u)}finally{if(i)throw i.error}}}}return t.prototype.matches=function(){return this._matches},t.prototype.partitions=function(){return this._partitions},t.prototype.setPartition=function(t){this._partitions=t},t.prototype.setPartitionValue=function(t,e){this._partitions.setValue(t,e)},t.prototype.removePartitionKey=function(t){return this._partitions.remove(t)},t.prototype.markPartitionAsUpdated=function(t,e){null==e&&(e=(new Date).getMilliseconds()),this._partitions.setValue(t,e)},t.prototype.replaceMatch=function(t){this._matches[t.id()]=t},t.prototype.reset=function(t){if(!this._partitions.containsKey(t))return null;var e=this._matches,r=BuilderProvider.getSnapshotBuilder(this.build());r._matches={},r._partitions.clear();var i=this.removePartitionKey(t);for(var n in r.setPartitionValue(t,i),this._matches){var o=this._matches[n],s=BuilderProvider.getMatchBuilder(o),a=s.reset(t);null==a||a.isEmpty()||r.insertChild(a.build()),s.isEmpty()?delete e[o.id()]:e[o.id()]=s.build()}return this._matches=e,r},t.prototype.insertChild=function(t){var e=this._matches[t.id()],r=null;if(null==e)this._matches[t.id()]=t;else{r=t.id();var i=BuilderProvider.getMatchBuilder(e);i.aggregateInsert(t),this._matches[t.id()]=i.build()}return r},t.prototype.updateChild=function(t){var e=this._matches[t.id()];if(null!=e){var r=BuilderProvider.getMatchBuilder(e);r.aggregateUpdate(t),this._matches[t.id()]=r.build()}else console.error("[UpdateMatch] Cannot found matchId %s to execute update match from %s",t.id(),t.meta()[Const.AGGREGATE_KEY])},t.prototype.deleteChild=function(t){var e=this._matches[t.id()],r=null;if(null!=e){var i=BuilderProvider.getMatchBuilder(e);return i.aggregateDelete(t)?delete this._matches[t.id()]:(this._matches[t.id()]=i.build(),r=t.id()),r}console.error("[DeleteMatch] Cannot found matchId %s to execute delete match from %s",t.id(),t.meta()[Const.AGGREGATE_KEY])},t.prototype.build=function(){var t={};for(var e in this._matches){var r=this._matches[e],i=t[r.sportType()];null==i&&(i=[],t[r.sportType()]=i),i.push(r)}return new data_structure_1.IndexedSnapshotImpl(t,this._partitions)},t}(),B2MatchBuilder=function(){function t(t){this._events={},this.mergeFrom(t)}return t.prototype.meta=function(){return this._meta},t.prototype.startTime=function(){return this._startTime},t.prototype.events=function(){return this._events},t.prototype.id=function(){return this._id},t.prototype.league=function(){return this._league},t.prototype.sport=function(){return this._sport},t.prototype.meata=function(){return this._meta},t.prototype.p1=function(){return this._p1},t.prototype.p2=function(){return this._p2},t.prototype.setEvent=function(t){this._events=t},t.prototype.mergeFrom=function(t){var e,r;for(var i in this._startTime=t.startTime(),this._id=t.id(),this._league=t.league(),this._sport=t.sportType(),this._meta={},t.meta())this._meta[i]=t.meta()[i];if(null!=t.events())try{for(var n=tslib_1.__values(t.events()),o=n.next();!o.done;o=n.next()){var s=o.value;this._events[s.id()]=s}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(e)throw e.error}}var a=t;this._p1=a.participantOne(),this._p2=a.participantTwo()},t.prototype.replaceEvent=function(t){this._events[t.id()]=t},t.prototype.reset=function(t){var e=t.toString(),r=this._meta[Const.AGGREGATE_KEY];if(!codec_1.Util.containsKey(r,e))return null;var i=BuilderProvider.getMatchBuilder(this.build()),n=codec_1.Util.removeKey(r,e);this._meta[Const.AGGREGATE_KEY]=n,i._meta[Const.AGGREGATE_KEY]=e;var o={};for(var s in i._events={},this._events){var a=this._events[s],u=BuilderProvider.getEventBuilder(a),c=u.reset(t);null==c||c.isEmpty()||i.insertChild(c.build()),u.isEmpty()?delete o[a.id()]:o[a.id()]=u.build()}return this._events=o,i},t.prototype.aggregateInsert=function(t){for(var e in t.meta())e!==Const.AGGREGATE_KEY&&(this._meta[e]=t.meta()[e]);var r=t.meta()[Const.AGGREGATE_KEY],i=this._meta[Const.AGGREGATE_KEY];this._meta[Const.AGGREGATE_KEY]=codec_1.Util.addKey(i,r)},t.prototype.aggregateUpdate=function(t){for(var e in t.meta())e!==Const.AGGREGATE_KEY&&(this._meta[e]=t.meta()[e])},t.prototype.aggregateDelete=function(t){var e=t.meta()[Const.AGGREGATE_KEY],r=this._meta[Const.AGGREGATE_KEY],i=codec_1.Util.removeKey(r,e);return this._meta[Const.AGGREGATE_KEY]=i,""===i},t.prototype.isEmpty=function(){var t=this._meta[Const.AGGREGATE_KEY];return null==t||""==t},t.prototype.insertChild=function(t){var e=this._events[t.id()],r=null;if(null==e)this._events[t.id()]=t;else{var i=BuilderProvider.getEventBuilder(e);i.aggregateInsert(t),this._events[t.id()]=i.build(),r=t.id()}return r},t.prototype.updateChild=function(t){var e=this._events[t.id()];if(null!=e){var r=BuilderProvider.getEventBuilder(e);r.aggregateUpdate(t),this._events[t.id()]=r.build()}else console.error("[UpdateEvent] Cannot found eventId %s to execute update event from %s",t.id(),t.meta()[Const.AGGREGATE_KEY])},t.prototype.deleteChild=function(t){var e=this._events[t.id()],r=null;if(null!=e){var i=BuilderProvider.getEventBuilder(e);return i.aggregateDelete(t)?delete this._events[t.id()]:(r=t.id(),this._events[t.id()]=i.build()),r}console.error("[DeleteEvent] Cannot found eventId %s to execute delete event from %s",t.id(),t.meta()[Const.AGGREGATE_KEY])},t.prototype.build=function(){throw new TypeError("Not supported in Abstract class")},t}(),B2EventBuilder=function(){function t(t){this._records={},this._states={},this.mergeFrom(t)}return t.prototype.id=function(){return this._id},t.prototype.records=function(){return this._records},t.prototype.matchId=function(){return this._matchId},t.prototype.eventType=function(){return this._eventType},t.prototype.meta=function(){return this._meta},t.prototype.states=function(){return this._states},t.prototype.mergeFrom=function(t){var e,r,i=t;if(this._id=t.id(),null!=t.records())try{for(var n=tslib_1.__values(i.records()),o=n.next();!o.done;o=n.next()){var s=o.value,a=Const.generateKey(s);this._records[a]=s}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(e)throw e.error}}for(var a in this.setStates(i.eventStates()),this._matchId=t.matchId(),this._eventType=t.eventType(),this._meta={},t.meta())this._meta[a]=t.meta()[a]},t.prototype.setStates=function(t){var e,r;if(null!=t)try{for(var i=tslib_1.__values(t),n=i.next();!n.done;n=i.next()){var o=n.value;this._states[o.partitionKey().toString()]=o}}catch(t){e={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}},t.prototype.insertChild=function(t){return this._records[Const.generateKey(t)]=t,null},t.prototype.updateChild=function(t){var e=this._records[Const.generateKey(t)];if(null!=e){var r=BuilderProvider.getRecordBuilder(e);r.merge(t),this._records[Const.generateKey(e)]=r.build()}else console.error("[UpdateOdd] Cannot find record "+this._matchId+" "+this._id+" "+t.source()+" "+t.id())},t.prototype.deleteChild=function(t){return delete this._records[Const.generateKey(t)],null},t.prototype.aggregateInsert=function(t){var e=this;t.eventStates().forEach(function(t){e._states[t.partitionKey().toString()]=t})},t.prototype.aggregateUpdate=function(t){var e=this;t.eventStates().forEach(function(t){e._states[t.partitionKey().toString()]=t})},t.prototype.aggregateDelete=function(t){var e=this;return t.eventStates().forEach(function(t){delete e._states[t.partitionKey().toString()]}),0==Object.keys(this._states).length},t.prototype.reset=function(t){var e,r;if(null==this._states[t.toString()])return null;var i=BuilderProvider.getEventBuilder(this.build());i._states={},i._records={};var n=this._states[t.toString()];i._states[t.toString()]=n,delete this._states[t.toString()];var o=Object.keys(this._records);try{for(var s=tslib_1.__values(o),a=s.next();!a.done;a=s.next()){var u=a.value,c=this._records[u];c.source()===t.source()&&this.getOddTypeInt(c.oddType())===this.getOddTypeInt(t.oddType())&&(i.insertChild(c),delete this._records[u])}}catch(t){e={error:t}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}return i},t.prototype.getOddTypeInt=function(t){return isNaN(t)?Number(jayeson_lib_record_1.OddType[t]):Number(t)},t.prototype.isEmpty=function(){return null==this._states||0==Object.keys(this._states).length},t.prototype.build=function(){throw new TypeError("Not Implemented for abstract class")},t}(),B2EventStateBuilder=function(){function t(t){this.mergeFrom(t)}return t.prototype.statsOne=function(){return this._statsOne},t.prototype.stateTwo=function(){return this._statsTwo},t.prototype.duration=function(){return this._duration},t.prototype.key=function(){return this._key},t.prototype.matchId=function(){return this._matchId},t.prototype.eventId=function(){return this._eventId},t.prototype.createdTime=function(){return this._createdTime},t.prototype.build=function(){throw new TypeError("UnSupported Operation in abstract class")},t.prototype.mergeFrom=function(t){var e=t;this._statsOne=e.statsOne(),this._statsTwo=e.statsTwo(),this._duration=e.duration(),this._key=e.partitionKey(),this._matchId=e.matchId(),this._eventId=e.eventId(),this._createdTime=(new Date).getMilliseconds()},t.prototype.merge=function(t){var e=t;this.setStatsOne(e.statsOf(0)),this.setStatsTwo(e.statsOf(1)),this.setDuration(e.duration()),this.setEventId(e.eventId()),this.setMatchId(e.matchId()),this.setKey(e.partitionKey())},t.prototype.setStatsOne=function(t){this._statsOne=t},t.prototype.setStatsTwo=function(t){this._statsTwo=t},t.prototype.setDuration=function(t){this._duration=t},t.prototype.setKey=function(t){this._key=t},t.prototype.setMatchId=function(t){this._matchId=t},t.prototype.setEventId=function(t){this._eventId=t},t.prototype.setCreatedTime=function(t){this._createdTime=t},t}(),B2RecordBuilder=function(){function t(t){this.mergeFrom(t)}return t.prototype.eventId=function(){return this._eventId},t.prototype.matchId=function(){return this._matchId},t.prototype.id=function(){return this._id},t.prototype.oddType=function(){return this._oddType},t.prototype.lbType=function(){return this._lbType},t.prototype.timetype=function(){return this._timetype},t.prototype.sportbook=function(){return this._sportbook},t.prototype.meta=function(){return this._meta},t.prototype.oddFormat=function(){return this._oddFormat},t.prototype.rateOver=function(){return this._rateOver},t.prototype.rateUnder=function(){return this._rateUnder},t.prototype.rateEqual=function(){return this._rateEqual},t.prototype.pivotValue=function(){return this._pivotValue},t.prototype.pivotType=function(){return this._pivotType},t.prototype.pivotBias=function(){return this._pivotBias},t.prototype.rateOverId=function(){return this._rateOverId},t.prototype.rateUnderId=function(){return this._rateUnderId},t.prototype.rateEqualId=function(){return this._rateEqualId},t.prototype.isSwapped=function(){return this._isSwapped},t.prototype.setEventId=function(t){this._eventId=t},t.prototype.setMatchId=function(t){this._matchId=t},t.prototype.setId=function(t){this._id=t},t.prototype.setOddType=function(t){this._oddType=t},t.prototype.setLbType=function(t){this._lbType=t},t.prototype.setTimeType=function(t){this._timetype=t},t.prototype.setSportbook=function(t){this._sportbook=t},t.prototype.setMeta=function(t){this._meta=t},t.prototype.setOddFormat=function(t){this._oddFormat=t},t.prototype.setRateOver=function(t){this._rateOver=t},t.prototype.setRateUnder=function(t){this._rateUnder=t},t.prototype.setRateEqual=function(t){this._rateEqual=t},t.prototype.setPivotValue=function(t){this._pivotValue=t},t.prototype.setPivotType=function(t){this._pivotType=t},t.prototype.setPivotBias=function(t){this._pivotBias=t},t.prototype.setRateOverId=function(t){this._rateOverId=t},t.prototype.setRateUnderId=function(t){this._rateUnderId=t},t.prototype.setRateEqualId=function(t){this._rateEqualId=t},t.prototype.setSwapped=function(t){this._isSwapped=t},t.prototype.build=function(){throw new TypeError("UnSupported in Abstract class")},t.prototype.merge=function(t){var e=t;this.setRateOver(e.rateOver()),this.setRateUnder(e.rateUnder()),this.setRateEqual(e.rateEqual()),e.rateOverId&&this.setRateOverId(e.rateOverId()),e.rateUnderId&&this.setRateOverId(e.rateUnderId()),e.rateEqualId&&this.setRateOverId(e.rateEqualId())},t.prototype.mergeFrom=function(t){var e=t;this._eventId=e.eventId(),this._matchId=e.matchId(),this._id=e.id(),this._oddType=e.oddType(),this._lbType=e.lbType(),this._timetype=e.timeType(),this._sportbook=e.source(),this._meta=e.meta(),this._oddFormat=e.oddFormat(),this._rateOver=e.rateOver(),this._rateUnder=e.rateUnder(),this._rateEqual=e.rateEqual(),this._pivotValue=e.pivotValue(),this._pivotType=e.pivotType(),this._pivotBias=e.pivotBias(),this._rateOverId=e.rateOverId(),this._rateUnderId=e.rateUnderId(),this._rateEqualId=e.rateEqualId(),this._isSwapped=e.isSwapped()},t}();exports.B2RecordBuilder=B2RecordBuilder,function(t){var e=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e}(IndexedSnapshotBuilder);t.Snapshot=e}(Builder||(Builder={})),function(t){!function(t){var e=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype.setGender=function(t){this.gender=t},e.prototype.setCountry=function(t){this.country=t},e.prototype.mergeFrom=function(e){t.prototype.mergeFrom.call(this,e);var r=e;this.setGender(r.gender()),this.setCountry(r.country())},e.prototype.build=function(){var t,e,r=[];try{for(var i=tslib_1.__values(Object.keys(this._events)),n=i.next();!n.done;n=i.next()){var o=n.value;r.push(this._events[o])}}catch(e){t={error:e}}finally{try{n&&!n.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return new jayeson_lib_record_1.TennisMatchImpl(this._p1,this._p2,this._startTime,r,this._id,this._league,this.gender,this.country,this._meta)},e}(B2MatchBuilder);t.Tennis=e;var r=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype.leagueType=function(){return this._leagueType},e.prototype.gender=function(){return this._gender},e.prototype.country=function(){return this._country},e.prototype.setLeagueType=function(t){this._leagueType=t},e.prototype.setGender=function(t){this._gender=t},e.prototype.setCountry=function(t){this._country=t},e.prototype.mergeFrom=function(e){t.prototype.mergeFrom.call(this,e);var r=e;this.setLeagueType(r.leagueType()),this.setCountry(e.country()),this.setGender(r.gender())},e.prototype.build=function(){var t,e,r=[];try{for(var i=tslib_1.__values(Object.keys(this._events)),n=i.next();!n.done;n=i.next()){var o=n.value;r.push(this._events[o])}}catch(e){t={error:e}}finally{try{n&&!n.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return new jayeson_lib_record_1.SoccerMatchImpl(this._p1,this._p2,this._startTime,r,this._id,this._league,this._meta,this._leagueType,this._gender,this._country)},e}(B2MatchBuilder);t.Soccer=r;var i=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype.gender=function(){return this._gender},e.prototype.country=function(){return this._country},e.prototype.setGender=function(t){this._gender=t},e.prototype.setCountry=function(t){this._country=t},e.prototype.build=function(){var t,e,r=[];try{for(var i=tslib_1.__values(Object.keys(this._events)),n=i.next();!n.done;n=i.next()){var o=n.value;r.push(this._events[o])}}catch(e){t={error:e}}finally{try{n&&!n.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return new jayeson_lib_record_1.BasketballMatchImpl(this._p1,this._p2,this._startTime,r,this._id,this._league,this._gender,this._country,this._meta)},e.prototype.mergeFrom=function(e){t.prototype.mergeFrom.call(this,e);var r=e;this.setGender(r.gender()),this.setCountry(r.country())},e}(B2MatchBuilder);t.Basketball=i}(t.Match||(t.Match={}))}(Builder||(Builder={})),function(t){!function(t){var e=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype.build=function(){var t,e,r,i,n=[];try{for(var o=tslib_1.__values(Object.keys(this._records)),s=o.next();!s.done;s=o.next()){var a=s.value;n.push(this._records[a])}}catch(e){t={error:e}}finally{try{s&&!s.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}var u=[];try{for(var c=tslib_1.__values(Object.keys(this._states)),d=c.next();!d.done;d=c.next()){var h=d.value;u.push(this._states[h])}}catch(t){r={error:t}}finally{try{d&&!d.done&&(i=c.return)&&i.call(c)}finally{if(r)throw r.error}}return new jayeson_lib_record_1.TennisEventImpl(this._id,n,u,this._matchId,this._eventType,this._meta)},e}(B2EventBuilder);t.Tennis=e;var r=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype.build=function(){var t,e,r,i,n=[];try{for(var o=tslib_1.__values(Object.keys(this._records)),s=o.next();!s.done;s=o.next()){var a=s.value;n.push(this._records[a])}}catch(e){t={error:e}}finally{try{s&&!s.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}var u=[];try{for(var c=tslib_1.__values(Object.keys(this._states)),d=c.next();!d.done;d=c.next()){var h=d.value;u.push(this._states[h])}}catch(t){r={error:t}}finally{try{d&&!d.done&&(i=c.return)&&i.call(c)}finally{if(r)throw r.error}}return new jayeson_lib_record_1.SoccerEventImpl(this._id,n,u,this._matchId,this._eventType,this._meta)},e}(B2EventBuilder);t.Soccer=r;var i=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype.build=function(){var t,e,r,i,n=[];try{for(var o=tslib_1.__values(Object.keys(this._records)),s=o.next();!s.done;s=o.next()){var a=s.value;n.push(this._records[a])}}catch(e){t={error:e}}finally{try{s&&!s.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}var u=[];try{for(var c=tslib_1.__values(Object.keys(this._states)),d=c.next();!d.done;d=c.next()){var h=d.value;u.push(this._states[h])}}catch(t){r={error:t}}finally{try{d&&!d.done&&(i=c.return)&&i.call(c)}finally{if(r)throw r.error}}return new jayeson_lib_record_1.BasketballEventImpl(this._id,n,u,this._matchId,this._eventType,this._meta)},e}(B2EventBuilder);t.Basketball=i}(t.Event||(t.Event={}))}(Builder||(Builder={})),function(t){!function(t){var e=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype.build=function(){return new jayeson_lib_record_1.TennisRecord(this._matchId,this._eventId,this._id,this._oddType,this._lbType,this._timetype,this._sportbook,this._oddFormat,this._meta,this._rateOver,this._rateUnder,this._rateEqual,this._pivotValue,this._pivotType,this._pivotBias,this._rateOverId,this._rateUnderId,this._rateEqualId,this._isSwapped)},e}(B2RecordBuilder);t.Tennis=e;var r=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype.build=function(){return new jayeson_lib_record_1.SoccerRecord(this._matchId,this._eventId,this._id,this._oddType,this._lbType,this._timetype,this._sportbook,this._oddFormat,this._meta,this._rateOver,this._rateUnder,this._rateEqual,this._pivotValue,this._pivotType,this._pivotBias,this._rateOverId,this._rateUnderId,this._rateEqualId,this._isSwapped)},e}(B2RecordBuilder);t.Soccer=r;var i=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype.build=function(){return new jayeson_lib_record_1.BasketballRecord(this._matchId,this._eventId,this._id,this._oddType,this._lbType,this._timetype,this._sportbook,this._oddFormat,this._meta,this._rateOver,this._rateUnder,this._rateEqual,this._pivotValue,this._pivotType,this._pivotBias,this._rateOverId,this._rateUnderId,this._rateEqualId,this._isSwapped)},e}(B2RecordBuilder);t.Basketball=i}(t.Record||(t.Record={}))}(Builder||(Builder={})),function(t){!function(t){var e=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype.build=function(){return new jayeson_lib_record_1.SoccerEventState(this._duration,this._key,this._matchId,this._eventId,null,this._statsOne.getScores()[0],this._statsTwo.getScores()[0],this._statsOne.getScores()[1],this._statsTwo.getScores()[1],this.segment,this.bookPriority)},e.prototype.setHostScore=function(t){var e=this._statsOne.getScores();e[0]=t,this._statsOne.setScores(e)},e.prototype.setHostCard=function(t){var e=this._statsOne.getScores();e[1]=t,this._statsOne.setScores(e)},e.prototype.setGuestScore=function(t){var e=this._statsTwo.getScores();e[0]=t,this._statsTwo.setScores(e)},e.prototype.setGuestCard=function(t){var e=this._statsTwo.getScores();e[1]=t,this._statsTwo.setScores(e)},e.prototype.setSegment=function(t){this.segment=t},e.prototype.setBookPriority=function(t){this.bookPriority=t},e.prototype.mergeFrom=function(e){t.prototype.mergeFrom.call(this,e);var r=e;this.setHostCard(r.hostCard()),this.setGuestCard(r.guestCard()),this.setHostScore(r.hostScore()),this.setGuestScore(r.guestScore()),this.setSegment(r.segment()),this.setBookPriority(r.bookPriority())},e.prototype.merge=function(e){t.prototype.merge.call(this,e);var r=e;null!=r.segment&&this.setSegment(r.segment())},e}(B2EventStateBuilder);t.Soccer=e;var r=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype.build=function(){return new jayeson_lib_record_1.TennisEventState(this._statsOne,this._statsTwo,this._duration,this._key,this._matchId,this._eventId,this._createdTime,this.setScore,this.game,this.bookPriority)},e.prototype.setSet=function(t){this.setScore=t},e.prototype.setGame=function(t){this.game=t},e.prototype.setBookPriority=function(t){this.bookPriority=t},e.prototype.mergeFrom=function(e){t.prototype.mergeFrom.call(this,e);var r=e;this.setSet(r.set()),this.setGame(r.game()),this.setBookPriority(r.bookPriority())},e}(B2EventStateBuilder);t.Tennis=r;var i=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype.build=function(){return new jayeson_lib_record_1.BasketballEventState(this._statsOne,this._statsTwo,this._duration,this._key,this._matchId,this._eventId,this._createdTime,this.segment,this.isTimeout,this.bookPriority)},e.prototype.setSegment=function(t){this.segment=t},e.prototype.setBookPriority=function(t){this.bookPriority=t},e.prototype.setTimeout=function(t){this.isTimeout=t},e.prototype.mergeFrom=function(e){t.prototype.mergeFrom.call(this,e)},e}(B2EventStateBuilder);t.Basketball=i}(t.EventState||(t.EventState={}))}(Builder||(Builder={}));var BuilderProvider=function(){function t(){}return t.getMatchBuilder=function(t){if(t instanceof jayeson_lib_record_1.SoccerMatchImpl)return new Builder.Match.Soccer(t);if(t instanceof jayeson_lib_record_1.TennisMatchImpl)return new Builder.Match.Tennis(t);if(t instanceof jayeson_lib_record_1.BasketballMatchImpl)return new Builder.Match.Basketball(t);throw new TypeError("Cannot Create Builder for "+t.constructor.toString())},t.getEventBuilder=function(t){if(t instanceof jayeson_lib_record_1.SoccerEventImpl)return new Builder.Event.Soccer(t);if(t instanceof jayeson_lib_record_1.TennisEventImpl)return new Builder.Event.Tennis(t);if(t instanceof jayeson_lib_record_1.BasketballEventImpl)return new Builder.Event.Basketball(t);throw new TypeError("Cannot Create Builder for "+t.constructor.toString())},t.getRecordBuilder=function(t){if(t instanceof jayeson_lib_record_1.SoccerRecord)return new Builder.Record.Soccer(t);if(t instanceof jayeson_lib_record_1.TennisRecord)return new Builder.Record.Tennis(t);if(t instanceof jayeson_lib_record_1.BasketballRecord)return new Builder.Record.Basketball(t);throw new TypeError("Cannot Create Builder for "+t.constructor.toString())},t.getEventStateBuilder=function(t){if(t instanceof jayeson_lib_record_1.SoccerEventState)return new Builder.EventState.Soccer(t);if(t instanceof jayeson_lib_record_1.TennisEventState)return new Builder.EventState.Tennis(t);if(t instanceof jayeson_lib_record_1.BasketballEventState)return new Builder.EventState.Basketball(t);throw new TypeError("Cannot Create Builder for "+t.constructor.toString())},t.getSnapshotBuilder=function(t){return new Builder.Snapshot(t)},t}();exports.BuilderProvider=BuilderProvider;