@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,4 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
+
if (ar || !(i in from)) {
|
|
20
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
+
ar[i] = from[i];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
+
};
|
|
26
|
+
var __values = (this && this.__values) || function(o) {
|
|
27
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
28
|
+
if (m) return m.call(o);
|
|
29
|
+
if (o && typeof o.length === "number") return {
|
|
30
|
+
next: function () {
|
|
31
|
+
if (o && i >= o.length) o = void 0;
|
|
32
|
+
return { value: o && o[i++], done: !o };
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
36
|
+
};
|
|
2
37
|
var connectionTimeout = function (error) {
|
|
3
38
|
return /^Connection failed: Connection Timeout/.test(error.message);
|
|
4
39
|
};
|
|
@@ -46,9 +81,9 @@ export var syncErrorMap = {
|
|
|
46
81
|
* @param observableError an error from ZenObservable subscribe error callback
|
|
47
82
|
*/
|
|
48
83
|
function unwrapObservableError(observableError) {
|
|
49
|
-
var _a = observableError.error, _b =
|
|
84
|
+
var _a = observableError.error, _b = _a === void 0 ? {
|
|
50
85
|
errors: [],
|
|
51
|
-
} : _a
|
|
86
|
+
} : _a, _c = __read(_b.errors, 1), error = _c[0];
|
|
52
87
|
return error;
|
|
53
88
|
}
|
|
54
89
|
export function getMutationErrorType(error) {
|
|
@@ -68,7 +103,7 @@ export function getSyncErrorType(error) {
|
|
|
68
103
|
*/
|
|
69
104
|
export function mapErrorToType(errorMap, error) {
|
|
70
105
|
var e_1, _a;
|
|
71
|
-
var errorTypes =
|
|
106
|
+
var errorTypes = __spreadArray([], __read(Object.keys(errorMap)), false);
|
|
72
107
|
try {
|
|
73
108
|
for (var errorTypes_1 = __values(errorTypes), errorTypes_1_1 = errorTypes_1.next(); !errorTypes_1_1.done; errorTypes_1_1 = errorTypes_1.next()) {
|
|
74
109
|
var errorType = errorTypes_1_1.value;
|
|
@@ -87,4 +122,3 @@ export function mapErrorToType(errorMap, error) {
|
|
|
87
122
|
}
|
|
88
123
|
return 'Unknown';
|
|
89
124
|
}
|
|
90
|
-
//# sourceMappingURL=errorMaps.js.map
|
|
@@ -5,7 +5,7 @@ import { ExclusiveStorage as Storage } from '../../storage/storage';
|
|
|
5
5
|
import { AuthModeStrategy, ConflictHandler, ErrorHandler, InternalSchema, PersistentModel, PersistentModelConstructor, SchemaModel, TypeConstructorMap, AmplifyContext } from '../../types';
|
|
6
6
|
import { MutationEventOutbox } from '../outbox';
|
|
7
7
|
import { TransformerMutationType } from '../utils';
|
|
8
|
-
|
|
8
|
+
type MutationProcessorEvent = {
|
|
9
9
|
operation: TransformerMutationType;
|
|
10
10
|
modelDefinition: SchemaModel;
|
|
11
11
|
model: PersistentModel;
|
|
@@ -1,6 +1,90 @@
|
|
|
1
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
49
|
+
var t = {};
|
|
50
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
51
|
+
t[p] = s[p];
|
|
52
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
53
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
54
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
55
|
+
t[p[i]] = s[p[i]];
|
|
56
|
+
}
|
|
57
|
+
return t;
|
|
58
|
+
};
|
|
59
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
60
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
61
|
+
if (!m) return o;
|
|
62
|
+
var i = m.call(o), r, ar = [], e;
|
|
63
|
+
try {
|
|
64
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
65
|
+
}
|
|
66
|
+
catch (error) { e = { error: error }; }
|
|
67
|
+
finally {
|
|
68
|
+
try {
|
|
69
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
70
|
+
}
|
|
71
|
+
finally { if (e) throw e.error; }
|
|
72
|
+
}
|
|
73
|
+
return ar;
|
|
74
|
+
};
|
|
75
|
+
var __values = (this && this.__values) || function(o) {
|
|
76
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
77
|
+
if (m) return m.call(o);
|
|
78
|
+
if (o && typeof o.length === "number") return {
|
|
79
|
+
next: function () {
|
|
80
|
+
if (o && i >= o.length) o = void 0;
|
|
81
|
+
return { value: o && o[i++], done: !o };
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
85
|
+
};
|
|
2
86
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
3
|
-
import { Category,
|
|
87
|
+
import { Category, Logger, DataStoreAction, jitteredBackoff, NonRetryableError, retry, BackgroundProcessManager, } from '@aws-amplify/core/internals/utils';
|
|
4
88
|
import Observable from 'zen-observable-ts';
|
|
5
89
|
import { DISCARD, isModelFieldType, isTargetNameAssociation, OpType, ProcessName, } from '../../types';
|
|
6
90
|
import { extractTargetNamesFromSrc, USER, ID } from '../../util';
|
|
@@ -102,8 +186,9 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
102
186
|
var _this = this;
|
|
103
187
|
return __generator(this, function (_a) {
|
|
104
188
|
switch (_a.label) {
|
|
105
|
-
case 0:
|
|
106
|
-
|
|
189
|
+
case 0:
|
|
190
|
+
if (!this.runningProcesses.isOpen) return [3 /*break*/, 2];
|
|
191
|
+
return [4 /*yield*/, this.runningProcesses.add(function (onTerminate) { return __awaiter(_this, void 0, void 0, function () {
|
|
107
192
|
var head, namespaceName, _loop_1, this_1, _a;
|
|
108
193
|
var _this = this;
|
|
109
194
|
var _b, _c;
|
|
@@ -119,18 +204,18 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
119
204
|
namespaceName = USER;
|
|
120
205
|
_loop_1 = function () {
|
|
121
206
|
var model, operation, data, condition, modelConstructor, result, opName, modelDefinition, modelAuthModes, operationAuthModes_1, authModeAttempts_1, authModeRetry_1, error_1, record, hasMore;
|
|
122
|
-
var
|
|
123
|
-
return __generator(this, function (
|
|
124
|
-
switch (
|
|
207
|
+
var _e;
|
|
208
|
+
return __generator(this, function (_f) {
|
|
209
|
+
switch (_f.label) {
|
|
125
210
|
case 0:
|
|
126
211
|
model = head.model, operation = head.operation, data = head.data, condition = head.condition;
|
|
127
212
|
modelConstructor = this_1.userClasses[model];
|
|
128
213
|
result = undefined;
|
|
129
214
|
opName = undefined;
|
|
130
215
|
modelDefinition = undefined;
|
|
131
|
-
|
|
216
|
+
_f.label = 1;
|
|
132
217
|
case 1:
|
|
133
|
-
|
|
218
|
+
_f.trys.push([1, 4, , 5]);
|
|
134
219
|
return [4 /*yield*/, getModelAuthModes({
|
|
135
220
|
authModeStrategy: this_1.authModeStrategy,
|
|
136
221
|
defaultAuthMode: this_1.amplifyConfig.aws_appsync_authenticationType,
|
|
@@ -138,7 +223,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
138
223
|
schema: this_1.schema,
|
|
139
224
|
})];
|
|
140
225
|
case 2:
|
|
141
|
-
modelAuthModes =
|
|
226
|
+
modelAuthModes = _f.sent();
|
|
142
227
|
operationAuthModes_1 = modelAuthModes[operation.toUpperCase()];
|
|
143
228
|
authModeAttempts_1 = 0;
|
|
144
229
|
authModeRetry_1 = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -147,17 +232,17 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
147
232
|
switch (_a.label) {
|
|
148
233
|
case 0:
|
|
149
234
|
_a.trys.push([0, 2, , 9]);
|
|
150
|
-
logger.debug("Attempting mutation with authMode: "
|
|
235
|
+
logger.debug("Attempting mutation with authMode: ".concat(operationAuthModes_1[authModeAttempts_1]));
|
|
151
236
|
return [4 /*yield*/, this.jitteredRetry(namespaceName, model, operation, data, condition, modelConstructor, this.MutationEvent, head, operationAuthModes_1[authModeAttempts_1], onTerminate)];
|
|
152
237
|
case 1:
|
|
153
238
|
response = _a.sent();
|
|
154
|
-
logger.debug("Mutation sent successfully with authMode: "
|
|
239
|
+
logger.debug("Mutation sent successfully with authMode: ".concat(operationAuthModes_1[authModeAttempts_1]));
|
|
155
240
|
return [2 /*return*/, response];
|
|
156
241
|
case 2:
|
|
157
242
|
error_2 = _a.sent();
|
|
158
243
|
authModeAttempts_1++;
|
|
159
244
|
if (!(authModeAttempts_1 >= operationAuthModes_1.length)) return [3 /*break*/, 7];
|
|
160
|
-
logger.debug("Mutation failed with authMode: "
|
|
245
|
+
logger.debug("Mutation failed with authMode: ".concat(operationAuthModes_1[authModeAttempts_1 - 1]));
|
|
161
246
|
_a.label = 3;
|
|
162
247
|
case 3:
|
|
163
248
|
_a.trys.push([3, 5, , 6]);
|
|
@@ -181,7 +266,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
181
266
|
return [3 /*break*/, 6];
|
|
182
267
|
case 6: throw error_2;
|
|
183
268
|
case 7:
|
|
184
|
-
logger.debug("Mutation failed with authMode: "
|
|
269
|
+
logger.debug("Mutation failed with authMode: ".concat(operationAuthModes_1[authModeAttempts_1 - 1], ". Retrying with authMode: ").concat(operationAuthModes_1[authModeAttempts_1]));
|
|
185
270
|
return [4 /*yield*/, authModeRetry_1()];
|
|
186
271
|
case 8: return [2 /*return*/, _a.sent()];
|
|
187
272
|
case 9: return [2 /*return*/];
|
|
@@ -190,10 +275,10 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
190
275
|
}); };
|
|
191
276
|
return [4 /*yield*/, authModeRetry_1()];
|
|
192
277
|
case 3:
|
|
193
|
-
|
|
278
|
+
_e = __read.apply(void 0, [_f.sent(), 3]), result = _e[0], opName = _e[1], modelDefinition = _e[2];
|
|
194
279
|
return [3 /*break*/, 5];
|
|
195
280
|
case 4:
|
|
196
|
-
error_1 =
|
|
281
|
+
error_1 = _f.sent();
|
|
197
282
|
if (error_1.message === 'Offline' ||
|
|
198
283
|
error_1.message === 'RetryMutation') {
|
|
199
284
|
return [2 /*return*/, "continue"];
|
|
@@ -213,7 +298,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
213
298
|
});
|
|
214
299
|
}); })];
|
|
215
300
|
case 6:
|
|
216
|
-
|
|
301
|
+
_f.sent();
|
|
217
302
|
return [2 /*return*/, "continue"];
|
|
218
303
|
case 7:
|
|
219
304
|
record = result.data[opName];
|
|
@@ -237,7 +322,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
237
322
|
});
|
|
238
323
|
}); })];
|
|
239
324
|
case 8:
|
|
240
|
-
|
|
325
|
+
_f.sent();
|
|
241
326
|
(_c = (_b = this_1.observer) === null || _b === void 0 ? void 0 : _b.next) === null || _c === void 0 ? void 0 : _c.call(_b, {
|
|
242
327
|
operation: operation,
|
|
243
328
|
modelDefinition: modelDefinition,
|
|
@@ -270,10 +355,11 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
270
355
|
return [2 /*return*/];
|
|
271
356
|
}
|
|
272
357
|
});
|
|
273
|
-
}); }, 'mutation resume loop')
|
|
358
|
+
}); }, 'mutation resume loop')];
|
|
274
359
|
case 1:
|
|
275
360
|
_a.sent();
|
|
276
|
-
|
|
361
|
+
_a.label = 2;
|
|
362
|
+
case 2: return [2 /*return*/];
|
|
277
363
|
}
|
|
278
364
|
});
|
|
279
365
|
});
|
|
@@ -284,15 +370,15 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
284
370
|
return __generator(this, function (_a) {
|
|
285
371
|
switch (_a.label) {
|
|
286
372
|
case 0: return [4 /*yield*/, retry(function (model, operation, data, condition, modelConstructor, MutationEvent, mutationEvent) { return __awaiter(_this, void 0, void 0, function () {
|
|
287
|
-
var _a, query, variables, graphQLCondition, opName, modelDefinition, authToken, tryWith, attempt, opType, customUserAgentDetails, result, err_1, _b, error, _c, _d, code, retryWith, err_2,
|
|
288
|
-
var
|
|
289
|
-
return __generator(this, function (
|
|
290
|
-
switch (
|
|
373
|
+
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;
|
|
374
|
+
var _h;
|
|
375
|
+
return __generator(this, function (_j) {
|
|
376
|
+
switch (_j.label) {
|
|
291
377
|
case 0:
|
|
292
378
|
_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];
|
|
293
379
|
return [4 /*yield*/, getTokenForCustomAuth(authMode, this.amplifyConfig)];
|
|
294
380
|
case 1:
|
|
295
|
-
authToken =
|
|
381
|
+
authToken = _j.sent();
|
|
296
382
|
tryWith = {
|
|
297
383
|
query: query,
|
|
298
384
|
variables: variables,
|
|
@@ -305,20 +391,20 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
305
391
|
category: Category.DataStore,
|
|
306
392
|
action: DataStoreAction.GraphQl,
|
|
307
393
|
};
|
|
308
|
-
|
|
394
|
+
_j.label = 2;
|
|
309
395
|
case 2:
|
|
310
|
-
|
|
396
|
+
_j.trys.push([2, 4, , 17]);
|
|
311
397
|
return [4 /*yield*/, this.amplifyContext.InternalAPI.graphql(tryWith, undefined, customUserAgentDetails)];
|
|
312
398
|
case 3:
|
|
313
|
-
result = (
|
|
399
|
+
result = (_j.sent());
|
|
314
400
|
// Use `as any` because TypeScript doesn't seem to like passing tuples
|
|
315
401
|
// through generic params.
|
|
316
402
|
return [2 /*return*/, [result, opName, modelDefinition]];
|
|
317
403
|
case 4:
|
|
318
|
-
err_1 =
|
|
404
|
+
err_1 = _j.sent();
|
|
319
405
|
if (!(err_1.errors && err_1.errors.length > 0)) return [3 /*break*/, 15];
|
|
320
406
|
_b = __read(err_1.errors, 1), error = _b[0];
|
|
321
|
-
_c = error.originalError, _d =
|
|
407
|
+
_c = error.originalError, _d = _c === void 0 ? {} : _c, _e = _d.code, code = _e === void 0 ? null : _e;
|
|
322
408
|
if (error.errorType === 'Unauthorized') {
|
|
323
409
|
throw new NonRetryableError('Unauthorized');
|
|
324
410
|
}
|
|
@@ -339,7 +425,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
339
425
|
retryWith = DISCARD;
|
|
340
426
|
return [3 /*break*/, 8];
|
|
341
427
|
case 5:
|
|
342
|
-
|
|
428
|
+
_j.trys.push([5, 7, , 8]);
|
|
343
429
|
return [4 /*yield*/, this.conflictHandler({
|
|
344
430
|
modelConstructor: modelConstructor,
|
|
345
431
|
localModel: this.modelInstanceCreator(modelConstructor, variables.input),
|
|
@@ -348,18 +434,18 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
348
434
|
attempts: attempt,
|
|
349
435
|
})];
|
|
350
436
|
case 6:
|
|
351
|
-
retryWith =
|
|
437
|
+
retryWith = _j.sent();
|
|
352
438
|
return [3 /*break*/, 8];
|
|
353
439
|
case 7:
|
|
354
|
-
err_2 =
|
|
440
|
+
err_2 = _j.sent();
|
|
355
441
|
logger.warn('conflict trycatch', err_2);
|
|
356
442
|
return [3 /*break*/, 17];
|
|
357
443
|
case 8:
|
|
358
444
|
if (!(retryWith === DISCARD)) return [3 /*break*/, 11];
|
|
359
|
-
|
|
445
|
+
_f = __read(buildGraphQLOperation(this.schema.namespaces[namespaceName], modelDefinition, 'GET'), 1), _g = __read(_f[0], 3), opName_1 = _g[1], query_1 = _g[2];
|
|
360
446
|
return [4 /*yield*/, getTokenForCustomAuth(authMode, this.amplifyConfig)];
|
|
361
447
|
case 9:
|
|
362
|
-
authToken_1 =
|
|
448
|
+
authToken_1 = _j.sent();
|
|
363
449
|
return [4 /*yield*/, this.amplifyContext.InternalAPI.graphql({
|
|
364
450
|
query: query_1,
|
|
365
451
|
variables: { id: variables.input.id },
|
|
@@ -367,7 +453,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
367
453
|
authToken: authToken_1,
|
|
368
454
|
}, undefined, customUserAgentDetails)];
|
|
369
455
|
case 10:
|
|
370
|
-
serverData =
|
|
456
|
+
serverData = _j.sent();
|
|
371
457
|
// onTerminate cancel graphql()
|
|
372
458
|
return [2 /*return*/, [serverData, opName_1, modelDefinition]];
|
|
373
459
|
case 11:
|
|
@@ -375,7 +461,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
375
461
|
updatedMutation = createMutationInstanceFromModelOperation(namespace.relationships, modelDefinition, opType, modelConstructor, retryWith, graphQLCondition, MutationEvent, this.modelInstanceCreator, mutationEvent.id);
|
|
376
462
|
return [4 /*yield*/, this.storage.save(updatedMutation)];
|
|
377
463
|
case 12:
|
|
378
|
-
|
|
464
|
+
_j.sent();
|
|
379
465
|
throw new NonRetryableError('RetryMutation');
|
|
380
466
|
case 13:
|
|
381
467
|
try {
|
|
@@ -400,13 +486,13 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
400
486
|
// Return empty tuple, dequeues the mutation
|
|
401
487
|
return [2 /*return*/, error.data
|
|
402
488
|
? [
|
|
403
|
-
{ data: (
|
|
489
|
+
{ data: (_h = {}, _h[opName] = error.data, _h) },
|
|
404
490
|
opName,
|
|
405
491
|
modelDefinition,
|
|
406
492
|
]
|
|
407
493
|
: []];
|
|
408
494
|
}
|
|
409
|
-
|
|
495
|
+
_j.label = 14;
|
|
410
496
|
case 14: return [3 /*break*/, 16];
|
|
411
497
|
case 15:
|
|
412
498
|
// Catch-all for client-side errors that don't come back in the `GraphQLError` format.
|
|
@@ -415,7 +501,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
415
501
|
case 16: return [3 /*break*/, 17];
|
|
416
502
|
case 17:
|
|
417
503
|
if (tryWith) return [3 /*break*/, 2];
|
|
418
|
-
|
|
504
|
+
_j.label = 18;
|
|
419
505
|
case 18: return [2 /*return*/];
|
|
420
506
|
}
|
|
421
507
|
});
|
|
@@ -448,7 +534,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
448
534
|
var _g = JSON.parse(data), _version = _g._version, parsedData = __rest(_g, ["_version"]);
|
|
449
535
|
// include all the fields that comprise a custom PK if one is specified
|
|
450
536
|
var deleteInput = {};
|
|
451
|
-
if (primaryKey
|
|
537
|
+
if (primaryKey && primaryKey.length) {
|
|
452
538
|
try {
|
|
453
539
|
for (var primaryKey_1 = __values(primaryKey), primaryKey_1_1 = primaryKey_1.next(); !primaryKey_1_1.done; primaryKey_1_1 = primaryKey_1.next()) {
|
|
454
540
|
var pkField = primaryKey_1_1.value;
|
|
@@ -553,7 +639,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
553
639
|
case TransformerMutationType.GET: // Intentionally blank
|
|
554
640
|
break;
|
|
555
641
|
default:
|
|
556
|
-
throw new Error("Invalid operation "
|
|
642
|
+
throw new Error("Invalid operation ".concat(operation));
|
|
557
643
|
}
|
|
558
644
|
// because it makes TS happy ...
|
|
559
645
|
return undefined;
|
|
@@ -583,10 +669,10 @@ var originalJitteredBackoff = jitteredBackoff(MAX_RETRY_DELAY_MS);
|
|
|
583
669
|
export var safeJitteredBackoff = function (attempt, _args, error) {
|
|
584
670
|
var attemptResult = originalJitteredBackoff(attempt);
|
|
585
671
|
// If this is the last attempt and it is a network error, we retry indefinitively every 5 minutes
|
|
586
|
-
if (attemptResult === false &&
|
|
672
|
+
if (attemptResult === false &&
|
|
673
|
+
(error || {}).message === 'Network Error') {
|
|
587
674
|
return MAX_RETRY_DELAY_MS;
|
|
588
675
|
}
|
|
589
676
|
return attemptResult;
|
|
590
677
|
};
|
|
591
678
|
export { MutationProcessor };
|
|
592
|
-
//# sourceMappingURL=mutation.js.map
|
|
@@ -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;
|