@jayesol/jayeson.lib.sports 2.2.4 → 2.2.5-beta.1205
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/README.md +113 -77
- package/lib/basketball_codec.d.ts +1 -1
- package/lib/basketball_codec.js +1 -1
- package/lib/client.d.ts +2 -2
- package/lib/client.js +1 -1
- package/lib/codec.d.ts +2 -2
- package/lib/codec.js +1 -1
- package/lib/core.d.ts +1 -1
- package/lib/core.js +1 -1
- package/lib/data_structure.d.ts +1 -1
- package/lib/data_structure.js +1 -1
- package/lib/dispatch.js +1 -1
- package/lib/index.js +1 -1
- package/lib/merge.d.ts +1 -1
- package/lib/merge.js +1 -1
- package/lib/message_class.d.ts +1 -1
- package/lib/message_class.js +1 -1
- package/lib/module.js +1 -1
- package/lib/mutable.d.ts +1 -1
- package/lib/mutable.js +1 -1
- package/lib/protobuf_bundle.d.ts +3 -409
- package/lib/protobuf_bundle.js +1 -1
- package/lib/receive.d.ts +1 -1
- package/lib/receive.js +1 -1
- package/lib/soccer_codec.d.ts +1 -1
- package/lib/soccer_codec.js +1 -1
- package/lib/tennis_codec.d.ts +1 -1
- package/lib/tennis_codec.js +1 -1
- package/package.json +49 -57
package/README.md
CHANGED
|
@@ -1,77 +1,113 @@
|
|
|
1
|
-
###
|
|
2
|
-
|
|
3
|
-
#### Packaging Structure
|
|
4
|
-
- Packages are classified into **"levels"**; **each vertical is a level. Veiwed from left to right**
|
|
5
|
-
- Arrows define dependency. E:g A -> B means A depend on B
|
|
6
|
-
- Any class can only depend on classes within it's package or classes from packages in previous levels
|
|
7
|
-
- There cannot be any dependency among packages of same level
|
|
8
|
-
|
|
9
|
-
#### Package-Info
|
|
10
|
-
- `jayeson.lib.sports.protobuf` - Classes generated by protobuf
|
|
11
|
-
- `jayeson.lib.sports.datastructure` - Core datastructure used across all classes
|
|
12
|
-
- `jayeson.lib.sports.filter` - Abstractions around IDataFilter combined with sport's datastructure
|
|
13
|
-
- `jayeson.lib.sports.mutable` - Provide Mutable builder's for jayeson.lib.record's datastructure
|
|
14
|
-
- `jayeson.lib.sports.util` - Static utility functions
|
|
15
|
-
- `jayeson.lib.sports.codec` - Definition of various message classes and logic to serialize data structure to Protibuf and vice versa
|
|
16
|
-
- `jayeson.lib.sports.core` - Core components used across whole library
|
|
17
|
-
- `jayeson.lib.sports.receive` - Implementation of logic to receive data from upstream
|
|
18
|
-
- `jayeson.lib.sports.receive.memory` - Implementation of logic to receive data in memory(E:g Bot)
|
|
19
|
-
- `jayeson.lib.sports.dispatch` - Abstractions for pushing received data downstream
|
|
20
|
-
- `jayeson.lib.sports.dispatch.relayer` - Abstratction to push data without any post-processing
|
|
21
|
-
- `jayeson.lib.sports.dispatch.
|
|
22
|
-
- `jayeson.lib.sports.dispatch.network` - Abstraction and logic to push data via network
|
|
23
|
-
- `jayeson.lib.sports.client` - Abstrations for end under to consume data
|
|
24
|
-
- `jayesib.lib.sports.module` - Various module bindings
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
+-------------------------------------------------------------------------------+
|
|
31
|
-
| |
|
|
32
|
-
| +-------------+ |
|
|
33
|
-
| | client +---------------------+ v
|
|
34
|
-
| +-------------+ | +-----------+
|
|
35
|
-
| +----+ | | filter +----------------+
|
|
36
|
-
| +---------------------+ | | | +-----------+ |
|
|
37
|
-
+--+ dispatch.
|
|
38
|
-
+---------------------+ +-------------+ +----------+ +-----------------+
|
|
39
|
-
+->| dispatch +---->| core +----+ +-----------+ | datastructure |
|
|
40
|
-
+--------------------+ | +-------------+ +----------+ |---->| mutable | +-----------------+
|
|
41
|
-
| dispatch.network +---+ | ^ ^ | +-----------+ ^
|
|
42
|
-
+--------------------+ | | | | | |
|
|
43
|
-
+--+ | | | +------------+
|
|
44
|
-
+-----------------+ +------------------+ | | | +-----------+ |
|
|
45
|
-
| | | dispatch.relayer +-------------------+ | |---->| util +-----+---+
|
|
46
|
-
| Module | +------------------+ | | +-----------+ | | +-----------------+
|
|
47
|
-
+-----------------+ | | | +-->| protobuf |
|
|
48
|
-
| | | +-----------------+
|
|
49
|
-
+-----------------+ +-------------+ | | +-----------+ |
|
|
50
|
-
| receive.memory +----------->| receive +------------> +---->| codec +-----+
|
|
51
|
-
+-----------------+ +-------------+ +-----------+
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
#### Message
|
|
55
|
-
|
|
56
|
-
Picture show how message gets
|
|
57
|
-
|
|
58
|
-

|
|
68
|
-
|
|
69
|
-
- Publish for non prod repo:
|
|
70
|
-
```
|
|
71
|
-
publish: snapshot
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
- Publish for production repo:
|
|
75
|
-
```
|
|
76
|
-
publish: prod
|
|
77
|
-
```
|
|
1
|
+
### Sportrelayereed
|
|
2
|
+
|
|
3
|
+
#### Packaging Structure
|
|
4
|
+
- Packages are classified into **"levels"**; **each vertical is a level. Veiwed from left to right**
|
|
5
|
+
- Arrows define dependency. E:g A -> B means A depend on B
|
|
6
|
+
- Any class can only depend on classes within it's package or classes from packages in previous levels
|
|
7
|
+
- There cannot be any dependency among packages of same level
|
|
8
|
+
|
|
9
|
+
#### Package-Info
|
|
10
|
+
- `jayeson.lib.sports.protobuf` - Classes generated by protobuf
|
|
11
|
+
- `jayeson.lib.sports.datastructure` - Core datastructure used across all classes
|
|
12
|
+
- `jayeson.lib.sports.filter` - Abstractions around IDataFilter combined with sport's datastructure
|
|
13
|
+
- `jayeson.lib.sports.mutable` - Provide Mutable builder's for jayeson.lib.record's datastructure
|
|
14
|
+
- `jayeson.lib.sports.util` - Static utility functions
|
|
15
|
+
- `jayeson.lib.sports.codec` - Definition of various message classes and logic to serialize data structure to Protibuf and vice versa
|
|
16
|
+
- `jayeson.lib.sports.core` - Core components used across whole library
|
|
17
|
+
- `jayeson.lib.sports.receive` - Implementation of logic to receive data from upstream
|
|
18
|
+
- `jayeson.lib.sports.receive.memory` - Implementation of logic to receive data in memory(E:g Bot)
|
|
19
|
+
- `jayeson.lib.sports.dispatch` - Abstractions for pushing received data downstream
|
|
20
|
+
- `jayeson.lib.sports.dispatch.relayer` - Abstratction to push data without any post-processing
|
|
21
|
+
- `jayeson.lib.sports.dispatch.tranrelayerorm` - Abstraction and logic to push data with post processing
|
|
22
|
+
- `jayeson.lib.sports.dispatch.network` - Abstraction and logic to push data via network
|
|
23
|
+
- `jayeson.lib.sports.client` - Abstrations for end under to consume data
|
|
24
|
+
- `jayesib.lib.sports.module` - Various module bindings
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
+-------------------------------------------------------------------------------+
|
|
31
|
+
| |
|
|
32
|
+
| +-------------+ |
|
|
33
|
+
| | client +---------------------+ v
|
|
34
|
+
| +-------------+ | +-----------+
|
|
35
|
+
| +----+ | | filter +----------------+
|
|
36
|
+
| +---------------------+ | | | +-----------+ |
|
|
37
|
+
+--+ dispatch.tranrelayerorm +-----+ v v v
|
|
38
|
+
+---------------------+ +-------------+ +----------+ +-----------------+
|
|
39
|
+
+->| dispatch +---->| core +----+ +-----------+ | datastructure |
|
|
40
|
+
+--------------------+ | +-------------+ +----------+ |---->| mutable | +-----------------+
|
|
41
|
+
| dispatch.network +---+ | ^ ^ | +-----------+ ^
|
|
42
|
+
+--------------------+ | | | | | |
|
|
43
|
+
+--+ | | | +------------+
|
|
44
|
+
+-----------------+ +------------------+ | | | +-----------+ |
|
|
45
|
+
| | | dispatch.relayer +-------------------+ | |---->| util +-----+---+
|
|
46
|
+
| Module | +------------------+ | | +-----------+ | | +-----------------+
|
|
47
|
+
+-----------------+ | | | +-->| protobuf |
|
|
48
|
+
| | | +-----------------+
|
|
49
|
+
+-----------------+ +-------------+ | | +-----------+ |
|
|
50
|
+
| receive.memory +----------->| receive +------------> +---->| codec +-----+
|
|
51
|
+
+-----------------+ +-------------+ +-----------+
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### Message Tranrelayerormation Flow
|
|
55
|
+
|
|
56
|
+
Picture show how message gets tranrelayerormed when they are passed from one component to other
|
|
57
|
+
|
|
58
|
+

