chain-db-ts 0.0.1 → 0.0.2
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/cjs/features/chain-db.d.ts +6 -0
- package/dist/cjs/features/constants.d.ts +1 -0
- package/dist/cjs/features/constants.js +2 -1
- package/dist/cjs/features/table.d.ts +6 -0
- package/dist/cjs/features/table.js +34 -0
- package/dist/cjs/features/types.d.ts +2 -0
- package/features/chain-db.d.ts +6 -0
- package/features/constants.d.ts +1 -0
- package/features/constants.js +1 -0
- package/features/table.d.ts +6 -0
- package/features/table.js +35 -1
- package/features/types.d.ts +2 -0
- package/package.json +1 -1
- package/tsconfig.json +0 -33
|
@@ -69,6 +69,12 @@ export declare class ChainDB {
|
|
|
69
69
|
* Persist table data on chain
|
|
70
70
|
*/
|
|
71
71
|
persist: () => Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Get the history of changes. A list of transactions from the most recent to the most old
|
|
74
|
+
* in a range of depth
|
|
75
|
+
* @param depth
|
|
76
|
+
*/
|
|
77
|
+
getHistory: (depth: number) => Promise<Model[]>;
|
|
72
78
|
}>;
|
|
73
79
|
}
|
|
74
80
|
export declare const connect: (server: string | null, data_base: string, user: string, password: string) => ChainDB;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const API = "http://localhost:2818";
|
|
2
2
|
export declare const CONTRACT_PAYLOAD = "/get_last_contract_transaction";
|
|
3
|
+
export declare const CONTRACT_TRANSACTIONS_PAYLOAD = "/get_contract_transactions";
|
|
3
4
|
export declare const CONTRACT_TRANSACTION = "/post_contract_transaction";
|
|
4
5
|
export declare const CREATE_USER_ACCOUNT = "/create_user_account";
|
|
5
6
|
export declare const GET_USER_ACCOUNT = "/get_user_account";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
exports.__esModule = true;
|
|
3
|
-
exports.CHECK_USER_NAME = exports.GET_ALL_TRANSFER_BY_USER_ID = exports.GET_TRANSFER_BY_USER_ID = exports.TRANSFER_UNITS = exports.GET_USER_ACCOUNT_BY_ID = exports.GET_USER_ACCOUNT = exports.CREATE_USER_ACCOUNT = exports.CONTRACT_TRANSACTION = exports.CONTRACT_PAYLOAD = exports.API = void 0;
|
|
3
|
+
exports.CHECK_USER_NAME = exports.GET_ALL_TRANSFER_BY_USER_ID = exports.GET_TRANSFER_BY_USER_ID = exports.TRANSFER_UNITS = exports.GET_USER_ACCOUNT_BY_ID = exports.GET_USER_ACCOUNT = exports.CREATE_USER_ACCOUNT = exports.CONTRACT_TRANSACTION = exports.CONTRACT_TRANSACTIONS_PAYLOAD = exports.CONTRACT_PAYLOAD = exports.API = void 0;
|
|
4
4
|
// Contants
|
|
5
5
|
exports.API = 'http://localhost:2818';
|
|
6
6
|
exports.CONTRACT_PAYLOAD = '/get_last_contract_transaction';
|
|
7
|
+
exports.CONTRACT_TRANSACTIONS_PAYLOAD = '/get_contract_transactions';
|
|
7
8
|
exports.CONTRACT_TRANSACTION = '/post_contract_transaction';
|
|
8
9
|
exports.CREATE_USER_ACCOUNT = '/create_user_account';
|
|
9
10
|
exports.GET_USER_ACCOUNT = '/get_user_account';
|
|
@@ -8,6 +8,12 @@ declare class Table<Model> {
|
|
|
8
8
|
* Persist table data on chain
|
|
9
9
|
*/
|
|
10
10
|
persist(): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Get the history of changes. A list of transactions from the most recent to the most old
|
|
13
|
+
* in a range of depth
|
|
14
|
+
* @param depth
|
|
15
|
+
*/
|
|
16
|
+
getHistory(depth: number): Promise<Model[]>;
|
|
11
17
|
}
|
|
12
18
|
export declare const get: <Model>(db: ChainDB, table_name: string, model: Model) => Promise<Table<Model>>;
|
|
13
19
|
export {};
|
|
@@ -83,6 +83,40 @@ var Table = /** @class */ (function () {
|
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* Get the history of changes. A list of transactions from the most recent to the most old
|
|
88
|
+
* in a range of depth
|
|
89
|
+
* @param depth
|
|
90
|
+
*/
|
|
91
|
+
Table.prototype.getHistory = function (depth) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
var url, contract_response, contract_data_json_list, transaction_data, _a;
|
|
94
|
+
return __generator(this, function (_b) {
|
|
95
|
+
switch (_b.label) {
|
|
96
|
+
case 0:
|
|
97
|
+
url = "".concat(this.db.api).concat(constants_1.CONTRACT_TRANSACTIONS_PAYLOAD, "/").concat(this.contract_id, "/").concat(this.db.access_key, "/").concat(depth);
|
|
98
|
+
_b.label = 1;
|
|
99
|
+
case 1:
|
|
100
|
+
_b.trys.push([1, 3, , 4]);
|
|
101
|
+
return [4 /*yield*/, axios_1["default"].get(url)];
|
|
102
|
+
case 2:
|
|
103
|
+
contract_response = _b.sent();
|
|
104
|
+
contract_data_json_list = contract_response.data;
|
|
105
|
+
transaction_data = contract_data_json_list.map(function (transaction) { return transaction.data; });
|
|
106
|
+
// Return empty if theres no data
|
|
107
|
+
if (contract_data_json_list.length === 1 && contract_data_json_list[0].tx_type === types_1.TransactionType.NONE) {
|
|
108
|
+
return [2 /*return*/, []];
|
|
109
|
+
}
|
|
110
|
+
// Return data. Only table fields, e.g.: [{fieldA: 'Hi', filedB: 22}]
|
|
111
|
+
return [2 /*return*/, transaction_data];
|
|
112
|
+
case 3:
|
|
113
|
+
_a = _b.sent();
|
|
114
|
+
throw new Error('Something went wrong!');
|
|
115
|
+
case 4: return [2 /*return*/];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
86
120
|
return Table;
|
|
87
121
|
}());
|
|
88
122
|
var get = function (db, table_name, model) { return __awaiter(void 0, void 0, void 0, function () {
|
package/features/chain-db.d.ts
CHANGED
|
@@ -69,6 +69,12 @@ export declare class ChainDB {
|
|
|
69
69
|
* Persist table data on chain
|
|
70
70
|
*/
|
|
71
71
|
persist: () => Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Get the history of changes. A list of transactions from the most recent to the most old
|
|
74
|
+
* in a range of depth
|
|
75
|
+
* @param depth
|
|
76
|
+
*/
|
|
77
|
+
getHistory: (depth: number) => Promise<Model[]>;
|
|
72
78
|
}>;
|
|
73
79
|
}
|
|
74
80
|
export declare const connect: (server: string | null, data_base: string, user: string, password: string) => ChainDB;
|
package/features/constants.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const API = "http://localhost:2818";
|
|
2
2
|
export declare const CONTRACT_PAYLOAD = "/get_last_contract_transaction";
|
|
3
|
+
export declare const CONTRACT_TRANSACTIONS_PAYLOAD = "/get_contract_transactions";
|
|
3
4
|
export declare const CONTRACT_TRANSACTION = "/post_contract_transaction";
|
|
4
5
|
export declare const CREATE_USER_ACCOUNT = "/create_user_account";
|
|
5
6
|
export declare const GET_USER_ACCOUNT = "/get_user_account";
|
package/features/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Contants
|
|
2
2
|
export var API = 'http://localhost:2818';
|
|
3
3
|
export var CONTRACT_PAYLOAD = '/get_last_contract_transaction';
|
|
4
|
+
export var CONTRACT_TRANSACTIONS_PAYLOAD = '/get_contract_transactions';
|
|
4
5
|
export var CONTRACT_TRANSACTION = '/post_contract_transaction';
|
|
5
6
|
export var CREATE_USER_ACCOUNT = '/create_user_account';
|
|
6
7
|
export var GET_USER_ACCOUNT = '/get_user_account';
|
package/features/table.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ declare class Table<Model> {
|
|
|
8
8
|
* Persist table data on chain
|
|
9
9
|
*/
|
|
10
10
|
persist(): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Get the history of changes. A list of transactions from the most recent to the most old
|
|
13
|
+
* in a range of depth
|
|
14
|
+
* @param depth
|
|
15
|
+
*/
|
|
16
|
+
getHistory(depth: number): Promise<Model[]>;
|
|
11
17
|
}
|
|
12
18
|
export declare const get: <Model>(db: ChainDB, table_name: string, model: Model) => Promise<Table<Model>>;
|
|
13
19
|
export {};
|
package/features/table.js
CHANGED
|
@@ -35,7 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
import axios from 'axios';
|
|
38
|
-
import { CONTRACT_PAYLOAD, CONTRACT_TRANSACTION } from './constants';
|
|
38
|
+
import { CONTRACT_PAYLOAD, CONTRACT_TRANSACTION, CONTRACT_TRANSACTIONS_PAYLOAD } from './constants';
|
|
39
39
|
import { TransactionType } from './types';
|
|
40
40
|
import { post } from './utils';
|
|
41
41
|
var Table = /** @class */ (function () {
|
|
@@ -77,6 +77,40 @@ var Table = /** @class */ (function () {
|
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* Get the history of changes. A list of transactions from the most recent to the most old
|
|
82
|
+
* in a range of depth
|
|
83
|
+
* @param depth
|
|
84
|
+
*/
|
|
85
|
+
Table.prototype.getHistory = function (depth) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
var url, contract_response, contract_data_json_list, transaction_data, _a;
|
|
88
|
+
return __generator(this, function (_b) {
|
|
89
|
+
switch (_b.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
url = "".concat(this.db.api).concat(CONTRACT_TRANSACTIONS_PAYLOAD, "/").concat(this.contract_id, "/").concat(this.db.access_key, "/").concat(depth);
|
|
92
|
+
_b.label = 1;
|
|
93
|
+
case 1:
|
|
94
|
+
_b.trys.push([1, 3, , 4]);
|
|
95
|
+
return [4 /*yield*/, axios.get(url)];
|
|
96
|
+
case 2:
|
|
97
|
+
contract_response = _b.sent();
|
|
98
|
+
contract_data_json_list = contract_response.data;
|
|
99
|
+
transaction_data = contract_data_json_list.map(function (transaction) { return transaction.data; });
|
|
100
|
+
// Return empty if theres no data
|
|
101
|
+
if (contract_data_json_list.length === 1 && contract_data_json_list[0].tx_type === TransactionType.NONE) {
|
|
102
|
+
return [2 /*return*/, []];
|
|
103
|
+
}
|
|
104
|
+
// Return data. Only table fields, e.g.: [{fieldA: 'Hi', filedB: 22}]
|
|
105
|
+
return [2 /*return*/, transaction_data];
|
|
106
|
+
case 3:
|
|
107
|
+
_a = _b.sent();
|
|
108
|
+
throw new Error('Something went wrong!');
|
|
109
|
+
case 4: return [2 /*return*/];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
80
114
|
return Table;
|
|
81
115
|
}());
|
|
82
116
|
export var get = function (db, table_name, model) { return __awaiter(void 0, void 0, void 0, function () {
|
package/features/types.d.ts
CHANGED
package/package.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -22,36 +22,3 @@
|
|
|
22
22
|
"baseUrl": "."
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
// {
|
|
27
|
-
// "compilerOptions": {
|
|
28
|
-
// "target": "es5",
|
|
29
|
-
// "module": "ESNext",
|
|
30
|
-
// "lib": ["es6", "esnext", "es2016", "es2017", "es2022"],
|
|
31
|
-
// "allowJs": true,
|
|
32
|
-
// "outDir": "build",
|
|
33
|
-
// "rootDir": "src",
|
|
34
|
-
// "strict": true,
|
|
35
|
-
// "noImplicitAny": true,
|
|
36
|
-
// "esModuleInterop": true,
|
|
37
|
-
// "resolveJsonModule": true,
|
|
38
|
-
// "moduleResolution": "node"
|
|
39
|
-
// }
|
|
40
|
-
// }
|
|
41
|
-
|
|
42
|
-
// {
|
|
43
|
-
// "compilerOptions": {
|
|
44
|
-
// "target": "es6",
|
|
45
|
-
// "module": "commonjs",
|
|
46
|
-
// "lib": ["es6", "esnext", "es2016", "es2017", "es2022"],
|
|
47
|
-
// "allowJs": true,
|
|
48
|
-
// "outDir": "build",
|
|
49
|
-
// "rootDir": "src",
|
|
50
|
-
// "strict": true,
|
|
51
|
-
// "noImplicitAny": true,
|
|
52
|
-
// "esModuleInterop": true,
|
|
53
|
-
// "resolveJsonModule": true,
|
|
54
|
-
// "moduleResolution": "node",
|
|
55
|
-
// "declaration": true
|
|
56
|
-
// }
|
|
57
|
-
// }
|