chain-db-ts 0.0.2 → 1.0.0-rc.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/CHANGELOG.md +110 -0
- package/dist/cjs/features/chain-db.d.ts +23 -64
- package/dist/cjs/features/chain-db.js +100 -263
- package/dist/cjs/features/constants.d.ts +11 -11
- package/dist/cjs/features/constants.js +22 -12
- package/dist/cjs/features/events.d.ts +28 -0
- package/dist/cjs/features/events.js +89 -0
- package/dist/cjs/features/table-doc.d.ts +37 -0
- package/dist/cjs/features/table-doc.js +135 -0
- package/dist/cjs/features/table.d.ts +81 -9
- package/dist/cjs/features/table.js +226 -70
- package/dist/cjs/features/types.d.ts +79 -21
- package/dist/cjs/features/types.js +30 -8
- package/dist/cjs/features/utils.d.ts +2 -1
- package/dist/cjs/features/utils.js +5 -2
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/index.js +8 -3
- package/features/chain-db.d.ts +23 -64
- package/features/chain-db.js +101 -241
- package/features/constants.d.ts +11 -11
- package/features/constants.js +14 -11
- package/features/events.d.ts +28 -0
- package/features/events.js +84 -0
- package/features/table-doc.d.ts +37 -0
- package/features/table-doc.js +129 -0
- package/features/table.d.ts +81 -9
- package/features/table.js +227 -69
- package/features/types.d.ts +79 -21
- package/features/types.js +29 -7
- package/features/utils.d.ts +2 -1
- package/features/utils.js +5 -2
- package/index.d.ts +3 -2
- package/index.js +3 -1
- package/package.json +5 -3
- package/readme.md +260 -132
- package/dist/cjs/features/access.d.ts +0 -6
- package/dist/cjs/features/access.js +0 -22
- package/features/access.d.ts +0 -6
- package/features/access.js +0 -16
|
@@ -39,45 +39,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
exports.__esModule = true;
|
|
42
|
-
exports.get = void 0;
|
|
43
42
|
var axios_1 = __importDefault(require("axios"));
|
|
44
43
|
var constants_1 = require("./constants");
|
|
45
|
-
var types_1 = require("./types");
|
|
46
44
|
var utils_1 = require("./utils");
|
|
45
|
+
var table_doc_1 = require("./table-doc");
|
|
47
46
|
var Table = /** @class */ (function () {
|
|
48
|
-
function Table(
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
47
|
+
function Table(name, db) {
|
|
48
|
+
this.name = '';
|
|
49
|
+
this.currentDoc = {};
|
|
50
|
+
this.name = name;
|
|
52
51
|
this.db = db;
|
|
53
52
|
}
|
|
54
53
|
/**
|
|
55
|
-
* Persist table data
|
|
54
|
+
* Persist table's document data changes
|
|
56
55
|
*/
|
|
57
56
|
Table.prototype.persist = function () {
|
|
58
57
|
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
-
var url,
|
|
60
|
-
return __generator(this, function (
|
|
61
|
-
switch (
|
|
58
|
+
var url, body, response, e_1;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
62
61
|
case 0:
|
|
63
|
-
url = "".concat(this.db.
|
|
64
|
-
contract_data = JSON.stringify(this.table);
|
|
62
|
+
url = "".concat(this.db.server).concat((0, constants_1.PERSIST_NEW_DATA)(this.name));
|
|
65
63
|
body = {
|
|
66
|
-
|
|
67
|
-
contract_id: this.contract_id,
|
|
68
|
-
db_access_key: this.db.access_key,
|
|
69
|
-
data: contract_data
|
|
64
|
+
data: this.currentDoc
|
|
70
65
|
};
|
|
71
|
-
|
|
66
|
+
_a.label = 1;
|
|
72
67
|
case 1:
|
|
73
|
-
|
|
74
|
-
return [4 /*yield*/, (0, utils_1.post)(url, body)];
|
|
68
|
+
_a.trys.push([1, 3, , 4]);
|
|
69
|
+
return [4 /*yield*/, (0, utils_1.post)(url, body, this.db.auth)];
|
|
75
70
|
case 2:
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
response = _a.sent();
|
|
72
|
+
if (!response.data.success) {
|
|
73
|
+
throw new Error(response.data.message);
|
|
74
|
+
}
|
|
75
|
+
return [2 /*return*/, response.data.data];
|
|
78
76
|
case 3:
|
|
79
|
-
|
|
80
|
-
throw new Error(
|
|
77
|
+
e_1 = _a.sent();
|
|
78
|
+
throw new Error("Something went wrong with persist operation: ".concat(e_1.message || String(e_1)));
|
|
81
79
|
case 4: return [2 /*return*/];
|
|
82
80
|
}
|
|
83
81
|
});
|
|
@@ -86,32 +84,218 @@ var Table = /** @class */ (function () {
|
|
|
86
84
|
/**
|
|
87
85
|
* Get the history of changes. A list of transactions from the most recent to the most old
|
|
88
86
|
* in a range of depth
|
|
89
|
-
* @param
|
|
87
|
+
* @param limit
|
|
90
88
|
*/
|
|
91
|
-
Table.prototype.getHistory = function (
|
|
89
|
+
Table.prototype.getHistory = function (limit) {
|
|
92
90
|
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
-
var url,
|
|
94
|
-
return __generator(this, function (
|
|
95
|
-
switch (
|
|
91
|
+
var url, response, e_2;
|
|
92
|
+
return __generator(this, function (_a) {
|
|
93
|
+
switch (_a.label) {
|
|
96
94
|
case 0:
|
|
97
|
-
url = "".concat(this.db.
|
|
98
|
-
|
|
95
|
+
url = "".concat(this.db.server).concat((0, constants_1.GET_HISTORY)(this.name, limit));
|
|
96
|
+
_a.label = 1;
|
|
99
97
|
case 1:
|
|
100
|
-
|
|
101
|
-
return [4 /*yield*/, axios_1["default"].get(url)];
|
|
98
|
+
_a.trys.push([1, 3, , 4]);
|
|
99
|
+
return [4 /*yield*/, axios_1["default"].get(url, { headers: { Authorization: "Basic ".concat(this.db.auth) } })];
|
|
102
100
|
case 2:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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*/, []];
|
|
101
|
+
response = _a.sent();
|
|
102
|
+
if (!response.data.success) {
|
|
103
|
+
throw new Error(response.data.message);
|
|
109
104
|
}
|
|
110
105
|
// Return data. Only table fields, e.g.: [{fieldA: 'Hi', filedB: 22}]
|
|
111
|
-
return [2 /*return*/,
|
|
106
|
+
return [2 /*return*/, response.data.data];
|
|
107
|
+
case 3:
|
|
108
|
+
e_2 = _a.sent();
|
|
109
|
+
throw new Error("Something went wrong with getHistory operation: ".concat(e_2.message || String(e_2)));
|
|
110
|
+
case 4: return [2 /*return*/];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Refetch the table data
|
|
117
|
+
*/
|
|
118
|
+
Table.prototype.refetch = function () {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
+
var url, response, e_3;
|
|
121
|
+
return __generator(this, function (_a) {
|
|
122
|
+
switch (_a.label) {
|
|
123
|
+
case 0:
|
|
124
|
+
url = "".concat(this.db.server).concat((0, constants_1.GET_TABLE)(this.name));
|
|
125
|
+
_a.label = 1;
|
|
126
|
+
case 1:
|
|
127
|
+
_a.trys.push([1, 3, , 4]);
|
|
128
|
+
return [4 /*yield*/, axios_1["default"].get(url, { headers: { Authorization: "Basic ".concat(this.db.auth) } })];
|
|
129
|
+
case 2:
|
|
130
|
+
response = _a.sent();
|
|
131
|
+
this.currentDoc = response.data.data ? response.data.data : {};
|
|
132
|
+
return [3 /*break*/, 4];
|
|
112
133
|
case 3:
|
|
113
|
-
|
|
114
|
-
throw new Error(
|
|
134
|
+
e_3 = _a.sent();
|
|
135
|
+
throw new Error("Something went wrong with refetch operation: ".concat(e_3.message || String(e_3)));
|
|
136
|
+
case 4: return [2 /*return*/];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Check if the table is empty
|
|
143
|
+
*/
|
|
144
|
+
Table.prototype.isEmpty = function () {
|
|
145
|
+
return Object.keys(this.currentDoc).length === 0;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Get the table's name
|
|
149
|
+
*/
|
|
150
|
+
Table.prototype.getName = function () {
|
|
151
|
+
return this.name;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Find items in the table using basic criteria with exact matches
|
|
155
|
+
* @param criteria Object with fields and values to match exactly, e.g.: {age: 44, name: "john"}
|
|
156
|
+
* @param limit Maximum number of items to return (default: 1000)
|
|
157
|
+
* @param reverse If true, returns items in reverse order (default: true)
|
|
158
|
+
* @returns Array of found items matching the criteria
|
|
159
|
+
* @example
|
|
160
|
+
* // Find items where age is 44
|
|
161
|
+
* table.findWhere({
|
|
162
|
+
* age: 44,
|
|
163
|
+
* })
|
|
164
|
+
*
|
|
165
|
+
* // Find items with multiple criteria
|
|
166
|
+
* table.findWhere({
|
|
167
|
+
* age: 44,
|
|
168
|
+
* name: "john",
|
|
169
|
+
* active: true,
|
|
170
|
+
* score: 100
|
|
171
|
+
* })
|
|
172
|
+
*/
|
|
173
|
+
Table.prototype.findWhere = function (criteria, limit, reverse) {
|
|
174
|
+
if (limit === void 0) { limit = 1000; }
|
|
175
|
+
if (reverse === void 0) { reverse = true; }
|
|
176
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
177
|
+
var url, body, response, e_4;
|
|
178
|
+
return __generator(this, function (_a) {
|
|
179
|
+
switch (_a.label) {
|
|
180
|
+
case 0:
|
|
181
|
+
url = "".concat(this.db.server).concat((0, constants_1.FIND_WHERE_BASIC)(this.name));
|
|
182
|
+
body = {
|
|
183
|
+
criteria: criteria,
|
|
184
|
+
limit: limit,
|
|
185
|
+
reverse: reverse
|
|
186
|
+
};
|
|
187
|
+
_a.label = 1;
|
|
188
|
+
case 1:
|
|
189
|
+
_a.trys.push([1, 3, , 4]);
|
|
190
|
+
return [4 /*yield*/, (0, utils_1.post)(url, body, this.db.auth)];
|
|
191
|
+
case 2:
|
|
192
|
+
response = _a.sent();
|
|
193
|
+
if (!response.data.success) {
|
|
194
|
+
throw new Error(response.data.message);
|
|
195
|
+
}
|
|
196
|
+
// Return found data. Only table fields, e.g.: [{fieldA: 'Hi', filedB: 22}]
|
|
197
|
+
return [2 /*return*/, response.data.data];
|
|
198
|
+
case 3:
|
|
199
|
+
e_4 = _a.sent();
|
|
200
|
+
throw new Error("Something went wrong with findWhere operation: ".concat(e_4.message || String(e_4)));
|
|
201
|
+
case 4: return [2 /*return*/];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Find items in the table using advanced criteria with operators
|
|
208
|
+
* @param criteria Array of criteria to filter items. Each criteria contains:
|
|
209
|
+
* - field: The field name to filter
|
|
210
|
+
* - operator: The operator to use in comparison. Available operators:
|
|
211
|
+
* - Eq (==) Equal
|
|
212
|
+
* - Ne (!=) Not Equal
|
|
213
|
+
* - Gt (>) Greater Than
|
|
214
|
+
* - Ge (>=) Greater Than or Equal
|
|
215
|
+
* - Lt (<) Less Than
|
|
216
|
+
* - Le (<=) Less Than or Equal
|
|
217
|
+
* - Contains: Check if field contains value (for strings and arrays)
|
|
218
|
+
* - StartsWith: Check if field starts with value (for strings)
|
|
219
|
+
* - EndsWith: Check if field ends with value (for strings)
|
|
220
|
+
* - value: The value to compare against
|
|
221
|
+
* @param limit Maximum number of items to return (default: 1000)
|
|
222
|
+
* @param reverse If true, returns items in reverse order (default: true)
|
|
223
|
+
* @returns Array of found items matching the criteria
|
|
224
|
+
* @example
|
|
225
|
+
* // Find items where greeting contains "arg"
|
|
226
|
+
* table.findWhereAdvanced([
|
|
227
|
+
* {
|
|
228
|
+
* field: "greeting",
|
|
229
|
+
* operator: Operators.Contains,
|
|
230
|
+
* value: "hello"
|
|
231
|
+
* }
|
|
232
|
+
* ])
|
|
233
|
+
*/
|
|
234
|
+
Table.prototype.findWhereAdvanced = function (criteria, limit, reverse) {
|
|
235
|
+
if (limit === void 0) { limit = 1000; }
|
|
236
|
+
if (reverse === void 0) { reverse = true; }
|
|
237
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
238
|
+
var url, body, response, e_5;
|
|
239
|
+
return __generator(this, function (_a) {
|
|
240
|
+
switch (_a.label) {
|
|
241
|
+
case 0:
|
|
242
|
+
url = "".concat(this.db.server).concat((0, constants_1.FIND_WHERE_ADVANCED)(this.name));
|
|
243
|
+
body = {
|
|
244
|
+
criteria: criteria,
|
|
245
|
+
limit: limit,
|
|
246
|
+
reverse: reverse
|
|
247
|
+
};
|
|
248
|
+
_a.label = 1;
|
|
249
|
+
case 1:
|
|
250
|
+
_a.trys.push([1, 3, , 4]);
|
|
251
|
+
return [4 /*yield*/, (0, utils_1.post)(url, body, this.db.auth)];
|
|
252
|
+
case 2:
|
|
253
|
+
response = _a.sent();
|
|
254
|
+
if (!response.data.success) {
|
|
255
|
+
throw new Error(response.data.message);
|
|
256
|
+
}
|
|
257
|
+
// Return found data. Only table fields, e.g.: [{fieldA: 'Hi', filedB: 22}]
|
|
258
|
+
return [2 /*return*/, response.data.data];
|
|
259
|
+
case 3:
|
|
260
|
+
e_5 = _a.sent();
|
|
261
|
+
throw new Error("Something went wrong with findWhereAdvanced operation: ".concat(e_5.message || String(e_5)));
|
|
262
|
+
case 4: return [2 /*return*/];
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Get the current document ID
|
|
269
|
+
*/
|
|
270
|
+
Table.prototype.getCurrentDocId = function () {
|
|
271
|
+
return this.currentDoc.doc_id;
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Get a specific document by its ID
|
|
275
|
+
* @param doc_id The document ID to retrieve
|
|
276
|
+
* @returns A TableDoc instance with the specific document data
|
|
277
|
+
*/
|
|
278
|
+
Table.prototype.getDoc = function (doc_id) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
280
|
+
var url, response, e_6;
|
|
281
|
+
return __generator(this, function (_a) {
|
|
282
|
+
switch (_a.label) {
|
|
283
|
+
case 0:
|
|
284
|
+
url = "".concat(this.db.server).concat((0, constants_1.GET_DOC)(this.name, doc_id));
|
|
285
|
+
_a.label = 1;
|
|
286
|
+
case 1:
|
|
287
|
+
_a.trys.push([1, 3, , 4]);
|
|
288
|
+
return [4 /*yield*/, axios_1["default"].get(url, { headers: { Authorization: "Basic ".concat(this.db.auth) } })];
|
|
289
|
+
case 2:
|
|
290
|
+
response = _a.sent();
|
|
291
|
+
if (!response.data.success) {
|
|
292
|
+
throw new Error(response.data.message);
|
|
293
|
+
}
|
|
294
|
+
// Create a TableDoc instance with the document data
|
|
295
|
+
return [2 /*return*/, new table_doc_1.TableDocImpl(this.name, doc_id, response.data.data, this.db)];
|
|
296
|
+
case 3:
|
|
297
|
+
e_6 = _a.sent();
|
|
298
|
+
throw new Error("Something went wrong with getDoc operation: ".concat(e_6.message || String(e_6)));
|
|
115
299
|
case 4: return [2 /*return*/];
|
|
116
300
|
}
|
|
117
301
|
});
|
|
@@ -119,32 +303,4 @@ var Table = /** @class */ (function () {
|
|
|
119
303
|
};
|
|
120
304
|
return Table;
|
|
121
305
|
}());
|
|
122
|
-
|
|
123
|
-
var contract_id, url, contract_response, contract_data_json, table_1, table, _a;
|
|
124
|
-
return __generator(this, function (_b) {
|
|
125
|
-
switch (_b.label) {
|
|
126
|
-
case 0:
|
|
127
|
-
contract_id = db.access.parse(db.name, table_name);
|
|
128
|
-
url = "".concat(db.api).concat(constants_1.CONTRACT_PAYLOAD, "/").concat(contract_id, "/").concat(db.access_key);
|
|
129
|
-
_b.label = 1;
|
|
130
|
-
case 1:
|
|
131
|
-
_b.trys.push([1, 3, , 4]);
|
|
132
|
-
return [4 /*yield*/, axios_1["default"].get(url)];
|
|
133
|
-
case 2:
|
|
134
|
-
contract_response = _b.sent();
|
|
135
|
-
contract_data_json = contract_response.data;
|
|
136
|
-
// If there's already a table (contract) with data, then, fetch its data
|
|
137
|
-
if (contract_data_json.tx_type === types_1.TransactionType.CONTRACT) {
|
|
138
|
-
table_1 = new Table(contract_data_json.data, contract_id, db);
|
|
139
|
-
return [2 /*return*/, table_1];
|
|
140
|
-
}
|
|
141
|
-
table = new Table(model, contract_id, db);
|
|
142
|
-
return [2 /*return*/, table];
|
|
143
|
-
case 3:
|
|
144
|
-
_a = _b.sent();
|
|
145
|
-
throw new Error('Something went wrong!');
|
|
146
|
-
case 4: return [2 /*return*/];
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}); };
|
|
150
|
-
exports.get = get;
|
|
306
|
+
exports["default"] = Table;
|
|
@@ -1,29 +1,87 @@
|
|
|
1
1
|
export type BasicResponse<D> = {
|
|
2
2
|
success: boolean;
|
|
3
|
-
|
|
3
|
+
message: string;
|
|
4
4
|
data?: D;
|
|
5
5
|
};
|
|
6
|
-
export type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export type Connection = {
|
|
7
|
+
server: string | null;
|
|
8
|
+
database: string;
|
|
9
|
+
user: string;
|
|
10
|
+
password: string;
|
|
10
11
|
};
|
|
11
|
-
export type
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export type Criteria<Model> = Partial<Record<keyof Model, string | number | boolean>>;
|
|
13
|
+
export type CriteriaAdvanced<Model> = {
|
|
14
|
+
field: Partial<keyof Model>;
|
|
15
|
+
/**
|
|
16
|
+
* @see Operators
|
|
17
|
+
*/
|
|
18
|
+
operator: string;
|
|
19
|
+
value: string | number | boolean;
|
|
15
20
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Operators for the advanced criteria
|
|
23
|
+
* @see https://docs.chaindb.com/docs/query-language/ (TODO)
|
|
24
|
+
*/
|
|
25
|
+
export declare const Operators: {
|
|
26
|
+
EQUAL: string;
|
|
27
|
+
NOT_EQUAL: string;
|
|
28
|
+
GREATER_THAN: string;
|
|
29
|
+
GREATER_THAN_OR_EQUAL: string;
|
|
30
|
+
LESS_THAN: string;
|
|
31
|
+
LESS_THAN_OR_EQUAL: string;
|
|
32
|
+
CONTAINS: string;
|
|
33
|
+
STARTS_WITH: string;
|
|
34
|
+
ENDS_WITH: string;
|
|
35
|
+
};
|
|
36
|
+
export declare const EventTypes: {
|
|
37
|
+
TABLE_PERSIST: string;
|
|
38
|
+
TABLE_UPDATE: string;
|
|
39
|
+
};
|
|
40
|
+
export type EventData = {
|
|
41
|
+
event_type: string;
|
|
42
|
+
database: string;
|
|
43
|
+
table: string;
|
|
44
|
+
/**
|
|
45
|
+
* Data of the event (also to/from the table)
|
|
46
|
+
*/
|
|
47
|
+
data: Record<string, any>;
|
|
48
|
+
/**
|
|
49
|
+
* Timestamp of the event
|
|
50
|
+
*/
|
|
51
|
+
timestamp: number;
|
|
52
|
+
};
|
|
53
|
+
export type EventCallback = (data: EventData) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Represents a specific document from a table
|
|
56
|
+
* Contains only the necessary methods to work with a specific document
|
|
57
|
+
*/
|
|
58
|
+
export interface TableDoc<Model> {
|
|
59
|
+
/**
|
|
60
|
+
* The document data
|
|
61
|
+
*/
|
|
62
|
+
doc: DocId<Model>;
|
|
63
|
+
/**
|
|
64
|
+
* Update the document data
|
|
65
|
+
* This will update the specific document without creating a new one
|
|
66
|
+
*/
|
|
67
|
+
update(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Get the table name this document belongs to
|
|
70
|
+
*/
|
|
71
|
+
getTableName(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Refetch the document data from the database
|
|
74
|
+
* Useful when the document might have been updated by another application
|
|
75
|
+
*/
|
|
76
|
+
refetch(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Check if the document is empty
|
|
79
|
+
*/
|
|
80
|
+
isEmpty(): boolean;
|
|
21
81
|
}
|
|
22
|
-
export type
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
block_hash: string;
|
|
28
|
-
block_height: number;
|
|
82
|
+
export type DocId<Model> = Model & {
|
|
83
|
+
/**
|
|
84
|
+
* The document ID (unique identifier). Immutable.
|
|
85
|
+
*/
|
|
86
|
+
readonly doc_id: string;
|
|
29
87
|
};
|
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
exports.__esModule = true;
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
exports.EventTypes = exports.Operators = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Operators for the advanced criteria
|
|
6
|
+
* @see https://docs.chaindb.com/docs/query-language/ (TODO)
|
|
7
|
+
*/
|
|
8
|
+
exports.Operators = {
|
|
9
|
+
// (==)
|
|
10
|
+
EQUAL: 'Eq',
|
|
11
|
+
// (!=)
|
|
12
|
+
NOT_EQUAL: 'Ne',
|
|
13
|
+
// (>)
|
|
14
|
+
GREATER_THAN: 'Gt',
|
|
15
|
+
// (>=)
|
|
16
|
+
GREATER_THAN_OR_EQUAL: 'Ge',
|
|
17
|
+
// (<)
|
|
18
|
+
LESS_THAN: 'Lt',
|
|
19
|
+
// (<=)
|
|
20
|
+
LESS_THAN_OR_EQUAL: 'Le',
|
|
21
|
+
// (for strings and arrays)
|
|
22
|
+
CONTAINS: 'Contains',
|
|
23
|
+
// (for strings)
|
|
24
|
+
STARTS_WITH: 'StartsWith',
|
|
25
|
+
// (for strings)
|
|
26
|
+
ENDS_WITH: 'EndsWith'
|
|
27
|
+
};
|
|
28
|
+
// Events
|
|
29
|
+
exports.EventTypes = {
|
|
30
|
+
TABLE_PERSIST: 'TablePersist',
|
|
31
|
+
TABLE_UPDATE: 'TableUpdate'
|
|
32
|
+
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { BasicResponse } from './types';
|
|
2
|
+
export declare const post: (url: string, body: any, auth?: string) => Promise<import("axios").AxiosResponse<BasicResponse<any>, any>>;
|
|
@@ -5,7 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.post = void 0;
|
|
7
7
|
var axios_1 = __importDefault(require("axios"));
|
|
8
|
-
var post = function (url, body) {
|
|
9
|
-
|
|
8
|
+
var post = function (url, body, auth) {
|
|
9
|
+
if (auth === void 0) { auth = ''; }
|
|
10
|
+
return axios_1["default"].post(url, body, {
|
|
11
|
+
headers: { 'content-type': 'application/json', Authorization: "Basic ".concat(auth) }
|
|
12
|
+
});
|
|
10
13
|
};
|
|
11
14
|
exports.post = post;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { ChainDB, connect } from './features/chain-db';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { BasicResponse, Operators, CriteriaAdvanced, Criteria, TableDoc, EventTypes, EventData, EventCallback, } from './features/types';
|
|
3
|
+
export { default as Events } from './features/events';
|
|
4
|
+
export { TableDocImpl } from './features/table-doc';
|
package/dist/cjs/index.js
CHANGED
|
@@ -11,9 +11,14 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
13
|
exports.__esModule = true;
|
|
14
|
-
exports.
|
|
14
|
+
exports.TableDocImpl = exports.Events = exports.EventTypes = exports.Operators = exports.connect = exports.ChainDB = void 0;
|
|
15
15
|
var chain_db_1 = require("./features/chain-db");
|
|
16
16
|
__createBinding(exports, chain_db_1, "ChainDB");
|
|
17
17
|
__createBinding(exports, chain_db_1, "connect");
|
|
18
|
-
var
|
|
19
|
-
__createBinding(exports,
|
|
18
|
+
var types_1 = require("./features/types");
|
|
19
|
+
__createBinding(exports, types_1, "Operators");
|
|
20
|
+
__createBinding(exports, types_1, "EventTypes");
|
|
21
|
+
var events_1 = require("./features/events");
|
|
22
|
+
__createBinding(exports, events_1, "default", "Events");
|
|
23
|
+
var table_doc_1 = require("./features/table-doc");
|
|
24
|
+
__createBinding(exports, table_doc_1, "TableDocImpl");
|
package/features/chain-db.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import Table from './table';
|
|
2
|
+
import { Connection, EventCallback } from './types';
|
|
3
3
|
export declare class ChainDB {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
server: string;
|
|
5
|
+
database: string;
|
|
6
|
+
auth: string;
|
|
7
|
+
private _events;
|
|
8
8
|
/**
|
|
9
9
|
* Connection information.
|
|
10
10
|
* @param server Server location. If the `server` parameter is empty, then "http://localhost" will be used.
|
|
@@ -12,69 +12,28 @@ export declare class ChainDB {
|
|
|
12
12
|
* @param user User to access the data base
|
|
13
13
|
* @param password Password to access the data base
|
|
14
14
|
*/
|
|
15
|
-
connect(
|
|
16
|
-
/**
|
|
17
|
-
* Create a new user account inside the connected table
|
|
18
|
-
* @param user_name
|
|
19
|
-
* @param password
|
|
20
|
-
* @param units
|
|
21
|
-
* @param password_hint
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
create_user_account(user_name: string, password: string, units?: number, password_hint?: string): Promise<BasicResponse<SignedUserAccount>>;
|
|
25
|
-
/**
|
|
26
|
-
* Get user account info (login method)
|
|
27
|
-
* @param user_name
|
|
28
|
-
* @param password
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
|
-
get_user_account(user_name: string, password: string): Promise<BasicResponse<SignedUserAccount>>;
|
|
32
|
-
/**
|
|
33
|
-
* Get user account info by its id
|
|
34
|
-
* @param user_id
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
get_user_account_by_id(user_id: string): Promise<BasicResponse<SignedUserAccount>>;
|
|
38
|
-
/**
|
|
39
|
-
* Check if user_name is already taken
|
|
40
|
-
* @param user_name
|
|
41
|
-
*/
|
|
42
|
-
check_user_name(user_name: string): Promise<BasicResponse<string>>;
|
|
43
|
-
/**
|
|
44
|
-
* Transfer units between users
|
|
45
|
-
* @param from user_id
|
|
46
|
-
* @param to user_id
|
|
47
|
-
* @param units
|
|
48
|
-
* @returns
|
|
49
|
-
*/
|
|
50
|
-
transfer_units(from: string, to: string, units: number): Promise<BasicResponse<null>>;
|
|
51
|
-
/**
|
|
52
|
-
* Fetch the last Transference of units Records by User
|
|
53
|
-
* @param user_id
|
|
54
|
-
* @returns
|
|
55
|
-
*/
|
|
56
|
-
get_transfer_by_user_id(user_id: string): Promise<BasicResponse<TransferUnitsRegistry>>;
|
|
57
|
-
/**
|
|
58
|
-
* Fetch all Transference of units Records by User
|
|
59
|
-
* @param user_id
|
|
60
|
-
* @returns
|
|
61
|
-
*/
|
|
62
|
-
get_all_transfers_by_user_id(user_id: string): Promise<BasicResponse<TransferUnitsRegistry[]>>;
|
|
15
|
+
connect(connection: Connection): Promise<void>;
|
|
63
16
|
/**
|
|
64
17
|
* Initialize a table, fetching its more updated data
|
|
65
18
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
19
|
+
getTable<Model>(table_name: string): Promise<Table<Model>>;
|
|
20
|
+
events(): {
|
|
21
|
+
/**
|
|
22
|
+
* Subscribe to an event
|
|
23
|
+
* @param event Event name to subscribe to @see {EventTypes}
|
|
24
|
+
* @param callback Function to call when the event is received
|
|
25
|
+
*/
|
|
26
|
+
subscribe: (event: string, callback: EventCallback) => void;
|
|
68
27
|
/**
|
|
69
|
-
*
|
|
28
|
+
* Unsubscribe from an event
|
|
29
|
+
* @param event Event name to unsubscribe from @see {EventTypes}
|
|
30
|
+
* @param callback Optional callback to remove. If not provided, all callbacks for the event will be removed.
|
|
70
31
|
*/
|
|
71
|
-
|
|
32
|
+
unsubscribe: (event: string, callback?: EventCallback) => void;
|
|
72
33
|
/**
|
|
73
|
-
*
|
|
74
|
-
* in a range of depth
|
|
75
|
-
* @param depth
|
|
34
|
+
* Close the events transmission
|
|
76
35
|
*/
|
|
77
|
-
|
|
78
|
-
}
|
|
36
|
+
closeEvents: () => void;
|
|
37
|
+
};
|
|
79
38
|
}
|
|
80
|
-
export declare const connect: (
|
|
39
|
+
export declare const connect: (connection: Connection) => Promise<ChainDB>;
|