@aws-amplify/datastore 4.0.12 → 4.0.13-push-notification-dryrun.43

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.
Files changed (111) hide show
  1. package/lib/datastore/datastore.d.ts +29 -3
  2. package/lib/datastore/datastore.js +308 -147
  3. package/lib/datastore/datastore.js.map +1 -1
  4. package/lib/predicates/index.d.ts +77 -7
  5. package/lib/predicates/index.js +142 -122
  6. package/lib/predicates/index.js.map +1 -1
  7. package/lib/predicates/next.d.ts +51 -10
  8. package/lib/predicates/next.js +111 -91
  9. package/lib/predicates/next.js.map +1 -1
  10. package/lib/storage/adapter/AsyncStorageAdapter.d.ts +28 -30
  11. package/lib/storage/adapter/AsyncStorageAdapter.js +135 -532
  12. package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
  13. package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
  14. package/lib/storage/adapter/IndexedDBAdapter.d.ts +28 -29
  15. package/lib/storage/adapter/IndexedDBAdapter.js +490 -885
  16. package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
  17. package/lib/storage/adapter/StorageAdapterBase.d.ts +134 -0
  18. package/lib/storage/adapter/StorageAdapterBase.js +439 -0
  19. package/lib/storage/adapter/StorageAdapterBase.js.map +1 -0
  20. package/lib/storage/relationship.d.ts +9 -0
  21. package/lib/storage/relationship.js +9 -0
  22. package/lib/storage/relationship.js.map +1 -1
  23. package/lib/storage/storage.d.ts +1 -1
  24. package/lib/storage/storage.js +4 -3
  25. package/lib/storage/storage.js.map +1 -1
  26. package/lib/sync/index.d.ts +15 -1
  27. package/lib/sync/index.js +80 -13
  28. package/lib/sync/index.js.map +1 -1
  29. package/lib/sync/outbox.js +14 -7
  30. package/lib/sync/outbox.js.map +1 -1
  31. package/lib/sync/processors/mutation.d.ts +10 -1
  32. package/lib/sync/processors/mutation.js +33 -12
  33. package/lib/sync/processors/mutation.js.map +1 -1
  34. package/lib/sync/processors/subscription.d.ts +7 -1
  35. package/lib/sync/processors/subscription.js +196 -135
  36. package/lib/sync/processors/subscription.js.map +1 -1
  37. package/lib/sync/processors/sync.d.ts +1 -1
  38. package/lib/sync/processors/sync.js.map +1 -1
  39. package/lib/sync/utils.d.ts +66 -2
  40. package/lib/sync/utils.js +264 -16
  41. package/lib/sync/utils.js.map +1 -1
  42. package/lib/types.d.ts +9 -1
  43. package/lib/types.js.map +1 -1
  44. package/lib/util.d.ts +16 -0
  45. package/lib/util.js +31 -2
  46. package/lib/util.js.map +1 -1
  47. package/lib-esm/datastore/datastore.d.ts +29 -3
  48. package/lib-esm/datastore/datastore.js +310 -149
  49. package/lib-esm/datastore/datastore.js.map +1 -1
  50. package/lib-esm/predicates/index.d.ts +77 -7
  51. package/lib-esm/predicates/index.js +143 -123
  52. package/lib-esm/predicates/index.js.map +1 -1
  53. package/lib-esm/predicates/next.d.ts +51 -10
  54. package/lib-esm/predicates/next.js +111 -91
  55. package/lib-esm/predicates/next.js.map +1 -1
  56. package/lib-esm/storage/adapter/AsyncStorageAdapter.d.ts +28 -30
  57. package/lib-esm/storage/adapter/AsyncStorageAdapter.js +138 -535
  58. package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
  59. package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
  60. package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +28 -29
  61. package/lib-esm/storage/adapter/IndexedDBAdapter.js +489 -884
  62. package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
  63. package/lib-esm/storage/adapter/StorageAdapterBase.d.ts +134 -0
  64. package/lib-esm/storage/adapter/StorageAdapterBase.js +437 -0
  65. package/lib-esm/storage/adapter/StorageAdapterBase.js.map +1 -0
  66. package/lib-esm/storage/relationship.d.ts +9 -0
  67. package/lib-esm/storage/relationship.js +9 -0
  68. package/lib-esm/storage/relationship.js.map +1 -1
  69. package/lib-esm/storage/storage.d.ts +1 -1
  70. package/lib-esm/storage/storage.js +4 -3
  71. package/lib-esm/storage/storage.js.map +1 -1
  72. package/lib-esm/sync/index.d.ts +15 -1
  73. package/lib-esm/sync/index.js +82 -15
  74. package/lib-esm/sync/index.js.map +1 -1
  75. package/lib-esm/sync/outbox.js +14 -7
  76. package/lib-esm/sync/outbox.js.map +1 -1
  77. package/lib-esm/sync/processors/mutation.d.ts +10 -1
  78. package/lib-esm/sync/processors/mutation.js +33 -12
  79. package/lib-esm/sync/processors/mutation.js.map +1 -1
  80. package/lib-esm/sync/processors/subscription.d.ts +7 -1
  81. package/lib-esm/sync/processors/subscription.js +197 -136
  82. package/lib-esm/sync/processors/subscription.js.map +1 -1
  83. package/lib-esm/sync/processors/sync.d.ts +1 -1
  84. package/lib-esm/sync/processors/sync.js.map +1 -1
  85. package/lib-esm/sync/utils.d.ts +66 -2
  86. package/lib-esm/sync/utils.js +261 -18
  87. package/lib-esm/sync/utils.js.map +1 -1
  88. package/lib-esm/types.d.ts +9 -1
  89. package/lib-esm/types.js.map +1 -1
  90. package/lib-esm/util.d.ts +16 -0
  91. package/lib-esm/util.js +32 -3
  92. package/lib-esm/util.js.map +1 -1
  93. package/package.json +12 -11
  94. package/src/datastore/datastore.ts +288 -159
  95. package/src/predicates/index.ts +145 -175
  96. package/src/predicates/next.ts +114 -81
  97. package/src/storage/adapter/AsyncStorageAdapter.ts +97 -563
  98. package/src/storage/adapter/AsyncStorageDatabase.ts +2 -2
  99. package/src/storage/adapter/IndexedDBAdapter.ts +318 -770
  100. package/src/storage/adapter/StorageAdapterBase.ts +545 -0
  101. package/src/storage/relationship.ts +9 -0
  102. package/src/storage/storage.ts +12 -9
  103. package/src/sync/index.ts +108 -20
  104. package/src/sync/outbox.ts +17 -11
  105. package/src/sync/processors/mutation.ts +35 -4
  106. package/src/sync/processors/subscription.ts +124 -10
  107. package/src/sync/processors/sync.ts +4 -1
  108. package/src/sync/utils.ts +285 -15
  109. package/src/types.ts +15 -2
  110. package/src/util.ts +40 -1
  111. package/CHANGELOG.md +0 -904
