@aws-amplify/datastore 4.7.5 → 5.0.1-console-preview.4208d73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/lib/authModeStrategies/defaultAuthStrategy.js +3 -2
- package/lib/authModeStrategies/index.js +3 -3
- package/lib/authModeStrategies/multiAuthStrategy.js +81 -24
- package/lib/datastore/datastore.d.ts +3 -4
- package/lib/datastore/datastore.js +361 -227
- package/lib/index.d.ts +1 -1
- package/lib/index.js +25 -12
- package/lib/predicates/index.js +46 -12
- package/lib/predicates/next.d.ts +2 -2
- package/lib/predicates/next.js +172 -74
- package/lib/predicates/sort.js +3 -4
- package/lib/ssr/index.js +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +240 -128
- package/lib/storage/adapter/AsyncStorageDatabase.js +100 -39
- package/lib/storage/adapter/InMemoryStore.js +68 -17
- package/lib/storage/adapter/InMemoryStore.native.js +5 -3
- package/lib/storage/adapter/IndexedDBAdapter.js +355 -199
- package/lib/storage/adapter/StorageAdapterBase.js +154 -85
- package/lib/storage/adapter/getDefaultAdapter/index.js +8 -9
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -3
- package/lib/storage/adapter/index.js +0 -1
- package/lib/storage/relationship.js +31 -21
- package/lib/storage/storage.d.ts +3 -3
- package/lib/storage/storage.js +143 -61
- package/lib/sync/datastoreConnectivity.d.ts +1 -1
- package/lib/sync/datastoreConnectivity.js +57 -9
- package/lib/sync/datastoreReachability/index.js +3 -3
- package/lib/sync/datastoreReachability/index.native.js +7 -5
- package/lib/sync/index.d.ts +1 -1
- package/lib/sync/index.js +193 -125
- package/lib/sync/merger.js +81 -10
- package/lib/sync/outbox.js +101 -30
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +41 -6
- package/lib/sync/processors/mutation.d.ts +1 -1
- package/lib/sync/processors/mutation.js +192 -101
- package/lib/sync/processors/subscription.d.ts +4 -1
- package/lib/sync/processors/subscription.js +190 -178
- package/lib/sync/processors/sync.d.ts +1 -1
- package/lib/sync/processors/sync.js +113 -47
- package/lib/sync/utils.d.ts +4 -4
- package/lib/sync/utils.js +162 -81
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types.d.ts +138 -140
- package/lib/types.js +40 -5
- package/lib/util.d.ts +9 -17
- package/lib/util.js +216 -100
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +0 -1
- package/lib-esm/authModeStrategies/index.js +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +76 -21
- package/lib-esm/datastore/datastore.d.ts +3 -4
- package/lib-esm/datastore/datastore.js +206 -77
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +0 -1
- package/lib-esm/predicates/index.js +40 -7
- package/lib-esm/predicates/next.d.ts +2 -2
- package/lib-esm/predicates/next.js +148 -52
- package/lib-esm/predicates/sort.js +2 -4
- package/lib-esm/ssr/index.js +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +203 -95
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +66 -5
- package/lib-esm/storage/adapter/InMemoryStore.js +52 -2
- package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +271 -138
- package/lib-esm/storage/adapter/StorageAdapterBase.js +130 -62
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -5
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +0 -1
- package/lib-esm/storage/adapter/index.js +1 -1
- package/lib-esm/storage/relationship.js +27 -18
- package/lib-esm/storage/storage.d.ts +3 -3
- package/lib-esm/storage/storage.js +87 -9
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +48 -3
- package/lib-esm/sync/datastoreReachability/index.js +1 -2
- package/lib-esm/sync/datastoreReachability/index.native.js +1 -2
- package/lib-esm/sync/index.d.ts +1 -1
- package/lib-esm/sync/index.js +136 -72
- package/lib-esm/sync/merger.js +73 -3
- package/lib-esm/sync/outbox.js +75 -5
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +39 -5
- package/lib-esm/sync/processors/mutation.d.ts +1 -1
- package/lib-esm/sync/processors/mutation.js +130 -44
- package/lib-esm/sync/processors/subscription.d.ts +4 -1
- package/lib-esm/sync/processors/subscription.js +134 -126
- package/lib-esm/sync/processors/sync.d.ts +1 -1
- package/lib-esm/sync/processors/sync.js +74 -12
- package/lib-esm/sync/utils.d.ts +4 -4
- package/lib-esm/sync/utils.js +135 -55
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types.d.ts +138 -140
- package/lib-esm/types.js +36 -2
- package/lib-esm/util.d.ts +9 -17
- package/lib-esm/util.js +96 -16
- package/package.json +139 -132
- package/src/authModeStrategies/multiAuthStrategy.ts +11 -12
- package/src/datastore/datastore.ts +32 -25
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/InMemoryStore.ts +1 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +1 -1
- package/src/storage/adapter/StorageAdapterBase.ts +1 -1
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -3
- package/src/storage/storage.ts +1 -1
- package/src/sync/datastoreConnectivity.ts +2 -2
- package/src/sync/datastoreReachability/index.native.ts +1 -1
- package/src/sync/datastoreReachability/index.ts +1 -1
- package/src/sync/index.ts +69 -78
- package/src/sync/processors/mutation.ts +16 -10
- package/src/sync/processors/subscription.ts +55 -127
- package/src/sync/processors/sync.ts +8 -4
- package/src/sync/utils.ts +7 -8
- package/src/types.ts +4 -8
- package/src/util.ts +5 -6
- package/lib/.tsbuildinfo +0 -3
- package/lib/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib/authModeStrategies/index.js.map +0 -1
- package/lib/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib/datastore/datastore.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/predicates/index.js.map +0 -1
- package/lib/predicates/next.js.map +0 -1
- package/lib/predicates/sort.js.map +0 -1
- package/lib/ssr/index.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib/storage/adapter/index.js.map +0 -1
- package/lib/storage/relationship.js.map +0 -1
- package/lib/storage/storage.js.map +0 -1
- package/lib/sync/datastoreConnectivity.js.map +0 -1
- package/lib/sync/datastoreReachability/index.js.map +0 -1
- package/lib/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib/sync/index.js.map +0 -1
- package/lib/sync/merger.js.map +0 -1
- package/lib/sync/outbox.js.map +0 -1
- package/lib/sync/processors/errorMaps.js.map +0 -1
- package/lib/sync/processors/mutation.js.map +0 -1
- package/lib/sync/processors/subscription.js.map +0 -1
- package/lib/sync/processors/sync.js.map +0 -1
- package/lib/sync/utils.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/util.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib-esm/authModeStrategies/index.js.map +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib-esm/datastore/datastore.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/predicates/index.js.map +0 -1
- package/lib-esm/predicates/next.js.map +0 -1
- package/lib-esm/predicates/sort.js.map +0 -1
- package/lib-esm/ssr/index.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib-esm/storage/adapter/index.js.map +0 -1
- package/lib-esm/storage/relationship.js.map +0 -1
- package/lib-esm/storage/storage.js.map +0 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib-esm/sync/index.js.map +0 -1
- package/lib-esm/sync/merger.js.map +0 -1
- package/lib-esm/sync/outbox.js.map +0 -1
- package/lib-esm/sync/processors/errorMaps.js.map +0 -1
- package/lib-esm/sync/processors/mutation.js.map +0 -1
- package/lib-esm/sync/processors/subscription.js.map +0 -1
- package/lib-esm/sync/processors/sync.js.map +0 -1
- package/lib-esm/sync/utils.js.map +0 -1
- package/lib-esm/types.js.map +0 -1
- package/lib-esm/util.js.map +0 -1
|
@@ -1,15 +1,103 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
88
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
89
|
+
};
|
|
2
90
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
91
|
+
exports.MutationProcessor = exports.safeJitteredBackoff = void 0;
|
|
4
92
|
var internals_1 = require("@aws-amplify/api/internals");
|
|
5
|
-
var
|
|
6
|
-
var zen_observable_ts_1 =
|
|
93
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
94
|
+
var zen_observable_ts_1 = __importDefault(require("zen-observable-ts"));
|
|
7
95
|
var types_1 = require("../../types");
|
|
8
96
|
var util_1 = require("../../util");
|
|
9
|
-
var
|
|
97
|
+
var utils_2 = require("../utils");
|
|
10
98
|
var errorMaps_1 = require("./errorMaps");
|
|
11
99
|
var MAX_ATTEMPTS = 10;
|
|
12
|
-
var logger = new
|
|
100
|
+
var logger = new utils_1.Logger('DataStore');
|
|
13
101
|
var MutationProcessor = /** @class */ (function () {
|
|
14
102
|
function MutationProcessor(schema, storage, userClasses, outbox, modelInstanceCreator, MutationEvent, amplifyConfig, authModeStrategy, errorHandler, conflictHandler, amplifyContext) {
|
|
15
103
|
if (amplifyConfig === void 0) { amplifyConfig = {}; }
|
|
@@ -26,7 +114,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
26
114
|
this.amplifyContext = amplifyContext;
|
|
27
115
|
this.typeQuery = new WeakMap();
|
|
28
116
|
this.processing = false;
|
|
29
|
-
this.runningProcesses = new
|
|
117
|
+
this.runningProcesses = new utils_1.BackgroundProcessManager();
|
|
30
118
|
this.amplifyContext.InternalAPI =
|
|
31
119
|
this.amplifyContext.InternalAPI || internals_1.InternalAPI;
|
|
32
120
|
this.generateQueries();
|
|
@@ -40,9 +128,9 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
40
128
|
return syncable;
|
|
41
129
|
})
|
|
42
130
|
.forEach(function (model) {
|
|
43
|
-
var _a =
|
|
44
|
-
var _b =
|
|
45
|
-
var _c =
|
|
131
|
+
var _a = __read((0, utils_2.buildGraphQLOperation)(namespace, model, 'CREATE'), 1), createMutation = _a[0];
|
|
132
|
+
var _b = __read((0, utils_2.buildGraphQLOperation)(namespace, model, 'UPDATE'), 1), updateMutation = _b[0];
|
|
133
|
+
var _c = __read((0, utils_2.buildGraphQLOperation)(namespace, model, 'DELETE'), 1), deleteMutation = _c[0];
|
|
46
134
|
_this.typeQuery.set(model, [
|
|
47
135
|
createMutation,
|
|
48
136
|
updateMutation,
|
|
@@ -56,7 +144,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
56
144
|
};
|
|
57
145
|
MutationProcessor.prototype.start = function () {
|
|
58
146
|
var _this = this;
|
|
59
|
-
this.runningProcesses = new
|
|
147
|
+
this.runningProcesses = new utils_1.BackgroundProcessManager();
|
|
60
148
|
var observable = new zen_observable_ts_1.default(function (observer) {
|
|
61
149
|
_this.observer = observer;
|
|
62
150
|
try {
|
|
@@ -66,8 +154,8 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
66
154
|
logger.error('mutations processor start error', error);
|
|
67
155
|
throw error;
|
|
68
156
|
}
|
|
69
|
-
return _this.runningProcesses.addCleaner(function () { return
|
|
70
|
-
return
|
|
157
|
+
return _this.runningProcesses.addCleaner(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
158
|
+
return __generator(this, function (_a) {
|
|
71
159
|
// The observer has unsubscribed and/or `stop()` has been called.
|
|
72
160
|
this.removeObserver();
|
|
73
161
|
this.pause();
|
|
@@ -78,8 +166,8 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
78
166
|
return observable;
|
|
79
167
|
};
|
|
80
168
|
MutationProcessor.prototype.stop = function () {
|
|
81
|
-
return
|
|
82
|
-
return
|
|
169
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
170
|
+
return __generator(this, function (_a) {
|
|
83
171
|
switch (_a.label) {
|
|
84
172
|
case 0:
|
|
85
173
|
this.removeObserver();
|
|
@@ -100,16 +188,17 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
100
188
|
this.observer = undefined;
|
|
101
189
|
};
|
|
102
190
|
MutationProcessor.prototype.resume = function () {
|
|
103
|
-
return
|
|
191
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
104
192
|
var _this = this;
|
|
105
|
-
return
|
|
193
|
+
return __generator(this, function (_a) {
|
|
106
194
|
switch (_a.label) {
|
|
107
|
-
case 0:
|
|
108
|
-
|
|
195
|
+
case 0:
|
|
196
|
+
if (!this.runningProcesses.isOpen) return [3 /*break*/, 2];
|
|
197
|
+
return [4 /*yield*/, this.runningProcesses.add(function (onTerminate) { return __awaiter(_this, void 0, void 0, function () {
|
|
109
198
|
var head, namespaceName, _loop_1, this_1, _a;
|
|
110
199
|
var _this = this;
|
|
111
200
|
var _b, _c;
|
|
112
|
-
return
|
|
201
|
+
return __generator(this, function (_d) {
|
|
113
202
|
switch (_d.label) {
|
|
114
203
|
case 0:
|
|
115
204
|
if (this.processing ||
|
|
@@ -121,45 +210,45 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
121
210
|
namespaceName = util_1.USER;
|
|
122
211
|
_loop_1 = function () {
|
|
123
212
|
var model, operation, data, condition, modelConstructor, result, opName, modelDefinition, modelAuthModes, operationAuthModes_1, authModeAttempts_1, authModeRetry_1, error_1, record, hasMore;
|
|
124
|
-
var
|
|
125
|
-
return
|
|
126
|
-
switch (
|
|
213
|
+
var _e;
|
|
214
|
+
return __generator(this, function (_f) {
|
|
215
|
+
switch (_f.label) {
|
|
127
216
|
case 0:
|
|
128
217
|
model = head.model, operation = head.operation, data = head.data, condition = head.condition;
|
|
129
218
|
modelConstructor = this_1.userClasses[model];
|
|
130
219
|
result = undefined;
|
|
131
220
|
opName = undefined;
|
|
132
221
|
modelDefinition = undefined;
|
|
133
|
-
|
|
222
|
+
_f.label = 1;
|
|
134
223
|
case 1:
|
|
135
|
-
|
|
136
|
-
return [4 /*yield*/,
|
|
224
|
+
_f.trys.push([1, 4, , 5]);
|
|
225
|
+
return [4 /*yield*/, (0, utils_2.getModelAuthModes)({
|
|
137
226
|
authModeStrategy: this_1.authModeStrategy,
|
|
138
227
|
defaultAuthMode: this_1.amplifyConfig.aws_appsync_authenticationType,
|
|
139
228
|
modelName: model,
|
|
140
229
|
schema: this_1.schema,
|
|
141
230
|
})];
|
|
142
231
|
case 2:
|
|
143
|
-
modelAuthModes =
|
|
232
|
+
modelAuthModes = _f.sent();
|
|
144
233
|
operationAuthModes_1 = modelAuthModes[operation.toUpperCase()];
|
|
145
234
|
authModeAttempts_1 = 0;
|
|
146
|
-
authModeRetry_1 = function () { return
|
|
235
|
+
authModeRetry_1 = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
147
236
|
var response, error_2, e_1;
|
|
148
|
-
return
|
|
237
|
+
return __generator(this, function (_a) {
|
|
149
238
|
switch (_a.label) {
|
|
150
239
|
case 0:
|
|
151
240
|
_a.trys.push([0, 2, , 9]);
|
|
152
|
-
logger.debug("Attempting mutation with authMode: "
|
|
241
|
+
logger.debug("Attempting mutation with authMode: ".concat(operationAuthModes_1[authModeAttempts_1]));
|
|
153
242
|
return [4 /*yield*/, this.jitteredRetry(namespaceName, model, operation, data, condition, modelConstructor, this.MutationEvent, head, operationAuthModes_1[authModeAttempts_1], onTerminate)];
|
|
154
243
|
case 1:
|
|
155
244
|
response = _a.sent();
|
|
156
|
-
logger.debug("Mutation sent successfully with authMode: "
|
|
245
|
+
logger.debug("Mutation sent successfully with authMode: ".concat(operationAuthModes_1[authModeAttempts_1]));
|
|
157
246
|
return [2 /*return*/, response];
|
|
158
247
|
case 2:
|
|
159
248
|
error_2 = _a.sent();
|
|
160
249
|
authModeAttempts_1++;
|
|
161
250
|
if (!(authModeAttempts_1 >= operationAuthModes_1.length)) return [3 /*break*/, 7];
|
|
162
|
-
logger.debug("Mutation failed with authMode: "
|
|
251
|
+
logger.debug("Mutation failed with authMode: ".concat(operationAuthModes_1[authModeAttempts_1 - 1]));
|
|
163
252
|
_a.label = 3;
|
|
164
253
|
case 3:
|
|
165
254
|
_a.trys.push([3, 5, , 6]);
|
|
@@ -169,7 +258,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
169
258
|
message: error_2.message,
|
|
170
259
|
model: modelConstructor.name,
|
|
171
260
|
operation: opName,
|
|
172
|
-
errorType: errorMaps_1.getMutationErrorType(error_2),
|
|
261
|
+
errorType: (0, errorMaps_1.getMutationErrorType)(error_2),
|
|
173
262
|
process: types_1.ProcessName.sync,
|
|
174
263
|
remoteModel: null,
|
|
175
264
|
cause: error_2,
|
|
@@ -183,7 +272,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
183
272
|
return [3 /*break*/, 6];
|
|
184
273
|
case 6: throw error_2;
|
|
185
274
|
case 7:
|
|
186
|
-
logger.debug("Mutation failed with authMode: "
|
|
275
|
+
logger.debug("Mutation failed with authMode: ".concat(operationAuthModes_1[authModeAttempts_1 - 1], ". Retrying with authMode: ").concat(operationAuthModes_1[authModeAttempts_1]));
|
|
187
276
|
return [4 /*yield*/, authModeRetry_1()];
|
|
188
277
|
case 8: return [2 /*return*/, _a.sent()];
|
|
189
278
|
case 9: return [2 /*return*/];
|
|
@@ -192,10 +281,10 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
192
281
|
}); };
|
|
193
282
|
return [4 /*yield*/, authModeRetry_1()];
|
|
194
283
|
case 3:
|
|
195
|
-
|
|
284
|
+
_e = __read.apply(void 0, [_f.sent(), 3]), result = _e[0], opName = _e[1], modelDefinition = _e[2];
|
|
196
285
|
return [3 /*break*/, 5];
|
|
197
286
|
case 4:
|
|
198
|
-
error_1 =
|
|
287
|
+
error_1 = _f.sent();
|
|
199
288
|
if (error_1.message === 'Offline' ||
|
|
200
289
|
error_1.message === 'RetryMutation') {
|
|
201
290
|
return [2 /*return*/, "continue"];
|
|
@@ -204,8 +293,8 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
204
293
|
case 5:
|
|
205
294
|
if (!(result === undefined)) return [3 /*break*/, 7];
|
|
206
295
|
logger.debug('done retrying');
|
|
207
|
-
return [4 /*yield*/, this_1.storage.runExclusive(function (storage) { return
|
|
208
|
-
return
|
|
296
|
+
return [4 /*yield*/, this_1.storage.runExclusive(function (storage) { return __awaiter(_this, void 0, void 0, function () {
|
|
297
|
+
return __generator(this, function (_a) {
|
|
209
298
|
switch (_a.label) {
|
|
210
299
|
case 0: return [4 /*yield*/, this.outbox.dequeue(storage)];
|
|
211
300
|
case 1:
|
|
@@ -215,13 +304,13 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
215
304
|
});
|
|
216
305
|
}); })];
|
|
217
306
|
case 6:
|
|
218
|
-
|
|
307
|
+
_f.sent();
|
|
219
308
|
return [2 /*return*/, "continue"];
|
|
220
309
|
case 7:
|
|
221
310
|
record = result.data[opName];
|
|
222
311
|
hasMore = false;
|
|
223
|
-
return [4 /*yield*/, this_1.storage.runExclusive(function (storage) { return
|
|
224
|
-
return
|
|
312
|
+
return [4 /*yield*/, this_1.storage.runExclusive(function (storage) { return __awaiter(_this, void 0, void 0, function () {
|
|
313
|
+
return __generator(this, function (_a) {
|
|
225
314
|
switch (_a.label) {
|
|
226
315
|
case 0:
|
|
227
316
|
// using runExclusive to prevent possible race condition
|
|
@@ -239,7 +328,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
239
328
|
});
|
|
240
329
|
}); })];
|
|
241
330
|
case 8:
|
|
242
|
-
|
|
331
|
+
_f.sent();
|
|
243
332
|
(_c = (_b = this_1.observer) === null || _b === void 0 ? void 0 : _b.next) === null || _c === void 0 ? void 0 : _c.call(_b, {
|
|
244
333
|
operation: operation,
|
|
245
334
|
modelDefinition: modelDefinition,
|
|
@@ -272,29 +361,30 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
272
361
|
return [2 /*return*/];
|
|
273
362
|
}
|
|
274
363
|
});
|
|
275
|
-
}); }, 'mutation resume loop')
|
|
364
|
+
}); }, 'mutation resume loop')];
|
|
276
365
|
case 1:
|
|
277
366
|
_a.sent();
|
|
278
|
-
|
|
367
|
+
_a.label = 2;
|
|
368
|
+
case 2: return [2 /*return*/];
|
|
279
369
|
}
|
|
280
370
|
});
|
|
281
371
|
});
|
|
282
372
|
};
|
|
283
373
|
MutationProcessor.prototype.jitteredRetry = function (namespaceName, model, operation, data, condition, modelConstructor, MutationEvent, mutationEvent, authMode, onTerminate) {
|
|
284
|
-
return
|
|
374
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
285
375
|
var _this = this;
|
|
286
|
-
return
|
|
376
|
+
return __generator(this, function (_a) {
|
|
287
377
|
switch (_a.label) {
|
|
288
|
-
case 0: return [4 /*yield*/,
|
|
289
|
-
var _a, query, variables, graphQLCondition, opName, modelDefinition, authToken, tryWith, attempt, opType, customUserAgentDetails, result, err_1, _b, error, _c, _d, code, retryWith, err_2,
|
|
290
|
-
var
|
|
291
|
-
return
|
|
292
|
-
switch (
|
|
378
|
+
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 () {
|
|
379
|
+
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;
|
|
380
|
+
var _h;
|
|
381
|
+
return __generator(this, function (_j) {
|
|
382
|
+
switch (_j.label) {
|
|
293
383
|
case 0:
|
|
294
|
-
_a =
|
|
295
|
-
return [4 /*yield*/,
|
|
384
|
+
_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];
|
|
385
|
+
return [4 /*yield*/, (0, utils_2.getTokenForCustomAuth)(authMode, this.amplifyConfig)];
|
|
296
386
|
case 1:
|
|
297
|
-
authToken =
|
|
387
|
+
authToken = _j.sent();
|
|
298
388
|
tryWith = {
|
|
299
389
|
query: query,
|
|
300
390
|
variables: variables,
|
|
@@ -304,31 +394,31 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
304
394
|
attempt = 0;
|
|
305
395
|
opType = this.opTypeFromTransformerOperation(operation);
|
|
306
396
|
customUserAgentDetails = {
|
|
307
|
-
category:
|
|
308
|
-
action:
|
|
397
|
+
category: utils_1.Category.DataStore,
|
|
398
|
+
action: utils_1.DataStoreAction.GraphQl,
|
|
309
399
|
};
|
|
310
|
-
|
|
400
|
+
_j.label = 2;
|
|
311
401
|
case 2:
|
|
312
|
-
|
|
402
|
+
_j.trys.push([2, 4, , 17]);
|
|
313
403
|
return [4 /*yield*/, this.amplifyContext.InternalAPI.graphql(tryWith, undefined, customUserAgentDetails)];
|
|
314
404
|
case 3:
|
|
315
|
-
result = (
|
|
405
|
+
result = (_j.sent());
|
|
316
406
|
// Use `as any` because TypeScript doesn't seem to like passing tuples
|
|
317
407
|
// through generic params.
|
|
318
408
|
return [2 /*return*/, [result, opName, modelDefinition]];
|
|
319
409
|
case 4:
|
|
320
|
-
err_1 =
|
|
410
|
+
err_1 = _j.sent();
|
|
321
411
|
if (!(err_1.errors && err_1.errors.length > 0)) return [3 /*break*/, 15];
|
|
322
|
-
_b =
|
|
323
|
-
_c = error.originalError, _d =
|
|
412
|
+
_b = __read(err_1.errors, 1), error = _b[0];
|
|
413
|
+
_c = error.originalError, _d = _c === void 0 ? {} : _c, _e = _d.code, code = _e === void 0 ? null : _e;
|
|
324
414
|
if (error.errorType === 'Unauthorized') {
|
|
325
|
-
throw new
|
|
415
|
+
throw new utils_1.NonRetryableError('Unauthorized');
|
|
326
416
|
}
|
|
327
417
|
if (error.message === 'Network Error' ||
|
|
328
418
|
code === 'ECONNABORTED' // refers to axios timeout error caused by device's bad network condition
|
|
329
419
|
) {
|
|
330
420
|
if (!this.processing) {
|
|
331
|
-
throw new
|
|
421
|
+
throw new utils_1.NonRetryableError('Offline');
|
|
332
422
|
}
|
|
333
423
|
// TODO: Check errors on different env (react-native or other browsers)
|
|
334
424
|
throw new Error('Network Error');
|
|
@@ -341,7 +431,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
341
431
|
retryWith = types_1.DISCARD;
|
|
342
432
|
return [3 /*break*/, 8];
|
|
343
433
|
case 5:
|
|
344
|
-
|
|
434
|
+
_j.trys.push([5, 7, , 8]);
|
|
345
435
|
return [4 /*yield*/, this.conflictHandler({
|
|
346
436
|
modelConstructor: modelConstructor,
|
|
347
437
|
localModel: this.modelInstanceCreator(modelConstructor, variables.input),
|
|
@@ -350,18 +440,18 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
350
440
|
attempts: attempt,
|
|
351
441
|
})];
|
|
352
442
|
case 6:
|
|
353
|
-
retryWith =
|
|
443
|
+
retryWith = _j.sent();
|
|
354
444
|
return [3 /*break*/, 8];
|
|
355
445
|
case 7:
|
|
356
|
-
err_2 =
|
|
446
|
+
err_2 = _j.sent();
|
|
357
447
|
logger.warn('conflict trycatch', err_2);
|
|
358
448
|
return [3 /*break*/, 17];
|
|
359
449
|
case 8:
|
|
360
450
|
if (!(retryWith === types_1.DISCARD)) return [3 /*break*/, 11];
|
|
361
|
-
|
|
362
|
-
return [4 /*yield*/,
|
|
451
|
+
_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];
|
|
452
|
+
return [4 /*yield*/, (0, utils_2.getTokenForCustomAuth)(authMode, this.amplifyConfig)];
|
|
363
453
|
case 9:
|
|
364
|
-
authToken_1 =
|
|
454
|
+
authToken_1 = _j.sent();
|
|
365
455
|
return [4 /*yield*/, this.amplifyContext.InternalAPI.graphql({
|
|
366
456
|
query: query_1,
|
|
367
457
|
variables: { id: variables.input.id },
|
|
@@ -369,16 +459,16 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
369
459
|
authToken: authToken_1,
|
|
370
460
|
}, undefined, customUserAgentDetails)];
|
|
371
461
|
case 10:
|
|
372
|
-
serverData =
|
|
462
|
+
serverData = _j.sent();
|
|
373
463
|
// onTerminate cancel graphql()
|
|
374
464
|
return [2 /*return*/, [serverData, opName_1, modelDefinition]];
|
|
375
465
|
case 11:
|
|
376
466
|
namespace = this.schema.namespaces[namespaceName];
|
|
377
|
-
updatedMutation =
|
|
467
|
+
updatedMutation = (0, utils_2.createMutationInstanceFromModelOperation)(namespace.relationships, modelDefinition, opType, modelConstructor, retryWith, graphQLCondition, MutationEvent, this.modelInstanceCreator, mutationEvent.id);
|
|
378
468
|
return [4 /*yield*/, this.storage.save(updatedMutation)];
|
|
379
469
|
case 12:
|
|
380
|
-
|
|
381
|
-
throw new
|
|
470
|
+
_j.sent();
|
|
471
|
+
throw new utils_1.NonRetryableError('RetryMutation');
|
|
382
472
|
case 13:
|
|
383
473
|
try {
|
|
384
474
|
this.errorHandler({
|
|
@@ -386,7 +476,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
386
476
|
localModel: variables.input,
|
|
387
477
|
message: error.message,
|
|
388
478
|
operation: operation,
|
|
389
|
-
errorType: errorMaps_1.getMutationErrorType(error),
|
|
479
|
+
errorType: (0, errorMaps_1.getMutationErrorType)(error),
|
|
390
480
|
errorInfo: error.errorInfo,
|
|
391
481
|
process: types_1.ProcessName.mutate,
|
|
392
482
|
cause: error,
|
|
@@ -402,22 +492,22 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
402
492
|
// Return empty tuple, dequeues the mutation
|
|
403
493
|
return [2 /*return*/, error.data
|
|
404
494
|
? [
|
|
405
|
-
{ data: (
|
|
495
|
+
{ data: (_h = {}, _h[opName] = error.data, _h) },
|
|
406
496
|
opName,
|
|
407
497
|
modelDefinition,
|
|
408
498
|
]
|
|
409
499
|
: []];
|
|
410
500
|
}
|
|
411
|
-
|
|
501
|
+
_j.label = 14;
|
|
412
502
|
case 14: return [3 /*break*/, 16];
|
|
413
503
|
case 15:
|
|
414
504
|
// Catch-all for client-side errors that don't come back in the `GraphQLError` format.
|
|
415
505
|
// These errors should not be retried.
|
|
416
|
-
throw new
|
|
506
|
+
throw new utils_1.NonRetryableError(err_1);
|
|
417
507
|
case 16: return [3 /*break*/, 17];
|
|
418
508
|
case 17:
|
|
419
509
|
if (tryWith) return [3 /*break*/, 2];
|
|
420
|
-
|
|
510
|
+
_j.label = 18;
|
|
421
511
|
case 18: return [2 /*return*/];
|
|
422
512
|
}
|
|
423
513
|
});
|
|
@@ -443,16 +533,16 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
443
533
|
var auth = (_d = modelDefinition.attributes) === null || _d === void 0 ? void 0 : _d.find(function (a) { return a.type === 'auth'; });
|
|
444
534
|
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'];
|
|
445
535
|
var queriesTuples = this.typeQuery.get(modelDefinition);
|
|
446
|
-
var _f =
|
|
447
|
-
var _b =
|
|
536
|
+
var _f = __read(queriesTuples.find(function (_a) {
|
|
537
|
+
var _b = __read(_a, 1), transformerMutationType = _b[0];
|
|
448
538
|
return transformerMutationType === operation;
|
|
449
539
|
}), 3), opName = _f[1], query = _f[2];
|
|
450
|
-
var _g = JSON.parse(data), _version = _g._version, parsedData =
|
|
540
|
+
var _g = JSON.parse(data), _version = _g._version, parsedData = __rest(_g, ["_version"]);
|
|
451
541
|
// include all the fields that comprise a custom PK if one is specified
|
|
452
542
|
var deleteInput = {};
|
|
453
|
-
if (primaryKey
|
|
543
|
+
if (primaryKey && primaryKey.length) {
|
|
454
544
|
try {
|
|
455
|
-
for (var primaryKey_1 =
|
|
545
|
+
for (var primaryKey_1 = __values(primaryKey), primaryKey_1_1 = primaryKey_1.next(); !primaryKey_1_1.done; primaryKey_1_1 = primaryKey_1.next()) {
|
|
456
546
|
var pkField = primaryKey_1_1.value;
|
|
457
547
|
deleteInput[pkField] = parsedData[pkField];
|
|
458
548
|
}
|
|
@@ -469,7 +559,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
469
559
|
deleteInput[util_1.ID] = parsedData.id;
|
|
470
560
|
}
|
|
471
561
|
var mutationInput;
|
|
472
|
-
if (operation ===
|
|
562
|
+
if (operation === utils_2.TransformerMutationType.DELETE) {
|
|
473
563
|
// For DELETE mutations, only the key(s) are included in the input
|
|
474
564
|
mutationInput = deleteInput;
|
|
475
565
|
}
|
|
@@ -478,7 +568,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
478
568
|
mutationInput = {};
|
|
479
569
|
var modelFields = Object.values(modelDefinition.fields);
|
|
480
570
|
try {
|
|
481
|
-
for (var modelFields_1 =
|
|
571
|
+
for (var modelFields_1 = __values(modelFields), modelFields_1_1 = modelFields_1.next(); !modelFields_1_1.done; modelFields_1_1 = modelFields_1.next()) {
|
|
482
572
|
var _h = modelFields_1_1.value, name_1 = _h.name, type = _h.type, association = _h.association, isReadOnly = _h.isReadOnly;
|
|
483
573
|
// omit readonly fields. cloud storage doesn't need them and won't take them!
|
|
484
574
|
if (isReadOnly) {
|
|
@@ -489,15 +579,15 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
489
579
|
continue;
|
|
490
580
|
}
|
|
491
581
|
// model fields should be stripped out from the input
|
|
492
|
-
if (types_1.isModelFieldType(type)) {
|
|
582
|
+
if ((0, types_1.isModelFieldType)(type)) {
|
|
493
583
|
// except for belongs to relations - we need to replace them with the correct foreign key(s)
|
|
494
|
-
if (types_1.isTargetNameAssociation(association) &&
|
|
584
|
+
if ((0, types_1.isTargetNameAssociation)(association) &&
|
|
495
585
|
association.connectionType === 'BELONGS_TO') {
|
|
496
|
-
var targetNames = util_1.extractTargetNamesFromSrc(association);
|
|
586
|
+
var targetNames = (0, util_1.extractTargetNamesFromSrc)(association);
|
|
497
587
|
if (targetNames) {
|
|
498
588
|
try {
|
|
499
589
|
// instead of including the connected model itself, we add its key(s) to the mutation input
|
|
500
|
-
for (var targetNames_1 = (e_4 = void 0,
|
|
590
|
+
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()) {
|
|
501
591
|
var targetName = targetNames_1_1.value;
|
|
502
592
|
mutationInput[targetName] = parsedData[targetName];
|
|
503
593
|
}
|
|
@@ -514,7 +604,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
514
604
|
continue;
|
|
515
605
|
}
|
|
516
606
|
// scalar fields / non-model types
|
|
517
|
-
if (operation ===
|
|
607
|
+
if (operation === utils_2.TransformerMutationType.UPDATE) {
|
|
518
608
|
if (!parsedData.hasOwnProperty(name_1)) {
|
|
519
609
|
// for update mutations - strip out a field if it's unchanged
|
|
520
610
|
continue;
|
|
@@ -533,9 +623,9 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
533
623
|
}
|
|
534
624
|
}
|
|
535
625
|
// Build mutation variables input object
|
|
536
|
-
var input =
|
|
626
|
+
var input = __assign(__assign({}, mutationInput), { _version: _version });
|
|
537
627
|
var graphQLCondition = JSON.parse(condition);
|
|
538
|
-
var variables =
|
|
628
|
+
var variables = __assign({ input: input }, (operation === utils_2.TransformerMutationType.CREATE
|
|
539
629
|
? {}
|
|
540
630
|
: {
|
|
541
631
|
condition: Object.keys(graphQLCondition).length > 0
|
|
@@ -546,16 +636,16 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
546
636
|
};
|
|
547
637
|
MutationProcessor.prototype.opTypeFromTransformerOperation = function (operation) {
|
|
548
638
|
switch (operation) {
|
|
549
|
-
case
|
|
639
|
+
case utils_2.TransformerMutationType.CREATE:
|
|
550
640
|
return types_1.OpType.INSERT;
|
|
551
|
-
case
|
|
641
|
+
case utils_2.TransformerMutationType.DELETE:
|
|
552
642
|
return types_1.OpType.DELETE;
|
|
553
|
-
case
|
|
643
|
+
case utils_2.TransformerMutationType.UPDATE:
|
|
554
644
|
return types_1.OpType.UPDATE;
|
|
555
|
-
case
|
|
645
|
+
case utils_2.TransformerMutationType.GET: // Intentionally blank
|
|
556
646
|
break;
|
|
557
647
|
default:
|
|
558
|
-
throw new Error("Invalid operation "
|
|
648
|
+
throw new Error("Invalid operation ".concat(operation));
|
|
559
649
|
}
|
|
560
650
|
// because it makes TS happy ...
|
|
561
651
|
return undefined;
|
|
@@ -567,7 +657,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
567
657
|
}());
|
|
568
658
|
exports.MutationProcessor = MutationProcessor;
|
|
569
659
|
var MAX_RETRY_DELAY_MS = 5 * 60 * 1000;
|
|
570
|
-
var originalJitteredBackoff =
|
|
660
|
+
var originalJitteredBackoff = (0, utils_1.jitteredBackoff)(MAX_RETRY_DELAY_MS);
|
|
571
661
|
/**
|
|
572
662
|
* @private
|
|
573
663
|
* Internal use of Amplify only.
|
|
@@ -583,12 +673,13 @@ var originalJitteredBackoff = core_1.jitteredBackoff(MAX_RETRY_DELAY_MS);
|
|
|
583
673
|
* @param error tested to see if `.message` is 'Network Error'
|
|
584
674
|
* @returns number | false :
|
|
585
675
|
*/
|
|
586
|
-
|
|
676
|
+
var safeJitteredBackoff = function (attempt, _args, error) {
|
|
587
677
|
var attemptResult = originalJitteredBackoff(attempt);
|
|
588
678
|
// If this is the last attempt and it is a network error, we retry indefinitively every 5 minutes
|
|
589
|
-
if (attemptResult === false &&
|
|
679
|
+
if (attemptResult === false &&
|
|
680
|
+
(error || {}).message === 'Network Error') {
|
|
590
681
|
return MAX_RETRY_DELAY_MS;
|
|
591
682
|
}
|
|
592
683
|
return attemptResult;
|
|
593
684
|
};
|
|
594
|
-
|
|
685
|
+
exports.safeJitteredBackoff = safeJitteredBackoff;
|
|
@@ -24,7 +24,10 @@ declare class SubscriptionProcessor {
|
|
|
24
24
|
private buildSubscription;
|
|
25
25
|
private getAuthorizationInfo;
|
|
26
26
|
private hubQueryCompletionListener;
|
|
27
|
-
start(): [
|
|
27
|
+
start(): [
|
|
28
|
+
Observable<CONTROL_MSG>,
|
|
29
|
+
Observable<[TransformerMutationType, SchemaModel, PersistentModel]>
|
|
30
|
+
];
|
|
28
31
|
stop(): Promise<void>;
|
|
29
32
|
private passesPredicateValidation;
|
|
30
33
|
private pushToBuffer;
|