@degenerate/generic 0.0.17 → 0.0.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@degenerate/generic",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
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",
@@ -30,7 +30,6 @@
30
30
  "homepage": "https://github.com/syncrude/safe#readme",
31
31
  "devDependencies": {
32
32
  "@eslint/js": "^9.12.0",
33
- "@jest/globals": "^29.7.0",
34
33
  "@types/elliptic": "^6.4.18",
35
34
  "@types/eslint__js": "^8.42.3",
36
35
  "@types/jest": "^29.5.13",
@@ -48,9 +47,8 @@
48
47
  "typescript-eslint": "^8.9.0"
49
48
  },
50
49
  "dependencies": {
51
- "@degenerate/rules": "^0.0.5",
52
50
  "bip39": "^3.1.0",
53
51
  "elliptic": "^6.5.7"
54
52
  },
55
- "gitHead": "19d2d9b7bf58aa69e761ad804f9c8e58ab6cde6f"
53
+ "gitHead": "0e8f76c14364f6d23ab66cdb9547d4e486fad9a4"
56
54
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=request-response-models.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request-response-models.d.ts","sourceRoot":"","sources":["../../../../src/models/generic/__tests__/request-response-models.ts"],"names":[],"mappings":""}
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- describe('IGenericResponse', () => {
4
- it('should create a successful response without an error', () => {
5
- const response = {
6
- successful: true,
7
- };
8
- expect(response.successful).toBe(true);
9
- expect(response.error).toBeUndefined();
10
- });
11
- it('should create a failed response with an error message', () => {
12
- const errorMessage = 'An error occurred';
13
- const response = {
14
- successful: false,
15
- error: errorMessage,
16
- };
17
- expect(response.successful).toBe(false);
18
- expect(response.error).toBe(errorMessage);
19
- });
20
- it('should handle optional error property correctly', () => {
21
- const response = {
22
- successful: true,
23
- };
24
- expect(response.successful).toBe(true);
25
- expect(response.error).toBeUndefined();
26
- const errorResponse = {
27
- successful: false,
28
- error: 'An error occurred',
29
- };
30
- expect(errorResponse.successful).toBe(false);
31
- expect(errorResponse.error).toBe('An error occurred');
32
- });
33
- });
@@ -1,78 +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 _version;
10
- private _rules;
11
- private _functions;
12
- private _transactionHistory;
13
- private _events;
14
- private isLocked;
15
- private _data;
16
- /**
17
- * This is the constructor for the share data object
18
- * @param id the id of the share data
19
- */
20
- constructor(id: string);
21
- /**
22
- * This adds a rule to the share block.
23
- * @param rule the rule to add to the share block
24
- */
25
- addRule(rule: IShareRuleApplied): void;
26
- /**
27
- * This gets the rules for the share block
28
- */
29
- get rules(): IShareRuleApplied[];
30
- /**
31
- * This gets the transaction history for the share block
32
- */
33
- addFunction(func: IShareFunction<any, (...args: any[]) => any, any>): void;
34
- /**
35
- * This gets the functions for the share block
36
- */
37
- get functions(): IShareFunction<any, (...args: any[]) => any, any>[];
38
- /**
39
- * This gets the events for the sharedata
40
- */
41
- get events(): IShareDataEvent[];
42
- /**
43
- * This adds an event to the share data
44
- * @param event the event to add
45
- */
46
- addEvent(event: IShareDataEvent): void;
47
- /**
48
- * This adds a transaction to the share block
49
- * @param rulesEvaluation the evaluation of the rules (result)
50
- * @param transactionFunction the function that was run
51
- */
52
- addTransactionAlreadyValidated(proposedData: IShareData, rulesEvaluation: IShareRuleEvalutionResult, transactionFunction: IShareFunction<any, (...args: any[]) => any, any>): void;
53
- /**
54
- * This adds a transaction to the share block but the transaction has not yet been validated
55
- *
56
- * @param proposedData the proposed data
57
- * @param transactionFunction the function that was attempted
58
- */
59
- addTransactionNotValidated(proposedData: IShareData, transactionFunction: IShareFunction<any, (...args: any[]) => any, any>): void;
60
- /**
61
- * This gets the transaction history for the share block
62
- */
63
- get transactionHistory(): IShareTransactionHistory[];
64
- /**
65
- * This returns the current state of data for the share block
66
- */
67
- get data(): IShareData;
68
- /**
69
- * This gets the version of the share data
70
- */
71
- get version(): number;
72
- /**
73
- * This copies a share data object to a new transaction number
74
- * @param transactionNumber the number of the transaction to run until.
75
- */
76
- copyTo(transactionNumber: number): ShareData;
77
- }
78
- //# 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,QAAQ,CAAS;IACzB,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;IAatB;;;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;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED;;;OAGG;IACH,MAAM,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS;CAa/C"}
@@ -1,161 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ShareData = void 0;
4
- const dist_1 = require("../../../rules/dist");
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._version = 1,
18
- this._id = id;
19
- this._rules = [];
20
- this._functions = [];
21
- this._transactionHistory = [];
22
- this._events = [];
23
- this._data = {};
24
- }
25
- //#region Getters and Setters
26
- /**
27
- * This adds a rule to the share block.
28
- * @param rule the rule to add to the share block
29
- */
30
- addRule(rule) {
31
- if (this.isLocked) {
32
- throw new errors_1.ShareDataIsLockedError(this._id, share_data_1.ShareDataTypes.RULE);
33
- }
34
- this._rules.push(rule);
35
- }
36
- /**
37
- * This gets the rules for the share block
38
- */
39
- get rules() {
40
- return this._rules;
41
- }
42
- /**
43
- * This gets the transaction history for the share block
44
- */
45
- addFunction(func) {
46
- if (this.isLocked) {
47
- throw new errors_1.ShareDataIsLockedError(this._id, share_data_1.ShareDataTypes.FUNCTION);
48
- }
49
- this._functions.push(func);
50
- }
51
- /**
52
- * This gets the functions for the share block
53
- */
54
- get functions() {
55
- return this._functions;
56
- }
57
- /**
58
- * This gets the events for the sharedata
59
- */
60
- get events() {
61
- return this._events;
62
- }
63
- /**
64
- * This adds an event to the share data
65
- * @param event the event to add
66
- */
67
- addEvent(event) {
68
- this._events.push(event);
69
- }
70
- /**
71
- * This adds a transaction to the share block
72
- * @param rulesEvaluation the evaluation of the rules (result)
73
- * @param transactionFunction the function that was run
74
- */
75
- addTransactionAlreadyValidated(proposedData, rulesEvaluation, transactionFunction) {
76
- // make sure the function is known.
77
- if (!this._functions.includes(transactionFunction)) {
78
- throw new Error('The function is not known');
79
- }
80
- const transactionTime = Date.now(); // get the current time
81
- const transactionId = this._transactionHistory.length + 1; // get the transaction id
82
- const ruleOutcome = (rulesEvaluation.proposedResult && rulesEvaluation.currentResult);
83
- const transaction = {
84
- ruleOutcome,
85
- ruleFailures: [],
86
- transactionFunction,
87
- transactionId: transactionId.toString(),
88
- transactionTime,
89
- };
90
- // the outcome of the rules is valid write the data to be the new current data.
91
- if (ruleOutcome) {
92
- this._data = proposedData;
93
- }
94
- this._transactionHistory.push(transaction);
95
- }
96
- /**
97
- * This adds a transaction to the share block but the transaction has not yet been validated
98
- *
99
- * @param proposedData the proposed data
100
- * @param transactionFunction the function that was attempted
101
- */
102
- addTransactionNotValidated(proposedData, transactionFunction) {
103
- // make sure the function is known.
104
- if (!this._functions.includes(transactionFunction)) {
105
- // throw ShareDataFunctionBeingAppliedDoesNotExistOnShareDataError
106
- throw new Error('The function is not known');
107
- }
108
- // // evaluate the rules.
109
- // const rulesEvalOutcome = evaluateRules('transaction', this._data, proposedData, this._rules);
110
- const rulesOutcome = (0, dist_1.startRuleEvaluation)(this._id, transactionFunction, this.functions, this._rules, this._data, proposedData);
111
- const transactionTime = Date.now(); // get the current time
112
- const transactionId = this._transactionHistory.length + 1; // get the transaction id
113
- const transaction = {
114
- ruleOutcome: rulesOutcome.isValidProposal,
115
- ruleFailures: [],
116
- transactionFunction,
117
- transactionId: transactionId.toString(),
118
- transactionTime,
119
- };
120
- // update the data if the rules are valid
121
- if (rulesOutcome.isValidProposal) {
122
- this._data = proposedData;
123
- }
124
- // add the transaction to the history
125
- this._transactionHistory.push(transaction);
126
- }
127
- /**
128
- * This gets the transaction history for the share block
129
- */
130
- get transactionHistory() {
131
- return this._transactionHistory;
132
- }
133
- /**
134
- * This returns the current state of data for the share block
135
- */
136
- get data() {
137
- return this._data;
138
- }
139
- /**
140
- * This gets the version of the share data
141
- */
142
- get version() {
143
- return this._version;
144
- }
145
- /**
146
- * This copies a share data object to a new transaction number
147
- * @param transactionNumber the number of the transaction to run until.
148
- */
149
- copyTo(transactionNumber) {
150
- // return share data with a new ID
151
- const newShareData = new ShareData(`${this._id}-${transactionNumber}`);
152
- newShareData._rules = [...this._rules];
153
- newShareData._functions = [...this._functions];
154
- newShareData._transactionHistory = [...this._transactionHistory];
155
- newShareData._events = [...this._events];
156
- newShareData._data = { ...this._data };
157
- newShareData._version = this._version;
158
- return newShareData;
159
- }
160
- }
161
- exports.ShareData = ShareData;