@or-sdk/key-value-storage 0.23.6 → 0.24.0
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 +9 -0
- package/dist/cjs/KeyValueStorage.js +189 -20
- package/dist/cjs/KeyValueStorage.js.map +1 -1
- package/dist/cjs/constants.js +9 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/utils/index.js +9 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/splitIntoParts.js +22 -0
- package/dist/cjs/utils/splitIntoParts.js.map +1 -0
- package/dist/esm/KeyValueStorage.js +94 -15
- package/dist/esm/KeyValueStorage.js.map +1 -1
- package/dist/esm/constants.js +8 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/splitIntoParts.js +20 -0
- package/dist/esm/utils/splitIntoParts.js.map +1 -0
- package/dist/types/KeyValueStorage.d.ts +13 -5
- package/dist/types/KeyValueStorage.d.ts.map +1 -1
- package/dist/types/constants.d.ts +7 -0
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/types.d.ts +27 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/splitIntoParts.d.ts +4 -0
- package/dist/types/utils/splitIntoParts.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/KeyValueStorage.ts +187 -33
- package/src/constants.ts +8 -0
- package/src/types.ts +33 -2
- package/src/utils/index.ts +4 -0
- package/src/utils/splitIntoParts.ts +26 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.24.0](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/key-value-storage@0.23.6...@or-sdk/key-value-storage@0.24.0) (2022-06-24)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **key-value-storage:** Key-value storage update: additional methods for listing collection and keys, copying and clearing collections, listKeys now returns List ([9d69e73](https://gitlab.com/onereach/platform/or-sdk-next/commit/9d69e73ee617f7421982d5f49ec57a66486d1c05))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
6
15
|
### [0.23.6](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/key-value-storage@0.23.5...@or-sdk/key-value-storage@0.23.6) (2022-06-20)
|
|
7
16
|
|
|
8
17
|
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -35,10 +46,21 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
47
|
}
|
|
37
48
|
};
|
|
49
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
+
};
|
|
38
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
59
|
exports.KeyValueStorage = void 0;
|
|
60
|
+
var base_1 = require("@or-sdk/base");
|
|
40
61
|
var sdk_api_1 = require("@or-sdk/sdk-api");
|
|
41
62
|
var constants_1 = require("./constants");
|
|
63
|
+
var utils_1 = require("./utils");
|
|
42
64
|
var KeyValueStorage = (function () {
|
|
43
65
|
function KeyValueStorage(params) {
|
|
44
66
|
var token = params.token, discoveryUrl = params.discoveryUrl, accountId = params.accountId, sdkUrl = params.sdkUrl;
|
|
@@ -52,43 +74,123 @@ var KeyValueStorage = (function () {
|
|
|
52
74
|
KeyValueStorage.prototype.composeRoute = function (route) {
|
|
53
75
|
return this.sdkApi.isCrossAccount ? "accounts/".concat(this.sdkApi.currentAccountId, "/").concat(route) : route;
|
|
54
76
|
};
|
|
55
|
-
KeyValueStorage.prototype.
|
|
77
|
+
KeyValueStorage.prototype.scrollCollections = function (_a, prefix) {
|
|
78
|
+
var numberOfItems = _a.numberOfItems, nextId = _a.nextId;
|
|
79
|
+
if (prefix === void 0) { prefix = ''; }
|
|
80
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
+
var params, _b, tables, isTruncated, newNext;
|
|
82
|
+
return __generator(this, function (_c) {
|
|
83
|
+
switch (_c.label) {
|
|
84
|
+
case 0:
|
|
85
|
+
params = {
|
|
86
|
+
prefix: prefix ? prefix : undefined,
|
|
87
|
+
next: nextId ? nextId : undefined,
|
|
88
|
+
maxKeys: numberOfItems ? numberOfItems : undefined,
|
|
89
|
+
};
|
|
90
|
+
return [4, this.sdkApi.makeRequest({
|
|
91
|
+
method: 'GET',
|
|
92
|
+
route: this.composeRoute("".concat(constants_1.STORAGE_ROUTE)),
|
|
93
|
+
params: params,
|
|
94
|
+
})];
|
|
95
|
+
case 1:
|
|
96
|
+
_b = _c.sent(), tables = _b.tables, isTruncated = _b.isTruncated, newNext = _b.next;
|
|
97
|
+
return [2, __assign(__assign({}, (0, base_1.makeList)(tables)), { isTruncated: isTruncated, nextId: newNext })];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
KeyValueStorage.prototype.listCollections = function (prefix) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
+
var itemsTotal, prevNext, _a, items, nextId;
|
|
105
|
+
return __generator(this, function (_b) {
|
|
106
|
+
switch (_b.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
itemsTotal = [];
|
|
109
|
+
_b.label = 1;
|
|
110
|
+
case 1: return [4, this.scrollCollections({
|
|
111
|
+
nextId: prevNext,
|
|
112
|
+
}, prefix)];
|
|
113
|
+
case 2:
|
|
114
|
+
_a = _b.sent(), items = _a.items, nextId = _a.nextId;
|
|
115
|
+
prevNext = nextId;
|
|
116
|
+
itemsTotal = __spreadArray(__spreadArray([], itemsTotal, true), items, true);
|
|
117
|
+
_b.label = 3;
|
|
118
|
+
case 3:
|
|
119
|
+
if (prevNext) return [3, 1];
|
|
120
|
+
_b.label = 4;
|
|
121
|
+
case 4: return [2, (0, base_1.makeList)(itemsTotal)];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
KeyValueStorage.prototype.scrollKeys = function (_a, collectionName, prefix, withValues) {
|
|
127
|
+
var numberOfItems = _a.numberOfItems, nextId = _a.nextId;
|
|
128
|
+
if (prefix === void 0) { prefix = ''; }
|
|
56
129
|
if (withValues === void 0) { withValues = false; }
|
|
57
130
|
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
-
var records;
|
|
59
|
-
return __generator(this, function (
|
|
60
|
-
switch (
|
|
61
|
-
case 0:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
131
|
+
var params, _b, records, isTruncated, newNext;
|
|
132
|
+
return __generator(this, function (_c) {
|
|
133
|
+
switch (_c.label) {
|
|
134
|
+
case 0:
|
|
135
|
+
params = {
|
|
136
|
+
prefix: prefix ? prefix : undefined,
|
|
137
|
+
next: nextId ? nextId : undefined,
|
|
138
|
+
maxKeys: numberOfItems ? numberOfItems : undefined,
|
|
139
|
+
withValues: withValues,
|
|
140
|
+
};
|
|
141
|
+
return [4, this.sdkApi.makeRequest({
|
|
142
|
+
method: 'GET',
|
|
143
|
+
route: this.composeRoute("".concat(constants_1.STORAGE_ROUTE, "/").concat(collectionName)),
|
|
144
|
+
params: params,
|
|
145
|
+
})];
|
|
69
146
|
case 1:
|
|
70
|
-
|
|
71
|
-
return [2, records];
|
|
147
|
+
_b = (_c.sent()).value, records = _b.records, isTruncated = _b.isTruncated, newNext = _b.next;
|
|
148
|
+
return [2, __assign(__assign({}, (0, base_1.makeList)(records)), { nextId: newNext, isTruncated: isTruncated })];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
KeyValueStorage.prototype.listKeys = function (collectionName, prefix, withValues) {
|
|
154
|
+
if (withValues === void 0) { withValues = false; }
|
|
155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
+
var itemsTotal, prevNext, _a, items, nextId;
|
|
157
|
+
return __generator(this, function (_b) {
|
|
158
|
+
switch (_b.label) {
|
|
159
|
+
case 0:
|
|
160
|
+
itemsTotal = [];
|
|
161
|
+
_b.label = 1;
|
|
162
|
+
case 1: return [4, this.scrollKeys({
|
|
163
|
+
nextId: prevNext,
|
|
164
|
+
}, collectionName, prefix, withValues)];
|
|
165
|
+
case 2:
|
|
166
|
+
_a = _b.sent(), items = _a.items, nextId = _a.nextId;
|
|
167
|
+
prevNext = nextId;
|
|
168
|
+
itemsTotal = __spreadArray(__spreadArray([], itemsTotal, true), items, true);
|
|
169
|
+
_b.label = 3;
|
|
170
|
+
case 3:
|
|
171
|
+
if (prevNext) return [3, 1];
|
|
172
|
+
_b.label = 4;
|
|
173
|
+
case 4: return [2, (0, base_1.makeList)(itemsTotal)];
|
|
72
174
|
}
|
|
73
175
|
});
|
|
74
176
|
});
|
|
75
177
|
};
|
|
76
|
-
KeyValueStorage.prototype.getValueByKey = function (
|
|
178
|
+
KeyValueStorage.prototype.getValueByKey = function (collectionName, key) {
|
|
77
179
|
return __awaiter(this, void 0, void 0, function () {
|
|
78
180
|
return __generator(this, function (_a) {
|
|
79
181
|
return [2, this.sdkApi.makeRequest({
|
|
80
182
|
method: 'GET',
|
|
81
|
-
route: this.composeRoute("".concat(constants_1.STORAGE_ROUTE, "/").concat(
|
|
183
|
+
route: this.composeRoute("".concat(constants_1.STORAGE_ROUTE, "/").concat(collectionName, "/").concat(key)),
|
|
82
184
|
})];
|
|
83
185
|
});
|
|
84
186
|
});
|
|
85
187
|
};
|
|
86
|
-
KeyValueStorage.prototype.setValueByKey = function (
|
|
188
|
+
KeyValueStorage.prototype.setValueByKey = function (collectionName, key, value, expire) {
|
|
87
189
|
return __awaiter(this, void 0, void 0, function () {
|
|
88
190
|
return __generator(this, function (_a) {
|
|
89
191
|
return [2, this.sdkApi.makeRequest({
|
|
90
192
|
method: 'POST',
|
|
91
|
-
route: this.composeRoute("".concat(constants_1.STORAGE_ROUTE, "/").concat(
|
|
193
|
+
route: this.composeRoute("".concat(constants_1.STORAGE_ROUTE, "/").concat(collectionName, "/").concat(key)),
|
|
92
194
|
data: {
|
|
93
195
|
expire: expire,
|
|
94
196
|
value: value,
|
|
@@ -97,16 +199,83 @@ var KeyValueStorage = (function () {
|
|
|
97
199
|
});
|
|
98
200
|
});
|
|
99
201
|
};
|
|
100
|
-
KeyValueStorage.prototype.deleteKey = function (
|
|
202
|
+
KeyValueStorage.prototype.deleteKey = function (collectionName, key) {
|
|
101
203
|
return __awaiter(this, void 0, void 0, function () {
|
|
102
204
|
return __generator(this, function (_a) {
|
|
103
205
|
return [2, this.sdkApi.makeRequest({
|
|
104
206
|
method: 'DELETE',
|
|
105
|
-
route: this.composeRoute("".concat(constants_1.STORAGE_ROUTE, "/").concat(
|
|
207
|
+
route: this.composeRoute("".concat(constants_1.STORAGE_ROUTE, "/").concat(collectionName, "/").concat(key)),
|
|
106
208
|
})];
|
|
107
209
|
});
|
|
108
210
|
});
|
|
109
211
|
};
|
|
212
|
+
KeyValueStorage.prototype.processMultipleRecords = function (records, action, collectionName) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
214
|
+
return __generator(this, function (_a) {
|
|
215
|
+
return [2, this.sdkApi.makeRequest({
|
|
216
|
+
method: 'POST',
|
|
217
|
+
route: this.composeRoute("".concat(constants_1.STORAGE_MULTIPLE_ROUTE)),
|
|
218
|
+
data: {
|
|
219
|
+
keys: records,
|
|
220
|
+
method: action,
|
|
221
|
+
table: collectionName,
|
|
222
|
+
},
|
|
223
|
+
})];
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
KeyValueStorage.prototype.copyCollection = function (sourceCollectionName, targetCollectionName) {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
229
|
+
var items, recordGroups, _i, recordGroups_1, records;
|
|
230
|
+
return __generator(this, function (_a) {
|
|
231
|
+
switch (_a.label) {
|
|
232
|
+
case 0: return [4, this.listKeys(sourceCollectionName, '', true)];
|
|
233
|
+
case 1:
|
|
234
|
+
items = (_a.sent()).items;
|
|
235
|
+
recordGroups = (0, utils_1.splitIntoParts)(items);
|
|
236
|
+
_i = 0, recordGroups_1 = recordGroups;
|
|
237
|
+
_a.label = 2;
|
|
238
|
+
case 2:
|
|
239
|
+
if (!(_i < recordGroups_1.length)) return [3, 5];
|
|
240
|
+
records = recordGroups_1[_i];
|
|
241
|
+
return [4, this.processMultipleRecords(records, constants_1.Action.SET, targetCollectionName)];
|
|
242
|
+
case 3:
|
|
243
|
+
_a.sent();
|
|
244
|
+
_a.label = 4;
|
|
245
|
+
case 4:
|
|
246
|
+
_i++;
|
|
247
|
+
return [3, 2];
|
|
248
|
+
case 5: return [2];
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
KeyValueStorage.prototype.clearCollection = function (collectionName) {
|
|
254
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
255
|
+
var items, recordGroups, _i, recordGroups_2, records;
|
|
256
|
+
return __generator(this, function (_a) {
|
|
257
|
+
switch (_a.label) {
|
|
258
|
+
case 0: return [4, this.listKeys(collectionName)];
|
|
259
|
+
case 1:
|
|
260
|
+
items = (_a.sent()).items;
|
|
261
|
+
recordGroups = (0, utils_1.splitIntoParts)(items);
|
|
262
|
+
_i = 0, recordGroups_2 = recordGroups;
|
|
263
|
+
_a.label = 2;
|
|
264
|
+
case 2:
|
|
265
|
+
if (!(_i < recordGroups_2.length)) return [3, 5];
|
|
266
|
+
records = recordGroups_2[_i];
|
|
267
|
+
return [4, this.processMultipleRecords(records, constants_1.Action.DELETE, collectionName)];
|
|
268
|
+
case 3:
|
|
269
|
+
_a.sent();
|
|
270
|
+
_a.label = 4;
|
|
271
|
+
case 4:
|
|
272
|
+
_i++;
|
|
273
|
+
return [3, 2];
|
|
274
|
+
case 5: return [2];
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
};
|
|
110
279
|
return KeyValueStorage;
|
|
111
280
|
}());
|
|
112
281
|
exports.KeyValueStorage = KeyValueStorage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyValueStorage.js","sourceRoot":"","sources":["../../src/KeyValueStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"KeyValueStorage.js","sourceRoot":"","sources":["../../src/KeyValueStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAA8C;A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MAAM,EAAE,cAAc,CAAC,EAAA;;wBAAzE,SAAyE,CAAC;;;wBADtD,IAAY,CAAA;;;;;;KAGnC;IACH,sBAAC;AAAD,CAAC,AA5QD,IA4QC;AA5QY,0CAAe"}
|
package/dist/cjs/constants.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STORAGE_ROUTE = void 0;
|
|
3
|
+
exports.Action = exports.STORAGE_MULTIPLE_ROUTE = exports.STORAGE_ROUTE = void 0;
|
|
4
4
|
exports.STORAGE_ROUTE = '/storage';
|
|
5
|
+
exports.STORAGE_MULTIPLE_ROUTE = '/storage-multiple';
|
|
6
|
+
var Action;
|
|
7
|
+
(function (Action) {
|
|
8
|
+
Action["GET"] = "get";
|
|
9
|
+
Action["SET"] = "set";
|
|
10
|
+
Action["DELETE"] = "delete";
|
|
11
|
+
Action["EXISTS"] = "exists";
|
|
12
|
+
})(Action = exports.Action || (exports.Action = {}));
|
|
5
13
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,UAAU,CAAC;AAC3B,QAAA,sBAAsB,GAAG,mBAAmB,CAAC;AAE1D,IAAY,MAKX;AALD,WAAY,MAAM;IAChB,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,2BAAiB,CAAA;IACjB,2BAAiB,CAAA;AACnB,CAAC,EALW,MAAM,GAAN,cAAM,KAAN,cAAM,QAKjB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.splitIntoParts = void 0;
|
|
7
|
+
var splitIntoParts_1 = require("./splitIntoParts");
|
|
8
|
+
Object.defineProperty(exports, "splitIntoParts", { enumerable: true, get: function () { return __importDefault(splitIntoParts_1).default; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAGA,mDAA6D;AAApD,iIAAA,OAAO,OAAkB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function splitIntoParts(records) {
|
|
4
|
+
var partLength = 10;
|
|
5
|
+
return records
|
|
6
|
+
.map(function (record) {
|
|
7
|
+
return {
|
|
8
|
+
key: record.key,
|
|
9
|
+
value: record.value,
|
|
10
|
+
};
|
|
11
|
+
})
|
|
12
|
+
.reduce(function (resultArray, item, index) {
|
|
13
|
+
var partIndex = Math.floor(index / partLength);
|
|
14
|
+
if (!resultArray[partIndex]) {
|
|
15
|
+
resultArray[partIndex] = [];
|
|
16
|
+
}
|
|
17
|
+
resultArray[partIndex].push(item);
|
|
18
|
+
return resultArray;
|
|
19
|
+
}, []);
|
|
20
|
+
}
|
|
21
|
+
exports.default = splitIntoParts;
|
|
22
|
+
//# sourceMappingURL=splitIntoParts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitIntoParts.js","sourceRoot":"","sources":["../../../src/utils/splitIntoParts.ts"],"names":[],"mappings":";;AAEA,SAAS,cAAc,CAAC,OAAgD;IACtE,IAAM,UAAU,GAAG,EAAE,CAAC;IAEtB,OAAO,OAAO;SACX,GAAG,CAAC,UAAA,MAAM;QACT,OAAO;YACL,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,UAAC,WAAW,EAAE,IAAI,EAAE,KAAK;QAC/B,IAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC;QAEjD,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE;YAC3B,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;SAC7B;QAED,WAAW,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAElC,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,EAA+B,CAAC,CAAC;AACxC,CAAC;AAED,kBAAe,cAAc,CAAC"}
|
|
@@ -7,8 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { makeList } from '@or-sdk/base';
|
|
10
11
|
import { SdkApi } from '@or-sdk/sdk-api';
|
|
11
|
-
import { STORAGE_ROUTE } from './constants';
|
|
12
|
+
import { Action, STORAGE_MULTIPLE_ROUTE, STORAGE_ROUTE } from './constants';
|
|
13
|
+
import { splitIntoParts } from './utils';
|
|
12
14
|
export class KeyValueStorage {
|
|
13
15
|
constructor(params) {
|
|
14
16
|
const { token, discoveryUrl, accountId, sdkUrl } = params;
|
|
@@ -22,32 +24,78 @@ export class KeyValueStorage {
|
|
|
22
24
|
composeRoute(route) {
|
|
23
25
|
return this.sdkApi.isCrossAccount ? `accounts/${this.sdkApi.currentAccountId}/${route}` : route;
|
|
24
26
|
}
|
|
25
|
-
|
|
27
|
+
scrollCollections({ numberOfItems, nextId }, prefix = '') {
|
|
26
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const
|
|
29
|
+
const params = {
|
|
30
|
+
prefix: prefix ? prefix : undefined,
|
|
31
|
+
next: nextId ? nextId : undefined,
|
|
32
|
+
maxKeys: numberOfItems ? numberOfItems : undefined,
|
|
33
|
+
};
|
|
34
|
+
const { tables, isTruncated, next: newNext } = yield this.sdkApi.makeRequest({
|
|
28
35
|
method: 'GET',
|
|
29
|
-
route: this.composeRoute(`${STORAGE_ROUTE}
|
|
30
|
-
params
|
|
31
|
-
prefix: prefix ? prefix : undefined,
|
|
32
|
-
withValues,
|
|
33
|
-
},
|
|
36
|
+
route: this.composeRoute(`${STORAGE_ROUTE}`),
|
|
37
|
+
params,
|
|
34
38
|
});
|
|
35
|
-
return
|
|
39
|
+
return Object.assign(Object.assign({}, makeList(tables)), { isTruncated, nextId: newNext });
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
listCollections(prefix) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
let itemsTotal = [];
|
|
45
|
+
let prevNext;
|
|
46
|
+
do {
|
|
47
|
+
const { items, nextId } = yield this.scrollCollections({
|
|
48
|
+
nextId: prevNext,
|
|
49
|
+
}, prefix);
|
|
50
|
+
prevNext = nextId;
|
|
51
|
+
itemsTotal = [...itemsTotal, ...items];
|
|
52
|
+
} while (prevNext);
|
|
53
|
+
return makeList(itemsTotal);
|
|
36
54
|
});
|
|
37
55
|
}
|
|
38
|
-
|
|
56
|
+
scrollKeys({ numberOfItems, nextId }, collectionName, prefix = '', withValues = false) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const params = {
|
|
59
|
+
prefix: prefix ? prefix : undefined,
|
|
60
|
+
next: nextId ? nextId : undefined,
|
|
61
|
+
maxKeys: numberOfItems ? numberOfItems : undefined,
|
|
62
|
+
withValues,
|
|
63
|
+
};
|
|
64
|
+
const { value: { records, isTruncated, next: newNext } } = yield this.sdkApi.makeRequest({
|
|
65
|
+
method: 'GET',
|
|
66
|
+
route: this.composeRoute(`${STORAGE_ROUTE}/${collectionName}`),
|
|
67
|
+
params,
|
|
68
|
+
});
|
|
69
|
+
return Object.assign(Object.assign({}, makeList(records)), { nextId: newNext, isTruncated });
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
listKeys(collectionName, prefix, withValues = false) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
let itemsTotal = [];
|
|
75
|
+
let prevNext;
|
|
76
|
+
do {
|
|
77
|
+
const { items, nextId } = yield this.scrollKeys({
|
|
78
|
+
nextId: prevNext,
|
|
79
|
+
}, collectionName, prefix, withValues);
|
|
80
|
+
prevNext = nextId;
|
|
81
|
+
itemsTotal = [...itemsTotal, ...items];
|
|
82
|
+
} while (prevNext);
|
|
83
|
+
return makeList(itemsTotal);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
getValueByKey(collectionName, key) {
|
|
39
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
88
|
return this.sdkApi.makeRequest({
|
|
41
89
|
method: 'GET',
|
|
42
|
-
route: this.composeRoute(`${STORAGE_ROUTE}/${
|
|
90
|
+
route: this.composeRoute(`${STORAGE_ROUTE}/${collectionName}/${key}`),
|
|
43
91
|
});
|
|
44
92
|
});
|
|
45
93
|
}
|
|
46
|
-
setValueByKey(
|
|
94
|
+
setValueByKey(collectionName, key, value, expire) {
|
|
47
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
96
|
return this.sdkApi.makeRequest({
|
|
49
97
|
method: 'POST',
|
|
50
|
-
route: this.composeRoute(`${STORAGE_ROUTE}/${
|
|
98
|
+
route: this.composeRoute(`${STORAGE_ROUTE}/${collectionName}/${key}`),
|
|
51
99
|
data: {
|
|
52
100
|
expire,
|
|
53
101
|
value,
|
|
@@ -55,13 +103,44 @@ export class KeyValueStorage {
|
|
|
55
103
|
});
|
|
56
104
|
});
|
|
57
105
|
}
|
|
58
|
-
deleteKey(
|
|
106
|
+
deleteKey(collectionName, key) {
|
|
59
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
108
|
return this.sdkApi.makeRequest({
|
|
61
109
|
method: 'DELETE',
|
|
62
|
-
route: this.composeRoute(`${STORAGE_ROUTE}/${
|
|
110
|
+
route: this.composeRoute(`${STORAGE_ROUTE}/${collectionName}/${key}`),
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
processMultipleRecords(records, action, collectionName) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
return this.sdkApi.makeRequest({
|
|
117
|
+
method: 'POST',
|
|
118
|
+
route: this.composeRoute(`${STORAGE_MULTIPLE_ROUTE}`),
|
|
119
|
+
data: {
|
|
120
|
+
keys: records,
|
|
121
|
+
method: action,
|
|
122
|
+
table: collectionName,
|
|
123
|
+
},
|
|
63
124
|
});
|
|
64
125
|
});
|
|
65
126
|
}
|
|
127
|
+
copyCollection(sourceCollectionName, targetCollectionName) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const { items } = yield this.listKeys(sourceCollectionName, '', true);
|
|
130
|
+
const recordGroups = splitIntoParts(items);
|
|
131
|
+
for (const records of recordGroups) {
|
|
132
|
+
yield this.processMultipleRecords(records, Action.SET, targetCollectionName);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
clearCollection(collectionName) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const { items } = yield this.listKeys(collectionName);
|
|
139
|
+
const recordGroups = splitIntoParts(items);
|
|
140
|
+
for (const records of recordGroups) {
|
|
141
|
+
yield this.processMultipleRecords(records, Action.DELETE, collectionName);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
66
145
|
}
|
|
67
146
|
//# sourceMappingURL=KeyValueStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyValueStorage.js","sourceRoot":"","sources":["../../src/KeyValueStorage.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,M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3E;QACH,CAAC;KAAA;CACF"}
|
package/dist/esm/constants.js
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
export const STORAGE_ROUTE = '/storage';
|
|
2
|
+
export const STORAGE_MULTIPLE_ROUTE = '/storage-multiple';
|
|
3
|
+
export var Action;
|
|
4
|
+
(function (Action) {
|
|
5
|
+
Action["GET"] = "get";
|
|
6
|
+
Action["SET"] = "set";
|
|
7
|
+
Action["DELETE"] = "delete";
|
|
8
|
+
Action["EXISTS"] = "exists";
|
|
9
|
+
})(Action || (Action = {}));
|
|
2
10
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;AACxC,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAE1D,MAAM,CAAN,IAAY,MAKX;AALD,WAAY,MAAM;IAChB,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,2BAAiB,CAAA;IACjB,2BAAiB,CAAA;AACnB,CAAC,EALW,MAAM,KAAN,MAAM,QAKjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function splitIntoParts(records) {
|
|
2
|
+
const partLength = 10;
|
|
3
|
+
return records
|
|
4
|
+
.map(record => {
|
|
5
|
+
return {
|
|
6
|
+
key: record.key,
|
|
7
|
+
value: record.value,
|
|
8
|
+
};
|
|
9
|
+
})
|
|
10
|
+
.reduce((resultArray, item, index) => {
|
|
11
|
+
const partIndex = Math.floor(index / partLength);
|
|
12
|
+
if (!resultArray[partIndex]) {
|
|
13
|
+
resultArray[partIndex] = [];
|
|
14
|
+
}
|
|
15
|
+
resultArray[partIndex].push(item);
|
|
16
|
+
return resultArray;
|
|
17
|
+
}, []);
|
|
18
|
+
}
|
|
19
|
+
export default splitIntoParts;
|
|
20
|
+
//# sourceMappingURL=splitIntoParts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitIntoParts.js","sourceRoot":"","sources":["../../../src/utils/splitIntoParts.ts"],"names":[],"mappings":"AAEA,SAAS,cAAc,CAAC,OAAgD;IACtE,MAAM,UAAU,GAAG,EAAE,CAAC;IAEtB,OAAO,OAAO;SACX,GAAG,CAAC,MAAM,CAAC,EAAE;QACZ,OAAO;YACL,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QACnC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC;QAEjD,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE;YAC3B,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;SAC7B;QAED,WAAW,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAElC,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,EAA+B,CAAC,CAAC;AACxC,CAAC;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { List } from '@or-sdk/base';
|
|
2
|
+
import { KeyValueStorageConfig, KeyValueStorageRecord, KeyValueStorageRecordWithLastModified, DeletedKeyValueStorageRecord, MultipleRecordsResult, ScrollOptions, ScrollResult } from './types';
|
|
3
|
+
import { Action } from './constants';
|
|
2
4
|
export declare class KeyValueStorage {
|
|
3
5
|
private readonly sdkApi;
|
|
4
6
|
constructor(params: KeyValueStorageConfig);
|
|
5
7
|
composeRoute(route: string): string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
scrollCollections({ numberOfItems, nextId }: ScrollOptions, prefix?: string): Promise<ScrollResult<string>>;
|
|
9
|
+
listCollections(prefix?: string): Promise<List<string>>;
|
|
10
|
+
scrollKeys({ numberOfItems, nextId }: ScrollOptions, collectionName: string, prefix?: string, withValues?: boolean): Promise<ScrollResult<KeyValueStorageRecordWithLastModified>>;
|
|
11
|
+
listKeys(collectionName: string, prefix?: string, withValues?: boolean): Promise<List<KeyValueStorageRecordWithLastModified>>;
|
|
12
|
+
getValueByKey(collectionName: string, key: string): Promise<KeyValueStorageRecord>;
|
|
13
|
+
setValueByKey(collectionName: string, key: string, value: Record<string, unknown> | string, expire?: number): Promise<KeyValueStorageRecord>;
|
|
14
|
+
deleteKey(collectionName: string, key: string): Promise<DeletedKeyValueStorageRecord>;
|
|
15
|
+
processMultipleRecords(records: KeyValueStorageRecord[], action: Action, collectionName: string): Promise<MultipleRecordsResult>;
|
|
16
|
+
copyCollection(sourceCollectionName: string, targetCollectionName: string): Promise<void>;
|
|
17
|
+
clearCollection(collectionName: string): Promise<void>;
|
|
10
18
|
}
|
|
11
19
|
//# sourceMappingURL=KeyValueStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyValueStorage.d.ts","sourceRoot":"","sources":["../../src/KeyValueStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"KeyValueStorage.d.ts","sourceRoot":"","sources":["../../src/KeyValueStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,MAAM,cAAc,CAAC;AAE9C,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,qCAAqC,EAC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E,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAsBhI,cAAc,CAAC,oBAAoB,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBzF,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CASpE"}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export declare const STORAGE_ROUTE = "/storage";
|
|
2
|
+
export declare const STORAGE_MULTIPLE_ROUTE = "/storage-multiple";
|
|
3
|
+
export declare enum Action {
|
|
4
|
+
GET = "get",
|
|
5
|
+
SET = "set",
|
|
6
|
+
DELETE = "delete",
|
|
7
|
+
EXISTS = "exists"
|
|
8
|
+
}
|
|
2
9
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,aAAa,CAAC;AACxC,eAAO,MAAM,sBAAsB,sBAAsB,CAAC;AAE1D,oBAAY,MAAM;IAChB,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Token } from '@or-sdk/base';
|
|
1
|
+
import { List, Token } from '@or-sdk/base';
|
|
2
2
|
export declare type KeyValueStorageConfig = {
|
|
3
3
|
token: Token;
|
|
4
4
|
discoveryUrl?: string;
|
|
@@ -12,5 +12,31 @@ export declare type KeyValueStorageRecord = {
|
|
|
12
12
|
export declare type KeyValueStorageRecordWithLastModified = KeyValueStorageRecord & {
|
|
13
13
|
lastModified: string;
|
|
14
14
|
};
|
|
15
|
+
export declare type ListCollectionsResponse = {
|
|
16
|
+
tables: string[];
|
|
17
|
+
isTruncated: boolean;
|
|
18
|
+
count: number;
|
|
19
|
+
next?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare type ListKeysResponse = {
|
|
22
|
+
value: {
|
|
23
|
+
records: KeyValueStorageRecordWithLastModified[];
|
|
24
|
+
isTruncated: boolean;
|
|
25
|
+
count: number;
|
|
26
|
+
next?: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
15
29
|
export declare type DeletedKeyValueStorageRecord = Required<Pick<KeyValueStorageRecord, 'value'>>;
|
|
30
|
+
export declare type ScrollOptions = {
|
|
31
|
+
numberOfItems?: number;
|
|
32
|
+
nextId?: string;
|
|
33
|
+
};
|
|
34
|
+
export declare type ScrollResult<T> = List<T> & {
|
|
35
|
+
isTruncated?: boolean;
|
|
36
|
+
nextId?: string;
|
|
37
|
+
};
|
|
38
|
+
export declare type KeyValueStorageRecordExists = KeyValueStorageRecord & {
|
|
39
|
+
exists: boolean;
|
|
40
|
+
};
|
|
41
|
+
export declare type MultipleRecordsResult = KeyValueStorageRecord[] | KeyValueStorageRecordExists[] | boolean;
|
|
16
42
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE3C,oBAAY,qBAAqB,GAAG;IAIlC,KAAK,EAAE,KAAK,CAAC;IAKb,YAAY,CAAC,EAAE,MAAM,CAAC;IAKtB,SAAS,CAAC,EAAE,MAAM,CAAC;IAKnB,MAAM,CAAC,EAAE,MAAM,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sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { KeyValueStorageRecord, KeyValueStorageRecordWithLastModified } from '../types';
|
|
2
|
+
declare function splitIntoParts(records: KeyValueStorageRecordWithLastModified[]): KeyValueStorageRecord[][];
|
|
3
|
+
export default splitIntoParts;
|
|
4
|
+
//# sourceMappingURL=splitIntoParts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitIntoParts.d.ts","sourceRoot":"","sources":["../../../src/utils/splitIntoParts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,qCAAqC,EAAE,MAAM,UAAU,CAAC;AAExF,iBAAS,cAAc,CAAC,OAAO,EAAE,qCAAqC,EAAE,GAAG,qBAAqB,EAAE,EAAE,CAqBnG;AAED,eAAe,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@or-sdk/key-value-storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "af2ae5b4961a4f7b359108fbd655c580d1bf7129"
|
|
31
31
|
}
|
package/src/KeyValueStorage.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { List, makeList } from '@or-sdk/base';
|
|
1
2
|
import { SdkApi } from '@or-sdk/sdk-api';
|
|
2
3
|
import {
|
|
3
4
|
KeyValueStorageConfig,
|
|
4
5
|
KeyValueStorageRecord,
|
|
5
6
|
KeyValueStorageRecordWithLastModified,
|
|
6
|
-
DeletedKeyValueStorageRecord,
|
|
7
|
+
DeletedKeyValueStorageRecord, ListKeysResponse, ListCollectionsResponse, MultipleRecordsResult,
|
|
8
|
+
ScrollOptions, ScrollResult,
|
|
7
9
|
} from './types';
|
|
8
|
-
import { STORAGE_ROUTE } from './constants';
|
|
10
|
+
import { Action, STORAGE_MULTIPLE_ROUTE, STORAGE_ROUTE } from './constants';
|
|
11
|
+
import { splitIntoParts } from './utils';
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* OneReach KeyValueStorage service client
|
|
@@ -39,73 +42,165 @@ export class KeyValueStorage {
|
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
/**
|
|
42
|
-
* List
|
|
45
|
+
* List collections with pagination
|
|
43
46
|
*
|
|
44
47
|
* ```typescript
|
|
45
|
-
* const
|
|
48
|
+
* const prefix = '__some_prefix';
|
|
49
|
+
* const numberOfItems = 30;
|
|
50
|
+
* const nextId = 'next-token'; // next page token from previous listCollectionsPaginated call
|
|
51
|
+
* const list = await keyValueStorage.scrollCollections({numberOfItems, nextId}, prefix);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
public async scrollCollections({ numberOfItems, nextId }: ScrollOptions, prefix = ''): Promise<ScrollResult<string>> {
|
|
55
|
+
const params = {
|
|
56
|
+
prefix: prefix ? prefix : undefined,
|
|
57
|
+
next: nextId ? nextId : undefined,
|
|
58
|
+
maxKeys: numberOfItems ? numberOfItems : undefined,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const { tables, isTruncated, next: newNext } = await this.sdkApi.makeRequest<ListCollectionsResponse>({
|
|
62
|
+
method: 'GET',
|
|
63
|
+
route: this.composeRoute(`${STORAGE_ROUTE}`),
|
|
64
|
+
params,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
...makeList<string>(tables),
|
|
69
|
+
isTruncated,
|
|
70
|
+
nextId: newNext,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* List collections
|
|
76
|
+
*
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const prefix = '__some_prefix';
|
|
79
|
+
* const list = await keyValueStorage.listCollections(prefix, withValues);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
public async listCollections(prefix?: string): Promise<List<string>> {
|
|
83
|
+
let itemsTotal: string[] = [];
|
|
84
|
+
let prevNext;
|
|
85
|
+
|
|
86
|
+
do {
|
|
87
|
+
const { items, nextId }: ScrollResult<string> = await this.scrollCollections({
|
|
88
|
+
nextId: prevNext,
|
|
89
|
+
}, prefix);
|
|
90
|
+
|
|
91
|
+
prevNext = nextId;
|
|
92
|
+
itemsTotal = [...itemsTotal, ...items];
|
|
93
|
+
} while (prevNext);
|
|
94
|
+
|
|
95
|
+
return makeList<string>(itemsTotal);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* List keys in a collection starting with given substring with pagination
|
|
100
|
+
*
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const collectionName = 'my-collection';
|
|
46
103
|
* const prefix = '__some_prefix';
|
|
47
104
|
* const withValues = false; // set to true to receive record values alongside key names
|
|
48
|
-
* const
|
|
105
|
+
* const numberOfItems = 30;
|
|
106
|
+
* const nextId = 'next-token'; // next page token from previous listKeysPaginated call
|
|
107
|
+
* const list = await keyValueStorage.scrollKeys({ numberOfItems, nextId }, collectionName, prefix, withValues);
|
|
49
108
|
* ```
|
|
50
109
|
*/
|
|
51
|
-
public async
|
|
52
|
-
|
|
53
|
-
|
|
110
|
+
public async scrollKeys(
|
|
111
|
+
{ numberOfItems, nextId }: ScrollOptions,
|
|
112
|
+
collectionName: string,
|
|
113
|
+
prefix = '',
|
|
54
114
|
withValues = false
|
|
55
|
-
): Promise<KeyValueStorageRecordWithLastModified
|
|
56
|
-
const {
|
|
57
|
-
|
|
58
|
-
|
|
115
|
+
): Promise<ScrollResult<KeyValueStorageRecordWithLastModified>> {
|
|
116
|
+
const params = {
|
|
117
|
+
prefix: prefix ? prefix : undefined,
|
|
118
|
+
next: nextId ? nextId : undefined,
|
|
119
|
+
maxKeys: numberOfItems ? numberOfItems : undefined,
|
|
120
|
+
withValues,
|
|
121
|
+
};
|
|
122
|
+
const { value: { records, isTruncated, next: newNext } } = await this.sdkApi.makeRequest<ListKeysResponse>({
|
|
59
123
|
method: 'GET',
|
|
60
|
-
route: this.composeRoute(`${STORAGE_ROUTE}/${
|
|
61
|
-
params
|
|
62
|
-
prefix: prefix ? prefix : undefined,
|
|
63
|
-
withValues,
|
|
64
|
-
},
|
|
124
|
+
route: this.composeRoute(`${STORAGE_ROUTE}/${collectionName}`),
|
|
125
|
+
params,
|
|
65
126
|
});
|
|
66
127
|
|
|
67
|
-
return
|
|
128
|
+
return {
|
|
129
|
+
...makeList<KeyValueStorageRecordWithLastModified>(records),
|
|
130
|
+
nextId: newNext,
|
|
131
|
+
isTruncated,
|
|
132
|
+
};
|
|
68
133
|
}
|
|
69
134
|
|
|
70
135
|
/**
|
|
71
|
-
*
|
|
136
|
+
* List keys in a collection starting with given substring
|
|
72
137
|
*
|
|
73
138
|
* ```typescript
|
|
74
|
-
* const
|
|
139
|
+
* const collectionName = 'my-collection';
|
|
140
|
+
* const prefix = '__some_prefix';
|
|
141
|
+
* const withValues = false; // set to true to receive record values alongside key names
|
|
142
|
+
* const list = await keyValueStorage.listKeys(collectionName, prefix, withValues);
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
public async listKeys(
|
|
146
|
+
collectionName: string,
|
|
147
|
+
prefix?: string,
|
|
148
|
+
withValues = false,
|
|
149
|
+
): Promise<List<KeyValueStorageRecordWithLastModified>> {
|
|
150
|
+
let itemsTotal: KeyValueStorageRecordWithLastModified[] = [];
|
|
151
|
+
let prevNext;
|
|
152
|
+
|
|
153
|
+
do {
|
|
154
|
+
const { items, nextId }: ScrollResult<KeyValueStorageRecordWithLastModified> = await this.scrollKeys({
|
|
155
|
+
nextId: prevNext,
|
|
156
|
+
}, collectionName, prefix, withValues);
|
|
157
|
+
|
|
158
|
+
prevNext = nextId;
|
|
159
|
+
itemsTotal = [...itemsTotal, ...items];
|
|
160
|
+
} while (prevNext);
|
|
161
|
+
|
|
162
|
+
return makeList<KeyValueStorageRecordWithLastModified>(itemsTotal);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Get value from collection by key
|
|
167
|
+
*
|
|
168
|
+
* ```typescript
|
|
169
|
+
* const collectionName = 'my-collection';
|
|
75
170
|
* const key = 'my-key';
|
|
76
|
-
* const record = await keyValueStorage.getValueByKey(
|
|
171
|
+
* const record = await keyValueStorage.getValueByKey(collectionName, key);
|
|
77
172
|
* ```
|
|
78
173
|
*/
|
|
79
174
|
public async getValueByKey(
|
|
80
|
-
|
|
175
|
+
collectionName: string,
|
|
81
176
|
key: string
|
|
82
177
|
): Promise<KeyValueStorageRecord> {
|
|
83
178
|
return this.sdkApi.makeRequest({
|
|
84
179
|
method: 'GET',
|
|
85
|
-
route: this.composeRoute(`${STORAGE_ROUTE}/${
|
|
180
|
+
route: this.composeRoute(`${STORAGE_ROUTE}/${collectionName}/${key}`),
|
|
86
181
|
});
|
|
87
182
|
}
|
|
88
183
|
|
|
89
184
|
/**
|
|
90
|
-
* Set value to
|
|
185
|
+
* Set value to collection by key
|
|
91
186
|
*
|
|
92
187
|
* ```typescript
|
|
93
|
-
* const
|
|
188
|
+
* const collectionName = 'my-collection';
|
|
94
189
|
* const key = 'my-key';
|
|
95
190
|
* const value = { 'prop': 'value' };
|
|
96
191
|
* const expire = 300000; // time before record deletion in milliseconds
|
|
97
|
-
* await keyValueStorage.setValueByKey(
|
|
192
|
+
* await keyValueStorage.setValueByKey(collectionName, key, value, expire);
|
|
98
193
|
* ```
|
|
99
194
|
*/
|
|
100
195
|
public async setValueByKey(
|
|
101
|
-
|
|
196
|
+
collectionName: string,
|
|
102
197
|
key: string,
|
|
103
198
|
value: Record<string, unknown> | string,
|
|
104
199
|
expire?: number
|
|
105
200
|
): Promise<KeyValueStorageRecord> {
|
|
106
201
|
return this.sdkApi.makeRequest({
|
|
107
202
|
method: 'POST',
|
|
108
|
-
route: this.composeRoute(`${STORAGE_ROUTE}/${
|
|
203
|
+
route: this.composeRoute(`${STORAGE_ROUTE}/${collectionName}/${key}`),
|
|
109
204
|
data: {
|
|
110
205
|
expire,
|
|
111
206
|
value,
|
|
@@ -114,21 +209,80 @@ export class KeyValueStorage {
|
|
|
114
209
|
}
|
|
115
210
|
|
|
116
211
|
/**
|
|
117
|
-
* Delete a key from a
|
|
212
|
+
* Delete a key from a collection
|
|
118
213
|
*
|
|
119
214
|
* ```typescript
|
|
120
|
-
* const
|
|
215
|
+
* const collectionName = 'my-collection';
|
|
121
216
|
* const key = 'my-key';
|
|
122
|
-
* const record = await keyValueStorage.deleteKey(
|
|
217
|
+
* const record = await keyValueStorage.deleteKey(collectionName, key);
|
|
123
218
|
* ```
|
|
124
219
|
*/
|
|
125
220
|
public async deleteKey(
|
|
126
|
-
|
|
221
|
+
collectionName: string,
|
|
127
222
|
key: string
|
|
128
223
|
): Promise<DeletedKeyValueStorageRecord> {
|
|
129
224
|
return this.sdkApi.makeRequest({
|
|
130
225
|
method: 'DELETE',
|
|
131
|
-
route: this.composeRoute(`${STORAGE_ROUTE}/${
|
|
226
|
+
route: this.composeRoute(`${STORAGE_ROUTE}/${collectionName}/${key}`),
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Process multiple records
|
|
232
|
+
*
|
|
233
|
+
* ```typescript
|
|
234
|
+
* const collectionName = 'my-collection';
|
|
235
|
+
* const records = [{ key: 'new-key', value: 'new-value' }]; // array of records to process, max 10
|
|
236
|
+
* const action = 'set'; // [ get, set, delete, exists ]
|
|
237
|
+
* const result = await keyValueStorage.processMultipleRecords(records, action, collectionName);
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
public async processMultipleRecords(records: KeyValueStorageRecord[], action: Action, collectionName: string): Promise<MultipleRecordsResult> {
|
|
241
|
+
return this.sdkApi.makeRequest({
|
|
242
|
+
method: 'POST',
|
|
243
|
+
route: this.composeRoute(`${STORAGE_MULTIPLE_ROUTE}`),
|
|
244
|
+
data: {
|
|
245
|
+
keys: records,
|
|
246
|
+
method: action,
|
|
247
|
+
table: collectionName,
|
|
248
|
+
},
|
|
132
249
|
});
|
|
133
250
|
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Copy records from one collection to another
|
|
254
|
+
*
|
|
255
|
+
* Existing records in the target collection will be preserved unless they have matching keys with records from the source collection
|
|
256
|
+
* ```typescript
|
|
257
|
+
* const sourceCollectionName = 'old-collection';
|
|
258
|
+
* const targetCollectionName = 'new-collection';
|
|
259
|
+
* const await keyValueStorage.copyCollection(sourceCollectionName, targetCollectionName);
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
public async copyCollection(sourceCollectionName: string, targetCollectionName: string): Promise<void> {
|
|
263
|
+
const { items } = await this.listKeys(sourceCollectionName, '', true);
|
|
264
|
+
|
|
265
|
+
const recordGroups = splitIntoParts(items);
|
|
266
|
+
|
|
267
|
+
for (const records of recordGroups) {
|
|
268
|
+
await this.processMultipleRecords(records, Action.SET, targetCollectionName);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Delete all records from collection
|
|
274
|
+
* ```typescript
|
|
275
|
+
* const collectionName = 'collection';
|
|
276
|
+
* const await keyValueStorage.clearCollection(collectionName);
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
public async clearCollection(collectionName: string): Promise<void> {
|
|
280
|
+
const { items } = await this.listKeys(collectionName);
|
|
281
|
+
|
|
282
|
+
const recordGroups = splitIntoParts(items);
|
|
283
|
+
|
|
284
|
+
for (const records of recordGroups) {
|
|
285
|
+
await this.processMultipleRecords(records, Action.DELETE, collectionName);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
134
288
|
}
|
package/src/constants.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Token } from '@or-sdk/base';
|
|
1
|
+
import { List, Token } from '@or-sdk/base';
|
|
2
2
|
|
|
3
3
|
export type KeyValueStorageConfig = {
|
|
4
4
|
/**
|
|
@@ -22,7 +22,6 @@ export type KeyValueStorageConfig = {
|
|
|
22
22
|
sdkUrl?: string;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
|
|
26
25
|
export type KeyValueStorageRecord = {
|
|
27
26
|
/**
|
|
28
27
|
* Record key
|
|
@@ -36,4 +35,36 @@ export type KeyValueStorageRecordWithLastModified = KeyValueStorageRecord & {
|
|
|
36
35
|
lastModified: string;
|
|
37
36
|
};
|
|
38
37
|
|
|
38
|
+
export type ListCollectionsResponse = {
|
|
39
|
+
tables: string[];
|
|
40
|
+
isTruncated: boolean;
|
|
41
|
+
count: number;
|
|
42
|
+
next?: string;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type ListKeysResponse = {
|
|
46
|
+
value: {
|
|
47
|
+
records: KeyValueStorageRecordWithLastModified[];
|
|
48
|
+
isTruncated: boolean;
|
|
49
|
+
count: number;
|
|
50
|
+
next?: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
39
54
|
export type DeletedKeyValueStorageRecord = Required<Pick<KeyValueStorageRecord, 'value'>>;
|
|
55
|
+
|
|
56
|
+
export type ScrollOptions = {
|
|
57
|
+
numberOfItems?: number;
|
|
58
|
+
nextId?: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type ScrollResult<T> = List<T> & {
|
|
62
|
+
isTruncated?: boolean;
|
|
63
|
+
nextId?: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type KeyValueStorageRecordExists = KeyValueStorageRecord & {
|
|
67
|
+
exists: boolean;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type MultipleRecordsResult = KeyValueStorageRecord[] | KeyValueStorageRecordExists[] | boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { KeyValueStorageRecord, KeyValueStorageRecordWithLastModified } from '../types';
|
|
2
|
+
|
|
3
|
+
function splitIntoParts(records: KeyValueStorageRecordWithLastModified[]): KeyValueStorageRecord[][] {
|
|
4
|
+
const partLength = 10;
|
|
5
|
+
|
|
6
|
+
return records
|
|
7
|
+
.map(record => {
|
|
8
|
+
return {
|
|
9
|
+
key: record.key,
|
|
10
|
+
value: record.value,
|
|
11
|
+
};
|
|
12
|
+
})
|
|
13
|
+
.reduce((resultArray, item, index) => {
|
|
14
|
+
const partIndex = Math.floor(index / partLength);
|
|
15
|
+
|
|
16
|
+
if (!resultArray[partIndex]) {
|
|
17
|
+
resultArray[partIndex] = [];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
resultArray[partIndex].push(item);
|
|
21
|
+
|
|
22
|
+
return resultArray;
|
|
23
|
+
}, [] as KeyValueStorageRecord[][]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default splitIntoParts;
|