@aws-amplify/datastore 3.14.4 → 3.14.5-unstable.2
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/CHANGELOG.md +0 -8
- package/lib/authModeStrategies/defaultAuthStrategy.d.ts +2 -0
- package/lib/authModeStrategies/index.d.ts +2 -0
- package/lib/authModeStrategies/multiAuthStrategy.d.ts +13 -0
- package/lib/authModeStrategies/multiAuthStrategy.js +6 -64
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.d.ts +207 -0
- package/lib/datastore/datastore.js +703 -297
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/index.d.ts +16 -0
- package/lib/index.js +6 -4
- package/lib/index.js.map +1 -1
- package/lib/predicates/index.d.ts +30 -0
- package/lib/predicates/index.js +127 -6
- package/lib/predicates/index.js.map +1 -1
- package/lib/predicates/next.d.ts +301 -0
- package/lib/predicates/next.js +816 -0
- package/lib/predicates/next.js.map +1 -0
- package/lib/predicates/sort.d.ts +8 -0
- package/lib/predicates/sort.js +10 -4
- package/lib/predicates/sort.js.map +1 -1
- package/lib/ssr/index.d.ts +3 -0
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +42 -0
- package/lib/storage/adapter/AsyncStorageAdapter.js +141 -382
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.d.ts +39 -0
- package/lib/storage/adapter/AsyncStorageDatabase.js +37 -98
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.d.ts +11 -0
- package/lib/storage/adapter/InMemoryStore.js +16 -67
- package/lib/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.native.d.ts +1 -0
- package/lib/storage/adapter/InMemoryStore.native.js +2 -4
- package/lib/storage/adapter/InMemoryStore.native.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.d.ts +61 -0
- package/lib/storage/adapter/IndexedDBAdapter.js +275 -419
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.d.ts +3 -0
- package/lib/storage/adapter/getDefaultAdapter/index.js +3 -5
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.d.ts +3 -0
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +2 -4
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +1 -1
- package/lib/storage/adapter/index.d.ts +9 -0
- package/lib/storage/relationship.d.ts +140 -0
- package/lib/storage/relationship.js +335 -0
- package/lib/storage/relationship.js.map +1 -0
- package/lib/storage/storage.d.ts +50 -0
- package/lib/storage/storage.js +72 -143
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.d.ts +16 -0
- package/lib/sync/datastoreConnectivity.js +6 -55
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/datastoreReachability/index.d.ts +3 -0
- package/lib/sync/datastoreReachability/index.native.d.ts +3 -0
- package/lib/sync/datastoreReachability/index.native.js +2 -4
- package/lib/sync/datastoreReachability/index.native.js.map +1 -1
- package/lib/sync/index.d.ts +89 -0
- package/lib/sync/index.js +49 -124
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.d.ts +17 -0
- package/lib/sync/merger.js +8 -74
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.d.ts +27 -0
- package/lib/sync/outbox.js +24 -97
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/errorMaps.d.ts +17 -0
- package/lib/sync/processors/errorMaps.js +5 -35
- package/lib/sync/processors/errorMaps.js.map +1 -1
- package/lib/sync/processors/mutation.d.ts +58 -0
- package/lib/sync/processors/mutation.js +47 -131
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.d.ts +33 -0
- package/lib/sync/processors/subscription.js +29 -102
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.d.ts +28 -0
- package/lib/sync/processors/sync.js +26 -102
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.d.ts +42 -0
- package/lib/sync/utils.js +40 -103
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.d.ts +554 -0
- package/lib/types.js +9 -39
- package/lib/types.js.map +1 -1
- package/lib/util.d.ts +189 -0
- package/lib/util.js +192 -188
- package/lib/util.js.map +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +2 -57
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +59 -8
- package/lib-esm/datastore/datastore.js +642 -234
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/index.d.ts +3 -2
- package/lib-esm/index.js +2 -1
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/predicates/index.d.ts +16 -2
- package/lib-esm/predicates/index.js +128 -7
- package/lib-esm/predicates/index.js.map +1 -1
- package/lib-esm/predicates/next.d.ts +301 -0
- package/lib-esm/predicates/next.js +812 -0
- package/lib-esm/predicates/next.js.map +1 -0
- package/lib-esm/predicates/sort.js +10 -4
- package/lib-esm/predicates/sort.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.d.ts +2 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +112 -350
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +7 -68
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.d.ts +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.js +1 -52
- package/lib-esm/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +4 -2
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +230 -367
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib-esm/storage/relationship.d.ts +140 -0
- package/lib-esm/storage/relationship.js +333 -0
- package/lib-esm/storage/relationship.js.map +1 -0
- package/lib-esm/storage/storage.d.ts +7 -6
- package/lib-esm/storage/storage.js +33 -101
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +1 -47
- package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
- package/lib-esm/sync/index.js +4 -76
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.js +1 -67
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.js +1 -74
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.js +2 -32
- package/lib-esm/sync/processors/errorMaps.js.map +1 -1
- package/lib-esm/sync/processors/mutation.js +12 -93
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.js +6 -69
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.js +2 -75
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.d.ts +1 -1
- package/lib-esm/sync/utils.js +32 -95
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +63 -10
- package/lib-esm/types.js +7 -38
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +39 -6
- package/lib-esm/util.js +171 -171
- package/lib-esm/util.js.map +1 -1
- package/package.json +21 -14
- package/src/authModeStrategies/multiAuthStrategy.ts +2 -2
- package/src/datastore/datastore.ts +699 -206
- package/src/index.ts +4 -0
- package/src/predicates/index.ts +143 -17
- package/src/predicates/next.ts +967 -0
- package/src/predicates/sort.ts +8 -2
- package/src/storage/adapter/AsyncStorageAdapter.ts +59 -181
- package/src/storage/adapter/AsyncStorageDatabase.ts +16 -15
- package/src/storage/adapter/InMemoryStore.ts +5 -2
- package/src/storage/adapter/IndexedDBAdapter.ts +169 -192
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -2
- package/src/storage/relationship.ts +272 -0
- package/src/storage/storage.ts +56 -37
- package/src/sync/datastoreConnectivity.ts +4 -4
- package/src/sync/index.ts +22 -28
- package/src/sync/merger.ts +1 -1
- package/src/sync/outbox.ts +6 -6
- package/src/sync/processors/errorMaps.ts +1 -1
- package/src/sync/processors/mutation.ts +23 -19
- package/src/sync/processors/subscription.ts +20 -16
- package/src/sync/processors/sync.ts +17 -17
- package/src/sync/utils.ts +42 -48
- package/src/types.ts +128 -16
- package/src/util.ts +108 -150
- package/build.js +0 -5
- package/dist/aws-amplify-datastore.js +0 -92787
- package/dist/aws-amplify-datastore.js.map +0 -1
- package/dist/aws-amplify-datastore.min.js +0 -66
- package/dist/aws-amplify-datastore.min.js.map +0 -1
- package/index.js +0 -7
- package/webpack.config.dev.js +0 -6
package/src/index.ts
CHANGED
|
@@ -3,6 +3,8 @@ export {
|
|
|
3
3
|
DataStoreClass,
|
|
4
4
|
initSchema,
|
|
5
5
|
ModelInstanceCreator,
|
|
6
|
+
AsyncCollection,
|
|
7
|
+
AsyncItem,
|
|
6
8
|
} from './datastore/datastore';
|
|
7
9
|
|
|
8
10
|
export {
|
|
@@ -20,6 +22,8 @@ import {
|
|
|
20
22
|
isModelConstructor,
|
|
21
23
|
} from './util';
|
|
22
24
|
|
|
25
|
+
export { NAMESPACES } from './util';
|
|
26
|
+
|
|
23
27
|
export const utils = {
|
|
24
28
|
USER,
|
|
25
29
|
traverseModel,
|
package/src/predicates/index.ts
CHANGED
|
@@ -8,11 +8,7 @@ import {
|
|
|
8
8
|
ProducerModelPredicate,
|
|
9
9
|
SchemaModel,
|
|
10
10
|
} from '../types';
|
|
11
|
-
import {
|
|
12
|
-
exhaustiveCheck,
|
|
13
|
-
extractPrimaryKeyFieldNames,
|
|
14
|
-
extractPrimaryKeyValues,
|
|
15
|
-
} from '../util';
|
|
11
|
+
import { extractPrimaryKeyFieldNames, extractPrimaryKeyValues } from '../util';
|
|
16
12
|
|
|
17
13
|
export { ModelSortPredicateCreator } from './sort';
|
|
18
14
|
|
|
@@ -24,6 +20,37 @@ export function isPredicatesAll(
|
|
|
24
20
|
return predicatesAllSet.has(predicate);
|
|
25
21
|
}
|
|
26
22
|
|
|
23
|
+
const groupKeys = new Set(['and', 'or', 'not']);
|
|
24
|
+
const isGroup = o => {
|
|
25
|
+
const keys = [...Object.keys(o)];
|
|
26
|
+
return keys.length === 1 && groupKeys.has(keys[0]);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const comparisonKeys = new Set([
|
|
30
|
+
'eq',
|
|
31
|
+
'ne',
|
|
32
|
+
'gt',
|
|
33
|
+
'lt',
|
|
34
|
+
'ge',
|
|
35
|
+
'le',
|
|
36
|
+
'contains',
|
|
37
|
+
'notContains',
|
|
38
|
+
'beginsWith',
|
|
39
|
+
'between',
|
|
40
|
+
]);
|
|
41
|
+
const isComparison = o => {
|
|
42
|
+
const keys = [...Object.keys(o)];
|
|
43
|
+
return !Array.isArray(o) && keys.length === 1 && comparisonKeys.has(keys[0]);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const isValid = o => {
|
|
47
|
+
if (Array.isArray(o)) {
|
|
48
|
+
return o.every(v => isValid(v));
|
|
49
|
+
} else {
|
|
50
|
+
return Object.keys(o).length === 1;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
27
54
|
// This symbol is not used at runtime, only its type (unique symbol)
|
|
28
55
|
export const PredicateAll = Symbol('A predicate that matches all records');
|
|
29
56
|
|
|
@@ -43,20 +70,21 @@ export class ModelPredicateCreator {
|
|
|
43
70
|
PredicatesGroup<any>
|
|
44
71
|
>();
|
|
45
72
|
|
|
46
|
-
|
|
73
|
+
static createPredicateBuilder<T extends PersistentModel>(
|
|
47
74
|
modelDefinition: SchemaModel
|
|
48
75
|
) {
|
|
49
76
|
const { name: modelName } = modelDefinition;
|
|
50
77
|
const fieldNames = new Set<keyof T>(Object.keys(modelDefinition.fields));
|
|
51
78
|
|
|
52
79
|
let handler: ProxyHandler<ModelPredicate<T>>;
|
|
80
|
+
|
|
53
81
|
const predicate = new Proxy(
|
|
54
82
|
{} as ModelPredicate<T>,
|
|
55
83
|
(handler = {
|
|
56
84
|
get(
|
|
57
|
-
|
|
85
|
+
_,
|
|
58
86
|
propertyKey,
|
|
59
|
-
|
|
87
|
+
self: ModelPredicate<T>
|
|
60
88
|
): PredicateExpression<T, any> {
|
|
61
89
|
const groupType = propertyKey as keyof PredicateGroups<T>;
|
|
62
90
|
|
|
@@ -80,7 +108,7 @@ export class ModelPredicateCreator {
|
|
|
80
108
|
|
|
81
109
|
// Set the recorder group
|
|
82
110
|
ModelPredicateCreator.predicateGroupsMap.set(
|
|
83
|
-
tmpPredicateRecorder,
|
|
111
|
+
tmpPredicateRecorder as any,
|
|
84
112
|
group
|
|
85
113
|
);
|
|
86
114
|
|
|
@@ -89,15 +117,15 @@ export class ModelPredicateCreator {
|
|
|
89
117
|
|
|
90
118
|
// Push the group to the top-level recorder
|
|
91
119
|
ModelPredicateCreator.predicateGroupsMap
|
|
92
|
-
.get(
|
|
120
|
+
.get(self as any)!
|
|
93
121
|
.predicates.push(group);
|
|
94
122
|
|
|
95
|
-
return
|
|
123
|
+
return self;
|
|
96
124
|
};
|
|
97
125
|
|
|
98
126
|
return result;
|
|
99
127
|
default:
|
|
100
|
-
|
|
128
|
+
// intentionally blank.
|
|
101
129
|
}
|
|
102
130
|
|
|
103
131
|
const field = propertyKey as keyof T;
|
|
@@ -113,9 +141,9 @@ export class ModelPredicateCreator {
|
|
|
113
141
|
operand: any
|
|
114
142
|
) => {
|
|
115
143
|
ModelPredicateCreator.predicateGroupsMap
|
|
116
|
-
.get(
|
|
144
|
+
.get(self as any)!
|
|
117
145
|
.predicates.push({ field, operator, operand });
|
|
118
|
-
return
|
|
146
|
+
return self;
|
|
119
147
|
};
|
|
120
148
|
return result;
|
|
121
149
|
},
|
|
@@ -126,7 +154,7 @@ export class ModelPredicateCreator {
|
|
|
126
154
|
type: 'and',
|
|
127
155
|
predicates: [],
|
|
128
156
|
};
|
|
129
|
-
ModelPredicateCreator.predicateGroupsMap.set(predicate, group);
|
|
157
|
+
ModelPredicateCreator.predicateGroupsMap.set(predicate as any, group);
|
|
130
158
|
|
|
131
159
|
return predicate;
|
|
132
160
|
}
|
|
@@ -145,12 +173,12 @@ export class ModelPredicateCreator {
|
|
|
145
173
|
throw new Error('The predicate is not valid');
|
|
146
174
|
}
|
|
147
175
|
|
|
148
|
-
return ModelPredicateCreator.predicateGroupsMap.get(predicate);
|
|
176
|
+
return ModelPredicateCreator.predicateGroupsMap.get(predicate as any);
|
|
149
177
|
}
|
|
150
178
|
|
|
151
179
|
// transforms cb-style predicate into Proxy
|
|
152
180
|
static createFromExisting<T extends PersistentModel>(
|
|
153
|
-
modelDefinition
|
|
181
|
+
modelDefinition?: SchemaModel,
|
|
154
182
|
existing?: ProducerModelPredicate<T>
|
|
155
183
|
) {
|
|
156
184
|
if (!existing || !modelDefinition) {
|
|
@@ -189,4 +217,102 @@ export class ModelPredicateCreator {
|
|
|
189
217
|
|
|
190
218
|
return modelPredicate;
|
|
191
219
|
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Searches a `Model` table for records matching the given equalities object.
|
|
223
|
+
*
|
|
224
|
+
* This only matches against fields given in the equalities object. No other
|
|
225
|
+
* fields are tested by the predicate.
|
|
226
|
+
*
|
|
227
|
+
* @param modelDefinition The model we need a predicate for.
|
|
228
|
+
* @param flatEqualities An object holding field equalities to search for.
|
|
229
|
+
*/
|
|
230
|
+
static createFromFlatEqualities<T extends PersistentModel>(
|
|
231
|
+
modelDefinition: SchemaModel,
|
|
232
|
+
flatEqualities: Record<string, any>
|
|
233
|
+
) {
|
|
234
|
+
let predicate =
|
|
235
|
+
ModelPredicateCreator.createPredicateBuilder<T>(modelDefinition);
|
|
236
|
+
|
|
237
|
+
for (const [field, value] of Object.entries(flatEqualities)) {
|
|
238
|
+
predicate = predicate[field]('eq' as any, value);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return predicate;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
static createGroupFromExisting<T extends PersistentModel>(
|
|
245
|
+
modelDefinition: SchemaModel,
|
|
246
|
+
group: 'and' | 'or' | 'not',
|
|
247
|
+
existingPredicates: (ProducerModelPredicate<T> | ModelPredicate<T>)[]
|
|
248
|
+
) {
|
|
249
|
+
let outer =
|
|
250
|
+
ModelPredicateCreator.createPredicateBuilder<T>(modelDefinition);
|
|
251
|
+
|
|
252
|
+
outer = outer[group](seed => {
|
|
253
|
+
let inner = seed;
|
|
254
|
+
for (const existing of existingPredicates) {
|
|
255
|
+
if (typeof existing === 'function') {
|
|
256
|
+
inner = existing(inner);
|
|
257
|
+
} else {
|
|
258
|
+
ModelPredicateCreator.predicateGroupsMap
|
|
259
|
+
.get(inner)
|
|
260
|
+
?.predicates.push(
|
|
261
|
+
ModelPredicateCreator.predicateGroupsMap.get(
|
|
262
|
+
existing as ModelPredicate<T>
|
|
263
|
+
)!
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return inner;
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
return outer;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
static transformGraphQLtoPredicateAST(gql: any) {
|
|
274
|
+
if (!isValid(gql)) {
|
|
275
|
+
throw new Error('Invalid QGL AST: ' + gql);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (isGroup(gql)) {
|
|
279
|
+
const groupkey = Object.keys(gql)[0];
|
|
280
|
+
const children = this.transformGraphQLtoPredicateAST(gql[groupkey]);
|
|
281
|
+
return {
|
|
282
|
+
type: groupkey,
|
|
283
|
+
predicates: Array.isArray(children) ? children : [children],
|
|
284
|
+
};
|
|
285
|
+
} else if (isComparison(gql)) {
|
|
286
|
+
const operatorKey = Object.keys(gql)[0];
|
|
287
|
+
return {
|
|
288
|
+
operator: operatorKey,
|
|
289
|
+
operand: gql[operatorKey],
|
|
290
|
+
};
|
|
291
|
+
} else {
|
|
292
|
+
if (Array.isArray(gql)) {
|
|
293
|
+
return gql.map(o => this.transformGraphQLtoPredicateAST(o));
|
|
294
|
+
} else {
|
|
295
|
+
const fieldKey = Object.keys(gql)[0];
|
|
296
|
+
return {
|
|
297
|
+
field: fieldKey,
|
|
298
|
+
...this.transformGraphQLtoPredicateAST(gql[fieldKey]),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
static createFromAST(
|
|
305
|
+
modelDefinition: SchemaModel,
|
|
306
|
+
ast: any
|
|
307
|
+
): ModelPredicate<any> {
|
|
308
|
+
const predicate =
|
|
309
|
+
ModelPredicateCreator.createPredicateBuilder(modelDefinition);
|
|
310
|
+
|
|
311
|
+
ModelPredicateCreator.predicateGroupsMap.set(
|
|
312
|
+
predicate,
|
|
313
|
+
this.transformGraphQLtoPredicateAST(ast)
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
return predicate;
|
|
317
|
+
}
|
|
192
318
|
}
|