@aws-amplify/datastore 3.12.6-next.13 → 3.12.6-next.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/lib/authModeStrategies/multiAuthStrategy.js +17 -64
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.js +682 -469
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/index.js +2 -4
- package/lib/index.js.map +1 -1
- package/lib/predicates/index.js +12 -2
- package/lib/predicates/index.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +393 -298
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js +97 -122
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.js +16 -67
- package/lib/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.native.js +2 -4
- package/lib/storage/adapter/InMemoryStore.native.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +497 -404
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js +3 -5
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +2 -4
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +1 -1
- package/lib/storage/storage.js +129 -151
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.js +13 -17
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/datastoreReachability/index.native.js +2 -4
- package/lib/sync/datastoreReachability/index.native.js.map +1 -1
- package/lib/sync/index.js +544 -488
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.js +21 -80
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.js +95 -162
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/errorMaps.js +4 -34
- package/lib/sync/processors/errorMaps.js.map +1 -1
- package/lib/sync/processors/mutation.js +285 -312
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.js +218 -259
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.js +141 -212
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.js +50 -61
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.js +13 -39
- package/lib/types.js.map +1 -1
- package/lib/util.js +429 -242
- package/lib/util.js.map +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.d.ts +11 -0
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +13 -57
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +107 -17
- package/lib-esm/datastore/datastore.js +649 -433
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/index.d.ts +3 -19
- package/lib-esm/predicates/index.d.ts +3 -2
- package/lib-esm/predicates/index.js +13 -3
- package/lib-esm/predicates/index.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.d.ts +4 -3
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +356 -258
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.d.ts +14 -4
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +67 -92
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.js +1 -52
- package/lib-esm/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +26 -4
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +446 -346
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/index.d.ts +1 -1
- package/lib-esm/storage/storage.d.ts +1 -1
- package/lib-esm/storage/storage.js +94 -113
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -0
- package/lib-esm/sync/datastoreConnectivity.js +10 -11
- package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
- package/lib-esm/sync/index.d.ts +31 -5
- package/lib-esm/sync/index.js +525 -466
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.d.ts +9 -3
- package/lib-esm/sync/merger.js +14 -73
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.d.ts +2 -2
- package/lib-esm/sync/outbox.js +79 -146
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.js +1 -31
- package/lib-esm/sync/processors/errorMaps.js.map +1 -1
- package/lib-esm/sync/processors/mutation.d.ts +2 -0
- package/lib-esm/sync/processors/mutation.js +271 -295
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.d.ts +2 -0
- package/lib-esm/sync/processors/subscription.js +214 -245
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.d.ts +2 -1
- package/lib-esm/sync/processors/sync.js +127 -195
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.d.ts +3 -2
- package/lib-esm/sync/utils.js +45 -57
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +65 -26
- package/lib-esm/types.js +10 -38
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +67 -24
- package/lib-esm/util.js +420 -233
- package/lib-esm/util.js.map +1 -1
- package/package.json +14 -7
- package/src/authModeStrategies/multiAuthStrategy.ts +12 -1
- package/src/datastore/datastore.ts +798 -397
- package/src/predicates/index.ts +32 -10
- package/src/storage/adapter/AsyncStorageAdapter.ts +309 -93
- package/src/storage/adapter/AsyncStorageDatabase.ts +74 -26
- package/src/storage/adapter/IndexedDBAdapter.ts +358 -134
- package/src/storage/adapter/index.ts +1 -1
- package/src/storage/storage.ts +69 -22
- package/src/sync/datastoreConnectivity.ts +6 -0
- package/src/sync/index.ts +521 -412
- package/src/sync/merger.ts +20 -4
- package/src/sync/outbox.ts +22 -9
- package/src/sync/processors/mutation.ts +188 -150
- package/src/sync/processors/subscription.ts +289 -253
- package/src/sync/processors/sync.ts +151 -138
- package/src/sync/utils.ts +67 -12
- package/src/types.ts +182 -30
- package/src/util.ts +505 -176
- package/build.js +0 -5
- package/dist/aws-amplify-datastore.js +0 -98255
- package/dist/aws-amplify-datastore.js.map +0 -1
- package/dist/aws-amplify-datastore.min.js +0 -66
- package/dist/aws-amplify-datastore.min.js.map +0 -1
- package/index.js +0 -7
- package/lib/authModeStrategies/defaultAuthStrategy.d.ts +0 -2
- package/lib/authModeStrategies/index.d.ts +0 -2
- package/lib/authModeStrategies/multiAuthStrategy.d.ts +0 -2
- package/lib/datastore/datastore.d.ts +0 -66
- package/lib/index.d.ts +0 -31
- package/lib/predicates/index.d.ts +0 -15
- package/lib/predicates/sort.d.ts +0 -8
- package/lib/ssr/index.d.ts +0 -3
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +0 -40
- package/lib/storage/adapter/AsyncStorageDatabase.d.ts +0 -29
- package/lib/storage/adapter/InMemoryStore.d.ts +0 -11
- package/lib/storage/adapter/InMemoryStore.native.d.ts +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.d.ts +0 -37
- package/lib/storage/adapter/getDefaultAdapter/index.d.ts +0 -3
- package/lib/storage/adapter/getDefaultAdapter/index.native.d.ts +0 -3
- package/lib/storage/adapter/index.d.ts +0 -9
- package/lib/storage/storage.d.ts +0 -49
- package/lib/sync/datastoreConnectivity.d.ts +0 -15
- package/lib/sync/datastoreReachability/index.d.ts +0 -3
- package/lib/sync/datastoreReachability/index.native.d.ts +0 -3
- package/lib/sync/index.d.ts +0 -63
- package/lib/sync/merger.d.ts +0 -11
- package/lib/sync/outbox.d.ts +0 -27
- package/lib/sync/processors/errorMaps.d.ts +0 -17
- package/lib/sync/processors/mutation.d.ts +0 -56
- package/lib/sync/processors/subscription.d.ts +0 -31
- package/lib/sync/processors/sync.d.ts +0 -27
- package/lib/sync/utils.d.ts +0 -41
- package/lib/types.d.ts +0 -462
- package/lib/util.d.ts +0 -113
- package/webpack.config.dev.js +0 -6
|
@@ -29,7 +29,7 @@ export interface Adapter extends SystemComponent {
|
|
|
29
29
|
firstOrLast: QueryOne
|
|
30
30
|
): Promise<T | undefined>;
|
|
31
31
|
batchSave<T extends PersistentModel>(
|
|
32
|
-
modelConstructor: PersistentModelConstructor<
|
|
32
|
+
modelConstructor: PersistentModelConstructor<T>,
|
|
33
33
|
items: ModelInstanceMetadata[]
|
|
34
34
|
): Promise<[T, OpType][]>;
|
|
35
35
|
}
|
package/src/storage/storage.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
validatePredicate,
|
|
27
27
|
valuesEqual,
|
|
28
28
|
} from '../util';
|
|
29
|
+
import { getIdentifierValue } from '../sync/utils';
|
|
29
30
|
import { Adapter } from './adapter';
|
|
30
31
|
import getDefaultAdapter from './adapter/getDefaultAdapter';
|
|
31
32
|
|
|
@@ -188,7 +189,21 @@ class StorageClass implements StorageFacade {
|
|
|
188
189
|
condition
|
|
189
190
|
);
|
|
190
191
|
|
|
191
|
-
const
|
|
192
|
+
const modelConstructor = isModelConstructor(modelOrModelConstructor)
|
|
193
|
+
? modelOrModelConstructor
|
|
194
|
+
: (Object.getPrototypeOf(modelOrModelConstructor || {})
|
|
195
|
+
.constructor as PersistentModelConstructor<T>);
|
|
196
|
+
const namespaceName = this.namespaceResolver(modelConstructor);
|
|
197
|
+
|
|
198
|
+
const modelDefinition =
|
|
199
|
+
this.schema.namespaces[namespaceName].models[modelConstructor.name];
|
|
200
|
+
|
|
201
|
+
const modelIds = new Set(
|
|
202
|
+
models.map(model => {
|
|
203
|
+
const modelId = getIdentifierValue(modelDefinition, model);
|
|
204
|
+
return modelId;
|
|
205
|
+
})
|
|
206
|
+
);
|
|
192
207
|
|
|
193
208
|
if (
|
|
194
209
|
!isModelConstructor(modelOrModelConstructor) &&
|
|
@@ -204,7 +219,8 @@ class StorageClass implements StorageFacade {
|
|
|
204
219
|
let theCondition: PredicatesGroup<any>;
|
|
205
220
|
|
|
206
221
|
if (!isModelConstructor(modelOrModelConstructor)) {
|
|
207
|
-
|
|
222
|
+
const modelId = getIdentifierValue(modelDefinition, model);
|
|
223
|
+
theCondition = modelIds.has(modelId)
|
|
208
224
|
? ModelPredicateCreator.getPredicates(condition, false)
|
|
209
225
|
: undefined;
|
|
210
226
|
}
|
|
@@ -337,30 +353,65 @@ class StorageClass implements StorageFacade {
|
|
|
337
353
|
|
|
338
354
|
// set original values for these fields
|
|
339
355
|
updatedFields.forEach((field: string) => {
|
|
340
|
-
const
|
|
356
|
+
const targetNames: any = isTargetNameAssociation(
|
|
341
357
|
fields[field]?.association
|
|
342
358
|
);
|
|
343
359
|
|
|
344
|
-
|
|
345
|
-
|
|
360
|
+
if (Array.isArray(targetNames)) {
|
|
361
|
+
// if field refers to a belongsTo relation, use the target field instead
|
|
362
|
+
|
|
363
|
+
for (const targetName of targetNames) {
|
|
364
|
+
// check field values by value. Ignore unchanged fields
|
|
365
|
+
if (!valuesEqual(source[targetName], originalElement[targetName])) {
|
|
366
|
+
// if the field was updated to 'undefined', replace with 'null' for compatibility with JSON and GraphQL
|
|
367
|
+
|
|
368
|
+
updatedElement[targetName] =
|
|
369
|
+
originalElement[targetName] === undefined
|
|
370
|
+
? null
|
|
371
|
+
: originalElement[targetName];
|
|
372
|
+
|
|
373
|
+
for (const fieldSet of compositeKeys) {
|
|
374
|
+
// include all of the fields that comprise the composite key
|
|
375
|
+
if (fieldSet.has(targetName)) {
|
|
376
|
+
for (const compositeField of fieldSet) {
|
|
377
|
+
updatedElement[compositeField] =
|
|
378
|
+
originalElement[compositeField];
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
} else {
|
|
385
|
+
// Backwards compatibility pre-CPK
|
|
386
|
+
|
|
387
|
+
// if field refers to a belongsTo relation, use the target field instead
|
|
388
|
+
const key = targetNames || field;
|
|
389
|
+
|
|
390
|
+
// check field values by value. Ignore unchanged fields
|
|
391
|
+
if (!valuesEqual(source[key], originalElement[key])) {
|
|
392
|
+
// if the field was updated to 'undefined', replace with 'null' for compatibility with JSON and GraphQL
|
|
346
393
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
// if the field was updated to 'undefined', replace with 'null' for compatibility with JSON and GraphQL
|
|
350
|
-
updatedElement[key] =
|
|
351
|
-
originalElement[key] === undefined ? null : originalElement[key];
|
|
394
|
+
updatedElement[key] =
|
|
395
|
+
originalElement[key] === undefined ? null : originalElement[key];
|
|
352
396
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
397
|
+
for (const fieldSet of compositeKeys) {
|
|
398
|
+
// include all of the fields that comprise the composite key
|
|
399
|
+
if (fieldSet.has(key)) {
|
|
400
|
+
for (const compositeField of fieldSet) {
|
|
401
|
+
updatedElement[compositeField] =
|
|
402
|
+
originalElement[compositeField];
|
|
403
|
+
}
|
|
358
404
|
}
|
|
359
405
|
}
|
|
360
406
|
}
|
|
361
407
|
}
|
|
362
408
|
});
|
|
363
409
|
|
|
410
|
+
// Exit early when there are no changes introduced in the update mutation
|
|
411
|
+
if (Object.keys(updatedElement).length === 0) {
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
|
|
364
415
|
// include field(s) from custom PK if one is specified for the model
|
|
365
416
|
if (primaryKey && primaryKey.length) {
|
|
366
417
|
for (const pkField of primaryKey) {
|
|
@@ -368,10 +419,6 @@ class StorageClass implements StorageFacade {
|
|
|
368
419
|
}
|
|
369
420
|
}
|
|
370
421
|
|
|
371
|
-
if (Object.keys(updatedElement).length === 0) {
|
|
372
|
-
return null;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
422
|
const { id, _version, _lastChangedAt, _deleted } = originalElement;
|
|
376
423
|
|
|
377
424
|
// For update mutations we only want to send fields with changes
|
|
@@ -421,7 +468,7 @@ class ExclusiveStorage implements StorageFacade {
|
|
|
421
468
|
patchesTuple?: [Patch[], PersistentModel]
|
|
422
469
|
): Promise<[T, OpType.INSERT | OpType.UPDATE][]> {
|
|
423
470
|
return this.runExclusive<[T, OpType.INSERT | OpType.UPDATE][]>(storage =>
|
|
424
|
-
storage.save
|
|
471
|
+
storage.save(model, condition, mutator, patchesTuple)
|
|
425
472
|
);
|
|
426
473
|
}
|
|
427
474
|
|
|
@@ -485,11 +532,11 @@ class ExclusiveStorage implements StorageFacade {
|
|
|
485
532
|
}
|
|
486
533
|
|
|
487
534
|
async clear() {
|
|
488
|
-
await this.storage.clear();
|
|
535
|
+
await this.runExclusive(storage => storage.clear());
|
|
489
536
|
}
|
|
490
537
|
|
|
491
538
|
batchSave<T extends PersistentModel>(
|
|
492
|
-
modelConstructor: PersistentModelConstructor<
|
|
539
|
+
modelConstructor: PersistentModelConstructor<T>,
|
|
493
540
|
items: ModelInstanceMetadata[]
|
|
494
541
|
): Promise<[T, OpType][]> {
|
|
495
542
|
return this.storage.batchSave(modelConstructor, items);
|
|
@@ -52,6 +52,12 @@ export default class DataStoreConnectivity {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// for consistency with other background processors.
|
|
56
|
+
async stop() {
|
|
57
|
+
this.unsubscribe();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
55
61
|
socketDisconnected() {
|
|
56
62
|
if (this.observer && typeof this.observer.next === 'function') {
|
|
57
63
|
this.observer.next({ online: false }); // Notify network issue from the socket
|