@aws-amplify/datastore 4.7.5 → 5.0.1-console-preview.4432977.0

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 (182) hide show
  1. package/README.md +4 -0
  2. package/lib/authModeStrategies/defaultAuthStrategy.js +3 -2
  3. package/lib/authModeStrategies/index.js +3 -3
  4. package/lib/authModeStrategies/multiAuthStrategy.js +81 -24
  5. package/lib/datastore/datastore.d.ts +3 -4
  6. package/lib/datastore/datastore.js +361 -227
  7. package/lib/index.d.ts +1 -1
  8. package/lib/index.js +25 -12
  9. package/lib/predicates/index.js +46 -12
  10. package/lib/predicates/next.d.ts +2 -2
  11. package/lib/predicates/next.js +172 -74
  12. package/lib/predicates/sort.js +3 -4
  13. package/lib/ssr/index.js +1 -1
  14. package/lib/storage/adapter/AsyncStorageAdapter.js +240 -128
  15. package/lib/storage/adapter/AsyncStorageDatabase.js +100 -39
  16. package/lib/storage/adapter/InMemoryStore.js +68 -17
  17. package/lib/storage/adapter/InMemoryStore.native.js +5 -3
  18. package/lib/storage/adapter/IndexedDBAdapter.js +355 -199
  19. package/lib/storage/adapter/StorageAdapterBase.js +154 -85
  20. package/lib/storage/adapter/getDefaultAdapter/index.js +8 -9
  21. package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -3
  22. package/lib/storage/adapter/index.js +0 -1
  23. package/lib/storage/relationship.js +31 -21
  24. package/lib/storage/storage.d.ts +3 -3
  25. package/lib/storage/storage.js +143 -61
  26. package/lib/sync/datastoreConnectivity.d.ts +1 -1
  27. package/lib/sync/datastoreConnectivity.js +57 -9
  28. package/lib/sync/datastoreReachability/index.js +3 -3
  29. package/lib/sync/datastoreReachability/index.native.js +7 -5
  30. package/lib/sync/index.d.ts +1 -1
  31. package/lib/sync/index.js +193 -125
  32. package/lib/sync/merger.js +81 -10
  33. package/lib/sync/outbox.js +101 -30
  34. package/lib/sync/processors/errorMaps.d.ts +1 -1
  35. package/lib/sync/processors/errorMaps.js +41 -6
  36. package/lib/sync/processors/mutation.d.ts +1 -1
  37. package/lib/sync/processors/mutation.js +192 -101
  38. package/lib/sync/processors/subscription.d.ts +4 -1
  39. package/lib/sync/processors/subscription.js +190 -178
  40. package/lib/sync/processors/sync.d.ts +1 -1
  41. package/lib/sync/processors/sync.js +113 -47
  42. package/lib/sync/utils.d.ts +4 -4
  43. package/lib/sync/utils.js +162 -81
  44. package/lib/tsconfig.tsbuildinfo +1 -0
  45. package/lib/types.d.ts +138 -140
  46. package/lib/types.js +40 -5
  47. package/lib/util.d.ts +9 -17
  48. package/lib/util.js +216 -100
  49. package/lib-esm/authModeStrategies/defaultAuthStrategy.js +0 -1
  50. package/lib-esm/authModeStrategies/index.js +0 -1
  51. package/lib-esm/authModeStrategies/multiAuthStrategy.js +76 -21
  52. package/lib-esm/datastore/datastore.d.ts +3 -4
  53. package/lib-esm/datastore/datastore.js +206 -77
  54. package/lib-esm/index.d.ts +1 -1
  55. package/lib-esm/index.js +0 -1
  56. package/lib-esm/predicates/index.js +40 -7
  57. package/lib-esm/predicates/next.d.ts +2 -2
  58. package/lib-esm/predicates/next.js +148 -52
  59. package/lib-esm/predicates/sort.js +2 -4
  60. package/lib-esm/ssr/index.js +0 -1
  61. package/lib-esm/storage/adapter/AsyncStorageAdapter.js +203 -95
  62. package/lib-esm/storage/adapter/AsyncStorageDatabase.js +66 -5
  63. package/lib-esm/storage/adapter/InMemoryStore.js +52 -2
  64. package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
  65. package/lib-esm/storage/adapter/IndexedDBAdapter.js +271 -138
  66. package/lib-esm/storage/adapter/StorageAdapterBase.js +130 -62
  67. package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -5
  68. package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +0 -1
  69. package/lib-esm/storage/adapter/index.js +1 -1
  70. package/lib-esm/storage/relationship.js +27 -18
  71. package/lib-esm/storage/storage.d.ts +3 -3
  72. package/lib-esm/storage/storage.js +87 -9
  73. package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
  74. package/lib-esm/sync/datastoreConnectivity.js +48 -3
  75. package/lib-esm/sync/datastoreReachability/index.js +1 -2
  76. package/lib-esm/sync/datastoreReachability/index.native.js +1 -2
  77. package/lib-esm/sync/index.d.ts +1 -1
  78. package/lib-esm/sync/index.js +136 -72
  79. package/lib-esm/sync/merger.js +73 -3
  80. package/lib-esm/sync/outbox.js +75 -5
  81. package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
  82. package/lib-esm/sync/processors/errorMaps.js +39 -5
  83. package/lib-esm/sync/processors/mutation.d.ts +1 -1
  84. package/lib-esm/sync/processors/mutation.js +130 -44
  85. package/lib-esm/sync/processors/subscription.d.ts +4 -1
  86. package/lib-esm/sync/processors/subscription.js +134 -126
  87. package/lib-esm/sync/processors/sync.d.ts +1 -1
  88. package/lib-esm/sync/processors/sync.js +74 -12
  89. package/lib-esm/sync/utils.d.ts +4 -4
  90. package/lib-esm/sync/utils.js +135 -55
  91. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  92. package/lib-esm/types.d.ts +138 -140
  93. package/lib-esm/types.js +36 -2
  94. package/lib-esm/util.d.ts +9 -17
  95. package/lib-esm/util.js +96 -16
  96. package/package.json +139 -132
  97. package/src/authModeStrategies/multiAuthStrategy.ts +11 -12
  98. package/src/datastore/datastore.ts +32 -25
  99. package/src/predicates/sort.ts +3 -1
  100. package/src/storage/adapter/InMemoryStore.ts +1 -1
  101. package/src/storage/adapter/IndexedDBAdapter.ts +1 -1
  102. package/src/storage/adapter/StorageAdapterBase.ts +1 -1
  103. package/src/storage/adapter/getDefaultAdapter/index.ts +2 -3
  104. package/src/storage/storage.ts +1 -1
  105. package/src/sync/datastoreConnectivity.ts +2 -2
  106. package/src/sync/datastoreReachability/index.native.ts +1 -1
  107. package/src/sync/datastoreReachability/index.ts +1 -1
  108. package/src/sync/index.ts +69 -78
  109. package/src/sync/processors/mutation.ts +16 -10
  110. package/src/sync/processors/subscription.ts +55 -127
  111. package/src/sync/processors/sync.ts +8 -4
  112. package/src/sync/utils.ts +7 -8
  113. package/src/types.ts +4 -8
  114. package/src/util.ts +5 -6
  115. package/lib/.tsbuildinfo +0 -3
  116. package/lib/authModeStrategies/defaultAuthStrategy.js.map +0 -1
  117. package/lib/authModeStrategies/index.js.map +0 -1
  118. package/lib/authModeStrategies/multiAuthStrategy.js.map +0 -1
  119. package/lib/datastore/datastore.js.map +0 -1
  120. package/lib/index.js.map +0 -1
  121. package/lib/predicates/index.js.map +0 -1
  122. package/lib/predicates/next.js.map +0 -1
  123. package/lib/predicates/sort.js.map +0 -1
  124. package/lib/ssr/index.js.map +0 -1
  125. package/lib/storage/adapter/AsyncStorageAdapter.js.map +0 -1
  126. package/lib/storage/adapter/AsyncStorageDatabase.js.map +0 -1
  127. package/lib/storage/adapter/InMemoryStore.js.map +0 -1
  128. package/lib/storage/adapter/InMemoryStore.native.js.map +0 -1
  129. package/lib/storage/adapter/IndexedDBAdapter.js.map +0 -1
  130. package/lib/storage/adapter/StorageAdapterBase.js.map +0 -1
  131. package/lib/storage/adapter/getDefaultAdapter/index.js.map +0 -1
  132. package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
  133. package/lib/storage/adapter/index.js.map +0 -1
  134. package/lib/storage/relationship.js.map +0 -1
  135. package/lib/storage/storage.js.map +0 -1
  136. package/lib/sync/datastoreConnectivity.js.map +0 -1
  137. package/lib/sync/datastoreReachability/index.js.map +0 -1
  138. package/lib/sync/datastoreReachability/index.native.js.map +0 -1
  139. package/lib/sync/index.js.map +0 -1
  140. package/lib/sync/merger.js.map +0 -1
  141. package/lib/sync/outbox.js.map +0 -1
  142. package/lib/sync/processors/errorMaps.js.map +0 -1
  143. package/lib/sync/processors/mutation.js.map +0 -1
  144. package/lib/sync/processors/subscription.js.map +0 -1
  145. package/lib/sync/processors/sync.js.map +0 -1
  146. package/lib/sync/utils.js.map +0 -1
  147. package/lib/types.js.map +0 -1
  148. package/lib/util.js.map +0 -1
  149. package/lib-esm/.tsbuildinfo +0 -3
  150. package/lib-esm/authModeStrategies/defaultAuthStrategy.js.map +0 -1
  151. package/lib-esm/authModeStrategies/index.js.map +0 -1
  152. package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +0 -1
  153. package/lib-esm/datastore/datastore.js.map +0 -1
  154. package/lib-esm/index.js.map +0 -1
  155. package/lib-esm/predicates/index.js.map +0 -1
  156. package/lib-esm/predicates/next.js.map +0 -1
  157. package/lib-esm/predicates/sort.js.map +0 -1
  158. package/lib-esm/ssr/index.js.map +0 -1
  159. package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +0 -1
  160. package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +0 -1
  161. package/lib-esm/storage/adapter/InMemoryStore.js.map +0 -1
  162. package/lib-esm/storage/adapter/InMemoryStore.native.js.map +0 -1
  163. package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +0 -1
  164. package/lib-esm/storage/adapter/StorageAdapterBase.js.map +0 -1
  165. package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +0 -1
  166. package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
  167. package/lib-esm/storage/adapter/index.js.map +0 -1
  168. package/lib-esm/storage/relationship.js.map +0 -1
  169. package/lib-esm/storage/storage.js.map +0 -1
  170. package/lib-esm/sync/datastoreConnectivity.js.map +0 -1
  171. package/lib-esm/sync/datastoreReachability/index.js.map +0 -1
  172. package/lib-esm/sync/datastoreReachability/index.native.js.map +0 -1
  173. package/lib-esm/sync/index.js.map +0 -1
  174. package/lib-esm/sync/merger.js.map +0 -1
  175. package/lib-esm/sync/outbox.js.map +0 -1
  176. package/lib-esm/sync/processors/errorMaps.js.map +0 -1
  177. package/lib-esm/sync/processors/mutation.js.map +0 -1
  178. package/lib-esm/sync/processors/subscription.js.map +0 -1
  179. package/lib-esm/sync/processors/sync.js.map +0 -1
  180. package/lib-esm/sync/utils.js.map +0 -1
  181. package/lib-esm/types.js.map +0 -1
  182. package/lib-esm/util.js.map +0 -1
