@aws-amplify/datastore 4.7.5 → 5.0.1-console-preview.4208d73.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/README.md +4 -0
- package/lib/authModeStrategies/defaultAuthStrategy.js +3 -2
- package/lib/authModeStrategies/index.js +3 -3
- package/lib/authModeStrategies/multiAuthStrategy.js +81 -24
- package/lib/datastore/datastore.d.ts +3 -4
- package/lib/datastore/datastore.js +361 -227
- package/lib/index.d.ts +1 -1
- package/lib/index.js +25 -12
- package/lib/predicates/index.js +46 -12
- package/lib/predicates/next.d.ts +2 -2
- package/lib/predicates/next.js +172 -74
- package/lib/predicates/sort.js +3 -4
- package/lib/ssr/index.js +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +240 -128
- package/lib/storage/adapter/AsyncStorageDatabase.js +100 -39
- package/lib/storage/adapter/InMemoryStore.js +68 -17
- package/lib/storage/adapter/InMemoryStore.native.js +5 -3
- package/lib/storage/adapter/IndexedDBAdapter.js +355 -199
- package/lib/storage/adapter/StorageAdapterBase.js +154 -85
- package/lib/storage/adapter/getDefaultAdapter/index.js +8 -9
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -3
- package/lib/storage/adapter/index.js +0 -1
- package/lib/storage/relationship.js +31 -21
- package/lib/storage/storage.d.ts +3 -3
- package/lib/storage/storage.js +143 -61
- package/lib/sync/datastoreConnectivity.d.ts +1 -1
- package/lib/sync/datastoreConnectivity.js +57 -9
- package/lib/sync/datastoreReachability/index.js +3 -3
- package/lib/sync/datastoreReachability/index.native.js +7 -5
- package/lib/sync/index.d.ts +1 -1
- package/lib/sync/index.js +193 -125
- package/lib/sync/merger.js +81 -10
- package/lib/sync/outbox.js +101 -30
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +41 -6
- package/lib/sync/processors/mutation.d.ts +1 -1
- package/lib/sync/processors/mutation.js +192 -101
- package/lib/sync/processors/subscription.d.ts +4 -1
- package/lib/sync/processors/subscription.js +190 -178
- package/lib/sync/processors/sync.d.ts +1 -1
- package/lib/sync/processors/sync.js +113 -47
- package/lib/sync/utils.d.ts +4 -4
- package/lib/sync/utils.js +162 -81
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types.d.ts +138 -140
- package/lib/types.js +40 -5
- package/lib/util.d.ts +9 -17
- package/lib/util.js +216 -100
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +0 -1
- package/lib-esm/authModeStrategies/index.js +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +76 -21
- package/lib-esm/datastore/datastore.d.ts +3 -4
- package/lib-esm/datastore/datastore.js +206 -77
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +0 -1
- package/lib-esm/predicates/index.js +40 -7
- package/lib-esm/predicates/next.d.ts +2 -2
- package/lib-esm/predicates/next.js +148 -52
- package/lib-esm/predicates/sort.js +2 -4
- package/lib-esm/ssr/index.js +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +203 -95
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +66 -5
- package/lib-esm/storage/adapter/InMemoryStore.js +52 -2
- package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +271 -138
- package/lib-esm/storage/adapter/StorageAdapterBase.js +130 -62
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -5
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +0 -1
- package/lib-esm/storage/adapter/index.js +1 -1
- package/lib-esm/storage/relationship.js +27 -18
- package/lib-esm/storage/storage.d.ts +3 -3
- package/lib-esm/storage/storage.js +87 -9
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +48 -3
- package/lib-esm/sync/datastoreReachability/index.js +1 -2
- package/lib-esm/sync/datastoreReachability/index.native.js +1 -2
- package/lib-esm/sync/index.d.ts +1 -1
- package/lib-esm/sync/index.js +136 -72
- package/lib-esm/sync/merger.js +73 -3
- package/lib-esm/sync/outbox.js +75 -5
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +39 -5
- package/lib-esm/sync/processors/mutation.d.ts +1 -1
- package/lib-esm/sync/processors/mutation.js +130 -44
- package/lib-esm/sync/processors/subscription.d.ts +4 -1
- package/lib-esm/sync/processors/subscription.js +134 -126
- package/lib-esm/sync/processors/sync.d.ts +1 -1
- package/lib-esm/sync/processors/sync.js +74 -12
- package/lib-esm/sync/utils.d.ts +4 -4
- package/lib-esm/sync/utils.js +135 -55
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types.d.ts +138 -140
- package/lib-esm/types.js +36 -2
- package/lib-esm/util.d.ts +9 -17
- package/lib-esm/util.js +96 -16
- package/package.json +139 -132
- package/src/authModeStrategies/multiAuthStrategy.ts +11 -12
- package/src/datastore/datastore.ts +32 -25
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/InMemoryStore.ts +1 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +1 -1
- package/src/storage/adapter/StorageAdapterBase.ts +1 -1
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -3
- package/src/storage/storage.ts +1 -1
- package/src/sync/datastoreConnectivity.ts +2 -2
- package/src/sync/datastoreReachability/index.native.ts +1 -1
- package/src/sync/datastoreReachability/index.ts +1 -1
- package/src/sync/index.ts +69 -78
- package/src/sync/processors/mutation.ts +16 -10
- package/src/sync/processors/subscription.ts +55 -127
- package/src/sync/processors/sync.ts +8 -4
- package/src/sync/utils.ts +7 -8
- package/src/types.ts +4 -8
- package/src/util.ts +5 -6
- package/lib/.tsbuildinfo +0 -3
- package/lib/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib/authModeStrategies/index.js.map +0 -1
- package/lib/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib/datastore/datastore.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/predicates/index.js.map +0 -1
- package/lib/predicates/next.js.map +0 -1
- package/lib/predicates/sort.js.map +0 -1
- package/lib/ssr/index.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib/storage/adapter/index.js.map +0 -1
- package/lib/storage/relationship.js.map +0 -1
- package/lib/storage/storage.js.map +0 -1
- package/lib/sync/datastoreConnectivity.js.map +0 -1
- package/lib/sync/datastoreReachability/index.js.map +0 -1
- package/lib/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib/sync/index.js.map +0 -1
- package/lib/sync/merger.js.map +0 -1
- package/lib/sync/outbox.js.map +0 -1
- package/lib/sync/processors/errorMaps.js.map +0 -1
- package/lib/sync/processors/mutation.js.map +0 -1
- package/lib/sync/processors/subscription.js.map +0 -1
- package/lib/sync/processors/sync.js.map +0 -1
- package/lib/sync/utils.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/util.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib-esm/authModeStrategies/index.js.map +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib-esm/datastore/datastore.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/predicates/index.js.map +0 -1
- package/lib-esm/predicates/next.js.map +0 -1
- package/lib-esm/predicates/sort.js.map +0 -1
- package/lib-esm/ssr/index.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib-esm/storage/adapter/index.js.map +0 -1
- package/lib-esm/storage/relationship.js.map +0 -1
- package/lib-esm/storage/storage.js.map +0 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib-esm/sync/index.js.map +0 -1
- package/lib-esm/sync/merger.js.map +0 -1
- package/lib-esm/sync/outbox.js.map +0 -1
- package/lib-esm/sync/processors/errorMaps.js.map +0 -1
- package/lib-esm/sync/processors/mutation.js.map +0 -1
- package/lib-esm/sync/processors/subscription.js.map +0 -1
- package/lib-esm/sync/processors/sync.js.map +0 -1
- package/lib-esm/sync/utils.js.map +0 -1
- package/lib-esm/types.js.map +0 -1
- package/lib-esm/util.js.map +0 -1
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
49
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
+
if (!m) return o;
|
|
52
|
+
var i = m.call(o), r, ar = [], e;
|
|
53
|
+
try {
|
|
54
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
+
}
|
|
56
|
+
catch (error) { e = { error: error }; }
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
+
}
|
|
61
|
+
finally { if (e) throw e.error; }
|
|
62
|
+
}
|
|
63
|
+
return ar;
|
|
64
|
+
};
|
|
2
65
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var tslib_1 = require("tslib");
|
|
4
66
|
var types_1 = require("../../types");
|
|
5
67
|
var util_1 = require("../../util");
|
|
6
68
|
var InMemoryStore_1 = require("./InMemoryStore");
|
|
@@ -14,7 +76,7 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
14
76
|
* Maps storeNames to a map of ulid->id
|
|
15
77
|
*/
|
|
16
78
|
this._collectionInMemoryIndex = new Map();
|
|
17
|
-
this.storage = InMemoryStore_1.createInMemoryStore();
|
|
79
|
+
this.storage = (0, InMemoryStore_1.createInMemoryStore)();
|
|
18
80
|
}
|
|
19
81
|
/**
|
|
20
82
|
* Collection index is map of stores (i.e. sync, metadata, mutation event, and data)
|
|
@@ -34,15 +96,15 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
34
96
|
*/
|
|
35
97
|
AsyncStorageDatabase.prototype.getMonotonicFactory = function (storeName) {
|
|
36
98
|
if (!monotonicFactoriesMap.has(storeName)) {
|
|
37
|
-
monotonicFactoriesMap.set(storeName, util_1.monotonicUlidFactory());
|
|
99
|
+
monotonicFactoriesMap.set(storeName, (0, util_1.monotonicUlidFactory)());
|
|
38
100
|
}
|
|
39
101
|
return monotonicFactoriesMap.get(storeName);
|
|
40
102
|
};
|
|
41
103
|
AsyncStorageDatabase.prototype.init = function () {
|
|
42
|
-
return
|
|
104
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
43
105
|
var allKeys, keysForCollectionEntries, allKeys_1, allKeys_1_1, key, _a, dbName, storeName, recordType, ulidOrId, id, ulid, id_1, newUlid, oldKey, newKey, item, e_1_1;
|
|
44
106
|
var e_1, _b;
|
|
45
|
-
return
|
|
107
|
+
return __generator(this, function (_c) {
|
|
46
108
|
switch (_c.label) {
|
|
47
109
|
case 0:
|
|
48
110
|
this._collectionInMemoryIndex.clear();
|
|
@@ -53,12 +115,12 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
53
115
|
_c.label = 2;
|
|
54
116
|
case 2:
|
|
55
117
|
_c.trys.push([2, 12, 13, 14]);
|
|
56
|
-
allKeys_1 =
|
|
118
|
+
allKeys_1 = __values(allKeys), allKeys_1_1 = allKeys_1.next();
|
|
57
119
|
_c.label = 3;
|
|
58
120
|
case 3:
|
|
59
121
|
if (!!allKeys_1_1.done) return [3 /*break*/, 11];
|
|
60
122
|
key = allKeys_1_1.value;
|
|
61
|
-
_a =
|
|
123
|
+
_a = __read(key.split('::'), 5), dbName = _a[0], storeName = _a[1], recordType = _a[2], ulidOrId = _a[3], id = _a[4];
|
|
62
124
|
if (!(dbName === DB_NAME)) return [3 /*break*/, 10];
|
|
63
125
|
if (!(recordType === DATA)) return [3 /*break*/, 9];
|
|
64
126
|
ulid = void 0;
|
|
@@ -116,12 +178,12 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
116
178
|
};
|
|
117
179
|
AsyncStorageDatabase.prototype.save = function (item, storeName, keys, keyValuesPath) {
|
|
118
180
|
var _a, _b;
|
|
119
|
-
return
|
|
181
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
120
182
|
var idxName, ulid, itemKey;
|
|
121
|
-
return
|
|
183
|
+
return __generator(this, function (_c) {
|
|
122
184
|
switch (_c.label) {
|
|
123
185
|
case 0:
|
|
124
|
-
idxName = util_1.indexNameFromKeys(keys);
|
|
186
|
+
idxName = (0, util_1.indexNameFromKeys)(keys);
|
|
125
187
|
ulid = ((_a = this.getCollectionIndex(storeName)) === null || _a === void 0 ? void 0 : _a.get(idxName)) ||
|
|
126
188
|
this.getMonotonicFactory(storeName)();
|
|
127
189
|
itemKey = this.getKeyForItem(storeName, keyValuesPath, ulid);
|
|
@@ -138,11 +200,11 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
138
200
|
});
|
|
139
201
|
};
|
|
140
202
|
AsyncStorageDatabase.prototype.batchSave = function (storeName, items, keys) {
|
|
141
|
-
return
|
|
203
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
142
204
|
var result, collection, keysToDelete, keysToSave, allItemsKeys, itemsMap, _loop_1, this_1, items_1, items_1_1, item, existingRecordsMap, existingRecordsKeys, allItemsKeys_1, allItemsKeys_1_1, key;
|
|
143
205
|
var e_2, _a, e_3, _b;
|
|
144
206
|
var _this = this;
|
|
145
|
-
return
|
|
207
|
+
return __generator(this, function (_c) {
|
|
146
208
|
switch (_c.label) {
|
|
147
209
|
case 0:
|
|
148
210
|
if (items.length === 0) {
|
|
@@ -175,7 +237,7 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
175
237
|
this_1 = this;
|
|
176
238
|
try {
|
|
177
239
|
/* Populate allItemKeys, keysToDelete, and keysToSave */
|
|
178
|
-
for (items_1 =
|
|
240
|
+
for (items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
179
241
|
item = items_1_1.value;
|
|
180
242
|
_loop_1(item);
|
|
181
243
|
}
|
|
@@ -192,11 +254,11 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
192
254
|
existingRecordsMap = _c.sent();
|
|
193
255
|
existingRecordsKeys = existingRecordsMap
|
|
194
256
|
.filter(function (_a) {
|
|
195
|
-
var _b =
|
|
257
|
+
var _b = __read(_a, 2), v = _b[1];
|
|
196
258
|
return !!v;
|
|
197
259
|
})
|
|
198
260
|
.reduce(function (set, _a) {
|
|
199
|
-
var _b =
|
|
261
|
+
var _b = __read(_a, 1), k = _b[0];
|
|
200
262
|
return set.add(k);
|
|
201
263
|
}, new Set());
|
|
202
264
|
// Delete
|
|
@@ -257,7 +319,7 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
257
319
|
// Save
|
|
258
320
|
_c.sent();
|
|
259
321
|
try {
|
|
260
|
-
for (allItemsKeys_1 =
|
|
322
|
+
for (allItemsKeys_1 = __values(allItemsKeys), allItemsKeys_1_1 = allItemsKeys_1.next(); !allItemsKeys_1_1.done; allItemsKeys_1_1 = allItemsKeys_1.next()) {
|
|
261
323
|
key = allItemsKeys_1_1.value;
|
|
262
324
|
if (keysToDelete.has(key) && existingRecordsKeys.has(key)) {
|
|
263
325
|
result.push([itemsMap[key].model, types_1.OpType.DELETE]);
|
|
@@ -283,9 +345,9 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
283
345
|
});
|
|
284
346
|
};
|
|
285
347
|
AsyncStorageDatabase.prototype.get = function (keyValuePath, storeName) {
|
|
286
|
-
return
|
|
348
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
287
349
|
var ulid, itemKey, recordAsString, record;
|
|
288
|
-
return
|
|
350
|
+
return __generator(this, function (_a) {
|
|
289
351
|
switch (_a.label) {
|
|
290
352
|
case 0:
|
|
291
353
|
ulid = this.getCollectionIndex(storeName).get(keyValuePath);
|
|
@@ -300,19 +362,19 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
300
362
|
});
|
|
301
363
|
};
|
|
302
364
|
AsyncStorageDatabase.prototype.getOne = function (firstOrLast, storeName) {
|
|
303
|
-
return
|
|
365
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
304
366
|
var collection, _a, itemId, ulid, itemKey, itemString, _b, result;
|
|
305
|
-
return
|
|
367
|
+
return __generator(this, function (_c) {
|
|
306
368
|
switch (_c.label) {
|
|
307
369
|
case 0:
|
|
308
370
|
collection = this.getCollectionIndex(storeName);
|
|
309
|
-
_a =
|
|
371
|
+
_a = __read(firstOrLast === types_1.QueryOne.FIRST
|
|
310
372
|
? (function () {
|
|
311
373
|
var e_4, _a, _b;
|
|
312
374
|
var id, ulid;
|
|
313
375
|
try {
|
|
314
|
-
for (var collection_1 =
|
|
315
|
-
_b =
|
|
376
|
+
for (var collection_1 = __values(collection), collection_1_1 = collection_1.next(); !collection_1_1.done; collection_1_1 = collection_1.next()) {
|
|
377
|
+
_b = __read(collection_1_1.value, 2), id = _b[0], ulid = _b[1];
|
|
316
378
|
break;
|
|
317
379
|
} // Get first element of the set
|
|
318
380
|
}
|
|
@@ -329,8 +391,8 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
329
391
|
var e_5, _a, _b;
|
|
330
392
|
var id, ulid;
|
|
331
393
|
try {
|
|
332
|
-
for (var collection_2 =
|
|
333
|
-
_b =
|
|
394
|
+
for (var collection_2 = __values(collection), collection_2_1 = collection_2.next(); !collection_2_1.done; collection_2_1 = collection_2.next()) {
|
|
395
|
+
_b = __read(collection_2_1.value, 2), id = _b[0], ulid = _b[1];
|
|
334
396
|
;
|
|
335
397
|
} // Get last element of the set
|
|
336
398
|
}
|
|
@@ -363,10 +425,10 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
363
425
|
* It then loads all the records for that filtered set of keys using multiGet()
|
|
364
426
|
*/
|
|
365
427
|
AsyncStorageDatabase.prototype.getAll = function (storeName, pagination) {
|
|
366
|
-
return
|
|
428
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
367
429
|
var collection, _a, _b, page, _c, limit, start, end, keysForStore, count, collection_3, collection_3_1, _d, id, ulid, storeRecordStrings, records;
|
|
368
430
|
var e_6, _e;
|
|
369
|
-
return
|
|
431
|
+
return __generator(this, function (_f) {
|
|
370
432
|
switch (_f.label) {
|
|
371
433
|
case 0:
|
|
372
434
|
collection = this.getCollectionIndex(storeName);
|
|
@@ -376,8 +438,8 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
376
438
|
keysForStore = [];
|
|
377
439
|
count = 0;
|
|
378
440
|
try {
|
|
379
|
-
for (collection_3 =
|
|
380
|
-
_d =
|
|
441
|
+
for (collection_3 = __values(collection), collection_3_1 = collection_3.next(); !collection_3_1.done; collection_3_1 = collection_3.next()) {
|
|
442
|
+
_d = __read(collection_3_1.value, 2), id = _d[0], ulid = _d[1];
|
|
381
443
|
count++;
|
|
382
444
|
if (count <= start) {
|
|
383
445
|
continue;
|
|
@@ -400,11 +462,11 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
400
462
|
storeRecordStrings = _f.sent();
|
|
401
463
|
records = storeRecordStrings
|
|
402
464
|
.filter(function (_a) {
|
|
403
|
-
var _b =
|
|
465
|
+
var _b = __read(_a, 2), value = _b[1];
|
|
404
466
|
return value;
|
|
405
467
|
})
|
|
406
468
|
.map(function (_a) {
|
|
407
|
-
var _b =
|
|
469
|
+
var _b = __read(_a, 2), value = _b[1];
|
|
408
470
|
return JSON.parse(value);
|
|
409
471
|
});
|
|
410
472
|
return [2 /*return*/, records];
|
|
@@ -413,9 +475,9 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
413
475
|
});
|
|
414
476
|
};
|
|
415
477
|
AsyncStorageDatabase.prototype.delete = function (key, storeName) {
|
|
416
|
-
return
|
|
478
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
417
479
|
var ulid, itemKey;
|
|
418
|
-
return
|
|
480
|
+
return __generator(this, function (_a) {
|
|
419
481
|
switch (_a.label) {
|
|
420
482
|
case 0:
|
|
421
483
|
ulid = this.getCollectionIndex(storeName).get(key);
|
|
@@ -433,9 +495,9 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
433
495
|
* Clear the AsyncStorage of all DataStore entries
|
|
434
496
|
*/
|
|
435
497
|
AsyncStorageDatabase.prototype.clear = function () {
|
|
436
|
-
return
|
|
498
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
437
499
|
var allKeys, allDataStoreKeys;
|
|
438
|
-
return
|
|
500
|
+
return __generator(this, function (_a) {
|
|
439
501
|
switch (_a.label) {
|
|
440
502
|
case 0: return [4 /*yield*/, this.storage.getAllKeys()];
|
|
441
503
|
case 1:
|
|
@@ -451,15 +513,14 @@ var AsyncStorageDatabase = /** @class */ (function () {
|
|
|
451
513
|
});
|
|
452
514
|
};
|
|
453
515
|
AsyncStorageDatabase.prototype.getKeyForItem = function (storeName, id, ulid) {
|
|
454
|
-
return this.getKeyPrefixForStoreItems(storeName)
|
|
516
|
+
return "".concat(this.getKeyPrefixForStoreItems(storeName), "::").concat(ulid, "::").concat(id);
|
|
455
517
|
};
|
|
456
518
|
AsyncStorageDatabase.prototype.getLegacyKeyForItem = function (storeName, id) {
|
|
457
|
-
return this.getKeyPrefixForStoreItems(storeName)
|
|
519
|
+
return "".concat(this.getKeyPrefixForStoreItems(storeName), "::").concat(id);
|
|
458
520
|
};
|
|
459
521
|
AsyncStorageDatabase.prototype.getKeyPrefixForStoreItems = function (storeName) {
|
|
460
|
-
return DB_NAME
|
|
522
|
+
return "".concat(DB_NAME, "::").concat(storeName, "::").concat(DATA);
|
|
461
523
|
};
|
|
462
524
|
return AsyncStorageDatabase;
|
|
463
525
|
}());
|
|
464
526
|
exports.default = AsyncStorageDatabase;
|
|
465
|
-
//# sourceMappingURL=AsyncStorageDatabase.js.map
|
|
@@ -1,54 +1,106 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
2
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
55
|
+
exports.createInMemoryStore = exports.InMemoryStore = void 0;
|
|
4
56
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
57
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
58
|
var InMemoryStore = /** @class */ (function () {
|
|
7
59
|
function InMemoryStore() {
|
|
8
60
|
var _this = this;
|
|
9
61
|
this.db = new Map();
|
|
10
|
-
this.getAllKeys = function () { return
|
|
11
|
-
return
|
|
62
|
+
this.getAllKeys = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
63
|
+
return __generator(this, function (_a) {
|
|
12
64
|
return [2 /*return*/, Array.from(this.db.keys())];
|
|
13
65
|
});
|
|
14
66
|
}); };
|
|
15
|
-
this.multiGet = function (keys) { return
|
|
67
|
+
this.multiGet = function (keys) { return __awaiter(_this, void 0, void 0, function () {
|
|
16
68
|
var _this = this;
|
|
17
|
-
return
|
|
69
|
+
return __generator(this, function (_a) {
|
|
18
70
|
return [2 /*return*/, keys.reduce(function (res, k) { return (res.push([k, _this.db.get(k)]), res); }, [])];
|
|
19
71
|
});
|
|
20
72
|
}); };
|
|
21
|
-
this.multiRemove = function (keys, callback) { return
|
|
73
|
+
this.multiRemove = function (keys, callback) { return __awaiter(_this, void 0, void 0, function () {
|
|
22
74
|
var _this = this;
|
|
23
|
-
return
|
|
75
|
+
return __generator(this, function (_a) {
|
|
24
76
|
keys.forEach(function (k) { return _this.db.delete(k); });
|
|
25
77
|
typeof callback === 'function' && callback();
|
|
26
78
|
return [2 /*return*/];
|
|
27
79
|
});
|
|
28
80
|
}); };
|
|
29
|
-
this.multiSet = function (entries, callback) { return
|
|
81
|
+
this.multiSet = function (entries, callback) { return __awaiter(_this, void 0, void 0, function () {
|
|
30
82
|
var _this = this;
|
|
31
|
-
return
|
|
83
|
+
return __generator(this, function (_a) {
|
|
32
84
|
entries.forEach(function (_a) {
|
|
33
|
-
var _b =
|
|
85
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
34
86
|
_this.setItem(key, value);
|
|
35
87
|
});
|
|
36
88
|
typeof callback === 'function' && callback();
|
|
37
89
|
return [2 /*return*/];
|
|
38
90
|
});
|
|
39
91
|
}); };
|
|
40
|
-
this.setItem = function (key, value) { return
|
|
41
|
-
return
|
|
92
|
+
this.setItem = function (key, value) { return __awaiter(_this, void 0, void 0, function () {
|
|
93
|
+
return __generator(this, function (_a) {
|
|
42
94
|
return [2 /*return*/, this.db.set(key, value)];
|
|
43
95
|
});
|
|
44
96
|
}); };
|
|
45
|
-
this.removeItem = function (key) { return
|
|
46
|
-
return
|
|
97
|
+
this.removeItem = function (key) { return __awaiter(_this, void 0, void 0, function () {
|
|
98
|
+
return __generator(this, function (_a) {
|
|
47
99
|
return [2 /*return*/, this.db.delete(key)];
|
|
48
100
|
});
|
|
49
101
|
}); };
|
|
50
|
-
this.getItem = function (key) { return
|
|
51
|
-
return
|
|
102
|
+
this.getItem = function (key) { return __awaiter(_this, void 0, void 0, function () {
|
|
103
|
+
return __generator(this, function (_a) {
|
|
52
104
|
return [2 /*return*/, this.db.get(key)];
|
|
53
105
|
});
|
|
54
106
|
}); };
|
|
@@ -60,4 +112,3 @@ function createInMemoryStore() {
|
|
|
60
112
|
return new InMemoryStore();
|
|
61
113
|
}
|
|
62
114
|
exports.createInMemoryStore = createInMemoryStore;
|
|
63
|
-
//# sourceMappingURL=InMemoryStore.js.map
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
6
|
+
exports.createInMemoryStore = void 0;
|
|
4
7
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
var async_storage_1 =
|
|
9
|
+
var async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
|
|
7
10
|
// See: https://react-native-async-storage.github.io/async-storage/
|
|
8
11
|
function createInMemoryStore() {
|
|
9
12
|
return async_storage_1.default;
|
|
10
13
|
}
|
|
11
14
|
exports.createInMemoryStore = createInMemoryStore;
|
|
12
|
-
//# sourceMappingURL=InMemoryStore.native.js.map
|