json-fs-query 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/browser/jsonFsQuery.js +2 -2
  2. package/browser/jsonFsQuery.min.js +1 -1
  3. package/dist/data/introspect/create.js +46 -46
  4. package/dist/data/introspect/definitions/field.js +35 -35
  5. package/dist/data/introspect/definitions/key.js +52 -52
  6. package/dist/data/introspect/definitions/keyReference.js +19 -19
  7. package/dist/data/introspect/definitions/record.js +31 -31
  8. package/dist/data/introspect/describe.js +14 -14
  9. package/dist/data/introspect/drop.js +36 -36
  10. package/dist/data/introspect/index.js +29 -29
  11. package/dist/data/introspect/policies/foreignKeyExists.js +24 -24
  12. package/dist/data/introspect/policies/hasDependents.js +51 -51
  13. package/dist/data/introspect/policies/keyGenerate.js +16 -16
  14. package/dist/data/introspect/policies/keyUnique.js +30 -30
  15. package/dist/data/introspect/policies/typeCheck.js +56 -56
  16. package/dist/data/introspect/policies/typeEnum.js +13 -13
  17. package/dist/data/introspect/policies/useDefault.js +12 -12
  18. package/dist/data/queries/deleteEntity.js +99 -99
  19. package/dist/data/queries/groupBy.js +21 -21
  20. package/dist/data/queries/insertEntity.js +116 -116
  21. package/dist/data/queries/joinEntity.js +31 -31
  22. package/dist/data/queries/limitOffset.js +20 -20
  23. package/dist/data/queries/mergeJoins.js +18 -18
  24. package/dist/data/queries/parser.js +29 -29
  25. package/dist/data/queries/query.js +17 -17
  26. package/dist/data/queries/readEntity.js +13 -13
  27. package/dist/data/queries/selectFields.js +35 -35
  28. package/dist/data/queries/sortBy.js +24 -24
  29. package/dist/data/queries/updateEntity.js +189 -189
  30. package/dist/data/queries/where.js +55 -55
  31. package/dist/data/utilities/computeKeyValue.js +25 -25
  32. package/dist/data/utilities/config.js +44 -44
  33. package/dist/data/utilities/deregisterRecord.js +33 -33
  34. package/dist/data/utilities/getConditionIndexedList.js +46 -46
  35. package/dist/data/utilities/getJoinIndexedList.js +75 -75
  36. package/dist/data/utilities/getMatchingIndexes.js +27 -27
  37. package/dist/data/utilities/matchIndexedJoins.js +60 -60
  38. package/dist/data/utilities/mergeJoin.js +43 -43
  39. package/dist/data/utilities/parsers/findCommand.js +24 -24
  40. package/dist/data/utilities/parsers/findConditions.js +27 -27
  41. package/dist/data/utilities/parsers/findGroupBy.js +21 -21
  42. package/dist/data/utilities/parsers/findInsertValues.js +33 -33
  43. package/dist/data/utilities/parsers/findJoinClauses.js +26 -26
  44. package/dist/data/utilities/parsers/findJoinEntity.js +21 -21
  45. package/dist/data/utilities/parsers/findLimit.js +21 -21
  46. package/dist/data/utilities/parsers/findMergeJoins.js +25 -25
  47. package/dist/data/utilities/parsers/findOffset.js +21 -21
  48. package/dist/data/utilities/parsers/findSelects.js +29 -29
  49. package/dist/data/utilities/parsers/findSortClauses.js +29 -29
  50. package/dist/data/utilities/parsers/findUpdateValues.js +33 -33
  51. package/dist/data/utilities/parsers/isEntityProperty.js +7 -7
  52. package/dist/data/utilities/parsers/parseLiteralValue.js +33 -33
  53. package/dist/data/utilities/parsers/parseQuery.js +50 -50
  54. package/dist/data/utilities/parsers/removeFromQuery.js +7 -7
  55. package/dist/data/utilities/parsers/splitEntityProperty.js +22 -22
  56. package/dist/data/utilities/parsers/splitQueries.js +10 -10
  57. package/dist/data/utilities/reconcileJoin.js +25 -25
  58. package/dist/data/utilities/reconcileJoins.js +25 -25
  59. package/dist/data/utilities/registerRecord.js +66 -66
  60. package/dist/data/utilities/removeFromIndex.js +43 -43
  61. package/dist/data/utilities/restrictIndexedList.js +44 -44
  62. package/dist/data/utilities/retrieveFile.js +27 -27
  63. package/dist/data/utilities/retrieveIndexes.js +23 -23
  64. package/dist/data/utilities/retrieveRecord.js +8 -8
  65. package/dist/data/utilities/retrieveRecords.js +20 -20
  66. package/dist/data/utilities/runQuery.js +86 -86
  67. package/dist/data/utilities/updateIndex.js +55 -55
  68. package/dist/data/utilities/useJoinClause.js +50 -50
  69. package/dist/index.js +41 -41
  70. package/package.json +9 -5
