@azuro-org/toolkit 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,30 +1,27 @@
1
1
  import { type Dictionaries } from '@azuro-org/dictionaries';
2
- type Outcome = {
2
+ type Outcome<T> = T & {
3
3
  conditionId: string;
4
4
  outcomeId: string;
5
5
  selectionName: string;
6
6
  lpAddress: string;
7
7
  coreAddress: string;
8
8
  };
9
- type Markets = {
9
+ type FinalMarket<T> = {
10
10
  marketName: string;
11
- outcomes: Outcome[][];
12
- }[];
11
+ outcomes: Outcome<T>[][];
12
+ };
13
13
  type Props = {
14
14
  lpAddress: string;
15
15
  conditions: {
16
16
  [key: string]: any;
17
17
  conditionId: string;
18
+ coreAddress: string;
18
19
  outcomes: {
19
20
  [key: string]: any;
20
21
  outcomeId: string;
21
22
  }[];
22
- core: {
23
- [key: string]: any;
24
- address: string;
25
- };
26
23
  }[];
27
24
  dictionaries: Dictionaries;
28
25
  };
29
- export default function aggregateOutcomesByMarkets(props: Props): Markets;
26
+ export default function aggregateOutcomesByMarkets<T extends {}>(props: Props): FinalMarket<T>[];
30
27
  export {};
package/dist/index.es.js CHANGED
@@ -1,57 +1,88 @@
1
- import {getMarketKey,getMarketName,assembleSelectionName}from'@azuro-org/dictionaries';function aggregateOutcomesByMarkets(props) {
1
+ import {getMarketKey,getMarketName,assembleSelectionName}from'@azuro-org/dictionaries';/******************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+
16
+ var __assign = function() {
17
+ __assign = Object.assign || function __assign(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+
27
+ function __rest(s, e) {
28
+ var t = {};
29
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
30
+ t[p] = s[p];
31
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
32
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
33
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
34
+ t[p[i]] = s[p[i]];
35
+ }
36
+ return t;
37
+ }function aggregateOutcomesByMarkets(props) {
2
38
  var lpAddress = props.lpAddress, conditions = props.conditions, dictionaries = props.dictionaries;
3
- // group conditions by marketId
4
- var outcomesByMarketKey = {};
5
- var result = {};
39
+ var marketsMap = {};
6
40
  conditions.forEach(function (_a) {
7
- var conditionId = _a.conditionId, outcomes = _a.outcomes, core = _a.core;
41
+ var conditionId = _a.conditionId, outcomes = _a.outcomes, coreAddress = _a.coreAddress;
8
42
  outcomes.forEach(function (_a) {
9
- var outcomeId = _a.outcomeId;
43
+ var outcomeId = _a.outcomeId, rest = __rest(_a, ["outcomeId"]);
44
+ // we are using the same key format that was discussed earlier
10
45
  var marketKey = getMarketKey(outcomeId, dictionaries);
46
+ // we are obtaining the human-readable names of each market and the corresponding outcome selections
11
47
  var marketName = getMarketName(outcomeId, dictionaries);
12
48
  var selectionName = assembleSelectionName(outcomeId, dictionaries);
13
- var outcome = {
14
- conditionId: conditionId,
15
- outcomeId: outcomeId,
16
- selectionName: selectionName,
17
- lpAddress: lpAddress,
18
- coreAddress: core.address,
19
- };
20
- // it's important to use "marketKey" because it's unique
21
- // on other hand "marketId" can be same for different groups of conditions
22
- // "marketKey" is a string template "marketId-gamePeriodId-gameTypeId[-teamPlayerId]"
23
- if (!outcomesByMarketKey[marketKey]) {
24
- outcomesByMarketKey[marketKey] = [];
25
- result[marketKey] = {
49
+ var outcome = __assign({ conditionId: conditionId, outcomeId: outcomeId, lpAddress: lpAddress, coreAddress: coreAddress, selectionName: selectionName }, rest);
50
+ if (!marketsMap[marketKey]) {
51
+ marketsMap[marketKey] = {
26
52
  marketName: marketName,
27
53
  outcomes: [],
28
54
  };
29
55
  }
30
- outcomesByMarketKey[marketKey].push(outcome);
56
+ marketsMap[marketKey].outcomes.push(outcome);
31
57
  });
32
58
  });
59
+ var finalMarketsMap = {};
33
60
  // sort by outcomeId and group by conditionId
34
- Object.keys(outcomesByMarketKey).forEach(function (marketKey) {
35
- var marketId = +marketKey.split('-')[0];
36
- // get outcomes related to the market
37
- var outcomes = outcomesByMarketKey[marketKey];
38
- // sort the conditions by selectionId (outcome)
61
+ Object.keys(marketsMap).forEach(function (marketKey) {
62
+ var _a = marketsMap[marketKey], marketName = _a.marketName, outcomes = _a.outcomes;
63
+ finalMarketsMap[marketKey] = {
64
+ marketName: marketName,
65
+ outcomes: null,
66
+ };
67
+ // sort the outcomes by `selectionId` (outcome's selection reference)
39
68
  outcomes.sort(function (a, b) {
40
69
  var left = dictionaries.outcomes[a.outcomeId].selectionId;
41
70
  var right = dictionaries.outcomes[b.outcomeId].selectionId;
42
71
  return left - right;
43
72
  });
44
- // markets with different conditionIds and not require additional grouping or sorting
45
- var marketsWithDifferentConditionIds = [1, 2];
46
- if (marketsWithDifferentConditionIds.includes(marketId)) {
47
- result[marketKey].outcomes = [outcomes];
73
+ // "Full Time Result" and "Double Chance" are the markets whose outcomes don't require sorting
74
+ var MARKETS_THAT_DONT_NEED_GROUPING = [1, 2];
75
+ var marketId = marketKey.split('-')[0];
76
+ if (MARKETS_THAT_DONT_NEED_GROUPING.includes(+marketId)) {
77
+ // it's worth noting that the outcomes are wrapped within an array here due to the "rows" that are presented below
78
+ finalMarketsMap[marketKey].outcomes = [outcomes];
48
79
  }
49
- // group by conditionId to allow draw outcomes by rows in UI, e.g.
50
- //
51
- // Team 1 - Total Goals:
52
- // Over (1.5) Under (1.5)
53
- // Over (0.5) Under (0.5)
54
80
  else {
81
+ // group the outcomes by condition ID, which will allow us to display the draw outcomes in separate rows
82
+ //
83
+ // Handicap:
84
+ // H1 (-0.5) H2 (0.5)
85
+ // H1 (0.5) H2 (-0.5)
55
86
  var outcomesByConditionId_1 = {};
56
87
  outcomes.forEach(function (outcome) {
57
88
  var key = outcome.conditionId;
@@ -60,8 +91,8 @@ import {getMarketKey,getMarketName,assembleSelectionName}from'@azuro-org/diction
60
91
  }
61
92
  outcomesByConditionId_1[key].push(outcome);
62
93
  });
63
- var outcomesArr = Object.values(outcomesByConditionId_1);
64
- result[marketKey].outcomes = outcomesArr.sort(function (a, b) {
94
+ var rows = Object.values(outcomesByConditionId_1);
95
+ finalMarketsMap[marketKey].outcomes = rows.sort(function (a, b) {
65
96
  var aSum = a.reduce(function (acc, _a) {
66
97
  var outcomeId = _a.outcomeId;
67
98
  return acc + +outcomeId;
@@ -74,5 +105,5 @@ import {getMarketKey,getMarketName,assembleSelectionName}from'@azuro-org/diction
74
105
  });
75
106
  }
76
107
  });
77
- return Object.values(result);
108
+ return Object.values(finalMarketsMap);
78
109
  }export{aggregateOutcomesByMarkets};
@@ -1,30 +1,27 @@
1
1
  import { type Dictionaries } from '@azuro-org/dictionaries';
2
- type Outcome = {
2
+ type Outcome<T> = T & {
3
3
  conditionId: string;
4
4
  outcomeId: string;
5
5
  selectionName: string;
6
6
  lpAddress: string;
7
7
  coreAddress: string;
8
8
  };
9
- type Markets = {
9
+ type FinalMarket<T> = {
10
10
  marketName: string;
11
- outcomes: Outcome[][];
12
- }[];
11
+ outcomes: Outcome<T>[][];
12
+ };
13
13
  type Props = {
14
14
  lpAddress: string;
15
15
  conditions: {
16
16
  [key: string]: any;
17
17
  conditionId: string;
18
+ coreAddress: string;
18
19
  outcomes: {
19
20
  [key: string]: any;
20
21
  outcomeId: string;
21
22
  }[];
22
- core: {
23
- [key: string]: any;
24
- address: string;
25
- };
26
23
  }[];
27
24
  dictionaries: Dictionaries;
28
25
  };
29
- export default function aggregateOutcomesByMarkets(props: Props): Markets;
26
+ export default function aggregateOutcomesByMarkets<T extends {}>(props: Props): FinalMarket<T>[];
30
27
  export {};
package/lib/index.js CHANGED
@@ -1,57 +1,88 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var dictionaries=require('@azuro-org/dictionaries');function aggregateOutcomesByMarkets(props) {
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var dictionaries=require('@azuro-org/dictionaries');/******************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+
16
+ var __assign = function() {
17
+ __assign = Object.assign || function __assign(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+
27
+ function __rest(s, e) {
28
+ var t = {};
29
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
30
+ t[p] = s[p];
31
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
32
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
33
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
34
+ t[p[i]] = s[p[i]];
35
+ }
36
+ return t;
37
+ }function aggregateOutcomesByMarkets(props) {
2
38
  var lpAddress = props.lpAddress, conditions = props.conditions, dictionaries$1 = props.dictionaries;
3
- // group conditions by marketId
4
- var outcomesByMarketKey = {};
5
- var result = {};
39
+ var marketsMap = {};
6
40
  conditions.forEach(function (_a) {
7
- var conditionId = _a.conditionId, outcomes = _a.outcomes, core = _a.core;
41
+ var conditionId = _a.conditionId, outcomes = _a.outcomes, coreAddress = _a.coreAddress;
8
42
  outcomes.forEach(function (_a) {
9
- var outcomeId = _a.outcomeId;
43
+ var outcomeId = _a.outcomeId, rest = __rest(_a, ["outcomeId"]);
44
+ // we are using the same key format that was discussed earlier
10
45
  var marketKey = dictionaries.getMarketKey(outcomeId, dictionaries$1);
46
+ // we are obtaining the human-readable names of each market and the corresponding outcome selections
11
47
  var marketName = dictionaries.getMarketName(outcomeId, dictionaries$1);
12
48
  var selectionName = dictionaries.assembleSelectionName(outcomeId, dictionaries$1);
13
- var outcome = {
14
- conditionId: conditionId,
15
- outcomeId: outcomeId,
16
- selectionName: selectionName,
17
- lpAddress: lpAddress,
18
- coreAddress: core.address,
19
- };
20
- // it's important to use "marketKey" because it's unique
21
- // on other hand "marketId" can be same for different groups of conditions
22
- // "marketKey" is a string template "marketId-gamePeriodId-gameTypeId[-teamPlayerId]"
23
- if (!outcomesByMarketKey[marketKey]) {
24
- outcomesByMarketKey[marketKey] = [];
25
- result[marketKey] = {
49
+ var outcome = __assign({ conditionId: conditionId, outcomeId: outcomeId, lpAddress: lpAddress, coreAddress: coreAddress, selectionName: selectionName }, rest);
50
+ if (!marketsMap[marketKey]) {
51
+ marketsMap[marketKey] = {
26
52
  marketName: marketName,
27
53
  outcomes: [],
28
54
  };
29
55
  }
30
- outcomesByMarketKey[marketKey].push(outcome);
56
+ marketsMap[marketKey].outcomes.push(outcome);
31
57
  });
32
58
  });
59
+ var finalMarketsMap = {};
33
60
  // sort by outcomeId and group by conditionId
34
- Object.keys(outcomesByMarketKey).forEach(function (marketKey) {
35
- var marketId = +marketKey.split('-')[0];
36
- // get outcomes related to the market
37
- var outcomes = outcomesByMarketKey[marketKey];
38
- // sort the conditions by selectionId (outcome)
61
+ Object.keys(marketsMap).forEach(function (marketKey) {
62
+ var _a = marketsMap[marketKey], marketName = _a.marketName, outcomes = _a.outcomes;
63
+ finalMarketsMap[marketKey] = {
64
+ marketName: marketName,
65
+ outcomes: null,
66
+ };
67
+ // sort the outcomes by `selectionId` (outcome's selection reference)
39
68
  outcomes.sort(function (a, b) {
40
69
  var left = dictionaries$1.outcomes[a.outcomeId].selectionId;
41
70
  var right = dictionaries$1.outcomes[b.outcomeId].selectionId;
42
71
  return left - right;
43
72
  });
44
- // markets with different conditionIds and not require additional grouping or sorting
45
- var marketsWithDifferentConditionIds = [1, 2];
46
- if (marketsWithDifferentConditionIds.includes(marketId)) {
47
- result[marketKey].outcomes = [outcomes];
73
+ // "Full Time Result" and "Double Chance" are the markets whose outcomes don't require sorting
74
+ var MARKETS_THAT_DONT_NEED_GROUPING = [1, 2];
75
+ var marketId = marketKey.split('-')[0];
76
+ if (MARKETS_THAT_DONT_NEED_GROUPING.includes(+marketId)) {
77
+ // it's worth noting that the outcomes are wrapped within an array here due to the "rows" that are presented below
78
+ finalMarketsMap[marketKey].outcomes = [outcomes];
48
79
  }
49
- // group by conditionId to allow draw outcomes by rows in UI, e.g.
50
- //
51
- // Team 1 - Total Goals:
52
- // Over (1.5) Under (1.5)
53
- // Over (0.5) Under (0.5)
54
80
  else {
81
+ // group the outcomes by condition ID, which will allow us to display the draw outcomes in separate rows
82
+ //
83
+ // Handicap:
84
+ // H1 (-0.5) H2 (0.5)
85
+ // H1 (0.5) H2 (-0.5)
55
86
  var outcomesByConditionId_1 = {};
56
87
  outcomes.forEach(function (outcome) {
57
88
  var key = outcome.conditionId;
@@ -60,8 +91,8 @@
60
91
  }
61
92
  outcomesByConditionId_1[key].push(outcome);
62
93
  });
63
- var outcomesArr = Object.values(outcomesByConditionId_1);
64
- result[marketKey].outcomes = outcomesArr.sort(function (a, b) {
94
+ var rows = Object.values(outcomesByConditionId_1);
95
+ finalMarketsMap[marketKey].outcomes = rows.sort(function (a, b) {
65
96
  var aSum = a.reduce(function (acc, _a) {
66
97
  var outcomeId = _a.outcomeId;
67
98
  return acc + +outcomeId;
@@ -74,5 +105,5 @@
74
105
  });
75
106
  }
76
107
  });
77
- return Object.values(result);
108
+ return Object.values(finalMarketsMap);
78
109
  }exports.aggregateOutcomesByMarkets=aggregateOutcomesByMarkets;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azuro-org/toolkit",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Set of helpers to work with Azuro protocol",
5
5
  "module": "dist/index.es.js",
6
6
  "main": "lib/index.js",