@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
|
@@ -17,7 +17,7 @@ declare class SyncProcessor {
|
|
|
17
17
|
start(typesLastSync: Map<SchemaModel, [string, number]>): Observable<SyncModelPage>;
|
|
18
18
|
stop(): Promise<void>;
|
|
19
19
|
}
|
|
20
|
-
export
|
|
20
|
+
export type SyncModelPage = {
|
|
21
21
|
namespace: string;
|
|
22
22
|
modelDefinition: SchemaModel;
|
|
23
23
|
items: ModelInstanceMetadata[];
|
|
@@ -1,10 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
var __values = (this && this.__values) || function(o) {
|
|
55
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
56
|
+
if (m) return m.call(o);
|
|
57
|
+
if (o && typeof o.length === "number") return {
|
|
58
|
+
next: function () {
|
|
59
|
+
if (o && i >= o.length) o = void 0;
|
|
60
|
+
return { value: o && o[i++], done: !o };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
64
|
+
};
|
|
65
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
66
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
67
|
+
};
|
|
2
68
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
69
|
+
exports.SyncProcessor = void 0;
|
|
4
70
|
var internals_1 = require("@aws-amplify/api/internals");
|
|
5
|
-
var zen_observable_ts_1 =
|
|
71
|
+
var zen_observable_ts_1 = __importDefault(require("zen-observable-ts"));
|
|
6
72
|
var types_1 = require("../../types");
|
|
7
73
|
var utils_1 = require("../utils");
|
|
74
|
+
var utils_2 = require("@aws-amplify/core/internals/utils");
|
|
8
75
|
var core_1 = require("@aws-amplify/core");
|
|
9
76
|
var predicates_1 = require("../../predicates");
|
|
10
77
|
var errorMaps_1 = require("./errorMaps");
|
|
@@ -13,7 +80,7 @@ var opResultDefaults = {
|
|
|
13
80
|
nextToken: null,
|
|
14
81
|
startedAt: null,
|
|
15
82
|
};
|
|
16
|
-
var logger = new
|
|
83
|
+
var logger = new utils_2.ConsoleLogger('DataStore');
|
|
17
84
|
var SyncProcessor = /** @class */ (function () {
|
|
18
85
|
function SyncProcessor(schema, syncPredicates, amplifyConfig, authModeStrategy, errorHandler, amplifyContext) {
|
|
19
86
|
if (amplifyConfig === void 0) { amplifyConfig = {}; }
|
|
@@ -24,7 +91,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
24
91
|
this.errorHandler = errorHandler;
|
|
25
92
|
this.amplifyContext = amplifyContext;
|
|
26
93
|
this.typeQuery = new WeakMap();
|
|
27
|
-
this.runningProcesses = new
|
|
94
|
+
this.runningProcesses = new utils_2.BackgroundProcessManager();
|
|
28
95
|
amplifyContext.InternalAPI = amplifyContext.InternalAPI || internals_1.InternalAPI;
|
|
29
96
|
this.generateQueries();
|
|
30
97
|
}
|
|
@@ -37,7 +104,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
37
104
|
return syncable;
|
|
38
105
|
})
|
|
39
106
|
.forEach(function (model) {
|
|
40
|
-
var _a =
|
|
107
|
+
var _a = __read((0, utils_1.buildGraphQLOperation)(namespace, model, 'LIST'), 1), _b = __read(_a[0]), opNameQuery = _b.slice(1);
|
|
41
108
|
_this.typeQuery.set(model, opNameQuery);
|
|
42
109
|
});
|
|
43
110
|
});
|
|
@@ -50,24 +117,24 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
50
117
|
if (!predicatesGroup) {
|
|
51
118
|
return null;
|
|
52
119
|
}
|
|
53
|
-
return utils_1.predicateToGraphQLFilter(predicatesGroup);
|
|
120
|
+
return (0, utils_1.predicateToGraphQLFilter)(predicatesGroup);
|
|
54
121
|
};
|
|
55
122
|
SyncProcessor.prototype.retrievePage = function (modelDefinition, lastSync, nextToken, limit, filter, onTerminate) {
|
|
56
123
|
if (limit === void 0) { limit = null; }
|
|
57
|
-
return
|
|
124
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
125
|
var _a, opName, query, variables, modelAuthModes, readAuthModes, authModeAttempts, authModeRetry, data, _b, _c, opResult, items, newNextToken, startedAt;
|
|
59
126
|
var _this = this;
|
|
60
|
-
return
|
|
127
|
+
return __generator(this, function (_d) {
|
|
61
128
|
switch (_d.label) {
|
|
62
129
|
case 0:
|
|
63
|
-
_a =
|
|
130
|
+
_a = __read(this.typeQuery.get(modelDefinition), 2), opName = _a[0], query = _a[1];
|
|
64
131
|
variables = {
|
|
65
132
|
limit: limit,
|
|
66
133
|
nextToken: nextToken,
|
|
67
134
|
lastSync: lastSync,
|
|
68
135
|
filter: filter,
|
|
69
136
|
};
|
|
70
|
-
return [4 /*yield*/, utils_1.getModelAuthModes({
|
|
137
|
+
return [4 /*yield*/, (0, utils_1.getModelAuthModes)({
|
|
71
138
|
authModeStrategy: this.authModeStrategy,
|
|
72
139
|
defaultAuthMode: this.amplifyConfig.aws_appsync_authenticationType,
|
|
73
140
|
modelName: modelDefinition.name,
|
|
@@ -77,10 +144,10 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
77
144
|
modelAuthModes = _d.sent();
|
|
78
145
|
readAuthModes = modelAuthModes.READ;
|
|
79
146
|
authModeAttempts = 0;
|
|
80
|
-
authModeRetry = function () { return
|
|
147
|
+
authModeRetry = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
81
148
|
var response, error_1, authMode;
|
|
82
149
|
var _a;
|
|
83
|
-
return
|
|
150
|
+
return __generator(this, function (_b) {
|
|
84
151
|
switch (_b.label) {
|
|
85
152
|
case 0:
|
|
86
153
|
if (!this.runningProcesses.isOpen) {
|
|
@@ -89,7 +156,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
89
156
|
_b.label = 1;
|
|
90
157
|
case 1:
|
|
91
158
|
_b.trys.push([1, 3, , 5]);
|
|
92
|
-
logger.debug("Attempting sync with authMode: "
|
|
159
|
+
logger.debug("Attempting sync with authMode: ".concat(readAuthModes[authModeAttempts]));
|
|
93
160
|
return [4 /*yield*/, this.jitteredRetry({
|
|
94
161
|
query: query,
|
|
95
162
|
variables: variables,
|
|
@@ -100,17 +167,17 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
100
167
|
})];
|
|
101
168
|
case 2:
|
|
102
169
|
response = _b.sent();
|
|
103
|
-
logger.debug("Sync successful with authMode: "
|
|
170
|
+
logger.debug("Sync successful with authMode: ".concat(readAuthModes[authModeAttempts]));
|
|
104
171
|
return [2 /*return*/, response];
|
|
105
172
|
case 3:
|
|
106
173
|
error_1 = _b.sent();
|
|
107
174
|
authModeAttempts++;
|
|
108
175
|
if (authModeAttempts >= readAuthModes.length) {
|
|
109
176
|
authMode = readAuthModes[authModeAttempts - 1];
|
|
110
|
-
logger.debug("Sync failed with authMode: "
|
|
111
|
-
if (utils_1.getClientSideAuthError(error_1) || utils_1.getForbiddenError(error_1)) {
|
|
177
|
+
logger.debug("Sync failed with authMode: ".concat(authMode), error_1);
|
|
178
|
+
if ((0, utils_1.getClientSideAuthError)(error_1) || (0, utils_1.getForbiddenError)(error_1)) {
|
|
112
179
|
// return empty list of data so DataStore will continue to sync other models
|
|
113
|
-
logger.warn("User is unauthorized to query "
|
|
180
|
+
logger.warn("User is unauthorized to query ".concat(opName, " with auth mode ").concat(authMode, ". No data could be returned."));
|
|
114
181
|
return [2 /*return*/, {
|
|
115
182
|
data: (_a = {},
|
|
116
183
|
_a[opName] = opResultDefaults,
|
|
@@ -119,7 +186,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
119
186
|
}
|
|
120
187
|
throw error_1;
|
|
121
188
|
}
|
|
122
|
-
logger.debug("Sync failed with authMode: "
|
|
189
|
+
logger.debug("Sync failed with authMode: ".concat(readAuthModes[authModeAttempts - 1], ". Retrying with authMode: ").concat(readAuthModes[authModeAttempts]));
|
|
123
190
|
return [4 /*yield*/, authModeRetry()];
|
|
124
191
|
case 4: return [2 /*return*/, _b.sent()];
|
|
125
192
|
case 5: return [2 /*return*/];
|
|
@@ -142,24 +209,24 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
142
209
|
};
|
|
143
210
|
SyncProcessor.prototype.jitteredRetry = function (_a) {
|
|
144
211
|
var query = _a.query, variables = _a.variables, opName = _a.opName, modelDefinition = _a.modelDefinition, authMode = _a.authMode, onTerminate = _a.onTerminate;
|
|
145
|
-
return
|
|
212
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
213
|
var _this = this;
|
|
147
|
-
return
|
|
214
|
+
return __generator(this, function (_b) {
|
|
148
215
|
switch (_b.label) {
|
|
149
|
-
case 0: return [4 /*yield*/,
|
|
216
|
+
case 0: return [4 /*yield*/, (0, utils_2.jitteredExponentialRetry)(function (query, variables) { return __awaiter(_this, void 0, void 0, function () {
|
|
150
217
|
var authToken, customUserAgentDetails, error_2, clientOrForbiddenErrorMessage, hasItems, unauthorized, otherErrors, result;
|
|
151
218
|
var _this = this;
|
|
152
219
|
var _a, _b, _c, _d;
|
|
153
|
-
return
|
|
220
|
+
return __generator(this, function (_e) {
|
|
154
221
|
switch (_e.label) {
|
|
155
222
|
case 0:
|
|
156
223
|
_e.trys.push([0, 3, , 6]);
|
|
157
|
-
return [4 /*yield*/, utils_1.getTokenForCustomAuth(authMode, this.amplifyConfig)];
|
|
224
|
+
return [4 /*yield*/, (0, utils_1.getTokenForCustomAuth)(authMode, this.amplifyConfig)];
|
|
158
225
|
case 1:
|
|
159
226
|
authToken = _e.sent();
|
|
160
227
|
customUserAgentDetails = {
|
|
161
|
-
category:
|
|
162
|
-
action:
|
|
228
|
+
category: utils_2.Category.DataStore,
|
|
229
|
+
action: utils_2.DataStoreAction.GraphQl,
|
|
163
230
|
};
|
|
164
231
|
return [4 /*yield*/, this.amplifyContext.InternalAPI.graphql({
|
|
165
232
|
query: query,
|
|
@@ -170,10 +237,10 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
170
237
|
case 2: return [2 /*return*/, _e.sent()];
|
|
171
238
|
case 3:
|
|
172
239
|
error_2 = _e.sent();
|
|
173
|
-
clientOrForbiddenErrorMessage = utils_1.getClientSideAuthError(error_2) || utils_1.getForbiddenError(error_2);
|
|
240
|
+
clientOrForbiddenErrorMessage = (0, utils_1.getClientSideAuthError)(error_2) || (0, utils_1.getForbiddenError)(error_2);
|
|
174
241
|
if (clientOrForbiddenErrorMessage) {
|
|
175
242
|
logger.error('Sync processor retry error:', error_2);
|
|
176
|
-
throw new
|
|
243
|
+
throw new utils_2.NonRetryableError(clientOrForbiddenErrorMessage);
|
|
177
244
|
}
|
|
178
245
|
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);
|
|
179
246
|
unauthorized = (error_2 === null || error_2 === void 0 ? void 0 : error_2.errors) &&
|
|
@@ -185,9 +252,9 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
185
252
|
result.data[opName].items = result.data[opName].items.filter(function (item) { return item !== null; });
|
|
186
253
|
}
|
|
187
254
|
if (!(hasItems && (otherErrors === null || otherErrors === void 0 ? void 0 : otherErrors.length))) return [3 /*break*/, 5];
|
|
188
|
-
return [4 /*yield*/, Promise.all(otherErrors.map(function (err) { return
|
|
255
|
+
return [4 /*yield*/, Promise.all(otherErrors.map(function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
189
256
|
var e_1;
|
|
190
|
-
return
|
|
257
|
+
return __generator(this, function (_a) {
|
|
191
258
|
switch (_a.label) {
|
|
192
259
|
case 0:
|
|
193
260
|
_a.trys.push([0, 2, , 3]);
|
|
@@ -197,7 +264,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
197
264
|
message: err.message,
|
|
198
265
|
model: modelDefinition.name,
|
|
199
266
|
operation: opName,
|
|
200
|
-
errorType: errorMaps_1.getSyncErrorType(err),
|
|
267
|
+
errorType: (0, errorMaps_1.getSyncErrorType)(err),
|
|
201
268
|
process: types_1.ProcessName.sync,
|
|
202
269
|
remoteModel: null,
|
|
203
270
|
cause: err,
|
|
@@ -255,12 +322,12 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
255
322
|
message: error_2.message,
|
|
256
323
|
model: modelDefinition.name,
|
|
257
324
|
operation: opName,
|
|
258
|
-
errorType: errorMaps_1.getSyncErrorType(error_2.errors[0]),
|
|
325
|
+
errorType: (0, errorMaps_1.getSyncErrorType)(error_2.errors[0]),
|
|
259
326
|
process: types_1.ProcessName.sync,
|
|
260
327
|
remoteModel: null,
|
|
261
328
|
cause: error_2,
|
|
262
329
|
});
|
|
263
|
-
throw new
|
|
330
|
+
throw new utils_2.NonRetryableError(error_2);
|
|
264
331
|
}
|
|
265
332
|
if ((_d = (_c = result.data) === null || _c === void 0 ? void 0 : _c[opName].items) === null || _d === void 0 ? void 0 : _d.length) {
|
|
266
333
|
return [2 /*return*/, result];
|
|
@@ -283,7 +350,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
283
350
|
var sortedTypesLastSyncs = Object.values(_this.schema.namespaces).reduce(function (map, namespace) {
|
|
284
351
|
var e_2, _a;
|
|
285
352
|
try {
|
|
286
|
-
for (var _b =
|
|
353
|
+
for (var _b = __values(Array.from(namespace.modelTopologicalOrdering.keys())), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
287
354
|
var modelName = _c.value;
|
|
288
355
|
var typeLastSync = typesLastSync.get(namespace.models[modelName]);
|
|
289
356
|
map.set(namespace.models[modelName], typeLastSync);
|
|
@@ -300,16 +367,16 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
300
367
|
}, new Map());
|
|
301
368
|
var allModelsReady = Array.from(sortedTypesLastSyncs.entries())
|
|
302
369
|
.filter(function (_a) {
|
|
303
|
-
var _b =
|
|
370
|
+
var _b = __read(_a, 1), syncable = _b[0].syncable;
|
|
304
371
|
return syncable;
|
|
305
372
|
})
|
|
306
373
|
.map(function (_a) {
|
|
307
|
-
var _b =
|
|
374
|
+
var _b = __read(_a, 2), modelDefinition = _b[0], _c = __read(_b[1], 2), namespace = _c[0], lastSync = _c[1];
|
|
308
375
|
return _this.runningProcesses.isOpen &&
|
|
309
|
-
_this.runningProcesses.add(function (onTerminate) { return
|
|
376
|
+
_this.runningProcesses.add(function (onTerminate) { return __awaiter(_this, void 0, void 0, function () {
|
|
310
377
|
var done, nextToken, startedAt, items, recordsReceived, filter, parents, promises, promise;
|
|
311
378
|
var _this = this;
|
|
312
|
-
return
|
|
379
|
+
return __generator(this, function (_a) {
|
|
313
380
|
switch (_a.label) {
|
|
314
381
|
case 0:
|
|
315
382
|
done = false;
|
|
@@ -320,12 +387,12 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
320
387
|
filter = this.graphqlFilterFromPredicate(modelDefinition);
|
|
321
388
|
parents = this.schema.namespaces[namespace].modelTopologicalOrdering.get(modelDefinition.name);
|
|
322
389
|
promises = parents.map(function (parent) {
|
|
323
|
-
return parentPromises.get(namespace
|
|
390
|
+
return parentPromises.get("".concat(namespace, "_").concat(parent));
|
|
324
391
|
});
|
|
325
|
-
promise = new Promise(function (res) { return
|
|
392
|
+
promise = new Promise(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
326
393
|
var limit, error_3, e_3;
|
|
327
394
|
var _a;
|
|
328
|
-
return
|
|
395
|
+
return __generator(this, function (_b) {
|
|
329
396
|
switch (_b.label) {
|
|
330
397
|
case 0: return [4 /*yield*/, Promise.all(promises)];
|
|
331
398
|
case 1:
|
|
@@ -338,7 +405,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
338
405
|
* finished terminating and/or waiting for its background processes to complete.
|
|
339
406
|
*/
|
|
340
407
|
if (!this.runningProcesses.isOpen) {
|
|
341
|
-
logger.debug("Sync processor has been stopped, terminating sync for "
|
|
408
|
+
logger.debug("Sync processor has been stopped, terminating sync for ".concat(modelDefinition.name));
|
|
342
409
|
return [2 /*return*/, res()];
|
|
343
410
|
}
|
|
344
411
|
limit = Math.min(maxRecordsToSync - recordsReceived, syncPageSize);
|
|
@@ -360,7 +427,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
360
427
|
message: error_3.message,
|
|
361
428
|
model: modelDefinition.name,
|
|
362
429
|
operation: null,
|
|
363
|
-
errorType: errorMaps_1.getSyncErrorType(error_3),
|
|
430
|
+
errorType: (0, errorMaps_1.getSyncErrorType)(error_3),
|
|
364
431
|
process: types_1.ProcessName.sync,
|
|
365
432
|
remoteModel: null,
|
|
366
433
|
cause: error_3,
|
|
@@ -405,14 +472,14 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
405
472
|
}
|
|
406
473
|
});
|
|
407
474
|
}); });
|
|
408
|
-
parentPromises.set(namespace
|
|
475
|
+
parentPromises.set("".concat(namespace, "_").concat(modelDefinition.name), promise);
|
|
409
476
|
return [4 /*yield*/, promise];
|
|
410
477
|
case 1:
|
|
411
478
|
_a.sent();
|
|
412
479
|
return [2 /*return*/];
|
|
413
480
|
}
|
|
414
481
|
});
|
|
415
|
-
}); }, "adding model "
|
|
482
|
+
}); }, "adding model ".concat(modelDefinition.name));
|
|
416
483
|
});
|
|
417
484
|
Promise.all(allModelsReady).then(function () {
|
|
418
485
|
observer.complete();
|
|
@@ -421,8 +488,8 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
421
488
|
return observable;
|
|
422
489
|
};
|
|
423
490
|
SyncProcessor.prototype.stop = function () {
|
|
424
|
-
return
|
|
425
|
-
return
|
|
491
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
492
|
+
return __generator(this, function (_a) {
|
|
426
493
|
switch (_a.label) {
|
|
427
494
|
case 0:
|
|
428
495
|
logger.debug('stopping sync processor');
|
|
@@ -441,4 +508,3 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
441
508
|
return SyncProcessor;
|
|
442
509
|
}());
|
|
443
510
|
exports.SyncProcessor = SyncProcessor;
|
|
444
|
-
//# sourceMappingURL=sync.js.map
|
package/lib/sync/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
|
|
2
1
|
import { GraphQLAuthError } from '@aws-amplify/api';
|
|
2
|
+
import { GraphQLAuthModeKeys } from '@aws-amplify/core/internals/utils';
|
|
3
3
|
import { ModelInstanceCreator } from '../datastore/datastore';
|
|
4
4
|
import { AuthorizationRule, GraphQLCondition, GraphQLFilter, ModelInstanceMetadata, OpType, PersistentModel, PersistentModelConstructor, PredicatesGroup, RelationshipType, SchemaModel, SchemaNamespace, SchemaNonModel, ModelOperation, InternalSchema, AuthModeStrategy } from '../types';
|
|
5
5
|
import { MutationEvent } from './';
|
|
@@ -93,14 +93,14 @@ export declare function getUserGroupsFromToken(token: {
|
|
|
93
93
|
}, rule: AuthorizationRule): string[];
|
|
94
94
|
export declare function getModelAuthModes({ authModeStrategy, defaultAuthMode, modelName, schema, }: {
|
|
95
95
|
authModeStrategy: AuthModeStrategy;
|
|
96
|
-
defaultAuthMode:
|
|
96
|
+
defaultAuthMode: GraphQLAuthModeKeys;
|
|
97
97
|
modelName: string;
|
|
98
98
|
schema: InternalSchema;
|
|
99
99
|
}): Promise<{
|
|
100
|
-
[key in ModelOperation]:
|
|
100
|
+
[key in ModelOperation]: GraphQLAuthModeKeys[];
|
|
101
101
|
}>;
|
|
102
102
|
export declare function getForbiddenError(error: any): any;
|
|
103
103
|
export declare function getClientSideAuthError(error: any): GraphQLAuthError;
|
|
104
|
-
export declare function getTokenForCustomAuth(authMode:
|
|
104
|
+
export declare function getTokenForCustomAuth(authMode: GraphQLAuthModeKeys, amplifyConfig?: Record<string, any>): Promise<string | undefined>;
|
|
105
105
|
export declare function getIdentifierValue(modelDefinition: SchemaModel, model: ModelInstanceMetadata | PersistentModel): string;
|
|
106
106
|
export {};
|