@aws-amplify/datastore 3.14.5-unstable.4 → 3.14.5
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 +19 -0
- package/build.js +5 -0
- package/dist/aws-amplify-datastore.js +92853 -0
- package/dist/aws-amplify-datastore.js.map +1 -0
- package/dist/aws-amplify-datastore.min.js +65 -0
- package/dist/aws-amplify-datastore.min.js.map +1 -0
- package/index.js +7 -0
- package/lib/authModeStrategies/multiAuthStrategy.js +64 -6
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.js +297 -703
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/index.js +4 -6
- package/lib/index.js.map +1 -1
- package/lib/predicates/index.js +6 -127
- package/lib/predicates/index.js.map +1 -1
- package/lib/predicates/sort.js +4 -10
- package/lib/predicates/sort.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +381 -138
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js +98 -37
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.js +67 -16
- package/lib/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.native.js +4 -2
- package/lib/storage/adapter/InMemoryStore.native.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +420 -272
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js +5 -3
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -2
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +1 -1
- package/lib/storage/storage.js +143 -72
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.js +55 -6
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/datastoreReachability/index.native.js +4 -2
- package/lib/sync/datastoreReachability/index.native.js.map +1 -1
- package/lib/sync/index.js +124 -49
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.js +74 -8
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.js +97 -24
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/errorMaps.js +35 -5
- package/lib/sync/processors/errorMaps.js.map +1 -1
- package/lib/sync/processors/mutation.js +131 -47
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.js +102 -29
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.js +102 -26
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.js +103 -40
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.js +39 -9
- package/lib/types.js.map +1 -1
- package/lib/util.js +188 -192
- package/lib/util.js.map +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +57 -2
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +8 -59
- package/lib-esm/datastore/datastore.js +234 -642
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/index.d.ts +2 -3
- package/lib-esm/index.js +1 -2
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/predicates/index.d.ts +2 -16
- package/lib-esm/predicates/index.js +7 -128
- package/lib-esm/predicates/index.js.map +1 -1
- package/lib-esm/predicates/sort.js +4 -10
- package/lib-esm/predicates/sort.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.d.ts +1 -2
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +349 -109
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +68 -7
- 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 +52 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +2 -4
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +368 -227
- 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/storage.d.ts +6 -7
- package/lib-esm/storage/storage.js +101 -33
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +47 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
- package/lib-esm/sync/index.js +76 -4
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.js +67 -1
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.js +74 -1
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.js +32 -2
- package/lib-esm/sync/processors/errorMaps.js.map +1 -1
- package/lib-esm/sync/processors/mutation.js +93 -12
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.js +69 -6
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.js +75 -2
- 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 +95 -32
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +10 -63
- package/lib-esm/types.js +38 -7
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +6 -39
- package/lib-esm/util.js +171 -171
- package/lib-esm/util.js.map +1 -1
- package/package.json +14 -21
- package/src/authModeStrategies/multiAuthStrategy.ts +2 -2
- package/src/datastore/datastore.ts +206 -699
- package/src/index.ts +0 -4
- package/src/predicates/index.ts +17 -143
- package/src/predicates/sort.ts +2 -8
- package/src/storage/adapter/AsyncStorageAdapter.ts +178 -56
- package/src/storage/adapter/AsyncStorageDatabase.ts +15 -16
- package/src/storage/adapter/InMemoryStore.ts +2 -5
- package/src/storage/adapter/IndexedDBAdapter.ts +191 -166
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -2
- package/src/storage/storage.ts +37 -56
- package/src/sync/datastoreConnectivity.ts +4 -4
- package/src/sync/index.ts +28 -22
- 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 +19 -23
- package/src/sync/processors/subscription.ts +16 -20
- package/src/sync/processors/sync.ts +17 -17
- package/src/sync/utils.ts +48 -42
- package/src/types.ts +16 -128
- package/src/util.ts +150 -108
- package/webpack.config.dev.js +6 -0
- package/lib/authModeStrategies/defaultAuthStrategy.d.ts +0 -2
- package/lib/authModeStrategies/index.d.ts +0 -2
- package/lib/authModeStrategies/multiAuthStrategy.d.ts +0 -13
- package/lib/datastore/datastore.d.ts +0 -207
- package/lib/index.d.ts +0 -16
- package/lib/predicates/index.d.ts +0 -30
- package/lib/predicates/next.d.ts +0 -301
- package/lib/predicates/next.js +0 -816
- package/lib/predicates/next.js.map +0 -1
- package/lib/predicates/sort.d.ts +0 -8
- package/lib/ssr/index.d.ts +0 -3
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +0 -42
- package/lib/storage/adapter/AsyncStorageDatabase.d.ts +0 -39
- package/lib/storage/adapter/InMemoryStore.d.ts +0 -11
- package/lib/storage/adapter/InMemoryStore.native.d.ts +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.d.ts +0 -61
- package/lib/storage/adapter/getDefaultAdapter/index.d.ts +0 -3
- package/lib/storage/adapter/getDefaultAdapter/index.native.d.ts +0 -3
- package/lib/storage/adapter/index.d.ts +0 -9
- package/lib/storage/relationship.d.ts +0 -140
- package/lib/storage/relationship.js +0 -335
- package/lib/storage/relationship.js.map +0 -1
- package/lib/storage/storage.d.ts +0 -50
- package/lib/sync/datastoreConnectivity.d.ts +0 -16
- package/lib/sync/datastoreReachability/index.d.ts +0 -3
- package/lib/sync/datastoreReachability/index.native.d.ts +0 -3
- package/lib/sync/index.d.ts +0 -89
- package/lib/sync/merger.d.ts +0 -17
- package/lib/sync/outbox.d.ts +0 -27
- package/lib/sync/processors/errorMaps.d.ts +0 -17
- package/lib/sync/processors/mutation.d.ts +0 -58
- package/lib/sync/processors/subscription.d.ts +0 -33
- package/lib/sync/processors/sync.d.ts +0 -28
- package/lib/sync/utils.d.ts +0 -42
- package/lib/types.d.ts +0 -554
- package/lib/util.d.ts +0 -189
- package/lib-esm/predicates/next.d.ts +0 -301
- package/lib-esm/predicates/next.js +0 -812
- package/lib-esm/predicates/next.js.map +0 -1
- package/lib-esm/storage/relationship.d.ts +0 -140
- package/lib-esm/storage/relationship.js +0 -333
- package/lib-esm/storage/relationship.js.map +0 -1
- package/src/predicates/next.ts +0 -967
- package/src/storage/relationship.ts +0 -272
|
@@ -1,9 +1,82 @@
|
|
|
1
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
38
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
39
|
+
var m = o[Symbol.asyncIterator], i;
|
|
40
|
+
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);
|
|
41
|
+
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); }); }; }
|
|
42
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
43
|
+
};
|
|
44
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
45
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
46
|
+
if (!m) return o;
|
|
47
|
+
var i = m.call(o), r, ar = [], e;
|
|
48
|
+
try {
|
|
49
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
50
|
+
}
|
|
51
|
+
catch (error) { e = { error: error }; }
|
|
52
|
+
finally {
|
|
53
|
+
try {
|
|
54
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
55
|
+
}
|
|
56
|
+
finally { if (e) throw e.error; }
|
|
57
|
+
}
|
|
58
|
+
return ar;
|
|
59
|
+
};
|
|
60
|
+
var __values = (this && this.__values) || function(o) {
|
|
61
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
62
|
+
if (m) return m.call(o);
|
|
63
|
+
if (o && typeof o.length === "number") return {
|
|
64
|
+
next: function () {
|
|
65
|
+
if (o && i >= o.length) o = void 0;
|
|
66
|
+
return { value: o && o[i++], done: !o };
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
70
|
+
};
|
|
71
|
+
var __spread = (this && this.__spread) || function () {
|
|
72
|
+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
73
|
+
return ar;
|
|
74
|
+
};
|
|
2
75
|
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
3
76
|
import * as idb from 'idb';
|
|
4
|
-
import { ModelPredicateCreator } from '../../predicates';
|
|
5
|
-
import { isPredicateObj,
|
|
6
|
-
import { getIndex, getIndexFromAssociation, isModelConstructor, isPrivateMode, traverseModel, validatePredicate,
|
|
77
|
+
import { ModelPredicateCreator, ModelSortPredicateCreator, } from '../../predicates';
|
|
78
|
+
import { isPredicateObj, OpType, QueryOne, } from '../../types';
|
|
79
|
+
import { exhaustiveCheck, getIndex, getIndexFromAssociation, isModelConstructor, isPrivateMode, traverseModel, validatePredicate, sortCompareFunction, keysEqual, getStorename, getIndexKeys, extractPrimaryKeyValues, isSafariCompatabilityMode, } from '../../util';
|
|
7
80
|
var logger = new Logger('DataStore');
|
|
8
81
|
var DB_NAME = 'amplify-datastore';
|
|
9
82
|
var IndexedDBAdapter = /** @class */ (function () {
|
|
@@ -277,13 +350,13 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
277
350
|
IndexedDBAdapter.prototype.save = function (model, condition) {
|
|
278
351
|
var e_2, _a;
|
|
279
352
|
return __awaiter(this, void 0, void 0, function () {
|
|
280
|
-
var modelConstructor, storeName, namespaceName, connectedModels, set, connectionStoreNames, tx, store, keyValues, fromDB, predicates,
|
|
353
|
+
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
354
|
var _this = this;
|
|
282
|
-
return __generator(this, function (
|
|
283
|
-
switch (
|
|
355
|
+
return __generator(this, function (_b) {
|
|
356
|
+
switch (_b.label) {
|
|
284
357
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
285
358
|
case 1:
|
|
286
|
-
|
|
359
|
+
_b.sent();
|
|
287
360
|
modelConstructor = Object.getPrototypeOf(model)
|
|
288
361
|
.constructor;
|
|
289
362
|
storeName = this.getStorenameForModel(modelConstructor);
|
|
@@ -302,10 +375,10 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
302
375
|
keyValues = this.getIndexKeyValuesFromModel(model);
|
|
303
376
|
return [4 /*yield*/, this._get(store, keyValues)];
|
|
304
377
|
case 2:
|
|
305
|
-
fromDB =
|
|
378
|
+
fromDB = _b.sent();
|
|
306
379
|
if (condition && fromDB) {
|
|
307
380
|
predicates = ModelPredicateCreator.getPredicates(condition);
|
|
308
|
-
|
|
381
|
+
predicateObjs = predicates.predicates, type = predicates.type;
|
|
309
382
|
isValid = validatePredicate(fromDB, type, predicateObjs);
|
|
310
383
|
if (!isValid) {
|
|
311
384
|
msg = 'Conditional update failed';
|
|
@@ -314,14 +387,14 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
314
387
|
}
|
|
315
388
|
}
|
|
316
389
|
result = [];
|
|
317
|
-
|
|
390
|
+
_b.label = 3;
|
|
318
391
|
case 3:
|
|
319
|
-
|
|
392
|
+
_b.trys.push([3, 11, 12, 17]);
|
|
320
393
|
connectionStoreNames_1 = __asyncValues(connectionStoreNames);
|
|
321
|
-
|
|
394
|
+
_b.label = 4;
|
|
322
395
|
case 4: return [4 /*yield*/, connectionStoreNames_1.next()];
|
|
323
396
|
case 5:
|
|
324
|
-
if (!(connectionStoreNames_1_1 =
|
|
397
|
+
if (!(connectionStoreNames_1_1 = _b.sent(), !connectionStoreNames_1_1.done)) return [3 /*break*/, 10];
|
|
325
398
|
resItem = connectionStoreNames_1_1.value;
|
|
326
399
|
storeName_1 = resItem.storeName, item = resItem.item, instance = resItem.instance, keys = resItem.keys;
|
|
327
400
|
store_1 = tx.objectStore(storeName_1);
|
|
@@ -331,7 +404,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
331
404
|
});
|
|
332
405
|
return [4 /*yield*/, this._get(store_1, itemKeyValues)];
|
|
333
406
|
case 6:
|
|
334
|
-
fromDB_1 =
|
|
407
|
+
fromDB_1 = _b.sent();
|
|
335
408
|
opType = fromDB_1 === undefined ? OpType.INSERT : OpType.UPDATE;
|
|
336
409
|
modelKeyValues = this.getIndexKeyValuesFromModel(model);
|
|
337
410
|
if (!(keysEqual(itemKeyValues, modelKeyValues) ||
|
|
@@ -340,25 +413,25 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
340
413
|
.index('byPk')
|
|
341
414
|
.getKey(this.canonicalKeyPath(itemKeyValues))];
|
|
342
415
|
case 7:
|
|
343
|
-
key =
|
|
416
|
+
key = _b.sent();
|
|
344
417
|
return [4 /*yield*/, store_1.put(item, key)];
|
|
345
418
|
case 8:
|
|
346
|
-
|
|
419
|
+
_b.sent();
|
|
347
420
|
result.push([instance, opType]);
|
|
348
|
-
|
|
421
|
+
_b.label = 9;
|
|
349
422
|
case 9: return [3 /*break*/, 4];
|
|
350
423
|
case 10: return [3 /*break*/, 17];
|
|
351
424
|
case 11:
|
|
352
|
-
e_2_1 =
|
|
425
|
+
e_2_1 = _b.sent();
|
|
353
426
|
e_2 = { error: e_2_1 };
|
|
354
427
|
return [3 /*break*/, 17];
|
|
355
428
|
case 12:
|
|
356
|
-
|
|
429
|
+
_b.trys.push([12, , 15, 16]);
|
|
357
430
|
if (!(connectionStoreNames_1_1 && !connectionStoreNames_1_1.done && (_a = connectionStoreNames_1.return))) return [3 /*break*/, 14];
|
|
358
431
|
return [4 /*yield*/, _a.call(connectionStoreNames_1)];
|
|
359
432
|
case 13:
|
|
360
|
-
|
|
361
|
-
|
|
433
|
+
_b.sent();
|
|
434
|
+
_b.label = 14;
|
|
362
435
|
case 14: return [3 /*break*/, 16];
|
|
363
436
|
case 15:
|
|
364
437
|
if (e_2) throw e_2.error;
|
|
@@ -366,32 +439,205 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
366
439
|
case 16: return [7 /*endfinally*/];
|
|
367
440
|
case 17: return [4 /*yield*/, tx.done];
|
|
368
441
|
case 18:
|
|
369
|
-
|
|
442
|
+
_b.sent();
|
|
370
443
|
return [2 /*return*/, result];
|
|
371
444
|
}
|
|
372
445
|
});
|
|
373
446
|
});
|
|
374
447
|
};
|
|
375
448
|
IndexedDBAdapter.prototype.load = function (namespaceName, srcModelName, records) {
|
|
449
|
+
var records_1, records_1_1, records_2, records_2_1;
|
|
450
|
+
var e_3, _a, e_4, _b, e_5, _c;
|
|
376
451
|
return __awaiter(this, void 0, void 0, function () {
|
|
377
|
-
var namespace, relations, connectionStoreNames, modelConstructor;
|
|
452
|
+
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
453
|
var _this = this;
|
|
379
|
-
return __generator(this, function (
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
454
|
+
return __generator(this, function (_e) {
|
|
455
|
+
switch (_e.label) {
|
|
456
|
+
case 0:
|
|
457
|
+
namespace = this.schema.namespaces[namespaceName];
|
|
458
|
+
relations = namespace.relationships[srcModelName].relationTypes;
|
|
459
|
+
connectionStoreNames = relations.map(function (_a) {
|
|
460
|
+
var modelName = _a.modelName;
|
|
461
|
+
return getStorename(namespaceName, modelName);
|
|
462
|
+
});
|
|
463
|
+
modelConstructor = this.getModelConstructorByModelName(namespaceName, srcModelName);
|
|
464
|
+
if (connectionStoreNames.length === 0) {
|
|
465
|
+
return [2 /*return*/, records.map(function (record) {
|
|
466
|
+
return _this.modelInstanceCreator(modelConstructor, record);
|
|
467
|
+
})];
|
|
468
|
+
}
|
|
469
|
+
tx = this.db.transaction(__spread(connectionStoreNames), 'readonly');
|
|
470
|
+
_e.label = 1;
|
|
471
|
+
case 1:
|
|
472
|
+
_e.trys.push([1, 38, 39, 44]);
|
|
473
|
+
relations_1 = __asyncValues(relations);
|
|
474
|
+
_e.label = 2;
|
|
475
|
+
case 2: return [4 /*yield*/, relations_1.next()];
|
|
476
|
+
case 3:
|
|
477
|
+
if (!(relations_1_1 = _e.sent(), !relations_1_1.done)) return [3 /*break*/, 37];
|
|
478
|
+
relation = relations_1_1.value;
|
|
479
|
+
fieldName = relation.fieldName, modelName = relation.modelName, targetName = relation.targetName, targetNames = relation.targetNames;
|
|
480
|
+
storeName = getStorename(namespaceName, modelName);
|
|
481
|
+
store = tx.objectStore(storeName);
|
|
482
|
+
modelConstructor_1 = this.getModelConstructorByModelName(namespaceName, modelName);
|
|
483
|
+
_d = relation.relationType;
|
|
484
|
+
switch (_d) {
|
|
485
|
+
case 'HAS_ONE': return [3 /*break*/, 4];
|
|
486
|
+
case 'BELONGS_TO': return [3 /*break*/, 19];
|
|
487
|
+
case 'HAS_MANY': return [3 /*break*/, 34];
|
|
488
|
+
}
|
|
489
|
+
return [3 /*break*/, 35];
|
|
490
|
+
case 4:
|
|
491
|
+
_e.trys.push([4, 12, 13, 18]);
|
|
492
|
+
records_1 = __asyncValues(records);
|
|
493
|
+
_e.label = 5;
|
|
494
|
+
case 5: return [4 /*yield*/, records_1.next()];
|
|
495
|
+
case 6:
|
|
496
|
+
if (!(records_1_1 = _e.sent(), !records_1_1.done)) return [3 /*break*/, 11];
|
|
497
|
+
recordItem = records_1_1.value;
|
|
498
|
+
if (!(targetNames === null || targetNames === void 0 ? void 0 : targetNames.length)) return [3 /*break*/, 8];
|
|
499
|
+
getByFields = [];
|
|
500
|
+
allPresent = void 0;
|
|
501
|
+
// iterate through all targetnames to make sure they are all present in the recordItem
|
|
502
|
+
allPresent = targetNames.every(function (targetName) {
|
|
503
|
+
return recordItem[targetName] != null;
|
|
504
|
+
});
|
|
505
|
+
if (!allPresent) {
|
|
506
|
+
return [3 /*break*/, 11];
|
|
507
|
+
}
|
|
508
|
+
getByFields = targetNames;
|
|
509
|
+
keys = getByFields.map(function (getByField) { return recordItem[getByField]; });
|
|
510
|
+
return [4 /*yield*/, this._get(store, keys)];
|
|
511
|
+
case 7:
|
|
512
|
+
connectionRecord = _e.sent();
|
|
513
|
+
recordItem[fieldName] =
|
|
514
|
+
connectionRecord &&
|
|
515
|
+
this.modelInstanceCreator(modelConstructor_1, connectionRecord);
|
|
516
|
+
return [3 /*break*/, 10];
|
|
517
|
+
case 8:
|
|
518
|
+
getByfield = recordItem[targetName]
|
|
519
|
+
? targetName
|
|
520
|
+
: fieldName;
|
|
521
|
+
// We break here, because the recordItem does not have 'team', the `getByField`
|
|
522
|
+
// extract the keys on the related model.
|
|
523
|
+
if (!recordItem[getByfield])
|
|
524
|
+
return [3 /*break*/, 11];
|
|
525
|
+
key = [recordItem[getByfield]];
|
|
526
|
+
return [4 /*yield*/, this._get(store, key)];
|
|
527
|
+
case 9:
|
|
528
|
+
connectionRecord = _e.sent();
|
|
529
|
+
recordItem[fieldName] =
|
|
530
|
+
connectionRecord &&
|
|
531
|
+
this.modelInstanceCreator(modelConstructor_1, connectionRecord);
|
|
532
|
+
_e.label = 10;
|
|
533
|
+
case 10: return [3 /*break*/, 5];
|
|
534
|
+
case 11: return [3 /*break*/, 18];
|
|
535
|
+
case 12:
|
|
536
|
+
e_4_1 = _e.sent();
|
|
537
|
+
e_4 = { error: e_4_1 };
|
|
538
|
+
return [3 /*break*/, 18];
|
|
539
|
+
case 13:
|
|
540
|
+
_e.trys.push([13, , 16, 17]);
|
|
541
|
+
if (!(records_1_1 && !records_1_1.done && (_b = records_1.return))) return [3 /*break*/, 15];
|
|
542
|
+
return [4 /*yield*/, _b.call(records_1)];
|
|
543
|
+
case 14:
|
|
544
|
+
_e.sent();
|
|
545
|
+
_e.label = 15;
|
|
546
|
+
case 15: return [3 /*break*/, 17];
|
|
547
|
+
case 16:
|
|
548
|
+
if (e_4) throw e_4.error;
|
|
549
|
+
return [7 /*endfinally*/];
|
|
550
|
+
case 17: return [7 /*endfinally*/];
|
|
551
|
+
case 18: return [3 /*break*/, 36];
|
|
552
|
+
case 19:
|
|
553
|
+
_e.trys.push([19, 27, 28, 33]);
|
|
554
|
+
records_2 = __asyncValues(records);
|
|
555
|
+
_e.label = 20;
|
|
556
|
+
case 20: return [4 /*yield*/, records_2.next()];
|
|
557
|
+
case 21:
|
|
558
|
+
if (!(records_2_1 = _e.sent(), !records_2_1.done)) return [3 /*break*/, 26];
|
|
559
|
+
recordItem = records_2_1.value;
|
|
560
|
+
if (!(targetNames === null || targetNames === void 0 ? void 0 : targetNames.length)) return [3 /*break*/, 23];
|
|
561
|
+
allPresent = void 0;
|
|
562
|
+
// iterate through all targetnames to make sure they are all present in the recordItem
|
|
563
|
+
allPresent = targetNames.every(function (targetName) {
|
|
564
|
+
return recordItem[targetName] != null;
|
|
565
|
+
});
|
|
566
|
+
// If not present, there is not yet a connected record
|
|
567
|
+
if (!allPresent) {
|
|
568
|
+
return [3 /*break*/, 26];
|
|
569
|
+
}
|
|
570
|
+
keys = targetNames
|
|
571
|
+
.filter(function (targetName) { var _a; return (_a = recordItem[targetName]) !== null && _a !== void 0 ? _a : false; })
|
|
572
|
+
.map(function (targetName) { return recordItem[targetName]; });
|
|
573
|
+
return [4 /*yield*/, this._get(store, keys)];
|
|
574
|
+
case 22:
|
|
575
|
+
connectionRecord = _e.sent();
|
|
576
|
+
recordItem[fieldName] =
|
|
577
|
+
connectionRecord &&
|
|
578
|
+
this.modelInstanceCreator(modelConstructor_1, connectionRecord);
|
|
579
|
+
targetNames === null || targetNames === void 0 ? void 0 : targetNames.map(function (targetName) {
|
|
580
|
+
delete recordItem[targetName];
|
|
581
|
+
});
|
|
582
|
+
return [3 /*break*/, 25];
|
|
583
|
+
case 23:
|
|
584
|
+
if (!recordItem[targetName]) return [3 /*break*/, 25];
|
|
585
|
+
key = [recordItem[targetName]];
|
|
586
|
+
return [4 /*yield*/, this._get(store, key)];
|
|
587
|
+
case 24:
|
|
588
|
+
connectionRecord = _e.sent();
|
|
589
|
+
recordItem[fieldName] =
|
|
590
|
+
connectionRecord &&
|
|
591
|
+
this.modelInstanceCreator(modelConstructor_1, connectionRecord);
|
|
592
|
+
delete recordItem[targetName];
|
|
593
|
+
_e.label = 25;
|
|
594
|
+
case 25: return [3 /*break*/, 20];
|
|
595
|
+
case 26: return [3 /*break*/, 33];
|
|
596
|
+
case 27:
|
|
597
|
+
e_5_1 = _e.sent();
|
|
598
|
+
e_5 = { error: e_5_1 };
|
|
599
|
+
return [3 /*break*/, 33];
|
|
600
|
+
case 28:
|
|
601
|
+
_e.trys.push([28, , 31, 32]);
|
|
602
|
+
if (!(records_2_1 && !records_2_1.done && (_c = records_2.return))) return [3 /*break*/, 30];
|
|
603
|
+
return [4 /*yield*/, _c.call(records_2)];
|
|
604
|
+
case 29:
|
|
605
|
+
_e.sent();
|
|
606
|
+
_e.label = 30;
|
|
607
|
+
case 30: return [3 /*break*/, 32];
|
|
608
|
+
case 31:
|
|
609
|
+
if (e_5) throw e_5.error;
|
|
610
|
+
return [7 /*endfinally*/];
|
|
611
|
+
case 32: return [7 /*endfinally*/];
|
|
612
|
+
case 33: return [3 /*break*/, 36];
|
|
613
|
+
case 34:
|
|
614
|
+
// TODO: Lazy loading
|
|
615
|
+
return [3 /*break*/, 36];
|
|
616
|
+
case 35:
|
|
617
|
+
exhaustiveCheck(relation.relationType);
|
|
618
|
+
return [3 /*break*/, 36];
|
|
619
|
+
case 36: return [3 /*break*/, 2];
|
|
620
|
+
case 37: return [3 /*break*/, 44];
|
|
621
|
+
case 38:
|
|
622
|
+
e_3_1 = _e.sent();
|
|
623
|
+
e_3 = { error: e_3_1 };
|
|
624
|
+
return [3 /*break*/, 44];
|
|
625
|
+
case 39:
|
|
626
|
+
_e.trys.push([39, , 42, 43]);
|
|
627
|
+
if (!(relations_1_1 && !relations_1_1.done && (_a = relations_1.return))) return [3 /*break*/, 41];
|
|
628
|
+
return [4 /*yield*/, _a.call(relations_1)];
|
|
629
|
+
case 40:
|
|
630
|
+
_e.sent();
|
|
631
|
+
_e.label = 41;
|
|
632
|
+
case 41: return [3 /*break*/, 43];
|
|
633
|
+
case 42:
|
|
634
|
+
if (e_3) throw e_3.error;
|
|
635
|
+
return [7 /*endfinally*/];
|
|
636
|
+
case 43: return [7 /*endfinally*/];
|
|
637
|
+
case 44: return [2 /*return*/, records.map(function (record) {
|
|
389
638
|
return _this.modelInstanceCreator(modelConstructor, record);
|
|
390
639
|
})];
|
|
391
640
|
}
|
|
392
|
-
return [2 /*return*/, records.map(function (record) {
|
|
393
|
-
return _this.modelInstanceCreator(modelConstructor, record);
|
|
394
|
-
})];
|
|
395
641
|
});
|
|
396
642
|
});
|
|
397
643
|
};
|
|
@@ -442,7 +688,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
442
688
|
});
|
|
443
689
|
}); })()];
|
|
444
690
|
case 2:
|
|
445
|
-
records =
|
|
691
|
+
records = _a.sent();
|
|
446
692
|
return [4 /*yield*/, this.load(namespaceName, modelConstructor.name, records)];
|
|
447
693
|
case 3: return [2 /*return*/, _a.sent()];
|
|
448
694
|
}
|
|
@@ -451,10 +697,13 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
451
697
|
};
|
|
452
698
|
IndexedDBAdapter.prototype.getByKey = function (storeName, keyValue) {
|
|
453
699
|
return __awaiter(this, void 0, void 0, function () {
|
|
700
|
+
var record;
|
|
454
701
|
return __generator(this, function (_a) {
|
|
455
702
|
switch (_a.label) {
|
|
456
703
|
case 0: return [4 /*yield*/, this._get(storeName, keyValue)];
|
|
457
|
-
case 1:
|
|
704
|
+
case 1:
|
|
705
|
+
record = _a.sent();
|
|
706
|
+
return [2 /*return*/, record];
|
|
458
707
|
}
|
|
459
708
|
});
|
|
460
709
|
});
|
|
@@ -470,7 +719,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
470
719
|
});
|
|
471
720
|
};
|
|
472
721
|
IndexedDBAdapter.prototype.keyValueFromPredicate = function (predicates, keyPath) {
|
|
473
|
-
var
|
|
722
|
+
var e_6, _a;
|
|
474
723
|
var predicateObjs = predicates.predicates;
|
|
475
724
|
if (predicateObjs.length !== keyPath.length) {
|
|
476
725
|
return;
|
|
@@ -486,159 +735,48 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
486
735
|
_loop_1(key);
|
|
487
736
|
}
|
|
488
737
|
}
|
|
489
|
-
catch (
|
|
738
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
490
739
|
finally {
|
|
491
740
|
try {
|
|
492
741
|
if (keyPath_1_1 && !keyPath_1_1.done && (_a = keyPath_1.return)) _a.call(keyPath_1);
|
|
493
742
|
}
|
|
494
|
-
finally { if (
|
|
743
|
+
finally { if (e_6) throw e_6.error; }
|
|
495
744
|
}
|
|
496
745
|
return keyValues.length === keyPath.length ? keyValues : undefined;
|
|
497
746
|
};
|
|
498
|
-
IndexedDBAdapter.prototype.matchingIndex = function (storeName, fieldName, transaction) {
|
|
499
|
-
var e_4, _a;
|
|
500
|
-
var store = transaction.objectStore(storeName);
|
|
501
|
-
try {
|
|
502
|
-
for (var _b = __values(store.indexNames), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
503
|
-
var name_1 = _c.value;
|
|
504
|
-
var idx = store.index(name_1);
|
|
505
|
-
if (idx.keyPath === fieldName) {
|
|
506
|
-
return idx;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
511
|
-
finally {
|
|
512
|
-
try {
|
|
513
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
514
|
-
}
|
|
515
|
-
finally { if (e_4) throw e_4.error; }
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
747
|
IndexedDBAdapter.prototype.filterOnPredicate = function (storeName, predicates) {
|
|
519
748
|
return __awaiter(this, void 0, void 0, function () {
|
|
520
|
-
var predicateObjs, type,
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
return __generator(this, function (_c) {
|
|
524
|
-
switch (_c.label) {
|
|
749
|
+
var predicateObjs, type, all, filtered;
|
|
750
|
+
return __generator(this, function (_a) {
|
|
751
|
+
switch (_a.label) {
|
|
525
752
|
case 0:
|
|
526
753
|
predicateObjs = predicates.predicates, type = predicates.type;
|
|
527
|
-
|
|
528
|
-
// one level down: `{and: {or: {and: { <the predicates we want> }}}}`
|
|
529
|
-
// so, we unpack and/or groups until we find a group with more than 1
|
|
530
|
-
// child OR a child that is not a group (and is therefore a predicate "object").
|
|
531
|
-
while (predicateObjs.length === 1 && isPredicateGroup(predicateObjs[0])) {
|
|
532
|
-
type = predicateObjs[0].type;
|
|
533
|
-
predicateObjs = predicateObjs[0].predicates;
|
|
534
|
-
}
|
|
535
|
-
fieldPredicates = predicateObjs.filter(function (p) {
|
|
536
|
-
return isPredicateObj(p);
|
|
537
|
-
});
|
|
538
|
-
txn = this.db.transaction(storeName);
|
|
539
|
-
predicateIndexes = fieldPredicates.map(function (p) {
|
|
540
|
-
return {
|
|
541
|
-
predicate: p,
|
|
542
|
-
index: _this.matchingIndex(storeName, String(p.field), txn),
|
|
543
|
-
};
|
|
544
|
-
});
|
|
545
|
-
// Explicitly wait for txns from index queries to complete before proceding.
|
|
546
|
-
// This helps ensure IndexedDB is in a stable, ready state. Else, subseqeuent
|
|
547
|
-
// qeuries can sometimes appear to deadlock (at least in FakeIndexedDB).
|
|
548
|
-
return [4 /*yield*/, txn.done];
|
|
754
|
+
return [4 /*yield*/, this.getAll(storeName)];
|
|
549
755
|
case 1:
|
|
550
|
-
|
|
551
|
-
// This helps ensure IndexedDB is in a stable, ready state. Else, subseqeuent
|
|
552
|
-
// qeuries can sometimes appear to deadlock (at least in FakeIndexedDB).
|
|
553
|
-
_c.sent();
|
|
554
|
-
if (!(type === 'and')) return [3 /*break*/, 6];
|
|
555
|
-
actualPredicateIndexes = predicateIndexes.filter(function (i) { return i.index && i.predicate.operator === 'eq'; });
|
|
556
|
-
if (!(actualPredicateIndexes.length > 0)) return [3 /*break*/, 3];
|
|
557
|
-
predicateIndex = actualPredicateIndexes[0];
|
|
558
|
-
return [4 /*yield*/, predicateIndex.index.getAll(predicateIndex.predicate.operand)];
|
|
559
|
-
case 2:
|
|
560
|
-
candidateResults = (_c.sent());
|
|
561
|
-
return [3 /*break*/, 5];
|
|
562
|
-
case 3: return [4 /*yield*/, this.getAll(storeName)];
|
|
563
|
-
case 4:
|
|
564
|
-
// no usable indexes
|
|
565
|
-
candidateResults = (_c.sent());
|
|
566
|
-
_c.label = 5;
|
|
567
|
-
case 5: return [3 /*break*/, 20];
|
|
568
|
-
case 6:
|
|
569
|
-
if (!(type === 'or')) return [3 /*break*/, 18];
|
|
570
|
-
if (!(predicateIndexes.length > 0 &&
|
|
571
|
-
predicateIndexes.every(function (i) { return i.index && i.predicate.operator === 'eq'; }))) return [3 /*break*/, 15];
|
|
572
|
-
distinctResults = new Map();
|
|
573
|
-
_c.label = 7;
|
|
574
|
-
case 7:
|
|
575
|
-
_c.trys.push([7, 12, 13, 14]);
|
|
576
|
-
predicateIndexes_1 = __values(predicateIndexes), predicateIndexes_1_1 = predicateIndexes_1.next();
|
|
577
|
-
_c.label = 8;
|
|
578
|
-
case 8:
|
|
579
|
-
if (!!predicateIndexes_1_1.done) return [3 /*break*/, 11];
|
|
580
|
-
predicateIndex = predicateIndexes_1_1.value;
|
|
581
|
-
return [4 /*yield*/, predicateIndex.index.getAll(predicateIndex.predicate.operand)];
|
|
582
|
-
case 9:
|
|
583
|
-
resultGroup = (_c.sent());
|
|
584
|
-
try {
|
|
585
|
-
for (resultGroup_1 = (e_6 = void 0, __values(resultGroup)), resultGroup_1_1 = resultGroup_1.next(); !resultGroup_1_1.done; resultGroup_1_1 = resultGroup_1.next()) {
|
|
586
|
-
item = resultGroup_1_1.value;
|
|
587
|
-
// TODO: custom PK
|
|
588
|
-
distinctResults.set(item.id, item);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
592
|
-
finally {
|
|
593
|
-
try {
|
|
594
|
-
if (resultGroup_1_1 && !resultGroup_1_1.done && (_b = resultGroup_1.return)) _b.call(resultGroup_1);
|
|
595
|
-
}
|
|
596
|
-
finally { if (e_6) throw e_6.error; }
|
|
597
|
-
}
|
|
598
|
-
_c.label = 10;
|
|
599
|
-
case 10:
|
|
600
|
-
predicateIndexes_1_1 = predicateIndexes_1.next();
|
|
601
|
-
return [3 /*break*/, 8];
|
|
602
|
-
case 11: return [3 /*break*/, 14];
|
|
603
|
-
case 12:
|
|
604
|
-
e_5_1 = _c.sent();
|
|
605
|
-
e_5 = { error: e_5_1 };
|
|
606
|
-
return [3 /*break*/, 14];
|
|
607
|
-
case 13:
|
|
608
|
-
try {
|
|
609
|
-
if (predicateIndexes_1_1 && !predicateIndexes_1_1.done && (_a = predicateIndexes_1.return)) _a.call(predicateIndexes_1);
|
|
610
|
-
}
|
|
611
|
-
finally { if (e_5) throw e_5.error; }
|
|
612
|
-
return [7 /*endfinally*/];
|
|
613
|
-
case 14:
|
|
614
|
-
// we could conceivably check for special conditions and return early here.
|
|
615
|
-
// but, this is simpler and has not yet had a measurable performance impact.
|
|
616
|
-
candidateResults = Array.from(distinctResults.values());
|
|
617
|
-
return [3 /*break*/, 17];
|
|
618
|
-
case 15: return [4 /*yield*/, this.getAll(storeName)];
|
|
619
|
-
case 16:
|
|
620
|
-
// either no usable indexes or not all conditions can use one.
|
|
621
|
-
candidateResults = (_c.sent());
|
|
622
|
-
_c.label = 17;
|
|
623
|
-
case 17: return [3 /*break*/, 20];
|
|
624
|
-
case 18: return [4 /*yield*/, this.getAll(storeName)];
|
|
625
|
-
case 19:
|
|
626
|
-
// nothing intelligent we can do with `not` groups unless or until we start
|
|
627
|
-
// smashing comparison operators against indexes -- at which point we could
|
|
628
|
-
// perform some reversal here.
|
|
629
|
-
candidateResults = (_c.sent());
|
|
630
|
-
_c.label = 20;
|
|
631
|
-
case 20:
|
|
756
|
+
all = _a.sent();
|
|
632
757
|
filtered = predicateObjs
|
|
633
|
-
?
|
|
634
|
-
:
|
|
758
|
+
? all.filter(function (m) { return validatePredicate(m, type, predicateObjs); })
|
|
759
|
+
: all;
|
|
635
760
|
return [2 /*return*/, filtered];
|
|
636
761
|
}
|
|
637
762
|
});
|
|
638
763
|
});
|
|
639
764
|
};
|
|
640
765
|
IndexedDBAdapter.prototype.inMemoryPagination = function (records, pagination) {
|
|
641
|
-
|
|
766
|
+
if (pagination && records.length > 1) {
|
|
767
|
+
if (pagination.sort) {
|
|
768
|
+
var sortPredicates = ModelSortPredicateCreator.getPredicates(pagination.sort);
|
|
769
|
+
if (sortPredicates.length) {
|
|
770
|
+
var compareFn = sortCompareFunction(sortPredicates);
|
|
771
|
+
records.sort(compareFn);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
var _a = pagination.page, page = _a === void 0 ? 0 : _a, _b = pagination.limit, limit = _b === void 0 ? 0 : _b;
|
|
775
|
+
var start = Math.max(0, page * limit) || 0;
|
|
776
|
+
var end = limit > 0 ? start + limit : records.length;
|
|
777
|
+
return records.slice(start, end);
|
|
778
|
+
}
|
|
779
|
+
return records;
|
|
642
780
|
};
|
|
643
781
|
IndexedDBAdapter.prototype.enginePagination = function (storeName, pagination) {
|
|
644
782
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -710,12 +848,12 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
710
848
|
};
|
|
711
849
|
IndexedDBAdapter.prototype.delete = function (modelOrModelConstructor, condition) {
|
|
712
850
|
return __awaiter(this, void 0, void 0, function () {
|
|
713
|
-
var deleteQueue, modelConstructor, nameSpace, storeName, models, relations, deletedModels, deletedModels, model, modelConstructor, namespaceName, storeName, tx, store, keyValues, fromDB, msg, predicates,
|
|
714
|
-
return __generator(this, function (
|
|
715
|
-
switch (
|
|
851
|
+
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;
|
|
852
|
+
return __generator(this, function (_a) {
|
|
853
|
+
switch (_a.label) {
|
|
716
854
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
717
855
|
case 1:
|
|
718
|
-
|
|
856
|
+
_a.sent();
|
|
719
857
|
deleteQueue = [];
|
|
720
858
|
if (!isModelConstructor(modelOrModelConstructor)) return [3 /*break*/, 9];
|
|
721
859
|
modelConstructor = modelOrModelConstructor;
|
|
@@ -723,16 +861,16 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
723
861
|
storeName = this.getStorenameForModel(modelConstructor);
|
|
724
862
|
return [4 /*yield*/, this.query(modelConstructor, condition)];
|
|
725
863
|
case 2:
|
|
726
|
-
models =
|
|
864
|
+
models = _a.sent();
|
|
727
865
|
relations = this.schema.namespaces[nameSpace].relationships[modelConstructor.name]
|
|
728
866
|
.relationTypes;
|
|
729
867
|
if (!(condition !== undefined)) return [3 /*break*/, 5];
|
|
730
868
|
return [4 /*yield*/, this.deleteTraverse(relations, models, modelConstructor.name, nameSpace, deleteQueue)];
|
|
731
869
|
case 3:
|
|
732
|
-
|
|
870
|
+
_a.sent();
|
|
733
871
|
return [4 /*yield*/, this.deleteItem(deleteQueue)];
|
|
734
872
|
case 4:
|
|
735
|
-
|
|
873
|
+
_a.sent();
|
|
736
874
|
deletedModels = deleteQueue.reduce(function (acc, _a) {
|
|
737
875
|
var items = _a.items;
|
|
738
876
|
return acc.concat(items);
|
|
@@ -740,7 +878,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
740
878
|
return [2 /*return*/, [models, deletedModels]];
|
|
741
879
|
case 5: return [4 /*yield*/, this.deleteTraverse(relations, models, modelConstructor.name, nameSpace, deleteQueue)];
|
|
742
880
|
case 6:
|
|
743
|
-
|
|
881
|
+
_a.sent();
|
|
744
882
|
// Delete all
|
|
745
883
|
return [4 /*yield*/, this.db
|
|
746
884
|
.transaction([storeName], 'readwrite')
|
|
@@ -748,7 +886,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
748
886
|
.clear()];
|
|
749
887
|
case 7:
|
|
750
888
|
// Delete all
|
|
751
|
-
|
|
889
|
+
_a.sent();
|
|
752
890
|
deletedModels = deleteQueue.reduce(function (acc, _a) {
|
|
753
891
|
var items = _a.items;
|
|
754
892
|
return acc.concat(items);
|
|
@@ -767,14 +905,14 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
767
905
|
keyValues = this.getIndexKeyValuesFromModel(model);
|
|
768
906
|
return [4 /*yield*/, this._get(store, keyValues)];
|
|
769
907
|
case 10:
|
|
770
|
-
fromDB =
|
|
908
|
+
fromDB = _a.sent();
|
|
771
909
|
if (fromDB === undefined) {
|
|
772
910
|
msg = 'Model instance not found in storage';
|
|
773
911
|
logger.warn(msg, { model: model });
|
|
774
912
|
return [2 /*return*/, [[model], []]];
|
|
775
913
|
}
|
|
776
914
|
predicates = ModelPredicateCreator.getPredicates(condition);
|
|
777
|
-
|
|
915
|
+
predicateObjs = predicates.predicates, type = predicates.type;
|
|
778
916
|
isValid = validatePredicate(fromDB, type, predicateObjs);
|
|
779
917
|
if (!isValid) {
|
|
780
918
|
msg = 'Conditional update failed';
|
|
@@ -783,21 +921,21 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
783
921
|
}
|
|
784
922
|
return [4 /*yield*/, tx.done];
|
|
785
923
|
case 11:
|
|
786
|
-
|
|
924
|
+
_a.sent();
|
|
787
925
|
relations = this.schema.namespaces[namespaceName].relationships[modelConstructor.name].relationTypes;
|
|
788
926
|
return [4 /*yield*/, this.deleteTraverse(relations, [model], modelConstructor.name, namespaceName, deleteQueue)];
|
|
789
927
|
case 12:
|
|
790
|
-
|
|
928
|
+
_a.sent();
|
|
791
929
|
return [3 /*break*/, 15];
|
|
792
930
|
case 13:
|
|
793
931
|
relations = this.schema.namespaces[namespaceName].relationships[modelConstructor.name].relationTypes;
|
|
794
932
|
return [4 /*yield*/, this.deleteTraverse(relations, [model], modelConstructor.name, namespaceName, deleteQueue)];
|
|
795
933
|
case 14:
|
|
796
|
-
|
|
797
|
-
|
|
934
|
+
_a.sent();
|
|
935
|
+
_a.label = 15;
|
|
798
936
|
case 15: return [4 /*yield*/, this.deleteItem(deleteQueue)];
|
|
799
937
|
case 16:
|
|
800
|
-
|
|
938
|
+
_a.sent();
|
|
801
939
|
deletedModels = deleteQueue.reduce(function (acc, _a) {
|
|
802
940
|
var items = _a.items;
|
|
803
941
|
return acc.concat(items);
|
|
@@ -809,36 +947,37 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
809
947
|
});
|
|
810
948
|
};
|
|
811
949
|
IndexedDBAdapter.prototype.deleteItem = function (deleteQueue) {
|
|
950
|
+
var deleteQueue_1, deleteQueue_1_1;
|
|
812
951
|
var e_7, _a, e_8, _b;
|
|
813
952
|
return __awaiter(this, void 0, void 0, function () {
|
|
814
|
-
var connectionStoreNames, tx,
|
|
815
|
-
return __generator(this, function (
|
|
816
|
-
switch (
|
|
953
|
+
var connectionStoreNames, tx, deleteItem, storeName, items, store, items_1, items_1_1, item, key, keyValues, itemKey, e_8_1, e_7_1;
|
|
954
|
+
return __generator(this, function (_c) {
|
|
955
|
+
switch (_c.label) {
|
|
817
956
|
case 0:
|
|
818
957
|
connectionStoreNames = deleteQueue.map(function (_a) {
|
|
819
958
|
var storeName = _a.storeName;
|
|
820
959
|
return storeName;
|
|
821
960
|
});
|
|
822
961
|
tx = this.db.transaction(__spread(connectionStoreNames), 'readwrite');
|
|
823
|
-
|
|
962
|
+
_c.label = 1;
|
|
824
963
|
case 1:
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
case 2: return [4 /*yield*/,
|
|
964
|
+
_c.trys.push([1, 22, 23, 28]);
|
|
965
|
+
deleteQueue_1 = __asyncValues(deleteQueue);
|
|
966
|
+
_c.label = 2;
|
|
967
|
+
case 2: return [4 /*yield*/, deleteQueue_1.next()];
|
|
829
968
|
case 3:
|
|
830
|
-
if (!(
|
|
831
|
-
deleteItem =
|
|
969
|
+
if (!(deleteQueue_1_1 = _c.sent(), !deleteQueue_1_1.done)) return [3 /*break*/, 21];
|
|
970
|
+
deleteItem = deleteQueue_1_1.value;
|
|
832
971
|
storeName = deleteItem.storeName, items = deleteItem.items;
|
|
833
972
|
store = tx.objectStore(storeName);
|
|
834
|
-
|
|
973
|
+
_c.label = 4;
|
|
835
974
|
case 4:
|
|
836
|
-
|
|
975
|
+
_c.trys.push([4, 14, 15, 20]);
|
|
837
976
|
items_1 = __asyncValues(items);
|
|
838
|
-
|
|
977
|
+
_c.label = 5;
|
|
839
978
|
case 5: return [4 /*yield*/, items_1.next()];
|
|
840
979
|
case 6:
|
|
841
|
-
if (!(items_1_1 =
|
|
980
|
+
if (!(items_1_1 = _c.sent(), !items_1_1.done)) return [3 /*break*/, 13];
|
|
842
981
|
item = items_1_1.value;
|
|
843
982
|
if (!item) return [3 /*break*/, 12];
|
|
844
983
|
key = void 0;
|
|
@@ -848,33 +987,33 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
848
987
|
.index('byPk')
|
|
849
988
|
.getKey(this.canonicalKeyPath(keyValues))];
|
|
850
989
|
case 7:
|
|
851
|
-
key =
|
|
990
|
+
key = _c.sent();
|
|
852
991
|
return [3 /*break*/, 10];
|
|
853
992
|
case 8:
|
|
854
993
|
itemKey = item.toString();
|
|
855
994
|
return [4 /*yield*/, store.index('byPk').getKey(itemKey)];
|
|
856
995
|
case 9:
|
|
857
|
-
key =
|
|
858
|
-
|
|
996
|
+
key = _c.sent();
|
|
997
|
+
_c.label = 10;
|
|
859
998
|
case 10:
|
|
860
999
|
if (!(key !== undefined)) return [3 /*break*/, 12];
|
|
861
1000
|
return [4 /*yield*/, store.delete(key)];
|
|
862
1001
|
case 11:
|
|
863
|
-
|
|
864
|
-
|
|
1002
|
+
_c.sent();
|
|
1003
|
+
_c.label = 12;
|
|
865
1004
|
case 12: return [3 /*break*/, 5];
|
|
866
1005
|
case 13: return [3 /*break*/, 20];
|
|
867
1006
|
case 14:
|
|
868
|
-
e_8_1 =
|
|
1007
|
+
e_8_1 = _c.sent();
|
|
869
1008
|
e_8 = { error: e_8_1 };
|
|
870
1009
|
return [3 /*break*/, 20];
|
|
871
1010
|
case 15:
|
|
872
|
-
|
|
1011
|
+
_c.trys.push([15, , 18, 19]);
|
|
873
1012
|
if (!(items_1_1 && !items_1_1.done && (_b = items_1.return))) return [3 /*break*/, 17];
|
|
874
1013
|
return [4 /*yield*/, _b.call(items_1)];
|
|
875
1014
|
case 16:
|
|
876
|
-
|
|
877
|
-
|
|
1015
|
+
_c.sent();
|
|
1016
|
+
_c.label = 17;
|
|
878
1017
|
case 17: return [3 /*break*/, 19];
|
|
879
1018
|
case 18:
|
|
880
1019
|
if (e_8) throw e_8.error;
|
|
@@ -883,16 +1022,16 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
883
1022
|
case 20: return [3 /*break*/, 2];
|
|
884
1023
|
case 21: return [3 /*break*/, 28];
|
|
885
1024
|
case 22:
|
|
886
|
-
e_7_1 =
|
|
1025
|
+
e_7_1 = _c.sent();
|
|
887
1026
|
e_7 = { error: e_7_1 };
|
|
888
1027
|
return [3 /*break*/, 28];
|
|
889
1028
|
case 23:
|
|
890
|
-
|
|
891
|
-
if (!(
|
|
892
|
-
return [4 /*yield*/, _a.call(
|
|
1029
|
+
_c.trys.push([23, , 26, 27]);
|
|
1030
|
+
if (!(deleteQueue_1_1 && !deleteQueue_1_1.done && (_a = deleteQueue_1.return))) return [3 /*break*/, 25];
|
|
1031
|
+
return [4 /*yield*/, _a.call(deleteQueue_1)];
|
|
893
1032
|
case 24:
|
|
894
|
-
|
|
895
|
-
|
|
1033
|
+
_c.sent();
|
|
1034
|
+
_c.label = 25;
|
|
896
1035
|
case 25: return [3 /*break*/, 27];
|
|
897
1036
|
case 26:
|
|
898
1037
|
if (e_7) throw e_7.error;
|
|
@@ -904,7 +1043,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
904
1043
|
});
|
|
905
1044
|
};
|
|
906
1045
|
IndexedDBAdapter.prototype.deleteTraverse = function (relations, models, srcModel, nameSpace, deleteQueue) {
|
|
907
|
-
var
|
|
1046
|
+
var relations_2, relations_2_1, models_1, models_1_1, models_2, models_2_1;
|
|
908
1047
|
var e_9, _a, e_10, _b, e_11, _c;
|
|
909
1048
|
return __awaiter(this, void 0, void 0, function () {
|
|
910
1049
|
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;
|
|
@@ -913,12 +1052,12 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
913
1052
|
switch (_e.label) {
|
|
914
1053
|
case 0:
|
|
915
1054
|
_e.trys.push([0, 38, 39, 44]);
|
|
916
|
-
|
|
1055
|
+
relations_2 = __asyncValues(relations);
|
|
917
1056
|
_e.label = 1;
|
|
918
|
-
case 1: return [4 /*yield*/,
|
|
1057
|
+
case 1: return [4 /*yield*/, relations_2.next()];
|
|
919
1058
|
case 2:
|
|
920
|
-
if (!(
|
|
921
|
-
rel =
|
|
1059
|
+
if (!(relations_2_1 = _e.sent(), !relations_2_1.done)) return [3 /*break*/, 37];
|
|
1060
|
+
rel = relations_2_1.value;
|
|
922
1061
|
relationType = rel.relationType, modelName = rel.modelName, targetName = rel.targetName, targetNames = rel.targetNames, associatedWith = rel.associatedWith;
|
|
923
1062
|
storeName = getStorename(nameSpace, modelName);
|
|
924
1063
|
_d = relationType;
|
|
@@ -1055,7 +1194,9 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1055
1194
|
case 34:
|
|
1056
1195
|
// Intentionally blank
|
|
1057
1196
|
return [3 /*break*/, 36];
|
|
1058
|
-
case 35:
|
|
1197
|
+
case 35:
|
|
1198
|
+
exhaustiveCheck(relationType);
|
|
1199
|
+
return [3 /*break*/, 36];
|
|
1059
1200
|
case 36: return [3 /*break*/, 1];
|
|
1060
1201
|
case 37: return [3 /*break*/, 44];
|
|
1061
1202
|
case 38:
|
|
@@ -1064,8 +1205,8 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1064
1205
|
return [3 /*break*/, 44];
|
|
1065
1206
|
case 39:
|
|
1066
1207
|
_e.trys.push([39, , 42, 43]);
|
|
1067
|
-
if (!(
|
|
1068
|
-
return [4 /*yield*/, _a.call(
|
|
1208
|
+
if (!(relations_2_1 && !relations_2_1.done && (_a = relations_2.return))) return [3 /*break*/, 41];
|
|
1209
|
+
return [4 /*yield*/, _a.call(relations_2)];
|
|
1069
1210
|
case 40:
|
|
1070
1211
|
_e.sent();
|
|
1071
1212
|
_e.label = 41;
|