@aws-amplify/datastore 3.11.3 → 3.11.4-unstable.11

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.
@@ -52736,7 +52736,7 @@ function _wrapNativeSuper(Class) {
52736
52736
 
52737
52737
  function _construct(Parent, args, Class) {
52738
52738
  if (_isNativeReflectConstruct()) {
52739
- _construct = Reflect.construct;
52739
+ _construct = Reflect.construct.bind();
52740
52740
  } else {
52741
52741
  _construct = function _construct(Parent, args, Class) {
52742
52742
  var a = [null];
@@ -52769,16 +52769,15 @@ function _isNativeFunction(fn) {
52769
52769
  }
52770
52770
 
52771
52771
  function _setPrototypeOf(o, p) {
52772
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
52772
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
52773
52773
  o.__proto__ = p;
52774
52774
  return o;
52775
52775
  };
52776
-
52777
52776
  return _setPrototypeOf(o, p);
52778
52777
  }
52779
52778
 
52780
52779
  function _getPrototypeOf(o) {
52781
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
52780
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
52782
52781
  return o.__proto__ || Object.getPrototypeOf(o);
52783
52782
  };
52784
52783
  return _getPrototypeOf(o);
@@ -53046,11 +53045,10 @@ function _inheritsLoose(subClass, superClass) {
53046
53045
  }
53047
53046
 
53048
53047
  function _setPrototypeOf(o, p) {
53049
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
53048
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
53050
53049
  o.__proto__ = p;
53051
53050
  return o;
53052
53051
  };
53053
-
53054
53052
  return _setPrototypeOf(o, p);
53055
53053
  }
53056
53054
  /*!
@@ -53103,11 +53101,10 @@ function _inheritsLoose(subClass, superClass) {
53103
53101
  }
53104
53102
 
53105
53103
  function _setPrototypeOf(o, p) {
53106
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
53104
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
53107
53105
  o.__proto__ = p;
53108
53106
  return o;
53109
53107
  };
53110
-
53111
53108
  return _setPrototypeOf(o, p);
53112
53109
  }
53113
53110
  /*!
@@ -71163,7 +71160,7 @@ var getAmplifyUserAgent = function getAmplifyUserAgent() {
71163
71160
  __webpack_require__.r(__webpack_exports__);
71164
71161
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "version", function() { return version; });
71165
71162
  // generated by genversion
71166
- var version = '4.5.5';
71163
+ var version = '4.5.6';
71167
71164
 
71168
71165
  /***/ }),
71169
71166
 
