@aws-amplify/datastore 3.7.4-custom-pk.96 → 3.7.4-custom-pk.97
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/aws-amplify-datastore.js +27 -29
- package/dist/aws-amplify-datastore.js.map +1 -1
- package/dist/aws-amplify-datastore.min.js +1 -1
- package/dist/aws-amplify-datastore.min.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +33 -32
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +33 -32
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/package.json +7 -7
- package/src/storage/adapter/IndexedDBAdapter.ts +59 -57
|
@@ -839,61 +839,34 @@ class IndexedDBAdapter implements Adapter {
|
|
|
839
839
|
deleteQueue: { storeName: string; items: T[] }[]
|
|
840
840
|
): Promise<void> {
|
|
841
841
|
for await (const rel of relations) {
|
|
842
|
-
const {
|
|
843
|
-
|
|
842
|
+
const {
|
|
843
|
+
relationType,
|
|
844
|
+
modelName,
|
|
845
|
+
targetName,
|
|
846
|
+
targetNames,
|
|
847
|
+
associatedWith,
|
|
848
|
+
} = rel;
|
|
844
849
|
|
|
845
850
|
const storeName = this.getStorename(nameSpace, modelName);
|
|
846
851
|
|
|
847
|
-
const index: string | string[] | undefined =
|
|
848
|
-
getIndex(
|
|
849
|
-
this.schema.namespaces[nameSpace].relationships[modelName]
|
|
850
|
-
.relationTypes,
|
|
851
|
-
srcModel
|
|
852
|
-
) ||
|
|
853
|
-
// if we were unable to find an index via relationTypes
|
|
854
|
-
// i.e. for keyName connections, attempt to find one by the
|
|
855
|
-
// associatedWith property
|
|
856
|
-
getIndexFromAssociation(
|
|
857
|
-
this.schema.namespaces[nameSpace].relationships[modelName].indexes,
|
|
858
|
-
rel.associatedWith
|
|
859
|
-
);
|
|
860
|
-
|
|
861
|
-
// TODO: refactor
|
|
862
852
|
switch (relationType) {
|
|
863
853
|
case 'HAS_ONE':
|
|
864
854
|
for await (const model of models) {
|
|
865
|
-
const hasOneIndex =
|
|
866
|
-
|
|
867
|
-
// CPK
|
|
868
|
-
if (targetNames && targetNames.length > 0) {
|
|
869
|
-
// iterate over targetNames array and see if each item is present in model object
|
|
870
|
-
// targetNames here being the keys for the CHILD model
|
|
871
|
-
const hasConnectedModelFields = targetNames.every(targetName =>
|
|
872
|
-
model.hasOwnProperty(targetName)
|
|
873
|
-
);
|
|
874
|
-
|
|
875
|
-
// PK / Composite key for the PARENT model
|
|
876
|
-
const keyValues = this.getIndexKeyValues(model);
|
|
855
|
+
const hasOneIndex = 'byPk';
|
|
877
856
|
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
// Values will be that of the child model
|
|
882
|
-
values = targetNames.map(
|
|
883
|
-
targetName => model[targetName]
|
|
884
|
-
) as any;
|
|
885
|
-
} else {
|
|
886
|
-
// values will be that of the parent model
|
|
887
|
-
values = keyValues as any;
|
|
888
|
-
}
|
|
857
|
+
if (targetNames?.length) {
|
|
858
|
+
// CPK codegen
|
|
859
|
+
const values = targetNames.map(targetName => model[targetName]);
|
|
889
860
|
|
|
890
861
|
if (values.length === 0) break;
|
|
891
862
|
|
|
892
|
-
const recordToDelete = <T>
|
|
893
|
-
.
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
863
|
+
const recordToDelete = <T>(
|
|
864
|
+
await this.db
|
|
865
|
+
.transaction(storeName, 'readwrite')
|
|
866
|
+
.objectStore(storeName)
|
|
867
|
+
.index(hasOneIndex)
|
|
868
|
+
.get(values)
|
|
869
|
+
);
|
|
897
870
|
|
|
898
871
|
await this.deleteTraverse(
|
|
899
872
|
this.schema.namespaces[nameSpace].relationships[modelName]
|
|
@@ -905,20 +878,36 @@ class IndexedDBAdapter implements Adapter {
|
|
|
905
878
|
);
|
|
906
879
|
break;
|
|
907
880
|
} else {
|
|
908
|
-
//
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
881
|
+
// PRE-CPK codegen
|
|
882
|
+
let index;
|
|
883
|
+
let values: string[];
|
|
884
|
+
|
|
885
|
+
if (targetName && targetName in model) {
|
|
886
|
+
index = hasOneIndex;
|
|
887
|
+
const value = model[targetName];
|
|
888
|
+
values = [value];
|
|
889
|
+
} else {
|
|
890
|
+
// backwards compatability for older versions of codegen that did not emit targetName for HAS_ONE relations
|
|
891
|
+
// TODO: can we deprecate this? it's been ~2 years since codegen started including targetName for HAS_ONE
|
|
892
|
+
// If we deprecate, we'll need to re-gen the MIPR in __tests__/schema.ts > newSchema
|
|
893
|
+
// otherwise some unit tests will fail
|
|
894
|
+
index = getIndex(
|
|
895
|
+
this.schema.namespaces[nameSpace].relationships[modelName]
|
|
896
|
+
.relationTypes,
|
|
897
|
+
srcModel
|
|
898
|
+
);
|
|
899
|
+
values = this.getIndexKeyValues(model);
|
|
900
|
+
}
|
|
914
901
|
|
|
915
|
-
if (!
|
|
902
|
+
if (!values || !index) break;
|
|
916
903
|
|
|
917
|
-
const recordToDelete = <T>
|
|
918
|
-
.
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
904
|
+
const recordToDelete = <T>(
|
|
905
|
+
await this.db
|
|
906
|
+
.transaction(storeName, 'readwrite')
|
|
907
|
+
.objectStore(storeName)
|
|
908
|
+
.index(index)
|
|
909
|
+
.get(values)
|
|
910
|
+
);
|
|
922
911
|
|
|
923
912
|
await this.deleteTraverse(
|
|
924
913
|
this.schema.namespaces[nameSpace].relationships[modelName]
|
|
@@ -933,6 +922,19 @@ class IndexedDBAdapter implements Adapter {
|
|
|
933
922
|
break;
|
|
934
923
|
case 'HAS_MANY':
|
|
935
924
|
for await (const model of models) {
|
|
925
|
+
const index =
|
|
926
|
+
// explicit bi-directional @hasMany and @manyToMany
|
|
927
|
+
getIndex(
|
|
928
|
+
this.schema.namespaces[nameSpace].relationships[modelName]
|
|
929
|
+
.relationTypes,
|
|
930
|
+
srcModel
|
|
931
|
+
) ||
|
|
932
|
+
// uni and/or implicit @hasMany
|
|
933
|
+
getIndexFromAssociation(
|
|
934
|
+
this.schema.namespaces[nameSpace].relationships[modelName]
|
|
935
|
+
.indexes,
|
|
936
|
+
associatedWith
|
|
937
|
+
);
|
|
936
938
|
const keyValues = this.getIndexKeyValues(model);
|
|
937
939
|
|
|
938
940
|
const childrenArray = await this.db
|