@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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// Default behavior is to use the primary auth mode for an API,
|
|
2
2
|
// so we are returning an empty array so that DataStore will default
|
|
3
3
|
// to using the primary auth mode.
|
|
4
|
-
export
|
|
5
|
-
//# sourceMappingURL=defaultAuthStrategy.js.map
|
|
4
|
+
export const defaultAuthStrategy = () => [];
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { __awaiter, __generator, __read, __spread } from "tslib";
|
|
2
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import {
|
|
5
|
-
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
|
|
3
|
+
import { fetchAuthSession } from '@aws-amplify/core';
|
|
6
4
|
import { ModelAttributeAuthProvider, ModelAttributeAuthAllow, } from '../types';
|
|
7
5
|
function getProviderFromRule(rule) {
|
|
8
6
|
// private with no provider means userPools
|
|
@@ -16,21 +14,21 @@ function getProviderFromRule(rule) {
|
|
|
16
14
|
return rule.provider;
|
|
17
15
|
}
|
|
18
16
|
function sortAuthRulesWithPriority(rules) {
|
|
19
|
-
|
|
17
|
+
const allowSortPriority = [
|
|
20
18
|
ModelAttributeAuthAllow.CUSTOM,
|
|
21
19
|
ModelAttributeAuthAllow.OWNER,
|
|
22
20
|
ModelAttributeAuthAllow.GROUPS,
|
|
23
21
|
ModelAttributeAuthAllow.PRIVATE,
|
|
24
22
|
ModelAttributeAuthAllow.PUBLIC,
|
|
25
23
|
];
|
|
26
|
-
|
|
24
|
+
const providerSortPriority = [
|
|
27
25
|
ModelAttributeAuthProvider.FUNCTION,
|
|
28
26
|
ModelAttributeAuthProvider.USER_POOLS,
|
|
29
27
|
ModelAttributeAuthProvider.OIDC,
|
|
30
28
|
ModelAttributeAuthProvider.IAM,
|
|
31
29
|
ModelAttributeAuthProvider.API_KEY,
|
|
32
30
|
];
|
|
33
|
-
return
|
|
31
|
+
return [...rules].sort((a, b) => {
|
|
34
32
|
if (a.allow === b.allow) {
|
|
35
33
|
return (providerSortPriority.indexOf(getProviderFromRule(a)) -
|
|
36
34
|
providerSortPriority.indexOf(getProviderFromRule(b)));
|
|
@@ -38,17 +36,16 @@ function sortAuthRulesWithPriority(rules) {
|
|
|
38
36
|
return (allowSortPriority.indexOf(a.allow) - allowSortPriority.indexOf(b.allow));
|
|
39
37
|
});
|
|
40
38
|
}
|
|
41
|
-
function getAuthRules(
|
|
42
|
-
var rules = _a.rules, currentUser = _a.currentUser;
|
|
39
|
+
function getAuthRules({ rules, currentUser, }) {
|
|
43
40
|
// Using Set to ensure uniqueness
|
|
44
|
-
|
|
45
|
-
rules.forEach(
|
|
41
|
+
const authModes = new Set();
|
|
42
|
+
rules.forEach(rule => {
|
|
46
43
|
switch (rule.allow) {
|
|
47
44
|
case ModelAttributeAuthAllow.CUSTOM:
|
|
48
45
|
// custom with no provider -> function
|
|
49
46
|
if (!rule.provider ||
|
|
50
47
|
rule.provider === ModelAttributeAuthProvider.FUNCTION) {
|
|
51
|
-
authModes.add(
|
|
48
|
+
authModes.add('lambda');
|
|
52
49
|
}
|
|
53
50
|
break;
|
|
54
51
|
case ModelAttributeAuthAllow.GROUPS:
|
|
@@ -56,10 +53,10 @@ function getAuthRules(_a) {
|
|
|
56
53
|
// We shouldn't attempt User Pool or OIDC if there isn't an authenticated user
|
|
57
54
|
if (currentUser) {
|
|
58
55
|
if (rule.provider === ModelAttributeAuthProvider.USER_POOLS) {
|
|
59
|
-
authModes.add(
|
|
56
|
+
authModes.add('userPool');
|
|
60
57
|
}
|
|
61
58
|
else if (rule.provider === ModelAttributeAuthProvider.OIDC) {
|
|
62
|
-
authModes.add(
|
|
59
|
+
authModes.add('oidc');
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
62
|
break;
|
|
@@ -70,22 +67,22 @@ function getAuthRules(_a) {
|
|
|
70
67
|
// private with no provider means userPools
|
|
71
68
|
if (!rule.provider ||
|
|
72
69
|
rule.provider === ModelAttributeAuthProvider.USER_POOLS) {
|
|
73
|
-
authModes.add(
|
|
70
|
+
authModes.add('userPool');
|
|
74
71
|
}
|
|
75
72
|
else if (rule.provider === ModelAttributeAuthProvider.IAM) {
|
|
76
|
-
authModes.add(
|
|
73
|
+
authModes.add('iam');
|
|
77
74
|
}
|
|
78
75
|
}
|
|
79
76
|
break;
|
|
80
77
|
}
|
|
81
78
|
case ModelAttributeAuthAllow.PUBLIC: {
|
|
82
79
|
if (rule.provider === ModelAttributeAuthProvider.IAM) {
|
|
83
|
-
authModes.add(
|
|
80
|
+
authModes.add('iam');
|
|
84
81
|
}
|
|
85
82
|
else if (!rule.provider ||
|
|
86
83
|
rule.provider === ModelAttributeAuthProvider.API_KEY) {
|
|
87
84
|
// public with no provider means apiKey
|
|
88
|
-
authModes.add(
|
|
85
|
+
authModes.add('apiKey');
|
|
89
86
|
}
|
|
90
87
|
break;
|
|
91
88
|
}
|
|
@@ -106,39 +103,25 @@ function getAuthRules(_a) {
|
|
|
106
103
|
* @param param0 The `{schema, modelName}` to inspect.
|
|
107
104
|
* @returns A sorted array of auth modes to attempt.
|
|
108
105
|
*/
|
|
109
|
-
export
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
attributes = schema.namespaces.user.models[modelName].attributes;
|
|
131
|
-
if (attributes) {
|
|
132
|
-
authAttribute = attributes.find(function (attr) { return attr.type === 'auth'; });
|
|
133
|
-
if ((_b = authAttribute === null || authAttribute === void 0 ? void 0 : authAttribute.properties) === null || _b === void 0 ? void 0 : _b.rules) {
|
|
134
|
-
sortedRules = sortAuthRulesWithPriority(authAttribute.properties.rules);
|
|
135
|
-
return [2 /*return*/, getAuthRules({ currentUser: currentUser, rules: sortedRules })];
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return [2 /*return*/, []];
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
};
|
|
106
|
+
export const multiAuthStrategy = (amplifyContext) => async ({ schema, modelName }) => {
|
|
107
|
+
let currentUser;
|
|
108
|
+
try {
|
|
109
|
+
const authSession = await fetchAuthSession();
|
|
110
|
+
if (authSession.tokens.accessToken) {
|
|
111
|
+
// the user is authenticated
|
|
112
|
+
currentUser = authSession;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
// No current user
|
|
117
|
+
}
|
|
118
|
+
const { attributes } = schema.namespaces.user.models[modelName];
|
|
119
|
+
if (attributes) {
|
|
120
|
+
const authAttribute = attributes.find(attr => attr.type === 'auth');
|
|
121
|
+
if (authAttribute?.properties?.rules) {
|
|
122
|
+
const sortedRules = sortAuthRulesWithPriority(authAttribute.properties.rules);
|
|
123
|
+
return getAuthRules({ currentUser, rules: sortedRules });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return [];
|
|
143
127
|
};
|
|
144
|
-
//# sourceMappingURL=multiAuthStrategy.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Observable from '
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
2
|
import { PredicateAll } from '../predicates';
|
|
3
|
-
import { ConflictHandler, DataStoreConfig,
|
|
3
|
+
import { ConflictHandler, DataStoreConfig, ProducerPaginationInput, PersistentModel, PersistentModelConstructor, Schema, SubscriptionMessage, DataStoreSnapshot, TypeConstructorMap, ErrorHandler, ObserveQueryOptions, PersistentModelMetaData, IdentifierFieldOrIdentifierObject, RecursiveModelPredicateExtender, ModelPredicateExtender } from '../types';
|
|
4
4
|
export declare let syncClasses: TypeConstructorMap;
|
|
5
5
|
/**
|
|
6
6
|
* Describes whether and to what a model is attached for lazy loading purposes.
|
|
@@ -41,8 +41,8 @@ export declare function attached<T extends PersistentModel | PersistentModel[]>(
|
|
|
41
41
|
*
|
|
42
42
|
* @param instance A model instance
|
|
43
43
|
*/
|
|
44
|
-
export declare const getAttachment: (instance:
|
|
45
|
-
declare const initSchema: (userSchema: Schema) =>
|
|
44
|
+
export declare const getAttachment: (instance: PersistentModel) => ModelAttachment;
|
|
45
|
+
declare const initSchema: (userSchema: Schema) => TypeConstructorMap;
|
|
46
46
|
/**
|
|
47
47
|
* Constructs a model and records it with its metadata in a weakset. Allows for
|
|
48
48
|
* the separate storage of core model fields and Amplify/DataStore metadata
|
|
@@ -92,7 +92,6 @@ export declare class AsyncCollection<T> implements AsyncIterable<T> {
|
|
|
92
92
|
}): Promise<T[]>;
|
|
93
93
|
}
|
|
94
94
|
declare class DataStore {
|
|
95
|
-
private Auth;
|
|
96
95
|
private InternalAPI;
|
|
97
96
|
private Cache;
|
|
98
97
|
private amplifyConfig;
|