@aws-amplify/datastore 3.12.6-next.20 → 3.12.6-next.32
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.js +13 -2
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.js +648 -344
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/predicates/index.js +12 -2
- package/lib/predicates/index.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +354 -203
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js +65 -28
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +444 -271
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/storage.js +93 -28
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.js +9 -0
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/index.js +522 -397
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.js +13 -6
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.js +77 -71
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/mutation.js +269 -209
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.js +213 -178
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.js +126 -121
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.js +43 -8
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.js +10 -1
- package/lib/types.js.map +1 -1
- 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 +13 -7
- 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/lib/authModeStrategies/defaultAuthStrategy.d.ts +0 -2
- package/lib/authModeStrategies/index.d.ts +0 -2
- package/lib/authModeStrategies/multiAuthStrategy.d.ts +0 -2
- package/lib/datastore/datastore.d.ts +0 -66
- package/lib/index.d.ts +0 -31
- package/lib/predicates/index.d.ts +0 -15
- package/lib/predicates/sort.d.ts +0 -8
- package/lib/ssr/index.d.ts +0 -3
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +0 -40
- package/lib/storage/adapter/AsyncStorageDatabase.d.ts +0 -29
- package/lib/storage/adapter/InMemoryStore.d.ts +0 -11
- package/lib/storage/adapter/InMemoryStore.native.d.ts +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.d.ts +0 -37
- package/lib/storage/adapter/getDefaultAdapter/index.d.ts +0 -3
- package/lib/storage/adapter/getDefaultAdapter/index.native.d.ts +0 -3
- package/lib/storage/adapter/index.d.ts +0 -9
- package/lib/storage/storage.d.ts +0 -49
- package/lib/sync/datastoreConnectivity.d.ts +0 -15
- package/lib/sync/datastoreReachability/index.d.ts +0 -3
- package/lib/sync/datastoreReachability/index.native.d.ts +0 -3
- package/lib/sync/index.d.ts +0 -63
- package/lib/sync/merger.d.ts +0 -11
- package/lib/sync/outbox.d.ts +0 -27
- package/lib/sync/processors/errorMaps.d.ts +0 -17
- package/lib/sync/processors/mutation.d.ts +0 -56
- package/lib/sync/processors/subscription.d.ts +0 -31
- package/lib/sync/processors/sync.d.ts +0 -27
- package/lib/sync/utils.d.ts +0 -41
- package/lib/types.d.ts +0 -462
- package/lib/util.d.ts +0 -113
- package/webpack.config.dev.js +0 -6
|
@@ -8,13 +8,14 @@ declare class SyncProcessor {
|
|
|
8
8
|
private readonly errorHandler;
|
|
9
9
|
private readonly amplifyContext;
|
|
10
10
|
private readonly typeQuery;
|
|
11
|
+
private runningProcesses;
|
|
11
12
|
constructor(schema: InternalSchema, syncPredicates: WeakMap<SchemaModel, ModelPredicate<any>>, amplifyConfig: Record<string, any>, authModeStrategy: AuthModeStrategy, errorHandler: ErrorHandler, amplifyContext: AmplifyContext);
|
|
12
13
|
private generateQueries;
|
|
13
14
|
private graphqlFilterFromPredicate;
|
|
14
15
|
private retrievePage;
|
|
15
|
-
private partialDataFeatureFlagEnabled;
|
|
16
16
|
private jitteredRetry;
|
|
17
17
|
start(typesLastSync: Map<SchemaModel, [string, number]>): Observable<SyncModelPage>;
|
|
18
|
+
stop(): Promise<void>;
|
|
18
19
|
}
|
|
19
20
|
export declare type SyncModelPage = {
|
|
20
21
|
namespace: string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator, __read, __values } from "tslib";
|
|
2
|
-
import API from '@aws-amplify/api';
|
|
2
|
+
import { API } from '@aws-amplify/api';
|
|
3
3
|
import Observable from 'zen-observable-ts';
|
|
4
4
|
import { ProcessName, } from '../../types';
|
|
5
5
|
import { buildGraphQLOperation, getModelAuthModes, getClientSideAuthError, getForbiddenError, predicateToGraphQLFilter, getTokenForCustomAuth, } from '../utils';
|
|
6
6
|
import { USER_AGENT_SUFFIX_DATASTORE } from '../../util';
|
|
7
|
-
import { jitteredExponentialRetry, ConsoleLogger as Logger, Hub, NonRetryableError, } from '@aws-amplify/core';
|
|
7
|
+
import { jitteredExponentialRetry, ConsoleLogger as Logger, Hub, NonRetryableError, BackgroundProcessManager, } from '@aws-amplify/core';
|
|
8
8
|
import { ModelPredicateCreator } from '../../predicates';
|
|
9
9
|
import { getSyncErrorType } from './errorMaps';
|
|
10
10
|
var opResultDefaults = {
|
|
@@ -23,6 +23,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
23
23
|
this.errorHandler = errorHandler;
|
|
24
24
|
this.amplifyContext = amplifyContext;
|
|
25
25
|
this.typeQuery = new WeakMap();
|
|
26
|
+
this.runningProcesses = new BackgroundProcessManager();
|
|
26
27
|
amplifyContext.API = amplifyContext.API || API;
|
|
27
28
|
this.generateQueries();
|
|
28
29
|
}
|
|
@@ -50,7 +51,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
50
51
|
}
|
|
51
52
|
return predicateToGraphQLFilter(predicatesGroup);
|
|
52
53
|
};
|
|
53
|
-
SyncProcessor.prototype.retrievePage = function (modelDefinition, lastSync, nextToken, limit, filter) {
|
|
54
|
+
SyncProcessor.prototype.retrievePage = function (modelDefinition, lastSync, nextToken, limit, filter, onTerminate) {
|
|
54
55
|
if (limit === void 0) { limit = null; }
|
|
55
56
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
57
|
var _a, opName, query, variables, modelAuthModes, readAuthModes, authModeAttempts, authModeRetry, data, _b, _c, opResult, items, newNextToken, startedAt;
|
|
@@ -81,7 +82,12 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
81
82
|
return __generator(this, function (_b) {
|
|
82
83
|
switch (_b.label) {
|
|
83
84
|
case 0:
|
|
84
|
-
|
|
85
|
+
if (!this.runningProcesses.isOpen) {
|
|
86
|
+
throw new Error('sync.retreievePage termination was requested. Exiting.');
|
|
87
|
+
}
|
|
88
|
+
_b.label = 1;
|
|
89
|
+
case 1:
|
|
90
|
+
_b.trys.push([1, 3, , 5]);
|
|
85
91
|
logger.debug("Attempting sync with authMode: " + readAuthModes[authModeAttempts]);
|
|
86
92
|
return [4 /*yield*/, this.jitteredRetry({
|
|
87
93
|
query: query,
|
|
@@ -89,12 +95,13 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
89
95
|
opName: opName,
|
|
90
96
|
modelDefinition: modelDefinition,
|
|
91
97
|
authMode: readAuthModes[authModeAttempts],
|
|
98
|
+
onTerminate: onTerminate,
|
|
92
99
|
})];
|
|
93
|
-
case
|
|
100
|
+
case 2:
|
|
94
101
|
response = _b.sent();
|
|
95
102
|
logger.debug("Sync successful with authMode: " + readAuthModes[authModeAttempts]);
|
|
96
103
|
return [2 /*return*/, response];
|
|
97
|
-
case
|
|
104
|
+
case 3:
|
|
98
105
|
error_1 = _b.sent();
|
|
99
106
|
authModeAttempts++;
|
|
100
107
|
if (authModeAttempts >= readAuthModes.length) {
|
|
@@ -113,8 +120,8 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
113
120
|
}
|
|
114
121
|
logger.debug("Sync failed with authMode: " + readAuthModes[authModeAttempts - 1] + ". Retrying with authMode: " + readAuthModes[authModeAttempts]);
|
|
115
122
|
return [4 /*yield*/, authModeRetry()];
|
|
116
|
-
case
|
|
117
|
-
case
|
|
123
|
+
case 4: return [2 /*return*/, _b.sent()];
|
|
124
|
+
case 5: return [2 /*return*/];
|
|
118
125
|
}
|
|
119
126
|
});
|
|
120
127
|
}); };
|
|
@@ -132,32 +139,23 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
132
139
|
});
|
|
133
140
|
});
|
|
134
141
|
};
|
|
135
|
-
// Partial data private feature flag. Not a public API. This will be removed in a future release.
|
|
136
|
-
SyncProcessor.prototype.partialDataFeatureFlagEnabled = function () {
|
|
137
|
-
try {
|
|
138
|
-
var flag = sessionStorage.getItem('datastorePartialData');
|
|
139
|
-
return Boolean(flag);
|
|
140
|
-
}
|
|
141
|
-
catch (e) {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
142
|
SyncProcessor.prototype.jitteredRetry = function (_a) {
|
|
146
|
-
var query = _a.query, variables = _a.variables, opName = _a.opName, modelDefinition = _a.modelDefinition, authMode = _a.authMode;
|
|
143
|
+
var query = _a.query, variables = _a.variables, opName = _a.opName, modelDefinition = _a.modelDefinition, authMode = _a.authMode, onTerminate = _a.onTerminate;
|
|
147
144
|
return __awaiter(this, void 0, void 0, function () {
|
|
148
145
|
var _this = this;
|
|
149
146
|
return __generator(this, function (_b) {
|
|
150
147
|
switch (_b.label) {
|
|
151
148
|
case 0: return [4 /*yield*/, jitteredExponentialRetry(function (query, variables) { return __awaiter(_this, void 0, void 0, function () {
|
|
152
|
-
var authToken, error_2, clientOrForbiddenErrorMessage, hasItems,
|
|
149
|
+
var authToken, error_2, clientOrForbiddenErrorMessage, hasItems, unauthorized, otherErrors, result;
|
|
153
150
|
var _this = this;
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
var _a, _b, _c, _d;
|
|
152
|
+
return __generator(this, function (_e) {
|
|
153
|
+
switch (_e.label) {
|
|
156
154
|
case 0:
|
|
157
|
-
|
|
155
|
+
_e.trys.push([0, 3, , 6]);
|
|
158
156
|
return [4 /*yield*/, getTokenForCustomAuth(authMode, this.amplifyConfig)];
|
|
159
157
|
case 1:
|
|
160
|
-
authToken =
|
|
158
|
+
authToken = _e.sent();
|
|
161
159
|
return [4 /*yield*/, this.amplifyContext.API.graphql({
|
|
162
160
|
query: query,
|
|
163
161
|
variables: variables,
|
|
@@ -165,23 +163,24 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
165
163
|
authToken: authToken,
|
|
166
164
|
userAgentSuffix: USER_AGENT_SUFFIX_DATASTORE,
|
|
167
165
|
})];
|
|
168
|
-
case 2: return [2 /*return*/,
|
|
166
|
+
case 2: return [2 /*return*/, _e.sent()];
|
|
169
167
|
case 3:
|
|
170
|
-
error_2 =
|
|
168
|
+
error_2 = _e.sent();
|
|
171
169
|
clientOrForbiddenErrorMessage = getClientSideAuthError(error_2) || getForbiddenError(error_2);
|
|
172
170
|
if (clientOrForbiddenErrorMessage) {
|
|
173
171
|
throw new NonRetryableError(clientOrForbiddenErrorMessage);
|
|
174
172
|
}
|
|
175
|
-
hasItems = Boolean(error_2
|
|
176
|
-
|
|
177
|
-
error_2.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (!hasItems) return [3 /*break*/, 6];
|
|
173
|
+
hasItems = Boolean((_b = (_a = error_2 === null || error_2 === void 0 ? void 0 : error_2.data) === null || _a === void 0 ? void 0 : _a[opName]) === null || _b === void 0 ? void 0 : _b.items);
|
|
174
|
+
unauthorized = (error_2 === null || error_2 === void 0 ? void 0 : error_2.errors) &&
|
|
175
|
+
error_2.errors.some(function (err) { return err.errorType === 'Unauthorized'; });
|
|
176
|
+
otherErrors = (error_2 === null || error_2 === void 0 ? void 0 : error_2.errors) &&
|
|
177
|
+
error_2.errors.filter(function (err) { return err.errorType !== 'Unauthorized'; });
|
|
181
178
|
result = error_2;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
179
|
+
if (hasItems) {
|
|
180
|
+
result.data[opName].items = result.data[opName].items.filter(function (item) { return item !== null; });
|
|
181
|
+
}
|
|
182
|
+
if (!(hasItems && (otherErrors === null || otherErrors === void 0 ? void 0 : otherErrors.length))) return [3 /*break*/, 5];
|
|
183
|
+
return [4 /*yield*/, Promise.all(otherErrors.map(function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
185
184
|
var e_1;
|
|
186
185
|
return __generator(this, function (_a) {
|
|
187
186
|
switch (_a.label) {
|
|
@@ -210,40 +209,30 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
210
209
|
});
|
|
211
210
|
}); }))];
|
|
212
211
|
case 4:
|
|
213
|
-
|
|
212
|
+
_e.sent();
|
|
214
213
|
Hub.dispatch('datastore', {
|
|
215
|
-
event: '
|
|
214
|
+
event: 'nonApplicableDataReceived',
|
|
216
215
|
data: {
|
|
217
|
-
errors:
|
|
216
|
+
errors: otherErrors,
|
|
218
217
|
modelName: modelDefinition.name,
|
|
219
218
|
},
|
|
220
219
|
});
|
|
221
|
-
|
|
222
|
-
case 5:
|
|
223
|
-
case 6: throw error_2;
|
|
224
|
-
case 7:
|
|
225
|
-
unauthorized = error_2 &&
|
|
226
|
-
error_2.errors &&
|
|
227
|
-
error_2.errors.some(function (err) { return err.errorType === 'Unauthorized'; });
|
|
220
|
+
_e.label = 5;
|
|
221
|
+
case 5:
|
|
228
222
|
if (unauthorized) {
|
|
229
|
-
result = error_2;
|
|
230
|
-
if (hasItems) {
|
|
231
|
-
result.data[opName].items = result.data[opName].items.filter(function (item) { return item !== null; });
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
result.data[opName] = __assign(__assign({}, opResultDefaults), result.data[opName]);
|
|
235
|
-
}
|
|
236
223
|
logger.warn('queryError', "User is unauthorized to query " + opName + ", some items could not be returned.");
|
|
224
|
+
result.data = result.data || {};
|
|
225
|
+
result.data[opName] = __assign(__assign({}, opResultDefaults), result.data[opName]);
|
|
237
226
|
return [2 /*return*/, result];
|
|
238
227
|
}
|
|
239
|
-
|
|
240
|
-
|
|
228
|
+
if ((_d = (_c = result.data) === null || _c === void 0 ? void 0 : _c[opName].items) === null || _d === void 0 ? void 0 : _d.length) {
|
|
229
|
+
return [2 /*return*/, result];
|
|
241
230
|
}
|
|
242
|
-
|
|
243
|
-
case
|
|
231
|
+
throw error_2;
|
|
232
|
+
case 6: return [2 /*return*/];
|
|
244
233
|
}
|
|
245
234
|
});
|
|
246
|
-
}); }, [query, variables])];
|
|
235
|
+
}); }, [query, variables], undefined, onTerminate)];
|
|
247
236
|
case 1: return [2 /*return*/, _b.sent()];
|
|
248
237
|
}
|
|
249
238
|
});
|
|
@@ -251,7 +240,6 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
251
240
|
};
|
|
252
241
|
SyncProcessor.prototype.start = function (typesLastSync) {
|
|
253
242
|
var _this = this;
|
|
254
|
-
var processing = true;
|
|
255
243
|
var _a = this.amplifyConfig, maxRecordsToSync = _a.maxRecordsToSync, syncPageSize = _a.syncPageSize;
|
|
256
244
|
var parentPromises = new Map();
|
|
257
245
|
var observable = new Observable(function (observer) {
|
|
@@ -280,77 +268,94 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
280
268
|
})
|
|
281
269
|
.map(function (_a) {
|
|
282
270
|
var _b = __read(_a, 2), modelDefinition = _b[0], _c = __read(_b[1], 2), namespace = _c[0], lastSync = _c[1];
|
|
283
|
-
return
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
promise = new Promise(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
300
|
-
var limit;
|
|
301
|
-
var _a;
|
|
302
|
-
return __generator(this, function (_b) {
|
|
303
|
-
switch (_b.label) {
|
|
304
|
-
case 0: return [4 /*yield*/, Promise.all(promises)];
|
|
305
|
-
case 1:
|
|
306
|
-
_b.sent();
|
|
307
|
-
_b.label = 2;
|
|
308
|
-
case 2:
|
|
309
|
-
if (!processing) {
|
|
310
|
-
return [2 /*return*/];
|
|
311
|
-
}
|
|
312
|
-
limit = Math.min(maxRecordsToSync - recordsReceived, syncPageSize);
|
|
313
|
-
return [4 /*yield*/, this.retrievePage(modelDefinition, lastSync, nextToken, limit, filter)];
|
|
314
|
-
case 3:
|
|
315
|
-
(_a = _b.sent(), items = _a.items, nextToken = _a.nextToken, startedAt = _a.startedAt);
|
|
316
|
-
recordsReceived += items.length;
|
|
317
|
-
done = nextToken === null || recordsReceived >= maxRecordsToSync;
|
|
318
|
-
observer.next({
|
|
319
|
-
namespace: namespace,
|
|
320
|
-
modelDefinition: modelDefinition,
|
|
321
|
-
items: items,
|
|
322
|
-
done: done,
|
|
323
|
-
startedAt: startedAt,
|
|
324
|
-
isFullSync: !lastSync,
|
|
325
|
-
});
|
|
326
|
-
_b.label = 4;
|
|
327
|
-
case 4:
|
|
328
|
-
if (!done) return [3 /*break*/, 2];
|
|
329
|
-
_b.label = 5;
|
|
330
|
-
case 5:
|
|
331
|
-
res();
|
|
332
|
-
return [2 /*return*/];
|
|
333
|
-
}
|
|
271
|
+
return _this.runningProcesses.isOpen &&
|
|
272
|
+
_this.runningProcesses.add(function (onTerminate) { return __awaiter(_this, void 0, void 0, function () {
|
|
273
|
+
var done, nextToken, startedAt, items, recordsReceived, filter, parents, promises, promise;
|
|
274
|
+
var _this = this;
|
|
275
|
+
return __generator(this, function (_a) {
|
|
276
|
+
switch (_a.label) {
|
|
277
|
+
case 0:
|
|
278
|
+
done = false;
|
|
279
|
+
nextToken = null;
|
|
280
|
+
startedAt = null;
|
|
281
|
+
items = null;
|
|
282
|
+
recordsReceived = 0;
|
|
283
|
+
filter = this.graphqlFilterFromPredicate(modelDefinition);
|
|
284
|
+
parents = this.schema.namespaces[namespace].modelTopologicalOrdering.get(modelDefinition.name);
|
|
285
|
+
promises = parents.map(function (parent) {
|
|
286
|
+
return parentPromises.get(namespace + "_" + parent);
|
|
334
287
|
});
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
288
|
+
promise = new Promise(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
289
|
+
var limit;
|
|
290
|
+
var _a;
|
|
291
|
+
return __generator(this, function (_b) {
|
|
292
|
+
switch (_b.label) {
|
|
293
|
+
case 0: return [4 /*yield*/, Promise.all(promises)];
|
|
294
|
+
case 1:
|
|
295
|
+
_b.sent();
|
|
296
|
+
_b.label = 2;
|
|
297
|
+
case 2:
|
|
298
|
+
if (!this.runningProcesses.isOpen) {
|
|
299
|
+
return [2 /*return*/];
|
|
300
|
+
}
|
|
301
|
+
limit = Math.min(maxRecordsToSync - recordsReceived, syncPageSize);
|
|
302
|
+
return [4 /*yield*/, this.retrievePage(modelDefinition, lastSync, nextToken, limit, filter, onTerminate)];
|
|
303
|
+
case 3:
|
|
304
|
+
(_a = _b.sent(), items = _a.items, nextToken = _a.nextToken, startedAt = _a.startedAt);
|
|
305
|
+
recordsReceived += items.length;
|
|
306
|
+
done =
|
|
307
|
+
nextToken === null || recordsReceived >= maxRecordsToSync;
|
|
308
|
+
observer.next({
|
|
309
|
+
namespace: namespace,
|
|
310
|
+
modelDefinition: modelDefinition,
|
|
311
|
+
items: items,
|
|
312
|
+
done: done,
|
|
313
|
+
startedAt: startedAt,
|
|
314
|
+
isFullSync: !lastSync,
|
|
315
|
+
});
|
|
316
|
+
_b.label = 4;
|
|
317
|
+
case 4:
|
|
318
|
+
if (!done) return [3 /*break*/, 2];
|
|
319
|
+
_b.label = 5;
|
|
320
|
+
case 5:
|
|
321
|
+
res();
|
|
322
|
+
return [2 /*return*/];
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}); });
|
|
326
|
+
parentPromises.set(namespace + "_" + modelDefinition.name, promise);
|
|
327
|
+
return [4 /*yield*/, promise];
|
|
328
|
+
case 1:
|
|
329
|
+
_a.sent();
|
|
330
|
+
return [2 /*return*/];
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}); }, "adding model " + modelDefinition.name);
|
|
344
334
|
});
|
|
345
335
|
Promise.all(allModelsReady).then(function () {
|
|
346
336
|
observer.complete();
|
|
347
337
|
});
|
|
348
|
-
return function () {
|
|
349
|
-
processing = false;
|
|
350
|
-
};
|
|
351
338
|
});
|
|
352
339
|
return observable;
|
|
353
340
|
};
|
|
341
|
+
SyncProcessor.prototype.stop = function () {
|
|
342
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
343
|
+
return __generator(this, function (_a) {
|
|
344
|
+
switch (_a.label) {
|
|
345
|
+
case 0:
|
|
346
|
+
logger.debug('stopping sync processor');
|
|
347
|
+
return [4 /*yield*/, this.runningProcesses.close()];
|
|
348
|
+
case 1:
|
|
349
|
+
_a.sent();
|
|
350
|
+
return [4 /*yield*/, this.runningProcesses.open()];
|
|
351
|
+
case 2:
|
|
352
|
+
_a.sent();
|
|
353
|
+
logger.debug('sync processor stopped');
|
|
354
|
+
return [2 /*return*/];
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
};
|
|
354
359
|
return SyncProcessor;
|
|
355
360
|
}());
|
|
356
361
|
export { SyncProcessor };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../../src/sync/processors/sync.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../../src/sync/processors/sync.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAoC,MAAM,kBAAkB,CAAC;AACzE,OAAO,UAAU,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EASN,WAAW,GAEX,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,wBAAwB,EACx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AAO,UAAU,CAAC;IACnB,CAAC;IAEK,4BAAI,GAAV;;;;;wBACC,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;wBACxC,qBAAM,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,EAAA;;wBAAnC,SAAmC,CAAC;wBACpC,qBAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAA;;wBAAlC,SAAkC,CAAC;wBACnC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;;;;;KACvC;IACF,oBAAC;AAAD,CAAC,AAtXD,IAsXC;AAWD,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/lib-esm/sync/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
|
|
2
2
|
import { GraphQLAuthError } from '@aws-amplify/api';
|
|
3
3
|
import { ModelInstanceCreator } from '../datastore/datastore';
|
|
4
|
-
import { AuthorizationRule, GraphQLCondition, GraphQLFilter, OpType, PersistentModel, PersistentModelConstructor, PredicatesGroup, RelationshipType, SchemaModel, SchemaNamespace, SchemaNonModel, ModelOperation, InternalSchema, AuthModeStrategy } from '../types';
|
|
4
|
+
import { AuthorizationRule, GraphQLCondition, GraphQLFilter, ModelInstanceMetadata, OpType, PersistentModel, PersistentModelConstructor, PredicatesGroup, RelationshipType, SchemaModel, SchemaNamespace, SchemaNonModel, ModelOperation, InternalSchema, AuthModeStrategy } from '../types';
|
|
5
5
|
import { MutationEvent } from './';
|
|
6
6
|
declare enum GraphQLOperationType {
|
|
7
7
|
LIST = "query",
|
|
@@ -22,7 +22,7 @@ export declare function getAuthorizationRules(modelDefinition: SchemaModel): Aut
|
|
|
22
22
|
export declare function buildSubscriptionGraphQLOperation(namespace: SchemaNamespace, modelDefinition: SchemaModel, transformerMutationType: TransformerMutationType, isOwnerAuthorization: boolean, ownerField: string): [TransformerMutationType, string, string];
|
|
23
23
|
export declare function buildGraphQLOperation(namespace: SchemaNamespace, modelDefinition: SchemaModel, graphQLOpType: keyof typeof GraphQLOperationType): [TransformerMutationType, string, string][];
|
|
24
24
|
export declare function createMutationInstanceFromModelOperation<T extends PersistentModel>(relationships: RelationshipType, modelDefinition: SchemaModel, opType: OpType, model: PersistentModelConstructor<T>, element: T, condition: GraphQLCondition, MutationEventConstructor: PersistentModelConstructor<MutationEvent>, modelInstanceCreator: ModelInstanceCreator, id?: string): MutationEvent;
|
|
25
|
-
export declare function predicateToGraphQLCondition(predicate: PredicatesGroup<any
|
|
25
|
+
export declare function predicateToGraphQLCondition(predicate: PredicatesGroup<any>, modelDefinition: SchemaModel): GraphQLCondition;
|
|
26
26
|
export declare function predicateToGraphQLFilter(predicatesGroup: PredicatesGroup<any>): GraphQLFilter;
|
|
27
27
|
export declare function getUserGroupsFromToken(token: {
|
|
28
28
|
[field: string]: any;
|
|
@@ -38,4 +38,5 @@ export declare function getModelAuthModes({ authModeStrategy, defaultAuthMode, m
|
|
|
38
38
|
export declare function getForbiddenError(error: any): any;
|
|
39
39
|
export declare function getClientSideAuthError(error: any): GraphQLAuthError;
|
|
40
40
|
export declare function getTokenForCustomAuth(authMode: GRAPHQL_AUTH_MODE, amplifyConfig?: Record<string, any>): Promise<string | undefined>;
|
|
41
|
+
export declare function getIdentifierValue(modelDefinition: SchemaModel, model: ModelInstanceMetadata | PersistentModel): string;
|
|
41
42
|
export {};
|
package/lib-esm/sync/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { __assign, __awaiter, __generator } from "tslib";
|
|
1
|
+
import { __assign, __awaiter, __generator, __read } from "tslib";
|
|
2
2
|
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
|
|
3
3
|
import { GraphQLAuthError } from '@aws-amplify/api';
|
|
4
4
|
import { Logger } from '@aws-amplify/core';
|
|
5
|
-
import { isEnumFieldType, isGraphQLScalarType, isPredicateObj, isSchemaModel, isTargetNameAssociation, isNonModelFieldType, OpType, ModelOperation, } from '../types';
|
|
6
|
-
import { exhaustiveCheck } from '../util';
|
|
5
|
+
import { isEnumFieldType, isGraphQLScalarType, isPredicateObj, isSchemaModel, isSchemaModelWithAttributes, isTargetNameAssociation, isNonModelFieldType, OpType, ModelOperation, } from '../types';
|
|
6
|
+
import { exhaustiveCheck, extractPrimaryKeyFieldNames, establishRelationAndKeys, IDENTIFIER_KEY_SEPARATOR, } from '../util';
|
|
7
7
|
var logger = new Logger('DataStore');
|
|
8
8
|
var GraphQLOperationType;
|
|
9
9
|
(function (GraphQLOperationType) {
|
|
@@ -43,7 +43,7 @@ export function generateSelectionSet(namespace, modelDefinition) {
|
|
|
43
43
|
if (isSchemaModel(modelDefinition)) {
|
|
44
44
|
scalarAndMetadataFields = scalarAndMetadataFields
|
|
45
45
|
.concat(getMetadataFields())
|
|
46
|
-
.concat(getConnectionFields(modelDefinition));
|
|
46
|
+
.concat(getConnectionFields(modelDefinition, namespace));
|
|
47
47
|
}
|
|
48
48
|
var result = scalarAndMetadataFields.join('\n');
|
|
49
49
|
return result;
|
|
@@ -57,7 +57,7 @@ function getImplicitOwnerField(modelDefinition, scalarFields) {
|
|
|
57
57
|
}
|
|
58
58
|
function getOwnerFields(modelDefinition) {
|
|
59
59
|
var ownerFields = [];
|
|
60
|
-
if (
|
|
60
|
+
if (isSchemaModelWithAttributes(modelDefinition)) {
|
|
61
61
|
modelDefinition.attributes.forEach(function (attr) {
|
|
62
62
|
if (attr.properties && attr.properties.rules) {
|
|
63
63
|
var rule = attr.properties.rules.find(function (rule) { return rule.allow === 'owner'; });
|
|
@@ -84,7 +84,8 @@ function getScalarFields(modelDefinition) {
|
|
|
84
84
|
}, {});
|
|
85
85
|
return result;
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
// Used for generating the selection set for queries and mutations
|
|
88
|
+
function getConnectionFields(modelDefinition, namespace) {
|
|
88
89
|
var result = [];
|
|
89
90
|
Object.values(modelDefinition.fields)
|
|
90
91
|
.filter(function (_a) {
|
|
@@ -101,7 +102,24 @@ function getConnectionFields(modelDefinition) {
|
|
|
101
102
|
break;
|
|
102
103
|
case 'BELONGS_TO':
|
|
103
104
|
if (isTargetNameAssociation(association)) {
|
|
104
|
-
|
|
105
|
+
// New codegen (CPK)
|
|
106
|
+
if (association.targetNames && association.targetNames.length > 0) {
|
|
107
|
+
// Need to retrieve relations in order to get connected model keys
|
|
108
|
+
var _b = __read(establishRelationAndKeys(namespace), 1), relations = _b[0];
|
|
109
|
+
var connectedModelName = modelDefinition.fields[name].type['model'];
|
|
110
|
+
var byPkIndex = relations[connectedModelName].indexes.find(function (_a) {
|
|
111
|
+
var _b = __read(_a, 1), name = _b[0];
|
|
112
|
+
return name === 'byPk';
|
|
113
|
+
});
|
|
114
|
+
var keyFields = byPkIndex && byPkIndex[1];
|
|
115
|
+
var keyFieldSelectionSet = keyFields === null || keyFields === void 0 ? void 0 : keyFields.join(' ');
|
|
116
|
+
// We rely on `_deleted` when we process the sync query (e.g. in batchSave in the adapters)
|
|
117
|
+
result.push(name + " { " + keyFieldSelectionSet + " _deleted }");
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// backwards-compatability for schema generated prior to custom primary key support
|
|
121
|
+
result.push(name + " { id _deleted }");
|
|
122
|
+
}
|
|
105
123
|
}
|
|
106
124
|
break;
|
|
107
125
|
default:
|
|
@@ -275,25 +293,35 @@ export function createMutationInstanceFromModelOperation(relationships, modelDef
|
|
|
275
293
|
}
|
|
276
294
|
return v;
|
|
277
295
|
};
|
|
278
|
-
var
|
|
296
|
+
var modelId = getIdentifierValue(modelDefinition, element);
|
|
297
|
+
var optionalId = OpType.INSERT && id ? { id: id } : {};
|
|
298
|
+
var mutationEvent = modelInstanceCreator(MutationEventConstructor, __assign(__assign({}, optionalId), { data: JSON.stringify(element, replacer), modelId: modelId, model: model.name, operation: operation, condition: JSON.stringify(condition) }));
|
|
279
299
|
return mutationEvent;
|
|
280
300
|
}
|
|
281
|
-
export function predicateToGraphQLCondition(predicate) {
|
|
301
|
+
export function predicateToGraphQLCondition(predicate, modelDefinition) {
|
|
282
302
|
var result = {};
|
|
283
303
|
if (!predicate || !Array.isArray(predicate.predicates)) {
|
|
284
304
|
return result;
|
|
285
305
|
}
|
|
306
|
+
var keyFields = extractPrimaryKeyFieldNames(modelDefinition);
|
|
286
307
|
predicate.predicates.forEach(function (p) {
|
|
287
308
|
var _a;
|
|
288
309
|
if (isPredicateObj(p)) {
|
|
289
310
|
var field = p.field, operator = p.operator, operand = p.operand;
|
|
290
|
-
|
|
311
|
+
// This is compatible with how the GQL Transform currently generates the Condition Input,
|
|
312
|
+
// i.e. any PK and SK fields are omitted and can't be used as conditions.
|
|
313
|
+
// However, I think this limits usability.
|
|
314
|
+
// What if we want to delete all records where SK > some value
|
|
315
|
+
// Or all records where PK = some value but SKs are different values
|
|
316
|
+
// TODO: if the Transform gets updated ^ we'll need to modify this logic to only omit
|
|
317
|
+
// key fields from the predicate/condition when ALL of the keyFields are present and using `eq` operators
|
|
318
|
+
if (keyFields.includes(field)) {
|
|
291
319
|
return;
|
|
292
320
|
}
|
|
293
321
|
result[field] = (_a = {}, _a[operator] = operand, _a);
|
|
294
322
|
}
|
|
295
323
|
else {
|
|
296
|
-
result[p.type] = predicateToGraphQLCondition(p);
|
|
324
|
+
result[p.type] = predicateToGraphQLCondition(p, modelDefinition);
|
|
297
325
|
}
|
|
298
326
|
});
|
|
299
327
|
return result;
|
|
@@ -450,4 +478,10 @@ export function getTokenForCustomAuth(authMode, amplifyConfig) {
|
|
|
450
478
|
});
|
|
451
479
|
});
|
|
452
480
|
}
|
|
481
|
+
// Util that takes a modelDefinition and model and returns either the id value(s) or the custom primary key value(s)
|
|
482
|
+
export function getIdentifierValue(modelDefinition, model) {
|
|
483
|
+
var pkFieldNames = extractPrimaryKeyFieldNames(modelDefinition);
|
|
484
|
+
var idOrPk = pkFieldNames.map(function (f) { return model[f]; }).join(IDENTIFIER_KEY_SEPARATOR);
|
|
485
|
+
return idOrPk;
|
|
486
|
+
}
|
|
453
487
|
//# sourceMappingURL=utils.js.map
|