json-fs-query 1.0.2 → 1.0.3
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/browser/jsonFsQuery.js +21 -5
- package/browser/jsonFsQuery.min.js +1 -1
- package/dist/data/queries/joinEntity.d.ts +1 -1
- package/dist/data/queries/joinEntity.js +7 -2
- package/dist/data/queries/joinEntity.min.js +1 -1
- package/dist/data/utilities/runQuery.js +14 -3
- package/dist/data/utilities/runQuery.min.js +1 -1
- package/package.json +1 -1
package/browser/jsonFsQuery.js
CHANGED
|
@@ -749,8 +749,13 @@
|
|
|
749
749
|
const _readEntity = require('./readEntity')
|
|
750
750
|
const _useJoinClause = require('../utilities/useJoinClause')
|
|
751
751
|
function _interopRequireDefault (e) { return e && e.__esModule ? e : { default: e } }
|
|
752
|
-
const joinEntity = async (entity, joinEntity, dataSets = {}, joinClauses = []) => {
|
|
753
|
-
|
|
752
|
+
const joinEntity = async (entity, joinEntity, dataSets = {}, joinClauses = [], entityAlreadyResolved = false) => {
|
|
753
|
+
// Same ambiguity readEntity() always has (can't tell "never loaded" from "loaded, zero rows
|
|
754
|
+
// matched") - runQuery already resolved entity's rows via an indexed condition in that second
|
|
755
|
+
// case, so entityAlreadyResolved tells this call not to reload and silently discard that result.
|
|
756
|
+
if (!entityAlreadyResolved) {
|
|
757
|
+
dataSets = await (0, _readEntity.readEntity)(entity, dataSets)
|
|
758
|
+
}
|
|
754
759
|
if (!joinClauses.length) {
|
|
755
760
|
return dataSets
|
|
756
761
|
}
|
|
@@ -2400,14 +2405,23 @@
|
|
|
2400
2405
|
let dataSet = {
|
|
2401
2406
|
[parsed.entity]: []
|
|
2402
2407
|
}
|
|
2408
|
+
// A condition that's indexed but genuinely matches nothing leaves dataSet[entity] at [] - the
|
|
2409
|
+
// same state it starts in before anything has looked at it at all. readEntity() (below) can't
|
|
2410
|
+
// tell those two states apart on its own (it reloads whenever the array is empty, regardless of
|
|
2411
|
+
// why), so capture here, before that ambiguity can happen, whether every condition actually got
|
|
2412
|
+
// resolved this way - if so, dataSet[entity] is already correct and must not be reloaded.
|
|
2413
|
+
const hadConditions = parsed.conditions.length > 0
|
|
2403
2414
|
parsed = await (0, _getConditionIndexedList.getConditionIndexedList)(parsed, recordData, dataSet)
|
|
2415
|
+
const conditionsFullyIndexed = hadConditions && parsed.conditions.length === 0
|
|
2404
2416
|
parsed = await (0, _getJoinIndexedList.getJoinIndexedList)(parsed, recordData, dataSet)
|
|
2405
2417
|
// delete/update act on whatever is already in dataSet[entity] - unlike read, which loads
|
|
2406
2418
|
// everything and lets the where-reduce below narrow it down afterward, they never get a second
|
|
2407
2419
|
// pass. So the matching rows have to be fully resolved (indexed conditions already are, via
|
|
2408
2420
|
// getConditionIndexedList above; anything left in parsed.conditions is not) before either runs.
|
|
2409
2421
|
if (parsed.command === 'delete' || parsed.command === 'update') {
|
|
2410
|
-
|
|
2422
|
+
if (!conditionsFullyIndexed) {
|
|
2423
|
+
dataSet = await (0, _readEntity.readEntity)(parsed.entity, dataSet)
|
|
2424
|
+
}
|
|
2411
2425
|
dataSet[parsed.entity] = parsed.conditions.reduce((remainingData, condition) => (0, _where.where)(remainingData, condition), dataSet[parsed.entity])
|
|
2412
2426
|
}
|
|
2413
2427
|
switch (parsed.command) {
|
|
@@ -2418,7 +2432,9 @@
|
|
|
2418
2432
|
dataSet = await (0, _insertEntity.insertEntity)(parsed.entity, parsed.insertValues, dataSet)
|
|
2419
2433
|
break
|
|
2420
2434
|
case 'read':
|
|
2421
|
-
|
|
2435
|
+
if (!conditionsFullyIndexed) {
|
|
2436
|
+
dataSet = await (0, _readEntity.readEntity)(parsed.entity, dataSet)
|
|
2437
|
+
}
|
|
2422
2438
|
break
|
|
2423
2439
|
case 'update':
|
|
2424
2440
|
dataSet = await (0, _updateEntity.updateEntity)(parsed.entity, parsed.updateValues, dataSet)
|
|
@@ -2426,7 +2442,7 @@
|
|
|
2426
2442
|
default:
|
|
2427
2443
|
throw new Error(`Unknown command: ${parsed.command}`)
|
|
2428
2444
|
}
|
|
2429
|
-
dataSet = await (0, _joinEntity.joinEntity)(parsed.entity, parsed.joinEntity, dataSet, parsed.joinClauses)
|
|
2445
|
+
dataSet = await (0, _joinEntity.joinEntity)(parsed.entity, parsed.joinEntity, dataSet, parsed.joinClauses, conditionsFullyIndexed)
|
|
2430
2446
|
dataSet = await (0, _mergeJoins.mergeJoins)(dataSet, parsed.mergeJoins)
|
|
2431
2447
|
// delete/update already had parsed.conditions applied above, before they ran. Re-applying the
|
|
2432
2448
|
// same conditions here would be wrong, not just redundant, for update specifically: if the
|