@aws-amplify/datastore 3.7.8-cloud-logging.7 → 3.7.8-cloud-logging.8

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +28 -55
  2. package/README.md +154 -0
  3. package/dist/aws-amplify-datastore.js +706 -370
  4. package/dist/aws-amplify-datastore.js.map +1 -1
  5. package/dist/aws-amplify-datastore.min.js +23 -79
  6. package/dist/aws-amplify-datastore.min.js.map +1 -1
  7. package/lib/datastore/datastore.js +16 -0
  8. package/lib/datastore/datastore.js.map +1 -1
  9. package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
  10. package/lib/storage/storage.d.ts +2 -2
  11. package/lib/storage/storage.js +17 -4
  12. package/lib/storage/storage.js.map +1 -1
  13. package/lib/sync/merger.js +1 -0
  14. package/lib/sync/merger.js.map +1 -1
  15. package/lib/sync/outbox.js +1 -0
  16. package/lib/sync/outbox.js.map +1 -1
  17. package/lib/sync/processors/mutation.d.ts +17 -0
  18. package/lib/sync/processors/mutation.js +27 -2
  19. package/lib/sync/processors/mutation.js.map +1 -1
  20. package/lib/sync/processors/subscription.js +1 -2
  21. package/lib/sync/processors/subscription.js.map +1 -1
  22. package/lib/sync/processors/sync.js.map +1 -1
  23. package/lib/sync/utils.js.map +1 -1
  24. package/lib/types.d.ts +3 -1
  25. package/lib/types.js.map +1 -1
  26. package/lib-esm/datastore/datastore.js +16 -0
  27. package/lib-esm/datastore/datastore.js.map +1 -1
  28. package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
  29. package/lib-esm/storage/storage.d.ts +2 -2
  30. package/lib-esm/storage/storage.js +17 -4
  31. package/lib-esm/storage/storage.js.map +1 -1
  32. package/lib-esm/sync/merger.js +1 -0
  33. package/lib-esm/sync/merger.js.map +1 -1
  34. package/lib-esm/sync/outbox.js +1 -0
  35. package/lib-esm/sync/outbox.js.map +1 -1
  36. package/lib-esm/sync/processors/mutation.d.ts +17 -0
  37. package/lib-esm/sync/processors/mutation.js +28 -3
  38. package/lib-esm/sync/processors/mutation.js.map +1 -1
  39. package/lib-esm/sync/processors/subscription.js +1 -2
  40. package/lib-esm/sync/processors/subscription.js.map +1 -1
  41. package/lib-esm/sync/processors/sync.js.map +1 -1
  42. package/lib-esm/sync/utils.js.map +1 -1
  43. package/lib-esm/types.d.ts +3 -1
  44. package/lib-esm/types.js.map +1 -1
  45. package/package.json +7 -7
  46. package/src/datastore/datastore.ts +20 -0
  47. package/src/storage/adapter/IndexedDBAdapter.ts +1 -0
  48. package/src/storage/storage.ts +20 -7
  49. package/src/sync/merger.ts +2 -0
  50. package/src/sync/outbox.ts +1 -0
  51. package/src/sync/processors/mutation.ts +38 -3
  52. package/src/sync/processors/subscription.ts +18 -20
  53. package/src/sync/processors/sync.ts +5 -4
  54. package/src/sync/utils.ts +3 -5
  55. package/src/types.ts +7 -1
  56. package/ssr/package.json +1 -1
@@ -1,8 +1,9 @@
1
1
  import API, { GraphQLResult, GRAPHQL_AUTH_MODE } from '@aws-amplify/api';
2
2
  import {
3
3
  ConsoleLogger as Logger,
4
- jitteredExponentialRetry,
4
+ jitteredBackoff,
5
5
  NonRetryableError,
6
+ retry,
6
7
  } from '@aws-amplify/core';
7
8
  import Observable, { ZenObservable } from 'zen-observable-ts';
8
9
  import { MutationEvent } from '../';
@@ -241,7 +242,7 @@ class MutationProcessor {
241
242
  ): Promise<
242
243
  [GraphQLResult<Record<string, PersistentModel>>, string, SchemaModel]
243
244
  > {
244
- return await jitteredExponentialRetry(
245
+ return await retry(
245
246
  async (
246
247
  model: string,
247
248
  operation: TransformerMutationType,
@@ -414,7 +415,8 @@ class MutationProcessor {
414
415
  modelConstructor,
415
416
  MutationEvent,
416
417
  mutationEvent,
417
- ]
418
+ ],
419
+ safeJitteredBackoff
418
420
  );
419
421
  }
420
422
 
@@ -536,4 +538,37 @@ class MutationProcessor {
536
538
  }
537
539
  }
538
540
 
541
+ const MAX_RETRY_DELAY_MS = 5 * 60 * 1000;
542
+ const originalJitteredBackoff = jitteredBackoff(MAX_RETRY_DELAY_MS);
543
+
544
+ /**
545
+ * @private
546
+ * Internal use of Amplify only.
547
+ *
548
+ * Wraps the jittered backoff calculation to retry Network Errors indefinitely.
549
+ * Backs off according to original jittered retry logic until the original retry
550
+ * logic hits its max. After this occurs, if the error is a Network Error, we
551
+ * ignore the attempt count and return MAX_RETRY_DELAY_MS to retry forever (until
552
+ * the request succeeds).
553
+ *
554
+ * @param attempt ignored
555
+ * @param _args ignored
556
+ * @param error tested to see if `.message` is 'Network Error'
557
+ * @returns number | false :
558
+ */
559
+ export const safeJitteredBackoff: typeof originalJitteredBackoff = (
560
+ attempt,
561
+ _args,
562
+ error
563
+ ) => {
564
+ const attemptResult = originalJitteredBackoff(attempt);
565
+
566
+ // If this is the last attempt and it is a network error, we retry indefinitively every 5 minutes
567
+ if (attemptResult === false && error?.message === 'Network Error') {
568
+ return MAX_RETRY_DELAY_MS;
569
+ }
570
+
571
+ return attemptResult;
572
+ };
573
+
539
574
  export { MutationProcessor };