@@ -1,15 +1,132 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
65
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
66
+ var m = o[Symbol.asyncIterator], i;
67
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
68
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
69
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
70
+ };
71
+ var __rest = (this && this.__rest) || function (s, e) {
72
+ var t = {};
73
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
74
+ t[p] = s[p];
75
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
76
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
77
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
78
+ t[p[i]] = s[p[i]];
79
+ }
80
+ return t;
81
+ };
82
+ var __read = (this && this.__read) || function (o, n) {
83
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
84
+ if (!m) return o;
85
+ var i = m.call(o), r, ar = [], e;
86
+ try {
87
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
88
+ }
89
+ catch (error) { e = { error: error }; }
90
+ finally {
91
+ try {
92
+ if (r && !r.done && (m = i["return"])) m.call(i);
93
+ }
94
+ finally { if (e) throw e.error; }
95
+ }
96
+ return ar;
97
+ };
98
+ var __values = (this && this.__values) || function(o) {
99
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
100
+ if (m) return m.call(o);
101
+ if (o && typeof o.length === "number") return {
102
+ next: function () {
103
+ if (o && i >= o.length) o = void 0;
104
+ return { value: o && o[i++], done: !o };
105
+ }
106
+ };
107
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
108
+ };
109
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
110
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
111
+ if (ar || !(i in from)) {
112
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
113
+ ar[i] = from[i];
114
+ }
115
+ }
116
+ return to.concat(ar || Array.prototype.slice.call(from));
117
+ };
118
+ var __importDefault = (this && this.__importDefault) || function (mod) {
119
+ return (mod && mod.__esModule) ? mod : { "default": mod };
120
+ };
2
121
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
122
+ exports.DataStore = exports.initSchema = exports.DataStoreClass = exports.AsyncCollection = exports.AsyncItem = exports.getAttachment = exports.attached = exports.syncClasses = void 0;
4
123
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
124
  // SPDX-License-Identifier: Apache-2.0
6
125
  var internals_1 = require("@aws-amplify/api/internals");
7
- var auth_1 = require("@aws-amplify/auth");
8
- var cache_1 = require("@aws-amplify/cache");
9
126
  var core_1 = require("@aws-amplify/core");
10
127
  var immer_1 = require("immer");
11
128
  var uuid_1 = require("uuid");
12
- var zen_observable_ts_1 = tslib_1.__importDefault(require("zen-observable-ts"));
129
+ var zen_observable_ts_1 = __importDefault(require("zen-observable-ts"));
13
130
  var authModeStrategies_1 = require("../authModeStrategies");
14
131
  var predicates_1 = require("../predicates");
15
132
  var storage_1 = require("../storage/storage");
@@ -19,11 +136,11 @@ var types_1 = require("../types");
19
136
  var util_1 = require("../util");
20
137
  var next_1 = require("../predicates/next");
21
138
  var utils_1 = require("../sync/utils");
22
- immer_1.setAutoFreeze(true);
23
- immer_1.enablePatches();
24
- var logger = new core_1.ConsoleLogger('DataStore');
25
- var ulid = util_1.monotonicUlidFactory(Date.now());
26
- var isNode = core_1.browserOrNode().isNode;
139
+ var utils_2 = require("@aws-amplify/core/internals/utils");
140
+ (0, immer_1.setAutoFreeze)(true);
141
+ (0, immer_1.enablePatches)();
142
+ var logger = new utils_2.Logger('DataStore');
143
+ var ulid = (0, util_1.monotonicUlidFactory)(Date.now());
27
144
  var SETTING_SCHEMA_VERSION = 'schemaVersion';
28
145
  var schema;
29
146
  var modelNamespaceMap = new WeakMap();