|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
PS: Drawn using Gliffy. Get source diagram from jayeson's gliffy account
|
|
62
|
+
|
|
63
|
+
#### CI/CD guideline
|
|
64
|
+
|
|
65
|
+
##### Publish
|
|
66
|
+
|
|
67
|
+
Guideline: [CI/CD guideline](https://docs.jayeson.com.sg/ops/operations/gitlab-cicd/usage#how-to-use)
|
|
68
|
+
|
|
69
|
+
- Publish for non prod repo:
|
|
70
|
+
```
|
|
71
|
+
publish: snapshot
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- Publish for production repo:
|
|
75
|
+
```
|
|
76
|
+
publish: prod
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
##### Deployment
|
|
81
|
+
|
|
82
|
+
Deploy to:
|
|
83
|
+
|
|
84
|
+
- **MyTest**
|
|
85
|
+
```
|
|
86
|
+
deploy: myTestUnity # For deploy to relayer of Unity in MyUnity environment
|
|
87
|
+
or
|
|
88
|
+
deploy: myTestVodds # For deploy to relayer of Vodds in MyVodds environment
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
- **Staging** environment:
|
|
94
|
+
```
|
|
95
|
+
deploy: stagUnity # For deploy to relayer of Unity in Staging Unity environment
|
|
96
|
+
or
|
|
97
|
+
deploy: stagVodds # For deploy to relayer of Vodds in Staging Vodds environment
|
|
98
|
+
or
|
|
99
|
+
deploy: stagFeed # For deploy to relayer of Vodds in Staging Feed environment
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- **Production** environment:
|
|
104
|
+
```
|
|
105
|
+
deploy: prodUnity # For deploy to relayer of Unity in Production Unity environment
|
|
106
|
+
or
|
|
107
|
+
deploy: prodVodds # For deploy to relayer of Vodds in Production Vodds environment
|
|
108
|
+
or
|
|
109
|
+
deploy: prodFeed # For deploy to relayer of Vodds in Production Vodds environment
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
Note: To deploy to Kubernetes (k8s), need to add the parameter k8s: 1.
|
|
113
|
+
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IBetMatch, BasketballMatchImpl, BasketballEventState, PartitionKey } from '@
|
|
1
|
+
import { IBetMatch, BasketballMatchImpl, BasketballEventState, PartitionKey } from '@longchau/jayeson.lib.record';
|
|
2
2
|
import * as proto from './protobuf_bundle';
|
|
3
3
|
import { ICodec, EncodeAction, CodecHelper } from './codec';
|
|
4
4
|
export declare class BasketballCodec implements ICodec {
|
package/lib/basketball_codec.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});var jayeson_lib_record_1=require("@longchau/jayeson.lib.record"),proto=require("./protobuf_bundle"),codec_1=require("./codec"),BasketballCodec=(()=>{function e(e){void 0===e&&(e=new codec_1.CodecHelper),this.codecHelper=e}return e.prototype.decodeMatch=function(e,c,a,b){var i=this;return e.map(function(e){var a=c[e.participants[0]],t=c[e.participants[1]],r=c[e.id],o=i.codecHelper.coerceInt64(e.startTime),l=c[e.league],s=c[e.country],n=null,_={},e=(null!=e.metaInfo&&(_=e.metaInfo),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 _=i.codecHelper.populatePKIntoMetaInfo(_,b),new jayeson_lib_record_1.BasketballMatchImpl(a,t,o,[],r,l,n,s,_)})},e.prototype.decodeEvent=function(e,s,n,_){var a,c=this,t=[],b={};for(a in e.forEach(function(e){var a=s[e.id],t=e.metaInfo,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(c.decodeState(o,a,e.state,s,n,_)),new jayeson_lib_record_1.BasketballEventImpl(a,[],l,o,r,t));void 0===b[o]&&(b[o]=[]),b[o].push(e)}),b){var r=new jayeson_lib_record_1.BasketballMatchImpl("","",0,b[a],a,"",jayeson_lib_record_1.BasketballGender.MEN,"",{});t.push(r)}return t},e.prototype.decodeRecord=function(e,E,a,t){var r,u=this,o=[],j={};for(r in e.forEach(function(e){var a=u.codecHelper.coerceInt64(e.id),t=jayeson_lib_record_1.OddType[e.oddType.toString()],r=jayeson_lib_record_1.LBType[e.lbType.toString()],o=null,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=E[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()],b=jayeson_lib_record_1.PivotBias[e.pivotBias.toString()],i=e.basketballRecord,d=!1,i=(i&&(d=i.swapped),u.codecHelper.formatRate(e.rates[0])),p=u.codecHelper.formatRate(e.rates[1]),y=u.codecHelper.formatRate(e.rates[2]),T=E[e.rateIds[0]],k=E[e.rateIds[1]],v=E[e.rateIds[2]],B=E[e.eventId],e=E[e.matchId],a=new jayeson_lib_record_1.BasketballRecord(e,B,a,t,r,o,l,s,n,i,p,y,_,c,b,T,k,v,d);void 0===j[e]&&(j[e]={}),void 0===j[e][B]&&(j[e][B]=[]),j[e][B].push(a)}),j){var l,s=j[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},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()],b=_.timeout,i=t.participantStats[0].scores,d=t.participantStats[1].scores;if(i.length<7)for(var p=i.length,y=0;p+y<7;y++)i.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(i[0],i[1],i[2],i[3],i[4],i[5],i[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,b,_)},e})();exports.BasketballCodec=BasketballCodec;
|
package/lib/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IBetEvent, IBetMatch, IBetRecord, IBetEventState, ISnapshot, PartitionKey } from '@
|
|
1
|
+
import { IBetEvent, IBetMatch, IBetRecord, IBetEventState, ISnapshot, PartitionKey } from '@longchau/jayeson.lib.record';
|
|
2
2
|
import { IEndPointDispatcher, IEndPointGroupManager } from './dispatch';
|
|
3
3
|
import { FSRepo } from './core';
|
|
4
4
|
import { IMessageClass, Subscriber, EPEvent } from '@jayesol/jayeson.lib.delivery';
|
|
@@ -7,7 +7,7 @@ import { IndexedSnapshot, DeltaOutgoing, Outgoing, IndexedSnapshotImpl } from ".
|
|
|
7
7
|
import { InEndPointEventHandler, SportsFeedInProcessor } from "./receive";
|
|
8
8
|
import { SportsFeedMessageGroup } from "./message_class";
|
|
9
9
|
import 'reflect-metadata';
|
|
10
|
-
import { RuleCombination } from '@
|
|
10
|
+
import { RuleCombination } from '@longchau/jayeson.model';
|
|
11
11
|
export declare class InsertMatch<M extends IBetMatch> {
|
|
12
12
|
private _after;
|
|
13
13
|
private _get;
|
package/lib/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __extends=this&&this.__extends||function(){var n=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}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),__decorate=this&&this.__decorate||function(t,e,r,n){var s,i=arguments.length,o=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;0<=a;a--)(s=t[a])&&(o=(i<3?s(o):3<i?s(e,r,o):s(e,r))||o);return 3<i&&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,n){return function(t,e){n(t,e,r)}};Object.defineProperty(exports,"__esModule",{value:!0});var dispatch_1=require("./dispatch"),codec_1=require("./codec"),core_1=require("./core"),delivery=require("@jayesol/jayeson.lib.delivery"),jayeson_lib_delivery_1=require("@jayesol/jayeson.lib.delivery"),Collections=require("typescript-collections"),T=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(e){return this._handlers.some(function(t){return t.handler===e})},t.prototype.removeHandler=function(e){var t=this._handlers.find(function(t){return t.handler===e});if(void 0===t)return null;var r=this._handlers.indexOf(t);return this._handlers.splice(r,1),t.dispatch},t.prototype.handlerSize=function(){return this._handlers.length},t.prototype.cleanUp=function(){for(var t=0,e=this._handlers.slice(0);t<e.length;t++){var r=e[t];this.unregister(r.handler)}},t=__decorate([injection_js_1.Injectable(),__param(0,injection_js_1.Inject(dispatch_1.EPGM_IMPL)),__param(1,injection_js_1.Inject(core_1.FSREPO_IMPL)),__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}(),MemoryDispatcher=function(s){function t(t,e,r){var n=s.call(this,i.MEMORY_STREAM,e)||this;return n._fsRepo=t,n.lastPushedSs=data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT,n._grp=e,n._handler=r,n._id=delivery.generateUUID(),n}var i;return __extends(t,s),(i=t).prototype.grp=function(){return this._grp},t.prototype.handler=function(){return this._handler},t.prototype.id=function(){return this._id},t.prototype.submit=function(t){this.isInitialized().isFulfilled()&&this.isInitialized().value()&&this.handleMessage(t)},t.prototype.onException=function(t){console.error("Exception when dispatching outgoing messages to dispatchers:"+t)},t.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)}},t.prototype.pushSwitchFilterStart=function(t){this._handler.onSwitchFilterStart(t)},t.prototype.pushSwitchFilterEnd=function(){this._handler.onSwitchFilterEnd()},t.prototype.pushFullSnapshotStart=function(){this._handler.onFullSnapshotStart()},t.prototype.pushFullSnapshotEnd=function(){this._handler.onFullSnapshotEnd()},t.prototype.pushSwitchFilterFail=function(t){this._handler.onSwitchFilterFail(t)},t.prototype.pushInsertMatch=function(t){for(var e=[],r=[],n=0,s=t.delta().matches();n<s.length;n++){var i=s[n];t.before().hasMatch(i.id())?r.push(i):e.push(i)}if(0!=e.length){var o=new InsertMatch(t.after(),e);this._handler.onInsertMatch(o)}if(0!=r.length){var a=new UpdateMatch(t.after(),r);this._handler.onUpdateMatch(a)}},t.prototype.pushInsertEvent=function(t){for(var e=[],r=[],n=0,s=this.events(t.delta().matches());n<s.length;n++){var i=s[n],o=t.before().match(i.matchId());null!=o&&o.hasEvent(i.id())?r.push(i):e.push(i)}if(0!=e.length){var a=new InsertEvent(t.after(),e);this._handler.onInsertEvent(a)}if(0<r.length){var p=new UpdateEvent(t.after(),r);this._handler.onUpdateEvent(p)}},t.prototype.pushInsertOdd=function(t){var e=this.records(this.events(t.delta().matches()));if(0<e.length){var r=new InsertOdd(t.after(),e);this._handler.onInsertOdd(r)}},t.prototype.pushUpdateMatch=function(t){var e=t.delta().matches();if(0<e.length){var r=new UpdateMatch(t.after(),e);this._handler.onUpdateMatch(r)}},t.prototype.pushUpdateEvent=function(t){var e=this.events(t.delta().matches());if(0<e.length){var r=new UpdateEvent(t.after(),e);this._handler.onUpdateEvent(r)}},t.prototype.pushUpdateOdd=function(t){var e=this.records(this.events(t.delta().matches()));if(0<e.length){var r=new UpdateOdd(t.after(),e);this._handler.onUpdateOdd(r)}},t.prototype.pushDeleteMatch=function(t){for(var e=[],r=[],n=0,s=t.delta().matches();n<s.length;n++){var i=s[n];t.after().hasMatch(i.id())?e.push(i):r.push(i)}if(0!=r.length){var o=new DeleteMatch(t.after(),r);this._handler.onDeleteMatch(o)}if(0!=e.length){var a=new UpdateMatch(t.after(),e);this._handler.onUpdateMatch(a)}},t.prototype.pushDeleteEvent=function(t){for(var e=[],r=[],n=0,s=this.events(t.delta().matches());n<s.length;n++){var i=s[n],o=t.after().match(i.matchId());null!=o&&o.hasEvent(i.id())?e.push(i):r.push(i)}if(0!=r.length){var a=new DeleteEvent(t.after(),r);this._handler.onDeleteEvent(a)}if(0!=e.length){var p=new UpdateEvent(t.after(),e);this._handler.onUpdateEvent(p)}},t.prototype.pushDeleteOdd=function(t){var e=this.records(this.events(t.delta().matches()));if(0<e.length){var r=new DeleteOdd(t.after(),e);this._handler.onDeleteOdd(r)}},t.prototype.pushReset=function(t){var e=t.delta().getPartitions().toArray(),r=new Reset(t.after(),e);this._handler.onReset(r)},t.prototype.events=function(t){for(var e=[],r=0,n=t;r<n.length;r++)for(var s=0,i=n[r].events();s<i.length;s++){var o=i[s];e.push(o)}return e},t.prototype.records=function(t){for(var e=[],r=0,n=t;r<n.length;r++)for(var s=0,i=n[r].records();s<i.length;s++){var o=i[s];e.push(o)}return e},t.prototype.states=function(t){for(var e=[],r=0,n=t;r<n.length;r++)for(var s=0,i=n[r].eventStates();s<i.length;s++){var o=i[s];e.push(o)}return e},t.prototype.isSame=function(t,e){return t.id()==e.id()},t.prototype.isInitialized=function(){return this._fsRepo.isReady(this.stream())},t.MEMORY_STREAM="MEMORY_AGGREGATED_STREAM",t=i=__decorate([injection_js_1.Injectable(),__metadata("design:paramtypes",[Object,message_class_1.SportsFeedMessageGroup,Object])],t)}(exports.AbstractComparableEPDispatcher=AbstractComparableEPDispatcher);exports.MemoryDispatcher=MemoryDispatcher;var SportsFeedClient=function(){function t(t,e,r,n,s,i){this._subscriber=n,this._epgm=r,this._eventHandler=s,this.configureEventHandler(s),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,i.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){if(t instanceof jayeson_lib_delivery_1.Subscriber.Event.ConsumptionStart)for(var e=0,r=t.streams;e<r.length;e++){var n=r[e];console.log("ConsumptionsStartEvent for streams "+n+" from "+t.endPoint)}else if(t instanceof jayeson_lib_delivery_1.Subscriber.Event.ConsumptionError)for(var s=0,i=t.streams;s<i.length;s++){n=i[s];console.log("ConsumptionsStartEvent for streams "+n)}else console.log("Received event "+t+" from "+t.endPoint)},t.prototype.configureEventHandler=function(t){this._subscriber.attachListener(t)},t.prototype.setUpStreamFilter=function(t){var r=this;if(0===Object.keys(this._eventHandler.streamSources()).length){var e=new codec_1.FilterRequest(codec_1.FilterRequest.IGNORED_REQUEST_ID,t);this._eventHandler.updateFilter(e);var n=null,s=new T.Promise(function(t,e){n=t});return n(!0),s}var i=this.filterRequestCounter++,o=new codec_1.FilterRequest(i,t),a=new T.Promise(function(t,e){r.resolverMap.setValue(i,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=__decorate([injection_js_1.Injectable(),__param(1,injection_js_1.Inject(core_1.FSREPO_IMPL)),__param(2,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])],t)}();exports.SportsFeedClient=SportsFeedClient;
|
|
1
|
+
var __extends=this&&this.__extends||(()=>{var n=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}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}})(),__decorate=this&&this.__decorate||function(t,e,r,n){var s,o=arguments.length,i=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(t,e,r,n);else for(var p=t.length-1;0<=p;p--)(s=t[p])&&(i=(o<3?s(i):3<o?s(e,r,i):s(e,r))||i);return 3<o&&i&&Object.defineProperty(e,r,i),i},__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,n){return function(t,e){n(t,e,r)}},dispatch_1=(Object.defineProperty(exports,"__esModule",{value:!0}),require("./dispatch")),codec_1=require("./codec"),core_1=require("./core"),delivery=require("@jayesol/jayeson.lib.delivery"),jayeson_lib_delivery_1=require("@jayesol/jayeson.lib.delivery"),Collections=require("typescript-collections"),T=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")),InsertMatch=(()=>{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})(),UpdateMatch=(exports.InsertMatch=InsertMatch,(()=>{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})()),DeleteMatch=(exports.UpdateMatch=UpdateMatch,(()=>{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})()),InsertEvent=(exports.DeleteMatch=DeleteMatch,(()=>{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})()),UpdateEvent=(exports.InsertEvent=InsertEvent,(()=>{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})()),DeleteEvent=(exports.UpdateEvent=UpdateEvent,(()=>{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})()),InsertOdd=(exports.DeleteEvent=DeleteEvent,(()=>{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})()),UpdateOdd=(exports.InsertOdd=InsertOdd,(()=>{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})()),DeleteOdd=(exports.UpdateOdd=UpdateOdd,(()=>{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})()),Reset=(exports.DeleteOdd=DeleteOdd,(()=>{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})()),FeedView=(exports.Reset=Reset,(()=>{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){var e;this.hasHandler(t)?console.warn("Handler already registered."):(e=new MemoryDispatcher(this._fsRepo,this._grp,t),this._epgm.registerEPD(e),this._handlers.push(new HandlerDispatcherTuple(t,e)))},t.prototype.unregister=function(t){t=this.removeHandler(t);null!=t&&this._epgm.deregisterEPD(t)},t.prototype.hasHandler=function(e){return this._handlers.some(function(t){return t.handler===e})},t.prototype.removeHandler=function(e){var t,r=this._handlers.find(function(t){return t.handler===e});return void 0!==r?(t=this._handlers.indexOf(r),this._handlers.splice(t,1),r.dispatch):null},t.prototype.handlerSize=function(){return this._handlers.length},t.prototype.cleanUp=function(){for(var t=0,e=this._handlers.slice(0);t<e.length;t++){var r=e[t];this.unregister(r.handler)}},__decorate([injection_js_1.Injectable(),__param(0,injection_js_1.Inject(dispatch_1.EPGM_IMPL)),__param(1,injection_js_1.Inject(core_1.FSREPO_IMPL)),__metadata("design:paramtypes",[Object,Object,message_class_1.SportsFeedMessageGroup])],t)})()),HandlerDispatcherTuple=(exports.FeedView=FeedView,function(t,e){this.handler=t,this.dispatch=e}),AbstractComparableEPDispatcher=(()=>{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})(),MemoryDispatcher=(s=>{function t(t,e,r){var n=s.call(this,o.MEMORY_STREAM,e)||this;return n._fsRepo=t,n.lastPushedSs=data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT,n._grp=e,n._handler=r,n._id=delivery.generateUUID(),n}var o;return __extends(t,s),(o=t).prototype.grp=function(){return this._grp},t.prototype.handler=function(){return this._handler},t.prototype.id=function(){return this._id},t.prototype.submit=function(t){this.isInitialized().isFulfilled()&&this.isInitialized().value()&&this.handleMessage(t)},t.prototype.onException=function(t){console.error("Exception when dispatching outgoing messages to dispatchers:"+t)},t.prototype.handleMessage=function(t){var e;this.grp().isIndicatorMessage(t.msgType())?t.msgType()==this._grp.SWITCH_FILTER_START()?(e=Number(t.msg()),this.pushSwitchFilterStart(e)):t.msgType()==this._grp.SWITCH_FILTER_END()?this.pushSwitchFilterEnd():t.msgType()==this._grp.FULLSNAPSHOT_START()?this.pushFullSnapshotStart():t.msgType()==this._grp.FULLSNAPSHOT_END()?this.pushFullSnapshotEnd():t.msgType()==this._grp.SWITCH_FILTER_FAIL()?(e=Number(t.msg()),this.pushSwitchFilterFail(e)):t.msgType()==this._grp.TTL_RESTORE_START()?this.pushFullSnapshotStart():t.msgType()==this._grp.TTL_RESTORE_END()&&this.pushFullSnapshotEnd():this.isSame((e=t).msgType(),this._grp.DATA_INSERT_MATCH())?this.pushInsertMatch(e):this.isSame(e.msgType(),this._grp.DATA_INSERT_EVENT())?this.pushInsertEvent(e):this.isSame(e.msgType(),this._grp.DATA_INSERT_ODD())?this.pushInsertOdd(e):this.isSame(e.msgType(),this._grp.DATA_UPDATE_MATCH())?this.pushUpdateMatch(e):this.isSame(e.msgType(),this._grp.DATA_UPDATE_EVENT())?this.pushUpdateEvent(e):this.isSame(e.msgType(),this._grp.DATA_UPDATE_ODD())?this.pushUpdateOdd(e):this.isSame(e.msgType(),this._grp.DATA_DELETE_MATCH())?this.pushDeleteMatch(e):this.isSame(e.msgType(),this._grp.DATA_DELETE_EVENT())?this.pushDeleteEvent(e):this.isSame(e.msgType(),this._grp.DATA_DELETE_ODD())?this.pushDeleteOdd(e):this.isSame(e.msgType(),this._grp.DATA_RESET())&&this.pushReset(e)},t.prototype.pushSwitchFilterStart=function(t){this._handler.onSwitchFilterStart(t)},t.prototype.pushSwitchFilterEnd=function(){this._handler.onSwitchFilterEnd()},t.prototype.pushFullSnapshotStart=function(){this._handler.onFullSnapshotStart()},t.prototype.pushFullSnapshotEnd=function(){this._handler.onFullSnapshotEnd()},t.prototype.pushSwitchFilterFail=function(t){this._handler.onSwitchFilterFail(t)},t.prototype.pushInsertMatch=function(t){for(var e,r=[],n=[],s=0,o=t.delta().matches();s<o.length;s++){var i=o[s];(t.before().hasMatch(i.id())?n:r).push(i)}0!=r.length&&(e=new InsertMatch(t.after(),r),this._handler.onInsertMatch(e)),0!=n.length&&(e=new UpdateMatch(t.after(),n),this._handler.onUpdateMatch(e))},t.prototype.pushInsertEvent=function(t){for(var e,r=[],n=[],s=0,o=this.events(t.delta().matches());s<o.length;s++){var i=o[s],p=t.before().match(i.matchId());(null!=p&&p.hasEvent(i.id())?n:r).push(i)}0!=r.length&&(e=new InsertEvent(t.after(),r),this._handler.onInsertEvent(e)),0<n.length&&(e=new UpdateEvent(t.after(),n),this._handler.onUpdateEvent(e))},t.prototype.pushInsertOdd=function(t){var e=this.records(this.events(t.delta().matches()));0<e.length&&(t=new InsertOdd(t.after(),e),this._handler.onInsertOdd(t))},t.prototype.pushUpdateMatch=function(t){var e=t.delta().matches();0<e.length&&(t=new UpdateMatch(t.after(),e),this._handler.onUpdateMatch(t))},t.prototype.pushUpdateEvent=function(t){var e=this.events(t.delta().matches());0<e.length&&(t=new UpdateEvent(t.after(),e),this._handler.onUpdateEvent(t))},t.prototype.pushUpdateOdd=function(t){var e=this.records(this.events(t.delta().matches()));0<e.length&&(t=new UpdateOdd(t.after(),e),this._handler.onUpdateOdd(t))},t.prototype.pushDeleteMatch=function(t){for(var e,r=[],n=[],s=0,o=t.delta().matches();s<o.length;s++){var i=o[s];(t.after().hasMatch(i.id())?r:n).push(i)}0!=n.length&&(e=new DeleteMatch(t.after(),n),this._handler.onDeleteMatch(e)),0!=r.length&&(e=new UpdateMatch(t.after(),r),this._handler.onUpdateMatch(e))},t.prototype.pushDeleteEvent=function(t){for(var e,r=[],n=[],s=0,o=this.events(t.delta().matches());s<o.length;s++){var i=o[s],p=t.after().match(i.matchId());(null!=p&&p.hasEvent(i.id())?r:n).push(i)}0!=n.length&&(e=new DeleteEvent(t.after(),n),this._handler.onDeleteEvent(e)),0!=r.length&&(e=new UpdateEvent(t.after(),r),this._handler.onUpdateEvent(e))},t.prototype.pushDeleteOdd=function(t){var e=this.records(this.events(t.delta().matches()));0<e.length&&(t=new DeleteOdd(t.after(),e),this._handler.onDeleteOdd(t))},t.prototype.pushReset=function(t){var e=t.delta().getPartitions().toArray(),t=new Reset(t.after(),e);this._handler.onReset(t)},t.prototype.events=function(t){for(var e=[],r=0,n=t;r<n.length;r++)for(var s=0,o=n[r].events();s<o.length;s++){var i=o[s];e.push(i)}return e},t.prototype.records=function(t){for(var e=[],r=0,n=t;r<n.length;r++)for(var s=0,o=n[r].records();s<o.length;s++){var i=o[s];e.push(i)}return e},t.prototype.states=function(t){for(var e=[],r=0,n=t;r<n.length;r++)for(var s=0,o=n[r].eventStates();s<o.length;s++){var i=o[s];e.push(i)}return e},t.prototype.isSame=function(t,e){return t.id()==e.id()},t.prototype.isInitialized=function(){return this._fsRepo.isReady(this.stream())},t.MEMORY_STREAM="MEMORY_AGGREGATED_STREAM",o=__decorate([injection_js_1.Injectable(),__metadata("design:paramtypes",[Object,message_class_1.SportsFeedMessageGroup,Object])],t)})(exports.AbstractComparableEPDispatcher=AbstractComparableEPDispatcher),SportsFeedClient=(exports.MemoryDispatcher=MemoryDispatcher,(()=>{function t(t,e,r,n,s,o){this._subscriber=n,this._epgm=r,this._eventHandler=s,this.configureEventHandler(s),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,o.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){if(t instanceof jayeson_lib_delivery_1.Subscriber.Event.ConsumptionStart)for(var e=0,r=t.streams;e<r.length;e++){var n=r[e];console.log("ConsumptionsStartEvent for streams "+n+" from "+t.endPoint)}else if(t instanceof jayeson_lib_delivery_1.Subscriber.Event.ConsumptionError)for(var s=0,o=t.streams;s<o.length;s++){n=o[s];console.log("ConsumptionsStartEvent for streams "+n)}else console.log("Received event "+t+" from "+t.endPoint)},t.prototype.configureEventHandler=function(t){this._subscriber.attachListener(t)},t.prototype.setUpStreamFilter=function(t){var r,n,e,s=this;return 0===Object.keys(this._eventHandler.streamSources()).length?(e=new codec_1.FilterRequest(codec_1.FilterRequest.IGNORED_REQUEST_ID,t),this._eventHandler.updateFilter(e),r=null,e=new T.Promise(function(t,e){r=t}),r(!0),e):(n=this.filterRequestCounter++,e=new codec_1.FilterRequest(n,t),t=new T.Promise(function(t,e){s.resolverMap.setValue(n,t)}),this._eventHandler.updateFilter(e),t)},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(){},__decorate([injection_js_1.Injectable(),__param(1,injection_js_1.Inject(core_1.FSREPO_IMPL)),__param(2,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])],t)})());exports.SportsFeedClient=SportsFeedClient;
|
package/lib/codec.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="long" />
|
|
2
2
|
import * as proto from "./protobuf_bundle";
|
|
3
|
-
import * as rec from "@
|
|
4
|
-
import { RuleCombination } from "@
|
|
3
|
+
import * as rec from "@longchau/jayeson.lib.record";
|
|
4
|
+
import { RuleCombination } from "@longchau/jayeson.model";
|
|
5
5
|
export declare enum EncodeAction {
|
|
6
6
|
INSERT = 0,
|
|
7
7
|
UPDATE = 1,
|
package/lib/codec.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});var EncodeAction,mutable_1=require("./mutable"),CodecHelper=((e=>{e[e.INSERT=0]="INSERT",e[e.UPDATE=1]="UPDATE",e[e.DELETE=2]="DELETE"})(EncodeAction=exports.EncodeAction||(exports.EncodeAction={})),(()=>{function e(){}return e.prototype.coerceInt64=function(e){return e.toNumber?e.toNumber():e},e.prototype.populatePKIntoMetaInfo=function(e,t){return e[mutable_1.Const.AGGREGATE_KEY]=t.toString(),e},e.prototype.formatRate=function(e){return Math.round(1e4*e)/1e4},e})()),FilterRequest=(exports.CodecHelper=CodecHelper,(()=>{function e(e,t){this._requestId=e,this._ruleCombination=t}return e.prototype.getRequestId=function(){return this._requestId},e.prototype.getFilterData=function(){return this._ruleCombination},e.prototype.toJSON=function(){return{requestId:this.getRequestId(),namespace:this._ruleCombination.namespace,filterRules:this._ruleCombination.filterRules}},e.IGNORED_REQUEST_ID=-1,e})()),Util=(exports.FilterRequest=FilterRequest,(()=>{function a(){}return a.addKey=function(e,t){if(-1!=t.search(a.SEPARATOR))throw new TypeError("Incoming String cannot contain Separator: "+a.SEPARATOR+" Incoming: "+t);return 0==e.length?t:-1===e.indexOf(t)?e+a.SEPARATOR+t:e},a.removeKey=function(e,t){var n=e.split(a.SEPARATOR),e=t.split(a.SEPARATOR);n.sort();for(var r=0,o=e;r<o.length;r++){var i=o[r],i=n.indexOf(i);if(!(i<0)&&(n.splice(i,1),0==n.length))return""}for(var u=n[0],c=1;c<n.length;c++)u=a.addKey(u,n[c]);return u},a.containsKey=function(e,t){if(null==e)return!1;if(-1!=t.search(a.SEPARATOR))throw new TypeError("Incoming String cannot contain Separator: "+a.SEPARATOR+" Incoming: "+t);return!(e.split(a.SEPARATOR).indexOf(t)<0)},a.SEPARATOR=",",a})());exports.Util=Util;
|
package/lib/core.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as Collections from 'typescript-collections';
|
|
|
4
4
|
import * as T from 'ts-promise';
|
|
5
5
|
import 'reflect-metadata';
|
|
6
6
|
import { InjectionToken } from 'injection-js';
|
|
7
|
-
import { PartitionKey, IBetMatch } from "@
|
|
7
|
+
import { PartitionKey, IBetMatch } from "@longchau/jayeson.lib.record";
|
|
8
8
|
import { SportsFeedMessageGroup } from "./message_class";
|
|
9
9
|
import { MergeableWrapper, TTLWrapper } from "./data_structure";
|
|
10
10
|
export interface ISnapshotHandler {
|
package/lib/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __extends=this&&this.__extends||function(){var n=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}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),__decorate=this&&this.__decorate||function(t,e,r,n){var o,i=arguments.length,s=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;0<=a;a--)(o=t[a])&&(s=(i<3?o(s):3<i?o(e,r,s):o(e,r))||s);return 3<i&&s&&Object.defineProperty(e,r,s),s},__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,n){return function(t,e){n(t,e,r)}};Object.defineProperty(exports,"__esModule",{value:!0});var data_structure_1=require("./data_structure"),Collections=require("typescript-collections"),T=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=__decorate([injection_js_1.Injectable(),__metadata("design:paramtypes",[])],t)}(),FSRepoImpl=function(o){function t(t,e){var r=o.call(this)||this;r.outputStreamName=t,r.sportsGroup=e,r._head=null;var n=r;return r.fssEndReceived=new T.Promise(function(t,e){n.promiseResolver=t,n.promiseRejector=e}),r}var e;return __extends(t,o),(e=t).prototype.head=function(){return this._head},t.prototype.appendSnapshot=function(t,e){return null==this._head?this.result=e.apply(null):this.result=e.apply(this._head),this._head=this.result.getAfter(),this.result.getDeltaOut()},t.prototype.getSnapshot=function(t){return void 0===t&&(t=""),null==this._head?data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT:this._head},t.prototype.getTtlRemoveSnapshot=function(){return null==this._head?[]:[new TTLRemoveCheck(null,this._head.getPartitions().toArray(),this.outputStreamName)]},t.prototype.push=function(e){if(e.msgType()==this.sportsGroup.FULLSNAPSHOT_START());else if(e.msgType()==this.sportsGroup.FULLSNAPSHOT_END())this.promiseResolver(!0);else{var r=this;this._handlers.forEach(function(t){t.process(r.outputStreamName,e)})}},t.prototype.isReady=function(t){return this.fssEndReceived},t.outputStream=new injection_js_1.InjectionToken("aggregatedStreamName"),t=e=__decorate([injection_js_1.Injectable(),__param(0,injection_js_1.Inject(e.outputStream)),__metadata("design:paramtypes",[String,message_class_1.SportsFeedMessageGroup])],t)}(exports.AbstractFSRepo=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=__decorate([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(i){function t(t,e,r,n){var o=i.call(this,e,r,n)||this;return o.ttlType=t,o}return __extends(t,i),t.prototype.getTtlType=function(){return this.ttlType},t}(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 e=new Collections.Dictionary;return this.keys.forEach(function(t){e.setValue(t,(new Date).getTime())}),e},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}(),TTLRestoreCheck=function(n){function t(t,e,r){return n.call(this,TTLType.RESTORE,t,e,r)||this}return __extends(t,n),t.prototype.apply=function(t){var n=this,o=t,i=!1,s=new Collections.Dictionary,a={},p=[];this.getKeys().forEach(function(t,e){if(n.getRecycleBin().containData(t)){i=!0;var r=(new Date).getTime();s.setValue(t,r),a=n.getRecycleBin().copyData(t,a),n.ttlRestoreWrapper=n.getRecycleBin().restoreData(new data_structure_2.TTLWrapper,o,t,r),o=n.ttlRestoreWrapper.getRemainingSs(),p.push(n.ttlRestoreWrapper.getRestoredSs())}});var e=[],r=new data_structure_2.MergeableWrapper;if(r.setAfter(o),i)return console.log("restore -----\x3e"+JSON.stringify(s.keys())),merge_1.DeltaTransformingLogicImpl.transformTTLRestore(p,this.getRecycleBin().getGrp(),this.getStream(),t,o,a,s);var c=new data_structure_1.Incoming(this.getRecycleBin().getGrp().ADMIN_REFRESH(),this.getStream(),new data_structure_1.IndexedSnapshotImpl(a,this.getKeysMapping()));return e.push(new TTLOutgoing(this.getTtlType(),c,o,t)),r.setDeltaOut(e),r},t}(exports.TTLCheck=TTLCheck);exports.TTLRestoreCheck=TTLRestoreCheck;var TTLRemoveCheck=function(n){function t(t,e,r){return n.call(this,TTLType.REMOVE,t,e,r)||this}return __extends(t,n),t.prototype.apply=function(t){for(var e=t.getPartitionMap(),r=new Collections.Dictionary,n=t,o=[],i=this.getRecycleBin().getTtlConfig(),s=!1,a=0,p=this.getKeys();a<p.length;a++){var c=p[a],u=0;if(e.containsKey(c)){switch(c.oddType()){case jayeson_lib_record_1.OddType.LIVE:u=e.getValue(c)+i.getLivettl();break;case jayeson_lib_record_1.OddType.TODAY:u=e.getValue(c)+i.getTodayttl();break;case jayeson_lib_record_1.OddType.EARLY:u=e.getValue(c)+i.getEarlyttl()}u<(new Date).getTime()&&(s=!0,r.setValue(c,e.getValue(c)),this.ttlRemoveWrapper=this.getRecycleBin().removeData(new data_structure_2.TTLWrapper,n,c),n=this.ttlRemoveWrapper.getRemainingSs(),o.push(this.ttlRemoveWrapper.getRemovedSs()))}}var l=[];if(s)return console.log("reseting -----\x3e"+JSON.stringify(r.keys())),merge_1.DeltaTransformingLogicImpl.transformTTLRemove(o,this.getRecycleBin().getGrp(),this.getStream(),t,n,r);var h=new data_structure_2.MergeableWrapper,g=new data_structure_1.Incoming(this.getRecycleBin().getGrp().ADMIN_REFRESH(),this.getStream(),new data_structure_1.IndexedSnapshotImpl({},this.getKeysMapping()));return l.push(new TTLOutgoing(this.getTtlType(),g,n,t)),h.setDeltaOut(l),h.setAfter(n),h},t}(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(),i=n.build();return this.expiredMatches.setValue(r,o),t.setRemovedSs(o),t.setRemainingSs(i),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 i=mutable_1.BuilderProvider.getSnapshotBuilder(o);return i.markPartitionAsUpdated(r,n),o=i.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(n){var o=this,i=null;return this.ttlStatus.isEmpty()||(this.getGrp().DATA_RESET().id()==n.msgType().id()?n.data().getPartitions().forEach(function(t){console.log("Dropping partition "+t),o.expiredMatches.remove(t)}):n.data().getPartitionMap().forEach(function(t,e){var r=[];o.ttlStatus.contains(t)&&(o.ttlStatus.remove(t),r.push(t)),0<r.length&&(i=new TTLRestoreCheck(o,r,n.stream()))})),i},t.prototype.getTtlRemoveSnapshot=function(){var e=this,t=this.getFsRepo().getTtlRemoveSnapshot();return t.forEach(function(t){t.setRecycleBin(e),t.getKeys().forEach(function(t){e.ttlStatus.add(t)})}),t},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=__decorate([injection_js_1.Injectable(),__metadata("design:paramtypes",[TTLConfig,message_class_1.SportsFeedMessageGroup,AbstractFSRepo])],t)}();exports.RecycleBin=RecycleBin;
|
|
1
|
+
var TTLType,__extends=this&&this.__extends||(()=>{var n=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}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}})(),__decorate=this&&this.__decorate||function(t,e,r,n){var o,s=arguments.length,i=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;0<=a;a--)(o=t[a])&&(i=(s<3?o(i):3<s?o(e,r,i):o(e,r))||i);return 3<s&&i&&Object.defineProperty(e,r,i),i},__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,n){return function(t,e){n(t,e,r)}},data_structure_1=(Object.defineProperty(exports,"__esModule",{value:!0}),require("./data_structure")),Collections=require("typescript-collections"),T=require("ts-promise"),injection_js_1=(require("reflect-metadata"),require("injection-js")),jayeson_lib_record_1=require("@longchau/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"),(()=>{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},__decorate([injection_js_1.Injectable(),__metadata("design:paramtypes",[])],t)})()),FSRepoImpl=(o=>{function t(t,e){var r=o.call(this)||this,n=(r.outputStreamName=t,r.sportsGroup=e,r._head=null,r);return r.fssEndReceived=new T.Promise(function(t,e){n.promiseResolver=t,n.promiseRejector=e}),r}var e;return __extends(t,o),(e=t).prototype.head=function(){return this._head},t.prototype.appendSnapshot=function(t,e){return null==this._head?this.result=e.apply(null):this.result=e.apply(this._head),this._head=this.result.getAfter(),this.result.getDeltaOut()},t.prototype.getSnapshot=function(t){return void 0===t&&(t=""),null==this._head?data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT:this._head},t.prototype.getTtlRemoveSnapshot=function(){return null==this._head?[]:[new TTLRemoveCheck(null,this._head.getPartitions().toArray(),this.outputStreamName)]},t.prototype.push=function(e){var r;e.msgType()!=this.sportsGroup.FULLSNAPSHOT_START()&&(e.msgType()==this.sportsGroup.FULLSNAPSHOT_END()?this.promiseResolver(!0):(r=this)._handlers.forEach(function(t){t.process(r.outputStreamName,e)}))},t.prototype.isReady=function(t){return this.fssEndReceived},t.outputStream=new injection_js_1.InjectionToken("aggregatedStreamName"),e=__decorate([injection_js_1.Injectable(),__param(0,injection_js_1.Inject(e.outputStream)),__metadata("design:paramtypes",[String,message_class_1.SportsFeedMessageGroup])],t)})(exports.AbstractFSRepo=AbstractFSRepo),Delta=(exports.FSRepoImpl=FSRepoImpl,(()=>{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})()),TTLConfig=(exports.Delta=Delta,(()=>{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(){var t,e,r;return this.enableTtl?(r=this.getLivettl(),t=this.getTodayttl(),e=this.getEarlyttl(),(r=Math.min(r,t,e)/2)<1e3?1e4:r):-1},t.prototype.isEnableTtl=function(){return this.enableTtl},t.prototype.setEnableTtl=function(t){this.enableTtl=t},__decorate([injection_js_1.Injectable()],t)})()),TTLOutgoing=(exports.TTLConfig=TTLConfig,(t=>{t[t.REMOVE=0]="REMOVE",t[t.RESTORE=1]="RESTORE"})(TTLType=exports.TTLType||(exports.TTLType={})),(o=>{function t(t,e,r,n){e=o.call(this,e,r,n)||this;return e.ttlType=t,e}return __extends(t,o),t.prototype.getTtlType=function(){return this.ttlType},t})(Delta)),TTLCheck=(exports.TTLOutgoing=TTLOutgoing,(()=>{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 e=new Collections.Dictionary;return this.keys.forEach(function(t){e.setValue(t,(new Date).getTime())}),e},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})()),TTLRestoreCheck=(n=>{function t(t,e,r){return n.call(this,TTLType.RESTORE,t,e,r)||this}return __extends(t,n),t.prototype.apply=function(t){var e,n=this,o=t,s=!1,i=new Collections.Dictionary,a={},p=[],r=(this.getKeys().forEach(function(t,e){var r;n.getRecycleBin().containData(t)&&(s=!0,r=(new Date).getTime(),i.setValue(t,r),a=n.getRecycleBin().copyData(t,a),n.ttlRestoreWrapper=n.getRecycleBin().restoreData(new data_structure_2.TTLWrapper,o,t,r),o=n.ttlRestoreWrapper.getRemainingSs(),p.push(n.ttlRestoreWrapper.getRestoredSs()))}),[]),c=new data_structure_2.MergeableWrapper;return c.setAfter(o),s?(console.log("restore -----\x3e"+JSON.stringify(i.keys())),merge_1.DeltaTransformingLogicImpl.transformTTLRestore(p,this.getRecycleBin().getGrp(),this.getStream(),t,o,a,i)):(e=new data_structure_1.Incoming(this.getRecycleBin().getGrp().ADMIN_REFRESH(),this.getStream(),new data_structure_1.IndexedSnapshotImpl(a,this.getKeysMapping())),r.push(new TTLOutgoing(this.getTtlType(),e,o,t)),c.setDeltaOut(r),c)},t})(exports.TTLCheck=TTLCheck),TTLRemoveCheck=(exports.TTLRestoreCheck=TTLRestoreCheck,(n=>{function t(t,e,r){return n.call(this,TTLType.REMOVE,t,e,r)||this}return __extends(t,n),t.prototype.apply=function(t){for(var e=t.getPartitionMap(),r=new Collections.Dictionary,n=t,o=[],s=this.getRecycleBin().getTtlConfig(),i=!1,a=0,p=this.getKeys();a<p.length;a++){var c=p[a],l=0;if(e.containsKey(c)){switch(c.oddType()){case jayeson_lib_record_1.OddType.LIVE:l=e.getValue(c)+s.getLivettl();break;case jayeson_lib_record_1.OddType.TODAY:l=e.getValue(c)+s.getTodayttl();break;case jayeson_lib_record_1.OddType.EARLY:l=e.getValue(c)+s.getEarlyttl()}l<(new Date).getTime()&&(i=!0,r.setValue(c,e.getValue(c)),this.ttlRemoveWrapper=this.getRecycleBin().removeData(new data_structure_2.TTLWrapper,n,c),n=this.ttlRemoveWrapper.getRemainingSs(),o.push(this.ttlRemoveWrapper.getRemovedSs()))}}var u,h,g=[];return i?(console.log("reseting -----\x3e"+JSON.stringify(r.keys())),merge_1.DeltaTransformingLogicImpl.transformTTLRemove(o,this.getRecycleBin().getGrp(),this.getStream(),t,n,r)):(u=new data_structure_2.MergeableWrapper,h=new data_structure_1.Incoming(this.getRecycleBin().getGrp().ADMIN_REFRESH(),this.getStream(),new data_structure_1.IndexedSnapshotImpl({},this.getKeysMapping())),g.push(new TTLOutgoing(this.getTtlType(),h,n,t)),u.setDeltaOut(g),u.setAfter(n),u)},t})(TTLCheck)),RecycleBin=(exports.TTLRemoveCheck=TTLRemoveCheck,(()=>{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){var n,o;return e.getPartitions().contains(r)?(n=(o=mutable_1.BuilderProvider.getSnapshotBuilder(e)).reset(r).build(),o=o.build(),this.expiredMatches.setValue(r,n),t.setRemovedSs(n),t.setRemainingSs(o)):(t.setRemainingSs(e),t.setRemovedSs(null)),t},t.prototype.restoreData=function(t,e,r,n){var o,s=this.expiredMatches.getValue(r);return null==s?(t.setRemainingSs(e),t.setRestoredSs(null)):((new Collections.Dictionary).setValue(r,n),(o=mutable_1.BuilderProvider.getSnapshotBuilder(s)).markPartitionAsUpdated(r,n),s=o.build(),e=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_MATCH(),s,e).getAfterSs(),e=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_EVENT(),s,e).getAfterSs(),e=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_ODD(),s,e).getAfterSs(),t.setRestoredSs(s),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(n){var o=this,s=null;return this.ttlStatus.isEmpty()||(this.getGrp().DATA_RESET().id()==n.msgType().id()?n.data().getPartitions().forEach(function(t){console.log("Dropping partition "+t),o.expiredMatches.remove(t)}):n.data().getPartitionMap().forEach(function(t,e){var r=[];o.ttlStatus.contains(t)&&(o.ttlStatus.remove(t),r.push(t)),0<r.length&&(s=new TTLRestoreCheck(o,r,n.stream()))})),s},t.prototype.getTtlRemoveSnapshot=function(){var e=this,t=this.getFsRepo().getTtlRemoveSnapshot();return t.forEach(function(t){t.setRecycleBin(e),t.getKeys().forEach(function(t){e.ttlStatus.add(t)})}),t},t.prototype.copyData=function(t,e){t=this.expiredMatches.getValue(t);return void 0===t?e:(e=new data_structure_1.IndexedSnapshotImpl(e),e=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_MATCH(),t,e).getAfterSs(),e=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_EVENT(),t,e).getAfterSs(),(e=merge_1.SnapshotUtil.combineSnapshots(this.getGrp().DATA_INSERT_ODD(),t,e).getAfterSs()).matchesSport)},t.prototype.getGrp=function(){return this.grp},__decorate([injection_js_1.Injectable(),__metadata("design:paramtypes",[TTLConfig,message_class_1.SportsFeedMessageGroup,AbstractFSRepo])],t)})());exports.RecycleBin=RecycleBin;
|
package/lib/data_structure.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Collections from 'typescript-collections';
|
|
2
2
|
import { IMessageClass } from "@jayesol/jayeson.lib.delivery";
|
|
3
|
-
import { ISnapshot, Snapshot, PartitionKey, IBetMatch } from "@
|
|
3
|
+
import { ISnapshot, Snapshot, PartitionKey, IBetMatch } from "@longchau/jayeson.lib.record";
|
|
4
4
|
export declare class Incoming {
|
|
5
5
|
private _msgType;
|
|
6
6
|
private _stream;
|
package/lib/data_structure.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var ConvertedMsg,__extends=this&&this.__extends||(()=>{var r=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])});return function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}})(),Collections=(Object.defineProperty(exports,"__esModule",{value:!0}),require("typescript-collections")),jayeson_lib_record_1=require("@longchau/jayeson.lib.record"),Incoming=(()=>{function t(t,e,n){this._msgType=t,this._stream=e,this._data=n}return t.prototype.msgType=function(){return this._msgType},t.prototype.stream=function(){return this._stream},t.prototype.data=function(){return this._data},t})(),IndexedSnapshotImpl=(exports.Incoming=Incoming,(n=>{function t(t,e){void 0===t&&(t={}),void 0===e&&(e=new Collections.Dictionary);t=n.call(this,t)||this;return t.partitions=e,t}return __extends(t,n),t.prototype.getPartitions=function(){for(var t=new Collections.Set,e=0,n=this.partitions.keys();e<n.length;e++){var r=n[e];t.add(r)}return t},t.prototype.getPartitionMap=function(){return this.partitions},t.EMPTY_SNAPSHOT=new t,t})(jayeson_lib_record_1.Snapshot)),OutgoingImpl=(exports.IndexedSnapshotImpl=IndexedSnapshotImpl,(()=>{function t(t,e){this._msgType=t,this._msg=e}return t.prototype.msgType=function(){return this._msgType},t.prototype.msg=function(){return this._msg},t})()),DeltaOutgoingImpl=(o=>{function t(t,e,n,r){t=o.call(this,t,e)||this;return t._delta=e,t._after=n,t._before=r,t}return __extends(t,o),t.prototype.after=function(){return this._after},t.prototype.delta=function(){return this._delta},t.prototype.before=function(){return this._before},t})(exports.OutgoingImpl=OutgoingImpl),MessageBeforeTransform=(exports.DeltaOutgoingImpl=DeltaOutgoingImpl,(()=>{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})()),MergeableWrapper=(exports.MessageBeforeTransform=MessageBeforeTransform,(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={})),(()=>{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})()),TTLWrapper=(exports.MergeableWrapper=MergeableWrapper,(()=>{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
|
-
|
|
1
|
+
var __extends=this&&this.__extends||(()=>{var s=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])});return function(t,e){function r(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}})(),__decorate=this&&this.__decorate||function(t,e,r,s){var o,n=arguments.length,p=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)p=Reflect.decorate(t,e,r,s);else for(var a=t.length-1;0<=a;a--)(o=t[a])&&(p=(n<3?o(p):3<n?o(e,r,p):o(e,r))||p);return 3<n&&p&&Object.defineProperty(e,r,p),p},__metadata=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},__param=this&&this.__param||function(r,s){return function(t,e){s(t,e,r)}},data_structure_1=(Object.defineProperty(exports,"__esModule",{value:!0}),require("./data_structure")),core_1=require("./core"),message_class_1=require("./message_class"),injection_js_1=require("injection-js"),WrapperImpl=(exports.EPGM_IMPL=new injection_js_1.InjectionToken("EpgmInstance"),(()=>{function t(t,e){this.__epg=t,this.__stream=e}return t.prototype.epg=function(){return this.__epg},t.prototype.stream=function(){return this.__stream},t})()),FullSnapshotWrapper=(n=>{function t(t,e,r,s){var o=n.call(this,t,e)||this;return o._epg=t,o._stream=e,o._epd=r,o.fullSnapshot=s,o}return __extends(t,n),t.prototype.epg=function(){return this._epg},t.prototype.stream=function(){return this._stream},t.prototype.epd=function(){return this._epd},t.prototype.process=function(){this._epd.readyToDispatch();var t=this._epg.generateFull(this);if(null!=t)for(var e=0;e<t.length;e++){var r=t[e];this._epd.submit(r)}},t.prototype.getFullSnapshot=function(){return this.fullSnapshot},t.prototype.setFullSnapshot=function(t){this.fullSnapshot=t},t})(exports.WrapperImpl=WrapperImpl),PartialSnapshotWrapper=(exports.FullSnapshotWrapper=FullSnapshotWrapper,(o=>{function t(t,e,r){var s=o.call(this,e,r)||this;return s._delta=t,s._epg=e,s._stream=r,s}return __extends(t,o),t.prototype.epg=function(){return this._epg},t.prototype.stream=function(){return this._stream},t.prototype.delta=function(){return this._delta},t.prototype.process=function(){for(var t=this._epg.generatePartial(this),e=this._epg.getEPDs(this._stream),r=0;r<e.length;r++)for(var s,o=e[r],n=0;n<t.length;n++)o.isReadyToDispatch()&&(s=t[n],o.submit(s))},t})(WrapperImpl)),IndicatorWrapper=(exports.PartialSnapshotWrapper=PartialSnapshotWrapper,(o=>{function t(t,e,r){var s=o.call(this,e,r)||this;return s._delta=t,s._epg=e,s._stream=r,s}return __extends(t,o),t.prototype.process=function(){for(var t=this._epg.getEPDs(this._stream),e=0;e<t.length;e++)t[e].submit(this._delta)},t})(WrapperImpl)),EPDispatcherException=(exports.IndicatorWrapper=IndicatorWrapper,(e=>{function t(t){return e.call(this,t)||this}return __extends(t,e),t})(Error)),EndPointGroupManager=(exports.EPDispatcherException=EPDispatcherException,(()=>{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(e,r){var s=this,o=r.stream();r.isInitialized().then(function(t){t&&(t=s._fsRepo.getSnapshot(o),t=new FullSnapshotWrapper(e,o,r,t),e.submitForProcess(t))})},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)},__decorate([injection_js_1.Injectable(),__param(0,injection_js_1.Inject(core_1.FSREPO_IMPL)),__metadata("design:paramtypes",[Object,message_class_1.SportsFeedMessageGroup])],t)})()),DispatchersGroup=(exports.EndPointGroupManager=EndPointGroupManager,(()=>{function t(t){this.streamName=t,this.dispatchers={}}return t.prototype.addEpd=function(t){this.dispatchers[t.id()]=t},t.prototype.removeEpd=function(t){var e=this.dispatchers[t.id()];return delete this.dispatchers[t.id()],e},t.prototype.get=function(t){return this.dispatchers[t]},t.prototype.getAll=function(){var e=this;return Object.keys(this.dispatchers).map(function(t){return e.dispatchers[t]})},t.prototype.isEmpty=function(){return 0==Object.keys(this.dispatchers).length},t})()),AbstractEPG=(exports.DispatchersGroup=DispatchersGroup,(()=>{function t(t){this.sportsFeedGroup=t,this.dispatchers={}}return t.prototype.hasEPD=function(t,e){t=this.dispatchers[t];return void 0!==t&&void 0!==t.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){t=this.dispatchers[t];return void 0!==t?t.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){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))},t.prototype.getSportsFeedGrp=function(){return this.sportsFeedGroup},t.prototype.generateFull=function(t){throw new Error("Method not implemented.")},t.prototype.generatePartial=function(t){throw new Error("Method not implemented.")},t})()),RelayEPG=(r=>{function t(t){var e=r.call(this,t)||this;return e._sportsFeedGroup=t,e}return __extends(t,r),t.prototype.submitForProcess=function(t){t.process()},t.prototype.onException=function(t){return console.error("Exception when dispatching snapshots to EPDs from RelayEPG. ",t),null},t.prototype.generateFull=function(t){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)]},t.prototype.generatePartial=function(t){t=t.delta();return"TTLOutgoing"==t.constructor.name?this.generateTtl(t):[t]},t.prototype.generateTtl=function(t){return this.isSameFormat(t.msgType(),this._sportsFeedGroup.ADMIN_REFRESH())?[]:t.getTtlType()==core_1.TTLType.REMOVE?[t]:this.generateTtlRestore(t)},t.prototype.generateTtlRestore=function(t){return[new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_MATCH(),t.delta(),t.delta(),data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_EVENT(),t.delta(),t.delta(),data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT),new data_structure_1.DeltaOutgoingImpl(this._sportsFeedGroup.DATA_INSERT_ODD(),t.delta(),t.delta(),data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT)]},t.prototype.isSameFormat=function(t,e){return t.instanceClass()==e.instanceClass()&&t.constructor.name==e.constructor.name},__decorate([injection_js_1.Injectable(),__metadata("design:paramtypes",[message_class_1.SportsFeedMessageGroup])],t)})(exports.AbstractEPG=AbstractEPG);exports.RelayEPG=RelayEPG;
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function __export(e){for(var r in e)exports.hasOwnProperty(r)||(exports[r]=e[r])}Object.defineProperty(exports,"__esModule",{value:!0}),__export(require("./basketball_codec")),__export(require("./client")),__export(require("./codec")),__export(require("./core")),__export(require("./data_structure")),__export(require("./dispatch")),__export(require("./message_class")),__export(require("./module")),__export(require("./receive")),__export(require("./soccer_codec")),__export(require("./tennis_codec"));
|
package/lib/merge.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IndexedSnapshot, Incoming, MessageBeforeTransform, MergeableWrapper } from './data_structure';
|
|
2
2
|
import { SportsFeedMessageGroup } from './message_class';
|
|
3
3
|
import { IMessageClass } from '@jayesol/jayeson.lib.delivery';
|
|
4
|
-
import { IBetMatch, PartitionKey } from '@
|
|
4
|
+
import { IBetMatch, PartitionKey } from '@longchau/jayeson.lib.record';
|
|
5
5
|
import * as Collections from 'typescript-collections';
|
|
6
6
|
export declare enum MsgType {
|
|
7
7
|
INSERT = 0,
|
package/lib/merge.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var MsgType,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 s(){}return s.combineSnapshots=function(e,t,r){if(e.group().id()!=s.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 s.SPORTS_GROUP.DATA_INSERT_MATCH().id():return s.processMatches(MsgType.INSERT,t,r);case s.SPORTS_GROUP.DATA_UPDATE_MATCH().id():return s.processMatches(MsgType.UPDATE,t,r);case s.SPORTS_GROUP.DATA_DELETE_MATCH().id():return s.processMatches(MsgType.DELETE,t,r);case s.SPORTS_GROUP.DATA_INSERT_EVENT().id():return s.processEvents(MsgType.INSERT,t,r);case s.SPORTS_GROUP.DATA_UPDATE_EVENT().id():return s.processEvents(MsgType.UPDATE,t,r);case s.SPORTS_GROUP.DATA_DELETE_EVENT().id():return s.processEvents(MsgType.DELETE,t,r);case s.SPORTS_GROUP.DATA_INSERT_ODD().id():return s.processOdds(MsgType.INSERT,t,r);case s.SPORTS_GROUP.DATA_UPDATE_ODD().id():return s.processOdds(MsgType.UPDATE,t,r);case s.SPORTS_GROUP.DATA_DELETE_ODD().id():return s.processOdds(MsgType.DELETE,t,r);case s.SPORTS_GROUP.DATA_RESET().id():return s.processReset(t,r);case s.SPORTS_GROUP.ADMIN_REFRESH().id():return s.processRefresh(t,r);default:var a;return console.error("FATAL: Received non data message class %s.Shouldnt come here",e),(a=new data_structure_1.MessageBeforeTransform).setAfterSs(r),a}},s.processRefresh=function(e,t){for(var r=mutable_1.BuilderProvider.getSnapshotBuilder(t),a=new data_structure_1.MessageBeforeTransform,s=0,n=e.getPartitions().toArray();s<n.length;s++){var i=n[s],l=e.getPartitionMap().getValue(i);r.markPartitionAsUpdated(i,l)}return a.setAfterSs(r.build()),a},s.processReset=function(e,t){for(var r=mutable_1.BuilderProvider.getSnapshotBuilder(t),a=new data_structure_1.MessageBeforeTransform,s=0,n=e.getPartitions().toArray();s<n.length;s++){var i=n[s];r.reset(i);var l=e.getPartitionMap().getValue(i);r.markPartitionAsUpdated(i,l)}return a.setAfterSs(r.build()),a},s.processMatches=function(e,t,r){for(var a=mutable_1.BuilderProvider.getSnapshotBuilder(r),s=new data_structure_1.MessageBeforeTransform,n=null,i=0,l=t.matches();i<l.length;i++){var u=l[i];switch(n=null,e){case MsgType.INSERT:null!=(n=a.insertChild(u))?s.setSuppressMatch(n):s.setInsertMatch(u.id());break;case MsgType.UPDATE:a.updateChild(u);break;case MsgType.DELETE:null!=(n=a.deleteChild(u))?s.setSuppressMatch(n):s.setDeleteMatch(u.id());break;default:console.error("[Match] FATAL: Shouldn't come here")}}for(var d=0,o=t.getPartitions().toArray();d<o.length;d++){var c=o[d],h=t.getPartitionMap().getValue(c);a.markPartitionAsUpdated(c,h)}return s.setAfterSs(a.build()),s},s.processEvents=function(e,t,r){for(var a=mutable_1.BuilderProvider.getSnapshotBuilder(r),s=new data_structure_1.MessageBeforeTransform,n=0,i=t.matches();n<i.length;n++){var l=i[n],u=r.match(l.id());if(null!=u){for(var d=mutable_1.BuilderProvider.getMatchBuilder(u),o=0,c=l.events();o<c.length;o++){var h=c[o];switch(e){case MsgType.INSERT:null!=d.insertChild(h)?s.setTransformEvent(h.matchId()+"_"+h.id()):s.setInsertEvent(h.matchId()+"_"+h.id());break;case MsgType.UPDATE:d.updateChild(h);break;case MsgType.DELETE:null!=d.deleteChild(h)?s.setTransformEvent(h.matchId()+"_"+h.id()):s.setDeleteEvent(h.matchId()+"_"+h.id());break;default:console.error("[Event] FATAL: Shouldn't come here")}}a.replaceMatch(d.build())}else console.error("Cannot find Match %s while processing %s",l.id(),MsgType)}for(var _=0,g=t.getPartitions().toArray();_<g.length;_++){var T=g[_],p=t.getPartitionMap().getValue(T);a.markPartitionAsUpdated(T,p)}return s.setAfterSs(a.build()),s.setBeforeSs(r),s},s.processOdds=function(e,t,r){for(var a=mutable_1.BuilderProvider.getSnapshotBuilder(r),s=new data_structure_1.MessageBeforeTransform,n=0,i=t.matches();n<i.length;n++){var l=i[n],u=r.match(l.id());if(null!=u){for(var d=mutable_1.BuilderProvider.getMatchBuilder(u),o=0,c=l.events();o<c.length;o++){var h=c[o],_=u.event(h.id());if(null!=_){for(var g=mutable_1.BuilderProvider.getEventBuilder(_),T=0,p=h.records();T<p.length;T++){var v=p[T];switch(e){case MsgType.INSERT:g.insertChild(v);break;case MsgType.UPDATE:g.updateChild(v);break;case MsgType.DELETE:g.deleteChild(v);break;default:console.error("[Record] FATAL: Shouldn't come here")}}d.replaceEvent(g.build())}else console.error("Cannot find Event %s_%s while processing %s",l.id(),h.id(),e)}a.replaceMatch(d.build())}else console.error("Cannot find Match %s while processing %s",l.id(),e)}for(var E=0,m=t.getPartitions().toArray();E<m.length;E++){var A=m[E],S=t.getPartitionMap().getValue(A);a.markPartitionAsUpdated(A,S)}return s.setAfterSs(a.build()),s},s.SPORTS_GROUP=new message_class_1.SportsFeedMessageGroup,s}();exports.SnapshotUtil=SnapshotUtil;var DeltaTransformingLogicImpl=function(){function f(){}return f.transform=function(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 n=[];return n.push(new data_structure_1.Incoming(r,t,a)),n},f.combineEventState=function(e,t,r,a,s,n){for(var i=mutable_1.BuilderProvider.getSnapshotBuilder(s),l=0,u=s.matches();l<u.length;l++){for(var d=u[l],o=mutable_1.BuilderProvider.getMatchBuilder(d),c=0,h=d.events();c<h.length;c++){var _=h[c],g=mutable_1.BuilderProvider.getEventBuilder(_);g.aggregateInsert(e.getAfterSs().match(d.id()).event(_.id())),o.replaceEvent(g.build())}i.replaceMatch(o.build())}return n.push(new data_structure_1.Incoming(t.DATA_UPDATE_EVENT(),a,i.build())),n},f.suppressInsertEvent=function(e,t,r,a,s,n){var i=mutable_1.BuilderProvider.getSnapshotBuilder(s),l=mutable_1.BuilderProvider.getSnapshotBuilder(s);if(0!=s.matches().length){if(0!=e.getInsertEvent().length){for(var u={},d=0,o=e.getTransformEvent();d<o.length;d++){var c=(S=o[d]).split("_")[0],h=S.split("_")[1],_=s.match(c),g=u[c];void 0===g&&(g=mutable_1.BuilderProvider.getMatchBuilder(_),u[c]=g),g.deleteChild(_.event(h))}for(var c in u)i.replaceMatch(u[c].build());n.push(new data_structure_1.Incoming(t.DATA_INSERT_EVENT(),a,i.build()))}if(0!=e.getTransformEvent().length){for(var T={},p=0,v=e.getInsertEvent();p<v.length;p++){c=(S=v[p]).split("_")[0],h=S.split("_")[1],_=s.match(c);var E=T[c];void 0===E&&(E=mutable_1.BuilderProvider.getMatchBuilder(_),T[c]=E),E.deleteChild(_.event(h))}for(var m=0,A=e.getTransformEvent();m<A.length;m++){c=(S=A[m]).split("_")[0],h=S.split("_")[1],_=s.match(c);var S,f=T[c];void 0===f&&(f=mutable_1.BuilderProvider.getMatchBuilder(_),T[c]=f);var b=mutable_1.BuilderProvider.getEventBuilder(_.event(h));b.aggregateInsert(e.getAfterSs().match(c).event(h)),f.replaceEvent(b.build())}for(var c in T)l.replaceMatch(T[c].build());n.push(new data_structure_1.Incoming(t.DATA_UPDATE_EVENT(),a,l.build()))}}return n},f.transformTTLRestore=function(e,t,r,a,s,n,i){for(var l=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,u=new data_structure_1.MergeableWrapper,d=0,o=e;d<o.length;d++){var c=o[d];l=SnapshotUtil.combineSnapshots(t.DATA_INSERT_MATCH(),c,l).getAfterSs(),l=SnapshotUtil.combineSnapshots(t.DATA_INSERT_EVENT(),c,l).getAfterSs(),l=SnapshotUtil.combineSnapshots(t.DATA_INSERT_ODD(),c,l).getAfterSs()}for(var h=a,_=[],g=0,T=this.breakdownTTL(t,r,new data_structure_2.IndexedSnapshotImpl(l.matchesSport,i));g<T.length;g++){var p=T[g],v=SnapshotUtil.combineSnapshots(p.msgType(),p.data(),h);if(p.msgType().id()==t.DATA_INSERT_MATCH().id()||p.msgType().id()==t.DATA_INSERT_EVENT().id())for(var E=0,m=f.transform(t,r,p.msgType(),p.data(),v);E<m.length;E++){var A=m[E],S=new core_1.Delta(A,v.getAfterSs(),h);_.push(S),h=v.getAfterSs()}else{S=new core_1.Delta(p,v.getAfterSs(),a);_.push(S)}}return u.setAfter(s),u.setDeltaOut(_),u},f.transformTTLRemove=function(e,t,r,a,s,n){for(var i,l=new data_structure_1.MergeableWrapper,u=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,d=0,o=e;d<o.length;d++){var c=o[d];u=SnapshotUtil.combineSnapshots(t.DATA_INSERT_MATCH(),c,u).getAfterSs(),u=SnapshotUtil.combineSnapshots(t.DATA_INSERT_EVENT(),c,u).getAfterSs(),u=SnapshotUtil.combineSnapshots(t.DATA_INSERT_ODD(),c,u).getAfterSs()}i=a;for(var h=[],_=0,g=f.breakdownReset(t,r,u);_<g.length;_++){var T=g[_],p=SnapshotUtil.combineSnapshots(T.msgType(),T.data(),i);if(T.msgType().id()==t.DATA_DELETE_MATCH().id()||T.msgType().id()==t.DATA_DELETE_EVENT().id())for(var v=0,E=f.transform(t,r,T.msgType(),T.data(),p);v<E.length;v++){var m=E[v],A=new core_1.Delta(m,p.getAfterSs(),i);h.push(A),i=p.getAfterSs()}else{A=new core_1.Delta(T,p.getAfterSs(),a);h.push(A)}}return l.setDeltaOut(h),l.setAfter(s),l},f.breakdownTTL=function(e,t,r){for(var a=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,s=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,n=mutable_1.BuilderProvider.getSnapshotBuilder(r),i=mutable_1.BuilderProvider.getSnapshotBuilder(r),l=0,u=r.matches();l<u.length;l++){for(var d=u[l],o=mutable_1.BuilderProvider.getMatchBuilder(d),c=mutable_1.BuilderProvider.getMatchBuilder(d),h=0,_=d.events();h<_.length;h++){var g=_[h];o.deleteChild(g);for(var T=mutable_1.BuilderProvider.getEventBuilder(g),p=0,v=g.records();p<v.length;p++){var E=v[p];T.deleteChild(E)}c.replaceEvent(T.build())}n.replaceMatch(o.build()),i.replaceMatch(c.build())}a=n.build(),s=i.build();var m=[];return m.push(new data_structure_1.Incoming(e.DATA_INSERT_MATCH(),t,a)),m.push(new data_structure_1.Incoming(e.DATA_INSERT_EVENT(),t,s)),m.push(new data_structure_1.Incoming(e.DATA_INSERT_ODD(),t,r)),m},f.breakdownReset=function(e,t,r){for(var a=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,s=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,n=mutable_1.BuilderProvider.getSnapshotBuilder(r),i=mutable_1.BuilderProvider.getSnapshotBuilder(r),l=0,u=r.matches();l<u.length;l++){for(var d=u[l],o=mutable_1.BuilderProvider.getMatchBuilder(d),c=mutable_1.BuilderProvider.getMatchBuilder(d),h=0,_=d.events();h<_.length;h++){var g=_[h];o.deleteChild(g);for(var T=mutable_1.BuilderProvider.getEventBuilder(g),p=0,v=g.records();p<v.length;p++){var E=v[p];T.deleteChild(E)}c.replaceEvent(T.build())}n.replaceMatch(o.build()),i.replaceMatch(c.build())}a=n.build(),s=i.build();var m=[];return m.push(new data_structure_1.Incoming(e.DATA_DELETE_ODD(),t,r)),m.push(new data_structure_1.Incoming(e.DATA_DELETE_EVENT(),t,s)),m.push(new data_structure_1.Incoming(e.DATA_DELETE_MATCH(),t,a)),m},f.suppressInsertMatch=function(e,t,r,a,s,n){var i=mutable_1.BuilderProvider.getSnapshotBuilder(s),l=mutable_1.BuilderProvider.getSnapshotBuilder(s);if(0!=e.getSuppressMatch().length)for(var u=0,d=e.getSuppressMatch();u<d.length;u++){var o=d[u],c=mutable_1.BuilderProvider.getMatchBuilder(s.match(o.split("_")[0]));i.deleteChild(c.build())}if(0!=e.getInsertMatch().length)for(var h=0,_=e.getInsertMatch();h<_.length;h++){o=_[h],c=mutable_1.BuilderProvider.getMatchBuilder(s.match(o.split("_")[0]));l.deleteChild(c.build())}return 0!=i.build().matches().length&&n.push(new data_structure_1.Incoming(t.DATA_INSERT_MATCH(),a,i.build())),n},f.suppressDeleteEvent=function(e,t,r,a,s,n){var i=mutable_1.BuilderProvider.getSnapshotBuilder(s),l=mutable_1.BuilderProvider.getSnapshotBuilder(s);if(0!=e.getDeleteEvent().length){for(var u={},d=0,o=e.getTransformEvent();d<o.length;d++){var c=(S=o[d]).split("_")[0],h=S.split("_")[1],_=e.getBeforeSs().match(c),g=u[c];void 0===g&&(g=mutable_1.BuilderProvider.getMatchBuilder(_),u[c]=g),g.deleteChild(_.event(h))}for(var c in u)i.replaceMatch(u[c].build());n.push(new data_structure_1.Incoming(t.DATA_DELETE_EVENT(),a,i.build()))}if(0!=e.getTransformEvent().length){for(var T={},p=0,v=e.getDeleteEvent();p<v.length;p++){c=(S=v[p]).split("_")[0],h=S.split("_")[1],_=e.getBeforeSs().match(c);var E=T[c];void 0===E&&(E=mutable_1.BuilderProvider.getMatchBuilder(_),T[c]=E),E.deleteChild(_.event(h))}for(var m=0,A=e.getTransformEvent();m<A.length;m++){c=(S=A[m]).split("_")[0],h=S.split("_")[1];var S,f=T[c];void 0===f&&(f=mutable_1.BuilderProvider.getMatchBuilder(e.getBeforeSs().match(c)),T[c]=f);var b=mutable_1.BuilderProvider.getEventBuilder(f.build().event(h));b.aggregateDelete(s.match(c).event(h)),f.replaceEvent(b.build())}for(var c in T)l.replaceMatch(T[c].build());n.push(new data_structure_1.Incoming(t.DATA_UPDATE_EVENT(),a,l.build()))}return n},f.suppressDeleteMatch=function(e,t,r,a,s,n){var i=mutable_1.BuilderProvider.getSnapshotBuilder(s),l=mutable_1.BuilderProvider.getSnapshotBuilder(s);if(0!=e.getSuppressMatch().length)for(var u=0,d=e.getSuppressMatch();u<d.length;u++){var o=d[u],c=mutable_1.BuilderProvider.getMatchBuilder(s.match(o.split("_")[0]));i.deleteChild(c.build())}if(0!=e.getDeleteMatch().length)for(var h=0,_=e.getDeleteMatch();h<_.length;h++){o=_[h],c=mutable_1.BuilderProvider.getMatchBuilder(s.match(o.split("_")[0]));l.deleteChild(c.build())}return 0!=i.build().matches().length&&n.push(new data_structure_1.Incoming(t.DATA_DELETE_MATCH(),a,i.build())),n},f}();exports.DeltaTransformingLogicImpl=DeltaTransformingLogicImpl;
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});var MsgType,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"),SnapshotUtil=((e=>{e[e.INSERT=0]="INSERT",e[e.UPDATE=1]="UPDATE",e[e.DELETE=2]="DELETE"})(MsgType=exports.MsgType||(exports.MsgType={})),(()=>{function s(){}return s.combineSnapshots=function(e,t,r){var a;if(e.group().id()!=s.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 s.SPORTS_GROUP.DATA_INSERT_MATCH().id():return s.processMatches(MsgType.INSERT,t,r);case s.SPORTS_GROUP.DATA_UPDATE_MATCH().id():return s.processMatches(MsgType.UPDATE,t,r);case s.SPORTS_GROUP.DATA_DELETE_MATCH().id():return s.processMatches(MsgType.DELETE,t,r);case s.SPORTS_GROUP.DATA_INSERT_EVENT().id():return s.processEvents(MsgType.INSERT,t,r);case s.SPORTS_GROUP.DATA_UPDATE_EVENT().id():return s.processEvents(MsgType.UPDATE,t,r);case s.SPORTS_GROUP.DATA_DELETE_EVENT().id():return s.processEvents(MsgType.DELETE,t,r);case s.SPORTS_GROUP.DATA_INSERT_ODD().id():return s.processOdds(MsgType.INSERT,t,r);case s.SPORTS_GROUP.DATA_UPDATE_ODD().id():return s.processOdds(MsgType.UPDATE,t,r);case s.SPORTS_GROUP.DATA_DELETE_ODD().id():return s.processOdds(MsgType.DELETE,t,r);case s.SPORTS_GROUP.DATA_RESET().id():return s.processReset(t,r);case s.SPORTS_GROUP.ADMIN_REFRESH().id():return s.processRefresh(t,r);default:return console.error("FATAL: Received non data message class %s.Shouldnt come here",e),(a=new data_structure_1.MessageBeforeTransform).setAfterSs(r),a}},s.processRefresh=function(e,t){for(var r=mutable_1.BuilderProvider.getSnapshotBuilder(t),t=new data_structure_1.MessageBeforeTransform,a=0,s=e.getPartitions().toArray();a<s.length;a++){var n=s[a],i=e.getPartitionMap().getValue(n);r.markPartitionAsUpdated(n,i)}return t.setAfterSs(r.build()),t},s.processReset=function(e,t){for(var r=mutable_1.BuilderProvider.getSnapshotBuilder(t),t=new data_structure_1.MessageBeforeTransform,a=0,s=e.getPartitions().toArray();a<s.length;a++){var n=s[a],i=(r.reset(n),e.getPartitionMap().getValue(n));r.markPartitionAsUpdated(n,i)}return t.setAfterSs(r.build()),t},s.processMatches=function(e,t,r){for(var a=mutable_1.BuilderProvider.getSnapshotBuilder(r),s=new data_structure_1.MessageBeforeTransform,n=null,i=0,l=t.matches();i<l.length;i++){var u=l[i],n=null;switch(e){case MsgType.INSERT:null!=(n=a.insertChild(u))?s.setSuppressMatch(n):s.setInsertMatch(u.id());break;case MsgType.UPDATE:a.updateChild(u);break;case MsgType.DELETE:null!=(n=a.deleteChild(u))?s.setSuppressMatch(n):s.setDeleteMatch(u.id());break;default:console.error("[Match] FATAL: Shouldn't come here")}}for(var d=0,o=t.getPartitions().toArray();d<o.length;d++){var c=o[d],h=t.getPartitionMap().getValue(c);a.markPartitionAsUpdated(c,h)}return s.setAfterSs(a.build()),s},s.processEvents=function(e,t,r){for(var a=mutable_1.BuilderProvider.getSnapshotBuilder(r),s=new data_structure_1.MessageBeforeTransform,n=0,i=t.matches();n<i.length;n++){var l=i[n],u=r.match(l.id());if(null==u)console.error("Cannot find Match %s while processing %s",l.id(),MsgType);else{for(var d=mutable_1.BuilderProvider.getMatchBuilder(u),o=0,c=l.events();o<c.length;o++){var h=c[o];switch(e){case MsgType.INSERT:null!=d.insertChild(h)?s.setTransformEvent(h.matchId()+"_"+h.id()):s.setInsertEvent(h.matchId()+"_"+h.id());break;case MsgType.UPDATE:d.updateChild(h);break;case MsgType.DELETE:null!=d.deleteChild(h)?s.setTransformEvent(h.matchId()+"_"+h.id()):s.setDeleteEvent(h.matchId()+"_"+h.id());break;default:console.error("[Event] FATAL: Shouldn't come here")}}a.replaceMatch(d.build())}}for(var _=0,g=t.getPartitions().toArray();_<g.length;_++){var T=g[_],p=t.getPartitionMap().getValue(T);a.markPartitionAsUpdated(T,p)}return s.setAfterSs(a.build()),s.setBeforeSs(r),s},s.processOdds=function(e,t,r){for(var a=mutable_1.BuilderProvider.getSnapshotBuilder(r),s=new data_structure_1.MessageBeforeTransform,n=0,i=t.matches();n<i.length;n++){var l=i[n],u=r.match(l.id());if(null==u)console.error("Cannot find Match %s while processing %s",l.id(),e);else{for(var d=mutable_1.BuilderProvider.getMatchBuilder(u),o=0,c=l.events();o<c.length;o++){var h=c[o],_=u.event(h.id());if(null==_)console.error("Cannot find Event %s_%s while processing %s",l.id(),h.id(),e);else{for(var g=mutable_1.BuilderProvider.getEventBuilder(_),T=0,p=h.records();T<p.length;T++){var E=p[T];switch(e){case MsgType.INSERT:g.insertChild(E);break;case MsgType.UPDATE:g.updateChild(E);break;case MsgType.DELETE:g.deleteChild(E);break;default:console.error("[Record] FATAL: Shouldn't come here")}}d.replaceEvent(g.build())}}a.replaceMatch(d.build())}}for(var v=0,m=t.getPartitions().toArray();v<m.length;v++){var A=m[v],S=t.getPartitionMap().getValue(A);a.markPartitionAsUpdated(A,S)}return s.setAfterSs(a.build()),s},s.SPORTS_GROUP=new message_class_1.SportsFeedMessageGroup,s})()),DeltaTransformingLogicImpl=(exports.SnapshotUtil=SnapshotUtil,(()=>{function f(){}return f.transform=function(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 n=[];return n.push(new data_structure_1.Incoming(r,t,a)),n},f.combineEventState=function(e,t,r,a,s,n){for(var i=mutable_1.BuilderProvider.getSnapshotBuilder(s),l=0,u=s.matches();l<u.length;l++){for(var d=u[l],o=mutable_1.BuilderProvider.getMatchBuilder(d),c=0,h=d.events();c<h.length;c++){var _=h[c],g=mutable_1.BuilderProvider.getEventBuilder(_);g.aggregateInsert(e.getAfterSs().match(d.id()).event(_.id())),o.replaceEvent(g.build())}i.replaceMatch(o.build())}return n.push(new data_structure_1.Incoming(t.DATA_UPDATE_EVENT(),a,i.build())),n},f.suppressInsertEvent=function(e,t,r,a,s,n){var i=mutable_1.BuilderProvider.getSnapshotBuilder(s),l=mutable_1.BuilderProvider.getSnapshotBuilder(s);if(0!=s.matches().length){if(0!=e.getInsertEvent().length){for(var u={},d=0,o=e.getTransformEvent();d<o.length;d++){var c=(S=o[d]).split("_")[0],h=S.split("_")[1],_=s.match(c),g=u[c];void 0===g&&(g=mutable_1.BuilderProvider.getMatchBuilder(_),u[c]=g),g.deleteChild(_.event(h))}for(c in u)i.replaceMatch(u[c].build());n.push(new data_structure_1.Incoming(t.DATA_INSERT_EVENT(),a,i.build()))}if(0!=e.getTransformEvent().length){for(var T={},p=0,E=e.getInsertEvent();p<E.length;p++){var c=(S=E[p]).split("_")[0],h=S.split("_")[1],_=s.match(c),v=T[c];void 0===v&&(v=mutable_1.BuilderProvider.getMatchBuilder(_),T[c]=v),v.deleteChild(_.event(h))}for(var m=0,A=e.getTransformEvent();m<A.length;m++){var S,c=(S=A[m]).split("_")[0],h=S.split("_")[1],_=s.match(c),f=T[c],b=(void 0===f&&(f=mutable_1.BuilderProvider.getMatchBuilder(_),T[c]=f),mutable_1.BuilderProvider.getEventBuilder(_.event(h)));b.aggregateInsert(e.getAfterSs().match(c).event(h)),f.replaceEvent(b.build())}for(c in T)l.replaceMatch(T[c].build());n.push(new data_structure_1.Incoming(t.DATA_UPDATE_EVENT(),a,l.build()))}}return n},f.transformTTLRestore=function(e,t,r,a,s,n,i){for(var l=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,u=new data_structure_1.MergeableWrapper,d=0,o=e;d<o.length;d++){var c=o[d],l=SnapshotUtil.combineSnapshots(t.DATA_INSERT_MATCH(),c,l).getAfterSs();l=SnapshotUtil.combineSnapshots(t.DATA_INSERT_EVENT(),c,l).getAfterSs(),l=SnapshotUtil.combineSnapshots(t.DATA_INSERT_ODD(),c,l).getAfterSs()}for(var h=a,_=[],g=0,T=this.breakdownTTL(t,r,new data_structure_2.IndexedSnapshotImpl(l.matchesSport,i));g<T.length;g++){var p=T[g],E=SnapshotUtil.combineSnapshots(p.msgType(),p.data(),h);if(p.msgType().id()==t.DATA_INSERT_MATCH().id()||p.msgType().id()==t.DATA_INSERT_EVENT().id())for(var v=0,m=f.transform(t,r,p.msgType(),p.data(),E);v<m.length;v++){var A=m[v],S=new core_1.Delta(A,E.getAfterSs(),h);_.push(S),h=E.getAfterSs()}else{S=new core_1.Delta(p,E.getAfterSs(),a);_.push(S)}}return u.setAfter(s),u.setDeltaOut(_),u},f.transformTTLRemove=function(e,t,r,a,s,n){for(var i=new data_structure_1.MergeableWrapper,l=data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,u=0,d=e;u<d.length;u++){var o=d[u],l=SnapshotUtil.combineSnapshots(t.DATA_INSERT_MATCH(),o,l).getAfterSs();l=SnapshotUtil.combineSnapshots(t.DATA_INSERT_EVENT(),o,l).getAfterSs(),l=SnapshotUtil.combineSnapshots(t.DATA_INSERT_ODD(),o,l).getAfterSs()}for(var c=a,h=[],_=0,g=f.breakdownReset(t,r,l);_<g.length;_++){var T=g[_],p=SnapshotUtil.combineSnapshots(T.msgType(),T.data(),c);if(T.msgType().id()==t.DATA_DELETE_MATCH().id()||T.msgType().id()==t.DATA_DELETE_EVENT().id())for(var E=0,v=f.transform(t,r,T.msgType(),T.data(),p);E<v.length;E++){var m=v[E],A=new core_1.Delta(m,p.getAfterSs(),c);h.push(A),c=p.getAfterSs()}else{A=new core_1.Delta(T,p.getAfterSs(),a);h.push(A)}}return i.setDeltaOut(h),i.setAfter(s),i},f.breakdownTTL=function(e,t,r){data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT;for(var a=mutable_1.BuilderProvider.getSnapshotBuilder(r),s=mutable_1.BuilderProvider.getSnapshotBuilder(r),n=0,i=r.matches();n<i.length;n++){for(var l=i[n],u=mutable_1.BuilderProvider.getMatchBuilder(l),d=mutable_1.BuilderProvider.getMatchBuilder(l),o=0,c=l.events();o<c.length;o++){for(var h=c[o],_=(u.deleteChild(h),mutable_1.BuilderProvider.getEventBuilder(h)),g=0,T=h.records();g<T.length;g++){var p=T[g];_.deleteChild(p)}d.replaceEvent(_.build())}a.replaceMatch(u.build()),s.replaceMatch(d.build())}var E=a.build(),v=s.build(),m=[];return m.push(new data_structure_1.Incoming(e.DATA_INSERT_MATCH(),t,E)),m.push(new data_structure_1.Incoming(e.DATA_INSERT_EVENT(),t,v)),m.push(new data_structure_1.Incoming(e.DATA_INSERT_ODD(),t,r)),m},f.breakdownReset=function(e,t,r){data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT,data_structure_2.IndexedSnapshotImpl.EMPTY_SNAPSHOT;for(var a=mutable_1.BuilderProvider.getSnapshotBuilder(r),s=mutable_1.BuilderProvider.getSnapshotBuilder(r),n=0,i=r.matches();n<i.length;n++){for(var l=i[n],u=mutable_1.BuilderProvider.getMatchBuilder(l),d=mutable_1.BuilderProvider.getMatchBuilder(l),o=0,c=l.events();o<c.length;o++){for(var h=c[o],_=(u.deleteChild(h),mutable_1.BuilderProvider.getEventBuilder(h)),g=0,T=h.records();g<T.length;g++){var p=T[g];_.deleteChild(p)}d.replaceEvent(_.build())}a.replaceMatch(u.build()),s.replaceMatch(d.build())}var E=a.build(),v=s.build(),m=[];return m.push(new data_structure_1.Incoming(e.DATA_DELETE_ODD(),t,r)),m.push(new data_structure_1.Incoming(e.DATA_DELETE_EVENT(),t,v)),m.push(new data_structure_1.Incoming(e.DATA_DELETE_MATCH(),t,E)),m},f.suppressInsertMatch=function(e,t,r,a,s,n){var i=mutable_1.BuilderProvider.getSnapshotBuilder(s),l=mutable_1.BuilderProvider.getSnapshotBuilder(s);if(0!=e.getSuppressMatch().length)for(var u=0,d=e.getSuppressMatch();u<d.length;u++){var o=d[u],c=mutable_1.BuilderProvider.getMatchBuilder(s.match(o.split("_")[0]));i.deleteChild(c.build())}if(0!=e.getInsertMatch().length)for(var h=0,_=e.getInsertMatch();h<_.length;h++){o=_[h],c=mutable_1.BuilderProvider.getMatchBuilder(s.match(o.split("_")[0]));l.deleteChild(c.build())}return 0!=i.build().matches().length&&n.push(new data_structure_1.Incoming(t.DATA_INSERT_MATCH(),a,i.build())),n},f.suppressDeleteEvent=function(e,t,r,a,s,n){var i=mutable_1.BuilderProvider.getSnapshotBuilder(s),l=mutable_1.BuilderProvider.getSnapshotBuilder(s);if(0!=e.getDeleteEvent().length){for(var u={},d=0,o=e.getTransformEvent();d<o.length;d++){var c=(S=o[d]).split("_")[0],h=S.split("_")[1],_=e.getBeforeSs().match(c),g=u[c];void 0===g&&(g=mutable_1.BuilderProvider.getMatchBuilder(_),u[c]=g),g.deleteChild(_.event(h))}for(c in u)i.replaceMatch(u[c].build());n.push(new data_structure_1.Incoming(t.DATA_DELETE_EVENT(),a,i.build()))}if(0!=e.getTransformEvent().length){for(var T={},p=0,E=e.getDeleteEvent();p<E.length;p++){var c=(S=E[p]).split("_")[0],h=S.split("_")[1],_=e.getBeforeSs().match(c),v=T[c];void 0===v&&(v=mutable_1.BuilderProvider.getMatchBuilder(_),T[c]=v),v.deleteChild(_.event(h))}for(var m=0,A=e.getTransformEvent();m<A.length;m++){var S,c=(S=A[m]).split("_")[0],h=S.split("_")[1],f=T[c],b=(void 0===f&&(f=mutable_1.BuilderProvider.getMatchBuilder(e.getBeforeSs().match(c)),T[c]=f),mutable_1.BuilderProvider.getEventBuilder(f.build().event(h)));b.aggregateDelete(s.match(c).event(h)),f.replaceEvent(b.build())}for(c in T)l.replaceMatch(T[c].build());n.push(new data_structure_1.Incoming(t.DATA_UPDATE_EVENT(),a,l.build()))}return n},f.suppressDeleteMatch=function(e,t,r,a,s,n){var i=mutable_1.BuilderProvider.getSnapshotBuilder(s),l=mutable_1.BuilderProvider.getSnapshotBuilder(s);if(0!=e.getSuppressMatch().length)for(var u=0,d=e.getSuppressMatch();u<d.length;u++){var o=d[u],c=mutable_1.BuilderProvider.getMatchBuilder(s.match(o.split("_")[0]));i.deleteChild(c.build())}if(0!=e.getDeleteMatch().length)for(var h=0,_=e.getDeleteMatch();h<_.length;h++){o=_[h],c=mutable_1.BuilderProvider.getMatchBuilder(s.match(o.split("_")[0]));l.deleteChild(c.build())}return 0!=i.build().matches().length&&n.push(new data_structure_1.Incoming(t.DATA_DELETE_MATCH(),a,i.build())),n},f})());exports.DeltaTransformingLogicImpl=DeltaTransformingLogicImpl;
|
package/lib/message_class.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import deliver = require('@jayesol/jayeson.lib.delivery');
|
|
2
|
-
import { PartitionKey, SportType, IBetMatch } from '@
|
|
2
|
+
import { PartitionKey, SportType, IBetMatch } from '@longchau/jayeson.lib.record';
|
|
3
3
|
import * as proto from './protobuf_bundle';
|
|
4
4
|
import * as Collections from 'typescript-collections';
|
|
5
5
|
import { ICodec } from './codec';
|