@aws-amplify/datastore 3.14.1-unstable.3 → 3.14.1

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 (111) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/aws-amplify-datastore.js +2798 -1458
  3. package/dist/aws-amplify-datastore.js.map +1 -1
  4. package/dist/aws-amplify-datastore.min.js +10 -10
  5. package/dist/aws-amplify-datastore.min.js.map +1 -1
  6. package/lib/authModeStrategies/multiAuthStrategy.js +11 -0
  7. package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
  8. package/lib/datastore/datastore.js +524 -323
  9. package/lib/datastore/datastore.js.map +1 -1
  10. package/lib/storage/adapter/IndexedDBAdapter.js +76 -25
  11. package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
  12. package/lib/storage/storage.js +2 -2
  13. package/lib/storage/storage.js.map +1 -1
  14. package/lib/sync/datastoreConnectivity.js +45 -0
  15. package/lib/sync/datastoreConnectivity.js.map +1 -1
  16. package/lib/sync/index.js +518 -395
  17. package/lib/sync/index.js.map +1 -1
  18. package/lib/sync/merger.js +6 -0
  19. package/lib/sync/merger.js.map +1 -1
  20. package/lib/sync/outbox.js +66 -62
  21. package/lib/sync/outbox.js.map +1 -1
  22. package/lib/sync/processors/mutation.js +207 -165
  23. package/lib/sync/processors/mutation.js.map +1 -1
  24. package/lib/sync/processors/subscription.js +210 -175
  25. package/lib/sync/processors/subscription.js.map +1 -1
  26. package/lib/sync/processors/sync.js +95 -72
  27. package/lib/sync/processors/sync.js.map +1 -1
  28. package/lib/sync/utils.js +1 -3
  29. package/lib/sync/utils.js.map +1 -1
  30. package/lib/util.js +89 -0
  31. package/lib/util.js.map +1 -1
  32. package/lib-esm/authModeStrategies/multiAuthStrategy.d.ts +11 -0
  33. package/lib-esm/authModeStrategies/multiAuthStrategy.js +11 -0
  34. package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
  35. package/lib-esm/datastore/datastore.d.ts +95 -2
  36. package/lib-esm/datastore/datastore.js +524 -323
  37. package/lib-esm/datastore/datastore.js.map +1 -1
  38. package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +21 -0
  39. package/lib-esm/storage/adapter/IndexedDBAdapter.js +77 -26
  40. package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
  41. package/lib-esm/storage/storage.js +2 -2
  42. package/lib-esm/storage/storage.js.map +1 -1
  43. package/lib-esm/sync/datastoreConnectivity.d.ts +1 -0
  44. package/lib-esm/sync/datastoreConnectivity.js +45 -0
  45. package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
  46. package/lib-esm/sync/index.d.ts +9 -1
  47. package/lib-esm/sync/index.js +519 -396
  48. package/lib-esm/sync/index.js.map +1 -1
  49. package/lib-esm/sync/merger.d.ts +6 -0
  50. package/lib-esm/sync/merger.js +6 -0
  51. package/lib-esm/sync/merger.js.map +1 -1
  52. package/lib-esm/sync/outbox.js +66 -62
  53. package/lib-esm/sync/outbox.js.map +1 -1
  54. package/lib-esm/sync/processors/mutation.d.ts +2 -0
  55. package/lib-esm/sync/processors/mutation.js +208 -166
  56. package/lib-esm/sync/processors/mutation.js.map +1 -1
  57. package/lib-esm/sync/processors/subscription.d.ts +2 -0
  58. package/lib-esm/sync/processors/subscription.js +211 -176
  59. package/lib-esm/sync/processors/subscription.js.map +1 -1
  60. package/lib-esm/sync/processors/sync.d.ts +2 -0
  61. package/lib-esm/sync/processors/sync.js +96 -73
  62. package/lib-esm/sync/processors/sync.js.map +1 -1
  63. package/lib-esm/sync/utils.js +1 -3
  64. package/lib-esm/sync/utils.js.map +1 -1
  65. package/lib-esm/util.d.ts +11 -0
  66. package/lib-esm/util.js +89 -0
  67. package/lib-esm/util.js.map +1 -1
  68. package/package.json +7 -7
  69. package/src/authModeStrategies/multiAuthStrategy.ts +11 -0
  70. package/src/datastore/datastore.ts +572 -366
  71. package/src/storage/adapter/IndexedDBAdapter.ts +50 -9
  72. package/src/storage/storage.ts +2 -2
  73. package/src/sync/datastoreConnectivity.ts +6 -0
  74. package/src/sync/index.ts +492 -400
  75. package/src/sync/merger.ts +6 -0
  76. package/src/sync/outbox.ts +1 -1
  77. package/src/sync/processors/mutation.ts +139 -104
  78. package/src/sync/processors/subscription.ts +287 -250
  79. package/src/sync/processors/sync.ts +88 -60
  80. package/src/sync/utils.ts +1 -3
  81. package/src/util.ts +92 -2
  82. package/lib/authModeStrategies/defaultAuthStrategy.d.ts +0 -2
  83. package/lib/authModeStrategies/index.d.ts +0 -2
  84. package/lib/authModeStrategies/multiAuthStrategy.d.ts +0 -2
  85. package/lib/datastore/datastore.d.ts +0 -63
  86. package/lib/index.d.ts +0 -15
  87. package/lib/predicates/index.d.ts +0 -16
  88. package/lib/predicates/sort.d.ts +0 -8
  89. package/lib/ssr/index.d.ts +0 -3
  90. package/lib/storage/adapter/AsyncStorageAdapter.d.ts +0 -41
  91. package/lib/storage/adapter/AsyncStorageDatabase.d.ts +0 -39
  92. package/lib/storage/adapter/InMemoryStore.d.ts +0 -11
  93. package/lib/storage/adapter/InMemoryStore.native.d.ts +0 -1
  94. package/lib/storage/adapter/IndexedDBAdapter.d.ts +0 -38
  95. package/lib/storage/adapter/getDefaultAdapter/index.d.ts +0 -3
  96. package/lib/storage/adapter/getDefaultAdapter/index.native.d.ts +0 -3
  97. package/lib/storage/adapter/index.d.ts +0 -9
  98. package/lib/storage/storage.d.ts +0 -49
  99. package/lib/sync/datastoreConnectivity.d.ts +0 -15
  100. package/lib/sync/datastoreReachability/index.d.ts +0 -3
  101. package/lib/sync/datastoreReachability/index.native.d.ts +0 -3
  102. package/lib/sync/index.d.ts +0 -81
  103. package/lib/sync/merger.d.ts +0 -11
  104. package/lib/sync/outbox.d.ts +0 -27
  105. package/lib/sync/processors/errorMaps.d.ts +0 -17
  106. package/lib/sync/processors/mutation.d.ts +0 -56
  107. package/lib/sync/processors/subscription.d.ts +0 -31
  108. package/lib/sync/processors/sync.d.ts +0 -26
  109. package/lib/sync/utils.d.ts +0 -42
  110. package/lib/types.d.ts +0 -501
  111. package/lib/util.d.ts +0 -145
