@aws-amplify/datastore 5.0.1-api-v6-models.c1977f8.0 → 5.0.1-api-v6-models.891fe0d.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.
Files changed (70) hide show
  1. package/lib/authModeStrategies/defaultAuthStrategy.js +1 -1
  2. package/lib/authModeStrategies/multiAuthStrategy.js +29 -105
  3. package/lib/datastore/datastore.js +887 -1370
  4. package/lib/index.js +1 -1
  5. package/lib/predicates/index.js +53 -102
  6. package/lib/predicates/next.js +310 -557
  7. package/lib/predicates/sort.js +24 -27
  8. package/lib/ssr/index.js +1 -1
  9. package/lib/storage/adapter/AsyncStorageAdapter.js +115 -449
  10. package/lib/storage/adapter/AsyncStorageDatabase.js +215 -480
  11. package/lib/storage/adapter/InMemoryStore.js +27 -101
  12. package/lib/storage/adapter/InMemoryStore.native.js +1 -1
  13. package/lib/storage/adapter/IndexedDBAdapter.js +441 -1002
  14. package/lib/storage/adapter/StorageAdapterBase.js +177 -396
  15. package/lib/storage/adapter/getDefaultAdapter/index.js +5 -6
  16. package/lib/storage/adapter/getDefaultAdapter/index.native.js +2 -2
  17. package/lib/storage/relationship.js +174 -260
  18. package/lib/storage/storage.js +244 -507
  19. package/lib/sync/datastoreConnectivity.js +29 -84
  20. package/lib/sync/datastoreReachability/index.js +1 -1
  21. package/lib/sync/datastoreReachability/index.native.js +2 -2
  22. package/lib/sync/index.js +512 -885
  23. package/lib/sync/merger.js +30 -133
  24. package/lib/sync/outbox.js +147 -302
  25. package/lib/sync/processors/errorMaps.js +30 -80
  26. package/lib/sync/processors/mutation.js +331 -579
  27. package/lib/sync/processors/subscription.js +268 -428
  28. package/lib/sync/processors/sync.js +276 -464
  29. package/lib/sync/utils.js +248 -393
  30. package/lib/tsconfig.tsbuildinfo +1 -1
  31. package/lib/types.js +16 -58
  32. package/lib/util.js +335 -575
  33. package/lib-esm/authModeStrategies/defaultAuthStrategy.js +1 -1
  34. package/lib-esm/authModeStrategies/multiAuthStrategy.js +27 -103
  35. package/lib-esm/datastore/datastore.js +874 -1359
  36. package/lib-esm/index.js +6 -6
  37. package/lib-esm/predicates/index.js +54 -104
  38. package/lib-esm/predicates/next.js +306 -555
  39. package/lib-esm/predicates/sort.js +24 -27
  40. package/lib-esm/ssr/index.js +1 -1
  41. package/lib-esm/storage/adapter/AsyncStorageAdapter.js +111 -446
  42. package/lib-esm/storage/adapter/AsyncStorageDatabase.js +212 -477
  43. package/lib-esm/storage/adapter/InMemoryStore.js +27 -102
  44. package/lib-esm/storage/adapter/IndexedDBAdapter.js +436 -997
  45. package/lib-esm/storage/adapter/StorageAdapterBase.js +172 -392
  46. package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -3
  47. package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +1 -1
  48. package/lib-esm/storage/relationship.js +173 -260
  49. package/lib-esm/storage/storage.js +236 -499
  50. package/lib-esm/sync/datastoreConnectivity.js +26 -82
  51. package/lib-esm/sync/datastoreReachability/index.js +1 -1
  52. package/lib-esm/sync/datastoreReachability/index.native.js +1 -1
  53. package/lib-esm/sync/index.js +498 -872
  54. package/lib-esm/sync/merger.js +28 -131
  55. package/lib-esm/sync/outbox.js +143 -298
  56. package/lib-esm/sync/processors/errorMaps.js +32 -82
  57. package/lib-esm/sync/processors/mutation.js +324 -572
  58. package/lib-esm/sync/processors/subscription.js +258 -418
  59. package/lib-esm/sync/processors/sync.js +269 -457
  60. package/lib-esm/sync/utils.js +245 -390
  61. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  62. package/lib-esm/types.js +16 -59
  63. package/lib-esm/util.js +335 -577
  64. package/package.json +12 -12
  65. package/src/datastore/datastore.ts +4 -3
  66. package/src/storage/adapter/getDefaultAdapter/index.ts +1 -3
  67. package/src/sync/processors/mutation.ts +1 -1
  68. package/src/sync/processors/sync.ts +1 -1
  69. package/src/sync/utils.ts +1 -1
  70. package/src/util.ts +44 -6
@@ -1,104 +1,18 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __rest = (this && this.__rest) || function (s, e) {
50
- var t = {};
51
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
- t[p] = s[p];
53
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
- t[p[i]] = s[p[i]];
57
- }
58
- return t;
59
- };
60
- var __read = (this && this.__read) || function (o, n) {
61
- var m = typeof Symbol === "function" && o[Symbol.iterator];
62
- if (!m) return o;
63
- var i = m.call(o), r, ar = [], e;
64
- try {
65
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
66
- }
67
- catch (error) { e = { error: error }; }
68
- finally {
69
- try {
70
- if (r && !r.done && (m = i["return"])) m.call(i);
71
- }
72
- finally { if (e) throw e.error; }
73
- }
74
- return ar;
75
- };
76
- var __values = (this && this.__values) || function(o) {
77
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
78
- if (m) return m.call(o);
79
- if (o && typeof o.length === "number") return {
80
- next: function () {
81
- if (o && i >= o.length) o = void 0;
82
- return { value: o && o[i++], done: !o };
83
- }
84
- };
85
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
86
- };
87
2
  Object.defineProperty(exports, "__esModule", { value: true });
88
3
  exports.MutationProcessor = exports.safeJitteredBackoff = void 0;
