@aws-amplify/datastore 4.0.12 → 4.0.13-push-notification-dryrun.43
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/datastore/datastore.d.ts +29 -3
- package/lib/datastore/datastore.js +308 -147
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/predicates/index.d.ts +77 -7
- package/lib/predicates/index.js +142 -122
- package/lib/predicates/index.js.map +1 -1
- package/lib/predicates/next.d.ts +51 -10
- package/lib/predicates/next.js +111 -91
- package/lib/predicates/next.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +28 -30
- package/lib/storage/adapter/AsyncStorageAdapter.js +135 -532
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.d.ts +28 -29
- package/lib/storage/adapter/IndexedDBAdapter.js +490 -885
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/adapter/StorageAdapterBase.d.ts +134 -0
- package/lib/storage/adapter/StorageAdapterBase.js +439 -0
- package/lib/storage/adapter/StorageAdapterBase.js.map +1 -0
- package/lib/storage/relationship.d.ts +9 -0
- package/lib/storage/relationship.js +9 -0
- package/lib/storage/relationship.js.map +1 -1
- package/lib/storage/storage.d.ts +1 -1
- package/lib/storage/storage.js +4 -3
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/index.d.ts +15 -1
- package/lib/sync/index.js +80 -13
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/outbox.js +14 -7
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/mutation.d.ts +10 -1
- package/lib/sync/processors/mutation.js +33 -12
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.d.ts +7 -1
- package/lib/sync/processors/subscription.js +196 -135
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.d.ts +1 -1
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.d.ts +66 -2
- package/lib/sync/utils.js +264 -16
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.d.ts +9 -1
- package/lib/types.js.map +1 -1
- package/lib/util.d.ts +16 -0
- package/lib/util.js +31 -2
- package/lib/util.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +29 -3
- package/lib-esm/datastore/datastore.js +310 -149
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/predicates/index.d.ts +77 -7
- package/lib-esm/predicates/index.js +143 -123
- package/lib-esm/predicates/index.js.map +1 -1
- package/lib-esm/predicates/next.d.ts +51 -10
- package/lib-esm/predicates/next.js +111 -91
- package/lib-esm/predicates/next.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.d.ts +28 -30
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +138 -535
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +28 -29
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +489 -884
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/StorageAdapterBase.d.ts +134 -0
- package/lib-esm/storage/adapter/StorageAdapterBase.js +437 -0
- package/lib-esm/storage/adapter/StorageAdapterBase.js.map +1 -0
- package/lib-esm/storage/relationship.d.ts +9 -0
- package/lib-esm/storage/relationship.js +9 -0
- package/lib-esm/storage/relationship.js.map +1 -1
- package/lib-esm/storage/storage.d.ts +1 -1
- package/lib-esm/storage/storage.js +4 -3
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/index.d.ts +15 -1
- package/lib-esm/sync/index.js +82 -15
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/outbox.js +14 -7
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/mutation.d.ts +10 -1
- package/lib-esm/sync/processors/mutation.js +33 -12
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.d.ts +7 -1
- package/lib-esm/sync/processors/subscription.js +197 -136
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.d.ts +1 -1
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.d.ts +66 -2
- package/lib-esm/sync/utils.js +261 -18
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +9 -1
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +16 -0
- package/lib-esm/util.js +32 -3
- package/lib-esm/util.js.map +1 -1
- package/package.json +12 -11
- package/src/datastore/datastore.ts +288 -159
- package/src/predicates/index.ts +145 -175
- package/src/predicates/next.ts +114 -81
- package/src/storage/adapter/AsyncStorageAdapter.ts +97 -563
- package/src/storage/adapter/AsyncStorageDatabase.ts +2 -2
- package/src/storage/adapter/IndexedDBAdapter.ts +318 -770
- package/src/storage/adapter/StorageAdapterBase.ts +545 -0
- package/src/storage/relationship.ts +9 -0
- package/src/storage/storage.ts +12 -9
- package/src/sync/index.ts +108 -20
- package/src/sync/outbox.ts +17 -11
- package/src/sync/processors/mutation.ts +35 -4
- package/src/sync/processors/subscription.ts +124 -10
- package/src/sync/processors/sync.ts +4 -1
- package/src/sync/utils.ts +285 -15
- package/src/types.ts +15 -2
- package/src/util.ts +40 -1
- package/CHANGELOG.md +0 -904
package/lib/predicates/index.js
CHANGED
|
@@ -9,11 +9,39 @@ function isPredicatesAll(predicate) {
|
|
|
9
9
|
return predicatesAllSet.has(predicate);
|
|
10
10
|
}
|
|
11
11
|
exports.isPredicatesAll = isPredicatesAll;
|
|
12
|
+
/**
|
|
13
|
+
* The valid logical grouping keys for a predicate group.
|
|
14
|
+
*/
|
|
12
15
|
var groupKeys = new Set(['and', 'or', 'not']);
|
|
16
|
+
/**
|
|
17
|
+
* Determines whether an object is a GraphQL style predicate "group", which must be an
|
|
18
|
+
* object containing a single "group key", which then contains the child condition(s).
|
|
19
|
+
*
|
|
20
|
+
* E.g.,
|
|
21
|
+
*
|
|
22
|
+
* ```
|
|
23
|
+
* { and: [ ... ] }
|
|
24
|
+
* { not: { ... } }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param o The object to test.
|
|
28
|
+
*/
|
|
13
29
|
var isGroup = function (o) {
|
|
14
30
|
var keys = tslib_1.__spread(Object.keys(o));
|
|
15
31
|
return keys.length === 1 && groupKeys.has(keys[0]);
|
|
16
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Determines whether an object specifies no conditions and should match everything,
|
|
35
|
+
* as would be the case with `Predicates.ALL`.
|
|
36
|
+
*
|
|
37
|
+
* @param o The object to test.
|
|
38
|
+
*/
|
|
39
|
+
var isEmpty = function (o) {
|
|
40
|
+
return !Array.isArray(o) && Object.keys(o).length === 0;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The valid comparison operators that can be used as keys in a predicate comparison object.
|
|
44
|
+
*/
|
|
17
45
|
exports.comparisonKeys = new Set([
|
|
18
46
|
'eq',
|
|
19
47
|
'ne',
|
|
@@ -26,16 +54,28 @@ exports.comparisonKeys = new Set([
|
|
|
26
54
|
'beginsWith',
|
|
27
55
|
'between',
|
|
28
56
|
]);
|
|
57
|
+
/**
|
|
58
|
+
* Determines whether an object is a GraphQL style predicate comparison node, which must
|
|
59
|
+
* be an object containing a single "comparison operator" key, which then contains the
|
|
60
|
+
* operand or operands to compare against.
|
|
61
|
+
*
|
|
62
|
+
* @param o The object to test.
|
|
63
|
+
*/
|
|
29
64
|
var isComparison = function (o) {
|
|
30
65
|
var keys = tslib_1.__spread(Object.keys(o));
|
|
31
66
|
return !Array.isArray(o) && keys.length === 1 && exports.comparisonKeys.has(keys[0]);
|
|
32
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* A light check to determine whether an object is a valid GraphQL Condition AST.
|
|
70
|
+
*
|
|
71
|
+
* @param o The object to test.
|
|
72
|
+
*/
|
|
33
73
|
var isValid = function (o) {
|
|
34
74
|
if (Array.isArray(o)) {
|
|
35
75
|
return o.every(function (v) { return isValid(v); });
|
|
36
76
|
}
|
|
37
77
|
else {
|
|
38
|
-
return Object.keys(o).length
|
|
78
|
+
return Object.keys(o).length <= 1;
|
|
39
79
|
}
|
|
40
80
|
};
|
|
41
81
|
// This symbol is not used at runtime, only its type (unique symbol)
|
|
@@ -58,61 +98,26 @@ exports.Predicates = Predicates;
|
|
|
58
98
|
var ModelPredicateCreator = /** @class */ (function () {
|
|
59
99
|
function ModelPredicateCreator() {
|
|
60
100
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var groupType = propertyKey;
|
|
68
|
-
switch (groupType) {
|
|
69
|
-
case 'and':
|
|
70
|
-
case 'or':
|
|
71
|
-
case 'not':
|
|
72
|
-
var result_1 = function (newPredicate) {
|
|
73
|
-
var group = {
|
|
74
|
-
type: groupType,
|
|
75
|
-
predicates: [],
|
|
76
|
-
};
|
|
77
|
-
// Create a new recorder
|
|
78
|
-
var tmpPredicateRecorder = new Proxy({}, handler);
|
|
79
|
-
// Set the recorder group
|
|
80
|
-
ModelPredicateCreator.predicateGroupsMap.set(tmpPredicateRecorder, group);
|
|
81
|
-
// Apply the predicates to the recorder (this is the step that records the changes)
|
|
82
|
-
newPredicate(tmpPredicateRecorder);
|
|
83
|
-
// Push the group to the top-level recorder
|
|
84
|
-
ModelPredicateCreator.predicateGroupsMap
|
|
85
|
-
.get(self)
|
|
86
|
-
.predicates.push(group);
|
|
87
|
-
return self;
|
|
88
|
-
};
|
|
89
|
-
return result_1;
|
|
90
|
-
default:
|
|
91
|
-
// intentionally blank.
|
|
92
|
-
}
|
|
93
|
-
var field = propertyKey;
|
|
94
|
-
if (!fieldNames.has(field)) {
|
|
95
|
-
throw new Error("Invalid field for model. field: " + field + ", model: " + modelName);
|
|
96
|
-
}
|
|
97
|
-
var result = function (operator, operand) {
|
|
98
|
-
ModelPredicateCreator.predicateGroupsMap
|
|
99
|
-
.get(self)
|
|
100
|
-
.predicates.push({ field: field, operator: operator, operand: operand });
|
|
101
|
-
return self;
|
|
102
|
-
};
|
|
103
|
-
return result;
|
|
104
|
-
},
|
|
105
|
-
}));
|
|
106
|
-
var group = {
|
|
107
|
-
type: 'and',
|
|
108
|
-
predicates: [],
|
|
109
|
-
};
|
|
110
|
-
ModelPredicateCreator.predicateGroupsMap.set(predicate, group);
|
|
111
|
-
return predicate;
|
|
112
|
-
};
|
|
101
|
+
/**
|
|
102
|
+
* Determines whether the given storage predicate (lookup key) is a predicate
|
|
103
|
+
* key that DataStore recognizes.
|
|
104
|
+
*
|
|
105
|
+
* @param predicate The storage predicate (lookup key) to test.
|
|
106
|
+
*/
|
|
113
107
|
ModelPredicateCreator.isValidPredicate = function (predicate) {
|
|
114
108
|
return ModelPredicateCreator.predicateGroupsMap.has(predicate);
|
|
115
109
|
};
|
|
110
|
+
/**
|
|
111
|
+
* Looks for the storage predicate AST that corresponds to a given storage
|
|
112
|
+
* predicate key.
|
|
113
|
+
*
|
|
114
|
+
* The key must have been created internally by a DataStore utility
|
|
115
|
+
* method, such as `ModelPredicate.createFromAST()`.
|
|
116
|
+
*
|
|
117
|
+
* @param predicate The predicate reference to look up.
|
|
118
|
+
* @param throwOnInvalid Whether to throw an exception if the predicate
|
|
119
|
+
* isn't a valid DataStore predicate.
|
|
120
|
+
*/
|
|
116
121
|
ModelPredicateCreator.getPredicates = function (predicate, throwOnInvalid) {
|
|
117
122
|
if (throwOnInvalid === void 0) { throwOnInvalid = true; }
|
|
118
123
|
if (throwOnInvalid && !ModelPredicateCreator.isValidPredicate(predicate)) {
|
|
@@ -120,25 +125,25 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
120
125
|
}
|
|
121
126
|
return ModelPredicateCreator.predicateGroupsMap.get(predicate);
|
|
122
127
|
};
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return ModelPredicateCreator.createPredicateBuilder(modelDefinition)[fieldName]('eq', value);
|
|
132
|
-
};
|
|
128
|
+
/**
|
|
129
|
+
* using the PK values from the given `model` (which can be a partial of T
|
|
130
|
+
* Creates a predicate that matches an instance described by `modelDefinition`
|
|
131
|
+
* that contains only PK field values.)
|
|
132
|
+
*
|
|
133
|
+
* @param modelDefinition The model definition to create a predicate for.
|
|
134
|
+
* @param model The model instance to extract value equalities from.
|
|
135
|
+
*/
|
|
133
136
|
ModelPredicateCreator.createForPk = function (modelDefinition, model) {
|
|
134
137
|
var keyFields = util_1.extractPrimaryKeyFieldNames(modelDefinition);
|
|
135
138
|
var keyValues = util_1.extractPrimaryKeyValues(model, keyFields);
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
var predicate = this.createFromAST(modelDefinition, {
|
|
140
|
+
and: keyFields.map(function (field, idx) {
|
|
141
|
+
var _a;
|
|
142
|
+
var operand = keyValues[idx];
|
|
143
|
+
return _a = {}, _a[field] = { eq: operand }, _a;
|
|
144
|
+
}),
|
|
140
145
|
});
|
|
141
|
-
return
|
|
146
|
+
return predicate;
|
|
142
147
|
};
|
|
143
148
|
/**
|
|
144
149
|
* Searches a `Model` table for records matching the given equalities object.
|
|
@@ -150,60 +155,50 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
150
155
|
* @param flatEqualities An object holding field equalities to search for.
|
|
151
156
|
*/
|
|
152
157
|
ModelPredicateCreator.createFromFlatEqualities = function (modelDefinition, flatEqualities) {
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
162
|
-
finally {
|
|
163
|
-
try {
|
|
164
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
165
|
-
}
|
|
166
|
-
finally { if (e_1) throw e_1.error; }
|
|
167
|
-
}
|
|
168
|
-
return predicate;
|
|
169
|
-
};
|
|
170
|
-
ModelPredicateCreator.createGroupFromExisting = function (modelDefinition, group, existingPredicates) {
|
|
171
|
-
var outer = ModelPredicateCreator.createPredicateBuilder(modelDefinition);
|
|
172
|
-
outer = outer[group](function (seed) {
|
|
173
|
-
var e_2, _a;
|
|
174
|
-
var _b;
|
|
175
|
-
var inner = seed;
|
|
176
|
-
try {
|
|
177
|
-
for (var existingPredicates_1 = tslib_1.__values(existingPredicates), existingPredicates_1_1 = existingPredicates_1.next(); !existingPredicates_1_1.done; existingPredicates_1_1 = existingPredicates_1.next()) {
|
|
178
|
-
var existing = existingPredicates_1_1.value;
|
|
179
|
-
if (typeof existing === 'function') {
|
|
180
|
-
inner = existing(inner);
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
(_b = ModelPredicateCreator.predicateGroupsMap
|
|
184
|
-
.get(inner)) === null || _b === void 0 ? void 0 : _b.predicates.push(ModelPredicateCreator.predicateGroupsMap.get(existing));
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
189
|
-
finally {
|
|
190
|
-
try {
|
|
191
|
-
if (existingPredicates_1_1 && !existingPredicates_1_1.done && (_a = existingPredicates_1.return)) _a.call(existingPredicates_1);
|
|
192
|
-
}
|
|
193
|
-
finally { if (e_2) throw e_2.error; }
|
|
194
|
-
}
|
|
195
|
-
return inner;
|
|
196
|
-
});
|
|
197
|
-
return outer;
|
|
158
|
+
var ast = {
|
|
159
|
+
and: Object.entries(flatEqualities).map(function (_a) {
|
|
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
|
+
}),
|
|
164
|
+
};
|
|
165
|
+
return this.createFromAST(modelDefinition, ast);
|
|
198
166
|
};
|
|
199
|
-
|
|
167
|
+
/**
|
|
168
|
+
* Accepts a GraphQL style filter predicate tree and transforms it into an
|
|
169
|
+
* AST that can be used for a storage adapter predicate. Example input:
|
|
170
|
+
*
|
|
171
|
+
* ```js
|
|
172
|
+
* {
|
|
173
|
+
* and: [
|
|
174
|
+
* { name: { eq: "Bob Jones" } },
|
|
175
|
+
* { age: { between: [32, 64] } },
|
|
176
|
+
* { not: {
|
|
177
|
+
* or: [
|
|
178
|
+
* { favoriteFood: { eq: 'pizza' } },
|
|
179
|
+
* { favoriteFood: { eq: 'tacos' } },
|
|
180
|
+
* ]
|
|
181
|
+
* }}
|
|
182
|
+
* ]
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* @param gql GraphQL style filter node.
|
|
187
|
+
*/
|
|
188
|
+
ModelPredicateCreator.transformGraphQLFilterNodeToPredicateAST = function (gql) {
|
|
200
189
|
var _this = this;
|
|
201
190
|
if (!isValid(gql)) {
|
|
202
|
-
throw new Error('Invalid
|
|
191
|
+
throw new Error('Invalid GraphQL Condition or subtree: ' + gql);
|
|
203
192
|
}
|
|
204
|
-
if (
|
|
193
|
+
if (isEmpty(gql)) {
|
|
194
|
+
return {
|
|
195
|
+
type: 'and',
|
|
196
|
+
predicates: [],
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
else if (isGroup(gql)) {
|
|
205
200
|
var groupkey = Object.keys(gql)[0];
|
|
206
|
-
var children = this.
|
|
201
|
+
var children = this.transformGraphQLFilterNodeToPredicateAST(gql[groupkey]);
|
|
207
202
|
return {
|
|
208
203
|
type: groupkey,
|
|
209
204
|
predicates: Array.isArray(children) ? children : [children],
|
|
@@ -218,19 +213,44 @@ var ModelPredicateCreator = /** @class */ (function () {
|
|
|
218
213
|
}
|
|
219
214
|
else {
|
|
220
215
|
if (Array.isArray(gql)) {
|
|
221
|
-
return gql.map(function (o) { return _this.
|
|
216
|
+
return gql.map(function (o) { return _this.transformGraphQLFilterNodeToPredicateAST(o); });
|
|
222
217
|
}
|
|
223
218
|
else {
|
|
224
219
|
var fieldKey = Object.keys(gql)[0];
|
|
225
|
-
return tslib_1.__assign({ field: fieldKey }, this.
|
|
220
|
+
return tslib_1.__assign({ field: fieldKey }, this.transformGraphQLFilterNodeToPredicateAST(gql[fieldKey]));
|
|
226
221
|
}
|
|
227
222
|
}
|
|
228
223
|
};
|
|
224
|
+
/**
|
|
225
|
+
* Accepts a GraphQL style filter predicate tree and transforms it into a predicate
|
|
226
|
+
* that storage adapters understand. Example input:
|
|
227
|
+
*
|
|
228
|
+
* ```js
|
|
229
|
+
* {
|
|
230
|
+
* and: [
|
|
231
|
+
* { name: { eq: "Bob Jones" } },
|
|
232
|
+
* { age: { between: [32, 64] } },
|
|
233
|
+
* { not: {
|
|
234
|
+
* or: [
|
|
235
|
+
* { favoriteFood: { eq: 'pizza' } },
|
|
236
|
+
* { favoriteFood: { eq: 'tacos' } },
|
|
237
|
+
* ]
|
|
238
|
+
* }}
|
|
239
|
+
* ]
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @param modelDefinition The model that the AST/predicate must be compatible with.
|
|
244
|
+
* @param ast The graphQL style AST that should specify conditions for `modelDefinition`.
|
|
245
|
+
*/
|
|
229
246
|
ModelPredicateCreator.createFromAST = function (modelDefinition, ast) {
|
|
230
|
-
var
|
|
231
|
-
ModelPredicateCreator.predicateGroupsMap.set(
|
|
232
|
-
return
|
|
247
|
+
var key = {};
|
|
248
|
+
ModelPredicateCreator.predicateGroupsMap.set(key, this.transformGraphQLFilterNodeToPredicateAST(ast));
|
|
249
|
+
return key;
|
|
233
250
|
};
|
|
251
|
+
/**
|
|
252
|
+
* Map of storage predicates (key objects) to storage predicate AST's.
|
|
253
|
+
*/
|
|
234
254
|
ModelPredicateCreator.predicateGroupsMap = new WeakMap();
|
|
235
255
|
return ModelPredicateCreator;
|
|
236
256
|
}());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/predicates/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/predicates/index.ts"],"names":[],"mappings":";;;AAOA,gCAA+E;AAE/E,+BAAmD;AAA1C,2CAAA,yBAAyB,CAAA;AAElC,IAAM,gBAAgB,GAAG,IAAI,OAAO,EAA+B,CAAC;AAEpE,SAAgB,eAAe,CAC9B,SAAc;IAEd,OAAO,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC;AAJD,0CAIC;AAED;;GAEG;AACH,IAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAEhD;;;;;;;;;;;;GAYG;AACH,IAAM,OAAO,GAAG,UAAA,CAAC;IAChB,IAAM,IAAI,oBAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF;;;;;GAKG;AACH,IAAM,OAAO,GAAG,UAAA,CAAC;IAChB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF;;GAEG;AACU,QAAA,cAAc,GAAG,IAAI,GAAG,CAAC;IACrC,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,UAAU;IACV,aAAa;IACb,YAAY;IACZ,SAAS;CACT,CAAC,CAAC;AAEH;;;;;;GA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;;;;;;;;;;;;;;;;;;;OAqBG;IACI,mCAAa,GAApB,UACC,eAA4B,EAC5B,GAAQ;QAER,IAAM,GAAG,GAAG,EAAuB,CAAC;QAEpC,qBAAqB,CAAC,kBAAkB,CAAC,GAAG,CAC3C,GAAG,EACH,IAAI,CAAC,wCAAwC,CAAC,GAAG,CAAC,CAClD,CAAC;QAEF,OAAO,GAAG,CAAC;IACZ,CAAC;IAnLD;;OAEG;IACY,wCAAkB,GAAG,IAAI,OAAO,EAG5C,CAAC;IA8KL,4BAAC;CAAA,AArLD,IAqLC;AArLY,sDAAqB"}
|
package/lib/predicates/next.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ declare type GroupOperator = 'and' | 'or' | 'not';
|
|
|
4
4
|
declare type UntypedCondition = {
|
|
5
5
|
fetch: (storage: StorageAdapter) => Promise<Record<string, any>[]>;
|
|
6
6
|
matches: (item: Record<string, any>) => Promise<boolean>;
|
|
7
|
-
copy(extract
|
|
7
|
+
copy(extract?: GroupCondition): [UntypedCondition, GroupCondition | undefined];
|
|
8
8
|
toAST(): any;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
@@ -35,12 +35,45 @@ export declare class FieldCondition {
|
|
|
35
35
|
* @param extract Not used. Present only to fulfill the `UntypedCondition` interface.
|
|
36
36
|
* @returns A new, identitical `FieldCondition`.
|
|
37
37
|
*/
|
|
38
|
-
copy(extract
|
|
38
|
+
copy(extract?: GroupCondition): [FieldCondition, GroupCondition | undefined];
|
|
39
|
+
/**
|
|
40
|
+
* Produces a tree structure similar to a graphql condition. The returned
|
|
41
|
+
* structure is "dumb" and is intended for another query/condition
|
|
42
|
+
* generation mechanism to interpret, such as the cloud or storage query
|
|
43
|
+
* builders.
|
|
44
|
+
*
|
|
45
|
+
* E.g.,
|
|
46
|
+
*
|
|
47
|
+
* ```json
|
|
48
|
+
* {
|
|
49
|
+
* "name": {
|
|
50
|
+
* "eq": "robert"
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
39
55
|
toAST(): {
|
|
40
56
|
[x: string]: {
|
|
41
57
|
[x: string]: string | string[];
|
|
42
58
|
};
|
|
43
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Produces a new condition (`FieldCondition` or `GroupCondition`) that
|
|
62
|
+
* matches the opposite of this condition.
|
|
63
|
+
*
|
|
64
|
+
* Intended to be used when applying De Morgan's Law, which can be done to
|
|
65
|
+
* produce more efficient queries against the storage layer if a negation
|
|
66
|
+
* appears in the query tree.
|
|
67
|
+
*
|
|
68
|
+
* For example:
|
|
69
|
+
*
|
|
70
|
+
* 1. `name.eq('robert')` becomes `name.ne('robert')`
|
|
71
|
+
* 2. `price.between(100, 200)` becomes `m => m.or(m => [m.price.lt(100), m.price.gt(200)])`
|
|
72
|
+
*
|
|
73
|
+
* @param model The model meta to use when construction a new `GroupCondition`
|
|
74
|
+
* for cases where the negation requires multiple `FieldCondition`'s.
|
|
75
|
+
*/
|
|
76
|
+
negated(model: ModelMeta<any>): GroupCondition | FieldCondition;
|
|
44
77
|
/**
|
|
45
78
|
* Not implemented. Not needed. GroupCondition instead consumes FieldConditions and
|
|
46
79
|
* transforms them into legacy predicates. (*For now.*)
|
|
@@ -166,7 +199,17 @@ export declare class GroupCondition {
|
|
|
166
199
|
* @param extract A node of interest. Its copy will *also* be returned if the node exists.
|
|
167
200
|
* @returns [The full copy, the copy of `extract` | undefined]
|
|
168
201
|
*/
|
|
169
|
-
copy(extract
|
|
202
|
+
copy(extract?: GroupCondition): [GroupCondition, GroupCondition | undefined];
|
|
203
|
+
/**
|
|
204
|
+
* Creates a new `GroupCondition` that contains only the local field conditions,
|
|
205
|
+
* omitting related model conditions. That resulting `GroupCondition` can be
|
|
206
|
+
* used to produce predicates that are compatible with the storage adapters and
|
|
207
|
+
* Cloud storage.
|
|
208
|
+
*
|
|
209
|
+
* @param negate Whether the condition tree should be negated according
|
|
210
|
+
* to De Morgan's law.
|
|
211
|
+
*/
|
|
212
|
+
withFieldConditionsOnly(negate: boolean): GroupCondition;
|
|
170
213
|
/**
|
|
171
214
|
* Returns a version of the predicate tree with unnecessary logical groups
|
|
172
215
|
* condensed and merged together. This is intended to create a dense tree
|
|
@@ -230,7 +273,11 @@ export declare class GroupCondition {
|
|
|
230
273
|
toAST(): {
|
|
231
274
|
[x: string]: any[];
|
|
232
275
|
};
|
|
233
|
-
|
|
276
|
+
/**
|
|
277
|
+
* Turn this predicate group into something a storage adapter
|
|
278
|
+
* understands how to use.
|
|
279
|
+
*/
|
|
280
|
+
toStoragePredicate<T>(): StoragePredicate<T>;
|
|
234
281
|
/**
|
|
235
282
|
* A JSON representation that's good for debugging.
|
|
236
283
|
*/
|
|
@@ -258,12 +305,6 @@ export declare class GroupCondition {
|
|
|
258
305
|
* `predicateFor()` returns objecst with recursive getters. To facilitate this,
|
|
259
306
|
* a `query` and `tail` can be provided to "accumulate" nested conditions.
|
|
260
307
|
*
|
|
261
|
-
* TODO: the sortof-immutable algorithm was originally done to support legacy style
|
|
262
|
-
* predicate branching (`p => p.x.eq(value).y.eq(value)`). i'm not sure this is
|
|
263
|
-
* necessary or beneficial at this point, since we decided that each field condition
|
|
264
|
-
* must flly terminate a branch. is the strong mutation barrier between chain links
|
|
265
|
-
* still necessary or helpful?
|
|
266
|
-
*
|
|
267
308
|
* @param ModelType The ModelMeta used to build child properties.
|
|
268
309
|
* @param field Scopes the query branch to a field.
|
|
269
310
|
* @param query A base query to build on. Omit to start a new query.
|