@aws-amplify/datastore 5.0.32 → 5.0.33-s-auth.30d0cd2.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/dist/cjs/authModeStrategies/multiAuthStrategy.js +1 -1
- package/dist/cjs/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/dist/cjs/datastore/datastore.js +46 -41
- package/dist/cjs/datastore/datastore.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/predicates/index.js +1 -0
- package/dist/cjs/predicates/index.js.map +1 -1
- package/dist/cjs/predicates/next.js +13 -12
- package/dist/cjs/predicates/next.js.map +1 -1
- package/dist/cjs/predicates/sort.js +2 -2
- package/dist/cjs/predicates/sort.js.map +1 -1
- package/dist/cjs/storage/adapter/AsyncStorageAdapter.js +21 -18
- package/dist/cjs/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/dist/cjs/storage/adapter/AsyncStorageDatabase.js +10 -9
- package/dist/cjs/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/dist/cjs/storage/adapter/InMemoryStore.js +4 -1
- package/dist/cjs/storage/adapter/InMemoryStore.js.map +1 -1
- package/dist/cjs/storage/adapter/IndexedDBAdapter.js +21 -23
- package/dist/cjs/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/dist/cjs/storage/adapter/StorageAdapterBase.js +7 -7
- package/dist/cjs/storage/adapter/StorageAdapterBase.js.map +1 -1
- package/dist/cjs/storage/adapter/getDefaultAdapter/index.js +4 -1
- package/dist/cjs/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/dist/cjs/storage/adapter/getDefaultAdapter/index.native.js +1 -0
- package/dist/cjs/storage/adapter/getDefaultAdapter/index.native.js.map +1 -1
- package/dist/cjs/storage/relationship.js +1 -0
- package/dist/cjs/storage/relationship.js.map +1 -1
- package/dist/cjs/storage/storage.js +14 -14
- package/dist/cjs/storage/storage.js.map +1 -1
- package/dist/cjs/sync/datastoreConnectivity.js +0 -3
- package/dist/cjs/sync/datastoreConnectivity.js.map +1 -1
- package/dist/cjs/sync/index.js +47 -43
- package/dist/cjs/sync/index.js.map +1 -1
- package/dist/cjs/sync/merger.js +1 -1
- package/dist/cjs/sync/merger.js.map +1 -1
- package/dist/cjs/sync/outbox.js +19 -17
- package/dist/cjs/sync/outbox.js.map +1 -1
- package/dist/cjs/sync/processors/errorMaps.js.map +1 -1
- package/dist/cjs/sync/processors/mutation.js +31 -28
- package/dist/cjs/sync/processors/mutation.js.map +1 -1
- package/dist/cjs/sync/processors/subscription.js +21 -12
- package/dist/cjs/sync/processors/subscription.js.map +1 -1
- package/dist/cjs/sync/processors/sync.js +25 -21
- package/dist/cjs/sync/processors/sync.js.map +1 -1
- package/dist/cjs/sync/utils.js +20 -21
- package/dist/cjs/sync/utils.js.map +1 -1
- package/dist/cjs/types.js +1 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/util.js +46 -25
- package/dist/cjs/util.js.map +1 -1
- package/dist/esm/authModeStrategies/multiAuthStrategy.d.ts +1 -1
- package/dist/esm/authModeStrategies/multiAuthStrategy.mjs +1 -1
- package/dist/esm/authModeStrategies/multiAuthStrategy.mjs.map +1 -1
- package/dist/esm/datastore/datastore.d.ts +4 -6
- package/dist/esm/datastore/datastore.mjs +42 -34
- package/dist/esm/datastore/datastore.mjs.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/predicates/index.mjs +1 -0
- package/dist/esm/predicates/index.mjs.map +1 -1
- package/dist/esm/predicates/next.d.ts +7 -7
- package/dist/esm/predicates/next.mjs +13 -12
- package/dist/esm/predicates/next.mjs.map +1 -1
- package/dist/esm/predicates/sort.d.ts +1 -1
- package/dist/esm/predicates/sort.mjs +2 -2
- package/dist/esm/predicates/sort.mjs.map +1 -1
- package/dist/esm/storage/adapter/AsyncStorageAdapter.d.ts +1 -1
- package/dist/esm/storage/adapter/AsyncStorageAdapter.mjs +21 -18
- package/dist/esm/storage/adapter/AsyncStorageAdapter.mjs.map +1 -1
- package/dist/esm/storage/adapter/AsyncStorageDatabase.mjs +10 -9
- package/dist/esm/storage/adapter/AsyncStorageDatabase.mjs.map +1 -1
- package/dist/esm/storage/adapter/InMemoryStore.mjs +4 -1
- package/dist/esm/storage/adapter/InMemoryStore.mjs.map +1 -1
- package/dist/esm/storage/adapter/IndexedDBAdapter.mjs +21 -23
- package/dist/esm/storage/adapter/IndexedDBAdapter.mjs.map +1 -1
- package/dist/esm/storage/adapter/StorageAdapterBase.d.ts +2 -2
- package/dist/esm/storage/adapter/StorageAdapterBase.mjs +7 -7
- package/dist/esm/storage/adapter/StorageAdapterBase.mjs.map +1 -1
- package/dist/esm/storage/adapter/getDefaultAdapter/index.mjs +3 -1
- package/dist/esm/storage/adapter/getDefaultAdapter/index.mjs.map +1 -1
- package/dist/esm/storage/adapter/getDefaultAdapter/index.native.mjs +1 -0
- package/dist/esm/storage/adapter/getDefaultAdapter/index.native.mjs.map +1 -1
- package/dist/esm/storage/adapter/index.d.ts +1 -1
- package/dist/esm/storage/relationship.mjs +1 -0
- package/dist/esm/storage/relationship.mjs.map +1 -1
- package/dist/esm/storage/storage.d.ts +11 -11
- package/dist/esm/storage/storage.mjs +10 -10
- package/dist/esm/storage/storage.mjs.map +1 -1
- package/dist/esm/sync/datastoreConnectivity.d.ts +2 -2
- package/dist/esm/sync/datastoreConnectivity.mjs +0 -3
- package/dist/esm/sync/datastoreConnectivity.mjs.map +1 -1
- package/dist/esm/sync/index.d.ts +3 -3
- package/dist/esm/sync/index.mjs +47 -43
- package/dist/esm/sync/index.mjs.map +1 -1
- package/dist/esm/sync/merger.d.ts +1 -1
- package/dist/esm/sync/merger.mjs +1 -1
- package/dist/esm/sync/merger.mjs.map +1 -1
- package/dist/esm/sync/outbox.d.ts +4 -4
- package/dist/esm/sync/outbox.mjs +19 -17
- package/dist/esm/sync/outbox.mjs.map +1 -1
- package/dist/esm/sync/processors/errorMaps.mjs.map +1 -1
- package/dist/esm/sync/processors/mutation.d.ts +5 -5
- package/dist/esm/sync/processors/mutation.mjs +31 -28
- package/dist/esm/sync/processors/mutation.mjs.map +1 -1
- package/dist/esm/sync/processors/subscription.d.ts +1 -1
- package/dist/esm/sync/processors/subscription.mjs +21 -12
- package/dist/esm/sync/processors/subscription.mjs.map +1 -1
- package/dist/esm/sync/processors/sync.d.ts +3 -3
- package/dist/esm/sync/processors/sync.mjs +13 -9
- package/dist/esm/sync/processors/sync.mjs.map +1 -1
- package/dist/esm/sync/utils.d.ts +11 -13
- package/dist/esm/sync/utils.mjs +20 -21
- package/dist/esm/sync/utils.mjs.map +1 -1
- package/dist/esm/types.d.ts +121 -131
- package/dist/esm/types.mjs +3 -2
- package/dist/esm/types.mjs.map +1 -1
- package/dist/esm/util.d.ts +5 -5
- package/dist/esm/util.mjs +46 -25
- package/dist/esm/util.mjs.map +1 -1
- package/package.json +74 -73
- package/src/authModeStrategies/multiAuthStrategy.ts +8 -4
- package/src/datastore/datastore.ts +145 -123
- package/src/index.ts +10 -8
- package/src/predicates/index.ts +10 -2
- package/src/predicates/next.ts +39 -28
- package/src/predicates/sort.ts +23 -26
- package/src/storage/adapter/AsyncStorageAdapter.ts +43 -25
- package/src/storage/adapter/AsyncStorageDatabase.ts +18 -10
- package/src/storage/adapter/InMemoryStore.ts +5 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +50 -37
- package/src/storage/adapter/StorageAdapterBase.ts +24 -18
- package/src/storage/adapter/getDefaultAdapter/index.native.ts +1 -0
- package/src/storage/adapter/getDefaultAdapter/index.ts +4 -1
- package/src/storage/adapter/index.ts +2 -2
- package/src/storage/relationship.ts +5 -1
- package/src/storage/storage.ts +38 -30
- package/src/sync/datastoreConnectivity.ts +4 -6
- package/src/sync/index.ts +228 -230
- package/src/sync/merger.ts +4 -3
- package/src/sync/outbox.ts +26 -24
- package/src/sync/processors/errorMaps.ts +5 -0
- package/src/sync/processors/mutation.ts +80 -72
- package/src/sync/processors/subscription.ts +69 -53
- package/src/sync/processors/sync.ts +49 -37
- package/src/sync/utils.ts +60 -41
- package/src/types.ts +165 -165
- package/src/util.ts +89 -53
|
@@ -3,53 +3,49 @@
|
|
|
3
3
|
import { GraphQLResult } from '@aws-amplify/api';
|
|
4
4
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
5
5
|
import {
|
|
6
|
+
ConsoleLogger,
|
|
6
7
|
Hub,
|
|
7
8
|
HubCapsule,
|
|
8
9
|
fetchAuthSession,
|
|
9
|
-
ConsoleLogger,
|
|
10
10
|
} from '@aws-amplify/core';
|
|
11
11
|
import {
|
|
12
|
+
BackgroundProcessManager,
|
|
12
13
|
Category,
|
|
13
14
|
CustomUserAgentDetails,
|
|
14
15
|
DataStoreAction,
|
|
15
|
-
BackgroundProcessManager,
|
|
16
16
|
GraphQLAuthMode,
|
|
17
|
-
AmplifyError,
|
|
18
17
|
JwtPayload,
|
|
19
18
|
} from '@aws-amplify/core/internals/utils';
|
|
20
|
-
|
|
21
19
|
import { Observable, Observer, SubscriptionLike } from 'rxjs';
|
|
20
|
+
import { CONTROL_MSG as PUBSUB_CONTROL_MSG } from '@aws-amplify/api-graphql';
|
|
21
|
+
|
|
22
22
|
import {
|
|
23
|
+
AmplifyContext,
|
|
24
|
+
AuthModeStrategy,
|
|
25
|
+
ErrorHandler,
|
|
23
26
|
InternalSchema,
|
|
27
|
+
ModelPredicate,
|
|
24
28
|
PersistentModel,
|
|
25
|
-
SchemaModel,
|
|
26
|
-
SchemaNamespace,
|
|
27
29
|
PredicatesGroup,
|
|
28
|
-
ModelPredicate,
|
|
29
|
-
AuthModeStrategy,
|
|
30
|
-
ErrorHandler,
|
|
31
30
|
ProcessName,
|
|
32
|
-
|
|
31
|
+
SchemaModel,
|
|
32
|
+
SchemaNamespace,
|
|
33
33
|
} from '../../types';
|
|
34
34
|
import {
|
|
35
|
+
RTFError,
|
|
36
|
+
TransformerMutationType,
|
|
35
37
|
buildSubscriptionGraphQLOperation,
|
|
38
|
+
generateRTFRemediation,
|
|
36
39
|
getAuthorizationRules,
|
|
37
40
|
getModelAuthModes,
|
|
38
|
-
getUserGroupsFromToken,
|
|
39
|
-
TransformerMutationType,
|
|
40
41
|
getTokenForCustomAuth,
|
|
42
|
+
getUserGroupsFromToken,
|
|
41
43
|
predicateToGraphQLFilter,
|
|
42
|
-
dynamicAuthFields,
|
|
43
|
-
filterFields,
|
|
44
|
-
repeatedFieldInGroup,
|
|
45
|
-
countFilterCombinations,
|
|
46
|
-
RTFError,
|
|
47
|
-
generateRTFRemediation,
|
|
48
44
|
} from '../utils';
|
|
49
45
|
import { ModelPredicateCreator } from '../../predicates';
|
|
50
46
|
import { validatePredicate } from '../../util';
|
|
47
|
+
|
|
51
48
|
import { getSubscriptionErrorType } from './errorMaps';
|
|
52
|
-
import { CONTROL_MSG as PUBSUB_CONTROL_MSG } from '@aws-amplify/api-graphql';
|
|
53
49
|
|
|
54
50
|
const logger = new ConsoleLogger('DataStore');
|
|
55
51
|
|
|
@@ -63,20 +59,22 @@ export enum USER_CREDENTIALS {
|
|
|
63
59
|
'auth',
|
|
64
60
|
}
|
|
65
61
|
|
|
66
|
-
|
|
62
|
+
interface AuthorizationInfo {
|
|
67
63
|
authMode: GraphQLAuthMode;
|
|
68
64
|
isOwner: boolean;
|
|
69
65
|
ownerField?: string;
|
|
70
66
|
ownerValue?: string;
|
|
71
|
-
}
|
|
67
|
+
}
|
|
72
68
|
|
|
73
69
|
class SubscriptionProcessor {
|
|
74
70
|
private readonly typeQuery = new WeakMap<
|
|
75
71
|
SchemaModel,
|
|
76
72
|
[TransformerMutationType, string, string][]
|
|
77
73
|
>();
|
|
74
|
+
|
|
78
75
|
private buffer: [TransformerMutationType, SchemaModel, PersistentModel][] =
|
|
79
76
|
[];
|
|
77
|
+
|
|
80
78
|
private dataObserver!: Observer<any>;
|
|
81
79
|
|
|
82
80
|
private runningProcesses = new BackgroundProcessManager();
|
|
@@ -102,7 +100,7 @@ class SubscriptionProcessor {
|
|
|
102
100
|
userCredentials: USER_CREDENTIALS,
|
|
103
101
|
oidcTokenPayload: JwtPayload | undefined,
|
|
104
102
|
authMode: GraphQLAuthMode,
|
|
105
|
-
filterArg
|
|
103
|
+
filterArg = false,
|
|
106
104
|
): {
|
|
107
105
|
opType: TransformerMutationType;
|
|
108
106
|
opName: string;
|
|
@@ -130,6 +128,7 @@ class SubscriptionProcessor {
|
|
|
130
128
|
ownerField!,
|
|
131
129
|
filterArg,
|
|
132
130
|
);
|
|
131
|
+
|
|
133
132
|
return { authMode, opType, opName, query, isOwner, ownerField, ownerValue };
|
|
134
133
|
}
|
|
135
134
|
|
|
@@ -164,6 +163,7 @@ class SubscriptionProcessor {
|
|
|
164
163
|
|
|
165
164
|
const validGroup =
|
|
166
165
|
(authMode === 'oidc' || authMode === 'userPool') &&
|
|
166
|
+
// eslint-disable-next-line array-callback-return
|
|
167
167
|
groupAuthRules.find(groupAuthRule => {
|
|
168
168
|
// validate token against groupClaim
|
|
169
169
|
if (oidcTokenPayload) {
|
|
@@ -233,7 +233,7 @@ class SubscriptionProcessor {
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
private hubQueryCompletionListener(
|
|
236
|
-
completed:
|
|
236
|
+
completed: () => void,
|
|
237
237
|
capsule: HubCapsule<'datastore', { event: string }>,
|
|
238
238
|
) {
|
|
239
239
|
const {
|
|
@@ -257,13 +257,14 @@ class SubscriptionProcessor {
|
|
|
257
257
|
|
|
258
258
|
// Creating subs for each model/operation combo so they can be unsubscribed
|
|
259
259
|
// independently, since the auth retry behavior is asynchronous.
|
|
260
|
-
let subscriptions:
|
|
261
|
-
|
|
260
|
+
let subscriptions: Record<
|
|
261
|
+
string,
|
|
262
|
+
{
|
|
262
263
|
[TransformerMutationType.CREATE]: SubscriptionLike[];
|
|
263
264
|
[TransformerMutationType.UPDATE]: SubscriptionLike[];
|
|
264
265
|
[TransformerMutationType.DELETE]: SubscriptionLike[];
|
|
265
|
-
}
|
|
266
|
-
|
|
266
|
+
}
|
|
267
|
+
> = {};
|
|
267
268
|
let oidcTokenPayload: JwtPayload | undefined;
|
|
268
269
|
let userCredentials = USER_CREDENTIALS.none;
|
|
269
270
|
this.runningProcesses.add(async () => {
|
|
@@ -369,7 +370,7 @@ class SubscriptionProcessor {
|
|
|
369
370
|
};
|
|
370
371
|
|
|
371
372
|
if (addFilter && predicatesGroup) {
|
|
372
|
-
variables
|
|
373
|
+
(variables as any).filter =
|
|
373
374
|
predicateToGraphQLFilter(predicatesGroup);
|
|
374
375
|
}
|
|
375
376
|
|
|
@@ -378,6 +379,7 @@ class SubscriptionProcessor {
|
|
|
378
379
|
observer.error(
|
|
379
380
|
'Owner field required, sign in is needed in order to perform this operation',
|
|
380
381
|
);
|
|
382
|
+
|
|
381
383
|
return;
|
|
382
384
|
}
|
|
383
385
|
|
|
@@ -390,18 +392,19 @@ class SubscriptionProcessor {
|
|
|
390
392
|
}`,
|
|
391
393
|
);
|
|
392
394
|
|
|
393
|
-
const queryObservable =
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
395
|
+
const queryObservable =
|
|
396
|
+
this.amplifyContext.InternalAPI.graphql(
|
|
397
|
+
{
|
|
398
|
+
query,
|
|
399
|
+
variables,
|
|
400
|
+
...{ authMode },
|
|
401
|
+
authToken,
|
|
402
|
+
},
|
|
403
|
+
undefined,
|
|
404
|
+
customUserAgentDetails,
|
|
405
|
+
) as unknown as Observable<
|
|
406
|
+
GraphQLResult<Record<string, PersistentModel>>
|
|
407
|
+
>;
|
|
405
408
|
|
|
406
409
|
let subscriptionReadyCallback: (param?: unknown) => void;
|
|
407
410
|
|
|
@@ -414,11 +417,11 @@ class SubscriptionProcessor {
|
|
|
414
417
|
next: result => {
|
|
415
418
|
const { data, errors } = result;
|
|
416
419
|
if (Array.isArray(errors) && errors.length > 0) {
|
|
417
|
-
const messages = (
|
|
418
|
-
{
|
|
420
|
+
const messages = (
|
|
421
|
+
errors as {
|
|
419
422
|
message: string;
|
|
420
423
|
}[]
|
|
421
|
-
|
|
424
|
+
).map(({ message }) => message);
|
|
422
425
|
|
|
423
426
|
logger.warn(
|
|
424
427
|
`Skipping incoming subscription. Messages: ${messages.join(
|
|
@@ -427,16 +430,16 @@ class SubscriptionProcessor {
|
|
|
427
430
|
);
|
|
428
431
|
|
|
429
432
|
this.drainBuffer();
|
|
433
|
+
|
|
430
434
|
return;
|
|
431
435
|
}
|
|
432
436
|
|
|
433
|
-
const
|
|
437
|
+
const resolvedPredicatesGroup =
|
|
434
438
|
ModelPredicateCreator.getPredicates(
|
|
435
439
|
this.syncPredicates.get(modelDefinition)!,
|
|
436
440
|
false,
|
|
437
441
|
);
|
|
438
442
|
|
|
439
|
-
// @ts-ignore
|
|
440
443
|
const { [opName]: record } = data;
|
|
441
444
|
|
|
442
445
|
// checking incoming subscription against syncPredicate.
|
|
@@ -446,7 +449,7 @@ class SubscriptionProcessor {
|
|
|
446
449
|
if (
|
|
447
450
|
this.passesPredicateValidation(
|
|
448
451
|
record,
|
|
449
|
-
|
|
452
|
+
resolvedPredicatesGroup!,
|
|
450
453
|
)
|
|
451
454
|
) {
|
|
452
455
|
this.pushToBuffer(
|
|
@@ -461,6 +464,7 @@ class SubscriptionProcessor {
|
|
|
461
464
|
const {
|
|
462
465
|
errors: [{ message = '' } = {}],
|
|
463
466
|
} = ({
|
|
467
|
+
// eslint-disable-next-line no-empty-pattern
|
|
464
468
|
errors: [],
|
|
465
469
|
} = subscriptionError);
|
|
466
470
|
|
|
@@ -488,6 +492,7 @@ class SubscriptionProcessor {
|
|
|
488
492
|
|
|
489
493
|
// retry subscription connection without filter
|
|
490
494
|
subscriptionRetry(operation, false);
|
|
495
|
+
|
|
491
496
|
return;
|
|
492
497
|
}
|
|
493
498
|
|
|
@@ -537,6 +542,7 @@ class SubscriptionProcessor {
|
|
|
537
542
|
}`,
|
|
538
543
|
);
|
|
539
544
|
subscriptionRetry(operation);
|
|
545
|
+
|
|
540
546
|
return;
|
|
541
547
|
}
|
|
542
548
|
}
|
|
@@ -544,6 +550,7 @@ class SubscriptionProcessor {
|
|
|
544
550
|
logger.warn('subscriptionError', message);
|
|
545
551
|
|
|
546
552
|
try {
|
|
553
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
547
554
|
await this.errorHandler({
|
|
548
555
|
recoverySuggestion:
|
|
549
556
|
'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',
|
|
@@ -583,11 +590,11 @@ class SubscriptionProcessor {
|
|
|
583
590
|
(async () => {
|
|
584
591
|
let boundFunction: any;
|
|
585
592
|
let removeBoundFunctionListener: () => void;
|
|
586
|
-
await new Promise(
|
|
587
|
-
subscriptionReadyCallback =
|
|
593
|
+
await new Promise(resolve => {
|
|
594
|
+
subscriptionReadyCallback = resolve;
|
|
588
595
|
boundFunction = this.hubQueryCompletionListener.bind(
|
|
589
596
|
this,
|
|
590
|
-
|
|
597
|
+
resolve,
|
|
591
598
|
);
|
|
592
599
|
removeBoundFunctionListener = Hub.listen(
|
|
593
600
|
'api',
|
|
@@ -615,13 +622,19 @@ class SubscriptionProcessor {
|
|
|
615
622
|
return this.runningProcesses.addCleaner(async () => {
|
|
616
623
|
Object.keys(subscriptions).forEach(modelName => {
|
|
617
624
|
subscriptions[modelName][TransformerMutationType.CREATE].forEach(
|
|
618
|
-
subscription =>
|
|
625
|
+
subscription => {
|
|
626
|
+
subscription.unsubscribe();
|
|
627
|
+
},
|
|
619
628
|
);
|
|
620
629
|
subscriptions[modelName][TransformerMutationType.UPDATE].forEach(
|
|
621
|
-
subscription =>
|
|
630
|
+
subscription => {
|
|
631
|
+
subscription.unsubscribe();
|
|
632
|
+
},
|
|
622
633
|
);
|
|
623
634
|
subscriptions[modelName][TransformerMutationType.DELETE].forEach(
|
|
624
|
-
subscription =>
|
|
635
|
+
subscription => {
|
|
636
|
+
subscription.unsubscribe();
|
|
637
|
+
},
|
|
625
638
|
);
|
|
626
639
|
});
|
|
627
640
|
});
|
|
@@ -669,7 +682,9 @@ class SubscriptionProcessor {
|
|
|
669
682
|
|
|
670
683
|
private drainBuffer() {
|
|
671
684
|
if (this.dataObserver) {
|
|
672
|
-
this.buffer.forEach(data =>
|
|
685
|
+
this.buffer.forEach(data => {
|
|
686
|
+
this.dataObserver.next!(data);
|
|
687
|
+
});
|
|
673
688
|
this.buffer = [];
|
|
674
689
|
}
|
|
675
690
|
}
|
|
@@ -711,6 +726,7 @@ class SubscriptionProcessor {
|
|
|
711
726
|
);
|
|
712
727
|
|
|
713
728
|
logger.warn(`${header}\n${message}\n${remediationMessage}`);
|
|
729
|
+
|
|
714
730
|
return true;
|
|
715
731
|
}
|
|
716
732
|
|
|
@@ -4,40 +4,40 @@ import { GraphQLResult } from '@aws-amplify/api';
|
|
|
4
4
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
5
5
|
import { Observable } from 'rxjs';
|
|
6
6
|
import {
|
|
7
|
+
BackgroundProcessManager,
|
|
8
|
+
Category,
|
|
9
|
+
CustomUserAgentDetails,
|
|
10
|
+
DataStoreAction,
|
|
11
|
+
GraphQLAuthMode,
|
|
12
|
+
NonRetryableError,
|
|
13
|
+
jitteredExponentialRetry,
|
|
14
|
+
} from '@aws-amplify/core/internals/utils';
|
|
15
|
+
import { ConsoleLogger, Hub } from '@aws-amplify/core';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
AmplifyContext,
|
|
19
|
+
AuthModeStrategy,
|
|
20
|
+
ErrorHandler,
|
|
21
|
+
GraphQLFilter,
|
|
7
22
|
InternalSchema,
|
|
8
23
|
ModelInstanceMetadata,
|
|
9
|
-
SchemaModel,
|
|
10
24
|
ModelPredicate,
|
|
11
25
|
PredicatesGroup,
|
|
12
|
-
GraphQLFilter,
|
|
13
|
-
AuthModeStrategy,
|
|
14
|
-
ErrorHandler,
|
|
15
26
|
ProcessName,
|
|
16
|
-
|
|
27
|
+
SchemaModel,
|
|
17
28
|
} from '../../types';
|
|
18
29
|
import {
|
|
19
30
|
buildGraphQLOperation,
|
|
20
|
-
getModelAuthModes,
|
|
21
31
|
getClientSideAuthError,
|
|
22
32
|
getForbiddenError,
|
|
23
|
-
|
|
33
|
+
getModelAuthModes,
|
|
24
34
|
getTokenForCustomAuth,
|
|
35
|
+
predicateToGraphQLFilter,
|
|
25
36
|
} from '../utils';
|
|
26
|
-
import {
|
|
27
|
-
jitteredExponentialRetry,
|
|
28
|
-
Category,
|
|
29
|
-
CustomUserAgentDetails,
|
|
30
|
-
DataStoreAction,
|
|
31
|
-
NonRetryableError,
|
|
32
|
-
BackgroundProcessManager,
|
|
33
|
-
GraphQLAuthMode,
|
|
34
|
-
AmplifyError,
|
|
35
|
-
} from '@aws-amplify/core/internals/utils';
|
|
36
|
-
|
|
37
|
-
import { Amplify, ConsoleLogger, Hub } from '@aws-amplify/core';
|
|
38
|
-
|
|
39
37
|
import { ModelPredicateCreator } from '../../predicates';
|
|
38
|
+
|
|
40
39
|
import { getSyncErrorType } from './errorMaps';
|
|
40
|
+
|
|
41
41
|
const opResultDefaults = {
|
|
42
42
|
items: [],
|
|
43
43
|
nextToken: null,
|
|
@@ -149,6 +149,7 @@ class SyncProcessor {
|
|
|
149
149
|
logger.debug(
|
|
150
150
|
`Sync successful with authMode: ${readAuthModes[authModeAttempts]}`,
|
|
151
151
|
);
|
|
152
|
+
|
|
152
153
|
return response;
|
|
153
154
|
} catch (error) {
|
|
154
155
|
authModeAttempts++;
|
|
@@ -174,7 +175,8 @@ class SyncProcessor {
|
|
|
174
175
|
readAuthModes[authModeAttempts - 1]
|
|
175
176
|
}. Retrying with authMode: ${readAuthModes[authModeAttempts]}`,
|
|
176
177
|
);
|
|
177
|
-
|
|
178
|
+
|
|
179
|
+
return authModeRetry();
|
|
178
180
|
}
|
|
179
181
|
};
|
|
180
182
|
|
|
@@ -206,16 +208,19 @@ class SyncProcessor {
|
|
|
206
208
|
authMode: GraphQLAuthMode;
|
|
207
209
|
onTerminate: Promise<void>;
|
|
208
210
|
}): Promise<
|
|
209
|
-
GraphQLResult<
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
211
|
+
GraphQLResult<
|
|
212
|
+
Record<
|
|
213
|
+
string,
|
|
214
|
+
{
|
|
215
|
+
items: T[];
|
|
216
|
+
nextToken: string;
|
|
217
|
+
startedAt: number;
|
|
218
|
+
}
|
|
219
|
+
>
|
|
220
|
+
>
|
|
216
221
|
> {
|
|
217
|
-
return
|
|
218
|
-
async (
|
|
222
|
+
return jitteredExponentialRetry(
|
|
223
|
+
async (retriedQuery, retriedVariables) => {
|
|
219
224
|
try {
|
|
220
225
|
const authToken = await getTokenForCustomAuth(
|
|
221
226
|
authMode,
|
|
@@ -229,8 +234,8 @@ class SyncProcessor {
|
|
|
229
234
|
|
|
230
235
|
return await this.amplifyContext.InternalAPI.graphql(
|
|
231
236
|
{
|
|
232
|
-
query,
|
|
233
|
-
variables,
|
|
237
|
+
query: retriedQuery,
|
|
238
|
+
variables: retriedVariables,
|
|
234
239
|
authMode,
|
|
235
240
|
authToken,
|
|
236
241
|
},
|
|
@@ -275,6 +280,7 @@ class SyncProcessor {
|
|
|
275
280
|
await Promise.all(
|
|
276
281
|
otherErrors.map(async err => {
|
|
277
282
|
try {
|
|
283
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
278
284
|
await this.errorHandler({
|
|
279
285
|
recoverySuggestion:
|
|
280
286
|
'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',
|
|
@@ -368,6 +374,7 @@ class SyncProcessor {
|
|
|
368
374
|
const typeLastSync = typesLastSync.get(namespace.models[modelName]);
|
|
369
375
|
map.set(namespace.models[modelName], typeLastSync!);
|
|
370
376
|
}
|
|
377
|
+
|
|
371
378
|
return map;
|
|
372
379
|
},
|
|
373
380
|
new Map<SchemaModel, [string, number]>(),
|
|
@@ -394,7 +401,8 @@ class SyncProcessor {
|
|
|
394
401
|
parentPromises.get(`${namespace}_${parent}`),
|
|
395
402
|
);
|
|
396
403
|
|
|
397
|
-
|
|
404
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
405
|
+
const promise = new Promise<void>(async resolve => {
|
|
398
406
|
await Promise.all(promises);
|
|
399
407
|
|
|
400
408
|
do {
|
|
@@ -407,7 +415,10 @@ class SyncProcessor {
|
|
|
407
415
|
logger.debug(
|
|
408
416
|
`Sync processor has been stopped, terminating sync for ${modelDefinition.name}`,
|
|
409
417
|
);
|
|
410
|
-
|
|
418
|
+
|
|
419
|
+
resolve();
|
|
420
|
+
|
|
421
|
+
return;
|
|
411
422
|
}
|
|
412
423
|
|
|
413
424
|
const limit = Math.min(
|
|
@@ -431,6 +442,7 @@ class SyncProcessor {
|
|
|
431
442
|
));
|
|
432
443
|
} catch (error) {
|
|
433
444
|
try {
|
|
445
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
434
446
|
await this.errorHandler({
|
|
435
447
|
recoverySuggestion:
|
|
436
448
|
'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',
|
|
@@ -472,7 +484,7 @@ class SyncProcessor {
|
|
|
472
484
|
});
|
|
473
485
|
} while (!done);
|
|
474
486
|
|
|
475
|
-
|
|
487
|
+
resolve();
|
|
476
488
|
});
|
|
477
489
|
|
|
478
490
|
parentPromises.set(
|
|
@@ -500,13 +512,13 @@ class SyncProcessor {
|
|
|
500
512
|
}
|
|
501
513
|
}
|
|
502
514
|
|
|
503
|
-
export
|
|
515
|
+
export interface SyncModelPage {
|
|
504
516
|
namespace: string;
|
|
505
517
|
modelDefinition: SchemaModel;
|
|
506
518
|
items: ModelInstanceMetadata[];
|
|
507
519
|
startedAt: number;
|
|
508
520
|
done: boolean;
|
|
509
521
|
isFullSync: boolean;
|
|
510
|
-
}
|
|
522
|
+
}
|
|
511
523
|
|
|
512
524
|
export { SyncProcessor };
|