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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/mutable.js CHANGED
@@ -1 +1,1061 @@
1
- "use strict";var __extends=this&&this.__extends||function(){var i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(t,e){function r(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}();Object.defineProperty(exports,"__esModule",{value:!0});var jayeson_lib_record_1=require("@jayesol/jayeson.lib.record"),data_structure_1=require("./data_structure"),codec_1=require("./codec"),Collections=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){if(this._matches={},this._partitions=new Collections.Dictionary,null!=t){for(var e=0,r=t.matches();e<r.length;e++){var i=r[e];this._matches[i.id()]=i}for(var o=0,n=t.getPartitionMap().keys();o<n.length;o++){var s=n[o];this._partitions.setValue(s,t.getPartitionMap().getValue(s))}}}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 o in r.setPartitionValue(t,i),this._matches){var n=this._matches[o],s=BuilderProvider.getMatchBuilder(n),a=s.reset(t);null==a||a.isEmpty()||r.insertChild(a.build()),s.isEmpty()?delete e[n.id()]:e[n.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){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=0,i=t.events();r<i.length;r++){var o=i[r];this._events[o.id()]=o}var n=t;this._p1=n.participantOne(),this._p2=n.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()),o=codec_1.Util.removeKey(r,e);this._meta[Const.AGGREGATE_KEY]=o,i._meta[Const.AGGREGATE_KEY]=e;var n={};for(var s in i._events={},this._events){var a=this._events[s],u=BuilderProvider.getEventBuilder(a),h=u.reset(t);null==h||h.isEmpty()||i.insertChild(h.build()),u.isEmpty()?delete n[a.id()]:n[a.id()]=u.build()}return this._events=n,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)},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=t;if(this._id=t.id(),null!=t.records())for(var r=0,i=e.records();r<i.length;r++){var o=i[r],n=Const.generateKey(o);this._records[n]=o}for(var n in this.setStates(e.eventStates()),this._matchId=t.matchId(),this._eventType=t.eventType(),this._meta={},t.meta())this._meta[n]=t.meta()[n]},t.prototype.setStates=function(t){if(null!=t)for(var e=0,r=t;e<r.length;e++){var i=r[e];this._states[i.partitionKey().toString()]=i}},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){if(null==this._states[t.toString()])return null;var e=BuilderProvider.getEventBuilder(this.build());e._states={},e._records={};var r=this._states[t.toString()];e._states[t.toString()]=r,delete this._states[t.toString()];for(var i=0,o=Object.keys(this._records);i<o.length;i++){var n=o[i],s=this._records[n];s.source()===t.source()&&this.getOddTypeInt(s.oddType())===this.getOddTypeInt(t.oddType())&&(e.insertChild(s),delete this._records[n])}return e},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,r=(__extends(i,e=IndexedSnapshotBuilder),i);function i(t){return e.call(this,t)||this}t.Snapshot=r}(Builder=Builder||{}),function(t){!function(t){var r,e=(__extends(i,r=B2MatchBuilder),i.prototype.setGender=function(t){this.gender=t},i.prototype.setCountry=function(t){this.country=t},i.prototype.mergeFrom=function(t){r.prototype.mergeFrom.call(this,t);var e=t;this.setGender(e.gender()),this.setCountry(e.country())},i.prototype.build=function(){for(var t=[],e=0,r=Object.keys(this._events);e<r.length;e++){var i=r[e];t.push(this._events[i])}return new jayeson_lib_record_1.TennisMatchImpl(this._p1,this._p2,this._startTime,t,this._id,this._league,this.gender,this.country,this._meta)},i);function i(t){return r.call(this,t)||this}t.Tennis=e;var o,n=(__extends(s,o=B2MatchBuilder),s.prototype.leagueType=function(){return this._leagueType},s.prototype.gender=function(){return this._gender},s.prototype.country=function(){return this._country},s.prototype.setLeagueType=function(t){this._leagueType=t},s.prototype.setGender=function(t){this._gender=t},s.prototype.setCountry=function(t){this._country=t},s.prototype.mergeFrom=function(t){o.prototype.mergeFrom.call(this,t);var e=t;this.setLeagueType(e.leagueType()),this.setCountry(t.country()),this.setGender(e.gender())},s.prototype.build=function(){for(var t=[],e=0,r=Object.keys(this._events);e<r.length;e++){var i=r[e];t.push(this._events[i])}return new jayeson_lib_record_1.SoccerMatchImpl(this._p1,this._p2,this._startTime,t,this._id,this._league,this._meta,this._leagueType,this._gender,this._country)},s);function s(t){return o.call(this,t)||this}t.Soccer=n;var a,u=(__extends(h,a=B2MatchBuilder),h.prototype.gender=function(){return this._gender},h.prototype.country=function(){return this._country},h.prototype.setGender=function(t){this._gender=t},h.prototype.setCountry=function(t){this._country=t},h.prototype.build=function(){for(var t=[],e=0,r=Object.keys(this._events);e<r.length;e++){var i=r[e];t.push(this._events[i])}return new jayeson_lib_record_1.BasketballMatchImpl(this._p1,this._p2,this._startTime,t,this._id,this._league,this._gender,this._country,this._meta)},h.prototype.mergeFrom=function(t){a.prototype.mergeFrom.call(this,t);var e=t;this.setGender(e.gender()),this.setCountry(e.country())},h);function h(t){return a.call(this,t)||this}t.Basketball=u}(t.Match||(t.Match={}))}(Builder=Builder||{}),function(t){!function(t){var e,r=(__extends(i,e=B2EventBuilder),i.prototype.build=function(){for(var t=[],e=0,r=Object.keys(this._records);e<r.length;e++){var i=r[e];t.push(this._records[i])}for(var o=[],n=0,s=Object.keys(this._states);n<s.length;n++){var a=s[n];o.push(this._states[a])}return new jayeson_lib_record_1.TennisEventImpl(this._id,t,o,this._matchId,this._eventType,this._meta)},i);function i(t){return e.call(this,t)||this}t.Tennis=r;var o,n=(__extends(s,o=B2EventBuilder),s.prototype.build=function(){for(var t=[],e=0,r=Object.keys(this._records);e<r.length;e++){var i=r[e];t.push(this._records[i])}for(var o=[],n=0,s=Object.keys(this._states);n<s.length;n++){var a=s[n];o.push(this._states[a])}return new jayeson_lib_record_1.SoccerEventImpl(this._id,t,o,this._matchId,this._eventType,this._meta)},s);function s(t){return o.call(this,t)||this}t.Soccer=n;var a,u=(__extends(h,a=B2EventBuilder),h.prototype.build=function(){for(var t=[],e=0,r=Object.keys(this._records);e<r.length;e++){var i=r[e];t.push(this._records[i])}for(var o=[],n=0,s=Object.keys(this._states);n<s.length;n++){var a=s[n];o.push(this._states[a])}return new jayeson_lib_record_1.BasketballEventImpl(this._id,t,o,this._matchId,this._eventType,this._meta)},h);function h(t){return a.call(this,t)||this}t.Basketball=u}(t.Event||(t.Event={}))}(Builder=Builder||{}),function(t){!function(t){var e,r=(__extends(i,e=B2RecordBuilder),i.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)},i);function i(t){return e.call(this,t)||this}t.Tennis=r;var o,n=(__extends(s,o=B2RecordBuilder),s.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)},s);function s(t){return o.call(this,t)||this}t.Soccer=n;var a,u=(__extends(h,a=B2RecordBuilder),h.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)},h);function h(t){return a.call(this,t)||this}t.Basketball=u}(t.Record||(t.Record={}))}(Builder=Builder||{}),function(t){!function(t){var r,e=(__extends(i,r=B2EventStateBuilder),i.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)},i.prototype.setHostScore=function(t){var e=this._statsOne.getScores();e[0]=t,this._statsOne.setScores(e)},i.prototype.setHostCard=function(t){var e=this._statsOne.getScores();e[1]=t,this._statsOne.setScores(e)},i.prototype.setGuestScore=function(t){var e=this._statsTwo.getScores();e[0]=t,this._statsTwo.setScores(e)},i.prototype.setGuestCard=function(t){var e=this._statsTwo.getScores();e[1]=t,this._statsTwo.setScores(e)},i.prototype.setSegment=function(t){this.segment=t},i.prototype.setBookPriority=function(t){this.bookPriority=t},i.prototype.mergeFrom=function(t){r.prototype.mergeFrom.call(this,t);var e=t;this.setHostCard(e.hostCard()),this.setGuestCard(e.guestCard()),this.setHostScore(e.hostScore()),this.setGuestScore(e.guestScore()),this.setSegment(e.segment()),this.setBookPriority(e.bookPriority())},i.prototype.merge=function(t){r.prototype.merge.call(this,t);var e=t;null!=e.segment&&this.setSegment(e.segment())},i);function i(t){return r.call(this,t)||this}t.Soccer=e;var o,n=(__extends(s,o=B2EventStateBuilder),s.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)},s.prototype.setSet=function(t){this.setScore=t},s.prototype.setGame=function(t){this.game=t},s.prototype.setBookPriority=function(t){this.bookPriority=t},s.prototype.mergeFrom=function(t){o.prototype.mergeFrom.call(this,t);var e=t;this.setSet(e.set()),this.setGame(e.game()),this.setBookPriority(e.bookPriority())},s);function s(t){return o.call(this,t)||this}t.Tennis=n;var a,u=(__extends(h,a=B2EventStateBuilder),h.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)},h.prototype.setSegment=function(t){this.segment=t},h.prototype.setBookPriority=function(t){this.bookPriority=t},h.prototype.setTimeout=function(t){this.isTimeout=t},h.prototype.mergeFrom=function(t){a.prototype.mergeFrom.call(this,t)},h);function h(t){return a.call(this,t)||this}t.Basketball=u}(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;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.BuilderProvider = exports.B2RecordBuilder = exports.Const = void 0;
27
+ const jayeson_lib_record_1 = require("@jayesol/jayeson.lib.record");
28
+ const data_structure_1 = require("./data_structure");
29
+ const codec_1 = require("./codec");
30
+ const Collections = __importStar(require("typescript-collections"));
31
+ class Const {
32
+ static generateKey(rec) {
33
+ return rec.source() + this.SEPARATOR + rec.id();
34
+ }
35
+ }
36
+ exports.Const = Const;
37
+ Const.AGGREGATE_KEY = "AGGREGATE_KEY";
38
+ Const.SEPARATOR = "_";
39
+ class IndexedSnapshotBuilder {
40
+ constructor(input) {
41
+ this._matches = {};
42
+ this._partitions = new Collections.Dictionary();
43
+ if (input != null) {
44
+ for (let match of input.matches()) {
45
+ this._matches[match.id()] = match;
46
+ }
47
+ for (let key of input.getPartitionMap().keys()) {
48
+ this._partitions.setValue(key, input.getPartitionMap().getValue(key));
49
+ }
50
+ }
51
+ }
52
+ matches() {
53
+ return this._matches;
54
+ }
55
+ partitions() {
56
+ return this._partitions;
57
+ }
58
+ setPartition(partition) {
59
+ this._partitions = partition;
60
+ }
61
+ setPartitionValue(key, value) {
62
+ this._partitions.setValue(key, value);
63
+ }
64
+ removePartitionKey(key) {
65
+ return this._partitions.remove(key);
66
+ }
67
+ markPartitionAsUpdated(key, time) {
68
+ if (time == null) {
69
+ time = new Date().getMilliseconds();
70
+ }
71
+ this._partitions.setValue(key, time);
72
+ }
73
+ replaceMatch(match) {
74
+ this._matches[match.id()] = match;
75
+ }
76
+ reset(key) {
77
+ if (!this._partitions.containsKey(key)) {
78
+ return null;
79
+ }
80
+ let updatedMatches = this._matches;
81
+ let removedDataSnapshotBuilder = BuilderProvider.getSnapshotBuilder(this.build());
82
+ removedDataSnapshotBuilder._matches = {};
83
+ removedDataSnapshotBuilder._partitions.clear();
84
+ // Transfer PK
85
+ let time = this.removePartitionKey(key);
86
+ removedDataSnapshotBuilder.setPartitionValue(key, time);
87
+ for (let matchId in this._matches) {
88
+ let match = this._matches[matchId];
89
+ let remainingMatchbuilder = BuilderProvider.getMatchBuilder(match);
90
+ let removedMatchBuilder = remainingMatchbuilder.reset(key);
91
+ if (removedMatchBuilder != null && !removedMatchBuilder.isEmpty()) {
92
+ removedDataSnapshotBuilder.insertChild(removedMatchBuilder.build());
93
+ }
94
+ if (!remainingMatchbuilder.isEmpty()) {
95
+ updatedMatches[match.id()] = remainingMatchbuilder.build();
96
+ }
97
+ else {
98
+ delete updatedMatches[match.id()];
99
+ }
100
+ }
101
+ this._matches = updatedMatches;
102
+ return removedDataSnapshotBuilder;
103
+ }
104
+ insertChild(incoming) {
105
+ let existing = this._matches[incoming.id()];
106
+ let suppressMatch = null;
107
+ if (existing == null) {
108
+ this._matches[incoming.id()] = incoming;
109
+ }
110
+ else {
111
+ // Clone the existing
112
+ suppressMatch = incoming.id();
113
+ let builder = BuilderProvider.getMatchBuilder(existing);
114
+ builder.aggregateInsert(incoming);
115
+ this._matches[incoming.id()] = builder.build();
116
+ }
117
+ return suppressMatch;
118
+ }
119
+ updateChild(incoming) {
120
+ let existing = this._matches[incoming.id()];
121
+ if (existing == null) {
122
+ console.error("[UpdateMatch] Cannot found matchId %s to execute update match from %s", incoming.id(), incoming.meta()[Const.AGGREGATE_KEY]);
123
+ return;
124
+ }
125
+ let builder = BuilderProvider.getMatchBuilder(existing);
126
+ builder.aggregateUpdate(incoming);
127
+ this._matches[incoming.id()] = builder.build();
128
+ }
129
+ deleteChild(incoming) {
130
+ let existing = this._matches[incoming.id()];
131
+ let suppressMatch = null;
132
+ if (existing == null) {
133
+ console.error("[DeleteMatch] Cannot found matchId %s to execute delete match from %s", incoming.id(), incoming.meta()[Const.AGGREGATE_KEY]);
134
+ return;
135
+ }
136
+ let builder = BuilderProvider.getMatchBuilder(existing);
137
+ let isEmpty = builder.aggregateDelete(incoming);
138
+ if (isEmpty) {
139
+ delete this._matches[incoming.id()];
140
+ }
141
+ else {
142
+ this._matches[incoming.id()] = builder.build();
143
+ suppressMatch = incoming.id();
144
+ }
145
+ return suppressMatch;
146
+ }
147
+ build() {
148
+ //Consolidate matches by sport type
149
+ let matches = {};
150
+ for (let matchId in this._matches) {
151
+ let match = this._matches[matchId];
152
+ let arr = matches[match.sportType()];
153
+ if (arr == null) {
154
+ arr = [];
155
+ matches[match.sportType()] = arr;
156
+ }
157
+ arr.push(match);
158
+ }
159
+ return new data_structure_1.IndexedSnapshotImpl(matches, this._partitions);
160
+ }
161
+ }
162
+ class B2MatchBuilder {
163
+ constructor(t) {
164
+ this._events = {};
165
+ this.mergeFrom(t);
166
+ }
167
+ meta() {
168
+ return this._meta;
169
+ }
170
+ startTime() {
171
+ return this._startTime;
172
+ }
173
+ events() {
174
+ return this._events;
175
+ }
176
+ id() {
177
+ return this._id;
178
+ }
179
+ league() {
180
+ return this._league;
181
+ }
182
+ sport() {
183
+ return this._sport;
184
+ }
185
+ meata() {
186
+ return this._meta;
187
+ }
188
+ p1() {
189
+ return this._p1;
190
+ }
191
+ p2() {
192
+ return this._p2;
193
+ }
194
+ setEvent(event) {
195
+ this._events = event;
196
+ }
197
+ mergeFrom(match) {
198
+ this._startTime = match.startTime();
199
+ this._id = match.id();
200
+ this._league = match.league();
201
+ this._sport = match.sportType();
202
+ this._meta = {};
203
+ for (let key in match.meta()) {
204
+ this._meta[key] = match.meta()[key];
205
+ }
206
+ if (match.events() != null) {
207
+ for (let evt of match.events()) {
208
+ this._events[evt.id()] = evt;
209
+ }
210
+ }
211
+ let b2Match = match;
212
+ this._p1 = b2Match.participantOne();
213
+ this._p2 = b2Match.participantTwo();
214
+ }
215
+ replaceEvent(evt) {
216
+ this._events[evt.id()] = evt;
217
+ }
218
+ reset(key) {
219
+ // Check if you have state for this key
220
+ let incoming = key.toString();
221
+ let existing = this._meta[Const.AGGREGATE_KEY];
222
+ if (!codec_1.Util.containsKey(existing, incoming)) {
223
+ return null;
224
+ }
225
+ let removedDataMatchBuilder = BuilderProvider.getMatchBuilder(this.build());
226
+ // Remove Pkey from this and add it to removed eventbuilder
227
+ let removed = codec_1.Util.removeKey(existing, incoming);
228
+ this._meta[Const.AGGREGATE_KEY] = removed;
229
+ removedDataMatchBuilder._meta[Const.AGGREGATE_KEY] = incoming;
230
+ let updatedEvents = {};
231
+ removedDataMatchBuilder._events = {};
232
+ for (let eventId in this._events) {
233
+ let event = this._events[eventId];
234
+ let remainingEventbuilder = BuilderProvider.getEventBuilder(event);
235
+ let removedEventBldr = remainingEventbuilder.reset(key);
236
+ if (removedEventBldr != null && !removedEventBldr.isEmpty()) {
237
+ removedDataMatchBuilder.insertChild(removedEventBldr.build());
238
+ }
239
+ if (!remainingEventbuilder.isEmpty()) {
240
+ updatedEvents[event.id()] = remainingEventbuilder.build();
241
+ }
242
+ else {
243
+ delete updatedEvents[event.id()];
244
+ }
245
+ }
246
+ this._events = updatedEvents;
247
+ return removedDataMatchBuilder;
248
+ }
249
+ aggregateInsert(match) {
250
+ for (let key in match.meta()) {
251
+ // Copy everything except Aggregated key
252
+ if (!(key === Const.AGGREGATE_KEY)) {
253
+ this._meta[key] = match.meta()[key];
254
+ }
255
+ }
256
+ // Copy aggregate key information as it specifies this insert is from which partition
257
+ let incoming = match.meta()[Const.AGGREGATE_KEY];
258
+ let existing = this._meta[Const.AGGREGATE_KEY];
259
+ this._meta[Const.AGGREGATE_KEY] = codec_1.Util.addKey(existing, incoming);
260
+ }
261
+ aggregateUpdate(match) {
262
+ for (let key in match.meta()) {
263
+ // Copy everything except Aggregated key
264
+ if (!(key === Const.AGGREGATE_KEY)) {
265
+ this._meta[key] = match.meta()[key];
266
+ }
267
+ }
268
+ }
269
+ aggregateDelete(match) {
270
+ let incoming = match.meta()[Const.AGGREGATE_KEY];
271
+ let existing = this._meta[Const.AGGREGATE_KEY];
272
+ let removed = codec_1.Util.removeKey(existing, incoming);
273
+ this._meta[Const.AGGREGATE_KEY] = removed;
274
+ return removed === "";
275
+ }
276
+ isEmpty() {
277
+ let existing = this._meta[Const.AGGREGATE_KEY];
278
+ if (existing == null || existing == "") {
279
+ return true;
280
+ }
281
+ return false;
282
+ }
283
+ insertChild(inputEvent) {
284
+ // If event doesnt exists this is the first insert
285
+ let exist = this._events[inputEvent.id()];
286
+ let suppressEvent = null;
287
+ if (exist == null) {
288
+ this._events[inputEvent.id()] = inputEvent;
289
+ }
290
+ else {
291
+ // Clone the existing
292
+ let builder = BuilderProvider.getEventBuilder(exist);
293
+ builder.aggregateInsert(inputEvent);
294
+ this._events[inputEvent.id()] = builder.build();
295
+ suppressEvent = inputEvent.id();
296
+ }
297
+ return suppressEvent;
298
+ }
299
+ updateChild(updateEvent) {
300
+ let existing = this._events[updateEvent.id()];
301
+ if (existing == null) {
302
+ console.error("[UpdateEvent] Cannot found eventId %s to execute update event from %s", updateEvent.id(), updateEvent.meta()[Const.AGGREGATE_KEY]);
303
+ return;
304
+ }
305
+ let builder = BuilderProvider.getEventBuilder(existing);
306
+ builder.aggregateUpdate(updateEvent);
307
+ this._events[updateEvent.id()] = builder.build();
308
+ }
309
+ deleteChild(inputEvent) {
310
+ let existing = this._events[inputEvent.id()];
311
+ let suppressEvent = null;
312
+ if (existing == null) {
313
+ console.error("[DeleteEvent] Cannot found eventId %s to execute delete event from %s", inputEvent.id(), inputEvent.meta()[Const.AGGREGATE_KEY]);
314
+ return;
315
+ }
316
+ let builder = BuilderProvider.getEventBuilder(existing);
317
+ let isEmpty = builder.aggregateDelete(inputEvent);
318
+ if (isEmpty) {
319
+ delete this._events[inputEvent.id()];
320
+ }
321
+ else {
322
+ suppressEvent = inputEvent.id();
323
+ this._events[inputEvent.id()] = builder.build();
324
+ }
325
+ return suppressEvent;
326
+ }
327
+ build() {
328
+ throw new TypeError("Not supported in Abstract class");
329
+ }
330
+ }
331
+ class B2EventBuilder {
332
+ constructor(event) {
333
+ this._records = {};
334
+ this._states = {};
335
+ this.mergeFrom(event);
336
+ }
337
+ id() {
338
+ return this._id;
339
+ }
340
+ records() {
341
+ return this._records;
342
+ }
343
+ matchId() {
344
+ return this._matchId;
345
+ }
346
+ eventType() {
347
+ return this._eventType;
348
+ }
349
+ meta() {
350
+ return this._meta;
351
+ }
352
+ states() {
353
+ return this._states;
354
+ }
355
+ mergeFrom(t) {
356
+ let event = t;
357
+ this._id = t.id();
358
+ if (t.records() != null) {
359
+ for (let record of event.records()) {
360
+ let key = Const.generateKey(record);
361
+ this._records[key] = record;
362
+ }
363
+ }
364
+ this.setStates(event.eventStates());
365
+ this._matchId = t.matchId();
366
+ this._eventType = t.eventType();
367
+ this._meta = {};
368
+ for (let key in t.meta()) {
369
+ this._meta[key] = t.meta()[key];
370
+ }
371
+ }
372
+ setStates(states) {
373
+ if (states != null) {
374
+ for (let state of states) {
375
+ this._states[state.partitionKey().toString()] = state;
376
+ }
377
+ }
378
+ }
379
+ insertChild(rec) {
380
+ this._records[Const.generateKey(rec)] = rec;
381
+ return null;
382
+ }
383
+ updateChild(rec) {
384
+ let exist = this._records[Const.generateKey(rec)];
385
+ if (exist == null) {
386
+ console.error("[UpdateOdd] Cannot find record " + this._matchId + " " + this._id + " " + rec.source() + " " + rec.id());
387
+ return;
388
+ }
389
+ let builder = BuilderProvider.getRecordBuilder(exist);
390
+ builder.merge(rec);
391
+ this._records[Const.generateKey(exist)] = builder.build();
392
+ }
393
+ deleteChild(rec) {
394
+ delete this._records[Const.generateKey(rec)];
395
+ return null;
396
+ }
397
+ aggregateInsert(event) {
398
+ event.eventStates().forEach(state => {
399
+ this._states[state.partitionKey().toString()] = state;
400
+ });
401
+ }
402
+ aggregateUpdate(event) {
403
+ event.eventStates().forEach(state => {
404
+ this._states[state.partitionKey().toString()] = state;
405
+ });
406
+ }
407
+ aggregateDelete(event) {
408
+ event.eventStates().forEach(state => {
409
+ delete this._states[state.partitionKey().toString()];
410
+ });
411
+ return Object.keys(this._states).length == 0;
412
+ }
413
+ reset(key) {
414
+ if (this._states[key.toString()] == null) {
415
+ return null;
416
+ }
417
+ // Create remvoved event builder
418
+ let removedDataEventBuilder = BuilderProvider.getEventBuilder(this.build());
419
+ // Clear removed event's state
420
+ removedDataEventBuilder._states = {};
421
+ removedDataEventBuilder._records = {};
422
+ // Transfer Event State
423
+ let state = this._states[key.toString()];
424
+ removedDataEventBuilder._states[key.toString()] = state;
425
+ delete this._states[key.toString()];
426
+ // Remove records
427
+ let recKeys = Object.keys(this._records);
428
+ for (let recKey of recKeys) {
429
+ let rec = this._records[recKey];
430
+ if (rec.source() === key.source() && this.getOddTypeInt(rec.oddType()) === this.getOddTypeInt(key.oddType())) {
431
+ removedDataEventBuilder.insertChild(rec);
432
+ delete this._records[recKey];
433
+ }
434
+ }
435
+ return removedDataEventBuilder;
436
+ }
437
+ getOddTypeInt(oddType) {
438
+ if (isNaN(oddType)) {
439
+ return Number(jayeson_lib_record_1.OddType[oddType]);
440
+ }
441
+ else {
442
+ return Number(oddType);
443
+ }
444
+ }
445
+ isEmpty() {
446
+ if (this._states == null) {
447
+ return true;
448
+ }
449
+ return (Object.keys(this._states).length == 0);
450
+ }
451
+ build() {
452
+ throw new TypeError("Not Implemented for abstract class");
453
+ }
454
+ }
455
+ class B2EventStateBuilder {
456
+ constructor(state) {
457
+ this.mergeFrom(state);
458
+ }
459
+ statsOne() {
460
+ return this._statsOne;
461
+ }
462
+ stateTwo() {
463
+ return this._statsTwo;
464
+ }
465
+ duration() {
466
+ return this._duration;
467
+ }
468
+ key() {
469
+ return this._key;
470
+ }
471
+ matchId() {
472
+ return this._matchId;
473
+ }
474
+ eventId() {
475
+ return this._eventId;
476
+ }
477
+ createdTime() {
478
+ return this._createdTime;
479
+ }
480
+ build() {
481
+ throw new TypeError("UnSupported Operation in abstract class");
482
+ }
483
+ mergeFrom(state) {
484
+ let b2State = state;
485
+ this._statsOne = b2State.statsOne();
486
+ this._statsTwo = b2State.statsTwo();
487
+ this._duration = b2State.duration();
488
+ this._key = b2State.partitionKey();
489
+ this._matchId = b2State.matchId();
490
+ this._eventId = b2State.eventId();
491
+ this._createdTime = new Date().getMilliseconds();
492
+ }
493
+ merge(state) {
494
+ let b2State = state;
495
+ this.setStatsOne(b2State.statsOf(0));
496
+ this.setStatsTwo(b2State.statsOf(1));
497
+ this.setDuration(b2State.duration());
498
+ this.setEventId(b2State.eventId());
499
+ this.setMatchId(b2State.matchId());
500
+ this.setKey(b2State.partitionKey());
501
+ }
502
+ setStatsOne(stasOne) {
503
+ this._statsOne = stasOne;
504
+ }
505
+ setStatsTwo(stasTwo) {
506
+ this._statsTwo = stasTwo;
507
+ }
508
+ setDuration(duration) {
509
+ this._duration = duration;
510
+ }
511
+ setKey(key) {
512
+ this._key = key;
513
+ }
514
+ setMatchId(matchId) {
515
+ this._matchId = matchId;
516
+ }
517
+ setEventId(eventId) {
518
+ this._eventId = eventId;
519
+ }
520
+ setCreatedTime(createdTime) {
521
+ this._createdTime = createdTime;
522
+ }
523
+ }
524
+ class B2RecordBuilder {
525
+ constructor(rec) {
526
+ this.mergeFrom(rec);
527
+ }
528
+ eventId() {
529
+ return this._eventId;
530
+ }
531
+ matchId() {
532
+ return this._matchId;
533
+ }
534
+ id() {
535
+ return this._id;
536
+ }
537
+ oddType() {
538
+ return this._oddType;
539
+ }
540
+ lbType() {
541
+ return this._lbType;
542
+ }
543
+ timetype() {
544
+ return this._timetype;
545
+ }
546
+ sportbook() {
547
+ return this._sportbook;
548
+ }
549
+ meta() {
550
+ return this._meta;
551
+ }
552
+ oddFormat() {
553
+ return this._oddFormat;
554
+ }
555
+ rateOver() {
556
+ return this._rateOver;
557
+ }
558
+ rateUnder() {
559
+ return this._rateUnder;
560
+ }
561
+ rateEqual() {
562
+ return this._rateEqual;
563
+ }
564
+ pivotValue() {
565
+ return this._pivotValue;
566
+ }
567
+ pivotType() {
568
+ return this._pivotType;
569
+ }
570
+ pivotBias() {
571
+ return this._pivotBias;
572
+ }
573
+ rateOverId() {
574
+ return this._rateOverId;
575
+ }
576
+ rateUnderId() {
577
+ return this._rateUnderId;
578
+ }
579
+ rateEqualId() {
580
+ return this._rateEqualId;
581
+ }
582
+ isSwapped() {
583
+ return this._isSwapped;
584
+ }
585
+ setEventId(eventId) {
586
+ this._eventId = eventId;
587
+ }
588
+ setMatchId(matchId) {
589
+ this._matchId = matchId;
590
+ }
591
+ setId(id) {
592
+ this._id = id;
593
+ }
594
+ setOddType(oddType) {
595
+ this._oddType = oddType;
596
+ }
597
+ setLbType(lbType) {
598
+ this._lbType = lbType;
599
+ }
600
+ setTimeType(timetype) {
601
+ this._timetype = timetype;
602
+ }
603
+ setSportbook(sportbook) {
604
+ this._sportbook = sportbook;
605
+ }
606
+ setMeta(meta) {
607
+ this._meta = meta;
608
+ }
609
+ setOddFormat(oddFormat) {
610
+ this._oddFormat = oddFormat;
611
+ }
612
+ setRateOver(rateOver) {
613
+ this._rateOver = rateOver;
614
+ }
615
+ setRateUnder(rateUnder) {
616
+ this._rateUnder = rateUnder;
617
+ }
618
+ setRateEqual(rateEqual) {
619
+ this._rateEqual = rateEqual;
620
+ }
621
+ setPivotValue(pivotValue) {
622
+ this._pivotValue = pivotValue;
623
+ }
624
+ setPivotType(pivotType) {
625
+ this._pivotType = pivotType;
626
+ }
627
+ setPivotBias(pivotBias) {
628
+ this._pivotBias = pivotBias;
629
+ }
630
+ setRateOverId(rateOverId) {
631
+ this._rateOverId = rateOverId;
632
+ }
633
+ setRateUnderId(rateUnderId) {
634
+ this._rateUnderId = rateUnderId;
635
+ }
636
+ setRateEqualId(rateEqualId) {
637
+ this._rateEqualId = rateEqualId;
638
+ }
639
+ setSwapped(isSwapped) {
640
+ this._isSwapped = isSwapped;
641
+ }
642
+ build() {
643
+ throw new TypeError("UnSupported in Abstract class");
644
+ }
645
+ merge(rec) {
646
+ let b2Rec = rec;
647
+ this.setRateOver(b2Rec.rateOver());
648
+ this.setRateUnder(b2Rec.rateUnder());
649
+ this.setRateEqual(b2Rec.rateEqual());
650
+ if (b2Rec.rateOverId) {
651
+ this.setRateOverId(b2Rec.rateOverId());
652
+ }
653
+ if (b2Rec.rateUnderId) {
654
+ this.setRateOverId(b2Rec.rateUnderId());
655
+ }
656
+ if (b2Rec.rateEqualId) {
657
+ this.setRateOverId(b2Rec.rateEqualId());
658
+ }
659
+ }
660
+ mergeFrom(record) {
661
+ let rec = record;
662
+ this._eventId = rec.eventId();
663
+ this._matchId = rec.matchId();
664
+ this._id = rec.id();
665
+ this._oddType = rec.oddType();
666
+ this._lbType = rec.lbType();
667
+ this._timetype = rec.timeType();
668
+ this._sportbook = rec.source();
669
+ this._meta = rec.meta();
670
+ this._oddFormat = rec.oddFormat();
671
+ this._rateOver = rec.rateOver();
672
+ this._rateUnder = rec.rateUnder();
673
+ this._rateEqual = rec.rateEqual();
674
+ this._pivotValue = rec.pivotValue();
675
+ this._pivotType = rec.pivotType();
676
+ this._pivotBias = rec.pivotBias();
677
+ this._rateOverId = rec.rateOverId();
678
+ this._rateUnderId = rec.rateUnderId();
679
+ this._rateEqualId = rec.rateEqualId();
680
+ this._isSwapped = rec.isSwapped();
681
+ }
682
+ }
683
+ exports.B2RecordBuilder = B2RecordBuilder;
684
+ /*
685
+ * Builder is the "concrete" implementation of
686
+ * builders for every sport specific match event and record builders
687
+ */
688
+ var Builder;
689
+ (function (Builder) {
690
+ class Snapshot extends IndexedSnapshotBuilder {
691
+ constructor(input) {
692
+ super(input);
693
+ }
694
+ }
695
+ Builder.Snapshot = Snapshot;
696
+ })(Builder || (Builder = {}));
697
+ (function (Builder) {
698
+ var Match;
699
+ (function (Match) {
700
+ class Tennis extends B2MatchBuilder {
701
+ constructor(t) {
702
+ super(t);
703
+ }
704
+ setGender(_gender) {
705
+ this.gender = _gender;
706
+ }
707
+ setCountry(_country) {
708
+ this.country = _country;
709
+ }
710
+ mergeFrom(t) {
711
+ super.mergeFrom(t);
712
+ let tm = t;
713
+ this.setGender(tm.gender());
714
+ this.setCountry(tm.country());
715
+ }
716
+ build() {
717
+ let events = [];
718
+ for (let evt of Object.keys(this._events)) {
719
+ events.push(this._events[evt]);
720
+ }
721
+ return new jayeson_lib_record_1.TennisMatchImpl(this._p1, this._p2, this._startTime, events, this._id, this._league, this.gender, this.country, this._meta);
722
+ }
723
+ }
724
+ Match.Tennis = Tennis;
725
+ class Soccer extends B2MatchBuilder {
726
+ constructor(t) {
727
+ super(t);
728
+ }
729
+ leagueType() {
730
+ return this._leagueType;
731
+ }
732
+ gender() {
733
+ return this._gender;
734
+ }
735
+ country() {
736
+ return this._country;
737
+ }
738
+ setLeagueType(leagueType) {
739
+ this._leagueType = leagueType;
740
+ }
741
+ setGender(gender) {
742
+ this._gender = gender;
743
+ }
744
+ setCountry(country) {
745
+ this._country = country;
746
+ }
747
+ mergeFrom(t) {
748
+ super.mergeFrom(t);
749
+ let sm = t;
750
+ this.setLeagueType(sm.leagueType());
751
+ this.setCountry(t.country());
752
+ this.setGender(sm.gender());
753
+ }
754
+ build() {
755
+ let events = [];
756
+ for (let evt of Object.keys(this._events)) {
757
+ events.push(this._events[evt]);
758
+ }
759
+ return new jayeson_lib_record_1.SoccerMatchImpl(this._p1, this._p2, this._startTime, events, this._id, this._league, this._meta, this._leagueType, this._gender, this._country);
760
+ }
761
+ }
762
+ Match.Soccer = Soccer;
763
+ class Basketball extends B2MatchBuilder {
764
+ constructor(t) {
765
+ super(t);
766
+ }
767
+ gender() {
768
+ return this._gender;
769
+ }
770
+ country() {
771
+ return this._country;
772
+ }
773
+ setGender(gender) {
774
+ this._gender = gender;
775
+ }
776
+ setCountry(country) {
777
+ this._country = country;
778
+ }
779
+ build() {
780
+ let events = [];
781
+ for (let evt of Object.keys(this._events)) {
782
+ events.push(this._events[evt]);
783
+ }
784
+ return new jayeson_lib_record_1.BasketballMatchImpl(this._p1, this._p2, this._startTime, events, this._id, this._league, this._gender, this._country, this._meta);
785
+ }
786
+ mergeFrom(match) {
787
+ super.mergeFrom(match);
788
+ let bm = match;
789
+ this.setGender(bm.gender());
790
+ this.setCountry(bm.country());
791
+ }
792
+ }
793
+ Match.Basketball = Basketball;
794
+ })(Match = Builder.Match || (Builder.Match = {}));
795
+ })(Builder || (Builder = {}));
796
+ /**
797
+ * TODO Fis the way records and states are generated before building
798
+ */
799
+ (function (Builder) {
800
+ var Event;
801
+ (function (Event) {
802
+ class Tennis extends B2EventBuilder {
803
+ constructor(event) {
804
+ super(event);
805
+ }
806
+ build() {
807
+ let records = [];
808
+ for (let rec of Object.keys(this._records)) {
809
+ records.push(this._records[rec]);
810
+ }
811
+ let states = [];
812
+ for (let state of Object.keys(this._states)) {
813
+ states.push(this._states[state]);
814
+ }
815
+ return new jayeson_lib_record_1.TennisEventImpl(this._id, records, states, this._matchId, this._eventType, this._meta);
816
+ }
817
+ }
818
+ Event.Tennis = Tennis;
819
+ class Soccer extends B2EventBuilder {
820
+ constructor(event) {
821
+ super(event);
822
+ }
823
+ build() {
824
+ let records = [];
825
+ for (let rec of Object.keys(this._records)) {
826
+ records.push(this._records[rec]);
827
+ }
828
+ let states = [];
829
+ for (let state of Object.keys(this._states)) {
830
+ states.push(this._states[state]);
831
+ }
832
+ return new jayeson_lib_record_1.SoccerEventImpl(this._id, records, states, this._matchId, this._eventType, this._meta);
833
+ }
834
+ }
835
+ Event.Soccer = Soccer;
836
+ class Basketball extends B2EventBuilder {
837
+ constructor(event) {
838
+ super(event);
839
+ }
840
+ build() {
841
+ let records = [];
842
+ for (let rec of Object.keys(this._records)) {
843
+ records.push(this._records[rec]);
844
+ }
845
+ let states = [];
846
+ for (let state of Object.keys(this._states)) {
847
+ states.push(this._states[state]);
848
+ }
849
+ return new jayeson_lib_record_1.BasketballEventImpl(this._id, records, states, this._matchId, this._eventType, this._meta);
850
+ }
851
+ }
852
+ Event.Basketball = Basketball;
853
+ })(Event = Builder.Event || (Builder.Event = {}));
854
+ })(Builder || (Builder = {}));
855
+ (function (Builder) {
856
+ var Record;
857
+ (function (Record) {
858
+ class Tennis extends B2RecordBuilder {
859
+ constructor(rec) {
860
+ super(rec);
861
+ }
862
+ build() {
863
+ 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);
864
+ }
865
+ }
866
+ Record.Tennis = Tennis;
867
+ class Soccer extends B2RecordBuilder {
868
+ constructor(rec) {
869
+ super(rec);
870
+ }
871
+ build() {
872
+ 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);
873
+ }
874
+ }
875
+ Record.Soccer = Soccer;
876
+ class Basketball extends B2RecordBuilder {
877
+ constructor(rec) {
878
+ super(rec);
879
+ }
880
+ build() {
881
+ 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);
882
+ }
883
+ }
884
+ Record.Basketball = Basketball;
885
+ })(Record = Builder.Record || (Builder.Record = {}));
886
+ })(Builder || (Builder = {}));
887
+ (function (Builder) {
888
+ var EventState;
889
+ (function (EventState) {
890
+ class Soccer extends B2EventStateBuilder {
891
+ constructor(state) {
892
+ super(state);
893
+ }
894
+ build() {
895
+ 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);
896
+ }
897
+ setHostScore(hostScore) {
898
+ let list = this._statsOne.getScores();
899
+ list[0] = hostScore;
900
+ this._statsOne.setScores(list);
901
+ }
902
+ setHostCard(hostCard) {
903
+ let list = this._statsOne.getScores();
904
+ list[1] = hostCard;
905
+ this._statsOne.setScores(list);
906
+ }
907
+ setGuestScore(guestScore) {
908
+ let list = this._statsTwo.getScores();
909
+ list[0] = guestScore;
910
+ this._statsTwo.setScores(list);
911
+ }
912
+ setGuestCard(guestCard) {
913
+ let list = this._statsTwo.getScores();
914
+ list[1] = guestCard;
915
+ this._statsTwo.setScores(list);
916
+ }
917
+ setSegment(segment) {
918
+ this.segment = segment;
919
+ }
920
+ setBookPriority(bookPriority) {
921
+ this.bookPriority = bookPriority;
922
+ }
923
+ mergeFrom(eventState) {
924
+ super.mergeFrom(eventState);
925
+ let se = eventState;
926
+ this.setHostCard(se.hostCard());
927
+ this.setGuestCard(se.guestCard());
928
+ this.setHostScore(se.hostScore());
929
+ this.setGuestScore(se.guestScore());
930
+ this.setSegment(se.segment());
931
+ this.setBookPriority(se.bookPriority());
932
+ }
933
+ merge(state) {
934
+ super.merge(state);
935
+ let se = state;
936
+ if (se.segment != null) {
937
+ this.setSegment(se.segment());
938
+ }
939
+ }
940
+ }
941
+ EventState.Soccer = Soccer;
942
+ class Tennis extends B2EventStateBuilder {
943
+ constructor(state) {
944
+ super(state);
945
+ }
946
+ build() {
947
+ 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);
948
+ }
949
+ setSet(setScore) {
950
+ this.setScore = setScore;
951
+ }
952
+ setGame(game) {
953
+ this.game = game;
954
+ }
955
+ setBookPriority(bookPriority) {
956
+ this.bookPriority = bookPriority;
957
+ }
958
+ mergeFrom(state) {
959
+ super.mergeFrom(state);
960
+ let st = state;
961
+ this.setSet(st.set());
962
+ this.setGame(st.game());
963
+ this.setBookPriority(st.bookPriority());
964
+ }
965
+ }
966
+ EventState.Tennis = Tennis;
967
+ class Basketball extends B2EventStateBuilder {
968
+ constructor(state) {
969
+ super(state);
970
+ }
971
+ build() {
972
+ 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);
973
+ }
974
+ setSegment(segment) {
975
+ this.segment = segment;
976
+ }
977
+ setBookPriority(bookPriority) {
978
+ this.bookPriority = bookPriority;
979
+ }
980
+ setTimeout(isTimeout) {
981
+ this.isTimeout = isTimeout;
982
+ }
983
+ mergeFrom(state) {
984
+ super.mergeFrom(state);
985
+ //be: BasketballEventState = <BasketballEventState> state;
986
+ //TODO
987
+ //setSegment(be.getSegment());
988
+ //setTimeout(be.isTimeout());
989
+ //setBookPriority(be.bookPriority());
990
+ }
991
+ }
992
+ EventState.Basketball = Basketball;
993
+ })(EventState = Builder.EventState || (Builder.EventState = {}));
994
+ })(Builder || (Builder = {}));
995
+ /**
996
+ * TODO:
997
+ * Fix use SoccerMatch interface instead of
998
+ * Implementation to check type
999
+ */
1000
+ class BuilderProvider {
1001
+ static getMatchBuilder(match) {
1002
+ if (match instanceof jayeson_lib_record_1.SoccerMatchImpl) {
1003
+ return new Builder.Match.Soccer(match);
1004
+ }
1005
+ else if (match instanceof jayeson_lib_record_1.TennisMatchImpl) {
1006
+ return new Builder.Match.Tennis(match);
1007
+ }
1008
+ else if (match instanceof jayeson_lib_record_1.BasketballMatchImpl) {
1009
+ return new Builder.Match.Basketball(match);
1010
+ }
1011
+ else {
1012
+ throw new TypeError("Cannot Create Builder for " + match.constructor.toString());
1013
+ }
1014
+ }
1015
+ static getEventBuilder(event) {
1016
+ if (event instanceof jayeson_lib_record_1.SoccerEventImpl) {
1017
+ return new Builder.Event.Soccer(event);
1018
+ }
1019
+ else if (event instanceof jayeson_lib_record_1.TennisEventImpl) {
1020
+ return new Builder.Event.Tennis(event);
1021
+ }
1022
+ else if (event instanceof jayeson_lib_record_1.BasketballEventImpl) {
1023
+ return new Builder.Event.Basketball(event);
1024
+ }
1025
+ else {
1026
+ throw new TypeError("Cannot Create Builder for " + event.constructor.toString());
1027
+ }
1028
+ }
1029
+ static getRecordBuilder(record) {
1030
+ if (record instanceof jayeson_lib_record_1.SoccerRecord) {
1031
+ return new Builder.Record.Soccer(record);
1032
+ }
1033
+ else if (record instanceof jayeson_lib_record_1.TennisRecord) {
1034
+ return new Builder.Record.Tennis(record);
1035
+ }
1036
+ else if (record instanceof jayeson_lib_record_1.BasketballRecord) {
1037
+ return new Builder.Record.Basketball(record);
1038
+ }
1039
+ else {
1040
+ throw new TypeError("Cannot Create Builder for " + record.constructor.toString());
1041
+ }
1042
+ }
1043
+ static getEventStateBuilder(state) {
1044
+ if (state instanceof jayeson_lib_record_1.SoccerEventState) {
1045
+ return new Builder.EventState.Soccer(state);
1046
+ }
1047
+ else if (state instanceof jayeson_lib_record_1.TennisEventState) {
1048
+ return new Builder.EventState.Tennis(state);
1049
+ }
1050
+ else if (state instanceof jayeson_lib_record_1.BasketballEventState) {
1051
+ return new Builder.EventState.Basketball(state);
1052
+ }
1053
+ else {
1054
+ throw new TypeError("Cannot Create Builder for " + state.constructor.toString());
1055
+ }
1056
+ }
1057
+ static getSnapshotBuilder(parentSs) {
1058
+ return new Builder.Snapshot(parentSs);
1059
+ }
1060
+ }
1061
+ exports.BuilderProvider = BuilderProvider;