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.
- package/browser/jsonFsQuery.js +10158 -27750
- package/browser/jsonFsQuery.min.js +1 -1
- package/dist/data/introspect/create.d.ts +10 -10
- package/dist/data/introspect/create.js +47 -47
- package/dist/data/introspect/definitions/field.d.ts +27 -27
- package/dist/data/introspect/definitions/field.js +36 -36
- package/dist/data/introspect/definitions/key.d.ts +25 -25
- package/dist/data/introspect/definitions/key.js +53 -53
- package/dist/data/introspect/definitions/keyReference.d.ts +17 -17
- package/dist/data/introspect/definitions/keyReference.js +20 -20
- package/dist/data/introspect/definitions/record.d.ts +25 -25
- package/dist/data/introspect/definitions/record.js +32 -32
- package/dist/data/introspect/describe.js +15 -15
- package/dist/data/introspect/drop.js +37 -37
- package/dist/data/introspect/index.d.ts +7 -7
- package/dist/data/introspect/index.js +30 -30
- package/dist/data/introspect/policies/foreignKeyExists.d.ts +8 -8
- package/dist/data/introspect/policies/foreignKeyExists.js +25 -25
- package/dist/data/introspect/policies/hasDependents.d.ts +12 -12
- package/dist/data/introspect/policies/hasDependents.js +52 -52
- package/dist/data/introspect/policies/keyGenerate.d.ts +1 -1
- package/dist/data/introspect/policies/keyGenerate.js +17 -17
- package/dist/data/introspect/policies/keyUnique.d.ts +9 -9
- package/dist/data/introspect/policies/keyUnique.js +31 -31
- package/dist/data/introspect/policies/typeCheck.d.ts +11 -11
- package/dist/data/introspect/policies/typeCheck.js +57 -57
- package/dist/data/introspect/policies/typeEnum.d.ts +1 -1
- package/dist/data/introspect/policies/typeEnum.js +9 -9
- package/dist/data/introspect/policies/useDefault.d.ts +1 -1
- package/dist/data/introspect/policies/useDefault.js +8 -8
- package/dist/data/queries/deleteEntity.d.ts +1 -1
- package/dist/data/queries/deleteEntity.js +100 -100
- package/dist/data/queries/groupBy.d.ts +1 -1
- package/dist/data/queries/groupBy.js +22 -22
- package/dist/data/queries/insertEntity.d.ts +1 -1
- package/dist/data/queries/insertEntity.js +117 -117
- package/dist/data/queries/joinEntity.d.ts +1 -1
- package/dist/data/queries/joinEntity.js +32 -32
- package/dist/data/queries/joinEntity.min.js +1 -1
- package/dist/data/queries/limitOffset.d.ts +7 -7
- package/dist/data/queries/limitOffset.js +21 -21
- package/dist/data/queries/mergeJoins.d.ts +1 -1
- package/dist/data/queries/mergeJoins.js +19 -19
- package/dist/data/queries/mergeJoins.min.js +1 -1
- package/dist/data/queries/parser.d.ts +1 -1
- package/dist/data/queries/parser.js +19 -19
- package/dist/data/queries/parser.min.js +1 -1
- package/dist/data/queries/query.d.ts +1 -1
- package/dist/data/queries/query.js +18 -18
- package/dist/data/queries/query.min.js +1 -1
- package/dist/data/queries/readEntity.js +14 -14
- package/dist/data/queries/selectFields.d.ts +9 -9
- package/dist/data/queries/selectFields.js +36 -36
- package/dist/data/queries/sortBy.d.ts +1 -1
- package/dist/data/queries/sortBy.js +15 -15
- package/dist/data/queries/sortBy.min.js +1 -1
- package/dist/data/queries/updateEntity.d.ts +1 -1
- package/dist/data/queries/updateEntity.js +190 -190
- package/dist/data/queries/where.d.ts +6 -6
- package/dist/data/queries/where.js +56 -56
- package/dist/data/utilities/computeKeyValue.d.ts +12 -12
- package/dist/data/utilities/computeKeyValue.js +26 -26
- package/dist/data/utilities/config.d.ts +27 -27
- package/dist/data/utilities/config.js +45 -45
- package/dist/data/utilities/deregisterRecord.d.ts +7 -7
- package/dist/data/utilities/deregisterRecord.js +34 -34
- package/dist/data/utilities/getConditionIndexedList.js +47 -47
- package/dist/data/utilities/getConditionIndexedList.min.js +1 -1
- package/dist/data/utilities/getJoinIndexedList.js +76 -76
- package/dist/data/utilities/getJoinIndexedList.min.js +1 -1
- package/dist/data/utilities/getMatchingIndexes.js +28 -28
- package/dist/data/utilities/getMatchingIndexes.min.js +1 -1
- package/dist/data/utilities/matchIndexedJoins.js +61 -61
- package/dist/data/utilities/matchIndexedJoins.min.js +1 -1
- package/dist/data/utilities/mergeJoin.js +44 -44
- package/dist/data/utilities/mergeJoin.min.js +1 -1
- package/dist/data/utilities/parsers/findCommand.d.ts +9 -9
- package/dist/data/utilities/parsers/findCommand.js +25 -25
- package/dist/data/utilities/parsers/findConditions.d.ts +14 -14
- package/dist/data/utilities/parsers/findConditions.js +28 -28
- package/dist/data/utilities/parsers/findConditions.min.js +1 -1
- package/dist/data/utilities/parsers/findGroupBy.d.ts +8 -8
- package/dist/data/utilities/parsers/findGroupBy.js +22 -22
- package/dist/data/utilities/parsers/findInsertValues.d.ts +12 -12
- package/dist/data/utilities/parsers/findInsertValues.js +34 -34
- package/dist/data/utilities/parsers/findJoinClauses.d.ts +12 -12
- package/dist/data/utilities/parsers/findJoinClauses.js +27 -27
- package/dist/data/utilities/parsers/findJoinClauses.min.js +1 -1
- package/dist/data/utilities/parsers/findJoinEntity.d.ts +8 -8
- package/dist/data/utilities/parsers/findJoinEntity.js +22 -22
- package/dist/data/utilities/parsers/findLimit.d.ts +8 -8
- package/dist/data/utilities/parsers/findLimit.js +22 -22
- package/dist/data/utilities/parsers/findMergeJoins.d.ts +11 -11
- package/dist/data/utilities/parsers/findMergeJoins.js +26 -26
- package/dist/data/utilities/parsers/findMergeJoins.min.js +1 -1
- package/dist/data/utilities/parsers/findOffset.d.ts +8 -8
- package/dist/data/utilities/parsers/findOffset.js +22 -22
- package/dist/data/utilities/parsers/findSelects.d.ts +11 -11
- package/dist/data/utilities/parsers/findSelects.js +30 -30
- package/dist/data/utilities/parsers/findSelects.min.js +1 -1
- package/dist/data/utilities/parsers/findSortClauses.d.ts +11 -11
- package/dist/data/utilities/parsers/findSortClauses.js +30 -30
- package/dist/data/utilities/parsers/findSortClauses.min.js +1 -1
- package/dist/data/utilities/parsers/findUpdateValues.d.ts +14 -14
- package/dist/data/utilities/parsers/findUpdateValues.js +34 -34
- package/dist/data/utilities/parsers/isEntityProperty.js +6 -6
- package/dist/data/utilities/parsers/parseLiteralValue.d.ts +11 -11
- package/dist/data/utilities/parsers/parseLiteralValue.js +34 -34
- package/dist/data/utilities/parsers/parseQuery.d.ts +32 -32
- package/dist/data/utilities/parsers/parseQuery.js +51 -51
- package/dist/data/utilities/parsers/parseQuery.min.js +1 -1
- package/dist/data/utilities/parsers/removeFromQuery.js +6 -6
- package/dist/data/utilities/parsers/splitEntityProperty.js +13 -13
- package/dist/data/utilities/parsers/splitQueries.js +9 -9
- package/dist/data/utilities/reconcileJoin.js +26 -26
- package/dist/data/utilities/reconcileJoins.js +26 -26
- package/dist/data/utilities/reconcileJoins.min.js +1 -1
- package/dist/data/utilities/registerRecord.d.ts +7 -7
- package/dist/data/utilities/registerRecord.js +67 -67
- package/dist/data/utilities/removeFromIndex.d.ts +13 -13
- package/dist/data/utilities/removeFromIndex.js +44 -46
- package/dist/data/utilities/restrictIndexedList.js +45 -45
- package/dist/data/utilities/retrieveFile.js +28 -28
- package/dist/data/utilities/retrieveFile.min.js +1 -1
- package/dist/data/utilities/retrieveIndexes.d.ts +1 -1
- package/dist/data/utilities/retrieveIndexes.js +24 -24
- package/dist/data/utilities/retrieveIndexes.min.js +1 -1
- package/dist/data/utilities/retrieveRecord.js +9 -9
- package/dist/data/utilities/retrieveRecords.js +21 -21
- package/dist/data/utilities/retrieveRecords.min.js +1 -1
- package/dist/data/utilities/runQuery.d.ts +1 -1
- package/dist/data/utilities/runQuery.js +87 -87
- package/dist/data/utilities/updateIndex.d.ts +16 -16
- package/dist/data/utilities/updateIndex.js +56 -56
- package/dist/data/utilities/useJoinClause.d.ts +5 -5
- package/dist/data/utilities/useJoinClause.js +51 -51
- package/dist/index.d.ts +4 -4
- package/dist/index.js +42 -42
- package/package.json +9 -5
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.typeEnum = void 0
|
|
7
|
-
require(
|
|
5
|
+
});
|
|
6
|
+
exports.typeEnum = void 0;
|
|
7
|
+
require("core-js/modules/es.array.includes.js");
|
|
8
8
|
const typeEnum = (values = [], value = '', optional = false) => {
|
|
9
9
|
if (values.includes(value)) {
|
|
10
|
-
return true
|
|
10
|
+
return true;
|
|
11
11
|
}
|
|
12
|
-
return typeof value === 'undefined' && optional
|
|
13
|
-
}
|
|
14
|
-
exports.typeEnum = typeEnum
|
|
12
|
+
return typeof value === 'undefined' && optional;
|
|
13
|
+
};
|
|
14
|
+
exports.typeEnum = typeEnum;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useDefault: (defaultValue?: string, value?: any) => any;
|
|
1
|
+
export declare const useDefault: (defaultValue?: string, value?: any) => any;
|
|
2
2
|
//# sourceMappingURL=useDefault.d.ts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.useDefault = void 0
|
|
5
|
+
});
|
|
6
|
+
exports.useDefault = void 0;
|
|
7
7
|
const useDefault = (defaultValue = '', value = undefined) => {
|
|
8
8
|
if (typeof value === 'undefined') {
|
|
9
|
-
return defaultValue
|
|
9
|
+
return defaultValue;
|
|
10
10
|
}
|
|
11
|
-
return value
|
|
12
|
-
}
|
|
13
|
-
exports.useDefault = useDefault
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
13
|
+
exports.useDefault = useDefault;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const deleteEntity: (entity?: string, dataSet?: Object) => Promise<Object>;
|
|
1
|
+
export declare const deleteEntity: (entity?: string, dataSet?: Object) => Promise<Object>;
|
|
2
2
|
//# sourceMappingURL=deleteEntity.d.ts.map
|
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.deleteEntity = void 0
|
|
7
|
-
require(
|
|
8
|
-
require(
|
|
9
|
-
require(
|
|
10
|
-
require(
|
|
11
|
-
require(
|
|
12
|
-
require(
|
|
13
|
-
require(
|
|
14
|
-
require(
|
|
15
|
-
require(
|
|
16
|
-
require(
|
|
17
|
-
require(
|
|
18
|
-
require(
|
|
19
|
-
require(
|
|
20
|
-
require(
|
|
21
|
-
require(
|
|
22
|
-
require(
|
|
23
|
-
require(
|
|
24
|
-
require(
|
|
25
|
-
require(
|
|
26
|
-
require(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const {
|
|
34
|
-
rm,
|
|
35
|
-
writeFile
|
|
36
|
-
} = require('fs/promises')
|
|
37
|
-
/**
|
|
38
|
-
* RESTRICT: reject the whole delete (before removing anything) if any row being deleted is still
|
|
39
|
-
* referenced by a single-field foreign key elsewhere. Only meaningful for a single-field primary
|
|
40
|
-
* key, since foreign key support itself is single-field only - a composite primary key can't be
|
|
41
|
-
* the target of one yet, so there's nothing to check.
|
|
42
|
-
* @param entity
|
|
43
|
-
* @param primaryKey
|
|
44
|
-
* @param toDelete
|
|
45
|
-
*/
|
|
46
|
-
const assertNoDependents = async (entity, primaryKey, toDelete) => {
|
|
47
|
-
if (!(0, _config.getSetting)('enforceForeignKeys', true) || primaryKey.fields.length !== 1) {
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
const property = primaryKey.fields[0]
|
|
51
|
-
for (const row of toDelete) {
|
|
52
|
-
if (await (0, _hasDependents.hasDependents)(entity, property, row[property])) {
|
|
53
|
-
throw new Error(`Cannot delete from "${entity}" where "${property}" = ${row[property]} - other records still reference it`)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* A record object carries no memory of which entry file it was read from, and files are not
|
|
59
|
-
* guaranteed to be named after any field's value, so the only reliable way to find a record's
|
|
60
|
-
* file is to re-scan every entry and match it by its primary key value(s) - a single field, or a
|
|
61
|
-
* composite of several for a multi-field primary key.
|
|
62
|
-
* @param entity
|
|
63
|
-
* @param record
|
|
64
|
-
* @param primaryKey
|
|
65
|
-
* @param deletedValues
|
|
66
|
-
*/
|
|
67
|
-
const removeMatchingEntries = async (entity, record, primaryKey, deletedValues) => {
|
|
68
|
-
const databasePath = (0, _config.getSetting)('databasePath', 'database/')
|
|
69
|
-
const remainingEntries = []
|
|
70
|
-
for (const fileName of record.entries) {
|
|
71
|
-
const data = await (0, _retrieveFile.retrieveFile)(`${record.path}/${fileName}`)
|
|
72
|
-
if (!deletedValues.has((0, _computeKeyValue.computeKeyValue)(primaryKey.fields, data))) {
|
|
73
|
-
remainingEntries.push(fileName)
|
|
74
|
-
continue
|
|
75
|
-
}
|
|
76
|
-
await rm(`${databasePath}${record.path}/${fileName}`)
|
|
77
|
-
for (const key of record.keys) {
|
|
78
|
-
await (0, _removeFromIndex.removeFromIndex)(record.path, key, (0, _computeKeyValue.computeKeyValue)(key.fields, data), fileName)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return remainingEntries
|
|
82
|
-
}
|
|
83
|
-
const deleteEntity = async (entity = '', dataSet = {}) => {
|
|
84
|
-
const databasePath = (0, _config.getSetting)('databasePath', 'database/')
|
|
85
|
-
const record = await (0, _retrieveRecord.retrieveRecord)(entity)
|
|
86
|
-
const primaryKey = record.keys.find(key => key.type === 'primary')
|
|
87
|
-
if (!primaryKey) {
|
|
88
|
-
throw new Error(`Cannot delete from "${entity}" without a primary key`)
|
|
89
|
-
}
|
|
90
|
-
const toDelete = dataSet[entity] || []
|
|
91
|
-
if (!toDelete.length) {
|
|
92
|
-
return dataSet
|
|
93
|
-
}
|
|
94
|
-
await assertNoDependents(entity, primaryKey, toDelete)
|
|
95
|
-
const deletedValues = new Set(toDelete.map(row => (0, _computeKeyValue.computeKeyValue)(primaryKey.fields, row)))
|
|
96
|
-
record.entries = await removeMatchingEntries(entity, record, primaryKey, deletedValues)
|
|
97
|
-
await writeFile(`${databasePath}${record.path}.json`, JSON.stringify(record, null, 2))
|
|
98
|
-
return dataSet
|
|
99
|
-
}
|
|
100
|
-
exports.deleteEntity = deleteEntity
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.deleteEntity = 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.find.js");
|
|
10
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
11
|
+
require("core-js/modules/esnext.set.add-all.js");
|
|
12
|
+
require("core-js/modules/esnext.set.delete-all.js");
|
|
13
|
+
require("core-js/modules/esnext.set.difference.js");
|
|
14
|
+
require("core-js/modules/esnext.set.every.js");
|
|
15
|
+
require("core-js/modules/esnext.set.filter.js");
|
|
16
|
+
require("core-js/modules/esnext.set.find.js");
|
|
17
|
+
require("core-js/modules/esnext.set.intersection.js");
|
|
18
|
+
require("core-js/modules/esnext.set.is-disjoint-from.js");
|
|
19
|
+
require("core-js/modules/esnext.set.is-subset-of.js");
|
|
20
|
+
require("core-js/modules/esnext.set.is-superset-of.js");
|
|
21
|
+
require("core-js/modules/esnext.set.join.js");
|
|
22
|
+
require("core-js/modules/esnext.set.map.js");
|
|
23
|
+
require("core-js/modules/esnext.set.reduce.js");
|
|
24
|
+
require("core-js/modules/esnext.set.some.js");
|
|
25
|
+
require("core-js/modules/esnext.set.symmetric-difference.js");
|
|
26
|
+
require("core-js/modules/esnext.set.union.js");
|
|
27
|
+
var _retrieveRecord = require("../utilities/retrieveRecord");
|
|
28
|
+
var _retrieveFile = require("../utilities/retrieveFile");
|
|
29
|
+
var _removeFromIndex = require("../utilities/removeFromIndex");
|
|
30
|
+
var _computeKeyValue = require("../utilities/computeKeyValue");
|
|
31
|
+
var _hasDependents = require("../introspect/policies/hasDependents");
|
|
32
|
+
var _config = require("../utilities/config");
|
|
33
|
+
const {
|
|
34
|
+
rm,
|
|
35
|
+
writeFile
|
|
36
|
+
} = require('fs/promises');
|
|
37
|
+
/**
|
|
38
|
+
* RESTRICT: reject the whole delete (before removing anything) if any row being deleted is still
|
|
39
|
+
* referenced by a single-field foreign key elsewhere. Only meaningful for a single-field primary
|
|
40
|
+
* key, since foreign key support itself is single-field only - a composite primary key can't be
|
|
41
|
+
* the target of one yet, so there's nothing to check.
|
|
42
|
+
* @param entity
|
|
43
|
+
* @param primaryKey
|
|
44
|
+
* @param toDelete
|
|
45
|
+
*/
|
|
46
|
+
const assertNoDependents = async (entity, primaryKey, toDelete) => {
|
|
47
|
+
if (!(0, _config.getSetting)('enforceForeignKeys', true) || primaryKey.fields.length !== 1) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const property = primaryKey.fields[0];
|
|
51
|
+
for (const row of toDelete) {
|
|
52
|
+
if (await (0, _hasDependents.hasDependents)(entity, property, row[property])) {
|
|
53
|
+
throw new Error(`Cannot delete from "${entity}" where "${property}" = ${row[property]} - other records still reference it`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* A record object carries no memory of which entry file it was read from, and files are not
|
|
59
|
+
* guaranteed to be named after any field's value, so the only reliable way to find a record's
|
|
60
|
+
* file is to re-scan every entry and match it by its primary key value(s) - a single field, or a
|
|
61
|
+
* composite of several for a multi-field primary key.
|
|
62
|
+
* @param entity
|
|
63
|
+
* @param record
|
|
64
|
+
* @param primaryKey
|
|
65
|
+
* @param deletedValues
|
|
66
|
+
*/
|
|
67
|
+
const removeMatchingEntries = async (entity, record, primaryKey, deletedValues) => {
|
|
68
|
+
const databasePath = (0, _config.getSetting)('databasePath', 'database/');
|
|
69
|
+
const remainingEntries = [];
|
|
70
|
+
for (const fileName of record.entries) {
|
|
71
|
+
const data = await (0, _retrieveFile.retrieveFile)(`${record.path}/${fileName}`);
|
|
72
|
+
if (!deletedValues.has((0, _computeKeyValue.computeKeyValue)(primaryKey.fields, data))) {
|
|
73
|
+
remainingEntries.push(fileName);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
await rm(`${databasePath}${record.path}/${fileName}`);
|
|
77
|
+
for (const key of record.keys) {
|
|
78
|
+
await (0, _removeFromIndex.removeFromIndex)(record.path, key, (0, _computeKeyValue.computeKeyValue)(key.fields, data), fileName);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return remainingEntries;
|
|
82
|
+
};
|
|
83
|
+
const deleteEntity = async (entity = '', dataSet = {}) => {
|
|
84
|
+
const databasePath = (0, _config.getSetting)('databasePath', 'database/');
|
|
85
|
+
const record = await (0, _retrieveRecord.retrieveRecord)(entity);
|
|
86
|
+
const primaryKey = record.keys.find(key => key.type === 'primary');
|
|
87
|
+
if (!primaryKey) {
|
|
88
|
+
throw new Error(`Cannot delete from "${entity}" without a primary key`);
|
|
89
|
+
}
|
|
90
|
+
const toDelete = dataSet[entity] || [];
|
|
91
|
+
if (!toDelete.length) {
|
|
92
|
+
return dataSet;
|
|
93
|
+
}
|
|
94
|
+
await assertNoDependents(entity, primaryKey, toDelete);
|
|
95
|
+
const deletedValues = new Set(toDelete.map(row => (0, _computeKeyValue.computeKeyValue)(primaryKey.fields, row)));
|
|
96
|
+
record.entries = await removeMatchingEntries(entity, record, primaryKey, deletedValues);
|
|
97
|
+
await writeFile(`${databasePath}${record.path}.json`, JSON.stringify(record, null, 2));
|
|
98
|
+
return dataSet;
|
|
99
|
+
};
|
|
100
|
+
exports.deleteEntity = deleteEntity;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const groupBy: (dataSet?: any[], groupProperty?: string) => any;
|
|
1
|
+
export declare const groupBy: (dataSet?: any[], groupProperty?: string) => any;
|
|
2
2
|
//# sourceMappingURL=groupBy.d.ts.map
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.groupBy = void 0
|
|
7
|
-
require(
|
|
8
|
-
require(
|
|
9
|
-
const groupBy = (dataSet = [], groupProperty = '') => {
|
|
10
|
-
if (!groupProperty) {
|
|
11
|
-
return dataSet
|
|
12
|
-
}
|
|
13
|
-
return dataSet.reduce((groupedData, data) => {
|
|
14
|
-
const property = data[groupProperty]
|
|
15
|
-
if (!Object.prototype.hasOwnProperty.call(groupedData, property)) {
|
|
16
|
-
groupedData[property] = []
|
|
17
|
-
}
|
|
18
|
-
groupedData[property].push(data)
|
|
19
|
-
return groupedData
|
|
20
|
-
}, {})
|
|
21
|
-
}
|
|
22
|
-
exports.groupBy = groupBy
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.groupBy = void 0;
|
|
7
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.reduce.js");
|
|
9
|
+
const groupBy = (dataSet = [], groupProperty = '') => {
|
|
10
|
+
if (!groupProperty) {
|
|
11
|
+
return dataSet;
|
|
12
|
+
}
|
|
13
|
+
return dataSet.reduce((groupedData, data) => {
|
|
14
|
+
const property = data[groupProperty];
|
|
15
|
+
if (!Object.prototype.hasOwnProperty.call(groupedData, property)) {
|
|
16
|
+
groupedData[property] = [];
|
|
17
|
+
}
|
|
18
|
+
groupedData[property].push(data);
|
|
19
|
+
return groupedData;
|
|
20
|
+
}, {});
|
|
21
|
+
};
|
|
22
|
+
exports.groupBy = groupBy;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const insertEntity: (entity?: string, values?: Object[], dataSet?: Object) => Promise<Object>;
|
|
1
|
+
export declare const insertEntity: (entity?: string, values?: Object[], dataSet?: Object) => Promise<Object>;
|
|
2
2
|
//# sourceMappingURL=insertEntity.d.ts.map
|
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.insertEntity = void 0
|
|
7
|
-
require(
|
|
8
|
-
require(
|
|
9
|
-
require(
|
|
10
|
-
require(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const {
|
|
22
|
-
writeFile
|
|
23
|
-
} = require('fs/promises')
|
|
24
|
-
/**
|
|
25
|
-
* Build one entity's stored values from the raw input values, generating any autoGenerate
|
|
26
|
-
* fields and applying field defaults, then throw if a required field still has no value.
|
|
27
|
-
* @param entity
|
|
28
|
-
* @param record
|
|
29
|
-
* @param rowValues
|
|
30
|
-
*/
|
|
31
|
-
const buildEntityValues = async (entity, record, rowValues = {}) => {
|
|
32
|
-
const entityValues = {}
|
|
33
|
-
for (const field of record.definition) {
|
|
34
|
-
let value = rowValues[field.name]
|
|
35
|
-
if (field.autoGenerate) {
|
|
36
|
-
value = await (0, _keyGenerate.keyGenerate)(entity, [field.name])
|
|
37
|
-
} else if (Object.prototype.hasOwnProperty.call(field, 'default')) {
|
|
38
|
-
value = (0, _useDefault.useDefault)(field
|
|
39
|
-
}
|
|
40
|
-
if (typeof value === 'undefined') {
|
|
41
|
-
if (!field.optional) {
|
|
42
|
-
throw new Error(`Missing required field "${field.name}" for ${entity}`)
|
|
43
|
-
}
|
|
44
|
-
continue
|
|
45
|
-
}
|
|
46
|
-
entityValues[field.name] = (0, _typeCheck.typeCheck)(field.type, value)
|
|
47
|
-
}
|
|
48
|
-
return entityValues
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Reject the insert if it collides with an existing primary or unique key value - a single field,
|
|
52
|
-
* or a composite of several for a multi-field key.
|
|
53
|
-
* @param entity
|
|
54
|
-
* @param record
|
|
55
|
-
* @param entityValues
|
|
56
|
-
*/
|
|
57
|
-
const assertUnique = async (entity, record, entityValues) => {
|
|
58
|
-
for (const key of record.keys) {
|
|
59
|
-
if (key.type !== 'primary' && key.type !== 'unique') {
|
|
60
|
-
continue
|
|
61
|
-
}
|
|
62
|
-
const checkKeys = key.fields.map(field => entityValues[field])
|
|
63
|
-
const isUnique = await (0, _keyUnique.keyUnique)(entity, key.fields, checkKeys)
|
|
64
|
-
if (!isUnique) {
|
|
65
|
-
throw new Error(`Duplicate value for ${key.type} key "${key.fields.join(', ')}" on ${entity}`)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Reject the insert if a single-field foreign key's value doesn't exist in the record it
|
|
71
|
-
* references.
|
|
72
|
-
* @param entity
|
|
73
|
-
* @param record
|
|
74
|
-
* @param entityValues
|
|
75
|
-
*/
|
|
76
|
-
const assertForeignKeys = async (entity, record, entityValues) => {
|
|
77
|
-
for (const key of record.keys) {
|
|
78
|
-
if (key.type !== 'foreign' || key.fields.length !== 1 || !key.references || key.references.length !== 1) {
|
|
79
|
-
continue
|
|
80
|
-
}
|
|
81
|
-
const field = key.fields[0]
|
|
82
|
-
if (!Object.prototype.hasOwnProperty.call(entityValues, field)) {
|
|
83
|
-
continue
|
|
84
|
-
}
|
|
85
|
-
const {
|
|
86
|
-
entity: refEntity,
|
|
87
|
-
property: refProperty
|
|
88
|
-
} = (0, _splitEntityProperty.splitEntityProperty)(key.references[0].fields[0])
|
|
89
|
-
const exists = await (0, _foreignKeyExists.foreignKeyExists)(refEntity, refProperty, entityValues[field])
|
|
90
|
-
if (!exists) {
|
|
91
|
-
throw new Error(`Foreign key "${field}" on ${entity} references a nonexistent ${refEntity}.${refProperty} = ${entityValues[field]}`)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const insertEntity = async (entity = '', values = [], dataSet = {}) => {
|
|
96
|
-
const databasePath = (0, _config.getSetting)('databasePath', 'database/')
|
|
97
|
-
const record = await (0, _retrieveRecord.retrieveRecord)(entity)
|
|
98
|
-
const primaryKey = record.keys.find(key => key.type === 'primary' && key.fields.length === 1)
|
|
99
|
-
if (!Object.prototype.hasOwnProperty.call(dataSet, entity)) {
|
|
100
|
-
dataSet[entity] = []
|
|
101
|
-
}
|
|
102
|
-
for (const rowValues of values) {
|
|
103
|
-
const entityValues = await buildEntityValues(entity, record, rowValues)
|
|
104
|
-
await assertUnique(entity, record, entityValues)
|
|
105
|
-
await assertForeignKeys(entity, record, entityValues)
|
|
106
|
-
const fileName = `${primaryKey ? entityValues[primaryKey.fields[0]] : crypto.randomUUID()}.json
|
|
107
|
-
await writeFile(`${databasePath}${record.path}/${fileName}`, JSON.stringify(entityValues, null, 2))
|
|
108
|
-
record.entries.push(fileName)
|
|
109
|
-
await writeFile(`${databasePath}${record.path}.json`, JSON.stringify(record, null, 2))
|
|
110
|
-
for (const key of record.keys) {
|
|
111
|
-
await (0, _updateIndex.updateIndex)(record.path, key, (0, _computeKeyValue.computeKeyValue)(key.fields, entityValues), fileName)
|
|
112
|
-
}
|
|
113
|
-
dataSet[entity].push(entityValues)
|
|
114
|
-
}
|
|
115
|
-
return dataSet
|
|
116
|
-
}
|
|
117
|
-
exports.insertEntity = insertEntity
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.insertEntity = 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.find.js");
|
|
10
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
11
|
+
var _retrieveRecord = require("../utilities/retrieveRecord");
|
|
12
|
+
var _updateIndex = require("../utilities/updateIndex");
|
|
13
|
+
var _keyGenerate = require("../introspect/policies/keyGenerate");
|
|
14
|
+
var _keyUnique = require("../introspect/policies/keyUnique");
|
|
15
|
+
var _useDefault = require("../introspect/policies/useDefault");
|
|
16
|
+
var _typeCheck = require("../introspect/policies/typeCheck");
|
|
17
|
+
var _foreignKeyExists = require("../introspect/policies/foreignKeyExists");
|
|
18
|
+
var _splitEntityProperty = require("../utilities/parsers/splitEntityProperty");
|
|
19
|
+
var _computeKeyValue = require("../utilities/computeKeyValue");
|
|
20
|
+
var _config = require("../utilities/config");
|
|
21
|
+
const {
|
|
22
|
+
writeFile
|
|
23
|
+
} = require('fs/promises');
|
|
24
|
+
/**
|
|
25
|
+
* Build one entity's stored values from the raw input values, generating any autoGenerate
|
|
26
|
+
* fields and applying field defaults, then throw if a required field still has no value.
|
|
27
|
+
* @param entity
|
|
28
|
+
* @param record
|
|
29
|
+
* @param rowValues
|
|
30
|
+
*/
|
|
31
|
+
const buildEntityValues = async (entity, record, rowValues = {}) => {
|
|
32
|
+
const entityValues = {};
|
|
33
|
+
for (const field of record.definition) {
|
|
34
|
+
let value = rowValues[field.name];
|
|
35
|
+
if (field.autoGenerate) {
|
|
36
|
+
value = await (0, _keyGenerate.keyGenerate)(entity, [field.name]);
|
|
37
|
+
} else if (Object.prototype.hasOwnProperty.call(field, 'default')) {
|
|
38
|
+
value = (0, _useDefault.useDefault)(field['default'], value);
|
|
39
|
+
}
|
|
40
|
+
if (typeof value === 'undefined') {
|
|
41
|
+
if (!field.optional) {
|
|
42
|
+
throw new Error(`Missing required field "${field.name}" for ${entity}`);
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
entityValues[field.name] = (0, _typeCheck.typeCheck)(field.type, value);
|
|
47
|
+
}
|
|
48
|
+
return entityValues;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Reject the insert if it collides with an existing primary or unique key value - a single field,
|
|
52
|
+
* or a composite of several for a multi-field key.
|
|
53
|
+
* @param entity
|
|
54
|
+
* @param record
|
|
55
|
+
* @param entityValues
|
|
56
|
+
*/
|
|
57
|
+
const assertUnique = async (entity, record, entityValues) => {
|
|
58
|
+
for (const key of record.keys) {
|
|
59
|
+
if (key.type !== 'primary' && key.type !== 'unique') {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const checkKeys = key.fields.map(field => entityValues[field]);
|
|
63
|
+
const isUnique = await (0, _keyUnique.keyUnique)(entity, key.fields, checkKeys);
|
|
64
|
+
if (!isUnique) {
|
|
65
|
+
throw new Error(`Duplicate value for ${key.type} key "${key.fields.join(', ')}" on ${entity}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Reject the insert if a single-field foreign key's value doesn't exist in the record it
|
|
71
|
+
* references.
|
|
72
|
+
* @param entity
|
|
73
|
+
* @param record
|
|
74
|
+
* @param entityValues
|
|
75
|
+
*/
|
|
76
|
+
const assertForeignKeys = async (entity, record, entityValues) => {
|
|
77
|
+
for (const key of record.keys) {
|
|
78
|
+
if (key.type !== 'foreign' || key.fields.length !== 1 || !key.references || key.references.length !== 1) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const field = key.fields[0];
|
|
82
|
+
if (!Object.prototype.hasOwnProperty.call(entityValues, field)) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const {
|
|
86
|
+
entity: refEntity,
|
|
87
|
+
property: refProperty
|
|
88
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(key.references[0].fields[0]);
|
|
89
|
+
const exists = await (0, _foreignKeyExists.foreignKeyExists)(refEntity, refProperty, entityValues[field]);
|
|
90
|
+
if (!exists) {
|
|
91
|
+
throw new Error(`Foreign key "${field}" on ${entity} references a nonexistent ${refEntity}.${refProperty} = ${entityValues[field]}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const insertEntity = async (entity = '', values = [], dataSet = {}) => {
|
|
96
|
+
const databasePath = (0, _config.getSetting)('databasePath', 'database/');
|
|
97
|
+
const record = await (0, _retrieveRecord.retrieveRecord)(entity);
|
|
98
|
+
const primaryKey = record.keys.find(key => key.type === 'primary' && key.fields.length === 1);
|
|
99
|
+
if (!Object.prototype.hasOwnProperty.call(dataSet, entity)) {
|
|
100
|
+
dataSet[entity] = [];
|
|
101
|
+
}
|
|
102
|
+
for (const rowValues of values) {
|
|
103
|
+
const entityValues = await buildEntityValues(entity, record, rowValues);
|
|
104
|
+
await assertUnique(entity, record, entityValues);
|
|
105
|
+
await assertForeignKeys(entity, record, entityValues);
|
|
106
|
+
const fileName = `${primaryKey ? entityValues[primaryKey.fields[0]] : crypto.randomUUID()}.json`;
|
|
107
|
+
await writeFile(`${databasePath}${record.path}/${fileName}`, JSON.stringify(entityValues, null, 2));
|
|
108
|
+
record.entries.push(fileName);
|
|
109
|
+
await writeFile(`${databasePath}${record.path}.json`, JSON.stringify(record, null, 2));
|
|
110
|
+
for (const key of record.keys) {
|
|
111
|
+
await (0, _updateIndex.updateIndex)(record.path, key, (0, _computeKeyValue.computeKeyValue)(key.fields, entityValues), fileName);
|
|
112
|
+
}
|
|
113
|
+
dataSet[entity].push(entityValues);
|
|
114
|
+
}
|
|
115
|
+
return dataSet;
|
|
116
|
+
};
|
|
117
|
+
exports.insertEntity = insertEntity;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const joinEntity: (entity: any, joinEntity: any, dataSets?: {}, joinClauses?: any[], entityAlreadyResolved?: boolean) => Promise<{}>;
|
|
1
|
+
export declare const joinEntity: (entity: any, joinEntity: any, dataSets?: {}, joinClauses?: any[], entityAlreadyResolved?: boolean) => Promise<{}>;
|
|
2
2
|
//# sourceMappingURL=joinEntity.d.ts.map
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.joinEntity = void 0
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault
|
|
11
|
-
const joinEntity = async (entity, joinEntity, dataSets = {}, joinClauses = [], entityAlreadyResolved = false) => {
|
|
12
|
-
// Same ambiguity readEntity() always has (can't tell "never loaded" from "loaded, zero rows
|
|
13
|
-
// matched") - runQuery already resolved entity's rows via an indexed condition in that second
|
|
14
|
-
// case, so entityAlreadyResolved tells this call not to reload and silently discard that result.
|
|
15
|
-
if (!entityAlreadyResolved) {
|
|
16
|
-
dataSets = await (0, _readEntity.readEntity)(entity, dataSets)
|
|
17
|
-
}
|
|
18
|
-
if (!joinClauses.length) {
|
|
19
|
-
return dataSets
|
|
20
|
-
}
|
|
21
|
-
dataSets = await (0, _readEntity.readEntity)(joinEntity, dataSets)
|
|
22
|
-
for (const anEntity in dataSets[entity]) {
|
|
23
|
-
let filterJoins = _siFunciona.default.cloneObject(dataSets)
|
|
24
|
-
filterJoins[entity] = [dataSets[entity][anEntity]]
|
|
25
|
-
for (const joinClause of joinClauses) {
|
|
26
|
-
filterJoins = await (0, _useJoinClause.useJoinClause)(joinClause, dataSets, filterJoins)
|
|
27
|
-
}
|
|
28
|
-
dataSets[entity][anEntity][joinEntity] = filterJoins[joinEntity]
|
|
29
|
-
}
|
|
30
|
-
return dataSets
|
|
31
|
-
}
|
|
32
|
-
exports.joinEntity = joinEntity
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.joinEntity = void 0;
|
|
7
|
+
var _siFunciona = _interopRequireDefault(require("si-funciona"));
|
|
8
|
+
var _readEntity = require("./readEntity");
|
|
9
|
+
var _useJoinClause = require("../utilities/useJoinClause");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
const joinEntity = async (entity, joinEntity, dataSets = {}, joinClauses = [], entityAlreadyResolved = false) => {
|
|
12
|
+
// Same ambiguity readEntity() always has (can't tell "never loaded" from "loaded, zero rows
|
|
13
|
+
// matched") - runQuery already resolved entity's rows via an indexed condition in that second
|
|
14
|
+
// case, so entityAlreadyResolved tells this call not to reload and silently discard that result.
|
|
15
|
+
if (!entityAlreadyResolved) {
|
|
16
|
+
dataSets = await (0, _readEntity.readEntity)(entity, dataSets);
|
|
17
|
+
}
|
|
18
|
+
if (!joinClauses.length) {
|
|
19
|
+
return dataSets;
|
|
20
|
+
}
|
|
21
|
+
dataSets = await (0, _readEntity.readEntity)(joinEntity, dataSets);
|
|
22
|
+
for (const anEntity in dataSets[entity]) {
|
|
23
|
+
let filterJoins = _siFunciona.default.cloneObject(dataSets);
|
|
24
|
+
filterJoins[entity] = [dataSets[entity][anEntity]];
|
|
25
|
+
for (const joinClause of joinClauses) {
|
|
26
|
+
filterJoins = await (0, _useJoinClause.useJoinClause)(joinClause, dataSets, filterJoins);
|
|
27
|
+
}
|
|
28
|
+
dataSets[entity][anEntity][joinEntity] = filterJoins[joinEntity];
|
|
29
|
+
}
|
|
30
|
+
return dataSets;
|
|
31
|
+
};
|
|
32
|
+
exports.joinEntity = joinEntity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.joinEntity=void 0;var _siFunciona=_interopRequireDefault(require("si-funciona")),_readEntity=require("./readEntity"),_useJoinClause=require("../utilities/useJoinClause");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const joinEntity=async(e,t,i={},n=[],r=!1)=>{if(r||(i=await(0,_readEntity.readEntity)(e,i)),!n.length)return i;i=await(0,_readEntity.readEntity)(t,i);for(const r in i[e]){let u=_siFunciona.default.cloneObject(i);u[e]=[i[e][r]];for(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.joinEntity=void 0;var _siFunciona=_interopRequireDefault(require("si-funciona")),_readEntity=require("./readEntity"),_useJoinClause=require("../utilities/useJoinClause");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const joinEntity=async(e,t,i={},n=[],r=!1)=>{if(r||(i=await(0,_readEntity.readEntity)(e,i)),!n.length)return i;i=await(0,_readEntity.readEntity)(t,i);for(const r in i[e]){let u=_siFunciona.default.cloneObject(i);u[e]=[i[e][r]];for(const e of n)u=await(0,_useJoinClause.useJoinClause)(e,i,u);i[e][r][t]=u[t]}return i};exports.joinEntity=joinEntity;
|