json-fs-query 1.0.5 → 1.0.6

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.
Files changed (70) hide show
  1. package/browser/jsonFsQuery.js +2 -2
  2. package/browser/jsonFsQuery.min.js +1 -1
  3. package/dist/data/introspect/create.js +46 -46
  4. package/dist/data/introspect/definitions/field.js +35 -35
  5. package/dist/data/introspect/definitions/key.js +52 -52
  6. package/dist/data/introspect/definitions/keyReference.js +19 -19
  7. package/dist/data/introspect/definitions/record.js +31 -31
  8. package/dist/data/introspect/describe.js +14 -14
  9. package/dist/data/introspect/drop.js +36 -36
  10. package/dist/data/introspect/index.js +29 -29
  11. package/dist/data/introspect/policies/foreignKeyExists.js +24 -24
  12. package/dist/data/introspect/policies/hasDependents.js +51 -51
  13. package/dist/data/introspect/policies/keyGenerate.js +16 -16
  14. package/dist/data/introspect/policies/keyUnique.js +30 -30
  15. package/dist/data/introspect/policies/typeCheck.js +56 -56
  16. package/dist/data/introspect/policies/typeEnum.js +13 -13
  17. package/dist/data/introspect/policies/useDefault.js +12 -12
  18. package/dist/data/queries/deleteEntity.js +99 -99
  19. package/dist/data/queries/groupBy.js +21 -21
  20. package/dist/data/queries/insertEntity.js +116 -116
  21. package/dist/data/queries/joinEntity.js +31 -31
  22. package/dist/data/queries/limitOffset.js +20 -20
  23. package/dist/data/queries/mergeJoins.js +18 -18
  24. package/dist/data/queries/parser.js +29 -29
  25. package/dist/data/queries/query.js +17 -17
  26. package/dist/data/queries/readEntity.js +13 -13
  27. package/dist/data/queries/selectFields.js +35 -35
  28. package/dist/data/queries/sortBy.js +24 -24
  29. package/dist/data/queries/updateEntity.js +189 -189
  30. package/dist/data/queries/where.js +55 -55
  31. package/dist/data/utilities/computeKeyValue.js +25 -25
  32. package/dist/data/utilities/config.js +44 -44
  33. package/dist/data/utilities/deregisterRecord.js +33 -33
  34. package/dist/data/utilities/getConditionIndexedList.js +46 -46
  35. package/dist/data/utilities/getJoinIndexedList.js +75 -75
  36. package/dist/data/utilities/getMatchingIndexes.js +27 -27
  37. package/dist/data/utilities/matchIndexedJoins.js +60 -60
  38. package/dist/data/utilities/mergeJoin.js +43 -43
  39. package/dist/data/utilities/parsers/findCommand.js +24 -24
  40. package/dist/data/utilities/parsers/findConditions.js +27 -27
  41. package/dist/data/utilities/parsers/findGroupBy.js +21 -21
  42. package/dist/data/utilities/parsers/findInsertValues.js +33 -33
  43. package/dist/data/utilities/parsers/findJoinClauses.js +26 -26
  44. package/dist/data/utilities/parsers/findJoinEntity.js +21 -21
  45. package/dist/data/utilities/parsers/findLimit.js +21 -21
  46. package/dist/data/utilities/parsers/findMergeJoins.js +25 -25
  47. package/dist/data/utilities/parsers/findOffset.js +21 -21
  48. package/dist/data/utilities/parsers/findSelects.js +29 -29
  49. package/dist/data/utilities/parsers/findSortClauses.js +29 -29
  50. package/dist/data/utilities/parsers/findUpdateValues.js +33 -33
  51. package/dist/data/utilities/parsers/isEntityProperty.js +7 -7
  52. package/dist/data/utilities/parsers/parseLiteralValue.js +33 -33
  53. package/dist/data/utilities/parsers/parseQuery.js +50 -50
  54. package/dist/data/utilities/parsers/removeFromQuery.js +7 -7
  55. package/dist/data/utilities/parsers/splitEntityProperty.js +22 -22
  56. package/dist/data/utilities/parsers/splitQueries.js +10 -10
  57. package/dist/data/utilities/reconcileJoin.js +25 -25
  58. package/dist/data/utilities/reconcileJoins.js +25 -25
  59. package/dist/data/utilities/registerRecord.js +66 -66
  60. package/dist/data/utilities/removeFromIndex.js +43 -43
  61. package/dist/data/utilities/restrictIndexedList.js +44 -44
  62. package/dist/data/utilities/retrieveFile.js +27 -27
  63. package/dist/data/utilities/retrieveIndexes.js +23 -23
  64. package/dist/data/utilities/retrieveRecord.js +8 -8
  65. package/dist/data/utilities/retrieveRecords.js +20 -20
  66. package/dist/data/utilities/runQuery.js +86 -86
  67. package/dist/data/utilities/updateIndex.js +55 -55
  68. package/dist/data/utilities/useJoinClause.js +50 -50
  69. package/dist/index.js +41 -41
  70. package/package.json +9 -5
