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,26 +1,26 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.reconcileJoins = void 0;
7
- var _splitEntityProperty = require("./parsers/splitEntityProperty");
8
- var _reconcileJoin = require("./reconcileJoin");
9
- const reconcileJoins = (propertyA, propertyB, dataSet) => {
10
- const {
11
- entity: entityA,
12
- property: propA
13
- } = (0, _splitEntityProperty.splitEntityProperty)(propertyA);
14
- const {
15
- entity: entityB,
16
- property: propB
17
- } = (0, _splitEntityProperty.splitEntityProperty)(propertyB);
18
- for (const entityName in dataSet) {
19
- for (const entityKey in dataSet[entityName]) {
20
- dataSet = (0, _reconcileJoin.reconcileJoin)(dataSet, entityName, entityKey, entityA, propA);
21
- dataSet = (0, _reconcileJoin.reconcileJoin)(dataSet, entityName, entityKey, entityB, propB);
22
- }
23
- }
24
- return dataSet;
25
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.reconcileJoins = void 0;
7
+ var _splitEntityProperty = require("./parsers/splitEntityProperty");
8
+ var _reconcileJoin = require("./reconcileJoin");
9
+ const reconcileJoins = (propertyA, propertyB, dataSet) => {
10
+ const {
11
+ entity: entityA,
12
+ property: propA
13
+ } = (0, _splitEntityProperty.splitEntityProperty)(propertyA);
14
+ const {
15
+ entity: entityB,
16
+ property: propB
17
+ } = (0, _splitEntityProperty.splitEntityProperty)(propertyB);
18
+ for (const entityName in dataSet) {
19
+ for (const entityKey in dataSet[entityName]) {
20
+ dataSet = (0, _reconcileJoin.reconcileJoin)(dataSet, entityName, entityKey, entityA, propA);
21
+ dataSet = (0, _reconcileJoin.reconcileJoin)(dataSet, entityName, entityKey, entityB, propB);
22
+ }
23
+ }
24
+ return dataSet;
25
+ };
26
26
  exports.reconcileJoins = reconcileJoins;
@@ -1,67 +1,67 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.registerRecord = void 0;
7
- require("core-js/modules/es.array.includes.js");
8
- require("core-js/modules/es.json.stringify.js");
9
- var _config = require("./config");
10
- const {
11
- readFile,
12
- writeFile
13
- } = require('fs/promises');
14
- /**
15
- * __RECORDS is itself an ordinary record - path/definition/keys/entries - whose entries are the
16
- * filenames of every other record that has been created. This is the schema it's given the first
17
- * time a record is registered and no __RECORDS.json exists yet, matching what a hand-authored
18
- * database (see test-data/__RECORDS.json) already expects to find.
19
- */
20
- const defaultRegistry = () => ({
21
- path: '',
22
- definition: [{
23
- name: 'path',
24
- type: 'string',
25
- optional: false,
26
- autoGenerate: false
27
- }, {
28
- name: 'definition',
29
- type: 'object',
30
- optional: false,
31
- autoGenerate: false
32
- }, {
33
- name: 'keys',
34
- type: 'array',
35
- optional: false,
36
- autoGenerate: false
37
- }, {
38
- name: 'entries',
39
- type: 'array',
40
- optional: false,
41
- autoGenerate: false
42
- }],
43
- keys: [],
44
- entries: []
45
- });
46
- /**
47
- * Add a record's filename to the __RECORDS registry, creating the registry file the first time
48
- * a record is created if it doesn't already exist.
49
- * @param recordName
50
- */
51
- const registerRecord = async recordName => {
52
- const databasePath = (0, _config.getSetting)('databasePath', 'database/');
53
- const registryPath = `${databasePath}__RECORDS.json`;
54
- let registry;
55
- try {
56
- registry = JSON.parse(await readFile(registryPath, 'utf8'));
57
- } catch (err) {
58
- registry = defaultRegistry();
59
- }
60
- const fileName = `${recordName}.json`;
61
- if (!registry.entries.includes(fileName)) {
62
- registry.entries.push(fileName);
63
- }
64
- await writeFile(registryPath, JSON.stringify(registry, null, 2));
65
- return registry;
66
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.registerRecord = void 0;
7
+ require("core-js/modules/es.array.includes.js");
8
+ require("core-js/modules/es.json.stringify.js");
9
+ var _config = require("./config");
10
+ const {
11
+ readFile,
12
+ writeFile
13
+ } = require('fs/promises');
14
+ /**
15
+ * __RECORDS is itself an ordinary record - path/definition/keys/entries - whose entries are the
16
+ * filenames of every other record that has been created. This is the schema it's given the first
17
+ * time a record is registered and no __RECORDS.json exists yet, matching what a hand-authored
18
+ * database (see test-data/__RECORDS.json) already expects to find.
19
+ */
20
+ const defaultRegistry = () => ({
21
+ path: '',
22
+ definition: [{
23
+ name: 'path',
24
+ type: 'string',
25
+ optional: false,
26
+ autoGenerate: false
27
+ }, {
28
+ name: 'definition',
29
+ type: 'object',
30
+ optional: false,
31
+ autoGenerate: false
32
+ }, {
33
+ name: 'keys',
34
+ type: 'array',
35
+ optional: false,
36
+ autoGenerate: false
37
+ }, {
38
+ name: 'entries',
39
+ type: 'array',
40
+ optional: false,
41
+ autoGenerate: false
42
+ }],
43
+ keys: [],
44
+ entries: []
45
+ });
46
+ /**
47
+ * Add a record's filename to the __RECORDS registry, creating the registry file the first time
48
+ * a record is created if it doesn't already exist.
49
+ * @param recordName
50
+ */
51
+ const registerRecord = async recordName => {
52
+ const databasePath = (0, _config.getSetting)('databasePath', 'database/');
53
+ const registryPath = `${databasePath}__RECORDS.json`;
54
+ let registry;
55
+ try {
56
+ registry = JSON.parse(await readFile(registryPath, 'utf8'));
57
+ } catch (err) {
58
+ registry = defaultRegistry();
59
+ }
60
+ const fileName = `${recordName}.json`;
61
+ if (!registry.entries.includes(fileName)) {
62
+ registry.entries.push(fileName);
63
+ }
64
+ await writeFile(registryPath, JSON.stringify(registry, null, 2));
65
+ return registry;
66
+ };
67
67
  exports.registerRecord = registerRecord;
@@ -1,14 +1,15 @@
1
- import { keyDefinition } from '../introspect/definitions/key';
2
- import { recordPath } from '../introspect/definitions/record';
3
- import { indexEntry } from './updateIndex';
4
- /**
5
- * Remove a single entry file from the index that backs one of a record's keys, dropping a value
6
- * entirely once its last file is removed. A key with no lookup, or an index file that doesn't
7
- * exist yet, is left untouched.
8
- * @param path
9
- * @param key
10
- * @param value
11
- * @param fileName
12
- */
13
- export declare const removeFromIndex: (path?: recordPath, key?: keyDefinition, value?: any, fileName?: string) => Promise<indexEntry[] | null>;
1
+ import { keyDefinition } from '../introspect/definitions/key';
2
+ import { recordPath } from '../introspect/definitions/record';
3
+ import { indexEntry } from './updateIndex';
4
+ /**
5
+ * Remove a single entry file from the index that backs one of a record's keys, dropping a value
6
+ * entirely once its last file is removed. A key with no lookup, or an index file that doesn't
7
+ * exist yet, is left untouched.
8
+ * @param path
9
+ * @param key
10
+ * @param value
11
+ * @param fileName
12
+ * @param type - The declared type of the indexed value (see keyValueType), so '3' and 3 are one entry.
13
+ */
14
+ export declare const removeFromIndex: (path?: recordPath, key?: keyDefinition, value?: any, fileName?: string, type?: string) => Promise<indexEntry[] | null>;
14
15
  //# sourceMappingURL=removeFromIndex.d.ts.map
@@ -9,6 +9,7 @@ require("core-js/modules/esnext.iterator.constructor.js");
9
9
  require("core-js/modules/esnext.iterator.filter.js");
10
10
  require("core-js/modules/esnext.iterator.map.js");
11
11
  var _config = require("./config");
12
+ var _compareAs = require("./compareAs");
12
13
  const {
13
14
  readFile,
14
15
  writeFile
@@ -21,8 +22,9 @@ const {
21
22
  * @param key
22
23
  * @param value
23
24
  * @param fileName
25
+ * @param type - The declared type of the indexed value (see keyValueType), so '3' and 3 are one entry.
24
26
  */
25
- const removeFromIndex = async (path = '', key = null, value = undefined, fileName = '') => {
27
+ const removeFromIndex = async (path = '', key = null, value = undefined, fileName = '', type = undefined) => {
26
28
  if (!key || !key.lookup) {
27
29
  return null;
28
30
  }
@@ -34,7 +36,7 @@ const removeFromIndex = async (path = '', key = null, value = undefined, fileNam
34
36
  } catch (err) {
35
37
  return null;
36
38
  }
37
- index = index.map(entry => entry.value == value ? {
39
+ index = index.map(entry => (0, _compareAs.sameValue)(type, entry.value, value) ? {
38
40
  value: entry.value,
39
41
  record: entry.record.filter(record => record !== fileName)
40
42
  } : entry).filter(entry => entry.record.length);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.removeFromIndex=void 0,require("core-js/modules/es.json.stringify.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.filter.js"),require("core-js/modules/esnext.iterator.map.js");var _config=require("./config");const{readFile:readFile,writeFile:writeFile}=require("fs/promises"),removeFromIndex=async(e="",r=null,t=void 0,o="")=>{if(!r||!r.lookup)return null;const i=`${(0,_config.getSetting)("databasePath","database/")}__indexes/${e}/${r.lookup}`;let s=[];try{s=JSON.parse(await readFile(i,"utf8"))}catch(e){return null}return s=s.map((e=>e.value==t?{value:e.value,record:e.record.filter((e=>e!==o))}:e)).filter((e=>e.record.length)),await writeFile(i,JSON.stringify(s,null,2)),s};exports.removeFromIndex=removeFromIndex;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.removeFromIndex=void 0,require("core-js/modules/es.json.stringify.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.filter.js"),require("core-js/modules/esnext.iterator.map.js");var _config=require("./config"),_compareAs=require("./compareAs");const{readFile:readFile,writeFile:writeFile}=require("fs/promises"),removeFromIndex=async(e="",r=null,o=void 0,t="",i=void 0)=>{if(!r||!r.lookup)return null;const s=`${(0,_config.getSetting)("databasePath","database/")}__indexes/${e}/${r.lookup}`;let a=[];try{a=JSON.parse(await readFile(s,"utf8"))}catch(e){return null}return a=a.map((e=>(0,_compareAs.sameValue)(i,e.value,o)?{value:e.value,record:e.record.filter((e=>e!==t))}:e)).filter((e=>e.record.length)),await writeFile(s,JSON.stringify(a,null,2)),a};exports.removeFromIndex=removeFromIndex;
@@ -1,45 +1,45 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.restrictIndexedList = void 0;
7
- var _splitEntityProperty = require("./parsers/splitEntityProperty");
8
- const restrictIndexedList = (joinClause, filterJoins, indexedClone) => {
9
- const {
10
- entity: entityA,
11
- property: propertyA
12
- } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyA);
13
- const {
14
- entity: entityB,
15
- property: propertyB
16
- } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyB);
17
- if (Object.prototype.hasOwnProperty.call(filterJoins, entityA)) {
18
- const existingEntities = filterJoins[entityA];
19
- if (!Object.prototype.hasOwnProperty.call(indexedClone, entityA)) {
20
- indexedClone[entityA] = {};
21
- }
22
- if (!Object.prototype.hasOwnProperty.call(indexedClone[entityA], propertyA)) {
23
- indexedClone[entityA][propertyA] = {};
24
- }
25
- indexedClone[entityA][propertyA] = [{
26
- value: existingEntities[0][propertyA],
27
- record: existingEntities
28
- }];
29
- }
30
- if (Object.prototype.hasOwnProperty.call(filterJoins, entityB)) {
31
- const existingEntities = filterJoins[entityB];
32
- if (!Object.prototype.hasOwnProperty.call(indexedClone, entityB)) {
33
- indexedClone[entityB] = {};
34
- }
35
- if (!Object.prototype.hasOwnProperty.call(indexedClone[entityB], propertyB)) {
36
- indexedClone[entityB][propertyB] = {};
37
- }
38
- indexedClone[entityB][propertyB] = [{
39
- value: existingEntities[0][propertyB],
40
- record: existingEntities
41
- }];
42
- }
43
- return indexedClone;
44
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.restrictIndexedList = void 0;
7
+ var _splitEntityProperty = require("./parsers/splitEntityProperty");
8
+ const restrictIndexedList = (joinClause, filterJoins, indexedClone) => {
9
+ const {
10
+ entity: entityA,
11
+ property: propertyA
12
+ } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyA);
13
+ const {
14
+ entity: entityB,
15
+ property: propertyB
16
+ } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyB);
17
+ if (Object.prototype.hasOwnProperty.call(filterJoins, entityA)) {
18
+ const existingEntities = filterJoins[entityA];
19
+ if (!Object.prototype.hasOwnProperty.call(indexedClone, entityA)) {
20
+ indexedClone[entityA] = {};
21
+ }
22
+ if (!Object.prototype.hasOwnProperty.call(indexedClone[entityA], propertyA)) {
23
+ indexedClone[entityA][propertyA] = {};
24
+ }
25
+ indexedClone[entityA][propertyA] = [{
26
+ value: existingEntities[0][propertyA],
27
+ record: existingEntities
28
+ }];
29
+ }
30
+ if (Object.prototype.hasOwnProperty.call(filterJoins, entityB)) {
31
+ const existingEntities = filterJoins[entityB];
32
+ if (!Object.prototype.hasOwnProperty.call(indexedClone, entityB)) {
33
+ indexedClone[entityB] = {};
34
+ }
35
+ if (!Object.prototype.hasOwnProperty.call(indexedClone[entityB], propertyB)) {
36
+ indexedClone[entityB][propertyB] = {};
37
+ }
38
+ indexedClone[entityB][propertyB] = [{
39
+ value: existingEntities[0][propertyB],
40
+ record: existingEntities
41
+ }];
42
+ }
43
+ return indexedClone;
44
+ };
45
45
  exports.restrictIndexedList = restrictIndexedList;
@@ -1,28 +1,28 @@
1
- "use strict";
2
-
3
- require("core-js/modules/esnext.weak-map.delete-all.js");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.retrieveFile = void 0;
8
- var jsEnv = _interopRequireWildcard(require("browser-or-node"));
9
- var _config = require("./config");
10
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
- const retrieveFile = async path => {
12
- let retrieveFn = url => fetch(url).then(res => res.json());
13
- const relativePath = jsEnv.isBrowser ? (0, _config.getSetting)('relativePath', '') : '';
14
- if (jsEnv.isNode) {
15
- const {
16
- readFile
17
- } = require('fs/promises');
18
- retrieveFn = url => readFile(url).then(res => JSON.parse(res));
19
- }
20
- const databasePath = (0, _config.getSetting)('databasePath', 'database/');
21
- const fetchUrl = `${relativePath}${databasePath}${path}`;
22
- const recordInfo = await retrieveFn(fetchUrl).catch(err => console.error(err));
23
- if (!recordInfo) {
24
- throw new Error(`Could not read ${path}`);
25
- }
26
- return recordInfo;
27
- };
1
+ "use strict";
2
+
3
+ require("core-js/modules/esnext.weak-map.delete-all.js");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.retrieveFile = void 0;
8
+ var jsEnv = _interopRequireWildcard(require("browser-or-node"));
9
+ var _config = require("./config");
10
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
+ const retrieveFile = async path => {
12
+ let retrieveFn = url => fetch(url).then(res => res.json());
13
+ const relativePath = jsEnv.isBrowser ? (0, _config.getSetting)('relativePath', '') : '';
14
+ if (jsEnv.isNode) {
15
+ const {
16
+ readFile
17
+ } = require('fs/promises');
18
+ retrieveFn = url => readFile(url).then(res => JSON.parse(res));
19
+ }
20
+ const databasePath = (0, _config.getSetting)('databasePath', 'database/');
21
+ const fetchUrl = `${relativePath}${databasePath}${path}`;
22
+ const recordInfo = await retrieveFn(fetchUrl).catch(err => console.error(err));
23
+ if (!recordInfo) {
24
+ throw new Error(`Could not read ${path}`);
25
+ }
26
+ return recordInfo;
27
+ };
28
28
  exports.retrieveFile = retrieveFile;
@@ -1,24 +1,24 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.retrieveIndexes = void 0;
7
- require("core-js/modules/es.array.includes.js");
8
- var _retrieveFile = require("./retrieveFile");
9
- var _retrieveRecord = require("./retrieveRecord");
10
- const retrieveIndexes = async (entity = '', properties = [], recordData = {}) => {
11
- if (!Object.prototype.hasOwnProperty.call(recordData, entity)) {
12
- recordData[entity] = await (0, _retrieveRecord.retrieveRecord)(entity);
13
- }
14
- const indexSet = {};
15
- for (const property of properties) {
16
- for (const key of recordData[entity].keys) {
17
- if (key.fields.includes(property)) {
18
- indexSet[property] = await (0, _retrieveFile.retrieveFile)(`__indexes/${entity}/${key.lookup}`);
19
- }
20
- }
21
- }
22
- return indexSet;
23
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.retrieveIndexes = void 0;
7
+ require("core-js/modules/es.array.includes.js");
8
+ var _retrieveFile = require("./retrieveFile");
9
+ var _retrieveRecord = require("./retrieveRecord");
10
+ const retrieveIndexes = async (entity = '', properties = [], recordData = {}) => {
11
+ if (!Object.prototype.hasOwnProperty.call(recordData, entity)) {
12
+ recordData[entity] = await (0, _retrieveRecord.retrieveRecord)(entity);
13
+ }
14
+ const indexSet = {};
15
+ for (const property of properties) {
16
+ for (const key of recordData[entity].keys) {
17
+ if (key.fields.includes(property)) {
18
+ indexSet[property] = await (0, _retrieveFile.retrieveFile)(`__indexes/${entity}/${key.lookup}`);
19
+ }
20
+ }
21
+ }
22
+ return indexSet;
23
+ };
24
24
  exports.retrieveIndexes = retrieveIndexes;
@@ -1,9 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.retrieveRecord = void 0;
7
- var _retrieveFile = require("./retrieveFile");
8
- const retrieveRecord = async (entity = '') => await (0, _retrieveFile.retrieveFile)(`${entity}.json`);
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.retrieveRecord = void 0;
7
+ var _retrieveFile = require("./retrieveFile");
8
+ const retrieveRecord = async (entity = '') => await (0, _retrieveFile.retrieveFile)(`${entity}.json`);
9
9
  exports.retrieveRecord = retrieveRecord;
@@ -1,21 +1,21 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.retrieveRecords = void 0;
7
- var _retrieveFile = require("./retrieveFile");
8
- var _retrieveRecord = require("./retrieveRecord");
9
- const retrieveRecords = async (entity = '') => {
10
- const recordFile = await (0, _retrieveRecord.retrieveRecord)(entity);
11
- const dataSet = [];
12
- for (const file of recordFile.entries) {
13
- const data = await (0, _retrieveFile.retrieveFile)(`${recordFile.path}/${file}`).catch(err => console.error(err));
14
- if (!data) {
15
- throw new Error(`Could not read entity ${file}`);
16
- }
17
- dataSet.push(data);
18
- }
19
- return dataSet;
20
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.retrieveRecords = void 0;
7
+ var _retrieveFile = require("./retrieveFile");
8
+ var _retrieveRecord = require("./retrieveRecord");
9
+ const retrieveRecords = async (entity = '') => {
10
+ const recordFile = await (0, _retrieveRecord.retrieveRecord)(entity);
11
+ const dataSet = [];
12
+ for (const file of recordFile.entries) {
13
+ const data = await (0, _retrieveFile.retrieveFile)(`${recordFile.path}/${file}`).catch(err => console.error(err));
14
+ if (!data) {
15
+ throw new Error(`Could not read entity ${file}`);
16
+ }
17
+ dataSet.push(data);
18
+ }
19
+ return dataSet;
20
+ };
21
21
  exports.retrieveRecords = retrieveRecords;
@@ -20,6 +20,31 @@ var _selectFields = require("../queries/selectFields");
20
20
  var _retrieveRecord = require("./retrieveRecord");
21
21
  var _getConditionIndexedList = require("./getConditionIndexedList");
22
22
  var _getJoinIndexedList = require("./getJoinIndexedList");
23
+ var _isEntityProperty = require("./parsers/isEntityProperty");
24
+ var _splitEntityProperty = require("./parsers/splitEntityProperty");
25
+ var _fieldType = require("./fieldType");
26
+ /**
27
+ * Give each condition its field's declared type, so where compares by it (a joined entity's field
28
+ * is looked up on that entity's record).
29
+ * @param parsed
30
+ * @param recordData
31
+ */
32
+ const typeConditions = async (parsed, recordData) => {
33
+ for (const condition of parsed.conditions) {
34
+ let entity = parsed.entity;
35
+ let property = condition.property;
36
+ if ((0, _isEntityProperty.isEntityProperty)(property)) {
37
+ ({
38
+ entity,
39
+ property
40
+ } = (0, _splitEntityProperty.splitEntityProperty)(property));
41
+ }
42
+ if (!Object.prototype.hasOwnProperty.call(recordData, entity)) {
43
+ recordData[entity] = await (0, _retrieveRecord.retrieveRecord)(entity);
44
+ }
45
+ condition.type = (0, _fieldType.fieldType)(recordData[entity], property);
46
+ }
47
+ };
23
48
  const runQuery = async parsed => {
24
49
  const recordData = {
25
50
  [parsed.entity]: await (0, _retrieveRecord.retrieveRecord)(parsed.entity)
@@ -27,6 +52,7 @@ const runQuery = async parsed => {
27
52
  if (typeof parsed.joinEntity !== 'undefined') {
28
53
  recordData[parsed.joinEntity] = await (0, _retrieveRecord.retrieveRecord)(parsed.joinEntity);
29
54
  }
55
+ await typeConditions(parsed, recordData);
30
56
  let dataSet = {
31
57
  [parsed.entity]: []
32
58
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.runQuery=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var _deleteEntity=require("../queries/deleteEntity"),_insertEntity=require("../queries/insertEntity"),_readEntity=require("../queries/readEntity"),_updateEntity=require("../queries/updateEntity"),_joinEntity=require("../queries/joinEntity"),_mergeJoins=require("../queries/mergeJoins"),_where=require("../queries/where"),_sortBy=require("../queries/sortBy"),_groupBy=require("../queries/groupBy"),_limitOffset=require("../queries/limitOffset"),_selectFields=require("../queries/selectFields"),_retrieveRecord=require("./retrieveRecord"),_getConditionIndexedList=require("./getConditionIndexedList"),_getJoinIndexedList=require("./getJoinIndexedList");const runQuery=async e=>{const t={[e.entity]:await(0,_retrieveRecord.retrieveRecord)(e.entity)};void 0!==e.joinEntity&&(t[e.joinEntity]=await(0,_retrieveRecord.retrieveRecord)(e.joinEntity));let i={[e.entity]:[]};const r=e.conditions.length>0;e=await(0,_getConditionIndexedList.getConditionIndexedList)(e,t,i);const n=r&&0===e.conditions.length;switch("delete"!==(e=await(0,_getJoinIndexedList.getJoinIndexedList)(e,t,i)).command&&"update"!==e.command||(n||(i=await(0,_readEntity.readEntity)(e.entity,i)),i[e.entity]=e.conditions.reduce(((e,t)=>(0,_where.where)(e,t)),i[e.entity])),e.command){case"delete":i=await(0,_deleteEntity.deleteEntity)(e.entity,i);break;case"insert":i=await(0,_insertEntity.insertEntity)(e.entity,e.insertValues,i);break;case"read":n||(i=await(0,_readEntity.readEntity)(e.entity,i));break;case"update":i=await(0,_updateEntity.updateEntity)(e.entity,e.updateValues,i);break;default:throw new Error(`Unknown command: ${e.command}`)}return i=await(0,_joinEntity.joinEntity)(e.entity,e.joinEntity,i,e.joinClauses,n),i=await(0,_mergeJoins.mergeJoins)(i,e.mergeJoins),"delete"!==e.command&&"update"!==e.command&&(i[e.entity]=e.conditions.reduce(((e,t)=>(0,_where.where)(e,t)),i[e.entity])),i[e.entity]=(0,_sortBy.sortBy)(i[e.entity],e.sortClauses),i[e.entity]=(0,_limitOffset.limitOffset)(i[e.entity],e.offset,e.limit),i[e.entity]=(0,_groupBy.groupBy)(i[e.entity],e.groupBy),i[e.entity]=(0,_selectFields.selectFields)(i[e.entity],e.selectClauses),i};exports.runQuery=runQuery;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.runQuery=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var _deleteEntity=require("../queries/deleteEntity"),_insertEntity=require("../queries/insertEntity"),_readEntity=require("../queries/readEntity"),_updateEntity=require("../queries/updateEntity"),_joinEntity=require("../queries/joinEntity"),_mergeJoins=require("../queries/mergeJoins"),_where=require("../queries/where"),_sortBy=require("../queries/sortBy"),_groupBy=require("../queries/groupBy"),_limitOffset=require("../queries/limitOffset"),_selectFields=require("../queries/selectFields"),_retrieveRecord=require("./retrieveRecord"),_getConditionIndexedList=require("./getConditionIndexedList"),_getJoinIndexedList=require("./getJoinIndexedList"),_isEntityProperty=require("./parsers/isEntityProperty"),_splitEntityProperty=require("./parsers/splitEntityProperty"),_fieldType=require("./fieldType");const typeConditions=async(e,t)=>{for(const i of e.conditions){let r=e.entity,n=i.property;(0,_isEntityProperty.isEntityProperty)(n)&&({entity:r,property:n}=(0,_splitEntityProperty.splitEntityProperty)(n)),Object.prototype.hasOwnProperty.call(t,r)||(t[r]=await(0,_retrieveRecord.retrieveRecord)(r)),i.type=(0,_fieldType.fieldType)(t[r],n)}},runQuery=async e=>{const t={[e.entity]:await(0,_retrieveRecord.retrieveRecord)(e.entity)};void 0!==e.joinEntity&&(t[e.joinEntity]=await(0,_retrieveRecord.retrieveRecord)(e.joinEntity)),await typeConditions(e,t);let i={[e.entity]:[]};const r=e.conditions.length>0;e=await(0,_getConditionIndexedList.getConditionIndexedList)(e,t,i);const n=r&&0===e.conditions.length;switch("delete"!==(e=await(0,_getJoinIndexedList.getJoinIndexedList)(e,t,i)).command&&"update"!==e.command||(n||(i=await(0,_readEntity.readEntity)(e.entity,i)),i[e.entity]=e.conditions.reduce(((e,t)=>(0,_where.where)(e,t)),i[e.entity])),e.command){case"delete":i=await(0,_deleteEntity.deleteEntity)(e.entity,i);break;case"insert":i=await(0,_insertEntity.insertEntity)(e.entity,e.insertValues,i);break;case"read":n||(i=await(0,_readEntity.readEntity)(e.entity,i));break;case"update":i=await(0,_updateEntity.updateEntity)(e.entity,e.updateValues,i);break;default:throw new Error(`Unknown command: ${e.command}`)}return i=await(0,_joinEntity.joinEntity)(e.entity,e.joinEntity,i,e.joinClauses,n),i=await(0,_mergeJoins.mergeJoins)(i,e.mergeJoins),"delete"!==e.command&&"update"!==e.command&&(i[e.entity]=e.conditions.reduce(((e,t)=>(0,_where.where)(e,t)),i[e.entity])),i[e.entity]=(0,_sortBy.sortBy)(i[e.entity],e.sortClauses),i[e.entity]=(0,_limitOffset.limitOffset)(i[e.entity],e.offset,e.limit),i[e.entity]=(0,_groupBy.groupBy)(i[e.entity],e.groupBy),i[e.entity]=(0,_selectFields.selectFields)(i[e.entity],e.selectClauses),i};exports.runQuery=runQuery;
@@ -1,17 +1,18 @@
1
- import { keyDefinition } from '../introspect/definitions/key';
2
- import { recordPath } from '../introspect/definitions/record';
3
- export type indexEntry = {
4
- value: any;
5
- record: string[];
6
- };
7
- /**
8
- * Add a single entry file to the index that backs one of a record's keys, creating the index
9
- * file (and its __indexes/{record} directory) the first time a value is indexed. Keys with no
10
- * lookup (multi-field keys are not indexed here) are left untouched.
11
- * @param path
12
- * @param key
13
- * @param value
14
- * @param fileName
15
- */
16
- export declare const updateIndex: (path?: recordPath, key?: keyDefinition, value?: any, fileName?: string) => Promise<indexEntry[] | null>;
1
+ import { keyDefinition } from '../introspect/definitions/key';
2
+ import { recordPath } from '../introspect/definitions/record';
3
+ export type indexEntry = {
4
+ value: any;
5
+ record: string[];
6
+ };
7
+ /**
8
+ * Add a single entry file to the index that backs one of a record's keys, creating the index
9
+ * file (and its __indexes/{record} directory) the first time a value is indexed. Keys with no
10
+ * lookup (multi-field keys are not indexed here) are left untouched.
11
+ * @param path
12
+ * @param key
13
+ * @param value
14
+ * @param fileName
15
+ * @param type - The declared type of the indexed value (see keyValueType), so '3' and 3 share one entry.
16
+ */
17
+ export declare const updateIndex: (path?: recordPath, key?: keyDefinition, value?: any, fileName?: string, type?: string) => Promise<indexEntry[] | null>;
17
18
  //# sourceMappingURL=updateIndex.d.ts.map
@@ -9,6 +9,7 @@ require("core-js/modules/es.json.stringify.js");
9
9
  require("core-js/modules/esnext.iterator.constructor.js");
10
10
  require("core-js/modules/esnext.iterator.find.js");
11
11
  var _config = require("./config");
12
+ var _compareAs = require("./compareAs");
12
13
  const {
13
14
  readFile,
14
15
  writeFile,
@@ -22,8 +23,9 @@ const {
22
23
  * @param key
23
24
  * @param value
24
25
  * @param fileName
26
+ * @param type - The declared type of the indexed value (see keyValueType), so '3' and 3 share one entry.
25
27
  */
26
- const updateIndex = async (path = '', key = null, value = undefined, fileName = '') => {
28
+ const updateIndex = async (path = '', key = null, value = undefined, fileName = '', type = undefined) => {
27
29
  if (!key || !key.lookup) {
28
30
  return null;
29
31
  }
@@ -36,7 +38,7 @@ const updateIndex = async (path = '', key = null, value = undefined, fileName =
36
38
  } catch (err) {
37
39
  index = [];
38
40
  }
39
- const existingEntry = index.find(entry => entry.value == value);
41
+ const existingEntry = index.find(entry => (0, _compareAs.sameValue)(type, entry.value, value));
40
42
  if (existingEntry) {
41
43
  if (!existingEntry.record.includes(fileName)) {
42
44
  existingEntry.record.push(fileName);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.updateIndex=void 0,require("core-js/modules/es.array.includes.js"),require("core-js/modules/es.json.stringify.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.find.js");var _config=require("./config");const{readFile:readFile,writeFile:writeFile,mkdir:mkdir}=require("fs/promises"),updateIndex=async(e="",r=null,i=void 0,s="")=>{if(!r||!r.lookup)return null;const t=`${(0,_config.getSetting)("databasePath","database/")}__indexes/${e}`,o=`${t}/${r.lookup}`;let u=[];try{u=JSON.parse(await readFile(o,"utf8"))}catch(e){u=[]}const d=u.find((e=>e.value==i));return d?d.record.includes(s)||d.record.push(s):u.push({value:i,record:[s]}),await mkdir(t,{recursive:!0}),await writeFile(o,JSON.stringify(u,null,2)),u};exports.updateIndex=updateIndex;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.updateIndex=void 0,require("core-js/modules/es.array.includes.js"),require("core-js/modules/es.json.stringify.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.find.js");var _config=require("./config"),_compareAs=require("./compareAs");const{readFile:readFile,writeFile:writeFile,mkdir:mkdir}=require("fs/promises"),updateIndex=async(e="",r=null,s=void 0,i="",t=void 0)=>{if(!r||!r.lookup)return null;const o=`${(0,_config.getSetting)("databasePath","database/")}__indexes/${e}`,a=`${o}/${r.lookup}`;let u=[];try{u=JSON.parse(await readFile(a,"utf8"))}catch(e){u=[]}const d=u.find((e=>(0,_compareAs.sameValue)(t,e.value,s)));return d?d.record.includes(i)||d.record.push(i):u.push({value:s,record:[i]}),await mkdir(o,{recursive:!0}),await writeFile(a,JSON.stringify(u,null,2)),u};exports.updateIndex=updateIndex;