@aws-amplify/datastore 4.7.5 → 5.0.1-console-preview.4208d73.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.
- package/README.md +4 -0
- package/lib/authModeStrategies/defaultAuthStrategy.js +3 -2
- package/lib/authModeStrategies/index.js +3 -3
- package/lib/authModeStrategies/multiAuthStrategy.js +81 -24
- package/lib/datastore/datastore.d.ts +3 -4
- package/lib/datastore/datastore.js +361 -227
- package/lib/index.d.ts +1 -1
- package/lib/index.js +25 -12
- package/lib/predicates/index.js +46 -12
- package/lib/predicates/next.d.ts +2 -2
- package/lib/predicates/next.js +172 -74
- package/lib/predicates/sort.js +3 -4
- package/lib/ssr/index.js +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +240 -128
- package/lib/storage/adapter/AsyncStorageDatabase.js +100 -39
- package/lib/storage/adapter/InMemoryStore.js +68 -17
- package/lib/storage/adapter/InMemoryStore.native.js +5 -3
- package/lib/storage/adapter/IndexedDBAdapter.js +355 -199
- package/lib/storage/adapter/StorageAdapterBase.js +154 -85
- package/lib/storage/adapter/getDefaultAdapter/index.js +8 -9
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -3
- package/lib/storage/adapter/index.js +0 -1
- package/lib/storage/relationship.js +31 -21
- package/lib/storage/storage.d.ts +3 -3
- package/lib/storage/storage.js +143 -61
- package/lib/sync/datastoreConnectivity.d.ts +1 -1
- package/lib/sync/datastoreConnectivity.js +57 -9
- package/lib/sync/datastoreReachability/index.js +3 -3
- package/lib/sync/datastoreReachability/index.native.js +7 -5
- package/lib/sync/index.d.ts +1 -1
- package/lib/sync/index.js +193 -125
- package/lib/sync/merger.js +81 -10
- package/lib/sync/outbox.js +101 -30
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +41 -6
- package/lib/sync/processors/mutation.d.ts +1 -1
- package/lib/sync/processors/mutation.js +192 -101
- package/lib/sync/processors/subscription.d.ts +4 -1
- package/lib/sync/processors/subscription.js +190 -178
- package/lib/sync/processors/sync.d.ts +1 -1
- package/lib/sync/processors/sync.js +113 -47
- package/lib/sync/utils.d.ts +4 -4
- package/lib/sync/utils.js +162 -81
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types.d.ts +138 -140
- package/lib/types.js +40 -5
- package/lib/util.d.ts +9 -17
- package/lib/util.js +216 -100
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +0 -1
- package/lib-esm/authModeStrategies/index.js +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +76 -21
- package/lib-esm/datastore/datastore.d.ts +3 -4
- package/lib-esm/datastore/datastore.js +206 -77
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +0 -1
- package/lib-esm/predicates/index.js +40 -7
- package/lib-esm/predicates/next.d.ts +2 -2
- package/lib-esm/predicates/next.js +148 -52
- package/lib-esm/predicates/sort.js +2 -4
- package/lib-esm/ssr/index.js +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +203 -95
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +66 -5
- package/lib-esm/storage/adapter/InMemoryStore.js +52 -2
- package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +271 -138
- package/lib-esm/storage/adapter/StorageAdapterBase.js +130 -62
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -5
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +0 -1
- package/lib-esm/storage/adapter/index.js +1 -1
- package/lib-esm/storage/relationship.js +27 -18
- package/lib-esm/storage/storage.d.ts +3 -3
- package/lib-esm/storage/storage.js +87 -9
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +48 -3
- package/lib-esm/sync/datastoreReachability/index.js +1 -2
- package/lib-esm/sync/datastoreReachability/index.native.js +1 -2
- package/lib-esm/sync/index.d.ts +1 -1
- package/lib-esm/sync/index.js +136 -72
- package/lib-esm/sync/merger.js +73 -3
- package/lib-esm/sync/outbox.js +75 -5
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +39 -5
- package/lib-esm/sync/processors/mutation.d.ts +1 -1
- package/lib-esm/sync/processors/mutation.js +130 -44
- package/lib-esm/sync/processors/subscription.d.ts +4 -1
- package/lib-esm/sync/processors/subscription.js +134 -126
- package/lib-esm/sync/processors/sync.d.ts +1 -1
- package/lib-esm/sync/processors/sync.js +74 -12
- package/lib-esm/sync/utils.d.ts +4 -4
- package/lib-esm/sync/utils.js +135 -55
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types.d.ts +138 -140
- package/lib-esm/types.js +36 -2
- package/lib-esm/util.d.ts +9 -17
- package/lib-esm/util.js +96 -16
- package/package.json +139 -132
- package/src/authModeStrategies/multiAuthStrategy.ts +11 -12
- package/src/datastore/datastore.ts +32 -25
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/InMemoryStore.ts +1 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +1 -1
- package/src/storage/adapter/StorageAdapterBase.ts +1 -1
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -3
- package/src/storage/storage.ts +1 -1
- package/src/sync/datastoreConnectivity.ts +2 -2
- package/src/sync/datastoreReachability/index.native.ts +1 -1
- package/src/sync/datastoreReachability/index.ts +1 -1
- package/src/sync/index.ts +69 -78
- package/src/sync/processors/mutation.ts +16 -10
- package/src/sync/processors/subscription.ts +55 -127
- package/src/sync/processors/sync.ts +8 -4
- package/src/sync/utils.ts +7 -8
- package/src/types.ts +4 -8
- package/src/util.ts +5 -6
- package/lib/.tsbuildinfo +0 -3
- package/lib/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib/authModeStrategies/index.js.map +0 -1
- package/lib/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib/datastore/datastore.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/predicates/index.js.map +0 -1
- package/lib/predicates/next.js.map +0 -1
- package/lib/predicates/sort.js.map +0 -1
- package/lib/ssr/index.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib/storage/adapter/index.js.map +0 -1
- package/lib/storage/relationship.js.map +0 -1
- package/lib/storage/storage.js.map +0 -1
- package/lib/sync/datastoreConnectivity.js.map +0 -1
- package/lib/sync/datastoreReachability/index.js.map +0 -1
- package/lib/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib/sync/index.js.map +0 -1
- package/lib/sync/merger.js.map +0 -1
- package/lib/sync/outbox.js.map +0 -1
- package/lib/sync/processors/errorMaps.js.map +0 -1
- package/lib/sync/processors/mutation.js.map +0 -1
- package/lib/sync/processors/subscription.js.map +0 -1
- package/lib/sync/processors/sync.js.map +0 -1
- package/lib/sync/utils.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/util.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib-esm/authModeStrategies/index.js.map +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib-esm/datastore/datastore.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/predicates/index.js.map +0 -1
- package/lib-esm/predicates/next.js.map +0 -1
- package/lib-esm/predicates/sort.js.map +0 -1
- package/lib-esm/ssr/index.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib-esm/storage/adapter/index.js.map +0 -1
- package/lib-esm/storage/relationship.js.map +0 -1
- package/lib-esm/storage/storage.js.map +0 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib-esm/sync/index.js.map +0 -1
- package/lib-esm/sync/merger.js.map +0 -1
- package/lib-esm/sync/outbox.js.map +0 -1
- package/lib-esm/sync/processors/errorMaps.js.map +0 -1
- package/lib-esm/sync/processors/mutation.js.map +0 -1
- package/lib-esm/sync/processors/subscription.js.map +0 -1
- package/lib-esm/sync/processors/sync.js.map +0 -1
- package/lib-esm/sync/utils.js.map +0 -1
- package/lib-esm/types.js.map +0 -1
- package/lib-esm/util.js.map +0 -1
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
Amplify,
|
|
8
|
-
ConsoleLogger as Logger,
|
|
9
|
-
Hub,
|
|
10
|
-
browserOrNode,
|
|
11
|
-
BackgroundProcessManager,
|
|
12
|
-
} from '@aws-amplify/core';
|
|
4
|
+
import { Amplify, Hub, Cache } from '@aws-amplify/core';
|
|
5
|
+
|
|
13
6
|
import {
|
|
14
7
|
Draft,
|
|
15
8
|
immerable,
|
|
@@ -110,6 +103,10 @@ import {
|
|
|
110
103
|
} from '../predicates/next';
|
|
111
104
|
import { getIdentifierValue } from '../sync/utils';
|
|
112
105
|
import DataStoreConnectivity from '../sync/datastoreConnectivity';
|
|
106
|
+
import {
|
|
107
|
+
BackgroundProcessManager,
|
|
108
|
+
Logger,
|
|
109
|
+
} from '@aws-amplify/core/internals/utils';
|
|
113
110
|
|
|
114
111
|
setAutoFreeze(true);
|
|
115
112
|
enablePatches();
|
|
@@ -117,7 +114,6 @@ enablePatches();
|
|
|
117
114
|
const logger = new Logger('DataStore');
|
|
118
115
|
|
|
119
116
|
const ulid = monotonicUlidFactory(Date.now());
|
|
120
|
-
const { isNode } = browserOrNode();
|
|
121
117
|
|
|
122
118
|
type SettingMetaData = {
|
|
123
119
|
identifier: ManagedIdentifier<Setting, 'id'>;
|
|
@@ -492,7 +488,6 @@ const checkSchemaCodegenVersion = (codegenVersion: string) => {
|
|
|
492
488
|
const majorVersion = 3;
|
|
493
489
|
const minorVersion = 2;
|
|
494
490
|
let isValid = false;
|
|
495
|
-
|
|
496
491
|
try {
|
|
497
492
|
const versionParts = codegenVersion.split('.');
|
|
498
493
|
const [major, minor, patch, patchrevision] = versionParts;
|
|
@@ -1383,7 +1378,6 @@ enum DataStoreState {
|
|
|
1383
1378
|
// https://github.com/aws-amplify/amplify-js/pull/10477/files#r1007363485
|
|
1384
1379
|
class DataStore {
|
|
1385
1380
|
// reference to configured category instances. Used for preserving SSR context
|
|
1386
|
-
private Auth = Auth;
|
|
1387
1381
|
private InternalAPI = InternalAPI;
|
|
1388
1382
|
private Cache = Cache;
|
|
1389
1383
|
|
|
@@ -1414,9 +1408,7 @@ class DataStore {
|
|
|
1414
1408
|
private storageAdapter!: Adapter;
|
|
1415
1409
|
// object that gets passed to descendent classes. Allows us to pass these down by reference
|
|
1416
1410
|
private amplifyContext: AmplifyContext = {
|
|
1417
|
-
Auth: this.Auth,
|
|
1418
1411
|
InternalAPI: this.InternalAPI,
|
|
1419
|
-
Cache: this.Cache,
|
|
1420
1412
|
};
|
|
1421
1413
|
private connectivityMonitor?: DataStoreConnectivity;
|
|
1422
1414
|
|
|
@@ -1531,6 +1523,7 @@ class DataStore {
|
|
|
1531
1523
|
await this.storage.init();
|
|
1532
1524
|
checkSchemaInitialized();
|
|
1533
1525
|
await checkSchemaVersion(this.storage, schema.version);
|
|
1526
|
+
|
|
1534
1527
|
const { aws_appsync_graphqlEndpoint } = this.amplifyConfig;
|
|
1535
1528
|
|
|
1536
1529
|
if (aws_appsync_graphqlEndpoint) {
|
|
@@ -1540,7 +1533,6 @@ class DataStore {
|
|
|
1540
1533
|
);
|
|
1541
1534
|
|
|
1542
1535
|
this.syncPredicates = await this.processSyncExpressions();
|
|
1543
|
-
|
|
1544
1536
|
this.sync = new SyncEngine(
|
|
1545
1537
|
schema,
|
|
1546
1538
|
namespaceResolver,
|
|
@@ -1563,11 +1555,8 @@ class DataStore {
|
|
|
1563
1555
|
.start({ fullSyncInterval: fullSyncIntervalInMilliseconds })
|
|
1564
1556
|
.subscribe({
|
|
1565
1557
|
next: ({ type, data }) => {
|
|
1566
|
-
// In Node, we need to wait for queries to be synced to prevent returning empty arrays.
|
|
1567
1558
|
// In the Browser, we can begin returning data once subscriptions are in place.
|
|
1568
|
-
const readyType =
|
|
1569
|
-
? ControlMessage.SYNC_ENGINE_SYNC_QUERIES_READY
|
|
1570
|
-
: ControlMessage.SYNC_ENGINE_STORAGE_SUBSCRIBED;
|
|
1559
|
+
const readyType = ControlMessage.SYNC_ENGINE_STORAGE_SUBSCRIBED;
|
|
1571
1560
|
|
|
1572
1561
|
if (type === readyType) {
|
|
1573
1562
|
this.initResolve();
|
|
@@ -2426,10 +2415,10 @@ class DataStore {
|
|
|
2426
2415
|
data?.model?.name === model.name
|
|
2427
2416
|
) {
|
|
2428
2417
|
generateAndEmitSnapshot();
|
|
2429
|
-
|
|
2418
|
+
hubRemove();
|
|
2430
2419
|
}
|
|
2431
2420
|
};
|
|
2432
|
-
Hub.listen('datastore', hubCallback);
|
|
2421
|
+
const hubRemove = Hub.listen('datastore', hubCallback);
|
|
2433
2422
|
|
|
2434
2423
|
return this.runningProcesses.addCleaner(async () => {
|
|
2435
2424
|
if (handle) {
|
|
@@ -2440,9 +2429,7 @@ class DataStore {
|
|
|
2440
2429
|
};
|
|
2441
2430
|
|
|
2442
2431
|
configure = (config: DataStoreConfig = {}) => {
|
|
2443
|
-
this.amplifyContext.Auth = this.Auth;
|
|
2444
2432
|
this.amplifyContext.InternalAPI = this.InternalAPI;
|
|
2445
|
-
this.amplifyContext.Cache = this.Cache;
|
|
2446
2433
|
|
|
2447
2434
|
const {
|
|
2448
2435
|
DataStore: configDataStore,
|
|
@@ -2458,9 +2445,24 @@ class DataStore {
|
|
|
2458
2445
|
...configFromAmplify
|
|
2459
2446
|
} = config;
|
|
2460
2447
|
|
|
2448
|
+
let apiKey = '';
|
|
2449
|
+
const currentAppSyncConfig = Amplify.getConfig().API?.AppSync;
|
|
2450
|
+
if (currentAppSyncConfig?.defaultAuthMode.type === 'apiKey') {
|
|
2451
|
+
apiKey = currentAppSyncConfig.defaultAuthMode.apiKey;
|
|
2452
|
+
}
|
|
2453
|
+
|
|
2454
|
+
const appSyncConfig = {
|
|
2455
|
+
aws_appsync_graphqlEndpoint: currentAppSyncConfig?.endpoint,
|
|
2456
|
+
aws_appsync_authenticationType:
|
|
2457
|
+
currentAppSyncConfig?.defaultAuthMode.type,
|
|
2458
|
+
aws_appsync_region: currentAppSyncConfig?.region,
|
|
2459
|
+
aws_appsync_apiKey: apiKey,
|
|
2460
|
+
};
|
|
2461
|
+
|
|
2461
2462
|
this.amplifyConfig = {
|
|
2462
|
-
...configFromAmplify,
|
|
2463
2463
|
...this.amplifyConfig,
|
|
2464
|
+
...configFromAmplify,
|
|
2465
|
+
...(currentAppSyncConfig && appSyncConfig),
|
|
2464
2466
|
};
|
|
2465
2467
|
|
|
2466
2468
|
this.conflictHandler = this.setConflictHandler(config);
|
|
@@ -2752,6 +2754,11 @@ class DataStore {
|
|
|
2752
2754
|
}
|
|
2753
2755
|
|
|
2754
2756
|
const instance = new DataStore();
|
|
2755
|
-
|
|
2757
|
+
instance.configure({});
|
|
2758
|
+
Hub.listen('core', capsule => {
|
|
2759
|
+
if (capsule.payload.event === 'configure') {
|
|
2760
|
+
instance.configure({});
|
|
2761
|
+
}
|
|
2762
|
+
});
|
|
2756
2763
|
|
|
2757
2764
|
export { DataStore as DataStoreClass, initSchema, instance as DataStore };
|
package/src/predicates/sort.ts
CHANGED
|
@@ -30,7 +30,9 @@ export class ModelSortPredicateCreator {
|
|
|
30
30
|
|
|
31
31
|
if (!fieldNames.has(field)) {
|
|
32
32
|
throw new Error(
|
|
33
|
-
`Invalid field for model. field: ${
|
|
33
|
+
`Invalid field for model. field: ${String(
|
|
34
|
+
field
|
|
35
|
+
)}, model: ${modelName}`
|
|
34
36
|
);
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
4
3
|
import * as idb from 'idb';
|
|
5
4
|
import {
|
|
6
5
|
isPredicateObj,
|
|
@@ -25,6 +24,7 @@ import {
|
|
|
25
24
|
isSafariCompatabilityMode,
|
|
26
25
|
} from '../../util';
|
|
27
26
|
import { StorageAdapterBase } from './StorageAdapterBase';
|
|
27
|
+
import { Logger } from '@aws-amplify/core/internals/utils';
|
|
28
28
|
|
|
29
29
|
const logger = new Logger('DataStore');
|
|
30
30
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
4
3
|
import { Adapter } from './index';
|
|
5
4
|
import { ModelInstanceCreator } from '../../datastore/datastore';
|
|
6
5
|
import { ModelPredicateCreator } from '../../predicates';
|
|
@@ -31,6 +30,7 @@ import {
|
|
|
31
30
|
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
32
31
|
import type AsyncStorageDatabase from './AsyncStorageDatabase';
|
|
33
32
|
import { ModelRelationship } from '../relationship';
|
|
33
|
+
import { Logger } from '@aws-amplify/core/internals/utils';
|
|
34
34
|
|
|
35
35
|
const logger = new Logger('DataStore');
|
|
36
36
|
const DB_NAME = 'amplify-datastore';
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { browserOrNode, isWebWorker } from '@aws-amplify/core';
|
|
4
3
|
import { Adapter } from '..';
|
|
5
4
|
import IndexedDBAdapter from '../IndexedDBAdapter';
|
|
6
5
|
import AsyncStorageAdapter from '../AsyncStorageAdapter';
|
|
7
|
-
|
|
6
|
+
import { isWebWorker } from '@aws-amplify/core/internals/utils';
|
|
8
7
|
const getDefaultAdapter: () => Adapter = () => {
|
|
9
|
-
const
|
|
8
|
+
const isBrowser = true; // TODO(v6): Update this for SSR
|
|
10
9
|
|
|
11
10
|
if ((isBrowser && window.indexedDB) || (isWebWorker() && self.indexedDB)) {
|
|
12
11
|
return IndexedDBAdapter as Adapter;
|
package/src/storage/storage.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { Logger, Mutex } from '@aws-amplify/core';
|
|
4
3
|
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
5
4
|
import PushStream from 'zen-push';
|
|
6
5
|
import { Patch } from 'immer';
|
|
@@ -32,6 +31,7 @@ import {
|
|
|
32
31
|
import { getIdentifierValue } from '../sync/utils';
|
|
33
32
|
import { Adapter } from './adapter';
|
|
34
33
|
import getDefaultAdapter from './adapter/getDefaultAdapter';
|
|
34
|
+
import { Logger, Mutex } from '@aws-amplify/core/internals/utils';
|
|
35
35
|
|
|
36
36
|
export type StorageSubscriptionMessage<T extends PersistentModel> =
|
|
37
37
|
InternalSubscriptionMessage<T> & {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
4
|
-
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
5
4
|
import { ReachabilityMonitor } from './datastoreReachability';
|
|
5
|
+
import { Logger } from '@aws-amplify/core/internals/utils';
|
|
6
6
|
|
|
7
7
|
const logger = new Logger('DataStore');
|
|
8
8
|
|
|
@@ -28,7 +28,7 @@ export default class DataStoreConnectivity {
|
|
|
28
28
|
if (this.observer) {
|
|
29
29
|
throw new Error('Subscriber already exists');
|
|
30
30
|
}
|
|
31
|
-
return new Observable(
|
|
31
|
+
return new Observable(observer => {
|
|
32
32
|
this.observer = observer;
|
|
33
33
|
// Will be used to forward socket connection changes, enhancing Reachability
|
|
34
34
|
|
|
@@ -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 { Reachability } from '@aws-amplify/core';
|
|
3
|
+
import { Reachability } from '@aws-amplify/core/internals/utils';
|
|
4
4
|
import { default as NetInfo } from '@react-native-community/netinfo';
|
|
5
5
|
|
|
6
6
|
export const ReachabilityMonitor = new Reachability().networkMonitor(NetInfo);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { Reachability } from '@aws-amplify/core';
|
|
3
|
+
import { Reachability } from '@aws-amplify/core/internals/utils';
|
|
4
4
|
|
|
5
5
|
export const ReachabilityMonitor = new Reachability().networkMonitor();
|
package/src/sync/index.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
ConsoleLogger as Logger,
|
|
4
|
+
Logger,
|
|
6
5
|
BackgroundProcessManager,
|
|
7
|
-
|
|
8
|
-
} from '@aws-amplify/core';
|
|
9
|
-
|
|
10
|
-
CONTROL_MSG as PUBSUB_CONTROL_MSG,
|
|
11
|
-
CONNECTION_STATE_CHANGE as PUBSUB_CONNECTION_STATE_CHANGE,
|
|
12
|
-
ConnectionState,
|
|
13
|
-
} from '@aws-amplify/pubsub';
|
|
6
|
+
} from '@aws-amplify/core/internals/utils';
|
|
7
|
+
import { Hub } from '@aws-amplify/core';
|
|
8
|
+
|
|
14
9
|
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
15
10
|
import { ModelInstanceCreator } from '../datastore/datastore';
|
|
16
11
|
import { ModelPredicateCreator } from '../predicates';
|
|
@@ -53,7 +48,12 @@ import {
|
|
|
53
48
|
TransformerMutationType,
|
|
54
49
|
} from './utils';
|
|
55
50
|
|
|
56
|
-
|
|
51
|
+
import {
|
|
52
|
+
CONTROL_MSG as PUBSUB_CONTROL_MSG,
|
|
53
|
+
ConnectionState,
|
|
54
|
+
CONNECTION_STATE_CHANGE as PUBSUB_CONNECTION_STATE_CHANGE,
|
|
55
|
+
} from '@aws-amplify/api-graphql';
|
|
56
|
+
|
|
57
57
|
const logger = new Logger('DataStore');
|
|
58
58
|
|
|
59
59
|
const ownSymbol = Symbol('sync');
|
|
@@ -249,53 +249,47 @@ export class SyncEngine {
|
|
|
249
249
|
[TransformerMutationType, SchemaModel, PersistentModel]
|
|
250
250
|
>;
|
|
251
251
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
);
|
|
257
|
-
} else {
|
|
258
|
-
this.stopDisruptionListener =
|
|
259
|
-
this.startDisruptionListener();
|
|
260
|
-
//#region GraphQL Subscriptions
|
|
261
|
-
[ctlSubsObservable, dataSubsObservable] =
|
|
262
|
-
this.subscriptionsProcessor.start();
|
|
263
|
-
|
|
264
|
-
try {
|
|
265
|
-
await new Promise<void>((resolve, reject) => {
|
|
266
|
-
onTerminate.then(reject);
|
|
267
|
-
const ctlSubsSubscription =
|
|
268
|
-
ctlSubsObservable.subscribe({
|
|
269
|
-
next: msg => {
|
|
270
|
-
if (msg === CONTROL_MSG.CONNECTED) {
|
|
271
|
-
resolve();
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
error: err => {
|
|
275
|
-
reject(err);
|
|
276
|
-
const handleDisconnect =
|
|
277
|
-
this.disconnectionHandler();
|
|
278
|
-
handleDisconnect(err);
|
|
279
|
-
},
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
subscriptions.push(ctlSubsSubscription);
|
|
283
|
-
});
|
|
284
|
-
} catch (err) {
|
|
285
|
-
observer.error(err);
|
|
286
|
-
failedStarting();
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
252
|
+
this.stopDisruptionListener =
|
|
253
|
+
this.startDisruptionListener();
|
|
254
|
+
//#region GraphQL Subscriptions
|
|
255
|
+
[ctlSubsObservable, dataSubsObservable] =
|
|
256
|
+
this.subscriptionsProcessor.start();
|
|
289
257
|
|
|
290
|
-
|
|
258
|
+
try {
|
|
259
|
+
await new Promise<void>((resolve, reject) => {
|
|
260
|
+
onTerminate.then(reject);
|
|
261
|
+
const ctlSubsSubscription = ctlSubsObservable.subscribe(
|
|
262
|
+
{
|
|
263
|
+
next: msg => {
|
|
264
|
+
if (msg === CONTROL_MSG.CONNECTED) {
|
|
265
|
+
resolve();
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
error: err => {
|
|
269
|
+
reject(err);
|
|
270
|
+
const handleDisconnect =
|
|
271
|
+
this.disconnectionHandler();
|
|
272
|
+
handleDisconnect(err);
|
|
273
|
+
},
|
|
274
|
+
}
|
|
275
|
+
);
|
|
291
276
|
|
|
292
|
-
|
|
293
|
-
type: ControlMessage.SYNC_ENGINE_SUBSCRIPTIONS_ESTABLISHED,
|
|
277
|
+
subscriptions.push(ctlSubsSubscription);
|
|
294
278
|
});
|
|
295
|
-
|
|
296
|
-
|
|
279
|
+
} catch (err) {
|
|
280
|
+
observer.error(err);
|
|
281
|
+
failedStarting();
|
|
282
|
+
return;
|
|
297
283
|
}
|
|
298
284
|
|
|
285
|
+
logger.log('Realtime ready');
|
|
286
|
+
|
|
287
|
+
observer.next({
|
|
288
|
+
type: ControlMessage.SYNC_ENGINE_SUBSCRIPTIONS_ESTABLISHED,
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
//#endregion
|
|
292
|
+
|
|
299
293
|
//#region Base & Sync queries
|
|
300
294
|
try {
|
|
301
295
|
await new Promise<void>((resolve, reject) => {
|
|
@@ -376,32 +370,29 @@ export class SyncEngine {
|
|
|
376
370
|
//#endregion
|
|
377
371
|
|
|
378
372
|
//#region Merge subscriptions buffer
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
)
|
|
403
|
-
);
|
|
404
|
-
}
|
|
373
|
+
subscriptions.push(
|
|
374
|
+
dataSubsObservable!.subscribe(
|
|
375
|
+
([_transformerMutationType, modelDefinition, item]) =>
|
|
376
|
+
this.runningProcesses.add(async () => {
|
|
377
|
+
const modelConstructor = this.userModelClasses[
|
|
378
|
+
modelDefinition.name
|
|
379
|
+
] as PersistentModelConstructor<any>;
|
|
380
|
+
|
|
381
|
+
const model = this.modelInstanceCreator(
|
|
382
|
+
modelConstructor,
|
|
383
|
+
item
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
await this.storage.runExclusive(storage =>
|
|
387
|
+
this.modelMerger.merge(
|
|
388
|
+
storage,
|
|
389
|
+
model,
|
|
390
|
+
modelDefinition
|
|
391
|
+
)
|
|
392
|
+
);
|
|
393
|
+
}, 'subscription dataSubsObservable event')
|
|
394
|
+
)
|
|
395
|
+
);
|
|
405
396
|
//#endregion
|
|
406
397
|
} else if (!online) {
|
|
407
398
|
this.online = online;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { GraphQLResult
|
|
3
|
+
import { GraphQLResult } from '@aws-amplify/api';
|
|
4
4
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
5
5
|
import {
|
|
6
6
|
Category,
|
|
7
|
-
|
|
7
|
+
Logger,
|
|
8
8
|
CustomUserAgentDetails,
|
|
9
9
|
DataStoreAction,
|
|
10
10
|
jitteredBackoff,
|
|
11
11
|
NonRetryableError,
|
|
12
12
|
retry,
|
|
13
13
|
BackgroundProcessManager,
|
|
14
|
-
|
|
14
|
+
GraphQLAuthModeKeys,
|
|
15
|
+
AmplifyError,
|
|
16
|
+
} from '@aws-amplify/core/internals/utils';
|
|
17
|
+
|
|
15
18
|
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
16
19
|
import { MutationEvent } from '../';
|
|
17
20
|
import { ModelInstanceCreator } from '../../datastore/datastore';
|
|
@@ -161,8 +164,8 @@ class MutationProcessor {
|
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
public async resume(): Promise<void> {
|
|
164
|
-
|
|
165
|
-
this.runningProcesses.add(async onTerminate => {
|
|
167
|
+
if (this.runningProcesses.isOpen) {
|
|
168
|
+
await this.runningProcesses.add(async onTerminate => {
|
|
166
169
|
if (
|
|
167
170
|
this.processing ||
|
|
168
171
|
!this.isReady() ||
|
|
@@ -170,7 +173,6 @@ class MutationProcessor {
|
|
|
170
173
|
) {
|
|
171
174
|
return;
|
|
172
175
|
}
|
|
173
|
-
|
|
174
176
|
this.processing = true;
|
|
175
177
|
let head: MutationEvent;
|
|
176
178
|
const namespaceName = USER;
|
|
@@ -300,7 +302,8 @@ class MutationProcessor {
|
|
|
300
302
|
|
|
301
303
|
// pauses itself
|
|
302
304
|
this.pause();
|
|
303
|
-
}, 'mutation resume loop')
|
|
305
|
+
}, 'mutation resume loop');
|
|
306
|
+
}
|
|
304
307
|
}
|
|
305
308
|
|
|
306
309
|
private async jitteredRetry(
|
|
@@ -312,7 +315,7 @@ class MutationProcessor {
|
|
|
312
315
|
modelConstructor: PersistentModelConstructor<PersistentModel>,
|
|
313
316
|
MutationEvent: PersistentModelConstructor<MutationEvent>,
|
|
314
317
|
mutationEvent: MutationEvent,
|
|
315
|
-
authMode:
|
|
318
|
+
authMode: GraphQLAuthModeKeys,
|
|
316
319
|
onTerminate: Promise<void>
|
|
317
320
|
): Promise<
|
|
318
321
|
[GraphQLResult<Record<string, PersistentModel>>, string, SchemaModel]
|
|
@@ -544,7 +547,7 @@ class MutationProcessor {
|
|
|
544
547
|
|
|
545
548
|
// include all the fields that comprise a custom PK if one is specified
|
|
546
549
|
const deleteInput = {};
|
|
547
|
-
if (primaryKey
|
|
550
|
+
if (primaryKey && primaryKey.length) {
|
|
548
551
|
for (const pkField of primaryKey) {
|
|
549
552
|
deleteInput[pkField] = parsedData[pkField];
|
|
550
553
|
}
|
|
@@ -679,7 +682,10 @@ export const safeJitteredBackoff: typeof originalJitteredBackoff = (
|
|
|
679
682
|
const attemptResult = originalJitteredBackoff(attempt);
|
|
680
683
|
|
|
681
684
|
// If this is the last attempt and it is a network error, we retry indefinitively every 5 minutes
|
|
682
|
-
if (
|
|
685
|
+
if (
|
|
686
|
+
attemptResult === false &&
|
|
687
|
+
((error || {}) as any).message === 'Network Error'
|
|
688
|
+
) {
|
|
683
689
|
return MAX_RETRY_DELAY_MS;
|
|
684
690
|
}
|
|
685
691
|
|