json-fs-query 1.0.4 → 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 (139) hide show
  1. package/browser/jsonFsQuery.js +10158 -27750
  2. package/browser/jsonFsQuery.min.js +1 -1
  3. package/dist/data/introspect/create.d.ts +10 -10
  4. package/dist/data/introspect/create.js +47 -47
  5. package/dist/data/introspect/definitions/field.d.ts +27 -27
  6. package/dist/data/introspect/definitions/field.js +36 -36
  7. package/dist/data/introspect/definitions/key.d.ts +25 -25
  8. package/dist/data/introspect/definitions/key.js +53 -53
  9. package/dist/data/introspect/definitions/keyReference.d.ts +17 -17
  10. package/dist/data/introspect/definitions/keyReference.js +20 -20
  11. package/dist/data/introspect/definitions/record.d.ts +25 -25
  12. package/dist/data/introspect/definitions/record.js +32 -32
  13. package/dist/data/introspect/describe.js +15 -15
  14. package/dist/data/introspect/drop.js +37 -37
  15. package/dist/data/introspect/index.d.ts +7 -7
  16. package/dist/data/introspect/index.js +30 -30
  17. package/dist/data/introspect/policies/foreignKeyExists.d.ts +8 -8
  18. package/dist/data/introspect/policies/foreignKeyExists.js +25 -25
  19. package/dist/data/introspect/policies/hasDependents.d.ts +12 -12
  20. package/dist/data/introspect/policies/hasDependents.js +52 -52
  21. package/dist/data/introspect/policies/keyGenerate.d.ts +1 -1
  22. package/dist/data/introspect/policies/keyGenerate.js +17 -17
  23. package/dist/data/introspect/policies/keyUnique.d.ts +9 -9
  24. package/dist/data/introspect/policies/keyUnique.js +31 -31
  25. package/dist/data/introspect/policies/typeCheck.d.ts +11 -11
  26. package/dist/data/introspect/policies/typeCheck.js +57 -57
  27. package/dist/data/introspect/policies/typeEnum.d.ts +1 -1
  28. package/dist/data/introspect/policies/typeEnum.js +9 -9
  29. package/dist/data/introspect/policies/useDefault.d.ts +1 -1
  30. package/dist/data/introspect/policies/useDefault.js +8 -8
  31. package/dist/data/queries/deleteEntity.d.ts +1 -1
  32. package/dist/data/queries/deleteEntity.js +100 -100
  33. package/dist/data/queries/groupBy.d.ts +1 -1
  34. package/dist/data/queries/groupBy.js +22 -22
  35. package/dist/data/queries/insertEntity.d.ts +1 -1
  36. package/dist/data/queries/insertEntity.js +117 -117
  37. package/dist/data/queries/joinEntity.d.ts +1 -1
  38. package/dist/data/queries/joinEntity.js +32 -32
  39. package/dist/data/queries/joinEntity.min.js +1 -1
  40. package/dist/data/queries/limitOffset.d.ts +7 -7
  41. package/dist/data/queries/limitOffset.js +21 -21
  42. package/dist/data/queries/mergeJoins.d.ts +1 -1
  43. package/dist/data/queries/mergeJoins.js +19 -19
  44. package/dist/data/queries/mergeJoins.min.js +1 -1
  45. package/dist/data/queries/parser.d.ts +1 -1
  46. package/dist/data/queries/parser.js +19 -19
  47. package/dist/data/queries/parser.min.js +1 -1
  48. package/dist/data/queries/query.d.ts +1 -1
  49. package/dist/data/queries/query.js +18 -18
  50. package/dist/data/queries/query.min.js +1 -1
  51. package/dist/data/queries/readEntity.js +14 -14
  52. package/dist/data/queries/selectFields.d.ts +9 -9
  53. package/dist/data/queries/selectFields.js +36 -36
  54. package/dist/data/queries/sortBy.d.ts +1 -1
  55. package/dist/data/queries/sortBy.js +15 -15
  56. package/dist/data/queries/sortBy.min.js +1 -1
  57. package/dist/data/queries/updateEntity.d.ts +1 -1
  58. package/dist/data/queries/updateEntity.js +190 -190
  59. package/dist/data/queries/where.d.ts +6 -6
  60. package/dist/data/queries/where.js +56 -56
  61. package/dist/data/utilities/computeKeyValue.d.ts +12 -12
  62. package/dist/data/utilities/computeKeyValue.js +26 -26
  63. package/dist/data/utilities/config.d.ts +27 -27
  64. package/dist/data/utilities/config.js +45 -45
  65. package/dist/data/utilities/deregisterRecord.d.ts +7 -7
  66. package/dist/data/utilities/deregisterRecord.js +34 -34
  67. package/dist/data/utilities/getConditionIndexedList.js +47 -47
  68. package/dist/data/utilities/getConditionIndexedList.min.js +1 -1
  69. package/dist/data/utilities/getJoinIndexedList.js +76 -76
  70. package/dist/data/utilities/getJoinIndexedList.min.js +1 -1
  71. package/dist/data/utilities/getMatchingIndexes.js +28 -28
  72. package/dist/data/utilities/getMatchingIndexes.min.js +1 -1
  73. package/dist/data/utilities/matchIndexedJoins.js +61 -61
  74. package/dist/data/utilities/matchIndexedJoins.min.js +1 -1
  75. package/dist/data/utilities/mergeJoin.js +44 -44
  76. package/dist/data/utilities/mergeJoin.min.js +1 -1
  77. package/dist/data/utilities/parsers/findCommand.d.ts +9 -9
  78. package/dist/data/utilities/parsers/findCommand.js +25 -25
  79. package/dist/data/utilities/parsers/findConditions.d.ts +14 -14
  80. package/dist/data/utilities/parsers/findConditions.js +28 -28
  81. package/dist/data/utilities/parsers/findConditions.min.js +1 -1
  82. package/dist/data/utilities/parsers/findGroupBy.d.ts +8 -8
  83. package/dist/data/utilities/parsers/findGroupBy.js +22 -22
  84. package/dist/data/utilities/parsers/findInsertValues.d.ts +12 -12
  85. package/dist/data/utilities/parsers/findInsertValues.js +34 -34
  86. package/dist/data/utilities/parsers/findJoinClauses.d.ts +12 -12
  87. package/dist/data/utilities/parsers/findJoinClauses.js +27 -27
  88. package/dist/data/utilities/parsers/findJoinClauses.min.js +1 -1
  89. package/dist/data/utilities/parsers/findJoinEntity.d.ts +8 -8
  90. package/dist/data/utilities/parsers/findJoinEntity.js +22 -22
  91. package/dist/data/utilities/parsers/findLimit.d.ts +8 -8
  92. package/dist/data/utilities/parsers/findLimit.js +22 -22
  93. package/dist/data/utilities/parsers/findMergeJoins.d.ts +11 -11
  94. package/dist/data/utilities/parsers/findMergeJoins.js +26 -26
  95. package/dist/data/utilities/parsers/findMergeJoins.min.js +1 -1
  96. package/dist/data/utilities/parsers/findOffset.d.ts +8 -8
  97. package/dist/data/utilities/parsers/findOffset.js +22 -22
  98. package/dist/data/utilities/parsers/findSelects.d.ts +11 -11
  99. package/dist/data/utilities/parsers/findSelects.js +30 -30
  100. package/dist/data/utilities/parsers/findSelects.min.js +1 -1
  101. package/dist/data/utilities/parsers/findSortClauses.d.ts +11 -11
  102. package/dist/data/utilities/parsers/findSortClauses.js +30 -30
  103. package/dist/data/utilities/parsers/findSortClauses.min.js +1 -1
  104. package/dist/data/utilities/parsers/findUpdateValues.d.ts +14 -14
  105. package/dist/data/utilities/parsers/findUpdateValues.js +34 -34
  106. package/dist/data/utilities/parsers/isEntityProperty.js +6 -6
  107. package/dist/data/utilities/parsers/parseLiteralValue.d.ts +11 -11
  108. package/dist/data/utilities/parsers/parseLiteralValue.js +34 -34
  109. package/dist/data/utilities/parsers/parseQuery.d.ts +32 -32
  110. package/dist/data/utilities/parsers/parseQuery.js +51 -51
  111. package/dist/data/utilities/parsers/parseQuery.min.js +1 -1
  112. package/dist/data/utilities/parsers/removeFromQuery.js +6 -6
  113. package/dist/data/utilities/parsers/splitEntityProperty.js +13 -13
  114. package/dist/data/utilities/parsers/splitQueries.js +9 -9
  115. package/dist/data/utilities/reconcileJoin.js +26 -26
  116. package/dist/data/utilities/reconcileJoins.js +26 -26
  117. package/dist/data/utilities/reconcileJoins.min.js +1 -1
  118. package/dist/data/utilities/registerRecord.d.ts +7 -7
  119. package/dist/data/utilities/registerRecord.js +67 -67
  120. package/dist/data/utilities/removeFromIndex.d.ts +13 -13
  121. package/dist/data/utilities/removeFromIndex.js +44 -46
  122. package/dist/data/utilities/restrictIndexedList.js +45 -45
  123. package/dist/data/utilities/retrieveFile.js +28 -28
  124. package/dist/data/utilities/retrieveFile.min.js +1 -1
  125. package/dist/data/utilities/retrieveIndexes.d.ts +1 -1
  126. package/dist/data/utilities/retrieveIndexes.js +24 -24
  127. package/dist/data/utilities/retrieveIndexes.min.js +1 -1
  128. package/dist/data/utilities/retrieveRecord.js +9 -9
  129. package/dist/data/utilities/retrieveRecords.js +21 -21
  130. package/dist/data/utilities/retrieveRecords.min.js +1 -1
  131. package/dist/data/utilities/runQuery.d.ts +1 -1
  132. package/dist/data/utilities/runQuery.js +87 -87
  133. package/dist/data/utilities/updateIndex.d.ts +16 -16
  134. package/dist/data/utilities/updateIndex.js +56 -56
  135. package/dist/data/utilities/useJoinClause.d.ts +5 -5
  136. package/dist/data/utilities/useJoinClause.js +51 -51
  137. package/dist/index.d.ts +4 -4
  138. package/dist/index.js +42 -42
  139. package/package.json +9 -5