@@ -48,11 +48,8 @@ class SubscriptionProcessor {
48
48
  SchemaModel,
49
49
  [TransformerMutationType, string, string][]
50
50
  >();
51
- private buffer: [
52
- TransformerMutationType,
53
- SchemaModel,
54
- PersistentModel
55
- ][] = [];
51
+ private buffer: [TransformerMutationType, SchemaModel, PersistentModel][] =
52
+ [];
56
53
  private dataObserver: ZenObservable.Observer<any>;
57
54
 
58
55
  constructor(
@@ -308,8 +305,8 @@ class SubscriptionProcessor {
308
305
  .forEach(async modelDefinition => {
309
306
  const modelAuthModes = await getModelAuthModes({
310
307
  authModeStrategy: this.authModeStrategy,
311
- defaultAuthMode: this.amplifyConfig
312
- .aws_appsync_authenticationType,
308
+ defaultAuthMode:
309
+ this.amplifyConfig.aws_appsync_authenticationType,
313
310
  modelName: modelDefinition.name,
314
311
  schema: this.schema,
315
312
  });
@@ -413,10 +410,11 @@ class SubscriptionProcessor {
413
410
  return;
414
411
  }
415
412
 
416
- const predicatesGroup = ModelPredicateCreator.getPredicates(
417
- this.syncPredicates.get(modelDefinition),
418
- false
419
- );
413
+ const predicatesGroup =
414
+ ModelPredicateCreator.getPredicates(
415
+ this.syncPredicates.get(modelDefinition),
416
+ false
417
+ );
420
418
 
421
419
  const { [opName]: record } = data;
422
420
 
@@ -534,15 +532,15 @@ class SubscriptionProcessor {
534
532
 
535
533
  return () => {
536
534
  Object.keys(subscriptions).forEach(modelName => {
537
- subscriptions[modelName][
538
- TransformerMutationType.CREATE
539
- ].forEach(subscription => subscription.unsubscribe());
540
- subscriptions[modelName][
541
- TransformerMutationType.UPDATE
542
- ].forEach(subscription => subscription.unsubscribe());
543
- subscriptions[modelName][
544
- TransformerMutationType.DELETE
545
- ].forEach(subscription => subscription.unsubscribe());
535
+ subscriptions[modelName][TransformerMutationType.CREATE].forEach(
536
+ subscription => subscription.unsubscribe()
537
+ );
538
+ subscriptions[modelName][TransformerMutationType.UPDATE].forEach(
539
+ subscription => subscription.unsubscribe()
540
+ );
541
+ subscriptions[modelName][TransformerMutationType.DELETE].forEach(
542
+ subscription => subscription.unsubscribe()
543
+ );
546
544
  });
547
545
  };
548
546
  });
@@ -65,10 +65,11 @@ class SyncProcessor {
65
65
  if (!this.syncPredicates) {
66
66
  return null;
67
67
  }
68
- const predicatesGroup: PredicatesGroup<any> = ModelPredicateCreator.getPredicates(
69
- this.syncPredicates.get(model),
70
- false
71
- );
68
+ const predicatesGroup: PredicatesGroup<any> =
69
+ ModelPredicateCreator.getPredicates(
70
+ this.syncPredicates.get(model),
71
+ false
72
+ );
72
73
 
73
74
  if (!predicatesGroup) {
74
75
  return null;
package/src/sync/utils.ts CHANGED
@@ -515,11 +515,9 @@ export async function getModelAuthModes({
515
515
  defaultAuthMode: GRAPHQL_AUTH_MODE;
516
516
  modelName: string;
517
517
  schema: InternalSchema;
518
- }): Promise<
519
- {
520
- [key in ModelOperation]: GRAPHQL_AUTH_MODE[];
521
- }
522
- > {
518
+ }): Promise<{
519
+ [key in ModelOperation]: GRAPHQL_AUTH_MODE[];
520
+ }> {
523
521
  const operations = Object.values(ModelOperation);
524
522
 
525
523
  const modelAuthModes: {
package/src/types.ts CHANGED
@@ -392,11 +392,17 @@ export enum OpType {
392
392
  DELETE = 'DELETE',
393
393
  }
394
394
 
395
- export type SubscriptionMessage<T extends PersistentModel> = {
395
+ export type SubscriptionMessage<T extends PersistentModel> = Pick<
396
+ InternalSubscriptionMessage<T>,
397
+ 'opType' | 'element' | 'model' | 'condition'
398
+ >;
399
+
400
+ export type InternalSubscriptionMessage<T extends PersistentModel> = {
396
401
  opType: OpType;
397
402
  element: T;
398
403
  model: PersistentModelConstructor<T>;
399
404
  condition: PredicatesGroup<T> | null;
405
+ savedElement?: T;
400
406
  };
401
407
 
402
408
  export type DataStoreSnapshot<T extends PersistentModel> = {
package/ssr/package.json CHANGED
@@ -5,4 +5,4 @@
5
5
  "react-native": {
6
6
  "../lib/ssr/index": "../lib-esm/ssr/index.js"
7
7
  }
8
- }
8
+ }