@jayesol/jayeson.lib.sports 2.2.7-beta → 2.2.7-beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/codec.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ import * as proto from "./protobuf_bundle";
2
+ import * as rec from "@jayesol/jayeson.lib.record";
3
+ import { RuleCombination } from "@jayesol/jayeson.model";
4
+ import Long = require("long");
5
+ export declare enum EncodeAction {
6
+ INSERT = 0,
7
+ UPDATE = 1,
8
+ DELETE = 2
9
+ }
10
+ export interface ICodec {
11
+ decodeRecord(input: proto.BaseRecord[], pool: string[], action: EncodeAction, key: rec.PartitionKey): rec.IBetMatch[];
12
+ decodeEvent(input: proto.BaseEvent[], pool: string[], action: EncodeAction, key: rec.PartitionKey): rec.IBetMatch[];
13
+ decodeMatch(input: proto.BaseMatch[], pool: string[], action: EncodeAction, key: rec.PartitionKey): rec.IBetMatch[];
14
+ }
15
+ export declare class CodecHelper {
16
+ constructor();
17
+ coerceInt64(val: number | Long): number;
18
+ populatePKIntoMetaInfo(meta: rec.StringMap, key: rec.PartitionKey): rec.StringMap;
19
+ formatRate(num: number): number;
20
+ }
21
+ export declare class FilterRequest {
22
+ private _requestId;
23
+ private _ruleCombination;
24
+ static readonly IGNORED_REQUEST_ID = -1;
25
+ constructor(_requestId: number, _ruleCombination: RuleCombination);
26
+ getRequestId(): number;
27
+ getFilterData(): RuleCombination;
28
+ toJSON(): any;
29
+ }
30
+ export declare class Util {
31
+ private static SEPARATOR;
32
+ /**
33
+ * Utility to Store array of String values as single String Also see
34
+ * {@link #removeKey(String, String)}
35
+ *
36
+ * @param existing
37
+ * "IBC_LIVE,CROWN_LIVE"
38
+ * @param incoming
39
+ * "SBO_LIVE"
40
+ * @return "IBC_LIVE,CROWN_LIVE,SBO_LIVE"
41
+ *
42
+ */
43
+ static addKey(existing: string, incoming: string): string;
44
+ /**
45
+ * Utility to remove element from string values Stored as String Also see
46
+ * {@link #addKey(String, String)}
47
+ *
48
+ * @param existing
49
+ * "IBC_LIVE,CROWN_LIVE"
50
+ * @param incoming
51
+ * "IBC_LIVE"
52
+ * @return "CROWN_LIVE". return empty string if there are no more keys. Return
53
+ * existing string if incoming is not present in existing
54
+ */
55
+ static removeKey(existing: string, incoming: string): string;
56
+ static containsKey(existing: string, incoming: string): boolean;
57
+ }
package/lib/codec.js ADDED
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Util = exports.FilterRequest = exports.CodecHelper = exports.EncodeAction = void 0;
4
+ const mutable_1 = require("./mutable");
5
+ var EncodeAction;
6
+ (function (EncodeAction) {
7
+ EncodeAction[EncodeAction["INSERT"] = 0] = "INSERT";
8
+ EncodeAction[EncodeAction["UPDATE"] = 1] = "UPDATE";
9
+ EncodeAction[EncodeAction["DELETE"] = 2] = "DELETE";
10
+ })(EncodeAction = exports.EncodeAction || (exports.EncodeAction = {}));
11
+ class CodecHelper {
12
+ constructor() { }
13
+ coerceInt64(val) {
14
+ if (val.toNumber) {
15
+ return val.toNumber();
16
+ }
17
+ else {
18
+ return val;
19
+ }
20
+ }
21
+ populatePKIntoMetaInfo(meta, key) {
22
+ meta[mutable_1.Const.AGGREGATE_KEY] = key.toString();
23
+ return meta;
24
+ }
25
+ formatRate(num) {
26
+ //Round input to 4 decimal places
27
+ return Math.round(num * 10000) / 10000;
28
+ }
29
+ }
30
+ exports.CodecHelper = CodecHelper;
31
+ class FilterRequest {
32
+ constructor(_requestId, _ruleCombination) {
33
+ this._requestId = _requestId;
34
+ this._ruleCombination = _ruleCombination;
35
+ }
36
+ getRequestId() {
37
+ return this._requestId;
38
+ }
39
+ getFilterData() {
40
+ return this._ruleCombination;
41
+ }
42
+ toJSON() {
43
+ return { "requestId": this.getRequestId(), "namespace": this._ruleCombination.namespace, "filterRules": this._ruleCombination.filterRules };
44
+ }
45
+ }
46
+ exports.FilterRequest = FilterRequest;
47
+ FilterRequest.IGNORED_REQUEST_ID = -1;
48
+ class Util {
49
+ /**
50
+ * Utility to Store array of String values as single String Also see
51
+ * {@link #removeKey(String, String)}
52
+ *
53
+ * @param existing
54
+ * "IBC_LIVE,CROWN_LIVE"
55
+ * @param incoming
56
+ * "SBO_LIVE"
57
+ * @return "IBC_LIVE,CROWN_LIVE,SBO_LIVE"
58
+ *
59
+ */
60
+ static addKey(existing, incoming) {
61
+ if (incoming.search(Util.SEPARATOR) != -1) {
62
+ throw new TypeError("Incoming String cannot contain Separator: " + Util.SEPARATOR + " Incoming: " + incoming);
63
+ }
64
+ if (existing.length == 0) {
65
+ return incoming;
66
+ }
67
+ else {
68
+ if (existing.indexOf(incoming) === -1) {
69
+ return existing + Util.SEPARATOR + incoming;
70
+ }
71
+ else {
72
+ return existing;
73
+ }
74
+ }
75
+ }
76
+ /**
77
+ * Utility to remove element from string values Stored as String Also see
78
+ * {@link #addKey(String, String)}
79
+ *
80
+ * @param existing
81
+ * "IBC_LIVE,CROWN_LIVE"
82
+ * @param incoming
83
+ * "IBC_LIVE"
84
+ * @return "CROWN_LIVE". return empty string if there are no more keys. Return
85
+ * existing string if incoming is not present in existing
86
+ */
87
+ static removeKey(existing, incoming) {
88
+ let split = existing.split(Util.SEPARATOR);
89
+ let incomingArr = incoming.split(Util.SEPARATOR);
90
+ split.sort();
91
+ for (let incoming of incomingArr) {
92
+ let index = split.indexOf(incoming);
93
+ // If not found return
94
+ if (index < 0) {
95
+ continue;
96
+ }
97
+ else {
98
+ split.splice(index, 1);
99
+ // Return empty string if removed is empty
100
+ if (split.length == 0) {
101
+ return "";
102
+ }
103
+ }
104
+ }
105
+ let finalStr = split[0];
106
+ for (let i = 1; i < split.length; i++) {
107
+ finalStr = Util.addKey(finalStr, split[i]);
108
+ }
109
+ return finalStr;
110
+ }
111
+ static containsKey(existing, incoming) {
112
+ if (existing == undefined) {
113
+ return false;
114
+ }
115
+ if (incoming.search(Util.SEPARATOR) != -1) {
116
+ throw new TypeError("Incoming String cannot contain Separator: " + Util.SEPARATOR + " Incoming: " + incoming);
117
+ }
118
+ let split = existing.split(Util.SEPARATOR);
119
+ let index = split.indexOf(incoming);
120
+ if (index < 0) {
121
+ return false;
122
+ }
123
+ else {
124
+ return true;
125
+ }
126
+ }
127
+ }
128
+ exports.Util = Util;
129
+ Util.SEPARATOR = ",";
package/lib/core.d.ts ADDED
@@ -0,0 +1,159 @@
1
+ import { Incoming, IndexedSnapshot, DeltaOutgoing, Outgoing } from "./data_structure";
2
+ import * as D from "@jayesol/jayeson.lib.delivery";
3
+ import * as Collections from 'typescript-collections';
4
+ import * as T from 'ts-promise';
5
+ import 'reflect-metadata';
6
+ import { InjectionToken } from 'injection-js';
7
+ import { PartitionKey, IBetMatch } from "@jayesol/jayeson.lib.record";
8
+ import { SportsFeedMessageGroup } from "./message_class";
9
+ import { MergeableWrapper, TTLWrapper } from "./data_structure";
10
+ export interface ISnapshotHandler {
11
+ process(streamName: string, snapshot: Outgoing): void;
12
+ toString(): string;
13
+ }
14
+ export interface FSRepo {
15
+ appendSnapshot(stream: string, mergeable: Mergeable): DeltaOutgoing[];
16
+ getSnapshot(streamName: string): IndexedSnapshot;
17
+ registerSnapshotHandler(ssHandler: ISnapshotHandler): void;
18
+ deRegisterSnapshotHandler(ssHandler: ISnapshotHandler): void;
19
+ getRegisteredHandlers(): ISnapshotHandler[];
20
+ push(outgoing: Outgoing): void;
21
+ isReady(stream: string): T.Promise<Boolean>;
22
+ }
23
+ export declare const FSREPO_IMPL: InjectionToken<FSRepo>;
24
+ export declare abstract class AbstractFSRepo implements FSRepo {
25
+ abstract getTtlRemoveSnapshot(): TTLRemoveCheck[];
26
+ protected _handlers: Collections.Set<ISnapshotHandler>;
27
+ constructor();
28
+ handlers(): Collections.Set<ISnapshotHandler>;
29
+ appendSnapshot(stream: string, mergeable: Mergeable): DeltaOutgoing[];
30
+ getSnapshot(streamName: string): IndexedSnapshot;
31
+ registerSnapshotHandler(ssHandler: ISnapshotHandler): void;
32
+ deRegisterSnapshotHandler(ssHandler: ISnapshotHandler): void;
33
+ getRegisteredHandlers(): ISnapshotHandler[];
34
+ push(outgoing: Outgoing): void;
35
+ isReady(stream: string): T.Promise<Boolean>;
36
+ }
37
+ export declare class FSRepoImpl extends AbstractFSRepo implements FSRepo {
38
+ outputStreamName: string;
39
+ private sportsGroup;
40
+ private _head;
41
+ static outputStream: InjectionToken<string>;
42
+ private fssEndReceived;
43
+ private result;
44
+ private promiseResolver;
45
+ private promiseRejector;
46
+ constructor(outputStreamName: string, sportsGroup: SportsFeedMessageGroup);
47
+ head(): IndexedSnapshot;
48
+ appendSnapshot(stream: string, logic: Mergeable): DeltaOutgoing[];
49
+ getSnapshot(streamName?: string): IndexedSnapshot;
50
+ getTtlRemoveSnapshot(): TTLRemoveCheck[];
51
+ push(outgoing: Outgoing): void;
52
+ isReady(stream: string): T.Promise<Boolean>;
53
+ }
54
+ export declare class Delta implements DeltaOutgoing {
55
+ private _incoming;
56
+ private _after;
57
+ private _before;
58
+ constructor(_incoming: Incoming, _after: IndexedSnapshot, _before: IndexedSnapshot);
59
+ incoming(): Incoming;
60
+ msgType(): D.IMessageClass;
61
+ after(): IndexedSnapshot;
62
+ delta(): IndexedSnapshot;
63
+ before(): IndexedSnapshot;
64
+ }
65
+ export interface Mergeable {
66
+ apply(before: IndexedSnapshot): MergeableWrapper;
67
+ }
68
+ export declare class TTLConfig {
69
+ private livettl;
70
+ private todayttl;
71
+ private earlyttl;
72
+ private enableTtl;
73
+ getLivettl(): number;
74
+ setLivettl(livettl: number): void;
75
+ getTodayttl(): number;
76
+ setTodayttl(todayttl: number): void;
77
+ getEarlyttl(): number;
78
+ setEarlyttl(earlyttl: number): void;
79
+ getRunInterval(): number;
80
+ isEnableTtl(): boolean;
81
+ setEnableTtl(enableTtl: boolean): void;
82
+ }
83
+ export declare enum TTLType {
84
+ REMOVE = 0,
85
+ RESTORE = 1
86
+ }
87
+ export declare class TTLOutgoing extends Delta implements DeltaOutgoing {
88
+ private readonly ttlType;
89
+ constructor(ttlType: TTLType, incoming: Incoming, after: IndexedSnapshot, before: IndexedSnapshot);
90
+ getTtlType(): TTLType;
91
+ }
92
+ export declare abstract class TTLCheck implements Mergeable {
93
+ private readonly ttlType;
94
+ private recycleBin;
95
+ private readonly keys;
96
+ private readonly stream;
97
+ constructor(ttlType: TTLType, recycleBin: RecycleBin, keys: PartitionKey[], stream: string);
98
+ getKeys(): PartitionKey[];
99
+ getKeysMapping(): Collections.Dictionary<PartitionKey, number>;
100
+ getTtlType(): TTLType;
101
+ getRecycleBin(): RecycleBin;
102
+ setRecycleBin(recycleBin: RecycleBin): void;
103
+ getStream(): string;
104
+ abstract apply(before: IndexedSnapshot): MergeableWrapper;
105
+ }
106
+ export declare class TTLRestoreCheck extends TTLCheck {
107
+ private ttlRestoreWrapper;
108
+ private transformingLogic;
109
+ constructor(recycleBin: RecycleBin, keys: PartitionKey[], stream: string);
110
+ apply(before: IndexedSnapshot): MergeableWrapper;
111
+ }
112
+ export declare class TTLRemoveCheck extends TTLCheck {
113
+ private ttlRemoveWrapper;
114
+ constructor(recycleBin: RecycleBin, keys: PartitionKey[], stream: string);
115
+ apply(before: IndexedSnapshot): MergeableWrapper;
116
+ }
117
+ export declare class RecycleBin {
118
+ private ttlConfig;
119
+ private grp;
120
+ private fsRepo;
121
+ private expiredMatches;
122
+ private ttlStatus;
123
+ constructor(ttlConfig: TTLConfig, grp: SportsFeedMessageGroup, fsRepo: AbstractFSRepo);
124
+ /**
125
+ * Remove the data for a given PartitionKey from a snapshot and return the
126
+ * modified snapshot. The removed data will be stored in this recycle bin.
127
+ *
128
+ * @param snapshot
129
+ * @param key
130
+ */
131
+ removeData(ttlRemoveWrapper: TTLWrapper, snapshot: IndexedSnapshot, key: PartitionKey): TTLWrapper;
132
+ /**
133
+ * Retrieves the data in this bin with given PartitionKey and combine it with
134
+ * the given snapshot.
135
+ *
136
+ * @param parent
137
+ * @param key
138
+ */
139
+ restoreData(ttlRestore: TTLWrapper, parent: IndexedSnapshot, key: PartitionKey, restoreTime: number): TTLWrapper;
140
+ clearBin(key: PartitionKey): void;
141
+ containData(key: PartitionKey): boolean;
142
+ getTtlConfig(): TTLConfig;
143
+ getFsRepo(): AbstractFSRepo;
144
+ getTtlRestoreSnapshot(incoming: Incoming): TTLRestoreCheck;
145
+ getTtlRemoveSnapshot(): TTLRemoveCheck[];
146
+ /**
147
+ * Copies the data in this RecycleBin related to the given PartitionKey into the
148
+ * list of matches.
149
+ *
150
+ * @param key
151
+ * @param matches
152
+ */
153
+ copyData(key: PartitionKey, matches: {
154
+ [sport: number]: IBetMatch[];
155
+ }): {
156
+ [sport: number]: IBetMatch[];
157
+ };
158
+ getGrp(): SportsFeedMessageGroup;
159
+ }