@@ -25,70 +25,28 @@ var isNode = core_1.browserOrNode().isNode;
25
25
  var SETTING_SCHEMA_VERSION = 'schemaVersion';
26
26
  var schema;
27
27
  var modelNamespaceMap = new WeakMap();
28
- // stores data for crafting the correct update mutation input for a model
29
- // Patch[] - array of changed fields and metadata
30
- // PersistentModel - the source model, used for diffing object-type fields
28
+ /**
29
+ * Stores data for crafting the correct update mutation input for a model.
30
+ *
31
+ * - `Patch[]` - array of changed fields and metadata.
32
+ * - `PersistentModel` - the source model, used for diffing object-type fields.
33
+ */
31
34
  var modelPatchesMap = new WeakMap();
32
35
  var getModelDefinition = function (modelConstructor) {
33
- var e_1, _a, e_2, _b;
34
36
  var namespace = modelNamespaceMap.get(modelConstructor);
35
37
  var definition = namespace
36
38
  ? schema.namespaces[namespace].models[modelConstructor.name]
37
39
  : undefined;
38
- // compatibility with legacy/pre-PK codegen for lazy loading to inject
39
- // index fields into the model definition.
40
- if (definition) {
41
- var indexes = schema.namespaces[namespace].relationships[modelConstructor.name]
42
- .indexes;
43
- var indexFields = new Set();
44
- try {
45
- for (var indexes_1 = tslib_1.__values(indexes), indexes_1_1 = indexes_1.next(); !indexes_1_1.done; indexes_1_1 = indexes_1.next()) {
46
- var index = indexes_1_1.value;
47
- try {
48
- for (var _c = (e_2 = void 0, tslib_1.__values(index[1])), _d = _c.next(); !_d.done; _d = _c.next()) {
49
- var indexField = _d.value;
50
- indexFields.add(indexField);
51
- }
52
- }
53
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
54
- finally {
55
- try {
56
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
57
- }
58
- finally { if (e_2) throw e_2.error; }
59
- }
60
- }
61
- }
62
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
63
- finally {
64
- try {
65
- if (indexes_1_1 && !indexes_1_1.done && (_a = indexes_1.return)) _a.call(indexes_1);
66
- }
67
- finally { if (e_1) throw e_1.error; }
68
- }
69
- definition.fields = tslib_1.__assign(tslib_1.__assign({}, Object.fromEntries(tslib_1.__spread(indexFields.values()).map(function (name) { return [
70
- name,
71
- {
72
- name: name,
73
- type: 'ID',
74
- isArray: false,
75
- },
76
- ]; }, []))), definition.fields);
77
- }
78
40
  return definition;
79
41
  };
80
- var getModelPKFieldName = function (modelConstructor) {
81
- var _a, _b, _c;
82
- var namespace = modelNamespaceMap.get(modelConstructor);
83
- return ((namespace && ((_c = (_b = (_a = schema.namespaces) === null || _a === void 0 ? void 0 : _a[namespace]) === null || _b === void 0 ? void 0 : _b.keys) === null || _c === void 0 ? void 0 : _c[modelConstructor.name].primaryKey)) || ['id']);
84
- };
42
+ /**
43
+ * Determines whether the given object is a Model Constructor that DataStore can
44
+ * safely use to construct objects and discover related metadata.
45
+ *
46
+ * @param obj The object to test.
47
+ */
85
48
  var isValidModelConstructor = function (obj) {
86
- if (util_1.isModelConstructor(obj) && modelNamespaceMap.has(obj)) {
87
- return true;
88
- }
89
- else {
90
- return false;
91
- }
49
+ return util_1.isModelConstructor(obj) && modelNamespaceMap.has(obj);
92
50
  };
93
51
  var namespaceResolver = function (modelConstructor) {
94
52
  var resolver = modelNamespaceMap.get(modelConstructor);
@@ -97,13 +55,32 @@ var namespaceResolver = function (modelConstructor) {
97
55
  }
98
56
  return resolver;
99
57
  };
