@aws-amplify/datastore 3.7.4-custom-pk.92 → 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 +56 -38
- package/dist/aws-amplify-datastore.js.map +1 -1
- package/dist/aws-amplify-datastore.min.js +2 -2
- package/dist/aws-amplify-datastore.min.js.map +1 -1
- package/lib/datastore/datastore.js +21 -8
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +33 -32
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/storage.js.map +1 -1
- package/lib/util.d.ts +2 -0
- package/lib/util.js +3 -1
- package/lib/util.js.map +1 -1
- package/lib-esm/datastore/datastore.js +21 -8
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +33 -32
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/util.d.ts +2 -0
- package/lib-esm/util.js +3 -1
- package/lib-esm/util.js.map +1 -1
- package/package.json +7 -7
- package/src/datastore/datastore.ts +24 -2
- package/src/storage/adapter/IndexedDBAdapter.ts +59 -57
- package/src/storage/storage.ts +0 -1
- package/src/util.ts +5 -1
|
@@ -83037,17 +83037,17 @@ function () {
|
|
|
83037
83037
|
|
|
83038
83038
|
this["delete"] = function (modelOrConstructor, identifierOrCriteria) {
|
|
83039
83039
|
return __awaiter(_this, void 0, void 0, function () {
|
|
83040
|
-
var condition, msg, modelConstructor, msg, modelDefinition,
|
|
83040
|
+
var condition, msg, modelConstructor, msg, modelDefinition, keyFields, msg, msg, _a, deleted, model, modelConstructor, msg, modelDefinition, pkPredicate, msg, _b, _c, deleted;
|
|
83041
83041
|
|
|
83042
|
-
return __generator(this, function (
|
|
83043
|
-
switch (
|
|
83042
|
+
return __generator(this, function (_d) {
|
|
83043
|
+
switch (_d.label) {
|
|
83044
83044
|
case 0:
|
|
83045
83045
|
return [4
|
|
83046
83046
|
/*yield*/
|
|
83047
83047
|
, this.start()];
|
|
83048
83048
|
|
|
83049
83049
|
case 1:
|
|
83050
|
-
|
|
83050
|
+
_d.sent();
|
|
83051
83051
|
|
|
83052
83052
|
if (!modelOrConstructor) {
|
|
83053
83053
|
msg = 'Model or Model Constructor required';
|
|
@@ -83073,8 +83073,17 @@ function () {
|
|
|
83073
83073
|
modelDefinition = getModelDefinition(modelConstructor);
|
|
83074
83074
|
|
|
83075
83075
|
if (typeof identifierOrCriteria === 'string') {
|
|
83076
|
-
|
|
83077
|
-
|
|
83076
|
+
keyFields = Object(_util__WEBPACK_IMPORTED_MODULE_12__["extractPrimaryKeyFieldNames"])(modelDefinition);
|
|
83077
|
+
|
|
83078
|
+
if (keyFields.length > 1) {
|
|
83079
|
+
msg = _util__WEBPACK_IMPORTED_MODULE_12__["errorMessages"].deleteByPkWithCompositeKeyPresent;
|
|
83080
|
+
logger.error(msg, {
|
|
83081
|
+
keyFields: keyFields
|
|
83082
|
+
});
|
|
83083
|
+
throw new Error(msg);
|
|
83084
|
+
}
|
|
83085
|
+
|
|
83086
|
+
condition = _predicates__WEBPACK_IMPORTED_MODULE_8__["ModelPredicateCreator"].createForSingleField(getModelDefinition(modelConstructor), keyFields[0], identifierOrCriteria);
|
|
83078
83087
|
} else {
|
|
83079
83088
|
if (Object(_types__WEBPACK_IMPORTED_MODULE_11__["isIdentifierObject"])(identifierOrCriteria, modelDefinition)) {
|
|
83080
83089
|
condition = _predicates__WEBPACK_IMPORTED_MODULE_8__["ModelPredicateCreator"].createForPk(modelDefinition, identifierOrCriteria);
|
|
@@ -83101,7 +83110,7 @@ function () {
|
|
|
83101
83110
|
, this.storage["delete"](modelConstructor, condition)];
|
|
83102
83111
|
|
|
83103
83112
|
case 2:
|
|
83104
|
-
|
|
83113
|
+
_a = __read.apply(void 0, [_d.sent(), 1]), deleted = _a[0];
|
|
83105
83114
|
return [2
|
|
83106
83115
|
/*return*/
|
|
83107
83116
|
, deleted];
|
|
@@ -83140,7 +83149,7 @@ function () {
|
|
|
83140
83149
|
, this.storage["delete"](model, condition)];
|
|
83141
83150
|
|
|
83142
83151
|
case 4:
|
|
83143
|
-
|
|
83152
|
+
_b = __read.apply(void 0, [_d.sent(), 1]), _c = __read(_b[0], 1), deleted = _c[0];
|
|
83144
83153
|
return [2
|
|
83145
83154
|
/*return*/
|
|
83146
83155
|
, deleted];
|
|
@@ -83173,6 +83182,15 @@ function () {
|
|
|
83173
83182
|
});
|
|
83174
83183
|
throw new Error(msg);
|
|
83175
83184
|
}
|
|
83185
|
+
} // observe should not accept object literal syntax
|
|
83186
|
+
|
|
83187
|
+
|
|
83188
|
+
if (identifierOrCriteria && modelConstructor && Object(_types__WEBPACK_IMPORTED_MODULE_11__["isIdentifierObject"])(identifierOrCriteria, getModelDefinition(modelConstructor))) {
|
|
83189
|
+
var msg = _util__WEBPACK_IMPORTED_MODULE_12__["errorMessages"].observeWithObjectLiteral;
|
|
83190
|
+
logger.error(msg, {
|
|
83191
|
+
objectLiteral: identifierOrCriteria
|
|
83192
|
+
});
|
|
83193
|
+
throw new Error(msg);
|
|
83176
83194
|
}
|
|
83177
83195
|
|
|
83178
83196
|
if (identifierOrCriteria !== undefined && modelConstructor === undefined) {
|
|
@@ -89255,7 +89273,7 @@ function () {
|
|
|
89255
89273
|
var e_9, _a, e_10, _b, e_11, _c;
|
|
89256
89274
|
|
|
89257
89275
|
return __awaiter(this, void 0, void 0, function () {
|
|
89258
|
-
var rel, relationType,
|
|
89276
|
+
var rel, relationType, modelName, targetName, targetNames, associatedWith, storeName, _d, model, hasOneIndex, values, recordToDelete, index, values, value, recordToDelete, e_10_1, model, index, keyValues, childrenArray, e_11_1, e_9_1;
|
|
89259
89277
|
|
|
89260
89278
|
var _this = this;
|
|
89261
89279
|
|
|
@@ -89277,12 +89295,8 @@ function () {
|
|
|
89277
89295
|
/*break*/
|
|
89278
89296
|
, 37];
|
|
89279
89297
|
rel = relations_2_1.value;
|
|
89280
|
-
relationType = rel.relationType,
|
|
89298
|
+
relationType = rel.relationType, modelName = rel.modelName, targetName = rel.targetName, targetNames = rel.targetNames, associatedWith = rel.associatedWith;
|
|
89281
89299
|
storeName = this.getStorename(nameSpace, modelName);
|
|
89282
|
-
index = Object(_util__WEBPACK_IMPORTED_MODULE_4__["getIndex"])(this.schema.namespaces[nameSpace].relationships[modelName].relationTypes, srcModel) || // if we were unable to find an index via relationTypes
|
|
89283
|
-
// i.e. for keyName connections, attempt to find one by the
|
|
89284
|
-
// associatedWith property
|
|
89285
|
-
Object(_util__WEBPACK_IMPORTED_MODULE_4__["getIndexFromAssociation"])(this.schema.namespaces[nameSpace].relationships[modelName].indexes, rel.associatedWith);
|
|
89286
89300
|
_d = relationType;
|
|
89287
89301
|
|
|
89288
89302
|
switch (_d) {
|
|
@@ -89322,26 +89336,13 @@ function () {
|
|
|
89322
89336
|
/*break*/
|
|
89323
89337
|
, 12];
|
|
89324
89338
|
model = models_1_1.value;
|
|
89325
|
-
hasOneIndex =
|
|
89326
|
-
if (!(targetNames
|
|
89339
|
+
hasOneIndex = 'byPk';
|
|
89340
|
+
if (!(targetNames === null || targetNames === void 0 ? void 0 : targetNames.length)) return [3
|
|
89327
89341
|
/*break*/
|
|
89328
89342
|
, 8];
|
|
89329
|
-
|
|
89330
|
-
return model
|
|
89343
|
+
values = targetNames.map(function (targetName) {
|
|
89344
|
+
return model[targetName];
|
|
89331
89345
|
});
|
|
89332
|
-
keyValues = this.getIndexKeyValues(model);
|
|
89333
|
-
values = [];
|
|
89334
|
-
|
|
89335
|
-
if (hasConnectedModelFields) {
|
|
89336
|
-
// Values will be that of the child model
|
|
89337
|
-
values = targetNames.map(function (targetName) {
|
|
89338
|
-
return model[targetName];
|
|
89339
|
-
});
|
|
89340
|
-
} else {
|
|
89341
|
-
// values will be that of the parent model
|
|
89342
|
-
values = keyValues;
|
|
89343
|
-
}
|
|
89344
|
-
|
|
89345
89346
|
if (values.length === 0) return [3
|
|
89346
89347
|
/*break*/
|
|
89347
89348
|
, 12];
|
|
@@ -89363,16 +89364,28 @@ function () {
|
|
|
89363
89364
|
, 12];
|
|
89364
89365
|
|
|
89365
89366
|
case 8:
|
|
89366
|
-
|
|
89367
|
-
|
|
89368
|
-
|
|
89369
|
-
|
|
89370
|
-
|
|
89367
|
+
index = void 0;
|
|
89368
|
+
values = void 0;
|
|
89369
|
+
|
|
89370
|
+
if (targetName && targetName in model) {
|
|
89371
|
+
index = hasOneIndex;
|
|
89372
|
+
value = model[targetName];
|
|
89373
|
+
values = [value];
|
|
89374
|
+
} else {
|
|
89375
|
+
// backwards compatability for older versions of codegen that did not emit targetName for HAS_ONE relations
|
|
89376
|
+
// TODO: can we deprecate this? it's been ~2 years since codegen started including targetName for HAS_ONE
|
|
89377
|
+
// If we deprecate, we'll need to re-gen the MIPR in __tests__/schema.ts > newSchema
|
|
89378
|
+
// otherwise some unit tests will fail
|
|
89379
|
+
index = Object(_util__WEBPACK_IMPORTED_MODULE_4__["getIndex"])(this.schema.namespaces[nameSpace].relationships[modelName].relationTypes, srcModel);
|
|
89380
|
+
values = this.getIndexKeyValues(model);
|
|
89381
|
+
}
|
|
89382
|
+
|
|
89383
|
+
if (!values || !index) return [3
|
|
89371
89384
|
/*break*/
|
|
89372
89385
|
, 12];
|
|
89373
89386
|
return [4
|
|
89374
89387
|
/*yield*/
|
|
89375
|
-
, this.db.transaction(storeName, 'readwrite').objectStore(storeName).index(
|
|
89388
|
+
, this.db.transaction(storeName, 'readwrite').objectStore(storeName).index(index).get(values)];
|
|
89376
89389
|
|
|
89377
89390
|
case 9:
|
|
89378
89391
|
recordToDelete = _e.sent();
|
|
@@ -89456,6 +89469,9 @@ function () {
|
|
|
89456
89469
|
/*break*/
|
|
89457
89470
|
, 26];
|
|
89458
89471
|
model = models_2_1.value;
|
|
89472
|
+
index = // explicit bi-directional @hasMany and @manyToMany
|
|
89473
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_4__["getIndex"])(this.schema.namespaces[nameSpace].relationships[modelName].relationTypes, srcModel) || // uni and/or implicit @hasMany
|
|
89474
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_4__["getIndexFromAssociation"])(this.schema.namespaces[nameSpace].relationships[modelName].indexes, associatedWith);
|
|
89459
89475
|
keyValues = this.getIndexKeyValues(model);
|
|
89460
89476
|
return [4
|
|
89461
89477
|
/*yield*/
|
|
@@ -97503,7 +97519,9 @@ var __values = undefined && undefined.__values || function (o) {
|
|
|
97503
97519
|
var ID = 'id';
|
|
97504
97520
|
var errorMessages = {
|
|
97505
97521
|
idEmptyString: 'An index field cannot contain an empty string value',
|
|
97506
|
-
queryByPkWithCompositeKeyPresent: 'Models with composite primary keys cannot
|
|
97522
|
+
queryByPkWithCompositeKeyPresent: 'Models with composite primary keys cannot be queried by a single key value. Use object literal syntax for composite keys instead: https://docs.amplify.aws/lib/datastore/advanced-workflows/q/platform/js/#querying-records-with-custom-primary-keys',
|
|
97523
|
+
deleteByPkWithCompositeKeyPresent: 'Models with composite primary keys cannot be deleted by a single key value, unless using a predicate. Use object literal syntax for composite keys instead: https://docs.amplify.aws/lib/datastore/advanced-workflows/q/platform/js/#querying-records-with-custom-primary-keys',
|
|
97524
|
+
observeWithObjectLiteral: 'Object literal syntax cannot be used with observe. Use a predicate instead: https://docs.amplify.aws/lib/datastore/data-access/q/platform/js/#predicates'
|
|
97507
97525
|
};
|
|
97508
97526
|
function extractKeyIfExists(modelDefinition) {
|
|
97509
97527
|
var _c;
|