@@ -1,34 +1,34 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.deregisterRecord = void 0;
7
- require("core-js/modules/es.json.stringify.js");
8
- require("core-js/modules/esnext.iterator.constructor.js");
9
- require("core-js/modules/esnext.iterator.filter.js");
10
- var _config = require("./config");
11
- const {
12
- readFile,
13
- writeFile
14
- } = require('fs/promises');
15
- /**
16
- * Remove a record's filename from the __RECORDS registry. A missing registry file is left
17
- * untouched rather than created, since there's nothing to remove from it.
18
- * @param recordName
19
- */
20
- const deregisterRecord = async recordName => {
21
- const databasePath = (0, _config.getSetting)('databasePath', 'database/');
22
- const registryPath = `${databasePath}__RECORDS.json`;
23
- let registry;
24
- try {
25
- registry = JSON.parse(await readFile(registryPath, 'utf8'));
26
- } catch (err) {
27
- return null;
28
- }
29
- const fileName = `${recordName}.json`;
30
- registry.entries = registry.entries.filter(entry => entry !== fileName);
31
- await writeFile(registryPath, JSON.stringify(registry, null, 2));
32
- return registry;
33
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.deregisterRecord = void 0;
7
+ require("core-js/modules/es.json.stringify.js");
8
+ require("core-js/modules/esnext.iterator.constructor.js");
9
+ require("core-js/modules/esnext.iterator.filter.js");
10
+ var _config = require("./config");
11
+ const {
12
+ readFile,
13
+ writeFile
14
+ } = require('fs/promises');
15
+ /**
16
+ * Remove a record's filename from the __RECORDS registry. A missing registry file is left
17
+ * untouched rather than created, since there's nothing to remove from it.
18
+ * @param recordName
19
+ */
20
+ const deregisterRecord = async recordName => {
21
+ const databasePath = (0, _config.getSetting)('databasePath', 'database/');
22
+ const registryPath = `${databasePath}__RECORDS.json`;
23
+ let registry;
24
+ try {
25
+ registry = JSON.parse(await readFile(registryPath, 'utf8'));
26
+ } catch (err) {
27
+ return null;
28
+ }
29
+ const fileName = `${recordName}.json`;
30
+ registry.entries = registry.entries.filter(entry => entry !== fileName);
31
+ await writeFile(registryPath, JSON.stringify(registry, null, 2));
32
+ return registry;
33
+ };
34
34
  exports.deregisterRecord = deregisterRecord;
@@ -1,47 +1,47 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getConditionIndexedList = void 0;
7
- var _isEntityProperty = require("./parsers/isEntityProperty");
8
- var _splitEntityProperty = require("./parsers/splitEntityProperty");
9
- var _retrieveRecord = require("./retrieveRecord");
10
- var _where = require("../queries/where");
11
- var _retrieveFile = require("./retrieveFile");
12
- var _getMatchingIndexes = require("./getMatchingIndexes");
13
- const getConditionIndexedList = async (parsed, recordData, dataSet) => {
14
- const reducedConditions = [];
15
- for (const condition of parsed.conditions) {
16
- let entity = parsed.entity;
17
- let property = condition.property;
18
- if ((0, _isEntityProperty.isEntityProperty)(property)) {
19
- const entityProperty = (0, _splitEntityProperty.splitEntityProperty)(property);
20
- entity = entityProperty.entity;
21
- property = entityProperty.property;
22
- }
23
- if (!Object.prototype.hasOwnProperty.call(recordData, entity)) {
24
- recordData[entity] = await (0, _retrieveRecord.retrieveRecord)(entity);
25
- }
26
- const indexed = {};
27
- const retrieveMatchedFiles = async (entity, property, recordData, condition, dataSet, indexed) => {
28
- const matchedRecords = (0, _where.where)(indexed[entity][property], {
29
- property: 'value',
30
- comparator: condition.comparator,
31
- value: condition.value
32
- });
33
- for (const matchedRecord of matchedRecords) {
34
- for (const file of matchedRecord.record) {
35
- dataSet[entity].push(await (0, _retrieveFile.retrieveFile)(`${entity}/${file}`));
36
- }
37
- }
38
- };
39
- const isIndexed = await (0, _getMatchingIndexes.getMatchingIndexes)(entity, property, recordData, condition, dataSet, indexed, retrieveMatchedFiles);
40
- if (!isIndexed) {
41
- reducedConditions.push(condition);
42
- }
43
- }
44
- parsed.conditions = reducedConditions;
45
- return parsed;
46
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getConditionIndexedList = void 0;
7
+ var _isEntityProperty = require("./parsers/isEntityProperty");
8
+ var _splitEntityProperty = require("./parsers/splitEntityProperty");
9
+ var _retrieveRecord = require("./retrieveRecord");
10
+ var _where = require("../queries/where");
11
+ var _retrieveFile = require("./retrieveFile");
12
+ var _getMatchingIndexes = require("./getMatchingIndexes");
13
+ const getConditionIndexedList = async (parsed, recordData, dataSet) => {
14
+ const reducedConditions = [];
15
+ for (const condition of parsed.conditions) {
16
+ let entity = parsed.entity;
17
+ let property = condition.property;
18
+ if ((0, _isEntityProperty.isEntityProperty)(property)) {
19
+ const entityProperty = (0, _splitEntityProperty.splitEntityProperty)(property);
20
+ entity = entityProperty.entity;
21
+ property = entityProperty.property;
22
+ }
23
+ if (!Object.prototype.hasOwnProperty.call(recordData, entity)) {
24
+ recordData[entity] = await (0, _retrieveRecord.retrieveRecord)(entity);
25
+ }
26
+ const indexed = {};
27
+ const retrieveMatchedFiles = async (entity, property, recordData, condition, dataSet, indexed) => {
28
+ const matchedRecords = (0, _where.where)(indexed[entity][property], {
29
+ property: 'value',
30
+ comparator: condition.comparator,
31
+ value: condition.value
32
+ });
33
+ for (const matchedRecord of matchedRecords) {
34
+ for (const file of matchedRecord.record) {
35
+ dataSet[entity].push(await (0, _retrieveFile.retrieveFile)(`${entity}/${file}`));
36
+ }
37
+ }
38
+ };
39
+ const isIndexed = await (0, _getMatchingIndexes.getMatchingIndexes)(entity, property, recordData, condition, dataSet, indexed, retrieveMatchedFiles);
40
+ if (!isIndexed) {
41
+ reducedConditions.push(condition);
42
+ }
43
+ }
44
+ parsed.conditions = reducedConditions;
45
+ return parsed;
46
+ };
47
47
  exports.getConditionIndexedList = getConditionIndexedList;
@@ -1,76 +1,76 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getJoinIndexedList = void 0;
7
- var _siFunciona = _interopRequireDefault(require("si-funciona"));
8
- var _splitEntityProperty = require("./parsers/splitEntityProperty");
9
- var _retrieveRecord = require("./retrieveRecord");
10
- var _getMatchingIndexes = require("./getMatchingIndexes");
11
- var _matchIndexedJoins = require("./matchIndexedJoins");
12
- var _restrictIndexedList = require("./restrictIndexedList");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- const getJoinIndexedList = async (parsed, recordData, dataSets) => {
15
- const reducedJoins = [];
16
- const indexed = {};
17
- let firstIteration = true;
18
- const entity = parsed.entity;
19
- const joinEntity = parsed.joinEntity;
20
- const joinClauses = parsed.joinClauses;
21
- if (!dataSets[entity].length) {
22
- // Nothing indexed entity's own rows yet (no WHERE condition narrowed them down ahead of this -
23
- // that only happens via getConditionIndexedList, called just before this). The loop below can't
24
- // pre-resolve anything against zero rows, so leave parsed.joinClauses exactly as parsed: the
25
- // later, unconditional joinEntity() call (once this command's own read actually runs) still
26
- // needs the real clauses to do the join itself. Previously this fell through to the loop,
27
- // which never ran, leaving reducedJoins (and so parsed.joinClauses) empty regardless of what
28
- // was actually parsed - silently discarding every join clause whenever the query had no WHERE.
29
- return parsed;
30
- }
31
- if (!joinClauses.length) {
32
- // A WHERE condition DID index entity's own rows above, but this query has no join at all -
33
- // joinEntity is undefined. The loop below writes dataSets[entity][anEntity][joinEntity]
34
- // unconditionally; left unguarded, that assigns a literal "undefined" key (object[undefined]
35
- // coerces to the string "undefined") onto every row, since there's no join to actually attach.
36
- return parsed;
37
- }
38
- for (const anEntity in dataSets[entity]) {
39
- const currentEntity = dataSets[entity][anEntity];
40
- // Loop over each of the main entities
41
- const filterJoins = {};
42
- filterJoins[entity] = [_siFunciona.default.cloneObject(currentEntity)];
43
- for (const joinClause of joinClauses) {
44
- let indexedClone = _siFunciona.default.cloneObject(indexed);
45
- const {
46
- entity: entityA,
47
- property: propertyA
48
- } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyA);
49
- const {
50
- entity: entityB,
51
- property: propertyB
52
- } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyB);
53
- // Get the record for the entities A and B, store on the recordData
54
- if (!Object.prototype.hasOwnProperty.call(recordData, entityA)) {
55
- recordData[entityA] = await (0, _retrieveRecord.retrieveRecord)(entityA);
56
- }
57
- if (!Object.prototype.hasOwnProperty.call(recordData, entityB)) {
58
- recordData[entityB] = await (0, _retrieveRecord.retrieveRecord)(entityB);
59
- }
60
- indexedClone = (0, _restrictIndexedList.restrictIndexedList)(joinClause, filterJoins, indexedClone);
61
- const retrieveMatchedFiles = (0, _matchIndexedJoins.matchIndexedJoins)(entity, indexedClone, dataSets);
62
- // Check if there are matching keys for the join condition
63
- const matchAResult = await (0, _getMatchingIndexes.getMatchingIndexes)(entityA, propertyA, recordData, joinClause, filterJoins, indexed);
64
- const matchBResult = await (0, _getMatchingIndexes.getMatchingIndexes)(entityB, propertyB, recordData, joinClause, filterJoins, indexed, retrieveMatchedFiles);
65
- const isIndexed = matchAResult || matchBResult;
66
- if (!isIndexed && firstIteration) {
67
- reducedJoins.push(joinClause);
68
- firstIteration = false;
69
- }
70
- }
71
- dataSets[entity][anEntity][joinEntity] = filterJoins[joinEntity];
72
- }
73
- parsed.joinClauses = reducedJoins;
74
- return parsed;
75
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getJoinIndexedList = void 0;
7
+ var _siFunciona = _interopRequireDefault(require("si-funciona"));
8
+ var _splitEntityProperty = require("./parsers/splitEntityProperty");
9
+ var _retrieveRecord = require("./retrieveRecord");
10
+ var _getMatchingIndexes = require("./getMatchingIndexes");
11
+ var _matchIndexedJoins = require("./matchIndexedJoins");
12
+ var _restrictIndexedList = require("./restrictIndexedList");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ const getJoinIndexedList = async (parsed, recordData, dataSets) => {
15
+ const reducedJoins = [];
16
+ const indexed = {};
17
+ let firstIteration = true;
18
+ const entity = parsed.entity;
19
+ const joinEntity = parsed.joinEntity;
20
+ const joinClauses = parsed.joinClauses;
21
+ if (!dataSets[entity].length) {
22
+ // Nothing indexed entity's own rows yet (no WHERE condition narrowed them down ahead of this -
23
+ // that only happens via getConditionIndexedList, called just before this). The loop below can't
24
+ // pre-resolve anything against zero rows, so leave parsed.joinClauses exactly as parsed: the
25
+ // later, unconditional joinEntity() call (once this command's own read actually runs) still
26
+ // needs the real clauses to do the join itself. Previously this fell through to the loop,
27
+ // which never ran, leaving reducedJoins (and so parsed.joinClauses) empty regardless of what
28
+ // was actually parsed - silently discarding every join clause whenever the query had no WHERE.
29
+ return parsed;
30
+ }
31
+ if (!joinClauses.length) {
32
+ // A WHERE condition DID index entity's own rows above, but this query has no join at all -
33
+ // joinEntity is undefined. The loop below writes dataSets[entity][anEntity][joinEntity]
34
+ // unconditionally; left unguarded, that assigns a literal "undefined" key (object[undefined]
35
+ // coerces to the string "undefined") onto every row, since there's no join to actually attach.
36
+ return parsed;
37
+ }
38
+ for (const anEntity in dataSets[entity]) {
39
+ const currentEntity = dataSets[entity][anEntity];
40
+ // Loop over each of the main entities
41
+ const filterJoins = {};
42
+ filterJoins[entity] = [_siFunciona.default.cloneObject(currentEntity)];
43
+ for (const joinClause of joinClauses) {
44
+ let indexedClone = _siFunciona.default.cloneObject(indexed);
45
+ const {
46
+ entity: entityA,
47
+ property: propertyA
48
+ } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyA);
49
+ const {
50
+ entity: entityB,
51
+ property: propertyB
52
+ } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyB);
53
+ // Get the record for the entities A and B, store on the recordData
54
+ if (!Object.prototype.hasOwnProperty.call(recordData, entityA)) {
55
+ recordData[entityA] = await (0, _retrieveRecord.retrieveRecord)(entityA);
56
+ }
57
+ if (!Object.prototype.hasOwnProperty.call(recordData, entityB)) {
58
+ recordData[entityB] = await (0, _retrieveRecord.retrieveRecord)(entityB);
59
+ }
60
+ indexedClone = (0, _restrictIndexedList.restrictIndexedList)(joinClause, filterJoins, indexedClone);
61
+ const retrieveMatchedFiles = (0, _matchIndexedJoins.matchIndexedJoins)(entity, indexedClone, dataSets);
62
+ // Check if there are matching keys for the join condition
63
+ const matchAResult = await (0, _getMatchingIndexes.getMatchingIndexes)(entityA, propertyA, recordData, joinClause, filterJoins, indexed);
64
+ const matchBResult = await (0, _getMatchingIndexes.getMatchingIndexes)(entityB, propertyB, recordData, joinClause, filterJoins, indexed, retrieveMatchedFiles);
65
+ const isIndexed = matchAResult || matchBResult;
66
+ if (!isIndexed && firstIteration) {
67
+ reducedJoins.push(joinClause);
68
+ firstIteration = false;
69
+ }
70
+ }
71
+ dataSets[entity][anEntity][joinEntity] = filterJoins[joinEntity];
72
+ }
73
+ parsed.joinClauses = reducedJoins;
74
+ return parsed;
75
+ };
76
76
  exports.getJoinIndexedList = getJoinIndexedList;
