@aws-amplify/datastore 4.7.22 → 4.7.26
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/lib/.tsbuildinfo +1 -3
- package/lib/authModeStrategies/defaultAuthStrategy.js +3 -1
- package/lib/authModeStrategies/defaultAuthStrategy.js.map +1 -1
- package/lib/authModeStrategies/index.js +3 -2
- package/lib/authModeStrategies/index.js.map +1 -1
- package/lib/authModeStrategies/multiAuthStrategy.js +33 -33
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.d.ts +4 -4
- package/lib/datastore/datastore.js +143 -131
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/datastore/loadGetRandomValues.d.ts +1 -0
- package/lib/datastore/loadGetRandomValues.js +11 -0
- package/lib/datastore/loadGetRandomValues.js.map +1 -0
- package/lib/datastore/loadGetRandomValues.native.d.ts +1 -0
- package/lib/datastore/loadGetRandomValues.native.js +26 -0
- package/lib/datastore/loadGetRandomValues.native.js.map +1 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.js +11 -9
- package/lib/index.js.map +1 -1
- package/lib/predicates/index.js +8 -7
- package/lib/predicates/index.js.map +1 -1
- package/lib/predicates/next.d.ts +3 -3
- package/lib/predicates/next.js +53 -47
- package/lib/predicates/next.js.map +1 -1
- package/lib/predicates/sort.js +2 -1
- package/lib/predicates/sort.js.map +1 -1
- package/lib/ssr/index.js +2 -2
- package/lib/ssr/index.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +110 -83
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js +7 -7
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.js +2 -1
- package/lib/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.native.js +1 -1
- package/lib/storage/adapter/InMemoryStore.native.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +152 -126
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/adapter/StorageAdapterBase.js +62 -53
- package/lib/storage/adapter/StorageAdapterBase.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js +2 -2
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib/storage/relationship.d.ts +4 -4
- package/lib/storage/relationship.js +19 -18
- package/lib/storage/relationship.js.map +1 -1
- package/lib/storage/storage.d.ts +3 -3
- package/lib/storage/storage.js +22 -24
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.d.ts +1 -1
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/datastoreReachability/index.js +1 -0
- package/lib/sync/datastoreReachability/index.js.map +1 -1
- package/lib/sync/datastoreReachability/index.native.js +1 -0
- package/lib/sync/datastoreReachability/index.native.js.map +1 -1
- package/lib/sync/index.d.ts +1 -1
- package/lib/sync/index.js +402 -408
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.js +3 -2
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.js +5 -6
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +8 -7
- package/lib/sync/processors/errorMaps.js.map +1 -1
- package/lib/sync/processors/mutation.d.ts +1 -1
- package/lib/sync/processors/mutation.js +52 -50
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.d.ts +4 -1
- package/lib/sync/processors/subscription.js +36 -32
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.d.ts +1 -1
- package/lib/sync/processors/sync.js +28 -27
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.js +96 -95
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.d.ts +139 -133
- package/lib/types.js +30 -29
- package/lib/types.js.map +1 -1
- package/lib/util.d.ts +12 -20
- package/lib/util.js +115 -80
- package/lib/util.js.map +1 -1
- package/lib-esm/.tsbuildinfo +1 -3
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +31 -33
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +4 -4
- package/lib-esm/datastore/datastore.js +67 -57
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/datastore/loadGetRandomValues.d.ts +1 -0
- package/lib-esm/datastore/loadGetRandomValues.js +7 -0
- package/lib-esm/datastore/loadGetRandomValues.js.map +1 -0
- package/lib-esm/datastore/loadGetRandomValues.native.d.ts +1 -0
- package/lib-esm/datastore/loadGetRandomValues.native.js +22 -0
- package/lib-esm/datastore/loadGetRandomValues.native.js.map +1 -0
- package/lib-esm/index.d.ts +3 -3
- package/lib-esm/index.js +1 -0
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/predicates/index.js +4 -4
- package/lib-esm/predicates/index.js.map +1 -1
- package/lib-esm/predicates/next.d.ts +3 -3
- package/lib-esm/predicates/next.js +45 -41
- package/lib-esm/predicates/next.js.map +1 -1
- package/lib-esm/predicates/sort.js +1 -1
- package/lib-esm/predicates/sort.js.map +1 -1
- package/lib-esm/ssr/index.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +103 -77
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +4 -4
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +142 -116
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/StorageAdapterBase.js +47 -39
- package/lib-esm/storage/adapter/StorageAdapterBase.js.map +1 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib-esm/storage/adapter/index.js +1 -0
- package/lib-esm/storage/relationship.d.ts +4 -4
- package/lib-esm/storage/relationship.js +17 -17
- package/lib-esm/storage/relationship.js.map +1 -1
- package/lib-esm/storage/storage.d.ts +3 -3
- package/lib-esm/storage/storage.js +10 -13
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
- package/lib-esm/sync/index.d.ts +1 -1
- package/lib-esm/sync/index.js +400 -407
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.js +2 -2
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.js +1 -3
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +4 -4
- package/lib-esm/sync/processors/errorMaps.js.map +1 -1
- package/lib-esm/sync/processors/mutation.d.ts +1 -1
- package/lib-esm/sync/processors/mutation.js +35 -35
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.d.ts +4 -1
- package/lib-esm/sync/processors/subscription.js +24 -21
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.d.ts +1 -1
- package/lib-esm/sync/processors/sync.js +17 -17
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.js +62 -62
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +139 -133
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +12 -20
- package/lib-esm/util.js +9 -9
- package/lib-esm/util.js.map +1 -1
- package/package.json +41 -30
- package/src/datastore/datastore.ts +6 -0
- package/src/datastore/loadGetRandomValues.native.ts +24 -0
- package/src/datastore/loadGetRandomValues.ts +7 -0
- package/src/index.ts +2 -0
- package/src/predicates/next.ts +1 -1
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/StorageAdapterBase.ts +2 -2
- package/src/storage/relationship.ts +9 -4
- package/src/sync/processors/subscription.ts +1 -1
- package/src/sync/processors/sync.ts +1 -1
- package/src/types.ts +2 -2
- package/src/util.ts +1 -1
package/lib/sync/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SyncEngine = exports.ControlMessage = void 0;
|
|
3
4
|
var tslib_1 = require("tslib");
|
|
4
5
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -16,7 +17,7 @@ var mutation_1 = require("./processors/mutation");
|
|
|
16
17
|
var subscription_1 = require("./processors/subscription");
|
|
17
18
|
var sync_1 = require("./processors/sync");
|
|
18
19
|
var utils_1 = require("./utils");
|
|
19
|
-
var isNode = core_1.browserOrNode().isNode;
|
|
20
|
+
var isNode = (0, core_1.browserOrNode)().isNode;
|
|
20
21
|
var logger = new core_1.ConsoleLogger('DataStore');
|
|
21
22
|
var ownSymbol = Symbol('sync');
|
|
22
23
|
var ControlMessage;
|
|
@@ -31,11 +32,11 @@ var ControlMessage;
|
|
|
31
32
|
ControlMessage["SYNC_ENGINE_OUTBOX_STATUS"] = "outboxStatus";
|
|
32
33
|
ControlMessage["SYNC_ENGINE_NETWORK_STATUS"] = "networkStatus";
|
|
33
34
|
ControlMessage["SYNC_ENGINE_READY"] = "ready";
|
|
34
|
-
})(ControlMessage
|
|
35
|
+
})(ControlMessage || (exports.ControlMessage = ControlMessage = {}));
|
|
35
36
|
var SyncEngine = /** @class */ (function () {
|
|
36
37
|
function SyncEngine(schema, namespaceResolver, modelClasses, userModelClasses, storage, modelInstanceCreator, conflictHandler, errorHandler, syncPredicates, amplifyConfig, authModeStrategy, amplifyContext, connectivityMonitor) {
|
|
37
|
-
var _this = this;
|
|
38
38
|
if (amplifyConfig === void 0) { amplifyConfig = {}; }
|
|
39
|
+
var _this = this;
|
|
39
40
|
this.schema = schema;
|
|
40
41
|
this.namespaceResolver = namespaceResolver;
|
|
41
42
|
this.modelClasses = modelClasses;
|
|
@@ -88,107 +89,143 @@ var SyncEngine = /** @class */ (function () {
|
|
|
88
89
|
return [2 /*return*/];
|
|
89
90
|
case 3:
|
|
90
91
|
startPromise = new Promise(function (doneStarting, failedStarting) {
|
|
91
|
-
_this.datastoreConnectivity.status().subscribe(function (_a) {
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
this.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (msg === subscription_1.CONTROL_MSG.CONNECTED) {
|
|
129
|
-
resolve();
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
error: function (err) {
|
|
133
|
-
reject(err);
|
|
134
|
-
var handleDisconnect = _this.disconnectionHandler();
|
|
135
|
-
handleDisconnect(err);
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
subscriptions.push(ctlSubsSubscription);
|
|
139
|
-
})];
|
|
140
|
-
case 3:
|
|
141
|
-
_b.sent();
|
|
142
|
-
return [3 /*break*/, 5];
|
|
143
|
-
case 4:
|
|
144
|
-
err_2 = _b.sent();
|
|
145
|
-
observer.error(err_2);
|
|
146
|
-
failedStarting();
|
|
147
|
-
return [2 /*return*/];
|
|
148
|
-
case 5:
|
|
149
|
-
logger.log('Realtime ready');
|
|
150
|
-
observer.next({
|
|
151
|
-
type: ControlMessage.SYNC_ENGINE_SUBSCRIPTIONS_ESTABLISHED,
|
|
152
|
-
});
|
|
153
|
-
_b.label = 6;
|
|
154
|
-
case 6:
|
|
155
|
-
_b.trys.push([6, 8, , 9]);
|
|
156
|
-
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
157
|
-
var syncQuerySubscription = _this.syncQueriesObservable().subscribe({
|
|
158
|
-
next: function (message) {
|
|
159
|
-
var type = message.type;
|
|
160
|
-
if (type ===
|
|
161
|
-
ControlMessage.SYNC_ENGINE_SYNC_QUERIES_READY) {
|
|
162
|
-
resolve();
|
|
163
|
-
}
|
|
164
|
-
observer.next(message);
|
|
165
|
-
},
|
|
166
|
-
complete: function () {
|
|
92
|
+
_this.datastoreConnectivity.status().subscribe(function (_a) { return tslib_1.__awaiter(_this, [_a], void 0, function (_b) {
|
|
93
|
+
var _this = this;
|
|
94
|
+
var online = _b.online;
|
|
95
|
+
return tslib_1.__generator(this, function (_c) {
|
|
96
|
+
return [2 /*return*/, this.runningProcesses.isOpen &&
|
|
97
|
+
this.runningProcesses.add(function (onTerminate) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
98
|
+
var ctlSubsObservable_1, dataSubsObservable, err_2, error_1;
|
|
99
|
+
var _a;
|
|
100
|
+
var _this = this;
|
|
101
|
+
return tslib_1.__generator(this, function (_b) {
|
|
102
|
+
switch (_b.label) {
|
|
103
|
+
case 0:
|
|
104
|
+
if (!(online && !this.online)) return [3 /*break*/, 10];
|
|
105
|
+
this.online = online;
|
|
106
|
+
observer.next({
|
|
107
|
+
type: ControlMessage.SYNC_ENGINE_NETWORK_STATUS,
|
|
108
|
+
data: {
|
|
109
|
+
active: this.online,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
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
|
+
this.stopDisruptionListener =
|
|
118
|
+
this.startDisruptionListener();
|
|
119
|
+
//#region GraphQL Subscriptions
|
|
120
|
+
_a = tslib_1.__read(this.subscriptionsProcessor.start(), 2), ctlSubsObservable_1 = _a[0], dataSubsObservable = _a[1];
|
|
121
|
+
_b.label = 2;
|
|
122
|
+
case 2:
|
|
123
|
+
_b.trys.push([2, 4, , 5]);
|
|
124
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
125
|
+
onTerminate.then(reject);
|
|
126
|
+
var ctlSubsSubscription = ctlSubsObservable_1.subscribe({
|
|
127
|
+
next: function (msg) {
|
|
128
|
+
if (msg === subscription_1.CONTROL_MSG.CONNECTED) {
|
|
167
129
|
resolve();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
error: function (err) {
|
|
133
|
+
reject(err);
|
|
134
|
+
var handleDisconnect = _this.disconnectionHandler();
|
|
135
|
+
handleDisconnect(err);
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
subscriptions.push(ctlSubsSubscription);
|
|
139
|
+
})];
|
|
140
|
+
case 3:
|
|
141
|
+
_b.sent();
|
|
142
|
+
return [3 /*break*/, 5];
|
|
143
|
+
case 4:
|
|
144
|
+
err_2 = _b.sent();
|
|
145
|
+
observer.error(err_2);
|
|
146
|
+
failedStarting();
|
|
147
|
+
return [2 /*return*/];
|
|
148
|
+
case 5:
|
|
149
|
+
logger.log('Realtime ready');
|
|
150
|
+
observer.next({
|
|
151
|
+
type: ControlMessage.SYNC_ENGINE_SUBSCRIPTIONS_ESTABLISHED,
|
|
152
|
+
});
|
|
153
|
+
_b.label = 6;
|
|
154
|
+
case 6:
|
|
155
|
+
_b.trys.push([6, 8, , 9]);
|
|
156
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
157
|
+
var syncQuerySubscription = _this.syncQueriesObservable().subscribe({
|
|
158
|
+
next: function (message) {
|
|
159
|
+
var type = message.type;
|
|
160
|
+
if (type ===
|
|
161
|
+
ControlMessage.SYNC_ENGINE_SYNC_QUERIES_READY) {
|
|
162
|
+
resolve();
|
|
163
|
+
}
|
|
164
|
+
observer.next(message);
|
|
165
|
+
},
|
|
166
|
+
complete: function () {
|
|
167
|
+
resolve();
|
|
168
|
+
},
|
|
169
|
+
error: function (error) {
|
|
170
|
+
reject(error);
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
if (syncQuerySubscription) {
|
|
174
|
+
subscriptions.push(syncQuerySubscription);
|
|
175
|
+
}
|
|
176
|
+
})];
|
|
177
|
+
case 7:
|
|
178
|
+
_b.sent();
|
|
179
|
+
return [3 /*break*/, 9];
|
|
180
|
+
case 8:
|
|
181
|
+
error_1 = _b.sent();
|
|
182
|
+
observer.error(error_1);
|
|
183
|
+
failedStarting();
|
|
184
|
+
return [2 /*return*/];
|
|
185
|
+
case 9:
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region process mutations (outbox)
|
|
188
|
+
subscriptions.push(this.mutationsProcessor
|
|
189
|
+
.start()
|
|
190
|
+
.subscribe(function (_a) {
|
|
191
|
+
var modelDefinition = _a.modelDefinition, item = _a.model, hasMore = _a.hasMore;
|
|
192
|
+
return _this.runningProcesses.add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
193
|
+
var modelConstructor, model;
|
|
194
|
+
var _this = this;
|
|
195
|
+
return tslib_1.__generator(this, function (_a) {
|
|
196
|
+
switch (_a.label) {
|
|
197
|
+
case 0:
|
|
198
|
+
modelConstructor = this.userModelClasses[modelDefinition.name];
|
|
199
|
+
model = this.modelInstanceCreator(modelConstructor, item);
|
|
200
|
+
return [4 /*yield*/, this.storage.runExclusive(function (storage) {
|
|
201
|
+
return _this.modelMerger.merge(storage, model, modelDefinition);
|
|
202
|
+
})];
|
|
203
|
+
case 1:
|
|
204
|
+
_a.sent();
|
|
205
|
+
observer.next({
|
|
206
|
+
type: ControlMessage.SYNC_ENGINE_OUTBOX_MUTATION_PROCESSED,
|
|
207
|
+
data: {
|
|
208
|
+
model: modelConstructor,
|
|
209
|
+
element: model,
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
observer.next({
|
|
213
|
+
type: ControlMessage.SYNC_ENGINE_OUTBOX_STATUS,
|
|
214
|
+
data: {
|
|
215
|
+
isEmpty: !hasMore,
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
return [2 /*return*/];
|
|
175
219
|
}
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
case 9:
|
|
186
|
-
//#endregion
|
|
187
|
-
//#region process mutations (outbox)
|
|
188
|
-
subscriptions.push(this.mutationsProcessor
|
|
189
|
-
.start()
|
|
190
|
-
.subscribe(function (_a) {
|
|
191
|
-
var modelDefinition = _a.modelDefinition, item = _a.model, hasMore = _a.hasMore;
|
|
220
|
+
});
|
|
221
|
+
}); }, 'mutation processor event');
|
|
222
|
+
}));
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region Merge subscriptions buffer
|
|
225
|
+
// TODO: extract to function
|
|
226
|
+
if (!isNode) {
|
|
227
|
+
subscriptions.push(dataSubsObservable.subscribe(function (_a) {
|
|
228
|
+
var _b = tslib_1.__read(_a, 3), _transformerMutationType = _b[0], modelDefinition = _b[1], item = _b[2];
|
|
192
229
|
return _this.runningProcesses.add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
193
230
|
var modelConstructor, model;
|
|
194
231
|
var _this = this;
|
|
@@ -202,72 +239,34 @@ var SyncEngine = /** @class */ (function () {
|
|
|
202
239
|
})];
|
|
203
240
|
case 1:
|
|
204
241
|
_a.sent();
|
|
205
|
-
observer.next({
|
|
206
|
-
type: ControlMessage.SYNC_ENGINE_OUTBOX_MUTATION_PROCESSED,
|
|
207
|
-
data: {
|
|
208
|
-
model: modelConstructor,
|
|
209
|
-
element: model,
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
observer.next({
|
|
213
|
-
type: ControlMessage.SYNC_ENGINE_OUTBOX_STATUS,
|
|
214
|
-
data: {
|
|
215
|
-
isEmpty: !hasMore,
|
|
216
|
-
},
|
|
217
|
-
});
|
|
218
242
|
return [2 /*return*/];
|
|
219
243
|
}
|
|
220
244
|
});
|
|
221
|
-
}); }, '
|
|
245
|
+
}); }, 'subscription dataSubsObservable event');
|
|
222
246
|
}));
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
});
|
|
245
|
-
}); }, 'subscription dataSubsObservable event');
|
|
246
|
-
}));
|
|
247
|
-
}
|
|
248
|
-
return [3 /*break*/, 11];
|
|
249
|
-
case 10:
|
|
250
|
-
if (!online) {
|
|
251
|
-
this.online = online;
|
|
252
|
-
observer.next({
|
|
253
|
-
type: ControlMessage.SYNC_ENGINE_NETWORK_STATUS,
|
|
254
|
-
data: {
|
|
255
|
-
active: this.online,
|
|
256
|
-
},
|
|
257
|
-
});
|
|
258
|
-
subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
|
259
|
-
subscriptions = [];
|
|
260
|
-
}
|
|
261
|
-
_b.label = 11;
|
|
262
|
-
case 11:
|
|
263
|
-
doneStarting();
|
|
264
|
-
return [2 /*return*/];
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
}); }, 'datastore connectivity event')];
|
|
268
|
-
});
|
|
247
|
+
}
|
|
248
|
+
return [3 /*break*/, 11];
|
|
249
|
+
case 10:
|
|
250
|
+
if (!online) {
|
|
251
|
+
this.online = online;
|
|
252
|
+
observer.next({
|
|
253
|
+
type: ControlMessage.SYNC_ENGINE_NETWORK_STATUS,
|
|
254
|
+
data: {
|
|
255
|
+
active: this.online,
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
|
259
|
+
subscriptions = [];
|
|
260
|
+
}
|
|
261
|
+
_b.label = 11;
|
|
262
|
+
case 11:
|
|
263
|
+
doneStarting();
|
|
264
|
+
return [2 /*return*/];
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}); }, 'datastore connectivity event')];
|
|
269
268
|
});
|
|
270
|
-
});
|
|
269
|
+
}); });
|
|
271
270
|
});
|
|
272
271
|
this.storage
|
|
273
272
|
.observe(null, null, ownSymbol)
|
|
@@ -277,51 +276,49 @@ var SyncEngine = /** @class */ (function () {
|
|
|
277
276
|
return modelDefinition.syncable === true;
|
|
278
277
|
})
|
|
279
278
|
.subscribe({
|
|
280
|
-
next: function (_a) {
|
|
281
|
-
var
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
return tslib_1.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}); }, 'storage event')];
|
|
322
|
-
});
|
|
279
|
+
next: function (_a) { return tslib_1.__awaiter(_this, [_a], void 0, function (_b) {
|
|
280
|
+
var _this = this;
|
|
281
|
+
var opType = _b.opType, model = _b.model, element = _b.element, condition = _b.condition;
|
|
282
|
+
return tslib_1.__generator(this, function (_c) {
|
|
283
|
+
return [2 /*return*/, this.runningProcesses.add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
284
|
+
var namespace, MutationEventConstructor, modelDefinition, graphQLCondition, mutationEvent;
|
|
285
|
+
return tslib_1.__generator(this, function (_a) {
|
|
286
|
+
switch (_a.label) {
|
|
287
|
+
case 0:
|
|
288
|
+
namespace = this.schema.namespaces[this.namespaceResolver(model)];
|
|
289
|
+
MutationEventConstructor = this.modelClasses['MutationEvent'];
|
|
290
|
+
modelDefinition = this.getModelDefinition(model);
|
|
291
|
+
graphQLCondition = (0, utils_1.predicateToGraphQLCondition)(condition, modelDefinition);
|
|
292
|
+
mutationEvent = (0, utils_1.createMutationInstanceFromModelOperation)(namespace.relationships, this.getModelDefinition(model), opType, model, element, graphQLCondition, MutationEventConstructor, this.modelInstanceCreator);
|
|
293
|
+
return [4 /*yield*/, this.outbox.enqueue(this.storage, mutationEvent)];
|
|
294
|
+
case 1:
|
|
295
|
+
_a.sent();
|
|
296
|
+
observer.next({
|
|
297
|
+
type: ControlMessage.SYNC_ENGINE_OUTBOX_MUTATION_ENQUEUED,
|
|
298
|
+
data: {
|
|
299
|
+
model: model,
|
|
300
|
+
element: element,
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
observer.next({
|
|
304
|
+
type: ControlMessage.SYNC_ENGINE_OUTBOX_STATUS,
|
|
305
|
+
data: {
|
|
306
|
+
isEmpty: false,
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
return [4 /*yield*/, startPromise];
|
|
310
|
+
case 2:
|
|
311
|
+
_a.sent();
|
|
312
|
+
// Set by the this.datastoreConnectivity.status().subscribe() loop
|
|
313
|
+
if (this.online) {
|
|
314
|
+
this.mutationsProcessor.resume();
|
|
315
|
+
}
|
|
316
|
+
return [2 /*return*/];
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}); }, 'storage event')];
|
|
323
320
|
});
|
|
324
|
-
},
|
|
321
|
+
}); },
|
|
325
322
|
});
|
|
326
323
|
observer.next({
|
|
327
324
|
type: ControlMessage.SYNC_ENGINE_STORAGE_SUBSCRIBED,
|
|
@@ -390,13 +387,13 @@ var SyncEngine = /** @class */ (function () {
|
|
|
390
387
|
terminated = false;
|
|
391
388
|
_loop_1 = function () {
|
|
392
389
|
var count, modelLastSync, paginatingModels, lastFullSyncStartedAt, syncInterval, start, syncDuration, lastStartedAt, msNextFullSync;
|
|
393
|
-
return tslib_1.__generator(this, function (
|
|
394
|
-
switch (
|
|
390
|
+
return tslib_1.__generator(this, function (_b) {
|
|
391
|
+
switch (_b.label) {
|
|
395
392
|
case 0:
|
|
396
393
|
count = new WeakMap();
|
|
397
394
|
return [4 /*yield*/, this_1.getModelsMetadataWithNextFullSync(Date.now())];
|
|
398
395
|
case 1:
|
|
399
|
-
modelLastSync =
|
|
396
|
+
modelLastSync = _b.sent();
|
|
400
397
|
paginatingModels = new Set(modelLastSync.keys());
|
|
401
398
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
402
399
|
if (!_this.runningProcesses.isOpen)
|
|
@@ -405,158 +402,157 @@ var SyncEngine = /** @class */ (function () {
|
|
|
405
402
|
syncQueriesSubscription = _this.syncQueriesProcessor
|
|
406
403
|
.start(modelLastSync)
|
|
407
404
|
.subscribe({
|
|
408
|
-
next: function (_a) {
|
|
409
|
-
var
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
lastStartedAt
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
return true;
|
|
446
|
-
}
|
|
447
|
-
oneByOne.push(item);
|
|
448
|
-
return false;
|
|
449
|
-
});
|
|
450
|
-
opTypeCount = [];
|
|
451
|
-
_e.label = 2;
|
|
452
|
-
case 2:
|
|
453
|
-
_e.trys.push([2, 7, 8, 9]);
|
|
454
|
-
oneByOne_1 = tslib_1.__values(oneByOne), oneByOne_1_1 = oneByOne_1.next();
|
|
455
|
-
_e.label = 3;
|
|
456
|
-
case 3:
|
|
457
|
-
if (!!oneByOne_1_1.done) return [3 /*break*/, 6];
|
|
458
|
-
item = oneByOne_1_1.value;
|
|
459
|
-
return [4 /*yield*/, this.modelMerger.merge(storage, item, modelDefinition)];
|
|
460
|
-
case 4:
|
|
461
|
-
opType = _e.sent();
|
|
462
|
-
if (opType !== undefined) {
|
|
463
|
-
opTypeCount.push([item, opType]);
|
|
405
|
+
next: function (_a) { return tslib_1.__awaiter(_this, [_a], void 0, function (_b) {
|
|
406
|
+
var modelConstructor, modelName, modelMetadata_1, lastFullSync, fullSyncInterval, counts;
|
|
407
|
+
var _this = this;
|
|
408
|
+
var namespace = _b.namespace, modelDefinition = _b.modelDefinition, items = _b.items, done = _b.done, startedAt = _b.startedAt, isFullSync = _b.isFullSync;
|
|
409
|
+
return tslib_1.__generator(this, function (_c) {
|
|
410
|
+
switch (_c.label) {
|
|
411
|
+
case 0:
|
|
412
|
+
modelConstructor = this.userModelClasses[modelDefinition.name];
|
|
413
|
+
if (!count.has(modelConstructor)) {
|
|
414
|
+
count.set(modelConstructor, {
|
|
415
|
+
new: 0,
|
|
416
|
+
updated: 0,
|
|
417
|
+
deleted: 0,
|
|
418
|
+
});
|
|
419
|
+
start = (0, util_1.getNow)();
|
|
420
|
+
lastStartedAt =
|
|
421
|
+
lastStartedAt === undefined
|
|
422
|
+
? startedAt
|
|
423
|
+
: Math.max(lastStartedAt, startedAt);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* If there are mutations in the outbox for a given id, those need to be
|
|
427
|
+
* merged individually. Otherwise, we can merge them in batches.
|
|
428
|
+
*/
|
|
429
|
+
return [4 /*yield*/, this.storage.runExclusive(function (storage) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
430
|
+
var idsInOutbox, oneByOne, page, opTypeCount, oneByOne_1, oneByOne_1_1, item, opType, e_1_1, _a, _b, _c, _d, counts;
|
|
431
|
+
var e_1, _e;
|
|
432
|
+
return tslib_1.__generator(this, function (_f) {
|
|
433
|
+
switch (_f.label) {
|
|
434
|
+
case 0: return [4 /*yield*/, this.outbox.getModelIds(storage)];
|
|
435
|
+
case 1:
|
|
436
|
+
idsInOutbox = _f.sent();
|
|
437
|
+
oneByOne = [];
|
|
438
|
+
page = items.filter(function (item) {
|
|
439
|
+
var itemId = (0, utils_1.getIdentifierValue)(modelDefinition, item);
|
|
440
|
+
if (!idsInOutbox.has(itemId)) {
|
|
441
|
+
return true;
|
|
464
442
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
443
|
+
oneByOne.push(item);
|
|
444
|
+
return false;
|
|
445
|
+
});
|
|
446
|
+
opTypeCount = [];
|
|
447
|
+
_f.label = 2;
|
|
448
|
+
case 2:
|
|
449
|
+
_f.trys.push([2, 7, 8, 9]);
|
|
450
|
+
oneByOne_1 = tslib_1.__values(oneByOne), oneByOne_1_1 = oneByOne_1.next();
|
|
451
|
+
_f.label = 3;
|
|
452
|
+
case 3:
|
|
453
|
+
if (!!oneByOne_1_1.done) return [3 /*break*/, 6];
|
|
454
|
+
item = oneByOne_1_1.value;
|
|
455
|
+
return [4 /*yield*/, this.modelMerger.merge(storage, item, modelDefinition)];
|
|
456
|
+
case 4:
|
|
457
|
+
opType = _f.sent();
|
|
458
|
+
if (opType !== undefined) {
|
|
459
|
+
opTypeCount.push([item, opType]);
|
|
460
|
+
}
|
|
461
|
+
_f.label = 5;
|
|
462
|
+
case 5:
|
|
463
|
+
oneByOne_1_1 = oneByOne_1.next();
|
|
464
|
+
return [3 /*break*/, 3];
|
|
465
|
+
case 6: return [3 /*break*/, 9];
|
|
466
|
+
case 7:
|
|
467
|
+
e_1_1 = _f.sent();
|
|
468
|
+
e_1 = { error: e_1_1 };
|
|
469
|
+
return [3 /*break*/, 9];
|
|
470
|
+
case 8:
|
|
471
|
+
try {
|
|
472
|
+
if (oneByOne_1_1 && !oneByOne_1_1.done && (_e = oneByOne_1.return)) _e.call(oneByOne_1);
|
|
473
|
+
}
|
|
474
|
+
finally { if (e_1) throw e_1.error; }
|
|
475
|
+
return [7 /*endfinally*/];
|
|
476
|
+
case 9:
|
|
477
|
+
_b = (_a = opTypeCount.push).apply;
|
|
478
|
+
_c = [opTypeCount];
|
|
479
|
+
_d = [[]];
|
|
480
|
+
return [4 /*yield*/, this.modelMerger.mergePage(storage, modelConstructor, page, modelDefinition)];
|
|
481
|
+
case 10:
|
|
482
|
+
_b.apply(_a, _c.concat([tslib_1.__spreadArray.apply(void 0, _d.concat([tslib_1.__read.apply(void 0, [(_f.sent())]), false]))]));
|
|
483
|
+
counts = count.get(modelConstructor);
|
|
484
|
+
opTypeCount.forEach(function (_a) {
|
|
485
|
+
var _b = tslib_1.__read(_a, 2), opType = _b[1];
|
|
486
|
+
switch (opType) {
|
|
487
|
+
case types_1.OpType.INSERT:
|
|
488
|
+
counts.new++;
|
|
489
|
+
break;
|
|
490
|
+
case types_1.OpType.UPDATE:
|
|
491
|
+
counts.updated++;
|
|
492
|
+
break;
|
|
493
|
+
case types_1.OpType.DELETE:
|
|
494
|
+
counts.deleted++;
|
|
495
|
+
break;
|
|
496
|
+
default:
|
|
497
|
+
throw new Error("Invalid opType ".concat(opType));
|
|
477
498
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
.ModelMetadata.copyOf(modelMetadata_1, function (draft) {
|
|
526
|
-
draft.lastSync = startedAt;
|
|
527
|
-
draft.lastFullSync = isFullSync
|
|
528
|
-
? startedAt
|
|
529
|
-
: modelMetadata_1.lastFullSync;
|
|
530
|
-
});
|
|
531
|
-
return [4 /*yield*/, this.storage.save(modelMetadata_1, undefined, ownSymbol)];
|
|
532
|
-
case 3:
|
|
533
|
-
_b.sent();
|
|
534
|
-
counts = count.get(modelConstructor);
|
|
535
|
-
this.modelSyncedStatus.set(modelConstructor, true);
|
|
499
|
+
});
|
|
500
|
+
return [2 /*return*/];
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
}); })];
|
|
504
|
+
case 1:
|
|
505
|
+
/**
|
|
506
|
+
* If there are mutations in the outbox for a given id, those need to be
|
|
507
|
+
* merged individually. Otherwise, we can merge them in batches.
|
|
508
|
+
*/
|
|
509
|
+
_c.sent();
|
|
510
|
+
if (!done) return [3 /*break*/, 4];
|
|
511
|
+
modelName = modelDefinition.name;
|
|
512
|
+
return [4 /*yield*/, this.getModelMetadata(namespace, modelName)];
|
|
513
|
+
case 2:
|
|
514
|
+
modelMetadata_1 = _c.sent();
|
|
515
|
+
lastFullSync = modelMetadata_1.lastFullSync, fullSyncInterval = modelMetadata_1.fullSyncInterval;
|
|
516
|
+
syncInterval = fullSyncInterval;
|
|
517
|
+
lastFullSyncStartedAt =
|
|
518
|
+
lastFullSyncStartedAt === undefined
|
|
519
|
+
? lastFullSync
|
|
520
|
+
: Math.max(lastFullSyncStartedAt, isFullSync ? startedAt : lastFullSync);
|
|
521
|
+
modelMetadata_1 = this.modelClasses
|
|
522
|
+
.ModelMetadata.copyOf(modelMetadata_1, function (draft) {
|
|
523
|
+
draft.lastSync = startedAt;
|
|
524
|
+
draft.lastFullSync = isFullSync
|
|
525
|
+
? startedAt
|
|
526
|
+
: modelMetadata_1.lastFullSync;
|
|
527
|
+
});
|
|
528
|
+
return [4 /*yield*/, this.storage.save(modelMetadata_1, undefined, ownSymbol)];
|
|
529
|
+
case 3:
|
|
530
|
+
_c.sent();
|
|
531
|
+
counts = count.get(modelConstructor);
|
|
532
|
+
this.modelSyncedStatus.set(modelConstructor, true);
|
|
533
|
+
observer.next({
|
|
534
|
+
type: ControlMessage.SYNC_ENGINE_MODEL_SYNCED,
|
|
535
|
+
data: {
|
|
536
|
+
model: modelConstructor,
|
|
537
|
+
isFullSync: isFullSync,
|
|
538
|
+
isDeltaSync: !isFullSync,
|
|
539
|
+
counts: counts,
|
|
540
|
+
},
|
|
541
|
+
});
|
|
542
|
+
paginatingModels.delete(modelDefinition);
|
|
543
|
+
if (paginatingModels.size === 0) {
|
|
544
|
+
syncDuration = (0, util_1.getNow)() - start;
|
|
545
|
+
resolve();
|
|
536
546
|
observer.next({
|
|
537
|
-
type: ControlMessage.
|
|
538
|
-
data: {
|
|
539
|
-
model: modelConstructor,
|
|
540
|
-
isFullSync: isFullSync,
|
|
541
|
-
isDeltaSync: !isFullSync,
|
|
542
|
-
counts: counts,
|
|
543
|
-
},
|
|
547
|
+
type: ControlMessage.SYNC_ENGINE_SYNC_QUERIES_READY,
|
|
544
548
|
});
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
type: ControlMessage.SYNC_ENGINE_SYNC_QUERIES_READY,
|
|
551
|
-
});
|
|
552
|
-
syncQueriesSubscription.unsubscribe();
|
|
553
|
-
}
|
|
554
|
-
_b.label = 4;
|
|
555
|
-
case 4: return [2 /*return*/];
|
|
556
|
-
}
|
|
557
|
-
});
|
|
549
|
+
syncQueriesSubscription.unsubscribe();
|
|
550
|
+
}
|
|
551
|
+
_c.label = 4;
|
|
552
|
+
case 4: return [2 /*return*/];
|
|
553
|
+
}
|
|
558
554
|
});
|
|
559
|
-
},
|
|
555
|
+
}); },
|
|
560
556
|
error: function (error) {
|
|
561
557
|
observer.error(error);
|
|
562
558
|
},
|
|
@@ -572,7 +568,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
572
568
|
});
|
|
573
569
|
})];
|
|
574
570
|
case 2:
|
|
575
|
-
|
|
571
|
+
_b.sent();
|
|
576
572
|
if (!lastFullSyncStartedAt) {
|
|
577
573
|
msNextFullSync = syncInterval - syncDuration;
|
|
578
574
|
}
|
|
@@ -582,7 +578,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
582
578
|
syncInterval -
|
|
583
579
|
(lastStartedAt + syncDuration);
|
|
584
580
|
}
|
|
585
|
-
logger.debug("Next fullSync in "
|
|
581
|
+
logger.debug("Next fullSync in ".concat(msNextFullSync / 1000, " seconds. (").concat(new Date(Date.now() + msNextFullSync), ")"));
|
|
586
582
|
// TODO: create `BackgroundProcessManager.sleep()` ... but, need to put
|
|
587
583
|
// a lot of thought into what that contract looks like to
|
|
588
584
|
// support possible use-cases:
|
|
@@ -628,7 +624,7 @@ var SyncEngine = /** @class */ (function () {
|
|
|
628
624
|
// TLDR; this is a lot of complexity here for a sleep(),
|
|
629
625
|
// but, it's not clear to me yet how to support an
|
|
630
626
|
// extensible, centralized cancelable `sleep()` elegantly.
|
|
631
|
-
|
|
627
|
+
_b.sent();
|
|
632
628
|
this_1.unsleepSyncQueriesObservable = null;
|
|
633
629
|
this_1.waitForSleepState = new Promise(function (resolve) {
|
|
634
630
|
_this.syncQueriesObservableStartSleeping = resolve;
|
|
@@ -745,55 +741,53 @@ var SyncEngine = /** @class */ (function () {
|
|
|
745
741
|
}
|
|
746
742
|
});
|
|
747
743
|
});
|
|
748
|
-
promises = models.map(function (_a) {
|
|
749
|
-
var
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
}
|
|
794
|
-
});
|
|
744
|
+
promises = models.map(function (_a) { return tslib_1.__awaiter(_this, [_a], void 0, function (_b) {
|
|
745
|
+
var modelMetadata, syncPredicate, lastSyncPredicate, prevSyncPredicate, syncPredicateUpdated_1;
|
|
746
|
+
var _c, _d, _e, _f;
|
|
747
|
+
var _g = tslib_1.__read(_b, 2), namespace = _g[0], model = _g[1];
|
|
748
|
+
return tslib_1.__generator(this, function (_h) {
|
|
749
|
+
switch (_h.label) {
|
|
750
|
+
case 0: return [4 /*yield*/, this.getModelMetadata(namespace, model.name)];
|
|
751
|
+
case 1:
|
|
752
|
+
modelMetadata = _h.sent();
|
|
753
|
+
syncPredicate = predicates_1.ModelPredicateCreator.getPredicates(this.syncPredicates.get(model), false);
|
|
754
|
+
lastSyncPredicate = syncPredicate
|
|
755
|
+
? JSON.stringify(syncPredicate)
|
|
756
|
+
: null;
|
|
757
|
+
if (!(modelMetadata === undefined)) return [3 /*break*/, 3];
|
|
758
|
+
return [4 /*yield*/, this.storage.save(this.modelInstanceCreator(ModelMetadataConstructor, {
|
|
759
|
+
model: model.name,
|
|
760
|
+
namespace: namespace,
|
|
761
|
+
lastSync: null,
|
|
762
|
+
fullSyncInterval: fullSyncInterval,
|
|
763
|
+
lastFullSync: null,
|
|
764
|
+
lastSyncPredicate: lastSyncPredicate,
|
|
765
|
+
}), undefined, ownSymbol)];
|
|
766
|
+
case 2:
|
|
767
|
+
_c = tslib_1.__read.apply(void 0, [_h.sent(), 1]), _d = tslib_1.__read(_c[0], 1), savedModel = _d[0];
|
|
768
|
+
return [3 /*break*/, 5];
|
|
769
|
+
case 3:
|
|
770
|
+
prevSyncPredicate = modelMetadata.lastSyncPredicate
|
|
771
|
+
? modelMetadata.lastSyncPredicate
|
|
772
|
+
: null;
|
|
773
|
+
syncPredicateUpdated_1 = prevSyncPredicate !== lastSyncPredicate;
|
|
774
|
+
return [4 /*yield*/, this.storage.save(ModelMetadataConstructor.copyOf(modelMetadata, function (draft) {
|
|
775
|
+
draft.fullSyncInterval = fullSyncInterval;
|
|
776
|
+
// perform a base sync if the syncPredicate changed in between calls to DataStore.start
|
|
777
|
+
// ensures that the local store contains all the data specified by the syncExpression
|
|
778
|
+
if (syncPredicateUpdated_1) {
|
|
779
|
+
draft.lastSync = null;
|
|
780
|
+
draft.lastFullSync = null;
|
|
781
|
+
draft.lastSyncPredicate = lastSyncPredicate;
|
|
782
|
+
}
|
|
783
|
+
}))];
|
|
784
|
+
case 4:
|
|
785
|
+
_e = tslib_1.__read.apply(void 0, [_h.sent(), 1]), _f = tslib_1.__read(_e[0], 1), savedModel = _f[0];
|
|
786
|
+
_h.label = 5;
|
|
787
|
+
case 5: return [2 /*return*/, savedModel];
|
|
788
|
+
}
|
|
795
789
|
});
|
|
796
|
-
});
|
|
790
|
+
}); });
|
|
797
791
|
result = {};
|
|
798
792
|
_d.label = 1;
|
|
799
793
|
case 1:
|