@aws-amplify/datastore 3.12.6-next.13 → 3.12.6-next.32
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 +58 -0
- package/lib/authModeStrategies/multiAuthStrategy.js +17 -64
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.js +682 -469
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/index.js +2 -4
- package/lib/index.js.map +1 -1
- package/lib/predicates/index.js +12 -2
- package/lib/predicates/index.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +393 -298
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js +97 -122
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.js +16 -67
- package/lib/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.native.js +2 -4
- package/lib/storage/adapter/InMemoryStore.native.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +497 -404
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- 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.js +2 -4
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +1 -1
- package/lib/storage/storage.js +129 -151
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.js +13 -17
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/datastoreReachability/index.native.js +2 -4
- package/lib/sync/datastoreReachability/index.native.js.map +1 -1
- package/lib/sync/index.js +544 -488
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.js +21 -80
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.js +95 -162
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/errorMaps.js +4 -34
- package/lib/sync/processors/errorMaps.js.map +1 -1
- package/lib/sync/processors/mutation.js +285 -312
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.js +218 -259
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.js +141 -212
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.js +50 -61
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.js +13 -39
- package/lib/types.js.map +1 -1
- package/lib/util.js +429 -242
- package/lib/util.js.map +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.d.ts +11 -0
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +13 -57
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +107 -17
- package/lib-esm/datastore/datastore.js +649 -433
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/index.d.ts +3 -19
- package/lib-esm/predicates/index.d.ts +3 -2
- package/lib-esm/predicates/index.js +13 -3
- package/lib-esm/predicates/index.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.d.ts +4 -3
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +356 -258
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.d.ts +14 -4
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +67 -92
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +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 +26 -4
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +446 -346
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/index.d.ts +1 -1
- package/lib-esm/storage/storage.d.ts +1 -1
- package/lib-esm/storage/storage.js +94 -113
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -0
- package/lib-esm/sync/datastoreConnectivity.js +10 -11
- package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
- package/lib-esm/sync/index.d.ts +31 -5
- package/lib-esm/sync/index.js +525 -466
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.d.ts +9 -3
- package/lib-esm/sync/merger.js +14 -73
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.d.ts +2 -2
- package/lib-esm/sync/outbox.js +79 -146
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.js +1 -31
- package/lib-esm/sync/processors/errorMaps.js.map +1 -1
- package/lib-esm/sync/processors/mutation.d.ts +2 -0
- package/lib-esm/sync/processors/mutation.js +271 -295
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.d.ts +2 -0
- package/lib-esm/sync/processors/subscription.js +214 -245
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.d.ts +2 -1
- package/lib-esm/sync/processors/sync.js +127 -195
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.d.ts +3 -2
- package/lib-esm/sync/utils.js +45 -57
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +65 -26
- package/lib-esm/types.js +10 -38
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +67 -24
- package/lib-esm/util.js +420 -233
- package/lib-esm/util.js.map +1 -1
- package/package.json +14 -7
- package/src/authModeStrategies/multiAuthStrategy.ts +12 -1
- package/src/datastore/datastore.ts +798 -397
- package/src/predicates/index.ts +32 -10
- package/src/storage/adapter/AsyncStorageAdapter.ts +309 -93
- package/src/storage/adapter/AsyncStorageDatabase.ts +74 -26
- package/src/storage/adapter/IndexedDBAdapter.ts +358 -134
- package/src/storage/adapter/index.ts +1 -1
- package/src/storage/storage.ts +69 -22
- package/src/sync/datastoreConnectivity.ts +6 -0
- package/src/sync/index.ts +521 -412
- package/src/sync/merger.ts +20 -4
- package/src/sync/outbox.ts +22 -9
- package/src/sync/processors/mutation.ts +188 -150
- package/src/sync/processors/subscription.ts +289 -253
- package/src/sync/processors/sync.ts +151 -138
- package/src/sync/utils.ts +67 -12
- package/src/types.ts +182 -30
- package/src/util.ts +505 -176
- package/build.js +0 -5
- package/dist/aws-amplify-datastore.js +0 -98255
- 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/lib/authModeStrategies/defaultAuthStrategy.d.ts +0 -2
- package/lib/authModeStrategies/index.d.ts +0 -2
- package/lib/authModeStrategies/multiAuthStrategy.d.ts +0 -2
- package/lib/datastore/datastore.d.ts +0 -66
- package/lib/index.d.ts +0 -31
- package/lib/predicates/index.d.ts +0 -15
- package/lib/predicates/sort.d.ts +0 -8
- package/lib/ssr/index.d.ts +0 -3
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +0 -40
- package/lib/storage/adapter/AsyncStorageDatabase.d.ts +0 -29
- 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 -37
- 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/storage.d.ts +0 -49
- package/lib/sync/datastoreConnectivity.d.ts +0 -15
- 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 -63
- package/lib/sync/merger.d.ts +0 -11
- 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 -56
- package/lib/sync/processors/subscription.d.ts +0 -31
- package/lib/sync/processors/sync.d.ts +0 -27
- package/lib/sync/utils.d.ts +0 -41
- package/lib/types.d.ts +0 -462
- package/lib/util.d.ts +0 -113
- 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 __values = (this && this.__values) || function(o) {
|
|
46
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
47
|
-
if (m) return m.call(o);
|
|
48
|
-
if (o && typeof o.length === "number") return {
|
|
49
|
-
next: function () {
|
|
50
|
-
if (o && i >= o.length) o = void 0;
|
|
51
|
-
return { value: o && o[i++], done: !o };
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
55
|
-
};
|
|
56
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
57
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
58
|
-
if (!m) return o;
|
|
59
|
-
var i = m.call(o), r, ar = [], e;
|
|
60
|
-
try {
|
|
61
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
62
|
-
}
|
|
63
|
-
catch (error) { e = { error: error }; }
|
|
64
|
-
finally {
|
|
65
|
-
try {
|
|
66
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
67
|
-
}
|
|
68
|
-
finally { if (e) throw e.error; }
|
|
69
|
-
}
|
|
70
|
-
return ar;
|
|
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");
|
|
@@ -90,12 +10,41 @@ var logger = new core_1.ConsoleLogger('DataStore');
|
|
|
90
10
|
var DB_NAME = 'amplify-datastore';
|
|
91
11
|
var IndexedDBAdapter = /** @class */ (function () {
|
|
92
12
|
function IndexedDBAdapter() {
|
|
13
|
+
var _this = this;
|
|
93
14
|
this.dbName = DB_NAME;
|
|
15
|
+
this.safariCompatabilityMode = false;
|
|
16
|
+
/**
|
|
17
|
+
* Checks the given path against the browser's IndexedDB implementation for
|
|
18
|
+
* necessary compatibility transformations, applying those transforms if needed.
|
|
19
|
+
*
|
|
20
|
+
* @param `keyArr` strings to compatibilize for browser-indexeddb index operations
|
|
21
|
+
* @returns An array or string, depending on and given key,
|
|
22
|
+
* that is ensured to be compatible with the IndexedDB implementation's nuances.
|
|
23
|
+
*/
|
|
24
|
+
this.canonicalKeyPath = function (keyArr) {
|
|
25
|
+
if (_this.safariCompatabilityMode) {
|
|
26
|
+
return keyArr.length > 1 ? keyArr : keyArr[0];
|
|
27
|
+
}
|
|
28
|
+
return keyArr;
|
|
29
|
+
};
|
|
94
30
|
}
|
|
31
|
+
IndexedDBAdapter.prototype.getStorenameForModel = function (modelConstructor) {
|
|
32
|
+
var namespace = this.namespaceResolver(modelConstructor);
|
|
33
|
+
var modelName = modelConstructor.name;
|
|
34
|
+
return util_1.getStorename(namespace, modelName);
|
|
35
|
+
};
|
|
36
|
+
// Retrieves primary key values from a model
|
|
37
|
+
IndexedDBAdapter.prototype.getIndexKeyValuesFromModel = function (model) {
|
|
38
|
+
var modelConstructor = Object.getPrototypeOf(model)
|
|
39
|
+
.constructor;
|
|
40
|
+
var namespaceName = this.namespaceResolver(modelConstructor);
|
|
41
|
+
var keys = util_1.getIndexKeys(this.schema.namespaces[namespaceName], modelConstructor.name);
|
|
42
|
+
return util_1.extractPrimaryKeyValues(model, keys);
|
|
43
|
+
};
|
|
95
44
|
IndexedDBAdapter.prototype.checkPrivate = function () {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
97
46
|
var isPrivate;
|
|
98
|
-
return __generator(this, function (_a) {
|
|
47
|
+
return tslib_1.__generator(this, function (_a) {
|
|
99
48
|
switch (_a.label) {
|
|
100
49
|
case 0: return [4 /*yield*/, util_1.isPrivateMode().then(function (isPrivate) {
|
|
101
50
|
return isPrivate;
|
|
@@ -114,35 +63,64 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
114
63
|
});
|
|
115
64
|
});
|
|
116
65
|
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Whether the browser's implementation of IndexedDB is coercing single-field
|
|
68
|
+
* indexes to a scalar key.
|
|
69
|
+
*
|
|
70
|
+
* If this returns `true`, we need to treat indexes containing a single field
|
|
71
|
+
* as scalars.
|
|
72
|
+
*
|
|
73
|
+
* See PR description for reference:
|
|
74
|
+
* https://github.com/aws-amplify/amplify-js/pull/10527
|
|
75
|
+
*/
|
|
76
|
+
IndexedDBAdapter.prototype.setSafariCompatabilityMode = function () {
|
|
77
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
78
|
+
var _a;
|
|
79
|
+
return tslib_1.__generator(this, function (_b) {
|
|
80
|
+
switch (_b.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
_a = this;
|
|
83
|
+
return [4 /*yield*/, util_1.isSafariCompatabilityMode()];
|
|
84
|
+
case 1:
|
|
85
|
+
_a.safariCompatabilityMode = _b.sent();
|
|
86
|
+
if (this.safariCompatabilityMode === true) {
|
|
87
|
+
logger.debug('IndexedDB Adapter is running in Safari Compatability Mode');
|
|
88
|
+
}
|
|
89
|
+
return [2 /*return*/];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
121
93
|
};
|
|
122
|
-
IndexedDBAdapter.prototype.
|
|
123
|
-
var storeName =
|
|
124
|
-
return
|
|
94
|
+
IndexedDBAdapter.prototype.getNamespaceAndModelFromStorename = function (storeName) {
|
|
95
|
+
var _a = tslib_1.__read(storeName.split('_')), namespaceName = _a[0], modelNameArr = _a.slice(1);
|
|
96
|
+
return {
|
|
97
|
+
namespaceName: namespaceName,
|
|
98
|
+
modelName: modelNameArr.join('_'),
|
|
99
|
+
};
|
|
125
100
|
};
|
|
126
101
|
IndexedDBAdapter.prototype.setUp = function (theSchema, namespaceResolver, modelInstanceCreator, getModelConstructorByModelName, sessionId) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
128
103
|
var VERSION, _a, error_1;
|
|
129
104
|
var _this = this;
|
|
130
|
-
return __generator(this, function (_b) {
|
|
105
|
+
return tslib_1.__generator(this, function (_b) {
|
|
131
106
|
switch (_b.label) {
|
|
132
107
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
133
108
|
case 1:
|
|
134
109
|
_b.sent();
|
|
135
|
-
|
|
110
|
+
return [4 /*yield*/, this.setSafariCompatabilityMode()];
|
|
111
|
+
case 2:
|
|
112
|
+
_b.sent();
|
|
113
|
+
if (!!this.initPromise) return [3 /*break*/, 3];
|
|
136
114
|
this.initPromise = new Promise(function (res, rej) {
|
|
137
115
|
_this.resolve = res;
|
|
138
116
|
_this.reject = rej;
|
|
139
117
|
});
|
|
140
|
-
return [3 /*break*/,
|
|
141
|
-
case
|
|
142
|
-
case 3:
|
|
143
|
-
_b.sent();
|
|
144
|
-
_b.label = 4;
|
|
118
|
+
return [3 /*break*/, 5];
|
|
119
|
+
case 3: return [4 /*yield*/, this.initPromise];
|
|
145
120
|
case 4:
|
|
121
|
+
_b.sent();
|
|
122
|
+
_b.label = 5;
|
|
123
|
+
case 5:
|
|
146
124
|
if (sessionId) {
|
|
147
125
|
this.dbName = DB_NAME + "-" + sessionId;
|
|
148
126
|
}
|
|
@@ -150,83 +128,80 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
150
128
|
this.namespaceResolver = namespaceResolver;
|
|
151
129
|
this.modelInstanceCreator = modelInstanceCreator;
|
|
152
130
|
this.getModelConstructorByModelName = getModelConstructorByModelName;
|
|
153
|
-
_b.label =
|
|
154
|
-
case
|
|
155
|
-
_b.trys.push([
|
|
156
|
-
if (!!this.db) return [3 /*break*/,
|
|
157
|
-
VERSION =
|
|
131
|
+
_b.label = 6;
|
|
132
|
+
case 6:
|
|
133
|
+
_b.trys.push([6, 9, , 10]);
|
|
134
|
+
if (!!this.db) return [3 /*break*/, 8];
|
|
135
|
+
VERSION = 3;
|
|
158
136
|
_a = this;
|
|
159
137
|
return [4 /*yield*/, idb.openDB(this.dbName, VERSION, {
|
|
160
|
-
upgrade: function (db, oldVersion, newVersion, txn) { return __awaiter(_this, void 0, void 0, function () {
|
|
161
|
-
var _a, _b, storeName, origStore, tmpName, newStore, cursor, count, e_1_1, error_2;
|
|
162
|
-
var e_1,
|
|
138
|
+
upgrade: function (db, oldVersion, newVersion, txn) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
139
|
+
var _a, _b, storeName, origStore, tmpName, _c, namespaceName, modelName, newStore, cursor, count, e_1_1, error_2;
|
|
140
|
+
var e_1, _d;
|
|
163
141
|
var _this = this;
|
|
164
|
-
return __generator(this, function (
|
|
165
|
-
switch (
|
|
142
|
+
return tslib_1.__generator(this, function (_e) {
|
|
143
|
+
switch (_e.label) {
|
|
166
144
|
case 0:
|
|
167
145
|
if (oldVersion === 0) {
|
|
168
146
|
Object.keys(theSchema.namespaces).forEach(function (namespaceName) {
|
|
169
147
|
var namespace = theSchema.namespaces[namespaceName];
|
|
170
148
|
Object.keys(namespace.models).forEach(function (modelName) {
|
|
171
|
-
var storeName =
|
|
149
|
+
var storeName = util_1.getStorename(namespaceName, modelName);
|
|
172
150
|
_this.createObjectStoreForModel(db, namespaceName, storeName, modelName);
|
|
173
151
|
});
|
|
174
152
|
});
|
|
175
153
|
return [2 /*return*/];
|
|
176
154
|
}
|
|
177
|
-
if (!(oldVersion === 1 && newVersion ===
|
|
178
|
-
|
|
155
|
+
if (!((oldVersion === 1 || oldVersion === 2) && newVersion === 3)) return [3 /*break*/, 16];
|
|
156
|
+
_e.label = 1;
|
|
179
157
|
case 1:
|
|
180
|
-
|
|
181
|
-
|
|
158
|
+
_e.trys.push([1, 14, , 15]);
|
|
159
|
+
_e.label = 2;
|
|
182
160
|
case 2:
|
|
183
|
-
|
|
184
|
-
_a = __values(txn.objectStoreNames), _b = _a.next();
|
|
185
|
-
|
|
161
|
+
_e.trys.push([2, 11, 12, 13]);
|
|
162
|
+
_a = tslib_1.__values(txn.objectStoreNames), _b = _a.next();
|
|
163
|
+
_e.label = 3;
|
|
186
164
|
case 3:
|
|
187
165
|
if (!!_b.done) return [3 /*break*/, 10];
|
|
188
166
|
storeName = _b.value;
|
|
189
167
|
origStore = txn.objectStore(storeName);
|
|
190
168
|
tmpName = "tmp_" + storeName;
|
|
191
169
|
origStore.name = tmpName;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
autoIncrement: true,
|
|
195
|
-
});
|
|
196
|
-
newStore.createIndex('byId', 'id', { unique: true });
|
|
170
|
+
_c = this.getNamespaceAndModelFromStorename(storeName), namespaceName = _c.namespaceName, modelName = _c.modelName;
|
|
171
|
+
newStore = this.createObjectStoreForModel(db, namespaceName, storeName, modelName);
|
|
197
172
|
return [4 /*yield*/, origStore.openCursor()];
|
|
198
173
|
case 4:
|
|
199
|
-
cursor =
|
|
174
|
+
cursor = _e.sent();
|
|
200
175
|
count = 0;
|
|
201
|
-
|
|
176
|
+
_e.label = 5;
|
|
202
177
|
case 5:
|
|
203
178
|
if (!(cursor && cursor.value)) return [3 /*break*/, 8];
|
|
204
179
|
// we don't pass key, since they are all new entries in the new store
|
|
205
180
|
return [4 /*yield*/, newStore.put(cursor.value)];
|
|
206
181
|
case 6:
|
|
207
182
|
// we don't pass key, since they are all new entries in the new store
|
|
208
|
-
|
|
183
|
+
_e.sent();
|
|
209
184
|
return [4 /*yield*/, cursor.continue()];
|
|
210
185
|
case 7:
|
|
211
|
-
cursor =
|
|
186
|
+
cursor = _e.sent();
|
|
212
187
|
count++;
|
|
213
188
|
return [3 /*break*/, 5];
|
|
214
189
|
case 8:
|
|
215
190
|
// delete original
|
|
216
191
|
db.deleteObjectStore(tmpName);
|
|
217
192
|
logger.debug(count + " " + storeName + " records migrated");
|
|
218
|
-
|
|
193
|
+
_e.label = 9;
|
|
219
194
|
case 9:
|
|
220
195
|
_b = _a.next();
|
|
221
196
|
return [3 /*break*/, 3];
|
|
222
197
|
case 10: return [3 /*break*/, 13];
|
|
223
198
|
case 11:
|
|
224
|
-
e_1_1 =
|
|
199
|
+
e_1_1 = _e.sent();
|
|
225
200
|
e_1 = { error: e_1_1 };
|
|
226
201
|
return [3 /*break*/, 13];
|
|
227
202
|
case 12:
|
|
228
203
|
try {
|
|
229
|
-
if (_b && !_b.done && (
|
|
204
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
230
205
|
}
|
|
231
206
|
finally { if (e_1) throw e_1.error; }
|
|
232
207
|
return [7 /*endfinally*/];
|
|
@@ -241,21 +216,21 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
241
216
|
.map(function (modelName) {
|
|
242
217
|
return [
|
|
243
218
|
modelName,
|
|
244
|
-
|
|
219
|
+
util_1.getStorename(namespaceName, modelName),
|
|
245
220
|
];
|
|
246
221
|
})
|
|
247
222
|
.filter(function (_a) {
|
|
248
|
-
var _b = __read(_a, 2), storeName = _b[1];
|
|
223
|
+
var _b = tslib_1.__read(_a, 2), storeName = _b[1];
|
|
249
224
|
return !objectStoreNames.has(storeName);
|
|
250
225
|
})
|
|
251
226
|
.forEach(function (_a) {
|
|
252
|
-
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];
|
|
253
228
|
_this.createObjectStoreForModel(db, namespaceName, storeName, modelName);
|
|
254
229
|
});
|
|
255
230
|
});
|
|
256
231
|
return [3 /*break*/, 15];
|
|
257
232
|
case 14:
|
|
258
|
-
error_2 =
|
|
233
|
+
error_2 = _e.sent();
|
|
259
234
|
logger.error('Error migrating IndexedDB data', error_2);
|
|
260
235
|
txn.abort();
|
|
261
236
|
throw error_2;
|
|
@@ -265,35 +240,35 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
265
240
|
});
|
|
266
241
|
}); },
|
|
267
242
|
})];
|
|
268
|
-
case
|
|
243
|
+
case 7:
|
|
269
244
|
_a.db = _b.sent();
|
|
270
245
|
this.resolve();
|
|
271
|
-
_b.label =
|
|
272
|
-
case
|
|
273
|
-
case
|
|
246
|
+
_b.label = 8;
|
|
247
|
+
case 8: return [3 /*break*/, 10];
|
|
248
|
+
case 9:
|
|
274
249
|
error_1 = _b.sent();
|
|
275
250
|
this.reject(error_1);
|
|
276
|
-
return [3 /*break*/,
|
|
277
|
-
case
|
|
251
|
+
return [3 /*break*/, 10];
|
|
252
|
+
case 10: return [2 /*return*/];
|
|
278
253
|
}
|
|
279
254
|
});
|
|
280
255
|
});
|
|
281
256
|
};
|
|
282
|
-
IndexedDBAdapter.prototype._get = function (storeOrStoreName,
|
|
283
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
257
|
+
IndexedDBAdapter.prototype._get = function (storeOrStoreName, keyArr) {
|
|
258
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
284
259
|
var index, storeName, store, result;
|
|
285
|
-
return __generator(this, function (_a) {
|
|
260
|
+
return tslib_1.__generator(this, function (_a) {
|
|
286
261
|
switch (_a.label) {
|
|
287
262
|
case 0:
|
|
288
263
|
if (typeof storeOrStoreName === 'string') {
|
|
289
264
|
storeName = storeOrStoreName;
|
|
290
|
-
index = this.db.transaction(storeName, 'readonly').store.index('
|
|
265
|
+
index = this.db.transaction(storeName, 'readonly').store.index('byPk');
|
|
291
266
|
}
|
|
292
267
|
else {
|
|
293
268
|
store = storeOrStoreName;
|
|
294
|
-
index = store.index('
|
|
269
|
+
index = store.index('byPk');
|
|
295
270
|
}
|
|
296
|
-
return [4 /*yield*/, index.get(
|
|
271
|
+
return [4 /*yield*/, index.get(this.canonicalKeyPath(keyArr))];
|
|
297
272
|
case 1:
|
|
298
273
|
result = _a.sent();
|
|
299
274
|
return [2 /*return*/, result];
|
|
@@ -303,10 +278,10 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
303
278
|
};
|
|
304
279
|
IndexedDBAdapter.prototype.save = function (model, condition) {
|
|
305
280
|
var e_2, _a;
|
|
306
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
307
|
-
var modelConstructor, storeName,
|
|
281
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
282
|
+
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;
|
|
308
283
|
var _this = this;
|
|
309
|
-
return __generator(this, function (_b) {
|
|
284
|
+
return tslib_1.__generator(this, function (_b) {
|
|
310
285
|
switch (_b.label) {
|
|
311
286
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
312
287
|
case 1:
|
|
@@ -314,18 +289,20 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
314
289
|
modelConstructor = Object.getPrototypeOf(model)
|
|
315
290
|
.constructor;
|
|
316
291
|
storeName = this.getStorenameForModel(modelConstructor);
|
|
317
|
-
connectedModels = util_1.traverseModel(modelConstructor.name, model, this.schema.namespaces[this.namespaceResolver(modelConstructor)], this.modelInstanceCreator, this.getModelConstructorByModelName);
|
|
318
292
|
namespaceName = this.namespaceResolver(modelConstructor);
|
|
293
|
+
connectedModels = util_1.traverseModel(modelConstructor.name, model, this.schema.namespaces[namespaceName], this.modelInstanceCreator, this.getModelConstructorByModelName);
|
|
319
294
|
set = new Set();
|
|
320
295
|
connectionStoreNames = Object.values(connectedModels).map(function (_a) {
|
|
321
296
|
var modelName = _a.modelName, item = _a.item, instance = _a.instance;
|
|
322
|
-
var storeName =
|
|
297
|
+
var storeName = util_1.getStorename(namespaceName, modelName);
|
|
323
298
|
set.add(storeName);
|
|
324
|
-
|
|
299
|
+
var keys = util_1.getIndexKeys(_this.schema.namespaces[namespaceName], modelName);
|
|
300
|
+
return { storeName: storeName, item: item, instance: instance, keys: keys };
|
|
325
301
|
});
|
|
326
|
-
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');
|
|
327
303
|
store = tx.objectStore(storeName);
|
|
328
|
-
|
|
304
|
+
keyValues = this.getIndexKeyValuesFromModel(model);
|
|
305
|
+
return [4 /*yield*/, this._get(store, keyValues)];
|
|
329
306
|
case 2:
|
|
330
307
|
fromDB = _b.sent();
|
|
331
308
|
if (condition && fromDB) {
|
|
@@ -342,21 +319,28 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
342
319
|
_b.label = 3;
|
|
343
320
|
case 3:
|
|
344
321
|
_b.trys.push([3, 11, 12, 17]);
|
|
345
|
-
connectionStoreNames_1 = __asyncValues(connectionStoreNames);
|
|
322
|
+
connectionStoreNames_1 = tslib_1.__asyncValues(connectionStoreNames);
|
|
346
323
|
_b.label = 4;
|
|
347
324
|
case 4: return [4 /*yield*/, connectionStoreNames_1.next()];
|
|
348
325
|
case 5:
|
|
349
326
|
if (!(connectionStoreNames_1_1 = _b.sent(), !connectionStoreNames_1_1.done)) return [3 /*break*/, 10];
|
|
350
327
|
resItem = connectionStoreNames_1_1.value;
|
|
351
|
-
storeName_1 = resItem.storeName, item = resItem.item, instance = resItem.instance;
|
|
328
|
+
storeName_1 = resItem.storeName, item = resItem.item, instance = resItem.instance, keys = resItem.keys;
|
|
352
329
|
store_1 = tx.objectStore(storeName_1);
|
|
353
|
-
|
|
354
|
-
|
|
330
|
+
itemKeyValues = keys.map(function (key) {
|
|
331
|
+
var value = item[key];
|
|
332
|
+
return value;
|
|
333
|
+
});
|
|
334
|
+
return [4 /*yield*/, this._get(store_1, itemKeyValues)];
|
|
355
335
|
case 6:
|
|
356
336
|
fromDB_1 = _b.sent();
|
|
357
337
|
opType = fromDB_1 === undefined ? types_1.OpType.INSERT : types_1.OpType.UPDATE;
|
|
358
|
-
|
|
359
|
-
|
|
338
|
+
modelKeyValues = this.getIndexKeyValuesFromModel(model);
|
|
339
|
+
if (!(util_1.keysEqual(itemKeyValues, modelKeyValues) ||
|
|
340
|
+
opType === types_1.OpType.INSERT)) return [3 /*break*/, 9];
|
|
341
|
+
return [4 /*yield*/, store_1
|
|
342
|
+
.index('byPk')
|
|
343
|
+
.getKey(this.canonicalKeyPath(itemKeyValues))];
|
|
360
344
|
case 7:
|
|
361
345
|
key = _b.sent();
|
|
362
346
|
return [4 /*yield*/, store_1.put(item, key)];
|
|
@@ -393,17 +377,17 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
393
377
|
IndexedDBAdapter.prototype.load = function (namespaceName, srcModelName, records) {
|
|
394
378
|
var records_1, records_1_1, records_2, records_2_1;
|
|
395
379
|
var e_3, _a, e_4, _b, e_5, _c;
|
|
396
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
397
|
-
var namespace, relations, connectionStoreNames, modelConstructor, tx, relations_1, relations_1_1, relation, fieldName, modelName, targetName, storeName, store, modelConstructor_1, _d, recordItem, getByfield, connectionRecord, e_4_1, recordItem, connectionRecord, e_5_1, e_3_1;
|
|
380
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
381
|
+
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;
|
|
398
382
|
var _this = this;
|
|
399
|
-
return __generator(this, function (_e) {
|
|
383
|
+
return tslib_1.__generator(this, function (_e) {
|
|
400
384
|
switch (_e.label) {
|
|
401
385
|
case 0:
|
|
402
386
|
namespace = this.schema.namespaces[namespaceName];
|
|
403
387
|
relations = namespace.relationships[srcModelName].relationTypes;
|
|
404
388
|
connectionStoreNames = relations.map(function (_a) {
|
|
405
389
|
var modelName = _a.modelName;
|
|
406
|
-
return
|
|
390
|
+
return util_1.getStorename(namespaceName, modelName);
|
|
407
391
|
});
|
|
408
392
|
modelConstructor = this.getModelConstructorByModelName(namespaceName, srcModelName);
|
|
409
393
|
if (connectionStoreNames.length === 0) {
|
|
@@ -411,125 +395,173 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
411
395
|
return _this.modelInstanceCreator(modelConstructor, record);
|
|
412
396
|
})];
|
|
413
397
|
}
|
|
414
|
-
tx = this.db.transaction(__spread(connectionStoreNames), 'readonly');
|
|
398
|
+
tx = this.db.transaction(tslib_1.__spread(connectionStoreNames), 'readonly');
|
|
415
399
|
_e.label = 1;
|
|
416
400
|
case 1:
|
|
417
|
-
_e.trys.push([1,
|
|
418
|
-
relations_1 = __asyncValues(relations);
|
|
401
|
+
_e.trys.push([1, 38, 39, 44]);
|
|
402
|
+
relations_1 = tslib_1.__asyncValues(relations);
|
|
419
403
|
_e.label = 2;
|
|
420
404
|
case 2: return [4 /*yield*/, relations_1.next()];
|
|
421
405
|
case 3:
|
|
422
|
-
if (!(relations_1_1 = _e.sent(), !relations_1_1.done)) return [3 /*break*/,
|
|
406
|
+
if (!(relations_1_1 = _e.sent(), !relations_1_1.done)) return [3 /*break*/, 37];
|
|
423
407
|
relation = relations_1_1.value;
|
|
424
|
-
fieldName = relation.fieldName, modelName = relation.modelName, targetName = relation.targetName;
|
|
425
|
-
storeName =
|
|
408
|
+
fieldName = relation.fieldName, modelName = relation.modelName, targetName = relation.targetName, targetNames = relation.targetNames;
|
|
409
|
+
storeName = util_1.getStorename(namespaceName, modelName);
|
|
426
410
|
store = tx.objectStore(storeName);
|
|
427
411
|
modelConstructor_1 = this.getModelConstructorByModelName(namespaceName, modelName);
|
|
428
412
|
_d = relation.relationType;
|
|
429
413
|
switch (_d) {
|
|
430
414
|
case 'HAS_ONE': return [3 /*break*/, 4];
|
|
431
|
-
case 'BELONGS_TO': return [3 /*break*/,
|
|
432
|
-
case 'HAS_MANY': return [3 /*break*/,
|
|
415
|
+
case 'BELONGS_TO': return [3 /*break*/, 19];
|
|
416
|
+
case 'HAS_MANY': return [3 /*break*/, 34];
|
|
433
417
|
}
|
|
434
|
-
return [3 /*break*/,
|
|
418
|
+
return [3 /*break*/, 35];
|
|
435
419
|
case 4:
|
|
436
|
-
_e.trys.push([4,
|
|
437
|
-
records_1 = __asyncValues(records);
|
|
420
|
+
_e.trys.push([4, 12, 13, 18]);
|
|
421
|
+
records_1 = tslib_1.__asyncValues(records);
|
|
438
422
|
_e.label = 5;
|
|
439
423
|
case 5: return [4 /*yield*/, records_1.next()];
|
|
440
424
|
case 6:
|
|
441
|
-
if (!(records_1_1 = _e.sent(), !records_1_1.done)) return [3 /*break*/,
|
|
425
|
+
if (!(records_1_1 = _e.sent(), !records_1_1.done)) return [3 /*break*/, 11];
|
|
442
426
|
recordItem = records_1_1.value;
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
427
|
+
if (!(targetNames === null || targetNames === void 0 ? void 0 : targetNames.length)) return [3 /*break*/, 8];
|
|
428
|
+
getByFields = [];
|
|
429
|
+
allPresent = void 0;
|
|
430
|
+
// iterate through all targetnames to make sure they are all present in the recordItem
|
|
431
|
+
allPresent = targetNames.every(function (targetName) {
|
|
432
|
+
return recordItem[targetName] != null;
|
|
433
|
+
});
|
|
434
|
+
if (!allPresent) {
|
|
435
|
+
return [3 /*break*/, 11];
|
|
436
|
+
}
|
|
437
|
+
getByFields = targetNames;
|
|
438
|
+
keys = getByFields.map(function (getByField) { return recordItem[getByField]; });
|
|
439
|
+
return [4 /*yield*/, this._get(store, keys)];
|
|
447
440
|
case 7:
|
|
448
441
|
connectionRecord = _e.sent();
|
|
449
442
|
recordItem[fieldName] =
|
|
450
443
|
connectionRecord &&
|
|
451
444
|
this.modelInstanceCreator(modelConstructor_1, connectionRecord);
|
|
452
|
-
|
|
453
|
-
case 8:
|
|
454
|
-
|
|
455
|
-
|
|
445
|
+
return [3 /*break*/, 10];
|
|
446
|
+
case 8:
|
|
447
|
+
getByfield = recordItem[targetName]
|
|
448
|
+
? targetName
|
|
449
|
+
: fieldName;
|
|
450
|
+
// We break here, because the recordItem does not have 'team', the `getByField`
|
|
451
|
+
// extract the keys on the related model.
|
|
452
|
+
if (!recordItem[getByfield])
|
|
453
|
+
return [3 /*break*/, 11];
|
|
454
|
+
key = [recordItem[getByfield]];
|
|
455
|
+
return [4 /*yield*/, this._get(store, key)];
|
|
456
|
+
case 9:
|
|
457
|
+
connectionRecord = _e.sent();
|
|
458
|
+
recordItem[fieldName] =
|
|
459
|
+
connectionRecord &&
|
|
460
|
+
this.modelInstanceCreator(modelConstructor_1, connectionRecord);
|
|
461
|
+
_e.label = 10;
|
|
462
|
+
case 10: return [3 /*break*/, 5];
|
|
463
|
+
case 11: return [3 /*break*/, 18];
|
|
464
|
+
case 12:
|
|
456
465
|
e_4_1 = _e.sent();
|
|
457
466
|
e_4 = { error: e_4_1 };
|
|
458
|
-
return [3 /*break*/,
|
|
459
|
-
case
|
|
460
|
-
_e.trys.push([
|
|
461
|
-
if (!(records_1_1 && !records_1_1.done && (_b = records_1.return))) return [3 /*break*/,
|
|
467
|
+
return [3 /*break*/, 18];
|
|
468
|
+
case 13:
|
|
469
|
+
_e.trys.push([13, , 16, 17]);
|
|
470
|
+
if (!(records_1_1 && !records_1_1.done && (_b = records_1.return))) return [3 /*break*/, 15];
|
|
462
471
|
return [4 /*yield*/, _b.call(records_1)];
|
|
463
|
-
case 12:
|
|
464
|
-
_e.sent();
|
|
465
|
-
_e.label = 13;
|
|
466
|
-
case 13: return [3 /*break*/, 15];
|
|
467
472
|
case 14:
|
|
473
|
+
_e.sent();
|
|
474
|
+
_e.label = 15;
|
|
475
|
+
case 15: return [3 /*break*/, 17];
|
|
476
|
+
case 16:
|
|
468
477
|
if (e_4) throw e_4.error;
|
|
469
478
|
return [7 /*endfinally*/];
|
|
470
|
-
case
|
|
471
|
-
case
|
|
472
|
-
case 17:
|
|
473
|
-
_e.trys.push([17, 23, 24, 29]);
|
|
474
|
-
records_2 = __asyncValues(records);
|
|
475
|
-
_e.label = 18;
|
|
476
|
-
case 18: return [4 /*yield*/, records_2.next()];
|
|
479
|
+
case 17: return [7 /*endfinally*/];
|
|
480
|
+
case 18: return [3 /*break*/, 36];
|
|
477
481
|
case 19:
|
|
478
|
-
|
|
482
|
+
_e.trys.push([19, 27, 28, 33]);
|
|
483
|
+
records_2 = tslib_1.__asyncValues(records);
|
|
484
|
+
_e.label = 20;
|
|
485
|
+
case 20: return [4 /*yield*/, records_2.next()];
|
|
486
|
+
case 21:
|
|
487
|
+
if (!(records_2_1 = _e.sent(), !records_2_1.done)) return [3 /*break*/, 26];
|
|
479
488
|
recordItem = records_2_1.value;
|
|
480
|
-
if (!
|
|
481
|
-
|
|
482
|
-
|
|
489
|
+
if (!(targetNames === null || targetNames === void 0 ? void 0 : targetNames.length)) return [3 /*break*/, 23];
|
|
490
|
+
allPresent = void 0;
|
|
491
|
+
// iterate through all targetnames to make sure they are all present in the recordItem
|
|
492
|
+
allPresent = targetNames.every(function (targetName) {
|
|
493
|
+
return recordItem[targetName] != null;
|
|
494
|
+
});
|
|
495
|
+
// If not present, there is not yet a connected record
|
|
496
|
+
if (!allPresent) {
|
|
497
|
+
return [3 /*break*/, 26];
|
|
498
|
+
}
|
|
499
|
+
keys = targetNames.map(function (targetName) { return recordItem[targetName]; });
|
|
500
|
+
return [4 /*yield*/, this._get(store, keys)];
|
|
501
|
+
case 22:
|
|
483
502
|
connectionRecord = _e.sent();
|
|
484
503
|
recordItem[fieldName] =
|
|
485
504
|
connectionRecord &&
|
|
486
505
|
this.modelInstanceCreator(modelConstructor_1, connectionRecord);
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
506
|
+
targetNames === null || targetNames === void 0 ? void 0 : targetNames.map(function (targetName) {
|
|
507
|
+
delete recordItem[targetName];
|
|
508
|
+
});
|
|
509
|
+
return [3 /*break*/, 25];
|
|
491
510
|
case 23:
|
|
511
|
+
if (!recordItem[targetName]) return [3 /*break*/, 25];
|
|
512
|
+
key = [recordItem[targetName]];
|
|
513
|
+
return [4 /*yield*/, this._get(store, key)];
|
|
514
|
+
case 24:
|
|
515
|
+
connectionRecord = _e.sent();
|
|
516
|
+
recordItem[fieldName] =
|
|
517
|
+
connectionRecord &&
|
|
518
|
+
this.modelInstanceCreator(modelConstructor_1, connectionRecord);
|
|
519
|
+
delete recordItem[targetName];
|
|
520
|
+
_e.label = 25;
|
|
521
|
+
case 25: return [3 /*break*/, 20];
|
|
522
|
+
case 26: return [3 /*break*/, 33];
|
|
523
|
+
case 27:
|
|
492
524
|
e_5_1 = _e.sent();
|
|
493
525
|
e_5 = { error: e_5_1 };
|
|
494
|
-
return [3 /*break*/,
|
|
495
|
-
case
|
|
496
|
-
_e.trys.push([
|
|
497
|
-
if (!(records_2_1 && !records_2_1.done && (_c = records_2.return))) return [3 /*break*/,
|
|
526
|
+
return [3 /*break*/, 33];
|
|
527
|
+
case 28:
|
|
528
|
+
_e.trys.push([28, , 31, 32]);
|
|
529
|
+
if (!(records_2_1 && !records_2_1.done && (_c = records_2.return))) return [3 /*break*/, 30];
|
|
498
530
|
return [4 /*yield*/, _c.call(records_2)];
|
|
499
|
-
case
|
|
531
|
+
case 29:
|
|
500
532
|
_e.sent();
|
|
501
|
-
_e.label =
|
|
502
|
-
case
|
|
503
|
-
case
|
|
533
|
+
_e.label = 30;
|
|
534
|
+
case 30: return [3 /*break*/, 32];
|
|
535
|
+
case 31:
|
|
504
536
|
if (e_5) throw e_5.error;
|
|
505
537
|
return [7 /*endfinally*/];
|
|
506
|
-
case
|
|
507
|
-
case
|
|
508
|
-
case
|
|
538
|
+
case 32: return [7 /*endfinally*/];
|
|
539
|
+
case 33: return [3 /*break*/, 36];
|
|
540
|
+
case 34:
|
|
509
541
|
// TODO: Lazy loading
|
|
510
|
-
return [3 /*break*/,
|
|
511
|
-
case
|
|
542
|
+
return [3 /*break*/, 36];
|
|
543
|
+
case 35:
|
|
512
544
|
util_1.exhaustiveCheck(relation.relationType);
|
|
513
|
-
return [3 /*break*/,
|
|
514
|
-
case
|
|
515
|
-
case
|
|
516
|
-
case
|
|
545
|
+
return [3 /*break*/, 36];
|
|
546
|
+
case 36: return [3 /*break*/, 2];
|
|
547
|
+
case 37: return [3 /*break*/, 44];
|
|
548
|
+
case 38:
|
|
517
549
|
e_3_1 = _e.sent();
|
|
518
550
|
e_3 = { error: e_3_1 };
|
|
519
|
-
return [3 /*break*/,
|
|
520
|
-
case
|
|
521
|
-
_e.trys.push([
|
|
522
|
-
if (!(relations_1_1 && !relations_1_1.done && (_a = relations_1.return))) return [3 /*break*/,
|
|
551
|
+
return [3 /*break*/, 44];
|
|
552
|
+
case 39:
|
|
553
|
+
_e.trys.push([39, , 42, 43]);
|
|
554
|
+
if (!(relations_1_1 && !relations_1_1.done && (_a = relations_1.return))) return [3 /*break*/, 41];
|
|
523
555
|
return [4 /*yield*/, _a.call(relations_1)];
|
|
524
|
-
case
|
|
556
|
+
case 40:
|
|
525
557
|
_e.sent();
|
|
526
|
-
_e.label =
|
|
527
|
-
case
|
|
528
|
-
case
|
|
558
|
+
_e.label = 41;
|
|
559
|
+
case 41: return [3 /*break*/, 43];
|
|
560
|
+
case 42:
|
|
529
561
|
if (e_3) throw e_3.error;
|
|
530
562
|
return [7 /*endfinally*/];
|
|
531
|
-
case
|
|
532
|
-
case
|
|
563
|
+
case 43: return [7 /*endfinally*/];
|
|
564
|
+
case 44: return [2 /*return*/, records.map(function (record) {
|
|
533
565
|
return _this.modelInstanceCreator(modelConstructor, record);
|
|
534
566
|
})];
|
|
535
567
|
}
|
|
@@ -537,10 +569,10 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
537
569
|
});
|
|
538
570
|
};
|
|
539
571
|
IndexedDBAdapter.prototype.query = function (modelConstructor, predicate, pagination) {
|
|
540
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
541
|
-
var storeName, namespaceName, predicates,
|
|
572
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
573
|
+
var storeName, namespaceName, predicates, keyPath, queryByKey, hasSort, hasPagination, records;
|
|
542
574
|
var _this = this;
|
|
543
|
-
return __generator(this, function (_a) {
|
|
575
|
+
return tslib_1.__generator(this, function (_a) {
|
|
544
576
|
switch (_a.label) {
|
|
545
577
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
546
578
|
case 1:
|
|
@@ -548,16 +580,17 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
548
580
|
storeName = this.getStorenameForModel(modelConstructor);
|
|
549
581
|
namespaceName = this.namespaceResolver(modelConstructor);
|
|
550
582
|
predicates = predicate && predicates_1.ModelPredicateCreator.getPredicates(predicate);
|
|
551
|
-
|
|
583
|
+
keyPath = util_1.getIndexKeys(this.schema.namespaces[namespaceName], modelConstructor.name);
|
|
584
|
+
queryByKey = predicates && this.keyValueFromPredicate(predicates, keyPath);
|
|
552
585
|
hasSort = pagination && pagination.sort;
|
|
553
586
|
hasPagination = pagination && pagination.limit;
|
|
554
|
-
return [4 /*yield*/, (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
587
|
+
return [4 /*yield*/, (function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
555
588
|
var record, filtered, all;
|
|
556
|
-
return __generator(this, function (_a) {
|
|
589
|
+
return tslib_1.__generator(this, function (_a) {
|
|
557
590
|
switch (_a.label) {
|
|
558
591
|
case 0:
|
|
559
|
-
if (!
|
|
560
|
-
return [4 /*yield*/, this.
|
|
592
|
+
if (!queryByKey) return [3 /*break*/, 2];
|
|
593
|
+
return [4 /*yield*/, this.getByKey(storeName, queryByKey)];
|
|
561
594
|
case 1:
|
|
562
595
|
record = _a.sent();
|
|
563
596
|
return [2 /*return*/, record ? [record] : []];
|
|
@@ -589,12 +622,12 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
589
622
|
});
|
|
590
623
|
});
|
|
591
624
|
};
|
|
592
|
-
IndexedDBAdapter.prototype.
|
|
593
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
625
|
+
IndexedDBAdapter.prototype.getByKey = function (storeName, keyValue) {
|
|
626
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
594
627
|
var record;
|
|
595
|
-
return __generator(this, function (_a) {
|
|
628
|
+
return tslib_1.__generator(this, function (_a) {
|
|
596
629
|
switch (_a.label) {
|
|
597
|
-
case 0: return [4 /*yield*/, this._get(storeName,
|
|
630
|
+
case 0: return [4 /*yield*/, this._get(storeName, keyValue)];
|
|
598
631
|
case 1:
|
|
599
632
|
record = _a.sent();
|
|
600
633
|
return [2 /*return*/, record];
|
|
@@ -603,8 +636,8 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
603
636
|
});
|
|
604
637
|
};
|
|
605
638
|
IndexedDBAdapter.prototype.getAll = function (storeName) {
|
|
606
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
607
|
-
return __generator(this, function (_a) {
|
|
639
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
640
|
+
return tslib_1.__generator(this, function (_a) {
|
|
608
641
|
switch (_a.label) {
|
|
609
642
|
case 0: return [4 /*yield*/, this.db.getAll(storeName)];
|
|
610
643
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -612,16 +645,36 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
612
645
|
});
|
|
613
646
|
});
|
|
614
647
|
};
|
|
615
|
-
IndexedDBAdapter.prototype.
|
|
648
|
+
IndexedDBAdapter.prototype.keyValueFromPredicate = function (predicates, keyPath) {
|
|
649
|
+
var e_6, _a;
|
|
616
650
|
var predicateObjs = predicates.predicates;
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
651
|
+
if (predicateObjs.length !== keyPath.length) {
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
var keyValues = [];
|
|
655
|
+
var _loop_1 = function (key) {
|
|
656
|
+
var predicateObj = predicateObjs.find(function (p) { return types_1.isPredicateObj(p) && p.field === key && p.operator === 'eq'; });
|
|
657
|
+
predicateObj && keyValues.push(predicateObj.operand);
|
|
658
|
+
};
|
|
659
|
+
try {
|
|
660
|
+
for (var keyPath_1 = tslib_1.__values(keyPath), keyPath_1_1 = keyPath_1.next(); !keyPath_1_1.done; keyPath_1_1 = keyPath_1.next()) {
|
|
661
|
+
var key = keyPath_1_1.value;
|
|
662
|
+
_loop_1(key);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
666
|
+
finally {
|
|
667
|
+
try {
|
|
668
|
+
if (keyPath_1_1 && !keyPath_1_1.done && (_a = keyPath_1.return)) _a.call(keyPath_1);
|
|
669
|
+
}
|
|
670
|
+
finally { if (e_6) throw e_6.error; }
|
|
671
|
+
}
|
|
672
|
+
return keyValues.length === keyPath.length ? keyValues : undefined;
|
|
620
673
|
};
|
|
621
674
|
IndexedDBAdapter.prototype.filterOnPredicate = function (storeName, predicates) {
|
|
622
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
675
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
623
676
|
var predicateObjs, type, all, filtered;
|
|
624
|
-
return __generator(this, function (_a) {
|
|
677
|
+
return tslib_1.__generator(this, function (_a) {
|
|
625
678
|
switch (_a.label) {
|
|
626
679
|
case 0:
|
|
627
680
|
predicateObjs = predicates.predicates, type = predicates.type;
|
|
@@ -653,9 +706,9 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
653
706
|
return records;
|
|
654
707
|
};
|
|
655
708
|
IndexedDBAdapter.prototype.enginePagination = function (storeName, pagination) {
|
|
656
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
709
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
657
710
|
var result, _a, page, _b, limit, initialRecord, cursor, pageResults, hasLimit;
|
|
658
|
-
return __generator(this, function (_c) {
|
|
711
|
+
return tslib_1.__generator(this, function (_c) {
|
|
659
712
|
switch (_c.label) {
|
|
660
713
|
case 0:
|
|
661
714
|
if (!pagination) return [3 /*break*/, 7];
|
|
@@ -700,9 +753,9 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
700
753
|
};
|
|
701
754
|
IndexedDBAdapter.prototype.queryOne = function (modelConstructor, firstOrLast) {
|
|
702
755
|
if (firstOrLast === void 0) { firstOrLast = types_1.QueryOne.FIRST; }
|
|
703
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
756
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
704
757
|
var storeName, cursor, result;
|
|
705
|
-
return __generator(this, function (_a) {
|
|
758
|
+
return tslib_1.__generator(this, function (_a) {
|
|
706
759
|
switch (_a.label) {
|
|
707
760
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
708
761
|
case 1:
|
|
@@ -721,9 +774,9 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
721
774
|
});
|
|
722
775
|
};
|
|
723
776
|
IndexedDBAdapter.prototype.delete = function (modelOrModelConstructor, condition) {
|
|
724
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
725
|
-
var deleteQueue, modelConstructor, nameSpace, storeName, models, relations, deletedModels, deletedModels, model, modelConstructor,
|
|
726
|
-
return __generator(this, function (_a) {
|
|
777
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
778
|
+
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;
|
|
779
|
+
return tslib_1.__generator(this, function (_a) {
|
|
727
780
|
switch (_a.label) {
|
|
728
781
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
729
782
|
case 1:
|
|
@@ -771,12 +824,13 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
771
824
|
model = modelOrModelConstructor;
|
|
772
825
|
modelConstructor = Object.getPrototypeOf(model)
|
|
773
826
|
.constructor;
|
|
774
|
-
|
|
827
|
+
namespaceName = this.namespaceResolver(modelConstructor);
|
|
775
828
|
storeName = this.getStorenameForModel(modelConstructor);
|
|
776
829
|
if (!condition) return [3 /*break*/, 13];
|
|
777
830
|
tx = this.db.transaction([storeName], 'readwrite');
|
|
778
831
|
store = tx.objectStore(storeName);
|
|
779
|
-
|
|
832
|
+
keyValues = this.getIndexKeyValuesFromModel(model);
|
|
833
|
+
return [4 /*yield*/, this._get(store, keyValues)];
|
|
780
834
|
case 10:
|
|
781
835
|
fromDB = _a.sent();
|
|
782
836
|
if (fromDB === undefined) {
|
|
@@ -795,16 +849,14 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
795
849
|
return [4 /*yield*/, tx.done];
|
|
796
850
|
case 11:
|
|
797
851
|
_a.sent();
|
|
798
|
-
relations = this.schema.namespaces[
|
|
799
|
-
|
|
800
|
-
return [4 /*yield*/, this.deleteTraverse(relations, [model], modelConstructor.name, nameSpace, deleteQueue)];
|
|
852
|
+
relations = this.schema.namespaces[namespaceName].relationships[modelConstructor.name].relationTypes;
|
|
853
|
+
return [4 /*yield*/, this.deleteTraverse(relations, [model], modelConstructor.name, namespaceName, deleteQueue)];
|
|
801
854
|
case 12:
|
|
802
855
|
_a.sent();
|
|
803
856
|
return [3 /*break*/, 15];
|
|
804
857
|
case 13:
|
|
805
|
-
relations = this.schema.namespaces[
|
|
806
|
-
|
|
807
|
-
return [4 /*yield*/, this.deleteTraverse(relations, [model], modelConstructor.name, nameSpace, deleteQueue)];
|
|
858
|
+
relations = this.schema.namespaces[namespaceName].relationships[modelConstructor.name].relationTypes;
|
|
859
|
+
return [4 /*yield*/, this.deleteTraverse(relations, [model], modelConstructor.name, namespaceName, deleteQueue)];
|
|
808
860
|
case 14:
|
|
809
861
|
_a.sent();
|
|
810
862
|
_a.label = 15;
|
|
@@ -823,21 +875,21 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
823
875
|
};
|
|
824
876
|
IndexedDBAdapter.prototype.deleteItem = function (deleteQueue) {
|
|
825
877
|
var deleteQueue_1, deleteQueue_1_1;
|
|
826
|
-
var
|
|
827
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
828
|
-
var connectionStoreNames, tx, deleteItem, storeName, items, store, items_1, items_1_1, item, key,
|
|
829
|
-
return __generator(this, function (_c) {
|
|
878
|
+
var e_7, _a, e_8, _b;
|
|
879
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
880
|
+
var connectionStoreNames, tx, deleteItem, storeName, items, store, items_1, items_1_1, item, key, keyValues, itemKey, e_8_1, e_7_1;
|
|
881
|
+
return tslib_1.__generator(this, function (_c) {
|
|
830
882
|
switch (_c.label) {
|
|
831
883
|
case 0:
|
|
832
884
|
connectionStoreNames = deleteQueue.map(function (_a) {
|
|
833
885
|
var storeName = _a.storeName;
|
|
834
886
|
return storeName;
|
|
835
887
|
});
|
|
836
|
-
tx = this.db.transaction(__spread(connectionStoreNames), 'readwrite');
|
|
888
|
+
tx = this.db.transaction(tslib_1.__spread(connectionStoreNames), 'readwrite');
|
|
837
889
|
_c.label = 1;
|
|
838
890
|
case 1:
|
|
839
891
|
_c.trys.push([1, 22, 23, 28]);
|
|
840
|
-
deleteQueue_1 = __asyncValues(deleteQueue);
|
|
892
|
+
deleteQueue_1 = tslib_1.__asyncValues(deleteQueue);
|
|
841
893
|
_c.label = 2;
|
|
842
894
|
case 2: return [4 /*yield*/, deleteQueue_1.next()];
|
|
843
895
|
case 3:
|
|
@@ -848,7 +900,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
848
900
|
_c.label = 4;
|
|
849
901
|
case 4:
|
|
850
902
|
_c.trys.push([4, 14, 15, 20]);
|
|
851
|
-
items_1 = __asyncValues(items);
|
|
903
|
+
items_1 = tslib_1.__asyncValues(items);
|
|
852
904
|
_c.label = 5;
|
|
853
905
|
case 5: return [4 /*yield*/, items_1.next()];
|
|
854
906
|
case 6:
|
|
@@ -857,11 +909,16 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
857
909
|
if (!item) return [3 /*break*/, 12];
|
|
858
910
|
key = void 0;
|
|
859
911
|
if (!(typeof item === 'object')) return [3 /*break*/, 8];
|
|
860
|
-
|
|
912
|
+
keyValues = this.getIndexKeyValuesFromModel(item);
|
|
913
|
+
return [4 /*yield*/, store
|
|
914
|
+
.index('byPk')
|
|
915
|
+
.getKey(this.canonicalKeyPath(keyValues))];
|
|
861
916
|
case 7:
|
|
862
917
|
key = _c.sent();
|
|
863
918
|
return [3 /*break*/, 10];
|
|
864
|
-
case 8:
|
|
919
|
+
case 8:
|
|
920
|
+
itemKey = item.toString();
|
|
921
|
+
return [4 /*yield*/, store.index('byPk').getKey(itemKey)];
|
|
865
922
|
case 9:
|
|
866
923
|
key = _c.sent();
|
|
867
924
|
_c.label = 10;
|
|
@@ -874,8 +931,8 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
874
931
|
case 12: return [3 /*break*/, 5];
|
|
875
932
|
case 13: return [3 /*break*/, 20];
|
|
876
933
|
case 14:
|
|
877
|
-
|
|
878
|
-
|
|
934
|
+
e_8_1 = _c.sent();
|
|
935
|
+
e_8 = { error: e_8_1 };
|
|
879
936
|
return [3 /*break*/, 20];
|
|
880
937
|
case 15:
|
|
881
938
|
_c.trys.push([15, , 18, 19]);
|
|
@@ -886,14 +943,14 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
886
943
|
_c.label = 17;
|
|
887
944
|
case 17: return [3 /*break*/, 19];
|
|
888
945
|
case 18:
|
|
889
|
-
if (
|
|
946
|
+
if (e_8) throw e_8.error;
|
|
890
947
|
return [7 /*endfinally*/];
|
|
891
948
|
case 19: return [7 /*endfinally*/];
|
|
892
949
|
case 20: return [3 /*break*/, 2];
|
|
893
950
|
case 21: return [3 /*break*/, 28];
|
|
894
951
|
case 22:
|
|
895
|
-
|
|
896
|
-
|
|
952
|
+
e_7_1 = _c.sent();
|
|
953
|
+
e_7 = { error: e_7_1 };
|
|
897
954
|
return [3 /*break*/, 28];
|
|
898
955
|
case 23:
|
|
899
956
|
_c.trys.push([23, , 26, 27]);
|
|
@@ -904,7 +961,7 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
904
961
|
_c.label = 25;
|
|
905
962
|
case 25: return [3 /*break*/, 27];
|
|
906
963
|
case 26:
|
|
907
|
-
if (
|
|
964
|
+
if (e_7) throw e_7.error;
|
|
908
965
|
return [7 /*endfinally*/];
|
|
909
966
|
case 27: return [7 /*endfinally*/];
|
|
910
967
|
case 28: return [2 /*return*/];
|
|
@@ -914,145 +971,178 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
914
971
|
};
|
|
915
972
|
IndexedDBAdapter.prototype.deleteTraverse = function (relations, models, srcModel, nameSpace, deleteQueue) {
|
|
916
973
|
var relations_2, relations_2_1, models_1, models_1_1, models_2, models_2_1;
|
|
917
|
-
var
|
|
918
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
919
|
-
var rel, relationType,
|
|
974
|
+
var e_9, _a, e_10, _b, e_11, _c;
|
|
975
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
976
|
+
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;
|
|
920
977
|
var _this = this;
|
|
921
|
-
return __generator(this, function (_e) {
|
|
978
|
+
return tslib_1.__generator(this, function (_e) {
|
|
922
979
|
switch (_e.label) {
|
|
923
980
|
case 0:
|
|
924
|
-
_e.trys.push([0,
|
|
925
|
-
relations_2 = __asyncValues(relations);
|
|
981
|
+
_e.trys.push([0, 38, 39, 44]);
|
|
982
|
+
relations_2 = tslib_1.__asyncValues(relations);
|
|
926
983
|
_e.label = 1;
|
|
927
984
|
case 1: return [4 /*yield*/, relations_2.next()];
|
|
928
985
|
case 2:
|
|
929
|
-
if (!(relations_2_1 = _e.sent(), !relations_2_1.done)) return [3 /*break*/,
|
|
986
|
+
if (!(relations_2_1 = _e.sent(), !relations_2_1.done)) return [3 /*break*/, 37];
|
|
930
987
|
rel = relations_2_1.value;
|
|
931
|
-
relationType = rel.relationType,
|
|
932
|
-
storeName =
|
|
933
|
-
index = util_1.getIndex(this.schema.namespaces[nameSpace].relationships[modelName]
|
|
934
|
-
.relationTypes, srcModel) ||
|
|
935
|
-
// if we were unable to find an index via relationTypes
|
|
936
|
-
// i.e. for keyName connections, attempt to find one by the
|
|
937
|
-
// associatedWith property
|
|
938
|
-
util_1.getIndexFromAssociation(this.schema.namespaces[nameSpace].relationships[modelName].indexes, rel.associatedWith);
|
|
988
|
+
relationType = rel.relationType, modelName = rel.modelName, targetName = rel.targetName, targetNames = rel.targetNames, associatedWith = rel.associatedWith;
|
|
989
|
+
storeName = util_1.getStorename(nameSpace, modelName);
|
|
939
990
|
_d = relationType;
|
|
940
991
|
switch (_d) {
|
|
941
992
|
case 'HAS_ONE': return [3 /*break*/, 3];
|
|
942
|
-
case 'HAS_MANY': return [3 /*break*/,
|
|
943
|
-
case 'BELONGS_TO': return [3 /*break*/,
|
|
993
|
+
case 'HAS_MANY': return [3 /*break*/, 20];
|
|
994
|
+
case 'BELONGS_TO': return [3 /*break*/, 34];
|
|
944
995
|
}
|
|
945
|
-
return [3 /*break*/,
|
|
996
|
+
return [3 /*break*/, 35];
|
|
946
997
|
case 3:
|
|
947
|
-
_e.trys.push([3,
|
|
948
|
-
models_1 = __asyncValues(models);
|
|
998
|
+
_e.trys.push([3, 13, 14, 19]);
|
|
999
|
+
models_1 = tslib_1.__asyncValues(models);
|
|
949
1000
|
_e.label = 4;
|
|
950
1001
|
case 4: return [4 /*yield*/, models_1.next()];
|
|
951
1002
|
case 5:
|
|
952
|
-
if (!(models_1_1 = _e.sent(), !models_1_1.done)) return [3 /*break*/,
|
|
1003
|
+
if (!(models_1_1 = _e.sent(), !models_1_1.done)) return [3 /*break*/, 12];
|
|
953
1004
|
model = models_1_1.value;
|
|
954
|
-
hasOneIndex =
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
if (
|
|
958
|
-
return [3 /*break*/,
|
|
1005
|
+
hasOneIndex = 'byPk';
|
|
1006
|
+
if (!(targetNames === null || targetNames === void 0 ? void 0 : targetNames.length)) return [3 /*break*/, 8];
|
|
1007
|
+
values = targetNames.map(function (targetName) { return model[targetName]; });
|
|
1008
|
+
if (values.length === 0)
|
|
1009
|
+
return [3 /*break*/, 12];
|
|
959
1010
|
return [4 /*yield*/, this.db
|
|
960
1011
|
.transaction(storeName, 'readwrite')
|
|
961
1012
|
.objectStore(storeName)
|
|
962
1013
|
.index(hasOneIndex)
|
|
963
|
-
.get(
|
|
1014
|
+
.get(this.canonicalKeyPath(values))];
|
|
964
1015
|
case 6:
|
|
965
1016
|
recordToDelete = (_e.sent());
|
|
966
1017
|
return [4 /*yield*/, this.deleteTraverse(this.schema.namespaces[nameSpace].relationships[modelName]
|
|
967
1018
|
.relationTypes, recordToDelete ? [recordToDelete] : [], modelName, nameSpace, deleteQueue)];
|
|
968
1019
|
case 7:
|
|
969
1020
|
_e.sent();
|
|
970
|
-
|
|
971
|
-
case 8:
|
|
972
|
-
|
|
1021
|
+
return [3 /*break*/, 12];
|
|
1022
|
+
case 8:
|
|
1023
|
+
index = void 0;
|
|
1024
|
+
values = void 0;
|
|
1025
|
+
if (targetName && targetName in model) {
|
|
1026
|
+
index = hasOneIndex;
|
|
1027
|
+
value = model[targetName];
|
|
1028
|
+
values = [value];
|
|
1029
|
+
}
|
|
1030
|
+
else {
|
|
1031
|
+
// backwards compatability for older versions of codegen that did not emit targetName for HAS_ONE relations
|
|
1032
|
+
// TODO: can we deprecate this? it's been ~2 years since codegen started including targetName for HAS_ONE
|
|
1033
|
+
// If we deprecate, we'll need to re-gen the MIPR in __tests__/schema.ts > newSchema
|
|
1034
|
+
// otherwise some unit tests will fail
|
|
1035
|
+
index = util_1.getIndex(this.schema.namespaces[nameSpace].relationships[modelName]
|
|
1036
|
+
.relationTypes, srcModel);
|
|
1037
|
+
values = this.getIndexKeyValuesFromModel(model);
|
|
1038
|
+
}
|
|
1039
|
+
if (!values || !index)
|
|
1040
|
+
return [3 /*break*/, 12];
|
|
1041
|
+
return [4 /*yield*/, this.db
|
|
1042
|
+
.transaction(storeName, 'readwrite')
|
|
1043
|
+
.objectStore(storeName)
|
|
1044
|
+
.index(index)
|
|
1045
|
+
.get(this.canonicalKeyPath(values))];
|
|
1046
|
+
case 9:
|
|
1047
|
+
recordToDelete = (_e.sent());
|
|
1048
|
+
return [4 /*yield*/, this.deleteTraverse(this.schema.namespaces[nameSpace].relationships[modelName]
|
|
1049
|
+
.relationTypes, recordToDelete ? [recordToDelete] : [], modelName, nameSpace, deleteQueue)];
|
|
973
1050
|
case 10:
|
|
974
|
-
e_9_1 = _e.sent();
|
|
975
|
-
e_9 = { error: e_9_1 };
|
|
976
|
-
return [3 /*break*/, 16];
|
|
977
|
-
case 11:
|
|
978
|
-
_e.trys.push([11, , 14, 15]);
|
|
979
|
-
if (!(models_1_1 && !models_1_1.done && (_b = models_1.return))) return [3 /*break*/, 13];
|
|
980
|
-
return [4 /*yield*/, _b.call(models_1)];
|
|
981
|
-
case 12:
|
|
982
1051
|
_e.sent();
|
|
983
|
-
_e.label =
|
|
984
|
-
case
|
|
1052
|
+
_e.label = 11;
|
|
1053
|
+
case 11: return [3 /*break*/, 4];
|
|
1054
|
+
case 12: return [3 /*break*/, 19];
|
|
1055
|
+
case 13:
|
|
1056
|
+
e_10_1 = _e.sent();
|
|
1057
|
+
e_10 = { error: e_10_1 };
|
|
1058
|
+
return [3 /*break*/, 19];
|
|
985
1059
|
case 14:
|
|
986
|
-
|
|
987
|
-
return [
|
|
988
|
-
|
|
989
|
-
case
|
|
1060
|
+
_e.trys.push([14, , 17, 18]);
|
|
1061
|
+
if (!(models_1_1 && !models_1_1.done && (_b = models_1.return))) return [3 /*break*/, 16];
|
|
1062
|
+
return [4 /*yield*/, _b.call(models_1)];
|
|
1063
|
+
case 15:
|
|
1064
|
+
_e.sent();
|
|
1065
|
+
_e.label = 16;
|
|
1066
|
+
case 16: return [3 /*break*/, 18];
|
|
990
1067
|
case 17:
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
case
|
|
995
|
-
case
|
|
996
|
-
|
|
1068
|
+
if (e_10) throw e_10.error;
|
|
1069
|
+
return [7 /*endfinally*/];
|
|
1070
|
+
case 18: return [7 /*endfinally*/];
|
|
1071
|
+
case 19: return [3 /*break*/, 36];
|
|
1072
|
+
case 20:
|
|
1073
|
+
_e.trys.push([20, 27, 28, 33]);
|
|
1074
|
+
models_2 = tslib_1.__asyncValues(models);
|
|
1075
|
+
_e.label = 21;
|
|
1076
|
+
case 21: return [4 /*yield*/, models_2.next()];
|
|
1077
|
+
case 22:
|
|
1078
|
+
if (!(models_2_1 = _e.sent(), !models_2_1.done)) return [3 /*break*/, 26];
|
|
997
1079
|
model = models_2_1.value;
|
|
1080
|
+
index =
|
|
1081
|
+
// explicit bi-directional @hasMany and @manyToMany
|
|
1082
|
+
util_1.getIndex(this.schema.namespaces[nameSpace].relationships[modelName]
|
|
1083
|
+
.relationTypes, srcModel) ||
|
|
1084
|
+
// uni and/or implicit @hasMany
|
|
1085
|
+
util_1.getIndexFromAssociation(this.schema.namespaces[nameSpace].relationships[modelName]
|
|
1086
|
+
.indexes, associatedWith);
|
|
1087
|
+
keyValues = this.getIndexKeyValuesFromModel(model);
|
|
998
1088
|
return [4 /*yield*/, this.db
|
|
999
1089
|
.transaction(storeName, 'readwrite')
|
|
1000
1090
|
.objectStore(storeName)
|
|
1001
1091
|
.index(index)
|
|
1002
|
-
.getAll(
|
|
1003
|
-
case
|
|
1092
|
+
.getAll(this.canonicalKeyPath(keyValues))];
|
|
1093
|
+
case 23:
|
|
1004
1094
|
childrenArray = _e.sent();
|
|
1005
1095
|
return [4 /*yield*/, this.deleteTraverse(this.schema.namespaces[nameSpace].relationships[modelName]
|
|
1006
1096
|
.relationTypes, childrenArray, modelName, nameSpace, deleteQueue)];
|
|
1007
|
-
case 21:
|
|
1008
|
-
_e.sent();
|
|
1009
|
-
_e.label = 22;
|
|
1010
|
-
case 22: return [3 /*break*/, 18];
|
|
1011
|
-
case 23: return [3 /*break*/, 30];
|
|
1012
1097
|
case 24:
|
|
1013
|
-
e_10_1 = _e.sent();
|
|
1014
|
-
e_10 = { error: e_10_1 };
|
|
1015
|
-
return [3 /*break*/, 30];
|
|
1016
|
-
case 25:
|
|
1017
|
-
_e.trys.push([25, , 28, 29]);
|
|
1018
|
-
if (!(models_2_1 && !models_2_1.done && (_c = models_2.return))) return [3 /*break*/, 27];
|
|
1019
|
-
return [4 /*yield*/, _c.call(models_2)];
|
|
1020
|
-
case 26:
|
|
1021
1098
|
_e.sent();
|
|
1022
|
-
_e.label =
|
|
1023
|
-
case
|
|
1099
|
+
_e.label = 25;
|
|
1100
|
+
case 25: return [3 /*break*/, 21];
|
|
1101
|
+
case 26: return [3 /*break*/, 33];
|
|
1102
|
+
case 27:
|
|
1103
|
+
e_11_1 = _e.sent();
|
|
1104
|
+
e_11 = { error: e_11_1 };
|
|
1105
|
+
return [3 /*break*/, 33];
|
|
1024
1106
|
case 28:
|
|
1025
|
-
|
|
1107
|
+
_e.trys.push([28, , 31, 32]);
|
|
1108
|
+
if (!(models_2_1 && !models_2_1.done && (_c = models_2.return))) return [3 /*break*/, 30];
|
|
1109
|
+
return [4 /*yield*/, _c.call(models_2)];
|
|
1110
|
+
case 29:
|
|
1111
|
+
_e.sent();
|
|
1112
|
+
_e.label = 30;
|
|
1113
|
+
case 30: return [3 /*break*/, 32];
|
|
1114
|
+
case 31:
|
|
1115
|
+
if (e_11) throw e_11.error;
|
|
1026
1116
|
return [7 /*endfinally*/];
|
|
1027
|
-
case
|
|
1028
|
-
case
|
|
1029
|
-
case
|
|
1117
|
+
case 32: return [7 /*endfinally*/];
|
|
1118
|
+
case 33: return [3 /*break*/, 36];
|
|
1119
|
+
case 34:
|
|
1030
1120
|
// Intentionally blank
|
|
1031
|
-
return [3 /*break*/,
|
|
1032
|
-
case 32:
|
|
1033
|
-
util_1.exhaustiveCheck(relationType);
|
|
1034
|
-
return [3 /*break*/, 33];
|
|
1035
|
-
case 33: return [3 /*break*/, 1];
|
|
1036
|
-
case 34: return [3 /*break*/, 41];
|
|
1121
|
+
return [3 /*break*/, 36];
|
|
1037
1122
|
case 35:
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
case
|
|
1042
|
-
|
|
1043
|
-
|
|
1123
|
+
util_1.exhaustiveCheck(relationType);
|
|
1124
|
+
return [3 /*break*/, 36];
|
|
1125
|
+
case 36: return [3 /*break*/, 1];
|
|
1126
|
+
case 37: return [3 /*break*/, 44];
|
|
1127
|
+
case 38:
|
|
1128
|
+
e_9_1 = _e.sent();
|
|
1129
|
+
e_9 = { error: e_9_1 };
|
|
1130
|
+
return [3 /*break*/, 44];
|
|
1131
|
+
case 39:
|
|
1132
|
+
_e.trys.push([39, , 42, 43]);
|
|
1133
|
+
if (!(relations_2_1 && !relations_2_1.done && (_a = relations_2.return))) return [3 /*break*/, 41];
|
|
1044
1134
|
return [4 /*yield*/, _a.call(relations_2)];
|
|
1045
|
-
case
|
|
1135
|
+
case 40:
|
|
1046
1136
|
_e.sent();
|
|
1047
|
-
_e.label =
|
|
1048
|
-
case
|
|
1049
|
-
case
|
|
1050
|
-
if (
|
|
1137
|
+
_e.label = 41;
|
|
1138
|
+
case 41: return [3 /*break*/, 43];
|
|
1139
|
+
case 42:
|
|
1140
|
+
if (e_9) throw e_9.error;
|
|
1051
1141
|
return [7 /*endfinally*/];
|
|
1052
|
-
case
|
|
1053
|
-
case
|
|
1142
|
+
case 43: return [7 /*endfinally*/];
|
|
1143
|
+
case 44:
|
|
1054
1144
|
deleteQueue.push({
|
|
1055
|
-
storeName:
|
|
1145
|
+
storeName: util_1.getStorename(nameSpace, srcModel),
|
|
1056
1146
|
items: models.map(function (record) {
|
|
1057
1147
|
return _this.modelInstanceCreator(_this.getModelConstructorByModelName(nameSpace, srcModel), record);
|
|
1058
1148
|
}),
|
|
@@ -1064,8 +1154,8 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1064
1154
|
};
|
|
1065
1155
|
IndexedDBAdapter.prototype.clear = function () {
|
|
1066
1156
|
var _a;
|
|
1067
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1068
|
-
return __generator(this, function (_b) {
|
|
1157
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1158
|
+
return tslib_1.__generator(this, function (_b) {
|
|
1069
1159
|
switch (_b.label) {
|
|
1070
1160
|
case 0: return [4 /*yield*/, this.checkPrivate()];
|
|
1071
1161
|
case 1:
|
|
@@ -1082,10 +1172,11 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1082
1172
|
});
|
|
1083
1173
|
};
|
|
1084
1174
|
IndexedDBAdapter.prototype.batchSave = function (modelConstructor, items) {
|
|
1085
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1086
|
-
var result, storeName, txn, store,
|
|
1087
|
-
var
|
|
1088
|
-
|
|
1175
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1176
|
+
var result, storeName, txn, store, _loop_2, this_1, items_2, items_2_1, item, e_12_1;
|
|
1177
|
+
var e_12, _a;
|
|
1178
|
+
var _this = this;
|
|
1179
|
+
return tslib_1.__generator(this, function (_b) {
|
|
1089
1180
|
switch (_b.label) {
|
|
1090
1181
|
case 0:
|
|
1091
1182
|
if (items.length === 0) {
|
|
@@ -1098,21 +1189,26 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1098
1189
|
storeName = this.getStorenameForModel(modelConstructor);
|
|
1099
1190
|
txn = this.db.transaction(storeName, 'readwrite');
|
|
1100
1191
|
store = txn.store;
|
|
1101
|
-
|
|
1102
|
-
var connectedModels,
|
|
1103
|
-
return __generator(this, function (_a) {
|
|
1192
|
+
_loop_2 = function (item) {
|
|
1193
|
+
var namespaceName, modelName, model, connectedModels, keyValues, _deleted, index, key, instance;
|
|
1194
|
+
return tslib_1.__generator(this, function (_a) {
|
|
1104
1195
|
switch (_a.label) {
|
|
1105
1196
|
case 0:
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1197
|
+
namespaceName = this_1.namespaceResolver(modelConstructor);
|
|
1198
|
+
modelName = modelConstructor.name;
|
|
1199
|
+
model = this_1.modelInstanceCreator(modelConstructor, item);
|
|
1200
|
+
connectedModels = util_1.traverseModel(modelName, model, this_1.schema.namespaces[namespaceName], this_1.modelInstanceCreator, this_1.getModelConstructorByModelName);
|
|
1201
|
+
keyValues = this_1.getIndexKeyValuesFromModel(model);
|
|
1202
|
+
_deleted = item._deleted;
|
|
1203
|
+
index = store.index('byPk');
|
|
1204
|
+
return [4 /*yield*/, index.getKey(this_1.canonicalKeyPath(keyValues))];
|
|
1110
1205
|
case 1:
|
|
1111
1206
|
key = _a.sent();
|
|
1112
1207
|
if (!!_deleted) return [3 /*break*/, 3];
|
|
1113
1208
|
instance = connectedModels.find(function (_a) {
|
|
1114
1209
|
var instance = _a.instance;
|
|
1115
|
-
|
|
1210
|
+
var instanceKeyValues = _this.getIndexKeyValuesFromModel(instance);
|
|
1211
|
+
return util_1.keysEqual(instanceKeyValues, keyValues);
|
|
1116
1212
|
}).instance;
|
|
1117
1213
|
result.push([
|
|
1118
1214
|
instance,
|
|
@@ -1137,12 +1233,12 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1137
1233
|
_b.label = 2;
|
|
1138
1234
|
case 2:
|
|
1139
1235
|
_b.trys.push([2, 7, 8, 9]);
|
|
1140
|
-
items_2 = __values(items), items_2_1 = items_2.next();
|
|
1236
|
+
items_2 = tslib_1.__values(items), items_2_1 = items_2.next();
|
|
1141
1237
|
_b.label = 3;
|
|
1142
1238
|
case 3:
|
|
1143
1239
|
if (!!items_2_1.done) return [3 /*break*/, 6];
|
|
1144
1240
|
item = items_2_1.value;
|
|
1145
|
-
return [5 /*yield**/,
|
|
1241
|
+
return [5 /*yield**/, _loop_2(item)];
|
|
1146
1242
|
case 4:
|
|
1147
1243
|
_b.sent();
|
|
1148
1244
|
_b.label = 5;
|
|
@@ -1151,14 +1247,14 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1151
1247
|
return [3 /*break*/, 3];
|
|
1152
1248
|
case 6: return [3 /*break*/, 9];
|
|
1153
1249
|
case 7:
|
|
1154
|
-
|
|
1155
|
-
|
|
1250
|
+
e_12_1 = _b.sent();
|
|
1251
|
+
e_12 = { error: e_12_1 };
|
|
1156
1252
|
return [3 /*break*/, 9];
|
|
1157
1253
|
case 8:
|
|
1158
1254
|
try {
|
|
1159
1255
|
if (items_2_1 && !items_2_1.done && (_a = items_2.return)) _a.call(items_2);
|
|
1160
1256
|
}
|
|
1161
|
-
finally { if (
|
|
1257
|
+
finally { if (e_12) throw e_12.error; }
|
|
1162
1258
|
return [7 /*endfinally*/];
|
|
1163
1259
|
case 9: return [4 /*yield*/, txn.done];
|
|
1164
1260
|
case 10:
|
|
@@ -1169,18 +1265,15 @@ var IndexedDBAdapter = /** @class */ (function () {
|
|
|
1169
1265
|
});
|
|
1170
1266
|
};
|
|
1171
1267
|
IndexedDBAdapter.prototype.createObjectStoreForModel = function (db, namespaceName, storeName, modelName) {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
indexes.forEach(function (index) { return store.createIndex(index, index); });
|
|
1180
|
-
store.createIndex('byId', 'id', { unique: true });
|
|
1181
|
-
return [2 /*return*/];
|
|
1182
|
-
});
|
|
1268
|
+
var store = db.createObjectStore(storeName, {
|
|
1269
|
+
autoIncrement: true,
|
|
1270
|
+
});
|
|
1271
|
+
var indexes = this.schema.namespaces[namespaceName].relationships[modelName].indexes;
|
|
1272
|
+
indexes.forEach(function (_a) {
|
|
1273
|
+
var _b = tslib_1.__read(_a, 3), idxName = _b[0], keyPath = _b[1], options = _b[2];
|
|
1274
|
+
store.createIndex(idxName, keyPath, options);
|
|
1183
1275
|
});
|
|
1276
|
+
return store;
|
|
1184
1277
|
};
|
|
1185
1278
|
return IndexedDBAdapter;
|
|
1186
1279
|
}());
|