@@ -1,28 +1,28 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getMatchingIndexes = void 0;
7
- require("core-js/modules/es.array.includes.js");
8
- var _retrieveIndexes = require("./retrieveIndexes");
9
- const getMatchingIndexes = async (entity, property, recordData, clause, dataSet, indexed, cb = null) => {
10
- let isIndexed = false;
11
- for (const key of recordData[entity].keys) {
12
- if (key.fields.includes(property)) {
13
- dataSet[entity] = [];
14
- if (!Object.prototype.hasOwnProperty.call(indexed, entity)) {
15
- indexed[entity] = {};
16
- }
17
- if (!Object.prototype.hasOwnProperty.call(indexed[entity], property)) {
18
- indexed[entity][property] = (await (0, _retrieveIndexes.retrieveIndexes)(entity, [property], recordData))[property];
19
- }
20
- if (typeof cb === 'function') {
21
- await cb(entity, property, recordData, clause, dataSet, indexed);
22
- }
23
- isIndexed = true;
24
- }
25
- }
26
- return isIndexed;
27
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getMatchingIndexes = void 0;
7
+ require("core-js/modules/es.array.includes.js");
8
+ var _retrieveIndexes = require("./retrieveIndexes");
9
+ const getMatchingIndexes = async (entity, property, recordData, clause, dataSet, indexed, cb = null) => {
10
+ let isIndexed = false;
11
+ for (const key of recordData[entity].keys) {
12
+ if (key.fields.includes(property)) {
13
+ dataSet[entity] = [];
14
+ if (!Object.prototype.hasOwnProperty.call(indexed, entity)) {
15
+ indexed[entity] = {};
16
+ }
17
+ if (!Object.prototype.hasOwnProperty.call(indexed[entity], property)) {
18
+ indexed[entity][property] = (await (0, _retrieveIndexes.retrieveIndexes)(entity, [property], recordData))[property];
19
+ }
20
+ if (typeof cb === 'function') {
21
+ await cb(entity, property, recordData, clause, dataSet, indexed);
22
+ }
23
+ isIndexed = true;
24
+ }
25
+ }
26
+ return isIndexed;
27
+ };
28
28
  exports.getMatchingIndexes = getMatchingIndexes;
@@ -1,61 +1,61 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.matchIndexedJoins = void 0;
7
- require("core-js/modules/esnext.iterator.constructor.js");
8
- require("core-js/modules/esnext.iterator.reduce.js");
9
- var _siFunciona = _interopRequireDefault(require("si-funciona"));
10
- var _where = require("../queries/where");
11
- var _retrieveFile = require("./retrieveFile");
12
- var _splitEntityProperty = require("./parsers/splitEntityProperty");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- const matchIndexedJoins = (entity, indexedClone, dataSets) => async (focusEntity, property, recordData, joinClause, filterJoins, indexed) => {
15
- const {
16
- entity: entityA,
17
- property: propertyA
18
- } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyA);
19
- const {
20
- entity: entityB,
21
- property: propertyB
22
- } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyB);
23
- const properties = [{
24
- entityFirst: entityA,
25
- propertyFirst: propertyA,
26
- entitySecond: entityB,
27
- propertySecond: propertyB
28
- }, {
29
- entityFirst: entityB,
30
- propertyFirst: propertyB,
31
- entitySecond: entityA,
32
- propertySecond: propertyA
33
- }];
34
- for (const checkProp of properties) {
35
- if (!Object.prototype.hasOwnProperty.call(indexedClone, checkProp.entitySecond)) {
36
- indexedClone[checkProp.entitySecond] = _siFunciona.default.cloneObject(indexed[checkProp.entitySecond]);
37
- }
38
- const matchedRecords = indexedClone[checkProp.entitySecond][checkProp.propertySecond].reduce((dataA, dataB) => _siFunciona.default.mergeArrays(dataA, (0, _where.where)(indexedClone[checkProp.entityFirst][checkProp.propertyFirst], {
39
- property: 'value',
40
- comparator: joinClause.comparator,
41
- value: dataB.value
42
- })), []);
43
- const skipPush = checkProp.entityFirst === entity;
44
- if (!Object.prototype.hasOwnProperty.call(dataSets, checkProp.entityFirst)) {
45
- dataSets[checkProp.entityFirst] = [];
46
- }
47
- for (const matchedRecord of matchedRecords) {
48
- for (const file of matchedRecord.record) {
49
- let entityRecord = file;
50
- if (typeof file === 'string') {
51
- entityRecord = await (0, _retrieveFile.retrieveFile)(`${checkProp.entityFirst}/${file}`);
52
- }
53
- if (!skipPush) {
54
- dataSets[checkProp.entityFirst].push(entityRecord);
55
- }
56
- filterJoins[checkProp.entityFirst].push(entityRecord);
57
- }
58
- }
59
- }
60
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.matchIndexedJoins = void 0;
7
+ require("core-js/modules/esnext.iterator.constructor.js");
8
+ require("core-js/modules/esnext.iterator.reduce.js");
9
+ var _siFunciona = _interopRequireDefault(require("si-funciona"));
10
+ var _where = require("../queries/where");
11
+ var _retrieveFile = require("./retrieveFile");
12
+ var _splitEntityProperty = require("./parsers/splitEntityProperty");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ const matchIndexedJoins = (entity, indexedClone, dataSets) => async (focusEntity, property, recordData, joinClause, filterJoins, indexed) => {
15
+ const {
16
+ entity: entityA,
17
+ property: propertyA
18
+ } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyA);
19
+ const {
20
+ entity: entityB,
21
+ property: propertyB
22
+ } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyB);
23
+ const properties = [{
24
+ entityFirst: entityA,
25
+ propertyFirst: propertyA,
26
+ entitySecond: entityB,
27
+ propertySecond: propertyB
28
+ }, {
29
+ entityFirst: entityB,
30
+ propertyFirst: propertyB,
31
+ entitySecond: entityA,
32
+ propertySecond: propertyA
33
+ }];
34
+ for (const checkProp of properties) {
35
+ if (!Object.prototype.hasOwnProperty.call(indexedClone, checkProp.entitySecond)) {
36
+ indexedClone[checkProp.entitySecond] = _siFunciona.default.cloneObject(indexed[checkProp.entitySecond]);
37
+ }
38
+ const matchedRecords = indexedClone[checkProp.entitySecond][checkProp.propertySecond].reduce((dataA, dataB) => _siFunciona.default.mergeArrays(dataA, (0, _where.where)(indexedClone[checkProp.entityFirst][checkProp.propertyFirst], {
39
+ property: 'value',
40
+ comparator: joinClause.comparator,
41
+ value: dataB.value
42
+ })), []);
43
+ const skipPush = checkProp.entityFirst === entity;
44
+ if (!Object.prototype.hasOwnProperty.call(dataSets, checkProp.entityFirst)) {
45
+ dataSets[checkProp.entityFirst] = [];
46
+ }
47
+ for (const matchedRecord of matchedRecords) {
48
+ for (const file of matchedRecord.record) {
49
+ let entityRecord = file;
50
+ if (typeof file === 'string') {
51
+ entityRecord = await (0, _retrieveFile.retrieveFile)(`${checkProp.entityFirst}/${file}`);
52
+ }
53
+ if (!skipPush) {
54
+ dataSets[checkProp.entityFirst].push(entityRecord);
55
+ }
56
+ filterJoins[checkProp.entityFirst].push(entityRecord);
57
+ }
58
+ }
59
+ }
60
+ };
61
61
  exports.matchIndexedJoins = matchIndexedJoins;
