j-templates 8.0.14 → 8.0.15
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/Store/Diff/diffTree.js +22 -4
- package/package.json +1 -1
package/Store/Diff/diffTree.js
CHANGED
|
@@ -160,7 +160,14 @@ function BuildProjectionOrder(projections) {
|
|
|
160
160
|
throw new Error(`DiffTree projection "${id}" is not defined`);
|
|
161
161
|
state.set(id, "visiting");
|
|
162
162
|
for (let x = 0; x < def.reads.length; x++) {
|
|
163
|
-
const
|
|
163
|
+
const read = def.reads[x];
|
|
164
|
+
const root = read.split(".", 1)[0];
|
|
165
|
+
if (root.endsWith("*") && x !== def.reads.length - 1)
|
|
166
|
+
throw `Wildcard reads only supported as the final read: ${root}`;
|
|
167
|
+
if (root.endsWith("*") && root.includes("."))
|
|
168
|
+
throw `Wildcard reads do not support dot nesting: ${root}`;
|
|
169
|
+
if (root.startsWith(PROJECTION_PREFIX) && read.endsWith("*"))
|
|
170
|
+
throw `Projection keys do not support wildcard reads: ${root}`;
|
|
164
171
|
if (root.startsWith(PROJECTION_PREFIX))
|
|
165
172
|
Visit(root.slice(PROJECTION_PREFIX.length), stack.concat(id));
|
|
166
173
|
}
|
|
@@ -203,13 +210,24 @@ function RunProjections(source, keyFunc, projections, memo) {
|
|
|
203
210
|
const diffResult = [];
|
|
204
211
|
for (let x = 0; x < projections.length; x++) {
|
|
205
212
|
const { id, reads, projection } = projections[x];
|
|
206
|
-
const values =
|
|
213
|
+
const values = [];
|
|
207
214
|
let allPathsExist = true;
|
|
208
|
-
|
|
209
|
-
|
|
215
|
+
let y = 0;
|
|
216
|
+
for (; allPathsExist && y < reads.length && !reads[y].endsWith("*"); y++) {
|
|
217
|
+
const read = reads[y];
|
|
218
|
+
const [value, found] = GetPathValue(source, read);
|
|
210
219
|
allPathsExist = found;
|
|
211
220
|
values[y] = (found && CreateSnapshot(source, keyFunc, value)) || value;
|
|
212
221
|
}
|
|
222
|
+
if (y < reads.length && reads[y].endsWith("*")) {
|
|
223
|
+
const prefix = reads[y].slice(0, reads[y].length - 1);
|
|
224
|
+
const keys = Object.keys(source).filter(key => key.startsWith(prefix));
|
|
225
|
+
for (let z = 0; z < keys.length; z++) {
|
|
226
|
+
const [value, found] = GetPathValue(source, keys[z]);
|
|
227
|
+
allPathsExist = allPathsExist && found;
|
|
228
|
+
values.push((found && CreateSnapshot(source, keyFunc, value)) || value);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
213
231
|
if (allPathsExist) {
|
|
214
232
|
const priorValues = memo.get(id);
|
|
215
233
|
if (!ArraysEqual(priorValues, values)) {
|