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.
- package/browser/jsonFsQuery.js +2 -2
- package/browser/jsonFsQuery.min.js +1 -1
- package/dist/data/introspect/create.js +46 -46
- package/dist/data/introspect/definitions/field.js +35 -35
- package/dist/data/introspect/definitions/key.js +52 -52
- package/dist/data/introspect/definitions/keyReference.js +19 -19
- package/dist/data/introspect/definitions/record.js +31 -31
- package/dist/data/introspect/describe.js +14 -14
- package/dist/data/introspect/drop.js +36 -36
- package/dist/data/introspect/index.js +29 -29
- package/dist/data/introspect/policies/foreignKeyExists.js +24 -24
- package/dist/data/introspect/policies/hasDependents.js +51 -51
- package/dist/data/introspect/policies/keyGenerate.js +16 -16
- package/dist/data/introspect/policies/keyUnique.js +30 -30
- package/dist/data/introspect/policies/typeCheck.js +56 -56
- package/dist/data/introspect/policies/typeEnum.js +13 -13
- package/dist/data/introspect/policies/useDefault.js +12 -12
- package/dist/data/queries/deleteEntity.js +99 -99
- package/dist/data/queries/groupBy.js +21 -21
- package/dist/data/queries/insertEntity.js +116 -116
- package/dist/data/queries/joinEntity.js +31 -31
- package/dist/data/queries/limitOffset.js +20 -20
- package/dist/data/queries/mergeJoins.js +18 -18
- package/dist/data/queries/parser.js +29 -29
- package/dist/data/queries/query.js +17 -17
- package/dist/data/queries/readEntity.js +13 -13
- package/dist/data/queries/selectFields.js +35 -35
- package/dist/data/queries/sortBy.js +24 -24
- package/dist/data/queries/updateEntity.js +189 -189
- package/dist/data/queries/where.js +55 -55
- package/dist/data/utilities/computeKeyValue.js +25 -25
- package/dist/data/utilities/config.js +44 -44
- package/dist/data/utilities/deregisterRecord.js +33 -33
- package/dist/data/utilities/getConditionIndexedList.js +46 -46
- package/dist/data/utilities/getJoinIndexedList.js +75 -75
- package/dist/data/utilities/getMatchingIndexes.js +27 -27
- package/dist/data/utilities/matchIndexedJoins.js +60 -60
- package/dist/data/utilities/mergeJoin.js +43 -43
- package/dist/data/utilities/parsers/findCommand.js +24 -24
- package/dist/data/utilities/parsers/findConditions.js +27 -27
- package/dist/data/utilities/parsers/findGroupBy.js +21 -21
- package/dist/data/utilities/parsers/findInsertValues.js +33 -33
- package/dist/data/utilities/parsers/findJoinClauses.js +26 -26
- package/dist/data/utilities/parsers/findJoinEntity.js +21 -21
- package/dist/data/utilities/parsers/findLimit.js +21 -21
- package/dist/data/utilities/parsers/findMergeJoins.js +25 -25
- package/dist/data/utilities/parsers/findOffset.js +21 -21
- package/dist/data/utilities/parsers/findSelects.js +29 -29
- package/dist/data/utilities/parsers/findSortClauses.js +29 -29
- package/dist/data/utilities/parsers/findUpdateValues.js +33 -33
- package/dist/data/utilities/parsers/isEntityProperty.js +7 -7
- package/dist/data/utilities/parsers/parseLiteralValue.js +33 -33
- package/dist/data/utilities/parsers/parseQuery.js +50 -50
- package/dist/data/utilities/parsers/removeFromQuery.js +7 -7
- package/dist/data/utilities/parsers/splitEntityProperty.js +22 -22
- package/dist/data/utilities/parsers/splitQueries.js +10 -10
- package/dist/data/utilities/reconcileJoin.js +25 -25
- package/dist/data/utilities/reconcileJoins.js +25 -25
- package/dist/data/utilities/registerRecord.js +66 -66
- package/dist/data/utilities/removeFromIndex.js +43 -43
- package/dist/data/utilities/restrictIndexedList.js +44 -44
- package/dist/data/utilities/retrieveFile.js +27 -27
- package/dist/data/utilities/retrieveIndexes.js +23 -23
- package/dist/data/utilities/retrieveRecord.js +8 -8
- package/dist/data/utilities/retrieveRecords.js +20 -20
- package/dist/data/utilities/runQuery.js +86 -86
- package/dist/data/utilities/updateIndex.js +55 -55
- package/dist/data/utilities/useJoinClause.js +50 -50
- package/dist/index.js +41 -41
- package/package.json +9 -5
|
@@ -1,117 +1,117 @@
|
|
|
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
|
-
};
|
|
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
117
|
exports.insertEntity = insertEntity;
|
|
@@ -1,32 +1,32 @@
|
|
|
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
|
-
};
|
|
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
32
|
exports.joinEntity = joinEntity;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.limitOffset = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Slice a dataSet down to at most `limit` rows, starting after the first `offset` of them.
|
|
9
|
-
* @param dataSet
|
|
10
|
-
* @param offset
|
|
11
|
-
* @param limit
|
|
12
|
-
*/
|
|
13
|
-
const limitOffset = (dataSet = [], offset, limit) => {
|
|
14
|
-
if (typeof offset === 'undefined' && typeof limit === 'undefined') {
|
|
15
|
-
return dataSet;
|
|
16
|
-
}
|
|
17
|
-
const start = offset ?? 0;
|
|
18
|
-
const end = typeof limit === 'number' ? start + limit : undefined;
|
|
19
|
-
return dataSet.slice(start, end);
|
|
20
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.limitOffset = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Slice a dataSet down to at most `limit` rows, starting after the first `offset` of them.
|
|
9
|
+
* @param dataSet
|
|
10
|
+
* @param offset
|
|
11
|
+
* @param limit
|
|
12
|
+
*/
|
|
13
|
+
const limitOffset = (dataSet = [], offset, limit) => {
|
|
14
|
+
if (typeof offset === 'undefined' && typeof limit === 'undefined') {
|
|
15
|
+
return dataSet;
|
|
16
|
+
}
|
|
17
|
+
const start = offset ?? 0;
|
|
18
|
+
const end = typeof limit === 'number' ? start + limit : undefined;
|
|
19
|
+
return dataSet.slice(start, end);
|
|
20
|
+
};
|
|
21
21
|
exports.limitOffset = limitOffset;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.mergeJoins = void 0;
|
|
7
|
-
var _mergeJoin = require("../utilities/mergeJoin");
|
|
8
|
-
var _reconcileJoins = require("../utilities/reconcileJoins");
|
|
9
|
-
const mergeJoins = async (dataSet = {}, merges = []) => {
|
|
10
|
-
if (!merges.length) {
|
|
11
|
-
return dataSet;
|
|
12
|
-
}
|
|
13
|
-
for (const merge of merges) {
|
|
14
|
-
dataSet = await (0, _mergeJoin.mergeJoin)(merge.propertyA, merge.propertyB, dataSet);
|
|
15
|
-
dataSet = (0, _reconcileJoins.reconcileJoins)(merge.propertyA, merge.propertyB, dataSet);
|
|
16
|
-
}
|
|
17
|
-
return dataSet;
|
|
18
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mergeJoins = void 0;
|
|
7
|
+
var _mergeJoin = require("../utilities/mergeJoin");
|
|
8
|
+
var _reconcileJoins = require("../utilities/reconcileJoins");
|
|
9
|
+
const mergeJoins = async (dataSet = {}, merges = []) => {
|
|
10
|
+
if (!merges.length) {
|
|
11
|
+
return dataSet;
|
|
12
|
+
}
|
|
13
|
+
for (const merge of merges) {
|
|
14
|
+
dataSet = await (0, _mergeJoin.mergeJoin)(merge.propertyA, merge.propertyB, dataSet);
|
|
15
|
+
dataSet = (0, _reconcileJoins.reconcileJoins)(merge.propertyA, merge.propertyB, dataSet);
|
|
16
|
+
}
|
|
17
|
+
return dataSet;
|
|
18
|
+
};
|
|
19
19
|
exports.mergeJoins = mergeJoins;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parser = void 0;
|
|
7
|
-
var _splitQueries = require("../utilities/parsers/splitQueries");
|
|
8
|
-
var _parseQuery = require("../utilities/parsers/parseQuery");
|
|
9
|
-
const parser = (queries = '') => {
|
|
10
|
-
const queryArray = (0, _splitQueries.splitQueries)(queries);
|
|
11
|
-
const parsedQueries = [];
|
|
12
|
-
let mergeQuery = '';
|
|
13
|
-
for (const query of queryArray) {
|
|
14
|
-
mergeQuery = mergeQuery ? `${mergeQuery}${query}` : query;
|
|
15
|
-
let parsedQuery = {};
|
|
16
|
-
try {
|
|
17
|
-
parsedQuery = (0, _parseQuery.parseQuery)(mergeQuery);
|
|
18
|
-
mergeQuery = '';
|
|
19
|
-
} catch (e) {
|
|
20
|
-
// attempt to combine queries to fix bad splits
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
parsedQueries.push(parsedQuery);
|
|
24
|
-
}
|
|
25
|
-
if (mergeQuery) {
|
|
26
|
-
throw new Error(`Failed to interpret: ${mergeQuery}`);
|
|
27
|
-
}
|
|
28
|
-
return parsedQueries;
|
|
29
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parser = void 0;
|
|
7
|
+
var _splitQueries = require("../utilities/parsers/splitQueries");
|
|
8
|
+
var _parseQuery = require("../utilities/parsers/parseQuery");
|
|
9
|
+
const parser = (queries = '') => {
|
|
10
|
+
const queryArray = (0, _splitQueries.splitQueries)(queries);
|
|
11
|
+
const parsedQueries = [];
|
|
12
|
+
let mergeQuery = '';
|
|
13
|
+
for (const query of queryArray) {
|
|
14
|
+
mergeQuery = mergeQuery ? `${mergeQuery}${query}` : query;
|
|
15
|
+
let parsedQuery = {};
|
|
16
|
+
try {
|
|
17
|
+
parsedQuery = (0, _parseQuery.parseQuery)(mergeQuery);
|
|
18
|
+
mergeQuery = '';
|
|
19
|
+
} catch (e) {
|
|
20
|
+
// attempt to combine queries to fix bad splits
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
parsedQueries.push(parsedQuery);
|
|
24
|
+
}
|
|
25
|
+
if (mergeQuery) {
|
|
26
|
+
throw new Error(`Failed to interpret: ${mergeQuery}`);
|
|
27
|
+
}
|
|
28
|
+
return parsedQueries;
|
|
29
|
+
};
|
|
30
30
|
exports.parser = parser;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.query = void 0;
|
|
7
|
-
var _parser = require("./parser");
|
|
8
|
-
var _runQuery = require("../utilities/runQuery");
|
|
9
|
-
const query = async (queryString = '') => {
|
|
10
|
-
const parsedQueries = (0, _parser.parser)(queryString);
|
|
11
|
-
const queryResults = [];
|
|
12
|
-
for (const parsed of parsedQueries) {
|
|
13
|
-
const dataSet = await (0, _runQuery.runQuery)(parsed);
|
|
14
|
-
queryResults.push(dataSet[parsed.entity]);
|
|
15
|
-
}
|
|
16
|
-
return queryResults;
|
|
17
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.query = void 0;
|
|
7
|
+
var _parser = require("./parser");
|
|
8
|
+
var _runQuery = require("../utilities/runQuery");
|
|
9
|
+
const query = async (queryString = '') => {
|
|
10
|
+
const parsedQueries = (0, _parser.parser)(queryString);
|
|
11
|
+
const queryResults = [];
|
|
12
|
+
for (const parsed of parsedQueries) {
|
|
13
|
+
const dataSet = await (0, _runQuery.runQuery)(parsed);
|
|
14
|
+
queryResults.push(dataSet[parsed.entity]);
|
|
15
|
+
}
|
|
16
|
+
return queryResults;
|
|
17
|
+
};
|
|
18
18
|
exports.query = query;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.readEntity = void 0;
|
|
7
|
-
var _retrieveRecords = require("../utilities/retrieveRecords");
|
|
8
|
-
const readEntity = async (entity = '', dataSet = {}) => {
|
|
9
|
-
if (!Object.prototype.hasOwnProperty.call(dataSet, entity) || !dataSet[entity].length) {
|
|
10
|
-
dataSet[entity] = await (0, _retrieveRecords.retrieveRecords)(entity);
|
|
11
|
-
}
|
|
12
|
-
return dataSet;
|
|
13
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.readEntity = void 0;
|
|
7
|
+
var _retrieveRecords = require("../utilities/retrieveRecords");
|
|
8
|
+
const readEntity = async (entity = '', dataSet = {}) => {
|
|
9
|
+
if (!Object.prototype.hasOwnProperty.call(dataSet, entity) || !dataSet[entity].length) {
|
|
10
|
+
dataSet[entity] = await (0, _retrieveRecords.retrieveRecords)(entity);
|
|
11
|
+
}
|
|
12
|
+
return dataSet;
|
|
13
|
+
};
|
|
14
14
|
exports.readEntity = readEntity;
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.selectFields = void 0;
|
|
7
|
-
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
-
require("core-js/modules/esnext.iterator.map.js");
|
|
9
|
-
require("core-js/modules/esnext.iterator.reduce.js");
|
|
10
|
-
const shapeRow = (row, selectClauses) => selectClauses.reduce((shaped, {
|
|
11
|
-
property,
|
|
12
|
-
alias
|
|
13
|
-
}) => {
|
|
14
|
-
shaped[alias || property] = row[property];
|
|
15
|
-
return shaped;
|
|
16
|
-
}, {});
|
|
17
|
-
/**
|
|
18
|
-
* Shape each row down to only the selected properties (aliased, when given). dataSet is either a plain array of
|
|
19
|
-
* rows, or (once groupBy has run) a plain object keyed by group value, each value an array of rows - both are
|
|
20
|
-
* shaped the same way, row by row.
|
|
21
|
-
* @param dataSet
|
|
22
|
-
* @param selectClauses
|
|
23
|
-
*/
|
|
24
|
-
const selectFields = (dataSet = [], selectClauses = []) => {
|
|
25
|
-
if (!selectClauses.length) {
|
|
26
|
-
return dataSet;
|
|
27
|
-
}
|
|
28
|
-
if (Array.isArray(dataSet)) {
|
|
29
|
-
return dataSet.map(row => shapeRow(row, selectClauses));
|
|
30
|
-
}
|
|
31
|
-
return Object.keys(dataSet).reduce((shaped, key) => {
|
|
32
|
-
shaped[key] = dataSet[key].map(row => shapeRow(row, selectClauses));
|
|
33
|
-
return shaped;
|
|
34
|
-
}, {});
|
|
35
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.selectFields = void 0;
|
|
7
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
9
|
+
require("core-js/modules/esnext.iterator.reduce.js");
|
|
10
|
+
const shapeRow = (row, selectClauses) => selectClauses.reduce((shaped, {
|
|
11
|
+
property,
|
|
12
|
+
alias
|
|
13
|
+
}) => {
|
|
14
|
+
shaped[alias || property] = row[property];
|
|
15
|
+
return shaped;
|
|
16
|
+
}, {});
|
|
17
|
+
/**
|
|
18
|
+
* Shape each row down to only the selected properties (aliased, when given). dataSet is either a plain array of
|
|
19
|
+
* rows, or (once groupBy has run) a plain object keyed by group value, each value an array of rows - both are
|
|
20
|
+
* shaped the same way, row by row.
|
|
21
|
+
* @param dataSet
|
|
22
|
+
* @param selectClauses
|
|
23
|
+
*/
|
|
24
|
+
const selectFields = (dataSet = [], selectClauses = []) => {
|
|
25
|
+
if (!selectClauses.length) {
|
|
26
|
+
return dataSet;
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(dataSet)) {
|
|
29
|
+
return dataSet.map(row => shapeRow(row, selectClauses));
|
|
30
|
+
}
|
|
31
|
+
return Object.keys(dataSet).reduce((shaped, key) => {
|
|
32
|
+
shaped[key] = dataSet[key].map(row => shapeRow(row, selectClauses));
|
|
33
|
+
return shaped;
|
|
34
|
+
}, {});
|
|
35
|
+
};
|
|
36
36
|
exports.selectFields = selectFields;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.sortBy = void 0;
|
|
7
|
-
const sortBy = (dataSet = [], sortClauses = []) => {
|
|
8
|
-
if (!sortClauses.length) {
|
|
9
|
-
return dataSet;
|
|
10
|
-
}
|
|
11
|
-
dataSet.sort((a, b) => {
|
|
12
|
-
for (const sortClause of sortClauses) {
|
|
13
|
-
const property = sortClause.property;
|
|
14
|
-
const direction = sortClause.direction;
|
|
15
|
-
if (a[property] == b[property]) {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
const result = a[property] < b[property] ? -1 : 1;
|
|
19
|
-
return direction === 'asc' ? result : result * -1;
|
|
20
|
-
}
|
|
21
|
-
return 0;
|
|
22
|
-
});
|
|
23
|
-
return dataSet;
|
|
24
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sortBy = void 0;
|
|
7
|
+
const sortBy = (dataSet = [], sortClauses = []) => {
|
|
8
|
+
if (!sortClauses.length) {
|
|
9
|
+
return dataSet;
|
|
10
|
+
}
|
|
11
|
+
dataSet.sort((a, b) => {
|
|
12
|
+
for (const sortClause of sortClauses) {
|
|
13
|
+
const property = sortClause.property;
|
|
14
|
+
const direction = sortClause.direction;
|
|
15
|
+
if (a[property] == b[property]) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const result = a[property] < b[property] ? -1 : 1;
|
|
19
|
+
return direction === 'asc' ? result : result * -1;
|
|
20
|
+
}
|
|
21
|
+
return 0;
|
|
22
|
+
});
|
|
23
|
+
return dataSet;
|
|
24
|
+
};
|
|
25
25
|
exports.sortBy = sortBy;
|