@@ -83084,6 +83081,17 @@ function () {
83084
83081
  var itemsChanged = new Map();
83085
83082
  var deletedItemIds = [];
83086
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
+ */
83087
83095
 
83088
83096
  var generateAndEmitSnapshot = function generateAndEmitSnapshot() {
83089
83097
  var snapshot = generateSnapshot();
@@ -83101,6 +83109,24 @@ function () {
83101
83109
  var sortOptions = sort ? {
83102
83110
  sort: sort
83103
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;
83104
83130
 
83105
83131
  (function () {
83106
83132
  return __awaiter(_this, void 0, void 0, function () {
@@ -83121,16 +83147,31 @@ function () {
83121
83147
  // first, query and return any locally-available records
83122
83148
  _a.sent().forEach(function (item) {
83123
83149
  return items.set(item.id, item);
83124
- }); // observe the model and send a stream of updates (debounced)
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.
83125
83154
 
83126
83155
 
83127
- handle = this.observe(model, // @ts-ignore TODO: fix this TSlint error
83128
- criteria).subscribe(function (_a) {
83156
+ handle = this.observe(model).subscribe(function (_a) {
83129
83157
  var element = _a.element,
83130
83158
  model = _a.model,
83131
83159
  opType = _a.opType;
83132
83160
 
83133
- var _b, _c; // Flag items which have been recently deleted
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
83134
83175
  // NOTE: Merging of separate operations to the same model instance is handled upstream
83135
83176
  // in the `mergePage` method within src/sync/merger.ts. The final state of a model instance
83136
83177
  // depends on the LATEST record (for a given id).
@@ -83172,7 +83213,13 @@ function () {
83172
83213
  }
83173
83214
  });
83174
83215
  });
83175
- })(); // TODO: abstract this function into a util file to be able to write better unit tests
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
+ */
83176
83223
 
83177
83224
 
83178
83225
  var generateSnapshot = function generateSnapshot() {
@@ -83199,6 +83246,15 @@ function () {
83199
83246
  isSynced: isSynced
83200
83247
  };
83201
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
+
83202
83258
 
83203
83259
  var emitSnapshot = function emitSnapshot(snapshot) {
83204
83260
  // send the generated snapshot to the primary subscription
@@ -83207,6 +83263,13 @@ function () {
83207
83263
  itemsChanged.clear();
83208
83264
  deletedItemIds = [];
83209
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
+
83210
83273
 
83211
83274
  var sortItems = function sortItems(itemsToSort) {
83212
83275
  var modelDefinition = getModelDefinition(model);
@@ -83219,7 +83282,15 @@ function () {
83219
83282
  var compareFn = Object(_util__WEBPACK_IMPORTED_MODULE_9__["sortCompareFunction"])(sortPredicates);
83220
83283
  itemsToSort.sort(compareFn);
83221
83284
  }
83222
- }; // send one last snapshot when the model is fully synced
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
+ */
83223
83294
 
83224
83295
 
83225
83296
  var hubCallback = function hubCallback(_a) {
@@ -92384,57 +92455,85 @@ var __values = undefined && undefined.__values || function (o) {
92384
92455
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
92385
92456
  };
92386
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
+
92387
92466
  var mutationErrorMap = {
92467
+ BadModel: function BadModel() {
92468
+ return false;
92469
+ },
92388
92470
  BadRecord: function BadRecord(error) {
92389
- return /^Cannot return \w+ for [\w-_]+ type/.test(error.message);
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
92390
92473
  },
92391
92474
  ConfigError: function ConfigError() {
92392
92475
  return false;
92393
92476
  },
92394
- Transient: function Transient() {
92395
- return false;
92477
+ Transient: function Transient(error) {
92478
+ return connectionTimeout(error) || serverError(error);
92396
92479
  },
92397
- Unauthorized: function Unauthorized() {
92398
- return false;
92480
+ Unauthorized: function Unauthorized(error) {
92481
+ return /^Request failed with status code 401/.test(error.message);
92399
92482
  }
92400
92483
  };
92401
92484
  var subscriptionErrorMap = {
92485
+ BadModel: function BadModel() {
92486
+ return false;
92487
+ },
92402
92488
  BadRecord: function BadRecord() {
92403
92489
  return false;
92404
92490
  },
92405
92491
  ConfigError: function ConfigError() {
92406
92492
  return false;
92407
92493
  },
92408
- Transient: function Transient() {
92409
- return false;
92494
+ Transient: function Transient(observableError) {
92495
+ var error = unwrapObservableError(observableError);
92496
+ return connectionTimeout(error) || serverError(error);
92410
92497
  },
92411
- Unauthorized: function Unauthorized(givenError) {
92412
- var _a = givenError.error,
92413
- _b = __read((_a === void 0 ? {
92414
- errors: []
92415
- } : _a).errors, 1),
92416
- _c = _b[0],
92417
- _d = (_c === void 0 ? {} : _c).message,
92418
- message = _d === void 0 ? '' : _d;
92419
-
92420
- var regex = /Connection failed.+Unauthorized/;
92421
- return regex.test(message);
92498
+ Unauthorized: function Unauthorized(observableError) {
92499
+ var error = unwrapObservableError(observableError);
92500
+ return /Connection failed.+Unauthorized/.test(error.message);
92422
92501
  }
92423
92502
  };
92424
92503
  var syncErrorMap = {
92504
+ BadModel: function BadModel() {
92505
+ return false;
92506
+ },
92425
92507
  BadRecord: function BadRecord(error) {
92426
92508
  return /^Cannot return \w+ for [\w-_]+ type/.test(error.message);
92427
92509
  },
92428
92510
  ConfigError: function ConfigError() {
92429
92511
  return false;
92430
92512
  },
92431
- Transient: function Transient() {
92432
- return false;
92513
+ Transient: function Transient(error) {
92514
+ return connectionTimeout(error) || serverError(error);
92433
92515
  },
92434
92516
  Unauthorized: function Unauthorized() {
92435
92517
  return false;
92436
92518
  }
92437
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
+
92438
92537
  function getMutationErrorType(error) {
92439
92538
  return mapErrorToType(mutationErrorMap, error);
92440
92539
  }