@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-esm/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-esm/index.js
CHANGED
|
@@ -4,12 +4,11 @@ export { DataStore, DataStoreClass, initSchema, AsyncCollection, AsyncItem, } fr
|
|
|
4
4
|
export { Predicates, ModelPredicateCreator, ModelSortPredicateCreator, } from './predicates';
|
|
5
5
|
import { traverseModel, validatePredicate, USER, isNonModelConstructor, isModelConstructor, } from './util';
|
|
6
6
|
export { NAMESPACES } from './util';
|
|
7
|
-
export
|
|
8
|
-
USER
|
|
9
|
-
traverseModel
|
|
10
|
-
validatePredicate
|
|
11
|
-
isNonModelConstructor
|
|
12
|
-
isModelConstructor
|
|
7
|
+
export const utils = {
|
|
8
|
+
USER,
|
|
9
|
+
traverseModel,
|
|
10
|
+
validatePredicate,
|
|
11
|
+
isNonModelConstructor,
|
|
12
|
+
isModelConstructor,
|
|
13
13
|
};
|
|
14
14
|
export * from './types';
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { __assign, __read, __spread } from "tslib";
|
|
2
1
|
import { extractPrimaryKeyFieldNames, extractPrimaryKeyValues } from '../util';
|
|
3
2
|
export { ModelSortPredicateCreator } from './sort';
|
|
4
|
-
|
|
3
|
+
const predicatesAllSet = new WeakSet();
|
|
5
4
|
export function isPredicatesAll(predicate) {
|
|
6
5
|
return predicatesAllSet.has(predicate);
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
9
8
|
* The valid logical grouping keys for a predicate group.
|
|
10
9
|
*/
|
|
11
|
-
|
|
10
|
+
const groupKeys = new Set(['and', 'or', 'not']);
|
|
12
11
|
/**
|
|
13
12
|
* Determines whether an object is a GraphQL style predicate "group", which must be an
|
|
14
13
|
* object containing a single "group key", which then contains the child condition(s).
|
|
@@ -22,8 +21,8 @@ var groupKeys = new Set(['and', 'or', 'not']);
|
|
|
22
21
|
*
|
|
23
22
|
* @param o The object to test.
|
|
24
23
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const isGroup = o => {
|
|
25
|
+
const keys = [...Object.keys(o)];
|
|
27
26
|
return keys.length === 1 && groupKeys.has(keys[0]);
|
|
28
27
|
};
|
|
29
28
|
/**
|
|
@@ -32,13 +31,13 @@ var isGroup = function (o) {
|
|
|
32
31
|
*
|
|
33
32
|
* @param o The object to test.
|
|
34
33
|
*/
|
|
35
|
-
|
|
34
|
+
const isEmpty = o => {
|
|
36
35
|
return !Array.isArray(o) && Object.keys(o).length === 0;
|
|
37
36
|
};
|
|
38
37
|
/**
|
|
39
38
|
* The valid comparison operators that can be used as keys in a predicate comparison object.
|
|
40
39
|
*/
|
|
41
|
-
export
|
|
40
|
+
export const comparisonKeys = new Set([
|
|
42
41
|
'eq',
|
|
43
42
|
'ne',
|
|
44
43
|
'gt',
|
|
@@ -57,8 +56,8 @@ export var comparisonKeys = new Set([
|
|
|
57
56
|
*
|
|
58
57
|
* @param o The object to test.
|
|
59
58
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const isComparison = o => {
|
|
60
|
+
const keys = [...Object.keys(o)];
|
|
62
61
|
return !Array.isArray(o) && keys.length === 1 && comparisonKeys.has(keys[0]);
|
|
63
62
|
};
|
|
64
63
|
/**
|
|
@@ -66,43 +65,33 @@ var isComparison = function (o) {
|
|
|
66
65
|
*
|
|
67
66
|
* @param o The object to test.
|
|
68
67
|
*/
|
|
69
|
-
|
|
68
|
+
const isValid = o => {
|
|
70
69
|
if (Array.isArray(o)) {
|
|
71
|
-
return o.every(
|
|
70
|
+
return o.every(v => isValid(v));
|
|
72
71
|
}
|
|
73
72
|
else {
|
|
74
73
|
return Object.keys(o).length <= 1;
|
|
75
74
|
}
|
|
76
75
|
};
|
|
77
76
|
// This symbol is not used at runtime, only its type (unique symbol)
|
|
78
|
-
export
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var predicate = (function (c) { return c; });
|
|
85
|
-
predicatesAllSet.add(predicate);
|
|
86
|
-
return predicate;
|
|
87
|
-
},
|
|
88
|
-
enumerable: true,
|
|
89
|
-
configurable: true
|
|
90
|
-
});
|
|
91
|
-
return Predicates;
|
|
92
|
-
}());
|
|
93
|
-
export { Predicates };
|
|
94
|
-
var ModelPredicateCreator = /** @class */ (function () {
|
|
95
|
-
function ModelPredicateCreator() {
|
|
77
|
+
export const PredicateAll = Symbol('A predicate that matches all records');
|
|
78
|
+
export class Predicates {
|
|
79
|
+
static get ALL() {
|
|
80
|
+
const predicate = (c => c);
|
|
81
|
+
predicatesAllSet.add(predicate);
|
|
82
|
+
return predicate;
|
|
96
83
|
}
|
|
84
|
+
}
|
|
85
|
+
class ModelPredicateCreator {
|
|
97
86
|
/**
|
|
98
87
|
* Determines whether the given storage predicate (lookup key) is a predicate
|
|
99
88
|
* key that DataStore recognizes.
|
|
100
89
|
*
|
|
101
90
|
* @param predicate The storage predicate (lookup key) to test.
|
|
102
91
|
*/
|
|
103
|
-
|
|
92
|
+
static isValidPredicate(predicate) {
|
|
104
93
|
return ModelPredicateCreator.predicateGroupsMap.has(predicate);
|
|
105
|
-
}
|
|
94
|
+
}
|
|
106
95
|
/**
|
|
107
96
|
* Looks for the storage predicate AST that corresponds to a given storage
|
|
108
97
|
* predicate key.
|
|
@@ -114,13 +103,12 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
114
103
|
* @param throwOnInvalid Whether to throw an exception if the predicate
|
|
115
104
|
* isn't a valid DataStore predicate.
|
|
116
105
|
*/
|
|
117
|
-
|
|
118
|
-
if (throwOnInvalid === void 0) { throwOnInvalid = true; }
|
|
106
|
+
static getPredicates(predicate, throwOnInvalid = true) {
|
|
119
107
|
if (throwOnInvalid && !ModelPredicateCreator.isValidPredicate(predicate)) {
|
|
120
108
|
throw new Error('The predicate is not valid');
|
|
121
109
|
}
|
|
122
110
|
return ModelPredicateCreator.predicateGroupsMap.get(predicate);
|
|
123
|
-
}
|
|
111
|
+
}
|
|
124
112
|
/**
|
|
125
113
|
* using the PK values from the given `model` (which can be a partial of T
|
|
126
114
|
* Creates a predicate that matches an instance described by `modelDefinition`
|
|
@@ -129,18 +117,17 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
129
117
|
* @param modelDefinition The model definition to create a predicate for.
|
|
130
118
|
* @param model The model instance to extract value equalities from.
|
|
131
119
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
and: keyFields.map(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return _a = {}, _a[field] = { eq: operand }, _a;
|
|
120
|
+
static createForPk(modelDefinition, model) {
|
|
121
|
+
const keyFields = extractPrimaryKeyFieldNames(modelDefinition);
|
|
122
|
+
const keyValues = extractPrimaryKeyValues(model, keyFields);
|
|
123
|
+
const predicate = this.createFromAST(modelDefinition, {
|
|
124
|
+
and: keyFields.map((field, idx) => {
|
|
125
|
+
const operand = keyValues[idx];
|
|
126
|
+
return { [field]: { eq: operand } };
|
|
140
127
|
}),
|
|
141
128
|
});
|
|
142
129
|
return predicate;
|
|
143
|
-
}
|
|
130
|
+
}
|
|
144
131
|
/**
|
|
145
132
|
* Searches a `Model` table for records matching the given equalities object.
|
|
146
133
|
*
|
|
@@ -150,16 +137,12 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
150
137
|
* @param modelDefinition The model we need a predicate for.
|
|
151
138
|
* @param flatEqualities An object holding field equalities to search for.
|
|
152
139
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
and: Object.entries(flatEqualities).map(
|
|
156
|
-
var _b;
|
|
157
|
-
var _c = __read(_a, 2), k = _c[0], v = _c[1];
|
|
158
|
-
return (_b = {}, _b[k] = { eq: v }, _b);
|
|
159
|
-
}),
|
|
140
|
+
static createFromFlatEqualities(modelDefinition, flatEqualities) {
|
|
141
|
+
const ast = {
|
|
142
|
+
and: Object.entries(flatEqualities).map(([k, v]) => ({ [k]: { eq: v } })),
|
|
160
143
|
};
|
|
161
144
|
return this.createFromAST(modelDefinition, ast);
|
|
162
|
-
}
|
|
145
|
+
}
|
|
163
146
|
/**
|
|
164
147
|
* Accepts a GraphQL style filter predicate tree and transforms it into an
|
|
165
148
|
* AST that can be used for a storage adapter predicate. Example input:
|
|
@@ -181,8 +164,7 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
181
164
|
*
|
|
182
165
|
* @param gql GraphQL style filter node.
|
|
183
166
|
*/
|
|
184
|
-
|
|
185
|
-
var _this = this;
|
|
167
|
+
static transformGraphQLFilterNodeToPredicateAST(gql) {
|
|
186
168
|
if (!isValid(gql)) {
|
|
187
169
|
throw new Error('Invalid GraphQL Condition or subtree: ' + JSON.stringify(gql));
|
|
188
170
|
}
|
|
@@ -193,15 +175,15 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
193
175
|
};
|
|
194
176
|
}
|
|
195
177
|
else if (isGroup(gql)) {
|
|
196
|
-
|
|
197
|
-
|
|
178
|
+
const groupkey = Object.keys(gql)[0];
|
|
179
|
+
const children = this.transformGraphQLFilterNodeToPredicateAST(gql[groupkey]);
|
|
198
180
|
return {
|
|
199
181
|
type: groupkey,
|
|
200
182
|
predicates: Array.isArray(children) ? children : [children],
|
|
201
183
|
};
|
|
202
184
|
}
|
|
203
185
|
else if (isComparison(gql)) {
|
|
204
|
-
|
|
186
|
+
const operatorKey = Object.keys(gql)[0];
|
|
205
187
|
return {
|
|
206
188
|
operator: operatorKey,
|
|
207
189
|
operand: gql[operatorKey],
|
|
@@ -209,14 +191,17 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
209
191
|
}
|
|
210
192
|
else {
|
|
211
193
|
if (Array.isArray(gql)) {
|
|
212
|
-
return gql.map(
|
|
194
|
+
return gql.map(o => this.transformGraphQLFilterNodeToPredicateAST(o));
|
|
213
195
|
}
|
|
214
196
|
else {
|
|
215
|
-
|
|
216
|
-
return
|
|
197
|
+
const fieldKey = Object.keys(gql)[0];
|
|
198
|
+
return {
|
|
199
|
+
field: fieldKey,
|
|
200
|
+
...this.transformGraphQLFilterNodeToPredicateAST(gql[fieldKey]),
|
|
201
|
+
};
|
|
217
202
|
}
|
|
218
203
|
}
|
|
219
|
-
}
|
|
204
|
+
}
|
|
220
205
|
/**
|
|
221
206
|
* Accepts a GraphQL style filter predicate tree and transforms it into a predicate
|
|
222
207
|
* that storage adapters understand. Example input:
|
|
@@ -239,16 +224,14 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
239
224
|
* @param modelDefinition The model that the AST/predicate must be compatible with.
|
|
240
225
|
* @param ast The graphQL style AST that should specify conditions for `modelDefinition`.
|
|
241
226
|
*/
|
|
242
|
-
|
|
243
|
-
|
|
227
|
+
static createFromAST(modelDefinition, ast) {
|
|
228
|
+
const key = {};
|
|
244
229
|
ModelPredicateCreator.predicateGroupsMap.set(key, this.transformGraphQLFilterNodeToPredicateAST(ast));
|
|
245
230
|
return key;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}());
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Map of storage predicates (key objects) to storage predicate AST's.
|
|
235
|
+
*/
|
|
236
|
+
ModelPredicateCreator.predicateGroupsMap = new WeakMap();
|
|
253
237
|
export { ModelPredicateCreator };
|
|
254
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -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];
|