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