@aws-amplify/datastore 4.7.5 → 5.0.1-console-preview.4432977.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 +81 -24
- package/lib/datastore/datastore.d.ts +3 -4
- package/lib/datastore/datastore.js +361 -227
- package/lib/index.d.ts +1 -1
- package/lib/index.js +25 -12
- package/lib/predicates/index.js +46 -12
- package/lib/predicates/next.d.ts +2 -2
- package/lib/predicates/next.js +172 -74
- package/lib/predicates/sort.js +3 -4
- package/lib/ssr/index.js +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +240 -128
- package/lib/storage/adapter/AsyncStorageDatabase.js +100 -39
- package/lib/storage/adapter/InMemoryStore.js +68 -17
- package/lib/storage/adapter/InMemoryStore.native.js +5 -3
- package/lib/storage/adapter/IndexedDBAdapter.js +355 -199
- package/lib/storage/adapter/StorageAdapterBase.js +154 -85
- package/lib/storage/adapter/getDefaultAdapter/index.js +8 -9
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -3
- package/lib/storage/adapter/index.js +0 -1
- package/lib/storage/relationship.js +31 -21
- package/lib/storage/storage.d.ts +3 -3
- package/lib/storage/storage.js +143 -61
- package/lib/sync/datastoreConnectivity.d.ts +1 -1
- package/lib/sync/datastoreConnectivity.js +57 -9
- package/lib/sync/datastoreReachability/index.js +3 -3
- package/lib/sync/datastoreReachability/index.native.js +7 -5
- package/lib/sync/index.d.ts +1 -1
- package/lib/sync/index.js +193 -125
- package/lib/sync/merger.js +81 -10
- package/lib/sync/outbox.js +101 -30
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +41 -6
- package/lib/sync/processors/mutation.d.ts +1 -1
- package/lib/sync/processors/mutation.js +192 -101
- package/lib/sync/processors/subscription.d.ts +4 -1
- package/lib/sync/processors/subscription.js +190 -178
- package/lib/sync/processors/sync.d.ts +1 -1
- package/lib/sync/processors/sync.js +113 -47
- package/lib/sync/utils.d.ts +4 -4
- package/lib/sync/utils.js +162 -81
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types.d.ts +138 -140
- package/lib/types.js +40 -5
- package/lib/util.d.ts +9 -17
- package/lib/util.js +216 -100
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +0 -1
- package/lib-esm/authModeStrategies/index.js +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +76 -21
- package/lib-esm/datastore/datastore.d.ts +3 -4
- package/lib-esm/datastore/datastore.js +206 -77
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +0 -1
- package/lib-esm/predicates/index.js +40 -7
- package/lib-esm/predicates/next.d.ts +2 -2
- package/lib-esm/predicates/next.js +148 -52
- package/lib-esm/predicates/sort.js +2 -4
- package/lib-esm/ssr/index.js +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +203 -95
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +66 -5
- package/lib-esm/storage/adapter/InMemoryStore.js +52 -2
- package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +271 -138
- package/lib-esm/storage/adapter/StorageAdapterBase.js +130 -62
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -5
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +0 -1
- package/lib-esm/storage/adapter/index.js +1 -1
- package/lib-esm/storage/relationship.js +27 -18
- package/lib-esm/storage/storage.d.ts +3 -3
- package/lib-esm/storage/storage.js +87 -9
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +48 -3
- package/lib-esm/sync/datastoreReachability/index.js +1 -2
- package/lib-esm/sync/datastoreReachability/index.native.js +1 -2
- package/lib-esm/sync/index.d.ts +1 -1
- package/lib-esm/sync/index.js +136 -72
- package/lib-esm/sync/merger.js +73 -3
- package/lib-esm/sync/outbox.js +75 -5
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +39 -5
- package/lib-esm/sync/processors/mutation.d.ts +1 -1
- package/lib-esm/sync/processors/mutation.js +130 -44
- package/lib-esm/sync/processors/subscription.d.ts +4 -1
- package/lib-esm/sync/processors/subscription.js +134 -126
- package/lib-esm/sync/processors/sync.d.ts +1 -1
- package/lib-esm/sync/processors/sync.js +74 -12
- package/lib-esm/sync/utils.d.ts +4 -4
- package/lib-esm/sync/utils.js +135 -55
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types.d.ts +138 -140
- package/lib-esm/types.js +36 -2
- package/lib-esm/util.d.ts +9 -17
- package/lib-esm/util.js +96 -16
- package/package.json +139 -132
- package/src/authModeStrategies/multiAuthStrategy.ts +11 -12
- package/src/datastore/datastore.ts +32 -25
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/InMemoryStore.ts +1 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +1 -1
- package/src/storage/adapter/StorageAdapterBase.ts +1 -1
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -3
- package/src/storage/storage.ts +1 -1
- package/src/sync/datastoreConnectivity.ts +2 -2
- package/src/sync/datastoreReachability/index.native.ts +1 -1
- package/src/sync/datastoreReachability/index.ts +1 -1
- package/src/sync/index.ts +69 -78
- package/src/sync/processors/mutation.ts +16 -10
- package/src/sync/processors/subscription.ts +55 -127
- package/src/sync/processors/sync.ts +8 -4
- package/src/sync/utils.ts +7 -8
- package/src/types.ts +4 -8
- package/src/util.ts +5 -6
- 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/predicates/next.js
CHANGED
|
@@ -1,13 +1,103 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
50
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
51
|
+
var m = o[Symbol.asyncIterator], i;
|
|
52
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
53
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
54
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
55
|
+
};
|
|
56
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
57
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
58
|
+
if (!m) return o;
|
|
59
|
+
var i = m.call(o), r, ar = [], e;
|
|
60
|
+
try {
|
|
61
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
62
|
+
}
|
|
63
|
+
catch (error) { e = { error: error }; }
|
|
64
|
+
finally {
|
|
65
|
+
try {
|
|
66
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
67
|
+
}
|
|
68
|
+
finally { if (e) throw e.error; }
|
|
69
|
+
}
|
|
70
|
+
return ar;
|
|
71
|
+
};
|
|
72
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
73
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
74
|
+
if (ar || !(i in from)) {
|
|
75
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
76
|
+
ar[i] = from[i];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
80
|
+
};
|
|
81
|
+
var __values = (this && this.__values) || function(o) {
|
|
82
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
83
|
+
if (m) return m.call(o);
|
|
84
|
+
if (o && typeof o.length === "number") return {
|
|
85
|
+
next: function () {
|
|
86
|
+
if (o && i >= o.length) o = void 0;
|
|
87
|
+
return { value: o && o[i++], done: !o };
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
91
|
+
};
|
|
2
92
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
93
|
+
exports.predicateFor = exports.recursivePredicateFor = exports.GroupCondition = exports.FieldCondition = exports.internals = void 0;
|
|
4
94
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
95
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
96
|
var types_1 = require("../types");
|
|
7
97
|
var index_1 = require("./index");
|
|
8
98
|
var relationship_1 = require("../storage/relationship");
|
|
9
99
|
var util_1 = require("../util");
|
|
10
|
-
var ops =
|
|
100
|
+
var ops = __spreadArray([], __read(index_1.comparisonKeys), false);
|
|
11
101
|
/**
|
|
12
102
|
* A map from keys (exposed to customers) to the internal predicate data
|
|
13
103
|
* structures invoking code should not muck with.
|
|
@@ -38,12 +128,13 @@ var registerPredicateInternals = function (condition, key) {
|
|
|
38
128
|
*
|
|
39
129
|
* @param key A key object previously returned by `registerPredicateInternals()`
|
|
40
130
|
*/
|
|
41
|
-
|
|
131
|
+
var internals = function (key) {
|
|
42
132
|
if (!predicateInternalsMap.has(key)) {
|
|
43
133
|
throw new Error("Invalid predicate. Terminate your predicate with a valid condition (e.g., `p => p.field.eq('value')`) or pass `Predicates.ALL`.");
|
|
44
134
|
}
|
|
45
135
|
return predicateInternalsMap.get(key);
|
|
46
136
|
};
|
|
137
|
+
exports.internals = internals;
|
|
47
138
|
/**
|
|
48
139
|
* Maps operators to negated operators.
|
|
49
140
|
* Used to facilitate propagation of negation down a tree of conditions.
|
|
@@ -81,7 +172,7 @@ var FieldCondition = /** @class */ (function () {
|
|
|
81
172
|
*/
|
|
82
173
|
FieldCondition.prototype.copy = function (extract) {
|
|
83
174
|
return [
|
|
84
|
-
new FieldCondition(this.field, this.operator,
|
|
175
|
+
new FieldCondition(this.field, this.operator, __spreadArray([], __read(this.operands), false)),
|
|
85
176
|
undefined,
|
|
86
177
|
];
|
|
87
178
|
};
|
|
@@ -153,8 +244,8 @@ var FieldCondition = /** @class */ (function () {
|
|
|
153
244
|
* @returns N/A. If ever implemented, return items from `storage` that match.
|
|
154
245
|
*/
|
|
155
246
|
FieldCondition.prototype.fetch = function (storage) {
|
|
156
|
-
return
|
|
157
|
-
return
|
|
247
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
248
|
+
return __generator(this, function (_a) {
|
|
158
249
|
return [2 /*return*/, Promise.reject('No implementation needed [yet].')];
|
|
159
250
|
});
|
|
160
251
|
});
|
|
@@ -165,10 +256,10 @@ var FieldCondition = /** @class */ (function () {
|
|
|
165
256
|
* @returns `Promise<boolean>`, `true` if matches; `false` otherwise.
|
|
166
257
|
*/
|
|
167
258
|
FieldCondition.prototype.matches = function (item) {
|
|
168
|
-
return
|
|
259
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
169
260
|
var v, operations, operation, result;
|
|
170
261
|
var _this = this;
|
|
171
|
-
return
|
|
262
|
+
return __generator(this, function (_a) {
|
|
172
263
|
v = item[this.field];
|
|
173
264
|
operations = {
|
|
174
265
|
eq: function () { return v === _this.operands[0]; },
|
|
@@ -188,7 +279,7 @@ var FieldCondition = /** @class */ (function () {
|
|
|
188
279
|
return [2 /*return*/, result];
|
|
189
280
|
}
|
|
190
281
|
else {
|
|
191
|
-
throw new Error("Invalid operator given: "
|
|
282
|
+
throw new Error("Invalid operator given: ".concat(this.operator));
|
|
192
283
|
}
|
|
193
284
|
return [2 /*return*/];
|
|
194
285
|
});
|
|
@@ -208,7 +299,7 @@ var FieldCondition = /** @class */ (function () {
|
|
|
208
299
|
var argsClause = count === 1 ? 'argument is' : 'arguments are';
|
|
209
300
|
return function () {
|
|
210
301
|
if (_this.operands.length !== count) {
|
|
211
|
-
return "Exactly "
|
|
302
|
+
return "Exactly ".concat(count, " ").concat(argsClause, " required.");
|
|
212
303
|
}
|
|
213
304
|
};
|
|
214
305
|
};
|
|
@@ -236,10 +327,10 @@ var FieldCondition = /** @class */ (function () {
|
|
|
236
327
|
if (validate) {
|
|
237
328
|
var e = validate();
|
|
238
329
|
if (typeof e === 'string')
|
|
239
|
-
throw new Error("Incorrect usage of `"
|
|
330
|
+
throw new Error("Incorrect usage of `".concat(this.operator, "()`: ").concat(e));
|
|
240
331
|
}
|
|
241
332
|
else {
|
|
242
|
-
throw new Error("Non-existent operator: `"
|
|
333
|
+
throw new Error("Non-existent operator: `".concat(this.operator, "()`"));
|
|
243
334
|
}
|
|
244
335
|
};
|
|
245
336
|
return FieldCondition;
|
|
@@ -252,7 +343,7 @@ exports.FieldCondition = FieldCondition;
|
|
|
252
343
|
*/
|
|
253
344
|
var getGroupId = (function () {
|
|
254
345
|
var seed = 1;
|
|
255
|
-
return function () { return "group_"
|
|
346
|
+
return function () { return "group_".concat(seed++); };
|
|
256
347
|
})();
|
|
257
348
|
/**
|
|
258
349
|
* A set of sub-conditions to operate against a model, optionally scoped to
|
|
@@ -331,7 +422,7 @@ var GroupCondition = /** @class */ (function () {
|
|
|
331
422
|
var copied = new GroupCondition(this.model, this.field, this.relationshipType, this.operator, []);
|
|
332
423
|
var extractedCopy = extract === this ? copied : undefined;
|
|
333
424
|
this.operands.forEach(function (o) {
|
|
334
|
-
var _a =
|
|
425
|
+
var _a = __read(o.copy(extract), 2), operandCopy = _a[0], extractedFromOperand = _a[1];
|
|
335
426
|
copied.operands.push(operandCopy);
|
|
336
427
|
extractedCopy = extractedCopy || extractedFromOperand;
|
|
337
428
|
});
|
|
@@ -433,11 +524,11 @@ var GroupCondition = /** @class */ (function () {
|
|
|
433
524
|
GroupCondition.prototype.fetch = function (storage, breadcrumb, negate) {
|
|
434
525
|
if (breadcrumb === void 0) { breadcrumb = []; }
|
|
435
526
|
if (negate === void 0) { negate = false; }
|
|
436
|
-
return
|
|
527
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
437
528
|
var resultGroups, operator, negateChildren, groups, conditions, groups_1, groups_1_1, g, relatives, relationship, allJoinConditions, relatives_1, relatives_1_1, relative, relativeConditions, i, predicate, _a, _b, e_1_1, predicate, _c, _d, _e, _f, getPKValue, resultIndex, resultGroups_1, resultGroups_1_1, group, intersectWith, _g, _h, k, resultGroups_2, resultGroups_2_1, group, group_1, group_1_1, item;
|
|
438
529
|
var e_1, _j, e_2, _k, _l, e_3, _m, e_4, _o, e_5, _p, e_6, _q;
|
|
439
530
|
var _this = this;
|
|
440
|
-
return
|
|
531
|
+
return __generator(this, function (_r) {
|
|
441
532
|
switch (_r.label) {
|
|
442
533
|
case 0:
|
|
443
534
|
if (!this.isOptimized) {
|
|
@@ -451,12 +542,12 @@ var GroupCondition = /** @class */ (function () {
|
|
|
451
542
|
_r.label = 1;
|
|
452
543
|
case 1:
|
|
453
544
|
_r.trys.push([1, 10, 11, 12]);
|
|
454
|
-
groups_1 =
|
|
545
|
+
groups_1 = __values(groups), groups_1_1 = groups_1.next();
|
|
455
546
|
_r.label = 2;
|
|
456
547
|
case 2:
|
|
457
548
|
if (!!groups_1_1.done) return [3 /*break*/, 9];
|
|
458
549
|
g = groups_1_1.value;
|
|
459
|
-
return [4 /*yield*/, g.fetch(storage,
|
|
550
|
+
return [4 /*yield*/, g.fetch(storage, __spreadArray(__spreadArray([], __read(breadcrumb), false), [this.groupId], false), negateChildren)];
|
|
460
551
|
case 3:
|
|
461
552
|
relatives = _r.sent();
|
|
462
553
|
// no relatives -> no need to attempt to perform a "join" query for
|
|
@@ -491,7 +582,7 @@ var GroupCondition = /** @class */ (function () {
|
|
|
491
582
|
if (!relationship) return [3 /*break*/, 5];
|
|
492
583
|
allJoinConditions = [];
|
|
493
584
|
try {
|
|
494
|
-
for (relatives_1 = (e_2 = void 0,
|
|
585
|
+
for (relatives_1 = (e_2 = void 0, __values(relatives)), relatives_1_1 = relatives_1.next(); !relatives_1_1.done; relatives_1_1 = relatives_1.next()) {
|
|
495
586
|
relative = relatives_1_1.value;
|
|
496
587
|
relativeConditions = [];
|
|
497
588
|
for (i = 0; i < relationship.localJoinFields.length; i++) {
|
|
@@ -565,7 +656,7 @@ var GroupCondition = /** @class */ (function () {
|
|
|
565
656
|
try {
|
|
566
657
|
// for each group, we intersect, removing items from the result index
|
|
567
658
|
// that aren't present in each subsequent group.
|
|
568
|
-
for (resultGroups_1 =
|
|
659
|
+
for (resultGroups_1 = __values(resultGroups), resultGroups_1_1 = resultGroups_1.next(); !resultGroups_1_1.done; resultGroups_1_1 = resultGroups_1.next()) {
|
|
569
660
|
group = resultGroups_1_1.value;
|
|
570
661
|
if (resultIndex === undefined) {
|
|
571
662
|
resultIndex = new Map(group.map(function (item) { return [getPKValue(item), item]; }));
|
|
@@ -573,7 +664,7 @@ var GroupCondition = /** @class */ (function () {
|
|
|
573
664
|
else {
|
|
574
665
|
intersectWith = new Map(group.map(function (item) { return [getPKValue(item), item]; }));
|
|
575
666
|
try {
|
|
576
|
-
for (_g = (e_4 = void 0,
|
|
667
|
+
for (_g = (e_4 = void 0, __values(resultIndex.keys())), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
577
668
|
k = _h.value;
|
|
578
669
|
if (!intersectWith.has(k)) {
|
|
579
670
|
resultIndex.delete(k);
|
|
@@ -605,10 +696,10 @@ var GroupCondition = /** @class */ (function () {
|
|
|
605
696
|
resultIndex = new Map();
|
|
606
697
|
try {
|
|
607
698
|
// just merge the groups, performing DISTINCT-ification by ID.
|
|
608
|
-
for (resultGroups_2 =
|
|
699
|
+
for (resultGroups_2 = __values(resultGroups), resultGroups_2_1 = resultGroups_2.next(); !resultGroups_2_1.done; resultGroups_2_1 = resultGroups_2.next()) {
|
|
609
700
|
group = resultGroups_2_1.value;
|
|
610
701
|
try {
|
|
611
|
-
for (group_1 = (e_6 = void 0,
|
|
702
|
+
for (group_1 = (e_6 = void 0, __values(group)), group_1_1 = group_1.next(); !group_1_1.done; group_1_1 = group_1.next()) {
|
|
612
703
|
item = group_1_1.value;
|
|
613
704
|
resultIndex.set(getPKValue(item), item);
|
|
614
705
|
}
|
|
@@ -645,23 +736,23 @@ var GroupCondition = /** @class */ (function () {
|
|
|
645
736
|
* @returns A boolean (promise): `true` if matched, `false` otherwise.
|
|
646
737
|
*/
|
|
647
738
|
GroupCondition.prototype.matches = function (item, ignoreFieldName) {
|
|
739
|
+
var _a, e_7, _b, _c;
|
|
648
740
|
if (ignoreFieldName === void 0) { ignoreFieldName = false; }
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
switch (_c.label) {
|
|
741
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
742
|
+
var itemToCheck, _d, _e, itemToCheck_1, itemToCheck_1_1, singleItem, e_7_1;
|
|
743
|
+
return __generator(this, function (_f) {
|
|
744
|
+
switch (_f.label) {
|
|
654
745
|
case 0:
|
|
655
746
|
if (!(this.field && !ignoreFieldName)) return [3 /*break*/, 2];
|
|
656
747
|
return [4 /*yield*/, item[this.field]];
|
|
657
748
|
case 1:
|
|
658
|
-
|
|
749
|
+
_d = _f.sent();
|
|
659
750
|
return [3 /*break*/, 3];
|
|
660
751
|
case 2:
|
|
661
|
-
|
|
662
|
-
|
|
752
|
+
_d = item;
|
|
753
|
+
_f.label = 3;
|
|
663
754
|
case 3:
|
|
664
|
-
itemToCheck =
|
|
755
|
+
itemToCheck = _d;
|
|
665
756
|
// if there is no item to check, we can stop recursing immediately.
|
|
666
757
|
// a condition cannot match against an item that does not exist. this
|
|
667
758
|
// can occur when `item.field` is optional in the schema.
|
|
@@ -669,55 +760,63 @@ var GroupCondition = /** @class */ (function () {
|
|
|
669
760
|
return [2 /*return*/, false];
|
|
670
761
|
}
|
|
671
762
|
if (!(this.relationshipType === 'HAS_MANY' &&
|
|
672
|
-
typeof itemToCheck[Symbol.asyncIterator] === 'function')) return [3 /*break*/,
|
|
673
|
-
|
|
763
|
+
typeof itemToCheck[Symbol.asyncIterator] === 'function')) return [3 /*break*/, 19];
|
|
764
|
+
_f.label = 4;
|
|
674
765
|
case 4:
|
|
675
|
-
|
|
676
|
-
itemToCheck_1 =
|
|
677
|
-
|
|
766
|
+
_f.trys.push([4, 12, 13, 18]);
|
|
767
|
+
_e = true, itemToCheck_1 = __asyncValues(itemToCheck);
|
|
768
|
+
_f.label = 5;
|
|
678
769
|
case 5: return [4 /*yield*/, itemToCheck_1.next()];
|
|
679
770
|
case 6:
|
|
680
|
-
if (!(itemToCheck_1_1 =
|
|
681
|
-
|
|
682
|
-
|
|
771
|
+
if (!(itemToCheck_1_1 = _f.sent(), _a = itemToCheck_1_1.done, !_a)) return [3 /*break*/, 11];
|
|
772
|
+
_c = itemToCheck_1_1.value;
|
|
773
|
+
_e = false;
|
|
774
|
+
_f.label = 7;
|
|
683
775
|
case 7:
|
|
684
|
-
|
|
776
|
+
_f.trys.push([7, , 9, 10]);
|
|
777
|
+
singleItem = _c;
|
|
778
|
+
return [4 /*yield*/, this.matches(singleItem, true)];
|
|
779
|
+
case 8:
|
|
780
|
+
if (_f.sent()) {
|
|
685
781
|
return [2 /*return*/, true];
|
|
686
782
|
}
|
|
687
|
-
|
|
688
|
-
case
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
return [3 /*break*/, 16];
|
|
694
|
-
case 11:
|
|
695
|
-
_c.trys.push([11, , 14, 15]);
|
|
696
|
-
if (!(itemToCheck_1_1 && !itemToCheck_1_1.done && (_a = itemToCheck_1.return))) return [3 /*break*/, 13];
|
|
697
|
-
return [4 /*yield*/, _a.call(itemToCheck_1)];
|
|
783
|
+
return [3 /*break*/, 10];
|
|
784
|
+
case 9:
|
|
785
|
+
_e = true;
|
|
786
|
+
return [7 /*endfinally*/];
|
|
787
|
+
case 10: return [3 /*break*/, 5];
|
|
788
|
+
case 11: return [3 /*break*/, 18];
|
|
698
789
|
case 12:
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
790
|
+
e_7_1 = _f.sent();
|
|
791
|
+
e_7 = { error: e_7_1 };
|
|
792
|
+
return [3 /*break*/, 18];
|
|
793
|
+
case 13:
|
|
794
|
+
_f.trys.push([13, , 16, 17]);
|
|
795
|
+
if (!(!_e && !_a && (_b = itemToCheck_1.return))) return [3 /*break*/, 15];
|
|
796
|
+
return [4 /*yield*/, _b.call(itemToCheck_1)];
|
|
702
797
|
case 14:
|
|
798
|
+
_f.sent();
|
|
799
|
+
_f.label = 15;
|
|
800
|
+
case 15: return [3 /*break*/, 17];
|
|
801
|
+
case 16:
|
|
703
802
|
if (e_7) throw e_7.error;
|
|
704
803
|
return [7 /*endfinally*/];
|
|
705
|
-
case
|
|
706
|
-
case
|
|
707
|
-
case 17:
|
|
708
|
-
if (!(this.operator === 'or')) return [3 /*break*/, 18];
|
|
709
|
-
return [2 /*return*/, util_1.asyncSome(this.operands, function (c) { return c.matches(itemToCheck); })];
|
|
710
|
-
case 18:
|
|
711
|
-
if (!(this.operator === 'and')) return [3 /*break*/, 19];
|
|
712
|
-
return [2 /*return*/, util_1.asyncEvery(this.operands, function (c) { return c.matches(itemToCheck); })];
|
|
804
|
+
case 17: return [7 /*endfinally*/];
|
|
805
|
+
case 18: return [2 /*return*/, false];
|
|
713
806
|
case 19:
|
|
714
|
-
if (!(this.operator === '
|
|
807
|
+
if (!(this.operator === 'or')) return [3 /*break*/, 20];
|
|
808
|
+
return [2 /*return*/, (0, util_1.asyncSome)(this.operands, function (c) { return c.matches(itemToCheck); })];
|
|
809
|
+
case 20:
|
|
810
|
+
if (!(this.operator === 'and')) return [3 /*break*/, 21];
|
|
811
|
+
return [2 /*return*/, (0, util_1.asyncEvery)(this.operands, function (c) { return c.matches(itemToCheck); })];
|
|
812
|
+
case 21:
|
|
813
|
+
if (!(this.operator === 'not')) return [3 /*break*/, 23];
|
|
715
814
|
if (this.operands.length !== 1) {
|
|
716
815
|
throw new Error('Invalid arguments! `not()` accepts exactly one predicate expression.');
|
|
717
816
|
}
|
|
718
817
|
return [4 /*yield*/, this.operands[0].matches(itemToCheck)];
|
|
719
|
-
case
|
|
720
|
-
case
|
|
818
|
+
case 22: return [2 /*return*/, !(_f.sent())];
|
|
819
|
+
case 23: throw new Error('Invalid group operator!');
|
|
721
820
|
}
|
|
722
821
|
});
|
|
723
822
|
});
|
|
@@ -745,7 +844,7 @@ var GroupCondition = /** @class */ (function () {
|
|
|
745
844
|
* A JSON representation that's good for debugging.
|
|
746
845
|
*/
|
|
747
846
|
GroupCondition.prototype.toJSON = function () {
|
|
748
|
-
return
|
|
847
|
+
return __assign(__assign({}, this), { model: this.model.schema.name });
|
|
749
848
|
};
|
|
750
849
|
return GroupCondition;
|
|
751
850
|
}());
|
|
@@ -789,7 +888,7 @@ function recursivePredicateFor(ModelType, allowRecursion, field, query, tail) {
|
|
|
789
888
|
// so it can be looked up later with in the internals when processing conditions.
|
|
790
889
|
registerPredicateInternals(baseCondition, link);
|
|
791
890
|
var copyLink = function () {
|
|
792
|
-
var _a =
|
|
891
|
+
var _a = __read(baseCondition.copy(tailCondition), 2), query = _a[0], newTail = _a[1];
|
|
793
892
|
var newLink = recursivePredicateFor(ModelType, allowRecursion, undefined, query, newTail);
|
|
794
893
|
return { query: query, newTail: newTail, newLink: newLink };
|
|
795
894
|
};
|
|
@@ -802,11 +901,11 @@ function recursivePredicateFor(ModelType, allowRecursion, field, query, tail) {
|
|
|
802
901
|
var _a = copyLink(), query = _a.query, newTail = _a.newTail;
|
|
803
902
|
var childConditions = builder(recursivePredicateFor(ModelType, allowRecursion));
|
|
804
903
|
if (!Array.isArray(childConditions)) {
|
|
805
|
-
throw new Error("Invalid predicate. `"
|
|
904
|
+
throw new Error("Invalid predicate. `".concat(op, "` groups must return an array of child conditions."));
|
|
806
905
|
}
|
|
807
906
|
// the customer will supply a child predicate, which apply to the `model.field`
|
|
808
907
|
// of the tail GroupCondition.
|
|
809
|
-
newTail === null || newTail === void 0 ? void 0 : newTail.operands.push(new GroupCondition(ModelType, field, undefined, op, childConditions.map(function (c) { return exports.internals(c); })));
|
|
908
|
+
newTail === null || newTail === void 0 ? void 0 : newTail.operands.push(new GroupCondition(ModelType, field, undefined, op, childConditions.map(function (c) { return (0, exports.internals)(c); })));
|
|
810
909
|
// FinalPredicate
|
|
811
910
|
return registerPredicateInternals(query);
|
|
812
911
|
};
|
|
@@ -820,7 +919,7 @@ function recursivePredicateFor(ModelType, allowRecursion, field, query, tail) {
|
|
|
820
919
|
// the difference being: not() does not accept an array of predicate-like objects.
|
|
821
920
|
// it negates only a *single* predicate subtree.
|
|
822
921
|
newTail === null || newTail === void 0 ? void 0 : newTail.operands.push(new GroupCondition(ModelType, field, undefined, 'not', [
|
|
823
|
-
exports.internals(builder(recursivePredicateFor(ModelType, allowRecursion))),
|
|
922
|
+
(0, exports.internals)(builder(recursivePredicateFor(ModelType, allowRecursion))),
|
|
824
923
|
]));
|
|
825
924
|
// A `FinalModelPredicate`.
|
|
826
925
|
// Return a thing that can no longer be extended, but instead used to `async filter(items)`
|
|
@@ -839,7 +938,7 @@ function recursivePredicateFor(ModelType, allowRecursion, field, query, tail) {
|
|
|
839
938
|
// against the target field (fieldName).
|
|
840
939
|
return ops.reduce(function (fieldMatcher, operator) {
|
|
841
940
|
var _a;
|
|
842
|
-
return
|
|
941
|
+
return __assign(__assign({}, fieldMatcher), (_a = {}, _a[operator] = function () {
|
|
843
942
|
var operands = [];
|
|
844
943
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
845
944
|
operands[_i] = arguments[_i];
|
|
@@ -878,7 +977,7 @@ function recursivePredicateFor(ModelType, allowRecursion, field, query, tail) {
|
|
|
878
977
|
// `Model.reletedModelField` returns a copy of the original link,
|
|
879
978
|
// and will contains copies of internal GroupConditions
|
|
880
979
|
// to head off mutability concerns.
|
|
881
|
-
var _a =
|
|
980
|
+
var _a = __read(baseCondition.copy(tailCondition), 2), newquery = _a[0], oldtail = _a[1];
|
|
882
981
|
var newtail = new GroupCondition(relatedMeta, fieldName, def.association.connectionType, 'and', []);
|
|
883
982
|
// `oldtail` here refers to the *copy* of the old tail.
|
|
884
983
|
// so, it's safe to modify at this point. and we need to modify
|
|
@@ -909,4 +1008,3 @@ function predicateFor(ModelType) {
|
|
|
909
1008
|
return recursivePredicateFor(ModelType, false);
|
|
910
1009
|
}
|
|
911
1010
|
exports.predicateFor = predicateFor;
|
|
912
|
-
//# sourceMappingURL=next.js.map
|
package/lib/predicates/sort.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.ModelSortPredicateCreator = void 0;
|
|
4
|
+
var ModelSortPredicateCreator = exports.ModelSortPredicateCreator = /** @class */ (function () {
|
|
4
5
|
function ModelSortPredicateCreator() {
|
|
5
6
|
}
|
|
6
7
|
ModelSortPredicateCreator.createPredicateBuilder = function (modelDefinition) {
|
|
@@ -11,7 +12,7 @@ var ModelSortPredicateCreator = /** @class */ (function () {
|
|
|
11
12
|
get: function (_target, propertyKey, receiver) {
|
|
12
13
|
var field = propertyKey;
|
|
13
14
|
if (!fieldNames.has(field)) {
|
|
14
|
-
throw new Error("Invalid field for model. field: "
|
|
15
|
+
throw new Error("Invalid field for model. field: ".concat(String(field), ", model: ").concat(modelName));
|
|
15
16
|
}
|
|
16
17
|
var result = function (sortDirection) {
|
|
17
18
|
var _a;
|
|
@@ -52,5 +53,3 @@ var ModelSortPredicateCreator = /** @class */ (function () {
|
|
|
52
53
|
ModelSortPredicateCreator.sortPredicateGroupsMap = new WeakMap();
|
|
53
54
|
return ModelSortPredicateCreator;
|
|
54
55
|
}());
|
|
55
|
-
exports.ModelSortPredicateCreator = ModelSortPredicateCreator;
|
|
56
|
-
//# sourceMappingURL=sort.js.map
|
package/lib/ssr/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeModel = exports.deserializeModel = void 0;
|
|
3
4
|
// Helper for converting JSON back into DataStore models (while respecting IDs)
|
|
4
5
|
function deserializeModel(Model, init) {
|
|
5
6
|
if (Array.isArray(init)) {
|
|
@@ -15,4 +16,3 @@ function serializeModel(model) {
|
|
|
15
16
|
return JSON.parse(JSON.stringify(model));
|
|
16
17
|
}
|
|
17
18
|
exports.serializeModel = serializeModel;
|
|
18
|
-
//# sourceMappingURL=index.js.map
|