@degenerate/generic 0.0.14 → 0.0.18
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/LICENCE.md +15 -0
- package/README.md +1 -1
- package/package.json +3 -3
- package/dist/share-data/share-data.d.ts +0 -73
- package/dist/share-data/share-data.d.ts.map +0 -1
- package/dist/share-data/share-data.js +0 -152
package/LICENCE.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2024] [Degenerateiinc.ca]
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
# @Degenerate/generic Package
|
|
2
2
|
|
|
3
|
-
This package contains generic functions and models for use in the SAFE ecosystem. The package is used to provide common functionality across the different services in the SAFE environment.
|
|
3
|
+
This package contains generic functions and models for use in the SAFE ecosystem. The package is used to provide common functionality across the different services in the SAFE environment.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@degenerate/generic",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
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",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"typescript-eslint": "^8.9.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@degenerate/rules": "^0.0.5",
|
|
52
51
|
"bip39": "^3.1.0",
|
|
53
52
|
"elliptic": "^6.5.7"
|
|
54
|
-
}
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "422633e36d3f60c773c8bf289285a78b5a75ef01"
|
|
55
55
|
}
|
|
@@ -1,73 +0,0 @@
|
|
|
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
|
-
}
|
|
73
|
-
//# sourceMappingURL=share-data.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|