@aws-amplify/datastore 4.7.6-api-v6-models.b3abc9b.0 → 5.0.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 +38 -53
- package/lib/datastore/datastore.d.ts +4 -5
- package/lib/datastore/datastore.js +929 -1284
- package/lib/index.d.ts +1 -1
- package/lib/index.js +26 -13
- package/lib/predicates/index.js +54 -69
- package/lib/predicates/next.d.ts +2 -2
- package/lib/predicates/next.js +313 -462
- package/lib/predicates/sort.js +24 -28
- package/lib/ssr/index.js +2 -2
- package/lib/storage/adapter/AsyncStorageAdapter.js +120 -342
- package/lib/storage/adapter/AsyncStorageDatabase.js +217 -421
- package/lib/storage/adapter/InMemoryStore.js +28 -51
- package/lib/storage/adapter/InMemoryStore.native.js +5 -3
- package/lib/storage/adapter/IndexedDBAdapter.js +466 -871
- package/lib/storage/adapter/StorageAdapterBase.js +180 -330
- package/lib/storage/adapter/getDefaultAdapter/index.js +8 -10
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +5 -4
- package/lib/storage/adapter/index.js +0 -1
- package/lib/storage/relationship.js +177 -253
- package/lib/storage/storage.d.ts +4 -4
- package/lib/storage/storage.js +255 -433
- package/lib/sync/datastoreConnectivity.d.ts +2 -2
- package/lib/sync/datastoreConnectivity.js +29 -39
- package/lib/sync/datastoreReachability/index.d.ts +1 -3
- package/lib/sync/datastoreReachability/index.js +3 -3
- package/lib/sync/datastoreReachability/index.native.d.ts +1 -3
- package/lib/sync/datastoreReachability/index.native.js +4 -5
- package/lib/sync/index.d.ts +2 -2
- package/lib/sync/index.js +522 -827
- package/lib/sync/merger.js +31 -63
- package/lib/sync/outbox.js +148 -232
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +30 -47
- package/lib/sync/processors/mutation.d.ts +2 -2
- package/lib/sync/processors/mutation.js +343 -502
- package/lib/sync/processors/subscription.d.ts +5 -2
- package/lib/sync/processors/subscription.js +283 -437
- package/lib/sync/processors/sync.d.ts +2 -2
- package/lib/sync/processors/sync.js +279 -404
- package/lib/sync/utils.d.ts +5 -4
- package/lib/sync/utils.js +267 -320
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types.d.ts +138 -140
- package/lib/types.js +17 -24
- package/lib/util.d.ts +9 -17
- package/lib/util.js +387 -511
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +1 -2
- package/lib-esm/authModeStrategies/index.js +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +35 -52
- package/lib-esm/datastore/datastore.d.ts +4 -5
- package/lib-esm/datastore/datastore.js +888 -1247
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +6 -7
- package/lib-esm/predicates/index.js +53 -70
- package/lib-esm/predicates/next.d.ts +2 -2
- package/lib-esm/predicates/next.js +306 -459
- package/lib-esm/predicates/sort.js +23 -28
- package/lib-esm/ssr/index.js +1 -2
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +111 -338
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +212 -416
- package/lib-esm/storage/adapter/InMemoryStore.js +27 -52
- package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +438 -866
- package/lib-esm/storage/adapter/StorageAdapterBase.js +173 -325
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -6
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +1 -2
- package/lib-esm/storage/adapter/index.js +1 -1
- package/lib-esm/storage/relationship.js +173 -251
- package/lib-esm/storage/storage.d.ts +4 -4
- package/lib-esm/storage/storage.js +242 -424
- package/lib-esm/sync/datastoreConnectivity.d.ts +2 -2
- package/lib-esm/sync/datastoreConnectivity.js +28 -39
- package/lib-esm/sync/datastoreReachability/index.d.ts +1 -3
- package/lib-esm/sync/datastoreReachability/index.js +2 -3
- package/lib-esm/sync/datastoreReachability/index.native.d.ts +1 -3
- package/lib-esm/sync/datastoreReachability/index.native.js +3 -4
- package/lib-esm/sync/index.d.ts +2 -2
- package/lib-esm/sync/index.js +502 -812
- package/lib-esm/sync/merger.js +28 -61
- package/lib-esm/sync/outbox.js +143 -228
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +32 -50
- package/lib-esm/sync/processors/mutation.d.ts +2 -2
- package/lib-esm/sync/processors/mutation.js +329 -490
- package/lib-esm/sync/processors/subscription.d.ts +5 -2
- package/lib-esm/sync/processors/subscription.js +266 -421
- package/lib-esm/sync/processors/sync.d.ts +2 -2
- package/lib-esm/sync/processors/sync.js +271 -397
- package/lib-esm/sync/utils.d.ts +5 -4
- package/lib-esm/sync/utils.js +252 -307
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types.d.ts +138 -140
- package/lib-esm/types.js +16 -25
- package/lib-esm/util.d.ts +9 -17
- package/lib-esm/util.js +335 -497
- package/package.json +31 -26
- package/src/authModeStrategies/multiAuthStrategy.ts +15 -12
- package/src/datastore/datastore.ts +36 -35
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/InMemoryStore.ts +1 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +2 -2
- package/src/storage/adapter/StorageAdapterBase.ts +2 -2
- package/src/storage/adapter/getDefaultAdapter/index.ts +1 -4
- package/src/storage/storage.ts +29 -24
- package/src/sync/datastoreConnectivity.ts +6 -6
- package/src/sync/datastoreReachability/index.native.ts +5 -3
- package/src/sync/datastoreReachability/index.ts +1 -1
- package/src/sync/index.ts +79 -89
- package/src/sync/processors/errorMaps.ts +7 -7
- package/src/sync/processors/mutation.ts +19 -13
- package/src/sync/processors/subscription.ts +221 -295
- package/src/sync/processors/sync.ts +11 -8
- package/src/sync/utils.ts +30 -15
- package/src/types.ts +4 -8
- package/src/util.ts +46 -9
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/datastore",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "AppSyncLocal support for aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"test": "npm run lint && jest -w 1 --coverage",
|
|
20
20
|
"test:size": "size-limit",
|
|
21
21
|
"build-with-test": "npm test && npm run build",
|
|
22
|
-
"build:cjs": "
|
|
23
|
-
"build:esm": "
|
|
24
|
-
"build:cjs:watch": "
|
|
25
|
-
"build:esm:watch": "rimraf lib-esm &&
|
|
22
|
+
"build:cjs": "rimraf lib && tsc -m commonjs --outDir lib && webpack && webpack --config ./webpack.config.dev.js",
|
|
23
|
+
"build:esm": "rimraf lib-esm && tsc -m esnext --outDir lib-esm",
|
|
24
|
+
"build:cjs:watch": "rimraf lib && tsc -m commonjs --outDir lib --watch",
|
|
25
|
+
"build:esm:watch": "rimraf lib-esm && tsc -m esnext --outDir lib-esm --watch",
|
|
26
26
|
"build": "yarn clean && yarn build:esm && npm run build:cjs",
|
|
27
27
|
"clean": "npm run clean:size && rimraf lib-esm lib dist",
|
|
28
28
|
"clean:size": "rimraf dual-publish-tmp tmp*",
|
|
@@ -40,14 +40,6 @@
|
|
|
40
40
|
"url": "https://github.com/aws/aws-amplify/issues"
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://aws-amplify.github.io/",
|
|
43
|
-
"devDependencies": {
|
|
44
|
-
"@react-native-community/netinfo": "4.7.0",
|
|
45
|
-
"@types/uuid": "3.4.6",
|
|
46
|
-
"@types/uuid-validate": "^0.0.1",
|
|
47
|
-
"dexie": "3.2.2",
|
|
48
|
-
"dexie-export-import": "1.0.3",
|
|
49
|
-
"fake-indexeddb": "3.0.0"
|
|
50
|
-
},
|
|
51
43
|
"files": [
|
|
52
44
|
"lib",
|
|
53
45
|
"lib-esm",
|
|
@@ -55,25 +47,33 @@
|
|
|
55
47
|
"ssr"
|
|
56
48
|
],
|
|
57
49
|
"dependencies": {
|
|
58
|
-
"@aws-amplify/api": "
|
|
59
|
-
"@aws-amplify/auth": "
|
|
60
|
-
"@aws-amplify/core": "5.8.6-api-v6-models.b3abc9b.0+b3abc9b",
|
|
61
|
-
"@aws-amplify/pubsub": "5.5.6-api-v6-models.b3abc9b.0+b3abc9b",
|
|
62
|
-
"amazon-cognito-identity-js": "6.3.7-api-v6-models.b3abc9b.0+b3abc9b",
|
|
50
|
+
"@aws-amplify/api": "6.0.0",
|
|
51
|
+
"@aws-amplify/auth": "6.0.0",
|
|
63
52
|
"buffer": "4.9.2",
|
|
64
53
|
"idb": "5.0.6",
|
|
65
54
|
"immer": "9.0.6",
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
"rxjs": "^7.8.1",
|
|
56
|
+
"ulid": "^2.3.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@aws-amplify/core": "^6.0.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@aws-amplify/core": "6.0.0",
|
|
63
|
+
"@aws-amplify/react-native": "^1.0.0",
|
|
64
|
+
"@types/uuid-validate": "^0.0.1",
|
|
65
|
+
"dexie": "3.2.2",
|
|
66
|
+
"dexie-export-import": "1.0.3",
|
|
67
|
+
"fake-indexeddb": "3.0.0",
|
|
68
|
+
"graphql": "15.8.0",
|
|
69
|
+
"typescript": "5.0.2"
|
|
70
70
|
},
|
|
71
71
|
"size-limit": [
|
|
72
72
|
{
|
|
73
73
|
"name": "DataStore (top-level class)",
|
|
74
74
|
"path": "./lib-esm/index.js",
|
|
75
75
|
"import": "{ Amplify, DataStore }",
|
|
76
|
-
"limit": "
|
|
76
|
+
"limit": "65.25 kB"
|
|
77
77
|
}
|
|
78
78
|
],
|
|
79
79
|
"jest": {
|
|
@@ -91,8 +91,10 @@
|
|
|
91
91
|
"target": "es5",
|
|
92
92
|
"allowJs": true,
|
|
93
93
|
"esModuleInterop": true,
|
|
94
|
-
"
|
|
95
|
-
"
|
|
94
|
+
"strictNullChecks": false,
|
|
95
|
+
"types": [
|
|
96
|
+
"@types/jest"
|
|
97
|
+
]
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
100
|
},
|
|
@@ -128,7 +130,10 @@
|
|
|
128
130
|
"dist",
|
|
129
131
|
"lib",
|
|
130
132
|
"lib-esm"
|
|
133
|
+
],
|
|
134
|
+
"setupFilesAfterEnv": [
|
|
135
|
+
"<rootDir>/jest.setup.js"
|
|
131
136
|
]
|
|
132
137
|
},
|
|
133
|
-
"gitHead": "
|
|
138
|
+
"gitHead": "d505105326d7f6214f6bd1e06eb20be3a3651377"
|
|
134
139
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
|
|
3
|
+
import { fetchAuthSession } from '@aws-amplify/core';
|
|
5
4
|
import {
|
|
6
5
|
AuthModeStrategy,
|
|
7
6
|
ModelAttributeAuthProperty,
|
|
@@ -9,6 +8,7 @@ import {
|
|
|
9
8
|
ModelAttributeAuthAllow,
|
|
10
9
|
AmplifyContext,
|
|
11
10
|
} from '../types';
|
|
11
|
+
import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
12
12
|
|
|
13
13
|
function getProviderFromRule(
|
|
14
14
|
rule: ModelAttributeAuthProperty
|
|
@@ -63,7 +63,7 @@ function getAuthRules({
|
|
|
63
63
|
currentUser: unknown;
|
|
64
64
|
}) {
|
|
65
65
|
// Using Set to ensure uniqueness
|
|
66
|
-
const authModes = new Set<
|
|
66
|
+
const authModes = new Set<GraphQLAuthMode>();
|
|
67
67
|
|
|
68
68
|
rules.forEach(rule => {
|
|
69
69
|
switch (rule.allow) {
|
|
@@ -73,7 +73,7 @@ function getAuthRules({
|
|
|
73
73
|
!rule.provider ||
|
|
74
74
|
rule.provider === ModelAttributeAuthProvider.FUNCTION
|
|
75
75
|
) {
|
|
76
|
-
authModes.add(
|
|
76
|
+
authModes.add('lambda');
|
|
77
77
|
}
|
|
78
78
|
break;
|
|
79
79
|
case ModelAttributeAuthAllow.GROUPS:
|
|
@@ -81,9 +81,9 @@ function getAuthRules({
|
|
|
81
81
|
// We shouldn't attempt User Pool or OIDC if there isn't an authenticated user
|
|
82
82
|
if (currentUser) {
|
|
83
83
|
if (rule.provider === ModelAttributeAuthProvider.USER_POOLS) {
|
|
84
|
-
authModes.add(
|
|
84
|
+
authModes.add('userPool');
|
|
85
85
|
} else if (rule.provider === ModelAttributeAuthProvider.OIDC) {
|
|
86
|
-
authModes.add(
|
|
86
|
+
authModes.add('oidc');
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
break;
|
|
@@ -96,9 +96,9 @@ function getAuthRules({
|
|
|
96
96
|
!rule.provider ||
|
|
97
97
|
rule.provider === ModelAttributeAuthProvider.USER_POOLS
|
|
98
98
|
) {
|
|
99
|
-
authModes.add(
|
|
99
|
+
authModes.add('userPool');
|
|
100
100
|
} else if (rule.provider === ModelAttributeAuthProvider.IAM) {
|
|
101
|
-
authModes.add(
|
|
101
|
+
authModes.add('iam');
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
@@ -106,13 +106,13 @@ function getAuthRules({
|
|
|
106
106
|
}
|
|
107
107
|
case ModelAttributeAuthAllow.PUBLIC: {
|
|
108
108
|
if (rule.provider === ModelAttributeAuthProvider.IAM) {
|
|
109
|
-
authModes.add(
|
|
109
|
+
authModes.add('iam');
|
|
110
110
|
} else if (
|
|
111
111
|
!rule.provider ||
|
|
112
112
|
rule.provider === ModelAttributeAuthProvider.API_KEY
|
|
113
113
|
) {
|
|
114
114
|
// public with no provider means apiKey
|
|
115
|
-
authModes.add(
|
|
115
|
+
authModes.add('apiKey');
|
|
116
116
|
}
|
|
117
117
|
break;
|
|
118
118
|
}
|
|
@@ -140,10 +140,13 @@ export const multiAuthStrategy: (
|
|
|
140
140
|
) => AuthModeStrategy =
|
|
141
141
|
(amplifyContext: AmplifyContext) =>
|
|
142
142
|
async ({ schema, modelName }) => {
|
|
143
|
-
amplifyContext.Auth = amplifyContext.Auth || Auth;
|
|
144
143
|
let currentUser;
|
|
145
144
|
try {
|
|
146
|
-
|
|
145
|
+
const authSession = await fetchAuthSession();
|
|
146
|
+
if (authSession.tokens.accessToken) {
|
|
147
|
+
// the user is authenticated
|
|
148
|
+
currentUser = authSession;
|
|
149
|
+
}
|
|
147
150
|
} catch (e) {
|
|
148
151
|
// No current user
|
|
149
152
|
}
|
|
@@ -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, ConsoleLogger } from '@aws-amplify/core';
|
|
5
|
+
|
|
13
6
|
import {
|
|
14
7
|
Draft,
|
|
15
8
|
immerable,
|
|
@@ -18,8 +11,8 @@ import {
|
|
|
18
11
|
enablePatches,
|
|
19
12
|
Patch,
|
|
20
13
|
} from 'immer';
|
|
21
|
-
import {
|
|
22
|
-
import Observable,
|
|
14
|
+
import { amplifyUuid, isBrowser } from '@aws-amplify/core/internals/utils';
|
|
15
|
+
import { Observable, SubscriptionLike, filter } from 'rxjs';
|
|
23
16
|
import { defaultAuthStrategy, multiAuthStrategy } from '../authModeStrategies';
|
|
24
17
|
import {
|
|
25
18
|
isPredicatesAll,
|
|
@@ -110,14 +103,14 @@ import {
|
|
|
110
103
|
} from '../predicates/next';
|
|
111
104
|
import { getIdentifierValue } from '../sync/utils';
|
|
112
105
|
import DataStoreConnectivity from '../sync/datastoreConnectivity';
|
|
106
|
+
import { BackgroundProcessManager } from '@aws-amplify/core/internals/utils';
|
|
113
107
|
|
|
114
108
|
setAutoFreeze(true);
|
|
115
109
|
enablePatches();
|
|
116
110
|
|
|
117
|
-
const logger = new
|
|
111
|
+
const logger = new ConsoleLogger('DataStore');
|
|
118
112
|
|
|
119
113
|
const ulid = monotonicUlidFactory(Date.now());
|
|
120
|
-
const { isNode } = browserOrNode();
|
|
121
114
|
|
|
122
115
|
type SettingMetaData = {
|
|
123
116
|
identifier: ManagedIdentifier<Setting, 'id'>;
|
|
@@ -492,7 +485,6 @@ const checkSchemaCodegenVersion = (codegenVersion: string) => {
|
|
|
492
485
|
const majorVersion = 3;
|
|
493
486
|
const minorVersion = 2;
|
|
494
487
|
let isValid = false;
|
|
495
|
-
|
|
496
488
|
try {
|
|
497
489
|
const versionParts = codegenVersion.split('.');
|
|
498
490
|
const [major, minor, patch, patchrevision] = versionParts;
|
|
@@ -843,13 +835,14 @@ const createModelClass = <T extends PersistentModel>(
|
|
|
843
835
|
const id = isInternalModel
|
|
844
836
|
? _id
|
|
845
837
|
: modelDefinition.syncable
|
|
846
|
-
?
|
|
838
|
+
? amplifyUuid()
|
|
847
839
|
: ulid();
|
|
848
840
|
|
|
849
841
|
(<ModelWithIDIdentifier>(<unknown>draft)).id = id;
|
|
850
842
|
} else if (isIdOptionallyManaged(modelDefinition)) {
|
|
851
843
|
// only auto-populate if the id was not provided
|
|
852
|
-
(<ModelWithIDIdentifier>(<unknown>draft)).id =
|
|
844
|
+
(<ModelWithIDIdentifier>(<unknown>draft)).id =
|
|
845
|
+
draft.id || amplifyUuid();
|
|
853
846
|
}
|
|
854
847
|
|
|
855
848
|
if (!isInternallyInitialized) {
|
|
@@ -1331,7 +1324,7 @@ async function checkSchemaVersion(
|
|
|
1331
1324
|
});
|
|
1332
1325
|
}
|
|
1333
1326
|
|
|
1334
|
-
let syncSubscription:
|
|
1327
|
+
let syncSubscription: SubscriptionLike;
|
|
1335
1328
|
|
|
1336
1329
|
function getNamespace(): SchemaNamespace {
|
|
1337
1330
|
const namespace: SchemaNamespace = {
|
|
@@ -1383,7 +1376,6 @@ enum DataStoreState {
|
|
|
1383
1376
|
// https://github.com/aws-amplify/amplify-js/pull/10477/files#r1007363485
|
|
1384
1377
|
class DataStore {
|
|
1385
1378
|
// reference to configured category instances. Used for preserving SSR context
|
|
1386
|
-
private Auth = Auth;
|
|
1387
1379
|
private InternalAPI = InternalAPI;
|
|
1388
1380
|
private Cache = Cache;
|
|
1389
1381
|
|
|
@@ -1414,9 +1406,7 @@ class DataStore {
|
|
|
1414
1406
|
private storageAdapter!: Adapter;
|
|
1415
1407
|
// object that gets passed to descendent classes. Allows us to pass these down by reference
|
|
1416
1408
|
private amplifyContext: AmplifyContext = {
|
|
1417
|
-
Auth: this.Auth,
|
|
1418
1409
|
InternalAPI: this.InternalAPI,
|
|
1419
|
-
Cache: this.Cache,
|
|
1420
1410
|
};
|
|
1421
1411
|
private connectivityMonitor?: DataStoreConnectivity;
|
|
1422
1412
|
|
|
@@ -1531,6 +1521,7 @@ class DataStore {
|
|
|
1531
1521
|
await this.storage.init();
|
|
1532
1522
|
checkSchemaInitialized();
|
|
1533
1523
|
await checkSchemaVersion(this.storage, schema.version);
|
|
1524
|
+
|
|
1534
1525
|
const { aws_appsync_graphqlEndpoint } = this.amplifyConfig;
|
|
1535
1526
|
|
|
1536
1527
|
if (aws_appsync_graphqlEndpoint) {
|
|
@@ -1540,7 +1531,6 @@ class DataStore {
|
|
|
1540
1531
|
);
|
|
1541
1532
|
|
|
1542
1533
|
this.syncPredicates = await this.processSyncExpressions();
|
|
1543
|
-
|
|
1544
1534
|
this.sync = new SyncEngine(
|
|
1545
1535
|
schema,
|
|
1546
1536
|
namespaceResolver,
|
|
@@ -1563,11 +1553,10 @@ class DataStore {
|
|
|
1563
1553
|
.start({ fullSyncInterval: fullSyncIntervalInMilliseconds })
|
|
1564
1554
|
.subscribe({
|
|
1565
1555
|
next: ({ type, data }) => {
|
|
1566
|
-
// In Node, we need to wait for queries to be synced to prevent returning empty arrays.
|
|
1567
1556
|
// In the Browser, we can begin returning data once subscriptions are in place.
|
|
1568
|
-
const readyType =
|
|
1569
|
-
? ControlMessage.
|
|
1570
|
-
: ControlMessage.
|
|
1557
|
+
const readyType = isBrowser()
|
|
1558
|
+
? ControlMessage.SYNC_ENGINE_STORAGE_SUBSCRIBED
|
|
1559
|
+
: ControlMessage.SYNC_ENGINE_SYNC_QUERIES_READY;
|
|
1571
1560
|
|
|
1572
1561
|
if (type === readyType) {
|
|
1573
1562
|
this.initResolve();
|
|
@@ -1737,7 +1726,6 @@ class DataStore {
|
|
|
1737
1726
|
return this.runningProcesses
|
|
1738
1727
|
.add(async () => {
|
|
1739
1728
|
await this.start();
|
|
1740
|
-
|
|
1741
1729
|
if (!this.storage) {
|
|
1742
1730
|
throw new Error('No storage to save to');
|
|
1743
1731
|
}
|
|
@@ -2128,7 +2116,7 @@ class DataStore {
|
|
|
2128
2116
|
}
|
|
2129
2117
|
|
|
2130
2118
|
return new Observable<SubscriptionMessage<T>>(observer => {
|
|
2131
|
-
let source:
|
|
2119
|
+
let source: SubscriptionLike;
|
|
2132
2120
|
|
|
2133
2121
|
this.runningProcesses
|
|
2134
2122
|
.add(async () => {
|
|
@@ -2137,7 +2125,7 @@ class DataStore {
|
|
|
2137
2125
|
// Filter the events returned by Storage according to namespace,
|
|
2138
2126
|
// append original element data, and subscribe to the observable
|
|
2139
2127
|
source = this.storage!.observe(modelConstructor)
|
|
2140
|
-
.filter(({ model }) => namespaceResolver(model) === USER)
|
|
2128
|
+
.pipe(filter(({ model }) => namespaceResolver(model) === USER))
|
|
2141
2129
|
.subscribe({
|
|
2142
2130
|
next: item =>
|
|
2143
2131
|
this.runningProcesses.isOpen &&
|
|
@@ -2211,7 +2199,7 @@ class DataStore {
|
|
|
2211
2199
|
const items = new Map<string, T>();
|
|
2212
2200
|
const itemsChanged = new Map<string, T>();
|
|
2213
2201
|
let deletedItemIds: string[] = [];
|
|
2214
|
-
let handle:
|
|
2202
|
+
let handle: SubscriptionLike;
|
|
2215
2203
|
// let predicate: ModelPredicate<T> | undefined;
|
|
2216
2204
|
let executivePredicate: GroupCondition | undefined;
|
|
2217
2205
|
|
|
@@ -2426,10 +2414,10 @@ class DataStore {
|
|
|
2426
2414
|
data?.model?.name === model.name
|
|
2427
2415
|
) {
|
|
2428
2416
|
generateAndEmitSnapshot();
|
|
2429
|
-
|
|
2417
|
+
hubRemove();
|
|
2430
2418
|
}
|
|
2431
2419
|
};
|
|
2432
|
-
Hub.listen('datastore', hubCallback);
|
|
2420
|
+
const hubRemove = Hub.listen('datastore', hubCallback);
|
|
2433
2421
|
|
|
2434
2422
|
return this.runningProcesses.addCleaner(async () => {
|
|
2435
2423
|
if (handle) {
|
|
@@ -2440,9 +2428,7 @@ class DataStore {
|
|
|
2440
2428
|
};
|
|
2441
2429
|
|
|
2442
2430
|
configure = (config: DataStoreConfig = {}) => {
|
|
2443
|
-
this.amplifyContext.Auth = this.Auth;
|
|
2444
2431
|
this.amplifyContext.InternalAPI = this.InternalAPI;
|
|
2445
|
-
this.amplifyContext.Cache = this.Cache;
|
|
2446
2432
|
|
|
2447
2433
|
const {
|
|
2448
2434
|
DataStore: configDataStore,
|
|
@@ -2458,9 +2444,19 @@ class DataStore {
|
|
|
2458
2444
|
...configFromAmplify
|
|
2459
2445
|
} = config;
|
|
2460
2446
|
|
|
2447
|
+
const currentAppSyncConfig = Amplify.getConfig().API?.GraphQL;
|
|
2448
|
+
|
|
2449
|
+
const appSyncConfig = {
|
|
2450
|
+
aws_appsync_graphqlEndpoint: currentAppSyncConfig?.endpoint,
|
|
2451
|
+
aws_appsync_authenticationType: currentAppSyncConfig?.defaultAuthMode,
|
|
2452
|
+
aws_appsync_region: currentAppSyncConfig?.region,
|
|
2453
|
+
aws_appsync_apiKey: currentAppSyncConfig?.apiKey,
|
|
2454
|
+
};
|
|
2455
|
+
|
|
2461
2456
|
this.amplifyConfig = {
|
|
2462
|
-
...configFromAmplify,
|
|
2463
2457
|
...this.amplifyConfig,
|
|
2458
|
+
...configFromAmplify,
|
|
2459
|
+
...(currentAppSyncConfig && appSyncConfig),
|
|
2464
2460
|
};
|
|
2465
2461
|
|
|
2466
2462
|
this.conflictHandler = this.setConflictHandler(config);
|
|
@@ -2752,6 +2748,11 @@ class DataStore {
|
|
|
2752
2748
|
}
|
|
2753
2749
|
|
|
2754
2750
|
const instance = new DataStore();
|
|
2755
|
-
|
|
2751
|
+
instance.configure({});
|
|
2752
|
+
Hub.listen('core', capsule => {
|
|
2753
|
+
if (capsule.payload.event === 'configure') {
|
|
2754
|
+
instance.configure({});
|
|
2755
|
+
}
|
|
2756
|
+
});
|
|
2756
2757
|
|
|
2757
2758
|
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,8 +24,9 @@ import {
|
|
|
25
24
|
isSafariCompatabilityMode,
|
|
26
25
|
} from '../../util';
|
|
27
26
|
import { StorageAdapterBase } from './StorageAdapterBase';
|
|
27
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
28
28
|
|
|
29
|
-
const logger = new
|
|
29
|
+
const logger = new ConsoleLogger('DataStore');
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* The point after which queries composed of multiple simple OR conditions
|
|
@@ -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,8 +30,9 @@ import {
|
|
|
31
30
|
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
32
31
|
import type AsyncStorageDatabase from './AsyncStorageDatabase';
|
|
33
32
|
import { ModelRelationship } from '../relationship';
|
|
33
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
34
34
|
|
|
35
|
-
const logger = new
|
|
35
|
+
const logger = new ConsoleLogger('DataStore');
|
|
36
36
|
const DB_NAME = 'amplify-datastore';
|
|
37
37
|
|
|
38
38
|
export abstract class StorageAdapterBase implements Adapter {
|
|
@@ -1,13 +1,10 @@
|
|
|
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, isBrowser } from '@aws-amplify/core/internals/utils';
|
|
8
7
|
const getDefaultAdapter: () => Adapter = () => {
|
|
9
|
-
const { isBrowser } = browserOrNode();
|
|
10
|
-
|
|
11
8
|
if ((isBrowser && window.indexedDB) || (isWebWorker() && self.indexedDB)) {
|
|
12
9
|
return IndexedDBAdapter as Adapter;
|
|
13
10
|
}
|
package/src/storage/storage.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
5
|
-
import PushStream from 'zen-push';
|
|
3
|
+
import { Observable, filter, map, Subject } from 'rxjs';
|
|
6
4
|
import { Patch } from 'immer';
|
|
7
5
|
import { ModelInstanceCreator } from '../datastore/datastore';
|
|
8
6
|
import { ModelPredicateCreator } from '../predicates';
|
|
@@ -32,6 +30,8 @@ import {
|
|
|
32
30
|
import { getIdentifierValue } from '../sync/utils';
|
|
33
31
|
import { Adapter } from './adapter';
|
|
34
32
|
import getDefaultAdapter from './adapter/getDefaultAdapter';
|
|
33
|
+
import { Mutex } from '@aws-amplify/core/internals/utils';
|
|
34
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
35
35
|
|
|
36
36
|
export type StorageSubscriptionMessage<T extends PersistentModel> =
|
|
37
37
|
InternalSubscriptionMessage<T> & {
|
|
@@ -41,13 +41,11 @@ export type StorageSubscriptionMessage<T extends PersistentModel> =
|
|
|
41
41
|
export type StorageFacade = Omit<Adapter, 'setUp'>;
|
|
42
42
|
export type Storage = InstanceType<typeof StorageClass>;
|
|
43
43
|
|
|
44
|
-
const logger = new
|
|
44
|
+
const logger = new ConsoleLogger('DataStore');
|
|
45
45
|
class StorageClass implements StorageFacade {
|
|
46
46
|
private initialized: Promise<void> | undefined;
|
|
47
|
-
private readonly pushStream:
|
|
48
|
-
|
|
49
|
-
} & Required<
|
|
50
|
-
ZenObservable.Observer<StorageSubscriptionMessage<PersistentModel>>
|
|
47
|
+
private readonly pushStream: Subject<
|
|
48
|
+
StorageSubscriptionMessage<PersistentModel>
|
|
51
49
|
>;
|
|
52
50
|
|
|
53
51
|
constructor(
|
|
@@ -62,7 +60,7 @@ class StorageClass implements StorageFacade {
|
|
|
62
60
|
private readonly sessionId?: string
|
|
63
61
|
) {
|
|
64
62
|
this.adapter = this.adapter || getDefaultAdapter();
|
|
65
|
-
this.pushStream = new
|
|
63
|
+
this.pushStream = new Subject();
|
|
66
64
|
}
|
|
67
65
|
|
|
68
66
|
static getNamespace() {
|
|
@@ -285,26 +283,33 @@ class StorageClass implements StorageFacade {
|
|
|
285
283
|
(predicate && ModelPredicateCreator.getPredicates(predicate, false)) ||
|
|
286
284
|
{};
|
|
287
285
|
|
|
288
|
-
let result = this.pushStream
|
|
289
|
-
.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
286
|
+
let result = this.pushStream
|
|
287
|
+
.pipe(
|
|
288
|
+
filter(({ mutator }) => {
|
|
289
|
+
return !skipOwn || mutator !== skipOwn;
|
|
290
|
+
})
|
|
291
|
+
)
|
|
292
|
+
.pipe(
|
|
293
|
+
map(
|
|
294
|
+
({ mutator: _mutator, ...message }) =>
|
|
295
|
+
message as SubscriptionMessage<T>
|
|
296
|
+
)
|
|
294
297
|
);
|
|
295
298
|
|
|
296
299
|
if (!listenToAll) {
|
|
297
|
-
result = result.
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
300
|
+
result = result.pipe(
|
|
301
|
+
filter(({ model, element }) => {
|
|
302
|
+
if (modelConstructor !== model) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
301
305
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
306
|
+
if (!!predicates && !!type) {
|
|
307
|
+
return validatePredicate(element, type, predicates);
|
|
308
|
+
}
|
|
305
309
|
|
|
306
|
-
|
|
307
|
-
|
|
310
|
+
return true;
|
|
311
|
+
})
|
|
312
|
+
);
|
|
308
313
|
}
|
|
309
314
|
|
|
310
315
|
return result;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import Observable,
|
|
4
|
-
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
3
|
+
import { Observable, Observer, SubscriptionLike } from 'rxjs';
|
|
5
4
|
import { ReachabilityMonitor } from './datastoreReachability';
|
|
5
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
6
6
|
|
|
7
|
-
const logger = new
|
|
7
|
+
const logger = new ConsoleLogger('DataStore');
|
|
8
8
|
|
|
9
9
|
const RECONNECTING_IN = 5000; // 5s this may be configurable in the future
|
|
10
10
|
|
|
@@ -15,8 +15,8 @@ type ConnectionStatus = {
|
|
|
15
15
|
|
|
16
16
|
export default class DataStoreConnectivity {
|
|
17
17
|
private connectionStatus: ConnectionStatus;
|
|
18
|
-
private observer!:
|
|
19
|
-
private subscription!:
|
|
18
|
+
private observer!: Observer<ConnectionStatus>;
|
|
19
|
+
private subscription!: SubscriptionLike;
|
|
20
20
|
private timeout!: ReturnType<typeof setTimeout>;
|
|
21
21
|
constructor() {
|
|
22
22
|
this.connectionStatus = {
|
|
@@ -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,8 @@
|
|
|
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';
|
|
4
|
-
import {
|
|
3
|
+
import { Reachability } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
import { loadNetInfo } from '@aws-amplify/react-native';
|
|
5
5
|
|
|
6
|
-
export const ReachabilityMonitor = new Reachability().networkMonitor(
|
|
6
|
+
export const ReachabilityMonitor = new Reachability().networkMonitor(
|
|
7
|
+
loadNetInfo()
|
|
8
|
+
);
|
|
@@ -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();
|