@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.
- package/CHANGELOG.md +12 -0
- package/dist/aws-amplify-datastore.js +2798 -1458
- package/dist/aws-amplify-datastore.js.map +1 -1
- package/dist/aws-amplify-datastore.min.js +10 -10
- package/dist/aws-amplify-datastore.min.js.map +1 -1
- package/lib/authModeStrategies/multiAuthStrategy.js +11 -0
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.js +524 -323
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +76 -25
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/storage.js +2 -2
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.js +45 -0
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/index.js +518 -395
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.js +6 -0
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.js +66 -62
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/mutation.js +207 -165
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.js +210 -175
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.js +95 -72
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.js +1 -3
- package/lib/sync/utils.js.map +1 -1
- package/lib/util.js +89 -0
- package/lib/util.js.map +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.d.ts +11 -0
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +11 -0
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +95 -2
- package/lib-esm/datastore/datastore.js +524 -323
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +21 -0
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +77 -26
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/storage.js +2 -2
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -0
- package/lib-esm/sync/datastoreConnectivity.js +45 -0
- package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
- package/lib-esm/sync/index.d.ts +9 -1
- package/lib-esm/sync/index.js +519 -396
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.d.ts +6 -0
- package/lib-esm/sync/merger.js +6 -0
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.js +66 -62
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/mutation.d.ts +2 -0
- package/lib-esm/sync/processors/mutation.js +208 -166
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.d.ts +2 -0
- package/lib-esm/sync/processors/subscription.js +211 -176
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.d.ts +2 -0
- package/lib-esm/sync/processors/sync.js +96 -73
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.js +1 -3
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/util.d.ts +11 -0
- package/lib-esm/util.js +89 -0
- package/lib-esm/util.js.map +1 -1
- package/package.json +7 -7
- package/src/authModeStrategies/multiAuthStrategy.ts +11 -0
- package/src/datastore/datastore.ts +572 -366
- package/src/storage/adapter/IndexedDBAdapter.ts +50 -9
- package/src/storage/storage.ts +2 -2
- package/src/sync/datastoreConnectivity.ts +6 -0
- package/src/sync/index.ts +492 -400
- package/src/sync/merger.ts +6 -0
- package/src/sync/outbox.ts +1 -1
- package/src/sync/processors/mutation.ts +139 -104
- package/src/sync/processors/subscription.ts +287 -250
- package/src/sync/processors/sync.ts +88 -60
- package/src/sync/utils.ts +1 -3
- package/src/util.ts +92 -2
- package/lib/authModeStrategies/defaultAuthStrategy.d.ts +0 -2
- package/lib/authModeStrategies/index.d.ts +0 -2
- package/lib/authModeStrategies/multiAuthStrategy.d.ts +0 -2
- package/lib/datastore/datastore.d.ts +0 -63
- package/lib/index.d.ts +0 -15
- package/lib/predicates/index.d.ts +0 -16
- package/lib/predicates/sort.d.ts +0 -8
- package/lib/ssr/index.d.ts +0 -3
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +0 -41
- package/lib/storage/adapter/AsyncStorageDatabase.d.ts +0 -39
- package/lib/storage/adapter/InMemoryStore.d.ts +0 -11
- package/lib/storage/adapter/InMemoryStore.native.d.ts +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.d.ts +0 -38
- package/lib/storage/adapter/getDefaultAdapter/index.d.ts +0 -3
- package/lib/storage/adapter/getDefaultAdapter/index.native.d.ts +0 -3
- package/lib/storage/adapter/index.d.ts +0 -9
- package/lib/storage/storage.d.ts +0 -49
- package/lib/sync/datastoreConnectivity.d.ts +0 -15
- package/lib/sync/datastoreReachability/index.d.ts +0 -3
- package/lib/sync/datastoreReachability/index.native.d.ts +0 -3
- package/lib/sync/index.d.ts +0 -81
- package/lib/sync/merger.d.ts +0 -11
- package/lib/sync/outbox.d.ts +0 -27
- package/lib/sync/processors/errorMaps.d.ts +0 -17
- package/lib/sync/processors/mutation.d.ts +0 -56
- package/lib/sync/processors/subscription.d.ts +0 -31
- package/lib/sync/processors/sync.d.ts +0 -26
- package/lib/sync/utils.d.ts +0 -42
- package/lib/types.d.ts +0 -501
- package/lib/util.d.ts +0 -145
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
getStorename,
|
|
34
34
|
getIndexKeys,
|
|
35
35
|
extractPrimaryKeyValues,
|
|
36
|
+
isSafariCompatabilityMode,
|
|
36
37
|
} from '../../util';
|
|
37
38
|
import { Adapter } from './index';
|
|
38
39
|
|
|
@@ -52,6 +53,7 @@ class IndexedDBAdapter implements Adapter {
|
|
|
52
53
|
private resolve: (value?: any) => void;
|
|
53
54
|
private reject: (value?: any) => void;
|
|
54
55
|
private dbName: string = DB_NAME;
|
|
56
|
+
private safariCompatabilityMode: boolean = false;
|
|
55
57
|
|
|
56
58
|
private getStorenameForModel(
|
|
57
59
|
modelConstructor: PersistentModelConstructor<any>
|
|
@@ -92,6 +94,24 @@ class IndexedDBAdapter implements Adapter {
|
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Whether the browser's implementation of IndexedDB is coercing single-field
|
|
99
|
+
* indexes to a scalar key.
|
|
100
|
+
*
|
|
101
|
+
* If this returns `true`, we need to treat indexes containing a single field
|
|
102
|
+
* as scalars.
|
|
103
|
+
*
|
|
104
|
+
* See PR description for reference:
|
|
105
|
+
* https://github.com/aws-amplify/amplify-js/pull/10527
|
|
106
|
+
*/
|
|
107
|
+
private async setSafariCompatabilityMode() {
|
|
108
|
+
this.safariCompatabilityMode = await isSafariCompatabilityMode();
|
|
109
|
+
|
|
110
|
+
if (this.safariCompatabilityMode === true) {
|
|
111
|
+
logger.debug('IndexedDB Adapter is running in Safari Compatability Mode');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
95
115
|
private getNamespaceAndModelFromStorename(storeName: string) {
|
|
96
116
|
const [namespaceName, ...modelNameArr] = storeName.split('_');
|
|
97
117
|
return {
|
|
@@ -111,6 +131,7 @@ class IndexedDBAdapter implements Adapter {
|
|
|
111
131
|
sessionId?: string
|
|
112
132
|
) {
|
|
113
133
|
await this.checkPrivate();
|
|
134
|
+
await this.setSafariCompatabilityMode();
|
|
114
135
|
|
|
115
136
|
if (!this.initPromise) {
|
|
116
137
|
this.initPromise = new Promise((res, rej) => {
|
|
@@ -244,7 +265,7 @@ class IndexedDBAdapter implements Adapter {
|
|
|
244
265
|
index = store.index('byPk');
|
|
245
266
|
}
|
|
246
267
|
|
|
247
|
-
const result = await index.get(keyArr);
|
|
268
|
+
const result = await index.get(this.canonicalKeyPath(keyArr));
|
|
248
269
|
|
|
249
270
|
return result;
|
|
250
271
|
}
|
|
@@ -326,7 +347,9 @@ class IndexedDBAdapter implements Adapter {
|
|
|
326
347
|
keysEqual(itemKeyValues, modelKeyValues) ||
|
|
327
348
|
opType === OpType.INSERT
|
|
328
349
|
) {
|
|
329
|
-
const key = await store
|
|
350
|
+
const key = await store
|
|
351
|
+
.index('byPk')
|
|
352
|
+
.getKey(this.canonicalKeyPath(itemKeyValues));
|
|
330
353
|
await store.put(item, key);
|
|
331
354
|
|
|
332
355
|
result.push([instance, opType]);
|
|
@@ -808,10 +831,12 @@ class IndexedDBAdapter implements Adapter {
|
|
|
808
831
|
|
|
809
832
|
if (typeof item === 'object') {
|
|
810
833
|
const keyValues = this.getIndexKeyValuesFromModel(item as T);
|
|
811
|
-
key = await store
|
|
834
|
+
key = await store
|
|
835
|
+
.index('byPk')
|
|
836
|
+
.getKey(this.canonicalKeyPath(keyValues));
|
|
812
837
|
} else {
|
|
813
|
-
const itemKey =
|
|
814
|
-
key = await store.index('byPk').getKey(
|
|
838
|
+
const itemKey = item.toString();
|
|
839
|
+
key = await store.index('byPk').getKey(itemKey);
|
|
815
840
|
}
|
|
816
841
|
|
|
817
842
|
if (key !== undefined) {
|
|
@@ -856,7 +881,7 @@ class IndexedDBAdapter implements Adapter {
|
|
|
856
881
|
.transaction(storeName, 'readwrite')
|
|
857
882
|
.objectStore(storeName)
|
|
858
883
|
.index(hasOneIndex)
|
|
859
|
-
.get(values)
|
|
884
|
+
.get(this.canonicalKeyPath(values))
|
|
860
885
|
);
|
|
861
886
|
|
|
862
887
|
await this.deleteTraverse(
|
|
@@ -897,7 +922,7 @@ class IndexedDBAdapter implements Adapter {
|
|
|
897
922
|
.transaction(storeName, 'readwrite')
|
|
898
923
|
.objectStore(storeName)
|
|
899
924
|
.index(index)
|
|
900
|
-
.get(values)
|
|
925
|
+
.get(this.canonicalKeyPath(values))
|
|
901
926
|
);
|
|
902
927
|
|
|
903
928
|
await this.deleteTraverse(
|
|
@@ -932,7 +957,7 @@ class IndexedDBAdapter implements Adapter {
|
|
|
932
957
|
.transaction(storeName, 'readwrite')
|
|
933
958
|
.objectStore(storeName)
|
|
934
959
|
.index(index as string)
|
|
935
|
-
.getAll(keyValues);
|
|
960
|
+
.getAll(this.canonicalKeyPath(keyValues));
|
|
936
961
|
|
|
937
962
|
await this.deleteTraverse(
|
|
938
963
|
this.schema.namespaces[nameSpace].relationships[modelName]
|
|
@@ -1009,7 +1034,8 @@ class IndexedDBAdapter implements Adapter {
|
|
|
1009
1034
|
const { _deleted } = item;
|
|
1010
1035
|
|
|
1011
1036
|
const index = store.index('byPk');
|
|
1012
|
-
|
|
1037
|
+
|
|
1038
|
+
const key = await index.getKey(this.canonicalKeyPath(keyValues));
|
|
1013
1039
|
|
|
1014
1040
|
if (!_deleted) {
|
|
1015
1041
|
const { instance } = connectedModels.find(({ instance }) => {
|
|
@@ -1055,6 +1081,21 @@ class IndexedDBAdapter implements Adapter {
|
|
|
1055
1081
|
|
|
1056
1082
|
return store;
|
|
1057
1083
|
}
|
|
1084
|
+
|
|
1085
|
+
/**
|
|
1086
|
+
* Checks the given path against the browser's IndexedDB implementation for
|
|
1087
|
+
* necessary compatibility transformations, applying those transforms if needed.
|
|
1088
|
+
*
|
|
1089
|
+
* @param `keyArr` strings to compatibilize for browser-indexeddb index operations
|
|
1090
|
+
* @returns An array or string, depending on and given key,
|
|
1091
|
+
* that is ensured to be compatible with the IndexedDB implementation's nuances.
|
|
1092
|
+
*/
|
|
1093
|
+
private canonicalKeyPath = (keyArr: string[]) => {
|
|
1094
|
+
if (this.safariCompatabilityMode) {
|
|
1095
|
+
return keyArr.length > 1 ? keyArr : keyArr[0];
|
|
1096
|
+
}
|
|
1097
|
+
return keyArr;
|
|
1098
|
+
};
|
|
1058
1099
|
}
|
|
1059
1100
|
|
|
1060
1101
|
export default new IndexedDBAdapter();
|
package/src/storage/storage.ts
CHANGED
|
@@ -407,7 +407,7 @@ class StorageClass implements StorageFacade {
|
|
|
407
407
|
}
|
|
408
408
|
});
|
|
409
409
|
|
|
410
|
-
|
|
410
|
+
// Exit early when there are no changes introduced in the update mutation
|
|
411
411
|
if (Object.keys(updatedElement).length === 0) {
|
|
412
412
|
return null;
|
|
413
413
|
}
|
|
@@ -532,7 +532,7 @@ class ExclusiveStorage implements StorageFacade {
|
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
async clear() {
|
|
535
|
-
await this.storage.clear();
|
|
535
|
+
await this.runExclusive(storage => storage.clear());
|
|
536
536
|
}
|
|
537
537
|
|
|
538
538
|
batchSave<T extends PersistentModel>(
|
|
@@ -52,6 +52,12 @@ export default class DataStoreConnectivity {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// for consistency with other background processors.
|
|
56
|
+
async stop() {
|
|
57
|
+
this.unsubscribe();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
55
61
|
socketDisconnected() {
|
|
56
62
|
if (this.observer && typeof this.observer.next === 'function') {
|
|
57
63
|
this.observer.next({ online: false }); // Notify network issue from the socket
|