@aws-amplify/datastore 3.11.2-unstable.1 → 3.11.2
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 +11 -0
- package/dist/aws-amplify-datastore.js +180 -123
- package/dist/aws-amplify-datastore.js.map +1 -1
- package/dist/aws-amplify-datastore.min.js +8 -8
- package/dist/aws-amplify-datastore.min.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.js +2 -2
- package/lib/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib/sync/processors/errorMaps.d.ts +17 -0
- package/lib/sync/processors/errorMaps.js +98 -0
- package/lib/sync/processors/errorMaps.js.map +1 -0
- package/lib/sync/processors/mutation.js +2 -5
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.js +2 -11
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.js +2 -5
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.d.ts +1 -11
- package/lib/sync/utils.js +0 -59
- package/lib/sync/utils.js.map +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.js +2 -2
- package/lib-esm/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.d.ts +17 -0
- package/lib-esm/sync/processors/errorMaps.js +92 -0
- package/lib-esm/sync/processors/errorMaps.js.map +1 -0
- package/lib-esm/sync/processors/mutation.js +3 -6
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.js +3 -12
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.js +3 -6
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.d.ts +1 -11
- package/lib-esm/sync/utils.js +0 -58
- package/lib-esm/sync/utils.js.map +1 -1
- package/package.json +9 -8
- package/src/storage/adapter/InMemoryStore.ts +2 -2
- package/src/sync/processors/errorMaps.ts +63 -0
- package/src/sync/processors/mutation.ts +2 -8
- package/src/sync/processors/subscription.ts +3 -19
- package/src/sync/processors/sync.ts +2 -8
- package/src/sync/utils.ts +0 -22
|
@@ -34,19 +34,13 @@ import {
|
|
|
34
34
|
getModelAuthModes,
|
|
35
35
|
TransformerMutationType,
|
|
36
36
|
getTokenForCustomAuth,
|
|
37
|
-
ErrorMap,
|
|
38
|
-
mapErrorToType,
|
|
39
37
|
} from '../utils';
|
|
38
|
+
import { getMutationErrorType } from './errorMaps';
|
|
40
39
|
|
|
41
40
|
const MAX_ATTEMPTS = 10;
|
|
42
41
|
|
|
43
42
|
const logger = new Logger('DataStore');
|
|
44
43
|
|
|
45
|
-
// TODO: add additional error maps
|
|
46
|
-
const errorMap = {
|
|
47
|
-
BadRecord: error => /^Cannot return \w+ for [\w-_]+ type/.test(error.message),
|
|
48
|
-
} as ErrorMap;
|
|
49
|
-
|
|
50
44
|
type MutationProcessorEvent = {
|
|
51
45
|
operation: TransformerMutationType;
|
|
52
46
|
modelDefinition: SchemaModel;
|
|
@@ -386,7 +380,7 @@ class MutationProcessor {
|
|
|
386
380
|
localModel: variables.input,
|
|
387
381
|
message: error.message,
|
|
388
382
|
operation,
|
|
389
|
-
errorType:
|
|
383
|
+
errorType: getMutationErrorType(error),
|
|
390
384
|
errorInfo: error.errorInfo,
|
|
391
385
|
process: ProcessName.mutate,
|
|
392
386
|
cause: error,
|
|
@@ -22,27 +22,13 @@ import {
|
|
|
22
22
|
getUserGroupsFromToken,
|
|
23
23
|
TransformerMutationType,
|
|
24
24
|
getTokenForCustomAuth,
|
|
25
|
-
mapErrorToType,
|
|
26
|
-
ErrorMap,
|
|
27
25
|
} from '../utils';
|
|
28
26
|
import { ModelPredicateCreator } from '../../predicates';
|
|
29
27
|
import { validatePredicate } from '../../util';
|
|
28
|
+
import { getSubscriptionErrorType } from './errorMaps';
|
|
30
29
|
|
|
31
30
|
const logger = new Logger('DataStore');
|
|
32
31
|
|
|
33
|
-
// TODO: add additional error maps
|
|
34
|
-
const errorMap = {
|
|
35
|
-
Unauthorized: (givenError: any) => {
|
|
36
|
-
const {
|
|
37
|
-
error: { errors: [{ message = '' } = {}] } = {
|
|
38
|
-
errors: [],
|
|
39
|
-
},
|
|
40
|
-
} = givenError;
|
|
41
|
-
const regex = /Connection failed.+Unauthorized/;
|
|
42
|
-
return regex.test(message);
|
|
43
|
-
},
|
|
44
|
-
} as ErrorMap;
|
|
45
|
-
|
|
46
32
|
export enum CONTROL_MSG {
|
|
47
33
|
CONNECTED = 'CONNECTED',
|
|
48
34
|
}
|
|
@@ -468,10 +454,8 @@ class SubscriptionProcessor {
|
|
|
468
454
|
message,
|
|
469
455
|
model: modelDefinition.name,
|
|
470
456
|
operation,
|
|
471
|
-
errorType:
|
|
472
|
-
|
|
473
|
-
subscriptionError
|
|
474
|
-
),
|
|
457
|
+
errorType:
|
|
458
|
+
getSubscriptionErrorType(subscriptionError),
|
|
475
459
|
process: ProcessName.subscribe,
|
|
476
460
|
remoteModel: null,
|
|
477
461
|
cause: subscriptionError,
|
|
@@ -18,8 +18,6 @@ import {
|
|
|
18
18
|
getForbiddenError,
|
|
19
19
|
predicateToGraphQLFilter,
|
|
20
20
|
getTokenForCustomAuth,
|
|
21
|
-
mapErrorToType,
|
|
22
|
-
ErrorMap,
|
|
23
21
|
} from '../utils';
|
|
24
22
|
import {
|
|
25
23
|
jitteredExponentialRetry,
|
|
@@ -29,6 +27,7 @@ import {
|
|
|
29
27
|
} from '@aws-amplify/core';
|
|
30
28
|
import { ModelPredicateCreator } from '../../predicates';
|
|
31
29
|
import { ModelInstanceCreator } from '../../datastore/datastore';
|
|
30
|
+
import { getSyncErrorType } from './errorMaps';
|
|
32
31
|
const opResultDefaults = {
|
|
33
32
|
items: [],
|
|
34
33
|
nextToken: null,
|
|
@@ -37,11 +36,6 @@ const opResultDefaults = {
|
|
|
37
36
|
|
|
38
37
|
const logger = new Logger('DataStore');
|
|
39
38
|
|
|
40
|
-
// TODO: add additional error maps
|
|
41
|
-
const errorMap = {
|
|
42
|
-
BadRecord: error => /^Cannot return \w+ for [\w-_]+ type/.test(error.message),
|
|
43
|
-
} as ErrorMap;
|
|
44
|
-
|
|
45
39
|
class SyncProcessor {
|
|
46
40
|
private readonly typeQuery = new WeakMap<SchemaModel, [string, string]>();
|
|
47
41
|
|
|
@@ -251,7 +245,7 @@ class SyncProcessor {
|
|
|
251
245
|
message: err.message,
|
|
252
246
|
model: modelDefinition.name,
|
|
253
247
|
operation: opName,
|
|
254
|
-
errorType:
|
|
248
|
+
errorType: getSyncErrorType(err),
|
|
255
249
|
process: ProcessName.sync,
|
|
256
250
|
remoteModel: null,
|
|
257
251
|
cause: err,
|
package/src/sync/utils.ts
CHANGED
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
ModelOperation,
|
|
27
27
|
InternalSchema,
|
|
28
28
|
AuthModeStrategy,
|
|
29
|
-
ErrorType,
|
|
30
29
|
} from '../types';
|
|
31
30
|
import { exhaustiveCheck } from '../util';
|
|
32
31
|
import { MutationEvent } from './';
|
|
@@ -41,27 +40,6 @@ enum GraphQLOperationType {
|
|
|
41
40
|
GET = 'query',
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
export type ErrorMap = {
|
|
45
|
-
[key in ErrorType]: (error: Error) => boolean;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Categorizes an error with a broad error type, intended to make
|
|
50
|
-
* customer error handling code simpler.
|
|
51
|
-
* @param errorMap Error names and a list of patterns that indicate them (each pattern as a regex or function)
|
|
52
|
-
* @param error The underying error to categorize.
|
|
53
|
-
*/
|
|
54
|
-
export function mapErrorToType(errorMap: ErrorMap, error: Error): ErrorType {
|
|
55
|
-
const errorTypes = [...Object.keys(errorMap)] as ErrorType[];
|
|
56
|
-
for (const errorType of errorTypes) {
|
|
57
|
-
const matcher = errorMap[errorType];
|
|
58
|
-
if (matcher(error)) {
|
|
59
|
-
return errorType;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return 'Unknown';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
43
|
export enum TransformerMutationType {
|
|
66
44
|
CREATE = 'Create',
|
|
67
45
|
UPDATE = 'Update',
|