@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
package/lib/index.js
CHANGED
|
@@ -27,7 +27,7 @@ var predicates_1 = require("./predicates");
|
|
|
27
27
|
Object.defineProperty(exports, "Predicates", { enumerable: true, get: function () { return predicates_1.Predicates; } });
|
|
28
28
|
Object.defineProperty(exports, "ModelPredicateCreator", { enumerable: true, get: function () { return predicates_1.ModelPredicateCreator; } });
|
|
29
29
|
Object.defineProperty(exports, "ModelSortPredicateCreator", { enumerable: true, get: function () { return predicates_1.ModelSortPredicateCreator; } });
|
|
30
|
-
|
|
30
|
+
const util_1 = require("./util");
|
|
31
31
|
var util_2 = require("./util");
|
|
32
32
|
Object.defineProperty(exports, "NAMESPACES", { enumerable: true, get: function () { return util_2.NAMESPACES; } });
|
|
33
33
|
exports.utils = {
|
package/lib/predicates/index.js
CHANGED
|
@@ -1,46 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.ModelPredicateCreator = exports.Predicates = exports.PredicateAll = exports.comparisonKeys = exports.isPredicatesAll = exports.ModelSortPredicateCreator = void 0;
|
|
40
|
-
|
|
4
|
+
const util_1 = require("../util");
|
|
41
5
|
var sort_1 = require("./sort");
|
|
42
6
|
Object.defineProperty(exports, "ModelSortPredicateCreator", { enumerable: true, get: function () { return sort_1.ModelSortPredicateCreator; } });
|
|
43
|
-
|
|
7
|
+
const predicatesAllSet = new WeakSet();
|
|
44
8
|
function isPredicatesAll(predicate) {
|
|
45
9
|
return predicatesAllSet.has(predicate);
|
|
46
10
|
}
|
|
@@ -48,7 +12,7 @@ exports.isPredicatesAll = isPredicatesAll;
|
|
|
48
12
|
/**
|
|
49
13
|
* The valid logical grouping keys for a predicate group.
|
|
50
14
|
*/
|
|
51
|
-
|
|
15
|
+
const groupKeys = new Set(['and', 'or', 'not']);
|
|
52
16
|
/**
|
|
53
17
|
* Determines whether an object is a GraphQL style predicate "group", which must be an
|
|
54
18
|
* object containing a single "group key", which then contains the child condition(s).
|
|
@@ -62,8 +26,8 @@ var groupKeys = new Set(['and', 'or', 'not']);
|
|
|
62
26
|
*
|
|
63
27
|
* @param o The object to test.
|
|
64
28
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
29
|
+
const isGroup = o => {
|
|
30
|
+
const keys = [...Object.keys(o)];
|
|
67
31
|
return keys.length === 1 && groupKeys.has(keys[0]);
|
|
68
32
|
};
|
|
69
33
|
/**
|
|
@@ -72,7 +36,7 @@ var isGroup = function (o) {
|
|
|
72
36
|
*
|
|
73
37
|
* @param o The object to test.
|
|
74
38
|
*/
|
|
75
|
-
|
|
39
|
+
const isEmpty = o => {
|
|
76
40
|
return !Array.isArray(o) && Object.keys(o).length === 0;
|
|
77
41
|
};
|
|
78
42
|
/**
|
|
@@ -97,8 +61,8 @@ exports.comparisonKeys = new Set([
|
|
|
97
61
|
*
|
|
98
62
|
* @param o The object to test.
|
|
99
63
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
64
|
+
const isComparison = o => {
|
|
65
|
+
const keys = [...Object.keys(o)];
|
|
102
66
|
return !Array.isArray(o) && keys.length === 1 && exports.comparisonKeys.has(keys[0]);
|
|
103
67
|
};
|
|
104
68
|
/**
|
|
@@ -106,9 +70,9 @@ var isComparison = function (o) {
|
|
|
106
70
|
*
|
|
107
71
|
* @param o The object to test.
|
|
108
72
|
*/
|
|
109
|
-
|
|
73
|
+
const isValid = o => {
|
|
110
74
|
if (Array.isArray(o)) {
|
|
111
|
-
return o.every(
|
|
75
|
+
return o.every(v => isValid(v));
|
|
112
76
|
}
|
|
113
77
|
else {
|
|
114
78
|
return Object.keys(o).length <= 1;
|
|
@@ -116,33 +80,24 @@ var isValid = function (o) {
|
|
|
116
80
|
};
|
|
117
81
|
// This symbol is not used at runtime, only its type (unique symbol)
|
|
118
82
|
exports.PredicateAll = Symbol('A predicate that matches all records');
|
|
119
|
-
|
|
120
|
-
|
|
83
|
+
class Predicates {
|
|
84
|
+
static get ALL() {
|
|
85
|
+
const predicate = (c => c);
|
|
86
|
+
predicatesAllSet.add(predicate);
|
|
87
|
+
return predicate;
|
|
121
88
|
}
|
|
122
|
-
|
|
123
|
-
get: function () {
|
|
124
|
-
var predicate = (function (c) { return c; });
|
|
125
|
-
predicatesAllSet.add(predicate);
|
|
126
|
-
return predicate;
|
|
127
|
-
},
|
|
128
|
-
enumerable: false,
|
|
129
|
-
configurable: true
|
|
130
|
-
});
|
|
131
|
-
return Predicates;
|
|
132
|
-
}());
|
|
89
|
+
}
|
|
133
90
|
exports.Predicates = Predicates;
|
|
134
|
-
|
|
135
|
-
function ModelPredicateCreator() {
|
|
136
|
-
}
|
|
91
|
+
class ModelPredicateCreator {
|
|
137
92
|
/**
|
|
138
93
|
* Determines whether the given storage predicate (lookup key) is a predicate
|
|
139
94
|
* key that DataStore recognizes.
|
|
140
95
|
*
|
|
141
96
|
* @param predicate The storage predicate (lookup key) to test.
|
|
142
97
|
*/
|
|
143
|
-
|
|
98
|
+
static isValidPredicate(predicate) {
|
|
144
99
|
return ModelPredicateCreator.predicateGroupsMap.has(predicate);
|
|
145
|
-
}
|
|
100
|
+
}
|
|
146
101
|
/**
|
|
147
102
|
* Looks for the storage predicate AST that corresponds to a given storage
|
|
148
103
|
* predicate key.
|
|
@@ -154,13 +109,12 @@ var ModelPredicateCreator = exports.ModelPredicateCreator = /** @class */ (funct
|
|
|
154
109
|
* @param throwOnInvalid Whether to throw an exception if the predicate
|
|
155
110
|
* isn't a valid DataStore predicate.
|
|
156
111
|
*/
|
|
157
|
-
|
|
158
|
-
if (throwOnInvalid === void 0) { throwOnInvalid = true; }
|
|
112
|
+
static getPredicates(predicate, throwOnInvalid = true) {
|
|
159
113
|
if (throwOnInvalid && !ModelPredicateCreator.isValidPredicate(predicate)) {
|
|
160
114
|
throw new Error('The predicate is not valid');
|
|
161
115
|
}
|
|
162
116
|
return ModelPredicateCreator.predicateGroupsMap.get(predicate);
|
|
163
|
-
}
|
|
117
|
+
}
|
|
164
118
|
/**
|
|
165
119
|
* using the PK values from the given `model` (which can be a partial of T
|
|
166
120
|
* Creates a predicate that matches an instance described by `modelDefinition`
|
|
@@ -169,18 +123,17 @@ var ModelPredicateCreator = exports.ModelPredicateCreator = /** @class */ (funct
|
|
|
169
123
|
* @param modelDefinition The model definition to create a predicate for.
|
|
170
124
|
* @param model The model instance to extract value equalities from.
|
|
171
125
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
and: keyFields.map(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return _a = {}, _a[field] = { eq: operand }, _a;
|
|
126
|
+
static createForPk(modelDefinition, model) {
|
|
127
|
+
const keyFields = (0, util_1.extractPrimaryKeyFieldNames)(modelDefinition);
|
|
128
|
+
const keyValues = (0, util_1.extractPrimaryKeyValues)(model, keyFields);
|
|
129
|
+
const predicate = this.createFromAST(modelDefinition, {
|
|
130
|
+
and: keyFields.map((field, idx) => {
|
|
131
|
+
const operand = keyValues[idx];
|
|
132
|
+
return { [field]: { eq: operand } };
|
|
180
133
|
}),
|
|
181
134
|
});
|
|
182
135
|
return predicate;
|
|
183
|
-
}
|
|
136
|
+
}
|
|
184
137
|
/**
|
|
185
138
|
* Searches a `Model` table for records matching the given equalities object.
|
|
186
139
|
*
|
|
@@ -190,16 +143,12 @@ var ModelPredicateCreator = exports.ModelPredicateCreator = /** @class */ (funct
|
|
|
190
143
|
* @param modelDefinition The model we need a predicate for.
|
|
191
144
|
* @param flatEqualities An object holding field equalities to search for.
|
|
192
145
|
*/
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
and: Object.entries(flatEqualities).map(
|
|
196
|
-
var _b;
|
|
197
|
-
var _c = __read(_a, 2), k = _c[0], v = _c[1];
|
|
198
|
-
return (_b = {}, _b[k] = { eq: v }, _b);
|
|
199
|
-
}),
|
|
146
|
+
static createFromFlatEqualities(modelDefinition, flatEqualities) {
|
|
147
|
+
const ast = {
|
|
148
|
+
and: Object.entries(flatEqualities).map(([k, v]) => ({ [k]: { eq: v } })),
|
|
200
149
|
};
|
|
201
150
|
return this.createFromAST(modelDefinition, ast);
|
|
202
|
-
}
|
|
151
|
+
}
|
|
203
152
|
/**
|
|
204
153
|
* Accepts a GraphQL style filter predicate tree and transforms it into an
|
|
205
154
|
* AST that can be used for a storage adapter predicate. Example input:
|
|
@@ -221,8 +170,7 @@ var ModelPredicateCreator = exports.ModelPredicateCreator = /** @class */ (funct
|
|
|
221
170
|
*
|
|
222
171
|
* @param gql GraphQL style filter node.
|
|
223
172
|
*/
|
|
224
|
-
|
|
225
|
-
var _this = this;
|
|
173
|
+
static transformGraphQLFilterNodeToPredicateAST(gql) {
|
|
226
174
|
if (!isValid(gql)) {
|
|
227
175
|
throw new Error('Invalid GraphQL Condition or subtree: ' + JSON.stringify(gql));
|
|
228
176
|
}
|
|
@@ -233,15 +181,15 @@ var ModelPredicateCreator = exports.ModelPredicateCreator = /** @class */ (funct
|
|
|
233
181
|
};
|
|
234
182
|
}
|
|
235
183
|
else if (isGroup(gql)) {
|
|
236
|
-
|
|
237
|
-
|
|
184
|
+
const groupkey = Object.keys(gql)[0];
|
|
185
|
+
const children = this.transformGraphQLFilterNodeToPredicateAST(gql[groupkey]);
|
|
238
186
|
return {
|
|
239
187
|
type: groupkey,
|
|
240
188
|
predicates: Array.isArray(children) ? children : [children],
|
|
241
189
|
};
|
|
242
190
|
}
|
|
243
191
|
else if (isComparison(gql)) {
|
|
244
|
-
|
|
192
|
+
const operatorKey = Object.keys(gql)[0];
|
|
245
193
|
return {
|
|
246
194
|
operator: operatorKey,
|
|
247
195
|
operand: gql[operatorKey],
|
|
@@ -249,14 +197,17 @@ var ModelPredicateCreator = exports.ModelPredicateCreator = /** @class */ (funct
|
|
|
249
197
|
}
|
|
250
198
|
else {
|
|
251
199
|
if (Array.isArray(gql)) {
|
|
252
|
-
return gql.map(
|
|
200
|
+
return gql.map(o => this.transformGraphQLFilterNodeToPredicateAST(o));
|
|
253
201
|
}
|
|
254
202
|
else {
|
|
255
|
-
|
|
256
|
-
return
|
|
203
|
+
const fieldKey = Object.keys(gql)[0];
|
|
204
|
+
return {
|
|
205
|
+
field: fieldKey,
|
|
206
|
+
...this.transformGraphQLFilterNodeToPredicateAST(gql[fieldKey]),
|
|
207
|
+
};
|
|
257
208
|
}
|
|
258
209
|
}
|
|
259
|
-
}
|
|
210
|
+
}
|
|
260
211
|
/**
|
|
261
212
|
* Accepts a GraphQL style filter predicate tree and transforms it into a predicate
|
|
262
213
|
* that storage adapters understand. Example input:
|
|
@@ -279,14 +230,14 @@ var ModelPredicateCreator = exports.ModelPredicateCreator = /** @class */ (funct
|
|
|
279
230
|
* @param modelDefinition The model that the AST/predicate must be compatible with.
|
|
280
231
|
* @param ast The graphQL style AST that should specify conditions for `modelDefinition`.
|
|
281
232
|
*/
|
|
282
|
-
|
|
283
|
-
|
|
233
|
+
static createFromAST(modelDefinition, ast) {
|
|
234
|
+
const key = {};
|
|
284
235
|
ModelPredicateCreator.predicateGroupsMap.set(key, this.transformGraphQLFilterNodeToPredicateAST(ast));
|
|
285
236
|
return key;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Map of storage predicates (key objects) to storage predicate AST's.
|
|
241
|
+
*/
|
|
242
|
+
ModelPredicateCreator.predicateGroupsMap = new WeakMap();
|
|
243
|
+
exports.ModelPredicateCreator = ModelPredicateCreator;
|