@aws-amplify/datastore 5.0.1-api-v6-models.8035dfc.0 → 5.0.1-api-v6-models.572a7b5.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/lib/authModeStrategies/multiAuthStrategy.js +6 -2
- package/lib/datastore/datastore.js +11 -10
- package/lib/storage/adapter/IndexedDBAdapter.js +2 -2
- package/lib/storage/adapter/StorageAdapterBase.js +2 -2
- package/lib/storage/storage.js +2 -1
- package/lib/sync/datastoreConnectivity.js +2 -2
- package/lib/sync/index.js +1 -1
- package/lib/sync/processors/errorMaps.js +5 -7
- package/lib/sync/processors/mutation.js +2 -1
- package/lib/sync/processors/subscription.js +10 -11
- package/lib/sync/processors/sync.js +11 -11
- package/lib/sync/utils.d.ts +1 -0
- package/lib/sync/utils.js +20 -9
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/util.js +4 -4
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +6 -2
- package/lib-esm/datastore/datastore.js +7 -6
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +2 -2
- package/lib-esm/storage/adapter/StorageAdapterBase.js +2 -2
- package/lib-esm/storage/storage.js +3 -2
- package/lib-esm/sync/datastoreConnectivity.js +2 -2
- package/lib-esm/sync/index.js +3 -3
- package/lib-esm/sync/processors/errorMaps.js +5 -7
- package/lib-esm/sync/processors/mutation.js +3 -2
- package/lib-esm/sync/processors/subscription.js +12 -13
- package/lib-esm/sync/processors/sync.js +13 -13
- package/lib-esm/sync/utils.d.ts +1 -0
- package/lib-esm/sync/utils.js +18 -8
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/util.js +4 -4
- package/package.json +9 -10
- package/src/authModeStrategies/multiAuthStrategy.ts +5 -1
- package/src/datastore/datastore.ts +7 -9
- package/src/storage/adapter/IndexedDBAdapter.ts +2 -2
- package/src/storage/adapter/StorageAdapterBase.ts +2 -2
- package/src/storage/storage.ts +3 -2
- package/src/sync/datastoreConnectivity.ts +2 -2
- package/src/sync/index.ts +4 -7
- package/src/sync/processors/errorMaps.ts +7 -7
- package/src/sync/processors/mutation.ts +2 -2
- package/src/sync/processors/subscription.ts +11 -7
- package/src/sync/processors/sync.ts +3 -4
- package/src/sync/utils.ts +24 -8
- package/src/util.ts +4 -4
package/lib/util.js
CHANGED
|
@@ -88,7 +88,7 @@ exports.getTimestampFields = exports.getIndexKeys = exports.keysEqual = exports.
|
|
|
88
88
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
89
89
|
// SPDX-License-Identifier: Apache-2.0
|
|
90
90
|
var ulid_1 = require("ulid");
|
|
91
|
-
var
|
|
91
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
92
92
|
var immer_1 = require("immer");
|
|
93
93
|
var types_1 = require("./types");
|
|
94
94
|
var predicates_1 = require("./predicates");
|
|
@@ -241,7 +241,7 @@ exports.traverseModel = traverseModel;
|
|
|
241
241
|
var privateModeCheckResult;
|
|
242
242
|
var isPrivateMode = function () {
|
|
243
243
|
return new Promise(function (resolve) {
|
|
244
|
-
var dbname = (0,
|
|
244
|
+
var dbname = (0, utils_1.amplifyUuid)();
|
|
245
245
|
var db;
|
|
246
246
|
var isPrivate = function () {
|
|
247
247
|
privateModeCheckResult = false;
|
|
@@ -295,7 +295,7 @@ var isSafariCompatabilityMode = function () { return __awaiter(void 0, void 0, v
|
|
|
295
295
|
switch (_c.label) {
|
|
296
296
|
case 0:
|
|
297
297
|
_c.trys.push([0, 6, , 7]);
|
|
298
|
-
dbName_1 = (0,
|
|
298
|
+
dbName_1 = (0, utils_1.amplifyUuid)();
|
|
299
299
|
storeName_1 = 'indexedDBFeatureProbeStore';
|
|
300
300
|
indexName_1 = 'idx';
|
|
301
301
|
if (indexedDB === null)
|
|
@@ -699,7 +699,7 @@ var isAWSJSON = function (val) {
|
|
|
699
699
|
exports.isAWSJSON = isAWSJSON;
|
|
700
700
|
var isAWSURL = function (val) {
|
|
701
701
|
try {
|
|
702
|
-
return !!new
|
|
702
|
+
return !!new utils_1.AmplifyUrl(val);
|
|
703
703
|
}
|
|
704
704
|
catch (_c) {
|
|
705
705
|
return false;
|
|
@@ -169,7 +169,7 @@ export var multiAuthStrategy = function (amplifyContext) {
|
|
|
169
169
|
return function (_a) {
|
|
170
170
|
var schema = _a.schema, modelName = _a.modelName;
|
|
171
171
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
172
|
-
var currentUser, e_1, attributes, authAttribute, sortedRules;
|
|
172
|
+
var currentUser, authSession, e_1, attributes, authAttribute, sortedRules;
|
|
173
173
|
var _b;
|
|
174
174
|
return __generator(this, function (_c) {
|
|
175
175
|
switch (_c.label) {
|
|
@@ -177,7 +177,11 @@ export var multiAuthStrategy = function (amplifyContext) {
|
|
|
177
177
|
_c.trys.push([0, 2, , 3]);
|
|
178
178
|
return [4 /*yield*/, fetchAuthSession()];
|
|
179
179
|
case 1:
|
|
180
|
-
|
|
180
|
+
authSession = _c.sent();
|
|
181
|
+
if (authSession.tokens.accessToken) {
|
|
182
|
+
// the user is authenticated
|
|
183
|
+
currentUser = authSession;
|
|
184
|
+
}
|
|
181
185
|
return [3 /*break*/, 3];
|
|
182
186
|
case 2:
|
|
183
187
|
e_1 = _c.sent();
|
|
@@ -117,9 +117,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
117
117
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
118
118
|
// SPDX-License-Identifier: Apache-2.0
|
|
119
119
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
120
|
-
import { Amplify, Hub, Cache } from '@aws-amplify/core';
|
|
120
|
+
import { Amplify, Hub, Cache, ConsoleLogger } from '@aws-amplify/core';
|
|
121
121
|
import { immerable, produce, setAutoFreeze, enablePatches, } from 'immer';
|
|
122
|
-
import {
|
|
122
|
+
import { amplifyUuid } from '@aws-amplify/core/internals/utils';
|
|
123
123
|
import { Observable, filter } from 'rxjs';
|
|
124
124
|
import { defaultAuthStrategy, multiAuthStrategy } from '../authModeStrategies';
|
|
125
125
|
import { isPredicatesAll, ModelPredicateCreator, ModelSortPredicateCreator, } from '../predicates';
|
|
@@ -130,10 +130,10 @@ import { GraphQLScalarType, isGraphQLScalarType, isSchemaModelWithAttributes, Au
|
|
|
130
130
|
import { DATASTORE, errorMessages, establishRelationAndKeys, isModelConstructor, monotonicUlidFactory, STORAGE, SYNC, USER, isNullOrUndefined, registerNonModelClass, sortCompareFunction, DeferredCallbackResolver, inMemoryPagination, extractPrimaryKeyFieldNames, extractPrimaryKeysAndValues, isIdManaged, isIdOptionallyManaged, mergePatches, getTimestampFields, } from '../util';
|
|
131
131
|
import { recursivePredicateFor, predicateFor, internals, } from '../predicates/next';
|
|
132
132
|
import { getIdentifierValue } from '../sync/utils';
|
|
133
|
-
import { BackgroundProcessManager
|
|
133
|
+
import { BackgroundProcessManager } from '@aws-amplify/core/internals/utils';
|
|
134
134
|
setAutoFreeze(true);
|
|
135
135
|
enablePatches();
|
|
136
|
-
var logger = new
|
|
136
|
+
var logger = new ConsoleLogger('DataStore');
|
|
137
137
|
var ulid = monotonicUlidFactory(Date.now());
|
|
138
138
|
var SETTING_SCHEMA_VERSION = 'schemaVersion';
|
|
139
139
|
var schema;
|
|
@@ -710,13 +710,14 @@ var createModelClass = function (modelDefinition) {
|
|
|
710
710
|
var id = isInternalModel
|
|
711
711
|
? _id
|
|
712
712
|
: modelDefinition.syncable
|
|
713
|
-
?
|
|
713
|
+
? amplifyUuid()
|
|
714
714
|
: ulid();
|
|
715
715
|
draft.id = id;
|
|
716
716
|
}
|
|
717
717
|
else if (isIdOptionallyManaged(modelDefinition)) {
|
|
718
718
|
// only auto-populate if the id was not provided
|
|
719
|
-
draft.id =
|
|
719
|
+
draft.id =
|
|
720
|
+
draft.id || amplifyUuid();
|
|
720
721
|
}
|
|
721
722
|
if (!isInternallyInitialized) {
|
|
722
723
|
checkReadOnlyPropertyOnCreate(draft, modelDefinition);
|
|
@@ -98,8 +98,8 @@ import * as idb from 'idb';
|
|
|
98
98
|
import { isPredicateObj, isPredicateGroup, OpType, QueryOne, } from '../../types';
|
|
99
99
|
import { isPrivateMode, traverseModel, validatePredicate, inMemoryPagination, keysEqual, getStorename, isSafariCompatabilityMode, } from '../../util';
|
|
100
100
|
import { StorageAdapterBase } from './StorageAdapterBase';
|
|
101
|
-
import {
|
|
102
|
-
var logger = new
|
|
101
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
102
|
+
var logger = new ConsoleLogger('DataStore');
|
|
103
103
|
/**
|
|
104
104
|
* The point after which queries composed of multiple simple OR conditions
|
|
105
105
|
* should scan-and-filter instead of individual queries for each condition.
|
|
@@ -56,8 +56,8 @@ import { ModelPredicateCreator } from '../../predicates';
|
|
|
56
56
|
import { isPredicateObj, } from '../../types';
|
|
57
57
|
import { getStorename, getIndexKeys, extractPrimaryKeyValues, traverseModel, validatePredicate, isModelConstructor, extractPrimaryKeyFieldNames, } from '../../util';
|
|
58
58
|
import { ModelRelationship } from '../relationship';
|
|
59
|
-
import {
|
|
60
|
-
var logger = new
|
|
59
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
60
|
+
var logger = new ConsoleLogger('DataStore');
|
|
61
61
|
var DB_NAME = 'amplify-datastore';
|
|
62
62
|
var StorageAdapterBase = /** @class */ (function () {
|
|
63
63
|
function StorageAdapterBase() {
|
|
@@ -91,8 +91,9 @@ import { OpType, QueryOne, isTargetNameAssociation, } from '../types';
|
|
|
91
91
|
import { isModelConstructor, STORAGE, validatePredicate, valuesEqual, } from '../util';
|
|
92
92
|
import { getIdentifierValue } from '../sync/utils';
|
|
93
93
|
import getDefaultAdapter from './adapter/getDefaultAdapter';
|
|
94
|
-
import {
|
|
95
|
-
|
|
94
|
+
import { Mutex } from '@aws-amplify/core/internals/utils';
|
|
95
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
96
|
+
var logger = new ConsoleLogger('DataStore');
|
|
96
97
|
var StorageClass = /** @class */ (function () {
|
|
97
98
|
function StorageClass(schema, namespaceResolver, getModelConstructorByModelName, modelInstanceCreator, adapter, sessionId) {
|
|
98
99
|
this.schema = schema;
|
|
@@ -49,8 +49,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
49
49
|
// SPDX-License-Identifier: Apache-2.0
|
|
50
50
|
import { Observable } from 'rxjs';
|
|
51
51
|
import { ReachabilityMonitor } from './datastoreReachability';
|
|
52
|
-
import {
|
|
53
|
-
var logger = new
|
|
52
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
53
|
+
var logger = new ConsoleLogger('DataStore');
|
|
54
54
|
var RECONNECTING_IN = 5000; // 5s this may be configurable in the future
|
|
55
55
|
var DataStoreConnectivity = /** @class */ (function () {
|
|
56
56
|
function DataStoreConnectivity() {
|
package/lib-esm/sync/index.js
CHANGED
|
@@ -72,8 +72,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
72
72
|
};
|
|
73
73
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
74
74
|
// SPDX-License-Identifier: Apache-2.0
|
|
75
|
-
import {
|
|
76
|
-
import { Hub } from '@aws-amplify/core';
|
|
75
|
+
import { BackgroundProcessManager } from '@aws-amplify/core/internals/utils';
|
|
76
|
+
import { Hub, ConsoleLogger } from '@aws-amplify/core';
|
|
77
77
|
import { filter, Observable, of } from 'rxjs';
|
|
78
78
|
import { ModelPredicateCreator } from '../predicates';
|
|
79
79
|
import { OpType, } from '../types';
|
|
@@ -86,7 +86,7 @@ import { CONTROL_MSG, SubscriptionProcessor } from './processors/subscription';
|
|
|
86
86
|
import { SyncProcessor } from './processors/sync';
|
|
87
87
|
import { createMutationInstanceFromModelOperation, getIdentifierValue, predicateToGraphQLCondition, } from './utils';
|
|
88
88
|
import { CONTROL_MSG as PUBSUB_CONTROL_MSG, ConnectionState, CONNECTION_STATE_CHANGE as PUBSUB_CONNECTION_STATE_CHANGE, } from '@aws-amplify/api-graphql';
|
|
89
|
-
var logger = new
|
|
89
|
+
var logger = new ConsoleLogger('DataStore');
|
|
90
90
|
var ownSymbol = Symbol('sync');
|
|
91
91
|
export var ControlMessage;
|
|
92
92
|
(function (ControlMessage) {
|
|
@@ -34,12 +34,11 @@ var __values = (this && this.__values) || function(o) {
|
|
|
34
34
|
};
|
|
35
35
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
36
36
|
};
|
|
37
|
+
import { resolveServiceErrorStatusCode } from '../utils';
|
|
37
38
|
var connectionTimeout = function (error) {
|
|
38
39
|
return /^Connection failed: Connection Timeout/.test(error.message);
|
|
39
40
|
};
|
|
40
|
-
var serverError = function (error) {
|
|
41
|
-
return /^Error: Request failed with status code 5\d\d/.test(error.message);
|
|
42
|
-
};
|
|
41
|
+
var serverError = function (error) { return resolveServiceErrorStatusCode(error) >= 500; };
|
|
43
42
|
export var mutationErrorMap = {
|
|
44
43
|
BadModel: function () { return false; },
|
|
45
44
|
BadRecord: function (error) {
|
|
@@ -51,7 +50,7 @@ export var mutationErrorMap = {
|
|
|
51
50
|
Transient: function (error) { return connectionTimeout(error) || serverError(error); },
|
|
52
51
|
Unauthorized: function (error) {
|
|
53
52
|
return error.message === 'Unauthorized' ||
|
|
54
|
-
|
|
53
|
+
resolveServiceErrorStatusCode(error) === 401;
|
|
55
54
|
},
|
|
56
55
|
};
|
|
57
56
|
export var subscriptionErrorMap = {
|
|
@@ -81,9 +80,8 @@ export var syncErrorMap = {
|
|
|
81
80
|
* @param observableError an error from ZenObservable subscribe error callback
|
|
82
81
|
*/
|
|
83
82
|
function unwrapObservableError(observableError) {
|
|
84
|
-
var _a
|
|
85
|
-
|
|
86
|
-
} : _a, _c = __read(_b.errors, 1), error = _c[0];
|
|
83
|
+
var _a;
|
|
84
|
+
var _b = __read((_a = __read(observableError.errors, 0), observableError).errors, 1), error = _b[0];
|
|
87
85
|
return error;
|
|
88
86
|
}
|
|
89
87
|
export function getMutationErrorType(error) {
|
|
@@ -84,14 +84,15 @@ var __values = (this && this.__values) || function(o) {
|
|
|
84
84
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
85
85
|
};
|
|
86
86
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
87
|
-
import { Category,
|
|
87
|
+
import { Category, DataStoreAction, jitteredBackoff, NonRetryableError, retry, BackgroundProcessManager, } from '@aws-amplify/core/internals/utils';
|
|
88
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
88
89
|
import { Observable } from 'rxjs';
|
|
89
90
|
import { DISCARD, isModelFieldType, isTargetNameAssociation, OpType, ProcessName, } from '../../types';
|
|
90
91
|
import { extractTargetNamesFromSrc, USER, ID } from '../../util';
|
|
91
92
|
import { buildGraphQLOperation, createMutationInstanceFromModelOperation, getModelAuthModes, TransformerMutationType, getTokenForCustomAuth, } from '../utils';
|
|
92
93
|
import { getMutationErrorType } from './errorMaps';
|
|
93
94
|
var MAX_ATTEMPTS = 10;
|
|
94
|
-
var logger = new
|
|
95
|
+
var logger = new ConsoleLogger('DataStore');
|
|
95
96
|
var MutationProcessor = /** @class */ (function () {
|
|
96
97
|
function MutationProcessor(schema, storage, userClasses, outbox, modelInstanceCreator, MutationEvent, amplifyConfig, authModeStrategy, errorHandler, conflictHandler, amplifyContext) {
|
|
97
98
|
if (amplifyConfig === void 0) { amplifyConfig = {}; }
|
|
@@ -71,8 +71,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
71
71
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
72
72
|
};
|
|
73
73
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
74
|
-
import { Hub, fetchAuthSession } from '@aws-amplify/core';
|
|
75
|
-
import { Category,
|
|
74
|
+
import { Hub, fetchAuthSession, ConsoleLogger, } from '@aws-amplify/core';
|
|
75
|
+
import { Category, DataStoreAction, BackgroundProcessManager, } from '@aws-amplify/core/internals/utils';
|
|
76
76
|
import { Observable } from 'rxjs';
|
|
77
77
|
import { ProcessName, } from '../../types';
|
|
78
78
|
import { buildSubscriptionGraphQLOperation, getAuthorizationRules, getModelAuthModes, getUserGroupsFromToken, TransformerMutationType, getTokenForCustomAuth, predicateToGraphQLFilter, RTFError, generateRTFRemediation, } from '../utils';
|
|
@@ -80,7 +80,7 @@ import { ModelPredicateCreator } from '../../predicates';
|
|
|
80
80
|
import { validatePredicate } from '../../util';
|
|
81
81
|
import { getSubscriptionErrorType } from './errorMaps';
|
|
82
82
|
import { CONTROL_MSG as PUBSUB_CONTROL_MSG } from '@aws-amplify/api-graphql';
|
|
83
|
-
var logger = new
|
|
83
|
+
var logger = new ConsoleLogger('DataStore');
|
|
84
84
|
export var CONTROL_MSG;
|
|
85
85
|
(function (CONTROL_MSG) {
|
|
86
86
|
CONTROL_MSG["CONNECTED"] = "CONNECTED";
|
|
@@ -325,13 +325,12 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
325
325
|
_this.drainBuffer();
|
|
326
326
|
},
|
|
327
327
|
error: function (subscriptionError) { return __awaiter(_this, void 0, void 0, function () {
|
|
328
|
-
var _a, _b, _c, _d,
|
|
329
|
-
|
|
330
|
-
|
|
328
|
+
var _a, _b, _c, _d, message, isRTFError, e_1;
|
|
329
|
+
var _e;
|
|
330
|
+
return __generator(this, function (_f) {
|
|
331
|
+
switch (_f.label) {
|
|
331
332
|
case 0:
|
|
332
|
-
_a = subscriptionError.
|
|
333
|
-
errors: [],
|
|
334
|
-
} : _a, _c = __read(_b.errors, 1), _d = _c[0], _e = _d === void 0 ? {} : _d, _f = _e.message, message = _f === void 0 ? '' : _f;
|
|
333
|
+
_a = __read((_e = __read(subscriptionError.errors, 0), subscriptionError).errors, 1), _b = _a[0], _c = _b === void 0 ? {} : _b, _d = _c.message, message = _d === void 0 ? '' : _d;
|
|
335
334
|
isRTFError =
|
|
336
335
|
// only attempt catch if a filter variable was added to the subscription query
|
|
337
336
|
addFilter &&
|
|
@@ -369,9 +368,9 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
369
368
|
}
|
|
370
369
|
}
|
|
371
370
|
logger.warn('subscriptionError', message);
|
|
372
|
-
|
|
371
|
+
_f.label = 1;
|
|
373
372
|
case 1:
|
|
374
|
-
|
|
373
|
+
_f.trys.push([1, 3, , 4]);
|
|
375
374
|
return [4 /*yield*/, this.errorHandler({
|
|
376
375
|
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',
|
|
377
376
|
localModel: null,
|
|
@@ -384,10 +383,10 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
384
383
|
cause: subscriptionError,
|
|
385
384
|
})];
|
|
386
385
|
case 2:
|
|
387
|
-
|
|
386
|
+
_f.sent();
|
|
388
387
|
return [3 /*break*/, 4];
|
|
389
388
|
case 3:
|
|
390
|
-
e_1 =
|
|
389
|
+
e_1 = _f.sent();
|
|
391
390
|
logger.error('Subscription error handler failed with:', e_1);
|
|
392
391
|
return [3 /*break*/, 4];
|
|
393
392
|
case 4:
|
|
@@ -65,8 +65,8 @@ import { InternalAPI } from '@aws-amplify/api/internals';
|
|
|
65
65
|
import { Observable } from 'rxjs';
|
|
66
66
|
import { ProcessName, } from '../../types';
|
|
67
67
|
import { buildGraphQLOperation, getModelAuthModes, getClientSideAuthError, getForbiddenError, predicateToGraphQLFilter, getTokenForCustomAuth, } from '../utils';
|
|
68
|
-
import { jitteredExponentialRetry, Category,
|
|
69
|
-
import { Hub } from '@aws-amplify/core';
|
|
68
|
+
import { jitteredExponentialRetry, Category, DataStoreAction, NonRetryableError, BackgroundProcessManager, } from '@aws-amplify/core/internals/utils';
|
|
69
|
+
import { Hub, ConsoleLogger } from '@aws-amplify/core';
|
|
70
70
|
import { ModelPredicateCreator } from '../../predicates';
|
|
71
71
|
import { getSyncErrorType } from './errorMaps';
|
|
72
72
|
var opResultDefaults = {
|
|
@@ -74,7 +74,7 @@ var opResultDefaults = {
|
|
|
74
74
|
nextToken: null,
|
|
75
75
|
startedAt: null,
|
|
76
76
|
};
|
|
77
|
-
var logger = new
|
|
77
|
+
var logger = new ConsoleLogger('DataStore');
|
|
78
78
|
var SyncProcessor = /** @class */ (function () {
|
|
79
79
|
function SyncProcessor(schema, syncPredicates, amplifyConfig, authModeStrategy, errorHandler, amplifyContext) {
|
|
80
80
|
if (amplifyConfig === void 0) { amplifyConfig = {}; }
|
|
@@ -210,14 +210,14 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
210
210
|
case 0: return [4 /*yield*/, jitteredExponentialRetry(function (query, variables) { return __awaiter(_this, void 0, void 0, function () {
|
|
211
211
|
var authToken, customUserAgentDetails, error_2, clientOrForbiddenErrorMessage, hasItems, unauthorized, otherErrors, result;
|
|
212
212
|
var _this = this;
|
|
213
|
-
var _a, _b, _c, _d;
|
|
214
|
-
return __generator(this, function (
|
|
215
|
-
switch (
|
|
213
|
+
var _a, _b, _c, _d, _e;
|
|
214
|
+
return __generator(this, function (_f) {
|
|
215
|
+
switch (_f.label) {
|
|
216
216
|
case 0:
|
|
217
|
-
|
|
217
|
+
_f.trys.push([0, 3, , 6]);
|
|
218
218
|
return [4 /*yield*/, getTokenForCustomAuth(authMode, this.amplifyConfig)];
|
|
219
219
|
case 1:
|
|
220
|
-
authToken =
|
|
220
|
+
authToken = _f.sent();
|
|
221
221
|
customUserAgentDetails = {
|
|
222
222
|
category: Category.DataStore,
|
|
223
223
|
action: DataStoreAction.GraphQl,
|
|
@@ -228,9 +228,9 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
228
228
|
authMode: authMode,
|
|
229
229
|
authToken: authToken,
|
|
230
230
|
}, undefined, customUserAgentDetails)];
|
|
231
|
-
case 2: return [2 /*return*/,
|
|
231
|
+
case 2: return [2 /*return*/, _f.sent()];
|
|
232
232
|
case 3:
|
|
233
|
-
error_2 =
|
|
233
|
+
error_2 = _f.sent();
|
|
234
234
|
clientOrForbiddenErrorMessage = getClientSideAuthError(error_2) || getForbiddenError(error_2);
|
|
235
235
|
if (clientOrForbiddenErrorMessage) {
|
|
236
236
|
logger.error('Sync processor retry error:', error_2);
|
|
@@ -275,7 +275,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
275
275
|
});
|
|
276
276
|
}); }))];
|
|
277
277
|
case 4:
|
|
278
|
-
|
|
278
|
+
_f.sent();
|
|
279
279
|
Hub.dispatch('datastore', {
|
|
280
280
|
event: 'nonApplicableDataReceived',
|
|
281
281
|
data: {
|
|
@@ -283,7 +283,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
283
283
|
modelName: modelDefinition.name,
|
|
284
284
|
},
|
|
285
285
|
});
|
|
286
|
-
|
|
286
|
+
_f.label = 5;
|
|
287
287
|
case 5:
|
|
288
288
|
/**
|
|
289
289
|
* Handle $util.unauthorized() in resolver request mapper, which responses with something
|
|
@@ -323,7 +323,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
323
323
|
});
|
|
324
324
|
throw new NonRetryableError(error_2);
|
|
325
325
|
}
|
|
326
|
-
if ((_d = (_c = result.data) === null || _c === void 0 ? void 0 : _c[opName]
|
|
326
|
+
if ((_e = (_d = (_c = result.data) === null || _c === void 0 ? void 0 : _c[opName]) === null || _d === void 0 ? void 0 : _d.items) === null || _e === void 0 ? void 0 : _e.length) {
|
|
327
327
|
return [2 /*return*/, result];
|
|
328
328
|
}
|
|
329
329
|
throw error_2;
|
package/lib-esm/sync/utils.d.ts
CHANGED
|
@@ -100,6 +100,7 @@ export declare function getModelAuthModes({ authModeStrategy, defaultAuthMode, m
|
|
|
100
100
|
[key in ModelOperation]: GraphQLAuthMode[];
|
|
101
101
|
}>;
|
|
102
102
|
export declare function getForbiddenError(error: any): any;
|
|
103
|
+
export declare function resolveServiceErrorStatusCode(error: unknown): number | null;
|
|
103
104
|
export declare function getClientSideAuthError(error: any): GraphQLAuthError;
|
|
104
105
|
export declare function getTokenForCustomAuth(authMode: GraphQLAuthMode, amplifyConfig?: Record<string, any>): Promise<string | undefined>;
|
|
105
106
|
export declare function getIdentifierValue(modelDefinition: SchemaModel, model: ModelInstanceMetadata | PersistentModel): string;
|
package/lib-esm/sync/utils.js
CHANGED
|
@@ -84,10 +84,10 @@ var __values = (this && this.__values) || function(o) {
|
|
|
84
84
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
85
85
|
// SPDX-License-Identifier: Apache-2.0
|
|
86
86
|
import { GraphQLAuthError } from '@aws-amplify/api';
|
|
87
|
-
import {
|
|
87
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
88
88
|
import { isEnumFieldType, isGraphQLScalarType, isPredicateObj, isSchemaModel, isSchemaModelWithAttributes, isTargetNameAssociation, isNonModelFieldType, OpType, ModelOperation, isPredicateGroup, } from '../types';
|
|
89
89
|
import { extractPrimaryKeyFieldNames, establishRelationAndKeys, IDENTIFIER_KEY_SEPARATOR, } from '../util';
|
|
90
|
-
var logger = new
|
|
90
|
+
var logger = new ConsoleLogger('DataStore');
|
|
91
91
|
var GraphQLOperationType;
|
|
92
92
|
(function (GraphQLOperationType) {
|
|
93
93
|
GraphQLOperationType["LIST"] = "query";
|
|
@@ -747,24 +747,34 @@ export function getModelAuthModes(_a) {
|
|
|
747
747
|
});
|
|
748
748
|
}
|
|
749
749
|
export function getForbiddenError(error) {
|
|
750
|
-
var
|
|
751
|
-
|
|
752
|
-
'Request failed with status code 403',
|
|
753
|
-
];
|
|
750
|
+
var _a;
|
|
751
|
+
var forbiddenErrorCodes = [401, 403];
|
|
754
752
|
var forbiddenError;
|
|
755
753
|
if (error && error.errors) {
|
|
756
754
|
forbiddenError = error.errors.find(function (err) {
|
|
757
|
-
return
|
|
755
|
+
return forbiddenErrorCodes.includes(resolveServiceErrorStatusCode(err));
|
|
758
756
|
});
|
|
759
757
|
}
|
|
760
758
|
else if (error && error.message) {
|
|
761
759
|
forbiddenError = error;
|
|
762
760
|
}
|
|
763
761
|
if (forbiddenError) {
|
|
764
|
-
return forbiddenError.message;
|
|
762
|
+
return ((_a = forbiddenError.message) !== null && _a !== void 0 ? _a : "Request failed with status code ".concat(resolveServiceErrorStatusCode(forbiddenError)));
|
|
765
763
|
}
|
|
766
764
|
return null;
|
|
767
765
|
}
|
|
766
|
+
export function resolveServiceErrorStatusCode(error) {
|
|
767
|
+
var _a, _b;
|
|
768
|
+
if ((_a = error === null || error === void 0 ? void 0 : error['$metadata']) === null || _a === void 0 ? void 0 : _a['httpStatusCode']) {
|
|
769
|
+
return Number((_b = error === null || error === void 0 ? void 0 : error['$metadata']) === null || _b === void 0 ? void 0 : _b['httpStatusCode']);
|
|
770
|
+
}
|
|
771
|
+
else if (error === null || error === void 0 ? void 0 : error.originalError) {
|
|
772
|
+
return resolveServiceErrorStatusCode(error === null || error === void 0 ? void 0 : error.originalError);
|
|
773
|
+
}
|
|
774
|
+
else {
|
|
775
|
+
return null;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
768
778
|
export function getClientSideAuthError(error) {
|
|
769
779
|
var clientSideAuthErrors = Object.values(GraphQLAuthError);
|
|
770
780
|
var clientSideError = error &&
|