@aws-amplify/datastore 3.12.6-next.20 → 3.12.6-next.36
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/CHANGELOG.md +58 -0
- package/lib/authModeStrategies/multiAuthStrategy.d.ts +11 -0
- package/lib/authModeStrategies/multiAuthStrategy.js +13 -2
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.d.ts +107 -17
- package/lib/datastore/datastore.js +648 -344
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/index.d.ts +3 -19
- package/lib/predicates/index.d.ts +3 -2
- package/lib/predicates/index.js +12 -2
- package/lib/predicates/index.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +4 -3
- package/lib/storage/adapter/AsyncStorageAdapter.js +354 -203
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.d.ts +14 -4
- package/lib/storage/adapter/AsyncStorageDatabase.js +65 -28
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.d.ts +26 -4
- package/lib/storage/adapter/IndexedDBAdapter.js +444 -271
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/adapter/index.d.ts +1 -1
- package/lib/storage/storage.d.ts +1 -1
- package/lib/storage/storage.js +93 -28
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.d.ts +1 -0
- package/lib/sync/datastoreConnectivity.js +9 -0
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/index.d.ts +31 -5
- package/lib/sync/index.js +522 -397
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.d.ts +9 -3
- package/lib/sync/merger.js +13 -6
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.d.ts +2 -2
- package/lib/sync/outbox.js +77 -71
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/mutation.d.ts +2 -0
- package/lib/sync/processors/mutation.js +269 -209
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.d.ts +2 -0
- package/lib/sync/processors/subscription.js +213 -178
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.d.ts +2 -1
- package/lib/sync/processors/sync.js +126 -121
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.d.ts +3 -2
- package/lib/sync/utils.js +43 -8
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.d.ts +65 -26
- package/lib/types.js +10 -1
- package/lib/types.js.map +1 -1
- package/lib/util.d.ts +67 -24
- package/lib/util.js +419 -166
- package/lib/util.js.map +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.d.ts +11 -0
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +12 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +107 -17
- package/lib-esm/datastore/datastore.js +648 -344
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/index.d.ts +3 -19
- package/lib-esm/predicates/index.d.ts +3 -2
- package/lib-esm/predicates/index.js +13 -3
- package/lib-esm/predicates/index.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.d.ts +4 -3
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +355 -204
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.d.ts +14 -4
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +66 -29
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +26 -4
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +445 -272
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/index.d.ts +1 -1
- package/lib-esm/storage/storage.d.ts +1 -1
- package/lib-esm/storage/storage.js +93 -28
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -0
- package/lib-esm/sync/datastoreConnectivity.js +10 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
- package/lib-esm/sync/index.d.ts +31 -5
- package/lib-esm/sync/index.js +524 -399
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.d.ts +9 -3
- package/lib-esm/sync/merger.js +13 -6
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.d.ts +2 -2
- package/lib-esm/sync/outbox.js +78 -72
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/mutation.d.ts +2 -0
- package/lib-esm/sync/processors/mutation.js +270 -210
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.d.ts +2 -0
- package/lib-esm/sync/processors/subscription.js +213 -178
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.d.ts +2 -1
- package/lib-esm/sync/processors/sync.js +126 -121
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.d.ts +3 -2
- package/lib-esm/sync/utils.js +45 -11
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +65 -26
- package/lib-esm/types.js +9 -2
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +67 -24
- package/lib-esm/util.js +419 -166
- package/lib-esm/util.js.map +1 -1
- package/package.json +16 -9
- package/src/authModeStrategies/multiAuthStrategy.ts +12 -1
- package/src/datastore/datastore.ts +798 -397
- package/src/predicates/index.ts +32 -10
- package/src/storage/adapter/AsyncStorageAdapter.ts +309 -93
- package/src/storage/adapter/AsyncStorageDatabase.ts +74 -26
- package/src/storage/adapter/IndexedDBAdapter.ts +358 -134
- package/src/storage/adapter/index.ts +1 -1
- package/src/storage/storage.ts +69 -22
- package/src/sync/datastoreConnectivity.ts +6 -0
- package/src/sync/index.ts +521 -412
- package/src/sync/merger.ts +20 -4
- package/src/sync/outbox.ts +22 -9
- package/src/sync/processors/mutation.ts +188 -150
- package/src/sync/processors/subscription.ts +289 -253
- package/src/sync/processors/sync.ts +151 -138
- package/src/sync/utils.ts +67 -12
- package/src/types.ts +182 -30
- package/src/util.ts +505 -176
- package/build.js +0 -5
- package/dist/aws-amplify-datastore.js +0 -83311
- package/dist/aws-amplify-datastore.js.map +0 -1
- package/dist/aws-amplify-datastore.min.js +0 -168
- package/dist/aws-amplify-datastore.min.js.map +0 -1
- package/index.js +0 -7
- package/webpack.config.dev.js +0 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
-
var api_1 =
|
|
4
|
+
var api_1 = require("@aws-amplify/api");
|
|
5
5
|
var core_1 = require("@aws-amplify/core");
|
|
6
6
|
var zen_observable_ts_1 = tslib_1.__importDefault(require("zen-observable-ts"));
|
|
7
7
|
var types_1 = require("../../types");
|
|
@@ -26,7 +26,8 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
26
26
|
this.amplifyContext = amplifyContext;
|
|
27
27
|
this.typeQuery = new WeakMap();
|
|
28
28
|
this.processing = false;
|
|
29
|
-
this.
|
|
29
|
+
this.runningProcesses = new core_1.BackgroundProcessManager();
|
|
30
|
+
this.amplifyContext.API = this.amplifyContext.API || api_1.API;
|
|
30
31
|
this.generateQueries();
|
|
31
32
|
}
|
|
32
33
|
MutationProcessor.prototype.generateQueries = function () {
|
|
@@ -56,164 +57,203 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
56
57
|
var _this = this;
|
|
57
58
|
var observable = new zen_observable_ts_1.default(function (observer) {
|
|
58
59
|
_this.observer = observer;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
try {
|
|
61
|
+
_this.resume();
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
logger.error('mutations processor start error', error);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
return _this.runningProcesses.addCleaner(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
68
|
+
return tslib_1.__generator(this, function (_a) {
|
|
69
|
+
this.pause();
|
|
70
|
+
return [2 /*return*/];
|
|
71
|
+
});
|
|
72
|
+
}); });
|
|
63
73
|
});
|
|
64
74
|
return observable;
|
|
65
75
|
};
|
|
76
|
+
MutationProcessor.prototype.stop = function () {
|
|
77
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
78
|
+
return tslib_1.__generator(this, function (_a) {
|
|
79
|
+
switch (_a.label) {
|
|
80
|
+
case 0: return [4 /*yield*/, this.runningProcesses.close()];
|
|
81
|
+
case 1:
|
|
82
|
+
_a.sent();
|
|
83
|
+
return [4 /*yield*/, this.runningProcesses.open()];
|
|
84
|
+
case 2:
|
|
85
|
+
_a.sent();
|
|
86
|
+
return [2 /*return*/];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
66
91
|
MutationProcessor.prototype.resume = function () {
|
|
67
92
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
68
|
-
var head, namespaceName, _loop_1, this_1, _a;
|
|
69
93
|
var _this = this;
|
|
70
|
-
return tslib_1.__generator(this, function (
|
|
71
|
-
switch (
|
|
72
|
-
case 0:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
case 2:
|
|
99
|
-
modelAuthModes = _b.sent();
|
|
100
|
-
operationAuthModes_1 = modelAuthModes[operation.toUpperCase()];
|
|
101
|
-
authModeAttempts_1 = 0;
|
|
102
|
-
authModeRetry_1 = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
103
|
-
var response, error_2;
|
|
104
|
-
return tslib_1.__generator(this, function (_a) {
|
|
105
|
-
switch (_a.label) {
|
|
106
|
-
case 0:
|
|
107
|
-
_a.trys.push([0, 2, , 4]);
|
|
108
|
-
logger.debug("Attempting mutation with authMode: " + operationAuthModes_1[authModeAttempts_1]);
|
|
109
|
-
return [4 /*yield*/, this.jitteredRetry(namespaceName, model, operation, data, condition, modelConstructor, this.MutationEvent, head, operationAuthModes_1[authModeAttempts_1])];
|
|
110
|
-
case 1:
|
|
111
|
-
response = _a.sent();
|
|
112
|
-
logger.debug("Mutation sent successfully with authMode: " + operationAuthModes_1[authModeAttempts_1]);
|
|
113
|
-
return [2 /*return*/, response];
|
|
114
|
-
case 2:
|
|
115
|
-
error_2 = _a.sent();
|
|
116
|
-
authModeAttempts_1++;
|
|
117
|
-
if (authModeAttempts_1 >= operationAuthModes_1.length) {
|
|
118
|
-
logger.debug("Mutation failed with authMode: " + operationAuthModes_1[authModeAttempts_1 - 1]);
|
|
119
|
-
throw error_2;
|
|
120
|
-
}
|
|
121
|
-
logger.debug("Mutation failed with authMode: " + operationAuthModes_1[authModeAttempts_1 - 1] + ". Retrying with authMode: " + operationAuthModes_1[authModeAttempts_1]);
|
|
122
|
-
return [4 /*yield*/, authModeRetry_1()];
|
|
123
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
124
|
-
case 4: return [2 /*return*/];
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}); };
|
|
128
|
-
return [4 /*yield*/, authModeRetry_1()];
|
|
129
|
-
case 3:
|
|
130
|
-
_a = tslib_1.__read.apply(void 0, [_b.sent(), 3]), result = _a[0], opName = _a[1], modelDefinition = _a[2];
|
|
131
|
-
return [3 /*break*/, 5];
|
|
132
|
-
case 4:
|
|
133
|
-
error_1 = _b.sent();
|
|
134
|
-
if (error_1.message === 'Offline' || error_1.message === 'RetryMutation') {
|
|
135
|
-
return [2 /*return*/, "continue"];
|
|
136
|
-
}
|
|
137
|
-
return [3 /*break*/, 5];
|
|
138
|
-
case 5:
|
|
139
|
-
if (!(result === undefined)) return [3 /*break*/, 7];
|
|
140
|
-
logger.debug('done retrying');
|
|
141
|
-
return [4 /*yield*/, this_1.storage.runExclusive(function (storage) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
142
|
-
return tslib_1.__generator(this, function (_a) {
|
|
143
|
-
switch (_a.label) {
|
|
144
|
-
case 0: return [4 /*yield*/, this.outbox.dequeue(storage)];
|
|
145
|
-
case 1:
|
|
146
|
-
_a.sent();
|
|
147
|
-
return [2 /*return*/];
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}); })];
|
|
151
|
-
case 6:
|
|
152
|
-
_b.sent();
|
|
153
|
-
return [2 /*return*/, "continue"];
|
|
154
|
-
case 7:
|
|
155
|
-
record = result.data[opName];
|
|
156
|
-
hasMore = false;
|
|
157
|
-
return [4 /*yield*/, this_1.storage.runExclusive(function (storage) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
158
|
-
return tslib_1.__generator(this, function (_a) {
|
|
159
|
-
switch (_a.label) {
|
|
160
|
-
case 0:
|
|
161
|
-
// using runExclusive to prevent possible race condition
|
|
162
|
-
// when another record gets enqueued between dequeue and peek
|
|
163
|
-
return [4 /*yield*/, this.outbox.dequeue(storage, record, operation)];
|
|
94
|
+
return tslib_1.__generator(this, function (_a) {
|
|
95
|
+
switch (_a.label) {
|
|
96
|
+
case 0: return [4 /*yield*/, (this.runningProcesses.isOpen &&
|
|
97
|
+
this.runningProcesses.add(function (onTerminate) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
98
|
+
var head, namespaceName, _loop_1, this_1, _a;
|
|
99
|
+
var _this = this;
|
|
100
|
+
return tslib_1.__generator(this, function (_b) {
|
|
101
|
+
switch (_b.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
if (this.processing ||
|
|
104
|
+
!this.isReady() ||
|
|
105
|
+
!this.runningProcesses.isOpen) {
|
|
106
|
+
return [2 /*return*/];
|
|
107
|
+
}
|
|
108
|
+
this.processing = true;
|
|
109
|
+
namespaceName = util_1.USER;
|
|
110
|
+
_loop_1 = function () {
|
|
111
|
+
var model, operation, data, condition, modelConstructor, result, opName, modelDefinition, modelAuthModes, operationAuthModes_1, authModeAttempts_1, authModeRetry_1, error_1, record, hasMore;
|
|
112
|
+
var _a;
|
|
113
|
+
return tslib_1.__generator(this, function (_b) {
|
|
114
|
+
switch (_b.label) {
|
|
115
|
+
case 0:
|
|
116
|
+
model = head.model, operation = head.operation, data = head.data, condition = head.condition;
|
|
117
|
+
modelConstructor = this_1.userClasses[model];
|
|
118
|
+
result = void 0;
|
|
119
|
+
opName = void 0;
|
|
120
|
+
modelDefinition = void 0;
|
|
121
|
+
_b.label = 1;
|
|
164
122
|
case 1:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
123
|
+
_b.trys.push([1, 4, , 5]);
|
|
124
|
+
return [4 /*yield*/, utils_1.getModelAuthModes({
|
|
125
|
+
authModeStrategy: this_1.authModeStrategy,
|
|
126
|
+
defaultAuthMode: this_1.amplifyConfig.aws_appsync_authenticationType,
|
|
127
|
+
modelName: model,
|
|
128
|
+
schema: this_1.schema,
|
|
129
|
+
})];
|
|
169
130
|
case 2:
|
|
170
|
-
|
|
131
|
+
modelAuthModes = _b.sent();
|
|
132
|
+
operationAuthModes_1 = modelAuthModes[operation.toUpperCase()];
|
|
133
|
+
authModeAttempts_1 = 0;
|
|
134
|
+
authModeRetry_1 = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
135
|
+
var response, error_2;
|
|
136
|
+
return tslib_1.__generator(this, function (_a) {
|
|
137
|
+
switch (_a.label) {
|
|
138
|
+
case 0:
|
|
139
|
+
_a.trys.push([0, 2, , 4]);
|
|
140
|
+
logger.debug("Attempting mutation with authMode: " + operationAuthModes_1[authModeAttempts_1]);
|
|
141
|
+
return [4 /*yield*/, this.jitteredRetry(namespaceName, model, operation, data, condition, modelConstructor, this.MutationEvent, head, operationAuthModes_1[authModeAttempts_1], onTerminate)];
|
|
142
|
+
case 1:
|
|
143
|
+
response = _a.sent();
|
|
144
|
+
logger.debug("Mutation sent successfully with authMode: " + operationAuthModes_1[authModeAttempts_1]);
|
|
145
|
+
return [2 /*return*/, response];
|
|
146
|
+
case 2:
|
|
147
|
+
error_2 = _a.sent();
|
|
148
|
+
authModeAttempts_1++;
|
|
149
|
+
if (authModeAttempts_1 >= operationAuthModes_1.length) {
|
|
150
|
+
logger.debug("Mutation failed with authMode: " + operationAuthModes_1[authModeAttempts_1 - 1]);
|
|
151
|
+
throw error_2;
|
|
152
|
+
}
|
|
153
|
+
logger.debug("Mutation failed with authMode: " + operationAuthModes_1[authModeAttempts_1 - 1] + ". Retrying with authMode: " + operationAuthModes_1[authModeAttempts_1]);
|
|
154
|
+
return [4 /*yield*/, authModeRetry_1()];
|
|
155
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
156
|
+
case 4: return [2 /*return*/];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}); };
|
|
160
|
+
return [4 /*yield*/, authModeRetry_1()];
|
|
161
|
+
case 3:
|
|
162
|
+
_a = tslib_1.__read.apply(void 0, [_b.sent(), 3]), result = _a[0], opName = _a[1], modelDefinition = _a[2];
|
|
163
|
+
return [3 /*break*/, 5];
|
|
164
|
+
case 4:
|
|
165
|
+
error_1 = _b.sent();
|
|
166
|
+
if (error_1.message === 'Offline' ||
|
|
167
|
+
error_1.message === 'RetryMutation') {
|
|
168
|
+
return [2 /*return*/, "continue"];
|
|
169
|
+
}
|
|
170
|
+
return [3 /*break*/, 5];
|
|
171
|
+
case 5:
|
|
172
|
+
if (!(result === undefined)) return [3 /*break*/, 7];
|
|
173
|
+
logger.debug('done retrying');
|
|
174
|
+
return [4 /*yield*/, this_1.storage.runExclusive(function (storage) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
175
|
+
return tslib_1.__generator(this, function (_a) {
|
|
176
|
+
switch (_a.label) {
|
|
177
|
+
case 0: return [4 /*yield*/, this.outbox.dequeue(storage)];
|
|
178
|
+
case 1:
|
|
179
|
+
_a.sent();
|
|
180
|
+
return [2 /*return*/];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}); })];
|
|
184
|
+
case 6:
|
|
185
|
+
_b.sent();
|
|
186
|
+
return [2 /*return*/, "continue"];
|
|
187
|
+
case 7:
|
|
188
|
+
record = result.data[opName];
|
|
189
|
+
hasMore = false;
|
|
190
|
+
return [4 /*yield*/, this_1.storage.runExclusive(function (storage) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
191
|
+
return tslib_1.__generator(this, function (_a) {
|
|
192
|
+
switch (_a.label) {
|
|
193
|
+
case 0:
|
|
194
|
+
// using runExclusive to prevent possible race condition
|
|
195
|
+
// when another record gets enqueued between dequeue and peek
|
|
196
|
+
return [4 /*yield*/, this.outbox.dequeue(storage, record, operation)];
|
|
197
|
+
case 1:
|
|
198
|
+
// using runExclusive to prevent possible race condition
|
|
199
|
+
// when another record gets enqueued between dequeue and peek
|
|
200
|
+
_a.sent();
|
|
201
|
+
return [4 /*yield*/, this.outbox.peek(storage)];
|
|
202
|
+
case 2:
|
|
203
|
+
hasMore = (_a.sent()) !== undefined;
|
|
204
|
+
return [2 /*return*/];
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}); })];
|
|
208
|
+
case 8:
|
|
209
|
+
_b.sent();
|
|
210
|
+
this_1.observer.next({
|
|
211
|
+
operation: operation,
|
|
212
|
+
modelDefinition: modelDefinition,
|
|
213
|
+
model: record,
|
|
214
|
+
hasMore: hasMore,
|
|
215
|
+
});
|
|
171
216
|
return [2 /*return*/];
|
|
172
217
|
}
|
|
173
218
|
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
219
|
+
};
|
|
220
|
+
this_1 = this;
|
|
221
|
+
_b.label = 1;
|
|
222
|
+
case 1:
|
|
223
|
+
_a = this.processing &&
|
|
224
|
+
this.runningProcesses.isOpen;
|
|
225
|
+
if (!_a) return [3 /*break*/, 3];
|
|
226
|
+
return [4 /*yield*/, this.outbox.peek(this.storage)];
|
|
227
|
+
case 2:
|
|
228
|
+
_a = (head = _b.sent()) !== undefined;
|
|
229
|
+
_b.label = 3;
|
|
230
|
+
case 3:
|
|
231
|
+
if (!_a) return [3 /*break*/, 5];
|
|
232
|
+
return [5 /*yield**/, _loop_1()];
|
|
233
|
+
case 4:
|
|
234
|
+
_b.sent();
|
|
235
|
+
return [3 /*break*/, 1];
|
|
236
|
+
case 5:
|
|
237
|
+
// pauses itself
|
|
238
|
+
this.pause();
|
|
239
|
+
return [2 /*return*/];
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}); }, 'mutation resume loop'))];
|
|
189
243
|
case 1:
|
|
190
|
-
_a
|
|
191
|
-
if (!_a) return [3 /*break*/, 3];
|
|
192
|
-
return [4 /*yield*/, this.outbox.peek(this.storage)];
|
|
193
|
-
case 2:
|
|
194
|
-
_a = (head = _b.sent()) !== undefined;
|
|
195
|
-
_b.label = 3;
|
|
196
|
-
case 3:
|
|
197
|
-
if (!_a) return [3 /*break*/, 5];
|
|
198
|
-
return [5 /*yield**/, _loop_1()];
|
|
199
|
-
case 4:
|
|
200
|
-
_b.sent();
|
|
201
|
-
return [3 /*break*/, 1];
|
|
202
|
-
case 5:
|
|
203
|
-
// pauses itself
|
|
204
|
-
this.pause();
|
|
244
|
+
_a.sent();
|
|
205
245
|
return [2 /*return*/];
|
|
206
246
|
}
|
|
207
247
|
});
|
|
208
248
|
});
|
|
209
249
|
};
|
|
210
|
-
MutationProcessor.prototype.jitteredRetry = function (namespaceName, model, operation, data, condition, modelConstructor, MutationEvent, mutationEvent, authMode) {
|
|
250
|
+
MutationProcessor.prototype.jitteredRetry = function (namespaceName, model, operation, data, condition, modelConstructor, MutationEvent, mutationEvent, authMode, onTerminate) {
|
|
211
251
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
212
252
|
var _this = this;
|
|
213
253
|
return tslib_1.__generator(this, function (_a) {
|
|
214
254
|
switch (_a.label) {
|
|
215
255
|
case 0: return [4 /*yield*/, core_1.retry(function (model, operation, data, condition, modelConstructor, MutationEvent, mutationEvent) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
216
|
-
var _a, query, variables, graphQLCondition, opName, modelDefinition, authToken, tryWith, attempt, opType, result, err_1, _b, error, _c, _d, code, retryWith, err_2, _e, _f, opName_1, query_1, authToken_1, serverData, namespace, updatedMutation
|
|
256
|
+
var _a, query, variables, graphQLCondition, opName, modelDefinition, authToken, tryWith, attempt, opType, result, err_1, _b, error, _c, _d, code, retryWith, err_2, _e, _f, opName_1, query_1, authToken_1, serverData, namespace, updatedMutation;
|
|
217
257
|
var _g;
|
|
218
258
|
return tslib_1.__generator(this, function (_h) {
|
|
219
259
|
switch (_h.label) {
|
|
@@ -233,14 +273,16 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
233
273
|
opType = this.opTypeFromTransformerOperation(operation);
|
|
234
274
|
_h.label = 2;
|
|
235
275
|
case 2:
|
|
236
|
-
_h.trys.push([2, 4, ,
|
|
276
|
+
_h.trys.push([2, 4, , 17]);
|
|
237
277
|
return [4 /*yield*/, this.amplifyContext.API.graphql(tryWith)];
|
|
238
278
|
case 3:
|
|
239
279
|
result = (_h.sent());
|
|
280
|
+
// `as any` because TypeScript doesn't seem to like passing tuples
|
|
281
|
+
// through generic params???
|
|
240
282
|
return [2 /*return*/, [result, opName, modelDefinition]];
|
|
241
283
|
case 4:
|
|
242
284
|
err_1 = _h.sent();
|
|
243
|
-
if (!(err_1.errors && err_1.errors.length > 0)) return [3 /*break*/,
|
|
285
|
+
if (!(err_1.errors && err_1.errors.length > 0)) return [3 /*break*/, 15];
|
|
244
286
|
_b = tslib_1.__read(err_1.errors, 1), error = _b[0];
|
|
245
287
|
_c = error.originalError, _d = (_c === void 0 ? {} : _c).code, code = _d === void 0 ? null : _d;
|
|
246
288
|
if (error.errorType === 'Unauthorized') {
|
|
@@ -277,7 +319,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
277
319
|
case 7:
|
|
278
320
|
err_2 = _h.sent();
|
|
279
321
|
logger.warn('conflict trycatch', err_2);
|
|
280
|
-
return [3 /*break*/,
|
|
322
|
+
return [3 /*break*/, 17];
|
|
281
323
|
case 8:
|
|
282
324
|
if (!(retryWith === types_1.DISCARD)) return [3 /*break*/, 11];
|
|
283
325
|
_e = tslib_1.__read(utils_1.buildGraphQLOperation(this.schema.namespaces[namespaceName], modelDefinition, 'GET'), 1), _f = tslib_1.__read(_e[0], 3), opName_1 = _f[1], query_1 = _f[2];
|
|
@@ -293,6 +335,7 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
293
335
|
})];
|
|
294
336
|
case 10:
|
|
295
337
|
serverData = _h.sent();
|
|
338
|
+
// onTerminate cancel graphql()
|
|
296
339
|
return [2 /*return*/, [serverData, opName_1, modelDefinition]];
|
|
297
340
|
case 11:
|
|
298
341
|
namespace = this.schema.namespaces[namespaceName];
|
|
@@ -302,8 +345,8 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
302
345
|
_h.sent();
|
|
303
346
|
throw new core_1.NonRetryableError('RetryMutation');
|
|
304
347
|
case 13:
|
|
305
|
-
|
|
306
|
-
|
|
348
|
+
try {
|
|
349
|
+
this.errorHandler({
|
|
307
350
|
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',
|
|
308
351
|
localModel: variables.input,
|
|
309
352
|
message: error.message,
|
|
@@ -315,33 +358,32 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
315
358
|
remoteModel: error.data
|
|
316
359
|
? this.modelInstanceCreator(modelConstructor, error.data)
|
|
317
360
|
: null,
|
|
318
|
-
})
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
case
|
|
336
|
-
case 18:
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
catch (err) {
|
|
364
|
+
logger.warn('Mutation error handler failed with:', err);
|
|
365
|
+
}
|
|
366
|
+
finally {
|
|
367
|
+
// Return empty tuple, dequeues the mutation
|
|
368
|
+
return [2 /*return*/, error.data
|
|
369
|
+
? [
|
|
370
|
+
{ data: (_g = {}, _g[opName] = error.data, _g) },
|
|
371
|
+
opName,
|
|
372
|
+
modelDefinition,
|
|
373
|
+
]
|
|
374
|
+
: []];
|
|
375
|
+
}
|
|
376
|
+
_h.label = 14;
|
|
377
|
+
case 14: return [3 /*break*/, 16];
|
|
378
|
+
case 15:
|
|
337
379
|
// Catch-all for client-side errors that don't come back in the `GraphQLError` format.
|
|
338
380
|
// These errors should not be retried.
|
|
339
381
|
throw new core_1.NonRetryableError(err_1);
|
|
340
|
-
case
|
|
341
|
-
case
|
|
382
|
+
case 16: return [3 /*break*/, 17];
|
|
383
|
+
case 17:
|
|
342
384
|
if (tryWith) return [3 /*break*/, 2];
|
|
343
|
-
_h.label =
|
|
344
|
-
case
|
|
385
|
+
_h.label = 18;
|
|
386
|
+
case 18: return [2 /*return*/];
|
|
345
387
|
}
|
|
346
388
|
});
|
|
347
389
|
}); }, [
|
|
@@ -352,25 +394,25 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
352
394
|
modelConstructor,
|
|
353
395
|
MutationEvent,
|
|
354
396
|
mutationEvent,
|
|
355
|
-
], exports.safeJitteredBackoff)];
|
|
397
|
+
], exports.safeJitteredBackoff, onTerminate)];
|
|
356
398
|
case 1: return [2 /*return*/, _a.sent()];
|
|
357
399
|
}
|
|
358
400
|
});
|
|
359
401
|
});
|
|
360
402
|
};
|
|
361
403
|
MutationProcessor.prototype.createQueryVariables = function (namespaceName, model, operation, data, condition) {
|
|
362
|
-
var e_1, _a;
|
|
404
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
363
405
|
var modelDefinition = this.schema.namespaces[namespaceName].models[model];
|
|
364
406
|
var primaryKey = this.schema.namespaces[namespaceName].keys[model].primaryKey;
|
|
365
407
|
var queriesTuples = this.typeQuery.get(modelDefinition);
|
|
366
|
-
var
|
|
408
|
+
var _d = tslib_1.__read(queriesTuples.find(function (_a) {
|
|
367
409
|
var _b = tslib_1.__read(_a, 1), transformerMutationType = _b[0];
|
|
368
410
|
return transformerMutationType === operation;
|
|
369
|
-
}), 3), opName =
|
|
370
|
-
var
|
|
411
|
+
}), 3), opName = _d[1], query = _d[2];
|
|
412
|
+
var _e = JSON.parse(data), _version = _e._version, parsedData = tslib_1.__rest(_e, ["_version"]);
|
|
371
413
|
// include all the fields that comprise a custom PK if one is specified
|
|
372
414
|
var deleteInput = {};
|
|
373
|
-
if (primaryKey
|
|
415
|
+
if (primaryKey === null || primaryKey === void 0 ? void 0 : primaryKey.length) {
|
|
374
416
|
try {
|
|
375
417
|
for (var primaryKey_1 = tslib_1.__values(primaryKey), primaryKey_1_1 = primaryKey_1.next(); !primaryKey_1_1.done; primaryKey_1_1 = primaryKey_1.next()) {
|
|
376
418
|
var pkField = primaryKey_1_1.value;
|
|
@@ -386,48 +428,66 @@ var MutationProcessor = /** @class */ (function () {
|
|
|
386
428
|
}
|
|
387
429
|
}
|
|
388
430
|
else {
|
|
389
|
-
deleteInput[
|
|
431
|
+
deleteInput[util_1.ID] = parsedData.id;
|
|
390
432
|
}
|
|
391
|
-
var
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
433
|
+
var mutationInput;
|
|
434
|
+
if (operation === utils_1.TransformerMutationType.DELETE) {
|
|
435
|
+
// For DELETE mutations, only the key(s) are included in the input
|
|
436
|
+
mutationInput = deleteInput;
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
// Otherwise, we construct the mutation input with the following logic
|
|
440
|
+
mutationInput = {};
|
|
441
|
+
var modelFields = Object.values(modelDefinition.fields);
|
|
442
|
+
try {
|
|
443
|
+
for (var modelFields_1 = tslib_1.__values(modelFields), modelFields_1_1 = modelFields_1.next(); !modelFields_1_1.done; modelFields_1_1 = modelFields_1.next()) {
|
|
444
|
+
var _f = modelFields_1_1.value, name_1 = _f.name, type = _f.type, association = _f.association;
|
|
445
|
+
// model fields should be stripped out from the input
|
|
446
|
+
if (types_1.isModelFieldType(type)) {
|
|
447
|
+
// except for belongs to relations - we need to replace them with the correct foreign key(s)
|
|
448
|
+
if (types_1.isTargetNameAssociation(association) &&
|
|
449
|
+
association.connectionType === 'BELONGS_TO') {
|
|
450
|
+
var targetNames = util_1.extractTargetNamesFromSrc(association);
|
|
451
|
+
if (targetNames) {
|
|
452
|
+
try {
|
|
453
|
+
// instead of including the connected model itself, we add its key(s) to the mutation input
|
|
454
|
+
for (var targetNames_1 = (e_3 = void 0, tslib_1.__values(targetNames)), targetNames_1_1 = targetNames_1.next(); !targetNames_1_1.done; targetNames_1_1 = targetNames_1.next()) {
|
|
455
|
+
var targetName = targetNames_1_1.value;
|
|
456
|
+
mutationInput[targetName] = parsedData[targetName];
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
460
|
+
finally {
|
|
461
|
+
try {
|
|
462
|
+
if (targetNames_1_1 && !targetNames_1_1.done && (_c = targetNames_1.return)) _c.call(targetNames_1);
|
|
463
|
+
}
|
|
464
|
+
finally { if (e_3) throw e_3.error; }
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
continue;
|
|
402
469
|
}
|
|
403
|
-
//
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
470
|
+
// scalar fields / non-model types
|
|
471
|
+
if (operation === utils_1.TransformerMutationType.UPDATE) {
|
|
472
|
+
if (!parsedData.hasOwnProperty(name_1)) {
|
|
473
|
+
// for update mutations - strip out a field if it's unchanged
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
// all other fields are added to the input object
|
|
478
|
+
mutationInput[name_1] = parsedData[name_1];
|
|
409
479
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
var fieldName = name;
|
|
416
|
-
var val = parsedData[name];
|
|
417
|
-
if (types_1.isModelFieldType(type) &&
|
|
418
|
-
types_1.isTargetNameAssociation(association)) {
|
|
419
|
-
fieldName = association.targetName;
|
|
420
|
-
val = parsedData[fieldName];
|
|
480
|
+
}
|
|
481
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
482
|
+
finally {
|
|
483
|
+
try {
|
|
484
|
+
if (modelFields_1_1 && !modelFields_1_1.done && (_b = modelFields_1.return)) _b.call(modelFields_1);
|
|
421
485
|
}
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
var _b = tslib_1.__read(_a, 2), k = _b[0], v = _b[1];
|
|
426
|
-
acc[k] = v;
|
|
427
|
-
return acc;
|
|
428
|
-
}, {});
|
|
486
|
+
finally { if (e_2) throw e_2.error; }
|
|
487
|
+
}
|
|
488
|
+
}
|
|
429
489
|
// Build mutation variables input object
|
|
430
|
-
var input = tslib_1.__assign(tslib_1.__assign({},
|
|
490
|
+
var input = tslib_1.__assign(tslib_1.__assign({}, mutationInput), { _version: _version });
|
|
431
491
|
var graphQLCondition = JSON.parse(condition);
|
|
432
492
|
var variables = tslib_1.__assign({ input: input }, (operation === utils_1.TransformerMutationType.CREATE
|
|
433
493
|
? {}
|