58
+ /**
59
+ * Creates a predicate without any conditions that can be passed to customer
60
+ * code to have conditions added to it.
61
+ *
62
+ * For example, in this query:
63
+ *
64
+ * ```ts
65
+ * await DataStore.query(
66
+ * Model,
67
+ * item => item.field.eq('value')
68
+ * );
69
+ * ```
70
+ *
71
+ * `buildSeedPredicate(Model)` is used to create `item`, which is passed to the
72
+ * predicate function, which in turn uses that "seed" predicate (`item`) to build
73
+ * a predicate tree.
74
+ *
75
+ * @param modelConstructor The model the predicate will query.
76
+ */
100
77
  var buildSeedPredicate = function (modelConstructor) {
101
78
  if (!modelConstructor)
102
79
  throw new Error('Missing modelConstructor');
103
80
  var modelSchema = getModelDefinition(modelConstructor);
104
81
  if (!modelSchema)
105
82
  throw new Error('Missing modelSchema');
106
- var pks = getModelPKFieldName(modelConstructor);
83
+ var pks = util_1.extractPrimaryKeyFieldNames(modelSchema);
107
84
  if (!pks)
108
85
  throw new Error('Could not determine PK');
109
86
  return next_1.recursivePredicateFor({
@@ -209,12 +186,13 @@ var initSchema = function (userSchema) {
209
186
  codegenVersion: userSchema.codegenVersion,
210
187
  };
211
188
  Object.keys(schema.namespaces).forEach(function (namespace) {
212
- var e_3, _a;
189
+ var e_1, _a;
213
190
  var _b = tslib_1.__read(util_1.establishRelationAndKeys(schema.namespaces[namespace]), 2), relations = _b[0], keys = _b[1];
214
191
  schema.namespaces[namespace].relationships = relations;
215
192
  schema.namespaces[namespace].keys = keys;
216
193
  var modelAssociations = new Map();
217
194
  Object.values(schema.namespaces[namespace].models).forEach(function (model) {
195
+ var e_2, _a, e_3, _b;
218
196
  var connectedModels = [];
219
197
  Object.values(model.fields)
220
198
  .filter(function (field) {
@@ -226,20 +204,64 @@ var initSchema = function (userSchema) {
226
204
  return connectedModels.push(field.type.model);
227
205
  });
228
206
  modelAssociations.set(model.name, connectedModels);
207
+ // Precompute model info (such as pk fields) so that downstream schema consumers
208
+ // (such as predicate builders) don't have to reach back into "DataStore" space
209
+ // to go looking for it.
229
210
  Object.values(model.fields).forEach(function (field) {
230
- if (typeof field.type === 'object' &&
231
- !Object.getOwnPropertyDescriptor(field.type, 'modelConstructor')) {
211
+ var relatedModel = userClasses[field.type.model];
212
+ if (util_1.isModelConstructor(relatedModel)) {
232
213
  Object.defineProperty(field.type, 'modelConstructor', {
233
214
  get: function () {
215
+ var relatedModelDefinition = getModelDefinition(relatedModel);
216
+ if (!relatedModelDefinition)
217
+ throw new Error("Could not find model definition for " + relatedModel.name);
234
218
  return {
235
- builder: userClasses[field.type.model],
236
- schema: schema.namespaces[namespace].models[field.type.model],
237
- pkField: getModelPKFieldName(userClasses[field.type.model]),
219
+ builder: relatedModel,
220
+ schema: relatedModelDefinition,
221
+ pkField: util_1.extractPrimaryKeyFieldNames(relatedModelDefinition),
238
222
  };
239
223
  },
240
224
  });
241
225
  }
242
226
  });
227
+ // compatibility with legacy/pre-PK codegen for lazy loading to inject
228
+ // index fields into the model definition.
229
+ // definition.cloudFields = { ...definition.fields };
230
+ var indexes = schema.namespaces[namespace].relationships[model.name].indexes;
231
+ var indexFields = new Set();
232
+ try {
233
+ for (var indexes_1 = tslib_1.__values(indexes), indexes_1_1 = indexes_1.next(); !indexes_1_1.done; indexes_1_1 = indexes_1.next()) {
234
+ var index = indexes_1_1.value;
235
+ try {
236
+ for (var _c = (e_3 = void 0, tslib_1.__values(index[1])), _d = _c.next(); !_d.done; _d = _c.next()) {
237
+ var indexField = _d.value;
238
+ indexFields.add(indexField);
239
+ }
240
+ }
241
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
242
+ finally {
243
+ try {
244
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
245
+ }
246
+ finally { if (e_3) throw e_3.error; }
247
+ }
248
+ }
249
+ }
250
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
251
+ finally {
252
+ try {
253
+ if (indexes_1_1 && !indexes_1_1.done && (_a = indexes_1.return)) _a.call(indexes_1);
254
+ }
255
+ finally { if (e_2) throw e_2.error; }
256
+ }
257
+ model.allFields = tslib_1.__assign(tslib_1.__assign({}, Object.fromEntries(tslib_1.__spread(indexFields.values()).map(function (name) { return [
258
+ name,
259
+ {
260
+ name: name,
261
+ type: 'ID',
262
+ isArray: false,
263
+ },
264
+ ]; }))), model.fields);
243
265
  });
244
266
  var result = new Map();
245
267
  var count = 1000;
@@ -252,7 +274,7 @@ var initSchema = function (userSchema) {
252
274
  throw new Error('Models are not topologically sortable. Please verify your schema.');
253
275
  }
254
276
  try {
255
- for (var _c = (e_3 = void 0, tslib_1.__values(Array.from(modelAssociations.keys()))), _d = _c.next(); !_d.done; _d = _c.next()) {
277
+ for (var _c = (e_1 = void 0, tslib_1.__values(Array.from(modelAssociations.keys()))), _d = _c.next(); !_d.done; _d = _c.next()) {
256
278
  var modelName = _d.value;
257
279
  var parents = modelAssociations.get(modelName);
258
280
  if (parents === null || parents === void 0 ? void 0 : parents.every(function (x) { return result.has(x); })) {
@@ -260,12 +282,12 @@ var initSchema = function (userSchema) {
260
282
  }
261
283
  }
262
284
  }
263
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
285
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
264
286
  finally {
265
287
  try {
266
288
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
267
289
  }
268
- finally { if (e_3) throw e_3.error; }
290
+ finally { if (e_1) throw e_1.error; }
269
291
  }
270
292
  Array.from(result.keys()).forEach(function (x) { return modelAssociations.delete(x); });
271
293
  }
@@ -309,7 +331,6 @@ var checkSchemaInitialized = function () {
309
331
  * @param codegenVersion schema codegenVersion
310
332
  */
311
333
  var checkSchemaCodegenVersion = function (codegenVersion) {
312
- // TODO: set to correct version when released in codegen
313
334
  var majorVersion = 3;
314
335
  var minorVersion = 2;
315
336
  var isValid = false;
@@ -357,7 +378,12 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
357
378
  var fieldDefinition = modelDefinition.fields[k];
358
379
  if (fieldDefinition !== undefined) {
359
380
  var type_1 = fieldDefinition.type, isRequired_1 = fieldDefinition.isRequired, isArrayNullable = fieldDefinition.isArrayNullable, name_1 = fieldDefinition.name, isArray = fieldDefinition.isArray;
381
+ var timestamps = types_1.isSchemaModelWithAttributes(modelDefinition)
382
+ ? util_1.getTimestampFields(modelDefinition)
383
+ : {};
384
+ var isTimestampField = !!timestamps[name_1];
360
385
  if (((!isArray && isRequired_1) || (isArray && !isArrayNullable)) &&
386
+ !isTimestampField &&
361
387
  (v === null || v === undefined)) {
362
388
  throw new Error("Field " + name_1 + " is required");
363
389
  }
@@ -491,6 +517,20 @@ var castInstanceType = function (modelDefinition, k, v) {
491
517
  }
492
518
  return v;
493
519
  };
520
+ /**
521
+ * Records the patches (as if against an empty object) used to initialize
522
+ * an instance of a Model. This can be used for determining which fields to
523
+ * send to the cloud durnig a CREATE mutation.
524
+ */
525
+ var initPatches = new WeakMap();
526
+ /**
527
+ * Attempts to apply type-aware, casted field values from a given `init`
528
+ * object to the given `draft`.
529
+ *
530
+ * @param init The initialization object to extract field values from.
531
+ * @param modelDefinition The definition describing the target object shape.
532
+ * @param draft The draft to apply field values to.
533
+ */
494
534
  var initializeInstance = function (init, modelDefinition, draft) {
495
535
  var modelValidator = validateModelFields(modelDefinition);
496
536
  Object.entries(init).forEach(function (_a) {
@@ -500,10 +540,51 @@ var initializeInstance = function (init, modelDefinition, draft) {
500
540
  draft[k] = parsedValue;
501
541
  });
502
542
  };
543
+ /**
544
+ * Updates a draft to standardize its customer-defined fields so that they are
545
+ * consistent with the data as it would look after having been synchronized from
546
+ * Cloud storage.
547
+ *
548
+ * The exceptions to this are:
549
+ *
550
+ * 1. Non-schema/Internal [sync] metadata fields.
551
+ * 2. Cloud-managed fields, which are `null` until set by cloud storage.
552
+ *
553
+ * This function should be expanded if/when deviations between canonical Cloud
554
+ * storage data and locally managed data are found. For now, the known areas
555
+ * that require normalization are:
556
+ *
557
+ * 1. Ensuring all non-metadata fields are *defined*. (I.e., turn `undefined` -> `null`.)
558
+ *
559
+ * @param modelDefinition Definition for the draft. Used to discover all fields.
560
+ * @param draft The instance draft to apply normalizations to.
561
+ */
562
+ var normalize = function (modelDefinition, draft) {
563
+ var e_4, _a;
564
+ try {
565
+ for (var _b = tslib_1.__values(Object.keys(modelDefinition.fields)), _c = _b.next(); !_c.done; _c = _b.next()) {
566
+ var k = _c.value;
567
+ if (draft[k] === undefined)
568
+ draft[k] = null;
569
+ }
570
+ }
571
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
572
+ finally {
573
+ try {
574
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
575
+ }
576
+ finally { if (e_4) throw e_4.error; }
577
+ }
578
+ };
503
579
  var createModelClass = function (modelDefinition) {
580
+ var e_5, _a;
504
581
  var clazz = /** @class */ (function () {
505
582
  function Model(init) {
506
- var instance = immer_1.produce(this, function (draft) {
583
+ // we create a base instance first so we can distinguish which fields were explicitly
584
+ // set by customer code versus those set by normalization. only those fields
585
+ // which are explicitly set by customers should be part of create mutations.
586
+ var patches = [];
587
+ var baseInstance = immer_1.produce(this, function (draft) {
507
588
  initializeInstance(init, modelDefinition, draft);
508
589
  // model is initialized inside a DataStore component (e.g. by Sync Engine, Storage Engine, etc.)
509
590
  var isInternallyInitialized = instancesMetadata.has(init);
@@ -533,8 +614,17 @@ var createModelClass = function (modelDefinition) {
533
614
  draft._lastChangedAt = _lastChangedAt;
534
615
  draft._deleted = _deleted;
535
616
  }
617
+ }, function (p) { return (patches = p); });
618
+ // now that we have a list of patches that encapsulate the explicit, customer-provided
619
+ // fields, we can normalize. patches from normalization are ignored, because the changes
620
+ // are only create to provide a consistent view of the data for fields pre/post sync
621
+ // where possible. (not all fields can be normalized pre-sync, because they're generally
622
+ // "cloud managed" fields, like createdAt and updatedAt.)
623
+ var normalized = immer_1.produce(baseInstance, function (draft) {
624
+ return normalize(modelDefinition, draft);
536
625
  });
537
- return instance;
626
+ initPatches.set(normalized, patches);
627
+ return normalized;
538
628
  }
539
629
  Model.copyOf = function (source, fn) {
540
630
  var modelConstructor = Object.getPrototypeOf(source || {}).constructor;
@@ -560,6 +650,7 @@ var createModelClass = function (modelDefinition) {
560
650
  var parsedValue = castInstanceType(modelDefinition, k, v);
561
651
  modelValidator(k, parsedValue);
562
652
  });
653
+ normalize(modelDefinition, draft);
563
654
  }, function (p) { return (patches = p); });
564
655
  var hasExistingPatches = modelPatchesMap.has(source);
565
656
  if (patches.length || hasExistingPatches) {
@@ -574,6 +665,15 @@ var createModelClass = function (modelDefinition) {
574
665
  checkReadOnlyPropertyOnUpdate(patches, modelDefinition);
575
666
  }
576
667
  }
668
+ else {
669
+ // always register patches when performing a copyOf, even if the
670
+ // patches list is empty. this allows `save()` to recognize when an
671
+ // instance is the result of a `copyOf()`. without more significant
672
+ // refactoring, this is the only way for `save()` to know which
673
+ // diffs (patches) are relevant for `storage` to use in building
674
+ // the list of "changed" fields for mutations.
675
+ modelPatchesMap.set(model, [[], source]);
676
+ }
577
677
  return attached(model, ModelAttachment.DataStore);
578
678
  };
579
679
  // "private" method (that's hidden via `Setting`) for `withSSRContext` to use
@@ -595,67 +695,89 @@ var createModelClass = function (modelDefinition) {
595
695
  }());
596
696
  clazz[immer_1.immerable] = true;
597
697
  Object.defineProperty(clazz, 'name', { value: modelDefinition.name });
598
- var _loop_1 = function (field) {
599
- if (!types_1.isFieldAssociation(modelDefinition, field)) {
600
- return "continue";
601
- }
602
- var _a = modelDefinition.fields[field], type = _a.type, localAssociation = _a.association, _b = _a.association, targetName = _b.targetName, targetNames = _b.targetNames;
603
- var relationship = new relationship_1.ModelRelationship({
604
- builder: clazz,
605
- schema: modelDefinition,
606
- pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
607
- }, field);
698
+ // Add getters/setters for relationship fields.
699
+ // getter - for lazy loading
700
+ // setter - for FK management
701
+ var allModelRelationships = relationship_1.ModelRelationship.allFrom({
702
+ builder: clazz,
703
+ schema: modelDefinition,
704
+ pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
705
+ });
706
+ var _loop_1 = function (relationship) {
707
+ var field = relationship.field;
608
708
  Object.defineProperty(clazz.prototype, modelDefinition.fields[field].name, {
609
709
  set: function (model) {
610
- if (!model || !(typeof model === 'object'))
710
+ if (!(typeof model === 'object' || typeof model === 'undefined'))
611
711
  return;
612
- // Avoid validation error when processing AppSync response with nested
613
- // selection set. Nested entitites lack version field and can not be validated
614
- // TODO: explore a more reliable method to solve this
615
- if (model.hasOwnProperty('_version')) {
616
- var modelConstructor = Object.getPrototypeOf(model || {})
617
- .constructor;
618
- if (!isValidModelConstructor(modelConstructor)) {
619
- var msg = "Value passed to " + modelDefinition.name + "." + field + " is not a valid instance of a model";
620
- logger.error(msg, { model: model });
621
- throw new Error(msg);
622
- }
623
- if (modelConstructor.name.toLowerCase() !==
624
- relationship.remoteModelConstructor.name.toLowerCase()) {
625
- var msg = "Value passed to " + modelDefinition.name + "." + field + " is not an instance of " + relationship.remoteModelConstructor.name;
626
- logger.error(msg, { model: model });
627
- throw new Error(msg);
712
+ // if model is undefined or null, the connection should be removed
713
+ if (model) {
714
+ // Avoid validation error when processing AppSync response with nested
715
+ // selection set. Nested entitites lack version field and can not be validated
716
+ // TODO: explore a more reliable method to solve this
717
+ if (model.hasOwnProperty('_version')) {
718
+ var modelConstructor = Object.getPrototypeOf(model || {})
719
+ .constructor;
720
+ if (!isValidModelConstructor(modelConstructor)) {
721
+ var msg = "Value passed to " + modelDefinition.name + "." + field + " is not a valid instance of a model";
722
+ logger.error(msg, { model: model });
723
+ throw new Error(msg);
724
+ }
725
+ if (modelConstructor.name.toLowerCase() !==
726
+ relationship.remoteModelConstructor.name.toLowerCase()) {
727
+ var msg = "Value passed to " + modelDefinition.name + "." + field + " is not an instance of " + relationship.remoteModelConstructor.name;
728
+ logger.error(msg, { model: model });
729
+ throw new Error(msg);
730
+ }
628
731
  }
629
732
  }
733
+ // if the relationship can be managed automagically, set the FK's
630
734
  if (relationship.isComplete) {
631
735
  for (var i = 0; i < relationship.localJoinFields.length; i++) {
632
- this[relationship.localJoinFields[i]] =
633
- model[relationship.remoteJoinFields[i]];
736
+ this[relationship.localJoinFields[i]] = model === null || model === void 0 ? void 0 : model[relationship.remoteJoinFields[i]];
634
737
  }
635
738
  var instanceMemos = modelInstanceAssociationsMap.has(this)
636
739
  ? modelInstanceAssociationsMap.get(this)
637
740
  : modelInstanceAssociationsMap.set(this, {}).get(this);
638
- instanceMemos[field] = model;
741
+ instanceMemos[field] = model || undefined;
639
742
  }
640
743
  },
641
744
  get: function () {
642
745
  var _this = this;
746
+ /**
747
+ * Bucket for holding related models instances specific to `this` instance.
748
+ */
643
749
  var instanceMemos = modelInstanceAssociationsMap.has(this)
644
750
  ? modelInstanceAssociationsMap.get(this)
645
751
  : modelInstanceAssociationsMap.set(this, {}).get(this);
752
+ // if the memos already has a result for this field, we'll use it.
753
+ // there is no "cache" invalidation of any kind; memos are permanent to
754
+ // keep an immutable perception of the instance.
646
755
  if (!instanceMemos.hasOwnProperty(field)) {
756
+ // before we populate the memo, we need to know where to look for relatives.
757
+ // today, this only supports DataStore. Models aren't managed elsewhere in Amplify.
647
758
  if (exports.getAttachment(this) === ModelAttachment.DataStore) {
759
+ // when we fetch the results using a query constructed under the guidance
760
+ // of the relationship metadata, we DO NOT AWAIT resolution. we want to
761
+ // drop the promise into the memo's synchronously, eliminating the chance
762
+ // for a race.
648
763
  var resultPromise = instance.query(relationship.remoteModelConstructor, function (base) {
649
764
  return base.and(function (q) {
650
765
  return relationship.remoteJoinFields.map(function (field, index) {
766
+ // TODO: anything we can use instead of `any` here?
651
767
  return q[field].eq(_this[relationship.localJoinFields[index]]);
652
768
  });
653
769
  });
654
770
  });
771
+ // results in hand, how we return them to the caller depends on the relationship type.
655
772
  if (relationship.type === 'HAS_MANY') {
773
+ // collections should support async iteration, even though we don't
774
+ // leverage it fully [yet].
656
775
  instanceMemos[field] = new AsyncCollection(resultPromise);
657
776
  }
658
777
  else {
778
+ // non-collections should only ever return 1 value *or nothing*.
779
+ // if we have more than 1 record, something's amiss. it's not our job
780
+ // pick a result for the customer. it's our job to say "something's wrong."
659
781
  instanceMemos[field] = resultPromise.then(function (rows) {
660
782
  if (rows.length > 1) {
661
783
  // should never happen for a HAS_ONE or BELONGS_TO.
@@ -685,11 +807,24 @@ var createModelClass = function (modelDefinition) {
685
807
  },
686
808
  });
687
809
  };
688
- for (var field in modelDefinition.fields) {
689
- _loop_1(field);
810
+ try {
811
+ for (var allModelRelationships_1 = tslib_1.__values(allModelRelationships), allModelRelationships_1_1 = allModelRelationships_1.next(); !allModelRelationships_1_1.done; allModelRelationships_1_1 = allModelRelationships_1.next()) {
812
+ var relationship = allModelRelationships_1_1.value;
813
+ _loop_1(relationship);
814
+ }
815
+ }
816
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
817
+ finally {
818
+ try {
819
+ if (allModelRelationships_1_1 && !allModelRelationships_1_1.done && (_a = allModelRelationships_1.return)) _a.call(allModelRelationships_1);
820
+ }
821
+ finally { if (e_5) throw e_5.error; }
690
822
  }
691
823
  return clazz;
692
824
  };
825
+ /**
826
+ * An eventually loaded related model instance.
827
+ */
693
828
  var AsyncItem = /** @class */ (function (_super) {
694
829
  tslib_1.__extends(AsyncItem, _super);
695
830
  function AsyncItem() {
@@ -698,10 +833,26 @@ var AsyncItem = /** @class */ (function (_super) {
698
833
  return AsyncItem;
699
834
  }(Promise));
700
835
  exports.AsyncItem = AsyncItem;
836
+ /**
837
+ * A collection of related model instances.
838
+ *
839
+ * This collection can be async-iterated or turned directly into an array using `toArray()`.
840
+ */
701
841
  var AsyncCollection = /** @class */ (function () {
702
842
  function AsyncCollection(values) {
703
843
  this.values = values;
704
844
  }
845
+ /**
846
+ * Facilitates async iteration.
847
+ *
848
+ * ```ts
849
+ * for await (const item of collection) {
850
+ * handle(item)
851
+ * }
852
+ * ```
853
+ *
854
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of
855
+ */
705
856
  AsyncCollection.prototype[Symbol.asyncIterator] = function () {
706
857
  var _this = this;
707
858
  var values;
@@ -735,11 +886,19 @@ var AsyncCollection = /** @class */ (function () {
735
886
  }); },
736
887
  };
737
888
  };
889
+ /**
890
+ * Turns the collection into an array, up to the amount specified in `max` param.
891
+ *
892
+ * ```ts
893
+ * const all = await collection.toArray();
894
+ * const first100 = await collection.toArray({max: 100});
895
+ * ```
896
+ */
738
897
  AsyncCollection.prototype.toArray = function (_a) {
739
898
  var _b = (_a === void 0 ? {} : _a).max, max = _b === void 0 ? Number.MAX_SAFE_INTEGER : _b;
740
- var e_4, _c;
899
+ var e_6, _c;
741
900
  return tslib_1.__awaiter(this, void 0, void 0, function () {
742
- var output, i, _d, _e, element, e_4_1;
901
+ var output, i, _d, _e, element, e_6_1;
743
902
  return tslib_1.__generator(this, function (_f) {
744
903
  switch (_f.label) {
745
904
  case 0:
@@ -765,8 +924,8 @@ var AsyncCollection = /** @class */ (function () {
765
924
  case 4: return [3 /*break*/, 2];
766
925
  case 5: return [3 /*break*/, 12];
767
926
  case 6:
768
- e_4_1 = _f.sent();
769
- e_4 = { error: e_4_1 };
927
+ e_6_1 = _f.sent();
928
+ e_6 = { error: e_6_1 };
770
929
  return [3 /*break*/, 12];
771
930
  case 7:
772
931
  _f.trys.push([7, , 10, 11]);
@@ -777,7 +936,7 @@ var AsyncCollection = /** @class */ (function () {
777
936
  _f.label = 9;
778
937
  case 9: return [3 /*break*/, 11];
779
938
  case 10:
780
- if (e_4) throw e_4.error;
939
+ if (e_6) throw e_6.error;
781
940
  return [7 /*endfinally*/];
782
941
  case 11: return [7 /*endfinally*/];
783
942
  case 12: return [2 /*return*/, output];
@@ -887,8 +1046,8 @@ function checkSchemaVersion(storage, version) {
887
1046
  var _a, schemaVersionSetting, storedValue;
888
1047
  return tslib_1.__generator(this, function (_b) {
889
1048
  switch (_b.label) {
890
- case 0: return [4 /*yield*/, s.query(Setting, predicates_1.ModelPredicateCreator.createFromExisting(modelDefinition, function (c) {
891
- return c.key('eq', SETTING_SCHEMA_VERSION);
1049
+ case 0: return [4 /*yield*/, s.query(Setting, predicates_1.ModelPredicateCreator.createFromAST(modelDefinition, {
1050
+ and: { key: { eq: SETTING_SCHEMA_VERSION } },
892
1051
  }), { page: 0, limit: 1 })];
893
1052
  case 1:
894
1053
  _a = tslib_1.__read.apply(void 0, [_b.sent(), 1]), schemaVersionSetting = _a[0];
@@ -964,6 +1123,8 @@ var DataStoreState;
964
1123
  DataStoreState["Stopping"] = "Stopping";
965
1124
  DataStoreState["Clearing"] = "Clearing";
966
1125
  })(DataStoreState || (DataStoreState = {}));
1126
+ // TODO: How can we get rid of the non-null assertions?
1127
+ // https://github.com/aws-amplify/amplify-js/pull/10477/files#r1007363485
967
1128
  var DataStore = /** @class */ (function () {
968
1129
  function DataStore() {
969
1130
  var _this = this;
@@ -1027,8 +1188,8 @@ var DataStore = /** @class */ (function () {
1027
1188
  /**
1028
1189
  * If not already done:
1029
1190
  * 1. Attaches and initializes storage.
1030
- * 1. Loads the schema and records metadata.
1031
- * 1. If `this.amplifyConfig.aws_appsync_graphqlEndpoint` contains a URL,
1191
+ * 2. Loads the schema and records metadata.
1192
+ * 3. If `this.amplifyConfig.aws_appsync_graphqlEndpoint` contains a URL,
1032
1193
  * attaches a sync engine, starts it, and subscribes.
1033
1194
  */
1034
1195
  this.start = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
@@ -1119,11 +1280,12 @@ var DataStore = /** @class */ (function () {
1119
1280
  .add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1120
1281
  var result, msg, modelDefinition, pagination, keyFields, msg, predicate, predicate, seedPredicate, predicate, returnOne;
1121
1282
  var _a;
1122
- return tslib_1.__generator(this, function (_b) {
1123
- switch (_b.label) {
1283
+ var _b;
1284
+ return tslib_1.__generator(this, function (_c) {
1285
+ switch (_c.label) {
1124
1286
  case 0: return [4 /*yield*/, this.start()];
1125
1287
  case 1:
1126
- _b.sent();
1288
+ _c.sent();
1127
1289
  if (!this.storage) {
1128
1290
  throw new Error('No storage to query');
1129
1291
  }
@@ -1150,37 +1312,37 @@ var DataStore = /** @class */ (function () {
1150
1312
  logger.error(msg, { keyFields: keyFields });
1151
1313
  throw new Error(msg);
1152
1314
  }
1153
- predicate = predicates_1.ModelPredicateCreator.createForSingleField(modelDefinition, keyFields[0], identifierOrCriteria);
1315
+ predicate = predicates_1.ModelPredicateCreator.createFromFlatEqualities(modelDefinition, (_a = {}, _a[keyFields[0]] = identifierOrCriteria, _a));
1154
1316
  return [4 /*yield*/, this.storage.query(modelConstructor, predicate, pagination)];
1155
1317
  case 2:
1156
- result = _b.sent();
1318
+ result = _c.sent();
1157
1319
  return [3 /*break*/, 9];
1158
1320
  case 3:
1159
1321
  if (!types_1.isIdentifierObject(identifierOrCriteria, modelDefinition)) return [3 /*break*/, 5];
1160
1322
  predicate = predicates_1.ModelPredicateCreator.createForPk(modelDefinition, identifierOrCriteria);
1161
1323
  return [4 /*yield*/, this.storage.query(modelConstructor, predicate, pagination)];
1162
1324
  case 4:
1163
- result = _b.sent();
1325
+ result = _c.sent();
1164
1326
  return [3 /*break*/, 9];
1165
1327
  case 5:
1166
1328
  if (!(!identifierOrCriteria ||
1167
1329
  predicates_1.isPredicatesAll(identifierOrCriteria))) return [3 /*break*/, 7];
1168
- return [4 /*yield*/, ((_a = this.storage) === null || _a === void 0 ? void 0 : _a.query(modelConstructor, undefined, pagination))];
1330
+ return [4 /*yield*/, ((_b = this.storage) === null || _b === void 0 ? void 0 : _b.query(modelConstructor, undefined, pagination))];
1169
1331
  case 6:
1170
- result = _b.sent();
1332
+ result = _c.sent();
1171
1333
  return [3 /*break*/, 9];
1172
1334
  case 7:
1173
1335
  seedPredicate = next_1.recursivePredicateFor({
1174
1336
  builder: modelConstructor,
1175
1337
  schema: modelDefinition,
1176
- pkField: getModelPKFieldName(modelConstructor),
1338
+ pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
1177
1339
  });
1178
1340
  predicate = next_1.internals(identifierOrCriteria(seedPredicate));
1179
1341
  return [4 /*yield*/, predicate.fetch(this.storage)];
1180
1342
  case 8:
1181
- result = (_b.sent());
1343
+ result = (_c.sent());
1182
1344
  result = util_1.inMemoryPagination(result, pagination);
1183
- _b.label = 9;
1345
+ _c.label = 9;
1184
1346
  case 9:
1185
1347
  returnOne = isQueryOne(identifierOrCriteria) ||
1186
1348
  types_1.isIdentifierObject(identifierOrCriteria, modelDefinition);
@@ -1196,7 +1358,7 @@ var DataStore = /** @class */ (function () {
1196
1358
  return tslib_1.__generator(this, function (_a) {
1197
1359
  return [2 /*return*/, this.runningProcesses
1198
1360
  .add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1199
- var patchesTuple, modelConstructor, msg, modelDefinition, modelMeta, producedCondition, _a, savedModel;
1361
+ var updatedPatchesTuple, initPatchesTuple, patchesTuple, modelConstructor, msg, modelDefinition, modelMeta, producedCondition, _a, savedModel;
1200
1362
  var _this = this;
1201
1363
  return tslib_1.__generator(this, function (_b) {
1202
1364
  switch (_b.label) {
@@ -1206,7 +1368,11 @@ var DataStore = /** @class */ (function () {
1206
1368
  if (!this.storage) {
1207
1369
  throw new Error('No storage to save to');
1208
1370
  }
1209
- patchesTuple = modelPatchesMap.get(model);
1371
+ updatedPatchesTuple = modelPatchesMap.get(model);
1372
+ initPatchesTuple = initPatches.has(model)
1373
+ ? [initPatches.get(model), {}]
1374
+ : undefined;
1375
+ patchesTuple = updatedPatchesTuple || initPatchesTuple;
1210
1376
  modelConstructor = model ? model.constructor : undefined;
1211
1377
  if (!isValidModelConstructor(modelConstructor)) {
1212
1378
  msg = 'Object is not an instance of a valid model';
@@ -1223,8 +1389,8 @@ var DataStore = /** @class */ (function () {
1223
1389
  pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
1224
1390
  };
1225
1391
  return [4 /*yield*/, this.storage.runExclusive(function (s) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1226
- var nonHasManyRelationships, nonHasManyRelationships_1, nonHasManyRelationships_1_1, relationship, queryObject, related, e_5_1;
1227
- var e_5, _a;
1392
+ var nonHasManyRelationships, nonHasManyRelationships_1, nonHasManyRelationships_1_1, relationship, queryObject, related, e_7_1;
1393
+ var e_7, _a;
1228
1394
  var _b;
1229
1395
  return tslib_1.__generator(this, function (_c) {
1230
1396
  switch (_c.label) {
@@ -1257,14 +1423,14 @@ var DataStore = /** @class */ (function () {
1257
1423
  return [3 /*break*/, 2];
1258
1424
  case 5: return [3 /*break*/, 8];
1259
1425
  case 6:
1260
- e_5_1 = _c.sent();
1261
- e_5 = { error: e_5_1 };
1426
+ e_7_1 = _c.sent();
1427
+ e_7 = { error: e_7_1 };
1262
1428
  return [3 /*break*/, 8];
1263
1429
  case 7:
1264
1430
  try {
1265
1431
  if (nonHasManyRelationships_1_1 && !nonHasManyRelationships_1_1.done && (_a = nonHasManyRelationships_1.return)) _a.call(nonHasManyRelationships_1);
1266
1432
  }
1267
- finally { if (e_5) throw e_5.error; }
1433
+ finally { if (e_7) throw e_7.error; }
1268
1434
  return [7 /*endfinally*/];
1269
1435
  case 8: return [2 /*return*/];
1270
1436
  }
@@ -1327,11 +1493,12 @@ var DataStore = /** @class */ (function () {
1327
1493
  return [2 /*return*/, this.runningProcesses
1328
1494
  .add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1329
1495
  var condition, msg, modelConstructor, msg, modelDefinition, keyFields, msg, msg, _a, deleted, model, modelConstructor, msg, modelDefinition, pkPredicate, msg, _b, _c, deleted;
1330
- return tslib_1.__generator(this, function (_d) {
1331
- switch (_d.label) {
1496
+ var _d;
1497
+ return tslib_1.__generator(this, function (_e) {
1498
+ switch (_e.label) {
1332
1499
  case 0: return [4 /*yield*/, this.start()];
1333
1500
  case 1:
1334
- _d.sent();
1501
+ _e.sent();
1335
1502
  if (!this.storage) {
1336
1503
  throw new Error('No storage to delete from');
1337
1504
  }
@@ -1358,7 +1525,7 @@ var DataStore = /** @class */ (function () {
1358
1525
  logger.error(msg, { keyFields: keyFields });
1359
1526
  throw new Error(msg);
1360
1527
  }
1361
- condition = predicates_1.ModelPredicateCreator.createForSingleField(modelDefinition, keyFields[0], identifierOrCriteria);
1528
+ condition = predicates_1.ModelPredicateCreator.createFromFlatEqualities(modelDefinition, (_d = {}, _d[keyFields[0]] = identifierOrCriteria, _d));
1362
1529
  }
1363
1530
  else {
1364
1531
  if (types_1.isIdentifierObject(identifierOrCriteria, modelDefinition)) {
@@ -1380,7 +1547,7 @@ var DataStore = /** @class */ (function () {
1380
1547
  }
1381
1548
  return [4 /*yield*/, this.storage.delete(modelConstructor, condition)];
1382
1549
  case 2:
1383
- _a = tslib_1.__read.apply(void 0, [_d.sent(), 1]), deleted = _a[0];
1550
+ _a = tslib_1.__read.apply(void 0, [_e.sent(), 1]), deleted = _a[0];
1384
1551
  return [2 /*return*/, attached(deleted, ModelAttachment.DataStore)];
1385
1552
  case 3:
1386
1553
  model = modelOrConstructor;
@@ -1406,14 +1573,14 @@ var DataStore = /** @class */ (function () {
1406
1573
  builder: modelConstructor,
1407
1574
  schema: modelDefinition,
1408
1575
  pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
1409
- }))).toStoragePredicate(pkPredicate);
1576
+ }))).toStoragePredicate();
1410
1577
  }
1411
1578
  else {
1412
1579
  condition = pkPredicate;
1413
1580
  }
1414
1581
  return [4 /*yield*/, this.storage.delete(model, condition)];
1415
1582
  case 4:
1416
- _b = tslib_1.__read.apply(void 0, [_d.sent(), 1]), _c = tslib_1.__read(_b[0], 1), deleted = _c[0];
1583
+ _b = tslib_1.__read.apply(void 0, [_e.sent(), 1]), _c = tslib_1.__read(_b[0], 1), deleted = _c[0];
1417
1584
  return [2 /*return*/, attached(deleted, ModelAttachment.DataStore)];
1418
1585
  }
1419
1586
  });
@@ -1685,9 +1852,6 @@ var DataStore = /** @class */ (function () {
1685
1852
  var _a, _b;
1686
1853
  var isSynced = (_b = (_a = _this.sync) === null || _a === void 0 ? void 0 : _a.getModelSyncedStatus(model)) !== null && _b !== void 0 ? _b : false;
1687
1854
  var itemsArray = tslib_1.__spread(Array.from(items.values()), Array.from(itemsChanged.values()));
1688
- if (options === null || options === void 0 ? void 0 : options.sort) {
1689
- sortItems(itemsArray);
1690
- }
1691
1855
  items.clear();
1692
1856
  itemsArray.forEach(function (item) {
1693
1857
  var itemModelDefinition = getModelDefinition(model);
@@ -1696,8 +1860,14 @@ var DataStore = /** @class */ (function () {
1696
1860
  });
1697
1861
  // remove deleted items from the final result set
1698
1862
  deletedItemIds.forEach(function (idOrPk) { return items.delete(idOrPk); });
1863
+ var snapshot = Array.from(items.values());
1864
+ // we sort after we merge the snapshots (items, itemsChanged)
1865
+ // otherwise, the merge may not
1866
+ if (options === null || options === void 0 ? void 0 : options.sort) {
1867
+ sortItems(snapshot);
1868
+ }
1699
1869
  return {
1700
- items: Array.from(items.values()),
1870
+ items: snapshot,
1701
1871
  isSynced: isSynced,
1702
1872
  };
1703
1873
  };
@@ -2021,15 +2191,6 @@ var DataStore = /** @class */ (function () {
2021
2191
  });
2022
2192
  });
2023
2193
  };
2024
- DataStore.prototype.createFromCondition = function (modelDefinition, condition) {
2025
- try {
2026
- return predicates_1.ModelPredicateCreator.createFromExisting(modelDefinition, condition);
2027
- }
2028
- catch (error) {
2029
- logger.error('Error creating Sync Predicate');
2030
- throw error;
2031
- }
2032
- };
2033
2194
  DataStore.prototype.unwrapPromise = function (conditionProducer) {
2034
2195
  return tslib_1.__awaiter(this, void 0, void 0, function () {
2035
2196
  var condition, error_1;