@aws-amplify/datastore 4.7.5 → 5.0.1-console-preview.4432977.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/lib/authModeStrategies/defaultAuthStrategy.js +3 -2
- package/lib/authModeStrategies/index.js +3 -3
- package/lib/authModeStrategies/multiAuthStrategy.js +81 -24
- package/lib/datastore/datastore.d.ts +3 -4
- package/lib/datastore/datastore.js +361 -227
- package/lib/index.d.ts +1 -1
- package/lib/index.js +25 -12
- package/lib/predicates/index.js +46 -12
- package/lib/predicates/next.d.ts +2 -2
- package/lib/predicates/next.js +172 -74
- package/lib/predicates/sort.js +3 -4
- package/lib/ssr/index.js +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +240 -128
- package/lib/storage/adapter/AsyncStorageDatabase.js +100 -39
- package/lib/storage/adapter/InMemoryStore.js +68 -17
- package/lib/storage/adapter/InMemoryStore.native.js +5 -3
- package/lib/storage/adapter/IndexedDBAdapter.js +355 -199
- package/lib/storage/adapter/StorageAdapterBase.js +154 -85
- package/lib/storage/adapter/getDefaultAdapter/index.js +8 -9
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -3
- package/lib/storage/adapter/index.js +0 -1
- package/lib/storage/relationship.js +31 -21
- package/lib/storage/storage.d.ts +3 -3
- package/lib/storage/storage.js +143 -61
- package/lib/sync/datastoreConnectivity.d.ts +1 -1
- package/lib/sync/datastoreConnectivity.js +57 -9
- package/lib/sync/datastoreReachability/index.js +3 -3
- package/lib/sync/datastoreReachability/index.native.js +7 -5
- package/lib/sync/index.d.ts +1 -1
- package/lib/sync/index.js +193 -125
- package/lib/sync/merger.js +81 -10
- package/lib/sync/outbox.js +101 -30
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +41 -6
- package/lib/sync/processors/mutation.d.ts +1 -1
- package/lib/sync/processors/mutation.js +192 -101
- package/lib/sync/processors/subscription.d.ts +4 -1
- package/lib/sync/processors/subscription.js +190 -178
- package/lib/sync/processors/sync.d.ts +1 -1
- package/lib/sync/processors/sync.js +113 -47
- package/lib/sync/utils.d.ts +4 -4
- package/lib/sync/utils.js +162 -81
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types.d.ts +138 -140
- package/lib/types.js +40 -5
- package/lib/util.d.ts +9 -17
- package/lib/util.js +216 -100
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +0 -1
- package/lib-esm/authModeStrategies/index.js +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +76 -21
- package/lib-esm/datastore/datastore.d.ts +3 -4
- package/lib-esm/datastore/datastore.js +206 -77
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +0 -1
- package/lib-esm/predicates/index.js +40 -7
- package/lib-esm/predicates/next.d.ts +2 -2
- package/lib-esm/predicates/next.js +148 -52
- package/lib-esm/predicates/sort.js +2 -4
- package/lib-esm/ssr/index.js +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +203 -95
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +66 -5
- package/lib-esm/storage/adapter/InMemoryStore.js +52 -2
- package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +271 -138
- package/lib-esm/storage/adapter/StorageAdapterBase.js +130 -62
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -5
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +0 -1
- package/lib-esm/storage/adapter/index.js +1 -1
- package/lib-esm/storage/relationship.js +27 -18
- package/lib-esm/storage/storage.d.ts +3 -3
- package/lib-esm/storage/storage.js +87 -9
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +48 -3
- package/lib-esm/sync/datastoreReachability/index.js +1 -2
- package/lib-esm/sync/datastoreReachability/index.native.js +1 -2
- package/lib-esm/sync/index.d.ts +1 -1
- package/lib-esm/sync/index.js +136 -72
- package/lib-esm/sync/merger.js +73 -3
- package/lib-esm/sync/outbox.js +75 -5
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +39 -5
- package/lib-esm/sync/processors/mutation.d.ts +1 -1
- package/lib-esm/sync/processors/mutation.js +130 -44
- package/lib-esm/sync/processors/subscription.d.ts +4 -1
- package/lib-esm/sync/processors/subscription.js +134 -126
- package/lib-esm/sync/processors/sync.d.ts +1 -1
- package/lib-esm/sync/processors/sync.js +74 -12
- package/lib-esm/sync/utils.d.ts +4 -4
- package/lib-esm/sync/utils.js +135 -55
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types.d.ts +138 -140
- package/lib-esm/types.js +36 -2
- package/lib-esm/util.d.ts +9 -17
- package/lib-esm/util.js +96 -16
- package/package.json +139 -132
- package/src/authModeStrategies/multiAuthStrategy.ts +11 -12
- package/src/datastore/datastore.ts +32 -25
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/InMemoryStore.ts +1 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +1 -1
- package/src/storage/adapter/StorageAdapterBase.ts +1 -1
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -3
- package/src/storage/storage.ts +1 -1
- package/src/sync/datastoreConnectivity.ts +2 -2
- package/src/sync/datastoreReachability/index.native.ts +1 -1
- package/src/sync/datastoreReachability/index.ts +1 -1
- package/src/sync/index.ts +69 -78
- package/src/sync/processors/mutation.ts +16 -10
- package/src/sync/processors/subscription.ts +55 -127
- package/src/sync/processors/sync.ts +8 -4
- package/src/sync/utils.ts +7 -8
- package/src/types.ts +4 -8
- package/src/util.ts +5 -6
- package/lib/.tsbuildinfo +0 -3
- package/lib/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib/authModeStrategies/index.js.map +0 -1
- package/lib/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib/datastore/datastore.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/predicates/index.js.map +0 -1
- package/lib/predicates/next.js.map +0 -1
- package/lib/predicates/sort.js.map +0 -1
- package/lib/ssr/index.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib/storage/adapter/index.js.map +0 -1
- package/lib/storage/relationship.js.map +0 -1
- package/lib/storage/storage.js.map +0 -1
- package/lib/sync/datastoreConnectivity.js.map +0 -1
- package/lib/sync/datastoreReachability/index.js.map +0 -1
- package/lib/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib/sync/index.js.map +0 -1
- package/lib/sync/merger.js.map +0 -1
- package/lib/sync/outbox.js.map +0 -1
- package/lib/sync/processors/errorMaps.js.map +0 -1
- package/lib/sync/processors/mutation.js.map +0 -1
- package/lib/sync/processors/subscription.js.map +0 -1
- package/lib/sync/processors/sync.js.map +0 -1
- package/lib/sync/utils.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/util.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib-esm/authModeStrategies/index.js.map +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib-esm/datastore/datastore.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/predicates/index.js.map +0 -1
- package/lib-esm/predicates/next.js.map +0 -1
- package/lib-esm/predicates/sort.js.map +0 -1
- package/lib-esm/ssr/index.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib-esm/storage/adapter/index.js.map +0 -1
- package/lib-esm/storage/relationship.js.map +0 -1
- package/lib-esm/storage/storage.js.map +0 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib-esm/sync/index.js.map +0 -1
- package/lib-esm/sync/merger.js.map +0 -1
- package/lib-esm/sync/outbox.js.map +0 -1
- package/lib-esm/sync/processors/errorMaps.js.map +0 -1
- package/lib-esm/sync/processors/mutation.js.map +0 -1
- package/lib-esm/sync/processors/subscription.js.map +0 -1
- package/lib-esm/sync/processors/sync.js.map +0 -1
- package/lib-esm/sync/utils.js.map +0 -1
- package/lib-esm/types.js.map +0 -1
- package/lib-esm/util.js.map +0 -1
|
@@ -1,25 +1,97 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
54
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
55
|
+
var m = o[Symbol.asyncIterator], i;
|
|
56
|
+
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);
|
|
57
|
+
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); }); }; }
|
|
58
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
72
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
73
|
+
};
|
|
2
74
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
75
|
+
exports.AsyncStorageAdapter = void 0;
|
|
4
76
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
77
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
var AsyncStorageDatabase_1 =
|
|
78
|
+
var AsyncStorageDatabase_1 = __importDefault(require("./AsyncStorageDatabase"));
|
|
7
79
|
var types_1 = require("../../types");
|
|
8
80
|
var util_1 = require("../../util");
|
|
9
81
|
var StorageAdapterBase_1 = require("./StorageAdapterBase");
|
|
10
82
|
var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
11
|
-
|
|
83
|
+
__extends(AsyncStorageAdapter, _super);
|
|
12
84
|
function AsyncStorageAdapter() {
|
|
13
85
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
14
86
|
}
|
|
15
87
|
// no-ops for this adapter
|
|
16
88
|
AsyncStorageAdapter.prototype.preSetUpChecks = function () {
|
|
17
|
-
return
|
|
89
|
+
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
18
90
|
return [2 /*return*/];
|
|
19
91
|
}); });
|
|
20
92
|
};
|
|
21
93
|
AsyncStorageAdapter.prototype.preOpCheck = function () {
|
|
22
|
-
return
|
|
94
|
+
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
23
95
|
return [2 /*return*/];
|
|
24
96
|
}); });
|
|
25
97
|
};
|
|
@@ -32,9 +104,9 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
32
104
|
* @returns AsyncStorageDatabase instance
|
|
33
105
|
*/
|
|
34
106
|
AsyncStorageAdapter.prototype.initDb = function () {
|
|
35
|
-
return
|
|
107
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
36
108
|
var db;
|
|
37
|
-
return
|
|
109
|
+
return __generator(this, function (_a) {
|
|
38
110
|
switch (_a.label) {
|
|
39
111
|
case 0:
|
|
40
112
|
db = new AsyncStorageDatabase_1.default();
|
|
@@ -47,8 +119,8 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
47
119
|
});
|
|
48
120
|
};
|
|
49
121
|
AsyncStorageAdapter.prototype.clear = function () {
|
|
50
|
-
return
|
|
51
|
-
return
|
|
122
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
123
|
+
return __generator(this, function (_a) {
|
|
52
124
|
switch (_a.label) {
|
|
53
125
|
case 0: return [4 /*yield*/, this.db.clear()];
|
|
54
126
|
case 1:
|
|
@@ -61,11 +133,11 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
61
133
|
});
|
|
62
134
|
};
|
|
63
135
|
AsyncStorageAdapter.prototype.batchSave = function (modelConstructor, items) {
|
|
64
|
-
return
|
|
136
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
137
|
var modelName, namespaceName, storeName, keys, batch, _loop_1, this_1, items_1, items_1_1, item;
|
|
66
138
|
var e_1, _a;
|
|
67
139
|
var _this = this;
|
|
68
|
-
return
|
|
140
|
+
return __generator(this, function (_b) {
|
|
69
141
|
switch (_b.label) {
|
|
70
142
|
case 0:
|
|
71
143
|
if (items.length === 0) {
|
|
@@ -73,23 +145,23 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
73
145
|
}
|
|
74
146
|
modelName = modelConstructor.name;
|
|
75
147
|
namespaceName = this.namespaceResolver(modelConstructor);
|
|
76
|
-
storeName = util_1.getStorename(namespaceName, modelName);
|
|
77
|
-
keys = util_1.getIndexKeys(this.schema.namespaces[namespaceName], modelName);
|
|
148
|
+
storeName = (0, util_1.getStorename)(namespaceName, modelName);
|
|
149
|
+
keys = (0, util_1.getIndexKeys)(this.schema.namespaces[namespaceName], modelName);
|
|
78
150
|
batch = [];
|
|
79
151
|
_loop_1 = function (item) {
|
|
80
152
|
var model = this_1.modelInstanceCreator(modelConstructor, item);
|
|
81
|
-
var connectedModels = util_1.traverseModel(modelName, model, this_1.schema.namespaces[namespaceName], this_1.modelInstanceCreator, this_1.getModelConstructorByModelName);
|
|
153
|
+
var connectedModels = (0, util_1.traverseModel)(modelName, model, this_1.schema.namespaces[namespaceName], this_1.modelInstanceCreator, this_1.getModelConstructorByModelName);
|
|
82
154
|
var keyValuesPath = this_1.getIndexKeyValuesPath(model);
|
|
83
155
|
var instance = connectedModels.find(function (_a) {
|
|
84
156
|
var instance = _a.instance;
|
|
85
157
|
var instanceKeyValuesPath = _this.getIndexKeyValuesPath(instance);
|
|
86
|
-
return util_1.keysEqual([instanceKeyValuesPath], [keyValuesPath]);
|
|
158
|
+
return (0, util_1.keysEqual)([instanceKeyValuesPath], [keyValuesPath]);
|
|
87
159
|
}).instance;
|
|
88
160
|
batch.push(instance);
|
|
89
161
|
};
|
|
90
162
|
this_1 = this;
|
|
91
163
|
try {
|
|
92
|
-
for (items_1 =
|
|
164
|
+
for (items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
93
165
|
item = items_1_1.value;
|
|
94
166
|
_loop_1(item);
|
|
95
167
|
}
|
|
@@ -108,9 +180,9 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
108
180
|
});
|
|
109
181
|
};
|
|
110
182
|
AsyncStorageAdapter.prototype._get = function (storeName, keyArr) {
|
|
111
|
-
return
|
|
183
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
184
|
var itemKeyValuesPath;
|
|
113
|
-
return
|
|
185
|
+
return __generator(this, function (_a) {
|
|
114
186
|
switch (_a.label) {
|
|
115
187
|
case 0:
|
|
116
188
|
itemKeyValuesPath = keyArr.join(util_1.DEFAULT_PRIMARY_KEY_VALUE_SEPARATOR);
|
|
@@ -121,74 +193,97 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
121
193
|
});
|
|
122
194
|
};
|
|
123
195
|
AsyncStorageAdapter.prototype.save = function (model, condition) {
|
|
124
|
-
var e_2,
|
|
125
|
-
return
|
|
126
|
-
var
|
|
127
|
-
return
|
|
128
|
-
switch (
|
|
196
|
+
var _a, e_2, _b, _c;
|
|
197
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
198
|
+
var _d, storeName, connectionStoreNames, modelKeyValues, fromDB, result, _loop_2, this_2, _e, connectionStoreNames_1, connectionStoreNames_1_1, e_2_1;
|
|
199
|
+
return __generator(this, function (_f) {
|
|
200
|
+
switch (_f.label) {
|
|
129
201
|
case 0:
|
|
130
|
-
|
|
202
|
+
_d = this.saveMetadata(model), storeName = _d.storeName, connectionStoreNames = _d.connectionStoreNames, modelKeyValues = _d.modelKeyValues;
|
|
131
203
|
return [4 /*yield*/, this._get(storeName, modelKeyValues)];
|
|
132
204
|
case 1:
|
|
133
|
-
fromDB =
|
|
205
|
+
fromDB = _f.sent();
|
|
134
206
|
this.validateSaveCondition(condition, fromDB);
|
|
135
207
|
result = [];
|
|
136
|
-
|
|
208
|
+
_f.label = 2;
|
|
137
209
|
case 2:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
210
|
+
_f.trys.push([2, 8, 9, 14]);
|
|
211
|
+
_loop_2 = function () {
|
|
212
|
+
var resItem, storeName_1, item, instance, keys, itemKeyValues, fromDB_1, opType;
|
|
213
|
+
return __generator(this, function (_g) {
|
|
214
|
+
switch (_g.label) {
|
|
215
|
+
case 0:
|
|
216
|
+
_c = connectionStoreNames_1_1.value;
|
|
217
|
+
_e = false;
|
|
218
|
+
_g.label = 1;
|
|
219
|
+
case 1:
|
|
220
|
+
_g.trys.push([1, , 5, 6]);
|
|
221
|
+
resItem = _c;
|
|
222
|
+
storeName_1 = resItem.storeName, item = resItem.item, instance = resItem.instance, keys = resItem.keys;
|
|
223
|
+
itemKeyValues = keys.map(function (key) { return item[key]; });
|
|
224
|
+
return [4 /*yield*/, this_2._get(storeName_1, itemKeyValues)];
|
|
225
|
+
case 2:
|
|
226
|
+
fromDB_1 = _g.sent();
|
|
227
|
+
opType = fromDB_1 ? types_1.OpType.UPDATE : types_1.OpType.INSERT;
|
|
228
|
+
if (!((0, util_1.keysEqual)(itemKeyValues, modelKeyValues) ||
|
|
229
|
+
opType === types_1.OpType.INSERT)) return [3 /*break*/, 4];
|
|
230
|
+
return [4 /*yield*/, this_2.db.save(item, storeName_1, keys, itemKeyValues.join(util_1.DEFAULT_PRIMARY_KEY_VALUE_SEPARATOR))];
|
|
231
|
+
case 3:
|
|
232
|
+
_g.sent();
|
|
233
|
+
result.push([instance, opType]);
|
|
234
|
+
_g.label = 4;
|
|
235
|
+
case 4: return [3 /*break*/, 6];
|
|
236
|
+
case 5:
|
|
237
|
+
_e = true;
|
|
238
|
+
return [7 /*endfinally*/];
|
|
239
|
+
case 6: return [2 /*return*/];
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
this_2 = this;
|
|
244
|
+
_e = true, connectionStoreNames_1 = __asyncValues(connectionStoreNames);
|
|
245
|
+
_f.label = 3;
|
|
141
246
|
case 3: return [4 /*yield*/, connectionStoreNames_1.next()];
|
|
142
247
|
case 4:
|
|
143
|
-
if (!(connectionStoreNames_1_1 =
|
|
144
|
-
|
|
145
|
-
storeName_1 = resItem.storeName, item = resItem.item, instance = resItem.instance, keys = resItem.keys;
|
|
146
|
-
itemKeyValues = keys.map(function (key) { return item[key]; });
|
|
147
|
-
return [4 /*yield*/, this._get(storeName_1, itemKeyValues)];
|
|
248
|
+
if (!(connectionStoreNames_1_1 = _f.sent(), _a = connectionStoreNames_1_1.done, !_a)) return [3 /*break*/, 7];
|
|
249
|
+
return [5 /*yield**/, _loop_2()];
|
|
148
250
|
case 5:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
_c.sent();
|
|
156
|
-
result.push([instance, opType]);
|
|
157
|
-
_c.label = 7;
|
|
158
|
-
case 7: return [3 /*break*/, 3];
|
|
159
|
-
case 8: return [3 /*break*/, 15];
|
|
160
|
-
case 9:
|
|
161
|
-
e_2_1 = _c.sent();
|
|
251
|
+
_f.sent();
|
|
252
|
+
_f.label = 6;
|
|
253
|
+
case 6: return [3 /*break*/, 3];
|
|
254
|
+
case 7: return [3 /*break*/, 14];
|
|
255
|
+
case 8:
|
|
256
|
+
e_2_1 = _f.sent();
|
|
162
257
|
e_2 = { error: e_2_1 };
|
|
163
|
-
return [3 /*break*/,
|
|
258
|
+
return [3 /*break*/, 14];
|
|
259
|
+
case 9:
|
|
260
|
+
_f.trys.push([9, , 12, 13]);
|
|
261
|
+
if (!(!_e && !_a && (_b = connectionStoreNames_1.return))) return [3 /*break*/, 11];
|
|
262
|
+
return [4 /*yield*/, _b.call(connectionStoreNames_1)];
|
|
164
263
|
case 10:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
case
|
|
169
|
-
_c.sent();
|
|
170
|
-
_c.label = 12;
|
|
171
|
-
case 12: return [3 /*break*/, 14];
|
|
172
|
-
case 13:
|
|
264
|
+
_f.sent();
|
|
265
|
+
_f.label = 11;
|
|
266
|
+
case 11: return [3 /*break*/, 13];
|
|
267
|
+
case 12:
|
|
173
268
|
if (e_2) throw e_2.error;
|
|
174
269
|
return [7 /*endfinally*/];
|
|
175
|
-
case
|
|
176
|
-
case
|
|
270
|
+
case 13: return [7 /*endfinally*/];
|
|
271
|
+
case 14: return [2 /*return*/, result];
|
|
177
272
|
}
|
|
178
273
|
});
|
|
179
274
|
});
|
|
180
275
|
};
|
|
181
276
|
AsyncStorageAdapter.prototype.query = function (modelConstructor, predicate, pagination) {
|
|
182
|
-
return
|
|
277
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
183
278
|
var _a, storeName, namespaceName, queryByKey, predicates, hasSort, hasPagination, records;
|
|
184
279
|
var _this = this;
|
|
185
|
-
return
|
|
280
|
+
return __generator(this, function (_b) {
|
|
186
281
|
switch (_b.label) {
|
|
187
282
|
case 0:
|
|
188
283
|
_a = this.queryMetadata(modelConstructor, predicate, pagination), storeName = _a.storeName, namespaceName = _a.namespaceName, queryByKey = _a.queryByKey, predicates = _a.predicates, hasSort = _a.hasSort, hasPagination = _a.hasPagination;
|
|
189
|
-
return [4 /*yield*/, (function () { return
|
|
284
|
+
return [4 /*yield*/, (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
190
285
|
var keyValues, record, filtered, all;
|
|
191
|
-
return
|
|
286
|
+
return __generator(this, function (_a) {
|
|
192
287
|
switch (_a.label) {
|
|
193
288
|
case 0:
|
|
194
289
|
if (!queryByKey) return [3 /*break*/, 2];
|
|
@@ -222,8 +317,8 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
222
317
|
});
|
|
223
318
|
};
|
|
224
319
|
AsyncStorageAdapter.prototype.getByKey = function (storeName, keyValuePath) {
|
|
225
|
-
return
|
|
226
|
-
return
|
|
320
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
321
|
+
return __generator(this, function (_a) {
|
|
227
322
|
switch (_a.label) {
|
|
228
323
|
case 0: return [4 /*yield*/, this.db.get(keyValuePath, storeName)];
|
|
229
324
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -232,8 +327,8 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
232
327
|
});
|
|
233
328
|
};
|
|
234
329
|
AsyncStorageAdapter.prototype.getAll = function (storeName) {
|
|
235
|
-
return
|
|
236
|
-
return
|
|
330
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
331
|
+
return __generator(this, function (_a) {
|
|
237
332
|
switch (_a.label) {
|
|
238
333
|
case 0: return [4 /*yield*/, this.db.getAll(storeName)];
|
|
239
334
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -242,9 +337,9 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
242
337
|
});
|
|
243
338
|
};
|
|
244
339
|
AsyncStorageAdapter.prototype.filterOnPredicate = function (storeName, predicates) {
|
|
245
|
-
return
|
|
340
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
246
341
|
var predicateObjs, type, all, filtered;
|
|
247
|
-
return
|
|
342
|
+
return __generator(this, function (_a) {
|
|
248
343
|
switch (_a.label) {
|
|
249
344
|
case 0:
|
|
250
345
|
predicateObjs = predicates.predicates, type = predicates.type;
|
|
@@ -252,7 +347,7 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
252
347
|
case 1:
|
|
253
348
|
all = _a.sent();
|
|
254
349
|
filtered = predicateObjs
|
|
255
|
-
? all.filter(function (m) { return util_1.validatePredicate(m, type, predicateObjs); })
|
|
350
|
+
? all.filter(function (m) { return (0, util_1.validatePredicate)(m, type, predicateObjs); })
|
|
256
351
|
: all;
|
|
257
352
|
return [2 /*return*/, filtered];
|
|
258
353
|
}
|
|
@@ -260,13 +355,13 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
260
355
|
});
|
|
261
356
|
};
|
|
262
357
|
AsyncStorageAdapter.prototype.inMemoryPagination = function (records, pagination) {
|
|
263
|
-
return util_1.inMemoryPagination(records, pagination);
|
|
358
|
+
return (0, util_1.inMemoryPagination)(records, pagination);
|
|
264
359
|
};
|
|
265
360
|
AsyncStorageAdapter.prototype.queryOne = function (modelConstructor, firstOrLast) {
|
|
266
361
|
if (firstOrLast === void 0) { firstOrLast = types_1.QueryOne.FIRST; }
|
|
267
|
-
return
|
|
362
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
268
363
|
var storeName, result;
|
|
269
|
-
return
|
|
364
|
+
return __generator(this, function (_a) {
|
|
270
365
|
switch (_a.label) {
|
|
271
366
|
case 0:
|
|
272
367
|
storeName = this.getStorenameForModel(modelConstructor);
|
|
@@ -279,73 +374,91 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
279
374
|
});
|
|
280
375
|
};
|
|
281
376
|
AsyncStorageAdapter.prototype.deleteItem = function (deleteQueue) {
|
|
282
|
-
var e_3,
|
|
283
|
-
return
|
|
284
|
-
var
|
|
285
|
-
return
|
|
286
|
-
switch (
|
|
377
|
+
var _a, e_3, _b, _c, _d, e_4, _e, _f;
|
|
378
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
379
|
+
var _g, _h, _j, deleteItem, storeName, items, _k, items_2, items_2_1, item, keyValuesPath, e_4_1, e_3_1;
|
|
380
|
+
return __generator(this, function (_l) {
|
|
381
|
+
switch (_l.label) {
|
|
287
382
|
case 0:
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
case 1: return [4 /*yield*/,
|
|
383
|
+
_l.trys.push([0, 23, 24, 29]);
|
|
384
|
+
_g = true, _h = __asyncValues(deleteQueue);
|
|
385
|
+
_l.label = 1;
|
|
386
|
+
case 1: return [4 /*yield*/, _h.next()];
|
|
292
387
|
case 2:
|
|
293
|
-
if (!(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
388
|
+
if (!(_j = _l.sent(), _a = _j.done, !_a)) return [3 /*break*/, 22];
|
|
389
|
+
_c = _j.value;
|
|
390
|
+
_g = false;
|
|
391
|
+
_l.label = 3;
|
|
297
392
|
case 3:
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
case
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
393
|
+
_l.trys.push([3, , 20, 21]);
|
|
394
|
+
deleteItem = _c;
|
|
395
|
+
storeName = deleteItem.storeName, items = deleteItem.items;
|
|
396
|
+
_l.label = 4;
|
|
397
|
+
case 4:
|
|
398
|
+
_l.trys.push([4, 13, 14, 19]);
|
|
399
|
+
_k = true, items_2 = (e_4 = void 0, __asyncValues(items));
|
|
400
|
+
_l.label = 5;
|
|
401
|
+
case 5: return [4 /*yield*/, items_2.next()];
|
|
402
|
+
case 6:
|
|
403
|
+
if (!(items_2_1 = _l.sent(), _d = items_2_1.done, !_d)) return [3 /*break*/, 12];
|
|
404
|
+
_f = items_2_1.value;
|
|
405
|
+
_k = false;
|
|
406
|
+
_l.label = 7;
|
|
407
|
+
case 7:
|
|
408
|
+
_l.trys.push([7, , 10, 11]);
|
|
409
|
+
item = _f;
|
|
410
|
+
if (!item) return [3 /*break*/, 9];
|
|
411
|
+
if (!(typeof item === 'object')) return [3 /*break*/, 9];
|
|
307
412
|
keyValuesPath = this.getIndexKeyValuesPath(item);
|
|
308
413
|
return [4 /*yield*/, this.db.delete(keyValuesPath, storeName)];
|
|
309
|
-
case
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
case
|
|
313
|
-
case 8: return [3 /*break*/, 15];
|
|
314
|
-
case 9:
|
|
315
|
-
e_4_1 = _e.sent();
|
|
316
|
-
e_4 = { error: e_4_1 };
|
|
317
|
-
return [3 /*break*/, 15];
|
|
414
|
+
case 8:
|
|
415
|
+
_l.sent();
|
|
416
|
+
_l.label = 9;
|
|
417
|
+
case 9: return [3 /*break*/, 11];
|
|
318
418
|
case 10:
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
case
|
|
323
|
-
_e.sent();
|
|
324
|
-
_e.label = 12;
|
|
325
|
-
case 12: return [3 /*break*/, 14];
|
|
419
|
+
_k = true;
|
|
420
|
+
return [7 /*endfinally*/];
|
|
421
|
+
case 11: return [3 /*break*/, 5];
|
|
422
|
+
case 12: return [3 /*break*/, 19];
|
|
326
423
|
case 13:
|
|
424
|
+
e_4_1 = _l.sent();
|
|
425
|
+
e_4 = { error: e_4_1 };
|
|
426
|
+
return [3 /*break*/, 19];
|
|
427
|
+
case 14:
|
|
428
|
+
_l.trys.push([14, , 17, 18]);
|
|
429
|
+
if (!(!_k && !_d && (_e = items_2.return))) return [3 /*break*/, 16];
|
|
430
|
+
return [4 /*yield*/, _e.call(items_2)];
|
|
431
|
+
case 15:
|
|
432
|
+
_l.sent();
|
|
433
|
+
_l.label = 16;
|
|
434
|
+
case 16: return [3 /*break*/, 18];
|
|
435
|
+
case 17:
|
|
327
436
|
if (e_4) throw e_4.error;
|
|
328
437
|
return [7 /*endfinally*/];
|
|
329
|
-
case
|
|
330
|
-
case
|
|
331
|
-
case
|
|
332
|
-
|
|
333
|
-
|
|
438
|
+
case 18: return [7 /*endfinally*/];
|
|
439
|
+
case 19: return [3 /*break*/, 21];
|
|
440
|
+
case 20:
|
|
441
|
+
_g = true;
|
|
442
|
+
return [7 /*endfinally*/];
|
|
443
|
+
case 21: return [3 /*break*/, 1];
|
|
444
|
+
case 22: return [3 /*break*/, 29];
|
|
445
|
+
case 23:
|
|
446
|
+
e_3_1 = _l.sent();
|
|
334
447
|
e_3 = { error: e_3_1 };
|
|
335
|
-
return [3 /*break*/,
|
|
336
|
-
case
|
|
337
|
-
|
|
338
|
-
if (!(
|
|
339
|
-
return [4 /*yield*/,
|
|
340
|
-
case
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
case
|
|
344
|
-
case
|
|
448
|
+
return [3 /*break*/, 29];
|
|
449
|
+
case 24:
|
|
450
|
+
_l.trys.push([24, , 27, 28]);
|
|
451
|
+
if (!(!_g && !_a && (_b = _h.return))) return [3 /*break*/, 26];
|
|
452
|
+
return [4 /*yield*/, _b.call(_h)];
|
|
453
|
+
case 25:
|
|
454
|
+
_l.sent();
|
|
455
|
+
_l.label = 26;
|
|
456
|
+
case 26: return [3 /*break*/, 28];
|
|
457
|
+
case 27:
|
|
345
458
|
if (e_3) throw e_3.error;
|
|
346
459
|
return [7 /*endfinally*/];
|
|
347
|
-
case
|
|
348
|
-
case
|
|
460
|
+
case 28: return [7 /*endfinally*/];
|
|
461
|
+
case 29: return [2 /*return*/];
|
|
349
462
|
}
|
|
350
463
|
});
|
|
351
464
|
});
|
|
@@ -364,4 +477,3 @@ var AsyncStorageAdapter = /** @class */ (function (_super) {
|
|
|
364
477
|
}(StorageAdapterBase_1.StorageAdapterBase));
|
|
365
478
|
exports.AsyncStorageAdapter = AsyncStorageAdapter;
|
|
366
479
|
exports.default = new AsyncStorageAdapter();
|
|
367
|
-
//# sourceMappingURL=AsyncStorageAdapter.js.map
|