@@ -1,45 +1,45 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
6
- exports.getSetting = exports.configure = void 0
7
- const defaults = {
8
- databasePath: 'database/',
9
- relativePath: '',
10
- enforceForeignKeys: true
11
- }
12
- let settings = {
13
- ...defaults
14
- }
15
- /**
16
- * Set where this package's data lives: databasePath (a filesystem path, used in Node) and/or
17
- * relativePath (a URL prefix prepended to databasePath, used when reading over fetch() in a
18
- * browser). Call this once before using create()/drop()/query() - a fresh consumer has no other
19
- * way to point this package at their own data directory.
20
- *
21
- * enforceForeignKeys (default true) controls whether deleteEntity/updateEntity block an operation
22
- * that would leave another record's foreign key pointing at a value that no longer exists -
23
- * mirroring MySQL's own foreign_key_checks setting, which is also toggleable rather than always
24
- * on, since strict enforcement isn't always what every consumer wants.
25
- * @param newSettings
26
- */
27
- const configure = newSettings => {
28
- settings = {
29
- ...settings,
30
- ...newSettings
31
- }
32
- }
33
- /**
34
- * Read one runtime setting, falling back to the given default if it was never configured. This is
35
- * the package's own lightweight replacement for reading settings via js-build-tools/gulp.config -
36
- * that module is a dev-time build tool, not something a published package should require at
37
- * runtime, and it isn't available at all once a consumer installs this package on its own.
38
- * @param key
39
- * @param defaultValue
40
- */
41
- exports.configure = configure
42
- const getSetting = (key, defaultValue) => {
43
- return typeof settings[key] !== 'undefined' ? settings[key] : defaultValue
44
- }
45
- exports.getSetting = getSetting
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSetting = exports.configure = void 0;
7
+ const defaults = {
8
+ databasePath: 'database/',
9
+ relativePath: '',
10
+ enforceForeignKeys: true
11
+ };
12
+ let settings = {
13
+ ...defaults
14
+ };
15
+ /**
16
+ * Set where this package's data lives: databasePath (a filesystem path, used in Node) and/or
17
+ * relativePath (a URL prefix prepended to databasePath, used when reading over fetch() in a
18
+ * browser). Call this once before using create()/drop()/query() - a fresh consumer has no other
19
+ * way to point this package at their own data directory.
20
+ *
21
+ * enforceForeignKeys (default true) controls whether deleteEntity/updateEntity block an operation
22
+ * that would leave another record's foreign key pointing at a value that no longer exists -
23
+ * mirroring MySQL's own foreign_key_checks setting, which is also toggleable rather than always
24
+ * on, since strict enforcement isn't always what every consumer wants.
25
+ * @param newSettings
26
+ */
27
+ const configure = newSettings => {
28
+ settings = {
29
+ ...settings,
30
+ ...newSettings
31
+ };
32
+ };
33
+ /**
34
+ * Read one runtime setting, falling back to the given default if it was never configured. This is
35
+ * the package's own lightweight replacement for reading settings via js-build-tools/gulp.config -
36
+ * that module is a dev-time build tool, not something a published package should require at
37
+ * runtime, and it isn't available at all once a consumer installs this package on its own.
38
+ * @param key
39
+ * @param defaultValue
40
+ */
41
+ exports.configure = configure;
42
+ const getSetting = (key, defaultValue) => {
43
+ return typeof settings[key] !== 'undefined' ? settings[key] : defaultValue;
44
+ };
45
+ exports.getSetting = getSetting;
@@ -1,8 +1,8 @@
1
- import { recordDefinition } from '../introspect/definitions/record';
2
- /**
3
- * Remove a record's filename from the __RECORDS registry. A missing registry file is left
4
- * untouched rather than created, since there's nothing to remove from it.
5
- * @param recordName
6
- */
7
- export declare const deregisterRecord: (recordName: string) => Promise<recordDefinition | null>;
1
+ import { recordDefinition } from '../introspect/definitions/record';
2
+ /**
3
+ * Remove a record's filename from the __RECORDS registry. A missing registry file is left
4
+ * untouched rather than created, since there's nothing to remove from it.
5
+ * @param recordName
6
+ */
7
+ export declare const deregisterRecord: (recordName: string) => Promise<recordDefinition | null>;
8
8
  //# sourceMappingURL=deregisterRecord.d.ts.map