89
- var internals_1 = require("@aws-amplify/api/internals");
90
- var utils_1 = require("@aws-amplify/core/internals/utils");
91
- var core_1 = require("@aws-amplify/core");
92
- var rxjs_1 = require("rxjs");
93
- var types_1 = require("../../types");
94
- var util_1 = require("../../util");
95
- var utils_2 = require("../utils");
96
- var errorMaps_1 = require("./errorMaps");
97
- var MAX_ATTEMPTS = 10;
98
- var logger = new core_1.ConsoleLogger('DataStore');
99
- var MutationProcessor = /** @class */ (function () {
100
- function MutationProcessor(schema, storage, userClasses, outbox, modelInstanceCreator, MutationEvent, amplifyConfig, authModeStrategy, errorHandler, conflictHandler, amplifyContext) {
101
- if (amplifyConfig === void 0) { amplifyConfig = {}; }
4
+ const internals_1 = require("@aws-amplify/api/internals");
5
+ const utils_1 = require("@aws-amplify/core/internals/utils");
6
+ const rxjs_1 = require("rxjs");
7
+ const types_1 = require("../../types");
8
+ const util_1 = require("../../util");
9
+ const utils_2 = require("../utils");
10
+ const errorMaps_1 = require("./errorMaps");
11
+ const core_1 = require("@aws-amplify/core");
12
+ const MAX_ATTEMPTS = 10;
13
+ const logger = new core_1.ConsoleLogger('DataStore');
14
+ class MutationProcessor {
15
+ constructor(schema, storage, userClasses, outbox, modelInstanceCreator, MutationEvent, amplifyConfig = {}, authModeStrategy, errorHandler, conflictHandler, amplifyContext) {
102
16
  this.schema = schema;
103
17
  this.storage = storage;
104
18
  this.userClasses = userClasses;
@@ -117,446 +31,299 @@ var MutationProcessor = /** @class */ (function () {
117
31
  this.amplifyContext.InternalAPI || internals_1.InternalAPI;
118
32
  this.generateQueries();
119
33
  }
120
- MutationProcessor.prototype.generateQueries = function () {
121
- var _this = this;
122
- Object.values(this.schema.namespaces).forEach(function (namespace) {
34
+ generateQueries() {
35
+ Object.values(this.schema.namespaces).forEach(namespace => {
123
36
  Object.values(namespace.models)
124
- .filter(function (_a) {
125
- var syncable = _a.syncable;
126
- return syncable;
127
- })
128
- .forEach(function (model) {
129
- var _a = __read((0, utils_2.buildGraphQLOperation)(namespace, model, 'CREATE'), 1), createMutation = _a[0];
130
- var _b = __read((0, utils_2.buildGraphQLOperation)(namespace, model, 'UPDATE'), 1), updateMutation = _b[0];
131
- var _c = __read((0, utils_2.buildGraphQLOperation)(namespace, model, 'DELETE'), 1), deleteMutation = _c[0];
132
- _this.typeQuery.set(model, [
37
+ .filter(({ syncable }) => syncable)
38
+ .forEach(model => {
39
+ const [createMutation] = (0, utils_2.buildGraphQLOperation)(namespace, model, 'CREATE');
40
+ const [updateMutation] = (0, utils_2.buildGraphQLOperation)(namespace, model, 'UPDATE');
41
+ const [deleteMutation] = (0, utils_2.buildGraphQLOperation)(namespace, model, 'DELETE');
42
+ this.typeQuery.set(model, [
133
43
  createMutation,
134
44
  updateMutation,
135
45
  deleteMutation,
136
46
  ]);
137
47
  });
138
48
  });
139
- };
140
- MutationProcessor.prototype.isReady = function () {
49
+ }
50
+ isReady() {
141
51
  return this.observer !== undefined;
142
- };
143
- MutationProcessor.prototype.start = function () {
144
- var _this = this;
52
+ }
53
+ start() {
145
54
  this.runningProcesses = new utils_1.BackgroundProcessManager();
146
- var observable = new rxjs_1.Observable(function (observer) {
147
- _this.observer = observer;
55
+ const observable = new rxjs_1.Observable(observer => {
56
+ this.observer = observer;
148
57
  try {
149
- _this.resume();
58
+ this.resume();
150
59
  }
151
60
  catch (error) {
152
61
  logger.error('mutations processor start error', error);
153
62
  throw error;
154
63
  }
155
- return _this.runningProcesses.addCleaner(function () { return __awaiter(_this, void 0, void 0, function () {
156
- return __generator(this, function (_a) {
157
- // The observer has unsubscribed and/or `stop()` has been called.
158
- this.removeObserver();
159
- this.pause();
160
- return [2 /*return*/];
161
- });
162
- }); });
163
- });
164
- return observable;
165
- };
166
- MutationProcessor.prototype.stop = function () {
167
- return __awaiter(this, void 0, void 0, function () {
168
- return __generator(this, function (_a) {
169
- switch (_a.label) {
170
- case 0:
171
- this.removeObserver();
172
- return [4 /*yield*/, this.runningProcesses.close()];
173
- case 1:
174
- _a.sent();
175
- return [4 /*yield*/, this.runningProcesses.open()];
176
- case 2:
177
- _a.sent();
178
- return [2 /*return*/];
179
- }
64
+ return this.runningProcesses.addCleaner(async () => {
65
+ // The observer has unsubscribed and/or `stop()` has been called.
66
+ this.removeObserver();
67
+ this.pause();
180
68
  });
181
69
  });
182
- };
183
- MutationProcessor.prototype.removeObserver = function () {
184
- var _a, _b;
185
- (_b = (_a = this.observer) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
70
+ return observable;
71
+ }
72
+ async stop() {
73
+ this.removeObserver();
74
+ await this.runningProcesses.close();
75
+ await this.runningProcesses.open();
76
+ }
77
+ removeObserver() {
78
+ this.observer?.complete?.();
186
79
  this.observer = undefined;
187
- };
188
- MutationProcessor.prototype.resume = function () {
189
- return __awaiter(this, void 0, void 0, function () {
190
- var _this = this;
191
- return __generator(this, function (_a) {
192
- switch (_a.label) {
193
- case 0:
194
- if (!this.runningProcesses.isOpen) return [3 /*break*/, 2];
195
- return [4 /*yield*/, this.runningProcesses.add(function (onTerminate) { return __awaiter(_this, void 0, void 0, function () {
196
- var head, namespaceName, _loop_1, this_1, _a;
197
- var _this = this;
198
- var _b, _c;
199
- return __generator(this, function (_d) {
200
- switch (_d.label) {
201
- case 0:
202
- if (this.processing ||
203
- !this.isReady() ||
204
- !this.runningProcesses.isOpen) {
205
- return [2 /*return*/];
206
- }
207
- this.processing = true;
208
- namespaceName = util_1.USER;
209
- _loop_1 = function () {
210
- var model, operation, data, condition, modelConstructor, result, opName, modelDefinition, modelAuthModes, operationAuthModes_1, authModeAttempts_1, authModeRetry_1, error_1, record, hasMore;
211
- var _e;
212
- return __generator(this, function (_f) {
213
- switch (_f.label) {
214
- case 0:
215
- model = head.model, operation = head.operation, data = head.data, condition = head.condition;
216
- modelConstructor = this_1.userClasses[model];
217
- result = undefined;
218
- opName = undefined;
219
- modelDefinition = undefined;
220
- _f.label = 1;
221
- case 1:
222
- _f.trys.push([1, 4, , 5]);
223
- return [4 /*yield*/, (0, utils_2.getModelAuthModes)({
224
- authModeStrategy: this_1.authModeStrategy,
225
- defaultAuthMode: this_1.amplifyConfig.aws_appsync_authenticationType,
226
- modelName: model,
227
- schema: this_1.schema,
228
- })];
229
- case 2:
230
- modelAuthModes = _f.sent();
231
- operationAuthModes_1 = modelAuthModes[operation.toUpperCase()];
232
- authModeAttempts_1 = 0;
233
- authModeRetry_1 = function () { return __awaiter(_this, void 0, void 0, function () {
234
- var response, error_2, e_1;
235
- return __generator(this, function (_a) {
236
- switch (_a.label) {
237
- case 0:
238
- _a.trys.push([0, 2, , 9]);
239
- logger.debug("Attempting mutation with authMode: ".concat(operationAuthModes_1[authModeAttempts_1]));
240
- return [4 /*yield*/, this.jitteredRetry(namespaceName, model, operation, data, condition, modelConstructor, this.MutationEvent, head, operationAuthModes_1[authModeAttempts_1], onTerminate)];
241
- case 1:
242
- response = _a.sent();
243
- logger.debug("Mutation sent successfully with authMode: ".concat(operationAuthModes_1[authModeAttempts_1]));
244
- return [2 /*return*/, response];
245
- case 2:
246
- error_2 = _a.sent();
247
- authModeAttempts_1++;
248
- if (!(authModeAttempts_1 >= operationAuthModes_1.length)) return [3 /*break*/, 7];
249
- logger.debug("Mutation failed with authMode: ".concat(operationAuthModes_1[authModeAttempts_1 - 1]));
250
- _a.label = 3;
251
- case 3:
252
- _a.trys.push([3, 5, , 6]);
253
- return [4 /*yield*/, this.errorHandler({
254
- recoverySuggestion: 'Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues',
255
- localModel: null,
256
- message: error_2.message,
257
- model: modelConstructor.name,
258
- operation: opName,
259
- errorType: (0, errorMaps_1.getMutationErrorType)(error_2),
260
- process: types_1.ProcessName.sync,
261
- remoteModel: null,
262
- cause: error_2,
263
- })];
264
- case 4:
265
- _a.sent();
266
- return [3 /*break*/, 6];
267
- case 5:
268
- e_1 = _a.sent();
269
- logger.error('Mutation error handler failed with:', e_1);
270
- return [3 /*break*/, 6];
271
- case 6: throw error_2;
272
- case 7:
273
- logger.debug("Mutation failed with authMode: ".concat(operationAuthModes_1[authModeAttempts_1 - 1], ". Retrying with authMode: ").concat(operationAuthModes_1[authModeAttempts_1]));
274
- return [4 /*yield*/, authModeRetry_1()];
275
- case 8: return [2 /*return*/, _a.sent()];
276
- case 9: return [2 /*return*/];
277
- }
278
- });
279
- }); };
280
- return [4 /*yield*/, authModeRetry_1()];
281
- case 3:
282
- _e = __read.apply(void 0, [_f.sent(), 3]), result = _e[0], opName = _e[1], modelDefinition = _e[2];
283
- return [3 /*break*/, 5];
284
- case 4:
285
- error_1 = _f.sent();
286
- if (error_1.message === 'Offline' ||
287
- error_1.message === 'RetryMutation') {
288
- return [2 /*return*/, "continue"];
289
- }
290
- return [3 /*break*/, 5];
291
- case 5:
292
- if (!(result === undefined)) return [3 /*break*/, 7];
293
- logger.debug('done retrying');
294
- return [4 /*yield*/, this_1.storage.runExclusive(function (storage) { return __awaiter(_this, void 0, void 0, function () {
295
- return __generator(this, function (_a) {
296
- switch (_a.label) {
297
- case 0: return [4 /*yield*/, this.outbox.dequeue(storage)];
298
- case 1:
299
- _a.sent();
300
- return [2 /*return*/];
301
- }
302
- });
303
- }); })];
304
- case 6:
305
- _f.sent();
306
- return [2 /*return*/, "continue"];
307
- case 7:
308
- record = result.data[opName];
309
- hasMore = false;
310
- return [4 /*yield*/, this_1.storage.runExclusive(function (storage) { return __awaiter(_this, void 0, void 0, function () {
311
- return __generator(this, function (_a) {
312
- switch (_a.label) {
313
- case 0:
314
- // using runExclusive to prevent possible race condition
315
- // when another record gets enqueued between dequeue and peek
316
- return [4 /*yield*/, this.outbox.dequeue(storage, record, operation)];
317
- case 1:
318
- // using runExclusive to prevent possible race condition
319
- // when another record gets enqueued between dequeue and peek
320
- _a.sent();
321
- return [4 /*yield*/, this.outbox.peek(storage)];
322
- case 2:
323
- hasMore = (_a.sent()) !== undefined;
324
- return [2 /*return*/];
325
- }
326
- });
327
- }); })];
328
- case 8:
329
- _f.sent();
330
- (_c = (_b = this_1.observer) === null || _b === void 0 ? void 0 : _b.next) === null || _c === void 0 ? void 0 : _c.call(_b, {
331
- operation: operation,
332
- modelDefinition: modelDefinition,
333
- model: record,
334
- hasMore: hasMore,
335
- });
336
- return [2 /*return*/];
337
- }
338
- });
339
- };
340
- this_1 = this;
341
- _d.label = 1;
342
- case 1:
343
- _a = this.processing &&
344
- this.runningProcesses.isOpen;
345
- if (!_a) return [3 /*break*/, 3];
346
- return [4 /*yield*/, this.outbox.peek(this.storage)];
347
- case 2:
348
- _a = (head = _d.sent()) !== undefined;
349
- _d.label = 3;
350
- case 3:
351
- if (!_a) return [3 /*break*/, 5];
352
- return [5 /*yield**/, _loop_1()];
353
- case 4:
354
- _d.sent();
355
- return [3 /*break*/, 1];
356
- case 5:
357
- // pauses itself
358
- this.pause();
359
- return [2 /*return*/];
80
+ }
81
+ async resume() {
82
+ if (this.runningProcesses.isOpen) {
83
+ await this.runningProcesses.add(async (onTerminate) => {
84
+ if (this.processing ||
85
+ !this.isReady() ||
86
+ !this.runningProcesses.isOpen) {
87
+ return;
88
+ }
89
+ this.processing = true;
90
+ let head;
91
+ const namespaceName = util_1.USER;
92
+ // start to drain outbox
93
+ while (this.processing &&
94
+ this.runningProcesses.isOpen &&
95
+ (head = await this.outbox.peek(this.storage)) !== undefined) {
96
+ const { model, operation, data, condition } = head;
97
+ const modelConstructor = this.userClasses[model];
98
+ let result = undefined;
99
+ let opName = undefined;
100
+ let modelDefinition = undefined;
101
+ try {
102
+ const modelAuthModes = await (0, utils_2.getModelAuthModes)({
103
+ authModeStrategy: this.authModeStrategy,
104
+ defaultAuthMode: this.amplifyConfig.aws_appsync_authenticationType,
105
+ modelName: model,
106
+ schema: this.schema,
107
+ });
108
+ const operationAuthModes = modelAuthModes[operation.toUpperCase()];
109
+ let authModeAttempts = 0;
110
+ const authModeRetry = async () => {
111
+ try {
112
+ logger.debug(`Attempting mutation with authMode: ${operationAuthModes[authModeAttempts]}`);
113
+ const response = await this.jitteredRetry(namespaceName, model, operation, data, condition, modelConstructor, this.MutationEvent, head, operationAuthModes[authModeAttempts], onTerminate);
114
+ logger.debug(`Mutation sent successfully with authMode: ${operationAuthModes[authModeAttempts]}`);
115
+ return response;
116
+ }
117
+ catch (error) {
118
+ authModeAttempts++;
119
+ if (authModeAttempts >= operationAuthModes.length) {
120
+ logger.debug(`Mutation failed with authMode: ${operationAuthModes[authModeAttempts - 1]}`);
121
+ try {
122
+ await this.errorHandler({
123
+ recoverySuggestion: 'Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues',
124
+ localModel: null,
125
+ message: error.message,
126
+ model: modelConstructor.name,
127
+ operation: opName,
128
+ errorType: (0, errorMaps_1.getMutationErrorType)(error),
129
+ process: types_1.ProcessName.sync,
130
+ remoteModel: null,
131
+ cause: error,
132
+ });
360
133
  }
361
- });
362
- }); }, 'mutation resume loop')];
363
- case 1:
364
- _a.sent();
365
- _a.label = 2;
366
- case 2: return [2 /*return*/];
134
+ catch (e) {
135
+ logger.error('Mutation error handler failed with:', e);
136
+ }
137
+ throw error;
138
+ }
139
+ logger.debug(`Mutation failed with authMode: ${operationAuthModes[authModeAttempts - 1]}. Retrying with authMode: ${operationAuthModes[authModeAttempts]}`);
140
+ return await authModeRetry();
141
+ }
142
+ };
143
+ [result, opName, modelDefinition] = await authModeRetry();
144
+ }
145
+ catch (error) {
146
+ if (error.message === 'Offline' ||
147
+ error.message === 'RetryMutation') {
148
+ continue;
149
+ }
150
+ }
151
+ if (result === undefined) {
152
+ logger.debug('done retrying');
153
+ await this.storage.runExclusive(async (storage) => {
154
+ await this.outbox.dequeue(storage);
155
+ });
156
+ continue;
157
+ }
158
+ const record = result.data[opName];
159
+ let hasMore = false;
160
+ await this.storage.runExclusive(async (storage) => {
161
+ // using runExclusive to prevent possible race condition
162
+ // when another record gets enqueued between dequeue and peek
163
+ await this.outbox.dequeue(storage, record, operation);
164
+ hasMore = (await this.outbox.peek(storage)) !== undefined;
165
+ });
166
+ this.observer?.next?.({
167
+ operation,
168
+ modelDefinition,
169
+ model: record,
170
+ hasMore,
171
+ });
367
172
  }
368
- });
369
- });
370
- };
371
- MutationProcessor.prototype.jitteredRetry = function (namespaceName, model, operation, data, condition, modelConstructor, MutationEvent, mutationEvent, authMode, onTerminate) {
372
- return __awaiter(this, void 0, void 0, function () {
373
- var _this = this;
374
- return __generator(this, function (_a) {
375
- switch (_a.label) {
376
- case 0: return [4 /*yield*/, (0, utils_1.retry)(function (model, operation, data, condition, modelConstructor, MutationEvent, mutationEvent) { return __awaiter(_this, void 0, void 0, function () {
377
- var _a, query, variables, graphQLCondition, opName, modelDefinition, authToken, tryWith, attempt, opType, customUserAgentDetails, result, err_1, _b, error, _c, _d, _e, code, retryWith, err_2, _f, _g, opName_1, query_1, authToken_1, serverData, namespace, updatedMutation;
378
- var _h;
379
- return __generator(this, function (_j) {
380
- switch (_j.label) {
381
- case 0:
382
- _a = __read(this.createQueryVariables(namespaceName, model, operation, data, condition), 5), query = _a[0], variables = _a[1], graphQLCondition = _a[2], opName = _a[3], modelDefinition = _a[4];
383
- return [4 /*yield*/, (0, utils_2.getTokenForCustomAuth)(authMode, this.amplifyConfig)];
384
- case 1:
385
- authToken = _j.sent();
386
- tryWith = {
387
- query: query,
388
- variables: variables,
389
- authMode: authMode,
390
- authToken: authToken,
391
- };
392
- attempt = 0;
393
- opType = this.opTypeFromTransformerOperation(operation);
394
- customUserAgentDetails = {
395
- category: utils_1.Category.DataStore,
396
- action: utils_1.DataStoreAction.GraphQl,
397
- };
398
- _j.label = 2;
399
- case 2:
400
- _j.trys.push([2, 4, , 17]);
401
- return [4 /*yield*/, this.amplifyContext.InternalAPI.graphql(tryWith, undefined, customUserAgentDetails)];
402
- case 3:
403
- result = (_j.sent());
404
- // Use `as any` because TypeScript doesn't seem to like passing tuples
405
- // through generic params.
406
- return [2 /*return*/, [result, opName, modelDefinition]];
407
- case 4:
408
- err_1 = _j.sent();
409
- if (!(err_1.errors && err_1.errors.length > 0)) return [3 /*break*/, 15];
410
- _b = __read(err_1.errors, 1), error = _b[0];
411
- _c = error.originalError, _d = _c === void 0 ? {} : _c, _e = _d.code, code = _e === void 0 ? null : _e;
412
- if (error.errorType === 'Unauthorized') {
413
- throw new utils_1.NonRetryableError('Unauthorized');
414
- }
415
- if (error.message === 'Network Error' ||
416
- code === 'ECONNABORTED' // refers to axios timeout error caused by device's bad network condition
417
- ) {
418
- if (!this.processing) {
419
- throw new utils_1.NonRetryableError('Offline');
420
- }
421
- // TODO: Check errors on different env (react-native or other browsers)
422
- throw new Error('Network Error');
423
- }
424
- if (!(error.errorType === 'ConflictUnhandled')) return [3 /*break*/, 13];
425
- // TODO: add on ConflictConditionalCheck error query last from server
426
- attempt++;
427
- retryWith = void 0;
428
- if (!(attempt > MAX_ATTEMPTS)) return [3 /*break*/, 5];
429
- retryWith = types_1.DISCARD;
430
- return [3 /*break*/, 8];
431
- case 5:
432
- _j.trys.push([5, 7, , 8]);
433
- return [4 /*yield*/, this.conflictHandler({
434
- modelConstructor: modelConstructor,
435
- localModel: this.modelInstanceCreator(modelConstructor, variables.input),
436
- remoteModel: this.modelInstanceCreator(modelConstructor, error.data),
437
- operation: opType,
438
- attempts: attempt,
439
- })];
440
- case 6:
441
- retryWith = _j.sent();
442
- return [3 /*break*/, 8];
443
- case 7:
444
- err_2 = _j.sent();
445
- logger.warn('conflict trycatch', err_2);
446
- return [3 /*break*/, 17];
447
- case 8:
448
- if (!(retryWith === types_1.DISCARD)) return [3 /*break*/, 11];
449
- _f = __read((0, utils_2.buildGraphQLOperation)(this.schema.namespaces[namespaceName], modelDefinition, 'GET'), 1), _g = __read(_f[0], 3), opName_1 = _g[1], query_1 = _g[2];
450
- return [4 /*yield*/, (0, utils_2.getTokenForCustomAuth)(authMode, this.amplifyConfig)];
451
- case 9:
452
- authToken_1 = _j.sent();
453
- return [4 /*yield*/, this.amplifyContext.InternalAPI.graphql({
454
- query: query_1,
455
- variables: { id: variables.input.id },
456
- authMode: authMode,
457
- authToken: authToken_1,
458
- }, undefined, customUserAgentDetails)];
459
- case 10:
460
- serverData = _j.sent();
461
- // onTerminate cancel graphql()
462
- return [2 /*return*/, [serverData, opName_1, modelDefinition]];
463
- case 11:
464
- namespace = this.schema.namespaces[namespaceName];
465
- updatedMutation = (0, utils_2.createMutationInstanceFromModelOperation)(namespace.relationships, modelDefinition, opType, modelConstructor, retryWith, graphQLCondition, MutationEvent, this.modelInstanceCreator, mutationEvent.id);
466
- return [4 /*yield*/, this.storage.save(updatedMutation)];
467
- case 12:
468
- _j.sent();
469
- throw new utils_1.NonRetryableError('RetryMutation');
470
- case 13:
471
- try {
472
- this.errorHandler({
473
- recoverySuggestion: 'Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues',
474
- localModel: variables.input,
475
- message: error.message,
476
- operation: operation,
477
- errorType: (0, errorMaps_1.getMutationErrorType)(error),
478
- errorInfo: error.errorInfo,
479
- process: types_1.ProcessName.mutate,
480
- cause: error,
481
- remoteModel: error.data
482
- ? this.modelInstanceCreator(modelConstructor, error.data)
483
- : null,
484
- });
485
- }
486
- catch (err) {
487
- logger.warn('Mutation error handler failed with:', err);
488
- }
489
- finally {
490
- // Return empty tuple, dequeues the mutation
491
- return [2 /*return*/, error.data
492
- ? [
493
- { data: (_h = {}, _h[opName] = error.data, _h) },
494
- opName,
495
- modelDefinition,
496
- ]
497
- : []];
498
- }
499
- _j.label = 14;
500
- case 14: return [3 /*break*/, 16];
501
- case 15:
502
- // Catch-all for client-side errors that don't come back in the `GraphQLError` format.
503
- // These errors should not be retried.
504
- throw new utils_1.NonRetryableError(err_1);
505
- case 16: return [3 /*break*/, 17];
506
- case 17:
507
- if (tryWith) return [3 /*break*/, 2];
508
- _j.label = 18;
509
- case 18: return [2 /*return*/];
173
+ // pauses itself
174
+ this.pause();
175
+ }, 'mutation resume loop');
176
+ }
177
+ }
178
+ async jitteredRetry(namespaceName, model, operation, data, condition, modelConstructor, MutationEvent, mutationEvent, authMode, onTerminate) {
179
+ return await (0, utils_1.retry)(async (model, operation, data, condition, modelConstructor, MutationEvent, mutationEvent) => {
180
+ const [query, variables, graphQLCondition, opName, modelDefinition] = this.createQueryVariables(namespaceName, model, operation, data, condition);
181
+ const authToken = await (0, utils_2.getTokenForCustomAuth)(authMode, this.amplifyConfig);
182
+ const tryWith = {
183
+ query,
184
+ variables,
185
+ authMode,
186
+ authToken,
187
+ };
188
+ let attempt = 0;
189
+ const opType = this.opTypeFromTransformerOperation(operation);
190
+ const customUserAgentDetails = {
191
+ category: utils_1.Category.DataStore,
192
+ action: utils_1.DataStoreAction.GraphQl,
193
+ };
194
+ do {
195
+ try {
196
+ const result = (await this.amplifyContext.InternalAPI.graphql(tryWith, undefined, customUserAgentDetails));
197
+ // Use `as any` because TypeScript doesn't seem to like passing tuples
198
+ // through generic params.
199
+ return [result, opName, modelDefinition];
200
+ }
201
+ catch (err) {
202
+ if (err.errors && err.errors.length > 0) {
203
+ const [error] = err.errors;
204
+ const { originalError: { code = null } = {} } = error;
205
+ if (error.errorType === 'Unauthorized') {
206
+ throw new utils_1.NonRetryableError('Unauthorized');
207
+ }
208
+ if (error.message === 'Network Error' ||
209
+ code === 'ECONNABORTED' // refers to axios timeout error caused by device's bad network condition
210
+ ) {
211
+ if (!this.processing) {
212
+ throw new utils_1.NonRetryableError('Offline');
213
+ }
214
+ // TODO: Check errors on different env (react-native or other browsers)
215
+ throw new Error('Network Error');
216
+ }
217
+ if (error.errorType === 'ConflictUnhandled') {
218
+ // TODO: add on ConflictConditionalCheck error query last from server
219
+ attempt++;
220
+ let retryWith;
221
+ if (attempt > MAX_ATTEMPTS) {
222
+ retryWith = types_1.DISCARD;
223
+ }
224
+ else {
225
+ try {
226
+ retryWith = await this.conflictHandler({
227
+ modelConstructor,
228
+ localModel: this.modelInstanceCreator(modelConstructor, variables.input),
229
+ remoteModel: this.modelInstanceCreator(modelConstructor, error.data),
230
+ operation: opType,
231
+ attempts: attempt,
232
+ });
233
+ }
234
+ catch (err) {
235
+ logger.warn('conflict trycatch', err);
236
+ continue;
510
237
  }
511
- });
512
- }); }, [
513
- model,
514
- operation,
515
- data,
516
- condition,
517
- modelConstructor,
518
- MutationEvent,
519
- mutationEvent,
520
- ], exports.safeJitteredBackoff, onTerminate)];
521
- case 1: return [2 /*return*/, _a.sent()];
238
+ }
239
+ if (retryWith === types_1.DISCARD) {
240
+ // Query latest from server and notify merger
241
+ const [[, opName, query]] = (0, utils_2.buildGraphQLOperation)(this.schema.namespaces[namespaceName], modelDefinition, 'GET');
242
+ const authToken = await (0, utils_2.getTokenForCustomAuth)(authMode, this.amplifyConfig);
243
+ const serverData = await this.amplifyContext.InternalAPI.graphql({
244
+ query,
245
+ variables: { id: variables.input.id },
246
+ authMode,
247
+ authToken,
248
+ }, undefined, customUserAgentDetails);
249
+ // onTerminate cancel graphql()
250
+ return [serverData, opName, modelDefinition];
251
+ }
252
+ const namespace = this.schema.namespaces[namespaceName];
253
+ // convert retry with to tryWith
254
+ const updatedMutation = (0, utils_2.createMutationInstanceFromModelOperation)(namespace.relationships, modelDefinition, opType, modelConstructor, retryWith, graphQLCondition, MutationEvent, this.modelInstanceCreator, mutationEvent.id);
255
+ await this.storage.save(updatedMutation);
256
+ throw new utils_1.NonRetryableError('RetryMutation');
257
+ }
258
+ else {
259
+ try {
260
+ this.errorHandler({
261
+ recoverySuggestion: 'Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues',
262
+ localModel: variables.input,
263
+ message: error.message,
264
+ operation,
265
+ errorType: (0, errorMaps_1.getMutationErrorType)(error),
266
+ errorInfo: error.errorInfo,
267
+ process: types_1.ProcessName.mutate,
268
+ cause: error,
269
+ remoteModel: error.data
270
+ ? this.modelInstanceCreator(modelConstructor, error.data)
271
+ : null,
272
+ });
273
+ }
274
+ catch (err) {
275
+ logger.warn('Mutation error handler failed with:', err);
276
+ }
277
+ finally {
278
+ // Return empty tuple, dequeues the mutation
279
+ return error.data
280
+ ? [
281
+ { data: { [opName]: error.data } },
282
+ opName,
283
+ modelDefinition,
284
+ ]
285
+ : [];
286
+ }
287
+ }
288
+ }
289
+ else {
290
+ // Catch-all for client-side errors that don't come back in the `GraphQLError` format.
291
+ // These errors should not be retried.
292
+ throw new utils_1.NonRetryableError(err);
293
+ }
522
294
  }
523
- });
524
- });
525
- };
526
- MutationProcessor.prototype.createQueryVariables = function (namespaceName, model, operation, data, condition) {
527
- var e_2, _a, e_3, _b, e_4, _c;
528
- var _d, _e;
529
- var modelDefinition = this.schema.namespaces[namespaceName].models[model];
530
- var primaryKey = this.schema.namespaces[namespaceName].keys[model].primaryKey;
531
- var auth = (_d = modelDefinition.attributes) === null || _d === void 0 ? void 0 : _d.find(function (a) { return a.type === 'auth'; });
532
- var ownerFields = ((_e = auth === null || auth === void 0 ? void 0 : auth.properties) === null || _e === void 0 ? void 0 : _e.rules.map(function (rule) { return rule.ownerField; }).filter(function (f) { return f; })) || ['owner'];
533
- var queriesTuples = this.typeQuery.get(modelDefinition);
534
- var _f = __read(queriesTuples.find(function (_a) {
535
- var _b = __read(_a, 1), transformerMutationType = _b[0];
536
- return transformerMutationType === operation;
537
- }), 3), opName = _f[1], query = _f[2];
538
- var _g = JSON.parse(data), _version = _g._version, parsedData = __rest(_g, ["_version"]);
295
+ } while (tryWith);
296
+ }, [
297
+ model,
298
+ operation,
299
+ data,
300
+ condition,
301
+ modelConstructor,
302
+ MutationEvent,
303
+ mutationEvent,
304
+ ], exports.safeJitteredBackoff, onTerminate);
305
+ }
306
+ createQueryVariables(namespaceName, model, operation, data, condition) {
307
+ const modelDefinition = this.schema.namespaces[namespaceName].models[model];
308
+ const { primaryKey } = this.schema.namespaces[namespaceName].keys[model];
309
+ const auth = modelDefinition.attributes?.find(a => a.type === 'auth');
310
+ const ownerFields = auth?.properties?.rules
311
+ .map(rule => rule.ownerField)
312
+ .filter(f => f) || ['owner'];
313
+ const queriesTuples = this.typeQuery.get(modelDefinition);
314
+ const [, opName, query] = queriesTuples.find(([transformerMutationType]) => transformerMutationType === operation);
315
+ const { _version, ...parsedData } = JSON.parse(data);
539
316
  // include all the fields that comprise a custom PK if one is specified
540
- var deleteInput = {};
317
+ const deleteInput = {};
541
318
  if (primaryKey && primaryKey.length) {
542
- try {
543
- for (var primaryKey_1 = __values(primaryKey), primaryKey_1_1 = primaryKey_1.next(); !primaryKey_1_1.done; primaryKey_1_1 = primaryKey_1.next()) {
544
- var pkField = primaryKey_1_1.value;
545
- deleteInput[pkField] = parsedData[pkField];
546
- }
547
- }
548
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
549
- finally {
550
- try {
551
- if (primaryKey_1_1 && !primaryKey_1_1.done && (_a = primaryKey_1.return)) _a.call(primaryKey_1);
552
- }
553
- finally { if (e_2) throw e_2.error; }
319
+ for (const pkField of primaryKey) {
320
+ deleteInput[pkField] = parsedData[pkField];
554
321
  }
555
322
  }
556
323
  else {
557
324
  deleteInput[util_1.ID] = parsedData.id;
558
325
  }
559
- var mutationInput;
326
+ let mutationInput;
560
327
  if (operation === utils_2.TransformerMutationType.DELETE) {
561
328
  // For DELETE mutations, only the key(s) are included in the input
562
329
  mutationInput = deleteInput;
@@ -564,75 +331,61 @@ var MutationProcessor = /** @class */ (function () {
564
331
  else {
565
332
  // Otherwise, we construct the mutation input with the following logic
566
333
  mutationInput = {};
567
- var modelFields = Object.values(modelDefinition.fields);
568
- try {
569
- for (var modelFields_1 = __values(modelFields), modelFields_1_1 = modelFields_1.next(); !modelFields_1_1.done; modelFields_1_1 = modelFields_1.next()) {
570
- var _h = modelFields_1_1.value, name_1 = _h.name, type = _h.type, association = _h.association, isReadOnly = _h.isReadOnly;
571
- // omit readonly fields. cloud storage doesn't need them and won't take them!
572
- if (isReadOnly) {
573
- continue;
574
- }
575
- // omit owner fields if it's `null`. cloud storage doesn't allow it.
576
- if (ownerFields.includes(name_1) && parsedData[name_1] === null) {
577
- continue;
578
- }
579
- // model fields should be stripped out from the input
580
- if ((0, types_1.isModelFieldType)(type)) {
581
- // except for belongs to relations - we need to replace them with the correct foreign key(s)
582
- if ((0, types_1.isTargetNameAssociation)(association) &&
583
- association.connectionType === 'BELONGS_TO') {
584
- var targetNames = (0, util_1.extractTargetNamesFromSrc)(association);
585
- if (targetNames) {
586
- try {
587
- // instead of including the connected model itself, we add its key(s) to the mutation input
588
- for (var targetNames_1 = (e_4 = void 0, __values(targetNames)), targetNames_1_1 = targetNames_1.next(); !targetNames_1_1.done; targetNames_1_1 = targetNames_1.next()) {
589
- var targetName = targetNames_1_1.value;
590
- mutationInput[targetName] = parsedData[targetName];
591
- }
592
- }
593
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
594
- finally {
595
- try {
596
- if (targetNames_1_1 && !targetNames_1_1.done && (_c = targetNames_1.return)) _c.call(targetNames_1);
597
- }
598
- finally { if (e_4) throw e_4.error; }
599
- }
334
+ const modelFields = Object.values(modelDefinition.fields);
335
+ for (const { name, type, association, isReadOnly } of modelFields) {
336
+ // omit readonly fields. cloud storage doesn't need them and won't take them!
337
+ if (isReadOnly) {
338
+ continue;
339
+ }
340
+ // omit owner fields if it's `null`. cloud storage doesn't allow it.
341
+ if (ownerFields.includes(name) && parsedData[name] === null) {
342
+ continue;
343
+ }
344
+ // model fields should be stripped out from the input
345
+ if ((0, types_1.isModelFieldType)(type)) {
346
+ // except for belongs to relations - we need to replace them with the correct foreign key(s)
347
+ if ((0, types_1.isTargetNameAssociation)(association) &&
348
+ association.connectionType === 'BELONGS_TO') {
349
+ const targetNames = (0, util_1.extractTargetNamesFromSrc)(association);
350
+ if (targetNames) {
351
+ // instead of including the connected model itself, we add its key(s) to the mutation input
352
+ for (const targetName of targetNames) {
353
+ mutationInput[targetName] = parsedData[targetName];
600
354
  }
601
355
  }
602
- continue;
603
- }
604
- // scalar fields / non-model types
605
- if (operation === utils_2.TransformerMutationType.UPDATE) {
606
- if (!parsedData.hasOwnProperty(name_1)) {
607
- // for update mutations - strip out a field if it's unchanged
608
- continue;
609
- }
610
356
  }
611
- // all other fields are added to the input object
612
- mutationInput[name_1] = parsedData[name_1];
357
+ continue;
613
358
  }
614
- }
615
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
616
- finally {
617
- try {
618
- if (modelFields_1_1 && !modelFields_1_1.done && (_b = modelFields_1.return)) _b.call(modelFields_1);
359
+ // scalar fields / non-model types
360
+ if (operation === utils_2.TransformerMutationType.UPDATE) {
361
+ if (!parsedData.hasOwnProperty(name)) {
362
+ // for update mutations - strip out a field if it's unchanged
363
+ continue;
364
+ }
619
365
  }
620
- finally { if (e_3) throw e_3.error; }
366
+ // all other fields are added to the input object
367
+ mutationInput[name] = parsedData[name];
621
368
  }
622
369
  }
623
370
  // Build mutation variables input object
624
- var input = __assign(__assign({}, mutationInput), { _version: _version });
625
- var graphQLCondition = JSON.parse(condition);
626
- var variables = __assign({ input: input }, (operation === utils_2.TransformerMutationType.CREATE
627
- ? {}
628
- : {
629
- condition: Object.keys(graphQLCondition).length > 0
630
- ? graphQLCondition
631
- : null,
632
- }));
371
+ const input = {
372
+ ...mutationInput,
373
+ _version,
374
+ };
375
+ const graphQLCondition = JSON.parse(condition);
376
+ const variables = {
377
+ input,
378
+ ...(operation === utils_2.TransformerMutationType.CREATE
379
+ ? {}
380
+ : {
381
+ condition: Object.keys(graphQLCondition).length > 0
382
+ ? graphQLCondition
383
+ : null,
384
+ }),
385
+ };
633
386
  return [query, variables, graphQLCondition, opName, modelDefinition];
634
- };
635
- MutationProcessor.prototype.opTypeFromTransformerOperation = function (operation) {
387
+ }
388
+ opTypeFromTransformerOperation(operation) {
636
389
  switch (operation) {
637
390
  case utils_2.TransformerMutationType.CREATE:
638
391
  return types_1.OpType.INSERT;
@@ -643,19 +396,18 @@ var MutationProcessor = /** @class */ (function () {
643
396
  case utils_2.TransformerMutationType.GET: // Intentionally blank
644
397
  break;
645
398
  default:
646
- throw new Error("Invalid operation ".concat(operation));
399
+ throw new Error(`Invalid operation ${operation}`);
647
400
  }
648
401
  // because it makes TS happy ...
649
402
  return undefined;
650
- };
651
- MutationProcessor.prototype.pause = function () {
403
+ }
404
+ pause() {
652
405
  this.processing = false;
653
- };
654
- return MutationProcessor;
655
- }());
406
+ }
407
+ }
656
408
  exports.MutationProcessor = MutationProcessor;
657
- var MAX_RETRY_DELAY_MS = 5 * 60 * 1000;
658
- var originalJitteredBackoff = (0, utils_1.jitteredBackoff)(MAX_RETRY_DELAY_MS);
409
+ const MAX_RETRY_DELAY_MS = 5 * 60 * 1000;
410
+ const originalJitteredBackoff = (0, utils_1.jitteredBackoff)(MAX_RETRY_DELAY_MS);
659
411
  /**
660
412
  * @private
661
413
  * Internal use of Amplify only.
@@ -671,8 +423,8 @@ var originalJitteredBackoff = (0, utils_1.jitteredBackoff)(MAX_RETRY_DELAY_MS);
671
423
  * @param error tested to see if `.message` is 'Network Error'
672
424
  * @returns number | false :
673
425
  */
674
- var safeJitteredBackoff = function (attempt, _args, error) {
675
- var attemptResult = originalJitteredBackoff(attempt);
426
+ const safeJitteredBackoff = (attempt, _args, error) => {
427
+ const attemptResult = originalJitteredBackoff(attempt);
676
428
  // If this is the last attempt and it is a network error, we retry indefinitively every 5 minutes
677
429
  if (attemptResult === false &&
678
430
  (error || {}).message === 'Network Error') {