@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,11 +1,104 @@
|
|
|
1
|
-
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
26
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
27
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
28
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
29
|
+
function step(op) {
|
|
30
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
31
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
32
|
+
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;
|
|
33
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
34
|
+
switch (op[0]) {
|
|
35
|
+
case 0: case 1: t = op; break;
|
|
36
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
37
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
38
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
39
|
+
default:
|
|
40
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
41
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
42
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
43
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
44
|
+
if (t[2]) _.ops.pop();
|
|
45
|
+
_.trys.pop(); continue;
|
|
46
|
+
}
|
|
47
|
+
op = body.call(thisArg, _);
|
|
48
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
49
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
53
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
54
|
+
var m = o[Symbol.asyncIterator], i;
|
|
55
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
56
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
57
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
58
|
+
};
|
|
59
|
+
var __values = (this && this.__values) || function(o) {
|
|
60
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
61
|
+
if (m) return m.call(o);
|
|
62
|
+
if (o && typeof o.length === "number") return {
|
|
63
|
+
next: function () {
|
|
64
|
+
if (o && i >= o.length) o = void 0;
|
|
65
|
+
return { value: o && o[i++], done: !o };
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
69
|
+
};
|
|
70
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
71
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
72
|
+
if (!m) return o;
|
|
73
|
+
var i = m.call(o), r, ar = [], e;
|
|
74
|
+
try {
|
|
75
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
76
|
+
}
|
|
77
|
+
catch (error) { e = { error: error }; }
|
|
78
|
+
finally {
|
|
79
|
+
try {
|
|
80
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
81
|
+
}
|
|
82
|
+
finally { if (e) throw e.error; }
|
|
83
|
+
}
|
|
84
|
+
return ar;
|
|
85
|
+
};
|
|
86
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
87
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
88
|
+
if (ar || !(i in from)) {
|
|
89
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
90
|
+
ar[i] = from[i];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
94
|
+
};
|
|
2
95
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
96
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
5
97
|
import * as idb from 'idb';
|
|
6
98
|
import { isPredicateObj, isPredicateGroup, OpType, QueryOne, } from '../../types';
|
|
7
99
|
import { isPrivateMode, traverseModel, validatePredicate, inMemoryPagination, keysEqual, getStorename, isSafariCompatabilityMode, } from '../../util';
|
|
8
100
|
import { StorageAdapterBase } from './StorageAdapterBase';
|
|
101
|
+
import { Logger } from '@aws-amplify/core/internals/utils';
|
|
9
102
|
var logger = new Logger('DataStore');
|
|
10
103
|
/**
|
|
11
104
|
* The point after which queries composed of multiple simple OR conditions
|
|
@@ -127,7 +220,7 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
127
220
|
if (!!_b.done) return [3 /*break*/, 10];
|
|
128
221
|
storeName = _b.value;
|
|
129
222
|
origStore = txn.objectStore(storeName);
|
|
130
|
-
tmpName = "tmp_"
|
|
223
|
+
tmpName = "tmp_".concat(storeName);
|
|
131
224
|
origStore.name = tmpName;
|
|
132
225
|
_c = this.getNamespaceAndModelFromStorename(storeName), namespaceName = _c.namespaceName, modelName = _c.modelName;
|
|
133
226
|
modelInCurrentSchema = modelName in this.schema.namespaces[namespaceName].models;
|
|
@@ -157,7 +250,7 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
157
250
|
case 8:
|
|
158
251
|
// delete original
|
|
159
252
|
db.deleteObjectStore(tmpName);
|
|
160
|
-
logger.debug(count
|
|
253
|
+
logger.debug("".concat(count, " ").concat(storeName, " records migrated"));
|
|
161
254
|
_e.label = 9;
|
|
162
255
|
case 9:
|
|
163
256
|
_b = _a.next();
|
|
@@ -252,71 +345,94 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
252
345
|
});
|
|
253
346
|
};
|
|
254
347
|
IndexedDBAdapter.prototype.save = function (model, condition) {
|
|
255
|
-
var e_2,
|
|
348
|
+
var _a, e_2, _b, _c;
|
|
256
349
|
return __awaiter(this, void 0, void 0, function () {
|
|
257
|
-
var
|
|
258
|
-
return __generator(this, function (
|
|
259
|
-
switch (
|
|
350
|
+
var _d, storeName, set, connectionStoreNames, modelKeyValues, tx, store, fromDB, result, _loop_1, this_1, _e, connectionStoreNames_1, connectionStoreNames_1_1, e_2_1;
|
|
351
|
+
return __generator(this, function (_f) {
|
|
352
|
+
switch (_f.label) {
|
|
260
353
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
261
354
|
case 1:
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
tx = this.db.transaction(
|
|
355
|
+
_f.sent();
|
|
356
|
+
_d = this.saveMetadata(model), storeName = _d.storeName, set = _d.set, connectionStoreNames = _d.connectionStoreNames, modelKeyValues = _d.modelKeyValues;
|
|
357
|
+
tx = this.db.transaction(__spreadArray([storeName], __read(Array.from(set.values())), false), 'readwrite');
|
|
265
358
|
store = tx.objectStore(storeName);
|
|
266
359
|
return [4 /*yield*/, this._get(store, modelKeyValues)];
|
|
267
360
|
case 2:
|
|
268
|
-
fromDB =
|
|
361
|
+
fromDB = _f.sent();
|
|
269
362
|
this.validateSaveCondition(condition, fromDB);
|
|
270
363
|
result = [];
|
|
271
|
-
|
|
364
|
+
_f.label = 3;
|
|
272
365
|
case 3:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
366
|
+
_f.trys.push([3, 9, 10, 15]);
|
|
367
|
+
_loop_1 = function () {
|
|
368
|
+
var resItem, storeName_1, item, instance, keys, store_1, itemKeyValues, fromDB_1, opType, key;
|
|
369
|
+
return __generator(this, function (_g) {
|
|
370
|
+
switch (_g.label) {
|
|
371
|
+
case 0:
|
|
372
|
+
_c = connectionStoreNames_1_1.value;
|
|
373
|
+
_e = false;
|
|
374
|
+
_g.label = 1;
|
|
375
|
+
case 1:
|
|
376
|
+
_g.trys.push([1, , 6, 7]);
|
|
377
|
+
resItem = _c;
|
|
378
|
+
storeName_1 = resItem.storeName, item = resItem.item, instance = resItem.instance, keys = resItem.keys;
|
|
379
|
+
store_1 = tx.objectStore(storeName_1);
|
|
380
|
+
itemKeyValues = keys.map(function (key) { return item[key]; });
|
|
381
|
+
return [4 /*yield*/, this_1._get(store_1, itemKeyValues)];
|
|
382
|
+
case 2:
|
|
383
|
+
fromDB_1 = _g.sent();
|
|
384
|
+
opType = fromDB_1 ? OpType.UPDATE : OpType.INSERT;
|
|
385
|
+
if (!(keysEqual(itemKeyValues, modelKeyValues) ||
|
|
386
|
+
opType === OpType.INSERT)) return [3 /*break*/, 5];
|
|
387
|
+
return [4 /*yield*/, store_1
|
|
388
|
+
.index('byPk')
|
|
389
|
+
.getKey(this_1.canonicalKeyPath(itemKeyValues))];
|
|
390
|
+
case 3:
|
|
391
|
+
key = _g.sent();
|
|
392
|
+
return [4 /*yield*/, store_1.put(item, key)];
|
|
393
|
+
case 4:
|
|
394
|
+
_g.sent();
|
|
395
|
+
result.push([instance, opType]);
|
|
396
|
+
_g.label = 5;
|
|
397
|
+
case 5: return [3 /*break*/, 7];
|
|
398
|
+
case 6:
|
|
399
|
+
_e = true;
|
|
400
|
+
return [7 /*endfinally*/];
|
|
401
|
+
case 7: return [2 /*return*/];
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
};
|
|
405
|
+
this_1 = this;
|
|
406
|
+
_e = true, connectionStoreNames_1 = __asyncValues(connectionStoreNames);
|
|
407
|
+
_f.label = 4;
|
|
276
408
|
case 4: return [4 /*yield*/, connectionStoreNames_1.next()];
|
|
277
409
|
case 5:
|
|
278
|
-
if (!(connectionStoreNames_1_1 =
|
|
279
|
-
|
|
280
|
-
storeName_1 = resItem.storeName, item = resItem.item, instance = resItem.instance, keys = resItem.keys;
|
|
281
|
-
store_1 = tx.objectStore(storeName_1);
|
|
282
|
-
itemKeyValues = keys.map(function (key) { return item[key]; });
|
|
283
|
-
return [4 /*yield*/, this._get(store_1, itemKeyValues)];
|
|
410
|
+
if (!(connectionStoreNames_1_1 = _f.sent(), _a = connectionStoreNames_1_1.done, !_a)) return [3 /*break*/, 8];
|
|
411
|
+
return [5 /*yield**/, _loop_1()];
|
|
284
412
|
case 6:
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
.getKey(this.canonicalKeyPath(itemKeyValues))];
|
|
292
|
-
case 7:
|
|
293
|
-
key = _c.sent();
|
|
294
|
-
return [4 /*yield*/, store_1.put(item, key)];
|
|
295
|
-
case 8:
|
|
296
|
-
_c.sent();
|
|
297
|
-
result.push([instance, opType]);
|
|
298
|
-
_c.label = 9;
|
|
299
|
-
case 9: return [3 /*break*/, 4];
|
|
300
|
-
case 10: return [3 /*break*/, 17];
|
|
301
|
-
case 11:
|
|
302
|
-
e_2_1 = _c.sent();
|
|
413
|
+
_f.sent();
|
|
414
|
+
_f.label = 7;
|
|
415
|
+
case 7: return [3 /*break*/, 4];
|
|
416
|
+
case 8: return [3 /*break*/, 15];
|
|
417
|
+
case 9:
|
|
418
|
+
e_2_1 = _f.sent();
|
|
303
419
|
e_2 = { error: e_2_1 };
|
|
304
|
-
return [3 /*break*/,
|
|
305
|
-
case
|
|
306
|
-
|
|
307
|
-
if (!(
|
|
308
|
-
return [4 /*yield*/,
|
|
420
|
+
return [3 /*break*/, 15];
|
|
421
|
+
case 10:
|
|
422
|
+
_f.trys.push([10, , 13, 14]);
|
|
423
|
+
if (!(!_e && !_a && (_b = connectionStoreNames_1.return))) return [3 /*break*/, 12];
|
|
424
|
+
return [4 /*yield*/, _b.call(connectionStoreNames_1)];
|
|
425
|
+
case 11:
|
|
426
|
+
_f.sent();
|
|
427
|
+
_f.label = 12;
|
|
428
|
+
case 12: return [3 /*break*/, 14];
|
|
309
429
|
case 13:
|
|
310
|
-
_c.sent();
|
|
311
|
-
_c.label = 14;
|
|
312
|
-
case 14: return [3 /*break*/, 16];
|
|
313
|
-
case 15:
|
|
314
430
|
if (e_2) throw e_2.error;
|
|
315
431
|
return [7 /*endfinally*/];
|
|
316
|
-
case
|
|
317
|
-
case
|
|
318
|
-
case
|
|
319
|
-
|
|
432
|
+
case 14: return [7 /*endfinally*/];
|
|
433
|
+
case 15: return [4 /*yield*/, tx.done];
|
|
434
|
+
case 16:
|
|
435
|
+
_f.sent();
|
|
320
436
|
return [2 /*return*/, result];
|
|
321
437
|
}
|
|
322
438
|
});
|
|
@@ -394,7 +510,7 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
394
510
|
};
|
|
395
511
|
IndexedDBAdapter.prototype.batchSave = function (modelConstructor, items) {
|
|
396
512
|
return __awaiter(this, void 0, void 0, function () {
|
|
397
|
-
var modelName, namespaceName, storeName, result, txn, store,
|
|
513
|
+
var modelName, namespaceName, storeName, result, txn, store, _loop_2, this_2, items_1, items_1_1, item, e_3_1;
|
|
398
514
|
var e_3, _a;
|
|
399
515
|
var _this = this;
|
|
400
516
|
return __generator(this, function (_b) {
|
|
@@ -411,19 +527,19 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
411
527
|
result = [];
|
|
412
528
|
txn = this.db.transaction(storeName, 'readwrite');
|
|
413
529
|
store = txn.store;
|
|
414
|
-
|
|
530
|
+
_loop_2 = function (item) {
|
|
415
531
|
var model, connectedModels, keyValues, _deleted, index, key, instance;
|
|
416
|
-
return __generator(this, function (
|
|
417
|
-
switch (
|
|
532
|
+
return __generator(this, function (_c) {
|
|
533
|
+
switch (_c.label) {
|
|
418
534
|
case 0:
|
|
419
|
-
model =
|
|
420
|
-
connectedModels = traverseModel(modelName, model,
|
|
421
|
-
keyValues =
|
|
535
|
+
model = this_2.modelInstanceCreator(modelConstructor, item);
|
|
536
|
+
connectedModels = traverseModel(modelName, model, this_2.schema.namespaces[namespaceName], this_2.modelInstanceCreator, this_2.getModelConstructorByModelName);
|
|
537
|
+
keyValues = this_2.getIndexKeyValuesFromModel(model);
|
|
422
538
|
_deleted = item._deleted;
|
|
423
539
|
index = store.index('byPk');
|
|
424
|
-
return [4 /*yield*/, index.getKey(
|
|
540
|
+
return [4 /*yield*/, index.getKey(this_2.canonicalKeyPath(keyValues))];
|
|
425
541
|
case 1:
|
|
426
|
-
key =
|
|
542
|
+
key = _c.sent();
|
|
427
543
|
if (!!_deleted) return [3 /*break*/, 3];
|
|
428
544
|
instance = connectedModels.find(function (_a) {
|
|
429
545
|
var instance = _a.instance;
|
|
@@ -436,20 +552,20 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
436
552
|
]);
|
|
437
553
|
return [4 /*yield*/, store.put(instance, key)];
|
|
438
554
|
case 2:
|
|
439
|
-
|
|
555
|
+
_c.sent();
|
|
440
556
|
return [3 /*break*/, 5];
|
|
441
557
|
case 3:
|
|
442
558
|
result.push([item, OpType.DELETE]);
|
|
443
559
|
if (!key) return [3 /*break*/, 5];
|
|
444
560
|
return [4 /*yield*/, store.delete(key)];
|
|
445
561
|
case 4:
|
|
446
|
-
|
|
447
|
-
|
|
562
|
+
_c.sent();
|
|
563
|
+
_c.label = 5;
|
|
448
564
|
case 5: return [2 /*return*/];
|
|
449
565
|
}
|
|
450
566
|
});
|
|
451
567
|
};
|
|
452
|
-
|
|
568
|
+
this_2 = this;
|
|
453
569
|
_b.label = 2;
|
|
454
570
|
case 2:
|
|
455
571
|
_b.trys.push([2, 7, 8, 9]);
|
|
@@ -458,7 +574,7 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
458
574
|
case 3:
|
|
459
575
|
if (!!items_1_1.done) return [3 /*break*/, 6];
|
|
460
576
|
item = items_1_1.value;
|
|
461
|
-
return [5 /*yield**/,
|
|
577
|
+
return [5 /*yield**/, _loop_2(item)];
|
|
462
578
|
case 4:
|
|
463
579
|
_b.sent();
|
|
464
580
|
_b.label = 5;
|
|
@@ -485,96 +601,114 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
485
601
|
});
|
|
486
602
|
};
|
|
487
603
|
IndexedDBAdapter.prototype.deleteItem = function (deleteQueue) {
|
|
488
|
-
var e_4,
|
|
604
|
+
var _a, e_4, _b, _c, _d, e_5, _e, _f;
|
|
489
605
|
return __awaiter(this, void 0, void 0, function () {
|
|
490
|
-
var connectionStoreNames, tx,
|
|
491
|
-
return __generator(this, function (
|
|
492
|
-
switch (
|
|
606
|
+
var connectionStoreNames, tx, _g, _h, _j, deleteItem, storeName, items, store, _k, items_2, items_2_1, item, key, keyValues, itemKey, e_5_1, e_4_1;
|
|
607
|
+
return __generator(this, function (_l) {
|
|
608
|
+
switch (_l.label) {
|
|
493
609
|
case 0:
|
|
494
610
|
connectionStoreNames = deleteQueue.map(function (_a) {
|
|
495
611
|
var storeName = _a.storeName;
|
|
496
612
|
return storeName;
|
|
497
613
|
});
|
|
498
|
-
tx = this.db.transaction(
|
|
499
|
-
|
|
614
|
+
tx = this.db.transaction(__spreadArray([], __read(connectionStoreNames), false), 'readwrite');
|
|
615
|
+
_l.label = 1;
|
|
500
616
|
case 1:
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
case 2: return [4 /*yield*/,
|
|
617
|
+
_l.trys.push([1, 28, 29, 34]);
|
|
618
|
+
_g = true, _h = __asyncValues(deleteQueue);
|
|
619
|
+
_l.label = 2;
|
|
620
|
+
case 2: return [4 /*yield*/, _h.next()];
|
|
505
621
|
case 3:
|
|
506
|
-
if (!(
|
|
507
|
-
|
|
622
|
+
if (!(_j = _l.sent(), _a = _j.done, !_a)) return [3 /*break*/, 27];
|
|
623
|
+
_c = _j.value;
|
|
624
|
+
_g = false;
|
|
625
|
+
_l.label = 4;
|
|
626
|
+
case 4:
|
|
627
|
+
_l.trys.push([4, , 25, 26]);
|
|
628
|
+
deleteItem = _c;
|
|
508
629
|
storeName = deleteItem.storeName, items = deleteItem.items;
|
|
509
630
|
store = tx.objectStore(storeName);
|
|
510
|
-
|
|
511
|
-
case
|
|
512
|
-
|
|
513
|
-
items_2 = __asyncValues(items);
|
|
514
|
-
|
|
515
|
-
case
|
|
516
|
-
case
|
|
517
|
-
if (!(items_2_1 =
|
|
518
|
-
|
|
519
|
-
|
|
631
|
+
_l.label = 5;
|
|
632
|
+
case 5:
|
|
633
|
+
_l.trys.push([5, 18, 19, 24]);
|
|
634
|
+
_k = true, items_2 = (e_5 = void 0, __asyncValues(items));
|
|
635
|
+
_l.label = 6;
|
|
636
|
+
case 6: return [4 /*yield*/, items_2.next()];
|
|
637
|
+
case 7:
|
|
638
|
+
if (!(items_2_1 = _l.sent(), _d = items_2_1.done, !_d)) return [3 /*break*/, 17];
|
|
639
|
+
_f = items_2_1.value;
|
|
640
|
+
_k = false;
|
|
641
|
+
_l.label = 8;
|
|
642
|
+
case 8:
|
|
643
|
+
_l.trys.push([8, , 15, 16]);
|
|
644
|
+
item = _f;
|
|
645
|
+
if (!item) return [3 /*break*/, 14];
|
|
520
646
|
key = void 0;
|
|
521
|
-
if (!(typeof item === 'object')) return [3 /*break*/,
|
|
647
|
+
if (!(typeof item === 'object')) return [3 /*break*/, 10];
|
|
522
648
|
keyValues = this.getIndexKeyValuesFromModel(item);
|
|
523
649
|
return [4 /*yield*/, store
|
|
524
650
|
.index('byPk')
|
|
525
651
|
.getKey(this.canonicalKeyPath(keyValues))];
|
|
526
|
-
case 7:
|
|
527
|
-
key = _e.sent();
|
|
528
|
-
return [3 /*break*/, 10];
|
|
529
|
-
case 8:
|
|
530
|
-
itemKey = item.toString();
|
|
531
|
-
return [4 /*yield*/, store.index('byPk').getKey(itemKey)];
|
|
532
652
|
case 9:
|
|
533
|
-
key =
|
|
534
|
-
|
|
653
|
+
key = _l.sent();
|
|
654
|
+
return [3 /*break*/, 12];
|
|
535
655
|
case 10:
|
|
536
|
-
|
|
537
|
-
return [4 /*yield*/, store.
|
|
656
|
+
itemKey = item.toString();
|
|
657
|
+
return [4 /*yield*/, store.index('byPk').getKey(itemKey)];
|
|
538
658
|
case 11:
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
case 12:
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
659
|
+
key = _l.sent();
|
|
660
|
+
_l.label = 12;
|
|
661
|
+
case 12:
|
|
662
|
+
if (!(key !== undefined)) return [3 /*break*/, 14];
|
|
663
|
+
return [4 /*yield*/, store.delete(key)];
|
|
664
|
+
case 13:
|
|
665
|
+
_l.sent();
|
|
666
|
+
_l.label = 14;
|
|
667
|
+
case 14: return [3 /*break*/, 16];
|
|
547
668
|
case 15:
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
case
|
|
552
|
-
_e.sent();
|
|
553
|
-
_e.label = 17;
|
|
554
|
-
case 17: return [3 /*break*/, 19];
|
|
669
|
+
_k = true;
|
|
670
|
+
return [7 /*endfinally*/];
|
|
671
|
+
case 16: return [3 /*break*/, 6];
|
|
672
|
+
case 17: return [3 /*break*/, 24];
|
|
555
673
|
case 18:
|
|
674
|
+
e_5_1 = _l.sent();
|
|
675
|
+
e_5 = { error: e_5_1 };
|
|
676
|
+
return [3 /*break*/, 24];
|
|
677
|
+
case 19:
|
|
678
|
+
_l.trys.push([19, , 22, 23]);
|
|
679
|
+
if (!(!_k && !_d && (_e = items_2.return))) return [3 /*break*/, 21];
|
|
680
|
+
return [4 /*yield*/, _e.call(items_2)];
|
|
681
|
+
case 20:
|
|
682
|
+
_l.sent();
|
|
683
|
+
_l.label = 21;
|
|
684
|
+
case 21: return [3 /*break*/, 23];
|
|
685
|
+
case 22:
|
|
556
686
|
if (e_5) throw e_5.error;
|
|
557
687
|
return [7 /*endfinally*/];
|
|
558
|
-
case
|
|
559
|
-
case
|
|
560
|
-
case
|
|
561
|
-
|
|
562
|
-
|
|
688
|
+
case 23: return [7 /*endfinally*/];
|
|
689
|
+
case 24: return [3 /*break*/, 26];
|
|
690
|
+
case 25:
|
|
691
|
+
_g = true;
|
|
692
|
+
return [7 /*endfinally*/];
|
|
693
|
+
case 26: return [3 /*break*/, 2];
|
|
694
|
+
case 27: return [3 /*break*/, 34];
|
|
695
|
+
case 28:
|
|
696
|
+
e_4_1 = _l.sent();
|
|
563
697
|
e_4 = { error: e_4_1 };
|
|
564
|
-
return [3 /*break*/,
|
|
565
|
-
case
|
|
566
|
-
|
|
567
|
-
if (!(
|
|
568
|
-
return [4 /*yield*/,
|
|
569
|
-
case
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
case
|
|
573
|
-
case
|
|
698
|
+
return [3 /*break*/, 34];
|
|
699
|
+
case 29:
|
|
700
|
+
_l.trys.push([29, , 32, 33]);
|
|
701
|
+
if (!(!_g && !_a && (_b = _h.return))) return [3 /*break*/, 31];
|
|
702
|
+
return [4 /*yield*/, _b.call(_h)];
|
|
703
|
+
case 30:
|
|
704
|
+
_l.sent();
|
|
705
|
+
_l.label = 31;
|
|
706
|
+
case 31: return [3 /*break*/, 33];
|
|
707
|
+
case 32:
|
|
574
708
|
if (e_4) throw e_4.error;
|
|
575
709
|
return [7 /*endfinally*/];
|
|
576
|
-
case
|
|
577
|
-
case
|
|
710
|
+
case 33: return [7 /*endfinally*/];
|
|
711
|
+
case 34: return [2 /*return*/];
|
|
578
712
|
}
|
|
579
713
|
});
|
|
580
714
|
});
|
|
@@ -697,8 +831,8 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
697
831
|
finally { if (e_6) throw e_6.error; }
|
|
698
832
|
}
|
|
699
833
|
var store = transaction.objectStore(storeName);
|
|
700
|
-
var
|
|
701
|
-
var e_8,
|
|
834
|
+
var _loop_3 = function (name_1) {
|
|
835
|
+
var e_8, _e;
|
|
702
836
|
var idx = store.index(name_1);
|
|
703
837
|
var keypath = Array.isArray(idx.keyPath) ? idx.keyPath : [idx.keyPath];
|
|
704
838
|
var matchingPredicateValues = [];
|
|
@@ -717,7 +851,7 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
717
851
|
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
718
852
|
finally {
|
|
719
853
|
try {
|
|
720
|
-
if (keypath_1_1 && !keypath_1_1.done && (
|
|
854
|
+
if (keypath_1_1 && !keypath_1_1.done && (_e = keypath_1.return)) _e.call(keypath_1);
|
|
721
855
|
}
|
|
722
856
|
finally { if (e_8) throw e_8.error; }
|
|
723
857
|
}
|
|
@@ -738,7 +872,7 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
738
872
|
try {
|
|
739
873
|
for (var _c = __values(store.indexNames), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
740
874
|
var name_1 = _d.value;
|
|
741
|
-
|
|
875
|
+
_loop_3(name_1);
|
|
742
876
|
}
|
|
743
877
|
}
|
|
744
878
|
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
@@ -788,7 +922,7 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
788
922
|
.map(function (o) {
|
|
789
923
|
return _this.matchingIndexQueries(storeName, [o], txn);
|
|
790
924
|
});
|
|
791
|
-
indexedQueries =
|
|
925
|
+
indexedQueries = __spreadArray(__spreadArray([], __read(groupQueries), false), __read(objectQueries), false).map(function (q) { return q[0]; })
|
|
792
926
|
.filter(function (i) { return i; });
|
|
793
927
|
// if, after hunting for base queries, we don't have exactly 1 base query
|
|
794
928
|
// for each child group + object, stop trying to optimize. we're not dealing
|
|
@@ -969,4 +1103,3 @@ var IndexedDBAdapter = /** @class */ (function (_super) {
|
|
|
969
1103
|
return IndexedDBAdapter;
|
|
970
1104
|
}(StorageAdapterBase));
|
|
971
1105
|
export default new IndexedDBAdapter();
|
|
972
|
-
//# sourceMappingURL=IndexedDBAdapter.js.map
|