@degenerate/generic 0.0.11 → 0.0.14
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/dist/errors/safe/safe-rules-errors.d.ts +19 -0
- package/dist/errors/safe/safe-rules-errors.d.ts.map +1 -1
- package/dist/errors/safe/safe-rules-errors.js +25 -2
- package/dist/helpers/array/array-helpers.d.ts +9 -1
- package/dist/helpers/array/array-helpers.d.ts.map +1 -1
- package/dist/helpers/array/array-helpers.js +12 -1
- package/dist/share-data/share-data.d.ts +72 -0
- package/dist/share-data/share-data.d.ts.map +1 -1
- package/dist/share-data/share-data.js +151 -165
- package/package.json +3 -2
|
@@ -1,4 +1,23 @@
|
|
|
1
|
+
import { ConditionType } from '../../models';
|
|
1
2
|
import { BaseError } from '../base-error';
|
|
3
|
+
/**
|
|
4
|
+
* This error is thrown when a evaluation condition data value is not valid
|
|
5
|
+
*/
|
|
6
|
+
export declare class SafeRuleEvaluationConditionDataValueError extends BaseError {
|
|
7
|
+
/**
|
|
8
|
+
* This error is thrown when a evaluation condition data value is not valid
|
|
9
|
+
*/
|
|
10
|
+
constructor(dataValue: unknown, conditionValue: unknown, conditionType: ConditionType);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* This error is thrown when a evaluation condition value is not valid
|
|
14
|
+
*/
|
|
15
|
+
export declare class SafeRuleEvaluationConditionValueError extends BaseError {
|
|
16
|
+
/**
|
|
17
|
+
* This error is thrown when a evaluation condition value is not valid
|
|
18
|
+
*/
|
|
19
|
+
constructor(dataValue: unknown, conditionValue: unknown, conditionType: ConditionType);
|
|
20
|
+
}
|
|
2
21
|
/**
|
|
3
22
|
* This error is thrown when a speical condition pattern is not valid
|
|
4
23
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-rules-errors.d.ts","sourceRoot":"","sources":["../../../src/errors/safe/safe-rules-errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C;;GAEG;AACH,qBAAa,8CAA+C,SAAQ,SAAS;IACzE;;OAEG;gBACS,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO;CAG1D"}
|
|
1
|
+
{"version":3,"file":"safe-rules-errors.d.ts","sourceRoot":"","sources":["../../../src/errors/safe/safe-rules-errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C;;GAEG;AACH,qBAAa,yCAA0C,SAAQ,SAAS;IACpE;;OAEG;gBACS,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa;CAGxF;AAED;;GAEG;AACH,qBAAa,qCAAsC,SAAQ,SAAS;IAChE;;OAEG;gBACS,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa;CAGxF;AAED;;GAEG;AACH,qBAAa,8CAA+C,SAAQ,SAAS;IACzE;;OAEG;gBACS,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO;CAG1D"}
|
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SafeRuleEvaluationSpecialConditionPatternError = void 0;
|
|
4
|
-
// This file contains the errors for the share data rules.
|
|
3
|
+
exports.SafeRuleEvaluationSpecialConditionPatternError = exports.SafeRuleEvaluationConditionValueError = exports.SafeRuleEvaluationConditionDataValueError = void 0;
|
|
5
4
|
const base_error_1 = require("../base-error");
|
|
5
|
+
/**
|
|
6
|
+
* This error is thrown when a evaluation condition data value is not valid
|
|
7
|
+
*/
|
|
8
|
+
class SafeRuleEvaluationConditionDataValueError extends base_error_1.BaseError {
|
|
9
|
+
/**
|
|
10
|
+
* This error is thrown when a evaluation condition data value is not valid
|
|
11
|
+
*/
|
|
12
|
+
constructor(dataValue, conditionValue, conditionType) {
|
|
13
|
+
super(`Share Rule condition evaluation for type ${conditionType} failed to execute. dataValue: ${dataValue} is incorrect for conditionValue: ${conditionValue}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.SafeRuleEvaluationConditionDataValueError = SafeRuleEvaluationConditionDataValueError;
|
|
17
|
+
/**
|
|
18
|
+
* This error is thrown when a evaluation condition value is not valid
|
|
19
|
+
*/
|
|
20
|
+
class SafeRuleEvaluationConditionValueError extends base_error_1.BaseError {
|
|
21
|
+
/**
|
|
22
|
+
* This error is thrown when a evaluation condition value is not valid
|
|
23
|
+
*/
|
|
24
|
+
constructor(dataValue, conditionValue, conditionType) {
|
|
25
|
+
super(`Share Rule condition evaluation for type ${conditionType} failed to execute. conditionValue: ${conditionValue} is incorrect for dataValue: ${dataValue}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.SafeRuleEvaluationConditionValueError = SafeRuleEvaluationConditionValueError;
|
|
6
29
|
/**
|
|
7
30
|
* This error is thrown when a speical condition pattern is not valid
|
|
8
31
|
*/
|
|
@@ -4,5 +4,13 @@
|
|
|
4
4
|
* @param incomingArray the incoming array to get a random item from.
|
|
5
5
|
*/
|
|
6
6
|
declare const getRandomItemFromArray: <T>(incomingArray: T[]) => T;
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* This ensures that all items in an array are of the same type.
|
|
9
|
+
*
|
|
10
|
+
* @param array the array to check
|
|
11
|
+
* @param type the type to check against
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
declare const checkIfAllItemsInAnArrayAreSameType: (array: unknown[], type: string) => boolean;
|
|
15
|
+
export { getRandomItemFromArray, checkIfAllItemsInAnArrayAreSameType, };
|
|
8
16
|
//# sourceMappingURL=array-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-helpers.d.ts","sourceRoot":"","sources":["../../../src/helpers/array/array-helpers.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,QAAA,MAAM,sBAAsB,GAAI,CAAC,iBAAiB,CAAC,EAAE,KAAG,CAGvD,CAAC;AAEF,OAAO,EAAE,sBAAsB,
|
|
1
|
+
{"version":3,"file":"array-helpers.d.ts","sourceRoot":"","sources":["../../../src/helpers/array/array-helpers.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,QAAA,MAAM,sBAAsB,GAAI,CAAC,iBAAiB,CAAC,EAAE,KAAG,CAGvD,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,mCAAmC,UAAW,OAAO,EAAE,QAAQ,MAAM,KAAG,OAE7E,CAAC;AAEF,OAAO,EACH,sBAAsB,EACtB,mCAAmC,GACtC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// This file contains the helper functions for arrays.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.getRandomItemFromArray = void 0;
|
|
4
|
+
exports.checkIfAllItemsInAnArrayAreSameType = exports.getRandomItemFromArray = void 0;
|
|
5
5
|
/**
|
|
6
6
|
* this gets a random item from an array.
|
|
7
7
|
*
|
|
@@ -12,3 +12,14 @@ const getRandomItemFromArray = (incomingArray) => {
|
|
|
12
12
|
return incomingArray[randomIndex];
|
|
13
13
|
};
|
|
14
14
|
exports.getRandomItemFromArray = getRandomItemFromArray;
|
|
15
|
+
/**
|
|
16
|
+
* This ensures that all items in an array are of the same type.
|
|
17
|
+
*
|
|
18
|
+
* @param array the array to check
|
|
19
|
+
* @param type the type to check against
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
const checkIfAllItemsInAnArrayAreSameType = (array, type) => {
|
|
23
|
+
return array.every(item => typeof item === type);
|
|
24
|
+
};
|
|
25
|
+
exports.checkIfAllItemsInAnArrayAreSameType = checkIfAllItemsInAnArrayAreSameType;
|
|
@@ -1 +1,73 @@
|
|
|
1
|
+
import { IShareDataEvent } from '../models/events/share-event-models';
|
|
2
|
+
import { IShareRuleApplied, IShareRuleEvalutionResult } from '../models/rules/share-rule-models';
|
|
3
|
+
import { IShareFunction, IShareTransactionHistory, IShareData } from '../models/share-data/share-data';
|
|
4
|
+
/**
|
|
5
|
+
* This contains the interface for the share data object
|
|
6
|
+
*/
|
|
7
|
+
export declare class ShareData {
|
|
8
|
+
private _id;
|
|
9
|
+
private _rules;
|
|
10
|
+
private _functions;
|
|
11
|
+
private _transactionHistory;
|
|
12
|
+
private _events;
|
|
13
|
+
private isLocked;
|
|
14
|
+
private _data;
|
|
15
|
+
/**
|
|
16
|
+
* This is the constructor for the share data object
|
|
17
|
+
* @param id the id of the share data
|
|
18
|
+
*/
|
|
19
|
+
constructor(id: string);
|
|
20
|
+
/**
|
|
21
|
+
* This adds a rule to the share block.
|
|
22
|
+
* @param rule the rule to add to the share block
|
|
23
|
+
*/
|
|
24
|
+
addRule(rule: IShareRuleApplied): void;
|
|
25
|
+
/**
|
|
26
|
+
* This gets the rules for the share block
|
|
27
|
+
*/
|
|
28
|
+
get rules(): IShareRuleApplied[];
|
|
29
|
+
/**
|
|
30
|
+
* This gets the transaction history for the share block
|
|
31
|
+
*/
|
|
32
|
+
addFunction(func: IShareFunction<any, (...args: any[]) => any, any>): void;
|
|
33
|
+
/**
|
|
34
|
+
* This gets the functions for the share block
|
|
35
|
+
*/
|
|
36
|
+
get functions(): IShareFunction<any, (...args: any[]) => any, any>[];
|
|
37
|
+
/**
|
|
38
|
+
* This gets the events for the sharedata
|
|
39
|
+
*/
|
|
40
|
+
get events(): IShareDataEvent[];
|
|
41
|
+
/**
|
|
42
|
+
* This adds an event to the share data
|
|
43
|
+
* @param event the event to add
|
|
44
|
+
*/
|
|
45
|
+
addEvent(event: IShareDataEvent): void;
|
|
46
|
+
/**
|
|
47
|
+
* This adds a transaction to the share block
|
|
48
|
+
* @param rulesEvaluation the evaluation of the rules (result)
|
|
49
|
+
* @param transactionFunction the function that was run
|
|
50
|
+
*/
|
|
51
|
+
addTransactionAlreadyValidated(proposedData: IShareData, rulesEvaluation: IShareRuleEvalutionResult, transactionFunction: IShareFunction<any, (...args: any[]) => any, any>): void;
|
|
52
|
+
/**
|
|
53
|
+
* This adds a transaction to the share block but the transaction has not yet been validated
|
|
54
|
+
*
|
|
55
|
+
* @param proposedData the proposed data
|
|
56
|
+
* @param transactionFunction the function that was attempted
|
|
57
|
+
*/
|
|
58
|
+
addTransactionNotValidated(proposedData: IShareData, transactionFunction: IShareFunction<any, (...args: any[]) => any, any>): void;
|
|
59
|
+
/**
|
|
60
|
+
* This gets the transaction history for the share block
|
|
61
|
+
*/
|
|
62
|
+
get transactionHistory(): IShareTransactionHistory[];
|
|
63
|
+
/**
|
|
64
|
+
* This returns the current state of data for the share block
|
|
65
|
+
*/
|
|
66
|
+
get data(): IShareData;
|
|
67
|
+
/**
|
|
68
|
+
* This copies a share data object to a new transaction number
|
|
69
|
+
* @param transactionNumber the number of the transaction to run until.
|
|
70
|
+
*/
|
|
71
|
+
copyTo(transactionNumber: number): ShareData;
|
|
72
|
+
}
|
|
1
73
|
//# sourceMappingURL=share-data.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"share-data.d.ts","sourceRoot":"","sources":["../../src/share-data/share-data.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"share-data.d.ts","sourceRoot":"","sources":["../../src/share-data/share-data.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AACjG,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,UAAU,EAAkB,MAAM,iCAAiC,CAAC;AAEvH;;GAEG;AACH,qBAAa,SAAS;IAClB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,UAAU,CAAsD;IACxE,OAAO,CAAC,mBAAmB,CAA6B;IACxD,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,KAAK,CAAa;IAE1B;;;OAGG;gBACS,EAAE,EAAE,MAAM;IAYtB;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI;IAOtC;;OAEG;IACH,IAAI,KAAK,IAAI,iBAAiB,EAAE,CAE/B;IAED;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI;IAO1E;;OAEG;IACH,IAAI,SAAS,IAAI,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,GAAG,CAAC,EAAE,CAEnE;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,eAAe,EAAE,CAE9B;IAED;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAItC;;;;OAIG;IACH,8BAA8B,CAC1B,YAAY,EAAE,UAAU,EACxB,eAAe,EAAE,yBAAyB,EAC1C,mBAAmB,EAAE,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,GAAG,CAAC,GACvE,IAAI;IAwBP;;;;;OAKG;IACH,0BAA0B,CACtB,YAAY,EAAE,UAAU,EACxB,mBAAmB,EAAE,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,GAAG,CAAC,GACvE,IAAI;IA0BP;;OAEG;IACH,IAAI,kBAAkB,IAAI,wBAAwB,EAAE,CAEnD;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,UAAU,CAErB;IAED;;;OAGG;IACH,MAAM,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS;CAW/C"}
|
|
@@ -1,166 +1,152 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
// * This copies a share data object to a new transaction number
|
|
154
|
-
// * @param transactionNumber the number of the transaction to run until.
|
|
155
|
-
// */
|
|
156
|
-
// copyTo(transactionNumber: number): ShareData {
|
|
157
|
-
// // return share data with a new ID
|
|
158
|
-
// const newShareData = new ShareData(`${this._id}-${transactionNumber}`);
|
|
159
|
-
// newShareData._rules = [...this._rules];
|
|
160
|
-
// newShareData._functions = [...this._functions];
|
|
161
|
-
// newShareData._transactionHistory = [...this._transactionHistory];
|
|
162
|
-
// newShareData._data = { ...this._data };
|
|
163
|
-
// return newShareData;
|
|
164
|
-
// }
|
|
165
|
-
// //#endregion Getters and Setters
|
|
166
|
-
// }
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ShareData = void 0;
|
|
4
|
+
const rules_1 = require("@degenerate/rules");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const share_data_1 = require("../models/share-data/share-data");
|
|
7
|
+
/**
|
|
8
|
+
* This contains the interface for the share data object
|
|
9
|
+
*/
|
|
10
|
+
class ShareData {
|
|
11
|
+
/**
|
|
12
|
+
* This is the constructor for the share data object
|
|
13
|
+
* @param id the id of the share data
|
|
14
|
+
*/
|
|
15
|
+
constructor(id) {
|
|
16
|
+
this.isLocked = false;
|
|
17
|
+
this._id = id;
|
|
18
|
+
this._rules = [];
|
|
19
|
+
this._functions = [];
|
|
20
|
+
this._transactionHistory = [];
|
|
21
|
+
this._events = [];
|
|
22
|
+
this._data = {};
|
|
23
|
+
}
|
|
24
|
+
//#region Getters and Setters
|
|
25
|
+
/**
|
|
26
|
+
* This adds a rule to the share block.
|
|
27
|
+
* @param rule the rule to add to the share block
|
|
28
|
+
*/
|
|
29
|
+
addRule(rule) {
|
|
30
|
+
if (this.isLocked) {
|
|
31
|
+
throw new errors_1.ShareDataIsLockedError(this._id, share_data_1.ShareDataTypes.RULE);
|
|
32
|
+
}
|
|
33
|
+
this._rules.push(rule);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* This gets the rules for the share block
|
|
37
|
+
*/
|
|
38
|
+
get rules() {
|
|
39
|
+
return this._rules;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* This gets the transaction history for the share block
|
|
43
|
+
*/
|
|
44
|
+
addFunction(func) {
|
|
45
|
+
if (this.isLocked) {
|
|
46
|
+
throw new errors_1.ShareDataIsLockedError(this._id, share_data_1.ShareDataTypes.FUNCTION);
|
|
47
|
+
}
|
|
48
|
+
this._functions.push(func);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* This gets the functions for the share block
|
|
52
|
+
*/
|
|
53
|
+
get functions() {
|
|
54
|
+
return this._functions;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* This gets the events for the sharedata
|
|
58
|
+
*/
|
|
59
|
+
get events() {
|
|
60
|
+
return this._events;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* This adds an event to the share data
|
|
64
|
+
* @param event the event to add
|
|
65
|
+
*/
|
|
66
|
+
addEvent(event) {
|
|
67
|
+
this._events.push(event);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* This adds a transaction to the share block
|
|
71
|
+
* @param rulesEvaluation the evaluation of the rules (result)
|
|
72
|
+
* @param transactionFunction the function that was run
|
|
73
|
+
*/
|
|
74
|
+
addTransactionAlreadyValidated(proposedData, rulesEvaluation, transactionFunction) {
|
|
75
|
+
// make sure the function is known.
|
|
76
|
+
if (!this._functions.includes(transactionFunction)) {
|
|
77
|
+
throw new Error('The function is not known');
|
|
78
|
+
}
|
|
79
|
+
const transactionTime = Date.now(); // get the current time
|
|
80
|
+
const transactionId = this._transactionHistory.length + 1; // get the transaction id
|
|
81
|
+
const ruleOutcome = (rulesEvaluation.proposedResult && rulesEvaluation.currentResult);
|
|
82
|
+
const transaction = {
|
|
83
|
+
ruleOutcome,
|
|
84
|
+
ruleFailures: [],
|
|
85
|
+
transactionFunction,
|
|
86
|
+
transactionId: transactionId.toString(),
|
|
87
|
+
transactionTime,
|
|
88
|
+
};
|
|
89
|
+
// the outcome of the rules is valid write the data to be the new current data.
|
|
90
|
+
if (ruleOutcome) {
|
|
91
|
+
this._data = proposedData;
|
|
92
|
+
}
|
|
93
|
+
this._transactionHistory.push(transaction);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* This adds a transaction to the share block but the transaction has not yet been validated
|
|
97
|
+
*
|
|
98
|
+
* @param proposedData the proposed data
|
|
99
|
+
* @param transactionFunction the function that was attempted
|
|
100
|
+
*/
|
|
101
|
+
addTransactionNotValidated(proposedData, transactionFunction) {
|
|
102
|
+
// make sure the function is known.
|
|
103
|
+
if (!this._functions.includes(transactionFunction)) {
|
|
104
|
+
// throw ShareDataFunctionBeingAppliedDoesNotExistOnShareDataError
|
|
105
|
+
throw new Error('The function is not known');
|
|
106
|
+
}
|
|
107
|
+
// // evaluate the rules.
|
|
108
|
+
// const rulesEvalOutcome = evaluateRules('transaction', this._data, proposedData, this._rules);
|
|
109
|
+
const rulesOutcome = (0, rules_1.startRuleEvaluation)(this._id, transactionFunction, this.functions, this._rules, this._data, proposedData);
|
|
110
|
+
const transactionTime = Date.now(); // get the current time
|
|
111
|
+
const transactionId = this._transactionHistory.length + 1; // get the transaction id
|
|
112
|
+
const transaction = {
|
|
113
|
+
ruleOutcome: rulesOutcome.isValidProposal,
|
|
114
|
+
ruleFailures: [],
|
|
115
|
+
transactionFunction,
|
|
116
|
+
transactionId: transactionId.toString(),
|
|
117
|
+
transactionTime,
|
|
118
|
+
};
|
|
119
|
+
// update the data if the rules are valid
|
|
120
|
+
if (rulesOutcome.isValidProposal) {
|
|
121
|
+
this._data = proposedData;
|
|
122
|
+
}
|
|
123
|
+
// add the transaction to the history
|
|
124
|
+
this._transactionHistory.push(transaction);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* This gets the transaction history for the share block
|
|
128
|
+
*/
|
|
129
|
+
get transactionHistory() {
|
|
130
|
+
return this._transactionHistory;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* This returns the current state of data for the share block
|
|
134
|
+
*/
|
|
135
|
+
get data() {
|
|
136
|
+
return this._data;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* This copies a share data object to a new transaction number
|
|
140
|
+
* @param transactionNumber the number of the transaction to run until.
|
|
141
|
+
*/
|
|
142
|
+
copyTo(transactionNumber) {
|
|
143
|
+
// return share data with a new ID
|
|
144
|
+
const newShareData = new ShareData(`${this._id}-${transactionNumber}`);
|
|
145
|
+
newShareData._rules = [...this._rules];
|
|
146
|
+
newShareData._functions = [...this._functions];
|
|
147
|
+
newShareData._transactionHistory = [...this._transactionHistory];
|
|
148
|
+
newShareData._data = { ...this._data };
|
|
149
|
+
return newShareData;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.ShareData = ShareData;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@degenerate/generic",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "This contains the generic information needed for the
|
|
3
|
+
"version": "0.0.14",
|
|
4
|
+
"description": "This contains the generic information needed for the ShareData Adaptive Framework Ecosystem (SAFE) network",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"typescript-eslint": "^8.9.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
+
"@degenerate/rules": "^0.0.5",
|
|
51
52
|
"bip39": "^3.1.0",
|
|
52
53
|
"elliptic": "^6.5.7"
|
|
53
54
|
}
|