@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/lib/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const utils: {
|
|
|
9
9
|
item: T;
|
|
10
10
|
instance: T;
|
|
11
11
|
}[];
|
|
12
|
-
validatePredicate: <T_2 extends Readonly<Record<string, any>>>(model: T_2, groupType:
|
|
12
|
+
validatePredicate: <T_2 extends Readonly<Record<string, any>>>(model: T_2, groupType: keyof import("./types").PredicateGroups<T_2>, predicatesOrGroups: (import("./types").PredicateObject<T_2> | import("./types").PredicatesGroup<T_2>)[]) => any;
|
|
13
13
|
isNonModelConstructor: (obj: any) => obj is import("./types").NonModelTypeConstructor<any>;
|
|
14
14
|
isModelConstructor: <T_3 extends Readonly<Record<string, any>>>(obj: any) => obj is import("./types").PersistentModelConstructor<T_3>;
|
|
15
15
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
17
|
+
exports.utils = exports.NAMESPACES = exports.ModelSortPredicateCreator = exports.ModelPredicateCreator = exports.Predicates = exports.AsyncItem = exports.AsyncCollection = exports.initSchema = exports.DataStoreClass = exports.DataStore = void 0;
|
|
4
18
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
19
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
20
|
var datastore_1 = require("./datastore/datastore");
|
|
7
|
-
exports
|
|
8
|
-
exports
|
|
9
|
-
exports
|
|
10
|
-
exports
|
|
11
|
-
exports
|
|
21
|
+
Object.defineProperty(exports, "DataStore", { enumerable: true, get: function () { return datastore_1.DataStore; } });
|
|
22
|
+
Object.defineProperty(exports, "DataStoreClass", { enumerable: true, get: function () { return datastore_1.DataStoreClass; } });
|
|
23
|
+
Object.defineProperty(exports, "initSchema", { enumerable: true, get: function () { return datastore_1.initSchema; } });
|
|
24
|
+
Object.defineProperty(exports, "AsyncCollection", { enumerable: true, get: function () { return datastore_1.AsyncCollection; } });
|
|
25
|
+
Object.defineProperty(exports, "AsyncItem", { enumerable: true, get: function () { return datastore_1.AsyncItem; } });
|
|
12
26
|
var predicates_1 = require("./predicates");
|
|
13
|
-
exports
|
|
14
|
-
exports
|
|
15
|
-
exports
|
|
16
|
-
|
|
27
|
+
Object.defineProperty(exports, "Predicates", { enumerable: true, get: function () { return predicates_1.Predicates; } });
|
|
28
|
+
Object.defineProperty(exports, "ModelPredicateCreator", { enumerable: true, get: function () { return predicates_1.ModelPredicateCreator; } });
|
|
29
|
+
Object.defineProperty(exports, "ModelSortPredicateCreator", { enumerable: true, get: function () { return predicates_1.ModelSortPredicateCreator; } });
|
|
30
|
+
const util_1 = require("./util");
|
|
17
31
|
var util_2 = require("./util");
|
|
18
|
-
exports
|
|
32
|
+
Object.defineProperty(exports, "NAMESPACES", { enumerable: true, get: function () { return util_2.NAMESPACES; } });
|
|
19
33
|
exports.utils = {
|
|
20
34
|
USER: util_1.USER,
|
|
21
35
|
traverseModel: util_1.traverseModel,
|
|
@@ -23,5 +37,4 @@ exports.utils = {
|
|
|
23
37
|
isNonModelConstructor: util_1.isNonModelConstructor,
|
|
24
38
|
isModelConstructor: util_1.isModelConstructor,
|
|
25
39
|
};
|
|
26
|
-
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
|
40
|
+
__exportStar(require("./types"), exports);
|
package/lib/predicates/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.ModelPredicateCreator = exports.Predicates = exports.PredicateAll = exports.comparisonKeys = exports.isPredicatesAll = exports.ModelSortPredicateCreator = void 0;
|
|
4
|
+
const util_1 = require("../util");
|
|
5
5
|
var sort_1 = require("./sort");
|
|
6
|
-
exports
|
|
7
|
-
|
|
6
|
+
Object.defineProperty(exports, "ModelSortPredicateCreator", { enumerable: true, get: function () { return sort_1.ModelSortPredicateCreator; } });
|
|
7
|
+
const predicatesAllSet = new WeakSet();
|
|
8
8
|
function isPredicatesAll(predicate) {
|
|
9
9
|
return predicatesAllSet.has(predicate);
|
|
10
10
|
}
|
|
@@ -12,7 +12,7 @@ exports.isPredicatesAll = isPredicatesAll;
|
|
|
12
12
|
/**
|
|
13
13
|
* The valid logical grouping keys for a predicate group.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
const groupKeys = new Set(['and', 'or', 'not']);
|
|
16
16
|
/**
|
|
17
17
|
* Determines whether an object is a GraphQL style predicate "group", which must be an
|
|
18
18
|
* object containing a single "group key", which then contains the child condition(s).
|
|
@@ -26,8 +26,8 @@ var groupKeys = new Set(['and', 'or', 'not']);
|
|
|
26
26
|
*
|
|
27
27
|
* @param o The object to test.
|
|
28
28
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const isGroup = o => {
|
|
30
|
+
const keys = [...Object.keys(o)];
|
|
31
31
|
return keys.length === 1 && groupKeys.has(keys[0]);
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
@@ -36,7 +36,7 @@ var isGroup = function (o) {
|
|
|
36
36
|
*
|
|
37
37
|
* @param o The object to test.
|
|
38
38
|
*/
|
|
39
|
-
|
|
39
|
+
const isEmpty = o => {
|
|
40
40
|
return !Array.isArray(o) && Object.keys(o).length === 0;
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
@@ -61,8 +61,8 @@ exports.comparisonKeys = new Set([
|
|
|
61
61
|
*
|
|
62
62
|
* @param o The object to test.
|
|
63
63
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const isComparison = o => {
|
|
65
|
+
const keys = [...Object.keys(o)];
|
|
66
66
|
return !Array.isArray(o) && keys.length === 1 && exports.comparisonKeys.has(keys[0]);
|
|
67
67
|
};
|
|
68
68
|
/**
|
|
@@ -70,9 +70,9 @@ var isComparison = function (o) {
|
|
|
70
70
|
*
|
|
71
71
|
* @param o The object to test.
|
|
72
72
|
*/
|
|
73
|
-
|
|
73
|
+
const isValid = o => {
|
|
74
74
|
if (Array.isArray(o)) {
|
|
75
|
-
return o.every(
|
|
75
|
+
return o.every(v => isValid(v));
|
|
76
76
|
}
|
|
77
77
|
else {
|
|
78
78
|
return Object.keys(o).length <= 1;
|
|
@@ -80,33 +80,24 @@ var isValid = function (o) {
|
|
|
80
80
|
};
|
|
81
81
|
// This symbol is not used at runtime, only its type (unique symbol)
|
|
82
82
|
exports.PredicateAll = Symbol('A predicate that matches all records');
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
class Predicates {
|
|
84
|
+
static get ALL() {
|
|
85
|
+
const predicate = (c => c);
|
|
86
|
+
predicatesAllSet.add(predicate);
|
|
87
|
+
return predicate;
|
|
85
88
|
}
|
|
86
|
-
|
|
87
|
-
get: function () {
|
|
88
|
-
var predicate = (function (c) { return c; });
|
|
89
|
-
predicatesAllSet.add(predicate);
|
|
90
|
-
return predicate;
|
|
91
|
-
},
|
|
92
|
-
enumerable: true,
|
|
93
|
-
configurable: true
|
|
94
|
-
});
|
|
95
|
-
return Predicates;
|
|
96
|
-
}());
|
|
89
|
+
}
|
|
97
90
|
exports.Predicates = Predicates;
|
|
98
|
-
|
|
99
|
-
function ModelPredicateCreator() {
|
|
100
|
-
}
|
|
91
|
+
class ModelPredicateCreator {
|
|
101
92
|
/**
|
|
102
93
|
* Determines whether the given storage predicate (lookup key) is a predicate
|
|
103
94
|
* key that DataStore recognizes.
|
|
104
95
|
*
|
|
105
96
|
* @param predicate The storage predicate (lookup key) to test.
|
|
106
97
|
*/
|
|
107
|
-
|
|
98
|
+
static isValidPredicate(predicate) {
|
|
108
99
|
return ModelPredicateCreator.predicateGroupsMap.has(predicate);
|
|
109
|
-
}
|
|
100
|
+
}
|
|
110
101
|
/**
|
|
111
102
|
* Looks for the storage predicate AST that corresponds to a given storage
|
|
112
103
|
* predicate key.
|
|
@@ -118,13 +109,12 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
118
109
|
* @param throwOnInvalid Whether to throw an exception if the predicate
|
|
119
110
|
* isn't a valid DataStore predicate.
|
|
120
111
|
*/
|
|
121
|
-
|
|
122
|
-
if (throwOnInvalid === void 0) { throwOnInvalid = true; }
|
|
112
|
+
static getPredicates(predicate, throwOnInvalid = true) {
|
|
123
113
|
if (throwOnInvalid && !ModelPredicateCreator.isValidPredicate(predicate)) {
|
|
124
114
|
throw new Error('The predicate is not valid');
|
|
125
115
|
}
|
|
126
116
|
return ModelPredicateCreator.predicateGroupsMap.get(predicate);
|
|
127
|
-
}
|
|
117
|
+
}
|
|
128
118
|
/**
|
|
129
119
|
* using the PK values from the given `model` (which can be a partial of T
|
|
130
120
|
* Creates a predicate that matches an instance described by `modelDefinition`
|
|
@@ -133,18 +123,17 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
133
123
|
* @param modelDefinition The model definition to create a predicate for.
|
|
134
124
|
* @param model The model instance to extract value equalities from.
|
|
135
125
|
*/
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
and: keyFields.map(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
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 } };
|
|
144
133
|
}),
|
|
145
134
|
});
|
|
146
135
|
return predicate;
|
|
147
|
-
}
|
|
136
|
+
}
|
|
148
137
|
/**
|
|
149
138
|
* Searches a `Model` table for records matching the given equalities object.
|
|
150
139
|
*
|
|
@@ -154,16 +143,12 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
154
143
|
* @param modelDefinition The model we need a predicate for.
|
|
155
144
|
* @param flatEqualities An object holding field equalities to search for.
|
|
156
145
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
and: Object.entries(flatEqualities).map(
|
|
160
|
-
var _b;
|
|
161
|
-
var _c = tslib_1.__read(_a, 2), k = _c[0], v = _c[1];
|
|
162
|
-
return (_b = {}, _b[k] = { eq: v }, _b);
|
|
163
|
-
}),
|
|
146
|
+
static createFromFlatEqualities(modelDefinition, flatEqualities) {
|
|
147
|
+
const ast = {
|
|
148
|
+
and: Object.entries(flatEqualities).map(([k, v]) => ({ [k]: { eq: v } })),
|
|
164
149
|
};
|
|
165
150
|
return this.createFromAST(modelDefinition, ast);
|
|
166
|
-
}
|
|
151
|
+
}
|
|
167
152
|
/**
|
|
168
153
|
* Accepts a GraphQL style filter predicate tree and transforms it into an
|
|
169
154
|
* AST that can be used for a storage adapter predicate. Example input:
|
|
@@ -185,8 +170,7 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
185
170
|
*
|
|
186
171
|
* @param gql GraphQL style filter node.
|
|
187
172
|
*/
|
|
188
|
-
|
|
189
|
-
var _this = this;
|
|
173
|
+
static transformGraphQLFilterNodeToPredicateAST(gql) {
|
|
190
174
|
if (!isValid(gql)) {
|
|
191
175
|
throw new Error('Invalid GraphQL Condition or subtree: ' + JSON.stringify(gql));
|
|
192
176
|
}
|
|
@@ -197,15 +181,15 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
197
181
|
};
|
|
198
182
|
}
|
|
199
183
|
else if (isGroup(gql)) {
|
|
200
|
-
|
|
201
|
-
|
|
184
|
+
const groupkey = Object.keys(gql)[0];
|
|
185
|
+
const children = this.transformGraphQLFilterNodeToPredicateAST(gql[groupkey]);
|
|
202
186
|
return {
|
|
203
187
|
type: groupkey,
|
|
204
188
|
predicates: Array.isArray(children) ? children : [children],
|
|
205
189
|
};
|
|
206
190
|
}
|
|
207
191
|
else if (isComparison(gql)) {
|
|
208
|
-
|
|
192
|
+
const operatorKey = Object.keys(gql)[0];
|
|
209
193
|
return {
|
|
210
194
|
operator: operatorKey,
|
|
211
195
|
operand: gql[operatorKey],
|
|
@@ -213,14 +197,17 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
213
197
|
}
|
|
214
198
|
else {
|
|
215
199
|
if (Array.isArray(gql)) {
|
|
216
|
-
return gql.map(
|
|
200
|
+
return gql.map(o => this.transformGraphQLFilterNodeToPredicateAST(o));
|
|
217
201
|
}
|
|
218
202
|
else {
|
|
219
|
-
|
|
220
|
-
return
|
|
203
|
+
const fieldKey = Object.keys(gql)[0];
|
|
204
|
+
return {
|
|
205
|
+
field: fieldKey,
|
|
206
|
+
...this.transformGraphQLFilterNodeToPredicateAST(gql[fieldKey]),
|
|
207
|
+
};
|
|
221
208
|
}
|
|
222
209
|
}
|
|
223
|
-
}
|
|
210
|
+
}
|
|
224
211
|
/**
|
|
225
212
|
* Accepts a GraphQL style filter predicate tree and transforms it into a predicate
|
|
226
213
|
* that storage adapters understand. Example input:
|
|
@@ -243,16 +230,14 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
243
230
|
* @param modelDefinition The model that the AST/predicate must be compatible with.
|
|
244
231
|
* @param ast The graphQL style AST that should specify conditions for `modelDefinition`.
|
|
245
232
|
*/
|
|
246
|
-
|
|
247
|
-
|
|
233
|
+
static createFromAST(modelDefinition, ast) {
|
|
234
|
+
const key = {};
|
|
248
235
|
ModelPredicateCreator.predicateGroupsMap.set(key, this.transformGraphQLFilterNodeToPredicateAST(ast));
|
|
249
236
|
return key;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}());
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Map of storage predicates (key objects) to storage predicate AST's.
|
|
241
|
+
*/
|
|
242
|
+
ModelPredicateCreator.predicateGroupsMap = new WeakMap();
|
|
257
243
|
exports.ModelPredicateCreator = ModelPredicateCreator;
|
|
258
|
-
//# sourceMappingURL=index.js.map
|
package/lib/predicates/next.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PersistentModel, ModelMeta, ModelPredicate as StoragePredicate, PredicateInternalsKey, V5ModelPredicate as ModelPredicate, RecursiveModelPredicate } from '../types';
|
|
2
2
|
import { ExclusiveStorage as StorageAdapter } from '../storage/storage';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
type GroupOperator = 'and' | 'or' | 'not';
|
|
4
|
+
type UntypedCondition = {
|
|
5
5
|
fetch: (storage: StorageAdapter) => Promise<Record<string, any>[]>;
|
|
6
6
|
matches: (item: Record<string, any>) => Promise<boolean>;
|
|
7
7
|
copy(extract?: GroupCondition): [UntypedCondition, GroupCondition | undefined];
|