@aws-amplify/datastore 4.7.5 → 5.0.1-console-preview.4208d73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/lib/authModeStrategies/defaultAuthStrategy.js +3 -2
- package/lib/authModeStrategies/index.js +3 -3
- package/lib/authModeStrategies/multiAuthStrategy.js +81 -24
- package/lib/datastore/datastore.d.ts +3 -4
- package/lib/datastore/datastore.js +361 -227
- package/lib/index.d.ts +1 -1
- package/lib/index.js +25 -12
- package/lib/predicates/index.js +46 -12
- package/lib/predicates/next.d.ts +2 -2
- package/lib/predicates/next.js +172 -74
- package/lib/predicates/sort.js +3 -4
- package/lib/ssr/index.js +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +240 -128
- package/lib/storage/adapter/AsyncStorageDatabase.js +100 -39
- package/lib/storage/adapter/InMemoryStore.js +68 -17
- package/lib/storage/adapter/InMemoryStore.native.js +5 -3
- package/lib/storage/adapter/IndexedDBAdapter.js +355 -199
- package/lib/storage/adapter/StorageAdapterBase.js +154 -85
- package/lib/storage/adapter/getDefaultAdapter/index.js +8 -9
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -3
- package/lib/storage/adapter/index.js +0 -1
- package/lib/storage/relationship.js +31 -21
- package/lib/storage/storage.d.ts +3 -3
- package/lib/storage/storage.js +143 -61
- package/lib/sync/datastoreConnectivity.d.ts +1 -1
- package/lib/sync/datastoreConnectivity.js +57 -9
- package/lib/sync/datastoreReachability/index.js +3 -3
- package/lib/sync/datastoreReachability/index.native.js +7 -5
- package/lib/sync/index.d.ts +1 -1
- package/lib/sync/index.js +193 -125
- package/lib/sync/merger.js +81 -10
- package/lib/sync/outbox.js +101 -30
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +41 -6
- package/lib/sync/processors/mutation.d.ts +1 -1
- package/lib/sync/processors/mutation.js +192 -101
- package/lib/sync/processors/subscription.d.ts +4 -1
- package/lib/sync/processors/subscription.js +190 -178
- package/lib/sync/processors/sync.d.ts +1 -1
- package/lib/sync/processors/sync.js +113 -47
- package/lib/sync/utils.d.ts +4 -4
- package/lib/sync/utils.js +162 -81
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types.d.ts +138 -140
- package/lib/types.js +40 -5
- package/lib/util.d.ts +9 -17
- package/lib/util.js +216 -100
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +0 -1
- package/lib-esm/authModeStrategies/index.js +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +76 -21
- package/lib-esm/datastore/datastore.d.ts +3 -4
- package/lib-esm/datastore/datastore.js +206 -77
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +0 -1
- package/lib-esm/predicates/index.js +40 -7
- package/lib-esm/predicates/next.d.ts +2 -2
- package/lib-esm/predicates/next.js +148 -52
- package/lib-esm/predicates/sort.js +2 -4
- package/lib-esm/ssr/index.js +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +203 -95
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +66 -5
- package/lib-esm/storage/adapter/InMemoryStore.js +52 -2
- package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +271 -138
- package/lib-esm/storage/adapter/StorageAdapterBase.js +130 -62
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -5
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +0 -1
- package/lib-esm/storage/adapter/index.js +1 -1
- package/lib-esm/storage/relationship.js +27 -18
- package/lib-esm/storage/storage.d.ts +3 -3
- package/lib-esm/storage/storage.js +87 -9
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +48 -3
- package/lib-esm/sync/datastoreReachability/index.js +1 -2
- package/lib-esm/sync/datastoreReachability/index.native.js +1 -2
- package/lib-esm/sync/index.d.ts +1 -1
- package/lib-esm/sync/index.js +136 -72
- package/lib-esm/sync/merger.js +73 -3
- package/lib-esm/sync/outbox.js +75 -5
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +39 -5
- package/lib-esm/sync/processors/mutation.d.ts +1 -1
- package/lib-esm/sync/processors/mutation.js +130 -44
- package/lib-esm/sync/processors/subscription.d.ts +4 -1
- package/lib-esm/sync/processors/subscription.js +134 -126
- package/lib-esm/sync/processors/sync.d.ts +1 -1
- package/lib-esm/sync/processors/sync.js +74 -12
- package/lib-esm/sync/utils.d.ts +4 -4
- package/lib-esm/sync/utils.js +135 -55
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types.d.ts +138 -140
- package/lib-esm/types.js +36 -2
- package/lib-esm/util.d.ts +9 -17
- package/lib-esm/util.js +96 -16
- package/package.json +139 -132
- package/src/authModeStrategies/multiAuthStrategy.ts +11 -12
- package/src/datastore/datastore.ts +32 -25
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/InMemoryStore.ts +1 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +1 -1
- package/src/storage/adapter/StorageAdapterBase.ts +1 -1
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -3
- package/src/storage/storage.ts +1 -1
- package/src/sync/datastoreConnectivity.ts +2 -2
- package/src/sync/datastoreReachability/index.native.ts +1 -1
- package/src/sync/datastoreReachability/index.ts +1 -1
- package/src/sync/index.ts +69 -78
- package/src/sync/processors/mutation.ts +16 -10
- package/src/sync/processors/subscription.ts +55 -127
- package/src/sync/processors/sync.ts +8 -4
- package/src/sync/utils.ts +7 -8
- package/src/types.ts +4 -8
- package/src/util.ts +5 -6
- package/lib/.tsbuildinfo +0 -3
- package/lib/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib/authModeStrategies/index.js.map +0 -1
- package/lib/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib/datastore/datastore.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/predicates/index.js.map +0 -1
- package/lib/predicates/next.js.map +0 -1
- package/lib/predicates/sort.js.map +0 -1
- package/lib/ssr/index.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib/storage/adapter/index.js.map +0 -1
- package/lib/storage/relationship.js.map +0 -1
- package/lib/storage/storage.js.map +0 -1
- package/lib/sync/datastoreConnectivity.js.map +0 -1
- package/lib/sync/datastoreReachability/index.js.map +0 -1
- package/lib/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib/sync/index.js.map +0 -1
- package/lib/sync/merger.js.map +0 -1
- package/lib/sync/outbox.js.map +0 -1
- package/lib/sync/processors/errorMaps.js.map +0 -1
- package/lib/sync/processors/mutation.js.map +0 -1
- package/lib/sync/processors/subscription.js.map +0 -1
- package/lib/sync/processors/sync.js.map +0 -1
- package/lib/sync/utils.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/util.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib-esm/authModeStrategies/index.js.map +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib-esm/datastore/datastore.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/predicates/index.js.map +0 -1
- package/lib-esm/predicates/next.js.map +0 -1
- package/lib-esm/predicates/sort.js.map +0 -1
- package/lib-esm/ssr/index.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib-esm/storage/adapter/index.js.map +0 -1
- package/lib-esm/storage/relationship.js.map +0 -1
- package/lib-esm/storage/storage.js.map +0 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib-esm/sync/index.js.map +0 -1
- package/lib-esm/sync/merger.js.map +0 -1
- package/lib-esm/sync/outbox.js.map +0 -1
- package/lib-esm/sync/processors/errorMaps.js.map +0 -1
- package/lib-esm/sync/processors/mutation.js.map +0 -1
- package/lib-esm/sync/processors/subscription.js.map +0 -1
- package/lib-esm/sync/processors/sync.js.map +0 -1
- package/lib-esm/sync/utils.js.map +0 -1
- package/lib-esm/types.js.map +0 -1
- package/lib-esm/util.js.map +0 -1
package/lib/sync/index.js
CHANGED
|
@@ -1,23 +1,98 @@
|
|
|
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 (g && (g = 0, op[0] && (_ = 0)), _) 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 __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
var __values = (this && this.__values) || function(o) {
|
|
55
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
56
|
+
if (m) return m.call(o);
|
|
57
|
+
if (o && typeof o.length === "number") return {
|
|
58
|
+
next: function () {
|
|
59
|
+
if (o && i >= o.length) o = void 0;
|
|
60
|
+
return { value: o && o[i++], done: !o };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
64
|
+
};
|
|
65
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
+
if (ar || !(i in from)) {
|
|
68
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
+
ar[i] = from[i];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
+
};
|
|
74
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
75
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
76
|
+
};
|
|
2
77
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
78
|
+
exports.SyncEngine = exports.ControlMessage = void 0;
|
|
4
79
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
80
|
// SPDX-License-Identifier: Apache-2.0
|
|
81
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
6
82
|
var core_1 = require("@aws-amplify/core");
|
|
7
|
-
var
|
|
8
|
-
var zen_observable_ts_1 = tslib_1.__importDefault(require("zen-observable-ts"));
|
|
83
|
+
var zen_observable_ts_1 = __importDefault(require("zen-observable-ts"));
|
|
9
84
|
var predicates_1 = require("../predicates");
|
|
10
85
|
var types_1 = require("../types");
|
|
11
86
|
var util_1 = require("../util");
|
|
12
|
-
var datastoreConnectivity_1 =
|
|
87
|
+
var datastoreConnectivity_1 = __importDefault(require("./datastoreConnectivity"));
|
|
13
88
|
var merger_1 = require("./merger");
|
|
14
89
|
var outbox_1 = require("./outbox");
|
|
15
90
|
var mutation_1 = require("./processors/mutation");
|
|
16
91
|
var subscription_1 = require("./processors/subscription");
|
|
17
92
|
var sync_1 = require("./processors/sync");
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var logger = new
|
|
93
|
+
var utils_2 = require("./utils");
|
|
94
|
+
var api_graphql_1 = require("@aws-amplify/api-graphql");
|
|
95
|
+
var logger = new utils_1.Logger('DataStore');
|
|
21
96
|
var ownSymbol = Symbol('sync');
|
|
22
97
|
var ControlMessage;
|
|
23
98
|
(function (ControlMessage) {
|
|
@@ -34,8 +109,8 @@ var ControlMessage;
|
|
|
34
109
|
})(ControlMessage = exports.ControlMessage || (exports.ControlMessage = {}));
|
|
35
110
|
var SyncEngine = /** @class */ (function () {
|
|
36
111
|
function SyncEngine(schema, namespaceResolver, modelClasses, userModelClasses, storage, modelInstanceCreator, conflictHandler, errorHandler, syncPredicates, amplifyConfig, authModeStrategy, amplifyContext, connectivityMonitor) {
|
|
37
|
-
var _this = this;
|
|
38
112
|
if (amplifyConfig === void 0) { amplifyConfig = {}; }
|
|
113
|
+
var _this = this;
|
|
39
114
|
this.schema = schema;
|
|
40
115
|
this.namespaceResolver = namespaceResolver;
|
|
41
116
|
this.modelClasses = modelClasses;
|
|
@@ -50,7 +125,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
50
125
|
this.online = false;
|
|
51
126
|
this.modelSyncedStatus = new WeakMap();
|
|
52
127
|
this.connectionDisrupted = false;
|
|
53
|
-
this.runningProcesses = new
|
|
128
|
+
this.runningProcesses = new utils_1.BackgroundProcessManager();
|
|
54
129
|
this.waitForSleepState = new Promise(function (resolve) {
|
|
55
130
|
_this.syncQueriesObservableStartSleeping = resolve;
|
|
56
131
|
});
|
|
@@ -71,10 +146,10 @@ var SyncEngine = /** @class */ (function () {
|
|
|
71
146
|
return new zen_observable_ts_1.default(function (observer) {
|
|
72
147
|
logger.log('starting sync engine...');
|
|
73
148
|
var subscriptions = [];
|
|
74
|
-
_this.runningProcesses.add(function () { return
|
|
149
|
+
_this.runningProcesses.add(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
75
150
|
var err_1, startPromise, hasMutationsInOutbox;
|
|
76
151
|
var _this = this;
|
|
77
|
-
return
|
|
152
|
+
return __generator(this, function (_a) {
|
|
78
153
|
switch (_a.label) {
|
|
79
154
|
case 0:
|
|
80
155
|
_a.trys.push([0, 2, , 3]);
|
|
@@ -90,18 +165,18 @@ var SyncEngine = /** @class */ (function () {
|
|
|
90
165
|
startPromise = new Promise(function (doneStarting, failedStarting) {
|
|
91
166
|
_this.datastoreConnectivity.status().subscribe(function (_a) {
|
|
92
167
|
var online = _a.online;
|
|
93
|
-
return
|
|
168
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
94
169
|
var _this = this;
|
|
95
|
-
return
|
|
170
|
+
return __generator(this, function (_b) {
|
|
96
171
|
return [2 /*return*/, this.runningProcesses.isOpen &&
|
|
97
|
-
this.runningProcesses.add(function (onTerminate) { return
|
|
172
|
+
this.runningProcesses.add(function (onTerminate) { return __awaiter(_this, void 0, void 0, function () {
|
|
98
173
|
var ctlSubsObservable_1, dataSubsObservable, err_2, error_1;
|
|
99
174
|
var _a;
|
|
100
175
|
var _this = this;
|
|
101
|
-
return
|
|
176
|
+
return __generator(this, function (_b) {
|
|
102
177
|
switch (_b.label) {
|
|
103
178
|
case 0:
|
|
104
|
-
if (!(online && !this.online)) return [3 /*break*/,
|
|
179
|
+
if (!(online && !this.online)) return [3 /*break*/, 9];
|
|
105
180
|
this.online = online;
|
|
106
181
|
observer.next({
|
|
107
182
|
type: ControlMessage.SYNC_ENGINE_NETWORK_STATUS,
|
|
@@ -110,17 +185,13 @@ var SyncEngine = /** @class */ (function () {
|
|
|
110
185
|
},
|
|
111
186
|
});
|
|
112
187
|
dataSubsObservable = void 0;
|
|
113
|
-
if (!isNode) return [3 /*break*/, 1];
|
|
114
|
-
logger.warn('Realtime disabled when in a server-side environment');
|
|
115
|
-
return [3 /*break*/, 6];
|
|
116
|
-
case 1:
|
|
117
188
|
this.stopDisruptionListener =
|
|
118
189
|
this.startDisruptionListener();
|
|
119
190
|
//#region GraphQL Subscriptions
|
|
120
|
-
_a =
|
|
121
|
-
_b.label =
|
|
122
|
-
case
|
|
123
|
-
_b.trys.push([
|
|
191
|
+
_a = __read(this.subscriptionsProcessor.start(), 2), ctlSubsObservable_1 = _a[0], dataSubsObservable = _a[1];
|
|
192
|
+
_b.label = 1;
|
|
193
|
+
case 1:
|
|
194
|
+
_b.trys.push([1, 3, , 4]);
|
|
124
195
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
125
196
|
onTerminate.then(reject);
|
|
126
197
|
var ctlSubsSubscription = ctlSubsObservable_1.subscribe({
|
|
@@ -137,22 +208,22 @@ var SyncEngine = /** @class */ (function () {
|
|
|
137
208
|
});
|
|
138
209
|
subscriptions.push(ctlSubsSubscription);
|
|
139
210
|
})];
|
|
140
|
-
case
|
|
211
|
+
case 2:
|
|
141
212
|
_b.sent();
|
|
142
|
-
return [3 /*break*/,
|
|
143
|
-
case
|
|
213
|
+
return [3 /*break*/, 4];
|
|
214
|
+
case 3:
|
|
144
215
|
err_2 = _b.sent();
|
|
145
216
|
observer.error(err_2);
|
|
146
217
|
failedStarting();
|
|
147
218
|
return [2 /*return*/];
|
|
148
|
-
case
|
|
219
|
+
case 4:
|
|
149
220
|
logger.log('Realtime ready');
|
|
150
221
|
observer.next({
|
|
151
222
|
type: ControlMessage.SYNC_ENGINE_SUBSCRIPTIONS_ESTABLISHED,
|
|
152
223
|
});
|
|
153
|
-
_b.label =
|
|
154
|
-
case
|
|
155
|
-
_b.trys.push([
|
|
224
|
+
_b.label = 5;
|
|
225
|
+
case 5:
|
|
226
|
+
_b.trys.push([5, 7, , 8]);
|
|
156
227
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
157
228
|
var syncQuerySubscription = _this.syncQueriesObservable().subscribe({
|
|
158
229
|
next: function (message) {
|
|
@@ -174,25 +245,25 @@ var SyncEngine = /** @class */ (function () {
|
|
|
174
245
|
subscriptions.push(syncQuerySubscription);
|
|
175
246
|
}
|
|
176
247
|
})];
|
|
177
|
-
case
|
|
248
|
+
case 6:
|
|
178
249
|
_b.sent();
|
|
179
|
-
return [3 /*break*/,
|
|
180
|
-
case
|
|
250
|
+
return [3 /*break*/, 8];
|
|
251
|
+
case 7:
|
|
181
252
|
error_1 = _b.sent();
|
|
182
253
|
observer.error(error_1);
|
|
183
254
|
failedStarting();
|
|
184
255
|
return [2 /*return*/];
|
|
185
|
-
case
|
|
256
|
+
case 8:
|
|
186
257
|
//#endregion
|
|
187
258
|
//#region process mutations (outbox)
|
|
188
259
|
subscriptions.push(this.mutationsProcessor
|
|
189
260
|
.start()
|
|
190
261
|
.subscribe(function (_a) {
|
|
191
262
|
var modelDefinition = _a.modelDefinition, item = _a.model, hasMore = _a.hasMore;
|
|
192
|
-
return _this.runningProcesses.add(function () { return
|
|
263
|
+
return _this.runningProcesses.add(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
193
264
|
var modelConstructor, model;
|
|
194
265
|
var _this = this;
|
|
195
|
-
return
|
|
266
|
+
return __generator(this, function (_a) {
|
|
196
267
|
switch (_a.label) {
|
|
197
268
|
case 0:
|
|
198
269
|
modelConstructor = this.userModelClasses[modelDefinition.name];
|
|
@@ -222,31 +293,28 @@ var SyncEngine = /** @class */ (function () {
|
|
|
222
293
|
}));
|
|
223
294
|
//#endregion
|
|
224
295
|
//#region Merge subscriptions buffer
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
var
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
return [3 /*break*/, 11];
|
|
249
|
-
case 10:
|
|
296
|
+
subscriptions.push(dataSubsObservable.subscribe(function (_a) {
|
|
297
|
+
var _b = __read(_a, 3), _transformerMutationType = _b[0], modelDefinition = _b[1], item = _b[2];
|
|
298
|
+
return _this.runningProcesses.add(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
299
|
+
var modelConstructor, model;
|
|
300
|
+
var _this = this;
|
|
301
|
+
return __generator(this, function (_a) {
|
|
302
|
+
switch (_a.label) {
|
|
303
|
+
case 0:
|
|
304
|
+
modelConstructor = this.userModelClasses[modelDefinition.name];
|
|
305
|
+
model = this.modelInstanceCreator(modelConstructor, item);
|
|
306
|
+
return [4 /*yield*/, this.storage.runExclusive(function (storage) {
|
|
307
|
+
return _this.modelMerger.merge(storage, model, modelDefinition);
|
|
308
|
+
})];
|
|
309
|
+
case 1:
|
|
310
|
+
_a.sent();
|
|
311
|
+
return [2 /*return*/];
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}); }, 'subscription dataSubsObservable event');
|
|
315
|
+
}));
|
|
316
|
+
return [3 /*break*/, 10];
|
|
317
|
+
case 9:
|
|
250
318
|
if (!online) {
|
|
251
319
|
this.online = online;
|
|
252
320
|
observer.next({
|
|
@@ -258,8 +326,8 @@ var SyncEngine = /** @class */ (function () {
|
|
|
258
326
|
subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
|
259
327
|
subscriptions = [];
|
|
260
328
|
}
|
|
261
|
-
_b.label =
|
|
262
|
-
case
|
|
329
|
+
_b.label = 10;
|
|
330
|
+
case 10:
|
|
263
331
|
doneStarting();
|
|
264
332
|
return [2 /*return*/];
|
|
265
333
|
}
|
|
@@ -279,19 +347,19 @@ var SyncEngine = /** @class */ (function () {
|
|
|
279
347
|
.subscribe({
|
|
280
348
|
next: function (_a) {
|
|
281
349
|
var opType = _a.opType, model = _a.model, element = _a.element, condition = _a.condition;
|
|
282
|
-
return
|
|
350
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
283
351
|
var _this = this;
|
|
284
|
-
return
|
|
285
|
-
return [2 /*return*/, this.runningProcesses.add(function () { return
|
|
352
|
+
return __generator(this, function (_b) {
|
|
353
|
+
return [2 /*return*/, this.runningProcesses.add(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
286
354
|
var namespace, MutationEventConstructor, modelDefinition, graphQLCondition, mutationEvent;
|
|
287
|
-
return
|
|
355
|
+
return __generator(this, function (_a) {
|
|
288
356
|
switch (_a.label) {
|
|
289
357
|
case 0:
|
|
290
358
|
namespace = this.schema.namespaces[this.namespaceResolver(model)];
|
|
291
359
|
MutationEventConstructor = this.modelClasses['MutationEvent'];
|
|
292
360
|
modelDefinition = this.getModelDefinition(model);
|
|
293
|
-
graphQLCondition =
|
|
294
|
-
mutationEvent =
|
|
361
|
+
graphQLCondition = (0, utils_2.predicateToGraphQLCondition)(condition, modelDefinition);
|
|
362
|
+
mutationEvent = (0, utils_2.createMutationInstanceFromModelOperation)(namespace.relationships, this.getModelDefinition(model), opType, model, element, graphQLCondition, MutationEventConstructor, this.modelInstanceCreator);
|
|
295
363
|
return [4 /*yield*/, this.outbox.enqueue(this.storage, mutationEvent)];
|
|
296
364
|
case 1:
|
|
297
365
|
_a.sent();
|
|
@@ -348,10 +416,10 @@ var SyncEngine = /** @class */ (function () {
|
|
|
348
416
|
});
|
|
349
417
|
};
|
|
350
418
|
SyncEngine.prototype.getModelsMetadataWithNextFullSync = function (currentTimeStamp) {
|
|
351
|
-
return
|
|
419
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
352
420
|
var modelLastSync, _a;
|
|
353
421
|
var _this = this;
|
|
354
|
-
return
|
|
422
|
+
return __generator(this, function (_b) {
|
|
355
423
|
switch (_b.label) {
|
|
356
424
|
case 0:
|
|
357
425
|
_a = Map.bind;
|
|
@@ -381,22 +449,22 @@ var SyncEngine = /** @class */ (function () {
|
|
|
381
449
|
return new zen_observable_ts_1.default(function (observer) {
|
|
382
450
|
var syncQueriesSubscription;
|
|
383
451
|
_this.runningProcesses.isOpen &&
|
|
384
|
-
_this.runningProcesses.add(function (onTerminate) { return
|
|
452
|
+
_this.runningProcesses.add(function (onTerminate) { return __awaiter(_this, void 0, void 0, function () {
|
|
385
453
|
var terminated, _loop_1, this_1;
|
|
386
454
|
var _this = this;
|
|
387
|
-
return
|
|
455
|
+
return __generator(this, function (_a) {
|
|
388
456
|
switch (_a.label) {
|
|
389
457
|
case 0:
|
|
390
458
|
terminated = false;
|
|
391
459
|
_loop_1 = function () {
|
|
392
460
|
var count, modelLastSync, paginatingModels, lastFullSyncStartedAt, syncInterval, start, syncDuration, lastStartedAt, msNextFullSync;
|
|
393
|
-
return
|
|
394
|
-
switch (
|
|
461
|
+
return __generator(this, function (_b) {
|
|
462
|
+
switch (_b.label) {
|
|
395
463
|
case 0:
|
|
396
464
|
count = new WeakMap();
|
|
397
465
|
return [4 /*yield*/, this_1.getModelsMetadataWithNextFullSync(Date.now())];
|
|
398
466
|
case 1:
|
|
399
|
-
modelLastSync =
|
|
467
|
+
modelLastSync = _b.sent();
|
|
400
468
|
paginatingModels = new Set(modelLastSync.keys());
|
|
401
469
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
402
470
|
if (!_this.runningProcesses.isOpen)
|
|
@@ -407,10 +475,10 @@ var SyncEngine = /** @class */ (function () {
|
|
|
407
475
|
.subscribe({
|
|
408
476
|
next: function (_a) {
|
|
409
477
|
var namespace = _a.namespace, modelDefinition = _a.modelDefinition, items = _a.items, done = _a.done, startedAt = _a.startedAt, isFullSync = _a.isFullSync;
|
|
410
|
-
return
|
|
478
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
411
479
|
var modelConstructor, modelName, modelMetadata_1, lastFullSync, fullSyncInterval, counts;
|
|
412
480
|
var _this = this;
|
|
413
|
-
return
|
|
481
|
+
return __generator(this, function (_b) {
|
|
414
482
|
switch (_b.label) {
|
|
415
483
|
case 0:
|
|
416
484
|
modelConstructor = this.userModelClasses[modelDefinition.name];
|
|
@@ -420,7 +488,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
420
488
|
updated: 0,
|
|
421
489
|
deleted: 0,
|
|
422
490
|
});
|
|
423
|
-
start = util_1.getNow();
|
|
491
|
+
start = (0, util_1.getNow)();
|
|
424
492
|
lastStartedAt =
|
|
425
493
|
lastStartedAt === undefined
|
|
426
494
|
? startedAt
|
|
@@ -430,17 +498,17 @@ var SyncEngine = /** @class */ (function () {
|
|
|
430
498
|
* If there are mutations in the outbox for a given id, those need to be
|
|
431
499
|
* merged individually. Otherwise, we can merge them in batches.
|
|
432
500
|
*/
|
|
433
|
-
return [4 /*yield*/, this.storage.runExclusive(function (storage) { return
|
|
434
|
-
var idsInOutbox, oneByOne, page, opTypeCount, oneByOne_1, oneByOne_1_1, item, opType, e_1_1, _a, _b, _c, counts;
|
|
435
|
-
var e_1,
|
|
436
|
-
return
|
|
437
|
-
switch (
|
|
501
|
+
return [4 /*yield*/, this.storage.runExclusive(function (storage) { return __awaiter(_this, void 0, void 0, function () {
|
|
502
|
+
var idsInOutbox, oneByOne, page, opTypeCount, oneByOne_1, oneByOne_1_1, item, opType, e_1_1, _a, _b, _c, _d, counts;
|
|
503
|
+
var e_1, _e;
|
|
504
|
+
return __generator(this, function (_f) {
|
|
505
|
+
switch (_f.label) {
|
|
438
506
|
case 0: return [4 /*yield*/, this.outbox.getModelIds(storage)];
|
|
439
507
|
case 1:
|
|
440
|
-
idsInOutbox =
|
|
508
|
+
idsInOutbox = _f.sent();
|
|
441
509
|
oneByOne = [];
|
|
442
510
|
page = items.filter(function (item) {
|
|
443
|
-
var itemId =
|
|
511
|
+
var itemId = (0, utils_2.getIdentifierValue)(modelDefinition, item);
|
|
444
512
|
if (!idsInOutbox.has(itemId)) {
|
|
445
513
|
return true;
|
|
446
514
|
}
|
|
@@ -448,44 +516,45 @@ var SyncEngine = /** @class */ (function () {
|
|
|
448
516
|
return false;
|
|
449
517
|
});
|
|
450
518
|
opTypeCount = [];
|
|
451
|
-
|
|
519
|
+
_f.label = 2;
|
|
452
520
|
case 2:
|
|
453
|
-
|
|
454
|
-
oneByOne_1 =
|
|
455
|
-
|
|
521
|
+
_f.trys.push([2, 7, 8, 9]);
|
|
522
|
+
oneByOne_1 = __values(oneByOne), oneByOne_1_1 = oneByOne_1.next();
|
|
523
|
+
_f.label = 3;
|
|
456
524
|
case 3:
|
|
457
525
|
if (!!oneByOne_1_1.done) return [3 /*break*/, 6];
|
|
458
526
|
item = oneByOne_1_1.value;
|
|
459
527
|
return [4 /*yield*/, this.modelMerger.merge(storage, item, modelDefinition)];
|
|
460
528
|
case 4:
|
|
461
|
-
opType =
|
|
529
|
+
opType = _f.sent();
|
|
462
530
|
if (opType !== undefined) {
|
|
463
531
|
opTypeCount.push([item, opType]);
|
|
464
532
|
}
|
|
465
|
-
|
|
533
|
+
_f.label = 5;
|
|
466
534
|
case 5:
|
|
467
535
|
oneByOne_1_1 = oneByOne_1.next();
|
|
468
536
|
return [3 /*break*/, 3];
|
|
469
537
|
case 6: return [3 /*break*/, 9];
|
|
470
538
|
case 7:
|
|
471
|
-
e_1_1 =
|
|
539
|
+
e_1_1 = _f.sent();
|
|
472
540
|
e_1 = { error: e_1_1 };
|
|
473
541
|
return [3 /*break*/, 9];
|
|
474
542
|
case 8:
|
|
475
543
|
try {
|
|
476
|
-
if (oneByOne_1_1 && !oneByOne_1_1.done && (
|
|
544
|
+
if (oneByOne_1_1 && !oneByOne_1_1.done && (_e = oneByOne_1.return)) _e.call(oneByOne_1);
|
|
477
545
|
}
|
|
478
546
|
finally { if (e_1) throw e_1.error; }
|
|
479
547
|
return [7 /*endfinally*/];
|
|
480
548
|
case 9:
|
|
481
549
|
_b = (_a = opTypeCount.push).apply;
|
|
482
550
|
_c = [opTypeCount];
|
|
551
|
+
_d = [[]];
|
|
483
552
|
return [4 /*yield*/, this.modelMerger.mergePage(storage, modelConstructor, page, modelDefinition)];
|
|
484
553
|
case 10:
|
|
485
|
-
_b.apply(_a, _c.concat([
|
|
554
|
+
_b.apply(_a, _c.concat([__spreadArray.apply(void 0, _d.concat([__read.apply(void 0, [(_f.sent())]), false]))]));
|
|
486
555
|
counts = count.get(modelConstructor);
|
|
487
556
|
opTypeCount.forEach(function (_a) {
|
|
488
|
-
var _b =
|
|
557
|
+
var _b = __read(_a, 2), opType = _b[1];
|
|
489
558
|
switch (opType) {
|
|
490
559
|
case types_1.OpType.INSERT:
|
|
491
560
|
counts.new++;
|
|
@@ -497,7 +566,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
497
566
|
counts.deleted++;
|
|
498
567
|
break;
|
|
499
568
|
default:
|
|
500
|
-
throw new Error("Invalid opType "
|
|
569
|
+
throw new Error("Invalid opType ".concat(opType));
|
|
501
570
|
}
|
|
502
571
|
});
|
|
503
572
|
return [2 /*return*/];
|
|
@@ -544,7 +613,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
544
613
|
});
|
|
545
614
|
paginatingModels.delete(modelDefinition);
|
|
546
615
|
if (paginatingModels.size === 0) {
|
|
547
|
-
syncDuration = util_1.getNow() - start;
|
|
616
|
+
syncDuration = (0, util_1.getNow)() - start;
|
|
548
617
|
resolve();
|
|
549
618
|
observer.next({
|
|
550
619
|
type: ControlMessage.SYNC_ENGINE_SYNC_QUERIES_READY,
|
|
@@ -572,7 +641,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
572
641
|
});
|
|
573
642
|
})];
|
|
574
643
|
case 2:
|
|
575
|
-
|
|
644
|
+
_b.sent();
|
|
576
645
|
if (!lastFullSyncStartedAt) {
|
|
577
646
|
msNextFullSync = syncInterval - syncDuration;
|
|
578
647
|
}
|
|
@@ -582,7 +651,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
582
651
|
syncInterval -
|
|
583
652
|
(lastStartedAt + syncDuration);
|
|
584
653
|
}
|
|
585
|
-
logger.debug("Next fullSync in "
|
|
654
|
+
logger.debug("Next fullSync in ".concat(msNextFullSync / 1000, " seconds. (").concat(new Date(Date.now() + msNextFullSync), ")"));
|
|
586
655
|
// TODO: create `BackgroundProcessManager.sleep()` ... but, need to put
|
|
587
656
|
// a lot of thought into what that contract looks like to
|
|
588
657
|
// support possible use-cases:
|
|
@@ -596,10 +665,10 @@ var SyncEngine = /** @class */ (function () {
|
|
|
596
665
|
// TLDR; this is a lot of complexity here for a sleep(),
|
|
597
666
|
// but, it's not clear to me yet how to support an
|
|
598
667
|
// extensible, centralized cancelable `sleep()` elegantly.
|
|
599
|
-
return [4 /*yield*/, this_1.runningProcesses.add(function (onTerminate) { return
|
|
668
|
+
return [4 /*yield*/, this_1.runningProcesses.add(function (onTerminate) { return __awaiter(_this, void 0, void 0, function () {
|
|
600
669
|
var sleepTimer, unsleep, sleep;
|
|
601
670
|
var _this = this;
|
|
602
|
-
return
|
|
671
|
+
return __generator(this, function (_a) {
|
|
603
672
|
sleep = new Promise(function (_unsleep) {
|
|
604
673
|
unsleep = _unsleep;
|
|
605
674
|
sleepTimer = setTimeout(unsleep, msNextFullSync);
|
|
@@ -628,7 +697,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
628
697
|
// TLDR; this is a lot of complexity here for a sleep(),
|
|
629
698
|
// but, it's not clear to me yet how to support an
|
|
630
699
|
// extensible, centralized cancelable `sleep()` elegantly.
|
|
631
|
-
|
|
700
|
+
_b.sent();
|
|
632
701
|
this_1.unsleepSyncQueriesObservable = null;
|
|
633
702
|
this_1.waitForSleepState = new Promise(function (resolve) {
|
|
634
703
|
_this.syncQueriesObservableStartSleeping = resolve;
|
|
@@ -655,8 +724,8 @@ var SyncEngine = /** @class */ (function () {
|
|
|
655
724
|
var _this = this;
|
|
656
725
|
return function (msg) {
|
|
657
726
|
// This implementation is tied to AWSAppSyncRealTimeProvider 'Connection closed', 'Timeout disconnect' msg
|
|
658
|
-
if (
|
|
659
|
-
|
|
727
|
+
if (api_graphql_1.CONTROL_MSG.CONNECTION_CLOSED === msg ||
|
|
728
|
+
api_graphql_1.CONTROL_MSG.TIMEOUT_DISCONNECT === msg) {
|
|
660
729
|
_this.datastoreConnectivity.socketDisconnected();
|
|
661
730
|
}
|
|
662
731
|
};
|
|
@@ -669,8 +738,8 @@ var SyncEngine = /** @class */ (function () {
|
|
|
669
738
|
* that they're disconnected, done retrying, etc..
|
|
670
739
|
*/
|
|
671
740
|
SyncEngine.prototype.stop = function () {
|
|
672
|
-
return
|
|
673
|
-
return
|
|
741
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
742
|
+
return __generator(this, function (_a) {
|
|
674
743
|
switch (_a.label) {
|
|
675
744
|
case 0:
|
|
676
745
|
logger.debug('stopping sync engine');
|
|
@@ -720,11 +789,11 @@ var SyncEngine = /** @class */ (function () {
|
|
|
720
789
|
});
|
|
721
790
|
};
|
|
722
791
|
SyncEngine.prototype.setupModels = function (params) {
|
|
723
|
-
return
|
|
792
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
724
793
|
var fullSyncInterval, ModelMetadataConstructor, models, savedModel, promises, result, _a, _b, modelMetadata, modelName, e_2_1;
|
|
725
794
|
var e_2, _c;
|
|
726
795
|
var _this = this;
|
|
727
|
-
return
|
|
796
|
+
return __generator(this, function (_d) {
|
|
728
797
|
switch (_d.label) {
|
|
729
798
|
case 0:
|
|
730
799
|
fullSyncInterval = params.fullSyncInterval;
|
|
@@ -746,11 +815,11 @@ var SyncEngine = /** @class */ (function () {
|
|
|
746
815
|
});
|
|
747
816
|
});
|
|
748
817
|
promises = models.map(function (_a) {
|
|
749
|
-
var _b =
|
|
750
|
-
return
|
|
818
|
+
var _b = __read(_a, 2), namespace = _b[0], model = _b[1];
|
|
819
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
751
820
|
var modelMetadata, syncPredicate, lastSyncPredicate, prevSyncPredicate, syncPredicateUpdated_1;
|
|
752
821
|
var _c, _d, _e, _f;
|
|
753
|
-
return
|
|
822
|
+
return __generator(this, function (_g) {
|
|
754
823
|
switch (_g.label) {
|
|
755
824
|
case 0: return [4 /*yield*/, this.getModelMetadata(namespace, model.name)];
|
|
756
825
|
case 1:
|
|
@@ -769,7 +838,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
769
838
|
lastSyncPredicate: lastSyncPredicate,
|
|
770
839
|
}), undefined, ownSymbol)];
|
|
771
840
|
case 2:
|
|
772
|
-
_c =
|
|
841
|
+
_c = __read.apply(void 0, [_g.sent(), 1]), _d = __read(_c[0], 1), savedModel = _d[0];
|
|
773
842
|
return [3 /*break*/, 5];
|
|
774
843
|
case 3:
|
|
775
844
|
prevSyncPredicate = modelMetadata.lastSyncPredicate
|
|
@@ -787,7 +856,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
787
856
|
}
|
|
788
857
|
}))];
|
|
789
858
|
case 4:
|
|
790
|
-
_e =
|
|
859
|
+
_e = __read.apply(void 0, [_g.sent(), 1]), _f = __read(_e[0], 1), savedModel = _f[0];
|
|
791
860
|
_g.label = 5;
|
|
792
861
|
case 5: return [2 /*return*/, savedModel];
|
|
793
862
|
}
|
|
@@ -800,7 +869,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
800
869
|
_d.trys.push([1, 6, 7, 8]);
|
|
801
870
|
return [4 /*yield*/, Promise.all(promises)];
|
|
802
871
|
case 2:
|
|
803
|
-
_a =
|
|
872
|
+
_a = __values.apply(void 0, [_d.sent()]), _b = _a.next();
|
|
804
873
|
_d.label = 3;
|
|
805
874
|
case 3:
|
|
806
875
|
if (!!_b.done) return [3 /*break*/, 5];
|
|
@@ -828,9 +897,9 @@ var SyncEngine = /** @class */ (function () {
|
|
|
828
897
|
});
|
|
829
898
|
};
|
|
830
899
|
SyncEngine.prototype.getModelsMetadata = function () {
|
|
831
|
-
return
|
|
900
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
832
901
|
var ModelMetadata, modelsMetadata;
|
|
833
|
-
return
|
|
902
|
+
return __generator(this, function (_a) {
|
|
834
903
|
switch (_a.label) {
|
|
835
904
|
case 0:
|
|
836
905
|
ModelMetadata = this.modelClasses
|
|
@@ -844,9 +913,9 @@ var SyncEngine = /** @class */ (function () {
|
|
|
844
913
|
});
|
|
845
914
|
};
|
|
846
915
|
SyncEngine.prototype.getModelMetadata = function (namespace, model) {
|
|
847
|
-
return
|
|
916
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
848
917
|
var ModelMetadata, predicate, _a, modelMetadata;
|
|
849
|
-
return
|
|
918
|
+
return __generator(this, function (_b) {
|
|
850
919
|
switch (_b.label) {
|
|
851
920
|
case 0:
|
|
852
921
|
ModelMetadata = this.modelClasses
|
|
@@ -857,7 +926,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
857
926
|
limit: 1,
|
|
858
927
|
})];
|
|
859
928
|
case 1:
|
|
860
|
-
_a =
|
|
929
|
+
_a = __read.apply(void 0, [_b.sent(), 1]), modelMetadata = _a[0];
|
|
861
930
|
return [2 /*return*/, modelMetadata];
|
|
862
931
|
}
|
|
863
932
|
});
|
|
@@ -989,16 +1058,16 @@ var SyncEngine = /** @class */ (function () {
|
|
|
989
1058
|
var _this = this;
|
|
990
1059
|
return core_1.Hub.listen('api', function (data) {
|
|
991
1060
|
if (data.source === 'PubSub' &&
|
|
992
|
-
data.payload.event ===
|
|
1061
|
+
data.payload.event === api_graphql_1.CONNECTION_STATE_CHANGE) {
|
|
993
1062
|
var connectionState = data.payload.data
|
|
994
1063
|
.connectionState;
|
|
995
1064
|
switch (connectionState) {
|
|
996
1065
|
// Do not need to listen for ConnectionDisruptedPendingNetwork
|
|
997
1066
|
// Normal network reconnection logic will handle the sync
|
|
998
|
-
case
|
|
1067
|
+
case api_graphql_1.ConnectionState.ConnectionDisrupted:
|
|
999
1068
|
_this.connectionDisrupted = true;
|
|
1000
1069
|
break;
|
|
1001
|
-
case
|
|
1070
|
+
case api_graphql_1.ConnectionState.Connected:
|
|
1002
1071
|
if (_this.connectionDisrupted) {
|
|
1003
1072
|
_this.scheduleSync();
|
|
1004
1073
|
}
|
|
@@ -1025,4 +1094,3 @@ var SyncEngine = /** @class */ (function () {
|
|
|
1025
1094
|
return SyncEngine;
|
|
1026
1095
|
}());
|
|
1027
1096
|
exports.SyncEngine = SyncEngine;
|
|
1028
|
-
//# sourceMappingURL=index.js.map
|