@@ -1,44 +1,44 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.mergeJoin = void 0;
7
- require("core-js/modules/esnext.iterator.constructor.js");
8
- require("core-js/modules/esnext.iterator.map.js");
9
- var _readEntity = require("../queries/readEntity");
10
- var _splitEntityProperty = require("./parsers/splitEntityProperty");
11
- var _where = require("../queries/where");
12
- const mergeJoin = async (propertyA = '', propertyB = '', dataSets = {}) => {
13
- const {
14
- entity: entityA,
15
- property: propA
16
- } = (0, _splitEntityProperty.splitEntityProperty)(propertyA);
17
- const {
18
- entity: entityB,
19
- property: propB
20
- } = (0, _splitEntityProperty.splitEntityProperty)(propertyB);
21
- dataSets = await (0, _readEntity.readEntity)(entityA, dataSets);
22
- dataSets = await (0, _readEntity.readEntity)(entityB, dataSets);
23
- dataSets[entityA] = dataSets[entityA].map(dataA => {
24
- const matches = (0, _where.where)(dataSets[entityB], {
25
- property: propB,
26
- comparator: '=',
27
- value: dataA[propA]
28
- });
29
- if (!matches.length) {
30
- return dataA;
31
- }
32
- const mergeMatch = matches[0];
33
- for (const prop in mergeMatch) {
34
- if (prop === propB) {
35
- // Skip the condition property since it is irrelevant
36
- continue;
37
- }
38
- dataA[`${entityB}.${prop}`] = mergeMatch[prop];
39
- }
40
- return dataA;
41
- });
42
- return dataSets;
43
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.mergeJoin = void 0;
7
+ require("core-js/modules/esnext.iterator.constructor.js");
8
+ require("core-js/modules/esnext.iterator.map.js");
9
+ var _readEntity = require("../queries/readEntity");
10
+ var _splitEntityProperty = require("./parsers/splitEntityProperty");
11
+ var _where = require("../queries/where");
12
+ const mergeJoin = async (propertyA = '', propertyB = '', dataSets = {}) => {
13
+ const {
14
+ entity: entityA,
15
+ property: propA
16
+ } = (0, _splitEntityProperty.splitEntityProperty)(propertyA);
17
+ const {
18
+ entity: entityB,
19
+ property: propB
20
+ } = (0, _splitEntityProperty.splitEntityProperty)(propertyB);
21
+ dataSets = await (0, _readEntity.readEntity)(entityA, dataSets);
22
+ dataSets = await (0, _readEntity.readEntity)(entityB, dataSets);
23
+ dataSets[entityA] = dataSets[entityA].map(dataA => {
24
+ const matches = (0, _where.where)(dataSets[entityB], {
25
+ property: propB,
26
+ comparator: '=',
27
+ value: dataA[propA]
28
+ });
29
+ if (!matches.length) {
30
+ return dataA;
31
+ }
32
+ const mergeMatch = matches[0];
33
+ for (const prop in mergeMatch) {
34
+ if (prop === propB) {
35
+ // Skip the condition property since it is irrelevant
36
+ continue;
37
+ }
38
+ dataA[`${entityB}.${prop}`] = mergeMatch[prop];
39
+ }
40
+ return dataA;
41
+ });
42
+ return dataSets;
43
+ };
44
44
  exports.mergeJoin = mergeJoin;
@@ -1,25 +1,25 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findCommand = void 0;
7
- var _removeFromQuery = require("./removeFromQuery");
8
- const commandMatch = /^(delete|insert|read|update)\s+([a-z0-9_-]+)[\w\n]*/i;
9
- /**
10
- * Extract command clauses from the query.
11
- * @param parsed
12
- * @param query
13
- */
14
- const findCommand = (parsed, query) => {
15
- const commandFound = query.match(commandMatch);
16
- parsed['command'] = undefined;
17
- parsed['entity'] = undefined;
18
- if (commandFound) {
19
- parsed['command'] = commandFound[1];
20
- parsed['entity'] = commandFound[2];
21
- return (0, _removeFromQuery.removeFromQuery)(commandFound[0], query);
22
- }
23
- return query;
24
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findCommand = void 0;
7
+ var _removeFromQuery = require("./removeFromQuery");
8
+ const commandMatch = /^(delete|insert|read|update)\s+([a-z0-9_-]+)[\w\n]*/i;
9
+ /**
10
+ * Extract command clauses from the query.
11
+ * @param parsed
12
+ * @param query
13
+ */
14
+ const findCommand = (parsed, query) => {
15
+ const commandFound = query.match(commandMatch);
16
+ parsed['command'] = undefined;
17
+ parsed['entity'] = undefined;
18
+ if (commandFound) {
19
+ parsed['command'] = commandFound[1];
20
+ parsed['entity'] = commandFound[2];
21
+ return (0, _removeFromQuery.removeFromQuery)(commandFound[0], query);
22
+ }
23
+ return query;
24
+ };
25
25
  exports.findCommand = findCommand;