@aws-amplify/datastore 5.0.32 → 5.0.33-s-auth.30d0cd2.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 (149) hide show
  1. package/dist/cjs/authModeStrategies/multiAuthStrategy.js +1 -1
  2. package/dist/cjs/authModeStrategies/multiAuthStrategy.js.map +1 -1
  3. package/dist/cjs/datastore/datastore.js +46 -41
  4. package/dist/cjs/datastore/datastore.js.map +1 -1
  5. package/dist/cjs/index.js +3 -1
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/cjs/predicates/index.js +1 -0
  8. package/dist/cjs/predicates/index.js.map +1 -1
  9. package/dist/cjs/predicates/next.js +13 -12
  10. package/dist/cjs/predicates/next.js.map +1 -1
  11. package/dist/cjs/predicates/sort.js +2 -2
  12. package/dist/cjs/predicates/sort.js.map +1 -1
  13. package/dist/cjs/storage/adapter/AsyncStorageAdapter.js +21 -18
  14. package/dist/cjs/storage/adapter/AsyncStorageAdapter.js.map +1 -1
  15. package/dist/cjs/storage/adapter/AsyncStorageDatabase.js +10 -9
  16. package/dist/cjs/storage/adapter/AsyncStorageDatabase.js.map +1 -1
  17. package/dist/cjs/storage/adapter/InMemoryStore.js +4 -1
  18. package/dist/cjs/storage/adapter/InMemoryStore.js.map +1 -1
  19. package/dist/cjs/storage/adapter/IndexedDBAdapter.js +21 -23
  20. package/dist/cjs/storage/adapter/IndexedDBAdapter.js.map +1 -1
  21. package/dist/cjs/storage/adapter/StorageAdapterBase.js +7 -7
  22. package/dist/cjs/storage/adapter/StorageAdapterBase.js.map +1 -1
  23. package/dist/cjs/storage/adapter/getDefaultAdapter/index.js +4 -1
  24. package/dist/cjs/storage/adapter/getDefaultAdapter/index.js.map +1 -1
  25. package/dist/cjs/storage/adapter/getDefaultAdapter/index.native.js +1 -0
  26. package/dist/cjs/storage/adapter/getDefaultAdapter/index.native.js.map +1 -1
  27. package/dist/cjs/storage/relationship.js +1 -0
  28. package/dist/cjs/storage/relationship.js.map +1 -1
  29. package/dist/cjs/storage/storage.js +14 -14
  30. package/dist/cjs/storage/storage.js.map +1 -1
  31. package/dist/cjs/sync/datastoreConnectivity.js +0 -3
  32. package/dist/cjs/sync/datastoreConnectivity.js.map +1 -1
  33. package/dist/cjs/sync/index.js +47 -43
  34. package/dist/cjs/sync/index.js.map +1 -1
  35. package/dist/cjs/sync/merger.js +1 -1
  36. package/dist/cjs/sync/merger.js.map +1 -1
  37. package/dist/cjs/sync/outbox.js +19 -17
  38. package/dist/cjs/sync/outbox.js.map +1 -1
  39. package/dist/cjs/sync/processors/errorMaps.js.map +1 -1
  40. package/dist/cjs/sync/processors/mutation.js +31 -28
  41. package/dist/cjs/sync/processors/mutation.js.map +1 -1
  42. package/dist/cjs/sync/processors/subscription.js +21 -12
  43. package/dist/cjs/sync/processors/subscription.js.map +1 -1
  44. package/dist/cjs/sync/processors/sync.js +25 -21
  45. package/dist/cjs/sync/processors/sync.js.map +1 -1
  46. package/dist/cjs/sync/utils.js +20 -21
  47. package/dist/cjs/sync/utils.js.map +1 -1
  48. package/dist/cjs/types.js +1 -0
  49. package/dist/cjs/types.js.map +1 -1
  50. package/dist/cjs/util.js +46 -25
  51. package/dist/cjs/util.js.map +1 -1
  52. package/dist/esm/authModeStrategies/multiAuthStrategy.d.ts +1 -1
  53. package/dist/esm/authModeStrategies/multiAuthStrategy.mjs +1 -1
  54. package/dist/esm/authModeStrategies/multiAuthStrategy.mjs.map +1 -1
  55. package/dist/esm/datastore/datastore.d.ts +4 -6
  56. package/dist/esm/datastore/datastore.mjs +42 -34
  57. package/dist/esm/datastore/datastore.mjs.map +1 -1
  58. package/dist/esm/index.d.ts +1 -1
  59. package/dist/esm/index.mjs +2 -2
  60. package/dist/esm/index.mjs.map +1 -1
  61. package/dist/esm/predicates/index.mjs +1 -0
  62. package/dist/esm/predicates/index.mjs.map +1 -1
  63. package/dist/esm/predicates/next.d.ts +7 -7
  64. package/dist/esm/predicates/next.mjs +13 -12
  65. package/dist/esm/predicates/next.mjs.map +1 -1
  66. package/dist/esm/predicates/sort.d.ts +1 -1
  67. package/dist/esm/predicates/sort.mjs +2 -2
  68. package/dist/esm/predicates/sort.mjs.map +1 -1
  69. package/dist/esm/storage/adapter/AsyncStorageAdapter.d.ts +1 -1
  70. package/dist/esm/storage/adapter/AsyncStorageAdapter.mjs +21 -18
  71. package/dist/esm/storage/adapter/AsyncStorageAdapter.mjs.map +1 -1
  72. package/dist/esm/storage/adapter/AsyncStorageDatabase.mjs +10 -9
  73. package/dist/esm/storage/adapter/AsyncStorageDatabase.mjs.map +1 -1
  74. package/dist/esm/storage/adapter/InMemoryStore.mjs +4 -1
  75. package/dist/esm/storage/adapter/InMemoryStore.mjs.map +1 -1
  76. package/dist/esm/storage/adapter/IndexedDBAdapter.mjs +21 -23
  77. package/dist/esm/storage/adapter/IndexedDBAdapter.mjs.map +1 -1
  78. package/dist/esm/storage/adapter/StorageAdapterBase.d.ts +2 -2
  79. package/dist/esm/storage/adapter/StorageAdapterBase.mjs +7 -7
  80. package/dist/esm/storage/adapter/StorageAdapterBase.mjs.map +1 -1
  81. package/dist/esm/storage/adapter/getDefaultAdapter/index.mjs +3 -1
  82. package/dist/esm/storage/adapter/getDefaultAdapter/index.mjs.map +1 -1
  83. package/dist/esm/storage/adapter/getDefaultAdapter/index.native.mjs +1 -0
  84. package/dist/esm/storage/adapter/getDefaultAdapter/index.native.mjs.map +1 -1
  85. package/dist/esm/storage/adapter/index.d.ts +1 -1
  86. package/dist/esm/storage/relationship.mjs +1 -0
  87. package/dist/esm/storage/relationship.mjs.map +1 -1
  88. package/dist/esm/storage/storage.d.ts +11 -11
  89. package/dist/esm/storage/storage.mjs +10 -10
  90. package/dist/esm/storage/storage.mjs.map +1 -1
  91. package/dist/esm/sync/datastoreConnectivity.d.ts +2 -2
  92. package/dist/esm/sync/datastoreConnectivity.mjs +0 -3
  93. package/dist/esm/sync/datastoreConnectivity.mjs.map +1 -1
  94. package/dist/esm/sync/index.d.ts +3 -3
  95. package/dist/esm/sync/index.mjs +47 -43
  96. package/dist/esm/sync/index.mjs.map +1 -1
  97. package/dist/esm/sync/merger.d.ts +1 -1
  98. package/dist/esm/sync/merger.mjs +1 -1
  99. package/dist/esm/sync/merger.mjs.map +1 -1
  100. package/dist/esm/sync/outbox.d.ts +4 -4
  101. package/dist/esm/sync/outbox.mjs +19 -17
  102. package/dist/esm/sync/outbox.mjs.map +1 -1
  103. package/dist/esm/sync/processors/errorMaps.mjs.map +1 -1
  104. package/dist/esm/sync/processors/mutation.d.ts +5 -5
  105. package/dist/esm/sync/processors/mutation.mjs +31 -28
  106. package/dist/esm/sync/processors/mutation.mjs.map +1 -1
  107. package/dist/esm/sync/processors/subscription.d.ts +1 -1
  108. package/dist/esm/sync/processors/subscription.mjs +21 -12
  109. package/dist/esm/sync/processors/subscription.mjs.map +1 -1
  110. package/dist/esm/sync/processors/sync.d.ts +3 -3
  111. package/dist/esm/sync/processors/sync.mjs +13 -9
  112. package/dist/esm/sync/processors/sync.mjs.map +1 -1
  113. package/dist/esm/sync/utils.d.ts +11 -13
  114. package/dist/esm/sync/utils.mjs +20 -21
  115. package/dist/esm/sync/utils.mjs.map +1 -1
  116. package/dist/esm/types.d.ts +121 -131
  117. package/dist/esm/types.mjs +3 -2
  118. package/dist/esm/types.mjs.map +1 -1
  119. package/dist/esm/util.d.ts +5 -5
  120. package/dist/esm/util.mjs +46 -25
  121. package/dist/esm/util.mjs.map +1 -1
  122. package/package.json +74 -73
  123. package/src/authModeStrategies/multiAuthStrategy.ts +8 -4
  124. package/src/datastore/datastore.ts +145 -123
  125. package/src/index.ts +10 -8
  126. package/src/predicates/index.ts +10 -2
  127. package/src/predicates/next.ts +39 -28
  128. package/src/predicates/sort.ts +23 -26
  129. package/src/storage/adapter/AsyncStorageAdapter.ts +43 -25
  130. package/src/storage/adapter/AsyncStorageDatabase.ts +18 -10
  131. package/src/storage/adapter/InMemoryStore.ts +5 -1
  132. package/src/storage/adapter/IndexedDBAdapter.ts +50 -37
  133. package/src/storage/adapter/StorageAdapterBase.ts +24 -18
  134. package/src/storage/adapter/getDefaultAdapter/index.native.ts +1 -0
  135. package/src/storage/adapter/getDefaultAdapter/index.ts +4 -1
  136. package/src/storage/adapter/index.ts +2 -2
  137. package/src/storage/relationship.ts +5 -1
  138. package/src/storage/storage.ts +38 -30
  139. package/src/sync/datastoreConnectivity.ts +4 -6
  140. package/src/sync/index.ts +228 -230
  141. package/src/sync/merger.ts +4 -3
  142. package/src/sync/outbox.ts +26 -24
  143. package/src/sync/processors/errorMaps.ts +5 -0
  144. package/src/sync/processors/mutation.ts +80 -72
  145. package/src/sync/processors/subscription.ts +69 -53
  146. package/src/sync/processors/sync.ts +49 -37
  147. package/src/sync/utils.ts +60 -41
  148. package/src/types.ts +165 -165
  149. package/src/util.ts +89 -53