@@ -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
- const _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
- exports.deregisterRecord = deregisterRecord
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
+ 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
- const _isEntityProperty = require('./parsers/isEntityProperty')
8
- const _splitEntityProperty = require('./parsers/splitEntityProperty')
9
- const _retrieveRecord = require('./retrieveRecord')
10
- const _where = require('../queries/where')
11
- const _retrieveFile = require('./retrieveFile')
12
- const _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
- exports.getConditionIndexedList = getConditionIndexedList
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
+ exports.getConditionIndexedList = getConditionIndexedList;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getConditionIndexedList=void 0;var _isEntityProperty=require("./parsers/isEntityProperty"),_splitEntityProperty=require("./parsers/splitEntityProperty"),_retrieveRecord=require("./retrieveRecord"),_where=require("../queries/where"),_retrieveFile=require("./retrieveFile"),_getMatchingIndexes=require("./getMatchingIndexes");const getConditionIndexedList=async(e,t,r)=>{let i=[];for(let o of e.conditions){let n=e.entity,s=o.property;if((0,_isEntityProperty.isEntityProperty)(s)){const e=(0,_splitEntityProperty.splitEntityProperty)(s);n=e.entity,s=e.property}Object.prototype.hasOwnProperty.call(t,n)||(t[n]=await(0,_retrieveRecord.retrieveRecord)(n));const p={},d=async(e,t,r,i,o,n)=>{const s=(0,_where.where)(n[e][t],{property:"value",comparator:i.comparator,value:i.value});for(let t of s)for(let r of t.record)o[e].push(await(0,_retrieveFile.retrieveFile)(`${e}/${r}`))};await(0,_getMatchingIndexes.getMatchingIndexes)(n,s,t,o,r,p,d)||i.push(o)}return e.conditions=i,e};exports.getConditionIndexedList=getConditionIndexedList;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getConditionIndexedList=void 0;var _isEntityProperty=require("./parsers/isEntityProperty"),_splitEntityProperty=require("./parsers/splitEntityProperty"),_retrieveRecord=require("./retrieveRecord"),_where=require("../queries/where"),_retrieveFile=require("./retrieveFile"),_getMatchingIndexes=require("./getMatchingIndexes");const getConditionIndexedList=async(e,t,r)=>{const i=[];for(const o of e.conditions){let n=e.entity,s=o.property;if((0,_isEntityProperty.isEntityProperty)(s)){const e=(0,_splitEntityProperty.splitEntityProperty)(s);n=e.entity,s=e.property}Object.prototype.hasOwnProperty.call(t,n)||(t[n]=await(0,_retrieveRecord.retrieveRecord)(n));const p={},c=async(e,t,r,i,o,n)=>{const s=(0,_where.where)(n[e][t],{property:"value",comparator:i.comparator,value:i.value});for(const t of s)for(const r of t.record)o[e].push(await(0,_retrieveFile.retrieveFile)(`${e}/${r}`))};await(0,_getMatchingIndexes.getMatchingIndexes)(n,s,t,o,r,p,c)||i.push(o)}return e.conditions=i,e};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
- const _siFunciona = _interopRequireDefault(require('si-funciona'))
8
- const _splitEntityProperty = require('./parsers/splitEntityProperty')
9
- const _retrieveRecord = require('./retrieveRecord')
10
- const _getMatchingIndexes = require('./getMatchingIndexes')
11
- const _matchIndexedJoins = require('./matchIndexedJoins')
12
- const _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
- exports.getJoinIndexedList = getJoinIndexedList
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
+ exports.getJoinIndexedList = getJoinIndexedList;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getJoinIndexedList=void 0;var _siFunciona=_interopRequireDefault(require("si-funciona")),_splitEntityProperty=require("./parsers/splitEntityProperty"),_retrieveRecord=require("./retrieveRecord"),_getMatchingIndexes=require("./getMatchingIndexes"),_matchIndexedJoins=require("./matchIndexedJoins"),_restrictIndexedList=require("./restrictIndexedList");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const getJoinIndexedList=async(e,t,r)=>{let i=[];const n={};let o=!0;const s=e.entity,c=e.joinEntity,d=e.joinClauses;if(!r[s].length)return e;if(!d.length)return e;for(const e in r[s]){const a=r[s][e];let p={};p[s]=[_siFunciona.default.cloneObject(a)];for(let e of d){let c=_siFunciona.default.cloneObject(n);const{entity:d,property:a}=(0,_splitEntityProperty.splitEntityProperty)(e.propertyA),{entity:l,property:u}=(0,_splitEntityProperty.splitEntityProperty)(e.propertyB);Object.prototype.hasOwnProperty.call(t,d)||(t[d]=await(0,_retrieveRecord.retrieveRecord)(d)),Object.prototype.hasOwnProperty.call(t,l)||(t[l]=await(0,_retrieveRecord.retrieveRecord)(l)),c=(0,_restrictIndexedList.restrictIndexedList)(e,p,c);const y=(0,_matchIndexedJoins.matchIndexedJoins)(s,c,r),_=await(0,_getMatchingIndexes.getMatchingIndexes)(d,a,t,e,p,n),x=await(0,_getMatchingIndexes.getMatchingIndexes)(l,u,t,e,p,n,y);!(_||x)&&o&&(i.push(e),o=!1)}r[s][e][c]=p[c]}return e.joinClauses=i,e};exports.getJoinIndexedList=getJoinIndexedList;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getJoinIndexedList=void 0;var _siFunciona=_interopRequireDefault(require("si-funciona")),_splitEntityProperty=require("./parsers/splitEntityProperty"),_retrieveRecord=require("./retrieveRecord"),_getMatchingIndexes=require("./getMatchingIndexes"),_matchIndexedJoins=require("./matchIndexedJoins"),_restrictIndexedList=require("./restrictIndexedList");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const getJoinIndexedList=async(e,t,r)=>{const i=[],n={};let o=!0;const s=e.entity,c=e.joinEntity,d=e.joinClauses;if(!r[s].length)return e;if(!d.length)return e;for(const e in r[s]){const a=r[s][e],p={};p[s]=[_siFunciona.default.cloneObject(a)];for(const e of d){let c=_siFunciona.default.cloneObject(n);const{entity:d,property:a}=(0,_splitEntityProperty.splitEntityProperty)(e.propertyA),{entity:u,property:l}=(0,_splitEntityProperty.splitEntityProperty)(e.propertyB);Object.prototype.hasOwnProperty.call(t,d)||(t[d]=await(0,_retrieveRecord.retrieveRecord)(d)),Object.prototype.hasOwnProperty.call(t,u)||(t[u]=await(0,_retrieveRecord.retrieveRecord)(u)),c=(0,_restrictIndexedList.restrictIndexedList)(e,p,c);const y=(0,_matchIndexedJoins.matchIndexedJoins)(s,c,r),_=await(0,_getMatchingIndexes.getMatchingIndexes)(d,a,t,e,p,n),x=await(0,_getMatchingIndexes.getMatchingIndexes)(u,l,t,e,p,n,y);!(_||x)&&o&&(i.push(e),o=!1)}r[s][e][c]=p[c]}return e.joinClauses=i,e};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
- const _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
- exports.getMatchingIndexes = getMatchingIndexes
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
+ exports.getMatchingIndexes = getMatchingIndexes;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getMatchingIndexes=void 0,require("core-js/modules/es.array.includes.js");var _retrieveIndexes=require("./retrieveIndexes");const getMatchingIndexes=async(e,t,r,s,n,i,o=null)=>{let a=!1;for(let c of r[e].keys)c.fields.includes(t)&&(n[e]=[],Object.prototype.hasOwnProperty.call(i,e)||(i[e]={}),Object.prototype.hasOwnProperty.call(i[e],t)||(i[e][t]=(await(0,_retrieveIndexes.retrieveIndexes)(e,[t],r))[t]),"function"==typeof o&&await o(e,t,r,s,n,i),a=!0);return a};exports.getMatchingIndexes=getMatchingIndexes;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getMatchingIndexes=void 0,require("core-js/modules/es.array.includes.js");var _retrieveIndexes=require("./retrieveIndexes");const getMatchingIndexes=async(e,t,r,s,n,o,i=null)=>{let a=!1;for(const c of r[e].keys)c.fields.includes(t)&&(n[e]=[],Object.prototype.hasOwnProperty.call(o,e)||(o[e]={}),Object.prototype.hasOwnProperty.call(o[e],t)||(o[e][t]=(await(0,_retrieveIndexes.retrieveIndexes)(e,[t],r))[t]),"function"==typeof i&&await i(e,t,r,s,n,o),a=!0);return a};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
- const _siFunciona = _interopRequireDefault(require('si-funciona'))
10
- const _where = require('../queries/where')
11
- const _retrieveFile = require('./retrieveFile')
12
- const _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
- exports.matchIndexedJoins = matchIndexedJoins
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
+ exports.matchIndexedJoins = matchIndexedJoins;