@aws-amplify/datastore 5.0.1-api-v6-models.c1977f8.0 → 5.0.1-api-v6-models.891fe0d.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/lib/authModeStrategies/defaultAuthStrategy.js +1 -1
- package/lib/authModeStrategies/multiAuthStrategy.js +29 -105
- package/lib/datastore/datastore.js +887 -1370
- package/lib/index.js +1 -1
- package/lib/predicates/index.js +53 -102
- package/lib/predicates/next.js +310 -557
- package/lib/predicates/sort.js +24 -27
- package/lib/ssr/index.js +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +115 -449
- package/lib/storage/adapter/AsyncStorageDatabase.js +215 -480
- package/lib/storage/adapter/InMemoryStore.js +27 -101
- package/lib/storage/adapter/InMemoryStore.native.js +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +441 -1002
- package/lib/storage/adapter/StorageAdapterBase.js +177 -396
- package/lib/storage/adapter/getDefaultAdapter/index.js +5 -6
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +2 -2
- package/lib/storage/relationship.js +174 -260
- package/lib/storage/storage.js +244 -507
- package/lib/sync/datastoreConnectivity.js +29 -84
- package/lib/sync/datastoreReachability/index.js +1 -1
- package/lib/sync/datastoreReachability/index.native.js +2 -2
- package/lib/sync/index.js +512 -885
- package/lib/sync/merger.js +30 -133
- package/lib/sync/outbox.js +147 -302
- package/lib/sync/processors/errorMaps.js +30 -80
- package/lib/sync/processors/mutation.js +331 -579
- package/lib/sync/processors/subscription.js +268 -428
- package/lib/sync/processors/sync.js +276 -464
- package/lib/sync/utils.js +248 -393
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.js +16 -58
- package/lib/util.js +335 -575
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +27 -103
- package/lib-esm/datastore/datastore.js +874 -1359
- package/lib-esm/index.js +6 -6
- package/lib-esm/predicates/index.js +54 -104
- package/lib-esm/predicates/next.js +306 -555
- package/lib-esm/predicates/sort.js +24 -27
- package/lib-esm/ssr/index.js +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +111 -446
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +212 -477
- package/lib-esm/storage/adapter/InMemoryStore.js +27 -102
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +436 -997
- package/lib-esm/storage/adapter/StorageAdapterBase.js +172 -392
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -3
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +1 -1
- package/lib-esm/storage/relationship.js +173 -260
- package/lib-esm/storage/storage.js +236 -499
- package/lib-esm/sync/datastoreConnectivity.js +26 -82
- package/lib-esm/sync/datastoreReachability/index.js +1 -1
- package/lib-esm/sync/datastoreReachability/index.native.js +1 -1
- package/lib-esm/sync/index.js +498 -872
- package/lib-esm/sync/merger.js +28 -131
- package/lib-esm/sync/outbox.js +143 -298
- package/lib-esm/sync/processors/errorMaps.js +32 -82
- package/lib-esm/sync/processors/mutation.js +324 -572
- package/lib-esm/sync/processors/subscription.js +258 -418
- package/lib-esm/sync/processors/sync.js +269 -457
- package/lib-esm/sync/utils.js +245 -390
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types.js +16 -59
- package/lib-esm/util.js +335 -577
- package/package.json +12 -12
- package/src/datastore/datastore.ts +4 -3
- package/src/storage/adapter/getDefaultAdapter/index.ts +1 -3
- package/src/sync/processors/mutation.ts +1 -1
- package/src/sync/processors/sync.ts +1 -1
- package/src/sync/utils.ts +1 -1
- package/src/util.ts +44 -6
|
@@ -1,4 +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
|
|
4
|
+
export const defaultAuthStrategy = () => [];
|
|
@@ -1,64 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
38
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
39
|
-
if (!m) return o;
|
|
40
|
-
var i = m.call(o), r, ar = [], e;
|
|
41
|
-
try {
|
|
42
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
43
|
-
}
|
|
44
|
-
catch (error) { e = { error: error }; }
|
|
45
|
-
finally {
|
|
46
|
-
try {
|
|
47
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
48
|
-
}
|
|
49
|
-
finally { if (e) throw e.error; }
|
|
50
|
-
}
|
|
51
|
-
return ar;
|
|
52
|
-
};
|
|
53
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
54
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
55
|
-
if (ar || !(i in from)) {
|
|
56
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
57
|
-
ar[i] = from[i];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
61
|
-
};
|
|
62
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
63
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
64
3
|
import { fetchAuthSession } from '@aws-amplify/core';
|
|
@@ -75,21 +14,21 @@ function getProviderFromRule(rule) {
|
|
|
75
14
|
return rule.provider;
|
|
76
15
|
}
|
|
77
16
|
function sortAuthRulesWithPriority(rules) {
|
|
78
|
-
|
|
17
|
+
const allowSortPriority = [
|
|
79
18
|
ModelAttributeAuthAllow.CUSTOM,
|
|
80
19
|
ModelAttributeAuthAllow.OWNER,
|
|
81
20
|
ModelAttributeAuthAllow.GROUPS,
|
|
82
21
|
ModelAttributeAuthAllow.PRIVATE,
|
|
83
22
|
ModelAttributeAuthAllow.PUBLIC,
|
|
84
23
|
];
|
|
85
|
-
|
|
24
|
+
const providerSortPriority = [
|
|
86
25
|
ModelAttributeAuthProvider.FUNCTION,
|
|
87
26
|
ModelAttributeAuthProvider.USER_POOLS,
|
|
88
27
|
ModelAttributeAuthProvider.OIDC,
|
|
89
28
|
ModelAttributeAuthProvider.IAM,
|
|
90
29
|
ModelAttributeAuthProvider.API_KEY,
|
|
91
30
|
];
|
|
92
|
-
return
|
|
31
|
+
return [...rules].sort((a, b) => {
|
|
93
32
|
if (a.allow === b.allow) {
|
|
94
33
|
return (providerSortPriority.indexOf(getProviderFromRule(a)) -
|
|
95
34
|
providerSortPriority.indexOf(getProviderFromRule(b)));
|
|
@@ -97,11 +36,10 @@ function sortAuthRulesWithPriority(rules) {
|
|
|
97
36
|
return (allowSortPriority.indexOf(a.allow) - allowSortPriority.indexOf(b.allow));
|
|
98
37
|
});
|
|
99
38
|
}
|
|
100
|
-
function getAuthRules(
|
|
101
|
-
var rules = _a.rules, currentUser = _a.currentUser;
|
|
39
|
+
function getAuthRules({ rules, currentUser, }) {
|
|
102
40
|
// Using Set to ensure uniqueness
|
|
103
|
-
|
|
104
|
-
rules.forEach(
|
|
41
|
+
const authModes = new Set();
|
|
42
|
+
rules.forEach(rule => {
|
|
105
43
|
switch (rule.allow) {
|
|
106
44
|
case ModelAttributeAuthAllow.CUSTOM:
|
|
107
45
|
// custom with no provider -> function
|
|
@@ -165,39 +103,25 @@ function getAuthRules(_a) {
|
|
|
165
103
|
* @param param0 The `{schema, modelName}` to inspect.
|
|
166
104
|
* @returns A sorted array of auth modes to attempt.
|
|
167
105
|
*/
|
|
168
|
-
export
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
case 3:
|
|
190
|
-
attributes = schema.namespaces.user.models[modelName].attributes;
|
|
191
|
-
if (attributes) {
|
|
192
|
-
authAttribute = attributes.find(function (attr) { return attr.type === 'auth'; });
|
|
193
|
-
if ((_b = authAttribute === null || authAttribute === void 0 ? void 0 : authAttribute.properties) === null || _b === void 0 ? void 0 : _b.rules) {
|
|
194
|
-
sortedRules = sortAuthRulesWithPriority(authAttribute.properties.rules);
|
|
195
|
-
return [2 /*return*/, getAuthRules({ currentUser: currentUser, rules: sortedRules })];
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return [2 /*return*/, []];
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
};
|
|
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 [];
|
|
203
127
|
};
|