@@ -1,6 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { ULID } from 'ulid';
4
+
4
5
  import {
5
6
  ModelInstanceMetadata,
6
7
  OpType,
@@ -13,6 +14,7 @@ import {
13
14
  indexNameFromKeys,
14
15
  monotonicUlidFactory,
15
16
  } from '../../util';
17
+
16
18
  import { createInMemoryStore } from './InMemoryStore';
17
19
 
18
20
  const DB_NAME = '@AmplifyDatastore';
@@ -72,12 +74,12 @@ class AsyncStorageDatabase {
72
74
  if (id === undefined) {
73
75
  // It is an old entry (without ulid). Need to migrate to new key format
74
76
 
75
- const id = ulidOrId;
77
+ const resolvedId = ulidOrId;
76
78
 
77
79
  const newUlid = this.getMonotonicFactory(storeName)();
78
80
 
79
- const oldKey = this.getLegacyKeyForItem(storeName, id);
80
- const newKey = this.getKeyForItem(storeName, id, newUlid);
81
+ const oldKey = this.getLegacyKeyForItem(storeName, resolvedId);
82
+ const newKey = this.getKeyForItem(storeName, resolvedId, newUlid);
81
83
 
82
84
  const item = await this.storage.getItem(oldKey);
83
85
 
@@ -161,7 +163,7 @@ class AsyncStorageDatabase {
161
163
  );
162
164
 
163
165
  allItemsKeys.push(key);
164
- itemsMap[key] = { ulid, model: <T>(<unknown>item) };
166
+ itemsMap[key] = { ulid, model: item as unknown as T };
165
167
 
166
168
  if (_deleted) {
167
169
  keysToDelete.add(key);
@@ -180,6 +182,7 @@ class AsyncStorageDatabase {
180
182
  await new Promise<void>((resolve, reject) => {
181
183
  if (keysToDelete.size === 0) {
182
184
  resolve();
185
+
183
186
  return;
184
187
  }
185
188
 
@@ -208,6 +211,7 @@ class AsyncStorageDatabase {
208
211
  await new Promise<void>((resolve, reject) => {
209
212
  if (keysToSave.size === 0) {
210
213
  resolve();
214
+
211
215
  return;
212
216
  }
213
217
 
@@ -258,6 +262,7 @@ class AsyncStorageDatabase {
258
262
  const itemKey = this.getKeyForItem(storeName, keyValuePath, ulid);
259
263
  const recordAsString = await this.storage.getItem(itemKey);
260
264
  const record = recordAsString && JSON.parse(recordAsString);
265
+
261
266
  return record;
262
267
  }
263
268
 
@@ -267,14 +272,17 @@ class AsyncStorageDatabase {
267
272
  const [itemId, ulid] =
268
273
  firstOrLast === QueryOne.FIRST
269
274
  ? (() => {
270
- let id: string, ulid: string;
271
- for ([id, ulid] of collection) break; // Get first element of the set
272
- return [id!, ulid!];
275
+ let resolvedId: string, resolvedUlid: string;
276
+ // eslint-disable-next-line no-unreachable-loop
277
+ for ([resolvedId, resolvedUlid] of collection) break; // Get first element of the set
278
+
279
+ return [resolvedId!, resolvedUlid!];
273
280
  })()
274
281
  : (() => {
275
- let id: string, ulid: string;
276
- for ([id, ulid] of collection); // Get last element of the set
277
- return [id!, ulid!];
282
+ let resolvedId: string, resolvedUlid: string;
283
+ for ([resolvedId, resolvedUlid] of collection); // Get last element of the set
284
+
285
+ return [resolvedId!, resolvedUlid!];
278
286
  })();
279
287
  const itemKey = this.getKeyForItem(storeName, itemId, ulid);
280
288
 
@@ -9,7 +9,11 @@ export class InMemoryStore {
9
9
 
10
10
  multiGet = async (keys: string[]) => {
11
11
  return keys.reduce(
12
- (res, k) => (res.push([k, this.db.get(k)!]), res),
12
+ (res, k) => {
13
+ res.push([k, this.db.get(k)!]);
14
+
15
+ return res;
16
+ },
13
17
  [] as [string, string][],
14
18
  );
15
19
  };
@@ -1,9 +1,9 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import * as idb from 'idb';
4
+ import { ConsoleLogger } from '@aws-amplify/core';
5
+
4
6
  import {
5
- isPredicateObj,
6
- isPredicateGroup,
7
7
  ModelInstanceMetadata,
8
8
  ModelPredicate,
9
9
  OpType,
@@ -13,18 +13,20 @@ import {
13
13
  PredicateObject,
14
14
  PredicatesGroup,
15
15
  QueryOne,
16
+ isPredicateGroup,
17
+ isPredicateObj,
16
18
  } from '../../types';
17
19
  import {
20
+ getStorename,
21
+ inMemoryPagination,
18
22
  isPrivateMode,
23
+ isSafariCompatabilityMode,
24
+ keysEqual,
19
25
  traverseModel,
20
26
  validatePredicate,
21
- inMemoryPagination,
22
- keysEqual,
23
- getStorename,
24
- isSafariCompatabilityMode,
25
27
  } from '../../util';
28
+
26
29
  import { StorageAdapterBase } from './StorageAdapterBase';
27
- import { ConsoleLogger } from '@aws-amplify/core';
28
30
 
29
31
  const logger = new ConsoleLogger('DataStore');
30
32
 
@@ -55,7 +57,7 @@ const DB_VERSION = 3;
55
57
 
56
58
  class IndexedDBAdapter extends StorageAdapterBase {
57
59
  protected db!: idb.IDBPDatabase;
58
- private safariCompatabilityMode: boolean = false;
60
+ private safariCompatabilityMode = false;
59
61
 
60
62
  // checks are called by StorageAdapterBase class
61
63
  protected async preSetUpChecks() {
@@ -77,7 +79,7 @@ class IndexedDBAdapter extends StorageAdapterBase {
77
79
  * @returns IDB Database instance
78
80
  */
79
81
  protected async initDb(): Promise<idb.IDBPDatabase> {
80
- return await idb.openDB(this.dbName, DB_VERSION, {
82
+ return idb.openDB(this.dbName, DB_VERSION, {
81
83
  upgrade: async (db, oldVersion, newVersion, txn) => {
82
84
  // create new database
83
85
  if (oldVersion === 0) {
@@ -171,8 +173,6 @@ class IndexedDBAdapter extends StorageAdapterBase {
171
173
  txn.abort();
172
174
  throw error;
173
175
  }
174
-
175
- return;
176
176
  }
177
177
  },
178
178
  });
@@ -194,7 +194,7 @@ class IndexedDBAdapter extends StorageAdapterBase {
194
194
 
195
195
  const result = await index.get(this.canonicalKeyPath(keyArr));
196
196
 
197
- return <T>result;
197
+ return result as T;
198
198
  }
199
199
 
200
200
  async clear(): Promise<void> {
@@ -228,22 +228,25 @@ class IndexedDBAdapter extends StorageAdapterBase {
228
228
 
229
229
  const result: [T, OpType.INSERT | OpType.UPDATE][] = [];
230
230
  for await (const resItem of connectionStoreNames) {
231
- const { storeName, item, instance, keys } = resItem;
232
- const store = tx.objectStore(storeName);
231
+ const { storeName: storeNameForRestItem, item, instance, keys } = resItem;
232
+ const storeForRestItem = tx.objectStore(storeNameForRestItem);
233
233
 
234
234
  const itemKeyValues: string[] = keys.map(key => item[key]);
235
235
 
236
- const fromDB = <T>await this._get(store, itemKeyValues);
237
- const opType: OpType = fromDB ? OpType.UPDATE : OpType.INSERT;
236
+ const fromDBForRestItem = (await this._get(
237
+ storeForRestItem,
238
+ itemKeyValues,
239
+ )) as T;
240
+ const opType: OpType = fromDBForRestItem ? OpType.UPDATE : OpType.INSERT;
238
241
 
239
242
  if (
240
243
  keysEqual(itemKeyValues, modelKeyValues) ||
241
244
  opType === OpType.INSERT
242
245
  ) {
243
- const key = await store
246
+ const key = await storeForRestItem
244
247
  .index('byPk')
245
248
  .getKey(this.canonicalKeyPath(itemKeyValues));
246
- await store.put(item, key);
249
+ await storeForRestItem.put(item, key);
247
250
  result.push([instance, opType]);
248
251
  }
249
252
  }
@@ -281,16 +284,19 @@ class IndexedDBAdapter extends StorageAdapterBase {
281
284
  //
282
285
  if (queryByKey) {
283
286
  const record = await this.getByKey(storeName, queryByKey);
287
+
284
288
  return record ? [record] : [];
285
289
  }
286
290
 
287
291
  if (predicates) {
288
292
  const filtered = await this.filterOnPredicate(storeName, predicates);
293
+
289
294
  return this.inMemoryPagination(filtered, pagination);
290
295
  }
291
296
 
292
297
  if (hasSort) {
293
298
  const all = await this.getAll(storeName);
299
+
294
300
  return this.inMemoryPagination(all, pagination);
295
301
  }
296
302
 
@@ -301,7 +307,7 @@ class IndexedDBAdapter extends StorageAdapterBase {
301
307
  return this.getAll(storeName);
302
308
  })()) as T[];
303
309
 
304
- return await this.load(namespaceName, modelConstructor.name, records);
310
+ return this.load(namespaceName, modelConstructor.name, records);
305
311
  }
306
312
 
307
313
  async queryOne<T extends PersistentModel>(
@@ -316,7 +322,7 @@ class IndexedDBAdapter extends StorageAdapterBase {
316
322
  .objectStore(storeName)
317
323
  .openCursor(undefined, firstOrLast === QueryOne.FIRST ? 'next' : 'prev');
318
324
 
319
- const result = cursor ? <T>cursor.value : undefined;
325
+ const result = cursor ? (cursor.value as T) : undefined;
320
326
 
321
327
  return result && this.modelInstanceCreator(modelConstructor, result);
322
328
  }
@@ -337,7 +343,7 @@ class IndexedDBAdapter extends StorageAdapterBase {
337
343
  const result: [T, OpType][] = [];
338
344
 
339
345
  const txn = this.db.transaction(storeName, 'readwrite');
340
- const store = txn.store;
346
+ const { store } = txn;
341
347
 
342
348
  for (const item of items) {
343
349
  const model = this.modelInstanceCreator(modelConstructor, item);
@@ -358,18 +364,23 @@ class IndexedDBAdapter extends StorageAdapterBase {
358
364
  const key = await index.getKey(this.canonicalKeyPath(keyValues));
359
365
 
360
366
  if (!_deleted) {
361
- const { instance } = connectedModels.find(({ instance }) => {
362
- const instanceKeyValues = this.getIndexKeyValuesFromModel(instance);
363
- return keysEqual(instanceKeyValues, keyValues);
364
- })!;
367
+ const { instance } = connectedModels.find(
368
+ ({ instance: connectedModelInstance }) => {
369
+ const instanceKeyValues = this.getIndexKeyValuesFromModel(
370
+ connectedModelInstance,
371
+ );
372
+
373
+ return keysEqual(instanceKeyValues, keyValues);
374
+ },
375
+ )!;
365
376
 
366
377
  result.push([
367
- <T>(<unknown>instance),
378
+ instance as unknown as T,
368
379
  key ? OpType.UPDATE : OpType.INSERT,
369
380
  ]);
370
381
  await store.put(instance, key);
371
382
  } else {
372
- result.push([<T>(<unknown>item), OpType.DELETE]);
383
+ result.push([item as unknown as T, OpType.DELETE]);
373
384
 
374
385
  if (key) {
375
386
  await store.delete(key);
@@ -419,14 +430,14 @@ class IndexedDBAdapter extends StorageAdapterBase {
419
430
  }
420
431
  }
421
432
 
422
- //#region platform-specific helper methods
433
+ // #region platform-specific helper methods
423
434
 
424
435
  private async checkPrivate() {
425
- const isPrivate = await isPrivateMode().then(isPrivate => {
426
- return isPrivate;
427
- });
436
+ const isPrivate = await isPrivateMode();
428
437
  if (isPrivate) {
429
438
  logger.error("IndexedDB not supported in this browser's private mode");
439
+
440
+ // eslint-disable-next-line prefer-promise-reject-errors
430
441
  return Promise.reject(
431
442
  "IndexedDB not supported in this browser's private mode",
432
443
  );
@@ -455,6 +466,7 @@ class IndexedDBAdapter extends StorageAdapterBase {
455
466
 
456
467
  private getNamespaceAndModelFromStorename(storeName: string) {
457
468
  const [namespaceName, ...modelNameArr] = storeName.split('_');
469
+
458
470
  return {
459
471
  namespaceName,
460
472
  modelName: modelNameArr.join('_'),
@@ -485,13 +497,13 @@ class IndexedDBAdapter extends StorageAdapterBase {
485
497
  storeName: string,
486
498
  keyValue: string[],
487
499
  ): Promise<T> {
488
- return <T>await this._get(storeName, keyValue);
500
+ return (await this._get(storeName, keyValue)) as T;
489
501
  }
490
502
 
491
503
  private async getAll<T extends PersistentModel>(
492
504
  storeName: string,
493
505
  ): Promise<T[]> {
494
- return await this.db.getAll(storeName);
506
+ return this.db.getAll(storeName);
495
507
  }
496
508
 
497
509
  /**
@@ -565,7 +577,7 @@ class IndexedDBAdapter extends StorageAdapterBase {
565
577
  isPredicateGroup(predicateObjs[0]) &&
566
578
  (predicateObjs[0] as PredicatesGroup<T>).type !== 'not'
567
579
  ) {
568
- type = (predicateObjs[0] as PredicatesGroup<T>).type;
580
+ ({ type } = predicateObjs[0] as PredicatesGroup<T>);
569
581
  predicateObjs = (predicateObjs[0] as PredicatesGroup<T>).predicates;
570
582
  }
571
583
 
@@ -702,7 +714,7 @@ class IndexedDBAdapter extends StorageAdapterBase {
702
714
  // nothing intelligent we can do with `not` groups unless or until we start
703
715
  // smashing comparison operators against indexes -- at which point we could
704
716
  // perform some reversal here.
705
- candidateResults = <T[]>await this.getAll(storeName);
717
+ candidateResults = (await this.getAll(storeName)) as T[];
706
718
  }
707
719
 
708
720
  const filtered = predicateObjs
@@ -753,7 +765,7 @@ class IndexedDBAdapter extends StorageAdapterBase {
753
765
 
754
766
  result = pageResults;
755
767
  } else {
756
- result = <T[]>await this.db.getAll(storeName);
768
+ result = (await this.db.getAll(storeName)) as T[];
757
769
  }
758
770
 
759
771
  return result;
@@ -771,9 +783,10 @@ class IndexedDBAdapter extends StorageAdapterBase {
771
783
  if (this.safariCompatabilityMode) {
772
784
  return keyArr.length > 1 ? keyArr : keyArr[0];
773
785
  }
786
+
774
787
  return keyArr;
775
788
  };
776
- //#endregion
789
+ // #endregion
777
790
  }
778
791
 
779
792
  export default new IndexedDBAdapter();
@@ -1,11 +1,12 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { Adapter } from './index';
3
+ import type { IDBPDatabase, IDBPObjectStore } from 'idb';
4
+ import { ConsoleLogger } from '@aws-amplify/core';
5
+
4
6
  import { ModelInstanceCreator } from '../../datastore/datastore';
5
7
  import { ModelPredicateCreator } from '../../predicates';
6
8
  import {
7
9
  InternalSchema,
8
- isPredicateObj,
9
10
  ModelInstanceMetadata,
10
11
  ModelPredicate,
11
12
  NamespaceResolver,
@@ -16,21 +17,23 @@ import {
16
17
  PredicateObject,
17
18
  PredicatesGroup,
18
19
  QueryOne,
20
+ isPredicateObj,
19
21
  } from '../../types';
20
22
  import {
21
23
  NAMESPACES,
22
- getStorename,
23
- getIndexKeys,
24
+ extractPrimaryKeyFieldNames,
24
25
  extractPrimaryKeyValues,
26
+ getIndexKeys,
27
+ getStorename,
28
+ isModelConstructor,
25
29
  traverseModel,
26
30
  validatePredicate,
27
- isModelConstructor,
28
- extractPrimaryKeyFieldNames,
29
31
  } from '../../util';
30
- import type { IDBPDatabase, IDBPObjectStore } from 'idb';
31
- import type AsyncStorageDatabase from './AsyncStorageDatabase';
32
32
  import { ModelRelationship } from '../relationship';
33
- import { ConsoleLogger } from '@aws-amplify/core';
33
+
34
+ import type AsyncStorageDatabase from './AsyncStorageDatabase';
35
+
36
+ import { Adapter } from './index';
34
37
 
35
38
  const logger = new ConsoleLogger('DataStore');
36
39
  const DB_NAME = 'amplify-datastore';
@@ -46,6 +49,7 @@ export abstract class StorageAdapterBase implements Adapter {
46
49
  namsespaceName: NAMESPACES,
47
50
  modelName: string,
48
51
  ) => PersistentModelConstructor<any>;
52
+
49
53
  protected initPromise!: Promise<void>;
50
54
  protected resolve!: (value?: any) => void;
51
55
  protected reject!: (value?: any) => void;
@@ -78,12 +82,13 @@ export abstract class StorageAdapterBase implements Adapter {
78
82
  await this.preSetUpChecks();
79
83
 
80
84
  if (!this.initPromise) {
81
- this.initPromise = new Promise((res, rej) => {
82
- this.resolve = res;
83
- this.reject = rej;
85
+ this.initPromise = new Promise((resolve, reject) => {
86
+ this.resolve = resolve;
87
+ this.reject = reject;
84
88
  });
85
89
  } else {
86
90
  await this.initPromise;
91
+
87
92
  return;
88
93
  }
89
94
  if (sessionId) {
@@ -195,13 +200,14 @@ export abstract class StorageAdapterBase implements Adapter {
195
200
  const set = new Set<string>();
196
201
  const connectionStoreNames = Object.values(connectedModels).map(
197
202
  ({ modelName, item, instance }) => {
198
- const storeName = getStorename(namespaceName, modelName);
199
- set.add(storeName);
203
+ const resolvedStoreName = getStorename(namespaceName, modelName);
204
+ set.add(resolvedStoreName);
200
205
  const keys = getIndexKeys(
201
206
  this.schema.namespaces[namespaceName],
202
207
  modelName,
203
208
  );
204
- return { storeName, item, instance, keys };
209
+
210
+ return { storeName: resolvedStoreName, item, instance, keys };
205
211
  },
206
212
  );
207
213
 
@@ -397,7 +403,7 @@ export abstract class StorageAdapterBase implements Adapter {
397
403
 
398
404
  const deletedModels = deleteQueue.reduce(
399
405
  (acc, { items }) => acc.concat(items),
400
- <T[]>[],
406
+ [] as T[],
401
407
  );
402
408
 
403
409
  return [models, deletedModels];
@@ -413,7 +419,7 @@ export abstract class StorageAdapterBase implements Adapter {
413
419
 
414
420
  const deletedModels = deleteQueue.reduce(
415
421
  (acc, { items }) => acc.concat(items),
416
- <T[]>[],
422
+ [] as T[],
417
423
  );
418
424
 
419
425
  return [models, deletedModels];
@@ -471,7 +477,7 @@ export abstract class StorageAdapterBase implements Adapter {
471
477
 
472
478
  const deletedModels = deleteQueue.reduce(
473
479
  (acc, { items }) => acc.concat(items),
474
- <T[]>[],
480
+ [] as T[],
475
481
  );
476
482
 
477
483
  return [[model], deletedModels];
@@ -1,6 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Adapter } from '..';
4
+ // eslint-disable-next-line import/no-named-as-default
4
5
  import AsyncStorageAdapter from '../AsyncStorageAdapter';
5
6
 
6
7
  const getDefaultAdapter: () => Adapter = () => {
@@ -1,9 +1,12 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+ import { isBrowser, isWebWorker } from '@aws-amplify/core/internals/utils';
4
+
3
5
  import { Adapter } from '..';
4
6
  import IndexedDBAdapter from '../IndexedDBAdapter';
7
+ // eslint-disable-next-line import/no-named-as-default
5
8
  import AsyncStorageAdapter from '../AsyncStorageAdapter';
6
- import { isWebWorker, isBrowser } from '@aws-amplify/core/internals/utils';
9
+
7
10
  const getDefaultAdapter: () => Adapter = () => {
8
11
  if ((isBrowser && window.indexedDB) || (isWebWorker() && self.indexedDB)) {
9
12
  return IndexedDBAdapter as Adapter;
@@ -17,10 +17,10 @@ export interface Adapter extends SystemComponent {
17
17
  model: T,
18
18
  condition?: ModelPredicate<T>,
19
19
  ): Promise<[T, OpType.INSERT | OpType.UPDATE][]>;
20
- delete: <T extends PersistentModel>(
20
+ delete<T extends PersistentModel>(
21
21
  modelOrModelConstructor: T | PersistentModelConstructor<T>,
22
22
  condition?: ModelPredicate<T>,
23
- ) => Promise<[T[], T[]]>;
23
+ ): Promise<[T[], T[]]>;
24
24
  query<T extends PersistentModel>(
25
25
  modelConstructor: PersistentModelConstructor<T>,
26
26
  predicate?: ModelPredicate<T>,
@@ -1,6 +1,6 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { isFieldAssociation, ModelFieldType, ModelMeta } from '../types';
3
+ import { ModelFieldType, ModelMeta, isFieldAssociation } from '../types';
4
4
 
5
5
  /**
6
6
  * Defines a relationship from a LOCAL model.field to a REMOTE model.field and helps
@@ -52,6 +52,7 @@ export class ModelRelationship<T> {
52
52
  const relationship = ModelRelationship.from(model, field);
53
53
  relationship && relationships.push(relationship);
54
54
  }
55
+
55
56
  return relationships;
56
57
  }
57
58
 
@@ -212,6 +213,7 @@ export class ModelRelationship<T> {
212
213
  // This case is theoretically unnecessary going forward.
213
214
  return [this.explicitRemoteAssociation.targetName!];
214
215
  } else if (this.explicitRemoteAssociation?.targetNames) {
216
+ // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
215
217
  return this.explicitRemoteAssociation?.targetNames!;
216
218
  } else if (this.localAssociatedWith) {
217
219
  return this.localAssociatedWith;
@@ -249,6 +251,7 @@ export class ModelRelationship<T> {
249
251
  for (let i = 0; i < this.localJoinFields.length; i++) {
250
252
  fk[this.localJoinFields[i]] = remote[this.remoteJoinFields[i]];
251
253
  }
254
+
252
255
  return fk;
253
256
  }
254
257
 
@@ -278,6 +281,7 @@ export class ModelRelationship<T> {
278
281
  if (localValue === null || localValue === undefined) return null;
279
282
  query[this.remoteJoinFields[i]] = local[this.localJoinFields[i]];
280
283
  }
284
+
281
285
  return query;
282
286
  }
283
287
  }