@@ -3,6 +3,15 @@ import { PredicateAll } from '../predicates';
3
3
  import { ConflictHandler, DataStoreConfig, NonModelTypeConstructor, ProducerPaginationInput, PersistentModel, PersistentModelConstructor, ProducerModelPredicate, Schema, SubscriptionMessage, DataStoreSnapshot, TypeConstructorMap, ErrorHandler, ObserveQueryOptions, PersistentModelMetaData, IdentifierFieldOrIdentifierObject } from '../types';
4
4
  export declare let syncClasses: TypeConstructorMap;
5
5
  declare const initSchema: (userSchema: Schema) => Record<string, PersistentModelConstructor<any> | NonModelTypeConstructor<unknown>>;
6
+ /**
7
+ * Constructs a model and records it with its metadata in a weakset. Allows for
8
+ * the separate storage of core model fields and Amplify/DataStore metadata
9
+ * fields that the customer app does not want exposed.
10
+ *
11
+ * @param modelConstructor The model constructor.
12
+ * @param init Init data that would normally be passed to the constructor.
13
+ * @returns The initialized model.
14
+ */
6
15
  export declare type ModelInstanceCreator = typeof modelInstanceCreator;
7
16
  declare function modelInstanceCreator<T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, init: Partial<T>): T;
8
17
  declare class DataStore {
@@ -26,7 +35,62 @@ declare class DataStore {
26
35
  private sessionId;
27
36
  private storageAdapter;
28
37
  private amplifyContext;
38
+ private connectivityMonitor?;
39
+ /**
40
+ * **IMPORTANT!**
41
+ *
42
+ * Accumulator for background things that can **and MUST** be called when
43
+ * DataStore stops.
44
+ *
45
+ * These jobs **MUST** be *idempotent promises* that resolve ONLY
46
+ * once the intended jobs are completely finished and/or otherwise destroyed
47
+ * and cleaned up with ZERO outstanding:
48
+ *
49
+ * 1. side effects (e.g., state changes)
50
+ * 1. callbacks
51
+ * 1. subscriptions
52
+ * 1. calls to storage
53
+ * 1. *etc.*
54
+ *
55
+ * Methods that create pending promises, subscriptions, callbacks, or any
56
+ * type of side effect **MUST** be registered with the manager. And, a new
57
+ * manager must be created after each `exit()`.
58
+ *
59
+ * Failure to comply will put DataStore into a highly unpredictable state
60
+ * when it needs to stop or clear -- which occurs when restarting with new
61
+ * sync expressions, during testing, and potentially during app code
62
+ * recovery handling, etc..
63
+ *
64
+ * It is up to the discretion of each disposer whether to wait for job
65
+ * completion or to cancel operations and issue failures *as long as the
66
+ * disposer returns in a reasonable amount of time.*
67
+ *
68
+ * (Reasonable = *seconds*, not minutes.)
69
+ */
70
+ private runningProcesses;
71
+ /**
72
+ * Indicates what state DataStore is in.
73
+ *
74
+ * Not [yet?] used for actual state management; but for messaging
75
+ * when errors occur, to help troubleshoot.
76
+ */
77
+ private state;
29
78
  getModuleName(): string;
79
+ /**
80
+ * Builds a function to capture `BackgroundManagerNotOpenError`'s to produce friendlier,
81
+ * more instructive errors for customers.
82
+ *
83
+ * @param operation The name of the operation (usually a Datastore method) the customer
84
+ * tried to call.
85
+ */
86
+ handleAddProcError(operation: string): (err: Error) => never;
87
+ /**
88
+ * If not already done:
89
+ * 1. Attaches and initializes storage.
90
+ * 1. Loads the schema and records metadata.
91
+ * 1. If `this.amplifyConfig.aws_appsync_graphqlEndpoint` contains a URL,
92
+ * attaches a sync engine, starts it, and subscribes.
93
+ */
30
94
  start: () => Promise<void>;
31
95
  query: {
32
96
  <T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, identifier: IdentifierFieldOrIdentifierObject<T, PersistentModelMetaData<T>>): Promise<T | undefined>;
@@ -50,13 +114,42 @@ declare class DataStore {
50
114
  <T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, criteria?: ProducerModelPredicate<T> | typeof PredicateAll, paginationProducer?: ObserveQueryOptions<T>): Observable<DataStoreSnapshot<T>>;
51
115
  };
52
116
  configure: (config?: DataStoreConfig) => void;
53
- clear: () => Promise<void>;
54
- stop: (this: DataStore) => Promise<void>;
117
+ /**
118
+ * Clears all data from storage and removes all data, schema info, other
119
+ * initialization details, and then stops DataStore.
120
+ *
121
+ * That said, reinitialization is required after clearing. This can be done
122
+ * by explicitiliy calling `start()` or any method that implicitly starts
123
+ * DataStore, such as `query()`, `save()`, or `delete()`.
124
+ */
125
+ clear(): Promise<void>;
126
+ /**
127
+ * Stops all DataStore sync activities.
128
+ *
129
+ * TODO: "Waits for graceful termination of
130
+ * running queries and terminates subscriptions."
131
+ */
132
+ stop(this: InstanceType<typeof DataStore>): Promise<void>;
133
+ /**
134
+ * Validates given pagination input from a query and creates a pagination
135
+ * argument for use against the storage layer.
136
+ *
137
+ * @param modelDefinition
138
+ * @param paginationProducer
139
+ */
55
140
  private processPagination;
141
+ /**
142
+ * Examines the configured `syncExpressions` and produces a WeakMap of
143
+ * SchemaModel -> predicate to use during sync.
144
+ */
56
145
  private processSyncExpressions;
57
146
  private createFromCondition;
58
147
  private unwrapPromise;
59
148
  private weakMapFromEntries;
149
+ /**
150
+ * A session ID to allow CMS to open databases against multiple apps.
151
+ * This session ID is only expected be set by AWS Amplify Studio.
152
+ */
60
153
  private retrieveSessionId;
61
154
  }
62
155
  declare const instance: DataStore;