@@ -1,34 +1,34 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.parseLiteralValue = void 0;
7
- /**
8
- * Several parsers (findConditions, findInsertValues, findUpdateValues) capture a query-string
9
- * literal into one of six consecutive alternation groups depending on its shape - quoted string,
10
- * number, array, null, true, false - since a single regex can't otherwise tell them apart. Given
11
- * the match and the index of the first of those six groups (which shifts depending on how many
12
- * groups come before it in the parent regex), return the literal with its real JS type.
13
- * @param match
14
- * @param baseIndex
15
- */
16
- const parseLiteralValue = (match, baseIndex) => {
17
- if (typeof match[baseIndex] !== 'undefined') {
18
- return match[baseIndex];
19
- }
20
- if (typeof match[baseIndex + 1] !== 'undefined') {
21
- return Number(match[baseIndex + 1]);
22
- }
23
- if (typeof match[baseIndex + 2] !== 'undefined') {
24
- return JSON.parse(match[baseIndex + 2]);
25
- }
26
- if (typeof match[baseIndex + 3] !== 'undefined') {
27
- return null;
28
- }
29
- if (typeof match[baseIndex + 4] !== 'undefined') {
30
- return true;
31
- }
32
- return false;
33
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseLiteralValue = void 0;
7
+ /**
8
+ * Several parsers (findConditions, findInsertValues, findUpdateValues) capture a query-string
9
+ * literal into one of six consecutive alternation groups depending on its shape - quoted string,
10
+ * number, array, null, true, false - since a single regex can't otherwise tell them apart. Given
11
+ * the match and the index of the first of those six groups (which shifts depending on how many
12
+ * groups come before it in the parent regex), return the literal with its real JS type.
13
+ * @param match
14
+ * @param baseIndex
15
+ */
16
+ const parseLiteralValue = (match, baseIndex) => {
17
+ if (typeof match[baseIndex] !== 'undefined') {
18
+ return match[baseIndex];
19
+ }
20
+ if (typeof match[baseIndex + 1] !== 'undefined') {
21
+ return Number(match[baseIndex + 1]);
22
+ }
23
+ if (typeof match[baseIndex + 2] !== 'undefined') {
24
+ return JSON.parse(match[baseIndex + 2]);
25
+ }
26
+ if (typeof match[baseIndex + 3] !== 'undefined') {
27
+ return null;
28
+ }
29
+ if (typeof match[baseIndex + 4] !== 'undefined') {
30
+ return true;
31
+ }
32
+ return false;
33
+ };
34
34
  exports.parseLiteralValue = parseLiteralValue;
@@ -1,51 +1,51 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.parseQuery = void 0;
7
- var _siFunciona = _interopRequireDefault(require("si-funciona"));
8
- var _findCommand = require("./findCommand");
9
- var _findInsertValues = require("./findInsertValues");
10
- var _findUpdateValues = require("./findUpdateValues");
11
- var _findJoinEntity = require("./findJoinEntity");
12
- var _findSelects = require("./findSelects");
13
- var _findConditions = require("./findConditions");
14
- var _findJoinClauses = require("./findJoinClauses");
15
- var _findMergeJoins = require("./findMergeJoins");
16
- var _findSortClauses = require("./findSortClauses");
17
- var _findGroupBy = require("./findGroupBy");
18
- var _findLimit = require("./findLimit");
19
- var _findOffset = require("./findOffset");
20
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
- /**
22
- * Break a query down into its components.
23
- * @param query
24
- */
25
- const parseQuery = query => {
26
- const parsedQuery = {
27
- command: undefined,
28
- entity: undefined,
29
- joinEntity: undefined,
30
- selectClauses: [],
31
- insertValues: [],
32
- updateValues: {},
33
- conditions: [],
34
- joinClauses: [],
35
- mergeJoins: [],
36
- sortClauses: [],
37
- groupBy: undefined,
38
- limit: undefined,
39
- offset: undefined
40
- };
41
- const {
42
- curry,
43
- pipe
44
- } = _siFunciona.default;
45
- query = pipe(curry(_findCommand.findCommand)(parsedQuery), curry(_findInsertValues.findInsertValues)(parsedQuery), curry(_findUpdateValues.findUpdateValues)(parsedQuery), curry(_findJoinEntity.findJoinEntity)(parsedQuery), curry(_findSelects.findSelects)(parsedQuery), curry(_findConditions.findConditions)(parsedQuery), curry(_findJoinClauses.findJoinClauses)(parsedQuery), curry(_findMergeJoins.findMergeJoins)(parsedQuery), curry(_findSortClauses.findSortClauses)(parsedQuery), curry(_findGroupBy.findGroupBy)(parsedQuery), curry(_findLimit.findLimit)(parsedQuery), curry(_findOffset.findOffset)(parsedQuery))(query);
46
- if (query) {
47
- throw new Error(`Unrecognized query value: ${query}`);
48
- }
49
- return parsedQuery;
50
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseQuery = void 0;
7
+ var _siFunciona = _interopRequireDefault(require("si-funciona"));
8
+ var _findCommand = require("./findCommand");
9
+ var _findInsertValues = require("./findInsertValues");
10
+ var _findUpdateValues = require("./findUpdateValues");
11
+ var _findJoinEntity = require("./findJoinEntity");
12
+ var _findSelects = require("./findSelects");
13
+ var _findConditions = require("./findConditions");
14
+ var _findJoinClauses = require("./findJoinClauses");
15
+ var _findMergeJoins = require("./findMergeJoins");
16
+ var _findSortClauses = require("./findSortClauses");
17
+ var _findGroupBy = require("./findGroupBy");
18
+ var _findLimit = require("./findLimit");
19
+ var _findOffset = require("./findOffset");
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
+ /**
22
+ * Break a query down into its components.
23
+ * @param query
24
+ */
25
+ const parseQuery = query => {
26
+ const parsedQuery = {
27
+ command: undefined,
28
+ entity: undefined,
29
+ joinEntity: undefined,
30
+ selectClauses: [],
31
+ insertValues: [],
32
+ updateValues: {},
33
+ conditions: [],
34
+ joinClauses: [],
35
+ mergeJoins: [],
36
+ sortClauses: [],
37
+ groupBy: undefined,
38
+ limit: undefined,
39
+ offset: undefined
40
+ };
41
+ const {
42
+ curry,
43
+ pipe
44
+ } = _siFunciona.default;
45
+ query = pipe(curry(_findCommand.findCommand)(parsedQuery), curry(_findInsertValues.findInsertValues)(parsedQuery), curry(_findUpdateValues.findUpdateValues)(parsedQuery), curry(_findJoinEntity.findJoinEntity)(parsedQuery), curry(_findSelects.findSelects)(parsedQuery), curry(_findConditions.findConditions)(parsedQuery), curry(_findJoinClauses.findJoinClauses)(parsedQuery), curry(_findMergeJoins.findMergeJoins)(parsedQuery), curry(_findSortClauses.findSortClauses)(parsedQuery), curry(_findGroupBy.findGroupBy)(parsedQuery), curry(_findLimit.findLimit)(parsedQuery), curry(_findOffset.findOffset)(parsedQuery))(query);
46
+ if (query) {
47
+ throw new Error(`Unrecognized query value: ${query}`);
48
+ }
49
+ return parsedQuery;
50
+ };
51
51
  exports.parseQuery = parseQuery;
@@ -1,8 +1,8 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.removeFromQuery = void 0;
7
- const removeFromQuery = (substring, query) => query.replace(substring, '').trim();
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.removeFromQuery = void 0;
7
+ const removeFromQuery = (substring, query) => query.replace(substring, '').trim();
8
8
  exports.removeFromQuery = removeFromQuery;
@@ -1,23 +1,23 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.splitEntityProperty = void 0;
7
- const entityMatch = /^[a-z0-9_-]+/i;
8
- const propertyMatch = /\.([a-z0-9_-]+)$/i;
9
- const splitEntityProperty = entityProp => {
10
- const entityFound = entityProp.match(entityMatch);
11
- if (!entityFound) {
12
- throw new Error(`Unable to use property: ${entityProp}`);
13
- }
14
- const propFound = entityProp.match(propertyMatch);
15
- if (!propFound) {
16
- throw new Error(`Unable to use property: ${entityProp}`);
17
- }
18
- return {
19
- entity: entityFound[0],
20
- property: propFound[1]
21
- };
22
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.splitEntityProperty = void 0;
7
+ const entityMatch = /^[a-z0-9_-]+/i;
8
+ const propertyMatch = /\.([a-z0-9_-]+)$/i;
9
+ const splitEntityProperty = entityProp => {
10
+ const entityFound = entityProp.match(entityMatch);
11
+ if (!entityFound) {
12
+ throw new Error(`Unable to use property: ${entityProp}`);
13
+ }
14
+ const propFound = entityProp.match(propertyMatch);
15
+ if (!propFound) {
16
+ throw new Error(`Unable to use property: ${entityProp}`);
17
+ }
18
+ return {
19
+ entity: entityFound[0],
20
+ property: propFound[1]
21
+ };
22
+ };
23
23
  exports.splitEntityProperty = splitEntityProperty;
@@ -1,11 +1,11 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.splitQueries = void 0;
7
- require("core-js/modules/esnext.iterator.constructor.js");
8
- require("core-js/modules/esnext.iterator.filter.js");
9
- const queryMatch = /\s*(?=(?:delete|insert|read|update)\s+[a-z0-9._-]+)\s*/i;
10
- const splitQueries = (queries = '') => queries.split(queryMatch).filter(query => query.length > 0);
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.splitQueries = void 0;
7
+ require("core-js/modules/esnext.iterator.constructor.js");
8
+ require("core-js/modules/esnext.iterator.filter.js");
9
+ const queryMatch = /\s*(?=(?:delete|insert|read|update)\s+[a-z0-9._-]+)\s*/i;
10
+ const splitQueries = (queries = '') => queries.split(queryMatch).filter(query => query.length > 0);
11
11
  exports.splitQueries = splitQueries;
@@ -1,26 +1,26 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.reconcileJoin = void 0;
7
- require("core-js/modules/esnext.iterator.constructor.js");
8
- require("core-js/modules/esnext.iterator.for-each.js");
9
- var _where = require("../queries/where");
10
- const reconcileJoin = (dataSet, entityName, entityKey, joinEntity, joinProp) => {
11
- const entity = dataSet[entityName][entityKey];
12
- if (Object.prototype.hasOwnProperty.call(entity, joinEntity) && Array.isArray(entity[joinEntity])) {
13
- entity[joinEntity].forEach((mergedEntity, k) => {
14
- const matchedEntity = (0, _where.where)(dataSet[joinEntity], {
15
- property: joinProp,
16
- comparator: '=',
17
- value: mergedEntity[joinProp]
18
- });
19
- if (matchedEntity.length) {
20
- dataSet[entityName][entityKey][joinEntity][k] = matchedEntity[0];
21
- }
22
- });
23
- }
24
- return dataSet;
25
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.reconcileJoin = void 0;
7
+ require("core-js/modules/esnext.iterator.constructor.js");
8
+ require("core-js/modules/esnext.iterator.for-each.js");
9
+ var _where = require("../queries/where");
10
+ const reconcileJoin = (dataSet, entityName, entityKey, joinEntity, joinProp) => {
11
+ const entity = dataSet[entityName][entityKey];
12
+ if (Object.prototype.hasOwnProperty.call(entity, joinEntity) && Array.isArray(entity[joinEntity])) {
13
+ entity[joinEntity].forEach((mergedEntity, k) => {
14
+ const matchedEntity = (0, _where.where)(dataSet[joinEntity], {
15
+ property: joinProp,
16
+ comparator: '=',
17
+ value: mergedEntity[joinProp]
18
+ });
19
+ if (matchedEntity.length) {
20
+ dataSet[entityName][entityKey][joinEntity][k] = matchedEntity[0];
21
+ }
22
+ });
23
+ }
24
+ return dataSet;
25
+ };
26
26
  exports.reconcileJoin = reconcileJoin;
@@ -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,44 +1,44 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.removeFromIndex = 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
- require("core-js/modules/esnext.iterator.map.js");
11
- var _config = require("./config");
12
- const {
13
- readFile,
14
- writeFile
15
- } = require('fs/promises');
16
- /**
17
- * Remove a single entry file from the index that backs one of a record's keys, dropping a value
18
- * entirely once its last file is removed. A key with no lookup, or an index file that doesn't
19
- * exist yet, is left untouched.
20
- * @param path
21
- * @param key
22
- * @param value
23
- * @param fileName
24
- */
25
- const removeFromIndex = async (path = '', key = null, value = undefined, fileName = '') => {
26
- if (!key || !key.lookup) {
27
- return null;
28
- }
29
- const databasePath = (0, _config.getSetting)('databasePath', 'database/');
30
- const indexPath = `${databasePath}__indexes/${path}/${key.lookup}`;
31
- let index = [];
32
- try {
33
- index = JSON.parse(await readFile(indexPath, 'utf8'));
34
- } catch (err) {
35
- return null;
36
- }
37
- index = index.map(entry => entry.value == value ? {
38
- value: entry.value,
39
- record: entry.record.filter(record => record !== fileName)
40
- } : entry).filter(entry => entry.record.length);
41
- await writeFile(indexPath, JSON.stringify(index, null, 2));
42
- return index;
43
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.removeFromIndex = 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
+ require("core-js/modules/esnext.iterator.map.js");
11
+ var _config = require("./config");
12
+ const {
13
+ readFile,
14
+ writeFile
15
+ } = require('fs/promises');
16
+ /**
17
+ * Remove a single entry file from the index that backs one of a record's keys, dropping a value
18
+ * entirely once its last file is removed. A key with no lookup, or an index file that doesn't
19
+ * exist yet, is left untouched.
20
+ * @param path
21
+ * @param key
22
+ * @param value
23
+ * @param fileName
24
+ */
25
+ const removeFromIndex = async (path = '', key = null, value = undefined, fileName = '') => {
26
+ if (!key || !key.lookup) {
27
+ return null;
28
+ }
29
+ const databasePath = (0, _config.getSetting)('databasePath', 'database/');
30
+ const indexPath = `${databasePath}__indexes/${path}/${key.lookup}`;
31
+ let index = [];
32
+ try {
33
+ index = JSON.parse(await readFile(indexPath, 'utf8'));
34
+ } catch (err) {
35
+ return null;
36
+ }
37
+ index = index.map(entry => entry.value == value ? {
38
+ value: entry.value,
39
+ record: entry.record.filter(record => record !== fileName)
40
+ } : entry).filter(entry => entry.record.length);
41
+ await writeFile(indexPath, JSON.stringify(index, null, 2));
42
+ return index;
43
+ };
44
44
  exports.removeFromIndex = removeFromIndex;