@aws-amplify/datastore 4.7.6-api-v6-models.b3abc9b.0 → 5.0.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 +38 -53
- package/lib/datastore/datastore.d.ts +4 -5
- package/lib/datastore/datastore.js +929 -1284
- package/lib/index.d.ts +1 -1
- package/lib/index.js +26 -13
- package/lib/predicates/index.js +54 -69
- package/lib/predicates/next.d.ts +2 -2
- package/lib/predicates/next.js +313 -462
- package/lib/predicates/sort.js +24 -28
- package/lib/ssr/index.js +2 -2
- package/lib/storage/adapter/AsyncStorageAdapter.js +120 -342
- package/lib/storage/adapter/AsyncStorageDatabase.js +217 -421
- package/lib/storage/adapter/InMemoryStore.js +28 -51
- package/lib/storage/adapter/InMemoryStore.native.js +5 -3
- package/lib/storage/adapter/IndexedDBAdapter.js +466 -871
- package/lib/storage/adapter/StorageAdapterBase.js +180 -330
- package/lib/storage/adapter/getDefaultAdapter/index.js +8 -10
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +5 -4
- package/lib/storage/adapter/index.js +0 -1
- package/lib/storage/relationship.js +177 -253
- package/lib/storage/storage.d.ts +4 -4
- package/lib/storage/storage.js +255 -433
- package/lib/sync/datastoreConnectivity.d.ts +2 -2
- package/lib/sync/datastoreConnectivity.js +29 -39
- package/lib/sync/datastoreReachability/index.d.ts +1 -3
- package/lib/sync/datastoreReachability/index.js +3 -3
- package/lib/sync/datastoreReachability/index.native.d.ts +1 -3
- package/lib/sync/datastoreReachability/index.native.js +4 -5
- package/lib/sync/index.d.ts +2 -2
- package/lib/sync/index.js +522 -827
- package/lib/sync/merger.js +31 -63
- package/lib/sync/outbox.js +148 -232
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +30 -47
- package/lib/sync/processors/mutation.d.ts +2 -2
- package/lib/sync/processors/mutation.js +343 -502
- package/lib/sync/processors/subscription.d.ts +5 -2
- package/lib/sync/processors/subscription.js +283 -437
- package/lib/sync/processors/sync.d.ts +2 -2
- package/lib/sync/processors/sync.js +279 -404
- package/lib/sync/utils.d.ts +5 -4
- package/lib/sync/utils.js +267 -320
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types.d.ts +138 -140
- package/lib/types.js +17 -24
- package/lib/util.d.ts +9 -17
- package/lib/util.js +387 -511
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +1 -2
- package/lib-esm/authModeStrategies/index.js +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +35 -52
- package/lib-esm/datastore/datastore.d.ts +4 -5
- package/lib-esm/datastore/datastore.js +888 -1247
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +6 -7
- package/lib-esm/predicates/index.js +53 -70
- package/lib-esm/predicates/next.d.ts +2 -2
- package/lib-esm/predicates/next.js +306 -459
- package/lib-esm/predicates/sort.js +23 -28
- package/lib-esm/ssr/index.js +1 -2
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +111 -338
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +212 -416
- package/lib-esm/storage/adapter/InMemoryStore.js +27 -52
- package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +438 -866
- package/lib-esm/storage/adapter/StorageAdapterBase.js +173 -325
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -6
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +1 -2
- package/lib-esm/storage/adapter/index.js +1 -1
- package/lib-esm/storage/relationship.js +173 -251
- package/lib-esm/storage/storage.d.ts +4 -4
- package/lib-esm/storage/storage.js +242 -424
- package/lib-esm/sync/datastoreConnectivity.d.ts +2 -2
- package/lib-esm/sync/datastoreConnectivity.js +28 -39
- package/lib-esm/sync/datastoreReachability/index.d.ts +1 -3
- package/lib-esm/sync/datastoreReachability/index.js +2 -3
- package/lib-esm/sync/datastoreReachability/index.native.d.ts +1 -3
- package/lib-esm/sync/datastoreReachability/index.native.js +3 -4
- package/lib-esm/sync/index.d.ts +2 -2
- package/lib-esm/sync/index.js +502 -812
- package/lib-esm/sync/merger.js +28 -61
- package/lib-esm/sync/outbox.js +143 -228
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +32 -50
- package/lib-esm/sync/processors/mutation.d.ts +2 -2
- package/lib-esm/sync/processors/mutation.js +329 -490
- package/lib-esm/sync/processors/subscription.d.ts +5 -2
- package/lib-esm/sync/processors/subscription.js +266 -421
- package/lib-esm/sync/processors/sync.d.ts +2 -2
- package/lib-esm/sync/processors/sync.js +271 -397
- package/lib-esm/sync/utils.d.ts +5 -4
- package/lib-esm/sync/utils.js +252 -307
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types.d.ts +138 -140
- package/lib-esm/types.js +16 -25
- package/lib-esm/util.d.ts +9 -17
- package/lib-esm/util.js +335 -497
- package/package.json +31 -26
- package/src/authModeStrategies/multiAuthStrategy.ts +15 -12
- package/src/datastore/datastore.ts +36 -35
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/InMemoryStore.ts +1 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +2 -2
- package/src/storage/adapter/StorageAdapterBase.ts +2 -2
- package/src/storage/adapter/getDefaultAdapter/index.ts +1 -4
- package/src/storage/storage.ts +29 -24
- package/src/sync/datastoreConnectivity.ts +6 -6
- package/src/sync/datastoreReachability/index.native.ts +5 -3
- package/src/sync/datastoreReachability/index.ts +1 -1
- package/src/sync/index.ts +79 -89
- package/src/sync/processors/errorMaps.ts +7 -7
- package/src/sync/processors/mutation.ts +19 -13
- package/src/sync/processors/subscription.ts +221 -295
- package/src/sync/processors/sync.ts +11 -8
- package/src/sync/utils.ts +30 -15
- package/src/types.ts +4 -8
- package/src/util.ts +46 -9
- 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
package/src/sync/index.ts
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Hub,
|
|
8
|
-
} from '@aws-amplify/core';
|
|
9
|
-
import {
|
|
10
|
-
CONTROL_MSG as PUBSUB_CONTROL_MSG,
|
|
11
|
-
CONNECTION_STATE_CHANGE as PUBSUB_CONNECTION_STATE_CHANGE,
|
|
12
|
-
ConnectionState,
|
|
13
|
-
} from '@aws-amplify/pubsub';
|
|
14
|
-
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
3
|
+
import { BackgroundProcessManager } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
import { Hub, ConsoleLogger } from '@aws-amplify/core';
|
|
5
|
+
|
|
6
|
+
import { filter, Observable, of, SubscriptionLike } from 'rxjs';
|
|
15
7
|
import { ModelInstanceCreator } from '../datastore/datastore';
|
|
16
8
|
import { ModelPredicateCreator } from '../predicates';
|
|
17
9
|
import { ExclusiveStorage as Storage } from '../storage/storage';
|
|
@@ -53,8 +45,13 @@ import {
|
|
|
53
45
|
TransformerMutationType,
|
|
54
46
|
} from './utils';
|
|
55
47
|
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
import {
|
|
49
|
+
CONTROL_MSG as PUBSUB_CONTROL_MSG,
|
|
50
|
+
ConnectionState,
|
|
51
|
+
CONNECTION_STATE_CHANGE as PUBSUB_CONNECTION_STATE_CHANGE,
|
|
52
|
+
} from '@aws-amplify/api-graphql';
|
|
53
|
+
|
|
54
|
+
const logger = new ConsoleLogger('DataStore');
|
|
58
55
|
|
|
59
56
|
const ownSymbol = Symbol('sync');
|
|
60
57
|
|
|
@@ -215,7 +212,7 @@ export class SyncEngine {
|
|
|
215
212
|
return new Observable<ControlMessageType<ControlMessage>>(observer => {
|
|
216
213
|
logger.log('starting sync engine...');
|
|
217
214
|
|
|
218
|
-
let subscriptions:
|
|
215
|
+
let subscriptions: SubscriptionLike[] = [];
|
|
219
216
|
|
|
220
217
|
this.runningProcesses.add(async () => {
|
|
221
218
|
try {
|
|
@@ -249,53 +246,47 @@ export class SyncEngine {
|
|
|
249
246
|
[TransformerMutationType, SchemaModel, PersistentModel]
|
|
250
247
|
>;
|
|
251
248
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
);
|
|
257
|
-
} else {
|
|
258
|
-
this.stopDisruptionListener =
|
|
259
|
-
this.startDisruptionListener();
|
|
260
|
-
//#region GraphQL Subscriptions
|
|
261
|
-
[ctlSubsObservable, dataSubsObservable] =
|
|
262
|
-
this.subscriptionsProcessor.start();
|
|
263
|
-
|
|
264
|
-
try {
|
|
265
|
-
await new Promise<void>((resolve, reject) => {
|
|
266
|
-
onTerminate.then(reject);
|
|
267
|
-
const ctlSubsSubscription =
|
|
268
|
-
ctlSubsObservable.subscribe({
|
|
269
|
-
next: msg => {
|
|
270
|
-
if (msg === CONTROL_MSG.CONNECTED) {
|
|
271
|
-
resolve();
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
error: err => {
|
|
275
|
-
reject(err);
|
|
276
|
-
const handleDisconnect =
|
|
277
|
-
this.disconnectionHandler();
|
|
278
|
-
handleDisconnect(err);
|
|
279
|
-
},
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
subscriptions.push(ctlSubsSubscription);
|
|
283
|
-
});
|
|
284
|
-
} catch (err) {
|
|
285
|
-
observer.error(err);
|
|
286
|
-
failedStarting();
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
249
|
+
this.stopDisruptionListener =
|
|
250
|
+
this.startDisruptionListener();
|
|
251
|
+
//#region GraphQL Subscriptions
|
|
252
|
+
[ctlSubsObservable, dataSubsObservable] =
|
|
253
|
+
this.subscriptionsProcessor.start();
|
|
289
254
|
|
|
290
|
-
|
|
255
|
+
try {
|
|
256
|
+
await new Promise<void>((resolve, reject) => {
|
|
257
|
+
onTerminate.then(reject);
|
|
258
|
+
const ctlSubsSubscription = ctlSubsObservable.subscribe(
|
|
259
|
+
{
|
|
260
|
+
next: msg => {
|
|
261
|
+
if (msg === CONTROL_MSG.CONNECTED) {
|
|
262
|
+
resolve();
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
error: err => {
|
|
266
|
+
reject(err);
|
|
267
|
+
const handleDisconnect =
|
|
268
|
+
this.disconnectionHandler();
|
|
269
|
+
handleDisconnect(err);
|
|
270
|
+
},
|
|
271
|
+
}
|
|
272
|
+
);
|
|
291
273
|
|
|
292
|
-
|
|
293
|
-
type: ControlMessage.SYNC_ENGINE_SUBSCRIPTIONS_ESTABLISHED,
|
|
274
|
+
subscriptions.push(ctlSubsSubscription);
|
|
294
275
|
});
|
|
295
|
-
|
|
296
|
-
|
|
276
|
+
} catch (err) {
|
|
277
|
+
observer.error(err);
|
|
278
|
+
failedStarting();
|
|
279
|
+
return;
|
|
297
280
|
}
|
|
298
281
|
|
|
282
|
+
logger.log('Realtime ready');
|
|
283
|
+
|
|
284
|
+
observer.next({
|
|
285
|
+
type: ControlMessage.SYNC_ENGINE_SUBSCRIPTIONS_ESTABLISHED,
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
//#endregion
|
|
289
|
+
|
|
299
290
|
//#region Base & Sync queries
|
|
300
291
|
try {
|
|
301
292
|
await new Promise<void>((resolve, reject) => {
|
|
@@ -376,32 +367,29 @@ export class SyncEngine {
|
|
|
376
367
|
//#endregion
|
|
377
368
|
|
|
378
369
|
//#region Merge subscriptions buffer
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
)
|
|
403
|
-
);
|
|
404
|
-
}
|
|
370
|
+
subscriptions.push(
|
|
371
|
+
dataSubsObservable!.subscribe(
|
|
372
|
+
([_transformerMutationType, modelDefinition, item]) =>
|
|
373
|
+
this.runningProcesses.add(async () => {
|
|
374
|
+
const modelConstructor = this.userModelClasses[
|
|
375
|
+
modelDefinition.name
|
|
376
|
+
] as PersistentModelConstructor<any>;
|
|
377
|
+
|
|
378
|
+
const model = this.modelInstanceCreator(
|
|
379
|
+
modelConstructor,
|
|
380
|
+
item
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
await this.storage.runExclusive(storage =>
|
|
384
|
+
this.modelMerger.merge(
|
|
385
|
+
storage,
|
|
386
|
+
model,
|
|
387
|
+
modelDefinition
|
|
388
|
+
)
|
|
389
|
+
);
|
|
390
|
+
}, 'subscription dataSubsObservable event')
|
|
391
|
+
)
|
|
392
|
+
);
|
|
405
393
|
//#endregion
|
|
406
394
|
} else if (!online) {
|
|
407
395
|
this.online = online;
|
|
@@ -425,10 +413,12 @@ export class SyncEngine {
|
|
|
425
413
|
|
|
426
414
|
this.storage
|
|
427
415
|
.observe(null, null, ownSymbol)
|
|
428
|
-
.
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
416
|
+
.pipe(
|
|
417
|
+
filter(({ model }) => {
|
|
418
|
+
const modelDefinition = this.getModelDefinition(model);
|
|
419
|
+
return modelDefinition.syncable === true;
|
|
420
|
+
})
|
|
421
|
+
)
|
|
432
422
|
.subscribe({
|
|
433
423
|
next: async ({ opType, model, element, condition }) =>
|
|
434
424
|
this.runningProcesses.add(async () => {
|
|
@@ -540,11 +530,11 @@ export class SyncEngine {
|
|
|
540
530
|
ControlMessageType<ControlMessage>
|
|
541
531
|
> {
|
|
542
532
|
if (!this.online) {
|
|
543
|
-
return
|
|
533
|
+
return of<ControlMessageType<ControlMessage>>({} as any); // TODO(v6): fix this
|
|
544
534
|
}
|
|
545
535
|
|
|
546
536
|
return new Observable<ControlMessageType<ControlMessage>>(observer => {
|
|
547
|
-
let syncQueriesSubscription:
|
|
537
|
+
let syncQueriesSubscription: SubscriptionLike;
|
|
548
538
|
|
|
549
539
|
this.runningProcesses.isOpen &&
|
|
550
540
|
this.runningProcesses.add(async onTerminate => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { ErrorType } from '../../types';
|
|
4
|
+
import { resolveServiceErrorStatusCode } from '../utils';
|
|
4
5
|
|
|
5
6
|
export type ErrorMap = Partial<{
|
|
6
7
|
[key in ErrorType]: (error: Error) => boolean;
|
|
@@ -9,8 +10,7 @@ export type ErrorMap = Partial<{
|
|
|
9
10
|
const connectionTimeout = error =>
|
|
10
11
|
/^Connection failed: Connection Timeout/.test(error.message);
|
|
11
12
|
|
|
12
|
-
const serverError = error =>
|
|
13
|
-
/^Error: Request failed with status code 5\d\d/.test(error.message);
|
|
13
|
+
const serverError = error => resolveServiceErrorStatusCode(error) >= 500;
|
|
14
14
|
|
|
15
15
|
export const mutationErrorMap: ErrorMap = {
|
|
16
16
|
BadModel: () => false,
|
|
@@ -25,7 +25,7 @@ export const mutationErrorMap: ErrorMap = {
|
|
|
25
25
|
Transient: error => connectionTimeout(error) || serverError(error),
|
|
26
26
|
Unauthorized: error =>
|
|
27
27
|
error.message === 'Unauthorized' ||
|
|
28
|
-
|
|
28
|
+
resolveServiceErrorStatusCode(error) === 401,
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
export const subscriptionErrorMap: ErrorMap = {
|
|
@@ -58,10 +58,10 @@ export const syncErrorMap: ErrorMap = {
|
|
|
58
58
|
*/
|
|
59
59
|
function unwrapObservableError(observableError: any) {
|
|
60
60
|
const {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} = observableError;
|
|
61
|
+
errors: [error],
|
|
62
|
+
} = ({
|
|
63
|
+
errors: [],
|
|
64
|
+
} = observableError);
|
|
65
65
|
|
|
66
66
|
return error;
|
|
67
67
|
}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { GraphQLResult
|
|
3
|
+
import { GraphQLResult } from '@aws-amplify/api';
|
|
4
4
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
5
5
|
import {
|
|
6
6
|
Category,
|
|
7
|
-
ConsoleLogger as Logger,
|
|
8
7
|
CustomUserAgentDetails,
|
|
9
8
|
DataStoreAction,
|
|
10
9
|
jitteredBackoff,
|
|
11
10
|
NonRetryableError,
|
|
12
11
|
retry,
|
|
13
12
|
BackgroundProcessManager,
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
GraphQLAuthMode,
|
|
14
|
+
AmplifyError,
|
|
15
|
+
} from '@aws-amplify/core/internals/utils';
|
|
16
|
+
|
|
17
|
+
import { Observable, Observer } from 'rxjs';
|
|
16
18
|
import { MutationEvent } from '../';
|
|
17
19
|
import { ModelInstanceCreator } from '../../datastore/datastore';
|
|
18
20
|
import { ExclusiveStorage as Storage } from '../../storage/storage';
|
|
@@ -44,10 +46,11 @@ import {
|
|
|
44
46
|
getTokenForCustomAuth,
|
|
45
47
|
} from '../utils';
|
|
46
48
|
import { getMutationErrorType } from './errorMaps';
|
|
49
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
47
50
|
|
|
48
51
|
const MAX_ATTEMPTS = 10;
|
|
49
52
|
|
|
50
|
-
const logger = new
|
|
53
|
+
const logger = new ConsoleLogger('DataStore');
|
|
51
54
|
|
|
52
55
|
type MutationProcessorEvent = {
|
|
53
56
|
operation: TransformerMutationType;
|
|
@@ -65,7 +68,7 @@ class MutationProcessor {
|
|
|
65
68
|
* yet started. In this case, `isReady()` will be `false` and `resume()` will exit
|
|
66
69
|
* early.
|
|
67
70
|
*/
|
|
68
|
-
private observer?:
|
|
71
|
+
private observer?: Observer<MutationProcessorEvent>;
|
|
69
72
|
private readonly typeQuery = new WeakMap<
|
|
70
73
|
SchemaModel,
|
|
71
74
|
[TransformerMutationType, string, string][]
|
|
@@ -161,8 +164,8 @@ class MutationProcessor {
|
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
public async resume(): Promise<void> {
|
|
164
|
-
|
|
165
|
-
this.runningProcesses.add(async onTerminate => {
|
|
167
|
+
if (this.runningProcesses.isOpen) {
|
|
168
|
+
await this.runningProcesses.add(async onTerminate => {
|
|
166
169
|
if (
|
|
167
170
|
this.processing ||
|
|
168
171
|
!this.isReady() ||
|
|
@@ -170,7 +173,6 @@ class MutationProcessor {
|
|
|
170
173
|
) {
|
|
171
174
|
return;
|
|
172
175
|
}
|
|
173
|
-
|
|
174
176
|
this.processing = true;
|
|
175
177
|
let head: MutationEvent;
|
|
176
178
|
const namespaceName = USER;
|
|
@@ -300,7 +302,8 @@ class MutationProcessor {
|
|
|
300
302
|
|
|
301
303
|
// pauses itself
|
|
302
304
|
this.pause();
|
|
303
|
-
}, 'mutation resume loop')
|
|
305
|
+
}, 'mutation resume loop');
|
|
306
|
+
}
|
|
304
307
|
}
|
|
305
308
|
|
|
306
309
|
private async jitteredRetry(
|
|
@@ -312,7 +315,7 @@ class MutationProcessor {
|
|
|
312
315
|
modelConstructor: PersistentModelConstructor<PersistentModel>,
|
|
313
316
|
MutationEvent: PersistentModelConstructor<MutationEvent>,
|
|
314
317
|
mutationEvent: MutationEvent,
|
|
315
|
-
authMode:
|
|
318
|
+
authMode: GraphQLAuthMode,
|
|
316
319
|
onTerminate: Promise<void>
|
|
317
320
|
): Promise<
|
|
318
321
|
[GraphQLResult<Record<string, PersistentModel>>, string, SchemaModel]
|
|
@@ -544,7 +547,7 @@ class MutationProcessor {
|
|
|
544
547
|
|
|
545
548
|
// include all the fields that comprise a custom PK if one is specified
|
|
546
549
|
const deleteInput = {};
|
|
547
|
-
if (primaryKey
|
|
550
|
+
if (primaryKey && primaryKey.length) {
|
|
548
551
|
for (const pkField of primaryKey) {
|
|
549
552
|
deleteInput[pkField] = parsedData[pkField];
|
|
550
553
|
}
|
|
@@ -679,7 +682,10 @@ export const safeJitteredBackoff: typeof originalJitteredBackoff = (
|
|
|
679
682
|
const attemptResult = originalJitteredBackoff(attempt);
|
|
680
683
|
|
|
681
684
|
// If this is the last attempt and it is a network error, we retry indefinitively every 5 minutes
|
|
682
|
-
if (
|
|
685
|
+
if (
|
|
686
|
+
attemptResult === false &&
|
|
687
|
+
((error || {}) as any).message === 'Network Error'
|
|
688
|
+
) {
|
|
683
689
|
return MAX_RETRY_DELAY_MS;
|
|
684
690
|
}
|
|
685
691
|
|