@@ -48,12 +165,12 @@ var getModelDefinition = function (modelConstructor) {
48
165
  * @param obj The object to test.
49
166
  */
50
167
  var isValidModelConstructor = function (obj) {
51
- return util_1.isModelConstructor(obj) && modelNamespaceMap.has(obj);
168
+ return (0, util_1.isModelConstructor)(obj) && modelNamespaceMap.has(obj);
52
169
  };
53
170
  var namespaceResolver = function (modelConstructor) {
54
171
  var resolver = modelNamespaceMap.get(modelConstructor);
55
172
  if (!resolver) {
56
- throw new Error("Namespace Resolver for '" + modelConstructor.name + "' not found! This is probably a bug in '@amplify-js/datastore'.");
173
+ throw new Error("Namespace Resolver for '".concat(modelConstructor.name, "' not found! This is probably a bug in '@amplify-js/datastore'."));
57
174
  }
58
175
  return resolver;
59
176
  };
@@ -82,10 +199,10 @@ var buildSeedPredicate = function (modelConstructor) {
82
199
  var modelSchema = getModelDefinition(modelConstructor);
83
200
  if (!modelSchema)
84
201
  throw new Error('Missing modelSchema');
85
- var pks = util_1.extractPrimaryKeyFieldNames(modelSchema);
202
+ var pks = (0, util_1.extractPrimaryKeyFieldNames)(modelSchema);
86
203
  if (!pks)
87
204
  throw new Error('Could not determine PK');
88
- return next_1.recursivePredicateFor({
205
+ return (0, next_1.recursivePredicateFor)({
89
206
  builder: modelConstructor,
90
207
  schema: modelSchema,
91
208
  pkField: pks,
@@ -154,11 +271,12 @@ exports.attached = attached;
154
271
  *
155
272
  * @param instance A model instance
156
273
  */
157
- exports.getAttachment = function (instance) {
274
+ var getAttachment = function (instance) {
158
275
  return attachedModelInstances.has(instance)
159
276
  ? attachedModelInstances.get(instance)
160
277
  : ModelAttachment.Detached;
161
278
  };
279
+ exports.getAttachment = getAttachment;
162
280
  var initSchema = function (userSchema) {
163
281
  var _a;
164
282
  if (schema !== undefined) {
@@ -167,7 +285,7 @@ var initSchema = function (userSchema) {
167
285
  }
168
286
  logger.log('validating schema', { schema: userSchema });
169
287
  checkSchemaCodegenVersion(userSchema.codegenVersion);
170
- var internalUserNamespace = tslib_1.__assign({ name: util_1.USER }, userSchema);
288
+ var internalUserNamespace = __assign({ name: util_1.USER }, userSchema);
171
289
  logger.log('DataStore', 'Init models');
172
290
  userClasses = createTypeClasses(internalUserNamespace);
173
291
  logger.log('DataStore', 'Models initialized');
@@ -189,7 +307,7 @@ var initSchema = function (userSchema) {
189
307
  };
190
308
  Object.keys(schema.namespaces).forEach(function (namespace) {
191
309
  var e_1, _a;
192
- var _b = tslib_1.__read(util_1.establishRelationAndKeys(schema.namespaces[namespace]), 2), relations = _b[0], keys = _b[1];
310
+ var _b = __read((0, util_1.establishRelationAndKeys)(schema.namespaces[namespace]), 2), relations = _b[0], keys = _b[1];
193
311
  schema.namespaces[namespace].relationships = relations;
194
312
  schema.namespaces[namespace].keys = keys;
195
313
  var modelAssociations = new Map();
@@ -211,16 +329,16 @@ var initSchema = function (userSchema) {
211
329
  // to go looking for it.
212
330
  Object.values(model.fields).forEach(function (field) {
213
331
  var relatedModel = userClasses[field.type.model];
214
- if (util_1.isModelConstructor(relatedModel)) {
332
+ if ((0, util_1.isModelConstructor)(relatedModel)) {
215
333
  Object.defineProperty(field.type, 'modelConstructor', {
216
334
  get: function () {
217
335
  var relatedModelDefinition = getModelDefinition(relatedModel);
218
336
  if (!relatedModelDefinition)
219
- throw new Error("Could not find model definition for " + relatedModel.name);
337
+ throw new Error("Could not find model definition for ".concat(relatedModel.name));
220
338
  return {
221
339
  builder: relatedModel,
222
340
  schema: relatedModelDefinition,
223
- pkField: util_1.extractPrimaryKeyFieldNames(relatedModelDefinition),
341
+ pkField: (0, util_1.extractPrimaryKeyFieldNames)(relatedModelDefinition),
224
342
  };
225
343
  },
226
344
  });
@@ -232,10 +350,10 @@ var initSchema = function (userSchema) {
232
350
  var indexes = schema.namespaces[namespace].relationships[model.name].indexes;
233
351
  var indexFields = new Set();
234
352
  try {
235
- for (var indexes_1 = tslib_1.__values(indexes), indexes_1_1 = indexes_1.next(); !indexes_1_1.done; indexes_1_1 = indexes_1.next()) {
353
+ for (var indexes_1 = __values(indexes), indexes_1_1 = indexes_1.next(); !indexes_1_1.done; indexes_1_1 = indexes_1.next()) {
236
354
  var index = indexes_1_1.value;
237
355
  try {
238
- for (var _c = (e_3 = void 0, tslib_1.__values(index[1])), _d = _c.next(); !_d.done; _d = _c.next()) {
356
+ for (var _c = (e_3 = void 0, __values(index[1])), _d = _c.next(); !_d.done; _d = _c.next()) {
239
357
  var indexField = _d.value;
240
358
  indexFields.add(indexField);
241
359
  }
@@ -256,7 +374,7 @@ var initSchema = function (userSchema) {
256
374
  }
257
375
  finally { if (e_2) throw e_2.error; }
258
376
  }
259
- model.allFields = tslib_1.__assign(tslib_1.__assign({}, Object.fromEntries(tslib_1.__spread(indexFields.values()).map(function (name) { return [
377
+ model.allFields = __assign(__assign({}, Object.fromEntries(__spreadArray([], __read(indexFields.values()), false).map(function (name) { return [
260
378
  name,
261
379
  {
262
380
  name: name,
@@ -276,7 +394,7 @@ var initSchema = function (userSchema) {
276
394
  throw new Error('Models are not topologically sortable. Please verify your schema.');
277
395
  }
278
396
  try {
279
- for (var _c = (e_1 = void 0, tslib_1.__values(Array.from(modelAssociations.keys()))), _d = _c.next(); !_d.done; _d = _c.next()) {
397
+ for (var _c = (e_1 = void 0, __values(Array.from(modelAssociations.keys()))), _d = _c.next(); !_d.done; _d = _c.next()) {
280
398
  var modelName = _d.value;
281
399
  var parents = modelAssociations.get(modelName);
282
400
  if (parents === null || parents === void 0 ? void 0 : parents.every(function (x) { return result.has(x); })) {
@@ -338,14 +456,14 @@ var checkSchemaCodegenVersion = function (codegenVersion) {
338
456
  var isValid = false;
339
457
  try {
340
458
  var versionParts = codegenVersion.split('.');
341
- var _a = tslib_1.__read(versionParts, 4), major = _a[0], minor = _a[1], patch = _a[2], patchrevision = _a[3];
459
+ var _a = __read(versionParts, 4), major = _a[0], minor = _a[1], patch = _a[2], patchrevision = _a[3];
342
460
  isValid = Number(major) === majorVersion && Number(minor) >= minorVersion;
343
461
  }
344
462
  catch (err) {
345
- console.log("Error parsing codegen version: " + codegenVersion + "\n" + err);
463
+ console.log("Error parsing codegen version: ".concat(codegenVersion, "\n").concat(err));
346
464
  }
347
465
  if (!isValid) {
348
- var message = "Models were generated with an unsupported version of codegen. Codegen artifacts are from " + (codegenVersion || 'an unknown version') + ", whereas ^" + majorVersion + "." + minorVersion + ".0 is required. " +
466
+ var message = "Models were generated with an unsupported version of codegen. Codegen artifacts are from ".concat(codegenVersion || 'an unknown version', ", whereas ^").concat(majorVersion, ".").concat(minorVersion, ".0 is required. ") +
349
467
  "Update to the latest CLI and run 'amplify codegen models'.";
350
468
  logger.error(message);
351
469
  throw new Error(message);
@@ -354,13 +472,13 @@ var checkSchemaCodegenVersion = function (codegenVersion) {
354
472
  var createTypeClasses = function (namespace) {
355
473
  var classes = {};
356
474
  Object.entries(namespace.models).forEach(function (_a) {
357
- var _b = tslib_1.__read(_a, 2), modelName = _b[0], modelDefinition = _b[1];
475
+ var _b = __read(_a, 2), modelName = _b[0], modelDefinition = _b[1];
358
476
  var clazz = createModelClass(modelDefinition);
359
477
  classes[modelName] = clazz;
360
478
  modelNamespaceMap.set(clazz, namespace.name);
361
479
  });
362
480
  Object.entries(namespace.nonModels || {}).forEach(function (_a) {
363
- var _b = tslib_1.__read(_a, 2), typeName = _b[0], typeDefinition = _b[1];
481
+ var _b = __read(_a, 2), typeName = _b[0], typeDefinition = _b[1];
364
482
  var clazz = createNonModelClass(typeDefinition);
365
483
  classes[typeName] = clazz;
366
484
  });
@@ -380,24 +498,24 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
380
498
  var fieldDefinition = modelDefinition.fields[k];
381
499
  if (fieldDefinition !== undefined) {
382
500
  var type_1 = fieldDefinition.type, isRequired_1 = fieldDefinition.isRequired, isArrayNullable = fieldDefinition.isArrayNullable, name_1 = fieldDefinition.name, isArray = fieldDefinition.isArray;
383
- var timestamps = types_1.isSchemaModelWithAttributes(modelDefinition)
384
- ? util_1.getTimestampFields(modelDefinition)
501
+ var timestamps = (0, types_1.isSchemaModelWithAttributes)(modelDefinition)
502
+ ? (0, util_1.getTimestampFields)(modelDefinition)
385
503
  : {};
386
504
  var isTimestampField = !!timestamps[name_1];
387
505
  if (((!isArray && isRequired_1) || (isArray && !isArrayNullable)) &&
388
506
  !isTimestampField &&
389
507
  (v === null || v === undefined)) {
390
- throw new Error("Field " + name_1 + " is required");
508
+ throw new Error("Field ".concat(name_1, " is required"));
391
509
  }
392
- if (types_1.isSchemaModelWithAttributes(modelDefinition) &&
393
- !util_1.isIdManaged(modelDefinition)) {
394
- var keys = util_1.extractPrimaryKeyFieldNames(modelDefinition);
510
+ if ((0, types_1.isSchemaModelWithAttributes)(modelDefinition) &&
511
+ !(0, util_1.isIdManaged)(modelDefinition)) {
512
+ var keys = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
395
513
  if (keys.includes(k) && v === '') {
396
514
  logger.error(util_1.errorMessages.idEmptyString, { k: k, value: v });
397
515
  throw new Error(util_1.errorMessages.idEmptyString);
398
516
  }
399
517
  }
400
- if (types_1.isGraphQLScalarType(type_1)) {
518
+ if ((0, types_1.isGraphQLScalarType)(type_1)) {
401
519
  var jsType_1 = types_1.GraphQLScalarType.getJSType(type_1);
402
520
  var validateScalar_1 = types_1.GraphQLScalarType.getValidationFunction(type_1);
403
521
  if (type_1 === 'AWSJSON') {
@@ -410,33 +528,33 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
410
528
  return;
411
529
  }
412
530
  catch (error) {
413
- throw new Error("Field " + name_1 + " is an invalid JSON object. " + v);
531
+ throw new Error("Field ".concat(name_1, " is an invalid JSON object. ").concat(v));
414
532
  }
415
533
  }
416
534
  }
417
535
  if (isArray) {
418
536
  var errorTypeText = jsType_1;
419
537
  if (!isRequired_1) {
420
- errorTypeText = jsType_1 + " | null | undefined";
538
+ errorTypeText = "".concat(jsType_1, " | null | undefined");
421
539
  }
422
540
  if (!Array.isArray(v) && !isArrayNullable) {
423
- throw new Error("Field " + name_1 + " should be of type [" + errorTypeText + "], " + typeof v + " received. " + v);
541
+ throw new Error("Field ".concat(name_1, " should be of type [").concat(errorTypeText, "], ").concat(typeof v, " received. ").concat(v));
424
542
  }
425
- if (!util_1.isNullOrUndefined(v) &&
543
+ if (!(0, util_1.isNullOrUndefined)(v) &&
426
544
  v.some(function (e) {
427
- return util_1.isNullOrUndefined(e) ? isRequired_1 : typeof e !== jsType_1;
545
+ return (0, util_1.isNullOrUndefined)(e) ? isRequired_1 : typeof e !== jsType_1;
428
546
  })) {
429
547
  var elemTypes = v
430
548
  .map(function (e) { return (e === null ? 'null' : typeof e); })
431
549
  .join(',');
432
- throw new Error("All elements in the " + name_1 + " array should be of type " + errorTypeText + ", [" + elemTypes + "] received. " + v);
550
+ throw new Error("All elements in the ".concat(name_1, " array should be of type ").concat(errorTypeText, ", [").concat(elemTypes, "] received. ").concat(v));
433
551
  }
434
- if (validateScalar_1 && !util_1.isNullOrUndefined(v)) {
552
+ if (validateScalar_1 && !(0, util_1.isNullOrUndefined)(v)) {
435
553
  var validationStatus = v.map(function (e) {
436
- if (!util_1.isNullOrUndefined(e)) {
554
+ if (!(0, util_1.isNullOrUndefined)(e)) {
437
555
  return validateScalar_1(e);
438
556
  }
439
- else if (util_1.isNullOrUndefined(e) && !isRequired_1) {
557
+ else if ((0, util_1.isNullOrUndefined)(e) && !isRequired_1) {
440
558
  return true;
441
559
  }
442
560
  else {
@@ -444,7 +562,7 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
444
562
  }
445
563
  });
446
564
  if (!validationStatus.every(function (s) { return s; })) {
447
- throw new Error("All elements in the " + name_1 + " array should be of type " + type_1 + ", validation failed for one or more elements. " + v);
565
+ throw new Error("All elements in the ".concat(name_1, " array should be of type ").concat(type_1, ", validation failed for one or more elements. ").concat(v));
448
566
  }
449
567
  }
450
568
  }
@@ -452,34 +570,34 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
452
570
  return;
453
571
  }
454
572
  else if (typeof v !== jsType_1 && v !== null) {
455
- throw new Error("Field " + name_1 + " should be of type " + jsType_1 + ", " + typeof v + " received. " + v);
573
+ throw new Error("Field ".concat(name_1, " should be of type ").concat(jsType_1, ", ").concat(typeof v, " received. ").concat(v));
456
574
  }
457
- else if (!util_1.isNullOrUndefined(v) &&
575
+ else if (!(0, util_1.isNullOrUndefined)(v) &&
458
576
  validateScalar_1 &&
459
577
  !validateScalar_1(v) // TODO: why never, TS ... why ...
460
578
  ) {
461
- throw new Error("Field " + name_1 + " should be of type " + type_1 + ", validation failed. " + v);
579
+ throw new Error("Field ".concat(name_1, " should be of type ").concat(type_1, ", validation failed. ").concat(v));
462
580
  }
463
581
  }
464
- else if (types_1.isNonModelFieldType(type_1)) {
582
+ else if ((0, types_1.isNonModelFieldType)(type_1)) {
465
583
  // do not check non model fields if undefined or null
466
- if (!util_1.isNullOrUndefined(v)) {
584
+ if (!(0, util_1.isNullOrUndefined)(v)) {
467
585
  var subNonModelDefinition_1 = schema.namespaces.user.nonModels[type_1.nonModel];
468
586
  var modelValidator_1 = validateModelFields(subNonModelDefinition_1);
469
587
  if (isArray) {
470
588
  var errorTypeText = type_1.nonModel;
471
589
  if (!isRequired_1) {
472
- errorTypeText = type_1.nonModel + " | null | undefined";
590
+ errorTypeText = "".concat(type_1.nonModel, " | null | undefined");
473
591
  }
474
592
  if (!Array.isArray(v)) {
475
- throw new Error("Field " + name_1 + " should be of type [" + errorTypeText + "], " + typeof v + " received. " + v);
593
+ throw new Error("Field ".concat(name_1, " should be of type [").concat(errorTypeText, "], ").concat(typeof v, " received. ").concat(v));
476
594
  }
477
595
  v.forEach(function (item) {
478
- if ((util_1.isNullOrUndefined(item) && isRequired_1) ||
596
+ if (((0, util_1.isNullOrUndefined)(item) && isRequired_1) ||
479
597
  (typeof item !== 'object' && typeof item !== 'undefined')) {
480
- throw new Error("All elements in the " + name_1 + " array should be of type " + type_1.nonModel + ", [" + typeof item + "] received. " + item);
598
+ throw new Error("All elements in the ".concat(name_1, " array should be of type ").concat(type_1.nonModel, ", [").concat(typeof item, "] received. ").concat(item));
481
599
  }
482
- if (!util_1.isNullOrUndefined(item)) {
600
+ if (!(0, util_1.isNullOrUndefined)(item)) {
483
601
  Object.keys(subNonModelDefinition_1.fields).forEach(function (subKey) {
484
602
  modelValidator_1(subKey, item[subKey]);
485
603
  });
@@ -488,7 +606,7 @@ var validateModelFields = function (modelDefinition) { return function (k, v) {
488
606
  }
489
607
  else {
490
608
  if (typeof v !== 'object') {
491
- throw new Error("Field " + name_1 + " should be of type " + type_1.nonModel + ", " + typeof v + " recieved. " + v);
609
+ throw new Error("Field ".concat(name_1, " should be of type ").concat(type_1.nonModel, ", ").concat(typeof v, " recieved. ").concat(v));
492
610
  }
493
611
  Object.keys(subNonModelDefinition_1.fields).forEach(function (subKey) {
494
612
  modelValidator_1(subKey, v[subKey]);
@@ -504,8 +622,8 @@ var castInstanceType = function (modelDefinition, k, v) {
504
622
  if (typeof v === 'string' &&
505
623
  (isArray ||
506
624
  type === 'AWSJSON' ||
507
- types_1.isNonModelFieldType(type) ||
508
- types_1.isModelFieldType(type))) {
625
+ (0, types_1.isNonModelFieldType)(type) ||
626
+ (0, types_1.isModelFieldType)(type))) {
509
627
  try {
510
628
  return JSON.parse(v);
511
629
  }
@@ -536,7 +654,7 @@ var initPatches = new WeakMap();
536
654
  var initializeInstance = function (init, modelDefinition, draft) {
537
655
  var modelValidator = validateModelFields(modelDefinition);
538
656
  Object.entries(init).forEach(function (_a) {
539
- var _b = tslib_1.__read(_a, 2), k = _b[0], v = _b[1];
657
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
540
658
  var parsedValue = castInstanceType(modelDefinition, k, v);
541
659
  modelValidator(k, parsedValue);
542
660
  draft[k] = parsedValue;
@@ -564,7 +682,7 @@ var initializeInstance = function (init, modelDefinition, draft) {
564
682
  var normalize = function (modelDefinition, draft) {
565
683
  var e_4, _a;
566
684
  try {
567
- for (var _b = tslib_1.__values(Object.keys(modelDefinition.fields)), _c = _b.next(); !_c.done; _c = _b.next()) {
685
+ for (var _b = __values(Object.keys(modelDefinition.fields)), _c = _b.next(); !_c.done; _c = _b.next()) {
568
686
  var k = _c.value;
569
687
  if (draft[k] === undefined)
570
688
  draft[k] = null;
@@ -586,7 +704,7 @@ var createModelClass = function (modelDefinition) {
586
704
  // set by customer code versus those set by normalization. only those fields
587
705
  // which are explicitly set by customers should be part of create mutations.
588
706
  var patches = [];
589
- var baseInstance = immer_1.produce(this, function (draft) {
707
+ var baseInstance = (0, immer_1.produce)(this, function (draft) {
590
708
  initializeInstance(init, modelDefinition, draft);
591
709
  // model is initialized inside a DataStore component (e.g. by Sync Engine, Storage Engine, etc.)
592
710
  var isInternallyInitialized = instancesMetadata.has(init);
@@ -594,18 +712,18 @@ var createModelClass = function (modelDefinition) {
594
712
  ? init
595
713
  : {};
596
714
  var _id = modelInstanceMetadata.id;
597
- if (util_1.isIdManaged(modelDefinition)) {
715
+ if ((0, util_1.isIdManaged)(modelDefinition)) {
598
716
  var isInternalModel = _id !== null && _id !== undefined;
599
717
  var id = isInternalModel
600
718
  ? _id
601
719
  : modelDefinition.syncable
602
- ? uuid_1.v4()
720
+ ? (0, uuid_1.v4)()
603
721
  : ulid();
604
722
  draft.id = id;
605
723
  }
606
- else if (util_1.isIdOptionallyManaged(modelDefinition)) {
724
+ else if ((0, util_1.isIdOptionallyManaged)(modelDefinition)) {
607
725
  // only auto-populate if the id was not provided
608
- draft.id = draft.id || uuid_1.v4();
726
+ draft.id = draft.id || (0, uuid_1.v4)();
609
727
  }
610
728
  if (!isInternallyInitialized) {
611
729
  checkReadOnlyPropertyOnCreate(draft, modelDefinition);
@@ -622,7 +740,7 @@ var createModelClass = function (modelDefinition) {
622
740
  // are only create to provide a consistent view of the data for fields pre/post sync
623
741
  // where possible. (not all fields can be normalized pre-sync, because they're generally
624
742
  // "cloud managed" fields, like createdAt and updatedAt.)
625
- var normalized = immer_1.produce(baseInstance, function (draft) {
743
+ var normalized = (0, immer_1.produce)(baseInstance, function (draft) {
626
744
  return normalize(modelDefinition, draft);
627
745
  });
628
746
  initPatches.set(normalized, patches);
@@ -636,19 +754,19 @@ var createModelClass = function (modelDefinition) {
636
754
  throw new Error(msg);
637
755
  }
638
756
  var patches = [];
639
- var model = immer_1.produce(source, function (draft) {
757
+ var model = (0, immer_1.produce)(source, function (draft) {
640
758
  fn(draft);
641
- var keyNames = util_1.extractPrimaryKeyFieldNames(modelDefinition);
759
+ var keyNames = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
642
760
  // Keys are immutable
643
761
  keyNames.forEach(function (key) {
644
762
  if (draft[key] !== source[key]) {
645
- logger.warn("copyOf() does not update PK fields. The '" + key + "' update is being ignored.", { source: source });
763
+ logger.warn("copyOf() does not update PK fields. The '".concat(key, "' update is being ignored."), { source: source });
646
764
  }
647
765
  draft[key] = source[key];
648
766
  });
649
767
  var modelValidator = validateModelFields(modelDefinition);
650
768
  Object.entries(draft).forEach(function (_a) {
651
- var _b = tslib_1.__read(_a, 2), k = _b[0], v = _b[1];
769
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
652
770
  var parsedValue = castInstanceType(modelDefinition, k, v);
653
771
  modelValidator(k, parsedValue);
654
772
  });
@@ -657,8 +775,8 @@ var createModelClass = function (modelDefinition) {
657
775
  var hasExistingPatches = modelPatchesMap.has(source);
658
776
  if (patches.length || hasExistingPatches) {
659
777
  if (hasExistingPatches) {
660
- var _a = tslib_1.__read(modelPatchesMap.get(source), 2), existingPatches = _a[0], existingSource = _a[1];
661
- var mergedPatches = util_1.mergePatches(existingSource, existingPatches, patches);
778
+ var _a = __read(modelPatchesMap.get(source), 2), existingPatches = _a[0], existingSource = _a[1];
779
+ var mergedPatches = (0, util_1.mergePatches)(existingSource, existingPatches, patches);
662
780
  modelPatchesMap.set(model, [mergedPatches, existingSource]);
663
781
  checkReadOnlyPropertyOnUpdate(mergedPatches, modelDefinition);
664
782
  }
@@ -688,7 +806,7 @@ var createModelClass = function (modelDefinition) {
688
806
  var instance = modelInstanceCreator(clazz, json);
689
807
  var modelValidator = validateModelFields(modelDefinition);
690
808
  Object.entries(instance).forEach(function (_a) {
691
- var _b = tslib_1.__read(_a, 2), k = _b[0], v = _b[1];
809
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
692
810
  modelValidator(k, v);
693
811
  });
694
812
  return attached(instance, ModelAttachment.DataStore);
@@ -703,7 +821,7 @@ var createModelClass = function (modelDefinition) {
703
821
  var allModelRelationships = relationship_1.ModelRelationship.allFrom({
704
822
  builder: clazz,
705
823
  schema: modelDefinition,
706
- pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
824
+ pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
707
825
  });
708
826
  var _loop_1 = function (relationship) {
709
827
  var field = relationship.field;
@@ -720,13 +838,13 @@ var createModelClass = function (modelDefinition) {
720
838
  var modelConstructor = Object.getPrototypeOf(model || {})
721
839
  .constructor;
722
840
  if (!isValidModelConstructor(modelConstructor)) {
723
- var msg = "Value passed to " + modelDefinition.name + "." + field + " is not a valid instance of a model";
841
+ var msg = "Value passed to ".concat(modelDefinition.name, ".").concat(field, " is not a valid instance of a model");
724
842
  logger.error(msg, { model: model });
725
843
  throw new Error(msg);
726
844
  }
727
845
  if (modelConstructor.name.toLowerCase() !==
728
846
  relationship.remoteModelConstructor.name.toLowerCase()) {
729
- var msg = "Value passed to " + modelDefinition.name + "." + field + " is not an instance of " + relationship.remoteModelConstructor.name;
847
+ var msg = "Value passed to ".concat(modelDefinition.name, ".").concat(field, " is not an instance of ").concat(relationship.remoteModelConstructor.name);
730
848
  logger.error(msg, { model: model });
731
849
  throw new Error(msg);
732
850
  }
@@ -735,7 +853,8 @@ var createModelClass = function (modelDefinition) {
735
853
  // if the relationship can be managed automagically, set the FK's
736
854
  if (relationship.isComplete) {
737
855
  for (var i = 0; i < relationship.localJoinFields.length; i++) {
738
- this[relationship.localJoinFields[i]] = model === null || model === void 0 ? void 0 : model[relationship.remoteJoinFields[i]];
856
+ this[relationship.localJoinFields[i]] =
857
+ model === null || model === void 0 ? void 0 : model[relationship.remoteJoinFields[i]];
739
858
  }
740
859
  var instanceMemos = modelInstanceAssociationsMap.has(this)
741
860
  ? modelInstanceAssociationsMap.get(this)
@@ -757,7 +876,7 @@ var createModelClass = function (modelDefinition) {
757
876
  if (!instanceMemos.hasOwnProperty(field)) {
758
877
  // before we populate the memo, we need to know where to look for relatives.
759
878
  // today, this only supports DataStore. Models aren't managed elsewhere in Amplify.
760
- if (exports.getAttachment(this) === ModelAttachment.DataStore) {
879
+ if ((0, exports.getAttachment)(this) === ModelAttachment.DataStore) {
761
880
  // when we fetch the results using a query constructed under the guidance
762
881
  // of the relationship metadata, we DO NOT AWAIT resolution. we want to
763
882
  // drop the promise into the memo's synchronously, eliminating the chance
@@ -783,7 +902,7 @@ var createModelClass = function (modelDefinition) {
783
902
  instanceMemos[field] = resultPromise.then(function (rows) {
784
903
  if (rows.length > 1) {
785
904
  // should never happen for a HAS_ONE or BELONGS_TO.
786
- var err = new Error("\n\t\t\t\t\t\t\t\t\tData integrity error.\n\t\t\t\t\t\t\t\t\tToo many records found for a HAS_ONE/BELONGS_TO field '" + modelDefinition.name + "." + field + "'\n\t\t\t\t\t\t\t\t");
905
+ var err = new Error("\n\t\t\t\t\t\t\t\t\tData integrity error.\n\t\t\t\t\t\t\t\t\tToo many records found for a HAS_ONE/BELONGS_TO field '".concat(modelDefinition.name, ".").concat(field, "'\n\t\t\t\t\t\t\t\t"));
787
906
  console.error(err);
788
907
  throw err;
789
908
  }
@@ -793,7 +912,7 @@ var createModelClass = function (modelDefinition) {
793
912
  });
794
913
  }
795
914
  }
796
- else if (exports.getAttachment(this) === ModelAttachment.API) {
915
+ else if ((0, exports.getAttachment)(this) === ModelAttachment.API) {
797
916
  throw new Error('Lazy loading from API is not yet supported!');
798
917
  }
799
918
  else {
@@ -810,7 +929,7 @@ var createModelClass = function (modelDefinition) {
810
929
  });
811
930
  };
812
931
  try {
813
- for (var allModelRelationships_1 = tslib_1.__values(allModelRelationships), allModelRelationships_1_1 = allModelRelationships_1.next(); !allModelRelationships_1_1.done; allModelRelationships_1_1 = allModelRelationships_1.next()) {
932
+ for (var allModelRelationships_1 = __values(allModelRelationships), allModelRelationships_1_1 = allModelRelationships_1.next(); !allModelRelationships_1_1.done; allModelRelationships_1_1 = allModelRelationships_1.next()) {
814
933
  var relationship = allModelRelationships_1_1.value;
815
934
  _loop_1(relationship);
816
935
  }
@@ -828,7 +947,7 @@ var createModelClass = function (modelDefinition) {
828
947
  * An eventually loaded related model instance.
829
948
  */
830
949
  var AsyncItem = /** @class */ (function (_super) {
831
- tslib_1.__extends(AsyncItem, _super);
950
+ __extends(AsyncItem, _super);
832
951
  function AsyncItem() {
833
952
  return _super !== null && _super.apply(this, arguments) || this;
834
953
  }
@@ -860,9 +979,9 @@ var AsyncCollection = /** @class */ (function () {
860
979
  var values;
861
980
  var index = 0;
862
981
  return {
863
- next: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
982
+ next: function () { return __awaiter(_this, void 0, void 0, function () {
864
983
  var result;
865
- return tslib_1.__generator(this, function (_a) {
984
+ return __generator(this, function (_a) {
866
985
  switch (_a.label) {
867
986
  case 0:
868
987
  if (!!values) return [3 /*break*/, 2];
@@ -897,45 +1016,52 @@ var AsyncCollection = /** @class */ (function () {
897
1016
  * ```
898
1017
  */
899
1018
  AsyncCollection.prototype.toArray = function (_a) {
900
- var _b = (_a === void 0 ? {} : _a).max, max = _b === void 0 ? Number.MAX_SAFE_INTEGER : _b;
901
- var e_6, _c;
902
- return tslib_1.__awaiter(this, void 0, void 0, function () {
903
- var output, i, _d, _e, element, e_6_1;
904
- return tslib_1.__generator(this, function (_f) {
905
- switch (_f.label) {
1019
+ var _b, e_6, _c, _d;
1020
+ var _e = _a === void 0 ? {} : _a, _f = _e.max, max = _f === void 0 ? Number.MAX_SAFE_INTEGER : _f;
1021
+ return __awaiter(this, void 0, void 0, function () {
1022
+ var output, i, _g, _h, _j, element, e_6_1;
1023
+ return __generator(this, function (_k) {
1024
+ switch (_k.label) {
906
1025
  case 0:
907
1026
  output = [];
908
1027
  i = 0;
909
- _f.label = 1;
1028
+ _k.label = 1;
910
1029
  case 1:
911
- _f.trys.push([1, 6, 7, 12]);
912
- _d = tslib_1.__asyncValues(this);
913
- _f.label = 2;
914
- case 2: return [4 /*yield*/, _d.next()];
1030
+ _k.trys.push([1, 6, 7, 12]);
1031
+ _g = true, _h = __asyncValues(this);
1032
+ _k.label = 2;
1033
+ case 2: return [4 /*yield*/, _h.next()];
915
1034
  case 3:
916
- if (!(_e = _f.sent(), !_e.done)) return [3 /*break*/, 5];
917
- element = _e.value;
918
- if (i < max) {
919
- output.push(element);
920
- i++;
1035
+ if (!(_j = _k.sent(), _b = _j.done, !_b)) return [3 /*break*/, 5];
1036
+ _d = _j.value;
1037
+ _g = false;
1038
+ try {
1039
+ element = _d;
1040
+ if (i < max) {
1041
+ output.push(element);
1042
+ i++;
1043
+ }
1044
+ else {
1045
+ return [3 /*break*/, 5];
1046
+ }
921
1047
  }
922
- else {
923
- return [3 /*break*/, 5];
1048
+ finally {
1049
+ _g = true;
924
1050
  }
925
- _f.label = 4;
1051
+ _k.label = 4;
926
1052
  case 4: return [3 /*break*/, 2];
927
1053
  case 5: return [3 /*break*/, 12];
928
1054
  case 6:
929
- e_6_1 = _f.sent();
1055
+ e_6_1 = _k.sent();
930
1056
  e_6 = { error: e_6_1 };
931
1057
  return [3 /*break*/, 12];
932
1058
  case 7:
933
- _f.trys.push([7, , 10, 11]);
934
- if (!(_e && !_e.done && (_c = _d.return))) return [3 /*break*/, 9];
935
- return [4 /*yield*/, _c.call(_d)];
1059
+ _k.trys.push([7, , 10, 11]);
1060
+ if (!(!_g && !_b && (_c = _h.return))) return [3 /*break*/, 9];
1061
+ return [4 /*yield*/, _c.call(_h)];
936
1062
  case 8:
937
- _f.sent();
938
- _f.label = 9;
1063
+ _k.sent();
1064
+ _k.label = 9;
939
1065
  case 9: return [3 /*break*/, 11];
940
1066
  case 10:
941
1067
  if (e_6) throw e_6.error;
@@ -954,7 +1080,7 @@ var checkReadOnlyPropertyOnCreate = function (draft, modelDefinition) {
954
1080
  var fields = modelDefinition.fields;
955
1081
  modelKeys.forEach(function (key) {
956
1082
  if (fields[key] && fields[key].isReadOnly) {
957
- throw new Error(key + " is read-only.");
1083
+ throw new Error("".concat(key, " is read-only."));
958
1084
  }
959
1085
  });
960
1086
  };
@@ -962,18 +1088,18 @@ var checkReadOnlyPropertyOnUpdate = function (patches, modelDefinition) {
962
1088
  var patchArray = patches.map(function (p) { return [p.path[0], p.value]; });
963
1089
  var fields = modelDefinition.fields;
964
1090
  patchArray.forEach(function (_a) {
965
- var _b = tslib_1.__read(_a, 2), key = _b[0], val = _b[1];
1091
+ var _b = __read(_a, 2), key = _b[0], val = _b[1];
966
1092
  if (!val || !fields[key])
967
1093
  return;
968
1094
  if (fields[key].isReadOnly) {
969
- throw new Error(key + " is read-only.");
1095
+ throw new Error("".concat(key, " is read-only."));
970
1096
  }
971
1097
  });
972
1098
  };
973
1099
  var createNonModelClass = function (typeDefinition) {
974
1100
  var clazz = /** @class */ (function () {
975
1101
  function Model(init) {
976
- var instance = immer_1.produce(this, function (draft) {
1102
+ var instance = (0, immer_1.produce)(this, function (draft) {
977
1103
  initializeInstance(init, typeDefinition, draft);
978
1104
  });
979
1105
  return instance;
@@ -982,7 +1108,7 @@ var createNonModelClass = function (typeDefinition) {
982
1108
  }());
983
1109
  clazz[immer_1.immerable] = true;
984
1110
  Object.defineProperty(clazz, 'name', { value: typeDefinition.name });
985
- util_1.registerNonModelClass(clazz);
1111
+ (0, util_1.registerNonModelClass)(clazz);
986
1112
  return clazz;
987
1113
  };
988
1114
  function isQueryOne(obj) {
@@ -991,7 +1117,7 @@ function isQueryOne(obj) {
991
1117
  function defaultConflictHandler(conflictData) {
992
1118
  var localModel = conflictData.localModel, modelConstructor = conflictData.modelConstructor, remoteModel = conflictData.remoteModel;
993
1119
  var _version = remoteModel._version;
994
- return modelInstanceCreator(modelConstructor, tslib_1.__assign(tslib_1.__assign({}, localModel), { _version: _version }));
1120
+ return modelInstanceCreator(modelConstructor, __assign(__assign({}, localModel), { _version: _version }));
995
1121
  }
996
1122
  function defaultErrorHandler(error) {
997
1123
  logger.warn(error);
@@ -1012,13 +1138,13 @@ function getModelConstructorByModelName(namespaceName, modelName) {
1012
1138
  result = storageClasses[modelName];
1013
1139
  break;
1014
1140
  default:
1015
- throw new Error("Invalid namespace: " + namespaceName);
1141
+ throw new Error("Invalid namespace: ".concat(namespaceName));
1016
1142
  }
1017
1143
  if (isValidModelConstructor(result)) {
1018
1144
  return result;
1019
1145
  }
1020
1146
  else {
1021
- var msg = "Model name is not valid for namespace. modelName: " + modelName + ", namespace: " + namespaceName;
1147
+ var msg = "Model name is not valid for namespace. modelName: ".concat(modelName, ", namespace: ").concat(namespaceName);
1022
1148
  logger.error(msg);
1023
1149
  throw new Error(msg);
1024
1150
  }
@@ -1036,23 +1162,23 @@ function getModelConstructorByModelName(namespaceName, modelName) {
1036
1162
  * @param version The expected schema version.
1037
1163
  */
1038
1164
  function checkSchemaVersion(storage, version) {
1039
- return tslib_1.__awaiter(this, void 0, void 0, function () {
1165
+ return __awaiter(this, void 0, void 0, function () {
1040
1166
  var Setting, modelDefinition;
1041
1167
  var _this = this;
1042
- return tslib_1.__generator(this, function (_a) {
1168
+ return __generator(this, function (_a) {
1043
1169
  switch (_a.label) {
1044
1170
  case 0:
1045
1171
  Setting = dataStoreClasses.Setting;
1046
1172
  modelDefinition = schema.namespaces[util_1.DATASTORE].models.Setting;
1047
- return [4 /*yield*/, storage.runExclusive(function (s) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1173
+ return [4 /*yield*/, storage.runExclusive(function (s) { return __awaiter(_this, void 0, void 0, function () {
1048
1174
  var _a, schemaVersionSetting, storedValue;
1049
- return tslib_1.__generator(this, function (_b) {
1175
+ return __generator(this, function (_b) {
1050
1176
  switch (_b.label) {
1051
1177
  case 0: return [4 /*yield*/, s.query(Setting, predicates_1.ModelPredicateCreator.createFromAST(modelDefinition, {
1052
1178
  and: { key: { eq: SETTING_SCHEMA_VERSION } },
1053
1179
  }), { page: 0, limit: 1 })];
1054
1180
  case 1:
1055
- _a = tslib_1.__read.apply(void 0, [_b.sent(), 1]), schemaVersionSetting = _a[0];
1181
+ _a = __read.apply(void 0, [_b.sent(), 1]), schemaVersionSetting = _a[0];
1056
1182
  if (!(schemaVersionSetting !== undefined &&
1057
1183
  schemaVersionSetting.value !== undefined)) return [3 /*break*/, 4];
1058
1184
  storedValue = JSON.parse(schemaVersionSetting.value);
@@ -1131,9 +1257,8 @@ var DataStore = /** @class */ (function () {
1131
1257
  function DataStore() {
1132
1258
  var _this = this;
1133
1259
  // reference to configured category instances. Used for preserving SSR context
1134
- this.Auth = auth_1.Auth;
1135
1260
  this.InternalAPI = internals_1.InternalAPI;
1136
- this.Cache = cache_1.Cache;
1261
+ this.Cache = core_1.Cache;
1137
1262
  // Non-null assertions (bang operator) have been added to most of these properties
1138
1263
  // to make TS happy. These properties are all expected to be set immediately after
1139
1264
  // construction.
@@ -1144,9 +1269,7 @@ var DataStore = /** @class */ (function () {
1144
1269
  this.syncPredicates = new WeakMap();
1145
1270
  // object that gets passed to descendent classes. Allows us to pass these down by reference
1146
1271
  this.amplifyContext = {
1147
- Auth: this.Auth,
1148
1272
  InternalAPI: this.InternalAPI,
1149
- Cache: this.Cache,
1150
1273
  };
1151
1274
  /**
1152
1275
  * **IMPORTANT!**
@@ -1179,7 +1302,7 @@ var DataStore = /** @class */ (function () {
1179
1302
  *
1180
1303
  * (Reasonable = *seconds*, not minutes.)
1181
1304
  */
1182
- this.runningProcesses = new core_1.BackgroundProcessManager();
1305
+ this.runningProcesses = new utils_2.BackgroundProcessManager();
1183
1306
  /**
1184
1307
  * Indicates what state DataStore is in.
1185
1308
  *
@@ -1194,14 +1317,14 @@ var DataStore = /** @class */ (function () {
1194
1317
  * 3. If `this.amplifyConfig.aws_appsync_graphqlEndpoint` contains a URL,
1195
1318
  * attaches a sync engine, starts it, and subscribes.
1196
1319
  */
1197
- this.start = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1320
+ this.start = function () { return __awaiter(_this, void 0, void 0, function () {
1198
1321
  var _this = this;
1199
- return tslib_1.__generator(this, function (_a) {
1322
+ return __generator(this, function (_a) {
1200
1323
  return [2 /*return*/, this.runningProcesses
1201
- .add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1324
+ .add(function () { return __awaiter(_this, void 0, void 0, function () {
1202
1325
  var aws_appsync_graphqlEndpoint, _a, fullSyncIntervalInMilliseconds;
1203
1326
  var _this = this;
1204
- return tslib_1.__generator(this, function (_b) {
1327
+ return __generator(this, function (_b) {
1205
1328
  switch (_b.label) {
1206
1329
  case 0:
1207
1330
  this.state = DataStoreState.Starting;
@@ -1239,11 +1362,8 @@ var DataStore = /** @class */ (function () {
1239
1362
  .subscribe({
1240
1363
  next: function (_a) {
1241
1364
  var type = _a.type, data = _a.data;
1242
- // In Node, we need to wait for queries to be synced to prevent returning empty arrays.
1243
1365
  // In the Browser, we can begin returning data once subscriptions are in place.
1244
- var readyType = isNode
1245
- ? sync_1.ControlMessage.SYNC_ENGINE_SYNC_QUERIES_READY
1246
- : sync_1.ControlMessage.SYNC_ENGINE_STORAGE_SUBSCRIBED;
1366
+ var readyType = sync_1.ControlMessage.SYNC_ENGINE_STORAGE_SUBSCRIBED;
1247
1367
  if (type === readyType) {
1248
1368
  _this.initResolve();
1249
1369
  }
@@ -1275,15 +1395,15 @@ var DataStore = /** @class */ (function () {
1275
1395
  .catch(this.handleAddProcError('DataStore.start()'))];
1276
1396
  });
1277
1397
  }); };
1278
- this.query = function (modelConstructor, identifierOrCriteria, paginationProducer) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1398
+ this.query = function (modelConstructor, identifierOrCriteria, paginationProducer) { return __awaiter(_this, void 0, void 0, function () {
1279
1399
  var _this = this;
1280
- return tslib_1.__generator(this, function (_a) {
1400
+ return __generator(this, function (_a) {
1281
1401
  return [2 /*return*/, this.runningProcesses
1282
- .add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1402
+ .add(function () { return __awaiter(_this, void 0, void 0, function () {
1283
1403
  var result, msg, modelDefinition, pagination, keyFields, msg, predicate, predicate, seedPredicate, predicate, returnOne;
1284
1404
  var _a;
1285
1405
  var _b;
1286
- return tslib_1.__generator(this, function (_c) {
1406
+ return __generator(this, function (_c) {
1287
1407
  switch (_c.label) {
1288
1408
  case 0: return [4 /*yield*/, this.start()];
1289
1409
  case 1:
@@ -1307,7 +1427,7 @@ var DataStore = /** @class */ (function () {
1307
1427
  throw new Error('Invalid model definition provided!');
1308
1428
  }
1309
1429
  pagination = this.processPagination(modelDefinition, paginationProducer);
1310
- keyFields = util_1.extractPrimaryKeyFieldNames(modelDefinition);
1430
+ keyFields = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
1311
1431
  if (!isQueryOne(identifierOrCriteria)) return [3 /*break*/, 3];
1312
1432
  if (keyFields.length > 1) {
1313
1433
  msg = util_1.errorMessages.queryByPkWithCompositeKeyPresent;
@@ -1320,7 +1440,7 @@ var DataStore = /** @class */ (function () {
1320
1440
  result = _c.sent();
1321
1441
  return [3 /*break*/, 9];
1322
1442
  case 3:
1323
- if (!types_1.isIdentifierObject(identifierOrCriteria, modelDefinition)) return [3 /*break*/, 5];
1443
+ if (!(0, types_1.isIdentifierObject)(identifierOrCriteria, modelDefinition)) return [3 /*break*/, 5];
1324
1444
  predicate = predicates_1.ModelPredicateCreator.createForPk(modelDefinition, identifierOrCriteria);
1325
1445
  return [4 /*yield*/, this.storage.query(modelConstructor, predicate, pagination)];
1326
1446
  case 4:
@@ -1328,26 +1448,26 @@ var DataStore = /** @class */ (function () {
1328
1448
  return [3 /*break*/, 9];
1329
1449
  case 5:
1330
1450
  if (!(!identifierOrCriteria ||
1331
- predicates_1.isPredicatesAll(identifierOrCriteria))) return [3 /*break*/, 7];
1451
+ (0, predicates_1.isPredicatesAll)(identifierOrCriteria))) return [3 /*break*/, 7];
1332
1452
  return [4 /*yield*/, ((_b = this.storage) === null || _b === void 0 ? void 0 : _b.query(modelConstructor, undefined, pagination))];
1333
1453
  case 6:
1334
1454
  result = _c.sent();
1335
1455
  return [3 /*break*/, 9];
1336
1456
  case 7:
1337
- seedPredicate = next_1.recursivePredicateFor({
1457
+ seedPredicate = (0, next_1.recursivePredicateFor)({
1338
1458
  builder: modelConstructor,
1339
1459
  schema: modelDefinition,
1340
- pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
1460
+ pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
1341
1461
  });
1342
- predicate = next_1.internals(identifierOrCriteria(seedPredicate));
1462
+ predicate = (0, next_1.internals)(identifierOrCriteria(seedPredicate));
1343
1463
  return [4 /*yield*/, predicate.fetch(this.storage)];
1344
1464
  case 8:
1345
1465
  result = (_c.sent());
1346
- result = util_1.inMemoryPagination(result, pagination);
1466
+ result = (0, util_1.inMemoryPagination)(result, pagination);
1347
1467
  _c.label = 9;
1348
1468
  case 9:
1349
1469
  returnOne = isQueryOne(identifierOrCriteria) ||
1350
- types_1.isIdentifierObject(identifierOrCriteria, modelDefinition);
1470
+ (0, types_1.isIdentifierObject)(identifierOrCriteria, modelDefinition);
1351
1471
  return [2 /*return*/, attached(returnOne ? result[0] : result, ModelAttachment.DataStore)];
1352
1472
  }
1353
1473
  });
@@ -1355,14 +1475,14 @@ var DataStore = /** @class */ (function () {
1355
1475
  .catch(this.handleAddProcError('DataStore.query()'))];
1356
1476
  });
1357
1477
  }); };
1358
- this.save = function (model, condition) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1478
+ this.save = function (model, condition) { return __awaiter(_this, void 0, void 0, function () {
1359
1479
  var _this = this;
1360
- return tslib_1.__generator(this, function (_a) {
1480
+ return __generator(this, function (_a) {
1361
1481
  return [2 /*return*/, this.runningProcesses
1362
- .add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1482
+ .add(function () { return __awaiter(_this, void 0, void 0, function () {
1363
1483
  var updatedPatchesTuple, initPatchesTuple, patchesTuple, modelConstructor, msg, modelDefinition, modelMeta, producedCondition, _a, savedModel;
1364
1484
  var _this = this;
1365
- return tslib_1.__generator(this, function (_b) {
1485
+ return __generator(this, function (_b) {
1366
1486
  switch (_b.label) {
1367
1487
  case 0: return [4 /*yield*/, this.start()];
1368
1488
  case 1:
@@ -1388,20 +1508,20 @@ var DataStore = /** @class */ (function () {
1388
1508
  modelMeta = {
1389
1509
  builder: modelConstructor,
1390
1510
  schema: modelDefinition,
1391
- pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
1511
+ pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
1392
1512
  };
1393
- return [4 /*yield*/, this.storage.runExclusive(function (s) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1513
+ return [4 /*yield*/, this.storage.runExclusive(function (s) { return __awaiter(_this, void 0, void 0, function () {
1394
1514
  var nonHasManyRelationships, nonHasManyRelationships_1, nonHasManyRelationships_1_1, relationship, queryObject, related, e_7_1;
1395
1515
  var e_7, _a;
1396
1516
  var _b;
1397
- return tslib_1.__generator(this, function (_c) {
1517
+ return __generator(this, function (_c) {
1398
1518
  switch (_c.label) {
1399
1519
  case 0:
1400
1520
  nonHasManyRelationships = relationship_1.ModelRelationship.allFrom(modelMeta).filter(function (r) { return r.type === 'BELONGS_TO'; });
1401
1521
  _c.label = 1;
1402
1522
  case 1:
1403
1523
  _c.trys.push([1, 6, 7, 8]);
1404
- nonHasManyRelationships_1 = tslib_1.__values(nonHasManyRelationships), nonHasManyRelationships_1_1 = nonHasManyRelationships_1.next();
1524
+ nonHasManyRelationships_1 = __values(nonHasManyRelationships), nonHasManyRelationships_1_1 = nonHasManyRelationships_1.next();
1405
1525
  _c.label = 2;
1406
1526
  case 2:
1407
1527
  if (!!nonHasManyRelationships_1_1.done) return [3 /*break*/, 5];
@@ -1413,10 +1533,10 @@ var DataStore = /** @class */ (function () {
1413
1533
  related = _c.sent();
1414
1534
  if (related.length === 0) {
1415
1535
  throw new Error([
1416
- "Data integrity error. You tried to save a " + modelDefinition.name + " (" + JSON.stringify(model) + ")",
1417
- "but the instance assigned to the \"" + relationship.field + "\" property",
1536
+ "Data integrity error. You tried to save a ".concat(modelDefinition.name, " (").concat(JSON.stringify(model), ")"),
1537
+ "but the instance assigned to the \"".concat(relationship.field, "\" property"),
1418
1538
  "does not exist in the local database. If you're trying to create the related",
1419
- "\"" + ((_b = relationship.remoteDefinition) === null || _b === void 0 ? void 0 : _b.name) + "\", you must save it independently first.",
1539
+ "\"".concat((_b = relationship.remoteDefinition) === null || _b === void 0 ? void 0 : _b.name, "\", you must save it independently first."),
1420
1540
  ].join(' '));
1421
1541
  }
1422
1542
  _c.label = 4;
@@ -1441,11 +1561,11 @@ var DataStore = /** @class */ (function () {
1441
1561
  case 2:
1442
1562
  _b.sent();
1443
1563
  producedCondition = condition
1444
- ? next_1.internals(condition(next_1.predicateFor(modelMeta))).toStoragePredicate()
1564
+ ? (0, next_1.internals)(condition((0, next_1.predicateFor)(modelMeta))).toStoragePredicate()
1445
1565
  : undefined;
1446
- return [4 /*yield*/, this.storage.runExclusive(function (s) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1566
+ return [4 /*yield*/, this.storage.runExclusive(function (s) { return __awaiter(_this, void 0, void 0, function () {
1447
1567
  var saved;
1448
- return tslib_1.__generator(this, function (_a) {
1568
+ return __generator(this, function (_a) {
1449
1569
  switch (_a.label) {
1450
1570
  case 0: return [4 /*yield*/, s.save(model, producedCondition, undefined, patchesTuple)];
1451
1571
  case 1:
@@ -1455,7 +1575,7 @@ var DataStore = /** @class */ (function () {
1455
1575
  });
1456
1576
  }); })];
1457
1577
  case 3:
1458
- _a = tslib_1.__read.apply(void 0, [_b.sent(), 1]), savedModel = _a[0];
1578
+ _a = __read.apply(void 0, [_b.sent(), 1]), savedModel = _a[0];
1459
1579
  return [2 /*return*/, attached(savedModel, ModelAttachment.DataStore)];
1460
1580
  }
1461
1581
  });
@@ -1489,14 +1609,14 @@ var DataStore = /** @class */ (function () {
1489
1609
  }
1490
1610
  return _this.errorHandler || defaultErrorHandler;
1491
1611
  };
1492
- this.delete = function (modelOrConstructor, identifierOrCriteria) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1612
+ this.delete = function (modelOrConstructor, identifierOrCriteria) { return __awaiter(_this, void 0, void 0, function () {
1493
1613
  var _this = this;
1494
- return tslib_1.__generator(this, function (_a) {
1614
+ return __generator(this, function (_a) {
1495
1615
  return [2 /*return*/, this.runningProcesses
1496
- .add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1616
+ .add(function () { return __awaiter(_this, void 0, void 0, function () {
1497
1617
  var condition, msg, modelConstructor, msg, modelDefinition, keyFields, msg, msg, _a, deleted, model, modelConstructor, msg, modelDefinition, pkPredicate, msg, _b, _c, deleted;
1498
1618
  var _d;
1499
- return tslib_1.__generator(this, function (_e) {
1619
+ return __generator(this, function (_e) {
1500
1620
  switch (_e.label) {
1501
1621
  case 0: return [4 /*yield*/, this.start()];
1502
1622
  case 1:
@@ -1521,7 +1641,7 @@ var DataStore = /** @class */ (function () {
1521
1641
  throw new Error('Could not find model definition for modelConstructor.');
1522
1642
  }
1523
1643
  if (typeof identifierOrCriteria === 'string') {
1524
- keyFields = util_1.extractPrimaryKeyFieldNames(modelDefinition);
1644
+ keyFields = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
1525
1645
  if (keyFields.length > 1) {
1526
1646
  msg = util_1.errorMessages.deleteByPkWithCompositeKeyPresent;
1527
1647
  logger.error(msg, { keyFields: keyFields });
@@ -1530,14 +1650,14 @@ var DataStore = /** @class */ (function () {
1530
1650
  condition = predicates_1.ModelPredicateCreator.createFromFlatEqualities(modelDefinition, (_d = {}, _d[keyFields[0]] = identifierOrCriteria, _d));
1531
1651
  }
1532
1652
  else {
1533
- if (types_1.isIdentifierObject(identifierOrCriteria, modelDefinition)) {
1653
+ if ((0, types_1.isIdentifierObject)(identifierOrCriteria, modelDefinition)) {
1534
1654
  condition = predicates_1.ModelPredicateCreator.createForPk(modelDefinition, identifierOrCriteria);
1535
1655
  }
1536
1656
  else {
1537
- condition = next_1.internals(identifierOrCriteria(next_1.predicateFor({
1657
+ condition = (0, next_1.internals)(identifierOrCriteria((0, next_1.predicateFor)({
1538
1658
  builder: modelConstructor,
1539
1659
  schema: modelDefinition,
1540
- pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
1660
+ pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
1541
1661
  }))).toStoragePredicate();
1542
1662
  }
1543
1663
  if (!condition ||
@@ -1549,7 +1669,7 @@ var DataStore = /** @class */ (function () {
1549
1669
  }
1550
1670
  return [4 /*yield*/, this.storage.delete(modelConstructor, condition)];
1551
1671
  case 2:
1552
- _a = tslib_1.__read.apply(void 0, [_e.sent(), 1]), deleted = _a[0];
1672
+ _a = __read.apply(void 0, [_e.sent(), 1]), deleted = _a[0];
1553
1673
  return [2 /*return*/, attached(deleted, ModelAttachment.DataStore)];
1554
1674
  case 3:
1555
1675
  model = modelOrConstructor;
@@ -1571,10 +1691,10 @@ var DataStore = /** @class */ (function () {
1571
1691
  logger.error(msg, { identifierOrCriteria: identifierOrCriteria });
1572
1692
  throw new Error(msg);
1573
1693
  }
1574
- condition = next_1.internals(identifierOrCriteria(next_1.predicateFor({
1694
+ condition = (0, next_1.internals)(identifierOrCriteria((0, next_1.predicateFor)({
1575
1695
  builder: modelConstructor,
1576
1696
  schema: modelDefinition,
1577
- pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
1697
+ pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
1578
1698
  }))).toStoragePredicate();
1579
1699
  }
1580
1700
  else {
@@ -1582,7 +1702,7 @@ var DataStore = /** @class */ (function () {
1582
1702
  }
1583
1703
  return [4 /*yield*/, this.storage.delete(model, condition)];
1584
1704
  case 4:
1585
- _b = tslib_1.__read.apply(void 0, [_e.sent(), 1]), _c = tslib_1.__read(_b[0], 1), deleted = _c[0];
1705
+ _b = __read.apply(void 0, [_e.sent(), 1]), _c = __read(_b[0], 1), deleted = _c[0];
1586
1706
  return [2 /*return*/, attached(deleted, ModelAttachment.DataStore)];
1587
1707
  }
1588
1708
  });
@@ -1616,7 +1736,7 @@ var DataStore = /** @class */ (function () {
1616
1736
  // observe should not accept object literal syntax
1617
1737
  if (identifierOrCriteria &&
1618
1738
  modelConstructor &&
1619
- types_1.isIdentifierObject(identifierOrCriteria, getModelDefinition(modelConstructor))) {
1739
+ (0, types_1.isIdentifierObject)(identifierOrCriteria, getModelDefinition(modelConstructor))) {
1620
1740
  var msg = util_1.errorMessages.observeWithObjectLiteral;
1621
1741
  logger.error(msg, { objectLiteral: identifierOrCriteria });
1622
1742
  throw new Error(msg);
@@ -1633,17 +1753,17 @@ var DataStore = /** @class */ (function () {
1633
1753
  }
1634
1754
  if (modelConstructor && typeof identifierOrCriteria === 'string') {
1635
1755
  var buildIdPredicate = function (seed) { return seed.id.eq(identifierOrCriteria); };
1636
- executivePredicate = next_1.internals(buildIdPredicate(buildSeedPredicate(modelConstructor)));
1756
+ executivePredicate = (0, next_1.internals)(buildIdPredicate(buildSeedPredicate(modelConstructor)));
1637
1757
  }
1638
1758
  else if (modelConstructor && typeof identifierOrCriteria === 'function') {
1639
- executivePredicate = next_1.internals(identifierOrCriteria(buildSeedPredicate(modelConstructor)));
1759
+ executivePredicate = (0, next_1.internals)(identifierOrCriteria(buildSeedPredicate(modelConstructor)));
1640
1760
  }
1641
1761
  return new zen_observable_ts_1.default(function (observer) {
1642
1762
  var source;
1643
1763
  _this.runningProcesses
1644
- .add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1764
+ .add(function () { return __awaiter(_this, void 0, void 0, function () {
1645
1765
  var _this = this;
1646
- return tslib_1.__generator(this, function (_a) {
1766
+ return __generator(this, function (_a) {
1647
1767
  switch (_a.label) {
1648
1768
  case 0: return [4 /*yield*/, this.start()];
1649
1769
  case 1:
@@ -1658,20 +1778,20 @@ var DataStore = /** @class */ (function () {
1658
1778
  .subscribe({
1659
1779
  next: function (item) {
1660
1780
  return _this.runningProcesses.isOpen &&
1661
- _this.runningProcesses.add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1781
+ _this.runningProcesses.add(function () { return __awaiter(_this, void 0, void 0, function () {
1662
1782
  var message, modelDefinition, keyFields, primaryKeysAndValues, freshElement, _a;
1663
- return tslib_1.__generator(this, function (_b) {
1783
+ return __generator(this, function (_b) {
1664
1784
  switch (_b.label) {
1665
1785
  case 0:
1666
1786
  message = item;
1667
1787
  if (!(item.opType !== 'DELETE')) return [3 /*break*/, 2];
1668
1788
  modelDefinition = getModelDefinition(item.model);
1669
- keyFields = util_1.extractPrimaryKeyFieldNames(modelDefinition);
1670
- primaryKeysAndValues = util_1.extractPrimaryKeysAndValues(item.element, keyFields);
1789
+ keyFields = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
1790
+ primaryKeysAndValues = (0, util_1.extractPrimaryKeysAndValues)(item.element, keyFields);
1671
1791
  return [4 /*yield*/, this.query(item.model, primaryKeysAndValues)];
1672
1792
  case 1:
1673
1793
  freshElement = _b.sent();
1674
- message = tslib_1.__assign(tslib_1.__assign({}, message), { element: freshElement });
1794
+ message = __assign(__assign({}, message), { element: freshElement });
1675
1795
  _b.label = 2;
1676
1796
  case 2:
1677
1797
  _a = !executivePredicate;
@@ -1703,8 +1823,8 @@ var DataStore = /** @class */ (function () {
1703
1823
  // better than no cleaner, but if the subscriber is handling the
1704
1824
  // complete() message async and not registering with the context,
1705
1825
  // this will still be problematic.
1706
- return _this.runningProcesses.addCleaner(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1707
- return tslib_1.__generator(this, function (_a) {
1826
+ return _this.runningProcesses.addCleaner(function () { return __awaiter(_this, void 0, void 0, function () {
1827
+ return __generator(this, function (_a) {
1708
1828
  if (source) {
1709
1829
  source.unsubscribe();
1710
1830
  }
@@ -1749,16 +1869,16 @@ var DataStore = /** @class */ (function () {
1749
1869
  throw new Error('Could not find model definition.');
1750
1870
  }
1751
1871
  if (model && typeof criteria === 'function') {
1752
- executivePredicate = next_1.internals(criteria(buildSeedPredicate(model)));
1872
+ executivePredicate = (0, next_1.internals)(criteria(buildSeedPredicate(model)));
1753
1873
  }
1754
- else if (predicates_1.isPredicatesAll(criteria)) {
1874
+ else if ((0, predicates_1.isPredicatesAll)(criteria)) {
1755
1875
  executivePredicate = undefined;
1756
1876
  }
1757
1877
  _this.runningProcesses
1758
- .add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1878
+ .add(function () { return __awaiter(_this, void 0, void 0, function () {
1759
1879
  var err_1;
1760
1880
  var _this = this;
1761
- return tslib_1.__generator(this, function (_a) {
1881
+ return __generator(this, function (_a) {
1762
1882
  switch (_a.label) {
1763
1883
  case 0:
1764
1884
  _a.trys.push([0, 2, , 3]);
@@ -1767,7 +1887,7 @@ var DataStore = /** @class */ (function () {
1767
1887
  // first, query and return any locally-available records
1768
1888
  (_a.sent()).forEach(function (item) {
1769
1889
  var itemModelDefinition = getModelDefinition(model);
1770
- var idOrPk = utils_1.getIdentifierValue(itemModelDefinition, item);
1890
+ var idOrPk = (0, utils_1.getIdentifierValue)(itemModelDefinition, item);
1771
1891
  items.set(idOrPk, item);
1772
1892
  });
1773
1893
  // Observe the model and send a stream of updates (debounced).
@@ -1777,14 +1897,14 @@ var DataStore = /** @class */ (function () {
1777
1897
  handle = this.observe(model).subscribe(function (_a) {
1778
1898
  var element = _a.element, model = _a.model, opType = _a.opType;
1779
1899
  return _this.runningProcesses.isOpen &&
1780
- _this.runningProcesses.add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1900
+ _this.runningProcesses.add(function () { return __awaiter(_this, void 0, void 0, function () {
1781
1901
  var itemModelDefinition, idOrPk, _a, isSynced, limit;
1782
1902
  var _b, _c;
1783
- return tslib_1.__generator(this, function (_d) {
1903
+ return __generator(this, function (_d) {
1784
1904
  switch (_d.label) {
1785
1905
  case 0:
1786
1906
  itemModelDefinition = getModelDefinition(model);
1787
- idOrPk = utils_1.getIdentifierValue(itemModelDefinition, element);
1907
+ idOrPk = (0, utils_1.getIdentifierValue)(itemModelDefinition, element);
1788
1908
  _a = executivePredicate;
1789
1909
  if (!_a) return [3 /*break*/, 2];
1790
1910
  return [4 /*yield*/, executivePredicate.matches(element)];
@@ -1853,11 +1973,11 @@ var DataStore = /** @class */ (function () {
1853
1973
  var generateSnapshot = function () {
1854
1974
  var _a, _b;
1855
1975
  var isSynced = (_b = (_a = _this.sync) === null || _a === void 0 ? void 0 : _a.getModelSyncedStatus(model)) !== null && _b !== void 0 ? _b : false;
1856
- var itemsArray = tslib_1.__spread(Array.from(items.values()), Array.from(itemsChanged.values()));
1976
+ var itemsArray = __spreadArray(__spreadArray([], __read(Array.from(items.values())), false), __read(Array.from(itemsChanged.values())), false);
1857
1977
  items.clear();
1858
1978
  itemsArray.forEach(function (item) {
1859
1979
  var itemModelDefinition = getModelDefinition(model);
1860
- var idOrPk = utils_1.getIdentifierValue(itemModelDefinition, item);
1980
+ var idOrPk = (0, utils_1.getIdentifierValue)(itemModelDefinition, item);
1861
1981
  items.set(idOrPk, item);
1862
1982
  });
1863
1983
  // remove deleted items from the final result set
@@ -1900,7 +2020,7 @@ var DataStore = /** @class */ (function () {
1900
2020
  var pagination = _this.processPagination(modelDefinition, options);
1901
2021
  var sortPredicates = predicates_1.ModelSortPredicateCreator.getPredicates(pagination.sort);
1902
2022
  if (sortPredicates.length) {
1903
- var compareFn = util_1.sortCompareFunction(sortPredicates);
2023
+ var compareFn = (0, util_1.sortCompareFunction)(sortPredicates);
1904
2024
  itemsToSort.sort(compareFn);
1905
2025
  }
1906
2026
  };
@@ -1913,18 +2033,18 @@ var DataStore = /** @class */ (function () {
1913
2033
  * @param payload The payload from the Hub event.
1914
2034
  */
1915
2035
  var hubCallback = function (_a) {
1916
- var payload = _a.payload;
1917
2036
  var _b;
2037
+ var payload = _a.payload;
1918
2038
  var event = payload.event, data = payload.data;
1919
2039
  if (event === sync_1.ControlMessage.SYNC_ENGINE_MODEL_SYNCED &&
1920
2040
  ((_b = data === null || data === void 0 ? void 0 : data.model) === null || _b === void 0 ? void 0 : _b.name) === model.name) {
1921
2041
  generateAndEmitSnapshot();
1922
- core_1.Hub.remove('datastore', hubCallback);
2042
+ hubRemove();
1923
2043
  }
1924
2044
  };
1925
- core_1.Hub.listen('datastore', hubCallback);
1926
- return _this.runningProcesses.addCleaner(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1927
- return tslib_1.__generator(this, function (_a) {
2045
+ var hubRemove = core_1.Hub.listen('datastore', hubCallback);
2046
+ return _this.runningProcesses.addCleaner(function () { return __awaiter(_this, void 0, void 0, function () {
2047
+ return __generator(this, function (_a) {
1928
2048
  if (handle) {
1929
2049
  handle.unsubscribe();
1930
2050
  }
@@ -1934,12 +2054,22 @@ var DataStore = /** @class */ (function () {
1934
2054
  });
1935
2055
  };
1936
2056
  this.configure = function (config) {
2057
+ var _a;
1937
2058
  if (config === void 0) { config = {}; }
1938
- _this.amplifyContext.Auth = _this.Auth;
1939
2059
  _this.amplifyContext.InternalAPI = _this.InternalAPI;
1940
- _this.amplifyContext.Cache = _this.Cache;
1941
- var configDataStore = config.DataStore, configAuthModeStrategyType = config.authModeStrategyType, configConflictHandler = config.conflictHandler, configErrorHandler = config.errorHandler, configMaxRecordsToSync = config.maxRecordsToSync, configSyncPageSize = config.syncPageSize, configFullSyncInterval = config.fullSyncInterval, configSyncExpressions = config.syncExpressions, configAuthProviders = config.authProviders, configStorageAdapter = config.storageAdapter, configFromAmplify = tslib_1.__rest(config, ["DataStore", "authModeStrategyType", "conflictHandler", "errorHandler", "maxRecordsToSync", "syncPageSize", "fullSyncInterval", "syncExpressions", "authProviders", "storageAdapter"]);
1942
- _this.amplifyConfig = tslib_1.__assign(tslib_1.__assign({}, configFromAmplify), _this.amplifyConfig);
2060
+ var configDataStore = config.DataStore, configAuthModeStrategyType = config.authModeStrategyType, configConflictHandler = config.conflictHandler, configErrorHandler = config.errorHandler, configMaxRecordsToSync = config.maxRecordsToSync, configSyncPageSize = config.syncPageSize, configFullSyncInterval = config.fullSyncInterval, configSyncExpressions = config.syncExpressions, configAuthProviders = config.authProviders, configStorageAdapter = config.storageAdapter, configFromAmplify = __rest(config, ["DataStore", "authModeStrategyType", "conflictHandler", "errorHandler", "maxRecordsToSync", "syncPageSize", "fullSyncInterval", "syncExpressions", "authProviders", "storageAdapter"]);
2061
+ var apiKey = '';
2062
+ var currentAppSyncConfig = (_a = core_1.Amplify.getConfig().API) === null || _a === void 0 ? void 0 : _a.AppSync;
2063
+ if ((currentAppSyncConfig === null || currentAppSyncConfig === void 0 ? void 0 : currentAppSyncConfig.defaultAuthMode.type) === 'apiKey') {
2064
+ apiKey = currentAppSyncConfig.defaultAuthMode.apiKey;
2065
+ }
2066
+ var appSyncConfig = {
2067
+ aws_appsync_graphqlEndpoint: currentAppSyncConfig === null || currentAppSyncConfig === void 0 ? void 0 : currentAppSyncConfig.endpoint,
2068
+ aws_appsync_authenticationType: currentAppSyncConfig === null || currentAppSyncConfig === void 0 ? void 0 : currentAppSyncConfig.defaultAuthMode.type,
2069
+ aws_appsync_region: currentAppSyncConfig === null || currentAppSyncConfig === void 0 ? void 0 : currentAppSyncConfig.region,
2070
+ aws_appsync_apiKey: apiKey,
2071
+ };
2072
+ _this.amplifyConfig = __assign(__assign(__assign({}, _this.amplifyConfig), configFromAmplify), (currentAppSyncConfig && appSyncConfig));
1943
2073
  _this.conflictHandler = _this.setConflictHandler(config);
1944
2074
  _this.errorHandler = _this.setErrorHandler(config);
1945
2075
  var authModeStrategyType = (configDataStore && configDataStore.authModeStrategyType) ||
@@ -1947,7 +2077,7 @@ var DataStore = /** @class */ (function () {
1947
2077
  types_1.AuthModeStrategyType.DEFAULT;
1948
2078
  switch (authModeStrategyType) {
1949
2079
  case types_1.AuthModeStrategyType.MULTI_AUTH:
1950
- _this.authModeStrategy = authModeStrategies_1.multiAuthStrategy(_this.amplifyContext);
2080
+ _this.authModeStrategy = (0, authModeStrategies_1.multiAuthStrategy)(_this.amplifyContext);
1951
2081
  break;
1952
2082
  case types_1.AuthModeStrategyType.DEFAULT:
1953
2083
  _this.authModeStrategy = authModeStrategies_1.defaultAuthStrategy;
@@ -2011,7 +2141,7 @@ var DataStore = /** @class */ (function () {
2011
2141
  var handler = function (err) {
2012
2142
  if (err.message.startsWith('BackgroundManagerNotOpenError')) {
2013
2143
  throw new Error([
2014
- "DataStoreStateError: Tried to execute `" + operation + "` while DataStore was \"" + _this.state + "\".",
2144
+ "DataStoreStateError: Tried to execute `".concat(operation, "` while DataStore was \"").concat(_this.state, "\"."),
2015
2145
  "This can only be done while DataStore is \"Started\" or \"Stopped\". To remedy:",
2016
2146
  'Ensure all calls to `stop()` and `clear()` have completed first.',
2017
2147
  'If this is not possible, retry the operation until it succeeds.',
@@ -2032,8 +2162,8 @@ var DataStore = /** @class */ (function () {
2032
2162
  * DataStore, such as `query()`, `save()`, or `delete()`.
2033
2163
  */
2034
2164
  DataStore.prototype.clear = function () {
2035
- return tslib_1.__awaiter(this, void 0, void 0, function () {
2036
- return tslib_1.__generator(this, function (_a) {
2165
+ return __awaiter(this, void 0, void 0, function () {
2166
+ return __generator(this, function (_a) {
2037
2167
  switch (_a.label) {
2038
2168
  case 0:
2039
2169
  checkSchemaInitialized();
@@ -2080,8 +2210,8 @@ var DataStore = /** @class */ (function () {
2080
2210
  * running queries and terminates subscriptions."
2081
2211
  */
2082
2212
  DataStore.prototype.stop = function () {
2083
- return tslib_1.__awaiter(this, void 0, void 0, function () {
2084
- return tslib_1.__generator(this, function (_a) {
2213
+ return __awaiter(this, void 0, void 0, function () {
2214
+ return __generator(this, function (_a) {
2085
2215
  switch (_a.label) {
2086
2216
  case 0:
2087
2217
  this.state = DataStoreState.Stopping;
@@ -2154,18 +2284,18 @@ var DataStore = /** @class */ (function () {
2154
2284
  * SchemaModel -> predicate to use during sync.
2155
2285
  */
2156
2286
  DataStore.prototype.processSyncExpressions = function () {
2157
- return tslib_1.__awaiter(this, void 0, void 0, function () {
2287
+ return __awaiter(this, void 0, void 0, function () {
2158
2288
  var syncPredicates;
2159
2289
  var _this = this;
2160
- return tslib_1.__generator(this, function (_a) {
2290
+ return __generator(this, function (_a) {
2161
2291
  switch (_a.label) {
2162
2292
  case 0:
2163
2293
  if (!this.syncExpressions || !this.syncExpressions.length) {
2164
2294
  return [2 /*return*/, new WeakMap()];
2165
2295
  }
2166
- return [4 /*yield*/, Promise.all(this.syncExpressions.map(function (syncExpression) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
2296
+ return [4 /*yield*/, Promise.all(this.syncExpressions.map(function (syncExpression) { return __awaiter(_this, void 0, void 0, function () {
2167
2297
  var _a, modelConstructor, conditionProducer, modelDefinition, condition, predicate;
2168
- return tslib_1.__generator(this, function (_b) {
2298
+ return __generator(this, function (_b) {
2169
2299
  switch (_b.label) {
2170
2300
  case 0: return [4 /*yield*/, syncExpression];
2171
2301
  case 1:
@@ -2174,13 +2304,13 @@ var DataStore = /** @class */ (function () {
2174
2304
  return [4 /*yield*/, this.unwrapPromise(conditionProducer)];
2175
2305
  case 2:
2176
2306
  condition = _b.sent();
2177
- if (predicates_1.isPredicatesAll(condition)) {
2307
+ if ((0, predicates_1.isPredicatesAll)(condition)) {
2178
2308
  return [2 /*return*/, [modelDefinition, null]];
2179
2309
  }
2180
- predicate = next_1.internals(condition(next_1.predicateFor({
2310
+ predicate = (0, next_1.internals)(condition((0, next_1.predicateFor)({
2181
2311
  builder: modelConstructor,
2182
2312
  schema: modelDefinition,
2183
- pkField: util_1.extractPrimaryKeyFieldNames(modelDefinition),
2313
+ pkField: (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition),
2184
2314
  }))).toStoragePredicate();
2185
2315
  return [2 /*return*/, [modelDefinition, predicate]];
2186
2316
  }
@@ -2194,9 +2324,9 @@ var DataStore = /** @class */ (function () {
2194
2324
  });
2195
2325
  };
2196
2326
  DataStore.prototype.unwrapPromise = function (conditionProducer) {
2197
- return tslib_1.__awaiter(this, void 0, void 0, function () {
2327
+ return __awaiter(this, void 0, void 0, function () {
2198
2328
  var condition, error_1;
2199
- return tslib_1.__generator(this, function (_a) {
2329
+ return __generator(this, function (_a) {
2200
2330
  switch (_a.label) {
2201
2331
  case 0:
2202
2332
  _a.trys.push([0, 2, , 3]);
@@ -2217,10 +2347,10 @@ var DataStore = /** @class */ (function () {
2217
2347
  };
2218
2348
  DataStore.prototype.weakMapFromEntries = function (entries) {
2219
2349
  return entries.reduce(function (map, _a) {
2220
- var _b = tslib_1.__read(_a, 2), modelDefinition = _b[0], predicate = _b[1];
2350
+ var _b = __read(_a, 2), modelDefinition = _b[0], predicate = _b[1];
2221
2351
  if (map.has(modelDefinition)) {
2222
2352
  var name_2 = modelDefinition.name;
2223
- logger.warn("You can only utilize one Sync Expression per model.\n Subsequent sync expressions for the " + name_2 + " model will be ignored.");
2353
+ logger.warn("You can only utilize one Sync Expression per model.\n Subsequent sync expressions for the ".concat(name_2, " model will be ignored."));
2224
2354
  return map;
2225
2355
  }
2226
2356
  if (predicate) {
@@ -2239,8 +2369,8 @@ var DataStore = /** @class */ (function () {
2239
2369
  if (sessionId) {
2240
2370
  var aws_appsync_graphqlEndpoint = this.amplifyConfig.aws_appsync_graphqlEndpoint;
2241
2371
  var appSyncUrl = aws_appsync_graphqlEndpoint.split('/')[2];
2242
- var _a = tslib_1.__read(appSyncUrl.split('.'), 1), appSyncId = _a[0];
2243
- return sessionId + "-" + appSyncId;
2372
+ var _a = __read(appSyncUrl.split('.'), 1), appSyncId = _a[0];
2373
+ return "".concat(sessionId, "-").concat(appSyncId);
2244
2374
  }
2245
2375
  }
2246
2376
  catch (_b) { }
@@ -2251,5 +2381,9 @@ var DataStore = /** @class */ (function () {
2251
2381
  exports.DataStoreClass = DataStore;
2252
2382
  var instance = new DataStore();
2253
2383
  exports.DataStore = instance;
2254
- core_1.Amplify.register(instance);
2255
- //# sourceMappingURL=datastore.js.map
2384
+ instance.configure({});
2385
+ core_1.Hub.listen('core', function (capsule) {
2386
+ if (capsule.payload.event === 'configure') {
2387
+ instance.configure({});
2388
+ }
2389
+ });