@aws-amplify/datastore 3.14.4 → 3.14.5-unstable.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -8
- package/lib/authModeStrategies/defaultAuthStrategy.d.ts +2 -0
- package/lib/authModeStrategies/index.d.ts +2 -0
- package/lib/authModeStrategies/multiAuthStrategy.d.ts +13 -0
- package/lib/authModeStrategies/multiAuthStrategy.js +6 -64
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.d.ts +207 -0
- package/lib/datastore/datastore.js +703 -297
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/index.d.ts +16 -0
- package/lib/index.js +6 -4
- package/lib/index.js.map +1 -1
- package/lib/predicates/index.d.ts +30 -0
- package/lib/predicates/index.js +127 -6
- package/lib/predicates/index.js.map +1 -1
- package/lib/predicates/next.d.ts +301 -0
- package/lib/predicates/next.js +816 -0
- package/lib/predicates/next.js.map +1 -0
- package/lib/predicates/sort.d.ts +8 -0
- package/lib/predicates/sort.js +10 -4
- package/lib/predicates/sort.js.map +1 -1
- package/lib/ssr/index.d.ts +3 -0
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +42 -0
- package/lib/storage/adapter/AsyncStorageAdapter.js +141 -382
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.d.ts +39 -0
- package/lib/storage/adapter/AsyncStorageDatabase.js +37 -98
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.d.ts +11 -0
- package/lib/storage/adapter/InMemoryStore.js +16 -67
- package/lib/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.native.d.ts +1 -0
- package/lib/storage/adapter/InMemoryStore.native.js +2 -4
- package/lib/storage/adapter/InMemoryStore.native.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.d.ts +61 -0
- package/lib/storage/adapter/IndexedDBAdapter.js +275 -419
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.d.ts +3 -0
- package/lib/storage/adapter/getDefaultAdapter/index.js +3 -5
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.d.ts +3 -0
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +2 -4
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +1 -1
- package/lib/storage/adapter/index.d.ts +9 -0
- package/lib/storage/relationship.d.ts +140 -0
- package/lib/storage/relationship.js +335 -0
- package/lib/storage/relationship.js.map +1 -0
- package/lib/storage/storage.d.ts +50 -0
- package/lib/storage/storage.js +72 -143
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.d.ts +16 -0
- package/lib/sync/datastoreConnectivity.js +6 -55
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/datastoreReachability/index.d.ts +3 -0
- package/lib/sync/datastoreReachability/index.native.d.ts +3 -0
- package/lib/sync/datastoreReachability/index.native.js +2 -4
- package/lib/sync/datastoreReachability/index.native.js.map +1 -1
- package/lib/sync/index.d.ts +89 -0
- package/lib/sync/index.js +49 -124
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.d.ts +17 -0
- package/lib/sync/merger.js +8 -74
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.d.ts +27 -0
- package/lib/sync/outbox.js +24 -97
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/errorMaps.d.ts +17 -0
- package/lib/sync/processors/errorMaps.js +5 -35
- package/lib/sync/processors/errorMaps.js.map +1 -1
- package/lib/sync/processors/mutation.d.ts +58 -0
- package/lib/sync/processors/mutation.js +47 -131
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.d.ts +33 -0
- package/lib/sync/processors/subscription.js +29 -102
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.d.ts +28 -0
- package/lib/sync/processors/sync.js +26 -102
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.d.ts +42 -0
- package/lib/sync/utils.js +40 -103
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.d.ts +554 -0
- package/lib/types.js +9 -39
- package/lib/types.js.map +1 -1
- package/lib/util.d.ts +189 -0
- package/lib/util.js +192 -188
- package/lib/util.js.map +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +2 -57
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +59 -8
- package/lib-esm/datastore/datastore.js +642 -234
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/index.d.ts +3 -2
- package/lib-esm/index.js +2 -1
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/predicates/index.d.ts +16 -2
- package/lib-esm/predicates/index.js +128 -7
- package/lib-esm/predicates/index.js.map +1 -1
- package/lib-esm/predicates/next.d.ts +301 -0
- package/lib-esm/predicates/next.js +812 -0
- package/lib-esm/predicates/next.js.map +1 -0
- package/lib-esm/predicates/sort.js +10 -4
- package/lib-esm/predicates/sort.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.d.ts +2 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +112 -350
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +7 -68
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.d.ts +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.js +1 -52
- package/lib-esm/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +4 -2
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +230 -367
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib-esm/storage/relationship.d.ts +140 -0
- package/lib-esm/storage/relationship.js +333 -0
- package/lib-esm/storage/relationship.js.map +1 -0
- package/lib-esm/storage/storage.d.ts +7 -6
- package/lib-esm/storage/storage.js +33 -101
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +1 -47
- package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
- package/lib-esm/sync/index.js +4 -76
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.js +1 -67
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.js +1 -74
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.js +2 -32
- package/lib-esm/sync/processors/errorMaps.js.map +1 -1
- package/lib-esm/sync/processors/mutation.js +12 -93
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.js +6 -69
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.js +2 -75
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.d.ts +1 -1
- package/lib-esm/sync/utils.js +32 -95
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +63 -10
- package/lib-esm/types.js +7 -38
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +39 -6
- package/lib-esm/util.js +171 -171
- package/lib-esm/util.js.map +1 -1
- package/package.json +21 -14
- package/src/authModeStrategies/multiAuthStrategy.ts +2 -2
- package/src/datastore/datastore.ts +699 -206
- package/src/index.ts +4 -0
- package/src/predicates/index.ts +143 -17
- package/src/predicates/next.ts +967 -0
- package/src/predicates/sort.ts +8 -2
- package/src/storage/adapter/AsyncStorageAdapter.ts +59 -181
- package/src/storage/adapter/AsyncStorageDatabase.ts +16 -15
- package/src/storage/adapter/InMemoryStore.ts +5 -2
- package/src/storage/adapter/IndexedDBAdapter.ts +169 -192
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -2
- package/src/storage/relationship.ts +272 -0
- package/src/storage/storage.ts +56 -37
- package/src/sync/datastoreConnectivity.ts +4 -4
- package/src/sync/index.ts +22 -28
- package/src/sync/merger.ts +1 -1
- package/src/sync/outbox.ts +6 -6
- package/src/sync/processors/errorMaps.ts +1 -1
- package/src/sync/processors/mutation.ts +23 -19
- package/src/sync/processors/subscription.ts +20 -16
- package/src/sync/processors/sync.ts +17 -17
- package/src/sync/utils.ts +42 -48
- package/src/types.ts +128 -16
- package/src/util.ts +108 -150
- package/build.js +0 -5
- package/dist/aws-amplify-datastore.js +0 -92787
- package/dist/aws-amplify-datastore.js.map +0 -1
- package/dist/aws-amplify-datastore.min.js +0 -66
- package/dist/aws-amplify-datastore.min.js.map +0 -1
- package/index.js +0 -7
- package/webpack.config.dev.js +0 -6
|
@@ -1,88 +1,8 @@
|
|
|
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 (_) 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 __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
39
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
40
|
-
var m = o[Symbol.asyncIterator], i;
|
|
41
|
-
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);
|
|
42
|
-
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); }); }; }
|
|
43
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
44
|
-
};
|
|
45
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
46
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
47
|
-
if (!m) return o;
|
|
48
|
-
var i = m.call(o), r, ar = [], e;
|
|
49
|
-
try {
|
|
50
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
51
|
-
}
|
|
52
|
-
catch (error) { e = { error: error }; }
|
|
53
|
-
finally {
|
|
54
|
-
try {
|
|
55
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
56
|
-
}
|
|
57
|
-
finally { if (e) throw e.error; }
|
|
58
|
-
}
|
|
59
|
-
return ar;
|
|
60
|
-
};
|
|
61
|
-
var __values = (this && this.__values) || function(o) {
|
|
62
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
63
|
-
if (m) return m.call(o);
|
|
64
|
-
if (o && typeof o.length === "number") return {
|
|
65
|
-
next: function () {
|
|
66
|
-
if (o && i >= o.length) o = void 0;
|
|
67
|
-
return { value: o && o[i++], done: !o };
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
71
|
-
};
|
|
72
|
-
var __spread = (this && this.__spread) || function () {
|
|
73
|
-
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
74
|
-
return ar;
|
|
75
|
-
};
|
|
76
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
77
|
-
if (mod && mod.__esModule) return mod;
|
|
78
|
-
var result = {};
|
|
79
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
80
|
-
result["default"] = mod;
|
|
81
|
-
return result;
|
|
82
|
-
};
|
|
83
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
84
4
|
var core_1 = require("@aws-amplify/core");
|
|
85
|
-
var idb = __importStar(require("idb"));
|
|
5
|
+
var idb = tslib_1.__importStar(require("idb"));
|
|
86
6
|
var predicates_1 = require("../../predicates");
|
|
87
7
|
var types_1 = require("../../types");
|
|
88
8
|
var util_1 = require("../../util");
|
|
@@ -122,9 +42,9 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
122
42
|
return util_1.extractPrimaryKeyValues(model, keys);
|
|
123
43
|
};
|
|
124
44
|
IndexedDBAdapter.prototype.checkPrivate = function () {
|
|
125
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
126
46
|
var isPrivate;
|
|
127
|
-
return __generator(this, function (_a) {
|
|
47
|
+
return tslib_1.__generator(this, function (_a) {
|
|
128
48
|
switch (_a.label) {
|
|
129
49
|
case 0: return [4 /*yield*/, util_1.isPrivateMode().then(function (isPrivate) {
|
|
130
50
|
return isPrivate;
|
|
@@ -154,9 +74,9 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
154
74
|
* https://github.com/aws-amplify/amplify-js/pull/10527
|
|
155
75
|
*/
|
|
156
76
|
IndexedDBAdapter.prototype.setSafariCompatabilityMode = function () {
|
|
157
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
158
78
|
var _a;
|
|
159
|
-
return __generator(this, function (_b) {
|
|
79
|
+
return tslib_1.__generator(this, function (_b) {
|
|
160
80
|
switch (_b.label) {
|
|
161
81
|
case 0:
|
|
162
82
|
_a = this;
|
|
@@ -172,17 +92,17 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
172
92
|
});
|
|
173
93
|
};
|
|
174
94
|
IndexedDBAdapter.prototype.getNamespaceAndModelFromStorename = function (storeName) {
|
|
175
|
-
var _a = __read(storeName.split('_')), namespaceName = _a[0], modelNameArr = _a.slice(1);
|
|
95
|
+
var _a = tslib_1.__read(storeName.split('_')), namespaceName = _a[0], modelNameArr = _a.slice(1);
|
|
176
96
|
return {
|
|
177
97
|
namespaceName: namespaceName,
|
|
178
98
|
modelName: modelNameArr.join('_'),
|
|
179
99
|
};
|
|
180
100
|
};
|
|
181
101
|
IndexedDBAdapter.prototype.setUp = function (theSchema, namespaceResolver, modelInstanceCreator, getModelConstructorByModelName, sessionId) {
|
|
182
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
183
103
|
var VERSION, _a, error_1;
|
|
184
104
|
var _this = this;
|
|
185
|
-
return __generator(this, function (_b) {
|
|
105
|
+
return tslib_1.__generator(this, function (_b) {
|
|
186
106
|
switch (_b.label) {
|
|
187
107
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
188
108
|
case 1:
|
|
@@ -215,11 +135,11 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
215
135
|
VERSION = 3;
|
|
216
136
|
_a = this;
|
|
217
137
|
return [4 /*yield*/, idb.openDB(this.dbName, VERSION, {
|
|
218
|
-
upgrade: function (db, oldVersion, newVersion, txn) { return __awaiter(_this, void 0, void 0, function () {
|
|
138
|
+
upgrade: function (db, oldVersion, newVersion, txn) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
219
139
|
var _a, _b, storeName, origStore, tmpName, _c, namespaceName, modelName, newStore, cursor, count, e_1_1, error_2;
|
|
220
140
|
var e_1, _d;
|
|
221
141
|
var _this = this;
|
|
222
|
-
return __generator(this, function (_e) {
|
|
142
|
+
return tslib_1.__generator(this, function (_e) {
|
|
223
143
|
switch (_e.label) {
|
|
224
144
|
case 0:
|
|
225
145
|
if (oldVersion === 0) {
|
|
@@ -239,7 +159,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
239
159
|
_e.label = 2;
|
|
240
160
|
case 2:
|
|
241
161
|
_e.trys.push([2, 11, 12, 13]);
|
|
242
|
-
_a = __values(txn.objectStoreNames), _b = _a.next();
|
|
162
|
+
_a = tslib_1.__values(txn.objectStoreNames), _b = _a.next();
|
|
243
163
|
_e.label = 3;
|
|
244
164
|
case 3:
|
|
245
165
|
if (!!_b.done) return [3 /*break*/, 10];
|
|
@@ -300,11 +220,11 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
300
220
|
];
|
|
301
221
|
})
|
|
302
222
|
.filter(function (_a) {
|
|
303
|
-
var _b = __read(_a, 2), storeName = _b[1];
|
|
223
|
+
var _b = tslib_1.__read(_a, 2), storeName = _b[1];
|
|
304
224
|
return !objectStoreNames.has(storeName);
|
|
305
225
|
})
|
|
306
226
|
.forEach(function (_a) {
|
|
307
|
-
var _b = __read(_a, 2), modelName = _b[0], storeName = _b[1];
|
|
227
|
+
var _b = tslib_1.__read(_a, 2), modelName = _b[0], storeName = _b[1];
|
|
308
228
|
_this.createObjectStoreForModel(db, namespaceName, storeName, modelName);
|
|
309
229
|
});
|
|
310
230
|
});
|
|
@@ -335,9 +255,9 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
335
255
|
});
|
|
336
256
|
};
|
|
337
257
|
IndexedDBAdapter.prototype._get = function (storeOrStoreName, keyArr) {
|
|
338
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
339
259
|
var index, storeName, store, result;
|
|
340
|
-
return __generator(this, function (_a) {
|
|
260
|
+
return tslib_1.__generator(this, function (_a) {
|
|
341
261
|
switch (_a.label) {
|
|
342
262
|
case 0:
|
|
343
263
|
if (typeof storeOrStoreName === 'string') {
|
|
@@ -358,14 +278,14 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
358
278
|
};
|
|
359
279
|
IndexedDBAdapter.prototype.save = function (model, condition) {
|
|
360
280
|
var e_2, _a;
|
|
361
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
362
|
-
var modelConstructor, storeName, namespaceName, connectedModels, set, connectionStoreNames, tx, store, keyValues, fromDB, predicates, predicateObjs, type, isValid, msg, result, connectionStoreNames_1, connectionStoreNames_1_1, resItem, storeName_1, item, instance, keys, store_1, itemKeyValues, fromDB_1, opType, modelKeyValues, key, e_2_1;
|
|
281
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
282
|
+
var modelConstructor, storeName, namespaceName, connectedModels, set, connectionStoreNames, tx, store, keyValues, fromDB, predicates, _b, predicateObjs, type, isValid, msg, result, connectionStoreNames_1, connectionStoreNames_1_1, resItem, storeName_1, item, instance, keys, store_1, itemKeyValues, fromDB_1, opType, modelKeyValues, key, e_2_1;
|
|
363
283
|
var _this = this;
|
|
364
|
-
return __generator(this, function (
|
|
365
|
-
switch (
|
|
284
|
+
return tslib_1.__generator(this, function (_c) {
|
|
285
|
+
switch (_c.label) {
|
|
366
286
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
367
287
|
case 1:
|
|
368
|
-
|
|
288
|
+
_c.sent();
|
|
369
289
|
modelConstructor = Object.getPrototypeOf(model)
|
|
370
290
|
.constructor;
|
|
371
291
|
storeName = this.getStorenameForModel(modelConstructor);
|
|
@@ -379,15 +299,15 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
379
299
|
var keys = util_1.getIndexKeys(_this.schema.namespaces[namespaceName], modelName);
|
|
380
300
|
return { storeName: storeName, item: item, instance: instance, keys: keys };
|
|
381
301
|
});
|
|
382
|
-
tx = this.db.transaction(__spread([storeName], Array.from(set.values())), 'readwrite');
|
|
302
|
+
tx = this.db.transaction(tslib_1.__spread([storeName], Array.from(set.values())), 'readwrite');
|
|
383
303
|
store = tx.objectStore(storeName);
|
|
384
304
|
keyValues = this.getIndexKeyValuesFromModel(model);
|
|
385
305
|
return [4 /*yield*/, this._get(store, keyValues)];
|
|
386
306
|
case 2:
|
|
387
|
-
fromDB =
|
|
307
|
+
fromDB = _c.sent();
|
|
388
308
|
if (condition && fromDB) {
|
|
389
309
|
predicates = predicates_1.ModelPredicateCreator.getPredicates(condition);
|
|
390
|
-
predicateObjs =
|
|
310
|
+
_b = predicates || {}, predicateObjs = _b.predicates, type = _b.type;
|
|
391
311
|
isValid = util_1.validatePredicate(fromDB, type, predicateObjs);
|
|
392
312
|
if (!isValid) {
|
|
393
313
|
msg = 'Conditional update failed';
|
|
@@ -396,14 +316,14 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
396
316
|
}
|
|
397
317
|
}
|
|
398
318
|
result = [];
|
|
399
|
-
|
|
319
|
+
_c.label = 3;
|
|
400
320
|
case 3:
|
|
401
|
-
|
|
402
|
-
connectionStoreNames_1 = __asyncValues(connectionStoreNames);
|
|
403
|
-
|
|
321
|
+
_c.trys.push([3, 11, 12, 17]);
|
|
322
|
+
connectionStoreNames_1 = tslib_1.__asyncValues(connectionStoreNames);
|
|
323
|
+
_c.label = 4;
|
|
404
324
|
case 4: return [4 /*yield*/, connectionStoreNames_1.next()];
|
|
405
325
|
case 5:
|
|
406
|
-
if (!(connectionStoreNames_1_1 =
|
|
326
|
+
if (!(connectionStoreNames_1_1 = _c.sent(), !connectionStoreNames_1_1.done)) return [3 /*break*/, 10];
|
|
407
327
|
resItem = connectionStoreNames_1_1.value;
|
|
408
328
|
storeName_1 = resItem.storeName, item = resItem.item, instance = resItem.instance, keys = resItem.keys;
|
|
409
329
|
store_1 = tx.objectStore(storeName_1);
|
|
@@ -413,7 +333,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
413
333
|
});
|
|
414
334
|
return [4 /*yield*/, this._get(store_1, itemKeyValues)];
|
|
415
335
|
case 6:
|
|
416
|
-
fromDB_1 =
|
|
336
|
+
fromDB_1 = _c.sent();
|
|
417
337
|
opType = fromDB_1 === undefined ? types_1.OpType.INSERT : types_1.OpType.UPDATE;
|
|
418
338
|
modelKeyValues = this.getIndexKeyValuesFromModel(model);
|
|
419
339
|
if (!(util_1.keysEqual(itemKeyValues, modelKeyValues) ||
|
|
@@ -422,25 +342,25 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
422
342
|
.index('byPk')
|
|
423
343
|
.getKey(this.canonicalKeyPath(itemKeyValues))];
|
|
424
344
|
case 7:
|
|
425
|
-
key =
|
|
345
|
+
key = _c.sent();
|
|
426
346
|
return [4 /*yield*/, store_1.put(item, key)];
|
|
427
347
|
case 8:
|
|
428
|
-
|
|
348
|
+
_c.sent();
|
|
429
349
|
result.push([instance, opType]);
|
|
430
|
-
|
|
350
|
+
_c.label = 9;
|
|
431
351
|
case 9: return [3 /*break*/, 4];
|
|
432
352
|
case 10: return [3 /*break*/, 17];
|
|
433
353
|
case 11:
|
|
434
|
-
e_2_1 =
|
|
354
|
+
e_2_1 = _c.sent();
|
|
435
355
|
e_2 = { error: e_2_1 };
|
|
436
356
|
return [3 /*break*/, 17];
|
|
437
357
|
case 12:
|
|
438
|
-
|
|
358
|
+
_c.trys.push([12, , 15, 16]);
|
|
439
359
|
if (!(connectionStoreNames_1_1 && !connectionStoreNames_1_1.done && (_a = connectionStoreNames_1.return))) return [3 /*break*/, 14];
|
|
440
360
|
return [4 /*yield*/, _a.call(connectionStoreNames_1)];
|
|
441
361
|
case 13:
|
|
442
|
-
|
|
443
|
-
|
|
362
|
+
_c.sent();
|
|
363
|
+
_c.label = 14;
|
|
444
364
|
case 14: return [3 /*break*/, 16];
|
|
445
365
|
case 15:
|
|
446
366
|
if (e_2) throw e_2.error;
|
|
@@ -448,211 +368,40 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
448
368
|
case 16: return [7 /*endfinally*/];
|
|
449
369
|
case 17: return [4 /*yield*/, tx.done];
|
|
450
370
|
case 18:
|
|
451
|
-
|
|
371
|
+
_c.sent();
|
|
452
372
|
return [2 /*return*/, result];
|
|
453
373
|
}
|
|
454
374
|
});
|
|
455
375
|
});
|
|
456
376
|
};
|
|
457
377
|
IndexedDBAdapter.prototype.load = function (namespaceName, srcModelName, records) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
461
|
-
var namespace, relations, connectionStoreNames, modelConstructor, tx, relations_1, relations_1_1, relation, fieldName, modelName, targetName, targetNames, storeName, store, modelConstructor_1, _d, recordItem, getByFields, allPresent, keys, connectionRecord, getByfield, key, connectionRecord, e_4_1, recordItem, allPresent, keys, connectionRecord, key, connectionRecord, e_5_1, e_3_1;
|
|
378
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
379
|
+
var namespace, relations, connectionStoreNames, modelConstructor;
|
|
462
380
|
var _this = this;
|
|
463
|
-
return __generator(this, function (
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
if (connectionStoreNames.length === 0) {
|
|
474
|
-
return [2 /*return*/, records.map(function (record) {
|
|
475
|
-
return _this.modelInstanceCreator(modelConstructor, record);
|
|
476
|
-
})];
|
|
477
|
-
}
|
|
478
|
-
tx = this.db.transaction(__spread(connectionStoreNames), 'readonly');
|
|
479
|
-
_e.label = 1;
|
|
480
|
-
case 1:
|
|
481
|
-
_e.trys.push([1, 38, 39, 44]);
|
|
482
|
-
relations_1 = __asyncValues(relations);
|
|
483
|
-
_e.label = 2;
|
|
484
|
-
case 2: return [4 /*yield*/, relations_1.next()];
|
|
485
|
-
case 3:
|
|
486
|
-
if (!(relations_1_1 = _e.sent(), !relations_1_1.done)) return [3 /*break*/, 37];
|
|
487
|
-
relation = relations_1_1.value;
|
|
488
|
-
fieldName = relation.fieldName, modelName = relation.modelName, targetName = relation.targetName, targetNames = relation.targetNames;
|
|
489
|
-
storeName = util_1.getStorename(namespaceName, modelName);
|
|
490
|
-
store = tx.objectStore(storeName);
|
|
491
|
-
modelConstructor_1 = this.getModelConstructorByModelName(namespaceName, modelName);
|
|
492
|
-
_d = relation.relationType;
|
|
493
|
-
switch (_d) {
|
|
494
|
-
case 'HAS_ONE': return [3 /*break*/, 4];
|
|
495
|
-
case 'BELONGS_TO': return [3 /*break*/, 19];
|
|
496
|
-
case 'HAS_MANY': return [3 /*break*/, 34];
|
|
497
|
-
}
|
|
498
|
-
return [3 /*break*/, 35];
|
|
499
|
-
case 4:
|
|
500
|
-
_e.trys.push([4, 12, 13, 18]);
|
|
501
|
-
records_1 = __asyncValues(records);
|
|
502
|
-
_e.label = 5;
|
|
503
|
-
case 5: return [4 /*yield*/, records_1.next()];
|
|
504
|
-
case 6:
|
|
505
|
-
if (!(records_1_1 = _e.sent(), !records_1_1.done)) return [3 /*break*/, 11];
|
|
506
|
-
recordItem = records_1_1.value;
|
|
507
|
-
if (!(targetNames === null || targetNames === void 0 ? void 0 : targetNames.length)) return [3 /*break*/, 8];
|
|
508
|
-
getByFields = [];
|
|
509
|
-
allPresent = void 0;
|
|
510
|
-
// iterate through all targetnames to make sure they are all present in the recordItem
|
|
511
|
-
allPresent = targetNames.every(function (targetName) {
|
|
512
|
-
return recordItem[targetName] != null;
|
|
513
|
-
});
|
|
514
|
-
if (!allPresent) {
|
|
515
|
-
return [3 /*break*/, 11];
|
|
516
|
-
}
|
|
517
|
-
getByFields = targetNames;
|
|
518
|
-
keys = getByFields.map(function (getByField) { return recordItem[getByField]; });
|
|
519
|
-
return [4 /*yield*/, this._get(store, keys)];
|
|
520
|
-
case 7:
|
|
521
|
-
connectionRecord = _e.sent();
|
|
522
|
-
recordItem[fieldName] =
|
|
523
|
-
connectionRecord &&
|
|
524
|
-
this.modelInstanceCreator(modelConstructor_1, connectionRecord);
|
|
525
|
-
return [3 /*break*/, 10];
|
|
526
|
-
case 8:
|
|
527
|
-
getByfield = recordItem[targetName]
|
|
528
|
-
? targetName
|
|
529
|
-
: fieldName;
|
|
530
|
-
// We break here, because the recordItem does not have 'team', the `getByField`
|
|
531
|
-
// extract the keys on the related model.
|
|
532
|
-
if (!recordItem[getByfield])
|
|
533
|
-
return [3 /*break*/, 11];
|
|
534
|
-
key = [recordItem[getByfield]];
|
|
535
|
-
return [4 /*yield*/, this._get(store, key)];
|
|
536
|
-
case 9:
|
|
537
|
-
connectionRecord = _e.sent();
|
|
538
|
-
recordItem[fieldName] =
|
|
539
|
-
connectionRecord &&
|
|
540
|
-
this.modelInstanceCreator(modelConstructor_1, connectionRecord);
|
|
541
|
-
_e.label = 10;
|
|
542
|
-
case 10: return [3 /*break*/, 5];
|
|
543
|
-
case 11: return [3 /*break*/, 18];
|
|
544
|
-
case 12:
|
|
545
|
-
e_4_1 = _e.sent();
|
|
546
|
-
e_4 = { error: e_4_1 };
|
|
547
|
-
return [3 /*break*/, 18];
|
|
548
|
-
case 13:
|
|
549
|
-
_e.trys.push([13, , 16, 17]);
|
|
550
|
-
if (!(records_1_1 && !records_1_1.done && (_b = records_1.return))) return [3 /*break*/, 15];
|
|
551
|
-
return [4 /*yield*/, _b.call(records_1)];
|
|
552
|
-
case 14:
|
|
553
|
-
_e.sent();
|
|
554
|
-
_e.label = 15;
|
|
555
|
-
case 15: return [3 /*break*/, 17];
|
|
556
|
-
case 16:
|
|
557
|
-
if (e_4) throw e_4.error;
|
|
558
|
-
return [7 /*endfinally*/];
|
|
559
|
-
case 17: return [7 /*endfinally*/];
|
|
560
|
-
case 18: return [3 /*break*/, 36];
|
|
561
|
-
case 19:
|
|
562
|
-
_e.trys.push([19, 27, 28, 33]);
|
|
563
|
-
records_2 = __asyncValues(records);
|
|
564
|
-
_e.label = 20;
|
|
565
|
-
case 20: return [4 /*yield*/, records_2.next()];
|
|
566
|
-
case 21:
|
|
567
|
-
if (!(records_2_1 = _e.sent(), !records_2_1.done)) return [3 /*break*/, 26];
|
|
568
|
-
recordItem = records_2_1.value;
|
|
569
|
-
if (!(targetNames === null || targetNames === void 0 ? void 0 : targetNames.length)) return [3 /*break*/, 23];
|
|
570
|
-
allPresent = void 0;
|
|
571
|
-
// iterate through all targetnames to make sure they are all present in the recordItem
|
|
572
|
-
allPresent = targetNames.every(function (targetName) {
|
|
573
|
-
return recordItem[targetName] != null;
|
|
574
|
-
});
|
|
575
|
-
// If not present, there is not yet a connected record
|
|
576
|
-
if (!allPresent) {
|
|
577
|
-
return [3 /*break*/, 26];
|
|
578
|
-
}
|
|
579
|
-
keys = targetNames.map(function (targetName) { return recordItem[targetName]; });
|
|
580
|
-
return [4 /*yield*/, this._get(store, keys)];
|
|
581
|
-
case 22:
|
|
582
|
-
connectionRecord = _e.sent();
|
|
583
|
-
recordItem[fieldName] =
|
|
584
|
-
connectionRecord &&
|
|
585
|
-
this.modelInstanceCreator(modelConstructor_1, connectionRecord);
|
|
586
|
-
targetNames === null || targetNames === void 0 ? void 0 : targetNames.map(function (targetName) {
|
|
587
|
-
delete recordItem[targetName];
|
|
588
|
-
});
|
|
589
|
-
return [3 /*break*/, 25];
|
|
590
|
-
case 23:
|
|
591
|
-
if (!recordItem[targetName]) return [3 /*break*/, 25];
|
|
592
|
-
key = [recordItem[targetName]];
|
|
593
|
-
return [4 /*yield*/, this._get(store, key)];
|
|
594
|
-
case 24:
|
|
595
|
-
connectionRecord = _e.sent();
|
|
596
|
-
recordItem[fieldName] =
|
|
597
|
-
connectionRecord &&
|
|
598
|
-
this.modelInstanceCreator(modelConstructor_1, connectionRecord);
|
|
599
|
-
delete recordItem[targetName];
|
|
600
|
-
_e.label = 25;
|
|
601
|
-
case 25: return [3 /*break*/, 20];
|
|
602
|
-
case 26: return [3 /*break*/, 33];
|
|
603
|
-
case 27:
|
|
604
|
-
e_5_1 = _e.sent();
|
|
605
|
-
e_5 = { error: e_5_1 };
|
|
606
|
-
return [3 /*break*/, 33];
|
|
607
|
-
case 28:
|
|
608
|
-
_e.trys.push([28, , 31, 32]);
|
|
609
|
-
if (!(records_2_1 && !records_2_1.done && (_c = records_2.return))) return [3 /*break*/, 30];
|
|
610
|
-
return [4 /*yield*/, _c.call(records_2)];
|
|
611
|
-
case 29:
|
|
612
|
-
_e.sent();
|
|
613
|
-
_e.label = 30;
|
|
614
|
-
case 30: return [3 /*break*/, 32];
|
|
615
|
-
case 31:
|
|
616
|
-
if (e_5) throw e_5.error;
|
|
617
|
-
return [7 /*endfinally*/];
|
|
618
|
-
case 32: return [7 /*endfinally*/];
|
|
619
|
-
case 33: return [3 /*break*/, 36];
|
|
620
|
-
case 34:
|
|
621
|
-
// TODO: Lazy loading
|
|
622
|
-
return [3 /*break*/, 36];
|
|
623
|
-
case 35:
|
|
624
|
-
util_1.exhaustiveCheck(relation.relationType);
|
|
625
|
-
return [3 /*break*/, 36];
|
|
626
|
-
case 36: return [3 /*break*/, 2];
|
|
627
|
-
case 37: return [3 /*break*/, 44];
|
|
628
|
-
case 38:
|
|
629
|
-
e_3_1 = _e.sent();
|
|
630
|
-
e_3 = { error: e_3_1 };
|
|
631
|
-
return [3 /*break*/, 44];
|
|
632
|
-
case 39:
|
|
633
|
-
_e.trys.push([39, , 42, 43]);
|
|
634
|
-
if (!(relations_1_1 && !relations_1_1.done && (_a = relations_1.return))) return [3 /*break*/, 41];
|
|
635
|
-
return [4 /*yield*/, _a.call(relations_1)];
|
|
636
|
-
case 40:
|
|
637
|
-
_e.sent();
|
|
638
|
-
_e.label = 41;
|
|
639
|
-
case 41: return [3 /*break*/, 43];
|
|
640
|
-
case 42:
|
|
641
|
-
if (e_3) throw e_3.error;
|
|
642
|
-
return [7 /*endfinally*/];
|
|
643
|
-
case 43: return [7 /*endfinally*/];
|
|
644
|
-
case 44: return [2 /*return*/, records.map(function (record) {
|
|
381
|
+
return tslib_1.__generator(this, function (_a) {
|
|
382
|
+
namespace = this.schema.namespaces[namespaceName];
|
|
383
|
+
relations = namespace.relationships[srcModelName].relationTypes;
|
|
384
|
+
connectionStoreNames = relations.map(function (_a) {
|
|
385
|
+
var modelName = _a.modelName;
|
|
386
|
+
return util_1.getStorename(namespaceName, modelName);
|
|
387
|
+
});
|
|
388
|
+
modelConstructor = this.getModelConstructorByModelName(namespaceName, srcModelName);
|
|
389
|
+
if (connectionStoreNames.length === 0) {
|
|
390
|
+
return [2 /*return*/, records.map(function (record) {
|
|
645
391
|
return _this.modelInstanceCreator(modelConstructor, record);
|
|
646
392
|
})];
|
|
647
393
|
}
|
|
394
|
+
return [2 /*return*/, records.map(function (record) {
|
|
395
|
+
return _this.modelInstanceCreator(modelConstructor, record);
|
|
396
|
+
})];
|
|
648
397
|
});
|
|
649
398
|
});
|
|
650
399
|
};
|
|
651
400
|
IndexedDBAdapter.prototype.query = function (modelConstructor, predicate, pagination) {
|
|
652
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
401
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
653
402
|
var storeName, namespaceName, predicates, keyPath, queryByKey, hasSort, hasPagination, records;
|
|
654
403
|
var _this = this;
|
|
655
|
-
return __generator(this, function (_a) {
|
|
404
|
+
return tslib_1.__generator(this, function (_a) {
|
|
656
405
|
switch (_a.label) {
|
|
657
406
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
658
407
|
case 1:
|
|
@@ -664,9 +413,9 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
664
413
|
queryByKey = predicates && this.keyValueFromPredicate(predicates, keyPath);
|
|
665
414
|
hasSort = pagination && pagination.sort;
|
|
666
415
|
hasPagination = pagination && pagination.limit;
|
|
667
|
-
return [4 /*yield*/, (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
416
|
+
return [4 /*yield*/, (function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
668
417
|
var record, filtered, all;
|
|
669
|
-
return __generator(this, function (_a) {
|
|
418
|
+
return tslib_1.__generator(this, function (_a) {
|
|
670
419
|
switch (_a.label) {
|
|
671
420
|
case 0:
|
|
672
421
|
if (!queryByKey) return [3 /*break*/, 2];
|
|
@@ -695,7 +444,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
695
444
|
});
|
|
696
445
|
}); })()];
|
|
697
446
|
case 2:
|
|
698
|
-
records = _a.sent();
|
|
447
|
+
records = (_a.sent());
|
|
699
448
|
return [4 /*yield*/, this.load(namespaceName, modelConstructor.name, records)];
|
|
700
449
|
case 3: return [2 /*return*/, _a.sent()];
|
|
701
450
|
}
|
|
@@ -703,21 +452,18 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
703
452
|
});
|
|
704
453
|
};
|
|
705
454
|
IndexedDBAdapter.prototype.getByKey = function (storeName, keyValue) {
|
|
706
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
707
|
-
|
|
708
|
-
return __generator(this, function (_a) {
|
|
455
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
456
|
+
return tslib_1.__generator(this, function (_a) {
|
|
709
457
|
switch (_a.label) {
|
|
710
458
|
case 0: return [4 /*yield*/, this._get(storeName, keyValue)];
|
|
711
|
-
case 1:
|
|
712
|
-
record = _a.sent();
|
|
713
|
-
return [2 /*return*/, record];
|
|
459
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
714
460
|
}
|
|
715
461
|
});
|
|
716
462
|
});
|
|
717
463
|
};
|
|
718
464
|
IndexedDBAdapter.prototype.getAll = function (storeName) {
|
|
719
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
720
|
-
return __generator(this, function (_a) {
|
|
465
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
466
|
+
return tslib_1.__generator(this, function (_a) {
|
|
721
467
|
switch (_a.label) {
|
|
722
468
|
case 0: return [4 /*yield*/, this.db.getAll(storeName)];
|
|
723
469
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -726,7 +472,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
726
472
|
});
|
|
727
473
|
};
|
|
728
474
|
IndexedDBAdapter.prototype.keyValueFromPredicate = function (predicates, keyPath) {
|
|
729
|
-
var
|
|
475
|
+
var e_3, _a;
|
|
730
476
|
var predicateObjs = predicates.predicates;
|
|
731
477
|
if (predicateObjs.length !== keyPath.length) {
|
|
732
478
|
return;
|
|
@@ -737,58 +483,169 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
737
483
|
predicateObj && keyValues.push(predicateObj.operand);
|
|
738
484
|
};
|
|
739
485
|
try {
|
|
740
|
-
for (var keyPath_1 = __values(keyPath), keyPath_1_1 = keyPath_1.next(); !keyPath_1_1.done; keyPath_1_1 = keyPath_1.next()) {
|
|
486
|
+
for (var keyPath_1 = tslib_1.__values(keyPath), keyPath_1_1 = keyPath_1.next(); !keyPath_1_1.done; keyPath_1_1 = keyPath_1.next()) {
|
|
741
487
|
var key = keyPath_1_1.value;
|
|
742
488
|
_loop_1(key);
|
|
743
489
|
}
|
|
744
490
|
}
|
|
745
|
-
catch (
|
|
491
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
746
492
|
finally {
|
|
747
493
|
try {
|
|
748
494
|
if (keyPath_1_1 && !keyPath_1_1.done && (_a = keyPath_1.return)) _a.call(keyPath_1);
|
|
749
495
|
}
|
|
750
|
-
finally { if (
|
|
496
|
+
finally { if (e_3) throw e_3.error; }
|
|
751
497
|
}
|
|
752
498
|
return keyValues.length === keyPath.length ? keyValues : undefined;
|
|
753
499
|
};
|
|
500
|
+
IndexedDBAdapter.prototype.matchingIndex = function (storeName, fieldName, transaction) {
|
|
501
|
+
var e_4, _a;
|
|
502
|
+
var store = transaction.objectStore(storeName);
|
|
503
|
+
try {
|
|
504
|
+
for (var _b = tslib_1.__values(store.indexNames), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
505
|
+
var name_1 = _c.value;
|
|
506
|
+
var idx = store.index(name_1);
|
|
507
|
+
if (idx.keyPath === fieldName) {
|
|
508
|
+
return idx;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
513
|
+
finally {
|
|
514
|
+
try {
|
|
515
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
516
|
+
}
|
|
517
|
+
finally { if (e_4) throw e_4.error; }
|
|
518
|
+
}
|
|
519
|
+
};
|
|
754
520
|
IndexedDBAdapter.prototype.filterOnPredicate = function (storeName, predicates) {
|
|
755
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
756
|
-
var predicateObjs, type,
|
|
757
|
-
|
|
758
|
-
|
|
521
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
522
|
+
var predicateObjs, type, candidateResults, fieldPredicates, txn, predicateIndexes, actualPredicateIndexes, predicateIndex, distinctResults, predicateIndexes_1, predicateIndexes_1_1, predicateIndex, resultGroup, resultGroup_1, resultGroup_1_1, item, e_5_1, filtered;
|
|
523
|
+
var e_5, _a, e_6, _b;
|
|
524
|
+
var _this = this;
|
|
525
|
+
return tslib_1.__generator(this, function (_c) {
|
|
526
|
+
switch (_c.label) {
|
|
759
527
|
case 0:
|
|
760
528
|
predicateObjs = predicates.predicates, type = predicates.type;
|
|
761
|
-
|
|
529
|
+
// the predicate objects we care about tend to be nested at least
|
|
530
|
+
// one level down: `{and: {or: {and: { <the predicates we want> }}}}`
|
|
531
|
+
// so, we unpack and/or groups until we find a group with more than 1
|
|
532
|
+
// child OR a child that is not a group (and is therefore a predicate "object").
|
|
533
|
+
while (predicateObjs.length === 1 && types_1.isPredicateGroup(predicateObjs[0])) {
|
|
534
|
+
type = predicateObjs[0].type;
|
|
535
|
+
predicateObjs = predicateObjs[0].predicates;
|
|
536
|
+
}
|
|
537
|
+
fieldPredicates = predicateObjs.filter(function (p) {
|
|
538
|
+
return types_1.isPredicateObj(p);
|
|
539
|
+
});
|
|
540
|
+
txn = this.db.transaction(storeName);
|
|
541
|
+
predicateIndexes = fieldPredicates.map(function (p) {
|
|
542
|
+
return {
|
|
543
|
+
predicate: p,
|
|
544
|
+
index: _this.matchingIndex(storeName, String(p.field), txn),
|
|
545
|
+
};
|
|
546
|
+
});
|
|
547
|
+
// Explicitly wait for txns from index queries to complete before proceding.
|
|
548
|
+
// This helps ensure IndexedDB is in a stable, ready state. Else, subseqeuent
|
|
549
|
+
// qeuries can sometimes appear to deadlock (at least in FakeIndexedDB).
|
|
550
|
+
return [4 /*yield*/, txn.done];
|
|
762
551
|
case 1:
|
|
763
|
-
|
|
552
|
+
// Explicitly wait for txns from index queries to complete before proceding.
|
|
553
|
+
// This helps ensure IndexedDB is in a stable, ready state. Else, subseqeuent
|
|
554
|
+
// qeuries can sometimes appear to deadlock (at least in FakeIndexedDB).
|
|
555
|
+
_c.sent();
|
|
556
|
+
if (!(type === 'and')) return [3 /*break*/, 6];
|
|
557
|
+
actualPredicateIndexes = predicateIndexes.filter(function (i) { return i.index && i.predicate.operator === 'eq'; });
|
|
558
|
+
if (!(actualPredicateIndexes.length > 0)) return [3 /*break*/, 3];
|
|
559
|
+
predicateIndex = actualPredicateIndexes[0];
|
|
560
|
+
return [4 /*yield*/, predicateIndex.index.getAll(predicateIndex.predicate.operand)];
|
|
561
|
+
case 2:
|
|
562
|
+
candidateResults = (_c.sent());
|
|
563
|
+
return [3 /*break*/, 5];
|
|
564
|
+
case 3: return [4 /*yield*/, this.getAll(storeName)];
|
|
565
|
+
case 4:
|
|
566
|
+
// no usable indexes
|
|
567
|
+
candidateResults = (_c.sent());
|
|
568
|
+
_c.label = 5;
|
|
569
|
+
case 5: return [3 /*break*/, 20];
|
|
570
|
+
case 6:
|
|
571
|
+
if (!(type === 'or')) return [3 /*break*/, 18];
|
|
572
|
+
if (!(predicateIndexes.length > 0 &&
|
|
573
|
+
predicateIndexes.every(function (i) { return i.index && i.predicate.operator === 'eq'; }))) return [3 /*break*/, 15];
|
|
574
|
+
distinctResults = new Map();
|
|
575
|
+
_c.label = 7;
|
|
576
|
+
case 7:
|
|
577
|
+
_c.trys.push([7, 12, 13, 14]);
|
|
578
|
+
predicateIndexes_1 = tslib_1.__values(predicateIndexes), predicateIndexes_1_1 = predicateIndexes_1.next();
|
|
579
|
+
_c.label = 8;
|
|
580
|
+
case 8:
|
|
581
|
+
if (!!predicateIndexes_1_1.done) return [3 /*break*/, 11];
|
|
582
|
+
predicateIndex = predicateIndexes_1_1.value;
|
|
583
|
+
return [4 /*yield*/, predicateIndex.index.getAll(predicateIndex.predicate.operand)];
|
|
584
|
+
case 9:
|
|
585
|
+
resultGroup = (_c.sent());
|
|
586
|
+
try {
|
|
587
|
+
for (resultGroup_1 = (e_6 = void 0, tslib_1.__values(resultGroup)), resultGroup_1_1 = resultGroup_1.next(); !resultGroup_1_1.done; resultGroup_1_1 = resultGroup_1.next()) {
|
|
588
|
+
item = resultGroup_1_1.value;
|
|
589
|
+
// TODO: custom PK
|
|
590
|
+
distinctResults.set(item.id, item);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
594
|
+
finally {
|
|
595
|
+
try {
|
|
596
|
+
if (resultGroup_1_1 && !resultGroup_1_1.done && (_b = resultGroup_1.return)) _b.call(resultGroup_1);
|
|
597
|
+
}
|
|
598
|
+
finally { if (e_6) throw e_6.error; }
|
|
599
|
+
}
|
|
600
|
+
_c.label = 10;
|
|
601
|
+
case 10:
|
|
602
|
+
predicateIndexes_1_1 = predicateIndexes_1.next();
|
|
603
|
+
return [3 /*break*/, 8];
|
|
604
|
+
case 11: return [3 /*break*/, 14];
|
|
605
|
+
case 12:
|
|
606
|
+
e_5_1 = _c.sent();
|
|
607
|
+
e_5 = { error: e_5_1 };
|
|
608
|
+
return [3 /*break*/, 14];
|
|
609
|
+
case 13:
|
|
610
|
+
try {
|
|
611
|
+
if (predicateIndexes_1_1 && !predicateIndexes_1_1.done && (_a = predicateIndexes_1.return)) _a.call(predicateIndexes_1);
|
|
612
|
+
}
|
|
613
|
+
finally { if (e_5) throw e_5.error; }
|
|
614
|
+
return [7 /*endfinally*/];
|
|
615
|
+
case 14:
|
|
616
|
+
// we could conceivably check for special conditions and return early here.
|
|
617
|
+
// but, this is simpler and has not yet had a measurable performance impact.
|
|
618
|
+
candidateResults = Array.from(distinctResults.values());
|
|
619
|
+
return [3 /*break*/, 17];
|
|
620
|
+
case 15: return [4 /*yield*/, this.getAll(storeName)];
|
|
621
|
+
case 16:
|
|
622
|
+
// either no usable indexes or not all conditions can use one.
|
|
623
|
+
candidateResults = (_c.sent());
|
|
624
|
+
_c.label = 17;
|
|
625
|
+
case 17: return [3 /*break*/, 20];
|
|
626
|
+
case 18: return [4 /*yield*/, this.getAll(storeName)];
|
|
627
|
+
case 19:
|
|
628
|
+
// nothing intelligent we can do with `not` groups unless or until we start
|
|
629
|
+
// smashing comparison operators against indexes -- at which point we could
|
|
630
|
+
// perform some reversal here.
|
|
631
|
+
candidateResults = (_c.sent());
|
|
632
|
+
_c.label = 20;
|
|
633
|
+
case 20:
|
|
764
634
|
filtered = predicateObjs
|
|
765
|
-
?
|
|
766
|
-
:
|
|
635
|
+
? candidateResults.filter(function (m) { return util_1.validatePredicate(m, type, predicateObjs); })
|
|
636
|
+
: candidateResults;
|
|
767
637
|
return [2 /*return*/, filtered];
|
|
768
638
|
}
|
|
769
639
|
});
|
|
770
640
|
});
|
|
771
641
|
};
|
|
772
642
|
IndexedDBAdapter.prototype.inMemoryPagination = function (records, pagination) {
|
|
773
|
-
|
|
774
|
-
if (pagination.sort) {
|
|
775
|
-
var sortPredicates = predicates_1.ModelSortPredicateCreator.getPredicates(pagination.sort);
|
|
776
|
-
if (sortPredicates.length) {
|
|
777
|
-
var compareFn = util_1.sortCompareFunction(sortPredicates);
|
|
778
|
-
records.sort(compareFn);
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
var _a = pagination.page, page = _a === void 0 ? 0 : _a, _b = pagination.limit, limit = _b === void 0 ? 0 : _b;
|
|
782
|
-
var start = Math.max(0, page * limit) || 0;
|
|
783
|
-
var end = limit > 0 ? start + limit : records.length;
|
|
784
|
-
return records.slice(start, end);
|
|
785
|
-
}
|
|
786
|
-
return records;
|
|
643
|
+
return util_1.inMemoryPagination(records, pagination);
|
|
787
644
|
};
|
|
788
645
|
IndexedDBAdapter.prototype.enginePagination = function (storeName, pagination) {
|
|
789
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
646
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
790
647
|
var result, _a, page, _b, limit, initialRecord, cursor, pageResults, hasLimit;
|
|
791
|
-
return __generator(this, function (_c) {
|
|
648
|
+
return tslib_1.__generator(this, function (_c) {
|
|
792
649
|
switch (_c.label) {
|
|
793
650
|
case 0:
|
|
794
651
|
if (!pagination) return [3 /*break*/, 7];
|
|
@@ -833,9 +690,9 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
833
690
|
};
|
|
834
691
|
IndexedDBAdapter.prototype.queryOne = function (modelConstructor, firstOrLast) {
|
|
835
692
|
if (firstOrLast === void 0) { firstOrLast = types_1.QueryOne.FIRST; }
|
|
836
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
693
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
837
694
|
var storeName, cursor, result;
|
|
838
|
-
return __generator(this, function (_a) {
|
|
695
|
+
return tslib_1.__generator(this, function (_a) {
|
|
839
696
|
switch (_a.label) {
|
|
840
697
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
841
698
|
case 1:
|
|
@@ -854,13 +711,13 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
854
711
|
});
|
|
855
712
|
};
|
|
856
713
|
IndexedDBAdapter.prototype.delete = function (modelOrModelConstructor, condition) {
|
|
857
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
858
|
-
var deleteQueue, modelConstructor, nameSpace, storeName, models, relations, deletedModels, deletedModels, model, modelConstructor, namespaceName, storeName, tx, store, keyValues, fromDB, msg, predicates, predicateObjs, type, isValid, msg, relations, relations, deletedModels;
|
|
859
|
-
return __generator(this, function (
|
|
860
|
-
switch (
|
|
714
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
715
|
+
var deleteQueue, modelConstructor, nameSpace, storeName, models, relations, deletedModels, deletedModels, model, modelConstructor, namespaceName, storeName, tx, store, keyValues, fromDB, msg, predicates, _a, predicateObjs, type, isValid, msg, relations, relations, deletedModels;
|
|
716
|
+
return tslib_1.__generator(this, function (_b) {
|
|
717
|
+
switch (_b.label) {
|
|
861
718
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
862
719
|
case 1:
|
|
863
|
-
|
|
720
|
+
_b.sent();
|
|
864
721
|
deleteQueue = [];
|
|
865
722
|
if (!util_1.isModelConstructor(modelOrModelConstructor)) return [3 /*break*/, 9];
|
|
866
723
|
modelConstructor = modelOrModelConstructor;
|
|
@@ -868,16 +725,16 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
868
725
|
storeName = this.getStorenameForModel(modelConstructor);
|
|
869
726
|
return [4 /*yield*/, this.query(modelConstructor, condition)];
|
|
870
727
|
case 2:
|
|
871
|
-
models =
|
|
728
|
+
models = _b.sent();
|
|
872
729
|
relations = this.schema.namespaces[nameSpace].relationships[modelConstructor.name]
|
|
873
730
|
.relationTypes;
|
|
874
731
|
if (!(condition !== undefined)) return [3 /*break*/, 5];
|
|
875
732
|
return [4 /*yield*/, this.deleteTraverse(relations, models, modelConstructor.name, nameSpace, deleteQueue)];
|
|
876
733
|
case 3:
|
|
877
|
-
|
|
734
|
+
_b.sent();
|
|
878
735
|
return [4 /*yield*/, this.deleteItem(deleteQueue)];
|
|
879
736
|
case 4:
|
|
880
|
-
|
|
737
|
+
_b.sent();
|
|
881
738
|
deletedModels = deleteQueue.reduce(function (acc, _a) {
|
|
882
739
|
var items = _a.items;
|
|
883
740
|
return acc.concat(items);
|
|
@@ -885,7 +742,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
885
742
|
return [2 /*return*/, [models, deletedModels]];
|
|
886
743
|
case 5: return [4 /*yield*/, this.deleteTraverse(relations, models, modelConstructor.name, nameSpace, deleteQueue)];
|
|
887
744
|
case 6:
|
|
888
|
-
|
|
745
|
+
_b.sent();
|
|
889
746
|
// Delete all
|
|
890
747
|
return [4 /*yield*/, this.db
|
|
891
748
|
.transaction([storeName], 'readwrite')
|
|
@@ -893,7 +750,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
893
750
|
.clear()];
|
|
894
751
|
case 7:
|
|
895
752
|
// Delete all
|
|
896
|
-
|
|
753
|
+
_b.sent();
|
|
897
754
|
deletedModels = deleteQueue.reduce(function (acc, _a) {
|
|
898
755
|
var items = _a.items;
|
|
899
756
|
return acc.concat(items);
|
|
@@ -912,14 +769,14 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
912
769
|
keyValues = this.getIndexKeyValuesFromModel(model);
|
|
913
770
|
return [4 /*yield*/, this._get(store, keyValues)];
|
|
914
771
|
case 10:
|
|
915
|
-
fromDB =
|
|
772
|
+
fromDB = _b.sent();
|
|
916
773
|
if (fromDB === undefined) {
|
|
917
774
|
msg = 'Model instance not found in storage';
|
|
918
775
|
logger.warn(msg, { model: model });
|
|
919
776
|
return [2 /*return*/, [[model], []]];
|
|
920
777
|
}
|
|
921
778
|
predicates = predicates_1.ModelPredicateCreator.getPredicates(condition);
|
|
922
|
-
predicateObjs =
|
|
779
|
+
_a = predicates, predicateObjs = _a.predicates, type = _a.type;
|
|
923
780
|
isValid = util_1.validatePredicate(fromDB, type, predicateObjs);
|
|
924
781
|
if (!isValid) {
|
|
925
782
|
msg = 'Conditional update failed';
|
|
@@ -928,21 +785,21 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
928
785
|
}
|
|
929
786
|
return [4 /*yield*/, tx.done];
|
|
930
787
|
case 11:
|
|
931
|
-
|
|
788
|
+
_b.sent();
|
|
932
789
|
relations = this.schema.namespaces[namespaceName].relationships[modelConstructor.name].relationTypes;
|
|
933
790
|
return [4 /*yield*/, this.deleteTraverse(relations, [model], modelConstructor.name, namespaceName, deleteQueue)];
|
|
934
791
|
case 12:
|
|
935
|
-
|
|
792
|
+
_b.sent();
|
|
936
793
|
return [3 /*break*/, 15];
|
|
937
794
|
case 13:
|
|
938
795
|
relations = this.schema.namespaces[namespaceName].relationships[modelConstructor.name].relationTypes;
|
|
939
796
|
return [4 /*yield*/, this.deleteTraverse(relations, [model], modelConstructor.name, namespaceName, deleteQueue)];
|
|
940
797
|
case 14:
|
|
941
|
-
|
|
942
|
-
|
|
798
|
+
_b.sent();
|
|
799
|
+
_b.label = 15;
|
|
943
800
|
case 15: return [4 /*yield*/, this.deleteItem(deleteQueue)];
|
|
944
801
|
case 16:
|
|
945
|
-
|
|
802
|
+
_b.sent();
|
|
946
803
|
deletedModels = deleteQueue.reduce(function (acc, _a) {
|
|
947
804
|
var items = _a.items;
|
|
948
805
|
return acc.concat(items);
|
|
@@ -954,37 +811,36 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
954
811
|
});
|
|
955
812
|
};
|
|
956
813
|
IndexedDBAdapter.prototype.deleteItem = function (deleteQueue) {
|
|
957
|
-
var deleteQueue_1, deleteQueue_1_1;
|
|
958
814
|
var e_7, _a, e_8, _b;
|
|
959
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
960
|
-
var connectionStoreNames, tx, deleteItem, storeName, items, store, items_1, items_1_1, item, key, keyValues, itemKey, e_8_1, e_7_1;
|
|
961
|
-
return __generator(this, function (
|
|
962
|
-
switch (
|
|
815
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
816
|
+
var connectionStoreNames, tx, _c, _d, deleteItem, storeName, items, store, items_1, items_1_1, item, key, keyValues, itemKey, e_8_1, e_7_1;
|
|
817
|
+
return tslib_1.__generator(this, function (_e) {
|
|
818
|
+
switch (_e.label) {
|
|
963
819
|
case 0:
|
|
964
820
|
connectionStoreNames = deleteQueue.map(function (_a) {
|
|
965
821
|
var storeName = _a.storeName;
|
|
966
822
|
return storeName;
|
|
967
823
|
});
|
|
968
|
-
tx = this.db.transaction(__spread(connectionStoreNames), 'readwrite');
|
|
969
|
-
|
|
824
|
+
tx = this.db.transaction(tslib_1.__spread(connectionStoreNames), 'readwrite');
|
|
825
|
+
_e.label = 1;
|
|
970
826
|
case 1:
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
case 2: return [4 /*yield*/,
|
|
827
|
+
_e.trys.push([1, 22, 23, 28]);
|
|
828
|
+
_c = tslib_1.__asyncValues(deleteQueue);
|
|
829
|
+
_e.label = 2;
|
|
830
|
+
case 2: return [4 /*yield*/, _c.next()];
|
|
975
831
|
case 3:
|
|
976
|
-
if (!(
|
|
977
|
-
deleteItem =
|
|
832
|
+
if (!(_d = _e.sent(), !_d.done)) return [3 /*break*/, 21];
|
|
833
|
+
deleteItem = _d.value;
|
|
978
834
|
storeName = deleteItem.storeName, items = deleteItem.items;
|
|
979
835
|
store = tx.objectStore(storeName);
|
|
980
|
-
|
|
836
|
+
_e.label = 4;
|
|
981
837
|
case 4:
|
|
982
|
-
|
|
983
|
-
items_1 = __asyncValues(items);
|
|
984
|
-
|
|
838
|
+
_e.trys.push([4, 14, 15, 20]);
|
|
839
|
+
items_1 = tslib_1.__asyncValues(items);
|
|
840
|
+
_e.label = 5;
|
|
985
841
|
case 5: return [4 /*yield*/, items_1.next()];
|
|
986
842
|
case 6:
|
|
987
|
-
if (!(items_1_1 =
|
|
843
|
+
if (!(items_1_1 = _e.sent(), !items_1_1.done)) return [3 /*break*/, 13];
|
|
988
844
|
item = items_1_1.value;
|
|
989
845
|
if (!item) return [3 /*break*/, 12];
|
|
990
846
|
key = void 0;
|
|
@@ -994,33 +850,33 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
994
850
|
.index('byPk')
|
|
995
851
|
.getKey(this.canonicalKeyPath(keyValues))];
|
|
996
852
|
case 7:
|
|
997
|
-
key =
|
|
853
|
+
key = _e.sent();
|
|
998
854
|
return [3 /*break*/, 10];
|
|
999
855
|
case 8:
|
|
1000
856
|
itemKey = item.toString();
|
|
1001
857
|
return [4 /*yield*/, store.index('byPk').getKey(itemKey)];
|
|
1002
858
|
case 9:
|
|
1003
|
-
key =
|
|
1004
|
-
|
|
859
|
+
key = _e.sent();
|
|
860
|
+
_e.label = 10;
|
|
1005
861
|
case 10:
|
|
1006
862
|
if (!(key !== undefined)) return [3 /*break*/, 12];
|
|
1007
863
|
return [4 /*yield*/, store.delete(key)];
|
|
1008
864
|
case 11:
|
|
1009
|
-
|
|
1010
|
-
|
|
865
|
+
_e.sent();
|
|
866
|
+
_e.label = 12;
|
|
1011
867
|
case 12: return [3 /*break*/, 5];
|
|
1012
868
|
case 13: return [3 /*break*/, 20];
|
|
1013
869
|
case 14:
|
|
1014
|
-
e_8_1 =
|
|
870
|
+
e_8_1 = _e.sent();
|
|
1015
871
|
e_8 = { error: e_8_1 };
|
|
1016
872
|
return [3 /*break*/, 20];
|
|
1017
873
|
case 15:
|
|
1018
|
-
|
|
874
|
+
_e.trys.push([15, , 18, 19]);
|
|
1019
875
|
if (!(items_1_1 && !items_1_1.done && (_b = items_1.return))) return [3 /*break*/, 17];
|
|
1020
876
|
return [4 /*yield*/, _b.call(items_1)];
|
|
1021
877
|
case 16:
|
|
1022
|
-
|
|
1023
|
-
|
|
878
|
+
_e.sent();
|
|
879
|
+
_e.label = 17;
|
|
1024
880
|
case 17: return [3 /*break*/, 19];
|
|
1025
881
|
case 18:
|
|
1026
882
|
if (e_8) throw e_8.error;
|
|
@@ -1029,16 +885,16 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1029
885
|
case 20: return [3 /*break*/, 2];
|
|
1030
886
|
case 21: return [3 /*break*/, 28];
|
|
1031
887
|
case 22:
|
|
1032
|
-
e_7_1 =
|
|
888
|
+
e_7_1 = _e.sent();
|
|
1033
889
|
e_7 = { error: e_7_1 };
|
|
1034
890
|
return [3 /*break*/, 28];
|
|
1035
891
|
case 23:
|
|
1036
|
-
|
|
1037
|
-
if (!(
|
|
1038
|
-
return [4 /*yield*/, _a.call(
|
|
892
|
+
_e.trys.push([23, , 26, 27]);
|
|
893
|
+
if (!(_d && !_d.done && (_a = _c.return))) return [3 /*break*/, 25];
|
|
894
|
+
return [4 /*yield*/, _a.call(_c)];
|
|
1039
895
|
case 24:
|
|
1040
|
-
|
|
1041
|
-
|
|
896
|
+
_e.sent();
|
|
897
|
+
_e.label = 25;
|
|
1042
898
|
case 25: return [3 /*break*/, 27];
|
|
1043
899
|
case 26:
|
|
1044
900
|
if (e_7) throw e_7.error;
|
|
@@ -1050,21 +906,21 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1050
906
|
});
|
|
1051
907
|
};
|
|
1052
908
|
IndexedDBAdapter.prototype.deleteTraverse = function (relations, models, srcModel, nameSpace, deleteQueue) {
|
|
1053
|
-
var
|
|
909
|
+
var relations_1, relations_1_1, models_1, models_1_1, models_2, models_2_1;
|
|
1054
910
|
var e_9, _a, e_10, _b, e_11, _c;
|
|
1055
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
911
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1056
912
|
var rel, relationType, modelName, targetName, targetNames, associatedWith, storeName, _d, model, hasOneIndex, values, recordToDelete, index, values, value, recordToDelete, e_10_1, model, index, keyValues, childrenArray, e_11_1, e_9_1;
|
|
1057
913
|
var _this = this;
|
|
1058
|
-
return __generator(this, function (_e) {
|
|
914
|
+
return tslib_1.__generator(this, function (_e) {
|
|
1059
915
|
switch (_e.label) {
|
|
1060
916
|
case 0:
|
|
1061
917
|
_e.trys.push([0, 38, 39, 44]);
|
|
1062
|
-
|
|
918
|
+
relations_1 = tslib_1.__asyncValues(relations);
|
|
1063
919
|
_e.label = 1;
|
|
1064
|
-
case 1: return [4 /*yield*/,
|
|
920
|
+
case 1: return [4 /*yield*/, relations_1.next()];
|
|
1065
921
|
case 2:
|
|
1066
|
-
if (!(
|
|
1067
|
-
rel =
|
|
922
|
+
if (!(relations_1_1 = _e.sent(), !relations_1_1.done)) return [3 /*break*/, 37];
|
|
923
|
+
rel = relations_1_1.value;
|
|
1068
924
|
relationType = rel.relationType, modelName = rel.modelName, targetName = rel.targetName, targetNames = rel.targetNames, associatedWith = rel.associatedWith;
|
|
1069
925
|
storeName = util_1.getStorename(nameSpace, modelName);
|
|
1070
926
|
_d = relationType;
|
|
@@ -1076,7 +932,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1076
932
|
return [3 /*break*/, 35];
|
|
1077
933
|
case 3:
|
|
1078
934
|
_e.trys.push([3, 13, 14, 19]);
|
|
1079
|
-
models_1 = __asyncValues(models);
|
|
935
|
+
models_1 = tslib_1.__asyncValues(models);
|
|
1080
936
|
_e.label = 4;
|
|
1081
937
|
case 4: return [4 /*yield*/, models_1.next()];
|
|
1082
938
|
case 5:
|
|
@@ -1084,7 +940,9 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1084
940
|
model = models_1_1.value;
|
|
1085
941
|
hasOneIndex = 'byPk';
|
|
1086
942
|
if (!(targetNames === null || targetNames === void 0 ? void 0 : targetNames.length)) return [3 /*break*/, 8];
|
|
1087
|
-
values = targetNames
|
|
943
|
+
values = targetNames
|
|
944
|
+
.filter(function (targetName) { var _a; return (_a = model[targetName]) !== null && _a !== void 0 ? _a : false; })
|
|
945
|
+
.map(function (targetName) { return model[targetName]; });
|
|
1088
946
|
if (values.length === 0)
|
|
1089
947
|
return [3 /*break*/, 12];
|
|
1090
948
|
return [4 /*yield*/, this.db
|
|
@@ -1151,7 +1009,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1151
1009
|
case 19: return [3 /*break*/, 36];
|
|
1152
1010
|
case 20:
|
|
1153
1011
|
_e.trys.push([20, 27, 28, 33]);
|
|
1154
|
-
models_2 = __asyncValues(models);
|
|
1012
|
+
models_2 = tslib_1.__asyncValues(models);
|
|
1155
1013
|
_e.label = 21;
|
|
1156
1014
|
case 21: return [4 /*yield*/, models_2.next()];
|
|
1157
1015
|
case 22:
|
|
@@ -1199,9 +1057,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1199
1057
|
case 34:
|
|
1200
1058
|
// Intentionally blank
|
|
1201
1059
|
return [3 /*break*/, 36];
|
|
1202
|
-
case 35:
|
|
1203
|
-
util_1.exhaustiveCheck(relationType);
|
|
1204
|
-
return [3 /*break*/, 36];
|
|
1060
|
+
case 35: throw new Error("Invalid relation type " + relationType);
|
|
1205
1061
|
case 36: return [3 /*break*/, 1];
|
|
1206
1062
|
case 37: return [3 /*break*/, 44];
|
|
1207
1063
|
case 38:
|
|
@@ -1210,8 +1066,8 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1210
1066
|
return [3 /*break*/, 44];
|
|
1211
1067
|
case 39:
|
|
1212
1068
|
_e.trys.push([39, , 42, 43]);
|
|
1213
|
-
if (!(
|
|
1214
|
-
return [4 /*yield*/, _a.call(
|
|
1069
|
+
if (!(relations_1_1 && !relations_1_1.done && (_a = relations_1.return))) return [3 /*break*/, 41];
|
|
1070
|
+
return [4 /*yield*/, _a.call(relations_1)];
|
|
1215
1071
|
case 40:
|
|
1216
1072
|
_e.sent();
|
|
1217
1073
|
_e.label = 41;
|
|
@@ -1234,8 +1090,8 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1234
1090
|
};
|
|
1235
1091
|
IndexedDBAdapter.prototype.clear = function () {
|
|
1236
1092
|
var _a;
|
|
1237
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1238
|
-
return __generator(this, function (_b) {
|
|
1093
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1094
|
+
return tslib_1.__generator(this, function (_b) {
|
|
1239
1095
|
switch (_b.label) {
|
|
1240
1096
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
1241
1097
|
case 1:
|
|
@@ -1252,11 +1108,11 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1252
1108
|
});
|
|
1253
1109
|
};
|
|
1254
1110
|
IndexedDBAdapter.prototype.batchSave = function (modelConstructor, items) {
|
|
1255
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1111
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1256
1112
|
var result, storeName, txn, store, _loop_2, this_1, items_2, items_2_1, item, e_12_1;
|
|
1257
1113
|
var e_12, _a;
|
|
1258
1114
|
var _this = this;
|
|
1259
|
-
return __generator(this, function (_b) {
|
|
1115
|
+
return tslib_1.__generator(this, function (_b) {
|
|
1260
1116
|
switch (_b.label) {
|
|
1261
1117
|
case 0:
|
|
1262
1118
|
if (items.length === 0) {
|
|
@@ -1271,7 +1127,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1271
1127
|
store = txn.store;
|
|
1272
1128
|
_loop_2 = function (item) {
|
|
1273
1129
|
var namespaceName, modelName, model, connectedModels, keyValues, _deleted, index, key, instance;
|
|
1274
|
-
return __generator(this, function (_a) {
|
|
1130
|
+
return tslib_1.__generator(this, function (_a) {
|
|
1275
1131
|
switch (_a.label) {
|
|
1276
1132
|
case 0:
|
|
1277
1133
|
namespaceName = this_1.namespaceResolver(modelConstructor);
|
|
@@ -1313,7 +1169,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1313
1169
|
_b.label = 2;
|
|
1314
1170
|
case 2:
|
|
1315
1171
|
_b.trys.push([2, 7, 8, 9]);
|
|
1316
|
-
items_2 = __values(items), items_2_1 = items_2.next();
|
|
1172
|
+
items_2 = tslib_1.__values(items), items_2_1 = items_2.next();
|
|
1317
1173
|
_b.label = 3;
|
|
1318
1174
|
case 3:
|
|
1319
1175
|
if (!!items_2_1.done) return [3 /*break*/, 6];
|
|
@@ -1350,7 +1206,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1350
1206
|
});
|
|
1351
1207
|
var indexes = this.schema.namespaces[namespaceName].relationships[modelName].indexes;
|
|
1352
1208
|
indexes.forEach(function (_a) {
|
|
1353
|
-
var _b = __read(_a, 3), idxName = _b[0], keyPath = _b[1], options = _b[2];
|
|
1209
|
+
var _b = tslib_1.__read(_a, 3), idxName = _b[0], keyPath = _b[1], options = _b[2];
|
|
1354
1210
|
store.createIndex(idxName, keyPath, options);
|
|
1355
1211
|
});
|
|
1356
1212
|
return store;
|