json-fs-query 1.0.5 → 1.1.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.
Files changed (94) hide show
  1. package/browser/jsonFsQuery.js +520 -363
  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 +5 -1
  12. package/dist/data/introspect/policies/foreignKeyExists.min.js +1 -1
  13. package/dist/data/introspect/policies/hasDependents.js +3 -1
  14. package/dist/data/introspect/policies/hasDependents.min.js +1 -1
  15. package/dist/data/introspect/policies/keyGenerate.js +16 -16
  16. package/dist/data/introspect/policies/keyUnique.js +5 -1
  17. package/dist/data/introspect/policies/keyUnique.min.js +1 -1
  18. package/dist/data/introspect/policies/typeCheck.js +56 -56
  19. package/dist/data/introspect/policies/typeEnum.js +13 -13
  20. package/dist/data/introspect/policies/useDefault.js +12 -12
  21. package/dist/data/queries/deleteEntity.js +2 -1
  22. package/dist/data/queries/deleteEntity.min.js +1 -1
  23. package/dist/data/queries/groupBy.js +21 -21
  24. package/dist/data/queries/insertEntity.js +2 -1
  25. package/dist/data/queries/insertEntity.min.js +1 -1
  26. package/dist/data/queries/joinEntity.js +31 -31
  27. package/dist/data/queries/limitOffset.js +20 -20
  28. package/dist/data/queries/mergeJoins.js +18 -18
  29. package/dist/data/queries/parser.js +29 -29
  30. package/dist/data/queries/query.js +17 -17
  31. package/dist/data/queries/readEntity.js +13 -13
  32. package/dist/data/queries/selectFields.js +35 -35
  33. package/dist/data/queries/sortBy.js +3 -0
  34. package/dist/data/queries/updateEntity.js +14 -10
  35. package/dist/data/queries/updateEntity.min.js +1 -1
  36. package/dist/data/queries/where.d.ts +7 -6
  37. package/dist/data/queries/where.js +18 -6
  38. package/dist/data/queries/where.min.js +1 -1
  39. package/dist/data/utilities/compareAs.d.ts +20 -0
  40. package/dist/data/utilities/compareAs.js +58 -0
  41. package/dist/data/utilities/compareAs.min.js +1 -0
  42. package/dist/data/utilities/computeKeyValue.js +25 -25
  43. package/dist/data/utilities/config.js +44 -44
  44. package/dist/data/utilities/deregisterRecord.js +33 -33
  45. package/dist/data/utilities/fieldType.d.ts +16 -0
  46. package/dist/data/utilities/fieldType.js +23 -0
  47. package/dist/data/utilities/fieldType.min.js +1 -0
  48. package/dist/data/utilities/getConditionIndexedList.js +2 -1
  49. package/dist/data/utilities/getConditionIndexedList.min.js +1 -1
  50. package/dist/data/utilities/getJoinIndexedList.js +75 -75
  51. package/dist/data/utilities/getMatchingIndexes.js +27 -27
  52. package/dist/data/utilities/matchIndexedJoins.js +3 -1
  53. package/dist/data/utilities/matchIndexedJoins.min.js +1 -1
  54. package/dist/data/utilities/mergeJoin.js +5 -1
  55. package/dist/data/utilities/mergeJoin.min.js +1 -1
  56. package/dist/data/utilities/parsers/findCommand.js +24 -24
  57. package/dist/data/utilities/parsers/findConditions.d.ts +15 -14
  58. package/dist/data/utilities/parsers/findConditions.js +27 -27
  59. package/dist/data/utilities/parsers/findGroupBy.js +21 -21
  60. package/dist/data/utilities/parsers/findInsertValues.js +33 -33
  61. package/dist/data/utilities/parsers/findJoinClauses.js +26 -26
  62. package/dist/data/utilities/parsers/findJoinEntity.js +21 -21
  63. package/dist/data/utilities/parsers/findLimit.js +21 -21
  64. package/dist/data/utilities/parsers/findMergeJoins.js +25 -25
  65. package/dist/data/utilities/parsers/findOffset.js +21 -21
  66. package/dist/data/utilities/parsers/findSelects.js +29 -29
  67. package/dist/data/utilities/parsers/findSortClauses.js +29 -29
  68. package/dist/data/utilities/parsers/findUpdateValues.js +33 -33
  69. package/dist/data/utilities/parsers/isEntityProperty.js +7 -7
  70. package/dist/data/utilities/parsers/parseLiteralValue.js +33 -33
  71. package/dist/data/utilities/parsers/parseQuery.js +50 -50
  72. package/dist/data/utilities/parsers/removeFromQuery.js +7 -7
  73. package/dist/data/utilities/parsers/splitEntityProperty.js +22 -22
  74. package/dist/data/utilities/parsers/splitQueries.js +10 -10
  75. package/dist/data/utilities/reconcileJoin.js +25 -25
  76. package/dist/data/utilities/reconcileJoins.js +25 -25
  77. package/dist/data/utilities/registerRecord.js +66 -66
  78. package/dist/data/utilities/removeFromIndex.d.ts +14 -13
  79. package/dist/data/utilities/removeFromIndex.js +4 -2
  80. package/dist/data/utilities/removeFromIndex.min.js +1 -1
  81. package/dist/data/utilities/restrictIndexedList.js +44 -44
  82. package/dist/data/utilities/retrieveFile.js +27 -27
  83. package/dist/data/utilities/retrieveIndexes.js +23 -23
  84. package/dist/data/utilities/retrieveRecord.js +8 -8
  85. package/dist/data/utilities/retrieveRecords.js +20 -20
  86. package/dist/data/utilities/runQuery.js +26 -0
  87. package/dist/data/utilities/runQuery.min.js +1 -1
  88. package/dist/data/utilities/updateIndex.d.ts +17 -16
  89. package/dist/data/utilities/updateIndex.js +4 -2
  90. package/dist/data/utilities/updateIndex.min.js +1 -1
  91. package/dist/data/utilities/useJoinClause.js +8 -2
  92. package/dist/data/utilities/useJoinClause.min.js +1 -1
  93. package/dist/index.js +41 -41
  94. package/package.json +14 -5
