@aws-amplify/datastore 3.11.4-unstable.2 → 3.11.4-unstable.9
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 +128 -26
- 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 +74 -6
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/sync/processors/errorMaps.js +38 -11
- package/lib/sync/processors/errorMaps.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/lib/types.js.map +1 -1
- package/lib-esm/datastore/datastore.js +75 -7
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.js +38 -11
- package/lib-esm/sync/processors/errorMaps.js.map +1 -1
- package/lib-esm/types.d.ts +1 -1
- package/lib-esm/types.js.map +1 -1
- package/package.json +8 -8
- package/src/datastore/datastore.ts +107 -27
- package/src/sync/processors/errorMaps.ts +43 -13
- package/src/types.ts +1 -0
|
@@ -83081,6 +83081,17 @@ function () {
|
|
|
83081
83081
|
var itemsChanged = new Map();
|
|
83082
83082
|
var deletedItemIds = [];
|
|
83083
83083
|
var handle;
|
|
83084
|
+
var predicate;
|
|
83085
|
+
/**
|
|
83086
|
+
* As the name suggests, this geneates a snapshot in the form of
|
|
83087
|
+
* `{items: T[], isSynced: boolean}`
|
|
83088
|
+
* and sends it to the observer.
|
|
83089
|
+
*
|
|
83090
|
+
* SIDE EFFECT: The underlying generation and emission methods may touch:
|
|
83091
|
+
* `items`, `itemsChanged`, and `deletedItemIds`.
|
|
83092
|
+
*
|
|
83093
|
+
* Refer to `generateSnapshot` and `emitSnapshot` for more details.
|
|
83094
|
+
*/
|
|
83084
83095
|
|
|
83085
83096
|
var generateAndEmitSnapshot = function generateAndEmitSnapshot() {
|
|
83086
83097
|
var snapshot = generateSnapshot();
|
|
@@ -83098,6 +83109,24 @@ function () {
|
|
|
83098
83109
|
var sortOptions = sort ? {
|
|
83099
83110
|
sort: sort
|
|
83100
83111
|
} : undefined;
|
|
83112
|
+
var modelDefinition = getModelDefinition(model);
|
|
83113
|
+
|
|
83114
|
+
if (isQueryOne(criteria)) {
|
|
83115
|
+
predicate = _predicates__WEBPACK_IMPORTED_MODULE_5__["ModelPredicateCreator"].createForId(modelDefinition, criteria);
|
|
83116
|
+
} else {
|
|
83117
|
+
if (Object(_predicates__WEBPACK_IMPORTED_MODULE_5__["isPredicatesAll"])(criteria)) {
|
|
83118
|
+
// Predicates.ALL means "all records", so no predicate (undefined)
|
|
83119
|
+
predicate = undefined;
|
|
83120
|
+
} else {
|
|
83121
|
+
predicate = _predicates__WEBPACK_IMPORTED_MODULE_5__["ModelPredicateCreator"].createFromExisting(modelDefinition, criteria);
|
|
83122
|
+
}
|
|
83123
|
+
}
|
|
83124
|
+
|
|
83125
|
+
var _a = _predicates__WEBPACK_IMPORTED_MODULE_5__["ModelPredicateCreator"].getPredicates(predicate, false) || {},
|
|
83126
|
+
predicates = _a.predicates,
|
|
83127
|
+
predicateGroupType = _a.type;
|
|
83128
|
+
|
|
83129
|
+
var hasPredicate = !!predicates;
|
|
83101
83130
|
|
|
83102
83131
|
(function () {
|
|
83103
83132
|
return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -83118,16 +83147,31 @@ function () {
|
|
|
83118
83147
|
// first, query and return any locally-available records
|
|
83119
83148
|
_a.sent().forEach(function (item) {
|
|
83120
83149
|
return items.set(item.id, item);
|
|
83121
|
-
}); //
|
|
83150
|
+
}); // Observe the model and send a stream of updates (debounced).
|
|
83151
|
+
// We need to post-filter results instead of passing criteria through
|
|
83152
|
+
// to have visibility into items that move from in-set to out-of-set.
|
|
83153
|
+
// We need to explicitly remove those items from the existing snapshot.
|
|
83122
83154
|
|
|
83123
83155
|
|
|
83124
|
-
handle = this.observe(model
|
|
83125
|
-
criteria).subscribe(function (_a) {
|
|
83156
|
+
handle = this.observe(model).subscribe(function (_a) {
|
|
83126
83157
|
var element = _a.element,
|
|
83127
83158
|
model = _a.model,
|
|
83128
83159
|
opType = _a.opType;
|
|
83129
83160
|
|
|
83130
|
-
var _b, _c;
|
|
83161
|
+
var _b, _c;
|
|
83162
|
+
|
|
83163
|
+
if (hasPredicate && !Object(_util__WEBPACK_IMPORTED_MODULE_9__["validatePredicate"])(element, predicateGroupType, predicates)) {
|
|
83164
|
+
if (opType === 'UPDATE' && (items.has(element.id) || itemsChanged.has(element.id))) {
|
|
83165
|
+
// tracking as a "deleted item" will include the item in
|
|
83166
|
+
// page limit calculations and ensure it is removed from the
|
|
83167
|
+
// final items collection, regardless of which collection(s)
|
|
83168
|
+
// it is currently in. (I mean, it could be in both, right!?)
|
|
83169
|
+
deletedItemIds.push(element.id);
|
|
83170
|
+
} else {
|
|
83171
|
+
// ignore updates for irrelevant/filtered items.
|
|
83172
|
+
return;
|
|
83173
|
+
}
|
|
83174
|
+
} // Flag items which have been recently deleted
|
|
83131
83175
|
// NOTE: Merging of separate operations to the same model instance is handled upstream
|
|
83132
83176
|
// in the `mergePage` method within src/sync/merger.ts. The final state of a model instance
|
|
83133
83177
|
// depends on the LATEST record (for a given id).
|
|
@@ -83169,7 +83213,13 @@ function () {
|
|
|
83169
83213
|
}
|
|
83170
83214
|
});
|
|
83171
83215
|
});
|
|
83172
|
-
})();
|
|
83216
|
+
})();
|
|
83217
|
+
/**
|
|
83218
|
+
* Combines the `items`, `itemsChanged`, and `deletedItemIds` collections into
|
|
83219
|
+
* a snapshot in the form of `{ items: T[], isSynced: boolean}`.
|
|
83220
|
+
*
|
|
83221
|
+
* SIDE EFFECT: The shared `items` collection is recreated.
|
|
83222
|
+
*/
|
|
83173
83223
|
|
|
83174
83224
|
|
|
83175
83225
|
var generateSnapshot = function generateSnapshot() {
|
|
@@ -83196,6 +83246,15 @@ function () {
|
|
|
83196
83246
|
isSynced: isSynced
|
|
83197
83247
|
};
|
|
83198
83248
|
};
|
|
83249
|
+
/**
|
|
83250
|
+
* Emits the list of items to the observer.
|
|
83251
|
+
*
|
|
83252
|
+
* SIDE EFFECT: `itemsChanged` and `deletedItemIds` are cleared to prepare
|
|
83253
|
+
* for the next snapshot.
|
|
83254
|
+
*
|
|
83255
|
+
* @param snapshot The generated items data to emit.
|
|
83256
|
+
*/
|
|
83257
|
+
|
|
83199
83258
|
|
|
83200
83259
|
var emitSnapshot = function emitSnapshot(snapshot) {
|
|
83201
83260
|
// send the generated snapshot to the primary subscription
|
|
@@ -83204,6 +83263,13 @@ function () {
|
|
|
83204
83263
|
itemsChanged.clear();
|
|
83205
83264
|
deletedItemIds = [];
|
|
83206
83265
|
};
|
|
83266
|
+
/**
|
|
83267
|
+
* Sorts an `Array` of `T` according to the sort instructions given in the
|
|
83268
|
+
* original `observeQuery()` call.
|
|
83269
|
+
*
|
|
83270
|
+
* @param itemsToSort A array of model type.
|
|
83271
|
+
*/
|
|
83272
|
+
|
|
83207
83273
|
|
|
83208
83274
|
var sortItems = function sortItems(itemsToSort) {
|
|
83209
83275
|
var modelDefinition = getModelDefinition(model);
|
|
@@ -83216,7 +83282,15 @@ function () {
|
|
|
83216
83282
|
var compareFn = Object(_util__WEBPACK_IMPORTED_MODULE_9__["sortCompareFunction"])(sortPredicates);
|
|
83217
83283
|
itemsToSort.sort(compareFn);
|
|
83218
83284
|
}
|
|
83219
|
-
};
|
|
83285
|
+
};
|
|
83286
|
+
/**
|
|
83287
|
+
* Force one last snapshot when the model is fully synced.
|
|
83288
|
+
*
|
|
83289
|
+
* This reduces latency for that last snapshot, which will otherwise
|
|
83290
|
+
* wait for the configured timeout.
|
|
83291
|
+
*
|
|
83292
|
+
* @param payload The payload from the Hub event.
|
|
83293
|
+
*/
|
|
83220
83294
|
|
|
83221
83295
|
|
|
83222
83296
|
var hubCallback = function hubCallback(_a) {
|
|
@@ -92381,57 +92455,85 @@ var __values = undefined && undefined.__values || function (o) {
|
|
|
92381
92455
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
92382
92456
|
};
|
|
92383
92457
|
|
|
92458
|
+
var connectionTimeout = function connectionTimeout(error) {
|
|
92459
|
+
return /^Connection failed: Connection Timeout/.test(error.message);
|
|
92460
|
+
};
|
|
92461
|
+
|
|
92462
|
+
var serverError = function serverError(error) {
|
|
92463
|
+
return /^Error: Request failed with status code 5\d\d/.test(error.message);
|
|
92464
|
+
};
|
|
92465
|
+
|
|
92384
92466
|
var mutationErrorMap = {
|
|
92467
|
+
BadModel: function BadModel() {
|
|
92468
|
+
return false;
|
|
92469
|
+
},
|
|
92385
92470
|
BadRecord: function BadRecord(error) {
|
|
92386
|
-
|
|
92471
|
+
var message = error.message;
|
|
92472
|
+
return /^Cannot return \w+ for [\w-_]+ type/.test(message) || /^Variable '.+' has coerced Null value for NonNull type/.test(message); // newly required field, out of date client
|
|
92387
92473
|
},
|
|
92388
92474
|
ConfigError: function ConfigError() {
|
|
92389
92475
|
return false;
|
|
92390
92476
|
},
|
|
92391
|
-
Transient: function Transient() {
|
|
92392
|
-
return
|
|
92477
|
+
Transient: function Transient(error) {
|
|
92478
|
+
return connectionTimeout(error) || serverError(error);
|
|
92393
92479
|
},
|
|
92394
|
-
Unauthorized: function Unauthorized() {
|
|
92395
|
-
return
|
|
92480
|
+
Unauthorized: function Unauthorized(error) {
|
|
92481
|
+
return /^Request failed with status code 401/.test(error.message);
|
|
92396
92482
|
}
|
|
92397
92483
|
};
|
|
92398
92484
|
var subscriptionErrorMap = {
|
|
92485
|
+
BadModel: function BadModel() {
|
|
92486
|
+
return false;
|
|
92487
|
+
},
|
|
92399
92488
|
BadRecord: function BadRecord() {
|
|
92400
92489
|
return false;
|
|
92401
92490
|
},
|
|
92402
92491
|
ConfigError: function ConfigError() {
|
|
92403
92492
|
return false;
|
|
92404
92493
|
},
|
|
92405
|
-
Transient: function Transient() {
|
|
92406
|
-
|
|
92494
|
+
Transient: function Transient(observableError) {
|
|
92495
|
+
var error = unwrapObservableError(observableError);
|
|
92496
|
+
return connectionTimeout(error) || serverError(error);
|
|
92407
92497
|
},
|
|
92408
|
-
Unauthorized: function Unauthorized(
|
|
92409
|
-
var
|
|
92410
|
-
|
|
92411
|
-
errors: []
|
|
92412
|
-
} : _a).errors, 1),
|
|
92413
|
-
_c = _b[0],
|
|
92414
|
-
_d = (_c === void 0 ? {} : _c).message,
|
|
92415
|
-
message = _d === void 0 ? '' : _d;
|
|
92416
|
-
|
|
92417
|
-
var regex = /Connection failed.+Unauthorized/;
|
|
92418
|
-
return regex.test(message);
|
|
92498
|
+
Unauthorized: function Unauthorized(observableError) {
|
|
92499
|
+
var error = unwrapObservableError(observableError);
|
|
92500
|
+
return /Connection failed.+Unauthorized/.test(error.message);
|
|
92419
92501
|
}
|
|
92420
92502
|
};
|
|
92421
92503
|
var syncErrorMap = {
|
|
92504
|
+
BadModel: function BadModel() {
|
|
92505
|
+
return false;
|
|
92506
|
+
},
|
|
92422
92507
|
BadRecord: function BadRecord(error) {
|
|
92423
92508
|
return /^Cannot return \w+ for [\w-_]+ type/.test(error.message);
|
|
92424
92509
|
},
|
|
92425
92510
|
ConfigError: function ConfigError() {
|
|
92426
92511
|
return false;
|
|
92427
92512
|
},
|
|
92428
|
-
Transient: function Transient() {
|
|
92429
|
-
return
|
|
92513
|
+
Transient: function Transient(error) {
|
|
92514
|
+
return connectionTimeout(error) || serverError(error);
|
|
92430
92515
|
},
|
|
92431
92516
|
Unauthorized: function Unauthorized() {
|
|
92432
92517
|
return false;
|
|
92433
92518
|
}
|
|
92434
92519
|
};
|
|
92520
|
+
/**
|
|
92521
|
+
* Get the first error reason of an observable.
|
|
92522
|
+
* Allows for error maps to be easily applied to observable errors
|
|
92523
|
+
*
|
|
92524
|
+
* @param observableError an error from ZenObservable subscribe error callback
|
|
92525
|
+
*/
|
|
92526
|
+
|
|
92527
|
+
function unwrapObservableError(observableError) {
|
|
92528
|
+
var _a = observableError.error,
|
|
92529
|
+
_b = __read((_a === void 0 ? {
|
|
92530
|
+
errors: []
|
|
92531
|
+
} : _a).errors, 1),
|
|
92532
|
+
error = _b[0];
|
|
92533
|
+
|
|
92534
|
+
return error;
|
|
92535
|
+
}
|
|
92536
|
+
|
|
92435
92537
|
function getMutationErrorType(error) {
|
|
92436
92538
|
return mapErrorToType(mutationErrorMap, error);
|
|
92437
92539
|
}
|