@@ -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;
@@ -10,6 +10,7 @@ var _siFunciona = _interopRequireDefault(require("si-funciona"));
10
10
  var _where = require("../queries/where");
11
11
  var _retrieveFile = require("./retrieveFile");
12
12
  var _splitEntityProperty = require("./parsers/splitEntityProperty");
13
+ var _fieldType = require("./fieldType");
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
15
  const matchIndexedJoins = (entity, indexedClone, dataSets) => async (focusEntity, property, recordData, joinClause, filterJoins, indexed) => {
15
16
  const {
@@ -38,7 +39,8 @@ const matchIndexedJoins = (entity, indexedClone, dataSets) => async (focusEntity
38
39
  const matchedRecords = indexedClone[checkProp.entitySecond][checkProp.propertySecond].reduce((dataA, dataB) => _siFunciona.default.mergeArrays(dataA, (0, _where.where)(indexedClone[checkProp.entityFirst][checkProp.propertyFirst], {
39
40
  property: 'value',
40
41
  comparator: joinClause.comparator,
41
- value: dataB.value
42
+ value: dataB.value,
43
+ type: (0, _fieldType.fieldType)(recordData[checkProp.entityFirst], checkProp.propertyFirst)
42
44
  })), []);
43
45
  const skipPush = checkProp.entityFirst === entity;
44
46
  if (!Object.prototype.hasOwnProperty.call(dataSets, checkProp.entityFirst)) {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.matchIndexedJoins=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var _siFunciona=_interopRequireDefault(require("si-funciona")),_where=require("../queries/where"),_retrieveFile=require("./retrieveFile"),_splitEntityProperty=require("./parsers/splitEntityProperty");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const matchIndexedJoins=(e,t,r)=>async(i,o,n,s,p,y)=>{const{entity:c,property:u}=(0,_splitEntityProperty.splitEntityProperty)(s.propertyA),{entity:a,property:d}=(0,_splitEntityProperty.splitEntityProperty)(s.propertyB),l=[{entityFirst:c,propertyFirst:u,entitySecond:a,propertySecond:d},{entityFirst:a,propertyFirst:d,entitySecond:c,propertySecond:u}];for(const i of l){Object.prototype.hasOwnProperty.call(t,i.entitySecond)||(t[i.entitySecond]=_siFunciona.default.cloneObject(y[i.entitySecond]));const o=t[i.entitySecond][i.propertySecond].reduce(((e,r)=>_siFunciona.default.mergeArrays(e,(0,_where.where)(t[i.entityFirst][i.propertyFirst],{property:"value",comparator:s.comparator,value:r.value}))),[]),n=i.entityFirst===e;Object.prototype.hasOwnProperty.call(r,i.entityFirst)||(r[i.entityFirst]=[]);for(const e of o)for(const t of e.record){let e=t;"string"==typeof t&&(e=await(0,_retrieveFile.retrieveFile)(`${i.entityFirst}/${t}`)),n||r[i.entityFirst].push(e),p[i.entityFirst].push(e)}}};exports.matchIndexedJoins=matchIndexedJoins;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.matchIndexedJoins=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var _siFunciona=_interopRequireDefault(require("si-funciona")),_where=require("../queries/where"),_retrieveFile=require("./retrieveFile"),_splitEntityProperty=require("./parsers/splitEntityProperty"),_fieldType=require("./fieldType");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const matchIndexedJoins=(e,t,r)=>async(i,o,n,s,p,y)=>{const{entity:c,property:u}=(0,_splitEntityProperty.splitEntityProperty)(s.propertyA),{entity:a,property:d}=(0,_splitEntityProperty.splitEntityProperty)(s.propertyB),l=[{entityFirst:c,propertyFirst:u,entitySecond:a,propertySecond:d},{entityFirst:a,propertyFirst:d,entitySecond:c,propertySecond:u}];for(const i of l){Object.prototype.hasOwnProperty.call(t,i.entitySecond)||(t[i.entitySecond]=_siFunciona.default.cloneObject(y[i.entitySecond]));const o=t[i.entitySecond][i.propertySecond].reduce(((e,r)=>_siFunciona.default.mergeArrays(e,(0,_where.where)(t[i.entityFirst][i.propertyFirst],{property:"value",comparator:s.comparator,value:r.value,type:(0,_fieldType.fieldType)(n[i.entityFirst],i.propertyFirst)}))),[]),c=i.entityFirst===e;Object.prototype.hasOwnProperty.call(r,i.entityFirst)||(r[i.entityFirst]=[]);for(const e of o)for(const t of e.record){let e=t;"string"==typeof t&&(e=await(0,_retrieveFile.retrieveFile)(`${i.entityFirst}/${t}`)),c||r[i.entityFirst].push(e),p[i.entityFirst].push(e)}}};exports.matchIndexedJoins=matchIndexedJoins;
@@ -9,6 +9,8 @@ require("core-js/modules/esnext.iterator.map.js");
9
9
  var _readEntity = require("../queries/readEntity");
10
10
  var _splitEntityProperty = require("./parsers/splitEntityProperty");
11
11
  var _where = require("../queries/where");
12
+ var _retrieveRecord = require("./retrieveRecord");
13
+ var _fieldType = require("./fieldType");
12
14
  const mergeJoin = async (propertyA = '', propertyB = '', dataSets = {}) => {
13
15
  const {
14
16
  entity: entityA,
@@ -20,11 +22,13 @@ const mergeJoin = async (propertyA = '', propertyB = '', dataSets = {}) => {
20
22
  } = (0, _splitEntityProperty.splitEntityProperty)(propertyB);
21
23
  dataSets = await (0, _readEntity.readEntity)(entityA, dataSets);
22
24
  dataSets = await (0, _readEntity.readEntity)(entityB, dataSets);
25
+ const typeB = (0, _fieldType.fieldType)(await (0, _retrieveRecord.retrieveRecord)(entityB), propB);
23
26
  dataSets[entityA] = dataSets[entityA].map(dataA => {
24
27
  const matches = (0, _where.where)(dataSets[entityB], {
25
28
  property: propB,
26
29
  comparator: '=',
27
- value: dataA[propA]
30
+ value: dataA[propA],
31
+ type: typeB
28
32
  });
29
33
  if (!matches.length) {
30
34
  return dataA;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mergeJoin=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.map.js");var _readEntity=require("../queries/readEntity"),_splitEntityProperty=require("./parsers/splitEntityProperty"),_where=require("../queries/where");const mergeJoin=async(e="",r="",t={})=>{const{entity:i,property:o}=(0,_splitEntityProperty.splitEntityProperty)(e),{entity:n,property:s}=(0,_splitEntityProperty.splitEntityProperty)(r);return t=await(0,_readEntity.readEntity)(i,t),(t=await(0,_readEntity.readEntity)(n,t))[i]=t[i].map((e=>{const r=(0,_where.where)(t[n],{property:s,comparator:"=",value:e[o]});if(!r.length)return e;const i=r[0];for(const r in i)r!==s&&(e[`${n}.${r}`]=i[r]);return e})),t};exports.mergeJoin=mergeJoin;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mergeJoin=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.map.js");var _readEntity=require("../queries/readEntity"),_splitEntityProperty=require("./parsers/splitEntityProperty"),_where=require("../queries/where"),_retrieveRecord=require("./retrieveRecord"),_fieldType=require("./fieldType");const mergeJoin=async(e="",r="",t={})=>{const{entity:i,property:o}=(0,_splitEntityProperty.splitEntityProperty)(e),{entity:n,property:s}=(0,_splitEntityProperty.splitEntityProperty)(r);t=await(0,_readEntity.readEntity)(i,t),t=await(0,_readEntity.readEntity)(n,t);const p=(0,_fieldType.fieldType)(await(0,_retrieveRecord.retrieveRecord)(n),s);return t[i]=t[i].map((e=>{const r=(0,_where.where)(t[n],{property:s,comparator:"=",value:e[o],type:p});if(!r.length)return e;const i=r[0];for(const r in i)r!==s&&(e[`${n}.${r}`]=i[r]);return e})),t};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;
@@ -1,15 +1,16 @@
1
- import { LiteralValue } from './parseLiteralValue';
2
- import { ParsedQuery } from './parseQuery';
3
- export type ConditionValue = LiteralValue;
4
- export type ParsedCondition = {
5
- property: string;
6
- comparator: string;
7
- value: ConditionValue;
8
- };
9
- /**
10
- * Extract condition clauses from the query.
11
- * @param parsed
12
- * @param query
13
- */
14
- export declare const findConditions: (parsed: ParsedQuery, query: string) => string;
1
+ import { LiteralValue } from './parseLiteralValue';
2
+ import { ParsedQuery } from './parseQuery';
3
+ export type ConditionValue = LiteralValue;
4
+ export type ParsedCondition = {
5
+ property: string;
6
+ comparator: string;
7
+ value: ConditionValue;
8
+ type?: string;
9
+ };
10
+ /**
11
+ * Extract condition clauses from the query.
12
+ * @param parsed
13
+ * @param query
14
+ */
15
+ export declare const findConditions: (parsed: ParsedQuery, query: string) => string;
15
16
  //# sourceMappingURL=findConditions.d.ts.map
@@ -1,28 +1,28 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findConditions = void 0;
7
- var _removeFromQuery = require("./removeFromQuery");
8
- var _parseLiteralValue = require("./parseLiteralValue");
9
- const conditionMatch = /(and|or)?\s*(where)\s+([a-z0-9_-]+\.?[a-z0-9_-]*)\s+(=|!=|>|<|>=|<=|in|between|like)\s+(["'](.*)['"]|([0-9]+)|(\[.*])|(null)|(true)|(false))/ig;
10
- /**
11
- * Extract condition clauses from the query.
12
- * @param parsed
13
- * @param query
14
- */
15
- const findConditions = (parsed, query) => {
16
- const conditionsFound = query.matchAll(conditionMatch);
17
- // @ts-ignore
18
- for (const condition of conditionsFound) {
19
- parsed['conditions'].push({
20
- property: condition[3],
21
- comparator: condition[4],
22
- value: (0, _parseLiteralValue.parseLiteralValue)(condition, 6)
23
- });
24
- query = (0, _removeFromQuery.removeFromQuery)(condition[0], query);
25
- }
26
- return query;
27
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findConditions = void 0;
7
+ var _removeFromQuery = require("./removeFromQuery");
8
+ var _parseLiteralValue = require("./parseLiteralValue");
9
+ const conditionMatch = /(and|or)?\s*(where)\s+([a-z0-9_-]+\.?[a-z0-9_-]*)\s+(=|!=|>|<|>=|<=|in|between|like)\s+(["'](.*)['"]|([0-9]+)|(\[.*])|(null)|(true)|(false))/ig;
10
+ /**
11
+ * Extract condition clauses from the query.
12
+ * @param parsed
13
+ * @param query
14
+ */
15
+ const findConditions = (parsed, query) => {
16
+ const conditionsFound = query.matchAll(conditionMatch);
17
+ // @ts-ignore
18
+ for (const condition of conditionsFound) {
19
+ parsed['conditions'].push({
20
+ property: condition[3],
21
+ comparator: condition[4],
22
+ value: (0, _parseLiteralValue.parseLiteralValue)(condition, 6)
23
+ });
24
+ query = (0, _removeFromQuery.removeFromQuery)(condition[0], query);
25
+ }
26
+ return query;
27
+ };
28
28
  exports.findConditions = findConditions;
@@ -1,22 +1,22 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findGroupBy = void 0;
7
- var _removeFromQuery = require("./removeFromQuery");
8
- const groupMatch = /group\s+by\s+(,?[a-z0-9._-]+)+/i;
9
- /**
10
- * Extract the group by clauses from the query.
11
- * @param parsed
12
- * @param query
13
- */
14
- const findGroupBy = (parsed, query) => {
15
- const groupFound = query.match(groupMatch);
16
- if (groupFound) {
17
- parsed['groupBy'] = groupFound ? groupFound[1] : undefined;
18
- return (0, _removeFromQuery.removeFromQuery)(groupFound[0], query);
19
- }
20
- return query;
21
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findGroupBy = void 0;
7
+ var _removeFromQuery = require("./removeFromQuery");
8
+ const groupMatch = /group\s+by\s+(,?[a-z0-9._-]+)+/i;
9
+ /**
10
+ * Extract the group by clauses from the query.
11
+ * @param parsed
12
+ * @param query
13
+ */
14
+ const findGroupBy = (parsed, query) => {
15
+ const groupFound = query.match(groupMatch);
16
+ if (groupFound) {
17
+ parsed['groupBy'] = groupFound ? groupFound[1] : undefined;
18
+ return (0, _removeFromQuery.removeFromQuery)(groupFound[0], query);
19
+ }
20
+ return query;
21
+ };
22
22
  exports.findGroupBy = findGroupBy;
@@ -1,34 +1,34 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findInsertValues = void 0;
7
- var _removeFromQuery = require("./removeFromQuery");
8
- var _parseLiteralValue = require("./parseLiteralValue");
9
- const literal = '(?:["\'][^"\']*[\'"]|[0-9]+|\\[.*?]|null|true|false)';
10
- const valuesClauseMatch = new RegExp(`(values)\\s+([a-z0-9_-]+\\s*=\\s*${literal}(?:\\s*,\\s*[a-z0-9_-]+\\s*=\\s*${literal})*)`, 'i');
11
- const assignmentMatch = /([a-z0-9_-]+)\s*=\s*(["'](.*?)['"]|([0-9]+)|(\[.*?])|(null)|(true)|(false))/ig;
12
- /**
13
- * Extract an insert's "values field = value, field2 = value2" clause from the query, the same way
14
- * findUpdateValues() does for "set". insertEntity() accepts an array of rows for bulk inserts, but
15
- * a query string only describes a single row for now - wrapped in a one-element array to match.
16
- * @param parsed
17
- * @param query
18
- */
19
- const findInsertValues = (parsed, query) => {
20
- const clauseFound = query.match(valuesClauseMatch);
21
- parsed['insertValues'] = [];
22
- if (!clauseFound) {
23
- return query;
24
- }
25
- const row = {};
26
- const assignmentsFound = clauseFound[2].matchAll(assignmentMatch);
27
- // @ts-ignore
28
- for (const assignment of assignmentsFound) {
29
- row[assignment[1]] = (0, _parseLiteralValue.parseLiteralValue)(assignment, 3);
30
- }
31
- parsed['insertValues'] = [row];
32
- return (0, _removeFromQuery.removeFromQuery)(clauseFound[0], query);
33
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findInsertValues = void 0;
7
+ var _removeFromQuery = require("./removeFromQuery");
8
+ var _parseLiteralValue = require("./parseLiteralValue");
9
+ const literal = '(?:["\'][^"\']*[\'"]|[0-9]+|\\[.*?]|null|true|false)';
10
+ const valuesClauseMatch = new RegExp(`(values)\\s+([a-z0-9_-]+\\s*=\\s*${literal}(?:\\s*,\\s*[a-z0-9_-]+\\s*=\\s*${literal})*)`, 'i');
11
+ const assignmentMatch = /([a-z0-9_-]+)\s*=\s*(["'](.*?)['"]|([0-9]+)|(\[.*?])|(null)|(true)|(false))/ig;
12
+ /**
13
+ * Extract an insert's "values field = value, field2 = value2" clause from the query, the same way
14
+ * findUpdateValues() does for "set". insertEntity() accepts an array of rows for bulk inserts, but
15
+ * a query string only describes a single row for now - wrapped in a one-element array to match.
16
+ * @param parsed
17
+ * @param query
18
+ */
19
+ const findInsertValues = (parsed, query) => {
20
+ const clauseFound = query.match(valuesClauseMatch);
21
+ parsed['insertValues'] = [];
22
+ if (!clauseFound) {
23
+ return query;
24
+ }
25
+ const row = {};
26
+ const assignmentsFound = clauseFound[2].matchAll(assignmentMatch);
27
+ // @ts-ignore
28
+ for (const assignment of assignmentsFound) {
29
+ row[assignment[1]] = (0, _parseLiteralValue.parseLiteralValue)(assignment, 3);
30
+ }
31
+ parsed['insertValues'] = [row];
32
+ return (0, _removeFromQuery.removeFromQuery)(clauseFound[0], query);
33
+ };
34
34
  exports.findInsertValues = findInsertValues;
@@ -1,27 +1,27 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findJoinClauses = void 0;
7
- var _removeFromQuery = require("./removeFromQuery");
8
- const joinClauseMatch = /(and)?\s*on\s+([a-z0-9_-]+\.[a-z0-9_-]+)\s+(=|!=|>|<|>=|<=|in|between|like)\s+([a-z0-9_-]+\.[a-z0-9_-]+)/ig;
9
- /**
10
- * Extract condition clauses from the query.
11
- * @param parsed
12
- * @param query
13
- */
14
- const findJoinClauses = (parsed, query) => {
15
- const joinClausesFound = query.matchAll(joinClauseMatch);
16
- // @ts-ignore
17
- for (const joinClause of joinClausesFound) {
18
- parsed['joinClauses'].push({
19
- propertyA: joinClause[2],
20
- comparator: joinClause[3],
21
- propertyB: joinClause[4]
22
- });
23
- query = (0, _removeFromQuery.removeFromQuery)(joinClause[0], query);
24
- }
25
- return query;
26
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findJoinClauses = void 0;
7
+ var _removeFromQuery = require("./removeFromQuery");
8
+ const joinClauseMatch = /(and)?\s*on\s+([a-z0-9_-]+\.[a-z0-9_-]+)\s+(=|!=|>|<|>=|<=|in|between|like)\s+([a-z0-9_-]+\.[a-z0-9_-]+)/ig;
9
+ /**
10
+ * Extract condition clauses from the query.
11
+ * @param parsed
12
+ * @param query
13
+ */
14
+ const findJoinClauses = (parsed, query) => {
15
+ const joinClausesFound = query.matchAll(joinClauseMatch);
16
+ // @ts-ignore
17
+ for (const joinClause of joinClausesFound) {
18
+ parsed['joinClauses'].push({
19
+ propertyA: joinClause[2],
20
+ comparator: joinClause[3],
21
+ propertyB: joinClause[4]
22
+ });
23
+ query = (0, _removeFromQuery.removeFromQuery)(joinClause[0], query);
24
+ }
25
+ return query;
26
+ };
27
27
  exports.findJoinClauses = findJoinClauses;
@@ -1,22 +1,22 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findJoinEntity = void 0;
7
- var _removeFromQuery = require("./removeFromQuery");
8
- const joinEntityMatch = /\.([a-z0-9_-]+)/i;
9
- /**
10
- * Extract the main join entity from the query.
11
- * @param parsed
12
- * @param query
13
- */
14
- const findJoinEntity = (parsed, query) => {
15
- const joinEntityFound = query.match(joinEntityMatch);
16
- if (joinEntityFound) {
17
- parsed['joinEntity'] = joinEntityFound ? joinEntityFound[1] : undefined;
18
- return (0, _removeFromQuery.removeFromQuery)(joinEntityFound[0], query);
19
- }
20
- return query;
21
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findJoinEntity = void 0;
7
+ var _removeFromQuery = require("./removeFromQuery");
8
+ const joinEntityMatch = /\.([a-z0-9_-]+)/i;
9
+ /**
10
+ * Extract the main join entity from the query.
11
+ * @param parsed
12
+ * @param query
13
+ */
14
+ const findJoinEntity = (parsed, query) => {
15
+ const joinEntityFound = query.match(joinEntityMatch);
16
+ if (joinEntityFound) {
17
+ parsed['joinEntity'] = joinEntityFound ? joinEntityFound[1] : undefined;
18
+ return (0, _removeFromQuery.removeFromQuery)(joinEntityFound[0], query);
19
+ }
20
+ return query;
21
+ };
22
22
  exports.findJoinEntity = findJoinEntity;